@orpc/shared 2.0.0-beta.3 → 2.0.0-beta.30

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/dist/index.mjs CHANGED
@@ -1,5 +1,5 @@
1
- import { AbortError, AsyncIteratorClass, isTypescriptObject, getOrBind } from '@standardserver/shared';
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
- async function toStringOrBytes(source) {
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 loadBytes(new Blob(source));
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 compareSequentialIds(a, b) {
161
- if (a.length !== b.length) {
162
- return a.length - b.length;
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 a < b ? -1 : a > b ? 1 : 0;
191
+ return qualities;
165
192
  }
166
-
167
- function onStart(callback) {
168
- return async (options, ...rest) => {
169
- await callback(options, ...rest);
170
- return await options.next();
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
- function onError(callback) {
181
- return async (options, ...rest) => {
182
- try {
183
- return await options.next();
184
- } catch (error) {
185
- await callback(error, options, ...rest);
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
- function onFinish(callback) {
191
- let state;
192
- return async (options, ...rest) => {
193
- try {
194
- const result = await options.next();
195
- state = [null, result, true];
196
- return result;
197
- } catch (error) {
198
- state = [error, void 0, false];
199
- throw error;
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
- function intercept(interceptors, options, main) {
206
- if (!interceptors?.length) {
207
- return main(options);
218
+
219
+ function compareSequentialIds(a, b) {
220
+ if (a.length !== b.length) {
221
+ return a.length - b.length;
208
222
  }
209
- const next = (options2, index) => {
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;
@@ -523,7 +585,7 @@ function isPlainObject(value) {
523
585
  function get(object, path) {
524
586
  let current = object;
525
587
  for (const key of path) {
526
- if (!isTypescriptObject(current)) {
588
+ if (!isTypescriptObject(current) || !Object.hasOwn(current, key)) {
527
589
  return void 0;
528
590
  }
529
591
  current = current[key];
@@ -534,13 +596,41 @@ function set(root, path, value) {
534
596
  let current = root;
535
597
  for (let i = 0; i < path.length - 1; i++) {
536
598
  const key = path[i];
537
- const next = current[key];
599
+ const next = Object.hasOwn(current, key) ? current[key] : void 0;
538
600
  if (!isTypescriptObject(next)) {
539
- current[key] = {};
601
+ const child = {};
602
+ defineOwnProperty(current, key, child);
603
+ current = child;
604
+ } else {
605
+ current = next;
606
+ }
607
+ }
608
+ defineOwnProperty(current, path.at(-1), value);
609
+ }
610
+ function defineOwnProperty(object, key, value) {
611
+ Object.defineProperty(object, key, {
612
+ value,
613
+ writable: true,
614
+ enumerable: true,
615
+ configurable: true
616
+ });
617
+ }
618
+ function mergeTwoLevels(first, second) {
619
+ if (!isPlainObject(first) || !isPlainObject(second)) {
620
+ return second;
621
+ }
622
+ const result = { ...first, ...second };
623
+ for (const key in second) {
624
+ if (!Object.hasOwn(first, key)) {
625
+ continue;
626
+ }
627
+ const firstValue = first[key];
628
+ const secondValue = second[key];
629
+ if (isPlainObject(firstValue) && isPlainObject(secondValue)) {
630
+ defineOwnProperty(result, key, { ...firstValue, ...secondValue });
540
631
  }
541
- current = current[key];
542
632
  }
543
- current[path.at(-1)] = value;
633
+ return result;
544
634
  }
545
635
  function omit(obj, keys) {
546
636
  const result = { ...obj };
@@ -556,10 +646,10 @@ function clone(value) {
556
646
  if (isPlainObject(value)) {
557
647
  const result = {};
558
648
  for (const key in value) {
559
- result[key] = clone(value[key]);
649
+ defineOwnProperty(result, key, clone(value[key]));
560
650
  }
561
651
  for (const sym of Object.getOwnPropertySymbols(value)) {
562
- result[sym] = clone(value[sym]);
652
+ defineOwnProperty(result, sym, clone(value[sym]));
563
653
  }
564
654
  return result;
565
655
  }
@@ -576,7 +666,8 @@ const NullProtoObj = /* @__PURE__ */ (() => {
576
666
  Object.freeze(e.prototype);
577
667
  return e;
578
668
  })();
579
- function bindMethods(obj) {
669
+ function bindMethods(obj, options = {}) {
670
+ const unbound = new Set(options.unbound);
580
671
  const methods = new NullProtoObj();
581
672
  let current = obj;
582
673
  while (current && current !== Object.prototype) {
@@ -584,18 +675,18 @@ function bindMethods(obj) {
584
675
  if (key === "constructor" || key in methods) {
585
676
  continue;
586
677
  }
587
- const val = obj[key];
678
+ const val = getOrBind(obj, key, { bind: !unbound.has(key) });
588
679
  if (typeof val === "function") {
589
- methods[key] = val.bind(obj);
680
+ methods[key] = val;
590
681
  }
591
682
  }
592
683
  for (const sym of Object.getOwnPropertySymbols(current)) {
593
684
  if (sym in methods) {
594
685
  continue;
595
686
  }
596
- const val = obj[sym];
687
+ const val = getOrBind(obj, sym, { bind: !unbound.has(sym) });
597
688
  if (typeof val === "function") {
598
- methods[sym] = val.bind(obj);
689
+ methods[sym] = val;
599
690
  }
600
691
  }
601
692
  current = Object.getPrototypeOf(current);
@@ -603,84 +694,6 @@ function bindMethods(obj) {
603
694
  return methods;
604
695
  }
605
696
 
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
697
  function promiseWithResolvers() {
685
698
  const result = {};
686
699
  result.promise = new Promise((resolve, reject) => {
@@ -690,69 +703,6 @@ function promiseWithResolvers() {
690
703
  return result;
691
704
  }
692
705
 
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
706
  function replicateReadableStream(stream, count) {
757
707
  if (count <= 0) {
758
708
  return [];
@@ -823,7 +773,7 @@ function traceReadableStream(options, stream) {
823
773
  }
824
774
  });
825
775
  }
826
- function streamToAsyncIteratorClass(stream, { signal } = {}) {
776
+ function streamToAsyncIteratorObject(stream, { signal } = {}) {
827
777
  const reader = stream.getReader();
828
778
  let cancelledBySignal = false;
829
779
  return new AsyncIteratorClass(
@@ -889,4 +839,228 @@ function asyncIteratorToUnproxiedDataStream(iterator) {
889
839
  });
890
840
  }
891
841
 
892
- export { AsyncIdQueue, NullProtoObj, ORPC_NAME, allAbortSignal, asyncIteratorToStream, asyncIteratorToUnproxiedDataStream, bindMethods, clone, compareSequentialIds, defer, findDeepMatches, get, getConstructor, getOpenTelemetryConfig, intercept, isAbortError, isDeepEqual, isPlainObject, isPropertyKey, loadBytes, matchesHttpPath, matchesHttpPathPrefix, mergeHttpPath, normalizeHttpPath, omit, onError, onFinish, onStart, onSuccess, once, override, pathToHttpPath, promiseWithResolvers, recordSpanError, replicateAsyncIterator, replicateReadableStream, resolveMaybeOptionalOptions, runInSpanContext, runWithSignal, runWithSpan, set, setOpenTelemetryConfig, setSpanAttributeIfDefined, sortPlugins, splitInHalf, startSpan, streamToAsyncIteratorClass, toOtelException, toSpanAttributeValue, toStringOrBytes, traceAsyncIterator, traceReadableStream, tryDecodeURIComponent, tryOrUndefined, value, wrapAsyncIterator, wrapReadableStream };
842
+ function onStart(callback) {
843
+ return async (options, ...rest) => {
844
+ await callback(options, ...rest);
845
+ return await options.next();
846
+ };
847
+ }
848
+ function onSuccess(callback) {
849
+ return async (options, ...rest) => {
850
+ const result = await options.next();
851
+ await callback(result, options, ...rest);
852
+ return result;
853
+ };
854
+ }
855
+ function onError(callback) {
856
+ return async (options, ...rest) => {
857
+ try {
858
+ return await options.next();
859
+ } catch (error) {
860
+ await callback(error, options, ...rest);
861
+ throw error;
862
+ }
863
+ };
864
+ }
865
+ function onFinish(callback) {
866
+ let state;
867
+ return async (options, ...rest) => {
868
+ try {
869
+ const result = await options.next();
870
+ state = [null, result, true];
871
+ return result;
872
+ } catch (error) {
873
+ state = [error, void 0, false];
874
+ throw error;
875
+ } finally {
876
+ await callback(state, options, ...rest);
877
+ }
878
+ };
879
+ }
880
+ function onAsyncIteratorObjectError(callback) {
881
+ return async (options, ...rest) => {
882
+ const output = await options.next();
883
+ if (!isAsyncIteratorObject(output)) {
884
+ return output;
885
+ }
886
+ return override(output, wrapAsyncIterator(output, {
887
+ onError: (error) => callback(error, options, ...rest)
888
+ }));
889
+ };
890
+ }
891
+ function onReadableStreamError(callback) {
892
+ return async (options, ...rest) => {
893
+ const output = await options.next();
894
+ if (!(output instanceof ReadableStream)) {
895
+ return output;
896
+ }
897
+ return override(output, wrapReadableStream(output, {
898
+ onError: (error) => callback(error, options, ...rest)
899
+ }));
900
+ };
901
+ }
902
+ function intercept(interceptors, options, main) {
903
+ if (!interceptors?.length) {
904
+ return main(options);
905
+ }
906
+ const next = (options2, index) => {
907
+ const interceptor = interceptors[index];
908
+ if (!interceptor) {
909
+ return main(options2);
910
+ }
911
+ return interceptor({
912
+ ...options2,
913
+ next: (newOptions = options2) => next(newOptions, index + 1)
914
+ });
915
+ };
916
+ return next(options, 0);
917
+ }
918
+
919
+ function sortPlugins(plugins) {
920
+ const pluginCount = plugins.length;
921
+ const pluginIdToIndices = /* @__PURE__ */ new Map();
922
+ for (let i = 0; i < pluginCount; i++) {
923
+ const plugin = plugins[i];
924
+ const indices = pluginIdToIndices.get(plugin.name);
925
+ if (indices === void 0) {
926
+ pluginIdToIndices.set(plugin.name, [i]);
927
+ } else {
928
+ indices.push(i);
929
+ }
930
+ }
931
+ const graph = Array.from(
932
+ { length: pluginCount },
933
+ () => /* @__PURE__ */ new Set()
934
+ );
935
+ for (let i = 0; i < pluginCount; i++) {
936
+ const plugin = plugins[i];
937
+ const beforeList = plugin.before;
938
+ if (beforeList !== void 0) {
939
+ for (const beforeId of beforeList) {
940
+ const beforeIndices = pluginIdToIndices.get(beforeId);
941
+ if (beforeIndices === void 0)
942
+ continue;
943
+ for (const beforeIndex of beforeIndices) {
944
+ const beforeGraph = graph[beforeIndex];
945
+ if (beforeGraph !== void 0) {
946
+ beforeGraph.add(i);
947
+ }
948
+ }
949
+ }
950
+ }
951
+ const afterList = plugin.after;
952
+ if (afterList !== void 0) {
953
+ const currentGraph = graph[i];
954
+ if (currentGraph !== void 0) {
955
+ for (const afterId of afterList) {
956
+ const afterIndices = pluginIdToIndices.get(afterId);
957
+ if (afterIndices === void 0)
958
+ continue;
959
+ for (const afterIndex of afterIndices) {
960
+ currentGraph.add(afterIndex);
961
+ }
962
+ }
963
+ }
964
+ }
965
+ }
966
+ const sorted = [];
967
+ const visiting = /* @__PURE__ */ new Set();
968
+ const visited = /* @__PURE__ */ new Set();
969
+ function visit(index) {
970
+ if (visited.has(index))
971
+ return;
972
+ if (visiting.has(index)) {
973
+ const plugin2 = plugins[index];
974
+ const pluginId = plugin2 !== void 0 ? plugin2.name : "unknown";
975
+ throw new Error(`Circular dependency detected involving plugin "${pluginId}"`);
976
+ }
977
+ visiting.add(index);
978
+ const deps = graph[index];
979
+ if (deps !== void 0) {
980
+ for (const depIndex of deps) {
981
+ visit(depIndex);
982
+ }
983
+ }
984
+ visiting.delete(index);
985
+ visited.add(index);
986
+ const plugin = plugins[index];
987
+ if (plugin !== void 0) {
988
+ sorted.push(plugin);
989
+ }
990
+ }
991
+ for (let i = 0; i < pluginCount; i++) {
992
+ visit(i);
993
+ }
994
+ return sorted;
995
+ }
996
+
997
+ function allAbortSignal(signals) {
998
+ const realSignals = signals.filter((signal) => signal !== void 0);
999
+ if (realSignals.length === 0 || realSignals.length !== signals.length) {
1000
+ return void 0;
1001
+ }
1002
+ const controller = new AbortController();
1003
+ const abortIfAllAborted = () => {
1004
+ if (realSignals.every((signal) => signal.aborted)) {
1005
+ controller.abort();
1006
+ }
1007
+ };
1008
+ abortIfAllAborted();
1009
+ for (const signal of realSignals) {
1010
+ signal.addEventListener("abort", () => {
1011
+ abortIfAllAborted();
1012
+ }, {
1013
+ once: true,
1014
+ signal: controller.signal
1015
+ });
1016
+ }
1017
+ return controller.signal;
1018
+ }
1019
+ function anyAbortSignal(signals) {
1020
+ const realSignals = signals.filter((signal) => signal !== void 0);
1021
+ if (realSignals.length === 0) {
1022
+ return void 0;
1023
+ }
1024
+ if (realSignals.length === 1) {
1025
+ return realSignals[0];
1026
+ }
1027
+ if (typeof AbortSignal.any === "function") {
1028
+ return AbortSignal.any(realSignals);
1029
+ }
1030
+ const controller = new AbortController();
1031
+ for (const signal of realSignals) {
1032
+ if (signal.aborted) {
1033
+ controller.abort(signal.reason);
1034
+ break;
1035
+ }
1036
+ signal.addEventListener("abort", () => {
1037
+ controller.abort(signal.reason);
1038
+ }, {
1039
+ once: true,
1040
+ signal: controller.signal
1041
+ });
1042
+ }
1043
+ return controller.signal;
1044
+ }
1045
+ async function runWithSignal(signal, fn) {
1046
+ if (!signal) {
1047
+ return fn();
1048
+ }
1049
+ signal.throwIfAborted();
1050
+ const { promise, reject, resolve } = promiseWithResolvers();
1051
+ let abortListener;
1052
+ signal.addEventListener("abort", abortListener = () => {
1053
+ reject(signal.reason);
1054
+ abortListener = void 0;
1055
+ });
1056
+ try {
1057
+ fn().then(resolve, reject);
1058
+ return await promise;
1059
+ } finally {
1060
+ if (abortListener) {
1061
+ signal.removeEventListener("abort", abortListener);
1062
+ }
1063
+ }
1064
+ }
1065
+
1066
+ export { AsyncIdQueue, NullProtoObj, ORPC_NAME, allAbortSignal, anyAbortSignal, asyncIteratorToStream, asyncIteratorToUnproxiedDataStream, bindMethods, clone, compareSequentialIds, consumeAsyncIterator, defer, findDeepMatches, get, getConstructor, getConstructors, getOpenTelemetryConfig, 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 };