Upload via GUI (7543 Dateien)

This commit is contained in:
2026-10-22 07:03:04 +00:00
parent 4f9494ae7b
commit ef911afb06
50 changed files with 1789 additions and 0 deletions
+17
View File
@@ -0,0 +1,17 @@
{
"$schema": "https://json-schema.org/draft/2020-12/schema",
"$id": "https://json-schema.org/draft/2020-12/meta/content",
"$vocabulary": {
"https://json-schema.org/draft/2020-12/vocab/content": true
},
"$dynamicAnchor": "meta",
"title": "Content vocabulary meta-schema",
"type": ["object", "boolean"],
"properties": {
"contentEncoding": {"type": "string"},
"contentMediaType": {"type": "string"},
"contentSchema": {"$dynamicRef": "#meta"}
}
}
+51
View File
@@ -0,0 +1,51 @@
{
"$schema": "https://json-schema.org/draft/2020-12/schema",
"$id": "https://json-schema.org/draft/2020-12/meta/core",
"$vocabulary": {
"https://json-schema.org/draft/2020-12/vocab/core": true
},
"$dynamicAnchor": "meta",
"title": "Core vocabulary meta-schema",
"type": ["object", "boolean"],
"properties": {
"$id": {
"$ref": "#/$defs/uriReferenceString",
"$comment": "Non-empty fragments not allowed.",
"pattern": "^[^#]*#?$"
},
"$schema": {"$ref": "#/$defs/uriString"},
"$ref": {"$ref": "#/$defs/uriReferenceString"},
"$anchor": {"$ref": "#/$defs/anchorString"},
"$dynamicRef": {"$ref": "#/$defs/uriReferenceString"},
"$dynamicAnchor": {"$ref": "#/$defs/anchorString"},
"$vocabulary": {
"type": "object",
"propertyNames": {"$ref": "#/$defs/uriString"},
"additionalProperties": {
"type": "boolean"
}
},
"$comment": {
"type": "string"
},
"$defs": {
"type": "object",
"additionalProperties": {"$dynamicRef": "#meta"}
}
},
"$defs": {
"anchorString": {
"type": "string",
"pattern": "^[A-Za-z_][-A-Za-z0-9._]*$"
},
"uriString": {
"type": "string",
"format": "uri"
},
"uriReferenceString": {
"type": "string",
"format": "uri-reference"
}
}
}
@@ -0,0 +1,14 @@
{
"$schema": "https://json-schema.org/draft/2020-12/schema",
"$id": "https://json-schema.org/draft/2020-12/meta/format-annotation",
"$vocabulary": {
"https://json-schema.org/draft/2020-12/vocab/format-annotation": true
},
"$dynamicAnchor": "meta",
"title": "Format vocabulary meta-schema for annotation results",
"type": ["object", "boolean"],
"properties": {
"format": {"type": "string"}
}
}
+37
View File
@@ -0,0 +1,37 @@
{
"$schema": "https://json-schema.org/draft/2020-12/schema",
"$id": "https://json-schema.org/draft/2020-12/meta/meta-data",
"$vocabulary": {
"https://json-schema.org/draft/2020-12/vocab/meta-data": true
},
"$dynamicAnchor": "meta",
"title": "Meta-data vocabulary meta-schema",
"type": ["object", "boolean"],
"properties": {
"title": {
"type": "string"
},
"description": {
"type": "string"
},
"default": true,
"deprecated": {
"type": "boolean",
"default": false
},
"readOnly": {
"type": "boolean",
"default": false
},
"writeOnly": {
"type": "boolean",
"default": false
},
"examples": {
"type": "array",
"items": true
}
}
}
+15
View File
@@ -0,0 +1,15 @@
{
"$schema": "https://json-schema.org/draft/2020-12/schema",
"$id": "https://json-schema.org/draft/2020-12/meta/unevaluated",
"$vocabulary": {
"https://json-schema.org/draft/2020-12/vocab/unevaluated": true
},
"$dynamicAnchor": "meta",
"title": "Unevaluated applicator vocabulary meta-schema",
"type": ["object", "boolean"],
"properties": {
"unevaluatedItems": {"$dynamicRef": "#meta"},
"unevaluatedProperties": {"$dynamicRef": "#meta"}
}
}
+90
View File
@@ -0,0 +1,90 @@
{
"$schema": "https://json-schema.org/draft/2020-12/schema",
"$id": "https://json-schema.org/draft/2020-12/meta/validation",
"$vocabulary": {
"https://json-schema.org/draft/2020-12/vocab/validation": true
},
"$dynamicAnchor": "meta",
"title": "Validation vocabulary meta-schema",
"type": ["object", "boolean"],
"properties": {
"type": {
"anyOf": [
{"$ref": "#/$defs/simpleTypes"},
{
"type": "array",
"items": {"$ref": "#/$defs/simpleTypes"},
"minItems": 1,
"uniqueItems": true
}
]
},
"const": true,
"enum": {
"type": "array",
"items": true
},
"multipleOf": {
"type": "number",
"exclusiveMinimum": 0
},
"maximum": {
"type": "number"
},
"exclusiveMaximum": {
"type": "number"
},
"minimum": {
"type": "number"
},
"exclusiveMinimum": {
"type": "number"
},
"maxLength": {"$ref": "#/$defs/nonNegativeInteger"},
"minLength": {"$ref": "#/$defs/nonNegativeIntegerDefault0"},
"pattern": {
"type": "string",
"format": "regex"
},
"maxItems": {"$ref": "#/$defs/nonNegativeInteger"},
"minItems": {"$ref": "#/$defs/nonNegativeIntegerDefault0"},
"uniqueItems": {
"type": "boolean",
"default": false
},
"maxContains": {"$ref": "#/$defs/nonNegativeInteger"},
"minContains": {
"$ref": "#/$defs/nonNegativeInteger",
"default": 1
},
"maxProperties": {"$ref": "#/$defs/nonNegativeInteger"},
"minProperties": {"$ref": "#/$defs/nonNegativeIntegerDefault0"},
"required": {"$ref": "#/$defs/stringArray"},
"dependentRequired": {
"type": "object",
"additionalProperties": {
"$ref": "#/$defs/stringArray"
}
}
},
"$defs": {
"nonNegativeInteger": {
"type": "integer",
"minimum": 0
},
"nonNegativeIntegerDefault0": {
"$ref": "#/$defs/nonNegativeInteger",
"default": 0
},
"simpleTypes": {
"enum": ["array", "boolean", "integer", "null", "number", "object", "string"]
},
"stringArray": {
"type": "array",
"items": {"type": "string"},
"uniqueItems": true,
"default": []
}
}
}
+55
View File
@@ -0,0 +1,55 @@
{
"$schema": "https://json-schema.org/draft/2020-12/schema",
"$id": "https://json-schema.org/draft/2020-12/schema",
"$vocabulary": {
"https://json-schema.org/draft/2020-12/vocab/core": true,
"https://json-schema.org/draft/2020-12/vocab/applicator": true,
"https://json-schema.org/draft/2020-12/vocab/unevaluated": true,
"https://json-schema.org/draft/2020-12/vocab/validation": true,
"https://json-schema.org/draft/2020-12/vocab/meta-data": true,
"https://json-schema.org/draft/2020-12/vocab/format-annotation": true,
"https://json-schema.org/draft/2020-12/vocab/content": true
},
"$dynamicAnchor": "meta",
"title": "Core and Validation specifications meta-schema",
"allOf": [
{"$ref": "meta/core"},
{"$ref": "meta/applicator"},
{"$ref": "meta/unevaluated"},
{"$ref": "meta/validation"},
{"$ref": "meta/meta-data"},
{"$ref": "meta/format-annotation"},
{"$ref": "meta/content"}
],
"type": ["object", "boolean"],
"$comment": "This meta-schema also defines keywords that have appeared in previous drafts in order to prevent incompatible extensions as they remain in common use.",
"properties": {
"definitions": {
"$comment": "\"definitions\" has been replaced by \"$defs\".",
"type": "object",
"additionalProperties": {"$dynamicRef": "#meta"},
"deprecated": true,
"default": {}
},
"dependencies": {
"$comment": "\"dependencies\" has been split and replaced by \"dependentSchemas\" and \"dependentRequired\" in order to serve their differing semantics.",
"type": "object",
"additionalProperties": {
"anyOf": [{"$dynamicRef": "#meta"}, {"$ref": "meta/validation#/$defs/stringArray"}]
},
"deprecated": true,
"default": {}
},
"$recursiveAnchor": {
"$comment": "\"$recursiveAnchor\" has been replaced by \"$dynamicAnchor\".",
"$ref": "meta/core#/$defs/anchorString",
"deprecated": true
},
"$recursiveRef": {
"$comment": "\"$recursiveRef\" has been replaced by \"$dynamicRef\".",
"$ref": "meta/core#/$defs/uriReferenceString",
"deprecated": true
}
}
}
+137
View File
@@ -0,0 +1,137 @@
{
"$schema": "http://json-schema.org/draft-06/schema#",
"$id": "http://json-schema.org/draft-06/schema#",
"title": "Core schema meta-schema",
"definitions": {
"schemaArray": {
"type": "array",
"minItems": 1,
"items": {"$ref": "#"}
},
"nonNegativeInteger": {
"type": "integer",
"minimum": 0
},
"nonNegativeIntegerDefault0": {
"allOf": [{"$ref": "#/definitions/nonNegativeInteger"}, {"default": 0}]
},
"simpleTypes": {
"enum": ["array", "boolean", "integer", "null", "number", "object", "string"]
},
"stringArray": {
"type": "array",
"items": {"type": "string"},
"uniqueItems": true,
"default": []
}
},
"type": ["object", "boolean"],
"properties": {
"$id": {
"type": "string",
"format": "uri-reference"
},
"$schema": {
"type": "string",
"format": "uri"
},
"$ref": {
"type": "string",
"format": "uri-reference"
},
"title": {
"type": "string"
},
"description": {
"type": "string"
},
"default": {},
"examples": {
"type": "array",
"items": {}
},
"multipleOf": {
"type": "number",
"exclusiveMinimum": 0
},
"maximum": {
"type": "number"
},
"exclusiveMaximum": {
"type": "number"
},
"minimum": {
"type": "number"
},
"exclusiveMinimum": {
"type": "number"
},
"maxLength": {"$ref": "#/definitions/nonNegativeInteger"},
"minLength": {"$ref": "#/definitions/nonNegativeIntegerDefault0"},
"pattern": {
"type": "string",
"format": "regex"
},
"additionalItems": {"$ref": "#"},
"items": {
"anyOf": [{"$ref": "#"}, {"$ref": "#/definitions/schemaArray"}],
"default": {}
},
"maxItems": {"$ref": "#/definitions/nonNegativeInteger"},
"minItems": {"$ref": "#/definitions/nonNegativeIntegerDefault0"},
"uniqueItems": {
"type": "boolean",
"default": false
},
"contains": {"$ref": "#"},
"maxProperties": {"$ref": "#/definitions/nonNegativeInteger"},
"minProperties": {"$ref": "#/definitions/nonNegativeIntegerDefault0"},
"required": {"$ref": "#/definitions/stringArray"},
"additionalProperties": {"$ref": "#"},
"definitions": {
"type": "object",
"additionalProperties": {"$ref": "#"},
"default": {}
},
"properties": {
"type": "object",
"additionalProperties": {"$ref": "#"},
"default": {}
},
"patternProperties": {
"type": "object",
"additionalProperties": {"$ref": "#"},
"default": {}
},
"dependencies": {
"type": "object",
"additionalProperties": {
"anyOf": [{"$ref": "#"}, {"$ref": "#/definitions/stringArray"}]
}
},
"propertyNames": {"$ref": "#"},
"const": {},
"enum": {
"type": "array",
"minItems": 1,
"uniqueItems": true
},
"type": {
"anyOf": [
{"$ref": "#/definitions/simpleTypes"},
{
"type": "array",
"items": {"$ref": "#/definitions/simpleTypes"},
"minItems": 1,
"uniqueItems": true
}
]
},
"format": {"type": "string"},
"allOf": {"$ref": "#/definitions/schemaArray"},
"anyOf": {"$ref": "#/definitions/schemaArray"},
"oneOf": {"$ref": "#/definitions/schemaArray"},
"not": {"$ref": "#"}
},
"default": {}
}
+151
View File
@@ -0,0 +1,151 @@
{
"$schema": "http://json-schema.org/draft-07/schema#",
"$id": "http://json-schema.org/draft-07/schema#",
"title": "Core schema meta-schema",
"definitions": {
"schemaArray": {
"type": "array",
"minItems": 1,
"items": {"$ref": "#"}
},
"nonNegativeInteger": {
"type": "integer",
"minimum": 0
},
"nonNegativeIntegerDefault0": {
"allOf": [{"$ref": "#/definitions/nonNegativeInteger"}, {"default": 0}]
},
"simpleTypes": {
"enum": ["array", "boolean", "integer", "null", "number", "object", "string"]
},
"stringArray": {
"type": "array",
"items": {"type": "string"},
"uniqueItems": true,
"default": []
}
},
"type": ["object", "boolean"],
"properties": {
"$id": {
"type": "string",
"format": "uri-reference"
},
"$schema": {
"type": "string",
"format": "uri"
},
"$ref": {
"type": "string",
"format": "uri-reference"
},
"$comment": {
"type": "string"
},
"title": {
"type": "string"
},
"description": {
"type": "string"
},
"default": true,
"readOnly": {
"type": "boolean",
"default": false
},
"examples": {
"type": "array",
"items": true
},
"multipleOf": {
"type": "number",
"exclusiveMinimum": 0
},
"maximum": {
"type": "number"
},
"exclusiveMaximum": {
"type": "number"
},
"minimum": {
"type": "number"
},
"exclusiveMinimum": {
"type": "number"
},
"maxLength": {"$ref": "#/definitions/nonNegativeInteger"},
"minLength": {"$ref": "#/definitions/nonNegativeIntegerDefault0"},
"pattern": {
"type": "string",
"format": "regex"
},
"additionalItems": {"$ref": "#"},
"items": {
"anyOf": [{"$ref": "#"}, {"$ref": "#/definitions/schemaArray"}],
"default": true
},
"maxItems": {"$ref": "#/definitions/nonNegativeInteger"},
"minItems": {"$ref": "#/definitions/nonNegativeIntegerDefault0"},
"uniqueItems": {
"type": "boolean",
"default": false
},
"contains": {"$ref": "#"},
"maxProperties": {"$ref": "#/definitions/nonNegativeInteger"},
"minProperties": {"$ref": "#/definitions/nonNegativeIntegerDefault0"},
"required": {"$ref": "#/definitions/stringArray"},
"additionalProperties": {"$ref": "#"},
"definitions": {
"type": "object",
"additionalProperties": {"$ref": "#"},
"default": {}
},
"properties": {
"type": "object",
"additionalProperties": {"$ref": "#"},
"default": {}
},
"patternProperties": {
"type": "object",
"additionalProperties": {"$ref": "#"},
"propertyNames": {"format": "regex"},
"default": {}
},
"dependencies": {
"type": "object",
"additionalProperties": {
"anyOf": [{"$ref": "#"}, {"$ref": "#/definitions/stringArray"}]
}
},
"propertyNames": {"$ref": "#"},
"const": true,
"enum": {
"type": "array",
"items": true,
"minItems": 1,
"uniqueItems": true
},
"type": {
"anyOf": [
{"$ref": "#/definitions/simpleTypes"},
{
"type": "array",
"items": {"$ref": "#/definitions/simpleTypes"},
"minItems": 1,
"uniqueItems": true
}
]
},
"format": {"type": "string"},
"contentMediaType": {"type": "string"},
"contentEncoding": {"type": "string"},
"if": {"$ref": "#"},
"then": {"$ref": "#"},
"else": {"$ref": "#"},
"allOf": {"$ref": "#/definitions/schemaArray"},
"anyOf": {"$ref": "#/definitions/schemaArray"},
"oneOf": {"$ref": "#/definitions/schemaArray"},
"not": {"$ref": "#"}
},
"default": true
}
+88
View File
@@ -0,0 +1,88 @@
{
"$schema": "http://json-schema.org/draft-07/schema#",
"$id": "https://raw.githubusercontent.com/ajv-validator/ajv/master/lib/refs/json-schema-secure.json#",
"title": "Meta-schema for the security assessment of JSON Schemas",
"description": "If a JSON AnySchema fails validation against this meta-schema, it may be unsafe to validate untrusted data",
"definitions": {
"schemaArray": {
"type": "array",
"minItems": 1,
"items": {"$ref": "#"}
}
},
"dependencies": {
"patternProperties": {
"description": "prevent slow validation of large property names",
"required": ["propertyNames"],
"properties": {
"propertyNames": {
"required": ["maxLength"]
}
}
},
"uniqueItems": {
"description": "prevent slow validation of large non-scalar arrays",
"if": {
"properties": {
"uniqueItems": {"const": true},
"items": {
"properties": {
"type": {
"anyOf": [
{
"enum": ["object", "array"]
},
{
"type": "array",
"contains": {"enum": ["object", "array"]}
}
]
}
}
}
}
},
"then": {
"required": ["maxItems"]
}
},
"pattern": {
"description": "prevent slow pattern matching of large strings",
"required": ["maxLength"]
},
"format": {
"description": "prevent slow format validation of large strings",
"required": ["maxLength"]
}
},
"properties": {
"additionalItems": {"$ref": "#"},
"additionalProperties": {"$ref": "#"},
"dependencies": {
"additionalProperties": {
"anyOf": [{"type": "array"}, {"$ref": "#"}]
}
},
"items": {
"anyOf": [{"$ref": "#"}, {"$ref": "#/definitions/schemaArray"}]
},
"definitions": {
"additionalProperties": {"$ref": "#"}
},
"patternProperties": {
"additionalProperties": {"$ref": "#"}
},
"properties": {
"additionalProperties": {"$ref": "#"}
},
"if": {"$ref": "#"},
"then": {"$ref": "#"},
"else": {"$ref": "#"},
"allOf": {"$ref": "#/definitions/schemaArray"},
"anyOf": {"$ref": "#/definitions/schemaArray"},
"oneOf": {"$ref": "#/definitions/schemaArray"},
"not": {"$ref": "#"},
"contains": {"$ref": "#"},
"propertyNames": {"$ref": "#"}
}
}
+3
View File
@@ -0,0 +1,3 @@
import { SchemaObject } from "../types";
declare const jtdMetaSchema: SchemaObject;
export default jtdMetaSchema;
+118
View File
@@ -0,0 +1,118 @@
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
const shared = (root) => {
const sch = {
nullable: { type: "boolean" },
metadata: {
optionalProperties: {
union: { elements: { ref: "schema" } },
},
additionalProperties: true,
},
};
if (root)
sch.definitions = { values: { ref: "schema" } };
return sch;
};
const emptyForm = (root) => ({
optionalProperties: shared(root),
});
const refForm = (root) => ({
properties: {
ref: { type: "string" },
},
optionalProperties: shared(root),
});
const typeForm = (root) => ({
properties: {
type: {
enum: [
"boolean",
"timestamp",
"string",
"float32",
"float64",
"int8",
"uint8",
"int16",
"uint16",
"int32",
"uint32",
],
},
},
optionalProperties: shared(root),
});
const enumForm = (root) => ({
properties: {
enum: { elements: { type: "string" } },
},
optionalProperties: shared(root),
});
const elementsForm = (root) => ({
properties: {
elements: { ref: "schema" },
},
optionalProperties: shared(root),
});
const propertiesForm = (root) => ({
properties: {
properties: { values: { ref: "schema" } },
},
optionalProperties: {
optionalProperties: { values: { ref: "schema" } },
additionalProperties: { type: "boolean" },
...shared(root),
},
});
const optionalPropertiesForm = (root) => ({
properties: {
optionalProperties: { values: { ref: "schema" } },
},
optionalProperties: {
additionalProperties: { type: "boolean" },
...shared(root),
},
});
const discriminatorForm = (root) => ({
properties: {
discriminator: { type: "string" },
mapping: {
values: {
metadata: {
union: [propertiesForm(false), optionalPropertiesForm(false)],
},
},
},
},
optionalProperties: shared(root),
});
const valuesForm = (root) => ({
properties: {
values: { ref: "schema" },
},
optionalProperties: shared(root),
});
const schema = (root) => ({
metadata: {
union: [
emptyForm,
refForm,
typeForm,
enumForm,
elementsForm,
propertiesForm,
optionalPropertiesForm,
discriminatorForm,
valuesForm,
].map((s) => s(root)),
},
});
const jtdMetaSchema = {
definitions: {
schema: schema(false),
},
...schema(true),
};
exports.default = jtdMetaSchema;
//# sourceMappingURL=jtd-schema.js.map
+1
View File
@@ -0,0 +1 @@
{"version":3,"file":"jtd-schema.js","sourceRoot":"","sources":["../../lib/refs/jtd-schema.ts"],"names":[],"mappings":";;AAIA,MAAM,MAAM,GAAe,CAAC,IAAI,EAAE,EAAE;IAClC,MAAM,GAAG,GAAiB;QACxB,QAAQ,EAAE,EAAC,IAAI,EAAE,SAAS,EAAC;QAC3B,QAAQ,EAAE;YACR,kBAAkB,EAAE;gBAClB,KAAK,EAAE,EAAC,QAAQ,EAAE,EAAC,GAAG,EAAE,QAAQ,EAAC,EAAC;aACnC;YACD,oBAAoB,EAAE,IAAI;SAC3B;KACF,CAAA;IACD,IAAI,IAAI;QAAE,GAAG,CAAC,WAAW,GAAG,EAAC,MAAM,EAAE,EAAC,GAAG,EAAE,QAAQ,EAAC,EAAC,CAAA;IACrD,OAAO,GAAG,CAAA;AACZ,CAAC,CAAA;AAED,MAAM,SAAS,GAAe,CAAC,IAAI,EAAE,EAAE,CAAC,CAAC;IACvC,kBAAkB,EAAE,MAAM,CAAC,IAAI,CAAC;CACjC,CAAC,CAAA;AAEF,MAAM,OAAO,GAAe,CAAC,IAAI,EAAE,EAAE,CAAC,CAAC;IACrC,UAAU,EAAE;QACV,GAAG,EAAE,EAAC,IAAI,EAAE,QAAQ,EAAC;KACtB;IACD,kBAAkB,EAAE,MAAM,CAAC,IAAI,CAAC;CACj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import * as equal from "fast-deep-equal";
type Equal = typeof equal & {
code: string;
};
declare const _default: Equal;
export default _default;
+7
View File
@@ -0,0 +1,7 @@
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
// https://github.com/ajv-validator/ajv/issues/889
const equal = require("fast-deep-equal");
equal.code = 'require("ajv/dist/runtime/equal").default';
exports.default = equal;
//# sourceMappingURL=equal.js.map
+1
View File
@@ -0,0 +1 @@
{"version":3,"file":"equal.js","sourceRoot":"","sources":["../../lib/runtime/equal.ts"],"names":[],"mappings":";;AAAA,kDAAkD;AAClD,yCAAwC;AAGtC,KAAe,CAAC,IAAI,GAAG,2CAA2C,CAAA;AAEpE,kBAAe,KAAc,CAAA"}
+18
View File
@@ -0,0 +1,18 @@
export declare function parseJson(s: string, pos: number): unknown;
export declare namespace parseJson {
var message: string | undefined;
var position: number;
var code: string;
}
export declare function parseJsonNumber(s: string, pos: number, maxDigits?: number): number | undefined;
export declare namespace parseJsonNumber {
var message: string | undefined;
var position: number;
var code: string;
}
export declare function parseJsonString(s: string, pos: number): string | undefined;
export declare namespace parseJsonString {
var message: string | undefined;
var position: number;
var code: string;
}
+185
View File
@@ -0,0 +1,185 @@
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.parseJsonString = exports.parseJsonNumber = exports.parseJson = void 0;
const rxParseJson = /position\s(\d+)(?: \(line \d+ column \d+\))?$/;
function parseJson(s, pos) {
let endPos;
parseJson.message = undefined;
let matches;
if (pos)
s = s.slice(pos);
try {
parseJson.position = pos + s.length;
return JSON.parse(s);
}
catch (e) {
matches = rxParseJson.exec(e.message);
if (!matches) {
parseJson.message = "unexpected end";
return undefined;
}
endPos = +matches[1];
const c = s[endPos];
s = s.slice(0, endPos);
parseJson.position = pos + endPos;
try {
return JSON.parse(s);
}
catch (e1) {
parseJson.message = `unexpected token ${c}`;
return undefined;
}
}
}
exports.parseJson = parseJson;
parseJson.message = undefined;
parseJson.position = 0;
parseJson.code = 'require("ajv/dist/runtime/parseJson").parseJson';
function parseJsonNumber(s, pos, maxDigits) {
let numStr = "";
let c;
parseJsonNumber.message = undefined;
if (s[pos] === "-") {
numStr += "-";
pos++;
}
if (s[pos] === "0") {
numStr += "0";
pos++;
}
else {
if (!parseDigits(maxDigits)) {
errorMessage();
return undefined;
}
}
if (maxDigits) {
parseJsonNumber.position = pos;
return +numStr;
}
if (s[pos] === ".") {
numStr += ".";
pos++;
if (!parseDigits()) {
errorMessage();
return undefined;
}
}
if (((c = s[pos]), c === "e" || c === "E")) {
numStr += "e";
pos++;
if (((c = s[pos]), c === "+" || c === "-")) {
numStr += c;
pos++;
}
if (!parseDigits()) {
errorMessage();
return undefined;
}
}
parseJsonNumber.position = pos;
return +numStr;
function parseDigits(maxLen) {
let digit = false;
while (((c = s[pos]), c >= "0" && c <= "9" && (maxLen === undefined || maxLen-- > 0))) {
digit = true;
numStr += c;
pos++;
}
return digit;
}
function errorMessage() {
parseJsonNumber.position = pos;
parseJsonNumber.message = pos < s.length ? `unexpected token ${s[pos]}` : "unexpected end";
}
}
exports.parseJsonNumber = parseJsonNumber;
parseJsonNumber.message = undefined;
parseJsonNumber.position = 0;
parseJsonNumber.code = 'require("ajv/dist/runtime/parseJson").parseJsonNumber';
const escapedChars = {
b: "\b",
f: "\f",
n: "\n",
r: "\r",
t: "\t",
'"': '"',
"/": "/",
"\\": "\\",
};
const CODE_A = "a".charCodeAt(0);
const CODE_0 = "0".charCodeAt(0);
function parseJsonString(s, pos) {
let str = "";
let c;
parseJsonString.message = undefined;
// eslint-disable-next-line no-constant-condition, @typescript-eslint/no-unnecessary-condition
while (true) {
c = s[pos++];
if (c === '"')
break;
if (c === "\\") {
c = s[pos];
if (c in escapedChars) {
str += escapedChars[c];
pos++;
}
else if (c === "u") {
pos++;
let count = 4;
let code = 0;
while (count--) {
code <<= 4;
c = s[pos];
// eslint-disable-next-line @typescript-eslint/no-unnecessary-condition
if (c === undefined) {
errorMessage("unexpected end");
return undefined;
}
c = c.toLowerCase();
if (c >= "a" && c <= "f") {
code += c.charCodeAt(0) - CODE_A + 10;
}
else if (c >= "0" && c <= "9") {
code += c.charCodeAt(0) - CODE_0;
}
else {
errorMessage(`unexpected token ${c}`);
return undefined;
}
pos++;
}
str += String.fromCharCode(code);
}
else {
errorMessage(`unexpected token ${c}`);
return undefined;
}
// eslint-disable-next-line @typescript-eslint/no-unnecessary-condition
}
else if (c === undefined) {
errorMessage("unexpected end");
return undefined;
}
else {
if (c.charCodeAt(0) >= 0x20) {
str += c;
}
else {
errorMessage(`unexpected token ${c}`);
return undefined;
}
}
}
parseJsonString.position = pos;
return str;
function errorMessage(msg) {
parseJsonString.position = pos;
parseJsonString.message = msg;
}
}
exports.parseJsonString = parseJsonString;
parseJsonString.message = undefined;
parseJsonString.position = 0;
parseJsonString.code = 'require("ajv/dist/runtime/parseJson").parseJsonString';
//# sourceMappingURL=parseJson.js.map
File diff suppressed because one or more lines are too long
+5
View File
@@ -0,0 +1,5 @@
declare function quote(s: string): string;
declare namespace quote {
var code: string;
}
export default quote;
+30
View File
@@ -0,0 +1,30 @@
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
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;
const escaped = {
"\b": "\\b",
"\t": "\\t",
"\n": "\\n",
"\f": "\\f",
"\r": "\\r",
'"': '\\"',
"\\": "\\\\",
};
function quote(s) {
rxEscapable.lastIndex = 0;
return ('"' +
(rxEscapable.test(s)
? s.replace(rxEscapable, (a) => {
const c = escaped[a];
return typeof c === "string"
? c
: "\\u" + ("0000" + a.charCodeAt(0).toString(16)).slice(-4);
})
: s) +
'"');
}
exports.default = quote;
quote.code = 'require("ajv/dist/runtime/quote").default';
//# sourceMappingURL=quote.js.map
+1
View File
@@ -0,0 +1 @@
{"version":3,"file":"quote.js","sourceRoot":"","sources":["../../lib/runtime/quote.ts"],"names":[],"mappings":";;AAAA,MAAM,WAAW;AACf,2EAA2E;AAC3E,iIAAiI,CAAA;AAEnI,MAAM,OAAO,GAA6B;IACxC,IAAI,EAAE,KAAK;IACX,IAAI,EAAE,KAAK;IACX,IAAI,EAAE,KAAK;IACX,IAAI,EAAE,KAAK;IACX,IAAI,EAAE,KAAK;IACX,GAAG,EAAE,KAAK;IACV,IAAI,EAAE,MAAM;CACb,CAAA;AAED,SAAwB,KAAK,CAAC,CAAS;IACrC,WAAW,CAAC,SAAS,GAAG,CAAC,CAAA;IACzB,OAAO,CACL,GAAG;QACH,CAAC,WAAW,CAAC,IAAI,CAAC,CAAC,CAAC;YAClB,CAAC,CAAC,CAAC,CAAC,OAAO,CAAC,WAAW,EAAE,CAAC,CAAC,EAAE,EAAE;gBAC3B,MAAM,CAAC,GAAG,OAAO,CAAC,CAAC,CAAC,CAAA;gBACpB,OAAO,OAAO,CAAC,KAAK,QAAQ;oBAC1B,CAAC,CAAC,CAAC;oBACH,CAAC,CAAC,KAAK,GAAG,CAAC,MAAM,GAAG,CAAC,CAAC,UAAU,CAAC,CAAC,CAAC,CAAC,QAAQ,CAAC,EAAE,CAAC,CAAC,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,CAAA;YAC/D,CAAC,CAAC;YACJ,CAAC,CAAC,CAAC,CAAC;QACN,GAAG,CACJ,CAAA;AACH,CAAC;AAdD,wBAcC;AAED,KAAK,CAAC,IAAI,GAAG,2CAA2C,CAAA"}
+6
View File
@@ -0,0 +1,6 @@
import * as re2 from "re2";
type Re2 = typeof re2 & {
code: string;
};
declare const _default: Re2;
export default _default;
+6
View File
@@ -0,0 +1,6 @@
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
const re2 = require("re2");
re2.code = 'require("ajv/dist/runtime/re2").default';
exports.default = re2;
//# sourceMappingURL=re2.js.map
+1
View File
@@ -0,0 +1 @@
{"version":3,"file":"re2.js","sourceRoot":"","sources":["../../lib/runtime/re2.ts"],"names":[],"mappings":";;AAAA,2BAA0B;AAGxB,GAAW,CAAC,IAAI,GAAG,yCAAyC,CAAA;AAE9D,kBAAe,GAAU,CAAA"}
+5
View File
@@ -0,0 +1,5 @@
declare function validTimestamp(str: string, allowDate: boolean): boolean;
declare namespace validTimestamp {
var code: string;
}
export default validTimestamp;
+42
View File
@@ -0,0 +1,42 @@
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
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, allowDate) {
// http://tools.ietf.org/html/rfc3339#section-5.6
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)
return false;
const y = +matches[1];
const m = +matches[2];
const d = +matches[3];
return (m >= 1 &&
m <= 12 &&
d >= 1 &&
(d <= DAYS[m] ||
// leap year: https://tools.ietf.org/html/rfc3339#appendix-C
(m === 2 && d === 29 && (y % 100 === 0 ? y % 400 === 0 : y % 4 === 0))));
}
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
+1
View File
@@ -0,0 +1 @@
{"version":3,"file":"timestamp.js","sourceRoot":"","sources":["../../lib/runtime/timestamp.ts"],"names":[],"mappings":";;AAAA,MAAM,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,CAAC,KAAK,EAAE,IAAI,CAAC,CAAC,GAAG,GAAG,KAAK,CAAC,CAAC,CAAC,CAAC,CAAC,GAAG,GAAG,KAAK,CAAC,CAAC,CAAC,CAAC,CAAC,GAAG,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,CAC1E,CAAA;AACH,CAAC;AAED,SAAS,SAAS,CAAC,GAAW;IAC5B,MAAM,OAAO,GAAoB,IAAI,CAAC,IAAI,CAAC,GAAG,CAAC,CAAA;IAC/C,IAAI,CAAC,OAAO;QAAE,OAAO,KAAK,CAAA;IAC1B,MAAM,EAAE,GAAW,CAAC,OAAO,CAAC,CAAC,CAAC,CAAA;IAC9B,MAAM,GAAG,GAAW,CAAC,OAAO,CAAC,CAAC,CAAC,CAAA;IAC/B,MAAM,GAAG,GAAW,CAAC,OAAO,CAAC,CAAC,CAAC,CAAA;IAC/B,MAAM,GAAG,GAAW,CAAC,CAAC,OAAO,CAAC,CAAC,CAAC,IAAI,CAAC,CAAC,CAAA;IACtC,MAAM,GAAG,GAAW,CAAC,CAAC,OAAO,CAAC,CAAC,CAAC,IAAI,CAAC,CAAC,CAAA;IACtC,OAAO,CACL,CAAC,EAAE,IAAI,EAAE,IAAI,GAAG,IAAI,EAAE,IAAI,GAAG,IAAI,EAAE,CAAC;QACpC,cAAc;QACd,CAAC,EAAE,GAAG,GAAG,KAAK,EAAE,IAAI,GAAG,GAAG,GAAG,KAAK,EAAE,IAAI,GAAG,KAAK,EAAE,CAAC,CACpD,CAAA;AACH,CAAC;AAED,cAAc,CAAC,IAAI,GAAG,+CAA+C,CAAA"}
+5
View File
@@ -0,0 +1,5 @@
declare function ucs2length(str: string): number;
declare namespace ucs2length {
var code: string;
}
export default ucs2length;
+24
View File
@@ -0,0 +1,24 @@
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
// https://mathiasbynens.be/notes/javascript-encoding
// https://github.com/bestiejs/punycode.js - punycode.ucs2.decode
function ucs2length(str) {
const len = str.length;
let length = 0;
let pos = 0;
let value;
while (pos < len) {
length++;
value = str.charCodeAt(pos++);
if (value >= 0xd800 && value <= 0xdbff && pos < len) {
// high surrogate, and there is a next character
value = str.charCodeAt(pos);
if ((value & 0xfc00) === 0xdc00)
pos++; // low surrogate
}
}
return length;
}
exports.default = ucs2length;
ucs2length.code = 'require("ajv/dist/runtime/ucs2length").default';
//# sourceMappingURL=ucs2length.js.map
+1
View File
@@ -0,0 +1 @@
{"version":3,"file":"ucs2length.js","sourceRoot":"","sources":["../../lib/runtime/ucs2length.ts"],"names":[],"mappings":";;AAAA,qDAAqD;AACrD,iEAAiE;AACjE,SAAwB,UAAU,CAAC,GAAW;IAC5C,MAAM,GAAG,GAAG,GAAG,CAAC,MAAM,CAAA;IACtB,IAAI,MAAM,GAAG,CAAC,CAAA;IACd,IAAI,GAAG,GAAG,CAAC,CAAA;IACX,IAAI,KAAa,CAAA;IACjB,OAAO,GAAG,GAAG,GAAG,EAAE,CAAC;QACjB,MAAM,EAAE,CAAA;QACR,KAAK,GAAG,GAAG,CAAC,UAAU,CAAC,GAAG,EAAE,CAAC,CAAA;QAC7B,IAAI,KAAK,IAAI,MAAM,IAAI,KAAK,IAAI,MAAM,IAAI,GAAG,GAAG,GAAG,EAAE,CAAC;YACpD,gDAAgD;YAChD,KAAK,GAAG,GAAG,CAAC,UAAU,CAAC,GAAG,CAAC,CAAA;YAC3B,IAAI,CAAC,KAAK,GAAG,MAAM,CAAC,KAAK,MAAM;gBAAE,GAAG,EAAE,CAAA,CAAC,gBAAgB;QACzD,CAAC;IACH,CAAC;IACD,OAAO,MAAM,CAAA;AACf,CAAC;AAfD,6BAeC;AAED,UAAU,CAAC,IAAI,GAAG,gDAAgD,CAAA"}
+6
View File
@@ -0,0 +1,6 @@
import * as uri from "fast-uri";
type URI = typeof uri & {
code: string;
};
declare const _default: URI;
export default _default;
+6
View File
@@ -0,0 +1,6 @@
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
const uri = require("fast-uri");
uri.code = 'require("ajv/dist/runtime/uri").default';
exports.default = uri;
//# sourceMappingURL=uri.js.map
+1
View File
@@ -0,0 +1 @@
{"version":3,"file":"uri.js","sourceRoot":"","sources":["../../lib/runtime/uri.ts"],"names":[],"mappings":";;AAAA,gCAA+B;AAG7B,GAAW,CAAC,IAAI,GAAG,yCAAyC,CAAA;AAE9D,kBAAe,GAAU,CAAA"}
+7
View File
@@ -0,0 +1,7 @@
import type { ErrorObject } from "../types";
export default class ValidationError extends Error {
readonly errors: Partial<ErrorObject>[];
readonly ajv: true;
readonly validation: true;
constructor(errors: Partial<ErrorObject>[]);
}
+11
View File
@@ -0,0 +1,11 @@
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
class ValidationError extends Error {
constructor(errors) {
super("validation failed");
this.errors = errors;
this.ajv = this.validation = true;
}
}
exports.default = ValidationError;
//# sourceMappingURL=validation_error.js.map
+1
View File
@@ -0,0 +1 @@
{"version":3,"file":"validation_error.js","sourceRoot":"","sources":["../../lib/runtime/validation_error.ts"],"names":[],"mappings":";;AAEA,MAAqB,eAAgB,SAAQ,KAAK;IAKhD,YAAY,MAA8B;QACxC,KAAK,CAAC,mBAAmB,CAAC,CAAA;QAC1B,IAAI,CAAC,MAAM,GAAG,MAAM,CAAA;QACpB,IAAI,CAAC,GAAG,GAAG,IAAI,CAAC,UAAU,GAAG,IAAI,CAAA;IACnC,CAAC;CACF;AAVD,kCAUC"}
+6
View File
@@ -0,0 +1,6 @@
import type AjvCore from "../core";
import type { AnyValidateFunction } from "../types";
declare function standaloneCode(ajv: AjvCore, refsOrFunc?: {
[K in string]?: string;
} | AnyValidateFunction): string;
export default standaloneCode;
+90
View File
@@ -0,0 +1,90 @@
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
const scope_1 = require("../compile/codegen/scope");
const code_1 = require("../compile/codegen/code");
function standaloneCode(ajv, refsOrFunc) {
if (!ajv.opts.code.source) {
throw new Error("moduleCode: ajv instance must have code.source option");
}
const { _n } = ajv.scope.opts;
return typeof refsOrFunc == "function"
? funcExportCode(refsOrFunc.source)
: refsOrFunc !== undefined
? multiExportsCode(refsOrFunc, getValidate)
: multiExportsCode(ajv.schemas, (sch) => sch.meta ? undefined : ajv.compile(sch.schema));
function getValidate(id) {
const v = ajv.getSchema(id);
if (!v)
throw new Error(`moduleCode: no schema with id ${id}`);
return v;
}
function funcExportCode(source) {
const usedValues = {};
const n = source === null || source === void 0 ? void 0 : source.validateName;
const vCode = validateCode(usedValues, source);
if (ajv.opts.code.esm) {
// Always do named export as `validate` rather than the variable `n` which is `validateXX` for known export value
return `"use strict";${_n}export const validate = ${n};${_n}export default ${n};${_n}${vCode}`;
}
return `"use strict";${_n}module.exports = ${n};${_n}module.exports.default = ${n};${_n}${vCode}`;
}
function multiExportsCode(schemas, getValidateFunc) {
var _a;
const usedValues = {};
let code = (0, code_1._) `"use strict";`;
for (const name in schemas) {
const v = getValidateFunc(schemas[name]);
if (v) {
const vCode = validateCode(usedValues, v.source);
const exportSyntax = ajv.opts.code.esm
? (0, code_1._) `export const ${(0, code_1.getEsmExportName)(name)}`
: (0, code_1._) `exports${(0, code_1.getProperty)(name)}`;
code = (0, code_1._) `${code}${_n}${exportSyntax} = ${(_a = v.source) === null || _a === void 0 ? void 0 : _a.validateName};${_n}${vCode}`;
}
}
return `${code}`;
}
function validateCode(usedValues, s) {
if (!s)
throw new Error('moduleCode: function does not have "source" property');
if (usedState(s.validateName) === scope_1.UsedValueState.Completed)
return code_1.nil;
setUsedState(s.validateName, scope_1.UsedValueState.Started);
const scopeCode = ajv.scope.scopeCode(s.scopeValues, usedValues, refValidateCode);
const code = new code_1._Code(`${scopeCode}${_n}${s.validateCode}`);
return s.evaluated ? (0, code_1._) `${code}${s.validateName}.evaluated = ${s.evaluated};${_n}` : code;
function refValidateCode(n) {
var _a;
const vRef = (_a = n.value) === null || _a === void 0 ? void 0 : _a.ref;
if (n.prefix === "validate" && typeof vRef == "function") {
const v = vRef;
return validateCode(usedValues, v.source);
}
else if ((n.prefix === "root" || n.prefix === "wrapper") && typeof vRef == "object") {
const { validate, validateName } = vRef;
if (!validateName)
throw new Error("ajv internal error");
const def = ajv.opts.code.es5 ? scope_1.varKinds.var : scope_1.varKinds.const;
const wrapper = (0, code_1._) `${def} ${n} = {validate: ${validateName}};`;
if (usedState(validateName) === scope_1.UsedValueState.Started)
return wrapper;
const vCode = validateCode(usedValues, validate === null || validate === void 0 ? void 0 : validate.source);
return (0, code_1._) `${wrapper}${_n}${vCode}`;
}
return undefined;
}
function usedState(name) {
var _a;
return (_a = usedValues[name.prefix]) === null || _a === void 0 ? void 0 : _a.get(name);
}
function setUsedState(name, state) {
const { prefix } = name;
const names = (usedValues[prefix] = usedValues[prefix] || new Map());
names.set(name, state);
}
}
}
module.exports = exports = standaloneCode;
Object.defineProperty(exports, "__esModule", { value: true });
exports.default = standaloneCode;
//# sourceMappingURL=index.js.map
+1
View File
@@ -0,0 +1 @@
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../lib/standalone/index.ts"],"names":[],"mappings":";;AAGA,oDAAkG;AAClG,kDAA0F;AAE1F,SAAS,cAAc,CACrB,GAAY,EACZ,UAA2D;IAE3D,IAAI,CAAC,GAAG,CAAC,IAAI,CAAC,IAAI,CAAC,MAAM,EAAE,CAAC;QAC1B,MAAM,IAAI,KAAK,CAAC,uDAAuD,CAAC,CAAA;IAC1E,CAAC;IACD,MAAM,EAAC,EAAE,EAAC,GAAG,GAAG,CAAC,KAAK,CAAC,IAAI,CAAA;IAC3B,OAAO,OAAO,UAAU,IAAI,UAAU;QACpC,CAAC,CAAC,cAAc,CAAC,UAAU,CAAC,MAAM,CAAC;QACnC,CAAC,CAAC,UAAU,KAAK,SAAS;YAC1B,CAAC,CAAC,gBAAgB,CAAS,UAAU,EAAE,WAAW,CAAC;YACnD,CAAC,CAAC,gBAAgB,CAAY,GAAG,CAAC,OAAO,EAAE,CAAC,GAAG,EAAE,EAAE,CAC/C,GAAG,CAAC,IAAI,CAAC,CAAC,CAAC,SAAS,CAAC,CAAC,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AG,IAAI,CAAA;YACrB,MAAM,KAAK,GAAG,CAAC,UAAU,CAAC,MAAM,CAAC,GAAG,UAAU,CAAC,MAAM,CAAC,IAAI,IAAI,GAAG,EAAE,CAAC,CAAA;YACpE,KAAK,CAAC,GAAG,CAAC,IAAI,EAAE,KAAK,CAAC,CAAA;QACxB,CAAC;IACH,CAAC;AACH,CAAC;AAED,MAAM,CAAC,OAAO,GAAG,OAAO,GAAG,cAAc,CAAA;AACzC,MAAM,CAAC,cAAc,CAAC,OAAO,EAAE,YAAY,EAAE,EAAC,KAAK,EAAE,IAAI,EAAC,CAAC,CAAA;AAE3D,kBAAe,cAAc,CAAA"}
+12
View File
@@ -0,0 +1,12 @@
import Ajv, { AnySchema, AnyValidateFunction, ErrorObject } from "../core";
export default class AjvPack {
readonly ajv: Ajv;
errors?: ErrorObject[] | null;
constructor(ajv: Ajv);
validate(schemaKeyRef: AnySchema | string, data: unknown): boolean | Promise<unknown>;
compile<T = unknown>(schema: AnySchema, meta?: boolean): AnyValidateFunction<T>;
getSchema<T = unknown>(keyRef: string): AnyValidateFunction<T> | undefined;
private getStandalone;
addSchema(...args: Parameters<typeof Ajv.prototype.addSchema>): AjvPack;
addKeyword(...args: Parameters<typeof Ajv.prototype.addKeyword>): AjvPack;
}
+35
View File
@@ -0,0 +1,35 @@
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
const core_1 = require("../core");
const _1 = require(".");
const requireFromString = require("require-from-string");
class AjvPack {
constructor(ajv) {
this.ajv = ajv;
}
validate(schemaKeyRef, data) {
return core_1.default.prototype.validate.call(this, schemaKeyRef, data);
}
compile(schema, meta) {
return this.getStandalone(this.ajv.compile(schema, meta));
}
getSchema(keyRef) {
const v = this.ajv.getSchema(keyRef);
if (!v)
return undefined;
return this.getStandalone(v);
}
getStandalone(v) {
return requireFromString((0, _1.default)(this.ajv, v));
}
addSchema(...args) {
this.ajv.addSchema.call(this.ajv, ...args);
return this;
}
addKeyword(...args) {
this.ajv.addKeyword.call(this.ajv, ...args);
return this;
}
}
exports.default = AjvPack;
//# sourceMappingURL=instance.js.map
+1
View File
@@ -0,0 +1 @@
{"version":3,"file":"instance.js","sourceRoot":"","sources":["../../lib/standalone/instance.ts"],"names":[],"mappings":";;AAAA,kCAAwE;AACxE,wBAA8B;AAC9B,yDAAwD;AAExD,MAAqB,OAAO;IAE1B,YAAqB,GAAQ;QAAR,QAAG,GAAH,GAAG,CAAK;IAAG,CAAC;IAEjC,QAAQ,CAAC,YAAgC,EAAE,IAAa;QACtD,OAAO,cAAG,CAAC,SAAS,CAAC,QAAQ,CAAC,IAAI,CAAC,IAAI,EAAE,YAAY,EAAE,IAAI,CAAC,CAAA;IAC9D,CAAC;IAED,OAAO,CAAc,MAAiB,EAAE,IAAc;QACpD,OAAO,IAAI,CAAC,aAAa,CAAC,IAAI,CAAC,GAAG,CAAC,OAAO,CAAI,MAAM,EAAE,IAAI,CAAC,CAAC,CAAA;IAC9D,CAAC;IAED,SAAS,CAAc,MAAc;QACnC,MAAM,CAAC,GAAG,IAAI,CAAC,GAAG,CAAC,SAAS,CAAI,MAAM,CAAC,CAAA;QACvC,IAAI,CAAC,CAAC;YAAE,OAAO,SAAS,CAAA;QACxB,OAAO,IAAI,CAAC,aAAa,CAAC,CAAC,CAAC,CAAA;IAC9B,CAAC;IAEO,aAAa,CAAc,CAAyB;QAC1D,OAAO,iBAAiB,CAAC,IAAA,UAAc,EAAC,IAAI,CAAC,GAAG,EAAE,CAAC,CAAC,CAA2B,CAAA;IACjF,CAAC;IAED,SAAS,CAAC,GAAG,IAAgD;QAC3D,IAAI,CAAC,GAAG,CAAC,SAAS,CAAC,IAAI,CAAC,IAAI,CAAC,GAAG,EAAE,GAAG,IAAI,CAAC,CAAA;QAC1C,OAAO,IAAI,CAAA;IACb,CAAC;IAED,UAAU,CAAC,GAAG,IAAiD;QAC7D,IAAI,CAAC,GAAG,CAAC,UAAU,CAAC,IAAI,CAAC,IAAI,CAAC,GAAG,EAAE,GAAG,IAAI,CAAC,CAAA;QAC3C,OAAO,IAAI,CAAA;IACb,CAAC;CACF;AA/BD,0BA+BC"}
+183
View File
@@ -0,0 +1,183 @@
import { URIComponent } from "fast-uri";
import type { CodeGen, Code, Name, ScopeValueSets, ValueScopeName } from "../compile/codegen";
import type { SchemaEnv, SchemaCxt, SchemaObjCxt } from "../compile";
import type { JSONType } from "../compile/rules";
import type { KeywordCxt } from "../compile/validate";
import type Ajv from "../core";
interface _SchemaObject {
id?: string;
$id?: string;
$schema?: string;
[x: string]: any;
}
export interface SchemaObject extends _SchemaObject {
id?: string;
$id?: string;
$schema?: string;
$async?: false;
[x: string]: any;
}
export interface AsyncSchema extends _SchemaObject {
$async: true;
}
export type AnySchemaObject = SchemaObject | AsyncSchema;
export type Schema = SchemaObject | boolean;
export type AnySchema = Schema | AsyncSchema;
export type SchemaMap = {
[Key in string]?: AnySchema;
};
export interface SourceCode {
validateName: ValueScopeName;
validateCode: string;
scopeValues: ScopeValueSets;
evaluated?: Code;
}
export interface DataValidationCxt<T extends string | number = string | number> {
instancePath: string;
parentData: {
[K in T]: any;
};
parentDataProperty: T;
rootData: Record<string, any> | any[];
dynamicAnchors: {
[Ref in string]?: ValidateFunction;
};
}
export interface ValidateFunction<T = unknown> {
(this: Ajv | any, data: any, dataCxt?: DataValidationCxt): data is T;
errors?: null | ErrorObject[];
evaluated?: Evaluated;
schema: AnySchema;
schemaEnv: SchemaEnv;
source?: SourceCode;
}
export interface JTDParser<T = unknown> {
(json: string): T | undefined;
message?: string;
position?: number;
}
export type EvaluatedProperties = {
[K in string]?: true;
} | true;
export type EvaluatedItems = number | true;
export interface Evaluated {
props?: EvaluatedProperties;
items?: EvaluatedItems;
dynamicProps: boolean;
dynamicItems: boolean;
}
export interface AsyncValidateFunction<T = unknown> extends ValidateFunction<T> {
(...args: Parameters<ValidateFunction<T>>): Promise<T>;
$async: true;
}
export type AnyValidateFunction<T = any> = ValidateFunction<T> | AsyncValidateFunction<T>;
export interface ErrorObject<K extends string = string, P = Record<string, any>, S = unknown> {
keyword: K;
instancePath: string;
schemaPath: string;
params: P;
propertyName?: string;
message?: string;
schema?: S;
parentSchema?: AnySchemaObject;
data?: unknown;
}
export type ErrorNoParams<K extends string, S = unknown> = ErrorObject<K, Record<string, never>, S>;
interface _KeywordDef {
keyword: string | string[];
type?: JSONType | JSONType[];
schemaType?: JSONType | JSONType[];
allowUndefined?: boolean;
$data?: boolean;
implements?: string[];
before?: string;
post?: boolean;
metaSchema?: AnySchemaObject;
validateSchema?: AnyValidateFunction;
dependencies?: string[];
error?: KeywordErrorDefinition;
$dataError?: KeywordErrorDefinition;
}
export interface CodeKeywordDefinition extends _KeywordDef {
code: (cxt: KeywordCxt, ruleType?: string) => void;
trackErrors?: boolean;
}
export type MacroKeywordFunc = (schema: any, parentSchema: AnySchemaObject, it: SchemaCxt) => AnySchema;
export type CompileKeywordFunc = (schema: any, parentSchema: AnySchemaObject, it: SchemaObjCxt) => DataValidateFunction;
export interface DataValidateFunction {
(...args: Parameters<ValidateFunction>): boolean | Promise<any>;
errors?: Partial<ErrorObject>[];
}
export interface SchemaValidateFunction {
(schema: any, data: any, parentSchema?: AnySchemaObject, dataCxt?: DataValidationCxt): boolean | Promise<any>;
errors?: Partial<ErrorObject>[];
}
export interface FuncKeywordDefinition extends _KeywordDef {
validate?: SchemaValidateFunction | DataValidateFunction;
compile?: CompileKeywordFunc;
schema?: boolean;
modifying?: boolean;
async?: boolean;
valid?: boolean;
errors?: boolean | "full";
}
export interface MacroKeywordDefinition extends FuncKeywordDefinition {
macro: MacroKeywordFunc;
}
export type KeywordDefinition = CodeKeywordDefinition | FuncKeywordDefinition | MacroKeywordDefinition;
export type AddedKeywordDefinition = KeywordDefinition & {
type: JSONType[];
schemaType: JSONType[];
};
export interface KeywordErrorDefinition {
message: string | Code | ((cxt: KeywordErrorCxt) => string | Code);
params?: Code | ((cxt: KeywordErrorCxt) => Code);
}
export type Vocabulary = (KeywordDefinition | string)[];
export interface KeywordErrorCxt {
gen: CodeGen;
keyword: string;
data: Name;
$data?: string | false;
schema: any;
parentSchema?: AnySchemaObject;
schemaCode: Code | number | boolean;
schemaValue: Code | number | boolean;
schemaType?: JSONType[];
errsCount?: Name;
params: KeywordCxtParams;
it: SchemaCxt;
}
export type KeywordCxtParams = {
[P in string]?: Code | string | number;
};
export type FormatValidator<T extends string | number> = (data: T) => boolean;
export type FormatCompare<T extends string | number> = (data1: T, data2: T) => number | undefined;
export type AsyncFormatValidator<T extends string | number> = (data: T) => Promise<boolean>;
export interface FormatDefinition<T extends string | number> {
type?: T extends string ? "string" | undefined : "number";
validate: FormatValidator<T> | (T extends string ? string | RegExp : never);
async?: false | undefined;
compare?: FormatCompare<T>;
}
export interface AsyncFormatDefinition<T extends string | number> {
type?: T extends string ? "string" | undefined : "number";
validate: AsyncFormatValidator<T>;
async: true;
compare?: FormatCompare<T>;
}
export type AddedFormat = true | RegExp | FormatValidator<string> | FormatDefinition<string> | FormatDefinition<number> | AsyncFormatDefinition<string> | AsyncFormatDefinition<number>;
export type Format = AddedFormat | string;
export interface RegExpEngine {
(pattern: string, u: string): RegExpLike;
code: string;
}
export interface RegExpLike {
test: (s: string) => boolean;
}
export interface UriResolver {
parse(uri: string): URIComponent;
resolve(base: string, path: string): string;
serialize(component: URIComponent): string;
}
export {};
+3
View File
@@ -0,0 +1,3 @@
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
//# sourceMappingURL=index.js.map
+1
View File
@@ -0,0 +1 @@
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../lib/types/index.ts"],"names":[],"mappings":""}
+125
View File
@@ -0,0 +1,125 @@
type StrictNullChecksWrapper<Name extends string, Type> = undefined extends null ? `strictNullChecks must be true in tsconfig to use ${Name}` : Type;
type UnionToIntersection<U> = (U extends any ? (_: U) => void : never) extends (_: infer I) => void ? I : never;
export type SomeJSONSchema = UncheckedJSONSchemaType<Known, true>;
type UncheckedPartialSchema<T> = Partial<UncheckedJSONSchemaType<T, true>>;
export type PartialSchema<T> = StrictNullChecksWrapper<"PartialSchema", UncheckedPartialSchema<T>>;
type JSONType<T extends string, IsPartial extends boolean> = IsPartial extends true ? T | undefined : T;
interface NumberKeywords {
minimum?: number;
maximum?: number;
exclusiveMinimum?: number;
exclusiveMaximum?: number;
multipleOf?: number;
format?: string;
}
interface StringKeywords {
minLength?: number;
maxLength?: number;
pattern?: string;
format?: string;
}
type UncheckedJSONSchemaType<T, IsPartial extends boolean> = (// these two unions allow arbitrary unions of types
{
anyOf: readonly UncheckedJSONSchemaType<T, IsPartial>[];
} | {
oneOf: readonly UncheckedJSONSchemaType<T, IsPartial>[];
} | ({
type: readonly (T extends number ? JSONType<"number" | "integer", IsPartial> : T extends string ? JSONType<"string", IsPartial> : T extends boolean ? JSONType<"boolean", IsPartial> : never)[];
} & UnionToIntersection<T extends number ? NumberKeywords : T extends string ? StringKeywords : T extends boolean ? {} : never>) | ((T extends number ? {
type: JSONType<"number" | "integer", IsPartial>;
} & NumberKeywords : T extends string ? {
type: JSONType<"string", IsPartial>;
} & StringKeywords : T extends boolean ? {
type: JSONType<"boolean", IsPartial>;
} : T extends readonly [any, ...any[]] ? {
type: JSONType<"array", IsPartial>;
items: {
readonly [K in keyof T]-?: UncheckedJSONSchemaType<T[K], false> & Nullable<T[K]>;
} & {
length: T["length"];
};
minItems: T["length"];
} & ({
maxItems: T["length"];
} | {
additionalItems: false;
}) : T extends readonly any[] ? {
type: JSONType<"array", IsPartial>;
items: UncheckedJSONSchemaType<T[0], false>;
contains?: UncheckedPartialSchema<T[0]>;
minItems?: number;
maxItems?: number;
minContains?: number;
maxContains?: number;
uniqueItems?: true;
additionalItems?: never;
} : T extends Record<string, any> ? {
type: JSONType<"object", IsPartial>;
additionalProperties?: boolean | UncheckedJSONSchemaType<T[string], false>;
unevaluatedProperties?: boolean | UncheckedJSONSchemaType<T[string], false>;
properties?: IsPartial extends true ? Partial<UncheckedPropertiesSchema<T>> : UncheckedPropertiesSchema<T>;
patternProperties?: Record<string, UncheckedJSONSchemaType<T[string], false>>;
propertyNames?: Omit<UncheckedJSONSchemaType<string, false>, "type"> & {
type?: "string";
};
dependencies?: {
[K in keyof T]?: readonly (keyof T)[] | UncheckedPartialSchema<T>;
};
dependentRequired?: {
[K in keyof T]?: readonly (keyof T)[];
};
dependentSchemas?: {
[K in keyof T]?: UncheckedPartialSchema<T>;
};
minProperties?: number;
maxProperties?: number;
} & (IsPartial extends true ? {
required: readonly (keyof T)[];
} : [UncheckedRequiredMembers<T>] extends [never] ? {
required?: readonly UncheckedRequiredMembers<T>[];
} : {
required: readonly UncheckedRequiredMembers<T>[];
}) : T extends null ? {
type: JSONType<"null", IsPartial>;
nullable: true;
} : never) & {
allOf?: readonly UncheckedPartialSchema<T>[];
anyOf?: readonly UncheckedPartialSchema<T>[];
oneOf?: readonly UncheckedPartialSchema<T>[];
if?: UncheckedPartialSchema<T>;
then?: UncheckedPartialSchema<T>;
else?: UncheckedPartialSchema<T>;
not?: UncheckedPartialSchema<T>;
})) & {
[keyword: string]: any;
$id?: string;
$ref?: string;
$defs?: Record<string, UncheckedJSONSchemaType<Known, true>>;
definitions?: Record<string, UncheckedJSONSchemaType<Known, true>>;
};
export type JSONSchemaType<T> = StrictNullChecksWrapper<"JSONSchemaType", UncheckedJSONSchemaType<T, false>>;
type Known = {
[key: string]: Known;
} | [Known, ...Known[]] | Known[] | number | string | boolean | null;
type UncheckedPropertiesSchema<T> = {
[K in keyof T]-?: (UncheckedJSONSchemaType<T[K], false> & Nullable<T[K]>) | {
$ref: string;
};
};
export type PropertiesSchema<T> = StrictNullChecksWrapper<"PropertiesSchema", UncheckedPropertiesSchema<T>>;
type UncheckedRequiredMembers<T> = {
[K in keyof T]-?: undefined extends T[K] ? never : K;
}[keyof T];
export type RequiredMembers<T> = StrictNullChecksWrapper<"RequiredMembers", UncheckedRequiredMembers<T>>;
type Nullable<T> = undefined extends T ? {
nullable: true;
const?: null;
enum?: readonly (T | null)[];
default?: T | null;
} : {
nullable?: false;
const?: T;
enum?: readonly T[];
default?: T;
};
export {};
+3
View File
@@ -0,0 +1,3 @@
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
//# sourceMappingURL=json-schema.js.map
+1
View File
@@ -0,0 +1 @@
{"version":3,"file":"json-schema.js","sourceRoot":"","sources":["../../lib/types/json-schema.ts"],"names":[],"mappings":""}
+174
View File
@@ -0,0 +1,174 @@
/** numeric strings */
type NumberType = "float32" | "float64" | "int8" | "uint8" | "int16" | "uint16" | "int32" | "uint32";
/** string strings */
type StringType = "string" | "timestamp";
/** Generic JTD Schema without inference of the represented type */
export type SomeJTDSchemaType = (// ref
{
ref: string;
} | {
type: NumberType | StringType | "boolean";
} | {
enum: string[];
} | {
elements: SomeJTDSchemaType;
} | {
values: SomeJTDSchemaType;
} | {
properties: Record<string, SomeJTDSchemaType>;
optionalProperties?: Record<string, SomeJTDSchemaType>;
additionalProperties?: boolean;
} | {
properties?: Record<string, SomeJTDSchemaType>;
optionalProperties: Record<string, SomeJTDSchemaType>;
additionalProperties?: boolean;
} | {
discriminator: string;
mapping: Record<string, SomeJTDSchemaType>;
} | {}) & {
nullable?: boolean;
metadata?: Record<string, unknown>;
definitions?: Record<string, SomeJTDSchemaType>;
};
/** required keys of an object, not undefined */
type RequiredKeys<T> = {
[K in keyof T]-?: undefined extends T[K] ? never : K;
}[keyof T];
/** optional or undifined-able keys of an object */
type OptionalKeys<T> = {
[K in keyof T]-?: undefined extends T[K] ? K : never;
}[keyof T];
/** type is true if T is a union type */
type IsUnion_<T, U extends T = T> = false extends (T extends unknown ? ([U] extends [T] ? false : true) : never) ? false : true;
type IsUnion<T> = IsUnion_<T>;
/** type is true if T is identically E */
type TypeEquality<T, E> = [T] extends [E] ? ([E] extends [T] ? true : false) : false;
/** type is true if T or null is identically E or null*/
type NullTypeEquality<T, E> = TypeEquality<T | null, E | null>;
/** gets only the string literals of a type or null if a type isn't a string literal */
type EnumString<T> = [T] extends [never] ? null : T extends string ? string extends T ? null : T : null;
/** true if type is a union of string literals */
type IsEnum<T> = null extends EnumString<T> ? false : true;
/** true only if all types are array types (not tuples) */
type IsElements<T> = false extends IsUnion<T> ? [T] extends [readonly unknown[]] ? undefined extends T[0.5] ? false : true : false : false;
/** true if the the type is a values type */
type IsValues<T> = false extends IsUnion<T> ? TypeEquality<keyof T, string> : false;
/** true if type is a properties type and Union is false, or type is a discriminator type and Union is true */
type IsRecord<T, Union extends boolean> = Union extends IsUnion<T> ? null extends EnumString<keyof T> ? false : true : false;
/** true if type represents an empty record */
type IsEmptyRecord<T> = [T] extends [Record<string, never>] ? [T] extends [never] ? false : true : false;
/** actual schema */
export type JTDSchemaType<T, D extends Record<string, unknown> = Record<string, never>> = (// refs - where null wasn't specified, must match exactly
(null extends EnumString<keyof D> ? never : ({
[K in keyof D]: [T] extends [D[K]] ? {
ref: K;
} : never;
}[keyof D] & {
nullable?: false;
}) | (null extends T ? {
[K in keyof D]: [Exclude<T, null>] extends [Exclude<D[K], null>] ? {
ref: K;
} : never;
}[keyof D] & {
nullable: true;
} : never)) | (unknown extends T ? {
nullable?: boolean;
} : never) | ((true extends NullTypeEquality<T, number> ? {
type: NumberType;
} : true extends NullTypeEquality<T, boolean> ? {
type: "boolean";
} : true extends NullTypeEquality<T, string> ? {
type: StringType;
} : true extends NullTypeEquality<T, Date> ? {
type: "timestamp";
} : true extends IsEnum<Exclude<T, null>> ? {
enum: EnumString<Exclude<T, null>>[];
} : true extends IsElements<Exclude<T, null>> ? T extends readonly (infer E)[] ? {
elements: JTDSchemaType<E, D>;
} : never : true extends IsEmptyRecord<Exclude<T, null>> ? {
properties: Record<string, never>;
optionalProperties?: Record<string, never>;
} | {
optionalProperties: Record<string, never>;
} : true extends IsValues<Exclude<T, null>> ? T extends Record<string, infer V> ? {
values: JTDSchemaType<V, D>;
} : never : true extends IsRecord<Exclude<T, null>, false> ? ([RequiredKeys<Exclude<T, null>>] extends [never] ? {
properties?: Record<string, never>;
} : {
properties: {
[K in RequiredKeys<T>]: JTDSchemaType<T[K], D>;
};
}) & ([OptionalKeys<Exclude<T, null>>] extends [never] ? {
optionalProperties?: Record<string, never>;
} : {
optionalProperties: {
[K in OptionalKeys<T>]: JTDSchemaType<Exclude<T[K], undefined>, D>;
};
}) & {
additionalProperties?: boolean;
} : true extends IsRecord<Exclude<T, null>, true> ? {
[K in keyof Exclude<T, null>]-?: Exclude<T, null>[K] extends string ? {
discriminator: K;
mapping: {
[M in Exclude<T, null>[K]]: JTDSchemaType<Omit<T extends Record<K, M> ? T : never, K>, D>;
};
} : never;
}[keyof Exclude<T, null>] : never) & (null extends T ? {
nullable: true;
} : {
nullable?: false;
}))) & {
metadata?: Record<string, unknown>;
definitions?: {
[K in keyof D]: JTDSchemaType<D[K], D>;
};
};
type JTDDataDef<S, D extends Record<string, unknown>> = // ref
(S extends {
ref: string;
} ? D extends {
[K in S["ref"]]: infer V;
} ? JTDDataDef<V, D> : never : S extends {
type: NumberType;
} ? number : S extends {
type: "boolean";
} ? boolean : S extends {
type: "string";
} ? string : S extends {
type: "timestamp";
} ? string | Date : S extends {
enum: readonly (infer E)[];
} ? string extends E ? never : [E] extends [string] ? E : never : S extends {
elements: infer E;
} ? JTDDataDef<E, D>[] : S extends {
properties: Record<string, unknown>;
optionalProperties?: Record<string, unknown>;
additionalProperties?: boolean;
} ? {
-readonly [K in keyof S["properties"]]-?: JTDDataDef<S["properties"][K], D>;
} & {
-readonly [K in keyof S["optionalProperties"]]+?: JTDDataDef<S["optionalProperties"][K], D>;
} & ([S["additionalProperties"]] extends [true] ? Record<string, unknown> : unknown) : S extends {
properties?: Record<string, unknown>;
optionalProperties: Record<string, unknown>;
additionalProperties?: boolean;
} ? {
-readonly [K in keyof S["properties"]]-?: JTDDataDef<S["properties"][K], D>;
} & {
-readonly [K in keyof S["optionalProperties"]]+?: JTDDataDef<S["optionalProperties"][K], D>;
} & ([S["additionalProperties"]] extends [true] ? Record<string, unknown> : unknown) : S extends {
values: infer V;
} ? Record<string, JTDDataDef<V, D>> : S extends {
discriminator: infer M;
mapping: Record<string, unknown>;
} ? [M] extends [string] ? {
[K in keyof S["mapping"]]: JTDDataDef<S["mapping"][K], D> & {
[KM in M]: K;
};
}[keyof S["mapping"]] : never : unknown) | (S extends {
nullable: true;
} ? null : never);
export type JTDDataType<S> = S extends {
definitions: Record<string, unknown>;
} ? JTDDataDef<S, S["definitions"]> : JTDDataDef<S, Record<string, never>>;
export {};