@blueking/bkui-form 1.0.1-beta.1 → 1.0.1-beta.3

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 (168) hide show
  1. package/esm/adapter/common/FieldGroupWrap.tsx.js +199 -0
  2. package/esm/adapter/field/ArrayField.tsx.js +55 -0
  3. package/esm/adapter/field/BooleanField.tsx.js +41 -0
  4. package/esm/adapter/field/CompositionField.tsx.js +113 -0
  5. package/esm/adapter/field/FieldProps.ts.js +85 -0
  6. package/esm/adapter/field/NumberField.tsx.js +19 -0
  7. package/esm/adapter/field/ObjectField.tsx.js +58 -0
  8. package/esm/adapter/field/SchemaField.tsx.js +28 -0
  9. package/esm/adapter/field/StringField.tsx.js +4 -0
  10. package/esm/adapter/widget/ArrayWidget.ts.js +196 -0
  11. package/esm/adapter/widget/ButtonWidget.ts.js +76 -0
  12. package/esm/adapter/widget/CheckboxWidget.ts.js +101 -0
  13. package/esm/adapter/widget/CollapseGroupWidget.ts.js +140 -0
  14. package/esm/adapter/widget/ColorPickerWidget.ts.js +71 -0
  15. package/esm/adapter/widget/InputWidget.ts.js +79 -0
  16. package/esm/adapter/widget/KeyValueArrayWidget.tsx.js +156 -0
  17. package/esm/adapter/widget/RadioWidget.ts.js +98 -0
  18. package/esm/adapter/widget/SelectWidget.ts.js +98 -0
  19. package/esm/adapter/widget/SwitchWidget.ts.js +73 -0
  20. package/esm/adapter/widget/TabGroupWidget.ts.js +145 -0
  21. package/esm/adapter/widget/TableWidget.ts.js +205 -0
  22. package/esm/adapter/widget/Widget.ts.js +497 -0
  23. package/esm/assets/fonts/iconcool.eot +0 -0
  24. package/esm/assets/fonts/iconcool.ttf +0 -0
  25. package/esm/assets/fonts/iconcool.woff +0 -0
  26. package/esm/assets/style.css +43 -0
  27. package/esm/controller/form.css +164 -0
  28. package/esm/controller/form.tsx.js +159 -0
  29. package/esm/controller/props.ts.js +75 -0
  30. package/esm/core/events.ts.js +74 -0
  31. package/esm/core/expression.ts.js +67 -0
  32. package/esm/core/lang.ts.js +25 -0
  33. package/esm/core/layout.ts.js +149 -0
  34. package/esm/core/path.ts.js +60 -0
  35. package/esm/core/proxy.ts.js +10 -0
  36. package/esm/core/reaction.ts.js +116 -0
  37. package/esm/core/register.ts.js +74 -0
  38. package/esm/core/schema.ts.js +302 -0
  39. package/esm/core/validator.ts.js +248 -0
  40. package/esm/core/widgetTree.ts.js +163 -0
  41. package/esm/index.ts.js +6 -0
  42. package/esm/node_modules/@blueking/cli-service/dist/lib/path.js +35 -0
  43. package/esm/node_modules/@blueking/cli-service/dist/lib/util.js +233 -0
  44. package/esm/node_modules/@blueking/cli-service/dist/tools/rust/helper/path.js +172 -0
  45. package/esm/node_modules/ajv/dist/ajv.js +50 -0
  46. package/esm/node_modules/ajv/dist/compile/codegen/code.js +156 -0
  47. package/esm/node_modules/ajv/dist/compile/codegen/index.js +697 -0
  48. package/esm/node_modules/ajv/dist/compile/codegen/scope.js +143 -0
  49. package/esm/node_modules/ajv/dist/compile/errors.js +123 -0
  50. package/esm/node_modules/ajv/dist/compile/index.js +242 -0
  51. package/esm/node_modules/ajv/dist/compile/names.js +28 -0
  52. package/esm/node_modules/ajv/dist/compile/ref_error.js +12 -0
  53. package/esm/node_modules/ajv/dist/compile/resolve.js +155 -0
  54. package/esm/node_modules/ajv/dist/compile/rules.js +26 -0
  55. package/esm/node_modules/ajv/dist/compile/util.js +178 -0
  56. package/esm/node_modules/ajv/dist/compile/validate/applicability.js +19 -0
  57. package/esm/node_modules/ajv/dist/compile/validate/boolSchema.js +50 -0
  58. package/esm/node_modules/ajv/dist/compile/validate/dataType.js +203 -0
  59. package/esm/node_modules/ajv/dist/compile/validate/defaults.js +35 -0
  60. package/esm/node_modules/ajv/dist/compile/validate/index.js +520 -0
  61. package/esm/node_modules/ajv/dist/compile/validate/keyword.js +124 -0
  62. package/esm/node_modules/ajv/dist/compile/validate/subschema.js +81 -0
  63. package/esm/node_modules/ajv/dist/core.js +618 -0
  64. package/esm/node_modules/ajv/dist/refs/data.json +13 -0
  65. package/esm/node_modules/ajv/dist/refs/json-schema-draft-07.json +151 -0
  66. package/esm/node_modules/ajv/dist/runtime/equal.js +7 -0
  67. package/esm/node_modules/ajv/dist/runtime/ucs2length.js +24 -0
  68. package/esm/node_modules/ajv/dist/runtime/uri.js +6 -0
  69. package/esm/node_modules/ajv/dist/runtime/validation_error.js +11 -0
  70. package/esm/node_modules/ajv/dist/vocabularies/applicator/additionalItems.js +49 -0
  71. package/esm/node_modules/ajv/dist/vocabularies/applicator/additionalProperties.js +106 -0
  72. package/esm/node_modules/ajv/dist/vocabularies/applicator/allOf.js +23 -0
  73. package/esm/node_modules/ajv/dist/vocabularies/applicator/anyOf.js +12 -0
  74. package/esm/node_modules/ajv/dist/vocabularies/applicator/contains.js +95 -0
  75. package/esm/node_modules/ajv/dist/vocabularies/applicator/dependencies.js +85 -0
  76. package/esm/node_modules/ajv/dist/vocabularies/applicator/if.js +66 -0
  77. package/esm/node_modules/ajv/dist/vocabularies/applicator/index.js +44 -0
  78. package/esm/node_modules/ajv/dist/vocabularies/applicator/items.js +52 -0
  79. package/esm/node_modules/ajv/dist/vocabularies/applicator/items2020.js +30 -0
  80. package/esm/node_modules/ajv/dist/vocabularies/applicator/not.js +26 -0
  81. package/esm/node_modules/ajv/dist/vocabularies/applicator/oneOf.js +60 -0
  82. package/esm/node_modules/ajv/dist/vocabularies/applicator/patternProperties.js +75 -0
  83. package/esm/node_modules/ajv/dist/vocabularies/applicator/prefixItems.js +12 -0
  84. package/esm/node_modules/ajv/dist/vocabularies/applicator/properties.js +54 -0
  85. package/esm/node_modules/ajv/dist/vocabularies/applicator/propertyNames.js +38 -0
  86. package/esm/node_modules/ajv/dist/vocabularies/applicator/thenElse.js +13 -0
  87. package/esm/node_modules/ajv/dist/vocabularies/code.js +131 -0
  88. package/esm/node_modules/ajv/dist/vocabularies/core/id.js +10 -0
  89. package/esm/node_modules/ajv/dist/vocabularies/core/index.js +16 -0
  90. package/esm/node_modules/ajv/dist/vocabularies/core/ref.js +122 -0
  91. package/esm/node_modules/ajv/dist/vocabularies/discriminator/index.js +104 -0
  92. package/esm/node_modules/ajv/dist/vocabularies/discriminator/types.js +9 -0
  93. package/esm/node_modules/ajv/dist/vocabularies/draft7.js +17 -0
  94. package/esm/node_modules/ajv/dist/vocabularies/format/format.js +92 -0
  95. package/esm/node_modules/ajv/dist/vocabularies/format/index.js +6 -0
  96. package/esm/node_modules/ajv/dist/vocabularies/metadata.js +18 -0
  97. package/esm/node_modules/ajv/dist/vocabularies/validation/const.js +25 -0
  98. package/esm/node_modules/ajv/dist/vocabularies/validation/enum.js +48 -0
  99. package/esm/node_modules/ajv/dist/vocabularies/validation/index.js +33 -0
  100. package/esm/node_modules/ajv/dist/vocabularies/validation/limitItems.js +24 -0
  101. package/esm/node_modules/ajv/dist/vocabularies/validation/limitLength.js +27 -0
  102. package/esm/node_modules/ajv/dist/vocabularies/validation/limitNumber.js +27 -0
  103. package/esm/node_modules/ajv/dist/vocabularies/validation/limitProperties.js +24 -0
  104. package/esm/node_modules/ajv/dist/vocabularies/validation/multipleOf.js +26 -0
  105. package/esm/node_modules/ajv/dist/vocabularies/validation/pattern.js +24 -0
  106. package/esm/node_modules/ajv/dist/vocabularies/validation/required.js +79 -0
  107. package/esm/node_modules/ajv/dist/vocabularies/validation/uniqueItems.js +64 -0
  108. package/esm/node_modules/ajv-formats/dist/formats.js +173 -0
  109. package/esm/node_modules/ajv-formats/dist/index.js +37 -0
  110. package/esm/node_modules/ajv-formats/dist/limit.js +69 -0
  111. package/esm/node_modules/ajv-i18n/localize/zh/index.js +154 -0
  112. package/esm/node_modules/fast-deep-equal/index.js +46 -0
  113. package/esm/node_modules/fast-uri/index.js +303 -0
  114. package/esm/node_modules/fast-uri/lib/schemes.js +188 -0
  115. package/esm/node_modules/fast-uri/lib/scopedChars.js +30 -0
  116. package/esm/node_modules/fast-uri/lib/utils.js +244 -0
  117. package/esm/node_modules/json-schema-traverse/index.js +89 -0
  118. package/esm/node_modules/semver/classes/comparator.js +143 -0
  119. package/esm/node_modules/semver/classes/range.js +557 -0
  120. package/esm/node_modules/semver/classes/semver.js +333 -0
  121. package/esm/node_modules/semver/functions/clean.js +8 -0
  122. package/esm/node_modules/semver/functions/cmp.js +54 -0
  123. package/esm/node_modules/semver/functions/coerce.js +62 -0
  124. package/esm/node_modules/semver/functions/compare-build.js +9 -0
  125. package/esm/node_modules/semver/functions/compare-loose.js +5 -0
  126. package/esm/node_modules/semver/functions/compare.js +7 -0
  127. package/esm/node_modules/semver/functions/diff.js +60 -0
  128. package/esm/node_modules/semver/functions/eq.js +5 -0
  129. package/esm/node_modules/semver/functions/gt.js +5 -0
  130. package/esm/node_modules/semver/functions/gte.js +5 -0
  131. package/esm/node_modules/semver/functions/inc.js +21 -0
  132. package/esm/node_modules/semver/functions/lt.js +5 -0
  133. package/esm/node_modules/semver/functions/lte.js +5 -0
  134. package/esm/node_modules/semver/functions/major.js +5 -0
  135. package/esm/node_modules/semver/functions/minor.js +5 -0
  136. package/esm/node_modules/semver/functions/neq.js +5 -0
  137. package/esm/node_modules/semver/functions/parse.js +18 -0
  138. package/esm/node_modules/semver/functions/patch.js +5 -0
  139. package/esm/node_modules/semver/functions/prerelease.js +8 -0
  140. package/esm/node_modules/semver/functions/rcompare.js +5 -0
  141. package/esm/node_modules/semver/functions/rsort.js +5 -0
  142. package/esm/node_modules/semver/functions/satisfies.js +12 -0
  143. package/esm/node_modules/semver/functions/sort.js +5 -0
  144. package/esm/node_modules/semver/functions/valid.js +8 -0
  145. package/esm/node_modules/semver/index.js +91 -0
  146. package/esm/node_modules/semver/internal/constants.js +37 -0
  147. package/esm/node_modules/semver/internal/debug.js +11 -0
  148. package/esm/node_modules/semver/internal/identifiers.js +29 -0
  149. package/esm/node_modules/semver/internal/lrucache.js +42 -0
  150. package/esm/node_modules/semver/internal/parse-options.js +17 -0
  151. package/esm/node_modules/semver/internal/re.js +223 -0
  152. package/esm/node_modules/semver/ranges/gtr.js +6 -0
  153. package/esm/node_modules/semver/ranges/intersects.js +9 -0
  154. package/esm/node_modules/semver/ranges/ltr.js +6 -0
  155. package/esm/node_modules/semver/ranges/max-satisfying.js +27 -0
  156. package/esm/node_modules/semver/ranges/min-satisfying.js +26 -0
  157. package/esm/node_modules/semver/ranges/min-version.js +63 -0
  158. package/esm/node_modules/semver/ranges/outside.js +82 -0
  159. package/esm/node_modules/semver/ranges/simplify.js +49 -0
  160. package/esm/node_modules/semver/ranges/subset.js +249 -0
  161. package/esm/node_modules/semver/ranges/to-comparators.js +10 -0
  162. package/esm/node_modules/semver/ranges/valid.js +13 -0
  163. package/esm/util/fetch.ts.js +190 -0
  164. package/esm/util/index.ts.js +276 -0
  165. package/package.json +3 -4
  166. package/dist/main.css +0 -208
  167. package/dist/main.js +0 -17353
  168. /package/{dist/svg/iconcool.eb237688.svg → esm/assets/fonts/iconcool.svg} +0 -0
@@ -0,0 +1,155 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.getSchemaRefs = exports.resolveUrl = exports.normalizeId = exports._getFullPath = exports.getFullPath = exports.inlineRef = void 0;
4
+ const util_1 = require('./util.js');
5
+ const equal = require('../../../fast-deep-equal/index.js');
6
+ const traverse = require('../../../json-schema-traverse/index.js');
7
+ // TODO refactor to use keyword definitions
8
+ const SIMPLE_INLINED = new Set([
9
+ "type",
10
+ "format",
11
+ "pattern",
12
+ "maxLength",
13
+ "minLength",
14
+ "maxProperties",
15
+ "minProperties",
16
+ "maxItems",
17
+ "minItems",
18
+ "maximum",
19
+ "minimum",
20
+ "uniqueItems",
21
+ "multipleOf",
22
+ "required",
23
+ "enum",
24
+ "const",
25
+ ]);
26
+ function inlineRef(schema, limit = true) {
27
+ if (typeof schema == "boolean")
28
+ return true;
29
+ if (limit === true)
30
+ return !hasRef(schema);
31
+ if (!limit)
32
+ return false;
33
+ return countKeys(schema) <= limit;
34
+ }
35
+ exports.inlineRef = inlineRef;
36
+ const REF_KEYWORDS = new Set([
37
+ "$ref",
38
+ "$recursiveRef",
39
+ "$recursiveAnchor",
40
+ "$dynamicRef",
41
+ "$dynamicAnchor",
42
+ ]);
43
+ function hasRef(schema) {
44
+ for (const key in schema) {
45
+ if (REF_KEYWORDS.has(key))
46
+ return true;
47
+ const sch = schema[key];
48
+ if (Array.isArray(sch) && sch.some(hasRef))
49
+ return true;
50
+ if (typeof sch == "object" && hasRef(sch))
51
+ return true;
52
+ }
53
+ return false;
54
+ }
55
+ function countKeys(schema) {
56
+ let count = 0;
57
+ for (const key in schema) {
58
+ if (key === "$ref")
59
+ return Infinity;
60
+ count++;
61
+ if (SIMPLE_INLINED.has(key))
62
+ continue;
63
+ if (typeof schema[key] == "object") {
64
+ (0, util_1.eachItem)(schema[key], (sch) => (count += countKeys(sch)));
65
+ }
66
+ if (count === Infinity)
67
+ return Infinity;
68
+ }
69
+ return count;
70
+ }
71
+ function getFullPath(resolver, id = "", normalize) {
72
+ if (normalize !== false)
73
+ id = normalizeId(id);
74
+ const p = resolver.parse(id);
75
+ return _getFullPath(resolver, p);
76
+ }
77
+ exports.getFullPath = getFullPath;
78
+ function _getFullPath(resolver, p) {
79
+ const serialized = resolver.serialize(p);
80
+ return serialized.split("#")[0] + "#";
81
+ }
82
+ exports._getFullPath = _getFullPath;
83
+ const TRAILING_SLASH_HASH = /#\/?$/;
84
+ function normalizeId(id) {
85
+ return id ? id.replace(TRAILING_SLASH_HASH, "") : "";
86
+ }
87
+ exports.normalizeId = normalizeId;
88
+ function resolveUrl(resolver, baseId, id) {
89
+ id = normalizeId(id);
90
+ return resolver.resolve(baseId, id);
91
+ }
92
+ exports.resolveUrl = resolveUrl;
93
+ const ANCHOR = /^[a-z_][-a-z0-9._]*$/i;
94
+ function getSchemaRefs(schema, baseId) {
95
+ if (typeof schema == "boolean")
96
+ return {};
97
+ const { schemaId, uriResolver } = this.opts;
98
+ const schId = normalizeId(schema[schemaId] || baseId);
99
+ const baseIds = { "": schId };
100
+ const pathPrefix = getFullPath(uriResolver, schId, false);
101
+ const localRefs = {};
102
+ const schemaRefs = new Set();
103
+ traverse(schema, { allKeys: true }, (sch, jsonPtr, _, parentJsonPtr) => {
104
+ if (parentJsonPtr === undefined)
105
+ return;
106
+ const fullPath = pathPrefix + jsonPtr;
107
+ let innerBaseId = baseIds[parentJsonPtr];
108
+ if (typeof sch[schemaId] == "string")
109
+ innerBaseId = addRef.call(this, sch[schemaId]);
110
+ addAnchor.call(this, sch.$anchor);
111
+ addAnchor.call(this, sch.$dynamicAnchor);
112
+ baseIds[jsonPtr] = innerBaseId;
113
+ function addRef(ref) {
114
+ // eslint-disable-next-line @typescript-eslint/unbound-method
115
+ const _resolve = this.opts.uriResolver.resolve;
116
+ ref = normalizeId(innerBaseId ? _resolve(innerBaseId, ref) : ref);
117
+ if (schemaRefs.has(ref))
118
+ throw ambiguos(ref);
119
+ schemaRefs.add(ref);
120
+ let schOrRef = this.refs[ref];
121
+ if (typeof schOrRef == "string")
122
+ schOrRef = this.refs[schOrRef];
123
+ if (typeof schOrRef == "object") {
124
+ checkAmbiguosRef(sch, schOrRef.schema, ref);
125
+ }
126
+ else if (ref !== normalizeId(fullPath)) {
127
+ if (ref[0] === "#") {
128
+ checkAmbiguosRef(sch, localRefs[ref], ref);
129
+ localRefs[ref] = sch;
130
+ }
131
+ else {
132
+ this.refs[ref] = fullPath;
133
+ }
134
+ }
135
+ return ref;
136
+ }
137
+ function addAnchor(anchor) {
138
+ if (typeof anchor == "string") {
139
+ if (!ANCHOR.test(anchor))
140
+ throw new Error(`invalid anchor "${anchor}"`);
141
+ addRef.call(this, `#${anchor}`);
142
+ }
143
+ }
144
+ });
145
+ return localRefs;
146
+ function checkAmbiguosRef(sch1, sch2, ref) {
147
+ if (sch2 !== undefined && !equal(sch1, sch2))
148
+ throw ambiguos(ref);
149
+ }
150
+ function ambiguos(ref) {
151
+ return new Error(`reference "${ref}" resolves to more than one schema`);
152
+ }
153
+ }
154
+ exports.getSchemaRefs = getSchemaRefs;
155
+ //# sourceMappingURL=resolve.js.map
@@ -0,0 +1,26 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.getRules = exports.isJSONType = void 0;
4
+ const _jsonTypes = ["string", "number", "integer", "boolean", "null", "object", "array"];
5
+ const jsonTypes = new Set(_jsonTypes);
6
+ function isJSONType(x) {
7
+ return typeof x == "string" && jsonTypes.has(x);
8
+ }
9
+ exports.isJSONType = isJSONType;
10
+ function getRules() {
11
+ const groups = {
12
+ number: { type: "number", rules: [] },
13
+ string: { type: "string", rules: [] },
14
+ array: { type: "array", rules: [] },
15
+ object: { type: "object", rules: [] },
16
+ };
17
+ return {
18
+ types: { ...groups, integer: true, boolean: true, null: true },
19
+ rules: [{ rules: [] }, groups.number, groups.string, groups.array, groups.object],
20
+ post: { rules: [] },
21
+ all: {},
22
+ keywords: {},
23
+ };
24
+ }
25
+ exports.getRules = getRules;
26
+ //# sourceMappingURL=rules.js.map
@@ -0,0 +1,178 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.checkStrictMode = exports.getErrorPath = exports.Type = exports.useFunc = exports.setEvaluated = exports.evaluatedPropsToName = exports.mergeEvaluated = exports.eachItem = exports.unescapeJsonPointer = exports.escapeJsonPointer = exports.escapeFragment = exports.unescapeFragment = exports.schemaRefOrVal = exports.schemaHasRulesButRef = exports.schemaHasRules = exports.checkUnknownRules = exports.alwaysValidSchema = exports.toHash = void 0;
4
+ const codegen_1 = require('./codegen/index.js');
5
+ const code_1 = require('./codegen/code.js');
6
+ // TODO refactor to use Set
7
+ function toHash(arr) {
8
+ const hash = {};
9
+ for (const item of arr)
10
+ hash[item] = true;
11
+ return hash;
12
+ }
13
+ exports.toHash = toHash;
14
+ function alwaysValidSchema(it, schema) {
15
+ if (typeof schema == "boolean")
16
+ return schema;
17
+ if (Object.keys(schema).length === 0)
18
+ return true;
19
+ checkUnknownRules(it, schema);
20
+ return !schemaHasRules(schema, it.self.RULES.all);
21
+ }
22
+ exports.alwaysValidSchema = alwaysValidSchema;
23
+ function checkUnknownRules(it, schema = it.schema) {
24
+ const { opts, self } = it;
25
+ if (!opts.strictSchema)
26
+ return;
27
+ if (typeof schema === "boolean")
28
+ return;
29
+ const rules = self.RULES.keywords;
30
+ for (const key in schema) {
31
+ if (!rules[key])
32
+ checkStrictMode(it, `unknown keyword: "${key}"`);
33
+ }
34
+ }
35
+ exports.checkUnknownRules = checkUnknownRules;
36
+ function schemaHasRules(schema, rules) {
37
+ if (typeof schema == "boolean")
38
+ return !schema;
39
+ for (const key in schema)
40
+ if (rules[key])
41
+ return true;
42
+ return false;
43
+ }
44
+ exports.schemaHasRules = schemaHasRules;
45
+ function schemaHasRulesButRef(schema, RULES) {
46
+ if (typeof schema == "boolean")
47
+ return !schema;
48
+ for (const key in schema)
49
+ if (key !== "$ref" && RULES.all[key])
50
+ return true;
51
+ return false;
52
+ }
53
+ exports.schemaHasRulesButRef = schemaHasRulesButRef;
54
+ function schemaRefOrVal({ topSchemaRef, schemaPath }, schema, keyword, $data) {
55
+ if (!$data) {
56
+ if (typeof schema == "number" || typeof schema == "boolean")
57
+ return schema;
58
+ if (typeof schema == "string")
59
+ return (0, codegen_1._) `${schema}`;
60
+ }
61
+ return (0, codegen_1._) `${topSchemaRef}${schemaPath}${(0, codegen_1.getProperty)(keyword)}`;
62
+ }
63
+ exports.schemaRefOrVal = schemaRefOrVal;
64
+ function unescapeFragment(str) {
65
+ return unescapeJsonPointer(decodeURIComponent(str));
66
+ }
67
+ exports.unescapeFragment = unescapeFragment;
68
+ function escapeFragment(str) {
69
+ return encodeURIComponent(escapeJsonPointer(str));
70
+ }
71
+ exports.escapeFragment = escapeFragment;
72
+ function escapeJsonPointer(str) {
73
+ if (typeof str == "number")
74
+ return `${str}`;
75
+ return str.replace(/~/g, "~0").replace(/\//g, "~1");
76
+ }
77
+ exports.escapeJsonPointer = escapeJsonPointer;
78
+ function unescapeJsonPointer(str) {
79
+ return str.replace(/~1/g, "/").replace(/~0/g, "~");
80
+ }
81
+ exports.unescapeJsonPointer = unescapeJsonPointer;
82
+ function eachItem(xs, f) {
83
+ if (Array.isArray(xs)) {
84
+ for (const x of xs)
85
+ f(x);
86
+ }
87
+ else {
88
+ f(xs);
89
+ }
90
+ }
91
+ exports.eachItem = eachItem;
92
+ function makeMergeEvaluated({ mergeNames, mergeToName, mergeValues, resultToName, }) {
93
+ return (gen, from, to, toName) => {
94
+ const res = to === undefined
95
+ ? from
96
+ : to instanceof codegen_1.Name
97
+ ? (from instanceof codegen_1.Name ? mergeNames(gen, from, to) : mergeToName(gen, from, to), to)
98
+ : from instanceof codegen_1.Name
99
+ ? (mergeToName(gen, to, from), from)
100
+ : mergeValues(from, to);
101
+ return toName === codegen_1.Name && !(res instanceof codegen_1.Name) ? resultToName(gen, res) : res;
102
+ };
103
+ }
104
+ exports.mergeEvaluated = {
105
+ props: makeMergeEvaluated({
106
+ mergeNames: (gen, from, to) => gen.if((0, codegen_1._) `${to} !== true && ${from} !== undefined`, () => {
107
+ gen.if((0, codegen_1._) `${from} === true`, () => gen.assign(to, true), () => gen.assign(to, (0, codegen_1._) `${to} || {}`).code((0, codegen_1._) `Object.assign(${to}, ${from})`));
108
+ }),
109
+ mergeToName: (gen, from, to) => gen.if((0, codegen_1._) `${to} !== true`, () => {
110
+ if (from === true) {
111
+ gen.assign(to, true);
112
+ }
113
+ else {
114
+ gen.assign(to, (0, codegen_1._) `${to} || {}`);
115
+ setEvaluated(gen, to, from);
116
+ }
117
+ }),
118
+ mergeValues: (from, to) => (from === true ? true : { ...from, ...to }),
119
+ resultToName: evaluatedPropsToName,
120
+ }),
121
+ items: makeMergeEvaluated({
122
+ mergeNames: (gen, from, to) => gen.if((0, codegen_1._) `${to} !== true && ${from} !== undefined`, () => gen.assign(to, (0, codegen_1._) `${from} === true ? true : ${to} > ${from} ? ${to} : ${from}`)),
123
+ mergeToName: (gen, from, to) => gen.if((0, codegen_1._) `${to} !== true`, () => gen.assign(to, from === true ? true : (0, codegen_1._) `${to} > ${from} ? ${to} : ${from}`)),
124
+ mergeValues: (from, to) => (from === true ? true : Math.max(from, to)),
125
+ resultToName: (gen, items) => gen.var("items", items),
126
+ }),
127
+ };
128
+ function evaluatedPropsToName(gen, ps) {
129
+ if (ps === true)
130
+ return gen.var("props", true);
131
+ const props = gen.var("props", (0, codegen_1._) `{}`);
132
+ if (ps !== undefined)
133
+ setEvaluated(gen, props, ps);
134
+ return props;
135
+ }
136
+ exports.evaluatedPropsToName = evaluatedPropsToName;
137
+ function setEvaluated(gen, props, ps) {
138
+ Object.keys(ps).forEach((p) => gen.assign((0, codegen_1._) `${props}${(0, codegen_1.getProperty)(p)}`, true));
139
+ }
140
+ exports.setEvaluated = setEvaluated;
141
+ const snippets = {};
142
+ function useFunc(gen, f) {
143
+ return gen.scopeValue("func", {
144
+ ref: f,
145
+ code: snippets[f.code] || (snippets[f.code] = new code_1._Code(f.code)),
146
+ });
147
+ }
148
+ exports.useFunc = useFunc;
149
+ var Type;
150
+ (function (Type) {
151
+ Type[Type["Num"] = 0] = "Num";
152
+ Type[Type["Str"] = 1] = "Str";
153
+ })(Type || (exports.Type = Type = {}));
154
+ function getErrorPath(dataProp, dataPropType, jsPropertySyntax) {
155
+ // let path
156
+ if (dataProp instanceof codegen_1.Name) {
157
+ const isNumber = dataPropType === Type.Num;
158
+ return jsPropertySyntax
159
+ ? isNumber
160
+ ? (0, codegen_1._) `"[" + ${dataProp} + "]"`
161
+ : (0, codegen_1._) `"['" + ${dataProp} + "']"`
162
+ : isNumber
163
+ ? (0, codegen_1._) `"/" + ${dataProp}`
164
+ : (0, codegen_1._) `"/" + ${dataProp}.replace(/~/g, "~0").replace(/\\//g, "~1")`; // TODO maybe use global escapePointer
165
+ }
166
+ return jsPropertySyntax ? (0, codegen_1.getProperty)(dataProp).toString() : "/" + escapeJsonPointer(dataProp);
167
+ }
168
+ exports.getErrorPath = getErrorPath;
169
+ function checkStrictMode(it, msg, mode = it.opts.strictSchema) {
170
+ if (!mode)
171
+ return;
172
+ msg = `strict mode: ${msg}`;
173
+ if (mode === true)
174
+ throw new Error(msg);
175
+ it.self.logger.warn(msg);
176
+ }
177
+ exports.checkStrictMode = checkStrictMode;
178
+ //# sourceMappingURL=util.js.map
@@ -0,0 +1,19 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.shouldUseRule = exports.shouldUseGroup = exports.schemaHasRulesForType = void 0;
4
+ function schemaHasRulesForType({ schema, self }, type) {
5
+ const group = self.RULES.types[type];
6
+ return group && group !== true && shouldUseGroup(schema, group);
7
+ }
8
+ exports.schemaHasRulesForType = schemaHasRulesForType;
9
+ function shouldUseGroup(schema, group) {
10
+ return group.rules.some((rule) => shouldUseRule(schema, rule));
11
+ }
12
+ exports.shouldUseGroup = shouldUseGroup;
13
+ function shouldUseRule(schema, rule) {
14
+ var _a;
15
+ return (schema[rule.keyword] !== undefined ||
16
+ ((_a = rule.definition.implements) === null || _a === void 0 ? void 0 : _a.some((kwd) => schema[kwd] !== undefined)));
17
+ }
18
+ exports.shouldUseRule = shouldUseRule;
19
+ //# sourceMappingURL=applicability.js.map
@@ -0,0 +1,50 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.boolOrEmptySchema = exports.topBoolOrEmptySchema = void 0;
4
+ const errors_1 = require('../errors.js');
5
+ const codegen_1 = require('../codegen/index.js');
6
+ const names_1 = require('../names.js');
7
+ const boolError = {
8
+ message: "boolean schema is false",
9
+ };
10
+ function topBoolOrEmptySchema(it) {
11
+ const { gen, schema, validateName } = it;
12
+ if (schema === false) {
13
+ falseSchemaError(it, false);
14
+ }
15
+ else if (typeof schema == "object" && schema.$async === true) {
16
+ gen.return(names_1.default.data);
17
+ }
18
+ else {
19
+ gen.assign((0, codegen_1._) `${validateName}.errors`, null);
20
+ gen.return(true);
21
+ }
22
+ }
23
+ exports.topBoolOrEmptySchema = topBoolOrEmptySchema;
24
+ function boolOrEmptySchema(it, valid) {
25
+ const { gen, schema } = it;
26
+ if (schema === false) {
27
+ gen.var(valid, false); // TODO var
28
+ falseSchemaError(it);
29
+ }
30
+ else {
31
+ gen.var(valid, true); // TODO var
32
+ }
33
+ }
34
+ exports.boolOrEmptySchema = boolOrEmptySchema;
35
+ function falseSchemaError(it, overrideAllErrors) {
36
+ const { gen, data } = it;
37
+ // TODO maybe some other interface should be used for non-keyword validation errors...
38
+ const cxt = {
39
+ gen,
40
+ keyword: "false schema",
41
+ data,
42
+ schema: false,
43
+ schemaCode: false,
44
+ schemaValue: false,
45
+ params: {},
46
+ it,
47
+ };
48
+ (0, errors_1.reportError)(cxt, boolError, undefined, overrideAllErrors);
49
+ }
50
+ //# sourceMappingURL=boolSchema.js.map
@@ -0,0 +1,203 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.reportTypeError = exports.checkDataTypes = exports.checkDataType = exports.coerceAndCheckDataType = exports.getJSONTypes = exports.getSchemaTypes = exports.DataType = void 0;
4
+ const rules_1 = require('../rules.js');
5
+ const applicability_1 = require('./applicability.js');
6
+ const errors_1 = require('../errors.js');
7
+ const codegen_1 = require('../codegen/index.js');
8
+ const util_1 = require('../util.js');
9
+ var DataType;
10
+ (function (DataType) {
11
+ DataType[DataType["Correct"] = 0] = "Correct";
12
+ DataType[DataType["Wrong"] = 1] = "Wrong";
13
+ })(DataType || (exports.DataType = DataType = {}));
14
+ function getSchemaTypes(schema) {
15
+ const types = getJSONTypes(schema.type);
16
+ const hasNull = types.includes("null");
17
+ if (hasNull) {
18
+ if (schema.nullable === false)
19
+ throw new Error("type: null contradicts nullable: false");
20
+ }
21
+ else {
22
+ if (!types.length && schema.nullable !== undefined) {
23
+ throw new Error('"nullable" cannot be used without "type"');
24
+ }
25
+ if (schema.nullable === true)
26
+ types.push("null");
27
+ }
28
+ return types;
29
+ }
30
+ exports.getSchemaTypes = getSchemaTypes;
31
+ // eslint-disable-next-line @typescript-eslint/no-redundant-type-constituents
32
+ function getJSONTypes(ts) {
33
+ const types = Array.isArray(ts) ? ts : ts ? [ts] : [];
34
+ if (types.every(rules_1.isJSONType))
35
+ return types;
36
+ throw new Error("type must be JSONType or JSONType[]: " + types.join(","));
37
+ }
38
+ exports.getJSONTypes = getJSONTypes;
39
+ function coerceAndCheckDataType(it, types) {
40
+ const { gen, data, opts } = it;
41
+ const coerceTo = coerceToTypes(types, opts.coerceTypes);
42
+ const checkTypes = types.length > 0 &&
43
+ !(coerceTo.length === 0 && types.length === 1 && (0, applicability_1.schemaHasRulesForType)(it, types[0]));
44
+ if (checkTypes) {
45
+ const wrongType = checkDataTypes(types, data, opts.strictNumbers, DataType.Wrong);
46
+ gen.if(wrongType, () => {
47
+ if (coerceTo.length)
48
+ coerceData(it, types, coerceTo);
49
+ else
50
+ reportTypeError(it);
51
+ });
52
+ }
53
+ return checkTypes;
54
+ }
55
+ exports.coerceAndCheckDataType = coerceAndCheckDataType;
56
+ const COERCIBLE = new Set(["string", "number", "integer", "boolean", "null"]);
57
+ function coerceToTypes(types, coerceTypes) {
58
+ return coerceTypes
59
+ ? types.filter((t) => COERCIBLE.has(t) || (coerceTypes === "array" && t === "array"))
60
+ : [];
61
+ }
62
+ function coerceData(it, types, coerceTo) {
63
+ const { gen, data, opts } = it;
64
+ const dataType = gen.let("dataType", (0, codegen_1._) `typeof ${data}`);
65
+ const coerced = gen.let("coerced", (0, codegen_1._) `undefined`);
66
+ if (opts.coerceTypes === "array") {
67
+ gen.if((0, codegen_1._) `${dataType} == 'object' && Array.isArray(${data}) && ${data}.length == 1`, () => gen
68
+ .assign(data, (0, codegen_1._) `${data}[0]`)
69
+ .assign(dataType, (0, codegen_1._) `typeof ${data}`)
70
+ .if(checkDataTypes(types, data, opts.strictNumbers), () => gen.assign(coerced, data)));
71
+ }
72
+ gen.if((0, codegen_1._) `${coerced} !== undefined`);
73
+ for (const t of coerceTo) {
74
+ if (COERCIBLE.has(t) || (t === "array" && opts.coerceTypes === "array")) {
75
+ coerceSpecificType(t);
76
+ }
77
+ }
78
+ gen.else();
79
+ reportTypeError(it);
80
+ gen.endIf();
81
+ gen.if((0, codegen_1._) `${coerced} !== undefined`, () => {
82
+ gen.assign(data, coerced);
83
+ assignParentData(it, coerced);
84
+ });
85
+ function coerceSpecificType(t) {
86
+ switch (t) {
87
+ case "string":
88
+ gen
89
+ .elseIf((0, codegen_1._) `${dataType} == "number" || ${dataType} == "boolean"`)
90
+ .assign(coerced, (0, codegen_1._) `"" + ${data}`)
91
+ .elseIf((0, codegen_1._) `${data} === null`)
92
+ .assign(coerced, (0, codegen_1._) `""`);
93
+ return;
94
+ case "number":
95
+ gen
96
+ .elseIf((0, codegen_1._) `${dataType} == "boolean" || ${data} === null
97
+ || (${dataType} == "string" && ${data} && ${data} == +${data})`)
98
+ .assign(coerced, (0, codegen_1._) `+${data}`);
99
+ return;
100
+ case "integer":
101
+ gen
102
+ .elseIf((0, codegen_1._) `${dataType} === "boolean" || ${data} === null
103
+ || (${dataType} === "string" && ${data} && ${data} == +${data} && !(${data} % 1))`)
104
+ .assign(coerced, (0, codegen_1._) `+${data}`);
105
+ return;
106
+ case "boolean":
107
+ gen
108
+ .elseIf((0, codegen_1._) `${data} === "false" || ${data} === 0 || ${data} === null`)
109
+ .assign(coerced, false)
110
+ .elseIf((0, codegen_1._) `${data} === "true" || ${data} === 1`)
111
+ .assign(coerced, true);
112
+ return;
113
+ case "null":
114
+ gen.elseIf((0, codegen_1._) `${data} === "" || ${data} === 0 || ${data} === false`);
115
+ gen.assign(coerced, null);
116
+ return;
117
+ case "array":
118
+ gen
119
+ .elseIf((0, codegen_1._) `${dataType} === "string" || ${dataType} === "number"
120
+ || ${dataType} === "boolean" || ${data} === null`)
121
+ .assign(coerced, (0, codegen_1._) `[${data}]`);
122
+ }
123
+ }
124
+ }
125
+ function assignParentData({ gen, parentData, parentDataProperty }, expr) {
126
+ // TODO use gen.property
127
+ gen.if((0, codegen_1._) `${parentData} !== undefined`, () => gen.assign((0, codegen_1._) `${parentData}[${parentDataProperty}]`, expr));
128
+ }
129
+ function checkDataType(dataType, data, strictNums, correct = DataType.Correct) {
130
+ const EQ = correct === DataType.Correct ? codegen_1.operators.EQ : codegen_1.operators.NEQ;
131
+ let cond;
132
+ switch (dataType) {
133
+ case "null":
134
+ return (0, codegen_1._) `${data} ${EQ} null`;
135
+ case "array":
136
+ cond = (0, codegen_1._) `Array.isArray(${data})`;
137
+ break;
138
+ case "object":
139
+ cond = (0, codegen_1._) `${data} && typeof ${data} == "object" && !Array.isArray(${data})`;
140
+ break;
141
+ case "integer":
142
+ cond = numCond((0, codegen_1._) `!(${data} % 1) && !isNaN(${data})`);
143
+ break;
144
+ case "number":
145
+ cond = numCond();
146
+ break;
147
+ default:
148
+ return (0, codegen_1._) `typeof ${data} ${EQ} ${dataType}`;
149
+ }
150
+ return correct === DataType.Correct ? cond : (0, codegen_1.not)(cond);
151
+ function numCond(_cond = codegen_1.nil) {
152
+ return (0, codegen_1.and)((0, codegen_1._) `typeof ${data} == "number"`, _cond, strictNums ? (0, codegen_1._) `isFinite(${data})` : codegen_1.nil);
153
+ }
154
+ }
155
+ exports.checkDataType = checkDataType;
156
+ function checkDataTypes(dataTypes, data, strictNums, correct) {
157
+ if (dataTypes.length === 1) {
158
+ return checkDataType(dataTypes[0], data, strictNums, correct);
159
+ }
160
+ let cond;
161
+ const types = (0, util_1.toHash)(dataTypes);
162
+ if (types.array && types.object) {
163
+ const notObj = (0, codegen_1._) `typeof ${data} != "object"`;
164
+ cond = types.null ? notObj : (0, codegen_1._) `!${data} || ${notObj}`;
165
+ delete types.null;
166
+ delete types.array;
167
+ delete types.object;
168
+ }
169
+ else {
170
+ cond = codegen_1.nil;
171
+ }
172
+ if (types.number)
173
+ delete types.integer;
174
+ for (const t in types)
175
+ cond = (0, codegen_1.and)(cond, checkDataType(t, data, strictNums, correct));
176
+ return cond;
177
+ }
178
+ exports.checkDataTypes = checkDataTypes;
179
+ const typeError = {
180
+ message: ({ schema }) => `must be ${schema}`,
181
+ params: ({ schema, schemaValue }) => typeof schema == "string" ? (0, codegen_1._) `{type: ${schema}}` : (0, codegen_1._) `{type: ${schemaValue}}`,
182
+ };
183
+ function reportTypeError(it) {
184
+ const cxt = getTypeErrorContext(it);
185
+ (0, errors_1.reportError)(cxt, typeError);
186
+ }
187
+ exports.reportTypeError = reportTypeError;
188
+ function getTypeErrorContext(it) {
189
+ const { gen, data, schema } = it;
190
+ const schemaCode = (0, util_1.schemaRefOrVal)(it, schema, "type");
191
+ return {
192
+ gen,
193
+ keyword: "type",
194
+ data,
195
+ schema: schema.type,
196
+ schemaCode,
197
+ schemaValue: schemaCode,
198
+ parentSchema: schema,
199
+ params: {},
200
+ it,
201
+ };
202
+ }
203
+ //# sourceMappingURL=dataType.js.map
@@ -0,0 +1,35 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.assignDefaults = void 0;
4
+ const codegen_1 = require('../codegen/index.js');
5
+ const util_1 = require('../util.js');
6
+ function assignDefaults(it, ty) {
7
+ const { properties, items } = it.schema;
8
+ if (ty === "object" && properties) {
9
+ for (const key in properties) {
10
+ assignDefault(it, key, properties[key].default);
11
+ }
12
+ }
13
+ else if (ty === "array" && Array.isArray(items)) {
14
+ items.forEach((sch, i) => assignDefault(it, i, sch.default));
15
+ }
16
+ }
17
+ exports.assignDefaults = assignDefaults;
18
+ function assignDefault(it, prop, defaultValue) {
19
+ const { gen, compositeRule, data, opts } = it;
20
+ if (defaultValue === undefined)
21
+ return;
22
+ const childData = (0, codegen_1._) `${data}${(0, codegen_1.getProperty)(prop)}`;
23
+ if (compositeRule) {
24
+ (0, util_1.checkStrictMode)(it, `default is ignored for: ${childData}`);
25
+ return;
26
+ }
27
+ let condition = (0, codegen_1._) `${childData} === undefined`;
28
+ if (opts.useDefaults === "empty") {
29
+ condition = (0, codegen_1._) `${condition} || ${childData} === null || ${childData} === ""`;
30
+ }
31
+ // `${childData} === undefined` +
32
+ // (opts.useDefaults === "empty" ? ` || ${childData} === null || ${childData} === ""` : "")
33
+ gen.if(condition, (0, codegen_1._) `${childData} = ${(0, codegen_1.stringify)(defaultValue)}`);
34
+ }
35
+ //# sourceMappingURL=defaults.js.map