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.
Files changed (161) hide show
  1. package/.editorconfig +1 -0
  2. package/.prettierignore +1 -0
  3. package/.prettierrc +7 -0
  4. package/CHANGELOG.md +106 -0
  5. package/README.md +811 -199
  6. package/TASKS.md +3 -81
  7. package/dist/index.d.ts +29 -71
  8. package/dist/jsonSchemaLibrary.js +1 -1
  9. package/dist/lib/SchemaService.d.ts +6 -8
  10. package/dist/lib/{addSchema.d.ts → addRemoteSchema.d.ts} +2 -1
  11. package/dist/lib/addValidator.d.ts +3 -2
  12. package/dist/lib/compile/getRef.d.ts +2 -1
  13. package/dist/lib/compile/index.d.ts +15 -1
  14. package/dist/lib/compile/types.d.ts +5 -0
  15. package/dist/lib/config/strings.d.ts +1 -39
  16. package/dist/lib/draft/index.d.ts +132 -0
  17. package/dist/lib/draft04/index.d.ts +7 -0
  18. package/dist/lib/draft06/compile/index.d.ts +16 -0
  19. package/dist/lib/draft06/index.d.ts +7 -0
  20. package/dist/lib/draft06/validation/keyword.d.ts +3 -0
  21. package/dist/lib/draft06/validation/type.d.ts +10 -0
  22. package/dist/lib/draft06/validation/typeKeywordMapping.d.ts +13 -0
  23. package/dist/lib/draft07/index.d.ts +7 -0
  24. package/dist/lib/each.d.ts +3 -2
  25. package/dist/lib/eachSchema.d.ts +2 -4
  26. package/dist/lib/getChildSchemaSelection.d.ts +7 -5
  27. package/dist/lib/getSchema.d.ts +2 -2
  28. package/dist/lib/getTemplate.d.ts +1 -1
  29. package/dist/lib/getTypeOf.d.ts +2 -1
  30. package/dist/lib/isValid.d.ts +1 -1
  31. package/dist/lib/jsoneditor/index.d.ts +7 -0
  32. package/dist/lib/resolveAllOf.d.ts +1 -1
  33. package/dist/lib/resolveAnyOf.d.ts +1 -1
  34. package/dist/lib/resolveOneOf.fuzzy.d.ts +1 -1
  35. package/dist/lib/resolveOneOf.strict.d.ts +2 -2
  36. package/dist/lib/{resolveRef.withOverwrite.d.ts → resolveRef.merge.d.ts} +0 -0
  37. package/dist/lib/schema/getTypeDefs.d.ts +6 -4
  38. package/dist/lib/schema/getTypeId.d.ts +1 -1
  39. package/dist/lib/schema/types.d.ts +7 -57
  40. package/dist/lib/step.d.ts +5 -5
  41. package/dist/lib/types.d.ts +11 -3
  42. package/dist/lib/utils/createCustomError.d.ts +8 -11
  43. package/dist/lib/utils/filter.d.ts +4 -4
  44. package/dist/lib/utils/flattenArray.d.ts +1 -1
  45. package/dist/lib/utils/merge.d.ts +3 -0
  46. package/dist/lib/utils/punycode.ucs2decode.d.ts +1 -1
  47. package/dist/lib/validate.d.ts +2 -2
  48. package/dist/lib/validateAsync.d.ts +1 -1
  49. package/dist/lib/validation/errors.d.ts +1 -3
  50. package/dist/lib/validation/format.d.ts +4 -11
  51. package/dist/lib/validation/keyword.d.ts +2 -27
  52. package/dist/lib/validation/type.d.ts +3 -10
  53. package/dist/lib/validation/typeKeywordMapping.d.ts +4 -4
  54. package/dist/module/index.js +23 -32
  55. package/dist/module/lib/SchemaService.js +7 -4
  56. package/dist/module/lib/{addSchema.js → addRemoteSchema.js} +2 -4
  57. package/dist/module/lib/addValidator.js +3 -4
  58. package/dist/module/lib/compile/getRef.js +1 -1
  59. package/dist/module/lib/compile/index.js +43 -18
  60. package/dist/module/lib/compile/types.js +1 -0
  61. package/dist/module/lib/config/strings.js +15 -2
  62. package/dist/module/lib/createSchemaOf.js +1 -1
  63. package/dist/module/lib/draft/index.js +133 -0
  64. package/dist/module/lib/draft04/index.js +90 -0
  65. package/dist/module/lib/draft06/compile/index.js +77 -0
  66. package/dist/module/lib/draft06/index.js +96 -0
  67. package/dist/module/lib/draft06/validation/keyword.js +168 -0
  68. package/dist/module/lib/draft06/validation/type.js +31 -0
  69. package/dist/module/lib/draft06/validation/typeKeywordMapping.js +15 -0
  70. package/dist/module/lib/draft07/index.js +96 -0
  71. package/dist/module/lib/each.js +2 -2
  72. package/dist/module/lib/eachSchema.js +28 -19
  73. package/dist/module/lib/getChildSchemaSelection.js +7 -6
  74. package/dist/module/lib/getSchema.js +4 -2
  75. package/dist/module/lib/getTemplate.js +42 -15
  76. package/dist/module/lib/jsoneditor/index.js +16 -0
  77. package/dist/module/lib/resolveAllOf.js +3 -4
  78. package/dist/module/lib/resolveOneOf.fuzzy.js +13 -3
  79. package/dist/module/lib/resolveOneOf.strict.js +49 -2
  80. package/dist/module/lib/{resolveRef.withOverwrite.js → resolveRef.merge.js} +0 -0
  81. package/dist/module/lib/resolveRef.strict.js +8 -0
  82. package/dist/module/lib/schema/getTypeDefs.js +14 -3
  83. package/dist/module/lib/schema/getTypeId.js +10 -6
  84. package/dist/module/lib/schema/types.js +33 -9
  85. package/dist/module/lib/step.js +67 -13
  86. package/dist/module/lib/types.js +7 -1
  87. package/dist/module/lib/utils/createCustomError.js +4 -4
  88. package/dist/module/lib/utils/filter.js +3 -5
  89. package/dist/module/lib/utils/flattenArray.js +4 -3
  90. package/dist/module/lib/utils/merge.js +4 -0
  91. package/dist/module/lib/utils/punycode.ucs2decode.js +4 -3
  92. package/dist/module/lib/validate.js +34 -8
  93. package/dist/module/lib/validateAsync.js +7 -7
  94. package/dist/module/lib/validation/errors.js +16 -3
  95. package/dist/module/lib/validation/format.js +115 -8
  96. package/dist/module/lib/validation/keyword.js +79 -32
  97. package/dist/module/lib/validation/type.js +2 -1
  98. package/index.ts +46 -32
  99. package/lib/SchemaService.ts +18 -11
  100. package/lib/{addSchema.ts → addRemoteSchema.ts} +3 -5
  101. package/lib/addValidator.ts +15 -12
  102. package/lib/compile/getRef.ts +3 -4
  103. package/lib/compile/index.ts +65 -19
  104. package/lib/compile/types.ts +6 -0
  105. package/lib/config/strings.ts +17 -3
  106. package/lib/createSchemaOf.ts +1 -3
  107. package/lib/draft/index.ts +201 -0
  108. package/lib/draft04/index.ts +95 -0
  109. package/lib/draft06/compile/index.ts +104 -0
  110. package/lib/draft06/index.ts +101 -0
  111. package/lib/draft06/validation/keyword.ts +199 -0
  112. package/lib/draft06/validation/type.ts +47 -0
  113. package/lib/draft06/validation/typeKeywordMapping.ts +15 -0
  114. package/lib/draft07/index.ts +101 -0
  115. package/lib/each.ts +11 -4
  116. package/lib/eachSchema.ts +45 -32
  117. package/lib/getChildSchemaSelection.ts +14 -7
  118. package/lib/getSchema.ts +18 -9
  119. package/lib/getTemplate.ts +155 -42
  120. package/lib/getTypeOf.ts +2 -1
  121. package/lib/isValid.ts +7 -3
  122. package/lib/jsoneditor/index.ts +20 -0
  123. package/lib/resolveAllOf.ts +10 -6
  124. package/lib/resolveAnyOf.ts +7 -3
  125. package/lib/resolveOneOf.fuzzy.ts +26 -9
  126. package/lib/resolveOneOf.strict.ts +63 -5
  127. package/lib/{resolveRef.withOverwrite.ts → resolveRef.merge.ts} +0 -0
  128. package/lib/resolveRef.strict.ts +9 -0
  129. package/lib/schema/getTypeDefs.ts +19 -7
  130. package/lib/schema/getTypeId.ts +11 -8
  131. package/lib/schema/types.ts +41 -9
  132. package/lib/step.ts +109 -25
  133. package/lib/types.ts +23 -5
  134. package/lib/utils/createCustomError.ts +8 -13
  135. package/lib/utils/filter.ts +7 -9
  136. package/lib/utils/flattenArray.ts +5 -4
  137. package/lib/utils/merge.ts +5 -0
  138. package/lib/utils/punycode.ucs2decode.ts +6 -5
  139. package/lib/validate.ts +47 -16
  140. package/lib/validateAsync.ts +15 -14
  141. package/lib/validation/errors.ts +17 -6
  142. package/lib/validation/format.ts +147 -13
  143. package/lib/validation/keyword.ts +172 -103
  144. package/lib/validation/type.ts +5 -1
  145. package/package.json +75 -63
  146. package/{dist/module/remotes/draft04.json → remotes/draft06.json} +47 -42
  147. package/remotes/draft07.json +172 -0
  148. package/remotes/draft2019-09.json +86 -0
  149. package/tsconfig.json +3 -10
  150. package/dist/lib/cores/CoreInterface.d.ts +0 -23
  151. package/dist/lib/cores/Draft04.d.ts +0 -13
  152. package/dist/lib/cores/JsonEditor.d.ts +0 -13
  153. package/dist/module/lib/cores/CoreInterface.js +0 -51
  154. package/dist/module/lib/cores/Draft04.js +0 -52
  155. package/dist/module/lib/cores/JsonEditor.js +0 -51
  156. package/dist/module/remotes/index.js +0 -10
  157. package/dist/remotes/index.d.ts +0 -5
  158. package/lib/cores/CoreInterface.ts +0 -76
  159. package/lib/cores/Draft04.ts +0 -66
  160. package/lib/cores/JsonEditor.ts +0 -64
  161. package/remotes/index.ts +0 -11
@@ -1,5 +1,6 @@
1
- import Core from "./cores/CoreInterface";
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: any): void;
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,3 @@
1
1
  import { JSONSchema } from "../types";
2
- export default function getRef(context: any, rootSchema: JSONSchema, $ref: any): any;
2
+ import { Context } from "./types";
3
+ export default function getRef(context: Context, rootSchema: JSONSchema, $ref: string): JSONSchema;
@@ -1,2 +1,16 @@
1
+ import { Draft } from "../draft";
1
2
  import { JSONSchema } from "../types";
2
- export default function compile(rootSchema: JSONSchema, force?: boolean): JSONSchema;
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;
@@ -0,0 +1,5 @@
1
+ import { JSONSchema, JSONPointer } from "../types";
2
+ export declare type Context = {
3
+ ids: Record<string, JSONPointer>;
4
+ remotes: Record<string, JSONSchema>;
5
+ };
@@ -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,3 @@
1
+ import { JSONValidator } from "../../types";
2
+ declare const KeywordValidation: Record<string, JSONValidator>;
3
+ export default KeywordValidation;
@@ -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 };
@@ -1,5 +1,6 @@
1
- import Core from "./cores/CoreInterface";
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 default function each(core: Core, data: any, callback: any, schema?: JSONSchema, pointer?: JSONPointer): void;
13
+ export declare function each(core: Core, data: any, callback: EachCallback, schema?: JSONSchema, pointer?: JSONPointer): void;
@@ -1,5 +1,3 @@
1
1
  import { JSONSchema, JSONPointer } from "./types";
2
- export interface OnSchema {
3
- (schema: JSONSchema, pointer: JSONPointer): void;
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 {Core} core - core to use
7
- * @param {String} property - parent schema of following property
8
- * @param {Object} [schema] - parent schema of following property
9
- * @return {Object}
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: any, property: any, schema?: any): any;
13
+ export default function getChildSchemaSelection(core: Draft, property: string | number, schema?: JSONSchema): JSONSchema[] | JSONError;
@@ -1,5 +1,5 @@
1
1
  import { JSONSchema, JSONPointer } from "./types";
2
- import Core from "./cores/CoreInterface";
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?: any, schema?: JSONSchema): JSONSchema;
16
+ export default function getSchema(core: Core, pointer: JSONPointer, data?: unknown, schema?: JSONSchema): JSONSchema;
@@ -1,5 +1,5 @@
1
1
  import { JSONSchema } from "./types";
2
- import Core from "./cores/CoreInterface";
2
+ import { Draft as Core } from "./draft";
3
3
  interface TemplateOptions {
4
4
  /** Add all properties (required and optional) to the generated data */
5
5
  addOptionalProps: boolean;
@@ -1 +1,2 @@
1
- export default function getTypeOf(value: any): any;
1
+ export declare type JSType = "array" | "bigint" | "boolean" | "function" | "null" | "number" | "object" | "string" | "symbol" | "undefined";
2
+ export default function getTypeOf(value: unknown): JSType;
@@ -1,5 +1,5 @@
1
1
  import { JSONSchema, JSONPointer } from "./types";
2
- import Core from "./cores/CoreInterface";
2
+ import { Draft as Core } from "./draft";
3
3
  /**
4
4
  * Test if the data is valid according to the given schema
5
5
  *
@@ -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 "./cores/CoreInterface";
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 "./cores/CoreInterface";
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
1
  import { JSONSchema, JSONPointer, JSONError } from "./types";
2
- import Core from "./cores/CoreInterface";
2
+ import { Draft as Core } from "./draft";
3
3
  /**
4
4
  * Selects and returns a oneOf schema for the given data
5
5
  *
@@ -1,5 +1,5 @@
1
- import Core from "./cores/CoreInterface";
2
- import { JSONSchema, JSONError, JSONPointer } from "./types";
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
  *
@@ -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): Array<{
8
- pointer: JSONPointer;
9
- def: any;
10
- }>;
11
+ export default function getTypeDefs(schema: JSONSchema): TypeDef[];
12
+ export {};
@@ -6,4 +6,4 @@ import { JSONSchema } from "../types";
6
6
  * @param schema
7
7
  * @return type id, if found
8
8
  */
9
- export default function getTypeId(schema: JSONSchema): string | undefined;
9
+ export default function getTypeId(schema: JSONSchema): string | string[] | undefined;
@@ -1,58 +1,8 @@
1
- declare const _default: {
2
- $ref: {
3
- type: boolean;
4
- };
5
- allOf: {
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
- export default _default;
7
+ declare const Types: Record<string, Type>;
8
+ export default Types;
@@ -1,5 +1,5 @@
1
1
  import { JSONSchema, JSONPointer, JSONError } from "./types";
2
- import Core from "./cores/CoreInterface";
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 - validator
11
- * @param key - property-name or array-index
12
- * @param schema - json schema of current data
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;
@@ -1,10 +1,10 @@
1
- import Core from "./cores/CoreInterface";
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" | "string";
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: any, pointer: JSONPointer): void | undefined | JSONError | Array<JSONError>;
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 interface CreateError {
3
- (data?: {
4
- [p: string]: any;
5
- }): JSONError;
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 __@see config/strings.ts
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 default function createCustomError(name: string): CreateError;
14
+ export declare function createCustomError(name: string): CreateError;
@@ -1,4 +1,4 @@
1
- export declare function isPromise(obj: any): boolean;
2
- export declare function isError(obj: any): boolean;
3
- export declare function errorOrPromise(error: any): boolean;
4
- export declare function errorsOnly(error: any): boolean;
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 = any>(list: Array<any>, result?: any[]): Array<T>;
1
+ export default function flattenArray<T = unknown>(list: unknown[], result?: T[]): T[];
@@ -1,2 +1,5 @@
1
+ /**
2
+ * returns a new json-schema, where properties are combined and arrays are replaced
3
+ */
1
4
  declare const _default: <T, K>(a: T, b: K) => T & K;
2
5
  export default _default;
@@ -13,4 +13,4 @@
13
13
  * @param string The Unicode input string (UCS-2).
14
14
  * @returns The new array of code points.
15
15
  */
16
- export default function ucs2decode(string: string): Array<string>;
16
+ export default function ucs2decode(string: string): string[];
@@ -1,5 +1,5 @@
1
1
  import { JSONSchema, JSONPointer, JSONError } from "./types";
2
- import Core from "./cores/CoreInterface";
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: any, schema?: JSONSchema, pointer?: JSONPointer): Array<JSONError>;
12
+ export default function validate(core: Core, value: unknown, schema?: JSONSchema, pointer?: JSONPointer): Array<JSONError>;
@@ -1,5 +1,5 @@
1
1
  import { JSONSchema, JSONPointer, JSONError } from "./types";
2
- import Core from "./cores/CoreInterface";
2
+ import { Draft as Core } from "./draft";
3
3
  export interface OnError {
4
4
  (error: JSONError): void;
5
5
  }