@orpc/shared 0.47.0 → 1.0.0-beta.1

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 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,6 +60,8 @@ 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.
package/dist/index.d.mts CHANGED
@@ -42,7 +42,7 @@ declare function onError<TError, TOptions extends {
42
42
  type: TError;
43
43
  };
44
44
  };
45
- type OnFinishState<TResult, TError> = [TResult, undefined, 'success'] | [undefined, TError, 'error'];
45
+ type OnFinishState<TResult, TError> = [TResult, null, 'success'] | [undefined, TError, 'error'];
46
46
  /**
47
47
  * Can used for interceptors or middlewares
48
48
  */
@@ -61,8 +61,6 @@ declare function parseEmptyableJSON(text: string | null | undefined): unknown;
61
61
  declare function stringifyJSON<T>(value: T): undefined extends T ? undefined | string : string;
62
62
 
63
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
64
  declare function findDeepMatches(check: (value: unknown) => boolean, payload: unknown, segments?: Segment[], maps?: Segment[][], values?: unknown[]): {
67
65
  maps: Segment[][];
68
66
  values: unknown[];
@@ -83,4 +81,4 @@ type SetOptional<T, K extends keyof T> = Omit<T, K> & Partial<Pick<T, K>>;
83
81
  type Value<T, TArgs extends any[] = []> = T | ((...args: TArgs) => Promisable<T>);
84
82
  declare function value<T, TArgs extends any[]>(value: Value<T, TArgs>, ...args: NoInfer<TArgs>): Promise<T extends Value<infer U, any> ? U : never>;
85
83
 
86
- export { type AnyFunction, type InterceptableOptions, type Interceptor, type InterceptorOptions, type MaybeOptionalOptions, type OmitChainMethodDeep, type OnFinishState, type Segment, type SetOptional, type Value, clone, findDeepMatches, get, intercept, isAsyncIteratorObject, isObject, isTypescriptObject, onError, onFinish, onStart, onSuccess, once, parseEmptyableJSON, set, stringifyJSON, toError, value };
84
+ export { type AnyFunction, type InterceptableOptions, type Interceptor, type InterceptorOptions, type MaybeOptionalOptions, type OmitChainMethodDeep, type OnFinishState, type Segment, type SetOptional, type Value, clone, findDeepMatches, intercept, isAsyncIteratorObject, isObject, isTypescriptObject, onError, onFinish, onStart, onSuccess, once, parseEmptyableJSON, stringifyJSON, toError, value };
package/dist/index.d.ts CHANGED
@@ -42,7 +42,7 @@ declare function onError<TError, TOptions extends {
42
42
  type: TError;
43
43
  };
44
44
  };
45
- type OnFinishState<TResult, TError> = [TResult, undefined, 'success'] | [undefined, TError, 'error'];
45
+ type OnFinishState<TResult, TError> = [TResult, null, 'success'] | [undefined, TError, 'error'];
46
46
  /**
47
47
  * Can used for interceptors or middlewares
48
48
  */
@@ -61,8 +61,6 @@ declare function parseEmptyableJSON(text: string | null | undefined): unknown;
61
61
  declare function stringifyJSON<T>(value: T): undefined extends T ? undefined | string : string;
62
62
 
63
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
64
  declare function findDeepMatches(check: (value: unknown) => boolean, payload: unknown, segments?: Segment[], maps?: Segment[][], values?: unknown[]): {
67
65
  maps: Segment[][];
68
66
  values: unknown[];
@@ -83,4 +81,4 @@ type SetOptional<T, K extends keyof T> = Omit<T, K> & Partial<Pick<T, K>>;
83
81
  type Value<T, TArgs extends any[] = []> = T | ((...args: TArgs) => Promisable<T>);
84
82
  declare function value<T, TArgs extends any[]>(value: Value<T, TArgs>, ...args: NoInfer<TArgs>): Promise<T extends Value<infer U, any> ? U : never>;
85
83
 
86
- export { type AnyFunction, type InterceptableOptions, type Interceptor, type InterceptorOptions, type MaybeOptionalOptions, type OmitChainMethodDeep, type OnFinishState, type Segment, type SetOptional, type Value, clone, findDeepMatches, get, intercept, isAsyncIteratorObject, isObject, isTypescriptObject, onError, onFinish, onStart, onSuccess, once, parseEmptyableJSON, set, stringifyJSON, toError, value };
84
+ export { type AnyFunction, type InterceptableOptions, type Interceptor, type InterceptorOptions, type MaybeOptionalOptions, type OmitChainMethodDeep, type OnFinishState, type Segment, type SetOptional, type Value, clone, findDeepMatches, intercept, isAsyncIteratorObject, isObject, isTypescriptObject, onError, onFinish, onStart, onSuccess, once, parseEmptyableJSON, stringifyJSON, toError, value };
package/dist/index.mjs CHANGED
@@ -1,86 +1,9 @@
1
1
  export { group, guard, mapEntries, mapValues, omit, retry, trim } from 'radash';
2
2
 
3
- function set(root, segments, value) {
4
- const ref = { root };
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];
29
- }
30
- function findDeepMatches(check, payload, segments = [], maps = [], values = []) {
31
- if (check(payload)) {
32
- maps.push(segments);
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");
54
- }
55
- function clone(value) {
56
- if (Array.isArray(value)) {
57
- return value.map(clone);
58
- }
59
- if (isObject(value)) {
60
- const result = {};
61
- for (const key in value) {
62
- result[key] = clone(value[key]);
63
- }
64
- return result;
65
- }
66
- return value;
67
- }
68
-
69
3
  function toError(error) {
70
4
  if (error instanceof Error) {
71
5
  return error;
72
6
  }
73
- if (typeof error === "string") {
74
- return new Error(error, { cause: error });
75
- }
76
- if (isObject(error)) {
77
- if ("message" in error && typeof error.message === "string") {
78
- return new Error(error.message, { cause: error });
79
- }
80
- if ("name" in error && typeof error.name === "string") {
81
- return new Error(error.name, { cause: error });
82
- }
83
- }
84
7
  return new Error("Unknown error", { cause: error });
85
8
  }
86
9
 
@@ -124,7 +47,7 @@ function onFinish(callback) {
124
47
  return async (options, ...rest) => {
125
48
  try {
126
49
  const result = await options.next();
127
- state = [result, void 0, "success"];
50
+ state = [result, null, "success"];
128
51
  return result;
129
52
  } catch (error) {
130
53
  state = [void 0, error, "error"];
@@ -166,6 +89,45 @@ function stringifyJSON(value) {
166
89
  return JSON.stringify(value);
167
90
  }
168
91
 
92
+ function findDeepMatches(check, payload, segments = [], maps = [], values = []) {
93
+ if (check(payload)) {
94
+ maps.push(segments);
95
+ values.push(payload);
96
+ } else if (Array.isArray(payload)) {
97
+ payload.forEach((v, i) => {
98
+ findDeepMatches(check, v, [...segments, i], maps, values);
99
+ });
100
+ } else if (isObject(payload)) {
101
+ for (const key in payload) {
102
+ findDeepMatches(check, payload[key], [...segments, key], maps, values);
103
+ }
104
+ }
105
+ return { maps, values };
106
+ }
107
+ function isObject(value) {
108
+ if (!value || typeof value !== "object") {
109
+ return false;
110
+ }
111
+ const proto = Object.getPrototypeOf(value);
112
+ return proto === Object.prototype || !proto || !proto.constructor;
113
+ }
114
+ function isTypescriptObject(value) {
115
+ return !!value && (typeof value === "object" || typeof value === "function");
116
+ }
117
+ function clone(value) {
118
+ if (Array.isArray(value)) {
119
+ return value.map(clone);
120
+ }
121
+ if (isObject(value)) {
122
+ const result = {};
123
+ for (const key in value) {
124
+ result[key] = clone(value[key]);
125
+ }
126
+ return result;
127
+ }
128
+ return value;
129
+ }
130
+
169
131
  function value(value2, ...args) {
170
132
  if (typeof value2 === "function") {
171
133
  return value2(...args);
@@ -173,4 +135,4 @@ function value(value2, ...args) {
173
135
  return value2;
174
136
  }
175
137
 
176
- export { clone, findDeepMatches, get, intercept, isAsyncIteratorObject, isObject, isTypescriptObject, onError, onFinish, onStart, onSuccess, once, parseEmptyableJSON, set, stringifyJSON, toError, value };
138
+ export { clone, findDeepMatches, intercept, isAsyncIteratorObject, isObject, isTypescriptObject, onError, onFinish, onStart, onSuccess, once, parseEmptyableJSON, 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.47.0",
4
+ "version": "1.0.0-beta.1",
5
5
  "license": "MIT",
6
6
  "homepage": "https://orpc.unnoq.com",
7
7
  "repository": {