@orpc/shared 0.15.0 → 0.17.0
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/dist/{chunk-4KZEIATV.js → chunk-CCTAECMC.js} +5 -9
- package/dist/error.js +1 -1
- package/dist/index.js +36 -1
- package/dist/src/constants.d.ts +3 -0
- package/dist/src/error.d.ts +5 -3
- package/dist/src/hook.d.ts +1 -1
- package/dist/src/index.d.ts +2 -0
- package/dist/src/proxy.d.ts +3 -0
- package/package.json +3 -3
|
@@ -1,5 +1,4 @@
|
|
|
1
1
|
// src/error.ts
|
|
2
|
-
import { ZodError } from "zod";
|
|
3
2
|
var ORPC_ERROR_CODE_STATUSES = {
|
|
4
3
|
BAD_REQUEST: 400,
|
|
5
4
|
UNAUTHORIZED: 401,
|
|
@@ -39,10 +38,7 @@ var ORPCError = class _ORPCError extends Error {
|
|
|
39
38
|
return this.zz$oe.data;
|
|
40
39
|
}
|
|
41
40
|
get issues() {
|
|
42
|
-
|
|
43
|
-
return this.zz$oe.cause.issues;
|
|
44
|
-
}
|
|
45
|
-
return void 0;
|
|
41
|
+
return this.zz$oe.issues;
|
|
46
42
|
}
|
|
47
43
|
toJSON() {
|
|
48
44
|
return {
|
|
@@ -60,9 +56,9 @@ var ORPCError = class _ORPCError extends Error {
|
|
|
60
56
|
return new _ORPCError({
|
|
61
57
|
code: json.code,
|
|
62
58
|
status: json.status,
|
|
63
|
-
message:
|
|
64
|
-
data:
|
|
65
|
-
|
|
59
|
+
message: json.message,
|
|
60
|
+
data: json.data,
|
|
61
|
+
issues: json.issues
|
|
66
62
|
});
|
|
67
63
|
}
|
|
68
64
|
};
|
|
@@ -89,4 +85,4 @@ export {
|
|
|
89
85
|
ORPCError,
|
|
90
86
|
convertToStandardError
|
|
91
87
|
};
|
|
92
|
-
//# sourceMappingURL=chunk-
|
|
88
|
+
//# sourceMappingURL=chunk-CCTAECMC.js.map
|
package/dist/error.js
CHANGED
package/dist/index.js
CHANGED
|
@@ -1,6 +1,10 @@
|
|
|
1
1
|
import {
|
|
2
2
|
convertToStandardError
|
|
3
|
-
} from "./chunk-
|
|
3
|
+
} from "./chunk-CCTAECMC.js";
|
|
4
|
+
|
|
5
|
+
// src/constants.ts
|
|
6
|
+
var ORPC_PROTOCOL_HEADER = "x-orpc-protocol";
|
|
7
|
+
var ORPC_PROTOCOL_VALUE = "orpc";
|
|
4
8
|
|
|
5
9
|
// src/hook.ts
|
|
6
10
|
async function executeWithHooks(options) {
|
|
@@ -116,6 +120,34 @@ function findDeepMatches(check, payload, segments = [], maps = [], values = [])
|
|
|
116
120
|
return { maps, values };
|
|
117
121
|
}
|
|
118
122
|
|
|
123
|
+
// src/proxy.ts
|
|
124
|
+
function createCallableObject(obj, func) {
|
|
125
|
+
const proxy = new Proxy(func, {
|
|
126
|
+
has(target, key) {
|
|
127
|
+
return Reflect.has(obj, key) || Reflect.has(target, key);
|
|
128
|
+
},
|
|
129
|
+
ownKeys(target) {
|
|
130
|
+
return Array.from(new Set(Reflect.ownKeys(obj).concat(...Reflect.ownKeys(target))));
|
|
131
|
+
},
|
|
132
|
+
get(target, key) {
|
|
133
|
+
if (!Reflect.has(target, key) || Reflect.has(obj, key)) {
|
|
134
|
+
return Reflect.get(obj, key);
|
|
135
|
+
}
|
|
136
|
+
return Reflect.get(target, key);
|
|
137
|
+
},
|
|
138
|
+
defineProperty(_, key, descriptor) {
|
|
139
|
+
return Reflect.defineProperty(obj, key, descriptor);
|
|
140
|
+
},
|
|
141
|
+
set(_, key, value2) {
|
|
142
|
+
return Reflect.set(obj, key, value2);
|
|
143
|
+
},
|
|
144
|
+
deleteProperty(target, key) {
|
|
145
|
+
return Reflect.deleteProperty(target, key) && Reflect.deleteProperty(obj, key);
|
|
146
|
+
}
|
|
147
|
+
});
|
|
148
|
+
return proxy;
|
|
149
|
+
}
|
|
150
|
+
|
|
119
151
|
// src/value.ts
|
|
120
152
|
function value(value2) {
|
|
121
153
|
if (typeof value2 === "function") {
|
|
@@ -128,7 +160,10 @@ function value(value2) {
|
|
|
128
160
|
import { isPlainObject as isPlainObject2 } from "is-what";
|
|
129
161
|
import { guard, mapEntries, mapValues, omit, trim } from "radash";
|
|
130
162
|
export {
|
|
163
|
+
ORPC_PROTOCOL_HEADER,
|
|
164
|
+
ORPC_PROTOCOL_VALUE,
|
|
131
165
|
convertToArray,
|
|
166
|
+
createCallableObject,
|
|
132
167
|
executeWithHooks,
|
|
133
168
|
findDeepMatches,
|
|
134
169
|
get,
|
package/dist/src/error.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import type { StandardSchemaV1 } from '@standard-schema/spec';
|
|
2
2
|
export declare const ORPC_ERROR_CODE_STATUSES: {
|
|
3
3
|
readonly BAD_REQUEST: 400;
|
|
4
4
|
readonly UNAUTHORIZED: 401;
|
|
@@ -26,7 +26,7 @@ export interface ORPCErrorJSON<TCode extends ORPCErrorCode, TData> {
|
|
|
26
26
|
status: number;
|
|
27
27
|
message: string;
|
|
28
28
|
data: TData;
|
|
29
|
-
issues?:
|
|
29
|
+
issues?: readonly StandardSchemaV1.Issue[];
|
|
30
30
|
}
|
|
31
31
|
export type ANY_ORPC_ERROR_JSON = ORPCErrorJSON<any, any>;
|
|
32
32
|
export type WELL_ORPC_ERROR_JSON = ORPCErrorJSON<ORPCErrorCode, unknown>;
|
|
@@ -36,6 +36,7 @@ export declare class ORPCError<TCode extends ORPCErrorCode, TData> extends Error
|
|
|
36
36
|
status?: number;
|
|
37
37
|
message?: string;
|
|
38
38
|
cause?: unknown;
|
|
39
|
+
issues?: readonly StandardSchemaV1.Issue[];
|
|
39
40
|
} & (undefined extends TData ? {
|
|
40
41
|
data?: TData;
|
|
41
42
|
} : {
|
|
@@ -46,6 +47,7 @@ export declare class ORPCError<TCode extends ORPCErrorCode, TData> extends Error
|
|
|
46
47
|
status?: number;
|
|
47
48
|
message?: string;
|
|
48
49
|
cause?: unknown;
|
|
50
|
+
issues?: readonly StandardSchemaV1.Issue[];
|
|
49
51
|
} & (undefined extends TData ? {
|
|
50
52
|
data?: TData;
|
|
51
53
|
} : {
|
|
@@ -54,7 +56,7 @@ export declare class ORPCError<TCode extends ORPCErrorCode, TData> extends Error
|
|
|
54
56
|
get code(): TCode;
|
|
55
57
|
get status(): number;
|
|
56
58
|
get data(): TData;
|
|
57
|
-
get issues():
|
|
59
|
+
get issues(): readonly StandardSchemaV1.Issue[] | undefined;
|
|
58
60
|
toJSON(): ORPCErrorJSON<TCode, TData>;
|
|
59
61
|
static fromJSON(json: unknown): ORPCError<ORPCErrorCode, any> | undefined;
|
|
60
62
|
}
|
package/dist/src/hook.d.ts
CHANGED
|
@@ -29,7 +29,7 @@ export interface Hooks<TInput, TOutput, TContext, TMeta extends (Record<string,
|
|
|
29
29
|
onError?: Arrayable<(state: OnErrorState<TInput>, context: TContext, meta: TMeta) => Promisable<void>>;
|
|
30
30
|
onFinish?: Arrayable<(state: OnSuccessState<TInput, TOutput> | OnErrorState<TInput>, context: TContext, meta: TMeta) => Promisable<void>>;
|
|
31
31
|
}
|
|
32
|
-
export declare function executeWithHooks<TInput, TOutput, TContext, TMeta extends (Record<string,
|
|
32
|
+
export declare function executeWithHooks<TInput, TOutput, TContext, TMeta extends (Record<string, any> & {
|
|
33
33
|
next?: never;
|
|
34
34
|
}) | undefined>(options: {
|
|
35
35
|
hooks?: Hooks<TInput, TOutput, TContext, TMeta>;
|
package/dist/src/index.d.ts
CHANGED
|
@@ -1,7 +1,9 @@
|
|
|
1
|
+
export * from './constants';
|
|
1
2
|
export * from './function';
|
|
2
3
|
export * from './hook';
|
|
3
4
|
export * from './json';
|
|
4
5
|
export * from './object';
|
|
6
|
+
export * from './proxy';
|
|
5
7
|
export * from './value';
|
|
6
8
|
export { isPlainObject } from 'is-what';
|
|
7
9
|
export { guard, mapEntries, mapValues, omit, trim } from 'radash';
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@orpc/shared",
|
|
3
3
|
"type": "module",
|
|
4
|
-
"version": "0.
|
|
4
|
+
"version": "0.17.0",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"homepage": "https://orpc.unnoq.com",
|
|
7
7
|
"repository": {
|
|
@@ -34,10 +34,10 @@
|
|
|
34
34
|
"dist"
|
|
35
35
|
],
|
|
36
36
|
"dependencies": {
|
|
37
|
+
"@standard-schema/spec": "1.0.0-beta.4",
|
|
37
38
|
"is-what": "^5.0.2",
|
|
38
39
|
"radash": "^12.1.0",
|
|
39
|
-
"type-fest": "^4.26.1"
|
|
40
|
-
"zod": "^3.24.1"
|
|
40
|
+
"type-fest": "^4.26.1"
|
|
41
41
|
},
|
|
42
42
|
"scripts": {
|
|
43
43
|
"build": "tsup --clean --sourcemap --entry.index=src/index.ts --entry.error=src/error.ts --format=esm --onSuccess='tsc -b --noCheck'",
|