@orpc/shared 2.0.0-beta.47 → 2.0.0-beta.49
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 +6 -7
- package/dist/args.d.ts +2 -0
- package/dist/args.js +3 -0
- package/dist/array.d.ts +2 -0
- package/dist/array.js +7 -0
- package/dist/bigint.d.ts +9 -0
- package/dist/bigint.js +19 -0
- package/dist/buffer.d.ts +18 -0
- package/dist/buffer.js +77 -0
- package/dist/compare.d.ts +1 -0
- package/dist/compare.js +45 -0
- package/dist/consts.d.ts +1 -0
- package/dist/consts.js +1 -0
- package/dist/error.d.ts +1 -0
- package/dist/error.js +3 -0
- package/dist/function.d.ts +12 -0
- package/dist/function.js +38 -0
- package/dist/http.d.ts +29 -0
- package/dist/http.js +113 -0
- package/dist/id.d.ts +8 -0
- package/dist/id.js +13 -0
- package/dist/index.d.ts +34 -492
- package/dist/index.js +32 -0
- package/dist/interceptor.d.ts +60 -0
- package/dist/interceptor.js +139 -0
- package/dist/iterator.d.ts +56 -0
- package/dist/iterator.js +157 -0
- package/dist/object.d.ts +60 -0
- package/dist/object.js +245 -0
- package/dist/plugin.d.ts +12 -0
- package/dist/plugin.js +61 -0
- package/dist/promise.d.ts +17 -0
- package/dist/promise.js +32 -0
- package/dist/proxy.d.ts +12 -0
- package/dist/proxy.js +24 -0
- package/dist/queue.d.ts +16 -0
- package/dist/queue.js +79 -0
- package/dist/signal.d.ts +18 -0
- package/dist/signal.js +85 -0
- package/dist/stream.d.ts +48 -0
- package/dist/stream.js +155 -0
- package/dist/tracing.d.ts +73 -0
- package/dist/tracing.js +94 -0
- package/dist/types.d.ts +26 -0
- package/dist/types.js +1 -0
- package/dist/value.d.ts +2 -0
- package/dist/value.js +6 -0
- package/package.json +17 -20
- package/dist/index.d.mts +0 -492
- package/dist/index.mjs +0 -1117
package/dist/index.mjs
DELETED
|
@@ -1,1117 +0,0 @@
|
|
|
1
|
-
import { getOrBind, isTypescriptObject, safeDecodeURIComponent, safeEncodeURIComponent, AbortError, AsyncIteratorClass, isAsyncIteratorObject, throwIfAborted } from '@standard-server/shared';
|
|
2
|
-
export { AbortError, AsyncIteratorClass, SequentialIdGenerator, getOrBind, isAsyncIteratorObject, isTypescriptObject, parseEmptyableJSON, safeDecodeURIComponent, safeEncodeURIComponent, sequential, sleep, stringifyJSON, throwIfAborted, toArray } from '@standard-server/shared';
|
|
3
|
-
|
|
4
|
-
function resolveMaybeOptionalOptions(rest) {
|
|
5
|
-
return rest[0] ?? {};
|
|
6
|
-
}
|
|
7
|
-
|
|
8
|
-
function splitInHalf(arr) {
|
|
9
|
-
const half = Math.ceil(arr.length / 2);
|
|
10
|
-
return [arr.slice(0, half), arr.slice(half)];
|
|
11
|
-
}
|
|
12
|
-
|
|
13
|
-
const DEFAULT_MAX_BIGINT_DIGITS = 4300;
|
|
14
|
-
const BIGINT_PATTERN = /^-?(?:0|[1-9]\d*)$/;
|
|
15
|
-
function parseBigIntString(value, maxDigits) {
|
|
16
|
-
const digits = value.startsWith("-") ? value.length - 1 : value.length;
|
|
17
|
-
if (digits > maxDigits || !BIGINT_PATTERN.test(value)) {
|
|
18
|
-
return void 0;
|
|
19
|
-
}
|
|
20
|
-
return BigInt(value);
|
|
21
|
-
}
|
|
22
|
-
|
|
23
|
-
async function loadBytes(source) {
|
|
24
|
-
if (typeof source.bytes === "function") {
|
|
25
|
-
return source.bytes();
|
|
26
|
-
}
|
|
27
|
-
return new Uint8Array(await source.arrayBuffer());
|
|
28
|
-
}
|
|
29
|
-
function toStringOrBytes(source) {
|
|
30
|
-
if (typeof source === "string") {
|
|
31
|
-
return source;
|
|
32
|
-
}
|
|
33
|
-
if (source instanceof ArrayBuffer) {
|
|
34
|
-
return new Uint8Array(source);
|
|
35
|
-
}
|
|
36
|
-
if (Array.isArray(source)) {
|
|
37
|
-
return concatBytes(source);
|
|
38
|
-
}
|
|
39
|
-
if (source instanceof Uint8Array) {
|
|
40
|
-
return source;
|
|
41
|
-
}
|
|
42
|
-
return new Uint8Array(source.buffer, source.byteOffset, source.byteLength);
|
|
43
|
-
}
|
|
44
|
-
function toBytes(item) {
|
|
45
|
-
if (typeof item === "string") {
|
|
46
|
-
return new TextEncoder().encode(item);
|
|
47
|
-
}
|
|
48
|
-
if (item instanceof ArrayBuffer) {
|
|
49
|
-
return new Uint8Array(item);
|
|
50
|
-
}
|
|
51
|
-
if (item instanceof Uint8Array) {
|
|
52
|
-
return item;
|
|
53
|
-
}
|
|
54
|
-
return new Uint8Array(item.buffer, item.byteOffset, item.byteLength);
|
|
55
|
-
}
|
|
56
|
-
function concatBytes(items) {
|
|
57
|
-
const chunks = items.map(toBytes);
|
|
58
|
-
const totalLength = chunks.reduce((sum, chunk) => sum + chunk.byteLength, 0);
|
|
59
|
-
const result = new Uint8Array(totalLength);
|
|
60
|
-
let offset = 0;
|
|
61
|
-
for (const chunk of chunks) {
|
|
62
|
-
result.set(chunk, offset);
|
|
63
|
-
offset += chunk.byteLength;
|
|
64
|
-
}
|
|
65
|
-
return result;
|
|
66
|
-
}
|
|
67
|
-
function encodeBase64(bytes) {
|
|
68
|
-
const native = bytes;
|
|
69
|
-
if (typeof native.toBase64 === "function") {
|
|
70
|
-
return native.toBase64();
|
|
71
|
-
}
|
|
72
|
-
const NodeBuffer = globalThis.process?.getBuiltinModule?.("node:buffer")?.Buffer;
|
|
73
|
-
if (NodeBuffer !== void 0) {
|
|
74
|
-
return NodeBuffer.from(bytes.buffer, bytes.byteOffset, bytes.byteLength).toString("base64");
|
|
75
|
-
}
|
|
76
|
-
const chunkSize = 8192;
|
|
77
|
-
let binaryString = "";
|
|
78
|
-
for (let i = 0; i < bytes.length; i += chunkSize) {
|
|
79
|
-
binaryString += String.fromCharCode(...bytes.subarray(i, i + chunkSize));
|
|
80
|
-
}
|
|
81
|
-
return btoa(binaryString);
|
|
82
|
-
}
|
|
83
|
-
|
|
84
|
-
function findDeepMatches(check, payload, segments = [], maps = [], values = []) {
|
|
85
|
-
if (check(payload)) {
|
|
86
|
-
maps.push(segments);
|
|
87
|
-
values.push(payload);
|
|
88
|
-
} else if (Array.isArray(payload)) {
|
|
89
|
-
payload.forEach((v, i) => {
|
|
90
|
-
findDeepMatches(check, v, [...segments, i], maps, values);
|
|
91
|
-
});
|
|
92
|
-
} else if (isPlainObject(payload)) {
|
|
93
|
-
for (const key of Object.keys(payload)) {
|
|
94
|
-
findDeepMatches(check, payload[key], [...segments, key], maps, values);
|
|
95
|
-
}
|
|
96
|
-
}
|
|
97
|
-
return { maps, values };
|
|
98
|
-
}
|
|
99
|
-
function getConstructor(value) {
|
|
100
|
-
if (!isTypescriptObject(value)) {
|
|
101
|
-
return null;
|
|
102
|
-
}
|
|
103
|
-
return Object.getPrototypeOf(value)?.constructor;
|
|
104
|
-
}
|
|
105
|
-
function* getConstructors(value) {
|
|
106
|
-
if (!isTypescriptObject(value)) {
|
|
107
|
-
return;
|
|
108
|
-
}
|
|
109
|
-
let proto = Object.getPrototypeOf(value);
|
|
110
|
-
while (proto != null) {
|
|
111
|
-
if (proto.constructor) {
|
|
112
|
-
yield proto.constructor;
|
|
113
|
-
}
|
|
114
|
-
proto = Object.getPrototypeOf(proto);
|
|
115
|
-
}
|
|
116
|
-
}
|
|
117
|
-
function isPlainObject(value) {
|
|
118
|
-
if (!value || typeof value !== "object") {
|
|
119
|
-
return false;
|
|
120
|
-
}
|
|
121
|
-
const proto = Object.getPrototypeOf(value);
|
|
122
|
-
return proto === Object.prototype || !proto || !proto.constructor;
|
|
123
|
-
}
|
|
124
|
-
function getOwn(object, key) {
|
|
125
|
-
return Object.hasOwn(object, key) ? object[key] : void 0;
|
|
126
|
-
}
|
|
127
|
-
function get(object, path) {
|
|
128
|
-
let current = object;
|
|
129
|
-
for (const key of path) {
|
|
130
|
-
if (!isTypescriptObject(current)) {
|
|
131
|
-
return void 0;
|
|
132
|
-
}
|
|
133
|
-
current = getOwn(current, key);
|
|
134
|
-
}
|
|
135
|
-
return current;
|
|
136
|
-
}
|
|
137
|
-
function set(root, path, value) {
|
|
138
|
-
let current = root;
|
|
139
|
-
for (let i = 0; i < path.length - 1; i++) {
|
|
140
|
-
const key = path[i];
|
|
141
|
-
const next = getOwn(current, key);
|
|
142
|
-
if (!isTypescriptObject(next)) {
|
|
143
|
-
const child = {};
|
|
144
|
-
setOwn(current, key, child);
|
|
145
|
-
current = child;
|
|
146
|
-
} else {
|
|
147
|
-
current = next;
|
|
148
|
-
}
|
|
149
|
-
}
|
|
150
|
-
setOwn(current, path.at(-1), value);
|
|
151
|
-
}
|
|
152
|
-
function setOwn(object, key, value) {
|
|
153
|
-
if (key === "__proto__") {
|
|
154
|
-
Object.defineProperty(object, key, {
|
|
155
|
-
value,
|
|
156
|
-
writable: true,
|
|
157
|
-
enumerable: true,
|
|
158
|
-
configurable: true
|
|
159
|
-
});
|
|
160
|
-
} else {
|
|
161
|
-
object[key] = value;
|
|
162
|
-
}
|
|
163
|
-
}
|
|
164
|
-
function mergeTwoLevels(first, second) {
|
|
165
|
-
if (!isPlainObject(first) || !isPlainObject(second)) {
|
|
166
|
-
return second;
|
|
167
|
-
}
|
|
168
|
-
const result = { ...first, ...second };
|
|
169
|
-
for (const key of Object.keys(second)) {
|
|
170
|
-
if (!Object.hasOwn(first, key)) {
|
|
171
|
-
continue;
|
|
172
|
-
}
|
|
173
|
-
const firstValue = first[key];
|
|
174
|
-
const secondValue = second[key];
|
|
175
|
-
if (isPlainObject(firstValue) && isPlainObject(secondValue)) {
|
|
176
|
-
result[key] = { ...firstValue, ...secondValue };
|
|
177
|
-
}
|
|
178
|
-
}
|
|
179
|
-
return result;
|
|
180
|
-
}
|
|
181
|
-
function omit(obj, keys) {
|
|
182
|
-
const result = { ...obj };
|
|
183
|
-
for (const key of keys) {
|
|
184
|
-
delete result[key];
|
|
185
|
-
}
|
|
186
|
-
return result;
|
|
187
|
-
}
|
|
188
|
-
function pick(obj, keys) {
|
|
189
|
-
const result = {};
|
|
190
|
-
for (const key of keys) {
|
|
191
|
-
if (Object.hasOwn(obj, key)) {
|
|
192
|
-
result[key] = obj[key];
|
|
193
|
-
}
|
|
194
|
-
}
|
|
195
|
-
return result;
|
|
196
|
-
}
|
|
197
|
-
function clone(value) {
|
|
198
|
-
return cloneWithVisited(value, /* @__PURE__ */ new WeakMap());
|
|
199
|
-
}
|
|
200
|
-
function cloneWithVisited(value, visited) {
|
|
201
|
-
if (Array.isArray(value)) {
|
|
202
|
-
const existing = visited.get(value);
|
|
203
|
-
if (existing) {
|
|
204
|
-
return existing;
|
|
205
|
-
}
|
|
206
|
-
const result = [];
|
|
207
|
-
visited.set(value, result);
|
|
208
|
-
for (const item of value) {
|
|
209
|
-
result.push(cloneWithVisited(item, visited));
|
|
210
|
-
}
|
|
211
|
-
return result;
|
|
212
|
-
}
|
|
213
|
-
if (isPlainObject(value)) {
|
|
214
|
-
const existing = visited.get(value);
|
|
215
|
-
if (existing) {
|
|
216
|
-
return existing;
|
|
217
|
-
}
|
|
218
|
-
const result = {};
|
|
219
|
-
visited.set(value, result);
|
|
220
|
-
for (const key of Object.keys(value)) {
|
|
221
|
-
setOwn(result, key, cloneWithVisited(value[key], visited));
|
|
222
|
-
}
|
|
223
|
-
for (const sym of Object.getOwnPropertySymbols(value)) {
|
|
224
|
-
setOwn(result, sym, cloneWithVisited(value[sym], visited));
|
|
225
|
-
}
|
|
226
|
-
return result;
|
|
227
|
-
}
|
|
228
|
-
return value;
|
|
229
|
-
}
|
|
230
|
-
function copyOnWrite(parent, key, original) {
|
|
231
|
-
const value = parent[key];
|
|
232
|
-
if (value !== original) {
|
|
233
|
-
return value;
|
|
234
|
-
}
|
|
235
|
-
let copy;
|
|
236
|
-
if (Array.isArray(value)) {
|
|
237
|
-
copy = value.slice();
|
|
238
|
-
} else if (isPlainObject(value)) {
|
|
239
|
-
copy = { ...value };
|
|
240
|
-
} else {
|
|
241
|
-
return value;
|
|
242
|
-
}
|
|
243
|
-
setOwn(parent, key, copy);
|
|
244
|
-
return copy;
|
|
245
|
-
}
|
|
246
|
-
function isPropertyKey(value) {
|
|
247
|
-
const type = typeof value;
|
|
248
|
-
return type === "string" || type === "number" || type === "symbol";
|
|
249
|
-
}
|
|
250
|
-
const NullProtoObj = /* @__PURE__ */ (() => {
|
|
251
|
-
const e = function() {
|
|
252
|
-
};
|
|
253
|
-
e.prototype = /* @__PURE__ */ Object.create(null);
|
|
254
|
-
Object.freeze(e.prototype);
|
|
255
|
-
return e;
|
|
256
|
-
})();
|
|
257
|
-
function bindMethods(obj, options = {}) {
|
|
258
|
-
const unbound = new Set(options.unbound);
|
|
259
|
-
const methods = new NullProtoObj();
|
|
260
|
-
let current = obj;
|
|
261
|
-
while (current && current !== Object.prototype) {
|
|
262
|
-
for (const key of Object.getOwnPropertyNames(current)) {
|
|
263
|
-
if (key === "constructor" || key in methods) {
|
|
264
|
-
continue;
|
|
265
|
-
}
|
|
266
|
-
const val = getOrBind(obj, key, { bind: !unbound.has(key) });
|
|
267
|
-
if (typeof val === "function") {
|
|
268
|
-
methods[key] = val;
|
|
269
|
-
}
|
|
270
|
-
}
|
|
271
|
-
for (const sym of Object.getOwnPropertySymbols(current)) {
|
|
272
|
-
if (sym in methods) {
|
|
273
|
-
continue;
|
|
274
|
-
}
|
|
275
|
-
const val = getOrBind(obj, sym, { bind: !unbound.has(sym) });
|
|
276
|
-
if (typeof val === "function") {
|
|
277
|
-
methods[sym] = val;
|
|
278
|
-
}
|
|
279
|
-
}
|
|
280
|
-
current = Object.getPrototypeOf(current);
|
|
281
|
-
}
|
|
282
|
-
return methods;
|
|
283
|
-
}
|
|
284
|
-
|
|
285
|
-
function isDeepEqual(a, b) {
|
|
286
|
-
return isDeepEqualInternal(a, b, /* @__PURE__ */ new WeakMap());
|
|
287
|
-
}
|
|
288
|
-
function isDeepEqualInternal(a, b, visited) {
|
|
289
|
-
if (Object.is(a, b)) {
|
|
290
|
-
return true;
|
|
291
|
-
}
|
|
292
|
-
if (Array.isArray(a)) {
|
|
293
|
-
if (!Array.isArray(b) || a.length !== b.length) {
|
|
294
|
-
return false;
|
|
295
|
-
}
|
|
296
|
-
} else if (!isPlainObject(a) || !isPlainObject(b)) {
|
|
297
|
-
return false;
|
|
298
|
-
}
|
|
299
|
-
const aRecord = a;
|
|
300
|
-
const bRecord = b;
|
|
301
|
-
const visitedMatches = visited.get(a);
|
|
302
|
-
if (visitedMatches?.has(b)) {
|
|
303
|
-
return true;
|
|
304
|
-
}
|
|
305
|
-
if (visitedMatches) {
|
|
306
|
-
visitedMatches.add(b);
|
|
307
|
-
} else {
|
|
308
|
-
visited.set(a, new WeakSet([b]));
|
|
309
|
-
}
|
|
310
|
-
const aKeys = Object.keys(aRecord).filter((k) => aRecord[k] !== void 0);
|
|
311
|
-
const bKeys = Object.keys(bRecord).filter((k) => bRecord[k] !== void 0);
|
|
312
|
-
if (aKeys.length !== bKeys.length) {
|
|
313
|
-
return false;
|
|
314
|
-
}
|
|
315
|
-
for (const key of aKeys) {
|
|
316
|
-
if (!Object.hasOwn(bRecord, key)) {
|
|
317
|
-
return false;
|
|
318
|
-
}
|
|
319
|
-
if (!isDeepEqualInternal(aRecord[key], bRecord[key], visited)) {
|
|
320
|
-
return false;
|
|
321
|
-
}
|
|
322
|
-
}
|
|
323
|
-
return true;
|
|
324
|
-
}
|
|
325
|
-
|
|
326
|
-
const ORPC_NAME = "orpc";
|
|
327
|
-
|
|
328
|
-
function isAbortError(error) {
|
|
329
|
-
return error instanceof Error && error.name.includes("Abort");
|
|
330
|
-
}
|
|
331
|
-
|
|
332
|
-
const AsyncGeneratorFunction = Object.getPrototypeOf(async function* () {
|
|
333
|
-
}).constructor;
|
|
334
|
-
function isAsyncGeneratorFunction(value) {
|
|
335
|
-
return value instanceof AsyncGeneratorFunction;
|
|
336
|
-
}
|
|
337
|
-
function once(fn) {
|
|
338
|
-
let cached;
|
|
339
|
-
return () => {
|
|
340
|
-
if (cached) {
|
|
341
|
-
return cached.result;
|
|
342
|
-
}
|
|
343
|
-
const result = fn();
|
|
344
|
-
cached = { result };
|
|
345
|
-
return result;
|
|
346
|
-
};
|
|
347
|
-
}
|
|
348
|
-
function defer(callback, delay = 0) {
|
|
349
|
-
if (typeof setTimeout === "function") {
|
|
350
|
-
setTimeout(callback, delay);
|
|
351
|
-
} else {
|
|
352
|
-
Promise.resolve().then(() => Promise.resolve().then(() => Promise.resolve().then(callback)));
|
|
353
|
-
}
|
|
354
|
-
}
|
|
355
|
-
function tryOrUndefined(fn) {
|
|
356
|
-
try {
|
|
357
|
-
return fn();
|
|
358
|
-
} catch {
|
|
359
|
-
return void 0;
|
|
360
|
-
}
|
|
361
|
-
}
|
|
362
|
-
|
|
363
|
-
function pathToHttpPath(path) {
|
|
364
|
-
return `/${path.map(safeEncodeURIComponent).join("/")}`;
|
|
365
|
-
}
|
|
366
|
-
function normalizeHttpPath(path) {
|
|
367
|
-
const paths = path.split("/");
|
|
368
|
-
if (paths.at(0) === "") {
|
|
369
|
-
paths.shift();
|
|
370
|
-
}
|
|
371
|
-
return pathToHttpPath(paths.map(safeDecodeURIComponent));
|
|
372
|
-
}
|
|
373
|
-
function mergeHttpPath(a, b) {
|
|
374
|
-
return `${a.endsWith("/") ? a.slice(0, -1) : a}${b}`;
|
|
375
|
-
}
|
|
376
|
-
function matchesHttpPathPrefix(url, prefix) {
|
|
377
|
-
if (!url.startsWith(prefix)) {
|
|
378
|
-
return false;
|
|
379
|
-
}
|
|
380
|
-
const charAfterPrefix = url[prefix.length];
|
|
381
|
-
return charAfterPrefix === "/" || charAfterPrefix === "?" || charAfterPrefix === "#" || charAfterPrefix === void 0 || prefix[prefix.length - 1] === "/";
|
|
382
|
-
}
|
|
383
|
-
function matchesHttpPath(url, path) {
|
|
384
|
-
const pathWithoutEndSlash = path.endsWith("/") ? path.slice(0, path.length - 1) : path;
|
|
385
|
-
if (!url.startsWith(pathWithoutEndSlash)) {
|
|
386
|
-
return false;
|
|
387
|
-
}
|
|
388
|
-
let charAfterPrefix = url[pathWithoutEndSlash.length];
|
|
389
|
-
if (charAfterPrefix === "/") {
|
|
390
|
-
charAfterPrefix = url[pathWithoutEndSlash.length + 1];
|
|
391
|
-
}
|
|
392
|
-
return charAfterPrefix === void 0 || charAfterPrefix === "?" || charAfterPrefix === "#";
|
|
393
|
-
}
|
|
394
|
-
const ACCEPT_ENCODING_QUALITY_REGEX = /^\s*q=([\d.]+)\s*$/i;
|
|
395
|
-
function parseAcceptEncodingQualities(header) {
|
|
396
|
-
const qualities = /* @__PURE__ */ new Map();
|
|
397
|
-
for (const part of header?.split(",") ?? []) {
|
|
398
|
-
const [rawCoding, ...params] = part.split(";");
|
|
399
|
-
const coding = rawCoding.trim().toLowerCase();
|
|
400
|
-
if (coding === "") {
|
|
401
|
-
continue;
|
|
402
|
-
}
|
|
403
|
-
const quality = params.map((param) => ACCEPT_ENCODING_QUALITY_REGEX.exec(param)?.[1]).find((value) => value !== void 0);
|
|
404
|
-
qualities.set(coding, quality === void 0 ? 1 : Number(quality));
|
|
405
|
-
}
|
|
406
|
-
return qualities;
|
|
407
|
-
}
|
|
408
|
-
function isAcceptableEncoding(qualities, coding) {
|
|
409
|
-
return (qualities.get(coding) ?? qualities.get("*") ?? 0) > 0;
|
|
410
|
-
}
|
|
411
|
-
function varyByAcceptEncoding(vary) {
|
|
412
|
-
if (vary === void 0) {
|
|
413
|
-
return "accept-encoding";
|
|
414
|
-
}
|
|
415
|
-
const fields = vary.split(",").map((field) => field.trim().toLowerCase());
|
|
416
|
-
return fields.includes("accept-encoding") || fields.includes("*") ? vary : `${vary}, accept-encoding`;
|
|
417
|
-
}
|
|
418
|
-
const CACHE_CONTROL_NO_TRANSFORM_REGEX = /(?:^|,)\s*no-transform\s*(?:,|$)/i;
|
|
419
|
-
function isNoTransformCacheControl(cacheControl) {
|
|
420
|
-
if (cacheControl === void 0) {
|
|
421
|
-
return false;
|
|
422
|
-
}
|
|
423
|
-
return CACHE_CONTROL_NO_TRANSFORM_REGEX.test(cacheControl);
|
|
424
|
-
}
|
|
425
|
-
const COMPRESSIBLE_CONTENT_TYPE_REGEX = /^\s*(?:text\/(?!event-stream(?:[;\s]|$))[^;\s]+|application\/(?:javascript|json|xml|xml-dtd|ecmascript|dart|postscript|rtf|tar|toml|vnd\.dart|vnd\.ms-fontobject|vnd\.ms-opentype|wasm|x-httpd-php|x-javascript|x-ns-proxy-autoconfig|x-sh|x-tar|x-virtualbox-hdd|x-virtualbox-ova|x-virtualbox-ovf|x-virtualbox-vbox|x-virtualbox-vdi|x-virtualbox-vhd|x-virtualbox-vmdk|x-www-form-urlencoded)|font\/(?:otf|ttf)|image\/(?:bmp|vnd\.adobe\.photoshop|vnd\.microsoft\.icon|vnd\.ms-dds|x-icon|x-ms-bmp)|message\/rfc822|model\/gltf-binary|x-shader\/x-fragment|x-shader\/x-vertex|[^;\s]+?\+(?:json|text|xml|yaml))(?:[;\s]|$)/i;
|
|
426
|
-
const MAX_COMPRESSIBLE_CONTENT_TYPE_LENGTH = 1024;
|
|
427
|
-
function isCompressibleContentType(contentType) {
|
|
428
|
-
if (contentType === null || contentType === void 0) {
|
|
429
|
-
return false;
|
|
430
|
-
}
|
|
431
|
-
if (contentType.length > MAX_COMPRESSIBLE_CONTENT_TYPE_LENGTH) {
|
|
432
|
-
return false;
|
|
433
|
-
}
|
|
434
|
-
return COMPRESSIBLE_CONTENT_TYPE_REGEX.test(contentType);
|
|
435
|
-
}
|
|
436
|
-
|
|
437
|
-
function compareSequentialIds(a, b) {
|
|
438
|
-
if (a.length !== b.length) {
|
|
439
|
-
return a.length - b.length;
|
|
440
|
-
}
|
|
441
|
-
return a < b ? -1 : a > b ? 1 : 0;
|
|
442
|
-
}
|
|
443
|
-
|
|
444
|
-
class AsyncIdQueue {
|
|
445
|
-
openIds = /* @__PURE__ */ new Set();
|
|
446
|
-
queues = /* @__PURE__ */ new Map();
|
|
447
|
-
waiters = /* @__PURE__ */ new Map();
|
|
448
|
-
get size() {
|
|
449
|
-
return this.openIds.size;
|
|
450
|
-
}
|
|
451
|
-
open(id) {
|
|
452
|
-
this.openIds.add(id);
|
|
453
|
-
}
|
|
454
|
-
isOpen(id) {
|
|
455
|
-
return this.openIds.has(id);
|
|
456
|
-
}
|
|
457
|
-
push(id, item) {
|
|
458
|
-
this.assertOpen(id);
|
|
459
|
-
const pending = this.waiters.get(id);
|
|
460
|
-
if (pending?.length) {
|
|
461
|
-
pending.shift()[0](item);
|
|
462
|
-
if (pending.length === 0) {
|
|
463
|
-
this.waiters.delete(id);
|
|
464
|
-
}
|
|
465
|
-
} else {
|
|
466
|
-
const items = this.queues.get(id);
|
|
467
|
-
if (items) {
|
|
468
|
-
items.push(item);
|
|
469
|
-
} else {
|
|
470
|
-
this.queues.set(id, [item]);
|
|
471
|
-
}
|
|
472
|
-
}
|
|
473
|
-
}
|
|
474
|
-
async pull(id) {
|
|
475
|
-
this.assertOpen(id);
|
|
476
|
-
const items = this.queues.get(id);
|
|
477
|
-
if (items?.length) {
|
|
478
|
-
const item = items.shift();
|
|
479
|
-
if (items.length === 0) {
|
|
480
|
-
this.queues.delete(id);
|
|
481
|
-
}
|
|
482
|
-
return item;
|
|
483
|
-
}
|
|
484
|
-
return new Promise((resolve, reject) => {
|
|
485
|
-
const waitingPulls = this.waiters.get(id);
|
|
486
|
-
const pending = [resolve, reject];
|
|
487
|
-
if (waitingPulls) {
|
|
488
|
-
waitingPulls.push(pending);
|
|
489
|
-
} else {
|
|
490
|
-
this.waiters.set(id, [pending]);
|
|
491
|
-
}
|
|
492
|
-
});
|
|
493
|
-
}
|
|
494
|
-
close({ id, reason } = {}) {
|
|
495
|
-
if (id === void 0) {
|
|
496
|
-
this.waiters.forEach((pendingPulls, id2) => {
|
|
497
|
-
const error2 = reason ?? new AbortError(`[AsyncIdQueue] Queue[${id2}] was closed or aborted while waiting for pulling.`);
|
|
498
|
-
pendingPulls.forEach(([, reject]) => reject(error2));
|
|
499
|
-
});
|
|
500
|
-
this.waiters.clear();
|
|
501
|
-
this.openIds.clear();
|
|
502
|
-
this.queues.clear();
|
|
503
|
-
return;
|
|
504
|
-
}
|
|
505
|
-
const error = reason ?? new AbortError(`[AsyncIdQueue] Queue[${id}] was closed or aborted while waiting for pulling.`);
|
|
506
|
-
this.waiters.get(id)?.forEach(([, reject]) => reject(error));
|
|
507
|
-
this.waiters.delete(id);
|
|
508
|
-
this.openIds.delete(id);
|
|
509
|
-
this.queues.delete(id);
|
|
510
|
-
}
|
|
511
|
-
assertOpen(id) {
|
|
512
|
-
if (!this.isOpen(id)) {
|
|
513
|
-
throw new Error(`[AsyncIdQueue] Cannot access queue[${id}] because it is not open or aborted.`);
|
|
514
|
-
}
|
|
515
|
-
}
|
|
516
|
-
}
|
|
517
|
-
|
|
518
|
-
const TRACER_SYMBOL = Symbol.for("ORPC_TRACER");
|
|
519
|
-
function setTracer(tracer) {
|
|
520
|
-
globalThis[TRACER_SYMBOL] = tracer;
|
|
521
|
-
}
|
|
522
|
-
function getTracer() {
|
|
523
|
-
return globalThis[TRACER_SYMBOL];
|
|
524
|
-
}
|
|
525
|
-
function startSpan(options) {
|
|
526
|
-
const tracer = getTracer();
|
|
527
|
-
if (!tracer) {
|
|
528
|
-
return void 0;
|
|
529
|
-
}
|
|
530
|
-
if (typeof options === "string") {
|
|
531
|
-
return tracer.startSpan(options);
|
|
532
|
-
}
|
|
533
|
-
return tracer.startSpan(options.name, options.parent);
|
|
534
|
-
}
|
|
535
|
-
function recordSpanError(span, error) {
|
|
536
|
-
if (!span) {
|
|
537
|
-
return;
|
|
538
|
-
}
|
|
539
|
-
span.recordException(isAbortError(error) ? "info" : "error", toTracingException(error));
|
|
540
|
-
}
|
|
541
|
-
function setSpanAttributeIfDefined(span, key, value) {
|
|
542
|
-
if (!span || value === void 0) {
|
|
543
|
-
return;
|
|
544
|
-
}
|
|
545
|
-
span.setAttribute(key, value);
|
|
546
|
-
}
|
|
547
|
-
function toTracingException(error) {
|
|
548
|
-
if (error instanceof Error) {
|
|
549
|
-
const exception = {
|
|
550
|
-
message: error.message,
|
|
551
|
-
name: error.name,
|
|
552
|
-
stack: error.stack
|
|
553
|
-
};
|
|
554
|
-
if ("code" in error && (typeof error.code === "string" || typeof error.code === "number")) {
|
|
555
|
-
exception.code = error.code;
|
|
556
|
-
}
|
|
557
|
-
return exception;
|
|
558
|
-
}
|
|
559
|
-
return { message: String(error) };
|
|
560
|
-
}
|
|
561
|
-
function toSpanAttributeValue(data) {
|
|
562
|
-
if (data === void 0) {
|
|
563
|
-
return "undefined";
|
|
564
|
-
}
|
|
565
|
-
try {
|
|
566
|
-
return JSON.stringify(data, (_, value) => {
|
|
567
|
-
if (typeof value === "bigint") {
|
|
568
|
-
return value.toString();
|
|
569
|
-
}
|
|
570
|
-
if (value instanceof Map || value instanceof Set) {
|
|
571
|
-
return Array.from(value);
|
|
572
|
-
}
|
|
573
|
-
return value;
|
|
574
|
-
});
|
|
575
|
-
} catch {
|
|
576
|
-
return String(data);
|
|
577
|
-
}
|
|
578
|
-
}
|
|
579
|
-
async function runWithSpan(options, fn) {
|
|
580
|
-
const tracer = getTracer();
|
|
581
|
-
if (!tracer) {
|
|
582
|
-
return fn();
|
|
583
|
-
}
|
|
584
|
-
const name = typeof options === "string" ? options : options.name;
|
|
585
|
-
const parent = typeof options === "string" ? void 0 : options.parent;
|
|
586
|
-
return tracer.startActiveSpan(name, parent, async (span) => {
|
|
587
|
-
try {
|
|
588
|
-
return await fn(span);
|
|
589
|
-
} catch (e) {
|
|
590
|
-
recordSpanError(span, e);
|
|
591
|
-
throw e;
|
|
592
|
-
} finally {
|
|
593
|
-
span.end();
|
|
594
|
-
}
|
|
595
|
-
});
|
|
596
|
-
}
|
|
597
|
-
function runInSpanContext(span, fn) {
|
|
598
|
-
const tracer = getTracer();
|
|
599
|
-
if (!span || !tracer) {
|
|
600
|
-
return fn();
|
|
601
|
-
}
|
|
602
|
-
return tracer.withActiveSpan(span, fn);
|
|
603
|
-
}
|
|
604
|
-
|
|
605
|
-
function wrapAsyncIterator(iterator, { runWith, mapResult, mapError, onError, onFinish }) {
|
|
606
|
-
runWith ??= (run) => run();
|
|
607
|
-
let isDone;
|
|
608
|
-
return new AsyncIteratorClass(async () => {
|
|
609
|
-
try {
|
|
610
|
-
let result;
|
|
611
|
-
try {
|
|
612
|
-
result = await runWith(() => iterator.next());
|
|
613
|
-
isDone = result.done;
|
|
614
|
-
} catch (error) {
|
|
615
|
-
isDone = true;
|
|
616
|
-
throw error;
|
|
617
|
-
}
|
|
618
|
-
return mapResult ? await mapResult(result) : result;
|
|
619
|
-
} catch (error) {
|
|
620
|
-
await onError?.(error);
|
|
621
|
-
throw mapError ? await mapError(error) : error;
|
|
622
|
-
}
|
|
623
|
-
}, async (_state) => {
|
|
624
|
-
try {
|
|
625
|
-
if (!isDone) {
|
|
626
|
-
try {
|
|
627
|
-
await runWith(async () => iterator.return?.());
|
|
628
|
-
} catch (error) {
|
|
629
|
-
await onError?.(error);
|
|
630
|
-
throw error;
|
|
631
|
-
}
|
|
632
|
-
}
|
|
633
|
-
} finally {
|
|
634
|
-
await onFinish?.();
|
|
635
|
-
}
|
|
636
|
-
});
|
|
637
|
-
}
|
|
638
|
-
function traceAsyncIterator(options, iterator) {
|
|
639
|
-
const getSpan = once(() => startSpan(options));
|
|
640
|
-
return wrapAsyncIterator(iterator, {
|
|
641
|
-
runWith: (run) => runInSpanContext(getSpan(), run),
|
|
642
|
-
mapResult(result) {
|
|
643
|
-
getSpan()?.addEvent(result.done ? "completed" : "yielded");
|
|
644
|
-
return result;
|
|
645
|
-
},
|
|
646
|
-
onError(error) {
|
|
647
|
-
recordSpanError(getSpan(), error);
|
|
648
|
-
},
|
|
649
|
-
onFinish() {
|
|
650
|
-
getSpan()?.end();
|
|
651
|
-
}
|
|
652
|
-
});
|
|
653
|
-
}
|
|
654
|
-
function replicateAsyncIterator(source, count) {
|
|
655
|
-
const queue = new AsyncIdQueue();
|
|
656
|
-
const ids = Array.from({ length: count }, (_, i) => i.toString());
|
|
657
|
-
let isSourceFinished = false;
|
|
658
|
-
const start = once(async () => {
|
|
659
|
-
try {
|
|
660
|
-
while (true) {
|
|
661
|
-
const item = await source.next();
|
|
662
|
-
ids.forEach((id) => {
|
|
663
|
-
if (queue.isOpen(id)) {
|
|
664
|
-
queue.push(id, { next: item });
|
|
665
|
-
}
|
|
666
|
-
});
|
|
667
|
-
if (item.done) {
|
|
668
|
-
break;
|
|
669
|
-
}
|
|
670
|
-
}
|
|
671
|
-
} catch (error) {
|
|
672
|
-
ids.forEach((id) => {
|
|
673
|
-
if (queue.isOpen(id)) {
|
|
674
|
-
queue.push(id, { error });
|
|
675
|
-
}
|
|
676
|
-
});
|
|
677
|
-
} finally {
|
|
678
|
-
isSourceFinished = true;
|
|
679
|
-
}
|
|
680
|
-
});
|
|
681
|
-
const replicated = ids.map((id) => {
|
|
682
|
-
queue.open(id);
|
|
683
|
-
return new AsyncIteratorClass(
|
|
684
|
-
async () => {
|
|
685
|
-
start();
|
|
686
|
-
const item = await queue.pull(id);
|
|
687
|
-
if (item.next) {
|
|
688
|
-
return item.next;
|
|
689
|
-
}
|
|
690
|
-
throw item.error;
|
|
691
|
-
},
|
|
692
|
-
async ({ kind, error }) => {
|
|
693
|
-
queue.close({ id, reason: error });
|
|
694
|
-
if (kind === "cancelled" && !queue.size && !isSourceFinished) {
|
|
695
|
-
isSourceFinished = true;
|
|
696
|
-
await source?.return?.();
|
|
697
|
-
}
|
|
698
|
-
}
|
|
699
|
-
);
|
|
700
|
-
});
|
|
701
|
-
return replicated;
|
|
702
|
-
}
|
|
703
|
-
function consumeAsyncIterator(iterator, options) {
|
|
704
|
-
void (async () => {
|
|
705
|
-
let onFinishState;
|
|
706
|
-
try {
|
|
707
|
-
const resolvedIterator = await iterator;
|
|
708
|
-
while (true) {
|
|
709
|
-
const { done, value } = await resolvedIterator.next();
|
|
710
|
-
if (done) {
|
|
711
|
-
const realValue = value;
|
|
712
|
-
onFinishState = [null, realValue, true];
|
|
713
|
-
options.onSuccess?.(realValue);
|
|
714
|
-
break;
|
|
715
|
-
}
|
|
716
|
-
try {
|
|
717
|
-
options.onEvent(value);
|
|
718
|
-
} catch (error) {
|
|
719
|
-
await resolvedIterator.return?.();
|
|
720
|
-
throw error;
|
|
721
|
-
}
|
|
722
|
-
}
|
|
723
|
-
} catch (error) {
|
|
724
|
-
onFinishState = [error, void 0, false];
|
|
725
|
-
options.onError?.(error);
|
|
726
|
-
} finally {
|
|
727
|
-
options.onFinish?.(onFinishState);
|
|
728
|
-
}
|
|
729
|
-
})();
|
|
730
|
-
return async () => {
|
|
731
|
-
await (await iterator)?.return?.();
|
|
732
|
-
};
|
|
733
|
-
}
|
|
734
|
-
|
|
735
|
-
function value(value2, ...args) {
|
|
736
|
-
if (typeof value2 === "function") {
|
|
737
|
-
return value2(...args);
|
|
738
|
-
}
|
|
739
|
-
return value2;
|
|
740
|
-
}
|
|
741
|
-
|
|
742
|
-
function override(target, partial) {
|
|
743
|
-
const proxy = new Proxy(typeof target === "function" ? partial : target, {
|
|
744
|
-
get(_, prop) {
|
|
745
|
-
const targetValue = prop in partial ? partial : value(target);
|
|
746
|
-
return getOrBind(targetValue, prop);
|
|
747
|
-
},
|
|
748
|
-
has(_, prop) {
|
|
749
|
-
return Reflect.has(partial, prop) || Reflect.has(value(target), prop);
|
|
750
|
-
}
|
|
751
|
-
});
|
|
752
|
-
return proxy;
|
|
753
|
-
}
|
|
754
|
-
|
|
755
|
-
function promiseWithResolvers() {
|
|
756
|
-
const result = {};
|
|
757
|
-
result.promise = new Promise((resolve, reject) => {
|
|
758
|
-
result.resolve = resolve;
|
|
759
|
-
result.reject = reject;
|
|
760
|
-
});
|
|
761
|
-
return result;
|
|
762
|
-
}
|
|
763
|
-
function captureAsyncContext() {
|
|
764
|
-
const { promise, resolve } = promiseWithResolvers();
|
|
765
|
-
const result = promise.then((callback) => callback());
|
|
766
|
-
let called = false;
|
|
767
|
-
return (callback) => {
|
|
768
|
-
if (called) {
|
|
769
|
-
return Promise.reject(new Error("A captured async context can be run only once."));
|
|
770
|
-
}
|
|
771
|
-
called = true;
|
|
772
|
-
resolve(callback);
|
|
773
|
-
return result;
|
|
774
|
-
};
|
|
775
|
-
}
|
|
776
|
-
|
|
777
|
-
function replicateReadableStream(stream, count) {
|
|
778
|
-
if (count <= 0) {
|
|
779
|
-
return [];
|
|
780
|
-
}
|
|
781
|
-
const replicated = [];
|
|
782
|
-
let pending = stream;
|
|
783
|
-
for (let index = 0; index < count - 1; index++) {
|
|
784
|
-
const [replica, remainder] = pending.tee();
|
|
785
|
-
replicated.push(replica);
|
|
786
|
-
pending = remainder;
|
|
787
|
-
}
|
|
788
|
-
replicated.push(pending);
|
|
789
|
-
return replicated;
|
|
790
|
-
}
|
|
791
|
-
function wrapReadableStream(stream, { runWith, mapResult, mapError, onError, onFinish }) {
|
|
792
|
-
runWith ??= (run) => run();
|
|
793
|
-
const reader = once(() => stream.getReader());
|
|
794
|
-
const finish = once(async () => onFinish?.());
|
|
795
|
-
return new ReadableStream({
|
|
796
|
-
async pull(controller) {
|
|
797
|
-
let result;
|
|
798
|
-
try {
|
|
799
|
-
const readResult = await runWith(() => reader().read());
|
|
800
|
-
result = mapResult ? await mapResult(readResult) : readResult;
|
|
801
|
-
} catch (error) {
|
|
802
|
-
try {
|
|
803
|
-
await onError?.(error);
|
|
804
|
-
controller.error(mapError ? await mapError(error) : error);
|
|
805
|
-
} finally {
|
|
806
|
-
await finish();
|
|
807
|
-
}
|
|
808
|
-
return;
|
|
809
|
-
}
|
|
810
|
-
if (result.done) {
|
|
811
|
-
controller.close();
|
|
812
|
-
await finish();
|
|
813
|
-
} else {
|
|
814
|
-
controller.enqueue(result.value);
|
|
815
|
-
}
|
|
816
|
-
},
|
|
817
|
-
async cancel(reason) {
|
|
818
|
-
try {
|
|
819
|
-
try {
|
|
820
|
-
await runWith(() => reader().cancel(reason));
|
|
821
|
-
} catch (error) {
|
|
822
|
-
await onError?.(error);
|
|
823
|
-
throw error;
|
|
824
|
-
}
|
|
825
|
-
} finally {
|
|
826
|
-
await finish();
|
|
827
|
-
}
|
|
828
|
-
}
|
|
829
|
-
}, { highWaterMark: 0 });
|
|
830
|
-
}
|
|
831
|
-
function traceReadableStream(options, stream) {
|
|
832
|
-
const getSpan = once(() => startSpan(options));
|
|
833
|
-
return wrapReadableStream(stream, {
|
|
834
|
-
runWith: (run) => runInSpanContext(getSpan(), run),
|
|
835
|
-
mapResult(result) {
|
|
836
|
-
getSpan()?.addEvent(result.done ? "closed" : "enqueued");
|
|
837
|
-
return result;
|
|
838
|
-
},
|
|
839
|
-
onError(error) {
|
|
840
|
-
recordSpanError(getSpan(), error);
|
|
841
|
-
},
|
|
842
|
-
onFinish() {
|
|
843
|
-
getSpan()?.end();
|
|
844
|
-
}
|
|
845
|
-
});
|
|
846
|
-
}
|
|
847
|
-
function streamToAsyncIteratorObject(stream, { signal } = {}) {
|
|
848
|
-
const reader = stream.getReader();
|
|
849
|
-
let cancelledBySignal = false;
|
|
850
|
-
return new AsyncIteratorClass(
|
|
851
|
-
async () => {
|
|
852
|
-
if (signal?.aborted) {
|
|
853
|
-
cancelledBySignal = true;
|
|
854
|
-
throw signal.reason;
|
|
855
|
-
}
|
|
856
|
-
if (!signal) {
|
|
857
|
-
return reader.read();
|
|
858
|
-
}
|
|
859
|
-
const { promise, reject } = promiseWithResolvers();
|
|
860
|
-
const onAbort = () => reject(signal.reason);
|
|
861
|
-
signal.addEventListener("abort", onAbort, { once: true });
|
|
862
|
-
try {
|
|
863
|
-
return await Promise.race([
|
|
864
|
-
reader.read(),
|
|
865
|
-
promise.catch(async (reason) => {
|
|
866
|
-
cancelledBySignal = true;
|
|
867
|
-
throw reason;
|
|
868
|
-
})
|
|
869
|
-
]);
|
|
870
|
-
} finally {
|
|
871
|
-
signal.removeEventListener("abort", onAbort);
|
|
872
|
-
}
|
|
873
|
-
},
|
|
874
|
-
async ({ kind, error }) => {
|
|
875
|
-
if (kind === "cancelled" || kind === "error" && cancelledBySignal) {
|
|
876
|
-
await reader.cancel(error);
|
|
877
|
-
}
|
|
878
|
-
}
|
|
879
|
-
);
|
|
880
|
-
}
|
|
881
|
-
function asyncIteratorToStream(iterator) {
|
|
882
|
-
return new ReadableStream({
|
|
883
|
-
async pull(controller) {
|
|
884
|
-
const { done, value } = await iterator.next();
|
|
885
|
-
if (done) {
|
|
886
|
-
controller.close();
|
|
887
|
-
} else {
|
|
888
|
-
controller.enqueue(value);
|
|
889
|
-
}
|
|
890
|
-
},
|
|
891
|
-
async cancel() {
|
|
892
|
-
await iterator.return?.();
|
|
893
|
-
}
|
|
894
|
-
});
|
|
895
|
-
}
|
|
896
|
-
function asyncIteratorToUnproxiedDataStream(iterator) {
|
|
897
|
-
return new ReadableStream({
|
|
898
|
-
async pull(controller) {
|
|
899
|
-
const { done, value } = await iterator.next();
|
|
900
|
-
if (done) {
|
|
901
|
-
controller.close();
|
|
902
|
-
} else {
|
|
903
|
-
const unproxied = isPlainObject(value) ? { ...value } : Array.isArray(value) ? value.map((i) => i) : value;
|
|
904
|
-
controller.enqueue(unproxied);
|
|
905
|
-
}
|
|
906
|
-
},
|
|
907
|
-
async cancel() {
|
|
908
|
-
await iterator.return?.();
|
|
909
|
-
}
|
|
910
|
-
});
|
|
911
|
-
}
|
|
912
|
-
|
|
913
|
-
function onStart(callback) {
|
|
914
|
-
return async (options, ...rest) => {
|
|
915
|
-
await callback(options, ...rest);
|
|
916
|
-
return await options.next();
|
|
917
|
-
};
|
|
918
|
-
}
|
|
919
|
-
function onSuccess(callback) {
|
|
920
|
-
return async (options, ...rest) => {
|
|
921
|
-
const result = await options.next();
|
|
922
|
-
await callback(result, options, ...rest);
|
|
923
|
-
return result;
|
|
924
|
-
};
|
|
925
|
-
}
|
|
926
|
-
function onError(callback) {
|
|
927
|
-
return async (options, ...rest) => {
|
|
928
|
-
try {
|
|
929
|
-
return await options.next();
|
|
930
|
-
} catch (error) {
|
|
931
|
-
await callback(error, options, ...rest);
|
|
932
|
-
throw error;
|
|
933
|
-
}
|
|
934
|
-
};
|
|
935
|
-
}
|
|
936
|
-
function onFinish(callback) {
|
|
937
|
-
return async (options, ...rest) => {
|
|
938
|
-
let state;
|
|
939
|
-
try {
|
|
940
|
-
const result = await options.next();
|
|
941
|
-
state = [null, result, true];
|
|
942
|
-
return result;
|
|
943
|
-
} catch (error) {
|
|
944
|
-
state = [error, void 0, false];
|
|
945
|
-
throw error;
|
|
946
|
-
} finally {
|
|
947
|
-
await callback(state, options, ...rest);
|
|
948
|
-
}
|
|
949
|
-
};
|
|
950
|
-
}
|
|
951
|
-
function onAsyncIteratorObjectError(callback) {
|
|
952
|
-
return async (options, ...rest) => {
|
|
953
|
-
const output = await options.next();
|
|
954
|
-
if (!isAsyncIteratorObject(output)) {
|
|
955
|
-
return output;
|
|
956
|
-
}
|
|
957
|
-
return override(output, wrapAsyncIterator(output, {
|
|
958
|
-
onError: (error) => callback(error, options, ...rest)
|
|
959
|
-
}));
|
|
960
|
-
};
|
|
961
|
-
}
|
|
962
|
-
function onReadableStreamError(callback) {
|
|
963
|
-
return async (options, ...rest) => {
|
|
964
|
-
const output = await options.next();
|
|
965
|
-
if (!(output instanceof ReadableStream)) {
|
|
966
|
-
return output;
|
|
967
|
-
}
|
|
968
|
-
return override(output, wrapReadableStream(output, {
|
|
969
|
-
onError: (error) => callback(error, options, ...rest)
|
|
970
|
-
}));
|
|
971
|
-
};
|
|
972
|
-
}
|
|
973
|
-
function intercept(interceptors, options, main) {
|
|
974
|
-
if (!interceptors?.length) {
|
|
975
|
-
return main(options);
|
|
976
|
-
}
|
|
977
|
-
const next = (options2, index) => {
|
|
978
|
-
const interceptor = interceptors[index];
|
|
979
|
-
if (!interceptor) {
|
|
980
|
-
return main(options2);
|
|
981
|
-
}
|
|
982
|
-
return interceptor({
|
|
983
|
-
...options2,
|
|
984
|
-
next: (newOptions = options2) => next(newOptions, index + 1)
|
|
985
|
-
});
|
|
986
|
-
};
|
|
987
|
-
return next(options, 0);
|
|
988
|
-
}
|
|
989
|
-
|
|
990
|
-
function sortPlugins(plugins) {
|
|
991
|
-
const pluginCount = plugins.length;
|
|
992
|
-
const pluginIdToIndices = /* @__PURE__ */ new Map();
|
|
993
|
-
for (let i = 0; i < pluginCount; i++) {
|
|
994
|
-
const plugin = plugins[i];
|
|
995
|
-
const indices = pluginIdToIndices.get(plugin.name);
|
|
996
|
-
if (indices === void 0) {
|
|
997
|
-
pluginIdToIndices.set(plugin.name, [i]);
|
|
998
|
-
} else {
|
|
999
|
-
indices.push(i);
|
|
1000
|
-
}
|
|
1001
|
-
}
|
|
1002
|
-
const dependencies = Array.from({ length: pluginCount }, () => []);
|
|
1003
|
-
for (let i = 0; i < pluginCount; i++) {
|
|
1004
|
-
const plugin = plugins[i];
|
|
1005
|
-
if (plugin.before !== void 0) {
|
|
1006
|
-
for (const beforeId of plugin.before) {
|
|
1007
|
-
const beforeIndices = pluginIdToIndices.get(beforeId);
|
|
1008
|
-
if (beforeIndices !== void 0) {
|
|
1009
|
-
for (const beforeIndex of beforeIndices) {
|
|
1010
|
-
dependencies[beforeIndex].push(i);
|
|
1011
|
-
}
|
|
1012
|
-
}
|
|
1013
|
-
}
|
|
1014
|
-
}
|
|
1015
|
-
if (plugin.after !== void 0) {
|
|
1016
|
-
for (const afterId of plugin.after) {
|
|
1017
|
-
const afterIndices = pluginIdToIndices.get(afterId);
|
|
1018
|
-
if (afterIndices !== void 0) {
|
|
1019
|
-
for (const afterIndex of afterIndices) {
|
|
1020
|
-
dependencies[i].push(afterIndex);
|
|
1021
|
-
}
|
|
1022
|
-
}
|
|
1023
|
-
}
|
|
1024
|
-
}
|
|
1025
|
-
}
|
|
1026
|
-
const sorted = [];
|
|
1027
|
-
const placed = /* @__PURE__ */ new Set();
|
|
1028
|
-
while (sorted.length < pluginCount) {
|
|
1029
|
-
const next = plugins.findIndex((_, i) => !placed.has(i) && dependencies[i].every((dependency) => placed.has(dependency)));
|
|
1030
|
-
if (next === -1) {
|
|
1031
|
-
throw new Error(`Circular dependency detected involving plugin "${findCyclicPlugin(plugins, dependencies, placed).name}"`);
|
|
1032
|
-
}
|
|
1033
|
-
placed.add(next);
|
|
1034
|
-
sorted.push(plugins[next]);
|
|
1035
|
-
}
|
|
1036
|
-
return sorted;
|
|
1037
|
-
}
|
|
1038
|
-
function findCyclicPlugin(plugins, dependencies, placed) {
|
|
1039
|
-
const seen = /* @__PURE__ */ new Set();
|
|
1040
|
-
let current = plugins.findIndex((_, i) => !placed.has(i));
|
|
1041
|
-
while (!seen.has(current)) {
|
|
1042
|
-
seen.add(current);
|
|
1043
|
-
current = dependencies[current].find((dependency) => !placed.has(dependency));
|
|
1044
|
-
}
|
|
1045
|
-
return plugins[current];
|
|
1046
|
-
}
|
|
1047
|
-
|
|
1048
|
-
function allAbortSignal(signals) {
|
|
1049
|
-
const realSignals = signals.filter((signal) => signal !== void 0);
|
|
1050
|
-
if (realSignals.length === 0 || realSignals.length !== signals.length) {
|
|
1051
|
-
return void 0;
|
|
1052
|
-
}
|
|
1053
|
-
const controller = new AbortController();
|
|
1054
|
-
const abortIfAllAborted = () => {
|
|
1055
|
-
if (realSignals.every((signal) => signal.aborted)) {
|
|
1056
|
-
controller.abort();
|
|
1057
|
-
}
|
|
1058
|
-
};
|
|
1059
|
-
abortIfAllAborted();
|
|
1060
|
-
for (const signal of realSignals) {
|
|
1061
|
-
signal.addEventListener("abort", () => {
|
|
1062
|
-
abortIfAllAborted();
|
|
1063
|
-
}, {
|
|
1064
|
-
once: true,
|
|
1065
|
-
signal: controller.signal
|
|
1066
|
-
});
|
|
1067
|
-
}
|
|
1068
|
-
return controller.signal;
|
|
1069
|
-
}
|
|
1070
|
-
function anyAbortSignal(signals) {
|
|
1071
|
-
const realSignals = signals.filter((signal) => signal !== void 0);
|
|
1072
|
-
if (realSignals.length === 0) {
|
|
1073
|
-
return void 0;
|
|
1074
|
-
}
|
|
1075
|
-
if (realSignals.length === 1) {
|
|
1076
|
-
return realSignals[0];
|
|
1077
|
-
}
|
|
1078
|
-
if (typeof AbortSignal !== "undefined" && typeof AbortSignal.any === "function") {
|
|
1079
|
-
return AbortSignal.any(realSignals);
|
|
1080
|
-
}
|
|
1081
|
-
const controller = new AbortController();
|
|
1082
|
-
for (const signal of realSignals) {
|
|
1083
|
-
if (signal.aborted) {
|
|
1084
|
-
controller.abort(signal.reason);
|
|
1085
|
-
break;
|
|
1086
|
-
}
|
|
1087
|
-
signal.addEventListener("abort", () => {
|
|
1088
|
-
controller.abort(signal.reason);
|
|
1089
|
-
}, {
|
|
1090
|
-
once: true,
|
|
1091
|
-
signal: controller.signal
|
|
1092
|
-
});
|
|
1093
|
-
}
|
|
1094
|
-
return controller.signal;
|
|
1095
|
-
}
|
|
1096
|
-
async function runWithSignal(signal, fn) {
|
|
1097
|
-
if (!signal) {
|
|
1098
|
-
return fn();
|
|
1099
|
-
}
|
|
1100
|
-
throwIfAborted(signal);
|
|
1101
|
-
const { promise, reject, resolve } = promiseWithResolvers();
|
|
1102
|
-
let abortListener;
|
|
1103
|
-
signal.addEventListener("abort", abortListener = () => {
|
|
1104
|
-
reject(signal.reason);
|
|
1105
|
-
abortListener = void 0;
|
|
1106
|
-
});
|
|
1107
|
-
try {
|
|
1108
|
-
fn().then(resolve, reject);
|
|
1109
|
-
return await promise;
|
|
1110
|
-
} finally {
|
|
1111
|
-
if (abortListener) {
|
|
1112
|
-
signal.removeEventListener("abort", abortListener);
|
|
1113
|
-
}
|
|
1114
|
-
}
|
|
1115
|
-
}
|
|
1116
|
-
|
|
1117
|
-
export { AsyncIdQueue, DEFAULT_MAX_BIGINT_DIGITS, NullProtoObj, ORPC_NAME, allAbortSignal, anyAbortSignal, asyncIteratorToStream, asyncIteratorToUnproxiedDataStream, bindMethods, captureAsyncContext, clone, compareSequentialIds, consumeAsyncIterator, copyOnWrite, defer, encodeBase64, findDeepMatches, get, getConstructor, getConstructors, getOwn, getTracer, intercept, isAbortError, isAcceptableEncoding, isAsyncGeneratorFunction, isCompressibleContentType, isDeepEqual, isNoTransformCacheControl, isPlainObject, isPropertyKey, loadBytes, matchesHttpPath, matchesHttpPathPrefix, mergeHttpPath, mergeTwoLevels, normalizeHttpPath, omit, onAsyncIteratorObjectError, onError, onFinish, onReadableStreamError, onStart, onSuccess, once, override, parseAcceptEncodingQualities, parseBigIntString, pathToHttpPath, pick, promiseWithResolvers, recordSpanError, replicateAsyncIterator, replicateReadableStream, resolveMaybeOptionalOptions, runInSpanContext, runWithSignal, runWithSpan, set, setOwn, setSpanAttributeIfDefined, setTracer, sortPlugins, splitInHalf, startSpan, streamToAsyncIteratorObject, toSpanAttributeValue, toStringOrBytes, toTracingException, traceAsyncIterator, traceReadableStream, tryOrUndefined, value, varyByAcceptEncoding, wrapAsyncIterator, wrapReadableStream };
|