@takeshape/json-schema 11.45.3 → 11.46.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.
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"schema-validator.d.ts","sourceRoot":"","sources":["../../src/schema-validator.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"schema-validator.d.ts","sourceRoot":"","sources":["../../src/schema-validator.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,WAAW,EAAE,OAAO,EAAE,YAAY,EAAE,MAAM,KAAK,CAAC;AAC9D,OAAO,GAAG,MAAM,KAAK,CAAC;AAMtB,MAAM,MAAM,IAAI,GAAG,GAAG,CAAC;AAEvB,MAAM,MAAM,cAAc,GAAG;IAC3B,aAAa,EAAE,OAAO,CAAC;IACvB,WAAW,EAAE,OAAO,CAAC;IACrB,UAAU,EAAE,OAAO,CAAC;CACrB,CAAC;AAEF,MAAM,MAAM,cAAc,GAAG;IAC3B,KAAK,EAAE,OAAO,CAAC;IACf,UAAU,EAAE,MAAM,CAAC;IACnB,MAAM,EAAE,WAAW,EAAE,CAAC;CACvB,CAAC;AAEF,MAAM,MAAM,SAAS,GAAG,CAAC,IAAI,EAAE,IAAI,EAAE,OAAO,CAAC,EAAE,OAAO,CAAC,cAAc,CAAC,KAAK,cAAc,CAAC;AAE1F,wBAAgB,aAAa,CAAC,YAAY,EAAE,MAAM,GAAG,MAAM,EAAE,CAE5D;AAwBD,wBAAgB,yBAAyB,CAAC,cAAc,EAAE,YAAY,EAAE,KAAK,EAAE,WAAW,GAAG,OAAO,CAWnG;AAYD,wBAAgB,SAAS,CAAC,GAAG,EAAE,MAAM,GAAG,MAAM,EAAE,CAE/C;AAeD;;GAEG;AACH,wBAAgB,gBAAgB,CAAC,cAAc,EAAE,YAAY,EAAE,YAAY,EAAE,MAAM,EAAE,GAAG,YAAY,GAAG,SAAS,CA6B/G;AAED,MAAM,MAAM,UAAU,GAAG,IAAI,CAAC,GAAG,EAAE,UAAU,GAAG,QAAQ,GAAG,WAAW,GAAG,YAAY,CAAC,CAAC;AAsBvF,wBAAgB,QAAQ,CAAC,GAAG,EAAE,UAAU,EAAE,EAAE,EAAE,MAAM,EAAE,IAAI,EAAE,IAAI,EAAE,OAAO,CAAC,EAAE,OAAO,CAAC,cAAc,CAAC,GAAG,cAAc,CA2BnH;AAED,OAAO,EAAE,GAAG,EAAE,KAAK,WAAW,EAAE,CAAC;AACjC,wBAAgB,SAAS,CAAC,OAAO,CAAC,EAAE,OAAO,GAAG,GAAG,CAmBhD;AAcD;;;GAGG;AACH,wBAAgB,SAAS,CAAC,MAAM,EAAE,YAAY,GAAG,YAAY,CAmB5D;AAED,wBAAgB,qBAAqB,CACnC,MAAM,EAAE,YAAY,GAAG,YAAY,EAAE,EACrC,WAAW,GAAE,YAAY,EAAO,EAChC,OAAO,GAAE,OAAY,GACpB,SAAS,CA0BX"}
|
package/dist/schema-validator.js
CHANGED
|
@@ -17,12 +17,12 @@ exports.isInvalidPropertyRequired = isInvalidPropertyRequired;
|
|
|
17
17
|
exports.parseDataPath = parseDataPath;
|
|
18
18
|
exports.refToPath = refToPath;
|
|
19
19
|
exports.validate = validate;
|
|
20
|
+
var _util = require("@takeshape/util");
|
|
20
21
|
var _ajv = _interopRequireDefault(require("ajv"));
|
|
21
22
|
var _ajvFormats = _interopRequireDefault(require("ajv-formats"));
|
|
22
23
|
var _get = _interopRequireDefault(require("lodash/get"));
|
|
23
|
-
var _unset = _interopRequireDefault(require("lodash/unset"));
|
|
24
24
|
var _isString = _interopRequireDefault(require("lodash/isString"));
|
|
25
|
-
var
|
|
25
|
+
var _unset = _interopRequireDefault(require("lodash/unset"));
|
|
26
26
|
function _interopRequireDefault(e) { return e && e.__esModule ? e : { default: e }; }
|
|
27
27
|
function parseDataPath(instancePath) {
|
|
28
28
|
return instancePath.substr(1).split('/');
|
|
@@ -76,8 +76,8 @@ function followRef(topLevelSchema, schema) {
|
|
|
76
76
|
* Given a schema object traverse it using a "instancePath" and return the schema at that path
|
|
77
77
|
*/
|
|
78
78
|
function followSchemaPath(topLevelSchema, instancePath) {
|
|
79
|
-
const followPath = (
|
|
80
|
-
schema = followRef(topLevelSchema,
|
|
79
|
+
const followPath = (schemaObject, path) => {
|
|
80
|
+
const schema = followRef(topLevelSchema, schemaObject);
|
|
81
81
|
if (path.length === 0) {
|
|
82
82
|
return schema;
|
|
83
83
|
}
|
|
@@ -172,7 +172,6 @@ function createAjv(options) {
|
|
|
172
172
|
*/
|
|
173
173
|
function isValidRegex(str) {
|
|
174
174
|
try {
|
|
175
|
-
// eslint-disable-next-line no-new
|
|
176
175
|
new RegExp(str, 'u');
|
|
177
176
|
return true;
|
|
178
177
|
} catch {
|
|
@@ -210,9 +209,13 @@ function createSchemaValidator(schema, metaSchemas = [], options = {}) {
|
|
|
210
209
|
...options
|
|
211
210
|
});
|
|
212
211
|
if (metaSchemas) {
|
|
213
|
-
|
|
212
|
+
for (const metaSchema of metaSchemas) {
|
|
213
|
+
ajv.addMetaSchema(metaSchema);
|
|
214
|
+
}
|
|
215
|
+
}
|
|
216
|
+
for (const schema of schemas) {
|
|
217
|
+
ajv.addSchema(fixSchema(schema));
|
|
214
218
|
}
|
|
215
|
-
schemas.forEach(schema => ajv.addSchema(fixSchema(schema)));
|
|
216
219
|
const defaultRef = schemas[0].$id;
|
|
217
220
|
if (!defaultRef) {
|
|
218
221
|
throw Error('Failed to create schema validator: schema is missing $id');
|
package/es/schema-validator.js
CHANGED
|
@@ -1,9 +1,9 @@
|
|
|
1
|
+
import { visit } from '@takeshape/util';
|
|
1
2
|
import Ajv from 'ajv';
|
|
2
3
|
import addFormats from 'ajv-formats';
|
|
3
4
|
import get from 'lodash/get';
|
|
4
|
-
import unset from 'lodash/unset';
|
|
5
5
|
import isString from 'lodash/isString';
|
|
6
|
-
import
|
|
6
|
+
import unset from 'lodash/unset';
|
|
7
7
|
export function parseDataPath(instancePath) {
|
|
8
8
|
return instancePath.substr(1).split('/');
|
|
9
9
|
}
|
|
@@ -56,8 +56,8 @@ function followRef(topLevelSchema, schema) {
|
|
|
56
56
|
* Given a schema object traverse it using a "instancePath" and return the schema at that path
|
|
57
57
|
*/
|
|
58
58
|
export function followSchemaPath(topLevelSchema, instancePath) {
|
|
59
|
-
const followPath = (
|
|
60
|
-
schema = followRef(topLevelSchema,
|
|
59
|
+
const followPath = (schemaObject, path) => {
|
|
60
|
+
const schema = followRef(topLevelSchema, schemaObject);
|
|
61
61
|
if (path.length === 0) {
|
|
62
62
|
return schema;
|
|
63
63
|
}
|
|
@@ -153,7 +153,6 @@ export function createAjv(options) {
|
|
|
153
153
|
*/
|
|
154
154
|
function isValidRegex(str) {
|
|
155
155
|
try {
|
|
156
|
-
// eslint-disable-next-line no-new
|
|
157
156
|
new RegExp(str, 'u');
|
|
158
157
|
return true;
|
|
159
158
|
} catch {
|
|
@@ -191,9 +190,13 @@ export function createSchemaValidator(schema, metaSchemas = [], options = {}) {
|
|
|
191
190
|
...options
|
|
192
191
|
});
|
|
193
192
|
if (metaSchemas) {
|
|
194
|
-
|
|
193
|
+
for (const metaSchema of metaSchemas) {
|
|
194
|
+
ajv.addMetaSchema(metaSchema);
|
|
195
|
+
}
|
|
196
|
+
}
|
|
197
|
+
for (const schema of schemas) {
|
|
198
|
+
ajv.addSchema(fixSchema(schema));
|
|
195
199
|
}
|
|
196
|
-
schemas.forEach(schema => ajv.addSchema(fixSchema(schema)));
|
|
197
200
|
const defaultRef = schemas[0].$id;
|
|
198
201
|
if (!defaultRef) {
|
|
199
202
|
throw Error('Failed to create schema validator: schema is missing $id');
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@takeshape/json-schema",
|
|
3
|
-
"version": "11.
|
|
3
|
+
"version": "11.46.0",
|
|
4
4
|
"description": "JSON Schema validator",
|
|
5
5
|
"homepage": "https://www.takeshape.io",
|
|
6
6
|
"repository": {
|
|
@@ -20,7 +20,7 @@
|
|
|
20
20
|
"ajv": "^8.12.0",
|
|
21
21
|
"ajv-formats": "^2.1.1",
|
|
22
22
|
"lodash": "^4.17.21",
|
|
23
|
-
"@takeshape/util": "11.
|
|
23
|
+
"@takeshape/util": "11.46.0"
|
|
24
24
|
},
|
|
25
25
|
"devDependencies": {
|
|
26
26
|
"@types/lodash": "^4.14.165"
|
|
@@ -38,8 +38,12 @@
|
|
|
38
38
|
"build:types": "tsc --emitDeclarationOnly --project tsconfig.build.json",
|
|
39
39
|
"build:types:ci": "mkdir -p \"${GITHUB_WORKSPACE}/typecheck-results/${npm_package_name#*\\/}\" && tsc --emitDeclarationOnly --project tsconfig.build.json --pretty false | typescript-jest-junit-reporter | tee \"${GITHUB_WORKSPACE}/typecheck-results/${npm_package_name#*\\/}/typescript-results.xml\"",
|
|
40
40
|
"clean": "del-cli dist es build *.tsbuildinfo",
|
|
41
|
-
"lint": "
|
|
42
|
-
"lint:
|
|
41
|
+
"lint": "pnpm lint:biome && pnpm lint:eslint",
|
|
42
|
+
"lint:biome": "biome check",
|
|
43
|
+
"lint:eslint": "eslint src -c ../../eslint.config.mjs",
|
|
44
|
+
"lint:ci": "pnpm lint:ci:biome",
|
|
45
|
+
"lint:ci:biome": "mkdir -p \"${GITHUB_WORKSPACE}/test-results/${npm_package_name#*\\/}\" && biome check --diagnostic-level error --reporter=junit > \"${GITHUB_WORKSPACE}/test-results/${npm_package_name#*\\/}/biome-results.xml\"",
|
|
46
|
+
"lint:ci:eslint": "pnpm lint:eslint --quiet --format json -o \"${GITHUB_WORKSPACE}/test-results/${npm_package_name#*\\/}/eslint-results.json\"",
|
|
43
47
|
"test": "jest",
|
|
44
48
|
"test-changed": "pnpm run test --changedSince=master",
|
|
45
49
|
"test:ci": "JEST_JUNIT_OUTPUT_DIR=\"${GITHUB_WORKSPACE}/test-results/${npm_package_name#*\\/}\" JEST_JUNIT_OUTPUT_NAME=\"jest-results.xml\" jest --silent --ci --coverageDirectory=\"${GITHUB_WORKSPACE}/coverage/${npm_package_name#*\\/}\" --reporters=default --reporters=jest-junit --maxWorkers=4",
|