@decs/typeschema
Advanced tools
Comparing version 0.8.1 to 0.8.2
@@ -1,1 +0,460 @@ | ||
"use strict";var oe=Object.create;var l=Object.defineProperty;var ae=Object.getOwnPropertyDescriptor;var se=Object.getOwnPropertyNames;var ne=Object.getPrototypeOf,ie=Object.prototype.hasOwnProperty;var u=(t,e)=>()=>(t&&(e=t(t=0)),e);var p=(t,e)=>{for(var r in e)l(t,r,{get:e[r],enumerable:!0})},h=(t,e,r,o)=>{if(e&&typeof e=="object"||typeof e=="function")for(let s of se(e))!ie.call(t,s)&&s!==r&&l(t,s,{get:()=>e[s],enumerable:!(o=ae(e,s))||o.enumerable});return t};var v=(t,e,r)=>(r=t!=null?oe(ne(t)):{},h(e||!t||!t.__esModule?l(r,"default",{value:t,enumerable:!0}):r,t)),ce=t=>h(l({},"__esModule",{value:!0}),t);var T={};p(T,{ajv:()=>me});var S,me,V=u(()=>{"use strict";S=v(require("ajv")),me=new S.default});var I={};p(I,{validate:()=>k.validate});var k,b=u(()=>{"use strict";k=require("@deepkit/type")});var O={};p(O,{isRight:()=>g.isRight});var g,B=u(()=>{"use strict";g=require("fp-ts/Either")});var J={};p(J,{ArgumentError:()=>N.ArgumentError,ow:()=>Ie});var z,N,Ie,E=u(()=>{"use strict";z=v(require("ow")),N=require("ow"),Ie=z.default});var _={};p(_,{TypeCompiler:()=>D.TypeCompiler});var D,Y=u(()=>{"use strict";D=require("@sinclair/typebox/compiler")});var U={};p(U,{safeParseAsync:()=>W.safeParseAsync});var W,q=u(()=>{"use strict";W=require("valibot")});var H={};p(H,{ValidationError:()=>L.ValidationError});var L,Q=u(()=>{"use strict";L=require("yup")});var Fe={};p(Fe,{ValidationIssue:()=>a,assert:()=>y,createAssert:()=>te,validate:()=>f});module.exports=ce(Fe);function x(t){return async e=>{let r=await Promise.all(t.map(o=>o(e)).filter(Boolean));if(r.length===0)throw new Error("Missing adapters for schema: "+e);if(r.length>1)throw new Error("Conflicting adapters for schema: "+e);return r[0]}}function m(t){let e,r=async()=>(e===void 0&&(e=await t()),e);return r.clear=()=>e=void 0,r}function n(t){return Symbol.for("TypeBox.Kind")in t}function i(t){return typeof t=="object"&&!("validate"in t)&&!("parse"in t)&&!("kind"in t)&&!n(t)}var pe=m(()=>Promise.resolve().then(()=>(V(),T))),ue=t=>e=>i(e)?t(e):void 0,w=ue(async t=>{let{ajv:e}=await pe(),r=e.compile(t);return async o=>r(o)?{data:o}:{issues:(r.errors??[]).map(({message:s,schemaPath:c})=>new a(s??"",[c]))}});var le=t=>e=>"infer"in e&&!n(e)&&!i(e)?t(e):void 0,R=le(async t=>async e=>{let r=t(e);return r.problems==null?{data:r.data}:{issues:Array.from(r.problems).map(({message:o,path:s})=>new a(o,s))}});var ye=t=>e=>typeof e=="function"&&!("assert"in e)?t(e):void 0,C=ye(async t=>async e=>{try{return{data:await t(e)}}catch(r){if(r instanceof Error)return{issues:[new a(r.message)]};throw r}});var ve=m(()=>Promise.resolve().then(()=>(b(),I))),xe=t=>e=>"kind"in e&&!n(e)&&!i(e)?t(e):void 0,A=xe(async t=>{let{validate:e}=await ve();return async r=>{let o=e(r,t);return o.length===0?{data:r}:{issues:o.map(({message:s,path:c})=>new a(s,[c]))}}});var Te=m(()=>Promise.resolve().then(()=>(B(),O))),Ve=t=>e=>"encode"in e&&!n(e)&&!i(e)?t(e):void 0,j=Ve(async t=>{let{isRight:e}=await Te();return async r=>{let o=t.decode(r);return e(o)?{data:o.right}:{issues:o.left.map(({message:s,context:c})=>new a(s??"",c.map(({key:d})=>d)))}}});var Re=t=>e=>"_flags"in e&&!n(e)&&!i(e)?t(e):void 0,P=Re(async t=>async e=>{let r=t.validate(e);return r.error==null?{data:r.value}:{issues:r.error.details.map(({message:o,path:s})=>new a(o,s))}});var ke=m(()=>Promise.resolve().then(()=>(E(),J))),be=t=>e=>"context"in e&&!n(e)&&!i(e)?t(e):void 0,M=be(async t=>{let{ow:e,ArgumentError:r}=await ke(),o=e.create(t);return async s=>{try{return o(s),{data:s}}catch(c){if(c instanceof r)return{issues:Array.from(c.validationErrors.values()).flatMap(d=>Array.from(d).map(re=>new a(re)))};throw c}}});var Oe=t=>e=>"reflect"in e&&!n(e)&&!i(e)?t(e):void 0,K=Oe(async t=>async e=>{let r=t.validate(e);return r.success?{data:r.value}:{issues:[new a(r.message)]}});var Be=t=>e=>"refiner"in e&&!n(e)&&!i(e)?t(e):void 0,Z=Be(async t=>async e=>{let r=t.validate(e,{coerce:!0});if(r[0]==null)return{data:r[1]};let{message:o,path:s}=r[0];return{issues:[new a(o,s)]}});var Pe=m(()=>Promise.resolve().then(()=>(Y(),_))),ze=t=>e=>n(e)?t(e):void 0,F=ze(async t=>{let{TypeCompiler:e}=await Pe(),r=e.Compile(t);return async o=>r.Check(o)?{data:o}:{issues:[...r.Errors(o)].map(({message:s,path:c})=>new a(s,[c]))}});var Ne=m(()=>Promise.resolve().then(()=>(q(),U))),Ee=t=>e=>"async"in e&&!n(e)&&!i(e)?t(e):void 0,G=Ee(async t=>{let{safeParseAsync:e}=await Ne();return async r=>{let o=await e(t,r);return o.success?{data:o.data}:{issues:o.error.issues.map(({message:s,path:c})=>new a(s,c?.map(({key:d})=>d)))}}});var Ke=m(()=>Promise.resolve().then(()=>(Q(),H))),Ze=t=>e=>"__isYupSchema__"in e&&!n(e)&&!i(e)?t(e):void 0,X=Ze(async t=>{let{ValidationError:e}=await Ke();return async r=>{try{return{data:await t.validate(r,{strict:!0})}}catch(o){if(o instanceof e){let{message:s,path:c}=o;return{issues:[new a(s,c!=null&&c!==""?[c]:void 0)]}}throw o}}});var De=t=>e=>"_def"in e&&!n(e)&&!i(e)?t(e):void 0,$=De(async t=>async e=>{let r=await t.safeParseAsync(e);return r.success?{data:r.data}:{issues:r.error.issues.map(({message:o,path:s})=>new a(o,s))}});var ee=x([w,R,C,A,j,P,M,K,Z,F,G,X,$]);var a=class extends Error{constructor(r,o){super(r);this.path=o}};async function f(t,e){return(await ee(t))(e)}async function y(t,e){let r=await f(t,e);if("issues"in r)throw new AggregateError(r.issues,"Assertion failed");return r.data}function te(t){return async e=>y(t,e)}0&&(module.exports={ValidationIssue,assert,createAssert,validate}); | ||
"use strict"; | ||
var __create = Object.create; | ||
var __defProp = Object.defineProperty; | ||
var __getOwnPropDesc = Object.getOwnPropertyDescriptor; | ||
var __getOwnPropNames = Object.getOwnPropertyNames; | ||
var __getProtoOf = Object.getPrototypeOf; | ||
var __hasOwnProp = Object.prototype.hasOwnProperty; | ||
var __esm = (fn, res) => function __init() { | ||
return fn && (res = (0, fn[__getOwnPropNames(fn)[0]])(fn = 0)), res; | ||
}; | ||
var __export = (target, all) => { | ||
for (var name in all) | ||
__defProp(target, name, { get: all[name], enumerable: true }); | ||
}; | ||
var __copyProps = (to, from, except, desc) => { | ||
if (from && typeof from === "object" || typeof from === "function") { | ||
for (let key of __getOwnPropNames(from)) | ||
if (!__hasOwnProp.call(to, key) && key !== except) | ||
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable }); | ||
} | ||
return to; | ||
}; | ||
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps( | ||
// If the requireer is in node compatibility mode or this is not an ESM | ||
// file that has been converted to a CommonJS file using a Babel- | ||
// compatible transform (i.e. "__esModule" has not been set), then set | ||
// "default" to the CommonJS "module.exports" for node compatibility. | ||
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target, | ||
mod | ||
)); | ||
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod); | ||
// src/adapters/modules/ajv.ts | ||
var ajv_exports = {}; | ||
__export(ajv_exports, { | ||
ajv: () => ajv | ||
}); | ||
var require_ajv, ajv; | ||
var init_ajv = __esm({ | ||
"src/adapters/modules/ajv.ts"() { | ||
"use strict"; | ||
require_ajv = __toESM(require("ajv")); | ||
ajv = new require_ajv.default(); | ||
} | ||
}); | ||
// src/adapters/modules/deepkit.ts | ||
var deepkit_exports = {}; | ||
__export(deepkit_exports, { | ||
validate: () => require_type.validate | ||
}); | ||
var require_type; | ||
var init_deepkit = __esm({ | ||
"src/adapters/modules/deepkit.ts"() { | ||
"use strict"; | ||
require_type = require("@deepkit/type"); | ||
} | ||
}); | ||
// src/adapters/modules/io-ts.ts | ||
var io_ts_exports = {}; | ||
__export(io_ts_exports, { | ||
isRight: () => require_Either.isRight | ||
}); | ||
var require_Either; | ||
var init_io_ts = __esm({ | ||
"src/adapters/modules/io-ts.ts"() { | ||
"use strict"; | ||
require_Either = require("fp-ts/Either"); | ||
} | ||
}); | ||
// src/adapters/modules/ow.ts | ||
var ow_exports = {}; | ||
__export(ow_exports, { | ||
ArgumentError: () => require_ow2.ArgumentError, | ||
ow: () => ow | ||
}); | ||
var require_ow, require_ow2, ow; | ||
var init_ow = __esm({ | ||
"src/adapters/modules/ow.ts"() { | ||
"use strict"; | ||
require_ow = __toESM(require("ow")); | ||
require_ow2 = require("ow"); | ||
ow = require_ow.default; | ||
} | ||
}); | ||
// src/adapters/modules/typebox.ts | ||
var typebox_exports = {}; | ||
__export(typebox_exports, { | ||
TypeCompiler: () => require_compiler.TypeCompiler | ||
}); | ||
var require_compiler; | ||
var init_typebox = __esm({ | ||
"src/adapters/modules/typebox.ts"() { | ||
"use strict"; | ||
require_compiler = require("@sinclair/typebox/compiler"); | ||
} | ||
}); | ||
// src/adapters/modules/valibot.ts | ||
var valibot_exports = {}; | ||
__export(valibot_exports, { | ||
safeParseAsync: () => require_valibot.safeParseAsync | ||
}); | ||
var require_valibot; | ||
var init_valibot = __esm({ | ||
"src/adapters/modules/valibot.ts"() { | ||
"use strict"; | ||
require_valibot = require("valibot"); | ||
} | ||
}); | ||
// src/adapters/modules/yup.ts | ||
var yup_exports = {}; | ||
__export(yup_exports, { | ||
ValidationError: () => require_yup.ValidationError | ||
}); | ||
var require_yup; | ||
var init_yup = __esm({ | ||
"src/adapters/modules/yup.ts"() { | ||
"use strict"; | ||
require_yup = require("yup"); | ||
} | ||
}); | ||
// src/index.ts | ||
var src_exports = {}; | ||
__export(src_exports, { | ||
ValidationIssue: () => ValidationIssue, | ||
assert: () => assert, | ||
createAssert: () => createAssert, | ||
validate: () => validate2 | ||
}); | ||
module.exports = __toCommonJS(src_exports); | ||
// src/adapters/index.ts | ||
function wrap(adapters) { | ||
return async (schema) => { | ||
const results = await Promise.all( | ||
adapters.map((adapter) => adapter(schema)).filter(Boolean) | ||
); | ||
if (results.length === 0) { | ||
throw new Error("Missing adapters for schema: " + schema); | ||
} | ||
if (results.length > 1) { | ||
throw new Error("Conflicting adapters for schema: " + schema); | ||
} | ||
return results[0]; | ||
}; | ||
} | ||
// src/utils.ts | ||
function memoize(fn) { | ||
let cache = void 0; | ||
const memoizedFn = async () => { | ||
if (cache === void 0) { | ||
cache = await fn(); | ||
} | ||
return cache; | ||
}; | ||
memoizedFn.clear = () => cache = void 0; | ||
return memoizedFn; | ||
} | ||
function isTypeBoxSchema(schema) { | ||
return Symbol.for("TypeBox.Kind") in schema; | ||
} | ||
function isJSONSchema(schema) { | ||
return typeof schema === "object" && !("validate" in schema) && !("parse" in schema) && !("kind" in schema) && !isTypeBoxSchema(schema); | ||
} | ||
// src/adapters/ajv.ts | ||
var fetchModule = /* @__PURE__ */ memoize( | ||
() => Promise.resolve().then(() => (init_ajv(), ajv_exports)) | ||
); | ||
var coerce = /* @__NO_SIDE_EFFECTS__ */ (fn) => (schema) => isJSONSchema(schema) ? fn(schema) : void 0; | ||
var createValidate = /* @__PURE__ */ coerce(async (schema) => { | ||
const { ajv: ajv2 } = await fetchModule(); | ||
const validateSchema = ajv2.compile(schema); | ||
return async (data) => { | ||
if (validateSchema(data)) { | ||
return { data }; | ||
} | ||
return { | ||
issues: (validateSchema.errors ?? []).map( | ||
({ message, schemaPath }) => new ValidationIssue(message ?? "", [schemaPath]) | ||
) | ||
}; | ||
}; | ||
}); | ||
// src/adapters/arktype.ts | ||
var coerce2 = /* @__NO_SIDE_EFFECTS__ */ (fn) => (schema) => "infer" in schema && !isTypeBoxSchema(schema) && !isJSONSchema(schema) ? fn(schema) : void 0; | ||
var createValidate2 = /* @__PURE__ */ coerce2( | ||
async (schema) => async (data) => { | ||
const result = schema(data); | ||
if (result.problems == null) { | ||
return { data: result.data }; | ||
} | ||
return { | ||
issues: Array.from(result.problems).map( | ||
({ message, path }) => new ValidationIssue(message, path) | ||
) | ||
}; | ||
} | ||
); | ||
// src/adapters/custom.ts | ||
var coerce3 = /* @__NO_SIDE_EFFECTS__ */ (fn) => (schema) => typeof schema === "function" && !("assert" in schema) ? fn(schema) : void 0; | ||
var createValidate3 = /* @__PURE__ */ coerce3( | ||
async (schema) => async (data) => { | ||
try { | ||
return { data: await schema(data) }; | ||
} catch (error) { | ||
if (error instanceof Error) { | ||
return { issues: [new ValidationIssue(error.message)] }; | ||
} | ||
throw error; | ||
} | ||
} | ||
); | ||
// src/adapters/deepkit.ts | ||
var fetchModule2 = /* @__PURE__ */ memoize( | ||
() => Promise.resolve().then(() => (init_deepkit(), deepkit_exports)) | ||
); | ||
var coerce4 = /* @__NO_SIDE_EFFECTS__ */ (fn) => (schema) => "kind" in schema && !isTypeBoxSchema(schema) && !isJSONSchema(schema) ? fn(schema) : void 0; | ||
var createValidate4 = /* @__PURE__ */ coerce4(async (schema) => { | ||
const { validate: validate3 } = await fetchModule2(); | ||
return async (data) => { | ||
const result = validate3(data, schema); | ||
if (result.length === 0) { | ||
return { data }; | ||
} | ||
return { | ||
issues: result.map( | ||
({ message, path }) => new ValidationIssue(message, [path]) | ||
) | ||
}; | ||
}; | ||
}); | ||
// src/adapters/io-ts.ts | ||
var fetchModule3 = /* @__PURE__ */ memoize( | ||
() => Promise.resolve().then(() => (init_io_ts(), io_ts_exports)) | ||
); | ||
var coerce5 = /* @__NO_SIDE_EFFECTS__ */ (fn) => (schema) => "encode" in schema && !isTypeBoxSchema(schema) && !isJSONSchema(schema) ? fn(schema) : void 0; | ||
var createValidate5 = /* @__PURE__ */ coerce5(async (schema) => { | ||
const { isRight: isRight2 } = await fetchModule3(); | ||
return async (data) => { | ||
const result = schema.decode(data); | ||
if (isRight2(result)) { | ||
return { data: result.right }; | ||
} | ||
return { | ||
issues: result.left.map( | ||
({ message, context }) => new ValidationIssue( | ||
message ?? "", | ||
context.map(({ key }) => key) | ||
) | ||
) | ||
}; | ||
}; | ||
}); | ||
// src/adapters/joi.ts | ||
var coerce6 = /* @__NO_SIDE_EFFECTS__ */ (fn) => (schema) => "_flags" in schema && !isTypeBoxSchema(schema) && !isJSONSchema(schema) ? fn(schema) : void 0; | ||
var createValidate6 = /* @__PURE__ */ coerce6( | ||
async (schema) => async (data) => { | ||
const result = schema.validate(data); | ||
if (result.error == null) { | ||
return { data: result.value }; | ||
} | ||
return { | ||
issues: result.error.details.map( | ||
({ message, path }) => new ValidationIssue(message, path) | ||
) | ||
}; | ||
} | ||
); | ||
// src/adapters/ow.ts | ||
var fetchModule4 = /* @__PURE__ */ memoize( | ||
() => Promise.resolve().then(() => (init_ow(), ow_exports)) | ||
); | ||
var coerce7 = /* @__NO_SIDE_EFFECTS__ */ (fn) => (schema) => "context" in schema && !isTypeBoxSchema(schema) && !isJSONSchema(schema) ? fn(schema) : void 0; | ||
var createValidate7 = /* @__PURE__ */ coerce7(async (schema) => { | ||
const { ow: ow2, ArgumentError: ArgumentError2 } = await fetchModule4(); | ||
const assertSchema = ow2.create(schema); | ||
return async (data) => { | ||
try { | ||
assertSchema(data); | ||
return { data }; | ||
} catch (error) { | ||
if (error instanceof ArgumentError2) { | ||
return { | ||
issues: Array.from(error.validationErrors.values()).flatMap( | ||
(messages) => Array.from(messages).map((message) => new ValidationIssue(message)) | ||
) | ||
}; | ||
} | ||
throw error; | ||
} | ||
}; | ||
}); | ||
// src/adapters/runtypes.ts | ||
var coerce8 = /* @__NO_SIDE_EFFECTS__ */ (fn) => (schema) => "reflect" in schema && !isTypeBoxSchema(schema) && !isJSONSchema(schema) ? fn(schema) : void 0; | ||
var createValidate8 = /* @__PURE__ */ coerce8( | ||
async (schema) => async (data) => { | ||
const result = schema.validate(data); | ||
if (result.success) { | ||
return { data: result.value }; | ||
} | ||
return { issues: [new ValidationIssue(result.message)] }; | ||
} | ||
); | ||
// src/adapters/superstruct.ts | ||
var coerce9 = /* @__NO_SIDE_EFFECTS__ */ (fn) => (schema) => "refiner" in schema && !isTypeBoxSchema(schema) && !isJSONSchema(schema) ? fn(schema) : void 0; | ||
var createValidate9 = /* @__PURE__ */ coerce9( | ||
async (schema) => async (data) => { | ||
const result = schema.validate(data, { coerce: true }); | ||
if (result[0] == null) { | ||
return { data: result[1] }; | ||
} | ||
const { message, path } = result[0]; | ||
return { issues: [new ValidationIssue(message, path)] }; | ||
} | ||
); | ||
// src/adapters/typebox.ts | ||
var fetchModule5 = /* @__PURE__ */ memoize( | ||
() => Promise.resolve().then(() => (init_typebox(), typebox_exports)) | ||
); | ||
var coerce10 = /* @__NO_SIDE_EFFECTS__ */ (fn) => (schema) => isTypeBoxSchema(schema) ? fn(schema) : void 0; | ||
var createValidate10 = /* @__PURE__ */ coerce10(async (schema) => { | ||
const { TypeCompiler: TypeCompiler2 } = await fetchModule5(); | ||
const result = TypeCompiler2.Compile(schema); | ||
return async (data) => { | ||
if (result.Check(data)) { | ||
return { data }; | ||
} | ||
return { | ||
issues: [...result.Errors(data)].map( | ||
({ message, path }) => new ValidationIssue(message, [path]) | ||
) | ||
}; | ||
}; | ||
}); | ||
// src/adapters/valibot.ts | ||
var fetchModule6 = /* @__PURE__ */ memoize( | ||
() => Promise.resolve().then(() => (init_valibot(), valibot_exports)) | ||
); | ||
var coerce11 = /* @__NO_SIDE_EFFECTS__ */ (fn) => (schema) => "async" in schema && !isTypeBoxSchema(schema) && !isJSONSchema(schema) ? fn(schema) : void 0; | ||
var createValidate11 = /* @__PURE__ */ coerce11(async (schema) => { | ||
const { safeParseAsync: safeParseAsync2 } = await fetchModule6(); | ||
return async (data) => { | ||
const result = await safeParseAsync2(schema, data); | ||
if (result.success) { | ||
return { data: result.data }; | ||
} | ||
return { | ||
issues: result.error.issues.map( | ||
({ message, path }) => new ValidationIssue(message, path?.map(({ key }) => key)) | ||
) | ||
}; | ||
}; | ||
}); | ||
// src/adapters/yup.ts | ||
var fetchModule7 = /* @__PURE__ */ memoize( | ||
() => Promise.resolve().then(() => (init_yup(), yup_exports)) | ||
); | ||
var coerce12 = /* @__NO_SIDE_EFFECTS__ */ (fn) => (schema) => "__isYupSchema__" in schema && !isTypeBoxSchema(schema) && !isJSONSchema(schema) ? fn(schema) : void 0; | ||
var createValidate12 = /* @__PURE__ */ coerce12(async (schema) => { | ||
const { ValidationError: ValidationError2 } = await fetchModule7(); | ||
return async (data) => { | ||
try { | ||
return { data: await schema.validate(data, { strict: true }) }; | ||
} catch (error) { | ||
if (error instanceof ValidationError2) { | ||
const { message, path } = error; | ||
return { | ||
issues: [ | ||
new ValidationIssue( | ||
message, | ||
path != null && path !== "" ? [path] : void 0 | ||
) | ||
] | ||
}; | ||
} | ||
throw error; | ||
} | ||
}; | ||
}); | ||
// src/adapters/zod.ts | ||
var coerce13 = /* @__NO_SIDE_EFFECTS__ */ (fn) => (schema) => "_def" in schema && !isTypeBoxSchema(schema) && !isJSONSchema(schema) ? fn(schema) : void 0; | ||
var createValidate13 = /* @__PURE__ */ coerce13( | ||
async (schema) => async (data) => { | ||
const result = await schema.safeParseAsync(data); | ||
if (result.success) { | ||
return { data: result.data }; | ||
} | ||
return { | ||
issues: result.error.issues.map( | ||
({ message, path }) => new ValidationIssue(message, path) | ||
) | ||
}; | ||
} | ||
); | ||
// src/registry.ts | ||
var createValidate14 = /* @__PURE__ */ wrap([ | ||
createValidate, | ||
createValidate2, | ||
createValidate3, | ||
createValidate4, | ||
createValidate5, | ||
createValidate6, | ||
createValidate7, | ||
createValidate8, | ||
createValidate9, | ||
createValidate10, | ||
createValidate11, | ||
createValidate12, | ||
createValidate13 | ||
]); | ||
// src/validation.ts | ||
var ValidationIssue = class extends Error { | ||
constructor(message, path) { | ||
super(message); | ||
this.path = path; | ||
} | ||
}; | ||
async function validate2(schema, data) { | ||
const validateSchema = await createValidate14(schema); | ||
return validateSchema(data); | ||
} | ||
async function assert(schema, data) { | ||
const result = await validate2(schema, data); | ||
if ("issues" in result) { | ||
throw new AggregateError(result.issues, "Assertion failed"); | ||
} | ||
return result.data; | ||
} | ||
function createAssert(schema) { | ||
return async (data) => assert(schema, data); | ||
} | ||
// Annotate the CommonJS export names for ESM require in node: | ||
0 && (module.exports = { | ||
ValidationIssue, | ||
assert, | ||
createAssert, | ||
validate | ||
}); |
{ | ||
"name": "@decs/typeschema", | ||
"version": "0.8.1", | ||
"version": "0.8.2", | ||
"description": "Universal adapter for schema validation", | ||
@@ -5,0 +5,0 @@ "keywords": [ |
Sorry, the diff of this file is not supported yet
Major refactor
Supply chain riskPackage has recently undergone a major refactor. It may be unstable or indicate significant internal changes. Use caution when updating to versions that include significant changes.
Found 1 instance in 1 package
Minified code
QualityThis package contains minified code. This may be harmless in some cases where minified code is included in packaged libraries, however packages on npm should not minify code.
Found 1 instance in 1 package
50012
905
1
1