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