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

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 (209) hide show
  1. package/dist/adapter/common/FieldGroupWrap.d.ts +209 -0
  2. package/dist/adapter/field/ArrayField.d.ts +147 -0
  3. package/dist/adapter/field/BooleanField.d.ts +145 -0
  4. package/dist/adapter/field/CompositionField.d.ts +151 -0
  5. package/dist/adapter/field/FieldProps.d.ts +70 -0
  6. package/dist/adapter/field/NumberField.d.ts +145 -0
  7. package/dist/adapter/field/ObjectField.d.ts +147 -0
  8. package/dist/adapter/field/SchemaField.d.ts +145 -0
  9. package/dist/adapter/field/StringField.d.ts +4 -0
  10. package/dist/adapter/widget/ArrayWidget.d.ts +154 -0
  11. package/dist/adapter/widget/ButtonWidget.d.ts +16 -0
  12. package/dist/adapter/widget/CheckboxWidget.d.ts +34 -0
  13. package/dist/adapter/widget/CollapseGroupWidget.d.ts +196 -0
  14. package/dist/adapter/widget/ColorPickerWidget.d.ts +8 -0
  15. package/dist/adapter/widget/InputWidget.d.ts +30 -0
  16. package/dist/adapter/widget/KeyValueArrayWidget.d.ts +157 -0
  17. package/dist/adapter/widget/RadioWidget.d.ts +37 -0
  18. package/dist/adapter/widget/SelectWidget.d.ts +37 -0
  19. package/dist/adapter/widget/SwitchWidget.d.ts +10 -0
  20. package/dist/adapter/widget/TabGroupWidget.d.ts +187 -0
  21. package/dist/adapter/widget/TableWidget.d.ts +154 -0
  22. package/dist/adapter/widget/Widget.d.ts +182 -0
  23. package/dist/controller/form.d.ts +141 -0
  24. package/dist/controller/props.d.ts +62 -0
  25. package/dist/core/events.d.ts +10 -0
  26. package/dist/core/expression.d.ts +13 -0
  27. package/dist/core/form.d.ts +5 -0
  28. package/dist/core/lang.d.ts +1 -0
  29. package/dist/core/layout.d.ts +20 -0
  30. package/dist/core/lifecycle.d.ts +0 -0
  31. package/dist/core/path.d.ts +9 -0
  32. package/dist/core/proxy.d.ts +3 -0
  33. package/dist/core/reaction.d.ts +5 -0
  34. package/dist/core/register.d.ts +19 -0
  35. package/dist/core/schema.d.ts +26 -0
  36. package/dist/core/validator.d.ts +35 -0
  37. package/dist/core/widgetTree.d.ts +40 -0
  38. package/dist/index.d.ts +6 -0
  39. package/dist/index.es.js +7443 -0
  40. package/dist/index.umd.js +12 -0
  41. package/dist/style.css +1 -0
  42. package/dist/util/fetch.d.ts +10 -0
  43. package/dist/util/index.d.ts +23 -0
  44. package/package.json +24 -12
  45. package/esm/adapter/common/FieldGroupWrap.tsx.js +0 -199
  46. package/esm/adapter/field/ArrayField.tsx.js +0 -55
  47. package/esm/adapter/field/BooleanField.tsx.js +0 -41
  48. package/esm/adapter/field/CompositionField.tsx.js +0 -113
  49. package/esm/adapter/field/FieldProps.ts.js +0 -85
  50. package/esm/adapter/field/NumberField.tsx.js +0 -19
  51. package/esm/adapter/field/ObjectField.tsx.js +0 -58
  52. package/esm/adapter/field/SchemaField.tsx.js +0 -28
  53. package/esm/adapter/field/StringField.tsx.js +0 -4
  54. package/esm/adapter/widget/ArrayWidget.ts.js +0 -196
  55. package/esm/adapter/widget/ButtonWidget.ts.js +0 -76
  56. package/esm/adapter/widget/CheckboxWidget.ts.js +0 -101
  57. package/esm/adapter/widget/CollapseGroupWidget.ts.js +0 -140
  58. package/esm/adapter/widget/ColorPickerWidget.ts.js +0 -71
  59. package/esm/adapter/widget/InputWidget.ts.js +0 -79
  60. package/esm/adapter/widget/KeyValueArrayWidget.tsx.js +0 -156
  61. package/esm/adapter/widget/RadioWidget.ts.js +0 -98
  62. package/esm/adapter/widget/SelectWidget.ts.js +0 -98
  63. package/esm/adapter/widget/SwitchWidget.ts.js +0 -73
  64. package/esm/adapter/widget/TabGroupWidget.ts.js +0 -145
  65. package/esm/adapter/widget/TableWidget.ts.js +0 -205
  66. package/esm/adapter/widget/Widget.ts.js +0 -497
  67. package/esm/assets/fonts/iconcool.eot +0 -0
  68. package/esm/assets/fonts/iconcool.svg +0 -53
  69. package/esm/assets/fonts/iconcool.ttf +0 -0
  70. package/esm/assets/fonts/iconcool.woff +0 -0
  71. package/esm/assets/style.css +0 -43
  72. package/esm/controller/form.css +0 -164
  73. package/esm/controller/form.tsx.js +0 -159
  74. package/esm/controller/props.ts.js +0 -75
  75. package/esm/core/events.ts.js +0 -74
  76. package/esm/core/expression.ts.js +0 -67
  77. package/esm/core/lang.ts.js +0 -25
  78. package/esm/core/layout.ts.js +0 -149
  79. package/esm/core/path.ts.js +0 -60
  80. package/esm/core/proxy.ts.js +0 -10
  81. package/esm/core/reaction.ts.js +0 -116
  82. package/esm/core/register.ts.js +0 -74
  83. package/esm/core/schema.ts.js +0 -302
  84. package/esm/core/validator.ts.js +0 -248
  85. package/esm/core/widgetTree.ts.js +0 -163
  86. package/esm/index.ts.js +0 -6
  87. package/esm/node_modules/@blueking/cli-service/dist/lib/path.js +0 -35
  88. package/esm/node_modules/@blueking/cli-service/dist/lib/util.js +0 -233
  89. package/esm/node_modules/@blueking/cli-service/dist/tools/rust/helper/path.js +0 -172
  90. package/esm/node_modules/ajv/dist/ajv.js +0 -50
  91. package/esm/node_modules/ajv/dist/compile/codegen/code.js +0 -156
  92. package/esm/node_modules/ajv/dist/compile/codegen/index.js +0 -697
  93. package/esm/node_modules/ajv/dist/compile/codegen/scope.js +0 -143
  94. package/esm/node_modules/ajv/dist/compile/errors.js +0 -123
  95. package/esm/node_modules/ajv/dist/compile/index.js +0 -242
  96. package/esm/node_modules/ajv/dist/compile/names.js +0 -28
  97. package/esm/node_modules/ajv/dist/compile/ref_error.js +0 -12
  98. package/esm/node_modules/ajv/dist/compile/resolve.js +0 -155
  99. package/esm/node_modules/ajv/dist/compile/rules.js +0 -26
  100. package/esm/node_modules/ajv/dist/compile/util.js +0 -178
  101. package/esm/node_modules/ajv/dist/compile/validate/applicability.js +0 -19
  102. package/esm/node_modules/ajv/dist/compile/validate/boolSchema.js +0 -50
  103. package/esm/node_modules/ajv/dist/compile/validate/dataType.js +0 -203
  104. package/esm/node_modules/ajv/dist/compile/validate/defaults.js +0 -35
  105. package/esm/node_modules/ajv/dist/compile/validate/index.js +0 -520
  106. package/esm/node_modules/ajv/dist/compile/validate/keyword.js +0 -124
  107. package/esm/node_modules/ajv/dist/compile/validate/subschema.js +0 -81
  108. package/esm/node_modules/ajv/dist/core.js +0 -618
  109. package/esm/node_modules/ajv/dist/refs/data.json +0 -13
  110. package/esm/node_modules/ajv/dist/refs/json-schema-draft-07.json +0 -151
  111. package/esm/node_modules/ajv/dist/runtime/equal.js +0 -7
  112. package/esm/node_modules/ajv/dist/runtime/ucs2length.js +0 -24
  113. package/esm/node_modules/ajv/dist/runtime/uri.js +0 -6
  114. package/esm/node_modules/ajv/dist/runtime/validation_error.js +0 -11
  115. package/esm/node_modules/ajv/dist/vocabularies/applicator/additionalItems.js +0 -49
  116. package/esm/node_modules/ajv/dist/vocabularies/applicator/additionalProperties.js +0 -106
  117. package/esm/node_modules/ajv/dist/vocabularies/applicator/allOf.js +0 -23
  118. package/esm/node_modules/ajv/dist/vocabularies/applicator/anyOf.js +0 -12
  119. package/esm/node_modules/ajv/dist/vocabularies/applicator/contains.js +0 -95
  120. package/esm/node_modules/ajv/dist/vocabularies/applicator/dependencies.js +0 -85
  121. package/esm/node_modules/ajv/dist/vocabularies/applicator/if.js +0 -66
  122. package/esm/node_modules/ajv/dist/vocabularies/applicator/index.js +0 -44
  123. package/esm/node_modules/ajv/dist/vocabularies/applicator/items.js +0 -52
  124. package/esm/node_modules/ajv/dist/vocabularies/applicator/items2020.js +0 -30
  125. package/esm/node_modules/ajv/dist/vocabularies/applicator/not.js +0 -26
  126. package/esm/node_modules/ajv/dist/vocabularies/applicator/oneOf.js +0 -60
  127. package/esm/node_modules/ajv/dist/vocabularies/applicator/patternProperties.js +0 -75
  128. package/esm/node_modules/ajv/dist/vocabularies/applicator/prefixItems.js +0 -12
  129. package/esm/node_modules/ajv/dist/vocabularies/applicator/properties.js +0 -54
  130. package/esm/node_modules/ajv/dist/vocabularies/applicator/propertyNames.js +0 -38
  131. package/esm/node_modules/ajv/dist/vocabularies/applicator/thenElse.js +0 -13
  132. package/esm/node_modules/ajv/dist/vocabularies/code.js +0 -131
  133. package/esm/node_modules/ajv/dist/vocabularies/core/id.js +0 -10
  134. package/esm/node_modules/ajv/dist/vocabularies/core/index.js +0 -16
  135. package/esm/node_modules/ajv/dist/vocabularies/core/ref.js +0 -122
  136. package/esm/node_modules/ajv/dist/vocabularies/discriminator/index.js +0 -104
  137. package/esm/node_modules/ajv/dist/vocabularies/discriminator/types.js +0 -9
  138. package/esm/node_modules/ajv/dist/vocabularies/draft7.js +0 -17
  139. package/esm/node_modules/ajv/dist/vocabularies/format/format.js +0 -92
  140. package/esm/node_modules/ajv/dist/vocabularies/format/index.js +0 -6
  141. package/esm/node_modules/ajv/dist/vocabularies/metadata.js +0 -18
  142. package/esm/node_modules/ajv/dist/vocabularies/validation/const.js +0 -25
  143. package/esm/node_modules/ajv/dist/vocabularies/validation/enum.js +0 -48
  144. package/esm/node_modules/ajv/dist/vocabularies/validation/index.js +0 -33
  145. package/esm/node_modules/ajv/dist/vocabularies/validation/limitItems.js +0 -24
  146. package/esm/node_modules/ajv/dist/vocabularies/validation/limitLength.js +0 -27
  147. package/esm/node_modules/ajv/dist/vocabularies/validation/limitNumber.js +0 -27
  148. package/esm/node_modules/ajv/dist/vocabularies/validation/limitProperties.js +0 -24
  149. package/esm/node_modules/ajv/dist/vocabularies/validation/multipleOf.js +0 -26
  150. package/esm/node_modules/ajv/dist/vocabularies/validation/pattern.js +0 -24
  151. package/esm/node_modules/ajv/dist/vocabularies/validation/required.js +0 -79
  152. package/esm/node_modules/ajv/dist/vocabularies/validation/uniqueItems.js +0 -64
  153. package/esm/node_modules/ajv-formats/dist/formats.js +0 -173
  154. package/esm/node_modules/ajv-formats/dist/index.js +0 -37
  155. package/esm/node_modules/ajv-formats/dist/limit.js +0 -69
  156. package/esm/node_modules/ajv-i18n/localize/zh/index.js +0 -154
  157. package/esm/node_modules/fast-deep-equal/index.js +0 -46
  158. package/esm/node_modules/fast-uri/index.js +0 -303
  159. package/esm/node_modules/fast-uri/lib/schemes.js +0 -188
  160. package/esm/node_modules/fast-uri/lib/scopedChars.js +0 -30
  161. package/esm/node_modules/fast-uri/lib/utils.js +0 -244
  162. package/esm/node_modules/json-schema-traverse/index.js +0 -89
  163. package/esm/node_modules/semver/classes/comparator.js +0 -143
  164. package/esm/node_modules/semver/classes/range.js +0 -557
  165. package/esm/node_modules/semver/classes/semver.js +0 -333
  166. package/esm/node_modules/semver/functions/clean.js +0 -8
  167. package/esm/node_modules/semver/functions/cmp.js +0 -54
  168. package/esm/node_modules/semver/functions/coerce.js +0 -62
  169. package/esm/node_modules/semver/functions/compare-build.js +0 -9
  170. package/esm/node_modules/semver/functions/compare-loose.js +0 -5
  171. package/esm/node_modules/semver/functions/compare.js +0 -7
  172. package/esm/node_modules/semver/functions/diff.js +0 -60
  173. package/esm/node_modules/semver/functions/eq.js +0 -5
  174. package/esm/node_modules/semver/functions/gt.js +0 -5
  175. package/esm/node_modules/semver/functions/gte.js +0 -5
  176. package/esm/node_modules/semver/functions/inc.js +0 -21
  177. package/esm/node_modules/semver/functions/lt.js +0 -5
  178. package/esm/node_modules/semver/functions/lte.js +0 -5
  179. package/esm/node_modules/semver/functions/major.js +0 -5
  180. package/esm/node_modules/semver/functions/minor.js +0 -5
  181. package/esm/node_modules/semver/functions/neq.js +0 -5
  182. package/esm/node_modules/semver/functions/parse.js +0 -18
  183. package/esm/node_modules/semver/functions/patch.js +0 -5
  184. package/esm/node_modules/semver/functions/prerelease.js +0 -8
  185. package/esm/node_modules/semver/functions/rcompare.js +0 -5
  186. package/esm/node_modules/semver/functions/rsort.js +0 -5
  187. package/esm/node_modules/semver/functions/satisfies.js +0 -12
  188. package/esm/node_modules/semver/functions/sort.js +0 -5
  189. package/esm/node_modules/semver/functions/valid.js +0 -8
  190. package/esm/node_modules/semver/index.js +0 -91
  191. package/esm/node_modules/semver/internal/constants.js +0 -37
  192. package/esm/node_modules/semver/internal/debug.js +0 -11
  193. package/esm/node_modules/semver/internal/identifiers.js +0 -29
  194. package/esm/node_modules/semver/internal/lrucache.js +0 -42
  195. package/esm/node_modules/semver/internal/parse-options.js +0 -17
  196. package/esm/node_modules/semver/internal/re.js +0 -223
  197. package/esm/node_modules/semver/ranges/gtr.js +0 -6
  198. package/esm/node_modules/semver/ranges/intersects.js +0 -9
  199. package/esm/node_modules/semver/ranges/ltr.js +0 -6
  200. package/esm/node_modules/semver/ranges/max-satisfying.js +0 -27
  201. package/esm/node_modules/semver/ranges/min-satisfying.js +0 -26
  202. package/esm/node_modules/semver/ranges/min-version.js +0 -63
  203. package/esm/node_modules/semver/ranges/outside.js +0 -82
  204. package/esm/node_modules/semver/ranges/simplify.js +0 -49
  205. package/esm/node_modules/semver/ranges/subset.js +0 -249
  206. package/esm/node_modules/semver/ranges/to-comparators.js +0 -10
  207. package/esm/node_modules/semver/ranges/valid.js +0 -13
  208. package/esm/util/fetch.ts.js +0 -190
  209. package/esm/util/index.ts.js +0 -276
@@ -1,122 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.callRef = exports.getValidate = void 0;
4
- const ref_error_1 = require('../../compile/ref_error.js');
5
- const code_1 = require('../code.js');
6
- const codegen_1 = require('../../compile/codegen/index.js');
7
- const names_1 = require('../../compile/names.js');
8
- const compile_1 = require('../../compile/index.js');
9
- const util_1 = require('../../compile/util.js');
10
- const def = {
11
- keyword: "$ref",
12
- schemaType: "string",
13
- code(cxt) {
14
- const { gen, schema: $ref, it } = cxt;
15
- const { baseId, schemaEnv: env, validateName, opts, self } = it;
16
- const { root } = env;
17
- if (($ref === "#" || $ref === "#/") && baseId === root.baseId)
18
- return callRootRef();
19
- const schOrEnv = compile_1.resolveRef.call(self, root, baseId, $ref);
20
- if (schOrEnv === undefined)
21
- throw new ref_error_1.default(it.opts.uriResolver, baseId, $ref);
22
- if (schOrEnv instanceof compile_1.SchemaEnv)
23
- return callValidate(schOrEnv);
24
- return inlineRefSchema(schOrEnv);
25
- function callRootRef() {
26
- if (env === root)
27
- return callRef(cxt, validateName, env, env.$async);
28
- const rootName = gen.scopeValue("root", { ref: root });
29
- return callRef(cxt, (0, codegen_1._) `${rootName}.validate`, root, root.$async);
30
- }
31
- function callValidate(sch) {
32
- const v = getValidate(cxt, sch);
33
- callRef(cxt, v, sch, sch.$async);
34
- }
35
- function inlineRefSchema(sch) {
36
- const schName = gen.scopeValue("schema", opts.code.source === true ? { ref: sch, code: (0, codegen_1.stringify)(sch) } : { ref: sch });
37
- const valid = gen.name("valid");
38
- const schCxt = cxt.subschema({
39
- schema: sch,
40
- dataTypes: [],
41
- schemaPath: codegen_1.nil,
42
- topSchemaRef: schName,
43
- errSchemaPath: $ref,
44
- }, valid);
45
- cxt.mergeEvaluated(schCxt);
46
- cxt.ok(valid);
47
- }
48
- },
49
- };
50
- function getValidate(cxt, sch) {
51
- const { gen } = cxt;
52
- return sch.validate
53
- ? gen.scopeValue("validate", { ref: sch.validate })
54
- : (0, codegen_1._) `${gen.scopeValue("wrapper", { ref: sch })}.validate`;
55
- }
56
- exports.getValidate = getValidate;
57
- function callRef(cxt, v, sch, $async) {
58
- const { gen, it } = cxt;
59
- const { allErrors, schemaEnv: env, opts } = it;
60
- const passCxt = opts.passContext ? names_1.default.this : codegen_1.nil;
61
- if ($async)
62
- callAsyncRef();
63
- else
64
- callSyncRef();
65
- function callAsyncRef() {
66
- if (!env.$async)
67
- throw new Error("async schema referenced by sync schema");
68
- const valid = gen.let("valid");
69
- gen.try(() => {
70
- gen.code((0, codegen_1._) `await ${(0, code_1.callValidateCode)(cxt, v, passCxt)}`);
71
- addEvaluatedFrom(v); // TODO will not work with async, it has to be returned with the result
72
- if (!allErrors)
73
- gen.assign(valid, true);
74
- }, (e) => {
75
- gen.if((0, codegen_1._) `!(${e} instanceof ${it.ValidationError})`, () => gen.throw(e));
76
- addErrorsFrom(e);
77
- if (!allErrors)
78
- gen.assign(valid, false);
79
- });
80
- cxt.ok(valid);
81
- }
82
- function callSyncRef() {
83
- cxt.result((0, code_1.callValidateCode)(cxt, v, passCxt), () => addEvaluatedFrom(v), () => addErrorsFrom(v));
84
- }
85
- function addErrorsFrom(source) {
86
- const errs = (0, codegen_1._) `${source}.errors`;
87
- gen.assign(names_1.default.vErrors, (0, codegen_1._) `${names_1.default.vErrors} === null ? ${errs} : ${names_1.default.vErrors}.concat(${errs})`); // TODO tagged
88
- gen.assign(names_1.default.errors, (0, codegen_1._) `${names_1.default.vErrors}.length`);
89
- }
90
- function addEvaluatedFrom(source) {
91
- var _a;
92
- if (!it.opts.unevaluated)
93
- return;
94
- const schEvaluated = (_a = sch === null || sch === void 0 ? void 0 : sch.validate) === null || _a === void 0 ? void 0 : _a.evaluated;
95
- // TODO refactor
96
- if (it.props !== true) {
97
- if (schEvaluated && !schEvaluated.dynamicProps) {
98
- if (schEvaluated.props !== undefined) {
99
- it.props = util_1.mergeEvaluated.props(gen, schEvaluated.props, it.props);
100
- }
101
- }
102
- else {
103
- const props = gen.var("props", (0, codegen_1._) `${source}.evaluated.props`);
104
- it.props = util_1.mergeEvaluated.props(gen, props, it.props, codegen_1.Name);
105
- }
106
- }
107
- if (it.items !== true) {
108
- if (schEvaluated && !schEvaluated.dynamicItems) {
109
- if (schEvaluated.items !== undefined) {
110
- it.items = util_1.mergeEvaluated.items(gen, schEvaluated.items, it.items);
111
- }
112
- }
113
- else {
114
- const items = gen.var("items", (0, codegen_1._) `${source}.evaluated.items`);
115
- it.items = util_1.mergeEvaluated.items(gen, items, it.items, codegen_1.Name);
116
- }
117
- }
118
- }
119
- }
120
- exports.callRef = callRef;
121
- exports.default = def;
122
- //# sourceMappingURL=ref.js.map
@@ -1,104 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- const codegen_1 = require('../../compile/codegen/index.js');
4
- const types_1 = require('./types.js');
5
- const compile_1 = require('../../compile/index.js');
6
- const ref_error_1 = require('../../compile/ref_error.js');
7
- const util_1 = require('../../compile/util.js');
8
- const error = {
9
- message: ({ params: { discrError, tagName } }) => discrError === types_1.DiscrError.Tag
10
- ? `tag "${tagName}" must be string`
11
- : `value of tag "${tagName}" must be in oneOf`,
12
- params: ({ params: { discrError, tag, tagName } }) => (0, codegen_1._) `{error: ${discrError}, tag: ${tagName}, tagValue: ${tag}}`,
13
- };
14
- const def = {
15
- keyword: "discriminator",
16
- type: "object",
17
- schemaType: "object",
18
- error,
19
- code(cxt) {
20
- const { gen, data, schema, parentSchema, it } = cxt;
21
- const { oneOf } = parentSchema;
22
- if (!it.opts.discriminator) {
23
- throw new Error("discriminator: requires discriminator option");
24
- }
25
- const tagName = schema.propertyName;
26
- if (typeof tagName != "string")
27
- throw new Error("discriminator: requires propertyName");
28
- if (schema.mapping)
29
- throw new Error("discriminator: mapping is not supported");
30
- if (!oneOf)
31
- throw new Error("discriminator: requires oneOf keyword");
32
- const valid = gen.let("valid", false);
33
- const tag = gen.const("tag", (0, codegen_1._) `${data}${(0, codegen_1.getProperty)(tagName)}`);
34
- gen.if((0, codegen_1._) `typeof ${tag} == "string"`, () => validateMapping(), () => cxt.error(false, { discrError: types_1.DiscrError.Tag, tag, tagName }));
35
- cxt.ok(valid);
36
- function validateMapping() {
37
- const mapping = getMapping();
38
- gen.if(false);
39
- for (const tagValue in mapping) {
40
- gen.elseIf((0, codegen_1._) `${tag} === ${tagValue}`);
41
- gen.assign(valid, applyTagSchema(mapping[tagValue]));
42
- }
43
- gen.else();
44
- cxt.error(false, { discrError: types_1.DiscrError.Mapping, tag, tagName });
45
- gen.endIf();
46
- }
47
- function applyTagSchema(schemaProp) {
48
- const _valid = gen.name("valid");
49
- const schCxt = cxt.subschema({ keyword: "oneOf", schemaProp }, _valid);
50
- cxt.mergeEvaluated(schCxt, codegen_1.Name);
51
- return _valid;
52
- }
53
- function getMapping() {
54
- var _a;
55
- const oneOfMapping = {};
56
- const topRequired = hasRequired(parentSchema);
57
- let tagRequired = true;
58
- for (let i = 0; i < oneOf.length; i++) {
59
- let sch = oneOf[i];
60
- if ((sch === null || sch === void 0 ? void 0 : sch.$ref) && !(0, util_1.schemaHasRulesButRef)(sch, it.self.RULES)) {
61
- const ref = sch.$ref;
62
- sch = compile_1.resolveRef.call(it.self, it.schemaEnv.root, it.baseId, ref);
63
- if (sch instanceof compile_1.SchemaEnv)
64
- sch = sch.schema;
65
- if (sch === undefined)
66
- throw new ref_error_1.default(it.opts.uriResolver, it.baseId, ref);
67
- }
68
- const propSch = (_a = sch === null || sch === void 0 ? void 0 : sch.properties) === null || _a === void 0 ? void 0 : _a[tagName];
69
- if (typeof propSch != "object") {
70
- throw new Error(`discriminator: oneOf subschemas (or referenced schemas) must have "properties/${tagName}"`);
71
- }
72
- tagRequired = tagRequired && (topRequired || hasRequired(sch));
73
- addMappings(propSch, i);
74
- }
75
- if (!tagRequired)
76
- throw new Error(`discriminator: "${tagName}" must be required`);
77
- return oneOfMapping;
78
- function hasRequired({ required }) {
79
- return Array.isArray(required) && required.includes(tagName);
80
- }
81
- function addMappings(sch, i) {
82
- if (sch.const) {
83
- addMapping(sch.const, i);
84
- }
85
- else if (sch.enum) {
86
- for (const tagValue of sch.enum) {
87
- addMapping(tagValue, i);
88
- }
89
- }
90
- else {
91
- throw new Error(`discriminator: "properties/${tagName}" must have "const" or "enum"`);
92
- }
93
- }
94
- function addMapping(tagValue, i) {
95
- if (typeof tagValue != "string" || tagValue in oneOfMapping) {
96
- throw new Error(`discriminator: "${tagName}" values must be unique strings`);
97
- }
98
- oneOfMapping[tagValue] = i;
99
- }
100
- }
101
- },
102
- };
103
- exports.default = def;
104
- //# sourceMappingURL=index.js.map
@@ -1,9 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.DiscrError = void 0;
4
- var DiscrError;
5
- (function (DiscrError) {
6
- DiscrError["Tag"] = "tag";
7
- DiscrError["Mapping"] = "mapping";
8
- })(DiscrError || (exports.DiscrError = DiscrError = {}));
9
- //# sourceMappingURL=types.js.map
@@ -1,17 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- const core_1 = require('./core/index.js');
4
- const validation_1 = require('./validation/index.js');
5
- const applicator_1 = require('./applicator/index.js');
6
- const format_1 = require('./format/index.js');
7
- const metadata_1 = require('./metadata.js');
8
- const draft7Vocabularies = [
9
- core_1.default,
10
- validation_1.default,
11
- (0, applicator_1.default)(),
12
- format_1.default,
13
- metadata_1.metadataVocabulary,
14
- metadata_1.contentVocabulary,
15
- ];
16
- exports.default = draft7Vocabularies;
17
- //# sourceMappingURL=draft7.js.map
@@ -1,92 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- const codegen_1 = require('../../compile/codegen/index.js');
4
- const error = {
5
- message: ({ schemaCode }) => (0, codegen_1.str) `must match format "${schemaCode}"`,
6
- params: ({ schemaCode }) => (0, codegen_1._) `{format: ${schemaCode}}`,
7
- };
8
- const def = {
9
- keyword: "format",
10
- type: ["number", "string"],
11
- schemaType: "string",
12
- $data: true,
13
- error,
14
- code(cxt, ruleType) {
15
- const { gen, data, $data, schema, schemaCode, it } = cxt;
16
- const { opts, errSchemaPath, schemaEnv, self } = it;
17
- if (!opts.validateFormats)
18
- return;
19
- if ($data)
20
- validate$DataFormat();
21
- else
22
- validateFormat();
23
- function validate$DataFormat() {
24
- const fmts = gen.scopeValue("formats", {
25
- ref: self.formats,
26
- code: opts.code.formats,
27
- });
28
- const fDef = gen.const("fDef", (0, codegen_1._) `${fmts}[${schemaCode}]`);
29
- const fType = gen.let("fType");
30
- const format = gen.let("format");
31
- // TODO simplify
32
- gen.if((0, codegen_1._) `typeof ${fDef} == "object" && !(${fDef} instanceof RegExp)`, () => gen.assign(fType, (0, codegen_1._) `${fDef}.type || "string"`).assign(format, (0, codegen_1._) `${fDef}.validate`), () => gen.assign(fType, (0, codegen_1._) `"string"`).assign(format, fDef));
33
- cxt.fail$data((0, codegen_1.or)(unknownFmt(), invalidFmt()));
34
- function unknownFmt() {
35
- if (opts.strictSchema === false)
36
- return codegen_1.nil;
37
- return (0, codegen_1._) `${schemaCode} && !${format}`;
38
- }
39
- function invalidFmt() {
40
- const callFormat = schemaEnv.$async
41
- ? (0, codegen_1._) `(${fDef}.async ? await ${format}(${data}) : ${format}(${data}))`
42
- : (0, codegen_1._) `${format}(${data})`;
43
- const validData = (0, codegen_1._) `(typeof ${format} == "function" ? ${callFormat} : ${format}.test(${data}))`;
44
- return (0, codegen_1._) `${format} && ${format} !== true && ${fType} === ${ruleType} && !${validData}`;
45
- }
46
- }
47
- function validateFormat() {
48
- const formatDef = self.formats[schema];
49
- if (!formatDef) {
50
- unknownFormat();
51
- return;
52
- }
53
- if (formatDef === true)
54
- return;
55
- const [fmtType, format, fmtRef] = getFormat(formatDef);
56
- if (fmtType === ruleType)
57
- cxt.pass(validCondition());
58
- function unknownFormat() {
59
- if (opts.strictSchema === false) {
60
- self.logger.warn(unknownMsg());
61
- return;
62
- }
63
- throw new Error(unknownMsg());
64
- function unknownMsg() {
65
- return `unknown format "${schema}" ignored in schema at path "${errSchemaPath}"`;
66
- }
67
- }
68
- function getFormat(fmtDef) {
69
- const code = fmtDef instanceof RegExp
70
- ? (0, codegen_1.regexpCode)(fmtDef)
71
- : opts.code.formats
72
- ? (0, codegen_1._) `${opts.code.formats}${(0, codegen_1.getProperty)(schema)}`
73
- : undefined;
74
- const fmt = gen.scopeValue("formats", { key: schema, ref: fmtDef, code });
75
- if (typeof fmtDef == "object" && !(fmtDef instanceof RegExp)) {
76
- return [fmtDef.type || "string", fmtDef.validate, (0, codegen_1._) `${fmt}.validate`];
77
- }
78
- return ["string", fmtDef, fmt];
79
- }
80
- function validCondition() {
81
- if (typeof formatDef == "object" && !(formatDef instanceof RegExp) && formatDef.async) {
82
- if (!schemaEnv.$async)
83
- throw new Error("async format in sync schema");
84
- return (0, codegen_1._) `await ${fmtRef}(${data})`;
85
- }
86
- return typeof format == "function" ? (0, codegen_1._) `${fmtRef}(${data})` : (0, codegen_1._) `${fmtRef}.test(${data})`;
87
- }
88
- }
89
- },
90
- };
91
- exports.default = def;
92
- //# sourceMappingURL=format.js.map
@@ -1,6 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- const format_1 = require('./format.js');
4
- const format = [format_1.default];
5
- exports.default = format;
6
- //# sourceMappingURL=index.js.map
@@ -1,18 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.contentVocabulary = exports.metadataVocabulary = void 0;
4
- exports.metadataVocabulary = [
5
- "title",
6
- "description",
7
- "default",
8
- "deprecated",
9
- "readOnly",
10
- "writeOnly",
11
- "examples",
12
- ];
13
- exports.contentVocabulary = [
14
- "contentMediaType",
15
- "contentEncoding",
16
- "contentSchema",
17
- ];
18
- //# sourceMappingURL=metadata.js.map
@@ -1,25 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- const codegen_1 = require('../../compile/codegen/index.js');
4
- const util_1 = require('../../compile/util.js');
5
- const equal_1 = require('../../runtime/equal.js');
6
- const error = {
7
- message: "must be equal to constant",
8
- params: ({ schemaCode }) => (0, codegen_1._) `{allowedValue: ${schemaCode}}`,
9
- };
10
- const def = {
11
- keyword: "const",
12
- $data: true,
13
- error,
14
- code(cxt) {
15
- const { gen, data, $data, schemaCode, schema } = cxt;
16
- if ($data || (schema && typeof schema == "object")) {
17
- cxt.fail$data((0, codegen_1._) `!${(0, util_1.useFunc)(gen, equal_1.default)}(${data}, ${schemaCode})`);
18
- }
19
- else {
20
- cxt.fail((0, codegen_1._) `${schema} !== ${data}`);
21
- }
22
- },
23
- };
24
- exports.default = def;
25
- //# sourceMappingURL=const.js.map
@@ -1,48 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- const codegen_1 = require('../../compile/codegen/index.js');
4
- const util_1 = require('../../compile/util.js');
5
- const equal_1 = require('../../runtime/equal.js');
6
- const error = {
7
- message: "must be equal to one of the allowed values",
8
- params: ({ schemaCode }) => (0, codegen_1._) `{allowedValues: ${schemaCode}}`,
9
- };
10
- const def = {
11
- keyword: "enum",
12
- schemaType: "array",
13
- $data: true,
14
- error,
15
- code(cxt) {
16
- const { gen, data, $data, schema, schemaCode, it } = cxt;
17
- if (!$data && schema.length === 0)
18
- throw new Error("enum must have non-empty array");
19
- const useLoop = schema.length >= it.opts.loopEnum;
20
- let eql;
21
- const getEql = () => (eql !== null && eql !== void 0 ? eql : (eql = (0, util_1.useFunc)(gen, equal_1.default)));
22
- let valid;
23
- if (useLoop || $data) {
24
- valid = gen.let("valid");
25
- cxt.block$data(valid, loopEnum);
26
- }
27
- else {
28
- /* istanbul ignore if */
29
- if (!Array.isArray(schema))
30
- throw new Error("ajv implementation error");
31
- const vSchema = gen.const("vSchema", schemaCode);
32
- valid = (0, codegen_1.or)(...schema.map((_x, i) => equalCode(vSchema, i)));
33
- }
34
- cxt.pass(valid);
35
- function loopEnum() {
36
- gen.assign(valid, false);
37
- gen.forOf("v", schemaCode, (v) => gen.if((0, codegen_1._) `${getEql()}(${data}, ${v})`, () => gen.assign(valid, true).break()));
38
- }
39
- function equalCode(vSchema, i) {
40
- const sch = schema[i];
41
- return typeof sch === "object" && sch !== null
42
- ? (0, codegen_1._) `${getEql()}(${data}, ${vSchema}[${i}])`
43
- : (0, codegen_1._) `${data} === ${sch}`;
44
- }
45
- },
46
- };
47
- exports.default = def;
48
- //# sourceMappingURL=enum.js.map
@@ -1,33 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- const limitNumber_1 = require('./limitNumber.js');
4
- const multipleOf_1 = require('./multipleOf.js');
5
- const limitLength_1 = require('./limitLength.js');
6
- const pattern_1 = require('./pattern.js');
7
- const limitProperties_1 = require('./limitProperties.js');
8
- const required_1 = require('./required.js');
9
- const limitItems_1 = require('./limitItems.js');
10
- const uniqueItems_1 = require('./uniqueItems.js');
11
- const const_1 = require('./const.js');
12
- const enum_1 = require('./enum.js');
13
- const validation = [
14
- // number
15
- limitNumber_1.default,
16
- multipleOf_1.default,
17
- // string
18
- limitLength_1.default,
19
- pattern_1.default,
20
- // object
21
- limitProperties_1.default,
22
- required_1.default,
23
- // array
24
- limitItems_1.default,
25
- uniqueItems_1.default,
26
- // any
27
- { keyword: "type", schemaType: ["string", "array"] },
28
- { keyword: "nullable", schemaType: "boolean" },
29
- const_1.default,
30
- enum_1.default,
31
- ];
32
- exports.default = validation;
33
- //# sourceMappingURL=index.js.map
@@ -1,24 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- const codegen_1 = require('../../compile/codegen/index.js');
4
- const error = {
5
- message({ keyword, schemaCode }) {
6
- const comp = keyword === "maxItems" ? "more" : "fewer";
7
- return (0, codegen_1.str) `must NOT have ${comp} than ${schemaCode} items`;
8
- },
9
- params: ({ schemaCode }) => (0, codegen_1._) `{limit: ${schemaCode}}`,
10
- };
11
- const def = {
12
- keyword: ["maxItems", "minItems"],
13
- type: "array",
14
- schemaType: "number",
15
- $data: true,
16
- error,
17
- code(cxt) {
18
- const { keyword, data, schemaCode } = cxt;
19
- const op = keyword === "maxItems" ? codegen_1.operators.GT : codegen_1.operators.LT;
20
- cxt.fail$data((0, codegen_1._) `${data}.length ${op} ${schemaCode}`);
21
- },
22
- };
23
- exports.default = def;
24
- //# sourceMappingURL=limitItems.js.map
@@ -1,27 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- const codegen_1 = require('../../compile/codegen/index.js');
4
- const util_1 = require('../../compile/util.js');
5
- const ucs2length_1 = require('../../runtime/ucs2length.js');
6
- const error = {
7
- message({ keyword, schemaCode }) {
8
- const comp = keyword === "maxLength" ? "more" : "fewer";
9
- return (0, codegen_1.str) `must NOT have ${comp} than ${schemaCode} characters`;
10
- },
11
- params: ({ schemaCode }) => (0, codegen_1._) `{limit: ${schemaCode}}`,
12
- };
13
- const def = {
14
- keyword: ["maxLength", "minLength"],
15
- type: "string",
16
- schemaType: "number",
17
- $data: true,
18
- error,
19
- code(cxt) {
20
- const { keyword, data, schemaCode, it } = cxt;
21
- const op = keyword === "maxLength" ? codegen_1.operators.GT : codegen_1.operators.LT;
22
- const len = it.opts.unicode === false ? (0, codegen_1._) `${data}.length` : (0, codegen_1._) `${(0, util_1.useFunc)(cxt.gen, ucs2length_1.default)}(${data})`;
23
- cxt.fail$data((0, codegen_1._) `${len} ${op} ${schemaCode}`);
24
- },
25
- };
26
- exports.default = def;
27
- //# sourceMappingURL=limitLength.js.map
@@ -1,27 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- const codegen_1 = require('../../compile/codegen/index.js');
4
- const ops = codegen_1.operators;
5
- const KWDs = {
6
- maximum: { okStr: "<=", ok: ops.LTE, fail: ops.GT },
7
- minimum: { okStr: ">=", ok: ops.GTE, fail: ops.LT },
8
- exclusiveMaximum: { okStr: "<", ok: ops.LT, fail: ops.GTE },
9
- exclusiveMinimum: { okStr: ">", ok: ops.GT, fail: ops.LTE },
10
- };
11
- const error = {
12
- message: ({ keyword, schemaCode }) => (0, codegen_1.str) `must be ${KWDs[keyword].okStr} ${schemaCode}`,
13
- params: ({ keyword, schemaCode }) => (0, codegen_1._) `{comparison: ${KWDs[keyword].okStr}, limit: ${schemaCode}}`,
14
- };
15
- const def = {
16
- keyword: Object.keys(KWDs),
17
- type: "number",
18
- schemaType: "number",
19
- $data: true,
20
- error,
21
- code(cxt) {
22
- const { keyword, data, schemaCode } = cxt;
23
- cxt.fail$data((0, codegen_1._) `${data} ${KWDs[keyword].fail} ${schemaCode} || isNaN(${data})`);
24
- },
25
- };
26
- exports.default = def;
27
- //# sourceMappingURL=limitNumber.js.map
@@ -1,24 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- const codegen_1 = require('../../compile/codegen/index.js');
4
- const error = {
5
- message({ keyword, schemaCode }) {
6
- const comp = keyword === "maxProperties" ? "more" : "fewer";
7
- return (0, codegen_1.str) `must NOT have ${comp} than ${schemaCode} properties`;
8
- },
9
- params: ({ schemaCode }) => (0, codegen_1._) `{limit: ${schemaCode}}`,
10
- };
11
- const def = {
12
- keyword: ["maxProperties", "minProperties"],
13
- type: "object",
14
- schemaType: "number",
15
- $data: true,
16
- error,
17
- code(cxt) {
18
- const { keyword, data, schemaCode } = cxt;
19
- const op = keyword === "maxProperties" ? codegen_1.operators.GT : codegen_1.operators.LT;
20
- cxt.fail$data((0, codegen_1._) `Object.keys(${data}).length ${op} ${schemaCode}`);
21
- },
22
- };
23
- exports.default = def;
24
- //# sourceMappingURL=limitProperties.js.map
@@ -1,26 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- const codegen_1 = require('../../compile/codegen/index.js');
4
- const error = {
5
- message: ({ schemaCode }) => (0, codegen_1.str) `must be multiple of ${schemaCode}`,
6
- params: ({ schemaCode }) => (0, codegen_1._) `{multipleOf: ${schemaCode}}`,
7
- };
8
- const def = {
9
- keyword: "multipleOf",
10
- type: "number",
11
- schemaType: "number",
12
- $data: true,
13
- error,
14
- code(cxt) {
15
- const { gen, data, schemaCode, it } = cxt;
16
- // const bdt = bad$DataType(schemaCode, <string>def.schemaType, $data)
17
- const prec = it.opts.multipleOfPrecision;
18
- const res = gen.let("res");
19
- const invalid = prec
20
- ? (0, codegen_1._) `Math.abs(Math.round(${res}) - ${res}) > 1e-${prec}`
21
- : (0, codegen_1._) `${res} !== parseInt(${res})`;
22
- cxt.fail$data((0, codegen_1._) `(${schemaCode} === 0 || (${res} = ${data}/${schemaCode}, ${invalid}))`);
23
- },
24
- };
25
- exports.default = def;
26
- //# sourceMappingURL=multipleOf.js.map
@@ -1,24 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- const code_1 = require('../code.js');
4
- const codegen_1 = require('../../compile/codegen/index.js');
5
- const error = {
6
- message: ({ schemaCode }) => (0, codegen_1.str) `must match pattern "${schemaCode}"`,
7
- params: ({ schemaCode }) => (0, codegen_1._) `{pattern: ${schemaCode}}`,
8
- };
9
- const def = {
10
- keyword: "pattern",
11
- type: "string",
12
- schemaType: "string",
13
- $data: true,
14
- error,
15
- code(cxt) {
16
- const { data, $data, schema, schemaCode, it } = cxt;
17
- // TODO regexp should be wrapped in try/catchs
18
- const u = it.opts.unicodeRegExp ? "u" : "";
19
- const regExp = $data ? (0, codegen_1._) `(new RegExp(${schemaCode}, ${u}))` : (0, code_1.usePattern)(cxt, schema);
20
- cxt.fail$data((0, codegen_1._) `!${regExp}.test(${data})`);
21
- },
22
- };
23
- exports.default = def;
24
- //# sourceMappingURL=pattern.js.map