@knapsack/schema-utils 4.70.0--canary.3797.b249674.0 → 4.70.0--canary.4821.56b0218.0
Sign up to get free protection for your applications and to get access to all the features.
- package/dist/schema-utils.js +93 -16
- package/dist/schema-utils.js.map +1 -1
- package/dist/schema-utils.mjs +58 -6
- package/dist/schema-utils.mjs.map +1 -1
- package/package.json +4 -4
package/dist/schema-utils.js
CHANGED
@@ -1,18 +1,95 @@
|
|
1
|
-
|
1
|
+
var __create = Object.create;
|
2
|
+
var __defProp = Object.defineProperty;
|
3
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
4
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
5
|
+
var __getProtoOf = Object.getPrototypeOf;
|
6
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
7
|
+
var __name = (target, value) => __defProp(target, "name", { value, configurable: true });
|
8
|
+
var __export = (target, all) => {
|
9
|
+
for (var name in all)
|
10
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
11
|
+
};
|
12
|
+
var __copyProps = (to, from, except, desc) => {
|
13
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
14
|
+
for (let key of __getOwnPropNames(from))
|
15
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
16
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
17
|
+
}
|
18
|
+
return to;
|
19
|
+
};
|
20
|
+
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
|
21
|
+
// If the importer is in node compatibility mode or this is not an ESM
|
22
|
+
// file that has been converted to a CommonJS file using a Babel-
|
23
|
+
// compatible transform (i.e. "__esModule" has not been set), then set
|
24
|
+
// "default" to the CommonJS "module.exports" for node compatibility.
|
25
|
+
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
|
26
|
+
mod
|
27
|
+
));
|
28
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
2
29
|
|
3
|
-
|
4
|
-
var
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
30
|
+
// src/schema-utils.ts
|
31
|
+
var schema_utils_exports = {};
|
32
|
+
__export(schema_utils_exports, {
|
33
|
+
ajv: () => ajv,
|
34
|
+
validateDataAgainstSchema: () => validateDataAgainstSchema,
|
35
|
+
validateSchema: () => validateSchema,
|
36
|
+
validateSchemaAndAssignDefaults: () => validateSchemaAndAssignDefaults
|
37
|
+
});
|
38
|
+
module.exports = __toCommonJS(schema_utils_exports);
|
39
|
+
var import_ajv = __toESM(require("ajv"));
|
40
|
+
var import_typeof = __toESM(require("ajv-keywords/keywords/typeof.js"));
|
41
|
+
var ajv = new import_ajv.default();
|
42
|
+
(0, import_typeof.default)(ajv);
|
43
|
+
var ajvDefaults = new import_ajv.default({
|
44
|
+
useDefaults: true
|
45
|
+
});
|
46
|
+
function validateSchema(schema) {
|
47
|
+
const isSchemaValid = ajv.validateSchema(schema);
|
48
|
+
return {
|
49
|
+
ok: isSchemaValid,
|
50
|
+
message: isSchemaValid ? "" : `Schema itself is not valid. ${ajv.errorsText()}`
|
51
|
+
};
|
52
|
+
}
|
53
|
+
__name(validateSchema, "validateSchema");
|
54
|
+
function validateSchemaAndAssignDefaults(schema, data) {
|
55
|
+
const { ok, message } = validateSchema(schema);
|
56
|
+
if (!ok) {
|
57
|
+
return {
|
58
|
+
ok: false,
|
59
|
+
message,
|
60
|
+
data
|
61
|
+
};
|
62
|
+
}
|
63
|
+
const newData = { ...data };
|
64
|
+
const isValid = !!ajvDefaults.validate(schema, newData);
|
65
|
+
return {
|
66
|
+
ok: isValid,
|
67
|
+
message: isValid ? "" : ajvDefaults.errorsText(),
|
68
|
+
data: newData
|
69
|
+
};
|
70
|
+
}
|
71
|
+
__name(validateSchemaAndAssignDefaults, "validateSchemaAndAssignDefaults");
|
72
|
+
function validateDataAgainstSchema(schema, data) {
|
73
|
+
const { ok, message } = validateSchema(schema);
|
74
|
+
if (!ok) {
|
75
|
+
return {
|
76
|
+
ok: false,
|
77
|
+
message
|
78
|
+
};
|
79
|
+
}
|
80
|
+
const isValid = !!ajv.validate(schema, data);
|
81
|
+
return {
|
82
|
+
ok: isValid,
|
83
|
+
message: isValid ? "" : ajv.errorsText(),
|
84
|
+
errors: isValid ? [] : ajv.errors
|
85
|
+
};
|
86
|
+
}
|
87
|
+
__name(validateDataAgainstSchema, "validateDataAgainstSchema");
|
88
|
+
// Annotate the CommonJS export names for ESM import in node:
|
89
|
+
0 && (module.exports = {
|
90
|
+
ajv,
|
91
|
+
validateDataAgainstSchema,
|
92
|
+
validateSchema,
|
93
|
+
validateSchemaAndAssignDefaults
|
94
|
+
});
|
18
95
|
//# sourceMappingURL=schema-utils.js.map
|
package/dist/schema-utils.js.map
CHANGED
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"sources":["../src/schema-utils.ts"],"
|
1
|
+
{"version":3,"sources":["../src/schema-utils.ts"],"sourcesContent":["import Ajv from 'ajv'; // https://github.com/epoberezkin/ajv\nimport addTypeofKeyword from 'ajv-keywords/keywords/typeof.js';\n\nexport const ajv = new Ajv();\n\naddTypeofKeyword(ajv);\n\ntype ajvErrors = import('ajv').ErrorObject[];\n\nconst ajvDefaults = new Ajv({\n useDefaults: true,\n});\n\n/**\n * Validate Schema itself (metaSchema)\n * Validates against contents of the `$schema` field\n * @link https://github.com/epoberezkin/ajv#validateschemaobject-schema---boolean\n */\nexport function validateSchema(schema: Record<string, unknown>): {\n ok: boolean;\n message: string;\n} {\n const isSchemaValid = ajv.validateSchema(schema);\n return {\n ok: isSchemaValid,\n message: isSchemaValid\n ? ''\n : `Schema itself is not valid. ${ajv.errorsText()}`,\n };\n}\n\n/**\n * Validate Schema and Assign Defaults\n * Any `default` on properties will be added if that property is absent\n * @link https://github.com/epoberezkin/ajv#assigning-defaults\n */\nexport function validateSchemaAndAssignDefaults<T>(\n schema: Record<string, unknown>,\n data: T,\n): { ok: boolean; message: string; data: T } {\n const { ok, message } = validateSchema(schema);\n if (!ok) {\n return {\n ok: false,\n message,\n data,\n };\n }\n\n const newData = { ...data };\n // This `validate` function mutates `newData`, so that's why we created a new object above first.\n const isValid = !!ajvDefaults.validate(schema, newData);\n return {\n ok: isValid,\n message: isValid ? '' : ajvDefaults.errorsText(),\n data: newData,\n };\n}\n\n/**\n * Validate Data against Schema\n * @link https://github.com/epoberezkin/ajv\n */\nexport function validateDataAgainstSchema<T>(\n schema: Record<string, unknown>,\n data: T,\n): {\n ok: boolean;\n message: string;\n errors?: ajvErrors;\n} {\n const { ok, message } = validateSchema(schema);\n if (!ok) {\n return {\n ok: false,\n message,\n };\n }\n\n const isValid = !!ajv.validate(schema, data);\n return {\n ok: isValid,\n message: isValid ? '' : ajv.errorsText(),\n errors: isValid ? [] : ajv.errors,\n };\n}\n\n//\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,iBAAgB;AAChB,oBAA6B;AAEtB,IAAM,MAAM,IAAI,WAAAA,QAAI;AAAA,IAE3B,cAAAC,SAAiB,GAAG;AAIpB,IAAM,cAAc,IAAI,WAAAD,QAAI;AAAA,EAC1B,aAAa;AACf,CAAC;AAOM,SAAS,eAAe,QAG7B;AACA,QAAM,gBAAgB,IAAI,eAAe,MAAM;AAC/C,SAAO;AAAA,IACL,IAAI;AAAA,IACJ,SAAS,gBACL,KACA,+BAA+B,IAAI,WAAW,CAAC;AAAA,EACrD;AACF;AAXgB;AAkBT,SAAS,gCACd,QACA,MAC2C;AAC3C,QAAM,EAAE,IAAI,QAAQ,IAAI,eAAe,MAAM;AAC7C,MAAI,CAAC,IAAI;AACP,WAAO;AAAA,MACL,IAAI;AAAA,MACJ;AAAA,MACA;AAAA,IACF;AAAA,EACF;AAEA,QAAM,UAAU,EAAE,GAAG,KAAK;AAE1B,QAAM,UAAU,CAAC,CAAC,YAAY,SAAS,QAAQ,OAAO;AACtD,SAAO;AAAA,IACL,IAAI;AAAA,IACJ,SAAS,UAAU,KAAK,YAAY,WAAW;AAAA,IAC/C,MAAM;AAAA,EACR;AACF;AArBgB;AA2BT,SAAS,0BACd,QACA,MAKA;AACA,QAAM,EAAE,IAAI,QAAQ,IAAI,eAAe,MAAM;AAC7C,MAAI,CAAC,IAAI;AACP,WAAO;AAAA,MACL,IAAI;AAAA,MACJ;AAAA,IACF;AAAA,EACF;AAEA,QAAM,UAAU,CAAC,CAAC,IAAI,SAAS,QAAQ,IAAI;AAC3C,SAAO;AAAA,IACL,IAAI;AAAA,IACJ,SAAS,UAAU,KAAK,IAAI,WAAW;AAAA,IACvC,QAAQ,UAAU,CAAC,IAAI,IAAI;AAAA,EAC7B;AACF;AAtBgB;","names":["Ajv","addTypeofKeyword"]}
|
package/dist/schema-utils.mjs
CHANGED
@@ -1,8 +1,60 @@
|
|
1
|
-
|
2
|
-
|
1
|
+
var __defProp = Object.defineProperty;
|
2
|
+
var __name = (target, value) => __defProp(target, "name", { value, configurable: true });
|
3
3
|
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
4
|
+
// src/schema-utils.ts
|
5
|
+
import Ajv from "ajv";
|
6
|
+
import addTypeofKeyword from "ajv-keywords/keywords/typeof.js";
|
7
|
+
var ajv = new Ajv();
|
8
|
+
addTypeofKeyword(ajv);
|
9
|
+
var ajvDefaults = new Ajv({
|
10
|
+
useDefaults: true
|
11
|
+
});
|
12
|
+
function validateSchema(schema) {
|
13
|
+
const isSchemaValid = ajv.validateSchema(schema);
|
14
|
+
return {
|
15
|
+
ok: isSchemaValid,
|
16
|
+
message: isSchemaValid ? "" : `Schema itself is not valid. ${ajv.errorsText()}`
|
17
|
+
};
|
18
|
+
}
|
19
|
+
__name(validateSchema, "validateSchema");
|
20
|
+
function validateSchemaAndAssignDefaults(schema, data) {
|
21
|
+
const { ok, message } = validateSchema(schema);
|
22
|
+
if (!ok) {
|
23
|
+
return {
|
24
|
+
ok: false,
|
25
|
+
message,
|
26
|
+
data
|
27
|
+
};
|
28
|
+
}
|
29
|
+
const newData = { ...data };
|
30
|
+
const isValid = !!ajvDefaults.validate(schema, newData);
|
31
|
+
return {
|
32
|
+
ok: isValid,
|
33
|
+
message: isValid ? "" : ajvDefaults.errorsText(),
|
34
|
+
data: newData
|
35
|
+
};
|
36
|
+
}
|
37
|
+
__name(validateSchemaAndAssignDefaults, "validateSchemaAndAssignDefaults");
|
38
|
+
function validateDataAgainstSchema(schema, data) {
|
39
|
+
const { ok, message } = validateSchema(schema);
|
40
|
+
if (!ok) {
|
41
|
+
return {
|
42
|
+
ok: false,
|
43
|
+
message
|
44
|
+
};
|
45
|
+
}
|
46
|
+
const isValid = !!ajv.validate(schema, data);
|
47
|
+
return {
|
48
|
+
ok: isValid,
|
49
|
+
message: isValid ? "" : ajv.errorsText(),
|
50
|
+
errors: isValid ? [] : ajv.errors
|
51
|
+
};
|
52
|
+
}
|
53
|
+
__name(validateDataAgainstSchema, "validateDataAgainstSchema");
|
54
|
+
export {
|
55
|
+
ajv,
|
56
|
+
validateDataAgainstSchema,
|
57
|
+
validateSchema,
|
58
|
+
validateSchemaAndAssignDefaults
|
59
|
+
};
|
8
60
|
//# sourceMappingURL=schema-utils.mjs.map
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"sources":["../src/schema-utils.ts"],"
|
1
|
+
{"version":3,"sources":["../src/schema-utils.ts"],"sourcesContent":["import Ajv from 'ajv'; // https://github.com/epoberezkin/ajv\nimport addTypeofKeyword from 'ajv-keywords/keywords/typeof.js';\n\nexport const ajv = new Ajv();\n\naddTypeofKeyword(ajv);\n\ntype ajvErrors = import('ajv').ErrorObject[];\n\nconst ajvDefaults = new Ajv({\n useDefaults: true,\n});\n\n/**\n * Validate Schema itself (metaSchema)\n * Validates against contents of the `$schema` field\n * @link https://github.com/epoberezkin/ajv#validateschemaobject-schema---boolean\n */\nexport function validateSchema(schema: Record<string, unknown>): {\n ok: boolean;\n message: string;\n} {\n const isSchemaValid = ajv.validateSchema(schema);\n return {\n ok: isSchemaValid,\n message: isSchemaValid\n ? ''\n : `Schema itself is not valid. ${ajv.errorsText()}`,\n };\n}\n\n/**\n * Validate Schema and Assign Defaults\n * Any `default` on properties will be added if that property is absent\n * @link https://github.com/epoberezkin/ajv#assigning-defaults\n */\nexport function validateSchemaAndAssignDefaults<T>(\n schema: Record<string, unknown>,\n data: T,\n): { ok: boolean; message: string; data: T } {\n const { ok, message } = validateSchema(schema);\n if (!ok) {\n return {\n ok: false,\n message,\n data,\n };\n }\n\n const newData = { ...data };\n // This `validate` function mutates `newData`, so that's why we created a new object above first.\n const isValid = !!ajvDefaults.validate(schema, newData);\n return {\n ok: isValid,\n message: isValid ? '' : ajvDefaults.errorsText(),\n data: newData,\n };\n}\n\n/**\n * Validate Data against Schema\n * @link https://github.com/epoberezkin/ajv\n */\nexport function validateDataAgainstSchema<T>(\n schema: Record<string, unknown>,\n data: T,\n): {\n ok: boolean;\n message: string;\n errors?: ajvErrors;\n} {\n const { ok, message } = validateSchema(schema);\n if (!ok) {\n return {\n ok: false,\n message,\n };\n }\n\n const isValid = !!ajv.validate(schema, data);\n return {\n ok: isValid,\n message: isValid ? '' : ajv.errorsText(),\n errors: isValid ? [] : ajv.errors,\n };\n}\n\n//\n"],"mappings":";;;;AAAA,OAAO,SAAS;AAChB,OAAO,sBAAsB;AAEtB,IAAM,MAAM,IAAI,IAAI;AAE3B,iBAAiB,GAAG;AAIpB,IAAM,cAAc,IAAI,IAAI;AAAA,EAC1B,aAAa;AACf,CAAC;AAOM,SAAS,eAAe,QAG7B;AACA,QAAM,gBAAgB,IAAI,eAAe,MAAM;AAC/C,SAAO;AAAA,IACL,IAAI;AAAA,IACJ,SAAS,gBACL,KACA,+BAA+B,IAAI,WAAW,CAAC;AAAA,EACrD;AACF;AAXgB;AAkBT,SAAS,gCACd,QACA,MAC2C;AAC3C,QAAM,EAAE,IAAI,QAAQ,IAAI,eAAe,MAAM;AAC7C,MAAI,CAAC,IAAI;AACP,WAAO;AAAA,MACL,IAAI;AAAA,MACJ;AAAA,MACA;AAAA,IACF;AAAA,EACF;AAEA,QAAM,UAAU,EAAE,GAAG,KAAK;AAE1B,QAAM,UAAU,CAAC,CAAC,YAAY,SAAS,QAAQ,OAAO;AACtD,SAAO;AAAA,IACL,IAAI;AAAA,IACJ,SAAS,UAAU,KAAK,YAAY,WAAW;AAAA,IAC/C,MAAM;AAAA,EACR;AACF;AArBgB;AA2BT,SAAS,0BACd,QACA,MAKA;AACA,QAAM,EAAE,IAAI,QAAQ,IAAI,eAAe,MAAM;AAC7C,MAAI,CAAC,IAAI;AACP,WAAO;AAAA,MACL,IAAI;AAAA,MACJ;AAAA,IACF;AAAA,EACF;AAEA,QAAM,UAAU,CAAC,CAAC,IAAI,SAAS,QAAQ,IAAI;AAC3C,SAAO;AAAA,IACL,IAAI;AAAA,IACJ,SAAS,UAAU,KAAK,IAAI,WAAW;AAAA,IACvC,QAAQ,UAAU,CAAC,IAAI,IAAI;AAAA,EAC7B;AACF;AAtBgB;","names":[]}
|
package/package.json
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
{
|
2
2
|
"name": "@knapsack/schema-utils",
|
3
3
|
"description": "A Knapsack component that helps build Design Systems",
|
4
|
-
"version": "4.70.0--canary.
|
4
|
+
"version": "4.70.0--canary.4821.56b0218.0",
|
5
5
|
"source": "src/schema-utils.ts",
|
6
6
|
"main": "dist/schema-utils.js",
|
7
7
|
"module": "dist/schema-utils.mjs",
|
@@ -29,8 +29,8 @@
|
|
29
29
|
"tslib": "^2.7.0"
|
30
30
|
},
|
31
31
|
"devDependencies": {
|
32
|
-
"@knapsack/eslint-config-starter": "4.70.0--canary.
|
33
|
-
"@knapsack/typescript-config-starter": "4.70.0--canary.
|
32
|
+
"@knapsack/eslint-config-starter": "4.70.0--canary.4821.56b0218.0",
|
33
|
+
"@knapsack/typescript-config-starter": "4.70.0--canary.4821.56b0218.0",
|
34
34
|
"eslint": "^8.57.0",
|
35
35
|
"tsup": "^8.2.4"
|
36
36
|
},
|
@@ -43,5 +43,5 @@
|
|
43
43
|
"directory": "libs/schema-utils",
|
44
44
|
"type": "git"
|
45
45
|
},
|
46
|
-
"gitHead": "
|
46
|
+
"gitHead": "56b02187ee87f98fefa3254d2a725a06fc1f13f8"
|
47
47
|
}
|