@nocobase/plugin-workflow-custom-action-trigger 2.1.0-alpha.10 → 2.1.0-alpha.12
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.
- package/dist/client/CustomActionTrigger.d.ts +39 -2
- package/dist/client/index.js +1 -1
- package/dist/externalVersion.js +10 -10
- package/dist/node_modules/joi/dist/joi-browser.min.js +1 -0
- package/dist/node_modules/joi/lib/annotate.js +175 -0
- package/dist/node_modules/joi/lib/base.js +1069 -0
- package/dist/node_modules/joi/lib/cache.js +143 -0
- package/dist/node_modules/joi/lib/common.js +216 -0
- package/dist/node_modules/joi/lib/compile.js +283 -0
- package/dist/node_modules/joi/lib/errors.js +271 -0
- package/dist/node_modules/joi/lib/extend.js +312 -0
- package/dist/node_modules/joi/lib/index.d.ts +2365 -0
- package/dist/node_modules/joi/lib/index.js +1 -0
- package/dist/node_modules/joi/lib/manifest.js +476 -0
- package/dist/node_modules/joi/lib/messages.js +178 -0
- package/dist/node_modules/joi/lib/modify.js +267 -0
- package/dist/node_modules/joi/lib/ref.js +414 -0
- package/dist/node_modules/joi/lib/schemas.js +302 -0
- package/dist/node_modules/joi/lib/state.js +166 -0
- package/dist/node_modules/joi/lib/template.js +463 -0
- package/dist/node_modules/joi/lib/trace.js +346 -0
- package/dist/node_modules/joi/lib/types/alternatives.js +364 -0
- package/dist/node_modules/joi/lib/types/any.js +174 -0
- package/dist/node_modules/joi/lib/types/array.js +809 -0
- package/dist/node_modules/joi/lib/types/binary.js +100 -0
- package/dist/node_modules/joi/lib/types/boolean.js +150 -0
- package/dist/node_modules/joi/lib/types/date.js +233 -0
- package/dist/node_modules/joi/lib/types/function.js +93 -0
- package/dist/node_modules/joi/lib/types/keys.js +1067 -0
- package/dist/node_modules/joi/lib/types/link.js +168 -0
- package/dist/node_modules/joi/lib/types/number.js +363 -0
- package/dist/node_modules/joi/lib/types/object.js +22 -0
- package/dist/node_modules/joi/lib/types/string.js +850 -0
- package/dist/node_modules/joi/lib/types/symbol.js +102 -0
- package/dist/node_modules/joi/lib/validator.js +750 -0
- package/dist/node_modules/joi/lib/values.js +263 -0
- package/dist/node_modules/joi/node_modules/@hapi/topo/lib/index.d.ts +60 -0
- package/dist/node_modules/joi/node_modules/@hapi/topo/lib/index.js +225 -0
- package/dist/node_modules/joi/node_modules/@hapi/topo/package.json +30 -0
- package/dist/node_modules/joi/package.json +1 -0
- package/dist/server/CustomActionTrigger.d.ts +11 -0
- package/dist/server/CustomActionTrigger.js +19 -0
- package/package.json +5 -2
|
@@ -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
|
+
};
|