@orpc/shared 0.0.0-next.b4e6d3a → 0.0.0-next.b825e0c
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/index.js +54 -58
- package/dist/src/index.d.ts +2 -2
- package/dist/src/object.d.ts +0 -4
- package/package.json +3 -1
- package/dist/src/types.d.ts +0 -3
package/dist/index.js
CHANGED
|
@@ -2,58 +2,8 @@
|
|
|
2
2
|
var ORPC_HANDLER_HEADER = "x-orpc-handler";
|
|
3
3
|
var ORPC_HANDLER_VALUE = "orpc";
|
|
4
4
|
|
|
5
|
-
// src/object.ts
|
|
6
|
-
function set(root, segments, value2) {
|
|
7
|
-
const ref = { root };
|
|
8
|
-
let currentRef = ref;
|
|
9
|
-
let preSegment = "root";
|
|
10
|
-
for (const segment of segments) {
|
|
11
|
-
currentRef = currentRef[preSegment];
|
|
12
|
-
preSegment = segment;
|
|
13
|
-
}
|
|
14
|
-
currentRef[preSegment] = value2;
|
|
15
|
-
return ref.root;
|
|
16
|
-
}
|
|
17
|
-
function get(root, segments) {
|
|
18
|
-
const ref = { root };
|
|
19
|
-
let currentRef = ref;
|
|
20
|
-
let preSegment = "root";
|
|
21
|
-
for (const segment of segments) {
|
|
22
|
-
if (typeof currentRef !== "object" && typeof currentRef !== "function" || currentRef === null) {
|
|
23
|
-
return void 0;
|
|
24
|
-
}
|
|
25
|
-
currentRef = currentRef[preSegment];
|
|
26
|
-
preSegment = segment;
|
|
27
|
-
}
|
|
28
|
-
if (typeof currentRef !== "object" && typeof currentRef !== "function" || currentRef === null) {
|
|
29
|
-
return void 0;
|
|
30
|
-
}
|
|
31
|
-
return currentRef[preSegment];
|
|
32
|
-
}
|
|
33
|
-
function findDeepMatches(check, payload, segments = [], maps = [], values = []) {
|
|
34
|
-
if (check(payload)) {
|
|
35
|
-
maps.push(segments);
|
|
36
|
-
values.push(payload);
|
|
37
|
-
} else if (Array.isArray(payload)) {
|
|
38
|
-
payload.forEach((v, i) => {
|
|
39
|
-
findDeepMatches(check, v, [...segments, i], maps, values);
|
|
40
|
-
});
|
|
41
|
-
} else if (isObject(payload)) {
|
|
42
|
-
for (const key in payload) {
|
|
43
|
-
findDeepMatches(check, payload[key], [...segments, key], maps, values);
|
|
44
|
-
}
|
|
45
|
-
}
|
|
46
|
-
return { maps, values };
|
|
47
|
-
}
|
|
48
|
-
function isObject(value2) {
|
|
49
|
-
if (!value2 || typeof value2 !== "object") {
|
|
50
|
-
return false;
|
|
51
|
-
}
|
|
52
|
-
const proto = Object.getPrototypeOf(value2);
|
|
53
|
-
return proto === Object.prototype || !proto || !proto.constructor;
|
|
54
|
-
}
|
|
55
|
-
|
|
56
5
|
// src/error.ts
|
|
6
|
+
import { isPlainObject } from "is-what";
|
|
57
7
|
function toError(error) {
|
|
58
8
|
if (error instanceof Error) {
|
|
59
9
|
return error;
|
|
@@ -61,7 +11,7 @@ function toError(error) {
|
|
|
61
11
|
if (typeof error === "string") {
|
|
62
12
|
return new Error(error, { cause: error });
|
|
63
13
|
}
|
|
64
|
-
if (
|
|
14
|
+
if (isPlainObject(error)) {
|
|
65
15
|
if ("message" in error && typeof error.message === "string") {
|
|
66
16
|
return new Error(error.message, { cause: error });
|
|
67
17
|
}
|
|
@@ -126,17 +76,17 @@ function onFinish(callback) {
|
|
|
126
76
|
}
|
|
127
77
|
async function intercept(interceptors, options, main) {
|
|
128
78
|
let index = 0;
|
|
129
|
-
const next = async (
|
|
79
|
+
const next = async (nextOptions = options) => {
|
|
130
80
|
const interceptor = interceptors[index++];
|
|
131
81
|
if (!interceptor) {
|
|
132
|
-
return await main(
|
|
82
|
+
return await main(nextOptions);
|
|
133
83
|
}
|
|
134
84
|
return await interceptor({
|
|
135
|
-
...
|
|
136
|
-
next
|
|
85
|
+
...nextOptions,
|
|
86
|
+
next
|
|
137
87
|
});
|
|
138
88
|
};
|
|
139
|
-
return await next(
|
|
89
|
+
return await next();
|
|
140
90
|
}
|
|
141
91
|
|
|
142
92
|
// src/json.ts
|
|
@@ -150,6 +100,51 @@ function parseJSONSafely(text) {
|
|
|
150
100
|
}
|
|
151
101
|
}
|
|
152
102
|
|
|
103
|
+
// src/object.ts
|
|
104
|
+
import { isPlainObject as isPlainObject2 } from "is-what";
|
|
105
|
+
function set(root, segments, value2) {
|
|
106
|
+
const ref = { root };
|
|
107
|
+
let currentRef = ref;
|
|
108
|
+
let preSegment = "root";
|
|
109
|
+
for (const segment of segments) {
|
|
110
|
+
currentRef = currentRef[preSegment];
|
|
111
|
+
preSegment = segment;
|
|
112
|
+
}
|
|
113
|
+
currentRef[preSegment] = value2;
|
|
114
|
+
return ref.root;
|
|
115
|
+
}
|
|
116
|
+
function get(root, segments) {
|
|
117
|
+
const ref = { root };
|
|
118
|
+
let currentRef = ref;
|
|
119
|
+
let preSegment = "root";
|
|
120
|
+
for (const segment of segments) {
|
|
121
|
+
if (typeof currentRef !== "object" && typeof currentRef !== "function" || currentRef === null) {
|
|
122
|
+
return void 0;
|
|
123
|
+
}
|
|
124
|
+
currentRef = currentRef[preSegment];
|
|
125
|
+
preSegment = segment;
|
|
126
|
+
}
|
|
127
|
+
if (typeof currentRef !== "object" && typeof currentRef !== "function" || currentRef === null) {
|
|
128
|
+
return void 0;
|
|
129
|
+
}
|
|
130
|
+
return currentRef[preSegment];
|
|
131
|
+
}
|
|
132
|
+
function findDeepMatches(check, payload, segments = [], maps = [], values = []) {
|
|
133
|
+
if (check(payload)) {
|
|
134
|
+
maps.push(segments);
|
|
135
|
+
values.push(payload);
|
|
136
|
+
} else if (Array.isArray(payload)) {
|
|
137
|
+
payload.forEach((v, i) => {
|
|
138
|
+
findDeepMatches(check, v, [...segments, i], maps, values);
|
|
139
|
+
});
|
|
140
|
+
} else if (isPlainObject2(payload)) {
|
|
141
|
+
for (const key in payload) {
|
|
142
|
+
findDeepMatches(check, payload[key], [...segments, key], maps, values);
|
|
143
|
+
}
|
|
144
|
+
}
|
|
145
|
+
return { maps, values };
|
|
146
|
+
}
|
|
147
|
+
|
|
153
148
|
// src/proxy.ts
|
|
154
149
|
function createCallableObject(obj, handler) {
|
|
155
150
|
const proxy = new Proxy(handler, {
|
|
@@ -187,6 +182,7 @@ function value(value2, ...args) {
|
|
|
187
182
|
}
|
|
188
183
|
|
|
189
184
|
// src/index.ts
|
|
185
|
+
import { isPlainObject as isPlainObject3 } from "is-what";
|
|
190
186
|
import { group, guard, mapEntries, mapValues, omit, trim } from "radash";
|
|
191
187
|
export {
|
|
192
188
|
ORPC_HANDLER_HEADER,
|
|
@@ -197,7 +193,7 @@ export {
|
|
|
197
193
|
group,
|
|
198
194
|
guard,
|
|
199
195
|
intercept,
|
|
200
|
-
|
|
196
|
+
isPlainObject3 as isPlainObject,
|
|
201
197
|
mapEntries,
|
|
202
198
|
mapValues,
|
|
203
199
|
omit,
|
package/dist/src/index.d.ts
CHANGED
|
@@ -6,8 +6,8 @@ export * from './interceptor';
|
|
|
6
6
|
export * from './json';
|
|
7
7
|
export * from './object';
|
|
8
8
|
export * from './proxy';
|
|
9
|
-
export * from './types';
|
|
10
9
|
export * from './value';
|
|
10
|
+
export { isPlainObject } from 'is-what';
|
|
11
11
|
export { group, guard, mapEntries, mapValues, omit, trim } from 'radash';
|
|
12
|
-
export type
|
|
12
|
+
export type * from 'type-fest';
|
|
13
13
|
//# sourceMappingURL=index.d.ts.map
|
package/dist/src/object.d.ts
CHANGED
|
@@ -5,8 +5,4 @@ export declare function findDeepMatches(check: (value: unknown) => boolean, payl
|
|
|
5
5
|
maps: Segment[][];
|
|
6
6
|
values: unknown[];
|
|
7
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
8
|
//# sourceMappingURL=object.d.ts.map
|
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.b825e0c",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"homepage": "https://orpc.unnoq.com",
|
|
7
7
|
"repository": {
|
|
@@ -29,6 +29,8 @@
|
|
|
29
29
|
"dist"
|
|
30
30
|
],
|
|
31
31
|
"dependencies": {
|
|
32
|
+
"@standard-schema/spec": "1.0.0-beta.4",
|
|
33
|
+
"is-what": "^5.0.2",
|
|
32
34
|
"radash": "^12.1.0",
|
|
33
35
|
"type-fest": "^4.26.1"
|
|
34
36
|
},
|
package/dist/src/types.d.ts
DELETED