@orpc/shared 2.0.0-beta.36 → 2.0.0-beta.37

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.d.mts CHANGED
@@ -1,7 +1,7 @@
1
1
  import { Arrayable, Promisable } from 'type-fest';
2
2
  export { Arrayable, IsEqual, PartialDeep, Promisable, Writable } from 'type-fest';
3
3
  import { AsyncIteratorClass } from '@standard-server/shared';
4
- export { AbortError, AsyncCleanupFn, AsyncIteratorClass, AsyncIteratorClassNextFn, SequentialIdGenerator, getOrBind, isAsyncIteratorObject, isTypescriptObject, parseEmptyableJSON, sequential, sleep, stringifyJSON, toArray } from '@standard-server/shared';
4
+ export { AbortError, AsyncCleanupFn, AsyncIteratorClass, AsyncIteratorClassNextFn, SequentialIdGenerator, getOrBind, isAsyncIteratorObject, isTypescriptObject, parseEmptyableJSON, safeDecodeURIComponent, safeEncodeURIComponent, sequential, sleep, stringifyJSON, toArray } from '@standard-server/shared';
5
5
 
6
6
  type MaybeOptionalOptions<TOptions> = object extends TOptions ? [options?: TOptions] : [options: TOptions];
7
7
  declare function resolveMaybeOptionalOptions<T>(rest: MaybeOptionalOptions<T>): T;
@@ -452,14 +452,5 @@ declare function asyncIteratorToStream<T>(iterator: AsyncIterator<T>): ReadableS
452
452
  */
453
453
  declare function asyncIteratorToUnproxiedDataStream<T>(iterator: AsyncIterator<T>): ReadableStream<T>;
454
454
 
455
- /**
456
- * `encodeURIComponent` that never throws, lone surrogates become U+FFFD.
457
- */
458
- declare function safeEncodeURIComponent(value: string): string;
459
- /**
460
- * `decodeURIComponent` that never throws, malformed input is returned unchanged.
461
- */
462
- declare function safeDecodeURIComponent(value: string): string;
463
-
464
- export { AsyncIdQueue, NullProtoObj, ORPC_NAME, allAbortSignal, anyAbortSignal, asyncIteratorToStream, asyncIteratorToUnproxiedDataStream, bindMethods, clone, compareSequentialIds, consumeAsyncIterator, defer, findDeepMatches, get, getConstructor, getConstructors, getOwn, getTracer, intercept, isAbortError, isAsyncGeneratorFunction, 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, safeDecodeURIComponent, safeEncodeURIComponent, set, setOwn, setSpanAttributeIfDefined, setTracer, sortPlugins, splitInHalf, startSpan, streamToAsyncIteratorObject, toSpanAttributeValue, toStringOrBytes, toTracingException, traceAsyncIterator, traceReadableStream, tryOrUndefined, value, varyByAcceptEncoding, wrapAsyncIterator, wrapReadableStream };
455
+ export { AsyncIdQueue, NullProtoObj, ORPC_NAME, allAbortSignal, anyAbortSignal, asyncIteratorToStream, asyncIteratorToUnproxiedDataStream, bindMethods, clone, compareSequentialIds, consumeAsyncIterator, defer, findDeepMatches, get, getConstructor, getConstructors, getOwn, getTracer, intercept, isAbortError, isAsyncGeneratorFunction, 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, setOwn, setSpanAttributeIfDefined, setTracer, sortPlugins, splitInHalf, startSpan, streamToAsyncIteratorObject, toSpanAttributeValue, toStringOrBytes, toTracingException, traceAsyncIterator, traceReadableStream, tryOrUndefined, value, varyByAcceptEncoding, wrapAsyncIterator, wrapReadableStream };
465
456
  export type { AnyFunction, AsyncIdQueueCloseOptions, ConsumeAsyncIteratorOptions, InterceptableOptions, Interceptor, InterceptorOptions, IntersectPick, MaybeOptionalOptions, OnFinishState, OrderablePlugin, PromiseWithError, Public, ReadableStreamReadResult, Registry, Segment, StartSpanOptions, ThrowableError, Tracer, TracingAttributeValue, TracingException, TracingExceptionLevel, TracingHeaders, TracingSpan, Value, WrapAsyncIteratorOptions, WrapReadableStreamOptions };
package/dist/index.d.ts CHANGED
@@ -1,7 +1,7 @@
1
1
  import { Arrayable, Promisable } from 'type-fest';
2
2
  export { Arrayable, IsEqual, PartialDeep, Promisable, Writable } from 'type-fest';
3
3
  import { AsyncIteratorClass } from '@standard-server/shared';
4
- export { AbortError, AsyncCleanupFn, AsyncIteratorClass, AsyncIteratorClassNextFn, SequentialIdGenerator, getOrBind, isAsyncIteratorObject, isTypescriptObject, parseEmptyableJSON, sequential, sleep, stringifyJSON, toArray } from '@standard-server/shared';
4
+ export { AbortError, AsyncCleanupFn, AsyncIteratorClass, AsyncIteratorClassNextFn, SequentialIdGenerator, getOrBind, isAsyncIteratorObject, isTypescriptObject, parseEmptyableJSON, safeDecodeURIComponent, safeEncodeURIComponent, sequential, sleep, stringifyJSON, toArray } from '@standard-server/shared';
5
5
 
6
6
  type MaybeOptionalOptions<TOptions> = object extends TOptions ? [options?: TOptions] : [options: TOptions];
7
7
  declare function resolveMaybeOptionalOptions<T>(rest: MaybeOptionalOptions<T>): T;
@@ -452,14 +452,5 @@ declare function asyncIteratorToStream<T>(iterator: AsyncIterator<T>): ReadableS
452
452
  */
453
453
  declare function asyncIteratorToUnproxiedDataStream<T>(iterator: AsyncIterator<T>): ReadableStream<T>;
454
454
 
455
- /**
456
- * `encodeURIComponent` that never throws, lone surrogates become U+FFFD.
457
- */
458
- declare function safeEncodeURIComponent(value: string): string;
459
- /**
460
- * `decodeURIComponent` that never throws, malformed input is returned unchanged.
461
- */
462
- declare function safeDecodeURIComponent(value: string): string;
463
-
464
- export { AsyncIdQueue, NullProtoObj, ORPC_NAME, allAbortSignal, anyAbortSignal, asyncIteratorToStream, asyncIteratorToUnproxiedDataStream, bindMethods, clone, compareSequentialIds, consumeAsyncIterator, defer, findDeepMatches, get, getConstructor, getConstructors, getOwn, getTracer, intercept, isAbortError, isAsyncGeneratorFunction, 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, safeDecodeURIComponent, safeEncodeURIComponent, set, setOwn, setSpanAttributeIfDefined, setTracer, sortPlugins, splitInHalf, startSpan, streamToAsyncIteratorObject, toSpanAttributeValue, toStringOrBytes, toTracingException, traceAsyncIterator, traceReadableStream, tryOrUndefined, value, varyByAcceptEncoding, wrapAsyncIterator, wrapReadableStream };
455
+ export { AsyncIdQueue, NullProtoObj, ORPC_NAME, allAbortSignal, anyAbortSignal, asyncIteratorToStream, asyncIteratorToUnproxiedDataStream, bindMethods, clone, compareSequentialIds, consumeAsyncIterator, defer, findDeepMatches, get, getConstructor, getConstructors, getOwn, getTracer, intercept, isAbortError, isAsyncGeneratorFunction, 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, setOwn, setSpanAttributeIfDefined, setTracer, sortPlugins, splitInHalf, startSpan, streamToAsyncIteratorObject, toSpanAttributeValue, toStringOrBytes, toTracingException, traceAsyncIterator, traceReadableStream, tryOrUndefined, value, varyByAcceptEncoding, wrapAsyncIterator, wrapReadableStream };
465
456
  export type { AnyFunction, AsyncIdQueueCloseOptions, ConsumeAsyncIteratorOptions, InterceptableOptions, Interceptor, InterceptorOptions, IntersectPick, MaybeOptionalOptions, OnFinishState, OrderablePlugin, PromiseWithError, Public, ReadableStreamReadResult, Registry, Segment, StartSpanOptions, ThrowableError, Tracer, TracingAttributeValue, TracingException, TracingExceptionLevel, TracingHeaders, TracingSpan, Value, WrapAsyncIteratorOptions, WrapReadableStreamOptions };
package/dist/index.mjs CHANGED
@@ -1,5 +1,5 @@
1
- import { AbortError, AsyncIteratorClass, getOrBind, isTypescriptObject, isAsyncIteratorObject } from '@standard-server/shared';
2
- export { AbortError, AsyncIteratorClass, SequentialIdGenerator, getOrBind, isAsyncIteratorObject, isTypescriptObject, parseEmptyableJSON, sequential, sleep, stringifyJSON, toArray } from '@standard-server/shared';
1
+ import { safeDecodeURIComponent, safeEncodeURIComponent, AbortError, AsyncIteratorClass, getOrBind, isTypescriptObject, isAsyncIteratorObject } from '@standard-server/shared';
2
+ export { AbortError, AsyncIteratorClass, SequentialIdGenerator, getOrBind, isAsyncIteratorObject, isTypescriptObject, parseEmptyableJSON, safeDecodeURIComponent, safeEncodeURIComponent, sequential, sleep, stringifyJSON, toArray } from '@standard-server/shared';
3
3
 
4
4
  function resolveMaybeOptionalOptions(rest) {
5
5
  return rest[0] ?? {};
@@ -142,25 +142,6 @@ function tryOrUndefined(fn) {
142
142
  }
143
143
  }
144
144
 
145
- const LONE_SURROGATE_REGEX = /[\uD800-\uDBFF](?![\uDC00-\uDFFF])|(?<![\uD800-\uDBFF])[\uDC00-\uDFFF]/g;
146
- function safeEncodeURIComponent(value) {
147
- try {
148
- return encodeURIComponent(value);
149
- } catch {
150
- return encodeURIComponent(value.replace(LONE_SURROGATE_REGEX, "\uFFFD"));
151
- }
152
- }
153
- function safeDecodeURIComponent(value) {
154
- if (!value.includes("%")) {
155
- return value;
156
- }
157
- try {
158
- return decodeURIComponent(value);
159
- } catch {
160
- return value;
161
- }
162
- }
163
-
164
145
  function pathToHttpPath(path) {
165
146
  return `/${path.map(safeEncodeURIComponent).join("/")}`;
166
147
  }
@@ -554,8 +535,8 @@ function findDeepMatches(check, payload, segments = [], maps = [], values = [])
554
535
  findDeepMatches(check, v, [...segments, i], maps, values);
555
536
  });
556
537
  } else if (isPlainObject(payload)) {
557
- for (const [key, value] of Object.entries(payload)) {
558
- findDeepMatches(check, value, [...segments, key], maps, values);
538
+ for (const key of Object.keys(payload)) {
539
+ findDeepMatches(check, payload[key], [...segments, key], maps, values);
559
540
  }
560
541
  }
561
542
  return { maps, values };
@@ -630,14 +611,14 @@ function mergeTwoLevels(first, second) {
630
611
  return second;
631
612
  }
632
613
  const result = { ...first, ...second };
633
- for (const key in second) {
614
+ for (const key of Object.keys(second)) {
634
615
  if (!Object.hasOwn(first, key)) {
635
616
  continue;
636
617
  }
637
618
  const firstValue = first[key];
638
619
  const secondValue = second[key];
639
620
  if (isPlainObject(firstValue) && isPlainObject(secondValue)) {
640
- setOwn(result, key, { ...firstValue, ...secondValue });
621
+ result[key] = { ...firstValue, ...secondValue };
641
622
  }
642
623
  }
643
624
  return result;
@@ -672,8 +653,8 @@ function cloneWithVisited(value, visited) {
672
653
  }
673
654
  const result = {};
674
655
  visited.set(value, result);
675
- for (const [key, item] of Object.entries(value)) {
676
- setOwn(result, key, cloneWithVisited(item, visited));
656
+ for (const key of Object.keys(value)) {
657
+ setOwn(result, key, cloneWithVisited(value[key], visited));
677
658
  }
678
659
  for (const sym of Object.getOwnPropertySymbols(value)) {
679
660
  setOwn(result, sym, cloneWithVisited(value[sym], visited));
@@ -955,71 +936,51 @@ function sortPlugins(plugins) {
955
936
  indices.push(i);
956
937
  }
957
938
  }
958
- const graph = Array.from(
959
- { length: pluginCount },
960
- () => /* @__PURE__ */ new Set()
961
- );
939
+ const dependencies = Array.from({ length: pluginCount }, () => []);
962
940
  for (let i = 0; i < pluginCount; i++) {
963
941
  const plugin = plugins[i];
964
- const beforeList = plugin.before;
965
- if (beforeList !== void 0) {
966
- for (const beforeId of beforeList) {
942
+ if (plugin.before !== void 0) {
943
+ for (const beforeId of plugin.before) {
967
944
  const beforeIndices = pluginIdToIndices.get(beforeId);
968
- if (beforeIndices === void 0)
969
- continue;
970
- for (const beforeIndex of beforeIndices) {
971
- const beforeGraph = graph[beforeIndex];
972
- if (beforeGraph !== void 0) {
973
- beforeGraph.add(i);
945
+ if (beforeIndices !== void 0) {
946
+ for (const beforeIndex of beforeIndices) {
947
+ dependencies[beforeIndex].push(i);
974
948
  }
975
949
  }
976
950
  }
977
951
  }
978
- const afterList = plugin.after;
979
- if (afterList !== void 0) {
980
- const currentGraph = graph[i];
981
- if (currentGraph !== void 0) {
982
- for (const afterId of afterList) {
983
- const afterIndices = pluginIdToIndices.get(afterId);
984
- if (afterIndices === void 0)
985
- continue;
952
+ if (plugin.after !== void 0) {
953
+ for (const afterId of plugin.after) {
954
+ const afterIndices = pluginIdToIndices.get(afterId);
955
+ if (afterIndices !== void 0) {
986
956
  for (const afterIndex of afterIndices) {
987
- currentGraph.add(afterIndex);
957
+ dependencies[i].push(afterIndex);
988
958
  }
989
959
  }
990
960
  }
991
961
  }
992
962
  }
993
963
  const sorted = [];
994
- const visiting = /* @__PURE__ */ new Set();
995
- const visited = /* @__PURE__ */ new Set();
996
- function visit(index) {
997
- if (visited.has(index))
998
- return;
999
- if (visiting.has(index)) {
1000
- const plugin2 = plugins[index];
1001
- const pluginId = plugin2 !== void 0 ? plugin2.name : "unknown";
1002
- throw new Error(`Circular dependency detected involving plugin "${pluginId}"`);
1003
- }
1004
- visiting.add(index);
1005
- const deps = graph[index];
1006
- if (deps !== void 0) {
1007
- for (const depIndex of deps) {
1008
- visit(depIndex);
1009
- }
1010
- }
1011
- visiting.delete(index);
1012
- visited.add(index);
1013
- const plugin = plugins[index];
1014
- if (plugin !== void 0) {
1015
- sorted.push(plugin);
964
+ const placed = /* @__PURE__ */ new Set();
965
+ while (sorted.length < pluginCount) {
966
+ const next = plugins.findIndex((_, i) => !placed.has(i) && dependencies[i].every((dependency) => placed.has(dependency)));
967
+ if (next === -1) {
968
+ throw new Error(`Circular dependency detected involving plugin "${findCyclicPlugin(plugins, dependencies, placed).name}"`);
1016
969
  }
1017
- }
1018
- for (let i = 0; i < pluginCount; i++) {
1019
- visit(i);
970
+ placed.add(next);
971
+ sorted.push(plugins[next]);
1020
972
  }
1021
973
  return sorted;
1022
974
  }
975
+ function findCyclicPlugin(plugins, dependencies, placed) {
976
+ const seen = /* @__PURE__ */ new Set();
977
+ let current = plugins.findIndex((_, i) => !placed.has(i));
978
+ while (!seen.has(current)) {
979
+ seen.add(current);
980
+ current = dependencies[current].find((dependency) => !placed.has(dependency));
981
+ }
982
+ return plugins[current];
983
+ }
1023
984
 
1024
985
  function allAbortSignal(signals) {
1025
986
  const realSignals = signals.filter((signal) => signal !== void 0);
@@ -1090,4 +1051,4 @@ async function runWithSignal(signal, fn) {
1090
1051
  }
1091
1052
  }
1092
1053
 
1093
- export { AsyncIdQueue, NullProtoObj, ORPC_NAME, allAbortSignal, anyAbortSignal, asyncIteratorToStream, asyncIteratorToUnproxiedDataStream, bindMethods, clone, compareSequentialIds, consumeAsyncIterator, defer, findDeepMatches, get, getConstructor, getConstructors, getOwn, getTracer, intercept, isAbortError, isAsyncGeneratorFunction, 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, safeDecodeURIComponent, safeEncodeURIComponent, set, setOwn, setSpanAttributeIfDefined, setTracer, sortPlugins, splitInHalf, startSpan, streamToAsyncIteratorObject, toSpanAttributeValue, toStringOrBytes, toTracingException, traceAsyncIterator, traceReadableStream, tryOrUndefined, value, varyByAcceptEncoding, wrapAsyncIterator, wrapReadableStream };
1054
+ export { AsyncIdQueue, NullProtoObj, ORPC_NAME, allAbortSignal, anyAbortSignal, asyncIteratorToStream, asyncIteratorToUnproxiedDataStream, bindMethods, clone, compareSequentialIds, consumeAsyncIterator, defer, findDeepMatches, get, getConstructor, getConstructors, getOwn, getTracer, intercept, isAbortError, isAsyncGeneratorFunction, 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, setOwn, setSpanAttributeIfDefined, setTracer, sortPlugins, splitInHalf, startSpan, streamToAsyncIteratorObject, toSpanAttributeValue, toStringOrBytes, toTracingException, traceAsyncIterator, traceReadableStream, tryOrUndefined, value, varyByAcceptEncoding, wrapAsyncIterator, wrapReadableStream };
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@orpc/shared",
3
3
  "type": "module",
4
- "version": "2.0.0-beta.36",
4
+ "version": "2.0.0-beta.37",
5
5
  "description": "Internal utilities shared across oRPC packages",
6
6
  "license": "MIT",
7
7
  "funding": [
@@ -30,7 +30,7 @@
30
30
  "dist"
31
31
  ],
32
32
  "dependencies": {
33
- "@standard-server/shared": "~0.9.0",
33
+ "@standard-server/shared": "~0.9.2",
34
34
  "radash": "^12.1.1",
35
35
  "type-fest": "^5.3.1"
36
36
  },