@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.
- package/dist/args.d.ts +1 -1
- package/dist/args.js +4 -2
- package/dist/array.d.ts +4 -1
- package/dist/array.js +11 -5
- package/dist/bigint.d.ts +1 -1
- package/dist/bigint.js +12 -16
- package/dist/buffer.d.ts +4 -4
- package/dist/buffer.js +44 -67
- package/dist/compare.d.ts +1 -1
- package/dist/compare.js +23 -42
- package/dist/consts.d.ts +1 -1
- package/dist/consts.js +3 -1
- package/dist/error.d.ts +1 -1
- package/dist/error.js +4 -2
- package/dist/function.d.ts +1 -1
- package/dist/function.js +27 -32
- package/dist/http.d.ts +29 -0
- package/dist/http.js +128 -94
- package/dist/id.d.ts +1 -1
- package/dist/id.js +11 -11
- package/dist/index.d.ts +26 -34
- package/dist/index.js +23 -32
- package/dist/interceptor.d.ts +17 -17
- package/dist/interceptor.js +106 -126
- package/dist/iterator.d.ts +41 -41
- package/dist/iterator.js +136 -152
- package/dist/object.d.ts +10 -8
- package/dist/object.js +176 -227
- package/dist/plugin.d.ts +7 -7
- package/dist/plugin.js +41 -57
- package/dist/promise.d.ts +4 -4
- package/dist/promise.js +28 -28
- package/dist/proxy.d.ts +2 -2
- package/dist/proxy.js +23 -22
- package/dist/queue.d.ts +13 -13
- package/dist/queue.js +64 -79
- package/dist/regex.d.ts +9 -0
- package/dist/regex.js +11 -0
- package/dist/signal.d.ts +7 -2
- package/dist/signal.js +83 -80
- package/dist/stream.d.ts +23 -23
- package/dist/stream.js +118 -144
- package/dist/tracing.d.ts +50 -50
- package/dist/tracing.js +60 -85
- package/dist/types.d.ts +7 -10
- package/dist/value.d.ts +1 -1
- package/dist/value.js +5 -5
- package/package.json +2 -2
- package/dist/types.js +0 -1
package/dist/http.js
CHANGED
|
@@ -1,113 +1,147 @@
|
|
|
1
|
-
import { safeDecodeURIComponent, safeEncodeURIComponent } from
|
|
2
|
-
|
|
3
|
-
|
|
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
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
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
|
-
|
|
13
|
-
|
|
11
|
+
function mergeHttpPath(a, b) {
|
|
12
|
+
return `${a.endsWith("/") ? a.slice(0, -1) : a}${b}`;
|
|
14
13
|
}
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
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
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
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
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
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
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
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
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
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
|
-
|
|
89
|
-
|
|
90
|
-
|
|
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
|
-
|
|
94
|
-
|
|
95
|
-
|
|
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
|
-
|
|
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
|
-
|
|
106
|
-
|
|
107
|
-
|
|
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
package/dist/id.js
CHANGED
|
@@ -1,13 +1,13 @@
|
|
|
1
|
+
// src/id.ts
|
|
1
2
|
/**
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
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
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
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
|
|
2
|
-
export
|
|
3
|
-
export
|
|
4
|
-
export
|
|
5
|
-
export
|
|
6
|
-
export
|
|
7
|
-
export
|
|
8
|
-
export
|
|
9
|
-
export
|
|
10
|
-
export
|
|
11
|
-
export
|
|
12
|
-
export
|
|
13
|
-
export
|
|
14
|
-
export
|
|
15
|
-
export
|
|
16
|
-
export
|
|
17
|
-
export
|
|
18
|
-
export
|
|
19
|
-
export
|
|
20
|
-
export
|
|
21
|
-
export
|
|
22
|
-
export
|
|
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";
|
package/dist/interceptor.d.ts
CHANGED
|
@@ -1,22 +1,22 @@
|
|
|
1
|
-
import
|
|
2
|
-
import
|
|
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,
|
|
5
|
-
|
|
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
|
-
|
|
13
|
-
}, TRest extends any[]>(callback: NoInfer<(options: TOptions, ...rest: TRest) => Promisable<void>>): (options: TOptions, ...rest: TRest) => T | Promise<Awaited<ReturnType<TOptions[
|
|
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
|
-
|
|
19
|
-
}, TRest extends any[]>(callback: NoInfer<(result: Awaited<ReturnType<TOptions[
|
|
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
|
-
|
|
28
|
-
}, TRest extends any[]>(callback: NoInfer<(error: ReturnType<TOptions[
|
|
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
|
-
|
|
35
|
-
}, TRest extends any[]>(callback: NoInfer<(state: OnFinishState<Awaited<ReturnType<TOptions[
|
|
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
|
-
|
|
47
|
-
}, TRest extends any[]>(callback: NoInfer<(error: ThrowableError | (ReturnType<TOptions[
|
|
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
|
-
|
|
59
|
-
}, TRest extends any[]>(callback: NoInfer<(error: ThrowableError | (ReturnType<TOptions[
|
|
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;
|