@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.
Files changed (145) hide show
  1. package/dist/client/index.js +1 -1
  2. package/dist/externalVersion.js +4 -4
  3. package/dist/node_modules/isolated-vm/.clang-tidy +13 -0
  4. package/dist/node_modules/isolated-vm/.dockerignore +9 -0
  5. package/dist/node_modules/isolated-vm/Dockerfile.alpine +9 -0
  6. package/dist/node_modules/isolated-vm/Dockerfile.debian +12 -0
  7. package/dist/node_modules/isolated-vm/LICENSE +13 -0
  8. package/dist/node_modules/isolated-vm/binding.gyp +120 -0
  9. package/dist/node_modules/isolated-vm/include.js +3 -0
  10. package/dist/node_modules/isolated-vm/inspector-example.js +59 -0
  11. package/dist/node_modules/isolated-vm/isolated-vm.d.ts +820 -0
  12. package/dist/node_modules/isolated-vm/isolated-vm.js +1 -0
  13. package/dist/node_modules/isolated-vm/native-example/binding.gyp +23 -0
  14. package/dist/node_modules/isolated-vm/native-example/example.cc +61 -0
  15. package/dist/node_modules/isolated-vm/native-example/package.json +13 -0
  16. package/dist/node_modules/isolated-vm/native-example/usage.js +35 -0
  17. package/dist/node_modules/isolated-vm/out/isolated_vm.node +0 -0
  18. package/dist/node_modules/isolated-vm/package.json +1 -0
  19. package/dist/node_modules/isolated-vm/src/external_copy/error.h +33 -0
  20. package/dist/node_modules/isolated-vm/src/external_copy/external_copy.cc +509 -0
  21. package/dist/node_modules/isolated-vm/src/external_copy/external_copy.h +117 -0
  22. package/dist/node_modules/isolated-vm/src/external_copy/serializer.cc +85 -0
  23. package/dist/node_modules/isolated-vm/src/external_copy/serializer.h +136 -0
  24. package/dist/node_modules/isolated-vm/src/external_copy/serializer_nortti.cc +73 -0
  25. package/dist/node_modules/isolated-vm/src/external_copy/string.cc +124 -0
  26. package/dist/node_modules/isolated-vm/src/external_copy/string.h +28 -0
  27. package/dist/node_modules/isolated-vm/src/isolate/allocator.h +32 -0
  28. package/dist/node_modules/isolated-vm/src/isolate/allocator_nortti.cc +142 -0
  29. package/dist/node_modules/isolated-vm/src/isolate/class_handle.h +334 -0
  30. package/dist/node_modules/isolated-vm/src/isolate/cpu_profile_manager.cc +220 -0
  31. package/dist/node_modules/isolated-vm/src/isolate/cpu_profile_manager.h +100 -0
  32. package/dist/node_modules/isolated-vm/src/isolate/environment.cc +626 -0
  33. package/dist/node_modules/isolated-vm/src/isolate/environment.h +381 -0
  34. package/dist/node_modules/isolated-vm/src/isolate/executor.cc +198 -0
  35. package/dist/node_modules/isolated-vm/src/isolate/executor.h +183 -0
  36. package/dist/node_modules/isolated-vm/src/isolate/external.h +64 -0
  37. package/dist/node_modules/isolated-vm/src/isolate/functor_runners.h +97 -0
  38. package/dist/node_modules/isolated-vm/src/isolate/generic/array.h +145 -0
  39. package/dist/node_modules/isolated-vm/src/isolate/generic/callbacks.h +272 -0
  40. package/dist/node_modules/isolated-vm/src/isolate/generic/error.h +140 -0
  41. package/dist/node_modules/isolated-vm/src/isolate/generic/extract_params.h +145 -0
  42. package/dist/node_modules/isolated-vm/src/isolate/generic/handle_cast.h +257 -0
  43. package/dist/node_modules/isolated-vm/src/isolate/generic/read_option.h +47 -0
  44. package/dist/node_modules/isolated-vm/src/isolate/holder.cc +88 -0
  45. package/dist/node_modules/isolated-vm/src/isolate/holder.h +63 -0
  46. package/dist/node_modules/isolated-vm/src/isolate/inspector.cc +200 -0
  47. package/dist/node_modules/isolated-vm/src/isolate/inspector.h +70 -0
  48. package/dist/node_modules/isolated-vm/src/isolate/node_wrapper.h +15 -0
  49. package/dist/node_modules/isolated-vm/src/isolate/platform_delegate.cc +22 -0
  50. package/dist/node_modules/isolated-vm/src/isolate/platform_delegate.h +46 -0
  51. package/dist/node_modules/isolated-vm/src/isolate/remote_handle.h +164 -0
  52. package/dist/node_modules/isolated-vm/src/isolate/run_with_timeout.h +171 -0
  53. package/dist/node_modules/isolated-vm/src/isolate/runnable.h +29 -0
  54. package/dist/node_modules/isolated-vm/src/isolate/scheduler.cc +191 -0
  55. package/dist/node_modules/isolated-vm/src/isolate/scheduler.h +165 -0
  56. package/dist/node_modules/isolated-vm/src/isolate/specific.h +35 -0
  57. package/dist/node_modules/isolated-vm/src/isolate/stack_trace.cc +219 -0
  58. package/dist/node_modules/isolated-vm/src/isolate/stack_trace.h +24 -0
  59. package/dist/node_modules/isolated-vm/src/isolate/strings.h +127 -0
  60. package/dist/node_modules/isolated-vm/src/isolate/three_phase_task.cc +385 -0
  61. package/dist/node_modules/isolated-vm/src/isolate/three_phase_task.h +136 -0
  62. package/dist/node_modules/isolated-vm/src/isolate/transferable.h +15 -0
  63. package/dist/node_modules/isolated-vm/src/isolate/util.h +45 -0
  64. package/dist/node_modules/isolated-vm/src/isolate/v8_inspector_wrapper.h +12 -0
  65. package/dist/node_modules/isolated-vm/src/isolate/v8_version.h +12 -0
  66. package/dist/node_modules/isolated-vm/src/isolated_vm.h +71 -0
  67. package/dist/node_modules/isolated-vm/src/lib/covariant.h +50 -0
  68. package/dist/node_modules/isolated-vm/src/lib/lockable.h +178 -0
  69. package/dist/node_modules/isolated-vm/src/lib/suspend.h +106 -0
  70. package/dist/node_modules/isolated-vm/src/lib/thread_pool.cc +98 -0
  71. package/dist/node_modules/isolated-vm/src/lib/thread_pool.h +45 -0
  72. package/dist/node_modules/isolated-vm/src/lib/timer.cc +233 -0
  73. package/dist/node_modules/isolated-vm/src/lib/timer.h +36 -0
  74. package/dist/node_modules/isolated-vm/src/module/callback.cc +151 -0
  75. package/dist/node_modules/isolated-vm/src/module/callback.h +64 -0
  76. package/dist/node_modules/isolated-vm/src/module/context_handle.cc +241 -0
  77. package/dist/node_modules/isolated-vm/src/module/context_handle.h +35 -0
  78. package/dist/node_modules/isolated-vm/src/module/evaluation.cc +109 -0
  79. package/dist/node_modules/isolated-vm/src/module/evaluation.h +99 -0
  80. package/dist/node_modules/isolated-vm/src/module/external_copy_handle.cc +119 -0
  81. package/dist/node_modules/isolated-vm/src/module/external_copy_handle.h +64 -0
  82. package/dist/node_modules/isolated-vm/src/module/isolate.cc +136 -0
  83. package/dist/node_modules/isolated-vm/src/module/isolate_handle.cc +611 -0
  84. package/dist/node_modules/isolated-vm/src/module/isolate_handle.h +47 -0
  85. package/dist/node_modules/isolated-vm/src/module/lib_handle.cc +77 -0
  86. package/dist/node_modules/isolated-vm/src/module/lib_handle.h +28 -0
  87. package/dist/node_modules/isolated-vm/src/module/module_handle.cc +475 -0
  88. package/dist/node_modules/isolated-vm/src/module/module_handle.h +68 -0
  89. package/dist/node_modules/isolated-vm/src/module/native_module_handle.cc +104 -0
  90. package/dist/node_modules/isolated-vm/src/module/native_module_handle.h +49 -0
  91. package/dist/node_modules/isolated-vm/src/module/reference_handle.cc +636 -0
  92. package/dist/node_modules/isolated-vm/src/module/reference_handle.h +106 -0
  93. package/dist/node_modules/isolated-vm/src/module/script_handle.cc +107 -0
  94. package/dist/node_modules/isolated-vm/src/module/script_handle.h +37 -0
  95. package/dist/node_modules/isolated-vm/src/module/session_handle.cc +173 -0
  96. package/dist/node_modules/isolated-vm/src/module/session_handle.h +31 -0
  97. package/dist/node_modules/isolated-vm/src/module/transferable.cc +268 -0
  98. package/dist/node_modules/isolated-vm/src/module/transferable.h +42 -0
  99. package/dist/node_modules/isolated-vm/vendor/v8_inspector/nodejs_v18.0.0.h +360 -0
  100. package/dist/node_modules/isolated-vm/vendor/v8_inspector/nodejs_v18.3.0.h +376 -0
  101. package/dist/node_modules/isolated-vm/vendor/v8_inspector/nodejs_v20.0.0.h +397 -0
  102. package/dist/node_modules/isolated-vm/vendor/v8_inspector/nodejs_v22.0.0.h +419 -0
  103. package/dist/node_modules/joi/dist/joi-browser.min.js +1 -0
  104. package/dist/node_modules/joi/lib/annotate.js +175 -0
  105. package/dist/node_modules/joi/lib/base.js +1069 -0
  106. package/dist/node_modules/joi/lib/cache.js +143 -0
  107. package/dist/node_modules/joi/lib/common.js +216 -0
  108. package/dist/node_modules/joi/lib/compile.js +283 -0
  109. package/dist/node_modules/joi/lib/errors.js +271 -0
  110. package/dist/node_modules/joi/lib/extend.js +312 -0
  111. package/dist/node_modules/joi/lib/index.d.ts +2365 -0
  112. package/dist/node_modules/joi/lib/index.js +1 -0
  113. package/dist/node_modules/joi/lib/manifest.js +476 -0
  114. package/dist/node_modules/joi/lib/messages.js +178 -0
  115. package/dist/node_modules/joi/lib/modify.js +267 -0
  116. package/dist/node_modules/joi/lib/ref.js +414 -0
  117. package/dist/node_modules/joi/lib/schemas.js +302 -0
  118. package/dist/node_modules/joi/lib/state.js +166 -0
  119. package/dist/node_modules/joi/lib/template.js +463 -0
  120. package/dist/node_modules/joi/lib/trace.js +346 -0
  121. package/dist/node_modules/joi/lib/types/alternatives.js +364 -0
  122. package/dist/node_modules/joi/lib/types/any.js +174 -0
  123. package/dist/node_modules/joi/lib/types/array.js +809 -0
  124. package/dist/node_modules/joi/lib/types/binary.js +100 -0
  125. package/dist/node_modules/joi/lib/types/boolean.js +150 -0
  126. package/dist/node_modules/joi/lib/types/date.js +233 -0
  127. package/dist/node_modules/joi/lib/types/function.js +93 -0
  128. package/dist/node_modules/joi/lib/types/keys.js +1067 -0
  129. package/dist/node_modules/joi/lib/types/link.js +168 -0
  130. package/dist/node_modules/joi/lib/types/number.js +363 -0
  131. package/dist/node_modules/joi/lib/types/object.js +22 -0
  132. package/dist/node_modules/joi/lib/types/string.js +850 -0
  133. package/dist/node_modules/joi/lib/types/symbol.js +102 -0
  134. package/dist/node_modules/joi/lib/validator.js +750 -0
  135. package/dist/node_modules/joi/lib/values.js +263 -0
  136. package/dist/node_modules/joi/node_modules/@hapi/topo/lib/index.d.ts +60 -0
  137. package/dist/node_modules/joi/node_modules/@hapi/topo/lib/index.js +225 -0
  138. package/dist/node_modules/joi/node_modules/@hapi/topo/package.json +30 -0
  139. package/dist/node_modules/joi/package.json +1 -0
  140. package/dist/node_modules/winston-transport/package.json +1 -1
  141. package/dist/server/IsolatedVm.js +75 -0
  142. package/dist/server/ScriptInstruction.d.ts +8 -0
  143. package/dist/server/ScriptInstruction.js +23 -1
  144. package/dist/server/Vm.js +42 -27
  145. package/package.json +4 -2
@@ -0,0 +1,267 @@
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
+
13
+ exports.Ids = internals.Ids = class {
14
+
15
+ constructor() {
16
+
17
+ this._byId = new Map();
18
+ this._byKey = new Map();
19
+ this._schemaChain = false;
20
+ }
21
+
22
+ clone() {
23
+
24
+ const clone = new internals.Ids();
25
+ clone._byId = new Map(this._byId);
26
+ clone._byKey = new Map(this._byKey);
27
+ clone._schemaChain = this._schemaChain;
28
+ return clone;
29
+ }
30
+
31
+ concat(source) {
32
+
33
+ if (source._schemaChain) {
34
+ this._schemaChain = true;
35
+ }
36
+
37
+ for (const [id, value] of source._byId.entries()) {
38
+ Assert(!this._byKey.has(id), 'Schema id conflicts with existing key:', id);
39
+ this._byId.set(id, value);
40
+ }
41
+
42
+ for (const [key, value] of source._byKey.entries()) {
43
+ Assert(!this._byId.has(key), 'Schema key conflicts with existing id:', key);
44
+ this._byKey.set(key, value);
45
+ }
46
+ }
47
+
48
+ fork(path, adjuster, root) {
49
+
50
+ const chain = this._collect(path);
51
+ chain.push({ schema: root });
52
+ const tail = chain.shift();
53
+ let adjusted = { id: tail.id, schema: adjuster(tail.schema) };
54
+
55
+ Assert(Common.isSchema(adjusted.schema), 'adjuster function failed to return a joi schema type');
56
+
57
+ for (const node of chain) {
58
+ adjusted = { id: node.id, schema: internals.fork(node.schema, adjusted.id, adjusted.schema) };
59
+ }
60
+
61
+ return adjusted.schema;
62
+ }
63
+
64
+ labels(path, behind = []) {
65
+
66
+ const current = path[0];
67
+ const node = this._get(current);
68
+ if (!node) {
69
+ return [...behind, ...path].join('.');
70
+ }
71
+
72
+ const forward = path.slice(1);
73
+ behind = [...behind, node.schema._flags.label || current];
74
+ if (!forward.length) {
75
+ return behind.join('.');
76
+ }
77
+
78
+ return node.schema._ids.labels(forward, behind);
79
+ }
80
+
81
+ reach(path, behind = []) {
82
+
83
+ const current = path[0];
84
+ const node = this._get(current);
85
+ Assert(node, 'Schema does not contain path', [...behind, ...path].join('.'));
86
+
87
+ const forward = path.slice(1);
88
+ if (!forward.length) {
89
+ return node.schema;
90
+ }
91
+
92
+ return node.schema._ids.reach(forward, [...behind, current]);
93
+ }
94
+
95
+ register(schema, { key } = {}) {
96
+
97
+ if (!schema ||
98
+ !Common.isSchema(schema)) {
99
+
100
+ return;
101
+ }
102
+
103
+ if (schema.$_property('schemaChain') ||
104
+ schema._ids._schemaChain) {
105
+
106
+ this._schemaChain = true;
107
+ }
108
+
109
+ const id = schema._flags.id;
110
+ if (id) {
111
+ const existing = this._byId.get(id);
112
+ Assert(!existing || existing.schema === schema, 'Cannot add different schemas with the same id:', id);
113
+ Assert(!this._byKey.has(id), 'Schema id conflicts with existing key:', id);
114
+
115
+ this._byId.set(id, { schema, id });
116
+ }
117
+
118
+ if (key) {
119
+ Assert(!this._byKey.has(key), 'Schema already contains key:', key);
120
+ Assert(!this._byId.has(key), 'Schema key conflicts with existing id:', key);
121
+
122
+ this._byKey.set(key, { schema, id: key });
123
+ }
124
+ }
125
+
126
+ reset() {
127
+
128
+ this._byId = new Map();
129
+ this._byKey = new Map();
130
+ this._schemaChain = false;
131
+ }
132
+
133
+ _collect(path, behind = [], nodes = []) {
134
+
135
+ const current = path[0];
136
+ const node = this._get(current);
137
+ Assert(node, 'Schema does not contain path', [...behind, ...path].join('.'));
138
+
139
+ nodes = [node, ...nodes];
140
+
141
+ const forward = path.slice(1);
142
+ if (!forward.length) {
143
+ return nodes;
144
+ }
145
+
146
+ return node.schema._ids._collect(forward, [...behind, current], nodes);
147
+ }
148
+
149
+ _get(id) {
150
+
151
+ return this._byId.get(id) || this._byKey.get(id);
152
+ }
153
+ };
154
+
155
+
156
+ internals.fork = function (schema, id, replacement) {
157
+
158
+ const each = (item, { key }) => {
159
+
160
+ if (id === (item._flags.id || key)) {
161
+ return replacement;
162
+ }
163
+ };
164
+
165
+ const obj = exports.schema(schema, { each, ref: false });
166
+ return obj ? obj.$_mutateRebuild() : schema;
167
+ };
168
+
169
+
170
+ exports.schema = function (schema, options) {
171
+
172
+ let obj;
173
+
174
+ for (const name in schema._flags) {
175
+ if (name[0] === '_') {
176
+ continue;
177
+ }
178
+
179
+ const result = internals.scan(schema._flags[name], { source: 'flags', name }, options);
180
+ if (result !== undefined) {
181
+ obj = obj || schema.clone();
182
+ obj._flags[name] = result;
183
+ }
184
+ }
185
+
186
+ for (let i = 0; i < schema._rules.length; ++i) {
187
+ const rule = schema._rules[i];
188
+ const result = internals.scan(rule.args, { source: 'rules', name: rule.name }, options);
189
+ if (result !== undefined) {
190
+ obj = obj || schema.clone();
191
+ const clone = Object.assign({}, rule);
192
+ clone.args = result;
193
+ obj._rules[i] = clone;
194
+
195
+ const existingUnique = obj._singleRules.get(rule.name);
196
+ if (existingUnique === rule) {
197
+ obj._singleRules.set(rule.name, clone);
198
+ }
199
+ }
200
+ }
201
+
202
+ for (const name in schema.$_terms) {
203
+ if (name[0] === '_') {
204
+ continue;
205
+ }
206
+
207
+ const result = internals.scan(schema.$_terms[name], { source: 'terms', name }, options);
208
+ if (result !== undefined) {
209
+ obj = obj || schema.clone();
210
+ obj.$_terms[name] = result;
211
+ }
212
+ }
213
+
214
+ return obj;
215
+ };
216
+
217
+
218
+ internals.scan = function (item, source, options, _path, _key) {
219
+
220
+ const path = _path || [];
221
+
222
+ if (item === null ||
223
+ typeof item !== 'object') {
224
+
225
+ return;
226
+ }
227
+
228
+ let clone;
229
+
230
+ if (Array.isArray(item)) {
231
+ for (let i = 0; i < item.length; ++i) {
232
+ const key = source.source === 'terms' && source.name === 'keys' && item[i].key;
233
+ const result = internals.scan(item[i], source, options, [i, ...path], key);
234
+ if (result !== undefined) {
235
+ clone = clone || item.slice();
236
+ clone[i] = result;
237
+ }
238
+ }
239
+
240
+ return clone;
241
+ }
242
+
243
+ if (options.schema !== false && Common.isSchema(item) ||
244
+ options.ref !== false && Ref.isRef(item)) {
245
+
246
+ const result = options.each(item, { ...source, path, key: _key });
247
+ if (result === item) {
248
+ return;
249
+ }
250
+
251
+ return result;
252
+ }
253
+
254
+ for (const key in item) {
255
+ if (key[0] === '_') {
256
+ continue;
257
+ }
258
+
259
+ const result = internals.scan(item[key], source, options, [key, ...path], _key);
260
+ if (result !== undefined) {
261
+ clone = clone || Object.assign({}, item);
262
+ clone[key] = result;
263
+ }
264
+ }
265
+
266
+ return clone;
267
+ };
@@ -0,0 +1,414 @@
1
+ 'use strict';
2
+
3
+ const Assert = require('@hapi/hoek/lib/assert');
4
+ const Clone = require('@hapi/hoek/lib/clone');
5
+ const Reach = require('@hapi/hoek/lib/reach');
6
+
7
+ const Common = require('./common');
8
+
9
+ let Template;
10
+
11
+
12
+ const internals = {
13
+ symbol: Symbol('ref'), // Used to internally identify references (shared with other joi versions)
14
+ defaults: {
15
+ adjust: null,
16
+ in: false,
17
+ iterables: null,
18
+ map: null,
19
+ separator: '.',
20
+ type: 'value'
21
+ }
22
+ };
23
+
24
+
25
+ exports.create = function (key, options = {}) {
26
+
27
+ Assert(typeof key === 'string', 'Invalid reference key:', key);
28
+ Common.assertOptions(options, ['adjust', 'ancestor', 'in', 'iterables', 'map', 'prefix', 'render', 'separator']);
29
+ Assert(!options.prefix || typeof options.prefix === 'object', 'options.prefix must be of type object');
30
+
31
+ const ref = Object.assign({}, internals.defaults, options);
32
+ delete ref.prefix;
33
+
34
+ const separator = ref.separator;
35
+ const context = internals.context(key, separator, options.prefix);
36
+ ref.type = context.type;
37
+ key = context.key;
38
+
39
+ if (ref.type === 'value') {
40
+ if (context.root) {
41
+ Assert(!separator || key[0] !== separator, 'Cannot specify relative path with root prefix');
42
+ ref.ancestor = 'root';
43
+ if (!key) {
44
+ key = null;
45
+ }
46
+ }
47
+
48
+ if (separator &&
49
+ separator === key) {
50
+
51
+ key = null;
52
+ ref.ancestor = 0;
53
+ }
54
+ else {
55
+ if (ref.ancestor !== undefined) {
56
+ Assert(!separator || !key || key[0] !== separator, 'Cannot combine prefix with ancestor option');
57
+ }
58
+ else {
59
+ const [ancestor, slice] = internals.ancestor(key, separator);
60
+ if (slice) {
61
+ key = key.slice(slice);
62
+ if (key === '') {
63
+ key = null;
64
+ }
65
+ }
66
+
67
+ ref.ancestor = ancestor;
68
+ }
69
+ }
70
+ }
71
+
72
+ ref.path = separator ? (key === null ? [] : key.split(separator)) : [key];
73
+
74
+ return new internals.Ref(ref);
75
+ };
76
+
77
+
78
+ exports.in = function (key, options = {}) {
79
+
80
+ return exports.create(key, { ...options, in: true });
81
+ };
82
+
83
+
84
+ exports.isRef = function (ref) {
85
+
86
+ return ref ? !!ref[Common.symbols.ref] : false;
87
+ };
88
+
89
+
90
+ internals.Ref = class {
91
+
92
+ constructor(options) {
93
+
94
+ Assert(typeof options === 'object', 'Invalid reference construction');
95
+ Common.assertOptions(options, [
96
+ 'adjust', 'ancestor', 'in', 'iterables', 'map', 'path', 'render', 'separator', 'type', // Copied
97
+ 'depth', 'key', 'root', 'display' // Overridden
98
+ ]);
99
+
100
+ Assert([false, undefined].includes(options.separator) || typeof options.separator === 'string' && options.separator.length === 1, 'Invalid separator');
101
+ Assert(!options.adjust || typeof options.adjust === 'function', 'options.adjust must be a function');
102
+ Assert(!options.map || Array.isArray(options.map), 'options.map must be an array');
103
+ Assert(!options.map || !options.adjust, 'Cannot set both map and adjust options');
104
+
105
+ Object.assign(this, internals.defaults, options);
106
+
107
+ Assert(this.type === 'value' || this.ancestor === undefined, 'Non-value references cannot reference ancestors');
108
+
109
+ if (Array.isArray(this.map)) {
110
+ this.map = new Map(this.map);
111
+ }
112
+
113
+ this.depth = this.path.length;
114
+ this.key = this.path.length ? this.path.join(this.separator) : null;
115
+ this.root = this.path[0];
116
+
117
+ this.updateDisplay();
118
+ }
119
+
120
+ resolve(value, state, prefs, local, options = {}) {
121
+
122
+ Assert(!this.in || options.in, 'Invalid in() reference usage');
123
+
124
+ if (this.type === 'global') {
125
+ return this._resolve(prefs.context, state, options);
126
+ }
127
+
128
+ if (this.type === 'local') {
129
+ return this._resolve(local, state, options);
130
+ }
131
+
132
+ if (!this.ancestor) {
133
+ return this._resolve(value, state, options);
134
+ }
135
+
136
+ if (this.ancestor === 'root') {
137
+ return this._resolve(state.ancestors[state.ancestors.length - 1], state, options);
138
+ }
139
+
140
+ Assert(this.ancestor <= state.ancestors.length, 'Invalid reference exceeds the schema root:', this.display);
141
+ return this._resolve(state.ancestors[this.ancestor - 1], state, options);
142
+ }
143
+
144
+ _resolve(target, state, options) {
145
+
146
+ let resolved;
147
+
148
+ if (this.type === 'value' &&
149
+ state.mainstay.shadow &&
150
+ options.shadow !== false) {
151
+
152
+ resolved = state.mainstay.shadow.get(this.absolute(state));
153
+ }
154
+
155
+ if (resolved === undefined) {
156
+ resolved = Reach(target, this.path, { iterables: this.iterables, functions: true });
157
+ }
158
+
159
+ if (this.adjust) {
160
+ resolved = this.adjust(resolved);
161
+ }
162
+
163
+ if (this.map) {
164
+ const mapped = this.map.get(resolved);
165
+ if (mapped !== undefined) {
166
+ resolved = mapped;
167
+ }
168
+ }
169
+
170
+ if (state.mainstay) {
171
+ state.mainstay.tracer.resolve(state, this, resolved);
172
+ }
173
+
174
+ return resolved;
175
+ }
176
+
177
+ toString() {
178
+
179
+ return this.display;
180
+ }
181
+
182
+ absolute(state) {
183
+
184
+ return [...state.path.slice(0, -this.ancestor), ...this.path];
185
+ }
186
+
187
+ clone() {
188
+
189
+ return new internals.Ref(this);
190
+ }
191
+
192
+ describe() {
193
+
194
+ const ref = { path: this.path };
195
+
196
+ if (this.type !== 'value') {
197
+ ref.type = this.type;
198
+ }
199
+
200
+ if (this.separator !== '.') {
201
+ ref.separator = this.separator;
202
+ }
203
+
204
+ if (this.type === 'value' &&
205
+ this.ancestor !== 1) {
206
+
207
+ ref.ancestor = this.ancestor;
208
+ }
209
+
210
+ if (this.map) {
211
+ ref.map = [...this.map];
212
+ }
213
+
214
+ for (const key of ['adjust', 'iterables', 'render']) {
215
+ if (this[key] !== null &&
216
+ this[key] !== undefined) {
217
+
218
+ ref[key] = this[key];
219
+ }
220
+ }
221
+
222
+ if (this.in !== false) {
223
+ ref.in = true;
224
+ }
225
+
226
+ return { ref };
227
+ }
228
+
229
+ updateDisplay() {
230
+
231
+ const key = this.key !== null ? this.key : '';
232
+ if (this.type !== 'value') {
233
+ this.display = `ref:${this.type}:${key}`;
234
+ return;
235
+ }
236
+
237
+ if (!this.separator) {
238
+ this.display = `ref:${key}`;
239
+ return;
240
+ }
241
+
242
+ if (!this.ancestor) {
243
+ this.display = `ref:${this.separator}${key}`;
244
+ return;
245
+ }
246
+
247
+ if (this.ancestor === 'root') {
248
+ this.display = `ref:root:${key}`;
249
+ return;
250
+ }
251
+
252
+ if (this.ancestor === 1) {
253
+ this.display = `ref:${key || '..'}`;
254
+ return;
255
+ }
256
+
257
+ const lead = new Array(this.ancestor + 1).fill(this.separator).join('');
258
+ this.display = `ref:${lead}${key || ''}`;
259
+ }
260
+ };
261
+
262
+
263
+ internals.Ref.prototype[Common.symbols.ref] = true;
264
+
265
+
266
+ exports.build = function (desc) {
267
+
268
+ desc = Object.assign({}, internals.defaults, desc);
269
+ if (desc.type === 'value' &&
270
+ desc.ancestor === undefined) {
271
+
272
+ desc.ancestor = 1;
273
+ }
274
+
275
+ return new internals.Ref(desc);
276
+ };
277
+
278
+
279
+ internals.context = function (key, separator, prefix = {}) {
280
+
281
+ key = key.trim();
282
+
283
+ if (prefix) {
284
+ const globalp = prefix.global === undefined ? '$' : prefix.global;
285
+ if (globalp !== separator &&
286
+ key.startsWith(globalp)) {
287
+
288
+ return { key: key.slice(globalp.length), type: 'global' };
289
+ }
290
+
291
+ const local = prefix.local === undefined ? '#' : prefix.local;
292
+ if (local !== separator &&
293
+ key.startsWith(local)) {
294
+
295
+ return { key: key.slice(local.length), type: 'local' };
296
+ }
297
+
298
+ const root = prefix.root === undefined ? '/' : prefix.root;
299
+ if (root !== separator &&
300
+ key.startsWith(root)) {
301
+
302
+ return { key: key.slice(root.length), type: 'value', root: true };
303
+ }
304
+ }
305
+
306
+ return { key, type: 'value' };
307
+ };
308
+
309
+
310
+ internals.ancestor = function (key, separator) {
311
+
312
+ if (!separator) {
313
+ return [1, 0]; // 'a_b' -> 1 (parent)
314
+ }
315
+
316
+ if (key[0] !== separator) { // 'a.b' -> 1 (parent)
317
+ return [1, 0];
318
+ }
319
+
320
+ if (key[1] !== separator) { // '.a.b' -> 0 (self)
321
+ return [0, 1];
322
+ }
323
+
324
+ let i = 2;
325
+ while (key[i] === separator) {
326
+ ++i;
327
+ }
328
+
329
+ return [i - 1, i]; // '...a.b.' -> 2 (grandparent)
330
+ };
331
+
332
+
333
+ exports.toSibling = 0;
334
+
335
+ exports.toParent = 1;
336
+
337
+
338
+ exports.Manager = class {
339
+
340
+ constructor() {
341
+
342
+ this.refs = []; // 0: [self refs], 1: [parent refs], 2: [grandparent refs], ...
343
+ }
344
+
345
+ register(source, target) {
346
+
347
+ if (!source) {
348
+ return;
349
+ }
350
+
351
+ target = target === undefined ? exports.toParent : target;
352
+
353
+ // Array
354
+
355
+ if (Array.isArray(source)) {
356
+ for (const ref of source) {
357
+ this.register(ref, target);
358
+ }
359
+
360
+ return;
361
+ }
362
+
363
+ // Schema
364
+
365
+ if (Common.isSchema(source)) {
366
+ for (const item of source._refs.refs) {
367
+ if (item.ancestor - target >= 0) {
368
+ this.refs.push({ ancestor: item.ancestor - target, root: item.root });
369
+ }
370
+ }
371
+
372
+ return;
373
+ }
374
+
375
+ // Reference
376
+
377
+ if (exports.isRef(source) &&
378
+ source.type === 'value' &&
379
+ source.ancestor - target >= 0) {
380
+
381
+ this.refs.push({ ancestor: source.ancestor - target, root: source.root });
382
+ }
383
+
384
+ // Template
385
+
386
+ Template = Template || require('./template');
387
+
388
+ if (Template.isTemplate(source)) {
389
+ this.register(source.refs(), target);
390
+ }
391
+ }
392
+
393
+ get length() {
394
+
395
+ return this.refs.length;
396
+ }
397
+
398
+ clone() {
399
+
400
+ const copy = new exports.Manager();
401
+ copy.refs = Clone(this.refs);
402
+ return copy;
403
+ }
404
+
405
+ reset() {
406
+
407
+ this.refs = [];
408
+ }
409
+
410
+ roots() {
411
+
412
+ return this.refs.filter((ref) => !ref.ancestor).map((ref) => ref.root);
413
+ }
414
+ };