@nocobase/plugin-workflow 2.1.0-beta.9 → 2.2.0-beta.1

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 (197) hide show
  1. package/dist/client/214.7e602cfe7a8251b8.js +10 -0
  2. package/dist/client/618.19af7f84261c815d.js +10 -0
  3. package/dist/client/67.452743ce8ec30617.js +10 -0
  4. package/dist/client/964.ffbf5b47ed12bbdc.js +10 -0
  5. package/dist/client/Branch.d.ts +7 -3
  6. package/dist/client/BranchContext.d.ts +18 -0
  7. package/dist/client/components/TimeoutInput.d.ts +11 -0
  8. package/dist/client/constants.d.ts +13 -0
  9. package/dist/client/flows/triggerWorkflows.d.ts +14 -1
  10. package/dist/client/hooks/{useWorkflowFilterActionProps.d.ts → useResourceFilterActionProps.d.ts} +1 -1
  11. package/dist/client/index.js +1 -1
  12. package/dist/client/nodes/create.d.ts +10 -0
  13. package/dist/client/nodes/destroy.d.ts +10 -0
  14. package/dist/client/nodes/index.d.ts +5 -0
  15. package/dist/client/nodes/query.d.ts +18 -2
  16. package/dist/client/nodes/update.d.ts +10 -0
  17. package/dist/client/schemas/collection.d.ts +8 -2
  18. package/dist/client/schemas/executions.d.ts +63 -2
  19. package/dist/client/triggers/collection.d.ts +14 -1
  20. package/dist/client/triggers/index.d.ts +4 -0
  21. package/dist/client/triggers/schedule/constants.d.ts +4 -0
  22. package/dist/client/triggers/schedule/index.d.ts +15 -0
  23. package/dist/client/utils.d.ts +17 -0
  24. package/dist/common/collections/executions.d.ts +44 -1
  25. package/dist/common/collections/executions.js +63 -1
  26. package/dist/common/collections/flow_nodes.d.ts +1 -0
  27. package/dist/common/collections/flow_nodes.js +1 -0
  28. package/dist/common/collections/jobs.d.ts +1 -0
  29. package/dist/common/collections/jobs.js +8 -0
  30. package/dist/common/collections/userWorkflowTasks.d.ts +1 -0
  31. package/dist/common/collections/userWorkflowTasks.js +1 -0
  32. package/dist/common/collections/workflowCategories.d.ts +1 -0
  33. package/dist/common/collections/workflowCategories.js +1 -0
  34. package/dist/common/collections/workflowCategoryRelations.d.ts +1 -0
  35. package/dist/common/collections/workflowCategoryRelations.js +1 -0
  36. package/dist/common/collections/workflowStats.d.ts +1 -0
  37. package/dist/common/collections/workflowStats.js +1 -0
  38. package/dist/common/collections/workflowTasks.js +1 -0
  39. package/dist/common/collections/workflowVersionStats.d.ts +1 -0
  40. package/dist/common/collections/workflowVersionStats.js +1 -0
  41. package/dist/common/collections/workflows.d.ts +66 -11
  42. package/dist/common/collections/workflows.js +35 -2
  43. package/dist/common/constants.d.ts +5 -0
  44. package/dist/common/constants.js +7 -0
  45. package/dist/externalVersion.js +15 -13
  46. package/dist/locale/de-DE.json +4 -0
  47. package/dist/locale/en-US.json +7 -0
  48. package/dist/locale/es-ES.json +4 -0
  49. package/dist/locale/fr-FR.json +4 -0
  50. package/dist/locale/hu-HU.json +7 -3
  51. package/dist/locale/id-ID.json +4 -0
  52. package/dist/locale/it-IT.json +4 -0
  53. package/dist/locale/ja-JP.json +5 -1
  54. package/dist/locale/ko-KR.json +4 -0
  55. package/dist/locale/nl-NL.json +7 -3
  56. package/dist/locale/pt-BR.json +4 -0
  57. package/dist/locale/ru-RU.json +4 -0
  58. package/dist/locale/tr-TR.json +4 -0
  59. package/dist/locale/uk-UA.json +7 -3
  60. package/dist/locale/vi-VN.json +7 -3
  61. package/dist/locale/zh-CN.json +10 -0
  62. package/dist/locale/zh-TW.json +7 -3
  63. package/dist/node_modules/cron-parser/lib/parser.js +1 -1
  64. package/dist/node_modules/cron-parser/package.json +1 -1
  65. package/dist/node_modules/joi/dist/joi-browser.min.js +1 -0
  66. package/dist/node_modules/joi/lib/annotate.js +175 -0
  67. package/dist/node_modules/joi/lib/base.js +1069 -0
  68. package/dist/node_modules/joi/lib/cache.js +143 -0
  69. package/dist/node_modules/joi/lib/common.js +216 -0
  70. package/dist/node_modules/joi/lib/compile.js +283 -0
  71. package/dist/node_modules/joi/lib/errors.js +271 -0
  72. package/dist/node_modules/joi/lib/extend.js +312 -0
  73. package/dist/node_modules/joi/lib/index.d.ts +2365 -0
  74. package/dist/node_modules/joi/lib/index.js +1 -0
  75. package/dist/node_modules/joi/lib/manifest.js +476 -0
  76. package/dist/node_modules/joi/lib/messages.js +178 -0
  77. package/dist/node_modules/joi/lib/modify.js +267 -0
  78. package/dist/node_modules/joi/lib/ref.js +414 -0
  79. package/dist/node_modules/joi/lib/schemas.js +302 -0
  80. package/dist/node_modules/joi/lib/state.js +166 -0
  81. package/dist/node_modules/joi/lib/template.js +463 -0
  82. package/dist/node_modules/joi/lib/trace.js +346 -0
  83. package/dist/node_modules/joi/lib/types/alternatives.js +364 -0
  84. package/dist/node_modules/joi/lib/types/any.js +174 -0
  85. package/dist/node_modules/joi/lib/types/array.js +809 -0
  86. package/dist/node_modules/joi/lib/types/binary.js +100 -0
  87. package/dist/node_modules/joi/lib/types/boolean.js +150 -0
  88. package/dist/node_modules/joi/lib/types/date.js +233 -0
  89. package/dist/node_modules/joi/lib/types/function.js +93 -0
  90. package/dist/node_modules/joi/lib/types/keys.js +1067 -0
  91. package/dist/node_modules/joi/lib/types/link.js +168 -0
  92. package/dist/node_modules/joi/lib/types/number.js +363 -0
  93. package/dist/node_modules/joi/lib/types/object.js +22 -0
  94. package/dist/node_modules/joi/lib/types/string.js +850 -0
  95. package/dist/node_modules/joi/lib/types/symbol.js +102 -0
  96. package/dist/node_modules/joi/lib/validator.js +750 -0
  97. package/dist/node_modules/joi/lib/values.js +263 -0
  98. package/dist/node_modules/joi/node_modules/@hapi/topo/lib/index.d.ts +60 -0
  99. package/dist/node_modules/joi/node_modules/@hapi/topo/lib/index.js +225 -0
  100. package/dist/node_modules/joi/node_modules/@hapi/topo/package.json +30 -0
  101. package/dist/node_modules/joi/package.json +1 -0
  102. package/dist/node_modules/lru-cache/dist/commonjs/diagnostics-channel.d.ts +5 -0
  103. package/dist/node_modules/lru-cache/dist/commonjs/diagnostics-channel.js +10 -0
  104. package/dist/node_modules/lru-cache/dist/commonjs/index.d.ts +1381 -0
  105. package/dist/node_modules/lru-cache/dist/commonjs/index.js +1692 -0
  106. package/dist/node_modules/lru-cache/dist/commonjs/index.min.js +1 -0
  107. package/dist/node_modules/lru-cache/dist/esm/browser/diagnostics-channel.d.ts +5 -0
  108. package/dist/node_modules/lru-cache/dist/esm/browser/diagnostics-channel.js +4 -0
  109. package/dist/node_modules/lru-cache/dist/esm/browser/index.d.ts +1381 -0
  110. package/dist/node_modules/lru-cache/dist/{mjs → esm/browser}/index.js +537 -179
  111. package/dist/node_modules/lru-cache/dist/esm/browser/index.min.js +2 -0
  112. package/dist/node_modules/lru-cache/dist/esm/diagnostics-channel.d.ts +5 -0
  113. package/dist/node_modules/lru-cache/dist/esm/diagnostics-channel.js +19 -0
  114. package/dist/node_modules/lru-cache/dist/esm/index.d.ts +1381 -0
  115. package/dist/node_modules/lru-cache/dist/{cjs → esm}/index.js +538 -184
  116. package/dist/node_modules/lru-cache/dist/esm/index.min.js +2 -0
  117. package/dist/node_modules/lru-cache/dist/esm/node/diagnostics-channel.d.ts +5 -0
  118. package/dist/node_modules/lru-cache/dist/esm/node/diagnostics-channel.js +7 -0
  119. package/dist/node_modules/lru-cache/dist/esm/node/index.d.ts +1381 -0
  120. package/dist/node_modules/lru-cache/dist/esm/node/index.js +1688 -0
  121. package/dist/node_modules/lru-cache/dist/esm/node/index.min.js +2 -0
  122. package/dist/node_modules/lru-cache/package.json +1 -1
  123. package/dist/node_modules/nodejs-snowflake/nodejs_snowflake.js +1 -1
  124. package/dist/node_modules/nodejs-snowflake/package.json +1 -1
  125. package/dist/server/Dispatcher.d.ts +12 -6
  126. package/dist/server/Dispatcher.js +309 -190
  127. package/dist/server/ExecutionTimeoutManager.d.ts +46 -0
  128. package/dist/server/ExecutionTimeoutManager.js +320 -0
  129. package/dist/server/Plugin.d.ts +17 -3
  130. package/dist/server/Plugin.js +54 -12
  131. package/dist/server/Processor.d.ts +64 -12
  132. package/dist/server/Processor.js +286 -48
  133. package/dist/server/RunningExecutionRegistry.d.ts +18 -0
  134. package/dist/server/RunningExecutionRegistry.js +48 -0
  135. package/dist/server/actions/executions.d.ts +4 -3
  136. package/dist/server/actions/executions.js +42 -21
  137. package/dist/server/actions/jobs.d.ts +2 -1
  138. package/dist/server/actions/jobs.js +28 -1
  139. package/dist/server/actions/nodes.d.ts +5 -0
  140. package/dist/server/actions/nodes.js +38 -5
  141. package/dist/server/actions/workflows.d.ts +6 -0
  142. package/dist/server/actions/workflows.js +38 -0
  143. package/dist/server/constants.d.ts +2 -0
  144. package/dist/server/constants.js +3 -0
  145. package/dist/server/index.d.ts +2 -0
  146. package/dist/server/index.js +2 -0
  147. package/dist/server/instructions/ConditionInstruction.d.ts +2 -0
  148. package/dist/server/instructions/ConditionInstruction.js +17 -0
  149. package/dist/server/instructions/CreateInstruction.d.ts +3 -0
  150. package/dist/server/instructions/CreateInstruction.js +25 -0
  151. package/dist/server/instructions/DestroyInstruction.d.ts +3 -0
  152. package/dist/server/instructions/DestroyInstruction.js +25 -0
  153. package/dist/server/instructions/EndInstruction.d.ts +2 -0
  154. package/dist/server/instructions/EndInstruction.js +4 -0
  155. package/dist/server/instructions/MultiConditionsInstruction.d.ts +2 -0
  156. package/dist/server/instructions/MultiConditionsInstruction.js +23 -0
  157. package/dist/server/instructions/OutputInstruction.d.ts +2 -0
  158. package/dist/server/instructions/OutputInstruction.js +15 -1
  159. package/dist/server/instructions/QueryInstruction.d.ts +3 -0
  160. package/dist/server/instructions/QueryInstruction.js +32 -7
  161. package/dist/server/instructions/UpdateInstruction.d.ts +3 -0
  162. package/dist/server/instructions/UpdateInstruction.js +27 -0
  163. package/dist/server/instructions/index.d.ts +24 -4
  164. package/dist/server/instructions/index.js +18 -0
  165. package/dist/server/migrations/20260423225800-fill-workflow-created-updated-by.d.ts +13 -0
  166. package/dist/server/migrations/20260423225800-fill-workflow-created-updated-by.js +57 -0
  167. package/dist/server/migrations/20260501120000-workflow-timeout.d.ts +13 -0
  168. package/dist/server/migrations/20260501120000-workflow-timeout.js +63 -0
  169. package/dist/server/timeout-errors.d.ts +13 -0
  170. package/dist/server/timeout-errors.js +47 -0
  171. package/dist/server/triggers/CollectionTrigger.d.ts +3 -0
  172. package/dist/server/triggers/CollectionTrigger.js +34 -0
  173. package/dist/server/triggers/ScheduleTrigger/index.d.ts +3 -0
  174. package/dist/server/triggers/ScheduleTrigger/index.js +18 -3
  175. package/dist/server/triggers/index.d.ts +3 -0
  176. package/dist/server/triggers/index.js +18 -0
  177. package/dist/server/types/Execution.d.ts +6 -0
  178. package/dist/server/types/Job.d.ts +3 -3
  179. package/dist/server/types/Workflow.d.ts +6 -1
  180. package/dist/server/utils.d.ts +27 -0
  181. package/dist/server/utils.js +142 -2
  182. package/dist/swagger/index.d.ts +66 -75
  183. package/dist/swagger/index.js +58 -67
  184. package/package.json +5 -4
  185. package/dist/client/0e458d99e9fc5e65.js +0 -10
  186. package/dist/client/27bd65abee87cafa.js +0 -10
  187. package/dist/client/478692c1637f2742.js +0 -10
  188. package/dist/client/f39e94207f92e352.js +0 -10
  189. package/dist/node_modules/lru-cache/LICENSE +0 -15
  190. package/dist/node_modules/lru-cache/dist/cjs/index-cjs.d.ts +0 -7
  191. package/dist/node_modules/lru-cache/dist/cjs/index-cjs.js +0 -1
  192. package/dist/node_modules/lru-cache/dist/cjs/index.d.ts +0 -807
  193. package/dist/node_modules/lru-cache/dist/cjs/index.min.js +0 -2
  194. package/dist/node_modules/lru-cache/dist/mjs/index.d.ts +0 -807
  195. package/dist/node_modules/lru-cache/dist/mjs/index.min.js +0 -2
  196. /package/dist/node_modules/lru-cache/dist/{cjs → commonjs}/package.json +0 -0
  197. /package/dist/node_modules/lru-cache/dist/{mjs → esm}/package.json +0 -0
@@ -0,0 +1,271 @@
1
+ 'use strict';
2
+
3
+ const Annotate = require('./annotate');
4
+ const Common = require('./common');
5
+ const Template = require('./template');
6
+
7
+
8
+ const internals = {};
9
+
10
+
11
+ exports.Report = class {
12
+
13
+ constructor(code, value, local, flags, messages, state, prefs) {
14
+
15
+ this.code = code;
16
+ this.flags = flags;
17
+ this.messages = messages;
18
+ this.path = state.path;
19
+ this.prefs = prefs;
20
+ this.state = state;
21
+ this.value = value;
22
+
23
+ this.message = null;
24
+ this.template = null;
25
+
26
+ this.local = local || {};
27
+ this.local.label = exports.label(this.flags, this.state, this.prefs, this.messages);
28
+
29
+ if (this.value !== undefined &&
30
+ !this.local.hasOwnProperty('value')) {
31
+
32
+ this.local.value = this.value;
33
+ }
34
+
35
+ if (this.path.length) {
36
+ const key = this.path[this.path.length - 1];
37
+ if (typeof key !== 'object') {
38
+ this.local.key = key;
39
+ }
40
+ }
41
+ }
42
+
43
+ _setTemplate(template) {
44
+
45
+ this.template = template;
46
+
47
+ if (!this.flags.label &&
48
+ this.path.length === 0) {
49
+
50
+ const localized = this._template(this.template, 'root');
51
+ if (localized) {
52
+ this.local.label = localized;
53
+ }
54
+ }
55
+ }
56
+
57
+ toString() {
58
+
59
+ if (this.message) {
60
+ return this.message;
61
+ }
62
+
63
+ const code = this.code;
64
+
65
+ if (!this.prefs.errors.render) {
66
+ return this.code;
67
+ }
68
+
69
+ const template = this._template(this.template) ||
70
+ this._template(this.prefs.messages) ||
71
+ this._template(this.messages);
72
+
73
+ if (template === undefined) {
74
+ return `Error code "${code}" is not defined, your custom type is missing the correct messages definition`;
75
+ }
76
+
77
+ // Render and cache result
78
+
79
+ this.message = template.render(this.value, this.state, this.prefs, this.local, { errors: this.prefs.errors, messages: [this.prefs.messages, this.messages] });
80
+ if (!this.prefs.errors.label) {
81
+ this.message = this.message.replace(/^"" /, '').trim();
82
+ }
83
+
84
+ return this.message;
85
+ }
86
+
87
+ _template(messages, code) {
88
+
89
+ return exports.template(this.value, messages, code || this.code, this.state, this.prefs);
90
+ }
91
+ };
92
+
93
+
94
+ exports.path = function (path) {
95
+
96
+ let label = '';
97
+ for (const segment of path) {
98
+ if (typeof segment === 'object') { // Exclude array single path segment
99
+ continue;
100
+ }
101
+
102
+ if (typeof segment === 'string') {
103
+ if (label) {
104
+ label += '.';
105
+ }
106
+
107
+ label += segment;
108
+ }
109
+ else {
110
+ label += `[${segment}]`;
111
+ }
112
+ }
113
+
114
+ return label;
115
+ };
116
+
117
+
118
+ exports.template = function (value, messages, code, state, prefs) {
119
+
120
+ if (!messages) {
121
+ return;
122
+ }
123
+
124
+ if (Template.isTemplate(messages)) {
125
+ return code !== 'root' ? messages : null;
126
+ }
127
+
128
+ let lang = prefs.errors.language;
129
+ if (Common.isResolvable(lang)) {
130
+ lang = lang.resolve(value, state, prefs);
131
+ }
132
+
133
+ if (lang &&
134
+ messages[lang]) {
135
+
136
+ if (messages[lang][code] !== undefined) {
137
+ return messages[lang][code];
138
+ }
139
+
140
+ if (messages[lang]['*'] !== undefined) {
141
+ return messages[lang]['*'];
142
+ }
143
+ }
144
+
145
+ if (!messages[code]) {
146
+ return messages['*'];
147
+ }
148
+
149
+ return messages[code];
150
+ };
151
+
152
+
153
+ exports.label = function (flags, state, prefs, messages) {
154
+
155
+ if (!prefs.errors.label) {
156
+ return '';
157
+ }
158
+
159
+ if (flags.label) {
160
+ return flags.label;
161
+ }
162
+
163
+ let path = state.path;
164
+ if (prefs.errors.label === 'key' &&
165
+ state.path.length > 1) {
166
+
167
+ path = state.path.slice(-1);
168
+ }
169
+
170
+ const normalized = exports.path(path);
171
+ if (normalized) {
172
+ return normalized;
173
+ }
174
+
175
+ return exports.template(null, prefs.messages, 'root', state, prefs) ||
176
+ messages && exports.template(null, messages, 'root', state, prefs) ||
177
+ 'value';
178
+ };
179
+
180
+
181
+ exports.process = function (errors, original, prefs) {
182
+
183
+ if (!errors) {
184
+ return null;
185
+ }
186
+
187
+ const { override, message, details } = exports.details(errors);
188
+ if (override) {
189
+ return override;
190
+ }
191
+
192
+ if (prefs.errors.stack) {
193
+ return new exports.ValidationError(message, details, original);
194
+ }
195
+
196
+ const limit = Error.stackTraceLimit;
197
+ Error.stackTraceLimit = 0;
198
+ const validationError = new exports.ValidationError(message, details, original);
199
+ Error.stackTraceLimit = limit;
200
+ return validationError;
201
+ };
202
+
203
+
204
+ exports.details = function (errors, options = {}) {
205
+
206
+ let messages = [];
207
+ const details = [];
208
+
209
+ for (const item of errors) {
210
+
211
+ // Override
212
+
213
+ if (item instanceof Error) {
214
+ if (options.override !== false) {
215
+ return { override: item };
216
+ }
217
+
218
+ const message = item.toString();
219
+ messages.push(message);
220
+
221
+ details.push({
222
+ message,
223
+ type: 'override',
224
+ context: { error: item }
225
+ });
226
+
227
+ continue;
228
+ }
229
+
230
+ // Report
231
+
232
+ const message = item.toString();
233
+ messages.push(message);
234
+
235
+ details.push({
236
+ message,
237
+ path: item.path.filter((v) => typeof v !== 'object'),
238
+ type: item.code,
239
+ context: item.local
240
+ });
241
+ }
242
+
243
+ if (messages.length > 1) {
244
+ messages = [...new Set(messages)];
245
+ }
246
+
247
+ return { message: messages.join('. '), details };
248
+ };
249
+
250
+
251
+ exports.ValidationError = class extends Error {
252
+
253
+ constructor(message, details, original) {
254
+
255
+ super(message);
256
+ this._original = original;
257
+ this.details = details;
258
+ }
259
+
260
+ static isError(err) {
261
+
262
+ return err instanceof exports.ValidationError;
263
+ }
264
+ };
265
+
266
+
267
+ exports.ValidationError.prototype.isJoi = true;
268
+
269
+ exports.ValidationError.prototype.name = 'ValidationError';
270
+
271
+ exports.ValidationError.prototype.annotate = Annotate.error;
@@ -0,0 +1,312 @@
1
+ 'use strict';
2
+
3
+ const Assert = require('@hapi/hoek/lib/assert');
4
+ const Clone = require('@hapi/hoek/lib/clone');
5
+
6
+ const Common = require('./common');
7
+ const Messages = require('./messages');
8
+
9
+
10
+ const internals = {};
11
+
12
+
13
+ exports.type = function (from, options) {
14
+
15
+ const base = Object.getPrototypeOf(from);
16
+ const prototype = Clone(base);
17
+ const schema = from._assign(Object.create(prototype));
18
+ const def = Object.assign({}, options); // Shallow cloned
19
+ delete def.base;
20
+
21
+ prototype._definition = def;
22
+
23
+ const parent = base._definition || {};
24
+ def.messages = Messages.merge(parent.messages, def.messages);
25
+ def.properties = Object.assign({}, parent.properties, def.properties);
26
+
27
+ // Type
28
+
29
+ schema.type = def.type;
30
+
31
+ // Flags
32
+
33
+ def.flags = Object.assign({}, parent.flags, def.flags);
34
+
35
+ // Terms
36
+
37
+ const terms = Object.assign({}, parent.terms);
38
+ if (def.terms) {
39
+ for (const name in def.terms) { // Only apply own terms
40
+ const term = def.terms[name];
41
+ Assert(schema.$_terms[name] === undefined, 'Invalid term override for', def.type, name);
42
+ schema.$_terms[name] = term.init;
43
+ terms[name] = term;
44
+ }
45
+ }
46
+
47
+ def.terms = terms;
48
+
49
+ // Constructor arguments
50
+
51
+ if (!def.args) {
52
+ def.args = parent.args;
53
+ }
54
+
55
+ // Prepare
56
+
57
+ def.prepare = internals.prepare(def.prepare, parent.prepare);
58
+
59
+ // Coerce
60
+
61
+ if (def.coerce) {
62
+ if (typeof def.coerce === 'function') {
63
+ def.coerce = { method: def.coerce };
64
+ }
65
+
66
+ if (def.coerce.from &&
67
+ !Array.isArray(def.coerce.from)) {
68
+
69
+ def.coerce = { method: def.coerce.method, from: [].concat(def.coerce.from) };
70
+ }
71
+ }
72
+
73
+ def.coerce = internals.coerce(def.coerce, parent.coerce);
74
+
75
+ // Validate
76
+
77
+ def.validate = internals.validate(def.validate, parent.validate);
78
+
79
+ // Rules
80
+
81
+ const rules = Object.assign({}, parent.rules);
82
+ if (def.rules) {
83
+ for (const name in def.rules) {
84
+ const rule = def.rules[name];
85
+ Assert(typeof rule === 'object', 'Invalid rule definition for', def.type, name);
86
+
87
+ let method = rule.method;
88
+ if (method === undefined) {
89
+ method = function () {
90
+
91
+ return this.$_addRule(name);
92
+ };
93
+ }
94
+
95
+ if (method) {
96
+ Assert(!prototype[name], 'Rule conflict in', def.type, name);
97
+ prototype[name] = method;
98
+ }
99
+
100
+ Assert(!rules[name], 'Rule conflict in', def.type, name);
101
+ rules[name] = rule;
102
+
103
+ if (rule.alias) {
104
+ const aliases = [].concat(rule.alias);
105
+ for (const alias of aliases) {
106
+ prototype[alias] = rule.method;
107
+ }
108
+ }
109
+
110
+ if (rule.args) {
111
+ rule.argsByName = new Map();
112
+ rule.args = rule.args.map((arg) => {
113
+
114
+ if (typeof arg === 'string') {
115
+ arg = { name: arg };
116
+ }
117
+
118
+ Assert(!rule.argsByName.has(arg.name), 'Duplicated argument name', arg.name);
119
+
120
+ if (Common.isSchema(arg.assert)) {
121
+ arg.assert = arg.assert.strict().label(arg.name);
122
+ }
123
+
124
+ rule.argsByName.set(arg.name, arg);
125
+ return arg;
126
+ });
127
+ }
128
+ }
129
+ }
130
+
131
+ def.rules = rules;
132
+
133
+ // Modifiers
134
+
135
+ const modifiers = Object.assign({}, parent.modifiers);
136
+ if (def.modifiers) {
137
+ for (const name in def.modifiers) {
138
+ Assert(!prototype[name], 'Rule conflict in', def.type, name);
139
+
140
+ const modifier = def.modifiers[name];
141
+ Assert(typeof modifier === 'function', 'Invalid modifier definition for', def.type, name);
142
+
143
+ const method = function (arg) {
144
+
145
+ return this.rule({ [name]: arg });
146
+ };
147
+
148
+ prototype[name] = method;
149
+ modifiers[name] = modifier;
150
+ }
151
+ }
152
+
153
+ def.modifiers = modifiers;
154
+
155
+ // Overrides
156
+
157
+ if (def.overrides) {
158
+ prototype._super = base;
159
+ schema.$_super = {}; // Backwards compatibility
160
+ for (const override in def.overrides) {
161
+ Assert(base[override], 'Cannot override missing', override);
162
+ def.overrides[override][Common.symbols.parent] = base[override];
163
+ schema.$_super[override] = base[override].bind(schema); // Backwards compatibility
164
+ }
165
+
166
+ Object.assign(prototype, def.overrides);
167
+ }
168
+
169
+ // Casts
170
+
171
+ def.cast = Object.assign({}, parent.cast, def.cast);
172
+
173
+ // Manifest
174
+
175
+ const manifest = Object.assign({}, parent.manifest, def.manifest);
176
+ manifest.build = internals.build(def.manifest && def.manifest.build, parent.manifest && parent.manifest.build);
177
+ def.manifest = manifest;
178
+
179
+ // Rebuild
180
+
181
+ def.rebuild = internals.rebuild(def.rebuild, parent.rebuild);
182
+
183
+ return schema;
184
+ };
185
+
186
+
187
+ // Helpers
188
+
189
+ internals.build = function (child, parent) {
190
+
191
+ if (!child ||
192
+ !parent) {
193
+
194
+ return child || parent;
195
+ }
196
+
197
+ return function (obj, desc) {
198
+
199
+ return parent(child(obj, desc), desc);
200
+ };
201
+ };
202
+
203
+
204
+ internals.coerce = function (child, parent) {
205
+
206
+ if (!child ||
207
+ !parent) {
208
+
209
+ return child || parent;
210
+ }
211
+
212
+ return {
213
+ from: child.from && parent.from ? [...new Set([...child.from, ...parent.from])] : null,
214
+ method(value, helpers) {
215
+
216
+ let coerced;
217
+ if (!parent.from ||
218
+ parent.from.includes(typeof value)) {
219
+
220
+ coerced = parent.method(value, helpers);
221
+ if (coerced) {
222
+ if (coerced.errors ||
223
+ coerced.value === undefined) {
224
+
225
+ return coerced;
226
+ }
227
+
228
+ value = coerced.value;
229
+ }
230
+ }
231
+
232
+ if (!child.from ||
233
+ child.from.includes(typeof value)) {
234
+
235
+ const own = child.method(value, helpers);
236
+ if (own) {
237
+ return own;
238
+ }
239
+ }
240
+
241
+ return coerced;
242
+ }
243
+ };
244
+ };
245
+
246
+
247
+ internals.prepare = function (child, parent) {
248
+
249
+ if (!child ||
250
+ !parent) {
251
+
252
+ return child || parent;
253
+ }
254
+
255
+ return function (value, helpers) {
256
+
257
+ const prepared = child(value, helpers);
258
+ if (prepared) {
259
+ if (prepared.errors ||
260
+ prepared.value === undefined) {
261
+
262
+ return prepared;
263
+ }
264
+
265
+ value = prepared.value;
266
+ }
267
+
268
+ return parent(value, helpers) || prepared;
269
+ };
270
+ };
271
+
272
+
273
+ internals.rebuild = function (child, parent) {
274
+
275
+ if (!child ||
276
+ !parent) {
277
+
278
+ return child || parent;
279
+ }
280
+
281
+ return function (schema) {
282
+
283
+ parent(schema);
284
+ child(schema);
285
+ };
286
+ };
287
+
288
+
289
+ internals.validate = function (child, parent) {
290
+
291
+ if (!child ||
292
+ !parent) {
293
+
294
+ return child || parent;
295
+ }
296
+
297
+ return function (value, helpers) {
298
+
299
+ const result = parent(value, helpers);
300
+ if (result) {
301
+ if (result.errors &&
302
+ (!Array.isArray(result.errors) || result.errors.length)) {
303
+
304
+ return result;
305
+ }
306
+
307
+ value = result.value;
308
+ }
309
+
310
+ return child(value, helpers) || result;
311
+ };
312
+ };