This commit is contained in:
lalBi94
2023-03-05 13:23:23 +01:00
commit 7bc56c09b5
14034 changed files with 1834369 additions and 0 deletions

View File

@@ -0,0 +1,21 @@
The MIT License (MIT)
Copyright (c) 2016 Evgeny Poberezkin
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.

File diff suppressed because it is too large Load Diff

View File

@@ -0,0 +1,5 @@
import type { MacroKeywordDefinition } from "ajv";
import type { GetDefinition } from "./_types";
declare type RangeKwd = "range" | "exclusiveRange";
export default function getRangeDef(keyword: RangeKwd): GetDefinition<MacroKeywordDefinition>;
export {};

View File

@@ -0,0 +1,28 @@
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
function getRangeDef(keyword) {
return () => ({
keyword,
type: "number",
schemaType: "array",
macro: function ([min, max]) {
validateRangeSchema(min, max);
return keyword === "range"
? { minimum: min, maximum: max }
: { exclusiveMinimum: min, exclusiveMaximum: max };
},
metaSchema: {
type: "array",
minItems: 2,
maxItems: 2,
items: { type: "number" },
},
});
function validateRangeSchema(min, max) {
if (min > max || (keyword === "exclusiveRange" && min === max)) {
throw new Error("There are no numbers in range");
}
}
}
exports.default = getRangeDef;
//# sourceMappingURL=_range.js.map

View File

@@ -0,0 +1 @@
{"version":3,"file":"_range.js","sourceRoot":"","sources":["../../src/definitions/_range.ts"],"names":[],"mappings":";;AAKA,SAAwB,WAAW,CAAC,OAAiB;IACnD,OAAO,GAAG,EAAE,CAAC,CAAC;QACZ,OAAO;QACP,IAAI,EAAE,QAAQ;QACd,UAAU,EAAE,OAAO;QACnB,KAAK,EAAE,UAAU,CAAC,GAAG,EAAE,GAAG,CAAmB;YAC3C,mBAAmB,CAAC,GAAG,EAAE,GAAG,CAAC,CAAA;YAC7B,OAAO,OAAO,KAAK,OAAO;gBACxB,CAAC,CAAC,EAAC,OAAO,EAAE,GAAG,EAAE,OAAO,EAAE,GAAG,EAAC;gBAC9B,CAAC,CAAC,EAAC,gBAAgB,EAAE,GAAG,EAAE,gBAAgB,EAAE,GAAG,EAAC,CAAA;QACpD,CAAC;QACD,UAAU,EAAE;YACV,IAAI,EAAE,OAAO;YACb,QAAQ,EAAE,CAAC;YACX,QAAQ,EAAE,CAAC;YACX,KAAK,EAAE,EAAC,IAAI,EAAE,QAAQ,EAAC;SACxB;KACF,CAAC,CAAA;IAEF,SAAS,mBAAmB,CAAC,GAAW,EAAE,GAAW;QACnD,IAAI,GAAG,GAAG,GAAG,IAAI,CAAC,OAAO,KAAK,gBAAgB,IAAI,GAAG,KAAK,GAAG,CAAC,EAAE;YAC9D,MAAM,IAAI,KAAK,CAAC,+BAA+B,CAAC,CAAA;SACjD;IACH,CAAC;AACH,CAAC;AAxBD,8BAwBC"}

View File

@@ -0,0 +1,5 @@
import type { MacroKeywordDefinition } from "ajv";
import type { GetDefinition } from "./_types";
declare type RequiredKwd = "anyRequired" | "oneRequired";
export default function getRequiredDef(keyword: RequiredKwd): GetDefinition<MacroKeywordDefinition>;
export {};

View File

@@ -0,0 +1,23 @@
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
function getRequiredDef(keyword) {
return () => ({
keyword,
type: "object",
schemaType: "array",
macro(schema) {
if (schema.length === 0)
return true;
if (schema.length === 1)
return { required: schema };
const comb = keyword === "anyRequired" ? "anyOf" : "oneOf";
return { [comb]: schema.map((p) => ({ required: [p] })) };
},
metaSchema: {
type: "array",
items: { type: "string" },
},
});
}
exports.default = getRequiredDef;
//# sourceMappingURL=_required.js.map

View File

@@ -0,0 +1 @@
{"version":3,"file":"_required.js","sourceRoot":"","sources":["../../src/definitions/_required.ts"],"names":[],"mappings":";;AAKA,SAAwB,cAAc,CACpC,OAAoB;IAEpB,OAAO,GAAG,EAAE,CAAC,CAAC;QACZ,OAAO;QACP,IAAI,EAAE,QAAQ;QACd,UAAU,EAAE,OAAO;QACnB,KAAK,CAAC,MAAgB;YACpB,IAAI,MAAM,CAAC,MAAM,KAAK,CAAC;gBAAE,OAAO,IAAI,CAAA;YACpC,IAAI,MAAM,CAAC,MAAM,KAAK,CAAC;gBAAE,OAAO,EAAC,QAAQ,EAAE,MAAM,EAAC,CAAA;YAClD,MAAM,IAAI,GAAG,OAAO,KAAK,aAAa,CAAC,CAAC,CAAC,OAAO,CAAC,CAAC,CAAC,OAAO,CAAA;YAC1D,OAAO,EAAC,CAAC,IAAI,CAAC,EAAE,MAAM,CAAC,GAAG,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,EAAC,QAAQ,EAAE,CAAC,CAAC,CAAC,EAAC,CAAC,CAAC,EAAC,CAAA;QACvD,CAAC;QACD,UAAU,EAAE;YACV,IAAI,EAAE,OAAO;YACb,KAAK,EAAE,EAAC,IAAI,EAAE,QAAQ,EAAC;SACxB;KACF,CAAC,CAAA;AACJ,CAAC;AAlBD,iCAkBC"}

View File

@@ -0,0 +1,5 @@
import type { KeywordDefinition } from "ajv";
export interface DefinitionOptions {
defaultMeta?: string | boolean;
}
export declare type GetDefinition<T extends KeywordDefinition> = (opts?: DefinitionOptions) => T;

View File

@@ -0,0 +1,3 @@
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
//# sourceMappingURL=_types.js.map

View File

@@ -0,0 +1 @@
{"version":3,"file":"_types.js","sourceRoot":"","sources":["../../src/definitions/_types.ts"],"names":[],"mappings":""}

View File

@@ -0,0 +1,4 @@
import type { DefinitionOptions } from "./_types";
import type { SchemaObject, KeywordCxt, Name } from "ajv";
export declare function metaSchemaRef({ defaultMeta }?: DefinitionOptions): SchemaObject;
export declare function usePattern({ gen, it: { opts } }: KeywordCxt, pattern: string, flags?: string): Name;

View File

@@ -0,0 +1,19 @@
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.usePattern = exports.metaSchemaRef = void 0;
const codegen_1 = require("ajv/dist/compile/codegen");
const META_SCHEMA_ID = "http://json-schema.org/schema";
function metaSchemaRef({ defaultMeta } = {}) {
return defaultMeta === false ? {} : { $ref: defaultMeta || META_SCHEMA_ID };
}
exports.metaSchemaRef = metaSchemaRef;
function usePattern({ gen, it: { opts } }, pattern, flags = opts.unicodeRegExp ? "u" : "") {
const rx = new RegExp(pattern, flags);
return gen.scopeValue("pattern", {
key: rx.toString(),
ref: rx,
code: (0, codegen_1._) `new RegExp(${pattern}, ${flags})`,
});
}
exports.usePattern = usePattern;
//# sourceMappingURL=_util.js.map

View File

@@ -0,0 +1 @@
{"version":3,"file":"_util.js","sourceRoot":"","sources":["../../src/definitions/_util.ts"],"names":[],"mappings":";;;AAEA,sDAA0C;AAE1C,MAAM,cAAc,GAAG,+BAA+B,CAAA;AAEtD,SAAgB,aAAa,CAAC,EAAC,WAAW,KAAuB,EAAE;IACjE,OAAO,WAAW,KAAK,KAAK,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,EAAC,IAAI,EAAE,WAAW,IAAI,cAAc,EAAC,CAAA;AAC3E,CAAC;AAFD,sCAEC;AAED,SAAgB,UAAU,CACxB,EAAC,GAAG,EAAE,EAAE,EAAE,EAAC,IAAI,EAAC,EAAa,EAC7B,OAAe,EACf,KAAK,GAAG,IAAI,CAAC,aAAa,CAAC,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC,EAAE;IAErC,MAAM,EAAE,GAAG,IAAI,MAAM,CAAC,OAAO,EAAE,KAAK,CAAC,CAAA;IACrC,OAAO,GAAG,CAAC,UAAU,CAAC,SAAS,EAAE;QAC/B,GAAG,EAAE,EAAE,CAAC,QAAQ,EAAE;QAClB,GAAG,EAAE,EAAE;QACP,IAAI,EAAE,IAAA,WAAC,EAAA,cAAc,OAAO,KAAK,KAAK,GAAG;KAC1C,CAAC,CAAA;AACJ,CAAC;AAXD,gCAWC"}

View File

@@ -0,0 +1,2 @@
import type { MacroKeywordDefinition } from "ajv";
export default function getDef(): MacroKeywordDefinition;

View File

@@ -0,0 +1,21 @@
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
function getDef() {
return {
keyword: "allRequired",
type: "object",
schemaType: "boolean",
macro(schema, parentSchema) {
if (!schema)
return true;
const required = Object.keys(parentSchema.properties);
if (required.length === 0)
return true;
return { required };
},
dependencies: ["properties"],
};
}
exports.default = getDef;
module.exports = getDef;
//# sourceMappingURL=allRequired.js.map

View File

@@ -0,0 +1 @@
{"version":3,"file":"allRequired.js","sourceRoot":"","sources":["../../src/definitions/allRequired.ts"],"names":[],"mappings":";;AAEA,SAAwB,MAAM;IAC5B,OAAO;QACL,OAAO,EAAE,aAAa;QACtB,IAAI,EAAE,QAAQ;QACd,UAAU,EAAE,SAAS;QACrB,KAAK,CAAC,MAAe,EAAE,YAAY;YACjC,IAAI,CAAC,MAAM;gBAAE,OAAO,IAAI,CAAA;YACxB,MAAM,QAAQ,GAAG,MAAM,CAAC,IAAI,CAAC,YAAY,CAAC,UAAU,CAAC,CAAA;YACrD,IAAI,QAAQ,CAAC,MAAM,KAAK,CAAC;gBAAE,OAAO,IAAI,CAAA;YACtC,OAAO,EAAC,QAAQ,EAAC,CAAA;QACnB,CAAC;QACD,YAAY,EAAE,CAAC,YAAY,CAAC;KAC7B,CAAA;AACH,CAAC;AAbD,yBAaC;AAED,MAAM,CAAC,OAAO,GAAG,MAAM,CAAA"}

View File

@@ -0,0 +1,4 @@
import type { MacroKeywordDefinition } from "ajv";
import type { GetDefinition } from "./_types";
declare const getDef: GetDefinition<MacroKeywordDefinition>;
export default getDef;

View File

@@ -0,0 +1,10 @@
"use strict";
var __importDefault = (this && this.__importDefault) || function (mod) {
return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
const _required_1 = __importDefault(require("./_required"));
const getDef = (0, _required_1.default)("anyRequired");
exports.default = getDef;
module.exports = getDef;
//# sourceMappingURL=anyRequired.js.map

View File

@@ -0,0 +1 @@
{"version":3,"file":"anyRequired.js","sourceRoot":"","sources":["../../src/definitions/anyRequired.ts"],"names":[],"mappings":";;;;;AAEA,4DAAwC;AAExC,MAAM,MAAM,GAA0C,IAAA,mBAAc,EAAC,aAAa,CAAC,CAAA;AAEnF,kBAAe,MAAM,CAAA;AACrB,MAAM,CAAC,OAAO,GAAG,MAAM,CAAA"}

View File

@@ -0,0 +1,3 @@
import type { MacroKeywordDefinition } from "ajv";
import type { DefinitionOptions } from "./_types";
export default function getDef(opts?: DefinitionOptions): MacroKeywordDefinition;

View File

@@ -0,0 +1,54 @@
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
const _util_1 = require("./_util");
function getDef(opts) {
return {
keyword: "deepProperties",
type: "object",
schemaType: "object",
macro: function (schema) {
const allOf = [];
for (const pointer in schema)
allOf.push(getSchema(pointer, schema[pointer]));
return { allOf };
},
metaSchema: {
type: "object",
propertyNames: { type: "string", format: "json-pointer" },
additionalProperties: (0, _util_1.metaSchemaRef)(opts),
},
};
}
exports.default = getDef;
function getSchema(jsonPointer, schema) {
const segments = jsonPointer.split("/");
const rootSchema = {};
let pointerSchema = rootSchema;
for (let i = 1; i < segments.length; i++) {
let segment = segments[i];
const isLast = i === segments.length - 1;
segment = unescapeJsonPointer(segment);
const properties = (pointerSchema.properties = {});
let items;
if (/[0-9]+/.test(segment)) {
let count = +segment;
items = pointerSchema.items = [];
pointerSchema.type = ["object", "array"];
while (count--)
items.push({});
}
else {
pointerSchema.type = "object";
}
pointerSchema = isLast ? schema : {};
properties[segment] = pointerSchema;
if (items)
items.push(pointerSchema);
}
return rootSchema;
}
function unescapeJsonPointer(str) {
return str.replace(/~1/g, "/").replace(/~0/g, "~");
}
module.exports = getDef;
//# sourceMappingURL=deepProperties.js.map

File diff suppressed because one or more lines are too long

View File

@@ -0,0 +1,2 @@
import type { CodeKeywordDefinition } from "ajv";
export default function getDef(): CodeKeywordDefinition;

View File

@@ -0,0 +1,33 @@
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
const codegen_1 = require("ajv/dist/compile/codegen");
function getDef() {
return {
keyword: "deepRequired",
type: "object",
schemaType: "array",
code(ctx) {
const { schema, data } = ctx;
const props = schema.map((jp) => (0, codegen_1._) `(${getData(jp)}) === undefined`);
ctx.fail((0, codegen_1.or)(...props));
function getData(jsonPointer) {
if (jsonPointer === "")
throw new Error("empty JSON pointer not allowed");
const segments = jsonPointer.split("/");
let x = data;
const xs = segments.map((s, i) => i ? (x = (0, codegen_1._) `${x}${(0, codegen_1.getProperty)(unescapeJPSegment(s))}`) : x);
return (0, codegen_1.and)(...xs);
}
},
metaSchema: {
type: "array",
items: { type: "string", format: "json-pointer" },
},
};
}
exports.default = getDef;
function unescapeJPSegment(s) {
return s.replace(/~1/g, "/").replace(/~0/g, "~");
}
module.exports = getDef;
//# sourceMappingURL=deepRequired.js.map

File diff suppressed because one or more lines are too long

View File

@@ -0,0 +1,7 @@
import type { FuncKeywordDefinition } from "ajv";
export declare type DynamicDefaultFunc = (args?: Record<string, any>) => () => any;
declare const DEFAULTS: Record<string, DynamicDefaultFunc | undefined>;
declare const getDef: (() => FuncKeywordDefinition) & {
DEFAULTS: typeof DEFAULTS;
};
export default getDef;

View File

@@ -0,0 +1,84 @@
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
const sequences = {};
const DEFAULTS = {
timestamp: () => () => Date.now(),
datetime: () => () => new Date().toISOString(),
date: () => () => new Date().toISOString().slice(0, 10),
time: () => () => new Date().toISOString().slice(11),
random: () => () => Math.random(),
randomint: (args) => {
var _a;
const max = (_a = args === null || args === void 0 ? void 0 : args.max) !== null && _a !== void 0 ? _a : 2;
return () => Math.floor(Math.random() * max);
},
seq: (args) => {
var _a;
const name = (_a = args === null || args === void 0 ? void 0 : args.name) !== null && _a !== void 0 ? _a : "";
sequences[name] || (sequences[name] = 0);
return () => sequences[name]++;
},
};
const getDef = Object.assign(_getDef, { DEFAULTS });
function _getDef() {
return {
keyword: "dynamicDefaults",
type: "object",
schemaType: ["string", "object"],
modifying: true,
valid: true,
compile(schema, _parentSchema, it) {
if (!it.opts.useDefaults || it.compositeRule)
return () => true;
const fs = {};
for (const key in schema)
fs[key] = getDefault(schema[key]);
const empty = it.opts.useDefaults === "empty";
return (data) => {
for (const prop in schema) {
if (data[prop] === undefined || (empty && (data[prop] === null || data[prop] === ""))) {
data[prop] = fs[prop]();
}
}
return true;
};
},
metaSchema: {
type: "object",
additionalProperties: {
anyOf: [
{ type: "string" },
{
type: "object",
additionalProperties: false,
required: ["func", "args"],
properties: {
func: { type: "string" },
args: { type: "object" },
},
},
],
},
},
};
}
function getDefault(d) {
return typeof d == "object" ? getObjDefault(d) : getStrDefault(d);
}
function getObjDefault({ func, args }) {
const def = DEFAULTS[func];
assertDefined(func, def);
return def(args);
}
function getStrDefault(d = "") {
const def = DEFAULTS[d];
assertDefined(d, def);
return def();
}
function assertDefined(name, def) {
if (!def)
throw new Error(`invalid "dynamicDefaults" keyword property value: ${name}`);
}
exports.default = getDef;
module.exports = getDef;
//# sourceMappingURL=dynamicDefaults.js.map

File diff suppressed because one or more lines are too long

View File

@@ -0,0 +1,4 @@
import type { MacroKeywordDefinition } from "ajv";
import type { GetDefinition } from "./_types";
declare const getDef: GetDefinition<MacroKeywordDefinition>;
export default getDef;

View File

@@ -0,0 +1,10 @@
"use strict";
var __importDefault = (this && this.__importDefault) || function (mod) {
return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
const _range_1 = __importDefault(require("./_range"));
const getDef = (0, _range_1.default)("exclusiveRange");
exports.default = getDef;
module.exports = getDef;
//# sourceMappingURL=exclusiveRange.js.map

View File

@@ -0,0 +1 @@
{"version":3,"file":"exclusiveRange.js","sourceRoot":"","sources":["../../src/definitions/exclusiveRange.ts"],"names":[],"mappings":";;;;;AAEA,sDAAkC;AAElC,MAAM,MAAM,GAA0C,IAAA,gBAAW,EAAC,gBAAgB,CAAC,CAAA;AAEnF,kBAAe,MAAM,CAAA;AACrB,MAAM,CAAC,OAAO,GAAG,MAAM,CAAA"}

View File

@@ -0,0 +1,6 @@
import type { Vocabulary, ErrorNoParams } from "ajv";
import type { DefinitionOptions } from "./_types";
import { PatternRequiredError } from "./patternRequired";
import { SelectError } from "./select";
export default function ajvKeywords(opts?: DefinitionOptions): Vocabulary;
export declare type AjvKeywordsError = PatternRequiredError | SelectError | ErrorNoParams<"range" | "exclusiveRange" | "anyRequired" | "oneRequired" | "allRequired" | "deepProperties" | "deepRequired" | "dynamicDefaults" | "instanceof" | "prohibited" | "regexp" | "transform" | "uniqueItemProperties">;

View File

@@ -0,0 +1,44 @@
"use strict";
var __importDefault = (this && this.__importDefault) || function (mod) {
return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
const typeof_1 = __importDefault(require("./typeof"));
const instanceof_1 = __importDefault(require("./instanceof"));
const range_1 = __importDefault(require("./range"));
const exclusiveRange_1 = __importDefault(require("./exclusiveRange"));
const regexp_1 = __importDefault(require("./regexp"));
const transform_1 = __importDefault(require("./transform"));
const uniqueItemProperties_1 = __importDefault(require("./uniqueItemProperties"));
const allRequired_1 = __importDefault(require("./allRequired"));
const anyRequired_1 = __importDefault(require("./anyRequired"));
const oneRequired_1 = __importDefault(require("./oneRequired"));
const patternRequired_1 = __importDefault(require("./patternRequired"));
const prohibited_1 = __importDefault(require("./prohibited"));
const deepProperties_1 = __importDefault(require("./deepProperties"));
const deepRequired_1 = __importDefault(require("./deepRequired"));
const dynamicDefaults_1 = __importDefault(require("./dynamicDefaults"));
const select_1 = __importDefault(require("./select"));
const definitions = [
typeof_1.default,
instanceof_1.default,
range_1.default,
exclusiveRange_1.default,
regexp_1.default,
transform_1.default,
uniqueItemProperties_1.default,
allRequired_1.default,
anyRequired_1.default,
oneRequired_1.default,
patternRequired_1.default,
prohibited_1.default,
deepProperties_1.default,
deepRequired_1.default,
dynamicDefaults_1.default,
];
function ajvKeywords(opts) {
return definitions.map((d) => d(opts)).concat((0, select_1.default)(opts));
}
exports.default = ajvKeywords;
module.exports = ajvKeywords;
//# sourceMappingURL=index.js.map

View File

@@ -0,0 +1 @@
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/definitions/index.ts"],"names":[],"mappings":";;;;;AAEA,sDAAgC;AAChC,8DAAwC;AACxC,oDAA2B;AAC3B,sEAA6C;AAC7C,sDAA6B;AAC7B,4DAAmC;AACnC,kFAAyD;AACzD,gEAAuC;AACvC,gEAAuC;AACvC,gEAAuC;AACvC,wEAAuE;AACvE,8DAAqC;AACrC,sEAA6C;AAC7C,kEAAyC;AACzC,wEAA+C;AAC/C,sDAA+C;AAE/C,MAAM,WAAW,GAAuC;IACtD,gBAAS;IACT,oBAAa;IACb,eAAK;IACL,wBAAc;IACd,gBAAM;IACN,mBAAS;IACT,8BAAoB;IACpB,qBAAW;IACX,qBAAW;IACX,qBAAW;IACX,yBAAe;IACf,oBAAU;IACV,wBAAc;IACd,sBAAY;IACZ,yBAAe;CAChB,CAAA;AAED,SAAwB,WAAW,CAAC,IAAwB;IAC1D,OAAO,WAAW,CAAC,GAAG,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,IAAI,CAAC,CAAC,CAAC,MAAM,CAAC,IAAA,gBAAS,EAAC,IAAI,CAAC,CAAC,CAAA;AAChE,CAAC;AAFD,8BAEC;AAqBD,MAAM,CAAC,OAAO,GAAG,WAAW,CAAA"}

View File

@@ -0,0 +1,7 @@
import type { FuncKeywordDefinition } from "ajv";
declare type Constructor = new (...args: any[]) => any;
declare const CONSTRUCTORS: Record<string, Constructor | undefined>;
declare const getDef: (() => FuncKeywordDefinition) & {
CONSTRUCTORS: typeof CONSTRUCTORS;
};
export default getDef;

View File

@@ -0,0 +1,54 @@
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
const CONSTRUCTORS = {
Object,
Array,
Function,
Number,
String,
Date,
RegExp,
};
/* istanbul ignore else */
if (typeof Buffer != "undefined")
CONSTRUCTORS.Buffer = Buffer;
/* istanbul ignore else */
if (typeof Promise != "undefined")
CONSTRUCTORS.Promise = Promise;
const getDef = Object.assign(_getDef, { CONSTRUCTORS });
function _getDef() {
return {
keyword: "instanceof",
schemaType: ["string", "array"],
compile(schema) {
if (typeof schema == "string") {
const C = getConstructor(schema);
return (data) => data instanceof C;
}
if (Array.isArray(schema)) {
const constructors = schema.map(getConstructor);
return (data) => {
for (const C of constructors) {
if (data instanceof C)
return true;
}
return false;
};
}
/* istanbul ignore next */
throw new Error("ajv implementation error");
},
metaSchema: {
anyOf: [{ type: "string" }, { type: "array", items: { type: "string" } }],
},
};
}
function getConstructor(c) {
const C = CONSTRUCTORS[c];
if (C)
return C;
throw new Error(`invalid "instanceof" keyword value ${c}`);
}
exports.default = getDef;
module.exports = getDef;
//# sourceMappingURL=instanceof.js.map

File diff suppressed because one or more lines are too long

View File

@@ -0,0 +1,4 @@
import type { MacroKeywordDefinition } from "ajv";
import type { GetDefinition } from "./_types";
declare const getDef: GetDefinition<MacroKeywordDefinition>;
export default getDef;

View File

@@ -0,0 +1,10 @@
"use strict";
var __importDefault = (this && this.__importDefault) || function (mod) {
return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
const _required_1 = __importDefault(require("./_required"));
const getDef = (0, _required_1.default)("oneRequired");
exports.default = getDef;
module.exports = getDef;
//# sourceMappingURL=oneRequired.js.map

View File

@@ -0,0 +1 @@
{"version":3,"file":"oneRequired.js","sourceRoot":"","sources":["../../src/definitions/oneRequired.ts"],"names":[],"mappings":";;;;;AAEA,4DAAwC;AAExC,MAAM,MAAM,GAA0C,IAAA,mBAAc,EAAC,aAAa,CAAC,CAAA;AAEnF,kBAAe,MAAM,CAAA;AACrB,MAAM,CAAC,OAAO,GAAG,MAAM,CAAA"}

View File

@@ -0,0 +1,5 @@
import type { CodeKeywordDefinition, ErrorObject } from "ajv";
export declare type PatternRequiredError = ErrorObject<"patternRequired", {
missingPattern: string;
}>;
export default function getDef(): CodeKeywordDefinition;

View File

@@ -0,0 +1,42 @@
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
const codegen_1 = require("ajv/dist/compile/codegen");
const _util_1 = require("./_util");
const error = {
message: ({ params: { missingPattern } }) => (0, codegen_1.str) `should have property matching pattern '${missingPattern}'`,
params: ({ params: { missingPattern } }) => (0, codegen_1._) `{missingPattern: ${missingPattern}}`,
};
function getDef() {
return {
keyword: "patternRequired",
type: "object",
schemaType: "array",
error,
code(cxt) {
const { gen, schema, data } = cxt;
if (schema.length === 0)
return;
const valid = gen.let("valid", true);
for (const pat of schema)
validateProperties(pat);
function validateProperties(pattern) {
const matched = gen.let("matched", false);
gen.forIn("key", data, (key) => {
gen.assign(matched, (0, codegen_1._) `${(0, _util_1.usePattern)(cxt, pattern)}.test(${key})`);
gen.if(matched, () => gen.break());
});
cxt.setParams({ missingPattern: pattern });
gen.assign(valid, (0, codegen_1.and)(valid, matched));
cxt.pass(valid);
}
},
metaSchema: {
type: "array",
items: { type: "string", format: "regex" },
uniqueItems: true,
},
};
}
exports.default = getDef;
module.exports = getDef;
//# sourceMappingURL=patternRequired.js.map

File diff suppressed because one or more lines are too long

View File

@@ -0,0 +1,2 @@
import type { MacroKeywordDefinition } from "ajv";
export default function getDef(): MacroKeywordDefinition;

View File

@@ -0,0 +1,23 @@
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
function getDef() {
return {
keyword: "prohibited",
type: "object",
schemaType: "array",
macro: function (schema) {
if (schema.length === 0)
return true;
if (schema.length === 1)
return { not: { required: schema } };
return { not: { anyOf: schema.map((p) => ({ required: [p] })) } };
},
metaSchema: {
type: "array",
items: { type: "string" },
},
};
}
exports.default = getDef;
module.exports = getDef;
//# sourceMappingURL=prohibited.js.map

View File

@@ -0,0 +1 @@
{"version":3,"file":"prohibited.js","sourceRoot":"","sources":["../../src/definitions/prohibited.ts"],"names":[],"mappings":";;AAEA,SAAwB,MAAM;IAC5B,OAAO;QACL,OAAO,EAAE,YAAY;QACrB,IAAI,EAAE,QAAQ;QACd,UAAU,EAAE,OAAO;QACnB,KAAK,EAAE,UAAU,MAAgB;YAC/B,IAAI,MAAM,CAAC,MAAM,KAAK,CAAC;gBAAE,OAAO,IAAI,CAAA;YACpC,IAAI,MAAM,CAAC,MAAM,KAAK,CAAC;gBAAE,OAAO,EAAC,GAAG,EAAE,EAAC,QAAQ,EAAE,MAAM,EAAC,EAAC,CAAA;YACzD,OAAO,EAAC,GAAG,EAAE,EAAC,KAAK,EAAE,MAAM,CAAC,GAAG,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,EAAC,QAAQ,EAAE,CAAC,CAAC,CAAC,EAAC,CAAC,CAAC,EAAC,EAAC,CAAA;QAC7D,CAAC;QACD,UAAU,EAAE;YACV,IAAI,EAAE,OAAO;YACb,KAAK,EAAE,EAAC,IAAI,EAAE,QAAQ,EAAC;SACxB;KACF,CAAA;AACH,CAAC;AAfD,yBAeC;AAED,MAAM,CAAC,OAAO,GAAG,MAAM,CAAA"}

View File

@@ -0,0 +1,4 @@
import type { MacroKeywordDefinition } from "ajv";
import type { GetDefinition } from "./_types";
declare const getDef: GetDefinition<MacroKeywordDefinition>;
export default getDef;

View File

@@ -0,0 +1,10 @@
"use strict";
var __importDefault = (this && this.__importDefault) || function (mod) {
return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
const _range_1 = __importDefault(require("./_range"));
const getDef = (0, _range_1.default)("range");
exports.default = getDef;
module.exports = getDef;
//# sourceMappingURL=range.js.map

View File

@@ -0,0 +1 @@
{"version":3,"file":"range.js","sourceRoot":"","sources":["../../src/definitions/range.ts"],"names":[],"mappings":";;;;;AAEA,sDAAkC;AAElC,MAAM,MAAM,GAA0C,IAAA,gBAAW,EAAC,OAAO,CAAC,CAAA;AAE1E,kBAAe,MAAM,CAAA;AACrB,MAAM,CAAC,OAAO,GAAG,MAAM,CAAA"}

Some files were not shown because too many files have changed in this diff Show More