@chainflip/sdk 1.4.0-alpha.2 → 1.4.0-alpha.3
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/broker-QU4VVLJN.mjs +79 -0
- package/dist/{chunk-LQGUI52U.mjs → chunk-EEVRQLUS.mjs} +65 -236
- package/dist/{chunk-4HLERQ4Y.mjs → chunk-GCBDMMEA.mjs} +22 -161
- package/dist/chunk-GL7BY5NM.mjs +235 -0
- package/dist/{contracts-ZLesmWHT.d.mts → contracts-49zdGryt.d.mts} +9 -1
- package/dist/{contracts-ZLesmWHT.d.ts → contracts-49zdGryt.d.ts} +9 -1
- package/dist/funding.d.mts +1 -1
- package/dist/funding.d.ts +1 -1
- package/dist/funding.js +107 -4831
- package/dist/funding.mjs +2 -2
- package/dist/swap.d.mts +12 -4
- package/dist/swap.d.ts +12 -4
- package/dist/swap.js +94 -284
- package/dist/swap.mjs +5 -5
- package/package.json +3 -2
- package/dist/broker-XWF7RRDY.mjs +0 -124
- package/dist/chunk-KHC24Z3O.mjs +0 -65
package/dist/funding.js
CHANGED
|
@@ -1,482 +1,15 @@
|
|
|
1
1
|
'use strict';
|
|
2
2
|
|
|
3
|
-
var
|
|
4
|
-
var
|
|
5
|
-
var ss582 = require('@chainflip/utils/ss58');
|
|
6
|
-
require('@chainflip/utils/base58');
|
|
3
|
+
var ethers = require('ethers');
|
|
4
|
+
var rpc = require('@chainflip/rpc');
|
|
7
5
|
|
|
8
|
-
function _interopDefault (e) { return e && e.__esModule ? e : { default: e }; }
|
|
9
|
-
|
|
10
|
-
function _interopNamespace(e) {
|
|
11
|
-
if (e && e.__esModule) return e;
|
|
12
|
-
var n = Object.create(null);
|
|
13
|
-
if (e) {
|
|
14
|
-
Object.keys(e).forEach(function (k) {
|
|
15
|
-
if (k !== 'default') {
|
|
16
|
-
var d = Object.getOwnPropertyDescriptor(e, k);
|
|
17
|
-
Object.defineProperty(n, k, d.get ? d : {
|
|
18
|
-
enumerable: true,
|
|
19
|
-
get: function () { return e[k]; }
|
|
20
|
-
});
|
|
21
|
-
}
|
|
22
|
-
});
|
|
23
|
-
}
|
|
24
|
-
n.default = e;
|
|
25
|
-
return Object.freeze(n);
|
|
26
|
-
}
|
|
27
|
-
|
|
28
|
-
var ethers2__namespace = /*#__PURE__*/_interopNamespace(ethers2);
|
|
29
|
-
var axios__default = /*#__PURE__*/_interopDefault(axios);
|
|
30
|
-
var ss582__namespace = /*#__PURE__*/_interopNamespace(ss582);
|
|
31
|
-
|
|
32
|
-
var __create = Object.create;
|
|
33
6
|
var __defProp = Object.defineProperty;
|
|
34
|
-
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
35
|
-
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
36
|
-
var __getProtoOf = Object.getPrototypeOf;
|
|
37
|
-
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
38
7
|
var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
|
|
39
8
|
var __name = (target, value) => __defProp(target, "name", { value, configurable: true });
|
|
40
|
-
var __commonJS = (cb, mod) => function __require() {
|
|
41
|
-
return mod || (0, cb[__getOwnPropNames(cb)[0]])((mod = { exports: {} }).exports, mod), mod.exports;
|
|
42
|
-
};
|
|
43
|
-
var __copyProps = (to, from, except, desc) => {
|
|
44
|
-
if (from && typeof from === "object" || typeof from === "function") {
|
|
45
|
-
for (let key of __getOwnPropNames(from))
|
|
46
|
-
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
47
|
-
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
48
|
-
}
|
|
49
|
-
return to;
|
|
50
|
-
};
|
|
51
|
-
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
|
|
52
|
-
// If the importer is in node compatibility mode or this is not an ESM
|
|
53
|
-
// file that has been converted to a CommonJS file using a Babel-
|
|
54
|
-
// compatible transform (i.e. "__esModule" has not been set), then set
|
|
55
|
-
// "default" to the CommonJS "module.exports" for node compatibility.
|
|
56
|
-
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
|
|
57
|
-
mod
|
|
58
|
-
));
|
|
59
9
|
var __publicField = (obj, key, value) => {
|
|
60
10
|
__defNormalProp(obj, typeof key !== "symbol" ? key + "" : key, value);
|
|
61
11
|
return value;
|
|
62
12
|
};
|
|
63
|
-
|
|
64
|
-
// ../../node_modules/.pnpm/bech32-buffer@0.2.1_patch_hash=elryfzb6nrq4qzi6wcigmgsdj4/node_modules/bech32-buffer/lib/bit-converter.js
|
|
65
|
-
var require_bit_converter = __commonJS({
|
|
66
|
-
"../../node_modules/.pnpm/bech32-buffer@0.2.1_patch_hash=elryfzb6nrq4qzi6wcigmgsdj4/node_modules/bech32-buffer/lib/bit-converter.js"(exports) {
|
|
67
|
-
Object.defineProperty(exports, "__esModule", {
|
|
68
|
-
value: true
|
|
69
|
-
});
|
|
70
|
-
exports.createBitArray = createBitArray;
|
|
71
|
-
exports.fromBits = fromBits;
|
|
72
|
-
exports.toBits = toBits;
|
|
73
|
-
function toBitArrayUnchecked(src) {
|
|
74
|
-
return src;
|
|
75
|
-
}
|
|
76
|
-
__name(toBitArrayUnchecked, "toBitArrayUnchecked");
|
|
77
|
-
function createBitArray(len) {
|
|
78
|
-
return toBitArrayUnchecked(new Uint8Array(len));
|
|
79
|
-
}
|
|
80
|
-
__name(createBitArray, "createBitArray");
|
|
81
|
-
function convert(src, srcBits, dst, dstBits, pad) {
|
|
82
|
-
var mask = (1 << dstBits) - 1;
|
|
83
|
-
var acc = 0;
|
|
84
|
-
var bits = 0;
|
|
85
|
-
var pos = 0;
|
|
86
|
-
src.forEach(function(b) {
|
|
87
|
-
acc = (acc << srcBits) + b;
|
|
88
|
-
bits += srcBits;
|
|
89
|
-
while (bits >= dstBits) {
|
|
90
|
-
bits -= dstBits;
|
|
91
|
-
dst[pos] = acc >> bits & mask;
|
|
92
|
-
pos += 1;
|
|
93
|
-
}
|
|
94
|
-
});
|
|
95
|
-
if (pad) {
|
|
96
|
-
if (bits > 0) {
|
|
97
|
-
dst[pos] = acc << dstBits - bits & mask;
|
|
98
|
-
}
|
|
99
|
-
} else {
|
|
100
|
-
if (bits >= srcBits) {
|
|
101
|
-
throw new Error("Excessive padding: ".concat(bits, " (max ").concat(srcBits - 1, " allowed)"));
|
|
102
|
-
}
|
|
103
|
-
if (acc % (1 << bits) !== 0) {
|
|
104
|
-
throw new Error("Non-zero padding");
|
|
105
|
-
}
|
|
106
|
-
}
|
|
107
|
-
}
|
|
108
|
-
__name(convert, "convert");
|
|
109
|
-
function toBits(src, bits, dst) {
|
|
110
|
-
if (bits > 8 || bits < 1) {
|
|
111
|
-
throw new RangeError("Invalid bits per element; 1 to 8 expected");
|
|
112
|
-
}
|
|
113
|
-
convert(toBitArrayUnchecked(src), 8, dst, bits, true);
|
|
114
|
-
return dst;
|
|
115
|
-
}
|
|
116
|
-
__name(toBits, "toBits");
|
|
117
|
-
function fromBits(src, bits, dst) {
|
|
118
|
-
if (bits > 8 || bits < 1) {
|
|
119
|
-
throw new RangeError("Invalid bits per element; 1 to 8 expected");
|
|
120
|
-
}
|
|
121
|
-
convert(src, bits, toBitArrayUnchecked(dst), 8, false);
|
|
122
|
-
return dst;
|
|
123
|
-
}
|
|
124
|
-
__name(fromBits, "fromBits");
|
|
125
|
-
}
|
|
126
|
-
});
|
|
127
|
-
|
|
128
|
-
// ../../node_modules/.pnpm/bech32-buffer@0.2.1_patch_hash=elryfzb6nrq4qzi6wcigmgsdj4/node_modules/bech32-buffer/lib/encoding.js
|
|
129
|
-
var require_encoding = __commonJS({
|
|
130
|
-
"../../node_modules/.pnpm/bech32-buffer@0.2.1_patch_hash=elryfzb6nrq4qzi6wcigmgsdj4/node_modules/bech32-buffer/lib/encoding.js"(exports) {
|
|
131
|
-
Object.defineProperty(exports, "__esModule", {
|
|
132
|
-
value: true
|
|
133
|
-
});
|
|
134
|
-
exports.CHECKSUM_LENGTH = void 0;
|
|
135
|
-
exports.createChecksum = createChecksum;
|
|
136
|
-
exports.decode = decode4;
|
|
137
|
-
exports.decodeWithPrefix = decodeWithPrefix;
|
|
138
|
-
exports.detectCase = detectCase;
|
|
139
|
-
exports.encode = encode2;
|
|
140
|
-
exports.expandPrefix = expandPrefix;
|
|
141
|
-
exports.verifyChecksum = verifyChecksum;
|
|
142
|
-
var _bitConverter = require_bit_converter();
|
|
143
|
-
var CHARSET = "qpzry9x8gf2tvdw0s3jn54khce6mua7l";
|
|
144
|
-
var BECH32M_CHECKSUM = 734539939;
|
|
145
|
-
var MIN_CHAR_CODE = 33;
|
|
146
|
-
var MAX_CHAR_CODE = 126;
|
|
147
|
-
var CHECKSUM_LENGTH = 6;
|
|
148
|
-
exports.CHECKSUM_LENGTH = CHECKSUM_LENGTH;
|
|
149
|
-
var CHAR_LOOKUP = function() {
|
|
150
|
-
var lookup = /* @__PURE__ */ new Map();
|
|
151
|
-
for (var i = 0; i < CHARSET.length; i += 1) {
|
|
152
|
-
lookup.set(CHARSET[i], i);
|
|
153
|
-
}
|
|
154
|
-
return lookup;
|
|
155
|
-
}();
|
|
156
|
-
var GEN = [
|
|
157
|
-
996825010,
|
|
158
|
-
642813549,
|
|
159
|
-
513874426,
|
|
160
|
-
1027748829,
|
|
161
|
-
705979059
|
|
162
|
-
];
|
|
163
|
-
function polymod(values) {
|
|
164
|
-
return values.reduce(
|
|
165
|
-
function(checksum, value) {
|
|
166
|
-
var bits = checksum >> 25;
|
|
167
|
-
var newChecksum = (checksum & 33554431) << 5 ^ value;
|
|
168
|
-
return GEN.reduce(function(chk, gen, i) {
|
|
169
|
-
return (bits >> i & 1) === 0 ? chk : chk ^ gen;
|
|
170
|
-
}, newChecksum);
|
|
171
|
-
},
|
|
172
|
-
/* initial checksum */
|
|
173
|
-
1
|
|
174
|
-
);
|
|
175
|
-
}
|
|
176
|
-
__name(polymod, "polymod");
|
|
177
|
-
function expandPrefix(prefix, outBuffer) {
|
|
178
|
-
for (var i = 0; i < prefix.length; i += 1) {
|
|
179
|
-
var code = prefix.charCodeAt(i);
|
|
180
|
-
outBuffer[i] = code >> 5;
|
|
181
|
-
outBuffer[i + prefix.length + 1] = code & 31;
|
|
182
|
-
}
|
|
183
|
-
outBuffer[prefix.length] = 0;
|
|
184
|
-
}
|
|
185
|
-
__name(expandPrefix, "expandPrefix");
|
|
186
|
-
function verifyChecksum(buffer) {
|
|
187
|
-
switch (polymod(buffer)) {
|
|
188
|
-
case 1:
|
|
189
|
-
return "bech32";
|
|
190
|
-
case BECH32M_CHECKSUM:
|
|
191
|
-
return "bech32m";
|
|
192
|
-
default:
|
|
193
|
-
return void 0;
|
|
194
|
-
}
|
|
195
|
-
}
|
|
196
|
-
__name(verifyChecksum, "verifyChecksum");
|
|
197
|
-
function createChecksum(buffer, encoding) {
|
|
198
|
-
var checksumConstant;
|
|
199
|
-
switch (encoding) {
|
|
200
|
-
case "bech32":
|
|
201
|
-
checksumConstant = 1;
|
|
202
|
-
break;
|
|
203
|
-
case "bech32m":
|
|
204
|
-
checksumConstant = BECH32M_CHECKSUM;
|
|
205
|
-
break;
|
|
206
|
-
default:
|
|
207
|
-
throw Error("Invalid encoding value: ".concat(encoding, "; expected bech32 or bech32m"));
|
|
208
|
-
}
|
|
209
|
-
var mod = polymod(buffer) ^ checksumConstant;
|
|
210
|
-
for (var i = 0; i < CHECKSUM_LENGTH; i += 1) {
|
|
211
|
-
var shift = 5 * (5 - i);
|
|
212
|
-
buffer[buffer.length - CHECKSUM_LENGTH + i] = mod >> shift & 31;
|
|
213
|
-
}
|
|
214
|
-
}
|
|
215
|
-
__name(createChecksum, "createChecksum");
|
|
216
|
-
function encode2(buffer) {
|
|
217
|
-
return buffer.reduce(function(acc, bits) {
|
|
218
|
-
return acc + CHARSET[bits];
|
|
219
|
-
}, "");
|
|
220
|
-
}
|
|
221
|
-
__name(encode2, "encode");
|
|
222
|
-
function decode4(message, dst) {
|
|
223
|
-
var realDst = dst || (0, _bitConverter.createBitArray)(message.length);
|
|
224
|
-
for (var i = 0; i < message.length; i += 1) {
|
|
225
|
-
var idx = CHAR_LOOKUP.get(message[i]);
|
|
226
|
-
if (idx === void 0) {
|
|
227
|
-
throw new Error("Invalid char in message: ".concat(message[i]));
|
|
228
|
-
}
|
|
229
|
-
realDst[i] = idx;
|
|
230
|
-
}
|
|
231
|
-
return realDst;
|
|
232
|
-
}
|
|
233
|
-
__name(decode4, "decode");
|
|
234
|
-
function decodeWithPrefix(prefix, message) {
|
|
235
|
-
var len = message.length + 2 * prefix.length + 1;
|
|
236
|
-
var dst = (0, _bitConverter.createBitArray)(len);
|
|
237
|
-
expandPrefix(prefix, dst.subarray(0, 2 * prefix.length + 1));
|
|
238
|
-
decode4(message, dst.subarray(2 * prefix.length + 1));
|
|
239
|
-
return dst;
|
|
240
|
-
}
|
|
241
|
-
__name(decodeWithPrefix, "decodeWithPrefix");
|
|
242
|
-
function detectCase(message) {
|
|
243
|
-
var messageDescription = arguments.length > 1 && arguments[1] !== void 0 ? arguments[1] : "message";
|
|
244
|
-
var hasLowerCase = false;
|
|
245
|
-
var hasUpperCase = false;
|
|
246
|
-
for (var i = 0; i < message.length; i += 1) {
|
|
247
|
-
var ord = message.charCodeAt(i);
|
|
248
|
-
if (ord < MIN_CHAR_CODE || ord > MAX_CHAR_CODE) {
|
|
249
|
-
throw new TypeError("Invalid char in ".concat(messageDescription, ": ").concat(ord, "; ") + "should be in ASCII range ".concat(MIN_CHAR_CODE, "-").concat(MAX_CHAR_CODE));
|
|
250
|
-
}
|
|
251
|
-
hasUpperCase = hasUpperCase || ord >= 65 && ord <= 90;
|
|
252
|
-
hasLowerCase = hasLowerCase || ord >= 97 && ord <= 122;
|
|
253
|
-
}
|
|
254
|
-
if (hasLowerCase && hasUpperCase) {
|
|
255
|
-
throw new TypeError("Mixed-case ".concat(messageDescription));
|
|
256
|
-
} else if (hasUpperCase) {
|
|
257
|
-
return "upper";
|
|
258
|
-
} else if (hasLowerCase) {
|
|
259
|
-
return "lower";
|
|
260
|
-
} else {
|
|
261
|
-
return null;
|
|
262
|
-
}
|
|
263
|
-
}
|
|
264
|
-
__name(detectCase, "detectCase");
|
|
265
|
-
}
|
|
266
|
-
});
|
|
267
|
-
|
|
268
|
-
// ../../node_modules/.pnpm/bech32-buffer@0.2.1_patch_hash=elryfzb6nrq4qzi6wcigmgsdj4/node_modules/bech32-buffer/lib/index.js
|
|
269
|
-
var require_lib = __commonJS({
|
|
270
|
-
"../../node_modules/.pnpm/bech32-buffer@0.2.1_patch_hash=elryfzb6nrq4qzi6wcigmgsdj4/node_modules/bech32-buffer/lib/index.js"(exports) {
|
|
271
|
-
Object.defineProperty(exports, "__esModule", {
|
|
272
|
-
value: true
|
|
273
|
-
});
|
|
274
|
-
exports.BitcoinAddress = void 0;
|
|
275
|
-
exports.decode = decode4;
|
|
276
|
-
exports.decodeTo5BitArray = decodeTo5BitArray;
|
|
277
|
-
exports.encode = encode2;
|
|
278
|
-
exports.encode5BitArray = encode5BitArray;
|
|
279
|
-
exports.from5BitArray = from5BitArray;
|
|
280
|
-
exports.to5BitArray = to5BitArray;
|
|
281
|
-
var _bitConverter = require_bit_converter();
|
|
282
|
-
var _encoding = require_encoding();
|
|
283
|
-
function _classCallCheck(instance, Constructor) {
|
|
284
|
-
if (!(instance instanceof Constructor)) {
|
|
285
|
-
throw new TypeError("Cannot call a class as a function");
|
|
286
|
-
}
|
|
287
|
-
}
|
|
288
|
-
__name(_classCallCheck, "_classCallCheck");
|
|
289
|
-
function _defineProperties(target, props) {
|
|
290
|
-
for (var i = 0; i < props.length; i++) {
|
|
291
|
-
var descriptor = props[i];
|
|
292
|
-
descriptor.enumerable = descriptor.enumerable || false;
|
|
293
|
-
descriptor.configurable = true;
|
|
294
|
-
if ("value" in descriptor)
|
|
295
|
-
descriptor.writable = true;
|
|
296
|
-
Object.defineProperty(target, descriptor.key, descriptor);
|
|
297
|
-
}
|
|
298
|
-
}
|
|
299
|
-
__name(_defineProperties, "_defineProperties");
|
|
300
|
-
function _createClass(Constructor, protoProps, staticProps) {
|
|
301
|
-
if (protoProps)
|
|
302
|
-
_defineProperties(Constructor.prototype, protoProps);
|
|
303
|
-
if (staticProps)
|
|
304
|
-
_defineProperties(Constructor, staticProps);
|
|
305
|
-
Object.defineProperty(Constructor, "prototype", {
|
|
306
|
-
writable: false
|
|
307
|
-
});
|
|
308
|
-
return Constructor;
|
|
309
|
-
}
|
|
310
|
-
__name(_createClass, "_createClass");
|
|
311
|
-
var MAX_ENC_LENGTH = 90;
|
|
312
|
-
function to5BitArray(src, dst) {
|
|
313
|
-
var len = Math.ceil(src.length * 8 / 5);
|
|
314
|
-
var realDst = dst || (0, _bitConverter.createBitArray)(len);
|
|
315
|
-
return (0, _bitConverter.toBits)(src, 5, realDst);
|
|
316
|
-
}
|
|
317
|
-
__name(to5BitArray, "to5BitArray");
|
|
318
|
-
function from5BitArray(src, dst) {
|
|
319
|
-
var len = Math.floor(src.length * 5 / 8);
|
|
320
|
-
var realDst = dst || new Uint8Array(len);
|
|
321
|
-
return (0, _bitConverter.fromBits)(src, 5, realDst);
|
|
322
|
-
}
|
|
323
|
-
__name(from5BitArray, "from5BitArray");
|
|
324
|
-
function encode5BitArray(prefix, data) {
|
|
325
|
-
var _detectCase;
|
|
326
|
-
var encoding = arguments.length > 2 && arguments[2] !== void 0 ? arguments[2] : "bech32";
|
|
327
|
-
var len = 2 * prefix.length + 1 + data.length + _encoding.CHECKSUM_LENGTH;
|
|
328
|
-
if (len - prefix.length > MAX_ENC_LENGTH) {
|
|
329
|
-
throw new Error("Message to be produced is too long (max ".concat(MAX_ENC_LENGTH, " supported)"));
|
|
330
|
-
}
|
|
331
|
-
var prefixCase = (_detectCase = (0, _encoding.detectCase)(prefix, "prefix")) !== null && _detectCase !== void 0 ? _detectCase : "lower";
|
|
332
|
-
var buffer = (0, _bitConverter.createBitArray)(len);
|
|
333
|
-
(0, _encoding.expandPrefix)(prefix.toLowerCase(), buffer.subarray(0, 2 * prefix.length + 1));
|
|
334
|
-
var dataBuffer = buffer.subarray(2 * prefix.length + 1, buffer.length - _encoding.CHECKSUM_LENGTH);
|
|
335
|
-
dataBuffer.set(data);
|
|
336
|
-
(0, _encoding.createChecksum)(buffer, encoding);
|
|
337
|
-
var encoded = (0, _encoding.encode)(buffer.subarray(2 * prefix.length + 1));
|
|
338
|
-
if (prefixCase === "upper") {
|
|
339
|
-
encoded = encoded.toUpperCase();
|
|
340
|
-
}
|
|
341
|
-
return "".concat(prefix, "1").concat(encoded);
|
|
342
|
-
}
|
|
343
|
-
__name(encode5BitArray, "encode5BitArray");
|
|
344
|
-
function encode2(prefix, data) {
|
|
345
|
-
var encoding = arguments.length > 2 && arguments[2] !== void 0 ? arguments[2] : "bech32";
|
|
346
|
-
return encode5BitArray(prefix, to5BitArray(data), encoding);
|
|
347
|
-
}
|
|
348
|
-
__name(encode2, "encode");
|
|
349
|
-
function decodeTo5BitArray(message) {
|
|
350
|
-
if (message.length > MAX_ENC_LENGTH) {
|
|
351
|
-
throw new TypeError("Message too long; max ".concat(MAX_ENC_LENGTH, " expected"));
|
|
352
|
-
}
|
|
353
|
-
(0, _encoding.detectCase)(message);
|
|
354
|
-
var lowerCaseMsg = message.toLowerCase();
|
|
355
|
-
var sepIdx = lowerCaseMsg.lastIndexOf("1");
|
|
356
|
-
if (sepIdx < 0) {
|
|
357
|
-
throw new Error('No separator char ("1") found');
|
|
358
|
-
}
|
|
359
|
-
if (sepIdx > message.length - _encoding.CHECKSUM_LENGTH - 1) {
|
|
360
|
-
throw new Error("Data part of the message too short (at least ".concat(_encoding.CHECKSUM_LENGTH, " chars expected)"));
|
|
361
|
-
}
|
|
362
|
-
var prefix = lowerCaseMsg.substring(0, sepIdx);
|
|
363
|
-
var bitArray = (0, _encoding.decodeWithPrefix)(prefix, lowerCaseMsg.substring(sepIdx + 1));
|
|
364
|
-
var encoding = (0, _encoding.verifyChecksum)(bitArray);
|
|
365
|
-
if (encoding === void 0) {
|
|
366
|
-
throw new Error("Invalid checksum");
|
|
367
|
-
}
|
|
368
|
-
return {
|
|
369
|
-
prefix,
|
|
370
|
-
encoding,
|
|
371
|
-
// Strip off the prefix from the front and the checksum from the end
|
|
372
|
-
data: bitArray.subarray(2 * prefix.length + 1, bitArray.length - _encoding.CHECKSUM_LENGTH)
|
|
373
|
-
};
|
|
374
|
-
}
|
|
375
|
-
__name(decodeTo5BitArray, "decodeTo5BitArray");
|
|
376
|
-
function decode4(message) {
|
|
377
|
-
var _decodeTo5BitArray = decodeTo5BitArray(message), prefix = _decodeTo5BitArray.prefix, encoding = _decodeTo5BitArray.encoding, bitArray = _decodeTo5BitArray.data;
|
|
378
|
-
return {
|
|
379
|
-
prefix,
|
|
380
|
-
encoding,
|
|
381
|
-
data: from5BitArray(bitArray)
|
|
382
|
-
};
|
|
383
|
-
}
|
|
384
|
-
__name(decode4, "decode");
|
|
385
|
-
var BitcoinAddress2 = /* @__PURE__ */ function() {
|
|
386
|
-
function BitcoinAddress3(prefix, scriptVersion, data) {
|
|
387
|
-
_classCallCheck(this, BitcoinAddress3);
|
|
388
|
-
if (prefix !== "bc" && prefix !== "tb" && prefix !== "bcrt") {
|
|
389
|
-
throw new Error('Invalid human-readable prefix, "bc", "tb", or "bcrt" expected');
|
|
390
|
-
}
|
|
391
|
-
if (scriptVersion < 0 || scriptVersion > 16) {
|
|
392
|
-
throw new RangeError("Invalid scriptVersion, value in range [0, 16] expected");
|
|
393
|
-
}
|
|
394
|
-
if (data.length < 2 || data.length > 40) {
|
|
395
|
-
throw new RangeError("Invalid script length: expected 2 to 40 bytes");
|
|
396
|
-
}
|
|
397
|
-
if (scriptVersion === 0 && data.length !== 20 && data.length !== 32) {
|
|
398
|
-
throw new Error("Invalid v0 script length: expected 20 or 32 bytes");
|
|
399
|
-
}
|
|
400
|
-
this.prefix = prefix;
|
|
401
|
-
this.scriptVersion = scriptVersion;
|
|
402
|
-
this.data = data;
|
|
403
|
-
}
|
|
404
|
-
__name(BitcoinAddress3, "BitcoinAddress");
|
|
405
|
-
_createClass(BitcoinAddress3, [
|
|
406
|
-
{
|
|
407
|
-
key: "type",
|
|
408
|
-
value: /* @__PURE__ */ __name(function type() {
|
|
409
|
-
if (this.scriptVersion !== 0) {
|
|
410
|
-
return void 0;
|
|
411
|
-
}
|
|
412
|
-
switch (this.data.length) {
|
|
413
|
-
case 20:
|
|
414
|
-
return "p2wpkh";
|
|
415
|
-
case 32:
|
|
416
|
-
return "p2wsh";
|
|
417
|
-
default:
|
|
418
|
-
return void 0;
|
|
419
|
-
}
|
|
420
|
-
}, "type")
|
|
421
|
-
},
|
|
422
|
-
{
|
|
423
|
-
key: "encode",
|
|
424
|
-
value: /* @__PURE__ */ __name(function encode3() {
|
|
425
|
-
var len = Math.ceil(this.data.length * 8 / 5);
|
|
426
|
-
var converted = (0, _bitConverter.createBitArray)(len + 1);
|
|
427
|
-
converted[0] = this.scriptVersion;
|
|
428
|
-
to5BitArray(this.data, converted.subarray(1));
|
|
429
|
-
var encoding = this.scriptVersion === 0 ? "bech32" : "bech32m";
|
|
430
|
-
return encode5BitArray(this.prefix, converted, encoding);
|
|
431
|
-
}, "encode")
|
|
432
|
-
}
|
|
433
|
-
], [
|
|
434
|
-
{
|
|
435
|
-
key: "decode",
|
|
436
|
-
value: (
|
|
437
|
-
/**
|
|
438
|
-
* Human-readable prefix. Equal to `'bc'` (for mainnet addresses)
|
|
439
|
-
* or `'tb'` (for testnet addresses).
|
|
440
|
-
*/
|
|
441
|
-
/**
|
|
442
|
-
* Script version. An integer between 0 and 16 (inclusive).
|
|
443
|
-
*/
|
|
444
|
-
/**
|
|
445
|
-
* Script data. A byte string with length 2 to 40 (inclusive).
|
|
446
|
-
*/
|
|
447
|
-
/**
|
|
448
|
-
* Decodes a Bitcoin address from a Bech32(m) string.
|
|
449
|
-
* As per BIP 350, the original encoding is expected for version 0 scripts, while
|
|
450
|
-
* other script versions expect the modified encoding.
|
|
451
|
-
*
|
|
452
|
-
* This method does not check whether the address is well-formed;
|
|
453
|
-
* use `type()` method on returned address to find that out.
|
|
454
|
-
*
|
|
455
|
-
* @param {string} message
|
|
456
|
-
* @returns {BitcoinAddress}
|
|
457
|
-
*/
|
|
458
|
-
/* @__PURE__ */ __name(function decode5(message) {
|
|
459
|
-
var _decodeTo5BitArray2 = decodeTo5BitArray(message), prefix = _decodeTo5BitArray2.prefix, data = _decodeTo5BitArray2.data, encoding = _decodeTo5BitArray2.encoding;
|
|
460
|
-
if (prefix !== "bc" && prefix !== "tb" && prefix !== "bcrt") {
|
|
461
|
-
throw new Error('Invalid human-readable prefix, "bc", "tb", or "bcrt" expected');
|
|
462
|
-
}
|
|
463
|
-
var scriptVersion = data[0];
|
|
464
|
-
if (scriptVersion === 0 && encoding !== "bech32") {
|
|
465
|
-
throw Error("Unexpected encoding ".concat(encoding, " used for version 0 script"));
|
|
466
|
-
}
|
|
467
|
-
if (scriptVersion > 0 && encoding !== "bech32m") {
|
|
468
|
-
throw Error("Unexpected encoding ".concat(encoding, " used for version ").concat(scriptVersion, " script"));
|
|
469
|
-
}
|
|
470
|
-
return new this(prefix, scriptVersion, from5BitArray(data.subarray(1)));
|
|
471
|
-
}, "decode")
|
|
472
|
-
)
|
|
473
|
-
}
|
|
474
|
-
]);
|
|
475
|
-
return BitcoinAddress3;
|
|
476
|
-
}();
|
|
477
|
-
exports.BitcoinAddress = BitcoinAddress2;
|
|
478
|
-
}
|
|
479
|
-
});
|
|
480
13
|
var _abi = [
|
|
481
14
|
{
|
|
482
15
|
inputs: [
|
|
@@ -548,10 +81,10 @@ var _abi = [
|
|
|
548
81
|
];
|
|
549
82
|
var _ERC20__factory = class _ERC20__factory {
|
|
550
83
|
static createInterface() {
|
|
551
|
-
return new
|
|
84
|
+
return new ethers.Interface(_abi);
|
|
552
85
|
}
|
|
553
86
|
static connect(address, runner) {
|
|
554
|
-
return new
|
|
87
|
+
return new ethers.Contract(address, _abi, runner);
|
|
555
88
|
}
|
|
556
89
|
};
|
|
557
90
|
__name(_ERC20__factory, "ERC20__factory");
|
|
@@ -1219,10 +752,10 @@ var _abi2 = [
|
|
|
1219
752
|
];
|
|
1220
753
|
var _StateChainGateway__factory = class _StateChainGateway__factory {
|
|
1221
754
|
static createInterface() {
|
|
1222
|
-
return new
|
|
755
|
+
return new ethers.Interface(_abi2);
|
|
1223
756
|
}
|
|
1224
757
|
static connect(address, runner) {
|
|
1225
|
-
return new
|
|
758
|
+
return new ethers.Contract(address, _abi2, runner);
|
|
1226
759
|
}
|
|
1227
760
|
};
|
|
1228
761
|
__name(_StateChainGateway__factory, "StateChainGateway__factory");
|
|
@@ -1360,14 +893,43 @@ var chainConstants = {
|
|
|
1360
893
|
blockTimeSeconds: 0.26
|
|
1361
894
|
}
|
|
1362
895
|
};
|
|
1363
|
-
function isValidAssetAndChain(
|
|
1364
|
-
const { asset
|
|
1365
|
-
if (!(
|
|
896
|
+
function isValidAssetAndChain(assetAndChain) {
|
|
897
|
+
const { asset, chain } = assetAndChain;
|
|
898
|
+
if (!(chain in Chains))
|
|
1366
899
|
return false;
|
|
1367
|
-
const validAssets = chainConstants[
|
|
1368
|
-
return validAssets.includes(
|
|
900
|
+
const validAssets = chainConstants[chain].assets;
|
|
901
|
+
return validAssets.includes(asset);
|
|
1369
902
|
}
|
|
1370
903
|
__name(isValidAssetAndChain, "isValidAssetAndChain");
|
|
904
|
+
function getInternalAsset(asset, assert2 = true) {
|
|
905
|
+
if (!isValidAssetAndChain(asset)) {
|
|
906
|
+
if (assert2) {
|
|
907
|
+
throw new Error(`invalid asset and chain combination: ${JSON.stringify(asset)}`);
|
|
908
|
+
}
|
|
909
|
+
return null;
|
|
910
|
+
}
|
|
911
|
+
const map = {
|
|
912
|
+
[Chains.Ethereum]: {
|
|
913
|
+
[Assets.USDC]: InternalAssets.Usdc,
|
|
914
|
+
[Assets.FLIP]: InternalAssets.Flip,
|
|
915
|
+
[Assets.ETH]: InternalAssets.Eth,
|
|
916
|
+
[Assets.USDT]: InternalAssets.Usdt
|
|
917
|
+
},
|
|
918
|
+
[Chains.Bitcoin]: {
|
|
919
|
+
[Assets.BTC]: InternalAssets.Btc
|
|
920
|
+
},
|
|
921
|
+
[Chains.Polkadot]: {
|
|
922
|
+
[Assets.DOT]: InternalAssets.Dot
|
|
923
|
+
},
|
|
924
|
+
[Chains.Arbitrum]: {
|
|
925
|
+
[Assets.USDC]: InternalAssets.ArbUsdc,
|
|
926
|
+
[Assets.ETH]: InternalAssets.ArbEth
|
|
927
|
+
}
|
|
928
|
+
};
|
|
929
|
+
const chain = map[asset.chain];
|
|
930
|
+
return chain[asset.asset];
|
|
931
|
+
}
|
|
932
|
+
__name(getInternalAsset, "getInternalAsset");
|
|
1371
933
|
|
|
1372
934
|
// ../shared/src/consts.ts
|
|
1373
935
|
({
|
|
@@ -1434,16 +996,16 @@ var extractOverrides = /* @__PURE__ */ __name((transactionOverrides) => {
|
|
|
1434
996
|
const { wait, ...ethersOverrides } = transactionOverrides;
|
|
1435
997
|
return ethersOverrides;
|
|
1436
998
|
}, "extractOverrides");
|
|
1437
|
-
function getTokenContractAddress(
|
|
1438
|
-
if (
|
|
999
|
+
function getTokenContractAddress(asset, network) {
|
|
1000
|
+
if (asset === InternalAssets.Flip)
|
|
1439
1001
|
return ADDRESSES[network].FLIP_CONTRACT_ADDRESS;
|
|
1440
|
-
if (
|
|
1002
|
+
if (asset === InternalAssets.Usdc)
|
|
1441
1003
|
return ADDRESSES[network].USDC_CONTRACT_ADDRESS;
|
|
1442
|
-
if (
|
|
1004
|
+
if (asset === InternalAssets.Usdt)
|
|
1443
1005
|
return ADDRESSES[network].USDT_CONTRACT_ADDRESS;
|
|
1444
|
-
if (
|
|
1006
|
+
if (asset === InternalAssets.ArbUsdc)
|
|
1445
1007
|
return ADDRESSES[network].ARBUSDC_CONTRACT_ADDRESS;
|
|
1446
|
-
throw new Error(`No contract address for ${
|
|
1008
|
+
throw new Error(`No contract address for ${asset} on ${network}`);
|
|
1447
1009
|
}
|
|
1448
1010
|
__name(getTokenContractAddress, "getTokenContractAddress");
|
|
1449
1011
|
var getStateChainGatewayContractAddress = /* @__PURE__ */ __name((network) => ADDRESSES[network].STATE_CHAIN_GATEWAY_ADDRESS, "getStateChainGatewayContractAddress");
|
|
@@ -1469,4345 +1031,59 @@ var getFlipBalance = /* @__PURE__ */ __name(async (network, signer) => {
|
|
|
1469
1031
|
const flip = ERC20__factory.connect(flipAddress, signer);
|
|
1470
1032
|
return flip.balanceOf(await signer.getAddress());
|
|
1471
1033
|
}, "getFlipBalance");
|
|
1472
|
-
|
|
1473
|
-
|
|
1474
|
-
|
|
1475
|
-
(function(util2) {
|
|
1476
|
-
util2.assertEqual = (val) => val;
|
|
1477
|
-
function assertIs(_arg) {
|
|
1478
|
-
}
|
|
1479
|
-
__name(assertIs, "assertIs");
|
|
1480
|
-
util2.assertIs = assertIs;
|
|
1481
|
-
function assertNever(_x) {
|
|
1482
|
-
throw new Error();
|
|
1483
|
-
}
|
|
1484
|
-
__name(assertNever, "assertNever");
|
|
1485
|
-
util2.assertNever = assertNever;
|
|
1486
|
-
util2.arrayToEnum = (items) => {
|
|
1487
|
-
const obj = {};
|
|
1488
|
-
for (const item of items) {
|
|
1489
|
-
obj[item] = item;
|
|
1490
|
-
}
|
|
1034
|
+
var camelCase = /* @__PURE__ */ __name((str) => str.replace(/_([a-z])/g, (_, char) => char.toUpperCase()), "camelCase");
|
|
1035
|
+
var camelCaseKeys = /* @__PURE__ */ __name((obj) => {
|
|
1036
|
+
if (typeof obj !== "object" || obj === null)
|
|
1491
1037
|
return obj;
|
|
1492
|
-
|
|
1493
|
-
|
|
1494
|
-
|
|
1495
|
-
|
|
1496
|
-
|
|
1497
|
-
|
|
1498
|
-
|
|
1499
|
-
|
|
1500
|
-
|
|
1501
|
-
|
|
1502
|
-
|
|
1503
|
-
|
|
1504
|
-
|
|
1505
|
-
|
|
1506
|
-
|
|
1507
|
-
|
|
1508
|
-
|
|
1509
|
-
|
|
1510
|
-
|
|
1511
|
-
|
|
1512
|
-
|
|
1513
|
-
|
|
1514
|
-
|
|
1515
|
-
|
|
1516
|
-
|
|
1517
|
-
|
|
1518
|
-
|
|
1519
|
-
|
|
1520
|
-
|
|
1521
|
-
|
|
1522
|
-
|
|
1523
|
-
|
|
1524
|
-
|
|
1525
|
-
|
|
1526
|
-
|
|
1527
|
-
|
|
1528
|
-
|
|
1529
|
-
|
|
1530
|
-
|
|
1531
|
-
|
|
1532
|
-
return
|
|
1533
|
-
|
|
1534
|
-
|
|
1535
|
-
|
|
1536
|
-
(function(objectUtil2) {
|
|
1537
|
-
objectUtil2.mergeShapes = (first, second) => {
|
|
1538
|
-
return {
|
|
1539
|
-
...first,
|
|
1540
|
-
...second
|
|
1541
|
-
// second overwrites first
|
|
1542
|
-
};
|
|
1543
|
-
};
|
|
1544
|
-
})(objectUtil || (objectUtil = {}));
|
|
1545
|
-
var ZodParsedType = util.arrayToEnum([
|
|
1546
|
-
"string",
|
|
1547
|
-
"nan",
|
|
1548
|
-
"number",
|
|
1549
|
-
"integer",
|
|
1550
|
-
"float",
|
|
1551
|
-
"boolean",
|
|
1552
|
-
"date",
|
|
1553
|
-
"bigint",
|
|
1554
|
-
"symbol",
|
|
1555
|
-
"function",
|
|
1556
|
-
"undefined",
|
|
1557
|
-
"null",
|
|
1558
|
-
"array",
|
|
1559
|
-
"object",
|
|
1560
|
-
"unknown",
|
|
1561
|
-
"promise",
|
|
1562
|
-
"void",
|
|
1563
|
-
"never",
|
|
1564
|
-
"map",
|
|
1565
|
-
"set"
|
|
1566
|
-
]);
|
|
1567
|
-
var getParsedType = /* @__PURE__ */ __name((data) => {
|
|
1568
|
-
const t = typeof data;
|
|
1569
|
-
switch (t) {
|
|
1570
|
-
case "undefined":
|
|
1571
|
-
return ZodParsedType.undefined;
|
|
1572
|
-
case "string":
|
|
1573
|
-
return ZodParsedType.string;
|
|
1574
|
-
case "number":
|
|
1575
|
-
return isNaN(data) ? ZodParsedType.nan : ZodParsedType.number;
|
|
1576
|
-
case "boolean":
|
|
1577
|
-
return ZodParsedType.boolean;
|
|
1578
|
-
case "function":
|
|
1579
|
-
return ZodParsedType.function;
|
|
1580
|
-
case "bigint":
|
|
1581
|
-
return ZodParsedType.bigint;
|
|
1582
|
-
case "symbol":
|
|
1583
|
-
return ZodParsedType.symbol;
|
|
1584
|
-
case "object":
|
|
1585
|
-
if (Array.isArray(data)) {
|
|
1586
|
-
return ZodParsedType.array;
|
|
1587
|
-
}
|
|
1588
|
-
if (data === null) {
|
|
1589
|
-
return ZodParsedType.null;
|
|
1590
|
-
}
|
|
1591
|
-
if (data.then && typeof data.then === "function" && data.catch && typeof data.catch === "function") {
|
|
1592
|
-
return ZodParsedType.promise;
|
|
1593
|
-
}
|
|
1594
|
-
if (typeof Map !== "undefined" && data instanceof Map) {
|
|
1595
|
-
return ZodParsedType.map;
|
|
1596
|
-
}
|
|
1597
|
-
if (typeof Set !== "undefined" && data instanceof Set) {
|
|
1598
|
-
return ZodParsedType.set;
|
|
1599
|
-
}
|
|
1600
|
-
if (typeof Date !== "undefined" && data instanceof Date) {
|
|
1601
|
-
return ZodParsedType.date;
|
|
1602
|
-
}
|
|
1603
|
-
return ZodParsedType.object;
|
|
1604
|
-
default:
|
|
1605
|
-
return ZodParsedType.unknown;
|
|
1606
|
-
}
|
|
1607
|
-
}, "getParsedType");
|
|
1608
|
-
var ZodIssueCode = util.arrayToEnum([
|
|
1609
|
-
"invalid_type",
|
|
1610
|
-
"invalid_literal",
|
|
1611
|
-
"custom",
|
|
1612
|
-
"invalid_union",
|
|
1613
|
-
"invalid_union_discriminator",
|
|
1614
|
-
"invalid_enum_value",
|
|
1615
|
-
"unrecognized_keys",
|
|
1616
|
-
"invalid_arguments",
|
|
1617
|
-
"invalid_return_type",
|
|
1618
|
-
"invalid_date",
|
|
1619
|
-
"invalid_string",
|
|
1620
|
-
"too_small",
|
|
1621
|
-
"too_big",
|
|
1622
|
-
"invalid_intersection_types",
|
|
1623
|
-
"not_multiple_of",
|
|
1624
|
-
"not_finite"
|
|
1625
|
-
]);
|
|
1626
|
-
var quotelessJson = /* @__PURE__ */ __name((obj) => {
|
|
1627
|
-
const json = JSON.stringify(obj, null, 2);
|
|
1628
|
-
return json.replace(/"([^"]+)":/g, "$1:");
|
|
1629
|
-
}, "quotelessJson");
|
|
1630
|
-
var _ZodError = class _ZodError extends Error {
|
|
1631
|
-
constructor(issues) {
|
|
1632
|
-
super();
|
|
1633
|
-
this.issues = [];
|
|
1634
|
-
this.addIssue = (sub) => {
|
|
1635
|
-
this.issues = [...this.issues, sub];
|
|
1636
|
-
};
|
|
1637
|
-
this.addIssues = (subs = []) => {
|
|
1638
|
-
this.issues = [...this.issues, ...subs];
|
|
1639
|
-
};
|
|
1640
|
-
const actualProto = new.target.prototype;
|
|
1641
|
-
if (Object.setPrototypeOf) {
|
|
1642
|
-
Object.setPrototypeOf(this, actualProto);
|
|
1643
|
-
} else {
|
|
1644
|
-
this.__proto__ = actualProto;
|
|
1645
|
-
}
|
|
1646
|
-
this.name = "ZodError";
|
|
1647
|
-
this.issues = issues;
|
|
1648
|
-
}
|
|
1649
|
-
get errors() {
|
|
1650
|
-
return this.issues;
|
|
1651
|
-
}
|
|
1652
|
-
format(_mapper) {
|
|
1653
|
-
const mapper = _mapper || function(issue) {
|
|
1654
|
-
return issue.message;
|
|
1655
|
-
};
|
|
1656
|
-
const fieldErrors = { _errors: [] };
|
|
1657
|
-
const processError = /* @__PURE__ */ __name((error) => {
|
|
1658
|
-
for (const issue of error.issues) {
|
|
1659
|
-
if (issue.code === "invalid_union") {
|
|
1660
|
-
issue.unionErrors.map(processError);
|
|
1661
|
-
} else if (issue.code === "invalid_return_type") {
|
|
1662
|
-
processError(issue.returnTypeError);
|
|
1663
|
-
} else if (issue.code === "invalid_arguments") {
|
|
1664
|
-
processError(issue.argumentsError);
|
|
1665
|
-
} else if (issue.path.length === 0) {
|
|
1666
|
-
fieldErrors._errors.push(mapper(issue));
|
|
1667
|
-
} else {
|
|
1668
|
-
let curr = fieldErrors;
|
|
1669
|
-
let i = 0;
|
|
1670
|
-
while (i < issue.path.length) {
|
|
1671
|
-
const el = issue.path[i];
|
|
1672
|
-
const terminal = i === issue.path.length - 1;
|
|
1673
|
-
if (!terminal) {
|
|
1674
|
-
curr[el] = curr[el] || { _errors: [] };
|
|
1675
|
-
} else {
|
|
1676
|
-
curr[el] = curr[el] || { _errors: [] };
|
|
1677
|
-
curr[el]._errors.push(mapper(issue));
|
|
1678
|
-
}
|
|
1679
|
-
curr = curr[el];
|
|
1680
|
-
i++;
|
|
1681
|
-
}
|
|
1682
|
-
}
|
|
1683
|
-
}
|
|
1684
|
-
}, "processError");
|
|
1685
|
-
processError(this);
|
|
1686
|
-
return fieldErrors;
|
|
1687
|
-
}
|
|
1688
|
-
static assert(value) {
|
|
1689
|
-
if (!(value instanceof _ZodError)) {
|
|
1690
|
-
throw new Error(`Not a ZodError: ${value}`);
|
|
1691
|
-
}
|
|
1692
|
-
}
|
|
1693
|
-
toString() {
|
|
1694
|
-
return this.message;
|
|
1695
|
-
}
|
|
1696
|
-
get message() {
|
|
1697
|
-
return JSON.stringify(this.issues, util.jsonStringifyReplacer, 2);
|
|
1698
|
-
}
|
|
1699
|
-
get isEmpty() {
|
|
1700
|
-
return this.issues.length === 0;
|
|
1701
|
-
}
|
|
1702
|
-
flatten(mapper = (issue) => issue.message) {
|
|
1703
|
-
const fieldErrors = {};
|
|
1704
|
-
const formErrors = [];
|
|
1705
|
-
for (const sub of this.issues) {
|
|
1706
|
-
if (sub.path.length > 0) {
|
|
1707
|
-
fieldErrors[sub.path[0]] = fieldErrors[sub.path[0]] || [];
|
|
1708
|
-
fieldErrors[sub.path[0]].push(mapper(sub));
|
|
1709
|
-
} else {
|
|
1710
|
-
formErrors.push(mapper(sub));
|
|
1711
|
-
}
|
|
1712
|
-
}
|
|
1713
|
-
return { formErrors, fieldErrors };
|
|
1714
|
-
}
|
|
1715
|
-
get formErrors() {
|
|
1716
|
-
return this.flatten();
|
|
1717
|
-
}
|
|
1718
|
-
};
|
|
1719
|
-
__name(_ZodError, "ZodError");
|
|
1720
|
-
var ZodError = _ZodError;
|
|
1721
|
-
ZodError.create = (issues) => {
|
|
1722
|
-
const error = new ZodError(issues);
|
|
1723
|
-
return error;
|
|
1724
|
-
};
|
|
1725
|
-
var errorMap = /* @__PURE__ */ __name((issue, _ctx) => {
|
|
1726
|
-
let message;
|
|
1727
|
-
switch (issue.code) {
|
|
1728
|
-
case ZodIssueCode.invalid_type:
|
|
1729
|
-
if (issue.received === ZodParsedType.undefined) {
|
|
1730
|
-
message = "Required";
|
|
1731
|
-
} else {
|
|
1732
|
-
message = `Expected ${issue.expected}, received ${issue.received}`;
|
|
1733
|
-
}
|
|
1734
|
-
break;
|
|
1735
|
-
case ZodIssueCode.invalid_literal:
|
|
1736
|
-
message = `Invalid literal value, expected ${JSON.stringify(issue.expected, util.jsonStringifyReplacer)}`;
|
|
1737
|
-
break;
|
|
1738
|
-
case ZodIssueCode.unrecognized_keys:
|
|
1739
|
-
message = `Unrecognized key(s) in object: ${util.joinValues(issue.keys, ", ")}`;
|
|
1740
|
-
break;
|
|
1741
|
-
case ZodIssueCode.invalid_union:
|
|
1742
|
-
message = `Invalid input`;
|
|
1743
|
-
break;
|
|
1744
|
-
case ZodIssueCode.invalid_union_discriminator:
|
|
1745
|
-
message = `Invalid discriminator value. Expected ${util.joinValues(issue.options)}`;
|
|
1746
|
-
break;
|
|
1747
|
-
case ZodIssueCode.invalid_enum_value:
|
|
1748
|
-
message = `Invalid enum value. Expected ${util.joinValues(issue.options)}, received '${issue.received}'`;
|
|
1749
|
-
break;
|
|
1750
|
-
case ZodIssueCode.invalid_arguments:
|
|
1751
|
-
message = `Invalid function arguments`;
|
|
1752
|
-
break;
|
|
1753
|
-
case ZodIssueCode.invalid_return_type:
|
|
1754
|
-
message = `Invalid function return type`;
|
|
1755
|
-
break;
|
|
1756
|
-
case ZodIssueCode.invalid_date:
|
|
1757
|
-
message = `Invalid date`;
|
|
1758
|
-
break;
|
|
1759
|
-
case ZodIssueCode.invalid_string:
|
|
1760
|
-
if (typeof issue.validation === "object") {
|
|
1761
|
-
if ("includes" in issue.validation) {
|
|
1762
|
-
message = `Invalid input: must include "${issue.validation.includes}"`;
|
|
1763
|
-
if (typeof issue.validation.position === "number") {
|
|
1764
|
-
message = `${message} at one or more positions greater than or equal to ${issue.validation.position}`;
|
|
1765
|
-
}
|
|
1766
|
-
} else if ("startsWith" in issue.validation) {
|
|
1767
|
-
message = `Invalid input: must start with "${issue.validation.startsWith}"`;
|
|
1768
|
-
} else if ("endsWith" in issue.validation) {
|
|
1769
|
-
message = `Invalid input: must end with "${issue.validation.endsWith}"`;
|
|
1770
|
-
} else {
|
|
1771
|
-
util.assertNever(issue.validation);
|
|
1772
|
-
}
|
|
1773
|
-
} else if (issue.validation !== "regex") {
|
|
1774
|
-
message = `Invalid ${issue.validation}`;
|
|
1775
|
-
} else {
|
|
1776
|
-
message = "Invalid";
|
|
1777
|
-
}
|
|
1778
|
-
break;
|
|
1779
|
-
case ZodIssueCode.too_small:
|
|
1780
|
-
if (issue.type === "array")
|
|
1781
|
-
message = `Array must contain ${issue.exact ? "exactly" : issue.inclusive ? `at least` : `more than`} ${issue.minimum} element(s)`;
|
|
1782
|
-
else if (issue.type === "string")
|
|
1783
|
-
message = `String must contain ${issue.exact ? "exactly" : issue.inclusive ? `at least` : `over`} ${issue.minimum} character(s)`;
|
|
1784
|
-
else if (issue.type === "number")
|
|
1785
|
-
message = `Number must be ${issue.exact ? `exactly equal to ` : issue.inclusive ? `greater than or equal to ` : `greater than `}${issue.minimum}`;
|
|
1786
|
-
else if (issue.type === "date")
|
|
1787
|
-
message = `Date must be ${issue.exact ? `exactly equal to ` : issue.inclusive ? `greater than or equal to ` : `greater than `}${new Date(Number(issue.minimum))}`;
|
|
1788
|
-
else
|
|
1789
|
-
message = "Invalid input";
|
|
1790
|
-
break;
|
|
1791
|
-
case ZodIssueCode.too_big:
|
|
1792
|
-
if (issue.type === "array")
|
|
1793
|
-
message = `Array must contain ${issue.exact ? `exactly` : issue.inclusive ? `at most` : `less than`} ${issue.maximum} element(s)`;
|
|
1794
|
-
else if (issue.type === "string")
|
|
1795
|
-
message = `String must contain ${issue.exact ? `exactly` : issue.inclusive ? `at most` : `under`} ${issue.maximum} character(s)`;
|
|
1796
|
-
else if (issue.type === "number")
|
|
1797
|
-
message = `Number must be ${issue.exact ? `exactly` : issue.inclusive ? `less than or equal to` : `less than`} ${issue.maximum}`;
|
|
1798
|
-
else if (issue.type === "bigint")
|
|
1799
|
-
message = `BigInt must be ${issue.exact ? `exactly` : issue.inclusive ? `less than or equal to` : `less than`} ${issue.maximum}`;
|
|
1800
|
-
else if (issue.type === "date")
|
|
1801
|
-
message = `Date must be ${issue.exact ? `exactly` : issue.inclusive ? `smaller than or equal to` : `smaller than`} ${new Date(Number(issue.maximum))}`;
|
|
1802
|
-
else
|
|
1803
|
-
message = "Invalid input";
|
|
1804
|
-
break;
|
|
1805
|
-
case ZodIssueCode.custom:
|
|
1806
|
-
message = `Invalid input`;
|
|
1807
|
-
break;
|
|
1808
|
-
case ZodIssueCode.invalid_intersection_types:
|
|
1809
|
-
message = `Intersection results could not be merged`;
|
|
1810
|
-
break;
|
|
1811
|
-
case ZodIssueCode.not_multiple_of:
|
|
1812
|
-
message = `Number must be a multiple of ${issue.multipleOf}`;
|
|
1813
|
-
break;
|
|
1814
|
-
case ZodIssueCode.not_finite:
|
|
1815
|
-
message = "Number must be finite";
|
|
1816
|
-
break;
|
|
1817
|
-
default:
|
|
1818
|
-
message = _ctx.defaultError;
|
|
1819
|
-
util.assertNever(issue);
|
|
1820
|
-
}
|
|
1821
|
-
return { message };
|
|
1822
|
-
}, "errorMap");
|
|
1823
|
-
var overrideErrorMap = errorMap;
|
|
1824
|
-
function setErrorMap(map) {
|
|
1825
|
-
overrideErrorMap = map;
|
|
1826
|
-
}
|
|
1827
|
-
__name(setErrorMap, "setErrorMap");
|
|
1828
|
-
function getErrorMap() {
|
|
1829
|
-
return overrideErrorMap;
|
|
1830
|
-
}
|
|
1831
|
-
__name(getErrorMap, "getErrorMap");
|
|
1832
|
-
var makeIssue = /* @__PURE__ */ __name((params) => {
|
|
1833
|
-
const { data, path, errorMaps, issueData } = params;
|
|
1834
|
-
const fullPath = [...path, ...issueData.path || []];
|
|
1835
|
-
const fullIssue = {
|
|
1836
|
-
...issueData,
|
|
1837
|
-
path: fullPath
|
|
1838
|
-
};
|
|
1839
|
-
if (issueData.message !== void 0) {
|
|
1840
|
-
return {
|
|
1841
|
-
...issueData,
|
|
1842
|
-
path: fullPath,
|
|
1843
|
-
message: issueData.message
|
|
1844
|
-
};
|
|
1845
|
-
}
|
|
1846
|
-
let errorMessage = "";
|
|
1847
|
-
const maps = errorMaps.filter((m) => !!m).slice().reverse();
|
|
1848
|
-
for (const map of maps) {
|
|
1849
|
-
errorMessage = map(fullIssue, { data, defaultError: errorMessage }).message;
|
|
1850
|
-
}
|
|
1851
|
-
return {
|
|
1852
|
-
...issueData,
|
|
1853
|
-
path: fullPath,
|
|
1854
|
-
message: errorMessage
|
|
1855
|
-
};
|
|
1856
|
-
}, "makeIssue");
|
|
1857
|
-
var EMPTY_PATH = [];
|
|
1858
|
-
function addIssueToContext(ctx, issueData) {
|
|
1859
|
-
const overrideMap = getErrorMap();
|
|
1860
|
-
const issue = makeIssue({
|
|
1861
|
-
issueData,
|
|
1862
|
-
data: ctx.data,
|
|
1863
|
-
path: ctx.path,
|
|
1864
|
-
errorMaps: [
|
|
1865
|
-
ctx.common.contextualErrorMap,
|
|
1866
|
-
ctx.schemaErrorMap,
|
|
1867
|
-
overrideMap,
|
|
1868
|
-
overrideMap === errorMap ? void 0 : errorMap
|
|
1869
|
-
// then global default map
|
|
1870
|
-
].filter((x) => !!x)
|
|
1871
|
-
});
|
|
1872
|
-
ctx.common.issues.push(issue);
|
|
1873
|
-
}
|
|
1874
|
-
__name(addIssueToContext, "addIssueToContext");
|
|
1875
|
-
var _ParseStatus = class _ParseStatus {
|
|
1876
|
-
constructor() {
|
|
1877
|
-
this.value = "valid";
|
|
1878
|
-
}
|
|
1879
|
-
dirty() {
|
|
1880
|
-
if (this.value === "valid")
|
|
1881
|
-
this.value = "dirty";
|
|
1882
|
-
}
|
|
1883
|
-
abort() {
|
|
1884
|
-
if (this.value !== "aborted")
|
|
1885
|
-
this.value = "aborted";
|
|
1886
|
-
}
|
|
1887
|
-
static mergeArray(status, results) {
|
|
1888
|
-
const arrayValue = [];
|
|
1889
|
-
for (const s of results) {
|
|
1890
|
-
if (s.status === "aborted")
|
|
1891
|
-
return INVALID;
|
|
1892
|
-
if (s.status === "dirty")
|
|
1893
|
-
status.dirty();
|
|
1894
|
-
arrayValue.push(s.value);
|
|
1895
|
-
}
|
|
1896
|
-
return { status: status.value, value: arrayValue };
|
|
1897
|
-
}
|
|
1898
|
-
static async mergeObjectAsync(status, pairs) {
|
|
1899
|
-
const syncPairs = [];
|
|
1900
|
-
for (const pair of pairs) {
|
|
1901
|
-
const key = await pair.key;
|
|
1902
|
-
const value = await pair.value;
|
|
1903
|
-
syncPairs.push({
|
|
1904
|
-
key,
|
|
1905
|
-
value
|
|
1906
|
-
});
|
|
1907
|
-
}
|
|
1908
|
-
return _ParseStatus.mergeObjectSync(status, syncPairs);
|
|
1909
|
-
}
|
|
1910
|
-
static mergeObjectSync(status, pairs) {
|
|
1911
|
-
const finalObject = {};
|
|
1912
|
-
for (const pair of pairs) {
|
|
1913
|
-
const { key, value } = pair;
|
|
1914
|
-
if (key.status === "aborted")
|
|
1915
|
-
return INVALID;
|
|
1916
|
-
if (value.status === "aborted")
|
|
1917
|
-
return INVALID;
|
|
1918
|
-
if (key.status === "dirty")
|
|
1919
|
-
status.dirty();
|
|
1920
|
-
if (value.status === "dirty")
|
|
1921
|
-
status.dirty();
|
|
1922
|
-
if (key.value !== "__proto__" && (typeof value.value !== "undefined" || pair.alwaysSet)) {
|
|
1923
|
-
finalObject[key.value] = value.value;
|
|
1924
|
-
}
|
|
1925
|
-
}
|
|
1926
|
-
return { status: status.value, value: finalObject };
|
|
1927
|
-
}
|
|
1928
|
-
};
|
|
1929
|
-
__name(_ParseStatus, "ParseStatus");
|
|
1930
|
-
var ParseStatus = _ParseStatus;
|
|
1931
|
-
var INVALID = Object.freeze({
|
|
1932
|
-
status: "aborted"
|
|
1933
|
-
});
|
|
1934
|
-
var DIRTY = /* @__PURE__ */ __name((value) => ({ status: "dirty", value }), "DIRTY");
|
|
1935
|
-
var OK = /* @__PURE__ */ __name((value) => ({ status: "valid", value }), "OK");
|
|
1936
|
-
var isAborted = /* @__PURE__ */ __name((x) => x.status === "aborted", "isAborted");
|
|
1937
|
-
var isDirty = /* @__PURE__ */ __name((x) => x.status === "dirty", "isDirty");
|
|
1938
|
-
var isValid = /* @__PURE__ */ __name((x) => x.status === "valid", "isValid");
|
|
1939
|
-
var isAsync = /* @__PURE__ */ __name((x) => typeof Promise !== "undefined" && x instanceof Promise, "isAsync");
|
|
1940
|
-
function __classPrivateFieldGet(receiver, state, kind, f) {
|
|
1941
|
-
if (kind === "a" && !f)
|
|
1942
|
-
throw new TypeError("Private accessor was defined without a getter");
|
|
1943
|
-
if (typeof state === "function" ? receiver !== state || !f : !state.has(receiver))
|
|
1944
|
-
throw new TypeError("Cannot read private member from an object whose class did not declare it");
|
|
1945
|
-
return kind === "m" ? f : kind === "a" ? f.call(receiver) : f ? f.value : state.get(receiver);
|
|
1946
|
-
}
|
|
1947
|
-
__name(__classPrivateFieldGet, "__classPrivateFieldGet");
|
|
1948
|
-
function __classPrivateFieldSet(receiver, state, value, kind, f) {
|
|
1949
|
-
if (kind === "m")
|
|
1950
|
-
throw new TypeError("Private method is not writable");
|
|
1951
|
-
if (kind === "a" && !f)
|
|
1952
|
-
throw new TypeError("Private accessor was defined without a setter");
|
|
1953
|
-
if (typeof state === "function" ? receiver !== state || !f : !state.has(receiver))
|
|
1954
|
-
throw new TypeError("Cannot write private member to an object whose class did not declare it");
|
|
1955
|
-
return kind === "a" ? f.call(receiver, value) : f ? f.value = value : state.set(receiver, value), value;
|
|
1956
|
-
}
|
|
1957
|
-
__name(__classPrivateFieldSet, "__classPrivateFieldSet");
|
|
1958
|
-
var errorUtil;
|
|
1959
|
-
(function(errorUtil2) {
|
|
1960
|
-
errorUtil2.errToObj = (message) => typeof message === "string" ? { message } : message || {};
|
|
1961
|
-
errorUtil2.toString = (message) => typeof message === "string" ? message : message === null || message === void 0 ? void 0 : message.message;
|
|
1962
|
-
})(errorUtil || (errorUtil = {}));
|
|
1963
|
-
var _ZodEnum_cache;
|
|
1964
|
-
var _ZodNativeEnum_cache;
|
|
1965
|
-
var _ParseInputLazyPath = class _ParseInputLazyPath {
|
|
1966
|
-
constructor(parent, value, path, key) {
|
|
1967
|
-
this._cachedPath = [];
|
|
1968
|
-
this.parent = parent;
|
|
1969
|
-
this.data = value;
|
|
1970
|
-
this._path = path;
|
|
1971
|
-
this._key = key;
|
|
1972
|
-
}
|
|
1973
|
-
get path() {
|
|
1974
|
-
if (!this._cachedPath.length) {
|
|
1975
|
-
if (this._key instanceof Array) {
|
|
1976
|
-
this._cachedPath.push(...this._path, ...this._key);
|
|
1977
|
-
} else {
|
|
1978
|
-
this._cachedPath.push(...this._path, this._key);
|
|
1979
|
-
}
|
|
1980
|
-
}
|
|
1981
|
-
return this._cachedPath;
|
|
1982
|
-
}
|
|
1983
|
-
};
|
|
1984
|
-
__name(_ParseInputLazyPath, "ParseInputLazyPath");
|
|
1985
|
-
var ParseInputLazyPath = _ParseInputLazyPath;
|
|
1986
|
-
var handleResult = /* @__PURE__ */ __name((ctx, result) => {
|
|
1987
|
-
if (isValid(result)) {
|
|
1988
|
-
return { success: true, data: result.value };
|
|
1989
|
-
} else {
|
|
1990
|
-
if (!ctx.common.issues.length) {
|
|
1991
|
-
throw new Error("Validation failed but no issues detected.");
|
|
1992
|
-
}
|
|
1993
|
-
return {
|
|
1994
|
-
success: false,
|
|
1995
|
-
get error() {
|
|
1996
|
-
if (this._error)
|
|
1997
|
-
return this._error;
|
|
1998
|
-
const error = new ZodError(ctx.common.issues);
|
|
1999
|
-
this._error = error;
|
|
2000
|
-
return this._error;
|
|
2001
|
-
}
|
|
2002
|
-
};
|
|
2003
|
-
}
|
|
2004
|
-
}, "handleResult");
|
|
2005
|
-
function processCreateParams(params) {
|
|
2006
|
-
if (!params)
|
|
2007
|
-
return {};
|
|
2008
|
-
const { errorMap: errorMap3, invalid_type_error, required_error, description } = params;
|
|
2009
|
-
if (errorMap3 && (invalid_type_error || required_error)) {
|
|
2010
|
-
throw new Error(`Can't use "invalid_type_error" or "required_error" in conjunction with custom error map.`);
|
|
2011
|
-
}
|
|
2012
|
-
if (errorMap3)
|
|
2013
|
-
return { errorMap: errorMap3, description };
|
|
2014
|
-
const customMap = /* @__PURE__ */ __name((iss, ctx) => {
|
|
2015
|
-
var _a, _b;
|
|
2016
|
-
const { message } = params;
|
|
2017
|
-
if (iss.code === "invalid_enum_value") {
|
|
2018
|
-
return { message: message !== null && message !== void 0 ? message : ctx.defaultError };
|
|
2019
|
-
}
|
|
2020
|
-
if (typeof ctx.data === "undefined") {
|
|
2021
|
-
return { message: (_a = message !== null && message !== void 0 ? message : required_error) !== null && _a !== void 0 ? _a : ctx.defaultError };
|
|
2022
|
-
}
|
|
2023
|
-
if (iss.code !== "invalid_type")
|
|
2024
|
-
return { message: ctx.defaultError };
|
|
2025
|
-
return { message: (_b = message !== null && message !== void 0 ? message : invalid_type_error) !== null && _b !== void 0 ? _b : ctx.defaultError };
|
|
2026
|
-
}, "customMap");
|
|
2027
|
-
return { errorMap: customMap, description };
|
|
2028
|
-
}
|
|
2029
|
-
__name(processCreateParams, "processCreateParams");
|
|
2030
|
-
var _ZodType = class _ZodType {
|
|
2031
|
-
constructor(def) {
|
|
2032
|
-
this.spa = this.safeParseAsync;
|
|
2033
|
-
this._def = def;
|
|
2034
|
-
this.parse = this.parse.bind(this);
|
|
2035
|
-
this.safeParse = this.safeParse.bind(this);
|
|
2036
|
-
this.parseAsync = this.parseAsync.bind(this);
|
|
2037
|
-
this.safeParseAsync = this.safeParseAsync.bind(this);
|
|
2038
|
-
this.spa = this.spa.bind(this);
|
|
2039
|
-
this.refine = this.refine.bind(this);
|
|
2040
|
-
this.refinement = this.refinement.bind(this);
|
|
2041
|
-
this.superRefine = this.superRefine.bind(this);
|
|
2042
|
-
this.optional = this.optional.bind(this);
|
|
2043
|
-
this.nullable = this.nullable.bind(this);
|
|
2044
|
-
this.nullish = this.nullish.bind(this);
|
|
2045
|
-
this.array = this.array.bind(this);
|
|
2046
|
-
this.promise = this.promise.bind(this);
|
|
2047
|
-
this.or = this.or.bind(this);
|
|
2048
|
-
this.and = this.and.bind(this);
|
|
2049
|
-
this.transform = this.transform.bind(this);
|
|
2050
|
-
this.brand = this.brand.bind(this);
|
|
2051
|
-
this.default = this.default.bind(this);
|
|
2052
|
-
this.catch = this.catch.bind(this);
|
|
2053
|
-
this.describe = this.describe.bind(this);
|
|
2054
|
-
this.pipe = this.pipe.bind(this);
|
|
2055
|
-
this.readonly = this.readonly.bind(this);
|
|
2056
|
-
this.isNullable = this.isNullable.bind(this);
|
|
2057
|
-
this.isOptional = this.isOptional.bind(this);
|
|
2058
|
-
}
|
|
2059
|
-
get description() {
|
|
2060
|
-
return this._def.description;
|
|
2061
|
-
}
|
|
2062
|
-
_getType(input) {
|
|
2063
|
-
return getParsedType(input.data);
|
|
2064
|
-
}
|
|
2065
|
-
_getOrReturnCtx(input, ctx) {
|
|
2066
|
-
return ctx || {
|
|
2067
|
-
common: input.parent.common,
|
|
2068
|
-
data: input.data,
|
|
2069
|
-
parsedType: getParsedType(input.data),
|
|
2070
|
-
schemaErrorMap: this._def.errorMap,
|
|
2071
|
-
path: input.path,
|
|
2072
|
-
parent: input.parent
|
|
2073
|
-
};
|
|
2074
|
-
}
|
|
2075
|
-
_processInputParams(input) {
|
|
2076
|
-
return {
|
|
2077
|
-
status: new ParseStatus(),
|
|
2078
|
-
ctx: {
|
|
2079
|
-
common: input.parent.common,
|
|
2080
|
-
data: input.data,
|
|
2081
|
-
parsedType: getParsedType(input.data),
|
|
2082
|
-
schemaErrorMap: this._def.errorMap,
|
|
2083
|
-
path: input.path,
|
|
2084
|
-
parent: input.parent
|
|
2085
|
-
}
|
|
2086
|
-
};
|
|
2087
|
-
}
|
|
2088
|
-
_parseSync(input) {
|
|
2089
|
-
const result = this._parse(input);
|
|
2090
|
-
if (isAsync(result)) {
|
|
2091
|
-
throw new Error("Synchronous parse encountered promise.");
|
|
2092
|
-
}
|
|
2093
|
-
return result;
|
|
2094
|
-
}
|
|
2095
|
-
_parseAsync(input) {
|
|
2096
|
-
const result = this._parse(input);
|
|
2097
|
-
return Promise.resolve(result);
|
|
2098
|
-
}
|
|
2099
|
-
parse(data, params) {
|
|
2100
|
-
const result = this.safeParse(data, params);
|
|
2101
|
-
if (result.success)
|
|
2102
|
-
return result.data;
|
|
2103
|
-
throw result.error;
|
|
2104
|
-
}
|
|
2105
|
-
safeParse(data, params) {
|
|
2106
|
-
var _a;
|
|
2107
|
-
const ctx = {
|
|
2108
|
-
common: {
|
|
2109
|
-
issues: [],
|
|
2110
|
-
async: (_a = params === null || params === void 0 ? void 0 : params.async) !== null && _a !== void 0 ? _a : false,
|
|
2111
|
-
contextualErrorMap: params === null || params === void 0 ? void 0 : params.errorMap
|
|
2112
|
-
},
|
|
2113
|
-
path: (params === null || params === void 0 ? void 0 : params.path) || [],
|
|
2114
|
-
schemaErrorMap: this._def.errorMap,
|
|
2115
|
-
parent: null,
|
|
2116
|
-
data,
|
|
2117
|
-
parsedType: getParsedType(data)
|
|
2118
|
-
};
|
|
2119
|
-
const result = this._parseSync({ data, path: ctx.path, parent: ctx });
|
|
2120
|
-
return handleResult(ctx, result);
|
|
2121
|
-
}
|
|
2122
|
-
async parseAsync(data, params) {
|
|
2123
|
-
const result = await this.safeParseAsync(data, params);
|
|
2124
|
-
if (result.success)
|
|
2125
|
-
return result.data;
|
|
2126
|
-
throw result.error;
|
|
2127
|
-
}
|
|
2128
|
-
async safeParseAsync(data, params) {
|
|
2129
|
-
const ctx = {
|
|
2130
|
-
common: {
|
|
2131
|
-
issues: [],
|
|
2132
|
-
contextualErrorMap: params === null || params === void 0 ? void 0 : params.errorMap,
|
|
2133
|
-
async: true
|
|
2134
|
-
},
|
|
2135
|
-
path: (params === null || params === void 0 ? void 0 : params.path) || [],
|
|
2136
|
-
schemaErrorMap: this._def.errorMap,
|
|
2137
|
-
parent: null,
|
|
2138
|
-
data,
|
|
2139
|
-
parsedType: getParsedType(data)
|
|
2140
|
-
};
|
|
2141
|
-
const maybeAsyncResult = this._parse({ data, path: ctx.path, parent: ctx });
|
|
2142
|
-
const result = await (isAsync(maybeAsyncResult) ? maybeAsyncResult : Promise.resolve(maybeAsyncResult));
|
|
2143
|
-
return handleResult(ctx, result);
|
|
2144
|
-
}
|
|
2145
|
-
refine(check, message) {
|
|
2146
|
-
const getIssueProperties = /* @__PURE__ */ __name((val) => {
|
|
2147
|
-
if (typeof message === "string" || typeof message === "undefined") {
|
|
2148
|
-
return { message };
|
|
2149
|
-
} else if (typeof message === "function") {
|
|
2150
|
-
return message(val);
|
|
2151
|
-
} else {
|
|
2152
|
-
return message;
|
|
2153
|
-
}
|
|
2154
|
-
}, "getIssueProperties");
|
|
2155
|
-
return this._refinement((val, ctx) => {
|
|
2156
|
-
const result = check(val);
|
|
2157
|
-
const setError = /* @__PURE__ */ __name(() => ctx.addIssue({
|
|
2158
|
-
code: ZodIssueCode.custom,
|
|
2159
|
-
...getIssueProperties(val)
|
|
2160
|
-
}), "setError");
|
|
2161
|
-
if (typeof Promise !== "undefined" && result instanceof Promise) {
|
|
2162
|
-
return result.then((data) => {
|
|
2163
|
-
if (!data) {
|
|
2164
|
-
setError();
|
|
2165
|
-
return false;
|
|
2166
|
-
} else {
|
|
2167
|
-
return true;
|
|
2168
|
-
}
|
|
2169
|
-
});
|
|
2170
|
-
}
|
|
2171
|
-
if (!result) {
|
|
2172
|
-
setError();
|
|
2173
|
-
return false;
|
|
2174
|
-
} else {
|
|
2175
|
-
return true;
|
|
2176
|
-
}
|
|
2177
|
-
});
|
|
2178
|
-
}
|
|
2179
|
-
refinement(check, refinementData) {
|
|
2180
|
-
return this._refinement((val, ctx) => {
|
|
2181
|
-
if (!check(val)) {
|
|
2182
|
-
ctx.addIssue(typeof refinementData === "function" ? refinementData(val, ctx) : refinementData);
|
|
2183
|
-
return false;
|
|
2184
|
-
} else {
|
|
2185
|
-
return true;
|
|
2186
|
-
}
|
|
2187
|
-
});
|
|
2188
|
-
}
|
|
2189
|
-
_refinement(refinement) {
|
|
2190
|
-
return new ZodEffects({
|
|
2191
|
-
schema: this,
|
|
2192
|
-
typeName: ZodFirstPartyTypeKind.ZodEffects,
|
|
2193
|
-
effect: { type: "refinement", refinement }
|
|
2194
|
-
});
|
|
2195
|
-
}
|
|
2196
|
-
superRefine(refinement) {
|
|
2197
|
-
return this._refinement(refinement);
|
|
2198
|
-
}
|
|
2199
|
-
optional() {
|
|
2200
|
-
return ZodOptional.create(this, this._def);
|
|
2201
|
-
}
|
|
2202
|
-
nullable() {
|
|
2203
|
-
return ZodNullable.create(this, this._def);
|
|
2204
|
-
}
|
|
2205
|
-
nullish() {
|
|
2206
|
-
return this.nullable().optional();
|
|
2207
|
-
}
|
|
2208
|
-
array() {
|
|
2209
|
-
return ZodArray.create(this, this._def);
|
|
2210
|
-
}
|
|
2211
|
-
promise() {
|
|
2212
|
-
return ZodPromise.create(this, this._def);
|
|
2213
|
-
}
|
|
2214
|
-
or(option) {
|
|
2215
|
-
return ZodUnion.create([this, option], this._def);
|
|
2216
|
-
}
|
|
2217
|
-
and(incoming) {
|
|
2218
|
-
return ZodIntersection.create(this, incoming, this._def);
|
|
2219
|
-
}
|
|
2220
|
-
transform(transform) {
|
|
2221
|
-
return new ZodEffects({
|
|
2222
|
-
...processCreateParams(this._def),
|
|
2223
|
-
schema: this,
|
|
2224
|
-
typeName: ZodFirstPartyTypeKind.ZodEffects,
|
|
2225
|
-
effect: { type: "transform", transform }
|
|
2226
|
-
});
|
|
2227
|
-
}
|
|
2228
|
-
default(def) {
|
|
2229
|
-
const defaultValueFunc = typeof def === "function" ? def : () => def;
|
|
2230
|
-
return new ZodDefault({
|
|
2231
|
-
...processCreateParams(this._def),
|
|
2232
|
-
innerType: this,
|
|
2233
|
-
defaultValue: defaultValueFunc,
|
|
2234
|
-
typeName: ZodFirstPartyTypeKind.ZodDefault
|
|
2235
|
-
});
|
|
2236
|
-
}
|
|
2237
|
-
brand() {
|
|
2238
|
-
return new ZodBranded({
|
|
2239
|
-
typeName: ZodFirstPartyTypeKind.ZodBranded,
|
|
2240
|
-
type: this,
|
|
2241
|
-
...processCreateParams(this._def)
|
|
2242
|
-
});
|
|
2243
|
-
}
|
|
2244
|
-
catch(def) {
|
|
2245
|
-
const catchValueFunc = typeof def === "function" ? def : () => def;
|
|
2246
|
-
return new ZodCatch({
|
|
2247
|
-
...processCreateParams(this._def),
|
|
2248
|
-
innerType: this,
|
|
2249
|
-
catchValue: catchValueFunc,
|
|
2250
|
-
typeName: ZodFirstPartyTypeKind.ZodCatch
|
|
2251
|
-
});
|
|
2252
|
-
}
|
|
2253
|
-
describe(description) {
|
|
2254
|
-
const This = this.constructor;
|
|
2255
|
-
return new This({
|
|
2256
|
-
...this._def,
|
|
2257
|
-
description
|
|
2258
|
-
});
|
|
2259
|
-
}
|
|
2260
|
-
pipe(target) {
|
|
2261
|
-
return ZodPipeline.create(this, target);
|
|
2262
|
-
}
|
|
2263
|
-
readonly() {
|
|
2264
|
-
return ZodReadonly.create(this);
|
|
2265
|
-
}
|
|
2266
|
-
isOptional() {
|
|
2267
|
-
return this.safeParse(void 0).success;
|
|
2268
|
-
}
|
|
2269
|
-
isNullable() {
|
|
2270
|
-
return this.safeParse(null).success;
|
|
2271
|
-
}
|
|
2272
|
-
};
|
|
2273
|
-
__name(_ZodType, "ZodType");
|
|
2274
|
-
var ZodType = _ZodType;
|
|
2275
|
-
var cuidRegex = /^c[^\s-]{8,}$/i;
|
|
2276
|
-
var cuid2Regex = /^[0-9a-z]+$/;
|
|
2277
|
-
var ulidRegex = /^[0-9A-HJKMNP-TV-Z]{26}$/;
|
|
2278
|
-
var uuidRegex = /^[0-9a-fA-F]{8}\b-[0-9a-fA-F]{4}\b-[0-9a-fA-F]{4}\b-[0-9a-fA-F]{4}\b-[0-9a-fA-F]{12}$/i;
|
|
2279
|
-
var nanoidRegex = /^[a-z0-9_-]{21}$/i;
|
|
2280
|
-
var durationRegex = /^[-+]?P(?!$)(?:(?:[-+]?\d+Y)|(?:[-+]?\d+[.,]\d+Y$))?(?:(?:[-+]?\d+M)|(?:[-+]?\d+[.,]\d+M$))?(?:(?:[-+]?\d+W)|(?:[-+]?\d+[.,]\d+W$))?(?:(?:[-+]?\d+D)|(?:[-+]?\d+[.,]\d+D$))?(?:T(?=[\d+-])(?:(?:[-+]?\d+H)|(?:[-+]?\d+[.,]\d+H$))?(?:(?:[-+]?\d+M)|(?:[-+]?\d+[.,]\d+M$))?(?:[-+]?\d+(?:[.,]\d+)?S)?)??$/;
|
|
2281
|
-
var emailRegex = /^(?!\.)(?!.*\.\.)([A-Z0-9_'+\-\.]*)[A-Z0-9_+-]@([A-Z0-9][A-Z0-9\-]*\.)+[A-Z]{2,}$/i;
|
|
2282
|
-
var _emojiRegex = `^(\\p{Extended_Pictographic}|\\p{Emoji_Component})+$`;
|
|
2283
|
-
var emojiRegex;
|
|
2284
|
-
var ipv4Regex = /^(?:(?:25[0-5]|2[0-4][0-9]|1[0-9][0-9]|[1-9][0-9]|[0-9])\.){3}(?:25[0-5]|2[0-4][0-9]|1[0-9][0-9]|[1-9][0-9]|[0-9])$/;
|
|
2285
|
-
var ipv6Regex = /^(([a-f0-9]{1,4}:){7}|::([a-f0-9]{1,4}:){0,6}|([a-f0-9]{1,4}:){1}:([a-f0-9]{1,4}:){0,5}|([a-f0-9]{1,4}:){2}:([a-f0-9]{1,4}:){0,4}|([a-f0-9]{1,4}:){3}:([a-f0-9]{1,4}:){0,3}|([a-f0-9]{1,4}:){4}:([a-f0-9]{1,4}:){0,2}|([a-f0-9]{1,4}:){5}:([a-f0-9]{1,4}:){0,1})([a-f0-9]{1,4}|(((25[0-5])|(2[0-4][0-9])|(1[0-9]{2})|([0-9]{1,2}))\.){3}((25[0-5])|(2[0-4][0-9])|(1[0-9]{2})|([0-9]{1,2})))$/;
|
|
2286
|
-
var base64Regex = /^([0-9a-zA-Z+/]{4})*(([0-9a-zA-Z+/]{2}==)|([0-9a-zA-Z+/]{3}=))?$/;
|
|
2287
|
-
var dateRegexSource = `((\\d\\d[2468][048]|\\d\\d[13579][26]|\\d\\d0[48]|[02468][048]00|[13579][26]00)-02-29|\\d{4}-((0[13578]|1[02])-(0[1-9]|[12]\\d|3[01])|(0[469]|11)-(0[1-9]|[12]\\d|30)|(02)-(0[1-9]|1\\d|2[0-8])))`;
|
|
2288
|
-
var dateRegex = new RegExp(`^${dateRegexSource}$`);
|
|
2289
|
-
function timeRegexSource(args) {
|
|
2290
|
-
let regex = `([01]\\d|2[0-3]):[0-5]\\d:[0-5]\\d`;
|
|
2291
|
-
if (args.precision) {
|
|
2292
|
-
regex = `${regex}\\.\\d{${args.precision}}`;
|
|
2293
|
-
} else if (args.precision == null) {
|
|
2294
|
-
regex = `${regex}(\\.\\d+)?`;
|
|
2295
|
-
}
|
|
2296
|
-
return regex;
|
|
2297
|
-
}
|
|
2298
|
-
__name(timeRegexSource, "timeRegexSource");
|
|
2299
|
-
function timeRegex(args) {
|
|
2300
|
-
return new RegExp(`^${timeRegexSource(args)}$`);
|
|
2301
|
-
}
|
|
2302
|
-
__name(timeRegex, "timeRegex");
|
|
2303
|
-
function datetimeRegex(args) {
|
|
2304
|
-
let regex = `${dateRegexSource}T${timeRegexSource(args)}`;
|
|
2305
|
-
const opts = [];
|
|
2306
|
-
opts.push(args.local ? `Z?` : `Z`);
|
|
2307
|
-
if (args.offset)
|
|
2308
|
-
opts.push(`([+-]\\d{2}:?\\d{2})`);
|
|
2309
|
-
regex = `${regex}(${opts.join("|")})`;
|
|
2310
|
-
return new RegExp(`^${regex}$`);
|
|
2311
|
-
}
|
|
2312
|
-
__name(datetimeRegex, "datetimeRegex");
|
|
2313
|
-
function isValidIP(ip, version) {
|
|
2314
|
-
if ((version === "v4" || !version) && ipv4Regex.test(ip)) {
|
|
2315
|
-
return true;
|
|
2316
|
-
}
|
|
2317
|
-
if ((version === "v6" || !version) && ipv6Regex.test(ip)) {
|
|
2318
|
-
return true;
|
|
1038
|
+
if (Array.isArray(obj))
|
|
1039
|
+
return obj.map((item) => camelCaseKeys(item));
|
|
1040
|
+
return Object.fromEntries(Object.entries(obj).map(([key, value]) => [
|
|
1041
|
+
camelCase(key),
|
|
1042
|
+
camelCaseKeys(value)
|
|
1043
|
+
]));
|
|
1044
|
+
}, "camelCaseKeys");
|
|
1045
|
+
var createRequest = /* @__PURE__ */ __name((method) => async (urlOrNetwork, ...params) => {
|
|
1046
|
+
const url = "network" in urlOrNetwork ? rpc.constants.PUBLIC_RPC_ENDPOINTS[urlOrNetwork.network] : urlOrNetwork.rpcUrl;
|
|
1047
|
+
const result = await new rpc.HttpClient(url).sendRequest(method, ...params);
|
|
1048
|
+
return camelCaseKeys(result);
|
|
1049
|
+
}, "createRequest");
|
|
1050
|
+
var transform = /* @__PURE__ */ __name((fn, cb) => (...args) => fn(...args).then(cb), "transform");
|
|
1051
|
+
var getFundingEnvironment = createRequest("cf_funding_environment");
|
|
1052
|
+
createRequest("cf_swapping_environment");
|
|
1053
|
+
createRequest("cf_ingress_egress_environment");
|
|
1054
|
+
createRequest("cf_environment");
|
|
1055
|
+
createRequest("cf_swap_rate");
|
|
1056
|
+
createRequest("state_getMetadata");
|
|
1057
|
+
createRequest("cf_supported_assets");
|
|
1058
|
+
createRequest("state_getRuntimeVersion");
|
|
1059
|
+
createRequest("chain_getBlockHash");
|
|
1060
|
+
transform(createRequest("cf_boost_pools_depth"), (result) => result.map(({ chain, asset, ...rest }) => ({
|
|
1061
|
+
asset: getInternalAsset({
|
|
1062
|
+
chain,
|
|
1063
|
+
asset
|
|
1064
|
+
}),
|
|
1065
|
+
...rest
|
|
1066
|
+
})));
|
|
1067
|
+
createRequest("cf_swap_rate_v2");
|
|
1068
|
+
|
|
1069
|
+
// ../shared/src/stateChainGateway/utils.ts
|
|
1070
|
+
var getStateChainGateway = /* @__PURE__ */ __name((networkOpts) => {
|
|
1071
|
+
const stateChainGatewayContractAddress = networkOpts.network === "localnet" ? networkOpts.stateChainGatewayContractAddress : getStateChainGatewayContractAddress(networkOpts.network);
|
|
1072
|
+
return StateChainGateway__factory.connect(stateChainGatewayContractAddress, networkOpts.signer);
|
|
1073
|
+
}, "getStateChainGateway");
|
|
1074
|
+
|
|
1075
|
+
// ../shared/src/guards.ts
|
|
1076
|
+
function assert(condition, message) {
|
|
1077
|
+
if (condition)
|
|
1078
|
+
return;
|
|
1079
|
+
const error = new Error(message);
|
|
1080
|
+
if (error.stack) {
|
|
1081
|
+
error.stack = error.stack.replace(/\n.+/, "\n");
|
|
2319
1082
|
}
|
|
2320
|
-
|
|
2321
|
-
}
|
|
2322
|
-
__name(isValidIP, "isValidIP");
|
|
2323
|
-
var _ZodString = class _ZodString extends ZodType {
|
|
2324
|
-
_parse(input) {
|
|
2325
|
-
if (this._def.coerce) {
|
|
2326
|
-
input.data = String(input.data);
|
|
2327
|
-
}
|
|
2328
|
-
const parsedType = this._getType(input);
|
|
2329
|
-
if (parsedType !== ZodParsedType.string) {
|
|
2330
|
-
const ctx2 = this._getOrReturnCtx(input);
|
|
2331
|
-
addIssueToContext(ctx2, {
|
|
2332
|
-
code: ZodIssueCode.invalid_type,
|
|
2333
|
-
expected: ZodParsedType.string,
|
|
2334
|
-
received: ctx2.parsedType
|
|
2335
|
-
});
|
|
2336
|
-
return INVALID;
|
|
2337
|
-
}
|
|
2338
|
-
const status = new ParseStatus();
|
|
2339
|
-
let ctx = void 0;
|
|
2340
|
-
for (const check of this._def.checks) {
|
|
2341
|
-
if (check.kind === "min") {
|
|
2342
|
-
if (input.data.length < check.value) {
|
|
2343
|
-
ctx = this._getOrReturnCtx(input, ctx);
|
|
2344
|
-
addIssueToContext(ctx, {
|
|
2345
|
-
code: ZodIssueCode.too_small,
|
|
2346
|
-
minimum: check.value,
|
|
2347
|
-
type: "string",
|
|
2348
|
-
inclusive: true,
|
|
2349
|
-
exact: false,
|
|
2350
|
-
message: check.message
|
|
2351
|
-
});
|
|
2352
|
-
status.dirty();
|
|
2353
|
-
}
|
|
2354
|
-
} else if (check.kind === "max") {
|
|
2355
|
-
if (input.data.length > check.value) {
|
|
2356
|
-
ctx = this._getOrReturnCtx(input, ctx);
|
|
2357
|
-
addIssueToContext(ctx, {
|
|
2358
|
-
code: ZodIssueCode.too_big,
|
|
2359
|
-
maximum: check.value,
|
|
2360
|
-
type: "string",
|
|
2361
|
-
inclusive: true,
|
|
2362
|
-
exact: false,
|
|
2363
|
-
message: check.message
|
|
2364
|
-
});
|
|
2365
|
-
status.dirty();
|
|
2366
|
-
}
|
|
2367
|
-
} else if (check.kind === "length") {
|
|
2368
|
-
const tooBig = input.data.length > check.value;
|
|
2369
|
-
const tooSmall = input.data.length < check.value;
|
|
2370
|
-
if (tooBig || tooSmall) {
|
|
2371
|
-
ctx = this._getOrReturnCtx(input, ctx);
|
|
2372
|
-
if (tooBig) {
|
|
2373
|
-
addIssueToContext(ctx, {
|
|
2374
|
-
code: ZodIssueCode.too_big,
|
|
2375
|
-
maximum: check.value,
|
|
2376
|
-
type: "string",
|
|
2377
|
-
inclusive: true,
|
|
2378
|
-
exact: true,
|
|
2379
|
-
message: check.message
|
|
2380
|
-
});
|
|
2381
|
-
} else if (tooSmall) {
|
|
2382
|
-
addIssueToContext(ctx, {
|
|
2383
|
-
code: ZodIssueCode.too_small,
|
|
2384
|
-
minimum: check.value,
|
|
2385
|
-
type: "string",
|
|
2386
|
-
inclusive: true,
|
|
2387
|
-
exact: true,
|
|
2388
|
-
message: check.message
|
|
2389
|
-
});
|
|
2390
|
-
}
|
|
2391
|
-
status.dirty();
|
|
2392
|
-
}
|
|
2393
|
-
} else if (check.kind === "email") {
|
|
2394
|
-
if (!emailRegex.test(input.data)) {
|
|
2395
|
-
ctx = this._getOrReturnCtx(input, ctx);
|
|
2396
|
-
addIssueToContext(ctx, {
|
|
2397
|
-
validation: "email",
|
|
2398
|
-
code: ZodIssueCode.invalid_string,
|
|
2399
|
-
message: check.message
|
|
2400
|
-
});
|
|
2401
|
-
status.dirty();
|
|
2402
|
-
}
|
|
2403
|
-
} else if (check.kind === "emoji") {
|
|
2404
|
-
if (!emojiRegex) {
|
|
2405
|
-
emojiRegex = new RegExp(_emojiRegex, "u");
|
|
2406
|
-
}
|
|
2407
|
-
if (!emojiRegex.test(input.data)) {
|
|
2408
|
-
ctx = this._getOrReturnCtx(input, ctx);
|
|
2409
|
-
addIssueToContext(ctx, {
|
|
2410
|
-
validation: "emoji",
|
|
2411
|
-
code: ZodIssueCode.invalid_string,
|
|
2412
|
-
message: check.message
|
|
2413
|
-
});
|
|
2414
|
-
status.dirty();
|
|
2415
|
-
}
|
|
2416
|
-
} else if (check.kind === "uuid") {
|
|
2417
|
-
if (!uuidRegex.test(input.data)) {
|
|
2418
|
-
ctx = this._getOrReturnCtx(input, ctx);
|
|
2419
|
-
addIssueToContext(ctx, {
|
|
2420
|
-
validation: "uuid",
|
|
2421
|
-
code: ZodIssueCode.invalid_string,
|
|
2422
|
-
message: check.message
|
|
2423
|
-
});
|
|
2424
|
-
status.dirty();
|
|
2425
|
-
}
|
|
2426
|
-
} else if (check.kind === "nanoid") {
|
|
2427
|
-
if (!nanoidRegex.test(input.data)) {
|
|
2428
|
-
ctx = this._getOrReturnCtx(input, ctx);
|
|
2429
|
-
addIssueToContext(ctx, {
|
|
2430
|
-
validation: "nanoid",
|
|
2431
|
-
code: ZodIssueCode.invalid_string,
|
|
2432
|
-
message: check.message
|
|
2433
|
-
});
|
|
2434
|
-
status.dirty();
|
|
2435
|
-
}
|
|
2436
|
-
} else if (check.kind === "cuid") {
|
|
2437
|
-
if (!cuidRegex.test(input.data)) {
|
|
2438
|
-
ctx = this._getOrReturnCtx(input, ctx);
|
|
2439
|
-
addIssueToContext(ctx, {
|
|
2440
|
-
validation: "cuid",
|
|
2441
|
-
code: ZodIssueCode.invalid_string,
|
|
2442
|
-
message: check.message
|
|
2443
|
-
});
|
|
2444
|
-
status.dirty();
|
|
2445
|
-
}
|
|
2446
|
-
} else if (check.kind === "cuid2") {
|
|
2447
|
-
if (!cuid2Regex.test(input.data)) {
|
|
2448
|
-
ctx = this._getOrReturnCtx(input, ctx);
|
|
2449
|
-
addIssueToContext(ctx, {
|
|
2450
|
-
validation: "cuid2",
|
|
2451
|
-
code: ZodIssueCode.invalid_string,
|
|
2452
|
-
message: check.message
|
|
2453
|
-
});
|
|
2454
|
-
status.dirty();
|
|
2455
|
-
}
|
|
2456
|
-
} else if (check.kind === "ulid") {
|
|
2457
|
-
if (!ulidRegex.test(input.data)) {
|
|
2458
|
-
ctx = this._getOrReturnCtx(input, ctx);
|
|
2459
|
-
addIssueToContext(ctx, {
|
|
2460
|
-
validation: "ulid",
|
|
2461
|
-
code: ZodIssueCode.invalid_string,
|
|
2462
|
-
message: check.message
|
|
2463
|
-
});
|
|
2464
|
-
status.dirty();
|
|
2465
|
-
}
|
|
2466
|
-
} else if (check.kind === "url") {
|
|
2467
|
-
try {
|
|
2468
|
-
new URL(input.data);
|
|
2469
|
-
} catch (_a) {
|
|
2470
|
-
ctx = this._getOrReturnCtx(input, ctx);
|
|
2471
|
-
addIssueToContext(ctx, {
|
|
2472
|
-
validation: "url",
|
|
2473
|
-
code: ZodIssueCode.invalid_string,
|
|
2474
|
-
message: check.message
|
|
2475
|
-
});
|
|
2476
|
-
status.dirty();
|
|
2477
|
-
}
|
|
2478
|
-
} else if (check.kind === "regex") {
|
|
2479
|
-
check.regex.lastIndex = 0;
|
|
2480
|
-
const testResult = check.regex.test(input.data);
|
|
2481
|
-
if (!testResult) {
|
|
2482
|
-
ctx = this._getOrReturnCtx(input, ctx);
|
|
2483
|
-
addIssueToContext(ctx, {
|
|
2484
|
-
validation: "regex",
|
|
2485
|
-
code: ZodIssueCode.invalid_string,
|
|
2486
|
-
message: check.message
|
|
2487
|
-
});
|
|
2488
|
-
status.dirty();
|
|
2489
|
-
}
|
|
2490
|
-
} else if (check.kind === "trim") {
|
|
2491
|
-
input.data = input.data.trim();
|
|
2492
|
-
} else if (check.kind === "includes") {
|
|
2493
|
-
if (!input.data.includes(check.value, check.position)) {
|
|
2494
|
-
ctx = this._getOrReturnCtx(input, ctx);
|
|
2495
|
-
addIssueToContext(ctx, {
|
|
2496
|
-
code: ZodIssueCode.invalid_string,
|
|
2497
|
-
validation: { includes: check.value, position: check.position },
|
|
2498
|
-
message: check.message
|
|
2499
|
-
});
|
|
2500
|
-
status.dirty();
|
|
2501
|
-
}
|
|
2502
|
-
} else if (check.kind === "toLowerCase") {
|
|
2503
|
-
input.data = input.data.toLowerCase();
|
|
2504
|
-
} else if (check.kind === "toUpperCase") {
|
|
2505
|
-
input.data = input.data.toUpperCase();
|
|
2506
|
-
} else if (check.kind === "startsWith") {
|
|
2507
|
-
if (!input.data.startsWith(check.value)) {
|
|
2508
|
-
ctx = this._getOrReturnCtx(input, ctx);
|
|
2509
|
-
addIssueToContext(ctx, {
|
|
2510
|
-
code: ZodIssueCode.invalid_string,
|
|
2511
|
-
validation: { startsWith: check.value },
|
|
2512
|
-
message: check.message
|
|
2513
|
-
});
|
|
2514
|
-
status.dirty();
|
|
2515
|
-
}
|
|
2516
|
-
} else if (check.kind === "endsWith") {
|
|
2517
|
-
if (!input.data.endsWith(check.value)) {
|
|
2518
|
-
ctx = this._getOrReturnCtx(input, ctx);
|
|
2519
|
-
addIssueToContext(ctx, {
|
|
2520
|
-
code: ZodIssueCode.invalid_string,
|
|
2521
|
-
validation: { endsWith: check.value },
|
|
2522
|
-
message: check.message
|
|
2523
|
-
});
|
|
2524
|
-
status.dirty();
|
|
2525
|
-
}
|
|
2526
|
-
} else if (check.kind === "datetime") {
|
|
2527
|
-
const regex = datetimeRegex(check);
|
|
2528
|
-
if (!regex.test(input.data)) {
|
|
2529
|
-
ctx = this._getOrReturnCtx(input, ctx);
|
|
2530
|
-
addIssueToContext(ctx, {
|
|
2531
|
-
code: ZodIssueCode.invalid_string,
|
|
2532
|
-
validation: "datetime",
|
|
2533
|
-
message: check.message
|
|
2534
|
-
});
|
|
2535
|
-
status.dirty();
|
|
2536
|
-
}
|
|
2537
|
-
} else if (check.kind === "date") {
|
|
2538
|
-
const regex = dateRegex;
|
|
2539
|
-
if (!regex.test(input.data)) {
|
|
2540
|
-
ctx = this._getOrReturnCtx(input, ctx);
|
|
2541
|
-
addIssueToContext(ctx, {
|
|
2542
|
-
code: ZodIssueCode.invalid_string,
|
|
2543
|
-
validation: "date",
|
|
2544
|
-
message: check.message
|
|
2545
|
-
});
|
|
2546
|
-
status.dirty();
|
|
2547
|
-
}
|
|
2548
|
-
} else if (check.kind === "time") {
|
|
2549
|
-
const regex = timeRegex(check);
|
|
2550
|
-
if (!regex.test(input.data)) {
|
|
2551
|
-
ctx = this._getOrReturnCtx(input, ctx);
|
|
2552
|
-
addIssueToContext(ctx, {
|
|
2553
|
-
code: ZodIssueCode.invalid_string,
|
|
2554
|
-
validation: "time",
|
|
2555
|
-
message: check.message
|
|
2556
|
-
});
|
|
2557
|
-
status.dirty();
|
|
2558
|
-
}
|
|
2559
|
-
} else if (check.kind === "duration") {
|
|
2560
|
-
if (!durationRegex.test(input.data)) {
|
|
2561
|
-
ctx = this._getOrReturnCtx(input, ctx);
|
|
2562
|
-
addIssueToContext(ctx, {
|
|
2563
|
-
validation: "duration",
|
|
2564
|
-
code: ZodIssueCode.invalid_string,
|
|
2565
|
-
message: check.message
|
|
2566
|
-
});
|
|
2567
|
-
status.dirty();
|
|
2568
|
-
}
|
|
2569
|
-
} else if (check.kind === "ip") {
|
|
2570
|
-
if (!isValidIP(input.data, check.version)) {
|
|
2571
|
-
ctx = this._getOrReturnCtx(input, ctx);
|
|
2572
|
-
addIssueToContext(ctx, {
|
|
2573
|
-
validation: "ip",
|
|
2574
|
-
code: ZodIssueCode.invalid_string,
|
|
2575
|
-
message: check.message
|
|
2576
|
-
});
|
|
2577
|
-
status.dirty();
|
|
2578
|
-
}
|
|
2579
|
-
} else if (check.kind === "base64") {
|
|
2580
|
-
if (!base64Regex.test(input.data)) {
|
|
2581
|
-
ctx = this._getOrReturnCtx(input, ctx);
|
|
2582
|
-
addIssueToContext(ctx, {
|
|
2583
|
-
validation: "base64",
|
|
2584
|
-
code: ZodIssueCode.invalid_string,
|
|
2585
|
-
message: check.message
|
|
2586
|
-
});
|
|
2587
|
-
status.dirty();
|
|
2588
|
-
}
|
|
2589
|
-
} else {
|
|
2590
|
-
util.assertNever(check);
|
|
2591
|
-
}
|
|
2592
|
-
}
|
|
2593
|
-
return { status: status.value, value: input.data };
|
|
2594
|
-
}
|
|
2595
|
-
_regex(regex, validation, message) {
|
|
2596
|
-
return this.refinement((data) => regex.test(data), {
|
|
2597
|
-
validation,
|
|
2598
|
-
code: ZodIssueCode.invalid_string,
|
|
2599
|
-
...errorUtil.errToObj(message)
|
|
2600
|
-
});
|
|
2601
|
-
}
|
|
2602
|
-
_addCheck(check) {
|
|
2603
|
-
return new _ZodString({
|
|
2604
|
-
...this._def,
|
|
2605
|
-
checks: [...this._def.checks, check]
|
|
2606
|
-
});
|
|
2607
|
-
}
|
|
2608
|
-
email(message) {
|
|
2609
|
-
return this._addCheck({ kind: "email", ...errorUtil.errToObj(message) });
|
|
2610
|
-
}
|
|
2611
|
-
url(message) {
|
|
2612
|
-
return this._addCheck({ kind: "url", ...errorUtil.errToObj(message) });
|
|
2613
|
-
}
|
|
2614
|
-
emoji(message) {
|
|
2615
|
-
return this._addCheck({ kind: "emoji", ...errorUtil.errToObj(message) });
|
|
2616
|
-
}
|
|
2617
|
-
uuid(message) {
|
|
2618
|
-
return this._addCheck({ kind: "uuid", ...errorUtil.errToObj(message) });
|
|
2619
|
-
}
|
|
2620
|
-
nanoid(message) {
|
|
2621
|
-
return this._addCheck({ kind: "nanoid", ...errorUtil.errToObj(message) });
|
|
2622
|
-
}
|
|
2623
|
-
cuid(message) {
|
|
2624
|
-
return this._addCheck({ kind: "cuid", ...errorUtil.errToObj(message) });
|
|
2625
|
-
}
|
|
2626
|
-
cuid2(message) {
|
|
2627
|
-
return this._addCheck({ kind: "cuid2", ...errorUtil.errToObj(message) });
|
|
2628
|
-
}
|
|
2629
|
-
ulid(message) {
|
|
2630
|
-
return this._addCheck({ kind: "ulid", ...errorUtil.errToObj(message) });
|
|
2631
|
-
}
|
|
2632
|
-
base64(message) {
|
|
2633
|
-
return this._addCheck({ kind: "base64", ...errorUtil.errToObj(message) });
|
|
2634
|
-
}
|
|
2635
|
-
ip(options) {
|
|
2636
|
-
return this._addCheck({ kind: "ip", ...errorUtil.errToObj(options) });
|
|
2637
|
-
}
|
|
2638
|
-
datetime(options) {
|
|
2639
|
-
var _a, _b;
|
|
2640
|
-
if (typeof options === "string") {
|
|
2641
|
-
return this._addCheck({
|
|
2642
|
-
kind: "datetime",
|
|
2643
|
-
precision: null,
|
|
2644
|
-
offset: false,
|
|
2645
|
-
local: false,
|
|
2646
|
-
message: options
|
|
2647
|
-
});
|
|
2648
|
-
}
|
|
2649
|
-
return this._addCheck({
|
|
2650
|
-
kind: "datetime",
|
|
2651
|
-
precision: typeof (options === null || options === void 0 ? void 0 : options.precision) === "undefined" ? null : options === null || options === void 0 ? void 0 : options.precision,
|
|
2652
|
-
offset: (_a = options === null || options === void 0 ? void 0 : options.offset) !== null && _a !== void 0 ? _a : false,
|
|
2653
|
-
local: (_b = options === null || options === void 0 ? void 0 : options.local) !== null && _b !== void 0 ? _b : false,
|
|
2654
|
-
...errorUtil.errToObj(options === null || options === void 0 ? void 0 : options.message)
|
|
2655
|
-
});
|
|
2656
|
-
}
|
|
2657
|
-
date(message) {
|
|
2658
|
-
return this._addCheck({ kind: "date", message });
|
|
2659
|
-
}
|
|
2660
|
-
time(options) {
|
|
2661
|
-
if (typeof options === "string") {
|
|
2662
|
-
return this._addCheck({
|
|
2663
|
-
kind: "time",
|
|
2664
|
-
precision: null,
|
|
2665
|
-
message: options
|
|
2666
|
-
});
|
|
2667
|
-
}
|
|
2668
|
-
return this._addCheck({
|
|
2669
|
-
kind: "time",
|
|
2670
|
-
precision: typeof (options === null || options === void 0 ? void 0 : options.precision) === "undefined" ? null : options === null || options === void 0 ? void 0 : options.precision,
|
|
2671
|
-
...errorUtil.errToObj(options === null || options === void 0 ? void 0 : options.message)
|
|
2672
|
-
});
|
|
2673
|
-
}
|
|
2674
|
-
duration(message) {
|
|
2675
|
-
return this._addCheck({ kind: "duration", ...errorUtil.errToObj(message) });
|
|
2676
|
-
}
|
|
2677
|
-
regex(regex, message) {
|
|
2678
|
-
return this._addCheck({
|
|
2679
|
-
kind: "regex",
|
|
2680
|
-
regex,
|
|
2681
|
-
...errorUtil.errToObj(message)
|
|
2682
|
-
});
|
|
2683
|
-
}
|
|
2684
|
-
includes(value, options) {
|
|
2685
|
-
return this._addCheck({
|
|
2686
|
-
kind: "includes",
|
|
2687
|
-
value,
|
|
2688
|
-
position: options === null || options === void 0 ? void 0 : options.position,
|
|
2689
|
-
...errorUtil.errToObj(options === null || options === void 0 ? void 0 : options.message)
|
|
2690
|
-
});
|
|
2691
|
-
}
|
|
2692
|
-
startsWith(value, message) {
|
|
2693
|
-
return this._addCheck({
|
|
2694
|
-
kind: "startsWith",
|
|
2695
|
-
value,
|
|
2696
|
-
...errorUtil.errToObj(message)
|
|
2697
|
-
});
|
|
2698
|
-
}
|
|
2699
|
-
endsWith(value, message) {
|
|
2700
|
-
return this._addCheck({
|
|
2701
|
-
kind: "endsWith",
|
|
2702
|
-
value,
|
|
2703
|
-
...errorUtil.errToObj(message)
|
|
2704
|
-
});
|
|
2705
|
-
}
|
|
2706
|
-
min(minLength, message) {
|
|
2707
|
-
return this._addCheck({
|
|
2708
|
-
kind: "min",
|
|
2709
|
-
value: minLength,
|
|
2710
|
-
...errorUtil.errToObj(message)
|
|
2711
|
-
});
|
|
2712
|
-
}
|
|
2713
|
-
max(maxLength, message) {
|
|
2714
|
-
return this._addCheck({
|
|
2715
|
-
kind: "max",
|
|
2716
|
-
value: maxLength,
|
|
2717
|
-
...errorUtil.errToObj(message)
|
|
2718
|
-
});
|
|
2719
|
-
}
|
|
2720
|
-
length(len, message) {
|
|
2721
|
-
return this._addCheck({
|
|
2722
|
-
kind: "length",
|
|
2723
|
-
value: len,
|
|
2724
|
-
...errorUtil.errToObj(message)
|
|
2725
|
-
});
|
|
2726
|
-
}
|
|
2727
|
-
/**
|
|
2728
|
-
* @deprecated Use z.string().min(1) instead.
|
|
2729
|
-
* @see {@link ZodString.min}
|
|
2730
|
-
*/
|
|
2731
|
-
nonempty(message) {
|
|
2732
|
-
return this.min(1, errorUtil.errToObj(message));
|
|
2733
|
-
}
|
|
2734
|
-
trim() {
|
|
2735
|
-
return new _ZodString({
|
|
2736
|
-
...this._def,
|
|
2737
|
-
checks: [...this._def.checks, { kind: "trim" }]
|
|
2738
|
-
});
|
|
2739
|
-
}
|
|
2740
|
-
toLowerCase() {
|
|
2741
|
-
return new _ZodString({
|
|
2742
|
-
...this._def,
|
|
2743
|
-
checks: [...this._def.checks, { kind: "toLowerCase" }]
|
|
2744
|
-
});
|
|
2745
|
-
}
|
|
2746
|
-
toUpperCase() {
|
|
2747
|
-
return new _ZodString({
|
|
2748
|
-
...this._def,
|
|
2749
|
-
checks: [...this._def.checks, { kind: "toUpperCase" }]
|
|
2750
|
-
});
|
|
2751
|
-
}
|
|
2752
|
-
get isDatetime() {
|
|
2753
|
-
return !!this._def.checks.find((ch) => ch.kind === "datetime");
|
|
2754
|
-
}
|
|
2755
|
-
get isDate() {
|
|
2756
|
-
return !!this._def.checks.find((ch) => ch.kind === "date");
|
|
2757
|
-
}
|
|
2758
|
-
get isTime() {
|
|
2759
|
-
return !!this._def.checks.find((ch) => ch.kind === "time");
|
|
2760
|
-
}
|
|
2761
|
-
get isDuration() {
|
|
2762
|
-
return !!this._def.checks.find((ch) => ch.kind === "duration");
|
|
2763
|
-
}
|
|
2764
|
-
get isEmail() {
|
|
2765
|
-
return !!this._def.checks.find((ch) => ch.kind === "email");
|
|
2766
|
-
}
|
|
2767
|
-
get isURL() {
|
|
2768
|
-
return !!this._def.checks.find((ch) => ch.kind === "url");
|
|
2769
|
-
}
|
|
2770
|
-
get isEmoji() {
|
|
2771
|
-
return !!this._def.checks.find((ch) => ch.kind === "emoji");
|
|
2772
|
-
}
|
|
2773
|
-
get isUUID() {
|
|
2774
|
-
return !!this._def.checks.find((ch) => ch.kind === "uuid");
|
|
2775
|
-
}
|
|
2776
|
-
get isNANOID() {
|
|
2777
|
-
return !!this._def.checks.find((ch) => ch.kind === "nanoid");
|
|
2778
|
-
}
|
|
2779
|
-
get isCUID() {
|
|
2780
|
-
return !!this._def.checks.find((ch) => ch.kind === "cuid");
|
|
2781
|
-
}
|
|
2782
|
-
get isCUID2() {
|
|
2783
|
-
return !!this._def.checks.find((ch) => ch.kind === "cuid2");
|
|
2784
|
-
}
|
|
2785
|
-
get isULID() {
|
|
2786
|
-
return !!this._def.checks.find((ch) => ch.kind === "ulid");
|
|
2787
|
-
}
|
|
2788
|
-
get isIP() {
|
|
2789
|
-
return !!this._def.checks.find((ch) => ch.kind === "ip");
|
|
2790
|
-
}
|
|
2791
|
-
get isBase64() {
|
|
2792
|
-
return !!this._def.checks.find((ch) => ch.kind === "base64");
|
|
2793
|
-
}
|
|
2794
|
-
get minLength() {
|
|
2795
|
-
let min = null;
|
|
2796
|
-
for (const ch of this._def.checks) {
|
|
2797
|
-
if (ch.kind === "min") {
|
|
2798
|
-
if (min === null || ch.value > min)
|
|
2799
|
-
min = ch.value;
|
|
2800
|
-
}
|
|
2801
|
-
}
|
|
2802
|
-
return min;
|
|
2803
|
-
}
|
|
2804
|
-
get maxLength() {
|
|
2805
|
-
let max = null;
|
|
2806
|
-
for (const ch of this._def.checks) {
|
|
2807
|
-
if (ch.kind === "max") {
|
|
2808
|
-
if (max === null || ch.value < max)
|
|
2809
|
-
max = ch.value;
|
|
2810
|
-
}
|
|
2811
|
-
}
|
|
2812
|
-
return max;
|
|
2813
|
-
}
|
|
2814
|
-
};
|
|
2815
|
-
__name(_ZodString, "ZodString");
|
|
2816
|
-
var ZodString = _ZodString;
|
|
2817
|
-
ZodString.create = (params) => {
|
|
2818
|
-
var _a;
|
|
2819
|
-
return new ZodString({
|
|
2820
|
-
checks: [],
|
|
2821
|
-
typeName: ZodFirstPartyTypeKind.ZodString,
|
|
2822
|
-
coerce: (_a = params === null || params === void 0 ? void 0 : params.coerce) !== null && _a !== void 0 ? _a : false,
|
|
2823
|
-
...processCreateParams(params)
|
|
2824
|
-
});
|
|
2825
|
-
};
|
|
2826
|
-
function floatSafeRemainder(val, step) {
|
|
2827
|
-
const valDecCount = (val.toString().split(".")[1] || "").length;
|
|
2828
|
-
const stepDecCount = (step.toString().split(".")[1] || "").length;
|
|
2829
|
-
const decCount = valDecCount > stepDecCount ? valDecCount : stepDecCount;
|
|
2830
|
-
const valInt = parseInt(val.toFixed(decCount).replace(".", ""));
|
|
2831
|
-
const stepInt = parseInt(step.toFixed(decCount).replace(".", ""));
|
|
2832
|
-
return valInt % stepInt / Math.pow(10, decCount);
|
|
2833
|
-
}
|
|
2834
|
-
__name(floatSafeRemainder, "floatSafeRemainder");
|
|
2835
|
-
var _ZodNumber = class _ZodNumber extends ZodType {
|
|
2836
|
-
constructor() {
|
|
2837
|
-
super(...arguments);
|
|
2838
|
-
this.min = this.gte;
|
|
2839
|
-
this.max = this.lte;
|
|
2840
|
-
this.step = this.multipleOf;
|
|
2841
|
-
}
|
|
2842
|
-
_parse(input) {
|
|
2843
|
-
if (this._def.coerce) {
|
|
2844
|
-
input.data = Number(input.data);
|
|
2845
|
-
}
|
|
2846
|
-
const parsedType = this._getType(input);
|
|
2847
|
-
if (parsedType !== ZodParsedType.number) {
|
|
2848
|
-
const ctx2 = this._getOrReturnCtx(input);
|
|
2849
|
-
addIssueToContext(ctx2, {
|
|
2850
|
-
code: ZodIssueCode.invalid_type,
|
|
2851
|
-
expected: ZodParsedType.number,
|
|
2852
|
-
received: ctx2.parsedType
|
|
2853
|
-
});
|
|
2854
|
-
return INVALID;
|
|
2855
|
-
}
|
|
2856
|
-
let ctx = void 0;
|
|
2857
|
-
const status = new ParseStatus();
|
|
2858
|
-
for (const check of this._def.checks) {
|
|
2859
|
-
if (check.kind === "int") {
|
|
2860
|
-
if (!util.isInteger(input.data)) {
|
|
2861
|
-
ctx = this._getOrReturnCtx(input, ctx);
|
|
2862
|
-
addIssueToContext(ctx, {
|
|
2863
|
-
code: ZodIssueCode.invalid_type,
|
|
2864
|
-
expected: "integer",
|
|
2865
|
-
received: "float",
|
|
2866
|
-
message: check.message
|
|
2867
|
-
});
|
|
2868
|
-
status.dirty();
|
|
2869
|
-
}
|
|
2870
|
-
} else if (check.kind === "min") {
|
|
2871
|
-
const tooSmall = check.inclusive ? input.data < check.value : input.data <= check.value;
|
|
2872
|
-
if (tooSmall) {
|
|
2873
|
-
ctx = this._getOrReturnCtx(input, ctx);
|
|
2874
|
-
addIssueToContext(ctx, {
|
|
2875
|
-
code: ZodIssueCode.too_small,
|
|
2876
|
-
minimum: check.value,
|
|
2877
|
-
type: "number",
|
|
2878
|
-
inclusive: check.inclusive,
|
|
2879
|
-
exact: false,
|
|
2880
|
-
message: check.message
|
|
2881
|
-
});
|
|
2882
|
-
status.dirty();
|
|
2883
|
-
}
|
|
2884
|
-
} else if (check.kind === "max") {
|
|
2885
|
-
const tooBig = check.inclusive ? input.data > check.value : input.data >= check.value;
|
|
2886
|
-
if (tooBig) {
|
|
2887
|
-
ctx = this._getOrReturnCtx(input, ctx);
|
|
2888
|
-
addIssueToContext(ctx, {
|
|
2889
|
-
code: ZodIssueCode.too_big,
|
|
2890
|
-
maximum: check.value,
|
|
2891
|
-
type: "number",
|
|
2892
|
-
inclusive: check.inclusive,
|
|
2893
|
-
exact: false,
|
|
2894
|
-
message: check.message
|
|
2895
|
-
});
|
|
2896
|
-
status.dirty();
|
|
2897
|
-
}
|
|
2898
|
-
} else if (check.kind === "multipleOf") {
|
|
2899
|
-
if (floatSafeRemainder(input.data, check.value) !== 0) {
|
|
2900
|
-
ctx = this._getOrReturnCtx(input, ctx);
|
|
2901
|
-
addIssueToContext(ctx, {
|
|
2902
|
-
code: ZodIssueCode.not_multiple_of,
|
|
2903
|
-
multipleOf: check.value,
|
|
2904
|
-
message: check.message
|
|
2905
|
-
});
|
|
2906
|
-
status.dirty();
|
|
2907
|
-
}
|
|
2908
|
-
} else if (check.kind === "finite") {
|
|
2909
|
-
if (!Number.isFinite(input.data)) {
|
|
2910
|
-
ctx = this._getOrReturnCtx(input, ctx);
|
|
2911
|
-
addIssueToContext(ctx, {
|
|
2912
|
-
code: ZodIssueCode.not_finite,
|
|
2913
|
-
message: check.message
|
|
2914
|
-
});
|
|
2915
|
-
status.dirty();
|
|
2916
|
-
}
|
|
2917
|
-
} else {
|
|
2918
|
-
util.assertNever(check);
|
|
2919
|
-
}
|
|
2920
|
-
}
|
|
2921
|
-
return { status: status.value, value: input.data };
|
|
2922
|
-
}
|
|
2923
|
-
gte(value, message) {
|
|
2924
|
-
return this.setLimit("min", value, true, errorUtil.toString(message));
|
|
2925
|
-
}
|
|
2926
|
-
gt(value, message) {
|
|
2927
|
-
return this.setLimit("min", value, false, errorUtil.toString(message));
|
|
2928
|
-
}
|
|
2929
|
-
lte(value, message) {
|
|
2930
|
-
return this.setLimit("max", value, true, errorUtil.toString(message));
|
|
2931
|
-
}
|
|
2932
|
-
lt(value, message) {
|
|
2933
|
-
return this.setLimit("max", value, false, errorUtil.toString(message));
|
|
2934
|
-
}
|
|
2935
|
-
setLimit(kind, value, inclusive, message) {
|
|
2936
|
-
return new _ZodNumber({
|
|
2937
|
-
...this._def,
|
|
2938
|
-
checks: [
|
|
2939
|
-
...this._def.checks,
|
|
2940
|
-
{
|
|
2941
|
-
kind,
|
|
2942
|
-
value,
|
|
2943
|
-
inclusive,
|
|
2944
|
-
message: errorUtil.toString(message)
|
|
2945
|
-
}
|
|
2946
|
-
]
|
|
2947
|
-
});
|
|
2948
|
-
}
|
|
2949
|
-
_addCheck(check) {
|
|
2950
|
-
return new _ZodNumber({
|
|
2951
|
-
...this._def,
|
|
2952
|
-
checks: [...this._def.checks, check]
|
|
2953
|
-
});
|
|
2954
|
-
}
|
|
2955
|
-
int(message) {
|
|
2956
|
-
return this._addCheck({
|
|
2957
|
-
kind: "int",
|
|
2958
|
-
message: errorUtil.toString(message)
|
|
2959
|
-
});
|
|
2960
|
-
}
|
|
2961
|
-
positive(message) {
|
|
2962
|
-
return this._addCheck({
|
|
2963
|
-
kind: "min",
|
|
2964
|
-
value: 0,
|
|
2965
|
-
inclusive: false,
|
|
2966
|
-
message: errorUtil.toString(message)
|
|
2967
|
-
});
|
|
2968
|
-
}
|
|
2969
|
-
negative(message) {
|
|
2970
|
-
return this._addCheck({
|
|
2971
|
-
kind: "max",
|
|
2972
|
-
value: 0,
|
|
2973
|
-
inclusive: false,
|
|
2974
|
-
message: errorUtil.toString(message)
|
|
2975
|
-
});
|
|
2976
|
-
}
|
|
2977
|
-
nonpositive(message) {
|
|
2978
|
-
return this._addCheck({
|
|
2979
|
-
kind: "max",
|
|
2980
|
-
value: 0,
|
|
2981
|
-
inclusive: true,
|
|
2982
|
-
message: errorUtil.toString(message)
|
|
2983
|
-
});
|
|
2984
|
-
}
|
|
2985
|
-
nonnegative(message) {
|
|
2986
|
-
return this._addCheck({
|
|
2987
|
-
kind: "min",
|
|
2988
|
-
value: 0,
|
|
2989
|
-
inclusive: true,
|
|
2990
|
-
message: errorUtil.toString(message)
|
|
2991
|
-
});
|
|
2992
|
-
}
|
|
2993
|
-
multipleOf(value, message) {
|
|
2994
|
-
return this._addCheck({
|
|
2995
|
-
kind: "multipleOf",
|
|
2996
|
-
value,
|
|
2997
|
-
message: errorUtil.toString(message)
|
|
2998
|
-
});
|
|
2999
|
-
}
|
|
3000
|
-
finite(message) {
|
|
3001
|
-
return this._addCheck({
|
|
3002
|
-
kind: "finite",
|
|
3003
|
-
message: errorUtil.toString(message)
|
|
3004
|
-
});
|
|
3005
|
-
}
|
|
3006
|
-
safe(message) {
|
|
3007
|
-
return this._addCheck({
|
|
3008
|
-
kind: "min",
|
|
3009
|
-
inclusive: true,
|
|
3010
|
-
value: Number.MIN_SAFE_INTEGER,
|
|
3011
|
-
message: errorUtil.toString(message)
|
|
3012
|
-
})._addCheck({
|
|
3013
|
-
kind: "max",
|
|
3014
|
-
inclusive: true,
|
|
3015
|
-
value: Number.MAX_SAFE_INTEGER,
|
|
3016
|
-
message: errorUtil.toString(message)
|
|
3017
|
-
});
|
|
3018
|
-
}
|
|
3019
|
-
get minValue() {
|
|
3020
|
-
let min = null;
|
|
3021
|
-
for (const ch of this._def.checks) {
|
|
3022
|
-
if (ch.kind === "min") {
|
|
3023
|
-
if (min === null || ch.value > min)
|
|
3024
|
-
min = ch.value;
|
|
3025
|
-
}
|
|
3026
|
-
}
|
|
3027
|
-
return min;
|
|
3028
|
-
}
|
|
3029
|
-
get maxValue() {
|
|
3030
|
-
let max = null;
|
|
3031
|
-
for (const ch of this._def.checks) {
|
|
3032
|
-
if (ch.kind === "max") {
|
|
3033
|
-
if (max === null || ch.value < max)
|
|
3034
|
-
max = ch.value;
|
|
3035
|
-
}
|
|
3036
|
-
}
|
|
3037
|
-
return max;
|
|
3038
|
-
}
|
|
3039
|
-
get isInt() {
|
|
3040
|
-
return !!this._def.checks.find((ch) => ch.kind === "int" || ch.kind === "multipleOf" && util.isInteger(ch.value));
|
|
3041
|
-
}
|
|
3042
|
-
get isFinite() {
|
|
3043
|
-
let max = null, min = null;
|
|
3044
|
-
for (const ch of this._def.checks) {
|
|
3045
|
-
if (ch.kind === "finite" || ch.kind === "int" || ch.kind === "multipleOf") {
|
|
3046
|
-
return true;
|
|
3047
|
-
} else if (ch.kind === "min") {
|
|
3048
|
-
if (min === null || ch.value > min)
|
|
3049
|
-
min = ch.value;
|
|
3050
|
-
} else if (ch.kind === "max") {
|
|
3051
|
-
if (max === null || ch.value < max)
|
|
3052
|
-
max = ch.value;
|
|
3053
|
-
}
|
|
3054
|
-
}
|
|
3055
|
-
return Number.isFinite(min) && Number.isFinite(max);
|
|
3056
|
-
}
|
|
3057
|
-
};
|
|
3058
|
-
__name(_ZodNumber, "ZodNumber");
|
|
3059
|
-
var ZodNumber = _ZodNumber;
|
|
3060
|
-
ZodNumber.create = (params) => {
|
|
3061
|
-
return new ZodNumber({
|
|
3062
|
-
checks: [],
|
|
3063
|
-
typeName: ZodFirstPartyTypeKind.ZodNumber,
|
|
3064
|
-
coerce: (params === null || params === void 0 ? void 0 : params.coerce) || false,
|
|
3065
|
-
...processCreateParams(params)
|
|
3066
|
-
});
|
|
3067
|
-
};
|
|
3068
|
-
var _ZodBigInt = class _ZodBigInt extends ZodType {
|
|
3069
|
-
constructor() {
|
|
3070
|
-
super(...arguments);
|
|
3071
|
-
this.min = this.gte;
|
|
3072
|
-
this.max = this.lte;
|
|
3073
|
-
}
|
|
3074
|
-
_parse(input) {
|
|
3075
|
-
if (this._def.coerce) {
|
|
3076
|
-
input.data = BigInt(input.data);
|
|
3077
|
-
}
|
|
3078
|
-
const parsedType = this._getType(input);
|
|
3079
|
-
if (parsedType !== ZodParsedType.bigint) {
|
|
3080
|
-
const ctx2 = this._getOrReturnCtx(input);
|
|
3081
|
-
addIssueToContext(ctx2, {
|
|
3082
|
-
code: ZodIssueCode.invalid_type,
|
|
3083
|
-
expected: ZodParsedType.bigint,
|
|
3084
|
-
received: ctx2.parsedType
|
|
3085
|
-
});
|
|
3086
|
-
return INVALID;
|
|
3087
|
-
}
|
|
3088
|
-
let ctx = void 0;
|
|
3089
|
-
const status = new ParseStatus();
|
|
3090
|
-
for (const check of this._def.checks) {
|
|
3091
|
-
if (check.kind === "min") {
|
|
3092
|
-
const tooSmall = check.inclusive ? input.data < check.value : input.data <= check.value;
|
|
3093
|
-
if (tooSmall) {
|
|
3094
|
-
ctx = this._getOrReturnCtx(input, ctx);
|
|
3095
|
-
addIssueToContext(ctx, {
|
|
3096
|
-
code: ZodIssueCode.too_small,
|
|
3097
|
-
type: "bigint",
|
|
3098
|
-
minimum: check.value,
|
|
3099
|
-
inclusive: check.inclusive,
|
|
3100
|
-
message: check.message
|
|
3101
|
-
});
|
|
3102
|
-
status.dirty();
|
|
3103
|
-
}
|
|
3104
|
-
} else if (check.kind === "max") {
|
|
3105
|
-
const tooBig = check.inclusive ? input.data > check.value : input.data >= check.value;
|
|
3106
|
-
if (tooBig) {
|
|
3107
|
-
ctx = this._getOrReturnCtx(input, ctx);
|
|
3108
|
-
addIssueToContext(ctx, {
|
|
3109
|
-
code: ZodIssueCode.too_big,
|
|
3110
|
-
type: "bigint",
|
|
3111
|
-
maximum: check.value,
|
|
3112
|
-
inclusive: check.inclusive,
|
|
3113
|
-
message: check.message
|
|
3114
|
-
});
|
|
3115
|
-
status.dirty();
|
|
3116
|
-
}
|
|
3117
|
-
} else if (check.kind === "multipleOf") {
|
|
3118
|
-
if (input.data % check.value !== BigInt(0)) {
|
|
3119
|
-
ctx = this._getOrReturnCtx(input, ctx);
|
|
3120
|
-
addIssueToContext(ctx, {
|
|
3121
|
-
code: ZodIssueCode.not_multiple_of,
|
|
3122
|
-
multipleOf: check.value,
|
|
3123
|
-
message: check.message
|
|
3124
|
-
});
|
|
3125
|
-
status.dirty();
|
|
3126
|
-
}
|
|
3127
|
-
} else {
|
|
3128
|
-
util.assertNever(check);
|
|
3129
|
-
}
|
|
3130
|
-
}
|
|
3131
|
-
return { status: status.value, value: input.data };
|
|
3132
|
-
}
|
|
3133
|
-
gte(value, message) {
|
|
3134
|
-
return this.setLimit("min", value, true, errorUtil.toString(message));
|
|
3135
|
-
}
|
|
3136
|
-
gt(value, message) {
|
|
3137
|
-
return this.setLimit("min", value, false, errorUtil.toString(message));
|
|
3138
|
-
}
|
|
3139
|
-
lte(value, message) {
|
|
3140
|
-
return this.setLimit("max", value, true, errorUtil.toString(message));
|
|
3141
|
-
}
|
|
3142
|
-
lt(value, message) {
|
|
3143
|
-
return this.setLimit("max", value, false, errorUtil.toString(message));
|
|
3144
|
-
}
|
|
3145
|
-
setLimit(kind, value, inclusive, message) {
|
|
3146
|
-
return new _ZodBigInt({
|
|
3147
|
-
...this._def,
|
|
3148
|
-
checks: [
|
|
3149
|
-
...this._def.checks,
|
|
3150
|
-
{
|
|
3151
|
-
kind,
|
|
3152
|
-
value,
|
|
3153
|
-
inclusive,
|
|
3154
|
-
message: errorUtil.toString(message)
|
|
3155
|
-
}
|
|
3156
|
-
]
|
|
3157
|
-
});
|
|
3158
|
-
}
|
|
3159
|
-
_addCheck(check) {
|
|
3160
|
-
return new _ZodBigInt({
|
|
3161
|
-
...this._def,
|
|
3162
|
-
checks: [...this._def.checks, check]
|
|
3163
|
-
});
|
|
3164
|
-
}
|
|
3165
|
-
positive(message) {
|
|
3166
|
-
return this._addCheck({
|
|
3167
|
-
kind: "min",
|
|
3168
|
-
value: BigInt(0),
|
|
3169
|
-
inclusive: false,
|
|
3170
|
-
message: errorUtil.toString(message)
|
|
3171
|
-
});
|
|
3172
|
-
}
|
|
3173
|
-
negative(message) {
|
|
3174
|
-
return this._addCheck({
|
|
3175
|
-
kind: "max",
|
|
3176
|
-
value: BigInt(0),
|
|
3177
|
-
inclusive: false,
|
|
3178
|
-
message: errorUtil.toString(message)
|
|
3179
|
-
});
|
|
3180
|
-
}
|
|
3181
|
-
nonpositive(message) {
|
|
3182
|
-
return this._addCheck({
|
|
3183
|
-
kind: "max",
|
|
3184
|
-
value: BigInt(0),
|
|
3185
|
-
inclusive: true,
|
|
3186
|
-
message: errorUtil.toString(message)
|
|
3187
|
-
});
|
|
3188
|
-
}
|
|
3189
|
-
nonnegative(message) {
|
|
3190
|
-
return this._addCheck({
|
|
3191
|
-
kind: "min",
|
|
3192
|
-
value: BigInt(0),
|
|
3193
|
-
inclusive: true,
|
|
3194
|
-
message: errorUtil.toString(message)
|
|
3195
|
-
});
|
|
3196
|
-
}
|
|
3197
|
-
multipleOf(value, message) {
|
|
3198
|
-
return this._addCheck({
|
|
3199
|
-
kind: "multipleOf",
|
|
3200
|
-
value,
|
|
3201
|
-
message: errorUtil.toString(message)
|
|
3202
|
-
});
|
|
3203
|
-
}
|
|
3204
|
-
get minValue() {
|
|
3205
|
-
let min = null;
|
|
3206
|
-
for (const ch of this._def.checks) {
|
|
3207
|
-
if (ch.kind === "min") {
|
|
3208
|
-
if (min === null || ch.value > min)
|
|
3209
|
-
min = ch.value;
|
|
3210
|
-
}
|
|
3211
|
-
}
|
|
3212
|
-
return min;
|
|
3213
|
-
}
|
|
3214
|
-
get maxValue() {
|
|
3215
|
-
let max = null;
|
|
3216
|
-
for (const ch of this._def.checks) {
|
|
3217
|
-
if (ch.kind === "max") {
|
|
3218
|
-
if (max === null || ch.value < max)
|
|
3219
|
-
max = ch.value;
|
|
3220
|
-
}
|
|
3221
|
-
}
|
|
3222
|
-
return max;
|
|
3223
|
-
}
|
|
3224
|
-
};
|
|
3225
|
-
__name(_ZodBigInt, "ZodBigInt");
|
|
3226
|
-
var ZodBigInt = _ZodBigInt;
|
|
3227
|
-
ZodBigInt.create = (params) => {
|
|
3228
|
-
var _a;
|
|
3229
|
-
return new ZodBigInt({
|
|
3230
|
-
checks: [],
|
|
3231
|
-
typeName: ZodFirstPartyTypeKind.ZodBigInt,
|
|
3232
|
-
coerce: (_a = params === null || params === void 0 ? void 0 : params.coerce) !== null && _a !== void 0 ? _a : false,
|
|
3233
|
-
...processCreateParams(params)
|
|
3234
|
-
});
|
|
3235
|
-
};
|
|
3236
|
-
var _ZodBoolean = class _ZodBoolean extends ZodType {
|
|
3237
|
-
_parse(input) {
|
|
3238
|
-
if (this._def.coerce) {
|
|
3239
|
-
input.data = Boolean(input.data);
|
|
3240
|
-
}
|
|
3241
|
-
const parsedType = this._getType(input);
|
|
3242
|
-
if (parsedType !== ZodParsedType.boolean) {
|
|
3243
|
-
const ctx = this._getOrReturnCtx(input);
|
|
3244
|
-
addIssueToContext(ctx, {
|
|
3245
|
-
code: ZodIssueCode.invalid_type,
|
|
3246
|
-
expected: ZodParsedType.boolean,
|
|
3247
|
-
received: ctx.parsedType
|
|
3248
|
-
});
|
|
3249
|
-
return INVALID;
|
|
3250
|
-
}
|
|
3251
|
-
return OK(input.data);
|
|
3252
|
-
}
|
|
3253
|
-
};
|
|
3254
|
-
__name(_ZodBoolean, "ZodBoolean");
|
|
3255
|
-
var ZodBoolean = _ZodBoolean;
|
|
3256
|
-
ZodBoolean.create = (params) => {
|
|
3257
|
-
return new ZodBoolean({
|
|
3258
|
-
typeName: ZodFirstPartyTypeKind.ZodBoolean,
|
|
3259
|
-
coerce: (params === null || params === void 0 ? void 0 : params.coerce) || false,
|
|
3260
|
-
...processCreateParams(params)
|
|
3261
|
-
});
|
|
3262
|
-
};
|
|
3263
|
-
var _ZodDate = class _ZodDate extends ZodType {
|
|
3264
|
-
_parse(input) {
|
|
3265
|
-
if (this._def.coerce) {
|
|
3266
|
-
input.data = new Date(input.data);
|
|
3267
|
-
}
|
|
3268
|
-
const parsedType = this._getType(input);
|
|
3269
|
-
if (parsedType !== ZodParsedType.date) {
|
|
3270
|
-
const ctx2 = this._getOrReturnCtx(input);
|
|
3271
|
-
addIssueToContext(ctx2, {
|
|
3272
|
-
code: ZodIssueCode.invalid_type,
|
|
3273
|
-
expected: ZodParsedType.date,
|
|
3274
|
-
received: ctx2.parsedType
|
|
3275
|
-
});
|
|
3276
|
-
return INVALID;
|
|
3277
|
-
}
|
|
3278
|
-
if (isNaN(input.data.getTime())) {
|
|
3279
|
-
const ctx2 = this._getOrReturnCtx(input);
|
|
3280
|
-
addIssueToContext(ctx2, {
|
|
3281
|
-
code: ZodIssueCode.invalid_date
|
|
3282
|
-
});
|
|
3283
|
-
return INVALID;
|
|
3284
|
-
}
|
|
3285
|
-
const status = new ParseStatus();
|
|
3286
|
-
let ctx = void 0;
|
|
3287
|
-
for (const check of this._def.checks) {
|
|
3288
|
-
if (check.kind === "min") {
|
|
3289
|
-
if (input.data.getTime() < check.value) {
|
|
3290
|
-
ctx = this._getOrReturnCtx(input, ctx);
|
|
3291
|
-
addIssueToContext(ctx, {
|
|
3292
|
-
code: ZodIssueCode.too_small,
|
|
3293
|
-
message: check.message,
|
|
3294
|
-
inclusive: true,
|
|
3295
|
-
exact: false,
|
|
3296
|
-
minimum: check.value,
|
|
3297
|
-
type: "date"
|
|
3298
|
-
});
|
|
3299
|
-
status.dirty();
|
|
3300
|
-
}
|
|
3301
|
-
} else if (check.kind === "max") {
|
|
3302
|
-
if (input.data.getTime() > check.value) {
|
|
3303
|
-
ctx = this._getOrReturnCtx(input, ctx);
|
|
3304
|
-
addIssueToContext(ctx, {
|
|
3305
|
-
code: ZodIssueCode.too_big,
|
|
3306
|
-
message: check.message,
|
|
3307
|
-
inclusive: true,
|
|
3308
|
-
exact: false,
|
|
3309
|
-
maximum: check.value,
|
|
3310
|
-
type: "date"
|
|
3311
|
-
});
|
|
3312
|
-
status.dirty();
|
|
3313
|
-
}
|
|
3314
|
-
} else {
|
|
3315
|
-
util.assertNever(check);
|
|
3316
|
-
}
|
|
3317
|
-
}
|
|
3318
|
-
return {
|
|
3319
|
-
status: status.value,
|
|
3320
|
-
value: new Date(input.data.getTime())
|
|
3321
|
-
};
|
|
3322
|
-
}
|
|
3323
|
-
_addCheck(check) {
|
|
3324
|
-
return new _ZodDate({
|
|
3325
|
-
...this._def,
|
|
3326
|
-
checks: [...this._def.checks, check]
|
|
3327
|
-
});
|
|
3328
|
-
}
|
|
3329
|
-
min(minDate, message) {
|
|
3330
|
-
return this._addCheck({
|
|
3331
|
-
kind: "min",
|
|
3332
|
-
value: minDate.getTime(),
|
|
3333
|
-
message: errorUtil.toString(message)
|
|
3334
|
-
});
|
|
3335
|
-
}
|
|
3336
|
-
max(maxDate, message) {
|
|
3337
|
-
return this._addCheck({
|
|
3338
|
-
kind: "max",
|
|
3339
|
-
value: maxDate.getTime(),
|
|
3340
|
-
message: errorUtil.toString(message)
|
|
3341
|
-
});
|
|
3342
|
-
}
|
|
3343
|
-
get minDate() {
|
|
3344
|
-
let min = null;
|
|
3345
|
-
for (const ch of this._def.checks) {
|
|
3346
|
-
if (ch.kind === "min") {
|
|
3347
|
-
if (min === null || ch.value > min)
|
|
3348
|
-
min = ch.value;
|
|
3349
|
-
}
|
|
3350
|
-
}
|
|
3351
|
-
return min != null ? new Date(min) : null;
|
|
3352
|
-
}
|
|
3353
|
-
get maxDate() {
|
|
3354
|
-
let max = null;
|
|
3355
|
-
for (const ch of this._def.checks) {
|
|
3356
|
-
if (ch.kind === "max") {
|
|
3357
|
-
if (max === null || ch.value < max)
|
|
3358
|
-
max = ch.value;
|
|
3359
|
-
}
|
|
3360
|
-
}
|
|
3361
|
-
return max != null ? new Date(max) : null;
|
|
3362
|
-
}
|
|
3363
|
-
};
|
|
3364
|
-
__name(_ZodDate, "ZodDate");
|
|
3365
|
-
var ZodDate = _ZodDate;
|
|
3366
|
-
ZodDate.create = (params) => {
|
|
3367
|
-
return new ZodDate({
|
|
3368
|
-
checks: [],
|
|
3369
|
-
coerce: (params === null || params === void 0 ? void 0 : params.coerce) || false,
|
|
3370
|
-
typeName: ZodFirstPartyTypeKind.ZodDate,
|
|
3371
|
-
...processCreateParams(params)
|
|
3372
|
-
});
|
|
3373
|
-
};
|
|
3374
|
-
var _ZodSymbol = class _ZodSymbol extends ZodType {
|
|
3375
|
-
_parse(input) {
|
|
3376
|
-
const parsedType = this._getType(input);
|
|
3377
|
-
if (parsedType !== ZodParsedType.symbol) {
|
|
3378
|
-
const ctx = this._getOrReturnCtx(input);
|
|
3379
|
-
addIssueToContext(ctx, {
|
|
3380
|
-
code: ZodIssueCode.invalid_type,
|
|
3381
|
-
expected: ZodParsedType.symbol,
|
|
3382
|
-
received: ctx.parsedType
|
|
3383
|
-
});
|
|
3384
|
-
return INVALID;
|
|
3385
|
-
}
|
|
3386
|
-
return OK(input.data);
|
|
3387
|
-
}
|
|
3388
|
-
};
|
|
3389
|
-
__name(_ZodSymbol, "ZodSymbol");
|
|
3390
|
-
var ZodSymbol = _ZodSymbol;
|
|
3391
|
-
ZodSymbol.create = (params) => {
|
|
3392
|
-
return new ZodSymbol({
|
|
3393
|
-
typeName: ZodFirstPartyTypeKind.ZodSymbol,
|
|
3394
|
-
...processCreateParams(params)
|
|
3395
|
-
});
|
|
3396
|
-
};
|
|
3397
|
-
var _ZodUndefined = class _ZodUndefined extends ZodType {
|
|
3398
|
-
_parse(input) {
|
|
3399
|
-
const parsedType = this._getType(input);
|
|
3400
|
-
if (parsedType !== ZodParsedType.undefined) {
|
|
3401
|
-
const ctx = this._getOrReturnCtx(input);
|
|
3402
|
-
addIssueToContext(ctx, {
|
|
3403
|
-
code: ZodIssueCode.invalid_type,
|
|
3404
|
-
expected: ZodParsedType.undefined,
|
|
3405
|
-
received: ctx.parsedType
|
|
3406
|
-
});
|
|
3407
|
-
return INVALID;
|
|
3408
|
-
}
|
|
3409
|
-
return OK(input.data);
|
|
3410
|
-
}
|
|
3411
|
-
};
|
|
3412
|
-
__name(_ZodUndefined, "ZodUndefined");
|
|
3413
|
-
var ZodUndefined = _ZodUndefined;
|
|
3414
|
-
ZodUndefined.create = (params) => {
|
|
3415
|
-
return new ZodUndefined({
|
|
3416
|
-
typeName: ZodFirstPartyTypeKind.ZodUndefined,
|
|
3417
|
-
...processCreateParams(params)
|
|
3418
|
-
});
|
|
3419
|
-
};
|
|
3420
|
-
var _ZodNull = class _ZodNull extends ZodType {
|
|
3421
|
-
_parse(input) {
|
|
3422
|
-
const parsedType = this._getType(input);
|
|
3423
|
-
if (parsedType !== ZodParsedType.null) {
|
|
3424
|
-
const ctx = this._getOrReturnCtx(input);
|
|
3425
|
-
addIssueToContext(ctx, {
|
|
3426
|
-
code: ZodIssueCode.invalid_type,
|
|
3427
|
-
expected: ZodParsedType.null,
|
|
3428
|
-
received: ctx.parsedType
|
|
3429
|
-
});
|
|
3430
|
-
return INVALID;
|
|
3431
|
-
}
|
|
3432
|
-
return OK(input.data);
|
|
3433
|
-
}
|
|
3434
|
-
};
|
|
3435
|
-
__name(_ZodNull, "ZodNull");
|
|
3436
|
-
var ZodNull = _ZodNull;
|
|
3437
|
-
ZodNull.create = (params) => {
|
|
3438
|
-
return new ZodNull({
|
|
3439
|
-
typeName: ZodFirstPartyTypeKind.ZodNull,
|
|
3440
|
-
...processCreateParams(params)
|
|
3441
|
-
});
|
|
3442
|
-
};
|
|
3443
|
-
var _ZodAny = class _ZodAny extends ZodType {
|
|
3444
|
-
constructor() {
|
|
3445
|
-
super(...arguments);
|
|
3446
|
-
this._any = true;
|
|
3447
|
-
}
|
|
3448
|
-
_parse(input) {
|
|
3449
|
-
return OK(input.data);
|
|
3450
|
-
}
|
|
3451
|
-
};
|
|
3452
|
-
__name(_ZodAny, "ZodAny");
|
|
3453
|
-
var ZodAny = _ZodAny;
|
|
3454
|
-
ZodAny.create = (params) => {
|
|
3455
|
-
return new ZodAny({
|
|
3456
|
-
typeName: ZodFirstPartyTypeKind.ZodAny,
|
|
3457
|
-
...processCreateParams(params)
|
|
3458
|
-
});
|
|
3459
|
-
};
|
|
3460
|
-
var _ZodUnknown = class _ZodUnknown extends ZodType {
|
|
3461
|
-
constructor() {
|
|
3462
|
-
super(...arguments);
|
|
3463
|
-
this._unknown = true;
|
|
3464
|
-
}
|
|
3465
|
-
_parse(input) {
|
|
3466
|
-
return OK(input.data);
|
|
3467
|
-
}
|
|
3468
|
-
};
|
|
3469
|
-
__name(_ZodUnknown, "ZodUnknown");
|
|
3470
|
-
var ZodUnknown = _ZodUnknown;
|
|
3471
|
-
ZodUnknown.create = (params) => {
|
|
3472
|
-
return new ZodUnknown({
|
|
3473
|
-
typeName: ZodFirstPartyTypeKind.ZodUnknown,
|
|
3474
|
-
...processCreateParams(params)
|
|
3475
|
-
});
|
|
3476
|
-
};
|
|
3477
|
-
var _ZodNever = class _ZodNever extends ZodType {
|
|
3478
|
-
_parse(input) {
|
|
3479
|
-
const ctx = this._getOrReturnCtx(input);
|
|
3480
|
-
addIssueToContext(ctx, {
|
|
3481
|
-
code: ZodIssueCode.invalid_type,
|
|
3482
|
-
expected: ZodParsedType.never,
|
|
3483
|
-
received: ctx.parsedType
|
|
3484
|
-
});
|
|
3485
|
-
return INVALID;
|
|
3486
|
-
}
|
|
3487
|
-
};
|
|
3488
|
-
__name(_ZodNever, "ZodNever");
|
|
3489
|
-
var ZodNever = _ZodNever;
|
|
3490
|
-
ZodNever.create = (params) => {
|
|
3491
|
-
return new ZodNever({
|
|
3492
|
-
typeName: ZodFirstPartyTypeKind.ZodNever,
|
|
3493
|
-
...processCreateParams(params)
|
|
3494
|
-
});
|
|
3495
|
-
};
|
|
3496
|
-
var _ZodVoid = class _ZodVoid extends ZodType {
|
|
3497
|
-
_parse(input) {
|
|
3498
|
-
const parsedType = this._getType(input);
|
|
3499
|
-
if (parsedType !== ZodParsedType.undefined) {
|
|
3500
|
-
const ctx = this._getOrReturnCtx(input);
|
|
3501
|
-
addIssueToContext(ctx, {
|
|
3502
|
-
code: ZodIssueCode.invalid_type,
|
|
3503
|
-
expected: ZodParsedType.void,
|
|
3504
|
-
received: ctx.parsedType
|
|
3505
|
-
});
|
|
3506
|
-
return INVALID;
|
|
3507
|
-
}
|
|
3508
|
-
return OK(input.data);
|
|
3509
|
-
}
|
|
3510
|
-
};
|
|
3511
|
-
__name(_ZodVoid, "ZodVoid");
|
|
3512
|
-
var ZodVoid = _ZodVoid;
|
|
3513
|
-
ZodVoid.create = (params) => {
|
|
3514
|
-
return new ZodVoid({
|
|
3515
|
-
typeName: ZodFirstPartyTypeKind.ZodVoid,
|
|
3516
|
-
...processCreateParams(params)
|
|
3517
|
-
});
|
|
3518
|
-
};
|
|
3519
|
-
var _ZodArray = class _ZodArray extends ZodType {
|
|
3520
|
-
_parse(input) {
|
|
3521
|
-
const { ctx, status } = this._processInputParams(input);
|
|
3522
|
-
const def = this._def;
|
|
3523
|
-
if (ctx.parsedType !== ZodParsedType.array) {
|
|
3524
|
-
addIssueToContext(ctx, {
|
|
3525
|
-
code: ZodIssueCode.invalid_type,
|
|
3526
|
-
expected: ZodParsedType.array,
|
|
3527
|
-
received: ctx.parsedType
|
|
3528
|
-
});
|
|
3529
|
-
return INVALID;
|
|
3530
|
-
}
|
|
3531
|
-
if (def.exactLength !== null) {
|
|
3532
|
-
const tooBig = ctx.data.length > def.exactLength.value;
|
|
3533
|
-
const tooSmall = ctx.data.length < def.exactLength.value;
|
|
3534
|
-
if (tooBig || tooSmall) {
|
|
3535
|
-
addIssueToContext(ctx, {
|
|
3536
|
-
code: tooBig ? ZodIssueCode.too_big : ZodIssueCode.too_small,
|
|
3537
|
-
minimum: tooSmall ? def.exactLength.value : void 0,
|
|
3538
|
-
maximum: tooBig ? def.exactLength.value : void 0,
|
|
3539
|
-
type: "array",
|
|
3540
|
-
inclusive: true,
|
|
3541
|
-
exact: true,
|
|
3542
|
-
message: def.exactLength.message
|
|
3543
|
-
});
|
|
3544
|
-
status.dirty();
|
|
3545
|
-
}
|
|
3546
|
-
}
|
|
3547
|
-
if (def.minLength !== null) {
|
|
3548
|
-
if (ctx.data.length < def.minLength.value) {
|
|
3549
|
-
addIssueToContext(ctx, {
|
|
3550
|
-
code: ZodIssueCode.too_small,
|
|
3551
|
-
minimum: def.minLength.value,
|
|
3552
|
-
type: "array",
|
|
3553
|
-
inclusive: true,
|
|
3554
|
-
exact: false,
|
|
3555
|
-
message: def.minLength.message
|
|
3556
|
-
});
|
|
3557
|
-
status.dirty();
|
|
3558
|
-
}
|
|
3559
|
-
}
|
|
3560
|
-
if (def.maxLength !== null) {
|
|
3561
|
-
if (ctx.data.length > def.maxLength.value) {
|
|
3562
|
-
addIssueToContext(ctx, {
|
|
3563
|
-
code: ZodIssueCode.too_big,
|
|
3564
|
-
maximum: def.maxLength.value,
|
|
3565
|
-
type: "array",
|
|
3566
|
-
inclusive: true,
|
|
3567
|
-
exact: false,
|
|
3568
|
-
message: def.maxLength.message
|
|
3569
|
-
});
|
|
3570
|
-
status.dirty();
|
|
3571
|
-
}
|
|
3572
|
-
}
|
|
3573
|
-
if (ctx.common.async) {
|
|
3574
|
-
return Promise.all([...ctx.data].map((item, i) => {
|
|
3575
|
-
return def.type._parseAsync(new ParseInputLazyPath(ctx, item, ctx.path, i));
|
|
3576
|
-
})).then((result2) => {
|
|
3577
|
-
return ParseStatus.mergeArray(status, result2);
|
|
3578
|
-
});
|
|
3579
|
-
}
|
|
3580
|
-
const result = [...ctx.data].map((item, i) => {
|
|
3581
|
-
return def.type._parseSync(new ParseInputLazyPath(ctx, item, ctx.path, i));
|
|
3582
|
-
});
|
|
3583
|
-
return ParseStatus.mergeArray(status, result);
|
|
3584
|
-
}
|
|
3585
|
-
get element() {
|
|
3586
|
-
return this._def.type;
|
|
3587
|
-
}
|
|
3588
|
-
min(minLength, message) {
|
|
3589
|
-
return new _ZodArray({
|
|
3590
|
-
...this._def,
|
|
3591
|
-
minLength: { value: minLength, message: errorUtil.toString(message) }
|
|
3592
|
-
});
|
|
3593
|
-
}
|
|
3594
|
-
max(maxLength, message) {
|
|
3595
|
-
return new _ZodArray({
|
|
3596
|
-
...this._def,
|
|
3597
|
-
maxLength: { value: maxLength, message: errorUtil.toString(message) }
|
|
3598
|
-
});
|
|
3599
|
-
}
|
|
3600
|
-
length(len, message) {
|
|
3601
|
-
return new _ZodArray({
|
|
3602
|
-
...this._def,
|
|
3603
|
-
exactLength: { value: len, message: errorUtil.toString(message) }
|
|
3604
|
-
});
|
|
3605
|
-
}
|
|
3606
|
-
nonempty(message) {
|
|
3607
|
-
return this.min(1, message);
|
|
3608
|
-
}
|
|
3609
|
-
};
|
|
3610
|
-
__name(_ZodArray, "ZodArray");
|
|
3611
|
-
var ZodArray = _ZodArray;
|
|
3612
|
-
ZodArray.create = (schema, params) => {
|
|
3613
|
-
return new ZodArray({
|
|
3614
|
-
type: schema,
|
|
3615
|
-
minLength: null,
|
|
3616
|
-
maxLength: null,
|
|
3617
|
-
exactLength: null,
|
|
3618
|
-
typeName: ZodFirstPartyTypeKind.ZodArray,
|
|
3619
|
-
...processCreateParams(params)
|
|
3620
|
-
});
|
|
3621
|
-
};
|
|
3622
|
-
function deepPartialify(schema) {
|
|
3623
|
-
if (schema instanceof ZodObject) {
|
|
3624
|
-
const newShape = {};
|
|
3625
|
-
for (const key in schema.shape) {
|
|
3626
|
-
const fieldSchema = schema.shape[key];
|
|
3627
|
-
newShape[key] = ZodOptional.create(deepPartialify(fieldSchema));
|
|
3628
|
-
}
|
|
3629
|
-
return new ZodObject({
|
|
3630
|
-
...schema._def,
|
|
3631
|
-
shape: () => newShape
|
|
3632
|
-
});
|
|
3633
|
-
} else if (schema instanceof ZodArray) {
|
|
3634
|
-
return new ZodArray({
|
|
3635
|
-
...schema._def,
|
|
3636
|
-
type: deepPartialify(schema.element)
|
|
3637
|
-
});
|
|
3638
|
-
} else if (schema instanceof ZodOptional) {
|
|
3639
|
-
return ZodOptional.create(deepPartialify(schema.unwrap()));
|
|
3640
|
-
} else if (schema instanceof ZodNullable) {
|
|
3641
|
-
return ZodNullable.create(deepPartialify(schema.unwrap()));
|
|
3642
|
-
} else if (schema instanceof ZodTuple) {
|
|
3643
|
-
return ZodTuple.create(schema.items.map((item) => deepPartialify(item)));
|
|
3644
|
-
} else {
|
|
3645
|
-
return schema;
|
|
3646
|
-
}
|
|
3647
|
-
}
|
|
3648
|
-
__name(deepPartialify, "deepPartialify");
|
|
3649
|
-
var _ZodObject = class _ZodObject extends ZodType {
|
|
3650
|
-
constructor() {
|
|
3651
|
-
super(...arguments);
|
|
3652
|
-
this._cached = null;
|
|
3653
|
-
this.nonstrict = this.passthrough;
|
|
3654
|
-
this.augment = this.extend;
|
|
3655
|
-
}
|
|
3656
|
-
_getCached() {
|
|
3657
|
-
if (this._cached !== null)
|
|
3658
|
-
return this._cached;
|
|
3659
|
-
const shape = this._def.shape();
|
|
3660
|
-
const keys = util.objectKeys(shape);
|
|
3661
|
-
return this._cached = { shape, keys };
|
|
3662
|
-
}
|
|
3663
|
-
_parse(input) {
|
|
3664
|
-
const parsedType = this._getType(input);
|
|
3665
|
-
if (parsedType !== ZodParsedType.object) {
|
|
3666
|
-
const ctx2 = this._getOrReturnCtx(input);
|
|
3667
|
-
addIssueToContext(ctx2, {
|
|
3668
|
-
code: ZodIssueCode.invalid_type,
|
|
3669
|
-
expected: ZodParsedType.object,
|
|
3670
|
-
received: ctx2.parsedType
|
|
3671
|
-
});
|
|
3672
|
-
return INVALID;
|
|
3673
|
-
}
|
|
3674
|
-
const { status, ctx } = this._processInputParams(input);
|
|
3675
|
-
const { shape, keys: shapeKeys } = this._getCached();
|
|
3676
|
-
const extraKeys = [];
|
|
3677
|
-
if (!(this._def.catchall instanceof ZodNever && this._def.unknownKeys === "strip")) {
|
|
3678
|
-
for (const key in ctx.data) {
|
|
3679
|
-
if (!shapeKeys.includes(key)) {
|
|
3680
|
-
extraKeys.push(key);
|
|
3681
|
-
}
|
|
3682
|
-
}
|
|
3683
|
-
}
|
|
3684
|
-
const pairs = [];
|
|
3685
|
-
for (const key of shapeKeys) {
|
|
3686
|
-
const keyValidator = shape[key];
|
|
3687
|
-
const value = ctx.data[key];
|
|
3688
|
-
pairs.push({
|
|
3689
|
-
key: { status: "valid", value: key },
|
|
3690
|
-
value: keyValidator._parse(new ParseInputLazyPath(ctx, value, ctx.path, key)),
|
|
3691
|
-
alwaysSet: key in ctx.data
|
|
3692
|
-
});
|
|
3693
|
-
}
|
|
3694
|
-
if (this._def.catchall instanceof ZodNever) {
|
|
3695
|
-
const unknownKeys = this._def.unknownKeys;
|
|
3696
|
-
if (unknownKeys === "passthrough") {
|
|
3697
|
-
for (const key of extraKeys) {
|
|
3698
|
-
pairs.push({
|
|
3699
|
-
key: { status: "valid", value: key },
|
|
3700
|
-
value: { status: "valid", value: ctx.data[key] }
|
|
3701
|
-
});
|
|
3702
|
-
}
|
|
3703
|
-
} else if (unknownKeys === "strict") {
|
|
3704
|
-
if (extraKeys.length > 0) {
|
|
3705
|
-
addIssueToContext(ctx, {
|
|
3706
|
-
code: ZodIssueCode.unrecognized_keys,
|
|
3707
|
-
keys: extraKeys
|
|
3708
|
-
});
|
|
3709
|
-
status.dirty();
|
|
3710
|
-
}
|
|
3711
|
-
} else if (unknownKeys === "strip")
|
|
3712
|
-
;
|
|
3713
|
-
else {
|
|
3714
|
-
throw new Error(`Internal ZodObject error: invalid unknownKeys value.`);
|
|
3715
|
-
}
|
|
3716
|
-
} else {
|
|
3717
|
-
const catchall = this._def.catchall;
|
|
3718
|
-
for (const key of extraKeys) {
|
|
3719
|
-
const value = ctx.data[key];
|
|
3720
|
-
pairs.push({
|
|
3721
|
-
key: { status: "valid", value: key },
|
|
3722
|
-
value: catchall._parse(
|
|
3723
|
-
new ParseInputLazyPath(ctx, value, ctx.path, key)
|
|
3724
|
-
//, ctx.child(key), value, getParsedType(value)
|
|
3725
|
-
),
|
|
3726
|
-
alwaysSet: key in ctx.data
|
|
3727
|
-
});
|
|
3728
|
-
}
|
|
3729
|
-
}
|
|
3730
|
-
if (ctx.common.async) {
|
|
3731
|
-
return Promise.resolve().then(async () => {
|
|
3732
|
-
const syncPairs = [];
|
|
3733
|
-
for (const pair of pairs) {
|
|
3734
|
-
const key = await pair.key;
|
|
3735
|
-
const value = await pair.value;
|
|
3736
|
-
syncPairs.push({
|
|
3737
|
-
key,
|
|
3738
|
-
value,
|
|
3739
|
-
alwaysSet: pair.alwaysSet
|
|
3740
|
-
});
|
|
3741
|
-
}
|
|
3742
|
-
return syncPairs;
|
|
3743
|
-
}).then((syncPairs) => {
|
|
3744
|
-
return ParseStatus.mergeObjectSync(status, syncPairs);
|
|
3745
|
-
});
|
|
3746
|
-
} else {
|
|
3747
|
-
return ParseStatus.mergeObjectSync(status, pairs);
|
|
3748
|
-
}
|
|
3749
|
-
}
|
|
3750
|
-
get shape() {
|
|
3751
|
-
return this._def.shape();
|
|
3752
|
-
}
|
|
3753
|
-
strict(message) {
|
|
3754
|
-
errorUtil.errToObj;
|
|
3755
|
-
return new _ZodObject({
|
|
3756
|
-
...this._def,
|
|
3757
|
-
unknownKeys: "strict",
|
|
3758
|
-
...message !== void 0 ? {
|
|
3759
|
-
errorMap: (issue, ctx) => {
|
|
3760
|
-
var _a, _b, _c, _d;
|
|
3761
|
-
const defaultError = (_c = (_b = (_a = this._def).errorMap) === null || _b === void 0 ? void 0 : _b.call(_a, issue, ctx).message) !== null && _c !== void 0 ? _c : ctx.defaultError;
|
|
3762
|
-
if (issue.code === "unrecognized_keys")
|
|
3763
|
-
return {
|
|
3764
|
-
message: (_d = errorUtil.errToObj(message).message) !== null && _d !== void 0 ? _d : defaultError
|
|
3765
|
-
};
|
|
3766
|
-
return {
|
|
3767
|
-
message: defaultError
|
|
3768
|
-
};
|
|
3769
|
-
}
|
|
3770
|
-
} : {}
|
|
3771
|
-
});
|
|
3772
|
-
}
|
|
3773
|
-
strip() {
|
|
3774
|
-
return new _ZodObject({
|
|
3775
|
-
...this._def,
|
|
3776
|
-
unknownKeys: "strip"
|
|
3777
|
-
});
|
|
3778
|
-
}
|
|
3779
|
-
passthrough() {
|
|
3780
|
-
return new _ZodObject({
|
|
3781
|
-
...this._def,
|
|
3782
|
-
unknownKeys: "passthrough"
|
|
3783
|
-
});
|
|
3784
|
-
}
|
|
3785
|
-
// const AugmentFactory =
|
|
3786
|
-
// <Def extends ZodObjectDef>(def: Def) =>
|
|
3787
|
-
// <Augmentation extends ZodRawShape>(
|
|
3788
|
-
// augmentation: Augmentation
|
|
3789
|
-
// ): ZodObject<
|
|
3790
|
-
// extendShape<ReturnType<Def["shape"]>, Augmentation>,
|
|
3791
|
-
// Def["unknownKeys"],
|
|
3792
|
-
// Def["catchall"]
|
|
3793
|
-
// > => {
|
|
3794
|
-
// return new ZodObject({
|
|
3795
|
-
// ...def,
|
|
3796
|
-
// shape: () => ({
|
|
3797
|
-
// ...def.shape(),
|
|
3798
|
-
// ...augmentation,
|
|
3799
|
-
// }),
|
|
3800
|
-
// }) as any;
|
|
3801
|
-
// };
|
|
3802
|
-
extend(augmentation) {
|
|
3803
|
-
return new _ZodObject({
|
|
3804
|
-
...this._def,
|
|
3805
|
-
shape: () => ({
|
|
3806
|
-
...this._def.shape(),
|
|
3807
|
-
...augmentation
|
|
3808
|
-
})
|
|
3809
|
-
});
|
|
3810
|
-
}
|
|
3811
|
-
/**
|
|
3812
|
-
* Prior to zod@1.0.12 there was a bug in the
|
|
3813
|
-
* inferred type of merged objects. Please
|
|
3814
|
-
* upgrade if you are experiencing issues.
|
|
3815
|
-
*/
|
|
3816
|
-
merge(merging) {
|
|
3817
|
-
const merged = new _ZodObject({
|
|
3818
|
-
unknownKeys: merging._def.unknownKeys,
|
|
3819
|
-
catchall: merging._def.catchall,
|
|
3820
|
-
shape: () => ({
|
|
3821
|
-
...this._def.shape(),
|
|
3822
|
-
...merging._def.shape()
|
|
3823
|
-
}),
|
|
3824
|
-
typeName: ZodFirstPartyTypeKind.ZodObject
|
|
3825
|
-
});
|
|
3826
|
-
return merged;
|
|
3827
|
-
}
|
|
3828
|
-
// merge<
|
|
3829
|
-
// Incoming extends AnyZodObject,
|
|
3830
|
-
// Augmentation extends Incoming["shape"],
|
|
3831
|
-
// NewOutput extends {
|
|
3832
|
-
// [k in keyof Augmentation | keyof Output]: k extends keyof Augmentation
|
|
3833
|
-
// ? Augmentation[k]["_output"]
|
|
3834
|
-
// : k extends keyof Output
|
|
3835
|
-
// ? Output[k]
|
|
3836
|
-
// : never;
|
|
3837
|
-
// },
|
|
3838
|
-
// NewInput extends {
|
|
3839
|
-
// [k in keyof Augmentation | keyof Input]: k extends keyof Augmentation
|
|
3840
|
-
// ? Augmentation[k]["_input"]
|
|
3841
|
-
// : k extends keyof Input
|
|
3842
|
-
// ? Input[k]
|
|
3843
|
-
// : never;
|
|
3844
|
-
// }
|
|
3845
|
-
// >(
|
|
3846
|
-
// merging: Incoming
|
|
3847
|
-
// ): ZodObject<
|
|
3848
|
-
// extendShape<T, ReturnType<Incoming["_def"]["shape"]>>,
|
|
3849
|
-
// Incoming["_def"]["unknownKeys"],
|
|
3850
|
-
// Incoming["_def"]["catchall"],
|
|
3851
|
-
// NewOutput,
|
|
3852
|
-
// NewInput
|
|
3853
|
-
// > {
|
|
3854
|
-
// const merged: any = new ZodObject({
|
|
3855
|
-
// unknownKeys: merging._def.unknownKeys,
|
|
3856
|
-
// catchall: merging._def.catchall,
|
|
3857
|
-
// shape: () =>
|
|
3858
|
-
// objectUtil.mergeShapes(this._def.shape(), merging._def.shape()),
|
|
3859
|
-
// typeName: ZodFirstPartyTypeKind.ZodObject,
|
|
3860
|
-
// }) as any;
|
|
3861
|
-
// return merged;
|
|
3862
|
-
// }
|
|
3863
|
-
setKey(key, schema) {
|
|
3864
|
-
return this.augment({ [key]: schema });
|
|
3865
|
-
}
|
|
3866
|
-
// merge<Incoming extends AnyZodObject>(
|
|
3867
|
-
// merging: Incoming
|
|
3868
|
-
// ): //ZodObject<T & Incoming["_shape"], UnknownKeys, Catchall> = (merging) => {
|
|
3869
|
-
// ZodObject<
|
|
3870
|
-
// extendShape<T, ReturnType<Incoming["_def"]["shape"]>>,
|
|
3871
|
-
// Incoming["_def"]["unknownKeys"],
|
|
3872
|
-
// Incoming["_def"]["catchall"]
|
|
3873
|
-
// > {
|
|
3874
|
-
// // const mergedShape = objectUtil.mergeShapes(
|
|
3875
|
-
// // this._def.shape(),
|
|
3876
|
-
// // merging._def.shape()
|
|
3877
|
-
// // );
|
|
3878
|
-
// const merged: any = new ZodObject({
|
|
3879
|
-
// unknownKeys: merging._def.unknownKeys,
|
|
3880
|
-
// catchall: merging._def.catchall,
|
|
3881
|
-
// shape: () =>
|
|
3882
|
-
// objectUtil.mergeShapes(this._def.shape(), merging._def.shape()),
|
|
3883
|
-
// typeName: ZodFirstPartyTypeKind.ZodObject,
|
|
3884
|
-
// }) as any;
|
|
3885
|
-
// return merged;
|
|
3886
|
-
// }
|
|
3887
|
-
catchall(index) {
|
|
3888
|
-
return new _ZodObject({
|
|
3889
|
-
...this._def,
|
|
3890
|
-
catchall: index
|
|
3891
|
-
});
|
|
3892
|
-
}
|
|
3893
|
-
pick(mask) {
|
|
3894
|
-
const shape = {};
|
|
3895
|
-
util.objectKeys(mask).forEach((key) => {
|
|
3896
|
-
if (mask[key] && this.shape[key]) {
|
|
3897
|
-
shape[key] = this.shape[key];
|
|
3898
|
-
}
|
|
3899
|
-
});
|
|
3900
|
-
return new _ZodObject({
|
|
3901
|
-
...this._def,
|
|
3902
|
-
shape: () => shape
|
|
3903
|
-
});
|
|
3904
|
-
}
|
|
3905
|
-
omit(mask) {
|
|
3906
|
-
const shape = {};
|
|
3907
|
-
util.objectKeys(this.shape).forEach((key) => {
|
|
3908
|
-
if (!mask[key]) {
|
|
3909
|
-
shape[key] = this.shape[key];
|
|
3910
|
-
}
|
|
3911
|
-
});
|
|
3912
|
-
return new _ZodObject({
|
|
3913
|
-
...this._def,
|
|
3914
|
-
shape: () => shape
|
|
3915
|
-
});
|
|
3916
|
-
}
|
|
3917
|
-
/**
|
|
3918
|
-
* @deprecated
|
|
3919
|
-
*/
|
|
3920
|
-
deepPartial() {
|
|
3921
|
-
return deepPartialify(this);
|
|
3922
|
-
}
|
|
3923
|
-
partial(mask) {
|
|
3924
|
-
const newShape = {};
|
|
3925
|
-
util.objectKeys(this.shape).forEach((key) => {
|
|
3926
|
-
const fieldSchema = this.shape[key];
|
|
3927
|
-
if (mask && !mask[key]) {
|
|
3928
|
-
newShape[key] = fieldSchema;
|
|
3929
|
-
} else {
|
|
3930
|
-
newShape[key] = fieldSchema.optional();
|
|
3931
|
-
}
|
|
3932
|
-
});
|
|
3933
|
-
return new _ZodObject({
|
|
3934
|
-
...this._def,
|
|
3935
|
-
shape: () => newShape
|
|
3936
|
-
});
|
|
3937
|
-
}
|
|
3938
|
-
required(mask) {
|
|
3939
|
-
const newShape = {};
|
|
3940
|
-
util.objectKeys(this.shape).forEach((key) => {
|
|
3941
|
-
if (mask && !mask[key]) {
|
|
3942
|
-
newShape[key] = this.shape[key];
|
|
3943
|
-
} else {
|
|
3944
|
-
const fieldSchema = this.shape[key];
|
|
3945
|
-
let newField = fieldSchema;
|
|
3946
|
-
while (newField instanceof ZodOptional) {
|
|
3947
|
-
newField = newField._def.innerType;
|
|
3948
|
-
}
|
|
3949
|
-
newShape[key] = newField;
|
|
3950
|
-
}
|
|
3951
|
-
});
|
|
3952
|
-
return new _ZodObject({
|
|
3953
|
-
...this._def,
|
|
3954
|
-
shape: () => newShape
|
|
3955
|
-
});
|
|
3956
|
-
}
|
|
3957
|
-
keyof() {
|
|
3958
|
-
return createZodEnum(util.objectKeys(this.shape));
|
|
3959
|
-
}
|
|
3960
|
-
};
|
|
3961
|
-
__name(_ZodObject, "ZodObject");
|
|
3962
|
-
var ZodObject = _ZodObject;
|
|
3963
|
-
ZodObject.create = (shape, params) => {
|
|
3964
|
-
return new ZodObject({
|
|
3965
|
-
shape: () => shape,
|
|
3966
|
-
unknownKeys: "strip",
|
|
3967
|
-
catchall: ZodNever.create(),
|
|
3968
|
-
typeName: ZodFirstPartyTypeKind.ZodObject,
|
|
3969
|
-
...processCreateParams(params)
|
|
3970
|
-
});
|
|
3971
|
-
};
|
|
3972
|
-
ZodObject.strictCreate = (shape, params) => {
|
|
3973
|
-
return new ZodObject({
|
|
3974
|
-
shape: () => shape,
|
|
3975
|
-
unknownKeys: "strict",
|
|
3976
|
-
catchall: ZodNever.create(),
|
|
3977
|
-
typeName: ZodFirstPartyTypeKind.ZodObject,
|
|
3978
|
-
...processCreateParams(params)
|
|
3979
|
-
});
|
|
3980
|
-
};
|
|
3981
|
-
ZodObject.lazycreate = (shape, params) => {
|
|
3982
|
-
return new ZodObject({
|
|
3983
|
-
shape,
|
|
3984
|
-
unknownKeys: "strip",
|
|
3985
|
-
catchall: ZodNever.create(),
|
|
3986
|
-
typeName: ZodFirstPartyTypeKind.ZodObject,
|
|
3987
|
-
...processCreateParams(params)
|
|
3988
|
-
});
|
|
3989
|
-
};
|
|
3990
|
-
var _ZodUnion = class _ZodUnion extends ZodType {
|
|
3991
|
-
_parse(input) {
|
|
3992
|
-
const { ctx } = this._processInputParams(input);
|
|
3993
|
-
const options = this._def.options;
|
|
3994
|
-
function handleResults(results) {
|
|
3995
|
-
for (const result of results) {
|
|
3996
|
-
if (result.result.status === "valid") {
|
|
3997
|
-
return result.result;
|
|
3998
|
-
}
|
|
3999
|
-
}
|
|
4000
|
-
for (const result of results) {
|
|
4001
|
-
if (result.result.status === "dirty") {
|
|
4002
|
-
ctx.common.issues.push(...result.ctx.common.issues);
|
|
4003
|
-
return result.result;
|
|
4004
|
-
}
|
|
4005
|
-
}
|
|
4006
|
-
const unionErrors = results.map((result) => new ZodError(result.ctx.common.issues));
|
|
4007
|
-
addIssueToContext(ctx, {
|
|
4008
|
-
code: ZodIssueCode.invalid_union,
|
|
4009
|
-
unionErrors
|
|
4010
|
-
});
|
|
4011
|
-
return INVALID;
|
|
4012
|
-
}
|
|
4013
|
-
__name(handleResults, "handleResults");
|
|
4014
|
-
if (ctx.common.async) {
|
|
4015
|
-
return Promise.all(options.map(async (option) => {
|
|
4016
|
-
const childCtx = {
|
|
4017
|
-
...ctx,
|
|
4018
|
-
common: {
|
|
4019
|
-
...ctx.common,
|
|
4020
|
-
issues: []
|
|
4021
|
-
},
|
|
4022
|
-
parent: null
|
|
4023
|
-
};
|
|
4024
|
-
return {
|
|
4025
|
-
result: await option._parseAsync({
|
|
4026
|
-
data: ctx.data,
|
|
4027
|
-
path: ctx.path,
|
|
4028
|
-
parent: childCtx
|
|
4029
|
-
}),
|
|
4030
|
-
ctx: childCtx
|
|
4031
|
-
};
|
|
4032
|
-
})).then(handleResults);
|
|
4033
|
-
} else {
|
|
4034
|
-
let dirty = void 0;
|
|
4035
|
-
const issues = [];
|
|
4036
|
-
for (const option of options) {
|
|
4037
|
-
const childCtx = {
|
|
4038
|
-
...ctx,
|
|
4039
|
-
common: {
|
|
4040
|
-
...ctx.common,
|
|
4041
|
-
issues: []
|
|
4042
|
-
},
|
|
4043
|
-
parent: null
|
|
4044
|
-
};
|
|
4045
|
-
const result = option._parseSync({
|
|
4046
|
-
data: ctx.data,
|
|
4047
|
-
path: ctx.path,
|
|
4048
|
-
parent: childCtx
|
|
4049
|
-
});
|
|
4050
|
-
if (result.status === "valid") {
|
|
4051
|
-
return result;
|
|
4052
|
-
} else if (result.status === "dirty" && !dirty) {
|
|
4053
|
-
dirty = { result, ctx: childCtx };
|
|
4054
|
-
}
|
|
4055
|
-
if (childCtx.common.issues.length) {
|
|
4056
|
-
issues.push(childCtx.common.issues);
|
|
4057
|
-
}
|
|
4058
|
-
}
|
|
4059
|
-
if (dirty) {
|
|
4060
|
-
ctx.common.issues.push(...dirty.ctx.common.issues);
|
|
4061
|
-
return dirty.result;
|
|
4062
|
-
}
|
|
4063
|
-
const unionErrors = issues.map((issues2) => new ZodError(issues2));
|
|
4064
|
-
addIssueToContext(ctx, {
|
|
4065
|
-
code: ZodIssueCode.invalid_union,
|
|
4066
|
-
unionErrors
|
|
4067
|
-
});
|
|
4068
|
-
return INVALID;
|
|
4069
|
-
}
|
|
4070
|
-
}
|
|
4071
|
-
get options() {
|
|
4072
|
-
return this._def.options;
|
|
4073
|
-
}
|
|
4074
|
-
};
|
|
4075
|
-
__name(_ZodUnion, "ZodUnion");
|
|
4076
|
-
var ZodUnion = _ZodUnion;
|
|
4077
|
-
ZodUnion.create = (types, params) => {
|
|
4078
|
-
return new ZodUnion({
|
|
4079
|
-
options: types,
|
|
4080
|
-
typeName: ZodFirstPartyTypeKind.ZodUnion,
|
|
4081
|
-
...processCreateParams(params)
|
|
4082
|
-
});
|
|
4083
|
-
};
|
|
4084
|
-
var getDiscriminator = /* @__PURE__ */ __name((type) => {
|
|
4085
|
-
if (type instanceof ZodLazy) {
|
|
4086
|
-
return getDiscriminator(type.schema);
|
|
4087
|
-
} else if (type instanceof ZodEffects) {
|
|
4088
|
-
return getDiscriminator(type.innerType());
|
|
4089
|
-
} else if (type instanceof ZodLiteral) {
|
|
4090
|
-
return [type.value];
|
|
4091
|
-
} else if (type instanceof ZodEnum) {
|
|
4092
|
-
return type.options;
|
|
4093
|
-
} else if (type instanceof ZodNativeEnum) {
|
|
4094
|
-
return util.objectValues(type.enum);
|
|
4095
|
-
} else if (type instanceof ZodDefault) {
|
|
4096
|
-
return getDiscriminator(type._def.innerType);
|
|
4097
|
-
} else if (type instanceof ZodUndefined) {
|
|
4098
|
-
return [void 0];
|
|
4099
|
-
} else if (type instanceof ZodNull) {
|
|
4100
|
-
return [null];
|
|
4101
|
-
} else if (type instanceof ZodOptional) {
|
|
4102
|
-
return [void 0, ...getDiscriminator(type.unwrap())];
|
|
4103
|
-
} else if (type instanceof ZodNullable) {
|
|
4104
|
-
return [null, ...getDiscriminator(type.unwrap())];
|
|
4105
|
-
} else if (type instanceof ZodBranded) {
|
|
4106
|
-
return getDiscriminator(type.unwrap());
|
|
4107
|
-
} else if (type instanceof ZodReadonly) {
|
|
4108
|
-
return getDiscriminator(type.unwrap());
|
|
4109
|
-
} else if (type instanceof ZodCatch) {
|
|
4110
|
-
return getDiscriminator(type._def.innerType);
|
|
4111
|
-
} else {
|
|
4112
|
-
return [];
|
|
4113
|
-
}
|
|
4114
|
-
}, "getDiscriminator");
|
|
4115
|
-
var _ZodDiscriminatedUnion = class _ZodDiscriminatedUnion extends ZodType {
|
|
4116
|
-
_parse(input) {
|
|
4117
|
-
const { ctx } = this._processInputParams(input);
|
|
4118
|
-
if (ctx.parsedType !== ZodParsedType.object) {
|
|
4119
|
-
addIssueToContext(ctx, {
|
|
4120
|
-
code: ZodIssueCode.invalid_type,
|
|
4121
|
-
expected: ZodParsedType.object,
|
|
4122
|
-
received: ctx.parsedType
|
|
4123
|
-
});
|
|
4124
|
-
return INVALID;
|
|
4125
|
-
}
|
|
4126
|
-
const discriminator = this.discriminator;
|
|
4127
|
-
const discriminatorValue = ctx.data[discriminator];
|
|
4128
|
-
const option = this.optionsMap.get(discriminatorValue);
|
|
4129
|
-
if (!option) {
|
|
4130
|
-
addIssueToContext(ctx, {
|
|
4131
|
-
code: ZodIssueCode.invalid_union_discriminator,
|
|
4132
|
-
options: Array.from(this.optionsMap.keys()),
|
|
4133
|
-
path: [discriminator]
|
|
4134
|
-
});
|
|
4135
|
-
return INVALID;
|
|
4136
|
-
}
|
|
4137
|
-
if (ctx.common.async) {
|
|
4138
|
-
return option._parseAsync({
|
|
4139
|
-
data: ctx.data,
|
|
4140
|
-
path: ctx.path,
|
|
4141
|
-
parent: ctx
|
|
4142
|
-
});
|
|
4143
|
-
} else {
|
|
4144
|
-
return option._parseSync({
|
|
4145
|
-
data: ctx.data,
|
|
4146
|
-
path: ctx.path,
|
|
4147
|
-
parent: ctx
|
|
4148
|
-
});
|
|
4149
|
-
}
|
|
4150
|
-
}
|
|
4151
|
-
get discriminator() {
|
|
4152
|
-
return this._def.discriminator;
|
|
4153
|
-
}
|
|
4154
|
-
get options() {
|
|
4155
|
-
return this._def.options;
|
|
4156
|
-
}
|
|
4157
|
-
get optionsMap() {
|
|
4158
|
-
return this._def.optionsMap;
|
|
4159
|
-
}
|
|
4160
|
-
/**
|
|
4161
|
-
* The constructor of the discriminated union schema. Its behaviour is very similar to that of the normal z.union() constructor.
|
|
4162
|
-
* However, it only allows a union of objects, all of which need to share a discriminator property. This property must
|
|
4163
|
-
* have a different value for each object in the union.
|
|
4164
|
-
* @param discriminator the name of the discriminator property
|
|
4165
|
-
* @param types an array of object schemas
|
|
4166
|
-
* @param params
|
|
4167
|
-
*/
|
|
4168
|
-
static create(discriminator, options, params) {
|
|
4169
|
-
const optionsMap = /* @__PURE__ */ new Map();
|
|
4170
|
-
for (const type of options) {
|
|
4171
|
-
const discriminatorValues = getDiscriminator(type.shape[discriminator]);
|
|
4172
|
-
if (!discriminatorValues.length) {
|
|
4173
|
-
throw new Error(`A discriminator value for key \`${discriminator}\` could not be extracted from all schema options`);
|
|
4174
|
-
}
|
|
4175
|
-
for (const value of discriminatorValues) {
|
|
4176
|
-
if (optionsMap.has(value)) {
|
|
4177
|
-
throw new Error(`Discriminator property ${String(discriminator)} has duplicate value ${String(value)}`);
|
|
4178
|
-
}
|
|
4179
|
-
optionsMap.set(value, type);
|
|
4180
|
-
}
|
|
4181
|
-
}
|
|
4182
|
-
return new _ZodDiscriminatedUnion({
|
|
4183
|
-
typeName: ZodFirstPartyTypeKind.ZodDiscriminatedUnion,
|
|
4184
|
-
discriminator,
|
|
4185
|
-
options,
|
|
4186
|
-
optionsMap,
|
|
4187
|
-
...processCreateParams(params)
|
|
4188
|
-
});
|
|
4189
|
-
}
|
|
4190
|
-
};
|
|
4191
|
-
__name(_ZodDiscriminatedUnion, "ZodDiscriminatedUnion");
|
|
4192
|
-
var ZodDiscriminatedUnion = _ZodDiscriminatedUnion;
|
|
4193
|
-
function mergeValues(a, b) {
|
|
4194
|
-
const aType = getParsedType(a);
|
|
4195
|
-
const bType = getParsedType(b);
|
|
4196
|
-
if (a === b) {
|
|
4197
|
-
return { valid: true, data: a };
|
|
4198
|
-
} else if (aType === ZodParsedType.object && bType === ZodParsedType.object) {
|
|
4199
|
-
const bKeys = util.objectKeys(b);
|
|
4200
|
-
const sharedKeys = util.objectKeys(a).filter((key) => bKeys.indexOf(key) !== -1);
|
|
4201
|
-
const newObj = { ...a, ...b };
|
|
4202
|
-
for (const key of sharedKeys) {
|
|
4203
|
-
const sharedValue = mergeValues(a[key], b[key]);
|
|
4204
|
-
if (!sharedValue.valid) {
|
|
4205
|
-
return { valid: false };
|
|
4206
|
-
}
|
|
4207
|
-
newObj[key] = sharedValue.data;
|
|
4208
|
-
}
|
|
4209
|
-
return { valid: true, data: newObj };
|
|
4210
|
-
} else if (aType === ZodParsedType.array && bType === ZodParsedType.array) {
|
|
4211
|
-
if (a.length !== b.length) {
|
|
4212
|
-
return { valid: false };
|
|
4213
|
-
}
|
|
4214
|
-
const newArray = [];
|
|
4215
|
-
for (let index = 0; index < a.length; index++) {
|
|
4216
|
-
const itemA = a[index];
|
|
4217
|
-
const itemB = b[index];
|
|
4218
|
-
const sharedValue = mergeValues(itemA, itemB);
|
|
4219
|
-
if (!sharedValue.valid) {
|
|
4220
|
-
return { valid: false };
|
|
4221
|
-
}
|
|
4222
|
-
newArray.push(sharedValue.data);
|
|
4223
|
-
}
|
|
4224
|
-
return { valid: true, data: newArray };
|
|
4225
|
-
} else if (aType === ZodParsedType.date && bType === ZodParsedType.date && +a === +b) {
|
|
4226
|
-
return { valid: true, data: a };
|
|
4227
|
-
} else {
|
|
4228
|
-
return { valid: false };
|
|
4229
|
-
}
|
|
4230
|
-
}
|
|
4231
|
-
__name(mergeValues, "mergeValues");
|
|
4232
|
-
var _ZodIntersection = class _ZodIntersection extends ZodType {
|
|
4233
|
-
_parse(input) {
|
|
4234
|
-
const { status, ctx } = this._processInputParams(input);
|
|
4235
|
-
const handleParsed = /* @__PURE__ */ __name((parsedLeft, parsedRight) => {
|
|
4236
|
-
if (isAborted(parsedLeft) || isAborted(parsedRight)) {
|
|
4237
|
-
return INVALID;
|
|
4238
|
-
}
|
|
4239
|
-
const merged = mergeValues(parsedLeft.value, parsedRight.value);
|
|
4240
|
-
if (!merged.valid) {
|
|
4241
|
-
addIssueToContext(ctx, {
|
|
4242
|
-
code: ZodIssueCode.invalid_intersection_types
|
|
4243
|
-
});
|
|
4244
|
-
return INVALID;
|
|
4245
|
-
}
|
|
4246
|
-
if (isDirty(parsedLeft) || isDirty(parsedRight)) {
|
|
4247
|
-
status.dirty();
|
|
4248
|
-
}
|
|
4249
|
-
return { status: status.value, value: merged.data };
|
|
4250
|
-
}, "handleParsed");
|
|
4251
|
-
if (ctx.common.async) {
|
|
4252
|
-
return Promise.all([
|
|
4253
|
-
this._def.left._parseAsync({
|
|
4254
|
-
data: ctx.data,
|
|
4255
|
-
path: ctx.path,
|
|
4256
|
-
parent: ctx
|
|
4257
|
-
}),
|
|
4258
|
-
this._def.right._parseAsync({
|
|
4259
|
-
data: ctx.data,
|
|
4260
|
-
path: ctx.path,
|
|
4261
|
-
parent: ctx
|
|
4262
|
-
})
|
|
4263
|
-
]).then(([left, right]) => handleParsed(left, right));
|
|
4264
|
-
} else {
|
|
4265
|
-
return handleParsed(this._def.left._parseSync({
|
|
4266
|
-
data: ctx.data,
|
|
4267
|
-
path: ctx.path,
|
|
4268
|
-
parent: ctx
|
|
4269
|
-
}), this._def.right._parseSync({
|
|
4270
|
-
data: ctx.data,
|
|
4271
|
-
path: ctx.path,
|
|
4272
|
-
parent: ctx
|
|
4273
|
-
}));
|
|
4274
|
-
}
|
|
4275
|
-
}
|
|
4276
|
-
};
|
|
4277
|
-
__name(_ZodIntersection, "ZodIntersection");
|
|
4278
|
-
var ZodIntersection = _ZodIntersection;
|
|
4279
|
-
ZodIntersection.create = (left, right, params) => {
|
|
4280
|
-
return new ZodIntersection({
|
|
4281
|
-
left,
|
|
4282
|
-
right,
|
|
4283
|
-
typeName: ZodFirstPartyTypeKind.ZodIntersection,
|
|
4284
|
-
...processCreateParams(params)
|
|
4285
|
-
});
|
|
4286
|
-
};
|
|
4287
|
-
var _ZodTuple = class _ZodTuple extends ZodType {
|
|
4288
|
-
_parse(input) {
|
|
4289
|
-
const { status, ctx } = this._processInputParams(input);
|
|
4290
|
-
if (ctx.parsedType !== ZodParsedType.array) {
|
|
4291
|
-
addIssueToContext(ctx, {
|
|
4292
|
-
code: ZodIssueCode.invalid_type,
|
|
4293
|
-
expected: ZodParsedType.array,
|
|
4294
|
-
received: ctx.parsedType
|
|
4295
|
-
});
|
|
4296
|
-
return INVALID;
|
|
4297
|
-
}
|
|
4298
|
-
if (ctx.data.length < this._def.items.length) {
|
|
4299
|
-
addIssueToContext(ctx, {
|
|
4300
|
-
code: ZodIssueCode.too_small,
|
|
4301
|
-
minimum: this._def.items.length,
|
|
4302
|
-
inclusive: true,
|
|
4303
|
-
exact: false,
|
|
4304
|
-
type: "array"
|
|
4305
|
-
});
|
|
4306
|
-
return INVALID;
|
|
4307
|
-
}
|
|
4308
|
-
const rest = this._def.rest;
|
|
4309
|
-
if (!rest && ctx.data.length > this._def.items.length) {
|
|
4310
|
-
addIssueToContext(ctx, {
|
|
4311
|
-
code: ZodIssueCode.too_big,
|
|
4312
|
-
maximum: this._def.items.length,
|
|
4313
|
-
inclusive: true,
|
|
4314
|
-
exact: false,
|
|
4315
|
-
type: "array"
|
|
4316
|
-
});
|
|
4317
|
-
status.dirty();
|
|
4318
|
-
}
|
|
4319
|
-
const items = [...ctx.data].map((item, itemIndex) => {
|
|
4320
|
-
const schema = this._def.items[itemIndex] || this._def.rest;
|
|
4321
|
-
if (!schema)
|
|
4322
|
-
return null;
|
|
4323
|
-
return schema._parse(new ParseInputLazyPath(ctx, item, ctx.path, itemIndex));
|
|
4324
|
-
}).filter((x) => !!x);
|
|
4325
|
-
if (ctx.common.async) {
|
|
4326
|
-
return Promise.all(items).then((results) => {
|
|
4327
|
-
return ParseStatus.mergeArray(status, results);
|
|
4328
|
-
});
|
|
4329
|
-
} else {
|
|
4330
|
-
return ParseStatus.mergeArray(status, items);
|
|
4331
|
-
}
|
|
4332
|
-
}
|
|
4333
|
-
get items() {
|
|
4334
|
-
return this._def.items;
|
|
4335
|
-
}
|
|
4336
|
-
rest(rest) {
|
|
4337
|
-
return new _ZodTuple({
|
|
4338
|
-
...this._def,
|
|
4339
|
-
rest
|
|
4340
|
-
});
|
|
4341
|
-
}
|
|
4342
|
-
};
|
|
4343
|
-
__name(_ZodTuple, "ZodTuple");
|
|
4344
|
-
var ZodTuple = _ZodTuple;
|
|
4345
|
-
ZodTuple.create = (schemas, params) => {
|
|
4346
|
-
if (!Array.isArray(schemas)) {
|
|
4347
|
-
throw new Error("You must pass an array of schemas to z.tuple([ ... ])");
|
|
4348
|
-
}
|
|
4349
|
-
return new ZodTuple({
|
|
4350
|
-
items: schemas,
|
|
4351
|
-
typeName: ZodFirstPartyTypeKind.ZodTuple,
|
|
4352
|
-
rest: null,
|
|
4353
|
-
...processCreateParams(params)
|
|
4354
|
-
});
|
|
4355
|
-
};
|
|
4356
|
-
var _ZodRecord = class _ZodRecord extends ZodType {
|
|
4357
|
-
get keySchema() {
|
|
4358
|
-
return this._def.keyType;
|
|
4359
|
-
}
|
|
4360
|
-
get valueSchema() {
|
|
4361
|
-
return this._def.valueType;
|
|
4362
|
-
}
|
|
4363
|
-
_parse(input) {
|
|
4364
|
-
const { status, ctx } = this._processInputParams(input);
|
|
4365
|
-
if (ctx.parsedType !== ZodParsedType.object) {
|
|
4366
|
-
addIssueToContext(ctx, {
|
|
4367
|
-
code: ZodIssueCode.invalid_type,
|
|
4368
|
-
expected: ZodParsedType.object,
|
|
4369
|
-
received: ctx.parsedType
|
|
4370
|
-
});
|
|
4371
|
-
return INVALID;
|
|
4372
|
-
}
|
|
4373
|
-
const pairs = [];
|
|
4374
|
-
const keyType = this._def.keyType;
|
|
4375
|
-
const valueType = this._def.valueType;
|
|
4376
|
-
for (const key in ctx.data) {
|
|
4377
|
-
pairs.push({
|
|
4378
|
-
key: keyType._parse(new ParseInputLazyPath(ctx, key, ctx.path, key)),
|
|
4379
|
-
value: valueType._parse(new ParseInputLazyPath(ctx, ctx.data[key], ctx.path, key)),
|
|
4380
|
-
alwaysSet: key in ctx.data
|
|
4381
|
-
});
|
|
4382
|
-
}
|
|
4383
|
-
if (ctx.common.async) {
|
|
4384
|
-
return ParseStatus.mergeObjectAsync(status, pairs);
|
|
4385
|
-
} else {
|
|
4386
|
-
return ParseStatus.mergeObjectSync(status, pairs);
|
|
4387
|
-
}
|
|
4388
|
-
}
|
|
4389
|
-
get element() {
|
|
4390
|
-
return this._def.valueType;
|
|
4391
|
-
}
|
|
4392
|
-
static create(first, second, third) {
|
|
4393
|
-
if (second instanceof ZodType) {
|
|
4394
|
-
return new _ZodRecord({
|
|
4395
|
-
keyType: first,
|
|
4396
|
-
valueType: second,
|
|
4397
|
-
typeName: ZodFirstPartyTypeKind.ZodRecord,
|
|
4398
|
-
...processCreateParams(third)
|
|
4399
|
-
});
|
|
4400
|
-
}
|
|
4401
|
-
return new _ZodRecord({
|
|
4402
|
-
keyType: ZodString.create(),
|
|
4403
|
-
valueType: first,
|
|
4404
|
-
typeName: ZodFirstPartyTypeKind.ZodRecord,
|
|
4405
|
-
...processCreateParams(second)
|
|
4406
|
-
});
|
|
4407
|
-
}
|
|
4408
|
-
};
|
|
4409
|
-
__name(_ZodRecord, "ZodRecord");
|
|
4410
|
-
var ZodRecord = _ZodRecord;
|
|
4411
|
-
var _ZodMap = class _ZodMap extends ZodType {
|
|
4412
|
-
get keySchema() {
|
|
4413
|
-
return this._def.keyType;
|
|
4414
|
-
}
|
|
4415
|
-
get valueSchema() {
|
|
4416
|
-
return this._def.valueType;
|
|
4417
|
-
}
|
|
4418
|
-
_parse(input) {
|
|
4419
|
-
const { status, ctx } = this._processInputParams(input);
|
|
4420
|
-
if (ctx.parsedType !== ZodParsedType.map) {
|
|
4421
|
-
addIssueToContext(ctx, {
|
|
4422
|
-
code: ZodIssueCode.invalid_type,
|
|
4423
|
-
expected: ZodParsedType.map,
|
|
4424
|
-
received: ctx.parsedType
|
|
4425
|
-
});
|
|
4426
|
-
return INVALID;
|
|
4427
|
-
}
|
|
4428
|
-
const keyType = this._def.keyType;
|
|
4429
|
-
const valueType = this._def.valueType;
|
|
4430
|
-
const pairs = [...ctx.data.entries()].map(([key, value], index) => {
|
|
4431
|
-
return {
|
|
4432
|
-
key: keyType._parse(new ParseInputLazyPath(ctx, key, ctx.path, [index, "key"])),
|
|
4433
|
-
value: valueType._parse(new ParseInputLazyPath(ctx, value, ctx.path, [index, "value"]))
|
|
4434
|
-
};
|
|
4435
|
-
});
|
|
4436
|
-
if (ctx.common.async) {
|
|
4437
|
-
const finalMap = /* @__PURE__ */ new Map();
|
|
4438
|
-
return Promise.resolve().then(async () => {
|
|
4439
|
-
for (const pair of pairs) {
|
|
4440
|
-
const key = await pair.key;
|
|
4441
|
-
const value = await pair.value;
|
|
4442
|
-
if (key.status === "aborted" || value.status === "aborted") {
|
|
4443
|
-
return INVALID;
|
|
4444
|
-
}
|
|
4445
|
-
if (key.status === "dirty" || value.status === "dirty") {
|
|
4446
|
-
status.dirty();
|
|
4447
|
-
}
|
|
4448
|
-
finalMap.set(key.value, value.value);
|
|
4449
|
-
}
|
|
4450
|
-
return { status: status.value, value: finalMap };
|
|
4451
|
-
});
|
|
4452
|
-
} else {
|
|
4453
|
-
const finalMap = /* @__PURE__ */ new Map();
|
|
4454
|
-
for (const pair of pairs) {
|
|
4455
|
-
const key = pair.key;
|
|
4456
|
-
const value = pair.value;
|
|
4457
|
-
if (key.status === "aborted" || value.status === "aborted") {
|
|
4458
|
-
return INVALID;
|
|
4459
|
-
}
|
|
4460
|
-
if (key.status === "dirty" || value.status === "dirty") {
|
|
4461
|
-
status.dirty();
|
|
4462
|
-
}
|
|
4463
|
-
finalMap.set(key.value, value.value);
|
|
4464
|
-
}
|
|
4465
|
-
return { status: status.value, value: finalMap };
|
|
4466
|
-
}
|
|
4467
|
-
}
|
|
4468
|
-
};
|
|
4469
|
-
__name(_ZodMap, "ZodMap");
|
|
4470
|
-
var ZodMap = _ZodMap;
|
|
4471
|
-
ZodMap.create = (keyType, valueType, params) => {
|
|
4472
|
-
return new ZodMap({
|
|
4473
|
-
valueType,
|
|
4474
|
-
keyType,
|
|
4475
|
-
typeName: ZodFirstPartyTypeKind.ZodMap,
|
|
4476
|
-
...processCreateParams(params)
|
|
4477
|
-
});
|
|
4478
|
-
};
|
|
4479
|
-
var _ZodSet = class _ZodSet extends ZodType {
|
|
4480
|
-
_parse(input) {
|
|
4481
|
-
const { status, ctx } = this._processInputParams(input);
|
|
4482
|
-
if (ctx.parsedType !== ZodParsedType.set) {
|
|
4483
|
-
addIssueToContext(ctx, {
|
|
4484
|
-
code: ZodIssueCode.invalid_type,
|
|
4485
|
-
expected: ZodParsedType.set,
|
|
4486
|
-
received: ctx.parsedType
|
|
4487
|
-
});
|
|
4488
|
-
return INVALID;
|
|
4489
|
-
}
|
|
4490
|
-
const def = this._def;
|
|
4491
|
-
if (def.minSize !== null) {
|
|
4492
|
-
if (ctx.data.size < def.minSize.value) {
|
|
4493
|
-
addIssueToContext(ctx, {
|
|
4494
|
-
code: ZodIssueCode.too_small,
|
|
4495
|
-
minimum: def.minSize.value,
|
|
4496
|
-
type: "set",
|
|
4497
|
-
inclusive: true,
|
|
4498
|
-
exact: false,
|
|
4499
|
-
message: def.minSize.message
|
|
4500
|
-
});
|
|
4501
|
-
status.dirty();
|
|
4502
|
-
}
|
|
4503
|
-
}
|
|
4504
|
-
if (def.maxSize !== null) {
|
|
4505
|
-
if (ctx.data.size > def.maxSize.value) {
|
|
4506
|
-
addIssueToContext(ctx, {
|
|
4507
|
-
code: ZodIssueCode.too_big,
|
|
4508
|
-
maximum: def.maxSize.value,
|
|
4509
|
-
type: "set",
|
|
4510
|
-
inclusive: true,
|
|
4511
|
-
exact: false,
|
|
4512
|
-
message: def.maxSize.message
|
|
4513
|
-
});
|
|
4514
|
-
status.dirty();
|
|
4515
|
-
}
|
|
4516
|
-
}
|
|
4517
|
-
const valueType = this._def.valueType;
|
|
4518
|
-
function finalizeSet(elements2) {
|
|
4519
|
-
const parsedSet = /* @__PURE__ */ new Set();
|
|
4520
|
-
for (const element of elements2) {
|
|
4521
|
-
if (element.status === "aborted")
|
|
4522
|
-
return INVALID;
|
|
4523
|
-
if (element.status === "dirty")
|
|
4524
|
-
status.dirty();
|
|
4525
|
-
parsedSet.add(element.value);
|
|
4526
|
-
}
|
|
4527
|
-
return { status: status.value, value: parsedSet };
|
|
4528
|
-
}
|
|
4529
|
-
__name(finalizeSet, "finalizeSet");
|
|
4530
|
-
const elements = [...ctx.data.values()].map((item, i) => valueType._parse(new ParseInputLazyPath(ctx, item, ctx.path, i)));
|
|
4531
|
-
if (ctx.common.async) {
|
|
4532
|
-
return Promise.all(elements).then((elements2) => finalizeSet(elements2));
|
|
4533
|
-
} else {
|
|
4534
|
-
return finalizeSet(elements);
|
|
4535
|
-
}
|
|
4536
|
-
}
|
|
4537
|
-
min(minSize, message) {
|
|
4538
|
-
return new _ZodSet({
|
|
4539
|
-
...this._def,
|
|
4540
|
-
minSize: { value: minSize, message: errorUtil.toString(message) }
|
|
4541
|
-
});
|
|
4542
|
-
}
|
|
4543
|
-
max(maxSize, message) {
|
|
4544
|
-
return new _ZodSet({
|
|
4545
|
-
...this._def,
|
|
4546
|
-
maxSize: { value: maxSize, message: errorUtil.toString(message) }
|
|
4547
|
-
});
|
|
4548
|
-
}
|
|
4549
|
-
size(size, message) {
|
|
4550
|
-
return this.min(size, message).max(size, message);
|
|
4551
|
-
}
|
|
4552
|
-
nonempty(message) {
|
|
4553
|
-
return this.min(1, message);
|
|
4554
|
-
}
|
|
4555
|
-
};
|
|
4556
|
-
__name(_ZodSet, "ZodSet");
|
|
4557
|
-
var ZodSet = _ZodSet;
|
|
4558
|
-
ZodSet.create = (valueType, params) => {
|
|
4559
|
-
return new ZodSet({
|
|
4560
|
-
valueType,
|
|
4561
|
-
minSize: null,
|
|
4562
|
-
maxSize: null,
|
|
4563
|
-
typeName: ZodFirstPartyTypeKind.ZodSet,
|
|
4564
|
-
...processCreateParams(params)
|
|
4565
|
-
});
|
|
4566
|
-
};
|
|
4567
|
-
var _ZodFunction = class _ZodFunction extends ZodType {
|
|
4568
|
-
constructor() {
|
|
4569
|
-
super(...arguments);
|
|
4570
|
-
this.validate = this.implement;
|
|
4571
|
-
}
|
|
4572
|
-
_parse(input) {
|
|
4573
|
-
const { ctx } = this._processInputParams(input);
|
|
4574
|
-
if (ctx.parsedType !== ZodParsedType.function) {
|
|
4575
|
-
addIssueToContext(ctx, {
|
|
4576
|
-
code: ZodIssueCode.invalid_type,
|
|
4577
|
-
expected: ZodParsedType.function,
|
|
4578
|
-
received: ctx.parsedType
|
|
4579
|
-
});
|
|
4580
|
-
return INVALID;
|
|
4581
|
-
}
|
|
4582
|
-
function makeArgsIssue(args, error) {
|
|
4583
|
-
return makeIssue({
|
|
4584
|
-
data: args,
|
|
4585
|
-
path: ctx.path,
|
|
4586
|
-
errorMaps: [
|
|
4587
|
-
ctx.common.contextualErrorMap,
|
|
4588
|
-
ctx.schemaErrorMap,
|
|
4589
|
-
getErrorMap(),
|
|
4590
|
-
errorMap
|
|
4591
|
-
].filter((x) => !!x),
|
|
4592
|
-
issueData: {
|
|
4593
|
-
code: ZodIssueCode.invalid_arguments,
|
|
4594
|
-
argumentsError: error
|
|
4595
|
-
}
|
|
4596
|
-
});
|
|
4597
|
-
}
|
|
4598
|
-
__name(makeArgsIssue, "makeArgsIssue");
|
|
4599
|
-
function makeReturnsIssue(returns, error) {
|
|
4600
|
-
return makeIssue({
|
|
4601
|
-
data: returns,
|
|
4602
|
-
path: ctx.path,
|
|
4603
|
-
errorMaps: [
|
|
4604
|
-
ctx.common.contextualErrorMap,
|
|
4605
|
-
ctx.schemaErrorMap,
|
|
4606
|
-
getErrorMap(),
|
|
4607
|
-
errorMap
|
|
4608
|
-
].filter((x) => !!x),
|
|
4609
|
-
issueData: {
|
|
4610
|
-
code: ZodIssueCode.invalid_return_type,
|
|
4611
|
-
returnTypeError: error
|
|
4612
|
-
}
|
|
4613
|
-
});
|
|
4614
|
-
}
|
|
4615
|
-
__name(makeReturnsIssue, "makeReturnsIssue");
|
|
4616
|
-
const params = { errorMap: ctx.common.contextualErrorMap };
|
|
4617
|
-
const fn = ctx.data;
|
|
4618
|
-
if (this._def.returns instanceof ZodPromise) {
|
|
4619
|
-
const me = this;
|
|
4620
|
-
return OK(async function(...args) {
|
|
4621
|
-
const error = new ZodError([]);
|
|
4622
|
-
const parsedArgs = await me._def.args.parseAsync(args, params).catch((e) => {
|
|
4623
|
-
error.addIssue(makeArgsIssue(args, e));
|
|
4624
|
-
throw error;
|
|
4625
|
-
});
|
|
4626
|
-
const result = await Reflect.apply(fn, this, parsedArgs);
|
|
4627
|
-
const parsedReturns = await me._def.returns._def.type.parseAsync(result, params).catch((e) => {
|
|
4628
|
-
error.addIssue(makeReturnsIssue(result, e));
|
|
4629
|
-
throw error;
|
|
4630
|
-
});
|
|
4631
|
-
return parsedReturns;
|
|
4632
|
-
});
|
|
4633
|
-
} else {
|
|
4634
|
-
const me = this;
|
|
4635
|
-
return OK(function(...args) {
|
|
4636
|
-
const parsedArgs = me._def.args.safeParse(args, params);
|
|
4637
|
-
if (!parsedArgs.success) {
|
|
4638
|
-
throw new ZodError([makeArgsIssue(args, parsedArgs.error)]);
|
|
4639
|
-
}
|
|
4640
|
-
const result = Reflect.apply(fn, this, parsedArgs.data);
|
|
4641
|
-
const parsedReturns = me._def.returns.safeParse(result, params);
|
|
4642
|
-
if (!parsedReturns.success) {
|
|
4643
|
-
throw new ZodError([makeReturnsIssue(result, parsedReturns.error)]);
|
|
4644
|
-
}
|
|
4645
|
-
return parsedReturns.data;
|
|
4646
|
-
});
|
|
4647
|
-
}
|
|
4648
|
-
}
|
|
4649
|
-
parameters() {
|
|
4650
|
-
return this._def.args;
|
|
4651
|
-
}
|
|
4652
|
-
returnType() {
|
|
4653
|
-
return this._def.returns;
|
|
4654
|
-
}
|
|
4655
|
-
args(...items) {
|
|
4656
|
-
return new _ZodFunction({
|
|
4657
|
-
...this._def,
|
|
4658
|
-
args: ZodTuple.create(items).rest(ZodUnknown.create())
|
|
4659
|
-
});
|
|
4660
|
-
}
|
|
4661
|
-
returns(returnType) {
|
|
4662
|
-
return new _ZodFunction({
|
|
4663
|
-
...this._def,
|
|
4664
|
-
returns: returnType
|
|
4665
|
-
});
|
|
4666
|
-
}
|
|
4667
|
-
implement(func) {
|
|
4668
|
-
const validatedFunc = this.parse(func);
|
|
4669
|
-
return validatedFunc;
|
|
4670
|
-
}
|
|
4671
|
-
strictImplement(func) {
|
|
4672
|
-
const validatedFunc = this.parse(func);
|
|
4673
|
-
return validatedFunc;
|
|
4674
|
-
}
|
|
4675
|
-
static create(args, returns, params) {
|
|
4676
|
-
return new _ZodFunction({
|
|
4677
|
-
args: args ? args : ZodTuple.create([]).rest(ZodUnknown.create()),
|
|
4678
|
-
returns: returns || ZodUnknown.create(),
|
|
4679
|
-
typeName: ZodFirstPartyTypeKind.ZodFunction,
|
|
4680
|
-
...processCreateParams(params)
|
|
4681
|
-
});
|
|
4682
|
-
}
|
|
4683
|
-
};
|
|
4684
|
-
__name(_ZodFunction, "ZodFunction");
|
|
4685
|
-
var ZodFunction = _ZodFunction;
|
|
4686
|
-
var _ZodLazy = class _ZodLazy extends ZodType {
|
|
4687
|
-
get schema() {
|
|
4688
|
-
return this._def.getter();
|
|
4689
|
-
}
|
|
4690
|
-
_parse(input) {
|
|
4691
|
-
const { ctx } = this._processInputParams(input);
|
|
4692
|
-
const lazySchema = this._def.getter();
|
|
4693
|
-
return lazySchema._parse({ data: ctx.data, path: ctx.path, parent: ctx });
|
|
4694
|
-
}
|
|
4695
|
-
};
|
|
4696
|
-
__name(_ZodLazy, "ZodLazy");
|
|
4697
|
-
var ZodLazy = _ZodLazy;
|
|
4698
|
-
ZodLazy.create = (getter, params) => {
|
|
4699
|
-
return new ZodLazy({
|
|
4700
|
-
getter,
|
|
4701
|
-
typeName: ZodFirstPartyTypeKind.ZodLazy,
|
|
4702
|
-
...processCreateParams(params)
|
|
4703
|
-
});
|
|
4704
|
-
};
|
|
4705
|
-
var _ZodLiteral = class _ZodLiteral extends ZodType {
|
|
4706
|
-
_parse(input) {
|
|
4707
|
-
if (input.data !== this._def.value) {
|
|
4708
|
-
const ctx = this._getOrReturnCtx(input);
|
|
4709
|
-
addIssueToContext(ctx, {
|
|
4710
|
-
received: ctx.data,
|
|
4711
|
-
code: ZodIssueCode.invalid_literal,
|
|
4712
|
-
expected: this._def.value
|
|
4713
|
-
});
|
|
4714
|
-
return INVALID;
|
|
4715
|
-
}
|
|
4716
|
-
return { status: "valid", value: input.data };
|
|
4717
|
-
}
|
|
4718
|
-
get value() {
|
|
4719
|
-
return this._def.value;
|
|
4720
|
-
}
|
|
4721
|
-
};
|
|
4722
|
-
__name(_ZodLiteral, "ZodLiteral");
|
|
4723
|
-
var ZodLiteral = _ZodLiteral;
|
|
4724
|
-
ZodLiteral.create = (value, params) => {
|
|
4725
|
-
return new ZodLiteral({
|
|
4726
|
-
value,
|
|
4727
|
-
typeName: ZodFirstPartyTypeKind.ZodLiteral,
|
|
4728
|
-
...processCreateParams(params)
|
|
4729
|
-
});
|
|
4730
|
-
};
|
|
4731
|
-
function createZodEnum(values, params) {
|
|
4732
|
-
return new ZodEnum({
|
|
4733
|
-
values,
|
|
4734
|
-
typeName: ZodFirstPartyTypeKind.ZodEnum,
|
|
4735
|
-
...processCreateParams(params)
|
|
4736
|
-
});
|
|
4737
|
-
}
|
|
4738
|
-
__name(createZodEnum, "createZodEnum");
|
|
4739
|
-
var _ZodEnum = class _ZodEnum extends ZodType {
|
|
4740
|
-
constructor() {
|
|
4741
|
-
super(...arguments);
|
|
4742
|
-
_ZodEnum_cache.set(this, void 0);
|
|
4743
|
-
}
|
|
4744
|
-
_parse(input) {
|
|
4745
|
-
if (typeof input.data !== "string") {
|
|
4746
|
-
const ctx = this._getOrReturnCtx(input);
|
|
4747
|
-
const expectedValues = this._def.values;
|
|
4748
|
-
addIssueToContext(ctx, {
|
|
4749
|
-
expected: util.joinValues(expectedValues),
|
|
4750
|
-
received: ctx.parsedType,
|
|
4751
|
-
code: ZodIssueCode.invalid_type
|
|
4752
|
-
});
|
|
4753
|
-
return INVALID;
|
|
4754
|
-
}
|
|
4755
|
-
if (!__classPrivateFieldGet(this, _ZodEnum_cache, "f")) {
|
|
4756
|
-
__classPrivateFieldSet(this, _ZodEnum_cache, new Set(this._def.values), "f");
|
|
4757
|
-
}
|
|
4758
|
-
if (!__classPrivateFieldGet(this, _ZodEnum_cache, "f").has(input.data)) {
|
|
4759
|
-
const ctx = this._getOrReturnCtx(input);
|
|
4760
|
-
const expectedValues = this._def.values;
|
|
4761
|
-
addIssueToContext(ctx, {
|
|
4762
|
-
received: ctx.data,
|
|
4763
|
-
code: ZodIssueCode.invalid_enum_value,
|
|
4764
|
-
options: expectedValues
|
|
4765
|
-
});
|
|
4766
|
-
return INVALID;
|
|
4767
|
-
}
|
|
4768
|
-
return OK(input.data);
|
|
4769
|
-
}
|
|
4770
|
-
get options() {
|
|
4771
|
-
return this._def.values;
|
|
4772
|
-
}
|
|
4773
|
-
get enum() {
|
|
4774
|
-
const enumValues2 = {};
|
|
4775
|
-
for (const val of this._def.values) {
|
|
4776
|
-
enumValues2[val] = val;
|
|
4777
|
-
}
|
|
4778
|
-
return enumValues2;
|
|
4779
|
-
}
|
|
4780
|
-
get Values() {
|
|
4781
|
-
const enumValues2 = {};
|
|
4782
|
-
for (const val of this._def.values) {
|
|
4783
|
-
enumValues2[val] = val;
|
|
4784
|
-
}
|
|
4785
|
-
return enumValues2;
|
|
4786
|
-
}
|
|
4787
|
-
get Enum() {
|
|
4788
|
-
const enumValues2 = {};
|
|
4789
|
-
for (const val of this._def.values) {
|
|
4790
|
-
enumValues2[val] = val;
|
|
4791
|
-
}
|
|
4792
|
-
return enumValues2;
|
|
4793
|
-
}
|
|
4794
|
-
extract(values, newDef = this._def) {
|
|
4795
|
-
return _ZodEnum.create(values, {
|
|
4796
|
-
...this._def,
|
|
4797
|
-
...newDef
|
|
4798
|
-
});
|
|
4799
|
-
}
|
|
4800
|
-
exclude(values, newDef = this._def) {
|
|
4801
|
-
return _ZodEnum.create(this.options.filter((opt) => !values.includes(opt)), {
|
|
4802
|
-
...this._def,
|
|
4803
|
-
...newDef
|
|
4804
|
-
});
|
|
4805
|
-
}
|
|
4806
|
-
};
|
|
4807
|
-
__name(_ZodEnum, "ZodEnum");
|
|
4808
|
-
var ZodEnum = _ZodEnum;
|
|
4809
|
-
_ZodEnum_cache = /* @__PURE__ */ new WeakMap();
|
|
4810
|
-
ZodEnum.create = createZodEnum;
|
|
4811
|
-
var _ZodNativeEnum = class _ZodNativeEnum extends ZodType {
|
|
4812
|
-
constructor() {
|
|
4813
|
-
super(...arguments);
|
|
4814
|
-
_ZodNativeEnum_cache.set(this, void 0);
|
|
4815
|
-
}
|
|
4816
|
-
_parse(input) {
|
|
4817
|
-
const nativeEnumValues = util.getValidEnumValues(this._def.values);
|
|
4818
|
-
const ctx = this._getOrReturnCtx(input);
|
|
4819
|
-
if (ctx.parsedType !== ZodParsedType.string && ctx.parsedType !== ZodParsedType.number) {
|
|
4820
|
-
const expectedValues = util.objectValues(nativeEnumValues);
|
|
4821
|
-
addIssueToContext(ctx, {
|
|
4822
|
-
expected: util.joinValues(expectedValues),
|
|
4823
|
-
received: ctx.parsedType,
|
|
4824
|
-
code: ZodIssueCode.invalid_type
|
|
4825
|
-
});
|
|
4826
|
-
return INVALID;
|
|
4827
|
-
}
|
|
4828
|
-
if (!__classPrivateFieldGet(this, _ZodNativeEnum_cache, "f")) {
|
|
4829
|
-
__classPrivateFieldSet(this, _ZodNativeEnum_cache, new Set(util.getValidEnumValues(this._def.values)), "f");
|
|
4830
|
-
}
|
|
4831
|
-
if (!__classPrivateFieldGet(this, _ZodNativeEnum_cache, "f").has(input.data)) {
|
|
4832
|
-
const expectedValues = util.objectValues(nativeEnumValues);
|
|
4833
|
-
addIssueToContext(ctx, {
|
|
4834
|
-
received: ctx.data,
|
|
4835
|
-
code: ZodIssueCode.invalid_enum_value,
|
|
4836
|
-
options: expectedValues
|
|
4837
|
-
});
|
|
4838
|
-
return INVALID;
|
|
4839
|
-
}
|
|
4840
|
-
return OK(input.data);
|
|
4841
|
-
}
|
|
4842
|
-
get enum() {
|
|
4843
|
-
return this._def.values;
|
|
4844
|
-
}
|
|
4845
|
-
};
|
|
4846
|
-
__name(_ZodNativeEnum, "ZodNativeEnum");
|
|
4847
|
-
var ZodNativeEnum = _ZodNativeEnum;
|
|
4848
|
-
_ZodNativeEnum_cache = /* @__PURE__ */ new WeakMap();
|
|
4849
|
-
ZodNativeEnum.create = (values, params) => {
|
|
4850
|
-
return new ZodNativeEnum({
|
|
4851
|
-
values,
|
|
4852
|
-
typeName: ZodFirstPartyTypeKind.ZodNativeEnum,
|
|
4853
|
-
...processCreateParams(params)
|
|
4854
|
-
});
|
|
4855
|
-
};
|
|
4856
|
-
var _ZodPromise = class _ZodPromise extends ZodType {
|
|
4857
|
-
unwrap() {
|
|
4858
|
-
return this._def.type;
|
|
4859
|
-
}
|
|
4860
|
-
_parse(input) {
|
|
4861
|
-
const { ctx } = this._processInputParams(input);
|
|
4862
|
-
if (ctx.parsedType !== ZodParsedType.promise && ctx.common.async === false) {
|
|
4863
|
-
addIssueToContext(ctx, {
|
|
4864
|
-
code: ZodIssueCode.invalid_type,
|
|
4865
|
-
expected: ZodParsedType.promise,
|
|
4866
|
-
received: ctx.parsedType
|
|
4867
|
-
});
|
|
4868
|
-
return INVALID;
|
|
4869
|
-
}
|
|
4870
|
-
const promisified = ctx.parsedType === ZodParsedType.promise ? ctx.data : Promise.resolve(ctx.data);
|
|
4871
|
-
return OK(promisified.then((data) => {
|
|
4872
|
-
return this._def.type.parseAsync(data, {
|
|
4873
|
-
path: ctx.path,
|
|
4874
|
-
errorMap: ctx.common.contextualErrorMap
|
|
4875
|
-
});
|
|
4876
|
-
}));
|
|
4877
|
-
}
|
|
4878
|
-
};
|
|
4879
|
-
__name(_ZodPromise, "ZodPromise");
|
|
4880
|
-
var ZodPromise = _ZodPromise;
|
|
4881
|
-
ZodPromise.create = (schema, params) => {
|
|
4882
|
-
return new ZodPromise({
|
|
4883
|
-
type: schema,
|
|
4884
|
-
typeName: ZodFirstPartyTypeKind.ZodPromise,
|
|
4885
|
-
...processCreateParams(params)
|
|
4886
|
-
});
|
|
4887
|
-
};
|
|
4888
|
-
var _ZodEffects = class _ZodEffects extends ZodType {
|
|
4889
|
-
innerType() {
|
|
4890
|
-
return this._def.schema;
|
|
4891
|
-
}
|
|
4892
|
-
sourceType() {
|
|
4893
|
-
return this._def.schema._def.typeName === ZodFirstPartyTypeKind.ZodEffects ? this._def.schema.sourceType() : this._def.schema;
|
|
4894
|
-
}
|
|
4895
|
-
_parse(input) {
|
|
4896
|
-
const { status, ctx } = this._processInputParams(input);
|
|
4897
|
-
const effect = this._def.effect || null;
|
|
4898
|
-
const checkCtx = {
|
|
4899
|
-
addIssue: (arg) => {
|
|
4900
|
-
addIssueToContext(ctx, arg);
|
|
4901
|
-
if (arg.fatal) {
|
|
4902
|
-
status.abort();
|
|
4903
|
-
} else {
|
|
4904
|
-
status.dirty();
|
|
4905
|
-
}
|
|
4906
|
-
},
|
|
4907
|
-
get path() {
|
|
4908
|
-
return ctx.path;
|
|
4909
|
-
}
|
|
4910
|
-
};
|
|
4911
|
-
checkCtx.addIssue = checkCtx.addIssue.bind(checkCtx);
|
|
4912
|
-
if (effect.type === "preprocess") {
|
|
4913
|
-
const processed = effect.transform(ctx.data, checkCtx);
|
|
4914
|
-
if (ctx.common.async) {
|
|
4915
|
-
return Promise.resolve(processed).then(async (processed2) => {
|
|
4916
|
-
if (status.value === "aborted")
|
|
4917
|
-
return INVALID;
|
|
4918
|
-
const result = await this._def.schema._parseAsync({
|
|
4919
|
-
data: processed2,
|
|
4920
|
-
path: ctx.path,
|
|
4921
|
-
parent: ctx
|
|
4922
|
-
});
|
|
4923
|
-
if (result.status === "aborted")
|
|
4924
|
-
return INVALID;
|
|
4925
|
-
if (result.status === "dirty")
|
|
4926
|
-
return DIRTY(result.value);
|
|
4927
|
-
if (status.value === "dirty")
|
|
4928
|
-
return DIRTY(result.value);
|
|
4929
|
-
return result;
|
|
4930
|
-
});
|
|
4931
|
-
} else {
|
|
4932
|
-
if (status.value === "aborted")
|
|
4933
|
-
return INVALID;
|
|
4934
|
-
const result = this._def.schema._parseSync({
|
|
4935
|
-
data: processed,
|
|
4936
|
-
path: ctx.path,
|
|
4937
|
-
parent: ctx
|
|
4938
|
-
});
|
|
4939
|
-
if (result.status === "aborted")
|
|
4940
|
-
return INVALID;
|
|
4941
|
-
if (result.status === "dirty")
|
|
4942
|
-
return DIRTY(result.value);
|
|
4943
|
-
if (status.value === "dirty")
|
|
4944
|
-
return DIRTY(result.value);
|
|
4945
|
-
return result;
|
|
4946
|
-
}
|
|
4947
|
-
}
|
|
4948
|
-
if (effect.type === "refinement") {
|
|
4949
|
-
const executeRefinement = /* @__PURE__ */ __name((acc) => {
|
|
4950
|
-
const result = effect.refinement(acc, checkCtx);
|
|
4951
|
-
if (ctx.common.async) {
|
|
4952
|
-
return Promise.resolve(result);
|
|
4953
|
-
}
|
|
4954
|
-
if (result instanceof Promise) {
|
|
4955
|
-
throw new Error("Async refinement encountered during synchronous parse operation. Use .parseAsync instead.");
|
|
4956
|
-
}
|
|
4957
|
-
return acc;
|
|
4958
|
-
}, "executeRefinement");
|
|
4959
|
-
if (ctx.common.async === false) {
|
|
4960
|
-
const inner = this._def.schema._parseSync({
|
|
4961
|
-
data: ctx.data,
|
|
4962
|
-
path: ctx.path,
|
|
4963
|
-
parent: ctx
|
|
4964
|
-
});
|
|
4965
|
-
if (inner.status === "aborted")
|
|
4966
|
-
return INVALID;
|
|
4967
|
-
if (inner.status === "dirty")
|
|
4968
|
-
status.dirty();
|
|
4969
|
-
executeRefinement(inner.value);
|
|
4970
|
-
return { status: status.value, value: inner.value };
|
|
4971
|
-
} else {
|
|
4972
|
-
return this._def.schema._parseAsync({ data: ctx.data, path: ctx.path, parent: ctx }).then((inner) => {
|
|
4973
|
-
if (inner.status === "aborted")
|
|
4974
|
-
return INVALID;
|
|
4975
|
-
if (inner.status === "dirty")
|
|
4976
|
-
status.dirty();
|
|
4977
|
-
return executeRefinement(inner.value).then(() => {
|
|
4978
|
-
return { status: status.value, value: inner.value };
|
|
4979
|
-
});
|
|
4980
|
-
});
|
|
4981
|
-
}
|
|
4982
|
-
}
|
|
4983
|
-
if (effect.type === "transform") {
|
|
4984
|
-
if (ctx.common.async === false) {
|
|
4985
|
-
const base = this._def.schema._parseSync({
|
|
4986
|
-
data: ctx.data,
|
|
4987
|
-
path: ctx.path,
|
|
4988
|
-
parent: ctx
|
|
4989
|
-
});
|
|
4990
|
-
if (!isValid(base))
|
|
4991
|
-
return base;
|
|
4992
|
-
const result = effect.transform(base.value, checkCtx);
|
|
4993
|
-
if (result instanceof Promise) {
|
|
4994
|
-
throw new Error(`Asynchronous transform encountered during synchronous parse operation. Use .parseAsync instead.`);
|
|
4995
|
-
}
|
|
4996
|
-
return { status: status.value, value: result };
|
|
4997
|
-
} else {
|
|
4998
|
-
return this._def.schema._parseAsync({ data: ctx.data, path: ctx.path, parent: ctx }).then((base) => {
|
|
4999
|
-
if (!isValid(base))
|
|
5000
|
-
return base;
|
|
5001
|
-
return Promise.resolve(effect.transform(base.value, checkCtx)).then((result) => ({ status: status.value, value: result }));
|
|
5002
|
-
});
|
|
5003
|
-
}
|
|
5004
|
-
}
|
|
5005
|
-
util.assertNever(effect);
|
|
5006
|
-
}
|
|
5007
|
-
};
|
|
5008
|
-
__name(_ZodEffects, "ZodEffects");
|
|
5009
|
-
var ZodEffects = _ZodEffects;
|
|
5010
|
-
ZodEffects.create = (schema, effect, params) => {
|
|
5011
|
-
return new ZodEffects({
|
|
5012
|
-
schema,
|
|
5013
|
-
typeName: ZodFirstPartyTypeKind.ZodEffects,
|
|
5014
|
-
effect,
|
|
5015
|
-
...processCreateParams(params)
|
|
5016
|
-
});
|
|
5017
|
-
};
|
|
5018
|
-
ZodEffects.createWithPreprocess = (preprocess, schema, params) => {
|
|
5019
|
-
return new ZodEffects({
|
|
5020
|
-
schema,
|
|
5021
|
-
effect: { type: "preprocess", transform: preprocess },
|
|
5022
|
-
typeName: ZodFirstPartyTypeKind.ZodEffects,
|
|
5023
|
-
...processCreateParams(params)
|
|
5024
|
-
});
|
|
5025
|
-
};
|
|
5026
|
-
var _ZodOptional = class _ZodOptional extends ZodType {
|
|
5027
|
-
_parse(input) {
|
|
5028
|
-
const parsedType = this._getType(input);
|
|
5029
|
-
if (parsedType === ZodParsedType.undefined) {
|
|
5030
|
-
return OK(void 0);
|
|
5031
|
-
}
|
|
5032
|
-
return this._def.innerType._parse(input);
|
|
5033
|
-
}
|
|
5034
|
-
unwrap() {
|
|
5035
|
-
return this._def.innerType;
|
|
5036
|
-
}
|
|
5037
|
-
};
|
|
5038
|
-
__name(_ZodOptional, "ZodOptional");
|
|
5039
|
-
var ZodOptional = _ZodOptional;
|
|
5040
|
-
ZodOptional.create = (type, params) => {
|
|
5041
|
-
return new ZodOptional({
|
|
5042
|
-
innerType: type,
|
|
5043
|
-
typeName: ZodFirstPartyTypeKind.ZodOptional,
|
|
5044
|
-
...processCreateParams(params)
|
|
5045
|
-
});
|
|
5046
|
-
};
|
|
5047
|
-
var _ZodNullable = class _ZodNullable extends ZodType {
|
|
5048
|
-
_parse(input) {
|
|
5049
|
-
const parsedType = this._getType(input);
|
|
5050
|
-
if (parsedType === ZodParsedType.null) {
|
|
5051
|
-
return OK(null);
|
|
5052
|
-
}
|
|
5053
|
-
return this._def.innerType._parse(input);
|
|
5054
|
-
}
|
|
5055
|
-
unwrap() {
|
|
5056
|
-
return this._def.innerType;
|
|
5057
|
-
}
|
|
5058
|
-
};
|
|
5059
|
-
__name(_ZodNullable, "ZodNullable");
|
|
5060
|
-
var ZodNullable = _ZodNullable;
|
|
5061
|
-
ZodNullable.create = (type, params) => {
|
|
5062
|
-
return new ZodNullable({
|
|
5063
|
-
innerType: type,
|
|
5064
|
-
typeName: ZodFirstPartyTypeKind.ZodNullable,
|
|
5065
|
-
...processCreateParams(params)
|
|
5066
|
-
});
|
|
5067
|
-
};
|
|
5068
|
-
var _ZodDefault = class _ZodDefault extends ZodType {
|
|
5069
|
-
_parse(input) {
|
|
5070
|
-
const { ctx } = this._processInputParams(input);
|
|
5071
|
-
let data = ctx.data;
|
|
5072
|
-
if (ctx.parsedType === ZodParsedType.undefined) {
|
|
5073
|
-
data = this._def.defaultValue();
|
|
5074
|
-
}
|
|
5075
|
-
return this._def.innerType._parse({
|
|
5076
|
-
data,
|
|
5077
|
-
path: ctx.path,
|
|
5078
|
-
parent: ctx
|
|
5079
|
-
});
|
|
5080
|
-
}
|
|
5081
|
-
removeDefault() {
|
|
5082
|
-
return this._def.innerType;
|
|
5083
|
-
}
|
|
5084
|
-
};
|
|
5085
|
-
__name(_ZodDefault, "ZodDefault");
|
|
5086
|
-
var ZodDefault = _ZodDefault;
|
|
5087
|
-
ZodDefault.create = (type, params) => {
|
|
5088
|
-
return new ZodDefault({
|
|
5089
|
-
innerType: type,
|
|
5090
|
-
typeName: ZodFirstPartyTypeKind.ZodDefault,
|
|
5091
|
-
defaultValue: typeof params.default === "function" ? params.default : () => params.default,
|
|
5092
|
-
...processCreateParams(params)
|
|
5093
|
-
});
|
|
5094
|
-
};
|
|
5095
|
-
var _ZodCatch = class _ZodCatch extends ZodType {
|
|
5096
|
-
_parse(input) {
|
|
5097
|
-
const { ctx } = this._processInputParams(input);
|
|
5098
|
-
const newCtx = {
|
|
5099
|
-
...ctx,
|
|
5100
|
-
common: {
|
|
5101
|
-
...ctx.common,
|
|
5102
|
-
issues: []
|
|
5103
|
-
}
|
|
5104
|
-
};
|
|
5105
|
-
const result = this._def.innerType._parse({
|
|
5106
|
-
data: newCtx.data,
|
|
5107
|
-
path: newCtx.path,
|
|
5108
|
-
parent: {
|
|
5109
|
-
...newCtx
|
|
5110
|
-
}
|
|
5111
|
-
});
|
|
5112
|
-
if (isAsync(result)) {
|
|
5113
|
-
return result.then((result2) => {
|
|
5114
|
-
return {
|
|
5115
|
-
status: "valid",
|
|
5116
|
-
value: result2.status === "valid" ? result2.value : this._def.catchValue({
|
|
5117
|
-
get error() {
|
|
5118
|
-
return new ZodError(newCtx.common.issues);
|
|
5119
|
-
},
|
|
5120
|
-
input: newCtx.data
|
|
5121
|
-
})
|
|
5122
|
-
};
|
|
5123
|
-
});
|
|
5124
|
-
} else {
|
|
5125
|
-
return {
|
|
5126
|
-
status: "valid",
|
|
5127
|
-
value: result.status === "valid" ? result.value : this._def.catchValue({
|
|
5128
|
-
get error() {
|
|
5129
|
-
return new ZodError(newCtx.common.issues);
|
|
5130
|
-
},
|
|
5131
|
-
input: newCtx.data
|
|
5132
|
-
})
|
|
5133
|
-
};
|
|
5134
|
-
}
|
|
5135
|
-
}
|
|
5136
|
-
removeCatch() {
|
|
5137
|
-
return this._def.innerType;
|
|
5138
|
-
}
|
|
5139
|
-
};
|
|
5140
|
-
__name(_ZodCatch, "ZodCatch");
|
|
5141
|
-
var ZodCatch = _ZodCatch;
|
|
5142
|
-
ZodCatch.create = (type, params) => {
|
|
5143
|
-
return new ZodCatch({
|
|
5144
|
-
innerType: type,
|
|
5145
|
-
typeName: ZodFirstPartyTypeKind.ZodCatch,
|
|
5146
|
-
catchValue: typeof params.catch === "function" ? params.catch : () => params.catch,
|
|
5147
|
-
...processCreateParams(params)
|
|
5148
|
-
});
|
|
5149
|
-
};
|
|
5150
|
-
var _ZodNaN = class _ZodNaN extends ZodType {
|
|
5151
|
-
_parse(input) {
|
|
5152
|
-
const parsedType = this._getType(input);
|
|
5153
|
-
if (parsedType !== ZodParsedType.nan) {
|
|
5154
|
-
const ctx = this._getOrReturnCtx(input);
|
|
5155
|
-
addIssueToContext(ctx, {
|
|
5156
|
-
code: ZodIssueCode.invalid_type,
|
|
5157
|
-
expected: ZodParsedType.nan,
|
|
5158
|
-
received: ctx.parsedType
|
|
5159
|
-
});
|
|
5160
|
-
return INVALID;
|
|
5161
|
-
}
|
|
5162
|
-
return { status: "valid", value: input.data };
|
|
5163
|
-
}
|
|
5164
|
-
};
|
|
5165
|
-
__name(_ZodNaN, "ZodNaN");
|
|
5166
|
-
var ZodNaN = _ZodNaN;
|
|
5167
|
-
ZodNaN.create = (params) => {
|
|
5168
|
-
return new ZodNaN({
|
|
5169
|
-
typeName: ZodFirstPartyTypeKind.ZodNaN,
|
|
5170
|
-
...processCreateParams(params)
|
|
5171
|
-
});
|
|
5172
|
-
};
|
|
5173
|
-
var BRAND = Symbol("zod_brand");
|
|
5174
|
-
var _ZodBranded = class _ZodBranded extends ZodType {
|
|
5175
|
-
_parse(input) {
|
|
5176
|
-
const { ctx } = this._processInputParams(input);
|
|
5177
|
-
const data = ctx.data;
|
|
5178
|
-
return this._def.type._parse({
|
|
5179
|
-
data,
|
|
5180
|
-
path: ctx.path,
|
|
5181
|
-
parent: ctx
|
|
5182
|
-
});
|
|
5183
|
-
}
|
|
5184
|
-
unwrap() {
|
|
5185
|
-
return this._def.type;
|
|
5186
|
-
}
|
|
5187
|
-
};
|
|
5188
|
-
__name(_ZodBranded, "ZodBranded");
|
|
5189
|
-
var ZodBranded = _ZodBranded;
|
|
5190
|
-
var _ZodPipeline = class _ZodPipeline extends ZodType {
|
|
5191
|
-
_parse(input) {
|
|
5192
|
-
const { status, ctx } = this._processInputParams(input);
|
|
5193
|
-
if (ctx.common.async) {
|
|
5194
|
-
const handleAsync = /* @__PURE__ */ __name(async () => {
|
|
5195
|
-
const inResult = await this._def.in._parseAsync({
|
|
5196
|
-
data: ctx.data,
|
|
5197
|
-
path: ctx.path,
|
|
5198
|
-
parent: ctx
|
|
5199
|
-
});
|
|
5200
|
-
if (inResult.status === "aborted")
|
|
5201
|
-
return INVALID;
|
|
5202
|
-
if (inResult.status === "dirty") {
|
|
5203
|
-
status.dirty();
|
|
5204
|
-
return DIRTY(inResult.value);
|
|
5205
|
-
} else {
|
|
5206
|
-
return this._def.out._parseAsync({
|
|
5207
|
-
data: inResult.value,
|
|
5208
|
-
path: ctx.path,
|
|
5209
|
-
parent: ctx
|
|
5210
|
-
});
|
|
5211
|
-
}
|
|
5212
|
-
}, "handleAsync");
|
|
5213
|
-
return handleAsync();
|
|
5214
|
-
} else {
|
|
5215
|
-
const inResult = this._def.in._parseSync({
|
|
5216
|
-
data: ctx.data,
|
|
5217
|
-
path: ctx.path,
|
|
5218
|
-
parent: ctx
|
|
5219
|
-
});
|
|
5220
|
-
if (inResult.status === "aborted")
|
|
5221
|
-
return INVALID;
|
|
5222
|
-
if (inResult.status === "dirty") {
|
|
5223
|
-
status.dirty();
|
|
5224
|
-
return {
|
|
5225
|
-
status: "dirty",
|
|
5226
|
-
value: inResult.value
|
|
5227
|
-
};
|
|
5228
|
-
} else {
|
|
5229
|
-
return this._def.out._parseSync({
|
|
5230
|
-
data: inResult.value,
|
|
5231
|
-
path: ctx.path,
|
|
5232
|
-
parent: ctx
|
|
5233
|
-
});
|
|
5234
|
-
}
|
|
5235
|
-
}
|
|
5236
|
-
}
|
|
5237
|
-
static create(a, b) {
|
|
5238
|
-
return new _ZodPipeline({
|
|
5239
|
-
in: a,
|
|
5240
|
-
out: b,
|
|
5241
|
-
typeName: ZodFirstPartyTypeKind.ZodPipeline
|
|
5242
|
-
});
|
|
5243
|
-
}
|
|
5244
|
-
};
|
|
5245
|
-
__name(_ZodPipeline, "ZodPipeline");
|
|
5246
|
-
var ZodPipeline = _ZodPipeline;
|
|
5247
|
-
var _ZodReadonly = class _ZodReadonly extends ZodType {
|
|
5248
|
-
_parse(input) {
|
|
5249
|
-
const result = this._def.innerType._parse(input);
|
|
5250
|
-
const freeze = /* @__PURE__ */ __name((data) => {
|
|
5251
|
-
if (isValid(data)) {
|
|
5252
|
-
data.value = Object.freeze(data.value);
|
|
5253
|
-
}
|
|
5254
|
-
return data;
|
|
5255
|
-
}, "freeze");
|
|
5256
|
-
return isAsync(result) ? result.then((data) => freeze(data)) : freeze(result);
|
|
5257
|
-
}
|
|
5258
|
-
unwrap() {
|
|
5259
|
-
return this._def.innerType;
|
|
5260
|
-
}
|
|
5261
|
-
};
|
|
5262
|
-
__name(_ZodReadonly, "ZodReadonly");
|
|
5263
|
-
var ZodReadonly = _ZodReadonly;
|
|
5264
|
-
ZodReadonly.create = (type, params) => {
|
|
5265
|
-
return new ZodReadonly({
|
|
5266
|
-
innerType: type,
|
|
5267
|
-
typeName: ZodFirstPartyTypeKind.ZodReadonly,
|
|
5268
|
-
...processCreateParams(params)
|
|
5269
|
-
});
|
|
5270
|
-
};
|
|
5271
|
-
function custom(check, params = {}, fatal) {
|
|
5272
|
-
if (check)
|
|
5273
|
-
return ZodAny.create().superRefine((data, ctx) => {
|
|
5274
|
-
var _a, _b;
|
|
5275
|
-
if (!check(data)) {
|
|
5276
|
-
const p = typeof params === "function" ? params(data) : typeof params === "string" ? { message: params } : params;
|
|
5277
|
-
const _fatal = (_b = (_a = p.fatal) !== null && _a !== void 0 ? _a : fatal) !== null && _b !== void 0 ? _b : true;
|
|
5278
|
-
const p2 = typeof p === "string" ? { message: p } : p;
|
|
5279
|
-
ctx.addIssue({ code: "custom", ...p2, fatal: _fatal });
|
|
5280
|
-
}
|
|
5281
|
-
});
|
|
5282
|
-
return ZodAny.create();
|
|
5283
|
-
}
|
|
5284
|
-
__name(custom, "custom");
|
|
5285
|
-
var late = {
|
|
5286
|
-
object: ZodObject.lazycreate
|
|
5287
|
-
};
|
|
5288
|
-
var ZodFirstPartyTypeKind;
|
|
5289
|
-
(function(ZodFirstPartyTypeKind2) {
|
|
5290
|
-
ZodFirstPartyTypeKind2["ZodString"] = "ZodString";
|
|
5291
|
-
ZodFirstPartyTypeKind2["ZodNumber"] = "ZodNumber";
|
|
5292
|
-
ZodFirstPartyTypeKind2["ZodNaN"] = "ZodNaN";
|
|
5293
|
-
ZodFirstPartyTypeKind2["ZodBigInt"] = "ZodBigInt";
|
|
5294
|
-
ZodFirstPartyTypeKind2["ZodBoolean"] = "ZodBoolean";
|
|
5295
|
-
ZodFirstPartyTypeKind2["ZodDate"] = "ZodDate";
|
|
5296
|
-
ZodFirstPartyTypeKind2["ZodSymbol"] = "ZodSymbol";
|
|
5297
|
-
ZodFirstPartyTypeKind2["ZodUndefined"] = "ZodUndefined";
|
|
5298
|
-
ZodFirstPartyTypeKind2["ZodNull"] = "ZodNull";
|
|
5299
|
-
ZodFirstPartyTypeKind2["ZodAny"] = "ZodAny";
|
|
5300
|
-
ZodFirstPartyTypeKind2["ZodUnknown"] = "ZodUnknown";
|
|
5301
|
-
ZodFirstPartyTypeKind2["ZodNever"] = "ZodNever";
|
|
5302
|
-
ZodFirstPartyTypeKind2["ZodVoid"] = "ZodVoid";
|
|
5303
|
-
ZodFirstPartyTypeKind2["ZodArray"] = "ZodArray";
|
|
5304
|
-
ZodFirstPartyTypeKind2["ZodObject"] = "ZodObject";
|
|
5305
|
-
ZodFirstPartyTypeKind2["ZodUnion"] = "ZodUnion";
|
|
5306
|
-
ZodFirstPartyTypeKind2["ZodDiscriminatedUnion"] = "ZodDiscriminatedUnion";
|
|
5307
|
-
ZodFirstPartyTypeKind2["ZodIntersection"] = "ZodIntersection";
|
|
5308
|
-
ZodFirstPartyTypeKind2["ZodTuple"] = "ZodTuple";
|
|
5309
|
-
ZodFirstPartyTypeKind2["ZodRecord"] = "ZodRecord";
|
|
5310
|
-
ZodFirstPartyTypeKind2["ZodMap"] = "ZodMap";
|
|
5311
|
-
ZodFirstPartyTypeKind2["ZodSet"] = "ZodSet";
|
|
5312
|
-
ZodFirstPartyTypeKind2["ZodFunction"] = "ZodFunction";
|
|
5313
|
-
ZodFirstPartyTypeKind2["ZodLazy"] = "ZodLazy";
|
|
5314
|
-
ZodFirstPartyTypeKind2["ZodLiteral"] = "ZodLiteral";
|
|
5315
|
-
ZodFirstPartyTypeKind2["ZodEnum"] = "ZodEnum";
|
|
5316
|
-
ZodFirstPartyTypeKind2["ZodEffects"] = "ZodEffects";
|
|
5317
|
-
ZodFirstPartyTypeKind2["ZodNativeEnum"] = "ZodNativeEnum";
|
|
5318
|
-
ZodFirstPartyTypeKind2["ZodOptional"] = "ZodOptional";
|
|
5319
|
-
ZodFirstPartyTypeKind2["ZodNullable"] = "ZodNullable";
|
|
5320
|
-
ZodFirstPartyTypeKind2["ZodDefault"] = "ZodDefault";
|
|
5321
|
-
ZodFirstPartyTypeKind2["ZodCatch"] = "ZodCatch";
|
|
5322
|
-
ZodFirstPartyTypeKind2["ZodPromise"] = "ZodPromise";
|
|
5323
|
-
ZodFirstPartyTypeKind2["ZodBranded"] = "ZodBranded";
|
|
5324
|
-
ZodFirstPartyTypeKind2["ZodPipeline"] = "ZodPipeline";
|
|
5325
|
-
ZodFirstPartyTypeKind2["ZodReadonly"] = "ZodReadonly";
|
|
5326
|
-
})(ZodFirstPartyTypeKind || (ZodFirstPartyTypeKind = {}));
|
|
5327
|
-
var instanceOfType = /* @__PURE__ */ __name((cls, params = {
|
|
5328
|
-
message: `Input not instance of ${cls.name}`
|
|
5329
|
-
}) => custom((data) => data instanceof cls, params), "instanceOfType");
|
|
5330
|
-
var stringType = ZodString.create;
|
|
5331
|
-
var numberType = ZodNumber.create;
|
|
5332
|
-
var nanType = ZodNaN.create;
|
|
5333
|
-
var bigIntType = ZodBigInt.create;
|
|
5334
|
-
var booleanType = ZodBoolean.create;
|
|
5335
|
-
var dateType = ZodDate.create;
|
|
5336
|
-
var symbolType = ZodSymbol.create;
|
|
5337
|
-
var undefinedType = ZodUndefined.create;
|
|
5338
|
-
var nullType = ZodNull.create;
|
|
5339
|
-
var anyType = ZodAny.create;
|
|
5340
|
-
var unknownType = ZodUnknown.create;
|
|
5341
|
-
var neverType = ZodNever.create;
|
|
5342
|
-
var voidType = ZodVoid.create;
|
|
5343
|
-
var arrayType = ZodArray.create;
|
|
5344
|
-
var objectType = ZodObject.create;
|
|
5345
|
-
var strictObjectType = ZodObject.strictCreate;
|
|
5346
|
-
var unionType = ZodUnion.create;
|
|
5347
|
-
var discriminatedUnionType = ZodDiscriminatedUnion.create;
|
|
5348
|
-
var intersectionType = ZodIntersection.create;
|
|
5349
|
-
var tupleType = ZodTuple.create;
|
|
5350
|
-
var recordType = ZodRecord.create;
|
|
5351
|
-
var mapType = ZodMap.create;
|
|
5352
|
-
var setType = ZodSet.create;
|
|
5353
|
-
var functionType = ZodFunction.create;
|
|
5354
|
-
var lazyType = ZodLazy.create;
|
|
5355
|
-
var literalType = ZodLiteral.create;
|
|
5356
|
-
var enumType = ZodEnum.create;
|
|
5357
|
-
var nativeEnumType = ZodNativeEnum.create;
|
|
5358
|
-
var promiseType = ZodPromise.create;
|
|
5359
|
-
var effectsType = ZodEffects.create;
|
|
5360
|
-
var optionalType = ZodOptional.create;
|
|
5361
|
-
var nullableType = ZodNullable.create;
|
|
5362
|
-
var preprocessType = ZodEffects.createWithPreprocess;
|
|
5363
|
-
var pipelineType = ZodPipeline.create;
|
|
5364
|
-
var ostring = /* @__PURE__ */ __name(() => stringType().optional(), "ostring");
|
|
5365
|
-
var onumber = /* @__PURE__ */ __name(() => numberType().optional(), "onumber");
|
|
5366
|
-
var oboolean = /* @__PURE__ */ __name(() => booleanType().optional(), "oboolean");
|
|
5367
|
-
var coerce = {
|
|
5368
|
-
string: (arg) => ZodString.create({ ...arg, coerce: true }),
|
|
5369
|
-
number: (arg) => ZodNumber.create({ ...arg, coerce: true }),
|
|
5370
|
-
boolean: (arg) => ZodBoolean.create({
|
|
5371
|
-
...arg,
|
|
5372
|
-
coerce: true
|
|
5373
|
-
}),
|
|
5374
|
-
bigint: (arg) => ZodBigInt.create({ ...arg, coerce: true }),
|
|
5375
|
-
date: (arg) => ZodDate.create({ ...arg, coerce: true })
|
|
5376
|
-
};
|
|
5377
|
-
var NEVER = INVALID;
|
|
5378
|
-
var z = /* @__PURE__ */ Object.freeze({
|
|
5379
|
-
__proto__: null,
|
|
5380
|
-
defaultErrorMap: errorMap,
|
|
5381
|
-
setErrorMap,
|
|
5382
|
-
getErrorMap,
|
|
5383
|
-
makeIssue,
|
|
5384
|
-
EMPTY_PATH,
|
|
5385
|
-
addIssueToContext,
|
|
5386
|
-
ParseStatus,
|
|
5387
|
-
INVALID,
|
|
5388
|
-
DIRTY,
|
|
5389
|
-
OK,
|
|
5390
|
-
isAborted,
|
|
5391
|
-
isDirty,
|
|
5392
|
-
isValid,
|
|
5393
|
-
isAsync,
|
|
5394
|
-
get util() {
|
|
5395
|
-
return util;
|
|
5396
|
-
},
|
|
5397
|
-
get objectUtil() {
|
|
5398
|
-
return objectUtil;
|
|
5399
|
-
},
|
|
5400
|
-
ZodParsedType,
|
|
5401
|
-
getParsedType,
|
|
5402
|
-
ZodType,
|
|
5403
|
-
datetimeRegex,
|
|
5404
|
-
ZodString,
|
|
5405
|
-
ZodNumber,
|
|
5406
|
-
ZodBigInt,
|
|
5407
|
-
ZodBoolean,
|
|
5408
|
-
ZodDate,
|
|
5409
|
-
ZodSymbol,
|
|
5410
|
-
ZodUndefined,
|
|
5411
|
-
ZodNull,
|
|
5412
|
-
ZodAny,
|
|
5413
|
-
ZodUnknown,
|
|
5414
|
-
ZodNever,
|
|
5415
|
-
ZodVoid,
|
|
5416
|
-
ZodArray,
|
|
5417
|
-
ZodObject,
|
|
5418
|
-
ZodUnion,
|
|
5419
|
-
ZodDiscriminatedUnion,
|
|
5420
|
-
ZodIntersection,
|
|
5421
|
-
ZodTuple,
|
|
5422
|
-
ZodRecord,
|
|
5423
|
-
ZodMap,
|
|
5424
|
-
ZodSet,
|
|
5425
|
-
ZodFunction,
|
|
5426
|
-
ZodLazy,
|
|
5427
|
-
ZodLiteral,
|
|
5428
|
-
ZodEnum,
|
|
5429
|
-
ZodNativeEnum,
|
|
5430
|
-
ZodPromise,
|
|
5431
|
-
ZodEffects,
|
|
5432
|
-
ZodTransformer: ZodEffects,
|
|
5433
|
-
ZodOptional,
|
|
5434
|
-
ZodNullable,
|
|
5435
|
-
ZodDefault,
|
|
5436
|
-
ZodCatch,
|
|
5437
|
-
ZodNaN,
|
|
5438
|
-
BRAND,
|
|
5439
|
-
ZodBranded,
|
|
5440
|
-
ZodPipeline,
|
|
5441
|
-
ZodReadonly,
|
|
5442
|
-
custom,
|
|
5443
|
-
Schema: ZodType,
|
|
5444
|
-
ZodSchema: ZodType,
|
|
5445
|
-
late,
|
|
5446
|
-
get ZodFirstPartyTypeKind() {
|
|
5447
|
-
return ZodFirstPartyTypeKind;
|
|
5448
|
-
},
|
|
5449
|
-
coerce,
|
|
5450
|
-
any: anyType,
|
|
5451
|
-
array: arrayType,
|
|
5452
|
-
bigint: bigIntType,
|
|
5453
|
-
boolean: booleanType,
|
|
5454
|
-
date: dateType,
|
|
5455
|
-
discriminatedUnion: discriminatedUnionType,
|
|
5456
|
-
effect: effectsType,
|
|
5457
|
-
"enum": enumType,
|
|
5458
|
-
"function": functionType,
|
|
5459
|
-
"instanceof": instanceOfType,
|
|
5460
|
-
intersection: intersectionType,
|
|
5461
|
-
lazy: lazyType,
|
|
5462
|
-
literal: literalType,
|
|
5463
|
-
map: mapType,
|
|
5464
|
-
nan: nanType,
|
|
5465
|
-
nativeEnum: nativeEnumType,
|
|
5466
|
-
never: neverType,
|
|
5467
|
-
"null": nullType,
|
|
5468
|
-
nullable: nullableType,
|
|
5469
|
-
number: numberType,
|
|
5470
|
-
object: objectType,
|
|
5471
|
-
oboolean,
|
|
5472
|
-
onumber,
|
|
5473
|
-
optional: optionalType,
|
|
5474
|
-
ostring,
|
|
5475
|
-
pipeline: pipelineType,
|
|
5476
|
-
preprocess: preprocessType,
|
|
5477
|
-
promise: promiseType,
|
|
5478
|
-
record: recordType,
|
|
5479
|
-
set: setType,
|
|
5480
|
-
strictObject: strictObjectType,
|
|
5481
|
-
string: stringType,
|
|
5482
|
-
symbol: symbolType,
|
|
5483
|
-
transformer: effectsType,
|
|
5484
|
-
tuple: tupleType,
|
|
5485
|
-
"undefined": undefinedType,
|
|
5486
|
-
union: unionType,
|
|
5487
|
-
unknown: unknownType,
|
|
5488
|
-
"void": voidType,
|
|
5489
|
-
NEVER,
|
|
5490
|
-
ZodIssueCode,
|
|
5491
|
-
quotelessJson,
|
|
5492
|
-
ZodError
|
|
5493
|
-
});
|
|
5494
|
-
|
|
5495
|
-
// ../shared/src/guards.ts
|
|
5496
|
-
var isString = /* @__PURE__ */ __name((value) => typeof value === "string", "isString");
|
|
5497
|
-
function assert(condition, message) {
|
|
5498
|
-
if (condition)
|
|
5499
|
-
return;
|
|
5500
|
-
const error = new Error(message);
|
|
5501
|
-
if (error.stack) {
|
|
5502
|
-
error.stack = error.stack.replace(/\n.+/, "\n");
|
|
5503
|
-
}
|
|
5504
|
-
throw error;
|
|
1083
|
+
throw error;
|
|
5505
1084
|
}
|
|
5506
1085
|
__name(assert, "assert");
|
|
5507
1086
|
|
|
5508
|
-
// ../shared/src/bitcoin.ts
|
|
5509
|
-
__toESM(require_lib());
|
|
5510
|
-
|
|
5511
|
-
// ../shared/src/parsers.ts
|
|
5512
|
-
var enumValues = Object.values;
|
|
5513
|
-
var safeStringify = /* @__PURE__ */ __name((obj) => JSON.stringify(obj, (key, value) => typeof value === "bigint" ? value.toString() : value), "safeStringify");
|
|
5514
|
-
var errorMap2 = /* @__PURE__ */ __name((_issue, context) => ({
|
|
5515
|
-
message: `received: ${safeStringify(context.data)}`
|
|
5516
|
-
}), "errorMap");
|
|
5517
|
-
var string = z.string({
|
|
5518
|
-
errorMap: errorMap2
|
|
5519
|
-
});
|
|
5520
|
-
var number = z.number({
|
|
5521
|
-
errorMap: errorMap2
|
|
5522
|
-
});
|
|
5523
|
-
var numericString = string.regex(/^[0-9]+$/);
|
|
5524
|
-
string.regex(/^[0-9]*$/);
|
|
5525
|
-
var hexString = string.refine((v) => /^0x[0-9a-f]*$/i.test(v));
|
|
5526
|
-
numericString.transform((arg) => `0x${BigInt(arg).toString(16)}`);
|
|
5527
|
-
var DOT_PREFIX = 0;
|
|
5528
|
-
z.union([
|
|
5529
|
-
string,
|
|
5530
|
-
hexString
|
|
5531
|
-
]).transform((arg) => {
|
|
5532
|
-
try {
|
|
5533
|
-
if (arg.startsWith("0x")) {
|
|
5534
|
-
return ss582__namespace.encode({
|
|
5535
|
-
data: arg,
|
|
5536
|
-
ss58Format: DOT_PREFIX
|
|
5537
|
-
});
|
|
5538
|
-
}
|
|
5539
|
-
return ss582__namespace.encode({
|
|
5540
|
-
data: ss582__namespace.decode(arg).data,
|
|
5541
|
-
ss58Format: DOT_PREFIX
|
|
5542
|
-
});
|
|
5543
|
-
} catch {
|
|
5544
|
-
return null;
|
|
5545
|
-
}
|
|
5546
|
-
}).refine(isString, {
|
|
5547
|
-
message: `address is not a valid polkadot address`
|
|
5548
|
-
});
|
|
5549
|
-
hexString.refine((address) => ethers2__namespace.isAddress(address), (address) => ({
|
|
5550
|
-
message: `${address} is not a valid ethereum address`
|
|
5551
|
-
}));
|
|
5552
|
-
string.refine((address) => address.startsWith("cF") && ss582__namespace.decode(address), (address) => ({
|
|
5553
|
-
message: `${address} is not a valid chainflip address`
|
|
5554
|
-
}));
|
|
5555
|
-
numericString.transform((arg) => BigInt(arg));
|
|
5556
|
-
var u128 = z.union([
|
|
5557
|
-
number,
|
|
5558
|
-
numericString,
|
|
5559
|
-
hexString
|
|
5560
|
-
]).transform((arg) => BigInt(arg));
|
|
5561
|
-
var unsignedInteger = z.union([
|
|
5562
|
-
u128,
|
|
5563
|
-
z.number().transform((n) => BigInt(n))
|
|
5564
|
-
]);
|
|
5565
|
-
var rustEnum = /* @__PURE__ */ __name((values) => z.object({
|
|
5566
|
-
__kind: z.enum(values)
|
|
5567
|
-
}).transform(({ __kind }) => __kind), "rustEnum");
|
|
5568
|
-
rustEnum(enumValues(InternalAssets));
|
|
5569
|
-
rustEnum(enumValues(Chains));
|
|
5570
|
-
z.nativeEnum(Chains);
|
|
5571
|
-
z.nativeEnum(Assets);
|
|
5572
|
-
z.nativeEnum(ChainflipNetworks);
|
|
5573
|
-
var uncheckedAssetAndChain = z.object({
|
|
5574
|
-
asset: z.string(),
|
|
5575
|
-
chain: z.string()
|
|
5576
|
-
});
|
|
5577
|
-
uncheckedAssetAndChain.refine((value) => isValidAssetAndChain(value));
|
|
5578
|
-
z.union([
|
|
5579
|
-
z.object({
|
|
5580
|
-
__kind: z.literal("CcmPrincipal"),
|
|
5581
|
-
value: unsignedInteger
|
|
5582
|
-
}).transform(({ value: ccmId }) => ({
|
|
5583
|
-
type: "PRINCIPAL",
|
|
5584
|
-
ccmId
|
|
5585
|
-
})),
|
|
5586
|
-
z.object({
|
|
5587
|
-
__kind: z.literal("CcmGas"),
|
|
5588
|
-
value: unsignedInteger
|
|
5589
|
-
}).transform(({ value: ccmId }) => ({
|
|
5590
|
-
type: "GAS",
|
|
5591
|
-
ccmId
|
|
5592
|
-
})),
|
|
5593
|
-
z.object({
|
|
5594
|
-
__kind: z.literal("Swap")
|
|
5595
|
-
}).transform(() => ({
|
|
5596
|
-
type: "SWAP"
|
|
5597
|
-
}))
|
|
5598
|
-
]);
|
|
5599
|
-
var chainflipSS58Prefix = 2112;
|
|
5600
|
-
z.union([
|
|
5601
|
-
hexString,
|
|
5602
|
-
string.regex(/^[a-f\d]$/i).transform((value) => `0x${value}`)
|
|
5603
|
-
]).transform((value) => ss582__namespace.encode({
|
|
5604
|
-
data: value,
|
|
5605
|
-
ss58Format: chainflipSS58Prefix
|
|
5606
|
-
}));
|
|
5607
|
-
z.union([
|
|
5608
|
-
z.object({
|
|
5609
|
-
__kind: z.literal("Swap"),
|
|
5610
|
-
swapId: u128
|
|
5611
|
-
}),
|
|
5612
|
-
z.object({
|
|
5613
|
-
__kind: z.literal("LiquidityProvision"),
|
|
5614
|
-
lpAccount: hexString
|
|
5615
|
-
}),
|
|
5616
|
-
z.object({
|
|
5617
|
-
__kind: z.literal("CcmTransfer"),
|
|
5618
|
-
principalSwapId: u128.nullable().optional(),
|
|
5619
|
-
gasSwapId: u128.nullable().optional()
|
|
5620
|
-
}),
|
|
5621
|
-
z.object({
|
|
5622
|
-
__kind: z.literal("NoAction")
|
|
5623
|
-
}),
|
|
5624
|
-
z.object({
|
|
5625
|
-
__kind: z.literal("BoostersCredited"),
|
|
5626
|
-
prewitnessedDepositId: u128
|
|
5627
|
-
})
|
|
5628
|
-
]);
|
|
5629
|
-
|
|
5630
|
-
// ../shared/src/rpc/index.ts
|
|
5631
|
-
var numberOrHex = z.union([
|
|
5632
|
-
z.string(),
|
|
5633
|
-
z.number()
|
|
5634
|
-
]).transform((str) => BigInt(str));
|
|
5635
|
-
var camelCase = /* @__PURE__ */ __name((str) => str.replace(/_([a-z])/g, (_, char) => char.toUpperCase()), "camelCase");
|
|
5636
|
-
var camelCaseKeys = /* @__PURE__ */ __name((obj) => {
|
|
5637
|
-
if (typeof obj !== "object" || obj === null)
|
|
5638
|
-
return obj;
|
|
5639
|
-
if (Array.isArray(obj))
|
|
5640
|
-
return obj.map((item) => camelCaseKeys(item));
|
|
5641
|
-
return Object.fromEntries(Object.entries(obj).map(([key, value]) => [
|
|
5642
|
-
camelCase(key),
|
|
5643
|
-
camelCaseKeys(value)
|
|
5644
|
-
]));
|
|
5645
|
-
}, "camelCaseKeys");
|
|
5646
|
-
var RPC_URLS = {
|
|
5647
|
-
[ChainflipNetworks.backspin]: "https://backspin-rpc.staging",
|
|
5648
|
-
[ChainflipNetworks.sisyphos]: "https://archive.sisyphos.chainflip.io",
|
|
5649
|
-
[ChainflipNetworks.perseverance]: "https://archive.perseverance.chainflip.io",
|
|
5650
|
-
[ChainflipNetworks.mainnet]: "https://mainnet-rpc.chainflip.io"
|
|
5651
|
-
};
|
|
5652
|
-
var createRequest = /* @__PURE__ */ __name((method, responseParser) => async (urlOrNetwork, ...params) => {
|
|
5653
|
-
const url = "network" in urlOrNetwork ? RPC_URLS[urlOrNetwork.network] : urlOrNetwork.rpcUrl;
|
|
5654
|
-
const { data } = await axios__default.default.post(url, {
|
|
5655
|
-
jsonrpc: "2.0",
|
|
5656
|
-
method,
|
|
5657
|
-
params,
|
|
5658
|
-
id: 1
|
|
5659
|
-
});
|
|
5660
|
-
const result = responseParser.safeParse(data.result);
|
|
5661
|
-
if (result.success) {
|
|
5662
|
-
return camelCaseKeys(result.data);
|
|
5663
|
-
}
|
|
5664
|
-
throw new Error(`RPC request "${method}" failed`, {
|
|
5665
|
-
cause: data.error
|
|
5666
|
-
});
|
|
5667
|
-
}, "createRequest");
|
|
5668
|
-
var createRequestWithoutParser = /* @__PURE__ */ __name((method) => async (urlOrNetwork, ...params) => {
|
|
5669
|
-
const url = "network" in urlOrNetwork ? RPC_URLS[urlOrNetwork.network] : urlOrNetwork.rpcUrl;
|
|
5670
|
-
const { data } = await axios__default.default.post(
|
|
5671
|
-
url,
|
|
5672
|
-
{
|
|
5673
|
-
jsonrpc: "2.0",
|
|
5674
|
-
method,
|
|
5675
|
-
params,
|
|
5676
|
-
id: 1
|
|
5677
|
-
},
|
|
5678
|
-
// prevent JSON.parse from being called because the RPC we are requesting
|
|
5679
|
-
// returns numbers that are unsafe to parse
|
|
5680
|
-
{
|
|
5681
|
-
transformResponse: (d) => d
|
|
5682
|
-
}
|
|
5683
|
-
);
|
|
5684
|
-
return data;
|
|
5685
|
-
}, "createRequestWithoutParser");
|
|
5686
|
-
var fundingEnvironment = z.object({
|
|
5687
|
-
redemption_tax: numberOrHex,
|
|
5688
|
-
minimum_funding_amount: numberOrHex
|
|
5689
|
-
});
|
|
5690
|
-
var getFundingEnvironment = createRequest("cf_funding_environment", fundingEnvironment);
|
|
5691
|
-
var chainAssetMapFactory = /* @__PURE__ */ __name((parser, defaultValue) => z.object({
|
|
5692
|
-
Bitcoin: z.object({
|
|
5693
|
-
BTC: parser
|
|
5694
|
-
}),
|
|
5695
|
-
Ethereum: z.object({
|
|
5696
|
-
ETH: parser,
|
|
5697
|
-
USDC: parser,
|
|
5698
|
-
FLIP: parser,
|
|
5699
|
-
USDT: parser.default(defaultValue)
|
|
5700
|
-
}),
|
|
5701
|
-
Polkadot: z.object({
|
|
5702
|
-
DOT: parser
|
|
5703
|
-
}),
|
|
5704
|
-
Arbitrum: z.object({
|
|
5705
|
-
ETH: parser,
|
|
5706
|
-
USDC: parser
|
|
5707
|
-
}).default({
|
|
5708
|
-
ETH: defaultValue,
|
|
5709
|
-
USDC: defaultValue
|
|
5710
|
-
})
|
|
5711
|
-
}), "chainAssetMapFactory");
|
|
5712
|
-
var chainMapFactory = /* @__PURE__ */ __name((parser, defaultValue) => z.object({
|
|
5713
|
-
Bitcoin: parser,
|
|
5714
|
-
Ethereum: parser,
|
|
5715
|
-
Polkadot: parser,
|
|
5716
|
-
Arbitrum: parser.default(defaultValue)
|
|
5717
|
-
}), "chainMapFactory");
|
|
5718
|
-
var chainNumberNullableMap = chainMapFactory(numberOrHex.nullable(), null);
|
|
5719
|
-
var swappingEnvironment = z.object({
|
|
5720
|
-
maximum_swap_amounts: chainAssetMapFactory(numberOrHex.nullable(), null)
|
|
5721
|
-
});
|
|
5722
|
-
createRequest("cf_swapping_environment", swappingEnvironment);
|
|
5723
|
-
var rename = /* @__PURE__ */ __name((mapping) => (obj) => Object.fromEntries(Object.entries(obj).map(([key, value]) => [
|
|
5724
|
-
key in mapping ? mapping[key] : key,
|
|
5725
|
-
value
|
|
5726
|
-
])), "rename");
|
|
5727
|
-
var ingressEgressEnvironment = z.object({
|
|
5728
|
-
minimum_deposit_amounts: chainAssetMapFactory(numberOrHex, 0),
|
|
5729
|
-
ingress_fees: chainAssetMapFactory(numberOrHex.nullable(), null),
|
|
5730
|
-
egress_fees: chainAssetMapFactory(numberOrHex.nullable(), null),
|
|
5731
|
-
witness_safety_margins: chainNumberNullableMap,
|
|
5732
|
-
egress_dust_limits: chainAssetMapFactory(numberOrHex, 1),
|
|
5733
|
-
// TODO(1.3): remove optional and default value
|
|
5734
|
-
channel_opening_fees: chainMapFactory(numberOrHex, 0).optional().default({
|
|
5735
|
-
Bitcoin: 0,
|
|
5736
|
-
Ethereum: 0,
|
|
5737
|
-
Polkadot: 0,
|
|
5738
|
-
Arbitrum: 0
|
|
5739
|
-
})
|
|
5740
|
-
}).transform(rename({
|
|
5741
|
-
egress_dust_limits: "minimum_egress_amounts"
|
|
5742
|
-
}));
|
|
5743
|
-
createRequest("cf_ingress_egress_environment", ingressEgressEnvironment);
|
|
5744
|
-
var rpcAssetSchema = z.union([
|
|
5745
|
-
z.object({
|
|
5746
|
-
chain: z.literal("Bitcoin"),
|
|
5747
|
-
asset: z.literal("BTC")
|
|
5748
|
-
}),
|
|
5749
|
-
z.object({
|
|
5750
|
-
chain: z.literal("Polkadot"),
|
|
5751
|
-
asset: z.literal("DOT")
|
|
5752
|
-
}),
|
|
5753
|
-
z.object({
|
|
5754
|
-
chain: z.literal("Ethereum"),
|
|
5755
|
-
asset: z.literal("FLIP")
|
|
5756
|
-
}),
|
|
5757
|
-
z.object({
|
|
5758
|
-
chain: z.literal("Ethereum"),
|
|
5759
|
-
asset: z.literal("ETH")
|
|
5760
|
-
}),
|
|
5761
|
-
z.object({
|
|
5762
|
-
chain: z.literal("Ethereum"),
|
|
5763
|
-
asset: z.literal("USDC")
|
|
5764
|
-
}),
|
|
5765
|
-
z.object({
|
|
5766
|
-
chain: z.literal("Ethereum"),
|
|
5767
|
-
asset: z.literal("USDT")
|
|
5768
|
-
}),
|
|
5769
|
-
z.object({
|
|
5770
|
-
chain: z.literal("Arbitrum"),
|
|
5771
|
-
asset: z.literal("ETH")
|
|
5772
|
-
}),
|
|
5773
|
-
z.object({
|
|
5774
|
-
chain: z.literal("Arbitrum"),
|
|
5775
|
-
asset: z.literal("USDC")
|
|
5776
|
-
})
|
|
5777
|
-
]);
|
|
5778
|
-
var environment = z.object({
|
|
5779
|
-
ingress_egress: ingressEgressEnvironment,
|
|
5780
|
-
swapping: swappingEnvironment,
|
|
5781
|
-
funding: fundingEnvironment
|
|
5782
|
-
});
|
|
5783
|
-
createRequest("cf_environment", environment);
|
|
5784
|
-
var swapRate = z.object({
|
|
5785
|
-
output: numberOrHex
|
|
5786
|
-
});
|
|
5787
|
-
createRequest("cf_swap_rate", swapRate);
|
|
5788
|
-
createRequest("state_getMetadata", hexString);
|
|
5789
|
-
var supportedAssets = z.array(uncheckedAssetAndChain);
|
|
5790
|
-
createRequest("cf_supported_assets", supportedAssets);
|
|
5791
|
-
createRequest("state_getRuntimeVersion", z.object({
|
|
5792
|
-
specVersion: z.number()
|
|
5793
|
-
}));
|
|
5794
|
-
createRequestWithoutParser("cf_pool_orders");
|
|
5795
|
-
createRequest("cf_pool_price_v2", z.object({
|
|
5796
|
-
range_order: numberOrHex
|
|
5797
|
-
}));
|
|
5798
|
-
createRequest("chain_getBlockHash", hexString);
|
|
5799
|
-
var boostPoolsDepthResponseSchema = z.array(z.intersection(rpcAssetSchema, z.object({
|
|
5800
|
-
tier: number,
|
|
5801
|
-
available_amount: u128
|
|
5802
|
-
})));
|
|
5803
|
-
createRequest("cf_boost_pools_depth", boostPoolsDepthResponseSchema);
|
|
5804
|
-
|
|
5805
|
-
// ../shared/src/stateChainGateway/utils.ts
|
|
5806
|
-
var getStateChainGateway = /* @__PURE__ */ __name((networkOpts) => {
|
|
5807
|
-
const stateChainGatewayContractAddress = networkOpts.network === "localnet" ? networkOpts.stateChainGatewayContractAddress : getStateChainGatewayContractAddress(networkOpts.network);
|
|
5808
|
-
return StateChainGateway__factory.connect(stateChainGatewayContractAddress, networkOpts.signer);
|
|
5809
|
-
}, "getStateChainGateway");
|
|
5810
|
-
|
|
5811
1087
|
// ../shared/src/stateChainGateway/approval.ts
|
|
5812
1088
|
var checkStateChainGatewayAllowance = /* @__PURE__ */ __name(async (amount, networkOpts) => {
|
|
5813
1089
|
const flipContractAddress = networkOpts.network === "localnet" ? networkOpts.flipContractAddress : getTokenContractAddress(InternalAssets.Flip, networkOpts.network);
|
|
@@ -5823,18 +1099,18 @@ var approveStateChainGateway = /* @__PURE__ */ __name(async (amount, networkOpts
|
|
|
5823
1099
|
}, "approveStateChainGateway");
|
|
5824
1100
|
|
|
5825
1101
|
// ../shared/src/stateChainGateway/index.ts
|
|
5826
|
-
var fundStateChainAccount = /* @__PURE__ */ __name(async (
|
|
1102
|
+
var fundStateChainAccount = /* @__PURE__ */ __name(async (accountId, amount, networkOpts, txOpts) => {
|
|
5827
1103
|
const flipContractAddress = networkOpts.network === "localnet" ? networkOpts.flipContractAddress : getTokenContractAddress(InternalAssets.Flip, networkOpts.network);
|
|
5828
1104
|
const stateChainGateway = getStateChainGateway(networkOpts);
|
|
5829
1105
|
const { hasSufficientAllowance } = await checkAllowance(amount, await stateChainGateway.getAddress(), flipContractAddress, networkOpts.signer);
|
|
5830
1106
|
assert(hasSufficientAllowance, "Insufficient allowance");
|
|
5831
|
-
const transaction = await stateChainGateway.fundStateChainAccount(
|
|
1107
|
+
const transaction = await stateChainGateway.fundStateChainAccount(accountId, amount, extractOverrides(txOpts));
|
|
5832
1108
|
await transaction.wait(txOpts.wait);
|
|
5833
1109
|
return transaction;
|
|
5834
1110
|
}, "fundStateChainAccount");
|
|
5835
|
-
var executeRedemption = /* @__PURE__ */ __name(async (
|
|
1111
|
+
var executeRedemption = /* @__PURE__ */ __name(async (accountId, networkOpts, txOpts) => {
|
|
5836
1112
|
const stateChainGateway = getStateChainGateway(networkOpts);
|
|
5837
|
-
const transaction = await stateChainGateway.executeRedemption(
|
|
1113
|
+
const transaction = await stateChainGateway.executeRedemption(accountId, extractOverrides(txOpts));
|
|
5838
1114
|
await transaction.wait(txOpts.wait);
|
|
5839
1115
|
return transaction;
|
|
5840
1116
|
}, "executeRedemption");
|
|
@@ -5846,10 +1122,10 @@ var getRedemptionDelay = /* @__PURE__ */ __name((networkOpts) => {
|
|
|
5846
1122
|
const stateChainGateway = getStateChainGateway(networkOpts);
|
|
5847
1123
|
return stateChainGateway.REDEMPTION_DELAY();
|
|
5848
1124
|
}, "getRedemptionDelay");
|
|
5849
|
-
var getPendingRedemption = /* @__PURE__ */ __name(async (
|
|
1125
|
+
var getPendingRedemption = /* @__PURE__ */ __name(async (accountId, networkOpts) => {
|
|
5850
1126
|
const stateChainGateway = getStateChainGateway(networkOpts);
|
|
5851
|
-
const pendingRedemption = await stateChainGateway.getPendingRedemption(
|
|
5852
|
-
return pendingRedemption.amount !== 0n ? stateChainGateway.getPendingRedemption(
|
|
1127
|
+
const pendingRedemption = await stateChainGateway.getPendingRedemption(accountId);
|
|
1128
|
+
return pendingRedemption.amount !== 0n ? stateChainGateway.getPendingRedemption(accountId) : void 0;
|
|
5853
1129
|
}, "getPendingRedemption");
|
|
5854
1130
|
|
|
5855
1131
|
// src/funding/sdk.ts
|
|
@@ -5873,15 +1149,15 @@ var _FundingSDK = class _FundingSDK {
|
|
|
5873
1149
|
* @param accountId the hex-encoded validator account id
|
|
5874
1150
|
* @param amount the amount to fund in base units of FLIP
|
|
5875
1151
|
*/
|
|
5876
|
-
async fundStateChainAccount(
|
|
5877
|
-
const tx = await fundStateChainAccount(
|
|
1152
|
+
async fundStateChainAccount(accountId, amount, txOpts = {}) {
|
|
1153
|
+
const tx = await fundStateChainAccount(accountId, amount, this.options, txOpts);
|
|
5878
1154
|
return tx.hash;
|
|
5879
1155
|
}
|
|
5880
1156
|
/**
|
|
5881
1157
|
* @param accountId the hex-encoded validator account id
|
|
5882
1158
|
*/
|
|
5883
|
-
async executeRedemption(
|
|
5884
|
-
const tx = await executeRedemption(
|
|
1159
|
+
async executeRedemption(accountId, txOpts = {}) {
|
|
1160
|
+
const tx = await executeRedemption(accountId, this.options, txOpts);
|
|
5885
1161
|
return tx.hash;
|
|
5886
1162
|
}
|
|
5887
1163
|
async getMinimumFunding() {
|
|
@@ -5893,8 +1169,8 @@ var _FundingSDK = class _FundingSDK {
|
|
|
5893
1169
|
async getFlipBalance() {
|
|
5894
1170
|
return getFlipBalance(this.options.network, this.options.signer);
|
|
5895
1171
|
}
|
|
5896
|
-
async getPendingRedemption(
|
|
5897
|
-
return getPendingRedemption(
|
|
1172
|
+
async getPendingRedemption(accountId) {
|
|
1173
|
+
return getPendingRedemption(accountId, this.options);
|
|
5898
1174
|
}
|
|
5899
1175
|
/**
|
|
5900
1176
|
* @param the amount of FLIP to request approval for
|