@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/http.js CHANGED
@@ -1,113 +1,147 @@
1
- import { safeDecodeURIComponent, safeEncodeURIComponent } from '@standard-server/shared';
2
- export function pathToHttpPath(path) {
3
- return `/${path.map(safeEncodeURIComponent).join('/')}`;
1
+ import { safeDecodeURIComponent, safeEncodeURIComponent } from "@standard-server/shared";
2
+ // src/http.ts
3
+ function pathToHttpPath(path) {
4
+ return `/${path.map(safeEncodeURIComponent).join("/")}`;
4
5
  }
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));
6
+ function normalizeHttpPath(path) {
7
+ const paths = path.split("/");
8
+ if (paths.at(0) === "") paths.shift();
9
+ return pathToHttpPath(paths.map(safeDecodeURIComponent));
11
10
  }
12
- export function mergeHttpPath(a, b) {
13
- return `${a.endsWith('/') ? a.slice(0, -1) : a}${b}`;
11
+ function mergeHttpPath(a, b) {
12
+ return `${a.endsWith("/") ? a.slice(0, -1) : a}${b}`;
14
13
  }
15
- export function matchesHttpPathPrefix(url, prefix) {
16
- if (!url.startsWith(prefix)) {
17
- return false;
18
- }
19
- const charAfterPrefix = url[prefix.length];
20
- // order by most common cases for better performance
21
- return (charAfterPrefix === '/' ||
22
- charAfterPrefix === '?' ||
23
- charAfterPrefix === '#' ||
24
- charAfterPrefix === undefined ||
25
- prefix[prefix.length - 1] === '/');
14
+ function matchesHttpPathPrefix(url, prefix) {
15
+ if (!url.startsWith(prefix)) return false;
16
+ const charAfterPrefix = url[prefix.length];
17
+ return charAfterPrefix === "/" || charAfterPrefix === "?" || charAfterPrefix === "#" || charAfterPrefix === void 0 || prefix[prefix.length - 1] === "/";
26
18
  }
27
- export function matchesHttpPath(url, path) {
28
- const pathWithoutEndSlash = path.endsWith('/') ? path.slice(0, path.length - 1) : path;
29
- if (!url.startsWith(pathWithoutEndSlash)) {
30
- return false;
31
- }
32
- let charAfterPrefix = url[pathWithoutEndSlash.length];
33
- if (charAfterPrefix === '/') {
34
- charAfterPrefix = url[pathWithoutEndSlash.length + 1];
35
- }
36
- // order by most common cases for better performance
37
- return charAfterPrefix === undefined || charAfterPrefix === '?' || charAfterPrefix === '#';
19
+ /**
20
+ * Removes `prefix` from `pathname`, or returns `undefined` when `pathname` is not under `prefix`.
21
+ * The rest of the path must start at a segment boundary, so `/apis` is not under `/api`.
22
+ */
23
+ function stripHttpPathPrefix(pathname, prefix) {
24
+ if (!pathname.startsWith(prefix)) return;
25
+ const charAfterPrefix = pathname[prefix.length];
26
+ if (charAfterPrefix === "/") return pathname.slice(prefix.length);
27
+ if (charAfterPrefix === void 0) return "/";
28
+ if (prefix[prefix.length - 1] === "/") return pathname.slice(prefix.length - 1);
29
+ }
30
+ function matchesHttpPath(url, path) {
31
+ const pathWithoutEndSlash = path.endsWith("/") ? path.slice(0, path.length - 1) : path;
32
+ if (!url.startsWith(pathWithoutEndSlash)) return false;
33
+ let charAfterPrefix = url[pathWithoutEndSlash.length];
34
+ if (charAfterPrefix === "/") charAfterPrefix = url[pathWithoutEndSlash.length + 1];
35
+ return charAfterPrefix === void 0 || charAfterPrefix === "?" || charAfterPrefix === "#";
36
+ }
37
+ /**
38
+ * Content codings that oRPC compression plugins can encode and decode.
39
+ */
40
+ const COMPRESSION_ENCODINGS = [
41
+ "gzip",
42
+ "deflate",
43
+ "deflate-raw"
44
+ ];
45
+ function isCompressionEncoding(encoding) {
46
+ return COMPRESSION_ENCODINGS.includes(encoding);
47
+ }
48
+ /**
49
+ * Parse Content-Encoding into ordered codings (order applied), ignoring empty list elements.
50
+ *
51
+ * @see https://www.rfc-editor.org/rfc/rfc9110.html#name-content-encoding
52
+ * @see https://www.rfc-editor.org/rfc/rfc9110.html#name-lists-rule-abnf-extension
53
+ */
54
+ function parseContentEncodings(header) {
55
+ const codings = [];
56
+ for (const part of header?.split(",") ?? []) {
57
+ const coding = part.trim().toLowerCase();
58
+ if (coding !== "") codings.push(coding);
59
+ }
60
+ return codings;
61
+ }
62
+ const AVG_UTF8_BYTES_PER_CHAR = 1.2;
63
+ /**
64
+ * Roughly estimates the UTF-8 byte length of a string without encoding it.
65
+ */
66
+ function estimateUtf8ByteLength(value) {
67
+ return value.length * AVG_UTF8_BYTES_PER_CHAR;
68
+ }
69
+ const FORM_DATA_PART_OVERHEAD = 64;
70
+ /**
71
+ * Estimates how many bytes of a FormData body are worth compressing. Non-compressible blobs count
72
+ * against the total. Returns `Infinity` when a compressible blob has an unknown size, and
73
+ * `-Infinity` when a non-compressible one does, since the estimate is then unreliable.
74
+ */
75
+ function estimateCompressibleFormDataSize(formData, isCompressible) {
76
+ let size = 0;
77
+ for (const [key, value] of formData) {
78
+ size += FORM_DATA_PART_OVERHEAD + key.length;
79
+ if (value instanceof Blob) {
80
+ if (!Number.isFinite(value.size)) {
81
+ if (!isCompressible(value.type)) return -Infinity;
82
+ size = Infinity;
83
+ } else size += isCompressible(value.type) ? value.size : -value.size;
84
+ } else size += estimateUtf8ByteLength(value);
85
+ }
86
+ return size;
38
87
  }
39
88
  const ACCEPT_ENCODING_QUALITY_REGEX = /^\s*q=([\d.]+)\s*$/i;
40
89
  /**
41
- * Parse Accept-Encoding into each coding's q-value, where `0` means the coding is explicitly
42
- * unacceptable. The `*` wildcard is kept under its own key; use {@link isAcceptableEncoding}
43
- * to decide whether a coding is acceptable.
44
- *
45
- * @see https://www.rfc-editor.org/rfc/rfc9110.html#name-accept-encoding
46
- */
47
- export function parseAcceptEncodingQualities(header) {
48
- const qualities = new Map();
49
- for (const part of header?.split(',') ?? []) {
50
- const [rawCoding, ...params] = part.split(';');
51
- const coding = rawCoding.trim().toLowerCase();
52
- if (coding === '') {
53
- continue;
54
- }
55
- const quality = params
56
- .map((param) => ACCEPT_ENCODING_QUALITY_REGEX.exec(param)?.[1])
57
- .find((value) => value !== undefined);
58
- qualities.set(coding, quality === undefined ? 1 : Number(quality));
59
- }
60
- return qualities;
90
+ * Parse Accept-Encoding into each coding's q-value, where `0` means the coding is explicitly
91
+ * unacceptable. The `*` wildcard is kept under its own key; use {@link isAcceptableEncoding}
92
+ * to decide whether a coding is acceptable.
93
+ *
94
+ * @see https://www.rfc-editor.org/rfc/rfc9110.html#name-accept-encoding
95
+ */
96
+ function parseAcceptEncodingQualities(header) {
97
+ const qualities = /* @__PURE__ */ new Map();
98
+ for (const part of header?.split(",") ?? []) {
99
+ const [rawCoding, ...params] = part.split(";");
100
+ const coding = rawCoding.trim().toLowerCase();
101
+ if (coding === "") continue;
102
+ const quality = params.map((param) => ACCEPT_ENCODING_QUALITY_REGEX.exec(param)?.[1]).find((value) => value !== void 0);
103
+ qualities.set(coding, quality === void 0 ? 1 : Number(quality));
104
+ }
105
+ return qualities;
61
106
  }
62
107
  /**
63
- * Whether the client accepts a coding, given qualities from {@link parseAcceptEncodingQualities}.
64
- * An explicit q-value takes precedence over the `*` wildcard, so `gzip;q=0, *` never accepts gzip.
65
- *
66
- * @see https://www.rfc-editor.org/rfc/rfc9110.html#name-accept-encoding
67
- */
68
- export function isAcceptableEncoding(qualities, coding) {
69
- return (qualities.get(coding) ?? qualities.get('*') ?? 0) > 0;
108
+ * Whether the client accepts a coding, given qualities from {@link parseAcceptEncodingQualities}.
109
+ * An explicit q-value takes precedence over the `*` wildcard, so `gzip;q=0, *` never accepts gzip.
110
+ *
111
+ * @see https://www.rfc-editor.org/rfc/rfc9110.html#name-accept-encoding
112
+ */
113
+ function isAcceptableEncoding(qualities, coding) {
114
+ return (qualities.get(coding) ?? qualities.get("*") ?? 0) > 0;
70
115
  }
71
116
  /**
72
- * Add `accept-encoding` to a Vary header value. The encoding is chosen from the request, so a
73
- * shared cache must key on it or it will hand a compressed body to a client that cannot decode it.
74
- *
75
- * @see https://www.rfc-editor.org/rfc/rfc9110.html#name-vary
76
- */
77
- export function varyByAcceptEncoding(vary) {
78
- if (vary === undefined) {
79
- return 'accept-encoding';
80
- }
81
- const fields = vary.split(',').map((field) => field.trim().toLowerCase());
82
- // `*` already forbids reuse across requests, so narrowing it would be a downgrade
83
- return fields.includes('accept-encoding') || fields.includes('*')
84
- ? vary
85
- : `${vary}, accept-encoding`;
117
+ * Add `accept-encoding` to a Vary header value. The encoding is chosen from the request, so a
118
+ * shared cache must key on it or it will hand a compressed body to a client that cannot decode it.
119
+ *
120
+ * @see https://www.rfc-editor.org/rfc/rfc9110.html#name-vary
121
+ */
122
+ function varyByAcceptEncoding(vary) {
123
+ if (vary === void 0) return "accept-encoding";
124
+ const fields = vary.split(",").map((field) => field.trim().toLowerCase());
125
+ return fields.includes("accept-encoding") || fields.includes("*") ? vary : `${vary}, accept-encoding`;
86
126
  }
87
127
  /**
88
- * Whether Cache-Control includes the no-transform directive, which forbids transforming the body.
89
- *
90
- * @see https://www.rfc-editor.org/rfc/rfc9111.html#name-no-transform
91
- */
128
+ * Whether Cache-Control includes the no-transform directive, which forbids transforming the body.
129
+ *
130
+ * @see https://www.rfc-editor.org/rfc/rfc9111.html#name-no-transform
131
+ */
92
132
  const CACHE_CONTROL_NO_TRANSFORM_REGEX = /(?:^|,)\s*no-transform\s*(?:,|$)/i;
93
- export function isNoTransformCacheControl(cacheControl) {
94
- if (cacheControl === undefined) {
95
- return false;
96
- }
97
- return CACHE_CONTROL_NO_TRANSFORM_REGEX.test(cacheControl);
133
+ function isNoTransformCacheControl(cacheControl) {
134
+ if (cacheControl === void 0) return false;
135
+ return CACHE_CONTROL_NO_TRANSFORM_REGEX.test(cacheControl);
98
136
  }
99
137
  /**
100
- * inspired from Hono Compression Plugin
101
- */
138
+ * inspired from Hono Compression Plugin
139
+ */
102
140
  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;
103
- // Cap length to skip the regex on pathological inputs.
104
141
  const MAX_COMPRESSIBLE_CONTENT_TYPE_LENGTH = 1024;
105
- export function isCompressibleContentType(contentType) {
106
- if (contentType === null || contentType === undefined) {
107
- return false;
108
- }
109
- if (contentType.length > MAX_COMPRESSIBLE_CONTENT_TYPE_LENGTH) {
110
- return false;
111
- }
112
- return COMPRESSIBLE_CONTENT_TYPE_REGEX.test(contentType);
142
+ function isCompressibleContentType(contentType) {
143
+ if (contentType === null || contentType === void 0) return false;
144
+ if (contentType.length > MAX_COMPRESSIBLE_CONTENT_TYPE_LENGTH) return false;
145
+ return COMPRESSIBLE_CONTENT_TYPE_REGEX.test(contentType);
113
146
  }
147
+ export { estimateCompressibleFormDataSize, estimateUtf8ByteLength, isAcceptableEncoding, isCompressibleContentType, isCompressionEncoding, isNoTransformCacheControl, matchesHttpPath, matchesHttpPathPrefix, mergeHttpPath, normalizeHttpPath, parseAcceptEncodingQualities, parseContentEncodings, pathToHttpPath, stripHttpPathPrefix, varyByAcceptEncoding };
package/dist/id.d.ts CHANGED
@@ -5,4 +5,4 @@
5
5
  * - positive if `a` > `b`
6
6
  * - 0 if equal
7
7
  */
8
- export declare function compareSequentialIds(a: string, b: string): number;
8
+ export declare function compareSequentialIds(a: string, b: string): number;
package/dist/id.js CHANGED
@@ -1,13 +1,13 @@
1
+ // src/id.ts
1
2
  /**
2
- * Compares two sequential IDs.
3
- * Returns:
4
- * - negative if `a` < `b`
5
- * - positive if `a` > `b`
6
- * - 0 if equal
7
- */
8
- export function compareSequentialIds(a, b) {
9
- if (a.length !== b.length) {
10
- return a.length - b.length;
11
- }
12
- return a < b ? -1 : a > b ? 1 : 0;
3
+ * Compares two sequential IDs.
4
+ * Returns:
5
+ * - negative if `a` < `b`
6
+ * - positive if `a` > `b`
7
+ * - 0 if equal
8
+ */
9
+ function compareSequentialIds(a, b) {
10
+ if (a.length !== b.length) return a.length - b.length;
11
+ return a < b ? -1 : a > b ? 1 : 0;
13
12
  }
13
+ export { compareSequentialIds };
package/dist/index.d.ts CHANGED
@@ -1,34 +1,26 @@
1
- export * from './args.ts';
2
- export * from './array.ts';
3
- export * from './bigint.ts';
4
- export * from './buffer.ts';
5
- export * from './compare.ts';
6
- export * from './consts.ts';
7
- export * from './error.ts';
8
- export * from './function.ts';
9
- export * from './http.ts';
10
- export * from './id.ts';
11
- export * from './interceptor.ts';
12
- export * from './iterator.ts';
13
- export * from './object.ts';
14
- export * from './plugin.ts';
15
- export * from './promise.ts';
16
- export * from './proxy.ts';
17
- export * from './queue.ts';
18
- export * from './signal.ts';
19
- export * from './stream.ts';
20
- export * from './tracing.ts';
21
- export * from './types.ts';
22
- export * from './value.ts';
23
- export {
24
- /**
25
- * @deprecated Use `isPlainObject` instead.
26
- */
27
- isPlainObject as isObject, } from './object.ts';
28
- export { AbortError, AsyncIteratorClass, getOrBind, isAsyncIteratorObject, isNonPrimitive,
29
- /**
30
- * @deprecated Use `isNonPrimitive` instead.
31
- */
32
- isNonPrimitive as isTypescriptObject, parseEmptyableJSON, safeDecodeURIComponent, safeEncodeURIComponent, sequential, SequentialIdGenerator, sleep, stringifyJSON, throwIfAborted, toArray, } from '@standard-server/shared';
33
- export type { AsyncCleanupFn, AsyncIteratorClassNextFn } from '@standard-server/shared';
34
- export type { Arrayable, IsEqual, PartialDeep, Promisable, Writable } from 'type-fest';
1
+ import { MaybeOptionalOptions, resolveMaybeOptionalOptions } from "./args.js";
2
+ import { splitInHalf, takeLast } from "./array.js";
3
+ import { DEFAULT_MAX_BIGINT_DIGITS, parseBigIntString } from "./bigint.js";
4
+ import { encodeBase64, loadBytes, toStringOrBytes } from "./buffer.js";
5
+ import { isDeepEqual } from "./compare.js";
6
+ import { ORPC_NAME } from "./consts.js";
7
+ import { isAbortError } from "./error.js";
8
+ import { AnyFunction, defer, isAsyncGeneratorFunction, once, tryOrUndefined } from "./function.js";
9
+ import { CompressionEncoding, estimateCompressibleFormDataSize, estimateUtf8ByteLength, isAcceptableEncoding, isCompressibleContentType, isCompressionEncoding, isNoTransformCacheControl, matchesHttpPath, matchesHttpPathPrefix, mergeHttpPath, normalizeHttpPath, parseAcceptEncodingQualities, parseContentEncodings, pathToHttpPath, stripHttpPathPrefix, varyByAcceptEncoding } from "./http.js";
10
+ import { compareSequentialIds } from "./id.js";
11
+ import { InterceptableOptions, Interceptor, InterceptorOptions, OnFinishState, intercept, onAsyncIteratorObjectError, onError, onFinish, onReadableStreamError, onStart, onSuccess } from "./interceptor.js";
12
+ import { ConsumeAsyncIteratorOptions, WrapAsyncIteratorOptions, consumeAsyncIterator, replicateAsyncIterator, traceAsyncIterator, wrapAsyncIterator } from "./iterator.js";
13
+ import { NullProtoObj, Segment, bindMethods, clone, copyOnWrite, findDeepMatches, get, getConstructor, getConstructors, getOwn, isPlainObject, isPlainObjectOrArray, isPropertyKey, mergeTwoLevels, omit, pick, set, setOwn } from "./object.js";
14
+ import { OrderablePlugin, sortPlugins } from "./plugin.js";
15
+ import { captureAsyncContext, promiseWithResolvers } from "./promise.js";
16
+ import { override } from "./proxy.js";
17
+ import { AsyncIdQueue, AsyncIdQueueCloseOptions } from "./queue.js";
18
+ import { INTEGER_REGEX, NON_NEGATIVE_INTEGER_REGEX } from "./regex.js";
19
+ import { DisposableAllAbortSignal, anyAbortSignal, disposableAllAbortSignal, listenAbort, runWithSignal } from "./signal.js";
20
+ import { ReadableStreamReadResult, WrapReadableStreamOptions, asyncIteratorToStream, asyncIteratorToUnproxiedDataStream, replicateReadableStream, streamToAsyncIteratorObject, traceReadableStream, wrapReadableStream } from "./stream.js";
21
+ import { StartSpanOptions, Tracer, TracingAttributeValue, TracingException, TracingExceptionLevel, TracingHeaders, TracingSpan, getTracer, recordSpanError, runInSpanContext, runWithSpan, setSpanAttributeIfDefined, setTracer, startSpan, toSpanAttributeValue, toTracingException } from "./tracing.js";
22
+ import { DistributiveOmit, IntersectPick, PromiseWithError, Public, Registry, ThrowableError } from "./types.js";
23
+ import { Value, value } from "./value.js";
24
+ import { AbortError, AsyncCleanupFn, AsyncIteratorClass, AsyncIteratorClassNextFn, SequentialIdGenerator, getOrBind, isAsyncIteratorObject, isNonPrimitive, isNonPrimitive as isTypescriptObject, parseEmptyableJSON, safeDecodeURIComponent, safeEncodeURIComponent, sequential, sleep, stringifyJSON, throwIfAborted, toArray } from "@standard-server/shared";
25
+ import { Arrayable, IsEqual, PartialDeep, Promisable, Writable } from "type-fest";
26
+ export { AbortError, AnyFunction, type Arrayable, type AsyncCleanupFn, AsyncIdQueue, AsyncIdQueueCloseOptions, AsyncIteratorClass, type AsyncIteratorClassNextFn, CompressionEncoding, ConsumeAsyncIteratorOptions, DEFAULT_MAX_BIGINT_DIGITS, DisposableAllAbortSignal, DistributiveOmit, INTEGER_REGEX, InterceptableOptions, Interceptor, InterceptorOptions, IntersectPick, type IsEqual, MaybeOptionalOptions, NON_NEGATIVE_INTEGER_REGEX, NullProtoObj, ORPC_NAME, OnFinishState, OrderablePlugin, type PartialDeep, type Promisable, PromiseWithError, Public, ReadableStreamReadResult, Registry, Segment, SequentialIdGenerator, StartSpanOptions, ThrowableError, Tracer, TracingAttributeValue, TracingException, TracingExceptionLevel, TracingHeaders, TracingSpan, Value, WrapAsyncIteratorOptions, WrapReadableStreamOptions, type Writable, anyAbortSignal, asyncIteratorToStream, asyncIteratorToUnproxiedDataStream, bindMethods, captureAsyncContext, clone, compareSequentialIds, consumeAsyncIterator, copyOnWrite, defer, disposableAllAbortSignal, encodeBase64, estimateCompressibleFormDataSize, estimateUtf8ByteLength, findDeepMatches, get, getConstructor, getConstructors, getOrBind, getOwn, getTracer, intercept, isAbortError, isAcceptableEncoding, isAsyncGeneratorFunction, isAsyncIteratorObject, isCompressibleContentType, isCompressionEncoding, isDeepEqual, isNoTransformCacheControl, isNonPrimitive, isPlainObject as isObject, isPlainObject, isPlainObjectOrArray, isPropertyKey, isTypescriptObject, listenAbort, loadBytes, matchesHttpPath, matchesHttpPathPrefix, mergeHttpPath, mergeTwoLevels, normalizeHttpPath, omit, onAsyncIteratorObjectError, onError, onFinish, onReadableStreamError, onStart, onSuccess, once, override, parseAcceptEncodingQualities, parseBigIntString, parseContentEncodings, parseEmptyableJSON, pathToHttpPath, pick, promiseWithResolvers, recordSpanError, replicateAsyncIterator, replicateReadableStream, resolveMaybeOptionalOptions, runInSpanContext, runWithSignal, runWithSpan, safeDecodeURIComponent, safeEncodeURIComponent, sequential, set, setOwn, setSpanAttributeIfDefined, setTracer, sleep, sortPlugins, splitInHalf, startSpan, streamToAsyncIteratorObject, stringifyJSON, stripHttpPathPrefix, takeLast, throwIfAborted, toArray, toSpanAttributeValue, toStringOrBytes, toTracingException, traceAsyncIterator, traceReadableStream, tryOrUndefined, value, varyByAcceptEncoding, wrapAsyncIterator, wrapReadableStream };
package/dist/index.js CHANGED
@@ -1,32 +1,23 @@
1
- export * from './args.js';
2
- export * from './array.js';
3
- export * from './bigint.js';
4
- export * from './buffer.js';
5
- export * from './compare.js';
6
- export * from './consts.js';
7
- export * from './error.js';
8
- export * from './function.js';
9
- export * from './http.js';
10
- export * from './id.js';
11
- export * from './interceptor.js';
12
- export * from './iterator.js';
13
- export * from './object.js';
14
- export * from './plugin.js';
15
- export * from './promise.js';
16
- export * from './proxy.js';
17
- export * from './queue.js';
18
- export * from './signal.js';
19
- export * from './stream.js';
20
- export * from './tracing.js';
21
- export * from './types.js';
22
- export * from './value.js';
23
- export {
24
- /**
25
- * @deprecated Use `isPlainObject` instead.
26
- */
27
- isPlainObject as isObject, } from './object.js';
28
- export { AbortError, AsyncIteratorClass, getOrBind, isAsyncIteratorObject, isNonPrimitive,
29
- /**
30
- * @deprecated Use `isNonPrimitive` instead.
31
- */
32
- isNonPrimitive as isTypescriptObject, parseEmptyableJSON, safeDecodeURIComponent, safeEncodeURIComponent, sequential, SequentialIdGenerator, sleep, stringifyJSON, throwIfAborted, toArray, } from '@standard-server/shared';
1
+ export { resolveMaybeOptionalOptions } from "./args.js";
2
+ export { splitInHalf, takeLast } from "./array.js";
3
+ export { DEFAULT_MAX_BIGINT_DIGITS, parseBigIntString } from "./bigint.js";
4
+ export { encodeBase64, loadBytes, toStringOrBytes } from "./buffer.js";
5
+ export { isDeepEqual } from "./compare.js";
6
+ export { ORPC_NAME } from "./consts.js";
7
+ export { isAbortError } from "./error.js";
8
+ export { defer, isAsyncGeneratorFunction, once, tryOrUndefined } from "./function.js";
9
+ export { estimateCompressibleFormDataSize, estimateUtf8ByteLength, isAcceptableEncoding, isCompressibleContentType, isCompressionEncoding, isNoTransformCacheControl, matchesHttpPath, matchesHttpPathPrefix, mergeHttpPath, normalizeHttpPath, parseAcceptEncodingQualities, parseContentEncodings, pathToHttpPath, stripHttpPathPrefix, varyByAcceptEncoding } from "./http.js";
10
+ export { compareSequentialIds } from "./id.js";
11
+ export { intercept, onAsyncIteratorObjectError, onError, onFinish, onReadableStreamError, onStart, onSuccess } from "./interceptor.js";
12
+ export { consumeAsyncIterator, replicateAsyncIterator, traceAsyncIterator, wrapAsyncIterator } from "./iterator.js";
13
+ export { NullProtoObj, bindMethods, clone, copyOnWrite, findDeepMatches, get, getConstructor, getConstructors, getOwn, isPlainObject as isObject, isPlainObject, isPlainObjectOrArray, isPropertyKey, mergeTwoLevels, omit, pick, set, setOwn } from "./object.js";
14
+ export { sortPlugins } from "./plugin.js";
15
+ export { captureAsyncContext, promiseWithResolvers } from "./promise.js";
16
+ export { override } from "./proxy.js";
17
+ export { AsyncIdQueue } from "./queue.js";
18
+ export { INTEGER_REGEX, NON_NEGATIVE_INTEGER_REGEX } from "./regex.js";
19
+ export { anyAbortSignal, disposableAllAbortSignal, listenAbort, runWithSignal } from "./signal.js";
20
+ export { asyncIteratorToStream, asyncIteratorToUnproxiedDataStream, replicateReadableStream, streamToAsyncIteratorObject, traceReadableStream, wrapReadableStream } from "./stream.js";
21
+ export { getTracer, recordSpanError, runInSpanContext, runWithSpan, setSpanAttributeIfDefined, setTracer, startSpan, toSpanAttributeValue, toTracingException } from "./tracing.js";
22
+ export { value } from "./value.js";
23
+ export { AbortError, AsyncIteratorClass, SequentialIdGenerator, getOrBind, isAsyncIteratorObject, isNonPrimitive, isNonPrimitive as isTypescriptObject, parseEmptyableJSON, safeDecodeURIComponent, safeEncodeURIComponent, sequential, sleep, stringifyJSON, throwIfAborted, toArray } from "@standard-server/shared";
@@ -1,22 +1,22 @@
1
- import type { Promisable } from 'type-fest';
2
- import type { PromiseWithError, ThrowableError } from './types.ts';
1
+ import { PromiseWithError, ThrowableError } from "./types.js";
2
+ import { Promisable } from "type-fest";
3
3
  export type InterceptableOptions = Record<string, any>;
4
- export type InterceptorOptions<TOptions extends InterceptableOptions, TResult> = Omit<TOptions, 'next'> & {
5
- next(options?: TOptions): TResult;
4
+ export type InterceptorOptions<TOptions extends InterceptableOptions, TResult> = Omit<TOptions, "next"> & {
5
+ next(options?: TOptions): TResult;
6
6
  };
7
7
  export type Interceptor<TOptions extends InterceptableOptions, TResult> = (options: InterceptorOptions<TOptions, TResult>) => TResult;
8
8
  /**
9
9
  * Can used for interceptors or middlewares
10
10
  */
11
11
  export declare function onStart<T, TOptions extends {
12
- next: () => any;
13
- }, TRest extends any[]>(callback: NoInfer<(options: TOptions, ...rest: TRest) => Promisable<void>>): (options: TOptions, ...rest: TRest) => T | Promise<Awaited<ReturnType<TOptions['next']>>>;
12
+ next: () => any;
13
+ }, TRest extends any[]>(callback: NoInfer<(options: TOptions, ...rest: TRest) => Promisable<void>>): (options: TOptions, ...rest: TRest) => T | Promise<Awaited<ReturnType<TOptions["next"]>>>;
14
14
  /**
15
15
  * Can used for interceptors or middlewares
16
16
  */
17
17
  export declare function onSuccess<T, TOptions extends {
18
- next: () => any;
19
- }, TRest extends any[]>(callback: NoInfer<(result: Awaited<ReturnType<TOptions['next']>>, options: TOptions, ...rest: TRest) => Promisable<void>>): (options: TOptions, ...rest: TRest) => T | Promise<Awaited<ReturnType<TOptions['next']>>>;
18
+ next: () => any;
19
+ }, TRest extends any[]>(callback: NoInfer<(result: Awaited<ReturnType<TOptions["next"]>>, options: TOptions, ...rest: TRest) => Promisable<void>>): (options: TOptions, ...rest: TRest) => T | Promise<Awaited<ReturnType<TOptions["next"]>>>;
20
20
  /**
21
21
  * Creates an interceptor or middleware that invokes a callback whenever an error
22
22
  * is thrown. The error is rethrown after the callback completes.
@@ -24,15 +24,15 @@ export declare function onSuccess<T, TOptions extends {
24
24
  * @see {@link https://orpc.dev/docs/adapters/fetch-api | Fetch API Adapter}
25
25
  */
26
26
  export declare function onError<T, TOptions extends {
27
- next: () => any;
28
- }, TRest extends any[]>(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']>>>;
27
+ next: () => any;
28
+ }, TRest extends any[]>(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"]>>>;
29
29
  export type OnFinishState<TResult, TError> = [error: TError, data: undefined, isSuccess: false] | [error: null, data: TResult, isSuccess: true];
30
30
  /**
31
31
  * Can used for interceptors or middlewares
32
32
  */
33
33
  export declare function onFinish<T, TOptions extends {
34
- next: () => any;
35
- }, TRest extends any[]>(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']>>>;
34
+ next: () => any;
35
+ }, TRest extends any[]>(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"]>>>;
36
36
  /**
37
37
  * Creates a middleware or interceptor that invokes a callback when the returned async
38
38
  * iterator object throws an error while being consumed.
@@ -43,8 +43,8 @@ export declare function onFinish<T, TOptions extends {
43
43
  * catch all possible errors.
44
44
  */
45
45
  export declare function onAsyncIteratorObjectError<T, TOptions extends {
46
- next: () => any;
47
- }, TRest extends any[]>(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']>>>;
46
+ next: () => any;
47
+ }, TRest extends any[]>(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"]>>>;
48
48
  /**
49
49
  * Creates an interceptor that invokes a callback when the returned readable
50
50
  * stream errors while being consumed.
@@ -55,6 +55,6 @@ export declare function onAsyncIteratorObjectError<T, TOptions extends {
55
55
  * all possible errors.
56
56
  */
57
57
  export declare function onReadableStreamError<T, TOptions extends {
58
- next: () => any;
59
- }, TRest extends any[]>(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']>>>;
60
- export declare function intercept<TOptions extends InterceptableOptions, TResult>(interceptors: undefined | Interceptor<TOptions, TResult>[], options: NoInfer<TOptions>, main: NoInfer<(options: TOptions) => TResult>): TResult;
58
+ next: () => any;
59
+ }, TRest extends any[]>(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"]>>>;
60
+ export declare function intercept<TOptions extends InterceptableOptions, TResult>(interceptors: undefined | Interceptor<TOptions, TResult>[], options: NoInfer<TOptions>, main: NoInfer<(options: TOptions) => TResult>): TResult;