@orpc/shared 0.0.0-next.db1f26d → 0.0.0-next.db61815
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 +335 -0
- package/dist/index.d.ts +335 -0
- package/dist/index.mjs +686 -0
- package/package.json +21 -19
- package/dist/error.js +0 -73
- package/dist/index.js +0 -81
- package/dist/src/error.d.ts +0 -58
- package/dist/src/index.d.ts +0 -7
- package/dist/src/json.d.ts +0 -2
- package/dist/src/object.d.ts +0 -8
- 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.db61815",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"homepage": "https://orpc.unnoq.com",
|
|
7
7
|
"repository": {
|
|
@@ -15,32 +15,34 @@
|
|
|
15
15
|
],
|
|
16
16
|
"exports": {
|
|
17
17
|
".": {
|
|
18
|
-
"types": "./dist/
|
|
19
|
-
"import": "./dist/index.
|
|
20
|
-
"default": "./dist/index.
|
|
21
|
-
},
|
|
22
|
-
"./error": {
|
|
23
|
-
"types": "./dist/src/error.d.ts",
|
|
24
|
-
"import": "./dist/error.js",
|
|
25
|
-
"default": "./dist/error.js"
|
|
26
|
-
},
|
|
27
|
-
"./🔒/*": {
|
|
28
|
-
"types": "./dist/src/*.d.ts"
|
|
18
|
+
"types": "./dist/index.d.mts",
|
|
19
|
+
"import": "./dist/index.mjs",
|
|
20
|
+
"default": "./dist/index.mjs"
|
|
29
21
|
}
|
|
30
22
|
},
|
|
31
23
|
"files": [
|
|
32
|
-
"!**/*.map",
|
|
33
|
-
"!**/*.tsbuildinfo",
|
|
34
24
|
"dist"
|
|
35
25
|
],
|
|
26
|
+
"peerDependencies": {
|
|
27
|
+
"@opentelemetry/api": ">=1.9.0"
|
|
28
|
+
},
|
|
29
|
+
"peerDependenciesMeta": {
|
|
30
|
+
"@opentelemetry/api": {
|
|
31
|
+
"optional": true
|
|
32
|
+
}
|
|
33
|
+
},
|
|
36
34
|
"dependencies": {
|
|
37
|
-
"
|
|
38
|
-
"
|
|
39
|
-
|
|
40
|
-
|
|
35
|
+
"radash": "^12.1.1",
|
|
36
|
+
"type-fest": "^5.0.1"
|
|
37
|
+
},
|
|
38
|
+
"devDependencies": {
|
|
39
|
+
"@opentelemetry/api": "^1.9.0",
|
|
40
|
+
"arktype": "2.1.22",
|
|
41
|
+
"valibot": "^1.1.0",
|
|
42
|
+
"zod": "^4.1.11"
|
|
41
43
|
},
|
|
42
44
|
"scripts": {
|
|
43
|
-
"build": "
|
|
45
|
+
"build": "unbuild",
|
|
44
46
|
"build:watch": "pnpm run build --watch",
|
|
45
47
|
"type:check": "tsc -b"
|
|
46
48
|
}
|
package/dist/error.js
DELETED
|
@@ -1,73 +0,0 @@
|
|
|
1
|
-
// src/error.ts
|
|
2
|
-
import { ZodError } from "zod";
|
|
3
|
-
var ORPC_ERROR_CODE_STATUSES = {
|
|
4
|
-
BAD_REQUEST: 400,
|
|
5
|
-
UNAUTHORIZED: 401,
|
|
6
|
-
FORBIDDEN: 403,
|
|
7
|
-
NOT_FOUND: 404,
|
|
8
|
-
METHOD_NOT_SUPPORTED: 405,
|
|
9
|
-
NOT_ACCEPTABLE: 406,
|
|
10
|
-
TIMEOUT: 408,
|
|
11
|
-
CONFLICT: 409,
|
|
12
|
-
PRECONDITION_FAILED: 412,
|
|
13
|
-
PAYLOAD_TOO_LARGE: 413,
|
|
14
|
-
UNSUPPORTED_MEDIA_TYPE: 415,
|
|
15
|
-
UNPROCESSABLE_CONTENT: 422,
|
|
16
|
-
TOO_MANY_REQUESTS: 429,
|
|
17
|
-
CLIENT_CLOSED_REQUEST: 499,
|
|
18
|
-
INTERNAL_SERVER_ERROR: 500,
|
|
19
|
-
NOT_IMPLEMENTED: 501,
|
|
20
|
-
BAD_GATEWAY: 502,
|
|
21
|
-
SERVICE_UNAVAILABLE: 503,
|
|
22
|
-
GATEWAY_TIMEOUT: 504
|
|
23
|
-
};
|
|
24
|
-
var ORPCError = class _ORPCError extends Error {
|
|
25
|
-
constructor(zz$oe) {
|
|
26
|
-
if (zz$oe.status && (zz$oe.status < 400 || zz$oe.status >= 600)) {
|
|
27
|
-
throw new Error("The ORPCError status code must be in the 400-599 range.");
|
|
28
|
-
}
|
|
29
|
-
super(zz$oe.message, { cause: zz$oe.cause });
|
|
30
|
-
this.zz$oe = zz$oe;
|
|
31
|
-
}
|
|
32
|
-
get code() {
|
|
33
|
-
return this.zz$oe.code;
|
|
34
|
-
}
|
|
35
|
-
get status() {
|
|
36
|
-
return this.zz$oe.status ?? ORPC_ERROR_CODE_STATUSES[this.code];
|
|
37
|
-
}
|
|
38
|
-
get data() {
|
|
39
|
-
return this.zz$oe.data;
|
|
40
|
-
}
|
|
41
|
-
get issues() {
|
|
42
|
-
if (this.code === "BAD_REQUEST" && this.zz$oe.cause instanceof ZodError) {
|
|
43
|
-
return this.zz$oe.cause.issues;
|
|
44
|
-
}
|
|
45
|
-
return void 0;
|
|
46
|
-
}
|
|
47
|
-
toJSON() {
|
|
48
|
-
return {
|
|
49
|
-
code: this.code,
|
|
50
|
-
status: this.status,
|
|
51
|
-
message: this.message,
|
|
52
|
-
data: this.data,
|
|
53
|
-
issues: this.issues
|
|
54
|
-
};
|
|
55
|
-
}
|
|
56
|
-
static fromJSON(json) {
|
|
57
|
-
if (typeof json !== "object" || json === null || !("code" in json) || !Object.keys(ORPC_ERROR_CODE_STATUSES).find((key) => json.code === key) || !("status" in json) || typeof json.status !== "number" || "message" in json && json.message !== void 0 && typeof json.message !== "string" || "issues" in json && json.issues !== void 0 && !Array.isArray(json.issues)) {
|
|
58
|
-
return void 0;
|
|
59
|
-
}
|
|
60
|
-
return new _ORPCError({
|
|
61
|
-
code: json.code,
|
|
62
|
-
status: json.status,
|
|
63
|
-
message: Reflect.get(json, "message"),
|
|
64
|
-
data: Reflect.get(json, "data"),
|
|
65
|
-
cause: "issues" in json ? new ZodError(json.issues) : void 0
|
|
66
|
-
});
|
|
67
|
-
}
|
|
68
|
-
};
|
|
69
|
-
export {
|
|
70
|
-
ORPCError,
|
|
71
|
-
ORPC_ERROR_CODE_STATUSES
|
|
72
|
-
};
|
|
73
|
-
//# sourceMappingURL=error.js.map
|
package/dist/index.js
DELETED
|
@@ -1,81 +0,0 @@
|
|
|
1
|
-
// src/json.ts
|
|
2
|
-
function parseJSONSafely(text) {
|
|
3
|
-
if (text === "")
|
|
4
|
-
return void 0;
|
|
5
|
-
try {
|
|
6
|
-
return JSON.parse(text);
|
|
7
|
-
} catch {
|
|
8
|
-
return text;
|
|
9
|
-
}
|
|
10
|
-
}
|
|
11
|
-
|
|
12
|
-
// src/object.ts
|
|
13
|
-
import { isPlainObject } from "is-what";
|
|
14
|
-
function set(root, segments, value2) {
|
|
15
|
-
const ref = { root };
|
|
16
|
-
let currentRef = ref;
|
|
17
|
-
let preSegment = "root";
|
|
18
|
-
for (const segment of segments) {
|
|
19
|
-
currentRef = currentRef[preSegment];
|
|
20
|
-
preSegment = segment;
|
|
21
|
-
}
|
|
22
|
-
currentRef[preSegment] = value2;
|
|
23
|
-
return ref.root;
|
|
24
|
-
}
|
|
25
|
-
function get(root, segments) {
|
|
26
|
-
const ref = { root };
|
|
27
|
-
let currentRef = ref;
|
|
28
|
-
let preSegment = "root";
|
|
29
|
-
for (const segment of segments) {
|
|
30
|
-
if (typeof currentRef !== "object" && typeof currentRef !== "function" || currentRef === null) {
|
|
31
|
-
return void 0;
|
|
32
|
-
}
|
|
33
|
-
currentRef = currentRef[preSegment];
|
|
34
|
-
preSegment = segment;
|
|
35
|
-
}
|
|
36
|
-
if (typeof currentRef !== "object" && typeof currentRef !== "function" || currentRef === null) {
|
|
37
|
-
return void 0;
|
|
38
|
-
}
|
|
39
|
-
return currentRef[preSegment];
|
|
40
|
-
}
|
|
41
|
-
function findDeepMatches(check, payload, segments = [], maps = [], values = []) {
|
|
42
|
-
if (check(payload)) {
|
|
43
|
-
maps.push(segments);
|
|
44
|
-
values.push(payload);
|
|
45
|
-
} else if (Array.isArray(payload)) {
|
|
46
|
-
payload.forEach((v, i) => {
|
|
47
|
-
findDeepMatches(check, v, [...segments, i], maps, values);
|
|
48
|
-
});
|
|
49
|
-
} else if (isPlainObject(payload)) {
|
|
50
|
-
for (const key in payload) {
|
|
51
|
-
findDeepMatches(check, payload[key], [...segments, key], maps, values);
|
|
52
|
-
}
|
|
53
|
-
}
|
|
54
|
-
return { maps, values };
|
|
55
|
-
}
|
|
56
|
-
|
|
57
|
-
// src/value.ts
|
|
58
|
-
function value(value2) {
|
|
59
|
-
if (typeof value2 === "function") {
|
|
60
|
-
return value2();
|
|
61
|
-
}
|
|
62
|
-
return value2;
|
|
63
|
-
}
|
|
64
|
-
|
|
65
|
-
// src/index.ts
|
|
66
|
-
import { isPlainObject as isPlainObject2 } from "is-what";
|
|
67
|
-
import { guard, mapEntries, mapValues, omit, trim } from "radash";
|
|
68
|
-
export {
|
|
69
|
-
findDeepMatches,
|
|
70
|
-
get,
|
|
71
|
-
guard,
|
|
72
|
-
isPlainObject2 as isPlainObject,
|
|
73
|
-
mapEntries,
|
|
74
|
-
mapValues,
|
|
75
|
-
omit,
|
|
76
|
-
parseJSONSafely,
|
|
77
|
-
set,
|
|
78
|
-
trim,
|
|
79
|
-
value
|
|
80
|
-
};
|
|
81
|
-
//# sourceMappingURL=index.js.map
|
package/dist/src/error.d.ts
DELETED
|
@@ -1,58 +0,0 @@
|
|
|
1
|
-
import { type ZodIssue } from 'zod';
|
|
2
|
-
export declare const ORPC_ERROR_CODE_STATUSES: {
|
|
3
|
-
readonly BAD_REQUEST: 400;
|
|
4
|
-
readonly UNAUTHORIZED: 401;
|
|
5
|
-
readonly FORBIDDEN: 403;
|
|
6
|
-
readonly NOT_FOUND: 404;
|
|
7
|
-
readonly METHOD_NOT_SUPPORTED: 405;
|
|
8
|
-
readonly NOT_ACCEPTABLE: 406;
|
|
9
|
-
readonly TIMEOUT: 408;
|
|
10
|
-
readonly CONFLICT: 409;
|
|
11
|
-
readonly PRECONDITION_FAILED: 412;
|
|
12
|
-
readonly PAYLOAD_TOO_LARGE: 413;
|
|
13
|
-
readonly UNSUPPORTED_MEDIA_TYPE: 415;
|
|
14
|
-
readonly UNPROCESSABLE_CONTENT: 422;
|
|
15
|
-
readonly TOO_MANY_REQUESTS: 429;
|
|
16
|
-
readonly CLIENT_CLOSED_REQUEST: 499;
|
|
17
|
-
readonly INTERNAL_SERVER_ERROR: 500;
|
|
18
|
-
readonly NOT_IMPLEMENTED: 501;
|
|
19
|
-
readonly BAD_GATEWAY: 502;
|
|
20
|
-
readonly SERVICE_UNAVAILABLE: 503;
|
|
21
|
-
readonly GATEWAY_TIMEOUT: 504;
|
|
22
|
-
};
|
|
23
|
-
export type ORPCErrorCode = keyof typeof ORPC_ERROR_CODE_STATUSES;
|
|
24
|
-
export declare class ORPCError<TCode extends ORPCErrorCode, TData> extends Error {
|
|
25
|
-
zz$oe: {
|
|
26
|
-
code: TCode;
|
|
27
|
-
status?: number;
|
|
28
|
-
message?: string;
|
|
29
|
-
cause?: unknown;
|
|
30
|
-
} & (undefined extends TData ? {
|
|
31
|
-
data?: TData;
|
|
32
|
-
} : {
|
|
33
|
-
data: TData;
|
|
34
|
-
});
|
|
35
|
-
constructor(zz$oe: {
|
|
36
|
-
code: TCode;
|
|
37
|
-
status?: number;
|
|
38
|
-
message?: string;
|
|
39
|
-
cause?: unknown;
|
|
40
|
-
} & (undefined extends TData ? {
|
|
41
|
-
data?: TData;
|
|
42
|
-
} : {
|
|
43
|
-
data: TData;
|
|
44
|
-
}));
|
|
45
|
-
get code(): TCode;
|
|
46
|
-
get status(): number;
|
|
47
|
-
get data(): TData;
|
|
48
|
-
get issues(): ZodIssue[] | undefined;
|
|
49
|
-
toJSON(): {
|
|
50
|
-
code: TCode;
|
|
51
|
-
status: number;
|
|
52
|
-
message: string;
|
|
53
|
-
data: TData;
|
|
54
|
-
issues?: ZodIssue[];
|
|
55
|
-
};
|
|
56
|
-
static fromJSON(json: unknown): ORPCError<ORPCErrorCode, any> | undefined;
|
|
57
|
-
}
|
|
58
|
-
//# sourceMappingURL=error.d.ts.map
|
package/dist/src/index.d.ts
DELETED
package/dist/src/json.d.ts
DELETED
package/dist/src/object.d.ts
DELETED
|
@@ -1,8 +0,0 @@
|
|
|
1
|
-
export type Segment = string | number;
|
|
2
|
-
export declare function set(root: Readonly<Record<string, unknown> | 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
|
-
//# sourceMappingURL=object.d.ts.map
|
package/dist/src/value.d.ts
DELETED