@orpc/shared 0.0.0-next.fe39bf3 → 0.0.0-next.fe89a39
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 +81 -0
- package/dist/index.d.mts +354 -0
- package/dist/index.d.ts +354 -0
- package/dist/index.mjs +708 -0
- package/package.json +21 -12
- package/dist/index.js +0 -155
- package/dist/src/chain.d.ts +0 -5
- package/dist/src/error.d.ts +0 -2
- package/dist/src/function.d.ts +0 -2
- package/dist/src/index.d.ts +0 -10
- package/dist/src/interceptor.d.ts +0 -45
- package/dist/src/object.d.ts +0 -12
- package/dist/src/types.d.ts +0 -3
- package/dist/src/value.d.ts +0 -4
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.fe89a39",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"homepage": "https://orpc.unnoq.com",
|
|
7
7
|
"repository": {
|
|
@@ -15,25 +15,34 @@
|
|
|
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
|
],
|
|
26
|
+
"peerDependencies": {
|
|
27
|
+
"@opentelemetry/api": ">=1.9.0"
|
|
28
|
+
},
|
|
29
|
+
"peerDependenciesMeta": {
|
|
30
|
+
"@opentelemetry/api": {
|
|
31
|
+
"optional": true
|
|
32
|
+
}
|
|
33
|
+
},
|
|
31
34
|
"dependencies": {
|
|
32
|
-
"radash": "^12.1.
|
|
33
|
-
"type-fest": "^
|
|
35
|
+
"radash": "^12.1.1",
|
|
36
|
+
"type-fest": "^5.1.0"
|
|
37
|
+
},
|
|
38
|
+
"devDependencies": {
|
|
39
|
+
"@opentelemetry/api": "^1.9.0",
|
|
40
|
+
"arktype": "2.1.23",
|
|
41
|
+
"valibot": "^1.1.0",
|
|
42
|
+
"zod": "^4.1.12"
|
|
34
43
|
},
|
|
35
44
|
"scripts": {
|
|
36
|
-
"build": "
|
|
45
|
+
"build": "unbuild",
|
|
37
46
|
"build:watch": "pnpm run build --watch",
|
|
38
47
|
"type:check": "tsc -b"
|
|
39
48
|
}
|
package/dist/index.js
DELETED
|
@@ -1,155 +0,0 @@
|
|
|
1
|
-
// src/object.ts
|
|
2
|
-
function set(root, segments, value2) {
|
|
3
|
-
const ref = { root };
|
|
4
|
-
let currentRef = ref;
|
|
5
|
-
let preSegment = "root";
|
|
6
|
-
for (const segment of segments) {
|
|
7
|
-
currentRef = currentRef[preSegment];
|
|
8
|
-
preSegment = segment;
|
|
9
|
-
}
|
|
10
|
-
currentRef[preSegment] = value2;
|
|
11
|
-
return ref.root;
|
|
12
|
-
}
|
|
13
|
-
function get(root, segments) {
|
|
14
|
-
const ref = { root };
|
|
15
|
-
let currentRef = ref;
|
|
16
|
-
let preSegment = "root";
|
|
17
|
-
for (const segment of segments) {
|
|
18
|
-
if (typeof currentRef !== "object" && typeof currentRef !== "function" || currentRef === null) {
|
|
19
|
-
return void 0;
|
|
20
|
-
}
|
|
21
|
-
currentRef = currentRef[preSegment];
|
|
22
|
-
preSegment = segment;
|
|
23
|
-
}
|
|
24
|
-
if (typeof currentRef !== "object" && typeof currentRef !== "function" || currentRef === null) {
|
|
25
|
-
return void 0;
|
|
26
|
-
}
|
|
27
|
-
return currentRef[preSegment];
|
|
28
|
-
}
|
|
29
|
-
function findDeepMatches(check, payload, segments = [], maps = [], values = []) {
|
|
30
|
-
if (check(payload)) {
|
|
31
|
-
maps.push(segments);
|
|
32
|
-
values.push(payload);
|
|
33
|
-
} else if (Array.isArray(payload)) {
|
|
34
|
-
payload.forEach((v, i) => {
|
|
35
|
-
findDeepMatches(check, v, [...segments, i], maps, values);
|
|
36
|
-
});
|
|
37
|
-
} else if (isObject(payload)) {
|
|
38
|
-
for (const key in payload) {
|
|
39
|
-
findDeepMatches(check, payload[key], [...segments, key], maps, values);
|
|
40
|
-
}
|
|
41
|
-
}
|
|
42
|
-
return { maps, values };
|
|
43
|
-
}
|
|
44
|
-
function isObject(value2) {
|
|
45
|
-
if (!value2 || typeof value2 !== "object") {
|
|
46
|
-
return false;
|
|
47
|
-
}
|
|
48
|
-
const proto = Object.getPrototypeOf(value2);
|
|
49
|
-
return proto === Object.prototype || !proto || !proto.constructor;
|
|
50
|
-
}
|
|
51
|
-
|
|
52
|
-
// src/error.ts
|
|
53
|
-
function toError(error) {
|
|
54
|
-
if (error instanceof Error) {
|
|
55
|
-
return error;
|
|
56
|
-
}
|
|
57
|
-
if (typeof error === "string") {
|
|
58
|
-
return new Error(error, { cause: error });
|
|
59
|
-
}
|
|
60
|
-
if (isObject(error)) {
|
|
61
|
-
if ("message" in error && typeof error.message === "string") {
|
|
62
|
-
return new Error(error.message, { cause: error });
|
|
63
|
-
}
|
|
64
|
-
if ("name" in error && typeof error.name === "string") {
|
|
65
|
-
return new Error(error.name, { cause: error });
|
|
66
|
-
}
|
|
67
|
-
}
|
|
68
|
-
return new Error("Unknown error", { cause: error });
|
|
69
|
-
}
|
|
70
|
-
|
|
71
|
-
// src/interceptor.ts
|
|
72
|
-
function onStart(callback) {
|
|
73
|
-
return async (options, ...rest) => {
|
|
74
|
-
await callback(options, ...rest);
|
|
75
|
-
return await options.next();
|
|
76
|
-
};
|
|
77
|
-
}
|
|
78
|
-
function onSuccess(callback) {
|
|
79
|
-
return async (options, ...rest) => {
|
|
80
|
-
const result = await options.next();
|
|
81
|
-
await callback(result, options, ...rest);
|
|
82
|
-
return result;
|
|
83
|
-
};
|
|
84
|
-
}
|
|
85
|
-
function onError(callback) {
|
|
86
|
-
return async (options, ...rest) => {
|
|
87
|
-
try {
|
|
88
|
-
return await options.next();
|
|
89
|
-
} catch (error) {
|
|
90
|
-
await callback(error, options, ...rest);
|
|
91
|
-
throw error;
|
|
92
|
-
}
|
|
93
|
-
};
|
|
94
|
-
}
|
|
95
|
-
function onFinish(callback) {
|
|
96
|
-
let state;
|
|
97
|
-
return async (options, ...rest) => {
|
|
98
|
-
try {
|
|
99
|
-
const result = await options.next();
|
|
100
|
-
state = [result, void 0, "success"];
|
|
101
|
-
return result;
|
|
102
|
-
} catch (error) {
|
|
103
|
-
state = [void 0, error, "error"];
|
|
104
|
-
throw error;
|
|
105
|
-
} finally {
|
|
106
|
-
await callback(state, options, ...rest);
|
|
107
|
-
}
|
|
108
|
-
};
|
|
109
|
-
}
|
|
110
|
-
async function intercept(interceptors, options, main) {
|
|
111
|
-
let index = 0;
|
|
112
|
-
const next = async (options2) => {
|
|
113
|
-
const interceptor = interceptors[index++];
|
|
114
|
-
if (!interceptor) {
|
|
115
|
-
return await main(options2);
|
|
116
|
-
}
|
|
117
|
-
return await interceptor({
|
|
118
|
-
...options2,
|
|
119
|
-
next: (newOptions = options2) => next(newOptions)
|
|
120
|
-
});
|
|
121
|
-
};
|
|
122
|
-
return await next(options);
|
|
123
|
-
}
|
|
124
|
-
|
|
125
|
-
// src/value.ts
|
|
126
|
-
function value(value2, ...args) {
|
|
127
|
-
if (typeof value2 === "function") {
|
|
128
|
-
return value2(...args);
|
|
129
|
-
}
|
|
130
|
-
return value2;
|
|
131
|
-
}
|
|
132
|
-
|
|
133
|
-
// src/index.ts
|
|
134
|
-
import { group, guard, mapEntries, mapValues, omit, retry, trim } from "radash";
|
|
135
|
-
export {
|
|
136
|
-
findDeepMatches,
|
|
137
|
-
get,
|
|
138
|
-
group,
|
|
139
|
-
guard,
|
|
140
|
-
intercept,
|
|
141
|
-
isObject,
|
|
142
|
-
mapEntries,
|
|
143
|
-
mapValues,
|
|
144
|
-
omit,
|
|
145
|
-
onError,
|
|
146
|
-
onFinish,
|
|
147
|
-
onStart,
|
|
148
|
-
onSuccess,
|
|
149
|
-
retry,
|
|
150
|
-
set,
|
|
151
|
-
toError,
|
|
152
|
-
trim,
|
|
153
|
-
value
|
|
154
|
-
};
|
|
155
|
-
//# sourceMappingURL=index.js.map
|
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/error.d.ts
DELETED
package/dist/src/function.d.ts
DELETED
package/dist/src/index.d.ts
DELETED
|
@@ -1,10 +0,0 @@
|
|
|
1
|
-
export * from './chain';
|
|
2
|
-
export * from './error';
|
|
3
|
-
export * from './function';
|
|
4
|
-
export * from './interceptor';
|
|
5
|
-
export * from './object';
|
|
6
|
-
export * from './types';
|
|
7
|
-
export * from './value';
|
|
8
|
-
export { group, guard, mapEntries, mapValues, omit, retry, trim } from 'radash';
|
|
9
|
-
export type { IsEqual, IsNever, PartialDeep, Promisable } from 'type-fest';
|
|
10
|
-
//# 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
|
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/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, 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
|