@itwin/core-frontend 3.0.0-dev.147 → 3.0.0-dev.148
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/lib/cjs/CheckpointConnection.js +1 -1
- package/lib/cjs/CheckpointConnection.js.map +1 -1
- package/lib/cjs/FrontendHubAccess.d.ts +11 -7
- package/lib/cjs/FrontendHubAccess.d.ts.map +1 -1
- package/lib/cjs/FrontendHubAccess.js.map +1 -1
- package/lib/esm/CheckpointConnection.js +1 -1
- package/lib/esm/CheckpointConnection.js.map +1 -1
- package/lib/esm/FrontendHubAccess.d.ts +11 -7
- package/lib/esm/FrontendHubAccess.d.ts.map +1 -1
- package/lib/esm/FrontendHubAccess.js.map +1 -1
- package/package.json +22 -22
|
@@ -64,7 +64,7 @@ class CheckpointConnection extends IModelConnection_1.IModelConnection {
|
|
|
64
64
|
const accessToken = await IModelApp_1.IModelApp.getAccessToken();
|
|
65
65
|
if (undefined === IModelApp_1.IModelApp.hubAccess)
|
|
66
66
|
throw new Error("Missing an implementation of FrontendHubAccess on IModelApp, it is required to open a remote iModel Connection. Please provide an implementation to the IModelApp.startup using IModelAppOptions.hubAccess.");
|
|
67
|
-
const changeset =
|
|
67
|
+
const changeset = await IModelApp_1.IModelApp.hubAccess.getChangesetFromVersion({ accessToken, iModelId, version });
|
|
68
68
|
const iModelRpcProps = { iTwinId, iModelId, changeset };
|
|
69
69
|
const openResponse = await this.callOpen(iModelRpcProps, routingContext);
|
|
70
70
|
const connection = new this(openResponse);
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"CheckpointConnection.js","sourceRoot":"","sources":["../../src/CheckpointConnection.ts"],"names":[],"mappings":";AAAA;;;+FAG+F;AAC/F;;GAEG;;;AAEH,sDAAsF;AACtF,oDAG4B;AAC5B,qEAAkE;AAClE,2CAAwC;AACxC,yDAAsD;AACtD,iEAA8D;AAE9D,MAAM,cAAc,GAAG,+CAAsB,CAAC,gBAAgB,C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C;gBAC5K,MAAM,IAAI,yBAAW,CAAC,4BAAa,CAAC,KAAK,EAAE,oCAAoC,CAAC,CAAC,CAAC,yCAAyC;aAC5H;YAED,uBAAuB,GAAG,IAAI,CAAC,GAAG,CAAC,4BAA4B,CAAC,GAAG,EAAE,uBAAuB,GAAG,CAAC,EAAE,mCAAgB,CAAC,iBAAiB,GAAG,qBAAqB,CAAC,CAAC;YAC9J,IAAI,OAAO,CAAC,aAAa,KAAK,uBAAuB,EAAE;gBACrD,OAAO,CAAC,aAAa,GAAG,uBAAuB,CAAC;gBAChD,qBAAM,CAAC,QAAQ,CAAC,cAAc,EAAE,8CAA8C,OAAO,CAAC,aAAa,wCAAwC,EAAE,WAAW,CAAC,CAAC;aAC3J;QACH,CAAC,CAAC,CAAC;QAEH,MAAM,WAAW,GAAG,oCAAsB,CAAC,mBAAmB,CAAC,cAAc,CAAC,KAAK,CAAC,CAAC,kBAAkB,CAAC,WAAW,CAAC,CAAC;QACrH,IAAI,YAAmC,CAAC;QACxC,IAAI;YACF,YAAY,GAAG,MAAM,WAAW,CAAC;SAClC;gBAAS;YACR,qBAAM,CAAC,QAAQ,CAAC,cAAc,EAAE,iDAAiD,EAAE,WAAW,CAAC,CAAC;YAChG,cAAc,EAAE,CAAC;SAClB;QAED,OAAO,YAAY,CAAC;IACtB,CAAC;IA4BD,sCAAsC;IAC/B,KAAK,CAAC,KAAK;QAChB,IAAI,IAAI,CAAC,QAAQ;YACf,OAAO;QAET,IAAI,CAAC,WAAW,EAAE,CAAC;QACnB,wBAAU,CAAC,gBAAgB,CAAC,cAAc,CAAC,IAAI,CAAC,wBAAwB,CAAC,CAAC;QAC1E,IAAI,CAAC,SAAS,GAAG,IAAI,CAAC;IACxB,CAAC;CACF;AAvHD,oDAuHC","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 IModelConnection\r\n */\r\n\r\nimport { BentleyError, BentleyStatus, GuidString, Logger } from \"@itwin/core-bentley\";\r\nimport {\r\n IModelConnectionProps, IModelError, IModelReadRpcInterface, IModelRpcOpenProps, IModelVersion, RpcManager, RpcNotFoundResponse, RpcOperation,\r\n RpcRequest, RpcRequestEvent,\r\n} from \"@itwin/core-common\";\r\nimport { FrontendLoggerCategory } from \"./FrontendLoggerCategory\";\r\nimport { IModelApp } from \"./IModelApp\";\r\nimport { IModelConnection } from \"./IModelConnection\";\r\nimport { IModelRoutingContext } from \"./IModelRoutingContext\";\r\n\r\nconst loggerCategory = FrontendLoggerCategory.IModelConnection;\r\n\r\n/**\r\n * An IModelConnection to a checkpoint of an iModel, hosted on a remote backend over RPC.\r\n * Due to the nature of RPC requests, the backend servicing this connection may change over time, and there may even be more than one backend\r\n * at servicing requests at the same time. For this reason, this type of connection may only be used with Checkpoint iModels that are\r\n * guaranteed to be the same on every backend. Obviously Checkpoint iModels only allow readonly access.\r\n * @public\r\n */\r\nexport class CheckpointConnection extends IModelConnection {\r\n /** The Guid that identifies the iTwin that owns this iModel. */\r\n public override get iTwinId(): GuidString { return super.iTwinId!; }\r\n /** The Guid that identifies this iModel. */\r\n public override get iModelId(): GuidString { return super.iModelId!; }\r\n\r\n /** Returns `true` if [[close]] has already been called. */\r\n public get isClosed(): boolean { return this._isClosed ? true : false; }\r\n protected _isClosed?: boolean;\r\n\r\n /** Type guard for instanceof [[CheckpointConnection]] */\r\n public override isCheckpointConnection(): this is CheckpointConnection { return true; }\r\n\r\n /**\r\n * Open a readonly IModelConnection to an iModel over RPC.\r\n */\r\n public static async openRemote(iTwinId: string, iModelId: string, version: IModelVersion = IModelVersion.latest()): Promise<CheckpointConnection> {\r\n const routingContext = IModelRoutingContext.current || IModelRoutingContext.default;\r\n const accessToken = await IModelApp.getAccessToken();\r\n\r\n if (undefined === IModelApp.hubAccess)\r\n throw new Error(\"Missing an implementation of FrontendHubAccess on IModelApp, it is required to open a remote iModel Connection. Please provide an implementation to the IModelApp.startup using IModelAppOptions.hubAccess.\");\r\n\r\n const changeset = { id: await IModelApp.hubAccess.getChangesetIdFromVersion({ accessToken, iModelId, version }) };\r\n\r\n const iModelRpcProps: IModelRpcOpenProps = { iTwinId, iModelId, changeset };\r\n const openResponse = await this.callOpen(iModelRpcProps, routingContext);\r\n\r\n const connection = new this(openResponse);\r\n RpcManager.setIModel(connection);\r\n connection.routingContext = routingContext;\r\n RpcRequest.notFoundHandlers.addListener(connection._reopenConnectionHandler);\r\n\r\n IModelConnection.onOpen.raiseEvent(connection);\r\n return connection;\r\n }\r\n\r\n private static async callOpen(iModelToken: IModelRpcOpenProps, routingContext: IModelRoutingContext): Promise<IModelConnectionProps> {\r\n // Try opening the iModel repeatedly accommodating any pending responses from the backend.\r\n // Waits for an increasing amount of time (but within a range) before checking on the pending request again.\r\n const connectionRetryIntervalRange = { min: 100, max: 5000 }; // in milliseconds\r\n let connectionRetryInterval = Math.min(connectionRetryIntervalRange.min, IModelConnection.connectionTimeout);\r\n\r\n const openForReadOperation = RpcOperation.lookup(IModelReadRpcInterface, \"getConnectionProps\");\r\n if (!openForReadOperation)\r\n throw new IModelError(BentleyStatus.ERROR, \"IModelReadRpcInterface.getConnectionProps() is not available\");\r\n openForReadOperation.policy.retryInterval = () => connectionRetryInterval;\r\n\r\n Logger.logTrace(loggerCategory, `IModelConnection.open`, iModelToken);\r\n const startTime = Date.now();\r\n\r\n const removeListener = RpcRequest.events.addListener((type: RpcRequestEvent, request: RpcRequest) => {\r\n if (type !== RpcRequestEvent.PendingUpdateReceived)\r\n return;\r\n if (!(openForReadOperation && request.operation === openForReadOperation))\r\n return;\r\n\r\n Logger.logTrace(loggerCategory, \"Received pending open notification in IModelConnection.open\", iModelToken);\r\n\r\n const connectionTimeElapsed = Date.now() - startTime;\r\n if (connectionTimeElapsed > IModelConnection.connectionTimeout) {\r\n Logger.logError(loggerCategory, `Timed out opening connection in IModelConnection.open (took longer than ${IModelConnection.connectionTimeout} milliseconds)`, iModelToken);\r\n throw new IModelError(BentleyStatus.ERROR, \"Opening a connection was timed out\"); // NEEDS_WORK: More specific error status\r\n }\r\n\r\n connectionRetryInterval = Math.min(connectionRetryIntervalRange.max, connectionRetryInterval * 2, IModelConnection.connectionTimeout - connectionTimeElapsed);\r\n if (request.retryInterval !== connectionRetryInterval) {\r\n request.retryInterval = connectionRetryInterval;\r\n Logger.logTrace(loggerCategory, `Adjusted open connection retry interval to ${request.retryInterval} milliseconds in IModelConnection.open`, iModelToken);\r\n }\r\n });\r\n\r\n const openPromise = IModelReadRpcInterface.getClientForRouting(routingContext.token).getConnectionProps(iModelToken);\r\n let openResponse: IModelConnectionProps;\r\n try {\r\n openResponse = await openPromise;\r\n } finally {\r\n Logger.logTrace(loggerCategory, \"Completed open request in IModelConnection.open\", iModelToken);\r\n removeListener();\r\n }\r\n\r\n return openResponse;\r\n }\r\n\r\n private _reopenConnectionHandler = async (request: RpcRequest<RpcNotFoundResponse>, response: any, resubmit: () => void, reject: (reason: any) => void) => {\r\n if (!response.hasOwnProperty(\"isIModelNotFoundResponse\"))\r\n return;\r\n\r\n const iModelRpcProps = request.parameters[0];\r\n if (this._fileKey !== iModelRpcProps.key)\r\n return; // The handler is called for a different connection than this\r\n\r\n Logger.logTrace(loggerCategory, \"Attempting to reopen connection\", () => iModelRpcProps);\r\n\r\n try {\r\n const openResponse = await CheckpointConnection.callOpen(iModelRpcProps, this.routingContext);\r\n // The new/reopened connection may have a new rpcKey and/or changesetId, but the other IModelRpcTokenProps should be the same\r\n this._fileKey = openResponse.key;\r\n this.changeset = openResponse.changeset!;\r\n\r\n } catch (error) {\r\n reject(BentleyError.getErrorMessage(error));\r\n } finally {\r\n }\r\n\r\n Logger.logTrace(loggerCategory, \"Resubmitting original request after reopening connection\", iModelRpcProps);\r\n request.parameters[0] = this.getRpcProps(); // Modify the token of the original request before resubmitting it.\r\n resubmit();\r\n };\r\n\r\n /** Close this CheckpointConnection */\r\n public async close(): Promise<void> {\r\n if (this.isClosed)\r\n return;\r\n\r\n this.beforeClose();\r\n RpcRequest.notFoundHandlers.removeListener(this._reopenConnectionHandler);\r\n this._isClosed = true;\r\n }\r\n}\r\n"]}
|
|
1
|
+
{"version":3,"file":"CheckpointConnection.js","sourceRoot":"","sources":["../../src/CheckpointConnection.ts"],"names":[],"mappings":";AAAA;;;+FAG+F;AAC/F;;GAEG;;;AAEH,sDAAsF;AACtF,oDAG4B;AAC5B,qEAAkE;AAClE,2CAAwC;AACxC,yDAAsD;AACtD,iEAA8D;AAE9D,MAAM,cAAc,GAAG,+CAAsB,CAAC,gBAAgB,CAAC;AAE/D;;;;;;GAMG;AACH,MAAa,oBAAqB,SAAQ,mCAAgB;IAA1D;;QAoFU,6BAAwB,GAAG,KAAK,EAAE,OAAwC,EAAE,QAAa,EAAE,QAAoB,EAAE,MAA6B,EAAE,EAAE;YACxJ,IAAI,CAAC,QAAQ,CAAC,cAAc,CAAC,0BAA0B,CAAC;gBACtD,OAAO;YAET,MAAM,cAAc,GAAG,OAAO,CAAC,UAAU,CAAC,CAAC,CAAC,CAAC;YAC7C,IAAI,IAAI,CAAC,QAAQ,KAAK,cAAc,CAAC,GAAG;gBACtC,OAAO,CAAC,6DAA6D;YAEvE,qBAAM,CAAC,QAAQ,CAAC,cAAc,EAAE,iCAAiC,EAAE,GAAG,EAAE,CAAC,cAAc,CAAC,CAAC;YAEzF,IAAI;gBACF,MAAM,YAAY,GAAG,MAAM,oBAAoB,CAAC,QAAQ,CAAC,cAAc,EAAE,IAAI,CAAC,cAAc,CAAC,CAAC;gBAC9F,6HAA6H;gBAC7H,IAAI,CAAC,QAAQ,GAAG,YAAY,CAAC,GAAG,CAAC;gBACjC,IAAI,CAAC,SAAS,GAAG,YAAY,CAAC,SAAU,CAAC;aAE1C;YAAC,OAAO,KAAK,EAAE;gBACd,MAAM,CAAC,2BAAY,CAAC,eAAe,CAAC,KAAK,CAAC,CAAC,CAAC;aAC7C;oBA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AAC,KAAK;QAChB,IAAI,IAAI,CAAC,QAAQ;YACf,OAAO;QAET,IAAI,CAAC,WAAW,EAAE,CAAC;QACnB,wBAAU,CAAC,gBAAgB,CAAC,cAAc,CAAC,IAAI,CAAC,wBAAwB,CAAC,CAAC;QAC1E,IAAI,CAAC,SAAS,GAAG,IAAI,CAAC;IACxB,CAAC;CACF;AAvHD,oDAuHC","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 IModelConnection\r\n */\r\n\r\nimport { BentleyError, BentleyStatus, GuidString, Logger } from \"@itwin/core-bentley\";\r\nimport {\r\n IModelConnectionProps, IModelError, IModelReadRpcInterface, IModelRpcOpenProps, IModelVersion, RpcManager, RpcNotFoundResponse, RpcOperation,\r\n RpcRequest, RpcRequestEvent,\r\n} from \"@itwin/core-common\";\r\nimport { FrontendLoggerCategory } from \"./FrontendLoggerCategory\";\r\nimport { IModelApp } from \"./IModelApp\";\r\nimport { IModelConnection } from \"./IModelConnection\";\r\nimport { IModelRoutingContext } from \"./IModelRoutingContext\";\r\n\r\nconst loggerCategory = FrontendLoggerCategory.IModelConnection;\r\n\r\n/**\r\n * An IModelConnection to a checkpoint of an iModel, hosted on a remote backend over RPC.\r\n * Due to the nature of RPC requests, the backend servicing this connection may change over time, and there may even be more than one backend\r\n * at servicing requests at the same time. For this reason, this type of connection may only be used with Checkpoint iModels that are\r\n * guaranteed to be the same on every backend. Obviously Checkpoint iModels only allow readonly access.\r\n * @public\r\n */\r\nexport class CheckpointConnection extends IModelConnection {\r\n /** The Guid that identifies the iTwin that owns this iModel. */\r\n public override get iTwinId(): GuidString { return super.iTwinId!; }\r\n /** The Guid that identifies this iModel. */\r\n public override get iModelId(): GuidString { return super.iModelId!; }\r\n\r\n /** Returns `true` if [[close]] has already been called. */\r\n public get isClosed(): boolean { return this._isClosed ? true : false; }\r\n protected _isClosed?: boolean;\r\n\r\n /** Type guard for instanceof [[CheckpointConnection]] */\r\n public override isCheckpointConnection(): this is CheckpointConnection { return true; }\r\n\r\n /**\r\n * Open a readonly IModelConnection to an iModel over RPC.\r\n */\r\n public static async openRemote(iTwinId: string, iModelId: string, version: IModelVersion = IModelVersion.latest()): Promise<CheckpointConnection> {\r\n const routingContext = IModelRoutingContext.current || IModelRoutingContext.default;\r\n const accessToken = await IModelApp.getAccessToken();\r\n\r\n if (undefined === IModelApp.hubAccess)\r\n throw new Error(\"Missing an implementation of FrontendHubAccess on IModelApp, it is required to open a remote iModel Connection. Please provide an implementation to the IModelApp.startup using IModelAppOptions.hubAccess.\");\r\n\r\n const changeset = await IModelApp.hubAccess.getChangesetFromVersion({ accessToken, iModelId, version });\r\n\r\n const iModelRpcProps: IModelRpcOpenProps = { iTwinId, iModelId, changeset };\r\n const openResponse = await this.callOpen(iModelRpcProps, routingContext);\r\n\r\n const connection = new this(openResponse);\r\n RpcManager.setIModel(connection);\r\n connection.routingContext = routingContext;\r\n RpcRequest.notFoundHandlers.addListener(connection._reopenConnectionHandler);\r\n\r\n IModelConnection.onOpen.raiseEvent(connection);\r\n return connection;\r\n }\r\n\r\n private static async callOpen(iModelToken: IModelRpcOpenProps, routingContext: IModelRoutingContext): Promise<IModelConnectionProps> {\r\n // Try opening the iModel repeatedly accommodating any pending responses from the backend.\r\n // Waits for an increasing amount of time (but within a range) before checking on the pending request again.\r\n const connectionRetryIntervalRange = { min: 100, max: 5000 }; // in milliseconds\r\n let connectionRetryInterval = Math.min(connectionRetryIntervalRange.min, IModelConnection.connectionTimeout);\r\n\r\n const openForReadOperation = RpcOperation.lookup(IModelReadRpcInterface, \"getConnectionProps\");\r\n if (!openForReadOperation)\r\n throw new IModelError(BentleyStatus.ERROR, \"IModelReadRpcInterface.getConnectionProps() is not available\");\r\n openForReadOperation.policy.retryInterval = () => connectionRetryInterval;\r\n\r\n Logger.logTrace(loggerCategory, `IModelConnection.open`, iModelToken);\r\n const startTime = Date.now();\r\n\r\n const removeListener = RpcRequest.events.addListener((type: RpcRequestEvent, request: RpcRequest) => {\r\n if (type !== RpcRequestEvent.PendingUpdateReceived)\r\n return;\r\n if (!(openForReadOperation && request.operation === openForReadOperation))\r\n return;\r\n\r\n Logger.logTrace(loggerCategory, \"Received pending open notification in IModelConnection.open\", iModelToken);\r\n\r\n const connectionTimeElapsed = Date.now() - startTime;\r\n if (connectionTimeElapsed > IModelConnection.connectionTimeout) {\r\n Logger.logError(loggerCategory, `Timed out opening connection in IModelConnection.open (took longer than ${IModelConnection.connectionTimeout} milliseconds)`, iModelToken);\r\n throw new IModelError(BentleyStatus.ERROR, \"Opening a connection was timed out\"); // NEEDS_WORK: More specific error status\r\n }\r\n\r\n connectionRetryInterval = Math.min(connectionRetryIntervalRange.max, connectionRetryInterval * 2, IModelConnection.connectionTimeout - connectionTimeElapsed);\r\n if (request.retryInterval !== connectionRetryInterval) {\r\n request.retryInterval = connectionRetryInterval;\r\n Logger.logTrace(loggerCategory, `Adjusted open connection retry interval to ${request.retryInterval} milliseconds in IModelConnection.open`, iModelToken);\r\n }\r\n });\r\n\r\n const openPromise = IModelReadRpcInterface.getClientForRouting(routingContext.token).getConnectionProps(iModelToken);\r\n let openResponse: IModelConnectionProps;\r\n try {\r\n openResponse = await openPromise;\r\n } finally {\r\n Logger.logTrace(loggerCategory, \"Completed open request in IModelConnection.open\", iModelToken);\r\n removeListener();\r\n }\r\n\r\n return openResponse;\r\n }\r\n\r\n private _reopenConnectionHandler = async (request: RpcRequest<RpcNotFoundResponse>, response: any, resubmit: () => void, reject: (reason: any) => void) => {\r\n if (!response.hasOwnProperty(\"isIModelNotFoundResponse\"))\r\n return;\r\n\r\n const iModelRpcProps = request.parameters[0];\r\n if (this._fileKey !== iModelRpcProps.key)\r\n return; // The handler is called for a different connection than this\r\n\r\n Logger.logTrace(loggerCategory, \"Attempting to reopen connection\", () => iModelRpcProps);\r\n\r\n try {\r\n const openResponse = await CheckpointConnection.callOpen(iModelRpcProps, this.routingContext);\r\n // The new/reopened connection may have a new rpcKey and/or changesetId, but the other IModelRpcTokenProps should be the same\r\n this._fileKey = openResponse.key;\r\n this.changeset = openResponse.changeset!;\r\n\r\n } catch (error) {\r\n reject(BentleyError.getErrorMessage(error));\r\n } finally {\r\n }\r\n\r\n Logger.logTrace(loggerCategory, \"Resubmitting original request after reopening connection\", iModelRpcProps);\r\n request.parameters[0] = this.getRpcProps(); // Modify the token of the original request before resubmitting it.\r\n resubmit();\r\n };\r\n\r\n /** Close this CheckpointConnection */\r\n public async close(): Promise<void> {\r\n if (this.isClosed)\r\n return;\r\n\r\n this.beforeClose();\r\n RpcRequest.notFoundHandlers.removeListener(this._reopenConnectionHandler);\r\n this._isClosed = true;\r\n }\r\n}\r\n"]}
|
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
* @module HubAccess
|
|
3
3
|
*/
|
|
4
4
|
import { AccessToken, GuidString } from "@itwin/core-bentley";
|
|
5
|
-
import {
|
|
5
|
+
import { ChangesetIndexAndId, IModelVersion } from "@itwin/core-common";
|
|
6
6
|
/** @public */
|
|
7
7
|
export interface IModelIdArg {
|
|
8
8
|
iModelId: GuidString;
|
|
@@ -10,12 +10,16 @@ export interface IModelIdArg {
|
|
|
10
10
|
}
|
|
11
11
|
/** @public */
|
|
12
12
|
export interface FrontendHubAccess {
|
|
13
|
-
|
|
14
|
-
|
|
13
|
+
getLatestChangeset(arg: IModelIdArg): Promise<ChangesetIndexAndId>;
|
|
14
|
+
getChangesetFromVersion(arg: IModelIdArg & {
|
|
15
15
|
version: IModelVersion;
|
|
16
|
-
}): Promise<
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
16
|
+
}): Promise<ChangesetIndexAndId>;
|
|
17
|
+
/**
|
|
18
|
+
* Fetches the changeset with the given named version.
|
|
19
|
+
* @param versionName If omitted will default to the latest named version.
|
|
20
|
+
*/
|
|
21
|
+
getChangesetFromNamedVersion(arg: IModelIdArg & {
|
|
22
|
+
versionName?: string;
|
|
23
|
+
}): Promise<ChangesetIndexAndId>;
|
|
20
24
|
}
|
|
21
25
|
//# sourceMappingURL=FrontendHubAccess.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"FrontendHubAccess.d.ts","sourceRoot":"","sources":["../../src/FrontendHubAccess.ts"],"names":[],"mappings":"AAIA;;GAEG;AAEH,OAAO,EAAE,WAAW,EAAE,UAAU,EAAE,MAAM,qBAAqB,CAAC;AAC9D,OAAO,EAAE,
|
|
1
|
+
{"version":3,"file":"FrontendHubAccess.d.ts","sourceRoot":"","sources":["../../src/FrontendHubAccess.ts"],"names":[],"mappings":"AAIA;;GAEG;AAEH,OAAO,EAAE,WAAW,EAAE,UAAU,EAAE,MAAM,qBAAqB,CAAC;AAC9D,OAAO,EAAE,mBAAmB,EAAE,aAAa,EAAE,MAAM,oBAAoB,CAAC;AAExE,cAAc;AACd,MAAM,WAAW,WAAW;IAC1B,QAAQ,EAAE,UAAU,CAAC;IACrB,WAAW,EAAE,WAAW,CAAC;CAC1B;AAED,cAAc;AACd,MAAM,WAAW,iBAAiB;IAChC,kBAAkB,CAAC,GAAG,EAAE,WAAW,GAAG,OAAO,CAAC,mBAAmB,CAAC,CAAC;IACnE,uBAAuB,CAAC,GAAG,EAAE,WAAW,GAAG;QAAE,OAAO,EAAE,aAAa,CAAA;KAAE,GAAG,OAAO,CAAC,mBAAmB,CAAC,CAAC;IACrG;;;OAGG;IACH,4BAA4B,CAAC,GAAG,EAAE,WAAW,GAAG;QAAE,WAAW,CAAC,EAAE,MAAM,CAAA;KAAE,GAAG,OAAO,CAAC,mBAAmB,CAAC,CAAC;CACzG"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"FrontendHubAccess.js","sourceRoot":"","sources":["../../src/FrontendHubAccess.ts"],"names":[],"mappings":";AAAA;;;+FAG+F;AAC/F;;GAEG","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 HubAccess\r\n */\r\n\r\nimport { AccessToken, GuidString } from \"@itwin/core-bentley\";\r\nimport {
|
|
1
|
+
{"version":3,"file":"FrontendHubAccess.js","sourceRoot":"","sources":["../../src/FrontendHubAccess.ts"],"names":[],"mappings":";AAAA;;;+FAG+F;AAC/F;;GAEG","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 HubAccess\r\n */\r\n\r\nimport { AccessToken, GuidString } from \"@itwin/core-bentley\";\r\nimport { ChangesetIndexAndId, IModelVersion } from \"@itwin/core-common\";\r\n\r\n/** @public */\r\nexport interface IModelIdArg {\r\n iModelId: GuidString;\r\n accessToken: AccessToken;\r\n}\r\n\r\n/** @public */\r\nexport interface FrontendHubAccess {\r\n getLatestChangeset(arg: IModelIdArg): Promise<ChangesetIndexAndId>;\r\n getChangesetFromVersion(arg: IModelIdArg & { version: IModelVersion }): Promise<ChangesetIndexAndId>;\r\n /**\r\n * Fetches the changeset with the given named version.\r\n * @param versionName If omitted will default to the latest named version.\r\n */\r\n getChangesetFromNamedVersion(arg: IModelIdArg & { versionName?: string }): Promise<ChangesetIndexAndId>;\r\n}\r\n"]}
|
|
@@ -61,7 +61,7 @@ export class CheckpointConnection extends IModelConnection {
|
|
|
61
61
|
const accessToken = await IModelApp.getAccessToken();
|
|
62
62
|
if (undefined === IModelApp.hubAccess)
|
|
63
63
|
throw new Error("Missing an implementation of FrontendHubAccess on IModelApp, it is required to open a remote iModel Connection. Please provide an implementation to the IModelApp.startup using IModelAppOptions.hubAccess.");
|
|
64
|
-
const changeset =
|
|
64
|
+
const changeset = await IModelApp.hubAccess.getChangesetFromVersion({ accessToken, iModelId, version });
|
|
65
65
|
const iModelRpcProps = { iTwinId, iModelId, changeset };
|
|
66
66
|
const openResponse = await this.callOpen(iModelRpcProps, routingContext);
|
|
67
67
|
const connection = new this(openResponse);
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"CheckpointConnection.js","sourceRoot":"","sources":["../../src/CheckpointConnection.ts"],"names":[],"mappings":"AAAA;;;+FAG+F;AAC/F;;GAEG;AAEH,OAAO,EAAE,YAAY,EAAE,aAAa,EAAc,MAAM,EAAE,MAAM,qBAAqB,CAAC;AACtF,OAAO,EACkB,WAAW,EAAE,sBAAsB,EAAsB,aAAa,EAAE,UAAU,EAAuB,YAAY,EAC5I,UAAU,EAAE,eAAe,GAC5B,MAAM,oBAAoB,CAAC;AAC5B,OAAO,EAAE,sBAAsB,EAAE,MAAM,0BAA0B,CAAC;AAClE,OAAO,EAAE,SAAS,EAAE,MAAM,aAAa,CAAC;AACxC,OAAO,EAAE,gBAAgB,EAAE,MAAM,oBAAoB,CAAC;AACtD,OAAO,EAAE,oBAAoB,EAAE,MAAM,wBAAwB,CAAC;AAE9D,MAAM,cAAc,GAAG,sBAAsB,CAAC,gBAAgB,CAAC;AAE/D;;;;;;GAMG;AACH,MAAM,OAAO,oBAAqB,SAAQ,gBAAgB;IAA1D;;QAoFU,6BAAwB,GAAG,KAAK,EAAE,OAAwC,EAAE,QAAa,EAAE,QAAoB,EAAE,MAA6B,EAAE,EAAE;YACxJ,IAAI,CAAC,QAAQ,CAAC,cAAc,CAAC,0BAA0B,CAAC;gBACtD,OAAO;YAET,MAAM,cAAc,GAAG,OAAO,CAAC,UAAU,CAAC,CAAC,CAAC,CAAC;YAC7C,IAAI,IAAI,CAAC,QAAQ,KAAK,cAAc,CAAC,GAAG;gBACtC,OAAO,CAAC,6DAA6D;YAEvE,MAAM,CAAC,QAAQ,CAAC,cAAc,EAAE,iCAAiC,EAAE,GAAG,EAAE,CAAC,cAAc,CAA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M,WAAW,GAAG,sBAAsB,CAAC,mBAAmB,CAAC,cAAc,CAAC,KAAK,CAAC,CAAC,kBAAkB,CAAC,WAAW,CAAC,CAAC;QACrH,IAAI,YAAmC,CAAC;QACxC,IAAI;YACF,YAAY,GAAG,MAAM,WAAW,CAAC;SAClC;gBAAS;YACR,MAAM,CAAC,QAAQ,CAAC,cAAc,EAAE,iDAAiD,EAAE,WAAW,CAAC,CAAC;YAChG,cAAc,EAAE,CAAC;SAClB;QAED,OAAO,YAAY,CAAC;IACtB,CAAC;IA4BD,sCAAsC;IAC/B,KAAK,CAAC,KAAK;QAChB,IAAI,IAAI,CAAC,QAAQ;YACf,OAAO;QAET,IAAI,CAAC,WAAW,EAAE,CAAC;QACnB,UAAU,CAAC,gBAAgB,CAAC,cAAc,CAAC,IAAI,CAAC,wBAAwB,CAAC,CAAC;QAC1E,IAAI,CAAC,SAAS,GAAG,IAAI,CAAC;IACxB,CAAC;CACF","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 IModelConnection\r\n */\r\n\r\nimport { BentleyError, BentleyStatus, GuidString, Logger } from \"@itwin/core-bentley\";\r\nimport {\r\n IModelConnectionProps, IModelError, IModelReadRpcInterface, IModelRpcOpenProps, IModelVersion, RpcManager, RpcNotFoundResponse, RpcOperation,\r\n RpcRequest, RpcRequestEvent,\r\n} from \"@itwin/core-common\";\r\nimport { FrontendLoggerCategory } from \"./FrontendLoggerCategory\";\r\nimport { IModelApp } from \"./IModelApp\";\r\nimport { IModelConnection } from \"./IModelConnection\";\r\nimport { IModelRoutingContext } from \"./IModelRoutingContext\";\r\n\r\nconst loggerCategory = FrontendLoggerCategory.IModelConnection;\r\n\r\n/**\r\n * An IModelConnection to a checkpoint of an iModel, hosted on a remote backend over RPC.\r\n * Due to the nature of RPC requests, the backend servicing this connection may change over time, and there may even be more than one backend\r\n * at servicing requests at the same time. For this reason, this type of connection may only be used with Checkpoint iModels that are\r\n * guaranteed to be the same on every backend. Obviously Checkpoint iModels only allow readonly access.\r\n * @public\r\n */\r\nexport class CheckpointConnection extends IModelConnection {\r\n /** The Guid that identifies the iTwin that owns this iModel. */\r\n public override get iTwinId(): GuidString { return super.iTwinId!; }\r\n /** The Guid that identifies this iModel. */\r\n public override get iModelId(): GuidString { return super.iModelId!; }\r\n\r\n /** Returns `true` if [[close]] has already been called. */\r\n public get isClosed(): boolean { return this._isClosed ? true : false; }\r\n protected _isClosed?: boolean;\r\n\r\n /** Type guard for instanceof [[CheckpointConnection]] */\r\n public override isCheckpointConnection(): this is CheckpointConnection { return true; }\r\n\r\n /**\r\n * Open a readonly IModelConnection to an iModel over RPC.\r\n */\r\n public static async openRemote(iTwinId: string, iModelId: string, version: IModelVersion = IModelVersion.latest()): Promise<CheckpointConnection> {\r\n const routingContext = IModelRoutingContext.current || IModelRoutingContext.default;\r\n const accessToken = await IModelApp.getAccessToken();\r\n\r\n if (undefined === IModelApp.hubAccess)\r\n throw new Error(\"Missing an implementation of FrontendHubAccess on IModelApp, it is required to open a remote iModel Connection. Please provide an implementation to the IModelApp.startup using IModelAppOptions.hubAccess.\");\r\n\r\n const changeset = { id: await IModelApp.hubAccess.getChangesetIdFromVersion({ accessToken, iModelId, version }) };\r\n\r\n const iModelRpcProps: IModelRpcOpenProps = { iTwinId, iModelId, changeset };\r\n const openResponse = await this.callOpen(iModelRpcProps, routingContext);\r\n\r\n const connection = new this(openResponse);\r\n RpcManager.setIModel(connection);\r\n connection.routingContext = routingContext;\r\n RpcRequest.notFoundHandlers.addListener(connection._reopenConnectionHandler);\r\n\r\n IModelConnection.onOpen.raiseEvent(connection);\r\n return connection;\r\n }\r\n\r\n private static async callOpen(iModelToken: IModelRpcOpenProps, routingContext: IModelRoutingContext): Promise<IModelConnectionProps> {\r\n // Try opening the iModel repeatedly accommodating any pending responses from the backend.\r\n // Waits for an increasing amount of time (but within a range) before checking on the pending request again.\r\n const connectionRetryIntervalRange = { min: 100, max: 5000 }; // in milliseconds\r\n let connectionRetryInterval = Math.min(connectionRetryIntervalRange.min, IModelConnection.connectionTimeout);\r\n\r\n const openForReadOperation = RpcOperation.lookup(IModelReadRpcInterface, \"getConnectionProps\");\r\n if (!openForReadOperation)\r\n throw new IModelError(BentleyStatus.ERROR, \"IModelReadRpcInterface.getConnectionProps() is not available\");\r\n openForReadOperation.policy.retryInterval = () => connectionRetryInterval;\r\n\r\n Logger.logTrace(loggerCategory, `IModelConnection.open`, iModelToken);\r\n const startTime = Date.now();\r\n\r\n const removeListener = RpcRequest.events.addListener((type: RpcRequestEvent, request: RpcRequest) => {\r\n if (type !== RpcRequestEvent.PendingUpdateReceived)\r\n return;\r\n if (!(openForReadOperation && request.operation === openForReadOperation))\r\n return;\r\n\r\n Logger.logTrace(loggerCategory, \"Received pending open notification in IModelConnection.open\", iModelToken);\r\n\r\n const connectionTimeElapsed = Date.now() - startTime;\r\n if (connectionTimeElapsed > IModelConnection.connectionTimeout) {\r\n Logger.logError(loggerCategory, `Timed out opening connection in IModelConnection.open (took longer than ${IModelConnection.connectionTimeout} milliseconds)`, iModelToken);\r\n throw new IModelError(BentleyStatus.ERROR, \"Opening a connection was timed out\"); // NEEDS_WORK: More specific error status\r\n }\r\n\r\n connectionRetryInterval = Math.min(connectionRetryIntervalRange.max, connectionRetryInterval * 2, IModelConnection.connectionTimeout - connectionTimeElapsed);\r\n if (request.retryInterval !== connectionRetryInterval) {\r\n request.retryInterval = connectionRetryInterval;\r\n Logger.logTrace(loggerCategory, `Adjusted open connection retry interval to ${request.retryInterval} milliseconds in IModelConnection.open`, iModelToken);\r\n }\r\n });\r\n\r\n const openPromise = IModelReadRpcInterface.getClientForRouting(routingContext.token).getConnectionProps(iModelToken);\r\n let openResponse: IModelConnectionProps;\r\n try {\r\n openResponse = await openPromise;\r\n } finally {\r\n Logger.logTrace(loggerCategory, \"Completed open request in IModelConnection.open\", iModelToken);\r\n removeListener();\r\n }\r\n\r\n return openResponse;\r\n }\r\n\r\n private _reopenConnectionHandler = async (request: RpcRequest<RpcNotFoundResponse>, response: any, resubmit: () => void, reject: (reason: any) => void) => {\r\n if (!response.hasOwnProperty(\"isIModelNotFoundResponse\"))\r\n return;\r\n\r\n const iModelRpcProps = request.parameters[0];\r\n if (this._fileKey !== iModelRpcProps.key)\r\n return; // The handler is called for a different connection than this\r\n\r\n Logger.logTrace(loggerCategory, \"Attempting to reopen connection\", () => iModelRpcProps);\r\n\r\n try {\r\n const openResponse = await CheckpointConnection.callOpen(iModelRpcProps, this.routingContext);\r\n // The new/reopened connection may have a new rpcKey and/or changesetId, but the other IModelRpcTokenProps should be the same\r\n this._fileKey = openResponse.key;\r\n this.changeset = openResponse.changeset!;\r\n\r\n } catch (error) {\r\n reject(BentleyError.getErrorMessage(error));\r\n } finally {\r\n }\r\n\r\n Logger.logTrace(loggerCategory, \"Resubmitting original request after reopening connection\", iModelRpcProps);\r\n request.parameters[0] = this.getRpcProps(); // Modify the token of the original request before resubmitting it.\r\n resubmit();\r\n };\r\n\r\n /** Close this CheckpointConnection */\r\n public async close(): Promise<void> {\r\n if (this.isClosed)\r\n return;\r\n\r\n this.beforeClose();\r\n RpcRequest.notFoundHandlers.removeListener(this._reopenConnectionHandler);\r\n this._isClosed = true;\r\n }\r\n}\r\n"]}
|
|
1
|
+
{"version":3,"file":"CheckpointConnection.js","sourceRoot":"","sources":["../../src/CheckpointConnection.ts"],"names":[],"mappings":"AAAA;;;+FAG+F;AAC/F;;GAEG;AAEH,OAAO,EAAE,YAAY,EAAE,aAAa,EAAc,MAAM,EAAE,MAAM,qBAAqB,CAAC;AACtF,OAAO,EACkB,WAAW,EAAE,sBAAsB,EAAsB,aAAa,EAAE,UAAU,EAAuB,YAAY,EAC5I,UAAU,EAAE,eAAe,GAC5B,MAAM,oBAAoB,CAAC;AAC5B,OAAO,EAAE,sBAAsB,EAAE,MAAM,0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C;IACxB,CAAC;CACF","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 IModelConnection\r\n */\r\n\r\nimport { BentleyError, BentleyStatus, GuidString, Logger } from \"@itwin/core-bentley\";\r\nimport {\r\n IModelConnectionProps, IModelError, IModelReadRpcInterface, IModelRpcOpenProps, IModelVersion, RpcManager, RpcNotFoundResponse, RpcOperation,\r\n RpcRequest, RpcRequestEvent,\r\n} from \"@itwin/core-common\";\r\nimport { FrontendLoggerCategory } from \"./FrontendLoggerCategory\";\r\nimport { IModelApp } from \"./IModelApp\";\r\nimport { IModelConnection } from \"./IModelConnection\";\r\nimport { IModelRoutingContext } from \"./IModelRoutingContext\";\r\n\r\nconst loggerCategory = FrontendLoggerCategory.IModelConnection;\r\n\r\n/**\r\n * An IModelConnection to a checkpoint of an iModel, hosted on a remote backend over RPC.\r\n * Due to the nature of RPC requests, the backend servicing this connection may change over time, and there may even be more than one backend\r\n * at servicing requests at the same time. For this reason, this type of connection may only be used with Checkpoint iModels that are\r\n * guaranteed to be the same on every backend. Obviously Checkpoint iModels only allow readonly access.\r\n * @public\r\n */\r\nexport class CheckpointConnection extends IModelConnection {\r\n /** The Guid that identifies the iTwin that owns this iModel. */\r\n public override get iTwinId(): GuidString { return super.iTwinId!; }\r\n /** The Guid that identifies this iModel. */\r\n public override get iModelId(): GuidString { return super.iModelId!; }\r\n\r\n /** Returns `true` if [[close]] has already been called. */\r\n public get isClosed(): boolean { return this._isClosed ? true : false; }\r\n protected _isClosed?: boolean;\r\n\r\n /** Type guard for instanceof [[CheckpointConnection]] */\r\n public override isCheckpointConnection(): this is CheckpointConnection { return true; }\r\n\r\n /**\r\n * Open a readonly IModelConnection to an iModel over RPC.\r\n */\r\n public static async openRemote(iTwinId: string, iModelId: string, version: IModelVersion = IModelVersion.latest()): Promise<CheckpointConnection> {\r\n const routingContext = IModelRoutingContext.current || IModelRoutingContext.default;\r\n const accessToken = await IModelApp.getAccessToken();\r\n\r\n if (undefined === IModelApp.hubAccess)\r\n throw new Error(\"Missing an implementation of FrontendHubAccess on IModelApp, it is required to open a remote iModel Connection. Please provide an implementation to the IModelApp.startup using IModelAppOptions.hubAccess.\");\r\n\r\n const changeset = await IModelApp.hubAccess.getChangesetFromVersion({ accessToken, iModelId, version });\r\n\r\n const iModelRpcProps: IModelRpcOpenProps = { iTwinId, iModelId, changeset };\r\n const openResponse = await this.callOpen(iModelRpcProps, routingContext);\r\n\r\n const connection = new this(openResponse);\r\n RpcManager.setIModel(connection);\r\n connection.routingContext = routingContext;\r\n RpcRequest.notFoundHandlers.addListener(connection._reopenConnectionHandler);\r\n\r\n IModelConnection.onOpen.raiseEvent(connection);\r\n return connection;\r\n }\r\n\r\n private static async callOpen(iModelToken: IModelRpcOpenProps, routingContext: IModelRoutingContext): Promise<IModelConnectionProps> {\r\n // Try opening the iModel repeatedly accommodating any pending responses from the backend.\r\n // Waits for an increasing amount of time (but within a range) before checking on the pending request again.\r\n const connectionRetryIntervalRange = { min: 100, max: 5000 }; // in milliseconds\r\n let connectionRetryInterval = Math.min(connectionRetryIntervalRange.min, IModelConnection.connectionTimeout);\r\n\r\n const openForReadOperation = RpcOperation.lookup(IModelReadRpcInterface, \"getConnectionProps\");\r\n if (!openForReadOperation)\r\n throw new IModelError(BentleyStatus.ERROR, \"IModelReadRpcInterface.getConnectionProps() is not available\");\r\n openForReadOperation.policy.retryInterval = () => connectionRetryInterval;\r\n\r\n Logger.logTrace(loggerCategory, `IModelConnection.open`, iModelToken);\r\n const startTime = Date.now();\r\n\r\n const removeListener = RpcRequest.events.addListener((type: RpcRequestEvent, request: RpcRequest) => {\r\n if (type !== RpcRequestEvent.PendingUpdateReceived)\r\n return;\r\n if (!(openForReadOperation && request.operation === openForReadOperation))\r\n return;\r\n\r\n Logger.logTrace(loggerCategory, \"Received pending open notification in IModelConnection.open\", iModelToken);\r\n\r\n const connectionTimeElapsed = Date.now() - startTime;\r\n if (connectionTimeElapsed > IModelConnection.connectionTimeout) {\r\n Logger.logError(loggerCategory, `Timed out opening connection in IModelConnection.open (took longer than ${IModelConnection.connectionTimeout} milliseconds)`, iModelToken);\r\n throw new IModelError(BentleyStatus.ERROR, \"Opening a connection was timed out\"); // NEEDS_WORK: More specific error status\r\n }\r\n\r\n connectionRetryInterval = Math.min(connectionRetryIntervalRange.max, connectionRetryInterval * 2, IModelConnection.connectionTimeout - connectionTimeElapsed);\r\n if (request.retryInterval !== connectionRetryInterval) {\r\n request.retryInterval = connectionRetryInterval;\r\n Logger.logTrace(loggerCategory, `Adjusted open connection retry interval to ${request.retryInterval} milliseconds in IModelConnection.open`, iModelToken);\r\n }\r\n });\r\n\r\n const openPromise = IModelReadRpcInterface.getClientForRouting(routingContext.token).getConnectionProps(iModelToken);\r\n let openResponse: IModelConnectionProps;\r\n try {\r\n openResponse = await openPromise;\r\n } finally {\r\n Logger.logTrace(loggerCategory, \"Completed open request in IModelConnection.open\", iModelToken);\r\n removeListener();\r\n }\r\n\r\n return openResponse;\r\n }\r\n\r\n private _reopenConnectionHandler = async (request: RpcRequest<RpcNotFoundResponse>, response: any, resubmit: () => void, reject: (reason: any) => void) => {\r\n if (!response.hasOwnProperty(\"isIModelNotFoundResponse\"))\r\n return;\r\n\r\n const iModelRpcProps = request.parameters[0];\r\n if (this._fileKey !== iModelRpcProps.key)\r\n return; // The handler is called for a different connection than this\r\n\r\n Logger.logTrace(loggerCategory, \"Attempting to reopen connection\", () => iModelRpcProps);\r\n\r\n try {\r\n const openResponse = await CheckpointConnection.callOpen(iModelRpcProps, this.routingContext);\r\n // The new/reopened connection may have a new rpcKey and/or changesetId, but the other IModelRpcTokenProps should be the same\r\n this._fileKey = openResponse.key;\r\n this.changeset = openResponse.changeset!;\r\n\r\n } catch (error) {\r\n reject(BentleyError.getErrorMessage(error));\r\n } finally {\r\n }\r\n\r\n Logger.logTrace(loggerCategory, \"Resubmitting original request after reopening connection\", iModelRpcProps);\r\n request.parameters[0] = this.getRpcProps(); // Modify the token of the original request before resubmitting it.\r\n resubmit();\r\n };\r\n\r\n /** Close this CheckpointConnection */\r\n public async close(): Promise<void> {\r\n if (this.isClosed)\r\n return;\r\n\r\n this.beforeClose();\r\n RpcRequest.notFoundHandlers.removeListener(this._reopenConnectionHandler);\r\n this._isClosed = true;\r\n }\r\n}\r\n"]}
|
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
* @module HubAccess
|
|
3
3
|
*/
|
|
4
4
|
import { AccessToken, GuidString } from "@itwin/core-bentley";
|
|
5
|
-
import {
|
|
5
|
+
import { ChangesetIndexAndId, IModelVersion } from "@itwin/core-common";
|
|
6
6
|
/** @public */
|
|
7
7
|
export interface IModelIdArg {
|
|
8
8
|
iModelId: GuidString;
|
|
@@ -10,12 +10,16 @@ export interface IModelIdArg {
|
|
|
10
10
|
}
|
|
11
11
|
/** @public */
|
|
12
12
|
export interface FrontendHubAccess {
|
|
13
|
-
|
|
14
|
-
|
|
13
|
+
getLatestChangeset(arg: IModelIdArg): Promise<ChangesetIndexAndId>;
|
|
14
|
+
getChangesetFromVersion(arg: IModelIdArg & {
|
|
15
15
|
version: IModelVersion;
|
|
16
|
-
}): Promise<
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
16
|
+
}): Promise<ChangesetIndexAndId>;
|
|
17
|
+
/**
|
|
18
|
+
* Fetches the changeset with the given named version.
|
|
19
|
+
* @param versionName If omitted will default to the latest named version.
|
|
20
|
+
*/
|
|
21
|
+
getChangesetFromNamedVersion(arg: IModelIdArg & {
|
|
22
|
+
versionName?: string;
|
|
23
|
+
}): Promise<ChangesetIndexAndId>;
|
|
20
24
|
}
|
|
21
25
|
//# sourceMappingURL=FrontendHubAccess.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"FrontendHubAccess.d.ts","sourceRoot":"","sources":["../../src/FrontendHubAccess.ts"],"names":[],"mappings":"AAIA;;GAEG;AAEH,OAAO,EAAE,WAAW,EAAE,UAAU,EAAE,MAAM,qBAAqB,CAAC;AAC9D,OAAO,EAAE,
|
|
1
|
+
{"version":3,"file":"FrontendHubAccess.d.ts","sourceRoot":"","sources":["../../src/FrontendHubAccess.ts"],"names":[],"mappings":"AAIA;;GAEG;AAEH,OAAO,EAAE,WAAW,EAAE,UAAU,EAAE,MAAM,qBAAqB,CAAC;AAC9D,OAAO,EAAE,mBAAmB,EAAE,aAAa,EAAE,MAAM,oBAAoB,CAAC;AAExE,cAAc;AACd,MAAM,WAAW,WAAW;IAC1B,QAAQ,EAAE,UAAU,CAAC;IACrB,WAAW,EAAE,WAAW,CAAC;CAC1B;AAED,cAAc;AACd,MAAM,WAAW,iBAAiB;IAChC,kBAAkB,CAAC,GAAG,EAAE,WAAW,GAAG,OAAO,CAAC,mBAAmB,CAAC,CAAC;IACnE,uBAAuB,CAAC,GAAG,EAAE,WAAW,GAAG;QAAE,OAAO,EAAE,aAAa,CAAA;KAAE,GAAG,OAAO,CAAC,mBAAmB,CAAC,CAAC;IACrG;;;OAGG;IACH,4BAA4B,CAAC,GAAG,EAAE,WAAW,GAAG;QAAE,WAAW,CAAC,EAAE,MAAM,CAAA;KAAE,GAAG,OAAO,CAAC,mBAAmB,CAAC,CAAC;CACzG"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"FrontendHubAccess.js","sourceRoot":"","sources":["../../src/FrontendHubAccess.ts"],"names":[],"mappings":"AAAA;;;+FAG+F;AAC/F;;GAEG","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 HubAccess\r\n */\r\n\r\nimport { AccessToken, GuidString } from \"@itwin/core-bentley\";\r\nimport {
|
|
1
|
+
{"version":3,"file":"FrontendHubAccess.js","sourceRoot":"","sources":["../../src/FrontendHubAccess.ts"],"names":[],"mappings":"AAAA;;;+FAG+F;AAC/F;;GAEG","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 HubAccess\r\n */\r\n\r\nimport { AccessToken, GuidString } from \"@itwin/core-bentley\";\r\nimport { ChangesetIndexAndId, IModelVersion } from \"@itwin/core-common\";\r\n\r\n/** @public */\r\nexport interface IModelIdArg {\r\n iModelId: GuidString;\r\n accessToken: AccessToken;\r\n}\r\n\r\n/** @public */\r\nexport interface FrontendHubAccess {\r\n getLatestChangeset(arg: IModelIdArg): Promise<ChangesetIndexAndId>;\r\n getChangesetFromVersion(arg: IModelIdArg & { version: IModelVersion }): Promise<ChangesetIndexAndId>;\r\n /**\r\n * Fetches the changeset with the given named version.\r\n * @param versionName If omitted will default to the latest named version.\r\n */\r\n getChangesetFromNamedVersion(arg: IModelIdArg & { versionName?: string }): Promise<ChangesetIndexAndId>;\r\n}\r\n"]}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@itwin/core-frontend",
|
|
3
|
-
"version": "3.0.0-dev.
|
|
3
|
+
"version": "3.0.0-dev.148",
|
|
4
4
|
"description": "iTwin.js frontend components",
|
|
5
5
|
"main": "lib/cjs/core-frontend.js",
|
|
6
6
|
"module": "lib/esm/core-frontend.js",
|
|
@@ -23,31 +23,31 @@
|
|
|
23
23
|
"url": "http://www.bentley.com"
|
|
24
24
|
},
|
|
25
25
|
"peerDependencies": {
|
|
26
|
-
"@bentley/itwin-client": "^3.0.0-dev.
|
|
27
|
-
"@itwin/appui-abstract": "^3.0.0-dev.
|
|
28
|
-
"@itwin/core-bentley": "^3.0.0-dev.
|
|
29
|
-
"@itwin/core-common": "^3.0.0-dev.
|
|
30
|
-
"@itwin/core-geometry": "^3.0.0-dev.
|
|
31
|
-
"@itwin/core-orbitgt": "^3.0.0-dev.
|
|
32
|
-
"@itwin/core-quantity": "^3.0.0-dev.
|
|
33
|
-
"@itwin/webgl-compatibility": "^3.0.0-dev.
|
|
26
|
+
"@bentley/itwin-client": "^3.0.0-dev.148",
|
|
27
|
+
"@itwin/appui-abstract": "^3.0.0-dev.148",
|
|
28
|
+
"@itwin/core-bentley": "^3.0.0-dev.148",
|
|
29
|
+
"@itwin/core-common": "^3.0.0-dev.148",
|
|
30
|
+
"@itwin/core-geometry": "^3.0.0-dev.148",
|
|
31
|
+
"@itwin/core-orbitgt": "^3.0.0-dev.148",
|
|
32
|
+
"@itwin/core-quantity": "^3.0.0-dev.148",
|
|
33
|
+
"@itwin/webgl-compatibility": "^3.0.0-dev.148"
|
|
34
34
|
},
|
|
35
35
|
"//devDependencies": [
|
|
36
36
|
"NOTE: All peerDependencies should also be listed as devDependencies since peerDependencies are not considered by npm install",
|
|
37
37
|
"NOTE: All tools used by scripts in this package must be listed as devDependencies"
|
|
38
38
|
],
|
|
39
39
|
"devDependencies": {
|
|
40
|
-
"@bentley/itwin-client": "3.0.0-dev.
|
|
41
|
-
"@itwin/appui-abstract": "3.0.0-dev.
|
|
42
|
-
"@itwin/build-tools": "3.0.0-dev.
|
|
43
|
-
"@itwin/core-bentley": "3.0.0-dev.
|
|
44
|
-
"@itwin/core-common": "3.0.0-dev.
|
|
45
|
-
"@itwin/core-geometry": "3.0.0-dev.
|
|
46
|
-
"@itwin/core-orbitgt": "3.0.0-dev.
|
|
47
|
-
"@itwin/core-quantity": "3.0.0-dev.
|
|
48
|
-
"@itwin/certa": "3.0.0-dev.
|
|
49
|
-
"@itwin/eslint-plugin": "3.0.0-dev.
|
|
50
|
-
"@itwin/webgl-compatibility": "3.0.0-dev.
|
|
40
|
+
"@bentley/itwin-client": "3.0.0-dev.148",
|
|
41
|
+
"@itwin/appui-abstract": "3.0.0-dev.148",
|
|
42
|
+
"@itwin/build-tools": "3.0.0-dev.148",
|
|
43
|
+
"@itwin/core-bentley": "3.0.0-dev.148",
|
|
44
|
+
"@itwin/core-common": "3.0.0-dev.148",
|
|
45
|
+
"@itwin/core-geometry": "3.0.0-dev.148",
|
|
46
|
+
"@itwin/core-orbitgt": "3.0.0-dev.148",
|
|
47
|
+
"@itwin/core-quantity": "3.0.0-dev.148",
|
|
48
|
+
"@itwin/certa": "3.0.0-dev.148",
|
|
49
|
+
"@itwin/eslint-plugin": "3.0.0-dev.148",
|
|
50
|
+
"@itwin/webgl-compatibility": "3.0.0-dev.148",
|
|
51
51
|
"@types/chai": "^4.1.4",
|
|
52
52
|
"@types/chai-as-promised": "^7",
|
|
53
53
|
"@types/mocha": "^8.2.2",
|
|
@@ -72,8 +72,8 @@
|
|
|
72
72
|
"NOTE: core-frontend should remain UI technology agnostic, so no react/angular dependencies are allowed"
|
|
73
73
|
],
|
|
74
74
|
"dependencies": {
|
|
75
|
-
"@itwin/core-i18n": "3.0.0-dev.
|
|
76
|
-
"@itwin/core-telemetry": "3.0.0-dev.
|
|
75
|
+
"@itwin/core-i18n": "3.0.0-dev.148",
|
|
76
|
+
"@itwin/core-telemetry": "3.0.0-dev.148",
|
|
77
77
|
"fuse.js": "^3.3.0",
|
|
78
78
|
"semver": "^5.5.0",
|
|
79
79
|
"wms-capabilities": "0.4.0",
|