@orpc/shared 0.0.0-next.da8ae32 → 0.0.0-next.df024bb
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 +68 -0
- package/dist/index.d.mts +85 -0
- package/dist/index.d.ts +85 -0
- package/dist/{index.js → index.mjs} +22 -74
- package/package.json +5 -10
- package/dist/src/chain.d.ts +0 -5
- package/dist/src/constants.d.ts +0 -3
- package/dist/src/error.d.ts +0 -2
- package/dist/src/function.d.ts +0 -3
- package/dist/src/index.d.ts +0 -13
- package/dist/src/interceptor.d.ts +0 -47
- package/dist/src/json.d.ts +0 -2
- package/dist/src/object.d.ts +0 -12
- package/dist/src/proxy.d.ts +0 -3
- package/dist/src/types.d.ts +0 -3
- package/dist/src/value.d.ts +0 -4
package/README.md
ADDED
|
@@ -0,0 +1,68 @@
|
|
|
1
|
+
<div align="center">
|
|
2
|
+
<image align="center" src="https://orpc.unnoq.com/logo.webp" width=280 alt="oRPC logo" />
|
|
3
|
+
</div>
|
|
4
|
+
|
|
5
|
+
<h1></h1>
|
|
6
|
+
|
|
7
|
+
<div align="center">
|
|
8
|
+
<a href="https://codecov.io/gh/unnoq/orpc">
|
|
9
|
+
<img alt="codecov" src="https://codecov.io/gh/unnoq/orpc/branch/main/graph/badge.svg">
|
|
10
|
+
</a>
|
|
11
|
+
<a href="https://www.npmjs.com/package/@orpc/shared">
|
|
12
|
+
<img alt="weekly downloads" src="https://img.shields.io/npm/dw/%40orpc%2Fshared?logo=npm" />
|
|
13
|
+
</a>
|
|
14
|
+
<a href="https://github.com/unnoq/orpc/blob/main/LICENSE">
|
|
15
|
+
<img alt="MIT License" src="https://img.shields.io/github/license/unnoq/orpc?logo=open-source-initiative" />
|
|
16
|
+
</a>
|
|
17
|
+
<a href="https://discord.gg/TXEbwRBvQn">
|
|
18
|
+
<img alt="Discord" src="https://img.shields.io/discord/1308966753044398161?color=7389D8&label&logo=discord&logoColor=ffffff" />
|
|
19
|
+
</a>
|
|
20
|
+
</div>
|
|
21
|
+
|
|
22
|
+
<h3 align="center">Typesafe APIs Made Simple 🪄</h3>
|
|
23
|
+
|
|
24
|
+
**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, ensuring a smooth and enjoyable developer experience.
|
|
25
|
+
|
|
26
|
+
---
|
|
27
|
+
|
|
28
|
+
## Highlights
|
|
29
|
+
|
|
30
|
+
- **End-to-End Type Safety 🔒**: Ensure complete type safety from inputs to outputs and errors, bridging server and client seamlessly.
|
|
31
|
+
- **First-Class OpenAPI 📄**: Adheres to the OpenAPI standard out of the box, ensuring seamless integration and comprehensive API documentation.
|
|
32
|
+
- **Contract-First Development 📜**: (Optional) Define your API contract upfront and implement it with confidence.
|
|
33
|
+
- **Exceptional Developer Experience ✨**: Enjoy a streamlined workflow with robust typing and clear, in-code documentation.
|
|
34
|
+
- **Multi-Runtime Support 🌍**: Run your code seamlessly on Cloudflare, Deno, Bun, Node.js, and more.
|
|
35
|
+
- **Framework Integrations 🧩**: Supports Tanstack Query (React, Vue), Pinia Colada, and more.
|
|
36
|
+
- **Server Actions ⚡️**: Fully compatible with React Server Actions on Next.js, TanStack Start, and more.
|
|
37
|
+
- **Standard Schema Support 🗂️**: Effortlessly work with Zod, Valibot, ArkType, and others right out of the box.
|
|
38
|
+
- **Fast & Lightweight 💨**: Built on native APIs across all runtimes – optimized for speed and efficiency.
|
|
39
|
+
- **Native Types 📦**: Enjoy built-in support for Date, File, Blob, BigInt, URL and more with no extra setup.
|
|
40
|
+
- **Lazy Router ⏱️**: Improve cold start times with our lazy routing feature.
|
|
41
|
+
- **SSE & Streaming 📡**: Provides SSE and streaming features – perfect for real-time notifications and AI-powered streaming responses.
|
|
42
|
+
- **Reusability 🔄**: Write once and reuse your code across multiple purposes effortlessly.
|
|
43
|
+
- **Extendability 🔌**: Easily enhance oRPC with plugins, middleware, and interceptors.
|
|
44
|
+
- **Reliability 🛡️**: Well-tested, fully TypeScript, production-ready, and MIT licensed for peace of mind.
|
|
45
|
+
- **Simplicity 💡**: Enjoy straightforward, clean code with no hidden magic.
|
|
46
|
+
|
|
47
|
+
## Documentation
|
|
48
|
+
|
|
49
|
+
You can find the full documentation [here](https://orpc.unnoq.com).
|
|
50
|
+
|
|
51
|
+
## Packages
|
|
52
|
+
|
|
53
|
+
- [@orpc/contract](https://www.npmjs.com/package/@orpc/contract): Build your API contract.
|
|
54
|
+
- [@orpc/server](https://www.npmjs.com/package/@orpc/server): Build your API or implement API contract.
|
|
55
|
+
- [@orpc/client](https://www.npmjs.com/package/@orpc/client): Consume your API on the client with type-safety.
|
|
56
|
+
- [@orpc/react-query](https://www.npmjs.com/package/@orpc/react-query): Integration with [React Query](https://tanstack.com/query/latest/docs/framework/react/overview).
|
|
57
|
+
- [@orpc/vue-query](https://www.npmjs.com/package/@orpc/vue-query): Integration with [Vue Query](https://tanstack.com/query/latest/docs/framework/vue/overview).
|
|
58
|
+
- [@orpc/vue-colada](https://www.npmjs.com/package/@orpc/vue-colada): Integration with [Pinia Colada](https://pinia-colada.esm.dev/).
|
|
59
|
+
- [@orpc/openapi](https://www.npmjs.com/package/@orpc/openapi): Generate OpenAPI specs and handle OpenAPI requests.
|
|
60
|
+
- [@orpc/zod](https://www.npmjs.com/package/@orpc/zod): More schemas that [Zod](https://zod.dev/) doesn't support yet.
|
|
61
|
+
|
|
62
|
+
## `@orpc/shared`
|
|
63
|
+
|
|
64
|
+
Provides shared utilities for oRPC packages.
|
|
65
|
+
|
|
66
|
+
## License
|
|
67
|
+
|
|
68
|
+
Distributed under the MIT License. See [LICENSE](https://github.com/unnoq/orpc/blob/main/LICENSE) for more information.
|
package/dist/index.d.mts
ADDED
|
@@ -0,0 +1,85 @@
|
|
|
1
|
+
import { Promisable } from 'type-fest';
|
|
2
|
+
export { IsEqual, IsNever, PartialDeep, Promisable } from 'type-fest';
|
|
3
|
+
export { group, guard, mapEntries, mapValues, omit, retry, trim } from 'radash';
|
|
4
|
+
|
|
5
|
+
type AnyFunction = (...args: any[]) => any;
|
|
6
|
+
declare function once<T extends () => any>(fn: T): () => ReturnType<T>;
|
|
7
|
+
|
|
8
|
+
type OmitChainMethodDeep<T extends object, K extends keyof any> = {
|
|
9
|
+
[P in keyof Omit<T, K>]: T[P] extends AnyFunction ? ((...args: Parameters<T[P]>) => OmitChainMethodDeep<ReturnType<T[P]>, K>) : T[P];
|
|
10
|
+
};
|
|
11
|
+
|
|
12
|
+
declare function toError(error: unknown): Error;
|
|
13
|
+
|
|
14
|
+
type InterceptableOptions = Record<string, any>;
|
|
15
|
+
type InterceptorOptions<TOptions extends InterceptableOptions, TResult> = Omit<TOptions, 'next'> & {
|
|
16
|
+
next(options?: TOptions): Promise<TResult>;
|
|
17
|
+
};
|
|
18
|
+
type Interceptor<TOptions extends InterceptableOptions, TResult, TError> = (options: InterceptorOptions<TOptions, TResult>) => Promise<TResult> & {
|
|
19
|
+
__error?: {
|
|
20
|
+
type: TError;
|
|
21
|
+
};
|
|
22
|
+
};
|
|
23
|
+
/**
|
|
24
|
+
* Can used for interceptors or middlewares
|
|
25
|
+
*/
|
|
26
|
+
declare function onStart<TOptions extends {
|
|
27
|
+
next(): any;
|
|
28
|
+
}, TRest extends any[]>(callback: NoInfer<(options: TOptions, ...rest: TRest) => Promisable<void>>): (options: TOptions, ...rest: TRest) => Promise<Awaited<ReturnType<TOptions['next']>>>;
|
|
29
|
+
/**
|
|
30
|
+
* Can used for interceptors or middlewares
|
|
31
|
+
*/
|
|
32
|
+
declare function onSuccess<TOptions extends {
|
|
33
|
+
next(): any;
|
|
34
|
+
}, 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']>>>;
|
|
35
|
+
/**
|
|
36
|
+
* Can used for interceptors or middlewares
|
|
37
|
+
*/
|
|
38
|
+
declare function onError<TError, TOptions extends {
|
|
39
|
+
next(): any;
|
|
40
|
+
}, TRest extends any[]>(callback: NoInfer<(error: TError, options: TOptions, ...rest: TRest) => Promisable<void>>): (options: TOptions, ...rest: TRest) => Promise<Awaited<ReturnType<TOptions['next']>>> & {
|
|
41
|
+
__error?: {
|
|
42
|
+
type: TError;
|
|
43
|
+
};
|
|
44
|
+
};
|
|
45
|
+
type OnFinishState<TResult, TError> = [TResult, undefined, 'success'] | [undefined, TError, 'error'];
|
|
46
|
+
/**
|
|
47
|
+
* Can used for interceptors or middlewares
|
|
48
|
+
*/
|
|
49
|
+
declare function onFinish<TError, TOptions extends {
|
|
50
|
+
next(): any;
|
|
51
|
+
}, TRest extends any[]>(callback: NoInfer<(state: OnFinishState<Awaited<ReturnType<TOptions['next']>>, TError>, options: TOptions, ...rest: TRest) => Promisable<void>>): (options: TOptions, ...rest: TRest) => Promise<Awaited<ReturnType<TOptions['next']>>> & {
|
|
52
|
+
__error?: {
|
|
53
|
+
type: TError;
|
|
54
|
+
};
|
|
55
|
+
};
|
|
56
|
+
declare function intercept<TOptions extends InterceptableOptions, TResult, TError>(interceptors: Interceptor<TOptions, TResult, TError>[], options: NoInfer<TOptions>, main: NoInfer<(options: TOptions) => Promisable<TResult>>): Promise<TResult>;
|
|
57
|
+
|
|
58
|
+
declare function isAsyncIteratorObject(maybe: unknown): maybe is AsyncIteratorObject<any, any, any>;
|
|
59
|
+
|
|
60
|
+
declare function parseEmptyableJSON(text: string | null | undefined): unknown;
|
|
61
|
+
declare function stringifyJSON<T>(value: T): undefined extends T ? undefined | string : string;
|
|
62
|
+
|
|
63
|
+
type Segment = string | number;
|
|
64
|
+
declare function set(root: unknown, segments: Readonly<Segment[]>, value: unknown): unknown;
|
|
65
|
+
declare function get(root: Readonly<Record<string, unknown> | unknown[]>, segments: Readonly<Segment[]>): unknown;
|
|
66
|
+
declare function findDeepMatches(check: (value: unknown) => boolean, payload: unknown, segments?: Segment[], maps?: Segment[][], values?: unknown[]): {
|
|
67
|
+
maps: Segment[][];
|
|
68
|
+
values: unknown[];
|
|
69
|
+
};
|
|
70
|
+
/**
|
|
71
|
+
* Check if the value is an object even it created by `Object.create(null)` or more tricky way.
|
|
72
|
+
*/
|
|
73
|
+
declare function isObject(value: unknown): value is Record<PropertyKey, unknown>;
|
|
74
|
+
/**
|
|
75
|
+
* Check if the value satisfy a `object` type in typescript
|
|
76
|
+
*/
|
|
77
|
+
declare function isTypescriptObject(value: unknown): value is object & Record<PropertyKey, unknown>;
|
|
78
|
+
|
|
79
|
+
type MaybeOptionalOptions<TOptions> = Record<never, never> extends TOptions ? [options?: TOptions] : [options: TOptions];
|
|
80
|
+
type SetOptional<T, K extends keyof T> = Omit<T, K> & Partial<Pick<T, K>>;
|
|
81
|
+
|
|
82
|
+
type Value<T, TArgs extends any[] = []> = T | ((...args: TArgs) => Promisable<T>);
|
|
83
|
+
declare function value<T, TArgs extends any[]>(value: Value<T, TArgs>, ...args: NoInfer<TArgs>): Promise<T extends Value<infer U, any> ? U : never>;
|
|
84
|
+
|
|
85
|
+
export { type AnyFunction, type InterceptableOptions, type Interceptor, type InterceptorOptions, type MaybeOptionalOptions, type OmitChainMethodDeep, type OnFinishState, type Segment, type SetOptional, type Value, findDeepMatches, get, intercept, isAsyncIteratorObject, isObject, isTypescriptObject, onError, onFinish, onStart, onSuccess, once, parseEmptyableJSON, set, stringifyJSON, toError, value };
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,85 @@
|
|
|
1
|
+
import { Promisable } from 'type-fest';
|
|
2
|
+
export { IsEqual, IsNever, PartialDeep, Promisable } from 'type-fest';
|
|
3
|
+
export { group, guard, mapEntries, mapValues, omit, retry, trim } from 'radash';
|
|
4
|
+
|
|
5
|
+
type AnyFunction = (...args: any[]) => any;
|
|
6
|
+
declare function once<T extends () => any>(fn: T): () => ReturnType<T>;
|
|
7
|
+
|
|
8
|
+
type OmitChainMethodDeep<T extends object, K extends keyof any> = {
|
|
9
|
+
[P in keyof Omit<T, K>]: T[P] extends AnyFunction ? ((...args: Parameters<T[P]>) => OmitChainMethodDeep<ReturnType<T[P]>, K>) : T[P];
|
|
10
|
+
};
|
|
11
|
+
|
|
12
|
+
declare function toError(error: unknown): Error;
|
|
13
|
+
|
|
14
|
+
type InterceptableOptions = Record<string, any>;
|
|
15
|
+
type InterceptorOptions<TOptions extends InterceptableOptions, TResult> = Omit<TOptions, 'next'> & {
|
|
16
|
+
next(options?: TOptions): Promise<TResult>;
|
|
17
|
+
};
|
|
18
|
+
type Interceptor<TOptions extends InterceptableOptions, TResult, TError> = (options: InterceptorOptions<TOptions, TResult>) => Promise<TResult> & {
|
|
19
|
+
__error?: {
|
|
20
|
+
type: TError;
|
|
21
|
+
};
|
|
22
|
+
};
|
|
23
|
+
/**
|
|
24
|
+
* Can used for interceptors or middlewares
|
|
25
|
+
*/
|
|
26
|
+
declare function onStart<TOptions extends {
|
|
27
|
+
next(): any;
|
|
28
|
+
}, TRest extends any[]>(callback: NoInfer<(options: TOptions, ...rest: TRest) => Promisable<void>>): (options: TOptions, ...rest: TRest) => Promise<Awaited<ReturnType<TOptions['next']>>>;
|
|
29
|
+
/**
|
|
30
|
+
* Can used for interceptors or middlewares
|
|
31
|
+
*/
|
|
32
|
+
declare function onSuccess<TOptions extends {
|
|
33
|
+
next(): any;
|
|
34
|
+
}, 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']>>>;
|
|
35
|
+
/**
|
|
36
|
+
* Can used for interceptors or middlewares
|
|
37
|
+
*/
|
|
38
|
+
declare function onError<TError, TOptions extends {
|
|
39
|
+
next(): any;
|
|
40
|
+
}, TRest extends any[]>(callback: NoInfer<(error: TError, options: TOptions, ...rest: TRest) => Promisable<void>>): (options: TOptions, ...rest: TRest) => Promise<Awaited<ReturnType<TOptions['next']>>> & {
|
|
41
|
+
__error?: {
|
|
42
|
+
type: TError;
|
|
43
|
+
};
|
|
44
|
+
};
|
|
45
|
+
type OnFinishState<TResult, TError> = [TResult, undefined, 'success'] | [undefined, TError, 'error'];
|
|
46
|
+
/**
|
|
47
|
+
* Can used for interceptors or middlewares
|
|
48
|
+
*/
|
|
49
|
+
declare function onFinish<TError, TOptions extends {
|
|
50
|
+
next(): any;
|
|
51
|
+
}, TRest extends any[]>(callback: NoInfer<(state: OnFinishState<Awaited<ReturnType<TOptions['next']>>, TError>, options: TOptions, ...rest: TRest) => Promisable<void>>): (options: TOptions, ...rest: TRest) => Promise<Awaited<ReturnType<TOptions['next']>>> & {
|
|
52
|
+
__error?: {
|
|
53
|
+
type: TError;
|
|
54
|
+
};
|
|
55
|
+
};
|
|
56
|
+
declare function intercept<TOptions extends InterceptableOptions, TResult, TError>(interceptors: Interceptor<TOptions, TResult, TError>[], options: NoInfer<TOptions>, main: NoInfer<(options: TOptions) => Promisable<TResult>>): Promise<TResult>;
|
|
57
|
+
|
|
58
|
+
declare function isAsyncIteratorObject(maybe: unknown): maybe is AsyncIteratorObject<any, any, any>;
|
|
59
|
+
|
|
60
|
+
declare function parseEmptyableJSON(text: string | null | undefined): unknown;
|
|
61
|
+
declare function stringifyJSON<T>(value: T): undefined extends T ? undefined | string : string;
|
|
62
|
+
|
|
63
|
+
type Segment = string | number;
|
|
64
|
+
declare function set(root: unknown, segments: Readonly<Segment[]>, value: unknown): unknown;
|
|
65
|
+
declare function get(root: Readonly<Record<string, unknown> | unknown[]>, segments: Readonly<Segment[]>): unknown;
|
|
66
|
+
declare function findDeepMatches(check: (value: unknown) => boolean, payload: unknown, segments?: Segment[], maps?: Segment[][], values?: unknown[]): {
|
|
67
|
+
maps: Segment[][];
|
|
68
|
+
values: unknown[];
|
|
69
|
+
};
|
|
70
|
+
/**
|
|
71
|
+
* Check if the value is an object even it created by `Object.create(null)` or more tricky way.
|
|
72
|
+
*/
|
|
73
|
+
declare function isObject(value: unknown): value is Record<PropertyKey, unknown>;
|
|
74
|
+
/**
|
|
75
|
+
* Check if the value satisfy a `object` type in typescript
|
|
76
|
+
*/
|
|
77
|
+
declare function isTypescriptObject(value: unknown): value is object & Record<PropertyKey, unknown>;
|
|
78
|
+
|
|
79
|
+
type MaybeOptionalOptions<TOptions> = Record<never, never> extends TOptions ? [options?: TOptions] : [options: TOptions];
|
|
80
|
+
type SetOptional<T, K extends keyof T> = Omit<T, K> & Partial<Pick<T, K>>;
|
|
81
|
+
|
|
82
|
+
type Value<T, TArgs extends any[] = []> = T | ((...args: TArgs) => Promisable<T>);
|
|
83
|
+
declare function value<T, TArgs extends any[]>(value: Value<T, TArgs>, ...args: NoInfer<TArgs>): Promise<T extends Value<infer U, any> ? U : never>;
|
|
84
|
+
|
|
85
|
+
export { type AnyFunction, type InterceptableOptions, type Interceptor, type InterceptorOptions, type MaybeOptionalOptions, type OmitChainMethodDeep, type OnFinishState, type Segment, type SetOptional, type Value, findDeepMatches, get, intercept, isAsyncIteratorObject, isObject, isTypescriptObject, onError, onFinish, onStart, onSuccess, once, parseEmptyableJSON, set, stringifyJSON, toError, value };
|
|
@@ -1,9 +1,6 @@
|
|
|
1
|
-
|
|
2
|
-
var ORPC_HANDLER_HEADER = "x-orpc-handler";
|
|
3
|
-
var ORPC_HANDLER_VALUE = "orpc";
|
|
1
|
+
export { group, guard, mapEntries, mapValues, omit, retry, trim } from 'radash';
|
|
4
2
|
|
|
5
|
-
|
|
6
|
-
function set(root, segments, value2) {
|
|
3
|
+
function set(root, segments, value) {
|
|
7
4
|
const ref = { root };
|
|
8
5
|
let currentRef = ref;
|
|
9
6
|
let preSegment = "root";
|
|
@@ -11,7 +8,7 @@ function set(root, segments, value2) {
|
|
|
11
8
|
currentRef = currentRef[preSegment];
|
|
12
9
|
preSegment = segment;
|
|
13
10
|
}
|
|
14
|
-
currentRef[preSegment] =
|
|
11
|
+
currentRef[preSegment] = value;
|
|
15
12
|
return ref.root;
|
|
16
13
|
}
|
|
17
14
|
function get(root, segments) {
|
|
@@ -45,15 +42,17 @@ function findDeepMatches(check, payload, segments = [], maps = [], values = [])
|
|
|
45
42
|
}
|
|
46
43
|
return { maps, values };
|
|
47
44
|
}
|
|
48
|
-
function isObject(
|
|
49
|
-
if (!
|
|
45
|
+
function isObject(value) {
|
|
46
|
+
if (!value || typeof value !== "object") {
|
|
50
47
|
return false;
|
|
51
48
|
}
|
|
52
|
-
const proto = Object.getPrototypeOf(
|
|
49
|
+
const proto = Object.getPrototypeOf(value);
|
|
53
50
|
return proto === Object.prototype || !proto || !proto.constructor;
|
|
54
51
|
}
|
|
52
|
+
function isTypescriptObject(value) {
|
|
53
|
+
return !!value && (typeof value === "object" || typeof value === "function");
|
|
54
|
+
}
|
|
55
55
|
|
|
56
|
-
// src/error.ts
|
|
57
56
|
function toError(error) {
|
|
58
57
|
if (error instanceof Error) {
|
|
59
58
|
return error;
|
|
@@ -72,7 +71,6 @@ function toError(error) {
|
|
|
72
71
|
return new Error("Unknown error", { cause: error });
|
|
73
72
|
}
|
|
74
73
|
|
|
75
|
-
// src/function.ts
|
|
76
74
|
function once(fn) {
|
|
77
75
|
let cached;
|
|
78
76
|
return () => {
|
|
@@ -85,7 +83,6 @@ function once(fn) {
|
|
|
85
83
|
};
|
|
86
84
|
}
|
|
87
85
|
|
|
88
|
-
// src/interceptor.ts
|
|
89
86
|
function onStart(callback) {
|
|
90
87
|
return async (options, ...rest) => {
|
|
91
88
|
await callback(options, ...rest);
|
|
@@ -139,46 +136,23 @@ async function intercept(interceptors, options, main) {
|
|
|
139
136
|
return await next(options);
|
|
140
137
|
}
|
|
141
138
|
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
return void 0;
|
|
146
|
-
try {
|
|
147
|
-
return JSON.parse(text);
|
|
148
|
-
} catch {
|
|
149
|
-
return text;
|
|
139
|
+
function isAsyncIteratorObject(maybe) {
|
|
140
|
+
if (!maybe || typeof maybe !== "object") {
|
|
141
|
+
return false;
|
|
150
142
|
}
|
|
143
|
+
return Symbol.asyncIterator in maybe && typeof maybe[Symbol.asyncIterator] === "function";
|
|
151
144
|
}
|
|
152
145
|
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
},
|
|
162
|
-
get(target, key) {
|
|
163
|
-
if (!Reflect.has(target, key) || Reflect.has(obj, key)) {
|
|
164
|
-
return Reflect.get(obj, key);
|
|
165
|
-
}
|
|
166
|
-
return Reflect.get(target, key);
|
|
167
|
-
},
|
|
168
|
-
defineProperty(_, key, descriptor) {
|
|
169
|
-
return Reflect.defineProperty(obj, key, descriptor);
|
|
170
|
-
},
|
|
171
|
-
set(_, key, value2) {
|
|
172
|
-
return Reflect.set(obj, key, value2);
|
|
173
|
-
},
|
|
174
|
-
deleteProperty(target, key) {
|
|
175
|
-
return Reflect.deleteProperty(target, key) && Reflect.deleteProperty(obj, key);
|
|
176
|
-
}
|
|
177
|
-
});
|
|
178
|
-
return proxy;
|
|
146
|
+
function parseEmptyableJSON(text) {
|
|
147
|
+
if (!text) {
|
|
148
|
+
return void 0;
|
|
149
|
+
}
|
|
150
|
+
return JSON.parse(text);
|
|
151
|
+
}
|
|
152
|
+
function stringifyJSON(value) {
|
|
153
|
+
return JSON.stringify(value);
|
|
179
154
|
}
|
|
180
155
|
|
|
181
|
-
// src/value.ts
|
|
182
156
|
function value(value2, ...args) {
|
|
183
157
|
if (typeof value2 === "function") {
|
|
184
158
|
return value2(...args);
|
|
@@ -186,30 +160,4 @@ function value(value2, ...args) {
|
|
|
186
160
|
return value2;
|
|
187
161
|
}
|
|
188
162
|
|
|
189
|
-
|
|
190
|
-
import { group, guard, mapEntries, mapValues, omit, trim } from "radash";
|
|
191
|
-
export {
|
|
192
|
-
ORPC_HANDLER_HEADER,
|
|
193
|
-
ORPC_HANDLER_VALUE,
|
|
194
|
-
createCallableObject,
|
|
195
|
-
findDeepMatches,
|
|
196
|
-
get,
|
|
197
|
-
group,
|
|
198
|
-
guard,
|
|
199
|
-
intercept,
|
|
200
|
-
isObject,
|
|
201
|
-
mapEntries,
|
|
202
|
-
mapValues,
|
|
203
|
-
omit,
|
|
204
|
-
onError,
|
|
205
|
-
onFinish,
|
|
206
|
-
onStart,
|
|
207
|
-
onSuccess,
|
|
208
|
-
once,
|
|
209
|
-
parseJSONSafely,
|
|
210
|
-
set,
|
|
211
|
-
toError,
|
|
212
|
-
trim,
|
|
213
|
-
value
|
|
214
|
-
};
|
|
215
|
-
//# sourceMappingURL=index.js.map
|
|
163
|
+
export { findDeepMatches, get, intercept, isAsyncIteratorObject, isObject, isTypescriptObject, onError, onFinish, onStart, onSuccess, once, parseEmptyableJSON, set, stringifyJSON, toError, 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.df024bb",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"homepage": "https://orpc.unnoq.com",
|
|
7
7
|
"repository": {
|
|
@@ -15,17 +15,12 @@
|
|
|
15
15
|
],
|
|
16
16
|
"exports": {
|
|
17
17
|
".": {
|
|
18
|
-
"types": "./dist/
|
|
19
|
-
"import": "./dist/index.
|
|
20
|
-
"default": "./dist/index.
|
|
21
|
-
},
|
|
22
|
-
"./🔒/*": {
|
|
23
|
-
"types": "./dist/src/*.d.ts"
|
|
18
|
+
"types": "./dist/index.d.mts",
|
|
19
|
+
"import": "./dist/index.mjs",
|
|
20
|
+
"default": "./dist/index.mjs"
|
|
24
21
|
}
|
|
25
22
|
},
|
|
26
23
|
"files": [
|
|
27
|
-
"!**/*.map",
|
|
28
|
-
"!**/*.tsbuildinfo",
|
|
29
24
|
"dist"
|
|
30
25
|
],
|
|
31
26
|
"dependencies": {
|
|
@@ -33,7 +28,7 @@
|
|
|
33
28
|
"type-fest": "^4.26.1"
|
|
34
29
|
},
|
|
35
30
|
"scripts": {
|
|
36
|
-
"build": "
|
|
31
|
+
"build": "unbuild",
|
|
37
32
|
"build:watch": "pnpm run build --watch",
|
|
38
33
|
"type:check": "tsc -b"
|
|
39
34
|
}
|
package/dist/src/chain.d.ts
DELETED
|
@@ -1,5 +0,0 @@
|
|
|
1
|
-
import type { AnyFunction } from './function';
|
|
2
|
-
export type OmitChainMethodDeep<T extends object, K extends keyof any> = {
|
|
3
|
-
[P in keyof Omit<T, K>]: T[P] extends AnyFunction ? ((...args: Parameters<T[P]>) => OmitChainMethodDeep<ReturnType<T[P]>, K>) : T[P];
|
|
4
|
-
};
|
|
5
|
-
//# sourceMappingURL=chain.d.ts.map
|
package/dist/src/constants.d.ts
DELETED
package/dist/src/error.d.ts
DELETED
package/dist/src/function.d.ts
DELETED
package/dist/src/index.d.ts
DELETED
|
@@ -1,13 +0,0 @@
|
|
|
1
|
-
export * from './chain';
|
|
2
|
-
export * from './constants';
|
|
3
|
-
export * from './error';
|
|
4
|
-
export * from './function';
|
|
5
|
-
export * from './interceptor';
|
|
6
|
-
export * from './json';
|
|
7
|
-
export * from './object';
|
|
8
|
-
export * from './proxy';
|
|
9
|
-
export * from './types';
|
|
10
|
-
export * from './value';
|
|
11
|
-
export { group, guard, mapEntries, mapValues, omit, trim } from 'radash';
|
|
12
|
-
export type { IsEqual, IsNever, JsonValue, PartialDeep, Promisable } from 'type-fest';
|
|
13
|
-
//# sourceMappingURL=index.d.ts.map
|
|
@@ -1,47 +0,0 @@
|
|
|
1
|
-
import type { Promisable } from 'type-fest';
|
|
2
|
-
import type { AnyFunction } from './function';
|
|
3
|
-
export type InterceptableOptions = Record<string, any>;
|
|
4
|
-
export type InterceptorOptions<TOptions extends InterceptableOptions, TResult> = Omit<TOptions, 'next'> & {
|
|
5
|
-
next(options?: TOptions): Promise<TResult>;
|
|
6
|
-
};
|
|
7
|
-
export type Interceptor<TOptions extends InterceptableOptions, TResult, TError> = (options: InterceptorOptions<TOptions, TResult>) => Promise<TResult> & {
|
|
8
|
-
__error?: {
|
|
9
|
-
type: TError;
|
|
10
|
-
};
|
|
11
|
-
};
|
|
12
|
-
/**
|
|
13
|
-
* Can used for interceptors or middlewares
|
|
14
|
-
*/
|
|
15
|
-
export declare function onStart<TOptions extends {
|
|
16
|
-
next(): any;
|
|
17
|
-
}, TRest extends any[]>(callback: NoInfer<(options: TOptions, ...rest: TRest) => Promisable<void>>): (options: TOptions, ...rest: TRest) => Promise<Awaited<ReturnType<TOptions['next']>>>;
|
|
18
|
-
/**
|
|
19
|
-
* Can used for interceptors or middlewares
|
|
20
|
-
*/
|
|
21
|
-
export declare function onSuccess<TOptions extends {
|
|
22
|
-
next(): any;
|
|
23
|
-
}, 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']>>>;
|
|
24
|
-
export type InferError<T extends AnyFunction> = T extends Interceptor<any, any, infer TError> ? TError : unknown;
|
|
25
|
-
/**
|
|
26
|
-
* Can used for interceptors or middlewares
|
|
27
|
-
*/
|
|
28
|
-
export declare function onError<TError, TOptions extends {
|
|
29
|
-
next(): any;
|
|
30
|
-
}, TRest extends any[]>(callback: NoInfer<(error: TError, options: TOptions, ...rest: TRest) => Promisable<void>>): (options: TOptions, ...rest: TRest) => Promise<Awaited<ReturnType<TOptions['next']>>> & {
|
|
31
|
-
__error?: {
|
|
32
|
-
type: TError;
|
|
33
|
-
};
|
|
34
|
-
};
|
|
35
|
-
export type OnFinishState<TResult, TError> = [TResult, undefined, 'success'] | [undefined, TError, 'error'];
|
|
36
|
-
/**
|
|
37
|
-
* Can used for interceptors or middlewares
|
|
38
|
-
*/
|
|
39
|
-
export declare function onFinish<TError, TOptions extends {
|
|
40
|
-
next(): any;
|
|
41
|
-
}, TRest extends any[]>(callback: NoInfer<(state: OnFinishState<Awaited<ReturnType<TOptions['next']>>, TError>, options: TOptions, ...rest: TRest) => Promisable<void>>): (options: TOptions, ...rest: TRest) => Promise<Awaited<ReturnType<TOptions['next']>>> & {
|
|
42
|
-
__error?: {
|
|
43
|
-
type: TError;
|
|
44
|
-
};
|
|
45
|
-
};
|
|
46
|
-
export declare function intercept<TOptions extends InterceptableOptions, TResult, TError>(interceptors: Interceptor<TOptions, TResult, TError>[], options: NoInfer<TOptions>, main: NoInfer<(options: TOptions) => Promisable<TResult>>): Promise<TResult>;
|
|
47
|
-
//# sourceMappingURL=interceptor.d.ts.map
|
package/dist/src/json.d.ts
DELETED
package/dist/src/object.d.ts
DELETED
|
@@ -1,12 +0,0 @@
|
|
|
1
|
-
export type Segment = string | number;
|
|
2
|
-
export declare function set(root: unknown, segments: Readonly<Segment[]>, value: unknown): unknown;
|
|
3
|
-
export declare function get(root: Readonly<Record<string, unknown> | unknown[]>, segments: Readonly<Segment[]>): unknown;
|
|
4
|
-
export declare function findDeepMatches(check: (value: unknown) => boolean, payload: unknown, segments?: Segment[], maps?: Segment[][], values?: unknown[]): {
|
|
5
|
-
maps: Segment[][];
|
|
6
|
-
values: unknown[];
|
|
7
|
-
};
|
|
8
|
-
/**
|
|
9
|
-
* Check if the value is an object even it created by `Object.create(null)` or more tricky way.
|
|
10
|
-
*/
|
|
11
|
-
export declare function isObject(value: unknown): value is Record<PropertyKey, unknown>;
|
|
12
|
-
//# sourceMappingURL=object.d.ts.map
|
package/dist/src/proxy.d.ts
DELETED
package/dist/src/types.d.ts
DELETED
package/dist/src/value.d.ts
DELETED
|
@@ -1,4 +0,0 @@
|
|
|
1
|
-
import type { Promisable } from 'type-fest';
|
|
2
|
-
export type Value<T, TArgs extends any[] = []> = T | ((...args: TArgs) => Promisable<T>);
|
|
3
|
-
export declare function value<T extends Value<any, TArgs>, TArgs extends any[] = []>(value: T, ...args: TArgs): Promise<T extends Value<infer U, any> ? U : never>;
|
|
4
|
-
//# sourceMappingURL=value.d.ts.map
|