@itwin/core-common 4.4.0-dev.5 → 4.4.0-dev.7
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 +11 -1
- package/lib/cjs/rpc/core/RpcInvocation.js +2 -2
- package/lib/cjs/rpc/core/RpcInvocation.js.map +1 -1
- package/lib/cjs/rpc/core/RpcMarshaling.d.ts +1 -1
- package/lib/cjs/rpc/core/RpcMarshaling.d.ts.map +1 -1
- package/lib/cjs/rpc/core/RpcMarshaling.js +1 -1
- package/lib/cjs/rpc/core/RpcMarshaling.js.map +1 -1
- package/lib/cjs/rpc/core/RpcProtocol.js +2 -2
- package/lib/cjs/rpc/core/RpcProtocol.js.map +1 -1
- package/lib/esm/rpc/core/RpcInvocation.js +2 -2
- package/lib/esm/rpc/core/RpcInvocation.js.map +1 -1
- package/lib/esm/rpc/core/RpcMarshaling.d.ts +1 -1
- package/lib/esm/rpc/core/RpcMarshaling.d.ts.map +1 -1
- package/lib/esm/rpc/core/RpcMarshaling.js +1 -1
- package/lib/esm/rpc/core/RpcMarshaling.js.map +1 -1
- package/lib/esm/rpc/core/RpcProtocol.js +2 -2
- package/lib/esm/rpc/core/RpcProtocol.js.map +1 -1
- package/package.json +6 -6
package/CHANGELOG.md
CHANGED
|
@@ -1,6 +1,16 @@
|
|
|
1
1
|
# Change Log - @itwin/core-common
|
|
2
2
|
|
|
3
|
-
This log was last generated on
|
|
3
|
+
This log was last generated on Thu, 14 Dec 2023 20:24:02 GMT and should not be manually modified.
|
|
4
|
+
|
|
5
|
+
## 4.3.2
|
|
6
|
+
Thu, 14 Dec 2023 20:23:02 GMT
|
|
7
|
+
|
|
8
|
+
_Version update only_
|
|
9
|
+
|
|
10
|
+
## 4.3.1
|
|
11
|
+
Wed, 13 Dec 2023 17:25:55 GMT
|
|
12
|
+
|
|
13
|
+
_Version update only_
|
|
4
14
|
|
|
5
15
|
## 4.3.0
|
|
6
16
|
Thu, 07 Dec 2023 17:43:09 GMT
|
|
@@ -156,14 +156,14 @@ class RpcInvocation {
|
|
|
156
156
|
async fulfillResolved(value) {
|
|
157
157
|
this._timeOut = new Date().getTime();
|
|
158
158
|
this.protocol.events.raiseEvent(RpcConstants_1.RpcProtocolEvent.BackendResponseCreated, this);
|
|
159
|
-
const result =
|
|
159
|
+
const result = RpcMarshaling_1.RpcMarshaling.serialize(this.protocol, value);
|
|
160
160
|
return this.fulfill(result, value);
|
|
161
161
|
}
|
|
162
162
|
async fulfillRejected(reason) {
|
|
163
163
|
this._timeOut = new Date().getTime();
|
|
164
164
|
if (!RpcConfiguration_1.RpcConfiguration.developmentMode)
|
|
165
165
|
reason.stack = undefined;
|
|
166
|
-
const result =
|
|
166
|
+
const result = RpcMarshaling_1.RpcMarshaling.serialize(this.protocol, reason);
|
|
167
167
|
if (reason instanceof RpcControl_1.RpcPendingResponse) {
|
|
168
168
|
this._pending = true;
|
|
169
169
|
this._threw = false;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"RpcInvocation.js","sourceRoot":"","sources":["../../../../src/rpc/core/RpcInvocation.ts"],"names":[],"mappings":";AAAA;;;+FAG+F;AAC/F;;GAEG;;;;AAEH,sDAA8J;AAC9J,qEAAkE;AAElE,mDAAgD;AAChD,qDAAkD;AAElD,yDAAsD;AACtD,iDAAoE;AACpE,6CAA0F;AAC1F,mDAAoE;AACpE,iDAA8C;AAC9C,+CAA+H;AAC/H,+CAAgE;AAqChE;;GAEG;AACH,MAAa,aAAa;IAwBxB,mCAAmC;IACnC,IAAW,MAAM;QACf,OAAO,IAAI,CAAC,MAAM,CAAC,CAAC,CAAC,+BAAgB,CAAC,QAAQ,CAAC,CAAC;YAC9C,IAAI,CAAC,QAAQ,CAAC,CAAC,CAAC,+BAAgB,CAAC,OAAO,CAAC,CAAC;gBACxC,IAAI,CAAC,SAAS,CAAC,CAAC,CAAC,+BAAgB,CAAC,QAAQ,CAAC,CAAC;oBAC1C,IAAI,CAAC,UAA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WAAW,CAAC,SAAS,GAAG,MAAM,CAAC;SAChC;QAED,IAAI,SAAS,YAAY,2BAAY,EAAE;YACrC,WAAW,CAAC,MAAM,GAAG,6BAAc,CAAC,GAAG,CAAC,SAAS,CAAC,CAAC,IAAI,CAAC;SACzD;IACH,CAAC;;;AA5Qa,yBAAW,GAAmB,KAAK,EAAE,SAAS,EAAE,EAAE,EAAE,EAAE,CAAC,EAAE,EAAE,AAAhD,CAAiD;AAD/D,sCAAa","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, BentleyError, BentleyStatus, GuidString, IModelStatus, Logger, RpcInterfaceStatus, StatusCategory, Tracing } from \"@itwin/core-bentley\";\r\nimport { CommonLoggerCategory } from \"../../CommonLoggerCategory\";\r\nimport { IModelRpcProps } from \"../../IModel\";\r\nimport { IModelError } from \"../../IModelError\";\r\nimport { RpcInterface } from \"../../RpcInterface\";\r\nimport { SessionProps } from \"../../SessionProps\";\r\nimport { RpcConfiguration } from \"./RpcConfiguration\";\r\nimport { RpcProtocolEvent, RpcRequestStatus } from \"./RpcConstants\";\r\nimport { RpcControlChannel, RpcNotFoundResponse, RpcPendingResponse } from \"./RpcControl\";\r\nimport { RpcMarshaling, RpcSerializedValue } from \"./RpcMarshaling\";\r\nimport { RpcOperation } from \"./RpcOperation\";\r\nimport { RpcManagedStatus, RpcProtocol, RpcProtocolVersion, RpcRequestFulfillment, SerializedRpcRequest } from \"./RpcProtocol\";\r\nimport { CURRENT_INVOCATION, RpcRegistry } from \"./RpcRegistry\";\r\n\r\n/* eslint-disable deprecation/deprecation */\r\n\r\n/** The properties of an RpcActivity.\r\n * @public\r\n * @extensions\r\n */\r\nexport interface RpcActivity extends SessionProps {\r\n /** Used for logging to correlate an Rpc activity between frontend and backend */\r\n readonly activityId: GuidString;\r\n\r\n /** access token for authorization */\r\n readonly accessToken: AccessToken;\r\n\r\n /** the name of the current rpc method */\r\n readonly rpcMethod?: string;\r\n\r\n readonly user?: string;\r\n}\r\n\r\n/** Serialized format for sending the request across the RPC layer\r\n * @public\r\n */\r\nexport interface SerializedRpcActivity {\r\n id: string;\r\n applicationId: string;\r\n applicationVersion: string;\r\n sessionId: string;\r\n authorization: string;\r\n user?: string;\r\n csrfToken?: { headerName: string, headerValue: string };\r\n}\r\n\r\n/** @internal */\r\nexport type RpcActivityRun = (activity: RpcActivity, fn: () => Promise<any>) => Promise<any>;\r\n\r\n/** An RPC operation invocation in response to a request.\r\n * @internal\r\n */\r\nexport class RpcInvocation {\r\n public static runActivity: RpcActivityRun = async (_activity, fn) => fn();\r\n private _threw: boolean = false;\r\n private _pending: boolean = false;\r\n private _notFound: boolean = false;\r\n private _noContent: boolean = false;\r\n private _timeIn: number = 0;\r\n private _timeOut: number = 0;\r\n\r\n /** The protocol for this invocation. */\r\n public readonly protocol: RpcProtocol;\r\n\r\n /** The received request. */\r\n public readonly request: SerializedRpcRequest;\r\n\r\n /** The operation of the request. */\r\n public readonly operation: RpcOperation = undefined as any;\r\n\r\n /** The implementation response. */\r\n public readonly result: Promise<any>;\r\n\r\n /** The fulfillment for this request. */\r\n public readonly fulfillment: Promise<RpcRequestFulfillment>;\r\n\r\n /** The status for this request. */\r\n public get status(): RpcRequestStatus {\r\n return this._threw ? RpcRequestStatus.Rejected :\r\n this._pending ? RpcRequestStatus.Pending :\r\n this._notFound ? RpcRequestStatus.NotFound :\r\n this._noContent ? RpcRequestStatus.NoContent :\r\n RpcRequestStatus.Resolved;\r\n }\r\n\r\n /** The elapsed time for this invocation. */\r\n public get elapsed(): number {\r\n return this._timeOut - this._timeIn;\r\n }\r\n\r\n /**\r\n * The invocation for the current RPC operation.\r\n * @note The return value of this function is only reliable in an RPC impl class member function where program control was received from the RpcInvocation constructor function.\r\n */\r\n public static current(rpcImpl: RpcInterface): RpcInvocation {\r\n return (rpcImpl as any)[CURRENT_INVOCATION];\r\n }\r\n\r\n /** Constructs an invocation. */\r\n public constructor(protocol: RpcProtocol, request: SerializedRpcRequest) {\r\n this._timeIn = new Date().getTime();\r\n this.protocol = protocol;\r\n this.request = request;\r\n\r\n try {\r\n try {\r\n this.operation = RpcOperation.lookup(this.request.operation.interfaceDefinition, this.request.operation.operationName);\r\n\r\n const backend = this.operation.interfaceVersion;\r\n const frontend = this.request.operation.interfaceVersion;\r\n if (!RpcInterface.isVersionCompatible(backend, frontend)) {\r\n throw new IModelError(RpcInterfaceStatus.IncompatibleVersion, `Backend version ${backend} does not match frontend version ${frontend} for RPC interface ${this.operation.operationName}.`);\r\n }\r\n } catch (error) {\r\n if (this.handleUnknownOperation(error)) {\r\n this.operation = RpcOperation.lookup(this.request.operation.interfaceDefinition, this.request.operation.operationName);\r\n } else {\r\n throw error;\r\n }\r\n }\r\n\r\n this.result = this.resolve();\r\n } catch (error) {\r\n this.result = this.reject(error);\r\n }\r\n\r\n this.fulfillment = this.result.then(async (value) => this._threw ? this.fulfillRejected(value) : this.fulfillResolved(value), async (reason) => this.fulfillRejected(reason));\r\n }\r\n\r\n private handleUnknownOperation(error: any): boolean {\r\n RpcControlChannel.ensureInitialized();\r\n return this.protocol.configuration.controlChannel.handleUnknownOperation(this, error);\r\n }\r\n\r\n public static sanitizeForLog(activity?: RpcActivity) {\r\n /* eslint-disable @typescript-eslint/naming-convention */\r\n return activity ? {\r\n ActivityId: activity.activityId, SessionId: activity.sessionId, ApplicationId: activity.applicationId, ApplicationVersion: activity.applicationVersion, rpcMethod: activity.rpcMethod,\r\n } : undefined;\r\n /* eslint-enable @typescript-eslint/naming-convention */\r\n }\r\n\r\n private async resolve(): Promise<any> {\r\n const request = this.request;\r\n const activity: RpcActivity = {\r\n activityId: request.id,\r\n applicationId: request.applicationId,\r\n applicationVersion: request.applicationVersion,\r\n sessionId: request.sessionId,\r\n user: request.user,\r\n accessToken: request.authorization,\r\n rpcMethod: request.operation.operationName,\r\n };\r\n\r\n try {\r\n this.protocol.events.raiseEvent(RpcProtocolEvent.RequestReceived, this);\r\n\r\n const parameters = request.parametersOverride || RpcMarshaling.deserialize(this.protocol, request.parameters);\r\n this.applyPolicies(parameters);\r\n const impl = RpcRegistry.instance.getImplForInterface(this.operation.interfaceDefinition);\r\n (impl as any)[CURRENT_INVOCATION] = this;\r\n const op = this.lookupOperationFunction(impl);\r\n\r\n return await RpcInvocation.runActivity(activity, async () => op.call(impl, ...parameters)\r\n .catch(async (error) => {\r\n // this catch block is intentionally placed inside `runActivity` to attach the right logging metadata and use the correct openTelemetry span.\r\n if (!(error instanceof RpcPendingResponse)) {\r\n Logger.logError(CommonLoggerCategory.RpcInterfaceBackend, \"Error in RPC operation\", { error: BentleyError.getErrorProps(error) });\r\n Tracing.setAttributes({ error: true });\r\n }\r\n throw error;\r\n }));\r\n } catch (error: unknown) {\r\n return this.reject(error);\r\n }\r\n }\r\n\r\n private applyPolicies(parameters: any) {\r\n if (!parameters || !Array.isArray(parameters))\r\n return;\r\n\r\n for (let i = 0; i !== parameters.length; ++i) {\r\n const parameter = parameters[i];\r\n const isToken = typeof (parameter) === \"object\" && parameter !== null && parameter.hasOwnProperty(\"iModelId\") && parameter.hasOwnProperty(\"iTwinId\");\r\n if (isToken && this.protocol.checkToken && !this.operation.policy.allowTokenMismatch) {\r\n const inflated = this.protocol.inflateToken(parameter, this.request);\r\n parameters[i] = inflated;\r\n\r\n if (!RpcInvocation.compareTokens(parameter, inflated)) {\r\n if (RpcConfiguration.throwOnTokenMismatch) {\r\n throw new IModelError(BentleyStatus.ERROR, \"IModelRpcProps mismatch detected for this request.\");\r\n } else {\r\n Logger.logWarning(CommonLoggerCategory.RpcInterfaceBackend, \"IModelRpcProps mismatch detected for this request.\");\r\n }\r\n }\r\n }\r\n }\r\n }\r\n\r\n private static compareTokens(a: IModelRpcProps, b: IModelRpcProps): boolean {\r\n return a.key === b.key &&\r\n a.iTwinId === b.iTwinId &&\r\n a.iModelId === b.iModelId &&\r\n (undefined === a.changeset || (a.changeset.id === b.changeset?.id));\r\n }\r\n\r\n private async reject(error: any): Promise<any> {\r\n this._threw = true;\r\n return error;\r\n }\r\n\r\n private async fulfillResolved(value: any): Promise<RpcRequestFulfillment> {\r\n this._timeOut = new Date().getTime();\r\n this.protocol.events.raiseEvent(RpcProtocolEvent.BackendResponseCreated, this);\r\n const result = await RpcMarshaling.serialize(this.protocol, value);\r\n return this.fulfill(result, value);\r\n }\r\n\r\n private async fulfillRejected(reason: any): Promise<RpcRequestFulfillment> {\r\n this._timeOut = new Date().getTime();\r\n if (!RpcConfiguration.developmentMode)\r\n reason.stack = undefined;\r\n\r\n const result = await RpcMarshaling.serialize(this.protocol, reason);\r\n\r\n if (reason instanceof RpcPendingResponse) {\r\n this._pending = true;\r\n this._threw = false;\r\n result.objects = reason.message;\r\n this.protocol.events.raiseEvent(RpcProtocolEvent.BackendReportedPending, this);\r\n } else if (this.supportsNoContent() && reason?.errorNumber === IModelStatus.NoContent) {\r\n this._noContent = true;\r\n this._threw = false;\r\n this.protocol.events.raiseEvent(RpcProtocolEvent.BackendReportedNoContent, this);\r\n } else if (reason instanceof RpcNotFoundResponse) {\r\n this._notFound = true;\r\n this._threw = false;\r\n this.protocol.events.raiseEvent(RpcProtocolEvent.BackendReportedNotFound, this);\r\n } else {\r\n this._threw = true;\r\n this.protocol.events.raiseEvent(RpcProtocolEvent.BackendErrorOccurred, this);\r\n }\r\n\r\n return this.fulfill(result, reason);\r\n }\r\n\r\n private supportsNoContent() {\r\n if (!this.request.protocolVersion) {\r\n return false;\r\n }\r\n\r\n return RpcProtocol.protocolVersion >= RpcProtocolVersion.IntroducedNoContent && this.request.protocolVersion >= RpcProtocolVersion.IntroducedNoContent;\r\n }\r\n\r\n private supportsStatusCategory() {\r\n if (!this.request.protocolVersion) {\r\n return false;\r\n }\r\n\r\n if (!this.protocol.supportsStatusCategory) {\r\n return false;\r\n }\r\n\r\n return RpcProtocol.protocolVersion >= RpcProtocolVersion.IntroducedStatusCategory && this.request.protocolVersion >= RpcProtocolVersion.IntroducedStatusCategory;\r\n }\r\n\r\n private fulfill(result: RpcSerializedValue, rawResult: any): RpcRequestFulfillment {\r\n const fulfillment: RpcRequestFulfillment = {\r\n result,\r\n rawResult,\r\n status: this.protocol.getCode(this.status),\r\n id: this.request.id,\r\n interfaceName: (typeof (this.operation) === \"undefined\") ? \"\" : this.operation.interfaceDefinition.interfaceName,\r\n allowCompression: this.operation?.policy.allowResponseCompression || false,\r\n };\r\n\r\n this.transformResponseStatus(fulfillment, rawResult);\r\n\r\n try {\r\n const impl = RpcRegistry.instance.getImplForInterface(this.operation.interfaceDefinition) as any;\r\n if (impl[CURRENT_INVOCATION] === this) {\r\n impl[CURRENT_INVOCATION] = undefined;\r\n }\r\n } catch (_err) { }\r\n\r\n return fulfillment;\r\n }\r\n\r\n private lookupOperationFunction(implementation: RpcInterface): (...args: any[]) => Promise<any> {\r\n const func = (implementation as any)[this.operation.operationName];\r\n if (!func || typeof (func) !== \"function\")\r\n throw new IModelError(BentleyStatus.ERROR, `RPC interface class \"${implementation.constructor.name}\" does not implement operation \"${this.operation.operationName}\".`);\r\n\r\n return func;\r\n }\r\n\r\n private transformResponseStatus(fulfillment: RpcRequestFulfillment, rawResult: any) {\r\n if (!this.supportsStatusCategory()) {\r\n return;\r\n }\r\n\r\n let managedStatus: \"notFound\" | \"pending\" | \"noContent\" | undefined;\r\n if (this._pending) {\r\n managedStatus = \"pending\";\r\n } else if (this._notFound) {\r\n managedStatus = \"notFound\";\r\n } else if (this._noContent) {\r\n managedStatus = \"noContent\";\r\n }\r\n\r\n if (managedStatus) {\r\n const responseValue = fulfillment.result.objects;\r\n const status: RpcManagedStatus = { iTwinRpcCoreResponse: true, managedStatus, responseValue };\r\n fulfillment.result.objects = JSON.stringify(status);\r\n status.responseValue = rawResult; // for ipc case\r\n fulfillment.rawResult = status;\r\n }\r\n\r\n if (rawResult instanceof BentleyError) {\r\n fulfillment.status = StatusCategory.for(rawResult).code;\r\n }\r\n }\r\n}\r\n"]}
|
|
1
|
+
{"version":3,"file":"RpcInvocation.js","sourceRoot":"","sources":["../../../../src/rpc/core/RpcInvocation.ts"],"names":[],"mappings":";AAAA;;;+FAG+F;AAC/F;;GAEG;;;;AAEH,sDAA8J;AAC9J,qEAAkE;AAElE,mDAAgD;AAChD,qDAAkD;AAElD,yDAAsD;AACtD,iDAAoE;AACpE,6CAA0F;AAC1F,mDAAoE;AACpE,iDAA8C;AAC9C,+CAA+H;AAC/H,+CAAgE;AAqChE;;GAEG;AACH,MAAa,aAAa;IAwBxB,mCAAmC;IACnC,IAAW,MAAM;QACf,OAAO,IAAI,CAAC,MAAM,CAAC,CAAC,CAAC,+BAAgB,CAAC,QAAQ,CAAC,CAAC;YAC9C,IAAI,CAAC,QAAQ,CAAC,CAAC,CAAC,+BAAgB,CAAC,OAAO,CAAC,CAAC;gBACxC,IAAI,CAAC,SAAS,CAAC,CAAC,CAAC,+BAAgB,CAAC,QAAQ,CAAC,CAAC;oBAC1C,IAAI,CAAC,UAAU,CAAC,CAAC,CAAC,+BAAgB,CAAC,SAAS,CAAC,CAAC;wBAC5C,+BAAgB,CAAC,QAAQ,CAAC;IACpC,CAAC;IAED,4CAA4C;IAC5C,IAAW,OAAO;QAChB,OAAO,IAAI,CAAC,QAAQ,GAAG,IAAI,CAAC,OAAO,CAAC;IACtC,CAAC;IAED;;;OAGG;IACI,MAAM,CAAC,OAAO,CAAC,OAAqB;QACzC,OAAQ,OAAe,CAAC,gCAAkB,CAAC,CAAC;IAC9C,CAAC;IAED,gCAAgC;IAChC,YAAmB,QAAqB,EAAE,OAA6B;QA7C/D,WAAM,GAAY,KAAK,CAAC;QACxB,aAAQ,GAAY,KAAK,CAAC;QAC1B,cAAS,GAAY,KAAK,CAAC;QAC3B,eAAU,GAAY,KAAK,CAAC;QAC5B,YAAO,GAAW,CAAC,CAAC;QACpB,aAAQ,GAAW,CAAC,C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AAC;IAEO,uBAAuB,CAAC,WAAkC,EAAE,SAAc;QAChF,IAAI,CAAC,IAAI,CAAC,sBAAsB,EAAE,EAAE;YAClC,OAAO;SACR;QAED,IAAI,aAA+D,CAAC;QACpE,IAAI,IAAI,CAAC,QAAQ,EAAE;YACjB,aAAa,GAAG,SAAS,CAAC;SAC3B;aAAM,IAAI,IAAI,CAAC,SAAS,EAAE;YACzB,aAAa,GAAG,UAAU,CAAC;SAC5B;aAAM,IAAI,IAAI,CAAC,UAAU,EAAE;YAC1B,aAAa,GAAG,WAAW,CAAC;SAC7B;QAED,IAAI,aAAa,EAAE;YACjB,MAAM,aAAa,GAAG,WAAW,CAAC,MAAM,CAAC,OAAO,CAAC;YACjD,MAAM,MAAM,GAAqB,EAAE,oBAAoB,EAAE,IAAI,EAAE,aAAa,EAAE,aAAa,EAAE,CAAC;YAC9F,WAAW,CAAC,MAAM,CAAC,OAAO,GAAG,IAAI,CAAC,SAAS,CAAC,MAAM,CAAC,CAAC;YACpD,MAAM,CAAC,aAAa,GAAG,SAAS,CAAC,CAAC,eAAe;YACjD,WAAW,CAAC,SAAS,GAAG,MAAM,CAAC;SAChC;QAED,IAAI,SAAS,YAAY,2BAAY,EAAE;YACrC,WAAW,CAAC,MAAM,GAAG,6BAAc,CAAC,GAAG,CAAC,SAAS,CAAC,CAAC,IAAI,CAAC;SACzD;IACH,CAAC;;;AA5Qa,yBAAW,GAAmB,KAAK,EAAE,SAAS,EAAE,EAAE,EAAE,EAAE,CAAC,EAAE,EAAE,AAAhD,CAAiD;AAD/D,sCAAa","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, BentleyError, BentleyStatus, GuidString, IModelStatus, Logger, RpcInterfaceStatus, StatusCategory, Tracing } from \"@itwin/core-bentley\";\r\nimport { CommonLoggerCategory } from \"../../CommonLoggerCategory\";\r\nimport { IModelRpcProps } from \"../../IModel\";\r\nimport { IModelError } from \"../../IModelError\";\r\nimport { RpcInterface } from \"../../RpcInterface\";\r\nimport { SessionProps } from \"../../SessionProps\";\r\nimport { RpcConfiguration } from \"./RpcConfiguration\";\r\nimport { RpcProtocolEvent, RpcRequestStatus } from \"./RpcConstants\";\r\nimport { RpcControlChannel, RpcNotFoundResponse, RpcPendingResponse } from \"./RpcControl\";\r\nimport { RpcMarshaling, RpcSerializedValue } from \"./RpcMarshaling\";\r\nimport { RpcOperation } from \"./RpcOperation\";\r\nimport { RpcManagedStatus, RpcProtocol, RpcProtocolVersion, RpcRequestFulfillment, SerializedRpcRequest } from \"./RpcProtocol\";\r\nimport { CURRENT_INVOCATION, RpcRegistry } from \"./RpcRegistry\";\r\n\r\n/* eslint-disable deprecation/deprecation */\r\n\r\n/** The properties of an RpcActivity.\r\n * @public\r\n * @extensions\r\n */\r\nexport interface RpcActivity extends SessionProps {\r\n /** Used for logging to correlate an Rpc activity between frontend and backend */\r\n readonly activityId: GuidString;\r\n\r\n /** access token for authorization */\r\n readonly accessToken: AccessToken;\r\n\r\n /** the name of the current rpc method */\r\n readonly rpcMethod?: string;\r\n\r\n readonly user?: string;\r\n}\r\n\r\n/** Serialized format for sending the request across the RPC layer\r\n * @public\r\n */\r\nexport interface SerializedRpcActivity {\r\n id: string;\r\n applicationId: string;\r\n applicationVersion: string;\r\n sessionId: string;\r\n authorization: string;\r\n user?: string;\r\n csrfToken?: { headerName: string, headerValue: string };\r\n}\r\n\r\n/** @internal */\r\nexport type RpcActivityRun = (activity: RpcActivity, fn: () => Promise<any>) => Promise<any>;\r\n\r\n/** An RPC operation invocation in response to a request.\r\n * @internal\r\n */\r\nexport class RpcInvocation {\r\n public static runActivity: RpcActivityRun = async (_activity, fn) => fn();\r\n private _threw: boolean = false;\r\n private _pending: boolean = false;\r\n private _notFound: boolean = false;\r\n private _noContent: boolean = false;\r\n private _timeIn: number = 0;\r\n private _timeOut: number = 0;\r\n\r\n /** The protocol for this invocation. */\r\n public readonly protocol: RpcProtocol;\r\n\r\n /** The received request. */\r\n public readonly request: SerializedRpcRequest;\r\n\r\n /** The operation of the request. */\r\n public readonly operation: RpcOperation = undefined as any;\r\n\r\n /** The implementation response. */\r\n public readonly result: Promise<any>;\r\n\r\n /** The fulfillment for this request. */\r\n public readonly fulfillment: Promise<RpcRequestFulfillment>;\r\n\r\n /** The status for this request. */\r\n public get status(): RpcRequestStatus {\r\n return this._threw ? RpcRequestStatus.Rejected :\r\n this._pending ? RpcRequestStatus.Pending :\r\n this._notFound ? RpcRequestStatus.NotFound :\r\n this._noContent ? RpcRequestStatus.NoContent :\r\n RpcRequestStatus.Resolved;\r\n }\r\n\r\n /** The elapsed time for this invocation. */\r\n public get elapsed(): number {\r\n return this._timeOut - this._timeIn;\r\n }\r\n\r\n /**\r\n * The invocation for the current RPC operation.\r\n * @note The return value of this function is only reliable in an RPC impl class member function where program control was received from the RpcInvocation constructor function.\r\n */\r\n public static current(rpcImpl: RpcInterface): RpcInvocation {\r\n return (rpcImpl as any)[CURRENT_INVOCATION];\r\n }\r\n\r\n /** Constructs an invocation. */\r\n public constructor(protocol: RpcProtocol, request: SerializedRpcRequest) {\r\n this._timeIn = new Date().getTime();\r\n this.protocol = protocol;\r\n this.request = request;\r\n\r\n try {\r\n try {\r\n this.operation = RpcOperation.lookup(this.request.operation.interfaceDefinition, this.request.operation.operationName);\r\n\r\n const backend = this.operation.interfaceVersion;\r\n const frontend = this.request.operation.interfaceVersion;\r\n if (!RpcInterface.isVersionCompatible(backend, frontend)) {\r\n throw new IModelError(RpcInterfaceStatus.IncompatibleVersion, `Backend version ${backend} does not match frontend version ${frontend} for RPC interface ${this.operation.operationName}.`);\r\n }\r\n } catch (error) {\r\n if (this.handleUnknownOperation(error)) {\r\n this.operation = RpcOperation.lookup(this.request.operation.interfaceDefinition, this.request.operation.operationName);\r\n } else {\r\n throw error;\r\n }\r\n }\r\n\r\n this.result = this.resolve();\r\n } catch (error) {\r\n this.result = this.reject(error);\r\n }\r\n\r\n this.fulfillment = this.result.then(async (value) => this._threw ? this.fulfillRejected(value) : this.fulfillResolved(value), async (reason) => this.fulfillRejected(reason));\r\n }\r\n\r\n private handleUnknownOperation(error: any): boolean {\r\n RpcControlChannel.ensureInitialized();\r\n return this.protocol.configuration.controlChannel.handleUnknownOperation(this, error);\r\n }\r\n\r\n public static sanitizeForLog(activity?: RpcActivity) {\r\n /* eslint-disable @typescript-eslint/naming-convention */\r\n return activity ? {\r\n ActivityId: activity.activityId, SessionId: activity.sessionId, ApplicationId: activity.applicationId, ApplicationVersion: activity.applicationVersion, rpcMethod: activity.rpcMethod,\r\n } : undefined;\r\n /* eslint-enable @typescript-eslint/naming-convention */\r\n }\r\n\r\n private async resolve(): Promise<any> {\r\n const request = this.request;\r\n const activity: RpcActivity = {\r\n activityId: request.id,\r\n applicationId: request.applicationId,\r\n applicationVersion: request.applicationVersion,\r\n sessionId: request.sessionId,\r\n user: request.user,\r\n accessToken: request.authorization,\r\n rpcMethod: request.operation.operationName,\r\n };\r\n\r\n try {\r\n this.protocol.events.raiseEvent(RpcProtocolEvent.RequestReceived, this);\r\n\r\n const parameters = request.parametersOverride || RpcMarshaling.deserialize(this.protocol, request.parameters);\r\n this.applyPolicies(parameters);\r\n const impl = RpcRegistry.instance.getImplForInterface(this.operation.interfaceDefinition);\r\n (impl as any)[CURRENT_INVOCATION] = this;\r\n const op = this.lookupOperationFunction(impl);\r\n\r\n return await RpcInvocation.runActivity(activity, async () => op.call(impl, ...parameters)\r\n .catch(async (error) => {\r\n // this catch block is intentionally placed inside `runActivity` to attach the right logging metadata and use the correct openTelemetry span.\r\n if (!(error instanceof RpcPendingResponse)) {\r\n Logger.logError(CommonLoggerCategory.RpcInterfaceBackend, \"Error in RPC operation\", { error: BentleyError.getErrorProps(error) });\r\n Tracing.setAttributes({ error: true });\r\n }\r\n throw error;\r\n }));\r\n } catch (error: unknown) {\r\n return this.reject(error);\r\n }\r\n }\r\n\r\n private applyPolicies(parameters: any) {\r\n if (!parameters || !Array.isArray(parameters))\r\n return;\r\n\r\n for (let i = 0; i !== parameters.length; ++i) {\r\n const parameter = parameters[i];\r\n const isToken = typeof (parameter) === \"object\" && parameter !== null && parameter.hasOwnProperty(\"iModelId\") && parameter.hasOwnProperty(\"iTwinId\");\r\n if (isToken && this.protocol.checkToken && !this.operation.policy.allowTokenMismatch) {\r\n const inflated = this.protocol.inflateToken(parameter, this.request);\r\n parameters[i] = inflated;\r\n\r\n if (!RpcInvocation.compareTokens(parameter, inflated)) {\r\n if (RpcConfiguration.throwOnTokenMismatch) {\r\n throw new IModelError(BentleyStatus.ERROR, \"IModelRpcProps mismatch detected for this request.\");\r\n } else {\r\n Logger.logWarning(CommonLoggerCategory.RpcInterfaceBackend, \"IModelRpcProps mismatch detected for this request.\");\r\n }\r\n }\r\n }\r\n }\r\n }\r\n\r\n private static compareTokens(a: IModelRpcProps, b: IModelRpcProps): boolean {\r\n return a.key === b.key &&\r\n a.iTwinId === b.iTwinId &&\r\n a.iModelId === b.iModelId &&\r\n (undefined === a.changeset || (a.changeset.id === b.changeset?.id));\r\n }\r\n\r\n private async reject(error: any): Promise<any> {\r\n this._threw = true;\r\n return error;\r\n }\r\n\r\n private async fulfillResolved(value: any): Promise<RpcRequestFulfillment> {\r\n this._timeOut = new Date().getTime();\r\n this.protocol.events.raiseEvent(RpcProtocolEvent.BackendResponseCreated, this);\r\n const result = RpcMarshaling.serialize(this.protocol, value);\r\n return this.fulfill(result, value);\r\n }\r\n\r\n private async fulfillRejected(reason: any): Promise<RpcRequestFulfillment> {\r\n this._timeOut = new Date().getTime();\r\n if (!RpcConfiguration.developmentMode)\r\n reason.stack = undefined;\r\n\r\n const result = RpcMarshaling.serialize(this.protocol, reason);\r\n\r\n if (reason instanceof RpcPendingResponse) {\r\n this._pending = true;\r\n this._threw = false;\r\n result.objects = reason.message;\r\n this.protocol.events.raiseEvent(RpcProtocolEvent.BackendReportedPending, this);\r\n } else if (this.supportsNoContent() && reason?.errorNumber === IModelStatus.NoContent) {\r\n this._noContent = true;\r\n this._threw = false;\r\n this.protocol.events.raiseEvent(RpcProtocolEvent.BackendReportedNoContent, this);\r\n } else if (reason instanceof RpcNotFoundResponse) {\r\n this._notFound = true;\r\n this._threw = false;\r\n this.protocol.events.raiseEvent(RpcProtocolEvent.BackendReportedNotFound, this);\r\n } else {\r\n this._threw = true;\r\n this.protocol.events.raiseEvent(RpcProtocolEvent.BackendErrorOccurred, this);\r\n }\r\n\r\n return this.fulfill(result, reason);\r\n }\r\n\r\n private supportsNoContent() {\r\n if (!this.request.protocolVersion) {\r\n return false;\r\n }\r\n\r\n return RpcProtocol.protocolVersion >= RpcProtocolVersion.IntroducedNoContent && this.request.protocolVersion >= RpcProtocolVersion.IntroducedNoContent;\r\n }\r\n\r\n private supportsStatusCategory() {\r\n if (!this.request.protocolVersion) {\r\n return false;\r\n }\r\n\r\n if (!this.protocol.supportsStatusCategory) {\r\n return false;\r\n }\r\n\r\n return RpcProtocol.protocolVersion >= RpcProtocolVersion.IntroducedStatusCategory && this.request.protocolVersion >= RpcProtocolVersion.IntroducedStatusCategory;\r\n }\r\n\r\n private fulfill(result: RpcSerializedValue, rawResult: any): RpcRequestFulfillment {\r\n const fulfillment: RpcRequestFulfillment = {\r\n result,\r\n rawResult,\r\n status: this.protocol.getCode(this.status),\r\n id: this.request.id,\r\n interfaceName: (typeof (this.operation) === \"undefined\") ? \"\" : this.operation.interfaceDefinition.interfaceName,\r\n allowCompression: this.operation?.policy.allowResponseCompression || false,\r\n };\r\n\r\n this.transformResponseStatus(fulfillment, rawResult);\r\n\r\n try {\r\n const impl = RpcRegistry.instance.getImplForInterface(this.operation.interfaceDefinition) as any;\r\n if (impl[CURRENT_INVOCATION] === this) {\r\n impl[CURRENT_INVOCATION] = undefined;\r\n }\r\n } catch (_err) { }\r\n\r\n return fulfillment;\r\n }\r\n\r\n private lookupOperationFunction(implementation: RpcInterface): (...args: any[]) => Promise<any> {\r\n const func = (implementation as any)[this.operation.operationName];\r\n if (!func || typeof (func) !== \"function\")\r\n throw new IModelError(BentleyStatus.ERROR, `RPC interface class \"${implementation.constructor.name}\" does not implement operation \"${this.operation.operationName}\".`);\r\n\r\n return func;\r\n }\r\n\r\n private transformResponseStatus(fulfillment: RpcRequestFulfillment, rawResult: any) {\r\n if (!this.supportsStatusCategory()) {\r\n return;\r\n }\r\n\r\n let managedStatus: \"notFound\" | \"pending\" | \"noContent\" | undefined;\r\n if (this._pending) {\r\n managedStatus = \"pending\";\r\n } else if (this._notFound) {\r\n managedStatus = \"notFound\";\r\n } else if (this._noContent) {\r\n managedStatus = \"noContent\";\r\n }\r\n\r\n if (managedStatus) {\r\n const responseValue = fulfillment.result.objects;\r\n const status: RpcManagedStatus = { iTwinRpcCoreResponse: true, managedStatus, responseValue };\r\n fulfillment.result.objects = JSON.stringify(status);\r\n status.responseValue = rawResult; // for ipc case\r\n fulfillment.rawResult = status;\r\n }\r\n\r\n if (rawResult instanceof BentleyError) {\r\n fulfillment.status = StatusCategory.for(rawResult).code;\r\n }\r\n }\r\n}\r\n"]}
|
|
@@ -29,7 +29,7 @@ export declare namespace RpcSerializedValue {
|
|
|
29
29
|
export declare class RpcMarshaling {
|
|
30
30
|
private constructor();
|
|
31
31
|
/** Serializes a value. */
|
|
32
|
-
static serialize(protocol: RpcProtocol | undefined, value: any):
|
|
32
|
+
static serialize(protocol: RpcProtocol | undefined, value: any): RpcSerializedValue;
|
|
33
33
|
/** Deserializes a value. */
|
|
34
34
|
static deserialize(protocol: RpcProtocol | undefined, value: RpcSerializedValue): any;
|
|
35
35
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"RpcMarshaling.d.ts","sourceRoot":"","sources":["../../../../src/rpc/core/RpcMarshaling.ts"],"names":[],"mappings":"AAIA;;GAEG;AAGH,OAAO,EAAE,eAAe,EAAE,MAAM,oBA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ChB,IAAI,EAAE,UAAU,EAAE,CAAC;IACnB,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB,MAAM,CAAC,EAAE,eAAe,CAAC;CAC1B;AAED,gBAAgB;AAChB,yBAAiB,kBAAkB,CAAC;IAClC,SAAgB,MAAM,CAAC,OAAO,SAAK,EAAE,IAAI,GAAE,UAAU,EAAO,GAAG,kBAAkB,CAEhF;CACF;AAED,gBAAgB;AAChB,qBAAa,aAAa;IACxB,OAAO;IAEP,0BAA0B;WACZ,SAAS,CAAC,QAAQ,EAAE,WAAW,GAAG,SAAS,EAAE,KAAK,EAAE,GAAG,GAAG,kBAAkB;IAgB1F,4BAA4B;WACd,WAAW,CAAC,QAAQ,EAAE,WAAW,GAAG,SAAS,EAAE,KAAK,EAAE,kBAAkB,GAAG,GAAG;CAoB7F"}
|
|
@@ -36,7 +36,7 @@ var RpcSerializedValue;
|
|
|
36
36
|
class RpcMarshaling {
|
|
37
37
|
constructor() { }
|
|
38
38
|
/** Serializes a value. */
|
|
39
|
-
static
|
|
39
|
+
static serialize(protocol, value) {
|
|
40
40
|
const serialized = RpcSerializedValue.create();
|
|
41
41
|
if (typeof (value) === "undefined") {
|
|
42
42
|
return serialized;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"RpcMarshaling.js","sourceRoot":"","sources":["../../../../src/rpc/core/RpcMarshaling.ts"],"names":[],"mappings":";AAAA;;;+FAG+F;AAC/F;;GAEG;;;AAEH,mDAA+D;AAI/D,0BAA0B;AAC1B,4CAA4C;AAE5C,SAAS,QAAQ,CAAC,GAAQ;IACxB,OAAO,GAAG,IAAI,OAAO,CAAC,GAAG,CAAC,WAAW,CAAC,KAAK,WAAW,IAAI,OAAO,CAAC,GAAG,CAAC,WAAW,CAAC,QAAQ,CAAC,KAAK,UAAU,IAAI,GAAG,CAAC,WAAW,CAAC,QAAQ,CAAC,GAAG,CAAC,CAAC;AAC9I,CAAC;AAED,IAAI,gBAAoC,CAAC;AACzC,IAAI,c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EO,MAAM,CAAC,YAAY,CAAC,KAAU;QACpC,IAAI,KAAK,YAAY,KAAK,EAAE;YAC1B,MAAM,KAAK,GAAG,MAAM,CAAC,yBAAyB,CAAC,KAAK,CAAC,CAAC;YACtD,KAAK,CAAC,OAAO,GAAG,EAAE,YAAY,EAAE,IAAI,EAAE,UAAU,EAAE,IAAI,EAAE,QAAQ,EAAE,IAAI,EAAE,KAAK,EAAE,IAAI,EAAE,CAAC;YACtF,KAAK,CAAC,IAAI,GAAG,EAAE,YAAY,EAAE,IAAI,EAAE,UAAU,EAAE,IAAI,EAAE,QAAQ,EAAE,IAAI,EAAE,KAAK,EAAE,KAAK,CAAC,IAAI,EAAE,CAAC;YACzF,KAAK,CAAC,OAAO,GAAG,EAAE,YAAY,EAAE,IAAI,EAAE,UAAU,EAAE,IAAI,EAAE,QAAQ,EAAE,IAAI,EAAE,KAAK,EAAE,KAAK,CAAC,OAAO,EAAE,CAAC;YAC/F,KAAK,CAAC,KAAK,GAAG,EAAE,YAAY,EAAE,IAAI,EAAE,UAAU,EAAE,IAAI,EAAE,QAAQ,EAAE,IAAI,EAAE,KAAK,EAAE,KAAK,CAAC,KAAK,EAAE,CAAC;YAC3F,OAAO,MAAM,CAAC,MAAM,CAAC,MAAM,CAAC,SAAS,EAAE,KAAK,CAAC,CAAC;SAC/C;QAED,OAAO,SAAS,CAAC;IACnB,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 RpcInterface\r\n */\r\n\r\nimport { BentleyStatus, IModelError } from \"../../IModelError\";\r\nimport { BackendReadable } from \"../../BackendTypes\";\r\nimport { RpcProtocol } from \"./RpcProtocol\";\r\n\r\n// cspell:ignore unmarshal\r\n/* eslint-disable deprecation/deprecation */\r\n\r\nfunction isBuffer(val: any): boolean {\r\n return val && typeof (val.constructor) !== \"undefined\" && typeof (val.constructor.isBuffer) === \"function\" && val.constructor.isBuffer(val);\r\n}\r\n\r\nlet marshalingTarget: RpcSerializedValue;\r\nlet chunkThreshold = 0;\r\n\r\n/** @internal */\r\nexport interface MarshalingBinaryMarker {\r\n isBinary: true;\r\n index: number;\r\n size: number;\r\n chunks: number;\r\n}\r\n\r\n/** @internal */\r\nexport namespace MarshalingBinaryMarker {\r\n export function createDefault(): MarshalingBinaryMarker {\r\n return { isBinary: true, index: 0, size: -1, chunks: 1 };\r\n }\r\n}\r\n\r\n/** @internal */\r\nexport interface RpcSerializedValue {\r\n objects: string;\r\n data: Uint8Array[];\r\n chunks?: number;\r\n stream?: BackendReadable;\r\n}\r\n\r\n/** @internal */\r\nexport namespace RpcSerializedValue {\r\n export function create(objects = \"\", data: Uint8Array[] = []): RpcSerializedValue {\r\n return { objects, data };\r\n }\r\n}\r\n\r\n/** @internal */\r\nexport class RpcMarshaling {\r\n private constructor() { }\r\n\r\n /** Serializes a value. */\r\n public static async serialize(protocol: RpcProtocol | undefined, value: any): Promise<RpcSerializedValue> {\r\n const serialized = RpcSerializedValue.create();\r\n\r\n if (typeof (value) === \"undefined\") {\r\n return serialized;\r\n }\r\n\r\n marshalingTarget = serialized;\r\n chunkThreshold = protocol ? protocol.transferChunkThreshold : 0;\r\n serialized.objects = JSON.stringify(value, (_key, _value) => WireFormat.marshal(_key, _value));\r\n marshalingTarget = undefined as any;\r\n chunkThreshold = 0;\r\n\r\n return serialized;\r\n }\r\n\r\n /** Deserializes a value. */\r\n public static deserialize(protocol: RpcProtocol | undefined, value: RpcSerializedValue): any {\r\n if (value.objects === \"\") {\r\n return undefined;\r\n }\r\n\r\n marshalingTarget = value;\r\n chunkThreshold = protocol ? protocol.transferChunkThreshold : 0;\r\n let result;\r\n try {\r\n result = JSON.parse(value.objects, (_key, _value) => WireFormat.unmarshal(_key, _value));\r\n } catch (error) {\r\n if (error instanceof SyntaxError)\r\n throw new IModelError(BentleyStatus.ERROR, `Invalid JSON: \"${value.objects}\"`);\r\n throw error;\r\n }\r\n marshalingTarget = undefined as any;\r\n chunkThreshold = 0;\r\n\r\n return result;\r\n }\r\n}\r\n\r\nclass WireFormat {\r\n /** JSON.stringify replacer callback. */\r\n public static marshal(this: any, _key: string, value: any) {\r\n const asBinary = WireFormat.marshalBinary(value);\r\n if (asBinary) {\r\n return asBinary;\r\n }\r\n\r\n const asError = WireFormat.marshalError(value);\r\n if (asError) {\r\n return asError;\r\n }\r\n\r\n return value;\r\n }\r\n\r\n /** JSON.parse reviver callback. */\r\n public static unmarshal(_key: string, value: any) {\r\n if (typeof (value) === \"object\" && value !== null && value.hasOwnProperty(\"isBinary\") && value.isBinary) {\r\n return WireFormat.unmarshalBinary(value);\r\n }\r\n\r\n return value;\r\n }\r\n\r\n private static marshalBinary(value: any): any {\r\n if (value instanceof Uint8Array || isBuffer(value)) {\r\n const marker: MarshalingBinaryMarker = { isBinary: true, index: -1, size: value.byteLength, chunks: 1 };\r\n\r\n if (chunkThreshold && value.byteLength > chunkThreshold) {\r\n marker.index = marshalingTarget.data.length;\r\n marker.chunks = 0;\r\n\r\n let cursor = value.byteOffset;\r\n const end = cursor + value.byteLength;\r\n let chunk = chunkThreshold;\r\n\r\n for (; ;) {\r\n if (cursor >= end) {\r\n break;\r\n }\r\n\r\n marshalingTarget.data.push(new Uint8Array(value.buffer, cursor, chunk));\r\n ++marker.chunks;\r\n cursor += chunk;\r\n\r\n const consumed = cursor - value.byteOffset;\r\n const remaining = value.byteLength - consumed;\r\n chunk = Math.min(chunkThreshold, remaining);\r\n }\r\n } else {\r\n marker.index = marshalingTarget.data.push(value) - 1;\r\n }\r\n\r\n return marker;\r\n } else {\r\n return undefined;\r\n }\r\n }\r\n\r\n private static unmarshalBinary(value: MarshalingBinaryMarker): any {\r\n if (value.index >= marshalingTarget.data.length) {\r\n throw new IModelError(BentleyStatus.ERROR, `Cannot unmarshal missing binary value.`);\r\n }\r\n\r\n if (value.chunks === 0) {\r\n return new Uint8Array();\r\n } else if (value.chunks === 1) {\r\n return new Uint8Array(marshalingTarget.data[value.index]);\r\n } else {\r\n const buffer = new ArrayBuffer(value.size);\r\n const view = new Uint8Array(buffer);\r\n\r\n let cursor = 0;\r\n for (let c = 0; c !== value.chunks; ++c) {\r\n const chunk = marshalingTarget.data[value.index + c];\r\n view.set(chunk, cursor);\r\n cursor += chunk.byteLength;\r\n }\r\n\r\n return view;\r\n }\r\n }\r\n\r\n private static marshalError(value: any) {\r\n if (value instanceof Error) {\r\n const props = Object.getOwnPropertyDescriptors(value);\r\n props.isError = { configurable: true, enumerable: true, writable: true, value: true };\r\n props.name = { configurable: true, enumerable: true, writable: true, value: value.name };\r\n props.message = { configurable: true, enumerable: true, writable: true, value: value.message };\r\n props.stack = { configurable: true, enumerable: true, writable: true, value: value.stack };\r\n return Object.create(Object.prototype, props);\r\n }\r\n\r\n return undefined;\r\n }\r\n}\r\n"]}
|
|
1
|
+
{"version":3,"file":"RpcMarshaling.js","sourceRoot":"","sources":["../../../../src/rpc/core/RpcMarshaling.ts"],"names":[],"mappings":";AAAA;;;+FAG+F;AAC/F;;GAEG;;;AAEH,mDAA+D;AAI/D,0BAA0B;AAC1B,4CAA4C;AAE5C,SAAS,QAAQ,CAAC,GAAQ;IACxB,OAAO,GAAG,IAAI,OAAO,CAAC,GAAG,CAAC,WAAW,CAAC,KAAK,WAAW,IAAI,OAAO,CAAC,GAAG,CAAC,WAAW,CAAC,QAAQ,CAAC,KAAK,UAAU,IAAI,GAAG,CAAC,WAAW,CAAC,QAAQ,CAAC,GAAG,CAAC,CAAC;AAC9I,CAAC;AAED,IAAI,gBAAoC,CAAC;AACzC,IAAI,cAAc,GAAG,CAAC,CAAC;AAUvB,gBAAgB;AAChB,IAAiB,sBAAsB,CAItC;AAJD,WAAiB,sBAAsB;IACrC,SAAgB,aAAa;QAC3B,OAAO,EAAE,QAAQ,EAAE,IAAI,EAAE,KAAK,EAAE,CAAC,EAAE,IAAI,EAAE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,UAAU,EAAE,IAAI,EAAE,QAAQ,EAAE,IAAI,EAAE,KAAK,EAAE,IAAI,EAAE,CAAC;YACtF,KAAK,CAAC,IAAI,GAAG,EAAE,YAAY,EAAE,IAAI,EAAE,UAAU,EAAE,IAAI,EAAE,QAAQ,EAAE,IAAI,EAAE,KAAK,EAAE,KAAK,CAAC,IAAI,EAAE,CAAC;YACzF,KAAK,CAAC,OAAO,GAAG,EAAE,YAAY,EAAE,IAAI,EAAE,UAAU,EAAE,IAAI,EAAE,QAAQ,EAAE,IAAI,EAAE,KAAK,EAAE,KAAK,CAAC,OAAO,EAAE,CAAC;YAC/F,KAAK,CAAC,KAAK,GAAG,EAAE,YAAY,EAAE,IAAI,EAAE,UAAU,EAAE,IAAI,EAAE,QAAQ,EAAE,IAAI,EAAE,KAAK,EAAE,KAAK,CAAC,KAAK,EAAE,CAAC;YAC3F,OAAO,MAAM,CAAC,MAAM,CAAC,MAAM,CAAC,SAAS,EAAE,KAAK,CAAC,CAAC;SAC/C;QAED,OAAO,SAAS,CAAC;IACnB,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 RpcInterface\r\n */\r\n\r\nimport { BentleyStatus, IModelError } from \"../../IModelError\";\r\nimport { BackendReadable } from \"../../BackendTypes\";\r\nimport { RpcProtocol } from \"./RpcProtocol\";\r\n\r\n// cspell:ignore unmarshal\r\n/* eslint-disable deprecation/deprecation */\r\n\r\nfunction isBuffer(val: any): boolean {\r\n return val && typeof (val.constructor) !== \"undefined\" && typeof (val.constructor.isBuffer) === \"function\" && val.constructor.isBuffer(val);\r\n}\r\n\r\nlet marshalingTarget: RpcSerializedValue;\r\nlet chunkThreshold = 0;\r\n\r\n/** @internal */\r\nexport interface MarshalingBinaryMarker {\r\n isBinary: true;\r\n index: number;\r\n size: number;\r\n chunks: number;\r\n}\r\n\r\n/** @internal */\r\nexport namespace MarshalingBinaryMarker {\r\n export function createDefault(): MarshalingBinaryMarker {\r\n return { isBinary: true, index: 0, size: -1, chunks: 1 };\r\n }\r\n}\r\n\r\n/** @internal */\r\nexport interface RpcSerializedValue {\r\n objects: string;\r\n data: Uint8Array[];\r\n chunks?: number;\r\n stream?: BackendReadable;\r\n}\r\n\r\n/** @internal */\r\nexport namespace RpcSerializedValue {\r\n export function create(objects = \"\", data: Uint8Array[] = []): RpcSerializedValue {\r\n return { objects, data };\r\n }\r\n}\r\n\r\n/** @internal */\r\nexport class RpcMarshaling {\r\n private constructor() { }\r\n\r\n /** Serializes a value. */\r\n public static serialize(protocol: RpcProtocol | undefined, value: any): RpcSerializedValue {\r\n const serialized = RpcSerializedValue.create();\r\n\r\n if (typeof (value) === \"undefined\") {\r\n return serialized;\r\n }\r\n\r\n marshalingTarget = serialized;\r\n chunkThreshold = protocol ? protocol.transferChunkThreshold : 0;\r\n serialized.objects = JSON.stringify(value, (_key, _value) => WireFormat.marshal(_key, _value));\r\n marshalingTarget = undefined as any;\r\n chunkThreshold = 0;\r\n\r\n return serialized;\r\n }\r\n\r\n /** Deserializes a value. */\r\n public static deserialize(protocol: RpcProtocol | undefined, value: RpcSerializedValue): any {\r\n if (value.objects === \"\") {\r\n return undefined;\r\n }\r\n\r\n marshalingTarget = value;\r\n chunkThreshold = protocol ? protocol.transferChunkThreshold : 0;\r\n let result;\r\n try {\r\n result = JSON.parse(value.objects, (_key, _value) => WireFormat.unmarshal(_key, _value));\r\n } catch (error) {\r\n if (error instanceof SyntaxError)\r\n throw new IModelError(BentleyStatus.ERROR, `Invalid JSON: \"${value.objects}\"`);\r\n throw error;\r\n }\r\n marshalingTarget = undefined as any;\r\n chunkThreshold = 0;\r\n\r\n return result;\r\n }\r\n}\r\n\r\nclass WireFormat {\r\n /** JSON.stringify replacer callback. */\r\n public static marshal(this: any, _key: string, value: any) {\r\n const asBinary = WireFormat.marshalBinary(value);\r\n if (asBinary) {\r\n return asBinary;\r\n }\r\n\r\n const asError = WireFormat.marshalError(value);\r\n if (asError) {\r\n return asError;\r\n }\r\n\r\n return value;\r\n }\r\n\r\n /** JSON.parse reviver callback. */\r\n public static unmarshal(_key: string, value: any) {\r\n if (typeof (value) === \"object\" && value !== null && value.hasOwnProperty(\"isBinary\") && value.isBinary) {\r\n return WireFormat.unmarshalBinary(value);\r\n }\r\n\r\n return value;\r\n }\r\n\r\n private static marshalBinary(value: any): any {\r\n if (value instanceof Uint8Array || isBuffer(value)) {\r\n const marker: MarshalingBinaryMarker = { isBinary: true, index: -1, size: value.byteLength, chunks: 1 };\r\n\r\n if (chunkThreshold && value.byteLength > chunkThreshold) {\r\n marker.index = marshalingTarget.data.length;\r\n marker.chunks = 0;\r\n\r\n let cursor = value.byteOffset;\r\n const end = cursor + value.byteLength;\r\n let chunk = chunkThreshold;\r\n\r\n for (; ;) {\r\n if (cursor >= end) {\r\n break;\r\n }\r\n\r\n marshalingTarget.data.push(new Uint8Array(value.buffer, cursor, chunk));\r\n ++marker.chunks;\r\n cursor += chunk;\r\n\r\n const consumed = cursor - value.byteOffset;\r\n const remaining = value.byteLength - consumed;\r\n chunk = Math.min(chunkThreshold, remaining);\r\n }\r\n } else {\r\n marker.index = marshalingTarget.data.push(value) - 1;\r\n }\r\n\r\n return marker;\r\n } else {\r\n return undefined;\r\n }\r\n }\r\n\r\n private static unmarshalBinary(value: MarshalingBinaryMarker): any {\r\n if (value.index >= marshalingTarget.data.length) {\r\n throw new IModelError(BentleyStatus.ERROR, `Cannot unmarshal missing binary value.`);\r\n }\r\n\r\n if (value.chunks === 0) {\r\n return new Uint8Array();\r\n } else if (value.chunks === 1) {\r\n return new Uint8Array(marshalingTarget.data[value.index]);\r\n } else {\r\n const buffer = new ArrayBuffer(value.size);\r\n const view = new Uint8Array(buffer);\r\n\r\n let cursor = 0;\r\n for (let c = 0; c !== value.chunks; ++c) {\r\n const chunk = marshalingTarget.data[value.index + c];\r\n view.set(chunk, cursor);\r\n cursor += chunk.byteLength;\r\n }\r\n\r\n return view;\r\n }\r\n }\r\n\r\n private static marshalError(value: any) {\r\n if (value instanceof Error) {\r\n const props = Object.getOwnPropertyDescriptors(value);\r\n props.isError = { configurable: true, enumerable: true, writable: true, value: true };\r\n props.name = { configurable: true, enumerable: true, writable: true, value: value.name };\r\n props.message = { configurable: true, enumerable: true, writable: true, value: value.message };\r\n props.stack = { configurable: true, enumerable: true, writable: true, value: value.stack };\r\n return Object.create(Object.prototype, props);\r\n }\r\n\r\n return undefined;\r\n }\r\n}\r\n"]}
|
|
@@ -17,7 +17,7 @@ const RpcMarshaling_1 = require("./RpcMarshaling");
|
|
|
17
17
|
var RpcRequestFulfillment;
|
|
18
18
|
(function (RpcRequestFulfillment) {
|
|
19
19
|
async function forUnknownError(request, error) {
|
|
20
|
-
const result =
|
|
20
|
+
const result = RpcMarshaling_1.RpcMarshaling.serialize(undefined, error);
|
|
21
21
|
return {
|
|
22
22
|
interfaceName: request.operation.interfaceDefinition,
|
|
23
23
|
id: request.id,
|
|
@@ -75,7 +75,7 @@ class RpcProtocol {
|
|
|
75
75
|
},
|
|
76
76
|
method: request.method,
|
|
77
77
|
path: request.path,
|
|
78
|
-
parameters:
|
|
78
|
+
parameters: RpcMarshaling_1.RpcMarshaling.serialize(request.protocol, request.parameters),
|
|
79
79
|
caching: RpcConstants_1.RpcResponseCacheControl.None,
|
|
80
80
|
protocolVersion: RpcProtocol.protocolVersion,
|
|
81
81
|
};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"RpcProtocol.js","sourceRoot":"","sources":["../../../../src/rpc/core/RpcProtocol.ts"],"names":[],"mappings":";AAAA;;;+FAG+F;AAC/F;;GAEG;;;AAEH,sDAA8C;AAG9C,yDAAsD;AACtD,iDAA6F;AAE7F,mDAAuE;AACvE,mDAAoE;AAwDpE,gBAAgB;AAChB,IAAiB,qBAAqB,CAYrC;AAZD,WAAiB,qBAAqB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,KAAK,CAAC;QAEnC,gEAAgE;QACzD,2BAAsB,GAAY,KAAK,CAAC;QAkD7C,IAAI,CAAC,aAAa,GAAG,aAAa,CAAC;QACnC,IAAI,CAAC,MAAM,CAAC,WAAW,CAAC,CAAC,IAAI,EAAE,MAAM,EAAE,EAAE,CAAC,WAAW,CAAC,MAAM,CAAC,UAAU,CAAC,IAAI,EAAE,MAAM,CAAC,CAAC,CAAC;IACzF,CAAC;IAED,gBAAgB;IACT,sBAAsB,CAAC,WAAmC,EAAE,OAAqB,IAAU,CAAC;IAEnG,gBAAgB;IACT,oBAAoB,CAAC,WAAmC,EAAE,KAAmB,IAAU,CAAC;IAE/F,gBAAgB;IACT,qBAAqB,CAAC,WAAmC,EAAE,OAAqB,IAAU,CAAC;IAElG,gBAAgB;IACT,mBAAmB,CAAC,WAAmC,EAAE,KAAmB,IAAU,CAAC;;AAhH9F,+DAA+D;AACxC,kBAAM,GAAqC,IAAI,sBAAO,EAAE,AAAlD,CAAmD;AAEhF,oFAAoF;AAC7D,2BAAe,GAAW,kBAAkB,CAAC,wBAAwB,AAAtD,CAAuD;AALzE,kCAAW","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 { BeEvent } from \"@itwin/core-bentley\";\r\nimport { IModelRpcProps } from \"../../IModel\";\r\nimport { RpcInterface, RpcInterfaceDefinition } from \"../../RpcInterface\";\r\nimport { RpcConfiguration } from \"./RpcConfiguration\";\r\nimport { RpcProtocolEvent, RpcRequestStatus, RpcResponseCacheControl } from \"./RpcConstants\";\r\nimport { RpcNotFoundResponse } from \"./RpcControl\";\r\nimport { RpcInvocation, SerializedRpcActivity } from \"./RpcInvocation\";\r\nimport { RpcMarshaling, RpcSerializedValue } from \"./RpcMarshaling\";\r\nimport { RpcOperation } from \"./RpcOperation\";\r\nimport { RpcRequest } from \"./RpcRequest\";\r\n\r\n/* eslint-disable deprecation/deprecation */\r\n\r\n/** A serialized RPC operation descriptor.\r\n * @internal\r\n */\r\nexport interface SerializedRpcOperation {\r\n interfaceDefinition: string;\r\n operationName: string;\r\n interfaceVersion: string;\r\n encodedRequest?: string;\r\n}\r\n\r\n/** A serialized RPC operation request.\r\n * @internal\r\n */\r\nexport interface SerializedRpcRequest extends SerializedRpcActivity {\r\n operation: SerializedRpcOperation;\r\n method: string;\r\n path: string;\r\n parameters: RpcSerializedValue;\r\n caching: RpcResponseCacheControl;\r\n ip?: string;\r\n protocolVersion?: number;\r\n parametersOverride?: any[];\r\n}\r\n\r\n/** An RPC operation request fulfillment.\r\n * @internal\r\n */\r\nexport interface RpcRequestFulfillment {\r\n /** The RPC interface for the request. */\r\n interfaceName: string;\r\n\r\n /** The id for the request. */\r\n id: string;\r\n\r\n /** The result for the request. */\r\n result: RpcSerializedValue;\r\n\r\n /** The un-serialized result for the request. */\r\n rawResult: any;\r\n\r\n /** A protocol-specific status code value for the request. */\r\n status: number;\r\n\r\n /* A protocol-specific value for retrying this request. */\r\n retry?: string;\r\n\r\n /** Whether to compress the result with one of the client's supported encodings. */\r\n allowCompression?: boolean;\r\n}\r\n\r\n/** @internal */\r\nexport namespace RpcRequestFulfillment {\r\n export async function forUnknownError(request: SerializedRpcRequest, error: any): Promise<RpcRequestFulfillment> {\r\n const result = await RpcMarshaling.serialize(undefined, error);\r\n\r\n return {\r\n interfaceName: request.operation.interfaceDefinition,\r\n id: request.id,\r\n result,\r\n rawResult: error,\r\n status: RpcRequestStatus.Rejected,\r\n };\r\n }\r\n}\r\n\r\n/** Handles RPC protocol events.\r\n * @internal\r\n */\r\nexport type RpcProtocolEventHandler = (type: RpcProtocolEvent, object: RpcRequest | RpcInvocation, err?: any) => void;\r\n\r\n/** Documents changes to the RPC protocol version.\r\n * @internal\r\n */\r\nexport enum RpcProtocolVersion {\r\n None = 0,\r\n IntroducedNoContent = 1,\r\n IntroducedStatusCategory = 2\r\n}\r\n\r\n/**\r\n * A backend response that is handled internally by the RPC system.\r\n * @internal\r\n */\r\nexport interface RpcManagedStatus {\r\n iTwinRpcCoreResponse: true;\r\n managedStatus: \"pending\" | \"notFound\" | \"noContent\";\r\n responseValue: string | { message: string } | RpcNotFoundResponse;\r\n}\r\n\r\n/** An application protocol for an RPC interface.\r\n * @internal\r\n */\r\nexport abstract class RpcProtocol {\r\n /** Events raised by all protocols. See [[RpcProtocolEvent]] */\r\n public static readonly events: BeEvent<RpcProtocolEventHandler> = new BeEvent();\r\n\r\n /** A version code that identifies the RPC protocol capabilties of this endpoint. */\r\n public static readonly protocolVersion: number = RpcProtocolVersion.IntroducedStatusCategory;\r\n\r\n /** The name of the RPC protocol version header. */\r\n public protocolVersionHeaderName = \"\";\r\n\r\n /** Events raised by the protocol. See [[RpcProtocolEvent]] */\r\n public readonly events: BeEvent<RpcProtocolEventHandler> = new BeEvent();\r\n\r\n /** The configuration for the protocol. */\r\n public readonly configuration: RpcConfiguration;\r\n\r\n /** The RPC request class for this protocol. */\r\n public abstract readonly requestType: typeof RpcRequest;\r\n\r\n /** The RPC invocation class for this protocol. */\r\n public readonly invocationType: typeof RpcInvocation = RpcInvocation;\r\n\r\n public serializedClientRequestContextHeaderNames: SerializedRpcActivity = {\r\n /** The name of the request id header. */\r\n id: \"\",\r\n\r\n /** The name of the application id header */\r\n applicationId: \"\",\r\n\r\n /** The name of the version header. */\r\n applicationVersion: \"\",\r\n\r\n /** The name of the session id header */\r\n sessionId: \"\",\r\n\r\n /** The name of the authorization header. */\r\n authorization: \"\",\r\n };\r\n\r\n /** If greater than zero, specifies where to break large binary request payloads. */\r\n public transferChunkThreshold: number = 0;\r\n\r\n /** Used by protocols that can transmit stream values natively. */\r\n public preserveStreams: boolean = false;\r\n\r\n /** Used by protocols that can transmit IModelRpcProps values natively. */\r\n public checkToken: boolean = false;\r\n\r\n /** Used by protocols that support user-defined status codes. */\r\n public supportsStatusCategory: boolean = false;\r\n\r\n /** If checkToken is true, will be called on the backend to inflate the IModelRpcProps for each request. */\r\n public inflateToken(tokenFromBody: IModelRpcProps, _request: SerializedRpcRequest): IModelRpcProps { return tokenFromBody; }\r\n\r\n /** Override to supply the status corresponding to a protocol-specific code value. */\r\n public getStatus(code: number): RpcRequestStatus {\r\n return code;\r\n }\r\n\r\n /** Override to supply the protocol-specific code corresponding to a status value. */\r\n public getCode(status: RpcRequestStatus): number {\r\n return status;\r\n }\r\n\r\n /** Override to supply the protocol-specific path value for an RPC operation. */\r\n public supplyPathForOperation(operation: RpcOperation, _request: RpcRequest | undefined): string {\r\n return JSON.stringify(operation);\r\n }\r\n\r\n /** Override to supply the operation for a protocol-specific path value. */\r\n public getOperationFromPath(path: string): SerializedRpcOperation {\r\n return JSON.parse(path);\r\n }\r\n\r\n /** Obtains the implementation result on the backend for an RPC operation request. */\r\n public async fulfill(request: SerializedRpcRequest): Promise<RpcRequestFulfillment> {\r\n return new (this.invocationType)(this, request).fulfillment;\r\n }\r\n\r\n /** Serializes a request. */\r\n public async serialize(request: RpcRequest): Promise<SerializedRpcRequest> {\r\n const serializedContext = await RpcConfiguration.requestContext.serialize(request);\r\n return {\r\n ...serializedContext,\r\n operation: {\r\n interfaceDefinition: request.operation.interfaceDefinition.interfaceName,\r\n operationName: request.operation.operationName,\r\n interfaceVersion: request.operation.interfaceVersion,\r\n },\r\n method: request.method,\r\n path: request.path,\r\n parameters: await RpcMarshaling.serialize(request.protocol, request.parameters),\r\n caching: RpcResponseCacheControl.None,\r\n protocolVersion: RpcProtocol.protocolVersion,\r\n };\r\n }\r\n\r\n /** Constructs a protocol. */\r\n public constructor(configuration: RpcConfiguration) {\r\n this.configuration = configuration;\r\n this.events.addListener((type, object) => RpcProtocol.events.raiseEvent(type, object));\r\n }\r\n\r\n /** @internal */\r\n public onRpcClientInitialized(_definition: RpcInterfaceDefinition, _client: RpcInterface): void { }\r\n\r\n /** @internal */\r\n public onRpcImplInitialized(_definition: RpcInterfaceDefinition, _impl: RpcInterface): void { }\r\n\r\n /** @internal */\r\n public onRpcClientTerminated(_definition: RpcInterfaceDefinition, _client: RpcInterface): void { }\r\n\r\n /** @internal */\r\n public onRpcImplTerminated(_definition: RpcInterfaceDefinition, _impl: RpcInterface): void { }\r\n}\r\n"]}
|
|
1
|
+
{"version":3,"file":"RpcProtocol.js","sourceRoot":"","sources":["../../../../src/rpc/core/RpcProtocol.ts"],"names":[],"mappings":";AAAA;;;+FAG+F;AAC/F;;GAEG;;;AAEH,sDAA8C;AAG9C,yDAAsD;AACtD,iDAA6F;AAE7F,mDAAuE;AACvE,mDAAoE;AAwDpE,gBAAgB;AAChB,IAAiB,qBAAqB,CAYrC;AAZD,WAAiB,qBAAqB;IAC7B,KAAK,UAAU,eAAe,CAAC,OAA6B,EAAE,KAAU;QAC7E,MAAM,MAAM,GAAG,6BAAa,CAAC,SAAS,CAAC,SAAS,EAAE,KAAK,CAAC,CAAC;QAEzD,OAAO;YACL,aAAa,EAAE,OAAO,CAAC,SAAS,CAAC,mBAAmB;YACpD,EAAE,EAAE,OAAO,CAAC,EAAE;YACd,MAAM;YACN,SAAS,EAAE,KAAK;YAChB,MAAM,EAAE,+BAAgB,CAAC,QAAQ;SAClC,CAAC;IACJ,CAAC;IAVqB,qCAAe,kBAUpC,CAAA;AACH,CAAC,EAZgB,qBAAqB,GAArB,6BAAqB,KAArB,6BAAqB,QAYrC;AAOD;;GAEG;AACH,IAAY,kBAIX;AAJD,WAAY,kBAAkB;IAC5B,2DAAQ,CAAA;IACR,yFAAuB,CAAA;IACvB,mGAA4B,CAAA;AAC9B,CAAC,EAJW,kBAAkB,GAAlB,0BAAkB,KAAlB,0BAAkB,QAI7B;AAYD;;GAEG;AACH,MAAsB,WAAW;IAmD/B,2GAA2G;IACpG,YAAY,CAAC,aAA6B,EAAE,QAA8B,IAAoB,OAAO,aAAa,CAAC,CAAC,CAAC;IAE5H,qFAAqF;IAC9E,SAAS,CAAC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A8D;QAC9C,WAAM,GAAqC,IAAI,sBAAO,EAAE,CAAC;QAQzE,kDAAkD;QAClC,mBAAc,GAAyB,6BAAa,CAAC;QAE9D,8CAAyC,GAA0B;YACxE,yCAAyC;YACzC,EAAE,EAAE,EAAE;YAEN,6CAA6C;YAC7C,aAAa,EAAE,EAAE;YAEjB,sCAAsC;YACtC,kBAAkB,EAAE,EAAE;YAEtB,yCAAyC;YACzC,SAAS,EAAE,EAAE;YAEb,4CAA4C;YAC5C,aAAa,EAAE,EAAE;SAClB,CAAC;QAEF,oFAAoF;QAC7E,2BAAsB,GAAW,CAAC,CAAC;QAE1C,kEAAkE;QAC3D,oBAAe,GAAY,KAAK,CAAC;QAExC,0EAA0E;QACnE,eAAU,GAAY,KAAK,CAAC;QAEnC,gEAAgE;QACzD,2BAAsB,GAAY,KAAK,CAAC;QAkD7C,IAAI,CAAC,aAAa,GAAG,aAAa,CAAC;QACnC,IAAI,CAAC,MAAM,CAAC,WAAW,CAAC,CAAC,IAAI,EAAE,MAAM,EAAE,EAAE,CAAC,WAAW,CAAC,MAAM,CAAC,UAAU,CAAC,IAAI,EAAE,MAAM,CAAC,CAAC,CAAC;IACzF,CAAC;IAED,gBAAgB;IACT,sBAAsB,CAAC,WAAmC,EAAE,OAAqB,IAAU,CAAC;IAEnG,gBAAgB;IACT,oBAAoB,CAAC,WAAmC,EAAE,KAAmB,IAAU,CAAC;IAE/F,gBAAgB;IACT,qBAAqB,CAAC,WAAmC,EAAE,OAAqB,IAAU,CAAC;IAElG,gBAAgB;IACT,mBAAmB,CAAC,WAAmC,EAAE,KAAmB,IAAU,CAAC;;AAhH9F,+DAA+D;AACxC,kBAAM,GAAqC,IAAI,sBAAO,EAAE,AAAlD,CAAmD;AAEhF,oFAAoF;AAC7D,2BAAe,GAAW,kBAAkB,CAAC,wBAAwB,AAAtD,CAAuD;AALzE,kCAAW","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 { BeEvent } from \"@itwin/core-bentley\";\r\nimport { IModelRpcProps } from \"../../IModel\";\r\nimport { RpcInterface, RpcInterfaceDefinition } from \"../../RpcInterface\";\r\nimport { RpcConfiguration } from \"./RpcConfiguration\";\r\nimport { RpcProtocolEvent, RpcRequestStatus, RpcResponseCacheControl } from \"./RpcConstants\";\r\nimport { RpcNotFoundResponse } from \"./RpcControl\";\r\nimport { RpcInvocation, SerializedRpcActivity } from \"./RpcInvocation\";\r\nimport { RpcMarshaling, RpcSerializedValue } from \"./RpcMarshaling\";\r\nimport { RpcOperation } from \"./RpcOperation\";\r\nimport { RpcRequest } from \"./RpcRequest\";\r\n\r\n/* eslint-disable deprecation/deprecation */\r\n\r\n/** A serialized RPC operation descriptor.\r\n * @internal\r\n */\r\nexport interface SerializedRpcOperation {\r\n interfaceDefinition: string;\r\n operationName: string;\r\n interfaceVersion: string;\r\n encodedRequest?: string;\r\n}\r\n\r\n/** A serialized RPC operation request.\r\n * @internal\r\n */\r\nexport interface SerializedRpcRequest extends SerializedRpcActivity {\r\n operation: SerializedRpcOperation;\r\n method: string;\r\n path: string;\r\n parameters: RpcSerializedValue;\r\n caching: RpcResponseCacheControl;\r\n ip?: string;\r\n protocolVersion?: number;\r\n parametersOverride?: any[];\r\n}\r\n\r\n/** An RPC operation request fulfillment.\r\n * @internal\r\n */\r\nexport interface RpcRequestFulfillment {\r\n /** The RPC interface for the request. */\r\n interfaceName: string;\r\n\r\n /** The id for the request. */\r\n id: string;\r\n\r\n /** The result for the request. */\r\n result: RpcSerializedValue;\r\n\r\n /** The un-serialized result for the request. */\r\n rawResult: any;\r\n\r\n /** A protocol-specific status code value for the request. */\r\n status: number;\r\n\r\n /* A protocol-specific value for retrying this request. */\r\n retry?: string;\r\n\r\n /** Whether to compress the result with one of the client's supported encodings. */\r\n allowCompression?: boolean;\r\n}\r\n\r\n/** @internal */\r\nexport namespace RpcRequestFulfillment {\r\n export async function forUnknownError(request: SerializedRpcRequest, error: any): Promise<RpcRequestFulfillment> {\r\n const result = RpcMarshaling.serialize(undefined, error);\r\n\r\n return {\r\n interfaceName: request.operation.interfaceDefinition,\r\n id: request.id,\r\n result,\r\n rawResult: error,\r\n status: RpcRequestStatus.Rejected,\r\n };\r\n }\r\n}\r\n\r\n/** Handles RPC protocol events.\r\n * @internal\r\n */\r\nexport type RpcProtocolEventHandler = (type: RpcProtocolEvent, object: RpcRequest | RpcInvocation, err?: any) => void;\r\n\r\n/** Documents changes to the RPC protocol version.\r\n * @internal\r\n */\r\nexport enum RpcProtocolVersion {\r\n None = 0,\r\n IntroducedNoContent = 1,\r\n IntroducedStatusCategory = 2\r\n}\r\n\r\n/**\r\n * A backend response that is handled internally by the RPC system.\r\n * @internal\r\n */\r\nexport interface RpcManagedStatus {\r\n iTwinRpcCoreResponse: true;\r\n managedStatus: \"pending\" | \"notFound\" | \"noContent\";\r\n responseValue: string | { message: string } | RpcNotFoundResponse;\r\n}\r\n\r\n/** An application protocol for an RPC interface.\r\n * @internal\r\n */\r\nexport abstract class RpcProtocol {\r\n /** Events raised by all protocols. See [[RpcProtocolEvent]] */\r\n public static readonly events: BeEvent<RpcProtocolEventHandler> = new BeEvent();\r\n\r\n /** A version code that identifies the RPC protocol capabilties of this endpoint. */\r\n public static readonly protocolVersion: number = RpcProtocolVersion.IntroducedStatusCategory;\r\n\r\n /** The name of the RPC protocol version header. */\r\n public protocolVersionHeaderName = \"\";\r\n\r\n /** Events raised by the protocol. See [[RpcProtocolEvent]] */\r\n public readonly events: BeEvent<RpcProtocolEventHandler> = new BeEvent();\r\n\r\n /** The configuration for the protocol. */\r\n public readonly configuration: RpcConfiguration;\r\n\r\n /** The RPC request class for this protocol. */\r\n public abstract readonly requestType: typeof RpcRequest;\r\n\r\n /** The RPC invocation class for this protocol. */\r\n public readonly invocationType: typeof RpcInvocation = RpcInvocation;\r\n\r\n public serializedClientRequestContextHeaderNames: SerializedRpcActivity = {\r\n /** The name of the request id header. */\r\n id: \"\",\r\n\r\n /** The name of the application id header */\r\n applicationId: \"\",\r\n\r\n /** The name of the version header. */\r\n applicationVersion: \"\",\r\n\r\n /** The name of the session id header */\r\n sessionId: \"\",\r\n\r\n /** The name of the authorization header. */\r\n authorization: \"\",\r\n };\r\n\r\n /** If greater than zero, specifies where to break large binary request payloads. */\r\n public transferChunkThreshold: number = 0;\r\n\r\n /** Used by protocols that can transmit stream values natively. */\r\n public preserveStreams: boolean = false;\r\n\r\n /** Used by protocols that can transmit IModelRpcProps values natively. */\r\n public checkToken: boolean = false;\r\n\r\n /** Used by protocols that support user-defined status codes. */\r\n public supportsStatusCategory: boolean = false;\r\n\r\n /** If checkToken is true, will be called on the backend to inflate the IModelRpcProps for each request. */\r\n public inflateToken(tokenFromBody: IModelRpcProps, _request: SerializedRpcRequest): IModelRpcProps { return tokenFromBody; }\r\n\r\n /** Override to supply the status corresponding to a protocol-specific code value. */\r\n public getStatus(code: number): RpcRequestStatus {\r\n return code;\r\n }\r\n\r\n /** Override to supply the protocol-specific code corresponding to a status value. */\r\n public getCode(status: RpcRequestStatus): number {\r\n return status;\r\n }\r\n\r\n /** Override to supply the protocol-specific path value for an RPC operation. */\r\n public supplyPathForOperation(operation: RpcOperation, _request: RpcRequest | undefined): string {\r\n return JSON.stringify(operation);\r\n }\r\n\r\n /** Override to supply the operation for a protocol-specific path value. */\r\n public getOperationFromPath(path: string): SerializedRpcOperation {\r\n return JSON.parse(path);\r\n }\r\n\r\n /** Obtains the implementation result on the backend for an RPC operation request. */\r\n public async fulfill(request: SerializedRpcRequest): Promise<RpcRequestFulfillment> {\r\n return new (this.invocationType)(this, request).fulfillment;\r\n }\r\n\r\n /** Serializes a request. */\r\n public async serialize(request: RpcRequest): Promise<SerializedRpcRequest> {\r\n const serializedContext = await RpcConfiguration.requestContext.serialize(request);\r\n return {\r\n ...serializedContext,\r\n operation: {\r\n interfaceDefinition: request.operation.interfaceDefinition.interfaceName,\r\n operationName: request.operation.operationName,\r\n interfaceVersion: request.operation.interfaceVersion,\r\n },\r\n method: request.method,\r\n path: request.path,\r\n parameters: RpcMarshaling.serialize(request.protocol, request.parameters),\r\n caching: RpcResponseCacheControl.None,\r\n protocolVersion: RpcProtocol.protocolVersion,\r\n };\r\n }\r\n\r\n /** Constructs a protocol. */\r\n public constructor(configuration: RpcConfiguration) {\r\n this.configuration = configuration;\r\n this.events.addListener((type, object) => RpcProtocol.events.raiseEvent(type, object));\r\n }\r\n\r\n /** @internal */\r\n public onRpcClientInitialized(_definition: RpcInterfaceDefinition, _client: RpcInterface): void { }\r\n\r\n /** @internal */\r\n public onRpcImplInitialized(_definition: RpcInterfaceDefinition, _impl: RpcInterface): void { }\r\n\r\n /** @internal */\r\n public onRpcClientTerminated(_definition: RpcInterfaceDefinition, _client: RpcInterface): void { }\r\n\r\n /** @internal */\r\n public onRpcImplTerminated(_definition: RpcInterfaceDefinition, _impl: RpcInterface): void { }\r\n}\r\n"]}
|
|
@@ -153,14 +153,14 @@ class RpcInvocation {
|
|
|
153
153
|
async fulfillResolved(value) {
|
|
154
154
|
this._timeOut = new Date().getTime();
|
|
155
155
|
this.protocol.events.raiseEvent(RpcProtocolEvent.BackendResponseCreated, this);
|
|
156
|
-
const result =
|
|
156
|
+
const result = RpcMarshaling.serialize(this.protocol, value);
|
|
157
157
|
return this.fulfill(result, value);
|
|
158
158
|
}
|
|
159
159
|
async fulfillRejected(reason) {
|
|
160
160
|
this._timeOut = new Date().getTime();
|
|
161
161
|
if (!RpcConfiguration.developmentMode)
|
|
162
162
|
reason.stack = undefined;
|
|
163
|
-
const result =
|
|
163
|
+
const result = RpcMarshaling.serialize(this.protocol, reason);
|
|
164
164
|
if (reason instanceof RpcPendingResponse) {
|
|
165
165
|
this._pending = true;
|
|
166
166
|
this._threw = false;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Rp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,GAAG,CAAC,SAAS,CAAC,CAAC,IAAI,CAAC;SACzD;IACH,CAAC;;;AA5Qa,yBAAW,GAAmB,KAAK,EAAE,SAAS,EAAE,EAAE,EAAE,EAAE,CAAC,EAAE,EAAE,AAAhD,CAAiD;SAD/D,aAAa","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, BentleyError, BentleyStatus, GuidString, IModelStatus, Logger, RpcInterfaceStatus, StatusCategory, Tracing } from \"@itwin/core-bentley\";\r\nimport { CommonLoggerCategory } from \"../../CommonLoggerCategory\";\r\nimport { IModelRpcProps } from \"../../IModel\";\r\nimport { IModelError } from \"../../IModelError\";\r\nimport { RpcInterface } from \"../../RpcInterface\";\r\nimport { SessionProps } from \"../../SessionProps\";\r\nimport { RpcConfiguration } from \"./RpcConfiguration\";\r\nimport { RpcProtocolEvent, RpcRequestStatus } from \"./RpcConstants\";\r\nimport { RpcControlChannel, RpcNotFoundResponse, RpcPendingResponse } from \"./RpcControl\";\r\nimport { RpcMarshaling, RpcSerializedValue } from \"./RpcMarshaling\";\r\nimport { RpcOperation } from \"./RpcOperation\";\r\nimport { RpcManagedStatus, RpcProtocol, RpcProtocolVersion, RpcRequestFulfillment, SerializedRpcRequest } from \"./RpcProtocol\";\r\nimport { CURRENT_INVOCATION, RpcRegistry } from \"./RpcRegistry\";\r\n\r\n/* eslint-disable deprecation/deprecation */\r\n\r\n/** The properties of an RpcActivity.\r\n * @public\r\n * @extensions\r\n */\r\nexport interface RpcActivity extends SessionProps {\r\n /** Used for logging to correlate an Rpc activity between frontend and backend */\r\n readonly activityId: GuidString;\r\n\r\n /** access token for authorization */\r\n readonly accessToken: AccessToken;\r\n\r\n /** the name of the current rpc method */\r\n readonly rpcMethod?: string;\r\n\r\n readonly user?: string;\r\n}\r\n\r\n/** Serialized format for sending the request across the RPC layer\r\n * @public\r\n */\r\nexport interface SerializedRpcActivity {\r\n id: string;\r\n applicationId: string;\r\n applicationVersion: string;\r\n sessionId: string;\r\n authorization: string;\r\n user?: string;\r\n csrfToken?: { headerName: string, headerValue: string };\r\n}\r\n\r\n/** @internal */\r\nexport type RpcActivityRun = (activity: RpcActivity, fn: () => Promise<any>) => Promise<any>;\r\n\r\n/** An RPC operation invocation in response to a request.\r\n * @internal\r\n */\r\nexport class RpcInvocation {\r\n public static runActivity: RpcActivityRun = async (_activity, fn) => fn();\r\n private _threw: boolean = false;\r\n private _pending: boolean = false;\r\n private _notFound: boolean = false;\r\n private _noContent: boolean = false;\r\n private _timeIn: number = 0;\r\n private _timeOut: number = 0;\r\n\r\n /** The protocol for this invocation. */\r\n public readonly protocol: RpcProtocol;\r\n\r\n /** The received request. */\r\n public readonly request: SerializedRpcRequest;\r\n\r\n /** The operation of the request. */\r\n public readonly operation: RpcOperation = undefined as any;\r\n\r\n /** The implementation response. */\r\n public readonly result: Promise<any>;\r\n\r\n /** The fulfillment for this request. */\r\n public readonly fulfillment: Promise<RpcRequestFulfillment>;\r\n\r\n /** The status for this request. */\r\n public get status(): RpcRequestStatus {\r\n return this._threw ? RpcRequestStatus.Rejected :\r\n this._pending ? RpcRequestStatus.Pending :\r\n this._notFound ? RpcRequestStatus.NotFound :\r\n this._noContent ? RpcRequestStatus.NoContent :\r\n RpcRequestStatus.Resolved;\r\n }\r\n\r\n /** The elapsed time for this invocation. */\r\n public get elapsed(): number {\r\n return this._timeOut - this._timeIn;\r\n }\r\n\r\n /**\r\n * The invocation for the current RPC operation.\r\n * @note The return value of this function is only reliable in an RPC impl class member function where program control was received from the RpcInvocation constructor function.\r\n */\r\n public static current(rpcImpl: RpcInterface): RpcInvocation {\r\n return (rpcImpl as any)[CURRENT_INVOCATION];\r\n }\r\n\r\n /** Constructs an invocation. */\r\n public constructor(protocol: RpcProtocol, request: SerializedRpcRequest) {\r\n this._timeIn = new Date().getTime();\r\n this.protocol = protocol;\r\n this.request = request;\r\n\r\n try {\r\n try {\r\n this.operation = RpcOperation.lookup(this.request.operation.interfaceDefinition, this.request.operation.operationName);\r\n\r\n const backend = this.operation.interfaceVersion;\r\n const frontend = this.request.operation.interfaceVersion;\r\n if (!RpcInterface.isVersionCompatible(backend, frontend)) {\r\n throw new IModelError(RpcInterfaceStatus.IncompatibleVersion, `Backend version ${backend} does not match frontend version ${frontend} for RPC interface ${this.operation.operationName}.`);\r\n }\r\n } catch (error) {\r\n if (this.handleUnknownOperation(error)) {\r\n this.operation = RpcOperation.lookup(this.request.operation.interfaceDefinition, this.request.operation.operationName);\r\n } else {\r\n throw error;\r\n }\r\n }\r\n\r\n this.result = this.resolve();\r\n } catch (error) {\r\n this.result = this.reject(error);\r\n }\r\n\r\n this.fulfillment = this.result.then(async (value) => this._threw ? this.fulfillRejected(value) : this.fulfillResolved(value), async (reason) => this.fulfillRejected(reason));\r\n }\r\n\r\n private handleUnknownOperation(error: any): boolean {\r\n RpcControlChannel.ensureInitialized();\r\n return this.protocol.configuration.controlChannel.handleUnknownOperation(this, error);\r\n }\r\n\r\n public static sanitizeForLog(activity?: RpcActivity) {\r\n /* eslint-disable @typescript-eslint/naming-convention */\r\n return activity ? {\r\n ActivityId: activity.activityId, SessionId: activity.sessionId, ApplicationId: activity.applicationId, ApplicationVersion: activity.applicationVersion, rpcMethod: activity.rpcMethod,\r\n } : undefined;\r\n /* eslint-enable @typescript-eslint/naming-convention */\r\n }\r\n\r\n private async resolve(): Promise<any> {\r\n const request = this.request;\r\n const activity: RpcActivity = {\r\n activityId: request.id,\r\n applicationId: request.applicationId,\r\n applicationVersion: request.applicationVersion,\r\n sessionId: request.sessionId,\r\n user: request.user,\r\n accessToken: request.authorization,\r\n rpcMethod: request.operation.operationName,\r\n };\r\n\r\n try {\r\n this.protocol.events.raiseEvent(RpcProtocolEvent.RequestReceived, this);\r\n\r\n const parameters = request.parametersOverride || RpcMarshaling.deserialize(this.protocol, request.parameters);\r\n this.applyPolicies(parameters);\r\n const impl = RpcRegistry.instance.getImplForInterface(this.operation.interfaceDefinition);\r\n (impl as any)[CURRENT_INVOCATION] = this;\r\n const op = this.lookupOperationFunction(impl);\r\n\r\n return await RpcInvocation.runActivity(activity, async () => op.call(impl, ...parameters)\r\n .catch(async (error) => {\r\n // this catch block is intentionally placed inside `runActivity` to attach the right logging metadata and use the correct openTelemetry span.\r\n if (!(error instanceof RpcPendingResponse)) {\r\n Logger.logError(CommonLoggerCategory.RpcInterfaceBackend, \"Error in RPC operation\", { error: BentleyError.getErrorProps(error) });\r\n Tracing.setAttributes({ error: true });\r\n }\r\n throw error;\r\n }));\r\n } catch (error: unknown) {\r\n return this.reject(error);\r\n }\r\n }\r\n\r\n private applyPolicies(parameters: any) {\r\n if (!parameters || !Array.isArray(parameters))\r\n return;\r\n\r\n for (let i = 0; i !== parameters.length; ++i) {\r\n const parameter = parameters[i];\r\n const isToken = typeof (parameter) === \"object\" && parameter !== null && parameter.hasOwnProperty(\"iModelId\") && parameter.hasOwnProperty(\"iTwinId\");\r\n if (isToken && this.protocol.checkToken && !this.operation.policy.allowTokenMismatch) {\r\n const inflated = this.protocol.inflateToken(parameter, this.request);\r\n parameters[i] = inflated;\r\n\r\n if (!RpcInvocation.compareTokens(parameter, inflated)) {\r\n if (RpcConfiguration.throwOnTokenMismatch) {\r\n throw new IModelError(BentleyStatus.ERROR, \"IModelRpcProps mismatch detected for this request.\");\r\n } else {\r\n Logger.logWarning(CommonLoggerCategory.RpcInterfaceBackend, \"IModelRpcProps mismatch detected for this request.\");\r\n }\r\n }\r\n }\r\n }\r\n }\r\n\r\n private static compareTokens(a: IModelRpcProps, b: IModelRpcProps): boolean {\r\n return a.key === b.key &&\r\n a.iTwinId === b.iTwinId &&\r\n a.iModelId === b.iModelId &&\r\n (undefined === a.changeset || (a.changeset.id === b.changeset?.id));\r\n }\r\n\r\n private async reject(error: any): Promise<any> {\r\n this._threw = true;\r\n return error;\r\n }\r\n\r\n private async fulfillResolved(value: any): Promise<RpcRequestFulfillment> {\r\n this._timeOut = new Date().getTime();\r\n this.protocol.events.raiseEvent(RpcProtocolEvent.BackendResponseCreated, this);\r\n const result = await RpcMarshaling.serialize(this.protocol, value);\r\n return this.fulfill(result, value);\r\n }\r\n\r\n private async fulfillRejected(reason: any): Promise<RpcRequestFulfillment> {\r\n this._timeOut = new Date().getTime();\r\n if (!RpcConfiguration.developmentMode)\r\n reason.stack = undefined;\r\n\r\n const result = await RpcMarshaling.serialize(this.protocol, reason);\r\n\r\n if (reason instanceof RpcPendingResponse) {\r\n this._pending = true;\r\n this._threw = false;\r\n result.objects = reason.message;\r\n this.protocol.events.raiseEvent(RpcProtocolEvent.BackendReportedPending, this);\r\n } else if (this.supportsNoContent() && reason?.errorNumber === IModelStatus.NoContent) {\r\n this._noContent = true;\r\n this._threw = false;\r\n this.protocol.events.raiseEvent(RpcProtocolEvent.BackendReportedNoContent, this);\r\n } else if (reason instanceof RpcNotFoundResponse) {\r\n this._notFound = true;\r\n this._threw = false;\r\n this.protocol.events.raiseEvent(RpcProtocolEvent.BackendReportedNotFound, this);\r\n } else {\r\n this._threw = true;\r\n this.protocol.events.raiseEvent(RpcProtocolEvent.BackendErrorOccurred, this);\r\n }\r\n\r\n return this.fulfill(result, reason);\r\n }\r\n\r\n private supportsNoContent() {\r\n if (!this.request.protocolVersion) {\r\n return false;\r\n }\r\n\r\n return RpcProtocol.protocolVersion >= RpcProtocolVersion.IntroducedNoContent && this.request.protocolVersion >= RpcProtocolVersion.IntroducedNoContent;\r\n }\r\n\r\n private supportsStatusCategory() {\r\n if (!this.request.protocolVersion) {\r\n return false;\r\n }\r\n\r\n if (!this.protocol.supportsStatusCategory) {\r\n return false;\r\n }\r\n\r\n return RpcProtocol.protocolVersion >= RpcProtocolVersion.IntroducedStatusCategory && this.request.protocolVersion >= RpcProtocolVersion.IntroducedStatusCategory;\r\n }\r\n\r\n private fulfill(result: RpcSerializedValue, rawResult: any): RpcRequestFulfillment {\r\n const fulfillment: RpcRequestFulfillment = {\r\n result,\r\n rawResult,\r\n status: this.protocol.getCode(this.status),\r\n id: this.request.id,\r\n interfaceName: (typeof (this.operation) === \"undefined\") ? \"\" : this.operation.interfaceDefinition.interfaceName,\r\n allowCompression: this.operation?.policy.allowResponseCompression || false,\r\n };\r\n\r\n this.transformResponseStatus(fulfillment, rawResult);\r\n\r\n try {\r\n const impl = RpcRegistry.instance.getImplForInterface(this.operation.interfaceDefinition) as any;\r\n if (impl[CURRENT_INVOCATION] === this) {\r\n impl[CURRENT_INVOCATION] = undefined;\r\n }\r\n } catch (_err) { }\r\n\r\n return fulfillment;\r\n }\r\n\r\n private lookupOperationFunction(implementation: RpcInterface): (...args: any[]) => Promise<any> {\r\n const func = (implementation as any)[this.operation.operationName];\r\n if (!func || typeof (func) !== \"function\")\r\n throw new IModelError(BentleyStatus.ERROR, `RPC interface class \"${implementation.constructor.name}\" does not implement operation \"${this.operation.operationName}\".`);\r\n\r\n return func;\r\n }\r\n\r\n private transformResponseStatus(fulfillment: RpcRequestFulfillment, rawResult: any) {\r\n if (!this.supportsStatusCategory()) {\r\n return;\r\n }\r\n\r\n let managedStatus: \"notFound\" | \"pending\" | \"noContent\" | undefined;\r\n if (this._pending) {\r\n managedStatus = \"pending\";\r\n } else if (this._notFound) {\r\n managedStatus = \"notFound\";\r\n } else if (this._noContent) {\r\n managedStatus = \"noContent\";\r\n }\r\n\r\n if (managedStatus) {\r\n const responseValue = fulfillment.result.objects;\r\n const status: RpcManagedStatus = { iTwinRpcCoreResponse: true, managedStatus, responseValue };\r\n fulfillment.result.objects = JSON.stringify(status);\r\n status.responseValue = rawResult; // for ipc case\r\n fulfillment.rawResult = status;\r\n }\r\n\r\n if (rawResult instanceof BentleyError) {\r\n fulfillment.status = StatusCategory.for(rawResult).code;\r\n }\r\n }\r\n}\r\n"]}
|
|
1
|
+
{"version":3,"file":"RpcInvocation.js","sourceRoot":"","sources":["../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CAAC;SACzD;IACH,CAAC;;;AA5Qa,yBAAW,GAAmB,KAAK,EAAE,SAAS,EAAE,EAAE,EAAE,EAAE,CAAC,EAAE,EAAE,AAAhD,CAAiD;SAD/D,aAAa","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, BentleyError, BentleyStatus, GuidString, IModelStatus, Logger, RpcInterfaceStatus, StatusCategory, Tracing } from \"@itwin/core-bentley\";\r\nimport { CommonLoggerCategory } from \"../../CommonLoggerCategory\";\r\nimport { IModelRpcProps } from \"../../IModel\";\r\nimport { IModelError } from \"../../IModelError\";\r\nimport { RpcInterface } from \"../../RpcInterface\";\r\nimport { SessionProps } from \"../../SessionProps\";\r\nimport { RpcConfiguration } from \"./RpcConfiguration\";\r\nimport { RpcProtocolEvent, RpcRequestStatus } from \"./RpcConstants\";\r\nimport { RpcControlChannel, RpcNotFoundResponse, RpcPendingResponse } from \"./RpcControl\";\r\nimport { RpcMarshaling, RpcSerializedValue } from \"./RpcMarshaling\";\r\nimport { RpcOperation } from \"./RpcOperation\";\r\nimport { RpcManagedStatus, RpcProtocol, RpcProtocolVersion, RpcRequestFulfillment, SerializedRpcRequest } from \"./RpcProtocol\";\r\nimport { CURRENT_INVOCATION, RpcRegistry } from \"./RpcRegistry\";\r\n\r\n/* eslint-disable deprecation/deprecation */\r\n\r\n/** The properties of an RpcActivity.\r\n * @public\r\n * @extensions\r\n */\r\nexport interface RpcActivity extends SessionProps {\r\n /** Used for logging to correlate an Rpc activity between frontend and backend */\r\n readonly activityId: GuidString;\r\n\r\n /** access token for authorization */\r\n readonly accessToken: AccessToken;\r\n\r\n /** the name of the current rpc method */\r\n readonly rpcMethod?: string;\r\n\r\n readonly user?: string;\r\n}\r\n\r\n/** Serialized format for sending the request across the RPC layer\r\n * @public\r\n */\r\nexport interface SerializedRpcActivity {\r\n id: string;\r\n applicationId: string;\r\n applicationVersion: string;\r\n sessionId: string;\r\n authorization: string;\r\n user?: string;\r\n csrfToken?: { headerName: string, headerValue: string };\r\n}\r\n\r\n/** @internal */\r\nexport type RpcActivityRun = (activity: RpcActivity, fn: () => Promise<any>) => Promise<any>;\r\n\r\n/** An RPC operation invocation in response to a request.\r\n * @internal\r\n */\r\nexport class RpcInvocation {\r\n public static runActivity: RpcActivityRun = async (_activity, fn) => fn();\r\n private _threw: boolean = false;\r\n private _pending: boolean = false;\r\n private _notFound: boolean = false;\r\n private _noContent: boolean = false;\r\n private _timeIn: number = 0;\r\n private _timeOut: number = 0;\r\n\r\n /** The protocol for this invocation. */\r\n public readonly protocol: RpcProtocol;\r\n\r\n /** The received request. */\r\n public readonly request: SerializedRpcRequest;\r\n\r\n /** The operation of the request. */\r\n public readonly operation: RpcOperation = undefined as any;\r\n\r\n /** The implementation response. */\r\n public readonly result: Promise<any>;\r\n\r\n /** The fulfillment for this request. */\r\n public readonly fulfillment: Promise<RpcRequestFulfillment>;\r\n\r\n /** The status for this request. */\r\n public get status(): RpcRequestStatus {\r\n return this._threw ? RpcRequestStatus.Rejected :\r\n this._pending ? RpcRequestStatus.Pending :\r\n this._notFound ? RpcRequestStatus.NotFound :\r\n this._noContent ? RpcRequestStatus.NoContent :\r\n RpcRequestStatus.Resolved;\r\n }\r\n\r\n /** The elapsed time for this invocation. */\r\n public get elapsed(): number {\r\n return this._timeOut - this._timeIn;\r\n }\r\n\r\n /**\r\n * The invocation for the current RPC operation.\r\n * @note The return value of this function is only reliable in an RPC impl class member function where program control was received from the RpcInvocation constructor function.\r\n */\r\n public static current(rpcImpl: RpcInterface): RpcInvocation {\r\n return (rpcImpl as any)[CURRENT_INVOCATION];\r\n }\r\n\r\n /** Constructs an invocation. */\r\n public constructor(protocol: RpcProtocol, request: SerializedRpcRequest) {\r\n this._timeIn = new Date().getTime();\r\n this.protocol = protocol;\r\n this.request = request;\r\n\r\n try {\r\n try {\r\n this.operation = RpcOperation.lookup(this.request.operation.interfaceDefinition, this.request.operation.operationName);\r\n\r\n const backend = this.operation.interfaceVersion;\r\n const frontend = this.request.operation.interfaceVersion;\r\n if (!RpcInterface.isVersionCompatible(backend, frontend)) {\r\n throw new IModelError(RpcInterfaceStatus.IncompatibleVersion, `Backend version ${backend} does not match frontend version ${frontend} for RPC interface ${this.operation.operationName}.`);\r\n }\r\n } catch (error) {\r\n if (this.handleUnknownOperation(error)) {\r\n this.operation = RpcOperation.lookup(this.request.operation.interfaceDefinition, this.request.operation.operationName);\r\n } else {\r\n throw error;\r\n }\r\n }\r\n\r\n this.result = this.resolve();\r\n } catch (error) {\r\n this.result = this.reject(error);\r\n }\r\n\r\n this.fulfillment = this.result.then(async (value) => this._threw ? this.fulfillRejected(value) : this.fulfillResolved(value), async (reason) => this.fulfillRejected(reason));\r\n }\r\n\r\n private handleUnknownOperation(error: any): boolean {\r\n RpcControlChannel.ensureInitialized();\r\n return this.protocol.configuration.controlChannel.handleUnknownOperation(this, error);\r\n }\r\n\r\n public static sanitizeForLog(activity?: RpcActivity) {\r\n /* eslint-disable @typescript-eslint/naming-convention */\r\n return activity ? {\r\n ActivityId: activity.activityId, SessionId: activity.sessionId, ApplicationId: activity.applicationId, ApplicationVersion: activity.applicationVersion, rpcMethod: activity.rpcMethod,\r\n } : undefined;\r\n /* eslint-enable @typescript-eslint/naming-convention */\r\n }\r\n\r\n private async resolve(): Promise<any> {\r\n const request = this.request;\r\n const activity: RpcActivity = {\r\n activityId: request.id,\r\n applicationId: request.applicationId,\r\n applicationVersion: request.applicationVersion,\r\n sessionId: request.sessionId,\r\n user: request.user,\r\n accessToken: request.authorization,\r\n rpcMethod: request.operation.operationName,\r\n };\r\n\r\n try {\r\n this.protocol.events.raiseEvent(RpcProtocolEvent.RequestReceived, this);\r\n\r\n const parameters = request.parametersOverride || RpcMarshaling.deserialize(this.protocol, request.parameters);\r\n this.applyPolicies(parameters);\r\n const impl = RpcRegistry.instance.getImplForInterface(this.operation.interfaceDefinition);\r\n (impl as any)[CURRENT_INVOCATION] = this;\r\n const op = this.lookupOperationFunction(impl);\r\n\r\n return await RpcInvocation.runActivity(activity, async () => op.call(impl, ...parameters)\r\n .catch(async (error) => {\r\n // this catch block is intentionally placed inside `runActivity` to attach the right logging metadata and use the correct openTelemetry span.\r\n if (!(error instanceof RpcPendingResponse)) {\r\n Logger.logError(CommonLoggerCategory.RpcInterfaceBackend, \"Error in RPC operation\", { error: BentleyError.getErrorProps(error) });\r\n Tracing.setAttributes({ error: true });\r\n }\r\n throw error;\r\n }));\r\n } catch (error: unknown) {\r\n return this.reject(error);\r\n }\r\n }\r\n\r\n private applyPolicies(parameters: any) {\r\n if (!parameters || !Array.isArray(parameters))\r\n return;\r\n\r\n for (let i = 0; i !== parameters.length; ++i) {\r\n const parameter = parameters[i];\r\n const isToken = typeof (parameter) === \"object\" && parameter !== null && parameter.hasOwnProperty(\"iModelId\") && parameter.hasOwnProperty(\"iTwinId\");\r\n if (isToken && this.protocol.checkToken && !this.operation.policy.allowTokenMismatch) {\r\n const inflated = this.protocol.inflateToken(parameter, this.request);\r\n parameters[i] = inflated;\r\n\r\n if (!RpcInvocation.compareTokens(parameter, inflated)) {\r\n if (RpcConfiguration.throwOnTokenMismatch) {\r\n throw new IModelError(BentleyStatus.ERROR, \"IModelRpcProps mismatch detected for this request.\");\r\n } else {\r\n Logger.logWarning(CommonLoggerCategory.RpcInterfaceBackend, \"IModelRpcProps mismatch detected for this request.\");\r\n }\r\n }\r\n }\r\n }\r\n }\r\n\r\n private static compareTokens(a: IModelRpcProps, b: IModelRpcProps): boolean {\r\n return a.key === b.key &&\r\n a.iTwinId === b.iTwinId &&\r\n a.iModelId === b.iModelId &&\r\n (undefined === a.changeset || (a.changeset.id === b.changeset?.id));\r\n }\r\n\r\n private async reject(error: any): Promise<any> {\r\n this._threw = true;\r\n return error;\r\n }\r\n\r\n private async fulfillResolved(value: any): Promise<RpcRequestFulfillment> {\r\n this._timeOut = new Date().getTime();\r\n this.protocol.events.raiseEvent(RpcProtocolEvent.BackendResponseCreated, this);\r\n const result = RpcMarshaling.serialize(this.protocol, value);\r\n return this.fulfill(result, value);\r\n }\r\n\r\n private async fulfillRejected(reason: any): Promise<RpcRequestFulfillment> {\r\n this._timeOut = new Date().getTime();\r\n if (!RpcConfiguration.developmentMode)\r\n reason.stack = undefined;\r\n\r\n const result = RpcMarshaling.serialize(this.protocol, reason);\r\n\r\n if (reason instanceof RpcPendingResponse) {\r\n this._pending = true;\r\n this._threw = false;\r\n result.objects = reason.message;\r\n this.protocol.events.raiseEvent(RpcProtocolEvent.BackendReportedPending, this);\r\n } else if (this.supportsNoContent() && reason?.errorNumber === IModelStatus.NoContent) {\r\n this._noContent = true;\r\n this._threw = false;\r\n this.protocol.events.raiseEvent(RpcProtocolEvent.BackendReportedNoContent, this);\r\n } else if (reason instanceof RpcNotFoundResponse) {\r\n this._notFound = true;\r\n this._threw = false;\r\n this.protocol.events.raiseEvent(RpcProtocolEvent.BackendReportedNotFound, this);\r\n } else {\r\n this._threw = true;\r\n this.protocol.events.raiseEvent(RpcProtocolEvent.BackendErrorOccurred, this);\r\n }\r\n\r\n return this.fulfill(result, reason);\r\n }\r\n\r\n private supportsNoContent() {\r\n if (!this.request.protocolVersion) {\r\n return false;\r\n }\r\n\r\n return RpcProtocol.protocolVersion >= RpcProtocolVersion.IntroducedNoContent && this.request.protocolVersion >= RpcProtocolVersion.IntroducedNoContent;\r\n }\r\n\r\n private supportsStatusCategory() {\r\n if (!this.request.protocolVersion) {\r\n return false;\r\n }\r\n\r\n if (!this.protocol.supportsStatusCategory) {\r\n return false;\r\n }\r\n\r\n return RpcProtocol.protocolVersion >= RpcProtocolVersion.IntroducedStatusCategory && this.request.protocolVersion >= RpcProtocolVersion.IntroducedStatusCategory;\r\n }\r\n\r\n private fulfill(result: RpcSerializedValue, rawResult: any): RpcRequestFulfillment {\r\n const fulfillment: RpcRequestFulfillment = {\r\n result,\r\n rawResult,\r\n status: this.protocol.getCode(this.status),\r\n id: this.request.id,\r\n interfaceName: (typeof (this.operation) === \"undefined\") ? \"\" : this.operation.interfaceDefinition.interfaceName,\r\n allowCompression: this.operation?.policy.allowResponseCompression || false,\r\n };\r\n\r\n this.transformResponseStatus(fulfillment, rawResult);\r\n\r\n try {\r\n const impl = RpcRegistry.instance.getImplForInterface(this.operation.interfaceDefinition) as any;\r\n if (impl[CURRENT_INVOCATION] === this) {\r\n impl[CURRENT_INVOCATION] = undefined;\r\n }\r\n } catch (_err) { }\r\n\r\n return fulfillment;\r\n }\r\n\r\n private lookupOperationFunction(implementation: RpcInterface): (...args: any[]) => Promise<any> {\r\n const func = (implementation as any)[this.operation.operationName];\r\n if (!func || typeof (func) !== \"function\")\r\n throw new IModelError(BentleyStatus.ERROR, `RPC interface class \"${implementation.constructor.name}\" does not implement operation \"${this.operation.operationName}\".`);\r\n\r\n return func;\r\n }\r\n\r\n private transformResponseStatus(fulfillment: RpcRequestFulfillment, rawResult: any) {\r\n if (!this.supportsStatusCategory()) {\r\n return;\r\n }\r\n\r\n let managedStatus: \"notFound\" | \"pending\" | \"noContent\" | undefined;\r\n if (this._pending) {\r\n managedStatus = \"pending\";\r\n } else if (this._notFound) {\r\n managedStatus = \"notFound\";\r\n } else if (this._noContent) {\r\n managedStatus = \"noContent\";\r\n }\r\n\r\n if (managedStatus) {\r\n const responseValue = fulfillment.result.objects;\r\n const status: RpcManagedStatus = { iTwinRpcCoreResponse: true, managedStatus, responseValue };\r\n fulfillment.result.objects = JSON.stringify(status);\r\n status.responseValue = rawResult; // for ipc case\r\n fulfillment.rawResult = status;\r\n }\r\n\r\n if (rawResult instanceof BentleyError) {\r\n fulfillment.status = StatusCategory.for(rawResult).code;\r\n }\r\n }\r\n}\r\n"]}
|
|
@@ -29,7 +29,7 @@ export declare namespace RpcSerializedValue {
|
|
|
29
29
|
export declare class RpcMarshaling {
|
|
30
30
|
private constructor();
|
|
31
31
|
/** Serializes a value. */
|
|
32
|
-
static serialize(protocol: RpcProtocol | undefined, value: any):
|
|
32
|
+
static serialize(protocol: RpcProtocol | undefined, value: any): RpcSerializedValue;
|
|
33
33
|
/** Deserializes a value. */
|
|
34
34
|
static deserialize(protocol: RpcProtocol | undefined, value: RpcSerializedValue): any;
|
|
35
35
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"RpcMarshaling.d.ts","sourceRoot":"","sources":["../../../../src/rpc/core/RpcMarshaling.ts"],"names":[],"mappings":"AAIA;;GAEG;AAGH,OAAO,EAAE,eAAe,EAAE,MAAM,oBAAoB,CAAC;AACrD,OAAO,EAAE,WAAW,EAAE,MAAM,eAAe,CAAC;AAY5C,gBAAgB;AAChB,MAAM,WAAW,sBAAsB;IACrC,QAAQ,EAAE,IAAI,CAAC;IACf,KAAK,EAAE,MAAM,CAAC;IACd,IAAI,EAAE,MAAM,CAAC;IACb,MAAM,EAAE,MAAM,CAAC;CAChB;AAED,gBAAgB;AAChB,yBAAiB,sBAAsB,CAAC;IACtC,SAAgB,aAAa,IAAI,sBAAsB,CAEtD;CACF;AAED,gBAAgB;AAChB,MAAM,WAAW,kBAAkB;IACjC,OAAO,EAAE,MAAM,CAAC;IAChB,IAAI,EAAE,UAAU,EAAE,CAAC;IACnB,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB,MAAM,CAAC,EAAE,eAAe,CAAC;CAC1B;AAED,gBAAgB;AAChB,yBAAiB,kBAAkB,CAAC;IAClC,SAAgB,MAAM,CAAC,OAAO,SAAK,EAAE,IAAI,GAAE,UAAU,EAAO,GAAG,kBAAkB,CAEhF;CACF;AAED,gBAAgB;AAChB,qBAAa,aAAa;IACxB,OAAO;IAEP,0BAA0B;
|
|
1
|
+
{"version":3,"file":"RpcMarshaling.d.ts","sourceRoot":"","sources":["../../../../src/rpc/core/RpcMarshaling.ts"],"names":[],"mappings":"AAIA;;GAEG;AAGH,OAAO,EAAE,eAAe,EAAE,MAAM,oBAAoB,CAAC;AACrD,OAAO,EAAE,WAAW,EAAE,MAAM,eAAe,CAAC;AAY5C,gBAAgB;AAChB,MAAM,WAAW,sBAAsB;IACrC,QAAQ,EAAE,IAAI,CAAC;IACf,KAAK,EAAE,MAAM,CAAC;IACd,IAAI,EAAE,MAAM,CAAC;IACb,MAAM,EAAE,MAAM,CAAC;CAChB;AAED,gBAAgB;AAChB,yBAAiB,sBAAsB,CAAC;IACtC,SAAgB,aAAa,IAAI,sBAAsB,CAEtD;CACF;AAED,gBAAgB;AAChB,MAAM,WAAW,kBAAkB;IACjC,OAAO,EAAE,MAAM,CAAC;IAChB,IAAI,EAAE,UAAU,EAAE,CAAC;IACnB,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB,MAAM,CAAC,EAAE,eAAe,CAAC;CAC1B;AAED,gBAAgB;AAChB,yBAAiB,kBAAkB,CAAC;IAClC,SAAgB,MAAM,CAAC,OAAO,SAAK,EAAE,IAAI,GAAE,UAAU,EAAO,GAAG,kBAAkB,CAEhF;CACF;AAED,gBAAgB;AAChB,qBAAa,aAAa;IACxB,OAAO;IAEP,0BAA0B;WACZ,SAAS,CAAC,QAAQ,EAAE,WAAW,GAAG,SAAS,EAAE,KAAK,EAAE,GAAG,GAAG,kBAAkB;IAgB1F,4BAA4B;WACd,WAAW,CAAC,QAAQ,EAAE,WAAW,GAAG,SAAS,EAAE,KAAK,EAAE,kBAAkB,GAAG,GAAG;CAoB7F"}
|
|
@@ -33,7 +33,7 @@ export var RpcSerializedValue;
|
|
|
33
33
|
export class RpcMarshaling {
|
|
34
34
|
constructor() { }
|
|
35
35
|
/** Serializes a value. */
|
|
36
|
-
static
|
|
36
|
+
static serialize(protocol, value) {
|
|
37
37
|
const serialized = RpcSerializedValue.create();
|
|
38
38
|
if (typeof (value) === "undefined") {
|
|
39
39
|
return serialized;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"RpcMarshaling.js","sourceRoot":"","sources":["../../../../src/r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QAED,OAAO,SAAS,CAAC;IACnB,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 RpcInterface\r\n */\r\n\r\nimport { BentleyStatus, IModelError } from \"../../IModelError\";\r\nimport { BackendReadable } from \"../../BackendTypes\";\r\nimport { RpcProtocol } from \"./RpcProtocol\";\r\n\r\n// cspell:ignore unmarshal\r\n/* eslint-disable deprecation/deprecation */\r\n\r\nfunction isBuffer(val: any): boolean {\r\n return val && typeof (val.constructor) !== \"undefined\" && typeof (val.constructor.isBuffer) === \"function\" && val.constructor.isBuffer(val);\r\n}\r\n\r\nlet marshalingTarget: RpcSerializedValue;\r\nlet chunkThreshold = 0;\r\n\r\n/** @internal */\r\nexport interface MarshalingBinaryMarker {\r\n isBinary: true;\r\n index: number;\r\n size: number;\r\n chunks: number;\r\n}\r\n\r\n/** @internal */\r\nexport namespace MarshalingBinaryMarker {\r\n export function createDefault(): MarshalingBinaryMarker {\r\n return { isBinary: true, index: 0, size: -1, chunks: 1 };\r\n }\r\n}\r\n\r\n/** @internal */\r\nexport interface RpcSerializedValue {\r\n objects: string;\r\n data: Uint8Array[];\r\n chunks?: number;\r\n stream?: BackendReadable;\r\n}\r\n\r\n/** @internal */\r\nexport namespace RpcSerializedValue {\r\n export function create(objects = \"\", data: Uint8Array[] = []): RpcSerializedValue {\r\n return { objects, data };\r\n }\r\n}\r\n\r\n/** @internal */\r\nexport class RpcMarshaling {\r\n private constructor() { }\r\n\r\n /** Serializes a value. */\r\n public static async serialize(protocol: RpcProtocol | undefined, value: any): Promise<RpcSerializedValue> {\r\n const serialized = RpcSerializedValue.create();\r\n\r\n if (typeof (value) === \"undefined\") {\r\n return serialized;\r\n }\r\n\r\n marshalingTarget = serialized;\r\n chunkThreshold = protocol ? protocol.transferChunkThreshold : 0;\r\n serialized.objects = JSON.stringify(value, (_key, _value) => WireFormat.marshal(_key, _value));\r\n marshalingTarget = undefined as any;\r\n chunkThreshold = 0;\r\n\r\n return serialized;\r\n }\r\n\r\n /** Deserializes a value. */\r\n public static deserialize(protocol: RpcProtocol | undefined, value: RpcSerializedValue): any {\r\n if (value.objects === \"\") {\r\n return undefined;\r\n }\r\n\r\n marshalingTarget = value;\r\n chunkThreshold = protocol ? protocol.transferChunkThreshold : 0;\r\n let result;\r\n try {\r\n result = JSON.parse(value.objects, (_key, _value) => WireFormat.unmarshal(_key, _value));\r\n } catch (error) {\r\n if (error instanceof SyntaxError)\r\n throw new IModelError(BentleyStatus.ERROR, `Invalid JSON: \"${value.objects}\"`);\r\n throw error;\r\n }\r\n marshalingTarget = undefined as any;\r\n chunkThreshold = 0;\r\n\r\n return result;\r\n }\r\n}\r\n\r\nclass WireFormat {\r\n /** JSON.stringify replacer callback. */\r\n public static marshal(this: any, _key: string, value: any) {\r\n const asBinary = WireFormat.marshalBinary(value);\r\n if (asBinary) {\r\n return asBinary;\r\n }\r\n\r\n const asError = WireFormat.marshalError(value);\r\n if (asError) {\r\n return asError;\r\n }\r\n\r\n return value;\r\n }\r\n\r\n /** JSON.parse reviver callback. */\r\n public static unmarshal(_key: string, value: any) {\r\n if (typeof (value) === \"object\" && value !== null && value.hasOwnProperty(\"isBinary\") && value.isBinary) {\r\n return WireFormat.unmarshalBinary(value);\r\n }\r\n\r\n return value;\r\n }\r\n\r\n private static marshalBinary(value: any): any {\r\n if (value instanceof Uint8Array || isBuffer(value)) {\r\n const marker: MarshalingBinaryMarker = { isBinary: true, index: -1, size: value.byteLength, chunks: 1 };\r\n\r\n if (chunkThreshold && value.byteLength > chunkThreshold) {\r\n marker.index = marshalingTarget.data.length;\r\n marker.chunks = 0;\r\n\r\n let cursor = value.byteOffset;\r\n const end = cursor + value.byteLength;\r\n let chunk = chunkThreshold;\r\n\r\n for (; ;) {\r\n if (cursor >= end) {\r\n break;\r\n }\r\n\r\n marshalingTarget.data.push(new Uint8Array(value.buffer, cursor, chunk));\r\n ++marker.chunks;\r\n cursor += chunk;\r\n\r\n const consumed = cursor - value.byteOffset;\r\n const remaining = value.byteLength - consumed;\r\n chunk = Math.min(chunkThreshold, remaining);\r\n }\r\n } else {\r\n marker.index = marshalingTarget.data.push(value) - 1;\r\n }\r\n\r\n return marker;\r\n } else {\r\n return undefined;\r\n }\r\n }\r\n\r\n private static unmarshalBinary(value: MarshalingBinaryMarker): any {\r\n if (value.index >= marshalingTarget.data.length) {\r\n throw new IModelError(BentleyStatus.ERROR, `Cannot unmarshal missing binary value.`);\r\n }\r\n\r\n if (value.chunks === 0) {\r\n return new Uint8Array();\r\n } else if (value.chunks === 1) {\r\n return new Uint8Array(marshalingTarget.data[value.index]);\r\n } else {\r\n const buffer = new ArrayBuffer(value.size);\r\n const view = new Uint8Array(buffer);\r\n\r\n let cursor = 0;\r\n for (let c = 0; c !== value.chunks; ++c) {\r\n const chunk = marshalingTarget.data[value.index + c];\r\n view.set(chunk, cursor);\r\n cursor += chunk.byteLength;\r\n }\r\n\r\n return view;\r\n }\r\n }\r\n\r\n private static marshalError(value: any) {\r\n if (value instanceof Error) {\r\n const props = Object.getOwnPropertyDescriptors(value);\r\n props.isError = { configurable: true, enumerable: true, writable: true, value: true };\r\n props.name = { configurable: true, enumerable: true, writable: true, value: value.name };\r\n props.message = { configurable: true, enumerable: true, writable: true, value: value.message };\r\n props.stack = { configurable: true, enumerable: true, writable: true, value: value.stack };\r\n return Object.create(Object.prototype, props);\r\n }\r\n\r\n return undefined;\r\n }\r\n}\r\n"]}
|
|
1
|
+
{"version":3,"file":"RpcMarshaling.js","sourceRoot":"","sources":["../../../../src/rpc/core/RpcMarshaling.ts"],"names":[],"mappings":"AAAA;;;+FAG+F;AAC/F;;GAEG;AAEH,OAAO,EAAE,aAAa,EAAE,WAAW,EAAE,MAAM,mBAAmB,CAAC;AAI/D,0BAA0B;AAC1B,4CAA4C;AAE5C,SAAS,QAA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gBAAgB,CAAC,IAAI,CAAC,KAAK,CAAC,KAAK,GAAG,CAAC,CAAC,CAAC;gBACrD,IAAI,CAAC,GAAG,CAAC,KAAK,EAAE,MAAM,CAAC,CAAC;gBACxB,MAAM,IAAI,KAAK,CAAC,UAAU,CAAC;aAC5B;YAED,OAAO,IAAI,CAAC;SACb;IACH,CAAC;IAEO,MAAM,CAAC,YAAY,CAAC,KAAU;QACpC,IAAI,KAAK,YAAY,KAAK,EAAE;YAC1B,MAAM,KAAK,GAAG,MAAM,CAAC,yBAAyB,CAAC,KAAK,CAAC,CAAC;YACtD,KAAK,CAAC,OAAO,GAAG,EAAE,YAAY,EAAE,IAAI,EAAE,UAAU,EAAE,IAAI,EAAE,QAAQ,EAAE,IAAI,EAAE,KAAK,EAAE,IAAI,EAAE,CAAC;YACtF,KAAK,CAAC,IAAI,GAAG,EAAE,YAAY,EAAE,IAAI,EAAE,UAAU,EAAE,IAAI,EAAE,QAAQ,EAAE,IAAI,EAAE,KAAK,EAAE,KAAK,CAAC,IAAI,EAAE,CAAC;YACzF,KAAK,CAAC,OAAO,GAAG,EAAE,YAAY,EAAE,IAAI,EAAE,UAAU,EAAE,IAAI,EAAE,QAAQ,EAAE,IAAI,EAAE,KAAK,EAAE,KAAK,CAAC,OAAO,EAAE,CAAC;YAC/F,KAAK,CAAC,KAAK,GAAG,EAAE,YAAY,EAAE,IAAI,EAAE,UAAU,EAAE,IAAI,EAAE,QAAQ,EAAE,IAAI,EAAE,KAAK,EAAE,KAAK,CAAC,KAAK,EAAE,CAAC;YAC3F,OAAO,MAAM,CAAC,MAAM,CAAC,MAAM,CAAC,SAAS,EAAE,KAAK,CAAC,CAAC;SAC/C;QAED,OAAO,SAAS,CAAC;IACnB,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 RpcInterface\r\n */\r\n\r\nimport { BentleyStatus, IModelError } from \"../../IModelError\";\r\nimport { BackendReadable } from \"../../BackendTypes\";\r\nimport { RpcProtocol } from \"./RpcProtocol\";\r\n\r\n// cspell:ignore unmarshal\r\n/* eslint-disable deprecation/deprecation */\r\n\r\nfunction isBuffer(val: any): boolean {\r\n return val && typeof (val.constructor) !== \"undefined\" && typeof (val.constructor.isBuffer) === \"function\" && val.constructor.isBuffer(val);\r\n}\r\n\r\nlet marshalingTarget: RpcSerializedValue;\r\nlet chunkThreshold = 0;\r\n\r\n/** @internal */\r\nexport interface MarshalingBinaryMarker {\r\n isBinary: true;\r\n index: number;\r\n size: number;\r\n chunks: number;\r\n}\r\n\r\n/** @internal */\r\nexport namespace MarshalingBinaryMarker {\r\n export function createDefault(): MarshalingBinaryMarker {\r\n return { isBinary: true, index: 0, size: -1, chunks: 1 };\r\n }\r\n}\r\n\r\n/** @internal */\r\nexport interface RpcSerializedValue {\r\n objects: string;\r\n data: Uint8Array[];\r\n chunks?: number;\r\n stream?: BackendReadable;\r\n}\r\n\r\n/** @internal */\r\nexport namespace RpcSerializedValue {\r\n export function create(objects = \"\", data: Uint8Array[] = []): RpcSerializedValue {\r\n return { objects, data };\r\n }\r\n}\r\n\r\n/** @internal */\r\nexport class RpcMarshaling {\r\n private constructor() { }\r\n\r\n /** Serializes a value. */\r\n public static serialize(protocol: RpcProtocol | undefined, value: any): RpcSerializedValue {\r\n const serialized = RpcSerializedValue.create();\r\n\r\n if (typeof (value) === \"undefined\") {\r\n return serialized;\r\n }\r\n\r\n marshalingTarget = serialized;\r\n chunkThreshold = protocol ? protocol.transferChunkThreshold : 0;\r\n serialized.objects = JSON.stringify(value, (_key, _value) => WireFormat.marshal(_key, _value));\r\n marshalingTarget = undefined as any;\r\n chunkThreshold = 0;\r\n\r\n return serialized;\r\n }\r\n\r\n /** Deserializes a value. */\r\n public static deserialize(protocol: RpcProtocol | undefined, value: RpcSerializedValue): any {\r\n if (value.objects === \"\") {\r\n return undefined;\r\n }\r\n\r\n marshalingTarget = value;\r\n chunkThreshold = protocol ? protocol.transferChunkThreshold : 0;\r\n let result;\r\n try {\r\n result = JSON.parse(value.objects, (_key, _value) => WireFormat.unmarshal(_key, _value));\r\n } catch (error) {\r\n if (error instanceof SyntaxError)\r\n throw new IModelError(BentleyStatus.ERROR, `Invalid JSON: \"${value.objects}\"`);\r\n throw error;\r\n }\r\n marshalingTarget = undefined as any;\r\n chunkThreshold = 0;\r\n\r\n return result;\r\n }\r\n}\r\n\r\nclass WireFormat {\r\n /** JSON.stringify replacer callback. */\r\n public static marshal(this: any, _key: string, value: any) {\r\n const asBinary = WireFormat.marshalBinary(value);\r\n if (asBinary) {\r\n return asBinary;\r\n }\r\n\r\n const asError = WireFormat.marshalError(value);\r\n if (asError) {\r\n return asError;\r\n }\r\n\r\n return value;\r\n }\r\n\r\n /** JSON.parse reviver callback. */\r\n public static unmarshal(_key: string, value: any) {\r\n if (typeof (value) === \"object\" && value !== null && value.hasOwnProperty(\"isBinary\") && value.isBinary) {\r\n return WireFormat.unmarshalBinary(value);\r\n }\r\n\r\n return value;\r\n }\r\n\r\n private static marshalBinary(value: any): any {\r\n if (value instanceof Uint8Array || isBuffer(value)) {\r\n const marker: MarshalingBinaryMarker = { isBinary: true, index: -1, size: value.byteLength, chunks: 1 };\r\n\r\n if (chunkThreshold && value.byteLength > chunkThreshold) {\r\n marker.index = marshalingTarget.data.length;\r\n marker.chunks = 0;\r\n\r\n let cursor = value.byteOffset;\r\n const end = cursor + value.byteLength;\r\n let chunk = chunkThreshold;\r\n\r\n for (; ;) {\r\n if (cursor >= end) {\r\n break;\r\n }\r\n\r\n marshalingTarget.data.push(new Uint8Array(value.buffer, cursor, chunk));\r\n ++marker.chunks;\r\n cursor += chunk;\r\n\r\n const consumed = cursor - value.byteOffset;\r\n const remaining = value.byteLength - consumed;\r\n chunk = Math.min(chunkThreshold, remaining);\r\n }\r\n } else {\r\n marker.index = marshalingTarget.data.push(value) - 1;\r\n }\r\n\r\n return marker;\r\n } else {\r\n return undefined;\r\n }\r\n }\r\n\r\n private static unmarshalBinary(value: MarshalingBinaryMarker): any {\r\n if (value.index >= marshalingTarget.data.length) {\r\n throw new IModelError(BentleyStatus.ERROR, `Cannot unmarshal missing binary value.`);\r\n }\r\n\r\n if (value.chunks === 0) {\r\n return new Uint8Array();\r\n } else if (value.chunks === 1) {\r\n return new Uint8Array(marshalingTarget.data[value.index]);\r\n } else {\r\n const buffer = new ArrayBuffer(value.size);\r\n const view = new Uint8Array(buffer);\r\n\r\n let cursor = 0;\r\n for (let c = 0; c !== value.chunks; ++c) {\r\n const chunk = marshalingTarget.data[value.index + c];\r\n view.set(chunk, cursor);\r\n cursor += chunk.byteLength;\r\n }\r\n\r\n return view;\r\n }\r\n }\r\n\r\n private static marshalError(value: any) {\r\n if (value instanceof Error) {\r\n const props = Object.getOwnPropertyDescriptors(value);\r\n props.isError = { configurable: true, enumerable: true, writable: true, value: true };\r\n props.name = { configurable: true, enumerable: true, writable: true, value: value.name };\r\n props.message = { configurable: true, enumerable: true, writable: true, value: value.message };\r\n props.stack = { configurable: true, enumerable: true, writable: true, value: value.stack };\r\n return Object.create(Object.prototype, props);\r\n }\r\n\r\n return undefined;\r\n }\r\n}\r\n"]}
|
|
@@ -14,7 +14,7 @@ import { RpcMarshaling } from "./RpcMarshaling";
|
|
|
14
14
|
export var RpcRequestFulfillment;
|
|
15
15
|
(function (RpcRequestFulfillment) {
|
|
16
16
|
async function forUnknownError(request, error) {
|
|
17
|
-
const result =
|
|
17
|
+
const result = RpcMarshaling.serialize(undefined, error);
|
|
18
18
|
return {
|
|
19
19
|
interfaceName: request.operation.interfaceDefinition,
|
|
20
20
|
id: request.id,
|
|
@@ -72,7 +72,7 @@ class RpcProtocol {
|
|
|
72
72
|
},
|
|
73
73
|
method: request.method,
|
|
74
74
|
path: request.path,
|
|
75
|
-
parameters:
|
|
75
|
+
parameters: RpcMarshaling.serialize(request.protocol, request.parameters),
|
|
76
76
|
caching: RpcResponseCacheControl.None,
|
|
77
77
|
protocolVersion: RpcProtocol.protocolVersion,
|
|
78
78
|
};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"RpcProtocol.js","sourceRoot":"","sources":["../../../../src/rpc/core/RpcProtocol.ts"],"names":[],"mappings":"AAAA;;;+FAG+F;AAC/F;;GAEG;AAEH,OAAO,EAAE,OAAO,EAAE,MAAM,qBAAqB,CAAC;AAG9C,OAAO,EAAE,gBAAgB,EAAE,MAAM,oBAAoB,CAAC;AACtD,OAAO,EAAoB,gBAAgB,EAAE,uBAAuB,EAAE,MAAM,gBAAgB,CAAC;AAE7F,OAAO,EAAE,aAAa,EAAyB,MAAM,iBAAiB,CAAC;AACvE,OAAO,EAAE,aAAa,EAAsB,MAAM,iBAAiB,CAAC;AAwDpE,gBAAgB;AAChB,MAAM,KAAW,qBAAqB,CAYrC;AAZD,WAAiB,qBAAqB;IAC7B,KAAK,UAAU,eAAe,CAAC,OAA6B,EAAE,KAAU;QAC7E,MAAM,MAAM,GAAG,MAAM,aAAa,CAAC,SAAS,CAAC,SAAS,EAAE,KAAK,CAAC,CAAC;QAE/D,OAAO;YACL,aAAa,EAAE,OAAO,CAAC,SAAS,CAAC,mBAAmB;YACpD,EAAE,EAAE,OAAO,CAAC,EAAE;YACd,MAAM;YACN,SAAS,EAAE,KAAK;YAChB,MAAM,EAAE,gBAAgB,CAAC,QAAQ;SAClC,CAAC;IACJ,CAAC;IAVqB,qCAAe,kBAUpC,CAAA;AACH,CAAC,EAZgB,qBAAqB,KAArB,qBAAqB,QAYrC;AAOD;;GAEG;AACH,MAAM,CAAN,IAAY,kBAIX;AAJD,WAAY,kBAAkB;IAC5B,2DAAQ,CAAA;IACR,yFAAuB,CAAA;IACvB,mGAA4B,CAAA;AAC9B,CAAC,EAJW,kBAAkB,KAAlB,kBAAkB,QAI7B;AAYD;;GAEG;AACH,MAAsB,WAAW;IAmD/B,2GAA2G;IACpG,YAAY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B,AAAtD,CAAuD;SALzE,WAAW","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 { BeEvent } from \"@itwin/core-bentley\";\r\nimport { IModelRpcProps } from \"../../IModel\";\r\nimport { RpcInterface, RpcInterfaceDefinition } from \"../../RpcInterface\";\r\nimport { RpcConfiguration } from \"./RpcConfiguration\";\r\nimport { RpcProtocolEvent, RpcRequestStatus, RpcResponseCacheControl } from \"./RpcConstants\";\r\nimport { RpcNotFoundResponse } from \"./RpcControl\";\r\nimport { RpcInvocation, SerializedRpcActivity } from \"./RpcInvocation\";\r\nimport { RpcMarshaling, RpcSerializedValue } from \"./RpcMarshaling\";\r\nimport { RpcOperation } from \"./RpcOperation\";\r\nimport { RpcRequest } from \"./RpcRequest\";\r\n\r\n/* eslint-disable deprecation/deprecation */\r\n\r\n/** A serialized RPC operation descriptor.\r\n * @internal\r\n */\r\nexport interface SerializedRpcOperation {\r\n interfaceDefinition: string;\r\n operationName: string;\r\n interfaceVersion: string;\r\n encodedRequest?: string;\r\n}\r\n\r\n/** A serialized RPC operation request.\r\n * @internal\r\n */\r\nexport interface SerializedRpcRequest extends SerializedRpcActivity {\r\n operation: SerializedRpcOperation;\r\n method: string;\r\n path: string;\r\n parameters: RpcSerializedValue;\r\n caching: RpcResponseCacheControl;\r\n ip?: string;\r\n protocolVersion?: number;\r\n parametersOverride?: any[];\r\n}\r\n\r\n/** An RPC operation request fulfillment.\r\n * @internal\r\n */\r\nexport interface RpcRequestFulfillment {\r\n /** The RPC interface for the request. */\r\n interfaceName: string;\r\n\r\n /** The id for the request. */\r\n id: string;\r\n\r\n /** The result for the request. */\r\n result: RpcSerializedValue;\r\n\r\n /** The un-serialized result for the request. */\r\n rawResult: any;\r\n\r\n /** A protocol-specific status code value for the request. */\r\n status: number;\r\n\r\n /* A protocol-specific value for retrying this request. */\r\n retry?: string;\r\n\r\n /** Whether to compress the result with one of the client's supported encodings. */\r\n allowCompression?: boolean;\r\n}\r\n\r\n/** @internal */\r\nexport namespace RpcRequestFulfillment {\r\n export async function forUnknownError(request: SerializedRpcRequest, error: any): Promise<RpcRequestFulfillment> {\r\n const result = await RpcMarshaling.serialize(undefined, error);\r\n\r\n return {\r\n interfaceName: request.operation.interfaceDefinition,\r\n id: request.id,\r\n result,\r\n rawResult: error,\r\n status: RpcRequestStatus.Rejected,\r\n };\r\n }\r\n}\r\n\r\n/** Handles RPC protocol events.\r\n * @internal\r\n */\r\nexport type RpcProtocolEventHandler = (type: RpcProtocolEvent, object: RpcRequest | RpcInvocation, err?: any) => void;\r\n\r\n/** Documents changes to the RPC protocol version.\r\n * @internal\r\n */\r\nexport enum RpcProtocolVersion {\r\n None = 0,\r\n IntroducedNoContent = 1,\r\n IntroducedStatusCategory = 2\r\n}\r\n\r\n/**\r\n * A backend response that is handled internally by the RPC system.\r\n * @internal\r\n */\r\nexport interface RpcManagedStatus {\r\n iTwinRpcCoreResponse: true;\r\n managedStatus: \"pending\" | \"notFound\" | \"noContent\";\r\n responseValue: string | { message: string } | RpcNotFoundResponse;\r\n}\r\n\r\n/** An application protocol for an RPC interface.\r\n * @internal\r\n */\r\nexport abstract class RpcProtocol {\r\n /** Events raised by all protocols. See [[RpcProtocolEvent]] */\r\n public static readonly events: BeEvent<RpcProtocolEventHandler> = new BeEvent();\r\n\r\n /** A version code that identifies the RPC protocol capabilties of this endpoint. */\r\n public static readonly protocolVersion: number = RpcProtocolVersion.IntroducedStatusCategory;\r\n\r\n /** The name of the RPC protocol version header. */\r\n public protocolVersionHeaderName = \"\";\r\n\r\n /** Events raised by the protocol. See [[RpcProtocolEvent]] */\r\n public readonly events: BeEvent<RpcProtocolEventHandler> = new BeEvent();\r\n\r\n /** The configuration for the protocol. */\r\n public readonly configuration: RpcConfiguration;\r\n\r\n /** The RPC request class for this protocol. */\r\n public abstract readonly requestType: typeof RpcRequest;\r\n\r\n /** The RPC invocation class for this protocol. */\r\n public readonly invocationType: typeof RpcInvocation = RpcInvocation;\r\n\r\n public serializedClientRequestContextHeaderNames: SerializedRpcActivity = {\r\n /** The name of the request id header. */\r\n id: \"\",\r\n\r\n /** The name of the application id header */\r\n applicationId: \"\",\r\n\r\n /** The name of the version header. */\r\n applicationVersion: \"\",\r\n\r\n /** The name of the session id header */\r\n sessionId: \"\",\r\n\r\n /** The name of the authorization header. */\r\n authorization: \"\",\r\n };\r\n\r\n /** If greater than zero, specifies where to break large binary request payloads. */\r\n public transferChunkThreshold: number = 0;\r\n\r\n /** Used by protocols that can transmit stream values natively. */\r\n public preserveStreams: boolean = false;\r\n\r\n /** Used by protocols that can transmit IModelRpcProps values natively. */\r\n public checkToken: boolean = false;\r\n\r\n /** Used by protocols that support user-defined status codes. */\r\n public supportsStatusCategory: boolean = false;\r\n\r\n /** If checkToken is true, will be called on the backend to inflate the IModelRpcProps for each request. */\r\n public inflateToken(tokenFromBody: IModelRpcProps, _request: SerializedRpcRequest): IModelRpcProps { return tokenFromBody; }\r\n\r\n /** Override to supply the status corresponding to a protocol-specific code value. */\r\n public getStatus(code: number): RpcRequestStatus {\r\n return code;\r\n }\r\n\r\n /** Override to supply the protocol-specific code corresponding to a status value. */\r\n public getCode(status: RpcRequestStatus): number {\r\n return status;\r\n }\r\n\r\n /** Override to supply the protocol-specific path value for an RPC operation. */\r\n public supplyPathForOperation(operation: RpcOperation, _request: RpcRequest | undefined): string {\r\n return JSON.stringify(operation);\r\n }\r\n\r\n /** Override to supply the operation for a protocol-specific path value. */\r\n public getOperationFromPath(path: string): SerializedRpcOperation {\r\n return JSON.parse(path);\r\n }\r\n\r\n /** Obtains the implementation result on the backend for an RPC operation request. */\r\n public async fulfill(request: SerializedRpcRequest): Promise<RpcRequestFulfillment> {\r\n return new (this.invocationType)(this, request).fulfillment;\r\n }\r\n\r\n /** Serializes a request. */\r\n public async serialize(request: RpcRequest): Promise<SerializedRpcRequest> {\r\n const serializedContext = await RpcConfiguration.requestContext.serialize(request);\r\n return {\r\n ...serializedContext,\r\n operation: {\r\n interfaceDefinition: request.operation.interfaceDefinition.interfaceName,\r\n operationName: request.operation.operationName,\r\n interfaceVersion: request.operation.interfaceVersion,\r\n },\r\n method: request.method,\r\n path: request.path,\r\n parameters: await RpcMarshaling.serialize(request.protocol, request.parameters),\r\n caching: RpcResponseCacheControl.None,\r\n protocolVersion: RpcProtocol.protocolVersion,\r\n };\r\n }\r\n\r\n /** Constructs a protocol. */\r\n public constructor(configuration: RpcConfiguration) {\r\n this.configuration = configuration;\r\n this.events.addListener((type, object) => RpcProtocol.events.raiseEvent(type, object));\r\n }\r\n\r\n /** @internal */\r\n public onRpcClientInitialized(_definition: RpcInterfaceDefinition, _client: RpcInterface): void { }\r\n\r\n /** @internal */\r\n public onRpcImplInitialized(_definition: RpcInterfaceDefinition, _impl: RpcInterface): void { }\r\n\r\n /** @internal */\r\n public onRpcClientTerminated(_definition: RpcInterfaceDefinition, _client: RpcInterface): void { }\r\n\r\n /** @internal */\r\n public onRpcImplTerminated(_definition: RpcInterfaceDefinition, _impl: RpcInterface): void { }\r\n}\r\n"]}
|
|
1
|
+
{"version":3,"file":"RpcProtocol.js","sourceRoot":"","sources":["../../../../src/rpc/core/RpcProtocol.ts"],"names":[],"mappings":"AAAA;;;+FAG+F;AAC/F;;GAEG;AAEH,OAAO,EAAE,OAAO,EAAE,MAAM,qBAAqB,CAAC;AAG9C,OAAO,EAAE,gBAAgB,EAAE,MAAM,oBAAoB,CAAC;AACtD,OAAO,EAAoB,gBAAgB,EAAE,uBAAuB,EAAE,MAAM,gBAAgB,CAAC;AAE7F,OAAO,EAAE,aAAa,EAAyB,MAAM,iBAAiB,CAAC;AACvE,OAAO,EAAE,aAAa,EAAsB,MAAM,iBAAiB,CAAC;AAwDpE,gBAAgB;AAChB,MAAM,KAAW,qBAAqB,CAYrC;AAZD,WAA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gE;QACzD,2BAAsB,GAAY,KAAK,CAAC;QAkD7C,IAAI,CAAC,aAAa,GAAG,aAAa,CAAC;QACnC,IAAI,CAAC,MAAM,CAAC,WAAW,CAAC,CAAC,IAAI,EAAE,MAAM,EAAE,EAAE,CAAC,WAAW,CAAC,MAAM,CAAC,UAAU,CAAC,IAAI,EAAE,MAAM,CAAC,CAAC,CAAC;IACzF,CAAC;IAED,gBAAgB;IACT,sBAAsB,CAAC,WAAmC,EAAE,OAAqB,IAAU,CAAC;IAEnG,gBAAgB;IACT,oBAAoB,CAAC,WAAmC,EAAE,KAAmB,IAAU,CAAC;IAE/F,gBAAgB;IACT,qBAAqB,CAAC,WAAmC,EAAE,OAAqB,IAAU,CAAC;IAElG,gBAAgB;IACT,mBAAmB,CAAC,WAAmC,EAAE,KAAmB,IAAU,CAAC;;AAhH9F,+DAA+D;AACxC,kBAAM,GAAqC,IAAI,OAAO,EAAE,AAAlD,CAAmD;AAEhF,oFAAoF;AAC7D,2BAAe,GAAW,kBAAkB,CAAC,wBAAwB,AAAtD,CAAuD;SALzE,WAAW","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 { BeEvent } from \"@itwin/core-bentley\";\r\nimport { IModelRpcProps } from \"../../IModel\";\r\nimport { RpcInterface, RpcInterfaceDefinition } from \"../../RpcInterface\";\r\nimport { RpcConfiguration } from \"./RpcConfiguration\";\r\nimport { RpcProtocolEvent, RpcRequestStatus, RpcResponseCacheControl } from \"./RpcConstants\";\r\nimport { RpcNotFoundResponse } from \"./RpcControl\";\r\nimport { RpcInvocation, SerializedRpcActivity } from \"./RpcInvocation\";\r\nimport { RpcMarshaling, RpcSerializedValue } from \"./RpcMarshaling\";\r\nimport { RpcOperation } from \"./RpcOperation\";\r\nimport { RpcRequest } from \"./RpcRequest\";\r\n\r\n/* eslint-disable deprecation/deprecation */\r\n\r\n/** A serialized RPC operation descriptor.\r\n * @internal\r\n */\r\nexport interface SerializedRpcOperation {\r\n interfaceDefinition: string;\r\n operationName: string;\r\n interfaceVersion: string;\r\n encodedRequest?: string;\r\n}\r\n\r\n/** A serialized RPC operation request.\r\n * @internal\r\n */\r\nexport interface SerializedRpcRequest extends SerializedRpcActivity {\r\n operation: SerializedRpcOperation;\r\n method: string;\r\n path: string;\r\n parameters: RpcSerializedValue;\r\n caching: RpcResponseCacheControl;\r\n ip?: string;\r\n protocolVersion?: number;\r\n parametersOverride?: any[];\r\n}\r\n\r\n/** An RPC operation request fulfillment.\r\n * @internal\r\n */\r\nexport interface RpcRequestFulfillment {\r\n /** The RPC interface for the request. */\r\n interfaceName: string;\r\n\r\n /** The id for the request. */\r\n id: string;\r\n\r\n /** The result for the request. */\r\n result: RpcSerializedValue;\r\n\r\n /** The un-serialized result for the request. */\r\n rawResult: any;\r\n\r\n /** A protocol-specific status code value for the request. */\r\n status: number;\r\n\r\n /* A protocol-specific value for retrying this request. */\r\n retry?: string;\r\n\r\n /** Whether to compress the result with one of the client's supported encodings. */\r\n allowCompression?: boolean;\r\n}\r\n\r\n/** @internal */\r\nexport namespace RpcRequestFulfillment {\r\n export async function forUnknownError(request: SerializedRpcRequest, error: any): Promise<RpcRequestFulfillment> {\r\n const result = RpcMarshaling.serialize(undefined, error);\r\n\r\n return {\r\n interfaceName: request.operation.interfaceDefinition,\r\n id: request.id,\r\n result,\r\n rawResult: error,\r\n status: RpcRequestStatus.Rejected,\r\n };\r\n }\r\n}\r\n\r\n/** Handles RPC protocol events.\r\n * @internal\r\n */\r\nexport type RpcProtocolEventHandler = (type: RpcProtocolEvent, object: RpcRequest | RpcInvocation, err?: any) => void;\r\n\r\n/** Documents changes to the RPC protocol version.\r\n * @internal\r\n */\r\nexport enum RpcProtocolVersion {\r\n None = 0,\r\n IntroducedNoContent = 1,\r\n IntroducedStatusCategory = 2\r\n}\r\n\r\n/**\r\n * A backend response that is handled internally by the RPC system.\r\n * @internal\r\n */\r\nexport interface RpcManagedStatus {\r\n iTwinRpcCoreResponse: true;\r\n managedStatus: \"pending\" | \"notFound\" | \"noContent\";\r\n responseValue: string | { message: string } | RpcNotFoundResponse;\r\n}\r\n\r\n/** An application protocol for an RPC interface.\r\n * @internal\r\n */\r\nexport abstract class RpcProtocol {\r\n /** Events raised by all protocols. See [[RpcProtocolEvent]] */\r\n public static readonly events: BeEvent<RpcProtocolEventHandler> = new BeEvent();\r\n\r\n /** A version code that identifies the RPC protocol capabilties of this endpoint. */\r\n public static readonly protocolVersion: number = RpcProtocolVersion.IntroducedStatusCategory;\r\n\r\n /** The name of the RPC protocol version header. */\r\n public protocolVersionHeaderName = \"\";\r\n\r\n /** Events raised by the protocol. See [[RpcProtocolEvent]] */\r\n public readonly events: BeEvent<RpcProtocolEventHandler> = new BeEvent();\r\n\r\n /** The configuration for the protocol. */\r\n public readonly configuration: RpcConfiguration;\r\n\r\n /** The RPC request class for this protocol. */\r\n public abstract readonly requestType: typeof RpcRequest;\r\n\r\n /** The RPC invocation class for this protocol. */\r\n public readonly invocationType: typeof RpcInvocation = RpcInvocation;\r\n\r\n public serializedClientRequestContextHeaderNames: SerializedRpcActivity = {\r\n /** The name of the request id header. */\r\n id: \"\",\r\n\r\n /** The name of the application id header */\r\n applicationId: \"\",\r\n\r\n /** The name of the version header. */\r\n applicationVersion: \"\",\r\n\r\n /** The name of the session id header */\r\n sessionId: \"\",\r\n\r\n /** The name of the authorization header. */\r\n authorization: \"\",\r\n };\r\n\r\n /** If greater than zero, specifies where to break large binary request payloads. */\r\n public transferChunkThreshold: number = 0;\r\n\r\n /** Used by protocols that can transmit stream values natively. */\r\n public preserveStreams: boolean = false;\r\n\r\n /** Used by protocols that can transmit IModelRpcProps values natively. */\r\n public checkToken: boolean = false;\r\n\r\n /** Used by protocols that support user-defined status codes. */\r\n public supportsStatusCategory: boolean = false;\r\n\r\n /** If checkToken is true, will be called on the backend to inflate the IModelRpcProps for each request. */\r\n public inflateToken(tokenFromBody: IModelRpcProps, _request: SerializedRpcRequest): IModelRpcProps { return tokenFromBody; }\r\n\r\n /** Override to supply the status corresponding to a protocol-specific code value. */\r\n public getStatus(code: number): RpcRequestStatus {\r\n return code;\r\n }\r\n\r\n /** Override to supply the protocol-specific code corresponding to a status value. */\r\n public getCode(status: RpcRequestStatus): number {\r\n return status;\r\n }\r\n\r\n /** Override to supply the protocol-specific path value for an RPC operation. */\r\n public supplyPathForOperation(operation: RpcOperation, _request: RpcRequest | undefined): string {\r\n return JSON.stringify(operation);\r\n }\r\n\r\n /** Override to supply the operation for a protocol-specific path value. */\r\n public getOperationFromPath(path: string): SerializedRpcOperation {\r\n return JSON.parse(path);\r\n }\r\n\r\n /** Obtains the implementation result on the backend for an RPC operation request. */\r\n public async fulfill(request: SerializedRpcRequest): Promise<RpcRequestFulfillment> {\r\n return new (this.invocationType)(this, request).fulfillment;\r\n }\r\n\r\n /** Serializes a request. */\r\n public async serialize(request: RpcRequest): Promise<SerializedRpcRequest> {\r\n const serializedContext = await RpcConfiguration.requestContext.serialize(request);\r\n return {\r\n ...serializedContext,\r\n operation: {\r\n interfaceDefinition: request.operation.interfaceDefinition.interfaceName,\r\n operationName: request.operation.operationName,\r\n interfaceVersion: request.operation.interfaceVersion,\r\n },\r\n method: request.method,\r\n path: request.path,\r\n parameters: RpcMarshaling.serialize(request.protocol, request.parameters),\r\n caching: RpcResponseCacheControl.None,\r\n protocolVersion: RpcProtocol.protocolVersion,\r\n };\r\n }\r\n\r\n /** Constructs a protocol. */\r\n public constructor(configuration: RpcConfiguration) {\r\n this.configuration = configuration;\r\n this.events.addListener((type, object) => RpcProtocol.events.raiseEvent(type, object));\r\n }\r\n\r\n /** @internal */\r\n public onRpcClientInitialized(_definition: RpcInterfaceDefinition, _client: RpcInterface): void { }\r\n\r\n /** @internal */\r\n public onRpcImplInitialized(_definition: RpcInterfaceDefinition, _impl: RpcInterface): void { }\r\n\r\n /** @internal */\r\n public onRpcClientTerminated(_definition: RpcInterfaceDefinition, _client: RpcInterface): void { }\r\n\r\n /** @internal */\r\n public onRpcImplTerminated(_definition: RpcInterfaceDefinition, _impl: RpcInterface): void { }\r\n}\r\n"]}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@itwin/core-common",
|
|
3
|
-
"version": "4.4.0-dev.
|
|
3
|
+
"version": "4.4.0-dev.7",
|
|
4
4
|
"description": "iTwin.js components common to frontend and backend",
|
|
5
5
|
"main": "lib/cjs/core-common.js",
|
|
6
6
|
"module": "lib/esm/core-common.js",
|
|
@@ -27,8 +27,8 @@
|
|
|
27
27
|
"js-base64": "^3.6.1"
|
|
28
28
|
},
|
|
29
29
|
"peerDependencies": {
|
|
30
|
-
"@itwin/core-bentley": "^4.4.0-dev.
|
|
31
|
-
"@itwin/core-geometry": "^4.4.0-dev.
|
|
30
|
+
"@itwin/core-bentley": "^4.4.0-dev.7",
|
|
31
|
+
"@itwin/core-geometry": "^4.4.0-dev.7"
|
|
32
32
|
},
|
|
33
33
|
"devDependencies": {
|
|
34
34
|
"@itwin/eslint-plugin": "4.0.0-dev.44",
|
|
@@ -42,9 +42,9 @@
|
|
|
42
42
|
"nyc": "^15.1.0",
|
|
43
43
|
"rimraf": "^3.0.2",
|
|
44
44
|
"typescript": "~5.0.2",
|
|
45
|
-
"@itwin/
|
|
46
|
-
"@itwin/
|
|
47
|
-
"@itwin/core-geometry": "4.4.0-dev.
|
|
45
|
+
"@itwin/core-bentley": "4.4.0-dev.7",
|
|
46
|
+
"@itwin/build-tools": "4.4.0-dev.7",
|
|
47
|
+
"@itwin/core-geometry": "4.4.0-dev.7"
|
|
48
48
|
},
|
|
49
49
|
"nyc": {
|
|
50
50
|
"extends": "./node_modules/@itwin/build-tools/.nycrc",
|