@multiagency/sdk 0.3.1
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/CHANGES.md +21 -0
- package/LICENSE +21 -0
- package/README.md +142 -0
- package/THIRD-PARTY-NOTICES +127 -0
- package/bin/release-server.d.mts +29 -0
- package/bin/release-server.mjs +143 -0
- package/dist/compensation-contract.d.ts +370 -0
- package/dist/compensation-contract.js +51 -0
- package/dist/contract/agent-connection.d.ts +86 -0
- package/dist/contract/agent-connection.js +36 -0
- package/dist/contract/app-access.d.ts +141 -0
- package/dist/contract/app-access.js +57 -0
- package/dist/contract/app-client.d.ts +140 -0
- package/dist/contract/app-client.js +61 -0
- package/dist/contract/app-consent.d.ts +68 -0
- package/dist/contract/app-consent.js +91 -0
- package/dist/contract/assets.d.ts +6 -0
- package/dist/contract/assets.js +6 -0
- package/dist/contract/client.d.ts +347 -0
- package/dist/contract/client.js +81 -0
- package/dist/contract/gateway.d.ts +74 -0
- package/dist/contract/gateway.js +47 -0
- package/dist/contract/index.d.ts +26 -0
- package/dist/contract/index.js +25 -0
- package/dist/contract/inputs.d.ts +230 -0
- package/dist/contract/inputs.js +99 -0
- package/dist/contract/intents-account.d.ts +5 -0
- package/dist/contract/intents-account.js +8 -0
- package/dist/contract/orpc-client.js +2037 -0
- package/dist/contract/owner-capabilities.d.ts +81 -0
- package/dist/contract/owner-capabilities.js +33 -0
- package/dist/contract/owner-client.d.ts +99 -0
- package/dist/contract/owner-client.js +146 -0
- package/dist/contract/owner-contract.d.ts +1156 -0
- package/dist/contract/owner-contract.js +37 -0
- package/dist/contract/owner-inputs.d.ts +166 -0
- package/dist/contract/owner-inputs.js +1 -0
- package/dist/contract/owner-outputs.d.ts +5749 -0
- package/dist/contract/owner-outputs.js +751 -0
- package/dist/contract/package-version.d.ts +5 -0
- package/dist/contract/package-version.js +2 -0
- package/dist/contract/payee-entry.d.ts +10 -0
- package/dist/contract/payee-entry.js +10 -0
- package/dist/contract/payee.d.ts +326 -0
- package/dist/contract/payee.js +32 -0
- package/dist/contract/permissions.d.ts +20 -0
- package/dist/contract/permissions.js +64 -0
- package/dist/contract/proposals.d.ts +178 -0
- package/dist/contract/proposals.js +27 -0
- package/dist/contract/run-log-schema.d.ts +888 -0
- package/dist/contract/run-log-schema.js +150 -0
- package/dist/contract/run-progress-schema.d.ts +104 -0
- package/dist/contract/run-progress-schema.js +20 -0
- package/dist/payee-contract.d.ts +9 -0
- package/dist/payee-contract.js +15 -0
- package/package.json +58 -0
- package/provenance.json +61 -0
- package/schemas/agentConnection.json +76 -0
- package/schemas/agentConnectionIssue.json +22 -0
- package/schemas/agentConnectionList.json +88 -0
- package/schemas/agentConnectionStarted.json +90 -0
- package/schemas/compensationSend.json +40 -0
- package/schemas/errorBody.json +16 -0
- package/schemas/fileResult.json +67 -0
- package/schemas/invoicesView.json +130 -0
- package/schemas/ownerCompensationView.json +556 -0
- package/schemas/payeeCompensationView.json +546 -0
- package/schemas/payeeWorkOrderRequest.json +31 -0
- package/schemas/publicWorkOrder.json +94 -0
- package/schemas/reportCommand.json +82 -0
- package/schemas/requestRecord.json +149 -0
- package/schemas/session.json +20 -0
- package/schemas/workOrderList.json +43 -0
- package/schemas/workOrderRequestResult.json +20 -0
- package/skills/app-server/SKILL.md +190 -0
- package/skills/getting-started/SKILL.md +90 -0
- package/skills/owner-workflows/SKILL.md +157 -0
- package/skills/payee-workflows/SKILL.md +200 -0
|
@@ -0,0 +1,2037 @@
|
|
|
1
|
+
// ../../../node_modules/.pnpm/@standard-server+shared@0.13.0/node_modules/@standard-server/shared/dist/index.mjs
|
|
2
|
+
function toArray(value2) {
|
|
3
|
+
return Array.isArray(value2) ? value2 : value2 === void 0 || value2 === null ? [] : [value2];
|
|
4
|
+
}
|
|
5
|
+
function sequential(fn) {
|
|
6
|
+
let lastOperationPromise = Promise.resolve();
|
|
7
|
+
return (...args) => {
|
|
8
|
+
return lastOperationPromise = lastOperationPromise.catch(() => {
|
|
9
|
+
}).then(() => {
|
|
10
|
+
return fn(...args);
|
|
11
|
+
});
|
|
12
|
+
};
|
|
13
|
+
}
|
|
14
|
+
function isAsyncIteratorObject(maybe) {
|
|
15
|
+
if (!maybe || typeof maybe !== "object") {
|
|
16
|
+
return false;
|
|
17
|
+
}
|
|
18
|
+
return "next" in maybe && typeof maybe.next === "function" && Symbol.asyncIterator in maybe && typeof maybe[Symbol.asyncIterator] === "function";
|
|
19
|
+
}
|
|
20
|
+
var fallbackAsyncDisposeSymbol = /* @__PURE__ */ Symbol.for("Symbol.asyncDispose");
|
|
21
|
+
var asyncDisposeSymbol = Symbol.asyncDispose ?? fallbackAsyncDisposeSymbol;
|
|
22
|
+
var AsyncIteratorClass = class {
|
|
23
|
+
isDone = false;
|
|
24
|
+
isExecuteComplete = false;
|
|
25
|
+
cleanup;
|
|
26
|
+
next;
|
|
27
|
+
constructor(next, cleanup) {
|
|
28
|
+
this.cleanup = cleanup;
|
|
29
|
+
this.next = sequential(async () => {
|
|
30
|
+
if (this.isDone) {
|
|
31
|
+
return { done: true, value: void 0 };
|
|
32
|
+
}
|
|
33
|
+
let errorRef;
|
|
34
|
+
try {
|
|
35
|
+
const result = await next();
|
|
36
|
+
if (this.isDone) {
|
|
37
|
+
return { done: true, value: void 0 };
|
|
38
|
+
}
|
|
39
|
+
if (result.done) {
|
|
40
|
+
this.isDone = true;
|
|
41
|
+
}
|
|
42
|
+
return result;
|
|
43
|
+
} catch (error) {
|
|
44
|
+
if (this.isDone) {
|
|
45
|
+
return { done: true, value: void 0 };
|
|
46
|
+
}
|
|
47
|
+
errorRef = { value: error };
|
|
48
|
+
this.isDone = true;
|
|
49
|
+
throw error;
|
|
50
|
+
} finally {
|
|
51
|
+
if (this.isDone && !this.isExecuteComplete) {
|
|
52
|
+
this.isExecuteComplete = true;
|
|
53
|
+
await this.cleanup(
|
|
54
|
+
errorRef ? { kind: "error", error: errorRef.value } : { kind: "success" }
|
|
55
|
+
);
|
|
56
|
+
}
|
|
57
|
+
}
|
|
58
|
+
});
|
|
59
|
+
}
|
|
60
|
+
async return(value2) {
|
|
61
|
+
this.isDone = true;
|
|
62
|
+
if (!this.isExecuteComplete) {
|
|
63
|
+
this.isExecuteComplete = true;
|
|
64
|
+
await this.cleanup({ kind: "cancelled" });
|
|
65
|
+
}
|
|
66
|
+
return { done: true, value: value2 };
|
|
67
|
+
}
|
|
68
|
+
async throw(error) {
|
|
69
|
+
this.isDone = true;
|
|
70
|
+
if (!this.isExecuteComplete) {
|
|
71
|
+
this.isExecuteComplete = true;
|
|
72
|
+
await this.cleanup({ kind: "cancelled", error });
|
|
73
|
+
}
|
|
74
|
+
throw error;
|
|
75
|
+
}
|
|
76
|
+
/**
|
|
77
|
+
* Uses the native Symbol.asyncDispose, or Symbol.for('Symbol.asyncDispose') on runtimes without it
|
|
78
|
+
*/
|
|
79
|
+
async [asyncDisposeSymbol]() {
|
|
80
|
+
this.isDone = true;
|
|
81
|
+
if (!this.isExecuteComplete) {
|
|
82
|
+
this.isExecuteComplete = true;
|
|
83
|
+
await this.cleanup({ kind: "cancelled" });
|
|
84
|
+
}
|
|
85
|
+
}
|
|
86
|
+
[Symbol.asyncIterator]() {
|
|
87
|
+
return this;
|
|
88
|
+
}
|
|
89
|
+
};
|
|
90
|
+
function parseEmptyableJSON(text) {
|
|
91
|
+
if (!text) {
|
|
92
|
+
return void 0;
|
|
93
|
+
}
|
|
94
|
+
return JSON.parse(text);
|
|
95
|
+
}
|
|
96
|
+
function stringifyJSON(value2) {
|
|
97
|
+
return JSON.stringify(value2);
|
|
98
|
+
}
|
|
99
|
+
function isTypescriptObject(maybeObject) {
|
|
100
|
+
if (!maybeObject) {
|
|
101
|
+
return false;
|
|
102
|
+
}
|
|
103
|
+
const type = typeof maybeObject;
|
|
104
|
+
return type === "object" || type === "function";
|
|
105
|
+
}
|
|
106
|
+
var GET_OR_BIND_CACHE = /* @__PURE__ */ new WeakMap();
|
|
107
|
+
function getOrBind(target, property, { bind = true } = {}) {
|
|
108
|
+
const value2 = Reflect.get(target, property);
|
|
109
|
+
if (!bind || typeof value2 !== "function") {
|
|
110
|
+
return value2;
|
|
111
|
+
}
|
|
112
|
+
let targetCache = GET_OR_BIND_CACHE.get(value2);
|
|
113
|
+
if (!targetCache) {
|
|
114
|
+
GET_OR_BIND_CACHE.set(value2, targetCache = /* @__PURE__ */ new WeakMap());
|
|
115
|
+
}
|
|
116
|
+
let bound = targetCache.get(target);
|
|
117
|
+
if (!bound) {
|
|
118
|
+
targetCache.set(target, bound = value2.bind(target));
|
|
119
|
+
}
|
|
120
|
+
return bound;
|
|
121
|
+
}
|
|
122
|
+
var LONE_SURROGATE_REGEX = /[\uD800-\uDFFF]/gu;
|
|
123
|
+
function safeEncodeURIComponent(value2) {
|
|
124
|
+
try {
|
|
125
|
+
return encodeURIComponent(value2);
|
|
126
|
+
} catch {
|
|
127
|
+
return encodeURIComponent(value2.replace(LONE_SURROGATE_REGEX, "\uFFFD"));
|
|
128
|
+
}
|
|
129
|
+
}
|
|
130
|
+
function safeDecodeURIComponent(value2) {
|
|
131
|
+
if (!value2.includes("%")) {
|
|
132
|
+
return value2;
|
|
133
|
+
}
|
|
134
|
+
try {
|
|
135
|
+
return decodeURIComponent(value2);
|
|
136
|
+
} catch {
|
|
137
|
+
return value2;
|
|
138
|
+
}
|
|
139
|
+
}
|
|
140
|
+
|
|
141
|
+
// ../../../node_modules/.pnpm/@orpc+shared@2.0.0-beta.47/node_modules/@orpc/shared/dist/index.mjs
|
|
142
|
+
function resolveMaybeOptionalOptions(rest) {
|
|
143
|
+
return rest[0] ?? {};
|
|
144
|
+
}
|
|
145
|
+
var DEFAULT_MAX_BIGINT_DIGITS = 4300;
|
|
146
|
+
var BIGINT_PATTERN = /^-?(?:0|[1-9]\d*)$/;
|
|
147
|
+
function parseBigIntString(value2, maxDigits) {
|
|
148
|
+
const digits = value2.startsWith("-") ? value2.length - 1 : value2.length;
|
|
149
|
+
if (digits > maxDigits || !BIGINT_PATTERN.test(value2)) {
|
|
150
|
+
return void 0;
|
|
151
|
+
}
|
|
152
|
+
return BigInt(value2);
|
|
153
|
+
}
|
|
154
|
+
function* getConstructors(value2) {
|
|
155
|
+
if (!isTypescriptObject(value2)) {
|
|
156
|
+
return;
|
|
157
|
+
}
|
|
158
|
+
let proto = Object.getPrototypeOf(value2);
|
|
159
|
+
while (proto != null) {
|
|
160
|
+
if (proto.constructor) {
|
|
161
|
+
yield proto.constructor;
|
|
162
|
+
}
|
|
163
|
+
proto = Object.getPrototypeOf(proto);
|
|
164
|
+
}
|
|
165
|
+
}
|
|
166
|
+
function isPlainObject(value2) {
|
|
167
|
+
if (!value2 || typeof value2 !== "object") {
|
|
168
|
+
return false;
|
|
169
|
+
}
|
|
170
|
+
const proto = Object.getPrototypeOf(value2);
|
|
171
|
+
return proto === Object.prototype || !proto || !proto.constructor;
|
|
172
|
+
}
|
|
173
|
+
function setOwn(object, key, value2) {
|
|
174
|
+
if (key === "__proto__") {
|
|
175
|
+
Object.defineProperty(object, key, {
|
|
176
|
+
value: value2,
|
|
177
|
+
writable: true,
|
|
178
|
+
enumerable: true,
|
|
179
|
+
configurable: true
|
|
180
|
+
});
|
|
181
|
+
} else {
|
|
182
|
+
object[key] = value2;
|
|
183
|
+
}
|
|
184
|
+
}
|
|
185
|
+
function copyOnWrite(parent, key, original) {
|
|
186
|
+
const value2 = parent[key];
|
|
187
|
+
if (value2 !== original) {
|
|
188
|
+
return value2;
|
|
189
|
+
}
|
|
190
|
+
let copy;
|
|
191
|
+
if (Array.isArray(value2)) {
|
|
192
|
+
copy = value2.slice();
|
|
193
|
+
} else if (isPlainObject(value2)) {
|
|
194
|
+
copy = { ...value2 };
|
|
195
|
+
} else {
|
|
196
|
+
return value2;
|
|
197
|
+
}
|
|
198
|
+
setOwn(parent, key, copy);
|
|
199
|
+
return copy;
|
|
200
|
+
}
|
|
201
|
+
var NullProtoObj = /* @__PURE__ */ (() => {
|
|
202
|
+
const e = function() {
|
|
203
|
+
};
|
|
204
|
+
e.prototype = /* @__PURE__ */ Object.create(null);
|
|
205
|
+
Object.freeze(e.prototype);
|
|
206
|
+
return e;
|
|
207
|
+
})();
|
|
208
|
+
var ORPC_NAME = "orpc";
|
|
209
|
+
function isAbortError(error) {
|
|
210
|
+
return error instanceof Error && error.name.includes("Abort");
|
|
211
|
+
}
|
|
212
|
+
var AsyncGeneratorFunction = Object.getPrototypeOf(async function* () {
|
|
213
|
+
}).constructor;
|
|
214
|
+
function once(fn) {
|
|
215
|
+
let cached;
|
|
216
|
+
return () => {
|
|
217
|
+
if (cached) {
|
|
218
|
+
return cached.result;
|
|
219
|
+
}
|
|
220
|
+
const result = fn();
|
|
221
|
+
cached = { result };
|
|
222
|
+
return result;
|
|
223
|
+
};
|
|
224
|
+
}
|
|
225
|
+
function pathToHttpPath(path) {
|
|
226
|
+
return `/${path.map(safeEncodeURIComponent).join("/")}`;
|
|
227
|
+
}
|
|
228
|
+
var TRACER_SYMBOL = /* @__PURE__ */ Symbol.for("ORPC_TRACER");
|
|
229
|
+
function getTracer() {
|
|
230
|
+
return globalThis[TRACER_SYMBOL];
|
|
231
|
+
}
|
|
232
|
+
function startSpan(options) {
|
|
233
|
+
const tracer = getTracer();
|
|
234
|
+
if (!tracer) {
|
|
235
|
+
return void 0;
|
|
236
|
+
}
|
|
237
|
+
if (typeof options === "string") {
|
|
238
|
+
return tracer.startSpan(options);
|
|
239
|
+
}
|
|
240
|
+
return tracer.startSpan(options.name, options.parent);
|
|
241
|
+
}
|
|
242
|
+
function recordSpanError(span, error) {
|
|
243
|
+
if (!span) {
|
|
244
|
+
return;
|
|
245
|
+
}
|
|
246
|
+
span.recordException(isAbortError(error) ? "info" : "error", toTracingException(error));
|
|
247
|
+
}
|
|
248
|
+
function toTracingException(error) {
|
|
249
|
+
if (error instanceof Error) {
|
|
250
|
+
const exception = {
|
|
251
|
+
message: error.message,
|
|
252
|
+
name: error.name,
|
|
253
|
+
stack: error.stack
|
|
254
|
+
};
|
|
255
|
+
if ("code" in error && (typeof error.code === "string" || typeof error.code === "number")) {
|
|
256
|
+
exception.code = error.code;
|
|
257
|
+
}
|
|
258
|
+
return exception;
|
|
259
|
+
}
|
|
260
|
+
return { message: String(error) };
|
|
261
|
+
}
|
|
262
|
+
async function runWithSpan(options, fn) {
|
|
263
|
+
const tracer = getTracer();
|
|
264
|
+
if (!tracer) {
|
|
265
|
+
return fn();
|
|
266
|
+
}
|
|
267
|
+
const name = typeof options === "string" ? options : options.name;
|
|
268
|
+
const parent = typeof options === "string" ? void 0 : options.parent;
|
|
269
|
+
return tracer.startActiveSpan(name, parent, async (span) => {
|
|
270
|
+
try {
|
|
271
|
+
return await fn(span);
|
|
272
|
+
} catch (e) {
|
|
273
|
+
recordSpanError(span, e);
|
|
274
|
+
throw e;
|
|
275
|
+
} finally {
|
|
276
|
+
span.end();
|
|
277
|
+
}
|
|
278
|
+
});
|
|
279
|
+
}
|
|
280
|
+
function runInSpanContext(span, fn) {
|
|
281
|
+
const tracer = getTracer();
|
|
282
|
+
if (!span || !tracer) {
|
|
283
|
+
return fn();
|
|
284
|
+
}
|
|
285
|
+
return tracer.withActiveSpan(span, fn);
|
|
286
|
+
}
|
|
287
|
+
function wrapAsyncIterator(iterator, { runWith, mapResult, mapError, onError, onFinish }) {
|
|
288
|
+
runWith ??= (run) => run();
|
|
289
|
+
let isDone;
|
|
290
|
+
return new AsyncIteratorClass(async () => {
|
|
291
|
+
try {
|
|
292
|
+
let result;
|
|
293
|
+
try {
|
|
294
|
+
result = await runWith(() => iterator.next());
|
|
295
|
+
isDone = result.done;
|
|
296
|
+
} catch (error) {
|
|
297
|
+
isDone = true;
|
|
298
|
+
throw error;
|
|
299
|
+
}
|
|
300
|
+
return mapResult ? await mapResult(result) : result;
|
|
301
|
+
} catch (error) {
|
|
302
|
+
await onError?.(error);
|
|
303
|
+
throw mapError ? await mapError(error) : error;
|
|
304
|
+
}
|
|
305
|
+
}, async (_state) => {
|
|
306
|
+
try {
|
|
307
|
+
if (!isDone) {
|
|
308
|
+
try {
|
|
309
|
+
await runWith(async () => iterator.return?.());
|
|
310
|
+
} catch (error) {
|
|
311
|
+
await onError?.(error);
|
|
312
|
+
throw error;
|
|
313
|
+
}
|
|
314
|
+
}
|
|
315
|
+
} finally {
|
|
316
|
+
await onFinish?.();
|
|
317
|
+
}
|
|
318
|
+
});
|
|
319
|
+
}
|
|
320
|
+
function traceAsyncIterator(options, iterator) {
|
|
321
|
+
const getSpan = once(() => startSpan(options));
|
|
322
|
+
return wrapAsyncIterator(iterator, {
|
|
323
|
+
runWith: (run) => runInSpanContext(getSpan(), run),
|
|
324
|
+
mapResult(result) {
|
|
325
|
+
getSpan()?.addEvent(result.done ? "completed" : "yielded");
|
|
326
|
+
return result;
|
|
327
|
+
},
|
|
328
|
+
onError(error) {
|
|
329
|
+
recordSpanError(getSpan(), error);
|
|
330
|
+
},
|
|
331
|
+
onFinish() {
|
|
332
|
+
getSpan()?.end();
|
|
333
|
+
}
|
|
334
|
+
});
|
|
335
|
+
}
|
|
336
|
+
function value(value2, ...args) {
|
|
337
|
+
if (typeof value2 === "function") {
|
|
338
|
+
return value2(...args);
|
|
339
|
+
}
|
|
340
|
+
return value2;
|
|
341
|
+
}
|
|
342
|
+
function override(target, partial) {
|
|
343
|
+
const proxy = new Proxy(typeof target === "function" ? partial : target, {
|
|
344
|
+
get(_, prop) {
|
|
345
|
+
const targetValue = prop in partial ? partial : value(target);
|
|
346
|
+
return getOrBind(targetValue, prop);
|
|
347
|
+
},
|
|
348
|
+
has(_, prop) {
|
|
349
|
+
return Reflect.has(partial, prop) || Reflect.has(value(target), prop);
|
|
350
|
+
}
|
|
351
|
+
});
|
|
352
|
+
return proxy;
|
|
353
|
+
}
|
|
354
|
+
function wrapReadableStream(stream, { runWith, mapResult, mapError, onError, onFinish }) {
|
|
355
|
+
runWith ??= (run) => run();
|
|
356
|
+
const reader = once(() => stream.getReader());
|
|
357
|
+
const finish = once(async () => onFinish?.());
|
|
358
|
+
return new ReadableStream({
|
|
359
|
+
async pull(controller) {
|
|
360
|
+
let result;
|
|
361
|
+
try {
|
|
362
|
+
const readResult = await runWith(() => reader().read());
|
|
363
|
+
result = mapResult ? await mapResult(readResult) : readResult;
|
|
364
|
+
} catch (error) {
|
|
365
|
+
try {
|
|
366
|
+
await onError?.(error);
|
|
367
|
+
controller.error(mapError ? await mapError(error) : error);
|
|
368
|
+
} finally {
|
|
369
|
+
await finish();
|
|
370
|
+
}
|
|
371
|
+
return;
|
|
372
|
+
}
|
|
373
|
+
if (result.done) {
|
|
374
|
+
controller.close();
|
|
375
|
+
await finish();
|
|
376
|
+
} else {
|
|
377
|
+
controller.enqueue(result.value);
|
|
378
|
+
}
|
|
379
|
+
},
|
|
380
|
+
async cancel(reason) {
|
|
381
|
+
try {
|
|
382
|
+
try {
|
|
383
|
+
await runWith(() => reader().cancel(reason));
|
|
384
|
+
} catch (error) {
|
|
385
|
+
await onError?.(error);
|
|
386
|
+
throw error;
|
|
387
|
+
}
|
|
388
|
+
} finally {
|
|
389
|
+
await finish();
|
|
390
|
+
}
|
|
391
|
+
}
|
|
392
|
+
}, { highWaterMark: 0 });
|
|
393
|
+
}
|
|
394
|
+
function traceReadableStream(options, stream) {
|
|
395
|
+
const getSpan = once(() => startSpan(options));
|
|
396
|
+
return wrapReadableStream(stream, {
|
|
397
|
+
runWith: (run) => runInSpanContext(getSpan(), run),
|
|
398
|
+
mapResult(result) {
|
|
399
|
+
getSpan()?.addEvent(result.done ? "closed" : "enqueued");
|
|
400
|
+
return result;
|
|
401
|
+
},
|
|
402
|
+
onError(error) {
|
|
403
|
+
recordSpanError(getSpan(), error);
|
|
404
|
+
},
|
|
405
|
+
onFinish() {
|
|
406
|
+
getSpan()?.end();
|
|
407
|
+
}
|
|
408
|
+
});
|
|
409
|
+
}
|
|
410
|
+
function intercept(interceptors, options, main) {
|
|
411
|
+
if (!interceptors?.length) {
|
|
412
|
+
return main(options);
|
|
413
|
+
}
|
|
414
|
+
const next = (options2, index) => {
|
|
415
|
+
const interceptor = interceptors[index];
|
|
416
|
+
if (!interceptor) {
|
|
417
|
+
return main(options2);
|
|
418
|
+
}
|
|
419
|
+
return interceptor({
|
|
420
|
+
...options2,
|
|
421
|
+
next: (newOptions = options2) => next(newOptions, index + 1)
|
|
422
|
+
});
|
|
423
|
+
};
|
|
424
|
+
return next(options, 0);
|
|
425
|
+
}
|
|
426
|
+
function sortPlugins(plugins) {
|
|
427
|
+
const pluginCount = plugins.length;
|
|
428
|
+
const pluginIdToIndices = /* @__PURE__ */ new Map();
|
|
429
|
+
for (let i = 0; i < pluginCount; i++) {
|
|
430
|
+
const plugin = plugins[i];
|
|
431
|
+
const indices = pluginIdToIndices.get(plugin.name);
|
|
432
|
+
if (indices === void 0) {
|
|
433
|
+
pluginIdToIndices.set(plugin.name, [i]);
|
|
434
|
+
} else {
|
|
435
|
+
indices.push(i);
|
|
436
|
+
}
|
|
437
|
+
}
|
|
438
|
+
const dependencies = Array.from({ length: pluginCount }, () => []);
|
|
439
|
+
for (let i = 0; i < pluginCount; i++) {
|
|
440
|
+
const plugin = plugins[i];
|
|
441
|
+
if (plugin.before !== void 0) {
|
|
442
|
+
for (const beforeId of plugin.before) {
|
|
443
|
+
const beforeIndices = pluginIdToIndices.get(beforeId);
|
|
444
|
+
if (beforeIndices !== void 0) {
|
|
445
|
+
for (const beforeIndex of beforeIndices) {
|
|
446
|
+
dependencies[beforeIndex].push(i);
|
|
447
|
+
}
|
|
448
|
+
}
|
|
449
|
+
}
|
|
450
|
+
}
|
|
451
|
+
if (plugin.after !== void 0) {
|
|
452
|
+
for (const afterId of plugin.after) {
|
|
453
|
+
const afterIndices = pluginIdToIndices.get(afterId);
|
|
454
|
+
if (afterIndices !== void 0) {
|
|
455
|
+
for (const afterIndex of afterIndices) {
|
|
456
|
+
dependencies[i].push(afterIndex);
|
|
457
|
+
}
|
|
458
|
+
}
|
|
459
|
+
}
|
|
460
|
+
}
|
|
461
|
+
}
|
|
462
|
+
const sorted = [];
|
|
463
|
+
const placed = /* @__PURE__ */ new Set();
|
|
464
|
+
while (sorted.length < pluginCount) {
|
|
465
|
+
const next = plugins.findIndex((_, i) => !placed.has(i) && dependencies[i].every((dependency) => placed.has(dependency)));
|
|
466
|
+
if (next === -1) {
|
|
467
|
+
throw new Error(`Circular dependency detected involving plugin "${findCyclicPlugin(plugins, dependencies, placed).name}"`);
|
|
468
|
+
}
|
|
469
|
+
placed.add(next);
|
|
470
|
+
sorted.push(plugins[next]);
|
|
471
|
+
}
|
|
472
|
+
return sorted;
|
|
473
|
+
}
|
|
474
|
+
function findCyclicPlugin(plugins, dependencies, placed) {
|
|
475
|
+
const seen = /* @__PURE__ */ new Set();
|
|
476
|
+
let current = plugins.findIndex((_, i) => !placed.has(i));
|
|
477
|
+
while (!seen.has(current)) {
|
|
478
|
+
seen.add(current);
|
|
479
|
+
current = dependencies[current].find((dependency) => !placed.has(dependency));
|
|
480
|
+
}
|
|
481
|
+
return plugins[current];
|
|
482
|
+
}
|
|
483
|
+
|
|
484
|
+
// ../../../node_modules/.pnpm/@standard-server+core@0.13.0/node_modules/@standard-server/core/dist/index.mjs
|
|
485
|
+
var EventStreamEncoderError = class extends TypeError {
|
|
486
|
+
};
|
|
487
|
+
var EventStreamDecoderError = class extends TypeError {
|
|
488
|
+
};
|
|
489
|
+
var ErrorEvent = class extends Error {
|
|
490
|
+
constructor(data, options = {}) {
|
|
491
|
+
super(options?.message ?? "Error Event", options);
|
|
492
|
+
this.data = data;
|
|
493
|
+
}
|
|
494
|
+
};
|
|
495
|
+
var EVENT_STREAM_LINE_ENDING_REGEX = /\r\n|[\n\r]/;
|
|
496
|
+
var EVENT_STREAM_LINE_ENDING_GLOBAL_REGEX = /\r\n|[\n\r]/g;
|
|
497
|
+
var EVENT_STREAM_INVALID_ID_CHAR_REGEX = /[\r\n\0]/;
|
|
498
|
+
function containsEventStreamLineBreak(value2) {
|
|
499
|
+
return EVENT_STREAM_LINE_ENDING_REGEX.test(value2);
|
|
500
|
+
}
|
|
501
|
+
function isEventStreamMessageId(maybe) {
|
|
502
|
+
return typeof maybe === "string" && !EVENT_STREAM_INVALID_ID_CHAR_REGEX.test(maybe);
|
|
503
|
+
}
|
|
504
|
+
function isEventStreamMessageRetry(maybe) {
|
|
505
|
+
return Number.isInteger(maybe) && maybe >= 0;
|
|
506
|
+
}
|
|
507
|
+
function isEventStreamMessageComment(maybe) {
|
|
508
|
+
return typeof maybe === "string" && !containsEventStreamLineBreak(maybe);
|
|
509
|
+
}
|
|
510
|
+
function assertEventStreamMessageId(id) {
|
|
511
|
+
if (!isEventStreamMessageId(id)) {
|
|
512
|
+
throw new EventStreamEncoderError(
|
|
513
|
+
"Event's id must not contain a carriage return, newline or NULL character"
|
|
514
|
+
);
|
|
515
|
+
}
|
|
516
|
+
}
|
|
517
|
+
function assertEventStreamMessageName(event) {
|
|
518
|
+
if (containsEventStreamLineBreak(event)) {
|
|
519
|
+
throw new EventStreamEncoderError(
|
|
520
|
+
"Event's event must not contain a carriage return or newline character"
|
|
521
|
+
);
|
|
522
|
+
}
|
|
523
|
+
}
|
|
524
|
+
function assertEventStreamMessageRetry(retry) {
|
|
525
|
+
if (!isEventStreamMessageRetry(retry)) {
|
|
526
|
+
throw new EventStreamEncoderError("Event's retry must be a integer and >= 0");
|
|
527
|
+
}
|
|
528
|
+
}
|
|
529
|
+
function assertEventStreamMessageComment(comment) {
|
|
530
|
+
if (!isEventStreamMessageComment(comment)) {
|
|
531
|
+
throw new EventStreamEncoderError(
|
|
532
|
+
"Event's comment must not contain a carriage return or newline character"
|
|
533
|
+
);
|
|
534
|
+
}
|
|
535
|
+
}
|
|
536
|
+
function encodeEventStreamMessageData(data) {
|
|
537
|
+
if (data === void 0) {
|
|
538
|
+
return "";
|
|
539
|
+
}
|
|
540
|
+
return `data: ${data.replace(EVENT_STREAM_LINE_ENDING_GLOBAL_REGEX, "\ndata: ")}
|
|
541
|
+
`;
|
|
542
|
+
}
|
|
543
|
+
function encodeEventStreamMessageComments(comments) {
|
|
544
|
+
let output = "";
|
|
545
|
+
for (const comment of comments ?? []) {
|
|
546
|
+
assertEventStreamMessageComment(comment);
|
|
547
|
+
output += `: ${comment}
|
|
548
|
+
`;
|
|
549
|
+
}
|
|
550
|
+
return output;
|
|
551
|
+
}
|
|
552
|
+
function encodeEventStreamMessage(message) {
|
|
553
|
+
let output = "";
|
|
554
|
+
output += encodeEventStreamMessageComments(message.comments);
|
|
555
|
+
if (message.event !== void 0 && (message.event !== "message" || message.data === void 0)) {
|
|
556
|
+
assertEventStreamMessageName(message.event);
|
|
557
|
+
output += `event: ${message.event}
|
|
558
|
+
`;
|
|
559
|
+
}
|
|
560
|
+
if (message.retry !== void 0) {
|
|
561
|
+
assertEventStreamMessageRetry(message.retry);
|
|
562
|
+
output += `retry: ${message.retry}
|
|
563
|
+
`;
|
|
564
|
+
}
|
|
565
|
+
if (message.id !== void 0) {
|
|
566
|
+
assertEventStreamMessageId(message.id);
|
|
567
|
+
output += `id: ${message.id}
|
|
568
|
+
`;
|
|
569
|
+
}
|
|
570
|
+
output += encodeEventStreamMessageData(message.data);
|
|
571
|
+
output += "\n";
|
|
572
|
+
return output;
|
|
573
|
+
}
|
|
574
|
+
var LINE_ENDING_REGEX = /\r\n?|\n/;
|
|
575
|
+
var MESSAGE_DELIMITER_REGEX = /[\r\n]{3,}|\r\r|\n[\r\n]/g;
|
|
576
|
+
var LEADING_LINE_ENDINGS_REGEX = /^[\r\n]+/;
|
|
577
|
+
var ASCII_DIGITS_REGEX = /^\d+$/;
|
|
578
|
+
var SPACE = 32;
|
|
579
|
+
var LF = 10;
|
|
580
|
+
var CR = 13;
|
|
581
|
+
function decodeEventStreamMessage(encoded) {
|
|
582
|
+
const message = {};
|
|
583
|
+
for (const line of encoded.split(LINE_ENDING_REGEX)) {
|
|
584
|
+
if (line === "") {
|
|
585
|
+
continue;
|
|
586
|
+
}
|
|
587
|
+
const index = line.indexOf(":");
|
|
588
|
+
const value2 = index === -1 ? "" : line.slice(line.charCodeAt(index + 1) === SPACE ? index + 2 : index + 1);
|
|
589
|
+
if (index === 0) {
|
|
590
|
+
(message.comments ??= []).push(value2);
|
|
591
|
+
continue;
|
|
592
|
+
}
|
|
593
|
+
switch (index === -1 ? line : line.slice(0, index)) {
|
|
594
|
+
case "data":
|
|
595
|
+
message.data = message.data === void 0 ? value2 : `${message.data}
|
|
596
|
+
${value2}`;
|
|
597
|
+
break;
|
|
598
|
+
case "event":
|
|
599
|
+
message.event = value2;
|
|
600
|
+
break;
|
|
601
|
+
case "id":
|
|
602
|
+
if (isEventStreamMessageId(value2)) {
|
|
603
|
+
message.id = value2;
|
|
604
|
+
}
|
|
605
|
+
break;
|
|
606
|
+
case "retry": {
|
|
607
|
+
const retry = Number.parseInt(value2, 10);
|
|
608
|
+
if (ASCII_DIGITS_REGEX.test(value2) && isEventStreamMessageRetry(retry)) {
|
|
609
|
+
message.retry = retry;
|
|
610
|
+
}
|
|
611
|
+
break;
|
|
612
|
+
}
|
|
613
|
+
}
|
|
614
|
+
}
|
|
615
|
+
if (!message.event) {
|
|
616
|
+
if (message.data === void 0) {
|
|
617
|
+
delete message.event;
|
|
618
|
+
} else {
|
|
619
|
+
message.event = "message";
|
|
620
|
+
}
|
|
621
|
+
}
|
|
622
|
+
return message;
|
|
623
|
+
}
|
|
624
|
+
var EventStreamDecoder = class {
|
|
625
|
+
constructor(onEvent) {
|
|
626
|
+
this.onEvent = onEvent;
|
|
627
|
+
}
|
|
628
|
+
// The incomplete message: empty, or text that neither starts with a line
|
|
629
|
+
// ending nor contains a blank line.
|
|
630
|
+
pending = [];
|
|
631
|
+
// Last MAX_DELIMITER_OVERLAP characters of the pending text, prefixed to the
|
|
632
|
+
// next chunk so a delimiter straddling the boundary is still found.
|
|
633
|
+
tail = "";
|
|
634
|
+
feed(chunk) {
|
|
635
|
+
if (this.pending.length === 0) {
|
|
636
|
+
const first = chunk.charCodeAt(0);
|
|
637
|
+
if (first === LF || first === CR) {
|
|
638
|
+
chunk = chunk.replace(LEADING_LINE_ENDINGS_REGEX, "");
|
|
639
|
+
}
|
|
640
|
+
}
|
|
641
|
+
if (chunk === "") {
|
|
642
|
+
return;
|
|
643
|
+
}
|
|
644
|
+
const scan = this.tail + chunk;
|
|
645
|
+
this.pending.push(chunk);
|
|
646
|
+
MESSAGE_DELIMITER_REGEX.lastIndex = 0;
|
|
647
|
+
let match = MESSAGE_DELIMITER_REGEX.exec(scan);
|
|
648
|
+
if (match === null) {
|
|
649
|
+
this.tail = scan.slice(-2);
|
|
650
|
+
return;
|
|
651
|
+
}
|
|
652
|
+
const buffered = this.pending.length === 1 ? chunk : this.pending.join("");
|
|
653
|
+
const offset = buffered.length - scan.length;
|
|
654
|
+
const parts = [];
|
|
655
|
+
let start = 0;
|
|
656
|
+
while (match !== null) {
|
|
657
|
+
parts.push(buffered.slice(start, offset + match.index));
|
|
658
|
+
start = offset + match.index + match[0].length;
|
|
659
|
+
match = MESSAGE_DELIMITER_REGEX.exec(scan);
|
|
660
|
+
}
|
|
661
|
+
const incomplete = buffered.slice(start);
|
|
662
|
+
this.pending = incomplete === "" ? [] : [incomplete];
|
|
663
|
+
this.tail = incomplete.slice(-2);
|
|
664
|
+
for (const encoded of parts) {
|
|
665
|
+
this.onEvent(decodeEventStreamMessage(encoded));
|
|
666
|
+
}
|
|
667
|
+
}
|
|
668
|
+
end() {
|
|
669
|
+
if (this.pending.length !== 0) {
|
|
670
|
+
throw new EventStreamDecoderError("Event Stream ended before complete");
|
|
671
|
+
}
|
|
672
|
+
}
|
|
673
|
+
};
|
|
674
|
+
var EventStreamDecoderStream = class {
|
|
675
|
+
readable;
|
|
676
|
+
writable;
|
|
677
|
+
constructor() {
|
|
678
|
+
let decoder;
|
|
679
|
+
const transform = new TransformStream({
|
|
680
|
+
start(controller) {
|
|
681
|
+
decoder = new EventStreamDecoder((event) => {
|
|
682
|
+
controller.enqueue(event);
|
|
683
|
+
});
|
|
684
|
+
},
|
|
685
|
+
transform(chunk) {
|
|
686
|
+
decoder.feed(chunk);
|
|
687
|
+
},
|
|
688
|
+
flush() {
|
|
689
|
+
decoder.end();
|
|
690
|
+
}
|
|
691
|
+
});
|
|
692
|
+
this.readable = transform.readable;
|
|
693
|
+
this.writable = transform.writable;
|
|
694
|
+
}
|
|
695
|
+
};
|
|
696
|
+
var EVENT_META_SYMBOL = /* @__PURE__ */ Symbol.for("STANDARD_SERVER_EVENT_META");
|
|
697
|
+
var EVENT_SOURCE_SYMBOL = /* @__PURE__ */ Symbol.for("STANDARD_SERVER_EVENT_SOURCE");
|
|
698
|
+
function withEventMeta(container, meta) {
|
|
699
|
+
let assertedMeta;
|
|
700
|
+
if (meta.id !== void 0) {
|
|
701
|
+
assertEventStreamMessageId(meta.id);
|
|
702
|
+
assertedMeta ??= {};
|
|
703
|
+
assertedMeta.id = meta.id;
|
|
704
|
+
}
|
|
705
|
+
if (meta.retry !== void 0) {
|
|
706
|
+
assertEventStreamMessageRetry(meta.retry);
|
|
707
|
+
assertedMeta ??= {};
|
|
708
|
+
assertedMeta.retry = meta.retry;
|
|
709
|
+
}
|
|
710
|
+
if (meta.comments !== void 0) {
|
|
711
|
+
for (const comment of meta.comments) {
|
|
712
|
+
assertEventStreamMessageComment(comment);
|
|
713
|
+
}
|
|
714
|
+
assertedMeta ??= {};
|
|
715
|
+
assertedMeta.comments = meta.comments;
|
|
716
|
+
}
|
|
717
|
+
if (!assertedMeta) {
|
|
718
|
+
return container;
|
|
719
|
+
}
|
|
720
|
+
return new Proxy(container, {
|
|
721
|
+
get(target, prop, _receiver) {
|
|
722
|
+
if (prop === EVENT_SOURCE_SYMBOL) {
|
|
723
|
+
return target;
|
|
724
|
+
}
|
|
725
|
+
if (prop === EVENT_META_SYMBOL) {
|
|
726
|
+
return assertedMeta;
|
|
727
|
+
}
|
|
728
|
+
return getOrBind(target, prop, { bind: prop !== "constructor" });
|
|
729
|
+
}
|
|
730
|
+
});
|
|
731
|
+
}
|
|
732
|
+
function unwrapEvent(container) {
|
|
733
|
+
if (!isTypescriptObject(container)) {
|
|
734
|
+
return [container, void 0];
|
|
735
|
+
}
|
|
736
|
+
const meta = container[EVENT_META_SYMBOL];
|
|
737
|
+
const target = container[EVENT_SOURCE_SYMBOL] ?? container;
|
|
738
|
+
return [target, meta];
|
|
739
|
+
}
|
|
740
|
+
function getEventMeta(container) {
|
|
741
|
+
if (!isTypescriptObject(container)) {
|
|
742
|
+
return void 0;
|
|
743
|
+
}
|
|
744
|
+
return container[EVENT_META_SYMBOL];
|
|
745
|
+
}
|
|
746
|
+
var FALLBACK_FILENAME_UNSAFE_CHAR_REGEX = /[^\x20-\x7E]|[;=]/g;
|
|
747
|
+
var QUOTED_STRING_SPECIAL_CHAR_REGEX = /[\\"]/g;
|
|
748
|
+
var QUOTED_PAIR_REGEX = /\\(.)/g;
|
|
749
|
+
var EXT_VALUE_RESERVED_CHAR_REGEX = /['()*]/g;
|
|
750
|
+
var EXT_VALUE_ALLOWED_ESCAPE_REGEX = /%(7C|60|5E)/g;
|
|
751
|
+
var EXT_VALUE_REGEX = /^([^']*)'[^']*'(.*)$/;
|
|
752
|
+
var EXT_VALUE_SUPPORTED_CHARSET_REGEX = /^(?:utf-8|us-ascii)$/i;
|
|
753
|
+
var CONTENT_DISPOSITION_PARAM_REGEX = /[\s;]*([^;=]*)(?:=\s*(?:"((?:\\.|[^"\\])*)"[^;]*|"[\s\S]*|([^;]*)))?/y;
|
|
754
|
+
function generateContentDisposition(filename, type = "inline") {
|
|
755
|
+
const encodedFilename = filename.replace(FALLBACK_FILENAME_UNSAFE_CHAR_REGEX, "_").replace(QUOTED_STRING_SPECIAL_CHAR_REGEX, "\\$&");
|
|
756
|
+
const encodedFilenameStar = safeEncodeURIComponent(filename).replace(EXT_VALUE_RESERVED_CHAR_REGEX, (c) => `%${c.charCodeAt(0).toString(16).toUpperCase()}`).replace(
|
|
757
|
+
EXT_VALUE_ALLOWED_ESCAPE_REGEX,
|
|
758
|
+
(str, hex) => String.fromCharCode(Number.parseInt(hex, 16))
|
|
759
|
+
);
|
|
760
|
+
return `${type}; filename="${encodedFilename}"; filename*=utf-8''${encodedFilenameStar}`;
|
|
761
|
+
}
|
|
762
|
+
function getContentDispositionParam(contentDisposition, name) {
|
|
763
|
+
CONTENT_DISPOSITION_PARAM_REGEX.lastIndex = 0;
|
|
764
|
+
while (CONTENT_DISPOSITION_PARAM_REGEX.lastIndex < contentDisposition.length) {
|
|
765
|
+
const [, paramName = "", quoted, token] = CONTENT_DISPOSITION_PARAM_REGEX.exec(contentDisposition);
|
|
766
|
+
if (paramName.trimEnd().toLowerCase() === name) {
|
|
767
|
+
return quoted !== void 0 ? quoted.replace(QUOTED_PAIR_REGEX, "$1") : token?.trim() || void 0;
|
|
768
|
+
}
|
|
769
|
+
}
|
|
770
|
+
return void 0;
|
|
771
|
+
}
|
|
772
|
+
function getFilenameFromContentDisposition(contentDisposition) {
|
|
773
|
+
const extValue = getContentDispositionParam(contentDisposition, "filename*");
|
|
774
|
+
const extValueMatch = extValue?.match(EXT_VALUE_REGEX);
|
|
775
|
+
if (extValueMatch) {
|
|
776
|
+
const [, charset = "", encodedFilename = ""] = extValueMatch;
|
|
777
|
+
if (EXT_VALUE_SUPPORTED_CHARSET_REGEX.test(charset)) {
|
|
778
|
+
return safeDecodeURIComponent(encodedFilename);
|
|
779
|
+
}
|
|
780
|
+
} else if (extValue) {
|
|
781
|
+
return safeDecodeURIComponent(extValue);
|
|
782
|
+
}
|
|
783
|
+
return getContentDispositionParam(contentDisposition, "filename");
|
|
784
|
+
}
|
|
785
|
+
function flattenStandardHeader(header) {
|
|
786
|
+
if (typeof header === "string" || header === void 0) {
|
|
787
|
+
return header;
|
|
788
|
+
}
|
|
789
|
+
if (header.length === 0) {
|
|
790
|
+
return void 0;
|
|
791
|
+
}
|
|
792
|
+
return header.join(", ");
|
|
793
|
+
}
|
|
794
|
+
var STANDARD_BODY_HINT_SET = /* @__PURE__ */ new Set([
|
|
795
|
+
"json",
|
|
796
|
+
"form-data",
|
|
797
|
+
"url-search-params",
|
|
798
|
+
"event-stream",
|
|
799
|
+
"octet-stream",
|
|
800
|
+
"file",
|
|
801
|
+
"none"
|
|
802
|
+
]);
|
|
803
|
+
function resolveStandardBodyHint(headers) {
|
|
804
|
+
const hint = flattenStandardHeader(headers["standard-server"]);
|
|
805
|
+
if (hint !== void 0 && STANDARD_BODY_HINT_SET.has(hint)) {
|
|
806
|
+
return hint;
|
|
807
|
+
}
|
|
808
|
+
const mimeType = flattenStandardHeader(headers["content-type"])?.split(";")[0]?.trim().toLowerCase();
|
|
809
|
+
const contentLength = flattenStandardHeader(headers["content-length"]);
|
|
810
|
+
if (mimeType === void 0 && (contentLength === void 0 || contentLength === "0")) {
|
|
811
|
+
return "none";
|
|
812
|
+
}
|
|
813
|
+
if (mimeType === "application/json") {
|
|
814
|
+
return "json";
|
|
815
|
+
}
|
|
816
|
+
if (mimeType === "multipart/form-data") {
|
|
817
|
+
return "form-data";
|
|
818
|
+
}
|
|
819
|
+
if (mimeType === "application/x-www-form-urlencoded") {
|
|
820
|
+
return "url-search-params";
|
|
821
|
+
}
|
|
822
|
+
if (mimeType === "text/event-stream") {
|
|
823
|
+
return "event-stream";
|
|
824
|
+
}
|
|
825
|
+
if (contentLength !== void 0) {
|
|
826
|
+
return "file";
|
|
827
|
+
}
|
|
828
|
+
const contentDisposition = flattenStandardHeader(headers["content-disposition"]);
|
|
829
|
+
if (contentDisposition !== void 0 && getFilenameFromContentDisposition(contentDisposition) !== void 0) {
|
|
830
|
+
return "file";
|
|
831
|
+
}
|
|
832
|
+
return "octet-stream";
|
|
833
|
+
}
|
|
834
|
+
function getRequiredStandardBodyHint(hint, headers) {
|
|
835
|
+
const resolved = resolveStandardBodyHint({
|
|
836
|
+
"content-type": headers["content-type"],
|
|
837
|
+
"content-length": headers["content-length"],
|
|
838
|
+
"content-disposition": headers["content-disposition"]
|
|
839
|
+
});
|
|
840
|
+
return resolved === hint ? void 0 : hint;
|
|
841
|
+
}
|
|
842
|
+
function mergeStandardHeaders(a, b) {
|
|
843
|
+
const merged = { ...a, ...b };
|
|
844
|
+
for (const key of Object.keys(b)) {
|
|
845
|
+
if (!Object.hasOwn(a, key)) {
|
|
846
|
+
continue;
|
|
847
|
+
}
|
|
848
|
+
const aValue = a[key];
|
|
849
|
+
const bValue = b[key];
|
|
850
|
+
merged[key] = aValue === void 0 || bValue === void 0 ? aValue ?? bValue : [...toArray(aValue), ...toArray(bValue)];
|
|
851
|
+
}
|
|
852
|
+
return merged;
|
|
853
|
+
}
|
|
854
|
+
function parseStandardUrl(url) {
|
|
855
|
+
const hashStart = url.indexOf("#");
|
|
856
|
+
const searchStart = url.indexOf("?");
|
|
857
|
+
const hasSearchBeforeHash = searchStart !== -1 && (hashStart === -1 || searchStart < hashStart);
|
|
858
|
+
const pathnameEnd = hasSearchBeforeHash ? searchStart : hashStart !== -1 ? hashStart : url.length;
|
|
859
|
+
const searchEnd = hashStart !== -1 ? hashStart : url.length;
|
|
860
|
+
const pathname = url.slice(0, pathnameEnd);
|
|
861
|
+
const search = hasSearchBeforeHash ? url.slice(searchStart, searchEnd) : void 0;
|
|
862
|
+
const hash = hashStart !== -1 ? url.slice(hashStart) : void 0;
|
|
863
|
+
return [pathname, search, hash];
|
|
864
|
+
}
|
|
865
|
+
|
|
866
|
+
// ../../../node_modules/.pnpm/@orpc+client@2.0.0-beta.47/node_modules/@orpc/client/dist/shared/client.LF04eOvL.mjs
|
|
867
|
+
var COMMON_ERROR_STATUS_MAP = {
|
|
868
|
+
BAD_REQUEST: 400,
|
|
869
|
+
UNAUTHORIZED: 401,
|
|
870
|
+
PAYMENT_REQUIRED: 402,
|
|
871
|
+
FORBIDDEN: 403,
|
|
872
|
+
NOT_FOUND: 404,
|
|
873
|
+
METHOD_NOT_SUPPORTED: 405,
|
|
874
|
+
NOT_ACCEPTABLE: 406,
|
|
875
|
+
TIMEOUT: 408,
|
|
876
|
+
CONFLICT: 409,
|
|
877
|
+
GONE: 410,
|
|
878
|
+
LENGTH_REQUIRED: 411,
|
|
879
|
+
PRECONDITION_FAILED: 412,
|
|
880
|
+
PAYLOAD_TOO_LARGE: 413,
|
|
881
|
+
UNSUPPORTED_MEDIA_TYPE: 415,
|
|
882
|
+
UNPROCESSABLE_CONTENT: 422,
|
|
883
|
+
PRECONDITION_REQUIRED: 428,
|
|
884
|
+
TOO_MANY_REQUESTS: 429,
|
|
885
|
+
CLIENT_CLOSED_REQUEST: 499,
|
|
886
|
+
INTERNAL_SERVER_ERROR: 500,
|
|
887
|
+
NOT_IMPLEMENTED: 501,
|
|
888
|
+
BAD_GATEWAY: 502,
|
|
889
|
+
SERVICE_UNAVAILABLE: 503,
|
|
890
|
+
GATEWAY_TIMEOUT: 504
|
|
891
|
+
};
|
|
892
|
+
var ORPCErrorConstructors;
|
|
893
|
+
var ORPCError = class _ORPCError extends Error {
|
|
894
|
+
static {
|
|
895
|
+
const ORPC_ERROR_CONSTRUCTORS_SYMBOL = /* @__PURE__ */ Symbol.for("ORPC_ERROR_CONSTRUCTORS");
|
|
896
|
+
void (globalThis[ORPC_ERROR_CONSTRUCTORS_SYMBOL] ??= /* @__PURE__ */ new WeakSet());
|
|
897
|
+
ORPCErrorConstructors = globalThis[ORPC_ERROR_CONSTRUCTORS_SYMBOL];
|
|
898
|
+
ORPCErrorConstructors.add(_ORPCError);
|
|
899
|
+
}
|
|
900
|
+
/**
|
|
901
|
+
* @remarks
|
|
902
|
+
* **Note**: The `__branch` property is used for type branding, helping TypeScript distinguish
|
|
903
|
+
* an `ORPCError` instance from plain objects with a similar structure.
|
|
904
|
+
*/
|
|
905
|
+
name = "ORPCError";
|
|
906
|
+
/**
|
|
907
|
+
* Indicates whether the error matches a definition in the procedure's `.errors` map,
|
|
908
|
+
* which makes its type inferable on the client.
|
|
909
|
+
*/
|
|
910
|
+
defined = false;
|
|
911
|
+
code;
|
|
912
|
+
data;
|
|
913
|
+
constructor(code, ...rest) {
|
|
914
|
+
const options = resolveMaybeOptionalOptions(rest);
|
|
915
|
+
const message = options.message ?? codeToMessage(code);
|
|
916
|
+
super(message, options);
|
|
917
|
+
this.code = code;
|
|
918
|
+
this.data = options.data;
|
|
919
|
+
}
|
|
920
|
+
toJSON() {
|
|
921
|
+
return {
|
|
922
|
+
defined: this.defined,
|
|
923
|
+
code: this.code,
|
|
924
|
+
message: this.message,
|
|
925
|
+
data: this.data
|
|
926
|
+
};
|
|
927
|
+
}
|
|
928
|
+
/**
|
|
929
|
+
* Workaround for Next.js where different contexts use separate
|
|
930
|
+
* dependency graphs, causing multiple ORPCError constructors existing and breaking
|
|
931
|
+
* `instanceof` checks across contexts.
|
|
932
|
+
*
|
|
933
|
+
* This is particularly problematic with "Optimized SSR", where orpc-client
|
|
934
|
+
* executes in one context but is invoked from another. When an error is thrown
|
|
935
|
+
* in the execution context, `instanceof ORPCError` checks fail in the
|
|
936
|
+
* invocation context due to separate class constructors.
|
|
937
|
+
*
|
|
938
|
+
* @todo Remove this and related code if Next.js resolves the multiple dependency graph issue.
|
|
939
|
+
*/
|
|
940
|
+
static [Symbol.hasInstance](instance) {
|
|
941
|
+
if (!ORPCErrorConstructors.has(this)) {
|
|
942
|
+
return super[Symbol.hasInstance](instance);
|
|
943
|
+
}
|
|
944
|
+
for (const constructor of getConstructors(instance)) {
|
|
945
|
+
if (ORPCErrorConstructors.has(constructor)) {
|
|
946
|
+
return true;
|
|
947
|
+
}
|
|
948
|
+
}
|
|
949
|
+
return false;
|
|
950
|
+
}
|
|
951
|
+
};
|
|
952
|
+
var ResponseError = class extends Error {
|
|
953
|
+
name = "ResponseError";
|
|
954
|
+
response;
|
|
955
|
+
constructor(options) {
|
|
956
|
+
super(options.message ?? `Received a ${options.response.status} response.`, options);
|
|
957
|
+
this.response = options.response;
|
|
958
|
+
}
|
|
959
|
+
};
|
|
960
|
+
var MalformedResponseError = class extends ResponseError {
|
|
961
|
+
name = "MalformedResponseError";
|
|
962
|
+
constructor(options) {
|
|
963
|
+
super({ ...options, message: options.message ?? inferMalformedResponseMessage(options.response) });
|
|
964
|
+
}
|
|
965
|
+
};
|
|
966
|
+
var INFERRED_MESSAGE_MAX_LENGTH = 256;
|
|
967
|
+
function inferMalformedResponseMessage(response) {
|
|
968
|
+
const candidate = isPlainObject(response.body) ? response.body.message : response.body;
|
|
969
|
+
if (typeof candidate === "string" && candidate.length > 0 && candidate.length <= INFERRED_MESSAGE_MAX_LENGTH) {
|
|
970
|
+
return candidate;
|
|
971
|
+
}
|
|
972
|
+
const commonCode = Object.entries(COMMON_ERROR_STATUS_MAP).find(([, status]) => status === response.status)?.[0];
|
|
973
|
+
return commonCode ? codeToMessage(commonCode) : "Malformed oRPC Response";
|
|
974
|
+
}
|
|
975
|
+
function codeToMessage(code) {
|
|
976
|
+
return code.split("_").map((word) => word.charAt(0).toUpperCase() + word.slice(1).toLowerCase()).join(" ");
|
|
977
|
+
}
|
|
978
|
+
|
|
979
|
+
// ../../../node_modules/.pnpm/@orpc+client@2.0.0-beta.47/node_modules/@orpc/client/dist/shared/client._wG5INmC.mjs
|
|
980
|
+
function toORPCError(error) {
|
|
981
|
+
return error instanceof ORPCError ? error : new ORPCError("INTERNAL_SERVER_ERROR", { cause: error });
|
|
982
|
+
}
|
|
983
|
+
function isORPCErrorJson(json) {
|
|
984
|
+
if (!isPlainObject(json)) {
|
|
985
|
+
return false;
|
|
986
|
+
}
|
|
987
|
+
const validKeys = ["defined", "code", "message", "data"];
|
|
988
|
+
if (Object.keys(json).some((k) => !validKeys.includes(k))) {
|
|
989
|
+
return false;
|
|
990
|
+
}
|
|
991
|
+
return "defined" in json && typeof json.defined === "boolean" && "code" in json && typeof json.code === "string" && "message" in json && typeof json.message === "string";
|
|
992
|
+
}
|
|
993
|
+
function createORPCErrorFromJson(json, options = {}) {
|
|
994
|
+
const error = new ORPCError(json.code, {
|
|
995
|
+
...json,
|
|
996
|
+
...options
|
|
997
|
+
});
|
|
998
|
+
error.defined = json.defined;
|
|
999
|
+
return error;
|
|
1000
|
+
}
|
|
1001
|
+
function wrapAsyncIteratorPreservingEventMeta(iterator, { mapResult, mapError, ...rest }) {
|
|
1002
|
+
return wrapAsyncIterator(iterator, {
|
|
1003
|
+
...rest,
|
|
1004
|
+
mapResult: mapResult && (async (result) => {
|
|
1005
|
+
const mapped = await mapResult(result);
|
|
1006
|
+
if (mapped.value !== result.value) {
|
|
1007
|
+
const meta = getEventMeta(result.value);
|
|
1008
|
+
if (meta && isTypescriptObject(mapped.value)) {
|
|
1009
|
+
return { done: mapped.done, value: withEventMeta(mapped.value, meta) };
|
|
1010
|
+
}
|
|
1011
|
+
}
|
|
1012
|
+
return mapped;
|
|
1013
|
+
}),
|
|
1014
|
+
mapError: mapError && (async (error) => {
|
|
1015
|
+
const mapped = await mapError(error);
|
|
1016
|
+
if (mapped !== error) {
|
|
1017
|
+
const meta = getEventMeta(error);
|
|
1018
|
+
if (meta && isTypescriptObject(mapped)) {
|
|
1019
|
+
return withEventMeta(mapped, meta);
|
|
1020
|
+
}
|
|
1021
|
+
}
|
|
1022
|
+
return mapped;
|
|
1023
|
+
})
|
|
1024
|
+
});
|
|
1025
|
+
}
|
|
1026
|
+
function invalidSerializedData(detail) {
|
|
1027
|
+
return new TypeError(`Invalid RPC serialized data: ${detail}`);
|
|
1028
|
+
}
|
|
1029
|
+
function assertSerializedType(ok, type, expected) {
|
|
1030
|
+
if (!ok) {
|
|
1031
|
+
throw invalidSerializedData(`type "${type}" expects ${expected}.`);
|
|
1032
|
+
}
|
|
1033
|
+
}
|
|
1034
|
+
function isWalkable(value2) {
|
|
1035
|
+
return Array.isArray(value2) || isPlainObject(value2);
|
|
1036
|
+
}
|
|
1037
|
+
function walkInto(parent, key, original, restored) {
|
|
1038
|
+
const value2 = parent[key];
|
|
1039
|
+
if (!isWalkable(value2) || restored?.has(value2)) {
|
|
1040
|
+
throw invalidSerializedData(`segment "${key}" cannot be walked into.`);
|
|
1041
|
+
}
|
|
1042
|
+
return value2 === original ? copyOnWrite(parent, key, original) : value2;
|
|
1043
|
+
}
|
|
1044
|
+
var DEFAULT_RPC_JSON_SERIALIZER_HANDLERS = {
|
|
1045
|
+
undefined: {
|
|
1046
|
+
condition(data) {
|
|
1047
|
+
return data === void 0;
|
|
1048
|
+
},
|
|
1049
|
+
serialize() {
|
|
1050
|
+
return null;
|
|
1051
|
+
},
|
|
1052
|
+
deserialize(serialized) {
|
|
1053
|
+
assertSerializedType(serialized === null, "undefined", "null");
|
|
1054
|
+
return void 0;
|
|
1055
|
+
},
|
|
1056
|
+
isTerminal: true
|
|
1057
|
+
},
|
|
1058
|
+
bigint: {
|
|
1059
|
+
condition(data) {
|
|
1060
|
+
return typeof data === "bigint";
|
|
1061
|
+
},
|
|
1062
|
+
serialize(data) {
|
|
1063
|
+
return data.toString();
|
|
1064
|
+
},
|
|
1065
|
+
deserialize(serialized) {
|
|
1066
|
+
assertSerializedType(typeof serialized === "string", "bigint", "a string");
|
|
1067
|
+
const value2 = parseBigIntString(serialized, DEFAULT_MAX_BIGINT_DIGITS);
|
|
1068
|
+
if (value2 === void 0) {
|
|
1069
|
+
throw invalidSerializedData(`type "bigint" expects a decimal integer string of at most ${DEFAULT_MAX_BIGINT_DIGITS} digits.`);
|
|
1070
|
+
}
|
|
1071
|
+
return value2;
|
|
1072
|
+
},
|
|
1073
|
+
isTerminal: true
|
|
1074
|
+
},
|
|
1075
|
+
date: {
|
|
1076
|
+
condition(data) {
|
|
1077
|
+
return data instanceof Date;
|
|
1078
|
+
},
|
|
1079
|
+
serialize(data) {
|
|
1080
|
+
if (Number.isNaN(data.getTime())) {
|
|
1081
|
+
return null;
|
|
1082
|
+
}
|
|
1083
|
+
return data.toISOString();
|
|
1084
|
+
},
|
|
1085
|
+
deserialize(serialized) {
|
|
1086
|
+
assertSerializedType(typeof serialized === "string" || serialized === null, "date", "a string or null");
|
|
1087
|
+
return new Date(serialized ?? Number.NaN);
|
|
1088
|
+
},
|
|
1089
|
+
isTerminal: true
|
|
1090
|
+
},
|
|
1091
|
+
nan: {
|
|
1092
|
+
condition(data) {
|
|
1093
|
+
return typeof data === "number" && Number.isNaN(data);
|
|
1094
|
+
},
|
|
1095
|
+
serialize() {
|
|
1096
|
+
return null;
|
|
1097
|
+
},
|
|
1098
|
+
deserialize(serialized) {
|
|
1099
|
+
assertSerializedType(serialized === null, "nan", "null");
|
|
1100
|
+
return Number.NaN;
|
|
1101
|
+
},
|
|
1102
|
+
isTerminal: true
|
|
1103
|
+
},
|
|
1104
|
+
infinity: {
|
|
1105
|
+
condition(data) {
|
|
1106
|
+
return data === Number.POSITIVE_INFINITY || data === Number.NEGATIVE_INFINITY;
|
|
1107
|
+
},
|
|
1108
|
+
serialize(data) {
|
|
1109
|
+
return data > 0 ? "Infinity" : "-Infinity";
|
|
1110
|
+
},
|
|
1111
|
+
deserialize(serialized) {
|
|
1112
|
+
assertSerializedType(serialized === "Infinity" || serialized === "-Infinity", "infinity", '"Infinity" or "-Infinity"');
|
|
1113
|
+
return serialized === "Infinity" ? Number.POSITIVE_INFINITY : Number.NEGATIVE_INFINITY;
|
|
1114
|
+
},
|
|
1115
|
+
isTerminal: true
|
|
1116
|
+
},
|
|
1117
|
+
url: {
|
|
1118
|
+
condition(data) {
|
|
1119
|
+
return data instanceof URL;
|
|
1120
|
+
},
|
|
1121
|
+
serialize(data) {
|
|
1122
|
+
return data.toString();
|
|
1123
|
+
},
|
|
1124
|
+
deserialize(serialized) {
|
|
1125
|
+
assertSerializedType(typeof serialized === "string", "url", "a string");
|
|
1126
|
+
return new URL(serialized);
|
|
1127
|
+
},
|
|
1128
|
+
isTerminal: true
|
|
1129
|
+
},
|
|
1130
|
+
set: {
|
|
1131
|
+
condition(data) {
|
|
1132
|
+
return data instanceof Set;
|
|
1133
|
+
},
|
|
1134
|
+
serialize(data) {
|
|
1135
|
+
return Array.from(data);
|
|
1136
|
+
},
|
|
1137
|
+
deserialize(serialized) {
|
|
1138
|
+
assertSerializedType(Array.isArray(serialized), "set", "an array");
|
|
1139
|
+
return new Set(serialized);
|
|
1140
|
+
}
|
|
1141
|
+
},
|
|
1142
|
+
map: {
|
|
1143
|
+
condition(data) {
|
|
1144
|
+
return data instanceof Map;
|
|
1145
|
+
},
|
|
1146
|
+
serialize(data) {
|
|
1147
|
+
return Array.from(data.entries());
|
|
1148
|
+
},
|
|
1149
|
+
deserialize(serialized) {
|
|
1150
|
+
assertSerializedType(Array.isArray(serialized), "map", "an array");
|
|
1151
|
+
return new Map(serialized);
|
|
1152
|
+
}
|
|
1153
|
+
}
|
|
1154
|
+
};
|
|
1155
|
+
var RPCJsonSerializer = class {
|
|
1156
|
+
handlers;
|
|
1157
|
+
inlineBuiltInHandlers;
|
|
1158
|
+
handlerEntries;
|
|
1159
|
+
omitUndefinedProperties;
|
|
1160
|
+
constructor(options = {}) {
|
|
1161
|
+
this.omitUndefinedProperties = options.omitUndefinedProperties !== false;
|
|
1162
|
+
this.handlers = Object.assign(new NullProtoObj(), DEFAULT_RPC_JSON_SERIALIZER_HANDLERS);
|
|
1163
|
+
const customHandlers = options.handlers;
|
|
1164
|
+
if (customHandlers === void 0) {
|
|
1165
|
+
this.inlineBuiltInHandlers = true;
|
|
1166
|
+
return;
|
|
1167
|
+
}
|
|
1168
|
+
let inlineBuiltInHandlers = true;
|
|
1169
|
+
let handlerEntries = [];
|
|
1170
|
+
for (const key of Object.keys(customHandlers)) {
|
|
1171
|
+
const handler = customHandlers[key];
|
|
1172
|
+
this.handlers[key] = handler;
|
|
1173
|
+
if (inlineBuiltInHandlers && key in DEFAULT_RPC_JSON_SERIALIZER_HANDLERS) {
|
|
1174
|
+
inlineBuiltInHandlers = false;
|
|
1175
|
+
}
|
|
1176
|
+
if (inlineBuiltInHandlers && handler !== void 0) {
|
|
1177
|
+
handlerEntries.push([key, handler]);
|
|
1178
|
+
}
|
|
1179
|
+
}
|
|
1180
|
+
if (!inlineBuiltInHandlers) {
|
|
1181
|
+
handlerEntries = [];
|
|
1182
|
+
for (const key of Object.keys(this.handlers)) {
|
|
1183
|
+
const handler = this.handlers[key];
|
|
1184
|
+
if (handler !== void 0) {
|
|
1185
|
+
handlerEntries.push([key, handler]);
|
|
1186
|
+
}
|
|
1187
|
+
}
|
|
1188
|
+
}
|
|
1189
|
+
this.inlineBuiltInHandlers = inlineBuiltInHandlers;
|
|
1190
|
+
this.handlerEntries = handlerEntries;
|
|
1191
|
+
}
|
|
1192
|
+
serializeJson(data) {
|
|
1193
|
+
let meta = [];
|
|
1194
|
+
const maps = [];
|
|
1195
|
+
const blobs = [];
|
|
1196
|
+
const json = this.serializeValue(data, [], meta, maps, blobs);
|
|
1197
|
+
meta = meta.length === 0 ? void 0 : meta;
|
|
1198
|
+
if (maps.length === 0) {
|
|
1199
|
+
return { json, meta };
|
|
1200
|
+
}
|
|
1201
|
+
return { json, meta, maps, blobs };
|
|
1202
|
+
}
|
|
1203
|
+
/**
|
|
1204
|
+
* `segments` is a shared mutable stack (push/pop while walking),
|
|
1205
|
+
* so it must be copied before being stored in `meta` or `maps`.
|
|
1206
|
+
*/
|
|
1207
|
+
serializeValue(data, segments, meta, maps, blobs) {
|
|
1208
|
+
if (this.inlineBuiltInHandlers) {
|
|
1209
|
+
switch (typeof data) {
|
|
1210
|
+
case "string":
|
|
1211
|
+
case "boolean":
|
|
1212
|
+
return data;
|
|
1213
|
+
case "number":
|
|
1214
|
+
if (Number.isFinite(data)) {
|
|
1215
|
+
return data;
|
|
1216
|
+
}
|
|
1217
|
+
if (Number.isNaN(data)) {
|
|
1218
|
+
meta.push(["nan", ...segments]);
|
|
1219
|
+
return null;
|
|
1220
|
+
}
|
|
1221
|
+
meta.push(["infinity", ...segments]);
|
|
1222
|
+
return data > 0 ? "Infinity" : "-Infinity";
|
|
1223
|
+
case "undefined":
|
|
1224
|
+
meta.push(["undefined", ...segments]);
|
|
1225
|
+
return null;
|
|
1226
|
+
case "bigint":
|
|
1227
|
+
meta.push(["bigint", ...segments]);
|
|
1228
|
+
return data.toString();
|
|
1229
|
+
case "object": {
|
|
1230
|
+
if (data === null) {
|
|
1231
|
+
return data;
|
|
1232
|
+
}
|
|
1233
|
+
if (data instanceof Date) {
|
|
1234
|
+
meta.push(["date", ...segments]);
|
|
1235
|
+
return Number.isNaN(data.getTime()) ? null : data.toISOString();
|
|
1236
|
+
}
|
|
1237
|
+
if (data instanceof URL) {
|
|
1238
|
+
meta.push(["url", ...segments]);
|
|
1239
|
+
return data.toString();
|
|
1240
|
+
}
|
|
1241
|
+
if (data instanceof Set) {
|
|
1242
|
+
const result = this.serializeValue(Array.from(data), segments, meta, maps, blobs);
|
|
1243
|
+
meta.push(["set", ...segments]);
|
|
1244
|
+
return result;
|
|
1245
|
+
}
|
|
1246
|
+
if (data instanceof Map) {
|
|
1247
|
+
const result = this.serializeValue(Array.from(data.entries()), segments, meta, maps, blobs);
|
|
1248
|
+
meta.push(["map", ...segments]);
|
|
1249
|
+
return result;
|
|
1250
|
+
}
|
|
1251
|
+
}
|
|
1252
|
+
}
|
|
1253
|
+
}
|
|
1254
|
+
const handlerEntries = this.handlerEntries;
|
|
1255
|
+
if (handlerEntries) {
|
|
1256
|
+
for (let i = 0; i < handlerEntries.length; i++) {
|
|
1257
|
+
const entry = handlerEntries[i];
|
|
1258
|
+
const handler = entry[1];
|
|
1259
|
+
if (handler.condition(data)) {
|
|
1260
|
+
const serialized = handler.serialize(data);
|
|
1261
|
+
if (handler.isTerminal) {
|
|
1262
|
+
meta.push([entry[0], ...segments]);
|
|
1263
|
+
if (serialized instanceof Blob) {
|
|
1264
|
+
maps.push(segments.slice());
|
|
1265
|
+
blobs.push(serialized);
|
|
1266
|
+
}
|
|
1267
|
+
return serialized;
|
|
1268
|
+
}
|
|
1269
|
+
const result = this.serializeValue(serialized, segments, meta, maps, blobs);
|
|
1270
|
+
meta.push([entry[0], ...segments]);
|
|
1271
|
+
return result;
|
|
1272
|
+
}
|
|
1273
|
+
}
|
|
1274
|
+
}
|
|
1275
|
+
if (data instanceof Blob) {
|
|
1276
|
+
maps.push(segments.slice());
|
|
1277
|
+
blobs.push(data);
|
|
1278
|
+
return data;
|
|
1279
|
+
}
|
|
1280
|
+
if (Array.isArray(data)) {
|
|
1281
|
+
const json = [];
|
|
1282
|
+
for (let i = 0; i < data.length; i++) {
|
|
1283
|
+
segments.push(i);
|
|
1284
|
+
json.push(this.serializeValue(data[i], segments, meta, maps, blobs));
|
|
1285
|
+
segments.pop();
|
|
1286
|
+
}
|
|
1287
|
+
return json;
|
|
1288
|
+
}
|
|
1289
|
+
if (isPlainObject(data)) {
|
|
1290
|
+
const json = new NullProtoObj();
|
|
1291
|
+
for (const k of Object.keys(data)) {
|
|
1292
|
+
const v = data[k];
|
|
1293
|
+
if (k === "toJSON" && typeof v === "function") {
|
|
1294
|
+
continue;
|
|
1295
|
+
}
|
|
1296
|
+
if (v === void 0 && this.omitUndefinedProperties) {
|
|
1297
|
+
continue;
|
|
1298
|
+
}
|
|
1299
|
+
segments.push(k);
|
|
1300
|
+
json[k] = this.serializeValue(v, segments, meta, maps, blobs);
|
|
1301
|
+
segments.pop();
|
|
1302
|
+
}
|
|
1303
|
+
return json;
|
|
1304
|
+
}
|
|
1305
|
+
return data;
|
|
1306
|
+
}
|
|
1307
|
+
deserializeJson(serialized) {
|
|
1308
|
+
const ref = { json: serialized.json };
|
|
1309
|
+
if (serialized.blobs?.length) {
|
|
1310
|
+
for (let i = 0; i < serialized.maps.length; i++) {
|
|
1311
|
+
const blob = serialized.blobs[i];
|
|
1312
|
+
if (!(blob instanceof Blob)) {
|
|
1313
|
+
throw invalidSerializedData(`blob ${i} is not a Blob.`);
|
|
1314
|
+
}
|
|
1315
|
+
const segments = serialized.maps[i];
|
|
1316
|
+
let original = serialized;
|
|
1317
|
+
let currentRef = ref;
|
|
1318
|
+
let preSegment = "json";
|
|
1319
|
+
for (let j = 0; j < segments.length; j++) {
|
|
1320
|
+
original = original[preSegment];
|
|
1321
|
+
currentRef = walkInto(currentRef, preSegment, original);
|
|
1322
|
+
preSegment = segments[j];
|
|
1323
|
+
if (!Object.hasOwn(currentRef, preSegment)) {
|
|
1324
|
+
throw invalidSerializedData(`segment "${preSegment}" does not exist.`);
|
|
1325
|
+
}
|
|
1326
|
+
}
|
|
1327
|
+
currentRef[preSegment] = blob;
|
|
1328
|
+
}
|
|
1329
|
+
}
|
|
1330
|
+
const meta = serialized.meta;
|
|
1331
|
+
if (meta) {
|
|
1332
|
+
let restored;
|
|
1333
|
+
const chain = meta.length === 1 ? void 0 : [];
|
|
1334
|
+
let chainDepth = 0;
|
|
1335
|
+
for (const item of meta) {
|
|
1336
|
+
const type = item[0];
|
|
1337
|
+
const handler = this.handlers[type];
|
|
1338
|
+
if (handler === void 0) {
|
|
1339
|
+
throw invalidSerializedData(`type "${type}" is not supported.`);
|
|
1340
|
+
}
|
|
1341
|
+
const depth = item.length - 1;
|
|
1342
|
+
const shared = Math.min(depth, chainDepth);
|
|
1343
|
+
let d = 0;
|
|
1344
|
+
let original = serialized;
|
|
1345
|
+
let currentRef = ref;
|
|
1346
|
+
let preSegment = "json";
|
|
1347
|
+
if (chain !== void 0 && shared > 0) {
|
|
1348
|
+
d = 1;
|
|
1349
|
+
while (d < shared && chain[3 * d] === item[d]) {
|
|
1350
|
+
d++;
|
|
1351
|
+
}
|
|
1352
|
+
currentRef = chain[3 * d - 2];
|
|
1353
|
+
original = chain[3 * d - 1];
|
|
1354
|
+
preSegment = item[d];
|
|
1355
|
+
if (!Object.hasOwn(currentRef, preSegment)) {
|
|
1356
|
+
throw invalidSerializedData(`segment "${preSegment}" does not exist.`);
|
|
1357
|
+
}
|
|
1358
|
+
}
|
|
1359
|
+
while (d < depth) {
|
|
1360
|
+
original = original[preSegment];
|
|
1361
|
+
currentRef = walkInto(currentRef, preSegment, original, restored);
|
|
1362
|
+
if (chain !== void 0) {
|
|
1363
|
+
chain[3 * d] = preSegment;
|
|
1364
|
+
chain[3 * d + 1] = currentRef;
|
|
1365
|
+
chain[3 * d + 2] = original;
|
|
1366
|
+
}
|
|
1367
|
+
preSegment = item[++d];
|
|
1368
|
+
if (!Object.hasOwn(currentRef, preSegment)) {
|
|
1369
|
+
throw invalidSerializedData(`segment "${preSegment}" does not exist.`);
|
|
1370
|
+
}
|
|
1371
|
+
}
|
|
1372
|
+
chainDepth = depth;
|
|
1373
|
+
const value2 = handler.deserialize(currentRef[preSegment]);
|
|
1374
|
+
currentRef[preSegment] = value2;
|
|
1375
|
+
if (isWalkable(value2)) {
|
|
1376
|
+
(restored ??= /* @__PURE__ */ new Set()).add(value2);
|
|
1377
|
+
}
|
|
1378
|
+
}
|
|
1379
|
+
}
|
|
1380
|
+
return ref.json;
|
|
1381
|
+
}
|
|
1382
|
+
};
|
|
1383
|
+
var RPCSerializer = class extends RPCJsonSerializer {
|
|
1384
|
+
defaultSerializeOptions;
|
|
1385
|
+
constructor(options = {}) {
|
|
1386
|
+
super(options);
|
|
1387
|
+
this.defaultSerializeOptions = options.serialize;
|
|
1388
|
+
}
|
|
1389
|
+
serialize(data, options = {}) {
|
|
1390
|
+
if (data === void 0 || data instanceof ReadableStream || data instanceof Blob) {
|
|
1391
|
+
return data;
|
|
1392
|
+
}
|
|
1393
|
+
if (isAsyncIteratorObject(data)) {
|
|
1394
|
+
return wrapAsyncIteratorPreservingEventMeta(data, {
|
|
1395
|
+
mapResult: (result) => {
|
|
1396
|
+
if (result.value === void 0) {
|
|
1397
|
+
return result;
|
|
1398
|
+
}
|
|
1399
|
+
return { done: result.done, value: this.serializePayload(result.value, false) };
|
|
1400
|
+
},
|
|
1401
|
+
mapError: (e) => new ErrorEvent(
|
|
1402
|
+
this.serializePayload(toORPCError(e).toJSON(), false),
|
|
1403
|
+
{ cause: e }
|
|
1404
|
+
)
|
|
1405
|
+
});
|
|
1406
|
+
}
|
|
1407
|
+
const useFormDataForBlobs = options.useFormDataForBlobFields ?? this.defaultSerializeOptions?.useFormDataForBlobFields ?? true;
|
|
1408
|
+
return this.serializePayload(data, useFormDataForBlobs);
|
|
1409
|
+
}
|
|
1410
|
+
serializePayload(data, useFormDataForBlobs) {
|
|
1411
|
+
const { json, meta, maps, blobs } = this.serializeJson(data);
|
|
1412
|
+
if (!useFormDataForBlobs || !blobs?.length) {
|
|
1413
|
+
return { json, meta };
|
|
1414
|
+
}
|
|
1415
|
+
const form = new FormData();
|
|
1416
|
+
form.set("data", stringifyJSON({ json, meta, maps }));
|
|
1417
|
+
blobs.forEach((blob, i) => {
|
|
1418
|
+
form.set(i.toString(), blob);
|
|
1419
|
+
});
|
|
1420
|
+
return form;
|
|
1421
|
+
}
|
|
1422
|
+
deserialize(data) {
|
|
1423
|
+
if (data === void 0 || data instanceof ReadableStream || data instanceof Blob) {
|
|
1424
|
+
return data;
|
|
1425
|
+
}
|
|
1426
|
+
if (isAsyncIteratorObject(data)) {
|
|
1427
|
+
return wrapAsyncIteratorPreservingEventMeta(data, {
|
|
1428
|
+
mapResult: (result) => {
|
|
1429
|
+
if (result.value === void 0) {
|
|
1430
|
+
return result;
|
|
1431
|
+
}
|
|
1432
|
+
return { done: result.done, value: this.deserializePayload(result.value) };
|
|
1433
|
+
},
|
|
1434
|
+
mapError: (e) => {
|
|
1435
|
+
if (!(e instanceof ErrorEvent)) {
|
|
1436
|
+
return e;
|
|
1437
|
+
}
|
|
1438
|
+
const deserialized = this.deserializePayload(e.data);
|
|
1439
|
+
if (isORPCErrorJson(deserialized)) {
|
|
1440
|
+
return createORPCErrorFromJson(deserialized, { cause: e });
|
|
1441
|
+
}
|
|
1442
|
+
return new ErrorEvent(deserialized, { cause: e });
|
|
1443
|
+
}
|
|
1444
|
+
});
|
|
1445
|
+
}
|
|
1446
|
+
return this.deserializePayload(data);
|
|
1447
|
+
}
|
|
1448
|
+
deserializePayload(data) {
|
|
1449
|
+
if (!(data instanceof FormData)) {
|
|
1450
|
+
return this.deserializeJson(data);
|
|
1451
|
+
}
|
|
1452
|
+
const serialized = JSON.parse(data.get("data"));
|
|
1453
|
+
const blobs = [];
|
|
1454
|
+
for (const [key, value2] of data) {
|
|
1455
|
+
if (value2 instanceof Blob) {
|
|
1456
|
+
blobs[Number(key)] = value2;
|
|
1457
|
+
}
|
|
1458
|
+
}
|
|
1459
|
+
return this.deserializeJson({ ...serialized, blobs });
|
|
1460
|
+
}
|
|
1461
|
+
};
|
|
1462
|
+
|
|
1463
|
+
// ../../../node_modules/.pnpm/@orpc+client@2.0.0-beta.47/node_modules/@orpc/client/dist/index.mjs
|
|
1464
|
+
var RECURSIVE_CLIENT_UNWRAP_KEYS = /* @__PURE__ */ new Set([
|
|
1465
|
+
/**
|
|
1466
|
+
* Prevents the client from being treated as a thenable when users
|
|
1467
|
+
* accidentally write `await client`.
|
|
1468
|
+
*/
|
|
1469
|
+
"then",
|
|
1470
|
+
/**
|
|
1471
|
+
* Commonly used by libraries to bind functions to a specific `this`
|
|
1472
|
+
* context.
|
|
1473
|
+
*/
|
|
1474
|
+
"bind",
|
|
1475
|
+
/**
|
|
1476
|
+
* Commonly used by libraries to invoke functions with a specific `this`
|
|
1477
|
+
* context.
|
|
1478
|
+
*/
|
|
1479
|
+
"call",
|
|
1480
|
+
/**
|
|
1481
|
+
* Commonly used by libraries to invoke functions with a specific `this`
|
|
1482
|
+
* context and an arguments array.
|
|
1483
|
+
*/
|
|
1484
|
+
"apply",
|
|
1485
|
+
/**
|
|
1486
|
+
* Commonly accessed during primitive conversion, inspection, and logging.
|
|
1487
|
+
*/
|
|
1488
|
+
"valueOf",
|
|
1489
|
+
/**
|
|
1490
|
+
* Commonly accessed during string conversion, inspection, and logging.
|
|
1491
|
+
*/
|
|
1492
|
+
"toString",
|
|
1493
|
+
/**
|
|
1494
|
+
* Commonly accessed by serializers such as `JSON.stringify`.
|
|
1495
|
+
*/
|
|
1496
|
+
"toJSON"
|
|
1497
|
+
]);
|
|
1498
|
+
function resolveFriendlyClientOptions(options) {
|
|
1499
|
+
return {
|
|
1500
|
+
...options,
|
|
1501
|
+
context: options.context ?? {}
|
|
1502
|
+
// Context only optional if all fields are optional
|
|
1503
|
+
};
|
|
1504
|
+
}
|
|
1505
|
+
function resolveClientRest(rest) {
|
|
1506
|
+
return [
|
|
1507
|
+
rest[0],
|
|
1508
|
+
// rest[0] can be undefined if TInput is optional,
|
|
1509
|
+
resolveFriendlyClientOptions(rest[1] ?? {})
|
|
1510
|
+
// rest[1] can be undefined if all fields of FriendlyClientOptions are optional
|
|
1511
|
+
];
|
|
1512
|
+
}
|
|
1513
|
+
function createORPCClient(link, { path = [], ...options } = {}) {
|
|
1514
|
+
const procedureClient = (...rest) => {
|
|
1515
|
+
const [input, callOptions] = resolveClientRest(rest);
|
|
1516
|
+
const interceptors = [
|
|
1517
|
+
...toArray(options.interceptors),
|
|
1518
|
+
...toArray(options.scoped?.interceptors)
|
|
1519
|
+
];
|
|
1520
|
+
return intercept(
|
|
1521
|
+
interceptors,
|
|
1522
|
+
{ ...callOptions, input, path },
|
|
1523
|
+
({ path: path2, input: input2, ...callOptions2 }) => link.call(path2, input2, callOptions2)
|
|
1524
|
+
);
|
|
1525
|
+
};
|
|
1526
|
+
const cache = /* @__PURE__ */ new Map();
|
|
1527
|
+
const recursive = new Proxy(procedureClient, {
|
|
1528
|
+
get(target, key) {
|
|
1529
|
+
if (typeof key !== "string" || RECURSIVE_CLIENT_UNWRAP_KEYS.has(key)) {
|
|
1530
|
+
return Reflect.get(target, key);
|
|
1531
|
+
}
|
|
1532
|
+
let client = cache.get(key);
|
|
1533
|
+
if (client === void 0) {
|
|
1534
|
+
client = createORPCClient(link, {
|
|
1535
|
+
...options,
|
|
1536
|
+
path: [...path, key],
|
|
1537
|
+
scoped: options.scoped?.[key]
|
|
1538
|
+
});
|
|
1539
|
+
cache.set(key, client);
|
|
1540
|
+
}
|
|
1541
|
+
return client;
|
|
1542
|
+
}
|
|
1543
|
+
});
|
|
1544
|
+
return recursive;
|
|
1545
|
+
}
|
|
1546
|
+
|
|
1547
|
+
// ../../../node_modules/.pnpm/@standard-server+fetch@0.13.0/node_modules/@standard-server/fetch/dist/index.mjs
|
|
1548
|
+
function toAsyncIteratorObject(stream) {
|
|
1549
|
+
const eventStream = stream?.pipeThrough(new TextDecoderStream()).pipeThrough(new EventStreamDecoderStream());
|
|
1550
|
+
const reader = eventStream?.getReader();
|
|
1551
|
+
return new AsyncIteratorClass(
|
|
1552
|
+
async () => {
|
|
1553
|
+
while (true) {
|
|
1554
|
+
const result = await reader?.read();
|
|
1555
|
+
if (result === void 0 || result.done) {
|
|
1556
|
+
throw new EventStreamDecoderError("Event Stream ended before complete");
|
|
1557
|
+
}
|
|
1558
|
+
const { value: value2 } = result;
|
|
1559
|
+
switch (value2.event) {
|
|
1560
|
+
case "message": {
|
|
1561
|
+
let message = parseEmptyableJSON(value2.data);
|
|
1562
|
+
if (isTypescriptObject(message)) {
|
|
1563
|
+
message = withEventMeta(message, value2);
|
|
1564
|
+
}
|
|
1565
|
+
return { done: false, value: message };
|
|
1566
|
+
}
|
|
1567
|
+
case "error": {
|
|
1568
|
+
let error = new ErrorEvent(parseEmptyableJSON(value2.data));
|
|
1569
|
+
error = withEventMeta(error, value2);
|
|
1570
|
+
throw error;
|
|
1571
|
+
}
|
|
1572
|
+
case "close": {
|
|
1573
|
+
let close = parseEmptyableJSON(value2.data);
|
|
1574
|
+
if (isTypescriptObject(close)) {
|
|
1575
|
+
close = withEventMeta(close, value2);
|
|
1576
|
+
}
|
|
1577
|
+
return { done: true, value: close };
|
|
1578
|
+
}
|
|
1579
|
+
}
|
|
1580
|
+
}
|
|
1581
|
+
},
|
|
1582
|
+
async () => {
|
|
1583
|
+
await reader?.cancel();
|
|
1584
|
+
}
|
|
1585
|
+
);
|
|
1586
|
+
}
|
|
1587
|
+
function toEventStream(iterator, options = {}) {
|
|
1588
|
+
const keepAliveEnabled = options.keepAlive?.enabled ?? true;
|
|
1589
|
+
const keepAliveInterval = options.keepAlive?.interval ?? 15e3;
|
|
1590
|
+
const keepAliveComment = options.keepAlive?.comment ?? "";
|
|
1591
|
+
const initialCommentEnabled = options.initialComment?.enabled ?? true;
|
|
1592
|
+
const initialComment = options.initialComment?.comment ?? "";
|
|
1593
|
+
let cancelled = false;
|
|
1594
|
+
let timeout;
|
|
1595
|
+
const stream = new ReadableStream({
|
|
1596
|
+
start(controller) {
|
|
1597
|
+
if (initialCommentEnabled) {
|
|
1598
|
+
controller.enqueue(
|
|
1599
|
+
encodeEventStreamMessage({
|
|
1600
|
+
comments: [initialComment]
|
|
1601
|
+
})
|
|
1602
|
+
);
|
|
1603
|
+
}
|
|
1604
|
+
},
|
|
1605
|
+
async pull(controller) {
|
|
1606
|
+
let result;
|
|
1607
|
+
try {
|
|
1608
|
+
if (keepAliveEnabled) {
|
|
1609
|
+
timeout = setInterval(() => {
|
|
1610
|
+
controller.enqueue(
|
|
1611
|
+
encodeEventStreamMessage({
|
|
1612
|
+
comments: [keepAliveComment]
|
|
1613
|
+
})
|
|
1614
|
+
);
|
|
1615
|
+
}, keepAliveInterval);
|
|
1616
|
+
}
|
|
1617
|
+
result = await iterator.next();
|
|
1618
|
+
} catch (err) {
|
|
1619
|
+
clearInterval(timeout);
|
|
1620
|
+
if (cancelled) {
|
|
1621
|
+
return;
|
|
1622
|
+
}
|
|
1623
|
+
if (err instanceof ErrorEvent) {
|
|
1624
|
+
controller.enqueue(
|
|
1625
|
+
encodeEventStreamMessage({
|
|
1626
|
+
...getEventMeta(err),
|
|
1627
|
+
event: "error",
|
|
1628
|
+
data: stringifyJSON(err.data)
|
|
1629
|
+
})
|
|
1630
|
+
);
|
|
1631
|
+
controller.close();
|
|
1632
|
+
} else {
|
|
1633
|
+
controller.error(err);
|
|
1634
|
+
}
|
|
1635
|
+
return;
|
|
1636
|
+
}
|
|
1637
|
+
clearInterval(timeout);
|
|
1638
|
+
if (cancelled) {
|
|
1639
|
+
return;
|
|
1640
|
+
}
|
|
1641
|
+
try {
|
|
1642
|
+
const [data, meta] = unwrapEvent(result.value);
|
|
1643
|
+
controller.enqueue(
|
|
1644
|
+
encodeEventStreamMessage({
|
|
1645
|
+
...meta,
|
|
1646
|
+
event: result.done ? "close" : "message",
|
|
1647
|
+
data: stringifyJSON(data)
|
|
1648
|
+
})
|
|
1649
|
+
);
|
|
1650
|
+
} catch (err) {
|
|
1651
|
+
try {
|
|
1652
|
+
if (!result.done) {
|
|
1653
|
+
await iterator.return?.();
|
|
1654
|
+
}
|
|
1655
|
+
} finally {
|
|
1656
|
+
controller.error(err);
|
|
1657
|
+
}
|
|
1658
|
+
return;
|
|
1659
|
+
}
|
|
1660
|
+
if (result.done) {
|
|
1661
|
+
controller.close();
|
|
1662
|
+
}
|
|
1663
|
+
},
|
|
1664
|
+
async cancel() {
|
|
1665
|
+
cancelled = true;
|
|
1666
|
+
clearInterval(timeout);
|
|
1667
|
+
await iterator.return?.();
|
|
1668
|
+
}
|
|
1669
|
+
}).pipeThrough(new TextEncoderStream());
|
|
1670
|
+
return stream;
|
|
1671
|
+
}
|
|
1672
|
+
async function toStandardBody(re, options) {
|
|
1673
|
+
const hint = options?.hint ?? resolveStandardBodyHint({
|
|
1674
|
+
"standard-server": re.headers.get("standard-server") ?? void 0,
|
|
1675
|
+
"content-type": re.headers.get("content-type") ?? void 0,
|
|
1676
|
+
"content-length": re.headers.get("content-length") ?? void 0,
|
|
1677
|
+
"content-disposition": re.headers.get("content-disposition") ?? void 0
|
|
1678
|
+
});
|
|
1679
|
+
if (hint === "none") {
|
|
1680
|
+
return void 0;
|
|
1681
|
+
}
|
|
1682
|
+
if (re.bodyUsed) {
|
|
1683
|
+
throw new TypeError("Failed to read body: body stream already read");
|
|
1684
|
+
}
|
|
1685
|
+
if (hint === "json") {
|
|
1686
|
+
const text = await re.text();
|
|
1687
|
+
return parseEmptyableJSON(text);
|
|
1688
|
+
}
|
|
1689
|
+
if (hint === "form-data") {
|
|
1690
|
+
return await re.formData();
|
|
1691
|
+
}
|
|
1692
|
+
if (hint === "url-search-params") {
|
|
1693
|
+
const text = await re.text();
|
|
1694
|
+
return new URLSearchParams(text);
|
|
1695
|
+
}
|
|
1696
|
+
if (hint === "event-stream") {
|
|
1697
|
+
return toAsyncIteratorObject(re.body);
|
|
1698
|
+
}
|
|
1699
|
+
if (hint === "file") {
|
|
1700
|
+
const contentDisposition = re.headers.get("content-disposition");
|
|
1701
|
+
const fileName = contentDisposition !== null ? getFilenameFromContentDisposition(contentDisposition) : void 0;
|
|
1702
|
+
const blob = await re.blob();
|
|
1703
|
+
return new File([blob], fileName ?? "blob", {
|
|
1704
|
+
type: blob.type
|
|
1705
|
+
});
|
|
1706
|
+
}
|
|
1707
|
+
return re.body ?? new ReadableStream({
|
|
1708
|
+
start(controller) {
|
|
1709
|
+
controller.close();
|
|
1710
|
+
}
|
|
1711
|
+
});
|
|
1712
|
+
}
|
|
1713
|
+
function toFetchBody(body, headers, options = {}) {
|
|
1714
|
+
headers = { ...headers };
|
|
1715
|
+
if (body instanceof ReadableStream) {
|
|
1716
|
+
headers["standard-server"] ??= "octet-stream";
|
|
1717
|
+
headers["content-type"] ??= "application/octet-stream";
|
|
1718
|
+
return [body, headers];
|
|
1719
|
+
}
|
|
1720
|
+
if (body instanceof Blob) {
|
|
1721
|
+
headers["standard-server"] ??= "file";
|
|
1722
|
+
headers["content-type"] ??= body.type;
|
|
1723
|
+
headers["content-disposition"] ??= generateContentDisposition(
|
|
1724
|
+
body instanceof File ? body.name ?? "" : "blob"
|
|
1725
|
+
);
|
|
1726
|
+
if (Number.isFinite(body.size)) {
|
|
1727
|
+
headers["content-length"] = body.size.toString();
|
|
1728
|
+
return [body, headers];
|
|
1729
|
+
}
|
|
1730
|
+
return [body.stream(), headers];
|
|
1731
|
+
}
|
|
1732
|
+
headers["standard-server"] = void 0;
|
|
1733
|
+
headers["content-length"] = void 0;
|
|
1734
|
+
if (body === void 0) {
|
|
1735
|
+
headers["standard-server"] = getRequiredStandardBodyHint("none", headers);
|
|
1736
|
+
return [void 0, headers];
|
|
1737
|
+
}
|
|
1738
|
+
if (body instanceof FormData) {
|
|
1739
|
+
headers["content-type"] = void 0;
|
|
1740
|
+
return [body, headers];
|
|
1741
|
+
}
|
|
1742
|
+
if (body instanceof URLSearchParams) {
|
|
1743
|
+
headers["content-type"] ??= "application/x-www-form-urlencoded";
|
|
1744
|
+
headers["standard-server"] = getRequiredStandardBodyHint("url-search-params", headers);
|
|
1745
|
+
return [body, headers];
|
|
1746
|
+
}
|
|
1747
|
+
if (isAsyncIteratorObject(body)) {
|
|
1748
|
+
headers["content-type"] ??= "text/event-stream";
|
|
1749
|
+
headers["standard-server"] = getRequiredStandardBodyHint("event-stream", headers);
|
|
1750
|
+
return [toEventStream(body, options.eventStream), headers];
|
|
1751
|
+
}
|
|
1752
|
+
headers["content-type"] ??= "application/json";
|
|
1753
|
+
headers["standard-server"] = getRequiredStandardBodyHint("json", headers);
|
|
1754
|
+
return [stringifyJSON(body), headers];
|
|
1755
|
+
}
|
|
1756
|
+
function toStandardHeaders(headers) {
|
|
1757
|
+
const standardHeaders = /* @__PURE__ */ Object.create(null);
|
|
1758
|
+
headers.forEach((value2, key) => {
|
|
1759
|
+
if (Array.isArray(standardHeaders[key])) {
|
|
1760
|
+
standardHeaders[key].push(value2);
|
|
1761
|
+
} else if (standardHeaders[key] !== void 0) {
|
|
1762
|
+
standardHeaders[key] = [standardHeaders[key], value2];
|
|
1763
|
+
} else {
|
|
1764
|
+
standardHeaders[key] = value2;
|
|
1765
|
+
}
|
|
1766
|
+
});
|
|
1767
|
+
return standardHeaders;
|
|
1768
|
+
}
|
|
1769
|
+
function toFetchHeaders(standardHeaders) {
|
|
1770
|
+
const headers = new Headers();
|
|
1771
|
+
for (const key of Object.keys(standardHeaders)) {
|
|
1772
|
+
if (key.startsWith(":")) {
|
|
1773
|
+
continue;
|
|
1774
|
+
}
|
|
1775
|
+
const value2 = standardHeaders[key];
|
|
1776
|
+
if (Array.isArray(value2)) {
|
|
1777
|
+
for (const v of value2) {
|
|
1778
|
+
headers.append(key, v);
|
|
1779
|
+
}
|
|
1780
|
+
} else if (value2 !== void 0) {
|
|
1781
|
+
headers.append(key, value2);
|
|
1782
|
+
}
|
|
1783
|
+
}
|
|
1784
|
+
return headers;
|
|
1785
|
+
}
|
|
1786
|
+
function toStandardLazyResponse(response) {
|
|
1787
|
+
return {
|
|
1788
|
+
resolveBody: (hint) => toStandardBody(response, { hint }),
|
|
1789
|
+
status: response.status,
|
|
1790
|
+
get headers() {
|
|
1791
|
+
const headers = toStandardHeaders(response.headers);
|
|
1792
|
+
Object.defineProperty(this, "headers", { value: headers, writable: true });
|
|
1793
|
+
return headers;
|
|
1794
|
+
},
|
|
1795
|
+
set headers(value2) {
|
|
1796
|
+
Object.defineProperty(this, "headers", { value: value2, writable: true });
|
|
1797
|
+
}
|
|
1798
|
+
};
|
|
1799
|
+
}
|
|
1800
|
+
|
|
1801
|
+
// ../../../node_modules/.pnpm/@orpc+client@2.0.0-beta.47/node_modules/@orpc/client/dist/shared/client.CKQeJJ2U.mjs
|
|
1802
|
+
var CompositeStandardLinkPlugin = class {
|
|
1803
|
+
name = "~composite";
|
|
1804
|
+
plugins;
|
|
1805
|
+
constructor(plugins = []) {
|
|
1806
|
+
this.plugins = sortPlugins(plugins);
|
|
1807
|
+
}
|
|
1808
|
+
init(options) {
|
|
1809
|
+
for (const plugin of this.plugins) {
|
|
1810
|
+
if (plugin.init) {
|
|
1811
|
+
options = plugin.init(options);
|
|
1812
|
+
}
|
|
1813
|
+
}
|
|
1814
|
+
return options;
|
|
1815
|
+
}
|
|
1816
|
+
};
|
|
1817
|
+
var StandardLink = class {
|
|
1818
|
+
constructor(codec, transport, options = {}) {
|
|
1819
|
+
this.codec = codec;
|
|
1820
|
+
this.transport = transport;
|
|
1821
|
+
options = new CompositeStandardLinkPlugin(options.plugins).init(options);
|
|
1822
|
+
this.interceptors = options.interceptors;
|
|
1823
|
+
this.transportInterceptors = options.transportInterceptors;
|
|
1824
|
+
}
|
|
1825
|
+
interceptors;
|
|
1826
|
+
transportInterceptors;
|
|
1827
|
+
/**
|
|
1828
|
+
* @throws ORPCError, MalformedResponseError, transport-level errors (network failures, timeouts, etc.)
|
|
1829
|
+
*/
|
|
1830
|
+
call(path, input, options) {
|
|
1831
|
+
return runWithSpan(`${ORPC_NAME}.${path.join("/")}`, (span) => {
|
|
1832
|
+
span?.setAttribute("rpc.system", ORPC_NAME);
|
|
1833
|
+
span?.setAttribute("rpc.method", path.join("."));
|
|
1834
|
+
if (getTracer() && isAsyncIteratorObject(input)) {
|
|
1835
|
+
input = override(input, traceAsyncIterator("consume_async_iterator_object_input", input));
|
|
1836
|
+
} else if (getTracer() && input instanceof ReadableStream) {
|
|
1837
|
+
input = override(input, traceReadableStream("consume_octet_stream_input", input));
|
|
1838
|
+
}
|
|
1839
|
+
return intercept(this.interceptors, { ...options, path, input }, async ({ path: path2, input: input2, ...options2 }) => {
|
|
1840
|
+
const tracer = getTracer();
|
|
1841
|
+
const activeSpan = tracer?.getActiveSpan() ?? span;
|
|
1842
|
+
let request = await runWithSpan(
|
|
1843
|
+
{ name: "encode_input", parent: activeSpan },
|
|
1844
|
+
() => this.codec.encodeInput(input2, path2, options2)
|
|
1845
|
+
);
|
|
1846
|
+
if (activeSpan && tracer?.inject) {
|
|
1847
|
+
const headers = { ...request.headers };
|
|
1848
|
+
tracer.inject(activeSpan, headers);
|
|
1849
|
+
request = { ...request, headers };
|
|
1850
|
+
}
|
|
1851
|
+
const response = await intercept(
|
|
1852
|
+
this.transportInterceptors,
|
|
1853
|
+
{ ...options2, path: path2, request },
|
|
1854
|
+
({ path: path3, request: request2, ...options3 }) => {
|
|
1855
|
+
const activeTransportSpan = tracer?.getActiveSpan() ?? activeSpan;
|
|
1856
|
+
return runWithSpan(
|
|
1857
|
+
{ name: "send_request", parent: activeTransportSpan },
|
|
1858
|
+
() => this.transport.send(request2, path3, options3)
|
|
1859
|
+
);
|
|
1860
|
+
}
|
|
1861
|
+
);
|
|
1862
|
+
const decodedResult = await runWithSpan(
|
|
1863
|
+
{ name: "decode_response", parent: activeSpan },
|
|
1864
|
+
() => this.codec.decodeResponse(response, path2, options2)
|
|
1865
|
+
);
|
|
1866
|
+
if (decodedResult.kind === "error") {
|
|
1867
|
+
throw decodedResult.error;
|
|
1868
|
+
}
|
|
1869
|
+
const output = decodedResult.output;
|
|
1870
|
+
if (getTracer() && isAsyncIteratorObject(output)) {
|
|
1871
|
+
return override(output, traceAsyncIterator("consume_async_iterator_object_output", output));
|
|
1872
|
+
} else if (getTracer() && output instanceof ReadableStream) {
|
|
1873
|
+
return override(output, traceReadableStream("consume_octet_stream_output", output));
|
|
1874
|
+
}
|
|
1875
|
+
return output;
|
|
1876
|
+
});
|
|
1877
|
+
});
|
|
1878
|
+
}
|
|
1879
|
+
};
|
|
1880
|
+
var END_SLASH_REGEX = /\/$/;
|
|
1881
|
+
var RPCLinkCodec = class {
|
|
1882
|
+
baseUrl;
|
|
1883
|
+
maxUrlLength;
|
|
1884
|
+
fallbackMethod;
|
|
1885
|
+
expectedMethod;
|
|
1886
|
+
headers;
|
|
1887
|
+
serializer;
|
|
1888
|
+
constructor(options) {
|
|
1889
|
+
this.baseUrl = options.url ?? "/";
|
|
1890
|
+
this.maxUrlLength = options.maxUrlLength ?? 2083;
|
|
1891
|
+
this.fallbackMethod = options.fallbackMethod ?? "POST";
|
|
1892
|
+
this.expectedMethod = options.method ?? this.fallbackMethod;
|
|
1893
|
+
this.headers = options.headers ?? {};
|
|
1894
|
+
this.serializer = options.serializer ?? new RPCSerializer();
|
|
1895
|
+
}
|
|
1896
|
+
async encodeInput(input, path, options) {
|
|
1897
|
+
let headers = toResolvedStandardHeaders(await value(this.headers, options, path, input));
|
|
1898
|
+
if (options.lastEventId !== void 0) {
|
|
1899
|
+
headers = mergeStandardHeaders(headers, { "last-event-id": options.lastEventId });
|
|
1900
|
+
}
|
|
1901
|
+
const expectedMethod = await value(this.expectedMethod, options, path, input);
|
|
1902
|
+
const baseUrl = await value(this.baseUrl, options, path, input);
|
|
1903
|
+
const [pathname, search, hash] = parseStandardUrl(baseUrl);
|
|
1904
|
+
const newPathname = `${pathname.replace(END_SLASH_REGEX, "")}${pathToHttpPath(path)}`;
|
|
1905
|
+
const serialized = this.serializer.serialize(input);
|
|
1906
|
+
if (expectedMethod === "GET" && !(serialized instanceof Blob) && !(serialized instanceof ReadableStream) && !(serialized instanceof FormData) && !isAsyncIteratorObject(serialized)) {
|
|
1907
|
+
const maxUrlLength = await value(this.maxUrlLength, options, path, input);
|
|
1908
|
+
const mergedSearch = new URLSearchParams(search);
|
|
1909
|
+
mergedSearch.append("data", stringifyJSON(serialized) ?? "");
|
|
1910
|
+
const url2 = `${newPathname}?${mergedSearch}${hash ?? ""}`;
|
|
1911
|
+
if (url2.length <= maxUrlLength) {
|
|
1912
|
+
return {
|
|
1913
|
+
body: void 0,
|
|
1914
|
+
method: expectedMethod,
|
|
1915
|
+
headers,
|
|
1916
|
+
url: url2,
|
|
1917
|
+
signal: options.signal
|
|
1918
|
+
};
|
|
1919
|
+
}
|
|
1920
|
+
}
|
|
1921
|
+
const url = `${newPathname}${search ?? ""}${hash ?? ""}`;
|
|
1922
|
+
return {
|
|
1923
|
+
url,
|
|
1924
|
+
method: expectedMethod === "GET" ? this.fallbackMethod : expectedMethod,
|
|
1925
|
+
headers,
|
|
1926
|
+
body: serialized,
|
|
1927
|
+
signal: options.signal
|
|
1928
|
+
};
|
|
1929
|
+
}
|
|
1930
|
+
async decodeResponse(response) {
|
|
1931
|
+
const isOk = response.status < 400;
|
|
1932
|
+
const body = await response.resolveBody();
|
|
1933
|
+
const deserialized = await (async () => {
|
|
1934
|
+
try {
|
|
1935
|
+
return this.serializer.deserialize(body);
|
|
1936
|
+
} catch (cause) {
|
|
1937
|
+
throw new MalformedResponseError({
|
|
1938
|
+
message: "Invalid RPC response format.",
|
|
1939
|
+
response: { status: response.status, headers: response.headers, body },
|
|
1940
|
+
cause
|
|
1941
|
+
});
|
|
1942
|
+
}
|
|
1943
|
+
})();
|
|
1944
|
+
if (!isOk) {
|
|
1945
|
+
if (isORPCErrorJson(deserialized)) {
|
|
1946
|
+
return {
|
|
1947
|
+
kind: "error",
|
|
1948
|
+
error: createORPCErrorFromJson(deserialized, {
|
|
1949
|
+
cause: new ResponseError({ response: { status: response.status, headers: response.headers, body } })
|
|
1950
|
+
})
|
|
1951
|
+
};
|
|
1952
|
+
}
|
|
1953
|
+
throw new MalformedResponseError({ response: { headers: response.headers, status: response.status, body } });
|
|
1954
|
+
}
|
|
1955
|
+
return { kind: "output", output: deserialized };
|
|
1956
|
+
}
|
|
1957
|
+
};
|
|
1958
|
+
function toResolvedStandardHeaders(headers) {
|
|
1959
|
+
if (typeof headers.forEach === "function") {
|
|
1960
|
+
return toStandardHeaders(headers);
|
|
1961
|
+
}
|
|
1962
|
+
return headers;
|
|
1963
|
+
}
|
|
1964
|
+
|
|
1965
|
+
// ../../../node_modules/.pnpm/@orpc+client@2.0.0-beta.47/node_modules/@orpc/client/dist/adapters/fetch/index.mjs
|
|
1966
|
+
var GET_SUPPORTED_DUPLEX_MODE = once(() => {
|
|
1967
|
+
try {
|
|
1968
|
+
let duplex;
|
|
1969
|
+
void new Request(
|
|
1970
|
+
"https://example.com",
|
|
1971
|
+
{
|
|
1972
|
+
method: "POST",
|
|
1973
|
+
body: new ReadableStream(),
|
|
1974
|
+
get duplex() {
|
|
1975
|
+
duplex = "half";
|
|
1976
|
+
return "half";
|
|
1977
|
+
}
|
|
1978
|
+
}
|
|
1979
|
+
);
|
|
1980
|
+
return duplex;
|
|
1981
|
+
} catch {
|
|
1982
|
+
return void 0;
|
|
1983
|
+
}
|
|
1984
|
+
});
|
|
1985
|
+
var FetchLinkTransport = class {
|
|
1986
|
+
origin;
|
|
1987
|
+
fetch;
|
|
1988
|
+
toFetchRequestOptions;
|
|
1989
|
+
constructor(options) {
|
|
1990
|
+
this.origin = options.origin;
|
|
1991
|
+
this.fetch = options.fetch ?? ((url, init) => globalThis.fetch(url, init));
|
|
1992
|
+
this.toFetchRequestOptions = options.toFetchRequest;
|
|
1993
|
+
}
|
|
1994
|
+
async send(standardRequest, path, options) {
|
|
1995
|
+
let origin = await value(this.origin, options, path);
|
|
1996
|
+
if (origin?.endsWith("/")) {
|
|
1997
|
+
origin = origin.slice(0, -1);
|
|
1998
|
+
}
|
|
1999
|
+
const url = `${origin ?? ""}${standardRequest.url}`;
|
|
2000
|
+
const [body, standardHeaders] = toFetchBody(standardRequest.body, standardRequest.headers, this.toFetchRequestOptions);
|
|
2001
|
+
const init = {
|
|
2002
|
+
body,
|
|
2003
|
+
headers: toFetchHeaders(standardHeaders),
|
|
2004
|
+
method: standardRequest.method,
|
|
2005
|
+
signal: options.signal,
|
|
2006
|
+
redirect: "manual"
|
|
2007
|
+
};
|
|
2008
|
+
if (body instanceof ReadableStream) {
|
|
2009
|
+
const duplex = GET_SUPPORTED_DUPLEX_MODE();
|
|
2010
|
+
if (duplex !== void 0) {
|
|
2011
|
+
init.duplex = duplex;
|
|
2012
|
+
}
|
|
2013
|
+
}
|
|
2014
|
+
const fetch = this.fetch;
|
|
2015
|
+
const response = await fetch(url, init, options, path);
|
|
2016
|
+
if (response.type === "opaqueredirect") {
|
|
2017
|
+
throw new TypeError("Unexpected redirect response: redirects are not followed.");
|
|
2018
|
+
}
|
|
2019
|
+
if (response.type === "opaque") {
|
|
2020
|
+
throw new TypeError("Unexpected opaque response: the response is unreadable, likely due to a no-cors request.");
|
|
2021
|
+
}
|
|
2022
|
+
const standardResponse = toStandardLazyResponse(response);
|
|
2023
|
+
return standardResponse;
|
|
2024
|
+
}
|
|
2025
|
+
};
|
|
2026
|
+
var RPCLink = class extends StandardLink {
|
|
2027
|
+
constructor(options) {
|
|
2028
|
+
const codec = new RPCLinkCodec(options);
|
|
2029
|
+
const transport = new FetchLinkTransport(options);
|
|
2030
|
+
super(codec, transport, options);
|
|
2031
|
+
}
|
|
2032
|
+
};
|
|
2033
|
+
export {
|
|
2034
|
+
ORPCError,
|
|
2035
|
+
RPCLink,
|
|
2036
|
+
createORPCClient
|
|
2037
|
+
};
|