@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,100 @@
|
|
|
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
|
+
|
|
11
|
+
|
|
12
|
+
module.exports = Any.extend({
|
|
13
|
+
|
|
14
|
+
type: 'binary',
|
|
15
|
+
|
|
16
|
+
coerce: {
|
|
17
|
+
from: ['string', 'object'],
|
|
18
|
+
method(value, { schema }) {
|
|
19
|
+
|
|
20
|
+
if (typeof value === 'string' || (value !== null && value.type === 'Buffer')) {
|
|
21
|
+
try {
|
|
22
|
+
return { value: Buffer.from(value, schema._flags.encoding) };
|
|
23
|
+
}
|
|
24
|
+
catch (ignoreErr) { }
|
|
25
|
+
}
|
|
26
|
+
}
|
|
27
|
+
},
|
|
28
|
+
|
|
29
|
+
validate(value, { error }) {
|
|
30
|
+
|
|
31
|
+
if (!Buffer.isBuffer(value)) {
|
|
32
|
+
return { value, errors: error('binary.base') };
|
|
33
|
+
}
|
|
34
|
+
},
|
|
35
|
+
|
|
36
|
+
rules: {
|
|
37
|
+
encoding: {
|
|
38
|
+
method(encoding) {
|
|
39
|
+
|
|
40
|
+
Assert(Buffer.isEncoding(encoding), 'Invalid encoding:', encoding);
|
|
41
|
+
|
|
42
|
+
return this.$_setFlag('encoding', encoding);
|
|
43
|
+
}
|
|
44
|
+
},
|
|
45
|
+
|
|
46
|
+
length: {
|
|
47
|
+
method(limit) {
|
|
48
|
+
|
|
49
|
+
return this.$_addRule({ name: 'length', method: 'length', args: { limit }, operator: '=' });
|
|
50
|
+
},
|
|
51
|
+
validate(value, helpers, { limit }, { name, operator, args }) {
|
|
52
|
+
|
|
53
|
+
if (Common.compare(value.length, limit, operator)) {
|
|
54
|
+
return value;
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
return helpers.error('binary.' + name, { limit: args.limit, value });
|
|
58
|
+
},
|
|
59
|
+
args: [
|
|
60
|
+
{
|
|
61
|
+
name: 'limit',
|
|
62
|
+
ref: true,
|
|
63
|
+
assert: Common.limit,
|
|
64
|
+
message: 'must be a positive integer'
|
|
65
|
+
}
|
|
66
|
+
]
|
|
67
|
+
},
|
|
68
|
+
|
|
69
|
+
max: {
|
|
70
|
+
method(limit) {
|
|
71
|
+
|
|
72
|
+
return this.$_addRule({ name: 'max', method: 'length', args: { limit }, operator: '<=' });
|
|
73
|
+
}
|
|
74
|
+
},
|
|
75
|
+
|
|
76
|
+
min: {
|
|
77
|
+
method(limit) {
|
|
78
|
+
|
|
79
|
+
return this.$_addRule({ name: 'min', method: 'length', args: { limit }, operator: '>=' });
|
|
80
|
+
}
|
|
81
|
+
}
|
|
82
|
+
},
|
|
83
|
+
|
|
84
|
+
cast: {
|
|
85
|
+
string: {
|
|
86
|
+
from: (value) => Buffer.isBuffer(value),
|
|
87
|
+
to(value, helpers) {
|
|
88
|
+
|
|
89
|
+
return value.toString();
|
|
90
|
+
}
|
|
91
|
+
}
|
|
92
|
+
},
|
|
93
|
+
|
|
94
|
+
messages: {
|
|
95
|
+
'binary.base': '{{#label}} must be a buffer or a string',
|
|
96
|
+
'binary.length': '{{#label}} must be {{#limit}} bytes',
|
|
97
|
+
'binary.max': '{{#label}} must be less than or equal to {{#limit}} bytes',
|
|
98
|
+
'binary.min': '{{#label}} must be at least {{#limit}} bytes'
|
|
99
|
+
}
|
|
100
|
+
});
|
|
@@ -0,0 +1,150 @@
|
|
|
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 Values = require('../values');
|
|
8
|
+
|
|
9
|
+
|
|
10
|
+
const internals = {};
|
|
11
|
+
|
|
12
|
+
|
|
13
|
+
internals.isBool = function (value) {
|
|
14
|
+
|
|
15
|
+
return typeof value === 'boolean';
|
|
16
|
+
};
|
|
17
|
+
|
|
18
|
+
|
|
19
|
+
module.exports = Any.extend({
|
|
20
|
+
|
|
21
|
+
type: 'boolean',
|
|
22
|
+
|
|
23
|
+
flags: {
|
|
24
|
+
|
|
25
|
+
sensitive: { default: false }
|
|
26
|
+
},
|
|
27
|
+
|
|
28
|
+
terms: {
|
|
29
|
+
|
|
30
|
+
falsy: {
|
|
31
|
+
init: null,
|
|
32
|
+
manifest: 'values'
|
|
33
|
+
},
|
|
34
|
+
|
|
35
|
+
truthy: {
|
|
36
|
+
init: null,
|
|
37
|
+
manifest: 'values'
|
|
38
|
+
}
|
|
39
|
+
},
|
|
40
|
+
|
|
41
|
+
coerce(value, { schema }) {
|
|
42
|
+
|
|
43
|
+
if (typeof value === 'boolean') {
|
|
44
|
+
return;
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
if (typeof value === 'string') {
|
|
48
|
+
const normalized = schema._flags.sensitive ? value : value.toLowerCase();
|
|
49
|
+
value = normalized === 'true' ? true : (normalized === 'false' ? false : value);
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
if (typeof value !== 'boolean') {
|
|
53
|
+
value = schema.$_terms.truthy && schema.$_terms.truthy.has(value, null, null, !schema._flags.sensitive) ||
|
|
54
|
+
(schema.$_terms.falsy && schema.$_terms.falsy.has(value, null, null, !schema._flags.sensitive) ? false : value);
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
return { value };
|
|
58
|
+
},
|
|
59
|
+
|
|
60
|
+
validate(value, { error }) {
|
|
61
|
+
|
|
62
|
+
if (typeof value !== 'boolean') {
|
|
63
|
+
return { value, errors: error('boolean.base') };
|
|
64
|
+
}
|
|
65
|
+
},
|
|
66
|
+
|
|
67
|
+
rules: {
|
|
68
|
+
truthy: {
|
|
69
|
+
method(...values) {
|
|
70
|
+
|
|
71
|
+
Common.verifyFlat(values, 'truthy');
|
|
72
|
+
|
|
73
|
+
const obj = this.clone();
|
|
74
|
+
obj.$_terms.truthy = obj.$_terms.truthy || new Values();
|
|
75
|
+
|
|
76
|
+
for (let i = 0; i < values.length; ++i) {
|
|
77
|
+
const value = values[i];
|
|
78
|
+
|
|
79
|
+
Assert(value !== undefined, 'Cannot call truthy with undefined');
|
|
80
|
+
obj.$_terms.truthy.add(value);
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
return obj;
|
|
84
|
+
}
|
|
85
|
+
},
|
|
86
|
+
|
|
87
|
+
falsy: {
|
|
88
|
+
method(...values) {
|
|
89
|
+
|
|
90
|
+
Common.verifyFlat(values, 'falsy');
|
|
91
|
+
|
|
92
|
+
const obj = this.clone();
|
|
93
|
+
obj.$_terms.falsy = obj.$_terms.falsy || new Values();
|
|
94
|
+
|
|
95
|
+
for (let i = 0; i < values.length; ++i) {
|
|
96
|
+
const value = values[i];
|
|
97
|
+
|
|
98
|
+
Assert(value !== undefined, 'Cannot call falsy with undefined');
|
|
99
|
+
obj.$_terms.falsy.add(value);
|
|
100
|
+
}
|
|
101
|
+
|
|
102
|
+
return obj;
|
|
103
|
+
}
|
|
104
|
+
},
|
|
105
|
+
|
|
106
|
+
sensitive: {
|
|
107
|
+
method(enabled = true) {
|
|
108
|
+
|
|
109
|
+
return this.$_setFlag('sensitive', enabled);
|
|
110
|
+
}
|
|
111
|
+
}
|
|
112
|
+
},
|
|
113
|
+
|
|
114
|
+
cast: {
|
|
115
|
+
number: {
|
|
116
|
+
from: internals.isBool,
|
|
117
|
+
to(value, helpers) {
|
|
118
|
+
|
|
119
|
+
return value ? 1 : 0;
|
|
120
|
+
}
|
|
121
|
+
},
|
|
122
|
+
string: {
|
|
123
|
+
from: internals.isBool,
|
|
124
|
+
to(value, helpers) {
|
|
125
|
+
|
|
126
|
+
return value ? 'true' : 'false';
|
|
127
|
+
}
|
|
128
|
+
}
|
|
129
|
+
},
|
|
130
|
+
|
|
131
|
+
manifest: {
|
|
132
|
+
|
|
133
|
+
build(obj, desc) {
|
|
134
|
+
|
|
135
|
+
if (desc.truthy) {
|
|
136
|
+
obj = obj.truthy(...desc.truthy);
|
|
137
|
+
}
|
|
138
|
+
|
|
139
|
+
if (desc.falsy) {
|
|
140
|
+
obj = obj.falsy(...desc.falsy);
|
|
141
|
+
}
|
|
142
|
+
|
|
143
|
+
return obj;
|
|
144
|
+
}
|
|
145
|
+
},
|
|
146
|
+
|
|
147
|
+
messages: {
|
|
148
|
+
'boolean.base': '{{#label}} must be a boolean'
|
|
149
|
+
}
|
|
150
|
+
});
|
|
@@ -0,0 +1,233 @@
|
|
|
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 Template = require('../template');
|
|
8
|
+
|
|
9
|
+
|
|
10
|
+
const internals = {};
|
|
11
|
+
|
|
12
|
+
|
|
13
|
+
internals.isDate = function (value) {
|
|
14
|
+
|
|
15
|
+
return value instanceof Date;
|
|
16
|
+
};
|
|
17
|
+
|
|
18
|
+
|
|
19
|
+
module.exports = Any.extend({
|
|
20
|
+
|
|
21
|
+
type: 'date',
|
|
22
|
+
|
|
23
|
+
coerce: {
|
|
24
|
+
from: ['number', 'string'],
|
|
25
|
+
method(value, { schema }) {
|
|
26
|
+
|
|
27
|
+
return { value: internals.parse(value, schema._flags.format) || value };
|
|
28
|
+
}
|
|
29
|
+
},
|
|
30
|
+
|
|
31
|
+
validate(value, { schema, error, prefs }) {
|
|
32
|
+
|
|
33
|
+
if (value instanceof Date &&
|
|
34
|
+
!isNaN(value.getTime())) {
|
|
35
|
+
|
|
36
|
+
return;
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
const format = schema._flags.format;
|
|
40
|
+
|
|
41
|
+
if (!prefs.convert ||
|
|
42
|
+
!format ||
|
|
43
|
+
typeof value !== 'string') {
|
|
44
|
+
|
|
45
|
+
return { value, errors: error('date.base') };
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
return { value, errors: error('date.format', { format }) };
|
|
49
|
+
},
|
|
50
|
+
|
|
51
|
+
rules: {
|
|
52
|
+
|
|
53
|
+
compare: {
|
|
54
|
+
method: false,
|
|
55
|
+
validate(value, helpers, { date }, { name, operator, args }) {
|
|
56
|
+
|
|
57
|
+
const to = date === 'now' ? Date.now() : date.getTime();
|
|
58
|
+
if (Common.compare(value.getTime(), to, operator)) {
|
|
59
|
+
return value;
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
return helpers.error('date.' + name, { limit: args.date, value });
|
|
63
|
+
},
|
|
64
|
+
args: [
|
|
65
|
+
{
|
|
66
|
+
name: 'date',
|
|
67
|
+
ref: true,
|
|
68
|
+
normalize: (date) => {
|
|
69
|
+
|
|
70
|
+
return date === 'now' ? date : internals.parse(date);
|
|
71
|
+
},
|
|
72
|
+
assert: (date) => date !== null,
|
|
73
|
+
message: 'must have a valid date format'
|
|
74
|
+
}
|
|
75
|
+
]
|
|
76
|
+
},
|
|
77
|
+
|
|
78
|
+
format: {
|
|
79
|
+
method(format) {
|
|
80
|
+
|
|
81
|
+
Assert(['iso', 'javascript', 'unix'].includes(format), 'Unknown date format', format);
|
|
82
|
+
|
|
83
|
+
return this.$_setFlag('format', format);
|
|
84
|
+
}
|
|
85
|
+
},
|
|
86
|
+
|
|
87
|
+
greater: {
|
|
88
|
+
method(date) {
|
|
89
|
+
|
|
90
|
+
return this.$_addRule({ name: 'greater', method: 'compare', args: { date }, operator: '>' });
|
|
91
|
+
}
|
|
92
|
+
},
|
|
93
|
+
|
|
94
|
+
iso: {
|
|
95
|
+
method() {
|
|
96
|
+
|
|
97
|
+
return this.format('iso');
|
|
98
|
+
}
|
|
99
|
+
},
|
|
100
|
+
|
|
101
|
+
less: {
|
|
102
|
+
method(date) {
|
|
103
|
+
|
|
104
|
+
return this.$_addRule({ name: 'less', method: 'compare', args: { date }, operator: '<' });
|
|
105
|
+
}
|
|
106
|
+
},
|
|
107
|
+
|
|
108
|
+
max: {
|
|
109
|
+
method(date) {
|
|
110
|
+
|
|
111
|
+
return this.$_addRule({ name: 'max', method: 'compare', args: { date }, operator: '<=' });
|
|
112
|
+
}
|
|
113
|
+
},
|
|
114
|
+
|
|
115
|
+
min: {
|
|
116
|
+
method(date) {
|
|
117
|
+
|
|
118
|
+
return this.$_addRule({ name: 'min', method: 'compare', args: { date }, operator: '>=' });
|
|
119
|
+
}
|
|
120
|
+
},
|
|
121
|
+
|
|
122
|
+
timestamp: {
|
|
123
|
+
method(type = 'javascript') {
|
|
124
|
+
|
|
125
|
+
Assert(['javascript', 'unix'].includes(type), '"type" must be one of "javascript, unix"');
|
|
126
|
+
|
|
127
|
+
return this.format(type);
|
|
128
|
+
}
|
|
129
|
+
}
|
|
130
|
+
},
|
|
131
|
+
|
|
132
|
+
cast: {
|
|
133
|
+
number: {
|
|
134
|
+
from: internals.isDate,
|
|
135
|
+
to(value, helpers) {
|
|
136
|
+
|
|
137
|
+
return value.getTime();
|
|
138
|
+
}
|
|
139
|
+
},
|
|
140
|
+
string: {
|
|
141
|
+
from: internals.isDate,
|
|
142
|
+
to(value, { prefs }) {
|
|
143
|
+
|
|
144
|
+
return Template.date(value, prefs);
|
|
145
|
+
}
|
|
146
|
+
}
|
|
147
|
+
},
|
|
148
|
+
|
|
149
|
+
messages: {
|
|
150
|
+
'date.base': '{{#label}} must be a valid date',
|
|
151
|
+
'date.format': '{{#label}} must be in {msg("date.format." + #format) || #format} format',
|
|
152
|
+
'date.greater': '{{#label}} must be greater than {{:#limit}}',
|
|
153
|
+
'date.less': '{{#label}} must be less than {{:#limit}}',
|
|
154
|
+
'date.max': '{{#label}} must be less than or equal to {{:#limit}}',
|
|
155
|
+
'date.min': '{{#label}} must be greater than or equal to {{:#limit}}',
|
|
156
|
+
|
|
157
|
+
// Messages used in date.format
|
|
158
|
+
|
|
159
|
+
'date.format.iso': 'ISO 8601 date',
|
|
160
|
+
'date.format.javascript': 'timestamp or number of milliseconds',
|
|
161
|
+
'date.format.unix': 'timestamp or number of seconds'
|
|
162
|
+
}
|
|
163
|
+
});
|
|
164
|
+
|
|
165
|
+
|
|
166
|
+
// Helpers
|
|
167
|
+
|
|
168
|
+
internals.parse = function (value, format) {
|
|
169
|
+
|
|
170
|
+
if (value instanceof Date) {
|
|
171
|
+
return value;
|
|
172
|
+
}
|
|
173
|
+
|
|
174
|
+
if (typeof value !== 'string' &&
|
|
175
|
+
(isNaN(value) || !isFinite(value))) {
|
|
176
|
+
|
|
177
|
+
return null;
|
|
178
|
+
}
|
|
179
|
+
|
|
180
|
+
if (/^\s*$/.test(value)) {
|
|
181
|
+
return null;
|
|
182
|
+
}
|
|
183
|
+
|
|
184
|
+
// ISO
|
|
185
|
+
|
|
186
|
+
if (format === 'iso') {
|
|
187
|
+
if (!Common.isIsoDate(value)) {
|
|
188
|
+
return null;
|
|
189
|
+
}
|
|
190
|
+
|
|
191
|
+
return internals.date(value.toString());
|
|
192
|
+
}
|
|
193
|
+
|
|
194
|
+
// Normalize number string
|
|
195
|
+
|
|
196
|
+
const original = value;
|
|
197
|
+
if (typeof value === 'string' &&
|
|
198
|
+
/^[+-]?\d+(\.\d+)?$/.test(value)) {
|
|
199
|
+
|
|
200
|
+
value = parseFloat(value);
|
|
201
|
+
}
|
|
202
|
+
|
|
203
|
+
// Timestamp
|
|
204
|
+
|
|
205
|
+
if (format) {
|
|
206
|
+
if (format === 'javascript') {
|
|
207
|
+
return internals.date(1 * value); // Casting to number
|
|
208
|
+
}
|
|
209
|
+
|
|
210
|
+
if (format === 'unix') {
|
|
211
|
+
return internals.date(1000 * value);
|
|
212
|
+
}
|
|
213
|
+
|
|
214
|
+
if (typeof original === 'string') {
|
|
215
|
+
return null;
|
|
216
|
+
}
|
|
217
|
+
}
|
|
218
|
+
|
|
219
|
+
// Plain
|
|
220
|
+
|
|
221
|
+
return internals.date(value);
|
|
222
|
+
};
|
|
223
|
+
|
|
224
|
+
|
|
225
|
+
internals.date = function (value) {
|
|
226
|
+
|
|
227
|
+
const date = new Date(value);
|
|
228
|
+
if (!isNaN(date.getTime())) {
|
|
229
|
+
return date;
|
|
230
|
+
}
|
|
231
|
+
|
|
232
|
+
return null;
|
|
233
|
+
};
|
|
@@ -0,0 +1,93 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
const Assert = require('@hapi/hoek/lib/assert');
|
|
4
|
+
|
|
5
|
+
const Keys = require('./keys');
|
|
6
|
+
|
|
7
|
+
|
|
8
|
+
const internals = {};
|
|
9
|
+
|
|
10
|
+
|
|
11
|
+
module.exports = Keys.extend({
|
|
12
|
+
|
|
13
|
+
type: 'function',
|
|
14
|
+
|
|
15
|
+
properties: {
|
|
16
|
+
typeof: 'function'
|
|
17
|
+
},
|
|
18
|
+
|
|
19
|
+
rules: {
|
|
20
|
+
arity: {
|
|
21
|
+
method(n) {
|
|
22
|
+
|
|
23
|
+
Assert(Number.isSafeInteger(n) && n >= 0, 'n must be a positive integer');
|
|
24
|
+
|
|
25
|
+
return this.$_addRule({ name: 'arity', args: { n } });
|
|
26
|
+
},
|
|
27
|
+
validate(value, helpers, { n }) {
|
|
28
|
+
|
|
29
|
+
if (value.length === n) {
|
|
30
|
+
return value;
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
return helpers.error('function.arity', { n });
|
|
34
|
+
}
|
|
35
|
+
},
|
|
36
|
+
|
|
37
|
+
class: {
|
|
38
|
+
method() {
|
|
39
|
+
|
|
40
|
+
return this.$_addRule('class');
|
|
41
|
+
},
|
|
42
|
+
validate(value, helpers) {
|
|
43
|
+
|
|
44
|
+
if ((/^\s*class\s/).test(value.toString())) {
|
|
45
|
+
return value;
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
return helpers.error('function.class', { value });
|
|
49
|
+
}
|
|
50
|
+
},
|
|
51
|
+
|
|
52
|
+
minArity: {
|
|
53
|
+
method(n) {
|
|
54
|
+
|
|
55
|
+
Assert(Number.isSafeInteger(n) && n > 0, 'n must be a strict positive integer');
|
|
56
|
+
|
|
57
|
+
return this.$_addRule({ name: 'minArity', args: { n } });
|
|
58
|
+
},
|
|
59
|
+
validate(value, helpers, { n }) {
|
|
60
|
+
|
|
61
|
+
if (value.length >= n) {
|
|
62
|
+
return value;
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
return helpers.error('function.minArity', { n });
|
|
66
|
+
}
|
|
67
|
+
},
|
|
68
|
+
|
|
69
|
+
maxArity: {
|
|
70
|
+
method(n) {
|
|
71
|
+
|
|
72
|
+
Assert(Number.isSafeInteger(n) && n >= 0, 'n must be a positive integer');
|
|
73
|
+
|
|
74
|
+
return this.$_addRule({ name: 'maxArity', args: { n } });
|
|
75
|
+
},
|
|
76
|
+
validate(value, helpers, { n }) {
|
|
77
|
+
|
|
78
|
+
if (value.length <= n) {
|
|
79
|
+
return value;
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
return helpers.error('function.maxArity', { n });
|
|
83
|
+
}
|
|
84
|
+
}
|
|
85
|
+
},
|
|
86
|
+
|
|
87
|
+
messages: {
|
|
88
|
+
'function.arity': '{{#label}} must have an arity of {{#n}}',
|
|
89
|
+
'function.class': '{{#label}} must be a class',
|
|
90
|
+
'function.maxArity': '{{#label}} must have an arity lesser or equal to {{#n}}',
|
|
91
|
+
'function.minArity': '{{#label}} must have an arity greater or equal to {{#n}}'
|
|
92
|
+
}
|
|
93
|
+
});
|