@adobe/data-rpc 0.10.11
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/LICENSE +21 -0
- package/README.md +159 -0
- package/dist/arg-async.test.d.ts +1 -0
- package/dist/arg-async.test.js +147 -0
- package/dist/arg-async.test.js.map +1 -0
- package/dist/arg-marshal.d.ts +34 -0
- package/dist/arg-marshal.js +90 -0
- package/dist/arg-marshal.js.map +1 -0
- package/dist/arg-observe.test.d.ts +1 -0
- package/dist/arg-observe.test.js +114 -0
- package/dist/arg-observe.test.js.map +1 -0
- package/dist/consume/caller-context.d.ts +47 -0
- package/dist/consume/caller-context.js +3 -0
- package/dist/consume/caller-context.js.map +1 -0
- package/dist/consume/make-generator.d.ts +16 -0
- package/dist/consume/make-generator.js +75 -0
- package/dist/consume/make-generator.js.map +1 -0
- package/dist/consume/make-observe.d.ts +16 -0
- package/dist/consume/make-observe.js +29 -0
- package/dist/consume/make-observe.js.map +1 -0
- package/dist/consume/make-promise.d.ts +12 -0
- package/dist/consume/make-promise.js +32 -0
- package/dist/consume/make-promise.js.map +1 -0
- package/dist/consume/make-void.d.ts +12 -0
- package/dist/consume/make-void.js +17 -0
- package/dist/consume/make-void.js.map +1 -0
- package/dist/consume/reconstruct-error.d.ts +7 -0
- package/dist/consume/reconstruct-error.js +14 -0
- package/dist/consume/reconstruct-error.js.map +1 -0
- package/dist/consume/synthesize-service.d.ts +10 -0
- package/dist/consume/synthesize-service.js +77 -0
- package/dist/consume/synthesize-service.js.map +1 -0
- package/dist/create-endpoint.d.ts +8 -0
- package/dist/create-endpoint.js +462 -0
- package/dist/create-endpoint.js.map +1 -0
- package/dist/endpoint.d.ts +64 -0
- package/dist/endpoint.js +3 -0
- package/dist/endpoint.js.map +1 -0
- package/dist/host/host-context.d.ts +28 -0
- package/dist/host/host-context.js +3 -0
- package/dist/host/host-context.js.map +1 -0
- package/dist/host/marshal-error.d.ts +8 -0
- package/dist/host/marshal-error.js +15 -0
- package/dist/host/marshal-error.js.map +1 -0
- package/dist/host/register-service.d.ts +10 -0
- package/dist/host/register-service.js +169 -0
- package/dist/host/register-service.js.map +1 -0
- package/dist/id.d.ts +7 -0
- package/dist/id.js +12 -0
- package/dist/id.js.map +1 -0
- package/dist/index.d.ts +7 -0
- package/dist/index.js +7 -0
- package/dist/index.js.map +1 -0
- package/dist/nested.test.d.ts +1 -0
- package/dist/nested.test.js +128 -0
- package/dist/nested.test.js.map +1 -0
- package/dist/protocol.d.ts +157 -0
- package/dist/protocol.js +18 -0
- package/dist/protocol.js.map +1 -0
- package/dist/review-fixes.test.d.ts +1 -0
- package/dist/review-fixes.test.js +200 -0
- package/dist/review-fixes.test.js.map +1 -0
- package/dist/rpc.test.d.ts +1 -0
- package/dist/rpc.test.js +250 -0
- package/dist/rpc.test.js.map +1 -0
- package/dist/transport.d.ts +32 -0
- package/dist/transport.js +3 -0
- package/dist/transport.js.map +1 -0
- package/dist/transports/loopback-transport.d.ts +13 -0
- package/dist/transports/loopback-transport.js +102 -0
- package/dist/transports/loopback-transport.js.map +1 -0
- package/dist/transports/loopback-transport.test.d.ts +1 -0
- package/dist/transports/loopback-transport.test.js +42 -0
- package/dist/transports/loopback-transport.test.js.map +1 -0
- package/dist/transports/message-port-transport.d.ts +14 -0
- package/dist/transports/message-port-transport.js +63 -0
- package/dist/transports/message-port-transport.js.map +1 -0
- package/dist/transports/message-port-transport.test.d.ts +1 -0
- package/dist/transports/message-port-transport.test.js +49 -0
- package/dist/transports/message-port-transport.test.js.map +1 -0
- package/dist/transports/window-transport.d.ts +20 -0
- package/dist/transports/window-transport.js +69 -0
- package/dist/transports/window-transport.js.map +1 -0
- package/dist/transports/window-transport.test.d.ts +1 -0
- package/dist/transports/window-transport.test.js +47 -0
- package/dist/transports/window-transport.test.js.map +1 -0
- package/package.json +38 -0
|
@@ -0,0 +1,169 @@
|
|
|
1
|
+
// © 2026 Adobe. MIT License. See /LICENSE for details.
|
|
2
|
+
import { validate } from "@adobe/data/schema";
|
|
3
|
+
import { isPureDataSchema } from "../arg-marshal.js";
|
|
4
|
+
import { reconstructError } from "../consume/reconstruct-error.js";
|
|
5
|
+
import { marshalError } from "./marshal-error.js";
|
|
6
|
+
/**
|
|
7
|
+
* Resolve an authorized, argument-validated member for an incoming request.
|
|
8
|
+
* `path` addresses the member from the service root, walking through any nested
|
|
9
|
+
* services. Returns the leaf member schema + callable, or an `RpcError`
|
|
10
|
+
* describing why it was refused (service not exposed, member absent, not
|
|
11
|
+
* permitted, or bad args).
|
|
12
|
+
*/
|
|
13
|
+
function resolve(ctx, service, path, args) {
|
|
14
|
+
const label = `${service}.${path.join(".")}`;
|
|
15
|
+
const exposed = ctx.exposed.get(service);
|
|
16
|
+
if (exposed === undefined) {
|
|
17
|
+
return { error: { name: "RpcError", message: `service "${service}" is not exposed` } };
|
|
18
|
+
}
|
|
19
|
+
if (path.length === 0) {
|
|
20
|
+
return { error: { name: "RpcError", message: `empty member path for service "${service}"` } };
|
|
21
|
+
}
|
|
22
|
+
if (!ctx.canInvoke(service, path.join("."))) {
|
|
23
|
+
return { error: { name: "RpcError", message: `"${label}" is not permitted` } };
|
|
24
|
+
}
|
|
25
|
+
// Walk the schema tree to the leaf member schema (through nested services).
|
|
26
|
+
// Own-property checks only, so a wire path can never reach an inherited member
|
|
27
|
+
// (e.g. `constructor`, `__proto__`) on the schema or the service object.
|
|
28
|
+
let memberSchema = exposed.schema;
|
|
29
|
+
for (const key of path) {
|
|
30
|
+
const props = memberSchema.properties;
|
|
31
|
+
if (props === undefined || !Object.prototype.hasOwnProperty.call(props, key)) {
|
|
32
|
+
return { error: { name: "RpcError", message: `service "${service}" has no member "${label}"` } };
|
|
33
|
+
}
|
|
34
|
+
memberSchema = props[key];
|
|
35
|
+
}
|
|
36
|
+
const params = memberSchema.signature?.parameters;
|
|
37
|
+
if (params !== undefined) {
|
|
38
|
+
const errors = [];
|
|
39
|
+
params.forEach((p, i) => {
|
|
40
|
+
if (i >= args.length)
|
|
41
|
+
errors.push(`missing required argument ${i} for "${label}"`);
|
|
42
|
+
// Only pure-Data params are validated; a param that carries an observe
|
|
43
|
+
// (an arg-observe ref on the wire) is not a validatable Data value.
|
|
44
|
+
else if (isPureDataSchema(p))
|
|
45
|
+
errors.push(...validate(p, args[i]));
|
|
46
|
+
});
|
|
47
|
+
if (errors.length > 0) {
|
|
48
|
+
return { error: { name: "RpcError", message: `invalid arguments for "${label}": ${errors.join("; ")}` } };
|
|
49
|
+
}
|
|
50
|
+
}
|
|
51
|
+
// Walk the service object tree to the leaf member (own properties only).
|
|
52
|
+
let target = exposed.service;
|
|
53
|
+
for (const key of path) {
|
|
54
|
+
if (target === null || typeof target !== "object" || !Object.prototype.hasOwnProperty.call(target, key)) {
|
|
55
|
+
return { error: { name: "RpcError", message: `service "${service}" has no member "${label}"` } };
|
|
56
|
+
}
|
|
57
|
+
target = target[key];
|
|
58
|
+
}
|
|
59
|
+
// Reconstruct any arg-observes into local Observes that pull from the caller.
|
|
60
|
+
const realArgs = ctx.unmarshalArgs(args, params);
|
|
61
|
+
return { memberSchema, target: target, args: realArgs };
|
|
62
|
+
}
|
|
63
|
+
/**
|
|
64
|
+
* Handle one incoming REQUEST message against the host's exposed services.
|
|
65
|
+
* Response/announcement kinds are handled elsewhere (the caller side); this
|
|
66
|
+
* covers get-schema, call, send, subscribe/unsubscribe, and the pull-based
|
|
67
|
+
* generator lifecycle. Returns `true` if the message was a host request it
|
|
68
|
+
* handled, `false` otherwise (so the endpoint can route it to the caller side).
|
|
69
|
+
*/
|
|
70
|
+
export function handleHostRequest(ctx, msg) {
|
|
71
|
+
switch (msg.kind) {
|
|
72
|
+
case "get-schema": {
|
|
73
|
+
const exposed = ctx.exposed.get(msg.service);
|
|
74
|
+
ctx.send({ kind: "schema", id: msg.id, service: msg.service, schema: exposed?.schema ?? null });
|
|
75
|
+
return true;
|
|
76
|
+
}
|
|
77
|
+
case "call": {
|
|
78
|
+
const r = resolve(ctx, msg.service, msg.path, msg.args);
|
|
79
|
+
if ("error" in r) {
|
|
80
|
+
ctx.send({ kind: "reject", id: msg.id, error: r.error });
|
|
81
|
+
return true;
|
|
82
|
+
}
|
|
83
|
+
const fn = r.target;
|
|
84
|
+
Promise.resolve()
|
|
85
|
+
.then(() => fn(...r.args))
|
|
86
|
+
.then((value) => ctx.send({ kind: "resolve", id: msg.id, value: value === undefined ? null : value }), (error) => ctx.send({ kind: "reject", id: msg.id, error: marshalError(error) }));
|
|
87
|
+
return true;
|
|
88
|
+
}
|
|
89
|
+
case "send": {
|
|
90
|
+
const r = resolve(ctx, msg.service, msg.path, msg.args);
|
|
91
|
+
if ("error" in r) {
|
|
92
|
+
ctx.onError(reconstructError(r.error));
|
|
93
|
+
return true;
|
|
94
|
+
}
|
|
95
|
+
// A void member's throw has no wire channel — surface it via onError.
|
|
96
|
+
try {
|
|
97
|
+
r.target(...r.args);
|
|
98
|
+
}
|
|
99
|
+
catch (error) {
|
|
100
|
+
ctx.onError(error);
|
|
101
|
+
}
|
|
102
|
+
return true;
|
|
103
|
+
}
|
|
104
|
+
case "subscribe": {
|
|
105
|
+
const r = resolve(ctx, msg.service, msg.path, msg.args);
|
|
106
|
+
if ("error" in r) {
|
|
107
|
+
// An observe has no error channel — surface the refusal via onError.
|
|
108
|
+
ctx.onError(reconstructError(r.error));
|
|
109
|
+
return true;
|
|
110
|
+
}
|
|
111
|
+
const observe = r.memberSchema.type === "observe"
|
|
112
|
+
? r.target
|
|
113
|
+
: r.target(...r.args);
|
|
114
|
+
const unobserve = observe((value) => ctx.send({ kind: "next", id: msg.id, value }));
|
|
115
|
+
ctx.hostSubs.set(msg.id, unobserve);
|
|
116
|
+
return true;
|
|
117
|
+
}
|
|
118
|
+
case "unsubscribe": {
|
|
119
|
+
ctx.hostSubs.get(msg.id)?.();
|
|
120
|
+
ctx.hostSubs.delete(msg.id);
|
|
121
|
+
return true;
|
|
122
|
+
}
|
|
123
|
+
case "iterate": {
|
|
124
|
+
const r = resolve(ctx, msg.service, msg.path, msg.args);
|
|
125
|
+
if ("error" in r) {
|
|
126
|
+
ctx.send({ kind: "throw", id: msg.id, error: r.error });
|
|
127
|
+
return true;
|
|
128
|
+
}
|
|
129
|
+
const gen = r.target(...r.args);
|
|
130
|
+
ctx.hostGens.set(msg.id, gen);
|
|
131
|
+
return true;
|
|
132
|
+
}
|
|
133
|
+
case "pull": {
|
|
134
|
+
const gen = ctx.hostGens.get(msg.id);
|
|
135
|
+
if (gen === undefined)
|
|
136
|
+
return true; // already returned / never iterated
|
|
137
|
+
gen.next().then((result) => {
|
|
138
|
+
if (result.done) {
|
|
139
|
+
ctx.hostGens.delete(msg.id);
|
|
140
|
+
ctx.send({ kind: "done", id: msg.id, value: result.value ?? undefined });
|
|
141
|
+
}
|
|
142
|
+
else {
|
|
143
|
+
ctx.send({ kind: "yield", id: msg.id, value: result.value });
|
|
144
|
+
}
|
|
145
|
+
}, (error) => {
|
|
146
|
+
ctx.hostGens.delete(msg.id);
|
|
147
|
+
ctx.send({ kind: "throw", id: msg.id, error: marshalError(error) });
|
|
148
|
+
});
|
|
149
|
+
return true;
|
|
150
|
+
}
|
|
151
|
+
case "return": {
|
|
152
|
+
const gen = ctx.hostGens.get(msg.id);
|
|
153
|
+
ctx.hostGens.delete(msg.id);
|
|
154
|
+
void gen?.return(undefined).catch((error) => ctx.onError(error));
|
|
155
|
+
return true;
|
|
156
|
+
}
|
|
157
|
+
case "raise": {
|
|
158
|
+
const gen = ctx.hostGens.get(msg.id);
|
|
159
|
+
ctx.hostGens.delete(msg.id);
|
|
160
|
+
void gen?.throw(reconstructError(msg.error)).catch(() => {
|
|
161
|
+
// The injected error propagating back out is expected; swallow it.
|
|
162
|
+
});
|
|
163
|
+
return true;
|
|
164
|
+
}
|
|
165
|
+
default:
|
|
166
|
+
return false;
|
|
167
|
+
}
|
|
168
|
+
}
|
|
169
|
+
//# sourceMappingURL=register-service.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"register-service.js","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
+
/**
|
|
2
|
+
* Creates a per-endpoint monotonic id allocator. Ids identify in-flight calls,
|
|
3
|
+
* subscriptions, and generators originated by THIS endpoint; they need only be
|
|
4
|
+
* unique per-originator (see the caller/host table split in `create-endpoint`),
|
|
5
|
+
* so a simple local counter suffices.
|
|
6
|
+
*/
|
|
7
|
+
export declare function createIdAllocator(): () => number;
|
package/dist/id.js
ADDED
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
// © 2026 Adobe. MIT License. See /LICENSE for details.
|
|
2
|
+
/**
|
|
3
|
+
* Creates a per-endpoint monotonic id allocator. Ids identify in-flight calls,
|
|
4
|
+
* subscriptions, and generators originated by THIS endpoint; they need only be
|
|
5
|
+
* unique per-originator (see the caller/host table split in `create-endpoint`),
|
|
6
|
+
* so a simple local counter suffices.
|
|
7
|
+
*/
|
|
8
|
+
export function createIdAllocator() {
|
|
9
|
+
let next = 1;
|
|
10
|
+
return () => next++;
|
|
11
|
+
}
|
|
12
|
+
//# sourceMappingURL=id.js.map
|
package/dist/id.js.map
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"id.js","sourceRoot":"","sources":["../src/id.ts"],"names":[],"mappings":"AAAA,uDAAuD;AAEvD;;;;;GAKG;AACH,MAAM,UAAU,iBAAiB;IAC7B,IAAI,IAAI,GAAG,CAAC,CAAC;IACb,OAAO,GAAG,EAAE,CAAC,IAAI,EAAE,CAAC;AACxB,CAAC"}
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
export { RPC_PROTOCOL_VERSION, type RpcMessage, type RpcError, type RpcRequestKind, type RpcResponseKind } from "./protocol.js";
|
|
2
|
+
export { type RpcTransport } from "./transport.js";
|
|
3
|
+
export { type RpcEndpoint, type RpcEndpointOptions } from "./endpoint.js";
|
|
4
|
+
export { createRpcEndpoint } from "./create-endpoint.js";
|
|
5
|
+
export { createRpcLoopbackTransport } from "./transports/loopback-transport.js";
|
|
6
|
+
export { createMessagePortTransport } from "./transports/message-port-transport.js";
|
|
7
|
+
export { createWindowTransport, type WindowTransportOptions } from "./transports/window-transport.js";
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
// © 2026 Adobe. MIT License. See /LICENSE for details.
|
|
2
|
+
export { RPC_PROTOCOL_VERSION } from "./protocol.js";
|
|
3
|
+
export { createRpcEndpoint } from "./create-endpoint.js";
|
|
4
|
+
export { createRpcLoopbackTransport } from "./transports/loopback-transport.js";
|
|
5
|
+
export { createMessagePortTransport } from "./transports/message-port-transport.js";
|
|
6
|
+
export { createWindowTransport } from "./transports/window-transport.js";
|
|
7
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,uDAAuD;AAEvD,OAAO,EAAE,oBAAoB,EAA6E,MAAM,eAAe,CAAC;AAGhI,OAAO,EAAE,iBAAiB,EAAE,MAAM,sBAAsB,CAAC;AACzD,OAAO,EAAE,0BAA0B,EAAE,MAAM,oCAAoC,CAAC;AAChF,OAAO,EAAE,0BAA0B,EAAE,MAAM,wCAAwC,CAAC;AACpF,OAAO,EAAE,qBAAqB,EAA+B,MAAM,kCAAkC,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,128 @@
|
|
|
1
|
+
// © 2026 Adobe. MIT License. See /LICENSE for details.
|
|
2
|
+
import { describe, it, expect } from "vitest";
|
|
3
|
+
import { Observe } from "@adobe/data/observe";
|
|
4
|
+
import { createRpcEndpoint } from "./create-endpoint.js";
|
|
5
|
+
import { createRpcLoopbackTransport } from "./transports/loopback-transport.js";
|
|
6
|
+
import { createMessagePortTransport } from "./transports/message-port-transport.js";
|
|
7
|
+
var ParentService;
|
|
8
|
+
(function (ParentService) {
|
|
9
|
+
ParentService.schema = {
|
|
10
|
+
type: "object",
|
|
11
|
+
properties: {
|
|
12
|
+
root: { type: "observe", value: { type: "number" } },
|
|
13
|
+
child: {
|
|
14
|
+
type: "object",
|
|
15
|
+
properties: {
|
|
16
|
+
value: { type: "observe", value: { type: "number" } },
|
|
17
|
+
add: { type: "function", signature: { parameters: [{ type: "number" }, { type: "number" }], returns: { type: "promise", value: { type: "number" } } } },
|
|
18
|
+
stream: { type: "function", signature: { parameters: [{ type: "number" }], returns: { type: "generator", value: { type: "number" } } } },
|
|
19
|
+
bump: { type: "function" },
|
|
20
|
+
deep: {
|
|
21
|
+
type: "object",
|
|
22
|
+
properties: {
|
|
23
|
+
greet: { type: "function", signature: { parameters: [{ type: "string" }], returns: { type: "promise", value: { type: "string" } } } },
|
|
24
|
+
},
|
|
25
|
+
required: ["greet"],
|
|
26
|
+
additionalProperties: false,
|
|
27
|
+
},
|
|
28
|
+
},
|
|
29
|
+
required: ["value", "add", "stream", "bump", "deep"],
|
|
30
|
+
additionalProperties: false,
|
|
31
|
+
},
|
|
32
|
+
},
|
|
33
|
+
required: ["root", "child"],
|
|
34
|
+
additionalProperties: false,
|
|
35
|
+
};
|
|
36
|
+
})(ParentService || (ParentService = {}));
|
|
37
|
+
function makeParent(seed) {
|
|
38
|
+
const [root] = Observe.createState(seed);
|
|
39
|
+
const [value, setValue] = Observe.createState(seed * 10);
|
|
40
|
+
let current = seed * 10;
|
|
41
|
+
const stats = { streamFinally: 0 };
|
|
42
|
+
const service = {
|
|
43
|
+
serviceName: `parent-${seed}`,
|
|
44
|
+
schema: Observe.fromConstant(ParentService.schema),
|
|
45
|
+
root,
|
|
46
|
+
child: {
|
|
47
|
+
value,
|
|
48
|
+
add: async (a, b) => a + b,
|
|
49
|
+
stream: async function* (to) {
|
|
50
|
+
try {
|
|
51
|
+
for (let i = 1; i <= to; i++)
|
|
52
|
+
yield i;
|
|
53
|
+
}
|
|
54
|
+
finally {
|
|
55
|
+
stats.streamFinally++;
|
|
56
|
+
}
|
|
57
|
+
},
|
|
58
|
+
bump: () => setValue((current += 1)),
|
|
59
|
+
deep: {
|
|
60
|
+
greet: async (name) => `hello ${name}`,
|
|
61
|
+
},
|
|
62
|
+
},
|
|
63
|
+
};
|
|
64
|
+
return { service, stats };
|
|
65
|
+
}
|
|
66
|
+
const flush = async (times = 8) => {
|
|
67
|
+
for (let i = 0; i < times; i++)
|
|
68
|
+
await new Promise((r) => setTimeout(r, 0));
|
|
69
|
+
};
|
|
70
|
+
describe("nested services", () => {
|
|
71
|
+
it("shims nested members on both sides and round-trips every kind", async () => {
|
|
72
|
+
const { a, b } = createRpcLoopbackTransport();
|
|
73
|
+
const ea = createRpcEndpoint(a);
|
|
74
|
+
const eb = createRpcEndpoint(b);
|
|
75
|
+
const host = makeParent(3);
|
|
76
|
+
ea.expose("parent", host.service, ParentService.schema);
|
|
77
|
+
const parent = eb.consume("parent", ParentService.schema);
|
|
78
|
+
// nested promise + doubly-nested promise
|
|
79
|
+
expect(await parent.child.add(2, 3)).toBe(5);
|
|
80
|
+
expect(await parent.child.deep.greet("world")).toBe("hello world");
|
|
81
|
+
// nested generator
|
|
82
|
+
const out = [];
|
|
83
|
+
for await (const n of parent.child.stream(3))
|
|
84
|
+
out.push(n);
|
|
85
|
+
expect(out).toEqual([1, 2, 3]);
|
|
86
|
+
expect(host.stats.streamFinally).toBe(1);
|
|
87
|
+
// nested observe + nested void mutation
|
|
88
|
+
const seen = [];
|
|
89
|
+
const un = parent.child.value((v) => seen.push(v));
|
|
90
|
+
await flush();
|
|
91
|
+
expect(seen).toEqual([30]); // seed*10
|
|
92
|
+
parent.child.bump();
|
|
93
|
+
await flush();
|
|
94
|
+
expect(seen).toEqual([30, 31]);
|
|
95
|
+
un();
|
|
96
|
+
// top-level observe still works alongside the nested tree
|
|
97
|
+
let rootSeen;
|
|
98
|
+
const un2 = parent.root((v) => { rootSeen = v; });
|
|
99
|
+
await flush();
|
|
100
|
+
expect(rootSeen).toBe(3);
|
|
101
|
+
un2();
|
|
102
|
+
ea.close();
|
|
103
|
+
eb.close();
|
|
104
|
+
});
|
|
105
|
+
it("rejects a nested call with invalid arguments (path-addressed validation)", async () => {
|
|
106
|
+
const { a, b } = createRpcLoopbackTransport();
|
|
107
|
+
const ea = createRpcEndpoint(a);
|
|
108
|
+
const eb = createRpcEndpoint(b);
|
|
109
|
+
ea.expose("parent", makeParent(1).service, ParentService.schema);
|
|
110
|
+
const parent = eb.consume("parent", ParentService.schema);
|
|
111
|
+
const untyped = parent;
|
|
112
|
+
await expect(untyped.child.add("nope", 2)).rejects.toThrowError(/invalid arguments.*parent\.child\.add/);
|
|
113
|
+
ea.close();
|
|
114
|
+
eb.close();
|
|
115
|
+
});
|
|
116
|
+
it("addresses nested members over a real MessageChannel (the iframe transport)", async () => {
|
|
117
|
+
const { port1, port2 } = new MessageChannel();
|
|
118
|
+
const ea = createRpcEndpoint(createMessagePortTransport(port1));
|
|
119
|
+
const eb = createRpcEndpoint(createMessagePortTransport(port2));
|
|
120
|
+
ea.expose("parent", makeParent(2).service, ParentService.schema);
|
|
121
|
+
const parent = eb.consume("parent", ParentService.schema);
|
|
122
|
+
expect(await parent.child.deep.greet("port")).toBe("hello port");
|
|
123
|
+
expect(await parent.child.add(20, 22)).toBe(42);
|
|
124
|
+
ea.close();
|
|
125
|
+
eb.close();
|
|
126
|
+
});
|
|
127
|
+
});
|
|
128
|
+
//# sourceMappingURL=nested.test.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"nested.test.js","sourceRoot":"","sources":["../src/nested.test.ts"],"names":[],"mappings":"AAAA,uDAAuD;AAEvD,OAAO,EAAE,QAAQ,EAAE,EAAE,EAAE,MAAM,EAAE,MAAM,QAAQ,CAAC;AAC9C,OAAO,EAAE,OAAO,EAAE,MAAM,qBAAqB,CAAC;AAI9C,OAAO,EAAE,iBAAiB,EAAE,MAAM,sBAAsB,CAAC;AACzD,OAAO,EAAE,0BAA0B,EAAE,MAAM,oCAAoC,CAAC;AAChF,OAAO,EAAE,0BAA0B,EAAE,MAAM,wCAAwC,CAAC;AA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,aAAa,CAAC,MAAM,CAAC,CAAC;QAE1D,MAAM,CAAC,MAAM,MAAM,CAAC,KAAK,CAAC,IAAI,CAAC,KAAK,CAAC,MAAM,CAAC,CAAC,CAAC,IAAI,CAAC,YAAY,CAAC,CAAC;QACjE,MAAM,CAAC,MAAM,MAAM,CAAC,KAAK,CAAC,GAAG,CAAC,EAAE,EAAE,EAAE,CAAC,CAAC,CAAC,IAAI,CAAC,EAAE,CAAC,CAAC;QAEhD,EAAE,CAAC,KAAK,EAAE,CAAC;QACX,EAAE,CAAC,KAAK,EAAE,CAAC;IACf,CAAC,CAAC,CAAC;AACP,CAAC,CAAC,CAAC"}
|
|
@@ -0,0 +1,157 @@
|
|
|
1
|
+
import type { Data } from "@adobe/data";
|
|
2
|
+
import type { Schema } from "@adobe/data/schema";
|
|
3
|
+
/**
|
|
4
|
+
* The wire protocol for `@adobe/data-rpc`.
|
|
5
|
+
*
|
|
6
|
+
* Every payload that crosses the boundary is `Data` (JSON + Set/Map/Blob) — never
|
|
7
|
+
* an `Observe`, `Promise`, `AsyncGenerator`, or function. The far side synthesizes
|
|
8
|
+
* equivalent-shaped members locally; only their `Data` values travel. A service
|
|
9
|
+
* gated on `AsyncDataService.IsValid` provably contains nothing else to marshal.
|
|
10
|
+
*
|
|
11
|
+
* The channel is symmetric: both endpoints originate requests. Direction is
|
|
12
|
+
* implicit in the message `kind` — the request and response kind sets are
|
|
13
|
+
* disjoint — so an `id` need only be unique per-originator. Each endpoint keeps
|
|
14
|
+
* SEPARATE caller-side and host-side pending tables; the same numeric id may be
|
|
15
|
+
* live in both directions at once with no cross-talk.
|
|
16
|
+
*/
|
|
17
|
+
/** Bumped when the wire shape changes incompatibly; peers exchange it in the handshake. */
|
|
18
|
+
export declare const RPC_PROTOCOL_VERSION = 1;
|
|
19
|
+
/**
|
|
20
|
+
* Serialized form of a thrown value. We never structured-clone the thrown value
|
|
21
|
+
* itself (that drops the subclass prototype and non-standard props); the host
|
|
22
|
+
* captures these three fields and the caller reconstructs a plain `Error`.
|
|
23
|
+
*/
|
|
24
|
+
export interface RpcError {
|
|
25
|
+
readonly name: string;
|
|
26
|
+
readonly message: string;
|
|
27
|
+
readonly stack?: string;
|
|
28
|
+
}
|
|
29
|
+
/** REQUEST kinds — always sent by the calling side toward the hosting side. */
|
|
30
|
+
export type RpcRequestKind = "hello" | "get-schema" | "call" | "send" | "subscribe" | "unsubscribe" | "iterate" | "pull" | "return" | "raise";
|
|
31
|
+
/** RESPONSE / announcement kinds — always sent by the hosting side toward the caller. */
|
|
32
|
+
export type RpcResponseKind = "welcome" | "available" | "unavailable" | "schema" | "resolve" | "reject" | "next" | "yield" | "done" | "throw";
|
|
33
|
+
export type RpcMessage = {
|
|
34
|
+
readonly kind: "hello";
|
|
35
|
+
readonly protocol: number;
|
|
36
|
+
} | {
|
|
37
|
+
readonly kind: "welcome";
|
|
38
|
+
readonly protocol: number;
|
|
39
|
+
} | {
|
|
40
|
+
readonly kind: "available";
|
|
41
|
+
readonly service: string;
|
|
42
|
+
readonly schema: Schema;
|
|
43
|
+
} | {
|
|
44
|
+
readonly kind: "unavailable";
|
|
45
|
+
readonly service: string;
|
|
46
|
+
} | {
|
|
47
|
+
readonly kind: "get-schema";
|
|
48
|
+
readonly id: number;
|
|
49
|
+
readonly service: string;
|
|
50
|
+
} | {
|
|
51
|
+
readonly kind: "schema";
|
|
52
|
+
readonly id: number;
|
|
53
|
+
readonly service: string;
|
|
54
|
+
readonly schema: Schema | null;
|
|
55
|
+
} | {
|
|
56
|
+
readonly kind: "call";
|
|
57
|
+
readonly id: number;
|
|
58
|
+
readonly service: string;
|
|
59
|
+
readonly path: readonly string[];
|
|
60
|
+
readonly args: readonly Data[];
|
|
61
|
+
} | {
|
|
62
|
+
readonly kind: "resolve";
|
|
63
|
+
readonly id: number;
|
|
64
|
+
readonly value: Data;
|
|
65
|
+
} | {
|
|
66
|
+
readonly kind: "reject";
|
|
67
|
+
readonly id: number;
|
|
68
|
+
readonly error: RpcError;
|
|
69
|
+
} | {
|
|
70
|
+
readonly kind: "send";
|
|
71
|
+
readonly id: number;
|
|
72
|
+
readonly service: string;
|
|
73
|
+
readonly path: readonly string[];
|
|
74
|
+
readonly args: readonly Data[];
|
|
75
|
+
} | {
|
|
76
|
+
readonly kind: "subscribe";
|
|
77
|
+
readonly id: number;
|
|
78
|
+
readonly service: string;
|
|
79
|
+
readonly path: readonly string[];
|
|
80
|
+
readonly args: readonly Data[];
|
|
81
|
+
} | {
|
|
82
|
+
readonly kind: "next";
|
|
83
|
+
readonly id: number;
|
|
84
|
+
readonly value: Data;
|
|
85
|
+
} | {
|
|
86
|
+
readonly kind: "unsubscribe";
|
|
87
|
+
readonly id: number;
|
|
88
|
+
} | {
|
|
89
|
+
readonly kind: "iterate";
|
|
90
|
+
readonly id: number;
|
|
91
|
+
readonly service: string;
|
|
92
|
+
readonly path: readonly string[];
|
|
93
|
+
readonly args: readonly Data[];
|
|
94
|
+
} | {
|
|
95
|
+
readonly kind: "pull";
|
|
96
|
+
readonly id: number;
|
|
97
|
+
} | {
|
|
98
|
+
readonly kind: "yield";
|
|
99
|
+
readonly id: number;
|
|
100
|
+
readonly value: Data;
|
|
101
|
+
} | {
|
|
102
|
+
readonly kind: "done";
|
|
103
|
+
readonly id: number;
|
|
104
|
+
readonly value?: Data;
|
|
105
|
+
} | {
|
|
106
|
+
readonly kind: "throw";
|
|
107
|
+
readonly id: number;
|
|
108
|
+
readonly error: RpcError;
|
|
109
|
+
} | {
|
|
110
|
+
readonly kind: "return";
|
|
111
|
+
readonly id: number;
|
|
112
|
+
} | {
|
|
113
|
+
readonly kind: "raise";
|
|
114
|
+
readonly id: number;
|
|
115
|
+
readonly error: RpcError;
|
|
116
|
+
} | {
|
|
117
|
+
readonly kind: "arg-subscribe";
|
|
118
|
+
readonly ref: number;
|
|
119
|
+
readonly sub: number;
|
|
120
|
+
} | {
|
|
121
|
+
readonly kind: "arg-next";
|
|
122
|
+
readonly sub: number;
|
|
123
|
+
readonly value: Data;
|
|
124
|
+
} | {
|
|
125
|
+
readonly kind: "arg-unsubscribe";
|
|
126
|
+
readonly sub: number;
|
|
127
|
+
} | {
|
|
128
|
+
readonly kind: "arg-resolve";
|
|
129
|
+
readonly ref: number;
|
|
130
|
+
readonly value: Data;
|
|
131
|
+
} | {
|
|
132
|
+
readonly kind: "arg-reject";
|
|
133
|
+
readonly ref: number;
|
|
134
|
+
readonly error: RpcError;
|
|
135
|
+
} | {
|
|
136
|
+
readonly kind: "arg-pull";
|
|
137
|
+
readonly ref: number;
|
|
138
|
+
} | {
|
|
139
|
+
readonly kind: "arg-yield";
|
|
140
|
+
readonly ref: number;
|
|
141
|
+
readonly value: Data;
|
|
142
|
+
} | {
|
|
143
|
+
readonly kind: "arg-done";
|
|
144
|
+
readonly ref: number;
|
|
145
|
+
readonly value?: Data;
|
|
146
|
+
} | {
|
|
147
|
+
readonly kind: "arg-throw";
|
|
148
|
+
readonly ref: number;
|
|
149
|
+
readonly error: RpcError;
|
|
150
|
+
} | {
|
|
151
|
+
readonly kind: "arg-return";
|
|
152
|
+
readonly ref: number;
|
|
153
|
+
} | {
|
|
154
|
+
readonly kind: "arg-raise";
|
|
155
|
+
readonly ref: number;
|
|
156
|
+
readonly error: RpcError;
|
|
157
|
+
};
|
package/dist/protocol.js
ADDED
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
// © 2026 Adobe. MIT License. See /LICENSE for details.
|
|
2
|
+
/**
|
|
3
|
+
* The wire protocol for `@adobe/data-rpc`.
|
|
4
|
+
*
|
|
5
|
+
* Every payload that crosses the boundary is `Data` (JSON + Set/Map/Blob) — never
|
|
6
|
+
* an `Observe`, `Promise`, `AsyncGenerator`, or function. The far side synthesizes
|
|
7
|
+
* equivalent-shaped members locally; only their `Data` values travel. A service
|
|
8
|
+
* gated on `AsyncDataService.IsValid` provably contains nothing else to marshal.
|
|
9
|
+
*
|
|
10
|
+
* The channel is symmetric: both endpoints originate requests. Direction is
|
|
11
|
+
* implicit in the message `kind` — the request and response kind sets are
|
|
12
|
+
* disjoint — so an `id` need only be unique per-originator. Each endpoint keeps
|
|
13
|
+
* SEPARATE caller-side and host-side pending tables; the same numeric id may be
|
|
14
|
+
* live in both directions at once with no cross-talk.
|
|
15
|
+
*/
|
|
16
|
+
/** Bumped when the wire shape changes incompatibly; peers exchange it in the handshake. */
|
|
17
|
+
export const RPC_PROTOCOL_VERSION = 1;
|
|
18
|
+
//# sourceMappingURL=protocol.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"protocol.js","sourceRoot":"","sources":["../src/protocol.ts"],"names":[],"mappings":"AAAA,uDAAuD;AAKvD;;;;;;;;;;;;;GAaG;AAEH,2FAA2F;AAC3F,MAAM,CAAC,MAAM,oBAAoB,GAAG,CAAC,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|