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 7.0.0-beta.9 to 7.0.0-rc.0

7

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, ScopeValueSets } from "./scope";
export { Scope, ScopeStore, ValueScope, ScopeValueSets, varKinds } from "./scope";
export declare type SafeExpr = Code | number | boolean | null;

@@ -20,7 +20,2 @@ export declare type Block = Code | (() => void);

};
export declare const varKinds: {
const: Name;
let: Name;
var: Name;
};
export interface CodeGenOptions {

@@ -27,0 +22,0 @@ es5?: boolean;

24

dist/compile/codegen/index.js
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.or = exports.and = exports.not = exports.CodeGen = exports.varKinds = exports.operators = exports.ValueScope = exports.Scope = exports.Name = exports.stringify = exports.getProperty = exports.nil = exports.strConcat = exports.str = exports._ = void 0;
exports.or = exports.and = exports.not = exports.CodeGen = exports.operators = exports.varKinds = exports.ValueScope = exports.Scope = exports.Name = exports.stringify = exports.getProperty = exports.nil = exports.strConcat = exports.str = exports._ = void 0;
const code_1 = require("./code");

@@ -17,2 +17,3 @@ const scope_1 = require("./scope");

Object.defineProperty(exports, "ValueScope", { enumerable: true, get: function () { return scope_2.ValueScope; } });
Object.defineProperty(exports, "varKinds", { enumerable: true, get: function () { return scope_2.varKinds; } });
exports.operators = {

@@ -29,7 +30,2 @@ GT: new code_1._Code(">"),

};
exports.varKinds = {
const: new code_1.Name("const"),
let: new code_1.Name("let"),
var: new code_1.Name("var"),
};
class Node {

@@ -51,3 +47,3 @@ optimizeNodes() {

render({ es5, _n }) {
const varKind = es5 ? exports.varKinds.var : this.varKind;
const varKind = es5 ? scope_1.varKinds.var : this.varKind;
const rhs = this.rhs === undefined ? "" : ` = ${this.rhs}`;

@@ -268,3 +264,3 @@ return `${varKind} ${this.name}${rhs};` + _n;

render(opts) {
const varKind = opts.es5 ? exports.varKinds.var : this.varKind;
const varKind = opts.es5 ? scope_1.varKinds.var : this.varKind;
const { name, from, to } = this;

@@ -414,11 +410,11 @@ return `for(${varKind} ${name}=${from}; ${name}<${to}; ${name}++)` + super.render(opts);

const(nameOrPrefix, rhs, _constant) {
return this._def(exports.varKinds.const, nameOrPrefix, rhs, _constant);
return this._def(scope_1.varKinds.const, nameOrPrefix, rhs, _constant);
}
// `let` declaration with optional assignment (`var` in es5 mode)
let(nameOrPrefix, rhs, _constant) {
return this._def(exports.varKinds.let, nameOrPrefix, rhs, _constant);
return this._def(scope_1.varKinds.let, nameOrPrefix, rhs, _constant);
}
// `var` declaration with optional assignment
var(nameOrPrefix, rhs, _constant) {
return this._def(exports.varKinds.var, nameOrPrefix, rhs, _constant);
return this._def(scope_1.varKinds.var, nameOrPrefix, rhs, _constant);
}

@@ -489,3 +485,3 @@ // assignment code

// `for` statement for a range of values
forRange(nameOrPrefix, from, to, forBody, varKind = exports.varKinds.let) {
forRange(nameOrPrefix, from, to, forBody, varKind = this.opts.es5 ? scope_1.varKinds.var : scope_1.varKinds.let) {
const name = this._scope.toName(nameOrPrefix);

@@ -495,3 +491,3 @@ return this._for(new ForRange(varKind, name, from, to), () => forBody(name));

// `for-of` statement (in es5 mode replace with a normal for loop)
forOf(nameOrPrefix, iterable, forBody, varKind = exports.varKinds.const) {
forOf(nameOrPrefix, iterable, forBody, varKind = scope_1.varKinds.const) {
const name = this._scope.toName(nameOrPrefix);

@@ -509,3 +505,3 @@ if (this.opts.es5) {

// With option `ownProperties` replaced with a `for-of` loop for object keys
forIn(nameOrPrefix, obj, forBody, varKind = exports.varKinds.const) {
forIn(nameOrPrefix, obj, forBody, varKind = this.opts.es5 ? scope_1.varKinds.var : scope_1.varKinds.const) {
if (this.opts.ownProperties) {

@@ -512,0 +508,0 @@ return this.forOf(nameOrPrefix, code_1._ `Object.keys(${obj})`, forBody);

@@ -18,2 +18,4 @@ import { Code, Name } from "./code";

scope: ScopeStore;
es5?: boolean;
lines?: boolean;
}

@@ -27,2 +29,7 @@ export declare type ScopeStore = Record<string, ValueReference[] | undefined>;

};
export declare const varKinds: {
const: Name;
let: Name;
var: Name;
};
export declare class Scope {

@@ -51,5 +58,9 @@ protected readonly _names: {

}
interface VSOptions extends ValueScopeOptions {
_n: Code;
}
export declare class ValueScope extends Scope {
protected readonly _values: ScopeValues;
protected readonly _scope: ScopeStore;
readonly opts: VSOptions;
constructor(opts: ValueScopeOptions);

@@ -56,0 +67,0 @@ get(): ScopeStore;

"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.ValueScope = exports.ValueScopeName = exports.Scope = void 0;
exports.ValueScope = exports.ValueScopeName = exports.Scope = exports.varKinds = void 0;
const code_1 = require("./code");

@@ -11,2 +11,7 @@ class ValueError extends Error {

}
exports.varKinds = {
const: new code_1.Name("const"),
let: new code_1.Name("let"),
var: new code_1.Name("var"),
};
class Scope {

@@ -48,2 +53,3 @@ constructor({ prefixes, parent } = {}) {

exports.ValueScopeName = ValueScopeName;
const line = code_1._ `\n`;
class ValueScope extends Scope {

@@ -54,2 +60,3 @@ constructor(opts) {

this._scope = opts.scope;
this.opts = { ...opts, _n: opts.lines ? line : code_1.nil };
}

@@ -118,6 +125,7 @@ get() {

if (c) {
code = code_1._ `${code}const ${name} = ${c};`;
const def = this.opts.es5 ? exports.varKinds.var : exports.varKinds.const;
code = code_1._ `${code}${def} ${name} = ${c};${this.opts._n}`;
}
else if ((c = getCode === null || getCode === void 0 ? void 0 : getCode(name))) {
code = code_1._ `${code}${c}`;
code = code_1._ `${code}${c}${this.opts._n}`;
}

@@ -124,0 +132,0 @@ else {

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

ownProperties?: boolean;
multipleOfPrecision?: boolean | number;
multipleOfPrecision?: number;
messages?: boolean;

@@ -58,0 +58,0 @@ code?: CodeOptions;

@@ -81,4 +81,2 @@ "use strict";

constructor(opts = {}) {
// shared external scope values for compiled functions
this.scope = new codegen_2.ValueScope({ scope: {}, prefixes: EXT_SCOPE_NAMES });
this.schemas = {};

@@ -90,6 +88,5 @@ this.refs = {};

this._cache = new Map();
opts = this.opts = {
...opts,
...requiredOptions(opts),
};
opts = this.opts = { ...opts, ...requiredOptions(opts) };
const { es5, lines } = this.opts.code;
this.scope = new codegen_2.ValueScope({ scope: {}, prefixes: EXT_SCOPE_NAMES, es5, lines });
this.logger = getLogger(opts.logger);

@@ -96,0 +93,0 @@ const formatOpt = opts.validateFormats;

"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
const scope_1 = require("../compile/codegen/scope");
const code_1 = require("../compile/codegen/code");

@@ -8,2 +9,3 @@ function standaloneCode(ajv, refsOrFunc) {

}
const { _n } = ajv.scope.opts;
return typeof refsOrFunc == "function"

@@ -24,3 +26,3 @@ ? funcExportCode(refsOrFunc.source)

const vCode = validateCode(usedValues, source);
return `"use strict";module.exports = ${n};module.exports.default = ${n};${vCode}`;
return `"use strict";${_n}module.exports = ${n};${_n}module.exports.default = ${n};${_n}${vCode}`;
}

@@ -35,3 +37,3 @@ function multiExportsCode(schemas, getValidateFunc) {

const vCode = validateCode(usedValues, v.source);
code = code_1._ `${code}exports${code_1.getProperty(name)} = ${(_a = v.source) === null || _a === void 0 ? void 0 : _a.validateName};${vCode}`;
code = code_1._ `${code}${_n}exports${code_1.getProperty(name)} = ${(_a = v.source) === null || _a === void 0 ? void 0 : _a.validateName};${_n}${vCode}`;
}

@@ -45,4 +47,4 @@ }

const scopeCode = ajv.scope.scopeCode(s.scopeValues, usedValues, refValidateCode);
const code = new code_1._Code(`${scopeCode}${s.validateCode}`);
return s.evaluated ? code_1._ `${code}${s.validateName}.evaluated = ${s.evaluated};` : code;
const code = new code_1._Code(`${scopeCode}${_n}${s.validateCode}`);
return s.evaluated ? code_1._ `${code}${s.validateName}.evaluated = ${s.evaluated};${_n}` : code;
function refValidateCode(n) {

@@ -58,3 +60,4 @@ var _a;

const vCode = validateCode(usedValues, validate === null || validate === void 0 ? void 0 : validate.source);
return code_1._ `const ${n} = {validate: ${validateName}};${vCode}`;
const def = ajv.opts.code.es5 ? scope_1.varKinds.var : scope_1.varKinds.const;
return code_1._ `${def} ${n} = {validate: ${validateName}};${_n}${vCode}`;
}

@@ -61,0 +64,0 @@ return undefined;

@@ -282,3 +282,3 @@ # API Reference

ownProperties: false,
multipleOfPrecision: false,
multipleOfPrecision: undefined,
messages: true,

@@ -285,0 +285,0 @@ code: {

import type {ScopeValueSets, NameValue, ValueScope, ValueScopeName} from "./scope"
import {_, nil, _Code, Code, Name, UsedNames, CodeItem, addCodeArg, _CodeOrName} from "./code"
import {Scope} from "./scope"
import {Scope, varKinds} from "./scope"
export {_, str, strConcat, nil, getProperty, stringify, Name, Code} from "./code"
export {Scope, ScopeStore, ValueScope, ScopeValueSets} from "./scope"
export {Scope, ScopeStore, ValueScope, ScopeValueSets, varKinds} from "./scope"

@@ -26,8 +26,2 @@ // type for expressions that can be safely inserted in code without quotes

export const varKinds = {
const: new Name("const"),
let: new Name("let"),
var: new Name("var"),
}
abstract class Node {

@@ -586,3 +580,3 @@ abstract readonly names: UsedNames

forBody: (index: Name) => void,
varKind: Code = varKinds.let
varKind: Code = this.opts.es5 ? varKinds.var : varKinds.let
): CodeGen {

@@ -617,3 +611,3 @@ const name = this._scope.toName(nameOrPrefix)

forBody: (item: Name) => void,
varKind: Code = varKinds.const
varKind: Code = this.opts.es5 ? varKinds.var : varKinds.const
): CodeGen {

@@ -620,0 +614,0 @@ if (this.opts.ownProperties) {

@@ -31,2 +31,4 @@ import {_, nil, Code, Name} from "./code"

scope: ScopeStore
es5?: boolean
lines?: boolean
}

@@ -44,2 +46,8 @@

export const varKinds = {
const: new Name("const"),
let: new Name("let"),
var: new Name("var"),
}
export class Scope {

@@ -97,5 +105,12 @@ protected readonly _names: {[Prefix in string]?: NameGroup} = {}

interface VSOptions extends ValueScopeOptions {
_n: Code
}
const line = _`\n`
export class ValueScope extends Scope {
protected readonly _values: ScopeValues = {}
protected readonly _scope: ScopeStore
readonly opts: VSOptions

@@ -105,2 +120,3 @@ constructor(opts: ValueScopeOptions) {

this._scope = opts.scope
this.opts = {...opts, _n: opts.lines ? line : nil}
}

@@ -182,5 +198,6 @@

if (c) {
code = _`${code}const ${name} = ${c};`
const def = this.opts.es5 ? varKinds.var : varKinds.const
code = _`${code}${def} ${name} = ${c};${this.opts._n}`
} else if ((c = getCode?.(name))) {
code = _`${code}${c}`
code = _`${code}${c}${this.opts._n}`
} else {

@@ -187,0 +204,0 @@ throw new ValueError(name)

@@ -116,3 +116,3 @@ export {

ownProperties?: boolean
multipleOfPrecision?: boolean | number
multipleOfPrecision?: number
messages?: boolean

@@ -241,3 +241,3 @@ code?: CodeOptions // NEW

// shared external scope values for compiled functions
readonly scope = new ValueScope({scope: {}, prefixes: EXT_SCOPE_NAMES})
readonly scope: ValueScope
readonly schemas: {[Key in string]?: SchemaEnv} = {}

@@ -256,6 +256,5 @@ readonly refs: {[Ref in string]?: SchemaEnv | string} = {}

constructor(opts: Options = {}) {
opts = this.opts = {
...opts,
...requiredOptions(opts),
}
opts = this.opts = {...opts, ...requiredOptions(opts)}
const {es5, lines} = this.opts.code
this.scope = new ValueScope({scope: {}, prefixes: EXT_SCOPE_NAMES, es5, lines})
this.logger = getLogger(opts.logger)

@@ -262,0 +261,0 @@ const formatOpt = opts.validateFormats

import type AjvCore from "../core"
import type {AnyValidateFunction, SourceCode} from "../types"
import type {ScopeValueSets, ValueScopeName} from "../compile/codegen/scope"
import {ScopeValueSets, ValueScopeName, varKinds} from "../compile/codegen/scope"
import {_, _Code, Code, getProperty} from "../compile/codegen/code"

@@ -14,2 +14,3 @@ import {SchemaEnv} from "../compile"

}
const {_n} = ajv.scope.opts
return typeof refsOrFunc == "function"

@@ -33,3 +34,3 @@ ? funcExportCode(refsOrFunc.source)

const vCode = validateCode(usedValues, source)
return `"use strict";module.exports = ${n};module.exports.default = ${n};${vCode}`
return `"use strict";${_n}module.exports = ${n};${_n}module.exports.default = ${n};${_n}${vCode}`
}

@@ -47,3 +48,3 @@

const vCode = validateCode(usedValues, v.source)
code = _`${code}exports${getProperty(name)} = ${v.source?.validateName};${vCode}`
code = _`${code}${_n}exports${getProperty(name)} = ${v.source?.validateName};${_n}${vCode}`
}

@@ -57,4 +58,4 @@ }

const scopeCode = ajv.scope.scopeCode(s.scopeValues, usedValues, refValidateCode)
const code = new _Code(`${scopeCode}${s.validateCode}`)
return s.evaluated ? _`${code}${s.validateName}.evaluated = ${s.evaluated};` : code
const code = new _Code(`${scopeCode}${_n}${s.validateCode}`)
return s.evaluated ? _`${code}${s.validateName}.evaluated = ${s.evaluated};${_n}` : code

@@ -69,3 +70,4 @@ function refValidateCode(n: ValueScopeName): Code | undefined {

const vCode = validateCode(usedValues, validate?.source)
return _`const ${n} = {validate: ${validateName}};${vCode}`
const def = ajv.opts.code.es5 ? varKinds.var : varKinds.const
return _`${def} ${n} = {validate: ${validateName}};${_n}${vCode}`
}

@@ -72,0 +74,0 @@ return undefined

{
"name": "ajv",
"version": "7.0.0-beta.9",
"version": "7.0.0-rc.0",
"description": "Another JSON Schema Validator",

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

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

[![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.9)
[![npm (beta)](https://img.shields.io/npm/v/ajv/beta)](https://www.npmjs.com/package/ajv/v/7.0.0-rc.0)
[![npm downloads](https://img.shields.io/npm/dm/ajv.svg)](https://www.npmjs.com/package/ajv)

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

// optional schema type annotation for schema to match MyData type
// Optional schema type annotation for schema to match MyData type.
// To use JSONSchemaType set `strictNullChecks: true` in tsconfig `compilerOptions`.
const schema: JSONSchemaType<MyData> = {

@@ -211,0 +212,0 @@ type: "object",

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