one
Version:
One is a new React Framework that makes Vite serve both native and web.
152 lines (148 loc) • 6.53 kB
JavaScript
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 ParamValidationError = /* @__PURE__ */function (Error1) {
"use strict";
_inherits(ParamValidationError2, Error1);
function ParamValidationError2(message, params) {
var issues = arguments.length > 2 && arguments[2] !== void 0 ? arguments[2] : [];
_class_call_check(this, ParamValidationError2);
var _this;
return _this = _call_super(this, ParamValidationError2, [message]), _define_property(_this, "routerCode", "VALIDATE_PARAMS"), _define_property(_this, "issues", void 0), _define_property(_this, "params", void 0), _this.name = "ParamValidationError", _this.params = params, _this.issues = issues, _this;
}
return ParamValidationError2;
}(_wrap_native_super(Error)),
RouteValidationError = /* @__PURE__ */function (Error1) {
"use strict";
_inherits(RouteValidationError2, Error1);
function RouteValidationError2(message, details) {
_class_call_check(this, RouteValidationError2);
var _this;
return _this = _call_super(this, RouteValidationError2, [message]), _define_property(_this, "routerCode", "VALIDATE_ROUTE"), _define_property(_this, "details", void 0), _this.name = "RouteValidationError", _this.details = details, _this;
}
return RouteValidationError2;
}(_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 validateParams(validator, input) {
if (isStandardSchema(validator)) {
var result = validator["~standard"].validate(input);
if (result.issues) throw new ParamValidationError("Route param validation failed", input, result.issues);
return result.value;
}
if (isZodLikeSchema(validator)) {
if (validator.safeParse) {
var result1 = validator.safeParse(input);
if (!result1.success) throw new ParamValidationError("Route param validation failed", input, [result1.error]);
return result1.data;
}
try {
return validator.parse(input);
} catch (error) {
throw new ParamValidationError("Route param validation failed", input, [error]);
}
}
if (isValidatorFn(validator)) try {
return validator(input);
} catch (error) {
throw new ParamValidationError("Route param validation failed", input, [error]);
}
throw new Error("Invalid validator provided to validateParams");
}
function zodParamValidator(schema) {
return schema;
}
export { ParamValidationError, RouteValidationError, validateParams, zodParamValidator };
//# sourceMappingURL=validateParams.native.js.map