@itwin/core-backend 3.0.0-dev.151 → 3.0.0-dev.152

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -205,7 +205,7 @@ export declare class IModelHost {
205
205
  private static _briefcaseCacheDir;
206
206
  private static logStartup;
207
207
  private static setupHostDirs;
208
- /** This method must be called when an iTwin.js services is shut down. Raises [[onBeforeShutdown]] */
208
+ /** This method must be called when an iTwin.js host is shut down. Raises [[onBeforeShutdown]] */
209
209
  static shutdown(): Promise<void>;
210
210
  /**
211
211
  * Add or update a property that should be included in a crash report.
@@ -1 +1 @@
1
- {"version":3,"file":"IModelHost.d.ts","sourceRoot":"","sources":["../../src/IModelHost.ts"],"names":[],"mappings":"AAIA;;GAEG;AAKH,OAAO,EAAE,cAAc,EAAiB,MAAM,0BAA0B,CAAC;AACzE,OAAO,EAAE,gBAAgB,EAAE,MAAM,uBAAuB,CAAC;AACzD,OAAO,EAAE,WAAW,EAAU,OAAO,EAAQ,UAAU,EAAkC,OAAO,EAAmB,MAAM,qBAAqB,CAAC;AAC/I,OAAO,EAAE,mBAAmB,EAA8B,YAAY,EAAE,YAAY,EAAE,MAAM,oBAAoB,CAAC;AACjH,OAAO,EAAE,gBAAgB,EAAE,MAAM,oBAAoB,CAAC;AAItD,OAAO,EAAoB,2BAA2B,EAAE,mBAAmB,EAAE,wBAAwB,EAAE,MAAM,uBAAuB,CAAC;AAUrI,OAAO,EAAkB,SAAS,EAAE,aAAa,EAAE,MAAM,uBAAuB,CAAC;AAQjF,aAAa;AACb,MAAM,WAAW,iCAAiC;IAChD,IAAI,EAAE,MAAM,CAAC;IACb,KAAK,EAAE,MAAM,CAAC;CACf;AAED;;GAEG;AACH,MAAM,WAAW,oBAAoB;IACnC,8JAA8J;IAC9J,QAAQ,EAAE,MAAM,CAAC;IACjB,sEAAsE;IACtE,aAAa,CAAC,EAAE,MAAM,CAAC;IACvB,wOAAwO;IACxO,gBAAgB,CAAC,EAA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cacheDir) !== null && _a !== void 0 ? _a : imodeljs_native_1.NativeLibrary.defaultCacheDir);
283
283
  this._briefcaseCacheDir = path.join(this._cacheDir, "imodels");
284
284
  }
285
- /** This method must be called when an iTwin.js services is shut down. Raises [[onBeforeShutdown]] */
285
+ /** This method must be called when an iTwin.js host is shut down. Raises [[onBeforeShutdown]] */
286
286
  static async shutdown() {
287
287
  // NB: This method is set as a node listener where `this` is unbound
288
288
  if (!IModelHost._isValid)
@@ -1 +1 @@
1
- {"version":3,"file":"IModelHost.js","sourceRoot":"","sources":["../../src/IModelHost.ts"],"names":[],"mappings":";AAAA;;;+FAG+F;AAC/F;;GAEG;;;AAEH,yBAAyB;AACzB,6BAA6B;AAC7B,iCAAiC;AACjC,8DAAyE;AACzE,0DAAyD;AACzD,sDAA+I;AAC/I,oDAAiH;AAEjH,mEAAgE;AAChE,mDAAgD;AAChD,yDAAsD;AACtD,+DAAqI;AACrI,iEAA8D;AAC9D,2DAAwD;AACxD,6CAA0C;AAC1C,gEAA6D;AAC7D,oEAAiE;AACjE,oEAAiE;AACjE,4EAAyE;AACzE,sDAAmD;AACnD,6CAAoD;AACpD,qDAAiF;AACjF,mDAAyF;AACzF,2EAAwE;AAExE,MAAM,cAAc,GAAG,6CAAqB,CAAC,UAAU,CAAC;AAqCxD;;GAEG;AACH,MAAa,uBAAuB;IAApC;QAqDE;;WAEG;QACI,2BAAsB,GAAG,uBAAuB,CAAC,yBAAyB,CAAC;QAClF;;WAEG;QACI,8BAAyB,GAAG,uBAAuB,CAAC,yBAAyB,CAAC;QAUrF;;WAEG;QACI,6BAAwB,GAAW,uBAAuB,CAAC,+BAA+B,CAAC;QAMlG;;WAEG;QACI,yBAAoB,GAAW,uBAAuB,CAAC,2BAA2B,CAAC;IAW5F,CAAC;;AA7FD,0DA6FC;AAhCC;;GAEG;AACW,iDAAyB,GAAG,EAAE,GAAG,IAAI,CAAC;AAEpD;;GAEG;AACW,uDAA+B,GAAG,EAAE,CAAC;AAMnD;;GAE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IAC1B,CAAC;IACD;;;OAGG;IACI,kBAAkB,CAAC,UAAkB,IAAwB,OAAO,UAAU,CAAC,CAAC,CAAC;IACxF;;;;OAIG;IACI,eAAe,CAAC,UAAkB;QACvC,MAAM,gBAAgB,GAAuB,IAAI,CAAC,kBAAkB,CAAC,UAAU,CAAC,CAAC;QACjF,IAAI,SAAS,KAAK,gBAAgB,EAAE;YAClC,MAAM,IAAI,yBAAW,CAAC,2BAAY,CAAC,QAAQ,EAAE,GAAG,UAAU,eAAe,CAAC,CAAC;SAC5E;QACD,OAAO,gBAAgB,CAAC;IAC1B,CAAC;CACF;AAnCD,4CAmCC","sourcesContent":["/*---------------------------------------------------------------------------------------------\r\n* Copyright (c) Bentley Systems, Incorporated. All rights reserved.\r\n* See LICENSE.md in the project root for license terms and full copyright notice.\r\n*--------------------------------------------------------------------------------------------*/\r\n/** @packageDocumentation\r\n * @module IModelHost\r\n */\r\n\r\nimport * as os from \"os\";\r\nimport * as path from \"path\";\r\nimport * as semver from \"semver\";\r\nimport { IModelJsNative, NativeLibrary } from \"@bentley/imodeljs-native\";\r\nimport { TelemetryManager } from \"@itwin/core-telemetry\";\r\nimport { AccessToken, assert, BeEvent, Guid, GuidString, IModelStatus, Logger, LogLevel, Mutable, ProcessDetector } from \"@itwin/core-bentley\";\r\nimport { AuthorizationClient, BentleyStatus, IModelError, LocalDirName, SessionProps } from \"@itwin/core-common\";\r\nimport { BackendHubAccess } from \"./BackendHubAccess\";\r\nimport { BackendLoggerCategory } from \"./BackendLoggerCategory\";\r\nimport { BisCoreSchema } from \"./BisCoreSchema\";\r\nimport { BriefcaseManager } from \"./BriefcaseManager\";\r\nimport { AzureBlobStorage, AzureBlobStorageCredentials, CloudStorageService, CloudStorageTileUploader } from \"./CloudStorageBackend\";\r\nimport { FunctionalSchema } from \"./domains/FunctionalSchema\";\r\nimport { GenericSchema } from \"./domains/GenericSchema\";\r\nimport { IModelJsFs } from \"./IModelJsFs\";\r\nimport { DevToolsRpcImpl } from \"./rpc-impl/DevToolsRpcImpl\";\r\nimport { IModelReadRpcImpl } from \"./rpc-impl/IModelReadRpcImpl\";\r\nimport { IModelTileRpcImpl } from \"./rpc-impl/IModelTileRpcImpl\";\r\nimport { SnapshotIModelRpcImpl } from \"./rpc-impl/SnapshotIModelRpcImpl\";\r\nimport { WipRpcImpl } from \"./rpc-impl/WipRpcImpl\";\r\nimport { initializeRpcBackend } from \"./RpcBackend\";\r\nimport { ITwinWorkspace, Workspace, WorkspaceOpts } from \"./workspace/Workspace\";\r\nimport { BaseSettings, SettingDictionary, SettingsPriority } from \"./workspace/Settings\";\r\nimport { SettingsSpecRegistry } from \"./workspace/SettingsSpecRegistry\";\r\n\r\nconst loggerCategory = BackendLoggerCategory.IModelHost;\r\n\r\n// cspell:ignore nodereport fatalerror apicall alicloud rpcs\r\n\r\n/** @alpha */\r\nexport interface CrashReportingConfigNameValuePair {\r\n name: string;\r\n value: string;\r\n}\r\n\r\n/** Configuration of the crash-reporting system.\r\n * @alpha\r\n */\r\nexport interface CrashReportingConfig {\r\n /** The directory to which *.dmp and/or iModelJsNativeCrash*.properties.txt files are written. This directory will be created if it does not already exist. */\r\n crashDir: string;\r\n /** max # .dmp files that may exist in crashDir. The default is 50. */\r\n maxDumpsInDir?: number;\r\n /** Enable crash-dumps? If so, .dmp and .properties.txt files will be generated and written to crashDir in the event of an unhandled native-code exception. If not, only .properties.txt files will be written. The default is false. */\r\n enableCrashDumps?: boolean;\r\n /** If enableCrashDumps is true, do you want a full-memory dump? Defaults to false. */\r\n wantFullMemoryDumps?: boolean;\r\n /** Enable node-report? If so, node-report files will be generated in the event of an unhandled exception or fatal error and written to crashDir. The default is false. */\r\n enableNodeReport?: boolean;\r\n /** Additional name, value pairs to write to iModelJsNativeCrash*.properties.txt file in the event of a crash. */\r\n params?: CrashReportingConfigNameValuePair[];\r\n /** Run this .js file to process .dmp and node-report files in the event of a crash.\r\n * This script will be executed with a single command-line parameter: the name of the dump or node-report file.\r\n * In the case of a dump file, there will be a second file with the same basename and the extension \".properties.txt\".\r\n * Since it runs in a separate process, this script will have no access to the Javascript\r\n * context of the exiting backend. No default.\r\n */\r\n dumpProcessorScriptFileName?: string;\r\n /** Upload crash dump and node-reports to Bentley's crash-reporting service? Defaults to false */\r\n uploadToBentley?: boolean;\r\n}\r\n\r\n/** Configuration of core-backend.\r\n * @public\r\n */\r\nexport class IModelHostConfiguration {\r\n\r\n /**\r\n * Root of the directory holding all the files that iTwin.js caches\r\n * - If not specified at startup a platform specific default is used -\r\n * - Windows: $(HOMEDIR)/AppData/Local/iModelJs/\r\n * - Mac/iOS: $(HOMEDIR)/Library/Caches/iModelJs/\r\n * - Linux: $(HOMEDIR)/.cache/iModelJs/\r\n * where $(HOMEDIR) is documented [here](https://nodejs.org/api/os.html#os_os_homedir)\r\n * - if specified, ensure it is set to a folder with read/write access.\r\n * - Sub-folders within this folder organize various caches -\r\n * - bc/ -> Briefcases\r\n * - appSettings/ -> Offline application settings (only relevant in native applications)\r\n * - etc.\r\n * @see [[IModelHost.cacheDir]] for the value it's set to after startup\r\n */\r\n public cacheDir?: LocalDirName;\r\n\r\n /** Options for creating the [[Workspace]]\r\n * @beta\r\n */\r\n public workspace?: WorkspaceOpts;\r\n\r\n /** The directory where the app's assets are found. */\r\n public appAssetsDir?: LocalDirName;\r\n\r\n /** The kind of iModel hub server to use.\r\n * @beta\r\n */\r\n public hubAccess?: BackendHubAccess;\r\n\r\n /** The Azure blob storage credentials to use for the tile cache service. If omitted and no external service implementation is provided, a local cache will be used.\r\n * @beta\r\n */\r\n public tileCacheAzureCredentials?: AzureBlobStorageCredentials;\r\n\r\n /**\r\n * @beta\r\n * @note A reference implementation is set for [[AzureBlobStorage]] if [[tileCacheAzureCredentials]] property is set. To supply a different implementation for any service provider (such as AWS),\r\n * set this property with a custom [[CloudStorageService]].\r\n */\r\n public tileCacheService?: CloudStorageService;\r\n\r\n /** Whether to restrict tile cache URLs by client IP address (if available).\r\n * @beta\r\n */\r\n public restrictTileUrlsByClientIp?: boolean;\r\n\r\n /** Whether to compress cached tiles.\r\n * Defaults to `true`.\r\n */\r\n public compressCachedTiles?: boolean;\r\n\r\n /** The time, in milliseconds, for which [IModelTileRpcInterface.requestTileTreeProps]($common) should wait before returning a \"pending\" status.\r\n * @internal\r\n */\r\n public tileTreeRequestTimeout = IModelHostConfiguration.defaultTileRequestTimeout;\r\n /** The time, in milliseconds, for which [IModelTileRpcInterface.requestTileContent]($common) should wait before returning a \"pending\" status.\r\n * @internal\r\n */\r\n public tileContentRequestTimeout = IModelHostConfiguration.defaultTileRequestTimeout;\r\n /** The default time, in milliseconds, used for [[tileTreeRequestTimeout]] and [[tileContentRequestTimeout]]. To change this, override one or both of those properties.\r\n * @internal\r\n */\r\n public static defaultTileRequestTimeout = 20 * 1000;\r\n\r\n /** The default time, in seconds, used for [[logTileLoadTimeThreshold]]. To change this, override that property.\r\n * @internal\r\n */\r\n public static defaultLogTileLoadTimeThreshold = 40;\r\n /** The backend will log when a tile took longer to load than this threshold in seconds.\r\n * @internal\r\n */\r\n public logTileLoadTimeThreshold: number = IModelHostConfiguration.defaultLogTileLoadTimeThreshold;\r\n\r\n /** The default size, in bytes, used for [[logTileSizeThreshold]]. To change this, override that property.\r\n * @internal\r\n */\r\n public static defaultLogTileSizeThreshold = 20 * 1000000;\r\n /** The backend will log when a tile is loaded with a size in bytes above this threshold.\r\n * @internal\r\n */\r\n public logTileSizeThreshold: number = IModelHostConfiguration.defaultLogTileSizeThreshold;\r\n\r\n /** Crash-reporting configuration\r\n * @alpha\r\n */\r\n public crashReportingConfig?: CrashReportingConfig;\r\n\r\n /** The AuthorizationClient used to get accessTokens\r\n * @beta\r\n */\r\n public authorizationClient?: AuthorizationClient;\r\n}\r\n\r\n/**\r\n * Settings for the application workspace.\r\n * @note this includes the default dictionary from the SettingsSpecRegistry\r\n */\r\nclass ApplicationSettings extends BaseSettings {\r\n private _remove?: VoidFunction;\r\n protected override verifyPriority(priority: SettingsPriority) {\r\n if (priority >= SettingsPriority.iModel) // iModel settings may not appear in ApplicationSettings\r\n throw new Error(\"Use IModelSettings\");\r\n }\r\n private updateDefaults() {\r\n const defaults: SettingDictionary = {};\r\n for (const [specName, val] of SettingsSpecRegistry.allSpecs) {\r\n if (val.default)\r\n defaults[specName] = val.default;\r\n }\r\n this.addDictionary(\"_default_\", 0, defaults);\r\n }\r\n\r\n public constructor() {\r\n super();\r\n this._remove = SettingsSpecRegistry.onSpecsChanged.addListener(() => this.updateDefaults());\r\n this.updateDefaults();\r\n }\r\n public override close() {\r\n if (this._remove) {\r\n this._remove();\r\n this._remove = undefined;\r\n }\r\n }\r\n}\r\n\r\n/** IModelHost initializes ($backend) and captures its configuration. A backend must call [[IModelHost.startup]] before using any backend classes.\r\n * See [the learning article]($docs/learning/backend/IModelHost.md)\r\n * @public\r\n */\r\nexport class IModelHost {\r\n private constructor() { }\r\n public static authorizationClient?: AuthorizationClient;\r\n\r\n /** @alpha */\r\n public static readonly telemetry = new TelemetryManager();\r\n\r\n public static backendVersion = \"\";\r\n private static _cacheDir = \"\";\r\n private static _appWorkspace?: Workspace;\r\n\r\n private static _platform?: typeof IModelJsNative;\r\n /** @internal */\r\n public static get platform(): typeof IModelJsNative {\r\n if (this._platform === undefined)\r\n throw new Error(\"IModelHost.startup must be called first\");\r\n return this._platform;\r\n }\r\n\r\n public static configuration?: IModelHostConfiguration;\r\n /** Event raised just after the backend IModelHost was started */\r\n public static readonly onAfterStartup = new BeEvent<() => void>();\r\n\r\n /** Event raised just before the backend IModelHost is to be shut down */\r\n public static readonly onBeforeShutdown = new BeEvent<() => void>();\r\n\r\n /** @internal */\r\n public static readonly session: Mutable<SessionProps> = { applicationId: \"2686\", applicationVersion: \"1.0.0\", sessionId: \"\" };\r\n\r\n /** A uniqueId for this session */\r\n public static get sessionId() { return this.session.sessionId; }\r\n public static set sessionId(id: GuidString) { this.session.sessionId = id; }\r\n\r\n /** The Id of this application - needs to be set only if it is an agent application. The applicationId will otherwise originate at the frontend. */\r\n public static get applicationId() { return this.session.applicationId; }\r\n public static set applicationId(id: string) { this.session.applicationId = id; }\r\n\r\n /** The version of this application - needs to be set if is an agent application. The applicationVersion will otherwise originate at the frontend. */\r\n public static get applicationVersion() { return this.session.applicationVersion; }\r\n public static set applicationVersion(version: string) { this.session.applicationVersion = version; }\r\n\r\n /** Root directory holding files that iTwin.js caches */\r\n public static get cacheDir(): LocalDirName { return this._cacheDir; }\r\n\r\n /** The application [[Workspace]] for this `IModelHost`\r\n * @note this `Workspace` only holds [[WorkspaceContainer]]s and [[Settings]] scoped to the currently loaded application(s).\r\n * All organization, iTwin, and iModel based containers or settings must be accessed through [[IModelDb.workspace]] and\r\n * attempting to add them to this Workspace will fail.\r\n * @beta\r\n */\r\n public static get appWorkspace(): Workspace { return this._appWorkspace!; } // eslint-disable-line @typescript-eslint/no-non-null-assertion\r\n\r\n /** The optional [[FileNameResolver]] that resolves keys and partial file names for snapshot iModels. */\r\n public static snapshotFileNameResolver?: FileNameResolver;\r\n\r\n /** Get the current access token for this IModelHost, or a blank string if none is available.\r\n * @note for web backends, this will *always* return a blank string because the backend itself has no token (but never needs one either.)\r\n * For all IpcHosts, where this backend is servicing a single frontend, this will be the user's token. For ElectronHost, the backend\r\n * obtains the token and forwards it to the frontend.\r\n * @note accessTokens expire periodically and are automatically refreshed, if possible. Therefore tokens should not be saved, and the value\r\n * returned by this method may change over time throughout the course of a session.\r\n */\r\n public static async getAccessToken(): Promise<AccessToken> {\r\n try {\r\n return (await this.authorizationClient?.getAccessToken()) ?? \"\";\r\n } catch (e) {\r\n return \"\";\r\n }\r\n }\r\n\r\n /** @internal */\r\n public static flushLog() {\r\n return this.platform.DgnDb.flushLog();\r\n }\r\n /** @internal */\r\n public static loadNative(): void {\r\n const platform = Platform.load();\r\n this.registerPlatform(platform);\r\n }\r\n\r\n private static registerPlatform(platform: typeof IModelJsNative): void {\r\n this._platform = platform;\r\n if (undefined === platform)\r\n return;\r\n\r\n if (!ProcessDetector.isMobileAppBackend)\r\n this.validateNativePlatformVersion();\r\n\r\n platform.logger = Logger;\r\n }\r\n\r\n private static validateNativePlatformVersion(): void {\r\n const requiredVersion = require(\"../../package.json\").dependencies[\"@bentley/imodeljs-native\"]; // eslint-disable-line @typescript-eslint/no-var-requires\r\n const thisVersion = this.platform.version;\r\n if (semver.satisfies(thisVersion, requiredVersion))\r\n return;\r\n if (IModelJsFs.existsSync(path.join(__dirname, \"DevBuild.txt\"))) {\r\n console.log(\"Bypassing version checks for development build\"); // eslint-disable-line no-console\r\n return;\r\n }\r\n this._platform = undefined;\r\n throw new IModelError(IModelStatus.BadRequest, `imodeljs-native version is (${thisVersion}). core-backend requires version (${requiredVersion})`);\r\n }\r\n\r\n /**\r\n * @internal\r\n * @note Use [[IModelHostConfiguration.tileCacheService]] to set the service provider.\r\n */\r\n public static tileCacheService?: CloudStorageService;\r\n\r\n /** @internal */\r\n public static tileUploader?: CloudStorageTileUploader;\r\n\r\n private static _hubAccess: BackendHubAccess;\r\n /** @internal */\r\n public static setHubAccess(hubAccess: BackendHubAccess) { this._hubAccess = hubAccess; }\r\n\r\n /** Provides access to the IModelHub for this IModelHost\r\n * @beta\r\n */\r\n public static get hubAccess(): BackendHubAccess { return this._hubAccess; }\r\n\r\n private static _isValid = false;\r\n /** Returns true if IModelHost is started. */\r\n public static get isValid() { return this._isValid; }\r\n /** This method must be called before any iTwin.js services are used.\r\n * @param configuration Host configuration data.\r\n * Raises [[onAfterStartup]].\r\n * @see [[shutdown]].\r\n */\r\n public static async startup(configuration: IModelHostConfiguration = new IModelHostConfiguration()): Promise<void> {\r\n if (this._isValid)\r\n return; // we're already initialized\r\n this._isValid = true;\r\n\r\n if (IModelHost.sessionId === \"\")\r\n IModelHost.sessionId = Guid.createValue();\r\n\r\n this.authorizationClient = configuration.authorizationClient;\r\n\r\n this.logStartup();\r\n\r\n this.backendVersion = require(\"../../package.json\").version; // eslint-disable-line @typescript-eslint/no-var-requires\r\n initializeRpcBackend();\r\n\r\n if (this._platform === undefined) {\r\n try {\r\n this.loadNative();\r\n } catch (error) {\r\n Logger.logError(loggerCategory, \"Error registering/loading the native platform API\", () => (configuration));\r\n throw error;\r\n }\r\n }\r\n\r\n if (configuration.crashReportingConfig && configuration.crashReportingConfig.crashDir && !ProcessDetector.isElectronAppBackend && !ProcessDetector.isMobileAppBackend) {\r\n this.platform.setCrashReporting(configuration.crashReportingConfig);\r\n\r\n Logger.logTrace(loggerCategory, \"Configured crash reporting\", () => ({\r\n enableCrashDumps: configuration.crashReportingConfig?.enableCrashDumps,\r\n wantFullMemoryDumps: configuration.crashReportingConfig?.wantFullMemoryDumps,\r\n enableNodeReport: configuration.crashReportingConfig?.enableNodeReport,\r\n uploadToBentley: configuration.crashReportingConfig?.uploadToBentley,\r\n }));\r\n\r\n if (configuration.crashReportingConfig.enableNodeReport) {\r\n try {\r\n // node-report reports on V8 fatal errors and unhandled exceptions/Promise rejections.\r\n const nodereport = require(\"node-report/api\"); // eslint-disable-line @typescript-eslint/no-var-requires\r\n nodereport.setEvents(\"exception+fatalerror+apicall\");\r\n nodereport.setDirectory(configuration.crashReportingConfig.crashDir);\r\n nodereport.setVerbose(\"yes\");\r\n Logger.logTrace(loggerCategory, \"Configured native crash reporting (node-report)\");\r\n } catch (err) {\r\n Logger.logWarning(loggerCategory, \"node-report is not installed.\");\r\n }\r\n }\r\n }\r\n\r\n this.setupHostDirs(configuration);\r\n this._appWorkspace = new ITwinWorkspace(new ApplicationSettings(), configuration.workspace);\r\n\r\n BriefcaseManager.initialize(this._briefcaseCacheDir);\r\n\r\n [\r\n IModelReadRpcImpl,\r\n IModelTileRpcImpl,\r\n SnapshotIModelRpcImpl,\r\n WipRpcImpl,\r\n DevToolsRpcImpl,\r\n ].forEach((rpc) => rpc.register()); // register all of the RPC implementations\r\n\r\n [\r\n BisCoreSchema,\r\n GenericSchema,\r\n FunctionalSchema,\r\n ].forEach((schema) => schema.registerSchema()); // register all of the schemas\r\n\r\n if (undefined !== configuration.hubAccess)\r\n IModelHost._hubAccess = configuration.hubAccess;\r\n IModelHost.configuration = configuration;\r\n IModelHost.setupTileCache();\r\n\r\n this.platform.setUseTileCache(IModelHost.tileCacheService ? false : true);\r\n\r\n process.once(\"beforeExit\", IModelHost.shutdown);\r\n IModelHost.onAfterStartup.raiseEvent();\r\n }\r\n\r\n private static _briefcaseCacheDir: LocalDirName;\r\n\r\n private static logStartup() {\r\n if (!Logger.isEnabled(loggerCategory, LogLevel.Trace))\r\n return;\r\n\r\n // Extract the iModel details from environment - note this is very specific to Bentley hosted backends, but is quite useful for tracing\r\n let startupInfo: any = {};\r\n const serviceName = process.env.FABRIC_SERVICE_NAME;\r\n if (serviceName) {\r\n // e.g., fabric:/iModelWebViewer3.0/iModelJSGuest/1/08daaeb3-b56f-480b-9051-7efc834d18ae/512d971d-b641-4735-bb1c-c07ab3e44ce7/c1315fcce125ca40b2d405bb7809214daf8b4c85\r\n const serviceNameComponents = serviceName.split(\"/\");\r\n if (serviceNameComponents.length === 7) {\r\n startupInfo = {\r\n ...startupInfo,\r\n iTwinId: serviceNameComponents[4],\r\n iModelId: serviceNameComponents[5],\r\n changesetId: serviceNameComponents[6],\r\n };\r\n }\r\n }\r\n\r\n Logger.logTrace(loggerCategory, \"IModelHost.startup\", () => startupInfo);\r\n }\r\n\r\n private static setupHostDirs(configuration: IModelHostConfiguration) {\r\n const setupDir = (dir: LocalDirName) => {\r\n dir = path.normalize(dir);\r\n IModelJsFs.recursiveMkDirSync(dir);\r\n return dir;\r\n };\r\n this._cacheDir = setupDir(configuration.cacheDir ?? NativeLibrary.defaultCacheDir);\r\n this._briefcaseCacheDir = path.join(this._cacheDir, \"imodels\");\r\n }\r\n\r\n /** This method must be called when an iTwin.js services is shut down. Raises [[onBeforeShutdown]] */\r\n public static async shutdown(): Promise<void> {\r\n // NB: This method is set as a node listener where `this` is unbound\r\n if (!IModelHost._isValid)\r\n return;\r\n\r\n IModelHost._isValid = false;\r\n IModelHost.onBeforeShutdown.raiseEvent();\r\n IModelHost.configuration = undefined;\r\n IModelHost.tileCacheService = undefined;\r\n IModelHost.tileUploader = undefined;\r\n IModelHost.appWorkspace.close();\r\n IModelHost._appWorkspace = undefined;\r\n process.removeListener(\"beforeExit\", IModelHost.shutdown);\r\n }\r\n\r\n /**\r\n * Add or update a property that should be included in a crash report.\r\n * @param name The name of the property\r\n * @param value The value of the property\r\n * @alpha\r\n */\r\n public static setCrashReportProperty(name: string, value: string): void {\r\n assert(undefined !== this._platform);\r\n this._platform.setCrashReportProperty(name, value);\r\n }\r\n\r\n /**\r\n * Remove a previously defined property so that will not be included in a crash report.\r\n * @param name The name of the property\r\n * @alpha\r\n */\r\n public static removeCrashReportProperty(name: string): void {\r\n assert(undefined !== this._platform);\r\n this._platform.setCrashReportProperty(name, undefined);\r\n }\r\n\r\n /**\r\n * Get all properties that will be included in a crash report.\r\n * @alpha\r\n */\r\n public static getCrashReportProperties(): CrashReportingConfigNameValuePair[] {\r\n assert(undefined !== this._platform);\r\n return this._platform.getCrashReportProperties();\r\n }\r\n\r\n /** The directory where application assets may be found */\r\n public static get appAssetsDir(): string | undefined { return undefined !== IModelHost.configuration ? IModelHost.configuration.appAssetsDir : undefined; }\r\n\r\n /** The time, in milliseconds, for which [IModelTileRpcInterface.requestTileTreeProps]($common) should wait before returning a \"pending\" status.\r\n * @internal\r\n */\r\n public static get tileTreeRequestTimeout(): number {\r\n return undefined !== IModelHost.configuration ? IModelHost.configuration.tileTreeRequestTimeout : IModelHostConfiguration.defaultTileRequestTimeout;\r\n }\r\n /** The time, in milliseconds, for which [IModelTileRpcInterface.requestTileContent]($common) should wait before returning a \"pending\" status.\r\n * @internal\r\n */\r\n public static get tileContentRequestTimeout(): number {\r\n return undefined !== IModelHost.configuration ? IModelHost.configuration.tileContentRequestTimeout : IModelHostConfiguration.defaultTileRequestTimeout;\r\n }\r\n\r\n /** The backend will log when a tile took longer to load than this threshold in seconds. */\r\n public static get logTileLoadTimeThreshold(): number { return undefined !== IModelHost.configuration ? IModelHost.configuration.logTileLoadTimeThreshold : IModelHostConfiguration.defaultLogTileLoadTimeThreshold; }\r\n /** The backend will log when a tile is loaded with a size in bytes above this threshold. */\r\n public static get logTileSizeThreshold(): number { return undefined !== IModelHost.configuration ? IModelHost.configuration.logTileSizeThreshold : IModelHostConfiguration.defaultLogTileSizeThreshold; }\r\n\r\n /** Whether external tile caching is active.\r\n * @internal\r\n */\r\n public static get usingExternalTileCache(): boolean {\r\n return undefined !== IModelHost.tileCacheService;\r\n }\r\n\r\n /** Whether to restrict tile cache URLs by client IP address.\r\n * @internal\r\n */\r\n public static get restrictTileUrlsByClientIp(): boolean { return undefined !== IModelHost.configuration && (IModelHost.configuration.restrictTileUrlsByClientIp ? true : false); }\r\n\r\n /** Whether to compress cached tiles.\r\n * @internal\r\n */\r\n public static get compressCachedTiles(): boolean { return false !== IModelHost.configuration?.compressCachedTiles; }\r\n\r\n private static setupTileCache() {\r\n assert(undefined !== IModelHost.configuration);\r\n const config = IModelHost.configuration;\r\n const service = config.tileCacheService;\r\n const credentials = config.tileCacheAzureCredentials;\r\n\r\n if (!service && !credentials)\r\n return;\r\n\r\n IModelHost.tileUploader = new CloudStorageTileUploader();\r\n\r\n if (credentials && !service) {\r\n IModelHost.tileCacheService = new AzureBlobStorage(credentials);\r\n } else if (!credentials && service) {\r\n IModelHost.tileCacheService = service;\r\n } else {\r\n throw new IModelError(BentleyStatus.ERROR, \"Cannot use both Azure and custom cloud storage providers for tile cache.\");\r\n }\r\n }\r\n}\r\n\r\n/** Information about the platform on which the app is running. Also see [[KnownLocations]] and [[IModelJsFs]].\r\n * @public\r\n */\r\nexport class Platform {\r\n /** Get the name of the platform. */\r\n public static get platformName(): \"win32\" | \"linux\" | \"darwin\" | \"ios\" | \"android\" | \"uwp\" {\r\n return process.platform as any;\r\n }\r\n\r\n /** @internal */\r\n public static load(): typeof IModelJsNative {\r\n return ProcessDetector.isMobileAppBackend ? (process as any)._linkedBinding(\"iModelJsNative\") : NativeLibrary.load();\r\n }\r\n}\r\n\r\n/** Well known directories that may be used by the application. Also see [[Platform]]\r\n * @public\r\n */\r\nexport class KnownLocations {\r\n\r\n /** The directory where the imodeljs-native assets are stored. */\r\n public static get nativeAssetsDir(): string { return IModelHost.platform.DgnDb.getAssetsDir(); }\r\n\r\n /** The directory where the core-backend assets are stored. */\r\n public static get packageAssetsDir(): string {\r\n return path.join(__dirname, \"assets\");\r\n }\r\n\r\n /** The temporary directory. */\r\n public static get tmpdir(): string {\r\n return os.tmpdir();\r\n }\r\n}\r\n\r\n/** Extend this class to provide custom file name resolution behavior.\r\n * @note Only `tryResolveKey` and/or `tryResolveFileName` need to be overridden as the implementations of `resolveKey` and `resolveFileName` work for most purposes.\r\n * @see [[IModelHost.snapshotFileNameResolver]]\r\n * @public\r\n */\r\nexport abstract class FileNameResolver {\r\n /** Resolve a file name from the specified key.\r\n * @param _fileKey The key that identifies the file name in a `Map` or other similar data structure.\r\n * @returns The resolved file name or `undefined` if not found.\r\n */\r\n public tryResolveKey(_fileKey: string): string | undefined { return undefined; }\r\n /** Resolve a file name from the specified key.\r\n * @param fileKey The key that identifies the file name in a `Map` or other similar data structure.\r\n * @returns The resolved file name.\r\n * @throws [[IModelError]] if not found.\r\n */\r\n public resolveKey(fileKey: string): string {\r\n const resolvedFileName: string | undefined = this.tryResolveKey(fileKey);\r\n if (undefined === resolvedFileName) {\r\n throw new IModelError(IModelStatus.NotFound, `${fileKey} not resolved`);\r\n }\r\n return resolvedFileName;\r\n }\r\n /** Resolve the input file name, which may be a partial name, into a full path file name.\r\n * @param inFileName The partial file name.\r\n * @returns The resolved full path file name or `undefined` if not found.\r\n */\r\n public tryResolveFileName(inFileName: string): string | undefined { return inFileName; }\r\n /** Resolve the input file name, which may be a partial name, into a full path file name.\r\n * @param inFileName The partial file name.\r\n * @returns The resolved full path file name.\r\n * @throws [[IModelError]] if not found.\r\n */\r\n public resolveFileName(inFileName: string): string {\r\n const resolvedFileName: string | undefined = this.tryResolveFileName(inFileName);\r\n if (undefined === resolvedFileName) {\r\n throw new IModelError(IModelStatus.NotFound, `${inFileName} not resolved`);\r\n }\r\n return resolvedFileName;\r\n }\r\n}\r\n"]}
1
+ {"version":3,"file":"IModelHost.js","sourceRoot":"","sources":["../../src/IModelHost.ts"],"names":[],"mappings":";AAAA;;;+FAG+F;AAC/F;;GAEG;;;AAEH,yBAAyB;AACzB,6BAA6B;AAC7B,iCAAiC;AACjC,8DAAyE;AACzE,0DAAyD;AACzD,sDAA+I;AAC/I,oDAAiH;AAEjH,mEAAgE;AAChE,mDAAgD;AAChD,yDAAsD;AACtD,+DAAqI;AACrI,iEAA8D;AAC9D,2DAAwD;AACxD,6CAA0C;AAC1C,gEAA6D;AAC7D,oEAAiE;AACjE,oEAAiE;AACjE,4EAAyE;AACzE,sDAAmD;AACnD,6CAAoD;AACpD,qDAAiF;AACjF,mDAAyF;AACzF,2EAAwE;AAExE,MAAM,cAAc,GAAG,6CAAqB,CAAC,UAAU,CAAC;AAqCxD;;GAEG;AACH,MAAa,uBAAuB;IAApC;QAqDE;;WAEG;QACI,2BAAsB,GAAG,uBAAuB,CAAC,yBAAyB,CAAC;QAClF;;WAEG;QACI,8BAAyB,GAAG,uBAAuB,CAAC,yBAAyB,CAAC;QAUrF;;WAEG;QACI,6BAAwB,GAAW,uBAAuB,CAAC,+BAA+B,CAAC;QAMlG;;WAEG;QACI,yBAAoB,GAAW,uBAAuB,CAAC,2BAA2B,CAAC;IAW5F,CAAC;;AA7FD,0DA6FC;AAhCC;;GAEG;AACW,iDAAyB,GAAG,EAAE,GAAG,IAAI,CAAC;AAEpD;;GAEG;AACW,uDAA+B,GAAG,EAAE,CAAC;AAMnD;;GAEG;AACW,mDAA2B,GAAG,EAAE,GAAG,OAAO,CAAC;AAiB3D;;;GAGG;AACH,MAAM,mBAAoB,SAAQ,uBAAY;IAe5C;QACE,KAAK,EAAE,CAAC;QACR,IAAI,CAAC,OAAO,GAAG,2CAAoB,CAAC,cAAc,CAAC,WAAW,CAAC,GAAG,E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;QACjF,IAAI,SAAS,KAAK,gBAAgB,EAAE;YAClC,MAAM,IAAI,yBAAW,CAAC,2BAAY,CAAC,QAAQ,EAAE,GAAG,UAAU,eAAe,CAAC,CAAC;SAC5E;QACD,OAAO,gBAAgB,CAAC;IAC1B,CAAC;CACF;AAnCD,4CAmCC","sourcesContent":["/*---------------------------------------------------------------------------------------------\r\n* Copyright (c) Bentley Systems, Incorporated. All rights reserved.\r\n* See LICENSE.md in the project root for license terms and full copyright notice.\r\n*--------------------------------------------------------------------------------------------*/\r\n/** @packageDocumentation\r\n * @module IModelHost\r\n */\r\n\r\nimport * as os from \"os\";\r\nimport * as path from \"path\";\r\nimport * as semver from \"semver\";\r\nimport { IModelJsNative, NativeLibrary } from \"@bentley/imodeljs-native\";\r\nimport { TelemetryManager } from \"@itwin/core-telemetry\";\r\nimport { AccessToken, assert, BeEvent, Guid, GuidString, IModelStatus, Logger, LogLevel, Mutable, ProcessDetector } from \"@itwin/core-bentley\";\r\nimport { AuthorizationClient, BentleyStatus, IModelError, LocalDirName, SessionProps } from \"@itwin/core-common\";\r\nimport { BackendHubAccess } from \"./BackendHubAccess\";\r\nimport { BackendLoggerCategory } from \"./BackendLoggerCategory\";\r\nimport { BisCoreSchema } from \"./BisCoreSchema\";\r\nimport { BriefcaseManager } from \"./BriefcaseManager\";\r\nimport { AzureBlobStorage, AzureBlobStorageCredentials, CloudStorageService, CloudStorageTileUploader } from \"./CloudStorageBackend\";\r\nimport { FunctionalSchema } from \"./domains/FunctionalSchema\";\r\nimport { GenericSchema } from \"./domains/GenericSchema\";\r\nimport { IModelJsFs } from \"./IModelJsFs\";\r\nimport { DevToolsRpcImpl } from \"./rpc-impl/DevToolsRpcImpl\";\r\nimport { IModelReadRpcImpl } from \"./rpc-impl/IModelReadRpcImpl\";\r\nimport { IModelTileRpcImpl } from \"./rpc-impl/IModelTileRpcImpl\";\r\nimport { SnapshotIModelRpcImpl } from \"./rpc-impl/SnapshotIModelRpcImpl\";\r\nimport { WipRpcImpl } from \"./rpc-impl/WipRpcImpl\";\r\nimport { initializeRpcBackend } from \"./RpcBackend\";\r\nimport { ITwinWorkspace, Workspace, WorkspaceOpts } from \"./workspace/Workspace\";\r\nimport { BaseSettings, SettingDictionary, SettingsPriority } from \"./workspace/Settings\";\r\nimport { SettingsSpecRegistry } from \"./workspace/SettingsSpecRegistry\";\r\n\r\nconst loggerCategory = BackendLoggerCategory.IModelHost;\r\n\r\n// cspell:ignore nodereport fatalerror apicall alicloud rpcs\r\n\r\n/** @alpha */\r\nexport interface CrashReportingConfigNameValuePair {\r\n name: string;\r\n value: string;\r\n}\r\n\r\n/** Configuration of the crash-reporting system.\r\n * @alpha\r\n */\r\nexport interface CrashReportingConfig {\r\n /** The directory to which *.dmp and/or iModelJsNativeCrash*.properties.txt files are written. This directory will be created if it does not already exist. */\r\n crashDir: string;\r\n /** max # .dmp files that may exist in crashDir. The default is 50. */\r\n maxDumpsInDir?: number;\r\n /** Enable crash-dumps? If so, .dmp and .properties.txt files will be generated and written to crashDir in the event of an unhandled native-code exception. If not, only .properties.txt files will be written. The default is false. */\r\n enableCrashDumps?: boolean;\r\n /** If enableCrashDumps is true, do you want a full-memory dump? Defaults to false. */\r\n wantFullMemoryDumps?: boolean;\r\n /** Enable node-report? If so, node-report files will be generated in the event of an unhandled exception or fatal error and written to crashDir. The default is false. */\r\n enableNodeReport?: boolean;\r\n /** Additional name, value pairs to write to iModelJsNativeCrash*.properties.txt file in the event of a crash. */\r\n params?: CrashReportingConfigNameValuePair[];\r\n /** Run this .js file to process .dmp and node-report files in the event of a crash.\r\n * This script will be executed with a single command-line parameter: the name of the dump or node-report file.\r\n * In the case of a dump file, there will be a second file with the same basename and the extension \".properties.txt\".\r\n * Since it runs in a separate process, this script will have no access to the Javascript\r\n * context of the exiting backend. No default.\r\n */\r\n dumpProcessorScriptFileName?: string;\r\n /** Upload crash dump and node-reports to Bentley's crash-reporting service? Defaults to false */\r\n uploadToBentley?: boolean;\r\n}\r\n\r\n/** Configuration of core-backend.\r\n * @public\r\n */\r\nexport class IModelHostConfiguration {\r\n\r\n /**\r\n * Root of the directory holding all the files that iTwin.js caches\r\n * - If not specified at startup a platform specific default is used -\r\n * - Windows: $(HOMEDIR)/AppData/Local/iModelJs/\r\n * - Mac/iOS: $(HOMEDIR)/Library/Caches/iModelJs/\r\n * - Linux: $(HOMEDIR)/.cache/iModelJs/\r\n * where $(HOMEDIR) is documented [here](https://nodejs.org/api/os.html#os_os_homedir)\r\n * - if specified, ensure it is set to a folder with read/write access.\r\n * - Sub-folders within this folder organize various caches -\r\n * - bc/ -> Briefcases\r\n * - appSettings/ -> Offline application settings (only relevant in native applications)\r\n * - etc.\r\n * @see [[IModelHost.cacheDir]] for the value it's set to after startup\r\n */\r\n public cacheDir?: LocalDirName;\r\n\r\n /** Options for creating the [[Workspace]]\r\n * @beta\r\n */\r\n public workspace?: WorkspaceOpts;\r\n\r\n /** The directory where the app's assets are found. */\r\n public appAssetsDir?: LocalDirName;\r\n\r\n /** The kind of iModel hub server to use.\r\n * @beta\r\n */\r\n public hubAccess?: BackendHubAccess;\r\n\r\n /** The Azure blob storage credentials to use for the tile cache service. If omitted and no external service implementation is provided, a local cache will be used.\r\n * @beta\r\n */\r\n public tileCacheAzureCredentials?: AzureBlobStorageCredentials;\r\n\r\n /**\r\n * @beta\r\n * @note A reference implementation is set for [[AzureBlobStorage]] if [[tileCacheAzureCredentials]] property is set. To supply a different implementation for any service provider (such as AWS),\r\n * set this property with a custom [[CloudStorageService]].\r\n */\r\n public tileCacheService?: CloudStorageService;\r\n\r\n /** Whether to restrict tile cache URLs by client IP address (if available).\r\n * @beta\r\n */\r\n public restrictTileUrlsByClientIp?: boolean;\r\n\r\n /** Whether to compress cached tiles.\r\n * Defaults to `true`.\r\n */\r\n public compressCachedTiles?: boolean;\r\n\r\n /** The time, in milliseconds, for which [IModelTileRpcInterface.requestTileTreeProps]($common) should wait before returning a \"pending\" status.\r\n * @internal\r\n */\r\n public tileTreeRequestTimeout = IModelHostConfiguration.defaultTileRequestTimeout;\r\n /** The time, in milliseconds, for which [IModelTileRpcInterface.requestTileContent]($common) should wait before returning a \"pending\" status.\r\n * @internal\r\n */\r\n public tileContentRequestTimeout = IModelHostConfiguration.defaultTileRequestTimeout;\r\n /** The default time, in milliseconds, used for [[tileTreeRequestTimeout]] and [[tileContentRequestTimeout]]. To change this, override one or both of those properties.\r\n * @internal\r\n */\r\n public static defaultTileRequestTimeout = 20 * 1000;\r\n\r\n /** The default time, in seconds, used for [[logTileLoadTimeThreshold]]. To change this, override that property.\r\n * @internal\r\n */\r\n public static defaultLogTileLoadTimeThreshold = 40;\r\n /** The backend will log when a tile took longer to load than this threshold in seconds.\r\n * @internal\r\n */\r\n public logTileLoadTimeThreshold: number = IModelHostConfiguration.defaultLogTileLoadTimeThreshold;\r\n\r\n /** The default size, in bytes, used for [[logTileSizeThreshold]]. To change this, override that property.\r\n * @internal\r\n */\r\n public static defaultLogTileSizeThreshold = 20 * 1000000;\r\n /** The backend will log when a tile is loaded with a size in bytes above this threshold.\r\n * @internal\r\n */\r\n public logTileSizeThreshold: number = IModelHostConfiguration.defaultLogTileSizeThreshold;\r\n\r\n /** Crash-reporting configuration\r\n * @alpha\r\n */\r\n public crashReportingConfig?: CrashReportingConfig;\r\n\r\n /** The AuthorizationClient used to get accessTokens\r\n * @beta\r\n */\r\n public authorizationClient?: AuthorizationClient;\r\n}\r\n\r\n/**\r\n * Settings for the application workspace.\r\n * @note this includes the default dictionary from the SettingsSpecRegistry\r\n */\r\nclass ApplicationSettings extends BaseSettings {\r\n private _remove?: VoidFunction;\r\n protected override verifyPriority(priority: SettingsPriority) {\r\n if (priority >= SettingsPriority.iModel) // iModel settings may not appear in ApplicationSettings\r\n throw new Error(\"Use IModelSettings\");\r\n }\r\n private updateDefaults() {\r\n const defaults: SettingDictionary = {};\r\n for (const [specName, val] of SettingsSpecRegistry.allSpecs) {\r\n if (val.default)\r\n defaults[specName] = val.default;\r\n }\r\n this.addDictionary(\"_default_\", 0, defaults);\r\n }\r\n\r\n public constructor() {\r\n super();\r\n this._remove = SettingsSpecRegistry.onSpecsChanged.addListener(() => this.updateDefaults());\r\n this.updateDefaults();\r\n }\r\n public override close() {\r\n if (this._remove) {\r\n this._remove();\r\n this._remove = undefined;\r\n }\r\n }\r\n}\r\n\r\n/** IModelHost initializes ($backend) and captures its configuration. A backend must call [[IModelHost.startup]] before using any backend classes.\r\n * See [the learning article]($docs/learning/backend/IModelHost.md)\r\n * @public\r\n */\r\nexport class IModelHost {\r\n private constructor() { }\r\n public static authorizationClient?: AuthorizationClient;\r\n\r\n /** @alpha */\r\n public static readonly telemetry = new TelemetryManager();\r\n\r\n public static backendVersion = \"\";\r\n private static _cacheDir = \"\";\r\n private static _appWorkspace?: Workspace;\r\n\r\n private static _platform?: typeof IModelJsNative;\r\n /** @internal */\r\n public static get platform(): typeof IModelJsNative {\r\n if (this._platform === undefined)\r\n throw new Error(\"IModelHost.startup must be called first\");\r\n return this._platform;\r\n }\r\n\r\n public static configuration?: IModelHostConfiguration;\r\n /** Event raised just after the backend IModelHost was started */\r\n public static readonly onAfterStartup = new BeEvent<() => void>();\r\n\r\n /** Event raised just before the backend IModelHost is to be shut down */\r\n public static readonly onBeforeShutdown = new BeEvent<() => void>();\r\n\r\n /** @internal */\r\n public static readonly session: Mutable<SessionProps> = { applicationId: \"2686\", applicationVersion: \"1.0.0\", sessionId: \"\" };\r\n\r\n /** A uniqueId for this session */\r\n public static get sessionId() { return this.session.sessionId; }\r\n public static set sessionId(id: GuidString) { this.session.sessionId = id; }\r\n\r\n /** The Id of this application - needs to be set only if it is an agent application. The applicationId will otherwise originate at the frontend. */\r\n public static get applicationId() { return this.session.applicationId; }\r\n public static set applicationId(id: string) { this.session.applicationId = id; }\r\n\r\n /** The version of this application - needs to be set if is an agent application. The applicationVersion will otherwise originate at the frontend. */\r\n public static get applicationVersion() { return this.session.applicationVersion; }\r\n public static set applicationVersion(version: string) { this.session.applicationVersion = version; }\r\n\r\n /** Root directory holding files that iTwin.js caches */\r\n public static get cacheDir(): LocalDirName { return this._cacheDir; }\r\n\r\n /** The application [[Workspace]] for this `IModelHost`\r\n * @note this `Workspace` only holds [[WorkspaceContainer]]s and [[Settings]] scoped to the currently loaded application(s).\r\n * All organization, iTwin, and iModel based containers or settings must be accessed through [[IModelDb.workspace]] and\r\n * attempting to add them to this Workspace will fail.\r\n * @beta\r\n */\r\n public static get appWorkspace(): Workspace { return this._appWorkspace!; } // eslint-disable-line @typescript-eslint/no-non-null-assertion\r\n\r\n /** The optional [[FileNameResolver]] that resolves keys and partial file names for snapshot iModels. */\r\n public static snapshotFileNameResolver?: FileNameResolver;\r\n\r\n /** Get the current access token for this IModelHost, or a blank string if none is available.\r\n * @note for web backends, this will *always* return a blank string because the backend itself has no token (but never needs one either.)\r\n * For all IpcHosts, where this backend is servicing a single frontend, this will be the user's token. For ElectronHost, the backend\r\n * obtains the token and forwards it to the frontend.\r\n * @note accessTokens expire periodically and are automatically refreshed, if possible. Therefore tokens should not be saved, and the value\r\n * returned by this method may change over time throughout the course of a session.\r\n */\r\n public static async getAccessToken(): Promise<AccessToken> {\r\n try {\r\n return (await this.authorizationClient?.getAccessToken()) ?? \"\";\r\n } catch (e) {\r\n return \"\";\r\n }\r\n }\r\n\r\n /** @internal */\r\n public static flushLog() {\r\n return this.platform.DgnDb.flushLog();\r\n }\r\n /** @internal */\r\n public static loadNative(): void {\r\n const platform = Platform.load();\r\n this.registerPlatform(platform);\r\n }\r\n\r\n private static registerPlatform(platform: typeof IModelJsNative): void {\r\n this._platform = platform;\r\n if (undefined === platform)\r\n return;\r\n\r\n if (!ProcessDetector.isMobileAppBackend)\r\n this.validateNativePlatformVersion();\r\n\r\n platform.logger = Logger;\r\n }\r\n\r\n private static validateNativePlatformVersion(): void {\r\n const requiredVersion = require(\"../../package.json\").dependencies[\"@bentley/imodeljs-native\"]; // eslint-disable-line @typescript-eslint/no-var-requires\r\n const thisVersion = this.platform.version;\r\n if (semver.satisfies(thisVersion, requiredVersion))\r\n return;\r\n if (IModelJsFs.existsSync(path.join(__dirname, \"DevBuild.txt\"))) {\r\n console.log(\"Bypassing version checks for development build\"); // eslint-disable-line no-console\r\n return;\r\n }\r\n this._platform = undefined;\r\n throw new IModelError(IModelStatus.BadRequest, `imodeljs-native version is (${thisVersion}). core-backend requires version (${requiredVersion})`);\r\n }\r\n\r\n /**\r\n * @internal\r\n * @note Use [[IModelHostConfiguration.tileCacheService]] to set the service provider.\r\n */\r\n public static tileCacheService?: CloudStorageService;\r\n\r\n /** @internal */\r\n public static tileUploader?: CloudStorageTileUploader;\r\n\r\n private static _hubAccess: BackendHubAccess;\r\n /** @internal */\r\n public static setHubAccess(hubAccess: BackendHubAccess) { this._hubAccess = hubAccess; }\r\n\r\n /** Provides access to the IModelHub for this IModelHost\r\n * @beta\r\n */\r\n public static get hubAccess(): BackendHubAccess { return this._hubAccess; }\r\n\r\n private static _isValid = false;\r\n /** Returns true if IModelHost is started. */\r\n public static get isValid() { return this._isValid; }\r\n /** This method must be called before any iTwin.js services are used.\r\n * @param configuration Host configuration data.\r\n * Raises [[onAfterStartup]].\r\n * @see [[shutdown]].\r\n */\r\n public static async startup(configuration: IModelHostConfiguration = new IModelHostConfiguration()): Promise<void> {\r\n if (this._isValid)\r\n return; // we're already initialized\r\n this._isValid = true;\r\n\r\n if (IModelHost.sessionId === \"\")\r\n IModelHost.sessionId = Guid.createValue();\r\n\r\n this.authorizationClient = configuration.authorizationClient;\r\n\r\n this.logStartup();\r\n\r\n this.backendVersion = require(\"../../package.json\").version; // eslint-disable-line @typescript-eslint/no-var-requires\r\n initializeRpcBackend();\r\n\r\n if (this._platform === undefined) {\r\n try {\r\n this.loadNative();\r\n } catch (error) {\r\n Logger.logError(loggerCategory, \"Error registering/loading the native platform API\", () => (configuration));\r\n throw error;\r\n }\r\n }\r\n\r\n if (configuration.crashReportingConfig && configuration.crashReportingConfig.crashDir && !ProcessDetector.isElectronAppBackend && !ProcessDetector.isMobileAppBackend) {\r\n this.platform.setCrashReporting(configuration.crashReportingConfig);\r\n\r\n Logger.logTrace(loggerCategory, \"Configured crash reporting\", () => ({\r\n enableCrashDumps: configuration.crashReportingConfig?.enableCrashDumps,\r\n wantFullMemoryDumps: configuration.crashReportingConfig?.wantFullMemoryDumps,\r\n enableNodeReport: configuration.crashReportingConfig?.enableNodeReport,\r\n uploadToBentley: configuration.crashReportingConfig?.uploadToBentley,\r\n }));\r\n\r\n if (configuration.crashReportingConfig.enableNodeReport) {\r\n try {\r\n // node-report reports on V8 fatal errors and unhandled exceptions/Promise rejections.\r\n const nodereport = require(\"node-report/api\"); // eslint-disable-line @typescript-eslint/no-var-requires\r\n nodereport.setEvents(\"exception+fatalerror+apicall\");\r\n nodereport.setDirectory(configuration.crashReportingConfig.crashDir);\r\n nodereport.setVerbose(\"yes\");\r\n Logger.logTrace(loggerCategory, \"Configured native crash reporting (node-report)\");\r\n } catch (err) {\r\n Logger.logWarning(loggerCategory, \"node-report is not installed.\");\r\n }\r\n }\r\n }\r\n\r\n this.setupHostDirs(configuration);\r\n this._appWorkspace = new ITwinWorkspace(new ApplicationSettings(), configuration.workspace);\r\n\r\n BriefcaseManager.initialize(this._briefcaseCacheDir);\r\n\r\n [\r\n IModelReadRpcImpl,\r\n IModelTileRpcImpl,\r\n SnapshotIModelRpcImpl,\r\n WipRpcImpl,\r\n DevToolsRpcImpl,\r\n ].forEach((rpc) => rpc.register()); // register all of the RPC implementations\r\n\r\n [\r\n BisCoreSchema,\r\n GenericSchema,\r\n FunctionalSchema,\r\n ].forEach((schema) => schema.registerSchema()); // register all of the schemas\r\n\r\n if (undefined !== configuration.hubAccess)\r\n IModelHost._hubAccess = configuration.hubAccess;\r\n IModelHost.configuration = configuration;\r\n IModelHost.setupTileCache();\r\n\r\n this.platform.setUseTileCache(IModelHost.tileCacheService ? false : true);\r\n\r\n process.once(\"beforeExit\", IModelHost.shutdown);\r\n IModelHost.onAfterStartup.raiseEvent();\r\n }\r\n\r\n private static _briefcaseCacheDir: LocalDirName;\r\n\r\n private static logStartup() {\r\n if (!Logger.isEnabled(loggerCategory, LogLevel.Trace))\r\n return;\r\n\r\n // Extract the iModel details from environment - note this is very specific to Bentley hosted backends, but is quite useful for tracing\r\n let startupInfo: any = {};\r\n const serviceName = process.env.FABRIC_SERVICE_NAME;\r\n if (serviceName) {\r\n // e.g., fabric:/iModelWebViewer3.0/iModelJSGuest/1/08daaeb3-b56f-480b-9051-7efc834d18ae/512d971d-b641-4735-bb1c-c07ab3e44ce7/c1315fcce125ca40b2d405bb7809214daf8b4c85\r\n const serviceNameComponents = serviceName.split(\"/\");\r\n if (serviceNameComponents.length === 7) {\r\n startupInfo = {\r\n ...startupInfo,\r\n iTwinId: serviceNameComponents[4],\r\n iModelId: serviceNameComponents[5],\r\n changesetId: serviceNameComponents[6],\r\n };\r\n }\r\n }\r\n\r\n Logger.logTrace(loggerCategory, \"IModelHost.startup\", () => startupInfo);\r\n }\r\n\r\n private static setupHostDirs(configuration: IModelHostConfiguration) {\r\n const setupDir = (dir: LocalDirName) => {\r\n dir = path.normalize(dir);\r\n IModelJsFs.recursiveMkDirSync(dir);\r\n return dir;\r\n };\r\n this._cacheDir = setupDir(configuration.cacheDir ?? NativeLibrary.defaultCacheDir);\r\n this._briefcaseCacheDir = path.join(this._cacheDir, \"imodels\");\r\n }\r\n\r\n /** This method must be called when an iTwin.js host is shut down. Raises [[onBeforeShutdown]] */\r\n public static async shutdown(): Promise<void> {\r\n // NB: This method is set as a node listener where `this` is unbound\r\n if (!IModelHost._isValid)\r\n return;\r\n\r\n IModelHost._isValid = false;\r\n IModelHost.onBeforeShutdown.raiseEvent();\r\n IModelHost.configuration = undefined;\r\n IModelHost.tileCacheService = undefined;\r\n IModelHost.tileUploader = undefined;\r\n IModelHost.appWorkspace.close();\r\n IModelHost._appWorkspace = undefined;\r\n process.removeListener(\"beforeExit\", IModelHost.shutdown);\r\n }\r\n\r\n /**\r\n * Add or update a property that should be included in a crash report.\r\n * @param name The name of the property\r\n * @param value The value of the property\r\n * @alpha\r\n */\r\n public static setCrashReportProperty(name: string, value: string): void {\r\n assert(undefined !== this._platform);\r\n this._platform.setCrashReportProperty(name, value);\r\n }\r\n\r\n /**\r\n * Remove a previously defined property so that will not be included in a crash report.\r\n * @param name The name of the property\r\n * @alpha\r\n */\r\n public static removeCrashReportProperty(name: string): void {\r\n assert(undefined !== this._platform);\r\n this._platform.setCrashReportProperty(name, undefined);\r\n }\r\n\r\n /**\r\n * Get all properties that will be included in a crash report.\r\n * @alpha\r\n */\r\n public static getCrashReportProperties(): CrashReportingConfigNameValuePair[] {\r\n assert(undefined !== this._platform);\r\n return this._platform.getCrashReportProperties();\r\n }\r\n\r\n /** The directory where application assets may be found */\r\n public static get appAssetsDir(): string | undefined { return undefined !== IModelHost.configuration ? IModelHost.configuration.appAssetsDir : undefined; }\r\n\r\n /** The time, in milliseconds, for which [IModelTileRpcInterface.requestTileTreeProps]($common) should wait before returning a \"pending\" status.\r\n * @internal\r\n */\r\n public static get tileTreeRequestTimeout(): number {\r\n return undefined !== IModelHost.configuration ? IModelHost.configuration.tileTreeRequestTimeout : IModelHostConfiguration.defaultTileRequestTimeout;\r\n }\r\n /** The time, in milliseconds, for which [IModelTileRpcInterface.requestTileContent]($common) should wait before returning a \"pending\" status.\r\n * @internal\r\n */\r\n public static get tileContentRequestTimeout(): number {\r\n return undefined !== IModelHost.configuration ? IModelHost.configuration.tileContentRequestTimeout : IModelHostConfiguration.defaultTileRequestTimeout;\r\n }\r\n\r\n /** The backend will log when a tile took longer to load than this threshold in seconds. */\r\n public static get logTileLoadTimeThreshold(): number { return undefined !== IModelHost.configuration ? IModelHost.configuration.logTileLoadTimeThreshold : IModelHostConfiguration.defaultLogTileLoadTimeThreshold; }\r\n /** The backend will log when a tile is loaded with a size in bytes above this threshold. */\r\n public static get logTileSizeThreshold(): number { return undefined !== IModelHost.configuration ? IModelHost.configuration.logTileSizeThreshold : IModelHostConfiguration.defaultLogTileSizeThreshold; }\r\n\r\n /** Whether external tile caching is active.\r\n * @internal\r\n */\r\n public static get usingExternalTileCache(): boolean {\r\n return undefined !== IModelHost.tileCacheService;\r\n }\r\n\r\n /** Whether to restrict tile cache URLs by client IP address.\r\n * @internal\r\n */\r\n public static get restrictTileUrlsByClientIp(): boolean { return undefined !== IModelHost.configuration && (IModelHost.configuration.restrictTileUrlsByClientIp ? true : false); }\r\n\r\n /** Whether to compress cached tiles.\r\n * @internal\r\n */\r\n public static get compressCachedTiles(): boolean { return false !== IModelHost.configuration?.compressCachedTiles; }\r\n\r\n private static setupTileCache() {\r\n assert(undefined !== IModelHost.configuration);\r\n const config = IModelHost.configuration;\r\n const service = config.tileCacheService;\r\n const credentials = config.tileCacheAzureCredentials;\r\n\r\n if (!service && !credentials)\r\n return;\r\n\r\n IModelHost.tileUploader = new CloudStorageTileUploader();\r\n\r\n if (credentials && !service) {\r\n IModelHost.tileCacheService = new AzureBlobStorage(credentials);\r\n } else if (!credentials && service) {\r\n IModelHost.tileCacheService = service;\r\n } else {\r\n throw new IModelError(BentleyStatus.ERROR, \"Cannot use both Azure and custom cloud storage providers for tile cache.\");\r\n }\r\n }\r\n}\r\n\r\n/** Information about the platform on which the app is running. Also see [[KnownLocations]] and [[IModelJsFs]].\r\n * @public\r\n */\r\nexport class Platform {\r\n /** Get the name of the platform. */\r\n public static get platformName(): \"win32\" | \"linux\" | \"darwin\" | \"ios\" | \"android\" | \"uwp\" {\r\n return process.platform as any;\r\n }\r\n\r\n /** @internal */\r\n public static load(): typeof IModelJsNative {\r\n return ProcessDetector.isMobileAppBackend ? (process as any)._linkedBinding(\"iModelJsNative\") : NativeLibrary.load();\r\n }\r\n}\r\n\r\n/** Well known directories that may be used by the application. Also see [[Platform]]\r\n * @public\r\n */\r\nexport class KnownLocations {\r\n\r\n /** The directory where the imodeljs-native assets are stored. */\r\n public static get nativeAssetsDir(): string { return IModelHost.platform.DgnDb.getAssetsDir(); }\r\n\r\n /** The directory where the core-backend assets are stored. */\r\n public static get packageAssetsDir(): string {\r\n return path.join(__dirname, \"assets\");\r\n }\r\n\r\n /** The temporary directory. */\r\n public static get tmpdir(): string {\r\n return os.tmpdir();\r\n }\r\n}\r\n\r\n/** Extend this class to provide custom file name resolution behavior.\r\n * @note Only `tryResolveKey` and/or `tryResolveFileName` need to be overridden as the implementations of `resolveKey` and `resolveFileName` work for most purposes.\r\n * @see [[IModelHost.snapshotFileNameResolver]]\r\n * @public\r\n */\r\nexport abstract class FileNameResolver {\r\n /** Resolve a file name from the specified key.\r\n * @param _fileKey The key that identifies the file name in a `Map` or other similar data structure.\r\n * @returns The resolved file name or `undefined` if not found.\r\n */\r\n public tryResolveKey(_fileKey: string): string | undefined { return undefined; }\r\n /** Resolve a file name from the specified key.\r\n * @param fileKey The key that identifies the file name in a `Map` or other similar data structure.\r\n * @returns The resolved file name.\r\n * @throws [[IModelError]] if not found.\r\n */\r\n public resolveKey(fileKey: string): string {\r\n const resolvedFileName: string | undefined = this.tryResolveKey(fileKey);\r\n if (undefined === resolvedFileName) {\r\n throw new IModelError(IModelStatus.NotFound, `${fileKey} not resolved`);\r\n }\r\n return resolvedFileName;\r\n }\r\n /** Resolve the input file name, which may be a partial name, into a full path file name.\r\n * @param inFileName The partial file name.\r\n * @returns The resolved full path file name or `undefined` if not found.\r\n */\r\n public tryResolveFileName(inFileName: string): string | undefined { return inFileName; }\r\n /** Resolve the input file name, which may be a partial name, into a full path file name.\r\n * @param inFileName The partial file name.\r\n * @returns The resolved full path file name.\r\n * @throws [[IModelError]] if not found.\r\n */\r\n public resolveFileName(inFileName: string): string {\r\n const resolvedFileName: string | undefined = this.tryResolveFileName(inFileName);\r\n if (undefined === resolvedFileName) {\r\n throw new IModelError(IModelStatus.NotFound, `${inFileName} not resolved`);\r\n }\r\n return resolvedFileName;\r\n }\r\n}\r\n"]}
@@ -2,26 +2,41 @@
2
2
  * @module Workspace
3
3
  */
4
4
  /// <reference types="node" />
5
- import { BlobCacheProps, BlobContainerProps, DaemonProps } from "@bentley/imodeljs-native";
5
+ import { DaemonProps } from "@bentley/imodeljs-native";
6
6
  import { LocalFileName } from "@itwin/core-common";
7
7
  /** @beta */
8
8
  export declare namespace CloudSqlite {
9
- type DbAlias = string;
10
- type AccountProps = BlobCacheProps;
11
- type ContainerProps = BlobContainerProps;
12
- type AccessProps = AccountProps & ContainerProps;
13
- type DownloadProps = AccessProps & {
14
- onProgress?: (loaded: number, total: number) => number;
15
- };
9
+ type DbName = string;
10
+ interface AccountProps {
11
+ /** blob storage module: e.g. "azure", "google", "aws". May also include URI style parameters. */
12
+ storageType: string;
13
+ /** blob store account name. */
14
+ accountName: string;
15
+ }
16
+ interface ContainerProps {
17
+ /** the name of the container. */
18
+ containerId: string;
19
+ /** SAS token that grants access to the container. */
20
+ sasToken: string;
21
+ }
22
+ type ContainerAccessProps = AccountProps & ContainerProps;
16
23
  type Logger = (stream: NodeJS.ReadableStream) => void;
17
24
  type ProcessProps = DaemonProps & AccountProps & {
18
25
  stdoutLogger?: Logger;
19
26
  stderrLogger?: Logger;
20
27
  };
21
- interface DbProps {
22
- dbAlias: DbAlias;
28
+ interface DbNameProp {
29
+ dbName: DbName;
30
+ }
31
+ interface DbProps extends DbNameProp {
23
32
  localFile: LocalFileName;
24
33
  }
34
+ type TransferDirection = "upload" | "download";
35
+ interface TransferProgress {
36
+ onProgress?: (loaded: number, total: number) => number;
37
+ }
38
+ type TransferProps = ContainerAccessProps & TransferProgress;
39
+ type TransferDbProps = TransferProps & DbProps;
25
40
  }
26
41
  /** @beta */
27
42
  export declare class CloudSqlite {
@@ -31,11 +46,16 @@ export declare class CloudSqlite {
31
46
  static get isRunning(): boolean;
32
47
  static startProcess(props: CloudSqlite.ProcessProps): Promise<void>;
33
48
  static stopProcess(): void;
34
- static attach(dbAlias: CloudSqlite.DbAlias, props: CloudSqlite.AccessProps): Promise<string>;
35
- static create(props: CloudSqlite.AccessProps): Promise<void>;
36
- static downloadDb(db: CloudSqlite.DbProps, props: CloudSqlite.DownloadProps): Promise<void>;
37
- static copyDb(oldVersion: string, newVersion: string, props: CloudSqlite.AccessProps): Promise<void>;
38
- static uploadDb(db: CloudSqlite.DbProps, props: CloudSqlite.AccessProps): Promise<void>;
39
- static deleteDb(db: CloudSqlite.DbProps, props: CloudSqlite.AccessProps): Promise<void>;
49
+ private static toBlobAccountProps;
50
+ private static toBlobAccessProps;
51
+ static attach(dbAlias: CloudSqlite.DbName, props: CloudSqlite.ContainerAccessProps): Promise<string>;
52
+ static initializeContainer(props: CloudSqlite.ContainerAccessProps): Promise<void>;
53
+ static transferDb(direction: CloudSqlite.TransferDirection, props: CloudSqlite.TransferDbProps): Promise<void>;
54
+ static uploadDb(props: CloudSqlite.TransferDbProps): Promise<void>;
55
+ static downloadDb(props: CloudSqlite.TransferDbProps): Promise<void>;
56
+ static copyDb(oldVersion: string, newVersion: string, props: CloudSqlite.ContainerAccessProps): Promise<void>;
57
+ static deleteDb(props: CloudSqlite.ContainerAccessProps & {
58
+ dbName: string;
59
+ }): Promise<void>;
40
60
  }
41
61
  //# sourceMappingURL=CloudSqlite.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"CloudSqlite.d.ts","sourceRoot":"","sources":["../../../src/workspace/CloudSqlite.ts"],"names":[],"mappings":"AAIA;;GAEG;;AAEH,OAAO,EAAE,cAAc,EAAE,kBAAkB,EAAoC,WAAW,EAAE,MAAM,0BAA0B,CAAC;AAE7H,OAAO,EAAe,aAAa,EAAE,MAAM,oBAAoB,CAAC;AAIhE,YAAY;AACZ,yBAAiB,WAAW,CAAC;IAC3B,KAAY,OAAO,GAAG,MAAM,CAAC;IAC7B,KAAY,YAAY,GAAG,cAAc,CAAC;IAC1C,KAAY,cAAc,GAAG,kBAAkB,CAAC;IAChD,KAAY,WAAW,GAAG,YAAY,GAAG,cAAc,CAAC;IACxD,KAAY,aAAa,GAAG,WAAW,GAAG;QAAE,UAAU,CAAC,EAAE,CAAC,MAAM,EAAE,MAAM,EAAE,KAAK,EAAE,MAAM,KAA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EmB,YAAY,CAAC,KAAK,EAAE,WAAW,CAAC,YAAY;WAUlD,WAAW;IAQzB,OAAO,CAAC,MAAM,CAAC,kBAAkB;IAMjC,OAAO,CAAC,MAAM,CAAC,iBAAiB;WAOZ,MAAM,CAAC,OAAO,EAAE,WAAW,CAAC,MAAM,EAAE,KAAK,EAAE,WAAW,CAAC,oBAAoB;WA0B3E,mBAAmB,CAAC,KAAK,EAAE,WAAW,CAAC,oBAAoB;WAM3D,UAAU,CAAC,SAAS,EAAE,WAAW,CAAC,iBAAiB,EAAE,KAAK,EAAE,WAAW,CAAC,eAAe;WAyBvF,QAAQ,CAAC,KAAK,EAAE,WAAW,CAAC,eAAe;WAI3C,UAAU,CAAC,KAAK,EAAE,WAAW,CAAC,eAAe;WAI7C,MAAM,CAAC,UAAU,EAAE,MAAM,EAAE,UAAU,EAAE,MAAM,EAAE,KAAK,EAAE,WAAW,CAAC,oBAAoB;WAMtF,QAAQ,CAAC,KAAK,EAAE,WAAW,CAAC,oBAAoB,GAAG;QAAE,MAAM,EAAE,MAAM,CAAA;KAAE;CAK1F"}
@@ -26,7 +26,7 @@ class CloudSqlite {
26
26
  static async startProcess(props) {
27
27
  if (this.isRunning)
28
28
  return;
29
- this.cloudProcess = imodeljs_native_1.BlobDaemon.start(props);
29
+ this.cloudProcess = imodeljs_native_1.BlobDaemon.start(this.toBlobAccountProps(props));
30
30
  // set up a listener to kill the containerProcess when we shut down
31
31
  this.removeShutdownListener = IModelHost_1.IModelHost.onBeforeShutdown.addOnce(() => this.killProcess());
32
32
  }
@@ -37,6 +37,19 @@ class CloudSqlite {
37
37
  }
38
38
  this.killProcess();
39
39
  }
40
+ static toBlobAccountProps(props) {
41
+ return {
42
+ user: props.accountName,
43
+ ...props,
44
+ };
45
+ }
46
+ static toBlobAccessProps(props) {
47
+ return {
48
+ container: props.containerId,
49
+ auth: props.sasToken,
50
+ ...this.toBlobAccountProps(props),
51
+ };
52
+ }
40
53
  static async attach(dbAlias, props) {
41
54
  const args = {
42
55
  log: "meh",
@@ -50,7 +63,7 @@ class CloudSqlite {
50
63
  // spawnOptions: {
51
64
  // stdio: "inherit",
52
65
  // },
53
- ...props,
66
+ ...this.toBlobAccessProps(props),
54
67
  };
55
68
  if (!this.isRunning)
56
69
  await this.startProcess(args);
@@ -59,48 +72,49 @@ class CloudSqlite {
59
72
  throw new Error(`Cannot attach: ${stat.errMsg}`);
60
73
  return imodeljs_native_1.BlobDaemon.getDbFileName(args);
61
74
  }
62
- static async create(props) {
63
- const stat = await imodeljs_native_1.BlobDaemon.command("create", { ...props, dbAlias: "" });
75
+ static async initializeContainer(props) {
76
+ const stat = await imodeljs_native_1.BlobDaemon.command("create", { ...this.toBlobAccessProps(props), dbAlias: "" });
64
77
  if (stat.result !== core_bentley_1.DbResult.BE_SQLITE_OK)
65
- throw new Error(`Cannot create container: ${stat.errMsg}`);
78
+ throw new Error(`Cannot initialize container: ${stat.errMsg}`);
66
79
  }
67
- static async downloadDb(db, props) {
68
- const downloader = new IModelHost_1.IModelHost.platform.CloudDbTransfer({ direction: "download", ...db, ...props });
80
+ static async transferDb(direction, props) {
81
+ const transfer = new IModelHost_1.IModelHost.platform.CloudDbTransfer({ direction, ...props, dbAlias: props.dbName, ...this.toBlobAccessProps(props) });
69
82
  let timer;
70
83
  try {
71
84
  let total = 0;
72
85
  const onProgress = props.onProgress;
73
86
  if (onProgress) {
74
87
  timer = setInterval(async () => {
75
- const progress = downloader.getProgress();
88
+ const progress = transfer.getProgress();
76
89
  total = progress.total;
77
90
  if (onProgress(progress.loaded, progress.total))
78
- downloader.cancelTransfer();
91
+ transfer.cancelTransfer();
79
92
  }, 250);
80
93
  }
81
- await downloader.promise;
94
+ await transfer.promise;
82
95
  onProgress === null || onProgress === void 0 ? void 0 : onProgress(total, total); // make sure we call progress func one last time when download completes
83
96
  }
84
97
  catch (err) {
85
- throw (err.message === "cancelled") ? new core_common_1.IModelError(core_bentley_1.BriefcaseStatus.DownloadCancelled, "download cancelled") : err;
98
+ throw (err.message === "cancelled") ? new core_common_1.IModelError(core_bentley_1.BriefcaseStatus.DownloadCancelled, `${direction} cancelled`) : err;
86
99
  }
87
100
  finally {
88
101
  if (timer)
89
102
  clearInterval(timer);
90
103
  }
91
104
  }
105
+ static async uploadDb(props) {
106
+ return this.transferDb("upload", props);
107
+ }
108
+ static async downloadDb(props) {
109
+ return this.transferDb("download", props);
110
+ }
92
111
  static async copyDb(oldVersion, newVersion, props) {
93
- const stat = await imodeljs_native_1.BlobDaemon.command("copy", { dbAlias: oldVersion, toAlias: newVersion, ...props });
112
+ const stat = await imodeljs_native_1.BlobDaemon.command("copy", { dbAlias: oldVersion, toAlias: newVersion, ...this.toBlobAccessProps(props) });
94
113
  if (stat.result !== core_bentley_1.DbResult.BE_SQLITE_OK)
95
114
  throw new Error(`Cannot copy db: ${stat.errMsg}`);
96
115
  }
97
- static async uploadDb(db, props) {
98
- const stat = await imodeljs_native_1.BlobDaemon.command("upload", { ...db, ...props });
99
- if (stat.result !== core_bentley_1.DbResult.BE_SQLITE_OK)
100
- throw new Error(`Cannot upload db: ${stat.errMsg}`);
101
- }
102
- static async deleteDb(db, props) {
103
- const stat = await imodeljs_native_1.BlobDaemon.command("delete", { ...db, ...props });
116
+ static async deleteDb(props) {
117
+ const stat = await imodeljs_native_1.BlobDaemon.command("delete", { dbAlias: props.dbName, ...this.toBlobAccessProps(props) });
104
118
  if (stat.result !== core_bentley_1.DbResult.BE_SQLITE_OK)
105
119
  throw new Error(`Cannot delete db: ${stat.errMsg}`);
106
120
  }
@@ -1 +1 @@
1
- {"version":3,"file":"CloudSqlite.js","sourceRoot":"","sources":["../../../src/workspace/CloudSqlite.ts"],"names":[],"mappings":";AAAA;;;+FAG+F;AAC/F;;GAEG;;;AAEH,8DAA6H;AAC7H,sDAAgE;AAChE,oDAAgE;AAEhE,8CAA2C;AAc3C,YAAY;AACZ,MAAa,WAAW;IAGd,MAAM,CAAC,WAAW;QACxB,IAAI,IAAI,CAAC,YAAY,EAAE;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,CAAC;QACrE,IAAI,IAAI,CAAC,MAAM,KAAK,uBAAQ,CAAC,YAAY;YACvC,MAAM,IAAI,KAAK,CAAC,qBAAqB,IAAI,CAAC,MAAM,EAAE,CAAC,CAAC;IACxD,CAAC;CACF;AA1GD,kCA0GC","sourcesContent":["/*---------------------------------------------------------------------------------------------\r\n* Copyright (c) Bentley Systems, Incorporated. All rights reserved.\r\n* See LICENSE.md in the project root for license terms and full copyright notice.\r\n*--------------------------------------------------------------------------------------------*/\r\n/** @packageDocumentation\r\n * @module Workspace\r\n */\r\n\r\nimport { BlobCacheProps, BlobContainerProps, BlobDaemon, BlobDaemonCommandArg, DaemonProps } from \"@bentley/imodeljs-native\";\r\nimport { BriefcaseStatus, DbResult } from \"@itwin/core-bentley\";\r\nimport { IModelError, LocalFileName } from \"@itwin/core-common\";\r\nimport { ChildProcess } from \"child_process\";\r\nimport { IModelHost } from \"../IModelHost\";\r\n\r\n/** @beta */\r\nexport namespace CloudSqlite {\r\n export type DbAlias = string;\r\n export type AccountProps = BlobCacheProps;\r\n export type ContainerProps = BlobContainerProps;\r\n export type AccessProps = AccountProps & ContainerProps;\r\n export type DownloadProps = AccessProps & { onProgress?: (loaded: number, total: number) => number };\r\n export type Logger = (stream: NodeJS.ReadableStream) => void;\r\n export type ProcessProps = DaemonProps & AccountProps & { stdoutLogger?: Logger, stderrLogger?: Logger };\r\n export interface DbProps { dbAlias: DbAlias, localFile: LocalFileName }\r\n}\r\n\r\n/** @beta */\r\nexport class CloudSqlite {\r\n private static cloudProcess?: ChildProcess;\r\n private static removeShutdownListener?: VoidFunction;\r\n private static killProcess() {\r\n if (this.cloudProcess) {\r\n this.cloudProcess.kill();\r\n this.cloudProcess = undefined;\r\n }\r\n }\r\n\r\n public static get isRunning() {\r\n return undefined !== this.cloudProcess;\r\n }\r\n\r\n public static async startProcess(props: CloudSqlite.ProcessProps) {\r\n if (this.isRunning)\r\n return;\r\n\r\n this.cloudProcess = BlobDaemon.start(props);\r\n\r\n // set up a listener to kill the containerProcess when we shut down\r\n this.removeShutdownListener = IModelHost.onBeforeShutdown.addOnce(() => this.killProcess());\r\n }\r\n\r\n public static stopProcess() {\r\n if (this.removeShutdownListener) {\r\n this.removeShutdownListener();\r\n this.removeShutdownListener = undefined;\r\n }\r\n this.killProcess();\r\n }\r\n\r\n public static async attach(dbAlias: CloudSqlite.DbAlias, props: CloudSqlite.AccessProps) {\r\n const args: BlobDaemonCommandArg & CloudSqlite.ProcessProps = {\r\n log: \"meh\",\r\n maxCacheSize: \"10G\",\r\n pollTime: 600,\r\n addr: \"127.0.0.2\",\r\n portNumber: 2030,\r\n persistAcrossSessions: true,\r\n lazy: false,\r\n dbAlias,\r\n // spawnOptions: {\r\n // stdio: \"inherit\",\r\n // },\r\n ...props,\r\n };\r\n\r\n if (!this.isRunning)\r\n await this.startProcess(args);\r\n\r\n const stat = await BlobDaemon.command(\"attach\", args);\r\n if (stat.result !== DbResult.BE_SQLITE_OK)\r\n throw new Error(`Cannot attach: ${stat.errMsg}`);\r\n\r\n return BlobDaemon.getDbFileName(args);\r\n }\r\n\r\n public static async create(props: CloudSqlite.AccessProps) {\r\n const stat = await BlobDaemon.command(\"create\", { ...props, dbAlias: \"\" });\r\n if (stat.result !== DbResult.BE_SQLITE_OK)\r\n throw new Error(`Cannot create container: ${stat.errMsg}`);\r\n }\r\n\r\n public static async downloadDb(db: CloudSqlite.DbProps, props: CloudSqlite.DownloadProps) {\r\n const downloader = new IModelHost.platform.CloudDbTransfer({ direction: \"download\", ...db, ...props });\r\n\r\n let timer: NodeJS.Timeout | undefined;\r\n try {\r\n let total = 0;\r\n const onProgress = props.onProgress;\r\n if (onProgress) {\r\n timer = setInterval(async () => { // set an interval timer to show progress every 250ms\r\n const progress = downloader.getProgress();\r\n total = progress.total;\r\n if (onProgress(progress.loaded, progress.total))\r\n downloader.cancelTransfer();\r\n }, 250);\r\n }\r\n await downloader.promise;\r\n onProgress?.(total, total); // make sure we call progress func one last time when download completes\r\n } catch (err: any) {\r\n throw (err.message === \"cancelled\") ? new IModelError(BriefcaseStatus.DownloadCancelled, \"download cancelled\") : err;\r\n } finally {\r\n if (timer)\r\n clearInterval(timer);\r\n }\r\n }\r\n\r\n public static async copyDb(oldVersion: string, newVersion: string, props: CloudSqlite.AccessProps) {\r\n const stat = await BlobDaemon.command(\"copy\", { dbAlias: oldVersion, toAlias: newVersion, ...props });\r\n if (stat.result !== DbResult.BE_SQLITE_OK)\r\n throw new Error(`Cannot copy db: ${stat.errMsg}`);\r\n }\r\n\r\n public static async uploadDb(db: CloudSqlite.DbProps, props: CloudSqlite.AccessProps) {\r\n const stat = await BlobDaemon.command(\"upload\", { ...db, ...props });\r\n if (stat.result !== DbResult.BE_SQLITE_OK)\r\n throw new Error(`Cannot upload db: ${stat.errMsg}`);\r\n }\r\n\r\n public static async deleteDb(db: CloudSqlite.DbProps, props: CloudSqlite.AccessProps) {\r\n const stat = await BlobDaemon.command(\"delete\", { ...db, ...props });\r\n if (stat.result !== DbResult.BE_SQLITE_OK)\r\n throw new Error(`Cannot delete db: ${stat.errMsg}`);\r\n }\r\n}\r\n"]}
1
+ {"version":3,"file":"CloudSqlite.js","sourceRoot":"","sources":["../../../src/workspace/CloudSqlite.ts"],"names":[],"mappings":";AAAA;;;+FAG+F;AAC/F;;GAEG;;;AAGH,8DAAyF;AACzF,sDAAgE;AAChE,oDAAgE;AAChE,8CAA2C;AA6B3C,YAAY;AACZ,MAAa,WAAW;IAGd,MAAM,CAAC,WAAW;QACxB,IAAI,IAAI,CAAC,YAAY,EAAE;YACrB,IAAI,CAAC,YAAY,CAAC,IAAI,EAAE,CAAC;YACzB,IAAI,CAAC,YAAY,GAAG,SAAS,CAAC;SAC/B;IACH,CAAC;IAEM,MAAM,KAAK,SAAS;QACzB,OAAO,SAAS,KAAK,IAAI,CAAC,YAAY,CAAC;IACzC,CAAC;IAEM,MAAM,CAAC,KAAK,CAAC,YAAY,CAAC,KAA+B;QAC9D,IAAI,IAAI,CAAC,SAAS;Y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tD,CAAC;IAEM,MAAM,CAAC,KAAK,CAAC,QAAQ,CAAC,KAA4D;QACvF,MAAM,IAAI,GAAG,MAAM,4BAAU,CAAC,OAAO,CAAC,QAAQ,EAAE,EAAE,OAAO,EAAE,KAAK,CAAC,MAAM,EAAE,GAAG,IAAI,CAAC,iBAAiB,CAAC,KAAK,CAAC,EAAE,CAAC,CAAC;QAC7G,IAAI,IAAI,CAAC,MAAM,KAAK,uBAAQ,CAAC,YAAY;YACvC,MAAM,IAAI,KAAK,CAAC,qBAAqB,IAAI,CAAC,MAAM,EAAE,CAAC,CAAC;IACxD,CAAC;CACF;AAzHD,kCAyHC","sourcesContent":["/*---------------------------------------------------------------------------------------------\r\n* Copyright (c) Bentley Systems, Incorporated. All rights reserved.\r\n* See LICENSE.md in the project root for license terms and full copyright notice.\r\n*--------------------------------------------------------------------------------------------*/\r\n/** @packageDocumentation\r\n * @module Workspace\r\n */\r\n\r\nimport { ChildProcess } from \"child_process\";\r\nimport { BlobDaemon, BlobDaemonCommandArg, DaemonProps } from \"@bentley/imodeljs-native\";\r\nimport { BriefcaseStatus, DbResult } from \"@itwin/core-bentley\";\r\nimport { IModelError, LocalFileName } from \"@itwin/core-common\";\r\nimport { IModelHost } from \"../IModelHost\";\r\n\r\n/** @beta */\r\nexport namespace CloudSqlite {\r\n export type DbName = string;\r\n\r\n export interface AccountProps {\r\n /** blob storage module: e.g. \"azure\", \"google\", \"aws\". May also include URI style parameters. */\r\n storageType: string;\r\n /** blob store account name. */\r\n accountName: string;\r\n }\r\n export interface ContainerProps {\r\n /** the name of the container. */\r\n containerId: string;\r\n /** SAS token that grants access to the container. */\r\n sasToken: string;\r\n }\r\n export type ContainerAccessProps = AccountProps & ContainerProps;\r\n export type Logger = (stream: NodeJS.ReadableStream) => void;\r\n export type ProcessProps = DaemonProps & AccountProps & { stdoutLogger?: Logger, stderrLogger?: Logger };\r\n export interface DbNameProp { dbName: DbName }\r\n export interface DbProps extends DbNameProp { localFile: LocalFileName }\r\n export type TransferDirection = \"upload\" | \"download\";\r\n export interface TransferProgress { onProgress?: (loaded: number, total: number) => number }\r\n export type TransferProps = ContainerAccessProps & TransferProgress;\r\n export type TransferDbProps = TransferProps & DbProps;\r\n}\r\n\r\n/** @beta */\r\nexport class CloudSqlite {\r\n private static cloudProcess?: ChildProcess;\r\n private static removeShutdownListener?: VoidFunction;\r\n private static killProcess() {\r\n if (this.cloudProcess) {\r\n this.cloudProcess.kill();\r\n this.cloudProcess = undefined;\r\n }\r\n }\r\n\r\n public static get isRunning() {\r\n return undefined !== this.cloudProcess;\r\n }\r\n\r\n public static async startProcess(props: CloudSqlite.ProcessProps) {\r\n if (this.isRunning)\r\n return;\r\n\r\n this.cloudProcess = BlobDaemon.start(this.toBlobAccountProps(props));\r\n\r\n // set up a listener to kill the containerProcess when we shut down\r\n this.removeShutdownListener = IModelHost.onBeforeShutdown.addOnce(() => this.killProcess());\r\n }\r\n\r\n public static stopProcess() {\r\n if (this.removeShutdownListener) {\r\n this.removeShutdownListener();\r\n this.removeShutdownListener = undefined;\r\n }\r\n this.killProcess();\r\n }\r\n\r\n private static toBlobAccountProps(props: CloudSqlite.AccountProps) {\r\n return {\r\n user: props.accountName,\r\n ...props,\r\n };\r\n }\r\n private static toBlobAccessProps(props: CloudSqlite.ContainerAccessProps) {\r\n return {\r\n container: props.containerId,\r\n auth: props.sasToken,\r\n ...this.toBlobAccountProps(props),\r\n };\r\n }\r\n public static async attach(dbAlias: CloudSqlite.DbName, props: CloudSqlite.ContainerAccessProps) {\r\n const args: BlobDaemonCommandArg & CloudSqlite.ProcessProps = {\r\n log: \"meh\",\r\n maxCacheSize: \"10G\",\r\n pollTime: 600,\r\n addr: \"127.0.0.2\",\r\n portNumber: 2030,\r\n persistAcrossSessions: true,\r\n lazy: false,\r\n dbAlias,\r\n // spawnOptions: {\r\n // stdio: \"inherit\",\r\n // },\r\n ...this.toBlobAccessProps(props),\r\n };\r\n\r\n if (!this.isRunning)\r\n await this.startProcess(args);\r\n\r\n const stat = await BlobDaemon.command(\"attach\", args);\r\n if (stat.result !== DbResult.BE_SQLITE_OK)\r\n throw new Error(`Cannot attach: ${stat.errMsg}`);\r\n\r\n return BlobDaemon.getDbFileName(args);\r\n }\r\n\r\n public static async initializeContainer(props: CloudSqlite.ContainerAccessProps) {\r\n const stat = await BlobDaemon.command(\"create\", { ...this.toBlobAccessProps(props), dbAlias: \"\" });\r\n if (stat.result !== DbResult.BE_SQLITE_OK)\r\n throw new Error(`Cannot initialize container: ${stat.errMsg}`);\r\n }\r\n\r\n public static async transferDb(direction: CloudSqlite.TransferDirection, props: CloudSqlite.TransferDbProps) {\r\n const transfer = new IModelHost.platform.CloudDbTransfer({ direction, ...props, dbAlias: props.dbName, ...this.toBlobAccessProps(props) });\r\n\r\n let timer: NodeJS.Timeout | undefined;\r\n try {\r\n let total = 0;\r\n const onProgress = props.onProgress;\r\n if (onProgress) {\r\n timer = setInterval(async () => { // set an interval timer to show progress every 250ms\r\n const progress = transfer.getProgress();\r\n total = progress.total;\r\n if (onProgress(progress.loaded, progress.total))\r\n transfer.cancelTransfer();\r\n }, 250);\r\n }\r\n await transfer.promise;\r\n onProgress?.(total, total); // make sure we call progress func one last time when download completes\r\n } catch (err: any) {\r\n throw (err.message === \"cancelled\") ? new IModelError(BriefcaseStatus.DownloadCancelled, `${direction} cancelled`) : err;\r\n } finally {\r\n if (timer)\r\n clearInterval(timer);\r\n }\r\n }\r\n\r\n public static async uploadDb(props: CloudSqlite.TransferDbProps) {\r\n return this.transferDb(\"upload\", props);\r\n }\r\n\r\n public static async downloadDb(props: CloudSqlite.TransferDbProps) {\r\n return this.transferDb(\"download\", props);\r\n }\r\n\r\n public static async copyDb(oldVersion: string, newVersion: string, props: CloudSqlite.ContainerAccessProps) {\r\n const stat = await BlobDaemon.command(\"copy\", { dbAlias: oldVersion, toAlias: newVersion, ...this.toBlobAccessProps(props) });\r\n if (stat.result !== DbResult.BE_SQLITE_OK)\r\n throw new Error(`Cannot copy db: ${stat.errMsg}`);\r\n }\r\n\r\n public static async deleteDb(props: CloudSqlite.ContainerAccessProps & { dbName: string }) {\r\n const stat = await BlobDaemon.command(\"delete\", { dbAlias: props.dbName, ...this.toBlobAccessProps(props) });\r\n if (stat.result !== DbResult.BE_SQLITE_OK)\r\n throw new Error(`Cannot delete db: ${stat.errMsg}`);\r\n }\r\n}\r\n"]}