@orpc/shared 0.0.0-next.de766b3 → 0.0.0-next.de7ca70
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/README.md +1 -1
- package/dist/index.d.mts +20 -11
- package/dist/index.d.ts +20 -11
- package/dist/index.mjs +19 -14
- package/package.json +3 -3
package/README.md
CHANGED
|
@@ -35,7 +35,7 @@
|
|
|
35
35
|
- **🔗 End-to-End Type Safety**: Ensure type-safe inputs, outputs, and errors from client to server.
|
|
36
36
|
- **📘 First-Class OpenAPI**: Built-in support that fully adheres to the OpenAPI standard.
|
|
37
37
|
- **📝 Contract-First Development**: Optionally define your API contract before implementation.
|
|
38
|
-
- **⚙️ Framework Integrations**: Seamlessly integrate with TanStack Query (React, Vue, Solid, Svelte), Pinia Colada, and more.
|
|
38
|
+
- **⚙️ Framework Integrations**: Seamlessly integrate with TanStack Query (React, Vue, Solid, Svelte, Angular), Pinia Colada, and more.
|
|
39
39
|
- **🚀 Server Actions**: Fully compatible with React Server Actions on Next.js, TanStack Start, and other platforms.
|
|
40
40
|
- **🔠 Standard Schema Support**: Works out of the box with Zod, Valibot, ArkType, and other schema validators.
|
|
41
41
|
- **🗃️ Native Types**: Supports native types like Date, File, Blob, BigInt, URL, and more.
|
package/dist/index.d.mts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { Promisable } from 'type-fest';
|
|
2
|
-
export { IsEqual, IsNever, PartialDeep, Promisable } from 'type-fest';
|
|
2
|
+
export { IsEqual, IsNever, JsonValue, PartialDeep, Promisable } from 'type-fest';
|
|
3
3
|
export { group, guard, mapEntries, mapValues, omit } from 'radash';
|
|
4
4
|
|
|
5
5
|
type MaybeOptionalOptions<TOptions> = Record<never, never> extends TOptions ? [options?: TOptions] : [options: TOptions];
|
|
@@ -8,6 +8,13 @@ declare function resolveMaybeOptionalOptions<T>(rest: MaybeOptionalOptions<T>):
|
|
|
8
8
|
declare function toArray<T>(value: T): T extends readonly any[] ? T : Exclude<T, undefined | null>[];
|
|
9
9
|
declare function splitInHalf<T>(arr: readonly T[]): [T[], T[]];
|
|
10
10
|
|
|
11
|
+
/**
|
|
12
|
+
* Converts Request/Response/Blob/File/.. to a buffer (ArrayBuffer or Uint8Array).
|
|
13
|
+
*
|
|
14
|
+
* Prefers the newer `.bytes` method when available as it more efficient but not widely supported yet.
|
|
15
|
+
*/
|
|
16
|
+
declare function readAsBuffer(source: Pick<Blob, 'arrayBuffer' | 'bytes'>): Promise<ArrayBuffer | Uint8Array>;
|
|
17
|
+
|
|
11
18
|
type AnyFunction = (...args: any[]) => any;
|
|
12
19
|
declare function once<T extends () => any>(fn: T): () => ReturnType<T>;
|
|
13
20
|
declare function sequential<A extends any[], R>(fn: (...args: A) => Promise<R>): (...args: A) => Promise<R>;
|
|
@@ -80,8 +87,8 @@ declare class EventPublisher<T extends Record<PropertyKey, any>> {
|
|
|
80
87
|
}
|
|
81
88
|
|
|
82
89
|
declare class SequentialIdGenerator {
|
|
83
|
-
private
|
|
84
|
-
generate():
|
|
90
|
+
private index;
|
|
91
|
+
generate(): string;
|
|
85
92
|
}
|
|
86
93
|
|
|
87
94
|
type SetOptional<T, K extends keyof T> = Omit<T, K> & Partial<Pick<T, K>>;
|
|
@@ -160,7 +167,9 @@ declare class AsyncIteratorClass<T, TReturn = unknown, TNext = unknown> implemen
|
|
|
160
167
|
declare function replicateAsyncIterator<T, TReturn, TNext>(source: AsyncIterator<T, TReturn, TNext>, count: number): (AsyncIteratorClass<T, TReturn, TNext>)[];
|
|
161
168
|
|
|
162
169
|
declare function parseEmptyableJSON(text: string | null | undefined): unknown;
|
|
163
|
-
declare function stringifyJSON<T>(value: T
|
|
170
|
+
declare function stringifyJSON<T>(value: T | {
|
|
171
|
+
toJSON(): T;
|
|
172
|
+
}): undefined extends T ? undefined | string : string;
|
|
164
173
|
|
|
165
174
|
type Segment = string | number;
|
|
166
175
|
declare function findDeepMatches(check: (value: unknown) => boolean, payload: unknown, segments?: Segment[], maps?: Segment[][], values?: unknown[]): {
|
|
@@ -183,7 +192,7 @@ declare const NullProtoObj: ({
|
|
|
183
192
|
});
|
|
184
193
|
|
|
185
194
|
interface AsyncIdQueueCloseOptions {
|
|
186
|
-
id?:
|
|
195
|
+
id?: string;
|
|
187
196
|
reason?: unknown;
|
|
188
197
|
}
|
|
189
198
|
declare class AsyncIdQueue<T> {
|
|
@@ -191,16 +200,16 @@ declare class AsyncIdQueue<T> {
|
|
|
191
200
|
private readonly items;
|
|
192
201
|
private readonly pendingPulls;
|
|
193
202
|
get length(): number;
|
|
194
|
-
open(id:
|
|
195
|
-
isOpen(id:
|
|
196
|
-
push(id:
|
|
197
|
-
pull(id:
|
|
203
|
+
open(id: string): void;
|
|
204
|
+
isOpen(id: string): boolean;
|
|
205
|
+
push(id: string, item: T): void;
|
|
206
|
+
pull(id: string): Promise<T>;
|
|
198
207
|
close({ id, reason }?: AsyncIdQueueCloseOptions): void;
|
|
199
|
-
assertOpen(id:
|
|
208
|
+
assertOpen(id: string): void;
|
|
200
209
|
}
|
|
201
210
|
|
|
202
211
|
type Value<T, TArgs extends any[] = []> = T | ((...args: TArgs) => T);
|
|
203
212
|
declare function value<T, TArgs extends any[]>(value: Value<T, TArgs>, ...args: NoInfer<TArgs>): T extends Value<infer U, any> ? U : never;
|
|
204
213
|
|
|
205
|
-
export { AsyncIdQueue, AsyncIteratorClass, EventPublisher, NullProtoObj, SequentialIdGenerator, clone, defer, findDeepMatches, get, intercept, isAsyncIteratorObject, isObject, isPropertyKey, isTypescriptObject, onError, onFinish, onStart, onSuccess, once, parseEmptyableJSON, replicateAsyncIterator, resolveMaybeOptionalOptions, sequential, splitInHalf, stringifyJSON, toArray, value };
|
|
214
|
+
export { AsyncIdQueue, AsyncIteratorClass, EventPublisher, NullProtoObj, SequentialIdGenerator, clone, defer, findDeepMatches, get, intercept, isAsyncIteratorObject, isObject, isPropertyKey, isTypescriptObject, onError, onFinish, onStart, onSuccess, once, parseEmptyableJSON, readAsBuffer, replicateAsyncIterator, resolveMaybeOptionalOptions, sequential, splitInHalf, stringifyJSON, toArray, value };
|
|
206
215
|
export type { AnyFunction, AsyncIdQueueCloseOptions, AsyncIteratorClassCleanupFn, AsyncIteratorClassNextFn, EventPublisherOptions, EventPublisherSubscribeIteratorOptions, InterceptableOptions, Interceptor, InterceptorOptions, IntersectPick, MaybeOptionalOptions, OmitChainMethodDeep, OnFinishState, PromiseWithError, Registry, Segment, SetOptional, ThrowableError, Value };
|
package/dist/index.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { Promisable } from 'type-fest';
|
|
2
|
-
export { IsEqual, IsNever, PartialDeep, Promisable } from 'type-fest';
|
|
2
|
+
export { IsEqual, IsNever, JsonValue, PartialDeep, Promisable } from 'type-fest';
|
|
3
3
|
export { group, guard, mapEntries, mapValues, omit } from 'radash';
|
|
4
4
|
|
|
5
5
|
type MaybeOptionalOptions<TOptions> = Record<never, never> extends TOptions ? [options?: TOptions] : [options: TOptions];
|
|
@@ -8,6 +8,13 @@ declare function resolveMaybeOptionalOptions<T>(rest: MaybeOptionalOptions<T>):
|
|
|
8
8
|
declare function toArray<T>(value: T): T extends readonly any[] ? T : Exclude<T, undefined | null>[];
|
|
9
9
|
declare function splitInHalf<T>(arr: readonly T[]): [T[], T[]];
|
|
10
10
|
|
|
11
|
+
/**
|
|
12
|
+
* Converts Request/Response/Blob/File/.. to a buffer (ArrayBuffer or Uint8Array).
|
|
13
|
+
*
|
|
14
|
+
* Prefers the newer `.bytes` method when available as it more efficient but not widely supported yet.
|
|
15
|
+
*/
|
|
16
|
+
declare function readAsBuffer(source: Pick<Blob, 'arrayBuffer' | 'bytes'>): Promise<ArrayBuffer | Uint8Array>;
|
|
17
|
+
|
|
11
18
|
type AnyFunction = (...args: any[]) => any;
|
|
12
19
|
declare function once<T extends () => any>(fn: T): () => ReturnType<T>;
|
|
13
20
|
declare function sequential<A extends any[], R>(fn: (...args: A) => Promise<R>): (...args: A) => Promise<R>;
|
|
@@ -80,8 +87,8 @@ declare class EventPublisher<T extends Record<PropertyKey, any>> {
|
|
|
80
87
|
}
|
|
81
88
|
|
|
82
89
|
declare class SequentialIdGenerator {
|
|
83
|
-
private
|
|
84
|
-
generate():
|
|
90
|
+
private index;
|
|
91
|
+
generate(): string;
|
|
85
92
|
}
|
|
86
93
|
|
|
87
94
|
type SetOptional<T, K extends keyof T> = Omit<T, K> & Partial<Pick<T, K>>;
|
|
@@ -160,7 +167,9 @@ declare class AsyncIteratorClass<T, TReturn = unknown, TNext = unknown> implemen
|
|
|
160
167
|
declare function replicateAsyncIterator<T, TReturn, TNext>(source: AsyncIterator<T, TReturn, TNext>, count: number): (AsyncIteratorClass<T, TReturn, TNext>)[];
|
|
161
168
|
|
|
162
169
|
declare function parseEmptyableJSON(text: string | null | undefined): unknown;
|
|
163
|
-
declare function stringifyJSON<T>(value: T
|
|
170
|
+
declare function stringifyJSON<T>(value: T | {
|
|
171
|
+
toJSON(): T;
|
|
172
|
+
}): undefined extends T ? undefined | string : string;
|
|
164
173
|
|
|
165
174
|
type Segment = string | number;
|
|
166
175
|
declare function findDeepMatches(check: (value: unknown) => boolean, payload: unknown, segments?: Segment[], maps?: Segment[][], values?: unknown[]): {
|
|
@@ -183,7 +192,7 @@ declare const NullProtoObj: ({
|
|
|
183
192
|
});
|
|
184
193
|
|
|
185
194
|
interface AsyncIdQueueCloseOptions {
|
|
186
|
-
id?:
|
|
195
|
+
id?: string;
|
|
187
196
|
reason?: unknown;
|
|
188
197
|
}
|
|
189
198
|
declare class AsyncIdQueue<T> {
|
|
@@ -191,16 +200,16 @@ declare class AsyncIdQueue<T> {
|
|
|
191
200
|
private readonly items;
|
|
192
201
|
private readonly pendingPulls;
|
|
193
202
|
get length(): number;
|
|
194
|
-
open(id:
|
|
195
|
-
isOpen(id:
|
|
196
|
-
push(id:
|
|
197
|
-
pull(id:
|
|
203
|
+
open(id: string): void;
|
|
204
|
+
isOpen(id: string): boolean;
|
|
205
|
+
push(id: string, item: T): void;
|
|
206
|
+
pull(id: string): Promise<T>;
|
|
198
207
|
close({ id, reason }?: AsyncIdQueueCloseOptions): void;
|
|
199
|
-
assertOpen(id:
|
|
208
|
+
assertOpen(id: string): void;
|
|
200
209
|
}
|
|
201
210
|
|
|
202
211
|
type Value<T, TArgs extends any[] = []> = T | ((...args: TArgs) => T);
|
|
203
212
|
declare function value<T, TArgs extends any[]>(value: Value<T, TArgs>, ...args: NoInfer<TArgs>): T extends Value<infer U, any> ? U : never;
|
|
204
213
|
|
|
205
|
-
export { AsyncIdQueue, AsyncIteratorClass, EventPublisher, NullProtoObj, SequentialIdGenerator, clone, defer, findDeepMatches, get, intercept, isAsyncIteratorObject, isObject, isPropertyKey, isTypescriptObject, onError, onFinish, onStart, onSuccess, once, parseEmptyableJSON, replicateAsyncIterator, resolveMaybeOptionalOptions, sequential, splitInHalf, stringifyJSON, toArray, value };
|
|
214
|
+
export { AsyncIdQueue, AsyncIteratorClass, EventPublisher, NullProtoObj, SequentialIdGenerator, clone, defer, findDeepMatches, get, intercept, isAsyncIteratorObject, isObject, isPropertyKey, isTypescriptObject, onError, onFinish, onStart, onSuccess, once, parseEmptyableJSON, readAsBuffer, replicateAsyncIterator, resolveMaybeOptionalOptions, sequential, splitInHalf, stringifyJSON, toArray, value };
|
|
206
215
|
export type { AnyFunction, AsyncIdQueueCloseOptions, AsyncIteratorClassCleanupFn, AsyncIteratorClassNextFn, EventPublisherOptions, EventPublisherSubscribeIteratorOptions, InterceptableOptions, Interceptor, InterceptorOptions, IntersectPick, MaybeOptionalOptions, OmitChainMethodDeep, OnFinishState, PromiseWithError, Registry, Segment, SetOptional, ThrowableError, Value };
|
package/dist/index.mjs
CHANGED
|
@@ -12,6 +12,13 @@ function splitInHalf(arr) {
|
|
|
12
12
|
return [arr.slice(0, half), arr.slice(half)];
|
|
13
13
|
}
|
|
14
14
|
|
|
15
|
+
function readAsBuffer(source) {
|
|
16
|
+
if (typeof source.bytes === "function") {
|
|
17
|
+
return source.bytes();
|
|
18
|
+
}
|
|
19
|
+
return source.arrayBuffer();
|
|
20
|
+
}
|
|
21
|
+
|
|
15
22
|
function once(fn) {
|
|
16
23
|
let cached;
|
|
17
24
|
return () => {
|
|
@@ -120,7 +127,7 @@ function isAsyncIteratorObject(maybe) {
|
|
|
120
127
|
if (!maybe || typeof maybe !== "object") {
|
|
121
128
|
return false;
|
|
122
129
|
}
|
|
123
|
-
return Symbol.asyncIterator in maybe && typeof maybe[Symbol.asyncIterator] === "function";
|
|
130
|
+
return "next" in maybe && typeof maybe.next === "function" && Symbol.asyncIterator in maybe && typeof maybe[Symbol.asyncIterator] === "function";
|
|
124
131
|
}
|
|
125
132
|
const fallbackAsyncDisposeSymbol = Symbol.for("asyncDispose");
|
|
126
133
|
const asyncDisposeSymbol = Symbol.asyncDispose ?? fallbackAsyncDisposeSymbol;
|
|
@@ -194,8 +201,8 @@ function replicateAsyncIterator(source, count) {
|
|
|
194
201
|
while (true) {
|
|
195
202
|
const item = await source.next();
|
|
196
203
|
for (let id = 0; id < count; id++) {
|
|
197
|
-
if (queue.isOpen(id)) {
|
|
198
|
-
queue.push(id, item);
|
|
204
|
+
if (queue.isOpen(id.toString())) {
|
|
205
|
+
queue.push(id.toString(), item);
|
|
199
206
|
}
|
|
200
207
|
}
|
|
201
208
|
if (item.done) {
|
|
@@ -207,12 +214,12 @@ function replicateAsyncIterator(source, count) {
|
|
|
207
214
|
}
|
|
208
215
|
});
|
|
209
216
|
for (let id = 0; id < count; id++) {
|
|
210
|
-
queue.open(id);
|
|
217
|
+
queue.open(id.toString());
|
|
211
218
|
replicated.push(new AsyncIteratorClass(
|
|
212
219
|
() => {
|
|
213
220
|
start();
|
|
214
221
|
return new Promise((resolve, reject) => {
|
|
215
|
-
queue.pull(id).then(resolve).catch(reject);
|
|
222
|
+
queue.pull(id.toString()).then(resolve).catch(reject);
|
|
216
223
|
defer(() => {
|
|
217
224
|
if (error) {
|
|
218
225
|
reject(error.value);
|
|
@@ -221,9 +228,9 @@ function replicateAsyncIterator(source, count) {
|
|
|
221
228
|
});
|
|
222
229
|
},
|
|
223
230
|
async (reason) => {
|
|
224
|
-
queue.close({ id });
|
|
231
|
+
queue.close({ id: id.toString() });
|
|
225
232
|
if (reason !== "next") {
|
|
226
|
-
if (replicated.every((_, id2) => !queue.isOpen(id2))) {
|
|
233
|
+
if (replicated.every((_, id2) => !queue.isOpen(id2.toString()))) {
|
|
227
234
|
await source?.return?.();
|
|
228
235
|
}
|
|
229
236
|
}
|
|
@@ -312,13 +319,11 @@ class EventPublisher {
|
|
|
312
319
|
}
|
|
313
320
|
|
|
314
321
|
class SequentialIdGenerator {
|
|
315
|
-
|
|
322
|
+
index = BigInt(0);
|
|
316
323
|
generate() {
|
|
317
|
-
|
|
318
|
-
|
|
319
|
-
|
|
320
|
-
}
|
|
321
|
-
return this.nextId++;
|
|
324
|
+
const id = this.index.toString(32);
|
|
325
|
+
this.index++;
|
|
326
|
+
return id;
|
|
322
327
|
}
|
|
323
328
|
}
|
|
324
329
|
|
|
@@ -451,4 +456,4 @@ function value(value2, ...args) {
|
|
|
451
456
|
return value2;
|
|
452
457
|
}
|
|
453
458
|
|
|
454
|
-
export { AsyncIdQueue, AsyncIteratorClass, EventPublisher, NullProtoObj, SequentialIdGenerator, clone, defer, findDeepMatches, get, intercept, isAsyncIteratorObject, isObject, isPropertyKey, isTypescriptObject, onError, onFinish, onStart, onSuccess, once, parseEmptyableJSON, replicateAsyncIterator, resolveMaybeOptionalOptions, sequential, splitInHalf, stringifyJSON, toArray, value };
|
|
459
|
+
export { AsyncIdQueue, AsyncIteratorClass, EventPublisher, NullProtoObj, SequentialIdGenerator, clone, defer, findDeepMatches, get, intercept, isAsyncIteratorObject, isObject, isPropertyKey, isTypescriptObject, onError, onFinish, onStart, onSuccess, once, parseEmptyableJSON, readAsBuffer, replicateAsyncIterator, resolveMaybeOptionalOptions, sequential, splitInHalf, stringifyJSON, toArray, value };
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@orpc/shared",
|
|
3
3
|
"type": "module",
|
|
4
|
-
"version": "0.0.0-next.
|
|
4
|
+
"version": "0.0.0-next.de7ca70",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"homepage": "https://orpc.unnoq.com",
|
|
7
7
|
"repository": {
|
|
@@ -24,13 +24,13 @@
|
|
|
24
24
|
"dist"
|
|
25
25
|
],
|
|
26
26
|
"dependencies": {
|
|
27
|
-
"radash": "^12.1.
|
|
27
|
+
"radash": "^12.1.1",
|
|
28
28
|
"type-fest": "^4.39.1"
|
|
29
29
|
},
|
|
30
30
|
"devDependencies": {
|
|
31
31
|
"arktype": "2.1.20",
|
|
32
32
|
"valibot": "^1.1.0",
|
|
33
|
-
"zod": "^3.25.
|
|
33
|
+
"zod": "^3.25.76"
|
|
34
34
|
},
|
|
35
35
|
"scripts": {
|
|
36
36
|
"build": "unbuild",
|