@itwin/core-backend 4.5.0-dev.7 → 4.5.0-dev.9
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.
- package/CHANGELOG.md +21 -1
- package/lib/cjs/BackendHubAccess.d.ts +1 -1
- package/lib/cjs/BackendHubAccess.d.ts.map +1 -1
- package/lib/cjs/BackendHubAccess.js.map +1 -1
- package/lib/cjs/CheckpointManager.d.ts +4 -3
- package/lib/cjs/CheckpointManager.d.ts.map +1 -1
- package/lib/cjs/CheckpointManager.js +37 -28
- package/lib/cjs/CheckpointManager.js.map +1 -1
- package/lib/cjs/CloudSqlite.d.ts +3 -1
- package/lib/cjs/CloudSqlite.d.ts.map +1 -1
- package/lib/cjs/CloudSqlite.js +2 -2
- package/lib/cjs/CloudSqlite.js.map +1 -1
- package/lib/cjs/IModelDb.d.ts +14 -23
- package/lib/cjs/IModelDb.d.ts.map +1 -1
- package/lib/cjs/IModelDb.js +25 -27
- package/lib/cjs/IModelDb.js.map +1 -1
- package/lib/cjs/IpcHost.d.ts.map +1 -1
- package/lib/cjs/IpcHost.js +3 -0
- package/lib/cjs/IpcHost.js.map +1 -1
- package/lib/cjs/rpc-impl/RpcBriefcaseUtility.d.ts.map +1 -1
- package/lib/cjs/rpc-impl/RpcBriefcaseUtility.js +12 -13
- package/lib/cjs/rpc-impl/RpcBriefcaseUtility.js.map +1 -1
- package/package.json +12 -12
package/lib/cjs/IpcHost.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"IpcHost.d.ts","sourceRoot":"","sources":["../../src/IpcHost.ts"],"names":[],"mappings":"AAIA;;GAEG;AAIH,OAAO,EACgC,yBAAyB,EAC7B,mBAAmB,EAAmB,WAAW,EAAE,gBAAgB,
|
|
1
|
+
{"version":3,"file":"IpcHost.d.ts","sourceRoot":"","sources":["../../src/IpcHost.ts"],"names":[],"mappings":"AAIA;;GAEG;AAIH,OAAO,EACgC,yBAAyB,EA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BAAiB,CAAC,CAAC,SAAS,MAAM,mBAAmB,EAAE,UAAU,EAAE,CAAC,EAAE,GAAG,IAAI,EAAE,UAAU,CAAC,mBAAmB,CAAC,CAAC,CAAC,CAAC;IAI/H,gBAAgB;WACF,UAAU,CAAC,CAAC,SAAS,MAAM,gBAAgB,EAAE,SAAS,EAAE,WAAW,GAAG,YAAY,EAAE,UAAU,EAAE,CAAC,EAAE,GAAG,IAAI,EAAE,UAAU,CAAC,gBAAgB,CAAC,CAAC,CAAC,CAAC;IAIzJ,gBAAgB;WACF,kBAAkB,CAAC,CAAC,SAAS,MAAM,yBAAyB,EAAE,SAAS,EAAE,WAAW,GAAG,YAAY,EAAE,UAAU,EAAE,CAAC,EAAE,GAAG,IAAI,EAAE,UAAU,CAAC,yBAAyB,CAAC,CAAC,CAAC,CAAC;IAInL;;;;OAIG;WACiB,OAAO,CAAC,GAAG,CAAC,EAAE,WAAW,GAAG,OAAO,CAAC,IAAI,CAAC;IAY7D,mEAAmE;WAC/C,QAAQ,IAAI,OAAO,CAAC,IAAI,CAAC;CAI9C;AAED;;;;;;;;;;;GAWG;AACH,8BAAsB,UAAU;IAC9B;;;;;;OAMG;IACH,aAAoB,WAAW,IAAI,MAAM,CAAC;IAE1C;;;;;OAKG;WACW,QAAQ,IAAI,cAAc;CAuBzC;AAkID;;;GAGG;AACH,wBAAgB,wBAAwB,CAAC,IAAI,EAAE,gBAAgB,EAAE,UAAU,EAAE,MAAM,cAAc,EAAE,gBAAgB,CAAC,EAAE,MAAM,GAAG,gBAAgB,CAa9I"}
|
package/lib/cjs/IpcHost.js
CHANGED
|
@@ -175,6 +175,9 @@ class IpcAppHandler extends IpcHandler {
|
|
|
175
175
|
const db = await IModelDb_1.BriefcaseDb.open(args);
|
|
176
176
|
return db.toJSON();
|
|
177
177
|
}
|
|
178
|
+
async openCheckpoint(checkpoint) {
|
|
179
|
+
return (await IModelDb_1.SnapshotDb.openCheckpoint(checkpoint)).getConnectionProps();
|
|
180
|
+
}
|
|
178
181
|
async openStandalone(filePath, openMode, opts) {
|
|
179
182
|
return IModelDb_1.StandaloneDb.openFile(filePath, openMode, opts).getConnectionProps();
|
|
180
183
|
}
|
package/lib/cjs/IpcHost.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"IpcHost.js","sourceRoot":"","sources":["../../src/IpcHost.ts"],"names":[],"mappings":";AAAA;;;+FAG+F;AAC/F;;GAEG;;;AAGH,sDAAqG;AACrG,oDAI4B;AAC5B,2DAAuE;AACvE,yCAAiE;AACjE,6CAA6D;AAC7D,oEAAyE;AAmBzE;;;;GAIG;AACH,MAAa,OAAO;IAGlB,2EAA2E;IACnE,MAAM,KAAK,GAAG,KAAuB,OAAO,IAAI,CAAC,IAAK,CAAC,CAAC,CAAC,CAAC,+DAA+D;IACjI,gIAAgI;IACzH,MAAM,KAAK,OAAO,KAAc,OAAO,SAAS,KAAK,IAAI,CAAC,IAAI,CAAC,CAAC,CAAC;IAExE;;;;OAIG;IACI,MAAM,CAAC,IAAI,CAAC,OAAe,EAAE,GAAG,IAAW;QAChD,IAAI,CAAC,GAAG,CAAC,IAAI,CAAC,IAAA,0BAAY,EAAC,OAAO,CAAC,EAAE,GAAG,IAAI,CAAC,CAAC;IAChD,CAAC;IAED;;;;;OAKG;IACI,MAAM,CAAC,MAAM,CAAC,OAAe,EAAE,OAAyC;QAC7E,OAAO,IAAI,CAAC,GAAG,CAAC,MAAM,CAAC,IAAA,0BAAY,EAAC,OAAO,CAAC,EAAE,OAAO,CAAC,CAAC;IACzD,CAAC;IACD;;;;;OAKG;IACI,MAAM,CAAC,WAAW,CAAC,OAAe,EAAE,QAAqB;QAC9D,OAAO,IAAI,CAAC,GAAG,CAAC,WAAW,CAAC,IAAA,0BAAY,EAAC,OAAO,CAAC,EAAE,QAAQ,CAAC,CAAC;IAC/D,CAAC;IACD;;;;OAIG;IACI,MAAM,CAAC,cAAc,CAAC,OAAe,EAAE,QAAqB;QACjE,IAAI,CAAC,G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,YAAY,CAAC,GAAW;QACnC,OAAO,mBAAQ,CAAC,SAAS,CAAC,GAAG,CAAC,CAAC,QAAQ,CAAC,YAAY,EAAE,CAAC;IACzD,CAAC;IACM,KAAK,CAAC,iBAAiB,CAAC,GAAW;QACxC,OAAO,mBAAQ,CAAC,SAAS,CAAC,GAAG,CAAC,CAAC,QAAQ,CAAC,iBAAiB,EAAE,CAAC;IAC9D,CAAC;IAEM,KAAK,CAAC,gBAAgB,CAAC,IAAkB;QAC9C,OAAO,uBAAU,CAAC,QAAQ,CAAC,gBAAgB,CAAC,IAAI,CAAC,CAAC;IACpD,CAAC;CACF;AAED;;;GAGG;AACH,SAAgB,wBAAwB,CAAC,IAAsB,EAAE,UAAgC,EAAE,gBAAyB;IAC1H,MAAM,QAAQ,GAAG,gBAAgB,IAAI,GAAG,CAAC,CAAC,+DAA+D;IACzG,IAAI,QAAQ,GAAG,IAAI,CAAC,GAAG,EAAE,GAAG,QAAQ,CAAC;IACrC,MAAM,gBAAgB,GAAqB,CAAC,MAAM,EAAE,KAAK,EAAE,EAAE;QAC3D,MAAM,GAAG,GAAG,IAAI,CAAC,GAAG,EAAE,CAAC;QACvB,IAAI,MAAM,IAAI,KAAK,IAAI,GAAG,IAAI,QAAQ,EAAE;YACtC,QAAQ,GAAG,GAAG,GAAG,QAAQ,CAAC;YAC1B,OAAO,IAAI,CAAC,MAAM,EAAE,KAAK,CAAC,CAAC;SAC5B;QACD,OAAO,UAAU,EAAE,CAAC;IACtB,CAAC,CAAC;IAEF,OAAO,gBAAgB,CAAC;AAC1B,CAAC;AAbD,4DAaC","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 NativeApp\r\n */\r\n\r\nimport { IModelJsNative } from \"@bentley/imodeljs-native\";\r\nimport { assert, BentleyError, IModelStatus, Logger, LogLevel, OpenMode } from \"@itwin/core-bentley\";\r\nimport {\r\n ChangesetIndex, ChangesetIndexAndId, EditingScopeNotifications, getPullChangesIpcChannel, IModelConnectionProps, IModelError, IModelRpcProps,\r\n ipcAppChannels, IpcAppFunctions, IpcAppNotifications, IpcInvokeReturn, IpcListener, IpcSocketBackend, iTwinChannel,\r\n OpenBriefcaseProps, PullChangesOptions, RemoveFunction, StandaloneOpenOptions, TileTreeContentIds, TxnNotifications,\r\n} from \"@itwin/core-common\";\r\nimport { ProgressFunction, ProgressStatus } from \"./CheckpointManager\";\r\nimport { BriefcaseDb, IModelDb, StandaloneDb } from \"./IModelDb\";\r\nimport { IModelHost, IModelHostOptions } from \"./IModelHost\";\r\nimport { cancelTileContentRequests } from \"./rpc-impl/IModelTileRpcImpl\";\r\n\r\n/**\r\n * Options for [[IpcHost.startup]]\r\n * @public\r\n */\r\nexport interface IpcHostOpts {\r\n iModelHost?: IModelHostOptions;\r\n ipcHost?: {\r\n /** The Ipc socket to use for communications with frontend. Allows undefined only for headless tests. */\r\n socket?: IpcSocketBackend;\r\n\r\n /** don't send stack information on exceptions */\r\n exceptions?: {\r\n noStack?: boolean;\r\n };\r\n };\r\n}\r\n\r\n/**\r\n * Used by applications that have a dedicated backend. IpcHosts may send messages to their corresponding IpcApp.\r\n * @note if either end terminates, the other must too.\r\n * @public\r\n */\r\nexport class IpcHost {\r\n public static noStack = false;\r\n private static _ipc: IpcSocketBackend | undefined;\r\n /** Get the implementation of the [IpcSocketBackend]($common) interface. */\r\n private static get ipc(): IpcSocketBackend { return this._ipc!; } // eslint-disable-line @typescript-eslint/no-non-null-assertion\r\n /** Determine whether Ipc is available for this backend. This will only be true if [[startup]] has been called on this class. */\r\n public static get isValid(): boolean { return undefined !== this._ipc; }\r\n\r\n /**\r\n * Send a message to the frontend over an Ipc channel.\r\n * @param channel the name of the channel matching the name registered with [[IpcApp.addListener]].\r\n * @param data The content of the message.\r\n */\r\n public static send(channel: string, ...data: any[]): void {\r\n this.ipc.send(iTwinChannel(channel), ...data);\r\n }\r\n\r\n /**\r\n * Establish a handler for an Ipc channel to receive [[Frontend.invoke]] calls\r\n * @param channel The name of the channel for this handler.\r\n * @param handler A function that supplies the implementation for `channel`\r\n * @note returns A function to call to remove the handler.\r\n */\r\n public static handle(channel: string, handler: (...args: any[]) => Promise<any>): RemoveFunction {\r\n return this.ipc.handle(iTwinChannel(channel), handler);\r\n }\r\n /**\r\n * Establish a handler to receive messages sent via [[IpcApp.send]].\r\n * @param channel The name of the channel for the messages.\r\n * @param listener A function called when messages are sent over `channel`\r\n * @note returns A function to call to remove the listener.\r\n */\r\n public static addListener(channel: string, listener: IpcListener): RemoveFunction {\r\n return this.ipc.addListener(iTwinChannel(channel), listener);\r\n }\r\n /**\r\n * Remove a previously registered listener\r\n * @param channel The name of the channel for the listener previously registered with [[addListener]]\r\n * @param listener The function passed to [[addListener]]\r\n */\r\n public static removeListener(channel: string, listener: IpcListener): void {\r\n this.ipc.removeListener(iTwinChannel(channel), listener);\r\n }\r\n\r\n private static notify(channel: string, briefcase: BriefcaseDb | StandaloneDb, methodName: string, ...args: any[]) {\r\n if (this.isValid)\r\n return this.send(`${channel}/${briefcase.key}`, methodName, ...args);\r\n }\r\n\r\n /** @internal */\r\n public static notifyIpcFrontend<T extends keyof IpcAppNotifications>(methodName: T, ...args: Parameters<IpcAppNotifications[T]>) {\r\n return IpcHost.send(ipcAppChannels.appNotify, methodName, ...args);\r\n }\r\n\r\n /** @internal */\r\n public static notifyTxns<T extends keyof TxnNotifications>(briefcase: BriefcaseDb | StandaloneDb, methodName: T, ...args: Parameters<TxnNotifications[T]>) {\r\n this.notify(ipcAppChannels.txns, briefcase, methodName, ...args);\r\n }\r\n\r\n /** @internal */\r\n public static notifyEditingScope<T extends keyof EditingScopeNotifications>(briefcase: BriefcaseDb | StandaloneDb, methodName: T, ...args: Parameters<EditingScopeNotifications[T]>) {\r\n this.notify(ipcAppChannels.editingScope, briefcase, methodName, ...args);\r\n }\r\n\r\n /**\r\n * Start the backend of an Ipc app.\r\n * @param opt\r\n * @note this method calls [[IModelHost.startup]] internally.\r\n */\r\n public static async startup(opt?: IpcHostOpts): Promise<void> {\r\n this._ipc = opt?.ipcHost?.socket;\r\n if (opt?.ipcHost?.exceptions?.noStack)\r\n this.noStack = true;\r\n\r\n if (this.isValid) { // for tests, we use IpcHost but don't have a frontend\r\n IpcAppHandler.register();\r\n }\r\n\r\n await IModelHost.startup(opt?.iModelHost);\r\n }\r\n\r\n /** Shutdown IpcHost backend. Also calls [[IModelHost.shutdown]] */\r\n public static async shutdown(): Promise<void> {\r\n this._ipc = undefined;\r\n await IModelHost.shutdown();\r\n }\r\n}\r\n\r\n/**\r\n * Base class for all implementations of an Ipc interface.\r\n *\r\n * Create a subclass to implement your Ipc interface. Your class should be declared like this:\r\n * ```ts\r\n * class MyHandler extends IpcHandler implements MyInterface\r\n * ```\r\n * to ensure all methods and signatures are correct.\r\n *\r\n * Then, call `MyClass.register` at startup to connect your class to your channel.\r\n * @public\r\n */\r\nexport abstract class IpcHandler {\r\n /**\r\n * All subclasses *must* implement this method to specify their channel name.\r\n *\r\n * Channel names are the key that connects Handlers and senders. The channel name of IpcHandlers must exactly match the name used by senders.\r\n * By convention, channel names should be prefixed by a *namespace* (e.g. `${appName}/`)\r\n * unique enough to disambiguate them from channels for other apps that may be running in the same processes.\r\n */\r\n public abstract get channelName(): string;\r\n\r\n /**\r\n * Register this class as the handler for methods on its channel. This static method creates a new instance\r\n * that becomes the handler and is `this` when its methods are called.\r\n * @returns A function that can be called to remove the handler.\r\n * @note this method should only be called once per channel. If it is called multiple times, subsequent calls replace the previous ones.\r\n */\r\n public static register(): RemoveFunction {\r\n const impl = new (this as any)() as IpcHandler; // create an instance of subclass. \"as any\" is necessary because base class is abstract\r\n return IpcHost.handle(impl.channelName, async (_evt: Event, funcName: string, ...args: any[]): Promise<IpcInvokeReturn> => {\r\n try {\r\n const func = (impl as any)[funcName];\r\n if (typeof func !== \"function\")\r\n throw new IModelError(IModelStatus.FunctionNotFound, `Method \"${impl.constructor.name}.${funcName}\" not found on IpcHandler registered for channel: ${impl.channelName}`);\r\n\r\n return { result: await func.call(impl, ...args) };\r\n } catch (err: any) {\r\n const ret: IpcInvokeReturn = {\r\n error: {\r\n name: err.hasOwnProperty(\"name\") ? err.name : err.constructor?.name ?? \"Unknown Error\",\r\n message: err.message ?? BentleyError.getErrorMessage(err),\r\n errorNumber: err.errorNumber ?? 0,\r\n },\r\n };\r\n if (!IpcHost.noStack)\r\n ret.error.stack = BentleyError.getErrorStack(err);\r\n return ret;\r\n }\r\n });\r\n }\r\n}\r\n\r\n/**\r\n * Implementation of IpcAppFunctions\r\n */\r\nclass IpcAppHandler extends IpcHandler implements IpcAppFunctions {\r\n public get channelName() { return ipcAppChannels.functions; }\r\n\r\n private _iModelKeyToPullStatus = new Map<string, ProgressStatus>();\r\n\r\n public async log(_timestamp: number, level: LogLevel, category: string, message: string, metaData?: any): Promise<void> {\r\n switch (level) {\r\n case LogLevel.Error:\r\n Logger.logError(category, message, metaData);\r\n break;\r\n case LogLevel.Info:\r\n Logger.logInfo(category, message, metaData);\r\n break;\r\n case LogLevel.Trace:\r\n Logger.logTrace(category, message, metaData);\r\n break;\r\n case LogLevel.Warning:\r\n Logger.logWarning(category, message, metaData);\r\n break;\r\n }\r\n }\r\n\r\n public async cancelTileContentRequests(tokenProps: IModelRpcProps, contentIds: TileTreeContentIds[]): Promise<void> {\r\n return cancelTileContentRequests(tokenProps, contentIds);\r\n }\r\n public async cancelElementGraphicsRequests(key: string, requestIds: string[]): Promise<void> {\r\n return IModelDb.findByKey(key).nativeDb.cancelElementGraphicsRequests(requestIds);\r\n }\r\n public async openBriefcase(args: OpenBriefcaseProps): Promise<IModelConnectionProps> {\r\n const db = await BriefcaseDb.open(args);\r\n return db.toJSON();\r\n }\r\n public async openStandalone(filePath: string, openMode: OpenMode, opts?: StandaloneOpenOptions): Promise<IModelConnectionProps> {\r\n return StandaloneDb.openFile(filePath, openMode, opts).getConnectionProps();\r\n }\r\n public async closeIModel(key: string): Promise<void> {\r\n IModelDb.findByKey(key).close();\r\n }\r\n public async saveChanges(key: string, description?: string): Promise<void> {\r\n IModelDb.findByKey(key).saveChanges(description);\r\n }\r\n public async hasPendingTxns(key: string): Promise<boolean> {\r\n return IModelDb.findByKey(key).nativeDb.hasPendingTxns();\r\n }\r\n\r\n public async isUndoPossible(key: string): Promise<boolean> {\r\n return IModelDb.findByKey(key).nativeDb.isUndoPossible();\r\n }\r\n public async isRedoPossible(key: string): Promise<boolean> {\r\n return IModelDb.findByKey(key).nativeDb.isRedoPossible();\r\n }\r\n public async getUndoString(key: string): Promise<string> {\r\n return IModelDb.findByKey(key).nativeDb.getUndoString();\r\n }\r\n public async getRedoString(key: string): Promise<string> {\r\n return IModelDb.findByKey(key).nativeDb.getUndoString();\r\n }\r\n\r\n public async pullChanges(key: string, toIndex?: ChangesetIndex, options?: PullChangesOptions): Promise<ChangesetIndexAndId> {\r\n const iModelDb = BriefcaseDb.findByKey(key);\r\n\r\n this._iModelKeyToPullStatus.set(key, ProgressStatus.Continue);\r\n const checkAbort = () => this._iModelKeyToPullStatus.get(key) ?? ProgressStatus.Continue;\r\n\r\n let onProgress: ProgressFunction | undefined;\r\n if (options?.reportProgress) {\r\n const progressCallback: ProgressFunction = (loaded, total) => {\r\n IpcHost.send(getPullChangesIpcChannel(iModelDb.iModelId), { loaded, total });\r\n return checkAbort();\r\n };\r\n onProgress = throttleProgressCallback(progressCallback, checkAbort, options?.progressInterval);\r\n } else if (options?.enableCancellation) {\r\n onProgress = checkAbort;\r\n }\r\n\r\n try {\r\n await iModelDb.pullChanges({ toIndex, onProgress });\r\n } finally {\r\n this._iModelKeyToPullStatus.delete(key);\r\n }\r\n\r\n return iModelDb.changeset as ChangesetIndexAndId;\r\n }\r\n public async cancelPullChangesRequest(key: string): Promise<void> {\r\n this._iModelKeyToPullStatus.set(key, ProgressStatus.Abort);\r\n }\r\n\r\n public async pushChanges(key: string, description: string): Promise<ChangesetIndexAndId> {\r\n const iModelDb = BriefcaseDb.findByKey(key);\r\n await iModelDb.pushChanges({ description });\r\n return iModelDb.changeset as ChangesetIndexAndId;\r\n }\r\n\r\n public async toggleGraphicalEditingScope(key: string, startSession: boolean): Promise<boolean> {\r\n const val: IModelJsNative.ErrorStatusOrResult<any, boolean> = IModelDb.findByKey(key).nativeDb.setGeometricModelTrackingEnabled(startSession);\r\n if (val.error)\r\n throw new IModelError(val.error.status, \"Failed to toggle graphical editing scope\");\r\n assert(undefined !== val.result);\r\n return val.result;\r\n }\r\n public async isGraphicalEditingSupported(key: string): Promise<boolean> {\r\n return IModelDb.findByKey(key).nativeDb.isGeometricModelTrackingSupported();\r\n }\r\n\r\n public async reverseTxns(key: string, numOperations: number): Promise<IModelStatus> {\r\n return IModelDb.findByKey(key).nativeDb.reverseTxns(numOperations);\r\n }\r\n public async reverseAllTxn(key: string): Promise<IModelStatus> {\r\n return IModelDb.findByKey(key).nativeDb.reverseAll();\r\n }\r\n public async reinstateTxn(key: string): Promise<IModelStatus> {\r\n return IModelDb.findByKey(key).nativeDb.reinstateTxn();\r\n }\r\n public async restartTxnSession(key: string): Promise<void> {\r\n return IModelDb.findByKey(key).nativeDb.restartTxnSession();\r\n }\r\n\r\n public async queryConcurrency(pool: \"io\" | \"cpu\"): Promise<number> {\r\n return IModelHost.platform.queryConcurrency(pool);\r\n }\r\n}\r\n\r\n/**\r\n * Prevents progress callback being called more frequently when provided interval.\r\n * @internal\r\n */\r\nexport function throttleProgressCallback(func: ProgressFunction, checkAbort: () => ProgressStatus, progressInterval?: number): ProgressFunction {\r\n const interval = progressInterval ?? 250; // by default, only send progress events every 250 milliseconds\r\n let nextTime = Date.now() + interval;\r\n const progressCallback: ProgressFunction = (loaded, total) => {\r\n const now = Date.now();\r\n if (loaded >= total || now >= nextTime) {\r\n nextTime = now + interval;\r\n return func(loaded, total);\r\n }\r\n return checkAbort();\r\n };\r\n\r\n return progressCallback;\r\n}\r\n"]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W;QACnC,OAAO,mBAAQ,CAAC,SAAS,CAAC,GAAG,CAAC,CAAC,QAAQ,CAAC,YAAY,EAAE,CAAC;IACzD,CAAC;IACM,KAAK,CAAC,iBAAiB,CAAC,GAAW;QACxC,OAAO,mBAAQ,CAAC,SAAS,CAAC,GAAG,CAAC,CAAC,QAAQ,CAAC,iBAAiB,EAAE,CAAC;IAC9D,CAAC;IAEM,KAAK,CAAC,gBAAgB,CAAC,IAAkB;QAC9C,OAAO,uBAAU,CAAC,QAAQ,CAAC,gBAAgB,CAAC,IAAI,CAAC,CAAC;IACpD,CAAC;CACF;AAED;;;GAGG;AACH,SAAgB,wBAAwB,CAAC,IAAsB,EAAE,UAAgC,EAAE,gBAAyB;IAC1H,MAAM,QAAQ,GAAG,gBAAgB,IAAI,GAAG,CAAC,CAAC,+DAA+D;IACzG,IAAI,QAAQ,GAAG,IAAI,CAAC,GAAG,EAAE,GAAG,QAAQ,CAAC;IACrC,MAAM,gBAAgB,GAAqB,CAAC,MAAM,EAAE,KAAK,EAAE,EAAE;QAC3D,MAAM,GAAG,GAAG,IAAI,CAAC,GAAG,EAAE,CAAC;QACvB,IAAI,MAAM,IAAI,KAAK,IAAI,GAAG,IAAI,QAAQ,EAAE;YACtC,QAAQ,GAAG,GAAG,GAAG,QAAQ,CAAC;YAC1B,OAAO,IAAI,CAAC,MAAM,EAAE,KAAK,CAAC,CAAC;SAC5B;QACD,OAAO,UAAU,EAAE,CAAC;IACtB,CAAC,CAAC;IAEF,OAAO,gBAAgB,CAAC;AAC1B,CAAC;AAbD,4DAaC","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 NativeApp\r\n */\r\n\r\nimport { IModelJsNative } from \"@bentley/imodeljs-native\";\r\nimport { assert, BentleyError, IModelStatus, Logger, LogLevel, OpenMode } from \"@itwin/core-bentley\";\r\nimport {\r\n ChangesetIndex, ChangesetIndexAndId, EditingScopeNotifications, getPullChangesIpcChannel, IModelConnectionProps, IModelError, IModelRpcProps,\r\n ipcAppChannels, IpcAppFunctions, IpcAppNotifications, IpcInvokeReturn, IpcListener, IpcSocketBackend, iTwinChannel,\r\n OpenBriefcaseProps, OpenCheckpointArgs, PullChangesOptions, RemoveFunction, StandaloneOpenOptions, TileTreeContentIds, TxnNotifications,\r\n} from \"@itwin/core-common\";\r\nimport { ProgressFunction, ProgressStatus } from \"./CheckpointManager\";\r\nimport { BriefcaseDb, IModelDb, SnapshotDb, StandaloneDb } from \"./IModelDb\";\r\nimport { IModelHost, IModelHostOptions } from \"./IModelHost\";\r\nimport { cancelTileContentRequests } from \"./rpc-impl/IModelTileRpcImpl\";\r\n\r\n/**\r\n * Options for [[IpcHost.startup]]\r\n * @public\r\n */\r\nexport interface IpcHostOpts {\r\n iModelHost?: IModelHostOptions;\r\n ipcHost?: {\r\n /** The Ipc socket to use for communications with frontend. Allows undefined only for headless tests. */\r\n socket?: IpcSocketBackend;\r\n\r\n /** don't send stack information on exceptions */\r\n exceptions?: {\r\n noStack?: boolean;\r\n };\r\n };\r\n}\r\n\r\n/**\r\n * Used by applications that have a dedicated backend. IpcHosts may send messages to their corresponding IpcApp.\r\n * @note if either end terminates, the other must too.\r\n * @public\r\n */\r\nexport class IpcHost {\r\n public static noStack = false;\r\n private static _ipc: IpcSocketBackend | undefined;\r\n /** Get the implementation of the [IpcSocketBackend]($common) interface. */\r\n private static get ipc(): IpcSocketBackend { return this._ipc!; } // eslint-disable-line @typescript-eslint/no-non-null-assertion\r\n /** Determine whether Ipc is available for this backend. This will only be true if [[startup]] has been called on this class. */\r\n public static get isValid(): boolean { return undefined !== this._ipc; }\r\n\r\n /**\r\n * Send a message to the frontend over an Ipc channel.\r\n * @param channel the name of the channel matching the name registered with [[IpcApp.addListener]].\r\n * @param data The content of the message.\r\n */\r\n public static send(channel: string, ...data: any[]): void {\r\n this.ipc.send(iTwinChannel(channel), ...data);\r\n }\r\n\r\n /**\r\n * Establish a handler for an Ipc channel to receive [[Frontend.invoke]] calls\r\n * @param channel The name of the channel for this handler.\r\n * @param handler A function that supplies the implementation for `channel`\r\n * @note returns A function to call to remove the handler.\r\n */\r\n public static handle(channel: string, handler: (...args: any[]) => Promise<any>): RemoveFunction {\r\n return this.ipc.handle(iTwinChannel(channel), handler);\r\n }\r\n /**\r\n * Establish a handler to receive messages sent via [[IpcApp.send]].\r\n * @param channel The name of the channel for the messages.\r\n * @param listener A function called when messages are sent over `channel`\r\n * @note returns A function to call to remove the listener.\r\n */\r\n public static addListener(channel: string, listener: IpcListener): RemoveFunction {\r\n return this.ipc.addListener(iTwinChannel(channel), listener);\r\n }\r\n /**\r\n * Remove a previously registered listener\r\n * @param channel The name of the channel for the listener previously registered with [[addListener]]\r\n * @param listener The function passed to [[addListener]]\r\n */\r\n public static removeListener(channel: string, listener: IpcListener): void {\r\n this.ipc.removeListener(iTwinChannel(channel), listener);\r\n }\r\n\r\n private static notify(channel: string, briefcase: BriefcaseDb | StandaloneDb, methodName: string, ...args: any[]) {\r\n if (this.isValid)\r\n return this.send(`${channel}/${briefcase.key}`, methodName, ...args);\r\n }\r\n\r\n /** @internal */\r\n public static notifyIpcFrontend<T extends keyof IpcAppNotifications>(methodName: T, ...args: Parameters<IpcAppNotifications[T]>) {\r\n return IpcHost.send(ipcAppChannels.appNotify, methodName, ...args);\r\n }\r\n\r\n /** @internal */\r\n public static notifyTxns<T extends keyof TxnNotifications>(briefcase: BriefcaseDb | StandaloneDb, methodName: T, ...args: Parameters<TxnNotifications[T]>) {\r\n this.notify(ipcAppChannels.txns, briefcase, methodName, ...args);\r\n }\r\n\r\n /** @internal */\r\n public static notifyEditingScope<T extends keyof EditingScopeNotifications>(briefcase: BriefcaseDb | StandaloneDb, methodName: T, ...args: Parameters<EditingScopeNotifications[T]>) {\r\n this.notify(ipcAppChannels.editingScope, briefcase, methodName, ...args);\r\n }\r\n\r\n /**\r\n * Start the backend of an Ipc app.\r\n * @param opt\r\n * @note this method calls [[IModelHost.startup]] internally.\r\n */\r\n public static async startup(opt?: IpcHostOpts): Promise<void> {\r\n this._ipc = opt?.ipcHost?.socket;\r\n if (opt?.ipcHost?.exceptions?.noStack)\r\n this.noStack = true;\r\n\r\n if (this.isValid) { // for tests, we use IpcHost but don't have a frontend\r\n IpcAppHandler.register();\r\n }\r\n\r\n await IModelHost.startup(opt?.iModelHost);\r\n }\r\n\r\n /** Shutdown IpcHost backend. Also calls [[IModelHost.shutdown]] */\r\n public static async shutdown(): Promise<void> {\r\n this._ipc = undefined;\r\n await IModelHost.shutdown();\r\n }\r\n}\r\n\r\n/**\r\n * Base class for all implementations of an Ipc interface.\r\n *\r\n * Create a subclass to implement your Ipc interface. Your class should be declared like this:\r\n * ```ts\r\n * class MyHandler extends IpcHandler implements MyInterface\r\n * ```\r\n * to ensure all methods and signatures are correct.\r\n *\r\n * Then, call `MyClass.register` at startup to connect your class to your channel.\r\n * @public\r\n */\r\nexport abstract class IpcHandler {\r\n /**\r\n * All subclasses *must* implement this method to specify their channel name.\r\n *\r\n * Channel names are the key that connects Handlers and senders. The channel name of IpcHandlers must exactly match the name used by senders.\r\n * By convention, channel names should be prefixed by a *namespace* (e.g. `${appName}/`)\r\n * unique enough to disambiguate them from channels for other apps that may be running in the same processes.\r\n */\r\n public abstract get channelName(): string;\r\n\r\n /**\r\n * Register this class as the handler for methods on its channel. This static method creates a new instance\r\n * that becomes the handler and is `this` when its methods are called.\r\n * @returns A function that can be called to remove the handler.\r\n * @note this method should only be called once per channel. If it is called multiple times, subsequent calls replace the previous ones.\r\n */\r\n public static register(): RemoveFunction {\r\n const impl = new (this as any)() as IpcHandler; // create an instance of subclass. \"as any\" is necessary because base class is abstract\r\n return IpcHost.handle(impl.channelName, async (_evt: Event, funcName: string, ...args: any[]): Promise<IpcInvokeReturn> => {\r\n try {\r\n const func = (impl as any)[funcName];\r\n if (typeof func !== \"function\")\r\n throw new IModelError(IModelStatus.FunctionNotFound, `Method \"${impl.constructor.name}.${funcName}\" not found on IpcHandler registered for channel: ${impl.channelName}`);\r\n\r\n return { result: await func.call(impl, ...args) };\r\n } catch (err: any) {\r\n const ret: IpcInvokeReturn = {\r\n error: {\r\n name: err.hasOwnProperty(\"name\") ? err.name : err.constructor?.name ?? \"Unknown Error\",\r\n message: err.message ?? BentleyError.getErrorMessage(err),\r\n errorNumber: err.errorNumber ?? 0,\r\n },\r\n };\r\n if (!IpcHost.noStack)\r\n ret.error.stack = BentleyError.getErrorStack(err);\r\n return ret;\r\n }\r\n });\r\n }\r\n}\r\n\r\n/**\r\n * Implementation of IpcAppFunctions\r\n */\r\nclass IpcAppHandler extends IpcHandler implements IpcAppFunctions {\r\n public get channelName() { return ipcAppChannels.functions; }\r\n\r\n private _iModelKeyToPullStatus = new Map<string, ProgressStatus>();\r\n\r\n public async log(_timestamp: number, level: LogLevel, category: string, message: string, metaData?: any): Promise<void> {\r\n switch (level) {\r\n case LogLevel.Error:\r\n Logger.logError(category, message, metaData);\r\n break;\r\n case LogLevel.Info:\r\n Logger.logInfo(category, message, metaData);\r\n break;\r\n case LogLevel.Trace:\r\n Logger.logTrace(category, message, metaData);\r\n break;\r\n case LogLevel.Warning:\r\n Logger.logWarning(category, message, metaData);\r\n break;\r\n }\r\n }\r\n\r\n public async cancelTileContentRequests(tokenProps: IModelRpcProps, contentIds: TileTreeContentIds[]): Promise<void> {\r\n return cancelTileContentRequests(tokenProps, contentIds);\r\n }\r\n public async cancelElementGraphicsRequests(key: string, requestIds: string[]): Promise<void> {\r\n return IModelDb.findByKey(key).nativeDb.cancelElementGraphicsRequests(requestIds);\r\n }\r\n public async openBriefcase(args: OpenBriefcaseProps): Promise<IModelConnectionProps> {\r\n const db = await BriefcaseDb.open(args);\r\n return db.toJSON();\r\n }\r\n public async openCheckpoint(checkpoint: OpenCheckpointArgs): Promise<IModelConnectionProps> {\r\n return (await SnapshotDb.openCheckpoint(checkpoint)).getConnectionProps();\r\n }\r\n public async openStandalone(filePath: string, openMode: OpenMode, opts?: StandaloneOpenOptions): Promise<IModelConnectionProps> {\r\n return StandaloneDb.openFile(filePath, openMode, opts).getConnectionProps();\r\n }\r\n public async closeIModel(key: string): Promise<void> {\r\n IModelDb.findByKey(key).close();\r\n }\r\n public async saveChanges(key: string, description?: string): Promise<void> {\r\n IModelDb.findByKey(key).saveChanges(description);\r\n }\r\n public async hasPendingTxns(key: string): Promise<boolean> {\r\n return IModelDb.findByKey(key).nativeDb.hasPendingTxns();\r\n }\r\n\r\n public async isUndoPossible(key: string): Promise<boolean> {\r\n return IModelDb.findByKey(key).nativeDb.isUndoPossible();\r\n }\r\n public async isRedoPossible(key: string): Promise<boolean> {\r\n return IModelDb.findByKey(key).nativeDb.isRedoPossible();\r\n }\r\n public async getUndoString(key: string): Promise<string> {\r\n return IModelDb.findByKey(key).nativeDb.getUndoString();\r\n }\r\n public async getRedoString(key: string): Promise<string> {\r\n return IModelDb.findByKey(key).nativeDb.getUndoString();\r\n }\r\n\r\n public async pullChanges(key: string, toIndex?: ChangesetIndex, options?: PullChangesOptions): Promise<ChangesetIndexAndId> {\r\n const iModelDb = BriefcaseDb.findByKey(key);\r\n\r\n this._iModelKeyToPullStatus.set(key, ProgressStatus.Continue);\r\n const checkAbort = () => this._iModelKeyToPullStatus.get(key) ?? ProgressStatus.Continue;\r\n\r\n let onProgress: ProgressFunction | undefined;\r\n if (options?.reportProgress) {\r\n const progressCallback: ProgressFunction = (loaded, total) => {\r\n IpcHost.send(getPullChangesIpcChannel(iModelDb.iModelId), { loaded, total });\r\n return checkAbort();\r\n };\r\n onProgress = throttleProgressCallback(progressCallback, checkAbort, options?.progressInterval);\r\n } else if (options?.enableCancellation) {\r\n onProgress = checkAbort;\r\n }\r\n\r\n try {\r\n await iModelDb.pullChanges({ toIndex, onProgress });\r\n } finally {\r\n this._iModelKeyToPullStatus.delete(key);\r\n }\r\n\r\n return iModelDb.changeset as ChangesetIndexAndId;\r\n }\r\n public async cancelPullChangesRequest(key: string): Promise<void> {\r\n this._iModelKeyToPullStatus.set(key, ProgressStatus.Abort);\r\n }\r\n\r\n public async pushChanges(key: string, description: string): Promise<ChangesetIndexAndId> {\r\n const iModelDb = BriefcaseDb.findByKey(key);\r\n await iModelDb.pushChanges({ description });\r\n return iModelDb.changeset as ChangesetIndexAndId;\r\n }\r\n\r\n public async toggleGraphicalEditingScope(key: string, startSession: boolean): Promise<boolean> {\r\n const val: IModelJsNative.ErrorStatusOrResult<any, boolean> = IModelDb.findByKey(key).nativeDb.setGeometricModelTrackingEnabled(startSession);\r\n if (val.error)\r\n throw new IModelError(val.error.status, \"Failed to toggle graphical editing scope\");\r\n assert(undefined !== val.result);\r\n return val.result;\r\n }\r\n public async isGraphicalEditingSupported(key: string): Promise<boolean> {\r\n return IModelDb.findByKey(key).nativeDb.isGeometricModelTrackingSupported();\r\n }\r\n\r\n public async reverseTxns(key: string, numOperations: number): Promise<IModelStatus> {\r\n return IModelDb.findByKey(key).nativeDb.reverseTxns(numOperations);\r\n }\r\n public async reverseAllTxn(key: string): Promise<IModelStatus> {\r\n return IModelDb.findByKey(key).nativeDb.reverseAll();\r\n }\r\n public async reinstateTxn(key: string): Promise<IModelStatus> {\r\n return IModelDb.findByKey(key).nativeDb.reinstateTxn();\r\n }\r\n public async restartTxnSession(key: string): Promise<void> {\r\n return IModelDb.findByKey(key).nativeDb.restartTxnSession();\r\n }\r\n\r\n public async queryConcurrency(pool: \"io\" | \"cpu\"): Promise<number> {\r\n return IModelHost.platform.queryConcurrency(pool);\r\n }\r\n}\r\n\r\n/**\r\n * Prevents progress callback being called more frequently when provided interval.\r\n * @internal\r\n */\r\nexport function throttleProgressCallback(func: ProgressFunction, checkAbort: () => ProgressStatus, progressInterval?: number): ProgressFunction {\r\n const interval = progressInterval ?? 250; // by default, only send progress events every 250 milliseconds\r\n let nextTime = Date.now() + interval;\r\n const progressCallback: ProgressFunction = (loaded, total) => {\r\n const now = Date.now();\r\n if (loaded >= total || now >= nextTime) {\r\n nextTime = now + interval;\r\n return func(loaded, total);\r\n }\r\n return checkAbort();\r\n };\r\n\r\n return progressCallback;\r\n}\r\n"]}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"RpcBriefcaseUtility.d.ts","sourceRoot":"","sources":["../../../src/rpc-impl/RpcBriefcaseUtility.ts"],"names":[],"mappings":"AAIA;;GAEG;AAEH,OAAO,EAAE,WAAW,EAA0D,MAAM,qBAAqB,CAAC;AAC1G,OAAO,EACL,cAAc,EAAE,qBAAqB,
|
|
1
|
+
{"version":3,"file":"RpcBriefcaseUtility.d.ts","sourceRoot":"","sources":["../../../src/rpc-impl/RpcBriefcaseUtility.ts"],"names":[],"mappings":"AAIA;;GAEG;AAEH,OAAO,EAAE,WAAW,EAA0D,MAAM,qBAAqB,CAAC;AAC1G,OAAO,EACL,cAAc,EAAE,qBAAqB,EAAe,kBAAkB,EAAE,cAAc,EAAiB,WAAW,EAAsB,QAAQ,EACjJ,MAAM,oBAAoB,CAAC;AAI5B,OAAO,EAAe,QAAQ,EAAc,MAAM,aAAa,CAAC;AAMhE,gBAAgB;AAChB,MAAM,WAAW,mBAAmB;IAClC,QAAQ,EAAE,WAAW,CAAC;IACtB,UAAU,EAAE,kBAAkB,CAAC;IAC/B,QAAQ,EAAE,QAAQ,CAAC;IACnB,iBAAiB,CAAC,EAAE,CAAC,CAAC,GAAG,EAAE,cAAc,KAAK,MAAM,CAAC,EAAE,CAAC;IACxD,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB,aAAa,CAAC,EAAE,OAAO,CAAC;CACzB;AACD;;;GAGG;AACH,qBAAa,mBAAmB;mBAET,eAAe;IA2DpC,OAAO,CAAC,MAAM,CAAC,kBAAkB,CAAgD;mBAC5D,aAAa;IAelC;;;;OAIG;WACiB,cAAc,CAAC,WAAW,EAAE,WAAW,EAAE,MAAM,EAAE,cAAc;WAQ/D,IAAI,CAAC,IAAI,EAAE,mBAAmB,GAAG;QAAE,QAAQ,EAAE,QAAQ,CAAC,YAAY,CAAA;KAAE,GAAG,OAAO,CAAC,QAAQ,CAAC;IAC5G;;OAEG;WAEiB,IAAI,CAAC,IAAI,EAAE,mBAAmB,GAAG;QAAE,QAAQ,EAAE,OAAO,CAAC,QAAQ,EAAE,cAAc,CAAC,CAAA;KAAE,GAAG,OAAO,CAAC,QAAQ,CAAC;WAgEpG,eAAe,CAAC,QAAQ,EAAE,WAAW,EAAE,UAAU,EAAE,kBAAkB,EAAE,QAAQ,EAAE,QAAQ,CAAC,YAAY,EAAE,OAAO,CAAC,EAAE,MAAM,GAAG,OAAO,CAAC,qBAAqB,CAAC;IAC7K;;OAEG;WAEiB,eAAe,CAAC,QAAQ,EAAE,WAAW,EAAE,UAAU,EAAE,kBAAkB,EAAE,QAAQ,EAAE,OAAO,CAAC,QAAQ,EAAE,cAAc,CAAC,EAAE,OAAO,CAAC,EAAE,MAAM,GAAG,OAAO,CAAC,qBAAqB,CAAC;CAQ1L"}
|
|
@@ -99,7 +99,7 @@ class RpcBriefcaseUtility {
|
|
|
99
99
|
static async findOpenIModel(accessToken, iModel) {
|
|
100
100
|
const iModelDb = IModelDb_1.IModelDb.findByKey(iModel.key);
|
|
101
101
|
// call refreshContainer, just in case this is a V2 checkpoint whose sasToken is about to expire, or its default transaction is about to be restarted.
|
|
102
|
-
await iModelDb.
|
|
102
|
+
await iModelDb.refreshContainerForRpc(accessToken);
|
|
103
103
|
return iModelDb;
|
|
104
104
|
}
|
|
105
105
|
/**
|
|
@@ -108,41 +108,40 @@ class RpcBriefcaseUtility {
|
|
|
108
108
|
*/
|
|
109
109
|
static async open(args) {
|
|
110
110
|
const { activity, tokenProps, syncMode } = args;
|
|
111
|
-
core_bentley_1.Logger.logTrace(loggerCategory, "RpcBriefcaseUtility.open",
|
|
111
|
+
core_bentley_1.Logger.logTrace(loggerCategory, "RpcBriefcaseUtility.open", tokenProps);
|
|
112
112
|
const timeout = args.timeout ?? 1000;
|
|
113
113
|
if (syncMode === core_common_1.SyncMode.PullOnly || syncMode === core_common_1.SyncMode.PullAndPush) {
|
|
114
114
|
const briefcaseDb = await core_bentley_1.BeDuration.race(timeout, this.openBriefcase(args));
|
|
115
115
|
if (briefcaseDb === undefined) {
|
|
116
|
-
core_bentley_1.Logger.logTrace(loggerCategory, "Open briefcase - pending",
|
|
116
|
+
core_bentley_1.Logger.logTrace(loggerCategory, "Open briefcase - pending", tokenProps);
|
|
117
117
|
throw new core_common_1.RpcPendingResponse(); // eslint-disable-line deprecation/deprecation
|
|
118
118
|
}
|
|
119
119
|
// note: usage is logged in the function BriefcaseManager.downloadNewBriefcaseAndOpen
|
|
120
120
|
return briefcaseDb;
|
|
121
121
|
}
|
|
122
|
-
(
|
|
123
|
-
|
|
124
|
-
(0, core_bentley_1.assert)(undefined !== tokenProps.changeset);
|
|
122
|
+
if (!tokenProps.iModelId || !tokenProps.iTwinId || !tokenProps.changeset)
|
|
123
|
+
throw new core_common_1.IModelError(core_bentley_1.IModelStatus.BadArg, "invalid arguments");
|
|
125
124
|
const checkpoint = {
|
|
126
125
|
iModelId: tokenProps.iModelId,
|
|
127
126
|
iTwinId: tokenProps.iTwinId,
|
|
128
127
|
changeset: tokenProps.changeset,
|
|
129
128
|
accessToken: activity.accessToken,
|
|
130
129
|
};
|
|
131
|
-
// opening a checkpoint
|
|
130
|
+
// opening a checkpoint.
|
|
132
131
|
let db;
|
|
133
132
|
// first check if it's already open
|
|
134
133
|
db = IModelDb_1.SnapshotDb.tryFindByKey(CheckpointManager_1.CheckpointManager.getKey(checkpoint));
|
|
135
134
|
if (db) {
|
|
136
|
-
core_bentley_1.Logger.logTrace(loggerCategory, "Checkpoint was already open",
|
|
135
|
+
core_bentley_1.Logger.logTrace(loggerCategory, "Checkpoint was already open", tokenProps);
|
|
137
136
|
return db;
|
|
138
137
|
}
|
|
139
138
|
try {
|
|
140
139
|
// now try V2 checkpoint
|
|
141
|
-
db = await IModelDb_1.SnapshotDb.
|
|
142
|
-
core_bentley_1.Logger.logTrace(loggerCategory, "using V2 checkpoint
|
|
140
|
+
db = await IModelDb_1.SnapshotDb.openCheckpointFromRpc(checkpoint);
|
|
141
|
+
core_bentley_1.Logger.logTrace(loggerCategory, "using V2 checkpoint", tokenProps);
|
|
143
142
|
}
|
|
144
143
|
catch (e) {
|
|
145
|
-
core_bentley_1.Logger.logTrace(loggerCategory, "unable to open V2 checkpoint - falling back to V1 checkpoint",
|
|
144
|
+
core_bentley_1.Logger.logTrace(loggerCategory, "unable to open V2 checkpoint - falling back to V1 checkpoint", { error: core_bentley_1.BentleyError.getErrorProps(e), ...tokenProps });
|
|
146
145
|
// this isn't a v2 checkpoint. Set up a race between the specified timeout period and the open. Throw an RpcPendingResponse exception if the timeout happens first.
|
|
147
146
|
const request = {
|
|
148
147
|
checkpoint,
|
|
@@ -151,10 +150,10 @@ class RpcBriefcaseUtility {
|
|
|
151
150
|
};
|
|
152
151
|
db = await core_bentley_1.BeDuration.race(timeout, CheckpointManager_1.V1CheckpointManager.getCheckpointDb(request));
|
|
153
152
|
if (db === undefined) {
|
|
154
|
-
core_bentley_1.Logger.logTrace(loggerCategory, "Open V1 checkpoint - pending",
|
|
153
|
+
core_bentley_1.Logger.logTrace(loggerCategory, "Open V1 checkpoint - pending", tokenProps);
|
|
155
154
|
throw new core_common_1.RpcPendingResponse(); // eslint-disable-line deprecation/deprecation
|
|
156
155
|
}
|
|
157
|
-
core_bentley_1.Logger.logTrace(loggerCategory, "Opened V1 checkpoint",
|
|
156
|
+
core_bentley_1.Logger.logTrace(loggerCategory, "Opened V1 checkpoint", tokenProps);
|
|
158
157
|
}
|
|
159
158
|
return db;
|
|
160
159
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"RpcBriefcaseUtility.js","sourceRoot":"","sources":["../../../src/rpc-impl/RpcBriefcaseUtility.ts"],"names":[],"mappings":";AAAA;;;+FAG+F;AAC/F;;GAEG;;;AAEH,sDAA0G;AAC1G,oDAE4B;AAC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U,EAAE,CAAC,CAAC,CAAC;SACpF;QAED,OAAO,EAAE,CAAC;IACZ,CAAC;IAQM,MAAM,CAAC,KAAK,CAAC,eAAe,CAAC,QAAqB,EAAE,UAA8B,EAAE,QAAkB,EAAE,UAAkB,IAAI;QACnI,IAAI,UAAU,CAAC,QAAQ;YACrB,MAAM,uBAAU,CAAC,WAAW,EAAE,UAAU,CAAC,UAAU,CAAC,QAAQ,CAAC,CAAC;QAChE,mDAAmD;QACnD,OAAO,CAAC,MAAM,IAAI,CAAC,IAAI,CAAC,EAAE,QAAQ,EAAE,UAAU,EAAE,QAAQ,EAAE,OAAO,EAAE,CAAC,CAAC,CAAC,MAAM,EAAE,CAAC;IACjF,CAAC;;AA/Gc,sCAAkB,GAAsC,IAAI,GAAG,EAAE,CAAC;AA7DtE,kDAAmB","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 RpcInterface\r\n */\r\n\r\nimport { AccessToken, assert, BeDuration, BentleyError, IModelStatus, Logger } from \"@itwin/core-bentley\";\r\nimport {\r\n BriefcaseProps, IModelConnectionProps, IModelRpcOpenProps, IModelRpcProps, IModelVersion, RpcActivity, RpcPendingResponse, SyncMode,\r\n} from \"@itwin/core-common\";\r\nimport { BackendLoggerCategory } from \"../BackendLoggerCategory\";\r\nimport { BriefcaseManager, RequestNewBriefcaseArg } from \"../BriefcaseManager\";\r\nimport { CheckpointManager, CheckpointProps, V1CheckpointManager } from \"../CheckpointManager\";\r\nimport { BriefcaseDb, IModelDb, SnapshotDb } from \"../IModelDb\";\r\nimport { IModelHost } from \"../IModelHost\";\r\nimport { IModelJsFs } from \"../IModelJsFs\";\r\n\r\nconst loggerCategory: string = BackendLoggerCategory.IModelDb;\r\n\r\n/** @internal */\r\nexport interface DownloadAndOpenArgs {\r\n activity: RpcActivity; // eslint-disable-line deprecation/deprecation\r\n tokenProps: IModelRpcOpenProps;\r\n syncMode: SyncMode;\r\n fileNameResolvers?: ((arg: BriefcaseProps) => string)[];\r\n timeout?: number;\r\n forceDownload?: boolean;\r\n}\r\n/**\r\n * Utility to open the iModel for RPC interfaces\r\n * @internal\r\n */\r\nexport class RpcBriefcaseUtility {\r\n\r\n private static async downloadAndOpen(args: DownloadAndOpenArgs): Promise<BriefcaseDb> {\r\n const { activity, tokenProps } = args;\r\n const accessToken = activity.accessToken;\r\n assert(undefined !== tokenProps.iModelId);\r\n\r\n const iModelId = tokenProps.iModelId;\r\n let myBriefcaseIds: number[];\r\n if (args.syncMode === SyncMode.PullOnly) {\r\n myBriefcaseIds = [0]; // PullOnly means briefcaseId 0\r\n } else {\r\n // check with iModelHub and see if we already have acquired any briefcaseIds\r\n myBriefcaseIds = await IModelHost.hubAccess.getMyBriefcaseIds({ accessToken, iModelId });\r\n }\r\n\r\n const resolvers = args.fileNameResolvers ?? [(arg) => BriefcaseManager.getFileName(arg)];\r\n\r\n // see if we can open any of the briefcaseIds we already acquired from iModelHub\r\n if (resolvers) {\r\n for (const resolver of resolvers) {\r\n for (const briefcaseId of myBriefcaseIds) {\r\n const fileName = resolver({ briefcaseId, iModelId });\r\n if (IModelJsFs.existsSync(fileName)) {\r\n const briefcaseDb = BriefcaseDb.findByFilename(fileName);\r\n if (briefcaseDb !== undefined)\r\n return briefcaseDb as BriefcaseDb;\r\n try {\r\n if (args.forceDownload)\r\n throw new Error(); // causes delete below\r\n const db = await BriefcaseDb.open({ fileName });\r\n if (db.changeset.id !== tokenProps.changeset?.id) {\r\n assert(undefined !== tokenProps.changeset);\r\n const toIndex = tokenProps.changeset?.index ??\r\n (await IModelHost.hubAccess.getChangesetFromVersion({ accessToken, iModelId, version: IModelVersion.asOfChangeSet(tokenProps.changeset.id) })).index;\r\n await BriefcaseManager.pullAndApplyChangesets(db, { accessToken, toIndex });\r\n }\r\n return db;\r\n } catch (error: any) {\r\n if (!(error.errorNumber === IModelStatus.AlreadyOpen))\r\n // somehow we have this briefcaseId and the file exists, but we can't open it. Delete it.\r\n await BriefcaseManager.deleteBriefcaseFiles(fileName, accessToken);\r\n }\r\n }\r\n }\r\n }\r\n }\r\n\r\n // no local briefcase available. Download one and open it.\r\n assert(undefined !== tokenProps.iTwinId);\r\n const request: RequestNewBriefcaseArg = {\r\n accessToken,\r\n iTwinId: tokenProps.iTwinId,\r\n iModelId,\r\n briefcaseId: args.syncMode === SyncMode.PullOnly ? 0 : undefined, // if briefcaseId is undefined, we'll acquire a new one.\r\n };\r\n\r\n const props = await BriefcaseManager.downloadBriefcase(request);\r\n return BriefcaseDb.open(props);\r\n }\r\n\r\n private static _briefcasePromises: Map<string, Promise<BriefcaseDb>> = new Map();\r\n private static async openBriefcase(args: DownloadAndOpenArgs): Promise<BriefcaseDb> {\r\n const key = `${args.tokenProps.iModelId}:${args.tokenProps.changeset?.id}:${args.tokenProps.changeset?.index}:${args.syncMode}`;\r\n const cachedPromise = this._briefcasePromises.get(key);\r\n if (cachedPromise)\r\n return cachedPromise;\r\n\r\n try {\r\n const briefcasePromise = this.downloadAndOpen(args); // save the fact that we're working on downloading so if we timeout, we'll reuse this request.\r\n this._briefcasePromises.set(key, briefcasePromise);\r\n return await briefcasePromise;\r\n } finally {\r\n this._briefcasePromises.delete(key); // the download and open is now done\r\n }\r\n }\r\n\r\n /** find a previously opened iModel for RPC.\r\n * @param accessToken necessary (only) for V2 checkpoints to refresh access token in daemon if it has expired. We use the accessToken of the current RPC request\r\n * to refresh the daemon, even though it will be used for all authorized users.\r\n * @param the IModelRpcProps to locate the opened iModel.\r\n */\r\n public static async findOpenIModel(accessToken: AccessToken, iModel: IModelRpcProps) {\r\n const iModelDb = IModelDb.findByKey(iModel.key);\r\n\r\n // call refreshContainer, just in case this is a V2 checkpoint whose sasToken is about to expire, or its default transaction is about to be restarted.\r\n await iModelDb.refreshContainer(accessToken);\r\n return iModelDb;\r\n }\r\n\r\n public static async open(args: DownloadAndOpenArgs & {syncMode: SyncMode.FixedVersion }): Promise<IModelDb>;\r\n /**\r\n * @deprecated in 4.4.0 - only `SyncMode.FixedVersion` should be used in RPC backends\r\n */\r\n // eslint-disable-next-line @typescript-eslint/unified-signatures -- these are separate to explicitly deprecate some SyncMode members.\r\n public static async open(args: DownloadAndOpenArgs & {syncMode: Exclude<SyncMode, \"FixedVersion\"> }): Promise<IModelDb>;\r\n /**\r\n * Download and open a checkpoint or briefcase, ensuring the operation completes within a default timeout. If the time to open exceeds the timeout period,\r\n * a RpcPendingResponse exception is thrown\r\n */\r\n public static async open(args: DownloadAndOpenArgs): Promise<IModelDb> {\r\n const { activity, tokenProps, syncMode } = args;\r\n Logger.logTrace(loggerCategory, \"RpcBriefcaseUtility.open\", () => ({ ...tokenProps }));\r\n\r\n const timeout = args.timeout ?? 1000;\r\n if (syncMode === SyncMode.PullOnly || syncMode === SyncMode.PullAndPush) {\r\n const briefcaseDb = await BeDuration.race(timeout, this.openBriefcase(args));\r\n\r\n if (briefcaseDb === undefined) {\r\n Logger.logTrace(loggerCategory, \"Open briefcase - pending\", () => ({ ...tokenProps }));\r\n throw new RpcPendingResponse(); // eslint-disable-line deprecation/deprecation\r\n }\r\n // note: usage is logged in the function BriefcaseManager.downloadNewBriefcaseAndOpen\r\n return briefcaseDb;\r\n }\r\n\r\n assert(undefined !== tokenProps.iModelId);\r\n assert(undefined !== tokenProps.iTwinId);\r\n assert(undefined !== tokenProps.changeset);\r\n\r\n const checkpoint: CheckpointProps = {\r\n iModelId: tokenProps.iModelId,\r\n iTwinId: tokenProps.iTwinId,\r\n changeset: tokenProps.changeset,\r\n accessToken: activity.accessToken,\r\n };\r\n\r\n // opening a checkpoint, readonly.\r\n let db: SnapshotDb | void;\r\n // first check if it's already open\r\n db = SnapshotDb.tryFindByKey(CheckpointManager.getKey(checkpoint));\r\n if (db) {\r\n Logger.logTrace(loggerCategory, \"Checkpoint was already open\", () => ({ ...tokenProps }));\r\n return db;\r\n }\r\n\r\n try {\r\n // now try V2 checkpoint\r\n db = await SnapshotDb.openCheckpointV2(checkpoint);\r\n Logger.logTrace(loggerCategory, \"using V2 checkpoint briefcase\", () => ({ ...tokenProps }));\r\n } catch (e) {\r\n Logger.logTrace(loggerCategory, \"unable to open V2 checkpoint - falling back to V1 checkpoint\", () => ({ error: BentleyError.getErrorProps(e), ...tokenProps }));\r\n\r\n // this isn't a v2 checkpoint. Set up a race between the specified timeout period and the open. Throw an RpcPendingResponse exception if the timeout happens first.\r\n const request = {\r\n checkpoint,\r\n localFile: V1CheckpointManager.getFileName(checkpoint),\r\n aliasFiles: [],\r\n };\r\n db = await BeDuration.race(timeout, V1CheckpointManager.getCheckpointDb(request));\r\n\r\n if (db === undefined) {\r\n Logger.logTrace(loggerCategory, \"Open V1 checkpoint - pending\", () => ({ ...tokenProps }));\r\n throw new RpcPendingResponse(); // eslint-disable-line deprecation/deprecation\r\n }\r\n Logger.logTrace(loggerCategory, \"Opened V1 checkpoint\", () => ({ ...tokenProps }));\r\n }\r\n\r\n return db;\r\n }\r\n\r\n public static async openWithTimeout(activity: RpcActivity, tokenProps: IModelRpcOpenProps, syncMode: SyncMode.FixedVersion, timeout?: number): Promise<IModelConnectionProps>;\r\n /**\r\n * @deprecated in 4.4.0 - only `SyncMode.FixedVersion` should be used in RPC backends\r\n */\r\n // eslint-disable-next-line @typescript-eslint/unified-signatures -- these are separate to explicitly deprecate some SyncMode members.\r\n public static async openWithTimeout(activity: RpcActivity, tokenProps: IModelRpcOpenProps, syncMode: Exclude<SyncMode, \"FixedVersion\">, timeout?: number): Promise<IModelConnectionProps>;\r\n public static async openWithTimeout(activity: RpcActivity, tokenProps: IModelRpcOpenProps, syncMode: SyncMode, timeout: number = 1000): Promise<IModelConnectionProps> { // eslint-disable-line deprecation/deprecation\r\n if (tokenProps.iModelId)\r\n await IModelHost.tileStorage?.initialize(tokenProps.iModelId);\r\n // eslint-disable-next-line deprecation/deprecation\r\n return (await this.open({ activity, tokenProps, sync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AkB,EAAE,UAAkB,IAAI;QACnI,IAAI,UAAU,CAAC,QAAQ;YACrB,MAAM,uBAAU,CAAC,WAAW,EAAE,UAAU,CAAC,UAAU,CAAC,QAAQ,CAAC,CAAC;QAChE,mDAAmD;QACnD,OAAO,CAAC,MAAM,IAAI,CAAC,IAAI,CAAC,EAAE,QAAQ,EAAE,UAAU,EAAE,QAAQ,EAAE,OAAO,EAAE,CAAC,CAAC,CAAC,MAAM,EAAE,CAAC;IACjF,CAAC;;AA7Gc,sCAAkB,GAAsC,IAAI,GAAG,EAAE,CAAC;AA7DtE,kDAAmB","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 RpcInterface\r\n */\r\n\r\nimport { AccessToken, assert, BeDuration, BentleyError, IModelStatus, Logger } from \"@itwin/core-bentley\";\r\nimport {\r\n BriefcaseProps, IModelConnectionProps, IModelError, IModelRpcOpenProps, IModelRpcProps, IModelVersion, RpcActivity, RpcPendingResponse, SyncMode,\r\n} from \"@itwin/core-common\";\r\nimport { BackendLoggerCategory } from \"../BackendLoggerCategory\";\r\nimport { BriefcaseManager, RequestNewBriefcaseArg } from \"../BriefcaseManager\";\r\nimport { CheckpointManager, V1CheckpointManager } from \"../CheckpointManager\";\r\nimport { BriefcaseDb, IModelDb, SnapshotDb } from \"../IModelDb\";\r\nimport { IModelHost } from \"../IModelHost\";\r\nimport { IModelJsFs } from \"../IModelJsFs\";\r\n\r\nconst loggerCategory: string = BackendLoggerCategory.IModelDb;\r\n\r\n/** @internal */\r\nexport interface DownloadAndOpenArgs {\r\n activity: RpcActivity; // eslint-disable-line deprecation/deprecation\r\n tokenProps: IModelRpcOpenProps;\r\n syncMode: SyncMode;\r\n fileNameResolvers?: ((arg: BriefcaseProps) => string)[];\r\n timeout?: number;\r\n forceDownload?: boolean;\r\n}\r\n/**\r\n * Utility to open the iModel for RPC interfaces\r\n * @internal\r\n */\r\nexport class RpcBriefcaseUtility {\r\n\r\n private static async downloadAndOpen(args: DownloadAndOpenArgs): Promise<BriefcaseDb> {\r\n const { activity, tokenProps } = args;\r\n const accessToken = activity.accessToken;\r\n assert(undefined !== tokenProps.iModelId);\r\n\r\n const iModelId = tokenProps.iModelId;\r\n let myBriefcaseIds: number[];\r\n if (args.syncMode === SyncMode.PullOnly) {\r\n myBriefcaseIds = [0]; // PullOnly means briefcaseId 0\r\n } else {\r\n // check with iModelHub and see if we already have acquired any briefcaseIds\r\n myBriefcaseIds = await IModelHost.hubAccess.getMyBriefcaseIds({ accessToken, iModelId });\r\n }\r\n\r\n const resolvers = args.fileNameResolvers ?? [(arg) => BriefcaseManager.getFileName(arg)];\r\n\r\n // see if we can open any of the briefcaseIds we already acquired from iModelHub\r\n if (resolvers) {\r\n for (const resolver of resolvers) {\r\n for (const briefcaseId of myBriefcaseIds) {\r\n const fileName = resolver({ briefcaseId, iModelId });\r\n if (IModelJsFs.existsSync(fileName)) {\r\n const briefcaseDb = BriefcaseDb.findByFilename(fileName);\r\n if (briefcaseDb !== undefined)\r\n return briefcaseDb as BriefcaseDb;\r\n try {\r\n if (args.forceDownload)\r\n throw new Error(); // causes delete below\r\n const db = await BriefcaseDb.open({ fileName });\r\n if (db.changeset.id !== tokenProps.changeset?.id) {\r\n assert(undefined !== tokenProps.changeset);\r\n const toIndex = tokenProps.changeset?.index ??\r\n (await IModelHost.hubAccess.getChangesetFromVersion({ accessToken, iModelId, version: IModelVersion.asOfChangeSet(tokenProps.changeset.id) })).index;\r\n await BriefcaseManager.pullAndApplyChangesets(db, { accessToken, toIndex });\r\n }\r\n return db;\r\n } catch (error: any) {\r\n if (!(error.errorNumber === IModelStatus.AlreadyOpen))\r\n // somehow we have this briefcaseId and the file exists, but we can't open it. Delete it.\r\n await BriefcaseManager.deleteBriefcaseFiles(fileName, accessToken);\r\n }\r\n }\r\n }\r\n }\r\n }\r\n\r\n // no local briefcase available. Download one and open it.\r\n assert(undefined !== tokenProps.iTwinId);\r\n const request: RequestNewBriefcaseArg = {\r\n accessToken,\r\n iTwinId: tokenProps.iTwinId,\r\n iModelId,\r\n briefcaseId: args.syncMode === SyncMode.PullOnly ? 0 : undefined, // if briefcaseId is undefined, we'll acquire a new one.\r\n };\r\n\r\n const props = await BriefcaseManager.downloadBriefcase(request);\r\n return BriefcaseDb.open(props);\r\n }\r\n\r\n private static _briefcasePromises: Map<string, Promise<BriefcaseDb>> = new Map();\r\n private static async openBriefcase(args: DownloadAndOpenArgs): Promise<BriefcaseDb> {\r\n const key = `${args.tokenProps.iModelId}:${args.tokenProps.changeset?.id}:${args.tokenProps.changeset?.index}:${args.syncMode}`;\r\n const cachedPromise = this._briefcasePromises.get(key);\r\n if (cachedPromise)\r\n return cachedPromise;\r\n\r\n try {\r\n const briefcasePromise = this.downloadAndOpen(args); // save the fact that we're working on downloading so if we timeout, we'll reuse this request.\r\n this._briefcasePromises.set(key, briefcasePromise);\r\n return await briefcasePromise;\r\n } finally {\r\n this._briefcasePromises.delete(key); // the download and open is now done\r\n }\r\n }\r\n\r\n /** find a previously opened iModel for RPC.\r\n * @param accessToken necessary (only) for V2 checkpoints to refresh access token in daemon if it has expired. We use the accessToken of the current RPC request\r\n * to refresh the daemon, even though it will be used for all authorized users.\r\n * @param the IModelRpcProps to locate the opened iModel.\r\n */\r\n public static async findOpenIModel(accessToken: AccessToken, iModel: IModelRpcProps) {\r\n const iModelDb = IModelDb.findByKey(iModel.key);\r\n\r\n // call refreshContainer, just in case this is a V2 checkpoint whose sasToken is about to expire, or its default transaction is about to be restarted.\r\n await iModelDb.refreshContainerForRpc(accessToken);\r\n return iModelDb;\r\n }\r\n\r\n public static async open(args: DownloadAndOpenArgs & { syncMode: SyncMode.FixedVersion }): Promise<IModelDb>;\r\n /**\r\n * @deprecated in 4.4.0 - only `SyncMode.FixedVersion` should be used in RPC backends\r\n */\r\n // eslint-disable-next-line @typescript-eslint/unified-signatures -- these are separate to explicitly deprecate some SyncMode members.\r\n public static async open(args: DownloadAndOpenArgs & { syncMode: Exclude<SyncMode, \"FixedVersion\"> }): Promise<IModelDb>;\r\n /**\r\n * Download and open a checkpoint or briefcase, ensuring the operation completes within a default timeout. If the time to open exceeds the timeout period,\r\n * a RpcPendingResponse exception is thrown\r\n */\r\n public static async open(args: DownloadAndOpenArgs): Promise<IModelDb> {\r\n const { activity, tokenProps, syncMode } = args;\r\n Logger.logTrace(loggerCategory, \"RpcBriefcaseUtility.open\", tokenProps);\r\n\r\n const timeout = args.timeout ?? 1000;\r\n if (syncMode === SyncMode.PullOnly || syncMode === SyncMode.PullAndPush) {\r\n const briefcaseDb = await BeDuration.race(timeout, this.openBriefcase(args));\r\n\r\n if (briefcaseDb === undefined) {\r\n Logger.logTrace(loggerCategory, \"Open briefcase - pending\", tokenProps);\r\n throw new RpcPendingResponse(); // eslint-disable-line deprecation/deprecation\r\n }\r\n // note: usage is logged in the function BriefcaseManager.downloadNewBriefcaseAndOpen\r\n return briefcaseDb;\r\n }\r\n if (!tokenProps.iModelId || !tokenProps.iTwinId || !tokenProps.changeset)\r\n throw new IModelError(IModelStatus.BadArg, \"invalid arguments\");\r\n\r\n const checkpoint = {\r\n iModelId: tokenProps.iModelId,\r\n iTwinId: tokenProps.iTwinId,\r\n changeset: tokenProps.changeset,\r\n accessToken: activity.accessToken,\r\n };\r\n\r\n // opening a checkpoint.\r\n let db: SnapshotDb | void;\r\n // first check if it's already open\r\n db = SnapshotDb.tryFindByKey(CheckpointManager.getKey(checkpoint));\r\n if (db) {\r\n Logger.logTrace(loggerCategory, \"Checkpoint was already open\", tokenProps);\r\n return db;\r\n }\r\n\r\n try {\r\n // now try V2 checkpoint\r\n db = await SnapshotDb.openCheckpointFromRpc(checkpoint);\r\n Logger.logTrace(loggerCategory, \"using V2 checkpoint\", tokenProps);\r\n } catch (e) {\r\n Logger.logTrace(loggerCategory, \"unable to open V2 checkpoint - falling back to V1 checkpoint\", { error: BentleyError.getErrorProps(e), ...tokenProps });\r\n\r\n // this isn't a v2 checkpoint. Set up a race between the specified timeout period and the open. Throw an RpcPendingResponse exception if the timeout happens first.\r\n const request = {\r\n checkpoint,\r\n localFile: V1CheckpointManager.getFileName(checkpoint),\r\n aliasFiles: [],\r\n };\r\n db = await BeDuration.race(timeout, V1CheckpointManager.getCheckpointDb(request));\r\n\r\n if (db === undefined) {\r\n Logger.logTrace(loggerCategory, \"Open V1 checkpoint - pending\", tokenProps);\r\n throw new RpcPendingResponse(); // eslint-disable-line deprecation/deprecation\r\n }\r\n Logger.logTrace(loggerCategory, \"Opened V1 checkpoint\", tokenProps);\r\n }\r\n\r\n return db;\r\n }\r\n\r\n public static async openWithTimeout(activity: RpcActivity, tokenProps: IModelRpcOpenProps, syncMode: SyncMode.FixedVersion, timeout?: number): Promise<IModelConnectionProps>;\r\n /**\r\n * @deprecated in 4.4.0 - only `SyncMode.FixedVersion` should be used in RPC backends\r\n */\r\n // eslint-disable-next-line @typescript-eslint/unified-signatures -- these are separate to explicitly deprecate some SyncMode members.\r\n public static async openWithTimeout(activity: RpcActivity, tokenProps: IModelRpcOpenProps, syncMode: Exclude<SyncMode, \"FixedVersion\">, timeout?: number): Promise<IModelConnectionProps>;\r\n public static async openWithTimeout(activity: RpcActivity, tokenProps: IModelRpcOpenProps, syncMode: SyncMode, timeout: number = 1000): Promise<IModelConnectionProps> { // eslint-disable-line deprecation/deprecation\r\n if (tokenProps.iModelId)\r\n await IModelHost.tileStorage?.initialize(tokenProps.iModelId);\r\n // eslint-disable-next-line deprecation/deprecation\r\n return (await this.open({ activity, tokenProps, syncMode, timeout })).toJSON();\r\n }\r\n\r\n}\r\n"]}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@itwin/core-backend",
|
|
3
|
-
"version": "4.5.0-dev.
|
|
3
|
+
"version": "4.5.0-dev.9",
|
|
4
4
|
"description": "iTwin.js backend components",
|
|
5
5
|
"main": "lib/cjs/core-backend.js",
|
|
6
6
|
"typings": "lib/cjs/core-backend",
|
|
@@ -25,9 +25,9 @@
|
|
|
25
25
|
"url": "http://www.bentley.com"
|
|
26
26
|
},
|
|
27
27
|
"peerDependencies": {
|
|
28
|
-
"@itwin/core-bentley": "^4.5.0-dev.
|
|
29
|
-
"@itwin/core-common": "^4.5.0-dev.
|
|
30
|
-
"@itwin/core-geometry": "^4.5.0-dev.
|
|
28
|
+
"@itwin/core-bentley": "^4.5.0-dev.9",
|
|
29
|
+
"@itwin/core-common": "^4.5.0-dev.9",
|
|
30
|
+
"@itwin/core-geometry": "^4.5.0-dev.9",
|
|
31
31
|
"@opentelemetry/api": "^1.0.4"
|
|
32
32
|
},
|
|
33
33
|
"peerDependenciesMeta": {
|
|
@@ -69,16 +69,16 @@
|
|
|
69
69
|
"ts-node": "^10.8.2",
|
|
70
70
|
"typescript": "~5.0.2",
|
|
71
71
|
"webpack": "^5.76.0",
|
|
72
|
-
"@itwin/build-tools": "4.5.0-dev.
|
|
73
|
-
"@itwin/core-
|
|
74
|
-
"@itwin/core-
|
|
75
|
-
"@itwin/core-common": "4.5.0-dev.
|
|
76
|
-
"@itwin/
|
|
77
|
-
"@itwin/
|
|
72
|
+
"@itwin/build-tools": "4.5.0-dev.9",
|
|
73
|
+
"@itwin/core-webpack-tools": "4.5.0-dev.9",
|
|
74
|
+
"@itwin/core-bentley": "4.5.0-dev.9",
|
|
75
|
+
"@itwin/core-common": "4.5.0-dev.9",
|
|
76
|
+
"@itwin/ecsql-common": "4.5.0-dev.9",
|
|
77
|
+
"@itwin/core-geometry": "4.5.0-dev.9",
|
|
78
78
|
"internal-tools": "3.0.0-dev.69"
|
|
79
79
|
},
|
|
80
80
|
"dependencies": {
|
|
81
|
-
"@bentley/imodeljs-native": "4.4.
|
|
81
|
+
"@bentley/imodeljs-native": "4.4.3",
|
|
82
82
|
"@itwin/cloud-agnostic-core": "^2.1.0",
|
|
83
83
|
"@itwin/object-storage-azure": "^2.2.2",
|
|
84
84
|
"@itwin/object-storage-core": "^2.2.2",
|
|
@@ -91,7 +91,7 @@
|
|
|
91
91
|
"semver": "^7.3.5",
|
|
92
92
|
"touch": "^3.1.0",
|
|
93
93
|
"ws": "^7.5.3",
|
|
94
|
-
"@itwin/core-telemetry": "4.5.0-dev.
|
|
94
|
+
"@itwin/core-telemetry": "4.5.0-dev.9"
|
|
95
95
|
},
|
|
96
96
|
"nyc": {
|
|
97
97
|
"extends": "./node_modules/@itwin/build-tools/.nycrc"
|