Socket
Socket
Sign inDemoInstall

ajv

Package Overview
Dependencies
5
Maintainers
2
Versions
351
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

Comparing version 8.0.5 to 8.1.0

2

dist/compile/validate/keyword.d.ts

@@ -8,2 +8,2 @@ import type { KeywordCxt } from ".";

export declare function validSchemaType(schema: unknown, schemaType: JSONType[], allowUndefined?: boolean): boolean;
export declare function validateKeywordUsage({ schema, opts, self }: SchemaObjCxt, def: AddedKeywordDefinition, keyword: string): void;
export declare function validateKeywordUsage({ schema, opts, self, errSchemaPath }: SchemaObjCxt, def: AddedKeywordDefinition, keyword: string): void;

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

exports.validSchemaType = validSchemaType;
function validateKeywordUsage({ schema, opts, self }, def, keyword) {
function validateKeywordUsage({ schema, opts, self, errSchemaPath }, def, keyword) {
/* istanbul ignore if */

@@ -115,3 +115,4 @@ if (Array.isArray(def.keyword) ? !def.keyword.includes(keyword) : def.keyword !== keyword) {

if (!valid) {
const msg = "keyword value is invalid: " + self.errorsText(def.validateSchema.errors);
const msg = `keyword "${keyword}" value is invalid at path "${errSchemaPath}": ` +
self.errorsText(def.validateSchema.errors);
if (opts.validateSchema === "log")

@@ -118,0 +119,0 @@ self.logger.error(msg);

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

discriminator?: boolean;
unicodeRegExp?: boolean;
$comment?: true | ((comment: string, schemaPath?: string, rootSchema?: AnySchemaObject) => unknown);

@@ -87,3 +88,3 @@ formats?: {

declare type RequiredInstanceOptions = {
[K in "strictSchema" | "strictNumbers" | "strictTypes" | "strictTuples" | "strictRequired" | "inlineRefs" | "loopRequired" | "loopEnum" | "meta" | "messages" | "addUsedSchema" | "validateSchema" | "validateFormats"]: NonNullable<Options[K]>;
[K in "strictSchema" | "strictNumbers" | "strictTypes" | "strictTuples" | "strictRequired" | "inlineRefs" | "loopRequired" | "loopEnum" | "meta" | "messages" | "addUsedSchema" | "validateSchema" | "validateFormats" | "unicodeRegExp"]: NonNullable<Options[K]>;
} & {

@@ -90,0 +91,0 @@ code: InstanceCodeOptions;

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

function requiredOptions(o) {
var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l, _m, _o, _p, _q, _r, _s, _t, _u;
var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l, _m, _o, _p, _q, _r, _s, _t, _u, _v;
const s = o.strict;

@@ -84,2 +84,3 @@ const _optz = (_a = o.code) === null || _a === void 0 ? void 0 : _a.optimize;

validateFormats: (_u = o.validateFormats) !== null && _u !== void 0 ? _u : true,
unicodeRegExp: (_v = o.unicodeRegExp) !== null && _v !== void 0 ? _v : true,
};

@@ -86,0 +87,0 @@ }

@@ -59,3 +59,3 @@ /** required keys of an object, not undefined */

} : never : true extends IsValues<T> ? T extends Record<string, infer V> ? {
values: JTDSchemaType<V>;
values: JTDSchemaType<V, D>;
} : never : true extends IsRecord<T, false> ? ([RequiredKeys<Exclude<T, null>>] extends [never] ? {

@@ -62,0 +62,0 @@ properties?: Record<string, never>;

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

if (patProps.length) {
definedProp = codegen_1.or(definedProp, ...patProps.map((p) => codegen_1._ `${code_1.usePattern(gen, p)}.test(${key})`));
definedProp = codegen_1.or(definedProp, ...patProps.map((p) => codegen_1._ `${code_1.usePattern(cxt, p)}.test(${key})`));
}

@@ -56,0 +56,0 @@ return codegen_1.not(definedProp);

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

gen.forIn("key", data, (key) => {
gen.if(codegen_1._ `${code_1.usePattern(gen, pat)}.test(${key})`, () => {
gen.if(codegen_1._ `${code_1.usePattern(cxt, pat)}.test(${key})`, () => {
cxt.subschema({

@@ -51,0 +51,0 @@ keyword: "patternProperties",

@@ -15,4 +15,4 @@ import type { SchemaMap } from "../types";

export declare function callValidateCode({ schemaCode, data, it: { gen, topSchemaRef, schemaPath, errorPath }, it }: KeywordCxt, func: Code, context: Code, passSchema?: boolean): Code;
export declare function usePattern(gen: CodeGen, pattern: string): Name;
export declare function usePattern({ gen, it: { opts } }: KeywordCxt, pattern: string): Name;
export declare function validateArray(cxt: KeywordCxt): Name;
export declare function validateUnion(cxt: KeywordCxt): void;

@@ -68,7 +68,8 @@ "use strict";

exports.callValidateCode = callValidateCode;
function usePattern(gen, pattern) {
function usePattern({ gen, it: { opts } }, pattern) {
const u = opts.unicodeRegExp ? "u" : "";
return gen.scopeValue("pattern", {
key: pattern,
ref: new RegExp(pattern, "u"),
code: codegen_1._ `new RegExp(${pattern}, "u")`,
ref: new RegExp(pattern, u),
code: codegen_1._ `new RegExp(${pattern}, ${u})`,
});

@@ -75,0 +76,0 @@ }

@@ -16,4 +16,6 @@ "use strict";

code(cxt) {
const { gen, data, $data, schema, schemaCode } = cxt;
const regExp = $data ? codegen_1._ `(new RegExp(${schemaCode}, "u"))` : code_1.usePattern(gen, schema); // TODO regexp should be wrapped in try/catch
const { data, $data, schema, schemaCode, it } = cxt;
// TODO regexp should be wrapped in try/catchs
const u = it.opts.unicodeRegExp ? "u" : "";
const regExp = $data ? codegen_1._ `(new RegExp(${schemaCode}, ${u}))` : code_1.usePattern(cxt, schema);
cxt.fail$data(codegen_1._ `!${regExp}.test(${data})`);

@@ -20,0 +22,0 @@ },

@@ -147,3 +147,3 @@ import type {KeywordCxt} from "."

export function validateKeywordUsage(
{schema, opts, self}: SchemaObjCxt,
{schema, opts, self, errSchemaPath}: SchemaObjCxt,
def: AddedKeywordDefinition,

@@ -165,3 +165,5 @@ keyword: string

if (!valid) {
const msg = "keyword value is invalid: " + self.errorsText(def.validateSchema.errors)
const msg =
`keyword "${keyword}" value is invalid at path "${errSchemaPath}": ` +
self.errorsText(def.validateSchema.errors)
if (opts.validateSchema === "log") self.logger.error(msg)

@@ -168,0 +170,0 @@ else throw new Error(msg)

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

discriminator?: boolean
unicodeRegExp?: boolean
$comment?:

@@ -216,3 +217,4 @@ | true

| "validateSchema"
| "validateFormats"]: NonNullable<Options[K]>
| "validateFormats"
| "unicodeRegExp"]: NonNullable<Options[K]>
} & {code: InstanceCodeOptions}

@@ -244,2 +246,3 @@

validateFormats: o.validateFormats ?? true,
unicodeRegExp: o.unicodeRegExp ?? true,
}

@@ -246,0 +249,0 @@ }

@@ -112,3 +112,3 @@ /** required keys of an object, not undefined */

? {
values: JTDSchemaType<V>
values: JTDSchemaType<V, D>
}

@@ -115,0 +115,0 @@ : never

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

if (patProps.length) {
definedProp = or(definedProp, ...patProps.map((p) => _`${usePattern(gen, p)}.test(${key})`))
definedProp = or(definedProp, ...patProps.map((p) => _`${usePattern(cxt, p)}.test(${key})`))
}

@@ -66,0 +66,0 @@ return not(definedProp)

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

gen.forIn("key", data, (key) => {
gen.if(_`${usePattern(gen, pat)}.test(${key})`, () => {
gen.if(_`${usePattern(cxt, pat)}.test(${key})`, () => {
cxt.subschema(

@@ -56,0 +56,0 @@ {

@@ -93,7 +93,8 @@ import type {AnySchema, SchemaMap} from "../types"

export function usePattern(gen: CodeGen, pattern: string): Name {
export function usePattern({gen, it: {opts}}: KeywordCxt, pattern: string): Name {
const u = opts.unicodeRegExp ? "u" : ""
return gen.scopeValue("pattern", {
key: pattern,
ref: new RegExp(pattern, "u"),
code: _`new RegExp(${pattern}, "u")`,
ref: new RegExp(pattern, u),
code: _`new RegExp(${pattern}, ${u})`,
})

@@ -100,0 +101,0 @@ }

@@ -20,4 +20,6 @@ import type {CodeKeywordDefinition, ErrorObject, KeywordErrorDefinition} from "../../types"

code(cxt: KeywordCxt) {
const {gen, data, $data, schema, schemaCode} = cxt
const regExp = $data ? _`(new RegExp(${schemaCode}, "u"))` : usePattern(gen, schema) // TODO regexp should be wrapped in try/catch
const {data, $data, schema, schemaCode, it} = cxt
// TODO regexp should be wrapped in try/catchs
const u = it.opts.unicodeRegExp ? "u" : ""
const regExp = $data ? _`(new RegExp(${schemaCode}, ${u}))` : usePattern(cxt, schema)
cxt.fail$data(_`!${regExp}.test(${data})`)

@@ -24,0 +26,0 @@ },

{
"name": "ajv",
"version": "8.0.5",
"version": "8.1.0",
"description": "Another JSON Schema Validator",

@@ -5,0 +5,0 @@ "main": "dist/ajv.js",

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

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc