Comparing version 8.7.1 to 8.8.0
@@ -13,3 +13,3 @@ export { Format, FormatDefinition, AsyncFormatDefinition, KeywordDefinition, KeywordErrorDefinition, CodeKeywordDefinition, MacroKeywordDefinition, FuncKeywordDefinition, Vocabulary, Schema, SchemaObject, AnySchemaObject, AsyncSchema, AnySchema, ValidateFunction, AsyncValidateFunction, AnyValidateFunction, ErrorObject, ErrorNoParams, } from "./types"; | ||
export { _, str, stringify, nil, Name, Code, CodeGen, CodeGenOptions } from "./compile/codegen"; | ||
import type { Schema, AnySchema, AnySchemaObject, SchemaObject, AsyncSchema, Vocabulary, KeywordDefinition, AddedKeywordDefinition, AnyValidateFunction, ValidateFunction, AsyncValidateFunction, ErrorObject, Format, AddedFormat } from "./types"; | ||
import type { Schema, AnySchema, AnySchemaObject, SchemaObject, AsyncSchema, Vocabulary, KeywordDefinition, AddedKeywordDefinition, AnyValidateFunction, ValidateFunction, AsyncValidateFunction, ErrorObject, Format, AddedFormat, RegExpEngine } from "./types"; | ||
import type { JSONSchemaType } from "./types/json-schema"; | ||
@@ -80,4 +80,6 @@ import type { JTDSchemaType, SomeJTDSchemaType, JTDDataType } from "./types/jtd-schema"; | ||
process?: (code: string, schema?: SchemaEnv) => string; | ||
regExp?: RegExpEngine; | ||
} | ||
interface InstanceCodeOptions extends CodeOptions { | ||
regExp: RegExpEngine; | ||
optimize: number; | ||
@@ -84,0 +86,0 @@ } |
@@ -22,2 +22,4 @@ "use strict"; | ||
const $dataRefSchema = require("./refs/data.json"); | ||
const defaultRegExp = (str, flags) => new RegExp(str, flags); | ||
defaultRegExp.code = "new RegExp"; | ||
const META_IGNORE_OPTIONS = ["removeAdditional", "useDefaults", "coerceTypes"]; | ||
@@ -64,24 +66,25 @@ const EXT_SCOPE_NAMES = new Set([ | ||
function requiredOptions(o) { | ||
var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l, _m, _o, _p, _q, _r, _s, _t, _u, _v, _w, _x; | ||
var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l, _m, _o, _p, _q, _r, _s, _t, _u, _v, _w, _x, _y, _z; | ||
const s = o.strict; | ||
const _optz = (_a = o.code) === null || _a === void 0 ? void 0 : _a.optimize; | ||
const optimize = _optz === true || _optz === undefined ? 1 : _optz || 0; | ||
const regExp = (_c = (_b = o.code) === null || _b === void 0 ? void 0 : _b.regExp) !== null && _c !== void 0 ? _c : defaultRegExp; | ||
return { | ||
strictSchema: (_c = (_b = o.strictSchema) !== null && _b !== void 0 ? _b : s) !== null && _c !== void 0 ? _c : true, | ||
strictNumbers: (_e = (_d = o.strictNumbers) !== null && _d !== void 0 ? _d : s) !== null && _e !== void 0 ? _e : true, | ||
strictTypes: (_g = (_f = o.strictTypes) !== null && _f !== void 0 ? _f : s) !== null && _g !== void 0 ? _g : "log", | ||
strictTuples: (_j = (_h = o.strictTuples) !== null && _h !== void 0 ? _h : s) !== null && _j !== void 0 ? _j : "log", | ||
strictRequired: (_l = (_k = o.strictRequired) !== null && _k !== void 0 ? _k : s) !== null && _l !== void 0 ? _l : false, | ||
code: o.code ? { ...o.code, optimize } : { optimize }, | ||
loopRequired: (_m = o.loopRequired) !== null && _m !== void 0 ? _m : MAX_EXPRESSION, | ||
loopEnum: (_o = o.loopEnum) !== null && _o !== void 0 ? _o : MAX_EXPRESSION, | ||
meta: (_p = o.meta) !== null && _p !== void 0 ? _p : true, | ||
messages: (_q = o.messages) !== null && _q !== void 0 ? _q : true, | ||
inlineRefs: (_r = o.inlineRefs) !== null && _r !== void 0 ? _r : true, | ||
schemaId: (_s = o.schemaId) !== null && _s !== void 0 ? _s : "$id", | ||
addUsedSchema: (_t = o.addUsedSchema) !== null && _t !== void 0 ? _t : true, | ||
validateSchema: (_u = o.validateSchema) !== null && _u !== void 0 ? _u : true, | ||
validateFormats: (_v = o.validateFormats) !== null && _v !== void 0 ? _v : true, | ||
unicodeRegExp: (_w = o.unicodeRegExp) !== null && _w !== void 0 ? _w : true, | ||
int32range: (_x = o.int32range) !== null && _x !== void 0 ? _x : true, | ||
strictSchema: (_e = (_d = o.strictSchema) !== null && _d !== void 0 ? _d : s) !== null && _e !== void 0 ? _e : true, | ||
strictNumbers: (_g = (_f = o.strictNumbers) !== null && _f !== void 0 ? _f : s) !== null && _g !== void 0 ? _g : true, | ||
strictTypes: (_j = (_h = o.strictTypes) !== null && _h !== void 0 ? _h : s) !== null && _j !== void 0 ? _j : "log", | ||
strictTuples: (_l = (_k = o.strictTuples) !== null && _k !== void 0 ? _k : s) !== null && _l !== void 0 ? _l : "log", | ||
strictRequired: (_o = (_m = o.strictRequired) !== null && _m !== void 0 ? _m : s) !== null && _o !== void 0 ? _o : false, | ||
code: o.code ? { ...o.code, optimize, regExp } : { optimize, regExp }, | ||
loopRequired: (_p = o.loopRequired) !== null && _p !== void 0 ? _p : MAX_EXPRESSION, | ||
loopEnum: (_q = o.loopEnum) !== null && _q !== void 0 ? _q : MAX_EXPRESSION, | ||
meta: (_r = o.meta) !== null && _r !== void 0 ? _r : true, | ||
messages: (_s = o.messages) !== null && _s !== void 0 ? _s : true, | ||
inlineRefs: (_t = o.inlineRefs) !== null && _t !== void 0 ? _t : true, | ||
schemaId: (_u = o.schemaId) !== null && _u !== void 0 ? _u : "$id", | ||
addUsedSchema: (_v = o.addUsedSchema) !== null && _v !== void 0 ? _v : true, | ||
validateSchema: (_w = o.validateSchema) !== null && _w !== void 0 ? _w : true, | ||
validateFormats: (_x = o.validateFormats) !== null && _x !== void 0 ? _x : true, | ||
unicodeRegExp: (_y = o.unicodeRegExp) !== null && _y !== void 0 ? _y : true, | ||
int32range: (_z = o.int32range) !== null && _z !== void 0 ? _z : true, | ||
}; | ||
@@ -88,0 +91,0 @@ } |
@@ -170,2 +170,9 @@ import type { CodeGen, Code, Name, ScopeValueSets, ValueScopeName } from "../compile/codegen"; | ||
export declare type Format = AddedFormat | string; | ||
export interface RegExpEngine { | ||
(pattern: string, u: string): RegExpLike; | ||
code: string; | ||
} | ||
export interface RegExpLike { | ||
test: (s: string) => boolean; | ||
} | ||
export {}; |
@@ -7,2 +7,3 @@ "use strict"; | ||
const names_1 = require("../compile/names"); | ||
const util_2 = require("../compile/util"); | ||
function checkReportMissingProp(cxt, prop) { | ||
@@ -69,8 +70,10 @@ const { gen, data, it } = cxt; | ||
exports.callValidateCode = callValidateCode; | ||
const newRegExp = (0, codegen_1._) `new RegExp`; | ||
function usePattern({ gen, it: { opts } }, pattern) { | ||
const u = opts.unicodeRegExp ? "u" : ""; | ||
const { regExp } = opts.code; | ||
return gen.scopeValue("pattern", { | ||
key: pattern, | ||
ref: new RegExp(pattern, u), | ||
code: (0, codegen_1._) `new RegExp(${pattern}, ${u})`, | ||
ref: regExp(pattern, u), | ||
code: (0, codegen_1._) `${regExp.code === "new RegExp" ? newRegExp : (0, util_2.useFunc)(gen, regExp)}(${pattern}, ${u})`, | ||
}); | ||
@@ -77,0 +80,0 @@ } |
@@ -51,2 +51,3 @@ export { | ||
AddedFormat, | ||
RegExpEngine, | ||
} from "./types" | ||
@@ -66,2 +67,5 @@ import type {JSONSchemaType} from "./types/json-schema" | ||
const defaultRegExp: RegExpEngine = (str, flags) => new RegExp(str, flags) | ||
defaultRegExp.code = "new RegExp" | ||
const META_IGNORE_OPTIONS: (keyof Options)[] = ["removeAdditional", "useDefaults", "coerceTypes"] | ||
@@ -146,5 +150,7 @@ const EXT_SCOPE_NAMES = new Set([ | ||
process?: (code: string, schema?: SchemaEnv) => string | ||
regExp?: RegExpEngine | ||
} | ||
interface InstanceCodeOptions extends CodeOptions { | ||
regExp: RegExpEngine | ||
optimize: number | ||
@@ -237,2 +243,3 @@ } | ||
const optimize = _optz === true || _optz === undefined ? 1 : _optz || 0 | ||
const regExp = o.code?.regExp ?? defaultRegExp | ||
return { | ||
@@ -244,3 +251,3 @@ strictSchema: o.strictSchema ?? s ?? true, | ||
strictRequired: o.strictRequired ?? s ?? false, | ||
code: o.code ? {...o.code, optimize} : {optimize}, | ||
code: o.code ? {...o.code, optimize, regExp} : {optimize, regExp}, | ||
loopRequired: o.loopRequired ?? MAX_EXPRESSION, | ||
@@ -287,2 +294,3 @@ loopEnum: o.loopEnum ?? MAX_EXPRESSION, | ||
const {es5, lines} = this.opts.code | ||
this.scope = new ValueScope({scope: {}, prefixes: EXT_SCOPE_NAMES, es5, lines}) | ||
@@ -289,0 +297,0 @@ this.logger = getLogger(opts.logger) |
@@ -225,1 +225,10 @@ import type {CodeGen, Code, Name, ScopeValueSets, ValueScopeName} from "../compile/codegen" | ||
export type Format = AddedFormat | string | ||
export interface RegExpEngine { | ||
(pattern: string, u: string): RegExpLike | ||
code: string | ||
} | ||
export interface RegExpLike { | ||
test: (s: string) => boolean | ||
} |
@@ -7,3 +7,3 @@ import type {AnySchema, SchemaMap} from "../types" | ||
import N from "../compile/names" | ||
import {useFunc} from "../compile/util" | ||
export function checkReportMissingProp(cxt: KeywordCxt, prop: string): void { | ||
@@ -94,8 +94,12 @@ const {gen, data, it} = cxt | ||
const newRegExp = _`new RegExp` | ||
export function usePattern({gen, it: {opts}}: KeywordCxt, pattern: string): Name { | ||
const u = opts.unicodeRegExp ? "u" : "" | ||
const {regExp} = opts.code | ||
return gen.scopeValue("pattern", { | ||
key: pattern, | ||
ref: new RegExp(pattern, u), | ||
code: _`new RegExp(${pattern}, ${u})`, | ||
ref: regExp(pattern, u), | ||
code: _`${regExp.code === "new RegExp" ? newRegExp : useFunc(gen, regExp)}(${pattern}, ${u})`, | ||
}) | ||
@@ -102,0 +106,0 @@ } |
{ | ||
"name": "ajv", | ||
"version": "8.7.1", | ||
"version": "8.8.0", | ||
"description": "Another JSON Schema Validator", | ||
@@ -20,3 +20,4 @@ "main": "dist/ajv.js", | ||
"test-cov": "nyc npm run test-spec", | ||
"bundle": "rm -rf bundle && rollup -c", | ||
"rollup": "rm -rf bundle && rollup -c", | ||
"bundle": "rm -rf bundle && node ./scripts/bundle.js ajv ajv7 ajv7 && node ./scripts/bundle.js 2019 ajv2019 ajv2019 && node ./scripts/bundle.js 2020 ajv2020 ajv2020 && node ./scripts/bundle.js jtd ajvJTD ajvJTD", | ||
"build": "rm -rf dist && tsc && cp -r lib/refs dist && rm dist/refs/json-schema-2019-09/index.ts && rm dist/refs/json-schema-2020-12/index.ts && rm dist/refs/jtd-schema.ts", | ||
@@ -79,2 +80,3 @@ "json-tests": "rm -rf spec/_json/*.js && node scripts/jsontests", | ||
"ajv-formats": "^3.0.0-rc.0", | ||
"browserify": "^17.0.0", | ||
"chai": "^4.0.1", | ||
@@ -100,2 +102,3 @@ "cross-env": "^7.0.2", | ||
"prettier": "^2.3.1", | ||
"re2": "^1.16.0", | ||
"rollup": "^2.44.0", | ||
@@ -102,0 +105,0 @@ "rollup-plugin-terser": "^7.0.2", |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
1009069
462
19768
39