@orpc/shared 0.0.0-next.d16a1b6 → 0.0.0-next.d3b4900
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 +18 -1
- package/dist/index.d.mts +10 -6
- package/dist/index.d.ts +10 -6
- package/dist/index.mjs +47 -64
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -1,3 +1,8 @@
|
|
|
1
|
+
> [!WARNING]
|
|
2
|
+
>
|
|
3
|
+
> `@orpc/shared` is an internal dependency of oRPC packages. It does not follow semver and may change at any time without notice.
|
|
4
|
+
> Please do not use it in your project.
|
|
5
|
+
|
|
1
6
|
<div align="center">
|
|
2
7
|
<image align="center" src="https://orpc.unnoq.com/logo.webp" width=280 alt="oRPC logo" />
|
|
3
8
|
</div>
|
|
@@ -32,7 +37,7 @@
|
|
|
32
37
|
- **Contract-First Development 📜**: (Optional) Define your API contract upfront and implement it with confidence.
|
|
33
38
|
- **Exceptional Developer Experience ✨**: Enjoy a streamlined workflow with robust typing and clear, in-code documentation.
|
|
34
39
|
- **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.
|
|
40
|
+
- **Framework Integrations 🧩**: Supports Tanstack Query (React, Vue, Solid, Svelte), Pinia Colada, and more.
|
|
36
41
|
- **Server Actions ⚡️**: Fully compatible with React Server Actions on Next.js, TanStack Start, and more.
|
|
37
42
|
- **Standard Schema Support 🗂️**: Effortlessly work with Zod, Valibot, ArkType, and others right out of the box.
|
|
38
43
|
- **Fast & Lightweight 💨**: Built on native APIs across all runtimes – optimized for speed and efficiency.
|
|
@@ -55,14 +60,26 @@ You can find the full documentation [here](https://orpc.unnoq.com).
|
|
|
55
60
|
- [@orpc/client](https://www.npmjs.com/package/@orpc/client): Consume your API on the client with type-safety.
|
|
56
61
|
- [@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
62
|
- [@orpc/vue-query](https://www.npmjs.com/package/@orpc/vue-query): Integration with [Vue Query](https://tanstack.com/query/latest/docs/framework/vue/overview).
|
|
63
|
+
- [@orpc/solid-query](https://www.npmjs.com/package/@orpc/solid-query): Integration with [Solid Query](https://tanstack.com/query/latest/docs/framework/solid/overview).
|
|
64
|
+
- [@orpc/svelte-query](https://www.npmjs.com/package/@orpc/svelte-query): Integration with [Svelte Query](https://tanstack.com/query/latest/docs/framework/svelte/overview).
|
|
58
65
|
- [@orpc/vue-colada](https://www.npmjs.com/package/@orpc/vue-colada): Integration with [Pinia Colada](https://pinia-colada.esm.dev/).
|
|
59
66
|
- [@orpc/openapi](https://www.npmjs.com/package/@orpc/openapi): Generate OpenAPI specs and handle OpenAPI requests.
|
|
60
67
|
- [@orpc/zod](https://www.npmjs.com/package/@orpc/zod): More schemas that [Zod](https://zod.dev/) doesn't support yet.
|
|
68
|
+
- [@orpc/valibot](https://www.npmjs.com/package/@orpc/valibot): OpenAPI spec generation from [Valibot](https://valibot.dev/).
|
|
69
|
+
- [@orpc/arktype](https://www.npmjs.com/package/@orpc/arktype): OpenAPI spec generation from [ArkType](https://arktype.io/).
|
|
61
70
|
|
|
62
71
|
## `@orpc/shared`
|
|
63
72
|
|
|
64
73
|
Provides shared utilities for oRPC packages.
|
|
65
74
|
|
|
75
|
+
## Sponsors
|
|
76
|
+
|
|
77
|
+
<p align="center">
|
|
78
|
+
<a href="https://cdn.jsdelivr.net/gh/unnoq/unnoq/sponsors.svg">
|
|
79
|
+
<img src='https://cdn.jsdelivr.net/gh/unnoq/unnoq/sponsors.svg'/>
|
|
80
|
+
</a>
|
|
81
|
+
</p>
|
|
82
|
+
|
|
66
83
|
## License
|
|
67
84
|
|
|
68
85
|
Distributed under the MIT License. See [LICENSE](https://github.com/unnoq/orpc/blob/main/LICENSE) for more information.
|
package/dist/index.d.mts
CHANGED
|
@@ -1,6 +1,11 @@
|
|
|
1
1
|
import { Promisable } from 'type-fest';
|
|
2
2
|
export { IsEqual, IsNever, PartialDeep, Promisable } from 'type-fest';
|
|
3
|
-
export { group, guard, mapEntries, mapValues, omit
|
|
3
|
+
export { group, guard, mapEntries, mapValues, omit } from 'radash';
|
|
4
|
+
|
|
5
|
+
type MaybeOptionalOptions<TOptions> = Record<never, never> extends TOptions ? [options?: TOptions] : [options: TOptions];
|
|
6
|
+
declare function resolveMaybeOptionalOptions<T>(rest: MaybeOptionalOptions<T>): T;
|
|
7
|
+
|
|
8
|
+
declare function toArray<T>(value: T | T[] | null | undefined): T[];
|
|
4
9
|
|
|
5
10
|
type AnyFunction = (...args: any[]) => any;
|
|
6
11
|
declare function once<T extends () => any>(fn: T): () => ReturnType<T>;
|
|
@@ -42,7 +47,7 @@ declare function onError<TError, TOptions extends {
|
|
|
42
47
|
type: TError;
|
|
43
48
|
};
|
|
44
49
|
};
|
|
45
|
-
type OnFinishState<TResult, TError> = [TResult,
|
|
50
|
+
type OnFinishState<TResult, TError> = [TResult, null, 'success'] | [undefined, TError, 'error'];
|
|
46
51
|
/**
|
|
47
52
|
* Can used for interceptors or middlewares
|
|
48
53
|
*/
|
|
@@ -61,8 +66,6 @@ declare function parseEmptyableJSON(text: string | null | undefined): unknown;
|
|
|
61
66
|
declare function stringifyJSON<T>(value: T): undefined extends T ? undefined | string : string;
|
|
62
67
|
|
|
63
68
|
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
69
|
declare function findDeepMatches(check: (value: unknown) => boolean, payload: unknown, segments?: Segment[], maps?: Segment[][], values?: unknown[]): {
|
|
67
70
|
maps: Segment[][];
|
|
68
71
|
values: unknown[];
|
|
@@ -75,11 +78,12 @@ declare function isObject(value: unknown): value is Record<PropertyKey, unknown>
|
|
|
75
78
|
* Check if the value satisfy a `object` type in typescript
|
|
76
79
|
*/
|
|
77
80
|
declare function isTypescriptObject(value: unknown): value is object & Record<PropertyKey, unknown>;
|
|
81
|
+
declare function clone<T>(value: T): T;
|
|
78
82
|
|
|
79
|
-
type MaybeOptionalOptions<TOptions> = [options: TOptions] | (Record<never, never> extends TOptions ? [] : never);
|
|
80
83
|
type SetOptional<T, K extends keyof T> = Omit<T, K> & Partial<Pick<T, K>>;
|
|
84
|
+
type IntersectPick<T, U> = Pick<T, keyof T & keyof U>;
|
|
81
85
|
|
|
82
86
|
type Value<T, TArgs extends any[] = []> = T | ((...args: TArgs) => Promisable<T>);
|
|
83
87
|
declare function value<T, TArgs extends any[]>(value: Value<T, TArgs>, ...args: NoInfer<TArgs>): Promise<T extends Value<infer U, any> ? U : never>;
|
|
84
88
|
|
|
85
|
-
export { type AnyFunction, type InterceptableOptions, type Interceptor, type InterceptorOptions, type MaybeOptionalOptions, type OmitChainMethodDeep, type OnFinishState, type Segment, type SetOptional, type Value,
|
|
89
|
+
export { type AnyFunction, type InterceptableOptions, type Interceptor, type InterceptorOptions, type IntersectPick, type MaybeOptionalOptions, type OmitChainMethodDeep, type OnFinishState, type Segment, type SetOptional, type Value, clone, findDeepMatches, intercept, isAsyncIteratorObject, isObject, isTypescriptObject, onError, onFinish, onStart, onSuccess, once, parseEmptyableJSON, resolveMaybeOptionalOptions, stringifyJSON, toArray, toError, value };
|
package/dist/index.d.ts
CHANGED
|
@@ -1,6 +1,11 @@
|
|
|
1
1
|
import { Promisable } from 'type-fest';
|
|
2
2
|
export { IsEqual, IsNever, PartialDeep, Promisable } from 'type-fest';
|
|
3
|
-
export { group, guard, mapEntries, mapValues, omit
|
|
3
|
+
export { group, guard, mapEntries, mapValues, omit } from 'radash';
|
|
4
|
+
|
|
5
|
+
type MaybeOptionalOptions<TOptions> = Record<never, never> extends TOptions ? [options?: TOptions] : [options: TOptions];
|
|
6
|
+
declare function resolveMaybeOptionalOptions<T>(rest: MaybeOptionalOptions<T>): T;
|
|
7
|
+
|
|
8
|
+
declare function toArray<T>(value: T | T[] | null | undefined): T[];
|
|
4
9
|
|
|
5
10
|
type AnyFunction = (...args: any[]) => any;
|
|
6
11
|
declare function once<T extends () => any>(fn: T): () => ReturnType<T>;
|
|
@@ -42,7 +47,7 @@ declare function onError<TError, TOptions extends {
|
|
|
42
47
|
type: TError;
|
|
43
48
|
};
|
|
44
49
|
};
|
|
45
|
-
type OnFinishState<TResult, TError> = [TResult,
|
|
50
|
+
type OnFinishState<TResult, TError> = [TResult, null, 'success'] | [undefined, TError, 'error'];
|
|
46
51
|
/**
|
|
47
52
|
* Can used for interceptors or middlewares
|
|
48
53
|
*/
|
|
@@ -61,8 +66,6 @@ declare function parseEmptyableJSON(text: string | null | undefined): unknown;
|
|
|
61
66
|
declare function stringifyJSON<T>(value: T): undefined extends T ? undefined | string : string;
|
|
62
67
|
|
|
63
68
|
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
69
|
declare function findDeepMatches(check: (value: unknown) => boolean, payload: unknown, segments?: Segment[], maps?: Segment[][], values?: unknown[]): {
|
|
67
70
|
maps: Segment[][];
|
|
68
71
|
values: unknown[];
|
|
@@ -75,11 +78,12 @@ declare function isObject(value: unknown): value is Record<PropertyKey, unknown>
|
|
|
75
78
|
* Check if the value satisfy a `object` type in typescript
|
|
76
79
|
*/
|
|
77
80
|
declare function isTypescriptObject(value: unknown): value is object & Record<PropertyKey, unknown>;
|
|
81
|
+
declare function clone<T>(value: T): T;
|
|
78
82
|
|
|
79
|
-
type MaybeOptionalOptions<TOptions> = [options: TOptions] | (Record<never, never> extends TOptions ? [] : never);
|
|
80
83
|
type SetOptional<T, K extends keyof T> = Omit<T, K> & Partial<Pick<T, K>>;
|
|
84
|
+
type IntersectPick<T, U> = Pick<T, keyof T & keyof U>;
|
|
81
85
|
|
|
82
86
|
type Value<T, TArgs extends any[] = []> = T | ((...args: TArgs) => Promisable<T>);
|
|
83
87
|
declare function value<T, TArgs extends any[]>(value: Value<T, TArgs>, ...args: NoInfer<TArgs>): Promise<T extends Value<infer U, any> ? U : never>;
|
|
84
88
|
|
|
85
|
-
export { type AnyFunction, type InterceptableOptions, type Interceptor, type InterceptorOptions, type MaybeOptionalOptions, type OmitChainMethodDeep, type OnFinishState, type Segment, type SetOptional, type Value,
|
|
89
|
+
export { type AnyFunction, type InterceptableOptions, type Interceptor, type InterceptorOptions, type IntersectPick, type MaybeOptionalOptions, type OmitChainMethodDeep, type OnFinishState, type Segment, type SetOptional, type Value, clone, findDeepMatches, intercept, isAsyncIteratorObject, isObject, isTypescriptObject, onError, onFinish, onStart, onSuccess, once, parseEmptyableJSON, resolveMaybeOptionalOptions, stringifyJSON, toArray, toError, value };
|
package/dist/index.mjs
CHANGED
|
@@ -1,73 +1,17 @@
|
|
|
1
|
-
export { group, guard, mapEntries, mapValues, omit
|
|
1
|
+
export { group, guard, mapEntries, mapValues, omit } from 'radash';
|
|
2
2
|
|
|
3
|
-
function
|
|
4
|
-
|
|
5
|
-
let currentRef = ref;
|
|
6
|
-
let preSegment = "root";
|
|
7
|
-
for (const segment of segments) {
|
|
8
|
-
currentRef = currentRef[preSegment];
|
|
9
|
-
preSegment = segment;
|
|
10
|
-
}
|
|
11
|
-
currentRef[preSegment] = value;
|
|
12
|
-
return ref.root;
|
|
13
|
-
}
|
|
14
|
-
function get(root, segments) {
|
|
15
|
-
const ref = { root };
|
|
16
|
-
let currentRef = ref;
|
|
17
|
-
let preSegment = "root";
|
|
18
|
-
for (const segment of segments) {
|
|
19
|
-
if (typeof currentRef !== "object" && typeof currentRef !== "function" || currentRef === null) {
|
|
20
|
-
return void 0;
|
|
21
|
-
}
|
|
22
|
-
currentRef = currentRef[preSegment];
|
|
23
|
-
preSegment = segment;
|
|
24
|
-
}
|
|
25
|
-
if (typeof currentRef !== "object" && typeof currentRef !== "function" || currentRef === null) {
|
|
26
|
-
return void 0;
|
|
27
|
-
}
|
|
28
|
-
return currentRef[preSegment];
|
|
3
|
+
function resolveMaybeOptionalOptions(rest) {
|
|
4
|
+
return rest[0] ?? {};
|
|
29
5
|
}
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
values.push(payload);
|
|
34
|
-
} else if (Array.isArray(payload)) {
|
|
35
|
-
payload.forEach((v, i) => {
|
|
36
|
-
findDeepMatches(check, v, [...segments, i], maps, values);
|
|
37
|
-
});
|
|
38
|
-
} else if (isObject(payload)) {
|
|
39
|
-
for (const key in payload) {
|
|
40
|
-
findDeepMatches(check, payload[key], [...segments, key], maps, values);
|
|
41
|
-
}
|
|
42
|
-
}
|
|
43
|
-
return { maps, values };
|
|
44
|
-
}
|
|
45
|
-
function isObject(value) {
|
|
46
|
-
if (!value || typeof value !== "object") {
|
|
47
|
-
return false;
|
|
48
|
-
}
|
|
49
|
-
const proto = Object.getPrototypeOf(value);
|
|
50
|
-
return proto === Object.prototype || !proto || !proto.constructor;
|
|
51
|
-
}
|
|
52
|
-
function isTypescriptObject(value) {
|
|
53
|
-
return !!value && (typeof value === "object" || typeof value === "function");
|
|
6
|
+
|
|
7
|
+
function toArray(value) {
|
|
8
|
+
return Array.isArray(value) ? value : value === void 0 || value === null ? [] : [value];
|
|
54
9
|
}
|
|
55
10
|
|
|
56
11
|
function toError(error) {
|
|
57
12
|
if (error instanceof Error) {
|
|
58
13
|
return error;
|
|
59
14
|
}
|
|
60
|
-
if (typeof error === "string") {
|
|
61
|
-
return new Error(error, { cause: error });
|
|
62
|
-
}
|
|
63
|
-
if (isObject(error)) {
|
|
64
|
-
if ("message" in error && typeof error.message === "string") {
|
|
65
|
-
return new Error(error.message, { cause: error });
|
|
66
|
-
}
|
|
67
|
-
if ("name" in error && typeof error.name === "string") {
|
|
68
|
-
return new Error(error.name, { cause: error });
|
|
69
|
-
}
|
|
70
|
-
}
|
|
71
15
|
return new Error("Unknown error", { cause: error });
|
|
72
16
|
}
|
|
73
17
|
|
|
@@ -111,7 +55,7 @@ function onFinish(callback) {
|
|
|
111
55
|
return async (options, ...rest) => {
|
|
112
56
|
try {
|
|
113
57
|
const result = await options.next();
|
|
114
|
-
state = [result,
|
|
58
|
+
state = [result, null, "success"];
|
|
115
59
|
return result;
|
|
116
60
|
} catch (error) {
|
|
117
61
|
state = [void 0, error, "error"];
|
|
@@ -153,6 +97,45 @@ function stringifyJSON(value) {
|
|
|
153
97
|
return JSON.stringify(value);
|
|
154
98
|
}
|
|
155
99
|
|
|
100
|
+
function findDeepMatches(check, payload, segments = [], maps = [], values = []) {
|
|
101
|
+
if (check(payload)) {
|
|
102
|
+
maps.push(segments);
|
|
103
|
+
values.push(payload);
|
|
104
|
+
} else if (Array.isArray(payload)) {
|
|
105
|
+
payload.forEach((v, i) => {
|
|
106
|
+
findDeepMatches(check, v, [...segments, i], maps, values);
|
|
107
|
+
});
|
|
108
|
+
} else if (isObject(payload)) {
|
|
109
|
+
for (const key in payload) {
|
|
110
|
+
findDeepMatches(check, payload[key], [...segments, key], maps, values);
|
|
111
|
+
}
|
|
112
|
+
}
|
|
113
|
+
return { maps, values };
|
|
114
|
+
}
|
|
115
|
+
function isObject(value) {
|
|
116
|
+
if (!value || typeof value !== "object") {
|
|
117
|
+
return false;
|
|
118
|
+
}
|
|
119
|
+
const proto = Object.getPrototypeOf(value);
|
|
120
|
+
return proto === Object.prototype || !proto || !proto.constructor;
|
|
121
|
+
}
|
|
122
|
+
function isTypescriptObject(value) {
|
|
123
|
+
return !!value && (typeof value === "object" || typeof value === "function");
|
|
124
|
+
}
|
|
125
|
+
function clone(value) {
|
|
126
|
+
if (Array.isArray(value)) {
|
|
127
|
+
return value.map(clone);
|
|
128
|
+
}
|
|
129
|
+
if (isObject(value)) {
|
|
130
|
+
const result = {};
|
|
131
|
+
for (const key in value) {
|
|
132
|
+
result[key] = clone(value[key]);
|
|
133
|
+
}
|
|
134
|
+
return result;
|
|
135
|
+
}
|
|
136
|
+
return value;
|
|
137
|
+
}
|
|
138
|
+
|
|
156
139
|
function value(value2, ...args) {
|
|
157
140
|
if (typeof value2 === "function") {
|
|
158
141
|
return value2(...args);
|
|
@@ -160,4 +143,4 @@ function value(value2, ...args) {
|
|
|
160
143
|
return value2;
|
|
161
144
|
}
|
|
162
145
|
|
|
163
|
-
export {
|
|
146
|
+
export { clone, findDeepMatches, intercept, isAsyncIteratorObject, isObject, isTypescriptObject, onError, onFinish, onStart, onSuccess, once, parseEmptyableJSON, resolveMaybeOptionalOptions, stringifyJSON, toArray, toError, value };
|