@orpc/shared 2.0.0-beta.5 → 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 (51) hide show
  1. package/README.md +137 -102
  2. package/dist/args.d.ts +2 -0
  3. package/dist/args.js +5 -0
  4. package/dist/array.d.ts +5 -0
  5. package/dist/array.js +13 -0
  6. package/dist/bigint.d.ts +9 -0
  7. package/dist/bigint.js +15 -0
  8. package/dist/buffer.d.ts +18 -0
  9. package/dist/buffer.js +54 -0
  10. package/dist/compare.d.ts +1 -0
  11. package/dist/compare.js +26 -0
  12. package/dist/consts.d.ts +1 -0
  13. package/dist/consts.js +3 -0
  14. package/dist/error.d.ts +1 -0
  15. package/dist/error.js +5 -0
  16. package/dist/function.d.ts +12 -0
  17. package/dist/function.js +33 -0
  18. package/dist/http.d.ts +58 -0
  19. package/dist/http.js +147 -0
  20. package/dist/id.d.ts +8 -0
  21. package/dist/id.js +13 -0
  22. package/dist/index.d.ts +26 -306
  23. package/dist/index.js +23 -0
  24. package/dist/interceptor.d.ts +60 -0
  25. package/dist/interceptor.js +119 -0
  26. package/dist/iterator.d.ts +56 -0
  27. package/dist/iterator.js +141 -0
  28. package/dist/object.d.ts +62 -0
  29. package/dist/object.js +194 -0
  30. package/dist/plugin.d.ts +12 -0
  31. package/dist/plugin.js +45 -0
  32. package/dist/promise.d.ts +17 -0
  33. package/dist/promise.js +32 -0
  34. package/dist/proxy.d.ts +12 -0
  35. package/dist/proxy.js +25 -0
  36. package/dist/queue.d.ts +16 -0
  37. package/dist/queue.js +64 -0
  38. package/dist/regex.d.ts +9 -0
  39. package/dist/regex.js +11 -0
  40. package/dist/signal.d.ts +23 -0
  41. package/dist/signal.js +88 -0
  42. package/dist/stream.d.ts +48 -0
  43. package/dist/stream.js +129 -0
  44. package/dist/tracing.d.ts +73 -0
  45. package/dist/tracing.js +69 -0
  46. package/dist/types.d.ts +23 -0
  47. package/dist/value.d.ts +2 -0
  48. package/dist/value.js +6 -0
  49. package/package.json +22 -30
  50. package/dist/index.d.mts +0 -306
  51. package/dist/index.mjs +0 -892
package/package.json CHANGED
@@ -1,50 +1,42 @@
1
1
  {
2
2
  "name": "@orpc/shared",
3
- "type": "module",
4
- "version": "2.0.0-beta.5",
5
- "license": "MIT",
3
+ "version": "2.0.0-beta.50",
4
+ "description": "Internal utilities shared across oRPC packages",
5
+ "keywords": [
6
+ "orpc"
7
+ ],
6
8
  "homepage": "https://orpc.dev",
9
+ "license": "MIT",
7
10
  "repository": {
8
11
  "type": "git",
9
12
  "url": "git+https://github.com/middleapi/orpc.git",
10
13
  "directory": "packages/shared"
11
14
  },
12
- "keywords": [
13
- "orpc"
15
+ "funding": [
16
+ "https://github.com/sponsors/dinwwwh",
17
+ "https://opencollective.com/middleapi"
18
+ ],
19
+ "files": [
20
+ "dist"
14
21
  ],
22
+ "type": "module",
15
23
  "sideEffects": false,
16
24
  "exports": {
17
25
  "./package.json": "./package.json",
18
26
  ".": {
19
- "types": "./dist/index.d.mts",
20
- "import": "./dist/index.mjs",
21
- "default": "./dist/index.mjs"
22
- }
23
- },
24
- "files": [
25
- "dist"
26
- ],
27
- "peerDependencies": {
28
- "@opentelemetry/api": ">=1.9.0"
29
- },
30
- "peerDependenciesMeta": {
31
- "@opentelemetry/api": {
32
- "optional": true
27
+ "types": "./dist/index.d.ts",
28
+ "import": "./dist/index.js",
29
+ "default": "./dist/index.js"
33
30
  }
34
31
  },
35
32
  "dependencies": {
36
- "@standardserver/shared": "^0.0.25",
37
- "radash": "^12.1.1",
38
- "type-fest": "^5.3.1"
33
+ "@standard-server/shared": "~0.16.0",
34
+ "type-fest": "^5.10.0"
39
35
  },
40
36
  "devDependencies": {
41
- "@opentelemetry/api": "^1.9.0",
42
- "arktype": "^2.1.29",
43
- "valibot": "^1.2.0",
44
- "zod": "^4.4.3"
37
+ "arktype": "^2.2.9",
38
+ "valibot": "^1.5.0",
39
+ "zod": "^4.6.7"
45
40
  },
46
- "scripts": {
47
- "build": "unbuild",
48
- "type:check": "tsc -b"
49
- }
41
+ "scripts": {}
50
42
  }
package/dist/index.d.mts DELETED
@@ -1,306 +0,0 @@
1
- import { Promisable } from 'type-fest';
2
- export { IsEqual, PartialDeep, Promisable, Writable } from 'type-fest';
3
- import { Tracer, TraceAPI, ContextAPI, PropagationAPI, SpanOptions, Context, Span, AttributeValue, Exception } from '@opentelemetry/api';
4
- import { AsyncIteratorClass } from '@standardserver/shared';
5
- export { AbortError, AsyncCleanupFn, AsyncIteratorClass, AsyncIteratorClassNextFn, SequentialIdGenerator, getOrBind, isAsyncIteratorObject, isTypescriptObject, parseEmptyableJSON, sleep, stringifyJSON, toArray } from '@standardserver/shared';
6
-
7
- type MaybeOptionalOptions<TOptions> = object extends TOptions ? [options?: TOptions] : [options: TOptions];
8
- declare function resolveMaybeOptionalOptions<T>(rest: MaybeOptionalOptions<T>): T;
9
-
10
- declare function splitInHalf<T>(arr: readonly T[]): [T[], T[]];
11
-
12
- /**
13
- * Load Request/Response/Blob/File/.. to a buffer (Uint8Array<ArrayBuffer>).
14
- *
15
- * Prefers the newer `.bytes` method when available as it more efficient but not widely supported yet.
16
- */
17
- declare function loadBytes(source: Pick<Blob, 'arrayBuffer' | 'bytes'>): Promise<Uint8Array<ArrayBuffer>>;
18
- /**
19
- * Normalize text or binary-like inputs to either:
20
- * - the original string value, or
21
- * - a Uint8Array view over the source bytes.
22
- */
23
- declare function toStringOrBytes(source: string | ArrayBuffer | Blob | Exclude<ConstructorParameters<typeof Blob>[0], undefined>[0][] | Pick<Uint8Array<ArrayBuffer>, 'buffer' | 'byteOffset' | 'byteLength'>): Promise<string | Uint8Array<ArrayBuffer>>;
24
-
25
- declare function isDeepEqual(a: unknown, b: unknown): boolean;
26
-
27
- declare const ORPC_NAME = "orpc";
28
-
29
- declare function isAbortError(error: unknown): error is Error;
30
-
31
- type AnyFunction = (...args: any[]) => any;
32
- declare function once<T>(fn: () => T): () => T;
33
- /**
34
- * Executes the callback function after the current call stack has been cleared.
35
- */
36
- declare function defer(callback: () => void): void;
37
- declare function tryOrUndefined<T>(fn: () => T): undefined | T;
38
-
39
- declare function pathToHttpPath(path: readonly string[]): `/${string}`;
40
- declare function normalizeHttpPath(path: string): `/${string}`;
41
- declare function mergeHttpPath(a: `/${string}`, b: `/${string}`): `/${string}`;
42
- declare function matchesHttpPathPrefix(url: `/${string}`, prefix: `/${string}`): boolean;
43
- declare function matchesHttpPath(url: `/${string}`, path: `/${string}`): boolean;
44
-
45
- /**
46
- * Compares two sequential IDs.
47
- * Returns:
48
- * - negative if `a` < `b`
49
- * - positive if `a` > `b`
50
- * - 0 if equal
51
- */
52
- declare function compareSequentialIds(a: string, b: string): number;
53
-
54
- type IntersectPick<T, U> = Pick<T, keyof T & keyof U>;
55
- /**
56
- * Remove protected/private properties/methods
57
- */
58
- type Public<T> = Pick<T, keyof T>;
59
- type PromiseWithError<T, TError> = Promise<T> & {
60
- __error?: {
61
- type: TError;
62
- };
63
- };
64
- /**
65
- * The place where you can config the orpc types.
66
- *
67
- * - `ThrowableError` the error type that represent throwable errors should be `Error` or `null | undefined | {}` if you want more strict.
68
- */
69
- interface Registry {
70
- }
71
- type ThrowableError = Registry extends {
72
- ThrowableError: infer T;
73
- } ? T : Error;
74
-
75
- type InterceptableOptions = Record<string, any>;
76
- type InterceptorOptions<TOptions extends InterceptableOptions, TResult> = Omit<TOptions, 'next'> & {
77
- next(options?: TOptions): TResult;
78
- };
79
- type Interceptor<TOptions extends InterceptableOptions, TResult> = (options: InterceptorOptions<TOptions, TResult>) => TResult;
80
- /**
81
- * Can used for interceptors or middlewares
82
- */
83
- declare function onStart<T, TOptions extends {
84
- next: () => any;
85
- }, TRest extends any[]>(callback: NoInfer<(options: TOptions, ...rest: TRest) => Promisable<void>>): (options: TOptions, ...rest: TRest) => T | Promise<Awaited<ReturnType<TOptions['next']>>>;
86
- /**
87
- * Can used for interceptors or middlewares
88
- */
89
- declare function onSuccess<T, TOptions extends {
90
- next: () => any;
91
- }, 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']>>>;
92
- /**
93
- * Can used for interceptors or middlewares
94
- */
95
- declare function onError<T, TOptions extends {
96
- next: () => any;
97
- }, 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']>>>;
98
- type OnFinishState<TResult, TError> = [error: TError, data: undefined, isSuccess: false] | [error: null, data: TResult, isSuccess: true];
99
- /**
100
- * Can used for interceptors or middlewares
101
- */
102
- declare function onFinish<T, TOptions extends {
103
- next: () => any;
104
- }, 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']>>>;
105
- declare function intercept<TOptions extends InterceptableOptions, TResult>(interceptors: undefined | Interceptor<TOptions, TResult>[], options: NoInfer<TOptions>, main: NoInfer<(options: TOptions) => TResult>): TResult;
106
-
107
- /**
108
- * Only import types from @opentelemetry/api to avoid runtime dependencies.
109
- */
110
-
111
- interface OpenTelemetryConfig {
112
- tracer: Tracer;
113
- trace: TraceAPI;
114
- context: ContextAPI;
115
- /**
116
- * propagation is optional, can reduce bundle size in some cases.
117
- */
118
- propagation?: PropagationAPI | undefined;
119
- }
120
- declare function setOpenTelemetryConfig(config: OpenTelemetryConfig | undefined): void;
121
- declare function getOpenTelemetryConfig(): OpenTelemetryConfig | undefined;
122
- interface StartSpanOptions extends SpanOptions {
123
- /**
124
- * The name of the span to create.
125
- */
126
- name: string;
127
- /**
128
- * Context to use for the created span.
129
- */
130
- context?: Context;
131
- }
132
- declare function startSpan(options: StartSpanOptions | string): Span | undefined;
133
- declare function recordSpanError(span: Span | undefined, error: unknown): void;
134
- declare function setSpanAttributeIfDefined(span: Span | undefined, key: string, value: AttributeValue | undefined): void;
135
- declare function toOtelException(error: unknown): Exclude<Exception, string>;
136
- declare function toSpanAttributeValue(data: unknown): string;
137
- interface RunWithSpanOptions extends StartSpanOptions {
138
- }
139
- declare function runWithSpan<T>(options: string | RunWithSpanOptions, fn: (span?: Span) => Promisable<T>): Promise<T>;
140
- declare function runInSpanContext<T>(span: Span | undefined, fn: () => Promisable<T>): Promise<T>;
141
-
142
- interface WrapAsyncIteratorOptions<TYield, TReturn, TMappedYield, TMappedReturn> {
143
- /**
144
- * Any call to the original iterator will be executed inside this function.
145
- * Useful when you want execution to happen within a specific context,
146
- * such as AsyncLocalStorage.
147
- */
148
- runWith?: <T>(run: () => Promise<T>) => Promise<T>;
149
- mapResult?: (result: IteratorResult<TYield, TReturn>) => Promisable<IteratorResult<TMappedYield, TMappedReturn>>;
150
- mapError?: (error: unknown) => Promisable<unknown>;
151
- onError?: (error: unknown) => Promisable<void>;
152
- /**
153
- * Execute after the stream finishes or is cancelled.
154
- */
155
- onFinish?: () => Promisable<void>;
156
- }
157
- declare function wrapAsyncIterator<TYield, TReturn, TMappedYield = TYield, TMappedReturn = TReturn>(iterator: AsyncIterator<TYield, TReturn>, { runWith, mapResult, mapError, onError, onFinish }: WrapAsyncIteratorOptions<TYield, TReturn, TMappedYield, TMappedReturn>): NoInfer<AsyncIteratorClass<TMappedYield, TMappedReturn>>;
158
- declare function traceAsyncIterator<T, TReturn, TNext>(options: StartSpanOptions | string, iterator: AsyncIterator<T, TReturn, TNext>): AsyncIteratorClass<T, TReturn, TNext>;
159
- declare function replicateAsyncIterator<T, TReturn, TNext>(source: AsyncIterator<T, TReturn, TNext>, count: number): (AsyncIteratorClass<T, TReturn, TNext>)[];
160
-
161
- type Segment = string | number;
162
- declare function findDeepMatches(check: (value: unknown) => boolean, payload: unknown, segments?: Segment[], maps?: Segment[][], values?: unknown[]): {
163
- maps: Segment[][];
164
- values: unknown[];
165
- };
166
- /**
167
- * Get constructor of the value
168
- *
169
- */
170
- declare function getConstructor(value: unknown): Function | null | undefined;
171
- /**
172
- * Checks whether a value is a plain object, including objects created with
173
- * `Object.create(null)`.
174
- */
175
- declare function isPlainObject(value: unknown): value is Record<PropertyKey, unknown>;
176
- declare function get(object: unknown, path: readonly PropertyKey[]): unknown;
177
- /**
178
- * Sets a value at the given path, creating plain objects for intermediate keys as needed.
179
- */
180
- declare function set(root: object, path: [PropertyKey, ...PropertyKey[]] | [...PropertyKey[], PropertyKey], value: unknown): void;
181
- declare function omit<T extends object, K extends keyof T>(obj: T, keys: readonly K[]): Omit<T, K>;
182
- declare function clone<T>(value: T): T;
183
- declare function isPropertyKey(value: unknown): value is PropertyKey;
184
- declare const NullProtoObj: ({
185
- new <T extends Record<PropertyKey, unknown>>(): T;
186
- });
187
- /**
188
- * Returns an object containing all methods of the given object, with each
189
- * method bound to the original object instance.
190
- *
191
- * Methods are collected from both the object itself and its prototype chain
192
- * (excluding `Object.prototype` and the `constructor` property).
193
- */
194
- declare function bindMethods<T extends object>(obj: T): Pick<T, {
195
- [K in keyof T]: T[K] extends AnyFunction ? K : never;
196
- }[keyof T]>;
197
-
198
- interface OrderablePlugin {
199
- /** Unique name of the plugin, used for ordering and identification. */
200
- name: string;
201
- /** Plugins this plugin should execute before. */
202
- before?: string[] | undefined;
203
- /** Plugins this plugin should execute after. */
204
- after?: string[] | undefined;
205
- }
206
- /**
207
- * Sorts plugins based on their `before` and `after` dependencies.
208
- */
209
- declare function sortPlugins<T extends OrderablePlugin>(plugins: T[]): T[];
210
-
211
- /**
212
- * Creates a promise together with its associated `resolve` and `reject`
213
- * functions.
214
- *
215
- * Equivalent to `Promise.withResolvers()`, but works in environments
216
- * where that API is not yet available.
217
- */
218
- declare function promiseWithResolvers<T>(): {
219
- promise: Promise<T>;
220
- resolve: (v: T) => void;
221
- reject: (reason: unknown) => void;
222
- };
223
-
224
- type Value<T, TArgs extends any[] = []> = T | ((...args: TArgs) => T);
225
- declare function value<T, TArgs extends any[]>(value: Value<T, TArgs>, ...args: NoInfer<TArgs>): T extends Value<infer U, any> ? U : never;
226
-
227
- /**
228
- * Creates a proxy that overlays a `partial` object on top of a `target`.
229
- *
230
- * - Properties from `partial` take precedence.
231
- * - Properties not present in `partial` fall back to the resolved `target`.
232
- * - Methods are bound to the proxy to ensure a consistent `this` context.
233
- *
234
- * Useful for overriding specific properties of an object while delegating
235
- * all other access to the original target without needing to know its full structure.
236
- */
237
- declare function override<T extends object, U extends object>(target: Value<T>, partial: U): U & Omit<T, keyof U>;
238
-
239
- interface AsyncIdQueueCloseOptions {
240
- id?: string;
241
- reason?: unknown;
242
- }
243
- declare class AsyncIdQueue<T> {
244
- private readonly openIds;
245
- private readonly queues;
246
- private readonly waiters;
247
- get size(): number;
248
- open(id: string): void;
249
- isOpen(id: string): boolean;
250
- push(id: string, item: T): void;
251
- pull(id: string): Promise<T>;
252
- close({ id, reason }?: AsyncIdQueueCloseOptions): void;
253
- private assertOpen;
254
- }
255
-
256
- /**
257
- * Returns a signal that aborts only after all provided signals are aborted.
258
- */
259
- declare function allAbortSignal(signals: readonly (AbortSignal | undefined)[]): AbortSignal | undefined;
260
- declare function runWithSignal<T>(signal: AbortSignal | undefined, fn: () => Promise<T>): Promise<T>;
261
-
262
- declare function replicateReadableStream<T>(stream: ReadableStream<T>, count: number): ReadableStream<T>[];
263
- type ReadableStreamReadResult<T> = {
264
- done: false;
265
- value: T;
266
- } | {
267
- done: true;
268
- value: undefined | T;
269
- };
270
- interface WrapReadableStreamOptions<T, TMapped> {
271
- /**
272
- * Any call to the original stream reader will be executed inside this function.
273
- * Useful when you want execution to happen within a specific context,
274
- * such as AsyncLocalStorage.
275
- */
276
- runWith?: <T>(run: () => Promise<T>) => Promise<T>;
277
- mapResult?: (result: ReadableStreamReadResult<T>) => Promisable<ReadableStreamReadResult<TMapped>>;
278
- mapError?: (error: unknown) => Promisable<unknown>;
279
- onError?: (error: unknown) => Promisable<void>;
280
- /**
281
- * Guaranteed to execute exactly once after the stream finishes or is cancelled.
282
- */
283
- onFinish?: () => Promisable<void>;
284
- }
285
- declare function wrapReadableStream<T, TMapped = T>(stream: ReadableStream<T>, { runWith, mapResult, mapError, onError, onFinish }: WrapReadableStreamOptions<T, TMapped>): NoInfer<ReadableStream<TMapped>>;
286
- declare function traceReadableStream<T>(options: StartSpanOptions | string, stream: ReadableStream<T>): ReadableStream<T>;
287
- /**
288
- * Converts a `ReadableStream` into an `AsyncIteratorClass`.
289
- */
290
- declare function streamToAsyncIteratorClass<T>(stream: ReadableStream<T>, { signal }?: {
291
- signal?: undefined | AbortSignal;
292
- }): AsyncIteratorClass<T>;
293
- /**
294
- * Converts an `AsyncIterator` into a `ReadableStream`.
295
- */
296
- declare function asyncIteratorToStream<T>(iterator: AsyncIterator<T>): ReadableStream<T>;
297
- /**
298
- * Converts an `AsyncIterator` into a `ReadableStream`, ensuring that
299
- * all emitted object values are *unproxied* before enqueuing.
300
- */
301
- declare function asyncIteratorToUnproxiedDataStream<T>(iterator: AsyncIterator<T>): ReadableStream<T>;
302
-
303
- declare function tryDecodeURIComponent(value: string): string;
304
-
305
- export { AsyncIdQueue, NullProtoObj, ORPC_NAME, allAbortSignal, asyncIteratorToStream, asyncIteratorToUnproxiedDataStream, bindMethods, clone, compareSequentialIds, defer, findDeepMatches, get, getConstructor, getOpenTelemetryConfig, intercept, isAbortError, isDeepEqual, isPlainObject, isPropertyKey, loadBytes, matchesHttpPath, matchesHttpPathPrefix, mergeHttpPath, normalizeHttpPath, omit, onError, onFinish, onStart, onSuccess, once, override, pathToHttpPath, promiseWithResolvers, recordSpanError, replicateAsyncIterator, replicateReadableStream, resolveMaybeOptionalOptions, runInSpanContext, runWithSignal, runWithSpan, set, setOpenTelemetryConfig, setSpanAttributeIfDefined, sortPlugins, splitInHalf, startSpan, streamToAsyncIteratorClass, toOtelException, toSpanAttributeValue, toStringOrBytes, traceAsyncIterator, traceReadableStream, tryDecodeURIComponent, tryOrUndefined, value, wrapAsyncIterator, wrapReadableStream };
306
- export type { AnyFunction, AsyncIdQueueCloseOptions, InterceptableOptions, Interceptor, InterceptorOptions, IntersectPick, MaybeOptionalOptions, OnFinishState, OpenTelemetryConfig, OrderablePlugin, PromiseWithError, Public, ReadableStreamReadResult, Registry, RunWithSpanOptions, Segment, StartSpanOptions, ThrowableError, Value, WrapAsyncIteratorOptions, WrapReadableStreamOptions };