@nocobase/plugin-workflow-custom-action-trigger 2.1.0-alpha.10 → 2.1.0-alpha.11
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,476 @@
|
|
|
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
|
+
const Ref = require('./ref');
|
|
9
|
+
const Template = require('./template');
|
|
10
|
+
|
|
11
|
+
let Schemas;
|
|
12
|
+
|
|
13
|
+
|
|
14
|
+
const internals = {};
|
|
15
|
+
|
|
16
|
+
|
|
17
|
+
exports.describe = function (schema) {
|
|
18
|
+
|
|
19
|
+
const def = schema._definition;
|
|
20
|
+
|
|
21
|
+
// Type
|
|
22
|
+
|
|
23
|
+
const desc = {
|
|
24
|
+
type: schema.type,
|
|
25
|
+
flags: {},
|
|
26
|
+
rules: []
|
|
27
|
+
};
|
|
28
|
+
|
|
29
|
+
// Flags
|
|
30
|
+
|
|
31
|
+
for (const flag in schema._flags) {
|
|
32
|
+
if (flag[0] !== '_') {
|
|
33
|
+
desc.flags[flag] = internals.describe(schema._flags[flag]);
|
|
34
|
+
}
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
if (!Object.keys(desc.flags).length) {
|
|
38
|
+
delete desc.flags;
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
// Preferences
|
|
42
|
+
|
|
43
|
+
if (schema._preferences) {
|
|
44
|
+
desc.preferences = Clone(schema._preferences, { shallow: ['messages'] });
|
|
45
|
+
delete desc.preferences[Common.symbols.prefs];
|
|
46
|
+
if (desc.preferences.messages) {
|
|
47
|
+
desc.preferences.messages = Messages.decompile(desc.preferences.messages);
|
|
48
|
+
}
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
// Allow / Invalid
|
|
52
|
+
|
|
53
|
+
if (schema._valids) {
|
|
54
|
+
desc.allow = schema._valids.describe();
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
if (schema._invalids) {
|
|
58
|
+
desc.invalid = schema._invalids.describe();
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
// Rules
|
|
62
|
+
|
|
63
|
+
for (const rule of schema._rules) {
|
|
64
|
+
const ruleDef = def.rules[rule.name];
|
|
65
|
+
if (ruleDef.manifest === false) { // Defaults to true
|
|
66
|
+
continue;
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
const item = { name: rule.name };
|
|
70
|
+
|
|
71
|
+
for (const custom in def.modifiers) {
|
|
72
|
+
if (rule[custom] !== undefined) {
|
|
73
|
+
item[custom] = internals.describe(rule[custom]);
|
|
74
|
+
}
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
if (rule.args) {
|
|
78
|
+
item.args = {};
|
|
79
|
+
for (const key in rule.args) {
|
|
80
|
+
const arg = rule.args[key];
|
|
81
|
+
if (key === 'options' &&
|
|
82
|
+
!Object.keys(arg).length) {
|
|
83
|
+
|
|
84
|
+
continue;
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
item.args[key] = internals.describe(arg, { assign: key });
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
if (!Object.keys(item.args).length) {
|
|
91
|
+
delete item.args;
|
|
92
|
+
}
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
desc.rules.push(item);
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
if (!desc.rules.length) {
|
|
99
|
+
delete desc.rules;
|
|
100
|
+
}
|
|
101
|
+
|
|
102
|
+
// Terms (must be last to verify no name conflicts)
|
|
103
|
+
|
|
104
|
+
for (const term in schema.$_terms) {
|
|
105
|
+
if (term[0] === '_') {
|
|
106
|
+
continue;
|
|
107
|
+
}
|
|
108
|
+
|
|
109
|
+
Assert(!desc[term], 'Cannot describe schema due to internal name conflict with', term);
|
|
110
|
+
|
|
111
|
+
const items = schema.$_terms[term];
|
|
112
|
+
if (!items) {
|
|
113
|
+
continue;
|
|
114
|
+
}
|
|
115
|
+
|
|
116
|
+
if (items instanceof Map) {
|
|
117
|
+
if (items.size) {
|
|
118
|
+
desc[term] = [...items.entries()];
|
|
119
|
+
}
|
|
120
|
+
|
|
121
|
+
continue;
|
|
122
|
+
}
|
|
123
|
+
|
|
124
|
+
if (Common.isValues(items)) {
|
|
125
|
+
desc[term] = items.describe();
|
|
126
|
+
continue;
|
|
127
|
+
}
|
|
128
|
+
|
|
129
|
+
Assert(def.terms[term], 'Term', term, 'missing configuration');
|
|
130
|
+
const manifest = def.terms[term].manifest;
|
|
131
|
+
const mapped = typeof manifest === 'object';
|
|
132
|
+
if (!items.length &&
|
|
133
|
+
!mapped) {
|
|
134
|
+
|
|
135
|
+
continue;
|
|
136
|
+
}
|
|
137
|
+
|
|
138
|
+
const normalized = [];
|
|
139
|
+
for (const item of items) {
|
|
140
|
+
normalized.push(internals.describe(item));
|
|
141
|
+
}
|
|
142
|
+
|
|
143
|
+
// Mapped
|
|
144
|
+
|
|
145
|
+
if (mapped) {
|
|
146
|
+
const { from, to } = manifest.mapped;
|
|
147
|
+
desc[term] = {};
|
|
148
|
+
for (const item of normalized) {
|
|
149
|
+
desc[term][item[to]] = item[from];
|
|
150
|
+
}
|
|
151
|
+
|
|
152
|
+
continue;
|
|
153
|
+
}
|
|
154
|
+
|
|
155
|
+
// Single
|
|
156
|
+
|
|
157
|
+
if (manifest === 'single') {
|
|
158
|
+
Assert(normalized.length === 1, 'Term', term, 'contains more than one item');
|
|
159
|
+
desc[term] = normalized[0];
|
|
160
|
+
continue;
|
|
161
|
+
}
|
|
162
|
+
|
|
163
|
+
// Array
|
|
164
|
+
|
|
165
|
+
desc[term] = normalized;
|
|
166
|
+
}
|
|
167
|
+
|
|
168
|
+
internals.validate(schema.$_root, desc);
|
|
169
|
+
return desc;
|
|
170
|
+
};
|
|
171
|
+
|
|
172
|
+
|
|
173
|
+
internals.describe = function (item, options = {}) {
|
|
174
|
+
|
|
175
|
+
if (Array.isArray(item)) {
|
|
176
|
+
return item.map(internals.describe);
|
|
177
|
+
}
|
|
178
|
+
|
|
179
|
+
if (item === Common.symbols.deepDefault) {
|
|
180
|
+
return { special: 'deep' };
|
|
181
|
+
}
|
|
182
|
+
|
|
183
|
+
if (typeof item !== 'object' ||
|
|
184
|
+
item === null) {
|
|
185
|
+
|
|
186
|
+
return item;
|
|
187
|
+
}
|
|
188
|
+
|
|
189
|
+
if (options.assign === 'options') {
|
|
190
|
+
return Clone(item);
|
|
191
|
+
}
|
|
192
|
+
|
|
193
|
+
if (Buffer && Buffer.isBuffer(item)) { // $lab:coverage:ignore$
|
|
194
|
+
return { buffer: item.toString('binary') };
|
|
195
|
+
}
|
|
196
|
+
|
|
197
|
+
if (item instanceof Date) {
|
|
198
|
+
return item.toISOString();
|
|
199
|
+
}
|
|
200
|
+
|
|
201
|
+
if (item instanceof Error) {
|
|
202
|
+
return item;
|
|
203
|
+
}
|
|
204
|
+
|
|
205
|
+
if (item instanceof RegExp) {
|
|
206
|
+
if (options.assign === 'regex') {
|
|
207
|
+
return item.toString();
|
|
208
|
+
}
|
|
209
|
+
|
|
210
|
+
return { regex: item.toString() };
|
|
211
|
+
}
|
|
212
|
+
|
|
213
|
+
if (item[Common.symbols.literal]) {
|
|
214
|
+
return { function: item.literal };
|
|
215
|
+
}
|
|
216
|
+
|
|
217
|
+
if (typeof item.describe === 'function') {
|
|
218
|
+
if (options.assign === 'ref') {
|
|
219
|
+
return item.describe().ref;
|
|
220
|
+
}
|
|
221
|
+
|
|
222
|
+
return item.describe();
|
|
223
|
+
}
|
|
224
|
+
|
|
225
|
+
const normalized = {};
|
|
226
|
+
for (const key in item) {
|
|
227
|
+
const value = item[key];
|
|
228
|
+
if (value === undefined) {
|
|
229
|
+
continue;
|
|
230
|
+
}
|
|
231
|
+
|
|
232
|
+
normalized[key] = internals.describe(value, { assign: key });
|
|
233
|
+
}
|
|
234
|
+
|
|
235
|
+
return normalized;
|
|
236
|
+
};
|
|
237
|
+
|
|
238
|
+
|
|
239
|
+
exports.build = function (joi, desc) {
|
|
240
|
+
|
|
241
|
+
const builder = new internals.Builder(joi);
|
|
242
|
+
return builder.parse(desc);
|
|
243
|
+
};
|
|
244
|
+
|
|
245
|
+
|
|
246
|
+
internals.Builder = class {
|
|
247
|
+
|
|
248
|
+
constructor(joi) {
|
|
249
|
+
|
|
250
|
+
this.joi = joi;
|
|
251
|
+
}
|
|
252
|
+
|
|
253
|
+
parse(desc) {
|
|
254
|
+
|
|
255
|
+
internals.validate(this.joi, desc);
|
|
256
|
+
|
|
257
|
+
// Type
|
|
258
|
+
|
|
259
|
+
let schema = this.joi[desc.type]()._bare();
|
|
260
|
+
const def = schema._definition;
|
|
261
|
+
|
|
262
|
+
// Flags
|
|
263
|
+
|
|
264
|
+
if (desc.flags) {
|
|
265
|
+
for (const flag in desc.flags) {
|
|
266
|
+
const setter = def.flags[flag] && def.flags[flag].setter || flag;
|
|
267
|
+
Assert(typeof schema[setter] === 'function', 'Invalid flag', flag, 'for type', desc.type);
|
|
268
|
+
schema = schema[setter](this.build(desc.flags[flag]));
|
|
269
|
+
}
|
|
270
|
+
}
|
|
271
|
+
|
|
272
|
+
// Preferences
|
|
273
|
+
|
|
274
|
+
if (desc.preferences) {
|
|
275
|
+
schema = schema.preferences(this.build(desc.preferences));
|
|
276
|
+
}
|
|
277
|
+
|
|
278
|
+
// Allow / Invalid
|
|
279
|
+
|
|
280
|
+
if (desc.allow) {
|
|
281
|
+
schema = schema.allow(...this.build(desc.allow));
|
|
282
|
+
}
|
|
283
|
+
|
|
284
|
+
if (desc.invalid) {
|
|
285
|
+
schema = schema.invalid(...this.build(desc.invalid));
|
|
286
|
+
}
|
|
287
|
+
|
|
288
|
+
// Rules
|
|
289
|
+
|
|
290
|
+
if (desc.rules) {
|
|
291
|
+
for (const rule of desc.rules) {
|
|
292
|
+
Assert(typeof schema[rule.name] === 'function', 'Invalid rule', rule.name, 'for type', desc.type);
|
|
293
|
+
|
|
294
|
+
const args = [];
|
|
295
|
+
if (rule.args) {
|
|
296
|
+
const built = {};
|
|
297
|
+
for (const key in rule.args) {
|
|
298
|
+
built[key] = this.build(rule.args[key], { assign: key });
|
|
299
|
+
}
|
|
300
|
+
|
|
301
|
+
const keys = Object.keys(built);
|
|
302
|
+
const definition = def.rules[rule.name].args;
|
|
303
|
+
if (definition) {
|
|
304
|
+
Assert(keys.length <= definition.length, 'Invalid number of arguments for', desc.type, rule.name, '(expected up to', definition.length, ', found', keys.length, ')');
|
|
305
|
+
for (const { name } of definition) {
|
|
306
|
+
args.push(built[name]);
|
|
307
|
+
}
|
|
308
|
+
}
|
|
309
|
+
else {
|
|
310
|
+
Assert(keys.length === 1, 'Invalid number of arguments for', desc.type, rule.name, '(expected up to 1, found', keys.length, ')');
|
|
311
|
+
args.push(built[keys[0]]);
|
|
312
|
+
}
|
|
313
|
+
}
|
|
314
|
+
|
|
315
|
+
// Apply
|
|
316
|
+
|
|
317
|
+
schema = schema[rule.name](...args);
|
|
318
|
+
|
|
319
|
+
// Ruleset
|
|
320
|
+
|
|
321
|
+
const options = {};
|
|
322
|
+
for (const custom in def.modifiers) {
|
|
323
|
+
if (rule[custom] !== undefined) {
|
|
324
|
+
options[custom] = this.build(rule[custom]);
|
|
325
|
+
}
|
|
326
|
+
}
|
|
327
|
+
|
|
328
|
+
if (Object.keys(options).length) {
|
|
329
|
+
schema = schema.rule(options);
|
|
330
|
+
}
|
|
331
|
+
}
|
|
332
|
+
}
|
|
333
|
+
|
|
334
|
+
// Terms
|
|
335
|
+
|
|
336
|
+
const terms = {};
|
|
337
|
+
for (const key in desc) {
|
|
338
|
+
if (['allow', 'flags', 'invalid', 'whens', 'preferences', 'rules', 'type'].includes(key)) {
|
|
339
|
+
continue;
|
|
340
|
+
}
|
|
341
|
+
|
|
342
|
+
Assert(def.terms[key], 'Term', key, 'missing configuration');
|
|
343
|
+
const manifest = def.terms[key].manifest;
|
|
344
|
+
|
|
345
|
+
if (manifest === 'schema') {
|
|
346
|
+
terms[key] = desc[key].map((item) => this.parse(item));
|
|
347
|
+
continue;
|
|
348
|
+
}
|
|
349
|
+
|
|
350
|
+
if (manifest === 'values') {
|
|
351
|
+
terms[key] = desc[key].map((item) => this.build(item));
|
|
352
|
+
continue;
|
|
353
|
+
}
|
|
354
|
+
|
|
355
|
+
if (manifest === 'single') {
|
|
356
|
+
terms[key] = this.build(desc[key]);
|
|
357
|
+
continue;
|
|
358
|
+
}
|
|
359
|
+
|
|
360
|
+
if (typeof manifest === 'object') {
|
|
361
|
+
terms[key] = {};
|
|
362
|
+
for (const name in desc[key]) {
|
|
363
|
+
const value = desc[key][name];
|
|
364
|
+
terms[key][name] = this.parse(value);
|
|
365
|
+
}
|
|
366
|
+
|
|
367
|
+
continue;
|
|
368
|
+
}
|
|
369
|
+
|
|
370
|
+
terms[key] = this.build(desc[key]);
|
|
371
|
+
}
|
|
372
|
+
|
|
373
|
+
if (desc.whens) {
|
|
374
|
+
terms.whens = desc.whens.map((when) => this.build(when));
|
|
375
|
+
}
|
|
376
|
+
|
|
377
|
+
schema = def.manifest.build(schema, terms);
|
|
378
|
+
schema.$_temp.ruleset = false;
|
|
379
|
+
return schema;
|
|
380
|
+
}
|
|
381
|
+
|
|
382
|
+
build(desc, options = {}) {
|
|
383
|
+
|
|
384
|
+
if (desc === null) {
|
|
385
|
+
return null;
|
|
386
|
+
}
|
|
387
|
+
|
|
388
|
+
if (Array.isArray(desc)) {
|
|
389
|
+
return desc.map((item) => this.build(item));
|
|
390
|
+
}
|
|
391
|
+
|
|
392
|
+
if (desc instanceof Error) {
|
|
393
|
+
return desc;
|
|
394
|
+
}
|
|
395
|
+
|
|
396
|
+
if (options.assign === 'options') {
|
|
397
|
+
return Clone(desc);
|
|
398
|
+
}
|
|
399
|
+
|
|
400
|
+
if (options.assign === 'regex') {
|
|
401
|
+
return internals.regex(desc);
|
|
402
|
+
}
|
|
403
|
+
|
|
404
|
+
if (options.assign === 'ref') {
|
|
405
|
+
return Ref.build(desc);
|
|
406
|
+
}
|
|
407
|
+
|
|
408
|
+
if (typeof desc !== 'object') {
|
|
409
|
+
return desc;
|
|
410
|
+
}
|
|
411
|
+
|
|
412
|
+
if (Object.keys(desc).length === 1) {
|
|
413
|
+
if (desc.buffer) {
|
|
414
|
+
Assert(Buffer, 'Buffers are not supported');
|
|
415
|
+
return Buffer && Buffer.from(desc.buffer, 'binary'); // $lab:coverage:ignore$
|
|
416
|
+
}
|
|
417
|
+
|
|
418
|
+
if (desc.function) {
|
|
419
|
+
return { [Common.symbols.literal]: true, literal: desc.function };
|
|
420
|
+
}
|
|
421
|
+
|
|
422
|
+
if (desc.override) {
|
|
423
|
+
return Common.symbols.override;
|
|
424
|
+
}
|
|
425
|
+
|
|
426
|
+
if (desc.ref) {
|
|
427
|
+
return Ref.build(desc.ref);
|
|
428
|
+
}
|
|
429
|
+
|
|
430
|
+
if (desc.regex) {
|
|
431
|
+
return internals.regex(desc.regex);
|
|
432
|
+
}
|
|
433
|
+
|
|
434
|
+
if (desc.special) {
|
|
435
|
+
Assert(['deep'].includes(desc.special), 'Unknown special value', desc.special);
|
|
436
|
+
return Common.symbols.deepDefault;
|
|
437
|
+
}
|
|
438
|
+
|
|
439
|
+
if (desc.value) {
|
|
440
|
+
return Clone(desc.value);
|
|
441
|
+
}
|
|
442
|
+
}
|
|
443
|
+
|
|
444
|
+
if (desc.type) {
|
|
445
|
+
return this.parse(desc);
|
|
446
|
+
}
|
|
447
|
+
|
|
448
|
+
if (desc.template) {
|
|
449
|
+
return Template.build(desc);
|
|
450
|
+
}
|
|
451
|
+
|
|
452
|
+
const normalized = {};
|
|
453
|
+
for (const key in desc) {
|
|
454
|
+
normalized[key] = this.build(desc[key], { assign: key });
|
|
455
|
+
}
|
|
456
|
+
|
|
457
|
+
return normalized;
|
|
458
|
+
}
|
|
459
|
+
};
|
|
460
|
+
|
|
461
|
+
|
|
462
|
+
internals.regex = function (string) {
|
|
463
|
+
|
|
464
|
+
const end = string.lastIndexOf('/');
|
|
465
|
+
const exp = string.slice(1, end);
|
|
466
|
+
const flags = string.slice(end + 1);
|
|
467
|
+
return new RegExp(exp, flags);
|
|
468
|
+
};
|
|
469
|
+
|
|
470
|
+
|
|
471
|
+
internals.validate = function (joi, desc) {
|
|
472
|
+
|
|
473
|
+
Schemas = Schemas || require('./schemas');
|
|
474
|
+
|
|
475
|
+
joi.assert(desc, Schemas.description);
|
|
476
|
+
};
|
|
@@ -0,0 +1,178 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
const Assert = require('@hapi/hoek/lib/assert');
|
|
4
|
+
const Clone = require('@hapi/hoek/lib/clone');
|
|
5
|
+
|
|
6
|
+
const Template = require('./template');
|
|
7
|
+
|
|
8
|
+
|
|
9
|
+
const internals = {};
|
|
10
|
+
|
|
11
|
+
|
|
12
|
+
exports.compile = function (messages, target) {
|
|
13
|
+
|
|
14
|
+
// Single value string ('plain error message', 'template {error} message')
|
|
15
|
+
|
|
16
|
+
if (typeof messages === 'string') {
|
|
17
|
+
Assert(!target, 'Cannot set single message string');
|
|
18
|
+
return new Template(messages);
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
// Single value template
|
|
22
|
+
|
|
23
|
+
if (Template.isTemplate(messages)) {
|
|
24
|
+
Assert(!target, 'Cannot set single message template');
|
|
25
|
+
return messages;
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
// By error code { 'number.min': <string | template> }
|
|
29
|
+
|
|
30
|
+
Assert(typeof messages === 'object' && !Array.isArray(messages), 'Invalid message options');
|
|
31
|
+
|
|
32
|
+
target = target ? Clone(target) : {};
|
|
33
|
+
|
|
34
|
+
for (let code in messages) {
|
|
35
|
+
const message = messages[code];
|
|
36
|
+
|
|
37
|
+
if (code === 'root' ||
|
|
38
|
+
Template.isTemplate(message)) {
|
|
39
|
+
|
|
40
|
+
target[code] = message;
|
|
41
|
+
continue;
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
if (typeof message === 'string') {
|
|
45
|
+
target[code] = new Template(message);
|
|
46
|
+
continue;
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
// By language { english: { 'number.min': <string | template> } }
|
|
50
|
+
|
|
51
|
+
Assert(typeof message === 'object' && !Array.isArray(message), 'Invalid message for', code);
|
|
52
|
+
|
|
53
|
+
const language = code;
|
|
54
|
+
target[language] = target[language] || {};
|
|
55
|
+
|
|
56
|
+
for (code in message) {
|
|
57
|
+
const localized = message[code];
|
|
58
|
+
|
|
59
|
+
if (code === 'root' ||
|
|
60
|
+
Template.isTemplate(localized)) {
|
|
61
|
+
|
|
62
|
+
target[language][code] = localized;
|
|
63
|
+
continue;
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
Assert(typeof localized === 'string', 'Invalid message for', code, 'in', language);
|
|
67
|
+
target[language][code] = new Template(localized);
|
|
68
|
+
}
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
return target;
|
|
72
|
+
};
|
|
73
|
+
|
|
74
|
+
|
|
75
|
+
exports.decompile = function (messages) {
|
|
76
|
+
|
|
77
|
+
// By error code { 'number.min': <string | template> }
|
|
78
|
+
|
|
79
|
+
const target = {};
|
|
80
|
+
for (let code in messages) {
|
|
81
|
+
const message = messages[code];
|
|
82
|
+
|
|
83
|
+
if (code === 'root') {
|
|
84
|
+
target.root = message;
|
|
85
|
+
continue;
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
if (Template.isTemplate(message)) {
|
|
89
|
+
target[code] = message.describe({ compact: true });
|
|
90
|
+
continue;
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
// By language { english: { 'number.min': <string | template> } }
|
|
94
|
+
|
|
95
|
+
const language = code;
|
|
96
|
+
target[language] = {};
|
|
97
|
+
|
|
98
|
+
for (code in message) {
|
|
99
|
+
const localized = message[code];
|
|
100
|
+
|
|
101
|
+
if (code === 'root') {
|
|
102
|
+
target[language].root = localized;
|
|
103
|
+
continue;
|
|
104
|
+
}
|
|
105
|
+
|
|
106
|
+
target[language][code] = localized.describe({ compact: true });
|
|
107
|
+
}
|
|
108
|
+
}
|
|
109
|
+
|
|
110
|
+
return target;
|
|
111
|
+
};
|
|
112
|
+
|
|
113
|
+
|
|
114
|
+
exports.merge = function (base, extended) {
|
|
115
|
+
|
|
116
|
+
if (!base) {
|
|
117
|
+
return exports.compile(extended);
|
|
118
|
+
}
|
|
119
|
+
|
|
120
|
+
if (!extended) {
|
|
121
|
+
return base;
|
|
122
|
+
}
|
|
123
|
+
|
|
124
|
+
// Single value string
|
|
125
|
+
|
|
126
|
+
if (typeof extended === 'string') {
|
|
127
|
+
return new Template(extended);
|
|
128
|
+
}
|
|
129
|
+
|
|
130
|
+
// Single value template
|
|
131
|
+
|
|
132
|
+
if (Template.isTemplate(extended)) {
|
|
133
|
+
return extended;
|
|
134
|
+
}
|
|
135
|
+
|
|
136
|
+
// By error code { 'number.min': <string | template> }
|
|
137
|
+
|
|
138
|
+
const target = Clone(base);
|
|
139
|
+
|
|
140
|
+
for (let code in extended) {
|
|
141
|
+
const message = extended[code];
|
|
142
|
+
|
|
143
|
+
if (code === 'root' ||
|
|
144
|
+
Template.isTemplate(message)) {
|
|
145
|
+
|
|
146
|
+
target[code] = message;
|
|
147
|
+
continue;
|
|
148
|
+
}
|
|
149
|
+
|
|
150
|
+
if (typeof message === 'string') {
|
|
151
|
+
target[code] = new Template(message);
|
|
152
|
+
continue;
|
|
153
|
+
}
|
|
154
|
+
|
|
155
|
+
// By language { english: { 'number.min': <string | template> } }
|
|
156
|
+
|
|
157
|
+
Assert(typeof message === 'object' && !Array.isArray(message), 'Invalid message for', code);
|
|
158
|
+
|
|
159
|
+
const language = code;
|
|
160
|
+
target[language] = target[language] || {};
|
|
161
|
+
|
|
162
|
+
for (code in message) {
|
|
163
|
+
const localized = message[code];
|
|
164
|
+
|
|
165
|
+
if (code === 'root' ||
|
|
166
|
+
Template.isTemplate(localized)) {
|
|
167
|
+
|
|
168
|
+
target[language][code] = localized;
|
|
169
|
+
continue;
|
|
170
|
+
}
|
|
171
|
+
|
|
172
|
+
Assert(typeof localized === 'string', 'Invalid message for', code, 'in', language);
|
|
173
|
+
target[language][code] = new Template(localized);
|
|
174
|
+
}
|
|
175
|
+
}
|
|
176
|
+
|
|
177
|
+
return target;
|
|
178
|
+
};
|