@decs/typeschema
Advanced tools
Comparing version 0.6.1 to 0.6.2
import type { Resolver } from '../resolver'; | ||
import type { FromJSONSchema, JSONSchema } from '../utils'; | ||
import type { SchemaObject } from 'ajv'; | ||
interface AjvResolver extends Resolver { | ||
base: JSONSchema; | ||
input: this['schema'] extends JSONSchema ? FromJSONSchema<this['schema']> : never; | ||
output: this['schema'] extends JSONSchema ? FromJSONSchema<this['schema']> : never; | ||
base: SchemaObject; | ||
input: never; | ||
output: never; | ||
} | ||
@@ -8,0 +8,0 @@ declare global { |
@@ -29,3 +29,5 @@ "use strict"; | ||
const utils_1 = require("../utils"); | ||
(registry_1.register.Ω = [undefined], (0, registry_1.register)(schema => ('kind' in schema && !(0, utils_1.isTypeBoxSchema)(schema) ? schema : null), async (schema) => { | ||
(registry_1.register.Ω = [undefined], (0, registry_1.register)(schema => 'kind' in schema && !(0, utils_1.isTypeBoxSchema)(schema) && !(0, utils_1.isJSONSchema)(schema) | ||
? schema | ||
: null, async (schema) => { | ||
const { validate } = await Promise.resolve().then(() => __importStar(require('@deepkit/type'))); | ||
@@ -32,0 +34,0 @@ return { |
@@ -29,3 +29,5 @@ "use strict"; | ||
const utils_1 = require("../utils"); | ||
(registry_1.register.Ω = [undefined], (0, registry_1.register)(schema => ('context' in schema && !(0, utils_1.isTypeBoxSchema)(schema) ? schema : null), async (schema) => { | ||
(registry_1.register.Ω = [undefined], (0, registry_1.register)(schema => 'context' in schema && !(0, utils_1.isTypeBoxSchema)(schema) && !(0, utils_1.isJSONSchema)(schema) | ||
? schema | ||
: null, async (schema) => { | ||
const ow = await Promise.resolve().then(() => __importStar(require('ow'))); | ||
@@ -32,0 +34,0 @@ const { ArgumentError } = ow; |
@@ -7,4 +7,2 @@ "use strict"; | ||
var _a; | ||
// eslint-disable-next-line @typescript-eslint/ban-ts-comment | ||
// @ts-ignore json-schema-to-ts can slow down type computation | ||
const wrappedSchema = (_a = (0, wrap_1.wrapCached)(schema)) !== null && _a !== void 0 ? _a : (await (0, wrap_1.wrap)(schema)); | ||
@@ -11,0 +9,0 @@ return wrappedSchema.validate(data); |
import type { Schema } from './schema'; | ||
import type { TKind, TSchema as TypeBoxSchema } from '@sinclair/typebox'; | ||
import type { FromSchema, JSONSchema as ActualJSONSchema } from 'json-schema-to-ts'; | ||
import type { TSchema } from '@sinclair/typebox'; | ||
import type { SchemaObject } from 'ajv'; | ||
export type IfDefined<T> = any extends T ? never : T; | ||
export declare function maybe<T>(fn: () => Promise<T>): Promise<T | undefined>; | ||
export declare function isTypeBoxSchema(schema: Schema): schema is TypeBoxSchema; | ||
export type JSONSchema = Exclude<ActualJSONSchema, boolean>; | ||
export type FromJSONSchema<TSchema extends JSONSchema> = TSchema extends IfDefined<TKind> ? never : FromSchema<TSchema>; | ||
export declare function isJSONSchema(schema: Schema): schema is JSONSchema; | ||
export declare function isTypeBoxSchema(schema: Schema): schema is TSchema; | ||
export declare function isJSONSchema(schema: Schema): schema is SchemaObject; |
@@ -19,6 +19,3 @@ "use strict"; | ||
} | ||
const results = | ||
// eslint-disable-next-line @typescript-eslint/ban-ts-comment | ||
// @ts-ignore json-schema-to-ts can slow down type computation | ||
await Promise.all(registry_1.adapters.map(async (adapter) => ({ | ||
const results = await Promise.all(registry_1.adapters.map(async (adapter) => ({ | ||
adapter, | ||
@@ -25,0 +22,0 @@ wrappedSchema: await adapter(schema), |
{ | ||
"name": "@decs/typeschema", | ||
"version": "0.6.1", | ||
"version": "0.6.2", | ||
"description": "Universal adapter for schema validation", | ||
@@ -141,6 +141,3 @@ "keywords": [ | ||
} | ||
}, | ||
"dependencies": { | ||
"json-schema-to-ts": "^2.9.1" | ||
} | ||
} |
@@ -85,3 +85,3 @@ <div id="header"> | ||
| [joi](https://joi.dev) | <a href="https://github.com/hapijs/joi" rel="nofollow"><img src="https://img.shields.io/github/stars/hapijs/joi?style=social" alt="GitHub stars"></a> | `Joi.string()` | ✅[^1] | | ||
| [ajv](https://ajv.js.org) | <a href="https://github.com/ajv-validator/ajv" rel="nofollow"><img src="https://img.shields.io/github/stars/ajv-validator/ajv?style=social" alt="GitHub stars"></a> | `{type: "string"} as const` | ✅ | | ||
| [ajv](https://ajv.js.org) | <a href="https://github.com/ajv-validator/ajv" rel="nofollow"><img src="https://img.shields.io/github/stars/ajv-validator/ajv?style=social" alt="GitHub stars"></a> | `{type: "string"}` | ✅[^1] | | ||
| [superstruct](https://docs.superstructjs.org) | <a href="https://github.com/ianstormtaylor/superstruct" rel="nofollow"><img src="https://img.shields.io/github/stars/ianstormtaylor/superstruct?style=social" alt="GitHub stars"></a> | `string()` | ✅[^2] | | ||
@@ -96,3 +96,3 @@ | [io-ts](https://gcanti.github.io/io-ts) | <a href="https://github.com/gcanti/io-ts" rel="nofollow"><img src="https://img.shields.io/github/stars/gcanti/io-ts?style=social" alt="GitHub stars"></a> | `t.string` | ✅ | | ||
[^1]: Type inference is not yet supported for [joi](https://joi.dev) and [deepkit](https://deepkit.io) | ||
[^1]: Type inference is not yet supported for [joi](https://joi.dev), [ajv](https://ajv.js.org), and [deepkit](https://deepkit.io) | ||
[^2]: Input type inference is not yet supported for [superstruct](https://docs.superstructjs.org) | ||
@@ -177,2 +177,1 @@ [^3]: For [ow](https://sindresorhus.com/ow), only v0.28.2 is supported (sindresorhus/ow#248) | ||
- API definition inspired by [@colinhacks](https://github.com/colinhacks)'s [proposal](https://twitter.com/colinhacks/status/1634284724796661761) | ||
- JSON Schema type inference powered by [`json-schema-to-ts`](https://github.com/ThomasAribart/json-schema-to-ts) |
12
44125
770
175
- Removedjson-schema-to-ts@^2.9.1
- Removed@babel/runtime@7.26.9(transitive)
- Removed@types/json-schema@7.0.15(transitive)
- Removedjson-schema-to-ts@2.12.0(transitive)
- Removedregenerator-runtime@0.14.1(transitive)
- Removedts-algebra@1.2.2(transitive)