first commit

This commit is contained in:
2026-03-10 16:18:05 +00:00
commit 11f9c069b5
31635 changed files with 3187747 additions and 0 deletions

79
node_modules/@expo/schema-utils/build/JSONSchema.d.ts generated vendored Normal file
View File

@@ -0,0 +1,79 @@
/**
* This interface was referenced by `JSONSchema`'s JSON-Schema
* via the `definition` "positiveInteger".
*/
export type PositiveInteger = number;
/**
* This interface was referenced by `JSONSchema`'s JSON-Schema
* via the `definition` "positiveIntegerDefault0".
*/
export type PositiveIntegerDefault0 = PositiveInteger;
/**
* @minItems 1
*
* This interface was referenced by `JSONSchema`'s JSON-Schema
* via the `definition` "schemaArray".
*/
export type SchemaArray = [JSONSchema, ...JSONSchema[]];
/**
* @minItems 1
*
* This interface was referenced by `JSONSchema`'s JSON-Schema
* via the `definition` "stringArray".
*/
export type StringArray = [string, ...string[]];
/**
* This interface was referenced by `JSONSchema`'s JSON-Schema
* via the `definition` "simpleTypes".
*/
export type SimpleTypes = 'array' | 'boolean' | 'integer' | 'null' | 'number' | 'object' | 'string';
/**
* Core schema meta-schema
*/
export interface JSONSchema<_SchemaType = unknown> {
id?: string;
$schema?: string;
title?: string;
description?: string;
default?: unknown;
multipleOf?: number;
maximum?: number;
exclusiveMaximum?: boolean;
minimum?: number;
exclusiveMinimum?: boolean;
maxLength?: PositiveInteger;
minLength?: PositiveIntegerDefault0;
pattern?: string;
additionalItems?: boolean | JSONSchema;
items?: JSONSchema | SchemaArray;
maxItems?: PositiveInteger;
minItems?: PositiveIntegerDefault0;
uniqueItems?: boolean;
maxProperties?: PositiveInteger;
minProperties?: PositiveIntegerDefault0;
required?: StringArray;
additionalProperties?: boolean | JSONSchema;
definitions?: {
[k: string]: JSONSchema;
};
properties?: {
[k: string]: JSONSchema;
};
patternProperties?: {
[k: string]: JSONSchema;
};
dependencies?: {
[k: string]: (JSONSchema | StringArray) | undefined;
};
/**
* @minItems 1
*/
enum?: [unknown, ...unknown[]];
type?: SimpleTypes | [SimpleTypes, ...SimpleTypes[]];
format?: string;
allOf?: SchemaArray;
anyOf?: SchemaArray;
oneOf?: SchemaArray;
not?: JSONSchema;
[k: string]: unknown | undefined;
}

2
node_modules/@expo/schema-utils/build/JSONSchema.js generated vendored Normal file
View File

@@ -0,0 +1,2 @@
"use strict";
//# sourceMappingURL=JSONSchema.js.map

View File

@@ -0,0 +1 @@
{"version":3,"file":"JSONSchema.js","names":[],"sources":["../src/JSONSchema.ts"],"sourcesContent":["/* eslint-disable @typescript-eslint/no-unused-vars */\n\n/**\n * This interface was referenced by `JSONSchema`'s JSON-Schema\n * via the `definition` \"positiveInteger\".\n */\nexport type PositiveInteger = number;\n/**\n * This interface was referenced by `JSONSchema`'s JSON-Schema\n * via the `definition` \"positiveIntegerDefault0\".\n */\nexport type PositiveIntegerDefault0 = PositiveInteger;\n/**\n * @minItems 1\n *\n * This interface was referenced by `JSONSchema`'s JSON-Schema\n * via the `definition` \"schemaArray\".\n */\nexport type SchemaArray = [JSONSchema, ...JSONSchema[]];\n/**\n * @minItems 1\n *\n * This interface was referenced by `JSONSchema`'s JSON-Schema\n * via the `definition` \"stringArray\".\n */\nexport type StringArray = [string, ...string[]];\n/**\n * This interface was referenced by `JSONSchema`'s JSON-Schema\n * via the `definition` \"simpleTypes\".\n */\nexport type SimpleTypes = 'array' | 'boolean' | 'integer' | 'null' | 'number' | 'object' | 'string';\n\n/**\n * Core schema meta-schema\n */\nexport interface JSONSchema<_SchemaType = unknown> {\n id?: string;\n $schema?: string;\n title?: string;\n description?: string;\n default?: unknown;\n multipleOf?: number;\n maximum?: number;\n exclusiveMaximum?: boolean;\n minimum?: number;\n exclusiveMinimum?: boolean;\n maxLength?: PositiveInteger;\n minLength?: PositiveIntegerDefault0;\n pattern?: string;\n additionalItems?: boolean | JSONSchema;\n items?: JSONSchema | SchemaArray;\n maxItems?: PositiveInteger;\n minItems?: PositiveIntegerDefault0;\n uniqueItems?: boolean;\n maxProperties?: PositiveInteger;\n minProperties?: PositiveIntegerDefault0;\n required?: StringArray;\n additionalProperties?: boolean | JSONSchema;\n definitions?: {\n [k: string]: JSONSchema;\n };\n properties?: {\n [k: string]: JSONSchema;\n };\n patternProperties?: {\n [k: string]: JSONSchema;\n };\n dependencies?: {\n [k: string]: (JSONSchema | StringArray) | undefined;\n };\n /**\n * @minItems 1\n */\n enum?: [unknown, ...unknown[]];\n type?: SimpleTypes | [SimpleTypes, ...SimpleTypes[]];\n format?: string;\n allOf?: SchemaArray;\n anyOf?: SchemaArray;\n oneOf?: SchemaArray;\n not?: JSONSchema;\n [k: string]: unknown | undefined;\n}\n"],"mappings":"","ignoreList":[]}

9
node_modules/@expo/schema-utils/build/deref.d.ts generated vendored Normal file
View File

@@ -0,0 +1,9 @@
/** Dereference JSON schema pointers.
*
* @remarks
* This is a minimal reimplementation of `json-schema-deref-sync` without
* file reference, URL/web reference, and loader support.
*
* @see https://github.com/cvent/json-schema-deref-sync
*/
export declare function deref(input: any): any;

176
node_modules/@expo/schema-utils/build/deref.js generated vendored Normal file
View File

@@ -0,0 +1,176 @@
"use strict";
Object.defineProperty(exports, "__esModule", {
value: true
});
exports.deref = deref;
/** Return JSON schema ref if input is of `NodeRef` type */
const getRef = node => node != null && typeof node === 'object' && '$ref' in node && typeof node.$ref === 'string' ? node.$ref : undefined;
/** Parse a JSON schema ref into a path array, or return undefined */
const parseRefMaybe = ref => {
if (ref == null || ref[0] !== '#') {
return undefined;
}
const props = [];
let startIndex = 1;
let index = 1;
let char;
while (index < ref.length) {
while ((char = ref.charCodeAt(index++)) && char !== 47 /*'/'*/);
const prop = ref.slice(startIndex, index - 1);
startIndex = index;
if (prop) props.push(prop);
}
return props.length ? props : undefined;
};
const NOT_FOUND_SYMBOL = Symbol();
/** Get value at given JSON schema path or return `NOT_FOUND_SYMBOL` */
const getValueAtPath = (input, ref) => {
let node = input;
for (let index = 0; index < ref.length; index++) {
const part = ref[index];
if (node != null && typeof node === 'object' && part in node) {
node = node[part];
} else {
node = NOT_FOUND_SYMBOL;
break;
}
}
return node;
};
/** Find all JSON schema refs recursively and add them to `refs` Map */
const findRefsRec = (node, refs, path) => {
if (node == null || typeof node !== 'object') {} else if (Array.isArray(node)) {
for (let index = 0, l = node.length; index < l; index++) {
const value = node[index];
const ref = getRef(value);
if (ref) {
const targetRef = parseRefMaybe(ref);
if (targetRef) refs.set([...path, index], targetRef);
} else if (value != null && typeof value === 'object') {
path.push(index);
findRefsRec(value, refs, path);
path.pop();
}
}
} else {
const record = node;
for (const key in record) {
const value = record[key];
const ref = getRef(value);
if (ref) {
const targetRef = parseRefMaybe(ref);
if (targetRef) refs.set([...path, key], targetRef);
} else if (value != null && typeof value === 'object') {
path.push(key);
findRefsRec(value, refs, path);
path.pop();
}
}
}
};
/** Detect whether target (where we set the source value) is a nested path inside the source path */
const isSelfReferencingRefEntry = (target, source) => {
for (let index = 0; index < source.length; index++) {
if (source[index] !== target[index]) return false;
}
return true;
};
/** Return sorted refs entries. Longest target paths will be returned first */
const getSortedRefEntries = refs => {
const entries = [...refs.entries()].sort((a, b) => b[1].length - a[1].length);
// Filter out self-referenceing paths. If we set nested targets to source values, we'd
// create unserializable circular references
return entries.filter(entry => !isSelfReferencingRefEntry(entry[0], entry[1]));
};
/** Dereference JSON schema pointers.
*
* @remarks
* This is a minimal reimplementation of `json-schema-deref-sync` without
* file reference, URL/web reference, and loader support.
*
* @see https://github.com/cvent/json-schema-deref-sync
*/
function deref(input) {
const refs = new Map();
// Find all JSON schema refs paths
findRefsRec(input, refs, []);
// Shallow copy output
const output = {
...input
};
// Process all ref entries with deepest targets first
nextRef: for (const [target, source] of getSortedRefEntries(refs)) {
let inputNode = input;
let outputNode = output;
let targetIndex = 0;
// For each path part on the target, traverse the output and clone the input
// to not pollute it
for (; targetIndex < target.length - 1; targetIndex++) {
const part = target[targetIndex];
if (inputNode == null || typeof inputNode !== 'object' || !(part in inputNode)) {
// If the part doesn't exist, we abort
break;
} else if (outputNode[part] === inputNode[part]) {
// Copy the input on the output if references are equal
outputNode[part] = Array.isArray(inputNode[part]) ? [...inputNode[part]] : {
...inputNode[part]
};
inputNode = inputNode[part];
outputNode = outputNode[part];
} else {
// If this part has already been copied, abort
break;
}
}
// For each remaining part on the target, continue traversing the output
for (; targetIndex < target.length - 1; targetIndex++) {
const part = target[targetIndex];
if (outputNode == null || typeof outputNode !== 'object' || !(part in outputNode)) {
// If the part doesn't exist, skip the entire ref
continue nextRef;
} else {
outputNode = outputNode[part];
}
}
// Get value from output
let sourceValue = getValueAtPath(output, source);
if (sourceValue === NOT_FOUND_SYMBOL) {
// If no value was found, try to get a value from the input instead
sourceValue = getValueAtPath(input, source);
// Otherwise, skip this ref
if (sourceValue === NOT_FOUND_SYMBOL) continue;
}
// Set the source value on the target path
// The for-loops prior have made sure that the output has already been deeply
// cloned and traversed for the entire path
outputNode[target[target.length - 1]] = sourceValue;
}
// Handle root refs last
const rootTargetRef = parseRefMaybe(getRef(input));
if (rootTargetRef) {
// Get value from output
let sourceValue = getValueAtPath(output, rootTargetRef);
// If no value was found, try to get a value from the input instead
if (sourceValue === NOT_FOUND_SYMBOL) {
sourceValue = getValueAtPath(input, rootTargetRef);
}
// Assign the target object to the output
if (sourceValue !== NOT_FOUND_SYMBOL && sourceValue != null) {
return typeof sourceValue === 'object' ? {
...sourceValue,
title: output.title,
description: output.description
} : sourceValue;
}
}
// Return the output with resolved refs
return output;
}
//# sourceMappingURL=deref.js.map

1
node_modules/@expo/schema-utils/build/deref.js.map generated vendored Normal file

File diff suppressed because one or more lines are too long

11
node_modules/@expo/schema-utils/build/index.d.ts generated vendored Normal file
View File

@@ -0,0 +1,11 @@
import { JSONSchema } from './JSONSchema';
import { BaseValidationError, ValidationError as ValidationResult } from './validate';
export { JSONSchema } from './JSONSchema';
export declare class ValidationError<T> extends Error {
schema: JSONSchema<T>;
errors: BaseValidationError[];
constructor(result: ValidationResult, schema: JSONSchema<T>);
toErrorsMessage(): string[];
}
export declare function derefSchema<T>(schema: JSONSchema<T>): JSONSchema<T>;
export declare function validate<T>(schema: JSONSchema<T>, value: unknown): asserts value is T;

93
node_modules/@expo/schema-utils/build/index.js generated vendored Normal file
View File

@@ -0,0 +1,93 @@
"use strict";
Object.defineProperty(exports, "__esModule", {
value: true
});
Object.defineProperty(exports, "JSONSchema", {
enumerable: true,
get: function () {
return _JSONSchema().JSONSchema;
}
});
exports.ValidationError = void 0;
exports.derefSchema = derefSchema;
exports.validate = validate;
function _deref() {
const data = require("./deref");
_deref = function () {
return data;
};
return data;
}
function _validate() {
const data = require("./validate");
_validate = function () {
return data;
};
return data;
}
function _JSONSchema() {
const data = require("./JSONSchema");
_JSONSchema = function () {
return data;
};
return data;
}
const CACHE_SYMBOL = Symbol('@expo/schema-utils');
const flattenValidationResults = (input, output = []) => {
output.push({
message: input.message,
path: input.path,
keyword: input.keyword,
value: input.value
});
for (let idx = 0; input.cause && idx < input.cause.length; idx++) {
flattenValidationResults(input.cause[idx], output);
}
return output;
};
const toErrorsMessages = errors => errors.map(error => {
return `\n - options${error.path} (${error.keyword}): ${error.message}`;
});
class ValidationError extends Error {
constructor(result, schema) {
const errors = flattenValidationResults(result);
const title = typeof schema.title === 'string' ? schema.title : 'Value';
super(`Invalid options object. ${title} options object does not match the defined schema.\n` + toErrorsMessages(errors).map(line => ` - options${line}`).join('\n'));
this.name = 'ValidationError';
this.errors = errors;
this.schema = schema;
}
toErrorsMessage() {
return toErrorsMessages(this.errors);
}
}
exports.ValidationError = ValidationError;
const derefSchemaCache = schema => {
let derefed = schema[CACHE_SYMBOL];
if (!derefed) {
derefed = {
schema: (0, _deref().deref)(schema),
cache: new WeakMap()
};
schema[CACHE_SYMBOL] = derefed;
}
return derefed;
};
function derefSchema(schema) {
return derefSchemaCache(schema).schema;
}
function validate(schema, value) {
const data = derefSchemaCache(schema);
let result;
if (typeof value !== 'object' || value == null || (result = data.cache.get(value)) === undefined) {
result = (0, _validate().validateSchema)(data.schema, value, '');
if (typeof value === 'object' && value != null) {
data.cache.set(value, result);
}
}
if (result) {
throw new ValidationError(result, data.schema);
}
}
//# sourceMappingURL=index.js.map

1
node_modules/@expo/schema-utils/build/index.js.map generated vendored Normal file

File diff suppressed because one or more lines are too long

11
node_modules/@expo/schema-utils/build/validate.d.ts generated vendored Normal file
View File

@@ -0,0 +1,11 @@
import { JSONSchema } from './JSONSchema';
export interface BaseValidationError {
message: string;
path: string;
keyword: string;
value: unknown;
}
export interface ValidationError extends BaseValidationError {
cause?: ValidationError[];
}
export declare const validateSchema: (schema: JSONSchema, value: unknown, path: string) => ValidationError | null;

565
node_modules/@expo/schema-utils/build/validate.js generated vendored Normal file
View File

@@ -0,0 +1,565 @@
"use strict";
Object.defineProperty(exports, "__esModule", {
value: true
});
exports.validateSchema = void 0;
const getValueType = value => {
const typeOf = typeof value;
switch (typeOf) {
case 'number':
return Number.isInteger(value) ? 'integer' : 'number';
case 'boolean':
case 'string':
return typeOf;
case 'object':
if (value === null) {
return 'null';
} else if (Array.isArray(value)) {
return 'array';
} else {
return 'object';
}
default:
return typeOf;
}
};
const isDeepEqual = (a, b) => {
if (a === b) {
return true;
} else if (a === null || b === null) {
return false;
} else if (typeof a !== typeof b) {
return false;
} else if (Array.isArray(a)) {
if (!Array.isArray(b) || a.length !== b.length) {
return false;
}
for (let idx = 0; idx < a.length; idx++) {
if (!isDeepEqual(a[idx], b[idx])) return false;
}
return true;
} else if (typeof a === 'object') {
const keysA = Object.keys(a);
const keysB = Object.keys(b);
if (!isDeepEqual(keysA, keysB)) {
return false;
}
for (let idx = 0; idx < keysA.length; idx++) {
if (!isDeepEqual(a[keysA[idx]], b[keysA[idx]])) {
return false;
}
}
return true;
} else {
return false;
}
};
const areArrayValuesUnique = array => {
for (let i = 0; i < array.length; i++) {
for (let j = 0; j < array.length; j++) {
if (i !== j && isDeepEqual(array[i], array[j])) {
return false;
}
}
}
return true;
};
const dateRe = /^\d{4}-\d{2}-\d{2}$/;
const dateTimeRe = /^\d{4}-\d{2}-\d{2}T\d{2}:\d{2}:\d{2}(\.\d{3})?Z?$/;
const timeRe = /^\d{2}:\d{2}:\d{2}$/;
const emailRe = /^[^\s@]+@[^\s@]+\.[^\s@]+$/;
const hostnameRe = /^[a-zA-Z0-9](?:[a-zA-Z0-9-]{0,61}[a-zA-Z0-9])?(\.[a-zA-Z0-9](?:[a-zA-Z0-9-]{0,61}[a-zA-Z0-9])?)*$/;
const uriRe = /^https?:\/\//;
const validateFormat = (format, value) => {
// NOTE: Left out ipv4 and ipv6
switch (format) {
case 'date-time':
return dateTimeRe.test(value);
case 'date':
return dateRe.test(value);
case 'time':
return timeRe.test(value);
case 'email':
return emailRe.test(value);
case 'hostname':
return hostnameRe.test(value);
case 'uri':
return uriRe.test(value);
default:
throw new TypeError(`Unsupported format "${format}"`);
}
};
const isEnumValue = (enumValues, value) => {
if (!enumValues.length) {
throw new TypeError('Empty enum array');
}
for (let idx = 0; idx < enumValues.length; idx++) {
if (isDeepEqual(value, enumValues[idx])) {
return true;
}
}
return false;
};
const validateString = (schema, value, path) => {
if (schema.minLength != null && value.length < schema.minLength) {
return {
message: `String must be at least ${schema.minLength} characters`,
keyword: 'minLength',
path,
value
};
} else if (schema.maxLength != null && value.length > schema.maxLength) {
return {
message: `String must be at most ${schema.maxLength} characters`,
keyword: 'maxLength',
path,
value
};
} else if (schema.pattern != null && !new RegExp(schema.pattern).test(value)) {
return {
message: `String does not match pattern: ${schema.pattern}`,
keyword: 'pattern',
path,
value
};
} else if (schema.format != null && !validateFormat(schema.format, value)) {
return {
message: `String does not match format: ${schema.format}`,
keyword: 'format',
path,
value
};
} else {
return null;
}
};
const validateNumber = (schema, value, path) => {
if (schema.multipleOf != null && value % schema.multipleOf !== 0) {
return {
message: `Number must be multiple of ${schema.multipleOf}`,
keyword: 'multipleOf',
path,
value
};
} else if (schema.minimum != null && value < schema.minimum) {
return {
message: `Number must be equal or greater than ${schema.minimum}`,
keyword: 'minimum',
path,
value
};
} else if (schema.maximum != null && value > schema.maximum) {
return {
message: `Number must be equal or less than ${schema.maximum}`,
keyword: 'maximum',
path,
value
};
} else if (schema.exclusiveMaximum === true && schema.maximum != null && value >= schema.maximum) {
return {
message: `Number must be less than ${schema.maximum}`,
keyword: 'exclusiveMaximum',
path,
value
};
} else if (typeof schema.exclusiveMaximum === 'number' && value >= schema.exclusiveMaximum) {
return {
message: `Number must be less than ${schema.exclusiveMaximum}`,
keyword: 'exclusiveMaximum',
path,
value
};
} else if (schema.exclusiveMinimum === true && schema.minimum != null && value <= schema.minimum) {
return {
message: `Number must be greater than ${schema.minimum}`,
keyword: 'exclusiveMinimum',
path,
value
};
} else if (typeof schema.exclusiveMinimum === 'number' && value <= schema.exclusiveMinimum) {
return {
message: `Number must be greater than ${schema.exclusiveMinimum}`,
keyword: 'exclusiveMinimum',
path,
value
};
} else {
return null;
}
};
const validateContains = (containsSchema, value, path) => {
for (let idx = 0; idx < value.length; idx++) {
if (validateSchema(containsSchema, value[idx], path) === null) {
return null;
}
}
return {
message: 'Array must contain at least one item matching the contains schema',
keyword: 'contains',
path,
value
};
};
const validateItems = (itemsSchema, additionalItems, value, path) => {
let child;
if (Array.isArray(itemsSchema)) {
let idx = 0;
for (idx = 0; idx < itemsSchema.length; idx++) {
if ((child = validateSchema(itemsSchema[idx], value[idx], `${path}[${idx}]`)) != null) {
return child;
}
}
if (idx < value.length) {
if (additionalItems === true) {
return null;
} else if (additionalItems) {
for (; idx < value.length; idx++) {
if ((child = validateSchema(additionalItems, value[idx], `${path}[${idx}]`)) != null) {
return child;
}
}
return null;
} else {
return {
message: `Array contained ${value.length - idx} more items than items schema`,
keyword: 'additionalItems',
path,
value
};
}
} else {
return null;
}
} else {
for (let idx = 0; idx < value.length; idx++) {
if ((child = validateSchema(itemsSchema, value[idx], `${path}[${idx}]`)) != null) {
return child;
}
}
return null;
}
};
const validateArray = (schema, value, path) => {
let child;
if (schema.minItems != null && value.length < schema.minItems) {
return {
message: `Array must have at least ${schema.minItems} items`,
keyword: 'minItems',
path,
value
};
} else if (schema.maxItems != null && value.length > schema.maxItems) {
return {
message: `Array must have at most ${schema.maxItems} items`,
keyword: 'maxItems',
path,
value
};
} else if (schema.uniqueItems && !areArrayValuesUnique(value)) {
return {
message: 'Array items must be unique',
keyword: 'uniqueItems',
path,
value
};
} else if (schema.contains != null && (child = validateContains(schema.contains, value, path)) != null) {
return child;
} else if (schema.items != null && (child = validateItems(schema.items, schema.additionalItems, value, path)) != null) {
return child;
} else {
return null;
}
};
const validateRequired = (keys, value, path) => {
for (let idx = 0; idx < keys.length; idx++) {
if (value[keys[idx]] === undefined) {
return {
message: `Required property "${keys[idx]}" is missing`,
keyword: 'required',
path: `${path}.${keys[idx]}`,
value
};
}
}
return null;
};
const validateProperties = (properties, value, path) => {
let child;
for (const key in properties) {
if (value[key] !== undefined && (child = validateSchema(properties[key], value[key], `${path}.${key}`)) != null) {
return child;
}
}
return null;
};
const validatePatternProperties = (validatedProperties, patternProperties, keys, value, path) => {
let child;
for (const pattern in patternProperties) {
const propertyRe = new RegExp(pattern);
for (let idx = 0; idx < keys.length; idx++) {
const key = keys[idx];
const childSchema = patternProperties[pattern];
if (propertyRe.test(key)) {
validatedProperties.add(key);
if ((child = validateSchema(childSchema, value[key], `${path}.${key}`)) != null) {
return child;
}
}
}
}
return null;
};
const validateAdditionalProperties = (additionalProperties, properties, visitedPatternProperties, keys, value, path) => {
if (additionalProperties === true) {
return null;
}
let child;
for (let idx = 0; idx < keys.length; idx++) {
const key = keys[idx];
if (!visitedPatternProperties.has(key) && !properties?.[key]) {
if (additionalProperties === false) {
return {
message: `Additional property "${key}" is not allowed`,
keyword: 'additionalProperties',
path: `${path}.${key}`,
value: value[key]
};
} else if ((child = validateSchema(additionalProperties, value[key], `${path}.${key}`)) != null) {
return child;
}
}
}
return null;
};
const validatePropertyNames = (propertyNames, keys, path) => {
let child;
for (let idx = 0; idx < keys.length; idx++) {
const key = keys[idx];
if ((child = validateString(propertyNames, key, `${path}.${key}`)) != null) {
child.message = `Property name "${key}" does not match schema. ${child.message}`;
return child;
}
}
return null;
};
const validateDependencies = (dependencies, value, path) => {
let child;
for (const key in dependencies) {
if (value[key] !== undefined) {
if (Array.isArray(dependencies[key])) {
for (let idx = 0; idx < dependencies[key].length; idx++) {
if (value[dependencies[key][idx]] === undefined) {
return {
message: `Property "${dependencies[key][idx]}" is required when "${key}" is present`,
keyword: 'dependencies',
path: `${path}.${dependencies[key][idx]}`,
value: undefined
};
}
}
} else if (dependencies[key] != null && (child = validateSchema(dependencies[key], value, path)) != null) {
return child;
}
}
}
return null;
};
const validateObject = (schema, value, path) => {
const keys = Object.keys(value);
const visitedPatternProperties = new Set();
let child;
if (schema.minProperties != null && keys.length < schema.minProperties) {
return {
message: `Object must have at least ${schema.minProperties} properties`,
keyword: 'minProperties',
path,
value
};
} else if (schema.maxProperties != null && keys.length > schema.maxProperties) {
return {
message: `Object must have at most ${schema.maxProperties} properties`,
keyword: 'maxProperties',
path,
value
};
} else if (schema.required != null && (child = validateRequired(schema.required, value, path)) != null) {
return child;
} else if (schema.properties != null && (child = validateProperties(schema.properties, value, path)) != null) {
return child;
} else if (schema.patternProperties != null && (child = validatePatternProperties(visitedPatternProperties, schema.patternProperties, keys, value, path)) != null) {
return child;
} else if (schema.additionalProperties != null && (child = validateAdditionalProperties(schema.additionalProperties, schema.properties, visitedPatternProperties, keys, value, path)) != null) {
return child;
} else if (schema.propertyNames != null && (child = validatePropertyNames(schema.propertyNames, keys, path)) != null) {
return child;
} else if (schema.dependencies != null && (child = validateDependencies(schema.dependencies, value, path)) != null) {
return child;
} else {
return null;
}
};
const validateType = (schemaType, valueType, path) => {
if (Array.isArray(schemaType)) {
if (valueType === 'integer' && schemaType.includes('number')) {
return null;
}
return !schemaType.includes(valueType) ? {
message: `Expected type ${schemaType.join(' or ')}, got ${valueType}`,
keyword: 'type',
path,
value: undefined
} : null;
} else {
if (valueType === 'integer' && schemaType === 'number') {
return null;
}
return schemaType !== valueType ? {
message: `Expected type ${schemaType}, got ${valueType}`,
keyword: 'type',
path,
value: undefined
} : null;
}
};
const validateAllOf = (schemas, value, path) => {
let child;
for (let idx = 0; idx < schemas.length; idx++) {
if ((child = validateSchema(schemas[idx], value, path)) != null) {
return child;
}
}
return null;
};
const validateAnyOf = (schemas, value, path) => {
let child;
const cause = [];
for (let idx = 0; idx < schemas.length; idx++) {
if ((child = validateSchema(schemas[idx], value, path)) != null) {
cause.push(child);
} else {
return null;
}
}
return {
message: 'No schema matched anyOf type',
keyword: 'anyOf',
path,
value,
cause
};
};
const validateOneOf = (schemas, value, path) => {
let child;
const cause = [];
for (let idx = 0; idx < schemas.length; idx++) {
if ((child = validateSchema(schemas[idx], value, path)) != null) {
cause.push(child);
}
}
if (cause.length >= schemas.length) {
return {
message: 'Value does not match any of the oneOf schemas',
keyword: 'oneOf',
path,
value,
cause
};
} else if (cause.length < schemas.length - 1) {
return {
message: `Value matches ${schemas.length - cause.length} schemas, but exactly one is required`,
keyword: 'oneOf',
path,
value,
cause
};
} else {
return null;
}
};
const validateConditional = (ifSchema, thenSchema, elseSchema, value, path) => {
let child;
if (validateSchema(ifSchema, value, path) != null) {
if (elseSchema != null && (child = validateSchema(elseSchema, value, path)) != null) {
return {
message: 'Value does not match "else" schema but did not match "if" condition schema',
keyword: 'else',
path,
value,
cause: [child]
};
} else {
return null;
}
} else if (thenSchema != null && (child = validateSchema(thenSchema, value, path)) != null) {
return {
message: 'Value does not match "then" schema but did match "if" condition schema',
keyword: 'then',
path,
value,
cause: [child]
};
} else {
return null;
}
};
const validateSchema = (schema, value, path) => {
if (typeof schema === 'boolean') {
// Draft 07: Schemas can be booleans
return !schema ? {
message: 'Schema is false',
keyword: 'schema',
path,
value: undefined
} : null;
}
const valueType = getValueType(value);
let child;
if (schema.type !== undefined && (child = validateType(schema.type, valueType, path)) != null) {
return child;
} else if (schema.const !== undefined && !isDeepEqual(value, schema.const)) {
return {
message: `Value must be equal to ${JSON.stringify(schema.const)}`,
keyword: 'const',
path,
value
};
} else if (schema.enum != null && !isEnumValue(schema.enum, value)) {
return {
message: `Value must be one of ${JSON.stringify(schema.enum)}`,
keyword: 'enum',
path,
value
};
} else if (schema.allOf != null && (child = validateAllOf(schema.allOf, value, path)) != null) {
return child;
} else if (schema.anyOf != null && (child = validateAnyOf(schema.anyOf, value, path)) != null) {
return child;
} else if (schema.oneOf != null && (child = validateOneOf(schema.oneOf, value, path)) != null) {
return child;
} else if (schema.not != null && validateSchema(schema.not, value, path) == null) {
return {
message: 'Value matches the not schema, but should not',
keyword: 'not',
path,
value
};
} else if (schema.if != null && (schema.then != null || schema.else != null) && (child = validateConditional(schema.if, schema.then, schema.else, value, path)) != null) {
return child;
}
switch (valueType) {
case 'string':
return validateString(schema, value, path);
case 'number':
case 'integer':
return validateNumber(schema, value, path);
case 'array':
return validateArray(schema, value, path);
case 'object':
return validateObject(schema, value, path);
default:
return null;
}
};
exports.validateSchema = validateSchema;
//# sourceMappingURL=validate.js.map

File diff suppressed because one or more lines are too long