Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

ajv

Package Overview
Dependencies
Maintainers
2
Versions
355
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

ajv - npm Package Compare versions

Comparing version 8.2.0 to 8.3.0

2

dist/core.d.ts

@@ -54,2 +54,4 @@ export { Format, FormatDefinition, AsyncFormatDefinition, KeywordDefinition, KeywordErrorDefinition, CodeKeywordDefinition, MacroKeywordDefinition, FuncKeywordDefinition, Vocabulary, Schema, SchemaObject, AnySchemaObject, AsyncSchema, AnySchema, ValidateFunction, AsyncValidateFunction, AnyValidateFunction, ErrorObject, ErrorNoParams, } from "./types";

jtd?: boolean;
/** (JTD only) Accepted Javascript types for `timestamp` type */
timestamp?: "string" | "date";
meta?: SchemaObject | boolean;

@@ -56,0 +58,0 @@ defaultMeta?: string | AnySchemaObject;

81

dist/types/json-schema.d.ts

@@ -1,4 +0,6 @@

export declare type SomeJSONSchema = JSONSchemaType<Known, true>;
export declare type PartialSchema<T> = Partial<JSONSchemaType<T, true>>;
declare type JSONType<T extends string, _partial extends boolean> = _partial extends true ? T | undefined : T;
declare type StrictNullChecksWrapper<Name extends string, Type> = undefined extends null ? `strictNullChecks must be true in tsconfig to use ${Name}` : Type;
export declare type SomeJSONSchema = UncheckedJSONSchemaType<Known, true>;
declare type UncheckedPartialSchema<T> = Partial<UncheckedJSONSchemaType<T, true>>;
export declare type PartialSchema<T> = StrictNullChecksWrapper<"PartialSchema", UncheckedPartialSchema<T>>;
declare type JSONType<T extends string, IsPartial extends boolean> = IsPartial extends true ? T | undefined : T;
interface NumberKeywords {

@@ -18,19 +20,19 @@ minimum?: number;

}
export declare type JSONSchemaType<T, _partial extends boolean = false> = (// these two unions allow arbitrary unions of types
declare type UncheckedJSONSchemaType<T, IsPartial extends boolean> = (// these two unions allow arbitrary unions of types
{
anyOf: readonly JSONSchemaType<T, _partial>[];
anyOf: readonly UncheckedJSONSchemaType<T, IsPartial>[];
} | {
oneOf: readonly JSONSchemaType<T, _partial>[];
oneOf: readonly UncheckedJSONSchemaType<T, IsPartial>[];
} | ({
type: (T extends number ? JSONType<"number" | "integer", _partial> : T extends string ? JSONType<"string", _partial> : T extends boolean ? JSONType<"boolean", _partial> : never)[];
type: (T extends number ? JSONType<"number" | "integer", IsPartial> : T extends string ? JSONType<"string", IsPartial> : T extends boolean ? JSONType<"boolean", IsPartial> : never)[];
} & (T extends number ? NumberKeywords : T extends string ? StringKeywords : T extends boolean ? unknown : never)) | ((T extends number ? {
type: JSONType<"number" | "integer", _partial>;
type: JSONType<"number" | "integer", IsPartial>;
} & NumberKeywords : T extends string ? {
type: JSONType<"string", _partial>;
type: JSONType<"string", IsPartial>;
} & StringKeywords : T extends boolean ? {
type: "boolean";
} : T extends [any, ...any[]] ? {
type: JSONType<"array", _partial>;
type: JSONType<"array", IsPartial>;
items: {
readonly [K in keyof T]-?: JSONSchemaType<T[K]> & Nullable<T[K]>;
readonly [K in keyof T]-?: UncheckedJSONSchemaType<T[K], false> & Nullable<T[K]>;
} & {

@@ -45,5 +47,5 @@ length: T["length"];

}) : T extends readonly any[] ? {
type: JSONType<"array", _partial>;
items: JSONSchemaType<T[0]>;
contains?: PartialSchema<T[0]>;
type: JSONType<"array", IsPartial>;
items: UncheckedJSONSchemaType<T[0], false>;
contains?: UncheckedPartialSchema<T[0]>;
minItems?: number;

@@ -56,14 +58,14 @@ maxItems?: number;

} : T extends Record<string, any> ? {
type: JSONType<"object", _partial>;
additionalProperties?: boolean | JSONSchemaType<T[string]>;
unevaluatedProperties?: boolean | JSONSchemaType<T[string]>;
properties?: _partial extends true ? Partial<PropertiesSchema<T>> : PropertiesSchema<T>;
type: JSONType<"object", IsPartial>;
additionalProperties?: boolean | UncheckedJSONSchemaType<T[string], false>;
unevaluatedProperties?: boolean | UncheckedJSONSchemaType<T[string], false>;
properties?: IsPartial extends true ? Partial<UncheckedPropertiesSchema<T>> : UncheckedPropertiesSchema<T>;
patternProperties?: {
[Pattern in string]?: JSONSchemaType<T[string]>;
[Pattern in string]?: UncheckedJSONSchemaType<T[string], false>;
};
propertyNames?: Omit<JSONSchemaType<string>, "type"> & {
propertyNames?: Omit<UncheckedJSONSchemaType<string, false>, "type"> & {
type?: "string";
};
dependencies?: {
[K in keyof T]?: Readonly<(keyof T)[]> | PartialSchema<T>;
[K in keyof T]?: Readonly<(keyof T)[]> | UncheckedPartialSchema<T>;
};

@@ -74,22 +76,22 @@ dependentRequired?: {

dependentSchemas?: {
[K in keyof T]?: PartialSchema<T>;
[K in keyof T]?: UncheckedPartialSchema<T>;
};
minProperties?: number;
maxProperties?: number;
} & (_partial extends true ? {
} & (IsPartial extends true ? {
required: Readonly<(keyof T)[]>;
} : [RequiredMembers<T>] extends [never] ? {
required?: Readonly<RequiredMembers<T>[]>;
} : [UncheckedRequiredMembers<T>] extends [never] ? {
required?: Readonly<UncheckedRequiredMembers<T>[]>;
} : {
required: Readonly<RequiredMembers<T>[]>;
required: Readonly<UncheckedRequiredMembers<T>[]>;
}) : T extends null ? {
nullable: true;
} : never) & {
allOf?: Readonly<PartialSchema<T>[]>;
anyOf?: Readonly<PartialSchema<T>[]>;
oneOf?: Readonly<PartialSchema<T>[]>;
if?: PartialSchema<T>;
then?: PartialSchema<T>;
else?: PartialSchema<T>;
not?: PartialSchema<T>;
allOf?: Readonly<UncheckedPartialSchema<T>[]>;
anyOf?: Readonly<UncheckedPartialSchema<T>[]>;
oneOf?: Readonly<UncheckedPartialSchema<T>[]>;
if?: UncheckedPartialSchema<T>;
then?: UncheckedPartialSchema<T>;
else?: UncheckedPartialSchema<T>;
not?: UncheckedPartialSchema<T>;
})) & {

@@ -100,19 +102,22 @@ [keyword: string]: any;

$defs?: {
[Key in string]?: JSONSchemaType<Known, true>;
[Key in string]?: UncheckedJSONSchemaType<Known, true>;
};
definitions?: {
[Key in string]?: JSONSchemaType<Known, true>;
[Key in string]?: UncheckedJSONSchemaType<Known, true>;
};
};
export declare type JSONSchemaType<T> = StrictNullChecksWrapper<"JSONSchemaType", UncheckedJSONSchemaType<T, false>>;
declare type Known = KnownRecord | [Known, ...Known[]] | Known[] | number | string | boolean | null;
interface KnownRecord extends Record<string, Known> {
}
export declare type PropertiesSchema<T> = {
[K in keyof T]-?: (JSONSchemaType<T[K]> & Nullable<T[K]>) | {
declare type UncheckedPropertiesSchema<T> = {
[K in keyof T]-?: (UncheckedJSONSchemaType<T[K], false> & Nullable<T[K]>) | {
$ref: string;
};
};
export declare type RequiredMembers<T> = {
export declare type PropertiesSchema<T> = StrictNullChecksWrapper<"PropertiesSchema", UncheckedPropertiesSchema<T>>;
declare type UncheckedRequiredMembers<T> = {
[K in keyof T]-?: undefined extends T[K] ? never : K;
}[keyof T];
export declare type RequiredMembers<T> = StrictNullChecksWrapper<"RequiredMembers", UncheckedRequiredMembers<T>>;
declare type Nullable<T> = undefined extends T ? {

@@ -119,0 +124,0 @@ nullable: true;

@@ -128,2 +128,4 @@ /** numeric strings */

} ? number : S extends {
type: "boolean";
} ? boolean : S extends {
type: "string";

@@ -130,0 +132,0 @@ } ? string : S extends {

@@ -21,2 +21,17 @@ "use strict";

};
function timestampCode(cxt) {
const { gen, data } = cxt;
switch (cxt.it.opts.timestamp) {
case "date":
return codegen_1._ `${data} instanceof Date `;
case "string": {
const vts = util_1.useFunc(gen, timestamp_1.default);
return codegen_1._ `typeof ${data} == "string" && ${vts}(${data})`;
}
default: {
const vts = util_1.useFunc(gen, timestamp_1.default);
return codegen_1._ `${data} instanceof Date || (typeof ${data} == "string" && ${vts}(${data}))`;
}
}
}
const def = {

@@ -28,3 +43,3 @@ keyword: "type",

metadata_1.checkMetadata(cxt);
const { gen, data, schema, parentSchema } = cxt;
const { data, schema, parentSchema } = cxt;
let cond;

@@ -37,4 +52,3 @@ switch (schema) {

case "timestamp": {
const vts = util_1.useFunc(gen, timestamp_1.default);
cond = codegen_1._ `${data} instanceof Date || (typeof ${data} == "string" && ${vts}(${data}))`;
cond = timestampCode(cxt);
break;

@@ -41,0 +55,0 @@ }

@@ -118,2 +118,4 @@ export {

jtd?: boolean // NEW
/** (JTD only) Accepted Javascript types for `timestamp` type */
timestamp?: "string" | "date"
meta?: SchemaObject | boolean

@@ -120,0 +122,0 @@ defaultMeta?: string | AnySchemaObject

/* eslint-disable @typescript-eslint/no-empty-interface */
export type SomeJSONSchema = JSONSchemaType<Known, true>
type StrictNullChecksWrapper<Name extends string, Type> = undefined extends null
? `strictNullChecks must be true in tsconfig to use ${Name}`
: Type
export type PartialSchema<T> = Partial<JSONSchemaType<T, true>>
export type SomeJSONSchema = UncheckedJSONSchemaType<Known, true>
type JSONType<T extends string, _partial extends boolean> = _partial extends true
type UncheckedPartialSchema<T> = Partial<UncheckedJSONSchemaType<T, true>>
export type PartialSchema<T> = StrictNullChecksWrapper<"PartialSchema", UncheckedPartialSchema<T>>
type JSONType<T extends string, IsPartial extends boolean> = IsPartial extends true
? T | undefined

@@ -26,9 +32,9 @@ : T

export type JSONSchemaType<T, _partial extends boolean = false> = (
type UncheckedJSONSchemaType<T, IsPartial extends boolean> = (
| // these two unions allow arbitrary unions of types
{
anyOf: readonly JSONSchemaType<T, _partial>[]
anyOf: readonly UncheckedJSONSchemaType<T, IsPartial>[]
}
| {
oneOf: readonly JSONSchemaType<T, _partial>[]
oneOf: readonly UncheckedJSONSchemaType<T, IsPartial>[]
}

@@ -38,7 +44,7 @@ // this union allows for { type: (primitive)[] } style schemas

type: (T extends number
? JSONType<"number" | "integer", _partial>
? JSONType<"number" | "integer", IsPartial>
: T extends string
? JSONType<"string", _partial>
? JSONType<"string", IsPartial>
: T extends boolean
? JSONType<"boolean", _partial>
? JSONType<"boolean", IsPartial>
: never)[]

@@ -55,7 +61,7 @@ } & (T extends number

? {
type: JSONType<"number" | "integer", _partial>
type: JSONType<"number" | "integer", IsPartial>
} & NumberKeywords
: T extends string
? {
type: JSONType<"string", _partial>
type: JSONType<"string", IsPartial>
} & StringKeywords

@@ -69,5 +75,5 @@ : T extends boolean

// JSON AnySchema for tuple
type: JSONType<"array", _partial>
type: JSONType<"array", IsPartial>
items: {
readonly [K in keyof T]-?: JSONSchemaType<T[K]> & Nullable<T[K]>
readonly [K in keyof T]-?: UncheckedJSONSchemaType<T[K], false> & Nullable<T[K]>
} & {length: T["length"]}

@@ -78,5 +84,5 @@ minItems: T["length"]

? {
type: JSONType<"array", _partial>
items: JSONSchemaType<T[0]>
contains?: PartialSchema<T[0]>
type: JSONType<"array", IsPartial>
items: UncheckedJSONSchemaType<T[0], false>
contains?: UncheckedPartialSchema<T[0]>
minItems?: number

@@ -95,11 +101,13 @@ maxItems?: number

// "patternProperties" and can be only used with interfaces that have string index
type: JSONType<"object", _partial>
additionalProperties?: boolean | JSONSchemaType<T[string]>
unevaluatedProperties?: boolean | JSONSchemaType<T[string]>
properties?: _partial extends true ? Partial<PropertiesSchema<T>> : PropertiesSchema<T>
patternProperties?: {[Pattern in string]?: JSONSchemaType<T[string]>}
propertyNames?: Omit<JSONSchemaType<string>, "type"> & {type?: "string"}
dependencies?: {[K in keyof T]?: Readonly<(keyof T)[]> | PartialSchema<T>}
type: JSONType<"object", IsPartial>
additionalProperties?: boolean | UncheckedJSONSchemaType<T[string], false>
unevaluatedProperties?: boolean | UncheckedJSONSchemaType<T[string], false>
properties?: IsPartial extends true
? Partial<UncheckedPropertiesSchema<T>>
: UncheckedPropertiesSchema<T>
patternProperties?: {[Pattern in string]?: UncheckedJSONSchemaType<T[string], false>}
propertyNames?: Omit<UncheckedJSONSchemaType<string, false>, "type"> & {type?: "string"}
dependencies?: {[K in keyof T]?: Readonly<(keyof T)[]> | UncheckedPartialSchema<T>}
dependentRequired?: {[K in keyof T]?: Readonly<(keyof T)[]>}
dependentSchemas?: {[K in keyof T]?: PartialSchema<T>}
dependentSchemas?: {[K in keyof T]?: UncheckedPartialSchema<T>}
minProperties?: number

@@ -110,7 +118,7 @@ maxProperties?: number

// "required" is not necessary if it's a non-partial type with no required keys
_partial extends true
IsPartial extends true
? {required: Readonly<(keyof T)[]>}
: [RequiredMembers<T>] extends [never]
? {required?: Readonly<RequiredMembers<T>[]>}
: {required: Readonly<RequiredMembers<T>[]>})
: [UncheckedRequiredMembers<T>] extends [never]
? {required?: Readonly<UncheckedRequiredMembers<T>[]>}
: {required: Readonly<UncheckedRequiredMembers<T>[]>})
: T extends null

@@ -121,9 +129,9 @@ ? {

: never) & {
allOf?: Readonly<PartialSchema<T>[]>
anyOf?: Readonly<PartialSchema<T>[]>
oneOf?: Readonly<PartialSchema<T>[]>
if?: PartialSchema<T>
then?: PartialSchema<T>
else?: PartialSchema<T>
not?: PartialSchema<T>
allOf?: Readonly<UncheckedPartialSchema<T>[]>
anyOf?: Readonly<UncheckedPartialSchema<T>[]>
oneOf?: Readonly<UncheckedPartialSchema<T>[]>
if?: UncheckedPartialSchema<T>
then?: UncheckedPartialSchema<T>
else?: UncheckedPartialSchema<T>
not?: UncheckedPartialSchema<T>
})

@@ -135,9 +143,14 @@ ) & {

$defs?: {
[Key in string]?: JSONSchemaType<Known, true>
[Key in string]?: UncheckedJSONSchemaType<Known, true>
}
definitions?: {
[Key in string]?: JSONSchemaType<Known, true>
[Key in string]?: UncheckedJSONSchemaType<Known, true>
}
}
export type JSONSchemaType<T> = StrictNullChecksWrapper<
"JSONSchemaType",
UncheckedJSONSchemaType<T, false>
>
type Known = KnownRecord | [Known, ...Known[]] | Known[] | number | string | boolean | null

@@ -147,10 +160,20 @@

export type PropertiesSchema<T> = {
[K in keyof T]-?: (JSONSchemaType<T[K]> & Nullable<T[K]>) | {$ref: string}
type UncheckedPropertiesSchema<T> = {
[K in keyof T]-?: (UncheckedJSONSchemaType<T[K], false> & Nullable<T[K]>) | {$ref: string}
}
export type RequiredMembers<T> = {
export type PropertiesSchema<T> = StrictNullChecksWrapper<
"PropertiesSchema",
UncheckedPropertiesSchema<T>
>
type UncheckedRequiredMembers<T> = {
[K in keyof T]-?: undefined extends T[K] ? never : K
}[keyof T]
export type RequiredMembers<T> = StrictNullChecksWrapper<
"RequiredMembers",
UncheckedRequiredMembers<T>
>
type Nullable<T> = undefined extends T

@@ -157,0 +180,0 @@ ? {

@@ -209,2 +209,4 @@ /** numeric strings */

? number
: S extends {type: "boolean"}
? boolean
: S extends {type: "string"}

@@ -211,0 +213,0 @@ ? string

@@ -8,2 +8,3 @@ import type {CodeKeywordDefinition, KeywordErrorDefinition} from "../../types"

import {typeErrorMessage, typeErrorParams, _JTDTypeError} from "./error"
import {_Code} from "../../compile/codegen/code"

@@ -30,2 +31,18 @@ export type JTDTypeError = _JTDTypeError<"type", JTDType, JTDType>

function timestampCode(cxt: KeywordCxt): _Code {
const {gen, data} = cxt
switch (cxt.it.opts.timestamp) {
case "date":
return _`${data} instanceof Date `
case "string": {
const vts = useFunc(gen, validTimestamp)
return _`typeof ${data} == "string" && ${vts}(${data})`
}
default: {
const vts = useFunc(gen, validTimestamp)
return _`${data} instanceof Date || (typeof ${data} == "string" && ${vts}(${data}))`
}
}
}
const def: CodeKeywordDefinition = {

@@ -37,3 +54,3 @@ keyword: "type",

checkMetadata(cxt)
const {gen, data, schema, parentSchema} = cxt
const {data, schema, parentSchema} = cxt
let cond: Code

@@ -46,4 +63,3 @@ switch (schema) {

case "timestamp": {
const vts = useFunc(gen, validTimestamp)
cond = _`${data} instanceof Date || (typeof ${data} == "string" && ${vts}(${data}))`
cond = timestampCode(cxt)
break

@@ -50,0 +66,0 @@ }

{
"name": "ajv",
"version": "8.2.0",
"version": "8.3.0",
"description": "Another JSON Schema Validator",

@@ -69,7 +69,7 @@ "main": "dist/ajv.js",

"@rollup/plugin-json": "^4.1.0",
"@rollup/plugin-node-resolve": "^11.2.1",
"@rollup/plugin-node-resolve": "^13.0.0",
"@rollup/plugin-typescript": "^8.2.1",
"@types/chai": "^4.2.12",
"@types/mocha": "^8.0.3",
"@types/node": "^14.0.27",
"@types/node": "^15.0.2",
"@types/require-from-string": "^1.2.0",

@@ -76,0 +76,0 @@ "@typescript-eslint/eslint-plugin": "^3.8.0",

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc