@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,168 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
const Assert = require('@hapi/hoek/lib/assert');
|
|
4
|
+
|
|
5
|
+
const Any = require('./any');
|
|
6
|
+
const Common = require('../common');
|
|
7
|
+
const Compile = require('../compile');
|
|
8
|
+
const Errors = require('../errors');
|
|
9
|
+
|
|
10
|
+
|
|
11
|
+
const internals = {};
|
|
12
|
+
|
|
13
|
+
|
|
14
|
+
module.exports = Any.extend({
|
|
15
|
+
|
|
16
|
+
type: 'link',
|
|
17
|
+
|
|
18
|
+
properties: {
|
|
19
|
+
schemaChain: true
|
|
20
|
+
},
|
|
21
|
+
|
|
22
|
+
terms: {
|
|
23
|
+
|
|
24
|
+
link: { init: null, manifest: 'single', register: false }
|
|
25
|
+
},
|
|
26
|
+
|
|
27
|
+
args(schema, ref) {
|
|
28
|
+
|
|
29
|
+
return schema.ref(ref);
|
|
30
|
+
},
|
|
31
|
+
|
|
32
|
+
validate(value, { schema, state, prefs }) {
|
|
33
|
+
|
|
34
|
+
Assert(schema.$_terms.link, 'Uninitialized link schema');
|
|
35
|
+
|
|
36
|
+
const linked = internals.generate(schema, value, state, prefs);
|
|
37
|
+
const ref = schema.$_terms.link[0].ref;
|
|
38
|
+
return linked.$_validate(value, state.nest(linked, `link:${ref.display}:${linked.type}`), prefs);
|
|
39
|
+
},
|
|
40
|
+
|
|
41
|
+
generate(schema, value, state, prefs) {
|
|
42
|
+
|
|
43
|
+
return internals.generate(schema, value, state, prefs);
|
|
44
|
+
},
|
|
45
|
+
|
|
46
|
+
rules: {
|
|
47
|
+
|
|
48
|
+
ref: {
|
|
49
|
+
method(ref) {
|
|
50
|
+
|
|
51
|
+
Assert(!this.$_terms.link, 'Cannot reinitialize schema');
|
|
52
|
+
|
|
53
|
+
ref = Compile.ref(ref);
|
|
54
|
+
|
|
55
|
+
Assert(ref.type === 'value' || ref.type === 'local', 'Invalid reference type:', ref.type);
|
|
56
|
+
Assert(ref.type === 'local' || ref.ancestor === 'root' || ref.ancestor > 0, 'Link cannot reference itself');
|
|
57
|
+
|
|
58
|
+
const obj = this.clone();
|
|
59
|
+
obj.$_terms.link = [{ ref }];
|
|
60
|
+
return obj;
|
|
61
|
+
}
|
|
62
|
+
},
|
|
63
|
+
|
|
64
|
+
relative: {
|
|
65
|
+
method(enabled = true) {
|
|
66
|
+
|
|
67
|
+
return this.$_setFlag('relative', enabled);
|
|
68
|
+
}
|
|
69
|
+
}
|
|
70
|
+
},
|
|
71
|
+
|
|
72
|
+
overrides: {
|
|
73
|
+
|
|
74
|
+
concat(source) {
|
|
75
|
+
|
|
76
|
+
Assert(this.$_terms.link, 'Uninitialized link schema');
|
|
77
|
+
Assert(Common.isSchema(source), 'Invalid schema object');
|
|
78
|
+
Assert(source.type !== 'link', 'Cannot merge type link with another link');
|
|
79
|
+
|
|
80
|
+
const obj = this.clone();
|
|
81
|
+
|
|
82
|
+
if (!obj.$_terms.whens) {
|
|
83
|
+
obj.$_terms.whens = [];
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
obj.$_terms.whens.push({ concat: source });
|
|
87
|
+
return obj.$_mutateRebuild();
|
|
88
|
+
}
|
|
89
|
+
},
|
|
90
|
+
|
|
91
|
+
manifest: {
|
|
92
|
+
|
|
93
|
+
build(obj, desc) {
|
|
94
|
+
|
|
95
|
+
Assert(desc.link, 'Invalid link description missing link');
|
|
96
|
+
return obj.ref(desc.link);
|
|
97
|
+
}
|
|
98
|
+
}
|
|
99
|
+
});
|
|
100
|
+
|
|
101
|
+
|
|
102
|
+
// Helpers
|
|
103
|
+
|
|
104
|
+
internals.generate = function (schema, value, state, prefs) {
|
|
105
|
+
|
|
106
|
+
let linked = state.mainstay.links.get(schema);
|
|
107
|
+
if (linked) {
|
|
108
|
+
return linked._generate(value, state, prefs).schema;
|
|
109
|
+
}
|
|
110
|
+
|
|
111
|
+
const ref = schema.$_terms.link[0].ref;
|
|
112
|
+
const { perspective, path } = internals.perspective(ref, state);
|
|
113
|
+
internals.assert(perspective, 'which is outside of schema boundaries', ref, schema, state, prefs);
|
|
114
|
+
|
|
115
|
+
try {
|
|
116
|
+
linked = path.length ? perspective.$_reach(path) : perspective;
|
|
117
|
+
}
|
|
118
|
+
catch (ignoreErr) {
|
|
119
|
+
internals.assert(false, 'to non-existing schema', ref, schema, state, prefs);
|
|
120
|
+
}
|
|
121
|
+
|
|
122
|
+
internals.assert(linked.type !== 'link', 'which is another link', ref, schema, state, prefs);
|
|
123
|
+
|
|
124
|
+
if (!schema._flags.relative) {
|
|
125
|
+
state.mainstay.links.set(schema, linked);
|
|
126
|
+
}
|
|
127
|
+
|
|
128
|
+
return linked._generate(value, state, prefs).schema;
|
|
129
|
+
};
|
|
130
|
+
|
|
131
|
+
|
|
132
|
+
internals.perspective = function (ref, state) {
|
|
133
|
+
|
|
134
|
+
if (ref.type === 'local') {
|
|
135
|
+
for (const { schema, key } of state.schemas) { // From parent to root
|
|
136
|
+
const id = schema._flags.id || key;
|
|
137
|
+
if (id === ref.path[0]) {
|
|
138
|
+
return { perspective: schema, path: ref.path.slice(1) };
|
|
139
|
+
}
|
|
140
|
+
|
|
141
|
+
if (schema.$_terms.shared) {
|
|
142
|
+
for (const shared of schema.$_terms.shared) {
|
|
143
|
+
if (shared._flags.id === ref.path[0]) {
|
|
144
|
+
return { perspective: shared, path: ref.path.slice(1) };
|
|
145
|
+
}
|
|
146
|
+
}
|
|
147
|
+
}
|
|
148
|
+
}
|
|
149
|
+
|
|
150
|
+
return { perspective: null, path: null };
|
|
151
|
+
}
|
|
152
|
+
|
|
153
|
+
if (ref.ancestor === 'root') {
|
|
154
|
+
return { perspective: state.schemas[state.schemas.length - 1].schema, path: ref.path };
|
|
155
|
+
}
|
|
156
|
+
|
|
157
|
+
return { perspective: state.schemas[ref.ancestor] && state.schemas[ref.ancestor].schema, path: ref.path };
|
|
158
|
+
};
|
|
159
|
+
|
|
160
|
+
|
|
161
|
+
internals.assert = function (condition, message, ref, schema, state, prefs) {
|
|
162
|
+
|
|
163
|
+
if (condition) { // Manual check to avoid generating error message on success
|
|
164
|
+
return;
|
|
165
|
+
}
|
|
166
|
+
|
|
167
|
+
Assert(false, `"${Errors.label(schema._flags, state, prefs)}" contains link reference "${ref.display}" ${message}`);
|
|
168
|
+
};
|
|
@@ -0,0 +1,363 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
const Assert = require('@hapi/hoek/lib/assert');
|
|
4
|
+
|
|
5
|
+
const Any = require('./any');
|
|
6
|
+
const Common = require('../common');
|
|
7
|
+
|
|
8
|
+
|
|
9
|
+
const internals = {
|
|
10
|
+
numberRx: /^\s*[+-]?(?:(?:\d+(?:\.\d*)?)|(?:\.\d+))(?:e([+-]?\d+))?\s*$/i,
|
|
11
|
+
precisionRx: /(?:\.(\d+))?(?:[eE]([+-]?\d+))?$/,
|
|
12
|
+
exponentialPartRegex: /[eE][+-]?\d+$/,
|
|
13
|
+
leadingSignAndZerosRegex: /^[+-]?(0*)?/,
|
|
14
|
+
dotRegex: /\./,
|
|
15
|
+
trailingZerosRegex: /0+$/,
|
|
16
|
+
decimalPlaces(value) {
|
|
17
|
+
|
|
18
|
+
const str = value.toString();
|
|
19
|
+
const dindex = str.indexOf('.');
|
|
20
|
+
const eindex = str.indexOf('e');
|
|
21
|
+
return (
|
|
22
|
+
(dindex < 0 ? 0 : (eindex < 0 ? str.length : eindex) - dindex - 1) +
|
|
23
|
+
(eindex < 0 ? 0 : Math.max(0, -parseInt(str.slice(eindex + 1))))
|
|
24
|
+
);
|
|
25
|
+
}
|
|
26
|
+
};
|
|
27
|
+
|
|
28
|
+
|
|
29
|
+
module.exports = Any.extend({
|
|
30
|
+
|
|
31
|
+
type: 'number',
|
|
32
|
+
|
|
33
|
+
flags: {
|
|
34
|
+
|
|
35
|
+
unsafe: { default: false }
|
|
36
|
+
},
|
|
37
|
+
|
|
38
|
+
coerce: {
|
|
39
|
+
from: 'string',
|
|
40
|
+
method(value, { schema, error }) {
|
|
41
|
+
|
|
42
|
+
const matches = value.match(internals.numberRx);
|
|
43
|
+
if (!matches) {
|
|
44
|
+
return;
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
value = value.trim();
|
|
48
|
+
const result = { value: parseFloat(value) };
|
|
49
|
+
|
|
50
|
+
if (result.value === 0) {
|
|
51
|
+
result.value = 0; // -0
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
if (!schema._flags.unsafe) {
|
|
55
|
+
if (value.match(/e/i)) {
|
|
56
|
+
if (internals.extractSignificantDigits(value) !== internals.extractSignificantDigits(String(result.value))) {
|
|
57
|
+
result.errors = error('number.unsafe');
|
|
58
|
+
return result;
|
|
59
|
+
}
|
|
60
|
+
}
|
|
61
|
+
else {
|
|
62
|
+
const string = result.value.toString();
|
|
63
|
+
if (string.match(/e/i)) {
|
|
64
|
+
return result;
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
if (string !== internals.normalizeDecimal(value)) {
|
|
68
|
+
result.errors = error('number.unsafe');
|
|
69
|
+
return result;
|
|
70
|
+
}
|
|
71
|
+
}
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
return result;
|
|
75
|
+
}
|
|
76
|
+
},
|
|
77
|
+
|
|
78
|
+
validate(value, { schema, error, prefs }) {
|
|
79
|
+
|
|
80
|
+
if (value === Infinity ||
|
|
81
|
+
value === -Infinity) {
|
|
82
|
+
|
|
83
|
+
return { value, errors: error('number.infinity') };
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
if (!Common.isNumber(value)) {
|
|
87
|
+
return { value, errors: error('number.base') };
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
const result = { value };
|
|
91
|
+
|
|
92
|
+
if (prefs.convert) {
|
|
93
|
+
const rule = schema.$_getRule('precision');
|
|
94
|
+
if (rule) {
|
|
95
|
+
const precision = Math.pow(10, rule.args.limit); // This is conceptually equivalent to using toFixed but it should be much faster
|
|
96
|
+
result.value = Math.round(result.value * precision) / precision;
|
|
97
|
+
}
|
|
98
|
+
}
|
|
99
|
+
|
|
100
|
+
if (result.value === 0) {
|
|
101
|
+
result.value = 0; // -0
|
|
102
|
+
}
|
|
103
|
+
|
|
104
|
+
if (!schema._flags.unsafe &&
|
|
105
|
+
(value > Number.MAX_SAFE_INTEGER || value < Number.MIN_SAFE_INTEGER)) {
|
|
106
|
+
|
|
107
|
+
result.errors = error('number.unsafe');
|
|
108
|
+
}
|
|
109
|
+
|
|
110
|
+
return result;
|
|
111
|
+
},
|
|
112
|
+
|
|
113
|
+
rules: {
|
|
114
|
+
|
|
115
|
+
compare: {
|
|
116
|
+
method: false,
|
|
117
|
+
validate(value, helpers, { limit }, { name, operator, args }) {
|
|
118
|
+
|
|
119
|
+
if (Common.compare(value, limit, operator)) {
|
|
120
|
+
return value;
|
|
121
|
+
}
|
|
122
|
+
|
|
123
|
+
return helpers.error('number.' + name, { limit: args.limit, value });
|
|
124
|
+
},
|
|
125
|
+
args: [
|
|
126
|
+
{
|
|
127
|
+
name: 'limit',
|
|
128
|
+
ref: true,
|
|
129
|
+
assert: Common.isNumber,
|
|
130
|
+
message: 'must be a number'
|
|
131
|
+
}
|
|
132
|
+
]
|
|
133
|
+
},
|
|
134
|
+
|
|
135
|
+
greater: {
|
|
136
|
+
method(limit) {
|
|
137
|
+
|
|
138
|
+
return this.$_addRule({ name: 'greater', method: 'compare', args: { limit }, operator: '>' });
|
|
139
|
+
}
|
|
140
|
+
},
|
|
141
|
+
|
|
142
|
+
integer: {
|
|
143
|
+
method() {
|
|
144
|
+
|
|
145
|
+
return this.$_addRule('integer');
|
|
146
|
+
},
|
|
147
|
+
validate(value, helpers) {
|
|
148
|
+
|
|
149
|
+
if (Math.trunc(value) - value === 0) {
|
|
150
|
+
return value;
|
|
151
|
+
}
|
|
152
|
+
|
|
153
|
+
return helpers.error('number.integer');
|
|
154
|
+
}
|
|
155
|
+
},
|
|
156
|
+
|
|
157
|
+
less: {
|
|
158
|
+
method(limit) {
|
|
159
|
+
|
|
160
|
+
return this.$_addRule({ name: 'less', method: 'compare', args: { limit }, operator: '<' });
|
|
161
|
+
}
|
|
162
|
+
},
|
|
163
|
+
|
|
164
|
+
max: {
|
|
165
|
+
method(limit) {
|
|
166
|
+
|
|
167
|
+
return this.$_addRule({ name: 'max', method: 'compare', args: { limit }, operator: '<=' });
|
|
168
|
+
}
|
|
169
|
+
},
|
|
170
|
+
|
|
171
|
+
min: {
|
|
172
|
+
method(limit) {
|
|
173
|
+
|
|
174
|
+
return this.$_addRule({ name: 'min', method: 'compare', args: { limit }, operator: '>=' });
|
|
175
|
+
}
|
|
176
|
+
},
|
|
177
|
+
|
|
178
|
+
multiple: {
|
|
179
|
+
method(base) {
|
|
180
|
+
|
|
181
|
+
const baseDecimalPlace = typeof base === 'number' ? internals.decimalPlaces(base) : null;
|
|
182
|
+
const pfactor = Math.pow(10, baseDecimalPlace);
|
|
183
|
+
|
|
184
|
+
return this.$_addRule({
|
|
185
|
+
name: 'multiple',
|
|
186
|
+
args: {
|
|
187
|
+
base,
|
|
188
|
+
baseDecimalPlace,
|
|
189
|
+
pfactor
|
|
190
|
+
}
|
|
191
|
+
});
|
|
192
|
+
},
|
|
193
|
+
validate(value, helpers, { base, baseDecimalPlace, pfactor }, options) {
|
|
194
|
+
|
|
195
|
+
const valueDecimalPlace = internals.decimalPlaces(value);
|
|
196
|
+
|
|
197
|
+
if (valueDecimalPlace > baseDecimalPlace) {
|
|
198
|
+
// Value with higher precision than base can never be a multiple
|
|
199
|
+
return helpers.error('number.multiple', { multiple: options.args.base, value });
|
|
200
|
+
}
|
|
201
|
+
|
|
202
|
+
return Math.round(pfactor * value) % Math.round(pfactor * base) === 0 ?
|
|
203
|
+
value :
|
|
204
|
+
helpers.error('number.multiple', { multiple: options.args.base, value });
|
|
205
|
+
},
|
|
206
|
+
args: [
|
|
207
|
+
{
|
|
208
|
+
name: 'base',
|
|
209
|
+
ref: true,
|
|
210
|
+
assert: (value) => typeof value === 'number' && isFinite(value) && value > 0,
|
|
211
|
+
message: 'must be a positive number'
|
|
212
|
+
},
|
|
213
|
+
'baseDecimalPlace',
|
|
214
|
+
'pfactor'
|
|
215
|
+
],
|
|
216
|
+
multi: true
|
|
217
|
+
},
|
|
218
|
+
|
|
219
|
+
negative: {
|
|
220
|
+
method() {
|
|
221
|
+
|
|
222
|
+
return this.sign('negative');
|
|
223
|
+
}
|
|
224
|
+
},
|
|
225
|
+
|
|
226
|
+
port: {
|
|
227
|
+
method() {
|
|
228
|
+
|
|
229
|
+
return this.$_addRule('port');
|
|
230
|
+
},
|
|
231
|
+
validate(value, helpers) {
|
|
232
|
+
|
|
233
|
+
if (Number.isSafeInteger(value) &&
|
|
234
|
+
value >= 0 &&
|
|
235
|
+
value <= 65535) {
|
|
236
|
+
|
|
237
|
+
return value;
|
|
238
|
+
}
|
|
239
|
+
|
|
240
|
+
return helpers.error('number.port');
|
|
241
|
+
}
|
|
242
|
+
},
|
|
243
|
+
|
|
244
|
+
positive: {
|
|
245
|
+
method() {
|
|
246
|
+
|
|
247
|
+
return this.sign('positive');
|
|
248
|
+
}
|
|
249
|
+
},
|
|
250
|
+
|
|
251
|
+
precision: {
|
|
252
|
+
method(limit) {
|
|
253
|
+
|
|
254
|
+
Assert(Number.isSafeInteger(limit), 'limit must be an integer');
|
|
255
|
+
|
|
256
|
+
return this.$_addRule({ name: 'precision', args: { limit } });
|
|
257
|
+
},
|
|
258
|
+
validate(value, helpers, { limit }) {
|
|
259
|
+
|
|
260
|
+
const places = value.toString().match(internals.precisionRx);
|
|
261
|
+
const decimals = Math.max((places[1] ? places[1].length : 0) - (places[2] ? parseInt(places[2], 10) : 0), 0);
|
|
262
|
+
if (decimals <= limit) {
|
|
263
|
+
return value;
|
|
264
|
+
}
|
|
265
|
+
|
|
266
|
+
return helpers.error('number.precision', { limit, value });
|
|
267
|
+
},
|
|
268
|
+
convert: true
|
|
269
|
+
},
|
|
270
|
+
|
|
271
|
+
sign: {
|
|
272
|
+
method(sign) {
|
|
273
|
+
|
|
274
|
+
Assert(['negative', 'positive'].includes(sign), 'Invalid sign', sign);
|
|
275
|
+
|
|
276
|
+
return this.$_addRule({ name: 'sign', args: { sign } });
|
|
277
|
+
},
|
|
278
|
+
validate(value, helpers, { sign }) {
|
|
279
|
+
|
|
280
|
+
if (sign === 'negative' && value < 0 ||
|
|
281
|
+
sign === 'positive' && value > 0) {
|
|
282
|
+
|
|
283
|
+
return value;
|
|
284
|
+
}
|
|
285
|
+
|
|
286
|
+
return helpers.error(`number.${sign}`);
|
|
287
|
+
}
|
|
288
|
+
},
|
|
289
|
+
|
|
290
|
+
unsafe: {
|
|
291
|
+
method(enabled = true) {
|
|
292
|
+
|
|
293
|
+
Assert(typeof enabled === 'boolean', 'enabled must be a boolean');
|
|
294
|
+
|
|
295
|
+
return this.$_setFlag('unsafe', enabled);
|
|
296
|
+
}
|
|
297
|
+
}
|
|
298
|
+
},
|
|
299
|
+
|
|
300
|
+
cast: {
|
|
301
|
+
string: {
|
|
302
|
+
from: (value) => typeof value === 'number',
|
|
303
|
+
to(value, helpers) {
|
|
304
|
+
|
|
305
|
+
return value.toString();
|
|
306
|
+
}
|
|
307
|
+
}
|
|
308
|
+
},
|
|
309
|
+
|
|
310
|
+
messages: {
|
|
311
|
+
'number.base': '{{#label}} must be a number',
|
|
312
|
+
'number.greater': '{{#label}} must be greater than {{#limit}}',
|
|
313
|
+
'number.infinity': '{{#label}} cannot be infinity',
|
|
314
|
+
'number.integer': '{{#label}} must be an integer',
|
|
315
|
+
'number.less': '{{#label}} must be less than {{#limit}}',
|
|
316
|
+
'number.max': '{{#label}} must be less than or equal to {{#limit}}',
|
|
317
|
+
'number.min': '{{#label}} must be greater than or equal to {{#limit}}',
|
|
318
|
+
'number.multiple': '{{#label}} must be a multiple of {{#multiple}}',
|
|
319
|
+
'number.negative': '{{#label}} must be a negative number',
|
|
320
|
+
'number.port': '{{#label}} must be a valid port',
|
|
321
|
+
'number.positive': '{{#label}} must be a positive number',
|
|
322
|
+
'number.precision': '{{#label}} must have no more than {{#limit}} decimal places',
|
|
323
|
+
'number.unsafe': '{{#label}} must be a safe number'
|
|
324
|
+
}
|
|
325
|
+
});
|
|
326
|
+
|
|
327
|
+
|
|
328
|
+
// Helpers
|
|
329
|
+
|
|
330
|
+
internals.extractSignificantDigits = function (value) {
|
|
331
|
+
|
|
332
|
+
return value
|
|
333
|
+
.replace(internals.exponentialPartRegex, '')
|
|
334
|
+
.replace(internals.dotRegex, '')
|
|
335
|
+
.replace(internals.trailingZerosRegex, '')
|
|
336
|
+
.replace(internals.leadingSignAndZerosRegex, '');
|
|
337
|
+
};
|
|
338
|
+
|
|
339
|
+
|
|
340
|
+
internals.normalizeDecimal = function (str) {
|
|
341
|
+
|
|
342
|
+
str = str
|
|
343
|
+
// Remove leading plus signs
|
|
344
|
+
.replace(/^\+/, '')
|
|
345
|
+
// Remove trailing zeros if there is a decimal point and unecessary decimal points
|
|
346
|
+
.replace(/\.0*$/, '')
|
|
347
|
+
// Add a integer 0 if the numbers starts with a decimal point
|
|
348
|
+
.replace(/^(-?)\.([^\.]*)$/, '$10.$2')
|
|
349
|
+
// Remove leading zeros
|
|
350
|
+
.replace(/^(-?)0+([0-9])/, '$1$2');
|
|
351
|
+
|
|
352
|
+
if (str.includes('.') &&
|
|
353
|
+
str.endsWith('0')) {
|
|
354
|
+
|
|
355
|
+
str = str.replace(/0+$/, '');
|
|
356
|
+
}
|
|
357
|
+
|
|
358
|
+
if (str === '-0') {
|
|
359
|
+
return '0';
|
|
360
|
+
}
|
|
361
|
+
|
|
362
|
+
return str;
|
|
363
|
+
};
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
const Keys = require('./keys');
|
|
4
|
+
|
|
5
|
+
|
|
6
|
+
const internals = {};
|
|
7
|
+
|
|
8
|
+
|
|
9
|
+
module.exports = Keys.extend({
|
|
10
|
+
|
|
11
|
+
type: 'object',
|
|
12
|
+
|
|
13
|
+
cast: {
|
|
14
|
+
map: {
|
|
15
|
+
from: (value) => value && typeof value === 'object',
|
|
16
|
+
to(value, helpers) {
|
|
17
|
+
|
|
18
|
+
return new Map(Object.entries(value));
|
|
19
|
+
}
|
|
20
|
+
}
|
|
21
|
+
}
|
|
22
|
+
});
|