@valbuild/ui 0.42.0 → 0.43.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/valbuild-ui.cjs.d.ts +1 -1
- package/dist/valbuild-ui.cjs.js +12858 -12814
- package/dist/valbuild-ui.esm.js +12858 -12814
- package/package.json +3 -3
- package/server/.tmp/assets/index-3OuTk_rp.js +201 -0
- package/server/.tmp/index.html +1 -1
- package/server/dist/valbuild-ui-main.cjs.js +3987 -150
- package/server/dist/valbuild-ui-main.esm.js +3987 -150
- package/server/dist/valbuild-ui-server.cjs.js +1 -1
- package/server/dist/valbuild-ui-server.esm.js +1 -1
- package/server/.tmp/assets/index-IXGqng3y.js +0 -201
|
@@ -961,7 +961,7 @@ function requireReact_development() {
|
|
|
961
961
|
_status: Uninitialized,
|
|
962
962
|
_result: ctor
|
|
963
963
|
};
|
|
964
|
-
var
|
|
964
|
+
var lazyType2 = {
|
|
965
965
|
$$typeof: REACT_LAZY_TYPE,
|
|
966
966
|
_payload: payload,
|
|
967
967
|
_init: lazyInitializer
|
|
@@ -969,7 +969,7 @@ function requireReact_development() {
|
|
|
969
969
|
{
|
|
970
970
|
var defaultProps;
|
|
971
971
|
var propTypes2;
|
|
972
|
-
Object.defineProperties(
|
|
972
|
+
Object.defineProperties(lazyType2, {
|
|
973
973
|
defaultProps: {
|
|
974
974
|
configurable: true,
|
|
975
975
|
get: function() {
|
|
@@ -978,7 +978,7 @@ function requireReact_development() {
|
|
|
978
978
|
set: function(newDefaultProps) {
|
|
979
979
|
error("React.lazy(...): It is not supported to assign `defaultProps` to a lazy component import. Either specify them where the component is defined, or create a wrapping component around it.");
|
|
980
980
|
defaultProps = newDefaultProps;
|
|
981
|
-
Object.defineProperty(
|
|
981
|
+
Object.defineProperty(lazyType2, "defaultProps", {
|
|
982
982
|
enumerable: true
|
|
983
983
|
});
|
|
984
984
|
}
|
|
@@ -991,14 +991,14 @@ function requireReact_development() {
|
|
|
991
991
|
set: function(newPropTypes) {
|
|
992
992
|
error("React.lazy(...): It is not supported to assign `propTypes` to a lazy component import. Either specify them where the component is defined, or create a wrapping component around it.");
|
|
993
993
|
propTypes2 = newPropTypes;
|
|
994
|
-
Object.defineProperty(
|
|
994
|
+
Object.defineProperty(lazyType2, "propTypes", {
|
|
995
995
|
enumerable: true
|
|
996
996
|
});
|
|
997
997
|
}
|
|
998
998
|
}
|
|
999
999
|
});
|
|
1000
1000
|
}
|
|
1001
|
-
return
|
|
1001
|
+
return lazyType2;
|
|
1002
1002
|
}
|
|
1003
1003
|
function forwardRef(render) {
|
|
1004
1004
|
{
|
|
@@ -1942,11 +1942,11 @@ function requireReact_production_min() {
|
|
|
1942
1942
|
if (hasRequiredReact_production_min)
|
|
1943
1943
|
return react_production_min;
|
|
1944
1944
|
hasRequiredReact_production_min = 1;
|
|
1945
|
-
var l = Symbol.for("react.element"), n = Symbol.for("react.portal"), p = Symbol.for("react.fragment"), q = Symbol.for("react.strict_mode"), r2 = Symbol.for("react.profiler"), t = Symbol.for("react.provider"), u = Symbol.for("react.context"), v = Symbol.for("react.forward_ref"), w = Symbol.for("react.suspense"), x = Symbol.for("react.memo"), y = Symbol.for("react.lazy"),
|
|
1945
|
+
var l = Symbol.for("react.element"), n = Symbol.for("react.portal"), p = Symbol.for("react.fragment"), q = Symbol.for("react.strict_mode"), r2 = Symbol.for("react.profiler"), t = Symbol.for("react.provider"), u = Symbol.for("react.context"), v = Symbol.for("react.forward_ref"), w = Symbol.for("react.suspense"), x = Symbol.for("react.memo"), y = Symbol.for("react.lazy"), z2 = Symbol.iterator;
|
|
1946
1946
|
function A(a) {
|
|
1947
1947
|
if (null === a || "object" !== typeof a)
|
|
1948
1948
|
return null;
|
|
1949
|
-
a =
|
|
1949
|
+
a = z2 && a[z2] || a["@@iterator"];
|
|
1950
1950
|
return "function" === typeof a ? a : null;
|
|
1951
1951
|
}
|
|
1952
1952
|
var B = { isMounted: function() {
|
|
@@ -2749,7 +2749,7 @@ function requireScheduler_production_min() {
|
|
|
2749
2749
|
return p.now() - q;
|
|
2750
2750
|
};
|
|
2751
2751
|
}
|
|
2752
|
-
var r2 = [], t = [], u = 1, v = null, y = 3,
|
|
2752
|
+
var r2 = [], t = [], u = 1, v = null, y = 3, z2 = false, A = false, B = false, D = "function" === typeof setTimeout ? setTimeout : null, E = "function" === typeof clearTimeout ? clearTimeout : null, F = "undefined" !== typeof setImmediate ? setImmediate : null;
|
|
2753
2753
|
"undefined" !== typeof navigator && void 0 !== navigator.scheduling && void 0 !== navigator.scheduling.isInputPending && navigator.scheduling.isInputPending.bind(navigator.scheduling);
|
|
2754
2754
|
function G(a) {
|
|
2755
2755
|
for (var b = h(t); null !== b; ) {
|
|
@@ -2776,7 +2776,7 @@ function requireScheduler_production_min() {
|
|
|
2776
2776
|
function J(a, b) {
|
|
2777
2777
|
A = false;
|
|
2778
2778
|
B && (B = false, E(L), L = -1);
|
|
2779
|
-
|
|
2779
|
+
z2 = true;
|
|
2780
2780
|
var c = y;
|
|
2781
2781
|
try {
|
|
2782
2782
|
G(b);
|
|
@@ -2802,7 +2802,7 @@ function requireScheduler_production_min() {
|
|
|
2802
2802
|
}
|
|
2803
2803
|
return w;
|
|
2804
2804
|
} finally {
|
|
2805
|
-
v = null, y = c,
|
|
2805
|
+
v = null, y = c, z2 = false;
|
|
2806
2806
|
}
|
|
2807
2807
|
}
|
|
2808
2808
|
var N2 = false, O = null, L = -1, P = 5, Q = -1;
|
|
@@ -2856,7 +2856,7 @@ function requireScheduler_production_min() {
|
|
|
2856
2856
|
a.callback = null;
|
|
2857
2857
|
};
|
|
2858
2858
|
exports.unstable_continueExecution = function() {
|
|
2859
|
-
A ||
|
|
2859
|
+
A || z2 || (A = true, I(J));
|
|
2860
2860
|
};
|
|
2861
2861
|
exports.unstable_forceFrameRate = function(a) {
|
|
2862
2862
|
0 > a || 125 < a ? console.error("forceFrameRate takes a positive int between 0 and 125, forcing frame rates higher than 125 fps is not supported") : P = 0 < a ? Math.floor(1e3 / a) : 5;
|
|
@@ -2929,7 +2929,7 @@ function requireScheduler_production_min() {
|
|
|
2929
2929
|
}
|
|
2930
2930
|
e = c + e;
|
|
2931
2931
|
a = { id: u++, callback: b, priorityLevel: a, startTime: c, expirationTime: e, sortIndex: -1 };
|
|
2932
|
-
c > d ? (a.sortIndex = c, f(t, a), null === h(r2) && a === h(t) && (B ? (E(L), L = -1) : B = true, K2(H, c - d))) : (a.sortIndex = e, f(r2, a), A ||
|
|
2932
|
+
c > d ? (a.sortIndex = c, f(t, a), null === h(r2) && a === h(t) && (B ? (E(L), L = -1) : B = true, K2(H, c - d))) : (a.sortIndex = e, f(r2, a), A || z2 || (A = true, I(J)));
|
|
2933
2933
|
return a;
|
|
2934
2934
|
};
|
|
2935
2935
|
exports.unstable_shouldYield = M;
|
|
@@ -5815,8 +5815,8 @@ function requireReactDom_development() {
|
|
|
5815
5815
|
{
|
|
5816
5816
|
var invalidProps = [];
|
|
5817
5817
|
for (var key in props) {
|
|
5818
|
-
var
|
|
5819
|
-
if (!
|
|
5818
|
+
var isValid2 = validateProperty(type, key);
|
|
5819
|
+
if (!isValid2) {
|
|
5820
5820
|
invalidProps.push(key);
|
|
5821
5821
|
}
|
|
5822
5822
|
}
|
|
@@ -5958,8 +5958,8 @@ function requireReactDom_development() {
|
|
|
5958
5958
|
{
|
|
5959
5959
|
var unknownProps = [];
|
|
5960
5960
|
for (var key in props) {
|
|
5961
|
-
var
|
|
5962
|
-
if (!
|
|
5961
|
+
var isValid2 = validateProperty$1(type, key, props[key], eventRegistry);
|
|
5962
|
+
if (!isValid2) {
|
|
5963
5963
|
unknownProps.push(key);
|
|
5964
5964
|
}
|
|
5965
5965
|
}
|
|
@@ -13298,11 +13298,11 @@ function requireReactDom_development() {
|
|
|
13298
13298
|
var contextType = ctor.contextType;
|
|
13299
13299
|
{
|
|
13300
13300
|
if ("contextType" in ctor) {
|
|
13301
|
-
var
|
|
13301
|
+
var isValid2 = (
|
|
13302
13302
|
// Allow null for conditional declaration
|
|
13303
13303
|
contextType === null || contextType !== void 0 && contextType.$$typeof === REACT_CONTEXT_TYPE && contextType._context === void 0
|
|
13304
13304
|
);
|
|
13305
|
-
if (!
|
|
13305
|
+
if (!isValid2 && !didWarnAboutInvalidateContextType.has(ctor)) {
|
|
13306
13306
|
didWarnAboutInvalidateContextType.add(ctor);
|
|
13307
13307
|
var addendum = "";
|
|
13308
13308
|
if (contextType === void 0) {
|
|
@@ -13743,9 +13743,9 @@ function requireReactDom_development() {
|
|
|
13743
13743
|
error("Functions are not valid as a React child. This may happen if you return a Component instead of <Component /> from render. Or maybe you meant to call this function rather than return it.");
|
|
13744
13744
|
}
|
|
13745
13745
|
}
|
|
13746
|
-
function resolveLazy(
|
|
13747
|
-
var payload =
|
|
13748
|
-
var init =
|
|
13746
|
+
function resolveLazy(lazyType2) {
|
|
13747
|
+
var payload = lazyType2._payload;
|
|
13748
|
+
var init = lazyType2._init;
|
|
13749
13749
|
return init(payload);
|
|
13750
13750
|
}
|
|
13751
13751
|
function ChildReconciler(shouldTrackSideEffects) {
|
|
@@ -24145,34 +24145,34 @@ function requireReactDom_production_min() {
|
|
|
24145
24145
|
this.sanitizeURL = f;
|
|
24146
24146
|
this.removeEmptyString = g;
|
|
24147
24147
|
}
|
|
24148
|
-
var
|
|
24148
|
+
var z2 = {};
|
|
24149
24149
|
"children dangerouslySetInnerHTML defaultValue defaultChecked innerHTML suppressContentEditableWarning suppressHydrationWarning style".split(" ").forEach(function(a) {
|
|
24150
|
-
|
|
24150
|
+
z2[a] = new v(a, 0, false, a, null, false, false);
|
|
24151
24151
|
});
|
|
24152
24152
|
[["acceptCharset", "accept-charset"], ["className", "class"], ["htmlFor", "for"], ["httpEquiv", "http-equiv"]].forEach(function(a) {
|
|
24153
24153
|
var b = a[0];
|
|
24154
|
-
|
|
24154
|
+
z2[b] = new v(b, 1, false, a[1], null, false, false);
|
|
24155
24155
|
});
|
|
24156
24156
|
["contentEditable", "draggable", "spellCheck", "value"].forEach(function(a) {
|
|
24157
|
-
|
|
24157
|
+
z2[a] = new v(a, 2, false, a.toLowerCase(), null, false, false);
|
|
24158
24158
|
});
|
|
24159
24159
|
["autoReverse", "externalResourcesRequired", "focusable", "preserveAlpha"].forEach(function(a) {
|
|
24160
|
-
|
|
24160
|
+
z2[a] = new v(a, 2, false, a, null, false, false);
|
|
24161
24161
|
});
|
|
24162
24162
|
"allowFullScreen async autoFocus autoPlay controls default defer disabled disablePictureInPicture disableRemotePlayback formNoValidate hidden loop noModule noValidate open playsInline readOnly required reversed scoped seamless itemScope".split(" ").forEach(function(a) {
|
|
24163
|
-
|
|
24163
|
+
z2[a] = new v(a, 3, false, a.toLowerCase(), null, false, false);
|
|
24164
24164
|
});
|
|
24165
24165
|
["checked", "multiple", "muted", "selected"].forEach(function(a) {
|
|
24166
|
-
|
|
24166
|
+
z2[a] = new v(a, 3, true, a, null, false, false);
|
|
24167
24167
|
});
|
|
24168
24168
|
["capture", "download"].forEach(function(a) {
|
|
24169
|
-
|
|
24169
|
+
z2[a] = new v(a, 4, false, a, null, false, false);
|
|
24170
24170
|
});
|
|
24171
24171
|
["cols", "rows", "size", "span"].forEach(function(a) {
|
|
24172
|
-
|
|
24172
|
+
z2[a] = new v(a, 6, false, a, null, false, false);
|
|
24173
24173
|
});
|
|
24174
24174
|
["rowSpan", "start"].forEach(function(a) {
|
|
24175
|
-
|
|
24175
|
+
z2[a] = new v(a, 5, false, a.toLowerCase(), null, false, false);
|
|
24176
24176
|
});
|
|
24177
24177
|
var ra = /[\-:]([a-z])/g;
|
|
24178
24178
|
function sa(a) {
|
|
@@ -24183,25 +24183,25 @@ function requireReactDom_production_min() {
|
|
|
24183
24183
|
ra,
|
|
24184
24184
|
sa
|
|
24185
24185
|
);
|
|
24186
|
-
|
|
24186
|
+
z2[b] = new v(b, 1, false, a, null, false, false);
|
|
24187
24187
|
});
|
|
24188
24188
|
"xlink:actuate xlink:arcrole xlink:role xlink:show xlink:title xlink:type".split(" ").forEach(function(a) {
|
|
24189
24189
|
var b = a.replace(ra, sa);
|
|
24190
|
-
|
|
24190
|
+
z2[b] = new v(b, 1, false, a, "http://www.w3.org/1999/xlink", false, false);
|
|
24191
24191
|
});
|
|
24192
24192
|
["xml:base", "xml:lang", "xml:space"].forEach(function(a) {
|
|
24193
24193
|
var b = a.replace(ra, sa);
|
|
24194
|
-
|
|
24194
|
+
z2[b] = new v(b, 1, false, a, "http://www.w3.org/XML/1998/namespace", false, false);
|
|
24195
24195
|
});
|
|
24196
24196
|
["tabIndex", "crossOrigin"].forEach(function(a) {
|
|
24197
|
-
|
|
24197
|
+
z2[a] = new v(a, 1, false, a.toLowerCase(), null, false, false);
|
|
24198
24198
|
});
|
|
24199
|
-
|
|
24199
|
+
z2.xlinkHref = new v("xlinkHref", 1, false, "xlink:href", "http://www.w3.org/1999/xlink", true, false);
|
|
24200
24200
|
["src", "href", "action", "formAction"].forEach(function(a) {
|
|
24201
|
-
|
|
24201
|
+
z2[a] = new v(a, 1, false, a.toLowerCase(), null, true, true);
|
|
24202
24202
|
});
|
|
24203
24203
|
function ta(a, b, c, d) {
|
|
24204
|
-
var e =
|
|
24204
|
+
var e = z2.hasOwnProperty(b) ? z2[b] : null;
|
|
24205
24205
|
if (null !== e ? 0 !== e.type : d || !(2 < b.length) || "o" !== b[0] && "O" !== b[0] || "n" !== b[1] && "N" !== b[1])
|
|
24206
24206
|
qa(b, c, e, d) && (c = null), d || null === e ? oa(b) && (null === c ? a.removeAttribute(b) : a.setAttribute(b, "" + c)) : e.mustUseProperty ? a[e.propertyName] = null === c ? 3 === e.type ? false : "" : c : (b = e.attributeName, d = e.attributeNamespace, null === c ? a.removeAttribute(b) : (e = e.type, c = 3 === e || 4 === e && true === c ? "" : "" + c, d ? a.setAttributeNS(d, b, c) : a.setAttribute(b, c)));
|
|
24207
24207
|
}
|
|
@@ -33601,11 +33601,11 @@ var swapBE = function swapBE2(c) {
|
|
|
33601
33601
|
return c;
|
|
33602
33602
|
};
|
|
33603
33603
|
var swap32 = isBE() ? swapBE : swapLE;
|
|
33604
|
-
var ch = function ch2(x, y,
|
|
33605
|
-
return
|
|
33604
|
+
var ch = function ch2(x, y, z2) {
|
|
33605
|
+
return z2 ^ x & (y ^ z2);
|
|
33606
33606
|
};
|
|
33607
|
-
var maj = function maj2(x, y,
|
|
33608
|
-
return x & y |
|
|
33607
|
+
var maj = function maj2(x, y, z2) {
|
|
33608
|
+
return x & y | z2 & (x | y);
|
|
33609
33609
|
};
|
|
33610
33610
|
var sigma0 = function sigma02(x) {
|
|
33611
33611
|
return (x >>> 2 | x << 30) ^ (x >>> 13 | x << 19) ^ (x >>> 22 | x << 10);
|
|
@@ -34056,6 +34056,22 @@ var ValApi = /* @__PURE__ */ function() {
|
|
|
34056
34056
|
return parse$1(res);
|
|
34057
34057
|
})["catch"](createError);
|
|
34058
34058
|
}
|
|
34059
|
+
}, {
|
|
34060
|
+
key: "postCommit",
|
|
34061
|
+
value: function postCommit(_ref3) {
|
|
34062
|
+
var patches = _ref3.patches, headers = _ref3.headers;
|
|
34063
|
+
return fetch("".concat(this.host, "/commit"), {
|
|
34064
|
+
method: "POST",
|
|
34065
|
+
body: JSON.stringify({
|
|
34066
|
+
patches
|
|
34067
|
+
}),
|
|
34068
|
+
headers: headers || {
|
|
34069
|
+
"Content-Type": "application/json"
|
|
34070
|
+
}
|
|
34071
|
+
}).then(function(res) {
|
|
34072
|
+
return parse$1(res);
|
|
34073
|
+
})["catch"](createError);
|
|
34074
|
+
}
|
|
34059
34075
|
}]);
|
|
34060
34076
|
return ValApi2;
|
|
34061
34077
|
}();
|
|
@@ -34095,8 +34111,8 @@ function _parse() {
|
|
|
34095
34111
|
return _context2.abrupt("return", err({
|
|
34096
34112
|
statusCode: res.status,
|
|
34097
34113
|
message: json.message || res.statusText,
|
|
34098
|
-
details: json.details || Object.fromEntries(Object.entries(json).filter(function(
|
|
34099
|
-
var
|
|
34114
|
+
details: json.details || Object.fromEntries(Object.entries(json).filter(function(_ref4) {
|
|
34115
|
+
var _ref5 = _slicedToArray$1(_ref4, 1), key = _ref5[0];
|
|
34100
34116
|
return key !== "message";
|
|
34101
34117
|
}))
|
|
34102
34118
|
}));
|
|
@@ -41248,7 +41264,7 @@ function requireLexical_prod() {
|
|
|
41248
41264
|
let m2 = false, n = "";
|
|
41249
41265
|
for (var p = 0; p < b.length; p++) {
|
|
41250
41266
|
var l = b[p], q = l.type, u = l.target, x = ub(u, h);
|
|
41251
|
-
if (!(null === x && u !== g ||
|
|
41267
|
+
if (!(null === x && u !== g || z2(x))) {
|
|
41252
41268
|
if ("characterData" === q) {
|
|
41253
41269
|
if (l = d && B(x))
|
|
41254
41270
|
a: {
|
|
@@ -41379,7 +41395,7 @@ function requireLexical_prod() {
|
|
|
41379
41395
|
if (null === b)
|
|
41380
41396
|
return false;
|
|
41381
41397
|
let c = b.nodeName;
|
|
41382
|
-
return
|
|
41398
|
+
return z2(ub(a)) && ("INPUT" === c || "TEXTAREA" === c || "true" === b.contentEditable && null == b.__lexicalEditor);
|
|
41383
41399
|
}
|
|
41384
41400
|
function Lb(a, b, c) {
|
|
41385
41401
|
let d = a.getRootElement();
|
|
@@ -41414,7 +41430,7 @@ function requireLexical_prod() {
|
|
|
41414
41430
|
return a & b && (null === c || 0 === (c & b)) ? a ^ b : null === c || c & b ? a | b : a;
|
|
41415
41431
|
}
|
|
41416
41432
|
function Xb(a) {
|
|
41417
|
-
return B(a) || Yb(a) ||
|
|
41433
|
+
return B(a) || Yb(a) || z2(a);
|
|
41418
41434
|
}
|
|
41419
41435
|
function Zb(a, b) {
|
|
41420
41436
|
if (null != b)
|
|
@@ -41687,10 +41703,10 @@ function requireLexical_prod() {
|
|
|
41687
41703
|
}
|
|
41688
41704
|
function Bc(a, b) {
|
|
41689
41705
|
a = a.getParent();
|
|
41690
|
-
!K2(a) || D(b) ||
|
|
41706
|
+
!K2(a) || D(b) || z2(b) || r2(99);
|
|
41691
41707
|
}
|
|
41692
41708
|
function Cc(a) {
|
|
41693
|
-
return (
|
|
41709
|
+
return (z2(a) || D(a) && !a.canBeEmpty()) && !a.isInline();
|
|
41694
41710
|
}
|
|
41695
41711
|
function Dc(a, b, c) {
|
|
41696
41712
|
c.style.removeProperty("caret-color");
|
|
@@ -41797,7 +41813,7 @@ function requireLexical_prod() {
|
|
|
41797
41813
|
var f = N2._keyToDOMMap;
|
|
41798
41814
|
e["__lexicalKey_" + N2._key] = a;
|
|
41799
41815
|
f.set(a, e);
|
|
41800
|
-
B(d) ? e.setAttribute("data-lexical-text", "true") :
|
|
41816
|
+
B(d) ? e.setAttribute("data-lexical-text", "true") : z2(d) && e.setAttribute("data-lexical-decorator", "true");
|
|
41801
41817
|
if (D(d)) {
|
|
41802
41818
|
a = d.__indent;
|
|
41803
41819
|
f = d.__size;
|
|
@@ -41816,7 +41832,7 @@ function requireLexical_prod() {
|
|
|
41816
41832
|
d.isInline() || pd(null, d, e);
|
|
41817
41833
|
uc(d) && (L += "\n\n", Kc += "\n\n");
|
|
41818
41834
|
} else
|
|
41819
|
-
f = d.getTextContent(),
|
|
41835
|
+
f = d.getTextContent(), z2(d) ? (g = d.decorate(N2, Lc), null !== g && qd(a, g), e.contentEditable = "false") : B(d) && (d.isDirectionless() || (M += f)), L += f, Kc += f;
|
|
41820
41836
|
null !== b && (null != c ? b.insertBefore(e, c) : (c = b.__lexicalLineBreak, null != c ? b.insertBefore(e, c) : b.appendChild(e)));
|
|
41821
41837
|
rc(ed, Mc, Pc, d, "created");
|
|
41822
41838
|
return e;
|
|
@@ -41831,7 +41847,7 @@ function requireLexical_prod() {
|
|
|
41831
41847
|
}
|
|
41832
41848
|
function rd(a, b) {
|
|
41833
41849
|
a = b.get(a);
|
|
41834
|
-
return Yb(a) ||
|
|
41850
|
+
return Yb(a) || z2(a) && a.isInline();
|
|
41835
41851
|
}
|
|
41836
41852
|
function pd(a, b, c) {
|
|
41837
41853
|
a = null !== a && (0 === a.__size || rd(a.__last, Tc));
|
|
@@ -41940,7 +41956,7 @@ function requireLexical_prod() {
|
|
|
41940
41956
|
}
|
|
41941
41957
|
uc(d) && (L += "\n\n", Kc += "\n\n");
|
|
41942
41958
|
} else
|
|
41943
|
-
c = d.getTextContent(),
|
|
41959
|
+
c = d.getTextContent(), z2(d) ? (e = d.decorate(N2, Lc), null !== e && qd(a, e)) : B(d) && !d.isDirectionless() && (M += c), L += c, Kc += c;
|
|
41944
41960
|
!Oc && K2(d) && d.__cachedText !== Kc && (d = d.getWritable(), d.__cachedText = Kc);
|
|
41945
41961
|
return f;
|
|
41946
41962
|
}
|
|
@@ -42030,7 +42046,7 @@ function requireLexical_prod() {
|
|
|
42030
42046
|
let c = a.target;
|
|
42031
42047
|
a = a.pointerType;
|
|
42032
42048
|
c instanceof Node && "touch" !== a && w(b, () => {
|
|
42033
|
-
|
|
42049
|
+
z2(ub(c)) || (Jd = true);
|
|
42034
42050
|
});
|
|
42035
42051
|
}
|
|
42036
42052
|
function Rd(a) {
|
|
@@ -43526,7 +43542,7 @@ function requireLexical_prod() {
|
|
|
43526
43542
|
p === c && (l = f ? l.slice(0, h) : l.slice(0, g));
|
|
43527
43543
|
k += l;
|
|
43528
43544
|
} else
|
|
43529
|
-
!
|
|
43545
|
+
!z2(p) && !Yb(p) || p === c && this.isCollapsed() || (k += p.getTextContent());
|
|
43530
43546
|
}
|
|
43531
43547
|
return k;
|
|
43532
43548
|
}
|
|
@@ -43754,8 +43770,8 @@ function requireLexical_prod() {
|
|
|
43754
43770
|
var k = false, m2 = null;
|
|
43755
43771
|
for (let q = 0; q < a.length; q++) {
|
|
43756
43772
|
var n = a[q];
|
|
43757
|
-
if (yc(d) ||
|
|
43758
|
-
k && !D(n) && !
|
|
43773
|
+
if (yc(d) || z2(d) || !D(n) || n.isInline())
|
|
43774
|
+
k && !D(n) && !z2(n) && yc(d.getParent()) && r2(28);
|
|
43759
43775
|
else {
|
|
43760
43776
|
if (n.is(g)) {
|
|
43761
43777
|
if (D(d) && d.isEmpty() && d.canReplaceWith(n)) {
|
|
@@ -43793,7 +43809,7 @@ function requireLexical_prod() {
|
|
|
43793
43809
|
}
|
|
43794
43810
|
k = false;
|
|
43795
43811
|
if (D(d) && !d.isInline())
|
|
43796
|
-
if (m2 = n,
|
|
43812
|
+
if (m2 = n, z2(n) && !n.isInline())
|
|
43797
43813
|
d = 1 === a.length && d.canBeEmpty() && d.isEmpty() ? d.insertBefore(n, false) : d.insertAfter(n, false);
|
|
43798
43814
|
else if (D(n)) {
|
|
43799
43815
|
if (n.canBeEmpty() || !n.isEmpty())
|
|
@@ -43801,13 +43817,13 @@ function requireLexical_prod() {
|
|
|
43801
43817
|
} else
|
|
43802
43818
|
p = d.getFirstChild(), null !== p ? p.insertBefore(n) : d.append(n), d = n;
|
|
43803
43819
|
else
|
|
43804
|
-
!D(n) || D(n) && n.isInline() ||
|
|
43820
|
+
!D(n) || D(n) && n.isInline() || z2(d) && !d.isInline() ? (m2 = n, C(this) && z2(n) && (D(d) || B(d)) && !n.isInline() ? (B(d) ? (p = d.getParentOrThrow(), [d] = d.splitText(c), d = d.getIndexWithinParent() + 1) : (p = d, d = c), [, d] = Ec(p, d), d = d.insertBefore(n)) : d = d.insertAfter(n, false)) : (n = d.getParentOrThrow(), Yb(d) && d.remove(), d = n, q--);
|
|
43805
43821
|
}
|
|
43806
43822
|
b && (B(f) ? f.select() : (a = d.getPreviousSibling(), B(a) ? a.select() : (a = d.getIndexWithinParent(), d.getParentOrThrow().select(a, a))));
|
|
43807
43823
|
if (D(d)) {
|
|
43808
43824
|
if (a = B(m2) ? m2 : D(m2) && m2.isInline() ? m2.getLastDescendant() : d.getLastDescendant(), b || (null === a ? d.select() : B(a) ? "" === a.getTextContent() ? a.selectPrevious() : a.select() : a.selectNext()), 0 !== e.length)
|
|
43809
43825
|
for (b = d, a = e.length - 1; 0 <= a; a--)
|
|
43810
|
-
c = e[a], h = c.getParentOrThrow(), !D(d) || Ye(c) ||
|
|
43826
|
+
c = e[a], h = c.getParentOrThrow(), !D(d) || Ye(c) || z2(c) && (!c.isInline() || c.isIsolated()) ? D(d) || Ye(c) ? D(c) && !c.canInsertAfter(d) ? (f = h.constructor.clone(h), D(f) || r2(29), f.append(c), d.insertAfter(f)) : d.insertAfter(c) : (d.insertBefore(c), d = c) : (b === d ? d.append(c) : d.insertBefore(c), d = c), h.isEmpty() && !h.canBeEmpty() && h.remove();
|
|
43811
43827
|
} else
|
|
43812
43828
|
b || (B(d) ? d.select() : (b = d.getParentOrThrow(), a = d.getIndexWithinParent() + 1, b.select(a, a)));
|
|
43813
43829
|
return true;
|
|
@@ -43880,7 +43896,7 @@ function requireLexical_prod() {
|
|
|
43880
43896
|
}
|
|
43881
43897
|
modify(a, b, c) {
|
|
43882
43898
|
var d = this.focus, e = this.anchor, f = "move" === a, g = tc(d, b);
|
|
43883
|
-
if (
|
|
43899
|
+
if (z2(g) && !g.isIsolated())
|
|
43884
43900
|
f && g.isKeyboardSelectable() ? (b = Ze(), b.add(g.__key), yb(b)) : (a = b ? g.getPreviousSibling() : g.getNextSibling(), B(a) ? (g = a.__key, b = b ? a.getTextContent().length : 0, d.set(g, b, "text"), f && e.set(g, b, "text")) : (c = g.getParentOrThrow(), D(a) ? (c = a.__key, g = b ? a.getChildrenSize() : 0) : (g = g.getIndexWithinParent(), c = c.__key, b || g++), d.set(c, g, "element"), f && e.set(c, g, "element")));
|
|
43885
43901
|
else if (e = F(), d = vb(e._window)) {
|
|
43886
43902
|
var h = e._blockCursorElement, k = e._rootElement;
|
|
@@ -43909,7 +43925,7 @@ function requireLexical_prod() {
|
|
|
43909
43925
|
return;
|
|
43910
43926
|
}
|
|
43911
43927
|
f = tc(d, a);
|
|
43912
|
-
if (
|
|
43928
|
+
if (z2(f) && !f.isIsolated()) {
|
|
43913
43929
|
f.isKeyboardSelectable() && D(e) && 0 === e.getChildrenSize() ? (e.remove(), a = Ze(), a.add(f.__key), yb(a)) : (f.remove(), F().dispatchCommand(aa, void 0));
|
|
43914
43930
|
return;
|
|
43915
43931
|
}
|
|
@@ -44011,7 +44027,7 @@ function requireLexical_prod() {
|
|
|
44011
44027
|
b && (c = h ? a.getLastDescendant() : a.getFirstDescendant(), null === c ? (f = a, e = 0) : (a = c, f = D(a) ? a : a.getParentOrThrow()));
|
|
44012
44028
|
B(a) ? (d = a, f = null, e = h ? a.getTextContentSize() : 0) : a !== f && h && !g && e++;
|
|
44013
44029
|
} else
|
|
44014
|
-
e = f.getIndexWithinParent(), e = 0 === b &&
|
|
44030
|
+
e = f.getIndexWithinParent(), e = 0 === b && z2(f) && jc(a) === f ? e : e + 1, f = f.getParentOrThrow();
|
|
44015
44031
|
if (D(f))
|
|
44016
44032
|
return new ze(f.__key, e, "element");
|
|
44017
44033
|
}
|
|
@@ -44041,7 +44057,7 @@ function requireLexical_prod() {
|
|
|
44041
44057
|
if (null === b)
|
|
44042
44058
|
return null;
|
|
44043
44059
|
d = bf(c, d, C(f) ? f.focus : null, e);
|
|
44044
|
-
if (null === d || "element" === b.type && "element" === d.type && (a = jc(a), c = jc(c),
|
|
44060
|
+
if (null === d || "element" === b.type && "element" === d.type && (a = jc(a), c = jc(c), z2(a) && z2(c)))
|
|
44045
44061
|
return null;
|
|
44046
44062
|
Xe(b, d, f);
|
|
44047
44063
|
return [b, d];
|
|
@@ -44596,7 +44612,7 @@ function requireLexical_prod() {
|
|
|
44596
44612
|
return true;
|
|
44597
44613
|
}
|
|
44598
44614
|
}
|
|
44599
|
-
function
|
|
44615
|
+
function z2(a) {
|
|
44600
44616
|
return a instanceof wf;
|
|
44601
44617
|
}
|
|
44602
44618
|
class xf extends be {
|
|
@@ -44944,7 +44960,7 @@ function requireLexical_prod() {
|
|
|
44944
44960
|
append(...a) {
|
|
44945
44961
|
for (let b = 0; b < a.length; b++) {
|
|
44946
44962
|
let c = a[b];
|
|
44947
|
-
D(c) ||
|
|
44963
|
+
D(c) || z2(c) || r2(56);
|
|
44948
44964
|
}
|
|
44949
44965
|
return super.append(...a);
|
|
44950
44966
|
}
|
|
@@ -45414,10 +45430,10 @@ function requireLexical_prod() {
|
|
|
45414
45430
|
return c.insertNodes(a, b);
|
|
45415
45431
|
};
|
|
45416
45432
|
Lexical_prod.$isBlockElementNode = Ye;
|
|
45417
|
-
Lexical_prod.$isDecoratorNode =
|
|
45433
|
+
Lexical_prod.$isDecoratorNode = z2;
|
|
45418
45434
|
Lexical_prod.$isElementNode = D;
|
|
45419
45435
|
Lexical_prod.$isInlineElementOrDecoratorNode = function(a) {
|
|
45420
|
-
return D(a) && a.isInline() ||
|
|
45436
|
+
return D(a) && a.isInline() || z2(a) && a.isInline();
|
|
45421
45437
|
};
|
|
45422
45438
|
Lexical_prod.$isLeafNode = Xb;
|
|
45423
45439
|
Lexical_prod.$isLineBreakNode = Yb;
|
|
@@ -47304,9 +47320,9 @@ function requireLexical_dev() {
|
|
|
47304
47320
|
throw Error(`reconcileNode: prevNode or nextNode does not exist in nodeMap`);
|
|
47305
47321
|
}
|
|
47306
47322
|
}
|
|
47307
|
-
const
|
|
47323
|
+
const isDirty2 = treatAllNodesAsDirty || activeDirtyLeaves.has(key) || activeDirtyElements.has(key);
|
|
47308
47324
|
const dom = getElementByKeyOrThrow(activeEditor$1, key);
|
|
47309
|
-
if (prevNode === nextNode && !
|
|
47325
|
+
if (prevNode === nextNode && !isDirty2) {
|
|
47310
47326
|
if ($isElementNode(prevNode)) {
|
|
47311
47327
|
const previousSubTreeTextContent = dom.__lexicalTextContent;
|
|
47312
47328
|
if (previousSubTreeTextContent !== void 0) {
|
|
@@ -47327,7 +47343,7 @@ function requireLexical_dev() {
|
|
|
47327
47343
|
}
|
|
47328
47344
|
return dom;
|
|
47329
47345
|
}
|
|
47330
|
-
if (prevNode !== nextNode &&
|
|
47346
|
+
if (prevNode !== nextNode && isDirty2) {
|
|
47331
47347
|
setMutatedNode(mutatedNodes, activeEditorNodes, activeMutationListeners, nextNode, "updated");
|
|
47332
47348
|
}
|
|
47333
47349
|
if (nextNode.updateDOM(prevNode, dom, activeEditorConfig)) {
|
|
@@ -47350,7 +47366,7 @@ function requireLexical_dev() {
|
|
|
47350
47366
|
if (nextFormat !== prevNode.__format) {
|
|
47351
47367
|
setElementFormat(dom, nextFormat);
|
|
47352
47368
|
}
|
|
47353
|
-
if (
|
|
47369
|
+
if (isDirty2) {
|
|
47354
47370
|
reconcileChildrenWithDirection(prevNode, nextNode, dom);
|
|
47355
47371
|
if (!$isRootNode(nextNode) && !nextNode.isInline()) {
|
|
47356
47372
|
reconcileElementTerminatingLineBreak(prevNode, nextNode, dom);
|
|
@@ -54613,7 +54629,7 @@ function requireLexicalSelection_prod() {
|
|
|
54613
54629
|
}
|
|
54614
54630
|
return b;
|
|
54615
54631
|
}
|
|
54616
|
-
function
|
|
54632
|
+
function z2(a) {
|
|
54617
54633
|
let b = u.get(a);
|
|
54618
54634
|
void 0 === b && (b = y(a), u.set(a, b));
|
|
54619
54635
|
return b;
|
|
@@ -54625,7 +54641,7 @@ function requireLexicalSelection_prod() {
|
|
|
54625
54641
|
return b;
|
|
54626
54642
|
}
|
|
54627
54643
|
function B(a, b) {
|
|
54628
|
-
var c =
|
|
54644
|
+
var c = z2("getStyle" in a ? a.getStyle() : a.style);
|
|
54629
54645
|
b = Object.entries(b).reduce((e, [d, f]) => {
|
|
54630
54646
|
null === f ? delete e[d] : e[d] = f;
|
|
54631
54647
|
return e;
|
|
@@ -54770,12 +54786,12 @@ function requireLexicalSelection_prod() {
|
|
|
54770
54786
|
var f = a.anchor, h = a.focus, g = a.isBackward();
|
|
54771
54787
|
let l = g ? h.offset : f.offset;
|
|
54772
54788
|
f = g ? h.getNode() : f.getNode();
|
|
54773
|
-
if ("" !== a.style && (a =
|
|
54789
|
+
if ("" !== a.style && (a = z2(a.style), null !== a && b in a))
|
|
54774
54790
|
return a[b];
|
|
54775
54791
|
for (a = 0; a < d.length; a++) {
|
|
54776
54792
|
var m2 = d[a];
|
|
54777
54793
|
if ((0 === a || 0 !== l || !m2.is(f)) && k.$isTextNode(m2)) {
|
|
54778
|
-
if (h = b, g = c, m2 = m2.getStyle(), m2 =
|
|
54794
|
+
if (h = b, g = c, m2 = m2.getStyle(), m2 = z2(m2), h = null !== m2 ? m2[h] || g : g, null === e)
|
|
54779
54795
|
e = h;
|
|
54780
54796
|
else if (e !== h) {
|
|
54781
54797
|
e = "";
|
|
@@ -54914,7 +54930,7 @@ function requireLexicalSelection_prod() {
|
|
|
54914
54930
|
}
|
|
54915
54931
|
return b;
|
|
54916
54932
|
};
|
|
54917
|
-
LexicalSelection_prod.getStyleObjectFromCSS =
|
|
54933
|
+
LexicalSelection_prod.getStyleObjectFromCSS = z2;
|
|
54918
54934
|
LexicalSelection_prod.trimTextContentFromAnchor = function(a, b, c) {
|
|
54919
54935
|
let e = b.getNode();
|
|
54920
54936
|
if (k.$isElementNode(e)) {
|
|
@@ -56248,7 +56264,7 @@ function requireLexicalList_prod() {
|
|
|
56248
56264
|
function w(a) {
|
|
56249
56265
|
return y().append(a);
|
|
56250
56266
|
}
|
|
56251
|
-
function
|
|
56267
|
+
function z2(a, b) {
|
|
56252
56268
|
return p(a) && (0 === b.length || 1 === b.length && a.is(b[0]) && 0 === a.getChildrenSize());
|
|
56253
56269
|
}
|
|
56254
56270
|
function B(a, b) {
|
|
@@ -56747,7 +56763,7 @@ function requireLexicalList_prod() {
|
|
|
56747
56763
|
var d = c.getNodes();
|
|
56748
56764
|
c = c.anchor.getNode();
|
|
56749
56765
|
var e = c.getParent();
|
|
56750
|
-
if (
|
|
56766
|
+
if (z2(c, d))
|
|
56751
56767
|
d = D(b), h.$isRootOrShadowRoot(e) ? (c.replace(d), e = y(), h.$isElementNode(c) && (e.setFormat(c.getFormatType()), e.setIndent(c.getIndent())), d.append(e)) : p(c) && (c = c.getParentOrThrow(), B(d, c.getChildren()), c.replace(d));
|
|
56752
56768
|
else
|
|
56753
56769
|
for (c = /* @__PURE__ */ new Set(), e = 0; e < d.length; e++) {
|
|
@@ -56788,7 +56804,7 @@ function requireLexicalList_prod() {
|
|
|
56788
56804
|
let b = h.$getSelection();
|
|
56789
56805
|
if (h.$isRangeSelection(b)) {
|
|
56790
56806
|
var c = /* @__PURE__ */ new Set(), d = b.getNodes(), e = b.anchor.getNode();
|
|
56791
|
-
if (
|
|
56807
|
+
if (z2(e, d))
|
|
56792
56808
|
c.add(r2(e));
|
|
56793
56809
|
else
|
|
56794
56810
|
for (e = 0; e < d.length; e++) {
|
|
@@ -58270,7 +58286,7 @@ function requireLexicalHistory_prod() {
|
|
|
58270
58286
|
b = a.length - b.length;
|
|
58271
58287
|
return 1 === b && d === f - 1 ? 2 : -1 === b && d === f + 1 ? 3 : -1 === b && d === f ? 4 : 0;
|
|
58272
58288
|
}
|
|
58273
|
-
function
|
|
58289
|
+
function z2(b, a) {
|
|
58274
58290
|
let l = Date.now(), h = 0;
|
|
58275
58291
|
return (n, f, d, e, m2, p) => {
|
|
58276
58292
|
let r2 = Date.now();
|
|
@@ -58311,7 +58327,7 @@ function requireLexicalHistory_prod() {
|
|
|
58311
58327
|
return { current: null, redoStack: [], undoStack: [] };
|
|
58312
58328
|
};
|
|
58313
58329
|
LexicalHistory_prod.registerHistory = function(b, a, l) {
|
|
58314
|
-
let h =
|
|
58330
|
+
let h = z2(b, l);
|
|
58315
58331
|
l = ({ editorState: d, prevEditorState: e, dirtyLeaves: m2, dirtyElements: p, tags: r2 }) => {
|
|
58316
58332
|
const q = a.current, v = a.redoStack, k = a.undoStack, g = null === q ? null : q.editorState;
|
|
58317
58333
|
if (null === q || d !== g) {
|
|
@@ -59521,7 +59537,7 @@ function requireLexicalClipboard_prod() {
|
|
|
59521
59537
|
return LexicalClipboard_prod;
|
|
59522
59538
|
hasRequiredLexicalClipboard_prod = 1;
|
|
59523
59539
|
var d = requireLexicalHtml(), p = requireLexicalSelection(), r2 = requireLexicalUtils(), u = requireLexical();
|
|
59524
|
-
function
|
|
59540
|
+
function z2(a) {
|
|
59525
59541
|
let b = new URLSearchParams();
|
|
59526
59542
|
b.append("code", a);
|
|
59527
59543
|
for (let c = 1; c < arguments.length; c++)
|
|
@@ -59555,16 +59571,16 @@ function requireLexicalClipboard_prod() {
|
|
|
59555
59571
|
} else
|
|
59556
59572
|
c.push(h), e = null;
|
|
59557
59573
|
}
|
|
59558
|
-
u.$isRangeSelection(b) ? b.insertNodes(c) : u.DEPRECATED_$isGridSelection(b) && (a = b.anchor.getNode(), u.DEPRECATED_$isGridCellNode(a) ||
|
|
59574
|
+
u.$isRangeSelection(b) ? b.insertNodes(c) : u.DEPRECATED_$isGridSelection(b) && (a = b.anchor.getNode(), u.DEPRECATED_$isGridCellNode(a) || z2(41), a.append(...c));
|
|
59559
59575
|
}
|
|
59560
59576
|
function F(a, b, c, e) {
|
|
59561
|
-
1 === a.length && u.DEPRECATED_$isGridNode(a[0]) ||
|
|
59577
|
+
1 === a.length && u.DEPRECATED_$isGridNode(a[0]) || z2(42);
|
|
59562
59578
|
var f = a[0];
|
|
59563
59579
|
a = f.getChildren();
|
|
59564
59580
|
c = f.getFirstChildOrThrow().getChildrenSize();
|
|
59565
59581
|
var h = f.getChildrenSize(), g = r2.$findMatchingParent(b.anchor.getNode(), (l) => u.DEPRECATED_$isGridCellNode(l));
|
|
59566
59582
|
b = (f = g && r2.$findMatchingParent(g, (l) => u.DEPRECATED_$isGridRowNode(l))) && r2.$findMatchingParent(f, (l) => u.DEPRECATED_$isGridNode(l));
|
|
59567
|
-
u.DEPRECATED_$isGridCellNode(g) && u.DEPRECATED_$isGridRowNode(f) && u.DEPRECATED_$isGridNode(b) ||
|
|
59583
|
+
u.DEPRECATED_$isGridCellNode(g) && u.DEPRECATED_$isGridRowNode(f) && u.DEPRECATED_$isGridNode(b) || z2(43);
|
|
59568
59584
|
var k = f.getIndexWithinParent(), m2 = Math.min(b.getChildrenSize() - 1, k + h - 1);
|
|
59569
59585
|
h = g.getIndexWithinParent();
|
|
59570
59586
|
g = Math.min(f.getChildrenSize() - 1, h + c - 1);
|
|
@@ -59577,17 +59593,17 @@ function requireLexicalClipboard_prod() {
|
|
|
59577
59593
|
let n, q;
|
|
59578
59594
|
for (let l = f; l <= k; l++) {
|
|
59579
59595
|
var t = m2[l];
|
|
59580
|
-
u.DEPRECATED_$isGridRowNode(t) ||
|
|
59596
|
+
u.DEPRECATED_$isGridRowNode(t) || z2(24);
|
|
59581
59597
|
var y = a[g];
|
|
59582
|
-
u.DEPRECATED_$isGridRowNode(y) ||
|
|
59598
|
+
u.DEPRECATED_$isGridRowNode(y) || z2(24);
|
|
59583
59599
|
t = t.getChildren();
|
|
59584
59600
|
y = y.getChildren();
|
|
59585
59601
|
let G = 0;
|
|
59586
59602
|
for (let v = c; v <= h; v++) {
|
|
59587
59603
|
let w = t[v];
|
|
59588
|
-
u.DEPRECATED_$isGridCellNode(w) ||
|
|
59604
|
+
u.DEPRECATED_$isGridCellNode(w) || z2(25);
|
|
59589
59605
|
let H = y[G];
|
|
59590
|
-
u.DEPRECATED_$isGridCellNode(H) ||
|
|
59606
|
+
u.DEPRECATED_$isGridCellNode(H) || z2(25);
|
|
59591
59607
|
l === f && v === c ? n = w.getKey() : l === k && v === h && (q = w.getKey());
|
|
59592
59608
|
let N2 = w.getChildren();
|
|
59593
59609
|
H.getChildren().forEach((x) => {
|
|
@@ -59612,9 +59628,9 @@ function requireLexicalClipboard_prod() {
|
|
|
59612
59628
|
var n = g;
|
|
59613
59629
|
k = n.exportJSON();
|
|
59614
59630
|
var q = n.constructor;
|
|
59615
|
-
k.type !== q.getType() &&
|
|
59631
|
+
k.type !== q.getType() && z2(58, q.name);
|
|
59616
59632
|
let t = k.children;
|
|
59617
|
-
u.$isElementNode(n) && (Array.isArray(t) ||
|
|
59633
|
+
u.$isElementNode(n) && (Array.isArray(t) || z2(59, q.name));
|
|
59618
59634
|
u.$isTextNode(g) && (g = g.__text, 0 < g.length ? k.text = g : f = false);
|
|
59619
59635
|
for (g = 0; g < m2.length; g++)
|
|
59620
59636
|
n = m2[g], q = J(a, b, n, k.children), !f && u.$isElementNode(c) && q && c.extractWithChild(n, b, "clone") && (f = true);
|
|
@@ -60171,7 +60187,7 @@ function requireLexicalRichText_prod() {
|
|
|
60171
60187
|
return { element: b };
|
|
60172
60188
|
}
|
|
60173
60189
|
static importJSON(b) {
|
|
60174
|
-
let a =
|
|
60190
|
+
let a = z2();
|
|
60175
60191
|
a.setFormat(b.format);
|
|
60176
60192
|
a.setIndent(b.indent);
|
|
60177
60193
|
a.setDirection(b.direction);
|
|
@@ -60194,7 +60210,7 @@ function requireLexicalRichText_prod() {
|
|
|
60194
60210
|
return true;
|
|
60195
60211
|
}
|
|
60196
60212
|
}
|
|
60197
|
-
function
|
|
60213
|
+
function z2() {
|
|
60198
60214
|
return k.$applyNodeReplacement(new x());
|
|
60199
60215
|
}
|
|
60200
60216
|
class B extends k.ElementNode {
|
|
@@ -60278,7 +60294,7 @@ function requireLexicalRichText_prod() {
|
|
|
60278
60294
|
return { node: d };
|
|
60279
60295
|
}
|
|
60280
60296
|
function y(b) {
|
|
60281
|
-
let a =
|
|
60297
|
+
let a = z2();
|
|
60282
60298
|
null !== b.style && a.setFormat(b.style.textAlign);
|
|
60283
60299
|
return { node: a };
|
|
60284
60300
|
}
|
|
@@ -60326,7 +60342,7 @@ function requireLexicalRichText_prod() {
|
|
|
60326
60342
|
return k.$isDecoratorNode(b);
|
|
60327
60343
|
}
|
|
60328
60344
|
LexicalRichText_prod.$createHeadingNode = E;
|
|
60329
|
-
LexicalRichText_prod.$createQuoteNode =
|
|
60345
|
+
LexicalRichText_prod.$createQuoteNode = z2;
|
|
60330
60346
|
LexicalRichText_prod.$isHeadingNode = function(b) {
|
|
60331
60347
|
return b instanceof B;
|
|
60332
60348
|
};
|
|
@@ -61327,7 +61343,7 @@ function requireLexicalRichTextPlugin_prod() {
|
|
|
61327
61343
|
return l.useMemo(() => {
|
|
61328
61344
|
let f = [], q = Object.keys(c);
|
|
61329
61345
|
for (let h = 0; h < q.length; h++) {
|
|
61330
|
-
let k = q[h], A = l.createElement(d, { onError: (
|
|
61346
|
+
let k = q[h], A = l.createElement(d, { onError: (z2) => a._onError(z2) }, l.createElement(l.Suspense, { fallback: null }, c[k])), r2 = a.getElementByKey(k);
|
|
61331
61347
|
null !== r2 && f.push(p.createPortal(A, r2, k));
|
|
61332
61348
|
}
|
|
61333
61349
|
return f;
|
|
@@ -61687,7 +61703,7 @@ function requireLexicalLink_prod() {
|
|
|
61687
61703
|
return n.$applyNodeReplacement(new w(a, b));
|
|
61688
61704
|
}
|
|
61689
61705
|
let y = n.createCommand("TOGGLE_LINK_COMMAND");
|
|
61690
|
-
function
|
|
61706
|
+
function z2(a, b) {
|
|
61691
61707
|
for (; null !== a && null !== (a = a.getParent()) && !b(a); )
|
|
61692
61708
|
;
|
|
61693
61709
|
return a;
|
|
@@ -61718,7 +61734,7 @@ function requireLexicalLink_prod() {
|
|
|
61718
61734
|
else {
|
|
61719
61735
|
if (1 === b.length) {
|
|
61720
61736
|
var e = b[0];
|
|
61721
|
-
e = v(e) ? e :
|
|
61737
|
+
e = v(e) ? e : z2(e, v);
|
|
61722
61738
|
if (null !== e) {
|
|
61723
61739
|
e.setURL(a);
|
|
61724
61740
|
void 0 !== d && e.setTarget(d);
|
|
@@ -62983,7 +62999,7 @@ function requireReactIs_production_min() {
|
|
|
62983
62999
|
return reactIs_production_min;
|
|
62984
63000
|
hasRequiredReactIs_production_min = 1;
|
|
62985
63001
|
var b = "function" === typeof Symbol && Symbol.for, c = b ? Symbol.for("react.element") : 60103, d = b ? Symbol.for("react.portal") : 60106, e = b ? Symbol.for("react.fragment") : 60107, f = b ? Symbol.for("react.strict_mode") : 60108, g = b ? Symbol.for("react.profiler") : 60114, h = b ? Symbol.for("react.provider") : 60109, k = b ? Symbol.for("react.context") : 60110, l = b ? Symbol.for("react.async_mode") : 60111, m2 = b ? Symbol.for("react.concurrent_mode") : 60111, n = b ? Symbol.for("react.forward_ref") : 60112, p = b ? Symbol.for("react.suspense") : 60113, q = b ? Symbol.for("react.suspense_list") : 60120, r2 = b ? Symbol.for("react.memo") : 60115, t = b ? Symbol.for("react.lazy") : 60116, v = b ? Symbol.for("react.block") : 60121, w = b ? Symbol.for("react.fundamental") : 60117, x = b ? Symbol.for("react.responder") : 60118, y = b ? Symbol.for("react.scope") : 60119;
|
|
62986
|
-
function
|
|
63002
|
+
function z2(a) {
|
|
62987
63003
|
if ("object" === typeof a && null !== a) {
|
|
62988
63004
|
var u = a.$$typeof;
|
|
62989
63005
|
switch (u) {
|
|
@@ -63014,7 +63030,7 @@ function requireReactIs_production_min() {
|
|
|
63014
63030
|
}
|
|
63015
63031
|
}
|
|
63016
63032
|
function A(a) {
|
|
63017
|
-
return
|
|
63033
|
+
return z2(a) === m2;
|
|
63018
63034
|
}
|
|
63019
63035
|
reactIs_production_min.AsyncMode = l;
|
|
63020
63036
|
reactIs_production_min.ConcurrentMode = m2;
|
|
@@ -63030,46 +63046,46 @@ function requireReactIs_production_min() {
|
|
|
63030
63046
|
reactIs_production_min.StrictMode = f;
|
|
63031
63047
|
reactIs_production_min.Suspense = p;
|
|
63032
63048
|
reactIs_production_min.isAsyncMode = function(a) {
|
|
63033
|
-
return A(a) ||
|
|
63049
|
+
return A(a) || z2(a) === l;
|
|
63034
63050
|
};
|
|
63035
63051
|
reactIs_production_min.isConcurrentMode = A;
|
|
63036
63052
|
reactIs_production_min.isContextConsumer = function(a) {
|
|
63037
|
-
return
|
|
63053
|
+
return z2(a) === k;
|
|
63038
63054
|
};
|
|
63039
63055
|
reactIs_production_min.isContextProvider = function(a) {
|
|
63040
|
-
return
|
|
63056
|
+
return z2(a) === h;
|
|
63041
63057
|
};
|
|
63042
63058
|
reactIs_production_min.isElement = function(a) {
|
|
63043
63059
|
return "object" === typeof a && null !== a && a.$$typeof === c;
|
|
63044
63060
|
};
|
|
63045
63061
|
reactIs_production_min.isForwardRef = function(a) {
|
|
63046
|
-
return
|
|
63062
|
+
return z2(a) === n;
|
|
63047
63063
|
};
|
|
63048
63064
|
reactIs_production_min.isFragment = function(a) {
|
|
63049
|
-
return
|
|
63065
|
+
return z2(a) === e;
|
|
63050
63066
|
};
|
|
63051
63067
|
reactIs_production_min.isLazy = function(a) {
|
|
63052
|
-
return
|
|
63068
|
+
return z2(a) === t;
|
|
63053
63069
|
};
|
|
63054
63070
|
reactIs_production_min.isMemo = function(a) {
|
|
63055
|
-
return
|
|
63071
|
+
return z2(a) === r2;
|
|
63056
63072
|
};
|
|
63057
63073
|
reactIs_production_min.isPortal = function(a) {
|
|
63058
|
-
return
|
|
63074
|
+
return z2(a) === d;
|
|
63059
63075
|
};
|
|
63060
63076
|
reactIs_production_min.isProfiler = function(a) {
|
|
63061
|
-
return
|
|
63077
|
+
return z2(a) === g;
|
|
63062
63078
|
};
|
|
63063
63079
|
reactIs_production_min.isStrictMode = function(a) {
|
|
63064
|
-
return
|
|
63080
|
+
return z2(a) === f;
|
|
63065
63081
|
};
|
|
63066
63082
|
reactIs_production_min.isSuspense = function(a) {
|
|
63067
|
-
return
|
|
63083
|
+
return z2(a) === p;
|
|
63068
63084
|
};
|
|
63069
63085
|
reactIs_production_min.isValidElementType = function(a) {
|
|
63070
63086
|
return "string" === typeof a || "function" === typeof a || a === e || a === m2 || a === g || a === f || a === p || a === q || "object" === typeof a && null !== a && (a.$$typeof === t || a.$$typeof === r2 || a.$$typeof === h || a.$$typeof === k || a.$$typeof === n || a.$$typeof === w || a.$$typeof === x || a.$$typeof === y || a.$$typeof === v);
|
|
63071
63087
|
};
|
|
63072
|
-
reactIs_production_min.typeOf =
|
|
63088
|
+
reactIs_production_min.typeOf = z2;
|
|
63073
63089
|
return reactIs_production_min;
|
|
63074
63090
|
}
|
|
63075
63091
|
var hasRequiredReactIs;
|
|
@@ -64371,7 +64387,11 @@ const X = createLucideIcon("X", [
|
|
|
64371
64387
|
]);
|
|
64372
64388
|
const className = "p-1 border rounded-full shadow border-accent";
|
|
64373
64389
|
const PREV_URL_KEY = "valbuild:urlBeforeNavigation";
|
|
64374
|
-
function ValMenu({
|
|
64390
|
+
function ValMenu({
|
|
64391
|
+
api,
|
|
64392
|
+
patches,
|
|
64393
|
+
onCommit
|
|
64394
|
+
}) {
|
|
64375
64395
|
const { theme: theme2, setTheme, editMode, setEditMode, session } = useValOverlayContext();
|
|
64376
64396
|
if (session.status === "success" && session.data.mode === "unauthorized") {
|
|
64377
64397
|
return /* @__PURE__ */ jsxRuntimeExports.jsxs(SingleItemMenu, { href: api.getLoginUrl(window.location.href), children: [
|
|
@@ -64387,20 +64407,12 @@ function ValMenu({ api }) {
|
|
|
64387
64407
|
}
|
|
64388
64408
|
const [patchCount, setPatchCount] = reactExports.useState();
|
|
64389
64409
|
reactExports.useEffect(() => {
|
|
64390
|
-
|
|
64391
|
-
|
|
64392
|
-
|
|
64393
|
-
let patchCount2 = 0;
|
|
64394
|
-
for (const moduleId in patchRes.value) {
|
|
64395
|
-
patchCount2 += patchRes.value[moduleId].length;
|
|
64396
|
-
}
|
|
64397
|
-
setPatchCount(patchCount2);
|
|
64398
|
-
} else {
|
|
64399
|
-
console.error("Could not load patches", patchRes.error);
|
|
64400
|
-
}
|
|
64401
|
-
});
|
|
64410
|
+
let patchCount2 = 0;
|
|
64411
|
+
for (const moduleId in patches) {
|
|
64412
|
+
patchCount2 += patches[moduleId].length;
|
|
64402
64413
|
}
|
|
64403
|
-
|
|
64414
|
+
setPatchCount(patchCount2);
|
|
64415
|
+
}, [patches]);
|
|
64404
64416
|
return /* @__PURE__ */ jsxRuntimeExports.jsxs(MenuContainer, { children: [
|
|
64405
64417
|
/* @__PURE__ */ jsxRuntimeExports.jsx(
|
|
64406
64418
|
MenuButton,
|
|
@@ -64440,10 +64452,23 @@ function ValMenu({ api }) {
|
|
|
64440
64452
|
children: /* @__PURE__ */ jsxRuntimeExports.jsx("div", { className: "h-[24px] w-[24px] flex justify-center items-center", children: editMode === "full" ? /* @__PURE__ */ jsxRuntimeExports.jsx(Minimize, { size: 15 }) : /* @__PURE__ */ jsxRuntimeExports.jsx(Maximize, { size: 15 }) })
|
|
64441
64453
|
}
|
|
64442
64454
|
),
|
|
64443
|
-
patchCount && /* @__PURE__ */ jsxRuntimeExports.jsx(
|
|
64455
|
+
patchCount !== void 0 && /* @__PURE__ */ jsxRuntimeExports.jsx(
|
|
64444
64456
|
MenuButton,
|
|
64445
64457
|
{
|
|
64446
64458
|
onClick: () => {
|
|
64459
|
+
if (patchCount > 0) {
|
|
64460
|
+
api.postCommit({ patches }).then((res) => {
|
|
64461
|
+
if (result.isErr(res)) {
|
|
64462
|
+
console.error(res.error);
|
|
64463
|
+
alert("Could not commit patches: " + res.error.message);
|
|
64464
|
+
} else {
|
|
64465
|
+
console.log("Committed patches: ", res.value);
|
|
64466
|
+
onCommit();
|
|
64467
|
+
}
|
|
64468
|
+
});
|
|
64469
|
+
} else {
|
|
64470
|
+
alert("No patches to commit");
|
|
64471
|
+
}
|
|
64447
64472
|
},
|
|
64448
64473
|
children: /* @__PURE__ */ jsxRuntimeExports.jsxs("div", { className: "relative h-[24px] w-[24px] flex justify-center items-center", children: [
|
|
64449
64474
|
/* @__PURE__ */ jsxRuntimeExports.jsx("div", { className: "absolute -right-[10px] -top-[10px] border border-border rounded-full px-1 font-sans text-xs bg-card text-accent", children: patchCount }),
|
|
@@ -64481,6 +64506,26 @@ function MenuButton({
|
|
|
64481
64506
|
}
|
|
64482
64507
|
);
|
|
64483
64508
|
}
|
|
64509
|
+
function usePatches(session, api) {
|
|
64510
|
+
const [patches, setPatches] = reactExports.useState({});
|
|
64511
|
+
const [patchResetId, setPatchResetId] = reactExports.useState(0);
|
|
64512
|
+
reactExports.useEffect(() => {
|
|
64513
|
+
if (session.status === "success" && session.data.mode === "proxy") {
|
|
64514
|
+
api.getPatches({}).then((patchRes) => {
|
|
64515
|
+
if (result.isOk(patchRes)) {
|
|
64516
|
+
const patchesByModuleId = {};
|
|
64517
|
+
for (const moduleId in patchRes.value) {
|
|
64518
|
+
patchesByModuleId[moduleId] = patchRes.value[moduleId].map((patch) => patch.patch_id);
|
|
64519
|
+
}
|
|
64520
|
+
setPatches(patchesByModuleId);
|
|
64521
|
+
} else {
|
|
64522
|
+
console.error("Could not load patches", patchRes.error);
|
|
64523
|
+
}
|
|
64524
|
+
});
|
|
64525
|
+
}
|
|
64526
|
+
}, [session, patchResetId]);
|
|
64527
|
+
return { patches, setPatchResetId };
|
|
64528
|
+
}
|
|
64484
64529
|
function useTheme(defaultTheme = "dark") {
|
|
64485
64530
|
const [theme2, setTheme] = reactExports.useState(defaultTheme);
|
|
64486
64531
|
reactExports.useEffect(() => {
|
|
@@ -64511,6 +64556,3794 @@ function useTheme(defaultTheme = "dark") {
|
|
|
64511
64556
|
}
|
|
64512
64557
|
];
|
|
64513
64558
|
}
|
|
64559
|
+
var util;
|
|
64560
|
+
(function(util2) {
|
|
64561
|
+
util2.assertEqual = (val) => val;
|
|
64562
|
+
function assertIs(_arg) {
|
|
64563
|
+
}
|
|
64564
|
+
util2.assertIs = assertIs;
|
|
64565
|
+
function assertNever(_x) {
|
|
64566
|
+
throw new Error();
|
|
64567
|
+
}
|
|
64568
|
+
util2.assertNever = assertNever;
|
|
64569
|
+
util2.arrayToEnum = (items) => {
|
|
64570
|
+
const obj = {};
|
|
64571
|
+
for (const item of items) {
|
|
64572
|
+
obj[item] = item;
|
|
64573
|
+
}
|
|
64574
|
+
return obj;
|
|
64575
|
+
};
|
|
64576
|
+
util2.getValidEnumValues = (obj) => {
|
|
64577
|
+
const validKeys = util2.objectKeys(obj).filter((k) => typeof obj[obj[k]] !== "number");
|
|
64578
|
+
const filtered = {};
|
|
64579
|
+
for (const k of validKeys) {
|
|
64580
|
+
filtered[k] = obj[k];
|
|
64581
|
+
}
|
|
64582
|
+
return util2.objectValues(filtered);
|
|
64583
|
+
};
|
|
64584
|
+
util2.objectValues = (obj) => {
|
|
64585
|
+
return util2.objectKeys(obj).map(function(e) {
|
|
64586
|
+
return obj[e];
|
|
64587
|
+
});
|
|
64588
|
+
};
|
|
64589
|
+
util2.objectKeys = typeof Object.keys === "function" ? (obj) => Object.keys(obj) : (object) => {
|
|
64590
|
+
const keys = [];
|
|
64591
|
+
for (const key in object) {
|
|
64592
|
+
if (Object.prototype.hasOwnProperty.call(object, key)) {
|
|
64593
|
+
keys.push(key);
|
|
64594
|
+
}
|
|
64595
|
+
}
|
|
64596
|
+
return keys;
|
|
64597
|
+
};
|
|
64598
|
+
util2.find = (arr, checker) => {
|
|
64599
|
+
for (const item of arr) {
|
|
64600
|
+
if (checker(item))
|
|
64601
|
+
return item;
|
|
64602
|
+
}
|
|
64603
|
+
return void 0;
|
|
64604
|
+
};
|
|
64605
|
+
util2.isInteger = typeof Number.isInteger === "function" ? (val) => Number.isInteger(val) : (val) => typeof val === "number" && isFinite(val) && Math.floor(val) === val;
|
|
64606
|
+
function joinValues(array, separator = " | ") {
|
|
64607
|
+
return array.map((val) => typeof val === "string" ? `'${val}'` : val).join(separator);
|
|
64608
|
+
}
|
|
64609
|
+
util2.joinValues = joinValues;
|
|
64610
|
+
util2.jsonStringifyReplacer = (_, value) => {
|
|
64611
|
+
if (typeof value === "bigint") {
|
|
64612
|
+
return value.toString();
|
|
64613
|
+
}
|
|
64614
|
+
return value;
|
|
64615
|
+
};
|
|
64616
|
+
})(util || (util = {}));
|
|
64617
|
+
var objectUtil;
|
|
64618
|
+
(function(objectUtil2) {
|
|
64619
|
+
objectUtil2.mergeShapes = (first, second) => {
|
|
64620
|
+
return {
|
|
64621
|
+
...first,
|
|
64622
|
+
...second
|
|
64623
|
+
// second overwrites first
|
|
64624
|
+
};
|
|
64625
|
+
};
|
|
64626
|
+
})(objectUtil || (objectUtil = {}));
|
|
64627
|
+
const ZodParsedType = util.arrayToEnum([
|
|
64628
|
+
"string",
|
|
64629
|
+
"nan",
|
|
64630
|
+
"number",
|
|
64631
|
+
"integer",
|
|
64632
|
+
"float",
|
|
64633
|
+
"boolean",
|
|
64634
|
+
"date",
|
|
64635
|
+
"bigint",
|
|
64636
|
+
"symbol",
|
|
64637
|
+
"function",
|
|
64638
|
+
"undefined",
|
|
64639
|
+
"null",
|
|
64640
|
+
"array",
|
|
64641
|
+
"object",
|
|
64642
|
+
"unknown",
|
|
64643
|
+
"promise",
|
|
64644
|
+
"void",
|
|
64645
|
+
"never",
|
|
64646
|
+
"map",
|
|
64647
|
+
"set"
|
|
64648
|
+
]);
|
|
64649
|
+
const getParsedType = (data) => {
|
|
64650
|
+
const t = typeof data;
|
|
64651
|
+
switch (t) {
|
|
64652
|
+
case "undefined":
|
|
64653
|
+
return ZodParsedType.undefined;
|
|
64654
|
+
case "string":
|
|
64655
|
+
return ZodParsedType.string;
|
|
64656
|
+
case "number":
|
|
64657
|
+
return isNaN(data) ? ZodParsedType.nan : ZodParsedType.number;
|
|
64658
|
+
case "boolean":
|
|
64659
|
+
return ZodParsedType.boolean;
|
|
64660
|
+
case "function":
|
|
64661
|
+
return ZodParsedType.function;
|
|
64662
|
+
case "bigint":
|
|
64663
|
+
return ZodParsedType.bigint;
|
|
64664
|
+
case "symbol":
|
|
64665
|
+
return ZodParsedType.symbol;
|
|
64666
|
+
case "object":
|
|
64667
|
+
if (Array.isArray(data)) {
|
|
64668
|
+
return ZodParsedType.array;
|
|
64669
|
+
}
|
|
64670
|
+
if (data === null) {
|
|
64671
|
+
return ZodParsedType.null;
|
|
64672
|
+
}
|
|
64673
|
+
if (data.then && typeof data.then === "function" && data.catch && typeof data.catch === "function") {
|
|
64674
|
+
return ZodParsedType.promise;
|
|
64675
|
+
}
|
|
64676
|
+
if (typeof Map !== "undefined" && data instanceof Map) {
|
|
64677
|
+
return ZodParsedType.map;
|
|
64678
|
+
}
|
|
64679
|
+
if (typeof Set !== "undefined" && data instanceof Set) {
|
|
64680
|
+
return ZodParsedType.set;
|
|
64681
|
+
}
|
|
64682
|
+
if (typeof Date !== "undefined" && data instanceof Date) {
|
|
64683
|
+
return ZodParsedType.date;
|
|
64684
|
+
}
|
|
64685
|
+
return ZodParsedType.object;
|
|
64686
|
+
default:
|
|
64687
|
+
return ZodParsedType.unknown;
|
|
64688
|
+
}
|
|
64689
|
+
};
|
|
64690
|
+
const ZodIssueCode = util.arrayToEnum([
|
|
64691
|
+
"invalid_type",
|
|
64692
|
+
"invalid_literal",
|
|
64693
|
+
"custom",
|
|
64694
|
+
"invalid_union",
|
|
64695
|
+
"invalid_union_discriminator",
|
|
64696
|
+
"invalid_enum_value",
|
|
64697
|
+
"unrecognized_keys",
|
|
64698
|
+
"invalid_arguments",
|
|
64699
|
+
"invalid_return_type",
|
|
64700
|
+
"invalid_date",
|
|
64701
|
+
"invalid_string",
|
|
64702
|
+
"too_small",
|
|
64703
|
+
"too_big",
|
|
64704
|
+
"invalid_intersection_types",
|
|
64705
|
+
"not_multiple_of",
|
|
64706
|
+
"not_finite"
|
|
64707
|
+
]);
|
|
64708
|
+
const quotelessJson = (obj) => {
|
|
64709
|
+
const json = JSON.stringify(obj, null, 2);
|
|
64710
|
+
return json.replace(/"([^"]+)":/g, "$1:");
|
|
64711
|
+
};
|
|
64712
|
+
class ZodError extends Error {
|
|
64713
|
+
constructor(issues) {
|
|
64714
|
+
super();
|
|
64715
|
+
this.issues = [];
|
|
64716
|
+
this.addIssue = (sub) => {
|
|
64717
|
+
this.issues = [...this.issues, sub];
|
|
64718
|
+
};
|
|
64719
|
+
this.addIssues = (subs = []) => {
|
|
64720
|
+
this.issues = [...this.issues, ...subs];
|
|
64721
|
+
};
|
|
64722
|
+
const actualProto = new.target.prototype;
|
|
64723
|
+
if (Object.setPrototypeOf) {
|
|
64724
|
+
Object.setPrototypeOf(this, actualProto);
|
|
64725
|
+
} else {
|
|
64726
|
+
this.__proto__ = actualProto;
|
|
64727
|
+
}
|
|
64728
|
+
this.name = "ZodError";
|
|
64729
|
+
this.issues = issues;
|
|
64730
|
+
}
|
|
64731
|
+
get errors() {
|
|
64732
|
+
return this.issues;
|
|
64733
|
+
}
|
|
64734
|
+
format(_mapper) {
|
|
64735
|
+
const mapper = _mapper || function(issue) {
|
|
64736
|
+
return issue.message;
|
|
64737
|
+
};
|
|
64738
|
+
const fieldErrors = { _errors: [] };
|
|
64739
|
+
const processError = (error) => {
|
|
64740
|
+
for (const issue of error.issues) {
|
|
64741
|
+
if (issue.code === "invalid_union") {
|
|
64742
|
+
issue.unionErrors.map(processError);
|
|
64743
|
+
} else if (issue.code === "invalid_return_type") {
|
|
64744
|
+
processError(issue.returnTypeError);
|
|
64745
|
+
} else if (issue.code === "invalid_arguments") {
|
|
64746
|
+
processError(issue.argumentsError);
|
|
64747
|
+
} else if (issue.path.length === 0) {
|
|
64748
|
+
fieldErrors._errors.push(mapper(issue));
|
|
64749
|
+
} else {
|
|
64750
|
+
let curr = fieldErrors;
|
|
64751
|
+
let i = 0;
|
|
64752
|
+
while (i < issue.path.length) {
|
|
64753
|
+
const el = issue.path[i];
|
|
64754
|
+
const terminal = i === issue.path.length - 1;
|
|
64755
|
+
if (!terminal) {
|
|
64756
|
+
curr[el] = curr[el] || { _errors: [] };
|
|
64757
|
+
} else {
|
|
64758
|
+
curr[el] = curr[el] || { _errors: [] };
|
|
64759
|
+
curr[el]._errors.push(mapper(issue));
|
|
64760
|
+
}
|
|
64761
|
+
curr = curr[el];
|
|
64762
|
+
i++;
|
|
64763
|
+
}
|
|
64764
|
+
}
|
|
64765
|
+
}
|
|
64766
|
+
};
|
|
64767
|
+
processError(this);
|
|
64768
|
+
return fieldErrors;
|
|
64769
|
+
}
|
|
64770
|
+
toString() {
|
|
64771
|
+
return this.message;
|
|
64772
|
+
}
|
|
64773
|
+
get message() {
|
|
64774
|
+
return JSON.stringify(this.issues, util.jsonStringifyReplacer, 2);
|
|
64775
|
+
}
|
|
64776
|
+
get isEmpty() {
|
|
64777
|
+
return this.issues.length === 0;
|
|
64778
|
+
}
|
|
64779
|
+
flatten(mapper = (issue) => issue.message) {
|
|
64780
|
+
const fieldErrors = {};
|
|
64781
|
+
const formErrors = [];
|
|
64782
|
+
for (const sub of this.issues) {
|
|
64783
|
+
if (sub.path.length > 0) {
|
|
64784
|
+
fieldErrors[sub.path[0]] = fieldErrors[sub.path[0]] || [];
|
|
64785
|
+
fieldErrors[sub.path[0]].push(mapper(sub));
|
|
64786
|
+
} else {
|
|
64787
|
+
formErrors.push(mapper(sub));
|
|
64788
|
+
}
|
|
64789
|
+
}
|
|
64790
|
+
return { formErrors, fieldErrors };
|
|
64791
|
+
}
|
|
64792
|
+
get formErrors() {
|
|
64793
|
+
return this.flatten();
|
|
64794
|
+
}
|
|
64795
|
+
}
|
|
64796
|
+
ZodError.create = (issues) => {
|
|
64797
|
+
const error = new ZodError(issues);
|
|
64798
|
+
return error;
|
|
64799
|
+
};
|
|
64800
|
+
const errorMap = (issue, _ctx) => {
|
|
64801
|
+
let message;
|
|
64802
|
+
switch (issue.code) {
|
|
64803
|
+
case ZodIssueCode.invalid_type:
|
|
64804
|
+
if (issue.received === ZodParsedType.undefined) {
|
|
64805
|
+
message = "Required";
|
|
64806
|
+
} else {
|
|
64807
|
+
message = `Expected ${issue.expected}, received ${issue.received}`;
|
|
64808
|
+
}
|
|
64809
|
+
break;
|
|
64810
|
+
case ZodIssueCode.invalid_literal:
|
|
64811
|
+
message = `Invalid literal value, expected ${JSON.stringify(issue.expected, util.jsonStringifyReplacer)}`;
|
|
64812
|
+
break;
|
|
64813
|
+
case ZodIssueCode.unrecognized_keys:
|
|
64814
|
+
message = `Unrecognized key(s) in object: ${util.joinValues(issue.keys, ", ")}`;
|
|
64815
|
+
break;
|
|
64816
|
+
case ZodIssueCode.invalid_union:
|
|
64817
|
+
message = `Invalid input`;
|
|
64818
|
+
break;
|
|
64819
|
+
case ZodIssueCode.invalid_union_discriminator:
|
|
64820
|
+
message = `Invalid discriminator value. Expected ${util.joinValues(issue.options)}`;
|
|
64821
|
+
break;
|
|
64822
|
+
case ZodIssueCode.invalid_enum_value:
|
|
64823
|
+
message = `Invalid enum value. Expected ${util.joinValues(issue.options)}, received '${issue.received}'`;
|
|
64824
|
+
break;
|
|
64825
|
+
case ZodIssueCode.invalid_arguments:
|
|
64826
|
+
message = `Invalid function arguments`;
|
|
64827
|
+
break;
|
|
64828
|
+
case ZodIssueCode.invalid_return_type:
|
|
64829
|
+
message = `Invalid function return type`;
|
|
64830
|
+
break;
|
|
64831
|
+
case ZodIssueCode.invalid_date:
|
|
64832
|
+
message = `Invalid date`;
|
|
64833
|
+
break;
|
|
64834
|
+
case ZodIssueCode.invalid_string:
|
|
64835
|
+
if (typeof issue.validation === "object") {
|
|
64836
|
+
if ("includes" in issue.validation) {
|
|
64837
|
+
message = `Invalid input: must include "${issue.validation.includes}"`;
|
|
64838
|
+
if (typeof issue.validation.position === "number") {
|
|
64839
|
+
message = `${message} at one or more positions greater than or equal to ${issue.validation.position}`;
|
|
64840
|
+
}
|
|
64841
|
+
} else if ("startsWith" in issue.validation) {
|
|
64842
|
+
message = `Invalid input: must start with "${issue.validation.startsWith}"`;
|
|
64843
|
+
} else if ("endsWith" in issue.validation) {
|
|
64844
|
+
message = `Invalid input: must end with "${issue.validation.endsWith}"`;
|
|
64845
|
+
} else {
|
|
64846
|
+
util.assertNever(issue.validation);
|
|
64847
|
+
}
|
|
64848
|
+
} else if (issue.validation !== "regex") {
|
|
64849
|
+
message = `Invalid ${issue.validation}`;
|
|
64850
|
+
} else {
|
|
64851
|
+
message = "Invalid";
|
|
64852
|
+
}
|
|
64853
|
+
break;
|
|
64854
|
+
case ZodIssueCode.too_small:
|
|
64855
|
+
if (issue.type === "array")
|
|
64856
|
+
message = `Array must contain ${issue.exact ? "exactly" : issue.inclusive ? `at least` : `more than`} ${issue.minimum} element(s)`;
|
|
64857
|
+
else if (issue.type === "string")
|
|
64858
|
+
message = `String must contain ${issue.exact ? "exactly" : issue.inclusive ? `at least` : `over`} ${issue.minimum} character(s)`;
|
|
64859
|
+
else if (issue.type === "number")
|
|
64860
|
+
message = `Number must be ${issue.exact ? `exactly equal to ` : issue.inclusive ? `greater than or equal to ` : `greater than `}${issue.minimum}`;
|
|
64861
|
+
else if (issue.type === "date")
|
|
64862
|
+
message = `Date must be ${issue.exact ? `exactly equal to ` : issue.inclusive ? `greater than or equal to ` : `greater than `}${new Date(Number(issue.minimum))}`;
|
|
64863
|
+
else
|
|
64864
|
+
message = "Invalid input";
|
|
64865
|
+
break;
|
|
64866
|
+
case ZodIssueCode.too_big:
|
|
64867
|
+
if (issue.type === "array")
|
|
64868
|
+
message = `Array must contain ${issue.exact ? `exactly` : issue.inclusive ? `at most` : `less than`} ${issue.maximum} element(s)`;
|
|
64869
|
+
else if (issue.type === "string")
|
|
64870
|
+
message = `String must contain ${issue.exact ? `exactly` : issue.inclusive ? `at most` : `under`} ${issue.maximum} character(s)`;
|
|
64871
|
+
else if (issue.type === "number")
|
|
64872
|
+
message = `Number must be ${issue.exact ? `exactly` : issue.inclusive ? `less than or equal to` : `less than`} ${issue.maximum}`;
|
|
64873
|
+
else if (issue.type === "bigint")
|
|
64874
|
+
message = `BigInt must be ${issue.exact ? `exactly` : issue.inclusive ? `less than or equal to` : `less than`} ${issue.maximum}`;
|
|
64875
|
+
else if (issue.type === "date")
|
|
64876
|
+
message = `Date must be ${issue.exact ? `exactly` : issue.inclusive ? `smaller than or equal to` : `smaller than`} ${new Date(Number(issue.maximum))}`;
|
|
64877
|
+
else
|
|
64878
|
+
message = "Invalid input";
|
|
64879
|
+
break;
|
|
64880
|
+
case ZodIssueCode.custom:
|
|
64881
|
+
message = `Invalid input`;
|
|
64882
|
+
break;
|
|
64883
|
+
case ZodIssueCode.invalid_intersection_types:
|
|
64884
|
+
message = `Intersection results could not be merged`;
|
|
64885
|
+
break;
|
|
64886
|
+
case ZodIssueCode.not_multiple_of:
|
|
64887
|
+
message = `Number must be a multiple of ${issue.multipleOf}`;
|
|
64888
|
+
break;
|
|
64889
|
+
case ZodIssueCode.not_finite:
|
|
64890
|
+
message = "Number must be finite";
|
|
64891
|
+
break;
|
|
64892
|
+
default:
|
|
64893
|
+
message = _ctx.defaultError;
|
|
64894
|
+
util.assertNever(issue);
|
|
64895
|
+
}
|
|
64896
|
+
return { message };
|
|
64897
|
+
};
|
|
64898
|
+
let overrideErrorMap = errorMap;
|
|
64899
|
+
function setErrorMap(map2) {
|
|
64900
|
+
overrideErrorMap = map2;
|
|
64901
|
+
}
|
|
64902
|
+
function getErrorMap() {
|
|
64903
|
+
return overrideErrorMap;
|
|
64904
|
+
}
|
|
64905
|
+
const makeIssue = (params) => {
|
|
64906
|
+
const { data, path, errorMaps, issueData } = params;
|
|
64907
|
+
const fullPath = [...path, ...issueData.path || []];
|
|
64908
|
+
const fullIssue = {
|
|
64909
|
+
...issueData,
|
|
64910
|
+
path: fullPath
|
|
64911
|
+
};
|
|
64912
|
+
let errorMessage = "";
|
|
64913
|
+
const maps = errorMaps.filter((m2) => !!m2).slice().reverse();
|
|
64914
|
+
for (const map2 of maps) {
|
|
64915
|
+
errorMessage = map2(fullIssue, { data, defaultError: errorMessage }).message;
|
|
64916
|
+
}
|
|
64917
|
+
return {
|
|
64918
|
+
...issueData,
|
|
64919
|
+
path: fullPath,
|
|
64920
|
+
message: issueData.message || errorMessage
|
|
64921
|
+
};
|
|
64922
|
+
};
|
|
64923
|
+
const EMPTY_PATH = [];
|
|
64924
|
+
function addIssueToContext(ctx, issueData) {
|
|
64925
|
+
const issue = makeIssue({
|
|
64926
|
+
issueData,
|
|
64927
|
+
data: ctx.data,
|
|
64928
|
+
path: ctx.path,
|
|
64929
|
+
errorMaps: [
|
|
64930
|
+
ctx.common.contextualErrorMap,
|
|
64931
|
+
ctx.schemaErrorMap,
|
|
64932
|
+
getErrorMap(),
|
|
64933
|
+
errorMap
|
|
64934
|
+
// then global default map
|
|
64935
|
+
].filter((x) => !!x)
|
|
64936
|
+
});
|
|
64937
|
+
ctx.common.issues.push(issue);
|
|
64938
|
+
}
|
|
64939
|
+
class ParseStatus {
|
|
64940
|
+
constructor() {
|
|
64941
|
+
this.value = "valid";
|
|
64942
|
+
}
|
|
64943
|
+
dirty() {
|
|
64944
|
+
if (this.value === "valid")
|
|
64945
|
+
this.value = "dirty";
|
|
64946
|
+
}
|
|
64947
|
+
abort() {
|
|
64948
|
+
if (this.value !== "aborted")
|
|
64949
|
+
this.value = "aborted";
|
|
64950
|
+
}
|
|
64951
|
+
static mergeArray(status, results) {
|
|
64952
|
+
const arrayValue = [];
|
|
64953
|
+
for (const s of results) {
|
|
64954
|
+
if (s.status === "aborted")
|
|
64955
|
+
return INVALID;
|
|
64956
|
+
if (s.status === "dirty")
|
|
64957
|
+
status.dirty();
|
|
64958
|
+
arrayValue.push(s.value);
|
|
64959
|
+
}
|
|
64960
|
+
return { status: status.value, value: arrayValue };
|
|
64961
|
+
}
|
|
64962
|
+
static async mergeObjectAsync(status, pairs) {
|
|
64963
|
+
const syncPairs = [];
|
|
64964
|
+
for (const pair of pairs) {
|
|
64965
|
+
syncPairs.push({
|
|
64966
|
+
key: await pair.key,
|
|
64967
|
+
value: await pair.value
|
|
64968
|
+
});
|
|
64969
|
+
}
|
|
64970
|
+
return ParseStatus.mergeObjectSync(status, syncPairs);
|
|
64971
|
+
}
|
|
64972
|
+
static mergeObjectSync(status, pairs) {
|
|
64973
|
+
const finalObject = {};
|
|
64974
|
+
for (const pair of pairs) {
|
|
64975
|
+
const { key, value } = pair;
|
|
64976
|
+
if (key.status === "aborted")
|
|
64977
|
+
return INVALID;
|
|
64978
|
+
if (value.status === "aborted")
|
|
64979
|
+
return INVALID;
|
|
64980
|
+
if (key.status === "dirty")
|
|
64981
|
+
status.dirty();
|
|
64982
|
+
if (value.status === "dirty")
|
|
64983
|
+
status.dirty();
|
|
64984
|
+
if (key.value !== "__proto__" && (typeof value.value !== "undefined" || pair.alwaysSet)) {
|
|
64985
|
+
finalObject[key.value] = value.value;
|
|
64986
|
+
}
|
|
64987
|
+
}
|
|
64988
|
+
return { status: status.value, value: finalObject };
|
|
64989
|
+
}
|
|
64990
|
+
}
|
|
64991
|
+
const INVALID = Object.freeze({
|
|
64992
|
+
status: "aborted"
|
|
64993
|
+
});
|
|
64994
|
+
const DIRTY = (value) => ({ status: "dirty", value });
|
|
64995
|
+
const OK = (value) => ({ status: "valid", value });
|
|
64996
|
+
const isAborted = (x) => x.status === "aborted";
|
|
64997
|
+
const isDirty = (x) => x.status === "dirty";
|
|
64998
|
+
const isValid = (x) => x.status === "valid";
|
|
64999
|
+
const isAsync = (x) => typeof Promise !== "undefined" && x instanceof Promise;
|
|
65000
|
+
var errorUtil;
|
|
65001
|
+
(function(errorUtil2) {
|
|
65002
|
+
errorUtil2.errToObj = (message) => typeof message === "string" ? { message } : message || {};
|
|
65003
|
+
errorUtil2.toString = (message) => typeof message === "string" ? message : message === null || message === void 0 ? void 0 : message.message;
|
|
65004
|
+
})(errorUtil || (errorUtil = {}));
|
|
65005
|
+
class ParseInputLazyPath {
|
|
65006
|
+
constructor(parent, value, path, key) {
|
|
65007
|
+
this._cachedPath = [];
|
|
65008
|
+
this.parent = parent;
|
|
65009
|
+
this.data = value;
|
|
65010
|
+
this._path = path;
|
|
65011
|
+
this._key = key;
|
|
65012
|
+
}
|
|
65013
|
+
get path() {
|
|
65014
|
+
if (!this._cachedPath.length) {
|
|
65015
|
+
if (this._key instanceof Array) {
|
|
65016
|
+
this._cachedPath.push(...this._path, ...this._key);
|
|
65017
|
+
} else {
|
|
65018
|
+
this._cachedPath.push(...this._path, this._key);
|
|
65019
|
+
}
|
|
65020
|
+
}
|
|
65021
|
+
return this._cachedPath;
|
|
65022
|
+
}
|
|
65023
|
+
}
|
|
65024
|
+
const handleResult = (ctx, result2) => {
|
|
65025
|
+
if (isValid(result2)) {
|
|
65026
|
+
return { success: true, data: result2.value };
|
|
65027
|
+
} else {
|
|
65028
|
+
if (!ctx.common.issues.length) {
|
|
65029
|
+
throw new Error("Validation failed but no issues detected.");
|
|
65030
|
+
}
|
|
65031
|
+
return {
|
|
65032
|
+
success: false,
|
|
65033
|
+
get error() {
|
|
65034
|
+
if (this._error)
|
|
65035
|
+
return this._error;
|
|
65036
|
+
const error = new ZodError(ctx.common.issues);
|
|
65037
|
+
this._error = error;
|
|
65038
|
+
return this._error;
|
|
65039
|
+
}
|
|
65040
|
+
};
|
|
65041
|
+
}
|
|
65042
|
+
};
|
|
65043
|
+
function processCreateParams(params) {
|
|
65044
|
+
if (!params)
|
|
65045
|
+
return {};
|
|
65046
|
+
const { errorMap: errorMap2, invalid_type_error, required_error, description } = params;
|
|
65047
|
+
if (errorMap2 && (invalid_type_error || required_error)) {
|
|
65048
|
+
throw new Error(`Can't use "invalid_type_error" or "required_error" in conjunction with custom error map.`);
|
|
65049
|
+
}
|
|
65050
|
+
if (errorMap2)
|
|
65051
|
+
return { errorMap: errorMap2, description };
|
|
65052
|
+
const customMap = (iss, ctx) => {
|
|
65053
|
+
if (iss.code !== "invalid_type")
|
|
65054
|
+
return { message: ctx.defaultError };
|
|
65055
|
+
if (typeof ctx.data === "undefined") {
|
|
65056
|
+
return { message: required_error !== null && required_error !== void 0 ? required_error : ctx.defaultError };
|
|
65057
|
+
}
|
|
65058
|
+
return { message: invalid_type_error !== null && invalid_type_error !== void 0 ? invalid_type_error : ctx.defaultError };
|
|
65059
|
+
};
|
|
65060
|
+
return { errorMap: customMap, description };
|
|
65061
|
+
}
|
|
65062
|
+
class ZodType {
|
|
65063
|
+
constructor(def) {
|
|
65064
|
+
this.spa = this.safeParseAsync;
|
|
65065
|
+
this._def = def;
|
|
65066
|
+
this.parse = this.parse.bind(this);
|
|
65067
|
+
this.safeParse = this.safeParse.bind(this);
|
|
65068
|
+
this.parseAsync = this.parseAsync.bind(this);
|
|
65069
|
+
this.safeParseAsync = this.safeParseAsync.bind(this);
|
|
65070
|
+
this.spa = this.spa.bind(this);
|
|
65071
|
+
this.refine = this.refine.bind(this);
|
|
65072
|
+
this.refinement = this.refinement.bind(this);
|
|
65073
|
+
this.superRefine = this.superRefine.bind(this);
|
|
65074
|
+
this.optional = this.optional.bind(this);
|
|
65075
|
+
this.nullable = this.nullable.bind(this);
|
|
65076
|
+
this.nullish = this.nullish.bind(this);
|
|
65077
|
+
this.array = this.array.bind(this);
|
|
65078
|
+
this.promise = this.promise.bind(this);
|
|
65079
|
+
this.or = this.or.bind(this);
|
|
65080
|
+
this.and = this.and.bind(this);
|
|
65081
|
+
this.transform = this.transform.bind(this);
|
|
65082
|
+
this.brand = this.brand.bind(this);
|
|
65083
|
+
this.default = this.default.bind(this);
|
|
65084
|
+
this.catch = this.catch.bind(this);
|
|
65085
|
+
this.describe = this.describe.bind(this);
|
|
65086
|
+
this.pipe = this.pipe.bind(this);
|
|
65087
|
+
this.readonly = this.readonly.bind(this);
|
|
65088
|
+
this.isNullable = this.isNullable.bind(this);
|
|
65089
|
+
this.isOptional = this.isOptional.bind(this);
|
|
65090
|
+
}
|
|
65091
|
+
get description() {
|
|
65092
|
+
return this._def.description;
|
|
65093
|
+
}
|
|
65094
|
+
_getType(input) {
|
|
65095
|
+
return getParsedType(input.data);
|
|
65096
|
+
}
|
|
65097
|
+
_getOrReturnCtx(input, ctx) {
|
|
65098
|
+
return ctx || {
|
|
65099
|
+
common: input.parent.common,
|
|
65100
|
+
data: input.data,
|
|
65101
|
+
parsedType: getParsedType(input.data),
|
|
65102
|
+
schemaErrorMap: this._def.errorMap,
|
|
65103
|
+
path: input.path,
|
|
65104
|
+
parent: input.parent
|
|
65105
|
+
};
|
|
65106
|
+
}
|
|
65107
|
+
_processInputParams(input) {
|
|
65108
|
+
return {
|
|
65109
|
+
status: new ParseStatus(),
|
|
65110
|
+
ctx: {
|
|
65111
|
+
common: input.parent.common,
|
|
65112
|
+
data: input.data,
|
|
65113
|
+
parsedType: getParsedType(input.data),
|
|
65114
|
+
schemaErrorMap: this._def.errorMap,
|
|
65115
|
+
path: input.path,
|
|
65116
|
+
parent: input.parent
|
|
65117
|
+
}
|
|
65118
|
+
};
|
|
65119
|
+
}
|
|
65120
|
+
_parseSync(input) {
|
|
65121
|
+
const result2 = this._parse(input);
|
|
65122
|
+
if (isAsync(result2)) {
|
|
65123
|
+
throw new Error("Synchronous parse encountered promise.");
|
|
65124
|
+
}
|
|
65125
|
+
return result2;
|
|
65126
|
+
}
|
|
65127
|
+
_parseAsync(input) {
|
|
65128
|
+
const result2 = this._parse(input);
|
|
65129
|
+
return Promise.resolve(result2);
|
|
65130
|
+
}
|
|
65131
|
+
parse(data, params) {
|
|
65132
|
+
const result2 = this.safeParse(data, params);
|
|
65133
|
+
if (result2.success)
|
|
65134
|
+
return result2.data;
|
|
65135
|
+
throw result2.error;
|
|
65136
|
+
}
|
|
65137
|
+
safeParse(data, params) {
|
|
65138
|
+
var _a;
|
|
65139
|
+
const ctx = {
|
|
65140
|
+
common: {
|
|
65141
|
+
issues: [],
|
|
65142
|
+
async: (_a = params === null || params === void 0 ? void 0 : params.async) !== null && _a !== void 0 ? _a : false,
|
|
65143
|
+
contextualErrorMap: params === null || params === void 0 ? void 0 : params.errorMap
|
|
65144
|
+
},
|
|
65145
|
+
path: (params === null || params === void 0 ? void 0 : params.path) || [],
|
|
65146
|
+
schemaErrorMap: this._def.errorMap,
|
|
65147
|
+
parent: null,
|
|
65148
|
+
data,
|
|
65149
|
+
parsedType: getParsedType(data)
|
|
65150
|
+
};
|
|
65151
|
+
const result2 = this._parseSync({ data, path: ctx.path, parent: ctx });
|
|
65152
|
+
return handleResult(ctx, result2);
|
|
65153
|
+
}
|
|
65154
|
+
async parseAsync(data, params) {
|
|
65155
|
+
const result2 = await this.safeParseAsync(data, params);
|
|
65156
|
+
if (result2.success)
|
|
65157
|
+
return result2.data;
|
|
65158
|
+
throw result2.error;
|
|
65159
|
+
}
|
|
65160
|
+
async safeParseAsync(data, params) {
|
|
65161
|
+
const ctx = {
|
|
65162
|
+
common: {
|
|
65163
|
+
issues: [],
|
|
65164
|
+
contextualErrorMap: params === null || params === void 0 ? void 0 : params.errorMap,
|
|
65165
|
+
async: true
|
|
65166
|
+
},
|
|
65167
|
+
path: (params === null || params === void 0 ? void 0 : params.path) || [],
|
|
65168
|
+
schemaErrorMap: this._def.errorMap,
|
|
65169
|
+
parent: null,
|
|
65170
|
+
data,
|
|
65171
|
+
parsedType: getParsedType(data)
|
|
65172
|
+
};
|
|
65173
|
+
const maybeAsyncResult = this._parse({ data, path: ctx.path, parent: ctx });
|
|
65174
|
+
const result2 = await (isAsync(maybeAsyncResult) ? maybeAsyncResult : Promise.resolve(maybeAsyncResult));
|
|
65175
|
+
return handleResult(ctx, result2);
|
|
65176
|
+
}
|
|
65177
|
+
refine(check, message) {
|
|
65178
|
+
const getIssueProperties = (val) => {
|
|
65179
|
+
if (typeof message === "string" || typeof message === "undefined") {
|
|
65180
|
+
return { message };
|
|
65181
|
+
} else if (typeof message === "function") {
|
|
65182
|
+
return message(val);
|
|
65183
|
+
} else {
|
|
65184
|
+
return message;
|
|
65185
|
+
}
|
|
65186
|
+
};
|
|
65187
|
+
return this._refinement((val, ctx) => {
|
|
65188
|
+
const result2 = check(val);
|
|
65189
|
+
const setError = () => ctx.addIssue({
|
|
65190
|
+
code: ZodIssueCode.custom,
|
|
65191
|
+
...getIssueProperties(val)
|
|
65192
|
+
});
|
|
65193
|
+
if (typeof Promise !== "undefined" && result2 instanceof Promise) {
|
|
65194
|
+
return result2.then((data) => {
|
|
65195
|
+
if (!data) {
|
|
65196
|
+
setError();
|
|
65197
|
+
return false;
|
|
65198
|
+
} else {
|
|
65199
|
+
return true;
|
|
65200
|
+
}
|
|
65201
|
+
});
|
|
65202
|
+
}
|
|
65203
|
+
if (!result2) {
|
|
65204
|
+
setError();
|
|
65205
|
+
return false;
|
|
65206
|
+
} else {
|
|
65207
|
+
return true;
|
|
65208
|
+
}
|
|
65209
|
+
});
|
|
65210
|
+
}
|
|
65211
|
+
refinement(check, refinementData) {
|
|
65212
|
+
return this._refinement((val, ctx) => {
|
|
65213
|
+
if (!check(val)) {
|
|
65214
|
+
ctx.addIssue(typeof refinementData === "function" ? refinementData(val, ctx) : refinementData);
|
|
65215
|
+
return false;
|
|
65216
|
+
} else {
|
|
65217
|
+
return true;
|
|
65218
|
+
}
|
|
65219
|
+
});
|
|
65220
|
+
}
|
|
65221
|
+
_refinement(refinement) {
|
|
65222
|
+
return new ZodEffects({
|
|
65223
|
+
schema: this,
|
|
65224
|
+
typeName: ZodFirstPartyTypeKind.ZodEffects,
|
|
65225
|
+
effect: { type: "refinement", refinement }
|
|
65226
|
+
});
|
|
65227
|
+
}
|
|
65228
|
+
superRefine(refinement) {
|
|
65229
|
+
return this._refinement(refinement);
|
|
65230
|
+
}
|
|
65231
|
+
optional() {
|
|
65232
|
+
return ZodOptional.create(this, this._def);
|
|
65233
|
+
}
|
|
65234
|
+
nullable() {
|
|
65235
|
+
return ZodNullable.create(this, this._def);
|
|
65236
|
+
}
|
|
65237
|
+
nullish() {
|
|
65238
|
+
return this.nullable().optional();
|
|
65239
|
+
}
|
|
65240
|
+
array() {
|
|
65241
|
+
return ZodArray.create(this, this._def);
|
|
65242
|
+
}
|
|
65243
|
+
promise() {
|
|
65244
|
+
return ZodPromise.create(this, this._def);
|
|
65245
|
+
}
|
|
65246
|
+
or(option) {
|
|
65247
|
+
return ZodUnion.create([this, option], this._def);
|
|
65248
|
+
}
|
|
65249
|
+
and(incoming) {
|
|
65250
|
+
return ZodIntersection.create(this, incoming, this._def);
|
|
65251
|
+
}
|
|
65252
|
+
transform(transform) {
|
|
65253
|
+
return new ZodEffects({
|
|
65254
|
+
...processCreateParams(this._def),
|
|
65255
|
+
schema: this,
|
|
65256
|
+
typeName: ZodFirstPartyTypeKind.ZodEffects,
|
|
65257
|
+
effect: { type: "transform", transform }
|
|
65258
|
+
});
|
|
65259
|
+
}
|
|
65260
|
+
default(def) {
|
|
65261
|
+
const defaultValueFunc = typeof def === "function" ? def : () => def;
|
|
65262
|
+
return new ZodDefault({
|
|
65263
|
+
...processCreateParams(this._def),
|
|
65264
|
+
innerType: this,
|
|
65265
|
+
defaultValue: defaultValueFunc,
|
|
65266
|
+
typeName: ZodFirstPartyTypeKind.ZodDefault
|
|
65267
|
+
});
|
|
65268
|
+
}
|
|
65269
|
+
brand() {
|
|
65270
|
+
return new ZodBranded({
|
|
65271
|
+
typeName: ZodFirstPartyTypeKind.ZodBranded,
|
|
65272
|
+
type: this,
|
|
65273
|
+
...processCreateParams(this._def)
|
|
65274
|
+
});
|
|
65275
|
+
}
|
|
65276
|
+
catch(def) {
|
|
65277
|
+
const catchValueFunc = typeof def === "function" ? def : () => def;
|
|
65278
|
+
return new ZodCatch({
|
|
65279
|
+
...processCreateParams(this._def),
|
|
65280
|
+
innerType: this,
|
|
65281
|
+
catchValue: catchValueFunc,
|
|
65282
|
+
typeName: ZodFirstPartyTypeKind.ZodCatch
|
|
65283
|
+
});
|
|
65284
|
+
}
|
|
65285
|
+
describe(description) {
|
|
65286
|
+
const This = this.constructor;
|
|
65287
|
+
return new This({
|
|
65288
|
+
...this._def,
|
|
65289
|
+
description
|
|
65290
|
+
});
|
|
65291
|
+
}
|
|
65292
|
+
pipe(target) {
|
|
65293
|
+
return ZodPipeline.create(this, target);
|
|
65294
|
+
}
|
|
65295
|
+
readonly() {
|
|
65296
|
+
return ZodReadonly.create(this);
|
|
65297
|
+
}
|
|
65298
|
+
isOptional() {
|
|
65299
|
+
return this.safeParse(void 0).success;
|
|
65300
|
+
}
|
|
65301
|
+
isNullable() {
|
|
65302
|
+
return this.safeParse(null).success;
|
|
65303
|
+
}
|
|
65304
|
+
}
|
|
65305
|
+
const cuidRegex = /^c[^\s-]{8,}$/i;
|
|
65306
|
+
const cuid2Regex = /^[a-z][a-z0-9]*$/;
|
|
65307
|
+
const ulidRegex = /^[0-9A-HJKMNP-TV-Z]{26}$/;
|
|
65308
|
+
const 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;
|
|
65309
|
+
const emailRegex = /^(?!\.)(?!.*\.\.)([A-Z0-9_+-\.]*)[A-Z0-9_+-]@([A-Z0-9][A-Z0-9\-]*\.)+[A-Z]{2,}$/i;
|
|
65310
|
+
const _emojiRegex = `^(\\p{Extended_Pictographic}|\\p{Emoji_Component})+$`;
|
|
65311
|
+
let emojiRegex;
|
|
65312
|
+
const ipv4Regex = /^(((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}))$/;
|
|
65313
|
+
const 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})))$/;
|
|
65314
|
+
const datetimeRegex = (args) => {
|
|
65315
|
+
if (args.precision) {
|
|
65316
|
+
if (args.offset) {
|
|
65317
|
+
return new RegExp(`^\\d{4}-\\d{2}-\\d{2}T\\d{2}:\\d{2}:\\d{2}\\.\\d{${args.precision}}(([+-]\\d{2}(:?\\d{2})?)|Z)$`);
|
|
65318
|
+
} else {
|
|
65319
|
+
return new RegExp(`^\\d{4}-\\d{2}-\\d{2}T\\d{2}:\\d{2}:\\d{2}\\.\\d{${args.precision}}Z$`);
|
|
65320
|
+
}
|
|
65321
|
+
} else if (args.precision === 0) {
|
|
65322
|
+
if (args.offset) {
|
|
65323
|
+
return new RegExp(`^\\d{4}-\\d{2}-\\d{2}T\\d{2}:\\d{2}:\\d{2}(([+-]\\d{2}(:?\\d{2})?)|Z)$`);
|
|
65324
|
+
} else {
|
|
65325
|
+
return new RegExp(`^\\d{4}-\\d{2}-\\d{2}T\\d{2}:\\d{2}:\\d{2}Z$`);
|
|
65326
|
+
}
|
|
65327
|
+
} else {
|
|
65328
|
+
if (args.offset) {
|
|
65329
|
+
return new RegExp(`^\\d{4}-\\d{2}-\\d{2}T\\d{2}:\\d{2}:\\d{2}(\\.\\d+)?(([+-]\\d{2}(:?\\d{2})?)|Z)$`);
|
|
65330
|
+
} else {
|
|
65331
|
+
return new RegExp(`^\\d{4}-\\d{2}-\\d{2}T\\d{2}:\\d{2}:\\d{2}(\\.\\d+)?Z$`);
|
|
65332
|
+
}
|
|
65333
|
+
}
|
|
65334
|
+
};
|
|
65335
|
+
function isValidIP(ip, version) {
|
|
65336
|
+
if ((version === "v4" || !version) && ipv4Regex.test(ip)) {
|
|
65337
|
+
return true;
|
|
65338
|
+
}
|
|
65339
|
+
if ((version === "v6" || !version) && ipv6Regex.test(ip)) {
|
|
65340
|
+
return true;
|
|
65341
|
+
}
|
|
65342
|
+
return false;
|
|
65343
|
+
}
|
|
65344
|
+
class ZodString extends ZodType {
|
|
65345
|
+
_parse(input) {
|
|
65346
|
+
if (this._def.coerce) {
|
|
65347
|
+
input.data = String(input.data);
|
|
65348
|
+
}
|
|
65349
|
+
const parsedType = this._getType(input);
|
|
65350
|
+
if (parsedType !== ZodParsedType.string) {
|
|
65351
|
+
const ctx2 = this._getOrReturnCtx(input);
|
|
65352
|
+
addIssueToContext(
|
|
65353
|
+
ctx2,
|
|
65354
|
+
{
|
|
65355
|
+
code: ZodIssueCode.invalid_type,
|
|
65356
|
+
expected: ZodParsedType.string,
|
|
65357
|
+
received: ctx2.parsedType
|
|
65358
|
+
}
|
|
65359
|
+
//
|
|
65360
|
+
);
|
|
65361
|
+
return INVALID;
|
|
65362
|
+
}
|
|
65363
|
+
const status = new ParseStatus();
|
|
65364
|
+
let ctx = void 0;
|
|
65365
|
+
for (const check of this._def.checks) {
|
|
65366
|
+
if (check.kind === "min") {
|
|
65367
|
+
if (input.data.length < check.value) {
|
|
65368
|
+
ctx = this._getOrReturnCtx(input, ctx);
|
|
65369
|
+
addIssueToContext(ctx, {
|
|
65370
|
+
code: ZodIssueCode.too_small,
|
|
65371
|
+
minimum: check.value,
|
|
65372
|
+
type: "string",
|
|
65373
|
+
inclusive: true,
|
|
65374
|
+
exact: false,
|
|
65375
|
+
message: check.message
|
|
65376
|
+
});
|
|
65377
|
+
status.dirty();
|
|
65378
|
+
}
|
|
65379
|
+
} else if (check.kind === "max") {
|
|
65380
|
+
if (input.data.length > check.value) {
|
|
65381
|
+
ctx = this._getOrReturnCtx(input, ctx);
|
|
65382
|
+
addIssueToContext(ctx, {
|
|
65383
|
+
code: ZodIssueCode.too_big,
|
|
65384
|
+
maximum: check.value,
|
|
65385
|
+
type: "string",
|
|
65386
|
+
inclusive: true,
|
|
65387
|
+
exact: false,
|
|
65388
|
+
message: check.message
|
|
65389
|
+
});
|
|
65390
|
+
status.dirty();
|
|
65391
|
+
}
|
|
65392
|
+
} else if (check.kind === "length") {
|
|
65393
|
+
const tooBig = input.data.length > check.value;
|
|
65394
|
+
const tooSmall = input.data.length < check.value;
|
|
65395
|
+
if (tooBig || tooSmall) {
|
|
65396
|
+
ctx = this._getOrReturnCtx(input, ctx);
|
|
65397
|
+
if (tooBig) {
|
|
65398
|
+
addIssueToContext(ctx, {
|
|
65399
|
+
code: ZodIssueCode.too_big,
|
|
65400
|
+
maximum: check.value,
|
|
65401
|
+
type: "string",
|
|
65402
|
+
inclusive: true,
|
|
65403
|
+
exact: true,
|
|
65404
|
+
message: check.message
|
|
65405
|
+
});
|
|
65406
|
+
} else if (tooSmall) {
|
|
65407
|
+
addIssueToContext(ctx, {
|
|
65408
|
+
code: ZodIssueCode.too_small,
|
|
65409
|
+
minimum: check.value,
|
|
65410
|
+
type: "string",
|
|
65411
|
+
inclusive: true,
|
|
65412
|
+
exact: true,
|
|
65413
|
+
message: check.message
|
|
65414
|
+
});
|
|
65415
|
+
}
|
|
65416
|
+
status.dirty();
|
|
65417
|
+
}
|
|
65418
|
+
} else if (check.kind === "email") {
|
|
65419
|
+
if (!emailRegex.test(input.data)) {
|
|
65420
|
+
ctx = this._getOrReturnCtx(input, ctx);
|
|
65421
|
+
addIssueToContext(ctx, {
|
|
65422
|
+
validation: "email",
|
|
65423
|
+
code: ZodIssueCode.invalid_string,
|
|
65424
|
+
message: check.message
|
|
65425
|
+
});
|
|
65426
|
+
status.dirty();
|
|
65427
|
+
}
|
|
65428
|
+
} else if (check.kind === "emoji") {
|
|
65429
|
+
if (!emojiRegex) {
|
|
65430
|
+
emojiRegex = new RegExp(_emojiRegex, "u");
|
|
65431
|
+
}
|
|
65432
|
+
if (!emojiRegex.test(input.data)) {
|
|
65433
|
+
ctx = this._getOrReturnCtx(input, ctx);
|
|
65434
|
+
addIssueToContext(ctx, {
|
|
65435
|
+
validation: "emoji",
|
|
65436
|
+
code: ZodIssueCode.invalid_string,
|
|
65437
|
+
message: check.message
|
|
65438
|
+
});
|
|
65439
|
+
status.dirty();
|
|
65440
|
+
}
|
|
65441
|
+
} else if (check.kind === "uuid") {
|
|
65442
|
+
if (!uuidRegex.test(input.data)) {
|
|
65443
|
+
ctx = this._getOrReturnCtx(input, ctx);
|
|
65444
|
+
addIssueToContext(ctx, {
|
|
65445
|
+
validation: "uuid",
|
|
65446
|
+
code: ZodIssueCode.invalid_string,
|
|
65447
|
+
message: check.message
|
|
65448
|
+
});
|
|
65449
|
+
status.dirty();
|
|
65450
|
+
}
|
|
65451
|
+
} else if (check.kind === "cuid") {
|
|
65452
|
+
if (!cuidRegex.test(input.data)) {
|
|
65453
|
+
ctx = this._getOrReturnCtx(input, ctx);
|
|
65454
|
+
addIssueToContext(ctx, {
|
|
65455
|
+
validation: "cuid",
|
|
65456
|
+
code: ZodIssueCode.invalid_string,
|
|
65457
|
+
message: check.message
|
|
65458
|
+
});
|
|
65459
|
+
status.dirty();
|
|
65460
|
+
}
|
|
65461
|
+
} else if (check.kind === "cuid2") {
|
|
65462
|
+
if (!cuid2Regex.test(input.data)) {
|
|
65463
|
+
ctx = this._getOrReturnCtx(input, ctx);
|
|
65464
|
+
addIssueToContext(ctx, {
|
|
65465
|
+
validation: "cuid2",
|
|
65466
|
+
code: ZodIssueCode.invalid_string,
|
|
65467
|
+
message: check.message
|
|
65468
|
+
});
|
|
65469
|
+
status.dirty();
|
|
65470
|
+
}
|
|
65471
|
+
} else if (check.kind === "ulid") {
|
|
65472
|
+
if (!ulidRegex.test(input.data)) {
|
|
65473
|
+
ctx = this._getOrReturnCtx(input, ctx);
|
|
65474
|
+
addIssueToContext(ctx, {
|
|
65475
|
+
validation: "ulid",
|
|
65476
|
+
code: ZodIssueCode.invalid_string,
|
|
65477
|
+
message: check.message
|
|
65478
|
+
});
|
|
65479
|
+
status.dirty();
|
|
65480
|
+
}
|
|
65481
|
+
} else if (check.kind === "url") {
|
|
65482
|
+
try {
|
|
65483
|
+
new URL(input.data);
|
|
65484
|
+
} catch (_a) {
|
|
65485
|
+
ctx = this._getOrReturnCtx(input, ctx);
|
|
65486
|
+
addIssueToContext(ctx, {
|
|
65487
|
+
validation: "url",
|
|
65488
|
+
code: ZodIssueCode.invalid_string,
|
|
65489
|
+
message: check.message
|
|
65490
|
+
});
|
|
65491
|
+
status.dirty();
|
|
65492
|
+
}
|
|
65493
|
+
} else if (check.kind === "regex") {
|
|
65494
|
+
check.regex.lastIndex = 0;
|
|
65495
|
+
const testResult = check.regex.test(input.data);
|
|
65496
|
+
if (!testResult) {
|
|
65497
|
+
ctx = this._getOrReturnCtx(input, ctx);
|
|
65498
|
+
addIssueToContext(ctx, {
|
|
65499
|
+
validation: "regex",
|
|
65500
|
+
code: ZodIssueCode.invalid_string,
|
|
65501
|
+
message: check.message
|
|
65502
|
+
});
|
|
65503
|
+
status.dirty();
|
|
65504
|
+
}
|
|
65505
|
+
} else if (check.kind === "trim") {
|
|
65506
|
+
input.data = input.data.trim();
|
|
65507
|
+
} else if (check.kind === "includes") {
|
|
65508
|
+
if (!input.data.includes(check.value, check.position)) {
|
|
65509
|
+
ctx = this._getOrReturnCtx(input, ctx);
|
|
65510
|
+
addIssueToContext(ctx, {
|
|
65511
|
+
code: ZodIssueCode.invalid_string,
|
|
65512
|
+
validation: { includes: check.value, position: check.position },
|
|
65513
|
+
message: check.message
|
|
65514
|
+
});
|
|
65515
|
+
status.dirty();
|
|
65516
|
+
}
|
|
65517
|
+
} else if (check.kind === "toLowerCase") {
|
|
65518
|
+
input.data = input.data.toLowerCase();
|
|
65519
|
+
} else if (check.kind === "toUpperCase") {
|
|
65520
|
+
input.data = input.data.toUpperCase();
|
|
65521
|
+
} else if (check.kind === "startsWith") {
|
|
65522
|
+
if (!input.data.startsWith(check.value)) {
|
|
65523
|
+
ctx = this._getOrReturnCtx(input, ctx);
|
|
65524
|
+
addIssueToContext(ctx, {
|
|
65525
|
+
code: ZodIssueCode.invalid_string,
|
|
65526
|
+
validation: { startsWith: check.value },
|
|
65527
|
+
message: check.message
|
|
65528
|
+
});
|
|
65529
|
+
status.dirty();
|
|
65530
|
+
}
|
|
65531
|
+
} else if (check.kind === "endsWith") {
|
|
65532
|
+
if (!input.data.endsWith(check.value)) {
|
|
65533
|
+
ctx = this._getOrReturnCtx(input, ctx);
|
|
65534
|
+
addIssueToContext(ctx, {
|
|
65535
|
+
code: ZodIssueCode.invalid_string,
|
|
65536
|
+
validation: { endsWith: check.value },
|
|
65537
|
+
message: check.message
|
|
65538
|
+
});
|
|
65539
|
+
status.dirty();
|
|
65540
|
+
}
|
|
65541
|
+
} else if (check.kind === "datetime") {
|
|
65542
|
+
const regex = datetimeRegex(check);
|
|
65543
|
+
if (!regex.test(input.data)) {
|
|
65544
|
+
ctx = this._getOrReturnCtx(input, ctx);
|
|
65545
|
+
addIssueToContext(ctx, {
|
|
65546
|
+
code: ZodIssueCode.invalid_string,
|
|
65547
|
+
validation: "datetime",
|
|
65548
|
+
message: check.message
|
|
65549
|
+
});
|
|
65550
|
+
status.dirty();
|
|
65551
|
+
}
|
|
65552
|
+
} else if (check.kind === "ip") {
|
|
65553
|
+
if (!isValidIP(input.data, check.version)) {
|
|
65554
|
+
ctx = this._getOrReturnCtx(input, ctx);
|
|
65555
|
+
addIssueToContext(ctx, {
|
|
65556
|
+
validation: "ip",
|
|
65557
|
+
code: ZodIssueCode.invalid_string,
|
|
65558
|
+
message: check.message
|
|
65559
|
+
});
|
|
65560
|
+
status.dirty();
|
|
65561
|
+
}
|
|
65562
|
+
} else {
|
|
65563
|
+
util.assertNever(check);
|
|
65564
|
+
}
|
|
65565
|
+
}
|
|
65566
|
+
return { status: status.value, value: input.data };
|
|
65567
|
+
}
|
|
65568
|
+
_regex(regex, validation, message) {
|
|
65569
|
+
return this.refinement((data) => regex.test(data), {
|
|
65570
|
+
validation,
|
|
65571
|
+
code: ZodIssueCode.invalid_string,
|
|
65572
|
+
...errorUtil.errToObj(message)
|
|
65573
|
+
});
|
|
65574
|
+
}
|
|
65575
|
+
_addCheck(check) {
|
|
65576
|
+
return new ZodString({
|
|
65577
|
+
...this._def,
|
|
65578
|
+
checks: [...this._def.checks, check]
|
|
65579
|
+
});
|
|
65580
|
+
}
|
|
65581
|
+
email(message) {
|
|
65582
|
+
return this._addCheck({ kind: "email", ...errorUtil.errToObj(message) });
|
|
65583
|
+
}
|
|
65584
|
+
url(message) {
|
|
65585
|
+
return this._addCheck({ kind: "url", ...errorUtil.errToObj(message) });
|
|
65586
|
+
}
|
|
65587
|
+
emoji(message) {
|
|
65588
|
+
return this._addCheck({ kind: "emoji", ...errorUtil.errToObj(message) });
|
|
65589
|
+
}
|
|
65590
|
+
uuid(message) {
|
|
65591
|
+
return this._addCheck({ kind: "uuid", ...errorUtil.errToObj(message) });
|
|
65592
|
+
}
|
|
65593
|
+
cuid(message) {
|
|
65594
|
+
return this._addCheck({ kind: "cuid", ...errorUtil.errToObj(message) });
|
|
65595
|
+
}
|
|
65596
|
+
cuid2(message) {
|
|
65597
|
+
return this._addCheck({ kind: "cuid2", ...errorUtil.errToObj(message) });
|
|
65598
|
+
}
|
|
65599
|
+
ulid(message) {
|
|
65600
|
+
return this._addCheck({ kind: "ulid", ...errorUtil.errToObj(message) });
|
|
65601
|
+
}
|
|
65602
|
+
ip(options) {
|
|
65603
|
+
return this._addCheck({ kind: "ip", ...errorUtil.errToObj(options) });
|
|
65604
|
+
}
|
|
65605
|
+
datetime(options) {
|
|
65606
|
+
var _a;
|
|
65607
|
+
if (typeof options === "string") {
|
|
65608
|
+
return this._addCheck({
|
|
65609
|
+
kind: "datetime",
|
|
65610
|
+
precision: null,
|
|
65611
|
+
offset: false,
|
|
65612
|
+
message: options
|
|
65613
|
+
});
|
|
65614
|
+
}
|
|
65615
|
+
return this._addCheck({
|
|
65616
|
+
kind: "datetime",
|
|
65617
|
+
precision: typeof (options === null || options === void 0 ? void 0 : options.precision) === "undefined" ? null : options === null || options === void 0 ? void 0 : options.precision,
|
|
65618
|
+
offset: (_a = options === null || options === void 0 ? void 0 : options.offset) !== null && _a !== void 0 ? _a : false,
|
|
65619
|
+
...errorUtil.errToObj(options === null || options === void 0 ? void 0 : options.message)
|
|
65620
|
+
});
|
|
65621
|
+
}
|
|
65622
|
+
regex(regex, message) {
|
|
65623
|
+
return this._addCheck({
|
|
65624
|
+
kind: "regex",
|
|
65625
|
+
regex,
|
|
65626
|
+
...errorUtil.errToObj(message)
|
|
65627
|
+
});
|
|
65628
|
+
}
|
|
65629
|
+
includes(value, options) {
|
|
65630
|
+
return this._addCheck({
|
|
65631
|
+
kind: "includes",
|
|
65632
|
+
value,
|
|
65633
|
+
position: options === null || options === void 0 ? void 0 : options.position,
|
|
65634
|
+
...errorUtil.errToObj(options === null || options === void 0 ? void 0 : options.message)
|
|
65635
|
+
});
|
|
65636
|
+
}
|
|
65637
|
+
startsWith(value, message) {
|
|
65638
|
+
return this._addCheck({
|
|
65639
|
+
kind: "startsWith",
|
|
65640
|
+
value,
|
|
65641
|
+
...errorUtil.errToObj(message)
|
|
65642
|
+
});
|
|
65643
|
+
}
|
|
65644
|
+
endsWith(value, message) {
|
|
65645
|
+
return this._addCheck({
|
|
65646
|
+
kind: "endsWith",
|
|
65647
|
+
value,
|
|
65648
|
+
...errorUtil.errToObj(message)
|
|
65649
|
+
});
|
|
65650
|
+
}
|
|
65651
|
+
min(minLength, message) {
|
|
65652
|
+
return this._addCheck({
|
|
65653
|
+
kind: "min",
|
|
65654
|
+
value: minLength,
|
|
65655
|
+
...errorUtil.errToObj(message)
|
|
65656
|
+
});
|
|
65657
|
+
}
|
|
65658
|
+
max(maxLength, message) {
|
|
65659
|
+
return this._addCheck({
|
|
65660
|
+
kind: "max",
|
|
65661
|
+
value: maxLength,
|
|
65662
|
+
...errorUtil.errToObj(message)
|
|
65663
|
+
});
|
|
65664
|
+
}
|
|
65665
|
+
length(len, message) {
|
|
65666
|
+
return this._addCheck({
|
|
65667
|
+
kind: "length",
|
|
65668
|
+
value: len,
|
|
65669
|
+
...errorUtil.errToObj(message)
|
|
65670
|
+
});
|
|
65671
|
+
}
|
|
65672
|
+
/**
|
|
65673
|
+
* @deprecated Use z.string().min(1) instead.
|
|
65674
|
+
* @see {@link ZodString.min}
|
|
65675
|
+
*/
|
|
65676
|
+
nonempty(message) {
|
|
65677
|
+
return this.min(1, errorUtil.errToObj(message));
|
|
65678
|
+
}
|
|
65679
|
+
trim() {
|
|
65680
|
+
return new ZodString({
|
|
65681
|
+
...this._def,
|
|
65682
|
+
checks: [...this._def.checks, { kind: "trim" }]
|
|
65683
|
+
});
|
|
65684
|
+
}
|
|
65685
|
+
toLowerCase() {
|
|
65686
|
+
return new ZodString({
|
|
65687
|
+
...this._def,
|
|
65688
|
+
checks: [...this._def.checks, { kind: "toLowerCase" }]
|
|
65689
|
+
});
|
|
65690
|
+
}
|
|
65691
|
+
toUpperCase() {
|
|
65692
|
+
return new ZodString({
|
|
65693
|
+
...this._def,
|
|
65694
|
+
checks: [...this._def.checks, { kind: "toUpperCase" }]
|
|
65695
|
+
});
|
|
65696
|
+
}
|
|
65697
|
+
get isDatetime() {
|
|
65698
|
+
return !!this._def.checks.find((ch3) => ch3.kind === "datetime");
|
|
65699
|
+
}
|
|
65700
|
+
get isEmail() {
|
|
65701
|
+
return !!this._def.checks.find((ch3) => ch3.kind === "email");
|
|
65702
|
+
}
|
|
65703
|
+
get isURL() {
|
|
65704
|
+
return !!this._def.checks.find((ch3) => ch3.kind === "url");
|
|
65705
|
+
}
|
|
65706
|
+
get isEmoji() {
|
|
65707
|
+
return !!this._def.checks.find((ch3) => ch3.kind === "emoji");
|
|
65708
|
+
}
|
|
65709
|
+
get isUUID() {
|
|
65710
|
+
return !!this._def.checks.find((ch3) => ch3.kind === "uuid");
|
|
65711
|
+
}
|
|
65712
|
+
get isCUID() {
|
|
65713
|
+
return !!this._def.checks.find((ch3) => ch3.kind === "cuid");
|
|
65714
|
+
}
|
|
65715
|
+
get isCUID2() {
|
|
65716
|
+
return !!this._def.checks.find((ch3) => ch3.kind === "cuid2");
|
|
65717
|
+
}
|
|
65718
|
+
get isULID() {
|
|
65719
|
+
return !!this._def.checks.find((ch3) => ch3.kind === "ulid");
|
|
65720
|
+
}
|
|
65721
|
+
get isIP() {
|
|
65722
|
+
return !!this._def.checks.find((ch3) => ch3.kind === "ip");
|
|
65723
|
+
}
|
|
65724
|
+
get minLength() {
|
|
65725
|
+
let min2 = null;
|
|
65726
|
+
for (const ch3 of this._def.checks) {
|
|
65727
|
+
if (ch3.kind === "min") {
|
|
65728
|
+
if (min2 === null || ch3.value > min2)
|
|
65729
|
+
min2 = ch3.value;
|
|
65730
|
+
}
|
|
65731
|
+
}
|
|
65732
|
+
return min2;
|
|
65733
|
+
}
|
|
65734
|
+
get maxLength() {
|
|
65735
|
+
let max2 = null;
|
|
65736
|
+
for (const ch3 of this._def.checks) {
|
|
65737
|
+
if (ch3.kind === "max") {
|
|
65738
|
+
if (max2 === null || ch3.value < max2)
|
|
65739
|
+
max2 = ch3.value;
|
|
65740
|
+
}
|
|
65741
|
+
}
|
|
65742
|
+
return max2;
|
|
65743
|
+
}
|
|
65744
|
+
}
|
|
65745
|
+
ZodString.create = (params) => {
|
|
65746
|
+
var _a;
|
|
65747
|
+
return new ZodString({
|
|
65748
|
+
checks: [],
|
|
65749
|
+
typeName: ZodFirstPartyTypeKind.ZodString,
|
|
65750
|
+
coerce: (_a = params === null || params === void 0 ? void 0 : params.coerce) !== null && _a !== void 0 ? _a : false,
|
|
65751
|
+
...processCreateParams(params)
|
|
65752
|
+
});
|
|
65753
|
+
};
|
|
65754
|
+
function floatSafeRemainder(val, step) {
|
|
65755
|
+
const valDecCount = (val.toString().split(".")[1] || "").length;
|
|
65756
|
+
const stepDecCount = (step.toString().split(".")[1] || "").length;
|
|
65757
|
+
const decCount = valDecCount > stepDecCount ? valDecCount : stepDecCount;
|
|
65758
|
+
const valInt = parseInt(val.toFixed(decCount).replace(".", ""));
|
|
65759
|
+
const stepInt = parseInt(step.toFixed(decCount).replace(".", ""));
|
|
65760
|
+
return valInt % stepInt / Math.pow(10, decCount);
|
|
65761
|
+
}
|
|
65762
|
+
class ZodNumber extends ZodType {
|
|
65763
|
+
constructor() {
|
|
65764
|
+
super(...arguments);
|
|
65765
|
+
this.min = this.gte;
|
|
65766
|
+
this.max = this.lte;
|
|
65767
|
+
this.step = this.multipleOf;
|
|
65768
|
+
}
|
|
65769
|
+
_parse(input) {
|
|
65770
|
+
if (this._def.coerce) {
|
|
65771
|
+
input.data = Number(input.data);
|
|
65772
|
+
}
|
|
65773
|
+
const parsedType = this._getType(input);
|
|
65774
|
+
if (parsedType !== ZodParsedType.number) {
|
|
65775
|
+
const ctx2 = this._getOrReturnCtx(input);
|
|
65776
|
+
addIssueToContext(ctx2, {
|
|
65777
|
+
code: ZodIssueCode.invalid_type,
|
|
65778
|
+
expected: ZodParsedType.number,
|
|
65779
|
+
received: ctx2.parsedType
|
|
65780
|
+
});
|
|
65781
|
+
return INVALID;
|
|
65782
|
+
}
|
|
65783
|
+
let ctx = void 0;
|
|
65784
|
+
const status = new ParseStatus();
|
|
65785
|
+
for (const check of this._def.checks) {
|
|
65786
|
+
if (check.kind === "int") {
|
|
65787
|
+
if (!util.isInteger(input.data)) {
|
|
65788
|
+
ctx = this._getOrReturnCtx(input, ctx);
|
|
65789
|
+
addIssueToContext(ctx, {
|
|
65790
|
+
code: ZodIssueCode.invalid_type,
|
|
65791
|
+
expected: "integer",
|
|
65792
|
+
received: "float",
|
|
65793
|
+
message: check.message
|
|
65794
|
+
});
|
|
65795
|
+
status.dirty();
|
|
65796
|
+
}
|
|
65797
|
+
} else if (check.kind === "min") {
|
|
65798
|
+
const tooSmall = check.inclusive ? input.data < check.value : input.data <= check.value;
|
|
65799
|
+
if (tooSmall) {
|
|
65800
|
+
ctx = this._getOrReturnCtx(input, ctx);
|
|
65801
|
+
addIssueToContext(ctx, {
|
|
65802
|
+
code: ZodIssueCode.too_small,
|
|
65803
|
+
minimum: check.value,
|
|
65804
|
+
type: "number",
|
|
65805
|
+
inclusive: check.inclusive,
|
|
65806
|
+
exact: false,
|
|
65807
|
+
message: check.message
|
|
65808
|
+
});
|
|
65809
|
+
status.dirty();
|
|
65810
|
+
}
|
|
65811
|
+
} else if (check.kind === "max") {
|
|
65812
|
+
const tooBig = check.inclusive ? input.data > check.value : input.data >= check.value;
|
|
65813
|
+
if (tooBig) {
|
|
65814
|
+
ctx = this._getOrReturnCtx(input, ctx);
|
|
65815
|
+
addIssueToContext(ctx, {
|
|
65816
|
+
code: ZodIssueCode.too_big,
|
|
65817
|
+
maximum: check.value,
|
|
65818
|
+
type: "number",
|
|
65819
|
+
inclusive: check.inclusive,
|
|
65820
|
+
exact: false,
|
|
65821
|
+
message: check.message
|
|
65822
|
+
});
|
|
65823
|
+
status.dirty();
|
|
65824
|
+
}
|
|
65825
|
+
} else if (check.kind === "multipleOf") {
|
|
65826
|
+
if (floatSafeRemainder(input.data, check.value) !== 0) {
|
|
65827
|
+
ctx = this._getOrReturnCtx(input, ctx);
|
|
65828
|
+
addIssueToContext(ctx, {
|
|
65829
|
+
code: ZodIssueCode.not_multiple_of,
|
|
65830
|
+
multipleOf: check.value,
|
|
65831
|
+
message: check.message
|
|
65832
|
+
});
|
|
65833
|
+
status.dirty();
|
|
65834
|
+
}
|
|
65835
|
+
} else if (check.kind === "finite") {
|
|
65836
|
+
if (!Number.isFinite(input.data)) {
|
|
65837
|
+
ctx = this._getOrReturnCtx(input, ctx);
|
|
65838
|
+
addIssueToContext(ctx, {
|
|
65839
|
+
code: ZodIssueCode.not_finite,
|
|
65840
|
+
message: check.message
|
|
65841
|
+
});
|
|
65842
|
+
status.dirty();
|
|
65843
|
+
}
|
|
65844
|
+
} else {
|
|
65845
|
+
util.assertNever(check);
|
|
65846
|
+
}
|
|
65847
|
+
}
|
|
65848
|
+
return { status: status.value, value: input.data };
|
|
65849
|
+
}
|
|
65850
|
+
gte(value, message) {
|
|
65851
|
+
return this.setLimit("min", value, true, errorUtil.toString(message));
|
|
65852
|
+
}
|
|
65853
|
+
gt(value, message) {
|
|
65854
|
+
return this.setLimit("min", value, false, errorUtil.toString(message));
|
|
65855
|
+
}
|
|
65856
|
+
lte(value, message) {
|
|
65857
|
+
return this.setLimit("max", value, true, errorUtil.toString(message));
|
|
65858
|
+
}
|
|
65859
|
+
lt(value, message) {
|
|
65860
|
+
return this.setLimit("max", value, false, errorUtil.toString(message));
|
|
65861
|
+
}
|
|
65862
|
+
setLimit(kind, value, inclusive, message) {
|
|
65863
|
+
return new ZodNumber({
|
|
65864
|
+
...this._def,
|
|
65865
|
+
checks: [
|
|
65866
|
+
...this._def.checks,
|
|
65867
|
+
{
|
|
65868
|
+
kind,
|
|
65869
|
+
value,
|
|
65870
|
+
inclusive,
|
|
65871
|
+
message: errorUtil.toString(message)
|
|
65872
|
+
}
|
|
65873
|
+
]
|
|
65874
|
+
});
|
|
65875
|
+
}
|
|
65876
|
+
_addCheck(check) {
|
|
65877
|
+
return new ZodNumber({
|
|
65878
|
+
...this._def,
|
|
65879
|
+
checks: [...this._def.checks, check]
|
|
65880
|
+
});
|
|
65881
|
+
}
|
|
65882
|
+
int(message) {
|
|
65883
|
+
return this._addCheck({
|
|
65884
|
+
kind: "int",
|
|
65885
|
+
message: errorUtil.toString(message)
|
|
65886
|
+
});
|
|
65887
|
+
}
|
|
65888
|
+
positive(message) {
|
|
65889
|
+
return this._addCheck({
|
|
65890
|
+
kind: "min",
|
|
65891
|
+
value: 0,
|
|
65892
|
+
inclusive: false,
|
|
65893
|
+
message: errorUtil.toString(message)
|
|
65894
|
+
});
|
|
65895
|
+
}
|
|
65896
|
+
negative(message) {
|
|
65897
|
+
return this._addCheck({
|
|
65898
|
+
kind: "max",
|
|
65899
|
+
value: 0,
|
|
65900
|
+
inclusive: false,
|
|
65901
|
+
message: errorUtil.toString(message)
|
|
65902
|
+
});
|
|
65903
|
+
}
|
|
65904
|
+
nonpositive(message) {
|
|
65905
|
+
return this._addCheck({
|
|
65906
|
+
kind: "max",
|
|
65907
|
+
value: 0,
|
|
65908
|
+
inclusive: true,
|
|
65909
|
+
message: errorUtil.toString(message)
|
|
65910
|
+
});
|
|
65911
|
+
}
|
|
65912
|
+
nonnegative(message) {
|
|
65913
|
+
return this._addCheck({
|
|
65914
|
+
kind: "min",
|
|
65915
|
+
value: 0,
|
|
65916
|
+
inclusive: true,
|
|
65917
|
+
message: errorUtil.toString(message)
|
|
65918
|
+
});
|
|
65919
|
+
}
|
|
65920
|
+
multipleOf(value, message) {
|
|
65921
|
+
return this._addCheck({
|
|
65922
|
+
kind: "multipleOf",
|
|
65923
|
+
value,
|
|
65924
|
+
message: errorUtil.toString(message)
|
|
65925
|
+
});
|
|
65926
|
+
}
|
|
65927
|
+
finite(message) {
|
|
65928
|
+
return this._addCheck({
|
|
65929
|
+
kind: "finite",
|
|
65930
|
+
message: errorUtil.toString(message)
|
|
65931
|
+
});
|
|
65932
|
+
}
|
|
65933
|
+
safe(message) {
|
|
65934
|
+
return this._addCheck({
|
|
65935
|
+
kind: "min",
|
|
65936
|
+
inclusive: true,
|
|
65937
|
+
value: Number.MIN_SAFE_INTEGER,
|
|
65938
|
+
message: errorUtil.toString(message)
|
|
65939
|
+
})._addCheck({
|
|
65940
|
+
kind: "max",
|
|
65941
|
+
inclusive: true,
|
|
65942
|
+
value: Number.MAX_SAFE_INTEGER,
|
|
65943
|
+
message: errorUtil.toString(message)
|
|
65944
|
+
});
|
|
65945
|
+
}
|
|
65946
|
+
get minValue() {
|
|
65947
|
+
let min2 = null;
|
|
65948
|
+
for (const ch3 of this._def.checks) {
|
|
65949
|
+
if (ch3.kind === "min") {
|
|
65950
|
+
if (min2 === null || ch3.value > min2)
|
|
65951
|
+
min2 = ch3.value;
|
|
65952
|
+
}
|
|
65953
|
+
}
|
|
65954
|
+
return min2;
|
|
65955
|
+
}
|
|
65956
|
+
get maxValue() {
|
|
65957
|
+
let max2 = null;
|
|
65958
|
+
for (const ch3 of this._def.checks) {
|
|
65959
|
+
if (ch3.kind === "max") {
|
|
65960
|
+
if (max2 === null || ch3.value < max2)
|
|
65961
|
+
max2 = ch3.value;
|
|
65962
|
+
}
|
|
65963
|
+
}
|
|
65964
|
+
return max2;
|
|
65965
|
+
}
|
|
65966
|
+
get isInt() {
|
|
65967
|
+
return !!this._def.checks.find((ch3) => ch3.kind === "int" || ch3.kind === "multipleOf" && util.isInteger(ch3.value));
|
|
65968
|
+
}
|
|
65969
|
+
get isFinite() {
|
|
65970
|
+
let max2 = null, min2 = null;
|
|
65971
|
+
for (const ch3 of this._def.checks) {
|
|
65972
|
+
if (ch3.kind === "finite" || ch3.kind === "int" || ch3.kind === "multipleOf") {
|
|
65973
|
+
return true;
|
|
65974
|
+
} else if (ch3.kind === "min") {
|
|
65975
|
+
if (min2 === null || ch3.value > min2)
|
|
65976
|
+
min2 = ch3.value;
|
|
65977
|
+
} else if (ch3.kind === "max") {
|
|
65978
|
+
if (max2 === null || ch3.value < max2)
|
|
65979
|
+
max2 = ch3.value;
|
|
65980
|
+
}
|
|
65981
|
+
}
|
|
65982
|
+
return Number.isFinite(min2) && Number.isFinite(max2);
|
|
65983
|
+
}
|
|
65984
|
+
}
|
|
65985
|
+
ZodNumber.create = (params) => {
|
|
65986
|
+
return new ZodNumber({
|
|
65987
|
+
checks: [],
|
|
65988
|
+
typeName: ZodFirstPartyTypeKind.ZodNumber,
|
|
65989
|
+
coerce: (params === null || params === void 0 ? void 0 : params.coerce) || false,
|
|
65990
|
+
...processCreateParams(params)
|
|
65991
|
+
});
|
|
65992
|
+
};
|
|
65993
|
+
class ZodBigInt extends ZodType {
|
|
65994
|
+
constructor() {
|
|
65995
|
+
super(...arguments);
|
|
65996
|
+
this.min = this.gte;
|
|
65997
|
+
this.max = this.lte;
|
|
65998
|
+
}
|
|
65999
|
+
_parse(input) {
|
|
66000
|
+
if (this._def.coerce) {
|
|
66001
|
+
input.data = BigInt(input.data);
|
|
66002
|
+
}
|
|
66003
|
+
const parsedType = this._getType(input);
|
|
66004
|
+
if (parsedType !== ZodParsedType.bigint) {
|
|
66005
|
+
const ctx2 = this._getOrReturnCtx(input);
|
|
66006
|
+
addIssueToContext(ctx2, {
|
|
66007
|
+
code: ZodIssueCode.invalid_type,
|
|
66008
|
+
expected: ZodParsedType.bigint,
|
|
66009
|
+
received: ctx2.parsedType
|
|
66010
|
+
});
|
|
66011
|
+
return INVALID;
|
|
66012
|
+
}
|
|
66013
|
+
let ctx = void 0;
|
|
66014
|
+
const status = new ParseStatus();
|
|
66015
|
+
for (const check of this._def.checks) {
|
|
66016
|
+
if (check.kind === "min") {
|
|
66017
|
+
const tooSmall = check.inclusive ? input.data < check.value : input.data <= check.value;
|
|
66018
|
+
if (tooSmall) {
|
|
66019
|
+
ctx = this._getOrReturnCtx(input, ctx);
|
|
66020
|
+
addIssueToContext(ctx, {
|
|
66021
|
+
code: ZodIssueCode.too_small,
|
|
66022
|
+
type: "bigint",
|
|
66023
|
+
minimum: check.value,
|
|
66024
|
+
inclusive: check.inclusive,
|
|
66025
|
+
message: check.message
|
|
66026
|
+
});
|
|
66027
|
+
status.dirty();
|
|
66028
|
+
}
|
|
66029
|
+
} else if (check.kind === "max") {
|
|
66030
|
+
const tooBig = check.inclusive ? input.data > check.value : input.data >= check.value;
|
|
66031
|
+
if (tooBig) {
|
|
66032
|
+
ctx = this._getOrReturnCtx(input, ctx);
|
|
66033
|
+
addIssueToContext(ctx, {
|
|
66034
|
+
code: ZodIssueCode.too_big,
|
|
66035
|
+
type: "bigint",
|
|
66036
|
+
maximum: check.value,
|
|
66037
|
+
inclusive: check.inclusive,
|
|
66038
|
+
message: check.message
|
|
66039
|
+
});
|
|
66040
|
+
status.dirty();
|
|
66041
|
+
}
|
|
66042
|
+
} else if (check.kind === "multipleOf") {
|
|
66043
|
+
if (input.data % check.value !== BigInt(0)) {
|
|
66044
|
+
ctx = this._getOrReturnCtx(input, ctx);
|
|
66045
|
+
addIssueToContext(ctx, {
|
|
66046
|
+
code: ZodIssueCode.not_multiple_of,
|
|
66047
|
+
multipleOf: check.value,
|
|
66048
|
+
message: check.message
|
|
66049
|
+
});
|
|
66050
|
+
status.dirty();
|
|
66051
|
+
}
|
|
66052
|
+
} else {
|
|
66053
|
+
util.assertNever(check);
|
|
66054
|
+
}
|
|
66055
|
+
}
|
|
66056
|
+
return { status: status.value, value: input.data };
|
|
66057
|
+
}
|
|
66058
|
+
gte(value, message) {
|
|
66059
|
+
return this.setLimit("min", value, true, errorUtil.toString(message));
|
|
66060
|
+
}
|
|
66061
|
+
gt(value, message) {
|
|
66062
|
+
return this.setLimit("min", value, false, errorUtil.toString(message));
|
|
66063
|
+
}
|
|
66064
|
+
lte(value, message) {
|
|
66065
|
+
return this.setLimit("max", value, true, errorUtil.toString(message));
|
|
66066
|
+
}
|
|
66067
|
+
lt(value, message) {
|
|
66068
|
+
return this.setLimit("max", value, false, errorUtil.toString(message));
|
|
66069
|
+
}
|
|
66070
|
+
setLimit(kind, value, inclusive, message) {
|
|
66071
|
+
return new ZodBigInt({
|
|
66072
|
+
...this._def,
|
|
66073
|
+
checks: [
|
|
66074
|
+
...this._def.checks,
|
|
66075
|
+
{
|
|
66076
|
+
kind,
|
|
66077
|
+
value,
|
|
66078
|
+
inclusive,
|
|
66079
|
+
message: errorUtil.toString(message)
|
|
66080
|
+
}
|
|
66081
|
+
]
|
|
66082
|
+
});
|
|
66083
|
+
}
|
|
66084
|
+
_addCheck(check) {
|
|
66085
|
+
return new ZodBigInt({
|
|
66086
|
+
...this._def,
|
|
66087
|
+
checks: [...this._def.checks, check]
|
|
66088
|
+
});
|
|
66089
|
+
}
|
|
66090
|
+
positive(message) {
|
|
66091
|
+
return this._addCheck({
|
|
66092
|
+
kind: "min",
|
|
66093
|
+
value: BigInt(0),
|
|
66094
|
+
inclusive: false,
|
|
66095
|
+
message: errorUtil.toString(message)
|
|
66096
|
+
});
|
|
66097
|
+
}
|
|
66098
|
+
negative(message) {
|
|
66099
|
+
return this._addCheck({
|
|
66100
|
+
kind: "max",
|
|
66101
|
+
value: BigInt(0),
|
|
66102
|
+
inclusive: false,
|
|
66103
|
+
message: errorUtil.toString(message)
|
|
66104
|
+
});
|
|
66105
|
+
}
|
|
66106
|
+
nonpositive(message) {
|
|
66107
|
+
return this._addCheck({
|
|
66108
|
+
kind: "max",
|
|
66109
|
+
value: BigInt(0),
|
|
66110
|
+
inclusive: true,
|
|
66111
|
+
message: errorUtil.toString(message)
|
|
66112
|
+
});
|
|
66113
|
+
}
|
|
66114
|
+
nonnegative(message) {
|
|
66115
|
+
return this._addCheck({
|
|
66116
|
+
kind: "min",
|
|
66117
|
+
value: BigInt(0),
|
|
66118
|
+
inclusive: true,
|
|
66119
|
+
message: errorUtil.toString(message)
|
|
66120
|
+
});
|
|
66121
|
+
}
|
|
66122
|
+
multipleOf(value, message) {
|
|
66123
|
+
return this._addCheck({
|
|
66124
|
+
kind: "multipleOf",
|
|
66125
|
+
value,
|
|
66126
|
+
message: errorUtil.toString(message)
|
|
66127
|
+
});
|
|
66128
|
+
}
|
|
66129
|
+
get minValue() {
|
|
66130
|
+
let min2 = null;
|
|
66131
|
+
for (const ch3 of this._def.checks) {
|
|
66132
|
+
if (ch3.kind === "min") {
|
|
66133
|
+
if (min2 === null || ch3.value > min2)
|
|
66134
|
+
min2 = ch3.value;
|
|
66135
|
+
}
|
|
66136
|
+
}
|
|
66137
|
+
return min2;
|
|
66138
|
+
}
|
|
66139
|
+
get maxValue() {
|
|
66140
|
+
let max2 = null;
|
|
66141
|
+
for (const ch3 of this._def.checks) {
|
|
66142
|
+
if (ch3.kind === "max") {
|
|
66143
|
+
if (max2 === null || ch3.value < max2)
|
|
66144
|
+
max2 = ch3.value;
|
|
66145
|
+
}
|
|
66146
|
+
}
|
|
66147
|
+
return max2;
|
|
66148
|
+
}
|
|
66149
|
+
}
|
|
66150
|
+
ZodBigInt.create = (params) => {
|
|
66151
|
+
var _a;
|
|
66152
|
+
return new ZodBigInt({
|
|
66153
|
+
checks: [],
|
|
66154
|
+
typeName: ZodFirstPartyTypeKind.ZodBigInt,
|
|
66155
|
+
coerce: (_a = params === null || params === void 0 ? void 0 : params.coerce) !== null && _a !== void 0 ? _a : false,
|
|
66156
|
+
...processCreateParams(params)
|
|
66157
|
+
});
|
|
66158
|
+
};
|
|
66159
|
+
class ZodBoolean extends ZodType {
|
|
66160
|
+
_parse(input) {
|
|
66161
|
+
if (this._def.coerce) {
|
|
66162
|
+
input.data = Boolean(input.data);
|
|
66163
|
+
}
|
|
66164
|
+
const parsedType = this._getType(input);
|
|
66165
|
+
if (parsedType !== ZodParsedType.boolean) {
|
|
66166
|
+
const ctx = this._getOrReturnCtx(input);
|
|
66167
|
+
addIssueToContext(ctx, {
|
|
66168
|
+
code: ZodIssueCode.invalid_type,
|
|
66169
|
+
expected: ZodParsedType.boolean,
|
|
66170
|
+
received: ctx.parsedType
|
|
66171
|
+
});
|
|
66172
|
+
return INVALID;
|
|
66173
|
+
}
|
|
66174
|
+
return OK(input.data);
|
|
66175
|
+
}
|
|
66176
|
+
}
|
|
66177
|
+
ZodBoolean.create = (params) => {
|
|
66178
|
+
return new ZodBoolean({
|
|
66179
|
+
typeName: ZodFirstPartyTypeKind.ZodBoolean,
|
|
66180
|
+
coerce: (params === null || params === void 0 ? void 0 : params.coerce) || false,
|
|
66181
|
+
...processCreateParams(params)
|
|
66182
|
+
});
|
|
66183
|
+
};
|
|
66184
|
+
class ZodDate extends ZodType {
|
|
66185
|
+
_parse(input) {
|
|
66186
|
+
if (this._def.coerce) {
|
|
66187
|
+
input.data = new Date(input.data);
|
|
66188
|
+
}
|
|
66189
|
+
const parsedType = this._getType(input);
|
|
66190
|
+
if (parsedType !== ZodParsedType.date) {
|
|
66191
|
+
const ctx2 = this._getOrReturnCtx(input);
|
|
66192
|
+
addIssueToContext(ctx2, {
|
|
66193
|
+
code: ZodIssueCode.invalid_type,
|
|
66194
|
+
expected: ZodParsedType.date,
|
|
66195
|
+
received: ctx2.parsedType
|
|
66196
|
+
});
|
|
66197
|
+
return INVALID;
|
|
66198
|
+
}
|
|
66199
|
+
if (isNaN(input.data.getTime())) {
|
|
66200
|
+
const ctx2 = this._getOrReturnCtx(input);
|
|
66201
|
+
addIssueToContext(ctx2, {
|
|
66202
|
+
code: ZodIssueCode.invalid_date
|
|
66203
|
+
});
|
|
66204
|
+
return INVALID;
|
|
66205
|
+
}
|
|
66206
|
+
const status = new ParseStatus();
|
|
66207
|
+
let ctx = void 0;
|
|
66208
|
+
for (const check of this._def.checks) {
|
|
66209
|
+
if (check.kind === "min") {
|
|
66210
|
+
if (input.data.getTime() < check.value) {
|
|
66211
|
+
ctx = this._getOrReturnCtx(input, ctx);
|
|
66212
|
+
addIssueToContext(ctx, {
|
|
66213
|
+
code: ZodIssueCode.too_small,
|
|
66214
|
+
message: check.message,
|
|
66215
|
+
inclusive: true,
|
|
66216
|
+
exact: false,
|
|
66217
|
+
minimum: check.value,
|
|
66218
|
+
type: "date"
|
|
66219
|
+
});
|
|
66220
|
+
status.dirty();
|
|
66221
|
+
}
|
|
66222
|
+
} else if (check.kind === "max") {
|
|
66223
|
+
if (input.data.getTime() > check.value) {
|
|
66224
|
+
ctx = this._getOrReturnCtx(input, ctx);
|
|
66225
|
+
addIssueToContext(ctx, {
|
|
66226
|
+
code: ZodIssueCode.too_big,
|
|
66227
|
+
message: check.message,
|
|
66228
|
+
inclusive: true,
|
|
66229
|
+
exact: false,
|
|
66230
|
+
maximum: check.value,
|
|
66231
|
+
type: "date"
|
|
66232
|
+
});
|
|
66233
|
+
status.dirty();
|
|
66234
|
+
}
|
|
66235
|
+
} else {
|
|
66236
|
+
util.assertNever(check);
|
|
66237
|
+
}
|
|
66238
|
+
}
|
|
66239
|
+
return {
|
|
66240
|
+
status: status.value,
|
|
66241
|
+
value: new Date(input.data.getTime())
|
|
66242
|
+
};
|
|
66243
|
+
}
|
|
66244
|
+
_addCheck(check) {
|
|
66245
|
+
return new ZodDate({
|
|
66246
|
+
...this._def,
|
|
66247
|
+
checks: [...this._def.checks, check]
|
|
66248
|
+
});
|
|
66249
|
+
}
|
|
66250
|
+
min(minDate, message) {
|
|
66251
|
+
return this._addCheck({
|
|
66252
|
+
kind: "min",
|
|
66253
|
+
value: minDate.getTime(),
|
|
66254
|
+
message: errorUtil.toString(message)
|
|
66255
|
+
});
|
|
66256
|
+
}
|
|
66257
|
+
max(maxDate, message) {
|
|
66258
|
+
return this._addCheck({
|
|
66259
|
+
kind: "max",
|
|
66260
|
+
value: maxDate.getTime(),
|
|
66261
|
+
message: errorUtil.toString(message)
|
|
66262
|
+
});
|
|
66263
|
+
}
|
|
66264
|
+
get minDate() {
|
|
66265
|
+
let min2 = null;
|
|
66266
|
+
for (const ch3 of this._def.checks) {
|
|
66267
|
+
if (ch3.kind === "min") {
|
|
66268
|
+
if (min2 === null || ch3.value > min2)
|
|
66269
|
+
min2 = ch3.value;
|
|
66270
|
+
}
|
|
66271
|
+
}
|
|
66272
|
+
return min2 != null ? new Date(min2) : null;
|
|
66273
|
+
}
|
|
66274
|
+
get maxDate() {
|
|
66275
|
+
let max2 = null;
|
|
66276
|
+
for (const ch3 of this._def.checks) {
|
|
66277
|
+
if (ch3.kind === "max") {
|
|
66278
|
+
if (max2 === null || ch3.value < max2)
|
|
66279
|
+
max2 = ch3.value;
|
|
66280
|
+
}
|
|
66281
|
+
}
|
|
66282
|
+
return max2 != null ? new Date(max2) : null;
|
|
66283
|
+
}
|
|
66284
|
+
}
|
|
66285
|
+
ZodDate.create = (params) => {
|
|
66286
|
+
return new ZodDate({
|
|
66287
|
+
checks: [],
|
|
66288
|
+
coerce: (params === null || params === void 0 ? void 0 : params.coerce) || false,
|
|
66289
|
+
typeName: ZodFirstPartyTypeKind.ZodDate,
|
|
66290
|
+
...processCreateParams(params)
|
|
66291
|
+
});
|
|
66292
|
+
};
|
|
66293
|
+
class ZodSymbol extends ZodType {
|
|
66294
|
+
_parse(input) {
|
|
66295
|
+
const parsedType = this._getType(input);
|
|
66296
|
+
if (parsedType !== ZodParsedType.symbol) {
|
|
66297
|
+
const ctx = this._getOrReturnCtx(input);
|
|
66298
|
+
addIssueToContext(ctx, {
|
|
66299
|
+
code: ZodIssueCode.invalid_type,
|
|
66300
|
+
expected: ZodParsedType.symbol,
|
|
66301
|
+
received: ctx.parsedType
|
|
66302
|
+
});
|
|
66303
|
+
return INVALID;
|
|
66304
|
+
}
|
|
66305
|
+
return OK(input.data);
|
|
66306
|
+
}
|
|
66307
|
+
}
|
|
66308
|
+
ZodSymbol.create = (params) => {
|
|
66309
|
+
return new ZodSymbol({
|
|
66310
|
+
typeName: ZodFirstPartyTypeKind.ZodSymbol,
|
|
66311
|
+
...processCreateParams(params)
|
|
66312
|
+
});
|
|
66313
|
+
};
|
|
66314
|
+
class ZodUndefined extends ZodType {
|
|
66315
|
+
_parse(input) {
|
|
66316
|
+
const parsedType = this._getType(input);
|
|
66317
|
+
if (parsedType !== ZodParsedType.undefined) {
|
|
66318
|
+
const ctx = this._getOrReturnCtx(input);
|
|
66319
|
+
addIssueToContext(ctx, {
|
|
66320
|
+
code: ZodIssueCode.invalid_type,
|
|
66321
|
+
expected: ZodParsedType.undefined,
|
|
66322
|
+
received: ctx.parsedType
|
|
66323
|
+
});
|
|
66324
|
+
return INVALID;
|
|
66325
|
+
}
|
|
66326
|
+
return OK(input.data);
|
|
66327
|
+
}
|
|
66328
|
+
}
|
|
66329
|
+
ZodUndefined.create = (params) => {
|
|
66330
|
+
return new ZodUndefined({
|
|
66331
|
+
typeName: ZodFirstPartyTypeKind.ZodUndefined,
|
|
66332
|
+
...processCreateParams(params)
|
|
66333
|
+
});
|
|
66334
|
+
};
|
|
66335
|
+
class ZodNull extends ZodType {
|
|
66336
|
+
_parse(input) {
|
|
66337
|
+
const parsedType = this._getType(input);
|
|
66338
|
+
if (parsedType !== ZodParsedType.null) {
|
|
66339
|
+
const ctx = this._getOrReturnCtx(input);
|
|
66340
|
+
addIssueToContext(ctx, {
|
|
66341
|
+
code: ZodIssueCode.invalid_type,
|
|
66342
|
+
expected: ZodParsedType.null,
|
|
66343
|
+
received: ctx.parsedType
|
|
66344
|
+
});
|
|
66345
|
+
return INVALID;
|
|
66346
|
+
}
|
|
66347
|
+
return OK(input.data);
|
|
66348
|
+
}
|
|
66349
|
+
}
|
|
66350
|
+
ZodNull.create = (params) => {
|
|
66351
|
+
return new ZodNull({
|
|
66352
|
+
typeName: ZodFirstPartyTypeKind.ZodNull,
|
|
66353
|
+
...processCreateParams(params)
|
|
66354
|
+
});
|
|
66355
|
+
};
|
|
66356
|
+
class ZodAny extends ZodType {
|
|
66357
|
+
constructor() {
|
|
66358
|
+
super(...arguments);
|
|
66359
|
+
this._any = true;
|
|
66360
|
+
}
|
|
66361
|
+
_parse(input) {
|
|
66362
|
+
return OK(input.data);
|
|
66363
|
+
}
|
|
66364
|
+
}
|
|
66365
|
+
ZodAny.create = (params) => {
|
|
66366
|
+
return new ZodAny({
|
|
66367
|
+
typeName: ZodFirstPartyTypeKind.ZodAny,
|
|
66368
|
+
...processCreateParams(params)
|
|
66369
|
+
});
|
|
66370
|
+
};
|
|
66371
|
+
class ZodUnknown extends ZodType {
|
|
66372
|
+
constructor() {
|
|
66373
|
+
super(...arguments);
|
|
66374
|
+
this._unknown = true;
|
|
66375
|
+
}
|
|
66376
|
+
_parse(input) {
|
|
66377
|
+
return OK(input.data);
|
|
66378
|
+
}
|
|
66379
|
+
}
|
|
66380
|
+
ZodUnknown.create = (params) => {
|
|
66381
|
+
return new ZodUnknown({
|
|
66382
|
+
typeName: ZodFirstPartyTypeKind.ZodUnknown,
|
|
66383
|
+
...processCreateParams(params)
|
|
66384
|
+
});
|
|
66385
|
+
};
|
|
66386
|
+
class ZodNever extends ZodType {
|
|
66387
|
+
_parse(input) {
|
|
66388
|
+
const ctx = this._getOrReturnCtx(input);
|
|
66389
|
+
addIssueToContext(ctx, {
|
|
66390
|
+
code: ZodIssueCode.invalid_type,
|
|
66391
|
+
expected: ZodParsedType.never,
|
|
66392
|
+
received: ctx.parsedType
|
|
66393
|
+
});
|
|
66394
|
+
return INVALID;
|
|
66395
|
+
}
|
|
66396
|
+
}
|
|
66397
|
+
ZodNever.create = (params) => {
|
|
66398
|
+
return new ZodNever({
|
|
66399
|
+
typeName: ZodFirstPartyTypeKind.ZodNever,
|
|
66400
|
+
...processCreateParams(params)
|
|
66401
|
+
});
|
|
66402
|
+
};
|
|
66403
|
+
class ZodVoid extends ZodType {
|
|
66404
|
+
_parse(input) {
|
|
66405
|
+
const parsedType = this._getType(input);
|
|
66406
|
+
if (parsedType !== ZodParsedType.undefined) {
|
|
66407
|
+
const ctx = this._getOrReturnCtx(input);
|
|
66408
|
+
addIssueToContext(ctx, {
|
|
66409
|
+
code: ZodIssueCode.invalid_type,
|
|
66410
|
+
expected: ZodParsedType.void,
|
|
66411
|
+
received: ctx.parsedType
|
|
66412
|
+
});
|
|
66413
|
+
return INVALID;
|
|
66414
|
+
}
|
|
66415
|
+
return OK(input.data);
|
|
66416
|
+
}
|
|
66417
|
+
}
|
|
66418
|
+
ZodVoid.create = (params) => {
|
|
66419
|
+
return new ZodVoid({
|
|
66420
|
+
typeName: ZodFirstPartyTypeKind.ZodVoid,
|
|
66421
|
+
...processCreateParams(params)
|
|
66422
|
+
});
|
|
66423
|
+
};
|
|
66424
|
+
class ZodArray extends ZodType {
|
|
66425
|
+
_parse(input) {
|
|
66426
|
+
const { ctx, status } = this._processInputParams(input);
|
|
66427
|
+
const def = this._def;
|
|
66428
|
+
if (ctx.parsedType !== ZodParsedType.array) {
|
|
66429
|
+
addIssueToContext(ctx, {
|
|
66430
|
+
code: ZodIssueCode.invalid_type,
|
|
66431
|
+
expected: ZodParsedType.array,
|
|
66432
|
+
received: ctx.parsedType
|
|
66433
|
+
});
|
|
66434
|
+
return INVALID;
|
|
66435
|
+
}
|
|
66436
|
+
if (def.exactLength !== null) {
|
|
66437
|
+
const tooBig = ctx.data.length > def.exactLength.value;
|
|
66438
|
+
const tooSmall = ctx.data.length < def.exactLength.value;
|
|
66439
|
+
if (tooBig || tooSmall) {
|
|
66440
|
+
addIssueToContext(ctx, {
|
|
66441
|
+
code: tooBig ? ZodIssueCode.too_big : ZodIssueCode.too_small,
|
|
66442
|
+
minimum: tooSmall ? def.exactLength.value : void 0,
|
|
66443
|
+
maximum: tooBig ? def.exactLength.value : void 0,
|
|
66444
|
+
type: "array",
|
|
66445
|
+
inclusive: true,
|
|
66446
|
+
exact: true,
|
|
66447
|
+
message: def.exactLength.message
|
|
66448
|
+
});
|
|
66449
|
+
status.dirty();
|
|
66450
|
+
}
|
|
66451
|
+
}
|
|
66452
|
+
if (def.minLength !== null) {
|
|
66453
|
+
if (ctx.data.length < def.minLength.value) {
|
|
66454
|
+
addIssueToContext(ctx, {
|
|
66455
|
+
code: ZodIssueCode.too_small,
|
|
66456
|
+
minimum: def.minLength.value,
|
|
66457
|
+
type: "array",
|
|
66458
|
+
inclusive: true,
|
|
66459
|
+
exact: false,
|
|
66460
|
+
message: def.minLength.message
|
|
66461
|
+
});
|
|
66462
|
+
status.dirty();
|
|
66463
|
+
}
|
|
66464
|
+
}
|
|
66465
|
+
if (def.maxLength !== null) {
|
|
66466
|
+
if (ctx.data.length > def.maxLength.value) {
|
|
66467
|
+
addIssueToContext(ctx, {
|
|
66468
|
+
code: ZodIssueCode.too_big,
|
|
66469
|
+
maximum: def.maxLength.value,
|
|
66470
|
+
type: "array",
|
|
66471
|
+
inclusive: true,
|
|
66472
|
+
exact: false,
|
|
66473
|
+
message: def.maxLength.message
|
|
66474
|
+
});
|
|
66475
|
+
status.dirty();
|
|
66476
|
+
}
|
|
66477
|
+
}
|
|
66478
|
+
if (ctx.common.async) {
|
|
66479
|
+
return Promise.all([...ctx.data].map((item, i) => {
|
|
66480
|
+
return def.type._parseAsync(new ParseInputLazyPath(ctx, item, ctx.path, i));
|
|
66481
|
+
})).then((result3) => {
|
|
66482
|
+
return ParseStatus.mergeArray(status, result3);
|
|
66483
|
+
});
|
|
66484
|
+
}
|
|
66485
|
+
const result2 = [...ctx.data].map((item, i) => {
|
|
66486
|
+
return def.type._parseSync(new ParseInputLazyPath(ctx, item, ctx.path, i));
|
|
66487
|
+
});
|
|
66488
|
+
return ParseStatus.mergeArray(status, result2);
|
|
66489
|
+
}
|
|
66490
|
+
get element() {
|
|
66491
|
+
return this._def.type;
|
|
66492
|
+
}
|
|
66493
|
+
min(minLength, message) {
|
|
66494
|
+
return new ZodArray({
|
|
66495
|
+
...this._def,
|
|
66496
|
+
minLength: { value: minLength, message: errorUtil.toString(message) }
|
|
66497
|
+
});
|
|
66498
|
+
}
|
|
66499
|
+
max(maxLength, message) {
|
|
66500
|
+
return new ZodArray({
|
|
66501
|
+
...this._def,
|
|
66502
|
+
maxLength: { value: maxLength, message: errorUtil.toString(message) }
|
|
66503
|
+
});
|
|
66504
|
+
}
|
|
66505
|
+
length(len, message) {
|
|
66506
|
+
return new ZodArray({
|
|
66507
|
+
...this._def,
|
|
66508
|
+
exactLength: { value: len, message: errorUtil.toString(message) }
|
|
66509
|
+
});
|
|
66510
|
+
}
|
|
66511
|
+
nonempty(message) {
|
|
66512
|
+
return this.min(1, message);
|
|
66513
|
+
}
|
|
66514
|
+
}
|
|
66515
|
+
ZodArray.create = (schema, params) => {
|
|
66516
|
+
return new ZodArray({
|
|
66517
|
+
type: schema,
|
|
66518
|
+
minLength: null,
|
|
66519
|
+
maxLength: null,
|
|
66520
|
+
exactLength: null,
|
|
66521
|
+
typeName: ZodFirstPartyTypeKind.ZodArray,
|
|
66522
|
+
...processCreateParams(params)
|
|
66523
|
+
});
|
|
66524
|
+
};
|
|
66525
|
+
function deepPartialify(schema) {
|
|
66526
|
+
if (schema instanceof ZodObject) {
|
|
66527
|
+
const newShape = {};
|
|
66528
|
+
for (const key in schema.shape) {
|
|
66529
|
+
const fieldSchema = schema.shape[key];
|
|
66530
|
+
newShape[key] = ZodOptional.create(deepPartialify(fieldSchema));
|
|
66531
|
+
}
|
|
66532
|
+
return new ZodObject({
|
|
66533
|
+
...schema._def,
|
|
66534
|
+
shape: () => newShape
|
|
66535
|
+
});
|
|
66536
|
+
} else if (schema instanceof ZodArray) {
|
|
66537
|
+
return new ZodArray({
|
|
66538
|
+
...schema._def,
|
|
66539
|
+
type: deepPartialify(schema.element)
|
|
66540
|
+
});
|
|
66541
|
+
} else if (schema instanceof ZodOptional) {
|
|
66542
|
+
return ZodOptional.create(deepPartialify(schema.unwrap()));
|
|
66543
|
+
} else if (schema instanceof ZodNullable) {
|
|
66544
|
+
return ZodNullable.create(deepPartialify(schema.unwrap()));
|
|
66545
|
+
} else if (schema instanceof ZodTuple) {
|
|
66546
|
+
return ZodTuple.create(schema.items.map((item) => deepPartialify(item)));
|
|
66547
|
+
} else {
|
|
66548
|
+
return schema;
|
|
66549
|
+
}
|
|
66550
|
+
}
|
|
66551
|
+
class ZodObject extends ZodType {
|
|
66552
|
+
constructor() {
|
|
66553
|
+
super(...arguments);
|
|
66554
|
+
this._cached = null;
|
|
66555
|
+
this.nonstrict = this.passthrough;
|
|
66556
|
+
this.augment = this.extend;
|
|
66557
|
+
}
|
|
66558
|
+
_getCached() {
|
|
66559
|
+
if (this._cached !== null)
|
|
66560
|
+
return this._cached;
|
|
66561
|
+
const shape = this._def.shape();
|
|
66562
|
+
const keys = util.objectKeys(shape);
|
|
66563
|
+
return this._cached = { shape, keys };
|
|
66564
|
+
}
|
|
66565
|
+
_parse(input) {
|
|
66566
|
+
const parsedType = this._getType(input);
|
|
66567
|
+
if (parsedType !== ZodParsedType.object) {
|
|
66568
|
+
const ctx2 = this._getOrReturnCtx(input);
|
|
66569
|
+
addIssueToContext(ctx2, {
|
|
66570
|
+
code: ZodIssueCode.invalid_type,
|
|
66571
|
+
expected: ZodParsedType.object,
|
|
66572
|
+
received: ctx2.parsedType
|
|
66573
|
+
});
|
|
66574
|
+
return INVALID;
|
|
66575
|
+
}
|
|
66576
|
+
const { status, ctx } = this._processInputParams(input);
|
|
66577
|
+
const { shape, keys: shapeKeys } = this._getCached();
|
|
66578
|
+
const extraKeys = [];
|
|
66579
|
+
if (!(this._def.catchall instanceof ZodNever && this._def.unknownKeys === "strip")) {
|
|
66580
|
+
for (const key in ctx.data) {
|
|
66581
|
+
if (!shapeKeys.includes(key)) {
|
|
66582
|
+
extraKeys.push(key);
|
|
66583
|
+
}
|
|
66584
|
+
}
|
|
66585
|
+
}
|
|
66586
|
+
const pairs = [];
|
|
66587
|
+
for (const key of shapeKeys) {
|
|
66588
|
+
const keyValidator = shape[key];
|
|
66589
|
+
const value = ctx.data[key];
|
|
66590
|
+
pairs.push({
|
|
66591
|
+
key: { status: "valid", value: key },
|
|
66592
|
+
value: keyValidator._parse(new ParseInputLazyPath(ctx, value, ctx.path, key)),
|
|
66593
|
+
alwaysSet: key in ctx.data
|
|
66594
|
+
});
|
|
66595
|
+
}
|
|
66596
|
+
if (this._def.catchall instanceof ZodNever) {
|
|
66597
|
+
const unknownKeys = this._def.unknownKeys;
|
|
66598
|
+
if (unknownKeys === "passthrough") {
|
|
66599
|
+
for (const key of extraKeys) {
|
|
66600
|
+
pairs.push({
|
|
66601
|
+
key: { status: "valid", value: key },
|
|
66602
|
+
value: { status: "valid", value: ctx.data[key] }
|
|
66603
|
+
});
|
|
66604
|
+
}
|
|
66605
|
+
} else if (unknownKeys === "strict") {
|
|
66606
|
+
if (extraKeys.length > 0) {
|
|
66607
|
+
addIssueToContext(ctx, {
|
|
66608
|
+
code: ZodIssueCode.unrecognized_keys,
|
|
66609
|
+
keys: extraKeys
|
|
66610
|
+
});
|
|
66611
|
+
status.dirty();
|
|
66612
|
+
}
|
|
66613
|
+
} else if (unknownKeys === "strip")
|
|
66614
|
+
;
|
|
66615
|
+
else {
|
|
66616
|
+
throw new Error(`Internal ZodObject error: invalid unknownKeys value.`);
|
|
66617
|
+
}
|
|
66618
|
+
} else {
|
|
66619
|
+
const catchall = this._def.catchall;
|
|
66620
|
+
for (const key of extraKeys) {
|
|
66621
|
+
const value = ctx.data[key];
|
|
66622
|
+
pairs.push({
|
|
66623
|
+
key: { status: "valid", value: key },
|
|
66624
|
+
value: catchall._parse(
|
|
66625
|
+
new ParseInputLazyPath(ctx, value, ctx.path, key)
|
|
66626
|
+
//, ctx.child(key), value, getParsedType(value)
|
|
66627
|
+
),
|
|
66628
|
+
alwaysSet: key in ctx.data
|
|
66629
|
+
});
|
|
66630
|
+
}
|
|
66631
|
+
}
|
|
66632
|
+
if (ctx.common.async) {
|
|
66633
|
+
return Promise.resolve().then(async () => {
|
|
66634
|
+
const syncPairs = [];
|
|
66635
|
+
for (const pair of pairs) {
|
|
66636
|
+
const key = await pair.key;
|
|
66637
|
+
syncPairs.push({
|
|
66638
|
+
key,
|
|
66639
|
+
value: await pair.value,
|
|
66640
|
+
alwaysSet: pair.alwaysSet
|
|
66641
|
+
});
|
|
66642
|
+
}
|
|
66643
|
+
return syncPairs;
|
|
66644
|
+
}).then((syncPairs) => {
|
|
66645
|
+
return ParseStatus.mergeObjectSync(status, syncPairs);
|
|
66646
|
+
});
|
|
66647
|
+
} else {
|
|
66648
|
+
return ParseStatus.mergeObjectSync(status, pairs);
|
|
66649
|
+
}
|
|
66650
|
+
}
|
|
66651
|
+
get shape() {
|
|
66652
|
+
return this._def.shape();
|
|
66653
|
+
}
|
|
66654
|
+
strict(message) {
|
|
66655
|
+
errorUtil.errToObj;
|
|
66656
|
+
return new ZodObject({
|
|
66657
|
+
...this._def,
|
|
66658
|
+
unknownKeys: "strict",
|
|
66659
|
+
...message !== void 0 ? {
|
|
66660
|
+
errorMap: (issue, ctx) => {
|
|
66661
|
+
var _a, _b, _c, _d;
|
|
66662
|
+
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;
|
|
66663
|
+
if (issue.code === "unrecognized_keys")
|
|
66664
|
+
return {
|
|
66665
|
+
message: (_d = errorUtil.errToObj(message).message) !== null && _d !== void 0 ? _d : defaultError
|
|
66666
|
+
};
|
|
66667
|
+
return {
|
|
66668
|
+
message: defaultError
|
|
66669
|
+
};
|
|
66670
|
+
}
|
|
66671
|
+
} : {}
|
|
66672
|
+
});
|
|
66673
|
+
}
|
|
66674
|
+
strip() {
|
|
66675
|
+
return new ZodObject({
|
|
66676
|
+
...this._def,
|
|
66677
|
+
unknownKeys: "strip"
|
|
66678
|
+
});
|
|
66679
|
+
}
|
|
66680
|
+
passthrough() {
|
|
66681
|
+
return new ZodObject({
|
|
66682
|
+
...this._def,
|
|
66683
|
+
unknownKeys: "passthrough"
|
|
66684
|
+
});
|
|
66685
|
+
}
|
|
66686
|
+
// const AugmentFactory =
|
|
66687
|
+
// <Def extends ZodObjectDef>(def: Def) =>
|
|
66688
|
+
// <Augmentation extends ZodRawShape>(
|
|
66689
|
+
// augmentation: Augmentation
|
|
66690
|
+
// ): ZodObject<
|
|
66691
|
+
// extendShape<ReturnType<Def["shape"]>, Augmentation>,
|
|
66692
|
+
// Def["unknownKeys"],
|
|
66693
|
+
// Def["catchall"]
|
|
66694
|
+
// > => {
|
|
66695
|
+
// return new ZodObject({
|
|
66696
|
+
// ...def,
|
|
66697
|
+
// shape: () => ({
|
|
66698
|
+
// ...def.shape(),
|
|
66699
|
+
// ...augmentation,
|
|
66700
|
+
// }),
|
|
66701
|
+
// }) as any;
|
|
66702
|
+
// };
|
|
66703
|
+
extend(augmentation) {
|
|
66704
|
+
return new ZodObject({
|
|
66705
|
+
...this._def,
|
|
66706
|
+
shape: () => ({
|
|
66707
|
+
...this._def.shape(),
|
|
66708
|
+
...augmentation
|
|
66709
|
+
})
|
|
66710
|
+
});
|
|
66711
|
+
}
|
|
66712
|
+
/**
|
|
66713
|
+
* Prior to zod@1.0.12 there was a bug in the
|
|
66714
|
+
* inferred type of merged objects. Please
|
|
66715
|
+
* upgrade if you are experiencing issues.
|
|
66716
|
+
*/
|
|
66717
|
+
merge(merging) {
|
|
66718
|
+
const merged = new ZodObject({
|
|
66719
|
+
unknownKeys: merging._def.unknownKeys,
|
|
66720
|
+
catchall: merging._def.catchall,
|
|
66721
|
+
shape: () => ({
|
|
66722
|
+
...this._def.shape(),
|
|
66723
|
+
...merging._def.shape()
|
|
66724
|
+
}),
|
|
66725
|
+
typeName: ZodFirstPartyTypeKind.ZodObject
|
|
66726
|
+
});
|
|
66727
|
+
return merged;
|
|
66728
|
+
}
|
|
66729
|
+
// merge<
|
|
66730
|
+
// Incoming extends AnyZodObject,
|
|
66731
|
+
// Augmentation extends Incoming["shape"],
|
|
66732
|
+
// NewOutput extends {
|
|
66733
|
+
// [k in keyof Augmentation | keyof Output]: k extends keyof Augmentation
|
|
66734
|
+
// ? Augmentation[k]["_output"]
|
|
66735
|
+
// : k extends keyof Output
|
|
66736
|
+
// ? Output[k]
|
|
66737
|
+
// : never;
|
|
66738
|
+
// },
|
|
66739
|
+
// NewInput extends {
|
|
66740
|
+
// [k in keyof Augmentation | keyof Input]: k extends keyof Augmentation
|
|
66741
|
+
// ? Augmentation[k]["_input"]
|
|
66742
|
+
// : k extends keyof Input
|
|
66743
|
+
// ? Input[k]
|
|
66744
|
+
// : never;
|
|
66745
|
+
// }
|
|
66746
|
+
// >(
|
|
66747
|
+
// merging: Incoming
|
|
66748
|
+
// ): ZodObject<
|
|
66749
|
+
// extendShape<T, ReturnType<Incoming["_def"]["shape"]>>,
|
|
66750
|
+
// Incoming["_def"]["unknownKeys"],
|
|
66751
|
+
// Incoming["_def"]["catchall"],
|
|
66752
|
+
// NewOutput,
|
|
66753
|
+
// NewInput
|
|
66754
|
+
// > {
|
|
66755
|
+
// const merged: any = new ZodObject({
|
|
66756
|
+
// unknownKeys: merging._def.unknownKeys,
|
|
66757
|
+
// catchall: merging._def.catchall,
|
|
66758
|
+
// shape: () =>
|
|
66759
|
+
// objectUtil.mergeShapes(this._def.shape(), merging._def.shape()),
|
|
66760
|
+
// typeName: ZodFirstPartyTypeKind.ZodObject,
|
|
66761
|
+
// }) as any;
|
|
66762
|
+
// return merged;
|
|
66763
|
+
// }
|
|
66764
|
+
setKey(key, schema) {
|
|
66765
|
+
return this.augment({ [key]: schema });
|
|
66766
|
+
}
|
|
66767
|
+
// merge<Incoming extends AnyZodObject>(
|
|
66768
|
+
// merging: Incoming
|
|
66769
|
+
// ): //ZodObject<T & Incoming["_shape"], UnknownKeys, Catchall> = (merging) => {
|
|
66770
|
+
// ZodObject<
|
|
66771
|
+
// extendShape<T, ReturnType<Incoming["_def"]["shape"]>>,
|
|
66772
|
+
// Incoming["_def"]["unknownKeys"],
|
|
66773
|
+
// Incoming["_def"]["catchall"]
|
|
66774
|
+
// > {
|
|
66775
|
+
// // const mergedShape = objectUtil.mergeShapes(
|
|
66776
|
+
// // this._def.shape(),
|
|
66777
|
+
// // merging._def.shape()
|
|
66778
|
+
// // );
|
|
66779
|
+
// const merged: any = new ZodObject({
|
|
66780
|
+
// unknownKeys: merging._def.unknownKeys,
|
|
66781
|
+
// catchall: merging._def.catchall,
|
|
66782
|
+
// shape: () =>
|
|
66783
|
+
// objectUtil.mergeShapes(this._def.shape(), merging._def.shape()),
|
|
66784
|
+
// typeName: ZodFirstPartyTypeKind.ZodObject,
|
|
66785
|
+
// }) as any;
|
|
66786
|
+
// return merged;
|
|
66787
|
+
// }
|
|
66788
|
+
catchall(index2) {
|
|
66789
|
+
return new ZodObject({
|
|
66790
|
+
...this._def,
|
|
66791
|
+
catchall: index2
|
|
66792
|
+
});
|
|
66793
|
+
}
|
|
66794
|
+
pick(mask) {
|
|
66795
|
+
const shape = {};
|
|
66796
|
+
util.objectKeys(mask).forEach((key) => {
|
|
66797
|
+
if (mask[key] && this.shape[key]) {
|
|
66798
|
+
shape[key] = this.shape[key];
|
|
66799
|
+
}
|
|
66800
|
+
});
|
|
66801
|
+
return new ZodObject({
|
|
66802
|
+
...this._def,
|
|
66803
|
+
shape: () => shape
|
|
66804
|
+
});
|
|
66805
|
+
}
|
|
66806
|
+
omit(mask) {
|
|
66807
|
+
const shape = {};
|
|
66808
|
+
util.objectKeys(this.shape).forEach((key) => {
|
|
66809
|
+
if (!mask[key]) {
|
|
66810
|
+
shape[key] = this.shape[key];
|
|
66811
|
+
}
|
|
66812
|
+
});
|
|
66813
|
+
return new ZodObject({
|
|
66814
|
+
...this._def,
|
|
66815
|
+
shape: () => shape
|
|
66816
|
+
});
|
|
66817
|
+
}
|
|
66818
|
+
/**
|
|
66819
|
+
* @deprecated
|
|
66820
|
+
*/
|
|
66821
|
+
deepPartial() {
|
|
66822
|
+
return deepPartialify(this);
|
|
66823
|
+
}
|
|
66824
|
+
partial(mask) {
|
|
66825
|
+
const newShape = {};
|
|
66826
|
+
util.objectKeys(this.shape).forEach((key) => {
|
|
66827
|
+
const fieldSchema = this.shape[key];
|
|
66828
|
+
if (mask && !mask[key]) {
|
|
66829
|
+
newShape[key] = fieldSchema;
|
|
66830
|
+
} else {
|
|
66831
|
+
newShape[key] = fieldSchema.optional();
|
|
66832
|
+
}
|
|
66833
|
+
});
|
|
66834
|
+
return new ZodObject({
|
|
66835
|
+
...this._def,
|
|
66836
|
+
shape: () => newShape
|
|
66837
|
+
});
|
|
66838
|
+
}
|
|
66839
|
+
required(mask) {
|
|
66840
|
+
const newShape = {};
|
|
66841
|
+
util.objectKeys(this.shape).forEach((key) => {
|
|
66842
|
+
if (mask && !mask[key]) {
|
|
66843
|
+
newShape[key] = this.shape[key];
|
|
66844
|
+
} else {
|
|
66845
|
+
const fieldSchema = this.shape[key];
|
|
66846
|
+
let newField = fieldSchema;
|
|
66847
|
+
while (newField instanceof ZodOptional) {
|
|
66848
|
+
newField = newField._def.innerType;
|
|
66849
|
+
}
|
|
66850
|
+
newShape[key] = newField;
|
|
66851
|
+
}
|
|
66852
|
+
});
|
|
66853
|
+
return new ZodObject({
|
|
66854
|
+
...this._def,
|
|
66855
|
+
shape: () => newShape
|
|
66856
|
+
});
|
|
66857
|
+
}
|
|
66858
|
+
keyof() {
|
|
66859
|
+
return createZodEnum(util.objectKeys(this.shape));
|
|
66860
|
+
}
|
|
66861
|
+
}
|
|
66862
|
+
ZodObject.create = (shape, params) => {
|
|
66863
|
+
return new ZodObject({
|
|
66864
|
+
shape: () => shape,
|
|
66865
|
+
unknownKeys: "strip",
|
|
66866
|
+
catchall: ZodNever.create(),
|
|
66867
|
+
typeName: ZodFirstPartyTypeKind.ZodObject,
|
|
66868
|
+
...processCreateParams(params)
|
|
66869
|
+
});
|
|
66870
|
+
};
|
|
66871
|
+
ZodObject.strictCreate = (shape, params) => {
|
|
66872
|
+
return new ZodObject({
|
|
66873
|
+
shape: () => shape,
|
|
66874
|
+
unknownKeys: "strict",
|
|
66875
|
+
catchall: ZodNever.create(),
|
|
66876
|
+
typeName: ZodFirstPartyTypeKind.ZodObject,
|
|
66877
|
+
...processCreateParams(params)
|
|
66878
|
+
});
|
|
66879
|
+
};
|
|
66880
|
+
ZodObject.lazycreate = (shape, params) => {
|
|
66881
|
+
return new ZodObject({
|
|
66882
|
+
shape,
|
|
66883
|
+
unknownKeys: "strip",
|
|
66884
|
+
catchall: ZodNever.create(),
|
|
66885
|
+
typeName: ZodFirstPartyTypeKind.ZodObject,
|
|
66886
|
+
...processCreateParams(params)
|
|
66887
|
+
});
|
|
66888
|
+
};
|
|
66889
|
+
class ZodUnion extends ZodType {
|
|
66890
|
+
_parse(input) {
|
|
66891
|
+
const { ctx } = this._processInputParams(input);
|
|
66892
|
+
const options = this._def.options;
|
|
66893
|
+
function handleResults(results) {
|
|
66894
|
+
for (const result2 of results) {
|
|
66895
|
+
if (result2.result.status === "valid") {
|
|
66896
|
+
return result2.result;
|
|
66897
|
+
}
|
|
66898
|
+
}
|
|
66899
|
+
for (const result2 of results) {
|
|
66900
|
+
if (result2.result.status === "dirty") {
|
|
66901
|
+
ctx.common.issues.push(...result2.ctx.common.issues);
|
|
66902
|
+
return result2.result;
|
|
66903
|
+
}
|
|
66904
|
+
}
|
|
66905
|
+
const unionErrors = results.map((result2) => new ZodError(result2.ctx.common.issues));
|
|
66906
|
+
addIssueToContext(ctx, {
|
|
66907
|
+
code: ZodIssueCode.invalid_union,
|
|
66908
|
+
unionErrors
|
|
66909
|
+
});
|
|
66910
|
+
return INVALID;
|
|
66911
|
+
}
|
|
66912
|
+
if (ctx.common.async) {
|
|
66913
|
+
return Promise.all(options.map(async (option) => {
|
|
66914
|
+
const childCtx = {
|
|
66915
|
+
...ctx,
|
|
66916
|
+
common: {
|
|
66917
|
+
...ctx.common,
|
|
66918
|
+
issues: []
|
|
66919
|
+
},
|
|
66920
|
+
parent: null
|
|
66921
|
+
};
|
|
66922
|
+
return {
|
|
66923
|
+
result: await option._parseAsync({
|
|
66924
|
+
data: ctx.data,
|
|
66925
|
+
path: ctx.path,
|
|
66926
|
+
parent: childCtx
|
|
66927
|
+
}),
|
|
66928
|
+
ctx: childCtx
|
|
66929
|
+
};
|
|
66930
|
+
})).then(handleResults);
|
|
66931
|
+
} else {
|
|
66932
|
+
let dirty = void 0;
|
|
66933
|
+
const issues = [];
|
|
66934
|
+
for (const option of options) {
|
|
66935
|
+
const childCtx = {
|
|
66936
|
+
...ctx,
|
|
66937
|
+
common: {
|
|
66938
|
+
...ctx.common,
|
|
66939
|
+
issues: []
|
|
66940
|
+
},
|
|
66941
|
+
parent: null
|
|
66942
|
+
};
|
|
66943
|
+
const result2 = option._parseSync({
|
|
66944
|
+
data: ctx.data,
|
|
66945
|
+
path: ctx.path,
|
|
66946
|
+
parent: childCtx
|
|
66947
|
+
});
|
|
66948
|
+
if (result2.status === "valid") {
|
|
66949
|
+
return result2;
|
|
66950
|
+
} else if (result2.status === "dirty" && !dirty) {
|
|
66951
|
+
dirty = { result: result2, ctx: childCtx };
|
|
66952
|
+
}
|
|
66953
|
+
if (childCtx.common.issues.length) {
|
|
66954
|
+
issues.push(childCtx.common.issues);
|
|
66955
|
+
}
|
|
66956
|
+
}
|
|
66957
|
+
if (dirty) {
|
|
66958
|
+
ctx.common.issues.push(...dirty.ctx.common.issues);
|
|
66959
|
+
return dirty.result;
|
|
66960
|
+
}
|
|
66961
|
+
const unionErrors = issues.map((issues2) => new ZodError(issues2));
|
|
66962
|
+
addIssueToContext(ctx, {
|
|
66963
|
+
code: ZodIssueCode.invalid_union,
|
|
66964
|
+
unionErrors
|
|
66965
|
+
});
|
|
66966
|
+
return INVALID;
|
|
66967
|
+
}
|
|
66968
|
+
}
|
|
66969
|
+
get options() {
|
|
66970
|
+
return this._def.options;
|
|
66971
|
+
}
|
|
66972
|
+
}
|
|
66973
|
+
ZodUnion.create = (types, params) => {
|
|
66974
|
+
return new ZodUnion({
|
|
66975
|
+
options: types,
|
|
66976
|
+
typeName: ZodFirstPartyTypeKind.ZodUnion,
|
|
66977
|
+
...processCreateParams(params)
|
|
66978
|
+
});
|
|
66979
|
+
};
|
|
66980
|
+
const getDiscriminator = (type) => {
|
|
66981
|
+
if (type instanceof ZodLazy) {
|
|
66982
|
+
return getDiscriminator(type.schema);
|
|
66983
|
+
} else if (type instanceof ZodEffects) {
|
|
66984
|
+
return getDiscriminator(type.innerType());
|
|
66985
|
+
} else if (type instanceof ZodLiteral) {
|
|
66986
|
+
return [type.value];
|
|
66987
|
+
} else if (type instanceof ZodEnum) {
|
|
66988
|
+
return type.options;
|
|
66989
|
+
} else if (type instanceof ZodNativeEnum) {
|
|
66990
|
+
return Object.keys(type.enum);
|
|
66991
|
+
} else if (type instanceof ZodDefault) {
|
|
66992
|
+
return getDiscriminator(type._def.innerType);
|
|
66993
|
+
} else if (type instanceof ZodUndefined) {
|
|
66994
|
+
return [void 0];
|
|
66995
|
+
} else if (type instanceof ZodNull) {
|
|
66996
|
+
return [null];
|
|
66997
|
+
} else {
|
|
66998
|
+
return null;
|
|
66999
|
+
}
|
|
67000
|
+
};
|
|
67001
|
+
class ZodDiscriminatedUnion extends ZodType {
|
|
67002
|
+
_parse(input) {
|
|
67003
|
+
const { ctx } = this._processInputParams(input);
|
|
67004
|
+
if (ctx.parsedType !== ZodParsedType.object) {
|
|
67005
|
+
addIssueToContext(ctx, {
|
|
67006
|
+
code: ZodIssueCode.invalid_type,
|
|
67007
|
+
expected: ZodParsedType.object,
|
|
67008
|
+
received: ctx.parsedType
|
|
67009
|
+
});
|
|
67010
|
+
return INVALID;
|
|
67011
|
+
}
|
|
67012
|
+
const discriminator = this.discriminator;
|
|
67013
|
+
const discriminatorValue = ctx.data[discriminator];
|
|
67014
|
+
const option = this.optionsMap.get(discriminatorValue);
|
|
67015
|
+
if (!option) {
|
|
67016
|
+
addIssueToContext(ctx, {
|
|
67017
|
+
code: ZodIssueCode.invalid_union_discriminator,
|
|
67018
|
+
options: Array.from(this.optionsMap.keys()),
|
|
67019
|
+
path: [discriminator]
|
|
67020
|
+
});
|
|
67021
|
+
return INVALID;
|
|
67022
|
+
}
|
|
67023
|
+
if (ctx.common.async) {
|
|
67024
|
+
return option._parseAsync({
|
|
67025
|
+
data: ctx.data,
|
|
67026
|
+
path: ctx.path,
|
|
67027
|
+
parent: ctx
|
|
67028
|
+
});
|
|
67029
|
+
} else {
|
|
67030
|
+
return option._parseSync({
|
|
67031
|
+
data: ctx.data,
|
|
67032
|
+
path: ctx.path,
|
|
67033
|
+
parent: ctx
|
|
67034
|
+
});
|
|
67035
|
+
}
|
|
67036
|
+
}
|
|
67037
|
+
get discriminator() {
|
|
67038
|
+
return this._def.discriminator;
|
|
67039
|
+
}
|
|
67040
|
+
get options() {
|
|
67041
|
+
return this._def.options;
|
|
67042
|
+
}
|
|
67043
|
+
get optionsMap() {
|
|
67044
|
+
return this._def.optionsMap;
|
|
67045
|
+
}
|
|
67046
|
+
/**
|
|
67047
|
+
* The constructor of the discriminated union schema. Its behaviour is very similar to that of the normal z.union() constructor.
|
|
67048
|
+
* However, it only allows a union of objects, all of which need to share a discriminator property. This property must
|
|
67049
|
+
* have a different value for each object in the union.
|
|
67050
|
+
* @param discriminator the name of the discriminator property
|
|
67051
|
+
* @param types an array of object schemas
|
|
67052
|
+
* @param params
|
|
67053
|
+
*/
|
|
67054
|
+
static create(discriminator, options, params) {
|
|
67055
|
+
const optionsMap = /* @__PURE__ */ new Map();
|
|
67056
|
+
for (const type of options) {
|
|
67057
|
+
const discriminatorValues = getDiscriminator(type.shape[discriminator]);
|
|
67058
|
+
if (!discriminatorValues) {
|
|
67059
|
+
throw new Error(`A discriminator value for key \`${discriminator}\` could not be extracted from all schema options`);
|
|
67060
|
+
}
|
|
67061
|
+
for (const value of discriminatorValues) {
|
|
67062
|
+
if (optionsMap.has(value)) {
|
|
67063
|
+
throw new Error(`Discriminator property ${String(discriminator)} has duplicate value ${String(value)}`);
|
|
67064
|
+
}
|
|
67065
|
+
optionsMap.set(value, type);
|
|
67066
|
+
}
|
|
67067
|
+
}
|
|
67068
|
+
return new ZodDiscriminatedUnion({
|
|
67069
|
+
typeName: ZodFirstPartyTypeKind.ZodDiscriminatedUnion,
|
|
67070
|
+
discriminator,
|
|
67071
|
+
options,
|
|
67072
|
+
optionsMap,
|
|
67073
|
+
...processCreateParams(params)
|
|
67074
|
+
});
|
|
67075
|
+
}
|
|
67076
|
+
}
|
|
67077
|
+
function mergeValues(a, b) {
|
|
67078
|
+
const aType = getParsedType(a);
|
|
67079
|
+
const bType = getParsedType(b);
|
|
67080
|
+
if (a === b) {
|
|
67081
|
+
return { valid: true, data: a };
|
|
67082
|
+
} else if (aType === ZodParsedType.object && bType === ZodParsedType.object) {
|
|
67083
|
+
const bKeys = util.objectKeys(b);
|
|
67084
|
+
const sharedKeys = util.objectKeys(a).filter((key) => bKeys.indexOf(key) !== -1);
|
|
67085
|
+
const newObj = { ...a, ...b };
|
|
67086
|
+
for (const key of sharedKeys) {
|
|
67087
|
+
const sharedValue = mergeValues(a[key], b[key]);
|
|
67088
|
+
if (!sharedValue.valid) {
|
|
67089
|
+
return { valid: false };
|
|
67090
|
+
}
|
|
67091
|
+
newObj[key] = sharedValue.data;
|
|
67092
|
+
}
|
|
67093
|
+
return { valid: true, data: newObj };
|
|
67094
|
+
} else if (aType === ZodParsedType.array && bType === ZodParsedType.array) {
|
|
67095
|
+
if (a.length !== b.length) {
|
|
67096
|
+
return { valid: false };
|
|
67097
|
+
}
|
|
67098
|
+
const newArray = [];
|
|
67099
|
+
for (let index2 = 0; index2 < a.length; index2++) {
|
|
67100
|
+
const itemA = a[index2];
|
|
67101
|
+
const itemB = b[index2];
|
|
67102
|
+
const sharedValue = mergeValues(itemA, itemB);
|
|
67103
|
+
if (!sharedValue.valid) {
|
|
67104
|
+
return { valid: false };
|
|
67105
|
+
}
|
|
67106
|
+
newArray.push(sharedValue.data);
|
|
67107
|
+
}
|
|
67108
|
+
return { valid: true, data: newArray };
|
|
67109
|
+
} else if (aType === ZodParsedType.date && bType === ZodParsedType.date && +a === +b) {
|
|
67110
|
+
return { valid: true, data: a };
|
|
67111
|
+
} else {
|
|
67112
|
+
return { valid: false };
|
|
67113
|
+
}
|
|
67114
|
+
}
|
|
67115
|
+
class ZodIntersection extends ZodType {
|
|
67116
|
+
_parse(input) {
|
|
67117
|
+
const { status, ctx } = this._processInputParams(input);
|
|
67118
|
+
const handleParsed = (parsedLeft, parsedRight) => {
|
|
67119
|
+
if (isAborted(parsedLeft) || isAborted(parsedRight)) {
|
|
67120
|
+
return INVALID;
|
|
67121
|
+
}
|
|
67122
|
+
const merged = mergeValues(parsedLeft.value, parsedRight.value);
|
|
67123
|
+
if (!merged.valid) {
|
|
67124
|
+
addIssueToContext(ctx, {
|
|
67125
|
+
code: ZodIssueCode.invalid_intersection_types
|
|
67126
|
+
});
|
|
67127
|
+
return INVALID;
|
|
67128
|
+
}
|
|
67129
|
+
if (isDirty(parsedLeft) || isDirty(parsedRight)) {
|
|
67130
|
+
status.dirty();
|
|
67131
|
+
}
|
|
67132
|
+
return { status: status.value, value: merged.data };
|
|
67133
|
+
};
|
|
67134
|
+
if (ctx.common.async) {
|
|
67135
|
+
return Promise.all([
|
|
67136
|
+
this._def.left._parseAsync({
|
|
67137
|
+
data: ctx.data,
|
|
67138
|
+
path: ctx.path,
|
|
67139
|
+
parent: ctx
|
|
67140
|
+
}),
|
|
67141
|
+
this._def.right._parseAsync({
|
|
67142
|
+
data: ctx.data,
|
|
67143
|
+
path: ctx.path,
|
|
67144
|
+
parent: ctx
|
|
67145
|
+
})
|
|
67146
|
+
]).then(([left, right]) => handleParsed(left, right));
|
|
67147
|
+
} else {
|
|
67148
|
+
return handleParsed(this._def.left._parseSync({
|
|
67149
|
+
data: ctx.data,
|
|
67150
|
+
path: ctx.path,
|
|
67151
|
+
parent: ctx
|
|
67152
|
+
}), this._def.right._parseSync({
|
|
67153
|
+
data: ctx.data,
|
|
67154
|
+
path: ctx.path,
|
|
67155
|
+
parent: ctx
|
|
67156
|
+
}));
|
|
67157
|
+
}
|
|
67158
|
+
}
|
|
67159
|
+
}
|
|
67160
|
+
ZodIntersection.create = (left, right, params) => {
|
|
67161
|
+
return new ZodIntersection({
|
|
67162
|
+
left,
|
|
67163
|
+
right,
|
|
67164
|
+
typeName: ZodFirstPartyTypeKind.ZodIntersection,
|
|
67165
|
+
...processCreateParams(params)
|
|
67166
|
+
});
|
|
67167
|
+
};
|
|
67168
|
+
class ZodTuple extends ZodType {
|
|
67169
|
+
_parse(input) {
|
|
67170
|
+
const { status, ctx } = this._processInputParams(input);
|
|
67171
|
+
if (ctx.parsedType !== ZodParsedType.array) {
|
|
67172
|
+
addIssueToContext(ctx, {
|
|
67173
|
+
code: ZodIssueCode.invalid_type,
|
|
67174
|
+
expected: ZodParsedType.array,
|
|
67175
|
+
received: ctx.parsedType
|
|
67176
|
+
});
|
|
67177
|
+
return INVALID;
|
|
67178
|
+
}
|
|
67179
|
+
if (ctx.data.length < this._def.items.length) {
|
|
67180
|
+
addIssueToContext(ctx, {
|
|
67181
|
+
code: ZodIssueCode.too_small,
|
|
67182
|
+
minimum: this._def.items.length,
|
|
67183
|
+
inclusive: true,
|
|
67184
|
+
exact: false,
|
|
67185
|
+
type: "array"
|
|
67186
|
+
});
|
|
67187
|
+
return INVALID;
|
|
67188
|
+
}
|
|
67189
|
+
const rest = this._def.rest;
|
|
67190
|
+
if (!rest && ctx.data.length > this._def.items.length) {
|
|
67191
|
+
addIssueToContext(ctx, {
|
|
67192
|
+
code: ZodIssueCode.too_big,
|
|
67193
|
+
maximum: this._def.items.length,
|
|
67194
|
+
inclusive: true,
|
|
67195
|
+
exact: false,
|
|
67196
|
+
type: "array"
|
|
67197
|
+
});
|
|
67198
|
+
status.dirty();
|
|
67199
|
+
}
|
|
67200
|
+
const items = [...ctx.data].map((item, itemIndex) => {
|
|
67201
|
+
const schema = this._def.items[itemIndex] || this._def.rest;
|
|
67202
|
+
if (!schema)
|
|
67203
|
+
return null;
|
|
67204
|
+
return schema._parse(new ParseInputLazyPath(ctx, item, ctx.path, itemIndex));
|
|
67205
|
+
}).filter((x) => !!x);
|
|
67206
|
+
if (ctx.common.async) {
|
|
67207
|
+
return Promise.all(items).then((results) => {
|
|
67208
|
+
return ParseStatus.mergeArray(status, results);
|
|
67209
|
+
});
|
|
67210
|
+
} else {
|
|
67211
|
+
return ParseStatus.mergeArray(status, items);
|
|
67212
|
+
}
|
|
67213
|
+
}
|
|
67214
|
+
get items() {
|
|
67215
|
+
return this._def.items;
|
|
67216
|
+
}
|
|
67217
|
+
rest(rest) {
|
|
67218
|
+
return new ZodTuple({
|
|
67219
|
+
...this._def,
|
|
67220
|
+
rest
|
|
67221
|
+
});
|
|
67222
|
+
}
|
|
67223
|
+
}
|
|
67224
|
+
ZodTuple.create = (schemas, params) => {
|
|
67225
|
+
if (!Array.isArray(schemas)) {
|
|
67226
|
+
throw new Error("You must pass an array of schemas to z.tuple([ ... ])");
|
|
67227
|
+
}
|
|
67228
|
+
return new ZodTuple({
|
|
67229
|
+
items: schemas,
|
|
67230
|
+
typeName: ZodFirstPartyTypeKind.ZodTuple,
|
|
67231
|
+
rest: null,
|
|
67232
|
+
...processCreateParams(params)
|
|
67233
|
+
});
|
|
67234
|
+
};
|
|
67235
|
+
class ZodRecord extends ZodType {
|
|
67236
|
+
get keySchema() {
|
|
67237
|
+
return this._def.keyType;
|
|
67238
|
+
}
|
|
67239
|
+
get valueSchema() {
|
|
67240
|
+
return this._def.valueType;
|
|
67241
|
+
}
|
|
67242
|
+
_parse(input) {
|
|
67243
|
+
const { status, ctx } = this._processInputParams(input);
|
|
67244
|
+
if (ctx.parsedType !== ZodParsedType.object) {
|
|
67245
|
+
addIssueToContext(ctx, {
|
|
67246
|
+
code: ZodIssueCode.invalid_type,
|
|
67247
|
+
expected: ZodParsedType.object,
|
|
67248
|
+
received: ctx.parsedType
|
|
67249
|
+
});
|
|
67250
|
+
return INVALID;
|
|
67251
|
+
}
|
|
67252
|
+
const pairs = [];
|
|
67253
|
+
const keyType = this._def.keyType;
|
|
67254
|
+
const valueType = this._def.valueType;
|
|
67255
|
+
for (const key in ctx.data) {
|
|
67256
|
+
pairs.push({
|
|
67257
|
+
key: keyType._parse(new ParseInputLazyPath(ctx, key, ctx.path, key)),
|
|
67258
|
+
value: valueType._parse(new ParseInputLazyPath(ctx, ctx.data[key], ctx.path, key))
|
|
67259
|
+
});
|
|
67260
|
+
}
|
|
67261
|
+
if (ctx.common.async) {
|
|
67262
|
+
return ParseStatus.mergeObjectAsync(status, pairs);
|
|
67263
|
+
} else {
|
|
67264
|
+
return ParseStatus.mergeObjectSync(status, pairs);
|
|
67265
|
+
}
|
|
67266
|
+
}
|
|
67267
|
+
get element() {
|
|
67268
|
+
return this._def.valueType;
|
|
67269
|
+
}
|
|
67270
|
+
static create(first, second, third) {
|
|
67271
|
+
if (second instanceof ZodType) {
|
|
67272
|
+
return new ZodRecord({
|
|
67273
|
+
keyType: first,
|
|
67274
|
+
valueType: second,
|
|
67275
|
+
typeName: ZodFirstPartyTypeKind.ZodRecord,
|
|
67276
|
+
...processCreateParams(third)
|
|
67277
|
+
});
|
|
67278
|
+
}
|
|
67279
|
+
return new ZodRecord({
|
|
67280
|
+
keyType: ZodString.create(),
|
|
67281
|
+
valueType: first,
|
|
67282
|
+
typeName: ZodFirstPartyTypeKind.ZodRecord,
|
|
67283
|
+
...processCreateParams(second)
|
|
67284
|
+
});
|
|
67285
|
+
}
|
|
67286
|
+
}
|
|
67287
|
+
class ZodMap extends ZodType {
|
|
67288
|
+
get keySchema() {
|
|
67289
|
+
return this._def.keyType;
|
|
67290
|
+
}
|
|
67291
|
+
get valueSchema() {
|
|
67292
|
+
return this._def.valueType;
|
|
67293
|
+
}
|
|
67294
|
+
_parse(input) {
|
|
67295
|
+
const { status, ctx } = this._processInputParams(input);
|
|
67296
|
+
if (ctx.parsedType !== ZodParsedType.map) {
|
|
67297
|
+
addIssueToContext(ctx, {
|
|
67298
|
+
code: ZodIssueCode.invalid_type,
|
|
67299
|
+
expected: ZodParsedType.map,
|
|
67300
|
+
received: ctx.parsedType
|
|
67301
|
+
});
|
|
67302
|
+
return INVALID;
|
|
67303
|
+
}
|
|
67304
|
+
const keyType = this._def.keyType;
|
|
67305
|
+
const valueType = this._def.valueType;
|
|
67306
|
+
const pairs = [...ctx.data.entries()].map(([key, value], index2) => {
|
|
67307
|
+
return {
|
|
67308
|
+
key: keyType._parse(new ParseInputLazyPath(ctx, key, ctx.path, [index2, "key"])),
|
|
67309
|
+
value: valueType._parse(new ParseInputLazyPath(ctx, value, ctx.path, [index2, "value"]))
|
|
67310
|
+
};
|
|
67311
|
+
});
|
|
67312
|
+
if (ctx.common.async) {
|
|
67313
|
+
const finalMap = /* @__PURE__ */ new Map();
|
|
67314
|
+
return Promise.resolve().then(async () => {
|
|
67315
|
+
for (const pair of pairs) {
|
|
67316
|
+
const key = await pair.key;
|
|
67317
|
+
const value = await pair.value;
|
|
67318
|
+
if (key.status === "aborted" || value.status === "aborted") {
|
|
67319
|
+
return INVALID;
|
|
67320
|
+
}
|
|
67321
|
+
if (key.status === "dirty" || value.status === "dirty") {
|
|
67322
|
+
status.dirty();
|
|
67323
|
+
}
|
|
67324
|
+
finalMap.set(key.value, value.value);
|
|
67325
|
+
}
|
|
67326
|
+
return { status: status.value, value: finalMap };
|
|
67327
|
+
});
|
|
67328
|
+
} else {
|
|
67329
|
+
const finalMap = /* @__PURE__ */ new Map();
|
|
67330
|
+
for (const pair of pairs) {
|
|
67331
|
+
const key = pair.key;
|
|
67332
|
+
const value = pair.value;
|
|
67333
|
+
if (key.status === "aborted" || value.status === "aborted") {
|
|
67334
|
+
return INVALID;
|
|
67335
|
+
}
|
|
67336
|
+
if (key.status === "dirty" || value.status === "dirty") {
|
|
67337
|
+
status.dirty();
|
|
67338
|
+
}
|
|
67339
|
+
finalMap.set(key.value, value.value);
|
|
67340
|
+
}
|
|
67341
|
+
return { status: status.value, value: finalMap };
|
|
67342
|
+
}
|
|
67343
|
+
}
|
|
67344
|
+
}
|
|
67345
|
+
ZodMap.create = (keyType, valueType, params) => {
|
|
67346
|
+
return new ZodMap({
|
|
67347
|
+
valueType,
|
|
67348
|
+
keyType,
|
|
67349
|
+
typeName: ZodFirstPartyTypeKind.ZodMap,
|
|
67350
|
+
...processCreateParams(params)
|
|
67351
|
+
});
|
|
67352
|
+
};
|
|
67353
|
+
class ZodSet extends ZodType {
|
|
67354
|
+
_parse(input) {
|
|
67355
|
+
const { status, ctx } = this._processInputParams(input);
|
|
67356
|
+
if (ctx.parsedType !== ZodParsedType.set) {
|
|
67357
|
+
addIssueToContext(ctx, {
|
|
67358
|
+
code: ZodIssueCode.invalid_type,
|
|
67359
|
+
expected: ZodParsedType.set,
|
|
67360
|
+
received: ctx.parsedType
|
|
67361
|
+
});
|
|
67362
|
+
return INVALID;
|
|
67363
|
+
}
|
|
67364
|
+
const def = this._def;
|
|
67365
|
+
if (def.minSize !== null) {
|
|
67366
|
+
if (ctx.data.size < def.minSize.value) {
|
|
67367
|
+
addIssueToContext(ctx, {
|
|
67368
|
+
code: ZodIssueCode.too_small,
|
|
67369
|
+
minimum: def.minSize.value,
|
|
67370
|
+
type: "set",
|
|
67371
|
+
inclusive: true,
|
|
67372
|
+
exact: false,
|
|
67373
|
+
message: def.minSize.message
|
|
67374
|
+
});
|
|
67375
|
+
status.dirty();
|
|
67376
|
+
}
|
|
67377
|
+
}
|
|
67378
|
+
if (def.maxSize !== null) {
|
|
67379
|
+
if (ctx.data.size > def.maxSize.value) {
|
|
67380
|
+
addIssueToContext(ctx, {
|
|
67381
|
+
code: ZodIssueCode.too_big,
|
|
67382
|
+
maximum: def.maxSize.value,
|
|
67383
|
+
type: "set",
|
|
67384
|
+
inclusive: true,
|
|
67385
|
+
exact: false,
|
|
67386
|
+
message: def.maxSize.message
|
|
67387
|
+
});
|
|
67388
|
+
status.dirty();
|
|
67389
|
+
}
|
|
67390
|
+
}
|
|
67391
|
+
const valueType = this._def.valueType;
|
|
67392
|
+
function finalizeSet(elements2) {
|
|
67393
|
+
const parsedSet = /* @__PURE__ */ new Set();
|
|
67394
|
+
for (const element of elements2) {
|
|
67395
|
+
if (element.status === "aborted")
|
|
67396
|
+
return INVALID;
|
|
67397
|
+
if (element.status === "dirty")
|
|
67398
|
+
status.dirty();
|
|
67399
|
+
parsedSet.add(element.value);
|
|
67400
|
+
}
|
|
67401
|
+
return { status: status.value, value: parsedSet };
|
|
67402
|
+
}
|
|
67403
|
+
const elements = [...ctx.data.values()].map((item, i) => valueType._parse(new ParseInputLazyPath(ctx, item, ctx.path, i)));
|
|
67404
|
+
if (ctx.common.async) {
|
|
67405
|
+
return Promise.all(elements).then((elements2) => finalizeSet(elements2));
|
|
67406
|
+
} else {
|
|
67407
|
+
return finalizeSet(elements);
|
|
67408
|
+
}
|
|
67409
|
+
}
|
|
67410
|
+
min(minSize, message) {
|
|
67411
|
+
return new ZodSet({
|
|
67412
|
+
...this._def,
|
|
67413
|
+
minSize: { value: minSize, message: errorUtil.toString(message) }
|
|
67414
|
+
});
|
|
67415
|
+
}
|
|
67416
|
+
max(maxSize, message) {
|
|
67417
|
+
return new ZodSet({
|
|
67418
|
+
...this._def,
|
|
67419
|
+
maxSize: { value: maxSize, message: errorUtil.toString(message) }
|
|
67420
|
+
});
|
|
67421
|
+
}
|
|
67422
|
+
size(size2, message) {
|
|
67423
|
+
return this.min(size2, message).max(size2, message);
|
|
67424
|
+
}
|
|
67425
|
+
nonempty(message) {
|
|
67426
|
+
return this.min(1, message);
|
|
67427
|
+
}
|
|
67428
|
+
}
|
|
67429
|
+
ZodSet.create = (valueType, params) => {
|
|
67430
|
+
return new ZodSet({
|
|
67431
|
+
valueType,
|
|
67432
|
+
minSize: null,
|
|
67433
|
+
maxSize: null,
|
|
67434
|
+
typeName: ZodFirstPartyTypeKind.ZodSet,
|
|
67435
|
+
...processCreateParams(params)
|
|
67436
|
+
});
|
|
67437
|
+
};
|
|
67438
|
+
class ZodFunction extends ZodType {
|
|
67439
|
+
constructor() {
|
|
67440
|
+
super(...arguments);
|
|
67441
|
+
this.validate = this.implement;
|
|
67442
|
+
}
|
|
67443
|
+
_parse(input) {
|
|
67444
|
+
const { ctx } = this._processInputParams(input);
|
|
67445
|
+
if (ctx.parsedType !== ZodParsedType.function) {
|
|
67446
|
+
addIssueToContext(ctx, {
|
|
67447
|
+
code: ZodIssueCode.invalid_type,
|
|
67448
|
+
expected: ZodParsedType.function,
|
|
67449
|
+
received: ctx.parsedType
|
|
67450
|
+
});
|
|
67451
|
+
return INVALID;
|
|
67452
|
+
}
|
|
67453
|
+
function makeArgsIssue(args, error) {
|
|
67454
|
+
return makeIssue({
|
|
67455
|
+
data: args,
|
|
67456
|
+
path: ctx.path,
|
|
67457
|
+
errorMaps: [
|
|
67458
|
+
ctx.common.contextualErrorMap,
|
|
67459
|
+
ctx.schemaErrorMap,
|
|
67460
|
+
getErrorMap(),
|
|
67461
|
+
errorMap
|
|
67462
|
+
].filter((x) => !!x),
|
|
67463
|
+
issueData: {
|
|
67464
|
+
code: ZodIssueCode.invalid_arguments,
|
|
67465
|
+
argumentsError: error
|
|
67466
|
+
}
|
|
67467
|
+
});
|
|
67468
|
+
}
|
|
67469
|
+
function makeReturnsIssue(returns, error) {
|
|
67470
|
+
return makeIssue({
|
|
67471
|
+
data: returns,
|
|
67472
|
+
path: ctx.path,
|
|
67473
|
+
errorMaps: [
|
|
67474
|
+
ctx.common.contextualErrorMap,
|
|
67475
|
+
ctx.schemaErrorMap,
|
|
67476
|
+
getErrorMap(),
|
|
67477
|
+
errorMap
|
|
67478
|
+
].filter((x) => !!x),
|
|
67479
|
+
issueData: {
|
|
67480
|
+
code: ZodIssueCode.invalid_return_type,
|
|
67481
|
+
returnTypeError: error
|
|
67482
|
+
}
|
|
67483
|
+
});
|
|
67484
|
+
}
|
|
67485
|
+
const params = { errorMap: ctx.common.contextualErrorMap };
|
|
67486
|
+
const fn = ctx.data;
|
|
67487
|
+
if (this._def.returns instanceof ZodPromise) {
|
|
67488
|
+
const me = this;
|
|
67489
|
+
return OK(async function(...args) {
|
|
67490
|
+
const error = new ZodError([]);
|
|
67491
|
+
const parsedArgs = await me._def.args.parseAsync(args, params).catch((e) => {
|
|
67492
|
+
error.addIssue(makeArgsIssue(args, e));
|
|
67493
|
+
throw error;
|
|
67494
|
+
});
|
|
67495
|
+
const result2 = await Reflect.apply(fn, this, parsedArgs);
|
|
67496
|
+
const parsedReturns = await me._def.returns._def.type.parseAsync(result2, params).catch((e) => {
|
|
67497
|
+
error.addIssue(makeReturnsIssue(result2, e));
|
|
67498
|
+
throw error;
|
|
67499
|
+
});
|
|
67500
|
+
return parsedReturns;
|
|
67501
|
+
});
|
|
67502
|
+
} else {
|
|
67503
|
+
const me = this;
|
|
67504
|
+
return OK(function(...args) {
|
|
67505
|
+
const parsedArgs = me._def.args.safeParse(args, params);
|
|
67506
|
+
if (!parsedArgs.success) {
|
|
67507
|
+
throw new ZodError([makeArgsIssue(args, parsedArgs.error)]);
|
|
67508
|
+
}
|
|
67509
|
+
const result2 = Reflect.apply(fn, this, parsedArgs.data);
|
|
67510
|
+
const parsedReturns = me._def.returns.safeParse(result2, params);
|
|
67511
|
+
if (!parsedReturns.success) {
|
|
67512
|
+
throw new ZodError([makeReturnsIssue(result2, parsedReturns.error)]);
|
|
67513
|
+
}
|
|
67514
|
+
return parsedReturns.data;
|
|
67515
|
+
});
|
|
67516
|
+
}
|
|
67517
|
+
}
|
|
67518
|
+
parameters() {
|
|
67519
|
+
return this._def.args;
|
|
67520
|
+
}
|
|
67521
|
+
returnType() {
|
|
67522
|
+
return this._def.returns;
|
|
67523
|
+
}
|
|
67524
|
+
args(...items) {
|
|
67525
|
+
return new ZodFunction({
|
|
67526
|
+
...this._def,
|
|
67527
|
+
args: ZodTuple.create(items).rest(ZodUnknown.create())
|
|
67528
|
+
});
|
|
67529
|
+
}
|
|
67530
|
+
returns(returnType) {
|
|
67531
|
+
return new ZodFunction({
|
|
67532
|
+
...this._def,
|
|
67533
|
+
returns: returnType
|
|
67534
|
+
});
|
|
67535
|
+
}
|
|
67536
|
+
implement(func) {
|
|
67537
|
+
const validatedFunc = this.parse(func);
|
|
67538
|
+
return validatedFunc;
|
|
67539
|
+
}
|
|
67540
|
+
strictImplement(func) {
|
|
67541
|
+
const validatedFunc = this.parse(func);
|
|
67542
|
+
return validatedFunc;
|
|
67543
|
+
}
|
|
67544
|
+
static create(args, returns, params) {
|
|
67545
|
+
return new ZodFunction({
|
|
67546
|
+
args: args ? args : ZodTuple.create([]).rest(ZodUnknown.create()),
|
|
67547
|
+
returns: returns || ZodUnknown.create(),
|
|
67548
|
+
typeName: ZodFirstPartyTypeKind.ZodFunction,
|
|
67549
|
+
...processCreateParams(params)
|
|
67550
|
+
});
|
|
67551
|
+
}
|
|
67552
|
+
}
|
|
67553
|
+
class ZodLazy extends ZodType {
|
|
67554
|
+
get schema() {
|
|
67555
|
+
return this._def.getter();
|
|
67556
|
+
}
|
|
67557
|
+
_parse(input) {
|
|
67558
|
+
const { ctx } = this._processInputParams(input);
|
|
67559
|
+
const lazySchema = this._def.getter();
|
|
67560
|
+
return lazySchema._parse({ data: ctx.data, path: ctx.path, parent: ctx });
|
|
67561
|
+
}
|
|
67562
|
+
}
|
|
67563
|
+
ZodLazy.create = (getter, params) => {
|
|
67564
|
+
return new ZodLazy({
|
|
67565
|
+
getter,
|
|
67566
|
+
typeName: ZodFirstPartyTypeKind.ZodLazy,
|
|
67567
|
+
...processCreateParams(params)
|
|
67568
|
+
});
|
|
67569
|
+
};
|
|
67570
|
+
class ZodLiteral extends ZodType {
|
|
67571
|
+
_parse(input) {
|
|
67572
|
+
if (input.data !== this._def.value) {
|
|
67573
|
+
const ctx = this._getOrReturnCtx(input);
|
|
67574
|
+
addIssueToContext(ctx, {
|
|
67575
|
+
received: ctx.data,
|
|
67576
|
+
code: ZodIssueCode.invalid_literal,
|
|
67577
|
+
expected: this._def.value
|
|
67578
|
+
});
|
|
67579
|
+
return INVALID;
|
|
67580
|
+
}
|
|
67581
|
+
return { status: "valid", value: input.data };
|
|
67582
|
+
}
|
|
67583
|
+
get value() {
|
|
67584
|
+
return this._def.value;
|
|
67585
|
+
}
|
|
67586
|
+
}
|
|
67587
|
+
ZodLiteral.create = (value, params) => {
|
|
67588
|
+
return new ZodLiteral({
|
|
67589
|
+
value,
|
|
67590
|
+
typeName: ZodFirstPartyTypeKind.ZodLiteral,
|
|
67591
|
+
...processCreateParams(params)
|
|
67592
|
+
});
|
|
67593
|
+
};
|
|
67594
|
+
function createZodEnum(values, params) {
|
|
67595
|
+
return new ZodEnum({
|
|
67596
|
+
values,
|
|
67597
|
+
typeName: ZodFirstPartyTypeKind.ZodEnum,
|
|
67598
|
+
...processCreateParams(params)
|
|
67599
|
+
});
|
|
67600
|
+
}
|
|
67601
|
+
class ZodEnum extends ZodType {
|
|
67602
|
+
_parse(input) {
|
|
67603
|
+
if (typeof input.data !== "string") {
|
|
67604
|
+
const ctx = this._getOrReturnCtx(input);
|
|
67605
|
+
const expectedValues = this._def.values;
|
|
67606
|
+
addIssueToContext(ctx, {
|
|
67607
|
+
expected: util.joinValues(expectedValues),
|
|
67608
|
+
received: ctx.parsedType,
|
|
67609
|
+
code: ZodIssueCode.invalid_type
|
|
67610
|
+
});
|
|
67611
|
+
return INVALID;
|
|
67612
|
+
}
|
|
67613
|
+
if (this._def.values.indexOf(input.data) === -1) {
|
|
67614
|
+
const ctx = this._getOrReturnCtx(input);
|
|
67615
|
+
const expectedValues = this._def.values;
|
|
67616
|
+
addIssueToContext(ctx, {
|
|
67617
|
+
received: ctx.data,
|
|
67618
|
+
code: ZodIssueCode.invalid_enum_value,
|
|
67619
|
+
options: expectedValues
|
|
67620
|
+
});
|
|
67621
|
+
return INVALID;
|
|
67622
|
+
}
|
|
67623
|
+
return OK(input.data);
|
|
67624
|
+
}
|
|
67625
|
+
get options() {
|
|
67626
|
+
return this._def.values;
|
|
67627
|
+
}
|
|
67628
|
+
get enum() {
|
|
67629
|
+
const enumValues = {};
|
|
67630
|
+
for (const val of this._def.values) {
|
|
67631
|
+
enumValues[val] = val;
|
|
67632
|
+
}
|
|
67633
|
+
return enumValues;
|
|
67634
|
+
}
|
|
67635
|
+
get Values() {
|
|
67636
|
+
const enumValues = {};
|
|
67637
|
+
for (const val of this._def.values) {
|
|
67638
|
+
enumValues[val] = val;
|
|
67639
|
+
}
|
|
67640
|
+
return enumValues;
|
|
67641
|
+
}
|
|
67642
|
+
get Enum() {
|
|
67643
|
+
const enumValues = {};
|
|
67644
|
+
for (const val of this._def.values) {
|
|
67645
|
+
enumValues[val] = val;
|
|
67646
|
+
}
|
|
67647
|
+
return enumValues;
|
|
67648
|
+
}
|
|
67649
|
+
extract(values) {
|
|
67650
|
+
return ZodEnum.create(values);
|
|
67651
|
+
}
|
|
67652
|
+
exclude(values) {
|
|
67653
|
+
return ZodEnum.create(this.options.filter((opt) => !values.includes(opt)));
|
|
67654
|
+
}
|
|
67655
|
+
}
|
|
67656
|
+
ZodEnum.create = createZodEnum;
|
|
67657
|
+
class ZodNativeEnum extends ZodType {
|
|
67658
|
+
_parse(input) {
|
|
67659
|
+
const nativeEnumValues = util.getValidEnumValues(this._def.values);
|
|
67660
|
+
const ctx = this._getOrReturnCtx(input);
|
|
67661
|
+
if (ctx.parsedType !== ZodParsedType.string && ctx.parsedType !== ZodParsedType.number) {
|
|
67662
|
+
const expectedValues = util.objectValues(nativeEnumValues);
|
|
67663
|
+
addIssueToContext(ctx, {
|
|
67664
|
+
expected: util.joinValues(expectedValues),
|
|
67665
|
+
received: ctx.parsedType,
|
|
67666
|
+
code: ZodIssueCode.invalid_type
|
|
67667
|
+
});
|
|
67668
|
+
return INVALID;
|
|
67669
|
+
}
|
|
67670
|
+
if (nativeEnumValues.indexOf(input.data) === -1) {
|
|
67671
|
+
const expectedValues = util.objectValues(nativeEnumValues);
|
|
67672
|
+
addIssueToContext(ctx, {
|
|
67673
|
+
received: ctx.data,
|
|
67674
|
+
code: ZodIssueCode.invalid_enum_value,
|
|
67675
|
+
options: expectedValues
|
|
67676
|
+
});
|
|
67677
|
+
return INVALID;
|
|
67678
|
+
}
|
|
67679
|
+
return OK(input.data);
|
|
67680
|
+
}
|
|
67681
|
+
get enum() {
|
|
67682
|
+
return this._def.values;
|
|
67683
|
+
}
|
|
67684
|
+
}
|
|
67685
|
+
ZodNativeEnum.create = (values, params) => {
|
|
67686
|
+
return new ZodNativeEnum({
|
|
67687
|
+
values,
|
|
67688
|
+
typeName: ZodFirstPartyTypeKind.ZodNativeEnum,
|
|
67689
|
+
...processCreateParams(params)
|
|
67690
|
+
});
|
|
67691
|
+
};
|
|
67692
|
+
class ZodPromise extends ZodType {
|
|
67693
|
+
unwrap() {
|
|
67694
|
+
return this._def.type;
|
|
67695
|
+
}
|
|
67696
|
+
_parse(input) {
|
|
67697
|
+
const { ctx } = this._processInputParams(input);
|
|
67698
|
+
if (ctx.parsedType !== ZodParsedType.promise && ctx.common.async === false) {
|
|
67699
|
+
addIssueToContext(ctx, {
|
|
67700
|
+
code: ZodIssueCode.invalid_type,
|
|
67701
|
+
expected: ZodParsedType.promise,
|
|
67702
|
+
received: ctx.parsedType
|
|
67703
|
+
});
|
|
67704
|
+
return INVALID;
|
|
67705
|
+
}
|
|
67706
|
+
const promisified = ctx.parsedType === ZodParsedType.promise ? ctx.data : Promise.resolve(ctx.data);
|
|
67707
|
+
return OK(promisified.then((data) => {
|
|
67708
|
+
return this._def.type.parseAsync(data, {
|
|
67709
|
+
path: ctx.path,
|
|
67710
|
+
errorMap: ctx.common.contextualErrorMap
|
|
67711
|
+
});
|
|
67712
|
+
}));
|
|
67713
|
+
}
|
|
67714
|
+
}
|
|
67715
|
+
ZodPromise.create = (schema, params) => {
|
|
67716
|
+
return new ZodPromise({
|
|
67717
|
+
type: schema,
|
|
67718
|
+
typeName: ZodFirstPartyTypeKind.ZodPromise,
|
|
67719
|
+
...processCreateParams(params)
|
|
67720
|
+
});
|
|
67721
|
+
};
|
|
67722
|
+
class ZodEffects extends ZodType {
|
|
67723
|
+
innerType() {
|
|
67724
|
+
return this._def.schema;
|
|
67725
|
+
}
|
|
67726
|
+
sourceType() {
|
|
67727
|
+
return this._def.schema._def.typeName === ZodFirstPartyTypeKind.ZodEffects ? this._def.schema.sourceType() : this._def.schema;
|
|
67728
|
+
}
|
|
67729
|
+
_parse(input) {
|
|
67730
|
+
const { status, ctx } = this._processInputParams(input);
|
|
67731
|
+
const effect = this._def.effect || null;
|
|
67732
|
+
const checkCtx = {
|
|
67733
|
+
addIssue: (arg) => {
|
|
67734
|
+
addIssueToContext(ctx, arg);
|
|
67735
|
+
if (arg.fatal) {
|
|
67736
|
+
status.abort();
|
|
67737
|
+
} else {
|
|
67738
|
+
status.dirty();
|
|
67739
|
+
}
|
|
67740
|
+
},
|
|
67741
|
+
get path() {
|
|
67742
|
+
return ctx.path;
|
|
67743
|
+
}
|
|
67744
|
+
};
|
|
67745
|
+
checkCtx.addIssue = checkCtx.addIssue.bind(checkCtx);
|
|
67746
|
+
if (effect.type === "preprocess") {
|
|
67747
|
+
const processed = effect.transform(ctx.data, checkCtx);
|
|
67748
|
+
if (ctx.common.issues.length) {
|
|
67749
|
+
return {
|
|
67750
|
+
status: "dirty",
|
|
67751
|
+
value: ctx.data
|
|
67752
|
+
};
|
|
67753
|
+
}
|
|
67754
|
+
if (ctx.common.async) {
|
|
67755
|
+
return Promise.resolve(processed).then((processed2) => {
|
|
67756
|
+
return this._def.schema._parseAsync({
|
|
67757
|
+
data: processed2,
|
|
67758
|
+
path: ctx.path,
|
|
67759
|
+
parent: ctx
|
|
67760
|
+
});
|
|
67761
|
+
});
|
|
67762
|
+
} else {
|
|
67763
|
+
return this._def.schema._parseSync({
|
|
67764
|
+
data: processed,
|
|
67765
|
+
path: ctx.path,
|
|
67766
|
+
parent: ctx
|
|
67767
|
+
});
|
|
67768
|
+
}
|
|
67769
|
+
}
|
|
67770
|
+
if (effect.type === "refinement") {
|
|
67771
|
+
const executeRefinement = (acc) => {
|
|
67772
|
+
const result2 = effect.refinement(acc, checkCtx);
|
|
67773
|
+
if (ctx.common.async) {
|
|
67774
|
+
return Promise.resolve(result2);
|
|
67775
|
+
}
|
|
67776
|
+
if (result2 instanceof Promise) {
|
|
67777
|
+
throw new Error("Async refinement encountered during synchronous parse operation. Use .parseAsync instead.");
|
|
67778
|
+
}
|
|
67779
|
+
return acc;
|
|
67780
|
+
};
|
|
67781
|
+
if (ctx.common.async === false) {
|
|
67782
|
+
const inner = this._def.schema._parseSync({
|
|
67783
|
+
data: ctx.data,
|
|
67784
|
+
path: ctx.path,
|
|
67785
|
+
parent: ctx
|
|
67786
|
+
});
|
|
67787
|
+
if (inner.status === "aborted")
|
|
67788
|
+
return INVALID;
|
|
67789
|
+
if (inner.status === "dirty")
|
|
67790
|
+
status.dirty();
|
|
67791
|
+
executeRefinement(inner.value);
|
|
67792
|
+
return { status: status.value, value: inner.value };
|
|
67793
|
+
} else {
|
|
67794
|
+
return this._def.schema._parseAsync({ data: ctx.data, path: ctx.path, parent: ctx }).then((inner) => {
|
|
67795
|
+
if (inner.status === "aborted")
|
|
67796
|
+
return INVALID;
|
|
67797
|
+
if (inner.status === "dirty")
|
|
67798
|
+
status.dirty();
|
|
67799
|
+
return executeRefinement(inner.value).then(() => {
|
|
67800
|
+
return { status: status.value, value: inner.value };
|
|
67801
|
+
});
|
|
67802
|
+
});
|
|
67803
|
+
}
|
|
67804
|
+
}
|
|
67805
|
+
if (effect.type === "transform") {
|
|
67806
|
+
if (ctx.common.async === false) {
|
|
67807
|
+
const base = this._def.schema._parseSync({
|
|
67808
|
+
data: ctx.data,
|
|
67809
|
+
path: ctx.path,
|
|
67810
|
+
parent: ctx
|
|
67811
|
+
});
|
|
67812
|
+
if (!isValid(base))
|
|
67813
|
+
return base;
|
|
67814
|
+
const result2 = effect.transform(base.value, checkCtx);
|
|
67815
|
+
if (result2 instanceof Promise) {
|
|
67816
|
+
throw new Error(`Asynchronous transform encountered during synchronous parse operation. Use .parseAsync instead.`);
|
|
67817
|
+
}
|
|
67818
|
+
return { status: status.value, value: result2 };
|
|
67819
|
+
} else {
|
|
67820
|
+
return this._def.schema._parseAsync({ data: ctx.data, path: ctx.path, parent: ctx }).then((base) => {
|
|
67821
|
+
if (!isValid(base))
|
|
67822
|
+
return base;
|
|
67823
|
+
return Promise.resolve(effect.transform(base.value, checkCtx)).then((result2) => ({ status: status.value, value: result2 }));
|
|
67824
|
+
});
|
|
67825
|
+
}
|
|
67826
|
+
}
|
|
67827
|
+
util.assertNever(effect);
|
|
67828
|
+
}
|
|
67829
|
+
}
|
|
67830
|
+
ZodEffects.create = (schema, effect, params) => {
|
|
67831
|
+
return new ZodEffects({
|
|
67832
|
+
schema,
|
|
67833
|
+
typeName: ZodFirstPartyTypeKind.ZodEffects,
|
|
67834
|
+
effect,
|
|
67835
|
+
...processCreateParams(params)
|
|
67836
|
+
});
|
|
67837
|
+
};
|
|
67838
|
+
ZodEffects.createWithPreprocess = (preprocess, schema, params) => {
|
|
67839
|
+
return new ZodEffects({
|
|
67840
|
+
schema,
|
|
67841
|
+
effect: { type: "preprocess", transform: preprocess },
|
|
67842
|
+
typeName: ZodFirstPartyTypeKind.ZodEffects,
|
|
67843
|
+
...processCreateParams(params)
|
|
67844
|
+
});
|
|
67845
|
+
};
|
|
67846
|
+
class ZodOptional extends ZodType {
|
|
67847
|
+
_parse(input) {
|
|
67848
|
+
const parsedType = this._getType(input);
|
|
67849
|
+
if (parsedType === ZodParsedType.undefined) {
|
|
67850
|
+
return OK(void 0);
|
|
67851
|
+
}
|
|
67852
|
+
return this._def.innerType._parse(input);
|
|
67853
|
+
}
|
|
67854
|
+
unwrap() {
|
|
67855
|
+
return this._def.innerType;
|
|
67856
|
+
}
|
|
67857
|
+
}
|
|
67858
|
+
ZodOptional.create = (type, params) => {
|
|
67859
|
+
return new ZodOptional({
|
|
67860
|
+
innerType: type,
|
|
67861
|
+
typeName: ZodFirstPartyTypeKind.ZodOptional,
|
|
67862
|
+
...processCreateParams(params)
|
|
67863
|
+
});
|
|
67864
|
+
};
|
|
67865
|
+
class ZodNullable extends ZodType {
|
|
67866
|
+
_parse(input) {
|
|
67867
|
+
const parsedType = this._getType(input);
|
|
67868
|
+
if (parsedType === ZodParsedType.null) {
|
|
67869
|
+
return OK(null);
|
|
67870
|
+
}
|
|
67871
|
+
return this._def.innerType._parse(input);
|
|
67872
|
+
}
|
|
67873
|
+
unwrap() {
|
|
67874
|
+
return this._def.innerType;
|
|
67875
|
+
}
|
|
67876
|
+
}
|
|
67877
|
+
ZodNullable.create = (type, params) => {
|
|
67878
|
+
return new ZodNullable({
|
|
67879
|
+
innerType: type,
|
|
67880
|
+
typeName: ZodFirstPartyTypeKind.ZodNullable,
|
|
67881
|
+
...processCreateParams(params)
|
|
67882
|
+
});
|
|
67883
|
+
};
|
|
67884
|
+
class ZodDefault extends ZodType {
|
|
67885
|
+
_parse(input) {
|
|
67886
|
+
const { ctx } = this._processInputParams(input);
|
|
67887
|
+
let data = ctx.data;
|
|
67888
|
+
if (ctx.parsedType === ZodParsedType.undefined) {
|
|
67889
|
+
data = this._def.defaultValue();
|
|
67890
|
+
}
|
|
67891
|
+
return this._def.innerType._parse({
|
|
67892
|
+
data,
|
|
67893
|
+
path: ctx.path,
|
|
67894
|
+
parent: ctx
|
|
67895
|
+
});
|
|
67896
|
+
}
|
|
67897
|
+
removeDefault() {
|
|
67898
|
+
return this._def.innerType;
|
|
67899
|
+
}
|
|
67900
|
+
}
|
|
67901
|
+
ZodDefault.create = (type, params) => {
|
|
67902
|
+
return new ZodDefault({
|
|
67903
|
+
innerType: type,
|
|
67904
|
+
typeName: ZodFirstPartyTypeKind.ZodDefault,
|
|
67905
|
+
defaultValue: typeof params.default === "function" ? params.default : () => params.default,
|
|
67906
|
+
...processCreateParams(params)
|
|
67907
|
+
});
|
|
67908
|
+
};
|
|
67909
|
+
class ZodCatch extends ZodType {
|
|
67910
|
+
_parse(input) {
|
|
67911
|
+
const { ctx } = this._processInputParams(input);
|
|
67912
|
+
const newCtx = {
|
|
67913
|
+
...ctx,
|
|
67914
|
+
common: {
|
|
67915
|
+
...ctx.common,
|
|
67916
|
+
issues: []
|
|
67917
|
+
}
|
|
67918
|
+
};
|
|
67919
|
+
const result2 = this._def.innerType._parse({
|
|
67920
|
+
data: newCtx.data,
|
|
67921
|
+
path: newCtx.path,
|
|
67922
|
+
parent: {
|
|
67923
|
+
...newCtx
|
|
67924
|
+
}
|
|
67925
|
+
});
|
|
67926
|
+
if (isAsync(result2)) {
|
|
67927
|
+
return result2.then((result3) => {
|
|
67928
|
+
return {
|
|
67929
|
+
status: "valid",
|
|
67930
|
+
value: result3.status === "valid" ? result3.value : this._def.catchValue({
|
|
67931
|
+
get error() {
|
|
67932
|
+
return new ZodError(newCtx.common.issues);
|
|
67933
|
+
},
|
|
67934
|
+
input: newCtx.data
|
|
67935
|
+
})
|
|
67936
|
+
};
|
|
67937
|
+
});
|
|
67938
|
+
} else {
|
|
67939
|
+
return {
|
|
67940
|
+
status: "valid",
|
|
67941
|
+
value: result2.status === "valid" ? result2.value : this._def.catchValue({
|
|
67942
|
+
get error() {
|
|
67943
|
+
return new ZodError(newCtx.common.issues);
|
|
67944
|
+
},
|
|
67945
|
+
input: newCtx.data
|
|
67946
|
+
})
|
|
67947
|
+
};
|
|
67948
|
+
}
|
|
67949
|
+
}
|
|
67950
|
+
removeCatch() {
|
|
67951
|
+
return this._def.innerType;
|
|
67952
|
+
}
|
|
67953
|
+
}
|
|
67954
|
+
ZodCatch.create = (type, params) => {
|
|
67955
|
+
return new ZodCatch({
|
|
67956
|
+
innerType: type,
|
|
67957
|
+
typeName: ZodFirstPartyTypeKind.ZodCatch,
|
|
67958
|
+
catchValue: typeof params.catch === "function" ? params.catch : () => params.catch,
|
|
67959
|
+
...processCreateParams(params)
|
|
67960
|
+
});
|
|
67961
|
+
};
|
|
67962
|
+
class ZodNaN extends ZodType {
|
|
67963
|
+
_parse(input) {
|
|
67964
|
+
const parsedType = this._getType(input);
|
|
67965
|
+
if (parsedType !== ZodParsedType.nan) {
|
|
67966
|
+
const ctx = this._getOrReturnCtx(input);
|
|
67967
|
+
addIssueToContext(ctx, {
|
|
67968
|
+
code: ZodIssueCode.invalid_type,
|
|
67969
|
+
expected: ZodParsedType.nan,
|
|
67970
|
+
received: ctx.parsedType
|
|
67971
|
+
});
|
|
67972
|
+
return INVALID;
|
|
67973
|
+
}
|
|
67974
|
+
return { status: "valid", value: input.data };
|
|
67975
|
+
}
|
|
67976
|
+
}
|
|
67977
|
+
ZodNaN.create = (params) => {
|
|
67978
|
+
return new ZodNaN({
|
|
67979
|
+
typeName: ZodFirstPartyTypeKind.ZodNaN,
|
|
67980
|
+
...processCreateParams(params)
|
|
67981
|
+
});
|
|
67982
|
+
};
|
|
67983
|
+
const BRAND = Symbol("zod_brand");
|
|
67984
|
+
class ZodBranded extends ZodType {
|
|
67985
|
+
_parse(input) {
|
|
67986
|
+
const { ctx } = this._processInputParams(input);
|
|
67987
|
+
const data = ctx.data;
|
|
67988
|
+
return this._def.type._parse({
|
|
67989
|
+
data,
|
|
67990
|
+
path: ctx.path,
|
|
67991
|
+
parent: ctx
|
|
67992
|
+
});
|
|
67993
|
+
}
|
|
67994
|
+
unwrap() {
|
|
67995
|
+
return this._def.type;
|
|
67996
|
+
}
|
|
67997
|
+
}
|
|
67998
|
+
class ZodPipeline extends ZodType {
|
|
67999
|
+
_parse(input) {
|
|
68000
|
+
const { status, ctx } = this._processInputParams(input);
|
|
68001
|
+
if (ctx.common.async) {
|
|
68002
|
+
const handleAsync = async () => {
|
|
68003
|
+
const inResult = await this._def.in._parseAsync({
|
|
68004
|
+
data: ctx.data,
|
|
68005
|
+
path: ctx.path,
|
|
68006
|
+
parent: ctx
|
|
68007
|
+
});
|
|
68008
|
+
if (inResult.status === "aborted")
|
|
68009
|
+
return INVALID;
|
|
68010
|
+
if (inResult.status === "dirty") {
|
|
68011
|
+
status.dirty();
|
|
68012
|
+
return DIRTY(inResult.value);
|
|
68013
|
+
} else {
|
|
68014
|
+
return this._def.out._parseAsync({
|
|
68015
|
+
data: inResult.value,
|
|
68016
|
+
path: ctx.path,
|
|
68017
|
+
parent: ctx
|
|
68018
|
+
});
|
|
68019
|
+
}
|
|
68020
|
+
};
|
|
68021
|
+
return handleAsync();
|
|
68022
|
+
} else {
|
|
68023
|
+
const inResult = this._def.in._parseSync({
|
|
68024
|
+
data: ctx.data,
|
|
68025
|
+
path: ctx.path,
|
|
68026
|
+
parent: ctx
|
|
68027
|
+
});
|
|
68028
|
+
if (inResult.status === "aborted")
|
|
68029
|
+
return INVALID;
|
|
68030
|
+
if (inResult.status === "dirty") {
|
|
68031
|
+
status.dirty();
|
|
68032
|
+
return {
|
|
68033
|
+
status: "dirty",
|
|
68034
|
+
value: inResult.value
|
|
68035
|
+
};
|
|
68036
|
+
} else {
|
|
68037
|
+
return this._def.out._parseSync({
|
|
68038
|
+
data: inResult.value,
|
|
68039
|
+
path: ctx.path,
|
|
68040
|
+
parent: ctx
|
|
68041
|
+
});
|
|
68042
|
+
}
|
|
68043
|
+
}
|
|
68044
|
+
}
|
|
68045
|
+
static create(a, b) {
|
|
68046
|
+
return new ZodPipeline({
|
|
68047
|
+
in: a,
|
|
68048
|
+
out: b,
|
|
68049
|
+
typeName: ZodFirstPartyTypeKind.ZodPipeline
|
|
68050
|
+
});
|
|
68051
|
+
}
|
|
68052
|
+
}
|
|
68053
|
+
class ZodReadonly extends ZodType {
|
|
68054
|
+
_parse(input) {
|
|
68055
|
+
const result2 = this._def.innerType._parse(input);
|
|
68056
|
+
if (isValid(result2)) {
|
|
68057
|
+
result2.value = Object.freeze(result2.value);
|
|
68058
|
+
}
|
|
68059
|
+
return result2;
|
|
68060
|
+
}
|
|
68061
|
+
}
|
|
68062
|
+
ZodReadonly.create = (type, params) => {
|
|
68063
|
+
return new ZodReadonly({
|
|
68064
|
+
innerType: type,
|
|
68065
|
+
typeName: ZodFirstPartyTypeKind.ZodReadonly,
|
|
68066
|
+
...processCreateParams(params)
|
|
68067
|
+
});
|
|
68068
|
+
};
|
|
68069
|
+
const custom = (check, params = {}, fatal) => {
|
|
68070
|
+
if (check)
|
|
68071
|
+
return ZodAny.create().superRefine((data, ctx) => {
|
|
68072
|
+
var _a, _b;
|
|
68073
|
+
if (!check(data)) {
|
|
68074
|
+
const p = typeof params === "function" ? params(data) : typeof params === "string" ? { message: params } : params;
|
|
68075
|
+
const _fatal = (_b = (_a = p.fatal) !== null && _a !== void 0 ? _a : fatal) !== null && _b !== void 0 ? _b : true;
|
|
68076
|
+
const p2 = typeof p === "string" ? { message: p } : p;
|
|
68077
|
+
ctx.addIssue({ code: "custom", ...p2, fatal: _fatal });
|
|
68078
|
+
}
|
|
68079
|
+
});
|
|
68080
|
+
return ZodAny.create();
|
|
68081
|
+
};
|
|
68082
|
+
const late = {
|
|
68083
|
+
object: ZodObject.lazycreate
|
|
68084
|
+
};
|
|
68085
|
+
var ZodFirstPartyTypeKind;
|
|
68086
|
+
(function(ZodFirstPartyTypeKind2) {
|
|
68087
|
+
ZodFirstPartyTypeKind2["ZodString"] = "ZodString";
|
|
68088
|
+
ZodFirstPartyTypeKind2["ZodNumber"] = "ZodNumber";
|
|
68089
|
+
ZodFirstPartyTypeKind2["ZodNaN"] = "ZodNaN";
|
|
68090
|
+
ZodFirstPartyTypeKind2["ZodBigInt"] = "ZodBigInt";
|
|
68091
|
+
ZodFirstPartyTypeKind2["ZodBoolean"] = "ZodBoolean";
|
|
68092
|
+
ZodFirstPartyTypeKind2["ZodDate"] = "ZodDate";
|
|
68093
|
+
ZodFirstPartyTypeKind2["ZodSymbol"] = "ZodSymbol";
|
|
68094
|
+
ZodFirstPartyTypeKind2["ZodUndefined"] = "ZodUndefined";
|
|
68095
|
+
ZodFirstPartyTypeKind2["ZodNull"] = "ZodNull";
|
|
68096
|
+
ZodFirstPartyTypeKind2["ZodAny"] = "ZodAny";
|
|
68097
|
+
ZodFirstPartyTypeKind2["ZodUnknown"] = "ZodUnknown";
|
|
68098
|
+
ZodFirstPartyTypeKind2["ZodNever"] = "ZodNever";
|
|
68099
|
+
ZodFirstPartyTypeKind2["ZodVoid"] = "ZodVoid";
|
|
68100
|
+
ZodFirstPartyTypeKind2["ZodArray"] = "ZodArray";
|
|
68101
|
+
ZodFirstPartyTypeKind2["ZodObject"] = "ZodObject";
|
|
68102
|
+
ZodFirstPartyTypeKind2["ZodUnion"] = "ZodUnion";
|
|
68103
|
+
ZodFirstPartyTypeKind2["ZodDiscriminatedUnion"] = "ZodDiscriminatedUnion";
|
|
68104
|
+
ZodFirstPartyTypeKind2["ZodIntersection"] = "ZodIntersection";
|
|
68105
|
+
ZodFirstPartyTypeKind2["ZodTuple"] = "ZodTuple";
|
|
68106
|
+
ZodFirstPartyTypeKind2["ZodRecord"] = "ZodRecord";
|
|
68107
|
+
ZodFirstPartyTypeKind2["ZodMap"] = "ZodMap";
|
|
68108
|
+
ZodFirstPartyTypeKind2["ZodSet"] = "ZodSet";
|
|
68109
|
+
ZodFirstPartyTypeKind2["ZodFunction"] = "ZodFunction";
|
|
68110
|
+
ZodFirstPartyTypeKind2["ZodLazy"] = "ZodLazy";
|
|
68111
|
+
ZodFirstPartyTypeKind2["ZodLiteral"] = "ZodLiteral";
|
|
68112
|
+
ZodFirstPartyTypeKind2["ZodEnum"] = "ZodEnum";
|
|
68113
|
+
ZodFirstPartyTypeKind2["ZodEffects"] = "ZodEffects";
|
|
68114
|
+
ZodFirstPartyTypeKind2["ZodNativeEnum"] = "ZodNativeEnum";
|
|
68115
|
+
ZodFirstPartyTypeKind2["ZodOptional"] = "ZodOptional";
|
|
68116
|
+
ZodFirstPartyTypeKind2["ZodNullable"] = "ZodNullable";
|
|
68117
|
+
ZodFirstPartyTypeKind2["ZodDefault"] = "ZodDefault";
|
|
68118
|
+
ZodFirstPartyTypeKind2["ZodCatch"] = "ZodCatch";
|
|
68119
|
+
ZodFirstPartyTypeKind2["ZodPromise"] = "ZodPromise";
|
|
68120
|
+
ZodFirstPartyTypeKind2["ZodBranded"] = "ZodBranded";
|
|
68121
|
+
ZodFirstPartyTypeKind2["ZodPipeline"] = "ZodPipeline";
|
|
68122
|
+
ZodFirstPartyTypeKind2["ZodReadonly"] = "ZodReadonly";
|
|
68123
|
+
})(ZodFirstPartyTypeKind || (ZodFirstPartyTypeKind = {}));
|
|
68124
|
+
const instanceOfType = (cls, params = {
|
|
68125
|
+
message: `Input not instance of ${cls.name}`
|
|
68126
|
+
}) => custom((data) => data instanceof cls, params);
|
|
68127
|
+
const stringType = ZodString.create;
|
|
68128
|
+
const numberType = ZodNumber.create;
|
|
68129
|
+
const nanType = ZodNaN.create;
|
|
68130
|
+
const bigIntType = ZodBigInt.create;
|
|
68131
|
+
const booleanType = ZodBoolean.create;
|
|
68132
|
+
const dateType = ZodDate.create;
|
|
68133
|
+
const symbolType = ZodSymbol.create;
|
|
68134
|
+
const undefinedType = ZodUndefined.create;
|
|
68135
|
+
const nullType = ZodNull.create;
|
|
68136
|
+
const anyType = ZodAny.create;
|
|
68137
|
+
const unknownType = ZodUnknown.create;
|
|
68138
|
+
const neverType = ZodNever.create;
|
|
68139
|
+
const voidType = ZodVoid.create;
|
|
68140
|
+
const arrayType = ZodArray.create;
|
|
68141
|
+
const objectType = ZodObject.create;
|
|
68142
|
+
const strictObjectType = ZodObject.strictCreate;
|
|
68143
|
+
const unionType = ZodUnion.create;
|
|
68144
|
+
const discriminatedUnionType = ZodDiscriminatedUnion.create;
|
|
68145
|
+
const intersectionType = ZodIntersection.create;
|
|
68146
|
+
const tupleType = ZodTuple.create;
|
|
68147
|
+
const recordType = ZodRecord.create;
|
|
68148
|
+
const mapType = ZodMap.create;
|
|
68149
|
+
const setType = ZodSet.create;
|
|
68150
|
+
const functionType = ZodFunction.create;
|
|
68151
|
+
const lazyType = ZodLazy.create;
|
|
68152
|
+
const literalType = ZodLiteral.create;
|
|
68153
|
+
const enumType = ZodEnum.create;
|
|
68154
|
+
const nativeEnumType = ZodNativeEnum.create;
|
|
68155
|
+
const promiseType = ZodPromise.create;
|
|
68156
|
+
const effectsType = ZodEffects.create;
|
|
68157
|
+
const optionalType = ZodOptional.create;
|
|
68158
|
+
const nullableType = ZodNullable.create;
|
|
68159
|
+
const preprocessType = ZodEffects.createWithPreprocess;
|
|
68160
|
+
const pipelineType = ZodPipeline.create;
|
|
68161
|
+
const ostring = () => stringType().optional();
|
|
68162
|
+
const onumber = () => numberType().optional();
|
|
68163
|
+
const oboolean = () => booleanType().optional();
|
|
68164
|
+
const coerce = {
|
|
68165
|
+
string: (arg) => ZodString.create({ ...arg, coerce: true }),
|
|
68166
|
+
number: (arg) => ZodNumber.create({ ...arg, coerce: true }),
|
|
68167
|
+
boolean: (arg) => ZodBoolean.create({
|
|
68168
|
+
...arg,
|
|
68169
|
+
coerce: true
|
|
68170
|
+
}),
|
|
68171
|
+
bigint: (arg) => ZodBigInt.create({ ...arg, coerce: true }),
|
|
68172
|
+
date: (arg) => ZodDate.create({ ...arg, coerce: true })
|
|
68173
|
+
};
|
|
68174
|
+
const NEVER = INVALID;
|
|
68175
|
+
var z = /* @__PURE__ */ Object.freeze({
|
|
68176
|
+
__proto__: null,
|
|
68177
|
+
defaultErrorMap: errorMap,
|
|
68178
|
+
setErrorMap,
|
|
68179
|
+
getErrorMap,
|
|
68180
|
+
makeIssue,
|
|
68181
|
+
EMPTY_PATH,
|
|
68182
|
+
addIssueToContext,
|
|
68183
|
+
ParseStatus,
|
|
68184
|
+
INVALID,
|
|
68185
|
+
DIRTY,
|
|
68186
|
+
OK,
|
|
68187
|
+
isAborted,
|
|
68188
|
+
isDirty,
|
|
68189
|
+
isValid,
|
|
68190
|
+
isAsync,
|
|
68191
|
+
get util() {
|
|
68192
|
+
return util;
|
|
68193
|
+
},
|
|
68194
|
+
get objectUtil() {
|
|
68195
|
+
return objectUtil;
|
|
68196
|
+
},
|
|
68197
|
+
ZodParsedType,
|
|
68198
|
+
getParsedType,
|
|
68199
|
+
ZodType,
|
|
68200
|
+
ZodString,
|
|
68201
|
+
ZodNumber,
|
|
68202
|
+
ZodBigInt,
|
|
68203
|
+
ZodBoolean,
|
|
68204
|
+
ZodDate,
|
|
68205
|
+
ZodSymbol,
|
|
68206
|
+
ZodUndefined,
|
|
68207
|
+
ZodNull,
|
|
68208
|
+
ZodAny,
|
|
68209
|
+
ZodUnknown,
|
|
68210
|
+
ZodNever,
|
|
68211
|
+
ZodVoid,
|
|
68212
|
+
ZodArray,
|
|
68213
|
+
ZodObject,
|
|
68214
|
+
ZodUnion,
|
|
68215
|
+
ZodDiscriminatedUnion,
|
|
68216
|
+
ZodIntersection,
|
|
68217
|
+
ZodTuple,
|
|
68218
|
+
ZodRecord,
|
|
68219
|
+
ZodMap,
|
|
68220
|
+
ZodSet,
|
|
68221
|
+
ZodFunction,
|
|
68222
|
+
ZodLazy,
|
|
68223
|
+
ZodLiteral,
|
|
68224
|
+
ZodEnum,
|
|
68225
|
+
ZodNativeEnum,
|
|
68226
|
+
ZodPromise,
|
|
68227
|
+
ZodEffects,
|
|
68228
|
+
ZodTransformer: ZodEffects,
|
|
68229
|
+
ZodOptional,
|
|
68230
|
+
ZodNullable,
|
|
68231
|
+
ZodDefault,
|
|
68232
|
+
ZodCatch,
|
|
68233
|
+
ZodNaN,
|
|
68234
|
+
BRAND,
|
|
68235
|
+
ZodBranded,
|
|
68236
|
+
ZodPipeline,
|
|
68237
|
+
ZodReadonly,
|
|
68238
|
+
custom,
|
|
68239
|
+
Schema: ZodType,
|
|
68240
|
+
ZodSchema: ZodType,
|
|
68241
|
+
late,
|
|
68242
|
+
get ZodFirstPartyTypeKind() {
|
|
68243
|
+
return ZodFirstPartyTypeKind;
|
|
68244
|
+
},
|
|
68245
|
+
coerce,
|
|
68246
|
+
any: anyType,
|
|
68247
|
+
array: arrayType,
|
|
68248
|
+
bigint: bigIntType,
|
|
68249
|
+
boolean: booleanType,
|
|
68250
|
+
date: dateType,
|
|
68251
|
+
discriminatedUnion: discriminatedUnionType,
|
|
68252
|
+
effect: effectsType,
|
|
68253
|
+
"enum": enumType,
|
|
68254
|
+
"function": functionType,
|
|
68255
|
+
"instanceof": instanceOfType,
|
|
68256
|
+
intersection: intersectionType,
|
|
68257
|
+
lazy: lazyType,
|
|
68258
|
+
literal: literalType,
|
|
68259
|
+
map: mapType,
|
|
68260
|
+
nan: nanType,
|
|
68261
|
+
nativeEnum: nativeEnumType,
|
|
68262
|
+
never: neverType,
|
|
68263
|
+
"null": nullType,
|
|
68264
|
+
nullable: nullableType,
|
|
68265
|
+
number: numberType,
|
|
68266
|
+
object: objectType,
|
|
68267
|
+
oboolean,
|
|
68268
|
+
onumber,
|
|
68269
|
+
optional: optionalType,
|
|
68270
|
+
ostring,
|
|
68271
|
+
pipeline: pipelineType,
|
|
68272
|
+
preprocess: preprocessType,
|
|
68273
|
+
promise: promiseType,
|
|
68274
|
+
record: recordType,
|
|
68275
|
+
set: setType,
|
|
68276
|
+
strictObject: strictObjectType,
|
|
68277
|
+
string: stringType,
|
|
68278
|
+
symbol: symbolType,
|
|
68279
|
+
transformer: effectsType,
|
|
68280
|
+
tuple: tupleType,
|
|
68281
|
+
"undefined": undefinedType,
|
|
68282
|
+
union: unionType,
|
|
68283
|
+
unknown: unknownType,
|
|
68284
|
+
"void": voidType,
|
|
68285
|
+
NEVER,
|
|
68286
|
+
ZodIssueCode,
|
|
68287
|
+
quotelessJson,
|
|
68288
|
+
ZodError
|
|
68289
|
+
});
|
|
68290
|
+
const Session = z.union([
|
|
68291
|
+
z.object({
|
|
68292
|
+
id: z.string(),
|
|
68293
|
+
mode: z.literal("proxy"),
|
|
68294
|
+
full_name: z.string().optional().nullable(),
|
|
68295
|
+
username: z.string().optional().nullable(),
|
|
68296
|
+
avatar_url: z.string().url().optional().nullable(),
|
|
68297
|
+
enabled: z.boolean()
|
|
68298
|
+
}),
|
|
68299
|
+
z.object({
|
|
68300
|
+
mode: z.literal("local"),
|
|
68301
|
+
enabled: z.boolean().optional()
|
|
68302
|
+
}),
|
|
68303
|
+
z.object({
|
|
68304
|
+
mode: z.literal("unauthorized"),
|
|
68305
|
+
enabled: z.boolean().optional()
|
|
68306
|
+
})
|
|
68307
|
+
]);
|
|
68308
|
+
function useSession(api) {
|
|
68309
|
+
const [session, setSession] = reactExports.useState({
|
|
68310
|
+
status: "not-asked"
|
|
68311
|
+
});
|
|
68312
|
+
const [sessionResetId, setSessionResetId] = reactExports.useState(0);
|
|
68313
|
+
reactExports.useEffect(() => {
|
|
68314
|
+
setSession({ status: "loading" });
|
|
68315
|
+
api.getSession().then(async (res) => {
|
|
68316
|
+
try {
|
|
68317
|
+
if (result.isOk(res)) {
|
|
68318
|
+
const session2 = res.value;
|
|
68319
|
+
setSession({ status: "success", data: Session.parse(session2) });
|
|
68320
|
+
} else {
|
|
68321
|
+
if (res.error.statusCode === 401) {
|
|
68322
|
+
setSession({
|
|
68323
|
+
status: "success",
|
|
68324
|
+
data: {
|
|
68325
|
+
mode: "unauthorized"
|
|
68326
|
+
}
|
|
68327
|
+
});
|
|
68328
|
+
} else if (sessionResetId < 3) {
|
|
68329
|
+
setTimeout(() => {
|
|
68330
|
+
setSessionResetId(sessionResetId + 1);
|
|
68331
|
+
}, 200 * sessionResetId);
|
|
68332
|
+
} else {
|
|
68333
|
+
setSession({ status: "error", error: "Could not fetch session" });
|
|
68334
|
+
}
|
|
68335
|
+
}
|
|
68336
|
+
} catch (e) {
|
|
68337
|
+
console.error("Could not authorize:", e);
|
|
68338
|
+
setSession({
|
|
68339
|
+
status: "error",
|
|
68340
|
+
error: "Got an error while trying to get session"
|
|
68341
|
+
});
|
|
68342
|
+
}
|
|
68343
|
+
});
|
|
68344
|
+
}, [sessionResetId]);
|
|
68345
|
+
return session;
|
|
68346
|
+
}
|
|
64514
68347
|
const falsyToString = (value) => typeof value === "boolean" ? "".concat(value) : value === 0 ? "0" : value;
|
|
64515
68348
|
const cx = clsx;
|
|
64516
68349
|
const cva = (base, config) => {
|
|
@@ -73226,7 +77059,7 @@ const useValModuleFromPath = (sourcePath) => {
|
|
|
73226
77059
|
moduleSchema: resolvedPath.schema
|
|
73227
77060
|
};
|
|
73228
77061
|
};
|
|
73229
|
-
const ValFullscreen = ({
|
|
77062
|
+
const ValFullscreen = ({ api }) => {
|
|
73230
77063
|
var _a, _b;
|
|
73231
77064
|
const { "*": pathFromParams } = useParams();
|
|
73232
77065
|
const [modules, setModules] = reactExports.useState(null);
|
|
@@ -73235,8 +77068,8 @@ const ValFullscreen = ({ valApi }) => {
|
|
|
73235
77068
|
const [selectedModuleId] = selectedPath ? Internal.splitModuleIdAndModulePath(selectedPath) : [void 0, void 0];
|
|
73236
77069
|
const moduleSource = selectedModuleId && ((_a = modules == null ? void 0 : modules[selectedModuleId]) == null ? void 0 : _a.source);
|
|
73237
77070
|
const moduleSchema = selectedModuleId && ((_b = modules == null ? void 0 : modules[selectedModuleId]) == null ? void 0 : _b.schema);
|
|
73238
|
-
const fatalErrors = Object.entries(modules || {}).flatMap(([, module2]) => {
|
|
73239
|
-
return module2.errors ? module2.errors.fatal ? module2.errors.fatal : [] : [];
|
|
77071
|
+
const fatalErrors = Object.entries(modules || {}).flatMap(([id, module2]) => {
|
|
77072
|
+
return module2.errors ? module2.errors.fatal ? module2.errors.fatal.map((e) => ({ id, ...e })) : [] : [];
|
|
73240
77073
|
});
|
|
73241
77074
|
const validationErrors = Object.entries(modules || {}).flatMap(
|
|
73242
77075
|
([, module2]) => {
|
|
@@ -73245,9 +77078,9 @@ const ValFullscreen = ({ valApi }) => {
|
|
|
73245
77078
|
);
|
|
73246
77079
|
if (fatalErrors && fatalErrors.length > 0) {
|
|
73247
77080
|
const message = fatalErrors.length === 1 ? fatalErrors[0].message : `Multiple errors detected:
|
|
73248
|
-
${fatalErrors.map((f, i) => `${i + 1}. ${f.message}`).join("\n")}
|
|
77081
|
+
${fatalErrors.map((f, i) => `${i + 1}. [${f.id}]: ${f.message}`).join("\n")}
|
|
73249
77082
|
|
|
73250
|
-
Showing stack trace of:
|
|
77083
|
+
Showing stack trace of: 1. ${fatalErrors[0].message}`;
|
|
73251
77084
|
const error2 = new Error(message);
|
|
73252
77085
|
error2.stack = fatalErrors[0].stack;
|
|
73253
77086
|
throw error2;
|
|
@@ -73286,7 +77119,7 @@ Showing stack trace of: 0. ${fatalErrors[0].message}`;
|
|
|
73286
77119
|
}, []);
|
|
73287
77120
|
reactExports.useEffect(() => {
|
|
73288
77121
|
console.log("(Re)-fetching modules");
|
|
73289
|
-
|
|
77122
|
+
api.getTree({ patch: true, includeSchema: true, includeSource: true }).then((res) => {
|
|
73290
77123
|
if (result.isOk(res)) {
|
|
73291
77124
|
setModules(res.value.modules);
|
|
73292
77125
|
} else {
|
|
@@ -73295,35 +77128,32 @@ Showing stack trace of: 0. ${fatalErrors[0].message}`;
|
|
|
73295
77128
|
}
|
|
73296
77129
|
});
|
|
73297
77130
|
}, [hmrHash]);
|
|
77131
|
+
const session = useSession(api);
|
|
73298
77132
|
const navigate = useNavigate();
|
|
73299
77133
|
const [theme2, setTheme] = useTheme();
|
|
73300
|
-
|
|
73301
|
-
const popStateListener = (event) => {
|
|
73302
|
-
console.log("popstate", event);
|
|
73303
|
-
};
|
|
73304
|
-
window.addEventListener("popstate", popStateListener);
|
|
73305
|
-
return () => {
|
|
73306
|
-
window.removeEventListener("popstate", popStateListener);
|
|
73307
|
-
};
|
|
73308
|
-
}, []);
|
|
77134
|
+
const { patches, setPatchResetId } = usePatches(session, api);
|
|
73309
77135
|
const hoverElemRef = React.useRef(null);
|
|
73310
77136
|
const initOnSubmit = reactExports.useCallback(
|
|
73311
77137
|
(path) => async (callback) => {
|
|
73312
77138
|
const [moduleId, modulePath] = Internal.splitModuleIdAndModulePath(path);
|
|
73313
77139
|
const patch = await callback(Internal.createPatchJSONPath(modulePath));
|
|
73314
|
-
return
|
|
77140
|
+
return api.postPatches(moduleId, patch).then((res) => {
|
|
73315
77141
|
if (result.isErr(res)) {
|
|
73316
77142
|
throw res.error;
|
|
73317
77143
|
} else {
|
|
73318
77144
|
if (!hmrHash) {
|
|
73319
|
-
|
|
77145
|
+
setPatchResetId((prev) => prev + 1);
|
|
77146
|
+
return api.getTree({
|
|
73320
77147
|
treePath: moduleId,
|
|
73321
77148
|
patch: true,
|
|
73322
77149
|
includeSchema: true,
|
|
73323
77150
|
includeSource: true
|
|
73324
77151
|
}).then((res2) => {
|
|
73325
77152
|
if (result.isOk(res2)) {
|
|
73326
|
-
setModules(
|
|
77153
|
+
setModules((modules2) => ({
|
|
77154
|
+
...modules2,
|
|
77155
|
+
...res2.value.modules
|
|
77156
|
+
}));
|
|
73327
77157
|
} else {
|
|
73328
77158
|
setError("Could not load modules: " + res2.error.message);
|
|
73329
77159
|
console.error(res2.error);
|
|
@@ -73343,9 +77173,9 @@ Showing stack trace of: 0. ${fatalErrors[0].message}`;
|
|
|
73343
77173
|
value: {
|
|
73344
77174
|
theme: theme2,
|
|
73345
77175
|
setTheme,
|
|
73346
|
-
api
|
|
77176
|
+
api,
|
|
73347
77177
|
editMode: "full",
|
|
73348
|
-
session
|
|
77178
|
+
session,
|
|
73349
77179
|
highlight: false,
|
|
73350
77180
|
setHighlight: () => {
|
|
73351
77181
|
},
|
|
@@ -73361,7 +77191,14 @@ Showing stack trace of: 0. ${fatalErrors[0].message}`;
|
|
|
73361
77191
|
className: "relative font-serif antialiased",
|
|
73362
77192
|
"data-mode": theme2,
|
|
73363
77193
|
children: [
|
|
73364
|
-
/* @__PURE__ */ jsxRuntimeExports.jsx("div", { className: "fixed -translate-x-1/2 z-overlay left-1/2 bottom-4", children: /* @__PURE__ */ jsxRuntimeExports.jsx(
|
|
77194
|
+
/* @__PURE__ */ jsxRuntimeExports.jsx("div", { className: "fixed -translate-x-1/2 z-overlay left-1/2 bottom-4", children: /* @__PURE__ */ jsxRuntimeExports.jsx(
|
|
77195
|
+
ValMenu,
|
|
77196
|
+
{
|
|
77197
|
+
api,
|
|
77198
|
+
patches,
|
|
77199
|
+
onCommit: () => setPatchResetId((prev) => prev + 1)
|
|
77200
|
+
}
|
|
77201
|
+
) }),
|
|
73365
77202
|
/* @__PURE__ */ jsxRuntimeExports.jsx("div", { id: "val-fullscreen-hover", ref: hoverElemRef }),
|
|
73366
77203
|
/* @__PURE__ */ jsxRuntimeExports.jsx(
|
|
73367
77204
|
ValFullscreenHoverContext.Provider,
|
|
@@ -75485,7 +79322,7 @@ function App() {
|
|
|
75485
79322
|
[
|
|
75486
79323
|
{
|
|
75487
79324
|
path: "/*",
|
|
75488
|
-
element: /* @__PURE__ */ jsxRuntimeExports.jsx(ErrorBoundary, { fallbackRender, children: /* @__PURE__ */ jsxRuntimeExports.jsx(ValFullscreen, {
|
|
79325
|
+
element: /* @__PURE__ */ jsxRuntimeExports.jsx(ErrorBoundary, { fallbackRender, children: /* @__PURE__ */ jsxRuntimeExports.jsx(ValFullscreen, { api: new ValApi("/api/val") }) })
|
|
75489
79326
|
}
|
|
75490
79327
|
],
|
|
75491
79328
|
{
|