@orpc/shared 0.36.1 → 0.37.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/index.js CHANGED
@@ -2,8 +2,58 @@
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 === null;
54
+ }
55
+
5
56
  // src/error.ts
6
- import { isPlainObject } from "is-what";
7
57
  function toError(error) {
8
58
  if (error instanceof Error) {
9
59
  return error;
@@ -11,7 +61,7 @@ function toError(error) {
11
61
  if (typeof error === "string") {
12
62
  return new Error(error, { cause: error });
13
63
  }
14
- if (isPlainObject(error)) {
64
+ if (isObject(error)) {
15
65
  if ("message" in error && typeof error.message === "string") {
16
66
  return new Error(error.message, { cause: error });
17
67
  }
@@ -100,51 +150,6 @@ function parseJSONSafely(text) {
100
150
  }
101
151
  }
102
152
 
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
-
148
153
  // src/proxy.ts
149
154
  function createCallableObject(obj, handler) {
150
155
  const proxy = new Proxy(handler, {
@@ -182,7 +187,6 @@ function value(value2, ...args) {
182
187
  }
183
188
 
184
189
  // src/index.ts
185
- import { isPlainObject as isPlainObject3 } from "is-what";
186
190
  import { group, guard, mapEntries, mapValues, omit, trim } from "radash";
187
191
  export {
188
192
  ORPC_HANDLER_HEADER,
@@ -193,7 +197,7 @@ export {
193
197
  group,
194
198
  guard,
195
199
  intercept,
196
- isPlainObject3 as isPlainObject,
200
+ isObject,
197
201
  mapEntries,
198
202
  mapValues,
199
203
  omit,
@@ -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';
9
10
  export * from './value';
10
- export { isPlainObject } from 'is-what';
11
11
  export { group, guard, mapEntries, mapValues, omit, trim } from 'radash';
12
- export type * from 'type-fest';
12
+ export type { IsEqual, IsNever, JsonValue, PartialDeep, Promisable } from 'type-fest';
13
13
  //# sourceMappingURL=index.d.ts.map
@@ -5,4 +5,9 @@ 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.
10
+ * Even object created by Object.create(null) is considered an object.
11
+ */
12
+ export declare function isObject(value: unknown): value is Record<PropertyKey, unknown>;
8
13
  //# sourceMappingURL=object.d.ts.map
@@ -0,0 +1,3 @@
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
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@orpc/shared",
3
3
  "type": "module",
4
- "version": "0.36.1",
4
+ "version": "0.37.0",
5
5
  "license": "MIT",
6
6
  "homepage": "https://orpc.unnoq.com",
7
7
  "repository": {
@@ -29,7 +29,6 @@
29
29
  "dist"
30
30
  ],
31
31
  "dependencies": {
32
- "is-what": "^5.0.2",
33
32
  "radash": "^12.1.0",
34
33
  "type-fest": "^4.26.1"
35
34
  },