@digipair/skill-ollama
Version:
1,321 lines (1,317 loc) • 2.38 MB
JavaScript
function _define_property$M(obj, key, value) {
if (key in obj) {
Object.defineProperty(obj, key, {
value: value,
enumerable: true,
configurable: true,
writable: true
});
} else {
obj[key] = value;
}
return obj;
}
function _object_spread$L(target) {
for(var i = 1; i < arguments.length; i++){
var source = arguments[i] != null ? arguments[i] : {};
var ownKeys = Object.keys(source);
if (typeof Object.getOwnPropertySymbols === "function") {
ownKeys = ownKeys.concat(Object.getOwnPropertySymbols(source).filter(function(sym) {
return Object.getOwnPropertyDescriptor(source, sym).enumerable;
}));
}
ownKeys.forEach(function(key) {
_define_property$M(target, key, source[key]);
});
}
return target;
}
function ownKeys$w(object, enumerableOnly) {
var keys = Object.keys(object);
if (Object.getOwnPropertySymbols) {
var symbols = Object.getOwnPropertySymbols(object);
if (enumerableOnly) {
symbols = symbols.filter(function(sym) {
return Object.getOwnPropertyDescriptor(object, sym).enumerable;
});
}
keys.push.apply(keys, symbols);
}
return keys;
}
function _object_spread_props$w(target, source) {
source = source != null ? source : {};
if (Object.getOwnPropertyDescriptors) {
Object.defineProperties(target, Object.getOwnPropertyDescriptors(source));
} else {
ownKeys$w(Object(source)).forEach(function(key) {
Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key));
});
}
return target;
}
var ignoreOverride = Symbol("Let zodToJsonSchema decide on which parser to use");
var defaultOptions$1 = {
name: undefined,
$refStrategy: "root",
basePath: [
"#"
],
effectStrategy: "input",
pipeStrategy: "all",
dateStrategy: "format:date-time",
mapStrategy: "entries",
removeAdditionalStrategy: "passthrough",
definitionPath: "definitions",
target: "jsonSchema7",
strictUnions: false,
definitions: {},
errorMessages: false,
markdownDescription: false,
patternStrategy: "escape",
applyRegexFlags: false,
emailStrategy: "format:email",
base64Strategy: "contentEncoding:base64",
nameStrategy: "ref"
};
var getDefaultOptions = function(options) {
return typeof options === "string" ? _object_spread_props$w(_object_spread$L({}, defaultOptions$1), {
name: options
}) : _object_spread$L({}, defaultOptions$1, options);
};
function _array_like_to_array$G(arr, len) {
if (len == null || len > arr.length) len = arr.length;
for(var i = 0, arr2 = new Array(len); i < len; i++)arr2[i] = arr[i];
return arr2;
}
function _array_with_holes$m(arr) {
if (Array.isArray(arr)) return arr;
}
function _array_without_holes$y(arr) {
if (Array.isArray(arr)) return _array_like_to_array$G(arr);
}
function _define_property$L(obj, key, value) {
if (key in obj) {
Object.defineProperty(obj, key, {
value: value,
enumerable: true,
configurable: true,
writable: true
});
} else {
obj[key] = value;
}
return obj;
}
function _iterable_to_array$y(iter) {
if (typeof Symbol !== "undefined" && iter[Symbol.iterator] != null || iter["@@iterator"] != null) return Array.from(iter);
}
function _iterable_to_array_limit$m(arr, i) {
var _i = arr == null ? null : typeof Symbol !== "undefined" && arr[Symbol.iterator] || arr["@@iterator"];
if (_i == null) return;
var _arr = [];
var _n = true;
var _d = false;
var _s, _e;
try {
for(_i = _i.call(arr); !(_n = (_s = _i.next()).done); _n = true){
_arr.push(_s.value);
if (i && _arr.length === i) break;
}
} catch (err) {
_d = true;
_e = err;
} finally{
try {
if (!_n && _i["return"] != null) _i["return"]();
} finally{
if (_d) throw _e;
}
}
return _arr;
}
function _non_iterable_rest$m() {
throw new TypeError("Invalid attempt to destructure non-iterable instance.\\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.");
}
function _non_iterable_spread$y() {
throw new TypeError("Invalid attempt to spread non-iterable instance.\\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.");
}
function _object_spread$K(target) {
for(var i = 1; i < arguments.length; i++){
var source = arguments[i] != null ? arguments[i] : {};
var ownKeys = Object.keys(source);
if (typeof Object.getOwnPropertySymbols === "function") {
ownKeys = ownKeys.concat(Object.getOwnPropertySymbols(source).filter(function(sym) {
return Object.getOwnPropertyDescriptor(source, sym).enumerable;
}));
}
ownKeys.forEach(function(key) {
_define_property$L(target, key, source[key]);
});
}
return target;
}
function ownKeys$v(object, enumerableOnly) {
var keys = Object.keys(object);
if (Object.getOwnPropertySymbols) {
var symbols = Object.getOwnPropertySymbols(object);
if (enumerableOnly) {
symbols = symbols.filter(function(sym) {
return Object.getOwnPropertyDescriptor(object, sym).enumerable;
});
}
keys.push.apply(keys, symbols);
}
return keys;
}
function _object_spread_props$v(target, source) {
source = source != null ? source : {};
if (Object.getOwnPropertyDescriptors) {
Object.defineProperties(target, Object.getOwnPropertyDescriptors(source));
} else {
ownKeys$v(Object(source)).forEach(function(key) {
Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key));
});
}
return target;
}
function _sliced_to_array$m(arr, i) {
return _array_with_holes$m(arr) || _iterable_to_array_limit$m(arr, i) || _unsupported_iterable_to_array$G(arr, i) || _non_iterable_rest$m();
}
function _to_consumable_array$y(arr) {
return _array_without_holes$y(arr) || _iterable_to_array$y(arr) || _unsupported_iterable_to_array$G(arr) || _non_iterable_spread$y();
}
function _unsupported_iterable_to_array$G(o, minLen) {
if (!o) return;
if (typeof o === "string") return _array_like_to_array$G(o, minLen);
var n = Object.prototype.toString.call(o).slice(8, -1);
if (n === "Object" && o.constructor) n = o.constructor.name;
if (n === "Map" || n === "Set") return Array.from(n);
if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _array_like_to_array$G(o, minLen);
}
var getRefs = function(options) {
var _options = getDefaultOptions(options);
var currentPath = _options.name !== undefined ? _to_consumable_array$y(_options.basePath).concat([
_options.definitionPath,
_options.name
]) : _options.basePath;
return _object_spread_props$v(_object_spread$K({}, _options), {
currentPath: currentPath,
propertyPath: undefined,
seen: new Map(Object.entries(_options.definitions).map(function(param) {
var _param = _sliced_to_array$m(param, 2), name = _param[0], def = _param[1];
return [
def._def,
{
def: def._def,
path: _to_consumable_array$y(_options.basePath).concat([
_options.definitionPath,
name
]),
// Resolution of references will be forced even though seen, so it's ok that the schema is undefined here for now.
jsonSchema: undefined
}
];
}))
});
};
function _define_property$K(obj, key, value) {
if (key in obj) {
Object.defineProperty(obj, key, {
value: value,
enumerable: true,
configurable: true,
writable: true
});
} else {
obj[key] = value;
}
return obj;
}
function _object_spread$J(target) {
for(var i = 1; i < arguments.length; i++){
var source = arguments[i] != null ? arguments[i] : {};
var ownKeys = Object.keys(source);
if (typeof Object.getOwnPropertySymbols === "function") {
ownKeys = ownKeys.concat(Object.getOwnPropertySymbols(source).filter(function(sym) {
return Object.getOwnPropertyDescriptor(source, sym).enumerable;
}));
}
ownKeys.forEach(function(key) {
_define_property$K(target, key, source[key]);
});
}
return target;
}
function ownKeys$u(object, enumerableOnly) {
var keys = Object.keys(object);
if (Object.getOwnPropertySymbols) {
var symbols = Object.getOwnPropertySymbols(object);
if (enumerableOnly) {
symbols = symbols.filter(function(sym) {
return Object.getOwnPropertyDescriptor(object, sym).enumerable;
});
}
keys.push.apply(keys, symbols);
}
return keys;
}
function _object_spread_props$u(target, source) {
source = source != null ? source : {};
if (Object.getOwnPropertyDescriptors) {
Object.defineProperties(target, Object.getOwnPropertyDescriptors(source));
} else {
ownKeys$u(Object(source)).forEach(function(key) {
Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key));
});
}
return target;
}
function addErrorMessage(res, key, errorMessage, refs) {
if (!(refs === null || refs === void 0 ? void 0 : refs.errorMessages)) return;
if (errorMessage) {
res.errorMessage = _object_spread_props$u(_object_spread$J({}, res.errorMessage), _define_property$K({}, key, errorMessage));
}
}
function setResponseValueAndErrors(res, key, value, errorMessage, refs) {
res[key] = value;
addErrorMessage(res, key, errorMessage, refs);
}
function _array_like_to_array$F(arr, len) {
if (len == null || len > arr.length) len = arr.length;
for(var i = 0, arr2 = new Array(len); i < len; i++)arr2[i] = arr[i];
return arr2;
}
function _array_with_holes$l(arr) {
if (Array.isArray(arr)) return arr;
}
function _array_without_holes$x(arr) {
if (Array.isArray(arr)) return _array_like_to_array$F(arr);
}
function _assert_this_initialized$u(self) {
if (self === void 0) {
throw new ReferenceError("this hasn't been initialised - super() hasn't been called");
}
return self;
}
function asyncGeneratorStep$s(gen, resolve, reject, _next, _throw, key, arg) {
try {
var info = gen[key](arg);
var value = info.value;
} catch (error) {
reject(error);
return;
}
if (info.done) {
resolve(value);
} else {
Promise.resolve(value).then(_next, _throw);
}
}
function _async_to_generator$s(fn) {
return function() {
var self = this, args = arguments;
return new Promise(function(resolve, reject) {
var gen = fn.apply(self, args);
function _next(value) {
asyncGeneratorStep$s(gen, resolve, reject, _next, _throw, "next", value);
}
function _throw(err) {
asyncGeneratorStep$s(gen, resolve, reject, _next, _throw, "throw", err);
}
_next(undefined);
});
};
}
function _class_call_check$K(instance, Constructor) {
if (!(instance instanceof Constructor)) {
throw new TypeError("Cannot call a class as a function");
}
}
function _construct$6(Parent, args, Class) {
if (_is_native_reflect_construct$u()) {
_construct$6 = Reflect.construct;
} else {
_construct$6 = function construct(Parent, args, Class) {
var a = [
null
];
a.push.apply(a, args);
var Constructor = Function.bind.apply(Parent, a);
var instance = new Constructor();
if (Class) _set_prototype_of$u(instance, Class.prototype);
return instance;
};
}
return _construct$6.apply(null, arguments);
}
function _defineProperties$E(target, props) {
for(var i = 0; i < props.length; i++){
var descriptor = props[i];
descriptor.enumerable = descriptor.enumerable || false;
descriptor.configurable = true;
if ("value" in descriptor) descriptor.writable = true;
Object.defineProperty(target, descriptor.key, descriptor);
}
}
function _create_class$E(Constructor, protoProps, staticProps) {
if (protoProps) _defineProperties$E(Constructor.prototype, protoProps);
if (staticProps) _defineProperties$E(Constructor, staticProps);
return Constructor;
}
function _define_property$J(obj, key, value) {
if (key in obj) {
Object.defineProperty(obj, key, {
value: value,
enumerable: true,
configurable: true,
writable: true
});
} else {
obj[key] = value;
}
return obj;
}
function _get_prototype_of$u(o) {
_get_prototype_of$u = Object.setPrototypeOf ? Object.getPrototypeOf : function getPrototypeOf(o) {
return o.__proto__ || Object.getPrototypeOf(o);
};
return _get_prototype_of$u(o);
}
function _inherits$u(subClass, superClass) {
if (typeof superClass !== "function" && superClass !== null) {
throw new TypeError("Super expression must either be null or a function");
}
subClass.prototype = Object.create(superClass && superClass.prototype, {
constructor: {
value: subClass,
writable: true,
configurable: true
}
});
if (superClass) _set_prototype_of$u(subClass, superClass);
}
function _instanceof$i(left, right) {
if (right != null && typeof Symbol !== "undefined" && right[Symbol.hasInstance]) {
return !!right[Symbol.hasInstance](left);
} else {
return left instanceof right;
}
}
function _is_native_function$6(fn) {
return Function.toString.call(fn).indexOf("[native code]") !== -1;
}
function _iterable_to_array$x(iter) {
if (typeof Symbol !== "undefined" && iter[Symbol.iterator] != null || iter["@@iterator"] != null) return Array.from(iter);
}
function _iterable_to_array_limit$l(arr, i) {
var _i = arr == null ? null : typeof Symbol !== "undefined" && arr[Symbol.iterator] || arr["@@iterator"];
if (_i == null) return;
var _arr = [];
var _n = true;
var _d = false;
var _s, _e;
try {
for(_i = _i.call(arr); !(_n = (_s = _i.next()).done); _n = true){
_arr.push(_s.value);
if (i && _arr.length === i) break;
}
} catch (err) {
_d = true;
_e = err;
} finally{
try {
if (!_n && _i["return"] != null) _i["return"]();
} finally{
if (_d) throw _e;
}
}
return _arr;
}
function _non_iterable_rest$l() {
throw new TypeError("Invalid attempt to destructure non-iterable instance.\\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.");
}
function _non_iterable_spread$x() {
throw new TypeError("Invalid attempt to spread non-iterable instance.\\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.");
}
function _object_spread$I(target) {
for(var i = 1; i < arguments.length; i++){
var source = arguments[i] != null ? arguments[i] : {};
var ownKeys = Object.keys(source);
if (typeof Object.getOwnPropertySymbols === "function") {
ownKeys = ownKeys.concat(Object.getOwnPropertySymbols(source).filter(function(sym) {
return Object.getOwnPropertyDescriptor(source, sym).enumerable;
}));
}
ownKeys.forEach(function(key) {
_define_property$J(target, key, source[key]);
});
}
return target;
}
function ownKeys$t(object, enumerableOnly) {
var keys = Object.keys(object);
if (Object.getOwnPropertySymbols) {
var symbols = Object.getOwnPropertySymbols(object);
if (enumerableOnly) {
symbols = symbols.filter(function(sym) {
return Object.getOwnPropertyDescriptor(object, sym).enumerable;
});
}
keys.push.apply(keys, symbols);
}
return keys;
}
function _object_spread_props$t(target, source) {
source = source != null ? source : {};
if (Object.getOwnPropertyDescriptors) {
Object.defineProperties(target, Object.getOwnPropertyDescriptors(source));
} else {
ownKeys$t(Object(source)).forEach(function(key) {
Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key));
});
}
return target;
}
function _possible_constructor_return$u(self, call) {
if (call && (_type_of$C(call) === "object" || typeof call === "function")) {
return call;
}
return _assert_this_initialized$u(self);
}
function _set_prototype_of$u(o, p) {
_set_prototype_of$u = Object.setPrototypeOf || function setPrototypeOf(o, p) {
o.__proto__ = p;
return o;
};
return _set_prototype_of$u(o, p);
}
function _sliced_to_array$l(arr, i) {
return _array_with_holes$l(arr) || _iterable_to_array_limit$l(arr, i) || _unsupported_iterable_to_array$F(arr, i) || _non_iterable_rest$l();
}
function _to_consumable_array$x(arr) {
return _array_without_holes$x(arr) || _iterable_to_array$x(arr) || _unsupported_iterable_to_array$F(arr) || _non_iterable_spread$x();
}
function _type_of$C(obj) {
"@swc/helpers - typeof";
return obj && typeof Symbol !== "undefined" && obj.constructor === Symbol ? "symbol" : typeof obj;
}
function _unsupported_iterable_to_array$F(o, minLen) {
if (!o) return;
if (typeof o === "string") return _array_like_to_array$F(o, minLen);
var n = Object.prototype.toString.call(o).slice(8, -1);
if (n === "Object" && o.constructor) n = o.constructor.name;
if (n === "Map" || n === "Set") return Array.from(n);
if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _array_like_to_array$F(o, minLen);
}
function _wrap_native_super$6(Class) {
var _cache = typeof Map === "function" ? new Map() : undefined;
_wrap_native_super$6 = function wrapNativeSuper(Class) {
if (Class === null || !_is_native_function$6(Class)) return Class;
if (typeof Class !== "function") {
throw new TypeError("Super expression must either be null or a function");
}
if (typeof _cache !== "undefined") {
if (_cache.has(Class)) return _cache.get(Class);
_cache.set(Class, Wrapper);
}
function Wrapper() {
return _construct$6(Class, arguments, _get_prototype_of$u(this).constructor);
}
Wrapper.prototype = Object.create(Class.prototype, {
constructor: {
value: Wrapper,
enumerable: false,
writable: true,
configurable: true
}
});
return _set_prototype_of$u(Wrapper, Class);
};
return _wrap_native_super$6(Class);
}
function _is_native_reflect_construct$u() {
if (typeof Reflect === "undefined" || !Reflect.construct) return false;
if (Reflect.construct.sham) return false;
if (typeof Proxy === "function") return true;
try {
Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function() {}));
return true;
} catch (e) {
return false;
}
}
function _create_super$u(Derived) {
var hasNativeReflectConstruct = _is_native_reflect_construct$u();
return function _createSuperInternal() {
var Super = _get_prototype_of$u(Derived), result;
if (hasNativeReflectConstruct) {
var NewTarget = _get_prototype_of$u(this).constructor;
result = Reflect.construct(Super, arguments, NewTarget);
} else {
result = Super.apply(this, arguments);
}
return _possible_constructor_return$u(this, result);
};
}
function _ts_generator$u(thisArg, body) {
var f, y, t, g, _ = {
label: 0,
sent: function() {
if (t[0] & 1) throw t[1];
return t[1];
},
trys: [],
ops: []
};
return g = {
next: verb(0),
"throw": verb(1),
"return": verb(2)
}, typeof Symbol === "function" && (g[Symbol.iterator] = function() {
return this;
}), g;
function verb(n) {
return function(v) {
return step([
n,
v
]);
};
}
function step(op) {
if (f) throw new TypeError("Generator is already executing.");
while(_)try {
if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
if (y = 0, t) op = [
op[0] & 2,
t.value
];
switch(op[0]){
case 0:
case 1:
t = op;
break;
case 4:
_.label++;
return {
value: op[1],
done: false
};
case 5:
_.label++;
y = op[1];
op = [
0
];
continue;
case 7:
op = _.ops.pop();
_.trys.pop();
continue;
default:
if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) {
_ = 0;
continue;
}
if (op[0] === 3 && (!t || op[1] > t[0] && op[1] < t[3])) {
_.label = op[1];
break;
}
if (op[0] === 6 && _.label < t[1]) {
_.label = t[1];
t = op;
break;
}
if (t && _.label < t[2]) {
_.label = t[2];
_.ops.push(op);
break;
}
if (t[2]) _.ops.pop();
_.trys.pop();
continue;
}
op = body.call(thisArg, _);
} catch (e) {
op = [
6,
e
];
y = 0;
} finally{
f = t = 0;
}
if (op[0] & 5) throw op[1];
return {
value: op[0] ? op[1] : void 0,
done: true
};
}
}
var util;
(function(util) {
util.assertEqual = function(val) {
return val;
};
function assertIs(_arg) {}
util.assertIs = assertIs;
function assertNever(_x) {
throw new Error();
}
util.assertNever = assertNever;
util.arrayToEnum = function(items) {
var obj = {};
var _iteratorNormalCompletion = true, _didIteratorError = false, _iteratorError = undefined;
try {
for(var _iterator = items[Symbol.iterator](), _step; !(_iteratorNormalCompletion = (_step = _iterator.next()).done); _iteratorNormalCompletion = true){
var item = _step.value;
obj[item] = item;
}
} catch (err) {
_didIteratorError = true;
_iteratorError = err;
} finally{
try {
if (!_iteratorNormalCompletion && _iterator.return != null) {
_iterator.return();
}
} finally{
if (_didIteratorError) {
throw _iteratorError;
}
}
}
return obj;
};
util.getValidEnumValues = function(obj) {
var validKeys = util.objectKeys(obj).filter(function(k) {
return typeof obj[obj[k]] !== "number";
});
var filtered = {};
var _iteratorNormalCompletion = true, _didIteratorError = false, _iteratorError = undefined;
try {
for(var _iterator = validKeys[Symbol.iterator](), _step; !(_iteratorNormalCompletion = (_step = _iterator.next()).done); _iteratorNormalCompletion = true){
var k = _step.value;
filtered[k] = obj[k];
}
} catch (err) {
_didIteratorError = true;
_iteratorError = err;
} finally{
try {
if (!_iteratorNormalCompletion && _iterator.return != null) {
_iterator.return();
}
} finally{
if (_didIteratorError) {
throw _iteratorError;
}
}
}
return util.objectValues(filtered);
};
util.objectValues = function(obj) {
return util.objectKeys(obj).map(function(e) {
return obj[e];
});
};
util.objectKeys = typeof Object.keys === "function" // eslint-disable-line ban/ban
? function(obj) {
return Object.keys(obj) // eslint-disable-line ban/ban
;
} : function(object) {
var keys = [];
for(var key in object){
if (Object.prototype.hasOwnProperty.call(object, key)) {
keys.push(key);
}
}
return keys;
};
util.find = function(arr, checker) {
var _iteratorNormalCompletion = true, _didIteratorError = false, _iteratorError = undefined;
try {
for(var _iterator = arr[Symbol.iterator](), _step; !(_iteratorNormalCompletion = (_step = _iterator.next()).done); _iteratorNormalCompletion = true){
var item = _step.value;
if (checker(item)) return item;
}
} catch (err) {
_didIteratorError = true;
_iteratorError = err;
} finally{
try {
if (!_iteratorNormalCompletion && _iterator.return != null) {
_iterator.return();
}
} finally{
if (_didIteratorError) {
throw _iteratorError;
}
}
}
return undefined;
};
util.isInteger = typeof Number.isInteger === "function" ? function(val) {
return Number.isInteger(val) // eslint-disable-line ban/ban
;
} : function(val) {
return typeof val === "number" && isFinite(val) && Math.floor(val) === val;
};
function joinValues(array) {
var separator = arguments.length > 1 && arguments[1] !== void 0 ? arguments[1] : " | ";
return array.map(function(val) {
return typeof val === "string" ? "'".concat(val, "'") : val;
}).join(separator);
}
util.joinValues = joinValues;
util.jsonStringifyReplacer = function(_, value) {
if ((typeof value === "undefined" ? "undefined" : _type_of$C(value)) === "bigint") {
return value.toString();
}
return value;
};
})(util || (util = {}));
var objectUtil;
(function(objectUtil) {
objectUtil.mergeShapes = function(first, second) {
return _object_spread$I({}, first, second);
};
})(objectUtil || (objectUtil = {}));
var ZodParsedType = util.arrayToEnum([
"string",
"nan",
"number",
"integer",
"float",
"boolean",
"date",
"bigint",
"symbol",
"function",
"undefined",
"null",
"array",
"object",
"unknown",
"promise",
"void",
"never",
"map",
"set"
]);
var getParsedType = function(data) {
var t = typeof data === "undefined" ? "undefined" : _type_of$C(data);
switch(t){
case "undefined":
return ZodParsedType.undefined;
case "string":
return ZodParsedType.string;
case "number":
return isNaN(data) ? ZodParsedType.nan : ZodParsedType.number;
case "boolean":
return ZodParsedType.boolean;
case "function":
return ZodParsedType.function;
case "bigint":
return ZodParsedType.bigint;
case "symbol":
return ZodParsedType.symbol;
case "object":
if (Array.isArray(data)) {
return ZodParsedType.array;
}
if (data === null) {
return ZodParsedType.null;
}
if (data.then && typeof data.then === "function" && data.catch && typeof data.catch === "function") {
return ZodParsedType.promise;
}
if (typeof Map !== "undefined" && _instanceof$i(data, Map)) {
return ZodParsedType.map;
}
if (typeof Set !== "undefined" && _instanceof$i(data, Set)) {
return ZodParsedType.set;
}
if (typeof Date !== "undefined" && _instanceof$i(data, Date)) {
return ZodParsedType.date;
}
return ZodParsedType.object;
default:
return ZodParsedType.unknown;
}
};
var ZodIssueCode = util.arrayToEnum([
"invalid_type",
"invalid_literal",
"custom",
"invalid_union",
"invalid_union_discriminator",
"invalid_enum_value",
"unrecognized_keys",
"invalid_arguments",
"invalid_return_type",
"invalid_date",
"invalid_string",
"too_small",
"too_big",
"invalid_intersection_types",
"not_multiple_of",
"not_finite"
]);
var quotelessJson = function(obj) {
var json = JSON.stringify(obj, null, 2);
return json.replace(/"([^"]+)":/g, "$1:");
};
var ZodError = /*#__PURE__*/ function _target(Error1) {
_inherits$u(ZodError, Error1);
var _super = _create_super$u(ZodError);
function ZodError(issues) {
_class_call_check$K(this, ZodError);
var _this;
_this = _super.call(this);
_this.issues = [];
_this.addIssue = function(sub) {
_this.issues = _to_consumable_array$x(_this.issues).concat([
sub
]);
};
_this.addIssues = function() {
var subs = arguments.length > 0 && arguments[0] !== void 0 ? arguments[0] : [];
_this.issues = _to_consumable_array$x(_this.issues).concat(_to_consumable_array$x(subs));
};
var actualProto = (_instanceof$i(this, ZodError) ? this.constructor : void 0).prototype;
if (Object.setPrototypeOf) {
// eslint-disable-next-line ban/ban
Object.setPrototypeOf(_assert_this_initialized$u(_this), actualProto);
} else {
_this.__proto__ = actualProto;
}
_this.name = "ZodError";
_this.issues = issues;
return _this;
}
_create_class$E(ZodError, [
{
key: "errors",
get: function get() {
return this.issues;
}
},
{
key: "format",
value: function format(_mapper) {
var mapper = _mapper || function(issue) {
return issue.message;
};
var fieldErrors = {
_errors: []
};
var processError = function(error) {
var _iteratorNormalCompletion = true, _didIteratorError = false, _iteratorError = undefined;
try {
for(var _iterator = error.issues[Symbol.iterator](), _step; !(_iteratorNormalCompletion = (_step = _iterator.next()).done); _iteratorNormalCompletion = true){
var issue = _step.value;
if (issue.code === "invalid_union") {
issue.unionErrors.map(processError);
} else if (issue.code === "invalid_return_type") {
processError(issue.returnTypeError);
} else if (issue.code === "invalid_arguments") {
processError(issue.argumentsError);
} else if (issue.path.length === 0) {
fieldErrors._errors.push(mapper(issue));
} else {
var curr = fieldErrors;
var i = 0;
while(i < issue.path.length){
var el = issue.path[i];
var terminal = i === issue.path.length - 1;
if (!terminal) {
curr[el] = curr[el] || {
_errors: []
};
// if (typeof el === "string") {
// curr[el] = curr[el] || { _errors: [] };
// } else if (typeof el === "number") {
// const errorArray: any = [];
// errorArray._errors = [];
// curr[el] = curr[el] || errorArray;
// }
} else {
curr[el] = curr[el] || {
_errors: []
};
curr[el]._errors.push(mapper(issue));
}
curr = curr[el];
i++;
}
}
}
} catch (err) {
_didIteratorError = true;
_iteratorError = err;
} finally{
try {
if (!_iteratorNormalCompletion && _iterator.return != null) {
_iterator.return();
}
} finally{
if (_didIteratorError) {
throw _iteratorError;
}
}
}
};
processError(this);
return fieldErrors;
}
},
{
key: "toString",
value: function toString() {
return this.message;
}
},
{
key: "message",
get: function get() {
return JSON.stringify(this.issues, util.jsonStringifyReplacer, 2);
}
},
{
key: "isEmpty",
get: function get() {
return this.issues.length === 0;
}
},
{
key: "flatten",
value: function flatten() {
var mapper = arguments.length > 0 && arguments[0] !== void 0 ? arguments[0] : function(issue) {
return issue.message;
};
var fieldErrors = {};
var formErrors = [];
var _iteratorNormalCompletion = true, _didIteratorError = false, _iteratorError = undefined;
try {
for(var _iterator = this.issues[Symbol.iterator](), _step; !(_iteratorNormalCompletion = (_step = _iterator.next()).done); _iteratorNormalCompletion = true){
var sub = _step.value;
if (sub.path.length > 0) {
fieldErrors[sub.path[0]] = fieldErrors[sub.path[0]] || [];
fieldErrors[sub.path[0]].push(mapper(sub));
} else {
formErrors.push(mapper(sub));
}
}
} catch (err) {
_didIteratorError = true;
_iteratorError = err;
} finally{
try {
if (!_iteratorNormalCompletion && _iterator.return != null) {
_iterator.return();
}
} finally{
if (_didIteratorError) {
throw _iteratorError;
}
}
}
return {
formErrors: formErrors,
fieldErrors: fieldErrors
};
}
},
{
key: "formErrors",
get: function get() {
return this.flatten();
}
}
], [
{
key: "assert",
value: function assert(value) {
if (!_instanceof$i(value, ZodError)) {
throw new Error("Not a ZodError: ".concat(value));
}
}
}
]);
return ZodError;
}(_wrap_native_super$6(Error));
ZodError.create = function(issues) {
var error = new ZodError(issues);
return error;
};
var errorMap = function(issue, _ctx) {
var message;
switch(issue.code){
case ZodIssueCode.invalid_type:
if (issue.received === ZodParsedType.undefined) {
message = "Required";
} else {
message = "Expected ".concat(issue.expected, ", received ").concat(issue.received);
}
break;
case ZodIssueCode.invalid_literal:
message = "Invalid literal value, expected ".concat(JSON.stringify(issue.expected, util.jsonStringifyReplacer));
break;
case ZodIssueCode.unrecognized_keys:
message = "Unrecognized key(s) in object: ".concat(util.joinValues(issue.keys, ", "));
break;
case ZodIssueCode.invalid_union:
message = "Invalid input";
break;
case ZodIssueCode.invalid_union_discriminator:
message = "Invalid discriminator value. Expected ".concat(util.joinValues(issue.options));
break;
case ZodIssueCode.invalid_enum_value:
message = "Invalid enum value. Expected ".concat(util.joinValues(issue.options), ", received '").concat(issue.received, "'");
break;
case ZodIssueCode.invalid_arguments:
message = "Invalid function arguments";
break;
case ZodIssueCode.invalid_return_type:
message = "Invalid function return type";
break;
case ZodIssueCode.invalid_date:
message = "Invalid date";
break;
case ZodIssueCode.invalid_string:
if (typeof issue.validation === "object") {
if ("includes" in issue.validation) {
message = 'Invalid input: must include "'.concat(issue.validation.includes, '"');
if (typeof issue.validation.position === "number") {
message = "".concat(message, " at one or more positions greater than or equal to ").concat(issue.validation.position);
}
} else if ("startsWith" in issue.validation) {
message = 'Invalid input: must start with "'.concat(issue.validation.startsWith, '"');
} else if ("endsWith" in issue.validation) {
message = 'Invalid input: must end with "'.concat(issue.validation.endsWith, '"');
} else {
util.assertNever(issue.validation);
}
} else if (issue.validation !== "regex") {
message = "Invalid ".concat(issue.validation);
} else {
message = "Invalid";
}
break;
case ZodIssueCode.too_small:
if (issue.type === "array") message = "Array must contain ".concat(issue.exact ? "exactly" : issue.inclusive ? "at least" : "more than", " ").concat(issue.minimum, " element(s)");
else if (issue.type === "string") message = "String must contain ".concat(issue.exact ? "exactly" : issue.inclusive ? "at least" : "over", " ").concat(issue.minimum, " character(s)");
else if (issue.type === "number") message = "Number must be ".concat(issue.exact ? "exactly equal to " : issue.inclusive ? "greater than or equal to " : "greater than ").concat(issue.minimum);
else if (issue.type === "date") message = "Date must be ".concat(issue.exact ? "exactly equal to " : issue.inclusive ? "greater than or equal to " : "greater than ").concat(new Date(Number(issue.minimum)));
else message = "Invalid input";
break;
case ZodIssueCode.too_big:
if (issue.type === "array") message = "Array must contain ".concat(issue.exact ? "exactly" : issue.inclusive ? "at most" : "less than", " ").concat(issue.maximum, " element(s)");
else if (issue.type === "string") message = "String must contain ".concat(issue.exact ? "exactly" : issue.inclusive ? "at most" : "under", " ").concat(issue.maximum, " character(s)");
else if (issue.type === "number") message = "Number must be ".concat(issue.exact ? "exactly" : issue.inclusive ? "less than or equal to" : "less than", " ").concat(issue.maximum);
else if (issue.type === "bigint") message = "BigInt must be ".concat(issue.exact ? "exactly" : issue.inclusive ? "less than or equal to" : "less than", " ").concat(issue.maximum);
else if (issue.type === "date") message = "Date must be ".concat(issue.exact ? "exactly" : issue.inclusive ? "smaller than or equal to" : "smaller than", " ").concat(new Date(Number(issue.maximum)));
else message = "Invalid input";
break;
case ZodIssueCode.custom:
message = "Invalid input";
break;
case ZodIssueCode.invalid_intersection_types:
message = "Intersection results could not be merged";
break;
case ZodIssueCode.not_multiple_of:
message = "Number must be a multiple of ".concat(issue.multipleOf);
break;
case ZodIssueCode.not_finite:
message = "Number must be finite";
break;
default:
message = _ctx.defaultError;
util.assertNever(issue);
}
return {
message: message
};
};
var overrideErrorMap = errorMap;
function setErrorMap(map) {
overrideErrorMap = map;
}
function getErrorMap() {
return overrideErrorMap;
}
var makeIssue = function(params) {
var data = params.data, path = params.path, errorMaps = params.errorMaps, issueData = params.issueData;
var fullPath = _to_consumable_array$x(path).concat(_to_consumable_array$x(issueData.path || []));
var fullIssue = _object_spread_props$t(_object_spread$I({}, issueData), {
path: fullPath
});
if (issueData.message !== undefined) {
return _object_spread_props$t(_object_spread$I({}, issueData), {
path: fullPath,
message: issueData.message
});
}
var errorMessage = "";
var maps = errorMaps.filter(function(m) {
return !!m;
}).slice().reverse();
var _iteratorNormalCompletion = true, _didIteratorError = false, _iteratorError = undefined;
try {
for(var _iterator = maps[Symbol.iterator](), _step; !(_iteratorNormalCompletion = (_step = _iterator.next()).done); _iteratorNormalCompletion = true){
var map = _step.value;
errorMessage = map(fullIssue, {
data: data,
defaultError: errorMessage
}).message;
}
} catch (err) {
_didIteratorError = true;
_iteratorError = err;
} finally{
try {
if (!_iteratorNormalCompletion && _iterator.return != null) {
_iterator.return();
}
} finally{
if (_didIteratorError) {
throw _iteratorError;
}
}
}
return _object_spread_props$t(_object_spread$I({}, issueData), {
path: fullPath,
message: errorMessage
});
};
var EMPTY_PATH = [];
function addIssueToContext(ctx, issueData) {
var overrideMap = getErrorMap();
var issue = makeIssue({
issueData: issueData,
data: ctx.data,
path: ctx.path,
errorMaps: [
ctx.common.contextualErrorMap,
ctx.schemaErrorMap,
overrideMap,
overrideMap === errorMap ? undefined : errorMap
].filter(function(x) {
return !!x;
})
});
ctx.common.issues.push(issue);
}
var ParseStatus = /*#__PURE__*/ function() {
function ParseStatus() {
_class_call_check$K(this, ParseStatus);
this.value = "valid";
}
_create_class$E(ParseStatus, [
{
key: "dirty",
value: function dirty() {
if (this.value === "valid") this.value = "dirty";
}
},
{
key: "abort",
value: function abort() {
if (this.value !== "aborted") this.value = "aborted";
}
}
], [
{
key: "mergeArray",
value: function mergeArray(status, results) {
var arrayValue = [];
var _iteratorNormalCompletion = true, _didIteratorError = false, _iteratorError = undefined;
try {
for(var _iterator = results[Symbol.iterator](), _step; !(_iteratorNormalCompletion = (_step = _iterator.next()).done); _iteratorNormalCompletion = true){
var s = _step.value;
if (s.status === "aborted") return INVALID;
if (s.status === "dirty") status.dirty();
arrayValue.push(s.value);
}
} catch (err) {
_didIteratorError = true;
_iteratorError = err;
} finally{
try {
if (!_iteratorNormalCompletion && _iterator.return != null) {
_iterator.return();
}
} finally{
if (_didIteratorError) {
throw _iteratorError;
}
}
}
return {
status: status.value,
value: arrayValue
};
}
},
{
key: "mergeObjectAsync",
value: function mergeObjectAsync(status, pairs) {
return _async_to_generator$s(function() {
var syncPairs, _iteratorNormalCompletion, _didIteratorError, _iteratorError, _iterator, _step, pair, key, value, err;
return _ts_generator$u(this, function(_state) {
switch(_state.label){
case 0:
syncPairs = [];
_iteratorNormalCompletion = true, _didIteratorError = false, _iteratorError = undefined;
_state.label = 1;
case 1:
_state.trys.push([
1,
7,
8,
9
]);
_iterator = pairs[Symbol.iterator]();
_state.label = 2;
case 2:
if (!!(_iteratorNormalCompletion = (_step = _iterator.next()).done)) return [
3,
6
];
pair = _step.value;
return [
4,
pair.key
];
case 3:
key = _state.sent();
return [
4,
pair.value
];
case 4:
value = _state.sent();
syncPairs.push({
key: key,
value: value
});
_state.label = 5;
case 5:
_iteratorNormalCompletion = true;
return [
3,
2
];
case 6:
return [
3,
9
];
case 7:
err = _state.sent();
_didIteratorError = true;
_iteratorError = err;
return [
3,