@nocobase/plugin-workflow-javascript 2.1.0-beta.9 → 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 (191) hide show
  1. package/build.config.ts +52 -0
  2. package/dist/client/615.a016da4e5f572288.js +10 -0
  3. package/dist/client/944.18159d8a1521708e.js +10 -0
  4. package/dist/client/CodeEditor.d.ts +8 -0
  5. package/dist/client/index.js +1 -1
  6. package/dist/externalVersion.js +4 -4
  7. package/dist/node_modules/@jitl/quickjs-ffi-types/LICENSE +21 -0
  8. package/dist/node_modules/@jitl/quickjs-ffi-types/README.md +5 -0
  9. package/dist/node_modules/@jitl/quickjs-ffi-types/dist/index.d.mts +549 -0
  10. package/dist/node_modules/@jitl/quickjs-ffi-types/dist/index.d.ts +549 -0
  11. package/dist/node_modules/@jitl/quickjs-ffi-types/dist/index.js +2 -0
  12. package/dist/node_modules/@jitl/quickjs-ffi-types/dist/index.js.map +1 -0
  13. package/dist/node_modules/@jitl/quickjs-ffi-types/dist/index.mjs +2 -0
  14. package/dist/node_modules/@jitl/quickjs-ffi-types/dist/index.mjs.map +1 -0
  15. package/dist/node_modules/@jitl/quickjs-ffi-types/package.json +36 -0
  16. package/dist/node_modules/@jitl/quickjs-wasmfile-debug-asyncify/LICENSE +47 -0
  17. package/dist/node_modules/@jitl/quickjs-wasmfile-debug-asyncify/README.md +93 -0
  18. package/dist/node_modules/@jitl/quickjs-wasmfile-debug-asyncify/dist/emscripten-module.browser.d.ts +15 -0
  19. package/dist/node_modules/@jitl/quickjs-wasmfile-debug-asyncify/dist/emscripten-module.browser.mjs +2 -0
  20. package/dist/node_modules/@jitl/quickjs-wasmfile-debug-asyncify/dist/emscripten-module.cjs +2 -0
  21. package/dist/node_modules/@jitl/quickjs-wasmfile-debug-asyncify/dist/emscripten-module.cloudflare.cjs +2 -0
  22. package/dist/node_modules/@jitl/quickjs-wasmfile-debug-asyncify/dist/emscripten-module.cloudflare.d.ts +15 -0
  23. package/dist/node_modules/@jitl/quickjs-wasmfile-debug-asyncify/dist/emscripten-module.d.ts +15 -0
  24. package/dist/node_modules/@jitl/quickjs-wasmfile-debug-asyncify/dist/emscripten-module.mjs +2 -0
  25. package/dist/node_modules/@jitl/quickjs-wasmfile-debug-asyncify/dist/emscripten-module.wasm +0 -0
  26. package/dist/node_modules/@jitl/quickjs-wasmfile-debug-asyncify/dist/emscripten-module.wasm.map +1 -0
  27. package/dist/node_modules/@jitl/quickjs-wasmfile-debug-asyncify/dist/ffi.d.mts +94 -0
  28. package/dist/node_modules/@jitl/quickjs-wasmfile-debug-asyncify/dist/ffi.d.ts +94 -0
  29. package/dist/node_modules/@jitl/quickjs-wasmfile-debug-asyncify/dist/ffi.js +2 -0
  30. package/dist/node_modules/@jitl/quickjs-wasmfile-debug-asyncify/dist/ffi.js.map +1 -0
  31. package/dist/node_modules/@jitl/quickjs-wasmfile-debug-asyncify/dist/ffi.mjs +2 -0
  32. package/dist/node_modules/@jitl/quickjs-wasmfile-debug-asyncify/dist/ffi.mjs.map +1 -0
  33. package/dist/node_modules/@jitl/quickjs-wasmfile-debug-asyncify/dist/index.d.mts +20 -0
  34. package/dist/node_modules/@jitl/quickjs-wasmfile-debug-asyncify/dist/index.d.ts +20 -0
  35. package/dist/node_modules/@jitl/quickjs-wasmfile-debug-asyncify/dist/index.js +2 -0
  36. package/dist/node_modules/@jitl/quickjs-wasmfile-debug-asyncify/dist/index.js.map +1 -0
  37. package/dist/node_modules/@jitl/quickjs-wasmfile-debug-asyncify/dist/index.mjs +2 -0
  38. package/dist/node_modules/@jitl/quickjs-wasmfile-debug-asyncify/dist/index.mjs.map +1 -0
  39. package/dist/node_modules/@jitl/quickjs-wasmfile-debug-asyncify/package.json +61 -0
  40. package/dist/node_modules/@jitl/quickjs-wasmfile-debug-sync/LICENSE +47 -0
  41. package/dist/node_modules/@jitl/quickjs-wasmfile-debug-sync/README.md +88 -0
  42. package/dist/node_modules/@jitl/quickjs-wasmfile-debug-sync/dist/emscripten-module.browser.d.ts +11 -0
  43. package/dist/node_modules/@jitl/quickjs-wasmfile-debug-sync/dist/emscripten-module.browser.mjs +5430 -0
  44. package/dist/node_modules/@jitl/quickjs-wasmfile-debug-sync/dist/emscripten-module.cjs +5485 -0
  45. package/dist/node_modules/@jitl/quickjs-wasmfile-debug-sync/dist/emscripten-module.cloudflare.cjs +5424 -0
  46. package/dist/node_modules/@jitl/quickjs-wasmfile-debug-sync/dist/emscripten-module.cloudflare.d.ts +11 -0
  47. package/dist/node_modules/@jitl/quickjs-wasmfile-debug-sync/dist/emscripten-module.d.ts +11 -0
  48. package/dist/node_modules/@jitl/quickjs-wasmfile-debug-sync/dist/emscripten-module.mjs +5541 -0
  49. package/dist/node_modules/@jitl/quickjs-wasmfile-debug-sync/dist/emscripten-module.wasm +0 -0
  50. package/dist/node_modules/@jitl/quickjs-wasmfile-debug-sync/dist/emscripten-module.wasm.map +1 -0
  51. package/dist/node_modules/@jitl/quickjs-wasmfile-debug-sync/dist/ffi.d.mts +85 -0
  52. package/dist/node_modules/@jitl/quickjs-wasmfile-debug-sync/dist/ffi.d.ts +85 -0
  53. package/dist/node_modules/@jitl/quickjs-wasmfile-debug-sync/dist/ffi.js +2 -0
  54. package/dist/node_modules/@jitl/quickjs-wasmfile-debug-sync/dist/ffi.js.map +1 -0
  55. package/dist/node_modules/@jitl/quickjs-wasmfile-debug-sync/dist/ffi.mjs +2 -0
  56. package/dist/node_modules/@jitl/quickjs-wasmfile-debug-sync/dist/ffi.mjs.map +1 -0
  57. package/dist/node_modules/@jitl/quickjs-wasmfile-debug-sync/dist/index.d.mts +20 -0
  58. package/dist/node_modules/@jitl/quickjs-wasmfile-debug-sync/dist/index.d.ts +20 -0
  59. package/dist/node_modules/@jitl/quickjs-wasmfile-debug-sync/dist/index.js +2 -0
  60. package/dist/node_modules/@jitl/quickjs-wasmfile-debug-sync/dist/index.js.map +1 -0
  61. package/dist/node_modules/@jitl/quickjs-wasmfile-debug-sync/dist/index.mjs +2 -0
  62. package/dist/node_modules/@jitl/quickjs-wasmfile-debug-sync/dist/index.mjs.map +1 -0
  63. package/dist/node_modules/@jitl/quickjs-wasmfile-debug-sync/package.json +61 -0
  64. package/dist/node_modules/@jitl/quickjs-wasmfile-release-asyncify/LICENSE +47 -0
  65. package/dist/node_modules/@jitl/quickjs-wasmfile-release-asyncify/README.md +89 -0
  66. package/dist/node_modules/@jitl/quickjs-wasmfile-release-asyncify/dist/emscripten-module.browser.d.ts +15 -0
  67. package/dist/node_modules/@jitl/quickjs-wasmfile-release-asyncify/dist/emscripten-module.browser.mjs +26 -0
  68. package/dist/node_modules/@jitl/quickjs-wasmfile-release-asyncify/dist/emscripten-module.cjs +25 -0
  69. package/dist/node_modules/@jitl/quickjs-wasmfile-release-asyncify/dist/emscripten-module.cloudflare.cjs +25 -0
  70. package/dist/node_modules/@jitl/quickjs-wasmfile-release-asyncify/dist/emscripten-module.cloudflare.d.ts +15 -0
  71. package/dist/node_modules/@jitl/quickjs-wasmfile-release-asyncify/dist/emscripten-module.d.ts +15 -0
  72. package/dist/node_modules/@jitl/quickjs-wasmfile-release-asyncify/dist/emscripten-module.mjs +30 -0
  73. package/dist/node_modules/@jitl/quickjs-wasmfile-release-asyncify/dist/emscripten-module.wasm +0 -0
  74. package/dist/node_modules/@jitl/quickjs-wasmfile-release-asyncify/dist/ffi.d.mts +94 -0
  75. package/dist/node_modules/@jitl/quickjs-wasmfile-release-asyncify/dist/ffi.d.ts +94 -0
  76. package/dist/node_modules/@jitl/quickjs-wasmfile-release-asyncify/dist/ffi.js +2 -0
  77. package/dist/node_modules/@jitl/quickjs-wasmfile-release-asyncify/dist/ffi.js.map +1 -0
  78. package/dist/node_modules/@jitl/quickjs-wasmfile-release-asyncify/dist/ffi.mjs +2 -0
  79. package/dist/node_modules/@jitl/quickjs-wasmfile-release-asyncify/dist/ffi.mjs.map +1 -0
  80. package/dist/node_modules/@jitl/quickjs-wasmfile-release-asyncify/dist/index.d.mts +20 -0
  81. package/dist/node_modules/@jitl/quickjs-wasmfile-release-asyncify/dist/index.d.ts +20 -0
  82. package/dist/node_modules/@jitl/quickjs-wasmfile-release-asyncify/dist/index.js +2 -0
  83. package/dist/node_modules/@jitl/quickjs-wasmfile-release-asyncify/dist/index.js.map +1 -0
  84. package/dist/node_modules/@jitl/quickjs-wasmfile-release-asyncify/dist/index.mjs +2 -0
  85. package/dist/node_modules/@jitl/quickjs-wasmfile-release-asyncify/dist/index.mjs.map +1 -0
  86. package/dist/node_modules/@jitl/quickjs-wasmfile-release-asyncify/package.json +61 -0
  87. package/dist/node_modules/@jitl/quickjs-wasmfile-release-sync/LICENSE +47 -0
  88. package/dist/node_modules/@jitl/quickjs-wasmfile-release-sync/README.md +82 -0
  89. package/dist/node_modules/@jitl/quickjs-wasmfile-release-sync/dist/emscripten-module.browser.d.ts +11 -0
  90. package/dist/node_modules/@jitl/quickjs-wasmfile-release-sync/dist/emscripten-module.browser.mjs +22 -0
  91. package/dist/node_modules/@jitl/quickjs-wasmfile-release-sync/dist/emscripten-module.cjs +21 -0
  92. package/dist/node_modules/@jitl/quickjs-wasmfile-release-sync/dist/emscripten-module.cloudflare.cjs +21 -0
  93. package/dist/node_modules/@jitl/quickjs-wasmfile-release-sync/dist/emscripten-module.cloudflare.d.ts +11 -0
  94. package/dist/node_modules/@jitl/quickjs-wasmfile-release-sync/dist/emscripten-module.d.ts +11 -0
  95. package/dist/node_modules/@jitl/quickjs-wasmfile-release-sync/dist/emscripten-module.mjs +25 -0
  96. package/dist/node_modules/@jitl/quickjs-wasmfile-release-sync/dist/emscripten-module.wasm +0 -0
  97. package/dist/node_modules/@jitl/quickjs-wasmfile-release-sync/dist/ffi.d.mts +85 -0
  98. package/dist/node_modules/@jitl/quickjs-wasmfile-release-sync/dist/ffi.d.ts +85 -0
  99. package/dist/node_modules/@jitl/quickjs-wasmfile-release-sync/dist/ffi.js +2 -0
  100. package/dist/node_modules/@jitl/quickjs-wasmfile-release-sync/dist/ffi.js.map +1 -0
  101. package/dist/node_modules/@jitl/quickjs-wasmfile-release-sync/dist/ffi.mjs +2 -0
  102. package/dist/node_modules/@jitl/quickjs-wasmfile-release-sync/dist/ffi.mjs.map +1 -0
  103. package/dist/node_modules/@jitl/quickjs-wasmfile-release-sync/dist/index.d.mts +20 -0
  104. package/dist/node_modules/@jitl/quickjs-wasmfile-release-sync/dist/index.d.ts +20 -0
  105. package/dist/node_modules/@jitl/quickjs-wasmfile-release-sync/dist/index.js +2 -0
  106. package/dist/node_modules/@jitl/quickjs-wasmfile-release-sync/dist/index.js.map +1 -0
  107. package/dist/node_modules/@jitl/quickjs-wasmfile-release-sync/dist/index.mjs +2 -0
  108. package/dist/node_modules/@jitl/quickjs-wasmfile-release-sync/dist/index.mjs.map +1 -0
  109. package/dist/node_modules/@jitl/quickjs-wasmfile-release-sync/package.json +61 -0
  110. package/dist/node_modules/joi/dist/joi-browser.min.js +1 -0
  111. package/dist/node_modules/joi/lib/annotate.js +175 -0
  112. package/dist/node_modules/joi/lib/base.js +1069 -0
  113. package/dist/node_modules/joi/lib/cache.js +143 -0
  114. package/dist/node_modules/joi/lib/common.js +216 -0
  115. package/dist/node_modules/joi/lib/compile.js +283 -0
  116. package/dist/node_modules/joi/lib/errors.js +271 -0
  117. package/dist/node_modules/joi/lib/extend.js +312 -0
  118. package/dist/node_modules/joi/lib/index.d.ts +2365 -0
  119. package/dist/node_modules/joi/lib/index.js +1 -0
  120. package/dist/node_modules/joi/lib/manifest.js +476 -0
  121. package/dist/node_modules/joi/lib/messages.js +178 -0
  122. package/dist/node_modules/joi/lib/modify.js +267 -0
  123. package/dist/node_modules/joi/lib/ref.js +414 -0
  124. package/dist/node_modules/joi/lib/schemas.js +302 -0
  125. package/dist/node_modules/joi/lib/state.js +166 -0
  126. package/dist/node_modules/joi/lib/template.js +463 -0
  127. package/dist/node_modules/joi/lib/trace.js +346 -0
  128. package/dist/node_modules/joi/lib/types/alternatives.js +364 -0
  129. package/dist/node_modules/joi/lib/types/any.js +174 -0
  130. package/dist/node_modules/joi/lib/types/array.js +809 -0
  131. package/dist/node_modules/joi/lib/types/binary.js +100 -0
  132. package/dist/node_modules/joi/lib/types/boolean.js +150 -0
  133. package/dist/node_modules/joi/lib/types/date.js +233 -0
  134. package/dist/node_modules/joi/lib/types/function.js +93 -0
  135. package/dist/node_modules/joi/lib/types/keys.js +1067 -0
  136. package/dist/node_modules/joi/lib/types/link.js +168 -0
  137. package/dist/node_modules/joi/lib/types/number.js +363 -0
  138. package/dist/node_modules/joi/lib/types/object.js +22 -0
  139. package/dist/node_modules/joi/lib/types/string.js +850 -0
  140. package/dist/node_modules/joi/lib/types/symbol.js +102 -0
  141. package/dist/node_modules/joi/lib/validator.js +750 -0
  142. package/dist/node_modules/joi/lib/values.js +263 -0
  143. package/dist/node_modules/joi/node_modules/@hapi/topo/lib/index.d.ts +60 -0
  144. package/dist/node_modules/joi/node_modules/@hapi/topo/lib/index.js +225 -0
  145. package/dist/node_modules/joi/node_modules/@hapi/topo/package.json +30 -0
  146. package/dist/node_modules/joi/package.json +1 -0
  147. package/dist/node_modules/quickjs-emscripten/LICENSE +21 -0
  148. package/dist/node_modules/quickjs-emscripten/README.md +928 -0
  149. package/dist/node_modules/quickjs-emscripten/dist/chunk-OHAYRCBA.mjs +2 -0
  150. package/dist/node_modules/quickjs-emscripten/dist/chunk-OHAYRCBA.mjs.map +1 -0
  151. package/dist/node_modules/quickjs-emscripten/dist/index.d.mts +57 -0
  152. package/dist/node_modules/quickjs-emscripten/dist/index.d.ts +57 -0
  153. package/dist/node_modules/quickjs-emscripten/dist/index.global.js +7309 -0
  154. package/dist/node_modules/quickjs-emscripten/dist/index.js +2 -0
  155. package/dist/node_modules/quickjs-emscripten/dist/index.js.map +1 -0
  156. package/dist/node_modules/quickjs-emscripten/dist/index.mjs +2 -0
  157. package/dist/node_modules/quickjs-emscripten/dist/index.mjs.map +1 -0
  158. package/dist/node_modules/quickjs-emscripten/dist/variants.d.mts +39 -0
  159. package/dist/node_modules/quickjs-emscripten/dist/variants.d.ts +39 -0
  160. package/dist/node_modules/quickjs-emscripten/dist/variants.js +2 -0
  161. package/dist/node_modules/quickjs-emscripten/dist/variants.js.map +1 -0
  162. package/dist/node_modules/quickjs-emscripten/dist/variants.mjs +2 -0
  163. package/dist/node_modules/quickjs-emscripten/dist/variants.mjs.map +1 -0
  164. package/dist/node_modules/quickjs-emscripten/package.json +69 -0
  165. package/dist/node_modules/quickjs-emscripten-core/LICENSE +21 -0
  166. package/dist/node_modules/quickjs-emscripten-core/README.md +341 -0
  167. package/dist/node_modules/quickjs-emscripten-core/README.template.md +70 -0
  168. package/dist/node_modules/quickjs-emscripten-core/dist/chunk-TAV5CUKK.mjs +2 -0
  169. package/dist/node_modules/quickjs-emscripten-core/dist/chunk-TAV5CUKK.mjs.map +1 -0
  170. package/dist/node_modules/quickjs-emscripten-core/dist/chunk-V2S4ZYJR.mjs +7 -0
  171. package/dist/node_modules/quickjs-emscripten-core/dist/chunk-V2S4ZYJR.mjs.map +1 -0
  172. package/dist/node_modules/quickjs-emscripten-core/dist/index.d.mts +2033 -0
  173. package/dist/node_modules/quickjs-emscripten-core/dist/index.d.ts +2033 -0
  174. package/dist/node_modules/quickjs-emscripten-core/dist/index.js +7 -0
  175. package/dist/node_modules/quickjs-emscripten-core/dist/index.js.map +1 -0
  176. package/dist/node_modules/quickjs-emscripten-core/dist/index.mjs +2 -0
  177. package/dist/node_modules/quickjs-emscripten-core/dist/index.mjs.map +1 -0
  178. package/dist/node_modules/quickjs-emscripten-core/dist/module-ES6BEMUI.mjs +2 -0
  179. package/dist/node_modules/quickjs-emscripten-core/dist/module-ES6BEMUI.mjs.map +1 -0
  180. package/dist/node_modules/quickjs-emscripten-core/dist/module-asyncify-2EFITU5U.mjs +2 -0
  181. package/dist/node_modules/quickjs-emscripten-core/dist/module-asyncify-2EFITU5U.mjs.map +1 -0
  182. package/dist/node_modules/quickjs-emscripten-core/package.json +49 -0
  183. package/dist/node_modules/winston-transport/index.js +2 -2
  184. package/dist/node_modules/winston-transport/package.json +1 -1
  185. package/dist/server/QuickJs.js +145 -0
  186. package/dist/server/ScriptInstruction.d.ts +24 -10
  187. package/dist/server/ScriptInstruction.js +51 -11
  188. package/dist/server/Vm.js +42 -27
  189. package/package.json +4 -7
  190. package/dist/client/907399554f340b0a.js +0 -10
  191. package/dist/client/d608e8e5c2f2b5cf.js +0 -10
@@ -0,0 +1,143 @@
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
+
8
+
9
+ const internals = {
10
+ max: 1000,
11
+ supported: new Set(['undefined', 'boolean', 'number', 'string'])
12
+ };
13
+
14
+
15
+ exports.provider = {
16
+
17
+ provision(options) {
18
+
19
+ return new internals.Cache(options);
20
+ }
21
+ };
22
+
23
+
24
+ // Least Recently Used (LRU) Cache
25
+
26
+ internals.Cache = class {
27
+
28
+ constructor(options = {}) {
29
+
30
+ Common.assertOptions(options, ['max']);
31
+ Assert(options.max === undefined || options.max && options.max > 0 && isFinite(options.max), 'Invalid max cache size');
32
+
33
+ this._max = options.max || internals.max;
34
+
35
+ this._map = new Map(); // Map of nodes by key
36
+ this._list = new internals.List(); // List of nodes (most recently used in head)
37
+ }
38
+
39
+ get length() {
40
+
41
+ return this._map.size;
42
+ }
43
+
44
+ set(key, value) {
45
+
46
+ if (key !== null &&
47
+ !internals.supported.has(typeof key)) {
48
+
49
+ return;
50
+ }
51
+
52
+ let node = this._map.get(key);
53
+ if (node) {
54
+ node.value = value;
55
+ this._list.first(node);
56
+ return;
57
+ }
58
+
59
+ node = this._list.unshift({ key, value });
60
+ this._map.set(key, node);
61
+ this._compact();
62
+ }
63
+
64
+ get(key) {
65
+
66
+ const node = this._map.get(key);
67
+ if (node) {
68
+ this._list.first(node);
69
+ return Clone(node.value);
70
+ }
71
+ }
72
+
73
+ _compact() {
74
+
75
+ if (this._map.size > this._max) {
76
+ const node = this._list.pop();
77
+ this._map.delete(node.key);
78
+ }
79
+ }
80
+ };
81
+
82
+
83
+ internals.List = class {
84
+
85
+ constructor() {
86
+
87
+ this.tail = null;
88
+ this.head = null;
89
+ }
90
+
91
+ unshift(node) {
92
+
93
+ node.next = null;
94
+ node.prev = this.head;
95
+
96
+ if (this.head) {
97
+ this.head.next = node;
98
+ }
99
+
100
+ this.head = node;
101
+
102
+ if (!this.tail) {
103
+ this.tail = node;
104
+ }
105
+
106
+ return node;
107
+ }
108
+
109
+ first(node) {
110
+
111
+ if (node === this.head) {
112
+ return;
113
+ }
114
+
115
+ this._remove(node);
116
+ this.unshift(node);
117
+ }
118
+
119
+ pop() {
120
+
121
+ return this._remove(this.tail);
122
+ }
123
+
124
+ _remove(node) {
125
+
126
+ const { next, prev } = node;
127
+
128
+ next.prev = prev;
129
+
130
+ if (prev) {
131
+ prev.next = next;
132
+ }
133
+
134
+ if (node === this.tail) {
135
+ this.tail = next;
136
+ }
137
+
138
+ node.prev = null;
139
+ node.next = null;
140
+
141
+ return node;
142
+ }
143
+ };
@@ -0,0 +1,216 @@
1
+ 'use strict';
2
+
3
+ const Assert = require('@hapi/hoek/lib/assert');
4
+ const AssertError = require('@hapi/hoek/lib/error');
5
+
6
+ const Pkg = require('../package.json');
7
+
8
+ let Messages;
9
+ let Schemas;
10
+
11
+
12
+ const internals = {
13
+ isoDate: /^(?:[-+]\d{2})?(?:\d{4}(?!\d{2}\b))(?:(-?)(?:(?:0[1-9]|1[0-2])(?:\1(?:[12]\d|0[1-9]|3[01]))?|W(?:[0-4]\d|5[0-2])(?:-?[1-7])?|(?:00[1-9]|0[1-9]\d|[12]\d{2}|3(?:[0-5]\d|6[1-6])))(?![T]$|[T][\d]+Z$)(?:[T\s](?:(?:(?:[01]\d|2[0-3])(?:(:?)[0-5]\d)?|24\:?00)(?:[.,]\d+(?!:))?)(?:\2[0-5]\d(?:[.,]\d+)?)?(?:[Z]|(?:[+-])(?:[01]\d|2[0-3])(?::?[0-5]\d)?)?)?)?$/
14
+ };
15
+
16
+
17
+ exports.version = Pkg.version;
18
+
19
+
20
+ exports.defaults = {
21
+ abortEarly: true,
22
+ allowUnknown: false,
23
+ artifacts: false,
24
+ cache: true,
25
+ context: null,
26
+ convert: true,
27
+ dateFormat: 'iso',
28
+ errors: {
29
+ escapeHtml: false,
30
+ label: 'path',
31
+ language: null,
32
+ render: true,
33
+ stack: false,
34
+ wrap: {
35
+ label: '"',
36
+ array: '[]'
37
+ }
38
+ },
39
+ externals: true,
40
+ messages: {},
41
+ nonEnumerables: false,
42
+ noDefaults: false,
43
+ presence: 'optional',
44
+ skipFunctions: false,
45
+ stripUnknown: false,
46
+ warnings: false
47
+ };
48
+
49
+
50
+ exports.symbols = {
51
+ any: Symbol.for('@hapi/joi/schema'), // Used to internally identify any-based types (shared with other joi versions)
52
+ arraySingle: Symbol('arraySingle'),
53
+ deepDefault: Symbol('deepDefault'),
54
+ errors: Symbol('errors'),
55
+ literal: Symbol('literal'),
56
+ override: Symbol('override'),
57
+ parent: Symbol('parent'),
58
+ prefs: Symbol('prefs'),
59
+ ref: Symbol('ref'),
60
+ template: Symbol('template'),
61
+ values: Symbol('values')
62
+ };
63
+
64
+
65
+ exports.assertOptions = function (options, keys, name = 'Options') {
66
+
67
+ Assert(options && typeof options === 'object' && !Array.isArray(options), 'Options must be of type object');
68
+ const unknownKeys = Object.keys(options).filter((k) => !keys.includes(k));
69
+ Assert(unknownKeys.length === 0, `${name} contain unknown keys: ${unknownKeys}`);
70
+ };
71
+
72
+
73
+ exports.checkPreferences = function (prefs) {
74
+
75
+ Schemas = Schemas || require('./schemas');
76
+
77
+ const result = Schemas.preferences.validate(prefs);
78
+
79
+ if (result.error) {
80
+ throw new AssertError([result.error.details[0].message]);
81
+ }
82
+ };
83
+
84
+
85
+ exports.compare = function (a, b, operator) {
86
+
87
+ switch (operator) {
88
+ case '=': return a === b;
89
+ case '>': return a > b;
90
+ case '<': return a < b;
91
+ case '>=': return a >= b;
92
+ case '<=': return a <= b;
93
+ }
94
+ };
95
+
96
+
97
+ exports.default = function (value, defaultValue) {
98
+
99
+ return value === undefined ? defaultValue : value;
100
+ };
101
+
102
+
103
+ exports.isIsoDate = function (date) {
104
+
105
+ return internals.isoDate.test(date);
106
+ };
107
+
108
+
109
+ exports.isNumber = function (value) {
110
+
111
+ return typeof value === 'number' && !isNaN(value);
112
+ };
113
+
114
+
115
+ exports.isResolvable = function (obj) {
116
+
117
+ if (!obj) {
118
+ return false;
119
+ }
120
+
121
+ return obj[exports.symbols.ref] || obj[exports.symbols.template];
122
+ };
123
+
124
+
125
+ exports.isSchema = function (schema, options = {}) {
126
+
127
+ const any = schema && schema[exports.symbols.any];
128
+ if (!any) {
129
+ return false;
130
+ }
131
+
132
+ Assert(options.legacy || any.version === exports.version, 'Cannot mix different versions of joi schemas');
133
+ return true;
134
+ };
135
+
136
+
137
+ exports.isValues = function (obj) {
138
+
139
+ return obj[exports.symbols.values];
140
+ };
141
+
142
+
143
+ exports.limit = function (value) {
144
+
145
+ return Number.isSafeInteger(value) && value >= 0;
146
+ };
147
+
148
+
149
+ exports.preferences = function (target, source) {
150
+
151
+ Messages = Messages || require('./messages');
152
+
153
+ target = target || {};
154
+ source = source || {};
155
+
156
+ const merged = Object.assign({}, target, source);
157
+ if (source.errors &&
158
+ target.errors) {
159
+
160
+ merged.errors = Object.assign({}, target.errors, source.errors);
161
+ merged.errors.wrap = Object.assign({}, target.errors.wrap, source.errors.wrap);
162
+ }
163
+
164
+ if (source.messages) {
165
+ merged.messages = Messages.compile(source.messages, target.messages);
166
+ }
167
+
168
+ delete merged[exports.symbols.prefs];
169
+ return merged;
170
+ };
171
+
172
+
173
+ exports.tryWithPath = function (fn, key, options = {}) {
174
+
175
+ try {
176
+ return fn();
177
+ }
178
+ catch (err) {
179
+ if (err.path !== undefined) {
180
+ err.path = key + '.' + err.path;
181
+ }
182
+ else {
183
+ err.path = key;
184
+ }
185
+
186
+ if (options.append) {
187
+ err.message = `${err.message} (${err.path})`;
188
+ }
189
+
190
+ throw err;
191
+ }
192
+ };
193
+
194
+
195
+ exports.validateArg = function (value, label, { assert, message }) {
196
+
197
+ if (exports.isSchema(assert)) {
198
+ const result = assert.validate(value);
199
+ if (!result.error) {
200
+ return;
201
+ }
202
+
203
+ return result.error.message;
204
+ }
205
+ else if (!assert(value)) {
206
+ return label ? `${label} ${message}` : message;
207
+ }
208
+ };
209
+
210
+
211
+ exports.verifyFlat = function (args, method) {
212
+
213
+ for (const arg of args) {
214
+ Assert(!Array.isArray(arg), 'Method no longer accepts array arguments:', method);
215
+ }
216
+ };
@@ -0,0 +1,283 @@
1
+ 'use strict';
2
+
3
+ const Assert = require('@hapi/hoek/lib/assert');
4
+
5
+ const Common = require('./common');
6
+ const Ref = require('./ref');
7
+
8
+
9
+ const internals = {};
10
+
11
+
12
+ exports.schema = function (Joi, config, options = {}) {
13
+
14
+ Common.assertOptions(options, ['appendPath', 'override']);
15
+
16
+ try {
17
+ return internals.schema(Joi, config, options);
18
+ }
19
+ catch (err) {
20
+ if (options.appendPath &&
21
+ err.path !== undefined) {
22
+
23
+ err.message = `${err.message} (${err.path})`;
24
+ }
25
+
26
+ throw err;
27
+ }
28
+ };
29
+
30
+
31
+ internals.schema = function (Joi, config, options) {
32
+
33
+ Assert(config !== undefined, 'Invalid undefined schema');
34
+
35
+ if (Array.isArray(config)) {
36
+ Assert(config.length, 'Invalid empty array schema');
37
+
38
+ if (config.length === 1) {
39
+ config = config[0];
40
+ }
41
+ }
42
+
43
+ const valid = (base, ...values) => {
44
+
45
+ if (options.override !== false) {
46
+ return base.valid(Joi.override, ...values);
47
+ }
48
+
49
+ return base.valid(...values);
50
+ };
51
+
52
+ if (internals.simple(config)) {
53
+ return valid(Joi, config);
54
+ }
55
+
56
+ if (typeof config === 'function') {
57
+ return Joi.custom(config);
58
+ }
59
+
60
+ Assert(typeof config === 'object', 'Invalid schema content:', typeof config);
61
+
62
+ if (Common.isResolvable(config)) {
63
+ return valid(Joi, config);
64
+ }
65
+
66
+ if (Common.isSchema(config)) {
67
+ return config;
68
+ }
69
+
70
+ if (Array.isArray(config)) {
71
+ for (const item of config) {
72
+ if (!internals.simple(item)) {
73
+ return Joi.alternatives().try(...config);
74
+ }
75
+ }
76
+
77
+ return valid(Joi, ...config);
78
+ }
79
+
80
+ if (config instanceof RegExp) {
81
+ return Joi.string().regex(config);
82
+ }
83
+
84
+ if (config instanceof Date) {
85
+ return valid(Joi.date(), config);
86
+ }
87
+
88
+ Assert(Object.getPrototypeOf(config) === Object.getPrototypeOf({}), 'Schema can only contain plain objects');
89
+
90
+ return Joi.object().keys(config);
91
+ };
92
+
93
+
94
+ exports.ref = function (id, options) {
95
+
96
+ return Ref.isRef(id) ? id : Ref.create(id, options);
97
+ };
98
+
99
+
100
+ exports.compile = function (root, schema, options = {}) {
101
+
102
+ Common.assertOptions(options, ['legacy']);
103
+
104
+ // Compiled by any supported version
105
+
106
+ const any = schema && schema[Common.symbols.any];
107
+ if (any) {
108
+ Assert(options.legacy || any.version === Common.version, 'Cannot mix different versions of joi schemas:', any.version, Common.version);
109
+ return schema;
110
+ }
111
+
112
+ // Uncompiled root
113
+
114
+ if (typeof schema !== 'object' ||
115
+ !options.legacy) {
116
+
117
+ return exports.schema(root, schema, { appendPath: true }); // Will error if schema contains other versions
118
+ }
119
+
120
+ // Scan schema for compiled parts
121
+
122
+ const compiler = internals.walk(schema);
123
+ if (!compiler) {
124
+ return exports.schema(root, schema, { appendPath: true });
125
+ }
126
+
127
+ return compiler.compile(compiler.root, schema);
128
+ };
129
+
130
+
131
+ internals.walk = function (schema) {
132
+
133
+ if (typeof schema !== 'object') {
134
+ return null;
135
+ }
136
+
137
+ if (Array.isArray(schema)) {
138
+ for (const item of schema) {
139
+ const compiler = internals.walk(item);
140
+ if (compiler) {
141
+ return compiler;
142
+ }
143
+ }
144
+
145
+ return null;
146
+ }
147
+
148
+ const any = schema[Common.symbols.any];
149
+ if (any) {
150
+ return { root: schema[any.root], compile: any.compile };
151
+ }
152
+
153
+ Assert(Object.getPrototypeOf(schema) === Object.getPrototypeOf({}), 'Schema can only contain plain objects');
154
+
155
+ for (const key in schema) {
156
+ const compiler = internals.walk(schema[key]);
157
+ if (compiler) {
158
+ return compiler;
159
+ }
160
+ }
161
+
162
+ return null;
163
+ };
164
+
165
+
166
+ internals.simple = function (value) {
167
+
168
+ return value === null || ['boolean', 'string', 'number'].includes(typeof value);
169
+ };
170
+
171
+
172
+ exports.when = function (schema, condition, options) {
173
+
174
+ if (options === undefined) {
175
+ Assert(condition && typeof condition === 'object', 'Missing options');
176
+
177
+ options = condition;
178
+ condition = Ref.create('.');
179
+ }
180
+
181
+ if (Array.isArray(options)) {
182
+ options = { switch: options };
183
+ }
184
+
185
+ Common.assertOptions(options, ['is', 'not', 'then', 'otherwise', 'switch', 'break']);
186
+
187
+ // Schema condition
188
+
189
+ if (Common.isSchema(condition)) {
190
+ Assert(options.is === undefined, '"is" can not be used with a schema condition');
191
+ Assert(options.not === undefined, '"not" can not be used with a schema condition');
192
+ Assert(options.switch === undefined, '"switch" can not be used with a schema condition');
193
+
194
+ return internals.condition(schema, { is: condition, then: options.then, otherwise: options.otherwise, break: options.break });
195
+ }
196
+
197
+ // Single condition
198
+
199
+ Assert(Ref.isRef(condition) || typeof condition === 'string', 'Invalid condition:', condition);
200
+ Assert(options.not === undefined || options.is === undefined, 'Cannot combine "is" with "not"');
201
+
202
+ if (options.switch === undefined) {
203
+ let rule = options;
204
+ if (options.not !== undefined) {
205
+ rule = { is: options.not, then: options.otherwise, otherwise: options.then, break: options.break };
206
+ }
207
+
208
+ let is = rule.is !== undefined ? schema.$_compile(rule.is) : schema.$_root.invalid(null, false, 0, '').required();
209
+ Assert(rule.then !== undefined || rule.otherwise !== undefined, 'options must have at least one of "then", "otherwise", or "switch"');
210
+ Assert(rule.break === undefined || rule.then === undefined || rule.otherwise === undefined, 'Cannot specify then, otherwise, and break all together');
211
+
212
+ if (options.is !== undefined &&
213
+ !Ref.isRef(options.is) &&
214
+ !Common.isSchema(options.is)) {
215
+
216
+ is = is.required(); // Only apply required if this wasn't already a schema or a ref
217
+ }
218
+
219
+ return internals.condition(schema, { ref: exports.ref(condition), is, then: rule.then, otherwise: rule.otherwise, break: rule.break });
220
+ }
221
+
222
+ // Switch statement
223
+
224
+ Assert(Array.isArray(options.switch), '"switch" must be an array');
225
+ Assert(options.is === undefined, 'Cannot combine "switch" with "is"');
226
+ Assert(options.not === undefined, 'Cannot combine "switch" with "not"');
227
+ Assert(options.then === undefined, 'Cannot combine "switch" with "then"');
228
+
229
+ const rule = {
230
+ ref: exports.ref(condition),
231
+ switch: [],
232
+ break: options.break
233
+ };
234
+
235
+ for (let i = 0; i < options.switch.length; ++i) {
236
+ const test = options.switch[i];
237
+ const last = i === options.switch.length - 1;
238
+
239
+ Common.assertOptions(test, last ? ['is', 'then', 'otherwise'] : ['is', 'then']);
240
+
241
+ Assert(test.is !== undefined, 'Switch statement missing "is"');
242
+ Assert(test.then !== undefined, 'Switch statement missing "then"');
243
+
244
+ const item = {
245
+ is: schema.$_compile(test.is),
246
+ then: schema.$_compile(test.then)
247
+ };
248
+
249
+ if (!Ref.isRef(test.is) &&
250
+ !Common.isSchema(test.is)) {
251
+
252
+ item.is = item.is.required(); // Only apply required if this wasn't already a schema or a ref
253
+ }
254
+
255
+ if (last) {
256
+ Assert(options.otherwise === undefined || test.otherwise === undefined, 'Cannot specify "otherwise" inside and outside a "switch"');
257
+ const otherwise = options.otherwise !== undefined ? options.otherwise : test.otherwise;
258
+ if (otherwise !== undefined) {
259
+ Assert(rule.break === undefined, 'Cannot specify both otherwise and break');
260
+ item.otherwise = schema.$_compile(otherwise);
261
+ }
262
+ }
263
+
264
+ rule.switch.push(item);
265
+ }
266
+
267
+ return rule;
268
+ };
269
+
270
+
271
+ internals.condition = function (schema, condition) {
272
+
273
+ for (const key of ['then', 'otherwise']) {
274
+ if (condition[key] === undefined) {
275
+ delete condition[key];
276
+ }
277
+ else {
278
+ condition[key] = schema.$_compile(condition[key]);
279
+ }
280
+ }
281
+
282
+ return condition;
283
+ };