json-schema-library
Advanced tools
Comparing version 10.0.0-rc7 to 10.0.0-rc8
@@ -7,8 +7,3 @@ declare const _default: { | ||
propertyBlacklist: string[]; | ||
templateDefaultOptions: { | ||
addOptionalProps: boolean; | ||
removeInvalidData: boolean; | ||
extendDefaults: boolean; | ||
}; | ||
}; | ||
export default _default; |
@@ -20,2 +20,3 @@ import addRemoteSchema from "../addRemoteSchema"; | ||
import { resolveOneOf } from "../features/oneOf"; | ||
export declare const templateDefaultOptions: TemplateOptions; | ||
export type DraftConfig = { | ||
@@ -117,2 +118,3 @@ /** error creators by id */ | ||
* @param [schema] - json schema, defaults to rootSchema | ||
* @param [options] - partial set of options to override draft-setting templateDefaultOptions | ||
* @return created template data | ||
@@ -119,0 +121,0 @@ */ |
@@ -6,8 +6,3 @@ export default { | ||
GET_TEMPLATE_RECURSION_LIMIT: 1, | ||
propertyBlacklist: ["_id"], | ||
templateDefaultOptions: { | ||
addOptionalProps: false, | ||
removeInvalidData: false, | ||
extendDefaults: true | ||
} | ||
propertyBlacklist: ["_id"] | ||
}; |
import copy from "../utils/copy"; | ||
import { isJsonError } from "../types"; | ||
import { isSchemaNode } from "../schemaNode"; | ||
export const templateDefaultOptions = { | ||
addOptionalProps: false, | ||
removeInvalidData: false, | ||
extendDefaults: true | ||
}; | ||
export class Draft { | ||
@@ -105,6 +110,8 @@ constructor(config, schema) { | ||
* @param [schema] - json schema, defaults to rootSchema | ||
* @param [options] - partial set of options to override draft-setting templateDefaultOptions | ||
* @return created template data | ||
*/ | ||
getTemplate(data, schema, opts = this.config.templateDefaultOptions) { | ||
return this.config.getTemplate(this, data, schema, opts); | ||
getTemplate(data, schema, opts) { | ||
const options = opts ? { ...this.config.templateDefaultOptions, ...opts } : this.config.templateDefaultOptions; | ||
return this.config.getTemplate(this, data, schema, options); | ||
} | ||
@@ -111,0 +118,0 @@ isValid(data, schema, pointer) { |
@@ -13,3 +13,2 @@ import addRemoteSchema from "./addRemoteSchema"; | ||
import resolveRef from "../resolveRef.strict"; | ||
import settings from "../config/settings"; | ||
import step from "../step"; | ||
@@ -19,3 +18,3 @@ import TYPES from "../validation/type"; | ||
import { createNode } from "../schemaNode"; | ||
import { Draft } from "../draft"; | ||
import { Draft, templateDefaultOptions } from "../draft"; | ||
import { each } from "../each"; | ||
@@ -28,13 +27,3 @@ import { eachSchema } from "../eachSchema"; | ||
typeKeywords: { | ||
array: [ | ||
"allOf", | ||
"anyOf", | ||
"enum", | ||
"items", | ||
"maxItems", | ||
"minItems", | ||
"not", | ||
"oneOf", | ||
"uniqueItems" | ||
], | ||
array: ["allOf", "anyOf", "enum", "items", "maxItems", "minItems", "not", "oneOf", "uniqueItems"], | ||
boolean: ["enum", "not", "allOf", "anyOf", "oneOf"], | ||
@@ -56,24 +45,4 @@ object: [ | ||
], | ||
string: [ | ||
"allOf", | ||
"anyOf", | ||
"enum", | ||
"format", | ||
"maxLength", | ||
"minLength", | ||
"not", | ||
"oneOf", | ||
"pattern" | ||
], | ||
number: [ | ||
"allOf", | ||
"anyOf", | ||
"enum", | ||
"format", | ||
"maximum", | ||
"minimum", | ||
"multipleOf", | ||
"not", | ||
"oneOf" | ||
], | ||
string: ["allOf", "anyOf", "enum", "format", "maxLength", "minLength", "not", "oneOf", "pattern"], | ||
number: ["allOf", "anyOf", "enum", "format", "maximum", "minimum", "multipleOf", "not", "oneOf"], | ||
null: ["allOf", "anyOf", "enum", "format", "not", "oneOf"] | ||
@@ -101,3 +70,3 @@ }, | ||
validate, | ||
templateDefaultOptions: settings.templateDefaultOptions | ||
templateDefaultOptions | ||
}; | ||
@@ -104,0 +73,0 @@ class Draft04 extends Draft { |
@@ -13,3 +13,2 @@ import addRemoteSchema from "../addRemoteSchema"; | ||
import resolveRef from "../resolveRef.strict"; | ||
import settings from "../config/settings"; | ||
import step from "../step"; | ||
@@ -19,3 +18,3 @@ import TYPES from "../validation/type"; | ||
import { createNode } from "../schemaNode"; | ||
import { Draft } from "../draft"; | ||
import { Draft, templateDefaultOptions } from "../draft"; | ||
import { each } from "../each"; | ||
@@ -59,14 +58,3 @@ import { eachSchema } from "../eachSchema"; | ||
], | ||
string: [ | ||
"allOf", | ||
"anyOf", | ||
"enum", | ||
"format", | ||
"if", | ||
"maxLength", | ||
"minLength", | ||
"not", | ||
"oneOf", | ||
"pattern" | ||
], | ||
string: ["allOf", "anyOf", "enum", "format", "if", "maxLength", "minLength", "not", "oneOf", "pattern"], | ||
number: [ | ||
@@ -108,3 +96,3 @@ "enum", | ||
validate, | ||
templateDefaultOptions: settings.templateDefaultOptions | ||
templateDefaultOptions | ||
}; | ||
@@ -111,0 +99,0 @@ class Draft06 extends Draft { |
@@ -13,3 +13,2 @@ import addRemoteSchema from "../addRemoteSchema"; | ||
import resolveRef from "../resolveRef.strict"; | ||
import settings from "../config/settings"; | ||
import step from "../step"; | ||
@@ -19,3 +18,3 @@ import TYPES from "../validation/type"; | ||
import { createNode } from "../schemaNode"; | ||
import { Draft } from "../draft"; | ||
import { Draft, templateDefaultOptions } from "../draft"; | ||
import { each } from "../each"; | ||
@@ -59,14 +58,3 @@ import { eachSchema } from "../eachSchema"; | ||
], | ||
string: [ | ||
"allOf", | ||
"anyOf", | ||
"enum", | ||
"format", | ||
"if", | ||
"maxLength", | ||
"minLength", | ||
"not", | ||
"oneOf", | ||
"pattern" | ||
], | ||
string: ["allOf", "anyOf", "enum", "format", "if", "maxLength", "minLength", "not", "oneOf", "pattern"], | ||
number: [ | ||
@@ -108,3 +96,3 @@ "allOf", | ||
validate, | ||
templateDefaultOptions: settings.templateDefaultOptions | ||
templateDefaultOptions | ||
}; | ||
@@ -111,0 +99,0 @@ class Draft07 extends Draft { |
@@ -13,3 +13,2 @@ import addRemoteSchema from "../addRemoteSchema"; | ||
import resolveRef from "../resolveRef"; | ||
import settings from "../config/settings"; | ||
import step from "../step"; | ||
@@ -19,3 +18,3 @@ import TYPES from "../validation/type"; | ||
import { createNode } from "../schemaNode"; | ||
import { Draft } from "../draft"; | ||
import { Draft, templateDefaultOptions } from "../draft"; | ||
import { each } from "../each"; | ||
@@ -63,14 +62,3 @@ import { eachSchema } from "../eachSchema"; | ||
], | ||
string: [ | ||
"allOf", | ||
"anyOf", | ||
"enum", | ||
"format", | ||
"if", | ||
"maxLength", | ||
"minLength", | ||
"not", | ||
"oneOf", | ||
"pattern" | ||
], | ||
string: ["allOf", "anyOf", "enum", "format", "if", "maxLength", "minLength", "not", "oneOf", "pattern"], | ||
number: [ | ||
@@ -112,3 +100,3 @@ "allOf", | ||
validate, | ||
templateDefaultOptions: settings.templateDefaultOptions | ||
templateDefaultOptions | ||
}; | ||
@@ -115,0 +103,0 @@ class Draft2019 extends Draft { |
@@ -14,3 +14,2 @@ /* eslint quote-props: 0, max-statements-per-line: ["error", { "max": 2 }] */ | ||
import { mergeSchema } from "./mergeSchema"; | ||
const defaultOptions = settings.templateDefaultOptions; | ||
let cache; | ||
@@ -365,6 +364,3 @@ function shouldResolveRef(schema, pointer) { | ||
cache = {}; | ||
if (opts) { | ||
return getTemplate(draft, data, schema, "#", { ...defaultOptions, ...opts }); | ||
} | ||
return getTemplate(draft, data, schema, "#", defaultOptions); | ||
return getTemplate(draft, data, schema, "#", opts !== null && opts !== void 0 ? opts : {}); | ||
}; |
@@ -6,8 +6,3 @@ export default { | ||
GET_TEMPLATE_RECURSION_LIMIT: 1, | ||
propertyBlacklist: ["_id"], | ||
templateDefaultOptions: { | ||
addOptionalProps: false, | ||
removeInvalidData: false, | ||
extendDefaults: true | ||
} | ||
propertyBlacklist: ["_id"] | ||
}; |
@@ -22,2 +22,8 @@ import addRemoteSchema from "../addRemoteSchema"; | ||
export const templateDefaultOptions: TemplateOptions = { | ||
addOptionalProps: false, | ||
removeInvalidData: false, | ||
extendDefaults: true | ||
}; | ||
export type DraftConfig = { | ||
@@ -169,10 +175,8 @@ /** error creators by id */ | ||
* @param [schema] - json schema, defaults to rootSchema | ||
* @param [options] - partial set of options to override draft-setting templateDefaultOptions | ||
* @return created template data | ||
*/ | ||
getTemplate( | ||
data?: unknown, | ||
schema?: JsonSchema, | ||
opts: TemplateOptions = this.config.templateDefaultOptions | ||
) { | ||
return this.config.getTemplate(this, data, schema, opts); | ||
getTemplate(data?: unknown, schema?: JsonSchema, opts?: TemplateOptions) { | ||
const options = opts ? { ...this.config.templateDefaultOptions, ...opts } : this.config.templateDefaultOptions; | ||
return this.config.getTemplate(this, data, schema, options); | ||
} | ||
@@ -234,7 +238,3 @@ | ||
validate(data: unknown, schema?: JsonSchema, pointer?: JsonPointer): JsonError[]; | ||
validate( | ||
data: unknown, | ||
schema: JsonSchema = this.rootSchema, | ||
pointer?: JsonPointer | ||
): JsonError[] { | ||
validate(data: unknown, schema: JsonSchema = this.rootSchema, pointer?: JsonPointer): JsonError[] { | ||
if (isSchemaNode(data)) { | ||
@@ -241,0 +241,0 @@ const inputData = schema; |
@@ -13,3 +13,2 @@ import addRemoteSchema from "./addRemoteSchema"; | ||
import resolveRef from "../resolveRef.strict"; | ||
import settings from "../config/settings"; | ||
import step from "../step"; | ||
@@ -19,3 +18,3 @@ import TYPES from "../validation/type"; | ||
import { createNode } from "../schemaNode"; | ||
import { DraftConfig, Draft } from "../draft"; | ||
import { DraftConfig, Draft, templateDefaultOptions } from "../draft"; | ||
import { each } from "../each"; | ||
@@ -30,13 +29,3 @@ import { eachSchema } from "../eachSchema"; | ||
typeKeywords: { | ||
array: [ | ||
"allOf", | ||
"anyOf", | ||
"enum", | ||
"items", | ||
"maxItems", | ||
"minItems", | ||
"not", | ||
"oneOf", | ||
"uniqueItems" | ||
], | ||
array: ["allOf", "anyOf", "enum", "items", "maxItems", "minItems", "not", "oneOf", "uniqueItems"], | ||
boolean: ["enum", "not", "allOf", "anyOf", "oneOf"], | ||
@@ -58,24 +47,4 @@ object: [ | ||
], | ||
string: [ | ||
"allOf", | ||
"anyOf", | ||
"enum", | ||
"format", | ||
"maxLength", | ||
"minLength", | ||
"not", | ||
"oneOf", | ||
"pattern" | ||
], | ||
number: [ | ||
"allOf", | ||
"anyOf", | ||
"enum", | ||
"format", | ||
"maximum", | ||
"minimum", | ||
"multipleOf", | ||
"not", | ||
"oneOf" | ||
], | ||
string: ["allOf", "anyOf", "enum", "format", "maxLength", "minLength", "not", "oneOf", "pattern"], | ||
number: ["allOf", "anyOf", "enum", "format", "maximum", "minimum", "multipleOf", "not", "oneOf"], | ||
null: ["allOf", "anyOf", "enum", "format", "not", "oneOf"] | ||
@@ -105,3 +74,3 @@ }, | ||
templateDefaultOptions: settings.templateDefaultOptions | ||
templateDefaultOptions | ||
}; | ||
@@ -108,0 +77,0 @@ |
@@ -13,3 +13,2 @@ import addRemoteSchema from "../addRemoteSchema"; | ||
import resolveRef from "../resolveRef.strict"; | ||
import settings from "../config/settings"; | ||
import step from "../step"; | ||
@@ -19,3 +18,3 @@ import TYPES from "../validation/type"; | ||
import { createNode } from "../schemaNode"; | ||
import { DraftConfig, Draft } from "../draft"; | ||
import { DraftConfig, Draft, templateDefaultOptions } from "../draft"; | ||
import { each } from "../each"; | ||
@@ -61,14 +60,3 @@ import { eachSchema } from "../eachSchema"; | ||
], | ||
string: [ | ||
"allOf", | ||
"anyOf", | ||
"enum", | ||
"format", | ||
"if", | ||
"maxLength", | ||
"minLength", | ||
"not", | ||
"oneOf", | ||
"pattern" | ||
], | ||
string: ["allOf", "anyOf", "enum", "format", "if", "maxLength", "minLength", "not", "oneOf", "pattern"], | ||
number: [ | ||
@@ -112,3 +100,3 @@ "enum", | ||
templateDefaultOptions: settings.templateDefaultOptions | ||
templateDefaultOptions | ||
}; | ||
@@ -115,0 +103,0 @@ |
@@ -13,3 +13,2 @@ import addRemoteSchema from "../addRemoteSchema"; | ||
import resolveRef from "../resolveRef.strict"; | ||
import settings from "../config/settings"; | ||
import step from "../step"; | ||
@@ -19,3 +18,3 @@ import TYPES from "../validation/type"; | ||
import { createNode } from "../schemaNode"; | ||
import { DraftConfig, Draft } from "../draft"; | ||
import { DraftConfig, Draft, templateDefaultOptions } from "../draft"; | ||
import { each } from "../each"; | ||
@@ -61,14 +60,3 @@ import { eachSchema } from "../eachSchema"; | ||
], | ||
string: [ | ||
"allOf", | ||
"anyOf", | ||
"enum", | ||
"format", | ||
"if", | ||
"maxLength", | ||
"minLength", | ||
"not", | ||
"oneOf", | ||
"pattern" | ||
], | ||
string: ["allOf", "anyOf", "enum", "format", "if", "maxLength", "minLength", "not", "oneOf", "pattern"], | ||
number: [ | ||
@@ -112,3 +100,3 @@ "allOf", | ||
templateDefaultOptions: settings.templateDefaultOptions | ||
templateDefaultOptions | ||
}; | ||
@@ -115,0 +103,0 @@ |
@@ -13,3 +13,2 @@ import addRemoteSchema from "../addRemoteSchema"; | ||
import resolveRef from "../resolveRef"; | ||
import settings from "../config/settings"; | ||
import step from "../step"; | ||
@@ -19,3 +18,3 @@ import TYPES from "../validation/type"; | ||
import { createNode } from "../schemaNode"; | ||
import { DraftConfig, Draft } from "../draft"; | ||
import { DraftConfig, Draft, templateDefaultOptions } from "../draft"; | ||
import { each } from "../each"; | ||
@@ -65,14 +64,3 @@ import { eachSchema } from "../eachSchema"; | ||
], | ||
string: [ | ||
"allOf", | ||
"anyOf", | ||
"enum", | ||
"format", | ||
"if", | ||
"maxLength", | ||
"minLength", | ||
"not", | ||
"oneOf", | ||
"pattern" | ||
], | ||
string: ["allOf", "anyOf", "enum", "format", "if", "maxLength", "minLength", "not", "oneOf", "pattern"], | ||
number: [ | ||
@@ -116,3 +104,3 @@ "allOf", | ||
templateDefaultOptions: settings.templateDefaultOptions | ||
templateDefaultOptions | ||
}; | ||
@@ -119,0 +107,0 @@ |
@@ -29,4 +29,2 @@ /* eslint quote-props: 0, max-statements-per-line: ["error", { "max": 2 }] */ | ||
const defaultOptions: TemplateOptions = settings.templateDefaultOptions; | ||
let cache: Record<string, JsonSchema>; | ||
@@ -443,6 +441,3 @@ function shouldResolveRef(schema: JsonSchema, pointer: JsonPointer) { | ||
cache = {}; | ||
if (opts) { | ||
return getTemplate(draft, data, schema, "#", { ...defaultOptions, ...opts }); | ||
} | ||
return getTemplate(draft, data, schema, "#", defaultOptions); | ||
return getTemplate(draft, data, schema, "#", opts ?? {}); | ||
}; |
{ | ||
"name": "json-schema-library", | ||
"version": "10.0.0-rc7", | ||
"version": "10.0.0-rc8", | ||
"description": "Customizable and hackable json-validator and json-schema utilities for traversal, data generation and validation", | ||
@@ -34,3 +34,3 @@ "module": "dist/module/index.js", | ||
"type": "git", | ||
"url": "https://github.com/sagold/json-schema-library.git" | ||
"url": "git+https://github.com/sagold/json-schema-library.git" | ||
}, | ||
@@ -62,3 +62,3 @@ "keywords": [ | ||
"@types/mocha": "^10.0.6", | ||
"@types/node": "^20.17.9", | ||
"@types/node": "^22.13.1", | ||
"@types/valid-url": "^1.0.7", | ||
@@ -77,12 +77,12 @@ "@typescript-eslint/eslint-plugin": "^7.18.0", | ||
"nyc": "^15.1.0", | ||
"terser-webpack-plugin": "^5.3.10", | ||
"ts-loader": "^9.5.1", | ||
"terser-webpack-plugin": "^5.3.11", | ||
"ts-loader": "^9.5.2", | ||
"ts-node": "^10.9.2", | ||
"typescript": "^5.7.2", | ||
"typescript": "^5.7.3", | ||
"watch": "^1.0.1", | ||
"webpack": "^5.96.1", | ||
"webpack-cli": "^5.1.4" | ||
"webpack": "^5.97.1", | ||
"webpack-cli": "^6.0.1" | ||
}, | ||
"dependencies": { | ||
"@sagold/json-pointer": "^6.0.1", | ||
"@sagold/json-pointer": "^7.0.0", | ||
"@sagold/json-query": "^6.2.0", | ||
@@ -96,5 +96,8 @@ "deepmerge": "^4.3.1", | ||
"resolutions": { | ||
"braces": ">=3.0.3", | ||
"cross-spawn": ">=7.0.6", | ||
"json5": ">=2.2.3", | ||
"lodash": ">=4", | ||
"merge": ">=2", | ||
"micromatch": ">=4.0.8", | ||
"string-width": "4.2.3" | ||
@@ -101,0 +104,0 @@ }, |
@@ -10,3 +10,3 @@ <p align="center"><img src="./docs/json-schema-library.png" width="256" alt="json-schema-library"></p> | ||
> β οΈ This documentation refers to the upcoming release version 10, which can be installed by `npm install json-schema-library@10.0.0-rc7`. For the latest release please refer to the [documentation of version 9.3.5](https://github.com/sagold/json-schema-library/tree/v9.3.5) | ||
> β οΈ This documentation refers to the upcoming release version 10, which can be installed by `npm install json-schema-library@10.0.0-rc8`. For the latest release please refer to the [documentation of version 9.3.5](https://github.com/sagold/json-schema-library/tree/v9.3.5) | ||
@@ -1009,2 +1009,14 @@ <p style="text-align:center"> | ||
- removed `templateDefaultOptions` from global settings-object. Instead configure getTemplate per draft instead on `draft.templateDefaultOptions` | ||
```ts | ||
new Draft2019(schema, { | ||
templateDefaultOptions: { | ||
addOptionalProps: false, | ||
removeInvalidData: false, | ||
extendDefaults: true | ||
}) | ||
}); | ||
``` | ||
_Draft 2019-09_ requires collection of previous resolved sub-schemas. Thus, an additional type `SchemaNode` had to be introduced, which is used in almost all draft methods defined for draft-configs. The api in draft-instances mostly stayed the same with the following exceptions: | ||
@@ -1011,0 +1023,0 @@ |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is too big to display
Sorry, the diff of this file is too big to display
2340730
228
54555
1091
+ Added@sagold/json-pointer@7.0.0(transitive)
- Removed@sagold/json-pointer@6.0.2(transitive)
Updated@sagold/json-pointer@^7.0.0