langchain 0.0.194 → 0.0.196
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/agents/toolkits/conversational_retrieval/token_buffer_memory.d.ts +1 -1
- package/dist/base_language/count_tokens.cjs +5 -70
- package/dist/base_language/count_tokens.d.ts +1 -10
- package/dist/base_language/count_tokens.js +1 -65
- package/dist/base_language/index.cjs +6 -196
- package/dist/base_language/index.d.ts +1 -111
- package/dist/base_language/index.js +1 -191
- package/dist/cache/base.cjs +15 -37
- package/dist/cache/base.d.ts +1 -20
- package/dist/cache/base.js +1 -33
- package/dist/cache/index.cjs +2 -46
- package/dist/cache/index.d.ts +1 -29
- package/dist/cache/index.js +1 -45
- package/dist/callbacks/base.cjs +3 -139
- package/dist/callbacks/base.d.ts +1 -266
- package/dist/callbacks/base.js +1 -126
- package/dist/callbacks/handlers/console.cjs +14 -221
- package/dist/callbacks/handlers/console.d.ts +1 -117
- package/dist/callbacks/handlers/console.js +1 -217
- package/dist/callbacks/handlers/initialize.cjs +15 -30
- package/dist/callbacks/handlers/initialize.d.ts +1 -16
- package/dist/callbacks/handlers/initialize.js +1 -27
- package/dist/callbacks/handlers/log_stream.cjs +15 -293
- package/dist/callbacks/handlers/log_stream.d.ts +1 -100
- package/dist/callbacks/handlers/log_stream.js +1 -289
- package/dist/callbacks/handlers/run_collector.cjs +15 -48
- package/dist/callbacks/handlers/run_collector.d.ts +1 -26
- package/dist/callbacks/handlers/run_collector.js +1 -46
- package/dist/callbacks/handlers/tracer.cjs +15 -375
- package/dist/callbacks/handlers/tracer.d.ts +1 -70
- package/dist/callbacks/handlers/tracer.js +1 -373
- package/dist/callbacks/handlers/tracer_langchain.cjs +15 -104
- package/dist/callbacks/handlers/tracer_langchain.d.ts +1 -41
- package/dist/callbacks/handlers/tracer_langchain.js +1 -102
- package/dist/callbacks/handlers/tracer_langchain_v1.cjs +15 -197
- package/dist/callbacks/handlers/tracer_langchain_v1.d.ts +1 -57
- package/dist/callbacks/handlers/tracer_langchain_v1.js +1 -195
- package/dist/callbacks/manager.cjs +15 -676
- package/dist/callbacks/manager.d.ts +1 -180
- package/dist/callbacks/manager.js +1 -666
- package/dist/callbacks/promises.cjs +14 -42
- package/dist/callbacks/promises.d.ts +1 -11
- package/dist/callbacks/promises.js +1 -37
- package/dist/chains/graph_qa/prompts.d.ts +1 -1
- package/dist/chains/openai_functions/structured_output.cjs +2 -2
- package/dist/chains/openai_functions/structured_output.d.ts +1 -1
- package/dist/chains/openai_functions/structured_output.js +1 -1
- package/dist/chat_models/baiduwenxin.d.ts +1 -1
- package/dist/chat_models/base.cjs +15 -296
- package/dist/chat_models/base.d.ts +1 -122
- package/dist/chat_models/base.js +1 -292
- package/dist/chat_models/bedrock/web.d.ts +1 -1
- package/dist/chat_models/fireworks.d.ts +1 -1
- package/dist/document.cjs +2 -24
- package/dist/document.d.ts +1 -12
- package/dist/document.js +1 -23
- package/dist/document_loaders/web/azure_blob_storage_file.d.ts +1 -1
- package/dist/document_loaders/web/s3.d.ts +1 -1
- package/dist/embeddings/base.cjs +15 -22
- package/dist/embeddings/base.d.ts +1 -33
- package/dist/embeddings/base.js +1 -20
- package/dist/embeddings/cache_backed.cjs +2 -2
- package/dist/embeddings/cache_backed.js +1 -1
- package/dist/embeddings/hf.cjs +1 -2
- package/dist/embeddings/hf.js +1 -2
- package/dist/evaluation/agents/trajectory.d.ts +1 -1
- package/dist/evaluation/criteria/prompt.d.ts +2 -2
- package/dist/evaluation/qa/prompt.d.ts +2 -2
- package/dist/experimental/hubs/makersuite/googlemakersuitehub.d.ts +1 -1
- package/dist/experimental/openai_assistant/index.cjs +2 -1
- package/dist/experimental/openai_assistant/index.d.ts +2 -1
- package/dist/experimental/openai_assistant/index.js +2 -1
- package/dist/experimental/openai_files/index.cjs +88 -0
- package/dist/experimental/openai_files/index.d.ts +79 -0
- package/dist/experimental/openai_files/index.js +84 -0
- package/dist/experimental/plan_and_execute/prompt.d.ts +1 -1
- package/dist/llms/base.cjs +15 -278
- package/dist/llms/base.d.ts +1 -115
- package/dist/llms/base.js +1 -275
- package/dist/llms/bedrock/web.d.ts +1 -1
- package/dist/llms/fireworks.d.ts +1 -1
- package/dist/load/import_constants.cjs +1 -0
- package/dist/load/import_constants.js +1 -0
- package/dist/load/import_map.cjs +4 -2
- package/dist/load/import_map.d.ts +2 -0
- package/dist/load/import_map.js +2 -0
- package/dist/load/index.cjs +7 -148
- package/dist/load/index.js +7 -148
- package/dist/load/map_keys.cjs +0 -24
- package/dist/load/map_keys.d.ts +0 -6
- package/dist/load/map_keys.js +1 -17
- package/dist/load/serializable.cjs +15 -178
- package/dist/load/serializable.d.ts +1 -66
- package/dist/load/serializable.js +1 -175
- package/dist/memory/base.cjs +17 -92
- package/dist/memory/base.d.ts +2 -68
- package/dist/memory/base.js +2 -87
- package/dist/output_parsers/openai_functions.cjs +2 -2
- package/dist/output_parsers/openai_functions.d.ts +1 -1
- package/dist/output_parsers/openai_functions.js +1 -1
- package/dist/output_parsers/regex.d.ts +1 -1
- package/dist/output_parsers/structured.d.ts +1 -1
- package/dist/prompts/base.cjs +8 -183
- package/dist/prompts/base.d.ts +3 -132
- package/dist/prompts/base.js +3 -178
- package/dist/prompts/chat.cjs +15 -477
- package/dist/prompts/chat.d.ts +1 -219
- package/dist/prompts/chat.js +1 -466
- package/dist/prompts/few_shot.cjs +15 -353
- package/dist/prompts/few_shot.d.ts +1 -192
- package/dist/prompts/few_shot.js +1 -350
- package/dist/prompts/index.cjs +3 -2
- package/dist/prompts/index.d.ts +2 -1
- package/dist/prompts/index.js +2 -1
- package/dist/prompts/pipeline.cjs +15 -142
- package/dist/prompts/pipeline.d.ts +1 -98
- package/dist/prompts/pipeline.js +1 -140
- package/dist/prompts/prompt.cjs +15 -146
- package/dist/prompts/prompt.d.ts +1 -92
- package/dist/prompts/prompt.js +1 -144
- package/dist/prompts/selectors/LengthBasedExampleSelector.cjs +15 -148
- package/dist/prompts/selectors/LengthBasedExampleSelector.d.ts +1 -89
- package/dist/prompts/selectors/LengthBasedExampleSelector.js +1 -146
- package/dist/prompts/selectors/SemanticSimilarityExampleSelector.cjs +15 -137
- package/dist/prompts/selectors/SemanticSimilarityExampleSelector.d.ts +1 -91
- package/dist/prompts/selectors/SemanticSimilarityExampleSelector.js +1 -135
- package/dist/prompts/selectors/conditional.cjs +15 -74
- package/dist/prompts/selectors/conditional.d.ts +1 -63
- package/dist/prompts/selectors/conditional.js +1 -69
- package/dist/prompts/serde.cjs +15 -0
- package/dist/prompts/serde.d.ts +1 -43
- package/dist/prompts/serde.js +1 -1
- package/dist/prompts/template.cjs +14 -88
- package/dist/prompts/template.d.ts +1 -36
- package/dist/prompts/template.js +1 -83
- package/dist/retrievers/chaindesk.cjs +9 -1
- package/dist/retrievers/chaindesk.d.ts +3 -1
- package/dist/retrievers/chaindesk.js +9 -1
- package/dist/retrievers/self_query/vectara.cjs +138 -0
- package/dist/retrievers/self_query/vectara.d.ts +41 -0
- package/dist/retrievers/self_query/vectara.js +134 -0
- package/dist/{util/@cfworker/json-schema → runnables}/index.cjs +1 -1
- package/dist/runnables/index.d.ts +1 -0
- package/dist/runnables/index.js +1 -0
- package/dist/schema/document.cjs +3 -34
- package/dist/schema/document.d.ts +2 -29
- package/dist/schema/document.js +2 -32
- package/dist/schema/index.cjs +37 -612
- package/dist/schema/index.d.ts +11 -311
- package/dist/schema/index.js +8 -583
- package/dist/schema/output_parser.cjs +15 -309
- package/dist/schema/output_parser.d.ts +1 -173
- package/dist/schema/output_parser.js +1 -301
- package/dist/schema/retriever.cjs +15 -77
- package/dist/schema/retriever.d.ts +1 -43
- package/dist/schema/retriever.js +1 -75
- package/dist/schema/runnable/base.cjs +10 -1072
- package/dist/schema/runnable/base.d.ts +1 -356
- package/dist/schema/runnable/base.js +1 -1060
- package/dist/schema/runnable/branch.cjs +2 -131
- package/dist/schema/runnable/branch.d.ts +1 -94
- package/dist/schema/runnable/branch.js +1 -130
- package/dist/schema/runnable/config.cjs +0 -6
- package/dist/schema/runnable/config.d.ts +1 -3
- package/dist/schema/runnable/config.js +1 -4
- package/dist/schema/runnable/index.cjs +15 -16
- package/dist/schema/runnable/index.d.ts +1 -5
- package/dist/schema/runnable/index.js +1 -4
- package/dist/schema/runnable/passthrough.cjs +3 -113
- package/dist/schema/runnable/passthrough.d.ts +1 -72
- package/dist/schema/runnable/passthrough.js +1 -111
- package/dist/schema/runnable/router.cjs +2 -71
- package/dist/schema/runnable/router.d.ts +1 -29
- package/dist/schema/runnable/router.js +1 -70
- package/dist/schema/storage.cjs +15 -8
- package/dist/schema/storage.d.ts +1 -57
- package/dist/schema/storage.js +1 -6
- package/dist/tools/bingserpapi.d.ts +1 -1
- package/dist/tools/searchapi.d.ts +1 -1
- package/dist/tools/serpapi.d.ts +1 -1
- package/dist/tools/serper.d.ts +1 -1
- package/dist/util/async_caller.cjs +14 -128
- package/dist/util/async_caller.d.ts +1 -45
- package/dist/util/async_caller.js +1 -124
- package/dist/vectorstores/vectara.cjs +77 -7
- package/dist/vectorstores/vectara.d.ts +9 -3
- package/dist/vectorstores/vectara.js +54 -7
- package/experimental/openai_files.cjs +1 -0
- package/experimental/openai_files.d.ts +1 -0
- package/experimental/openai_files.js +1 -0
- package/package.json +27 -5
- package/retrievers/self_query/vectara.cjs +1 -0
- package/retrievers/self_query/vectara.d.ts +1 -0
- package/retrievers/self_query/vectara.js +1 -0
- package/runnables.cjs +1 -0
- package/runnables.d.ts +1 -0
- package/runnables.js +1 -0
- package/dist/util/@cfworker/json-schema/index.d.ts +0 -1
- package/dist/util/@cfworker/json-schema/index.js +0 -1
- package/dist/util/@cfworker/json-schema/src/deep-compare-strict.cjs +0 -43
- package/dist/util/@cfworker/json-schema/src/deep-compare-strict.d.ts +0 -1
- package/dist/util/@cfworker/json-schema/src/deep-compare-strict.js +0 -39
- package/dist/util/@cfworker/json-schema/src/dereference.cjs +0 -169
- package/dist/util/@cfworker/json-schema/src/dereference.d.ts +0 -12
- package/dist/util/@cfworker/json-schema/src/dereference.js +0 -165
- package/dist/util/@cfworker/json-schema/src/format.cjs +0 -139
- package/dist/util/@cfworker/json-schema/src/format.d.ts +0 -2
- package/dist/util/@cfworker/json-schema/src/format.js +0 -136
- package/dist/util/@cfworker/json-schema/src/index.cjs +0 -24
- package/dist/util/@cfworker/json-schema/src/index.d.ts +0 -8
- package/dist/util/@cfworker/json-schema/src/index.js +0 -8
- package/dist/util/@cfworker/json-schema/src/pointer.cjs +0 -11
- package/dist/util/@cfworker/json-schema/src/pointer.d.ts +0 -2
- package/dist/util/@cfworker/json-schema/src/pointer.js +0 -6
- package/dist/util/@cfworker/json-schema/src/types.cjs +0 -2
- package/dist/util/@cfworker/json-schema/src/types.d.ts +0 -72
- package/dist/util/@cfworker/json-schema/src/types.js +0 -1
- package/dist/util/@cfworker/json-schema/src/ucs2-length.cjs +0 -28
- package/dist/util/@cfworker/json-schema/src/ucs2-length.d.ts +0 -6
- package/dist/util/@cfworker/json-schema/src/ucs2-length.js +0 -24
- package/dist/util/@cfworker/json-schema/src/validate.cjs +0 -808
- package/dist/util/@cfworker/json-schema/src/validate.d.ts +0 -3
- package/dist/util/@cfworker/json-schema/src/validate.js +0 -804
- package/dist/util/@cfworker/json-schema/src/validator.cjs +0 -44
- package/dist/util/@cfworker/json-schema/src/validator.d.ts +0 -10
- package/dist/util/@cfworker/json-schema/src/validator.js +0 -40
- package/dist/util/fast-json-patch/index.cjs +0 -49
- package/dist/util/fast-json-patch/index.d.ts +0 -22
- package/dist/util/fast-json-patch/index.js +0 -16
- package/dist/util/fast-json-patch/src/core.cjs +0 -469
- package/dist/util/fast-json-patch/src/core.d.ts +0 -111
- package/dist/util/fast-json-patch/src/core.js +0 -459
- package/dist/util/fast-json-patch/src/duplex.cjs +0 -237
- package/dist/util/fast-json-patch/src/duplex.d.ts +0 -23
- package/dist/util/fast-json-patch/src/duplex.js +0 -230
- package/dist/util/fast-json-patch/src/helpers.cjs +0 -194
- package/dist/util/fast-json-patch/src/helpers.d.ts +0 -36
- package/dist/util/fast-json-patch/src/helpers.js +0 -181
- package/dist/util/js-sha1/hash.cjs +0 -358
- package/dist/util/js-sha1/hash.d.ts +0 -1
- package/dist/util/js-sha1/hash.js +0 -355
|
@@ -1,804 +0,0 @@
|
|
|
1
|
-
import { deepCompareStrict } from "./deep-compare-strict.js";
|
|
2
|
-
import { dereference } from "./dereference.js";
|
|
3
|
-
import { fastFormat } from "./format.js";
|
|
4
|
-
import { encodePointer } from "./pointer.js";
|
|
5
|
-
import { ucs2length } from "./ucs2-length.js";
|
|
6
|
-
export function validate(instance, schema, draft = "2019-09", lookup = dereference(schema), shortCircuit = true, recursiveAnchor = null, instanceLocation = "#", schemaLocation = "#", evaluated = Object.create(null)) {
|
|
7
|
-
if (schema === true) {
|
|
8
|
-
return { valid: true, errors: [] };
|
|
9
|
-
}
|
|
10
|
-
if (schema === false) {
|
|
11
|
-
return {
|
|
12
|
-
valid: false,
|
|
13
|
-
errors: [
|
|
14
|
-
{
|
|
15
|
-
instanceLocation,
|
|
16
|
-
keyword: "false",
|
|
17
|
-
keywordLocation: instanceLocation,
|
|
18
|
-
error: "False boolean schema.",
|
|
19
|
-
},
|
|
20
|
-
],
|
|
21
|
-
};
|
|
22
|
-
}
|
|
23
|
-
const rawInstanceType = typeof instance;
|
|
24
|
-
let instanceType;
|
|
25
|
-
switch (rawInstanceType) {
|
|
26
|
-
case "boolean":
|
|
27
|
-
case "number":
|
|
28
|
-
case "string":
|
|
29
|
-
instanceType = rawInstanceType;
|
|
30
|
-
break;
|
|
31
|
-
case "object":
|
|
32
|
-
if (instance === null) {
|
|
33
|
-
instanceType = "null";
|
|
34
|
-
}
|
|
35
|
-
else if (Array.isArray(instance)) {
|
|
36
|
-
instanceType = "array";
|
|
37
|
-
}
|
|
38
|
-
else {
|
|
39
|
-
instanceType = "object";
|
|
40
|
-
}
|
|
41
|
-
break;
|
|
42
|
-
default:
|
|
43
|
-
// undefined, bigint, function, symbol
|
|
44
|
-
throw new Error(`Instances of "${rawInstanceType}" type are not supported.`);
|
|
45
|
-
}
|
|
46
|
-
const { $ref, $recursiveRef, $recursiveAnchor, type: $type, const: $const, enum: $enum, required: $required, not: $not, anyOf: $anyOf, allOf: $allOf, oneOf: $oneOf, if: $if, then: $then, else: $else, format: $format, properties: $properties, patternProperties: $patternProperties, additionalProperties: $additionalProperties, unevaluatedProperties: $unevaluatedProperties, minProperties: $minProperties, maxProperties: $maxProperties, propertyNames: $propertyNames, dependentRequired: $dependentRequired, dependentSchemas: $dependentSchemas, dependencies: $dependencies, prefixItems: $prefixItems, items: $items, additionalItems: $additionalItems, unevaluatedItems: $unevaluatedItems, contains: $contains, minContains: $minContains, maxContains: $maxContains, minItems: $minItems, maxItems: $maxItems, uniqueItems: $uniqueItems, minimum: $minimum, maximum: $maximum, exclusiveMinimum: $exclusiveMinimum, exclusiveMaximum: $exclusiveMaximum, multipleOf: $multipleOf, minLength: $minLength, maxLength: $maxLength, pattern: $pattern, __absolute_ref__, __absolute_recursive_ref__, } = schema;
|
|
47
|
-
const errors = [];
|
|
48
|
-
if ($recursiveAnchor === true && recursiveAnchor === null) {
|
|
49
|
-
recursiveAnchor = schema;
|
|
50
|
-
}
|
|
51
|
-
if ($recursiveRef === "#") {
|
|
52
|
-
const refSchema = recursiveAnchor === null
|
|
53
|
-
? lookup[__absolute_recursive_ref__]
|
|
54
|
-
: recursiveAnchor;
|
|
55
|
-
const keywordLocation = `${schemaLocation}/$recursiveRef`;
|
|
56
|
-
const result = validate(instance, recursiveAnchor === null ? schema : recursiveAnchor, draft, lookup, shortCircuit, refSchema, instanceLocation, keywordLocation, evaluated);
|
|
57
|
-
if (!result.valid) {
|
|
58
|
-
errors.push({
|
|
59
|
-
instanceLocation,
|
|
60
|
-
keyword: "$recursiveRef",
|
|
61
|
-
keywordLocation,
|
|
62
|
-
error: "A subschema had errors.",
|
|
63
|
-
}, ...result.errors);
|
|
64
|
-
}
|
|
65
|
-
}
|
|
66
|
-
if ($ref !== undefined) {
|
|
67
|
-
const uri = __absolute_ref__ || $ref;
|
|
68
|
-
const refSchema = lookup[uri];
|
|
69
|
-
if (refSchema === undefined) {
|
|
70
|
-
let message = `Unresolved $ref "${$ref}".`;
|
|
71
|
-
if (__absolute_ref__ && __absolute_ref__ !== $ref) {
|
|
72
|
-
message += ` Absolute URI "${__absolute_ref__}".`;
|
|
73
|
-
}
|
|
74
|
-
message += `\nKnown schemas:\n- ${Object.keys(lookup).join("\n- ")}`;
|
|
75
|
-
throw new Error(message);
|
|
76
|
-
}
|
|
77
|
-
const keywordLocation = `${schemaLocation}/$ref`;
|
|
78
|
-
const result = validate(instance, refSchema, draft, lookup, shortCircuit, recursiveAnchor, instanceLocation, keywordLocation, evaluated);
|
|
79
|
-
if (!result.valid) {
|
|
80
|
-
errors.push({
|
|
81
|
-
instanceLocation,
|
|
82
|
-
keyword: "$ref",
|
|
83
|
-
keywordLocation,
|
|
84
|
-
error: "A subschema had errors.",
|
|
85
|
-
}, ...result.errors);
|
|
86
|
-
}
|
|
87
|
-
if (draft === "4" || draft === "7") {
|
|
88
|
-
return { valid: errors.length === 0, errors };
|
|
89
|
-
}
|
|
90
|
-
}
|
|
91
|
-
if (Array.isArray($type)) {
|
|
92
|
-
let length = $type.length;
|
|
93
|
-
let valid = false;
|
|
94
|
-
for (let i = 0; i < length; i++) {
|
|
95
|
-
if (instanceType === $type[i] ||
|
|
96
|
-
($type[i] === "integer" &&
|
|
97
|
-
instanceType === "number" &&
|
|
98
|
-
instance % 1 === 0 &&
|
|
99
|
-
instance === instance)) {
|
|
100
|
-
valid = true;
|
|
101
|
-
break;
|
|
102
|
-
}
|
|
103
|
-
}
|
|
104
|
-
if (!valid) {
|
|
105
|
-
errors.push({
|
|
106
|
-
instanceLocation,
|
|
107
|
-
keyword: "type",
|
|
108
|
-
keywordLocation: `${schemaLocation}/type`,
|
|
109
|
-
error: `Instance type "${instanceType}" is invalid. Expected "${$type.join('", "')}".`,
|
|
110
|
-
});
|
|
111
|
-
}
|
|
112
|
-
}
|
|
113
|
-
else if ($type === "integer") {
|
|
114
|
-
if (instanceType !== "number" || instance % 1 || instance !== instance) {
|
|
115
|
-
errors.push({
|
|
116
|
-
instanceLocation,
|
|
117
|
-
keyword: "type",
|
|
118
|
-
keywordLocation: `${schemaLocation}/type`,
|
|
119
|
-
error: `Instance type "${instanceType}" is invalid. Expected "${$type}".`,
|
|
120
|
-
});
|
|
121
|
-
}
|
|
122
|
-
}
|
|
123
|
-
else if ($type !== undefined && instanceType !== $type) {
|
|
124
|
-
errors.push({
|
|
125
|
-
instanceLocation,
|
|
126
|
-
keyword: "type",
|
|
127
|
-
keywordLocation: `${schemaLocation}/type`,
|
|
128
|
-
error: `Instance type "${instanceType}" is invalid. Expected "${$type}".`,
|
|
129
|
-
});
|
|
130
|
-
}
|
|
131
|
-
if ($const !== undefined) {
|
|
132
|
-
if (instanceType === "object" || instanceType === "array") {
|
|
133
|
-
if (!deepCompareStrict(instance, $const)) {
|
|
134
|
-
errors.push({
|
|
135
|
-
instanceLocation,
|
|
136
|
-
keyword: "const",
|
|
137
|
-
keywordLocation: `${schemaLocation}/const`,
|
|
138
|
-
error: `Instance does not match ${JSON.stringify($const)}.`,
|
|
139
|
-
});
|
|
140
|
-
}
|
|
141
|
-
}
|
|
142
|
-
else if (instance !== $const) {
|
|
143
|
-
errors.push({
|
|
144
|
-
instanceLocation,
|
|
145
|
-
keyword: "const",
|
|
146
|
-
keywordLocation: `${schemaLocation}/const`,
|
|
147
|
-
error: `Instance does not match ${JSON.stringify($const)}.`,
|
|
148
|
-
});
|
|
149
|
-
}
|
|
150
|
-
}
|
|
151
|
-
if ($enum !== undefined) {
|
|
152
|
-
if (instanceType === "object" || instanceType === "array") {
|
|
153
|
-
if (!$enum.some((value) => deepCompareStrict(instance, value))) {
|
|
154
|
-
errors.push({
|
|
155
|
-
instanceLocation,
|
|
156
|
-
keyword: "enum",
|
|
157
|
-
keywordLocation: `${schemaLocation}/enum`,
|
|
158
|
-
error: `Instance does not match any of ${JSON.stringify($enum)}.`,
|
|
159
|
-
});
|
|
160
|
-
}
|
|
161
|
-
}
|
|
162
|
-
else if (!$enum.some((value) => instance === value)) {
|
|
163
|
-
errors.push({
|
|
164
|
-
instanceLocation,
|
|
165
|
-
keyword: "enum",
|
|
166
|
-
keywordLocation: `${schemaLocation}/enum`,
|
|
167
|
-
error: `Instance does not match any of ${JSON.stringify($enum)}.`,
|
|
168
|
-
});
|
|
169
|
-
}
|
|
170
|
-
}
|
|
171
|
-
if ($not !== undefined) {
|
|
172
|
-
const keywordLocation = `${schemaLocation}/not`;
|
|
173
|
-
const result = validate(instance, $not, draft, lookup, shortCircuit, recursiveAnchor, instanceLocation, keywordLocation /*,
|
|
174
|
-
evaluated*/);
|
|
175
|
-
if (result.valid) {
|
|
176
|
-
errors.push({
|
|
177
|
-
instanceLocation,
|
|
178
|
-
keyword: "not",
|
|
179
|
-
keywordLocation,
|
|
180
|
-
error: 'Instance matched "not" schema.',
|
|
181
|
-
});
|
|
182
|
-
}
|
|
183
|
-
}
|
|
184
|
-
let subEvaluateds = [];
|
|
185
|
-
if ($anyOf !== undefined) {
|
|
186
|
-
const keywordLocation = `${schemaLocation}/anyOf`;
|
|
187
|
-
const errorsLength = errors.length;
|
|
188
|
-
let anyValid = false;
|
|
189
|
-
for (let i = 0; i < $anyOf.length; i++) {
|
|
190
|
-
const subSchema = $anyOf[i];
|
|
191
|
-
const subEvaluated = Object.create(evaluated);
|
|
192
|
-
const result = validate(instance, subSchema, draft, lookup, shortCircuit, $recursiveAnchor === true ? recursiveAnchor : null, instanceLocation, `${keywordLocation}/${i}`, subEvaluated);
|
|
193
|
-
errors.push(...result.errors);
|
|
194
|
-
anyValid = anyValid || result.valid;
|
|
195
|
-
if (result.valid) {
|
|
196
|
-
subEvaluateds.push(subEvaluated);
|
|
197
|
-
}
|
|
198
|
-
}
|
|
199
|
-
if (anyValid) {
|
|
200
|
-
errors.length = errorsLength;
|
|
201
|
-
}
|
|
202
|
-
else {
|
|
203
|
-
errors.splice(errorsLength, 0, {
|
|
204
|
-
instanceLocation,
|
|
205
|
-
keyword: "anyOf",
|
|
206
|
-
keywordLocation,
|
|
207
|
-
error: "Instance does not match any subschemas.",
|
|
208
|
-
});
|
|
209
|
-
}
|
|
210
|
-
}
|
|
211
|
-
if ($allOf !== undefined) {
|
|
212
|
-
const keywordLocation = `${schemaLocation}/allOf`;
|
|
213
|
-
const errorsLength = errors.length;
|
|
214
|
-
let allValid = true;
|
|
215
|
-
for (let i = 0; i < $allOf.length; i++) {
|
|
216
|
-
const subSchema = $allOf[i];
|
|
217
|
-
const subEvaluated = Object.create(evaluated);
|
|
218
|
-
const result = validate(instance, subSchema, draft, lookup, shortCircuit, $recursiveAnchor === true ? recursiveAnchor : null, instanceLocation, `${keywordLocation}/${i}`, subEvaluated);
|
|
219
|
-
errors.push(...result.errors);
|
|
220
|
-
allValid = allValid && result.valid;
|
|
221
|
-
if (result.valid) {
|
|
222
|
-
subEvaluateds.push(subEvaluated);
|
|
223
|
-
}
|
|
224
|
-
}
|
|
225
|
-
if (allValid) {
|
|
226
|
-
errors.length = errorsLength;
|
|
227
|
-
}
|
|
228
|
-
else {
|
|
229
|
-
errors.splice(errorsLength, 0, {
|
|
230
|
-
instanceLocation,
|
|
231
|
-
keyword: "allOf",
|
|
232
|
-
keywordLocation,
|
|
233
|
-
error: `Instance does not match every subschema.`,
|
|
234
|
-
});
|
|
235
|
-
}
|
|
236
|
-
}
|
|
237
|
-
if ($oneOf !== undefined) {
|
|
238
|
-
const keywordLocation = `${schemaLocation}/oneOf`;
|
|
239
|
-
const errorsLength = errors.length;
|
|
240
|
-
const matches = $oneOf.filter((subSchema, i) => {
|
|
241
|
-
const subEvaluated = Object.create(evaluated);
|
|
242
|
-
const result = validate(instance, subSchema, draft, lookup, shortCircuit, $recursiveAnchor === true ? recursiveAnchor : null, instanceLocation, `${keywordLocation}/${i}`, subEvaluated);
|
|
243
|
-
errors.push(...result.errors);
|
|
244
|
-
if (result.valid) {
|
|
245
|
-
subEvaluateds.push(subEvaluated);
|
|
246
|
-
}
|
|
247
|
-
return result.valid;
|
|
248
|
-
}).length;
|
|
249
|
-
if (matches === 1) {
|
|
250
|
-
errors.length = errorsLength;
|
|
251
|
-
}
|
|
252
|
-
else {
|
|
253
|
-
errors.splice(errorsLength, 0, {
|
|
254
|
-
instanceLocation,
|
|
255
|
-
keyword: "oneOf",
|
|
256
|
-
keywordLocation,
|
|
257
|
-
error: `Instance does not match exactly one subschema (${matches} matches).`,
|
|
258
|
-
});
|
|
259
|
-
}
|
|
260
|
-
}
|
|
261
|
-
if (instanceType === "object" || instanceType === "array") {
|
|
262
|
-
Object.assign(evaluated, ...subEvaluateds);
|
|
263
|
-
}
|
|
264
|
-
if ($if !== undefined) {
|
|
265
|
-
const keywordLocation = `${schemaLocation}/if`;
|
|
266
|
-
const conditionResult = validate(instance, $if, draft, lookup, shortCircuit, recursiveAnchor, instanceLocation, keywordLocation, evaluated).valid;
|
|
267
|
-
if (conditionResult) {
|
|
268
|
-
if ($then !== undefined) {
|
|
269
|
-
const thenResult = validate(instance, $then, draft, lookup, shortCircuit, recursiveAnchor, instanceLocation, `${schemaLocation}/then`, evaluated);
|
|
270
|
-
if (!thenResult.valid) {
|
|
271
|
-
errors.push({
|
|
272
|
-
instanceLocation,
|
|
273
|
-
keyword: "if",
|
|
274
|
-
keywordLocation,
|
|
275
|
-
error: `Instance does not match "then" schema.`,
|
|
276
|
-
}, ...thenResult.errors);
|
|
277
|
-
}
|
|
278
|
-
}
|
|
279
|
-
}
|
|
280
|
-
else if ($else !== undefined) {
|
|
281
|
-
const elseResult = validate(instance, $else, draft, lookup, shortCircuit, recursiveAnchor, instanceLocation, `${schemaLocation}/else`, evaluated);
|
|
282
|
-
if (!elseResult.valid) {
|
|
283
|
-
errors.push({
|
|
284
|
-
instanceLocation,
|
|
285
|
-
keyword: "if",
|
|
286
|
-
keywordLocation,
|
|
287
|
-
error: `Instance does not match "else" schema.`,
|
|
288
|
-
}, ...elseResult.errors);
|
|
289
|
-
}
|
|
290
|
-
}
|
|
291
|
-
}
|
|
292
|
-
if (instanceType === "object") {
|
|
293
|
-
if ($required !== undefined) {
|
|
294
|
-
for (const key of $required) {
|
|
295
|
-
if (!(key in instance)) {
|
|
296
|
-
errors.push({
|
|
297
|
-
instanceLocation,
|
|
298
|
-
keyword: "required",
|
|
299
|
-
keywordLocation: `${schemaLocation}/required`,
|
|
300
|
-
error: `Instance does not have required property "${key}".`,
|
|
301
|
-
});
|
|
302
|
-
}
|
|
303
|
-
}
|
|
304
|
-
}
|
|
305
|
-
const keys = Object.keys(instance);
|
|
306
|
-
if ($minProperties !== undefined && keys.length < $minProperties) {
|
|
307
|
-
errors.push({
|
|
308
|
-
instanceLocation,
|
|
309
|
-
keyword: "minProperties",
|
|
310
|
-
keywordLocation: `${schemaLocation}/minProperties`,
|
|
311
|
-
error: `Instance does not have at least ${$minProperties} properties.`,
|
|
312
|
-
});
|
|
313
|
-
}
|
|
314
|
-
if ($maxProperties !== undefined && keys.length > $maxProperties) {
|
|
315
|
-
errors.push({
|
|
316
|
-
instanceLocation,
|
|
317
|
-
keyword: "maxProperties",
|
|
318
|
-
keywordLocation: `${schemaLocation}/maxProperties`,
|
|
319
|
-
error: `Instance does not have at least ${$maxProperties} properties.`,
|
|
320
|
-
});
|
|
321
|
-
}
|
|
322
|
-
if ($propertyNames !== undefined) {
|
|
323
|
-
const keywordLocation = `${schemaLocation}/propertyNames`;
|
|
324
|
-
for (const key in instance) {
|
|
325
|
-
const subInstancePointer = `${instanceLocation}/${encodePointer(key)}`;
|
|
326
|
-
const result = validate(key, $propertyNames, draft, lookup, shortCircuit, recursiveAnchor, subInstancePointer, keywordLocation);
|
|
327
|
-
if (!result.valid) {
|
|
328
|
-
errors.push({
|
|
329
|
-
instanceLocation,
|
|
330
|
-
keyword: "propertyNames",
|
|
331
|
-
keywordLocation,
|
|
332
|
-
error: `Property name "${key}" does not match schema.`,
|
|
333
|
-
}, ...result.errors);
|
|
334
|
-
}
|
|
335
|
-
}
|
|
336
|
-
}
|
|
337
|
-
if ($dependentRequired !== undefined) {
|
|
338
|
-
const keywordLocation = `${schemaLocation}/dependantRequired`;
|
|
339
|
-
for (const key in $dependentRequired) {
|
|
340
|
-
if (key in instance) {
|
|
341
|
-
const required = $dependentRequired[key];
|
|
342
|
-
for (const dependantKey of required) {
|
|
343
|
-
if (!(dependantKey in instance)) {
|
|
344
|
-
errors.push({
|
|
345
|
-
instanceLocation,
|
|
346
|
-
keyword: "dependentRequired",
|
|
347
|
-
keywordLocation,
|
|
348
|
-
error: `Instance has "${key}" but does not have "${dependantKey}".`,
|
|
349
|
-
});
|
|
350
|
-
}
|
|
351
|
-
}
|
|
352
|
-
}
|
|
353
|
-
}
|
|
354
|
-
}
|
|
355
|
-
if ($dependentSchemas !== undefined) {
|
|
356
|
-
for (const key in $dependentSchemas) {
|
|
357
|
-
const keywordLocation = `${schemaLocation}/dependentSchemas`;
|
|
358
|
-
if (key in instance) {
|
|
359
|
-
const result = validate(instance, $dependentSchemas[key], draft, lookup, shortCircuit, recursiveAnchor, instanceLocation, `${keywordLocation}/${encodePointer(key)}`, evaluated);
|
|
360
|
-
if (!result.valid) {
|
|
361
|
-
errors.push({
|
|
362
|
-
instanceLocation,
|
|
363
|
-
keyword: "dependentSchemas",
|
|
364
|
-
keywordLocation,
|
|
365
|
-
error: `Instance has "${key}" but does not match dependant schema.`,
|
|
366
|
-
}, ...result.errors);
|
|
367
|
-
}
|
|
368
|
-
}
|
|
369
|
-
}
|
|
370
|
-
}
|
|
371
|
-
if ($dependencies !== undefined) {
|
|
372
|
-
const keywordLocation = `${schemaLocation}/dependencies`;
|
|
373
|
-
for (const key in $dependencies) {
|
|
374
|
-
if (key in instance) {
|
|
375
|
-
const propsOrSchema = $dependencies[key];
|
|
376
|
-
if (Array.isArray(propsOrSchema)) {
|
|
377
|
-
for (const dependantKey of propsOrSchema) {
|
|
378
|
-
if (!(dependantKey in instance)) {
|
|
379
|
-
errors.push({
|
|
380
|
-
instanceLocation,
|
|
381
|
-
keyword: "dependencies",
|
|
382
|
-
keywordLocation,
|
|
383
|
-
error: `Instance has "${key}" but does not have "${dependantKey}".`,
|
|
384
|
-
});
|
|
385
|
-
}
|
|
386
|
-
}
|
|
387
|
-
}
|
|
388
|
-
else {
|
|
389
|
-
const result = validate(instance, propsOrSchema, draft, lookup, shortCircuit, recursiveAnchor, instanceLocation, `${keywordLocation}/${encodePointer(key)}`);
|
|
390
|
-
if (!result.valid) {
|
|
391
|
-
errors.push({
|
|
392
|
-
instanceLocation,
|
|
393
|
-
keyword: "dependencies",
|
|
394
|
-
keywordLocation,
|
|
395
|
-
error: `Instance has "${key}" but does not match dependant schema.`,
|
|
396
|
-
}, ...result.errors);
|
|
397
|
-
}
|
|
398
|
-
}
|
|
399
|
-
}
|
|
400
|
-
}
|
|
401
|
-
}
|
|
402
|
-
const thisEvaluated = Object.create(null);
|
|
403
|
-
let stop = false;
|
|
404
|
-
if ($properties !== undefined) {
|
|
405
|
-
const keywordLocation = `${schemaLocation}/properties`;
|
|
406
|
-
for (const key in $properties) {
|
|
407
|
-
if (!(key in instance)) {
|
|
408
|
-
continue;
|
|
409
|
-
}
|
|
410
|
-
const subInstancePointer = `${instanceLocation}/${encodePointer(key)}`;
|
|
411
|
-
const result = validate(instance[key], $properties[key], draft, lookup, shortCircuit, recursiveAnchor, subInstancePointer, `${keywordLocation}/${encodePointer(key)}`);
|
|
412
|
-
if (result.valid) {
|
|
413
|
-
evaluated[key] = thisEvaluated[key] = true;
|
|
414
|
-
}
|
|
415
|
-
else {
|
|
416
|
-
stop = shortCircuit;
|
|
417
|
-
errors.push({
|
|
418
|
-
instanceLocation,
|
|
419
|
-
keyword: "properties",
|
|
420
|
-
keywordLocation,
|
|
421
|
-
error: `Property "${key}" does not match schema.`,
|
|
422
|
-
}, ...result.errors);
|
|
423
|
-
if (stop)
|
|
424
|
-
break;
|
|
425
|
-
}
|
|
426
|
-
}
|
|
427
|
-
}
|
|
428
|
-
if (!stop && $patternProperties !== undefined) {
|
|
429
|
-
const keywordLocation = `${schemaLocation}/patternProperties`;
|
|
430
|
-
for (const pattern in $patternProperties) {
|
|
431
|
-
const regex = new RegExp(pattern);
|
|
432
|
-
const subSchema = $patternProperties[pattern];
|
|
433
|
-
for (const key in instance) {
|
|
434
|
-
if (!regex.test(key)) {
|
|
435
|
-
continue;
|
|
436
|
-
}
|
|
437
|
-
const subInstancePointer = `${instanceLocation}/${encodePointer(key)}`;
|
|
438
|
-
const result = validate(instance[key], subSchema, draft, lookup, shortCircuit, recursiveAnchor, subInstancePointer, `${keywordLocation}/${encodePointer(pattern)}`);
|
|
439
|
-
if (result.valid) {
|
|
440
|
-
evaluated[key] = thisEvaluated[key] = true;
|
|
441
|
-
}
|
|
442
|
-
else {
|
|
443
|
-
stop = shortCircuit;
|
|
444
|
-
errors.push({
|
|
445
|
-
instanceLocation,
|
|
446
|
-
keyword: "patternProperties",
|
|
447
|
-
keywordLocation,
|
|
448
|
-
error: `Property "${key}" matches pattern "${pattern}" but does not match associated schema.`,
|
|
449
|
-
}, ...result.errors);
|
|
450
|
-
}
|
|
451
|
-
}
|
|
452
|
-
}
|
|
453
|
-
}
|
|
454
|
-
if (!stop && $additionalProperties !== undefined) {
|
|
455
|
-
const keywordLocation = `${schemaLocation}/additionalProperties`;
|
|
456
|
-
for (const key in instance) {
|
|
457
|
-
if (thisEvaluated[key]) {
|
|
458
|
-
continue;
|
|
459
|
-
}
|
|
460
|
-
const subInstancePointer = `${instanceLocation}/${encodePointer(key)}`;
|
|
461
|
-
const result = validate(instance[key], $additionalProperties, draft, lookup, shortCircuit, recursiveAnchor, subInstancePointer, keywordLocation);
|
|
462
|
-
if (result.valid) {
|
|
463
|
-
evaluated[key] = true;
|
|
464
|
-
}
|
|
465
|
-
else {
|
|
466
|
-
stop = shortCircuit;
|
|
467
|
-
errors.push({
|
|
468
|
-
instanceLocation,
|
|
469
|
-
keyword: "additionalProperties",
|
|
470
|
-
keywordLocation,
|
|
471
|
-
error: `Property "${key}" does not match additional properties schema.`,
|
|
472
|
-
}, ...result.errors);
|
|
473
|
-
}
|
|
474
|
-
}
|
|
475
|
-
}
|
|
476
|
-
else if (!stop && $unevaluatedProperties !== undefined) {
|
|
477
|
-
const keywordLocation = `${schemaLocation}/unevaluatedProperties`;
|
|
478
|
-
for (const key in instance) {
|
|
479
|
-
if (!evaluated[key]) {
|
|
480
|
-
const subInstancePointer = `${instanceLocation}/${encodePointer(key)}`;
|
|
481
|
-
const result = validate(instance[key], $unevaluatedProperties, draft, lookup, shortCircuit, recursiveAnchor, subInstancePointer, keywordLocation);
|
|
482
|
-
if (result.valid) {
|
|
483
|
-
evaluated[key] = true;
|
|
484
|
-
}
|
|
485
|
-
else {
|
|
486
|
-
errors.push({
|
|
487
|
-
instanceLocation,
|
|
488
|
-
keyword: "unevaluatedProperties",
|
|
489
|
-
keywordLocation,
|
|
490
|
-
error: `Property "${key}" does not match unevaluated properties schema.`,
|
|
491
|
-
}, ...result.errors);
|
|
492
|
-
}
|
|
493
|
-
}
|
|
494
|
-
}
|
|
495
|
-
}
|
|
496
|
-
}
|
|
497
|
-
else if (instanceType === "array") {
|
|
498
|
-
if ($maxItems !== undefined && instance.length > $maxItems) {
|
|
499
|
-
errors.push({
|
|
500
|
-
instanceLocation,
|
|
501
|
-
keyword: "maxItems",
|
|
502
|
-
keywordLocation: `${schemaLocation}/maxItems`,
|
|
503
|
-
error: `Array has too many items (${instance.length} > ${$maxItems}).`,
|
|
504
|
-
});
|
|
505
|
-
}
|
|
506
|
-
if ($minItems !== undefined && instance.length < $minItems) {
|
|
507
|
-
errors.push({
|
|
508
|
-
instanceLocation,
|
|
509
|
-
keyword: "minItems",
|
|
510
|
-
keywordLocation: `${schemaLocation}/minItems`,
|
|
511
|
-
error: `Array has too few items (${instance.length} < ${$minItems}).`,
|
|
512
|
-
});
|
|
513
|
-
}
|
|
514
|
-
const length = instance.length;
|
|
515
|
-
let i = 0;
|
|
516
|
-
let stop = false;
|
|
517
|
-
if ($prefixItems !== undefined) {
|
|
518
|
-
const keywordLocation = `${schemaLocation}/prefixItems`;
|
|
519
|
-
const length2 = Math.min($prefixItems.length, length);
|
|
520
|
-
for (; i < length2; i++) {
|
|
521
|
-
const result = validate(instance[i], $prefixItems[i], draft, lookup, shortCircuit, recursiveAnchor, `${instanceLocation}/${i}`, `${keywordLocation}/${i}`);
|
|
522
|
-
evaluated[i] = true;
|
|
523
|
-
if (!result.valid) {
|
|
524
|
-
stop = shortCircuit;
|
|
525
|
-
errors.push({
|
|
526
|
-
instanceLocation,
|
|
527
|
-
keyword: "prefixItems",
|
|
528
|
-
keywordLocation,
|
|
529
|
-
error: `Items did not match schema.`,
|
|
530
|
-
}, ...result.errors);
|
|
531
|
-
if (stop)
|
|
532
|
-
break;
|
|
533
|
-
}
|
|
534
|
-
}
|
|
535
|
-
}
|
|
536
|
-
if ($items !== undefined) {
|
|
537
|
-
const keywordLocation = `${schemaLocation}/items`;
|
|
538
|
-
if (Array.isArray($items)) {
|
|
539
|
-
const length2 = Math.min($items.length, length);
|
|
540
|
-
for (; i < length2; i++) {
|
|
541
|
-
const result = validate(instance[i], $items[i], draft, lookup, shortCircuit, recursiveAnchor, `${instanceLocation}/${i}`, `${keywordLocation}/${i}`);
|
|
542
|
-
evaluated[i] = true;
|
|
543
|
-
if (!result.valid) {
|
|
544
|
-
stop = shortCircuit;
|
|
545
|
-
errors.push({
|
|
546
|
-
instanceLocation,
|
|
547
|
-
keyword: "items",
|
|
548
|
-
keywordLocation,
|
|
549
|
-
error: `Items did not match schema.`,
|
|
550
|
-
}, ...result.errors);
|
|
551
|
-
if (stop)
|
|
552
|
-
break;
|
|
553
|
-
}
|
|
554
|
-
}
|
|
555
|
-
}
|
|
556
|
-
else {
|
|
557
|
-
for (; i < length; i++) {
|
|
558
|
-
const result = validate(instance[i], $items, draft, lookup, shortCircuit, recursiveAnchor, `${instanceLocation}/${i}`, keywordLocation);
|
|
559
|
-
evaluated[i] = true;
|
|
560
|
-
if (!result.valid) {
|
|
561
|
-
stop = shortCircuit;
|
|
562
|
-
errors.push({
|
|
563
|
-
instanceLocation,
|
|
564
|
-
keyword: "items",
|
|
565
|
-
keywordLocation,
|
|
566
|
-
error: `Items did not match schema.`,
|
|
567
|
-
}, ...result.errors);
|
|
568
|
-
if (stop)
|
|
569
|
-
break;
|
|
570
|
-
}
|
|
571
|
-
}
|
|
572
|
-
}
|
|
573
|
-
if (!stop && $additionalItems !== undefined) {
|
|
574
|
-
const keywordLocation = `${schemaLocation}/additionalItems`;
|
|
575
|
-
for (; i < length; i++) {
|
|
576
|
-
const result = validate(instance[i], $additionalItems, draft, lookup, shortCircuit, recursiveAnchor, `${instanceLocation}/${i}`, keywordLocation);
|
|
577
|
-
evaluated[i] = true;
|
|
578
|
-
if (!result.valid) {
|
|
579
|
-
stop = shortCircuit;
|
|
580
|
-
errors.push({
|
|
581
|
-
instanceLocation,
|
|
582
|
-
keyword: "additionalItems",
|
|
583
|
-
keywordLocation,
|
|
584
|
-
error: `Items did not match additional items schema.`,
|
|
585
|
-
}, ...result.errors);
|
|
586
|
-
}
|
|
587
|
-
}
|
|
588
|
-
}
|
|
589
|
-
}
|
|
590
|
-
if ($contains !== undefined) {
|
|
591
|
-
if (length === 0 && $minContains === undefined) {
|
|
592
|
-
errors.push({
|
|
593
|
-
instanceLocation,
|
|
594
|
-
keyword: "contains",
|
|
595
|
-
keywordLocation: `${schemaLocation}/contains`,
|
|
596
|
-
error: `Array is empty. It must contain at least one item matching the schema.`,
|
|
597
|
-
});
|
|
598
|
-
}
|
|
599
|
-
else if ($minContains !== undefined && length < $minContains) {
|
|
600
|
-
errors.push({
|
|
601
|
-
instanceLocation,
|
|
602
|
-
keyword: "minContains",
|
|
603
|
-
keywordLocation: `${schemaLocation}/minContains`,
|
|
604
|
-
error: `Array has less items (${length}) than minContains (${$minContains}).`,
|
|
605
|
-
});
|
|
606
|
-
}
|
|
607
|
-
else {
|
|
608
|
-
const keywordLocation = `${schemaLocation}/contains`;
|
|
609
|
-
const errorsLength = errors.length;
|
|
610
|
-
let contained = 0;
|
|
611
|
-
for (let j = 0; j < length; j++) {
|
|
612
|
-
const result = validate(instance[j], $contains, draft, lookup, shortCircuit, recursiveAnchor, `${instanceLocation}/${j}`, keywordLocation);
|
|
613
|
-
if (result.valid) {
|
|
614
|
-
evaluated[j] = true;
|
|
615
|
-
contained++;
|
|
616
|
-
}
|
|
617
|
-
else {
|
|
618
|
-
errors.push(...result.errors);
|
|
619
|
-
}
|
|
620
|
-
}
|
|
621
|
-
if (contained >= ($minContains || 0)) {
|
|
622
|
-
errors.length = errorsLength;
|
|
623
|
-
}
|
|
624
|
-
if ($minContains === undefined &&
|
|
625
|
-
$maxContains === undefined &&
|
|
626
|
-
contained === 0) {
|
|
627
|
-
errors.splice(errorsLength, 0, {
|
|
628
|
-
instanceLocation,
|
|
629
|
-
keyword: "contains",
|
|
630
|
-
keywordLocation,
|
|
631
|
-
error: `Array does not contain item matching schema.`,
|
|
632
|
-
});
|
|
633
|
-
}
|
|
634
|
-
else if ($minContains !== undefined && contained < $minContains) {
|
|
635
|
-
errors.push({
|
|
636
|
-
instanceLocation,
|
|
637
|
-
keyword: "minContains",
|
|
638
|
-
keywordLocation: `${schemaLocation}/minContains`,
|
|
639
|
-
error: `Array must contain at least ${$minContains} items matching schema. Only ${contained} items were found.`,
|
|
640
|
-
});
|
|
641
|
-
}
|
|
642
|
-
else if ($maxContains !== undefined && contained > $maxContains) {
|
|
643
|
-
errors.push({
|
|
644
|
-
instanceLocation,
|
|
645
|
-
keyword: "maxContains",
|
|
646
|
-
keywordLocation: `${schemaLocation}/maxContains`,
|
|
647
|
-
error: `Array may contain at most ${$maxContains} items matching schema. ${contained} items were found.`,
|
|
648
|
-
});
|
|
649
|
-
}
|
|
650
|
-
}
|
|
651
|
-
}
|
|
652
|
-
if (!stop && $unevaluatedItems !== undefined) {
|
|
653
|
-
const keywordLocation = `${schemaLocation}/unevaluatedItems`;
|
|
654
|
-
for (i; i < length; i++) {
|
|
655
|
-
if (evaluated[i]) {
|
|
656
|
-
continue;
|
|
657
|
-
}
|
|
658
|
-
const result = validate(instance[i], $unevaluatedItems, draft, lookup, shortCircuit, recursiveAnchor, `${instanceLocation}/${i}`, keywordLocation);
|
|
659
|
-
evaluated[i] = true;
|
|
660
|
-
if (!result.valid) {
|
|
661
|
-
errors.push({
|
|
662
|
-
instanceLocation,
|
|
663
|
-
keyword: "unevaluatedItems",
|
|
664
|
-
keywordLocation,
|
|
665
|
-
error: `Items did not match unevaluated items schema.`,
|
|
666
|
-
}, ...result.errors);
|
|
667
|
-
}
|
|
668
|
-
}
|
|
669
|
-
}
|
|
670
|
-
if ($uniqueItems) {
|
|
671
|
-
for (let j = 0; j < length; j++) {
|
|
672
|
-
const a = instance[j];
|
|
673
|
-
const ao = typeof a === "object" && a !== null;
|
|
674
|
-
for (let k = 0; k < length; k++) {
|
|
675
|
-
if (j === k) {
|
|
676
|
-
continue;
|
|
677
|
-
}
|
|
678
|
-
const b = instance[k];
|
|
679
|
-
const bo = typeof b === "object" && b !== null;
|
|
680
|
-
if (a === b || (ao && bo && deepCompareStrict(a, b))) {
|
|
681
|
-
errors.push({
|
|
682
|
-
instanceLocation,
|
|
683
|
-
keyword: "uniqueItems",
|
|
684
|
-
keywordLocation: `${schemaLocation}/uniqueItems`,
|
|
685
|
-
error: `Duplicate items at indexes ${j} and ${k}.`,
|
|
686
|
-
});
|
|
687
|
-
j = Number.MAX_SAFE_INTEGER;
|
|
688
|
-
k = Number.MAX_SAFE_INTEGER;
|
|
689
|
-
}
|
|
690
|
-
}
|
|
691
|
-
}
|
|
692
|
-
}
|
|
693
|
-
}
|
|
694
|
-
else if (instanceType === "number") {
|
|
695
|
-
if (draft === "4") {
|
|
696
|
-
if ($minimum !== undefined &&
|
|
697
|
-
(($exclusiveMinimum === true && instance <= $minimum) ||
|
|
698
|
-
instance < $minimum)) {
|
|
699
|
-
errors.push({
|
|
700
|
-
instanceLocation,
|
|
701
|
-
keyword: "minimum",
|
|
702
|
-
keywordLocation: `${schemaLocation}/minimum`,
|
|
703
|
-
error: `${instance} is less than ${$exclusiveMinimum ? "or equal to " : ""} ${$minimum}.`,
|
|
704
|
-
});
|
|
705
|
-
}
|
|
706
|
-
if ($maximum !== undefined &&
|
|
707
|
-
(($exclusiveMaximum === true && instance >= $maximum) ||
|
|
708
|
-
instance > $maximum)) {
|
|
709
|
-
errors.push({
|
|
710
|
-
instanceLocation,
|
|
711
|
-
keyword: "maximum",
|
|
712
|
-
keywordLocation: `${schemaLocation}/maximum`,
|
|
713
|
-
error: `${instance} is greater than ${$exclusiveMaximum ? "or equal to " : ""} ${$maximum}.`,
|
|
714
|
-
});
|
|
715
|
-
}
|
|
716
|
-
}
|
|
717
|
-
else {
|
|
718
|
-
if ($minimum !== undefined && instance < $minimum) {
|
|
719
|
-
errors.push({
|
|
720
|
-
instanceLocation,
|
|
721
|
-
keyword: "minimum",
|
|
722
|
-
keywordLocation: `${schemaLocation}/minimum`,
|
|
723
|
-
error: `${instance} is less than ${$minimum}.`,
|
|
724
|
-
});
|
|
725
|
-
}
|
|
726
|
-
if ($maximum !== undefined && instance > $maximum) {
|
|
727
|
-
errors.push({
|
|
728
|
-
instanceLocation,
|
|
729
|
-
keyword: "maximum",
|
|
730
|
-
keywordLocation: `${schemaLocation}/maximum`,
|
|
731
|
-
error: `${instance} is greater than ${$maximum}.`,
|
|
732
|
-
});
|
|
733
|
-
}
|
|
734
|
-
if ($exclusiveMinimum !== undefined && instance <= $exclusiveMinimum) {
|
|
735
|
-
errors.push({
|
|
736
|
-
instanceLocation,
|
|
737
|
-
keyword: "exclusiveMinimum",
|
|
738
|
-
keywordLocation: `${schemaLocation}/exclusiveMinimum`,
|
|
739
|
-
error: `${instance} is less than ${$exclusiveMinimum}.`,
|
|
740
|
-
});
|
|
741
|
-
}
|
|
742
|
-
if ($exclusiveMaximum !== undefined && instance >= $exclusiveMaximum) {
|
|
743
|
-
errors.push({
|
|
744
|
-
instanceLocation,
|
|
745
|
-
keyword: "exclusiveMaximum",
|
|
746
|
-
keywordLocation: `${schemaLocation}/exclusiveMaximum`,
|
|
747
|
-
error: `${instance} is greater than or equal to ${$exclusiveMaximum}.`,
|
|
748
|
-
});
|
|
749
|
-
}
|
|
750
|
-
}
|
|
751
|
-
if ($multipleOf !== undefined) {
|
|
752
|
-
const remainder = instance % $multipleOf;
|
|
753
|
-
if (Math.abs(0 - remainder) >= 1.1920929e-7 &&
|
|
754
|
-
Math.abs($multipleOf - remainder) >= 1.1920929e-7) {
|
|
755
|
-
errors.push({
|
|
756
|
-
instanceLocation,
|
|
757
|
-
keyword: "multipleOf",
|
|
758
|
-
keywordLocation: `${schemaLocation}/multipleOf`,
|
|
759
|
-
error: `${instance} is not a multiple of ${$multipleOf}.`,
|
|
760
|
-
});
|
|
761
|
-
}
|
|
762
|
-
}
|
|
763
|
-
}
|
|
764
|
-
else if (instanceType === "string") {
|
|
765
|
-
const length = $minLength === undefined && $maxLength === undefined
|
|
766
|
-
? 0
|
|
767
|
-
: ucs2length(instance);
|
|
768
|
-
if ($minLength !== undefined && length < $minLength) {
|
|
769
|
-
errors.push({
|
|
770
|
-
instanceLocation,
|
|
771
|
-
keyword: "minLength",
|
|
772
|
-
keywordLocation: `${schemaLocation}/minLength`,
|
|
773
|
-
error: `String is too short (${length} < ${$minLength}).`,
|
|
774
|
-
});
|
|
775
|
-
}
|
|
776
|
-
if ($maxLength !== undefined && length > $maxLength) {
|
|
777
|
-
errors.push({
|
|
778
|
-
instanceLocation,
|
|
779
|
-
keyword: "maxLength",
|
|
780
|
-
keywordLocation: `${schemaLocation}/maxLength`,
|
|
781
|
-
error: `String is too long (${length} > ${$maxLength}).`,
|
|
782
|
-
});
|
|
783
|
-
}
|
|
784
|
-
if ($pattern !== undefined && !new RegExp($pattern).test(instance)) {
|
|
785
|
-
errors.push({
|
|
786
|
-
instanceLocation,
|
|
787
|
-
keyword: "pattern",
|
|
788
|
-
keywordLocation: `${schemaLocation}/pattern`,
|
|
789
|
-
error: `String does not match pattern.`,
|
|
790
|
-
});
|
|
791
|
-
}
|
|
792
|
-
if ($format !== undefined &&
|
|
793
|
-
fastFormat[$format] &&
|
|
794
|
-
!fastFormat[$format](instance)) {
|
|
795
|
-
errors.push({
|
|
796
|
-
instanceLocation,
|
|
797
|
-
keyword: "format",
|
|
798
|
-
keywordLocation: `${schemaLocation}/format`,
|
|
799
|
-
error: `String does not match format "${$format}".`,
|
|
800
|
-
});
|
|
801
|
-
}
|
|
802
|
-
}
|
|
803
|
-
return { valid: errors.length === 0, errors };
|
|
804
|
-
}
|