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

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (86) hide show
  1. package/README.md +4 -4
  2. package/dist/args.js +3 -0
  3. package/dist/array.js +7 -0
  4. package/dist/bigint.d.ts +9 -0
  5. package/dist/bigint.js +19 -0
  6. package/dist/buffer.d.ts +18 -0
  7. package/dist/buffer.js +77 -0
  8. package/dist/compare.js +45 -0
  9. package/dist/consts.js +1 -0
  10. package/dist/error.js +3 -0
  11. package/dist/{function.d.mts → function.d.ts} +5 -5
  12. package/dist/function.js +38 -0
  13. package/dist/{http.d.mts → http.d.ts} +16 -16
  14. package/dist/http.js +113 -0
  15. package/dist/id.d.ts +8 -0
  16. package/dist/id.js +13 -0
  17. package/dist/index.d.ts +34 -0
  18. package/dist/index.js +32 -0
  19. package/dist/interceptor.d.ts +60 -0
  20. package/dist/interceptor.js +139 -0
  21. package/dist/iterator.d.ts +56 -0
  22. package/dist/iterator.js +157 -0
  23. package/dist/object.d.ts +60 -0
  24. package/dist/object.js +245 -0
  25. package/dist/plugin.d.ts +12 -0
  26. package/dist/plugin.js +61 -0
  27. package/dist/promise.d.ts +17 -0
  28. package/dist/promise.js +32 -0
  29. package/dist/proxy.d.ts +12 -0
  30. package/dist/proxy.js +24 -0
  31. package/dist/queue.d.ts +16 -0
  32. package/dist/queue.js +79 -0
  33. package/dist/signal.d.ts +18 -0
  34. package/dist/signal.js +85 -0
  35. package/dist/stream.d.ts +48 -0
  36. package/dist/stream.js +155 -0
  37. package/dist/tracing.d.ts +73 -0
  38. package/dist/tracing.js +94 -0
  39. package/dist/types.d.ts +26 -0
  40. package/dist/value.d.ts +2 -0
  41. package/dist/value.js +6 -0
  42. package/package.json +16 -18
  43. package/dist/args.mjs +0 -3
  44. package/dist/array.mjs +0 -7
  45. package/dist/bigint.d.mts +0 -9
  46. package/dist/bigint.mjs +0 -12
  47. package/dist/buffer.d.mts +0 -18
  48. package/dist/buffer.mjs +0 -66
  49. package/dist/compare.mjs +0 -43
  50. package/dist/consts.mjs +0 -1
  51. package/dist/error.mjs +0 -3
  52. package/dist/function.mjs +0 -31
  53. package/dist/http.mjs +0 -83
  54. package/dist/id.d.mts +0 -8
  55. package/dist/id.mjs +0 -7
  56. package/dist/index.d.mts +0 -25
  57. package/dist/index.mjs +0 -23
  58. package/dist/interceptor.d.mts +0 -96
  59. package/dist/interceptor.mjs +0 -102
  60. package/dist/iterator.d.mts +0 -82
  61. package/dist/iterator.mjs +0 -151
  62. package/dist/object.d.mts +0 -64
  63. package/dist/object.mjs +0 -221
  64. package/dist/plugin.d.mts +0 -12
  65. package/dist/plugin.mjs +0 -58
  66. package/dist/promise.d.mts +0 -17
  67. package/dist/promise.mjs +0 -23
  68. package/dist/proxy.d.mts +0 -15
  69. package/dist/proxy.mjs +0 -15
  70. package/dist/queue.d.mts +0 -16
  71. package/dist/queue.mjs +0 -74
  72. package/dist/signal.d.mts +0 -13
  73. package/dist/signal.mjs +0 -74
  74. package/dist/stream.d.mts +0 -54
  75. package/dist/stream.mjs +0 -138
  76. package/dist/tracing.d.mts +0 -73
  77. package/dist/tracing.mjs +0 -89
  78. package/dist/types.d.mts +0 -32
  79. package/dist/value.d.mts +0 -8
  80. package/dist/value.mjs +0 -6
  81. /package/dist/{args.d.mts → args.d.ts} +0 -0
  82. /package/dist/{array.d.mts → array.d.ts} +0 -0
  83. /package/dist/{compare.d.mts → compare.d.ts} +0 -0
  84. /package/dist/{consts.d.mts → consts.d.ts} +0 -0
  85. /package/dist/{error.d.mts → error.d.ts} +0 -0
  86. /package/dist/{types.mjs → types.js} +0 -0
@@ -0,0 +1,94 @@
1
+ import { isAbortError } from './error.js';
2
+ const TRACER_SYMBOL = /* @__PURE__ */ Symbol.for('ORPC_TRACER');
3
+ export function setTracer(tracer) {
4
+ ;
5
+ globalThis[TRACER_SYMBOL] = tracer;
6
+ }
7
+ export function getTracer() {
8
+ return globalThis[TRACER_SYMBOL];
9
+ }
10
+ export function startSpan(options) {
11
+ const tracer = getTracer();
12
+ if (!tracer) {
13
+ return undefined;
14
+ }
15
+ if (typeof options === 'string') {
16
+ return tracer.startSpan(options);
17
+ }
18
+ return tracer.startSpan(options.name, options.parent);
19
+ }
20
+ export function recordSpanError(span, error) {
21
+ if (!span) {
22
+ return;
23
+ }
24
+ // DO NOT treat aborted error as error if happen during business logic (assumed)
25
+ span.recordException(isAbortError(error) ? 'info' : 'error', toTracingException(error));
26
+ }
27
+ export function setSpanAttributeIfDefined(span, key, value) {
28
+ if (!span || value === undefined) {
29
+ return;
30
+ }
31
+ span.setAttribute(key, value);
32
+ }
33
+ export function toTracingException(error) {
34
+ if (error instanceof Error) {
35
+ const exception = {
36
+ message: error.message,
37
+ name: error.name,
38
+ stack: error.stack,
39
+ };
40
+ if ('code' in error && (typeof error.code === 'string' || typeof error.code === 'number')) {
41
+ exception.code = error.code;
42
+ }
43
+ return exception;
44
+ }
45
+ return { message: String(error) };
46
+ }
47
+ export function toSpanAttributeValue(data) {
48
+ if (data === undefined) {
49
+ return 'undefined';
50
+ }
51
+ try {
52
+ // oxlint-disable-next-line no-restricted-properties
53
+ return JSON.stringify(data, (_, value) => {
54
+ if (typeof value === 'bigint') {
55
+ return value.toString();
56
+ }
57
+ if (value instanceof Map || value instanceof Set) {
58
+ return Array.from(value);
59
+ }
60
+ return value;
61
+ });
62
+ }
63
+ catch {
64
+ // oxlint-disable-next-line typescript/no-base-to-string
65
+ return String(data);
66
+ }
67
+ }
68
+ export async function runWithSpan(options, fn) {
69
+ const tracer = getTracer();
70
+ if (!tracer) {
71
+ return fn();
72
+ }
73
+ const name = typeof options === 'string' ? options : options.name;
74
+ const parent = typeof options === 'string' ? undefined : options.parent;
75
+ return tracer.startActiveSpan(name, parent, async (span) => {
76
+ try {
77
+ return await fn(span);
78
+ }
79
+ catch (e) {
80
+ recordSpanError(span, e);
81
+ throw e;
82
+ }
83
+ finally {
84
+ span.end();
85
+ }
86
+ });
87
+ }
88
+ export function runInSpanContext(span, fn) {
89
+ const tracer = getTracer();
90
+ if (!span || !tracer) {
91
+ return fn();
92
+ }
93
+ return tracer.withActiveSpan(span, fn);
94
+ }
@@ -0,0 +1,26 @@
1
+ export type IntersectPick<T, U> = Pick<T, keyof T & keyof U>;
2
+ /**
3
+ * Like `Omit`, but distributes over unions and keeps known keys beside index signatures.
4
+ */
5
+ export type DistributiveOmit<T, K extends PropertyKey> = {
6
+ [P in keyof T as P extends K ? never : P]: T[P];
7
+ };
8
+ /**
9
+ * Remove protected/private properties/methods
10
+ */
11
+ export type Public<T> = Pick<T, keyof T>;
12
+ export type PromiseWithError<T, TError> = Promise<T> & {
13
+ __error?: {
14
+ type: TError;
15
+ };
16
+ };
17
+ /**
18
+ * The place where you can config the orpc types.
19
+ *
20
+ * - `ThrowableError` the error type that represent throwable errors should be `Error` or `null | undefined | {}` if you want more strict.
21
+ */
22
+ export interface Registry {
23
+ }
24
+ export type ThrowableError = Registry extends {
25
+ ThrowableError: infer T;
26
+ } ? T : Error;
@@ -0,0 +1,2 @@
1
+ export type Value<T, TArgs extends any[] = []> = T | ((...args: TArgs) => T);
2
+ export declare function value<T, TArgs extends any[]>(value: Value<T, TArgs>, ...args: NoInfer<TArgs>): T extends Value<infer U, any> ? U : never;
package/dist/value.js ADDED
@@ -0,0 +1,6 @@
1
+ export function value(value, ...args) {
2
+ if (typeof value === 'function') {
3
+ return value(...args);
4
+ }
5
+ return value;
6
+ }
package/package.json CHANGED
@@ -1,36 +1,36 @@
1
1
  {
2
2
  "name": "@orpc/shared",
3
- "type": "module",
4
- "version": "2.0.0-beta.48",
3
+ "version": "2.0.0-beta.49",
5
4
  "description": "Internal utilities shared across oRPC packages",
6
- "license": "MIT",
7
- "funding": [
8
- "https://github.com/sponsors/dinwwwh",
9
- "https://opencollective.com/middleapi"
5
+ "keywords": [
6
+ "orpc"
10
7
  ],
11
8
  "homepage": "https://orpc.dev",
9
+ "license": "MIT",
12
10
  "repository": {
13
11
  "type": "git",
14
12
  "url": "git+https://github.com/middleapi/orpc.git",
15
13
  "directory": "packages/shared"
16
14
  },
17
- "keywords": [
18
- "orpc"
15
+ "funding": [
16
+ "https://github.com/sponsors/dinwwwh",
17
+ "https://opencollective.com/middleapi"
18
+ ],
19
+ "files": [
20
+ "dist"
19
21
  ],
22
+ "type": "module",
20
23
  "sideEffects": false,
21
24
  "exports": {
22
25
  "./package.json": "./package.json",
23
26
  ".": {
24
- "types": "./dist/index.d.mts",
25
- "import": "./dist/index.mjs",
26
- "default": "./dist/index.mjs"
27
+ "types": "./dist/index.d.ts",
28
+ "import": "./dist/index.js",
29
+ "default": "./dist/index.js"
27
30
  }
28
31
  },
29
- "files": [
30
- "dist"
31
- ],
32
32
  "dependencies": {
33
- "@standard-server/shared": "~0.14.0",
33
+ "@standard-server/shared": "~0.15.0",
34
34
  "type-fest": "^5.10.0"
35
35
  },
36
36
  "devDependencies": {
@@ -38,7 +38,5 @@
38
38
  "valibot": "^1.5.0",
39
39
  "zod": "^4.6.7"
40
40
  },
41
- "scripts": {
42
- "type:check": "tsc -b"
43
- }
41
+ "scripts": {}
44
42
  }
package/dist/args.mjs DELETED
@@ -1,3 +0,0 @@
1
- export function resolveMaybeOptionalOptions(rest) {
2
- return rest[0] ?? {};
3
- }
package/dist/array.mjs DELETED
@@ -1,7 +0,0 @@
1
- export function toArray(value) {
2
- return Array.isArray(value) ? value : value === undefined || value === null ? [] : [value];
3
- }
4
- export function splitInHalf(arr) {
5
- const half = Math.ceil(arr.length / 2);
6
- return [arr.slice(0, half), arr.slice(half)];
7
- }
package/dist/bigint.d.mts DELETED
@@ -1,9 +0,0 @@
1
- /**
2
- * Default maximum digits, excluding a leading `-`, when parsing a `bigint` from a string.
3
- */
4
- export declare const DEFAULT_MAX_BIGINT_DIGITS = 4300;
5
- /**
6
- * Parses a `bigint.toString()` string, or returns `undefined` if it is invalid or has more than `maxDigits` digits.
7
- * The length is checked first, since `BigInt()` is super-linear in the digit count.
8
- */
9
- export declare function parseBigIntString(value: string, maxDigits: number): bigint | undefined;
package/dist/bigint.mjs DELETED
@@ -1,12 +0,0 @@
1
-
2
- export const DEFAULT_MAX_BIGINT_DIGITS = 4300;
3
-
4
- const BIGINT_PATTERN = /^-?(?:0|[1-9]\d*)$/;
5
-
6
- export function parseBigIntString(value, maxDigits) {
7
- const digits = value.startsWith("-") ? value.length - 1 : value.length;
8
- if (digits > maxDigits || !BIGINT_PATTERN.test(value)) {
9
- return undefined;
10
- }
11
- return BigInt(value);
12
- }
package/dist/buffer.d.mts DELETED
@@ -1,18 +0,0 @@
1
- import type { Arrayable } from "type-fest";
2
- /**
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
- export declare function loadBytes(source: Pick<Blob, "arrayBuffer" | "bytes">): ReturnType<Blob["bytes"]>;
8
- /**
9
- * Normalize text or binary-like inputs to either:
10
- * - the original string value, or
11
- * - a Uint8Array view over the source bytes.
12
- */
13
- export declare function toStringOrBytes(source: Arrayable<string | ArrayBuffer | Pick<Uint8Array<ArrayBuffer>, "buffer" | "byteOffset" | "byteLength">>): string | Awaited<ReturnType<Blob["bytes"]>>;
14
- /**
15
- * Encodes bytes to standard, padded base64, as data URLs and many protocols require.
16
- * Prefers the native `toBase64` or `Buffer`, which are far faster for large outputs.
17
- */
18
- export declare function encodeBase64(bytes: Uint8Array): string;
package/dist/buffer.mjs DELETED
@@ -1,66 +0,0 @@
1
-
2
- export async function loadBytes(source) {
3
- if (typeof source.bytes === "function") {
4
-
5
- return source.bytes();
6
- }
7
- return new Uint8Array(await source.arrayBuffer());
8
- }
9
-
10
- export function toStringOrBytes(source) {
11
- if (typeof source === "string") {
12
- return source;
13
- }
14
- if (source instanceof ArrayBuffer) {
15
- return new Uint8Array(source);
16
- }
17
- if (Array.isArray(source)) {
18
- return concatBytes(source);
19
- }
20
- if (source instanceof Uint8Array) {
21
- return source;
22
- }
23
- return new Uint8Array(source.buffer, source.byteOffset, source.byteLength);
24
- }
25
- function toBytes(item) {
26
- if (typeof item === "string") {
27
- return new TextEncoder().encode(item);
28
- }
29
- if (item instanceof ArrayBuffer) {
30
- return new Uint8Array(item);
31
- }
32
- if (item instanceof Uint8Array) {
33
- return item;
34
- }
35
- return new Uint8Array(item.buffer, item.byteOffset, item.byteLength);
36
- }
37
- function concatBytes(items) {
38
- const chunks = items.map(toBytes);
39
- const totalLength = chunks.reduce((sum, chunk) => sum + chunk.byteLength, 0);
40
- const result = new Uint8Array(totalLength);
41
- let offset = 0;
42
- for (const chunk of chunks) {
43
- result.set(chunk, offset);
44
- offset += chunk.byteLength;
45
- }
46
- return result;
47
- }
48
-
49
- export function encodeBase64(bytes) {
50
- const native = bytes;
51
- if (typeof native.toBase64 === "function") {
52
- return native.toBase64();
53
- }
54
-
55
-
56
- const NodeBuffer = globalThis.process?.getBuiltinModule?.("node:buffer")?.Buffer;
57
- if (NodeBuffer !== undefined) {
58
- return NodeBuffer.from(bytes.buffer, bytes.byteOffset, bytes.byteLength).toString("base64");
59
- }
60
- const chunkSize = 8192;
61
- let binaryString = "";
62
- for (let i = 0; i < bytes.length; i += chunkSize) {
63
- binaryString += String.fromCharCode(...bytes.subarray(i, i + chunkSize));
64
- }
65
- return btoa(binaryString);
66
- }
package/dist/compare.mjs DELETED
@@ -1,43 +0,0 @@
1
- import { isPlainObject } from "./object.mjs";
2
- export function isDeepEqual(a, b) {
3
- return isDeepEqualInternal(a, b, new WeakMap());
4
- }
5
- 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
- } else if (!isPlainObject(a) || !isPlainObject(b)) {
14
-
15
-
16
- return false;
17
- }
18
- const aRecord = a;
19
- const bRecord = b;
20
- const visitedMatches = visited.get(a);
21
- if (visitedMatches?.has(b)) {
22
- return true;
23
- }
24
- if (visitedMatches) {
25
- visitedMatches.add(b);
26
- } else {
27
- visited.set(a, new WeakSet([b]));
28
- }
29
- const aKeys = Object.keys(aRecord).filter((k) => aRecord[k] !== undefined);
30
- const bKeys = Object.keys(bRecord).filter((k) => bRecord[k] !== undefined);
31
- if (aKeys.length !== bKeys.length) {
32
- return false;
33
- }
34
- for (const key of aKeys) {
35
- if (!Object.hasOwn(bRecord, key)) {
36
- return false;
37
- }
38
- if (!isDeepEqualInternal(aRecord[key], bRecord[key], visited)) {
39
- return false;
40
- }
41
- }
42
- return true;
43
- }
package/dist/consts.mjs DELETED
@@ -1 +0,0 @@
1
- export const ORPC_NAME = "orpc";
package/dist/error.mjs DELETED
@@ -1,3 +0,0 @@
1
- export function isAbortError(error) {
2
- return error instanceof Error && error.name.includes("Abort");
3
- }
package/dist/function.mjs DELETED
@@ -1,31 +0,0 @@
1
- const AsyncGeneratorFunction = /* @__PURE__ */ (() => Object.getPrototypeOf(async function* () {}).constructor)();
2
-
3
- export function isAsyncGeneratorFunction(value) {
4
- return value instanceof AsyncGeneratorFunction;
5
- }
6
- export function once(fn) {
7
- let cached;
8
- return () => {
9
- if (cached) {
10
- return cached.result;
11
- }
12
- const result = fn();
13
- cached = { result };
14
- return result;
15
- };
16
- }
17
-
18
- export function defer(callback, delay = 0) {
19
- if (typeof setTimeout === "function") {
20
- setTimeout(callback, delay);
21
- } else {
22
- Promise.resolve().then(() => Promise.resolve().then(() => Promise.resolve().then(callback)));
23
- }
24
- }
25
- export function tryOrUndefined(fn) {
26
- try {
27
- return fn();
28
- } catch {
29
- return undefined;
30
- }
31
- }
package/dist/http.mjs DELETED
@@ -1,83 +0,0 @@
1
- import { safeDecodeURIComponent, safeEncodeURIComponent } from "@standard-server/shared";
2
- export function pathToHttpPath(path) {
3
- return `/${path.map(safeEncodeURIComponent).join("/")}`;
4
- }
5
- export function normalizeHttpPath(path) {
6
- const paths = path.split("/");
7
- if (paths.at(0) === "") {
8
- paths.shift();
9
- }
10
- return pathToHttpPath(paths.map(safeDecodeURIComponent));
11
- }
12
- export function mergeHttpPath(a, b) {
13
- return `${a.endsWith("/") ? a.slice(0, -1) : a}${b}`;
14
- }
15
- export function matchesHttpPathPrefix(url, prefix) {
16
- if (!url.startsWith(prefix)) {
17
- return false;
18
- }
19
- const charAfterPrefix = url[prefix.length];
20
-
21
- return charAfterPrefix === "/" || charAfterPrefix === "?" || charAfterPrefix === "#" || charAfterPrefix === undefined || prefix[prefix.length - 1] === "/";
22
- }
23
- export function matchesHttpPath(url, path) {
24
- const pathWithoutEndSlash = path.endsWith("/") ? path.slice(0, path.length - 1) : path;
25
- if (!url.startsWith(pathWithoutEndSlash)) {
26
- return false;
27
- }
28
- let charAfterPrefix = url[pathWithoutEndSlash.length];
29
- if (charAfterPrefix === "/") {
30
- charAfterPrefix = url[pathWithoutEndSlash.length + 1];
31
- }
32
-
33
- return charAfterPrefix === undefined || charAfterPrefix === "?" || charAfterPrefix === "#";
34
- }
35
- const ACCEPT_ENCODING_QUALITY_REGEX = /^\s*q=([\d.]+)\s*$/i;
36
-
37
- export function parseAcceptEncodingQualities(header) {
38
- const qualities = new Map();
39
- for (const part of header?.split(",") ?? []) {
40
- const [rawCoding, ...params] = part.split(";");
41
- const coding = rawCoding.trim().toLowerCase();
42
- if (coding === "") {
43
- continue;
44
- }
45
- const quality = params.map((param) => ACCEPT_ENCODING_QUALITY_REGEX.exec(param)?.[1]).find((value) => value !== undefined);
46
- qualities.set(coding, quality === undefined ? 1 : Number(quality));
47
- }
48
- return qualities;
49
- }
50
-
51
- export function isAcceptableEncoding(qualities, coding) {
52
- return (qualities.get(coding) ?? qualities.get("*") ?? 0) > 0;
53
- }
54
-
55
- export function varyByAcceptEncoding(vary) {
56
- if (vary === undefined) {
57
- return "accept-encoding";
58
- }
59
- const fields = vary.split(",").map((field) => field.trim().toLowerCase());
60
-
61
- return fields.includes("accept-encoding") || fields.includes("*") ? vary : `${vary}, accept-encoding`;
62
- }
63
-
64
- const CACHE_CONTROL_NO_TRANSFORM_REGEX = /(?:^|,)\s*no-transform\s*(?:,|$)/i;
65
- export function isNoTransformCacheControl(cacheControl) {
66
- if (cacheControl === undefined) {
67
- return false;
68
- }
69
- return CACHE_CONTROL_NO_TRANSFORM_REGEX.test(cacheControl);
70
- }
71
-
72
- 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;
73
-
74
- const MAX_COMPRESSIBLE_CONTENT_TYPE_LENGTH = 1024;
75
- export function isCompressibleContentType(contentType) {
76
- if (contentType === null || contentType === undefined) {
77
- return false;
78
- }
79
- if (contentType.length > MAX_COMPRESSIBLE_CONTENT_TYPE_LENGTH) {
80
- return false;
81
- }
82
- return COMPRESSIBLE_CONTENT_TYPE_REGEX.test(contentType);
83
- }
package/dist/id.d.mts DELETED
@@ -1,8 +0,0 @@
1
- /**
2
- * Compares two sequential IDs.
3
- * Returns:
4
- * - negative if `a` < `b`
5
- * - positive if `a` > `b`
6
- * - 0 if equal
7
- */
8
- export declare function compareSequentialIds(a: string, b: string): number;
package/dist/id.mjs DELETED
@@ -1,7 +0,0 @@
1
-
2
- export function compareSequentialIds(a, b) {
3
- if (a.length !== b.length) {
4
- return a.length - b.length;
5
- }
6
- return a < b ? -1 : a > b ? 1 : 0;
7
- }
package/dist/index.d.mts DELETED
@@ -1,25 +0,0 @@
1
- export * from "./args.mjs";
2
- export * from "./array.mjs";
3
- export * from "./bigint.mjs";
4
- export * from "./buffer.mjs";
5
- export * from "./compare.mjs";
6
- export * from "./consts.mjs";
7
- export * from "./error.mjs";
8
- export * from "./function.mjs";
9
- export * from "./http.mjs";
10
- export * from "./id.mjs";
11
- export * from "./interceptor.mjs";
12
- export * from "./iterator.mjs";
13
- export * from "./object.mjs";
14
- export * from "./plugin.mjs";
15
- export * from "./promise.mjs";
16
- export * from "./proxy.mjs";
17
- export * from "./queue.mjs";
18
- export * from "./signal.mjs";
19
- export * from "./stream.mjs";
20
- export * from "./tracing.mjs";
21
- export * from "./types.mjs";
22
- export * from "./value.mjs";
23
- export { AbortError, AsyncIteratorClass, getOrBind, isAsyncIteratorObject, isTypescriptObject, parseEmptyableJSON, safeDecodeURIComponent, safeEncodeURIComponent, sequential, SequentialIdGenerator, sleep, stringifyJSON, throwIfAborted, toArray } from "@standard-server/shared";
24
- export type { AsyncCleanupFn, AsyncIteratorClassNextFn } from "@standard-server/shared";
25
- export type { Arrayable, IsEqual, PartialDeep, Promisable, Writable } from "type-fest";
package/dist/index.mjs DELETED
@@ -1,23 +0,0 @@
1
- export * from "./args.mjs";
2
- export * from "./array.mjs";
3
- export * from "./bigint.mjs";
4
- export * from "./buffer.mjs";
5
- export * from "./compare.mjs";
6
- export * from "./consts.mjs";
7
- export * from "./error.mjs";
8
- export * from "./function.mjs";
9
- export * from "./http.mjs";
10
- export * from "./id.mjs";
11
- export * from "./interceptor.mjs";
12
- export * from "./iterator.mjs";
13
- export * from "./object.mjs";
14
- export * from "./plugin.mjs";
15
- export * from "./promise.mjs";
16
- export * from "./proxy.mjs";
17
- export * from "./queue.mjs";
18
- export * from "./signal.mjs";
19
- export * from "./stream.mjs";
20
- export * from "./tracing.mjs";
21
- export * from "./types.mjs";
22
- export * from "./value.mjs";
23
- export { AbortError, AsyncIteratorClass, getOrBind, isAsyncIteratorObject, isTypescriptObject, parseEmptyableJSON, safeDecodeURIComponent, safeEncodeURIComponent, sequential, SequentialIdGenerator, sleep, stringifyJSON, throwIfAborted, toArray } from "@standard-server/shared";
@@ -1,96 +0,0 @@
1
- import type { Promisable } from "type-fest";
2
- import type { PromiseWithError, ThrowableError } from "./types.mjs";
3
- export type InterceptableOptions = Record<string, any>;
4
- export type InterceptorOptions<
5
- TOptions extends InterceptableOptions,
6
- TResult
7
- > = Omit<TOptions, "next"> & {
8
- next(options?: TOptions): TResult;
9
- };
10
- export type Interceptor<
11
- TOptions extends InterceptableOptions,
12
- TResult
13
- > = (options: InterceptorOptions<TOptions, TResult>) => TResult;
14
- /**
15
- * Can used for interceptors or middlewares
16
- */
17
- export declare function onStart<
18
- T,
19
- TOptions extends {
20
- next: () => any;
21
- },
22
- TRest extends any[]
23
- >(callback: NoInfer<(options: TOptions, ...rest: TRest) => Promisable<void>>): (options: TOptions, ...rest: TRest) => T | Promise<Awaited<ReturnType<TOptions["next"]>>>;
24
- /**
25
- * Can used for interceptors or middlewares
26
- */
27
- export declare function onSuccess<
28
- T,
29
- TOptions extends {
30
- next: () => any;
31
- },
32
- TRest extends any[]
33
- >(callback: NoInfer<(result: Awaited<ReturnType<TOptions["next"]>>, options: TOptions, ...rest: TRest) => Promisable<void>>): (options: TOptions, ...rest: TRest) => T | Promise<Awaited<ReturnType<TOptions["next"]>>>;
34
- /**
35
- * Creates an interceptor or middleware that invokes a callback whenever an error
36
- * is thrown. The error is rethrown after the callback completes.
37
- *
38
- * @see {@link https://orpc.dev/docs/adapters/fetch-api | Fetch API Adapter}
39
- */
40
- export declare function onError<
41
- T,
42
- TOptions extends {
43
- next: () => any;
44
- },
45
- TRest extends any[]
46
- >(callback: NoInfer<(error: ReturnType<TOptions["next"]> extends PromiseWithError<any, infer E> ? E : ThrowableError, options: TOptions, ...rest: TRest) => Promisable<void>>): (options: TOptions, ...rest: TRest) => T | Promise<Awaited<ReturnType<TOptions["next"]>>>;
47
- export type OnFinishState<
48
- TResult,
49
- TError
50
- > = [error: TError, data: undefined, isSuccess: false] | [error: null, data: TResult, isSuccess: true];
51
- /**
52
- * Can used for interceptors or middlewares
53
- */
54
- export declare function onFinish<
55
- T,
56
- TOptions extends {
57
- next: () => any;
58
- },
59
- TRest extends any[]
60
- >(callback: NoInfer<(state: OnFinishState<Awaited<ReturnType<TOptions["next"]>>, ReturnType<TOptions["next"]> extends PromiseWithError<any, infer E> ? E : ThrowableError>, options: TOptions, ...rest: TRest) => Promisable<void>>): (options: TOptions, ...rest: TRest) => T | Promise<Awaited<ReturnType<TOptions["next"]>>>;
61
- /**
62
- * Creates a middleware or interceptor that invokes a callback when the returned async
63
- * iterator object throws an error while being consumed.
64
- *
65
- * This does not replace the `onError`. `onError` only fires on the
66
- * initial call (before the interceptor returns the iterator), whereas this
67
- * callback only fires while consuming the iterator. Use both together to
68
- * catch all possible errors.
69
- */
70
- export declare function onAsyncIteratorObjectError<
71
- T,
72
- TOptions extends {
73
- next: () => any;
74
- },
75
- TRest extends any[]
76
- >(callback: NoInfer<(error: ThrowableError | (ReturnType<TOptions["next"]> extends PromiseWithError<any, infer E> ? E : ThrowableError), options: TOptions, ...rest: TRest) => Promisable<void>>): (options: TOptions, ...rest: TRest) => T | Promise<Awaited<ReturnType<TOptions["next"]>>>;
77
- /**
78
- * Creates an interceptor that invokes a callback when the returned readable
79
- * stream errors while being consumed.
80
- *
81
- * This does not replace the `onError`. `onError` only fires on the
82
- * initial call (before the interceptor returns the stream), whereas this
83
- * callback only fires while consuming the stream. Use both together to catch
84
- * all possible errors.
85
- */
86
- export declare function onReadableStreamError<
87
- T,
88
- TOptions extends {
89
- next: () => any;
90
- },
91
- TRest extends any[]
92
- >(callback: NoInfer<(error: ThrowableError | (ReturnType<TOptions["next"]> extends PromiseWithError<any, infer E> ? E : ThrowableError), options: TOptions, ...rest: TRest) => Promisable<void>>): (options: TOptions, ...rest: TRest) => T | Promise<Awaited<ReturnType<TOptions["next"]>>>;
93
- export declare function intercept<
94
- TOptions extends InterceptableOptions,
95
- TResult
96
- >(interceptors: undefined | Interceptor<TOptions, TResult>[], options: NoInfer<TOptions>, main: NoInfer<(options: TOptions) => TResult>): TResult;