@webpieces/ipc-bridge 0.4.790 → 0.4.792

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@webpieces/ipc-bridge",
3
- "version": "0.4.790",
3
+ "version": "0.4.792",
4
4
  "description": "Portable typed duplex IPC client and server factories for browser, React Native and Node",
5
5
  "type": "commonjs",
6
6
  "main": "./src/index.js",
@@ -22,6 +22,6 @@
22
22
  "access": "public"
23
23
  },
24
24
  "dependencies": {
25
- "@webpieces/core-util": "0.4.790"
25
+ "@webpieces/core-util": "0.4.792"
26
26
  }
27
27
  }
@@ -30,8 +30,10 @@ class IpcClientFactory {
30
30
  if (request === null || request === undefined)
31
31
  throw new errors_1.ApiImplementationError('IPC requests require one non-null DTO');
32
32
  const reply = await this.connection.request(new ipc_1.IpcRequest(apiId, methodId, context, request));
33
- if (reply.type === 'failure')
34
- throw errors_1.ApiErrorCodec.decode(reply.error);
33
+ // EVERY reply passes the seam, success included, so an app can turn an
34
+ // apparently-successful reply into a throw. `asserts reply is IpcSuccess`
35
+ // is what leaves no `type === 'failure'` branch behind here.
36
+ ipc_1.IpcClientErrorTranslator.throwIfFailure(reply);
35
37
  return reply.body === null ? undefined : reply.body;
36
38
  });
37
39
  });
@@ -1 +1 @@
1
- {"version":3,"file":"IpcClientFactory.js","sourceRoot":"","sources":["../../../../../packages/core/ipc-bridge/src/IpcClientFactory.ts"],"names":[],"mappings":";;;AAAA,wDAAoF;AACpF,kDAWkC;AAElC,gGAAgG;AAChG,MAAa,gBAAgB;IAEJ;IACA;IACA;IAHrB,YACqB,UAAyB,EACzB,OAAmB,EACnB,MAAuB;QAFvB,eAAU,GAAV,UAAU,CAAe;QACzB,YAAO,GAAP,OAAO,CAAY;QACnB,WAAM,GAAN,MAAM,CAAiB;IACzC,CAAC;IAEJ,0FAA0F;IAC1F,WAAW,CAAC,OAAuB;QAC/B,OA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,KAAK,IAAI,CAAC,CAAC,CAAC,SAAS,CAAC,CAAC,CAAC,KAAK,CAAC,IAAI,CAAC;gBACxD,CAAC,CACJ,CAAC;YACN,CAAC,CAAC,CAAC;QACP,CAAC;QACD,OAAO,IAAI,KAAK,CAAC,MAAM,CAAC,MAAM,CAAC,IAAI,CAAM,EAAE,IAAI,eAAe,CAAC,OAAO,CAAC,CAAC,CAAC;IAC7E,CAAC;CACJ;AA7CD,4CA6CC;AAED,MAAM,eAAe;IAGI;IAFrB;IACI,0IAA0I;IACzH,OAAyE;QAAzE,YAAO,GAAP,OAAO,CAAkE;IAC3F,CAAC;IACJ,0IAA0I;IAC1I,GAAG,CAAC,OAAU,EAAE,GAAoB;QAChC,8FAA8F;QAC9F,OAAO,IAAI,CAAC,OAAO,CAAC,GAAG,CAAC,GAAG,CAAC,CAAC;IACjC,CAAC;IACD,GAAG,CAAC,OAAU,EAAE,GAAoB;QAChC,OAAO,IAAI,CAAC,OAAO,CAAC,GAAG,CAAC,GAAG,CAAC,CAAC;IACjC,CAAC;CACJ","sourcesContent":["import { ApiErrorCodec, ApiImplementationError } from '@webpieces/core-util/errors';\nimport {\n IpcCallContext,\n IpcConnection,\n IpcApiType,\n IpcLogging,\n IpcRequest,\n IpcCallLogger,\n assertInternalApi,\n getIpcEndpoints,\n getIpcMaskSpec,\n MaskSpec,\n} from '@webpieces/core-util/ipc';\n\n/** Typed proxies on one trusted duplex connection; no HTTP decorators or container required. */\nexport class IpcClientFactory {\n constructor(\n private readonly connection: IpcConnection,\n private readonly logging: IpcLogging,\n private readonly parent?: IpcCallContext,\n ) {}\n\n /** Explicit scope propagation is safe across concurrent async calls in browser and RN. */\n withContext(context: IpcCallContext): IpcClientFactory {\n return new IpcClientFactory(this.connection, this.logging, context);\n }\n\n createClient<T extends object>(apiClass: IpcApiType<T>): T {\n const apiId = assertInternalApi(apiClass);\n const endpoints = getIpcEndpoints(apiClass);\n // webpieces-disable no-any-unknown -- untrusted IPC data is schema-validated; generic dispatch cannot assume a DTO type before validation\n const methods = new Map<PropertyKey, (request: unknown) => Promise<unknown>>();\n for (const [key, methodId] of Object.entries(endpoints)) {\n // webpieces-disable no-any-unknown -- untrusted IPC data is schema-validated; generic dispatch cannot assume a DTO type before validation\n methods.set(key, async (request: unknown): Promise<unknown> => {\n const context = this.connection.newContext(this.parent);\n return IpcCallLogger.execute(\n this.logging,\n context,\n 'client',\n apiId,\n methodId,\n getIpcMaskSpec(apiClass, key) ?? new MaskSpec({}),\n request,\n async () => {\n if (request === null || request === undefined)\n throw new ApiImplementationError(\n 'IPC requests require one non-null DTO',\n );\n const reply = await this.connection.request(\n new IpcRequest(apiId, methodId, context, request),\n );\n if (reply.type === 'failure') throw ApiErrorCodec.decode(reply.error);\n return reply.body === null ? undefined : reply.body;\n },\n );\n });\n }\n return new Proxy(Object.create(null) as T, new IpcProxyHandler(methods));\n }\n}\n\nclass IpcProxyHandler<T extends object> implements ProxyHandler<T> {\n constructor(\n // webpieces-disable no-any-unknown -- untrusted IPC data is schema-validated; generic dispatch cannot assume a DTO type before validation\n private readonly methods: ReadonlyMap<PropertyKey, (request: unknown) => Promise<unknown>>,\n ) {}\n // webpieces-disable no-any-unknown -- untrusted IPC data is schema-validated; generic dispatch cannot assume a DTO type before validation\n get(_target: T, key: string | symbol): unknown {\n // Promise assimilation, inspection, symbols and framework instrumentation aren't RPC methods.\n return this.methods.get(key);\n }\n has(_target: T, key: string | symbol): boolean {\n return this.methods.has(key);\n }\n}\n"]}
1
+ {"version":3,"file":"IpcClientFactory.js","sourceRoot":"","sources":["../../../../../packages/core/ipc-bridge/src/IpcClientFactory.ts"],"names":[],"mappings":";;;AAAA,wDAAqE;AACrE,kDAYkC;AAElC,gGAAgG;AAChG,MAAa,gBAAgB;IAEJ;IACA;IACA;IAHrB,YACqB,UAAyB,EACzB,OAAmB,EACnB,MAAuB;QAFvB,eAAU,GAAV,UAAU,CAAe;QACzB,YAAO,GAAP,OAAO,CAAY;QACnB,WAAM,GAAN,M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AAC,cAAc,CAAC,KAAK,CAAC,CAAC;oBAC/C,OAAO,KAAK,CAAC,IAAI,KAAK,IAAI,CAAC,CAAC,CAAC,SAAS,CAAC,CAAC,CAAC,KAAK,CAAC,IAAI,CAAC;gBACxD,CAAC,CACJ,CAAC;YACN,CAAC,CAAC,CAAC;QACP,CAAC;QACD,OAAO,IAAI,KAAK,CAAC,MAAM,CAAC,MAAM,CAAC,IAAI,CAAM,EAAE,IAAI,eAAe,CAAC,OAAO,CAAC,CAAC,CAAC;IAC7E,CAAC;CACJ;AAhDD,4CAgDC;AAED,MAAM,eAAe;IAGI;IAFrB;IACI,0IAA0I;IACzH,OAAyE;QAAzE,YAAO,GAAP,OAAO,CAAkE;IAC3F,CAAC;IACJ,0IAA0I;IAC1I,GAAG,CAAC,OAAU,EAAE,GAAoB;QAChC,8FAA8F;QAC9F,OAAO,IAAI,CAAC,OAAO,CAAC,GAAG,CAAC,GAAG,CAAC,CAAC;IACjC,CAAC;IACD,GAAG,CAAC,OAAU,EAAE,GAAoB;QAChC,OAAO,IAAI,CAAC,OAAO,CAAC,GAAG,CAAC,GAAG,CAAC,CAAC;IACjC,CAAC;CACJ","sourcesContent":["import { ApiImplementationError } from '@webpieces/core-util/errors';\nimport {\n IpcCallContext,\n IpcClientErrorTranslator,\n IpcConnection,\n IpcApiType,\n IpcLogging,\n IpcRequest,\n IpcCallLogger,\n assertInternalApi,\n getIpcEndpoints,\n getIpcMaskSpec,\n MaskSpec,\n} from '@webpieces/core-util/ipc';\n\n/** Typed proxies on one trusted duplex connection; no HTTP decorators or container required. */\nexport class IpcClientFactory {\n constructor(\n private readonly connection: IpcConnection,\n private readonly logging: IpcLogging,\n private readonly parent?: IpcCallContext,\n ) {}\n\n /** Explicit scope propagation is safe across concurrent async calls in browser and RN. */\n withContext(context: IpcCallContext): IpcClientFactory {\n return new IpcClientFactory(this.connection, this.logging, context);\n }\n\n createClient<T extends object>(apiClass: IpcApiType<T>): T {\n const apiId = assertInternalApi(apiClass);\n const endpoints = getIpcEndpoints(apiClass);\n // webpieces-disable no-any-unknown -- untrusted IPC data is schema-validated; generic dispatch cannot assume a DTO type before validation\n const methods = new Map<PropertyKey, (request: unknown) => Promise<unknown>>();\n for (const [key, methodId] of Object.entries(endpoints)) {\n // webpieces-disable no-any-unknown -- untrusted IPC data is schema-validated; generic dispatch cannot assume a DTO type before validation\n methods.set(key, async (request: unknown): Promise<unknown> => {\n const context = this.connection.newContext(this.parent);\n return IpcCallLogger.execute(\n this.logging,\n context,\n 'client',\n apiId,\n methodId,\n getIpcMaskSpec(apiClass, key) ?? new MaskSpec({}),\n request,\n async () => {\n if (request === null || request === undefined)\n throw new ApiImplementationError(\n 'IPC requests require one non-null DTO',\n );\n const reply = await this.connection.request(\n new IpcRequest(apiId, methodId, context, request),\n );\n // EVERY reply passes the seam, success included, so an app can turn an\n // apparently-successful reply into a throw. `asserts reply is IpcSuccess`\n // is what leaves no `type === 'failure'` branch behind here.\n IpcClientErrorTranslator.throwIfFailure(reply);\n return reply.body === null ? undefined : reply.body;\n },\n );\n });\n }\n return new Proxy(Object.create(null) as T, new IpcProxyHandler(methods));\n }\n}\n\nclass IpcProxyHandler<T extends object> implements ProxyHandler<T> {\n constructor(\n // webpieces-disable no-any-unknown -- untrusted IPC data is schema-validated; generic dispatch cannot assume a DTO type before validation\n private readonly methods: ReadonlyMap<PropertyKey, (request: unknown) => Promise<unknown>>,\n ) {}\n // webpieces-disable no-any-unknown -- untrusted IPC data is schema-validated; generic dispatch cannot assume a DTO type before validation\n get(_target: T, key: string | symbol): unknown {\n // Promise assimilation, inspection, symbols and framework instrumentation aren't RPC methods.\n return this.methods.get(key);\n }\n has(_target: T, key: string | symbol): boolean {\n return this.methods.has(key);\n }\n}\n"]}
@@ -7,8 +7,6 @@ export interface IpcControllerScope<T> {
7
7
  export declare class IpcServerFactory {
8
8
  private readonly logging;
9
9
  private readonly registrations;
10
- /** This receiver OWNS the reply, so it publishes through the shared boundary rule, not the raw codec. */
11
- private readonly boundary;
12
10
  constructor(logging: IpcLogging);
13
11
  create<T extends object>(apiClass: IpcApiType<T>, controller: T): void;
14
12
  createScoped<T extends object>(apiClass: IpcApiType<T>, scope: IpcControllerScope<T>): void;
@@ -14,8 +14,6 @@ class IpcRegistration {
14
14
  class IpcServerFactory {
15
15
  logging;
16
16
  registrations = new Map();
17
- /** This receiver OWNS the reply, so it publishes through the shared boundary rule, not the raw codec. */
18
- boundary = new errors_1.ApiErrorBoundary();
19
17
  constructor(logging) {
20
18
  this.logging = logging;
21
19
  }
@@ -60,7 +58,9 @@ class IpcServerFactory {
60
58
  }
61
59
  catch (err) {
62
60
  const error = (0, ipc_1.toError)(err);
63
- return new ipc_1.IpcFailure(request.context, this.boundary.encode(error));
61
+ // This receiver OWNS the reply, so it publishes through the app-reachable IPC seam. The
62
+ // webpieces default there is the shared `ApiErrorBoundary` rule, not the raw codec.
63
+ return new ipc_1.IpcFailure(request.context, ipc_1.IpcRegistry.getErrorTranslator().toWire(error));
64
64
  }
65
65
  };
66
66
  }
@@ -1 +1 @@
1
- {"version":3,"file":"IpcServerFactory.js","sourceRoot":"","sources":["../../../../../packages/core/ipc-bridge/src/IpcServerFactory.ts"],"names":[],"mappings":";;;AAAA,wDAIqC;AACrC,kDAckC;AAMlC,MAAM,eAAe;IAEI;IADrB,0IAA0I;IAC1I,YAAqB,MAAiD;QAAjD,WAAM,GAAN,MAAM,CAA2C;IAAG,CAAC;CAC7E;AAED,wGAAwG;AACxG,MAAa,gBAAgB;IAII;IAHZ,aAAa,GAAG,IAAI,GAAG,EAAwC,CAAC;IACjF,yGAAyG;IACxF,QAAQ,GAAG,IAAI,yBAAgB,EAAE,CAAC;IACnD,YAA6B,OAAmB;QAAnB,YAAO,GAAP,OAAO,CAAY;IAAG,CAAC;IAEpD,MAAM,CAAmB,QAAuB,EAAE,UAAa;QAC3D,IAAI,CAAC,QAAQ,CAAC,QAAQ,EAAE,GAAG,EAAE,CAAC,UAAU,CAAC,CAAC;IAC9C,CAA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webpieces/core-util/errors';\nimport {\n IpcCallContext,\n IpcApiType,\n IpcFailure,\n IpcLogging,\n IpcReply,\n IpcRequest,\n IpcSuccess,\n IpcCallLogger,\n toError,\n assertInternalApi,\n getIpcEndpoints,\n getIpcMaskSpec,\n MaskSpec,\n} from '@webpieces/core-util/ipc';\n\n/** Construct a receiver using explicit call context when it needs to make nested outbound calls. */\nexport interface IpcControllerScope<T> {\n create(context: IpcCallContext): T;\n}\nclass IpcRegistration {\n // webpieces-disable no-any-unknown -- untrusted IPC data is schema-validated; generic dispatch cannot assume a DTO type before validation\n constructor(readonly invoke: (request: IpcRequest) => Promise<unknown>) {}\n}\n\n/** One dispatcher hosts multiple explicitly registered APIs and never enumerates controller members. */\nexport class IpcServerFactory {\n private readonly registrations = new Map<string, Map<string, IpcRegistration>>();\n /** This receiver OWNS the reply, so it publishes through the shared boundary rule, not the raw codec. */\n private readonly boundary = new ApiErrorBoundary();\n constructor(private readonly logging: IpcLogging) {}\n\n create<T extends object>(apiClass: IpcApiType<T>, controller: T): void {\n this.register(apiClass, () => controller);\n }\n\n createScoped<T extends object>(apiClass: IpcApiType<T>, scope: IpcControllerScope<T>): void {\n this.register(apiClass, (context: IpcCallContext) => scope.create(context));\n }\n\n private register<T extends object>(\n apiClass: IpcApiType<T>,\n controller: (context: IpcCallContext) => T,\n ): void {\n const apiId = assertInternalApi(apiClass);\n if (this.registrations.has(apiId))\n throw new ApiImplementationError(`Duplicate IPC API registration: ${apiId}`);\n const methods = new Map<string, IpcRegistration>();\n for (const [key, methodId] of Object.entries(getIpcEndpoints(apiClass))) {\n methods.set(\n methodId,\n new IpcRegistration(async (request) => {\n // Logging wraps validation and invocation; only handle() below encodes exceptions.\n return IpcCallLogger.execute(\n this.logging,\n request.context,\n 'server',\n apiId,\n methodId,\n getIpcMaskSpec(apiClass, key) ?? new MaskSpec({}),\n request.body,\n async () => {\n if (request.body === null || request.body === undefined)\n throw new ApiImplementationError(\n 'IPC requests require one non-null DTO',\n );\n const instance = controller(request.context);\n const invoke = instance[key as keyof T];\n if (typeof invoke !== 'function')\n throw new ApiImplementationError(\n `IPC implementation is missing ${apiId}.${methodId}`,\n );\n const result =\n await // webpieces-disable no-any-unknown -- untrusted IPC data is schema-validated; generic dispatch cannot assume a DTO type before validation\n (invoke as (request: unknown) => Promise<unknown>).call(\n instance,\n request.body,\n );\n return result;\n },\n );\n }),\n );\n }\n this.registrations.set(apiId, methods);\n }\n\n /** Bootstrap passes this function to the ONE connection's setHandler before sending calls. */\n readonly handle = async (request: IpcRequest): Promise<IpcReply> => {\n // eslint-disable-next-line @webpieces/no-unmanaged-exceptions -- receiver translates to a failure reply; the generated client reconstructs and throws it\n try {\n const method = this.registrations.get(request.apiId)?.get(request.methodId);\n if (!method) throw new ApiEndpointNotFoundError('Unknown IPC API or method');\n const body = await method.invoke(request);\n return new IpcSuccess(request.context, body === undefined ? null : body);\n } catch (err: unknown) {\n const error = toError(err);\n return new IpcFailure(request.context, this.boundary.encode(error));\n }\n };\n}\n"]}
1
+ {"version":3,"file":"IpcServerFactory.js","sourceRoot":"","sources":["../../../../../packages/core/ipc-bridge/src/IpcServerFactory.ts"],"names":[],"mappings":";;;AAAA,wDAA+F;AAC/F,kDAekC;AAMlC,MAAM,eAAe;IAEI;IADrB,0IAA0I;IAC1I,YAAqB,MAAiD;QAAjD,WAAM,GAAN,MAAM,CAA2C;IAAG,CAAC;CAC7E;AAED,wGAAwG;AACxG,MAAa,gBAAgB;IAEI;IADZ,aAAa,GAAG,IAAI,GAAG,EAAwC,CAAC;IACjF,YAA6B,OAAmB;QAAnB,YAAO,GAAP,OAAO,CAAY;IAAG,CAAC;IAEpD,MAAM,CAAmB,QAAuB,EAAE,UAAa;QAC3D,IAAI,CAAC,QAAQ,CAAC,QAAQ,EAAE,GAAG,EAAE,CAAC,UAAU,CAAC,CAAC;IAC9C,CAAC;IAED,YAAY,CAAmB,QAAuB,EAAE,KAA4B;QAChF,IAAI,CAAC,QAAQ,CAAC,QAAQ,EAA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,CAAC;oBACN,MAAM,MAAM,GACR,MAAM,0IAA0I;qBAC/I,MAAiD,CAAC,IAAI,CACnD,QAAQ,EACR,OAAO,CAAC,IAAI,CACf,CAAC;oBACN,OAAO,MAAM,CAAC;gBAClB,CAAC,CACJ,CAAC;YACN,CAAC,CAAC,CACL,CAAC;QACN,CAAC;QACD,IAAI,CAAC,aAAa,CAAC,GAAG,CAAC,KAAK,EAAE,OAAO,CAAC,CAAC;IAC3C,CAAC;IAED,8FAA8F;IACrF,MAAM,GAAG,KAAK,EAAE,OAAmB,EAAqB,EAAE;QAC/D,yJAAyJ;QACzJ,IAAI,CAAC;YACD,MAAM,MAAM,GAAG,IAAI,CAAC,aAAa,CAAC,GAAG,CAAC,OAAO,CAAC,KAAK,CAAC,EAAE,GAAG,CAAC,OAAO,CAAC,QAAQ,CAAC,CAAC;YAC5E,IAAI,CAAC,MAAM;gBAAE,MAAM,IAAI,iCAAwB,CAAC,2BAA2B,CAAC,CAAC;YAC7E,MAAM,IAAI,GAAG,MAAM,MAAM,CAAC,MAAM,CAAC,OAAO,CAAC,CAAC;YAC1C,OAAO,IAAI,gBAAU,CAAC,OAAO,CAAC,OAAO,EAAE,IAAI,KAAK,SAAS,CAAC,CAAC,CAAC,IAAI,CAAC,CAAC,CAAC,IAAI,CAAC,CAAC;QAC7E,CAAC;QAAC,OAAO,GAAY,EAAE,CAAC;YACpB,MAAM,KAAK,GAAG,IAAA,aAAO,EAAC,GAAG,CAAC,CAAC;YAC3B,wFAAwF;YACxF,oFAAoF;YACpF,OAAO,IAAI,gBAAU,CAAC,OAAO,CAAC,OAAO,EAAE,iBAAW,CAAC,kBAAkB,EAAE,CAAC,MAAM,CAAC,KAAK,CAAC,CAAC,CAAC;QAC3F,CAAC;IACL,CAAC,CAAC;CACL;AA1ED,4CA0EC","sourcesContent":["import { ApiEndpointNotFoundError, ApiImplementationError } from '@webpieces/core-util/errors';\nimport {\n IpcCallContext,\n IpcApiType,\n IpcRegistry,\n IpcFailure,\n IpcLogging,\n IpcReply,\n IpcRequest,\n IpcSuccess,\n IpcCallLogger,\n toError,\n assertInternalApi,\n getIpcEndpoints,\n getIpcMaskSpec,\n MaskSpec,\n} from '@webpieces/core-util/ipc';\n\n/** Construct a receiver using explicit call context when it needs to make nested outbound calls. */\nexport interface IpcControllerScope<T> {\n create(context: IpcCallContext): T;\n}\nclass IpcRegistration {\n // webpieces-disable no-any-unknown -- untrusted IPC data is schema-validated; generic dispatch cannot assume a DTO type before validation\n constructor(readonly invoke: (request: IpcRequest) => Promise<unknown>) {}\n}\n\n/** One dispatcher hosts multiple explicitly registered APIs and never enumerates controller members. */\nexport class IpcServerFactory {\n private readonly registrations = new Map<string, Map<string, IpcRegistration>>();\n constructor(private readonly logging: IpcLogging) {}\n\n create<T extends object>(apiClass: IpcApiType<T>, controller: T): void {\n this.register(apiClass, () => controller);\n }\n\n createScoped<T extends object>(apiClass: IpcApiType<T>, scope: IpcControllerScope<T>): void {\n this.register(apiClass, (context: IpcCallContext) => scope.create(context));\n }\n\n private register<T extends object>(\n apiClass: IpcApiType<T>,\n controller: (context: IpcCallContext) => T,\n ): void {\n const apiId = assertInternalApi(apiClass);\n if (this.registrations.has(apiId))\n throw new ApiImplementationError(`Duplicate IPC API registration: ${apiId}`);\n const methods = new Map<string, IpcRegistration>();\n for (const [key, methodId] of Object.entries(getIpcEndpoints(apiClass))) {\n methods.set(\n methodId,\n new IpcRegistration(async (request) => {\n // Logging wraps validation and invocation; only handle() below encodes exceptions.\n return IpcCallLogger.execute(\n this.logging,\n request.context,\n 'server',\n apiId,\n methodId,\n getIpcMaskSpec(apiClass, key) ?? new MaskSpec({}),\n request.body,\n async () => {\n if (request.body === null || request.body === undefined)\n throw new ApiImplementationError(\n 'IPC requests require one non-null DTO',\n );\n const instance = controller(request.context);\n const invoke = instance[key as keyof T];\n if (typeof invoke !== 'function')\n throw new ApiImplementationError(\n `IPC implementation is missing ${apiId}.${methodId}`,\n );\n const result =\n await // webpieces-disable no-any-unknown -- untrusted IPC data is schema-validated; generic dispatch cannot assume a DTO type before validation\n (invoke as (request: unknown) => Promise<unknown>).call(\n instance,\n request.body,\n );\n return result;\n },\n );\n }),\n );\n }\n this.registrations.set(apiId, methods);\n }\n\n /** Bootstrap passes this function to the ONE connection's setHandler before sending calls. */\n readonly handle = async (request: IpcRequest): Promise<IpcReply> => {\n // eslint-disable-next-line @webpieces/no-unmanaged-exceptions -- receiver translates to a failure reply; the generated client reconstructs and throws it\n try {\n const method = this.registrations.get(request.apiId)?.get(request.methodId);\n if (!method) throw new ApiEndpointNotFoundError('Unknown IPC API or method');\n const body = await method.invoke(request);\n return new IpcSuccess(request.context, body === undefined ? null : body);\n } catch (err: unknown) {\n const error = toError(err);\n // This receiver OWNS the reply, so it publishes through the app-reachable IPC seam. The\n // webpieces default there is the shared `ApiErrorBoundary` rule, not the raw codec.\n return new IpcFailure(request.context, IpcRegistry.getErrorTranslator().toWire(error));\n }\n };\n}\n"]}