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.3.0 to 8.4.0

10

dist/compile/jtd/parse.js

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

function parseType(cxt) {
const { gen, schema, data } = cxt;
const { gen, schema, data, self } = cxt;
switch (schema.type) {

@@ -233,6 +233,10 @@ case "boolean":

case "timestamp": {
// TODO parse timestamp?
parseString(cxt);
const vts = util_1.useFunc(gen, timestamp_1.default);
gen.if(codegen_1._ `!${vts}(${data})`, () => parsingError(cxt, codegen_1.str `invalid timestamp`));
const { allowDate, parseDate } = self.opts;
const notValid = allowDate ? codegen_1._ `!${vts}(${data}, true)` : codegen_1._ `!${vts}(${data})`;
const fail = parseDate
? codegen_1.or(notValid, codegen_1._ `(${data} = new Date(${data}), false)`, codegen_1._ `isNaN(${data}.valueOf())`)
: notValid;
gen.if(fail, () => parsingError(cxt, codegen_1.str `invalid timestamp`));
break;

@@ -239,0 +243,0 @@ }

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

unicodeRegExp?: boolean;
timestamp?: "string" | "date";
parseDate?: boolean;
allowDate?: boolean;
$comment?: true | ((comment: string, schemaPath?: string, rootSchema?: AnySchemaObject) => unknown);

@@ -55,4 +58,2 @@ formats?: {

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

@@ -59,0 +60,0 @@ defaultMeta?: string | AnySchemaObject;

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

serialize: "Map is used as cache, schema object as key.",
ajvErrors: "It is default now, see option `strict`.",
ajvErrors: "It is default now.",
};

@@ -57,0 +57,0 @@ const deprecatedOptions = {

"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
const rxEscapable =
// eslint-disable-next-line no-control-regex, no-misleading-character-class
const rxEscapable = /[\\"\u0000-\u001f\u007f-\u009f\u00ad\u0600-\u0604\u070f\u17b4\u17b5\u200c-\u200f\u2028-\u202f\u2060-\u206f\ufeff\ufff0-\uffff]/g;
/[\\"\u0000-\u001f\u007f-\u009f\u00ad\u0600-\u0604\u070f\u17b4\u17b5\u200c-\u200f\u2028-\u202f\u2060-\u206f\ufeff\ufff0-\uffff]/g;
const escaped = {

@@ -6,0 +7,0 @@ "\b": "\\b",

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

declare function validTimestamp(str: string): boolean;
declare function validTimestamp(str: string, allowDate: boolean): boolean;
declare namespace validTimestamp {

@@ -3,0 +3,0 @@ var code: string;

"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
const DATE_TIME = /^(\d\d\d\d)-(\d\d)-(\d\d)(?:t|\s)(\d\d):(\d\d):(\d\d)(?:\.\d+)?(?:z|([+-]\d\d)(?::?(\d\d))?)$/i;
const DT_SEPARATOR = /t|\s/i;
const DATE = /^(\d\d\d\d)-(\d\d)-(\d\d)$/;
const TIME = /^(\d\d):(\d\d):(\d\d)(?:\.\d+)?(?:z|([+-]\d\d)(?::?(\d\d))?)$/i;
const DAYS = [0, 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31];
function validTimestamp(str) {
function validTimestamp(str, allowDate) {
// http://tools.ietf.org/html/rfc3339#section-5.6
const matches = DATE_TIME.exec(str);
const dt = str.split(DT_SEPARATOR);
return ((dt.length === 2 && validDate(dt[0]) && validTime(dt[1])) ||
(allowDate && dt.length === 1 && validDate(dt[0])));
}
exports.default = validTimestamp;
function validDate(str) {
const matches = DATE.exec(str);
if (!matches)

@@ -13,7 +21,2 @@ return false;

const d = +matches[3];
const hr = +matches[4];
const min = +matches[5];
const sec = +matches[6];
const tzH = +(matches[7] || 0);
const tzM = +(matches[8] || 0);
return (m >= 1 &&

@@ -24,9 +27,18 @@ m <= 12 &&

// leap year: https://tools.ietf.org/html/rfc3339#appendix-C
(m === 2 && d === 29 && (y % 100 === 0 ? y % 400 === 0 : y % 4 === 0))) &&
((hr <= 23 && min <= 59 && sec <= 59) ||
// leap second
(hr - tzH === 23 && min - tzM === 59 && sec === 60)));
(m === 2 && d === 29 && (y % 100 === 0 ? y % 400 === 0 : y % 4 === 0))));
}
exports.default = validTimestamp;
function validTime(str) {
const matches = TIME.exec(str);
if (!matches)
return false;
const hr = +matches[1];
const min = +matches[2];
const sec = +matches[3];
const tzH = +(matches[4] || 0);
const tzM = +(matches[5] || 0);
return ((hr <= 23 && min <= 59 && sec <= 59) ||
// leap second
(hr - tzH === 23 && min - tzM === 59 && sec === 60));
}
validTimestamp.code = 'require("ajv/dist/runtime/timestamp").default';
//# sourceMappingURL=timestamp.js.map

@@ -22,15 +22,10 @@ "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 { gen, data, it } = cxt;
const { timestamp, allowDate } = it.opts;
if (timestamp === "date")
return codegen_1._ `${data} instanceof Date `;
const vts = util_1.useFunc(gen, timestamp_1.default);
const allowDateArg = allowDate ? codegen_1._ `, true` : codegen_1.nil;
const validString = codegen_1._ `typeof ${data} == "string" && ${vts}(${data}${allowDateArg})`;
return timestamp === "string" ? validString : codegen_1.or(codegen_1._ `${data} instanceof Date`, validString);
}

@@ -37,0 +32,0 @@ const def = {

@@ -5,3 +5,3 @@ import type Ajv from "../../core"

import {SchemaEnv, getCompilingSchema} from ".."
import {_, str, and, nil, not, CodeGen, Code, Name, SafeExpr} from "../codegen"
import {_, str, and, or, nil, not, CodeGen, Code, Name, SafeExpr} from "../codegen"
import MissingRefError from "../ref_error"

@@ -257,3 +257,3 @@ import N from "../names"

function parseType(cxt: ParseCxt): void {
const {gen, schema, data} = cxt
const {gen, schema, data, self} = cxt
switch (schema.type) {

@@ -267,6 +267,10 @@ case "boolean":

case "timestamp": {
// TODO parse timestamp?
parseString(cxt)
const vts = useFunc(gen, validTimestamp)
gen.if(_`!${vts}(${data})`, () => parsingError(cxt, str`invalid timestamp`))
const {allowDate, parseDate} = self.opts
const notValid = allowDate ? _`!${vts}(${data}, true)` : _`!${vts}(${data})`
const fail: Code = parseDate
? or(notValid, _`(${data} = new Date(${data}), false)`, _`isNaN(${data}.valueOf())`)
: notValid
gen.if(fail, () => parsingError(cxt, str`invalid timestamp`))
break

@@ -273,0 +277,0 @@ }

@@ -101,2 +101,5 @@ export {

unicodeRegExp?: boolean
timestamp?: "string" | "date" // JTD only
parseDate?: boolean // JTD only
allowDate?: boolean // JTD only
$comment?:

@@ -119,4 +122,2 @@ | true

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

@@ -197,3 +198,3 @@ defaultMeta?: string | AnySchemaObject

serialize: "Map is used as cache, schema object as key.",
ajvErrors: "It is default now, see option `strict`.",
ajvErrors: "It is default now.",
}

@@ -200,0 +201,0 @@

@@ -1,3 +0,4 @@

// eslint-disable-next-line no-control-regex, no-misleading-character-class
const rxEscapable = /[\\"\u0000-\u001f\u007f-\u009f\u00ad\u0600-\u0604\u070f\u17b4\u17b5\u200c-\u200f\u2028-\u202f\u2060-\u206f\ufeff\ufff0-\uffff]/g
const rxEscapable =
// eslint-disable-next-line no-control-regex, no-misleading-character-class
/[\\"\u0000-\u001f\u007f-\u009f\u00ad\u0600-\u0604\u070f\u17b4\u17b5\u200c-\u200f\u2028-\u202f\u2060-\u206f\ufeff\ufff0-\uffff]/g

@@ -4,0 +5,0 @@ const escaped: {[K in string]?: string} = {

@@ -1,7 +0,17 @@

const DATE_TIME = /^(\d\d\d\d)-(\d\d)-(\d\d)(?:t|\s)(\d\d):(\d\d):(\d\d)(?:\.\d+)?(?:z|([+-]\d\d)(?::?(\d\d))?)$/i
const DT_SEPARATOR = /t|\s/i
const DATE = /^(\d\d\d\d)-(\d\d)-(\d\d)$/
const TIME = /^(\d\d):(\d\d):(\d\d)(?:\.\d+)?(?:z|([+-]\d\d)(?::?(\d\d))?)$/i
const DAYS = [0, 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31]
export default function validTimestamp(str: string): boolean {
export default function validTimestamp(str: string, allowDate: boolean): boolean {
// http://tools.ietf.org/html/rfc3339#section-5.6
const matches: string[] | null = DATE_TIME.exec(str)
const dt: string[] = str.split(DT_SEPARATOR)
return (
(dt.length === 2 && validDate(dt[0]) && validTime(dt[1])) ||
(allowDate && dt.length === 1 && validDate(dt[0]))
)
}
function validDate(str: string): boolean {
const matches: string[] | null = DATE.exec(str)
if (!matches) return false

@@ -11,7 +21,2 @@ const y: number = +matches[1]

const d: number = +matches[3]
const hr: number = +matches[4]
const min: number = +matches[5]
const sec: number = +matches[6]
const tzH: number = +(matches[7] || 0)
const tzM: number = +(matches[8] || 0)
return (

@@ -23,9 +28,21 @@ m >= 1 &&

// leap year: https://tools.ietf.org/html/rfc3339#appendix-C
(m === 2 && d === 29 && (y % 100 === 0 ? y % 400 === 0 : y % 4 === 0))) &&
((hr <= 23 && min <= 59 && sec <= 59) ||
// leap second
(hr - tzH === 23 && min - tzM === 59 && sec === 60))
(m === 2 && d === 29 && (y % 100 === 0 ? y % 400 === 0 : y % 4 === 0)))
)
}
function validTime(str: string): boolean {
const matches: string[] | null = TIME.exec(str)
if (!matches) return false
const hr: number = +matches[1]
const min: number = +matches[2]
const sec: number = +matches[3]
const tzH: number = +(matches[4] || 0)
const tzM: number = +(matches[5] || 0)
return (
(hr <= 23 && min <= 59 && sec <= 59) ||
// leap second
(hr - tzH === 23 && min - tzM === 59 && sec === 60)
)
}
validTimestamp.code = 'require("ajv/dist/runtime/timestamp").default'
import type {CodeKeywordDefinition, KeywordErrorDefinition} from "../../types"
import type {KeywordCxt} from "../../compile/validate"
import {_, or, Code} from "../../compile/codegen"
import {_, nil, or, Code} from "../../compile/codegen"
import validTimestamp from "../../runtime/timestamp"

@@ -8,3 +8,2 @@ import {useFunc} from "../../compile/util"

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

@@ -31,16 +30,10 @@ 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}))`
}
}
function timestampCode(cxt: KeywordCxt): Code {
const {gen, data, it} = cxt
const {timestamp, allowDate} = it.opts
if (timestamp === "date") return _`${data} instanceof Date `
const vts = useFunc(gen, validTimestamp)
const allowDateArg = allowDate ? _`, true` : nil
const validString = _`typeof ${data} == "string" && ${vts}(${data}${allowDateArg})`
return timestamp === "string" ? validString : or(_`${data} instanceof Date`, validString)
}

@@ -47,0 +40,0 @@

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

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

"json-schema-test": "^2.0.0",
"karma": "^5.0.0",
"karma": "^6.0.0",
"karma-chrome-launcher": "^3.0.0",

@@ -94,0 +94,0 @@ "karma-mocha": "^2.0.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

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