@orpc/shared 2.0.0-beta.49 → 2.0.0-beta.50

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.
Files changed (49) hide show
  1. package/dist/args.d.ts +1 -1
  2. package/dist/args.js +4 -2
  3. package/dist/array.d.ts +4 -1
  4. package/dist/array.js +11 -5
  5. package/dist/bigint.d.ts +1 -1
  6. package/dist/bigint.js +12 -16
  7. package/dist/buffer.d.ts +4 -4
  8. package/dist/buffer.js +44 -67
  9. package/dist/compare.d.ts +1 -1
  10. package/dist/compare.js +23 -42
  11. package/dist/consts.d.ts +1 -1
  12. package/dist/consts.js +3 -1
  13. package/dist/error.d.ts +1 -1
  14. package/dist/error.js +4 -2
  15. package/dist/function.d.ts +1 -1
  16. package/dist/function.js +27 -32
  17. package/dist/http.d.ts +29 -0
  18. package/dist/http.js +128 -94
  19. package/dist/id.d.ts +1 -1
  20. package/dist/id.js +11 -11
  21. package/dist/index.d.ts +26 -34
  22. package/dist/index.js +23 -32
  23. package/dist/interceptor.d.ts +17 -17
  24. package/dist/interceptor.js +106 -126
  25. package/dist/iterator.d.ts +41 -41
  26. package/dist/iterator.js +136 -152
  27. package/dist/object.d.ts +10 -8
  28. package/dist/object.js +176 -227
  29. package/dist/plugin.d.ts +7 -7
  30. package/dist/plugin.js +41 -57
  31. package/dist/promise.d.ts +4 -4
  32. package/dist/promise.js +28 -28
  33. package/dist/proxy.d.ts +2 -2
  34. package/dist/proxy.js +23 -22
  35. package/dist/queue.d.ts +13 -13
  36. package/dist/queue.js +64 -79
  37. package/dist/regex.d.ts +9 -0
  38. package/dist/regex.js +11 -0
  39. package/dist/signal.d.ts +7 -2
  40. package/dist/signal.js +83 -80
  41. package/dist/stream.d.ts +23 -23
  42. package/dist/stream.js +118 -144
  43. package/dist/tracing.d.ts +50 -50
  44. package/dist/tracing.js +60 -85
  45. package/dist/types.d.ts +7 -10
  46. package/dist/value.d.ts +1 -1
  47. package/dist/value.js +5 -5
  48. package/package.json +2 -2
  49. package/dist/types.js +0 -1
package/dist/args.d.ts CHANGED
@@ -1,2 +1,2 @@
1
1
  export type MaybeOptionalOptions<TOptions> = object extends TOptions ? [options?: TOptions] : [options: TOptions];
2
- export declare function resolveMaybeOptionalOptions<T>(rest: MaybeOptionalOptions<T>): T;
2
+ export declare function resolveMaybeOptionalOptions<T>(rest: MaybeOptionalOptions<T>): T;
package/dist/args.js CHANGED
@@ -1,3 +1,5 @@
1
- export function resolveMaybeOptionalOptions(rest) {
2
- return rest[0] ?? {}; // 0 only undefined when all fields are optional
1
+ // src/args.ts
2
+ function resolveMaybeOptionalOptions(rest) {
3
+ return rest[0] ?? {};
3
4
  }
5
+ export { resolveMaybeOptionalOptions };
package/dist/array.d.ts CHANGED
@@ -1,2 +1,5 @@
1
- export declare function toArray<T>(value: T): T extends readonly any[] ? T : Exclude<T, undefined | null>[];
2
1
  export declare function splitInHalf<T>(arr: readonly T[]): [T[], T[]];
2
+ /**
3
+ * Keeps only the last `maxSize` items, returning the same array when it already fits.
4
+ */
5
+ export declare function takeLast<T>(items: T[], maxSize: number): T[];
package/dist/array.js CHANGED
@@ -1,7 +1,13 @@
1
- export function toArray(value) {
2
- return (Array.isArray(value) ? value : value === undefined || value === null ? [] : [value]);
1
+ // src/array.ts
2
+ function splitInHalf(arr) {
3
+ const half = Math.ceil(arr.length / 2);
4
+ return [arr.slice(0, half), arr.slice(half)];
3
5
  }
4
- export function splitInHalf(arr) {
5
- const half = Math.ceil(arr.length / 2);
6
- return [arr.slice(0, half), arr.slice(half)];
6
+ /**
7
+ * Keeps only the last `maxSize` items, returning the same array when it already fits.
8
+ */
9
+ function takeLast(items, maxSize) {
10
+ if (items.length <= maxSize) return items;
11
+ return items.slice(items.length - maxSize);
7
12
  }
13
+ export { splitInHalf, takeLast };
package/dist/bigint.d.ts CHANGED
@@ -6,4 +6,4 @@ export declare const DEFAULT_MAX_BIGINT_DIGITS = 4300;
6
6
  * Parses a `bigint.toString()` string, or returns `undefined` if it is invalid or has more than `maxDigits` digits.
7
7
  * The length is checked first, since `BigInt()` is super-linear in the digit count.
8
8
  */
9
- export declare function parseBigIntString(value: string, maxDigits: number): bigint | undefined;
9
+ export declare function parseBigIntString(value: string, maxDigits: number): bigint | undefined;
package/dist/bigint.js CHANGED
@@ -1,19 +1,15 @@
1
+ import { INTEGER_REGEX } from "./regex.js";
2
+ // src/bigint.ts
1
3
  /**
2
- * Default maximum digits, excluding a leading `-`, when parsing a `bigint` from a string.
3
- */
4
- export const DEFAULT_MAX_BIGINT_DIGITS = 4300;
4
+ * Default maximum digits, excluding a leading `-`, when parsing a `bigint` from a string.
5
+ */
6
+ const DEFAULT_MAX_BIGINT_DIGITS = 4300;
5
7
  /**
6
- * Matches `bigint.toString()` output only.
7
- */
8
- const BIGINT_PATTERN = /^-?(?:0|[1-9]\d*)$/;
9
- /**
10
- * Parses a `bigint.toString()` string, or returns `undefined` if it is invalid or has more than `maxDigits` digits.
11
- * The length is checked first, since `BigInt()` is super-linear in the digit count.
12
- */
13
- export function parseBigIntString(value, maxDigits) {
14
- const digits = value.startsWith('-') ? value.length - 1 : value.length;
15
- if (digits > maxDigits || !BIGINT_PATTERN.test(value)) {
16
- return undefined;
17
- }
18
- return BigInt(value);
8
+ * Parses a `bigint.toString()` string, or returns `undefined` if it is invalid or has more than `maxDigits` digits.
9
+ * The length is checked first, since `BigInt()` is super-linear in the digit count.
10
+ */
11
+ function parseBigIntString(value, maxDigits) {
12
+ if ((value.startsWith("-") ? value.length - 1 : value.length) > maxDigits || !INTEGER_REGEX.test(value)) return;
13
+ return BigInt(value);
19
14
  }
15
+ export { DEFAULT_MAX_BIGINT_DIGITS, parseBigIntString };
package/dist/buffer.d.ts CHANGED
@@ -1,18 +1,18 @@
1
- import type { Arrayable } from 'type-fest';
1
+ import { Arrayable } from "type-fest";
2
2
  /**
3
3
  * Load Request/Response/Blob/File/.. to a buffer (Uint8Array<ArrayBuffer>).
4
4
  *
5
5
  * Prefers the newer `.bytes` method when available as it more efficient but not widely supported yet.
6
6
  */
7
- export declare function loadBytes(source: Pick<Blob, 'arrayBuffer' | 'bytes'>): ReturnType<Blob['bytes']>;
7
+ export declare function loadBytes(source: Pick<Blob, "arrayBuffer" | "bytes">): ReturnType<Blob["bytes"]>;
8
8
  /**
9
9
  * Normalize text or binary-like inputs to either:
10
10
  * - the original string value, or
11
11
  * - a Uint8Array view over the source bytes.
12
12
  */
13
- export declare function toStringOrBytes(source: Arrayable<string | ArrayBuffer | Pick<Uint8Array<ArrayBuffer>, 'buffer' | 'byteOffset' | 'byteLength'>>): string | Awaited<ReturnType<Blob['bytes']>>;
13
+ export declare function toStringOrBytes(source: Arrayable<string | ArrayBuffer | Pick<Uint8Array<ArrayBuffer>, "buffer" | "byteOffset" | "byteLength">>): string | Awaited<ReturnType<Blob["bytes"]>>;
14
14
  /**
15
15
  * Encodes bytes to standard, padded base64, as data URLs and many protocols require.
16
16
  * Prefers the native `toBase64` or `Buffer`, which are far faster for large outputs.
17
17
  */
18
- export declare function encodeBase64(bytes: Uint8Array): string;
18
+ export declare function encodeBase64(bytes: Uint8Array): string;
package/dist/buffer.js CHANGED
@@ -1,77 +1,54 @@
1
+ // src/buffer.ts
1
2
  /**
2
- * Load Request/Response/Blob/File/.. to a buffer (Uint8Array<ArrayBuffer>).
3
- *
4
- * Prefers the newer `.bytes` method when available as it more efficient but not widely supported yet.
5
- */
6
- export async function loadBytes(source) {
7
- // oxlint-disable-next-line no-restricted-properties
8
- if (typeof source.bytes === 'function') {
9
- // oxlint-disable-next-line no-restricted-properties
10
- return source.bytes();
11
- }
12
- return new Uint8Array(await source.arrayBuffer());
3
+ * Load Request/Response/Blob/File/.. to a buffer (Uint8Array<ArrayBuffer>).
4
+ *
5
+ * Prefers the newer `.bytes` method when available as it more efficient but not widely supported yet.
6
+ */
7
+ async function loadBytes(source) {
8
+ if (typeof source.bytes === "function") return source.bytes();
9
+ return new Uint8Array(await source.arrayBuffer());
13
10
  }
14
11
  /**
15
- * Normalize text or binary-like inputs to either:
16
- * - the original string value, or
17
- * - a Uint8Array view over the source bytes.
18
- */
19
- export function toStringOrBytes(source) {
20
- if (typeof source === 'string') {
21
- return source;
22
- }
23
- if (source instanceof ArrayBuffer) {
24
- return new Uint8Array(source);
25
- }
26
- if (Array.isArray(source)) {
27
- return concatBytes(source);
28
- }
29
- if (source instanceof Uint8Array) {
30
- return source;
31
- }
32
- return new Uint8Array(source.buffer, source.byteOffset, source.byteLength);
12
+ * Normalize text or binary-like inputs to either:
13
+ * - the original string value, or
14
+ * - a Uint8Array view over the source bytes.
15
+ */
16
+ function toStringOrBytes(source) {
17
+ if (typeof source === "string") return source;
18
+ if (source instanceof ArrayBuffer) return new Uint8Array(source);
19
+ if (Array.isArray(source)) return concatBytes(source);
20
+ if (source instanceof Uint8Array) return source;
21
+ return new Uint8Array(source.buffer, source.byteOffset, source.byteLength);
33
22
  }
34
23
  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);
24
+ if (typeof item === "string") return new TextEncoder().encode(item);
25
+ if (item instanceof ArrayBuffer) return new Uint8Array(item);
26
+ if (item instanceof Uint8Array) return item;
27
+ return new Uint8Array(item.buffer, item.byteOffset, item.byteLength);
45
28
  }
46
29
  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;
30
+ const chunks = items.map(toBytes);
31
+ const totalLength = chunks.reduce((sum, chunk) => sum + chunk.byteLength, 0);
32
+ const result = new Uint8Array(totalLength);
33
+ let offset = 0;
34
+ for (const chunk of chunks) {
35
+ result.set(chunk, offset);
36
+ offset += chunk.byteLength;
37
+ }
38
+ return result;
56
39
  }
57
40
  /**
58
- * Encodes bytes to standard, padded base64, as data URLs and many protocols require.
59
- * Prefers the native `toBase64` or `Buffer`, which are far faster for large outputs.
60
- */
61
- export function encodeBase64(bytes) {
62
- const native = bytes;
63
- if (typeof native.toBase64 === 'function') {
64
- return native.toBase64();
65
- }
66
- // loaded at runtime, so the package keeps working on runtimes without Node.js built-ins
67
- const NodeBuffer = globalThis.process?.getBuiltinModule?.('node:buffer')?.Buffer;
68
- if (NodeBuffer !== undefined) {
69
- return NodeBuffer.from(bytes.buffer, bytes.byteOffset, bytes.byteLength).toString('base64');
70
- }
71
- const chunkSize = 8192; // 8KB chunks to stay well below call stack limits
72
- let binaryString = '';
73
- for (let i = 0; i < bytes.length; i += chunkSize) {
74
- binaryString += String.fromCharCode(...bytes.subarray(i, i + chunkSize));
75
- }
76
- return btoa(binaryString);
41
+ * Encodes bytes to standard, padded base64, as data URLs and many protocols require.
42
+ * Prefers the native `toBase64` or `Buffer`, which are far faster for large outputs.
43
+ */
44
+ function encodeBase64(bytes) {
45
+ const native = bytes;
46
+ if (typeof native.toBase64 === "function") return native.toBase64();
47
+ const NodeBuffer = globalThis.process?.getBuiltinModule?.("node:buffer")?.Buffer;
48
+ if (NodeBuffer !== void 0) return NodeBuffer.from(bytes.buffer, bytes.byteOffset, bytes.byteLength).toString("base64");
49
+ const chunkSize = 8192;
50
+ let binaryString = "";
51
+ for (let i = 0; i < bytes.length; i += chunkSize) binaryString += String.fromCharCode(...bytes.subarray(i, i + chunkSize));
52
+ return btoa(binaryString);
77
53
  }
54
+ export { encodeBase64, loadBytes, toStringOrBytes };
package/dist/compare.d.ts CHANGED
@@ -1 +1 @@
1
- export declare function isDeepEqual(a: unknown, b: unknown): boolean;
1
+ export declare function isDeepEqual(a: unknown, b: unknown): boolean;
package/dist/compare.js CHANGED
@@ -1,45 +1,26 @@
1
- import { isPlainObject } from './object.js';
2
- export function isDeepEqual(a, b) {
3
- return isDeepEqualInternal(a, b, new WeakMap());
1
+ import { isPlainObject } from "./object.js";
2
+ // src/compare.ts
3
+ function isDeepEqual(a, b) {
4
+ return isDeepEqualInternal(a, b, /* @__PURE__ */ new WeakMap());
4
5
  }
5
6
  function isDeepEqualInternal(a, b, visited) {
6
- if (Object.is(a, b)) {
7
- return true;
8
- }
9
- if (Array.isArray(a)) {
10
- if (!Array.isArray(b) || a.length !== b.length) {
11
- return false;
12
- }
13
- }
14
- else if (!isPlainObject(a) || !isPlainObject(b)) {
15
- // Anything else (primitives, Date, RegExp, Map, Set, class instances, ...) is only equal when Object.is above matched:
16
- // non-plain objects keep their state outside own enumerable keys, so they cannot be compared structurally
17
- return false;
18
- }
19
- const aRecord = a;
20
- const bRecord = b;
21
- const visitedMatches = visited.get(a);
22
- if (visitedMatches?.has(b)) {
23
- return true;
24
- }
25
- if (visitedMatches) {
26
- visitedMatches.add(b);
27
- }
28
- else {
29
- visited.set(a, new WeakSet([b]));
30
- }
31
- const aKeys = Object.keys(aRecord).filter((k) => aRecord[k] !== undefined);
32
- const bKeys = Object.keys(bRecord).filter((k) => bRecord[k] !== undefined);
33
- if (aKeys.length !== bKeys.length) {
34
- return false;
35
- }
36
- for (const key of aKeys) {
37
- if (!Object.hasOwn(bRecord, key)) {
38
- return false;
39
- }
40
- if (!isDeepEqualInternal(aRecord[key], bRecord[key], visited)) {
41
- return false;
42
- }
43
- }
44
- return true;
7
+ if (Object.is(a, b)) return true;
8
+ if (Array.isArray(a)) {
9
+ if (!Array.isArray(b) || a.length !== b.length) return false;
10
+ } else if (!isPlainObject(a) || !isPlainObject(b)) return false;
11
+ const aRecord = a;
12
+ const bRecord = b;
13
+ const visitedMatches = visited.get(a);
14
+ if (visitedMatches?.has(b)) return true;
15
+ if (visitedMatches) visitedMatches.add(b);
16
+ else visited.set(a, new WeakSet([b]));
17
+ const aKeys = Object.keys(aRecord).filter((k) => aRecord[k] !== void 0);
18
+ const bKeys = Object.keys(bRecord).filter((k) => bRecord[k] !== void 0);
19
+ if (aKeys.length !== bKeys.length) return false;
20
+ for (const key of aKeys) {
21
+ if (!Object.hasOwn(bRecord, key)) return false;
22
+ if (!isDeepEqualInternal(aRecord[key], bRecord[key], visited)) return false;
23
+ }
24
+ return true;
45
25
  }
26
+ export { isDeepEqual };
package/dist/consts.d.ts CHANGED
@@ -1 +1 @@
1
- export declare const ORPC_NAME = "orpc";
1
+ export declare const ORPC_NAME = "orpc";
package/dist/consts.js CHANGED
@@ -1 +1,3 @@
1
- export const ORPC_NAME = 'orpc';
1
+ // src/consts.ts
2
+ const ORPC_NAME = "orpc";
3
+ export { ORPC_NAME };
package/dist/error.d.ts CHANGED
@@ -1 +1 @@
1
- export declare function isAbortError(error: unknown): error is Error;
1
+ export declare function isAbortError(error: unknown): error is Error;
package/dist/error.js CHANGED
@@ -1,3 +1,5 @@
1
- export function isAbortError(error) {
2
- return error instanceof Error && error.name.includes('Abort');
1
+ // src/error.ts
2
+ function isAbortError(error) {
3
+ return error instanceof Error && error.name.includes("Abort");
3
4
  }
5
+ export { isAbortError };
@@ -9,4 +9,4 @@ export declare function once<T>(fn: () => T): () => T;
9
9
  * waiting at least `delay` ms when `setTimeout` is available.
10
10
  */
11
11
  export declare function defer(callback: () => void, delay?: number): void;
12
- export declare function tryOrUndefined<T>(fn: () => T): undefined | T;
12
+ export declare function tryOrUndefined<T>(fn: () => T): undefined | T;
package/dist/function.js CHANGED
@@ -1,38 +1,33 @@
1
- const AsyncGeneratorFunction = /* @__PURE__ */ (() => Object.getPrototypeOf(async function* () { }).constructor)();
1
+ // src/function.ts
2
+ const AsyncGeneratorFunction = /* @__PURE__ */ (() => Object.getPrototypeOf(async function* () {}).constructor)();
2
3
  /**
3
- * Checks whether a value is an async generator function (`async function*`).
4
- */
5
- export function isAsyncGeneratorFunction(value) {
6
- return value instanceof AsyncGeneratorFunction;
4
+ * Checks whether a value is an async generator function (`async function*`).
5
+ */
6
+ function isAsyncGeneratorFunction(value) {
7
+ return value instanceof AsyncGeneratorFunction;
7
8
  }
8
- export function once(fn) {
9
- let cached;
10
- return () => {
11
- if (cached) {
12
- return cached.result;
13
- }
14
- const result = fn();
15
- cached = { result };
16
- return result;
17
- };
9
+ function once(fn) {
10
+ let cached;
11
+ return () => {
12
+ if (cached) return cached.result;
13
+ const result = fn();
14
+ cached = { result };
15
+ return result;
16
+ };
18
17
  }
19
18
  /**
20
- * Executes the callback function after the current call stack has been cleared,
21
- * waiting at least `delay` ms when `setTimeout` is available.
22
- */
23
- export function defer(callback, delay = 0) {
24
- if (typeof setTimeout === 'function') {
25
- setTimeout(callback, delay);
26
- }
27
- else {
28
- void Promise.resolve().then(() => Promise.resolve().then(() => Promise.resolve().then(callback)));
29
- }
19
+ * Executes the callback function after the current call stack has been cleared,
20
+ * waiting at least `delay` ms when `setTimeout` is available.
21
+ */
22
+ function defer(callback, delay = 0) {
23
+ if (typeof setTimeout === "function") setTimeout(callback, delay);
24
+ else Promise.resolve().then(() => Promise.resolve().then(() => Promise.resolve().then(callback)));
30
25
  }
31
- export function tryOrUndefined(fn) {
32
- try {
33
- return fn();
34
- }
35
- catch {
36
- return undefined;
37
- }
26
+ function tryOrUndefined(fn) {
27
+ try {
28
+ return fn();
29
+ } catch {
30
+ return;
31
+ }
38
32
  }
33
+ export { defer, isAsyncGeneratorFunction, once, tryOrUndefined };
package/dist/http.d.ts CHANGED
@@ -2,7 +2,35 @@ export declare function pathToHttpPath(path: readonly string[]): `/${string}`;
2
2
  export declare function normalizeHttpPath(path: string): `/${string}`;
3
3
  export declare function mergeHttpPath(a: `/${string}`, b: `/${string}`): `/${string}`;
4
4
  export declare function matchesHttpPathPrefix(url: `/${string}`, prefix: `/${string}`): boolean;
5
+ /**
6
+ * Removes `prefix` from `pathname`, or returns `undefined` when `pathname` is not under `prefix`.
7
+ * The rest of the path must start at a segment boundary, so `/apis` is not under `/api`.
8
+ */
9
+ export declare function stripHttpPathPrefix(pathname: `/${string}`, prefix: `/${string}`): `/${string}` | undefined;
5
10
  export declare function matchesHttpPath(url: `/${string}`, path: `/${string}`): boolean;
11
+ /**
12
+ * Content codings that oRPC compression plugins can encode and decode.
13
+ */
14
+ declare const COMPRESSION_ENCODINGS: readonly ["gzip", "deflate", "deflate-raw"];
15
+ export type CompressionEncoding = (typeof COMPRESSION_ENCODINGS)[number];
16
+ export declare function isCompressionEncoding(encoding: string): encoding is CompressionEncoding;
17
+ /**
18
+ * Parse Content-Encoding into ordered codings (order applied), ignoring empty list elements.
19
+ *
20
+ * @see https://www.rfc-editor.org/rfc/rfc9110.html#name-content-encoding
21
+ * @see https://www.rfc-editor.org/rfc/rfc9110.html#name-lists-rule-abnf-extension
22
+ */
23
+ export declare function parseContentEncodings(header: string | undefined): string[];
24
+ /**
25
+ * Roughly estimates the UTF-8 byte length of a string without encoding it.
26
+ */
27
+ export declare function estimateUtf8ByteLength(value: string): number;
28
+ /**
29
+ * Estimates how many bytes of a FormData body are worth compressing. Non-compressible blobs count
30
+ * against the total. Returns `Infinity` when a compressible blob has an unknown size, and
31
+ * `-Infinity` when a non-compressible one does, since the estimate is then unreliable.
32
+ */
33
+ export declare function estimateCompressibleFormDataSize(formData: FormData, isCompressible: (contentType: string) => boolean): number;
6
34
  /**
7
35
  * Parse Accept-Encoding into each coding's q-value, where `0` means the coding is explicitly
8
36
  * unacceptable. The `*` wildcard is kept under its own key; use {@link isAcceptableEncoding}
@@ -27,3 +55,4 @@ export declare function isAcceptableEncoding(qualities: Map<string, number>, cod
27
55
  export declare function varyByAcceptEncoding(vary: string | undefined): string;
28
56
  export declare function isNoTransformCacheControl(cacheControl: string | undefined): boolean;
29
57
  export declare function isCompressibleContentType(contentType: string | null | undefined): boolean;
58
+ export {};