@orpc/shared 0.0.0-next.ee46dab → 0.0.0-next.eea495c
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 +13 -17
- package/dist/index.d.mts +14 -12
- package/dist/index.d.ts +14 -12
- package/dist/index.mjs +11 -8
- package/package.json +2 -2
package/README.md
CHANGED
|
@@ -26,28 +26,24 @@
|
|
|
26
26
|
|
|
27
27
|
<h3 align="center">Typesafe APIs Made Simple 🪄</h3>
|
|
28
28
|
|
|
29
|
-
**oRPC is a powerful combination of RPC and OpenAPI**, makes it easy to build APIs that are end-to-end type-safe and adhere to OpenAPI standards
|
|
29
|
+
**oRPC is a powerful combination of RPC and OpenAPI**, makes it easy to build APIs that are end-to-end type-safe and adhere to OpenAPI standards
|
|
30
30
|
|
|
31
31
|
---
|
|
32
32
|
|
|
33
33
|
## Highlights
|
|
34
34
|
|
|
35
|
-
-
|
|
36
|
-
-
|
|
37
|
-
-
|
|
38
|
-
-
|
|
39
|
-
-
|
|
40
|
-
-
|
|
41
|
-
-
|
|
42
|
-
-
|
|
43
|
-
-
|
|
44
|
-
-
|
|
45
|
-
-
|
|
46
|
-
-
|
|
47
|
-
- **Reusability 🔄**: Write once and reuse your code across multiple purposes effortlessly.
|
|
48
|
-
- **Extendability 🔌**: Easily enhance oRPC with plugins, middleware, and interceptors.
|
|
49
|
-
- **Reliability 🛡️**: Well-tested, fully TypeScript, production-ready, and MIT licensed for peace of mind.
|
|
50
|
-
- **Simplicity 💡**: Enjoy straightforward, clean code with no hidden magic.
|
|
35
|
+
- **🔗 End-to-End Type Safety**: Ensure type-safe inputs, outputs, and errors from client to server.
|
|
36
|
+
- **📘 First-Class OpenAPI**: Built-in support that fully adheres to the OpenAPI standard.
|
|
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.
|
|
39
|
+
- **🚀 Server Actions**: Fully compatible with React Server Actions on Next.js, TanStack Start, and other platforms.
|
|
40
|
+
- **🔠 Standard Schema Support**: Works out of the box with Zod, Valibot, ArkType, and other schema validators.
|
|
41
|
+
- **🗃️ Native Types**: Supports native types like Date, File, Blob, BigInt, URL, and more.
|
|
42
|
+
- **⏱️ Lazy Router**: Enhance cold start times with our lazy routing feature.
|
|
43
|
+
- **📡 SSE & Streaming**: Enjoy full type-safe support for SSE and streaming.
|
|
44
|
+
- **🌍 Multi-Runtime Support**: Fast and lightweight on Cloudflare, Deno, Bun, Node.js, and beyond.
|
|
45
|
+
- **🔌 Extendability**: Easily extend functionality with plugins, middleware, and interceptors.
|
|
46
|
+
- **🛡️ Reliability**: Well-tested, TypeScript-based, production-ready, and MIT licensed.
|
|
51
47
|
|
|
52
48
|
## Documentation
|
|
53
49
|
|
package/dist/index.d.mts
CHANGED
|
@@ -5,7 +5,8 @@ export { group, guard, mapEntries, mapValues, omit } from 'radash';
|
|
|
5
5
|
type MaybeOptionalOptions<TOptions> = Record<never, never> extends TOptions ? [options?: TOptions] : [options: TOptions];
|
|
6
6
|
declare function resolveMaybeOptionalOptions<T>(rest: MaybeOptionalOptions<T>): T;
|
|
7
7
|
|
|
8
|
-
declare function toArray<T>(value: T
|
|
8
|
+
declare function toArray<T>(value: T): T extends readonly any[] ? T : Exclude<T, undefined | null>[];
|
|
9
|
+
declare function splitInHalf<T>(arr: readonly T[]): [T[], T[]];
|
|
9
10
|
|
|
10
11
|
type AnyFunction = (...args: any[]) => any;
|
|
11
12
|
declare function once<T extends () => any>(fn: T): () => ReturnType<T>;
|
|
@@ -36,32 +37,32 @@ type InterceptableOptions = Record<string, any>;
|
|
|
36
37
|
type InterceptorOptions<TOptions extends InterceptableOptions, TResult, TError> = Omit<TOptions, 'next'> & {
|
|
37
38
|
next(options?: TOptions): PromiseWithError<TResult, TError>;
|
|
38
39
|
};
|
|
39
|
-
type Interceptor<TOptions extends InterceptableOptions, TResult, TError> = (options: InterceptorOptions<TOptions, TResult, TError>) =>
|
|
40
|
+
type Interceptor<TOptions extends InterceptableOptions, TResult, TError> = (options: InterceptorOptions<TOptions, TResult, TError>) => Promisable<TResult>;
|
|
40
41
|
/**
|
|
41
42
|
* Can used for interceptors or middlewares
|
|
42
43
|
*/
|
|
43
|
-
declare function onStart<TOptions extends {
|
|
44
|
+
declare function onStart<T, TOptions extends {
|
|
44
45
|
next(): any;
|
|
45
|
-
}, TRest extends any[]>(callback: NoInfer<(options: TOptions, ...rest: TRest) => Promisable<void>>): (options: TOptions, ...rest: TRest) => Promise<Awaited<ReturnType<TOptions['next']>>>;
|
|
46
|
+
}, TRest extends any[]>(callback: NoInfer<(options: TOptions, ...rest: TRest) => Promisable<void>>): (options: TOptions, ...rest: TRest) => T | Promise<Awaited<ReturnType<TOptions['next']>>>;
|
|
46
47
|
/**
|
|
47
48
|
* Can used for interceptors or middlewares
|
|
48
49
|
*/
|
|
49
|
-
declare function onSuccess<TOptions extends {
|
|
50
|
+
declare function onSuccess<T, TOptions extends {
|
|
50
51
|
next(): any;
|
|
51
|
-
}, TRest extends any[]>(callback: NoInfer<(result: Awaited<ReturnType<TOptions['next']>>, options: TOptions, ...rest: TRest) => Promisable<void>>): (options: TOptions, ...rest: TRest) => Promise<Awaited<ReturnType<TOptions['next']>>>;
|
|
52
|
+
}, 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']>>>;
|
|
52
53
|
/**
|
|
53
54
|
* Can used for interceptors or middlewares
|
|
54
55
|
*/
|
|
55
|
-
declare function onError<TOptions extends {
|
|
56
|
+
declare function onError<T, TOptions extends {
|
|
56
57
|
next(): any;
|
|
57
|
-
}, 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) => Promise<Awaited<ReturnType<TOptions['next']>>>;
|
|
58
|
-
type OnFinishState<TResult, TError> = [
|
|
58
|
+
}, 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']>>>;
|
|
59
|
+
type OnFinishState<TResult, TError> = [error: TError, data: undefined, isSuccess: false] | [error: null, data: TResult, isSuccess: true];
|
|
59
60
|
/**
|
|
60
61
|
* Can used for interceptors or middlewares
|
|
61
62
|
*/
|
|
62
|
-
declare function onFinish<TOptions extends {
|
|
63
|
+
declare function onFinish<T, TOptions extends {
|
|
63
64
|
next(): any;
|
|
64
|
-
}, 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) => Promise<Awaited<ReturnType<TOptions['next']>>>;
|
|
65
|
+
}, 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']>>>;
|
|
65
66
|
declare function intercept<TOptions extends InterceptableOptions, TResult, TError>(interceptors: Interceptor<TOptions, TResult, TError>[], options: NoInfer<TOptions>, main: NoInfer<(options: TOptions) => Promisable<TResult>>): Promise<TResult>;
|
|
66
67
|
|
|
67
68
|
declare function isAsyncIteratorObject(maybe: unknown): maybe is AsyncIteratorObject<any, any, any>;
|
|
@@ -88,4 +89,5 @@ declare function get(object: object, path: readonly string[]): unknown;
|
|
|
88
89
|
type Value<T, TArgs extends any[] = []> = T | ((...args: TArgs) => Promisable<T>);
|
|
89
90
|
declare function value<T, TArgs extends any[]>(value: Value<T, TArgs>, ...args: NoInfer<TArgs>): Promise<T extends Value<infer U, any> ? U : never>;
|
|
90
91
|
|
|
91
|
-
export {
|
|
92
|
+
export { clone, findDeepMatches, get, intercept, isAsyncIteratorObject, isObject, isTypescriptObject, onError, onFinish, onStart, onSuccess, once, parseEmptyableJSON, resolveMaybeOptionalOptions, splitInHalf, stringifyJSON, toArray, value };
|
|
93
|
+
export type { AnyFunction, InterceptableOptions, Interceptor, InterceptorOptions, IntersectPick, MaybeOptionalOptions, OmitChainMethodDeep, OnFinishState, PromiseWithError, Registry, Segment, SetOptional, ThrowableError, Value };
|
package/dist/index.d.ts
CHANGED
|
@@ -5,7 +5,8 @@ export { group, guard, mapEntries, mapValues, omit } from 'radash';
|
|
|
5
5
|
type MaybeOptionalOptions<TOptions> = Record<never, never> extends TOptions ? [options?: TOptions] : [options: TOptions];
|
|
6
6
|
declare function resolveMaybeOptionalOptions<T>(rest: MaybeOptionalOptions<T>): T;
|
|
7
7
|
|
|
8
|
-
declare function toArray<T>(value: T
|
|
8
|
+
declare function toArray<T>(value: T): T extends readonly any[] ? T : Exclude<T, undefined | null>[];
|
|
9
|
+
declare function splitInHalf<T>(arr: readonly T[]): [T[], T[]];
|
|
9
10
|
|
|
10
11
|
type AnyFunction = (...args: any[]) => any;
|
|
11
12
|
declare function once<T extends () => any>(fn: T): () => ReturnType<T>;
|
|
@@ -36,32 +37,32 @@ type InterceptableOptions = Record<string, any>;
|
|
|
36
37
|
type InterceptorOptions<TOptions extends InterceptableOptions, TResult, TError> = Omit<TOptions, 'next'> & {
|
|
37
38
|
next(options?: TOptions): PromiseWithError<TResult, TError>;
|
|
38
39
|
};
|
|
39
|
-
type Interceptor<TOptions extends InterceptableOptions, TResult, TError> = (options: InterceptorOptions<TOptions, TResult, TError>) =>
|
|
40
|
+
type Interceptor<TOptions extends InterceptableOptions, TResult, TError> = (options: InterceptorOptions<TOptions, TResult, TError>) => Promisable<TResult>;
|
|
40
41
|
/**
|
|
41
42
|
* Can used for interceptors or middlewares
|
|
42
43
|
*/
|
|
43
|
-
declare function onStart<TOptions extends {
|
|
44
|
+
declare function onStart<T, TOptions extends {
|
|
44
45
|
next(): any;
|
|
45
|
-
}, TRest extends any[]>(callback: NoInfer<(options: TOptions, ...rest: TRest) => Promisable<void>>): (options: TOptions, ...rest: TRest) => Promise<Awaited<ReturnType<TOptions['next']>>>;
|
|
46
|
+
}, TRest extends any[]>(callback: NoInfer<(options: TOptions, ...rest: TRest) => Promisable<void>>): (options: TOptions, ...rest: TRest) => T | Promise<Awaited<ReturnType<TOptions['next']>>>;
|
|
46
47
|
/**
|
|
47
48
|
* Can used for interceptors or middlewares
|
|
48
49
|
*/
|
|
49
|
-
declare function onSuccess<TOptions extends {
|
|
50
|
+
declare function onSuccess<T, TOptions extends {
|
|
50
51
|
next(): any;
|
|
51
|
-
}, TRest extends any[]>(callback: NoInfer<(result: Awaited<ReturnType<TOptions['next']>>, options: TOptions, ...rest: TRest) => Promisable<void>>): (options: TOptions, ...rest: TRest) => Promise<Awaited<ReturnType<TOptions['next']>>>;
|
|
52
|
+
}, 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']>>>;
|
|
52
53
|
/**
|
|
53
54
|
* Can used for interceptors or middlewares
|
|
54
55
|
*/
|
|
55
|
-
declare function onError<TOptions extends {
|
|
56
|
+
declare function onError<T, TOptions extends {
|
|
56
57
|
next(): any;
|
|
57
|
-
}, 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) => Promise<Awaited<ReturnType<TOptions['next']>>>;
|
|
58
|
-
type OnFinishState<TResult, TError> = [
|
|
58
|
+
}, 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']>>>;
|
|
59
|
+
type OnFinishState<TResult, TError> = [error: TError, data: undefined, isSuccess: false] | [error: null, data: TResult, isSuccess: true];
|
|
59
60
|
/**
|
|
60
61
|
* Can used for interceptors or middlewares
|
|
61
62
|
*/
|
|
62
|
-
declare function onFinish<TOptions extends {
|
|
63
|
+
declare function onFinish<T, TOptions extends {
|
|
63
64
|
next(): any;
|
|
64
|
-
}, 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) => Promise<Awaited<ReturnType<TOptions['next']>>>;
|
|
65
|
+
}, 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']>>>;
|
|
65
66
|
declare function intercept<TOptions extends InterceptableOptions, TResult, TError>(interceptors: Interceptor<TOptions, TResult, TError>[], options: NoInfer<TOptions>, main: NoInfer<(options: TOptions) => Promisable<TResult>>): Promise<TResult>;
|
|
66
67
|
|
|
67
68
|
declare function isAsyncIteratorObject(maybe: unknown): maybe is AsyncIteratorObject<any, any, any>;
|
|
@@ -88,4 +89,5 @@ declare function get(object: object, path: readonly string[]): unknown;
|
|
|
88
89
|
type Value<T, TArgs extends any[] = []> = T | ((...args: TArgs) => Promisable<T>);
|
|
89
90
|
declare function value<T, TArgs extends any[]>(value: Value<T, TArgs>, ...args: NoInfer<TArgs>): Promise<T extends Value<infer U, any> ? U : never>;
|
|
90
91
|
|
|
91
|
-
export {
|
|
92
|
+
export { clone, findDeepMatches, get, intercept, isAsyncIteratorObject, isObject, isTypescriptObject, onError, onFinish, onStart, onSuccess, once, parseEmptyableJSON, resolveMaybeOptionalOptions, splitInHalf, stringifyJSON, toArray, value };
|
|
93
|
+
export type { AnyFunction, InterceptableOptions, Interceptor, InterceptorOptions, IntersectPick, MaybeOptionalOptions, OmitChainMethodDeep, OnFinishState, PromiseWithError, Registry, Segment, SetOptional, ThrowableError, Value };
|
package/dist/index.mjs
CHANGED
|
@@ -7,6 +7,10 @@ function resolveMaybeOptionalOptions(rest) {
|
|
|
7
7
|
function toArray(value) {
|
|
8
8
|
return Array.isArray(value) ? value : value === void 0 || value === null ? [] : [value];
|
|
9
9
|
}
|
|
10
|
+
function splitInHalf(arr) {
|
|
11
|
+
const half = Math.ceil(arr.length / 2);
|
|
12
|
+
return [arr.slice(0, half), arr.slice(half)];
|
|
13
|
+
}
|
|
10
14
|
|
|
11
15
|
function once(fn) {
|
|
12
16
|
let cached;
|
|
@@ -48,10 +52,10 @@ function onFinish(callback) {
|
|
|
48
52
|
return async (options, ...rest) => {
|
|
49
53
|
try {
|
|
50
54
|
const result = await options.next();
|
|
51
|
-
state = [
|
|
55
|
+
state = [null, result, true];
|
|
52
56
|
return result;
|
|
53
57
|
} catch (error) {
|
|
54
|
-
state = [void 0,
|
|
58
|
+
state = [error, void 0, false];
|
|
55
59
|
throw error;
|
|
56
60
|
} finally {
|
|
57
61
|
await callback(state, options, ...rest);
|
|
@@ -59,18 +63,17 @@ function onFinish(callback) {
|
|
|
59
63
|
};
|
|
60
64
|
}
|
|
61
65
|
async function intercept(interceptors, options, main) {
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
const interceptor = interceptors[index++];
|
|
66
|
+
const next = async (options2, index) => {
|
|
67
|
+
const interceptor = interceptors[index];
|
|
65
68
|
if (!interceptor) {
|
|
66
69
|
return await main(options2);
|
|
67
70
|
}
|
|
68
71
|
return await interceptor({
|
|
69
72
|
...options2,
|
|
70
|
-
next: (newOptions = options2) => next(newOptions)
|
|
73
|
+
next: (newOptions = options2) => next(newOptions, index + 1)
|
|
71
74
|
});
|
|
72
75
|
};
|
|
73
|
-
return
|
|
76
|
+
return next(options, 0);
|
|
74
77
|
}
|
|
75
78
|
|
|
76
79
|
function isAsyncIteratorObject(maybe) {
|
|
@@ -146,4 +149,4 @@ function value(value2, ...args) {
|
|
|
146
149
|
return value2;
|
|
147
150
|
}
|
|
148
151
|
|
|
149
|
-
export { clone, findDeepMatches, get, intercept, isAsyncIteratorObject, isObject, isTypescriptObject, onError, onFinish, onStart, onSuccess, once, parseEmptyableJSON, resolveMaybeOptionalOptions, stringifyJSON, toArray, value };
|
|
152
|
+
export { clone, findDeepMatches, get, intercept, isAsyncIteratorObject, isObject, isTypescriptObject, onError, onFinish, onStart, onSuccess, once, parseEmptyableJSON, resolveMaybeOptionalOptions, 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.eea495c",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"homepage": "https://orpc.unnoq.com",
|
|
7
7
|
"repository": {
|
|
@@ -25,7 +25,7 @@
|
|
|
25
25
|
],
|
|
26
26
|
"dependencies": {
|
|
27
27
|
"radash": "^12.1.0",
|
|
28
|
-
"type-fest": "^4.
|
|
28
|
+
"type-fest": "^4.39.1"
|
|
29
29
|
},
|
|
30
30
|
"scripts": {
|
|
31
31
|
"build": "unbuild",
|