@nocobase/plugin-workflow 2.1.0-alpha.1 → 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/LICENSE +201 -661
- package/README.md +79 -10
- package/dist/client/93d3f3f8ced1c194.js +10 -0
- package/dist/client/AddNodeContext.d.ts +1 -0
- package/dist/client/NodeClipboardContext.d.ts +11 -0
- package/dist/client/NodeDragContext.d.ts +11 -0
- package/dist/client/c46a9a8d11a5be44.js +10 -0
- package/dist/client/cd221313681d6736.js +10 -0
- package/dist/client/e9463c8cd2a45481.js +10 -0
- package/dist/client/hooks/{useWorkflowFilterActionProps.d.ts → useResourceFilterActionProps.d.ts} +1 -1
- package/dist/client/index.d.ts +3 -0
- package/dist/client/index.js +1 -1
- package/dist/client/models/NodeDetailsGridModel.d.ts +13 -0
- package/dist/client/models/NodeDetailsModel.d.ts +34 -0
- package/dist/client/models/NodeValueModel.d.ts +15 -0
- package/dist/client/models/TaskCardCommonItemModel.d.ts +14 -0
- package/dist/client/models/index.d.ts +11 -0
- package/dist/client/nodeVariableUtils.d.ts +14 -0
- package/dist/client/nodes/calculation.d.ts +7 -0
- package/dist/client/nodes/create.d.ts +23 -0
- package/dist/client/nodes/destroy.d.ts +10 -0
- package/dist/client/nodes/index.d.ts +24 -0
- package/dist/client/nodes/output.d.ts +53 -0
- package/dist/client/nodes/query.d.ts +23 -0
- package/dist/client/nodes/update.d.ts +11 -0
- package/dist/client/schemas/executions.d.ts +41 -22
- package/dist/client/style.d.ts +4 -0
- package/dist/client/triggers/collection.d.ts +27 -1
- package/dist/client/triggers/index.d.ts +14 -0
- package/dist/client/triggers/schedule/constants.d.ts +4 -0
- package/dist/client/triggers/schedule/index.d.ts +28 -0
- package/dist/common/collections/executions.d.ts +22 -22
- package/dist/common/collections/executions.js +12 -0
- package/dist/common/collections/jobs.js +4 -0
- package/dist/common/collections/workflows.d.ts +22 -9
- package/dist/common/collections/workflows.js +9 -1
- package/dist/externalVersion.js +12 -12
- package/dist/locale/de-DE.json +10 -3
- package/dist/locale/en-US.json +22 -3
- package/dist/locale/es-ES.json +10 -3
- package/dist/locale/fr-FR.json +10 -3
- package/dist/locale/hu-HU.json +10 -2
- package/dist/locale/id-ID.json +10 -2
- package/dist/locale/it-IT.json +10 -3
- package/dist/locale/ja-JP.json +10 -5
- package/dist/locale/ko-KR.json +10 -3
- package/dist/locale/nl-NL.json +10 -3
- package/dist/locale/pt-BR.json +10 -3
- package/dist/locale/ru-RU.json +10 -3
- package/dist/locale/tr-TR.json +10 -3
- package/dist/locale/uk-UA.json +10 -3
- package/dist/locale/vi-VN.json +10 -2
- package/dist/locale/zh-CN.json +28 -5
- package/dist/locale/zh-TW.json +10 -3
- package/dist/node_modules/cron-parser/package.json +1 -1
- 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/node_modules/lru-cache/package.json +1 -1
- package/dist/node_modules/nodejs-snowflake/package.json +1 -1
- package/dist/server/Dispatcher.d.ts +3 -2
- package/dist/server/Dispatcher.js +76 -62
- package/dist/server/Plugin.d.ts +1 -0
- package/dist/server/Plugin.js +32 -1
- package/dist/server/Processor.d.ts +9 -0
- package/dist/server/Processor.js +6 -1
- package/dist/server/actions/index.js +2 -0
- package/dist/server/actions/nodes.d.ts +7 -0
- package/dist/server/actions/nodes.js +315 -4
- package/dist/server/actions/workflows.d.ts +6 -0
- package/dist/server/actions/workflows.js +38 -0
- package/dist/server/instructions/ConditionInstruction.js +4 -1
- package/dist/server/instructions/CreateInstruction.d.ts +3 -0
- package/dist/server/instructions/CreateInstruction.js +21 -0
- package/dist/server/instructions/DestroyInstruction.d.ts +3 -0
- package/dist/server/instructions/DestroyInstruction.js +22 -0
- package/dist/server/instructions/EndInstruction.d.ts +2 -0
- package/dist/server/instructions/EndInstruction.js +4 -0
- package/dist/server/instructions/OutputInstruction.d.ts +21 -0
- package/dist/server/instructions/OutputInstruction.js +54 -0
- package/dist/server/instructions/QueryInstruction.d.ts +3 -0
- package/dist/server/instructions/QueryInstruction.js +21 -0
- package/dist/server/instructions/UpdateInstruction.d.ts +3 -0
- package/dist/server/instructions/UpdateInstruction.js +22 -0
- package/dist/server/instructions/index.d.ts +4 -0
- package/dist/server/instructions/index.js +18 -0
- package/dist/server/repositories/WorkflowRepository.js +2 -1
- package/dist/server/triggers/CollectionTrigger.d.ts +3 -0
- package/dist/server/triggers/CollectionTrigger.js +23 -0
- package/dist/server/triggers/ScheduleTrigger/index.d.ts +3 -0
- package/dist/server/triggers/ScheduleTrigger/index.js +18 -3
- package/dist/server/triggers/index.d.ts +3 -0
- package/dist/server/triggers/index.js +18 -0
- package/dist/server/utils.d.ts +2 -0
- package/dist/server/utils.js +22 -2
- package/dist/swagger/index.d.ts +814 -62
- package/dist/swagger/index.js +975 -205
- package/package.json +4 -3
- package/dist/client/27bd65abee87cafa.js +0 -10
- package/dist/client/80d4cd8911e03c27.js +0 -10
- package/dist/client/bfc2a351589613e1.js +0 -10
- package/dist/client/e078314a62391f36.js +0 -10
|
@@ -0,0 +1,463 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
const Assert = require('@hapi/hoek/lib/assert');
|
|
4
|
+
const Clone = require('@hapi/hoek/lib/clone');
|
|
5
|
+
const EscapeHtml = require('@hapi/hoek/lib/escapeHtml');
|
|
6
|
+
const Formula = require('@sideway/formula');
|
|
7
|
+
|
|
8
|
+
const Common = require('./common');
|
|
9
|
+
const Errors = require('./errors');
|
|
10
|
+
const Ref = require('./ref');
|
|
11
|
+
|
|
12
|
+
|
|
13
|
+
const internals = {
|
|
14
|
+
symbol: Symbol('template'),
|
|
15
|
+
|
|
16
|
+
opens: new Array(1000).join('\u0000'),
|
|
17
|
+
closes: new Array(1000).join('\u0001'),
|
|
18
|
+
|
|
19
|
+
dateFormat: {
|
|
20
|
+
date: Date.prototype.toDateString,
|
|
21
|
+
iso: Date.prototype.toISOString,
|
|
22
|
+
string: Date.prototype.toString,
|
|
23
|
+
time: Date.prototype.toTimeString,
|
|
24
|
+
utc: Date.prototype.toUTCString
|
|
25
|
+
}
|
|
26
|
+
};
|
|
27
|
+
|
|
28
|
+
|
|
29
|
+
module.exports = exports = internals.Template = class {
|
|
30
|
+
|
|
31
|
+
constructor(source, options) {
|
|
32
|
+
|
|
33
|
+
Assert(typeof source === 'string', 'Template source must be a string');
|
|
34
|
+
Assert(!source.includes('\u0000') && !source.includes('\u0001'), 'Template source cannot contain reserved control characters');
|
|
35
|
+
|
|
36
|
+
this.source = source;
|
|
37
|
+
this.rendered = source;
|
|
38
|
+
|
|
39
|
+
this._template = null;
|
|
40
|
+
|
|
41
|
+
if (options) {
|
|
42
|
+
const { functions, ...opts } = options;
|
|
43
|
+
this._settings = Object.keys(opts).length ? Clone(opts) : undefined;
|
|
44
|
+
this._functions = functions;
|
|
45
|
+
if (this._functions) {
|
|
46
|
+
Assert(Object.keys(this._functions).every((key) => typeof key === 'string'), 'Functions keys must be strings');
|
|
47
|
+
Assert(Object.values(this._functions).every((key) => typeof key === 'function'), 'Functions values must be functions');
|
|
48
|
+
}
|
|
49
|
+
}
|
|
50
|
+
else {
|
|
51
|
+
this._settings = undefined;
|
|
52
|
+
this._functions = undefined;
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
this._parse();
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
_parse() {
|
|
59
|
+
|
|
60
|
+
// 'text {raw} {{ref}} \\{{ignore}} {{ignore\\}} {{ignore {{ignore}'
|
|
61
|
+
|
|
62
|
+
if (!this.source.includes('{')) {
|
|
63
|
+
return;
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
// Encode escaped \\{{{{{
|
|
67
|
+
|
|
68
|
+
const encoded = internals.encode(this.source);
|
|
69
|
+
|
|
70
|
+
// Split on first { in each set
|
|
71
|
+
|
|
72
|
+
const parts = internals.split(encoded);
|
|
73
|
+
|
|
74
|
+
// Process parts
|
|
75
|
+
|
|
76
|
+
let refs = false;
|
|
77
|
+
const processed = [];
|
|
78
|
+
const head = parts.shift();
|
|
79
|
+
if (head) {
|
|
80
|
+
processed.push(head);
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
for (const part of parts) {
|
|
84
|
+
const raw = part[0] !== '{';
|
|
85
|
+
const ender = raw ? '}' : '}}';
|
|
86
|
+
const end = part.indexOf(ender);
|
|
87
|
+
if (end === -1 || // Ignore non-matching closing
|
|
88
|
+
part[1] === '{') { // Ignore more than two {
|
|
89
|
+
|
|
90
|
+
processed.push(`{${internals.decode(part)}`);
|
|
91
|
+
continue;
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
let variable = part.slice(raw ? 0 : 1, end);
|
|
95
|
+
const wrapped = variable[0] === ':';
|
|
96
|
+
if (wrapped) {
|
|
97
|
+
variable = variable.slice(1);
|
|
98
|
+
}
|
|
99
|
+
|
|
100
|
+
const dynamic = this._ref(internals.decode(variable), { raw, wrapped });
|
|
101
|
+
processed.push(dynamic);
|
|
102
|
+
if (typeof dynamic !== 'string') {
|
|
103
|
+
refs = true;
|
|
104
|
+
}
|
|
105
|
+
|
|
106
|
+
const rest = part.slice(end + ender.length);
|
|
107
|
+
if (rest) {
|
|
108
|
+
processed.push(internals.decode(rest));
|
|
109
|
+
}
|
|
110
|
+
}
|
|
111
|
+
|
|
112
|
+
if (!refs) {
|
|
113
|
+
this.rendered = processed.join('');
|
|
114
|
+
return;
|
|
115
|
+
}
|
|
116
|
+
|
|
117
|
+
this._template = processed;
|
|
118
|
+
}
|
|
119
|
+
|
|
120
|
+
static date(date, prefs) {
|
|
121
|
+
|
|
122
|
+
return internals.dateFormat[prefs.dateFormat].call(date);
|
|
123
|
+
}
|
|
124
|
+
|
|
125
|
+
describe(options = {}) {
|
|
126
|
+
|
|
127
|
+
if (!this._settings &&
|
|
128
|
+
options.compact) {
|
|
129
|
+
|
|
130
|
+
return this.source;
|
|
131
|
+
}
|
|
132
|
+
|
|
133
|
+
const desc = { template: this.source };
|
|
134
|
+
if (this._settings) {
|
|
135
|
+
desc.options = this._settings;
|
|
136
|
+
}
|
|
137
|
+
|
|
138
|
+
if (this._functions) {
|
|
139
|
+
desc.functions = this._functions;
|
|
140
|
+
}
|
|
141
|
+
|
|
142
|
+
return desc;
|
|
143
|
+
}
|
|
144
|
+
|
|
145
|
+
static build(desc) {
|
|
146
|
+
|
|
147
|
+
return new internals.Template(desc.template, desc.options || desc.functions ? { ...desc.options, functions: desc.functions } : undefined);
|
|
148
|
+
}
|
|
149
|
+
|
|
150
|
+
isDynamic() {
|
|
151
|
+
|
|
152
|
+
return !!this._template;
|
|
153
|
+
}
|
|
154
|
+
|
|
155
|
+
static isTemplate(template) {
|
|
156
|
+
|
|
157
|
+
return template ? !!template[Common.symbols.template] : false;
|
|
158
|
+
}
|
|
159
|
+
|
|
160
|
+
refs() {
|
|
161
|
+
|
|
162
|
+
if (!this._template) {
|
|
163
|
+
return;
|
|
164
|
+
}
|
|
165
|
+
|
|
166
|
+
const refs = [];
|
|
167
|
+
for (const part of this._template) {
|
|
168
|
+
if (typeof part !== 'string') {
|
|
169
|
+
refs.push(...part.refs);
|
|
170
|
+
}
|
|
171
|
+
}
|
|
172
|
+
|
|
173
|
+
return refs;
|
|
174
|
+
}
|
|
175
|
+
|
|
176
|
+
resolve(value, state, prefs, local) {
|
|
177
|
+
|
|
178
|
+
if (this._template &&
|
|
179
|
+
this._template.length === 1) {
|
|
180
|
+
|
|
181
|
+
return this._part(this._template[0], /* context -> [*/ value, state, prefs, local, {} /*] */);
|
|
182
|
+
}
|
|
183
|
+
|
|
184
|
+
return this.render(value, state, prefs, local);
|
|
185
|
+
}
|
|
186
|
+
|
|
187
|
+
_part(part, ...args) {
|
|
188
|
+
|
|
189
|
+
if (part.ref) {
|
|
190
|
+
return part.ref.resolve(...args);
|
|
191
|
+
}
|
|
192
|
+
|
|
193
|
+
return part.formula.evaluate(args);
|
|
194
|
+
}
|
|
195
|
+
|
|
196
|
+
render(value, state, prefs, local, options = {}) {
|
|
197
|
+
|
|
198
|
+
if (!this.isDynamic()) {
|
|
199
|
+
return this.rendered;
|
|
200
|
+
}
|
|
201
|
+
|
|
202
|
+
const parts = [];
|
|
203
|
+
for (const part of this._template) {
|
|
204
|
+
if (typeof part === 'string') {
|
|
205
|
+
parts.push(part);
|
|
206
|
+
}
|
|
207
|
+
else {
|
|
208
|
+
const rendered = this._part(part, /* context -> [*/ value, state, prefs, local, options /*] */);
|
|
209
|
+
const string = internals.stringify(rendered, value, state, prefs, local, options);
|
|
210
|
+
if (string !== undefined) {
|
|
211
|
+
const result = part.raw || (options.errors && options.errors.escapeHtml) === false ? string : EscapeHtml(string);
|
|
212
|
+
parts.push(internals.wrap(result, part.wrapped && prefs.errors.wrap.label));
|
|
213
|
+
}
|
|
214
|
+
}
|
|
215
|
+
}
|
|
216
|
+
|
|
217
|
+
return parts.join('');
|
|
218
|
+
}
|
|
219
|
+
|
|
220
|
+
_ref(content, { raw, wrapped }) {
|
|
221
|
+
|
|
222
|
+
const refs = [];
|
|
223
|
+
const reference = (variable) => {
|
|
224
|
+
|
|
225
|
+
const ref = Ref.create(variable, this._settings);
|
|
226
|
+
refs.push(ref);
|
|
227
|
+
return (context) => {
|
|
228
|
+
|
|
229
|
+
const resolved = ref.resolve(...context);
|
|
230
|
+
return resolved !== undefined ? resolved : null;
|
|
231
|
+
};
|
|
232
|
+
};
|
|
233
|
+
|
|
234
|
+
try {
|
|
235
|
+
const functions = this._functions ? { ...internals.functions, ...this._functions } : internals.functions;
|
|
236
|
+
var formula = new Formula.Parser(content, { reference, functions, constants: internals.constants });
|
|
237
|
+
}
|
|
238
|
+
catch (err) {
|
|
239
|
+
err.message = `Invalid template variable "${content}" fails due to: ${err.message}`;
|
|
240
|
+
throw err;
|
|
241
|
+
}
|
|
242
|
+
|
|
243
|
+
if (formula.single) {
|
|
244
|
+
if (formula.single.type === 'reference') {
|
|
245
|
+
const ref = refs[0];
|
|
246
|
+
return { ref, raw, refs, wrapped: wrapped || ref.type === 'local' && ref.key === 'label' };
|
|
247
|
+
}
|
|
248
|
+
|
|
249
|
+
return internals.stringify(formula.single.value);
|
|
250
|
+
}
|
|
251
|
+
|
|
252
|
+
return { formula, raw, refs };
|
|
253
|
+
}
|
|
254
|
+
|
|
255
|
+
toString() {
|
|
256
|
+
|
|
257
|
+
return this.source;
|
|
258
|
+
}
|
|
259
|
+
};
|
|
260
|
+
|
|
261
|
+
|
|
262
|
+
internals.Template.prototype[Common.symbols.template] = true;
|
|
263
|
+
internals.Template.prototype.isImmutable = true; // Prevents Hoek from deep cloning schema objects
|
|
264
|
+
|
|
265
|
+
|
|
266
|
+
internals.encode = function (string) {
|
|
267
|
+
|
|
268
|
+
return string
|
|
269
|
+
.replace(/\\(\{+)/g, ($0, $1) => {
|
|
270
|
+
|
|
271
|
+
return internals.opens.slice(0, $1.length);
|
|
272
|
+
})
|
|
273
|
+
.replace(/\\(\}+)/g, ($0, $1) => {
|
|
274
|
+
|
|
275
|
+
return internals.closes.slice(0, $1.length);
|
|
276
|
+
});
|
|
277
|
+
};
|
|
278
|
+
|
|
279
|
+
|
|
280
|
+
internals.decode = function (string) {
|
|
281
|
+
|
|
282
|
+
return string
|
|
283
|
+
.replace(/\u0000/g, '{')
|
|
284
|
+
.replace(/\u0001/g, '}');
|
|
285
|
+
};
|
|
286
|
+
|
|
287
|
+
|
|
288
|
+
internals.split = function (string) {
|
|
289
|
+
|
|
290
|
+
const parts = [];
|
|
291
|
+
let current = '';
|
|
292
|
+
|
|
293
|
+
for (let i = 0; i < string.length; ++i) {
|
|
294
|
+
const char = string[i];
|
|
295
|
+
|
|
296
|
+
if (char === '{') {
|
|
297
|
+
let next = '';
|
|
298
|
+
while (i + 1 < string.length &&
|
|
299
|
+
string[i + 1] === '{') {
|
|
300
|
+
|
|
301
|
+
next += '{';
|
|
302
|
+
++i;
|
|
303
|
+
}
|
|
304
|
+
|
|
305
|
+
parts.push(current);
|
|
306
|
+
current = next;
|
|
307
|
+
}
|
|
308
|
+
else {
|
|
309
|
+
current += char;
|
|
310
|
+
}
|
|
311
|
+
}
|
|
312
|
+
|
|
313
|
+
parts.push(current);
|
|
314
|
+
return parts;
|
|
315
|
+
};
|
|
316
|
+
|
|
317
|
+
|
|
318
|
+
internals.wrap = function (value, ends) {
|
|
319
|
+
|
|
320
|
+
if (!ends) {
|
|
321
|
+
return value;
|
|
322
|
+
}
|
|
323
|
+
|
|
324
|
+
if (ends.length === 1) {
|
|
325
|
+
return `${ends}${value}${ends}`;
|
|
326
|
+
}
|
|
327
|
+
|
|
328
|
+
return `${ends[0]}${value}${ends[1]}`;
|
|
329
|
+
};
|
|
330
|
+
|
|
331
|
+
|
|
332
|
+
internals.stringify = function (value, original, state, prefs, local, options = {}) {
|
|
333
|
+
|
|
334
|
+
const type = typeof value;
|
|
335
|
+
const wrap = prefs && prefs.errors && prefs.errors.wrap || {};
|
|
336
|
+
|
|
337
|
+
let skipWrap = false;
|
|
338
|
+
if (Ref.isRef(value) &&
|
|
339
|
+
value.render) {
|
|
340
|
+
|
|
341
|
+
skipWrap = value.in;
|
|
342
|
+
value = value.resolve(original, state, prefs, local, { in: value.in, ...options });
|
|
343
|
+
}
|
|
344
|
+
|
|
345
|
+
if (value === null) {
|
|
346
|
+
return 'null';
|
|
347
|
+
}
|
|
348
|
+
|
|
349
|
+
if (type === 'string') {
|
|
350
|
+
return internals.wrap(value, options.arrayItems && wrap.string);
|
|
351
|
+
}
|
|
352
|
+
|
|
353
|
+
if (type === 'number' ||
|
|
354
|
+
type === 'function' ||
|
|
355
|
+
type === 'symbol') {
|
|
356
|
+
|
|
357
|
+
return value.toString();
|
|
358
|
+
}
|
|
359
|
+
|
|
360
|
+
if (type !== 'object') {
|
|
361
|
+
return JSON.stringify(value);
|
|
362
|
+
}
|
|
363
|
+
|
|
364
|
+
if (value instanceof Date) {
|
|
365
|
+
return internals.Template.date(value, prefs);
|
|
366
|
+
}
|
|
367
|
+
|
|
368
|
+
if (value instanceof Map) {
|
|
369
|
+
const pairs = [];
|
|
370
|
+
for (const [key, sym] of value.entries()) {
|
|
371
|
+
pairs.push(`${key.toString()} -> ${sym.toString()}`);
|
|
372
|
+
}
|
|
373
|
+
|
|
374
|
+
value = pairs;
|
|
375
|
+
}
|
|
376
|
+
|
|
377
|
+
if (!Array.isArray(value)) {
|
|
378
|
+
return value.toString();
|
|
379
|
+
}
|
|
380
|
+
|
|
381
|
+
const values = [];
|
|
382
|
+
for (const item of value) {
|
|
383
|
+
values.push(internals.stringify(item, original, state, prefs, local, { arrayItems: true, ...options }));
|
|
384
|
+
}
|
|
385
|
+
|
|
386
|
+
return internals.wrap(values.join(', '), !skipWrap && wrap.array);
|
|
387
|
+
};
|
|
388
|
+
|
|
389
|
+
|
|
390
|
+
internals.constants = {
|
|
391
|
+
|
|
392
|
+
true: true,
|
|
393
|
+
false: false,
|
|
394
|
+
null: null,
|
|
395
|
+
|
|
396
|
+
second: 1000,
|
|
397
|
+
minute: 60 * 1000,
|
|
398
|
+
hour: 60 * 60 * 1000,
|
|
399
|
+
day: 24 * 60 * 60 * 1000
|
|
400
|
+
};
|
|
401
|
+
|
|
402
|
+
|
|
403
|
+
internals.functions = {
|
|
404
|
+
|
|
405
|
+
if(condition, then, otherwise) {
|
|
406
|
+
|
|
407
|
+
return condition ? then : otherwise;
|
|
408
|
+
},
|
|
409
|
+
|
|
410
|
+
length(item) {
|
|
411
|
+
|
|
412
|
+
if (typeof item === 'string') {
|
|
413
|
+
return item.length;
|
|
414
|
+
}
|
|
415
|
+
|
|
416
|
+
if (!item || typeof item !== 'object') {
|
|
417
|
+
return null;
|
|
418
|
+
}
|
|
419
|
+
|
|
420
|
+
if (Array.isArray(item)) {
|
|
421
|
+
return item.length;
|
|
422
|
+
}
|
|
423
|
+
|
|
424
|
+
return Object.keys(item).length;
|
|
425
|
+
},
|
|
426
|
+
|
|
427
|
+
msg(code) {
|
|
428
|
+
|
|
429
|
+
const [value, state, prefs, local, options] = this;
|
|
430
|
+
const messages = options.messages;
|
|
431
|
+
if (!messages) {
|
|
432
|
+
return '';
|
|
433
|
+
}
|
|
434
|
+
|
|
435
|
+
const template = Errors.template(value, messages[0], code, state, prefs) || Errors.template(value, messages[1], code, state, prefs);
|
|
436
|
+
if (!template) {
|
|
437
|
+
return '';
|
|
438
|
+
}
|
|
439
|
+
|
|
440
|
+
return template.render(value, state, prefs, local, options);
|
|
441
|
+
},
|
|
442
|
+
|
|
443
|
+
number(value) {
|
|
444
|
+
|
|
445
|
+
if (typeof value === 'number') {
|
|
446
|
+
return value;
|
|
447
|
+
}
|
|
448
|
+
|
|
449
|
+
if (typeof value === 'string') {
|
|
450
|
+
return parseFloat(value);
|
|
451
|
+
}
|
|
452
|
+
|
|
453
|
+
if (typeof value === 'boolean') {
|
|
454
|
+
return value ? 1 : 0;
|
|
455
|
+
}
|
|
456
|
+
|
|
457
|
+
if (value instanceof Date) {
|
|
458
|
+
return value.getTime();
|
|
459
|
+
}
|
|
460
|
+
|
|
461
|
+
return null;
|
|
462
|
+
}
|
|
463
|
+
};
|