UNPKG

@itwin/core-backend

Version:
97 lines 4.59 kB
/*--------------------------------------------------------------------------------------------- * Copyright (c) Bentley Systems, Incorporated. All rights reserved. * See LICENSE.md in the project root for license terms and full copyright notice. *--------------------------------------------------------------------------------------------*/ /** @packageDocumentation * @module Workspace */ import { Logger, UnexpectedErrors } from "@itwin/core-bentley"; import { BackendLoggerCategory } from "../BackendLoggerCategory"; import { _implementationProhibited } from "../internal/Symbols"; function makeSettingName(name) { return `${"itwin/core/workspace"}/${name}`; } /** The names of various [[Setting]]s with special meaning to the [[Workspace]] system. * @beta */ export var WorkspaceSettingNames; (function (WorkspaceSettingNames) { /** The name of a setting that, when present in a [[WorkspaceDb]] loaded by [[Workspace.loadSettingsDictionary]], will automatically * be used to find and load additional [[SettingsDictionary]]'s in other [[WorkspaceDb]]s. This permits you to chain the settings inside on [[WorkspaceDb]] * to others upon which they depend. * This setting's value is an array of [[WorkspaceDbSettingsProps]]s. */ WorkspaceSettingNames.settingsWorkspaces = makeSettingName("settingsWorkspaces"); })(WorkspaceSettingNames || (WorkspaceSettingNames = {})); function getWorkspaceResource(dbs, name, type) { for (const db of dbs) { const val = type === "blob" ? db.getBlob(name) : db.getString(name); if (undefined !== val) { return val; } } return undefined; } /** @beta */ export var Workspace; (function (Workspace) { /** A function invoked to handle exceptions produced while loading workspace data. * Applications can override this function to notify the user and/or attempt to diagnose the problem. * The default implementation simply logs each exception. */ Workspace.exceptionDiagnosticFn = (e) => { if (e instanceof Error) Logger.logException(BackendLoggerCategory.Workspace, e); else UnexpectedErrors.handle(e); }; /** A function invoked each time any [[SettingsDictionary]] is loaded from a [[WorkspaceDb]]. * Applications can override this function to notify the user and/or record diagnostics. * The default implementation simply records an information message in the [Logger]($bentley). */ Workspace.onSettingsDictionaryLoadedFn = (loaded) => { Logger.logInfo(BackendLoggerCategory.Workspace, `loaded setting dictionary ${loaded.dict.props.name} from ${loaded.from.dbFileName}`); }; /** Searches a list of [[WorkspaceDb]]s for a string resource of a given name. * The list is searched in order, and the first resource with the request name is returned. * If no such resource exists, the function returns `undefined`. * @see [[WorkspaceDb.getString]] if you only need to search a single `WorkspaceDb`. * @beta */ function getStringResource(args) { return getWorkspaceResource(args.dbs, args.name, "string"); } Workspace.getStringResource = getStringResource; /** Searches a list of [[WorkspaceDb]]s for a blob resource of a given name. * The list is searched in order, and the first resource with the request name is returned. * If no such resource exists, the function returns `undefined`. * @see [[WorkspaceDb.getblob]] if you only need to search a single `WorkspaceDb`. * @beta */ function getBlobResource(args) { return getWorkspaceResource(args.dbs, args.name, "blob"); } Workspace.getBlobResource = getBlobResource; /** Query a list of [[WorkspaceDb]]s to find resources of a particular type with names matching a specified pattern. * @see [[WorkspaceDb.queryResources]] if you only need to query a single `WorkspaceDb`. * @beta */ function queryResources(args) { const resources = []; for (const db of args.dbs) { db.queryResources({ type: args.type, namePattern: args.namePattern, nameCompare: args.nameCompare, callback: (names) => { for (const name of names) { resources.push({ db, name }); } }, }); } args.callback(resources); } Workspace.queryResources = queryResources; })(Workspace || (Workspace = {})); //# sourceMappingURL=Workspace.js.map