@nocobase/plugin-workflow-javascript 2.1.0-alpha.12 → 2.1.0-alpha.14
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/index.js +1 -1
- package/dist/externalVersion.js +4 -4
- package/dist/node_modules/isolated-vm/.clang-tidy +13 -0
- package/dist/node_modules/isolated-vm/.dockerignore +9 -0
- package/dist/node_modules/isolated-vm/Dockerfile.alpine +9 -0
- package/dist/node_modules/isolated-vm/Dockerfile.debian +12 -0
- package/dist/node_modules/isolated-vm/LICENSE +13 -0
- package/dist/node_modules/isolated-vm/binding.gyp +120 -0
- package/dist/node_modules/isolated-vm/include.js +3 -0
- package/dist/node_modules/isolated-vm/inspector-example.js +59 -0
- package/dist/node_modules/isolated-vm/isolated-vm.d.ts +820 -0
- package/dist/node_modules/isolated-vm/isolated-vm.js +1 -0
- package/dist/node_modules/isolated-vm/native-example/binding.gyp +23 -0
- package/dist/node_modules/isolated-vm/native-example/example.cc +61 -0
- package/dist/node_modules/isolated-vm/native-example/package.json +13 -0
- package/dist/node_modules/isolated-vm/native-example/usage.js +35 -0
- package/dist/node_modules/isolated-vm/out/isolated_vm.node +0 -0
- package/dist/node_modules/isolated-vm/package.json +1 -0
- package/dist/node_modules/isolated-vm/src/external_copy/error.h +33 -0
- package/dist/node_modules/isolated-vm/src/external_copy/external_copy.cc +509 -0
- package/dist/node_modules/isolated-vm/src/external_copy/external_copy.h +117 -0
- package/dist/node_modules/isolated-vm/src/external_copy/serializer.cc +85 -0
- package/dist/node_modules/isolated-vm/src/external_copy/serializer.h +136 -0
- package/dist/node_modules/isolated-vm/src/external_copy/serializer_nortti.cc +73 -0
- package/dist/node_modules/isolated-vm/src/external_copy/string.cc +124 -0
- package/dist/node_modules/isolated-vm/src/external_copy/string.h +28 -0
- package/dist/node_modules/isolated-vm/src/isolate/allocator.h +32 -0
- package/dist/node_modules/isolated-vm/src/isolate/allocator_nortti.cc +142 -0
- package/dist/node_modules/isolated-vm/src/isolate/class_handle.h +334 -0
- package/dist/node_modules/isolated-vm/src/isolate/cpu_profile_manager.cc +220 -0
- package/dist/node_modules/isolated-vm/src/isolate/cpu_profile_manager.h +100 -0
- package/dist/node_modules/isolated-vm/src/isolate/environment.cc +626 -0
- package/dist/node_modules/isolated-vm/src/isolate/environment.h +381 -0
- package/dist/node_modules/isolated-vm/src/isolate/executor.cc +198 -0
- package/dist/node_modules/isolated-vm/src/isolate/executor.h +183 -0
- package/dist/node_modules/isolated-vm/src/isolate/external.h +64 -0
- package/dist/node_modules/isolated-vm/src/isolate/functor_runners.h +97 -0
- package/dist/node_modules/isolated-vm/src/isolate/generic/array.h +145 -0
- package/dist/node_modules/isolated-vm/src/isolate/generic/callbacks.h +272 -0
- package/dist/node_modules/isolated-vm/src/isolate/generic/error.h +140 -0
- package/dist/node_modules/isolated-vm/src/isolate/generic/extract_params.h +145 -0
- package/dist/node_modules/isolated-vm/src/isolate/generic/handle_cast.h +257 -0
- package/dist/node_modules/isolated-vm/src/isolate/generic/read_option.h +47 -0
- package/dist/node_modules/isolated-vm/src/isolate/holder.cc +88 -0
- package/dist/node_modules/isolated-vm/src/isolate/holder.h +63 -0
- package/dist/node_modules/isolated-vm/src/isolate/inspector.cc +200 -0
- package/dist/node_modules/isolated-vm/src/isolate/inspector.h +70 -0
- package/dist/node_modules/isolated-vm/src/isolate/node_wrapper.h +15 -0
- package/dist/node_modules/isolated-vm/src/isolate/platform_delegate.cc +22 -0
- package/dist/node_modules/isolated-vm/src/isolate/platform_delegate.h +46 -0
- package/dist/node_modules/isolated-vm/src/isolate/remote_handle.h +164 -0
- package/dist/node_modules/isolated-vm/src/isolate/run_with_timeout.h +171 -0
- package/dist/node_modules/isolated-vm/src/isolate/runnable.h +29 -0
- package/dist/node_modules/isolated-vm/src/isolate/scheduler.cc +191 -0
- package/dist/node_modules/isolated-vm/src/isolate/scheduler.h +165 -0
- package/dist/node_modules/isolated-vm/src/isolate/specific.h +35 -0
- package/dist/node_modules/isolated-vm/src/isolate/stack_trace.cc +219 -0
- package/dist/node_modules/isolated-vm/src/isolate/stack_trace.h +24 -0
- package/dist/node_modules/isolated-vm/src/isolate/strings.h +127 -0
- package/dist/node_modules/isolated-vm/src/isolate/three_phase_task.cc +385 -0
- package/dist/node_modules/isolated-vm/src/isolate/three_phase_task.h +136 -0
- package/dist/node_modules/isolated-vm/src/isolate/transferable.h +15 -0
- package/dist/node_modules/isolated-vm/src/isolate/util.h +45 -0
- package/dist/node_modules/isolated-vm/src/isolate/v8_inspector_wrapper.h +12 -0
- package/dist/node_modules/isolated-vm/src/isolate/v8_version.h +12 -0
- package/dist/node_modules/isolated-vm/src/isolated_vm.h +71 -0
- package/dist/node_modules/isolated-vm/src/lib/covariant.h +50 -0
- package/dist/node_modules/isolated-vm/src/lib/lockable.h +178 -0
- package/dist/node_modules/isolated-vm/src/lib/suspend.h +106 -0
- package/dist/node_modules/isolated-vm/src/lib/thread_pool.cc +98 -0
- package/dist/node_modules/isolated-vm/src/lib/thread_pool.h +45 -0
- package/dist/node_modules/isolated-vm/src/lib/timer.cc +233 -0
- package/dist/node_modules/isolated-vm/src/lib/timer.h +36 -0
- package/dist/node_modules/isolated-vm/src/module/callback.cc +151 -0
- package/dist/node_modules/isolated-vm/src/module/callback.h +64 -0
- package/dist/node_modules/isolated-vm/src/module/context_handle.cc +241 -0
- package/dist/node_modules/isolated-vm/src/module/context_handle.h +35 -0
- package/dist/node_modules/isolated-vm/src/module/evaluation.cc +109 -0
- package/dist/node_modules/isolated-vm/src/module/evaluation.h +99 -0
- package/dist/node_modules/isolated-vm/src/module/external_copy_handle.cc +119 -0
- package/dist/node_modules/isolated-vm/src/module/external_copy_handle.h +64 -0
- package/dist/node_modules/isolated-vm/src/module/isolate.cc +136 -0
- package/dist/node_modules/isolated-vm/src/module/isolate_handle.cc +611 -0
- package/dist/node_modules/isolated-vm/src/module/isolate_handle.h +47 -0
- package/dist/node_modules/isolated-vm/src/module/lib_handle.cc +77 -0
- package/dist/node_modules/isolated-vm/src/module/lib_handle.h +28 -0
- package/dist/node_modules/isolated-vm/src/module/module_handle.cc +475 -0
- package/dist/node_modules/isolated-vm/src/module/module_handle.h +68 -0
- package/dist/node_modules/isolated-vm/src/module/native_module_handle.cc +104 -0
- package/dist/node_modules/isolated-vm/src/module/native_module_handle.h +49 -0
- package/dist/node_modules/isolated-vm/src/module/reference_handle.cc +636 -0
- package/dist/node_modules/isolated-vm/src/module/reference_handle.h +106 -0
- package/dist/node_modules/isolated-vm/src/module/script_handle.cc +107 -0
- package/dist/node_modules/isolated-vm/src/module/script_handle.h +37 -0
- package/dist/node_modules/isolated-vm/src/module/session_handle.cc +173 -0
- package/dist/node_modules/isolated-vm/src/module/session_handle.h +31 -0
- package/dist/node_modules/isolated-vm/src/module/transferable.cc +268 -0
- package/dist/node_modules/isolated-vm/src/module/transferable.h +42 -0
- package/dist/node_modules/isolated-vm/vendor/v8_inspector/nodejs_v18.0.0.h +360 -0
- package/dist/node_modules/isolated-vm/vendor/v8_inspector/nodejs_v18.3.0.h +376 -0
- package/dist/node_modules/isolated-vm/vendor/v8_inspector/nodejs_v20.0.0.h +397 -0
- package/dist/node_modules/isolated-vm/vendor/v8_inspector/nodejs_v22.0.0.h +419 -0
- 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/winston-transport/package.json +1 -1
- package/dist/server/IsolatedVm.js +75 -0
- package/dist/server/ScriptInstruction.d.ts +8 -0
- package/dist/server/ScriptInstruction.js +23 -1
- package/dist/server/Vm.js +42 -27
- package/package.json +4 -2
|
@@ -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
|
+
};
|