@orpc/shared 2.0.0-beta.3 → 2.0.0-beta.31
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 +71 -101
- package/dist/index.d.mts +116 -16
- package/dist/index.d.ts +116 -16
- package/dist/index.mjs +394 -217
- package/package.json +10 -5
package/dist/index.mjs
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { AbortError, AsyncIteratorClass, isTypescriptObject,
|
|
2
|
-
export { AbortError, AsyncIteratorClass, SequentialIdGenerator, getOrBind, isAsyncIteratorObject, isTypescriptObject, parseEmptyableJSON, sleep, stringifyJSON, toArray } from '@standardserver/shared';
|
|
1
|
+
import { AbortError, AsyncIteratorClass, getOrBind, isTypescriptObject, isAsyncIteratorObject } from '@standardserver/shared';
|
|
2
|
+
export { AbortError, AsyncIteratorClass, SequentialIdGenerator, getOrBind, isAsyncIteratorObject, isTypescriptObject, parseEmptyableJSON, sequential, sleep, stringifyJSON, toArray } from '@standardserver/shared';
|
|
3
3
|
|
|
4
4
|
function resolveMaybeOptionalOptions(rest) {
|
|
5
5
|
return rest[0] ?? {};
|
|
@@ -16,24 +16,44 @@ async function loadBytes(source) {
|
|
|
16
16
|
}
|
|
17
17
|
return new Uint8Array(await source.arrayBuffer());
|
|
18
18
|
}
|
|
19
|
-
|
|
19
|
+
function toStringOrBytes(source) {
|
|
20
20
|
if (typeof source === "string") {
|
|
21
21
|
return source;
|
|
22
22
|
}
|
|
23
23
|
if (source instanceof ArrayBuffer) {
|
|
24
24
|
return new Uint8Array(source);
|
|
25
25
|
}
|
|
26
|
-
if (source instanceof Blob) {
|
|
27
|
-
return loadBytes(source);
|
|
28
|
-
}
|
|
29
26
|
if (Array.isArray(source)) {
|
|
30
|
-
return
|
|
27
|
+
return concatBytes(source);
|
|
31
28
|
}
|
|
32
29
|
if (source instanceof Uint8Array) {
|
|
33
30
|
return source;
|
|
34
31
|
}
|
|
35
32
|
return new Uint8Array(source.buffer, source.byteOffset, source.byteLength);
|
|
36
33
|
}
|
|
34
|
+
function toBytes(item) {
|
|
35
|
+
if (typeof item === "string") {
|
|
36
|
+
return new TextEncoder().encode(item);
|
|
37
|
+
}
|
|
38
|
+
if (item instanceof ArrayBuffer) {
|
|
39
|
+
return new Uint8Array(item);
|
|
40
|
+
}
|
|
41
|
+
if (item instanceof Uint8Array) {
|
|
42
|
+
return item;
|
|
43
|
+
}
|
|
44
|
+
return new Uint8Array(item.buffer, item.byteOffset, item.byteLength);
|
|
45
|
+
}
|
|
46
|
+
function concatBytes(items) {
|
|
47
|
+
const chunks = items.map(toBytes);
|
|
48
|
+
const totalLength = chunks.reduce((sum, chunk) => sum + chunk.byteLength, 0);
|
|
49
|
+
const result = new Uint8Array(totalLength);
|
|
50
|
+
let offset = 0;
|
|
51
|
+
for (const chunk of chunks) {
|
|
52
|
+
result.set(chunk, offset);
|
|
53
|
+
offset += chunk.byteLength;
|
|
54
|
+
}
|
|
55
|
+
return result;
|
|
56
|
+
}
|
|
37
57
|
|
|
38
58
|
function isDeepEqual(a, b) {
|
|
39
59
|
return isDeepEqualInternal(a, b, /* @__PURE__ */ new WeakMap());
|
|
@@ -156,67 +176,51 @@ function matchesHttpPath(url, path) {
|
|
|
156
176
|
}
|
|
157
177
|
return charAfterPrefix === void 0 || charAfterPrefix === "?" || charAfterPrefix === "#";
|
|
158
178
|
}
|
|
159
|
-
|
|
160
|
-
function
|
|
161
|
-
|
|
162
|
-
|
|
179
|
+
const ACCEPT_ENCODING_QUALITY_REGEX = /^\s*q=([\d.]+)\s*$/i;
|
|
180
|
+
function parseAcceptEncodingQualities(header) {
|
|
181
|
+
const qualities = /* @__PURE__ */ new Map();
|
|
182
|
+
for (const part of header?.split(",") ?? []) {
|
|
183
|
+
const [rawCoding, ...params] = part.split(";");
|
|
184
|
+
const coding = rawCoding.trim().toLowerCase();
|
|
185
|
+
if (coding === "") {
|
|
186
|
+
continue;
|
|
187
|
+
}
|
|
188
|
+
const quality = params.map((param) => ACCEPT_ENCODING_QUALITY_REGEX.exec(param)?.[1]).find((value) => value !== void 0);
|
|
189
|
+
qualities.set(coding, quality === void 0 ? 1 : Number(quality));
|
|
163
190
|
}
|
|
164
|
-
return
|
|
191
|
+
return qualities;
|
|
165
192
|
}
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
}
|
|
172
|
-
}
|
|
173
|
-
function onSuccess(callback) {
|
|
174
|
-
return async (options, ...rest) => {
|
|
175
|
-
const result = await options.next();
|
|
176
|
-
await callback(result, options, ...rest);
|
|
177
|
-
return result;
|
|
178
|
-
};
|
|
193
|
+
function varyByAcceptEncoding(vary) {
|
|
194
|
+
if (vary === void 0) {
|
|
195
|
+
return "accept-encoding";
|
|
196
|
+
}
|
|
197
|
+
const fields = vary.split(",").map((field) => field.trim().toLowerCase());
|
|
198
|
+
return fields.includes("accept-encoding") || fields.includes("*") ? vary : `${vary}, accept-encoding`;
|
|
179
199
|
}
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
throw error;
|
|
187
|
-
}
|
|
188
|
-
};
|
|
200
|
+
const CACHE_CONTROL_NO_TRANSFORM_REGEX = /(?:^|,)\s*no-transform\s*(?:,|$)/i;
|
|
201
|
+
function isNoTransformCacheControl(cacheControl) {
|
|
202
|
+
if (cacheControl === void 0) {
|
|
203
|
+
return false;
|
|
204
|
+
}
|
|
205
|
+
return CACHE_CONTROL_NO_TRANSFORM_REGEX.test(cacheControl);
|
|
189
206
|
}
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
} finally {
|
|
201
|
-
await callback(state, options, ...rest);
|
|
202
|
-
}
|
|
203
|
-
};
|
|
207
|
+
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;
|
|
208
|
+
const MAX_COMPRESSIBLE_CONTENT_TYPE_LENGTH = 1024;
|
|
209
|
+
function isCompressibleContentType(contentType) {
|
|
210
|
+
if (contentType === null || contentType === void 0) {
|
|
211
|
+
return false;
|
|
212
|
+
}
|
|
213
|
+
if (contentType.length > MAX_COMPRESSIBLE_CONTENT_TYPE_LENGTH) {
|
|
214
|
+
return false;
|
|
215
|
+
}
|
|
216
|
+
return COMPRESSIBLE_CONTENT_TYPE_REGEX.test(contentType);
|
|
204
217
|
}
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
218
|
+
|
|
219
|
+
function compareSequentialIds(a, b) {
|
|
220
|
+
if (a.length !== b.length) {
|
|
221
|
+
return a.length - b.length;
|
|
208
222
|
}
|
|
209
|
-
|
|
210
|
-
const interceptor = interceptors[index];
|
|
211
|
-
if (!interceptor) {
|
|
212
|
-
return main(options2);
|
|
213
|
-
}
|
|
214
|
-
return interceptor({
|
|
215
|
-
...options2,
|
|
216
|
-
next: (newOptions = options2) => next(newOptions, index + 1)
|
|
217
|
-
});
|
|
218
|
-
};
|
|
219
|
-
return next(options, 0);
|
|
223
|
+
return a < b ? -1 : a > b ? 1 : 0;
|
|
220
224
|
}
|
|
221
225
|
|
|
222
226
|
const SPAN_ERROR_STATUS = 2;
|
|
@@ -491,6 +495,52 @@ function replicateAsyncIterator(source, count) {
|
|
|
491
495
|
});
|
|
492
496
|
return replicated;
|
|
493
497
|
}
|
|
498
|
+
function consumeAsyncIterator(iterator, options) {
|
|
499
|
+
void (async () => {
|
|
500
|
+
let onFinishState;
|
|
501
|
+
try {
|
|
502
|
+
const resolvedIterator = await iterator;
|
|
503
|
+
while (true) {
|
|
504
|
+
const { done, value } = await resolvedIterator.next();
|
|
505
|
+
if (done) {
|
|
506
|
+
const realValue = value;
|
|
507
|
+
onFinishState = [null, realValue, true];
|
|
508
|
+
options.onSuccess?.(realValue);
|
|
509
|
+
break;
|
|
510
|
+
}
|
|
511
|
+
options.onEvent(value);
|
|
512
|
+
}
|
|
513
|
+
} catch (error) {
|
|
514
|
+
onFinishState = [error, void 0, false];
|
|
515
|
+
options.onError?.(error);
|
|
516
|
+
} finally {
|
|
517
|
+
options.onFinish?.(onFinishState);
|
|
518
|
+
}
|
|
519
|
+
})();
|
|
520
|
+
return async () => {
|
|
521
|
+
await (await iterator)?.return?.();
|
|
522
|
+
};
|
|
523
|
+
}
|
|
524
|
+
|
|
525
|
+
function value(value2, ...args) {
|
|
526
|
+
if (typeof value2 === "function") {
|
|
527
|
+
return value2(...args);
|
|
528
|
+
}
|
|
529
|
+
return value2;
|
|
530
|
+
}
|
|
531
|
+
|
|
532
|
+
function override(target, partial) {
|
|
533
|
+
const proxy = new Proxy(typeof target === "function" ? partial : target, {
|
|
534
|
+
get(_, prop) {
|
|
535
|
+
const targetValue = prop in partial ? partial : value(target);
|
|
536
|
+
return getOrBind(targetValue, prop);
|
|
537
|
+
},
|
|
538
|
+
has(_, prop) {
|
|
539
|
+
return Reflect.has(partial, prop) || Reflect.has(value(target), prop);
|
|
540
|
+
}
|
|
541
|
+
});
|
|
542
|
+
return proxy;
|
|
543
|
+
}
|
|
494
544
|
|
|
495
545
|
function findDeepMatches(check, payload, segments = [], maps = [], values = []) {
|
|
496
546
|
if (check(payload)) {
|
|
@@ -513,6 +563,18 @@ function getConstructor(value) {
|
|
|
513
563
|
}
|
|
514
564
|
return Object.getPrototypeOf(value)?.constructor;
|
|
515
565
|
}
|
|
566
|
+
function* getConstructors(value) {
|
|
567
|
+
if (!isTypescriptObject(value)) {
|
|
568
|
+
return;
|
|
569
|
+
}
|
|
570
|
+
let proto = Object.getPrototypeOf(value);
|
|
571
|
+
while (proto != null) {
|
|
572
|
+
if (proto.constructor) {
|
|
573
|
+
yield proto.constructor;
|
|
574
|
+
}
|
|
575
|
+
proto = Object.getPrototypeOf(proto);
|
|
576
|
+
}
|
|
577
|
+
}
|
|
516
578
|
function isPlainObject(value) {
|
|
517
579
|
if (!value || typeof value !== "object") {
|
|
518
580
|
return false;
|
|
@@ -520,10 +582,13 @@ function isPlainObject(value) {
|
|
|
520
582
|
const proto = Object.getPrototypeOf(value);
|
|
521
583
|
return proto === Object.prototype || !proto || !proto.constructor;
|
|
522
584
|
}
|
|
585
|
+
function getOwn(object, key) {
|
|
586
|
+
return Object.hasOwn(object, key) ? object[key] : void 0;
|
|
587
|
+
}
|
|
523
588
|
function get(object, path) {
|
|
524
589
|
let current = object;
|
|
525
590
|
for (const key of path) {
|
|
526
|
-
if (!isTypescriptObject(current)) {
|
|
591
|
+
if (!isTypescriptObject(current) || !Object.hasOwn(current, key)) {
|
|
527
592
|
return void 0;
|
|
528
593
|
}
|
|
529
594
|
current = current[key];
|
|
@@ -534,13 +599,41 @@ function set(root, path, value) {
|
|
|
534
599
|
let current = root;
|
|
535
600
|
for (let i = 0; i < path.length - 1; i++) {
|
|
536
601
|
const key = path[i];
|
|
537
|
-
const next = current[key];
|
|
602
|
+
const next = Object.hasOwn(current, key) ? current[key] : void 0;
|
|
538
603
|
if (!isTypescriptObject(next)) {
|
|
539
|
-
|
|
604
|
+
const child = {};
|
|
605
|
+
defineOwnProperty(current, key, child);
|
|
606
|
+
current = child;
|
|
607
|
+
} else {
|
|
608
|
+
current = next;
|
|
609
|
+
}
|
|
610
|
+
}
|
|
611
|
+
defineOwnProperty(current, path.at(-1), value);
|
|
612
|
+
}
|
|
613
|
+
function defineOwnProperty(object, key, value) {
|
|
614
|
+
Object.defineProperty(object, key, {
|
|
615
|
+
value,
|
|
616
|
+
writable: true,
|
|
617
|
+
enumerable: true,
|
|
618
|
+
configurable: true
|
|
619
|
+
});
|
|
620
|
+
}
|
|
621
|
+
function mergeTwoLevels(first, second) {
|
|
622
|
+
if (!isPlainObject(first) || !isPlainObject(second)) {
|
|
623
|
+
return second;
|
|
624
|
+
}
|
|
625
|
+
const result = { ...first, ...second };
|
|
626
|
+
for (const key in second) {
|
|
627
|
+
if (!Object.hasOwn(first, key)) {
|
|
628
|
+
continue;
|
|
629
|
+
}
|
|
630
|
+
const firstValue = first[key];
|
|
631
|
+
const secondValue = second[key];
|
|
632
|
+
if (isPlainObject(firstValue) && isPlainObject(secondValue)) {
|
|
633
|
+
defineOwnProperty(result, key, { ...firstValue, ...secondValue });
|
|
540
634
|
}
|
|
541
|
-
current = current[key];
|
|
542
635
|
}
|
|
543
|
-
|
|
636
|
+
return result;
|
|
544
637
|
}
|
|
545
638
|
function omit(obj, keys) {
|
|
546
639
|
const result = { ...obj };
|
|
@@ -556,10 +649,10 @@ function clone(value) {
|
|
|
556
649
|
if (isPlainObject(value)) {
|
|
557
650
|
const result = {};
|
|
558
651
|
for (const key in value) {
|
|
559
|
-
result
|
|
652
|
+
defineOwnProperty(result, key, clone(value[key]));
|
|
560
653
|
}
|
|
561
654
|
for (const sym of Object.getOwnPropertySymbols(value)) {
|
|
562
|
-
result
|
|
655
|
+
defineOwnProperty(result, sym, clone(value[sym]));
|
|
563
656
|
}
|
|
564
657
|
return result;
|
|
565
658
|
}
|
|
@@ -576,7 +669,8 @@ const NullProtoObj = /* @__PURE__ */ (() => {
|
|
|
576
669
|
Object.freeze(e.prototype);
|
|
577
670
|
return e;
|
|
578
671
|
})();
|
|
579
|
-
function bindMethods(obj) {
|
|
672
|
+
function bindMethods(obj, options = {}) {
|
|
673
|
+
const unbound = new Set(options.unbound);
|
|
580
674
|
const methods = new NullProtoObj();
|
|
581
675
|
let current = obj;
|
|
582
676
|
while (current && current !== Object.prototype) {
|
|
@@ -584,18 +678,18 @@ function bindMethods(obj) {
|
|
|
584
678
|
if (key === "constructor" || key in methods) {
|
|
585
679
|
continue;
|
|
586
680
|
}
|
|
587
|
-
const val = obj
|
|
681
|
+
const val = getOrBind(obj, key, { bind: !unbound.has(key) });
|
|
588
682
|
if (typeof val === "function") {
|
|
589
|
-
methods[key] = val
|
|
683
|
+
methods[key] = val;
|
|
590
684
|
}
|
|
591
685
|
}
|
|
592
686
|
for (const sym of Object.getOwnPropertySymbols(current)) {
|
|
593
687
|
if (sym in methods) {
|
|
594
688
|
continue;
|
|
595
689
|
}
|
|
596
|
-
const val = obj
|
|
690
|
+
const val = getOrBind(obj, sym, { bind: !unbound.has(sym) });
|
|
597
691
|
if (typeof val === "function") {
|
|
598
|
-
methods[sym] = val
|
|
692
|
+
methods[sym] = val;
|
|
599
693
|
}
|
|
600
694
|
}
|
|
601
695
|
current = Object.getPrototypeOf(current);
|
|
@@ -603,84 +697,6 @@ function bindMethods(obj) {
|
|
|
603
697
|
return methods;
|
|
604
698
|
}
|
|
605
699
|
|
|
606
|
-
function sortPlugins(plugins) {
|
|
607
|
-
const pluginCount = plugins.length;
|
|
608
|
-
const pluginIdToIndices = /* @__PURE__ */ new Map();
|
|
609
|
-
for (let i = 0; i < pluginCount; i++) {
|
|
610
|
-
const plugin = plugins[i];
|
|
611
|
-
const indices = pluginIdToIndices.get(plugin.name);
|
|
612
|
-
if (indices === void 0) {
|
|
613
|
-
pluginIdToIndices.set(plugin.name, [i]);
|
|
614
|
-
} else {
|
|
615
|
-
indices.push(i);
|
|
616
|
-
}
|
|
617
|
-
}
|
|
618
|
-
const graph = Array.from(
|
|
619
|
-
{ length: pluginCount },
|
|
620
|
-
() => /* @__PURE__ */ new Set()
|
|
621
|
-
);
|
|
622
|
-
for (let i = 0; i < pluginCount; i++) {
|
|
623
|
-
const plugin = plugins[i];
|
|
624
|
-
const beforeList = plugin.before;
|
|
625
|
-
if (beforeList !== void 0) {
|
|
626
|
-
for (const beforeId of beforeList) {
|
|
627
|
-
const beforeIndices = pluginIdToIndices.get(beforeId);
|
|
628
|
-
if (beforeIndices === void 0)
|
|
629
|
-
continue;
|
|
630
|
-
for (const beforeIndex of beforeIndices) {
|
|
631
|
-
const beforeGraph = graph[beforeIndex];
|
|
632
|
-
if (beforeGraph !== void 0) {
|
|
633
|
-
beforeGraph.add(i);
|
|
634
|
-
}
|
|
635
|
-
}
|
|
636
|
-
}
|
|
637
|
-
}
|
|
638
|
-
const afterList = plugin.after;
|
|
639
|
-
if (afterList !== void 0) {
|
|
640
|
-
const currentGraph = graph[i];
|
|
641
|
-
if (currentGraph !== void 0) {
|
|
642
|
-
for (const afterId of afterList) {
|
|
643
|
-
const afterIndices = pluginIdToIndices.get(afterId);
|
|
644
|
-
if (afterIndices === void 0)
|
|
645
|
-
continue;
|
|
646
|
-
for (const afterIndex of afterIndices) {
|
|
647
|
-
currentGraph.add(afterIndex);
|
|
648
|
-
}
|
|
649
|
-
}
|
|
650
|
-
}
|
|
651
|
-
}
|
|
652
|
-
}
|
|
653
|
-
const sorted = [];
|
|
654
|
-
const visiting = /* @__PURE__ */ new Set();
|
|
655
|
-
const visited = /* @__PURE__ */ new Set();
|
|
656
|
-
function visit(index) {
|
|
657
|
-
if (visited.has(index))
|
|
658
|
-
return;
|
|
659
|
-
if (visiting.has(index)) {
|
|
660
|
-
const plugin2 = plugins[index];
|
|
661
|
-
const pluginId = plugin2 !== void 0 ? plugin2.name : "unknown";
|
|
662
|
-
throw new Error(`Circular dependency detected involving plugin "${pluginId}"`);
|
|
663
|
-
}
|
|
664
|
-
visiting.add(index);
|
|
665
|
-
const deps = graph[index];
|
|
666
|
-
if (deps !== void 0) {
|
|
667
|
-
for (const depIndex of deps) {
|
|
668
|
-
visit(depIndex);
|
|
669
|
-
}
|
|
670
|
-
}
|
|
671
|
-
visiting.delete(index);
|
|
672
|
-
visited.add(index);
|
|
673
|
-
const plugin = plugins[index];
|
|
674
|
-
if (plugin !== void 0) {
|
|
675
|
-
sorted.push(plugin);
|
|
676
|
-
}
|
|
677
|
-
}
|
|
678
|
-
for (let i = 0; i < pluginCount; i++) {
|
|
679
|
-
visit(i);
|
|
680
|
-
}
|
|
681
|
-
return sorted;
|
|
682
|
-
}
|
|
683
|
-
|
|
684
700
|
function promiseWithResolvers() {
|
|
685
701
|
const result = {};
|
|
686
702
|
result.promise = new Promise((resolve, reject) => {
|
|
@@ -690,69 +706,6 @@ function promiseWithResolvers() {
|
|
|
690
706
|
return result;
|
|
691
707
|
}
|
|
692
708
|
|
|
693
|
-
function value(value2, ...args) {
|
|
694
|
-
if (typeof value2 === "function") {
|
|
695
|
-
return value2(...args);
|
|
696
|
-
}
|
|
697
|
-
return value2;
|
|
698
|
-
}
|
|
699
|
-
|
|
700
|
-
function override(target, partial) {
|
|
701
|
-
const proxy = new Proxy(typeof target === "function" ? partial : target, {
|
|
702
|
-
get(_, prop) {
|
|
703
|
-
const targetValue = prop in partial ? partial : value(target);
|
|
704
|
-
return getOrBind(targetValue, prop);
|
|
705
|
-
},
|
|
706
|
-
has(_, prop) {
|
|
707
|
-
return Reflect.has(partial, prop) || Reflect.has(value(target), prop);
|
|
708
|
-
}
|
|
709
|
-
});
|
|
710
|
-
return proxy;
|
|
711
|
-
}
|
|
712
|
-
|
|
713
|
-
function allAbortSignal(signals) {
|
|
714
|
-
const realSignals = signals.filter((signal) => signal !== void 0);
|
|
715
|
-
if (realSignals.length === 0 || realSignals.length !== signals.length) {
|
|
716
|
-
return void 0;
|
|
717
|
-
}
|
|
718
|
-
const controller = new AbortController();
|
|
719
|
-
const abortIfAllAborted = () => {
|
|
720
|
-
if (realSignals.every((signal) => signal.aborted)) {
|
|
721
|
-
controller.abort();
|
|
722
|
-
}
|
|
723
|
-
};
|
|
724
|
-
abortIfAllAborted();
|
|
725
|
-
for (const signal of realSignals) {
|
|
726
|
-
signal.addEventListener("abort", () => {
|
|
727
|
-
abortIfAllAborted();
|
|
728
|
-
}, {
|
|
729
|
-
once: true,
|
|
730
|
-
signal: controller.signal
|
|
731
|
-
});
|
|
732
|
-
}
|
|
733
|
-
return controller.signal;
|
|
734
|
-
}
|
|
735
|
-
async function runWithSignal(signal, fn) {
|
|
736
|
-
if (!signal) {
|
|
737
|
-
return fn();
|
|
738
|
-
}
|
|
739
|
-
signal.throwIfAborted();
|
|
740
|
-
const { promise, reject, resolve } = promiseWithResolvers();
|
|
741
|
-
let abortListener;
|
|
742
|
-
signal.addEventListener("abort", abortListener = () => {
|
|
743
|
-
reject(signal.reason);
|
|
744
|
-
abortListener = void 0;
|
|
745
|
-
});
|
|
746
|
-
try {
|
|
747
|
-
fn().then(resolve, reject);
|
|
748
|
-
return await promise;
|
|
749
|
-
} finally {
|
|
750
|
-
if (abortListener) {
|
|
751
|
-
signal.removeEventListener("abort", abortListener);
|
|
752
|
-
}
|
|
753
|
-
}
|
|
754
|
-
}
|
|
755
|
-
|
|
756
709
|
function replicateReadableStream(stream, count) {
|
|
757
710
|
if (count <= 0) {
|
|
758
711
|
return [];
|
|
@@ -823,7 +776,7 @@ function traceReadableStream(options, stream) {
|
|
|
823
776
|
}
|
|
824
777
|
});
|
|
825
778
|
}
|
|
826
|
-
function
|
|
779
|
+
function streamToAsyncIteratorObject(stream, { signal } = {}) {
|
|
827
780
|
const reader = stream.getReader();
|
|
828
781
|
let cancelledBySignal = false;
|
|
829
782
|
return new AsyncIteratorClass(
|
|
@@ -889,4 +842,228 @@ function asyncIteratorToUnproxiedDataStream(iterator) {
|
|
|
889
842
|
});
|
|
890
843
|
}
|
|
891
844
|
|
|
892
|
-
|
|
845
|
+
function onStart(callback) {
|
|
846
|
+
return async (options, ...rest) => {
|
|
847
|
+
await callback(options, ...rest);
|
|
848
|
+
return await options.next();
|
|
849
|
+
};
|
|
850
|
+
}
|
|
851
|
+
function onSuccess(callback) {
|
|
852
|
+
return async (options, ...rest) => {
|
|
853
|
+
const result = await options.next();
|
|
854
|
+
await callback(result, options, ...rest);
|
|
855
|
+
return result;
|
|
856
|
+
};
|
|
857
|
+
}
|
|
858
|
+
function onError(callback) {
|
|
859
|
+
return async (options, ...rest) => {
|
|
860
|
+
try {
|
|
861
|
+
return await options.next();
|
|
862
|
+
} catch (error) {
|
|
863
|
+
await callback(error, options, ...rest);
|
|
864
|
+
throw error;
|
|
865
|
+
}
|
|
866
|
+
};
|
|
867
|
+
}
|
|
868
|
+
function onFinish(callback) {
|
|
869
|
+
let state;
|
|
870
|
+
return async (options, ...rest) => {
|
|
871
|
+
try {
|
|
872
|
+
const result = await options.next();
|
|
873
|
+
state = [null, result, true];
|
|
874
|
+
return result;
|
|
875
|
+
} catch (error) {
|
|
876
|
+
state = [error, void 0, false];
|
|
877
|
+
throw error;
|
|
878
|
+
} finally {
|
|
879
|
+
await callback(state, options, ...rest);
|
|
880
|
+
}
|
|
881
|
+
};
|
|
882
|
+
}
|
|
883
|
+
function onAsyncIteratorObjectError(callback) {
|
|
884
|
+
return async (options, ...rest) => {
|
|
885
|
+
const output = await options.next();
|
|
886
|
+
if (!isAsyncIteratorObject(output)) {
|
|
887
|
+
return output;
|
|
888
|
+
}
|
|
889
|
+
return override(output, wrapAsyncIterator(output, {
|
|
890
|
+
onError: (error) => callback(error, options, ...rest)
|
|
891
|
+
}));
|
|
892
|
+
};
|
|
893
|
+
}
|
|
894
|
+
function onReadableStreamError(callback) {
|
|
895
|
+
return async (options, ...rest) => {
|
|
896
|
+
const output = await options.next();
|
|
897
|
+
if (!(output instanceof ReadableStream)) {
|
|
898
|
+
return output;
|
|
899
|
+
}
|
|
900
|
+
return override(output, wrapReadableStream(output, {
|
|
901
|
+
onError: (error) => callback(error, options, ...rest)
|
|
902
|
+
}));
|
|
903
|
+
};
|
|
904
|
+
}
|
|
905
|
+
function intercept(interceptors, options, main) {
|
|
906
|
+
if (!interceptors?.length) {
|
|
907
|
+
return main(options);
|
|
908
|
+
}
|
|
909
|
+
const next = (options2, index) => {
|
|
910
|
+
const interceptor = interceptors[index];
|
|
911
|
+
if (!interceptor) {
|
|
912
|
+
return main(options2);
|
|
913
|
+
}
|
|
914
|
+
return interceptor({
|
|
915
|
+
...options2,
|
|
916
|
+
next: (newOptions = options2) => next(newOptions, index + 1)
|
|
917
|
+
});
|
|
918
|
+
};
|
|
919
|
+
return next(options, 0);
|
|
920
|
+
}
|
|
921
|
+
|
|
922
|
+
function sortPlugins(plugins) {
|
|
923
|
+
const pluginCount = plugins.length;
|
|
924
|
+
const pluginIdToIndices = /* @__PURE__ */ new Map();
|
|
925
|
+
for (let i = 0; i < pluginCount; i++) {
|
|
926
|
+
const plugin = plugins[i];
|
|
927
|
+
const indices = pluginIdToIndices.get(plugin.name);
|
|
928
|
+
if (indices === void 0) {
|
|
929
|
+
pluginIdToIndices.set(plugin.name, [i]);
|
|
930
|
+
} else {
|
|
931
|
+
indices.push(i);
|
|
932
|
+
}
|
|
933
|
+
}
|
|
934
|
+
const graph = Array.from(
|
|
935
|
+
{ length: pluginCount },
|
|
936
|
+
() => /* @__PURE__ */ new Set()
|
|
937
|
+
);
|
|
938
|
+
for (let i = 0; i < pluginCount; i++) {
|
|
939
|
+
const plugin = plugins[i];
|
|
940
|
+
const beforeList = plugin.before;
|
|
941
|
+
if (beforeList !== void 0) {
|
|
942
|
+
for (const beforeId of beforeList) {
|
|
943
|
+
const beforeIndices = pluginIdToIndices.get(beforeId);
|
|
944
|
+
if (beforeIndices === void 0)
|
|
945
|
+
continue;
|
|
946
|
+
for (const beforeIndex of beforeIndices) {
|
|
947
|
+
const beforeGraph = graph[beforeIndex];
|
|
948
|
+
if (beforeGraph !== void 0) {
|
|
949
|
+
beforeGraph.add(i);
|
|
950
|
+
}
|
|
951
|
+
}
|
|
952
|
+
}
|
|
953
|
+
}
|
|
954
|
+
const afterList = plugin.after;
|
|
955
|
+
if (afterList !== void 0) {
|
|
956
|
+
const currentGraph = graph[i];
|
|
957
|
+
if (currentGraph !== void 0) {
|
|
958
|
+
for (const afterId of afterList) {
|
|
959
|
+
const afterIndices = pluginIdToIndices.get(afterId);
|
|
960
|
+
if (afterIndices === void 0)
|
|
961
|
+
continue;
|
|
962
|
+
for (const afterIndex of afterIndices) {
|
|
963
|
+
currentGraph.add(afterIndex);
|
|
964
|
+
}
|
|
965
|
+
}
|
|
966
|
+
}
|
|
967
|
+
}
|
|
968
|
+
}
|
|
969
|
+
const sorted = [];
|
|
970
|
+
const visiting = /* @__PURE__ */ new Set();
|
|
971
|
+
const visited = /* @__PURE__ */ new Set();
|
|
972
|
+
function visit(index) {
|
|
973
|
+
if (visited.has(index))
|
|
974
|
+
return;
|
|
975
|
+
if (visiting.has(index)) {
|
|
976
|
+
const plugin2 = plugins[index];
|
|
977
|
+
const pluginId = plugin2 !== void 0 ? plugin2.name : "unknown";
|
|
978
|
+
throw new Error(`Circular dependency detected involving plugin "${pluginId}"`);
|
|
979
|
+
}
|
|
980
|
+
visiting.add(index);
|
|
981
|
+
const deps = graph[index];
|
|
982
|
+
if (deps !== void 0) {
|
|
983
|
+
for (const depIndex of deps) {
|
|
984
|
+
visit(depIndex);
|
|
985
|
+
}
|
|
986
|
+
}
|
|
987
|
+
visiting.delete(index);
|
|
988
|
+
visited.add(index);
|
|
989
|
+
const plugin = plugins[index];
|
|
990
|
+
if (plugin !== void 0) {
|
|
991
|
+
sorted.push(plugin);
|
|
992
|
+
}
|
|
993
|
+
}
|
|
994
|
+
for (let i = 0; i < pluginCount; i++) {
|
|
995
|
+
visit(i);
|
|
996
|
+
}
|
|
997
|
+
return sorted;
|
|
998
|
+
}
|
|
999
|
+
|
|
1000
|
+
function allAbortSignal(signals) {
|
|
1001
|
+
const realSignals = signals.filter((signal) => signal !== void 0);
|
|
1002
|
+
if (realSignals.length === 0 || realSignals.length !== signals.length) {
|
|
1003
|
+
return void 0;
|
|
1004
|
+
}
|
|
1005
|
+
const controller = new AbortController();
|
|
1006
|
+
const abortIfAllAborted = () => {
|
|
1007
|
+
if (realSignals.every((signal) => signal.aborted)) {
|
|
1008
|
+
controller.abort();
|
|
1009
|
+
}
|
|
1010
|
+
};
|
|
1011
|
+
abortIfAllAborted();
|
|
1012
|
+
for (const signal of realSignals) {
|
|
1013
|
+
signal.addEventListener("abort", () => {
|
|
1014
|
+
abortIfAllAborted();
|
|
1015
|
+
}, {
|
|
1016
|
+
once: true,
|
|
1017
|
+
signal: controller.signal
|
|
1018
|
+
});
|
|
1019
|
+
}
|
|
1020
|
+
return controller.signal;
|
|
1021
|
+
}
|
|
1022
|
+
function anyAbortSignal(signals) {
|
|
1023
|
+
const realSignals = signals.filter((signal) => signal !== void 0);
|
|
1024
|
+
if (realSignals.length === 0) {
|
|
1025
|
+
return void 0;
|
|
1026
|
+
}
|
|
1027
|
+
if (realSignals.length === 1) {
|
|
1028
|
+
return realSignals[0];
|
|
1029
|
+
}
|
|
1030
|
+
if (typeof AbortSignal.any === "function") {
|
|
1031
|
+
return AbortSignal.any(realSignals);
|
|
1032
|
+
}
|
|
1033
|
+
const controller = new AbortController();
|
|
1034
|
+
for (const signal of realSignals) {
|
|
1035
|
+
if (signal.aborted) {
|
|
1036
|
+
controller.abort(signal.reason);
|
|
1037
|
+
break;
|
|
1038
|
+
}
|
|
1039
|
+
signal.addEventListener("abort", () => {
|
|
1040
|
+
controller.abort(signal.reason);
|
|
1041
|
+
}, {
|
|
1042
|
+
once: true,
|
|
1043
|
+
signal: controller.signal
|
|
1044
|
+
});
|
|
1045
|
+
}
|
|
1046
|
+
return controller.signal;
|
|
1047
|
+
}
|
|
1048
|
+
async function runWithSignal(signal, fn) {
|
|
1049
|
+
if (!signal) {
|
|
1050
|
+
return fn();
|
|
1051
|
+
}
|
|
1052
|
+
signal.throwIfAborted();
|
|
1053
|
+
const { promise, reject, resolve } = promiseWithResolvers();
|
|
1054
|
+
let abortListener;
|
|
1055
|
+
signal.addEventListener("abort", abortListener = () => {
|
|
1056
|
+
reject(signal.reason);
|
|
1057
|
+
abortListener = void 0;
|
|
1058
|
+
});
|
|
1059
|
+
try {
|
|
1060
|
+
fn().then(resolve, reject);
|
|
1061
|
+
return await promise;
|
|
1062
|
+
} finally {
|
|
1063
|
+
if (abortListener) {
|
|
1064
|
+
signal.removeEventListener("abort", abortListener);
|
|
1065
|
+
}
|
|
1066
|
+
}
|
|
1067
|
+
}
|
|
1068
|
+
|
|
1069
|
+
export { AsyncIdQueue, NullProtoObj, ORPC_NAME, allAbortSignal, anyAbortSignal, asyncIteratorToStream, asyncIteratorToUnproxiedDataStream, bindMethods, clone, compareSequentialIds, consumeAsyncIterator, defer, findDeepMatches, get, getConstructor, getConstructors, getOpenTelemetryConfig, getOwn, intercept, isAbortError, isCompressibleContentType, isDeepEqual, isNoTransformCacheControl, isPlainObject, isPropertyKey, loadBytes, matchesHttpPath, matchesHttpPathPrefix, mergeHttpPath, mergeTwoLevels, normalizeHttpPath, omit, onAsyncIteratorObjectError, onError, onFinish, onReadableStreamError, onStart, onSuccess, once, override, parseAcceptEncodingQualities, pathToHttpPath, promiseWithResolvers, recordSpanError, replicateAsyncIterator, replicateReadableStream, resolveMaybeOptionalOptions, runInSpanContext, runWithSignal, runWithSpan, set, setOpenTelemetryConfig, setSpanAttributeIfDefined, sortPlugins, splitInHalf, startSpan, streamToAsyncIteratorObject, toOtelException, toSpanAttributeValue, toStringOrBytes, traceAsyncIterator, traceReadableStream, tryDecodeURIComponent, tryOrUndefined, value, varyByAcceptEncoding, wrapAsyncIterator, wrapReadableStream };
|