@webpieces/ipc-bridge 0.4.762 → 0.4.763
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/README.md
CHANGED
|
@@ -26,11 +26,11 @@ The DTO, IDs and metadata live in the shared API package. The names of the abstr
|
|
|
26
26
|
|
|
27
27
|
Construct `IpcConnection` with an `IpcTransport` adapter and `IpcConnectionOptions`: a positive timeout, a connection-wide unique ID generator, a scheduler returning timer cancellation functions, and an error owner. The adapter sends strings and subscribes once to incoming strings, transport errors and close events. Its send Promise must reject on send failure; parse/message-error callbacks go to the failure subscriber. A vendor bus adapter must not expose vendor Node declarations through its public contract. Do not install a second vendor handler for every API.
|
|
28
28
|
|
|
29
|
-
`IpcLogging.context(call)` is required and supplies an active per-call `ApiCallContext` carrying the transaction/call/parent IDs in the host logger. Both factories invoke framework `LogApiCallImpl`; receiver logging happens before encoding failures and sender completion logging happens after decoding. `
|
|
29
|
+
`IpcLogging.context(call)` is required and supplies an active per-call `ApiCallContext` carrying the transaction/call/parent IDs in the host logger. Both factories invoke framework `LogApiCallImpl`; receiver logging happens before encoding failures and sender completion logging happens after decoding. `ApiEndUserError` is rethrown but remains a successful monitoring outcome. Configure the normal framework logging backend at bootstrap. Masking affects logs, never wire DTOs.
|
|
30
30
|
|
|
31
31
|
Use `clients.withContext(inboundContext)` when making nested calls; this copies the transaction and makes the inbound call the parent. No ambient mutable state is held across awaits. `createScoped` on the server supports constructing a controller with a scoped client factory.
|
|
32
32
|
|
|
33
|
-
Timeout rejects with the existing `
|
|
33
|
+
Timeout rejects with the existing `ApiCallTimeoutError`. Send/close/disposal rejects with local `IpcTransportError`, preserving the original failure as standard `cause`. This extends `Error`, not semantic `ApiError`, and is never a remote wire category. A receiver throwing `ApiUnavailableError` still arrives as that canonical semantic error, so callers can distinguish a failed local bridge from an unavailable remote implementation. A timeout does not cancel remote side effects, and the framework never replays requests. `dispose()` rejects pending requests and closes the adapter. Late replies are reported and ignored. Malformed envelopes and correlation mismatches fail the connection, including its pending calls. Observe all OS-callback send Promises or route rejections to the application's explicit error owner.
|
|
34
34
|
|
|
35
35
|
Host responsibilities: validate WebView origins/navigation/session identity and expose only authorized APIs. Suspension/resume, coalescing native state, durable usage journals and installed shell protocol minimums are application policies. Generic IPC cannot make suspended website JavaScript execute. Android/iOS lifecycle and locked-screen tests remain downstream integration work.
|
|
36
36
|
|
|
@@ -47,7 +47,7 @@ server.create(NavigationApi, new NavigationController(router));
|
|
|
47
47
|
connection.setHandler(server.handle); // exactly once, before sending any calls
|
|
48
48
|
```
|
|
49
49
|
|
|
50
|
-
One connection has one dispatcher containing multiple APIs. Duplicate registrations fail. Unknown API/method IDs return canonical `
|
|
50
|
+
One connection has one dispatcher containing multiple APIs. Duplicate registrations fail. Unknown API/method IDs return canonical `ApiEndpointNotFoundError`, distinct from a missing domain entity. Successful void is encoded explicitly as null. Receiver exceptions are logged then encoded with the same `ApiErrorCodec` used by the sender to reconstruct canonical errors.
|
|
51
51
|
|
|
52
52
|
`createScoped(Api, scope)` accepts an `IpcControllerScope<T>` whose `create(context)` supplies the implementation for that invocation. Inject a `clients.withContext(context)` proxy into this controller when it calls back or invokes another API. Concurrent calls have separate context objects and do not overwrite a global async context.
|
|
53
53
|
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@webpieces/ipc-bridge",
|
|
3
|
-
"version": "0.4.
|
|
3
|
+
"version": "0.4.763",
|
|
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.
|
|
25
|
+
"@webpieces/core-util": "0.4.763"
|
|
26
26
|
}
|
|
27
27
|
}
|
package/src/IpcClientFactory.js
CHANGED
|
@@ -28,7 +28,7 @@ class IpcClientFactory {
|
|
|
28
28
|
const context = this.connection.newContext(this.parent);
|
|
29
29
|
return ipc_1.IpcCallLogger.execute(this.logging, context, 'client', apiId, methodId, (0, ipc_1.getIpcMaskSpec)(apiClass, key) ?? new ipc_1.MaskSpec({}), request, async () => {
|
|
30
30
|
if (request === null || request === undefined)
|
|
31
|
-
throw new errors_1.
|
|
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
33
|
if (reply.type === 'failure')
|
|
34
34
|
throw errors_1.ApiErrorCodec.decode(reply.error);
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"IpcClientFactory.js","sourceRoot":"","sources":["../../../../../packages/core/ipc-bridge/src/IpcClientFactory.ts"],"names":[],"mappings":";;;AAAA,
|
|
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,OAAO,IAAI,gBAAgB,CAAC,IAAI,CAAC,UAAU,EAAE,IAAI,CAAC,OAAO,EAAE,OAAO,CAAC,CAAC;IACxE,CAAC;IAED,YAAY,CAAmB,QAAuB;QAClD,MAAM,KAAK,GAAG,IAAA,uBAAiB,EAAC,QAAQ,CAAC,CAAC;QAC1C,MAAM,SAAS,GAAG,IAAA,qBAAe,EAAC,QAAQ,CAAC,CAAC;QAC5C,0IAA0I;QAC1I,MAA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6CC;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"]}
|
package/src/IpcServerFactory.js
CHANGED
|
@@ -26,18 +26,18 @@ class IpcServerFactory {
|
|
|
26
26
|
register(apiClass, controller) {
|
|
27
27
|
const apiId = (0, ipc_1.assertInternalApi)(apiClass);
|
|
28
28
|
if (this.registrations.has(apiId))
|
|
29
|
-
throw new errors_1.
|
|
29
|
+
throw new errors_1.ApiImplementationError(`Duplicate IPC API registration: ${apiId}`);
|
|
30
30
|
const methods = new Map();
|
|
31
31
|
for (const [key, methodId] of Object.entries((0, ipc_1.getIpcEndpoints)(apiClass))) {
|
|
32
32
|
methods.set(methodId, new IpcRegistration(async (request) => {
|
|
33
33
|
// Logging wraps validation and invocation; only handle() below encodes exceptions.
|
|
34
34
|
return ipc_1.IpcCallLogger.execute(this.logging, request.context, 'server', apiId, methodId, (0, ipc_1.getIpcMaskSpec)(apiClass, key) ?? new ipc_1.MaskSpec({}), request.body, async () => {
|
|
35
35
|
if (request.body === null || request.body === undefined)
|
|
36
|
-
throw new errors_1.
|
|
36
|
+
throw new errors_1.ApiImplementationError('IPC requests require one non-null DTO');
|
|
37
37
|
const instance = controller(request.context);
|
|
38
38
|
const invoke = instance[key];
|
|
39
39
|
if (typeof invoke !== 'function')
|
|
40
|
-
throw new errors_1.
|
|
40
|
+
throw new errors_1.ApiImplementationError(`IPC implementation is missing ${apiId}.${methodId}`);
|
|
41
41
|
const result = await // webpieces-disable no-any-unknown -- untrusted IPC data is schema-validated; generic dispatch cannot assume a DTO type before validation
|
|
42
42
|
invoke.call(instance, request.body);
|
|
43
43
|
return result;
|
|
@@ -52,7 +52,7 @@ class IpcServerFactory {
|
|
|
52
52
|
try {
|
|
53
53
|
const method = this.registrations.get(request.apiId)?.get(request.methodId);
|
|
54
54
|
if (!method)
|
|
55
|
-
throw new errors_1.
|
|
55
|
+
throw new errors_1.ApiEndpointNotFoundError('Unknown IPC API or method');
|
|
56
56
|
const body = await method.invoke(request);
|
|
57
57
|
return new ipc_1.IpcSuccess(request.context, body === undefined ? null : body);
|
|
58
58
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"IpcServerFactory.js","sourceRoot":"","sources":["../../../../../packages/core/ipc-bridge/src/IpcServerFactory.ts"],"names":[],"mappings":";;;AAAA,
|
|
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;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,IA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C","sourcesContent":["import {\n ApiErrorCodec,\n ApiEndpointNotFoundError,\n ApiImplementationError,\n} from '@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 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, ApiErrorCodec.encode(error));\n }\n };\n}\n"]}
|