UNPKG

one

Version:

One is a new React Framework that makes Vite serve both native and web.

203 lines (199 loc) 7.68 kB
"use strict"; var __defProp = Object.defineProperty; var __getOwnPropDesc = Object.getOwnPropertyDescriptor; var __getOwnPropNames = Object.getOwnPropertyNames; var __hasOwnProp = Object.prototype.hasOwnProperty; var __export = (target, all) => { for (var name in all) __defProp(target, name, { get: all[name], enumerable: !0 }); }, __copyProps = (to, from, except, desc) => { if (from && typeof from == "object" || typeof from == "function") for (let key of __getOwnPropNames(from)) !__hasOwnProp.call(to, key) && key !== except && __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable }); return to; }; var __toCommonJS = mod => __copyProps(__defProp({}, "__esModule", { value: !0 }), mod); var validateSearch_exports = {}; __export(validateSearch_exports, { SearchValidationError: () => SearchValidationError, parseSearchString: () => parseSearchString, validateSearch: () => validateSearch, withFallback: () => withFallback, zodSearchValidator: () => zodSearchValidator }); module.exports = __toCommonJS(validateSearch_exports); function _assert_this_initialized(self) { if (self === void 0) throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); return self; } function _call_super(_this, derived, args) { return derived = _get_prototype_of(derived), _possible_constructor_return(_this, _is_native_reflect_construct() ? Reflect.construct(derived, args || [], _get_prototype_of(_this).constructor) : derived.apply(_this, args)); } function _class_call_check(instance, Constructor) { if (!(instance instanceof Constructor)) throw new TypeError("Cannot call a class as a function"); } function _construct(Parent, args, Class) { return _is_native_reflect_construct() ? _construct = Reflect.construct : _construct = function (Parent2, args2, Class2) { var a = [null]; a.push.apply(a, args2); var Constructor = Function.bind.apply(Parent2, a), instance = new Constructor(); return Class2 && _set_prototype_of(instance, Class2.prototype), instance; }, _construct.apply(null, arguments); } function _define_property(obj, key, value) { return key in obj ? Object.defineProperty(obj, key, { value, enumerable: !0, configurable: !0, writable: !0 }) : obj[key] = value, obj; } function _get_prototype_of(o) { return _get_prototype_of = Object.setPrototypeOf ? Object.getPrototypeOf : function (o2) { return o2.__proto__ || Object.getPrototypeOf(o2); }, _get_prototype_of(o); } function _inherits(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: !0, configurable: !0 } }), superClass && _set_prototype_of(subClass, superClass); } function _is_native_function(fn) { return Function.toString.call(fn).indexOf("[native code]") !== -1; } function _possible_constructor_return(self, call) { return call && (_type_of(call) === "object" || typeof call == "function") ? call : _assert_this_initialized(self); } function _set_prototype_of(o, p) { return _set_prototype_of = Object.setPrototypeOf || function (o2, p2) { return o2.__proto__ = p2, o2; }, _set_prototype_of(o, p); } function _type_of(obj) { "@swc/helpers - typeof"; return obj && typeof Symbol < "u" && obj.constructor === Symbol ? "symbol" : typeof obj; } function _wrap_native_super(Class) { var _cache = typeof Map == "function" ? /* @__PURE__ */new Map() : void 0; return _wrap_native_super = function (Class2) { if (Class2 === null || !_is_native_function(Class2)) return Class2; if (typeof Class2 != "function") throw new TypeError("Super expression must either be null or a function"); if (typeof _cache < "u") { if (_cache.has(Class2)) return _cache.get(Class2); _cache.set(Class2, Wrapper); } function Wrapper() { return _construct(Class2, arguments, _get_prototype_of(this).constructor); } return Wrapper.prototype = Object.create(Class2.prototype, { constructor: { value: Wrapper, enumerable: !1, writable: !0, configurable: !0 } }), _set_prototype_of(Wrapper, Class2); }, _wrap_native_super(Class); } function _is_native_reflect_construct() { try { var result = !Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function () {})); } catch {} return (_is_native_reflect_construct = function () { return !!result; })(); } var SearchValidationError = /* @__PURE__ */function (Error1) { "use strict"; _inherits(SearchValidationError2, Error1); function SearchValidationError2(message) { var issues = arguments.length > 1 && arguments[1] !== void 0 ? arguments[1] : []; _class_call_check(this, SearchValidationError2); var _this; return _this = _call_super(this, SearchValidationError2, [message]), _define_property(_this, "routerCode", "VALIDATE_SEARCH"), _define_property(_this, "issues", void 0), _this.name = "SearchValidationError", _this.issues = issues, _this; } return SearchValidationError2; }(_wrap_native_super(Error)); function isStandardSchema(value) { var _value_standard; return (typeof value > "u" ? "undefined" : _type_of(value)) === "object" && value !== null && "~standard" in value && typeof ((_value_standard = value["~standard"]) === null || _value_standard === void 0 ? void 0 : _value_standard.validate) == "function"; } function isZodLikeSchema(value) { return (typeof value > "u" ? "undefined" : _type_of(value)) === "object" && value !== null && typeof value.parse == "function"; } function isValidatorFn(value) { return typeof value == "function"; } function parseSearchString(search) { var params = {}, searchParams = new URLSearchParams(search); return searchParams.forEach(function (value, key) { var existing = params[key]; existing === void 0 ? params[key] = value : Array.isArray(existing) ? existing.push(value) : params[key] = [existing, value]; }), params; } function validateSearch(validator, input) { if (isStandardSchema(validator)) { var result = validator["~standard"].validate(input); if (result.issues) throw new SearchValidationError("Search param validation failed", result.issues); return result.value; } if (isZodLikeSchema(validator)) { if (validator.safeParse) { var result1 = validator.safeParse(input); if (!result1.success) throw new SearchValidationError("Search param validation failed", [result1.error]); return result1.data; } try { return validator.parse(input); } catch (error) { throw new SearchValidationError("Search param validation failed", [error]); } } if (isValidatorFn(validator)) try { return validator(input); } catch (error) { throw new SearchValidationError("Search param validation failed", [error]); } throw new Error("Invalid validator provided to validateSearch"); } function zodSearchValidator(schema) { return schema; } function withFallback(schema, fallbackValue) { return { parse(value) { try { return schema.parse(value); } catch { return fallbackValue; } }, safeParse(value) { try { return { success: !0, data: schema.parse(value) }; } catch { return { success: !0, data: fallbackValue }; } } }; } //# sourceMappingURL=validateSearch.native.js.map