Comparing version 7.0.0-beta.8 to 7.0.0-beta.9
@@ -7,5 +7,5 @@ import type { AnySchema, AnySchemaObject, AnyValidateFunction, EvaluatedProperties, EvaluatedItems } from "../types"; | ||
import { JSONType } from "./rules"; | ||
export interface SchemaRefs { | ||
[ref: string]: SchemaEnv | AnySchema | undefined; | ||
} | ||
export declare type SchemaRefs = { | ||
[Ref in string]?: SchemaEnv | AnySchema; | ||
}; | ||
export interface SchemaCxt { | ||
@@ -12,0 +12,0 @@ readonly gen: CodeGen; |
import type { AnySchema, AnySchemaObject } from "../types"; | ||
import type Ajv from "../ajv"; | ||
import URI = require("uri-js"); | ||
export interface LocalRefs { | ||
[ref: string]: AnySchemaObject | undefined; | ||
} | ||
export declare type LocalRefs = { | ||
[Ref in string]?: AnySchemaObject; | ||
}; | ||
export declare function inlineRef(schema: AnySchema, limit?: boolean | number): boolean; | ||
@@ -8,0 +8,0 @@ export declare function getFullPath(id?: string, normalize?: boolean): string; |
@@ -12,6 +12,6 @@ import type { AddedKeywordDefinition } from "../types"; | ||
all: { | ||
[key: string]: boolean | Rule | undefined; | ||
[Key in string]?: boolean | Rule; | ||
}; | ||
keywords: { | ||
[key: string]: boolean | undefined; | ||
[Key in string]?: boolean; | ||
}; | ||
@@ -18,0 +18,0 @@ types: ValidationTypes; |
@@ -11,3 +11,3 @@ import type { AnySchema, EvaluatedProperties, EvaluatedItems } from "../types"; | ||
export declare function schemaHasRules(schema: AnySchema, rules: { | ||
[key: string]: boolean | Rule | undefined; | ||
[Key in string]?: boolean | Rule; | ||
}): boolean; | ||
@@ -14,0 +14,0 @@ export declare function schemaHasRulesButRef(schema: AnySchema, RULES: ValidationRules): boolean; |
@@ -36,3 +36,3 @@ export { Format, FormatDefinition, AsyncFormatDefinition, KeywordDefinition, KeywordErrorDefinition, CodeKeywordDefinition, MacroKeywordDefinition, FuncKeywordDefinition, Vocabulary, Schema, SchemaObject, AnySchemaObject, AsyncSchema, AnySchema, ValidateFunction, AsyncValidateFunction, AnyValidateFunction, ErrorObject, } from "./types"; | ||
schemas?: AnySchema[] | { | ||
[key: string]: AnySchema; | ||
[Key in string]?: AnySchema; | ||
}; | ||
@@ -39,0 +39,0 @@ logger?: Logger | false; |
@@ -23,5 +23,5 @@ import type { CodeGen, Code, Name, ScopeValueSets } from "../compile/codegen"; | ||
export declare type AnySchema = Schema | AsyncSchema; | ||
export interface SchemaMap { | ||
[key: string]: AnySchema | undefined; | ||
} | ||
export declare type SchemaMap = { | ||
[Key in string]?: AnySchema; | ||
}; | ||
export interface SourceCode { | ||
@@ -33,6 +33,8 @@ validateName: Name; | ||
} | ||
interface DataValidationCxt { | ||
export interface DataValidationCxt<T extends string | number = string | number> { | ||
dataPath: string; | ||
parentData: Record<string, any> | any[]; | ||
parentDataProperty: string | number; | ||
parentData: { | ||
[K in T]: any; | ||
}; | ||
parentDataProperty: T; | ||
rootData: Record<string, any> | any[]; | ||
@@ -142,5 +144,5 @@ dynamicAnchors: { | ||
} | ||
export interface KeywordCxtParams { | ||
[x: string]: Code | string | number | undefined; | ||
} | ||
export declare type KeywordCxtParams = { | ||
[P in string]?: Code | string | number; | ||
}; | ||
export declare type FormatValidator<T extends string | number> = (data: T) => boolean; | ||
@@ -147,0 +149,0 @@ export declare type FormatCompare<T extends string | number> = (data1: T, data2: T) => number | undefined; |
export declare type SomeJSONSchema = JSONSchemaType<Known, true>; | ||
export declare type PartialSchema<T> = Partial<JSONSchemaType<T, true>>; | ||
export declare type JSONSchemaType<T, _partial = false> = (T extends number ? { | ||
type: "number" | "integer"; | ||
declare type JSONType<T extends string, _partial extends boolean> = _partial extends true ? T | undefined : T; | ||
export declare type JSONSchemaType<T, _partial extends boolean = false> = (T extends number ? { | ||
type: JSONType<"number" | "integer", _partial>; | ||
minimum?: number; | ||
@@ -12,3 +13,3 @@ maximum?: number; | ||
} : T extends string ? { | ||
type: "string"; | ||
type: JSONType<"string", _partial>; | ||
minLength?: number; | ||
@@ -21,3 +22,3 @@ maxLength?: number; | ||
} : T extends [any, ...any[]] ? { | ||
type: "array"; | ||
type: JSONType<"array", _partial>; | ||
items: { | ||
@@ -34,3 +35,3 @@ [K in keyof T]-?: JSONSchemaType<T[K]> & Nullable<T[K]>; | ||
}) : T extends any[] ? { | ||
type: "array"; | ||
type: JSONType<"array", _partial>; | ||
items: JSONSchemaType<T[0]>; | ||
@@ -40,16 +41,25 @@ contains?: PartialSchema<T[0]>; | ||
maxItems?: number; | ||
minContains?: number; | ||
maxContains?: number; | ||
uniqueItems?: true; | ||
additionalItems?: never; | ||
} : T extends Record<string, any> ? { | ||
type: "object"; | ||
type: JSONType<"object", _partial>; | ||
required: _partial extends true ? (keyof T)[] : RequiredMembers<T>[]; | ||
additionalProperties: boolean | JSONSchemaType<T[string]>; | ||
additionalProperties?: boolean | JSONSchemaType<T[string]>; | ||
unevaluatedProperties?: boolean | JSONSchemaType<T[string]>; | ||
properties?: _partial extends true ? Partial<PropertiesSchema<T>> : PropertiesSchema<T>; | ||
patternProperties?: { | ||
[pattern: string]: JSONSchemaType<T[string]>; | ||
[Pattern in string]?: JSONSchemaType<T[string]>; | ||
}; | ||
propertyNames?: JSONSchemaType<string>; | ||
dependencies?: { | ||
[K in keyof T]?: (keyof T)[] | PartialSchema<T> | undefined; | ||
[K in keyof T]?: (keyof T)[] | PartialSchema<T>; | ||
}; | ||
dependentRequired?: { | ||
[K in keyof T]?: (keyof T)[]; | ||
}; | ||
dependentSchemas?: { | ||
[K in keyof T]?: PartialSchema<T>; | ||
}; | ||
minProperties?: number; | ||
@@ -64,6 +74,6 @@ maxProperties?: number; | ||
$defs?: { | ||
[key: string]: JSONSchemaType<Known, true>; | ||
[Key in string]?: JSONSchemaType<Known, true>; | ||
}; | ||
definitions?: { | ||
[key: string]: JSONSchemaType<Known, true>; | ||
[Key in string]?: JSONSchemaType<Known, true>; | ||
}; | ||
@@ -70,0 +80,0 @@ allOf?: PartialSchema<T>[]; |
@@ -12,5 +12,5 @@ import type { CodeKeywordDefinition, ErrorObject, KeywordErrorDefinition, SchemaMap } from "../../types"; | ||
export declare function validatePropertyDeps(cxt: KeywordCxt, propertyDeps?: { | ||
[x: string]: string[]; | ||
[K in string]?: string[]; | ||
}): void; | ||
export declare function validateSchemaDeps(cxt: KeywordCxt, schemaDeps?: SchemaMap): void; | ||
export default def; |
@@ -20,4 +20,4 @@ import type { | ||
export interface SchemaRefs { | ||
[ref: string]: SchemaEnv | AnySchema | undefined | ||
export type SchemaRefs = { | ||
[Ref in string]?: SchemaEnv | AnySchema | ||
} | ||
@@ -24,0 +24,0 @@ |
@@ -9,5 +9,3 @@ import type {AnySchema, AnySchemaObject} from "../types" | ||
// the hash of local references inside the schema (created by getSchemaRefs), used for inline resolution | ||
export interface LocalRefs { | ||
[ref: string]: AnySchemaObject | undefined | ||
} | ||
export type LocalRefs = {[Ref in string]?: AnySchemaObject} | ||
@@ -98,3 +96,3 @@ // TODO refactor to use keyword definitions | ||
const schemaId = normalizeId(schema.$id) | ||
const baseIds: {[jsonPtr: string]: string} = {"": schemaId} | ||
const baseIds: {[JsonPtr in string]?: string} = {"": schemaId} | ||
const pathPrefix = getFullPath(schemaId, false) | ||
@@ -101,0 +99,0 @@ const localRefs: LocalRefs = {} |
@@ -20,4 +20,4 @@ import type {AddedKeywordDefinition} from "../types" | ||
post: RuleGroup | ||
all: {[key: string]: boolean | Rule | undefined} // rules that have to be validated | ||
keywords: {[key: string]: boolean | undefined} // all known keywords (superset of "all") | ||
all: {[Key in string]?: boolean | Rule} // rules that have to be validated | ||
keywords: {[Key in string]?: boolean} // all known keywords (superset of "all") | ||
types: ValidationTypes | ||
@@ -24,0 +24,0 @@ } |
@@ -33,3 +33,3 @@ import type {AnySchema, EvaluatedProperties, EvaluatedItems} from "../types" | ||
schema: AnySchema, | ||
rules: {[key: string]: boolean | Rule | undefined} | ||
rules: {[Key in string]?: boolean | Rule} | ||
): boolean { | ||
@@ -36,0 +36,0 @@ if (typeof schema == "boolean") return !schema |
@@ -96,3 +96,3 @@ export { | ||
keywords?: Vocabulary | ||
schemas?: AnySchema[] | {[key: string]: AnySchema} | ||
schemas?: AnySchema[] | {[Key in string]?: AnySchema} | ||
logger?: Logger | false | ||
@@ -610,6 +610,3 @@ loadSchema?: (uri: string) => Promise<AnySchemaObject> | ||
private _removeAllSchemas( | ||
schemas: {[ref: string]: SchemaEnv | string | undefined}, | ||
regex?: RegExp | ||
): void { | ||
private _removeAllSchemas(schemas: {[Ref in string]?: SchemaEnv | string}, regex?: RegExp): void { | ||
for (const keyRef in schemas) { | ||
@@ -706,3 +703,3 @@ const sch = schemas[keyRef] | ||
if (Array.isArray(optsSchemas)) this.addSchema(optsSchemas) | ||
else for (const key in optsSchemas) this.addSchema(optsSchemas[key], key) | ||
else for (const key in optsSchemas) this.addSchema(optsSchemas[key] as AnySchema, key) | ||
} | ||
@@ -717,3 +714,6 @@ | ||
function addInitialKeywords(this: Ajv, defs: Vocabulary | {[x: string]: KeywordDefinition}): void { | ||
function addInitialKeywords( | ||
this: Ajv, | ||
defs: Vocabulary | {[K in string]?: KeywordDefinition} | ||
): void { | ||
if (Array.isArray(defs)) { | ||
@@ -725,3 +725,3 @@ this.addVocabulary(defs) | ||
for (const keyword in defs) { | ||
const def = defs[keyword] | ||
const def = defs[keyword] as KeywordDefinition | ||
if (!def.keyword) def.keyword = keyword | ||
@@ -728,0 +728,0 @@ this.addKeyword(def) |
@@ -30,5 +30,3 @@ import type {CodeGen, Code, Name, ScopeValueSets} from "../compile/codegen" | ||
export interface SchemaMap { | ||
[key: string]: AnySchema | undefined | ||
} | ||
export type SchemaMap = {[Key in string]?: AnySchema} | ||
@@ -42,6 +40,6 @@ export interface SourceCode { | ||
interface DataValidationCxt { | ||
export interface DataValidationCxt<T extends string | number = string | number> { | ||
dataPath: string | ||
parentData: Record<string, any> | any[] | ||
parentDataProperty: string | number | ||
parentData: {[K in T]: any} // object or array | ||
parentDataProperty: T // string or number | ||
rootData: Record<string, any> | any[] | ||
@@ -187,5 +185,3 @@ dynamicAnchors: {[Ref in string]?: ValidateFunction} | ||
export interface KeywordCxtParams { | ||
[x: string]: Code | string | number | undefined | ||
} | ||
export type KeywordCxtParams = {[P in string]?: Code | string | number} | ||
@@ -192,0 +188,0 @@ export type FormatValidator<T extends string | number> = (data: T) => boolean |
@@ -6,5 +6,9 @@ /* eslint-disable @typescript-eslint/no-empty-interface */ | ||
export type JSONSchemaType<T, _partial = false> = (T extends number | ||
type JSONType<T extends string, _partial extends boolean> = _partial extends true | ||
? T | undefined | ||
: T | ||
export type JSONSchemaType<T, _partial extends boolean = false> = (T extends number | ||
? { | ||
type: "number" | "integer" | ||
type: JSONType<"number" | "integer", _partial> | ||
minimum?: number | ||
@@ -19,3 +23,3 @@ maximum?: number | ||
? { | ||
type: "string" | ||
type: JSONType<"string", _partial> | ||
minLength?: number | ||
@@ -33,3 +37,3 @@ maxLength?: number | ||
// JSON AnySchema for tuple | ||
type: "array" | ||
type: JSONType<"array", _partial> | ||
items: { | ||
@@ -42,3 +46,3 @@ [K in keyof T]-?: JSONSchemaType<T[K]> & Nullable<T[K]> | ||
? { | ||
type: "array" | ||
type: JSONType<"array", _partial> | ||
items: JSONSchemaType<T[0]> | ||
@@ -48,2 +52,4 @@ contains?: PartialSchema<T[0]> | ||
maxItems?: number | ||
minContains?: number | ||
maxContains?: number | ||
uniqueItems?: true | ||
@@ -54,19 +60,18 @@ additionalItems?: never | ||
? { | ||
// JSON AnySchema for records and dicitonaries | ||
// "required" and "additionalProperties" are not optional because they are often forgotten | ||
// "properties" are optional for more concise dicitonary schemas | ||
// JSON AnySchema for records and dictionaries | ||
// "required" is not optional because it is often forgotten | ||
// "properties" are optional for more concise dictionary schemas | ||
// "patternProperties" and can be only used with interfaces that have string index | ||
type: "object" | ||
type: JSONType<"object", _partial> | ||
// "required" type does not guarantee that all required properties are listed | ||
// it only asserts that optional cannot be listed | ||
required: _partial extends true ? (keyof T)[] : RequiredMembers<T>[] | ||
additionalProperties: boolean | JSONSchemaType<T[string]> | ||
additionalProperties?: boolean | JSONSchemaType<T[string]> | ||
unevaluatedProperties?: boolean | JSONSchemaType<T[string]> | ||
properties?: _partial extends true ? Partial<PropertiesSchema<T>> : PropertiesSchema<T> | ||
patternProperties?: { | ||
[pattern: string]: JSONSchemaType<T[string]> | ||
} | ||
patternProperties?: {[Pattern in string]?: JSONSchemaType<T[string]>} | ||
propertyNames?: JSONSchemaType<string> | ||
dependencies?: { | ||
[K in keyof T]?: (keyof T)[] | PartialSchema<T> | undefined | ||
} | ||
dependencies?: {[K in keyof T]?: (keyof T)[] | PartialSchema<T>} | ||
dependentRequired?: {[K in keyof T]?: (keyof T)[]} | ||
dependentSchemas?: {[K in keyof T]?: PartialSchema<T>} | ||
minProperties?: number | ||
@@ -84,6 +89,6 @@ maxProperties?: number | ||
$defs?: { | ||
[key: string]: JSONSchemaType<Known, true> | ||
[Key in string]?: JSONSchemaType<Known, true> | ||
} | ||
definitions?: { | ||
[key: string]: JSONSchemaType<Known, true> | ||
[Key in string]?: JSONSchemaType<Known, true> | ||
} | ||
@@ -114,4 +119,4 @@ allOf?: PartialSchema<T>[] | ||
nullable: true | ||
const?: never // any non-null value would fail `null`, `null` would fail any other value | ||
enum?: (T | null)[] // `null` must be explicitely included in "enum" for `null` to pass | ||
const?: never // any non-null value would fail `const: null`, `null` would fail any other value in const | ||
enum?: (T | null)[] // `null` must be explicitly included in "enum" for `null` to pass | ||
default?: T | null | ||
@@ -118,0 +123,0 @@ } |
@@ -13,5 +13,3 @@ import type { | ||
interface PropertyDependencies { | ||
[x: string]: string[] | ||
} | ||
type PropertyDependencies = {[K in string]?: string[]} | ||
@@ -67,3 +65,3 @@ type SchemaDependencies = SchemaMap | ||
cxt: KeywordCxt, | ||
propertyDeps: {[x: string]: string[]} = cxt.schema | ||
propertyDeps: {[K in string]?: string[]} = cxt.schema | ||
): void { | ||
@@ -74,3 +72,3 @@ const {gen, data, it} = cxt | ||
for (const prop in propertyDeps) { | ||
const deps = propertyDeps[prop] | ||
const deps = propertyDeps[prop] as string[] | ||
if (deps.length === 0) continue | ||
@@ -77,0 +75,0 @@ const hasProperty = propertyInData(data, prop, it.opts.ownProperties) |
{ | ||
"name": "ajv", | ||
"version": "7.0.0-beta.8", | ||
"version": "7.0.0-beta.9", | ||
"description": "Another JSON Schema Validator", | ||
@@ -5,0 +5,0 @@ "main": "dist/ajv.js", |
@@ -9,3 +9,3 @@ <img align="right" alt="Ajv logo" width="160" src="https://ajv.js.org/images/ajv_logo.png"> | ||
[![npm](https://img.shields.io/npm/v/ajv.svg)](https://www.npmjs.com/package/ajv) | ||
[![npm (beta)](https://img.shields.io/npm/v/ajv/beta)](https://www.npmjs.com/package/ajv/v/7.0.0-beta.8) | ||
[![npm (beta)](https://img.shields.io/npm/v/ajv/beta)](https://www.npmjs.com/package/ajv/v/7.0.0-beta.9) | ||
[![npm downloads](https://img.shields.io/npm/dm/ajv.svg)](https://www.npmjs.com/package/ajv) | ||
@@ -12,0 +12,0 @@ [![Coverage Status](https://coveralls.io/repos/github/ajv-validator/ajv/badge.svg?branch=master)](https://coveralls.io/github/ajv-validator/ajv?branch=master) |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
864148
13973