json-schema-library 5.3.0 → 7.0.0
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/.editorconfig +1 -0
- package/.prettierignore +1 -0
- package/.prettierrc +7 -0
- package/CHANGELOG.md +106 -0
- package/README.md +811 -199
- package/TASKS.md +3 -81
- package/dist/index.d.ts +29 -71
- package/dist/jsonSchemaLibrary.js +1 -1
- package/dist/lib/SchemaService.d.ts +6 -8
- package/dist/lib/{addSchema.d.ts → addRemoteSchema.d.ts} +2 -1
- package/dist/lib/addValidator.d.ts +3 -2
- package/dist/lib/compile/getRef.d.ts +2 -1
- package/dist/lib/compile/index.d.ts +15 -1
- package/dist/lib/compile/types.d.ts +5 -0
- package/dist/lib/config/strings.d.ts +1 -39
- package/dist/lib/draft/index.d.ts +132 -0
- package/dist/lib/draft04/index.d.ts +7 -0
- package/dist/lib/draft06/compile/index.d.ts +16 -0
- package/dist/lib/draft06/index.d.ts +7 -0
- package/dist/lib/draft06/validation/keyword.d.ts +3 -0
- package/dist/lib/draft06/validation/type.d.ts +10 -0
- package/dist/lib/draft06/validation/typeKeywordMapping.d.ts +13 -0
- package/dist/lib/draft07/index.d.ts +7 -0
- package/dist/lib/each.d.ts +3 -2
- package/dist/lib/eachSchema.d.ts +2 -4
- package/dist/lib/getChildSchemaSelection.d.ts +7 -5
- package/dist/lib/getSchema.d.ts +2 -2
- package/dist/lib/getTemplate.d.ts +1 -1
- package/dist/lib/getTypeOf.d.ts +2 -1
- package/dist/lib/isValid.d.ts +1 -1
- package/dist/lib/jsoneditor/index.d.ts +7 -0
- package/dist/lib/resolveAllOf.d.ts +1 -1
- package/dist/lib/resolveAnyOf.d.ts +1 -1
- package/dist/lib/resolveOneOf.fuzzy.d.ts +1 -1
- package/dist/lib/resolveOneOf.strict.d.ts +2 -2
- package/dist/lib/{resolveRef.withOverwrite.d.ts → resolveRef.merge.d.ts} +0 -0
- package/dist/lib/schema/getTypeDefs.d.ts +6 -4
- package/dist/lib/schema/getTypeId.d.ts +1 -1
- package/dist/lib/schema/types.d.ts +7 -57
- package/dist/lib/step.d.ts +5 -5
- package/dist/lib/types.d.ts +11 -3
- package/dist/lib/utils/createCustomError.d.ts +8 -11
- package/dist/lib/utils/filter.d.ts +4 -4
- package/dist/lib/utils/flattenArray.d.ts +1 -1
- package/dist/lib/utils/merge.d.ts +3 -0
- package/dist/lib/utils/punycode.ucs2decode.d.ts +1 -1
- package/dist/lib/validate.d.ts +2 -2
- package/dist/lib/validateAsync.d.ts +1 -1
- package/dist/lib/validation/errors.d.ts +1 -3
- package/dist/lib/validation/format.d.ts +4 -11
- package/dist/lib/validation/keyword.d.ts +2 -27
- package/dist/lib/validation/type.d.ts +3 -10
- package/dist/lib/validation/typeKeywordMapping.d.ts +4 -4
- package/dist/module/index.js +23 -32
- package/dist/module/lib/SchemaService.js +7 -4
- package/dist/module/lib/{addSchema.js → addRemoteSchema.js} +2 -4
- package/dist/module/lib/addValidator.js +3 -4
- package/dist/module/lib/compile/getRef.js +1 -1
- package/dist/module/lib/compile/index.js +43 -18
- package/dist/module/lib/compile/types.js +1 -0
- package/dist/module/lib/config/strings.js +15 -2
- package/dist/module/lib/createSchemaOf.js +1 -1
- package/dist/module/lib/draft/index.js +133 -0
- package/dist/module/lib/draft04/index.js +90 -0
- package/dist/module/lib/draft06/compile/index.js +77 -0
- package/dist/module/lib/draft06/index.js +96 -0
- package/dist/module/lib/draft06/validation/keyword.js +168 -0
- package/dist/module/lib/draft06/validation/type.js +31 -0
- package/dist/module/lib/draft06/validation/typeKeywordMapping.js +15 -0
- package/dist/module/lib/draft07/index.js +96 -0
- package/dist/module/lib/each.js +2 -2
- package/dist/module/lib/eachSchema.js +28 -19
- package/dist/module/lib/getChildSchemaSelection.js +7 -6
- package/dist/module/lib/getSchema.js +4 -2
- package/dist/module/lib/getTemplate.js +42 -15
- package/dist/module/lib/jsoneditor/index.js +16 -0
- package/dist/module/lib/resolveAllOf.js +3 -4
- package/dist/module/lib/resolveOneOf.fuzzy.js +13 -3
- package/dist/module/lib/resolveOneOf.strict.js +49 -2
- package/dist/module/lib/{resolveRef.withOverwrite.js → resolveRef.merge.js} +0 -0
- package/dist/module/lib/resolveRef.strict.js +8 -0
- package/dist/module/lib/schema/getTypeDefs.js +14 -3
- package/dist/module/lib/schema/getTypeId.js +10 -6
- package/dist/module/lib/schema/types.js +33 -9
- package/dist/module/lib/step.js +67 -13
- package/dist/module/lib/types.js +7 -1
- package/dist/module/lib/utils/createCustomError.js +4 -4
- package/dist/module/lib/utils/filter.js +3 -5
- package/dist/module/lib/utils/flattenArray.js +4 -3
- package/dist/module/lib/utils/merge.js +4 -0
- package/dist/module/lib/utils/punycode.ucs2decode.js +4 -3
- package/dist/module/lib/validate.js +34 -8
- package/dist/module/lib/validateAsync.js +7 -7
- package/dist/module/lib/validation/errors.js +16 -3
- package/dist/module/lib/validation/format.js +115 -8
- package/dist/module/lib/validation/keyword.js +79 -32
- package/dist/module/lib/validation/type.js +2 -1
- package/index.ts +46 -32
- package/lib/SchemaService.ts +18 -11
- package/lib/{addSchema.ts → addRemoteSchema.ts} +3 -5
- package/lib/addValidator.ts +15 -12
- package/lib/compile/getRef.ts +3 -4
- package/lib/compile/index.ts +65 -19
- package/lib/compile/types.ts +6 -0
- package/lib/config/strings.ts +17 -3
- package/lib/createSchemaOf.ts +1 -3
- package/lib/draft/index.ts +201 -0
- package/lib/draft04/index.ts +95 -0
- package/lib/draft06/compile/index.ts +104 -0
- package/lib/draft06/index.ts +101 -0
- package/lib/draft06/validation/keyword.ts +199 -0
- package/lib/draft06/validation/type.ts +47 -0
- package/lib/draft06/validation/typeKeywordMapping.ts +15 -0
- package/lib/draft07/index.ts +101 -0
- package/lib/each.ts +11 -4
- package/lib/eachSchema.ts +45 -32
- package/lib/getChildSchemaSelection.ts +14 -7
- package/lib/getSchema.ts +18 -9
- package/lib/getTemplate.ts +155 -42
- package/lib/getTypeOf.ts +2 -1
- package/lib/isValid.ts +7 -3
- package/lib/jsoneditor/index.ts +20 -0
- package/lib/resolveAllOf.ts +10 -6
- package/lib/resolveAnyOf.ts +7 -3
- package/lib/resolveOneOf.fuzzy.ts +26 -9
- package/lib/resolveOneOf.strict.ts +63 -5
- package/lib/{resolveRef.withOverwrite.ts → resolveRef.merge.ts} +0 -0
- package/lib/resolveRef.strict.ts +9 -0
- package/lib/schema/getTypeDefs.ts +19 -7
- package/lib/schema/getTypeId.ts +11 -8
- package/lib/schema/types.ts +41 -9
- package/lib/step.ts +109 -25
- package/lib/types.ts +23 -5
- package/lib/utils/createCustomError.ts +8 -13
- package/lib/utils/filter.ts +7 -9
- package/lib/utils/flattenArray.ts +5 -4
- package/lib/utils/merge.ts +5 -0
- package/lib/utils/punycode.ucs2decode.ts +6 -5
- package/lib/validate.ts +47 -16
- package/lib/validateAsync.ts +15 -14
- package/lib/validation/errors.ts +17 -6
- package/lib/validation/format.ts +147 -13
- package/lib/validation/keyword.ts +172 -103
- package/lib/validation/type.ts +5 -1
- package/package.json +75 -63
- package/{dist/module/remotes/draft04.json → remotes/draft06.json} +47 -42
- package/remotes/draft07.json +172 -0
- package/remotes/draft2019-09.json +86 -0
- package/tsconfig.json +3 -10
- package/dist/lib/cores/CoreInterface.d.ts +0 -23
- package/dist/lib/cores/Draft04.d.ts +0 -13
- package/dist/lib/cores/JsonEditor.d.ts +0 -13
- package/dist/module/lib/cores/CoreInterface.js +0 -51
- package/dist/module/lib/cores/Draft04.js +0 -52
- package/dist/module/lib/cores/JsonEditor.js +0 -51
- package/dist/module/remotes/index.js +0 -10
- package/dist/remotes/index.d.ts +0 -5
- package/lib/cores/CoreInterface.ts +0 -76
- package/lib/cores/Draft04.ts +0 -66
- package/lib/cores/JsonEditor.ts +0 -64
- package/remotes/index.ts +0 -11
|
@@ -1,5 +1,6 @@
|
|
|
1
|
-
import Core from "./
|
|
1
|
+
import { Draft as Core } from "./draft";
|
|
2
2
|
import { JSONValidator } from "./types";
|
|
3
|
+
import { CreateError } from "./utils/createCustomError";
|
|
3
4
|
/**
|
|
4
5
|
* @throws Error
|
|
5
6
|
* Adds a custom error. May override existing errors
|
|
@@ -8,7 +9,7 @@ import { JSONValidator } from "./types";
|
|
|
8
9
|
* @param errorId id of error @see /lib/validation/errors
|
|
9
10
|
* @param errorCreator - function returning an error-object @see /lib/utils/createCustomError
|
|
10
11
|
*/
|
|
11
|
-
declare function addError(core: Core, errorId: string, errorCreator:
|
|
12
|
+
declare function addError(core: Core, errorId: string, errorCreator: CreateError): void;
|
|
12
13
|
/**
|
|
13
14
|
* Adds a custom format validator. Existing format may not be overriden (may still be modified manually)
|
|
14
15
|
* @param core
|
|
@@ -1,2 +1,16 @@
|
|
|
1
|
+
import { Draft } from "../draft";
|
|
1
2
|
import { JSONSchema } from "../types";
|
|
2
|
-
|
|
3
|
+
/**
|
|
4
|
+
* compiles the input root schema for `$ref` resolution and returns it again
|
|
5
|
+
* @attention this modifies input schema but maintains object-structure
|
|
6
|
+
*
|
|
7
|
+
* for a compiled json-schema you can call getRef on any contained schema (location of type).
|
|
8
|
+
* this resolves a $ref target to a valid schema (for a valid $ref)
|
|
9
|
+
*
|
|
10
|
+
* @param draft
|
|
11
|
+
* @param schemaToCompile - json-schema to compile
|
|
12
|
+
* @param [rootSchema] - compiled root json-schema to use for definitions resolution
|
|
13
|
+
* @param [force] = false - force compile json-schema
|
|
14
|
+
* @return compiled copy of input json-schema
|
|
15
|
+
*/
|
|
16
|
+
export default function compileSchema(draft: Draft, schemaToCompile: JSONSchema, rootSchema?: JSONSchema, force?: boolean): JSONSchema;
|
|
@@ -1,40 +1,2 @@
|
|
|
1
|
-
declare const _default:
|
|
2
|
-
AdditionalItemsError: string;
|
|
3
|
-
AdditionalPropertiesError: string;
|
|
4
|
-
AnyOfError: string;
|
|
5
|
-
AllOfError: string;
|
|
6
|
-
EnumError: string;
|
|
7
|
-
FormatDateTimeError: string;
|
|
8
|
-
FormatEmailError: string;
|
|
9
|
-
FormatUrlError: string;
|
|
10
|
-
FormatUriError: string;
|
|
11
|
-
FormatHostnameError: string;
|
|
12
|
-
FormatIPV4Error: string;
|
|
13
|
-
FormatIPV6Error: string;
|
|
14
|
-
FormatRegExError: string;
|
|
15
|
-
MaximumError: string;
|
|
16
|
-
MaxItemsError: string;
|
|
17
|
-
MaxLengthError: string;
|
|
18
|
-
MaxPropertiesError: string;
|
|
19
|
-
MinimumError: string;
|
|
20
|
-
MinItemsError: string;
|
|
21
|
-
MinLengthError: string;
|
|
22
|
-
MinPropertiesError: string;
|
|
23
|
-
MissingOneOfPropertyError: string;
|
|
24
|
-
MissingDependencyError: string;
|
|
25
|
-
MultipleOfError: string;
|
|
26
|
-
MultipleOneOfError: string;
|
|
27
|
-
NoAdditionalPropertiesError: string;
|
|
28
|
-
NotError: string;
|
|
29
|
-
OneOfError: string;
|
|
30
|
-
OneOfPropertyError: string;
|
|
31
|
-
PatternError: string;
|
|
32
|
-
PatternPropertiesError: string;
|
|
33
|
-
RequiredPropertyError: string;
|
|
34
|
-
TypeError: string;
|
|
35
|
-
UndefinedValueError: string;
|
|
36
|
-
UnknownPropertyError: string;
|
|
37
|
-
UniqueItemsError: string;
|
|
38
|
-
ValueNotEmptyError: string;
|
|
39
|
-
};
|
|
1
|
+
declare const _default: Record<string, string>;
|
|
40
2
|
export default _default;
|
|
@@ -0,0 +1,132 @@
|
|
|
1
|
+
import step from "../step";
|
|
2
|
+
import validate from "../validate";
|
|
3
|
+
import resolveOneOf from "../resolveOneOf.strict";
|
|
4
|
+
import resolveRef from "../resolveRef.strict";
|
|
5
|
+
import resolveAllOf from "../resolveAllOf";
|
|
6
|
+
import resolveAnyOf from "../resolveAnyOf";
|
|
7
|
+
import getTemplate from "../getTemplate";
|
|
8
|
+
import getChildSchemaSelection from "../getChildSchemaSelection";
|
|
9
|
+
import getSchema from "../getSchema";
|
|
10
|
+
import { each, EachCallback } from "../each";
|
|
11
|
+
import isValid from "../isValid";
|
|
12
|
+
import { eachSchema, EachSchemaCallback } from "../eachSchema";
|
|
13
|
+
import createSchemaOf from "../createSchemaOf";
|
|
14
|
+
import compileSchema from "../compileSchema";
|
|
15
|
+
import { CreateError } from "../utils/createCustomError";
|
|
16
|
+
import addRemoteSchema from "../addRemoteSchema";
|
|
17
|
+
import { JSONSchema, JSONPointer, JSONValidator, JSONTypeValidator, JSONError } from "../types";
|
|
18
|
+
export declare type DraftConfig = {
|
|
19
|
+
/** error creators by id */
|
|
20
|
+
errors: Record<string, CreateError>;
|
|
21
|
+
/** map for valid keywords of a type */
|
|
22
|
+
typeKeywords: Record<string, string[]>;
|
|
23
|
+
/** keyword validators */
|
|
24
|
+
validateKeyword: Record<string, JSONValidator>;
|
|
25
|
+
/** type validators */
|
|
26
|
+
validateType: Record<string, JSONTypeValidator>;
|
|
27
|
+
/** format validators */
|
|
28
|
+
validateFormat: Record<string, JSONValidator>;
|
|
29
|
+
addRemoteSchema: typeof addRemoteSchema;
|
|
30
|
+
compileSchema: typeof compileSchema;
|
|
31
|
+
createSchemaOf: typeof createSchemaOf;
|
|
32
|
+
each: typeof each;
|
|
33
|
+
eachSchema: typeof eachSchema;
|
|
34
|
+
getChildSchemaSelection: typeof getChildSchemaSelection;
|
|
35
|
+
getSchema: typeof getSchema;
|
|
36
|
+
getTemplate: typeof getTemplate;
|
|
37
|
+
isValid: typeof isValid;
|
|
38
|
+
resolveAllOf: typeof resolveAllOf;
|
|
39
|
+
resolveAnyOf: typeof resolveAnyOf;
|
|
40
|
+
resolveOneOf: typeof resolveOneOf;
|
|
41
|
+
resolveRef: typeof resolveRef;
|
|
42
|
+
step: typeof step;
|
|
43
|
+
validate: typeof validate;
|
|
44
|
+
};
|
|
45
|
+
export declare class Draft {
|
|
46
|
+
readonly config: DraftConfig;
|
|
47
|
+
/** entry point of schema */
|
|
48
|
+
private __rootSchema;
|
|
49
|
+
/** cache for remote schemas */
|
|
50
|
+
remotes: Record<string, JSONSchema>;
|
|
51
|
+
/** error creators by id */
|
|
52
|
+
readonly errors: Record<string, CreateError>;
|
|
53
|
+
/** map for valid keywords of a type */
|
|
54
|
+
readonly typeKeywords: Record<string, string[]>;
|
|
55
|
+
/** keyword validators */
|
|
56
|
+
readonly validateKeyword: Record<string, JSONValidator>;
|
|
57
|
+
/** type validators */
|
|
58
|
+
readonly validateType: Record<string, JSONTypeValidator>;
|
|
59
|
+
/** format validators */
|
|
60
|
+
readonly validateFormat: Record<string, JSONValidator>;
|
|
61
|
+
constructor(config: DraftConfig, schema?: JSONSchema);
|
|
62
|
+
get rootSchema(): JSONSchema;
|
|
63
|
+
set rootSchema(rootSchema: JSONSchema);
|
|
64
|
+
/**
|
|
65
|
+
* register a json-schema to be referenced from another json-schema
|
|
66
|
+
* @param url - base-url of json-schema (aka id)
|
|
67
|
+
* @param schema - json-schema root
|
|
68
|
+
*/
|
|
69
|
+
addRemoteSchema(url: string, schema: JSONSchema): void;
|
|
70
|
+
compileSchema(schema: JSONSchema): JSONSchema;
|
|
71
|
+
createSchemaOf(data: unknown): JSONSchema;
|
|
72
|
+
/**
|
|
73
|
+
* Iterates over data, retrieving its schema
|
|
74
|
+
*
|
|
75
|
+
* @param data - the data to iterate
|
|
76
|
+
* @param callback - will be called with (schema, data, pointer) on each item
|
|
77
|
+
* @param [schema] - the schema matching the data. Defaults to rootSchema
|
|
78
|
+
* @param [pointer] - pointer to current data. Default to rootPointer
|
|
79
|
+
*/
|
|
80
|
+
each(data: any, callback: EachCallback, schema?: JSONSchema, pointer?: JSONPointer): void;
|
|
81
|
+
eachSchema(callback: EachSchemaCallback, schema?: JSONSchema): void;
|
|
82
|
+
getChildSchemaSelection(property: string | number, schema?: JSONSchema): JSONError | JSONSchema[];
|
|
83
|
+
/**
|
|
84
|
+
* Returns the json-schema of a data-json-pointer.
|
|
85
|
+
* Notes
|
|
86
|
+
* - Uses core.step to walk through data and schema
|
|
87
|
+
*
|
|
88
|
+
* @param pointer - json pointer in data to get the json schema for
|
|
89
|
+
* @param [data] - the data object, which includes the json pointers value. This is optional, as
|
|
90
|
+
* long as no oneOf, anyOf, etc statement is part of the pointers schema
|
|
91
|
+
* @param [schema] - the json schema to iterate. Defaults to core.rootSchema
|
|
92
|
+
* @return json schema object of the json-pointer or an error
|
|
93
|
+
*/
|
|
94
|
+
getSchema(pointer?: JSONPointer, data?: any, schema?: JSONSchema): JSONSchema | JSONError;
|
|
95
|
+
/**
|
|
96
|
+
* Create data object matching the given schema
|
|
97
|
+
*
|
|
98
|
+
* @param [data] - optional template data
|
|
99
|
+
* @param [schema] - json schema, defaults to rootSchema
|
|
100
|
+
* @return created template data
|
|
101
|
+
*/
|
|
102
|
+
getTemplate(data?: unknown, schema?: JSONSchema): any;
|
|
103
|
+
isValid(data: any, schema?: JSONSchema, pointer?: JSONPointer): boolean;
|
|
104
|
+
resolveAnyOf(data: any, schema: JSONSchema, pointer?: JSONPointer): JSONSchema;
|
|
105
|
+
resolveAllOf(data: any, schema: JSONSchema, pointer?: JSONPointer): JSONSchema;
|
|
106
|
+
resolveRef(schema: JSONSchema): JSONSchema;
|
|
107
|
+
resolveOneOf(data: any, schema: JSONSchema, pointer?: JSONPointer): JSONSchema;
|
|
108
|
+
setSchema(schema: JSONSchema): void;
|
|
109
|
+
/**
|
|
110
|
+
* Returns the json-schema of the given object property or array item.
|
|
111
|
+
* e.g. it steps by one key into the data
|
|
112
|
+
*
|
|
113
|
+
* This helper determines the location of the property within the schema (additional properties, oneOf, ...) and
|
|
114
|
+
* returns the correct schema.
|
|
115
|
+
*
|
|
116
|
+
* @param key - property-name or array-index
|
|
117
|
+
* @param schema - json schema of current data
|
|
118
|
+
* @param data - parent of key
|
|
119
|
+
* @param [pointer] - pointer to schema and data (parent of key)
|
|
120
|
+
* @return Schema or Error if failed resolving key
|
|
121
|
+
*/
|
|
122
|
+
step(key: string | number, schema: JSONSchema, data: any, pointer?: JSONPointer): JSONSchema;
|
|
123
|
+
/**
|
|
124
|
+
* Validate data by a json schema
|
|
125
|
+
*
|
|
126
|
+
* @param value - value to validate
|
|
127
|
+
* @param [schema] - json schema, defaults to rootSchema
|
|
128
|
+
* @param [pointer] - json pointer pointing to value (used for error-messages only)
|
|
129
|
+
* @return list of errors or empty
|
|
130
|
+
*/
|
|
131
|
+
validate(data: unknown, schema?: JSONSchema, pointer?: JSONPointer): JSONError[];
|
|
132
|
+
}
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import { DraftConfig, Draft } from "../draft";
|
|
2
|
+
import { JSONSchema } from "../types";
|
|
3
|
+
declare const draft04Config: DraftConfig;
|
|
4
|
+
declare class Draft04 extends Draft {
|
|
5
|
+
constructor(schema?: JSONSchema, config?: Partial<DraftConfig>);
|
|
6
|
+
}
|
|
7
|
+
export { Draft04, draft04Config };
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import { Draft } from "../../draft";
|
|
2
|
+
import { JSONSchema } from "../../types";
|
|
3
|
+
/**
|
|
4
|
+
* @draft starting with _draft 06_ keyword `id` has been renamed to `$id`
|
|
5
|
+
*
|
|
6
|
+
* compiles the input root schema for $ref resolution and returns it again
|
|
7
|
+
* @attention this modifies input schema but maintains object-structure
|
|
8
|
+
*
|
|
9
|
+
* for a compiled json-schema you can call getRef on any contained schema (location of type).
|
|
10
|
+
* this resolves a $ref target to a valid schema (for a valid $ref)
|
|
11
|
+
*
|
|
12
|
+
* @param rootSchema root json-schema ($id, defs, ... ) to compile
|
|
13
|
+
* @param [force] = false force compile json-schema
|
|
14
|
+
* @return compiled json-schema
|
|
15
|
+
*/
|
|
16
|
+
export default function compileSchema(draft: Draft, schemaToCompile: JSONSchema, rootSchema?: JSONSchema, force?: boolean): JSONSchema;
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import { DraftConfig, Draft } from "../draft";
|
|
2
|
+
import { JSONSchema } from "../types";
|
|
3
|
+
declare const draft06Config: DraftConfig;
|
|
4
|
+
declare class Draft06 extends Draft {
|
|
5
|
+
constructor(schema?: JSONSchema, config?: Partial<DraftConfig>);
|
|
6
|
+
}
|
|
7
|
+
export { Draft06, draft06Config };
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import { JSONTypeValidator } from "../../types";
|
|
2
|
+
/**
|
|
3
|
+
* @todo: type is also a keyword, as is properties, items, etc
|
|
4
|
+
*
|
|
5
|
+
* An instance has one of six primitive types (http://json-schema.org/latest/json-schema-core.html#rfc.section.4.2)
|
|
6
|
+
* or seven in case of ajv https://github.com/epoberezkin/ajv/blob/master/KEYWORDS.md#type
|
|
7
|
+
* 1 null, 2 boolean, 3 object, 4 array, 5 number, 6 string (7 integer)
|
|
8
|
+
*/
|
|
9
|
+
declare const validationType: Record<string, JSONTypeValidator>;
|
|
10
|
+
export default validationType;
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Mapping, used in type validation to iterate over type-specific keywords to validate
|
|
3
|
+
* - overview https://epoberezkin.github.io/ajv/keywords.html
|
|
4
|
+
*/
|
|
5
|
+
declare const _default: {
|
|
6
|
+
array: string[];
|
|
7
|
+
boolean: string[];
|
|
8
|
+
object: string[];
|
|
9
|
+
string: string[];
|
|
10
|
+
number: string[];
|
|
11
|
+
null: string[];
|
|
12
|
+
};
|
|
13
|
+
export default _default;
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import { DraftConfig, Draft } from "../draft";
|
|
2
|
+
import { JSONSchema } from "../types";
|
|
3
|
+
declare const draft07Config: DraftConfig;
|
|
4
|
+
declare class Draft07 extends Draft {
|
|
5
|
+
constructor(schema?: JSONSchema, config?: Partial<DraftConfig>);
|
|
6
|
+
}
|
|
7
|
+
export { Draft07, draft07Config };
|
package/dist/lib/each.d.ts
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
|
-
import Core from "./
|
|
1
|
+
import { Draft as Core } from "./draft";
|
|
2
2
|
import { JSONSchema, JSONPointer } from "./types";
|
|
3
|
+
export declare type EachCallback = (schema: JSONSchema, data: unknown, pointer: JSONPointer) => void;
|
|
3
4
|
/**
|
|
4
5
|
* Iterates over data, retrieving its schema
|
|
5
6
|
*
|
|
@@ -9,4 +10,4 @@ import { JSONSchema, JSONPointer } from "./types";
|
|
|
9
10
|
* @param [schema] - the schema matching the data. Defaults to rootSchema
|
|
10
11
|
* @param [pointer] - pointer to current data. Default to rootPointer
|
|
11
12
|
*/
|
|
12
|
-
export
|
|
13
|
+
export declare function each(core: Core, data: any, callback: EachCallback, schema?: JSONSchema, pointer?: JSONPointer): void;
|
package/dist/lib/eachSchema.d.ts
CHANGED
|
@@ -1,5 +1,3 @@
|
|
|
1
1
|
import { JSONSchema, JSONPointer } from "./types";
|
|
2
|
-
export
|
|
3
|
-
|
|
4
|
-
}
|
|
5
|
-
export default function eachSchema(schema: JSONSchema, callback: OnSchema, pointer?: JSONPointer): void;
|
|
2
|
+
export declare type EachSchemaCallback = (schema: JSONSchema, pointer: JSONPointer) => void;
|
|
3
|
+
export declare function eachSchema(schema: JSONSchema, callback: EachSchemaCallback, pointer?: JSONPointer): void;
|
|
@@ -1,11 +1,13 @@
|
|
|
1
|
+
import { Draft } from "./draft";
|
|
2
|
+
import { JSONError, JSONSchema } from "./types";
|
|
1
3
|
/**
|
|
2
4
|
* Returns a list of possible child-schemas for the given property key. In case of a oneOf selection, multiple schemas
|
|
3
5
|
* could be added at the given property (e.g. item-index), thus an array of options is returned. In all other cases
|
|
4
6
|
* a list with a single item will be returned
|
|
5
7
|
*
|
|
6
|
-
* @param
|
|
7
|
-
* @param
|
|
8
|
-
* @param
|
|
9
|
-
* @return
|
|
8
|
+
* @param core - core to use
|
|
9
|
+
* @param property - parent schema of following property
|
|
10
|
+
* @param [schema] - parent schema of following property
|
|
11
|
+
* @return
|
|
10
12
|
*/
|
|
11
|
-
export default function getChildSchemaSelection(core:
|
|
13
|
+
export default function getChildSchemaSelection(core: Draft, property: string | number, schema?: JSONSchema): JSONSchema[] | JSONError;
|
package/dist/lib/getSchema.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { JSONSchema, JSONPointer } from "./types";
|
|
2
|
-
import Core from "./
|
|
2
|
+
import { Draft as Core } from "./draft";
|
|
3
3
|
/**
|
|
4
4
|
* Returns the json-schema of a data-json-pointer.
|
|
5
5
|
*
|
|
@@ -13,4 +13,4 @@ import Core from "./cores/CoreInterface";
|
|
|
13
13
|
* @param [schema] - the json schema to iterate. Defaults to core.rootSchema
|
|
14
14
|
* @return json schema object of the json-pointer or an error
|
|
15
15
|
*/
|
|
16
|
-
export default function getSchema(core: Core, pointer: JSONPointer, data?:
|
|
16
|
+
export default function getSchema(core: Core, pointer: JSONPointer, data?: unknown, schema?: JSONSchema): JSONSchema;
|
package/dist/lib/getTypeOf.d.ts
CHANGED
|
@@ -1 +1,2 @@
|
|
|
1
|
-
export
|
|
1
|
+
export declare type JSType = "array" | "bigint" | "boolean" | "function" | "null" | "number" | "object" | "string" | "symbol" | "undefined";
|
|
2
|
+
export default function getTypeOf(value: unknown): JSType;
|
package/dist/lib/isValid.d.ts
CHANGED
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import { Draft, DraftConfig } from "../draft";
|
|
2
|
+
import { JSONSchema } from "../types";
|
|
3
|
+
declare const draftJsonEditorConfig: DraftConfig;
|
|
4
|
+
declare class JsonEditor extends Draft {
|
|
5
|
+
constructor(schema?: JSONSchema, config?: Partial<DraftConfig>);
|
|
6
|
+
}
|
|
7
|
+
export { JsonEditor, draftJsonEditorConfig };
|
|
@@ -1,3 +1,3 @@
|
|
|
1
1
|
import { JSONSchema, JSONPointer, JSONError } from "./types";
|
|
2
|
-
import Core from "./
|
|
2
|
+
import { Draft as Core } from "./draft";
|
|
3
3
|
export default function resolveAllOf(core: Core, data: any, schema?: JSONSchema, pointer?: JSONPointer): JSONSchema | JSONError;
|
|
@@ -1,3 +1,3 @@
|
|
|
1
1
|
import { JSONSchema, JSONPointer, JSONError } from "./types";
|
|
2
|
-
import Core from "./
|
|
2
|
+
import { Draft as Core } from "./draft";
|
|
3
3
|
export default function resolveAnyOf(core: Core, data: any, schema?: JSONSchema, pointer?: JSONPointer): JSONSchema | JSONError;
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import
|
|
2
|
-
import {
|
|
1
|
+
import { JSONSchema, JSONPointer, JSONError } from "./types";
|
|
2
|
+
import { Draft as Core } from "./draft";
|
|
3
3
|
/**
|
|
4
4
|
* Selects and returns a oneOf schema for the given data
|
|
5
5
|
*
|
|
File without changes
|
|
@@ -1,10 +1,12 @@
|
|
|
1
1
|
import { JSONSchema, JSONPointer } from "../types";
|
|
2
|
+
declare type TypeDef = {
|
|
3
|
+
pointer: JSONPointer;
|
|
4
|
+
def: unknown;
|
|
5
|
+
};
|
|
2
6
|
/**
|
|
3
7
|
* Returns a list of all (direct) type definitions from the given schema
|
|
4
8
|
* @param schema
|
|
5
9
|
* @return list of type definition, given as { pointer, def }
|
|
6
10
|
*/
|
|
7
|
-
export default function getTypeDefs(schema: JSONSchema):
|
|
8
|
-
|
|
9
|
-
def: any;
|
|
10
|
-
}>;
|
|
11
|
+
export default function getTypeDefs(schema: JSONSchema): TypeDef[];
|
|
12
|
+
export {};
|
|
@@ -1,58 +1,8 @@
|
|
|
1
|
-
declare
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
type: boolean;
|
|
7
|
-
definitions: string[];
|
|
8
|
-
};
|
|
9
|
-
anyOf: {
|
|
10
|
-
type: boolean;
|
|
11
|
-
definitions: string[];
|
|
12
|
-
};
|
|
13
|
-
array: {
|
|
14
|
-
type: boolean;
|
|
15
|
-
definitions: string[];
|
|
16
|
-
validationKeywords: string[];
|
|
17
|
-
keywords: string[];
|
|
18
|
-
};
|
|
19
|
-
boolean: {
|
|
20
|
-
type: boolean;
|
|
21
|
-
};
|
|
22
|
-
enum: {
|
|
23
|
-
type: boolean;
|
|
24
|
-
};
|
|
25
|
-
integer: {
|
|
26
|
-
type: boolean;
|
|
27
|
-
definitions: string[];
|
|
28
|
-
validationKeywords: string[];
|
|
29
|
-
};
|
|
30
|
-
not: {
|
|
31
|
-
type: boolean;
|
|
32
|
-
definitions: string[];
|
|
33
|
-
};
|
|
34
|
-
number: {
|
|
35
|
-
type: boolean;
|
|
36
|
-
definitions: string[];
|
|
37
|
-
validationKeywords: string[];
|
|
38
|
-
};
|
|
39
|
-
null: {
|
|
40
|
-
type: boolean;
|
|
41
|
-
};
|
|
42
|
-
object: {
|
|
43
|
-
type: boolean;
|
|
44
|
-
definitions: string[];
|
|
45
|
-
validationKeywords: string[];
|
|
46
|
-
keywords: string[];
|
|
47
|
-
};
|
|
48
|
-
oneOf: {
|
|
49
|
-
type: boolean;
|
|
50
|
-
definitions: string[];
|
|
51
|
-
};
|
|
52
|
-
string: {
|
|
53
|
-
type: boolean;
|
|
54
|
-
definitions: string[];
|
|
55
|
-
validationKeywords: string[];
|
|
56
|
-
};
|
|
1
|
+
export declare type Type = {
|
|
2
|
+
type: boolean;
|
|
3
|
+
definitions?: string[];
|
|
4
|
+
validationKeywords?: string[];
|
|
5
|
+
keywords?: string[];
|
|
57
6
|
};
|
|
58
|
-
|
|
7
|
+
declare const Types: Record<string, Type>;
|
|
8
|
+
export default Types;
|
package/dist/lib/step.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { JSONSchema, JSONPointer, JSONError } from "./types";
|
|
2
|
-
import Core from "./
|
|
2
|
+
import { Draft as Core } from "./draft";
|
|
3
3
|
/**
|
|
4
4
|
* Returns the json-schema of the given object property or array item.
|
|
5
5
|
* e.g. it steps by one key into the data
|
|
@@ -7,11 +7,11 @@ import Core from "./cores/CoreInterface";
|
|
|
7
7
|
* This helper determines the location of the property within the schema (additional properties, oneOf, ...) and
|
|
8
8
|
* returns the correct schema.
|
|
9
9
|
*
|
|
10
|
-
* @param core
|
|
11
|
-
* @param key
|
|
12
|
-
* @param schema
|
|
10
|
+
* @param core - validator
|
|
11
|
+
* @param key - property-name or array-index
|
|
12
|
+
* @param schema - json schema of current data
|
|
13
13
|
* @param data - parent of key
|
|
14
|
-
* @param [pointer]
|
|
14
|
+
* @param [pointer] - pointer to schema and data (parent of key)
|
|
15
15
|
* @return Schema or Error if failed resolving key
|
|
16
16
|
*/
|
|
17
17
|
export default function step(core: Core, key: string | number, schema: JSONSchema, data?: any, pointer?: JSONPointer): JSONSchema | JSONError;
|
package/dist/lib/types.d.ts
CHANGED
|
@@ -1,10 +1,10 @@
|
|
|
1
|
-
import Core from "./
|
|
1
|
+
import { Draft as Core } from "./draft";
|
|
2
2
|
export declare type JSONSchema = {
|
|
3
3
|
[p: string]: any;
|
|
4
4
|
};
|
|
5
5
|
export declare type JSONPointer = string;
|
|
6
6
|
export declare type JSONError = {
|
|
7
|
-
type: "error"
|
|
7
|
+
type: "error";
|
|
8
8
|
name: string;
|
|
9
9
|
code: string;
|
|
10
10
|
message: string;
|
|
@@ -13,6 +13,14 @@ export declare type JSONError = {
|
|
|
13
13
|
};
|
|
14
14
|
[p: string]: any;
|
|
15
15
|
};
|
|
16
|
+
/**
|
|
17
|
+
* ts type guard for json error
|
|
18
|
+
* @returns true if passed type is a JSONError
|
|
19
|
+
*/
|
|
20
|
+
export declare function isJSONError(error: any): error is JSONError;
|
|
16
21
|
export interface JSONValidator {
|
|
17
|
-
(core: Core, schema: JSONSchema, value:
|
|
22
|
+
(core: Core, schema: JSONSchema, value: unknown, pointer: JSONPointer): void | undefined | JSONError | JSONError[] | JSONError[][];
|
|
23
|
+
}
|
|
24
|
+
export interface JSONTypeValidator {
|
|
25
|
+
(core: Core, schema: JSONSchema, value: unknown, pointer: JSONPointer): Array<void | undefined | JSONError | JSONError[] | JSONError[][]>;
|
|
18
26
|
}
|
|
@@ -1,17 +1,14 @@
|
|
|
1
|
-
import { JSONError } from "../types";
|
|
2
|
-
export
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
export declare function createError(name: string, data?: {
|
|
8
|
-
[p: string]: any;
|
|
9
|
-
}): JSONError;
|
|
1
|
+
import { JSONError, JSONPointer } from "../types";
|
|
2
|
+
export declare type ErrorData = {
|
|
3
|
+
pointer: JSONPointer;
|
|
4
|
+
} & Record<string, unknown>;
|
|
5
|
+
export declare type CreateError = (data: ErrorData) => JSONError;
|
|
6
|
+
export declare function createError(name: string, data: ErrorData): JSONError;
|
|
10
7
|
/**
|
|
11
8
|
* Creates a custom Error-Constructor which instances may be identified by `customError instanceof Error`. Its messages
|
|
12
|
-
* are defined by strings-object
|
|
9
|
+
* are defined by strings-object @see config/strings.ts
|
|
13
10
|
*
|
|
14
11
|
* @param name - id of error (camelcased)
|
|
15
12
|
* @return error constructor function
|
|
16
13
|
*/
|
|
17
|
-
export
|
|
14
|
+
export declare function createCustomError(name: string): CreateError;
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
|
|
2
|
-
export declare function
|
|
3
|
-
export declare function errorOrPromise(error:
|
|
4
|
-
export declare function errorsOnly(error:
|
|
1
|
+
import { JSONError } from "../types";
|
|
2
|
+
export declare function isPromise(obj: unknown): obj is Promise<unknown>;
|
|
3
|
+
export declare function errorOrPromise(error: unknown): error is JSONError | Promise<unknown>;
|
|
4
|
+
export declare function errorsOnly(error: unknown): error is JSONError;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
export default function flattenArray<T =
|
|
1
|
+
export default function flattenArray<T = unknown>(list: unknown[], result?: T[]): T[];
|
package/dist/lib/validate.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { JSONSchema, JSONPointer, JSONError } from "./types";
|
|
2
|
-
import Core from "./
|
|
2
|
+
import { Draft as Core } from "./draft";
|
|
3
3
|
/**
|
|
4
4
|
* Validate data by a json schema
|
|
5
5
|
*
|
|
@@ -9,4 +9,4 @@ import Core from "./cores/CoreInterface";
|
|
|
9
9
|
* @param [pointer] - json pointer pointing to value (used for error-messages only)
|
|
10
10
|
* @return list of errors or empty
|
|
11
11
|
*/
|
|
12
|
-
export default function validate(core: Core, value:
|
|
12
|
+
export default function validate(core: Core, value: unknown, schema?: JSONSchema, pointer?: JSONPointer): Array<JSONError>;
|