@vscode/component-explorer 0.2.1-17 → 0.2.1-171
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 +198 -27
- package/dist/browserDaemonClient-AB8d4x2O.js +3465 -0
- package/dist/browserDaemonClient-AB8d4x2O.js.map +1 -0
- package/dist/components/BottomDebugPanel.d.ts +8 -0
- package/dist/components/BottomDebugPanel.d.ts.map +1 -0
- package/dist/components/DebugPanelPlacement.d.ts +3 -0
- package/dist/components/DebugPanelPlacement.d.ts.map +1 -0
- package/dist/components/DebugWorkbench.d.ts +42 -0
- package/dist/components/DebugWorkbench.d.ts.map +1 -0
- package/dist/components/DebugWorkbenchLayout.d.ts +30 -0
- package/dist/components/DebugWorkbenchLayout.d.ts.map +1 -0
- package/dist/components/DebugWorkbenchState.d.ts +31 -0
- package/dist/components/DebugWorkbenchState.d.ts.map +1 -0
- package/dist/components/ExplorerModel.d.ts +28 -5
- package/dist/components/ExplorerModel.d.ts.map +1 -1
- package/dist/components/FixtureDebugStore.d.ts +20 -0
- package/dist/components/FixtureDebugStore.d.ts.map +1 -0
- package/dist/components/FixturePreviewItem.d.ts +11 -0
- package/dist/components/FixturePreviewItem.d.ts.map +1 -1
- package/dist/components/LeftSidebar.d.ts.map +1 -1
- package/dist/components/PageViewportState.d.ts +34 -0
- package/dist/components/PageViewportState.d.ts.map +1 -0
- package/dist/components/PreviewArea.d.ts.map +1 -1
- package/dist/components/RightSidebar.d.ts +8 -2
- package/dist/components/RightSidebar.d.ts.map +1 -1
- package/dist/components/TitleBar.d.ts.map +1 -1
- package/dist/components/TreeView.d.ts +3 -1
- package/dist/components/TreeView.d.ts.map +1 -1
- package/dist/components/favoriteFixtures.d.ts +4 -0
- package/dist/components/favoriteFixtures.d.ts.map +1 -0
- package/dist/components/icons.d.ts +12 -8
- package/dist/components/icons.d.ts.map +1 -1
- package/dist/components/types.d.ts +2 -0
- package/dist/components/types.d.ts.map +1 -1
- package/dist/core/ComponentRenderer.d.ts +26 -3
- package/dist/core/ComponentRenderer.d.ts.map +1 -1
- package/dist/core/ErrorInfo.d.ts +21 -1
- package/dist/core/ErrorInfo.d.ts.map +1 -1
- package/dist/core/FixtureInputStore.d.ts +32 -0
- package/dist/core/FixtureInputStore.d.ts.map +1 -0
- package/dist/core/FixtureInteractionRuntime.d.ts +30 -0
- package/dist/core/FixtureInteractionRuntime.d.ts.map +1 -0
- package/dist/core/FixtureNode.d.ts.map +1 -1
- package/dist/core/FixtureRegistry.d.ts +2 -0
- package/dist/core/FixtureRegistry.d.ts.map +1 -1
- package/dist/core/RenderTimeout.d.ts +39 -0
- package/dist/core/RenderTimeout.d.ts.map +1 -0
- package/dist/core/fixtureApi.d.ts +234 -32
- package/dist/core/fixtureApi.d.ts.map +1 -1
- package/dist/core/fixtureApiConsumer.d.ts +22 -2
- package/dist/core/fixtureApiConsumer.d.ts.map +1 -1
- package/dist/core/index.d.ts +7 -3
- package/dist/core/index.d.ts.map +1 -1
- package/dist/core/inputAggregation.d.ts +31 -0
- package/dist/core/inputAggregation.d.ts.map +1 -0
- package/dist/daemon/DaemonConfig.d.ts +0 -2
- package/dist/daemon/DaemonConfig.d.ts.map +1 -1
- package/dist/daemon/DaemonModel.d.ts +12 -6
- package/dist/daemon/DaemonModel.d.ts.map +1 -1
- package/dist/daemon/browserDaemonClient.d.ts +3 -0
- package/dist/daemon/browserDaemonClient.d.ts.map +1 -0
- package/dist/fixtureApi.d-DjVuiRlO.d.ts +533 -0
- package/dist/index.d.ts +53 -10
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +11 -9
- package/dist/lib/explorerQueryParams.d.ts +2 -2
- package/dist/lib/explorerQueryParams.d.ts.map +1 -1
- package/dist/lib/fixtureSizeCache.d.ts +2 -0
- package/dist/lib/fixtureSizeCache.d.ts.map +1 -1
- package/dist/modes/EmbeddedMode.d.ts +7 -0
- package/dist/modes/EmbeddedMode.d.ts.map +1 -1
- package/dist/modes/ExplorerUIMode.d.ts +1 -1
- package/dist/modes/ExplorerUIMode.d.ts.map +1 -1
- package/dist/modes/HeadlessMode.d.ts +12 -3
- package/dist/modes/HeadlessMode.d.ts.map +1 -1
- package/dist/{runtimeVersion-DMb19DDZ.js → runtimeVersion-B2GU8TAG.js} +80 -39
- package/dist/runtimeVersion-B2GU8TAG.js.map +1 -0
- package/dist/viewer.d.ts +2900 -24
- package/dist/viewer.d.ts.map +1 -1
- package/dist/viewer.js +5596 -2332
- package/dist/viewer.js.map +1 -1
- package/package.json +10 -6
- package/dist/core/PropertySchema.d.ts +0 -40
- package/dist/core/PropertySchema.d.ts.map +0 -1
- package/dist/runtimeVersion-DMb19DDZ.js.map +0 -1
|
@@ -0,0 +1,3465 @@
|
|
|
1
|
+
var Ut = Object.defineProperty;
|
|
2
|
+
var Bt = (t, e, r) => e in t ? Ut(t, e, { enumerable: !0, configurable: !0, writable: !0, value: r }) : t[e] = r;
|
|
3
|
+
var l = (t, e, r) => Bt(t, typeof e != "symbol" ? e + "" : e, r);
|
|
4
|
+
import { object as v, optional as g, unknown as V, string as u, enum as B, union as K, number as P, void as Ge, array as T, int as Y, nonnegative as X, strictObject as pe, literal as ie, record as wt, boolean as se, positive as Kt } from "zod/mini";
|
|
5
|
+
import { safeParse as z, toJSONSchema as Jt } from "zod/v4/core";
|
|
6
|
+
import { z as d } from "zod";
|
|
7
|
+
const Ft = /* @__PURE__ */ new Set([
|
|
8
|
+
"type",
|
|
9
|
+
"format",
|
|
10
|
+
"properties",
|
|
11
|
+
"required",
|
|
12
|
+
"additionalProperties",
|
|
13
|
+
"items",
|
|
14
|
+
"prefixItems",
|
|
15
|
+
"const",
|
|
16
|
+
"enum",
|
|
17
|
+
"anyOf",
|
|
18
|
+
"oneOf",
|
|
19
|
+
"discriminator",
|
|
20
|
+
"$ref",
|
|
21
|
+
"title",
|
|
22
|
+
"description"
|
|
23
|
+
]);
|
|
24
|
+
function C(t) {
|
|
25
|
+
if (t === !0 || t === !1) return t;
|
|
26
|
+
if (t === null || typeof t != "object") throw new Error(`normalizeJsonSchema: expected object, got ${typeof t}`);
|
|
27
|
+
if (Array.isArray(t)) throw new Error("normalizeJsonSchema: expected object, got array");
|
|
28
|
+
const e = t;
|
|
29
|
+
if ("not" in e && Vt(e.not)) return !1;
|
|
30
|
+
if (Array.isArray(e.type)) {
|
|
31
|
+
const s = e.type;
|
|
32
|
+
if (s.length === 0 || new Set(s).size !== s.length || s.some((a) => ![
|
|
33
|
+
"null",
|
|
34
|
+
"boolean",
|
|
35
|
+
"number",
|
|
36
|
+
"integer",
|
|
37
|
+
"string",
|
|
38
|
+
"array",
|
|
39
|
+
"object"
|
|
40
|
+
].includes(a))) throw new Error("normalizeJsonSchema: type array must contain distinct JSON Schema type names");
|
|
41
|
+
const { title: n, description: o, ...i } = e;
|
|
42
|
+
return C({
|
|
43
|
+
title: n,
|
|
44
|
+
description: o,
|
|
45
|
+
anyOf: s.map((a) => {
|
|
46
|
+
const c = {
|
|
47
|
+
...i,
|
|
48
|
+
type: a
|
|
49
|
+
};
|
|
50
|
+
return a !== "object" && (delete c.properties, delete c.required, delete c.additionalProperties), a !== "array" && (delete c.items, delete c.prefixItems), a !== "string" && a !== "number" && a !== "integer" && delete c.format, c;
|
|
51
|
+
})
|
|
52
|
+
});
|
|
53
|
+
}
|
|
54
|
+
const r = {};
|
|
55
|
+
for (const [s, n] of Object.entries(e)) {
|
|
56
|
+
if (!Ft.has(s)) continue;
|
|
57
|
+
const o = Gt(s, n);
|
|
58
|
+
o !== void 0 && (r[s] = o);
|
|
59
|
+
}
|
|
60
|
+
if (r.type === "object" && !("additionalProperties" in r) && (r.additionalProperties = !1), Array.isArray(r.oneOf) && !("discriminator" in r)) {
|
|
61
|
+
const s = Yt(r.oneOf);
|
|
62
|
+
s !== void 0 && (r.discriminator = s);
|
|
63
|
+
}
|
|
64
|
+
return "discriminator" in r && !Array.isArray(r.oneOf) && delete r.discriminator, Object.keys(r).length === 0 ? !0 : r;
|
|
65
|
+
}
|
|
66
|
+
function Gt(t, e) {
|
|
67
|
+
switch (t) {
|
|
68
|
+
case "properties": {
|
|
69
|
+
if (!Ie(e)) return {};
|
|
70
|
+
const r = {};
|
|
71
|
+
for (const [s, n] of Object.entries(e)) r[s] = C(n);
|
|
72
|
+
return r;
|
|
73
|
+
}
|
|
74
|
+
case "items":
|
|
75
|
+
case "additionalProperties":
|
|
76
|
+
return e === !1 ? !1 : C(e);
|
|
77
|
+
case "prefixItems":
|
|
78
|
+
case "anyOf":
|
|
79
|
+
case "oneOf":
|
|
80
|
+
return Array.isArray(e) ? e.map((r) => C(r)) : [];
|
|
81
|
+
case "discriminator": {
|
|
82
|
+
if (!Ie(e)) return;
|
|
83
|
+
const r = e.propertyName;
|
|
84
|
+
return typeof r != "string" || r.length === 0 ? void 0 : { propertyName: r };
|
|
85
|
+
}
|
|
86
|
+
case "enum":
|
|
87
|
+
return Array.isArray(e) ? e.slice() : [];
|
|
88
|
+
case "required":
|
|
89
|
+
return Array.isArray(e) ? e.slice().sort() : [];
|
|
90
|
+
default:
|
|
91
|
+
return e;
|
|
92
|
+
}
|
|
93
|
+
}
|
|
94
|
+
function Vt(t) {
|
|
95
|
+
return Ie(t) && Object.keys(t).length === 0;
|
|
96
|
+
}
|
|
97
|
+
function Ie(t) {
|
|
98
|
+
return t !== null && typeof t == "object" && !Array.isArray(t);
|
|
99
|
+
}
|
|
100
|
+
function Yt(t) {
|
|
101
|
+
if (t.length < 2) return;
|
|
102
|
+
const e = [];
|
|
103
|
+
for (const s of t) {
|
|
104
|
+
if (s === !0 || s === !1 || s.type !== "object") return;
|
|
105
|
+
const n = s.properties;
|
|
106
|
+
if (!n) return;
|
|
107
|
+
e.push(n);
|
|
108
|
+
}
|
|
109
|
+
let r = Ve(e[0]);
|
|
110
|
+
for (let s = 1; s < e.length; s++)
|
|
111
|
+
if (r = r.filter((n) => Ve(e[s]).includes(n)), r.length === 0) return;
|
|
112
|
+
for (const s of r) {
|
|
113
|
+
const n = /* @__PURE__ */ new Set();
|
|
114
|
+
let o = !0;
|
|
115
|
+
for (const i of e) {
|
|
116
|
+
const a = i[s], c = JSON.stringify(a.const);
|
|
117
|
+
if (n.has(c)) {
|
|
118
|
+
o = !1;
|
|
119
|
+
break;
|
|
120
|
+
}
|
|
121
|
+
n.add(c);
|
|
122
|
+
}
|
|
123
|
+
if (o) return { propertyName: s };
|
|
124
|
+
}
|
|
125
|
+
}
|
|
126
|
+
function Ve(t) {
|
|
127
|
+
const e = [];
|
|
128
|
+
for (const [r, s] of Object.entries(t))
|
|
129
|
+
s === !0 || s === !1 || "const" in s && e.push(r);
|
|
130
|
+
return e;
|
|
131
|
+
}
|
|
132
|
+
const Qt = Symbol("linkrpc.rpcFailure");
|
|
133
|
+
var bt, Ye = (bt = Qt, class {
|
|
134
|
+
constructor(t) {
|
|
135
|
+
l(this, "error");
|
|
136
|
+
l(this, bt, !0);
|
|
137
|
+
this.error = t, Object.freeze(this);
|
|
138
|
+
}
|
|
139
|
+
});
|
|
140
|
+
const R = {
|
|
141
|
+
/** Default code for named LinkRPC application errors. */
|
|
142
|
+
applicationError: 1,
|
|
143
|
+
parseError: -32700,
|
|
144
|
+
invalidRequest: -32600,
|
|
145
|
+
methodNotFound: -32601,
|
|
146
|
+
invalidParams: -32602,
|
|
147
|
+
internalError: -32603,
|
|
148
|
+
/** Caller is authenticated but lacks a capability covering the call. */
|
|
149
|
+
permissionRequired: -32401,
|
|
150
|
+
/** The peer a request was routed to detached before it could respond. */
|
|
151
|
+
peerDisconnected: -32402,
|
|
152
|
+
/** The request exceeded the hub's idle timeout with no stream activity. */
|
|
153
|
+
requestTimeout: -32403,
|
|
154
|
+
/** The request was cancelled (by the caller, or by the hub on disconnect). */
|
|
155
|
+
cancelled: -32800
|
|
156
|
+
};
|
|
157
|
+
function yt(t) {
|
|
158
|
+
return typeof t.method == "string" && t.id !== void 0;
|
|
159
|
+
}
|
|
160
|
+
function Se(t) {
|
|
161
|
+
return typeof t.method == "string" && t.id === void 0;
|
|
162
|
+
}
|
|
163
|
+
function ke(t) {
|
|
164
|
+
return typeof t.method != "string";
|
|
165
|
+
}
|
|
166
|
+
const It = Symbol("linkrpc.applicationError");
|
|
167
|
+
function Qe(t) {
|
|
168
|
+
return Object.freeze(Object.defineProperty(t, It, { value: !0 }));
|
|
169
|
+
}
|
|
170
|
+
const Xt = /* @__PURE__ */ new WeakMap();
|
|
171
|
+
function Zt(t) {
|
|
172
|
+
return `/${String(t).replace(/~/g, "~0").replace(/\//g, "~1")}`;
|
|
173
|
+
}
|
|
174
|
+
const Xe = /* @__PURE__ */ new WeakMap();
|
|
175
|
+
function St(t, e) {
|
|
176
|
+
return tr(t.bodySchema ?? er(t), e);
|
|
177
|
+
}
|
|
178
|
+
function er(t) {
|
|
179
|
+
let e = Xe.get(t);
|
|
180
|
+
if (e === void 0) {
|
|
181
|
+
const r = t.dataSchema === void 0 ? {} : { data: t.dataSchema };
|
|
182
|
+
e = t.type === void 0 ? pe({
|
|
183
|
+
message: ie(t.message),
|
|
184
|
+
...r
|
|
185
|
+
}) : pe({
|
|
186
|
+
message: u(),
|
|
187
|
+
data: pe({
|
|
188
|
+
type: ie(t.type),
|
|
189
|
+
...r
|
|
190
|
+
})
|
|
191
|
+
}), Xe.set(t, e);
|
|
192
|
+
}
|
|
193
|
+
return e;
|
|
194
|
+
}
|
|
195
|
+
function tr(t, e) {
|
|
196
|
+
const r = z(t, e);
|
|
197
|
+
return r.success ? typeof r.data != "object" || r.data === null || !("message" in r.data) || typeof r.data.message != "string" ? {
|
|
198
|
+
success: !1,
|
|
199
|
+
issues: [{
|
|
200
|
+
path: "/message",
|
|
201
|
+
message: "Expected a string message"
|
|
202
|
+
}]
|
|
203
|
+
} : {
|
|
204
|
+
success: !0,
|
|
205
|
+
data: {
|
|
206
|
+
...r.data,
|
|
207
|
+
message: r.data.message
|
|
208
|
+
}
|
|
209
|
+
} : {
|
|
210
|
+
success: !1,
|
|
211
|
+
issues: kt(r.error.issues)
|
|
212
|
+
};
|
|
213
|
+
}
|
|
214
|
+
function kt(t, e = []) {
|
|
215
|
+
return t.flatMap((r) => {
|
|
216
|
+
const s = [...e, ...r.path];
|
|
217
|
+
return r.code === "invalid_union" ? r.errors.flatMap((n) => kt(n, s)) : r.code === "unrecognized_keys" ? r.keys.map((n) => ({
|
|
218
|
+
path: Ee([...s, n]),
|
|
219
|
+
message: "Unexpected property"
|
|
220
|
+
})) : [{
|
|
221
|
+
path: Ee(s),
|
|
222
|
+
message: r.message
|
|
223
|
+
}];
|
|
224
|
+
});
|
|
225
|
+
}
|
|
226
|
+
function Ee(t) {
|
|
227
|
+
return t.map(Zt).join("");
|
|
228
|
+
}
|
|
229
|
+
function Et(t, e = [], r = /* @__PURE__ */ new Set()) {
|
|
230
|
+
if (t === null || typeof t == "string" || typeof t == "boolean" || typeof t == "number" && Number.isFinite(t)) return [];
|
|
231
|
+
if (typeof t != "object" || r.has(t) || !Array.isArray(t) && Object.getPrototypeOf(t) !== Object.prototype && Object.getPrototypeOf(t) !== null) return [{
|
|
232
|
+
path: Ee(e),
|
|
233
|
+
message: "Expected a JSON value"
|
|
234
|
+
}];
|
|
235
|
+
r.add(t);
|
|
236
|
+
const s = (Array.isArray(t) ? Array.from(t.entries()) : Object.entries(t)).flatMap(([n, o]) => Et(o, [...e, n], r));
|
|
237
|
+
return r.delete(t), s;
|
|
238
|
+
}
|
|
239
|
+
function rr(t) {
|
|
240
|
+
return typeof t == "object" && t !== null && t[It] === !0;
|
|
241
|
+
}
|
|
242
|
+
function sr(t) {
|
|
243
|
+
if (Ot(t), t >= -32768 && t <= -32e3 || t === -32800) throw new Error(`Application error code ${t} is reserved by JSON-RPC or LinkRPC.`);
|
|
244
|
+
}
|
|
245
|
+
function Ot(t) {
|
|
246
|
+
if (!Number.isInteger(t) || t < -2147483648 || t > 2147483647) throw new Error(`Application error code ${t} must be a signed 32-bit integer.`);
|
|
247
|
+
}
|
|
248
|
+
var nr = class Oe {
|
|
249
|
+
constructor(e, r, s, n = {}, o, i, a = []) {
|
|
250
|
+
l(this, "paramsSchema");
|
|
251
|
+
l(this, "resultSchema");
|
|
252
|
+
l(this, "errorSchema");
|
|
253
|
+
l(this, "docs");
|
|
254
|
+
l(this, "clientStreamSchema");
|
|
255
|
+
l(this, "serverStreamSchema");
|
|
256
|
+
l(this, "applicationErrors");
|
|
257
|
+
l(this, "kind", "request");
|
|
258
|
+
/** Declared checked errors, retained as a tuple for generated-contract consumers. */
|
|
259
|
+
l(this, "errors");
|
|
260
|
+
this.paramsSchema = e, this.resultSchema = r, this.errorSchema = s, this.docs = n, this.clientStreamSchema = o, this.serverStreamSchema = i, this.applicationErrors = a;
|
|
261
|
+
const c = /* @__PURE__ */ new Set();
|
|
262
|
+
for (const f of a) {
|
|
263
|
+
if (a.some((p) => p !== f && p.code === f.code && (p.bodySchema !== void 0 || f.bodySchema !== void 0))) throw new Error(`Raw error code ${f.code} cannot be shared.`);
|
|
264
|
+
if (f.bodySchema !== void 0) {
|
|
265
|
+
Ot(f.code);
|
|
266
|
+
const p = `code:${f.code}`;
|
|
267
|
+
if (c.has(p)) throw new Error(`Duplicate application error ${p}.`);
|
|
268
|
+
c.add(p);
|
|
269
|
+
continue;
|
|
270
|
+
}
|
|
271
|
+
if (sr(f.code), typeof f.message != "string") throw new Error("Application error message must be a string.");
|
|
272
|
+
if (f.type !== void 0 && (typeof f.type != "string" || f.type.length === 0)) throw new Error("Application error type must be a nonempty string.");
|
|
273
|
+
const h = f.type === void 0 ? `code:${f.code}` : `type:${f.type}`;
|
|
274
|
+
if (c.has(h)) throw new Error(`Duplicate application error ${h}.`);
|
|
275
|
+
c.add(h);
|
|
276
|
+
}
|
|
277
|
+
this.applicationErrors = Object.freeze([...a]), this.errors = this.applicationErrors;
|
|
278
|
+
}
|
|
279
|
+
/**
|
|
280
|
+
* Return a copy of this request type with stream payload schemas
|
|
281
|
+
* attached. Pass `undefined` for either direction to leave it
|
|
282
|
+
* closed.
|
|
283
|
+
* `NoInfer` keeps a contextual MemberMap's `any` stream slots from
|
|
284
|
+
* widening undeclared directions; only the supplied schemas infer payloads.
|
|
285
|
+
*/
|
|
286
|
+
withStream(e) {
|
|
287
|
+
return new Oe(this.paramsSchema, this.resultSchema, this.errorSchema, this.docs, e.client, e.server, this.applicationErrors);
|
|
288
|
+
}
|
|
289
|
+
/**
|
|
290
|
+
* Return a copy with an explicit, typed set of checked application errors.
|
|
291
|
+
* The legacy third `requestType` schema remains accepted for compatibility,
|
|
292
|
+
* but does not opt a method into checked errors.
|
|
293
|
+
*/
|
|
294
|
+
withErrors(e) {
|
|
295
|
+
return new Oe(this.paramsSchema, this.resultSchema, this.errorSchema, this.docs, this.clientStreamSchema, this.serverStreamSchema, e);
|
|
296
|
+
}
|
|
297
|
+
}, or = class {
|
|
298
|
+
constructor(t, e = {}) {
|
|
299
|
+
l(this, "paramsSchema");
|
|
300
|
+
l(this, "docs");
|
|
301
|
+
l(this, "kind", "notification");
|
|
302
|
+
this.paramsSchema = t, this.docs = e;
|
|
303
|
+
}
|
|
304
|
+
};
|
|
305
|
+
function w(t, e, r, s) {
|
|
306
|
+
const n = {};
|
|
307
|
+
return new nr(t, e ?? Ge(), Ge(), n);
|
|
308
|
+
}
|
|
309
|
+
function ir(t, e = {}) {
|
|
310
|
+
return new or(t, e);
|
|
311
|
+
}
|
|
312
|
+
function ar(t, e) {
|
|
313
|
+
var n, o;
|
|
314
|
+
const r = Xt.get(t);
|
|
315
|
+
if (r !== void 0) {
|
|
316
|
+
for (const [i, a] of Object.entries(r.components)) {
|
|
317
|
+
if (e === void 0) throw new Error("Imported schema references require a component destination");
|
|
318
|
+
Re(e.components, i, C(a));
|
|
319
|
+
}
|
|
320
|
+
return C(r.schema);
|
|
321
|
+
}
|
|
322
|
+
const s = (o = (n = t._zod) == null ? void 0 : n.def) == null ? void 0 : o.type;
|
|
323
|
+
return s === "void" || s === "undefined" ? !0 : cr(Jt(t, { override: (i) => {
|
|
324
|
+
var c;
|
|
325
|
+
const a = (c = e == null ? void 0 : e.parameterNames) == null ? void 0 : c.get(i.zodSchema);
|
|
326
|
+
if (a !== void 0) {
|
|
327
|
+
for (const f of Object.keys(i.jsonSchema)) delete i.jsonSchema[f];
|
|
328
|
+
i.jsonSchema.$ref = `linkrpc-parameter:${encodeURIComponent(a)}`;
|
|
329
|
+
} else if ((e == null ? void 0 : e.parameterNames) !== void 0) {
|
|
330
|
+
for (const f of [
|
|
331
|
+
"allOf",
|
|
332
|
+
"patternProperties",
|
|
333
|
+
"unevaluatedProperties",
|
|
334
|
+
"if",
|
|
335
|
+
"then",
|
|
336
|
+
"else",
|
|
337
|
+
"contains"
|
|
338
|
+
]) if (f in i.jsonSchema) throw new Error(`Unsupported template JSON Schema keyword "${f}"`);
|
|
339
|
+
}
|
|
340
|
+
} }), e);
|
|
341
|
+
}
|
|
342
|
+
function cr(t, e) {
|
|
343
|
+
if (!ae(t)) return C(t);
|
|
344
|
+
const r = ae(t.$defs) ? t.$defs : {}, s = $e(t);
|
|
345
|
+
if (Object.keys(r).length === 0 && s.size === 0) return C(t);
|
|
346
|
+
if (e === void 0) throw new Error("zodToSvcJsonSchema: local references require a component destination");
|
|
347
|
+
const n = `method=${ue(e.methodName)}&schema=${ue(e.schemaPosition)}`, o = /* @__PURE__ */ new Map();
|
|
348
|
+
for (const f of Object.keys(r)) o.set(f, `${n}&def=${ue(f)}`);
|
|
349
|
+
const i = s.has("#") ? `${n}&root` : void 0, a = (f) => je(f, o, i);
|
|
350
|
+
for (const [f, h] of Object.entries(r)) {
|
|
351
|
+
const p = o.get(f);
|
|
352
|
+
if (p === void 0) throw new Error(`zodToSvcJsonSchema: missing component for "${f}"`);
|
|
353
|
+
Re(e.components, p, C(a(h)));
|
|
354
|
+
}
|
|
355
|
+
const c = a(t);
|
|
356
|
+
return i !== void 0 ? (Re(e.components, i, C(c)), { $ref: Pe(i) }) : C(c);
|
|
357
|
+
}
|
|
358
|
+
function $e(t, e = /* @__PURE__ */ new Set()) {
|
|
359
|
+
if (Array.isArray(t)) {
|
|
360
|
+
for (const r of t) $e(r, e);
|
|
361
|
+
return e;
|
|
362
|
+
}
|
|
363
|
+
if (!ae(t)) return e;
|
|
364
|
+
typeof t.$ref == "string" && t.$ref.startsWith("#") && e.add(t.$ref);
|
|
365
|
+
for (const r of Object.values(t)) $e(r, e);
|
|
366
|
+
return e;
|
|
367
|
+
}
|
|
368
|
+
function je(t, e, r) {
|
|
369
|
+
if (Array.isArray(t)) return t.map((n) => je(n, e, r));
|
|
370
|
+
if (!ae(t)) return t;
|
|
371
|
+
const s = {};
|
|
372
|
+
for (const [n, o] of Object.entries(t))
|
|
373
|
+
n !== "$defs" && (n === "$ref" && typeof o == "string" ? s[n] = dr(o, e, r) : s[n] = je(o, e, r));
|
|
374
|
+
return s;
|
|
375
|
+
}
|
|
376
|
+
function dr(t, e, r) {
|
|
377
|
+
if (t === "#") {
|
|
378
|
+
if (r === void 0) throw new Error("zodToSvcJsonSchema: root reference has no component destination");
|
|
379
|
+
return Pe(r);
|
|
380
|
+
}
|
|
381
|
+
if (t.startsWith("#/$defs/")) {
|
|
382
|
+
const s = t.slice(8), n = [...e.keys()].find((i) => $t(i) === s), o = n === void 0 ? void 0 : e.get(n);
|
|
383
|
+
if (o === void 0) throw new Error(`zodToSvcJsonSchema: dangling local reference "${t}"`);
|
|
384
|
+
return Pe(o);
|
|
385
|
+
}
|
|
386
|
+
if (t.startsWith("#") && !t.startsWith("#/components/schemas/")) throw new Error(`zodToSvcJsonSchema: unsupported local reference "${t}"`);
|
|
387
|
+
return t;
|
|
388
|
+
}
|
|
389
|
+
function Re(t, e, r) {
|
|
390
|
+
if (Object.hasOwn(t, e)) throw new Error(`zodToSvcJsonSchema: duplicate component name "${e}"`);
|
|
391
|
+
t[e] = r;
|
|
392
|
+
}
|
|
393
|
+
function Pe(t) {
|
|
394
|
+
return `#/components/schemas/${$t(t)}`;
|
|
395
|
+
}
|
|
396
|
+
function $t(t) {
|
|
397
|
+
return t.replace(/~/g, "~0").replace(/\//g, "~1");
|
|
398
|
+
}
|
|
399
|
+
function ue(t) {
|
|
400
|
+
return encodeURIComponent(t).replace(/~/g, "%7E");
|
|
401
|
+
}
|
|
402
|
+
function ae(t) {
|
|
403
|
+
return t !== null && typeof t == "object" && !Array.isArray(t);
|
|
404
|
+
}
|
|
405
|
+
var b = class extends Error {
|
|
406
|
+
constructor() {
|
|
407
|
+
super(...arguments);
|
|
408
|
+
l(this, "name", "SchemaValidationError");
|
|
409
|
+
}
|
|
410
|
+
};
|
|
411
|
+
const jt = "#/components/schemas/";
|
|
412
|
+
function fr(t) {
|
|
413
|
+
return jt + t.replace(/~/g, "~0").replace(/\//g, "~1");
|
|
414
|
+
}
|
|
415
|
+
function U(t) {
|
|
416
|
+
if (!t.startsWith(jt)) throw new b(`Invalid component reference: ${t}`);
|
|
417
|
+
const e = t.slice(21);
|
|
418
|
+
if (e.includes("/") || /~(?:[^01]|$)/.test(e)) throw new b(`Invalid component reference token: ${t}`);
|
|
419
|
+
return e.replace(/~1/g, "/").replace(/~0/g, "~");
|
|
420
|
+
}
|
|
421
|
+
function hr(t) {
|
|
422
|
+
const e = oe(t);
|
|
423
|
+
if (e === void 0) throw new Error("jcsCanonicalize: value is not JSON-representable");
|
|
424
|
+
return e;
|
|
425
|
+
}
|
|
426
|
+
new TextEncoder();
|
|
427
|
+
function oe(t, e = /* @__PURE__ */ new Set()) {
|
|
428
|
+
if (typeof t == "number" && Number.isNaN(t)) throw new Error("NaN is not allowed");
|
|
429
|
+
if (typeof t == "number" && !Number.isFinite(t)) throw new Error("Infinity is not allowed");
|
|
430
|
+
if (t === null || typeof t != "object") return JSON.stringify(t);
|
|
431
|
+
const r = t;
|
|
432
|
+
if (typeof r.toJSON == "function") {
|
|
433
|
+
if (e.has(r)) throw new Error("Circular reference detected");
|
|
434
|
+
e.add(r);
|
|
435
|
+
const n = oe(r.toJSON(), e);
|
|
436
|
+
return e.delete(r), n;
|
|
437
|
+
}
|
|
438
|
+
if (e.has(r)) throw new Error("Circular reference detected");
|
|
439
|
+
e.add(r);
|
|
440
|
+
let s;
|
|
441
|
+
if (Array.isArray(r)) s = `[${r.map((n) => oe(n === void 0 || typeof n == "symbol" ? null : n, e)).join(",")}]`;
|
|
442
|
+
else {
|
|
443
|
+
const n = [];
|
|
444
|
+
for (const o of Object.keys(r).sort()) {
|
|
445
|
+
const i = r[o];
|
|
446
|
+
i === void 0 || typeof i == "symbol" || n.push(`${JSON.stringify(o)}:${oe(i, e)}`);
|
|
447
|
+
}
|
|
448
|
+
s = `{${n.join(",")}}`;
|
|
449
|
+
}
|
|
450
|
+
return e.delete(r), s;
|
|
451
|
+
}
|
|
452
|
+
const lr = new Uint32Array([
|
|
453
|
+
1116352408,
|
|
454
|
+
1899447441,
|
|
455
|
+
3049323471,
|
|
456
|
+
3921009573,
|
|
457
|
+
961987163,
|
|
458
|
+
1508970993,
|
|
459
|
+
2453635748,
|
|
460
|
+
2870763221,
|
|
461
|
+
3624381080,
|
|
462
|
+
310598401,
|
|
463
|
+
607225278,
|
|
464
|
+
1426881987,
|
|
465
|
+
1925078388,
|
|
466
|
+
2162078206,
|
|
467
|
+
2614888103,
|
|
468
|
+
3248222580,
|
|
469
|
+
3835390401,
|
|
470
|
+
4022224774,
|
|
471
|
+
264347078,
|
|
472
|
+
604807628,
|
|
473
|
+
770255983,
|
|
474
|
+
1249150122,
|
|
475
|
+
1555081692,
|
|
476
|
+
1996064986,
|
|
477
|
+
2554220882,
|
|
478
|
+
2821834349,
|
|
479
|
+
2952996808,
|
|
480
|
+
3210313671,
|
|
481
|
+
3336571891,
|
|
482
|
+
3584528711,
|
|
483
|
+
113926993,
|
|
484
|
+
338241895,
|
|
485
|
+
666307205,
|
|
486
|
+
773529912,
|
|
487
|
+
1294757372,
|
|
488
|
+
1396182291,
|
|
489
|
+
1695183700,
|
|
490
|
+
1986661051,
|
|
491
|
+
2177026350,
|
|
492
|
+
2456956037,
|
|
493
|
+
2730485921,
|
|
494
|
+
2820302411,
|
|
495
|
+
3259730800,
|
|
496
|
+
3345764771,
|
|
497
|
+
3516065817,
|
|
498
|
+
3600352804,
|
|
499
|
+
4094571909,
|
|
500
|
+
275423344,
|
|
501
|
+
430227734,
|
|
502
|
+
506948616,
|
|
503
|
+
659060556,
|
|
504
|
+
883997877,
|
|
505
|
+
958139571,
|
|
506
|
+
1322822218,
|
|
507
|
+
1537002063,
|
|
508
|
+
1747873779,
|
|
509
|
+
1955562222,
|
|
510
|
+
2024104815,
|
|
511
|
+
2227730452,
|
|
512
|
+
2361852424,
|
|
513
|
+
2428436474,
|
|
514
|
+
2756734187,
|
|
515
|
+
3204031479,
|
|
516
|
+
3329325298
|
|
517
|
+
]);
|
|
518
|
+
function q(t, e) {
|
|
519
|
+
return t >>> e | t << 32 - e;
|
|
520
|
+
}
|
|
521
|
+
function pr(t) {
|
|
522
|
+
const e = t.length, r = e * 8, s = e + 9 + 63 & -64, n = new Uint8Array(s);
|
|
523
|
+
n.set(t), n[e] = 128;
|
|
524
|
+
const o = new DataView(n.buffer);
|
|
525
|
+
o.setUint32(s - 8, Math.floor(r / 4294967296), !1), o.setUint32(s - 4, r >>> 0, !1);
|
|
526
|
+
const i = new Uint32Array([
|
|
527
|
+
1779033703,
|
|
528
|
+
3144134277,
|
|
529
|
+
1013904242,
|
|
530
|
+
2773480762,
|
|
531
|
+
1359893119,
|
|
532
|
+
2600822924,
|
|
533
|
+
528734635,
|
|
534
|
+
1541459225
|
|
535
|
+
]), a = /* @__PURE__ */ new Uint32Array(64);
|
|
536
|
+
for (let h = 0; h < s; h += 64) {
|
|
537
|
+
for (let E = 0; E < 16; E++) a[E] = o.getUint32(h + E * 4, !1);
|
|
538
|
+
for (let E = 16; E < 64; E++) {
|
|
539
|
+
const $ = a[E - 15], J = a[E - 2], O = q($, 7) ^ q($, 18) ^ $ >>> 3, L = q(J, 17) ^ q(J, 19) ^ J >>> 10;
|
|
540
|
+
a[E] = a[E - 16] + O + a[E - 7] + L >>> 0;
|
|
541
|
+
}
|
|
542
|
+
let p = i[0], m = i[1], y = i[2], _ = i[3], I = i[4], j = i[5], S = i[6], x = i[7];
|
|
543
|
+
for (let E = 0; E < 64; E++) {
|
|
544
|
+
const $ = q(I, 6) ^ q(I, 11) ^ q(I, 25), J = I & j ^ ~I & S, O = x + $ + J + lr[E] + a[E] >>> 0, L = (q(p, 2) ^ q(p, 13) ^ q(p, 22)) + (p & m ^ p & y ^ m & y) >>> 0;
|
|
545
|
+
x = S, S = j, j = I, I = _ + O >>> 0, _ = y, y = m, m = p, p = O + L >>> 0;
|
|
546
|
+
}
|
|
547
|
+
i[0] = i[0] + p >>> 0, i[1] = i[1] + m >>> 0, i[2] = i[2] + y >>> 0, i[3] = i[3] + _ >>> 0, i[4] = i[4] + I >>> 0, i[5] = i[5] + j >>> 0, i[6] = i[6] + S >>> 0, i[7] = i[7] + x >>> 0;
|
|
548
|
+
}
|
|
549
|
+
const c = /* @__PURE__ */ new Uint8Array(32), f = new DataView(c.buffer);
|
|
550
|
+
for (let h = 0; h < 8; h++) f.setUint32(h * 4, i[h], !1);
|
|
551
|
+
return c;
|
|
552
|
+
}
|
|
553
|
+
const ur = [
|
|
554
|
+
"params",
|
|
555
|
+
"result",
|
|
556
|
+
"clientStream",
|
|
557
|
+
"serverStream"
|
|
558
|
+
];
|
|
559
|
+
function Ce(t) {
|
|
560
|
+
const e = hr(Te(mr(t), !0)), r = pr(new TextEncoder().encode(e));
|
|
561
|
+
return Array.from(r.subarray(0, 8), (s) => s.toString(16).padStart(2, "0")).join("");
|
|
562
|
+
}
|
|
563
|
+
function mr(t) {
|
|
564
|
+
var n;
|
|
565
|
+
const e = Object.fromEntries(Object.entries(t.methods).map(([o, i]) => {
|
|
566
|
+
const a = { ...i };
|
|
567
|
+
for (const c of ur) {
|
|
568
|
+
const f = a[c];
|
|
569
|
+
f !== void 0 && (a[c] = C(f));
|
|
570
|
+
}
|
|
571
|
+
return i.errors !== void 0 && (a.errors = i.errors.map((c) => c.schema !== void 0 ? {
|
|
572
|
+
...c,
|
|
573
|
+
schema: C(c.schema)
|
|
574
|
+
} : {
|
|
575
|
+
...c,
|
|
576
|
+
...c.data === void 0 ? {} : { data: C(c.data) }
|
|
577
|
+
})), [o, a];
|
|
578
|
+
})), r = (n = t.components) == null ? void 0 : n.schemas, s = r === void 0 ? t.components : {
|
|
579
|
+
...t.components,
|
|
580
|
+
schemas: Object.fromEntries(Object.entries(r).map(([o, i]) => [o, C(i)]))
|
|
581
|
+
};
|
|
582
|
+
return {
|
|
583
|
+
...t,
|
|
584
|
+
methods: e,
|
|
585
|
+
...s === void 0 ? {} : { components: s }
|
|
586
|
+
};
|
|
587
|
+
}
|
|
588
|
+
function gr(t, e) {
|
|
589
|
+
return t === "comment" || t.startsWith("x-") || e && (t === "hash" || t === "tags");
|
|
590
|
+
}
|
|
591
|
+
function Te(t, e = !1) {
|
|
592
|
+
if (t === null || typeof t != "object") return t;
|
|
593
|
+
if (Array.isArray(t)) return t.map((s) => Te(s));
|
|
594
|
+
const r = {};
|
|
595
|
+
for (const s of Object.keys(t)) {
|
|
596
|
+
if (gr(s, e)) continue;
|
|
597
|
+
const n = t[s];
|
|
598
|
+
n !== void 0 && (r[s] = Te(n));
|
|
599
|
+
}
|
|
600
|
+
return r;
|
|
601
|
+
}
|
|
602
|
+
const re = "x-interface-templates";
|
|
603
|
+
function vr(t, e) {
|
|
604
|
+
const r = /* @__PURE__ */ Object.create(null), s = [];
|
|
605
|
+
for (const [o, i] of Object.entries(e)) {
|
|
606
|
+
const a = r[i.template.id];
|
|
607
|
+
if (a !== void 0 && !Pt(a, i.template)) throw new Error(`Conflicting definitions for interface template "${i.template.id}"`);
|
|
608
|
+
r[i.template.id] = a === void 0 ? i.template : {
|
|
609
|
+
...a,
|
|
610
|
+
tags: ce([...a.tags ?? [], ...i.template.tags ?? []])
|
|
611
|
+
}, s.push({
|
|
612
|
+
...i.schema,
|
|
613
|
+
name: o
|
|
614
|
+
});
|
|
615
|
+
}
|
|
616
|
+
const n = ce([...t.tags ?? [], ...s.flatMap((o) => r[o.template].tags ?? [])]);
|
|
617
|
+
return {
|
|
618
|
+
...t,
|
|
619
|
+
...t.tags !== void 0 || n.length > 0 ? { tags: n } : {},
|
|
620
|
+
[re]: {
|
|
621
|
+
templates: r,
|
|
622
|
+
instances: s
|
|
623
|
+
}
|
|
624
|
+
};
|
|
625
|
+
}
|
|
626
|
+
function Ae(t) {
|
|
627
|
+
Ke(t);
|
|
628
|
+
const e = t[re];
|
|
629
|
+
return ce([...t.tags ?? [], ...((e == null ? void 0 : e.instances) ?? []).flatMap((r) => {
|
|
630
|
+
var s;
|
|
631
|
+
return ((s = e == null ? void 0 : e.templates[r.template]) == null ? void 0 : s.tags) ?? [];
|
|
632
|
+
})]);
|
|
633
|
+
}
|
|
634
|
+
function ce(t) {
|
|
635
|
+
return [...new Set(t)].sort();
|
|
636
|
+
}
|
|
637
|
+
function Ke(t) {
|
|
638
|
+
de(t.tags, `Interface "${t.id}"`);
|
|
639
|
+
const e = t[re];
|
|
640
|
+
if (e === void 0) return;
|
|
641
|
+
if (!k(e) || !k(e.templates) || !Array.isArray(e.instances)) throw new b(`${re} must contain templates and instances`);
|
|
642
|
+
const r = e.templates;
|
|
643
|
+
for (const [o, i] of Object.entries(r)) {
|
|
644
|
+
if (!k(i) || i.id !== o) throw new b(`Interface template key "${o}" must match its id`);
|
|
645
|
+
br(i);
|
|
646
|
+
}
|
|
647
|
+
const s = /* @__PURE__ */ new Map(), n = /* @__PURE__ */ new Set();
|
|
648
|
+
for (const o of e.instances) {
|
|
649
|
+
if (!k(o)) throw new b("Interface template instance must be an object");
|
|
650
|
+
if (typeof o.name != "string") throw new b("Interface template instance name must be a string");
|
|
651
|
+
if (typeof o.template != "string") throw new b("Interface template reference must be a string");
|
|
652
|
+
if (o.prefix !== void 0) throw new b("Interface template instances require explicit member mappings, not prefixes");
|
|
653
|
+
if (!k(o.members)) throw new b("Interface template members must be an object");
|
|
654
|
+
if (!k(o.arguments)) throw new b("Interface template arguments must be an object");
|
|
655
|
+
const i = {
|
|
656
|
+
name: o.name,
|
|
657
|
+
template: o.template,
|
|
658
|
+
members: o.members,
|
|
659
|
+
arguments: o.arguments
|
|
660
|
+
};
|
|
661
|
+
if (Fe(i.name, "interface template instance name"), n.has(i.name)) throw new b(`Interface template instance name collision at "${i.name}"`);
|
|
662
|
+
n.add(i.name);
|
|
663
|
+
const a = r[i.template];
|
|
664
|
+
if (!Object.hasOwn(r, i.template)) throw new b(`Interface template instance "${i.name}" references unknown template "${i.template}"`);
|
|
665
|
+
if (wr(i, a), i.members !== void 0) {
|
|
666
|
+
for (const c of Object.keys(i.members)) if (!Object.hasOwn(a.methods, c)) throw new b(`Unknown mapped member "${c}"`);
|
|
667
|
+
for (const c of Object.keys(a.methods)) {
|
|
668
|
+
const f = i.members[c];
|
|
669
|
+
if (!Object.hasOwn(i.members, c) || typeof f != "string") throw new b(`Missing mapped member "${c}"`);
|
|
670
|
+
}
|
|
671
|
+
}
|
|
672
|
+
yr(t, i, a, s);
|
|
673
|
+
}
|
|
674
|
+
}
|
|
675
|
+
function _r(t, e) {
|
|
676
|
+
if (t.id !== e.id || t.hash !== e.hash || Ce(t) !== t.hash || Ce(e) !== e.hash) return t;
|
|
677
|
+
de(t.tags, `Interface "${t.id}"`), de(e.tags, `Interface "${e.id}"`);
|
|
678
|
+
const r = Ze(e), s = Ze(t);
|
|
679
|
+
if (e["x-interface-templates"] !== void 0 && r === void 0) return t;
|
|
680
|
+
if (t["x-interface-templates"] !== void 0 && s === void 0) return e;
|
|
681
|
+
if (s !== void 0 && r === void 0) return t;
|
|
682
|
+
if (r !== void 0 && s !== void 0) {
|
|
683
|
+
for (const [i, a] of Object.entries(s.templates)) if (!Object.hasOwn(r.templates, i) || !Pt(a, r.templates[i])) return t;
|
|
684
|
+
for (const i of s.instances) if (!r.instances.some((a) => D(i, a))) return t;
|
|
685
|
+
for (const [i, a] of Object.entries(s)) if (i !== "templates" && i !== "instances" && !D(a, r[i])) return t;
|
|
686
|
+
}
|
|
687
|
+
const n = Ae(t), o = Ae(e);
|
|
688
|
+
return n.some((i) => !o.includes(i)) ? t : s === void 0 && r !== void 0 || s !== void 0 && r !== void 0 && (Object.keys(r.templates).length > Object.keys(s.templates).length || r.instances.length > s.instances.length) || o.length > n.length ? e : t;
|
|
689
|
+
}
|
|
690
|
+
function Ze(t) {
|
|
691
|
+
if (t["x-interface-templates"] !== void 0) {
|
|
692
|
+
try {
|
|
693
|
+
Ke(t);
|
|
694
|
+
} catch (e) {
|
|
695
|
+
if (!(e instanceof b)) throw e;
|
|
696
|
+
return;
|
|
697
|
+
}
|
|
698
|
+
return t[re];
|
|
699
|
+
}
|
|
700
|
+
}
|
|
701
|
+
function br(t) {
|
|
702
|
+
if (!k(t) || typeof t.id != "string" || t.id.length === 0) throw new b("Interface template id must be a non-empty string");
|
|
703
|
+
if (!Array.isArray(t.parameters) || !k(t.methods)) throw new b(`Interface template "${t.id}" must contain parameters and methods`);
|
|
704
|
+
de(t.tags, `Interface template "${t.id}"`);
|
|
705
|
+
const e = /* @__PURE__ */ new Set();
|
|
706
|
+
for (const s of t.parameters) {
|
|
707
|
+
if (typeof s != "string" || s.length === 0) throw new b(`Interface template "${t.id}" has an invalid parameter name`);
|
|
708
|
+
if (e.has(s)) throw new b(`Interface template "${t.id}" repeats parameter "${s}"`);
|
|
709
|
+
e.add(s);
|
|
710
|
+
}
|
|
711
|
+
const r = Ct(t.components);
|
|
712
|
+
for (const [s, n] of Object.entries(t.methods)) {
|
|
713
|
+
if (Fe(s, `member of interface template "${t.id}"`), !k(n) || !Object.hasOwn(n, "params")) throw new b(`Interface template "${t.id}" member "${s}" has no params`);
|
|
714
|
+
for (const o of Je) {
|
|
715
|
+
const i = n[o];
|
|
716
|
+
(o === "params" || i !== void 0) && ee(i, e, r, /* @__PURE__ */ new Set());
|
|
717
|
+
}
|
|
718
|
+
if (n.errors !== void 0 && !Array.isArray(n.errors)) throw new b("Interface template method errors must be an array");
|
|
719
|
+
for (const o of n.errors ?? []) {
|
|
720
|
+
if (!k(o)) throw new b("Interface template method error must be an object");
|
|
721
|
+
o.schema !== void 0 && ee(o.schema, e, r, /* @__PURE__ */ new Set()), o.data !== void 0 && ee(o.data, e, r, /* @__PURE__ */ new Set());
|
|
722
|
+
}
|
|
723
|
+
}
|
|
724
|
+
for (const s of Object.values(r)) ee(s, e, r, /* @__PURE__ */ new Set());
|
|
725
|
+
}
|
|
726
|
+
function ee(t, e, r, s) {
|
|
727
|
+
if (typeof t != "boolean") {
|
|
728
|
+
if (!k(t)) throw new b("Interface template schema must be an object or boolean");
|
|
729
|
+
if (!s.has(t)) {
|
|
730
|
+
if (s.add(t), "$parameter" in t) {
|
|
731
|
+
if (Object.keys(t).length !== 1 || typeof t.$parameter != "string") throw new b("A schema parameter reference must contain only $parameter");
|
|
732
|
+
if (!e.has(t.$parameter)) throw new b(`Unknown schema parameter "${t.$parameter}"`);
|
|
733
|
+
return;
|
|
734
|
+
}
|
|
735
|
+
if ("$ref" in t) {
|
|
736
|
+
if (typeof t.$ref != "string") throw new b("Component reference must be a string");
|
|
737
|
+
const n = U(t.$ref);
|
|
738
|
+
if (!Object.hasOwn(r, n)) throw new b(`Unknown interface template component "${n}"`);
|
|
739
|
+
}
|
|
740
|
+
for (const n of Tt(t)) ee(n, e, r, s);
|
|
741
|
+
}
|
|
742
|
+
}
|
|
743
|
+
}
|
|
744
|
+
function wr(t, e) {
|
|
745
|
+
const r = new Set(e.parameters);
|
|
746
|
+
for (const s of Object.keys(t.arguments)) if (!r.has(s)) throw new b(`Interface template instance "${t.name}" supplies unknown parameter "${s}"`);
|
|
747
|
+
for (const s of r) {
|
|
748
|
+
const n = t.arguments[s];
|
|
749
|
+
if (!k(n) || !Object.hasOwn(n, "schema")) throw new b(`Interface template instance "${t.name}" is missing parameter "${s}"`);
|
|
750
|
+
const o = Ct(n.components);
|
|
751
|
+
Ne(n.schema, o, /* @__PURE__ */ new Set());
|
|
752
|
+
for (const i of Object.values(o)) Ne(i, o, /* @__PURE__ */ new Set());
|
|
753
|
+
}
|
|
754
|
+
}
|
|
755
|
+
function Ne(t, e, r) {
|
|
756
|
+
if (typeof t != "boolean") {
|
|
757
|
+
if (!k(t)) throw new b("Concrete schema argument must be an object or boolean");
|
|
758
|
+
if (!r.has(t)) {
|
|
759
|
+
if (r.add(t), "$parameter" in t) throw new b("Concrete schema arguments cannot contain $parameter");
|
|
760
|
+
if ("$ref" in t) {
|
|
761
|
+
if (typeof t.$ref != "string") throw new b("Component reference must be a string");
|
|
762
|
+
const s = U(t.$ref);
|
|
763
|
+
if (!Object.hasOwn(e, s)) throw new b(`Unknown schema argument component "${s}"`);
|
|
764
|
+
}
|
|
765
|
+
for (const s of Tt(t)) Ne(s, e, r);
|
|
766
|
+
}
|
|
767
|
+
}
|
|
768
|
+
}
|
|
769
|
+
function yr(t, e, r, s) {
|
|
770
|
+
var a;
|
|
771
|
+
const n = {}, o = Object.fromEntries(Object.entries(r.methods).map(([c, f]) => [c, Sr(f, r, e, n)])), i = ((a = t.components) == null ? void 0 : a.schemas) ?? {};
|
|
772
|
+
for (const [c, f] of Object.entries(o)) {
|
|
773
|
+
const h = Ir(e, c);
|
|
774
|
+
Fe(h, `mapped member of interface template instance "${e.name}"`);
|
|
775
|
+
const p = s.get(h);
|
|
776
|
+
if (p !== void 0) throw new b(`Interface template member collision at "${h}" between "${p}" and "${e.name}"`);
|
|
777
|
+
s.set(h, e.name);
|
|
778
|
+
const m = t.methods[h];
|
|
779
|
+
if (m === void 0) throw new b(`Interface template instance "${e.name}" is missing mapped member "${h}"`);
|
|
780
|
+
if (!Er(f, m, n, i)) throw new b(`Interface template instance "${e.name}" member "${h}" does not match its instantiated template`);
|
|
781
|
+
}
|
|
782
|
+
}
|
|
783
|
+
function Ir(t, e) {
|
|
784
|
+
const r = t.members[e];
|
|
785
|
+
if (r !== void 0) return r;
|
|
786
|
+
throw new Error(`Missing mapped member "${e}"`);
|
|
787
|
+
}
|
|
788
|
+
function Sr(t, e, r, s) {
|
|
789
|
+
const n = (i) => Me(i, e, r, s, /* @__PURE__ */ new Map()), o = {
|
|
790
|
+
...t,
|
|
791
|
+
params: n(t.params)
|
|
792
|
+
};
|
|
793
|
+
for (const i of Je.slice(1)) {
|
|
794
|
+
const a = t[i];
|
|
795
|
+
a !== void 0 && (o[i] = n(a));
|
|
796
|
+
}
|
|
797
|
+
return t.errors !== void 0 && (o.errors = t.errors.map((i) => i.schema !== void 0 ? {
|
|
798
|
+
code: i.code,
|
|
799
|
+
schema: n(i.schema)
|
|
800
|
+
} : {
|
|
801
|
+
code: i.code,
|
|
802
|
+
message: i.message,
|
|
803
|
+
...i.type === void 0 ? {} : { type: i.type },
|
|
804
|
+
...i.data === void 0 ? {} : { data: n(i.data) }
|
|
805
|
+
})), o;
|
|
806
|
+
}
|
|
807
|
+
function Me(t, e, r, s, n) {
|
|
808
|
+
return typeof t == "boolean" ? t : "$parameter" in t ? kr(t.$parameter, r, s, n) : Rt(t, (o) => {
|
|
809
|
+
var a, c;
|
|
810
|
+
const i = `template:${e.id}:${o}`;
|
|
811
|
+
if (!Object.hasOwn(s, i)) {
|
|
812
|
+
const f = (c = (a = e.components) == null ? void 0 : a.schemas) == null ? void 0 : c[o];
|
|
813
|
+
if (f === void 0) throw new Error(`Unknown interface template component "${o}"`);
|
|
814
|
+
s[i] = !1, s[i] = Me(f, e, r, s, n);
|
|
815
|
+
}
|
|
816
|
+
return i;
|
|
817
|
+
}, (o) => Me(o, e, r, s, n));
|
|
818
|
+
}
|
|
819
|
+
function kr(t, e, r, s) {
|
|
820
|
+
const n = e.arguments[t];
|
|
821
|
+
if (n === void 0) throw new Error(`Missing schema argument "${t}"`);
|
|
822
|
+
const o = (i) => Rt(i, (a) => {
|
|
823
|
+
var m, y;
|
|
824
|
+
const c = `${t}:${a}`, f = s.get(c);
|
|
825
|
+
if (f !== void 0) return f;
|
|
826
|
+
const h = `argument:${e.name}:${t}:${a}`;
|
|
827
|
+
s.set(c, h);
|
|
828
|
+
const p = (y = (m = n.components) == null ? void 0 : m.schemas) == null ? void 0 : y[a];
|
|
829
|
+
if (p === void 0) throw new Error(`Unknown schema argument component "${a}"`);
|
|
830
|
+
return r[h] = !1, r[h] = o(p), h;
|
|
831
|
+
}, (a) => o(a));
|
|
832
|
+
return o(n.schema);
|
|
833
|
+
}
|
|
834
|
+
function Rt(t, e, r) {
|
|
835
|
+
if (typeof t == "boolean") return t;
|
|
836
|
+
const s = {};
|
|
837
|
+
for (const [n, o] of Object.entries(t)) n === "$ref" && typeof o == "string" ? s.$ref = fr(e(U(o))) : n === "properties" && k(o) ? s.properties = Object.fromEntries(Object.entries(o).map(([i, a]) => [i, r(a)])) : n === "additionalProperties" || n === "items" ? s[n] = typeof o == "boolean" ? o : r(o) : n === "prefixItems" || n === "anyOf" || n === "oneOf" ? s[n] = o.map(r) : s[n] = o;
|
|
838
|
+
return s;
|
|
839
|
+
}
|
|
840
|
+
function Er(t, e, r, s) {
|
|
841
|
+
const n = { ...t }, o = { ...e };
|
|
842
|
+
for (const c of Je) {
|
|
843
|
+
const f = t[c], h = e[c];
|
|
844
|
+
if (delete n[c], delete o[c], f === void 0 || h === void 0) {
|
|
845
|
+
if (f !== h) return !1;
|
|
846
|
+
} else if (!N(f, h, r, s)) return !1;
|
|
847
|
+
}
|
|
848
|
+
const i = n.errors, a = o.errors;
|
|
849
|
+
return delete n.errors, delete o.errors, D(n, o) ? i === void 0 || a === void 0 ? i === a : i.length !== a.length ? !1 : i.every((c, f) => {
|
|
850
|
+
const h = a[f];
|
|
851
|
+
return c.schema !== void 0 || h.schema !== void 0 ? c.schema !== void 0 && h.schema !== void 0 && c.code === h.code && N(c.schema, h.schema, r, s) : c.code === h.code && c.type === h.type && c.message === h.message && (c.data === void 0 || h.data === void 0 ? c.data === h.data : N(c.data, h.data, r, s));
|
|
852
|
+
}) : !1;
|
|
853
|
+
}
|
|
854
|
+
function Pt(t, e) {
|
|
855
|
+
const { tags: r, ...s } = t, { tags: n, ...o } = e;
|
|
856
|
+
return D(s, o);
|
|
857
|
+
}
|
|
858
|
+
function de(t, e) {
|
|
859
|
+
if (t !== void 0 && (!Array.isArray(t) || t.some((r) => typeof r != "string")))
|
|
860
|
+
throw new b(`${e} tags must be an array of strings`);
|
|
861
|
+
}
|
|
862
|
+
function N(t, e, r, s, n = /* @__PURE__ */ new WeakMap()) {
|
|
863
|
+
if (typeof t == "boolean" || typeof e == "boolean") return t === e;
|
|
864
|
+
let o = n.get(t);
|
|
865
|
+
if (o != null && o.has(e)) return !0;
|
|
866
|
+
o === void 0 && (o = /* @__PURE__ */ new WeakSet(), n.set(t, o)), o.add(e);
|
|
867
|
+
const i = "$ref" in t ? t.$ref : void 0, a = "$ref" in e ? e.$ref : void 0, c = i === void 0 ? qe(t) : et(t), f = a === void 0 ? qe(e) : et(e);
|
|
868
|
+
if (i !== void 0 && Object.keys(c).length === 0) {
|
|
869
|
+
const m = r[U(i)];
|
|
870
|
+
return m !== void 0 && N(m, e, r, s, n);
|
|
871
|
+
}
|
|
872
|
+
if (a !== void 0 && Object.keys(f).length === 0) {
|
|
873
|
+
const m = s[U(a)];
|
|
874
|
+
return m !== void 0 && N(t, m, r, s, n);
|
|
875
|
+
}
|
|
876
|
+
if (!Or(c, f, r, s, n)) return !1;
|
|
877
|
+
if (i === void 0 || a === void 0) {
|
|
878
|
+
if (i === a) return !0;
|
|
879
|
+
const m = i ?? a, y = i === void 0 ? s : r, _ = y[U(m)];
|
|
880
|
+
return _ === void 0 ? !1 : i === void 0 ? N(t, _, r, y, n) : N(_, e, y, s, n);
|
|
881
|
+
}
|
|
882
|
+
const h = r[U(i)], p = s[U(a)];
|
|
883
|
+
return h !== void 0 && p !== void 0 && N(h, p, r, s, n);
|
|
884
|
+
}
|
|
885
|
+
function Or(t, e, r, s, n) {
|
|
886
|
+
const o = Object.keys(t).sort();
|
|
887
|
+
if (!D(o, Object.keys(e).sort())) return !1;
|
|
888
|
+
for (const i of o) {
|
|
889
|
+
const a = t[i], c = e[i];
|
|
890
|
+
if (i === "properties" && k(a) && k(c)) {
|
|
891
|
+
const f = Object.keys(a).sort();
|
|
892
|
+
if (!D(f, Object.keys(c).sort()) || !f.every((h) => N(a[h], c[h], r, s, n))) return !1;
|
|
893
|
+
} else if ((i === "items" || i === "additionalProperties") && xe(a) && xe(c)) {
|
|
894
|
+
if (!N(a, c, r, s, n)) return !1;
|
|
895
|
+
} else if ((i === "prefixItems" || i === "anyOf" || i === "oneOf") && Array.isArray(a) && Array.isArray(c)) {
|
|
896
|
+
if (a.length !== c.length || !a.every((f, h) => N(f, c[h], r, s, n))) return !1;
|
|
897
|
+
} else if (!D(a, c)) return !1;
|
|
898
|
+
}
|
|
899
|
+
return !0;
|
|
900
|
+
}
|
|
901
|
+
function Ct(t) {
|
|
902
|
+
if (t === void 0) return {};
|
|
903
|
+
if (!k(t) || t.schemas !== void 0 && !k(t.schemas)) throw new b("Schema components and component schemas must be objects");
|
|
904
|
+
return t.schemas ?? {};
|
|
905
|
+
}
|
|
906
|
+
function Tt(t) {
|
|
907
|
+
const e = [];
|
|
908
|
+
if (t.properties !== void 0) {
|
|
909
|
+
if (!k(t.properties)) throw new b("Schema properties must be an object");
|
|
910
|
+
e.push(...Object.values(t.properties));
|
|
911
|
+
}
|
|
912
|
+
for (const r of ["items", "additionalProperties"]) {
|
|
913
|
+
const s = t[r];
|
|
914
|
+
if (s !== void 0) {
|
|
915
|
+
if (!xe(s)) throw new b(`Schema ${r} must be an object or boolean`);
|
|
916
|
+
e.push(s);
|
|
917
|
+
}
|
|
918
|
+
}
|
|
919
|
+
for (const r of [
|
|
920
|
+
"prefixItems",
|
|
921
|
+
"anyOf",
|
|
922
|
+
"oneOf"
|
|
923
|
+
]) {
|
|
924
|
+
const s = t[r];
|
|
925
|
+
if (s !== void 0) {
|
|
926
|
+
if (!Array.isArray(s)) throw new b(`Schema ${r} must be an array`);
|
|
927
|
+
e.push(...s);
|
|
928
|
+
}
|
|
929
|
+
}
|
|
930
|
+
return e;
|
|
931
|
+
}
|
|
932
|
+
const Je = [
|
|
933
|
+
"params",
|
|
934
|
+
"result",
|
|
935
|
+
"clientStream",
|
|
936
|
+
"serverStream"
|
|
937
|
+
], $r = /^[A-Za-z0-9!#$%&'()*+,\-;=?@\[\]^_`{|}~]+$/;
|
|
938
|
+
function Fe(t, e) {
|
|
939
|
+
if (!$r.test(t)) throw new b(`Invalid ${e} "${t}"`);
|
|
940
|
+
}
|
|
941
|
+
function et(t) {
|
|
942
|
+
const e = qe(t);
|
|
943
|
+
return delete e.$ref, e;
|
|
944
|
+
}
|
|
945
|
+
function qe(t) {
|
|
946
|
+
return Object.fromEntries(Object.entries(t));
|
|
947
|
+
}
|
|
948
|
+
function xe(t) {
|
|
949
|
+
return typeof t == "boolean" || k(t);
|
|
950
|
+
}
|
|
951
|
+
function k(t) {
|
|
952
|
+
return t !== null && typeof t == "object" && !Array.isArray(t);
|
|
953
|
+
}
|
|
954
|
+
function D(t, e) {
|
|
955
|
+
if (t === e) return !0;
|
|
956
|
+
if (Array.isArray(t) || Array.isArray(e)) return Array.isArray(t) && Array.isArray(e) && t.length === e.length && t.every((n, o) => D(n, e[o]));
|
|
957
|
+
if (!k(t) || !k(e)) return !1;
|
|
958
|
+
const r = Object.keys(t).sort(), s = Object.keys(e).sort();
|
|
959
|
+
return r.length === s.length && r.every((n, o) => n === s[o] && D(t[n], e[n]));
|
|
960
|
+
}
|
|
961
|
+
function jr(t) {
|
|
962
|
+
if (t !== void 0)
|
|
963
|
+
for (const [e, r] of Object.entries(t.methods)) {
|
|
964
|
+
if (r.result === void 0 && r.errors !== void 0) throw new Error(`Notification "${e}" cannot declare application errors.`);
|
|
965
|
+
const s = /* @__PURE__ */ new Set(), n = r.errors ?? [];
|
|
966
|
+
for (const o of n) {
|
|
967
|
+
if (!Number.isInteger(o.code) || o.code < -2147483648 || o.code > 2147483647) throw new Error(`Application error code ${o.code} on "${e}" must be a signed 32-bit integer.`);
|
|
968
|
+
if (n.some((a) => a !== o && a.code === o.code && (a.schema !== void 0 || o.schema !== void 0))) throw new Error(`Raw error code ${o.code} on "${e}" cannot be shared.`);
|
|
969
|
+
if (o.schema !== void 0) {
|
|
970
|
+
if ([
|
|
971
|
+
"message",
|
|
972
|
+
"type",
|
|
973
|
+
"data"
|
|
974
|
+
].some((a) => Object.hasOwn(o, a))) throw new Error(`Raw error ${o.code} on "${e}" must contain only code and schema.`);
|
|
975
|
+
} else {
|
|
976
|
+
if (typeof o.message != "string") throw new Error(`Application error message on "${e}" must be a string.`);
|
|
977
|
+
if (o.code >= -32768 && o.code <= -32e3 || o.code === -32800) throw new Error(`Application error code ${o.code} on "${e}" is reserved by JSON-RPC or LinkRPC.`);
|
|
978
|
+
if (o.type !== void 0 && (typeof o.type != "string" || o.type.length === 0)) throw new Error(`Application error type on "${e}" must be a nonempty string.`);
|
|
979
|
+
}
|
|
980
|
+
const i = o.type === void 0 ? `code:${o.code}` : `type:${o.type}`;
|
|
981
|
+
if (s.has(i)) throw new Error(`Duplicate application error ${i} on "${e}".`);
|
|
982
|
+
s.add(i);
|
|
983
|
+
}
|
|
984
|
+
}
|
|
985
|
+
}
|
|
986
|
+
const tt = Symbol.for("@hediet/linkrpc.interfaceTemplateGroup"), Q = /* @__PURE__ */ new WeakMap();
|
|
987
|
+
var rt = class {
|
|
988
|
+
constructor(t, e, r = {}) {
|
|
989
|
+
l(this, "info");
|
|
990
|
+
l(this, "members");
|
|
991
|
+
/** Typed wire references for capability and access-request construction. */
|
|
992
|
+
l(this, "ref");
|
|
993
|
+
if (this.info = t, this.members = e, r.frozenSchema !== void 0 && r.templates !== void 0) throw new Error("Cannot combine frozenSchema with authored templates");
|
|
994
|
+
const s = r.templates === void 0 ? r.frozenSchema : vr(me(t, e, ""), r.templates);
|
|
995
|
+
jr(s), s !== void 0 && Ke(s);
|
|
996
|
+
const n = s === void 0 ? ce(t.tags ?? []) : Ae(s);
|
|
997
|
+
if ((t.tags !== void 0 || n.length > 0) && (this.info = {
|
|
998
|
+
...t,
|
|
999
|
+
tags: n
|
|
1000
|
+
}), Q.set(this, {
|
|
1001
|
+
frozenSchema: s,
|
|
1002
|
+
schemaCache: void 0,
|
|
1003
|
+
hashCache: void 0,
|
|
1004
|
+
declarationGroups: void 0
|
|
1005
|
+
}), this.ref = Object.fromEntries(Object.keys(e).map((o) => [o, {
|
|
1006
|
+
interfaceId: this.info.id,
|
|
1007
|
+
interfaceHash: this.schemaHash,
|
|
1008
|
+
member: o
|
|
1009
|
+
}])), t.hash !== void 0 && this.schemaHash !== t.hash) throw new Error(`Interface hash mismatch for "${t.id}": expected "${t.hash}", got "${this.schemaHash}". The interface's wire contract changed — update the pinned hash to "${this.schemaHash}" after reviewing the change.`);
|
|
1010
|
+
}
|
|
1011
|
+
/** @internal Materialize authored groups using the existing wire call functions verbatim. */
|
|
1012
|
+
nestClient(t) {
|
|
1013
|
+
const e = Q.get(this).declarationGroups;
|
|
1014
|
+
if (e === void 0) return t;
|
|
1015
|
+
const r = new Set(Object.values(e).flatMap((n) => Object.values(n))), s = /* @__PURE__ */ Object.create(null);
|
|
1016
|
+
for (const [n, o] of Object.entries(t)) r.has(n) || (s[n] = o);
|
|
1017
|
+
for (const [n, o] of Object.entries(e)) {
|
|
1018
|
+
const i = /* @__PURE__ */ Object.create(null);
|
|
1019
|
+
for (const [a, c] of Object.entries(o)) i[a] = t[c];
|
|
1020
|
+
s[n] = i;
|
|
1021
|
+
}
|
|
1022
|
+
return s;
|
|
1023
|
+
}
|
|
1024
|
+
/** Validate grouped implementations atomically, then lower them to wire handlers. */
|
|
1025
|
+
flattenHandlers(t) {
|
|
1026
|
+
const e = Q.get(this).declarationGroups;
|
|
1027
|
+
if (e === void 0) return t;
|
|
1028
|
+
const r = (f, h) => {
|
|
1029
|
+
if (f === null || typeof f != "object" || Array.isArray(f)) throw new Error(`Expected handler group object at "${h}"`);
|
|
1030
|
+
return f;
|
|
1031
|
+
}, s = r(t, this.info.id), n = new Set(Object.values(e).flatMap((f) => Object.values(f))), o = Object.keys(this.members).filter((f) => !n.has(f)), i = /* @__PURE__ */ new Set([...Object.keys(e), ...o]);
|
|
1032
|
+
for (const f of Reflect.ownKeys(s)) if (typeof f != "string" || !i.has(f)) throw new Error(`Unexpected handler "${String(f)}"; grouped members require grouped handlers`);
|
|
1033
|
+
const a = /* @__PURE__ */ Object.create(null), c = (f, h, p) => {
|
|
1034
|
+
if (!Object.hasOwn(f, h) || typeof f[h] != "function") throw new Error(`Missing or invalid handler "${p}"`);
|
|
1035
|
+
return f[h];
|
|
1036
|
+
};
|
|
1037
|
+
for (const f of o) a[f] = c(s, f, f);
|
|
1038
|
+
for (const [f, h] of Object.entries(e)) {
|
|
1039
|
+
if (!Object.hasOwn(s, f)) throw new Error(`Missing handler group "${f}"`);
|
|
1040
|
+
const p = r(s[f], f);
|
|
1041
|
+
for (const m of Reflect.ownKeys(p)) if (typeof m != "string" || !Object.hasOwn(h, m)) throw new Error(`Unexpected handler "${f}.${String(m)}"`);
|
|
1042
|
+
for (const [m, y] of Object.entries(h)) a[y] = c(p, m, `${f}.${m}`);
|
|
1043
|
+
}
|
|
1044
|
+
return a;
|
|
1045
|
+
}
|
|
1046
|
+
/** Content hash of this interface (see `computeInterfaceHash`). */
|
|
1047
|
+
get schemaHash() {
|
|
1048
|
+
const t = Q.get(this);
|
|
1049
|
+
return t.hashCache === void 0 && (t.hashCache = Ce(t.frozenSchema ?? me(this.info, this.members, ""))), t.hashCache;
|
|
1050
|
+
}
|
|
1051
|
+
/** Lower the definition to a wire-format `LinkRpcInterfaceSchema`, hash filled in. */
|
|
1052
|
+
toSchema() {
|
|
1053
|
+
const t = Q.get(this);
|
|
1054
|
+
return t.schemaCache === void 0 && (t.schemaCache = t.frozenSchema !== void 0 ? {
|
|
1055
|
+
...t.frozenSchema,
|
|
1056
|
+
hash: this.schemaHash,
|
|
1057
|
+
...this.info.tags !== void 0 ? { tags: [...this.info.tags] } : {}
|
|
1058
|
+
} : me(this.info, this.members, this.schemaHash)), t.schemaCache;
|
|
1059
|
+
}
|
|
1060
|
+
};
|
|
1061
|
+
function me(t, e, r) {
|
|
1062
|
+
const s = /* @__PURE__ */ Object.create(null), n = {};
|
|
1063
|
+
for (const [i, a] of Object.entries(e)) s[i] = Rr(i, a, n);
|
|
1064
|
+
const o = {
|
|
1065
|
+
id: t.id,
|
|
1066
|
+
hash: r,
|
|
1067
|
+
methods: s
|
|
1068
|
+
};
|
|
1069
|
+
return Object.keys(n).length > 0 && (o.components = { schemas: n }), t.description !== void 0 && (o.description = t.description), t.comment !== void 0 && (o.comment = t.comment), t.tags !== void 0 && (o.tags = [...new Set(t.tags)]), o;
|
|
1070
|
+
}
|
|
1071
|
+
function Rr(t, e, r, s = (n, o) => Pr(t, o, n, r)) {
|
|
1072
|
+
const n = e.docs;
|
|
1073
|
+
if (e.kind === "request") {
|
|
1074
|
+
const i = {
|
|
1075
|
+
params: s(e.paramsSchema, "params"),
|
|
1076
|
+
result: s(e.resultSchema, "result")
|
|
1077
|
+
};
|
|
1078
|
+
return e.clientStreamSchema !== void 0 && (i.clientStream = s(e.clientStreamSchema, "clientStream")), e.serverStreamSchema !== void 0 && (i.serverStream = s(e.serverStreamSchema, "serverStream")), e.applicationErrors.length > 0 && (i.errors = e.applicationErrors.map((a) => {
|
|
1079
|
+
if (a.bodySchema !== void 0) return {
|
|
1080
|
+
code: a.code,
|
|
1081
|
+
schema: s(a.bodySchema, `error=${a.code}`)
|
|
1082
|
+
};
|
|
1083
|
+
const c = {
|
|
1084
|
+
code: a.code,
|
|
1085
|
+
message: a.message,
|
|
1086
|
+
...a.type === void 0 ? {} : { type: a.type }
|
|
1087
|
+
};
|
|
1088
|
+
return a.dataSchema !== void 0 && (c.data = s(a.dataSchema, `error=${a.code}`)), c;
|
|
1089
|
+
})), n.description !== void 0 && (i.description = n.description), n.comment !== void 0 && (i.comment = n.comment), n.annotations !== void 0 && (i.annotations = n.annotations), i;
|
|
1090
|
+
}
|
|
1091
|
+
const o = { params: s(e.paramsSchema, "params") };
|
|
1092
|
+
return n.description !== void 0 && (o.description = n.description), n.comment !== void 0 && (o.comment = n.comment), n.annotations !== void 0 && (o.annotations = n.annotations), o;
|
|
1093
|
+
}
|
|
1094
|
+
function Pr(t, e, r, s) {
|
|
1095
|
+
return ar(r, {
|
|
1096
|
+
methodName: t,
|
|
1097
|
+
schemaPosition: e,
|
|
1098
|
+
components: s
|
|
1099
|
+
});
|
|
1100
|
+
}
|
|
1101
|
+
function M(t, e, r = {}) {
|
|
1102
|
+
const s = Object.entries(e), n = (p) => p !== null && typeof p == "object" && tt in p && p[tt] === !0;
|
|
1103
|
+
if (!s.some(([, p]) => n(p))) return new rt(t, e, r);
|
|
1104
|
+
const o = /* @__PURE__ */ Object.create(null), i = /* @__PURE__ */ Object.create(null), a = Object.assign(/* @__PURE__ */ Object.create(null), r.templates), c = new Set(s.filter(([, p]) => n(p)).map(([p]) => p)), f = (p, m) => {
|
|
1105
|
+
if (Object.hasOwn(o, p) || c.has(p)) throw new Error(`Interface member collision at "${p}"`);
|
|
1106
|
+
o[p] = m;
|
|
1107
|
+
};
|
|
1108
|
+
for (const [p, m] of s) {
|
|
1109
|
+
if (!n(m)) {
|
|
1110
|
+
f(p, m);
|
|
1111
|
+
continue;
|
|
1112
|
+
}
|
|
1113
|
+
if (Object.hasOwn(a, p)) throw new Error(`Interface template instance collision at "${p}"`);
|
|
1114
|
+
const y = /* @__PURE__ */ Object.create(null);
|
|
1115
|
+
if (m.mapping !== void 0) {
|
|
1116
|
+
for (const _ of Object.keys(m.mapping)) if (!Object.hasOwn(m.members, _)) throw new Error(`Unknown mapped member "${_}"`);
|
|
1117
|
+
}
|
|
1118
|
+
for (const [_, I] of Object.entries(m.members)) {
|
|
1119
|
+
if (m.mapping !== void 0 && !Object.hasOwn(m.mapping, _)) throw new Error(`Missing mapped member "${_}"`);
|
|
1120
|
+
const j = m.mapping === void 0 ? `${p}$${_}` : m.mapping[_];
|
|
1121
|
+
if (typeof j != "string" || j.length === 0) throw new Error(`Missing mapped member "${_}"`);
|
|
1122
|
+
f(j, I), y[_] = j;
|
|
1123
|
+
}
|
|
1124
|
+
i[p] = Object.freeze(y), a[p] = {
|
|
1125
|
+
template: m.template,
|
|
1126
|
+
schema: {
|
|
1127
|
+
template: m.template.id,
|
|
1128
|
+
arguments: m.arguments,
|
|
1129
|
+
members: y
|
|
1130
|
+
}
|
|
1131
|
+
};
|
|
1132
|
+
}
|
|
1133
|
+
const h = new rt(t, o, {
|
|
1134
|
+
...r,
|
|
1135
|
+
templates: a
|
|
1136
|
+
});
|
|
1137
|
+
return Q.get(h).declarationGroups = Object.freeze(i), h;
|
|
1138
|
+
}
|
|
1139
|
+
const W = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-_";
|
|
1140
|
+
function At(t) {
|
|
1141
|
+
let e = "", r = 0;
|
|
1142
|
+
for (; r + 3 <= t.length; r += 3) {
|
|
1143
|
+
const n = t[r] << 16 | t[r + 1] << 8 | t[r + 2];
|
|
1144
|
+
e += W[n >> 18 & 63] + W[n >> 12 & 63] + W[n >> 6 & 63] + W[n & 63];
|
|
1145
|
+
}
|
|
1146
|
+
const s = t.length - r;
|
|
1147
|
+
if (s === 1) {
|
|
1148
|
+
const n = t[r] << 16;
|
|
1149
|
+
e += W[n >> 18 & 63] + W[n >> 12 & 63];
|
|
1150
|
+
} else if (s === 2) {
|
|
1151
|
+
const n = t[r] << 16 | t[r + 1] << 8;
|
|
1152
|
+
e += W[n >> 18 & 63] + W[n >> 12 & 63] + W[n >> 6 & 63];
|
|
1153
|
+
}
|
|
1154
|
+
return e;
|
|
1155
|
+
}
|
|
1156
|
+
const Cr = v({
|
|
1157
|
+
portId: u(),
|
|
1158
|
+
label: g(u())
|
|
1159
|
+
}), Tr = v({
|
|
1160
|
+
type: g(u()),
|
|
1161
|
+
label: g(u()),
|
|
1162
|
+
processId: g(P()),
|
|
1163
|
+
processType: g(u()),
|
|
1164
|
+
nodeStatusServiceId: g(u()),
|
|
1165
|
+
metadata: g(wt(u(), K([
|
|
1166
|
+
u(),
|
|
1167
|
+
P(),
|
|
1168
|
+
se()
|
|
1169
|
+
])))
|
|
1170
|
+
}), Nt = v({
|
|
1171
|
+
source: B(["self", "attacher"]),
|
|
1172
|
+
descriptor: Tr
|
|
1173
|
+
}), Ar = v({
|
|
1174
|
+
nodeId: u(),
|
|
1175
|
+
kind: g(B(["endpoint", "hub"])),
|
|
1176
|
+
label: g(u()),
|
|
1177
|
+
descriptors: g(T(Nt)),
|
|
1178
|
+
ports: T(Cr)
|
|
1179
|
+
}), st = v({
|
|
1180
|
+
nodeId: u(),
|
|
1181
|
+
portId: u()
|
|
1182
|
+
}), nt = v({
|
|
1183
|
+
address: g(u()),
|
|
1184
|
+
port: g(P().check(Y(), X()))
|
|
1185
|
+
}), Nr = v({
|
|
1186
|
+
type: u(),
|
|
1187
|
+
local: g(nt),
|
|
1188
|
+
remote: g(nt),
|
|
1189
|
+
path: g(u()),
|
|
1190
|
+
metadata: g(wt(u(), K([
|
|
1191
|
+
u(),
|
|
1192
|
+
P(),
|
|
1193
|
+
se()
|
|
1194
|
+
])))
|
|
1195
|
+
}), Mr = v({
|
|
1196
|
+
from: st,
|
|
1197
|
+
to: st,
|
|
1198
|
+
label: g(u()),
|
|
1199
|
+
peerState: g(B([
|
|
1200
|
+
"identified",
|
|
1201
|
+
"pending",
|
|
1202
|
+
"unsupported",
|
|
1203
|
+
"error"
|
|
1204
|
+
])),
|
|
1205
|
+
transport: g(Nr)
|
|
1206
|
+
}), qr = v({
|
|
1207
|
+
serviceId: u(),
|
|
1208
|
+
nodeId: u(),
|
|
1209
|
+
portId: u(),
|
|
1210
|
+
match: B(["exact", "prefix"])
|
|
1211
|
+
}), xr = v({
|
|
1212
|
+
observerServiceId: u(),
|
|
1213
|
+
entryNodeId: u(),
|
|
1214
|
+
nodes: T(Ar),
|
|
1215
|
+
links: T(Mr),
|
|
1216
|
+
routes: T(qr)
|
|
1217
|
+
}), Lr = M({
|
|
1218
|
+
id: "hubrpc.topology",
|
|
1219
|
+
description: "Inspect the transport graph visible from a service. A watch emits invalidation ticks; consumers re-fetch getGraph after each tick."
|
|
1220
|
+
}, {
|
|
1221
|
+
getGraph: w(v({}), xr).withStream({ client: v({}) }),
|
|
1222
|
+
watchGraph: w(v({}), v({})).withStream({ server: v({}) })
|
|
1223
|
+
}), ot = v({
|
|
1224
|
+
edgeId: u(),
|
|
1225
|
+
portId: u(),
|
|
1226
|
+
requestId: g(K([P(), u()]))
|
|
1227
|
+
}), Wr = v({
|
|
1228
|
+
type: ie("transit"),
|
|
1229
|
+
timeMs: P(),
|
|
1230
|
+
nodeId: u(),
|
|
1231
|
+
in: g(ot),
|
|
1232
|
+
out: g(ot),
|
|
1233
|
+
disposition: B([
|
|
1234
|
+
"forwarded",
|
|
1235
|
+
"consumed",
|
|
1236
|
+
"dropped",
|
|
1237
|
+
"unroutable"
|
|
1238
|
+
]),
|
|
1239
|
+
kind: B([
|
|
1240
|
+
"request",
|
|
1241
|
+
"notification",
|
|
1242
|
+
"response",
|
|
1243
|
+
"stream"
|
|
1244
|
+
]),
|
|
1245
|
+
method: g(u()),
|
|
1246
|
+
params: g(V()),
|
|
1247
|
+
result: g(V()),
|
|
1248
|
+
error: g(v({
|
|
1249
|
+
code: P(),
|
|
1250
|
+
message: u(),
|
|
1251
|
+
data: g(V())
|
|
1252
|
+
}))
|
|
1253
|
+
}), zr = v({
|
|
1254
|
+
type: ie("overflow"),
|
|
1255
|
+
dropped: P().check(Y(), X())
|
|
1256
|
+
}), it = K([Wr, zr]), at = v({
|
|
1257
|
+
delivered: P().check(Y(), X()),
|
|
1258
|
+
dropped: P().check(Y(), X())
|
|
1259
|
+
}), Dr = v({
|
|
1260
|
+
methodPrefix: g(u()),
|
|
1261
|
+
trafficIgnoreKey: g(u()),
|
|
1262
|
+
focusRequest: g(v({
|
|
1263
|
+
portId: u(),
|
|
1264
|
+
requestId: K([P(), u()])
|
|
1265
|
+
}))
|
|
1266
|
+
}), Hr = v({
|
|
1267
|
+
methodPrefix: g(u()),
|
|
1268
|
+
trafficIgnoreKey: g(u()),
|
|
1269
|
+
focusRequest: g(v({
|
|
1270
|
+
portId: u(),
|
|
1271
|
+
requestId: K([P(), u()])
|
|
1272
|
+
})),
|
|
1273
|
+
maxPayloadBytes: P().check(Y(), X())
|
|
1274
|
+
}), Ur = M({
|
|
1275
|
+
id: "hubrpc.traffic",
|
|
1276
|
+
description: "Stream raw message transits for the entire node hosting the addressed service. Payload-free and explicitly payload-bearing variants keep disclosure opt-in."
|
|
1277
|
+
}, {
|
|
1278
|
+
watch: w(Dr, at).withStream({ server: it }),
|
|
1279
|
+
watchWithPayloads: w(Hr, at).withStream({ server: it })
|
|
1280
|
+
}), Br = v({
|
|
1281
|
+
/**
|
|
1282
|
+
* Random identity of this connection's node. It is a topology-correlation
|
|
1283
|
+
* label only and must not be used for authentication or authorization.
|
|
1284
|
+
*/
|
|
1285
|
+
nodeId: u(),
|
|
1286
|
+
/** Random identity of this connection's port on its node. */
|
|
1287
|
+
portId: u(),
|
|
1288
|
+
/** Optional diagnostic descriptors; never used for authorization. */
|
|
1289
|
+
descriptors: g(T(Nt))
|
|
1290
|
+
}), Mt = M({
|
|
1291
|
+
id: "hubrpc.node",
|
|
1292
|
+
description: "Topology bootstrap: identify the node and port at this end of the direct connection."
|
|
1293
|
+
}, { getNodeId: w(v({}), Br) }), F = {
|
|
1294
|
+
/** callee → caller: progress, partial results. Routes like a response. */
|
|
1295
|
+
toCaller: "toCaller",
|
|
1296
|
+
/** caller → callee: input, cancellation, keepalive ping. */
|
|
1297
|
+
toCallee: "toCallee"
|
|
1298
|
+
}, H = {
|
|
1299
|
+
/**
|
|
1300
|
+
* Ask the callee to abort the in-flight request. Always {@link
|
|
1301
|
+
* StreamDir.toCallee}. The callee surfaces this as an `AbortSignal`
|
|
1302
|
+
* and is expected to settle the request (typically with a
|
|
1303
|
+
* `cancelled` error response).
|
|
1304
|
+
*/
|
|
1305
|
+
cancel: "cancel",
|
|
1306
|
+
/**
|
|
1307
|
+
* Keepalive / liveness probe. Resets the hub's per-request idle timer
|
|
1308
|
+
* so a long-running call is not reaped, and lets either side actively
|
|
1309
|
+
* probe the peer. Carries a `nonce` the peer echoes in its {@link
|
|
1310
|
+
* StreamControlType.pong}. May travel in either direction. Emitted
|
|
1311
|
+
* automatically (without awaiting a pong) by the channel for streaming
|
|
1312
|
+
* calls; see {@link STREAM_METHOD}.
|
|
1313
|
+
*/
|
|
1314
|
+
ping: "ping",
|
|
1315
|
+
/**
|
|
1316
|
+
* Reply to a {@link StreamControlType.ping}, echoing the ping's
|
|
1317
|
+
* `nonce` so the prober can correlate it. Travels opposite the ping.
|
|
1318
|
+
* Carries no app effect — purely a liveness acknowledgement.
|
|
1319
|
+
*/
|
|
1320
|
+
pong: "pong"
|
|
1321
|
+
}, Kr = M({
|
|
1322
|
+
id: "$stream",
|
|
1323
|
+
description: "Reserved sub-protocol for in-flight stream messages correlated to a request by `requestId`."
|
|
1324
|
+
}, { send: ir(v({
|
|
1325
|
+
/**
|
|
1326
|
+
* Id of the in-flight request the message belongs to.
|
|
1327
|
+
* The hub rewrites this across the forwarding boundary
|
|
1328
|
+
* in the same way it rewrites response ids.
|
|
1329
|
+
*/
|
|
1330
|
+
requestId: K([P(), u()]),
|
|
1331
|
+
/**
|
|
1332
|
+
* Which way this message travels relative to the request.
|
|
1333
|
+
* Explicit so the hub can author messages (e.g. cancel on
|
|
1334
|
+
* disconnect) without inferring direction from arrival.
|
|
1335
|
+
*/
|
|
1336
|
+
dir: B(["toCaller", "toCallee"]),
|
|
1337
|
+
/**
|
|
1338
|
+
* Reserved control verb (cancel / ping / pong). Mutually
|
|
1339
|
+
* exclusive with `payload` in practice: a control message
|
|
1340
|
+
* is interpreted by the runtime, not the application.
|
|
1341
|
+
*/
|
|
1342
|
+
control: g(v({
|
|
1343
|
+
type: B([
|
|
1344
|
+
"cancel",
|
|
1345
|
+
"ping",
|
|
1346
|
+
"pong"
|
|
1347
|
+
]),
|
|
1348
|
+
/** Open-set human/diagnostic reason; see {@link StreamControlReason}. */
|
|
1349
|
+
reason: g(u()),
|
|
1350
|
+
/**
|
|
1351
|
+
* Correlation token. A `ping` carries a fresh nonce;
|
|
1352
|
+
* the matching `pong` echoes it back so the prober
|
|
1353
|
+
* can resolve the right outstanding probe.
|
|
1354
|
+
*/
|
|
1355
|
+
nonce: g(u())
|
|
1356
|
+
})),
|
|
1357
|
+
/** Opaque app payload — typed per call by the request's stream schema. */
|
|
1358
|
+
payload: g(V())
|
|
1359
|
+
}), { description: "Emit a stream message tied to the request `requestId`." }) }), te = `${Kr.info.id}::send`;
|
|
1360
|
+
var Jr = class {
|
|
1361
|
+
constructor(t) {
|
|
1362
|
+
l(this, "_focused");
|
|
1363
|
+
this._focused = t.focus !== void 0 ? new qt([t.focus]) : void 0;
|
|
1364
|
+
}
|
|
1365
|
+
shouldInclude(t) {
|
|
1366
|
+
var e;
|
|
1367
|
+
return ((e = this._focused) == null ? void 0 : e.accept(t).matches) ?? !0;
|
|
1368
|
+
}
|
|
1369
|
+
}, Fr = class {
|
|
1370
|
+
constructor() {
|
|
1371
|
+
l(this, "_active", /* @__PURE__ */ new Set());
|
|
1372
|
+
l(this, "_unclaimed", /* @__PURE__ */ new Map());
|
|
1373
|
+
}
|
|
1374
|
+
accept(t) {
|
|
1375
|
+
if (t.kind === "request" && Vr(t.method)) {
|
|
1376
|
+
const e = Yr(t.params);
|
|
1377
|
+
let r = this._findFlow(t);
|
|
1378
|
+
return r === void 0 ? (r = new qt(We(t), Gr(t)), Le(t) || this._active.add(r)) : r.accept(t), Le(t) ? (this._removeFlow(r), !0) : (e !== void 0 && this._unclaimed.set(e, r), !0);
|
|
1379
|
+
}
|
|
1380
|
+
for (const e of this._active) {
|
|
1381
|
+
const r = e.accept(t);
|
|
1382
|
+
if (r.matches)
|
|
1383
|
+
return r.completed && this._removeFlow(e), !0;
|
|
1384
|
+
}
|
|
1385
|
+
return !1;
|
|
1386
|
+
}
|
|
1387
|
+
_findFlow(t) {
|
|
1388
|
+
for (const e of this._active) if (e.matches(t)) return e;
|
|
1389
|
+
}
|
|
1390
|
+
_removeFlow(t) {
|
|
1391
|
+
this._active.delete(t);
|
|
1392
|
+
for (const [e, r] of this._unclaimed) r === t && this._unclaimed.delete(e);
|
|
1393
|
+
}
|
|
1394
|
+
claim(t) {
|
|
1395
|
+
return this._unclaimed.delete(t);
|
|
1396
|
+
}
|
|
1397
|
+
clear() {
|
|
1398
|
+
this._active.clear(), this._unclaimed.clear();
|
|
1399
|
+
}
|
|
1400
|
+
forgetPort(t) {
|
|
1401
|
+
for (const e of this._active) e.hasPort(t) && this._removeFlow(e);
|
|
1402
|
+
}
|
|
1403
|
+
}, qt = class {
|
|
1404
|
+
constructor(t, e = t[0]) {
|
|
1405
|
+
l(this, "_endpoints", /* @__PURE__ */ new Set());
|
|
1406
|
+
l(this, "_ports", /* @__PURE__ */ new Set());
|
|
1407
|
+
l(this, "_completionEndpoint");
|
|
1408
|
+
for (const r of t)
|
|
1409
|
+
this._endpoints.add(Z(r)), this._ports.add(r.portId);
|
|
1410
|
+
this._completionEndpoint = e === void 0 ? void 0 : Z(e);
|
|
1411
|
+
}
|
|
1412
|
+
matches(t) {
|
|
1413
|
+
return We(t).some((e) => this._endpoints.has(Z(e)));
|
|
1414
|
+
}
|
|
1415
|
+
hasPort(t) {
|
|
1416
|
+
return this._ports.has(t);
|
|
1417
|
+
}
|
|
1418
|
+
accept(t) {
|
|
1419
|
+
const e = We(t);
|
|
1420
|
+
if (!this.matches(t)) return {
|
|
1421
|
+
matches: !1,
|
|
1422
|
+
completed: !1
|
|
1423
|
+
};
|
|
1424
|
+
for (const s of e)
|
|
1425
|
+
this._endpoints.add(Z(s)), this._ports.add(s.portId);
|
|
1426
|
+
const r = t.kind === "response" && (Le(t) || this._completionEndpoint !== void 0 && e.some((s) => Z(s) === this._completionEndpoint));
|
|
1427
|
+
return r && this._endpoints.clear(), {
|
|
1428
|
+
matches: !0,
|
|
1429
|
+
completed: r
|
|
1430
|
+
};
|
|
1431
|
+
}
|
|
1432
|
+
};
|
|
1433
|
+
function Le(t) {
|
|
1434
|
+
return t.disposition === "dropped" || t.disposition === "unroutable";
|
|
1435
|
+
}
|
|
1436
|
+
function We(t) {
|
|
1437
|
+
var r, s;
|
|
1438
|
+
const e = [];
|
|
1439
|
+
return ((r = t.in) == null ? void 0 : r.requestId) !== void 0 && e.push(fe(t.in)), ((s = t.out) == null ? void 0 : s.requestId) !== void 0 && e.push(fe(t.out)), e;
|
|
1440
|
+
}
|
|
1441
|
+
function fe(t) {
|
|
1442
|
+
return {
|
|
1443
|
+
portId: t.portId,
|
|
1444
|
+
requestId: t.requestId
|
|
1445
|
+
};
|
|
1446
|
+
}
|
|
1447
|
+
function Gr(t) {
|
|
1448
|
+
var e, r;
|
|
1449
|
+
if (((e = t.in) == null ? void 0 : e.requestId) !== void 0) return fe(t.in);
|
|
1450
|
+
if (((r = t.out) == null ? void 0 : r.requestId) !== void 0) return fe(t.out);
|
|
1451
|
+
}
|
|
1452
|
+
function Z(t) {
|
|
1453
|
+
return JSON.stringify([
|
|
1454
|
+
t.portId,
|
|
1455
|
+
typeof t.requestId,
|
|
1456
|
+
t.requestId
|
|
1457
|
+
]);
|
|
1458
|
+
}
|
|
1459
|
+
function Vr(t) {
|
|
1460
|
+
return (t == null ? void 0 : t.endsWith("::hubrpc.traffic::watch")) === !0 || (t == null ? void 0 : t.endsWith("::hubrpc.traffic::watchWithPayloads")) === !0 || t === "hubrpc.traffic::watch" || t === "hubrpc.traffic::watchWithPayloads";
|
|
1461
|
+
}
|
|
1462
|
+
function Yr(t) {
|
|
1463
|
+
if (t === null || Array.isArray(t) || typeof t != "object" || !("trafficIgnoreKey" in t)) return;
|
|
1464
|
+
const e = t.trafficIgnoreKey;
|
|
1465
|
+
return typeof e == "string" ? e : void 0;
|
|
1466
|
+
}
|
|
1467
|
+
const Qr = 256;
|
|
1468
|
+
var Xr = class {
|
|
1469
|
+
constructor(t, e, r, s = Qr) {
|
|
1470
|
+
l(this, "_options");
|
|
1471
|
+
l(this, "_send");
|
|
1472
|
+
l(this, "_onDispose");
|
|
1473
|
+
l(this, "_queueLimit");
|
|
1474
|
+
l(this, "_queue", []);
|
|
1475
|
+
l(this, "_active", !0);
|
|
1476
|
+
l(this, "_pumping", !1);
|
|
1477
|
+
l(this, "_overflowPending", 0);
|
|
1478
|
+
l(this, "_delivered", 0);
|
|
1479
|
+
l(this, "_dropped", 0);
|
|
1480
|
+
l(this, "_resolveClosed");
|
|
1481
|
+
l(this, "_filter");
|
|
1482
|
+
l(this, "closed");
|
|
1483
|
+
this._options = t, this._send = e, this._onDispose = r, this._queueLimit = s;
|
|
1484
|
+
let n;
|
|
1485
|
+
this.closed = new Promise((o) => n = o), this._resolveClosed = n, this._filter = new Jr({ focus: t.focusRequest });
|
|
1486
|
+
}
|
|
1487
|
+
enqueue(t) {
|
|
1488
|
+
var r;
|
|
1489
|
+
if (!this._active || !this._filter.shouldInclude(t) || this._options.methodPrefix !== void 0 && !((r = t.method) != null && r.startsWith(this._options.methodPrefix))) return;
|
|
1490
|
+
const e = this._options.maxPayloadBytes === void 0 ? Zr(t) : es(t, this._options.maxPayloadBytes);
|
|
1491
|
+
this._queue.length >= this._queueLimit && (this._queue.shift(), this._dropped++, this._overflowPending++), this._queue.push(e), this._pumping || (this._pumping = !0, queueMicrotask(() => void this._pump()));
|
|
1492
|
+
}
|
|
1493
|
+
dispose() {
|
|
1494
|
+
this._active && (this._active = !1, this._dropped += this._queue.length, this._queue.length = 0, this._overflowPending = 0, this._onDispose(), this._pumping || this._complete());
|
|
1495
|
+
}
|
|
1496
|
+
async _pump() {
|
|
1497
|
+
try {
|
|
1498
|
+
for (; this._active; ) {
|
|
1499
|
+
if (this._overflowPending > 0) {
|
|
1500
|
+
const e = this._overflowPending;
|
|
1501
|
+
this._overflowPending = 0, await this._send({
|
|
1502
|
+
type: "overflow",
|
|
1503
|
+
dropped: e
|
|
1504
|
+
});
|
|
1505
|
+
continue;
|
|
1506
|
+
}
|
|
1507
|
+
const t = this._queue.shift();
|
|
1508
|
+
if (t === void 0) break;
|
|
1509
|
+
await this._send(t), this._delivered++;
|
|
1510
|
+
}
|
|
1511
|
+
} catch {
|
|
1512
|
+
this.dispose();
|
|
1513
|
+
} finally {
|
|
1514
|
+
this._pumping = !1, this._active ? (this._queue.length > 0 || this._overflowPending > 0) && (this._pumping = !0, queueMicrotask(() => void this._pump())) : this._complete();
|
|
1515
|
+
}
|
|
1516
|
+
}
|
|
1517
|
+
_complete() {
|
|
1518
|
+
this._resolveClosed({
|
|
1519
|
+
delivered: this._delivered,
|
|
1520
|
+
dropped: this._dropped
|
|
1521
|
+
});
|
|
1522
|
+
}
|
|
1523
|
+
};
|
|
1524
|
+
function Zr(t) {
|
|
1525
|
+
const { params: e, result: r, error: s, ...n } = t;
|
|
1526
|
+
return s === void 0 ? n : {
|
|
1527
|
+
...n,
|
|
1528
|
+
error: {
|
|
1529
|
+
code: s.code,
|
|
1530
|
+
message: s.message
|
|
1531
|
+
}
|
|
1532
|
+
};
|
|
1533
|
+
}
|
|
1534
|
+
function es(t, e) {
|
|
1535
|
+
return {
|
|
1536
|
+
...t,
|
|
1537
|
+
params: ge(t.params, e),
|
|
1538
|
+
result: ge(t.result, e),
|
|
1539
|
+
error: t.error === void 0 ? void 0 : {
|
|
1540
|
+
...t.error,
|
|
1541
|
+
data: ge(t.error.data, e)
|
|
1542
|
+
}
|
|
1543
|
+
};
|
|
1544
|
+
}
|
|
1545
|
+
function ge(t, e) {
|
|
1546
|
+
if (t === void 0) return;
|
|
1547
|
+
if (e === Number.POSITIVE_INFINITY) return t;
|
|
1548
|
+
const r = JSON.stringify(t);
|
|
1549
|
+
if (r === void 0) return;
|
|
1550
|
+
const s = new TextEncoder().encode(r);
|
|
1551
|
+
if (s.byteLength <= e) return t;
|
|
1552
|
+
const n = new TextEncoder();
|
|
1553
|
+
let o = new TextDecoder().decode(s.slice(0, e));
|
|
1554
|
+
for (; n.encode(o).byteLength > e; ) o = o.slice(0, -1);
|
|
1555
|
+
return o;
|
|
1556
|
+
}
|
|
1557
|
+
const ts = 18e5, rs = 4096;
|
|
1558
|
+
var xt = class {
|
|
1559
|
+
constructor(t, e, r, s) {
|
|
1560
|
+
l(this, "_nodeId");
|
|
1561
|
+
l(this, "_portId");
|
|
1562
|
+
l(this, "_emit");
|
|
1563
|
+
l(this, "_isObserved");
|
|
1564
|
+
l(this, "_outboundRequests", /* @__PURE__ */ new Map());
|
|
1565
|
+
l(this, "_inboundRequests", /* @__PURE__ */ new Map());
|
|
1566
|
+
l(this, "observe", (t, e) => {
|
|
1567
|
+
this._onMessage(t, e);
|
|
1568
|
+
});
|
|
1569
|
+
this._nodeId = t, this._portId = e, this._emit = r, this._isObserved = s;
|
|
1570
|
+
}
|
|
1571
|
+
dispose() {
|
|
1572
|
+
this._outboundRequests.clear(), this._inboundRequests.clear();
|
|
1573
|
+
}
|
|
1574
|
+
_onMessage(t, e) {
|
|
1575
|
+
const r = Date.now();
|
|
1576
|
+
this._pruneRequestCorrelations(r);
|
|
1577
|
+
const s = this._isObserved();
|
|
1578
|
+
s || this.dispose();
|
|
1579
|
+
let n;
|
|
1580
|
+
const o = this._endpoint("id" in e ? e.id ?? void 0 : void 0), i = {
|
|
1581
|
+
type: "transit",
|
|
1582
|
+
timeMs: r,
|
|
1583
|
+
nodeId: this._nodeId,
|
|
1584
|
+
...t === "inbound" ? { in: o } : { out: o },
|
|
1585
|
+
disposition: t === "inbound" ? "consumed" : "forwarded"
|
|
1586
|
+
};
|
|
1587
|
+
if (yt(e)) {
|
|
1588
|
+
const c = {
|
|
1589
|
+
method: e.method,
|
|
1590
|
+
timeMs: r
|
|
1591
|
+
};
|
|
1592
|
+
if (s) {
|
|
1593
|
+
const f = this._requestMap(t), h = a(e.id);
|
|
1594
|
+
f.delete(h), f.set(h, c);
|
|
1595
|
+
}
|
|
1596
|
+
n = {
|
|
1597
|
+
...i,
|
|
1598
|
+
kind: "request",
|
|
1599
|
+
method: e.method,
|
|
1600
|
+
params: e.params
|
|
1601
|
+
};
|
|
1602
|
+
} else if (ke(e)) {
|
|
1603
|
+
const c = t === "inbound" ? this._outboundRequests : this._inboundRequests, f = a(e.id), h = c.get(f);
|
|
1604
|
+
c.delete(f), n = {
|
|
1605
|
+
...i,
|
|
1606
|
+
kind: "response",
|
|
1607
|
+
method: h == null ? void 0 : h.method,
|
|
1608
|
+
result: "result" in e ? e.result : void 0,
|
|
1609
|
+
error: "error" in e ? e.error : void 0
|
|
1610
|
+
};
|
|
1611
|
+
} else if (Se(e) && e.method === te) {
|
|
1612
|
+
const c = e.params, f = this._endpoint(c == null ? void 0 : c.requestId);
|
|
1613
|
+
n = {
|
|
1614
|
+
...i,
|
|
1615
|
+
...t === "inbound" ? { in: f } : { out: f },
|
|
1616
|
+
kind: "stream",
|
|
1617
|
+
method: te,
|
|
1618
|
+
params: e.params
|
|
1619
|
+
};
|
|
1620
|
+
} else n = {
|
|
1621
|
+
...i,
|
|
1622
|
+
kind: "notification",
|
|
1623
|
+
method: e.method,
|
|
1624
|
+
params: e.params
|
|
1625
|
+
};
|
|
1626
|
+
function a(c) {
|
|
1627
|
+
return JSON.stringify([typeof c, c]);
|
|
1628
|
+
}
|
|
1629
|
+
this._emit(n);
|
|
1630
|
+
}
|
|
1631
|
+
_requestMap(t) {
|
|
1632
|
+
return t === "outbound" ? this._outboundRequests : this._inboundRequests;
|
|
1633
|
+
}
|
|
1634
|
+
_endpoint(t) {
|
|
1635
|
+
return {
|
|
1636
|
+
edgeId: this._portId,
|
|
1637
|
+
portId: this._portId,
|
|
1638
|
+
...t !== void 0 ? { requestId: t } : {}
|
|
1639
|
+
};
|
|
1640
|
+
}
|
|
1641
|
+
_pruneRequestCorrelations(t) {
|
|
1642
|
+
this._pruneRequestMap(this._outboundRequests, t), this._pruneRequestMap(this._inboundRequests, t);
|
|
1643
|
+
}
|
|
1644
|
+
_pruneRequestMap(t, e) {
|
|
1645
|
+
for (; t.size !== 0; ) {
|
|
1646
|
+
const r = t.entries().next().value;
|
|
1647
|
+
if (r === void 0 || t.size <= rs && e - r[1].timeMs <= ts) return;
|
|
1648
|
+
t.delete(r[0]);
|
|
1649
|
+
}
|
|
1650
|
+
}
|
|
1651
|
+
}, ss = class {
|
|
1652
|
+
constructor(t, e, r, s) {
|
|
1653
|
+
l(this, "_connection");
|
|
1654
|
+
l(this, "_nodeId");
|
|
1655
|
+
l(this, "_options");
|
|
1656
|
+
l(this, "_isObserved");
|
|
1657
|
+
this._connection = t, this._nodeId = e, this._options = r, this._isObserved = s;
|
|
1658
|
+
}
|
|
1659
|
+
snapshotTopology() {
|
|
1660
|
+
const { portId: t, label: e, peer: r, transport: s } = this._options, n = [{
|
|
1661
|
+
nodeId: this._nodeId,
|
|
1662
|
+
ports: [{
|
|
1663
|
+
portId: t,
|
|
1664
|
+
...e === void 0 ? {} : { label: e }
|
|
1665
|
+
}]
|
|
1666
|
+
}], o = [];
|
|
1667
|
+
return r !== void 0 && (n.push({
|
|
1668
|
+
nodeId: r.nodeId,
|
|
1669
|
+
kind: "endpoint",
|
|
1670
|
+
...r.label === void 0 ? {} : { label: r.label },
|
|
1671
|
+
ports: [{ portId: r.portId }]
|
|
1672
|
+
}), o.push({
|
|
1673
|
+
from: {
|
|
1674
|
+
nodeId: this._nodeId,
|
|
1675
|
+
portId: t
|
|
1676
|
+
},
|
|
1677
|
+
to: {
|
|
1678
|
+
nodeId: r.nodeId,
|
|
1679
|
+
portId: r.portId
|
|
1680
|
+
},
|
|
1681
|
+
peerState: "identified",
|
|
1682
|
+
...s === void 0 ? {} : { transport: s }
|
|
1683
|
+
})), {
|
|
1684
|
+
nodes: n,
|
|
1685
|
+
links: o,
|
|
1686
|
+
routes: []
|
|
1687
|
+
};
|
|
1688
|
+
}
|
|
1689
|
+
onTopologyChanged(t) {
|
|
1690
|
+
return { dispose: () => {
|
|
1691
|
+
} };
|
|
1692
|
+
}
|
|
1693
|
+
observeTraffic(t) {
|
|
1694
|
+
const e = new xt(this._nodeId, this._options.portId, t, this._isObserved), r = this._connection.observeWireMessages(e.observe);
|
|
1695
|
+
return { dispose: () => {
|
|
1696
|
+
r.dispose(), e.dispose();
|
|
1697
|
+
} };
|
|
1698
|
+
}
|
|
1699
|
+
}, ns = class {
|
|
1700
|
+
constructor(t) {
|
|
1701
|
+
l(this, "_options");
|
|
1702
|
+
l(this, "_sources", /* @__PURE__ */ new Map());
|
|
1703
|
+
l(this, "_trackedConnections", /* @__PURE__ */ new Set());
|
|
1704
|
+
l(this, "_bindings", /* @__PURE__ */ new Set());
|
|
1705
|
+
l(this, "_subscribers", /* @__PURE__ */ new Set());
|
|
1706
|
+
l(this, "_observers", /* @__PURE__ */ new Set());
|
|
1707
|
+
l(this, "_topologyListeners", /* @__PURE__ */ new Set());
|
|
1708
|
+
l(this, "_trafficSources", /* @__PURE__ */ new Set());
|
|
1709
|
+
l(this, "_trafficWatches", new Fr());
|
|
1710
|
+
l(this, "_disposed", !1);
|
|
1711
|
+
l(this, "nodeId");
|
|
1712
|
+
this._options = t, this.nodeId = t.nodeId;
|
|
1713
|
+
}
|
|
1714
|
+
get observerCount() {
|
|
1715
|
+
return this._subscribers.size + this._observers.size;
|
|
1716
|
+
}
|
|
1717
|
+
addSource(t) {
|
|
1718
|
+
if (this._assertActive(), this._sources.has(t)) throw new Error("Inspection source is already registered");
|
|
1719
|
+
const e = () => new Set(t.snapshotTopology().nodes.flatMap((i) => i.ports.map((a) => a.portId)));
|
|
1720
|
+
let r = e();
|
|
1721
|
+
const s = t.onTopologyChanged(() => {
|
|
1722
|
+
const i = e(), a = [...r].filter((c) => !i.has(c));
|
|
1723
|
+
r = i, this._forgetUnusedPorts(a), this._invalidateTopology();
|
|
1724
|
+
});
|
|
1725
|
+
let n;
|
|
1726
|
+
try {
|
|
1727
|
+
n = t.observeTraffic((i) => this.publishTransit(i));
|
|
1728
|
+
} catch (i) {
|
|
1729
|
+
throw s.dispose(), i;
|
|
1730
|
+
}
|
|
1731
|
+
const o = { dispose: () => {
|
|
1732
|
+
this._sources.get(t) === o && (this._sources.delete(t), s.dispose(), n.dispose(), this._forgetUnusedPorts([...r]), this._invalidateTopology());
|
|
1733
|
+
} };
|
|
1734
|
+
return this._sources.set(t, o), this._invalidateTopology(), o;
|
|
1735
|
+
}
|
|
1736
|
+
trackConnection(t, e) {
|
|
1737
|
+
if (this._assertActive(), this.getGraph("").nodes.some((i) => i.ports.some((a) => a.portId === e.portId))) throw new Error(`Inspection port "${e.portId}" is already registered`);
|
|
1738
|
+
const r = new ss(t, this.nodeId, e, () => this.observerCount !== 0), s = this.addSource(r);
|
|
1739
|
+
let n;
|
|
1740
|
+
try {
|
|
1741
|
+
n = t.onDidClose(() => o.dispose());
|
|
1742
|
+
} catch (i) {
|
|
1743
|
+
throw s.dispose(), i;
|
|
1744
|
+
}
|
|
1745
|
+
const o = { dispose: () => {
|
|
1746
|
+
this._trackedConnections.delete(o), n.dispose(), s.dispose();
|
|
1747
|
+
} };
|
|
1748
|
+
return this._trackedConnections.add(o), o;
|
|
1749
|
+
}
|
|
1750
|
+
expose(t, e) {
|
|
1751
|
+
this._assertActive();
|
|
1752
|
+
const r = e.portId ?? is(), s = new os(r), n = [];
|
|
1753
|
+
this._bindings.add(s);
|
|
1754
|
+
const o = { serviceId: e.serviceId };
|
|
1755
|
+
try {
|
|
1756
|
+
const i = new xt(this.nodeId, r, (a) => this._trafficWatches.accept(a), () => !1);
|
|
1757
|
+
n.push(t.observeWireMessages(i.observe)), n.push({ dispose: () => i.dispose() }), n.push(t.registerInspection(Mt, { getNodeId: () => ({
|
|
1758
|
+
nodeId: this.nodeId,
|
|
1759
|
+
portId: r,
|
|
1760
|
+
...(e.descriptors ?? this._options.descriptors) === void 0 ? {} : { descriptors: [...e.descriptors ?? this._options.descriptors ?? []] }
|
|
1761
|
+
}) }, o)), n.push(t.registerInspection(Lr, {
|
|
1762
|
+
getGraph: () => this.getGraph(e.serviceId, e.includeRoute === !1 ? void 0 : r),
|
|
1763
|
+
watchGraph: (a, c, f) => this._watchGraph(s, f)
|
|
1764
|
+
}, o)), n.push(t.registerInspection(Ur, {
|
|
1765
|
+
watch: (a, c, f) => this._watchTraffic(s, a, f),
|
|
1766
|
+
watchWithPayloads: (a, c, f) => this._watchTraffic(s, a, f)
|
|
1767
|
+
}, o));
|
|
1768
|
+
} catch (i) {
|
|
1769
|
+
for (const a of n.reverse()) a.dispose();
|
|
1770
|
+
throw this._bindings.delete(s), i;
|
|
1771
|
+
}
|
|
1772
|
+
return s.onDispose = () => {
|
|
1773
|
+
this._bindings.delete(s);
|
|
1774
|
+
for (const i of n.reverse()) i.dispose();
|
|
1775
|
+
this._forgetUnusedPorts([r]), this._invalidateTopology();
|
|
1776
|
+
}, n.push(t.onDidClose(() => s.dispose())), this._invalidateTopology(), s;
|
|
1777
|
+
}
|
|
1778
|
+
getGraph(t, e) {
|
|
1779
|
+
this._assertActive();
|
|
1780
|
+
const r = /* @__PURE__ */ new Map(), s = (i) => {
|
|
1781
|
+
const a = r.get(i.nodeId), c = new Map(a == null ? void 0 : a.ports.map((f) => [f.portId, f]));
|
|
1782
|
+
for (const f of i.ports) c.set(f.portId, {
|
|
1783
|
+
...c.get(f.portId),
|
|
1784
|
+
...f
|
|
1785
|
+
});
|
|
1786
|
+
r.set(i.nodeId, {
|
|
1787
|
+
...a,
|
|
1788
|
+
...i,
|
|
1789
|
+
ports: [...c.values()]
|
|
1790
|
+
});
|
|
1791
|
+
};
|
|
1792
|
+
s({
|
|
1793
|
+
nodeId: this.nodeId,
|
|
1794
|
+
kind: this._options.kind ?? "endpoint",
|
|
1795
|
+
...this._options.label === void 0 ? {} : { label: this._options.label },
|
|
1796
|
+
...this._options.descriptors === void 0 ? {} : { descriptors: [...this._options.descriptors] },
|
|
1797
|
+
ports: []
|
|
1798
|
+
});
|
|
1799
|
+
const n = [], o = [];
|
|
1800
|
+
for (const i of this._sources.keys()) {
|
|
1801
|
+
const a = i.snapshotTopology();
|
|
1802
|
+
for (const c of a.nodes) s(c);
|
|
1803
|
+
n.push(...a.links), o.push(...a.routes);
|
|
1804
|
+
}
|
|
1805
|
+
for (const i of this._bindings) s({
|
|
1806
|
+
nodeId: this.nodeId,
|
|
1807
|
+
ports: [{ portId: i.portId }]
|
|
1808
|
+
});
|
|
1809
|
+
return e !== void 0 && o.push({
|
|
1810
|
+
serviceId: t,
|
|
1811
|
+
nodeId: this.nodeId,
|
|
1812
|
+
portId: e,
|
|
1813
|
+
match: "exact"
|
|
1814
|
+
}), {
|
|
1815
|
+
observerServiceId: t,
|
|
1816
|
+
entryNodeId: this.nodeId,
|
|
1817
|
+
nodes: [...r.values()],
|
|
1818
|
+
links: n,
|
|
1819
|
+
routes: o
|
|
1820
|
+
};
|
|
1821
|
+
}
|
|
1822
|
+
publishTransit(t) {
|
|
1823
|
+
if (!(this._disposed || this._trafficWatches.accept(t))) {
|
|
1824
|
+
for (const e of [...this._observers]) try {
|
|
1825
|
+
e(t);
|
|
1826
|
+
} catch {
|
|
1827
|
+
}
|
|
1828
|
+
for (const e of this._subscribers) e.enqueue(t);
|
|
1829
|
+
}
|
|
1830
|
+
}
|
|
1831
|
+
subscribe(t, e) {
|
|
1832
|
+
if (this._assertActive(), t.trafficIgnoreKey !== void 0 && !this._trafficWatches.claim(t.trafficIgnoreKey)) throw new Error("Traffic watch request was not observed before subscription");
|
|
1833
|
+
const r = new Xr(t, e, () => {
|
|
1834
|
+
this._subscribers.delete(r), this._stopUnusedTrafficSources();
|
|
1835
|
+
});
|
|
1836
|
+
this._subscribers.add(r);
|
|
1837
|
+
try {
|
|
1838
|
+
this._startTrafficSources();
|
|
1839
|
+
} catch (s) {
|
|
1840
|
+
throw r.dispose(), s;
|
|
1841
|
+
}
|
|
1842
|
+
return r;
|
|
1843
|
+
}
|
|
1844
|
+
observeTraffic(t) {
|
|
1845
|
+
this._assertActive(), this._observers.add(t);
|
|
1846
|
+
const e = { dispose: () => {
|
|
1847
|
+
this._observers.delete(t), this._stopUnusedTrafficSources();
|
|
1848
|
+
} };
|
|
1849
|
+
try {
|
|
1850
|
+
this._startTrafficSources();
|
|
1851
|
+
} catch (r) {
|
|
1852
|
+
throw e.dispose(), r;
|
|
1853
|
+
}
|
|
1854
|
+
return e;
|
|
1855
|
+
}
|
|
1856
|
+
addTrafficSource(t) {
|
|
1857
|
+
this._assertActive();
|
|
1858
|
+
const e = { source: t };
|
|
1859
|
+
this._trafficSources.add(e);
|
|
1860
|
+
try {
|
|
1861
|
+
this._startTrafficSources();
|
|
1862
|
+
} catch (r) {
|
|
1863
|
+
throw this._trafficSources.delete(e), r;
|
|
1864
|
+
}
|
|
1865
|
+
return { dispose: () => {
|
|
1866
|
+
var r;
|
|
1867
|
+
this._trafficSources.delete(e), (r = e.observation) == null || r.dispose(), e.observation = void 0;
|
|
1868
|
+
} };
|
|
1869
|
+
}
|
|
1870
|
+
dispose() {
|
|
1871
|
+
if (!this._disposed) {
|
|
1872
|
+
this._disposed = !0;
|
|
1873
|
+
for (const t of [...this._bindings]) t.dispose();
|
|
1874
|
+
for (const t of [...this._subscribers]) t.dispose();
|
|
1875
|
+
this._observers.clear(), this._stopUnusedTrafficSources(), this._trafficSources.clear();
|
|
1876
|
+
for (const t of [...this._trackedConnections]) t.dispose();
|
|
1877
|
+
for (const t of [...this._sources.values()]) t.dispose();
|
|
1878
|
+
this._topologyListeners.clear(), this._trafficWatches.clear();
|
|
1879
|
+
}
|
|
1880
|
+
}
|
|
1881
|
+
_startTrafficSources() {
|
|
1882
|
+
if (this.observerCount !== 0)
|
|
1883
|
+
for (const t of this._trafficSources) t.observation ?? (t.observation = t.source.observe((e) => this.publishTransit(e)));
|
|
1884
|
+
}
|
|
1885
|
+
_stopUnusedTrafficSources() {
|
|
1886
|
+
var t;
|
|
1887
|
+
if (this.observerCount === 0)
|
|
1888
|
+
for (const e of this._trafficSources)
|
|
1889
|
+
(t = e.observation) == null || t.dispose(), e.observation = void 0;
|
|
1890
|
+
}
|
|
1891
|
+
_invalidateTopology() {
|
|
1892
|
+
if (!this._disposed)
|
|
1893
|
+
for (const t of this._topologyListeners) t();
|
|
1894
|
+
}
|
|
1895
|
+
_forgetUnusedPorts(t) {
|
|
1896
|
+
if (this._disposed) return;
|
|
1897
|
+
const e = new Set(this.getGraph("").nodes.flatMap((r) => r.ports.map((s) => s.portId)));
|
|
1898
|
+
for (const r of t) e.has(r) || this._trafficWatches.forgetPort(r);
|
|
1899
|
+
}
|
|
1900
|
+
_watchGraph(t, e) {
|
|
1901
|
+
return new Promise((r, s) => {
|
|
1902
|
+
let n = !1, o = !0;
|
|
1903
|
+
const i = () => {
|
|
1904
|
+
o = !1, this._topologyListeners.delete(a), e.signal.removeEventListener("abort", i), t.abort.signal.removeEventListener("abort", i), r({});
|
|
1905
|
+
}, a = () => {
|
|
1906
|
+
n || !o || (n = !0, queueMicrotask(() => {
|
|
1907
|
+
n = !1, o && e.send({}).catch((c) => {
|
|
1908
|
+
s(c), i();
|
|
1909
|
+
});
|
|
1910
|
+
}));
|
|
1911
|
+
};
|
|
1912
|
+
this._topologyListeners.add(a), e.signal.addEventListener("abort", i, { once: !0 }), t.abort.signal.addEventListener("abort", i, { once: !0 }), (e.signal.aborted || t.abort.signal.aborted) && i();
|
|
1913
|
+
});
|
|
1914
|
+
}
|
|
1915
|
+
async _watchTraffic(t, e, r) {
|
|
1916
|
+
const s = this.subscribe(e, (o) => r.send(o)), n = () => s.dispose();
|
|
1917
|
+
r.signal.addEventListener("abort", n, { once: !0 }), t.abort.signal.addEventListener("abort", n, { once: !0 }), (r.signal.aborted || t.abort.signal.aborted) && n();
|
|
1918
|
+
try {
|
|
1919
|
+
return await s.closed;
|
|
1920
|
+
} finally {
|
|
1921
|
+
r.signal.removeEventListener("abort", n), t.abort.signal.removeEventListener("abort", n), s.dispose();
|
|
1922
|
+
}
|
|
1923
|
+
}
|
|
1924
|
+
_assertActive() {
|
|
1925
|
+
if (this._disposed) throw new Error("Inspection host is disposed");
|
|
1926
|
+
}
|
|
1927
|
+
}, os = class {
|
|
1928
|
+
constructor(t) {
|
|
1929
|
+
l(this, "portId");
|
|
1930
|
+
l(this, "abort", new AbortController());
|
|
1931
|
+
l(this, "onDispose", () => {
|
|
1932
|
+
});
|
|
1933
|
+
this.portId = t;
|
|
1934
|
+
}
|
|
1935
|
+
dispose() {
|
|
1936
|
+
this.abort.signal.aborted || (this.abort.abort(), this.onDispose());
|
|
1937
|
+
}
|
|
1938
|
+
};
|
|
1939
|
+
function is() {
|
|
1940
|
+
const t = /* @__PURE__ */ new Uint8Array(16);
|
|
1941
|
+
return globalThis.crypto.getRandomValues(t), `port:${At(t)}`;
|
|
1942
|
+
}
|
|
1943
|
+
var ct = class extends Error {
|
|
1944
|
+
constructor(e, r) {
|
|
1945
|
+
super(`Server error ${e.code} does not match its declared schema: ${r.map((s) => `${s.path || "/"}: ${s.message}`).join("; ")}`);
|
|
1946
|
+
l(this, "original");
|
|
1947
|
+
l(this, "issues");
|
|
1948
|
+
l(this, "kind", "nonCompliantServer");
|
|
1949
|
+
this.original = e, this.issues = r, this.name = "NonCompliantServerError";
|
|
1950
|
+
}
|
|
1951
|
+
};
|
|
1952
|
+
function dt(t) {
|
|
1953
|
+
if (t.includes("::") || !/^[\x20-\x7e]*$/.test(t)) throw new Error('Bare interface prefix must contain only printable ASCII and must not contain "::".');
|
|
1954
|
+
}
|
|
1955
|
+
new Set("break case catch class const continue debugger default delete do else enum export extends false finally for function if import in instanceof new null return super switch this throw true try typeof var void while with implements interface let package private protected public static yield await".split(" "));
|
|
1956
|
+
function as(t) {
|
|
1957
|
+
const e = t.split("::");
|
|
1958
|
+
if (e.length === 3 && e[0].length === 0 && e[1].length > 0 && e[2].length > 0) return {
|
|
1959
|
+
kind: "interface",
|
|
1960
|
+
interfaceId: e[1],
|
|
1961
|
+
member: e[2]
|
|
1962
|
+
};
|
|
1963
|
+
if (!e.some((r) => r.length === 0)) {
|
|
1964
|
+
if (e.length === 1) return {
|
|
1965
|
+
kind: "bare",
|
|
1966
|
+
member: e[0]
|
|
1967
|
+
};
|
|
1968
|
+
if (e.length === 2) return {
|
|
1969
|
+
kind: "interface",
|
|
1970
|
+
interfaceId: e[0],
|
|
1971
|
+
member: e[1]
|
|
1972
|
+
};
|
|
1973
|
+
if (e.length === 3) return {
|
|
1974
|
+
kind: "full",
|
|
1975
|
+
serviceId: e[0],
|
|
1976
|
+
interfaceId: e[1],
|
|
1977
|
+
member: e[2]
|
|
1978
|
+
};
|
|
1979
|
+
}
|
|
1980
|
+
}
|
|
1981
|
+
const cs = "$hubrpcSignature", ds = "$hubrpcUnsigned", fs = "$hubrpc";
|
|
1982
|
+
function ft(t) {
|
|
1983
|
+
if (t === void 0) return;
|
|
1984
|
+
if (t === null || typeof t != "object" || Array.isArray(t)) return t;
|
|
1985
|
+
const e = t, r = [
|
|
1986
|
+
fs,
|
|
1987
|
+
cs,
|
|
1988
|
+
ds
|
|
1989
|
+
];
|
|
1990
|
+
if (!r.some((n) => n in e)) return e;
|
|
1991
|
+
const s = {};
|
|
1992
|
+
for (const n of Object.keys(e))
|
|
1993
|
+
r.includes(n) || (s[n] = e[n]);
|
|
1994
|
+
return s;
|
|
1995
|
+
}
|
|
1996
|
+
const ht = M({
|
|
1997
|
+
id: "hubrpc.defaults",
|
|
1998
|
+
description: "Reflection: preset default service / interface on this connection."
|
|
1999
|
+
}, {
|
|
2000
|
+
get: w(v({}), v({
|
|
2001
|
+
serviceId: g(u()),
|
|
2002
|
+
interfaceId: g(u()),
|
|
2003
|
+
/** Hash of the preset interface, if known. */
|
|
2004
|
+
interfaceHash: g(u())
|
|
2005
|
+
})),
|
|
2006
|
+
listBindings: w(v({}), v({ bindings: T(v({
|
|
2007
|
+
prefix: u(),
|
|
2008
|
+
serviceId: g(u()),
|
|
2009
|
+
interfaceId: u(),
|
|
2010
|
+
interfaceHash: u()
|
|
2011
|
+
})) }))
|
|
2012
|
+
}), hs = v({
|
|
2013
|
+
principal: u(),
|
|
2014
|
+
transitive: g(se())
|
|
2015
|
+
}), ls = T(hs), ze = K([v({ exact: u() }), v({ prefix: u() })]), ps = v({
|
|
2016
|
+
serviceId: u(),
|
|
2017
|
+
interfaceId: u(),
|
|
2018
|
+
/** Hash of the interface as implemented by this service. */
|
|
2019
|
+
interfaceHash: u(),
|
|
2020
|
+
/** Optional, non-authoritative discovery labels of this implemented interface. */
|
|
2021
|
+
tags: g(T(u())),
|
|
2022
|
+
/** Optional non-normative description of the owning service. */
|
|
2023
|
+
serviceDescription: g(u()),
|
|
2024
|
+
/**
|
|
2025
|
+
* Root principals required to access this service, in CNF: the caller must
|
|
2026
|
+
* satisfy **every** set (AND), and a set is satisfied by **any one** of its
|
|
2027
|
+
* principals (OR). Omitted/empty => no root-principal requirement.
|
|
2028
|
+
*/
|
|
2029
|
+
rootPrincipalSets: g(T(ls)),
|
|
2030
|
+
/**
|
|
2031
|
+
* Service-id regions reachable through this referral. Meaningful only for
|
|
2032
|
+
* `hubrpc.directory` entries; omission defaults to the referral service-id
|
|
2033
|
+
* subtree.
|
|
2034
|
+
*/
|
|
2035
|
+
reachableServiceIds: g(T(ze))
|
|
2036
|
+
}), lt = M({
|
|
2037
|
+
id: "hubrpc.directory",
|
|
2038
|
+
description: "Reflection: list services exposed by this endpoint. Can also list other directory services that can be explored."
|
|
2039
|
+
}, {
|
|
2040
|
+
list: w(v({
|
|
2041
|
+
/** Filter: only return services implementing this interface id. */
|
|
2042
|
+
interfaceId: g(u()),
|
|
2043
|
+
/** Filter: only return services whose interface id starts with this prefix. */
|
|
2044
|
+
interfaceIdPrefix: g(u()),
|
|
2045
|
+
/** Filter: only return entries for this service id. */
|
|
2046
|
+
serviceId: g(u()),
|
|
2047
|
+
/** Union filter used to constrain a transitive directory walk. */
|
|
2048
|
+
serviceIdScopes: g(T(ze)),
|
|
2049
|
+
/** Paging: opaque continuation token from a previous response. */
|
|
2050
|
+
cursor: g(u()),
|
|
2051
|
+
/** Paging: max items in this page. Server MAY return fewer. */
|
|
2052
|
+
limit: g(P().check(Y(), Kt())),
|
|
2053
|
+
/** Soft cap on time the server spends gathering this page, in ms. */
|
|
2054
|
+
timeoutMs: g(P().check(Y(), X()))
|
|
2055
|
+
}), v({
|
|
2056
|
+
items: T(ps),
|
|
2057
|
+
/** Omitted => no more pages. */
|
|
2058
|
+
nextCursor: g(u()),
|
|
2059
|
+
/** True if `timeoutMs` cut the page short before exhausting results. */
|
|
2060
|
+
truncated: g(se())
|
|
2061
|
+
})),
|
|
2062
|
+
/**
|
|
2063
|
+
* Coarse change tap on the directory.
|
|
2064
|
+
*
|
|
2065
|
+
* `watch` is a long-lived streaming request that emits an **empty tick**
|
|
2066
|
+
* whenever the (optionally filtered) directory *might* have changed. The
|
|
2067
|
+
* tick carries no delta and no payload — its only meaning is "re-`list`
|
|
2068
|
+
* now". The consumer reconciles against its own last snapshot.
|
|
2069
|
+
*
|
|
2070
|
+
* This keeps the server stateless: it never computes or replays
|
|
2071
|
+
* per-item deltas, never does an initial-sync replay. Over-emission is
|
|
2072
|
+
* allowed (the consumer re-lists and finds nothing new); under-emission
|
|
2073
|
+
* is not. Ticks are coalesced. The `interfaceId` / `serviceId` filters
|
|
2074
|
+
* mirror `list` and are a relevance hint, not a guarantee.
|
|
2075
|
+
*
|
|
2076
|
+
* The request resolves when the caller cancels (or the connection
|
|
2077
|
+
* drops); the runtime auto-detaches the stream when it settles.
|
|
2078
|
+
*/
|
|
2079
|
+
watch: w(v({
|
|
2080
|
+
/** Relevance hint: changes touching this interface id. */
|
|
2081
|
+
interfaceId: g(u()),
|
|
2082
|
+
/** Relevance hint: changes touching an interface id with this prefix. */
|
|
2083
|
+
interfaceIdPrefix: g(u()),
|
|
2084
|
+
/** Relevance hint: changes touching this service id. */
|
|
2085
|
+
serviceId: g(u()),
|
|
2086
|
+
/** Relevance hint: changes within any of these service-id regions. */
|
|
2087
|
+
serviceIdScopes: g(T(ze))
|
|
2088
|
+
}), v({})).withStream({
|
|
2089
|
+
/** Empty tick: "the directory may have changed; re-list." */
|
|
2090
|
+
server: v({})
|
|
2091
|
+
})
|
|
2092
|
+
}), De = M({
|
|
2093
|
+
id: "hubrpc.schemas",
|
|
2094
|
+
description: "Reflection: fetch interface schemas by id (+ optional hash). Must serve the interfaces advertised in this endpoint's directory."
|
|
2095
|
+
}, { get: w(v({
|
|
2096
|
+
interfaceId: u(),
|
|
2097
|
+
/** Omit => server picks the version it exposes. */
|
|
2098
|
+
hash: g(u())
|
|
2099
|
+
}), v({
|
|
2100
|
+
/** A full `SvcInterfaceSchema`. */
|
|
2101
|
+
schema: V()
|
|
2102
|
+
})) });
|
|
2103
|
+
function us(t, e) {
|
|
2104
|
+
return "exact" in e ? t === e.exact : e.prefix === "" || t === e.prefix || t.startsWith(`${e.prefix}/`);
|
|
2105
|
+
}
|
|
2106
|
+
function Lt(t, e) {
|
|
2107
|
+
return e === void 0 || e.some((r) => us(t, r));
|
|
2108
|
+
}
|
|
2109
|
+
var ms = class Wt {
|
|
2110
|
+
constructor(e, r, s) {
|
|
2111
|
+
l(this, "sender");
|
|
2112
|
+
l(this, "_setHandler");
|
|
2113
|
+
l(this, "_setWireObserver");
|
|
2114
|
+
this.sender = e, this._setHandler = r, this._setWireObserver = s;
|
|
2115
|
+
}
|
|
2116
|
+
/** Bind the inbound request/notification handler. May be called before or after construction of {@link LinkRpcConnection}. */
|
|
2117
|
+
setRequestHandler(e) {
|
|
2118
|
+
this._setHandler(e);
|
|
2119
|
+
}
|
|
2120
|
+
/**
|
|
2121
|
+
* Install the endpoint inspection observer at the JSON-RPC wire boundary.
|
|
2122
|
+
* Intended for {@link LinkRpcConnection}; ordinary consumers should use the
|
|
2123
|
+
* public `hubrpc.traffic` service instead.
|
|
2124
|
+
*/
|
|
2125
|
+
setWireMessageObserver(e) {
|
|
2126
|
+
var r;
|
|
2127
|
+
(r = this._setWireObserver) == null || r.call(this, e);
|
|
2128
|
+
}
|
|
2129
|
+
/**
|
|
2130
|
+
* Compose this channel with a sender-side decorator (typically the
|
|
2131
|
+
* signing layer). The decorator wraps {@link sender} only; the
|
|
2132
|
+
* {@link setRequestHandler} binding is shared with the original channel
|
|
2133
|
+
* so the receive side is bound exactly once regardless of decoration depth.
|
|
2134
|
+
*/
|
|
2135
|
+
withSender(e) {
|
|
2136
|
+
return new Wt(e(this.sender), this._setHandler, this._setWireObserver);
|
|
2137
|
+
}
|
|
2138
|
+
}, A = class extends Error {
|
|
2139
|
+
constructor(e, r, s, n = "local", o = s !== void 0) {
|
|
2140
|
+
super(e);
|
|
2141
|
+
l(this, "code");
|
|
2142
|
+
l(this, "origin");
|
|
2143
|
+
l(this, "data");
|
|
2144
|
+
l(this, "hasData");
|
|
2145
|
+
this.code = r, this.origin = n, this.message = e, this.name = "RpcError", this.hasData = o, o && (this.data = s);
|
|
2146
|
+
}
|
|
2147
|
+
};
|
|
2148
|
+
const gs = 6e5;
|
|
2149
|
+
var vs = class zt {
|
|
2150
|
+
constructor(e, r) {
|
|
2151
|
+
l(this, "_transport");
|
|
2152
|
+
l(this, "_requestsDeferred");
|
|
2153
|
+
l(this, "_nextId", 1);
|
|
2154
|
+
l(this, "_pending", /* @__PURE__ */ new Map());
|
|
2155
|
+
/**
|
|
2156
|
+
* Per-request callbacks invoked when a {@link STREAM_METHOD}
|
|
2157
|
+
* notification arrives with a matching `requestId`. Used in both
|
|
2158
|
+
* directions: outgoing-request callers register here keyed by the
|
|
2159
|
+
* id they sent; per-call incoming-request stream handles register
|
|
2160
|
+
* keyed by the id they observed. Entries are removed when the
|
|
2161
|
+
* corresponding request completes (response received for outgoing,
|
|
2162
|
+
* response sent for incoming).
|
|
2163
|
+
*/
|
|
2164
|
+
l(this, "_streamListeners", /* @__PURE__ */ new Map());
|
|
2165
|
+
/**
|
|
2166
|
+
* Per-incoming-request handlers for reserved `control` messages
|
|
2167
|
+
* (cancel / ping / pong) arriving as stream notifications. Keyed
|
|
2168
|
+
* by the id observed; removed when the request settles.
|
|
2169
|
+
*/
|
|
2170
|
+
l(this, "_streamControl", /* @__PURE__ */ new Map());
|
|
2171
|
+
l(this, "_incomingAborts", /* @__PURE__ */ new Map());
|
|
2172
|
+
l(this, "_handler");
|
|
2173
|
+
l(this, "_wireObserver");
|
|
2174
|
+
l(this, "_closeError");
|
|
2175
|
+
l(this, "_deferredMessages", []);
|
|
2176
|
+
this._transport = e, this._requestsDeferred = r, this._transport.setListener((s) => this._onMessage(s));
|
|
2177
|
+
}
|
|
2178
|
+
/**
|
|
2179
|
+
* Wrap a transport in a {@link Channel}. The channel's sender is live
|
|
2180
|
+
* immediately; call {@link Channel.setRequestHandler} (or pass the channel
|
|
2181
|
+
* to {@link LinkRpcConnection}) to bind the inbound handler.
|
|
2182
|
+
*/
|
|
2183
|
+
static create(e) {
|
|
2184
|
+
return this.createWithClose(e).channel;
|
|
2185
|
+
}
|
|
2186
|
+
/**
|
|
2187
|
+
* Wrap a transport with lifecycle hooks. deferRequests queues requests,
|
|
2188
|
+
* notifications, and their input streams until resumeRequests is called.
|
|
2189
|
+
* Responses and output streams remain live for setup-time outbound calls.
|
|
2190
|
+
*/
|
|
2191
|
+
static createWithClose(e, r = {}) {
|
|
2192
|
+
const s = new zt(e, r.deferRequests === !0);
|
|
2193
|
+
return {
|
|
2194
|
+
channel: new ms(s, (n) => s.setRequestHandler(n), (n) => s.setWireMessageObserver(n)),
|
|
2195
|
+
close: () => s.close(),
|
|
2196
|
+
resumeRequests: () => s.resumeRequests()
|
|
2197
|
+
};
|
|
2198
|
+
}
|
|
2199
|
+
setRequestHandler(e) {
|
|
2200
|
+
this._handler = e;
|
|
2201
|
+
}
|
|
2202
|
+
setWireMessageObserver(e) {
|
|
2203
|
+
this._wireObserver = e;
|
|
2204
|
+
}
|
|
2205
|
+
resumeRequests() {
|
|
2206
|
+
for (; this._deferredMessages.length > 0; ) this._dispatchMessage(this._deferredMessages.shift());
|
|
2207
|
+
this._requestsDeferred = !1;
|
|
2208
|
+
}
|
|
2209
|
+
async sendRequest(e, r, s) {
|
|
2210
|
+
this._throwIfClosed();
|
|
2211
|
+
const n = this._nextId++, o = {
|
|
2212
|
+
jsonrpc: "2.0",
|
|
2213
|
+
id: n,
|
|
2214
|
+
method: e
|
|
2215
|
+
};
|
|
2216
|
+
r !== void 0 && (o.params = r);
|
|
2217
|
+
const i = new Promise((a, c) => {
|
|
2218
|
+
this._pending.set(String(n), {
|
|
2219
|
+
resolve: a,
|
|
2220
|
+
reject: c
|
|
2221
|
+
});
|
|
2222
|
+
});
|
|
2223
|
+
this._observeOutbound(o, s);
|
|
2224
|
+
try {
|
|
2225
|
+
await this._transport.send(o);
|
|
2226
|
+
} catch (a) {
|
|
2227
|
+
throw this._pending.delete(String(n)), this._observeSendFailure(n, a), a;
|
|
2228
|
+
}
|
|
2229
|
+
return i;
|
|
2230
|
+
}
|
|
2231
|
+
async sendNotification(e, r, s) {
|
|
2232
|
+
this._throwIfClosed();
|
|
2233
|
+
const n = {
|
|
2234
|
+
jsonrpc: "2.0",
|
|
2235
|
+
method: e
|
|
2236
|
+
};
|
|
2237
|
+
r !== void 0 && (n.params = r), this._observeOutbound(n, s), await this._transport.send(n);
|
|
2238
|
+
}
|
|
2239
|
+
sendRequestWithStream(e, r, s) {
|
|
2240
|
+
var y;
|
|
2241
|
+
this._throwIfClosed();
|
|
2242
|
+
const n = this._nextId++, o = String(n);
|
|
2243
|
+
let i, a;
|
|
2244
|
+
const c = new Promise((_, I) => {
|
|
2245
|
+
i = _, a = I;
|
|
2246
|
+
});
|
|
2247
|
+
this._pending.set(o, {
|
|
2248
|
+
resolve: i,
|
|
2249
|
+
reject: a
|
|
2250
|
+
}), s != null && s.onStreamMessage && this._streamListeners.set(o, s.onStreamMessage);
|
|
2251
|
+
const f = this._makePinger(n, F.toCallee);
|
|
2252
|
+
this._streamControl.set(o, f.onControl);
|
|
2253
|
+
const h = setInterval(() => {
|
|
2254
|
+
this._sendStream(n, F.toCallee, { control: { type: H.ping } });
|
|
2255
|
+
}, gs);
|
|
2256
|
+
(y = h.unref) == null || y.call(h);
|
|
2257
|
+
const p = () => {
|
|
2258
|
+
clearInterval(h), f.dispose(), this._streamControl.delete(o);
|
|
2259
|
+
}, m = (_ = "streaming request disposed") => {
|
|
2260
|
+
this._pending.delete(o) && (this._streamListeners.delete(o), p(), a(new A(_, R.cancelled)));
|
|
2261
|
+
};
|
|
2262
|
+
return c.then(p, p), (async () => {
|
|
2263
|
+
const _ = {
|
|
2264
|
+
jsonrpc: "2.0",
|
|
2265
|
+
id: n,
|
|
2266
|
+
method: e
|
|
2267
|
+
};
|
|
2268
|
+
r !== void 0 && (_.params = r), this._observeOutbound(_, s), await this._transport.send(_);
|
|
2269
|
+
})().catch((_) => {
|
|
2270
|
+
this._pending.delete(o), this._streamListeners.delete(o), this._observeSendFailure(n, _), p(), a(_ instanceof Error ? _ : new Error(String(_)));
|
|
2271
|
+
}), {
|
|
2272
|
+
result: c,
|
|
2273
|
+
send: (_) => this._sendStream(n, F.toCallee, { payload: _ }),
|
|
2274
|
+
cancel: (_) => this._sendStream(n, F.toCallee, { control: _ !== void 0 ? {
|
|
2275
|
+
type: H.cancel,
|
|
2276
|
+
reason: _
|
|
2277
|
+
} : { type: H.cancel } }),
|
|
2278
|
+
dispose: m,
|
|
2279
|
+
ping: f.ping
|
|
2280
|
+
};
|
|
2281
|
+
}
|
|
2282
|
+
/**
|
|
2283
|
+
* Build the symmetric ping/pong machinery for one in-flight request.
|
|
2284
|
+
*
|
|
2285
|
+
* `outboundDir` is the direction *this* side emits controls in
|
|
2286
|
+
* (`toCallee` for the caller, `toCaller` for the callee). A received
|
|
2287
|
+
* ping is answered with a pong in that same direction, echoing the
|
|
2288
|
+
* ping's nonce; a received pong resolves the matching outstanding
|
|
2289
|
+
* {@link ping} probe.
|
|
2290
|
+
*/
|
|
2291
|
+
_makePinger(e, r) {
|
|
2292
|
+
const s = /* @__PURE__ */ new Map();
|
|
2293
|
+
let n = 1;
|
|
2294
|
+
return {
|
|
2295
|
+
ping: () => {
|
|
2296
|
+
const c = `${e}:${n++}`, f = new Promise((h, p) => s.set(c, {
|
|
2297
|
+
resolve: h,
|
|
2298
|
+
reject: p
|
|
2299
|
+
}));
|
|
2300
|
+
return this._sendStream(e, r, { control: {
|
|
2301
|
+
type: H.ping,
|
|
2302
|
+
nonce: c
|
|
2303
|
+
} }), f;
|
|
2304
|
+
},
|
|
2305
|
+
onControl: (c) => {
|
|
2306
|
+
if (c.type === H.ping) this._sendStream(e, r, { control: {
|
|
2307
|
+
type: H.pong,
|
|
2308
|
+
nonce: c.nonce
|
|
2309
|
+
} });
|
|
2310
|
+
else if (c.type === H.pong && c.nonce !== void 0) {
|
|
2311
|
+
const f = s.get(c.nonce);
|
|
2312
|
+
f && (s.delete(c.nonce), f.resolve());
|
|
2313
|
+
}
|
|
2314
|
+
},
|
|
2315
|
+
dispose: () => {
|
|
2316
|
+
const c = new A("Request settled before pong", R.cancelled);
|
|
2317
|
+
for (const f of s.values()) f.reject(c);
|
|
2318
|
+
s.clear();
|
|
2319
|
+
}
|
|
2320
|
+
};
|
|
2321
|
+
}
|
|
2322
|
+
/**
|
|
2323
|
+
* Emit a stream notification ({@link STREAM_METHOD}) associated with
|
|
2324
|
+
* an in-flight request. Internal: outgoing-side callers reach this
|
|
2325
|
+
* via {@link RawStreamingCall.send} / `cancel`; incoming-side handlers
|
|
2326
|
+
* reach it via {@link IncomingStream.send}.
|
|
2327
|
+
*/
|
|
2328
|
+
async _sendStream(e, r, s) {
|
|
2329
|
+
this._throwIfClosed();
|
|
2330
|
+
const n = {
|
|
2331
|
+
requestId: e,
|
|
2332
|
+
dir: r,
|
|
2333
|
+
...s
|
|
2334
|
+
}, o = {
|
|
2335
|
+
jsonrpc: "2.0",
|
|
2336
|
+
method: te,
|
|
2337
|
+
params: n
|
|
2338
|
+
};
|
|
2339
|
+
this._observeOutbound(o), await this._transport.send(o);
|
|
2340
|
+
}
|
|
2341
|
+
close() {
|
|
2342
|
+
if (this._closeError) return;
|
|
2343
|
+
const e = new A("Connection closed", R.peerDisconnected);
|
|
2344
|
+
this._closeError = e, this._deferredMessages.length = 0;
|
|
2345
|
+
for (const r of this._incomingAborts.values()) r.abort(e);
|
|
2346
|
+
this._incomingAborts.clear(), this._transport.dispose();
|
|
2347
|
+
for (const r of this._pending.values()) r.reject(e);
|
|
2348
|
+
this._pending.clear(), this._streamListeners.clear(), this._streamControl.clear();
|
|
2349
|
+
}
|
|
2350
|
+
_throwIfClosed() {
|
|
2351
|
+
if (this._closeError) throw this._closeError;
|
|
2352
|
+
}
|
|
2353
|
+
_onMessage(e) {
|
|
2354
|
+
var r;
|
|
2355
|
+
if (this._observeInbound(e), this._requestsDeferred && !ke(e) && !(Se(e) && e.method === te && ((r = e.params) == null ? void 0 : r.dir) === F.toCaller)) {
|
|
2356
|
+
this._deferredMessages.push(e);
|
|
2357
|
+
return;
|
|
2358
|
+
}
|
|
2359
|
+
this._dispatchMessage(e);
|
|
2360
|
+
}
|
|
2361
|
+
_dispatchMessage(e) {
|
|
2362
|
+
const r = e.context;
|
|
2363
|
+
if (ke(e)) {
|
|
2364
|
+
if (e.id === null) return;
|
|
2365
|
+
const s = String(e.id), n = this._pending.get(s);
|
|
2366
|
+
if (!n) return;
|
|
2367
|
+
if (this._pending.delete(s), this._streamListeners.delete(s), "error" in e) {
|
|
2368
|
+
const o = e.error, i = new A(o.message, o.code, o.data, "remote", Object.hasOwn(o, "data"));
|
|
2369
|
+
n.reject(i);
|
|
2370
|
+
} else n.resolve(e.result);
|
|
2371
|
+
return;
|
|
2372
|
+
}
|
|
2373
|
+
if (yt(e)) {
|
|
2374
|
+
this._handleRequest(e, r).catch(() => {
|
|
2375
|
+
});
|
|
2376
|
+
return;
|
|
2377
|
+
}
|
|
2378
|
+
if (Se(e)) {
|
|
2379
|
+
if (e.method === te) {
|
|
2380
|
+
this._handleStreamNotification(e);
|
|
2381
|
+
return;
|
|
2382
|
+
}
|
|
2383
|
+
this._handleNotification(e, r);
|
|
2384
|
+
return;
|
|
2385
|
+
}
|
|
2386
|
+
}
|
|
2387
|
+
_handleStreamNotification(e) {
|
|
2388
|
+
var i;
|
|
2389
|
+
const r = e.params;
|
|
2390
|
+
if (!r) return;
|
|
2391
|
+
const s = r.requestId;
|
|
2392
|
+
if (s === void 0) return;
|
|
2393
|
+
const n = String(s);
|
|
2394
|
+
if (r.control) {
|
|
2395
|
+
(i = this._streamControl.get(n)) == null || i(r.control);
|
|
2396
|
+
return;
|
|
2397
|
+
}
|
|
2398
|
+
const o = this._streamListeners.get(n);
|
|
2399
|
+
o && o(r.payload);
|
|
2400
|
+
}
|
|
2401
|
+
async _handleRequest(e, r) {
|
|
2402
|
+
const s = String(e.id), n = this._makePinger(e.id, F.toCaller), o = {
|
|
2403
|
+
send: (c) => this._sendStream(e.id, F.toCaller, { payload: c }),
|
|
2404
|
+
onMessage: (c) => {
|
|
2405
|
+
c ? this._streamListeners.set(s, c) : this._streamListeners.delete(s);
|
|
2406
|
+
},
|
|
2407
|
+
ping: n.ping
|
|
2408
|
+
}, i = new AbortController();
|
|
2409
|
+
this._incomingAborts.set(s, i), this._streamControl.set(s, (c) => {
|
|
2410
|
+
c.type === H.cancel ? i.abort(new A(c.reason ?? "cancelled", R.cancelled)) : n.onControl(c);
|
|
2411
|
+
});
|
|
2412
|
+
let a;
|
|
2413
|
+
try {
|
|
2414
|
+
if (!this._handler) a = { error: {
|
|
2415
|
+
code: R.methodNotFound,
|
|
2416
|
+
message: `No handler registered on this endpoint (method: ${e.method}).`
|
|
2417
|
+
} };
|
|
2418
|
+
else try {
|
|
2419
|
+
a = await this._handler.handleRequest({
|
|
2420
|
+
method: e.method,
|
|
2421
|
+
params: e.params,
|
|
2422
|
+
context: r,
|
|
2423
|
+
stream: o,
|
|
2424
|
+
signal: i.signal
|
|
2425
|
+
});
|
|
2426
|
+
} catch (c) {
|
|
2427
|
+
a = { error: {
|
|
2428
|
+
code: R.internalError,
|
|
2429
|
+
message: c instanceof Error ? c.message : String(c)
|
|
2430
|
+
} };
|
|
2431
|
+
}
|
|
2432
|
+
} finally {
|
|
2433
|
+
this._streamListeners.delete(s), this._streamControl.delete(s), this._incomingAborts.delete(s), n.dispose();
|
|
2434
|
+
}
|
|
2435
|
+
if ("result" in a) {
|
|
2436
|
+
const c = {
|
|
2437
|
+
jsonrpc: "2.0",
|
|
2438
|
+
id: e.id,
|
|
2439
|
+
result: a.result
|
|
2440
|
+
};
|
|
2441
|
+
this._observeOutbound(c), await this._transport.send(c);
|
|
2442
|
+
} else {
|
|
2443
|
+
const c = {
|
|
2444
|
+
jsonrpc: "2.0",
|
|
2445
|
+
id: e.id,
|
|
2446
|
+
error: a.error
|
|
2447
|
+
};
|
|
2448
|
+
this._observeOutbound(c), await this._transport.send(c);
|
|
2449
|
+
}
|
|
2450
|
+
}
|
|
2451
|
+
_handleNotification(e, r) {
|
|
2452
|
+
if (this._handler)
|
|
2453
|
+
try {
|
|
2454
|
+
this._handler.handleNotification({
|
|
2455
|
+
method: e.method,
|
|
2456
|
+
params: e.params,
|
|
2457
|
+
context: r,
|
|
2458
|
+
stream: _s,
|
|
2459
|
+
signal: bs
|
|
2460
|
+
});
|
|
2461
|
+
} catch {
|
|
2462
|
+
}
|
|
2463
|
+
}
|
|
2464
|
+
_observeInbound(e) {
|
|
2465
|
+
const r = this._wireObserver;
|
|
2466
|
+
r !== void 0 && r("inbound", e);
|
|
2467
|
+
}
|
|
2468
|
+
_observeOutbound(e, r) {
|
|
2469
|
+
const s = this._wireObserver;
|
|
2470
|
+
s !== void 0 && s("outbound", e);
|
|
2471
|
+
}
|
|
2472
|
+
_observeSendFailure(e, r) {
|
|
2473
|
+
this._wireObserver !== void 0 && this._observeInbound({
|
|
2474
|
+
jsonrpc: "2.0",
|
|
2475
|
+
id: e,
|
|
2476
|
+
error: {
|
|
2477
|
+
code: R.peerDisconnected,
|
|
2478
|
+
message: r instanceof Error ? r.message : String(r)
|
|
2479
|
+
}
|
|
2480
|
+
});
|
|
2481
|
+
}
|
|
2482
|
+
};
|
|
2483
|
+
const _s = {
|
|
2484
|
+
send: () => Promise.resolve(),
|
|
2485
|
+
onMessage: () => {
|
|
2486
|
+
},
|
|
2487
|
+
ping: () => Promise.resolve()
|
|
2488
|
+
}, bs = new AbortController().signal;
|
|
2489
|
+
function pt(t) {
|
|
2490
|
+
return typeof t == "object" && t !== null && "interface" in t && "mode" in t && (t.mode === "qualified" || t.mode === "default" || t.mode === "bare");
|
|
2491
|
+
}
|
|
2492
|
+
var ws = class Dt {
|
|
2493
|
+
/**
|
|
2494
|
+
* Construct from a {@link Channel} (binds the inbound handler and uses
|
|
2495
|
+
* `channel.sender` for outbound calls) or from a bare
|
|
2496
|
+
* {@link IRequestSender} (send-only — no inbound handler is registered,
|
|
2497
|
+
* useful for bootstrap flows like `createManagedIdentity`).
|
|
2498
|
+
*/
|
|
2499
|
+
constructor(e, r = {}) {
|
|
2500
|
+
/** Underlying JSON-RPC sender — useful for callers that need raw access (e.g. to call hub-served methods that bypass the interface registry). */
|
|
2501
|
+
l(this, "channel");
|
|
2502
|
+
/** key = `${serviceId ?? ""}::${interfaceId}` */
|
|
2503
|
+
l(this, "_registry", /* @__PURE__ */ new Map());
|
|
2504
|
+
/** Descriptions for services that have been registered with a `serviceDescription`. */
|
|
2505
|
+
l(this, "_serviceDescriptions", /* @__PURE__ */ new Map());
|
|
2506
|
+
/** Root-node-id requirement sets recorded per serviceId. */
|
|
2507
|
+
l(this, "_serviceRootPrincipalSets", /* @__PURE__ */ new Map());
|
|
2508
|
+
l(this, "_directoryWatchers", /* @__PURE__ */ new Set());
|
|
2509
|
+
l(this, "_directoryListeners", /* @__PURE__ */ new Set());
|
|
2510
|
+
l(this, "_inspection");
|
|
2511
|
+
l(this, "_inspectionHost");
|
|
2512
|
+
l(this, "_serviceInspectionRegistrations", /* @__PURE__ */ new Map());
|
|
2513
|
+
l(this, "_wireObservers", /* @__PURE__ */ new Set());
|
|
2514
|
+
l(this, "_closeListeners", /* @__PURE__ */ new Set());
|
|
2515
|
+
l(this, "_closed", !1);
|
|
2516
|
+
l(this, "_wireChannel");
|
|
2517
|
+
l(this, "_validateOutboundParams");
|
|
2518
|
+
/** Bare-method bindings, keyed by their exact wire prefix. */
|
|
2519
|
+
l(this, "_bareBindings", /* @__PURE__ */ new Map());
|
|
2520
|
+
l(this, "_generateTopologyId");
|
|
2521
|
+
this._validateOutboundParams = r.validateOutboundParams !== !1, this._generateTopologyId = r.generateTopologyId ?? ys, "sender" in e ? (this._wireChannel = e, this.channel = e.sender, e.setRequestHandler({
|
|
2522
|
+
handleRequest: (s) => this._handleRequest(s),
|
|
2523
|
+
handleNotification: (s) => this._handleNotification(s)
|
|
2524
|
+
})) : (this._wireChannel = void 0, this.channel = e);
|
|
2525
|
+
}
|
|
2526
|
+
/**
|
|
2527
|
+
* Convenience: build a {@link JsonRpcChannel} `Channel` from the
|
|
2528
|
+
* given transport and wrap it in an `LinkRpcConnection`. Use this
|
|
2529
|
+
* when you have a transport at hand and don't need a decorator
|
|
2530
|
+
* stack (e.g. signing).
|
|
2531
|
+
*/
|
|
2532
|
+
static fromTransport(e, r = {}) {
|
|
2533
|
+
return new Dt(vs.create(e), r);
|
|
2534
|
+
}
|
|
2535
|
+
get(e, r) {
|
|
2536
|
+
return this._getClient(e, r, !1);
|
|
2537
|
+
}
|
|
2538
|
+
_getClient(e, r, s) {
|
|
2539
|
+
if (pt(e)) {
|
|
2540
|
+
if (r !== void 0) throw new Error(`${s ? "getResultClient" : "get"}: ${e.mode === "bare" ? "bare " : ""}interface targets do not accept service or call options.`);
|
|
2541
|
+
return e.mode === "bare" ? this._buildBareClient(e.interface, e.prefix, s) : this._buildClient(e.interface, e.mode === "qualified" ? { serviceId: e.serviceId } : {}, void 0, e.mode === "default", s);
|
|
2542
|
+
}
|
|
2543
|
+
return this._buildClient(e, r ?? {}, void 0, !1, s);
|
|
2544
|
+
}
|
|
2545
|
+
/**
|
|
2546
|
+
* Get a typed client that emits foreign-protocol bare method names.
|
|
2547
|
+
* Unlike {@link get}, these calls carry no LinkRPC interface metadata.
|
|
2548
|
+
*/
|
|
2549
|
+
getBare(e, r = {}) {
|
|
2550
|
+
return this._buildBareClient(e, r.prefix ?? "", !1);
|
|
2551
|
+
}
|
|
2552
|
+
_buildBareClient(e, r, s) {
|
|
2553
|
+
dt(r);
|
|
2554
|
+
for (const [n, o] of Object.entries(e.members)) if (o.kind === "request" && (o.clientStreamSchema !== void 0 || o.serverStreamSchema !== void 0)) throw new Error(`getBare: streaming method "${n}" is not supported on foreign wires.`);
|
|
2555
|
+
return this._buildClient(e, {}, r, !1, s);
|
|
2556
|
+
}
|
|
2557
|
+
getResultClient(e, r) {
|
|
2558
|
+
return this._getClient(e, r, !0);
|
|
2559
|
+
}
|
|
2560
|
+
/** Get a service-scoped handle; all interfaces obtained from it route via `serviceId` (form 3). */
|
|
2561
|
+
service(e) {
|
|
2562
|
+
return new Os(this, e);
|
|
2563
|
+
}
|
|
2564
|
+
/** Register handlers, adding preset routing when passed a default or bare target. */
|
|
2565
|
+
register(e, r, s = {}) {
|
|
2566
|
+
if (pt(e)) {
|
|
2567
|
+
if (e.mode === "qualified") {
|
|
2568
|
+
if (s.serviceId !== void 0 && s.serviceId !== e.serviceId) throw new Error("register: serviceId conflicts with interface target.");
|
|
2569
|
+
return this._register(e.interface, r, {
|
|
2570
|
+
...s,
|
|
2571
|
+
serviceId: e.serviceId || void 0
|
|
2572
|
+
}, !1);
|
|
2573
|
+
}
|
|
2574
|
+
const n = e.mode === "bare" ? e.prefix : "";
|
|
2575
|
+
return dt(n), this._register(e.interface, r, s, !1, n);
|
|
2576
|
+
}
|
|
2577
|
+
return this._register(e, r, s, !1);
|
|
2578
|
+
}
|
|
2579
|
+
/** Register inspection contracts without recursively enabling service inspection. */
|
|
2580
|
+
registerInspection(e, r, s = {}) {
|
|
2581
|
+
return this._register(e, r, s, !0);
|
|
2582
|
+
}
|
|
2583
|
+
/** Observe this connection without replacing another inspection scope's observer. */
|
|
2584
|
+
observeWireMessages(e) {
|
|
2585
|
+
if (this._closed) throw new Error("Connection is closed");
|
|
2586
|
+
if (this._wireChannel === void 0) throw new Error("Connection has no observable wire channel");
|
|
2587
|
+
return this._wireObservers.add(e), this._wireChannel.setWireMessageObserver((r, s) => {
|
|
2588
|
+
for (const n of [...this._wireObservers]) try {
|
|
2589
|
+
n(r, s);
|
|
2590
|
+
} catch {
|
|
2591
|
+
}
|
|
2592
|
+
}), { dispose: () => {
|
|
2593
|
+
var r;
|
|
2594
|
+
this._wireObservers.delete(e), this._wireObservers.size === 0 && ((r = this._wireChannel) == null || r.setWireMessageObserver(void 0));
|
|
2595
|
+
} };
|
|
2596
|
+
}
|
|
2597
|
+
onDidClose(e) {
|
|
2598
|
+
if (this._closed) throw new Error("Connection is closed");
|
|
2599
|
+
return this._closeListeners.add(e), { dispose: () => {
|
|
2600
|
+
this._closeListeners.delete(e);
|
|
2601
|
+
} };
|
|
2602
|
+
}
|
|
2603
|
+
_register(e, r, s, n, o) {
|
|
2604
|
+
const i = s.serviceId, a = `${i ?? ""}::${e.info.id}`;
|
|
2605
|
+
if (this._registry.has(a)) throw new Error(`Interface "${e.info.id}" already registered${i ? ` under service "${i}"` : ""}.`);
|
|
2606
|
+
if (o !== void 0 && this._bareBindings.has(o)) throw new Error(`Bare interface prefix "${o}" is already registered.`);
|
|
2607
|
+
let c = !1;
|
|
2608
|
+
if (s.serviceDescription !== void 0) {
|
|
2609
|
+
if (i === void 0) throw new Error("register: `serviceDescription` requires `serviceId`.");
|
|
2610
|
+
const m = this._serviceDescriptions.get(i);
|
|
2611
|
+
if (m !== void 0 && m !== s.serviceDescription) throw new Error(`register: conflicting descriptions for service "${i}".`);
|
|
2612
|
+
c = m === void 0;
|
|
2613
|
+
}
|
|
2614
|
+
let f = !1;
|
|
2615
|
+
if (s.rootPrincipalSets !== void 0) {
|
|
2616
|
+
if (i === void 0) throw new Error("register: `rootPrincipalSets` requires `serviceId`.");
|
|
2617
|
+
const m = this._serviceRootPrincipalSets.get(i);
|
|
2618
|
+
if (m !== void 0 && !Is(m, s.rootPrincipalSets)) throw new Error(`register: conflicting rootPrincipalSets for service "${i}".`);
|
|
2619
|
+
f = m === void 0;
|
|
2620
|
+
}
|
|
2621
|
+
const h = {
|
|
2622
|
+
iface: e,
|
|
2623
|
+
handlers: e.flattenHandlers(r),
|
|
2624
|
+
serviceId: i,
|
|
2625
|
+
internalInspection: n
|
|
2626
|
+
};
|
|
2627
|
+
if (c && this._serviceDescriptions.set(i, s.serviceDescription), f && this._serviceRootPrincipalSets.set(i, s.rootPrincipalSets), this._registry.set(a, h), o !== void 0 && this._bareBindings.set(o, {
|
|
2628
|
+
prefix: o,
|
|
2629
|
+
entry: h
|
|
2630
|
+
}), this._notifyDirectoryWatchers(h, c || f), !n && i !== void 0 && this._inspection !== void 0 && !this._serviceInspectionRegistrations.has(i)) try {
|
|
2631
|
+
this._installServiceInspection(i);
|
|
2632
|
+
} catch (m) {
|
|
2633
|
+
throw this._registry.delete(a), o !== void 0 && this._bareBindings.delete(o), c && this._serviceDescriptions.delete(i), f && this._serviceRootPrincipalSets.delete(i), this._notifyDirectoryWatchers(h), m;
|
|
2634
|
+
}
|
|
2635
|
+
let p = !1;
|
|
2636
|
+
return { dispose: () => {
|
|
2637
|
+
if (!p && (p = !0, this._registry.get(a) === h)) {
|
|
2638
|
+
this._registry.delete(a);
|
|
2639
|
+
for (const [m, y] of this._bareBindings) y.entry === h && this._bareBindings.delete(m);
|
|
2640
|
+
this._notifyDirectoryWatchers(h), i !== void 0 && !this._hasBusinessServiceRegistration(i) && (this._removeServiceInspection(i), this._serviceDescriptions.delete(i), this._serviceRootPrincipalSets.delete(i));
|
|
2641
|
+
}
|
|
2642
|
+
} };
|
|
2643
|
+
}
|
|
2644
|
+
/** Snapshot of every interface currently registered on this connection. */
|
|
2645
|
+
listRegisteredInterfaces() {
|
|
2646
|
+
return Array.from(this._registry.values()).map((e) => {
|
|
2647
|
+
const r = e.serviceId ?? "", s = {
|
|
2648
|
+
serviceId: r,
|
|
2649
|
+
interfaceId: e.iface.info.id,
|
|
2650
|
+
interfaceHash: e.iface.schemaHash
|
|
2651
|
+
};
|
|
2652
|
+
e.iface.info.tags !== void 0 && (s.tags = e.iface.info.tags);
|
|
2653
|
+
const n = r === "" ? void 0 : this._serviceDescriptions.get(r);
|
|
2654
|
+
n !== void 0 && (s.serviceDescription = n);
|
|
2655
|
+
const o = r === "" ? void 0 : this._serviceRootPrincipalSets.get(r);
|
|
2656
|
+
return o !== void 0 && (s.rootPrincipalSets = o), s;
|
|
2657
|
+
});
|
|
2658
|
+
}
|
|
2659
|
+
/** Subscribe to coarse local directory changes; listeners must re-list. */
|
|
2660
|
+
onDidChangeDirectory(e) {
|
|
2661
|
+
return this._directoryListeners.add(e), () => this._directoryListeners.delete(e);
|
|
2662
|
+
}
|
|
2663
|
+
/**
|
|
2664
|
+
* Look up a registered interface definition by id (and optional content
|
|
2665
|
+
* hash). Returns `undefined` if no registered interface matches.
|
|
2666
|
+
*/
|
|
2667
|
+
findRegisteredInterface(e, r) {
|
|
2668
|
+
let s;
|
|
2669
|
+
for (const n of this._registry.values())
|
|
2670
|
+
n.iface.info.id === e && (r !== void 0 && n.iface.schemaHash !== r || (s === void 0 || _r(s.toSchema(), n.iface.toSchema()) === n.iface.toSchema()) && (s = n.iface));
|
|
2671
|
+
return s;
|
|
2672
|
+
}
|
|
2673
|
+
/**
|
|
2674
|
+
* Register the three linkrpc reflection interfaces (`defaults`,
|
|
2675
|
+
* `directory`, `schemas`), backed by this connection's live registry.
|
|
2676
|
+
*
|
|
2677
|
+
* By default they live under the root service (form-2 reachable as
|
|
2678
|
+
* `hubrpc.directory::list`). Pass `serviceId` to additionally mount
|
|
2679
|
+
* them under a specific service — useful for participants that live
|
|
2680
|
+
* behind a hub, so callers can reach reflection via form-3
|
|
2681
|
+
* `<serviceId>::hubrpc.directory::list`.
|
|
2682
|
+
*
|
|
2683
|
+
* Idempotent: re-registering the same `(serviceId, interfaceId)` pair
|
|
2684
|
+
* is a no-op.
|
|
2685
|
+
*/
|
|
2686
|
+
enableReflection(e = {}) {
|
|
2687
|
+
const r = `${e.serviceId ?? ""}::${ht.info.id}`;
|
|
2688
|
+
if (this._registry.has(r)) return { dispose() {
|
|
2689
|
+
} };
|
|
2690
|
+
const s = `${e.serviceId ?? ""}::`;
|
|
2691
|
+
for (const a of [lt, De]) if (this._registry.has(`${s}${a.info.id}`)) throw new Error(`enableReflection: partial reflection registration for service "${e.serviceId ?? ""}".`);
|
|
2692
|
+
const n = e.serviceId !== void 0 ? { serviceId: e.serviceId } : {}, o = [];
|
|
2693
|
+
if (o.push(this.register(ht, {
|
|
2694
|
+
get: () => {
|
|
2695
|
+
const a = this._bareBindings.get("");
|
|
2696
|
+
return a ? {
|
|
2697
|
+
serviceId: a.entry.serviceId,
|
|
2698
|
+
interfaceId: a.entry.iface.info.id,
|
|
2699
|
+
interfaceHash: a.entry.iface.schemaHash
|
|
2700
|
+
} : {};
|
|
2701
|
+
},
|
|
2702
|
+
listBindings: () => ({ bindings: Array.from(this._bareBindings.values()).sort((a, c) => a.prefix < c.prefix ? -1 : a.prefix > c.prefix ? 1 : 0).map((a) => ({
|
|
2703
|
+
prefix: a.prefix,
|
|
2704
|
+
serviceId: a.entry.serviceId,
|
|
2705
|
+
interfaceId: a.entry.iface.info.id,
|
|
2706
|
+
interfaceHash: a.entry.iface.schemaHash
|
|
2707
|
+
})) })
|
|
2708
|
+
}, n)), o.push(this.register(lt, {
|
|
2709
|
+
list: ({ interfaceId: a, interfaceIdPrefix: c, serviceId: f, serviceIdScopes: h, cursor: p, limit: m }) => {
|
|
2710
|
+
const y = this.listRegisteredInterfaces().filter((S) => e.serviceId === void 0 || S.serviceId === e.serviceId).filter((S) => a === void 0 || S.interfaceId === a).filter((S) => c === void 0 || S.interfaceId.startsWith(c)).filter((S) => f === void 0 || S.serviceId === f).filter((S) => Lt(S.serviceId, h)), _ = p === void 0 ? 0 : Number.parseInt(p, 10) || 0, I = m === void 0 ? y.length : Math.min(y.length, _ + m), j = y.slice(_, I).map((S) => {
|
|
2711
|
+
var x;
|
|
2712
|
+
return {
|
|
2713
|
+
serviceId: S.serviceId,
|
|
2714
|
+
interfaceId: S.interfaceId,
|
|
2715
|
+
interfaceHash: S.interfaceHash,
|
|
2716
|
+
tags: S.tags === void 0 ? void 0 : [...S.tags],
|
|
2717
|
+
serviceDescription: S.serviceDescription,
|
|
2718
|
+
rootPrincipalSets: (x = S.rootPrincipalSets) == null ? void 0 : x.map((E) => E.map(($) => ({ ...$ })))
|
|
2719
|
+
};
|
|
2720
|
+
});
|
|
2721
|
+
return I < y.length ? {
|
|
2722
|
+
items: j,
|
|
2723
|
+
nextCursor: String(I)
|
|
2724
|
+
} : { items: j };
|
|
2725
|
+
},
|
|
2726
|
+
watch: (a, c, f) => new Promise((h) => {
|
|
2727
|
+
const p = {
|
|
2728
|
+
interfaceId: a.interfaceId,
|
|
2729
|
+
interfaceIdPrefix: a.interfaceIdPrefix,
|
|
2730
|
+
serviceId: a.serviceId,
|
|
2731
|
+
serviceIdScopes: a.serviceIdScopes,
|
|
2732
|
+
send: () => f.send({})
|
|
2733
|
+
};
|
|
2734
|
+
this._directoryWatchers.add(p);
|
|
2735
|
+
const m = () => {
|
|
2736
|
+
this._directoryWatchers.delete(p), h({});
|
|
2737
|
+
};
|
|
2738
|
+
if (f.signal.aborted) {
|
|
2739
|
+
m();
|
|
2740
|
+
return;
|
|
2741
|
+
}
|
|
2742
|
+
f.signal.addEventListener("abort", m, { once: !0 });
|
|
2743
|
+
})
|
|
2744
|
+
}, n)), o.push(this.register(De, { get: ({ interfaceId: a, hash: c }) => {
|
|
2745
|
+
const f = this.findRegisteredInterface(a, c);
|
|
2746
|
+
if (!f) throw new A("Interface not found", R.methodNotFound, {
|
|
2747
|
+
reason: "unknown-interface",
|
|
2748
|
+
interfaceId: a,
|
|
2749
|
+
hash: c
|
|
2750
|
+
});
|
|
2751
|
+
return { schema: f.toSchema() };
|
|
2752
|
+
} }, n)), e.serviceId !== void 0) try {
|
|
2753
|
+
this.enableReflection();
|
|
2754
|
+
} catch (a) {
|
|
2755
|
+
for (const c of o.reverse()) c.dispose();
|
|
2756
|
+
throw a;
|
|
2757
|
+
}
|
|
2758
|
+
let i = !1;
|
|
2759
|
+
return { dispose: () => {
|
|
2760
|
+
if (!i) {
|
|
2761
|
+
i = !0;
|
|
2762
|
+
for (const a of o.reverse()) a.dispose();
|
|
2763
|
+
}
|
|
2764
|
+
} };
|
|
2765
|
+
}
|
|
2766
|
+
_notifyDirectoryWatchers(e, r = !1) {
|
|
2767
|
+
for (const s of this._directoryListeners) try {
|
|
2768
|
+
s();
|
|
2769
|
+
} catch {
|
|
2770
|
+
}
|
|
2771
|
+
for (const s of this._directoryWatchers) {
|
|
2772
|
+
if (s.pending) continue;
|
|
2773
|
+
const n = ut(s, e), o = r && e.serviceId !== void 0 && [...this._registry.values()].some((i) => i.serviceId === e.serviceId && ut(s, i));
|
|
2774
|
+
!n && !o || (s.pending = !0, queueMicrotask(() => {
|
|
2775
|
+
s.pending = !1, this._directoryWatchers.has(s) && s.send();
|
|
2776
|
+
}));
|
|
2777
|
+
}
|
|
2778
|
+
}
|
|
2779
|
+
/**
|
|
2780
|
+
* Enable the root `hubrpc.node::getNodeId` topology-bootstrap service.
|
|
2781
|
+
*
|
|
2782
|
+
* The generated ids are stable while this registration is active. They are
|
|
2783
|
+
* unauthenticated correlation labels only; callers must not use them for
|
|
2784
|
+
* identity, capability, or authorization decisions.
|
|
2785
|
+
*/
|
|
2786
|
+
enableInspection(e) {
|
|
2787
|
+
if (this._inspection !== void 0) return this._inspection;
|
|
2788
|
+
const r = {
|
|
2789
|
+
nodeId: this._generateTopologyId("node"),
|
|
2790
|
+
portId: this._generateTopologyId("port"),
|
|
2791
|
+
...e !== void 0 ? { descriptors: [...e] } : {}
|
|
2792
|
+
}, s = this._register(Mt, { getNodeId: () => r }, {}, !0), n = new ns({
|
|
2793
|
+
nodeId: r.nodeId,
|
|
2794
|
+
descriptors: e
|
|
2795
|
+
});
|
|
2796
|
+
try {
|
|
2797
|
+
this._wireChannel !== void 0 && n.trackConnection(this, { portId: r.portId });
|
|
2798
|
+
} catch (a) {
|
|
2799
|
+
throw n.dispose(), s.dispose(), a;
|
|
2800
|
+
}
|
|
2801
|
+
this._inspectionHost = n;
|
|
2802
|
+
let o = !1;
|
|
2803
|
+
const i = {
|
|
2804
|
+
...r,
|
|
2805
|
+
observeTraffic: (a) => n.observeTraffic(a),
|
|
2806
|
+
dispose: () => {
|
|
2807
|
+
if (!o) {
|
|
2808
|
+
o = !0;
|
|
2809
|
+
for (const a of [...this._serviceInspectionRegistrations.keys()]) this._removeServiceInspection(a);
|
|
2810
|
+
n.dispose(), this._inspectionHost === n && (this._inspectionHost = void 0), s.dispose(), this._inspection === i && (this._inspection = void 0);
|
|
2811
|
+
}
|
|
2812
|
+
}
|
|
2813
|
+
};
|
|
2814
|
+
this._inspection = i;
|
|
2815
|
+
try {
|
|
2816
|
+
const a = new Set(Array.from(this._registry.values()).filter((c) => c.serviceId !== void 0 && !c.internalInspection).map((c) => c.serviceId));
|
|
2817
|
+
for (const c of a) this._installServiceInspection(c);
|
|
2818
|
+
} catch (a) {
|
|
2819
|
+
throw i.dispose(), a;
|
|
2820
|
+
}
|
|
2821
|
+
return i;
|
|
2822
|
+
}
|
|
2823
|
+
/** Number of active endpoint traffic stream subscribers. */
|
|
2824
|
+
get trafficObserverCount() {
|
|
2825
|
+
var e;
|
|
2826
|
+
return ((e = this._inspectionHost) == null ? void 0 : e.observerCount) ?? 0;
|
|
2827
|
+
}
|
|
2828
|
+
close() {
|
|
2829
|
+
var e, r;
|
|
2830
|
+
if (!this._closed) {
|
|
2831
|
+
this._closed = !0;
|
|
2832
|
+
for (const s of [...this._closeListeners]) s();
|
|
2833
|
+
this._closeListeners.clear(), (e = this._inspection) == null || e.dispose(), this._wireObservers.clear(), (r = this._wireChannel) == null || r.setWireMessageObserver(void 0), this.channel.close();
|
|
2834
|
+
}
|
|
2835
|
+
}
|
|
2836
|
+
_buildClient(e, r, s, n = !1, o = !1) {
|
|
2837
|
+
const { serviceId: i, ...a } = r, c = s === void 0 ? {
|
|
2838
|
+
ctx: a,
|
|
2839
|
+
interfaceHash: e.schemaHash
|
|
2840
|
+
} : void 0, f = s ?? (n ? "" : i ? `${i}::${e.info.id}::` : `${e.info.id}::`), h = /* @__PURE__ */ Object.create(null);
|
|
2841
|
+
for (const [p, m] of Object.entries(e.members)) {
|
|
2842
|
+
const y = `${f}${p}`;
|
|
2843
|
+
if (m.kind === "request")
|
|
2844
|
+
if (m.clientStreamSchema !== void 0 || m.serverStreamSchema !== void 0) {
|
|
2845
|
+
const _ = m.serverStreamSchema;
|
|
2846
|
+
h[p] = (I, j) => {
|
|
2847
|
+
const S = j == null ? void 0 : j.onMessage, x = S !== void 0 ? (O) => {
|
|
2848
|
+
if (_ !== void 0) {
|
|
2849
|
+
const L = z(_, O);
|
|
2850
|
+
if (!L.success) return;
|
|
2851
|
+
S(L.data);
|
|
2852
|
+
return;
|
|
2853
|
+
}
|
|
2854
|
+
S(O);
|
|
2855
|
+
} : void 0, E = x !== void 0 ? {
|
|
2856
|
+
...c,
|
|
2857
|
+
onStreamMessage: x
|
|
2858
|
+
} : c;
|
|
2859
|
+
let $;
|
|
2860
|
+
try {
|
|
2861
|
+
this._validateOutboundParamsFor(m, y, I), $ = this.channel.sendRequestWithStream(y, I, E);
|
|
2862
|
+
} catch (O) {
|
|
2863
|
+
if (!o) throw O;
|
|
2864
|
+
$ = {
|
|
2865
|
+
result: Promise.reject(O),
|
|
2866
|
+
send: () => {
|
|
2867
|
+
throw O;
|
|
2868
|
+
},
|
|
2869
|
+
cancel: () => {
|
|
2870
|
+
throw O;
|
|
2871
|
+
},
|
|
2872
|
+
ping: async () => {
|
|
2873
|
+
throw O;
|
|
2874
|
+
}
|
|
2875
|
+
};
|
|
2876
|
+
}
|
|
2877
|
+
const J = mt($.result.then((O) => gt(m.resultSchema, O, y)), m, o);
|
|
2878
|
+
return Object.assign(J, {
|
|
2879
|
+
send: async (O) => $.send(O),
|
|
2880
|
+
cancel: async (O) => $.cancel(O),
|
|
2881
|
+
dispose: (O) => {
|
|
2882
|
+
var L;
|
|
2883
|
+
return (L = $.dispose) == null ? void 0 : L.call($, O);
|
|
2884
|
+
},
|
|
2885
|
+
ping: () => $.ping()
|
|
2886
|
+
});
|
|
2887
|
+
};
|
|
2888
|
+
} else h[p] = (_) => mt((async () => {
|
|
2889
|
+
this._validateOutboundParamsFor(m, y, _);
|
|
2890
|
+
const I = await this.channel.sendRequest(y, _, c);
|
|
2891
|
+
return gt(m.resultSchema, I, y);
|
|
2892
|
+
})(), m, o);
|
|
2893
|
+
else {
|
|
2894
|
+
const _ = (I) => {
|
|
2895
|
+
this._validateOutboundParamsFor(m, y, I), this.channel.sendNotification(y, I, c);
|
|
2896
|
+
};
|
|
2897
|
+
h[p] = s === void 0 ? async (I) => _(I) : _;
|
|
2898
|
+
}
|
|
2899
|
+
}
|
|
2900
|
+
return e.nestClient(h);
|
|
2901
|
+
}
|
|
2902
|
+
_validateOutboundParamsFor(e, r, s) {
|
|
2903
|
+
this._validateOutboundParams && He(e.paramsSchema, s, `Invalid params for ${r}`, R.invalidParams);
|
|
2904
|
+
}
|
|
2905
|
+
async _handleRequest(e) {
|
|
2906
|
+
const r = this._parseRouted(e.method);
|
|
2907
|
+
if (!r.ok) return ne(r.reason, e.method);
|
|
2908
|
+
const { entry: s, memberName: n } = r, o = s.iface.members[n];
|
|
2909
|
+
if (!o) return ne("unknown-method", e.method);
|
|
2910
|
+
const i = s.handlers[n];
|
|
2911
|
+
if (!i) return ne("unknown-method", e.method);
|
|
2912
|
+
const a = ft(e.params), c = z(o.paramsSchema, a);
|
|
2913
|
+
if (!c.success) return { error: {
|
|
2914
|
+
code: R.invalidParams,
|
|
2915
|
+
message: "Invalid params",
|
|
2916
|
+
data: { issues: c.error.issues }
|
|
2917
|
+
} };
|
|
2918
|
+
if (o.kind !== "request") return ne("unknown-method", e.method);
|
|
2919
|
+
const f = this._buildStreamApi(e.stream, e.signal, o);
|
|
2920
|
+
try {
|
|
2921
|
+
const h = await i(c.data, e.context, f), p = ks(o, h);
|
|
2922
|
+
return p !== void 0 ? { error: p } : (He(o.resultSchema, h, `Invalid result for ${e.method}`, R.internalError), { result: h === void 0 ? null : h });
|
|
2923
|
+
} catch (h) {
|
|
2924
|
+
return h instanceof A ? { error: {
|
|
2925
|
+
code: h.code,
|
|
2926
|
+
message: h.message,
|
|
2927
|
+
data: h.data
|
|
2928
|
+
} } : { error: {
|
|
2929
|
+
code: R.internalError,
|
|
2930
|
+
message: h instanceof Error ? h.message : String(h)
|
|
2931
|
+
} };
|
|
2932
|
+
}
|
|
2933
|
+
}
|
|
2934
|
+
_buildStreamApi(e, r, s) {
|
|
2935
|
+
return {
|
|
2936
|
+
send: (n) => {
|
|
2937
|
+
if (s.serverStreamSchema) {
|
|
2938
|
+
const o = z(s.serverStreamSchema, n);
|
|
2939
|
+
if (!o.success) throw new Error(`Server stream payload failed schema validation: ${o.error.message}`);
|
|
2940
|
+
}
|
|
2941
|
+
return e.send(n);
|
|
2942
|
+
},
|
|
2943
|
+
onMessage: (n) => {
|
|
2944
|
+
e.onMessage((o) => {
|
|
2945
|
+
if (s.clientStreamSchema) {
|
|
2946
|
+
const i = z(s.clientStreamSchema, o);
|
|
2947
|
+
if (!i.success) return;
|
|
2948
|
+
n(i.data);
|
|
2949
|
+
return;
|
|
2950
|
+
}
|
|
2951
|
+
});
|
|
2952
|
+
},
|
|
2953
|
+
ping: () => e.ping(),
|
|
2954
|
+
signal: r
|
|
2955
|
+
};
|
|
2956
|
+
}
|
|
2957
|
+
_handleNotification(e) {
|
|
2958
|
+
const r = this._parseRouted(e.method);
|
|
2959
|
+
if (!r.ok) return;
|
|
2960
|
+
const { entry: s, memberName: n } = r, o = s.iface.members[n];
|
|
2961
|
+
if ((o == null ? void 0 : o.kind) !== "notification") return;
|
|
2962
|
+
const i = s.handlers[n];
|
|
2963
|
+
if (!i) return;
|
|
2964
|
+
const a = ft(e.params), c = z(o.paramsSchema, a);
|
|
2965
|
+
c.success && i(c.data, e.context);
|
|
2966
|
+
}
|
|
2967
|
+
_parseRouted(e) {
|
|
2968
|
+
const r = as(e);
|
|
2969
|
+
if (!r) return {
|
|
2970
|
+
ok: !1,
|
|
2971
|
+
reason: "bad-method-grammar"
|
|
2972
|
+
};
|
|
2973
|
+
if (r.kind === "bare") {
|
|
2974
|
+
let i;
|
|
2975
|
+
for (const a of this._bareBindings.values()) r.member.startsWith(a.prefix) && (i === void 0 || a.prefix.length > i.prefix.length) && (i = a);
|
|
2976
|
+
return i ? {
|
|
2977
|
+
ok: !0,
|
|
2978
|
+
entry: i.entry,
|
|
2979
|
+
memberName: r.member.slice(i.prefix.length)
|
|
2980
|
+
} : {
|
|
2981
|
+
ok: !1,
|
|
2982
|
+
reason: "no-preset"
|
|
2983
|
+
};
|
|
2984
|
+
}
|
|
2985
|
+
const s = r.kind === "full" ? r.serviceId : void 0, n = `${s ?? ""}::${r.interfaceId}`, o = this._registry.get(n);
|
|
2986
|
+
return o ? {
|
|
2987
|
+
ok: !0,
|
|
2988
|
+
entry: o,
|
|
2989
|
+
memberName: r.member
|
|
2990
|
+
} : {
|
|
2991
|
+
ok: !1,
|
|
2992
|
+
reason: s ? "unknown-service" : "unknown-interface"
|
|
2993
|
+
};
|
|
2994
|
+
}
|
|
2995
|
+
_installServiceInspection(e) {
|
|
2996
|
+
if (this._serviceInspectionRegistrations.has(e)) return;
|
|
2997
|
+
const r = this._inspection, s = this._inspectionHost;
|
|
2998
|
+
r === void 0 || s === void 0 || this._serviceInspectionRegistrations.set(e, [s.expose(this, {
|
|
2999
|
+
serviceId: e,
|
|
3000
|
+
portId: r.portId
|
|
3001
|
+
})]);
|
|
3002
|
+
}
|
|
3003
|
+
_removeServiceInspection(e) {
|
|
3004
|
+
const r = this._serviceInspectionRegistrations.get(e);
|
|
3005
|
+
if (r !== void 0) {
|
|
3006
|
+
this._serviceInspectionRegistrations.delete(e);
|
|
3007
|
+
for (const s of r.reverse()) s.dispose();
|
|
3008
|
+
}
|
|
3009
|
+
}
|
|
3010
|
+
_hasBusinessServiceRegistration(e) {
|
|
3011
|
+
return Array.from(this._registry.values()).some((r) => r.serviceId === e && !r.internalInspection);
|
|
3012
|
+
}
|
|
3013
|
+
};
|
|
3014
|
+
function ys(t) {
|
|
3015
|
+
const e = /* @__PURE__ */ new Uint8Array(16);
|
|
3016
|
+
return globalThis.crypto.getRandomValues(e), `${t}:${At(e)}`;
|
|
3017
|
+
}
|
|
3018
|
+
function Is(t, e) {
|
|
3019
|
+
if (t.length !== e.length) return !1;
|
|
3020
|
+
for (let r = 0; r < t.length; r++) {
|
|
3021
|
+
const s = t[r], n = e[r];
|
|
3022
|
+
if (s.length !== n.length) return !1;
|
|
3023
|
+
for (let o = 0; o < s.length; o++)
|
|
3024
|
+
if (s[o].principal !== n[o].principal || s[o].transitive === !0 != (n[o].transitive === !0)) return !1;
|
|
3025
|
+
}
|
|
3026
|
+
return !0;
|
|
3027
|
+
}
|
|
3028
|
+
function ut(t, e) {
|
|
3029
|
+
const r = e.serviceId ?? "";
|
|
3030
|
+
return (t.interfaceId === void 0 || t.interfaceId === e.iface.info.id) && (t.interfaceIdPrefix === void 0 || e.iface.info.id.startsWith(t.interfaceIdPrefix)) && (t.serviceId === void 0 || t.serviceId === r) && Lt(r, t.serviceIdScopes);
|
|
3031
|
+
}
|
|
3032
|
+
function mt(t, e, r = !1) {
|
|
3033
|
+
const s = t.then((o) => ({
|
|
3034
|
+
ok: !0,
|
|
3035
|
+
value: o
|
|
3036
|
+
}), (o) => ({
|
|
3037
|
+
ok: !1,
|
|
3038
|
+
error: Ss(o, e.applicationErrors),
|
|
3039
|
+
cause: o
|
|
3040
|
+
})), n = s.then((o) => {
|
|
3041
|
+
if (o.ok) return o.value;
|
|
3042
|
+
if (r) return new Ye(o.error.kind === "application" ? {
|
|
3043
|
+
kind: "application",
|
|
3044
|
+
error: o.error
|
|
3045
|
+
} : {
|
|
3046
|
+
kind: "generic",
|
|
3047
|
+
error: o.error
|
|
3048
|
+
});
|
|
3049
|
+
if (o.error.kind === "application") return new Ye(o.error);
|
|
3050
|
+
throw o.error.kind === "nonCompliantServer" ? o.error : o.cause;
|
|
3051
|
+
});
|
|
3052
|
+
return Object.assign(n, { result: async () => {
|
|
3053
|
+
n.catch(() => {
|
|
3054
|
+
});
|
|
3055
|
+
const o = await s;
|
|
3056
|
+
return o.ok ? o : {
|
|
3057
|
+
ok: !1,
|
|
3058
|
+
error: o.error
|
|
3059
|
+
};
|
|
3060
|
+
} });
|
|
3061
|
+
}
|
|
3062
|
+
function Ss(t, e) {
|
|
3063
|
+
if (t instanceof ct) return t;
|
|
3064
|
+
if (!(t instanceof A) || t.origin !== "remote") return {
|
|
3065
|
+
kind: t instanceof A && t.origin === "transport" ? "transport" : "local",
|
|
3066
|
+
cause: t
|
|
3067
|
+
};
|
|
3068
|
+
const r = {
|
|
3069
|
+
code: t.code,
|
|
3070
|
+
message: t.message,
|
|
3071
|
+
...t.hasData ? { data: t.data } : {}
|
|
3072
|
+
}, s = e.filter((i) => i.code === t.code).sort((i, a) => +(a.type !== void 0) - +(i.type !== void 0)), n = {
|
|
3073
|
+
message: t.message,
|
|
3074
|
+
...t.hasData ? { data: t.data } : {}
|
|
3075
|
+
}, o = [];
|
|
3076
|
+
for (const i of s) {
|
|
3077
|
+
const a = St(i, n);
|
|
3078
|
+
if (!a.success) {
|
|
3079
|
+
o.push(...a.issues);
|
|
3080
|
+
continue;
|
|
3081
|
+
}
|
|
3082
|
+
if (i.type === void 0) return Qe({
|
|
3083
|
+
...a.data,
|
|
3084
|
+
kind: "application",
|
|
3085
|
+
code: i.code
|
|
3086
|
+
});
|
|
3087
|
+
const c = a.data.data;
|
|
3088
|
+
return Qe({
|
|
3089
|
+
kind: "application",
|
|
3090
|
+
code: i.code,
|
|
3091
|
+
message: a.data.message,
|
|
3092
|
+
type: i.type,
|
|
3093
|
+
...typeof c == "object" && c !== null && "data" in c ? { data: c.data } : {}
|
|
3094
|
+
});
|
|
3095
|
+
}
|
|
3096
|
+
return s.length > 0 ? new ct(r, o) : {
|
|
3097
|
+
kind: "remote",
|
|
3098
|
+
...r
|
|
3099
|
+
};
|
|
3100
|
+
}
|
|
3101
|
+
function ks(t, e) {
|
|
3102
|
+
if (!rr(e)) return;
|
|
3103
|
+
const r = e, s = t.applicationErrors.find((c) => c.code === r.code && c.type === r.type && (c.bodySchema !== void 0 || c.type !== void 0 || c.message === r.message));
|
|
3104
|
+
if (s === void 0) throw new A(`Undeclared application error ${String(r.code)}`, R.internalError);
|
|
3105
|
+
const n = Object.hasOwn(e, "data") ? { data: e.data } : {}, o = {
|
|
3106
|
+
message: e.message,
|
|
3107
|
+
...s.type === void 0 ? n : { data: {
|
|
3108
|
+
type: s.type,
|
|
3109
|
+
...n
|
|
3110
|
+
} }
|
|
3111
|
+
}, i = St(s, o), a = i.success ? Et(o) : i.issues;
|
|
3112
|
+
if (a.length > 0) throw new A(`Invalid data for application error ${s.code}`, R.internalError, { issues: a.map((c) => ({ ...c })) });
|
|
3113
|
+
return {
|
|
3114
|
+
code: s.code,
|
|
3115
|
+
...o
|
|
3116
|
+
};
|
|
3117
|
+
}
|
|
3118
|
+
function gt(t, e, r) {
|
|
3119
|
+
const s = Es(t, e);
|
|
3120
|
+
return He(t, s, `Invalid result for ${r}`, R.internalError), s;
|
|
3121
|
+
}
|
|
3122
|
+
function He(t, e, r, s) {
|
|
3123
|
+
const n = z(t, e);
|
|
3124
|
+
if (!n.success) throw new A(r, s, { issues: n.error.issues });
|
|
3125
|
+
}
|
|
3126
|
+
function Es(t, e) {
|
|
3127
|
+
if (e !== null) return e;
|
|
3128
|
+
if (z(t, null).success) return null;
|
|
3129
|
+
if (!z(t, void 0).success)
|
|
3130
|
+
return null;
|
|
3131
|
+
}
|
|
3132
|
+
var Os = class {
|
|
3133
|
+
constructor(t, e) {
|
|
3134
|
+
l(this, "_connection");
|
|
3135
|
+
l(this, "_serviceId");
|
|
3136
|
+
this._connection = t, this._serviceId = e;
|
|
3137
|
+
}
|
|
3138
|
+
getResultClient(t, e = {}) {
|
|
3139
|
+
return this._connection.getResultClient(t, {
|
|
3140
|
+
...e,
|
|
3141
|
+
serviceId: this._serviceId
|
|
3142
|
+
});
|
|
3143
|
+
}
|
|
3144
|
+
get(t, e = {}) {
|
|
3145
|
+
return this._connection.get(t, {
|
|
3146
|
+
...e,
|
|
3147
|
+
serviceId: this._serviceId
|
|
3148
|
+
});
|
|
3149
|
+
}
|
|
3150
|
+
register(t, e, r = {}) {
|
|
3151
|
+
return this._connection.register(t, e, {
|
|
3152
|
+
...r,
|
|
3153
|
+
serviceId: this._serviceId
|
|
3154
|
+
});
|
|
3155
|
+
}
|
|
3156
|
+
};
|
|
3157
|
+
function ne(t, e) {
|
|
3158
|
+
return { error: {
|
|
3159
|
+
code: R.methodNotFound,
|
|
3160
|
+
message: `Method not found: ${e}`,
|
|
3161
|
+
data: {
|
|
3162
|
+
reason: t,
|
|
3163
|
+
method: e
|
|
3164
|
+
}
|
|
3165
|
+
} };
|
|
3166
|
+
}
|
|
3167
|
+
$s(globalThis, {});
|
|
3168
|
+
function $s(t, e) {
|
|
3169
|
+
return new Proxy(t, {
|
|
3170
|
+
get(r, s, n) {
|
|
3171
|
+
return s in e ? e[s] : t[s];
|
|
3172
|
+
},
|
|
3173
|
+
set(r, s, n) {
|
|
3174
|
+
return s in e && delete e[s], t[s] = n, !0;
|
|
3175
|
+
},
|
|
3176
|
+
deleteProperty(r, s) {
|
|
3177
|
+
let n = !1;
|
|
3178
|
+
return s in e && (delete e[s], n = !0), s in t && (delete t[s], n = !0), n;
|
|
3179
|
+
},
|
|
3180
|
+
ownKeys(r) {
|
|
3181
|
+
const s = Reflect.ownKeys(t), n = Reflect.ownKeys(e), o = new Set(n);
|
|
3182
|
+
return [...s.filter((i) => !o.has(i)), ...n];
|
|
3183
|
+
},
|
|
3184
|
+
defineProperty(r, s, n) {
|
|
3185
|
+
return s in e && delete e[s], Reflect.defineProperty(t, s, n), !0;
|
|
3186
|
+
},
|
|
3187
|
+
getOwnPropertyDescriptor(r, s) {
|
|
3188
|
+
return s in e ? Reflect.getOwnPropertyDescriptor(e, s) : Reflect.getOwnPropertyDescriptor(t, s);
|
|
3189
|
+
},
|
|
3190
|
+
has(r, s) {
|
|
3191
|
+
return s in e || s in t;
|
|
3192
|
+
}
|
|
3193
|
+
});
|
|
3194
|
+
}
|
|
3195
|
+
const G = u();
|
|
3196
|
+
M({
|
|
3197
|
+
id: "identity",
|
|
3198
|
+
description: "Per-participant key oracle: exposes signing and HPKE-based wrap/unwrap for the identity the executor has attached to this participant's root overlay. Private keys never leave the executor."
|
|
3199
|
+
}, {
|
|
3200
|
+
getPrincipal: w(v({}), v({ principal: u() })),
|
|
3201
|
+
getWrapPublicKey: w(v({}), v({ wrapPublicKey: G })),
|
|
3202
|
+
sign: w(v({ bytes: G }), v({ signature: G })),
|
|
3203
|
+
wrap: w(v({
|
|
3204
|
+
domain: u(),
|
|
3205
|
+
bytes: G
|
|
3206
|
+
}), v({ blob: G })),
|
|
3207
|
+
unwrap: w(v({
|
|
3208
|
+
domain: u(),
|
|
3209
|
+
blob: G
|
|
3210
|
+
}), v({ bytes: G }))
|
|
3211
|
+
});
|
|
3212
|
+
M({
|
|
3213
|
+
id: "identity.storage",
|
|
3214
|
+
description: "Per-identity persistent key/value store. Scope is the executor's managed-identity slot; lifecycle is tied to the identity itself. Backed by an at-rest-encrypted file in the executor."
|
|
3215
|
+
}, {
|
|
3216
|
+
get: w(v({ key: u() }), v({ value: g(V()) })),
|
|
3217
|
+
set: w(v({
|
|
3218
|
+
key: u(),
|
|
3219
|
+
value: V()
|
|
3220
|
+
}), v({})),
|
|
3221
|
+
delete: w(v({ key: u() }), v({ existed: se() })),
|
|
3222
|
+
list: w(v({ prefix: g(u()) }), v({ keys: T(u()) }))
|
|
3223
|
+
});
|
|
3224
|
+
const ve = d.object({}).default({}), he = d.object({ message: d.string(), stack: d.string().optional() }), le = d.object({
|
|
3225
|
+
type: d.enum(["console.error", "console.warn", "console.log", "window.error", "window.unhandledrejection"]),
|
|
3226
|
+
message: d.string(),
|
|
3227
|
+
stack: d.string().optional()
|
|
3228
|
+
}), vt = d.object({
|
|
3229
|
+
hasError: d.boolean(),
|
|
3230
|
+
errors: d.array(he).readonly(),
|
|
3231
|
+
events: d.array(le).readonly()
|
|
3232
|
+
}), _e = d.object({
|
|
3233
|
+
fixtureId: d.string(),
|
|
3234
|
+
originalHash: d.string(),
|
|
3235
|
+
modifiedHash: d.string(),
|
|
3236
|
+
comment: d.string(),
|
|
3237
|
+
approvedAt: d.string()
|
|
3238
|
+
}), be = d.object({
|
|
3239
|
+
fixtureId: d.string(),
|
|
3240
|
+
originalHash: d.string(),
|
|
3241
|
+
modifiedHash: d.string()
|
|
3242
|
+
}), _t = d.object({
|
|
3243
|
+
fixtureId: d.string(),
|
|
3244
|
+
expectedVisualDescriptions: d.array(d.string()),
|
|
3245
|
+
screenshotHash: d.string()
|
|
3246
|
+
}), js = d.union([
|
|
3247
|
+
d.object({
|
|
3248
|
+
name: d.string(),
|
|
3249
|
+
sourceKind: d.enum(["current", "worktree"]),
|
|
3250
|
+
isLoading: d.literal(!0)
|
|
3251
|
+
}),
|
|
3252
|
+
d.object({
|
|
3253
|
+
name: d.string(),
|
|
3254
|
+
sourceKind: d.enum(["current", "worktree"]),
|
|
3255
|
+
isLoading: d.literal(!1).optional(),
|
|
3256
|
+
serverUrl: d.string(),
|
|
3257
|
+
sourceTreeId: d.string(),
|
|
3258
|
+
worktreePath: d.string().optional(),
|
|
3259
|
+
ref: d.string().optional()
|
|
3260
|
+
})
|
|
3261
|
+
]), Rs = d.array(js), Ue = Rs, we = d.union([d.object({ sessions: Ue }), d.object({ error: d.string() })]), Ht = d.object({
|
|
3262
|
+
hash: d.string().optional(),
|
|
3263
|
+
image: d.string().optional(),
|
|
3264
|
+
hasError: d.boolean(),
|
|
3265
|
+
error: he.optional(),
|
|
3266
|
+
events: d.array(le).optional(),
|
|
3267
|
+
output: d.unknown().optional()
|
|
3268
|
+
}), Ps = Ht.extend({
|
|
3269
|
+
sourceTreeId: d.string(),
|
|
3270
|
+
isStable: d.boolean().optional(),
|
|
3271
|
+
stabilityScreenshots: d.array(d.object({
|
|
3272
|
+
hash: d.string(),
|
|
3273
|
+
delayMs: d.number(),
|
|
3274
|
+
image: d.string().optional()
|
|
3275
|
+
})).optional(),
|
|
3276
|
+
previousDispose: vt.optional(),
|
|
3277
|
+
currentDispose: vt.optional()
|
|
3278
|
+
}), Cs = Ps, Ts = d.discriminatedUnion("type", [
|
|
3279
|
+
d.object({ type: d.literal("source-change"), sessionName: d.string(), sourceTreeId: d.string() }),
|
|
3280
|
+
d.object({ type: d.literal("ref-change"), sessionName: d.string(), newCommit: d.string() }),
|
|
3281
|
+
d.object({ type: d.literal("session-change") }),
|
|
3282
|
+
d.object({ type: d.literal("log"), level: d.enum(["info", "debug", "trace"]), message: d.string() })
|
|
3283
|
+
]), As = d.object({
|
|
3284
|
+
clientName: d.string()
|
|
3285
|
+
}), ye = M({ id: "component-explorer.daemon-initialization" }, {
|
|
3286
|
+
initialize: w(As, d.void())
|
|
3287
|
+
}), Ns = d.object({ sessionName: d.string(), sourceTreeId: d.string() }), Be = M({ id: "component-explorer.daemon" }, {
|
|
3288
|
+
fixturesList: w(Ns, d.object({
|
|
3289
|
+
fixtures: d.array(d.object({
|
|
3290
|
+
fixtureId: d.string(),
|
|
3291
|
+
fixtureName: d.string(),
|
|
3292
|
+
groupPath: d.array(d.string()),
|
|
3293
|
+
background: d.enum(["light", "dark"]),
|
|
3294
|
+
labels: d.array(d.string()).readonly(),
|
|
3295
|
+
expectedVisualDescriptions: d.array(d.string()).readonly(),
|
|
3296
|
+
inputSchema: d.unknown().optional()
|
|
3297
|
+
})),
|
|
3298
|
+
loadError: d.string().optional()
|
|
3299
|
+
})),
|
|
3300
|
+
screenshotsTake: w(d.object({
|
|
3301
|
+
fixtureId: d.string(),
|
|
3302
|
+
sourceTreeId: d.string(),
|
|
3303
|
+
sessionName: d.string(),
|
|
3304
|
+
includeImage: d.boolean().optional(),
|
|
3305
|
+
stabilityCheck: d.boolean().optional(),
|
|
3306
|
+
reloadBeforeRender: d.boolean().optional(),
|
|
3307
|
+
input: d.unknown().optional(),
|
|
3308
|
+
disposeAfter: d.boolean().optional()
|
|
3309
|
+
}), Cs),
|
|
3310
|
+
screenshotsTakeBatch: w(d.object({
|
|
3311
|
+
fixtureIds: d.array(d.string()),
|
|
3312
|
+
sourceTreeId: d.string(),
|
|
3313
|
+
sessionName: d.string(),
|
|
3314
|
+
includeImages: d.boolean().optional(),
|
|
3315
|
+
reloadBetweenFixtures: d.boolean().optional(),
|
|
3316
|
+
input: d.unknown().optional()
|
|
3317
|
+
}), d.object({ sourceTreeId: d.string(), screenshots: d.array(Ht.extend({ fixtureId: d.string() })) })),
|
|
3318
|
+
screenshotsCompare: w(d.object({
|
|
3319
|
+
fixtureId: d.string(),
|
|
3320
|
+
baselineSessionName: d.string(),
|
|
3321
|
+
baselineSourceTreeId: d.string(),
|
|
3322
|
+
currentSessionName: d.string(),
|
|
3323
|
+
currentSourceTreeId: d.string(),
|
|
3324
|
+
includeImages: d.boolean().optional()
|
|
3325
|
+
}), d.object({
|
|
3326
|
+
match: d.boolean(),
|
|
3327
|
+
baselineHash: d.string().optional(),
|
|
3328
|
+
currentHash: d.string().optional(),
|
|
3329
|
+
baselineImage: d.string().optional(),
|
|
3330
|
+
currentImage: d.string().optional(),
|
|
3331
|
+
baselineHasError: d.boolean(),
|
|
3332
|
+
baselineError: he.optional(),
|
|
3333
|
+
baselineEvents: d.array(le).optional(),
|
|
3334
|
+
baselineOutput: d.unknown().optional(),
|
|
3335
|
+
currentHasError: d.boolean(),
|
|
3336
|
+
currentError: he.optional(),
|
|
3337
|
+
currentEvents: d.array(le).optional(),
|
|
3338
|
+
currentOutput: d.unknown().optional(),
|
|
3339
|
+
labels: d.array(d.string()).readonly().optional(),
|
|
3340
|
+
labelsBefore: d.array(d.string()).readonly().optional(),
|
|
3341
|
+
approval: _e.optional()
|
|
3342
|
+
})),
|
|
3343
|
+
approvalsApprove: w(be.extend({ comment: d.string() }), d.void()),
|
|
3344
|
+
approvalsRevoke: w(be, d.void()),
|
|
3345
|
+
approvalsList: w(d.object({ fixtureId: d.string().optional() }), d.array(_e)),
|
|
3346
|
+
approvalsLookup: w(be, d.union([_e, d.null()])),
|
|
3347
|
+
visualReviewGetStatus: w(_t, d.union([
|
|
3348
|
+
d.literal("no-expectations"),
|
|
3349
|
+
d.object({
|
|
3350
|
+
expectedVisualDescriptions: d.array(d.string()).readonly(),
|
|
3351
|
+
status: d.enum(["approved", "needs-review"]),
|
|
3352
|
+
approval: d.object({ approvedAt: d.string(), comment: d.string() }).optional()
|
|
3353
|
+
})
|
|
3354
|
+
])),
|
|
3355
|
+
visualReviewApprove: w(_t.extend({ comment: d.string() }), d.void()),
|
|
3356
|
+
evaluate: w(d.object({
|
|
3357
|
+
sessionName: d.string(),
|
|
3358
|
+
sourceTreeId: d.string(),
|
|
3359
|
+
expression: d.string(),
|
|
3360
|
+
fixtureId: d.string().optional()
|
|
3361
|
+
}), d.object({ result: d.unknown() })),
|
|
3362
|
+
setBrowserVisibility: w(d.object({ visible: d.boolean() }), d.object({ visible: d.boolean() })),
|
|
3363
|
+
events: w(ve, d.void()).withStream({ server: Ts }),
|
|
3364
|
+
sessions: w(ve, Ue),
|
|
3365
|
+
restartSession: w(d.object({ sessionName: d.string() }), Ue),
|
|
3366
|
+
openSession: w(d.object({ name: d.string(), ref: d.string() }), we),
|
|
3367
|
+
closeSession: w(d.object({ name: d.string() }), we),
|
|
3368
|
+
updateSessionRef: w(d.object({ name: d.string(), ref: d.string() }), we),
|
|
3369
|
+
shutdown: w(ve, d.void())
|
|
3370
|
+
});
|
|
3371
|
+
function Ms(t) {
|
|
3372
|
+
const e = t.get(Be);
|
|
3373
|
+
return {
|
|
3374
|
+
fixtures: { list: e.fixturesList },
|
|
3375
|
+
screenshots: { take: e.screenshotsTake, takeBatch: e.screenshotsTakeBatch, compare: e.screenshotsCompare },
|
|
3376
|
+
approvals: { approve: e.approvalsApprove, revoke: e.approvalsRevoke, list: e.approvalsList, lookup: e.approvalsLookup },
|
|
3377
|
+
visualReview: { getStatus: e.visualReviewGetStatus, approve: e.visualReviewApprove },
|
|
3378
|
+
evaluate: e.evaluate,
|
|
3379
|
+
setBrowserVisibility: e.setBrowserVisibility,
|
|
3380
|
+
events: e.events,
|
|
3381
|
+
sessions: e.sessions,
|
|
3382
|
+
restartSession: e.restartSession,
|
|
3383
|
+
openSession: e.openSession,
|
|
3384
|
+
closeSession: e.closeSession,
|
|
3385
|
+
updateSessionRef: e.updateSessionRef,
|
|
3386
|
+
shutdown: e.shutdown
|
|
3387
|
+
};
|
|
3388
|
+
}
|
|
3389
|
+
async function qs(t, e) {
|
|
3390
|
+
const r = t.get(De);
|
|
3391
|
+
return await r.get({ interfaceId: ye.info.id, hash: ye.schemaHash }), await t.get(ye).initialize({ clientName: e }), await r.get({ interfaceId: Be.info.id, hash: Be.schemaHash }), Ms(t);
|
|
3392
|
+
}
|
|
3393
|
+
const xs = "/__explorer/daemon-rpc";
|
|
3394
|
+
async function Us() {
|
|
3395
|
+
const t = new URL(xs, location.href);
|
|
3396
|
+
t.protocol = location.protocol === "https:" ? "wss:" : "ws:";
|
|
3397
|
+
const e = new WebSocket(t);
|
|
3398
|
+
let r, s = () => {
|
|
3399
|
+
};
|
|
3400
|
+
const n = new Promise((c, f) => {
|
|
3401
|
+
s = f;
|
|
3402
|
+
}), o = new Ls(e, () => {
|
|
3403
|
+
r == null || r.close(), s(new Error("Daemon WebSocket closed"));
|
|
3404
|
+
});
|
|
3405
|
+
let i = !1;
|
|
3406
|
+
const a = () => {
|
|
3407
|
+
i || (i = !0, r == null || r.close(), o.dispose());
|
|
3408
|
+
};
|
|
3409
|
+
try {
|
|
3410
|
+
if (await Promise.race([
|
|
3411
|
+
new Promise((f, h) => {
|
|
3412
|
+
if (e.readyState === WebSocket.OPEN) {
|
|
3413
|
+
f();
|
|
3414
|
+
return;
|
|
3415
|
+
}
|
|
3416
|
+
e.addEventListener("open", () => f(), { once: !0 }), e.addEventListener("error", () => h(new Error("Daemon WebSocket failed to open")), { once: !0 });
|
|
3417
|
+
}),
|
|
3418
|
+
n
|
|
3419
|
+
]), e.readyState !== WebSocket.OPEN)
|
|
3420
|
+
throw new Error("Daemon WebSocket closed before initialization");
|
|
3421
|
+
return r = ws.fromTransport(o), { methods: await qs(r, "explorer-ui"), dispose: a };
|
|
3422
|
+
} catch (c) {
|
|
3423
|
+
throw a(), c;
|
|
3424
|
+
}
|
|
3425
|
+
}
|
|
3426
|
+
class Ls {
|
|
3427
|
+
constructor(e, r) {
|
|
3428
|
+
l(this, "_listener");
|
|
3429
|
+
l(this, "_buffer", []);
|
|
3430
|
+
l(this, "_disposed", !1);
|
|
3431
|
+
l(this, "_handleMessage", (e) => {
|
|
3432
|
+
try {
|
|
3433
|
+
const r = JSON.parse(e.data);
|
|
3434
|
+
if (!r || typeof r != "object" || !("jsonrpc" in r) || r.jsonrpc !== "2.0")
|
|
3435
|
+
throw new Error("Invalid daemon RPC message");
|
|
3436
|
+
this._listener ? this._listener(r) : this._buffer.push(r);
|
|
3437
|
+
} catch {
|
|
3438
|
+
this._socket.close(1003, "Invalid daemon RPC message"), this._onClose();
|
|
3439
|
+
}
|
|
3440
|
+
});
|
|
3441
|
+
l(this, "_handleClose", () => this._onClose());
|
|
3442
|
+
l(this, "_handleError", () => {
|
|
3443
|
+
this._onClose(), this._socket.close();
|
|
3444
|
+
});
|
|
3445
|
+
this._socket = e, this._onClose = r, e.addEventListener("message", this._handleMessage), e.addEventListener("close", this._handleClose), e.addEventListener("error", this._handleError);
|
|
3446
|
+
}
|
|
3447
|
+
send(e) {
|
|
3448
|
+
if (this._socket.readyState !== WebSocket.OPEN)
|
|
3449
|
+
throw new Error("Daemon WebSocket is not open");
|
|
3450
|
+
this._socket.send(JSON.stringify(e));
|
|
3451
|
+
}
|
|
3452
|
+
setListener(e) {
|
|
3453
|
+
this._listener = e, e && queueMicrotask(() => {
|
|
3454
|
+
for (; this._listener && this._buffer.length; )
|
|
3455
|
+
this._listener(this._buffer.shift());
|
|
3456
|
+
});
|
|
3457
|
+
}
|
|
3458
|
+
dispose() {
|
|
3459
|
+
this._disposed || (this._disposed = !0, this._listener = void 0, this._buffer.length = 0, this._socket.removeEventListener("message", this._handleMessage), this._socket.removeEventListener("close", this._handleClose), this._socket.removeEventListener("error", this._handleError), this._socket.close());
|
|
3460
|
+
}
|
|
3461
|
+
}
|
|
3462
|
+
export {
|
|
3463
|
+
Us as createBrowserDaemonClient
|
|
3464
|
+
};
|
|
3465
|
+
//# sourceMappingURL=browserDaemonClient-AB8d4x2O.js.map
|