@itwin/core-backend 4.5.0-dev.3 → 4.5.0-dev.32
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 +51 -1
- package/LICENSE.md +1 -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/Element.d.ts +6 -0
- package/lib/cjs/Element.d.ts.map +1 -1
- package/lib/cjs/Element.js +7 -1
- package/lib/cjs/Element.js.map +1 -1
- package/lib/cjs/IModelDb.d.ts +32 -27
- package/lib/cjs/IModelDb.d.ts.map +1 -1
- package/lib/cjs/IModelDb.js +153 -28
- package/lib/cjs/IModelDb.js.map +1 -1
- package/lib/cjs/IModelHost.d.ts +0 -2
- package/lib/cjs/IModelHost.d.ts.map +1 -1
- package/lib/cjs/IModelHost.js +0 -4
- package/lib/cjs/IModelHost.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/Material.js +1 -1
- package/lib/cjs/Material.js.map +1 -1
- package/lib/cjs/TileStorage.d.ts.map +1 -1
- package/lib/cjs/TileStorage.js +9 -1
- package/lib/cjs/TileStorage.js.map +1 -1
- package/lib/cjs/rpc/web/logging.d.ts.map +1 -1
- package/lib/cjs/rpc/web/logging.js +3 -2
- package/lib/cjs/rpc/web/logging.js.map +1 -1
- package/lib/cjs/rpc/web/response.d.ts.map +1 -1
- package/lib/cjs/rpc/web/response.js +16 -0
- package/lib/cjs/rpc/web/response.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 +13 -13
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"logging.d.ts","sourceRoot":"","sources":["../../../../src/rpc/web/logging.ts"],"names":[],"mappings":"AAIA;;GAEG;AAGH,OAAO,EAAwB,aAAa,EAAE,gBAAgB,EAAE,gBAAgB,EAAE,MAAM,oBAAoB,CAAC;AAK7G,qBAAa,uBAAwB,SAAQ,gBAAgB;cAClC,gBAAgB,CAAC,KAAK,EAAE,gBAAgB,EAAE,MAAM,EAAE,aAAa,GAAG,OAAO,CAAC,IAAI,CAAC;cAQrF,WAAW,IAAI,MAAM;YAI1B,eAAe;
|
|
1
|
+
{"version":3,"file":"logging.d.ts","sourceRoot":"","sources":["../../../../src/rpc/web/logging.ts"],"names":[],"mappings":"AAIA;;GAEG;AAGH,OAAO,EAAwB,aAAa,EAAE,gBAAgB,EAAE,gBAAgB,EAAE,MAAM,oBAAoB,CAAC;AAK7G,qBAAa,uBAAwB,SAAQ,gBAAgB;cAClC,gBAAgB,CAAC,KAAK,EAAE,gBAAgB,EAAE,MAAM,EAAE,aAAa,GAAG,OAAO,CAAC,IAAI,CAAC;cAQrF,WAAW,IAAI,MAAM;YAI1B,eAAe;CAmB9B"}
|
|
@@ -28,7 +28,7 @@ class WebAppRpcLoggingBackend extends core_common_1.WebAppRpcLogging {
|
|
|
28
28
|
const pathIds = this.findPathIds(invocation.request.path);
|
|
29
29
|
const result = await invocation.result;
|
|
30
30
|
const errorMessage = result.message ? result.message : result.objects; // Can be an error or an RpcSerializedValue
|
|
31
|
-
|
|
31
|
+
const metadata = {
|
|
32
32
|
method: invocation.request.method,
|
|
33
33
|
path: invocation.request.path,
|
|
34
34
|
status: invocation.status,
|
|
@@ -37,7 +37,8 @@ class WebAppRpcLoggingBackend extends core_common_1.WebAppRpcLogging {
|
|
|
37
37
|
ActivityId: invocation.request.id,
|
|
38
38
|
MachineName: this.getHostname(),
|
|
39
39
|
...pathIds,
|
|
40
|
-
}
|
|
40
|
+
};
|
|
41
|
+
core_bentley_1.Logger.logError(core_common_1.CommonLoggerCategory.RpcInterfaceBackend, `${message}.${operationDescriptor}`, metadata);
|
|
41
42
|
}
|
|
42
43
|
}
|
|
43
44
|
exports.WebAppRpcLoggingBackend = WebAppRpcLoggingBackend;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"logging.js","sourceRoot":"","sources":["../../../../src/rpc/web/logging.ts"],"names":[],"mappings":";AAAA;;;+FAG+F;AAC/F;;GAEG;;;AAEH,sDAA6C;AAC7C,oDAA6G;AAC7G,yBAAyB;AAEzB,4CAA4C;AAE5C,MAAa,uBAAwB,SAAQ,8BAAgB;IACxC,KAAK,CAAC,gBAAgB,CAAC,KAAuB,EAAE,MAAqB;QACtF,QAAQ,KAAK,EAAE;YACb,KAAK,8BAAgB,CAAC,eAAe,CAAC,CAAC,OAAO,IAAI,CAAC,UAAU,CAAC,kCAAoB,CAAC,mBAAmB,EAAE,8BAA8B,EAAE,MAAM,CAAC,OAAO,CAAC,CAAC;YACxJ,KAAK,8BAAgB,CAAC,oBAAoB,CAAC,CAAC,OAAO,IAAI,CAAC,eAAe,CAAC,4BAA4B,EAAE,MAAM,CAAC,CAAC;YAC9G,KAAK,8BAAgB,CAAC,sBAAsB,CAAC,CAAC,OAAO,IAAI,CAAC,WAAW,CAAC,kCAAoB,CAAC,mBAAmB,EAAE,+BAA+B,EAAE,MAAM,CAAC,OAAO,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,OAAO,CAAC,CAAC;SACjM;IACH,CAAC;IAEkB,WAAW;QAC5B,OAAO,EAAE,CAAC,QAAQ,E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AO,EAAE,CAAC,QAAQ,EAAE,CAAC;IACvB,CAAC;IAEO,KAAK,CAAC,eAAe,CAAC,OAAe,EAAE,UAAyB;QACtE,MAAM,mBAAmB,GAAG,IAAI,CAAC,wBAAwB,CAAC,UAAU,CAAC,SAAS,CAAC,CAAC;QAChF,MAAM,OAAO,GAAG,IAAI,CAAC,WAAW,CAAC,UAAU,CAAC,OAAO,CAAC,IAAI,CAAC,CAAC;QAC1D,MAAM,MAAM,GAAG,MAAM,UAAU,CAAC,MAAM,CAAC;QACvC,MAAM,YAAY,GAAG,MAAM,CAAC,OAAO,CAAC,CAAC,CAAC,MAAM,CAAC,OAAO,CAAC,CAAC,CAAC,MAAM,CAAC,OAAO,CAAC,CAAC,2CAA2C;QAElH,MAAM,QAAQ,GAAG;YACf,MAAM,EAAE,UAAU,CAAC,OAAO,CAAC,MAAM;YACjC,IAAI,EAAE,UAAU,CAAC,OAAO,CAAC,IAAI;YAC7B,MAAM,EAAE,UAAU,CAAC,MAAM;YACzB,YAAY;YACZ,uGAAuG;YACvG,UAAU,EAAE,UAAU,CAAC,OAAO,CAAC,EAAE;YACjC,WAAW,EAAE,IAAI,CAAC,WAAW,EAAE;YAC/B,GAAG,OAAO;SACX,CAAC;QAEF,qBAAM,CAAC,QAAQ,CAAC,kCAAoB,CAAC,mBAAmB,EAAE,GAAG,OAAO,IAAI,mBAAmB,EAAE,EAAE,QAAQ,CAAC,CAAC;IAC3G,CAAC;CACF;AAhCD,0DAgCC","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 { Logger } from \"@itwin/core-bentley\";\r\nimport { CommonLoggerCategory, RpcInvocation, RpcProtocolEvent, WebAppRpcLogging } from \"@itwin/core-common\";\r\nimport * as os from \"os\";\r\n\r\n/* eslint-disable deprecation/deprecation */\r\n\r\nexport class WebAppRpcLoggingBackend extends WebAppRpcLogging {\r\n protected override async logProtocolEvent(event: RpcProtocolEvent, object: RpcInvocation): Promise<void> {\r\n switch (event) {\r\n case RpcProtocolEvent.RequestReceived: return this.logRequest(CommonLoggerCategory.RpcInterfaceBackend, \"RpcInterface.backend.request\", object.request);\r\n case RpcProtocolEvent.BackendErrorOccurred: return this.logErrorBackend(\"RpcInterface.backend.error\", object);\r\n case RpcProtocolEvent.BackendResponseCreated: return this.logResponse(CommonLoggerCategory.RpcInterfaceBackend, \"RpcInterface.backend.response\", object.request, object.status, object.elapsed);\r\n }\r\n }\r\n\r\n protected override getHostname(): string {\r\n return os.hostname();\r\n }\r\n\r\n private async logErrorBackend(message: string, invocation: RpcInvocation): Promise<void> {\r\n const operationDescriptor = this.buildOperationDescriptor(invocation.operation);\r\n const pathIds = this.findPathIds(invocation.request.path);\r\n const result = await invocation.result;\r\n const errorMessage = result.message ? result.message : result.objects; // Can be an error or an RpcSerializedValue\r\n\r\n const metadata = {\r\n method: invocation.request.method,\r\n path: invocation.request.path,\r\n status: invocation.status,\r\n errorMessage,\r\n // Alert! The following properties are required by Bentley DevOps standards. Do not change their names!\r\n ActivityId: invocation.request.id, // eslint-disable-line @typescript-eslint/naming-convention\r\n MachineName: this.getHostname(), // eslint-disable-line @typescript-eslint/naming-convention\r\n ...pathIds,\r\n };\r\n\r\n Logger.logError(CommonLoggerCategory.RpcInterfaceBackend, `${message}.${operationDescriptor}`, metadata);\r\n }\r\n}\r\n"]}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"response.d.ts","sourceRoot":"","sources":["../../../../src/rpc/web/response.ts"],"names":[],"mappings":"AAIA;;GAEG;
|
|
1
|
+
{"version":3,"file":"response.d.ts","sourceRoot":"","sources":["../../../../src/rpc/web/response.ts"],"names":[],"mappings":"AAIA;;GAEG;AAGH,OAAO,EAEL,iBAAiB,EACjB,kBAAkB,EAKlB,qBAAqB,EAGrB,oBAAoB,EAEpB,iBAAiB,EAElB,MAAM,oBAAoB,CAAC;AA6D5B,gBAAgB;AAChB,wBAAsB,YAAY,CAAC,QAAQ,EAAE,iBAAiB,EAAE,OAAO,EAAE,oBAAoB,EAAE,WAAW,EAAE,qBAAqB,EAAE,GAAG,EAAE,iBAAiB,EAAE,GAAG,EAAE,kBAAkB,iBAuCjL"}
|
|
@@ -8,6 +8,7 @@
|
|
|
8
8
|
*/
|
|
9
9
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
10
10
|
exports.sendResponse = void 0;
|
|
11
|
+
const core_bentley_1 = require("@itwin/core-bentley");
|
|
11
12
|
const core_common_1 = require("@itwin/core-common");
|
|
12
13
|
/* eslint-disable deprecation/deprecation */
|
|
13
14
|
function configureResponse(protocol, request, fulfillment, res) {
|
|
@@ -65,6 +66,7 @@ function configureStream(fulfillment) {
|
|
|
65
66
|
}
|
|
66
67
|
/** @internal */
|
|
67
68
|
async function sendResponse(protocol, request, fulfillment, req, res) {
|
|
69
|
+
logResponse(request, fulfillment.status, fulfillment.rawResult);
|
|
68
70
|
const versionHeader = protocol.protocolVersionHeaderName;
|
|
69
71
|
if (versionHeader && core_common_1.RpcProtocol.protocolVersion) {
|
|
70
72
|
res.set(versionHeader, core_common_1.RpcProtocol.protocolVersion.toString());
|
|
@@ -103,4 +105,18 @@ async function sendResponse(protocol, request, fulfillment, req, res) {
|
|
|
103
105
|
}
|
|
104
106
|
}
|
|
105
107
|
exports.sendResponse = sendResponse;
|
|
108
|
+
function logResponse(request, statusCode, resultObj) {
|
|
109
|
+
const metadata = {
|
|
110
|
+
ActivityId: request.id,
|
|
111
|
+
method: request.method,
|
|
112
|
+
path: request.path,
|
|
113
|
+
operation: request.operation,
|
|
114
|
+
statusCode,
|
|
115
|
+
error: resultObj instanceof Error ? resultObj : undefined,
|
|
116
|
+
};
|
|
117
|
+
if (statusCode < 400)
|
|
118
|
+
core_bentley_1.Logger.logInfo(core_common_1.CommonLoggerCategory.RpcInterfaceBackend, "RPC over HTTP success response", metadata);
|
|
119
|
+
else
|
|
120
|
+
core_bentley_1.Logger.logError(core_common_1.CommonLoggerCategory.RpcInterfaceBackend, "RPC over HTTP failure response", metadata);
|
|
121
|
+
}
|
|
106
122
|
//# sourceMappingURL=response.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"response.js","sourceRoot":"","sources":["../../../../src/rpc/web/response.ts"],"names":[],"mappings":";AAAA;;;+FAG+F;AAC/F;;GAEG;;;AAEH,oDAc4B;AAE5B,4CAA4C;AAE5C,SAAS,iBAAiB,CAAC,QAA2B,EAAE,OAA6B,EAAE,WAAkC,EAAE,GAAuB;IAChJ,MAAM,OAAO,GAAG,QAAQ,CAAC,SAAS,CAAC,WAAW,CAAC,MAAM,CAAC,KAAK,8BAAgB,CAAC,QAAQ,CAAC;IACrF,iJAAiJ;IACjJ,kJAAkJ;IAElJ,yFAAyF;IACzF,MAAM,gBAAgB,GAAG,IAAI,CAAC;IAC9B,IAAI,OAAO,IAAI,OAAO,CAAC,OAAO,KAAK,qCAAuB,CAAC,SAAS,EAAE;QACpE,gDAAgD;QAChD,IAAI,WAAW,CAAC,MAAM,CAAC,OAAO,CAAC,MAAM,GAAG,CAAC,EAAE,GAAG,EAAE,IAAI,CAAC,CAAC,EAAE;YACtD,GAAG,CAAC,GAAG,CAAC,eAAe,EAAE,UAAU,CAAC,CAAC;SACtC;aAAM,IAAI,OAAO,CAAC,SAAS,CAAC,aAAa,KAAK,qBAAqB,EAAE;YACpE,GAAG,CAAC,GAAG,CAAC,eAAe,EAAE,UAAU,CAAC,CAAC;SACtC;aAAM,IAAI,OAAO,CAAC,SAAS,CAAC,aAAa,KAAK,oBAAoB,EAAE;YACnE,qKAAqK;YACrK,GAAG,CAAC,GAAG,CAAC,eAAe,EAAE,YAAY,gBAAgB,GAAG,EAAE,wBAAwB,CAAC,CAAC;SACrF;aAAM,IAAI,OAAO,CAAC,SAAS,CAAC,aAAa,KAAK,0BAA0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Ae,CAAC,WAAW,CAAC,CAAC;KAC7C;SAAM;QACL,YAAY,GAAG,aAAa,CAAC,WAAW,EAAE,GAAG,CAAC,CAAC;KAChD;IAED,iBAAiB,CAAC,QAAQ,EAAE,OAAO,EAAE,WAAW,EAAE,GAAG,CAAC,CAAC;IACvD,GAAG,CAAC,MAAM,CAAC,WAAW,CAAC,MAAM,CAAC,CAAC;IAE/B,IAAI,WAAW,CAAC,gBAAgB,IAAI,GAAG,CAAC,MAAM,CAAC,iBAAiB,CAAC,EAAE,QAAQ,CAAC,MAAM,CAAC,EAAE;QACnF,GAAG,CAAC,GAAG,CAAC,kBAAkB,EAAE,MAAM,CAAC,CAAC;QACpC,MAAM,oBAAoB,GAAG,CAAC,YAAY,YAAY,MAAM,CAAC,CAAC,CAAC,CAAC,YAAY,CAAC,CAAC,CAAC,QAAQ,CAAC,IAAI,CAAC,YAAY,CAAC,CAAC;QAC3G,YAAY,GAAG,oBAAoB,CAAC,IAAI,CAAC,UAAU,EAAE,CAAC,CAAC;KACxD;IAED,6GAA6G;IAC7G,iCAAiC;IACjC,IAAI,YAAY,YAAY,MAAM,EAAE;QAClC,YAAY,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC;KACxB;SAAM;QACL,GAAG,CAAC,IAAI,CAAC,YAAY,CAAC,CAAC;KACxB;AACH,CAAC;AArCD,oCAqCC","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 {\r\n HttpServerRequest,\r\n HttpServerResponse,\r\n ReadableFormData,\r\n RpcContentType,\r\n RpcMultipart,\r\n RpcProtocol,\r\n RpcRequestFulfillment,\r\n RpcRequestStatus,\r\n RpcResponseCacheControl,\r\n SerializedRpcRequest,\r\n WEB_RPC_CONSTANTS,\r\n WebAppRpcProtocol,\r\n WebAppRpcRequest,\r\n} from \"@itwin/core-common\";\r\n\r\n/* eslint-disable deprecation/deprecation */\r\n\r\nfunction configureResponse(protocol: WebAppRpcProtocol, request: SerializedRpcRequest, fulfillment: RpcRequestFulfillment, res: HttpServerResponse) {\r\n const success = protocol.getStatus(fulfillment.status) === RpcRequestStatus.Resolved;\r\n // TODO: Use stale-while-revalidate in cache headers. This needs to be tested, and does not currently have support in the router/caching-service.\r\n // This will allow browsers to use stale cached responses while also revalidating with the router, allowing us to start up a backend if necessary.\r\n\r\n // RPC Caching Service uses the s-maxage header to determine the TTL for the redis cache.\r\n const oneHourInSeconds = 3600;\r\n if (success && request.caching === RpcResponseCacheControl.Immutable) {\r\n // If response size is > 50 MB, do not cache it.\r\n if (fulfillment.result.objects.length > (50 * 10 ** 7)) {\r\n res.set(\"Cache-Control\", \"no-store\");\r\n } else if (request.operation.operationName === \"generateTileContent\") {\r\n res.set(\"Cache-Control\", \"no-store\");\r\n } else if (request.operation.operationName === \"getConnectionProps\") {\r\n // GetConnectionprops can't be cached on the browser longer than the lifespan of the backend. The lifespan of backend may shrink too. Keep it at 1 second to be safe.\r\n res.set(\"Cache-Control\", `s-maxage=${oneHourInSeconds * 24}, max-age=1, immutable`);\r\n } else if (request.operation.operationName === \"getTileCacheContainerUrl\") {\r\n // getTileCacheContainerUrl returns a SAS with an expiry of 23:59:59. We can't exceed that time when setting the max-age.\r\n res.set(\"Cache-Control\", `s-maxage=${oneHourInSeconds * 23}, max-age=${oneHourInSeconds * 23}, immutable`);\r\n } else {\r\n res.set(\"Cache-Control\", `s-maxage=${oneHourInSeconds * 24}, max-age=${oneHourInSeconds * 48}, immutable`);\r\n }\r\n }\r\n\r\n if (fulfillment.retry) {\r\n res.set(\"Retry-After\", fulfillment.retry);\r\n }\r\n}\r\n\r\nfunction configureText(fulfillment: RpcRequestFulfillment, res: HttpServerResponse): string {\r\n res.set(WEB_RPC_CONSTANTS.CONTENT, WEB_RPC_CONSTANTS.TEXT);\r\n return (fulfillment.status === 204) ? \"\" : fulfillment.result.objects;\r\n}\r\n\r\nfunction configureBinary(fulfillment: RpcRequestFulfillment, res: HttpServerResponse): Buffer {\r\n res.set(WEB_RPC_CONSTANTS.CONTENT, WEB_RPC_CONSTANTS.BINARY);\r\n const data = fulfillment.result.data[0];\r\n return Buffer.isBuffer(data) ? data : Buffer.from(data);\r\n}\r\n\r\nfunction configureMultipart(fulfillment: RpcRequestFulfillment, res: HttpServerResponse): ReadableFormData {\r\n const response = RpcMultipart.createStream(fulfillment.result);\r\n const headers = response.getHeaders();\r\n for (const header in headers) {\r\n if (headers.hasOwnProperty(header)) {\r\n res.set(header, headers[header]);\r\n }\r\n }\r\n\r\n return response;\r\n}\r\n\r\nfunction configureStream(fulfillment: RpcRequestFulfillment) {\r\n // eslint-disable-next-line @typescript-eslint/no-non-null-assertion\r\n return fulfillment.result.stream!;\r\n}\r\n\r\n/** @internal */\r\nexport async function sendResponse(protocol: WebAppRpcProtocol, request: SerializedRpcRequest, fulfillment: RpcRequestFulfillment, req: HttpServerRequest, res: HttpServerResponse) {\r\n const versionHeader = protocol.protocolVersionHeaderName;\r\n if (versionHeader && RpcProtocol.protocolVersion) {\r\n res.set(versionHeader, RpcProtocol.protocolVersion.toString());\r\n }\r\n // eslint-disable-next-line @typescript-eslint/naming-convention\r\n const { Readable, Stream } = await import(/* webpackIgnore: true */ \"stream\");\r\n const { createGzip } = await import(/* webpackIgnore: true */ \"zlib\");\r\n\r\n const transportType = WebAppRpcRequest.computeTransportType(fulfillment.result, fulfillment.rawResult);\r\n let responseBody;\r\n if (transportType === RpcContentType.Binary) {\r\n responseBody = configureBinary(fulfillment, res);\r\n } else if (transportType === RpcContentType.Multipart) {\r\n responseBody = configureMultipart(fulfillment, res);\r\n } else if (transportType === RpcContentType.Stream) {\r\n responseBody = configureStream(fulfillment);\r\n } else {\r\n responseBody = configureText(fulfillment, res);\r\n }\r\n\r\n configureResponse(protocol, request, fulfillment, res);\r\n res.status(fulfillment.status);\r\n\r\n if (fulfillment.allowCompression && req.header(\"Accept-Encoding\")?.includes(\"gzip\")) {\r\n res.set(\"Content-Encoding\", \"gzip\");\r\n const readableResponseBody = (responseBody instanceof Stream) ? responseBody : Readable.from(responseBody);\r\n responseBody = readableResponseBody.pipe(createGzip());\r\n }\r\n\r\n // This check should in theory look for instances of Readable, but that would break backend implementation at\r\n // core/backend/src/RpcBackend.ts\r\n if (responseBody instanceof Stream) {\r\n responseBody.pipe(res);\r\n } else {\r\n res.send(responseBody);\r\n }\r\n}\r\n"]}
|
|
1
|
+
{"version":3,"file":"response.js","sourceRoot":"","sources":["../../../../src/rpc/web/response.ts"],"names":[],"mappings":";AAAA;;;+FAG+F;AAC/F;;GAEG;;;AAEH,sDAA6C;AAC7C,oDAe4B;AAE5B,4CAA4C;AAE5C,SAAS,iBAAiB,CAAC,QAA2B,EAAE,OAA6B,EAAE,WAAkC,EAAE,GAAuB;IAChJ,MAAM,OAAO,GAAG,QAAQ,CAAC,SAAS,CAAC,WAAW,CAAC,MAAM,CAAC,KAAK,8BAAgB,CAAC,QAAQ,CAAC;IACrF,iJAAiJ;IACjJ,kJAAkJ;IAElJ,yFAAyF;IACzF,MAAM,gBAAgB,GAAG,IAAI,CAAC;IAC9B,IAAI,OAAO,IAAI,OAAO,CAAC,OAAO,KAAK,qCAAuB,CAAC,SAAS,EAAE;QACpE,gDAAgD;QAChD,IAAI,WAAW,CAAC,MAAM,CAAC,OAAO,CAAC,MAAM,GAAG,CAAC,EAAE,GAAG,EAAE,IAAI,CAAC,CAAC,EAAE;YACtD,GAAG,CAAC,GAAG,CAAC,eAAe,EAAE,UAAU,CAAC,CAAC;SACtC;aAAM,IAAI,OAAO,CAAC,SAAS,CAAC,aAAa,KAAK,qBAAqB,EAAE;YACpE,GAAG,CAAC,GAAG,CAAC,eAAe,EAAE,UAAU,CAAC,CAAC;SACtC;aAAM,IAAI,OAAO,CAAC,SAAS,CAAC,aAAa,KAAK,oBAAoB,EAAE;YACnE,qKAAqK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tB,IAAI,EAAE,OAAO,CAAC,IAAI;QAClB,SAAS,EAAE,OAAO,CAAC,SAAS;QAC5B,UAAU;QACV,KAAK,EAAE,SAAS,YAAY,KAAK,CAAC,CAAC,CAAC,SAAS,CAAC,CAAC,CAAC,SAAS;KAC1D,CAAC;IAEF,IAAI,UAAU,GAAG,GAAG;QAClB,qBAAM,CAAC,OAAO,CAAC,kCAAoB,CAAC,mBAAmB,EAAE,gCAAgC,EAAE,QAAQ,CAAC,CAAC;;QAErG,qBAAM,CAAC,QAAQ,CAAC,kCAAoB,CAAC,mBAAmB,EAAE,gCAAgC,EAAE,QAAQ,CAAC,CAAC;AAC1G,CAAC","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 { Logger } from \"@itwin/core-bentley\";\r\nimport {\r\n CommonLoggerCategory,\r\n HttpServerRequest,\r\n HttpServerResponse,\r\n ReadableFormData,\r\n RpcContentType,\r\n RpcMultipart,\r\n RpcProtocol,\r\n RpcRequestFulfillment,\r\n RpcRequestStatus,\r\n RpcResponseCacheControl,\r\n SerializedRpcRequest,\r\n WEB_RPC_CONSTANTS,\r\n WebAppRpcProtocol,\r\n WebAppRpcRequest,\r\n} from \"@itwin/core-common\";\r\n\r\n/* eslint-disable deprecation/deprecation */\r\n\r\nfunction configureResponse(protocol: WebAppRpcProtocol, request: SerializedRpcRequest, fulfillment: RpcRequestFulfillment, res: HttpServerResponse) {\r\n const success = protocol.getStatus(fulfillment.status) === RpcRequestStatus.Resolved;\r\n // TODO: Use stale-while-revalidate in cache headers. This needs to be tested, and does not currently have support in the router/caching-service.\r\n // This will allow browsers to use stale cached responses while also revalidating with the router, allowing us to start up a backend if necessary.\r\n\r\n // RPC Caching Service uses the s-maxage header to determine the TTL for the redis cache.\r\n const oneHourInSeconds = 3600;\r\n if (success && request.caching === RpcResponseCacheControl.Immutable) {\r\n // If response size is > 50 MB, do not cache it.\r\n if (fulfillment.result.objects.length > (50 * 10 ** 7)) {\r\n res.set(\"Cache-Control\", \"no-store\");\r\n } else if (request.operation.operationName === \"generateTileContent\") {\r\n res.set(\"Cache-Control\", \"no-store\");\r\n } else if (request.operation.operationName === \"getConnectionProps\") {\r\n // GetConnectionprops can't be cached on the browser longer than the lifespan of the backend. The lifespan of backend may shrink too. Keep it at 1 second to be safe.\r\n res.set(\"Cache-Control\", `s-maxage=${oneHourInSeconds * 24}, max-age=1, immutable`);\r\n } else if (request.operation.operationName === \"getTileCacheContainerUrl\") {\r\n // getTileCacheContainerUrl returns a SAS with an expiry of 23:59:59. We can't exceed that time when setting the max-age.\r\n res.set(\"Cache-Control\", `s-maxage=${oneHourInSeconds * 23}, max-age=${oneHourInSeconds * 23}, immutable`);\r\n } else {\r\n res.set(\"Cache-Control\", `s-maxage=${oneHourInSeconds * 24}, max-age=${oneHourInSeconds * 48}, immutable`);\r\n }\r\n }\r\n\r\n if (fulfillment.retry) {\r\n res.set(\"Retry-After\", fulfillment.retry);\r\n }\r\n}\r\n\r\nfunction configureText(fulfillment: RpcRequestFulfillment, res: HttpServerResponse): string {\r\n res.set(WEB_RPC_CONSTANTS.CONTENT, WEB_RPC_CONSTANTS.TEXT);\r\n return (fulfillment.status === 204) ? \"\" : fulfillment.result.objects;\r\n}\r\n\r\nfunction configureBinary(fulfillment: RpcRequestFulfillment, res: HttpServerResponse): Buffer {\r\n res.set(WEB_RPC_CONSTANTS.CONTENT, WEB_RPC_CONSTANTS.BINARY);\r\n const data = fulfillment.result.data[0];\r\n return Buffer.isBuffer(data) ? data : Buffer.from(data);\r\n}\r\n\r\nfunction configureMultipart(fulfillment: RpcRequestFulfillment, res: HttpServerResponse): ReadableFormData {\r\n const response = RpcMultipart.createStream(fulfillment.result);\r\n const headers = response.getHeaders();\r\n for (const header in headers) {\r\n if (headers.hasOwnProperty(header)) {\r\n res.set(header, headers[header]);\r\n }\r\n }\r\n\r\n return response;\r\n}\r\n\r\nfunction configureStream(fulfillment: RpcRequestFulfillment) {\r\n // eslint-disable-next-line @typescript-eslint/no-non-null-assertion\r\n return fulfillment.result.stream!;\r\n}\r\n\r\n/** @internal */\r\nexport async function sendResponse(protocol: WebAppRpcProtocol, request: SerializedRpcRequest, fulfillment: RpcRequestFulfillment, req: HttpServerRequest, res: HttpServerResponse) {\r\n logResponse(request, fulfillment.status, fulfillment.rawResult);\r\n\r\n const versionHeader = protocol.protocolVersionHeaderName;\r\n if (versionHeader && RpcProtocol.protocolVersion) {\r\n res.set(versionHeader, RpcProtocol.protocolVersion.toString());\r\n }\r\n // eslint-disable-next-line @typescript-eslint/naming-convention\r\n const { Readable, Stream } = await import(/* webpackIgnore: true */ \"stream\");\r\n const { createGzip } = await import(/* webpackIgnore: true */ \"zlib\");\r\n\r\n const transportType = WebAppRpcRequest.computeTransportType(fulfillment.result, fulfillment.rawResult);\r\n let responseBody;\r\n if (transportType === RpcContentType.Binary) {\r\n responseBody = configureBinary(fulfillment, res);\r\n } else if (transportType === RpcContentType.Multipart) {\r\n responseBody = configureMultipart(fulfillment, res);\r\n } else if (transportType === RpcContentType.Stream) {\r\n responseBody = configureStream(fulfillment);\r\n } else {\r\n responseBody = configureText(fulfillment, res);\r\n }\r\n\r\n configureResponse(protocol, request, fulfillment, res);\r\n res.status(fulfillment.status);\r\n\r\n if (fulfillment.allowCompression && req.header(\"Accept-Encoding\")?.includes(\"gzip\")) {\r\n res.set(\"Content-Encoding\", \"gzip\");\r\n const readableResponseBody = (responseBody instanceof Stream) ? responseBody : Readable.from(responseBody);\r\n responseBody = readableResponseBody.pipe(createGzip());\r\n }\r\n\r\n // This check should in theory look for instances of Readable, but that would break backend implementation at\r\n // core/backend/src/RpcBackend.ts\r\n if (responseBody instanceof Stream) {\r\n responseBody.pipe(res);\r\n } else {\r\n res.send(responseBody);\r\n }\r\n}\r\n\r\nfunction logResponse(request: SerializedRpcRequest, statusCode: number, resultObj: unknown) {\r\n const metadata = {\r\n ActivityId: request.id, // eslint-disable-line @typescript-eslint/naming-convention\r\n method: request.method,\r\n path: request.path,\r\n operation: request.operation,\r\n statusCode,\r\n error: resultObj instanceof Error ? resultObj : undefined,\r\n };\r\n\r\n if (statusCode < 400)\r\n Logger.logInfo(CommonLoggerCategory.RpcInterfaceBackend, \"RPC over HTTP success response\", metadata);\r\n else\r\n Logger.logError(CommonLoggerCategory.RpcInterfaceBackend, \"RPC over HTTP failure response\", metadata);\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);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,8BAA8B,EAAE,GAAG,EAAE,CAAC,CAAC,EAAE,GAAG,UAAU,EAAE,CAAC,CAAC,CAAC;gBAC3F,MAAM,IAAI,gCAAkB,EAAE,CAAC,CAAC,8CAA8C;aAC/E;YACD,qBAAM,CAAC,QAAQ,CAAC,cAAc,EAAE,sBAAsB,EAAE,GAAG,EAAE,CAAC,CAAC,EAAE,GAAG,UAAU,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, syncMode, timeout })).toJSON();\r\n }\r\n\r\n}\r\n"]}
|
|
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;AAC5B,oEAAiE;AACjE,0DAA+E;AAC/E,4DAA8E;AAC9E,0CAAgE;AAChE,8CAA2C;AAC3C,8CAA2C;AAE3C,MAAM,cAAc,GAAW,6CAAqB,CAAC,QAAQ,CAAC;AAW9D;;;GAGG;AACH,MAAa,mBAAmB;IAEtB,MAAM,CAAC,KAAK,CAAC,eAAe,CAAC,IAAyB;QAC5D,MAAM,EAAE,QAAQ,EAAE,UAAU,EAAE,GAAG,IAAI,CAAC;QACtC,MAAM,WAAW,GAAG,QAAQ,CAAC,WAAW,CAAC;QACzC,IAAA,qBAAM,EAAC,SAAS,KAAK,UAAU,CAAC,QAAQ,CAAC,CAAC;QAE1C,MAAM,QAAQ,GAAG,UAAU,CAAC,QAAQ,CAAC;QACrC,IAAI,cAAwB,CAAC;QAC7B,IAAI,IAAI,CAAC,QAAQ,KAAK,sBAAQ,CAAC,QAAQ,EAAE;YACvC,cAAc,GAAG,CAAC,CAAC,CAAC,CAAC,CAAC,+BAA+B;SACtD;aAAM;YACL,4EAA4E;YAC5E,cAAc,GAAG,MAAM,uBAAU,CAAC,SAAS,CAAC,iBAAiB,CAAC,EAAE,WAAW,EAAE,QAAQ,EAAE,CAAC,CAAC;SAC1F;QAED,MAAM,SAAS,GAAG,IAAI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MAAM,IAAI,gCAAkB,EAAE,CAAC,CAAC,8CAA8C;aAC/E;YACD,qBAAM,CAAC,QAAQ,CAAC,cAAc,EAAE,sBAAsB,EAAE,UAAU,CAAC,CAAC;SACrE;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;;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.32",
|
|
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.32",
|
|
29
|
+
"@itwin/core-common": "^4.5.0-dev.32",
|
|
30
|
+
"@itwin/core-geometry": "^4.5.0-dev.32",
|
|
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/
|
|
73
|
-
"@itwin/
|
|
74
|
-
"@itwin/core-
|
|
75
|
-
"@itwin/core-geometry": "4.5.0-dev.
|
|
76
|
-
"@itwin/core-webpack-tools": "4.5.0-dev.
|
|
77
|
-
"
|
|
78
|
-
"
|
|
72
|
+
"@itwin/core-bentley": "4.5.0-dev.32",
|
|
73
|
+
"@itwin/build-tools": "4.5.0-dev.32",
|
|
74
|
+
"@itwin/core-common": "4.5.0-dev.32",
|
|
75
|
+
"@itwin/core-geometry": "4.5.0-dev.32",
|
|
76
|
+
"@itwin/core-webpack-tools": "4.5.0-dev.32",
|
|
77
|
+
"@itwin/ecsql-common": "4.5.0-dev.32",
|
|
78
|
+
"internal-tools": "3.0.0-dev.69"
|
|
79
79
|
},
|
|
80
80
|
"dependencies": {
|
|
81
|
-
"@bentley/imodeljs-native": "4.
|
|
81
|
+
"@bentley/imodeljs-native": "4.5.14",
|
|
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.32"
|
|
95
95
|
},
|
|
96
96
|
"nyc": {
|
|
97
97
|
"extends": "./node_modules/@itwin/build-tools/.nycrc"
|