@nocobase/plugin-workflow 2.1.0-beta.8 → 2.2.0-alpha.1

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.
Files changed (197) hide show
  1. package/dist/client/214.7e602cfe7a8251b8.js +10 -0
  2. package/dist/client/618.19af7f84261c815d.js +10 -0
  3. package/dist/client/67.452743ce8ec30617.js +10 -0
  4. package/dist/client/964.ffbf5b47ed12bbdc.js +10 -0
  5. package/dist/client/Branch.d.ts +7 -3
  6. package/dist/client/BranchContext.d.ts +18 -0
  7. package/dist/client/components/TimeoutInput.d.ts +11 -0
  8. package/dist/client/constants.d.ts +13 -0
  9. package/dist/client/flows/triggerWorkflows.d.ts +14 -1
  10. package/dist/client/hooks/{useWorkflowFilterActionProps.d.ts → useResourceFilterActionProps.d.ts} +1 -1
  11. package/dist/client/index.js +1 -1
  12. package/dist/client/nodes/create.d.ts +10 -0
  13. package/dist/client/nodes/destroy.d.ts +10 -0
  14. package/dist/client/nodes/index.d.ts +5 -0
  15. package/dist/client/nodes/query.d.ts +18 -2
  16. package/dist/client/nodes/update.d.ts +10 -0
  17. package/dist/client/schemas/collection.d.ts +8 -2
  18. package/dist/client/schemas/executions.d.ts +63 -2
  19. package/dist/client/triggers/collection.d.ts +14 -1
  20. package/dist/client/triggers/index.d.ts +4 -0
  21. package/dist/client/triggers/schedule/constants.d.ts +4 -0
  22. package/dist/client/triggers/schedule/index.d.ts +15 -0
  23. package/dist/client/utils.d.ts +17 -0
  24. package/dist/common/collections/executions.d.ts +44 -1
  25. package/dist/common/collections/executions.js +63 -1
  26. package/dist/common/collections/flow_nodes.d.ts +1 -0
  27. package/dist/common/collections/flow_nodes.js +1 -0
  28. package/dist/common/collections/jobs.d.ts +1 -0
  29. package/dist/common/collections/jobs.js +8 -0
  30. package/dist/common/collections/userWorkflowTasks.d.ts +1 -0
  31. package/dist/common/collections/userWorkflowTasks.js +1 -0
  32. package/dist/common/collections/workflowCategories.d.ts +1 -0
  33. package/dist/common/collections/workflowCategories.js +1 -0
  34. package/dist/common/collections/workflowCategoryRelations.d.ts +1 -0
  35. package/dist/common/collections/workflowCategoryRelations.js +1 -0
  36. package/dist/common/collections/workflowStats.d.ts +1 -0
  37. package/dist/common/collections/workflowStats.js +1 -0
  38. package/dist/common/collections/workflowTasks.js +1 -0
  39. package/dist/common/collections/workflowVersionStats.d.ts +1 -0
  40. package/dist/common/collections/workflowVersionStats.js +1 -0
  41. package/dist/common/collections/workflows.d.ts +66 -11
  42. package/dist/common/collections/workflows.js +35 -2
  43. package/dist/common/constants.d.ts +5 -0
  44. package/dist/common/constants.js +7 -0
  45. package/dist/externalVersion.js +15 -13
  46. package/dist/locale/de-DE.json +4 -0
  47. package/dist/locale/en-US.json +7 -0
  48. package/dist/locale/es-ES.json +4 -0
  49. package/dist/locale/fr-FR.json +4 -0
  50. package/dist/locale/hu-HU.json +7 -3
  51. package/dist/locale/id-ID.json +4 -0
  52. package/dist/locale/it-IT.json +4 -0
  53. package/dist/locale/ja-JP.json +5 -1
  54. package/dist/locale/ko-KR.json +4 -0
  55. package/dist/locale/nl-NL.json +7 -3
  56. package/dist/locale/pt-BR.json +4 -0
  57. package/dist/locale/ru-RU.json +4 -0
  58. package/dist/locale/tr-TR.json +4 -0
  59. package/dist/locale/uk-UA.json +7 -3
  60. package/dist/locale/vi-VN.json +7 -3
  61. package/dist/locale/zh-CN.json +10 -0
  62. package/dist/locale/zh-TW.json +7 -3
  63. package/dist/node_modules/cron-parser/lib/parser.js +1 -1
  64. package/dist/node_modules/cron-parser/package.json +1 -1
  65. package/dist/node_modules/joi/dist/joi-browser.min.js +1 -0
  66. package/dist/node_modules/joi/lib/annotate.js +175 -0
  67. package/dist/node_modules/joi/lib/base.js +1069 -0
  68. package/dist/node_modules/joi/lib/cache.js +143 -0
  69. package/dist/node_modules/joi/lib/common.js +216 -0
  70. package/dist/node_modules/joi/lib/compile.js +283 -0
  71. package/dist/node_modules/joi/lib/errors.js +271 -0
  72. package/dist/node_modules/joi/lib/extend.js +312 -0
  73. package/dist/node_modules/joi/lib/index.d.ts +2365 -0
  74. package/dist/node_modules/joi/lib/index.js +1 -0
  75. package/dist/node_modules/joi/lib/manifest.js +476 -0
  76. package/dist/node_modules/joi/lib/messages.js +178 -0
  77. package/dist/node_modules/joi/lib/modify.js +267 -0
  78. package/dist/node_modules/joi/lib/ref.js +414 -0
  79. package/dist/node_modules/joi/lib/schemas.js +302 -0
  80. package/dist/node_modules/joi/lib/state.js +166 -0
  81. package/dist/node_modules/joi/lib/template.js +463 -0
  82. package/dist/node_modules/joi/lib/trace.js +346 -0
  83. package/dist/node_modules/joi/lib/types/alternatives.js +364 -0
  84. package/dist/node_modules/joi/lib/types/any.js +174 -0
  85. package/dist/node_modules/joi/lib/types/array.js +809 -0
  86. package/dist/node_modules/joi/lib/types/binary.js +100 -0
  87. package/dist/node_modules/joi/lib/types/boolean.js +150 -0
  88. package/dist/node_modules/joi/lib/types/date.js +233 -0
  89. package/dist/node_modules/joi/lib/types/function.js +93 -0
  90. package/dist/node_modules/joi/lib/types/keys.js +1067 -0
  91. package/dist/node_modules/joi/lib/types/link.js +168 -0
  92. package/dist/node_modules/joi/lib/types/number.js +363 -0
  93. package/dist/node_modules/joi/lib/types/object.js +22 -0
  94. package/dist/node_modules/joi/lib/types/string.js +850 -0
  95. package/dist/node_modules/joi/lib/types/symbol.js +102 -0
  96. package/dist/node_modules/joi/lib/validator.js +750 -0
  97. package/dist/node_modules/joi/lib/values.js +263 -0
  98. package/dist/node_modules/joi/node_modules/@hapi/topo/lib/index.d.ts +60 -0
  99. package/dist/node_modules/joi/node_modules/@hapi/topo/lib/index.js +225 -0
  100. package/dist/node_modules/joi/node_modules/@hapi/topo/package.json +30 -0
  101. package/dist/node_modules/joi/package.json +1 -0
  102. package/dist/node_modules/lru-cache/dist/commonjs/diagnostics-channel.d.ts +5 -0
  103. package/dist/node_modules/lru-cache/dist/commonjs/diagnostics-channel.js +10 -0
  104. package/dist/node_modules/lru-cache/dist/commonjs/index.d.ts +1381 -0
  105. package/dist/node_modules/lru-cache/dist/commonjs/index.js +1692 -0
  106. package/dist/node_modules/lru-cache/dist/commonjs/index.min.js +1 -0
  107. package/dist/node_modules/lru-cache/dist/esm/browser/diagnostics-channel.d.ts +5 -0
  108. package/dist/node_modules/lru-cache/dist/esm/browser/diagnostics-channel.js +4 -0
  109. package/dist/node_modules/lru-cache/dist/esm/browser/index.d.ts +1381 -0
  110. package/dist/node_modules/lru-cache/dist/{mjs → esm/browser}/index.js +537 -179
  111. package/dist/node_modules/lru-cache/dist/esm/browser/index.min.js +2 -0
  112. package/dist/node_modules/lru-cache/dist/esm/diagnostics-channel.d.ts +5 -0
  113. package/dist/node_modules/lru-cache/dist/esm/diagnostics-channel.js +19 -0
  114. package/dist/node_modules/lru-cache/dist/esm/index.d.ts +1381 -0
  115. package/dist/node_modules/lru-cache/dist/{cjs → esm}/index.js +538 -184
  116. package/dist/node_modules/lru-cache/dist/esm/index.min.js +2 -0
  117. package/dist/node_modules/lru-cache/dist/esm/node/diagnostics-channel.d.ts +5 -0
  118. package/dist/node_modules/lru-cache/dist/esm/node/diagnostics-channel.js +7 -0
  119. package/dist/node_modules/lru-cache/dist/esm/node/index.d.ts +1381 -0
  120. package/dist/node_modules/lru-cache/dist/esm/node/index.js +1688 -0
  121. package/dist/node_modules/lru-cache/dist/esm/node/index.min.js +2 -0
  122. package/dist/node_modules/lru-cache/package.json +1 -1
  123. package/dist/node_modules/nodejs-snowflake/nodejs_snowflake.js +1 -1
  124. package/dist/node_modules/nodejs-snowflake/package.json +1 -1
  125. package/dist/server/Dispatcher.d.ts +12 -6
  126. package/dist/server/Dispatcher.js +309 -190
  127. package/dist/server/ExecutionTimeoutManager.d.ts +46 -0
  128. package/dist/server/ExecutionTimeoutManager.js +320 -0
  129. package/dist/server/Plugin.d.ts +17 -3
  130. package/dist/server/Plugin.js +54 -12
  131. package/dist/server/Processor.d.ts +64 -12
  132. package/dist/server/Processor.js +286 -48
  133. package/dist/server/RunningExecutionRegistry.d.ts +18 -0
  134. package/dist/server/RunningExecutionRegistry.js +48 -0
  135. package/dist/server/actions/executions.d.ts +4 -3
  136. package/dist/server/actions/executions.js +42 -21
  137. package/dist/server/actions/jobs.d.ts +2 -1
  138. package/dist/server/actions/jobs.js +28 -1
  139. package/dist/server/actions/nodes.d.ts +5 -0
  140. package/dist/server/actions/nodes.js +38 -5
  141. package/dist/server/actions/workflows.d.ts +6 -0
  142. package/dist/server/actions/workflows.js +38 -0
  143. package/dist/server/constants.d.ts +2 -0
  144. package/dist/server/constants.js +3 -0
  145. package/dist/server/index.d.ts +2 -0
  146. package/dist/server/index.js +2 -0
  147. package/dist/server/instructions/ConditionInstruction.d.ts +2 -0
  148. package/dist/server/instructions/ConditionInstruction.js +17 -0
  149. package/dist/server/instructions/CreateInstruction.d.ts +3 -0
  150. package/dist/server/instructions/CreateInstruction.js +25 -0
  151. package/dist/server/instructions/DestroyInstruction.d.ts +3 -0
  152. package/dist/server/instructions/DestroyInstruction.js +25 -0
  153. package/dist/server/instructions/EndInstruction.d.ts +2 -0
  154. package/dist/server/instructions/EndInstruction.js +4 -0
  155. package/dist/server/instructions/MultiConditionsInstruction.d.ts +2 -0
  156. package/dist/server/instructions/MultiConditionsInstruction.js +23 -0
  157. package/dist/server/instructions/OutputInstruction.d.ts +2 -0
  158. package/dist/server/instructions/OutputInstruction.js +15 -1
  159. package/dist/server/instructions/QueryInstruction.d.ts +3 -0
  160. package/dist/server/instructions/QueryInstruction.js +32 -7
  161. package/dist/server/instructions/UpdateInstruction.d.ts +3 -0
  162. package/dist/server/instructions/UpdateInstruction.js +27 -0
  163. package/dist/server/instructions/index.d.ts +24 -4
  164. package/dist/server/instructions/index.js +18 -0
  165. package/dist/server/migrations/20260423225800-fill-workflow-created-updated-by.d.ts +13 -0
  166. package/dist/server/migrations/20260423225800-fill-workflow-created-updated-by.js +57 -0
  167. package/dist/server/migrations/20260501120000-workflow-timeout.d.ts +13 -0
  168. package/dist/server/migrations/20260501120000-workflow-timeout.js +63 -0
  169. package/dist/server/timeout-errors.d.ts +13 -0
  170. package/dist/server/timeout-errors.js +47 -0
  171. package/dist/server/triggers/CollectionTrigger.d.ts +3 -0
  172. package/dist/server/triggers/CollectionTrigger.js +34 -0
  173. package/dist/server/triggers/ScheduleTrigger/index.d.ts +3 -0
  174. package/dist/server/triggers/ScheduleTrigger/index.js +18 -3
  175. package/dist/server/triggers/index.d.ts +3 -0
  176. package/dist/server/triggers/index.js +18 -0
  177. package/dist/server/types/Execution.d.ts +6 -0
  178. package/dist/server/types/Job.d.ts +3 -3
  179. package/dist/server/types/Workflow.d.ts +6 -1
  180. package/dist/server/utils.d.ts +27 -0
  181. package/dist/server/utils.js +142 -2
  182. package/dist/swagger/index.d.ts +66 -75
  183. package/dist/swagger/index.js +58 -67
  184. package/package.json +5 -4
  185. package/dist/client/0e458d99e9fc5e65.js +0 -10
  186. package/dist/client/27bd65abee87cafa.js +0 -10
  187. package/dist/client/478692c1637f2742.js +0 -10
  188. package/dist/client/f39e94207f92e352.js +0 -10
  189. package/dist/node_modules/lru-cache/LICENSE +0 -15
  190. package/dist/node_modules/lru-cache/dist/cjs/index-cjs.d.ts +0 -7
  191. package/dist/node_modules/lru-cache/dist/cjs/index-cjs.js +0 -1
  192. package/dist/node_modules/lru-cache/dist/cjs/index.d.ts +0 -807
  193. package/dist/node_modules/lru-cache/dist/cjs/index.min.js +0 -2
  194. package/dist/node_modules/lru-cache/dist/mjs/index.d.ts +0 -807
  195. package/dist/node_modules/lru-cache/dist/mjs/index.min.js +0 -2
  196. /package/dist/node_modules/lru-cache/dist/{cjs → commonjs}/package.json +0 -0
  197. /package/dist/node_modules/lru-cache/dist/{mjs → esm}/package.json +0 -0
@@ -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
+ });