Socket
Socket
Sign inDemoInstall

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 7.0.0-beta.7 to 7.0.0-beta.8

dist/compile/ucs2length.d.ts

2

dist/compile/codegen/index.d.ts

@@ -5,3 +5,3 @@ import type { ScopeValueSets, NameValue, ValueScope, ValueScopeName } from "./scope";

export { _, str, strConcat, nil, getProperty, stringify, Name, Code } from "./code";
export { Scope, ScopeStore, ValueScope } from "./scope";
export { Scope, ScopeStore, ValueScope, ScopeValueSets } from "./scope";
export declare type SafeExpr = Code | number | boolean | null;

@@ -8,0 +8,0 @@ export declare type Block = Code | (() => void);

@@ -20,11 +20,11 @@ import { Code, Name } from "./code";

export declare type ScopeStore = Record<string, ValueReference[] | undefined>;
interface ScopeValues {
[prefix: string]: Map<unknown, ValueScopeName> | undefined;
}
export interface ScopeValueSets {
[prefix: string]: Set<ValueScopeName> | undefined;
}
declare type ScopeValues = {
[Prefix in string]?: Map<unknown, ValueScopeName>;
};
export declare type ScopeValueSets = {
[Prefix in string]?: Set<ValueScopeName>;
};
export declare class Scope {
protected readonly _names: {
[prefix: string]: NameGroup | undefined;
[Prefix in string]?: NameGroup;
};

@@ -59,5 +59,5 @@ protected readonly _prefixes?: Set<string>;

scopeRefs(scopeName: Name, values?: ScopeValues | ScopeValueSets): Code;
scopeCode(values?: ScopeValues | ScopeValueSets): Code;
scopeCode(values?: ScopeValues | ScopeValueSets, usedValues?: ScopeValueSets, getCode?: (n: ValueScopeName) => Code | undefined): Code;
private _reduceValues;
}
export {};

@@ -95,17 +95,30 @@ "use strict";

}
scopeCode(values = this._values) {
scopeCode(values = this._values, usedValues, getCode) {
return this._reduceValues(values, (name) => {
var _a;
const c = (_a = name.value) === null || _a === void 0 ? void 0 : _a.code;
if (c)
return c;
throw new ValueError(name);
});
if (name.value === undefined)
throw new Error(`CodeGen: name "${name}" has no value`);
return name.value.code;
}, usedValues, getCode);
}
_reduceValues(values, valueCode) {
var _a;
_reduceValues(values, valueCode, usedValues = {}, getCode) {
let code = code_1.nil;
for (const prefix in values) {
(_a = values[prefix]) === null || _a === void 0 ? void 0 : _a.forEach((name) => {
code = code_1._ `${code}const ${name} = ${valueCode(name)};`;
const vs = values[prefix];
if (!vs)
continue;
const nameSet = (usedValues[prefix] = usedValues[prefix] || new Set());
vs.forEach((name) => {
if (nameSet.has(name))
return;
nameSet.add(name);
let c = valueCode(name);
if (c) {
code = code_1._ `${code}const ${name} = ${c};`;
}
else if ((c = getCode === null || getCode === void 0 ? void 0 : getCode(name))) {
code = code_1._ `${code}${c}`;
}
else {
throw new ValueError(name);
}
});

@@ -112,0 +125,0 @@ }

@@ -59,3 +59,5 @@ "use strict";

dataTypes: [],
topSchemaRef: gen.scopeValue("schema", { ref: sch.schema }),
topSchemaRef: gen.scopeValue("schema", this.opts.code.source === true
? { ref: sch.schema, code: codegen_1.stringify(sch.schema) }
: { ref: sch.schema }),
validateName,

@@ -81,3 +83,4 @@ ValidationError: _ValidationError,

// gen.optimize(1)
sourceCode = `${gen.scopeRefs(names_1.default.scope)}${gen}`;
const validateCode = gen.toString();
sourceCode = `${gen.scopeRefs(names_1.default.scope)}return ${validateCode}`;
// console.log((codeSize += sourceCode.length), (nodeCount += gen.nodeCount))

@@ -89,3 +92,3 @@ if (this.opts.code.process)

const validate = makeValidate(this, this.scope.get());
gen.scopeValue(validateName, { ref: validate });
this.scope.value(validateName, { ref: validate });
validate.errors = null;

@@ -97,6 +100,3 @@ validate.schema = sch.schema;

if (this.opts.code.source === true) {
validate.source = {
code: sourceCode,
scope: this.scope,
};
validate.source = { validateName, validateCode, scopeValues: gen._values };
}

@@ -111,2 +111,4 @@ if (this.opts.unevaluated) {

};
if (validate.source)
validate.source.evaluated = codegen_1.stringify(validate.evaluated);
}

@@ -113,0 +115,0 @@ sch.validate = validate;

@@ -20,3 +20,2 @@ import type { AnySchema, EvaluatedProperties, EvaluatedItems } from "../types";

export declare function eachItem<T>(xs: T | T[], f: (x: T) => void): void;
export declare function ucs2length(str: string): number;
declare type SomeEvaluated = EvaluatedProperties | EvaluatedItems;

@@ -23,0 +22,0 @@ declare type MergeEvaluatedFunc<T extends SomeEvaluated> = (gen: CodeGen, from: Name | T, to: Name | Exclude<T, true> | undefined, toName?: typeof Name) => Name | T;

"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.setEvaluated = exports.evaluatedPropsToName = exports.mergeEvaluated = exports.ucs2length = exports.eachItem = exports.unescapeJsonPointer = exports.escapeJsonPointer = exports.escapeFragment = exports.unescapeFragment = exports.schemaRefOrVal = exports.schemaHasRulesButRef = exports.schemaHasRules = exports.checkUnknownRules = exports.alwaysValidSchema = exports.toHash = void 0;
exports.setEvaluated = exports.evaluatedPropsToName = exports.mergeEvaluated = exports.eachItem = exports.unescapeJsonPointer = exports.escapeJsonPointer = exports.escapeFragment = exports.unescapeFragment = exports.schemaRefOrVal = exports.schemaHasRulesButRef = exports.schemaHasRules = exports.checkUnknownRules = exports.alwaysValidSchema = exports.toHash = void 0;
const codegen_1 = require("./codegen");

@@ -92,22 +92,2 @@ const validate_1 = require("./validate");

exports.eachItem = eachItem;
// https://mathiasbynens.be/notes/javascript-encoding
// https://github.com/bestiejs/punycode.js - punycode.ucs2.decode
function ucs2length(str) {
const len = str.length;
let length = 0;
let pos = 0;
let value;
while (pos < len) {
length++;
value = str.charCodeAt(pos++);
if (value >= 0xd800 && value <= 0xdbff && pos < len) {
// high surrogate, and there is a next character
value = str.charCodeAt(pos);
if ((value & 0xfc00) === 0xdc00)
pos++; // low surrogate
}
}
return length;
}
exports.ucs2length = ucs2length;
function makeMergeEvaluated({ mergeNames, mergeToName, mergeValues, resultToName, }) {

@@ -114,0 +94,0 @@ return (gen, from, to, toName) => {

@@ -24,9 +24,12 @@ "use strict";

function validateFunction({ gen, validateName, schema, schemaEnv, opts }, body) {
gen.return(() => opts.code.es5
? gen.func(validateName, codegen_1._ `${names_1.default.data}, ${names_1.default.valCxt}`, schemaEnv.$async, () => {
if (opts.code.es5) {
gen.func(validateName, codegen_1._ `${names_1.default.data}, ${names_1.default.valCxt}`, schemaEnv.$async, () => {
gen.code(codegen_1._ `"use strict"; ${funcSourceUrl(schema, opts)}`);
destructureValCxtES5(gen, opts);
gen.code(body);
})
: gen.func(validateName, codegen_1._ `${names_1.default.data}, ${destructureValCxt(opts)}`, schemaEnv.$async, () => gen.code(funcSourceUrl(schema, opts)).code(body)));
});
}
else {
gen.func(validateName, codegen_1._ `${names_1.default.data}, ${destructureValCxt(opts)}`, schemaEnv.$async, () => gen.code(funcSourceUrl(schema, opts)).code(body));
}
}

@@ -33,0 +36,0 @@ function destructureValCxt(opts) {

@@ -105,4 +105,4 @@ "use strict";

throw new Error(`keyword "${keyword}" failed to compile`);
return gen.scopeValue("keyword", { ref: result }); // TODO value.code
return gen.scopeValue("keyword", typeof result == "function" ? { ref: result } : { ref: result, code: codegen_1.stringify(result) });
}
//# sourceMappingURL=keyword.js.map

@@ -1,2 +0,2 @@

export { Format, FormatDefinition, AsyncFormatDefinition, KeywordDefinition, KeywordErrorDefinition, CodeKeywordDefinition, MacroKeywordDefinition, FuncKeywordDefinition, Vocabulary, Schema, SchemaObject, AnySchemaObject, AsyncSchema, AnySchema, ValidateFunction, AsyncValidateFunction, ErrorObject, } from "./types";
export { Format, FormatDefinition, AsyncFormatDefinition, KeywordDefinition, KeywordErrorDefinition, CodeKeywordDefinition, MacroKeywordDefinition, FuncKeywordDefinition, Vocabulary, Schema, SchemaObject, AnySchemaObject, AsyncSchema, AnySchema, ValidateFunction, AsyncValidateFunction, AnyValidateFunction, ErrorObject, } from "./types";
export { SchemaCxt, SchemaObjCxt } from "./compile";

@@ -95,9 +95,9 @@ export interface Plugin<Opts> {

readonly schemas: {
[key: string]: SchemaEnv | undefined;
[Key in string]?: SchemaEnv;
};
readonly refs: {
[ref: string]: SchemaEnv | string | undefined;
[Ref in string]?: SchemaEnv | string;
};
readonly formats: {
[name: string]: AddedFormat | undefined;
[Name in string]?: AddedFormat;
};

@@ -104,0 +104,0 @@ readonly RULES: ValidationRules;

@@ -130,7 +130,6 @@ "use strict";

if (!v)
throw new Error('no schema with key or ref "' + schemaKeyRef + '"');
throw new Error(`no schema with key or ref "${schemaKeyRef}"`);
}
else {
const sch = this._addSchema(schemaKeyRef);
v = sch.validate || this._compileSchemaEnv(sch);
v = this.compile(schemaKeyRef);
}

@@ -137,0 +136,0 @@ const valid = v(data);

@@ -1,2 +0,2 @@

import type { CodeGen, Code, Name, Scope } from "../compile/codegen";
import type { CodeGen, Code, Name, ScopeValueSets } from "../compile/codegen";
import type { SchemaEnv, SchemaCxt, SchemaObjCxt } from "../compile";

@@ -26,5 +26,7 @@ import type { JSONType } from "../compile/rules";

}
interface SourceCode {
code: string;
scope: Scope;
export interface SourceCode {
validateName: Name;
validateCode: string;
scopeValues: ScopeValueSets;
evaluated?: Code;
}

@@ -31,0 +33,0 @@ interface DataValidationCxt {

@@ -15,3 +15,3 @@ "use strict";

const { gen, schema, it } = cxt;
const { baseId, schemaEnv: env, validateName, self } = it;
const { baseId, schemaEnv: env, validateName, opts, self } = it;
if (schema === "#" || schema === "#/")

@@ -44,3 +44,3 @@ return callRootRef();

function inlineRefSchema(sch) {
const schName = gen.scopeValue("schema", { ref: sch });
const schName = gen.scopeValue("schema", opts.code.source === true ? { ref: sch, code: codegen_1.stringify(sch) } : { ref: sch });
const valid = gen.name("valid");

@@ -47,0 +47,0 @@ const schCxt = cxt.subschema({

@@ -33,3 +33,3 @@ "use strict";

gen.if(codegen_1._ `typeof ${fDef} == "object" && !(${fDef} instanceof RegExp)`, () => gen.assign(fType, codegen_1._ `${fDef}.type || "string"`).assign(format, codegen_1._ `${fDef}.validate`), () => gen.assign(fType, codegen_1._ `"string"`).assign(format, fDef));
cxt.fail$data(codegen_1.or(unknownFmt(), invalidFmt())); // TODO this is not tested. Possibly require ajv-formats to test formats in ajv as well
cxt.fail$data(codegen_1.or(unknownFmt(), invalidFmt()));
function unknownFmt() {

@@ -36,0 +36,0 @@ if (opts.strict === false)

"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
const codegen_1 = require("../../compile/codegen");
const util_1 = require("../../compile/util");
const ucs2length_1 = require("../../compile/ucs2length");
const error = {

@@ -27,4 +27,4 @@ message({ keyword, schemaCode }) {

const u2l = cxt.gen.scopeValue("func", {
ref: util_1.ucs2length,
code: codegen_1._ `require("ajv/dist/compile/ucs2length")`,
ref: ucs2length_1.default,
code: codegen_1._ `require("ajv/dist/compile/ucs2length").default`,
});

@@ -31,0 +31,0 @@ len = codegen_1._ `${u2l}(${data})`;

@@ -10,3 +10,3 @@ # Security considerations

- [ReDoS attack](#redos-attack)
- [Content Security Policies](#content-security-policies)
- [Content Security Policy](#content-security-policy)

@@ -78,10 +78,8 @@ ## Security contact

## Content Security Policies
## Content Security Policy
If you're using Ajv in a browser document that is loaded with a Content Security Policy (CSP), that policy will require a `script-src` directive that includes the value `'unsafe-eval'`.
When using Ajv in a browser page with enabled Content Security Policy (CSP), `script-src` directive must include `'unsafe-eval'`.
:warning: NOTE, however, that `unsafe-eval` is NOT recommended in a secure CSP[[1]](https://developer.chrome.com/extensions/contentSecurityPolicy#relaxing-eval), as it has the potential to open the document to cross-site scripting (XSS) attacks.
**Please note**: `unsafe-eval` is NOT recommended in a secure CSP[[1]](https://developer.chrome.com/extensions/contentSecurityPolicy#relaxing-eval), as it has the potential to open the document to cross-site scripting (XSS) attacks.
In order to make use of Ajv without easing your CSP, you can [pre-compile a schema using the CLI](https://github.com/ajv-validator/ajv-cli#compile-schemas). This will transpile the schema JSON into a JavaScript file that exports a `validate` function that works similarly to a schema compiled at runtime.
Note that pre-compilation of schemas is performed using [ajv-pack](https://github.com/ajv-validator/ajv-pack) and there are [some limitations to the schema features it can compile](https://github.com/ajv-validator/ajv-pack#limitations). A successfully pre-compiled schema is equivalent to the same schema compiled at runtime.
In order to use Ajv without relaxing CSP, you can [compile the schemas using CLI](https://github.com/ajv-validator/ajv-cli#compile-schemas) or programmatically in your build code - see [Standalone validation code](./standalone.md). Compiled JavaScript file can export one or several validation functions that have the same code as the schemas compiled at runtime.

@@ -6,3 +6,3 @@ import type {ScopeValueSets, NameValue, ValueScope, ValueScopeName} from "./scope"

export {_, str, strConcat, nil, getProperty, stringify, Name, Code} from "./code"
export {Scope, ScopeStore, ValueScope} from "./scope"
export {Scope, ScopeStore, ValueScope, ScopeValueSets} from "./scope"

@@ -9,0 +9,0 @@ // type for expressions that can be safely inserted in code without quotes

@@ -35,12 +35,12 @@ import {_, nil, Code, Name} from "./code"

interface ScopeValues {
[prefix: string]: Map<unknown, ValueScopeName> | undefined
type ScopeValues = {
[Prefix in string]?: Map<unknown, ValueScopeName>
}
export interface ScopeValueSets {
[prefix: string]: Set<ValueScopeName> | undefined
export type ScopeValueSets = {
[Prefix in string]?: Set<ValueScopeName>
}
export class Scope {
protected readonly _names: {[prefix: string]: NameGroup | undefined} = {}
protected readonly _names: {[Prefix in string]?: NameGroup} = {}
protected readonly _prefixes?: Set<string>

@@ -147,8 +147,16 @@ protected readonly _parent?: Scope

scopeCode(values: ScopeValues | ScopeValueSets = this._values): Code {
return this._reduceValues(values, (name: ValueScopeName) => {
const c = name.value?.code
if (c) return c
throw new ValueError(name)
})
scopeCode(
values: ScopeValues | ScopeValueSets = this._values,
usedValues?: ScopeValueSets,
getCode?: (n: ValueScopeName) => Code | undefined
): Code {
return this._reduceValues(
values,
(name: ValueScopeName) => {
if (name.value === undefined) throw new Error(`CodeGen: name "${name}" has no value`)
return name.value.code
},
usedValues,
getCode
)
}

@@ -158,8 +166,22 @@

values: ScopeValues | ScopeValueSets,
valueCode: (n: ValueScopeName) => Code
valueCode: (n: ValueScopeName) => Code | undefined,
usedValues: ScopeValueSets = {},
getCode?: (n: ValueScopeName) => Code | undefined
): Code {
let code: Code = nil
for (const prefix in values) {
values[prefix]?.forEach((name: ValueScopeName) => {
code = _`${code}const ${name} = ${valueCode(name)};`
const vs = values[prefix]
if (!vs) continue
const nameSet = (usedValues[prefix] = usedValues[prefix] || new Set())
vs.forEach((name: ValueScopeName) => {
if (nameSet.has(name)) return
nameSet.add(name)
let c = valueCode(name)
if (c) {
code = _`${code}const ${name} = ${c};`
} else if ((c = getCode?.(name))) {
code = _`${code}${c}`
} else {
throw new ValueError(name)
}
})

@@ -166,0 +188,0 @@ }

@@ -11,3 +11,3 @@ import type {

import type {InstanceOptions} from "../core"
import {CodeGen, _, nil, Name, Code} from "./codegen"
import {CodeGen, _, nil, stringify, Name, Code} from "./codegen"
import {ValidationError} from "./error_classes"

@@ -126,6 +126,11 @@ import N from "./names"

dataNames: [N.data],
dataPathArr: [nil], // TODO can its lenght be used as dataLevel if nil is removed?
dataPathArr: [nil], // TODO can its length be used as dataLevel if nil is removed?
dataLevel: 0,
dataTypes: [],
topSchemaRef: gen.scopeValue("schema", {ref: sch.schema}),
topSchemaRef: gen.scopeValue(
"schema",
this.opts.code.source === true
? {ref: sch.schema, code: stringify(sch.schema)}
: {ref: sch.schema}
),
validateName,

@@ -152,3 +157,4 @@ ValidationError: _ValidationError,

// gen.optimize(1)
sourceCode = `${gen.scopeRefs(N.scope)}${gen}`
const validateCode = gen.toString()
sourceCode = `${gen.scopeRefs(N.scope)}return ${validateCode}`
// console.log((codeSize += sourceCode.length), (nodeCount += gen.nodeCount))

@@ -159,3 +165,3 @@ if (this.opts.code.process) sourceCode = this.opts.code.process(sourceCode, sch)

const validate: AnyValidateFunction = makeValidate(this, this.scope.get())
gen.scopeValue(validateName, {ref: validate})
this.scope.value(validateName, {ref: validate})

@@ -167,6 +173,3 @@ validate.errors = null

if (this.opts.code.source === true) {
validate.source = {
code: sourceCode,
scope: this.scope,
}
validate.source = {validateName, validateCode, scopeValues: gen._values}
}

@@ -181,2 +184,3 @@ if (this.opts.unevaluated) {

}
if (validate.source) validate.source.evaluated = stringify(validate.evaluated)
}

@@ -183,0 +187,0 @@ sch.validate = validate

@@ -84,21 +84,2 @@ import type {AnySchema, EvaluatedProperties, EvaluatedItems} from "../types"

// https://mathiasbynens.be/notes/javascript-encoding
// https://github.com/bestiejs/punycode.js - punycode.ucs2.decode
export function ucs2length(str: string): number {
const len = str.length
let length = 0
let pos = 0
let value: number
while (pos < len) {
length++
value = str.charCodeAt(pos++)
if (value >= 0xd800 && value <= 0xdbff && pos < len) {
// high surrogate, and there is a next character
value = str.charCodeAt(pos)
if ((value & 0xfc00) === 0xdc00) pos++ // low surrogate
}
}
return length
}
type SomeEvaluated = EvaluatedProperties | EvaluatedItems

@@ -105,0 +86,0 @@

@@ -28,13 +28,13 @@ import type {AnySchema} from "../../types"

): void {
gen.return(() =>
opts.code.es5
? gen.func(validateName, _`${N.data}, ${N.valCxt}`, schemaEnv.$async, () => {
gen.code(_`"use strict"; ${funcSourceUrl(schema, opts)}`)
destructureValCxtES5(gen, opts)
gen.code(body)
})
: gen.func(validateName, _`${N.data}, ${destructureValCxt(opts)}`, schemaEnv.$async, () =>
gen.code(funcSourceUrl(schema, opts)).code(body)
)
)
if (opts.code.es5) {
gen.func(validateName, _`${N.data}, ${N.valCxt}`, schemaEnv.$async, () => {
gen.code(_`"use strict"; ${funcSourceUrl(schema, opts)}`)
destructureValCxtES5(gen, opts)
gen.code(body)
})
} else {
gen.func(validateName, _`${N.data}, ${destructureValCxt(opts)}`, schemaEnv.$async, () =>
gen.code(funcSourceUrl(schema, opts)).code(body)
)
}
}

@@ -41,0 +41,0 @@

@@ -14,3 +14,3 @@ import type {

import {callValidateCode} from "../../vocabularies/code"
import {CodeGen, _, nil, not, Code, Name} from "../codegen"
import {CodeGen, _, nil, not, stringify, Code, Name} from "../codegen"
import N from "../names"

@@ -141,3 +141,6 @@

if (result === undefined) throw new Error(`keyword "${keyword}" failed to compile`)
return gen.scopeValue("keyword", {ref: result}) // TODO value.code
return gen.scopeValue(
"keyword",
typeof result == "function" ? {ref: result} : {ref: result, code: stringify(result)}
)
}

@@ -18,2 +18,3 @@ export {

AsyncValidateFunction,
AnyValidateFunction,
ErrorObject,

@@ -241,8 +242,8 @@ } from "./types"

readonly scope = new ValueScope({scope: {}, prefixes: EXT_SCOPE_NAMES})
readonly schemas: {[key: string]: SchemaEnv | undefined} = {}
readonly refs: {[ref: string]: SchemaEnv | string | undefined} = {}
readonly formats: {[name: string]: AddedFormat | undefined} = {}
readonly schemas: {[Key in string]?: SchemaEnv} = {}
readonly refs: {[Ref in string]?: SchemaEnv | string} = {}
readonly formats: {[Name in string]?: AddedFormat} = {}
readonly RULES: ValidationRules
readonly _compilations: Set<SchemaEnv> = new Set()
private readonly _loading: {[ref: string]: Promise<AnySchemaObject> | undefined} = {}
private readonly _loading: {[Ref in string]?: Promise<AnySchemaObject>} = {}
private readonly _cache: Map<AnySchema, SchemaEnv> = new Map()

@@ -305,6 +306,5 @@ private readonly _metaOpts: InstanceOptions

v = this.getSchema(schemaKeyRef)
if (!v) throw new Error('no schema with key or ref "' + schemaKeyRef + '"')
if (!v) throw new Error(`no schema with key or ref "${schemaKeyRef}"`)
} else {
const sch = this._addSchema(schemaKeyRef)
v = sch.validate || this._compileSchemaEnv(sch)
v = this.compile<T>(schemaKeyRef)
}

@@ -311,0 +311,0 @@

@@ -1,2 +0,2 @@

import type {CodeGen, Code, Name, Scope} from "../compile/codegen"
import type {CodeGen, Code, Name, ScopeValueSets} from "../compile/codegen"
import type {SchemaEnv, SchemaCxt, SchemaObjCxt} from "../compile"

@@ -34,5 +34,7 @@ import type {JSONType} from "../compile/rules"

interface SourceCode {
code: string
scope: Scope
export interface SourceCode {
validateName: Name
validateCode: string
scopeValues: ScopeValueSets
evaluated?: Code
}

@@ -39,0 +41,0 @@

@@ -5,3 +5,3 @@ import type {CodeKeywordDefinition, AnySchema} from "../../types"

import {callValidateCode} from "../code"
import {_, nil, Code, Name} from "../../compile/codegen"
import {_, nil, stringify, Code, Name} from "../../compile/codegen"
import N from "../../compile/names"

@@ -16,3 +16,3 @@ import {SchemaEnv, resolveRef} from "../../compile"

const {gen, schema, it} = cxt
const {baseId, schemaEnv: env, validateName, self} = it
const {baseId, schemaEnv: env, validateName, opts, self} = it
if (schema === "#" || schema === "#/") return callRootRef()

@@ -43,3 +43,6 @@ const schOrEnv = resolveRef.call(self, env.root, baseId, schema)

function inlineRefSchema(sch: AnySchema): void {
const schName = gen.scopeValue("schema", {ref: sch})
const schName = gen.scopeValue(
"schema",
opts.code.source === true ? {ref: sch, code: stringify(sch)} : {ref: sch}
)
const valid = gen.name("valid")

@@ -46,0 +49,0 @@ const schCxt = cxt.subschema(

@@ -56,3 +56,3 @@ import type {

)
cxt.fail$data(or(unknownFmt(), invalidFmt())) // TODO this is not tested. Possibly require ajv-formats to test formats in ajv as well
cxt.fail$data(or(unknownFmt(), invalidFmt()))

@@ -59,0 +59,0 @@ function unknownFmt(): Code {

import type {CodeKeywordDefinition, KeywordErrorDefinition} from "../../types"
import type KeywordCxt from "../../compile/context"
import {_, str, operators} from "../../compile/codegen"
import {ucs2length} from "../../compile/util"
import ucs2length from "../../compile/ucs2length"

@@ -29,3 +29,3 @@ const error: KeywordErrorDefinition = {

ref: ucs2length,
code: _`require("ajv/dist/compile/ucs2length")`,
code: _`require("ajv/dist/compile/ucs2length").default`,
})

@@ -32,0 +32,0 @@ len = _`${u2l}(${data})`

{
"name": "ajv",
"version": "7.0.0-beta.7",
"version": "7.0.0-beta.8",
"description": "Another JSON Schema Validator",

@@ -28,3 +28,3 @@ "main": "dist/ajv.js",

"test-all": "npm run test-cov && if-node-version 12 npm run test-browser",
"test": "npm run build && npm run json-tests && npm run eslint && npm run test-cov",
"test": "npm link && npm link ajv && npm run json-tests && npm run eslint && npm run test-cov",
"test-ci": "AJV_FULL_TEST=true npm test",

@@ -68,2 +68,3 @@ "prepublish": "npm run build",

"json-schema-traverse": "^0.5.0",
"require-from-string": "^2.0.2",
"uri-js": "^4.2.2"

@@ -76,5 +77,6 @@ },

"@types/node": "^14.0.27",
"@types/require-from-string": "^1.2.0",
"@typescript-eslint/eslint-plugin": "^3.8.0",
"@typescript-eslint/parser": "^3.8.0",
"ajv-formats": "^0.5.0",
"ajv-formats": "^0.6.1",
"browserify": "^17.0.0",

@@ -81,0 +83,0 @@ "chai": "^4.0.1",

@@ -7,5 +7,5 @@ <img align="right" alt="Ajv logo" width="160" src="https://ajv.js.org/images/ajv_logo.png">

[![Build Status](https://travis-ci.org/ajv-validator/ajv.svg?branch=master)](https://travis-ci.org/ajv-validator/ajv)
[![build](https://github.com/ajv-validator/ajv/workflows/build/badge.svg)](https://github.com/ajv-validator/ajv/actions?query=workflow%3Abuild)
[![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.5)
[![npm (beta)](https://img.shields.io/npm/v/ajv/beta)](https://www.npmjs.com/package/ajv/v/7.0.0-beta.8)
[![npm downloads](https://img.shields.io/npm/dm/ajv.svg)](https://www.npmjs.com/package/ajv)

@@ -55,3 +55,3 @@ [![Coverage Status](https://coveralls.io/repos/github/ajv-validator/ajv/badge.svg?branch=master)](https://coveralls.io/github/ajv-validator/ajv?branch=master)

- [Using in browser](#using-in-browser)
- [Content Security Policies](./docs/security.md#content-security-policies)
- [Content Security Policy](./docs/security.md#content-security-policy)
- [Command line interface](#command-line-interface)

@@ -71,2 +71,3 @@ - [API reference](./docs/api.md)

- [Asynchronous schema compilation](./docs/validation.md#asynchronous-schema-compilation)
- [Standalone validation code](./docs/standalone.md)
- [Asynchronous validation](./docs/validation.md#asynchronous-validation)

@@ -81,3 +82,3 @@ - [Modifying data](./docs/validation.md#modifying-data-during-validation): [additional properties](./docs/validation.md#removing-additional-properties), [defaults](./docs/validation.md#assigning-defaults), [type coercion](./docs/validation.md#coercing-data-types)

- [ReDoS attack](./docs/security.md#redos-attack)
- [Content Security Policies](./docs/security.md#content-security-policies)
- [Content Security Policy](./docs/security.md#content-security-policy)
- [Plugins](#plugins)

@@ -257,3 +258,3 @@ - [Related packages](#related-packages)

See [Content Security Policies](./docs/security.md#content-security-policies) to decide the best approach how to use Ajv in the browser.
See [Content Security Policy](./docs/security.md#content-security-policy) to decide the best approach how to use Ajv in the browser.

@@ -281,3 +282,3 @@ Whether you use Ajv or compiled schemas, it is recommended that you bundle them together with your code.

- compiling JSON Schemas to test their validity
- BETA: generating standalone module exporting a validation function to be used without Ajv (using [ajv-pack](https://github.com/ajv-validator/ajv-pack))
- generating [standalone validation code](./docs/standalone.md) that exports validation function(s) to be used without Ajv
- migrate schemas to draft-07 (using [json-schema-migrate](https://github.com/epoberezkin/json-schema-migrate))

@@ -314,3 +315,2 @@ - validating data file(s) against JSON Schema

- [ajv-merge-patch](https://github.com/ajv-validator/ajv-merge-patch) - plugin with keywords $merge and $patch
- [ajv-pack](https://github.com/ajv-validator/ajv-pack) - produces a compact module exporting validation functions
- [ajv-formats-draft2019](https://github.com/luzlab/ajv-formats-draft2019) - format validators for draft2019 that aren't included in [ajv-formats](https://github.com/ajv-validator/ajv-formats) (ie. `idn-hostname`, `idn-email`, `iri`, `iri-reference` and `duration`).

@@ -317,0 +317,0 @@

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

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

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