@ray-js/robot-data-stream 0.0.14 → 0.0.15-beta.1
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/lib/mqtt/createCommonOptions.d.ts +4 -2
- package/lib/mqtt/createCommonOptions.js +10 -5
- package/lib/mqtt/hooks/useStructuredMessage.d.ts +14 -0
- package/lib/mqtt/hooks/useStructuredMessage.js +131 -0
- package/lib/mqtt/mqttProvider.d.ts +19 -1
- package/lib/mqtt/mqttProvider.js +69 -8
- package/lib/mqtt/promise.d.ts +57 -4
- package/lib/mqtt/promise.js +115 -36
- package/lib/mqtt/type/fun.d.ts +49 -0
- package/lib/mqtt/type/fun.js +145 -0
- package/lib/mqtt/type/index.d.ts +0 -7
- package/lib/mqtt/type/index.js +0 -1
- package/lib/mqtt/type/protocols/base.d.ts +5 -0
- package/lib/mqtt/type/protocols/base.js +32 -0
- package/lib/mqtt/type/protocols/carpetCleanProtocol.d.ts +8 -0
- package/lib/mqtt/type/protocols/carpetCleanProtocol.js +16 -0
- package/lib/mqtt/type/protocols/carpetProtocol.d.ts +41 -0
- package/lib/mqtt/type/protocols/carpetProtocol.js +202 -0
- package/lib/mqtt/type/protocols/devInfoProtocol.d.ts +5 -0
- package/lib/mqtt/type/protocols/devInfoProtocol.js +12 -0
- package/lib/mqtt/type/protocols/deviceModelProtocol.d.ts +8 -0
- package/lib/mqtt/type/protocols/deviceModelProtocol.js +34 -0
- package/lib/mqtt/type/protocols/furnitureModelProtocol.d.ts +10 -0
- package/lib/mqtt/type/protocols/furnitureModelProtocol.js +35 -0
- package/lib/mqtt/type/protocols/historyMapProtocol.d.ts +17 -0
- package/lib/mqtt/type/protocols/historyMapProtocol.js +37 -0
- package/lib/mqtt/type/protocols/index.d.ts +20 -0
- package/lib/mqtt/type/protocols/index.js +20 -0
- package/lib/mqtt/type/protocols/partDivisionProtocol.d.ts +8 -0
- package/lib/mqtt/type/protocols/partDivisionProtocol.js +12 -0
- package/lib/mqtt/type/protocols/partMergeProtocol.d.ts +7 -0
- package/lib/mqtt/type/protocols/partMergeProtocol.js +12 -0
- package/lib/mqtt/type/protocols/passwordProtocol.d.ts +11 -0
- package/lib/mqtt/type/protocols/passwordProtocol.js +25 -0
- package/lib/mqtt/type/protocols/quietHoursProtocol.d.ts +8 -0
- package/lib/mqtt/type/protocols/quietHoursProtocol.js +35 -0
- package/lib/mqtt/type/protocols/resetMapProtocol.d.ts +4 -0
- package/lib/mqtt/type/protocols/resetMapProtocol.js +1 -0
- package/lib/mqtt/type/protocols/roomPropertyProtocol.d.ts +14 -0
- package/lib/mqtt/type/protocols/roomPropertyProtocol.js +113 -0
- package/lib/mqtt/type/protocols/scheduleProtocol.d.ts +18 -0
- package/lib/mqtt/type/protocols/scheduleProtocol.js +100 -0
- package/lib/mqtt/type/protocols/selectRoomCleanProtocol.d.ts +8 -0
- package/lib/mqtt/type/protocols/selectRoomCleanProtocol.js +40 -0
- package/lib/mqtt/type/protocols/spotCleanProtocol.d.ts +9 -0
- package/lib/mqtt/type/protocols/spotCleanProtocol.js +72 -0
- package/lib/mqtt/type/protocols/virtualAreaProtocol.d.ts +8 -0
- package/lib/mqtt/type/protocols/virtualAreaProtocol.js +36 -0
- package/lib/mqtt/type/protocols/virtualWallProtocol.d.ts +8 -0
- package/lib/mqtt/type/protocols/virtualWallProtocol.js +25 -0
- package/lib/mqtt/type/protocols/voiceProtocol.d.ts +8 -0
- package/lib/mqtt/type/protocols/voiceProtocol.js +23 -0
- package/lib/mqtt/type/protocols/wifiMapProtocol.d.ts +8 -0
- package/lib/mqtt/type/protocols/wifiMapProtocol.js +14 -0
- package/lib/mqtt/type/protocols/zoneCleanProtocol.d.ts +8 -0
- package/lib/mqtt/type/protocols/zoneCleanProtocol.js +49 -0
- package/lib/mqtt/useCarpet.d.ts +7 -67
- package/lib/mqtt/useCarpet.js +101 -181
- package/lib/mqtt/useCarpetClean.d.ts +2 -11
- package/lib/mqtt/useCarpetClean.js +24 -51
- package/lib/mqtt/useDevInfo.d.ts +8 -6
- package/lib/mqtt/useDevInfo.js +44 -36
- package/lib/mqtt/useDeviceModel.d.ts +6 -19
- package/lib/mqtt/useDeviceModel.js +29 -42
- package/lib/mqtt/useFurnitureModel.d.ts +6 -18
- package/lib/mqtt/useFurnitureModel.js +29 -43
- package/lib/mqtt/useHistoryMap.d.ts +2 -18
- package/lib/mqtt/useHistoryMap.js +102 -119
- package/lib/mqtt/usePartDivision.d.ts +2 -9
- package/lib/mqtt/usePartDivision.js +48 -57
- package/lib/mqtt/usePartMerge.d.ts +2 -8
- package/lib/mqtt/usePartMerge.js +34 -49
- package/lib/mqtt/usePassword.d.ts +6 -13
- package/lib/mqtt/usePassword.js +84 -74
- package/lib/mqtt/useQuiteHours.d.ts +4 -37
- package/lib/mqtt/useQuiteHours.js +66 -100
- package/lib/mqtt/useResetMap.d.ts +2 -8
- package/lib/mqtt/useResetMap.js +27 -34
- package/lib/mqtt/useRoomProperty.d.ts +8 -9
- package/lib/mqtt/useRoomProperty.js +67 -65
- package/lib/mqtt/useSchedule.d.ts +3 -23
- package/lib/mqtt/useSchedule.js +72 -101
- package/lib/mqtt/useSelectRoomClean.d.ts +3 -24
- package/lib/mqtt/useSelectRoomClean.js +107 -133
- package/lib/mqtt/useSpotClean.d.ts +5 -15
- package/lib/mqtt/useSpotClean.js +68 -121
- package/lib/mqtt/useVirtualArea.d.ts +6 -17
- package/lib/mqtt/useVirtualArea.js +109 -119
- package/lib/mqtt/useVirtualWall.d.ts +2 -18
- package/lib/mqtt/useVirtualWall.js +69 -90
- package/lib/mqtt/useVoice.d.ts +2 -16
- package/lib/mqtt/useVoice.js +48 -68
- package/lib/mqtt/useWifiMap.d.ts +6 -5
- package/lib/mqtt/useWifiMap.js +43 -42
- package/lib/mqtt/useZoneClean.d.ts +2 -21
- package/lib/mqtt/useZoneClean.js +125 -137
- package/lib/myLib/zod/mini/index.d.cts +1 -0
- package/lib/myLib/zod/mini/index.d.ts +1 -0
- package/lib/myLib/zod/mini/index.js +1 -0
- package/lib/myLib/zod/mini/package.json +6 -0
- package/lib/myLib/zod/src/mini/index.d.ts +1 -0
- package/lib/myLib/zod/src/mini/index.js +1 -0
- package/lib/myLib/zod/src/v4/core/api.d.ts +306 -0
- package/lib/myLib/zod/src/v4/core/api.js +1256 -0
- package/lib/myLib/zod/src/v4/core/checks.d.ts +278 -0
- package/lib/myLib/zod/src/v4/core/checks.js +816 -0
- package/lib/myLib/zod/src/v4/core/config.d.ts +9 -0
- package/lib/myLib/zod/src/v4/core/config.js +5 -0
- package/lib/myLib/zod/src/v4/core/core.d.ts +70 -0
- package/lib/myLib/zod/src/v4/core/core.js +95 -0
- package/lib/myLib/zod/src/v4/core/doc.d.ts +14 -0
- package/lib/myLib/zod/src/v4/core/doc.js +42 -0
- package/lib/myLib/zod/src/v4/core/errors.d.ts +220 -0
- package/lib/myLib/zod/src/v4/core/errors.js +232 -0
- package/lib/myLib/zod/src/v4/core/index.d.ts +15 -0
- package/lib/myLib/zod/src/v4/core/index.js +15 -0
- package/lib/myLib/zod/src/v4/core/json-schema-generator.d.ts +65 -0
- package/lib/myLib/zod/src/v4/core/json-schema-generator.js +120 -0
- package/lib/myLib/zod/src/v4/core/json-schema-processors.d.ts +49 -0
- package/lib/myLib/zod/src/v4/core/json-schema-processors.js +593 -0
- package/lib/myLib/zod/src/v4/core/json-schema.d.ts +88 -0
- package/lib/myLib/zod/src/v4/core/json-schema.js +1 -0
- package/lib/myLib/zod/src/v4/core/parse.d.ts +49 -0
- package/lib/myLib/zod/src/v4/core/parse.js +147 -0
- package/lib/myLib/zod/src/v4/core/regexes.d.ts +78 -0
- package/lib/myLib/zod/src/v4/core/regexes.js +146 -0
- package/lib/myLib/zod/src/v4/core/registries.d.ts +35 -0
- package/lib/myLib/zod/src/v4/core/registries.js +51 -0
- package/lib/myLib/zod/src/v4/core/schemas.d.ts +1136 -0
- package/lib/myLib/zod/src/v4/core/schemas.js +2745 -0
- package/lib/myLib/zod/src/v4/core/standard-schema.d.ts +126 -0
- package/lib/myLib/zod/src/v4/core/standard-schema.js +1 -0
- package/lib/myLib/zod/src/v4/core/to-json-schema.d.ts +114 -0
- package/lib/myLib/zod/src/v4/core/to-json-schema.js +488 -0
- package/lib/myLib/zod/src/v4/core/util.d.ts +199 -0
- package/lib/myLib/zod/src/v4/core/util.js +656 -0
- package/lib/myLib/zod/src/v4/core/versions.d.ts +5 -0
- package/lib/myLib/zod/src/v4/core/versions.js +5 -0
- package/lib/myLib/zod/src/v4/core/zsf.d.ts +91 -0
- package/lib/myLib/zod/src/v4/core/zsf.js +1 -0
- package/lib/myLib/zod/src/v4/mini/checks.d.ts +1 -0
- package/lib/myLib/zod/src/v4/mini/checks.js +1 -0
- package/lib/myLib/zod/src/v4/mini/coerce.d.ts +7 -0
- package/lib/myLib/zod/src/v4/mini/coerce.js +27 -0
- package/lib/myLib/zod/src/v4/mini/external.d.ts +11 -0
- package/lib/myLib/zod/src/v4/mini/external.js +16 -0
- package/lib/myLib/zod/src/v4/mini/index.d.ts +3 -0
- package/lib/myLib/zod/src/v4/mini/index.js +3 -0
- package/lib/myLib/zod/src/v4/mini/iso.d.ts +22 -0
- package/lib/myLib/zod/src/v4/mini/iso.js +46 -0
- package/lib/myLib/zod/src/v4/mini/parse.d.ts +1 -0
- package/lib/myLib/zod/src/v4/mini/parse.js +1 -0
- package/lib/myLib/zod/src/v4/mini/schemas.js +1244 -0
- package/lib/utils/index.d.ts +1 -0
- package/lib/utils/index.js +2 -1
- package/package.json +5 -3
|
@@ -0,0 +1,656 @@
|
|
|
1
|
+
import _objectSpread from "@babel/runtime/helpers/esm/objectSpread2";
|
|
2
|
+
import "core-js/modules/esnext.iterator.constructor.js";
|
|
3
|
+
import "core-js/modules/esnext.iterator.filter.js";
|
|
4
|
+
import "core-js/modules/esnext.iterator.map.js";
|
|
5
|
+
import "core-js/modules/esnext.iterator.reduce.js";
|
|
6
|
+
// json
|
|
7
|
+
|
|
8
|
+
// utils
|
|
9
|
+
|
|
10
|
+
// | bigint | boolean | symbol;
|
|
11
|
+
|
|
12
|
+
// string | Array<unknown> | Set<unknown> | File;
|
|
13
|
+
|
|
14
|
+
// functions
|
|
15
|
+
export function assertEqual(val) {
|
|
16
|
+
return val;
|
|
17
|
+
}
|
|
18
|
+
export function assertNotEqual(val) {
|
|
19
|
+
return val;
|
|
20
|
+
}
|
|
21
|
+
export function assertIs() {}
|
|
22
|
+
export function assertNever() {
|
|
23
|
+
throw new Error("Unexpected value in exhaustive check");
|
|
24
|
+
}
|
|
25
|
+
export function assert() {}
|
|
26
|
+
export function getEnumValues(entries) {
|
|
27
|
+
const numericValues = Object.values(entries).filter(v => typeof v === "number");
|
|
28
|
+
const values = Object.entries(entries).filter(_ref => {
|
|
29
|
+
let [k, _] = _ref;
|
|
30
|
+
return numericValues.indexOf(+k) === -1;
|
|
31
|
+
}).map(_ref2 => {
|
|
32
|
+
let [_, v] = _ref2;
|
|
33
|
+
return v;
|
|
34
|
+
});
|
|
35
|
+
return values;
|
|
36
|
+
}
|
|
37
|
+
export function joinValues(array) {
|
|
38
|
+
let separator = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : "|";
|
|
39
|
+
return array.map(val => stringifyPrimitive(val)).join(separator);
|
|
40
|
+
}
|
|
41
|
+
export function jsonStringifyReplacer(_, value) {
|
|
42
|
+
if (typeof value === "bigint") return value.toString();
|
|
43
|
+
return value;
|
|
44
|
+
}
|
|
45
|
+
export function cached(getter) {
|
|
46
|
+
return {
|
|
47
|
+
get value() {
|
|
48
|
+
{
|
|
49
|
+
const value = getter();
|
|
50
|
+
Object.defineProperty(this, "value", {
|
|
51
|
+
value
|
|
52
|
+
});
|
|
53
|
+
return value;
|
|
54
|
+
}
|
|
55
|
+
throw new Error("cached value already set");
|
|
56
|
+
}
|
|
57
|
+
};
|
|
58
|
+
}
|
|
59
|
+
export function nullish(input) {
|
|
60
|
+
return input === null || input === undefined;
|
|
61
|
+
}
|
|
62
|
+
export function cleanRegex(source) {
|
|
63
|
+
const start = source.startsWith("^") ? 1 : 0;
|
|
64
|
+
const end = source.endsWith("$") ? source.length - 1 : source.length;
|
|
65
|
+
return source.slice(start, end);
|
|
66
|
+
}
|
|
67
|
+
export function floatSafeRemainder(val, step) {
|
|
68
|
+
const valDecCount = (val.toString().split(".")[1] || "").length;
|
|
69
|
+
const stepString = step.toString();
|
|
70
|
+
let stepDecCount = (stepString.split(".")[1] || "").length;
|
|
71
|
+
if (stepDecCount === 0 && /\d?e-\d?/.test(stepString)) {
|
|
72
|
+
const match = stepString.match(/\d?e-(\d?)/);
|
|
73
|
+
if (match !== null && match !== void 0 && match[1]) {
|
|
74
|
+
stepDecCount = Number.parseInt(match[1]);
|
|
75
|
+
}
|
|
76
|
+
}
|
|
77
|
+
const decCount = valDecCount > stepDecCount ? valDecCount : stepDecCount;
|
|
78
|
+
const valInt = Number.parseInt(val.toFixed(decCount).replace(".", ""));
|
|
79
|
+
const stepInt = Number.parseInt(step.toFixed(decCount).replace(".", ""));
|
|
80
|
+
return valInt % stepInt / 10 ** decCount;
|
|
81
|
+
}
|
|
82
|
+
const EVALUATING = Symbol("evaluating");
|
|
83
|
+
export function defineLazy(object, key, getter) {
|
|
84
|
+
let value = undefined;
|
|
85
|
+
Object.defineProperty(object, key, {
|
|
86
|
+
get() {
|
|
87
|
+
if (value === EVALUATING) {
|
|
88
|
+
// Circular reference detected, return undefined to break the cycle
|
|
89
|
+
return undefined;
|
|
90
|
+
}
|
|
91
|
+
if (value === undefined) {
|
|
92
|
+
value = EVALUATING;
|
|
93
|
+
value = getter();
|
|
94
|
+
}
|
|
95
|
+
return value;
|
|
96
|
+
},
|
|
97
|
+
set(v) {
|
|
98
|
+
Object.defineProperty(object, key, {
|
|
99
|
+
value: v
|
|
100
|
+
// configurable: true,
|
|
101
|
+
});
|
|
102
|
+
// object[key] = v;
|
|
103
|
+
},
|
|
104
|
+
configurable: true
|
|
105
|
+
});
|
|
106
|
+
}
|
|
107
|
+
export function objectClone(obj) {
|
|
108
|
+
return Object.create(Object.getPrototypeOf(obj), Object.getOwnPropertyDescriptors(obj));
|
|
109
|
+
}
|
|
110
|
+
export function assignProp(target, prop, value) {
|
|
111
|
+
Object.defineProperty(target, prop, {
|
|
112
|
+
value,
|
|
113
|
+
writable: true,
|
|
114
|
+
enumerable: true,
|
|
115
|
+
configurable: true
|
|
116
|
+
});
|
|
117
|
+
}
|
|
118
|
+
export function mergeDefs() {
|
|
119
|
+
const mergedDescriptors = {};
|
|
120
|
+
for (var _len = arguments.length, defs = new Array(_len), _key = 0; _key < _len; _key++) {
|
|
121
|
+
defs[_key] = arguments[_key];
|
|
122
|
+
}
|
|
123
|
+
for (const def of defs) {
|
|
124
|
+
const descriptors = Object.getOwnPropertyDescriptors(def);
|
|
125
|
+
Object.assign(mergedDescriptors, descriptors);
|
|
126
|
+
}
|
|
127
|
+
return Object.defineProperties({}, mergedDescriptors);
|
|
128
|
+
}
|
|
129
|
+
export function cloneDef(schema) {
|
|
130
|
+
return mergeDefs(schema._zod.def);
|
|
131
|
+
}
|
|
132
|
+
export function getElementAtPath(obj, path) {
|
|
133
|
+
if (!path) return obj;
|
|
134
|
+
return path.reduce((acc, key) => acc === null || acc === void 0 ? void 0 : acc[key], obj);
|
|
135
|
+
}
|
|
136
|
+
export function promiseAllObject(promisesObj) {
|
|
137
|
+
const keys = Object.keys(promisesObj);
|
|
138
|
+
const promises = keys.map(key => promisesObj[key]);
|
|
139
|
+
return Promise.all(promises).then(results => {
|
|
140
|
+
const resolvedObj = {};
|
|
141
|
+
for (let i = 0; i < keys.length; i++) {
|
|
142
|
+
resolvedObj[keys[i]] = results[i];
|
|
143
|
+
}
|
|
144
|
+
return resolvedObj;
|
|
145
|
+
});
|
|
146
|
+
}
|
|
147
|
+
export function randomString() {
|
|
148
|
+
let length = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : 10;
|
|
149
|
+
const chars = "abcdefghijklmnopqrstuvwxyz";
|
|
150
|
+
let str = "";
|
|
151
|
+
for (let i = 0; i < length; i++) {
|
|
152
|
+
str += chars[Math.floor(Math.random() * chars.length)];
|
|
153
|
+
}
|
|
154
|
+
return str;
|
|
155
|
+
}
|
|
156
|
+
export function esc(str) {
|
|
157
|
+
return JSON.stringify(str);
|
|
158
|
+
}
|
|
159
|
+
export function slugify(input) {
|
|
160
|
+
return input.toLowerCase().trim().replace(/[^\w\s-]/g, "").replace(/[\s_-]+/g, "-").replace(/^-+|-+$/g, "");
|
|
161
|
+
}
|
|
162
|
+
export const captureStackTrace = "captureStackTrace" in Error ? Error.captureStackTrace : function () {};
|
|
163
|
+
export function isObject(data) {
|
|
164
|
+
return typeof data === "object" && data !== null && !Array.isArray(data);
|
|
165
|
+
}
|
|
166
|
+
export const allowsEval = cached(() => {
|
|
167
|
+
var _navigator;
|
|
168
|
+
// @ts-ignore
|
|
169
|
+
if (typeof navigator !== "undefined" && (_navigator = navigator) !== null && _navigator !== void 0 && (_navigator = _navigator.userAgent) !== null && _navigator !== void 0 && _navigator.includes("Cloudflare")) {
|
|
170
|
+
return false;
|
|
171
|
+
}
|
|
172
|
+
try {
|
|
173
|
+
const F = Function;
|
|
174
|
+
new F("");
|
|
175
|
+
return true;
|
|
176
|
+
} catch (_) {
|
|
177
|
+
return false;
|
|
178
|
+
}
|
|
179
|
+
});
|
|
180
|
+
export function isPlainObject(o) {
|
|
181
|
+
if (isObject(o) === false) return false;
|
|
182
|
+
|
|
183
|
+
// modified constructor
|
|
184
|
+
const ctor = o.constructor;
|
|
185
|
+
if (ctor === undefined) return true;
|
|
186
|
+
if (typeof ctor !== "function") return true;
|
|
187
|
+
|
|
188
|
+
// modified prototype
|
|
189
|
+
const prot = ctor.prototype;
|
|
190
|
+
if (isObject(prot) === false) return false;
|
|
191
|
+
|
|
192
|
+
// ctor doesn't have static `isPrototypeOf`
|
|
193
|
+
if (Object.prototype.hasOwnProperty.call(prot, "isPrototypeOf") === false) {
|
|
194
|
+
return false;
|
|
195
|
+
}
|
|
196
|
+
return true;
|
|
197
|
+
}
|
|
198
|
+
export function shallowClone(o) {
|
|
199
|
+
if (isPlainObject(o)) return _objectSpread({}, o);
|
|
200
|
+
if (Array.isArray(o)) return [...o];
|
|
201
|
+
return o;
|
|
202
|
+
}
|
|
203
|
+
export function numKeys(data) {
|
|
204
|
+
let keyCount = 0;
|
|
205
|
+
for (const key in data) {
|
|
206
|
+
if (Object.prototype.hasOwnProperty.call(data, key)) {
|
|
207
|
+
keyCount++;
|
|
208
|
+
}
|
|
209
|
+
}
|
|
210
|
+
return keyCount;
|
|
211
|
+
}
|
|
212
|
+
export const getParsedType = data => {
|
|
213
|
+
const t = typeof data;
|
|
214
|
+
switch (t) {
|
|
215
|
+
case "undefined":
|
|
216
|
+
return "undefined";
|
|
217
|
+
case "string":
|
|
218
|
+
return "string";
|
|
219
|
+
case "number":
|
|
220
|
+
return Number.isNaN(data) ? "nan" : "number";
|
|
221
|
+
case "boolean":
|
|
222
|
+
return "boolean";
|
|
223
|
+
case "function":
|
|
224
|
+
return "function";
|
|
225
|
+
case "bigint":
|
|
226
|
+
return "bigint";
|
|
227
|
+
case "symbol":
|
|
228
|
+
return "symbol";
|
|
229
|
+
case "object":
|
|
230
|
+
if (Array.isArray(data)) {
|
|
231
|
+
return "array";
|
|
232
|
+
}
|
|
233
|
+
if (data === null) {
|
|
234
|
+
return "null";
|
|
235
|
+
}
|
|
236
|
+
if (data.then && typeof data.then === "function" && data.catch && typeof data.catch === "function") {
|
|
237
|
+
return "promise";
|
|
238
|
+
}
|
|
239
|
+
if (typeof Map !== "undefined" && data instanceof Map) {
|
|
240
|
+
return "map";
|
|
241
|
+
}
|
|
242
|
+
if (typeof Set !== "undefined" && data instanceof Set) {
|
|
243
|
+
return "set";
|
|
244
|
+
}
|
|
245
|
+
if (typeof Date !== "undefined" && data instanceof Date) {
|
|
246
|
+
return "date";
|
|
247
|
+
}
|
|
248
|
+
// @ts-ignore
|
|
249
|
+
if (typeof File !== "undefined" && data instanceof File) {
|
|
250
|
+
return "file";
|
|
251
|
+
}
|
|
252
|
+
return "object";
|
|
253
|
+
default:
|
|
254
|
+
throw new Error(`Unknown data type: ${t}`);
|
|
255
|
+
}
|
|
256
|
+
};
|
|
257
|
+
export const propertyKeyTypes = new Set(["string", "number", "symbol"]);
|
|
258
|
+
export const primitiveTypes = new Set(["string", "number", "bigint", "boolean", "symbol", "undefined"]);
|
|
259
|
+
export function escapeRegex(str) {
|
|
260
|
+
return str.replace(/[.*+?^${}()|[\]\\]/g, "\\$&");
|
|
261
|
+
}
|
|
262
|
+
|
|
263
|
+
// zod-specific utils
|
|
264
|
+
export function clone(inst, def, params) {
|
|
265
|
+
const cl = new inst._zod.constr(def !== null && def !== void 0 ? def : inst._zod.def);
|
|
266
|
+
if (!def || params !== null && params !== void 0 && params.parent) cl._zod.parent = inst;
|
|
267
|
+
return cl;
|
|
268
|
+
}
|
|
269
|
+
export function normalizeParams(_params) {
|
|
270
|
+
const params = _params;
|
|
271
|
+
if (!params) return {};
|
|
272
|
+
if (typeof params === "string") return {
|
|
273
|
+
error: () => params
|
|
274
|
+
};
|
|
275
|
+
if ((params === null || params === void 0 ? void 0 : params.message) !== undefined) {
|
|
276
|
+
if ((params === null || params === void 0 ? void 0 : params.error) !== undefined) throw new Error("Cannot specify both `message` and `error` params");
|
|
277
|
+
params.error = params.message;
|
|
278
|
+
}
|
|
279
|
+
delete params.message;
|
|
280
|
+
if (typeof params.error === "string") return _objectSpread(_objectSpread({}, params), {}, {
|
|
281
|
+
error: () => params.error
|
|
282
|
+
});
|
|
283
|
+
return params;
|
|
284
|
+
}
|
|
285
|
+
export function createTransparentProxy(getter) {
|
|
286
|
+
let target;
|
|
287
|
+
return new Proxy({}, {
|
|
288
|
+
get(_, prop, receiver) {
|
|
289
|
+
target ??= getter();
|
|
290
|
+
return Reflect.get(target, prop, receiver);
|
|
291
|
+
},
|
|
292
|
+
set(_, prop, value, receiver) {
|
|
293
|
+
target ??= getter();
|
|
294
|
+
return Reflect.set(target, prop, value, receiver);
|
|
295
|
+
},
|
|
296
|
+
has(_, prop) {
|
|
297
|
+
target ??= getter();
|
|
298
|
+
return Reflect.has(target, prop);
|
|
299
|
+
},
|
|
300
|
+
deleteProperty(_, prop) {
|
|
301
|
+
target ??= getter();
|
|
302
|
+
return Reflect.deleteProperty(target, prop);
|
|
303
|
+
},
|
|
304
|
+
ownKeys() {
|
|
305
|
+
target ??= getter();
|
|
306
|
+
return Reflect.ownKeys(target);
|
|
307
|
+
},
|
|
308
|
+
getOwnPropertyDescriptor(_, prop) {
|
|
309
|
+
target ??= getter();
|
|
310
|
+
return Reflect.getOwnPropertyDescriptor(target, prop);
|
|
311
|
+
},
|
|
312
|
+
defineProperty(_, prop, descriptor) {
|
|
313
|
+
target ??= getter();
|
|
314
|
+
return Reflect.defineProperty(target, prop, descriptor);
|
|
315
|
+
}
|
|
316
|
+
});
|
|
317
|
+
}
|
|
318
|
+
export function stringifyPrimitive(value) {
|
|
319
|
+
if (typeof value === "bigint") return value.toString() + "n";
|
|
320
|
+
if (typeof value === "string") return `"${value}"`;
|
|
321
|
+
return `${value}`;
|
|
322
|
+
}
|
|
323
|
+
export function optionalKeys(shape) {
|
|
324
|
+
return Object.keys(shape).filter(k => {
|
|
325
|
+
return shape[k]._zod.optin === "optional" && shape[k]._zod.optout === "optional";
|
|
326
|
+
});
|
|
327
|
+
}
|
|
328
|
+
export const NUMBER_FORMAT_RANGES = {
|
|
329
|
+
safeint: [Number.MIN_SAFE_INTEGER, Number.MAX_SAFE_INTEGER],
|
|
330
|
+
int32: [-2147483648, 2147483647],
|
|
331
|
+
uint32: [0, 4294967295],
|
|
332
|
+
float32: [-3.4028234663852886e38, 3.4028234663852886e38],
|
|
333
|
+
float64: [-Number.MAX_VALUE, Number.MAX_VALUE]
|
|
334
|
+
};
|
|
335
|
+
export const BIGINT_FORMAT_RANGES = {
|
|
336
|
+
int64: [/* @__PURE__*/BigInt("-9223372036854775808"), /* @__PURE__*/BigInt("9223372036854775807")],
|
|
337
|
+
uint64: [/* @__PURE__*/BigInt(0), /* @__PURE__*/BigInt("18446744073709551615")]
|
|
338
|
+
};
|
|
339
|
+
export function pick(schema, mask) {
|
|
340
|
+
const currDef = schema._zod.def;
|
|
341
|
+
const checks = currDef.checks;
|
|
342
|
+
const hasChecks = checks && checks.length > 0;
|
|
343
|
+
if (hasChecks) {
|
|
344
|
+
throw new Error(".pick() cannot be used on object schemas containing refinements");
|
|
345
|
+
}
|
|
346
|
+
const def = mergeDefs(schema._zod.def, {
|
|
347
|
+
get shape() {
|
|
348
|
+
const newShape = {};
|
|
349
|
+
for (const key in mask) {
|
|
350
|
+
if (!(key in currDef.shape)) {
|
|
351
|
+
throw new Error(`Unrecognized key: "${key}"`);
|
|
352
|
+
}
|
|
353
|
+
if (!mask[key]) continue;
|
|
354
|
+
newShape[key] = currDef.shape[key];
|
|
355
|
+
}
|
|
356
|
+
assignProp(this, "shape", newShape); // self-caching
|
|
357
|
+
return newShape;
|
|
358
|
+
},
|
|
359
|
+
checks: []
|
|
360
|
+
});
|
|
361
|
+
return clone(schema, def);
|
|
362
|
+
}
|
|
363
|
+
export function omit(schema, mask) {
|
|
364
|
+
const currDef = schema._zod.def;
|
|
365
|
+
const checks = currDef.checks;
|
|
366
|
+
const hasChecks = checks && checks.length > 0;
|
|
367
|
+
if (hasChecks) {
|
|
368
|
+
throw new Error(".omit() cannot be used on object schemas containing refinements");
|
|
369
|
+
}
|
|
370
|
+
const def = mergeDefs(schema._zod.def, {
|
|
371
|
+
get shape() {
|
|
372
|
+
const newShape = _objectSpread({}, schema._zod.def.shape);
|
|
373
|
+
for (const key in mask) {
|
|
374
|
+
if (!(key in currDef.shape)) {
|
|
375
|
+
throw new Error(`Unrecognized key: "${key}"`);
|
|
376
|
+
}
|
|
377
|
+
if (!mask[key]) continue;
|
|
378
|
+
delete newShape[key];
|
|
379
|
+
}
|
|
380
|
+
assignProp(this, "shape", newShape); // self-caching
|
|
381
|
+
return newShape;
|
|
382
|
+
},
|
|
383
|
+
checks: []
|
|
384
|
+
});
|
|
385
|
+
return clone(schema, def);
|
|
386
|
+
}
|
|
387
|
+
export function extend(schema, shape) {
|
|
388
|
+
if (!isPlainObject(shape)) {
|
|
389
|
+
throw new Error("Invalid input to extend: expected a plain object");
|
|
390
|
+
}
|
|
391
|
+
const checks = schema._zod.def.checks;
|
|
392
|
+
const hasChecks = checks && checks.length > 0;
|
|
393
|
+
if (hasChecks) {
|
|
394
|
+
// Only throw if new shape overlaps with existing shape
|
|
395
|
+
// Use getOwnPropertyDescriptor to check key existence without accessing values
|
|
396
|
+
const existingShape = schema._zod.def.shape;
|
|
397
|
+
for (const key in shape) {
|
|
398
|
+
if (Object.getOwnPropertyDescriptor(existingShape, key) !== undefined) {
|
|
399
|
+
throw new Error("Cannot overwrite keys on object schemas containing refinements. Use `.safeExtend()` instead.");
|
|
400
|
+
}
|
|
401
|
+
}
|
|
402
|
+
}
|
|
403
|
+
const def = mergeDefs(schema._zod.def, {
|
|
404
|
+
get shape() {
|
|
405
|
+
const _shape = _objectSpread(_objectSpread({}, schema._zod.def.shape), shape);
|
|
406
|
+
assignProp(this, "shape", _shape); // self-caching
|
|
407
|
+
return _shape;
|
|
408
|
+
}
|
|
409
|
+
});
|
|
410
|
+
return clone(schema, def);
|
|
411
|
+
}
|
|
412
|
+
export function safeExtend(schema, shape) {
|
|
413
|
+
if (!isPlainObject(shape)) {
|
|
414
|
+
throw new Error("Invalid input to safeExtend: expected a plain object");
|
|
415
|
+
}
|
|
416
|
+
const def = mergeDefs(schema._zod.def, {
|
|
417
|
+
get shape() {
|
|
418
|
+
const _shape = _objectSpread(_objectSpread({}, schema._zod.def.shape), shape);
|
|
419
|
+
assignProp(this, "shape", _shape); // self-caching
|
|
420
|
+
return _shape;
|
|
421
|
+
}
|
|
422
|
+
});
|
|
423
|
+
return clone(schema, def);
|
|
424
|
+
}
|
|
425
|
+
export function merge(a, b) {
|
|
426
|
+
const def = mergeDefs(a._zod.def, {
|
|
427
|
+
get shape() {
|
|
428
|
+
const _shape = _objectSpread(_objectSpread({}, a._zod.def.shape), b._zod.def.shape);
|
|
429
|
+
assignProp(this, "shape", _shape); // self-caching
|
|
430
|
+
return _shape;
|
|
431
|
+
},
|
|
432
|
+
get catchall() {
|
|
433
|
+
return b._zod.def.catchall;
|
|
434
|
+
},
|
|
435
|
+
checks: [] // delete existing checks
|
|
436
|
+
});
|
|
437
|
+
return clone(a, def);
|
|
438
|
+
}
|
|
439
|
+
export function partial(Class, schema, mask) {
|
|
440
|
+
const currDef = schema._zod.def;
|
|
441
|
+
const checks = currDef.checks;
|
|
442
|
+
const hasChecks = checks && checks.length > 0;
|
|
443
|
+
if (hasChecks) {
|
|
444
|
+
throw new Error(".partial() cannot be used on object schemas containing refinements");
|
|
445
|
+
}
|
|
446
|
+
const def = mergeDefs(schema._zod.def, {
|
|
447
|
+
get shape() {
|
|
448
|
+
const oldShape = schema._zod.def.shape;
|
|
449
|
+
const shape = _objectSpread({}, oldShape);
|
|
450
|
+
if (mask) {
|
|
451
|
+
for (const key in mask) {
|
|
452
|
+
if (!(key in oldShape)) {
|
|
453
|
+
throw new Error(`Unrecognized key: "${key}"`);
|
|
454
|
+
}
|
|
455
|
+
if (!mask[key]) continue;
|
|
456
|
+
// if (oldShape[key]!._zod.optin === "optional") continue;
|
|
457
|
+
shape[key] = Class ? new Class({
|
|
458
|
+
type: "optional",
|
|
459
|
+
innerType: oldShape[key]
|
|
460
|
+
}) : oldShape[key];
|
|
461
|
+
}
|
|
462
|
+
} else {
|
|
463
|
+
for (const key in oldShape) {
|
|
464
|
+
// if (oldShape[key]!._zod.optin === "optional") continue;
|
|
465
|
+
shape[key] = Class ? new Class({
|
|
466
|
+
type: "optional",
|
|
467
|
+
innerType: oldShape[key]
|
|
468
|
+
}) : oldShape[key];
|
|
469
|
+
}
|
|
470
|
+
}
|
|
471
|
+
assignProp(this, "shape", shape); // self-caching
|
|
472
|
+
return shape;
|
|
473
|
+
},
|
|
474
|
+
checks: []
|
|
475
|
+
});
|
|
476
|
+
return clone(schema, def);
|
|
477
|
+
}
|
|
478
|
+
export function required(Class, schema, mask) {
|
|
479
|
+
const def = mergeDefs(schema._zod.def, {
|
|
480
|
+
get shape() {
|
|
481
|
+
const oldShape = schema._zod.def.shape;
|
|
482
|
+
const shape = _objectSpread({}, oldShape);
|
|
483
|
+
if (mask) {
|
|
484
|
+
for (const key in mask) {
|
|
485
|
+
if (!(key in shape)) {
|
|
486
|
+
throw new Error(`Unrecognized key: "${key}"`);
|
|
487
|
+
}
|
|
488
|
+
if (!mask[key]) continue;
|
|
489
|
+
// overwrite with non-optional
|
|
490
|
+
shape[key] = new Class({
|
|
491
|
+
type: "nonoptional",
|
|
492
|
+
innerType: oldShape[key]
|
|
493
|
+
});
|
|
494
|
+
}
|
|
495
|
+
} else {
|
|
496
|
+
for (const key in oldShape) {
|
|
497
|
+
// overwrite with non-optional
|
|
498
|
+
shape[key] = new Class({
|
|
499
|
+
type: "nonoptional",
|
|
500
|
+
innerType: oldShape[key]
|
|
501
|
+
});
|
|
502
|
+
}
|
|
503
|
+
}
|
|
504
|
+
assignProp(this, "shape", shape); // self-caching
|
|
505
|
+
return shape;
|
|
506
|
+
}
|
|
507
|
+
});
|
|
508
|
+
return clone(schema, def);
|
|
509
|
+
}
|
|
510
|
+
// invalid_type | too_big | too_small | invalid_format | not_multiple_of | unrecognized_keys | invalid_union | invalid_key | invalid_element | invalid_value | custom
|
|
511
|
+
export function aborted(x) {
|
|
512
|
+
let startIndex = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : 0;
|
|
513
|
+
if (x.aborted === true) return true;
|
|
514
|
+
for (let i = startIndex; i < x.issues.length; i++) {
|
|
515
|
+
var _x$issues$i;
|
|
516
|
+
if (((_x$issues$i = x.issues[i]) === null || _x$issues$i === void 0 ? void 0 : _x$issues$i.continue) !== true) {
|
|
517
|
+
return true;
|
|
518
|
+
}
|
|
519
|
+
}
|
|
520
|
+
return false;
|
|
521
|
+
}
|
|
522
|
+
export function prefixIssues(path, issues) {
|
|
523
|
+
return issues.map(iss => {
|
|
524
|
+
iss.path ??= [];
|
|
525
|
+
iss.path.unshift(path);
|
|
526
|
+
return iss;
|
|
527
|
+
});
|
|
528
|
+
}
|
|
529
|
+
export function unwrapMessage(message) {
|
|
530
|
+
return typeof message === "string" ? message : message === null || message === void 0 ? void 0 : message.message;
|
|
531
|
+
}
|
|
532
|
+
export function finalizeIssue(iss, ctx, config) {
|
|
533
|
+
var _iss$path;
|
|
534
|
+
const full = _objectSpread(_objectSpread({}, iss), {}, {
|
|
535
|
+
path: (_iss$path = iss.path) !== null && _iss$path !== void 0 ? _iss$path : []
|
|
536
|
+
});
|
|
537
|
+
|
|
538
|
+
// for backwards compatibility
|
|
539
|
+
if (!iss.message) {
|
|
540
|
+
var _ref3, _ref4, _ref5, _unwrapMessage, _iss$inst, _iss$inst$error, _ctx$error, _config$customError, _config$localeError;
|
|
541
|
+
const message = (_ref3 = (_ref4 = (_ref5 = (_unwrapMessage = unwrapMessage((_iss$inst = iss.inst) === null || _iss$inst === void 0 || (_iss$inst = _iss$inst._zod.def) === null || _iss$inst === void 0 || (_iss$inst$error = _iss$inst.error) === null || _iss$inst$error === void 0 ? void 0 : _iss$inst$error.call(_iss$inst, iss))) !== null && _unwrapMessage !== void 0 ? _unwrapMessage : unwrapMessage(ctx === null || ctx === void 0 || (_ctx$error = ctx.error) === null || _ctx$error === void 0 ? void 0 : _ctx$error.call(ctx, iss))) !== null && _ref5 !== void 0 ? _ref5 : unwrapMessage((_config$customError = config.customError) === null || _config$customError === void 0 ? void 0 : _config$customError.call(config, iss))) !== null && _ref4 !== void 0 ? _ref4 : unwrapMessage((_config$localeError = config.localeError) === null || _config$localeError === void 0 ? void 0 : _config$localeError.call(config, iss))) !== null && _ref3 !== void 0 ? _ref3 : "Invalid input";
|
|
542
|
+
full.message = message;
|
|
543
|
+
}
|
|
544
|
+
|
|
545
|
+
// delete (full as any).def;
|
|
546
|
+
delete full.inst;
|
|
547
|
+
delete full.continue;
|
|
548
|
+
if (!(ctx !== null && ctx !== void 0 && ctx.reportInput)) {
|
|
549
|
+
delete full.input;
|
|
550
|
+
}
|
|
551
|
+
return full;
|
|
552
|
+
}
|
|
553
|
+
export function getSizableOrigin(input) {
|
|
554
|
+
if (input instanceof Set) return "set";
|
|
555
|
+
if (input instanceof Map) return "map";
|
|
556
|
+
// @ts-ignore
|
|
557
|
+
if (input instanceof File) return "file";
|
|
558
|
+
return "unknown";
|
|
559
|
+
}
|
|
560
|
+
export function getLengthableOrigin(input) {
|
|
561
|
+
if (Array.isArray(input)) return "array";
|
|
562
|
+
if (typeof input === "string") return "string";
|
|
563
|
+
return "unknown";
|
|
564
|
+
}
|
|
565
|
+
export function parsedType(data) {
|
|
566
|
+
const t = typeof data;
|
|
567
|
+
switch (t) {
|
|
568
|
+
case "number":
|
|
569
|
+
{
|
|
570
|
+
return Number.isNaN(data) ? "nan" : "number";
|
|
571
|
+
}
|
|
572
|
+
case "object":
|
|
573
|
+
{
|
|
574
|
+
if (data === null) {
|
|
575
|
+
return "null";
|
|
576
|
+
}
|
|
577
|
+
if (Array.isArray(data)) {
|
|
578
|
+
return "array";
|
|
579
|
+
}
|
|
580
|
+
const obj = data;
|
|
581
|
+
if (obj && Object.getPrototypeOf(obj) !== Object.prototype && "constructor" in obj && obj.constructor) {
|
|
582
|
+
return obj.constructor.name;
|
|
583
|
+
}
|
|
584
|
+
}
|
|
585
|
+
}
|
|
586
|
+
return t;
|
|
587
|
+
}
|
|
588
|
+
|
|
589
|
+
////////// REFINES //////////
|
|
590
|
+
|
|
591
|
+
export function issue() {
|
|
592
|
+
for (var _len2 = arguments.length, args = new Array(_len2), _key2 = 0; _key2 < _len2; _key2++) {
|
|
593
|
+
args[_key2] = arguments[_key2];
|
|
594
|
+
}
|
|
595
|
+
const [iss, input, inst] = args;
|
|
596
|
+
if (typeof iss === "string") {
|
|
597
|
+
return {
|
|
598
|
+
message: iss,
|
|
599
|
+
code: "custom",
|
|
600
|
+
input,
|
|
601
|
+
inst
|
|
602
|
+
};
|
|
603
|
+
}
|
|
604
|
+
return _objectSpread({}, iss);
|
|
605
|
+
}
|
|
606
|
+
export function cleanEnum(obj) {
|
|
607
|
+
return Object.entries(obj).filter(_ref6 => {
|
|
608
|
+
let [k, _] = _ref6;
|
|
609
|
+
// return true if NaN, meaning it's not a number, thus a string key
|
|
610
|
+
return Number.isNaN(Number.parseInt(k, 10));
|
|
611
|
+
}).map(el => el[1]);
|
|
612
|
+
}
|
|
613
|
+
|
|
614
|
+
// Codec utility functions
|
|
615
|
+
export function base64ToUint8Array(base64) {
|
|
616
|
+
const binaryString = atob(base64);
|
|
617
|
+
const bytes = new Uint8Array(binaryString.length);
|
|
618
|
+
for (let i = 0; i < binaryString.length; i++) {
|
|
619
|
+
bytes[i] = binaryString.charCodeAt(i);
|
|
620
|
+
}
|
|
621
|
+
return bytes;
|
|
622
|
+
}
|
|
623
|
+
export function uint8ArrayToBase64(bytes) {
|
|
624
|
+
let binaryString = "";
|
|
625
|
+
for (let i = 0; i < bytes.length; i++) {
|
|
626
|
+
binaryString += String.fromCharCode(bytes[i]);
|
|
627
|
+
}
|
|
628
|
+
return btoa(binaryString);
|
|
629
|
+
}
|
|
630
|
+
export function base64urlToUint8Array(base64url) {
|
|
631
|
+
const base64 = base64url.replace(/-/g, "+").replace(/_/g, "/");
|
|
632
|
+
const padding = "=".repeat((4 - base64.length % 4) % 4);
|
|
633
|
+
return base64ToUint8Array(base64 + padding);
|
|
634
|
+
}
|
|
635
|
+
export function uint8ArrayToBase64url(bytes) {
|
|
636
|
+
return uint8ArrayToBase64(bytes).replace(/\+/g, "-").replace(/\//g, "_").replace(/=/g, "");
|
|
637
|
+
}
|
|
638
|
+
export function hexToUint8Array(hex) {
|
|
639
|
+
const cleanHex = hex.replace(/^0x/, "");
|
|
640
|
+
if (cleanHex.length % 2 !== 0) {
|
|
641
|
+
throw new Error("Invalid hex string length");
|
|
642
|
+
}
|
|
643
|
+
const bytes = new Uint8Array(cleanHex.length / 2);
|
|
644
|
+
for (let i = 0; i < cleanHex.length; i += 2) {
|
|
645
|
+
bytes[i / 2] = Number.parseInt(cleanHex.slice(i, i + 2), 16);
|
|
646
|
+
}
|
|
647
|
+
return bytes;
|
|
648
|
+
}
|
|
649
|
+
export function uint8ArrayToHex(bytes) {
|
|
650
|
+
return Array.from(bytes).map(b => b.toString(16).padStart(2, "0")).join("");
|
|
651
|
+
}
|
|
652
|
+
|
|
653
|
+
// instanceof
|
|
654
|
+
export class Class {
|
|
655
|
+
constructor() {}
|
|
656
|
+
}
|