@decs/typeschema
Advanced tools
Comparing version 0.5.1 to 0.5.2
@@ -29,14 +29,8 @@ "use strict"; | ||
const utils_1 = require("../utils"); | ||
(0, registry_1.register)(async (schema) => { | ||
const Ajv = await (0, utils_1.maybe)(() => Promise.resolve().then(() => __importStar(require('ajv')))); | ||
if (Ajv == null) { | ||
return null; | ||
let ajv = null; | ||
(0, registry_1.register)(schema => ((0, utils_1.isJSONSchema)(schema) ? schema : null), async (schema) => { | ||
if (ajv == null) { | ||
const Ajv = await Promise.resolve().then(() => __importStar(require('ajv'))); | ||
ajv = new Ajv.default(); | ||
} | ||
if (!(0, utils_1.isJSONSchema)(schema)) { | ||
return null; | ||
} | ||
return schema; | ||
}, async (schema) => { | ||
const Ajv = await Promise.resolve().then(() => __importStar(require('ajv'))); | ||
const ajv = new Ajv.default(); | ||
const validate = ajv.compile(schema); | ||
@@ -54,2 +48,2 @@ return { | ||
}; | ||
}); | ||
}, 'ajv'); |
"use strict"; | ||
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) { | ||
if (k2 === undefined) k2 = k; | ||
var desc = Object.getOwnPropertyDescriptor(m, k); | ||
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) { | ||
desc = { enumerable: true, get: function() { return m[k]; } }; | ||
} | ||
Object.defineProperty(o, k2, desc); | ||
}) : (function(o, m, k, k2) { | ||
if (k2 === undefined) k2 = k; | ||
o[k2] = m[k]; | ||
})); | ||
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) { | ||
Object.defineProperty(o, "default", { enumerable: true, value: v }); | ||
}) : function(o, v) { | ||
o["default"] = v; | ||
}); | ||
var __importStar = (this && this.__importStar) || function (mod) { | ||
if (mod && mod.__esModule) return mod; | ||
var result = {}; | ||
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k); | ||
__setModuleDefault(result, mod); | ||
return result; | ||
}; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
@@ -29,12 +6,5 @@ const registry_1 = require("../registry"); | ||
const utils_1 = require("../utils"); | ||
(0, registry_1.register)(async (schema) => { | ||
const ArkType = await (0, utils_1.maybe)(() => Promise.resolve().then(() => __importStar(require('arktype')))); | ||
if (ArkType == null) { | ||
return null; | ||
} | ||
if (!('infer' in schema) || 'static' in schema || (0, utils_1.isJSONSchema)(schema)) { | ||
return null; | ||
} | ||
return schema; | ||
}, async (schema) => ({ | ||
(0, registry_1.register)(schema => 'infer' in schema && !(0, utils_1.isTypeBoxSchema)(schema) && !(0, utils_1.isJSONSchema)(schema) | ||
? schema | ||
: null, async (schema) => ({ | ||
validate: async (data) => { | ||
@@ -46,5 +16,5 @@ const result = schema(data); | ||
return { | ||
issues: [...result.problems].map(({ message, path }) => new schema_1.ValidationIssue(message, path)), | ||
issues: Array.from(result.problems).map(({ message, path }) => new schema_1.ValidationIssue(message, path)), | ||
}; | ||
}, | ||
})); | ||
}), 'arktype'); |
@@ -5,8 +5,3 @@ "use strict"; | ||
const schema_1 = require("../schema"); | ||
(0, registry_1.register)(async (schema) => { | ||
if (typeof schema !== 'function' || 'assert' in schema) { | ||
return null; | ||
} | ||
return schema; | ||
}, async (schema) => ({ | ||
(0, registry_1.register)(schema => typeof schema === 'function' && !('assert' in schema) ? schema : null, async (schema) => ({ | ||
validate: async (data) => { | ||
@@ -13,0 +8,0 @@ try { |
@@ -29,22 +29,17 @@ "use strict"; | ||
const utils_1 = require("../utils"); | ||
(0, registry_1.register)(async (schema) => { | ||
const IoTs = await (0, utils_1.maybe)(() => Promise.resolve().then(() => __importStar(require('io-ts')))); | ||
if (IoTs == null) { | ||
return null; | ||
} | ||
if (!('encode' in schema) || 'static' in schema || (0, utils_1.isJSONSchema)(schema)) { | ||
return null; | ||
} | ||
return schema; | ||
}, async (schema) => ({ | ||
validate: async (data) => { | ||
const { isRight } = await Promise.resolve().then(() => __importStar(require('fp-ts/Either'))); | ||
const result = schema.decode(data); | ||
if (isRight(result)) { | ||
return { data: result.right }; | ||
} | ||
return { | ||
issues: result.left.map(({ message, context }) => new schema_1.ValidationIssue(message !== null && message !== void 0 ? message : '', context.map(({ key }) => key))), | ||
}; | ||
}, | ||
})); | ||
(0, registry_1.register)(schema => 'encode' in schema && !(0, utils_1.isTypeBoxSchema)(schema) && !(0, utils_1.isJSONSchema)(schema) | ||
? schema | ||
: null, async (schema) => { | ||
const { isRight } = await Promise.resolve().then(() => __importStar(require('fp-ts/Either'))); | ||
return { | ||
validate: async (data) => { | ||
const result = schema.decode(data); | ||
if (isRight(result)) { | ||
return { data: result.right }; | ||
} | ||
return { | ||
issues: result.left.map(({ message, context }) => new schema_1.ValidationIssue(message !== null && message !== void 0 ? message : '', context.map(({ key }) => key))), | ||
}; | ||
}, | ||
}; | ||
}, 'io-ts'); |
"use strict"; | ||
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) { | ||
if (k2 === undefined) k2 = k; | ||
var desc = Object.getOwnPropertyDescriptor(m, k); | ||
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) { | ||
desc = { enumerable: true, get: function() { return m[k]; } }; | ||
} | ||
Object.defineProperty(o, k2, desc); | ||
}) : (function(o, m, k, k2) { | ||
if (k2 === undefined) k2 = k; | ||
o[k2] = m[k]; | ||
})); | ||
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) { | ||
Object.defineProperty(o, "default", { enumerable: true, value: v }); | ||
}) : function(o, v) { | ||
o["default"] = v; | ||
}); | ||
var __importStar = (this && this.__importStar) || function (mod) { | ||
if (mod && mod.__esModule) return mod; | ||
var result = {}; | ||
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k); | ||
__setModuleDefault(result, mod); | ||
return result; | ||
}; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
@@ -29,12 +6,5 @@ const registry_1 = require("../registry"); | ||
const utils_1 = require("../utils"); | ||
(0, registry_1.register)(async (schema) => { | ||
const Joi = await (0, utils_1.maybe)(() => Promise.resolve().then(() => __importStar(require('joi')))); | ||
if (Joi == null) { | ||
return null; | ||
} | ||
if (!('_flags' in schema) || 'static' in schema || (0, utils_1.isJSONSchema)(schema)) { | ||
return null; | ||
} | ||
return schema; | ||
}, async (schema) => ({ | ||
(0, registry_1.register)(schema => '_flags' in schema && !(0, utils_1.isTypeBoxSchema)(schema) && !(0, utils_1.isJSONSchema)(schema) | ||
? schema | ||
: null, async (schema) => ({ | ||
validate: async (data) => { | ||
@@ -49,2 +19,2 @@ const result = schema.validate(data); | ||
}, | ||
})); | ||
}), 'joi'); |
"use strict"; | ||
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) { | ||
if (k2 === undefined) k2 = k; | ||
var desc = Object.getOwnPropertyDescriptor(m, k); | ||
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) { | ||
desc = { enumerable: true, get: function() { return m[k]; } }; | ||
} | ||
Object.defineProperty(o, k2, desc); | ||
}) : (function(o, m, k, k2) { | ||
if (k2 === undefined) k2 = k; | ||
o[k2] = m[k]; | ||
})); | ||
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) { | ||
Object.defineProperty(o, "default", { enumerable: true, value: v }); | ||
}) : function(o, v) { | ||
o["default"] = v; | ||
}); | ||
var __importStar = (this && this.__importStar) || function (mod) { | ||
if (mod && mod.__esModule) return mod; | ||
var result = {}; | ||
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k); | ||
__setModuleDefault(result, mod); | ||
return result; | ||
}; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
@@ -29,12 +6,5 @@ const registry_1 = require("../registry"); | ||
const utils_1 = require("../utils"); | ||
(0, registry_1.register)(async (schema) => { | ||
const Runtypes = await (0, utils_1.maybe)(() => Promise.resolve().then(() => __importStar(require('runtypes')))); | ||
if (Runtypes == null) { | ||
return null; | ||
} | ||
if (!('reflect' in schema) || 'static' in schema || (0, utils_1.isJSONSchema)(schema)) { | ||
return null; | ||
} | ||
return schema; | ||
}, async (schema) => ({ | ||
(0, registry_1.register)(schema => 'reflect' in schema && !(0, utils_1.isTypeBoxSchema)(schema) && !(0, utils_1.isJSONSchema)(schema) | ||
? schema | ||
: null, async (schema) => ({ | ||
validate: async (data) => { | ||
@@ -47,2 +17,2 @@ const result = schema.validate(data); | ||
}, | ||
})); | ||
}), 'runtypes'); |
"use strict"; | ||
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) { | ||
if (k2 === undefined) k2 = k; | ||
var desc = Object.getOwnPropertyDescriptor(m, k); | ||
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) { | ||
desc = { enumerable: true, get: function() { return m[k]; } }; | ||
} | ||
Object.defineProperty(o, k2, desc); | ||
}) : (function(o, m, k, k2) { | ||
if (k2 === undefined) k2 = k; | ||
o[k2] = m[k]; | ||
})); | ||
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) { | ||
Object.defineProperty(o, "default", { enumerable: true, value: v }); | ||
}) : function(o, v) { | ||
o["default"] = v; | ||
}); | ||
var __importStar = (this && this.__importStar) || function (mod) { | ||
if (mod && mod.__esModule) return mod; | ||
var result = {}; | ||
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k); | ||
__setModuleDefault(result, mod); | ||
return result; | ||
}; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
@@ -29,12 +6,5 @@ const registry_1 = require("../registry"); | ||
const utils_1 = require("../utils"); | ||
(0, registry_1.register)(async (schema) => { | ||
const Superstruct = await (0, utils_1.maybe)(() => Promise.resolve().then(() => __importStar(require('superstruct')))); | ||
if (Superstruct == null) { | ||
return null; | ||
} | ||
if (!('refiner' in schema) || 'static' in schema || (0, utils_1.isJSONSchema)(schema)) { | ||
return null; | ||
} | ||
return schema; | ||
}, async (schema) => ({ | ||
(0, registry_1.register)(schema => 'refiner' in schema && !(0, utils_1.isTypeBoxSchema)(schema) && !(0, utils_1.isJSONSchema)(schema) | ||
? schema | ||
: null, async (schema) => ({ | ||
validate: async (data) => { | ||
@@ -48,2 +18,2 @@ const result = schema.validate(data, { coerce: true }); | ||
}, | ||
})); | ||
}), 'superstruct'); |
@@ -29,12 +29,3 @@ "use strict"; | ||
const utils_1 = require("../utils"); | ||
(0, registry_1.register)(async (schema) => { | ||
const TypeBox = await (0, utils_1.maybe)(() => Promise.resolve().then(() => __importStar(require('@sinclair/typebox')))); | ||
if (TypeBox == null) { | ||
return null; | ||
} | ||
if (!(TypeBox.Kind in schema) || (0, utils_1.isJSONSchema)(schema)) { | ||
return null; | ||
} | ||
return schema; | ||
}, async (schema) => { | ||
(0, registry_1.register)(schema => ((0, utils_1.isTypeBoxSchema)(schema) ? schema : null), async (schema) => { | ||
const { TypeCompiler } = await Promise.resolve().then(() => __importStar(require('@sinclair/typebox/compiler'))); | ||
@@ -52,2 +43,2 @@ const result = TypeCompiler.Compile(schema); | ||
}; | ||
}); | ||
}, '@sinclair/typebox'); |
@@ -29,31 +29,26 @@ "use strict"; | ||
const utils_1 = require("../utils"); | ||
(0, registry_1.register)(async (schema) => { | ||
const Yup = await (0, utils_1.maybe)(() => Promise.resolve().then(() => __importStar(require('yup')))); | ||
if (Yup == null) { | ||
return null; | ||
} | ||
if (!('__isYupSchema__' in schema) || | ||
'static' in schema || | ||
(0, utils_1.isJSONSchema)(schema)) { | ||
return null; | ||
} | ||
return schema; | ||
}, async (schema) => ({ | ||
validate: async (data) => { | ||
try { | ||
return { data: await schema.validate(data, { strict: true }) }; | ||
} | ||
catch (error) { | ||
const Yup = await Promise.resolve().then(() => __importStar(require('yup'))); | ||
if (error instanceof Yup.ValidationError) { | ||
const { message, path } = error; | ||
return { | ||
issues: [ | ||
new schema_1.ValidationIssue(message, path != null && path !== '' ? [path] : undefined), | ||
], | ||
}; | ||
(0, registry_1.register)(schema => '__isYupSchema__' in schema && | ||
!(0, utils_1.isTypeBoxSchema)(schema) && | ||
!(0, utils_1.isJSONSchema)(schema) | ||
? schema | ||
: null, async (schema) => { | ||
const { ValidationError } = await Promise.resolve().then(() => __importStar(require('yup'))); | ||
return { | ||
validate: async (data) => { | ||
try { | ||
return { data: await schema.validate(data, { strict: true }) }; | ||
} | ||
throw error; | ||
} | ||
}, | ||
})); | ||
catch (error) { | ||
if (error instanceof ValidationError) { | ||
const { message, path } = error; | ||
return { | ||
issues: [ | ||
new schema_1.ValidationIssue(message, path != null && path !== '' ? [path] : undefined), | ||
], | ||
}; | ||
} | ||
throw error; | ||
} | ||
}, | ||
}; | ||
}, 'yup'); |
"use strict"; | ||
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) { | ||
if (k2 === undefined) k2 = k; | ||
var desc = Object.getOwnPropertyDescriptor(m, k); | ||
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) { | ||
desc = { enumerable: true, get: function() { return m[k]; } }; | ||
} | ||
Object.defineProperty(o, k2, desc); | ||
}) : (function(o, m, k, k2) { | ||
if (k2 === undefined) k2 = k; | ||
o[k2] = m[k]; | ||
})); | ||
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) { | ||
Object.defineProperty(o, "default", { enumerable: true, value: v }); | ||
}) : function(o, v) { | ||
o["default"] = v; | ||
}); | ||
var __importStar = (this && this.__importStar) || function (mod) { | ||
if (mod && mod.__esModule) return mod; | ||
var result = {}; | ||
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k); | ||
__setModuleDefault(result, mod); | ||
return result; | ||
}; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
@@ -29,12 +6,5 @@ const registry_1 = require("../registry"); | ||
const utils_1 = require("../utils"); | ||
(0, registry_1.register)(async (schema) => { | ||
const Zod = await (0, utils_1.maybe)(() => Promise.resolve().then(() => __importStar(require('zod')))); | ||
if (Zod == null) { | ||
return null; | ||
} | ||
if (!('_def' in schema) || 'static' in schema || (0, utils_1.isJSONSchema)(schema)) { | ||
return null; | ||
} | ||
return schema; | ||
}, async (schema) => ({ | ||
(0, registry_1.register)(schema => '_def' in schema && !(0, utils_1.isTypeBoxSchema)(schema) && !(0, utils_1.isJSONSchema)(schema) | ||
? schema | ||
: null, async (schema) => ({ | ||
validate: async (data) => { | ||
@@ -49,2 +19,2 @@ const result = await schema.safeParseAsync(data); | ||
}, | ||
})); | ||
}), 'zod'); |
@@ -6,2 +6,2 @@ import type { Infer } from '.'; | ||
export declare const adapters: Array<Adapter>; | ||
export declare function register<TKey extends keyof TypeSchemaRegistry>(coerce: <TSchema extends Schema>(schema: TSchema) => Promise<InferSchema<TypeSchemaRegistry[TKey], Infer<TSchema>> | null>, wrap: <T>(schema: InferSchema<TypeSchemaRegistry[TKey], T>) => Promise<TypeSchema<T>>): void; | ||
export declare function register<TKey extends keyof TypeSchemaRegistry>(coerce: <TSchema extends Schema>(schema: TSchema) => InferSchema<TypeSchemaRegistry[TKey], Infer<TSchema>> | null, wrap: <T>(schema: InferSchema<TypeSchemaRegistry[TKey], T>) => Promise<TypeSchema<T>>, module?: string): void; |
"use strict"; | ||
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) { | ||
if (k2 === undefined) k2 = k; | ||
var desc = Object.getOwnPropertyDescriptor(m, k); | ||
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) { | ||
desc = { enumerable: true, get: function() { return m[k]; } }; | ||
} | ||
Object.defineProperty(o, k2, desc); | ||
}) : (function(o, m, k, k2) { | ||
if (k2 === undefined) k2 = k; | ||
o[k2] = m[k]; | ||
})); | ||
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) { | ||
Object.defineProperty(o, "default", { enumerable: true, value: v }); | ||
}) : function(o, v) { | ||
o["default"] = v; | ||
}); | ||
var __importStar = (this && this.__importStar) || function (mod) { | ||
if (mod && mod.__esModule) return mod; | ||
var result = {}; | ||
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k); | ||
__setModuleDefault(result, mod); | ||
return result; | ||
}; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.register = exports.adapters = void 0; | ||
const utils_1 = require("./utils"); | ||
exports.adapters = []; | ||
function register(coerce, wrap) { | ||
function register(coerce, wrap, module) { | ||
exports.adapters.push(async (schema) => { | ||
const coercedSchema = await coerce(schema); | ||
if (module != null) { | ||
const result = await (0, utils_1.maybe)(() => Promise.resolve(`${module}`).then(s => __importStar(require(s)))); | ||
if (result == null) { | ||
return null; | ||
} | ||
} | ||
const coercedSchema = coerce(schema); | ||
return coercedSchema != null ? wrap(coercedSchema) : null; | ||
@@ -9,0 +39,0 @@ }); |
{ | ||
"name": "@decs/typeschema", | ||
"version": "0.5.1", | ||
"version": "0.5.2", | ||
"description": "Universal adapter for schema validation", | ||
@@ -5,0 +5,0 @@ "keywords": [ |
Dynamic require
Supply chain riskDynamic require can indicate the package is performing dangerous or unsafe dynamic code execution.
Found 1 instance in 1 package
36895
648
1