@orpc/shared 0.0.0-next.cc4cb21 → 0.0.0-next.cd121e3

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,5 +1,5 @@
1
1
  <div align="center">
2
- <image align="center" src="https://orpc.unnoq.com/logo.webp" width=280 />
2
+ <image align="center" src="https://orpc.unnoq.com/logo.webp" width=280 alt="oRPC logo" />
3
3
  </div>
4
4
 
5
5
  <h1></h1>
@@ -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> = [options: TOptions] | (Record<never, never> extends TOptions ? [] : never);
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 };
@@ -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> = [options: TOptions] | (Record<never, never> extends TOptions ? [] : never);
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,5 +1,6 @@
1
- // src/object.ts
2
- function set(root, segments, value2) {
1
+ export { group, guard, mapEntries, mapValues, omit, retry, trim } from 'radash';
2
+
3
+ function set(root, segments, value) {
3
4
  const ref = { root };
4
5
  let currentRef = ref;
5
6
  let preSegment = "root";
@@ -7,7 +8,7 @@ function set(root, segments, value2) {
7
8
  currentRef = currentRef[preSegment];
8
9
  preSegment = segment;
9
10
  }
10
- currentRef[preSegment] = value2;
11
+ currentRef[preSegment] = value;
11
12
  return ref.root;
12
13
  }
13
14
  function get(root, segments) {
@@ -41,18 +42,17 @@ function findDeepMatches(check, payload, segments = [], maps = [], values = [])
41
42
  }
42
43
  return { maps, values };
43
44
  }
44
- function isObject(value2) {
45
- if (!value2 || typeof value2 !== "object") {
45
+ function isObject(value) {
46
+ if (!value || typeof value !== "object") {
46
47
  return false;
47
48
  }
48
- const proto = Object.getPrototypeOf(value2);
49
+ const proto = Object.getPrototypeOf(value);
49
50
  return proto === Object.prototype || !proto || !proto.constructor;
50
51
  }
51
- function isTypescriptObject(value2) {
52
- return !!value2 && (typeof value2 === "object" || typeof value2 === "function");
52
+ function isTypescriptObject(value) {
53
+ return !!value && (typeof value === "object" || typeof value === "function");
53
54
  }
54
55
 
55
- // src/error.ts
56
56
  function toError(error) {
57
57
  if (error instanceof Error) {
58
58
  return error;
@@ -71,7 +71,6 @@ function toError(error) {
71
71
  return new Error("Unknown error", { cause: error });
72
72
  }
73
73
 
74
- // src/function.ts
75
74
  function once(fn) {
76
75
  let cached;
77
76
  return () => {
@@ -84,7 +83,6 @@ function once(fn) {
84
83
  };
85
84
  }
86
85
 
87
- // src/interceptor.ts
88
86
  function onStart(callback) {
89
87
  return async (options, ...rest) => {
90
88
  await callback(options, ...rest);
@@ -138,7 +136,6 @@ async function intercept(interceptors, options, main) {
138
136
  return await next(options);
139
137
  }
140
138
 
141
- // src/iterator.ts
142
139
  function isAsyncIteratorObject(maybe) {
143
140
  if (!maybe || typeof maybe !== "object") {
144
141
  return false;
@@ -146,15 +143,16 @@ function isAsyncIteratorObject(maybe) {
146
143
  return Symbol.asyncIterator in maybe && typeof maybe[Symbol.asyncIterator] === "function";
147
144
  }
148
145
 
149
- // src/json.ts
150
146
  function parseEmptyableJSON(text) {
151
147
  if (!text) {
152
148
  return void 0;
153
149
  }
154
150
  return JSON.parse(text);
155
151
  }
152
+ function stringifyJSON(value) {
153
+ return JSON.stringify(value);
154
+ }
156
155
 
157
- // src/value.ts
158
156
  function value(value2, ...args) {
159
157
  if (typeof value2 === "function") {
160
158
  return value2(...args);
@@ -162,30 +160,4 @@ function value(value2, ...args) {
162
160
  return value2;
163
161
  }
164
162
 
165
- // src/index.ts
166
- import { group, guard, mapEntries, mapValues, omit, retry, trim } from "radash";
167
- export {
168
- findDeepMatches,
169
- get,
170
- group,
171
- guard,
172
- intercept,
173
- isAsyncIteratorObject,
174
- isObject,
175
- isTypescriptObject,
176
- mapEntries,
177
- mapValues,
178
- omit,
179
- onError,
180
- onFinish,
181
- onStart,
182
- onSuccess,
183
- once,
184
- parseEmptyableJSON,
185
- retry,
186
- set,
187
- toError,
188
- trim,
189
- value
190
- };
191
- //# 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.cc4cb21",
4
+ "version": "0.0.0-next.cd121e3",
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/src/index.d.ts",
19
- "import": "./dist/index.js",
20
- "default": "./dist/index.js"
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": "tsup --clean --sourcemap --entry.index=src/index.ts --format=esm --onSuccess='tsc -b --noCheck'",
31
+ "build": "unbuild",
37
32
  "build:watch": "pnpm run build --watch",
38
33
  "type:check": "tsc -b"
39
34
  }
@@ -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
@@ -1,2 +0,0 @@
1
- export declare function toError(error: unknown): Error;
2
- //# sourceMappingURL=error.d.ts.map
@@ -1,3 +0,0 @@
1
- export type AnyFunction = (...args: any[]) => any;
2
- export declare function once<T extends () => any>(fn: T): () => ReturnType<T>;
3
- //# sourceMappingURL=function.d.ts.map
@@ -1,12 +0,0 @@
1
- export * from './chain';
2
- export * from './error';
3
- export * from './function';
4
- export * from './interceptor';
5
- export * from './iterator';
6
- export * from './json';
7
- export * from './object';
8
- export * from './types';
9
- export * from './value';
10
- export { group, guard, mapEntries, mapValues, omit, retry, trim } from 'radash';
11
- export type { IsEqual, IsNever, PartialDeep, Promisable } from 'type-fest';
12
- //# sourceMappingURL=index.d.ts.map
@@ -1,45 +0,0 @@
1
- import type { Promisable } from 'type-fest';
2
- export type InterceptableOptions = Record<string, any>;
3
- export type InterceptorOptions<TOptions extends InterceptableOptions, TResult> = Omit<TOptions, 'next'> & {
4
- next(options?: TOptions): Promise<TResult>;
5
- };
6
- export type Interceptor<TOptions extends InterceptableOptions, TResult, TError> = (options: InterceptorOptions<TOptions, TResult>) => Promise<TResult> & {
7
- __error?: {
8
- type: TError;
9
- };
10
- };
11
- /**
12
- * Can used for interceptors or middlewares
13
- */
14
- export declare function onStart<TOptions extends {
15
- next(): any;
16
- }, TRest extends any[]>(callback: NoInfer<(options: TOptions, ...rest: TRest) => Promisable<void>>): (options: TOptions, ...rest: TRest) => Promise<Awaited<ReturnType<TOptions['next']>>>;
17
- /**
18
- * Can used for interceptors or middlewares
19
- */
20
- export declare function onSuccess<TOptions extends {
21
- next(): any;
22
- }, 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']>>>;
23
- /**
24
- * Can used for interceptors or middlewares
25
- */
26
- export declare function onError<TError, TOptions extends {
27
- next(): any;
28
- }, TRest extends any[]>(callback: NoInfer<(error: TError, options: TOptions, ...rest: TRest) => Promisable<void>>): (options: TOptions, ...rest: TRest) => Promise<Awaited<ReturnType<TOptions['next']>>> & {
29
- __error?: {
30
- type: TError;
31
- };
32
- };
33
- export type OnFinishState<TResult, TError> = [TResult, undefined, 'success'] | [undefined, TError, 'error'];
34
- /**
35
- * Can used for interceptors or middlewares
36
- */
37
- export declare function onFinish<TError, TOptions extends {
38
- next(): any;
39
- }, 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']>>> & {
40
- __error?: {
41
- type: TError;
42
- };
43
- };
44
- 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>;
45
- //# sourceMappingURL=interceptor.d.ts.map
@@ -1,2 +0,0 @@
1
- export declare function isAsyncIteratorObject(maybe: unknown): maybe is AsyncIteratorObject<any, any, any>;
2
- //# sourceMappingURL=iterator.d.ts.map
@@ -1,2 +0,0 @@
1
- export declare function parseEmptyableJSON(text: string): unknown;
2
- //# sourceMappingURL=json.d.ts.map
@@ -1,16 +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
- /**
13
- * Check if the value satisfy a `object` type in typescript
14
- */
15
- export declare function isTypescriptObject(value: unknown): value is object & Record<PropertyKey, unknown>;
16
- //# sourceMappingURL=object.d.ts.map
@@ -1,3 +0,0 @@
1
- export type MaybeOptionalOptions<TOptions> = [options: TOptions] | (Record<never, never> extends TOptions ? [] : never);
2
- export type SetOptional<T, K extends keyof T> = Omit<T, K> & Partial<Pick<T, K>>;
3
- //# sourceMappingURL=types.d.ts.map
@@ -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, TArgs extends any[]>(value: Value<T, TArgs>, ...args: NoInfer<TArgs>): Promise<T extends Value<infer U, any> ? U : never>;
4
- //# sourceMappingURL=value.d.ts.map