@nocobase/plugin-workflow-request-interceptor 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.
- package/dist/client/RequestInterceptionTrigger.d.ts +10 -0
- package/dist/client/index.js +1 -1
- package/dist/externalVersion.js +7 -7
- 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/server/RequestInterceptionTrigger.d.ts +3 -0
- package/dist/server/RequestInterceptionTrigger.js +62 -5
- package/package.json +5 -2
|
@@ -0,0 +1,263 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
const Assert = require('@hapi/hoek/lib/assert');
|
|
4
|
+
const DeepEqual = require('@hapi/hoek/lib/deepEqual');
|
|
5
|
+
|
|
6
|
+
const Common = require('./common');
|
|
7
|
+
|
|
8
|
+
|
|
9
|
+
const internals = {};
|
|
10
|
+
|
|
11
|
+
|
|
12
|
+
module.exports = internals.Values = class {
|
|
13
|
+
|
|
14
|
+
constructor(values, refs) {
|
|
15
|
+
|
|
16
|
+
this._values = new Set(values);
|
|
17
|
+
this._refs = new Set(refs);
|
|
18
|
+
this._lowercase = internals.lowercases(values);
|
|
19
|
+
|
|
20
|
+
this._override = false;
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
get length() {
|
|
24
|
+
|
|
25
|
+
return this._values.size + this._refs.size;
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
add(value, refs) {
|
|
29
|
+
|
|
30
|
+
// Reference
|
|
31
|
+
|
|
32
|
+
if (Common.isResolvable(value)) {
|
|
33
|
+
if (!this._refs.has(value)) {
|
|
34
|
+
this._refs.add(value);
|
|
35
|
+
|
|
36
|
+
if (refs) { // Skipped in a merge
|
|
37
|
+
refs.register(value);
|
|
38
|
+
}
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
return;
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
// Value
|
|
45
|
+
|
|
46
|
+
if (!this.has(value, null, null, false)) {
|
|
47
|
+
this._values.add(value);
|
|
48
|
+
|
|
49
|
+
if (typeof value === 'string') {
|
|
50
|
+
this._lowercase.set(value.toLowerCase(), value);
|
|
51
|
+
}
|
|
52
|
+
}
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
static merge(target, source, remove) {
|
|
56
|
+
|
|
57
|
+
target = target || new internals.Values();
|
|
58
|
+
|
|
59
|
+
if (source) {
|
|
60
|
+
if (source._override) {
|
|
61
|
+
return source.clone();
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
for (const item of [...source._values, ...source._refs]) {
|
|
65
|
+
target.add(item);
|
|
66
|
+
}
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
if (remove) {
|
|
70
|
+
for (const item of [...remove._values, ...remove._refs]) {
|
|
71
|
+
target.remove(item);
|
|
72
|
+
}
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
return target.length ? target : null;
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
remove(value) {
|
|
79
|
+
|
|
80
|
+
// Reference
|
|
81
|
+
|
|
82
|
+
if (Common.isResolvable(value)) {
|
|
83
|
+
this._refs.delete(value);
|
|
84
|
+
return;
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
// Value
|
|
88
|
+
|
|
89
|
+
this._values.delete(value);
|
|
90
|
+
|
|
91
|
+
if (typeof value === 'string') {
|
|
92
|
+
this._lowercase.delete(value.toLowerCase());
|
|
93
|
+
}
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
has(value, state, prefs, insensitive) {
|
|
97
|
+
|
|
98
|
+
return !!this.get(value, state, prefs, insensitive);
|
|
99
|
+
}
|
|
100
|
+
|
|
101
|
+
get(value, state, prefs, insensitive) {
|
|
102
|
+
|
|
103
|
+
if (!this.length) {
|
|
104
|
+
return false;
|
|
105
|
+
}
|
|
106
|
+
|
|
107
|
+
// Simple match
|
|
108
|
+
|
|
109
|
+
if (this._values.has(value)) {
|
|
110
|
+
return { value };
|
|
111
|
+
}
|
|
112
|
+
|
|
113
|
+
// Case insensitive string match
|
|
114
|
+
|
|
115
|
+
if (typeof value === 'string' &&
|
|
116
|
+
value &&
|
|
117
|
+
insensitive) {
|
|
118
|
+
|
|
119
|
+
const found = this._lowercase.get(value.toLowerCase());
|
|
120
|
+
if (found) {
|
|
121
|
+
return { value: found };
|
|
122
|
+
}
|
|
123
|
+
}
|
|
124
|
+
|
|
125
|
+
if (!this._refs.size &&
|
|
126
|
+
typeof value !== 'object') {
|
|
127
|
+
|
|
128
|
+
return false;
|
|
129
|
+
}
|
|
130
|
+
|
|
131
|
+
// Objects
|
|
132
|
+
|
|
133
|
+
if (typeof value === 'object') {
|
|
134
|
+
for (const item of this._values) {
|
|
135
|
+
if (DeepEqual(item, value)) {
|
|
136
|
+
return { value: item };
|
|
137
|
+
}
|
|
138
|
+
}
|
|
139
|
+
}
|
|
140
|
+
|
|
141
|
+
// References
|
|
142
|
+
|
|
143
|
+
if (state) {
|
|
144
|
+
for (const ref of this._refs) {
|
|
145
|
+
const resolved = ref.resolve(value, state, prefs, null, { in: true });
|
|
146
|
+
if (resolved === undefined) {
|
|
147
|
+
continue;
|
|
148
|
+
}
|
|
149
|
+
|
|
150
|
+
const items = !ref.in || typeof resolved !== 'object'
|
|
151
|
+
? [resolved]
|
|
152
|
+
: Array.isArray(resolved) ? resolved : Object.keys(resolved);
|
|
153
|
+
|
|
154
|
+
for (const item of items) {
|
|
155
|
+
if (typeof item !== typeof value) {
|
|
156
|
+
continue;
|
|
157
|
+
}
|
|
158
|
+
|
|
159
|
+
if (insensitive &&
|
|
160
|
+
value &&
|
|
161
|
+
typeof value === 'string') {
|
|
162
|
+
|
|
163
|
+
if (item.toLowerCase() === value.toLowerCase()) {
|
|
164
|
+
return { value: item, ref };
|
|
165
|
+
}
|
|
166
|
+
}
|
|
167
|
+
else {
|
|
168
|
+
if (DeepEqual(item, value)) {
|
|
169
|
+
return { value: item, ref };
|
|
170
|
+
}
|
|
171
|
+
}
|
|
172
|
+
}
|
|
173
|
+
}
|
|
174
|
+
}
|
|
175
|
+
|
|
176
|
+
return false;
|
|
177
|
+
}
|
|
178
|
+
|
|
179
|
+
override() {
|
|
180
|
+
|
|
181
|
+
this._override = true;
|
|
182
|
+
}
|
|
183
|
+
|
|
184
|
+
values(options) {
|
|
185
|
+
|
|
186
|
+
if (options &&
|
|
187
|
+
options.display) {
|
|
188
|
+
|
|
189
|
+
const values = [];
|
|
190
|
+
|
|
191
|
+
for (const item of [...this._values, ...this._refs]) {
|
|
192
|
+
if (item !== undefined) {
|
|
193
|
+
values.push(item);
|
|
194
|
+
}
|
|
195
|
+
}
|
|
196
|
+
|
|
197
|
+
return values;
|
|
198
|
+
}
|
|
199
|
+
|
|
200
|
+
return Array.from([...this._values, ...this._refs]);
|
|
201
|
+
}
|
|
202
|
+
|
|
203
|
+
clone() {
|
|
204
|
+
|
|
205
|
+
const set = new internals.Values(this._values, this._refs);
|
|
206
|
+
set._override = this._override;
|
|
207
|
+
return set;
|
|
208
|
+
}
|
|
209
|
+
|
|
210
|
+
concat(source) {
|
|
211
|
+
|
|
212
|
+
Assert(!source._override, 'Cannot concat override set of values');
|
|
213
|
+
|
|
214
|
+
const set = new internals.Values([...this._values, ...source._values], [...this._refs, ...source._refs]);
|
|
215
|
+
set._override = this._override;
|
|
216
|
+
return set;
|
|
217
|
+
}
|
|
218
|
+
|
|
219
|
+
describe() {
|
|
220
|
+
|
|
221
|
+
const normalized = [];
|
|
222
|
+
|
|
223
|
+
if (this._override) {
|
|
224
|
+
normalized.push({ override: true });
|
|
225
|
+
}
|
|
226
|
+
|
|
227
|
+
for (const value of this._values.values()) {
|
|
228
|
+
normalized.push(value && typeof value === 'object' ? { value } : value);
|
|
229
|
+
}
|
|
230
|
+
|
|
231
|
+
for (const value of this._refs.values()) {
|
|
232
|
+
normalized.push(value.describe());
|
|
233
|
+
}
|
|
234
|
+
|
|
235
|
+
return normalized;
|
|
236
|
+
}
|
|
237
|
+
};
|
|
238
|
+
|
|
239
|
+
|
|
240
|
+
internals.Values.prototype[Common.symbols.values] = true;
|
|
241
|
+
|
|
242
|
+
|
|
243
|
+
// Aliases
|
|
244
|
+
|
|
245
|
+
internals.Values.prototype.slice = internals.Values.prototype.clone;
|
|
246
|
+
|
|
247
|
+
|
|
248
|
+
// Helpers
|
|
249
|
+
|
|
250
|
+
internals.lowercases = function (from) {
|
|
251
|
+
|
|
252
|
+
const map = new Map();
|
|
253
|
+
|
|
254
|
+
if (from) {
|
|
255
|
+
for (const value of from) {
|
|
256
|
+
if (typeof value === 'string') {
|
|
257
|
+
map.set(value.toLowerCase(), value);
|
|
258
|
+
}
|
|
259
|
+
}
|
|
260
|
+
}
|
|
261
|
+
|
|
262
|
+
return map;
|
|
263
|
+
};
|
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
export class Sorter<T> {
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* An array of the topologically sorted nodes. This list is renewed upon each call to topo.add().
|
|
5
|
+
*/
|
|
6
|
+
nodes: T[];
|
|
7
|
+
|
|
8
|
+
/**
|
|
9
|
+
* Adds a node or list of nodes to be added and topologically sorted
|
|
10
|
+
*
|
|
11
|
+
* @param nodes - A mixed value or array of mixed values to be added as nodes to the topologically sorted list.
|
|
12
|
+
* @param options - Optional sorting information about the nodes.
|
|
13
|
+
*
|
|
14
|
+
* @returns Returns an array of the topologically sorted nodes.
|
|
15
|
+
*/
|
|
16
|
+
add(nodes: T | T[], options?: Options): T[];
|
|
17
|
+
|
|
18
|
+
/**
|
|
19
|
+
* Merges another Sorter object into the current object.
|
|
20
|
+
*
|
|
21
|
+
* @param others - The other object or array of objects to be merged into the current one.
|
|
22
|
+
*
|
|
23
|
+
* @returns Returns an array of the topologically sorted nodes.
|
|
24
|
+
*/
|
|
25
|
+
merge(others: Sorter<T> | Sorter<T>[]): T[];
|
|
26
|
+
|
|
27
|
+
/**
|
|
28
|
+
* Sorts the nodes array (only required if the manual option is used when adding items)
|
|
29
|
+
*/
|
|
30
|
+
sort(): T[];
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
|
|
34
|
+
export interface Options {
|
|
35
|
+
|
|
36
|
+
/**
|
|
37
|
+
* The sorting group the added items belong to
|
|
38
|
+
*/
|
|
39
|
+
readonly group?: string;
|
|
40
|
+
|
|
41
|
+
/**
|
|
42
|
+
* The group or groups the added items must come before
|
|
43
|
+
*/
|
|
44
|
+
readonly before?: string | string[];
|
|
45
|
+
|
|
46
|
+
/**
|
|
47
|
+
* The group or groups the added items must come after
|
|
48
|
+
*/
|
|
49
|
+
readonly after?: string | string[];
|
|
50
|
+
|
|
51
|
+
/**
|
|
52
|
+
* A number used to sort items with equal before/after requirements
|
|
53
|
+
*/
|
|
54
|
+
readonly sort?: number;
|
|
55
|
+
|
|
56
|
+
/**
|
|
57
|
+
* If true, the array is not sorted automatically until sort() is called
|
|
58
|
+
*/
|
|
59
|
+
readonly manual?: boolean;
|
|
60
|
+
}
|
|
@@ -0,0 +1,225 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
const Assert = require('@hapi/hoek/lib/assert');
|
|
4
|
+
|
|
5
|
+
|
|
6
|
+
const internals = {};
|
|
7
|
+
|
|
8
|
+
|
|
9
|
+
exports.Sorter = class {
|
|
10
|
+
|
|
11
|
+
constructor() {
|
|
12
|
+
|
|
13
|
+
this._items = [];
|
|
14
|
+
this.nodes = [];
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
add(nodes, options) {
|
|
18
|
+
|
|
19
|
+
options = options || {};
|
|
20
|
+
|
|
21
|
+
// Validate rules
|
|
22
|
+
|
|
23
|
+
const before = [].concat(options.before || []);
|
|
24
|
+
const after = [].concat(options.after || []);
|
|
25
|
+
const group = options.group || '?';
|
|
26
|
+
const sort = options.sort || 0; // Used for merging only
|
|
27
|
+
|
|
28
|
+
Assert(!before.includes(group), `Item cannot come before itself: ${group}`);
|
|
29
|
+
Assert(!before.includes('?'), 'Item cannot come before unassociated items');
|
|
30
|
+
Assert(!after.includes(group), `Item cannot come after itself: ${group}`);
|
|
31
|
+
Assert(!after.includes('?'), 'Item cannot come after unassociated items');
|
|
32
|
+
|
|
33
|
+
if (!Array.isArray(nodes)) {
|
|
34
|
+
nodes = [nodes];
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
for (const node of nodes) {
|
|
38
|
+
const item = {
|
|
39
|
+
seq: this._items.length,
|
|
40
|
+
sort,
|
|
41
|
+
before,
|
|
42
|
+
after,
|
|
43
|
+
group,
|
|
44
|
+
node
|
|
45
|
+
};
|
|
46
|
+
|
|
47
|
+
this._items.push(item);
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
// Insert event
|
|
51
|
+
|
|
52
|
+
if (!options.manual) {
|
|
53
|
+
const valid = this._sort();
|
|
54
|
+
Assert(valid, 'item', group !== '?' ? `added into group ${group}` : '', 'created a dependencies error');
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
return this.nodes;
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
merge(others) {
|
|
61
|
+
|
|
62
|
+
if (!Array.isArray(others)) {
|
|
63
|
+
others = [others];
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
for (const other of others) {
|
|
67
|
+
if (other) {
|
|
68
|
+
for (const item of other._items) {
|
|
69
|
+
this._items.push(Object.assign({}, item)); // Shallow cloned
|
|
70
|
+
}
|
|
71
|
+
}
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
// Sort items
|
|
75
|
+
|
|
76
|
+
this._items.sort(internals.mergeSort);
|
|
77
|
+
for (let i = 0; i < this._items.length; ++i) {
|
|
78
|
+
this._items[i].seq = i;
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
const valid = this._sort();
|
|
82
|
+
Assert(valid, 'merge created a dependencies error');
|
|
83
|
+
|
|
84
|
+
return this.nodes;
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
sort() {
|
|
88
|
+
|
|
89
|
+
const valid = this._sort();
|
|
90
|
+
Assert(valid, 'sort created a dependencies error');
|
|
91
|
+
|
|
92
|
+
return this.nodes;
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
_sort() {
|
|
96
|
+
|
|
97
|
+
// Construct graph
|
|
98
|
+
|
|
99
|
+
const graph = {};
|
|
100
|
+
const graphAfters = Object.create(null); // A prototype can bungle lookups w/ false positives
|
|
101
|
+
const groups = Object.create(null);
|
|
102
|
+
|
|
103
|
+
for (const item of this._items) {
|
|
104
|
+
const seq = item.seq; // Unique across all items
|
|
105
|
+
const group = item.group;
|
|
106
|
+
|
|
107
|
+
// Determine Groups
|
|
108
|
+
|
|
109
|
+
groups[group] = groups[group] || [];
|
|
110
|
+
groups[group].push(seq);
|
|
111
|
+
|
|
112
|
+
// Build intermediary graph using 'before'
|
|
113
|
+
|
|
114
|
+
graph[seq] = item.before;
|
|
115
|
+
|
|
116
|
+
// Build second intermediary graph with 'after'
|
|
117
|
+
|
|
118
|
+
for (const after of item.after) {
|
|
119
|
+
graphAfters[after] = graphAfters[after] || [];
|
|
120
|
+
graphAfters[after].push(seq);
|
|
121
|
+
}
|
|
122
|
+
}
|
|
123
|
+
|
|
124
|
+
// Expand intermediary graph
|
|
125
|
+
|
|
126
|
+
for (const node in graph) {
|
|
127
|
+
const expandedGroups = [];
|
|
128
|
+
|
|
129
|
+
for (const graphNodeItem in graph[node]) {
|
|
130
|
+
const group = graph[node][graphNodeItem];
|
|
131
|
+
groups[group] = groups[group] || [];
|
|
132
|
+
expandedGroups.push(...groups[group]);
|
|
133
|
+
}
|
|
134
|
+
|
|
135
|
+
graph[node] = expandedGroups;
|
|
136
|
+
}
|
|
137
|
+
|
|
138
|
+
// Merge intermediary graph using graphAfters into final graph
|
|
139
|
+
|
|
140
|
+
for (const group in graphAfters) {
|
|
141
|
+
if (groups[group]) {
|
|
142
|
+
for (const node of groups[group]) {
|
|
143
|
+
graph[node].push(...graphAfters[group]);
|
|
144
|
+
}
|
|
145
|
+
}
|
|
146
|
+
}
|
|
147
|
+
|
|
148
|
+
// Compile ancestors
|
|
149
|
+
|
|
150
|
+
const ancestors = {};
|
|
151
|
+
for (const node in graph) {
|
|
152
|
+
const children = graph[node];
|
|
153
|
+
for (const child of children) {
|
|
154
|
+
ancestors[child] = ancestors[child] || [];
|
|
155
|
+
ancestors[child].push(node);
|
|
156
|
+
}
|
|
157
|
+
}
|
|
158
|
+
|
|
159
|
+
// Topo sort
|
|
160
|
+
|
|
161
|
+
const visited = {};
|
|
162
|
+
const sorted = [];
|
|
163
|
+
|
|
164
|
+
for (let i = 0; i < this._items.length; ++i) { // Looping through item.seq values out of order
|
|
165
|
+
let next = i;
|
|
166
|
+
|
|
167
|
+
if (ancestors[i]) {
|
|
168
|
+
next = null;
|
|
169
|
+
for (let j = 0; j < this._items.length; ++j) { // As above, these are item.seq values
|
|
170
|
+
if (visited[j] === true) {
|
|
171
|
+
continue;
|
|
172
|
+
}
|
|
173
|
+
|
|
174
|
+
if (!ancestors[j]) {
|
|
175
|
+
ancestors[j] = [];
|
|
176
|
+
}
|
|
177
|
+
|
|
178
|
+
const shouldSeeCount = ancestors[j].length;
|
|
179
|
+
let seenCount = 0;
|
|
180
|
+
for (let k = 0; k < shouldSeeCount; ++k) {
|
|
181
|
+
if (visited[ancestors[j][k]]) {
|
|
182
|
+
++seenCount;
|
|
183
|
+
}
|
|
184
|
+
}
|
|
185
|
+
|
|
186
|
+
if (seenCount === shouldSeeCount) {
|
|
187
|
+
next = j;
|
|
188
|
+
break;
|
|
189
|
+
}
|
|
190
|
+
}
|
|
191
|
+
}
|
|
192
|
+
|
|
193
|
+
if (next !== null) {
|
|
194
|
+
visited[next] = true;
|
|
195
|
+
sorted.push(next);
|
|
196
|
+
}
|
|
197
|
+
}
|
|
198
|
+
|
|
199
|
+
if (sorted.length !== this._items.length) {
|
|
200
|
+
return false;
|
|
201
|
+
}
|
|
202
|
+
|
|
203
|
+
const seqIndex = {};
|
|
204
|
+
for (const item of this._items) {
|
|
205
|
+
seqIndex[item.seq] = item;
|
|
206
|
+
}
|
|
207
|
+
|
|
208
|
+
this._items = [];
|
|
209
|
+
this.nodes = [];
|
|
210
|
+
|
|
211
|
+
for (const value of sorted) {
|
|
212
|
+
const sortedItem = seqIndex[value];
|
|
213
|
+
this.nodes.push(sortedItem.node);
|
|
214
|
+
this._items.push(sortedItem);
|
|
215
|
+
}
|
|
216
|
+
|
|
217
|
+
return true;
|
|
218
|
+
}
|
|
219
|
+
};
|
|
220
|
+
|
|
221
|
+
|
|
222
|
+
internals.mergeSort = (a, b) => {
|
|
223
|
+
|
|
224
|
+
return a.sort === b.sort ? 0 : (a.sort < b.sort ? -1 : 1);
|
|
225
|
+
};
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@hapi/topo",
|
|
3
|
+
"description": "Topological sorting with grouping support",
|
|
4
|
+
"version": "5.1.0",
|
|
5
|
+
"repository": "git://github.com/hapijs/topo",
|
|
6
|
+
"main": "lib/index.js",
|
|
7
|
+
"types": "lib/index.d.ts",
|
|
8
|
+
"files": [
|
|
9
|
+
"lib"
|
|
10
|
+
],
|
|
11
|
+
"keywords": [
|
|
12
|
+
"topological",
|
|
13
|
+
"sort",
|
|
14
|
+
"toposort",
|
|
15
|
+
"topsort"
|
|
16
|
+
],
|
|
17
|
+
"dependencies": {
|
|
18
|
+
"@hapi/hoek": "^9.0.0"
|
|
19
|
+
},
|
|
20
|
+
"devDependencies": {
|
|
21
|
+
"@hapi/code": "8.x.x",
|
|
22
|
+
"@hapi/lab": "24.x.x",
|
|
23
|
+
"typescript": "~4.0.2"
|
|
24
|
+
},
|
|
25
|
+
"scripts": {
|
|
26
|
+
"test": "lab -a @hapi/code -t 100 -L -Y",
|
|
27
|
+
"test-cov-html": "lab -a @hapi/code -t 100 -L -r html -o coverage.html"
|
|
28
|
+
},
|
|
29
|
+
"license": "BSD-3-Clause"
|
|
30
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"name":"joi","description":"Object schema validation","version":"17.13.3","repository":"git://github.com/hapijs/joi","main":"lib/index.js","types":"lib/index.d.ts","browser":"dist/joi-browser.min.js","files":["lib/**/*","dist/*"],"keywords":["schema","validation"],"dependencies":{"@hapi/hoek":"^9.3.0","@hapi/topo":"^5.1.0","@sideway/address":"^4.1.5","@sideway/formula":"^3.0.1","@sideway/pinpoint":"^2.0.0"},"devDependencies":{"@hapi/bourne":"2.x.x","@hapi/code":"8.x.x","@hapi/joi-legacy-test":"npm:@hapi/joi@15.x.x","@hapi/lab":"^25.1.3","@types/node":"^14.18.63","typescript":"4.3.x"},"scripts":{"prepublishOnly":"cd browser && npm install && npm run build","test":"lab -t 100 -a @hapi/code -L -Y","test-cov-html":"lab -r html -o coverage.html -a @hapi/code"},"license":"BSD-3-Clause","_lastModified":"2026-06-10T18:13:31.462Z"}
|
|
@@ -6,9 +6,12 @@
|
|
|
6
6
|
* This project is dual-licensed under AGPL-3.0 and NocoBase Commercial License.
|
|
7
7
|
* For more information, please refer to: https://www.nocobase.com/agreement.
|
|
8
8
|
*/
|
|
9
|
+
import Joi from 'joi';
|
|
9
10
|
import { EventOptions, Trigger, WorkflowModel } from '@nocobase/plugin-workflow';
|
|
10
11
|
export default class RequestInterceptionTrigger extends Trigger {
|
|
11
12
|
static TYPE: string;
|
|
13
|
+
configSchema: Joi.ObjectSchema<any>;
|
|
14
|
+
validateConfig(config: Record<string, any>): Record<string, string>;
|
|
12
15
|
sync: boolean;
|
|
13
16
|
middleware: (context: any, next: any) => Promise<any>;
|
|
14
17
|
constructor(workflow: any);
|
|
@@ -40,6 +40,7 @@ __export(RequestInterceptionTrigger_exports, {
|
|
|
40
40
|
});
|
|
41
41
|
module.exports = __toCommonJS(RequestInterceptionTrigger_exports);
|
|
42
42
|
var import_lodash = require("lodash");
|
|
43
|
+
var import_joi = __toESM(require("joi"));
|
|
43
44
|
var import_plugin_error_handler = __toESM(require("@nocobase/plugin-error-handler"));
|
|
44
45
|
var import_plugin_workflow = require("@nocobase/plugin-workflow");
|
|
45
46
|
var import_data_source_manager = require("@nocobase/data-source-manager");
|
|
@@ -54,6 +55,29 @@ class RequestInterceptionError extends Error {
|
|
|
54
55
|
}
|
|
55
56
|
class RequestInterceptionTrigger extends import_plugin_workflow.Trigger {
|
|
56
57
|
static TYPE = "request-interception";
|
|
58
|
+
configSchema = import_joi.default.object({
|
|
59
|
+
collection: import_joi.default.string().required(),
|
|
60
|
+
global: import_joi.default.boolean().optional(),
|
|
61
|
+
actions: import_joi.default.when("global", {
|
|
62
|
+
is: true,
|
|
63
|
+
then: import_joi.default.array().items(
|
|
64
|
+
import_joi.default.string().valid(
|
|
65
|
+
import_constants.INTERCEPTABLE_ACTIONS.CREATE,
|
|
66
|
+
import_constants.INTERCEPTABLE_ACTIONS.UPDATE,
|
|
67
|
+
import_constants.INTERCEPTABLE_ACTIONS.UPSERT,
|
|
68
|
+
import_constants.INTERCEPTABLE_ACTIONS.DESTROY
|
|
69
|
+
)
|
|
70
|
+
).min(1).required().messages({ "array.min": "At least one action is required in global mode" }),
|
|
71
|
+
otherwise: import_joi.default.array().items(import_joi.default.string()).optional()
|
|
72
|
+
})
|
|
73
|
+
});
|
|
74
|
+
validateConfig(config) {
|
|
75
|
+
const errors = super.validateConfig(config);
|
|
76
|
+
if (errors) {
|
|
77
|
+
return errors;
|
|
78
|
+
}
|
|
79
|
+
return (0, import_plugin_workflow.validateCollectionField)(config.collection, this.workflow.app.dataSourceManager);
|
|
80
|
+
}
|
|
57
81
|
sync = true;
|
|
58
82
|
middleware = async (context, next) => {
|
|
59
83
|
const {
|
|
@@ -101,10 +125,19 @@ class RequestInterceptionTrigger extends import_plugin_workflow.Trigger {
|
|
|
101
125
|
}
|
|
102
126
|
return aIndex - bIndex;
|
|
103
127
|
});
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
128
|
+
const syncWorkflows = localWorkflows.filter((workflow) => triggerWorkflowsMap.has(workflow.key)).concat(globalWorkflows);
|
|
129
|
+
for (const [index, workflow] of syncWorkflows.entries()) {
|
|
130
|
+
const syncLogMeta = {
|
|
131
|
+
workflowId: workflow.id,
|
|
132
|
+
workflowKey: workflow.key,
|
|
133
|
+
workflowTitle: workflow.title,
|
|
134
|
+
resourceName,
|
|
135
|
+
actionName,
|
|
136
|
+
currentSyncOrder: index + 1,
|
|
137
|
+
totalSyncWorkflows: syncWorkflows.length,
|
|
138
|
+
remainingSyncWorkflows: syncWorkflows.length - index - 1
|
|
139
|
+
};
|
|
140
|
+
context.logger.debug("[Workflow pre-action]: executing sync workflow", syncLogMeta);
|
|
108
141
|
const processor = await this.workflow.trigger(
|
|
109
142
|
workflow,
|
|
110
143
|
{
|
|
@@ -119,25 +152,49 @@ class RequestInterceptionTrigger extends import_plugin_workflow.Trigger {
|
|
|
119
152
|
{ httpContext: context }
|
|
120
153
|
);
|
|
121
154
|
if (!processor) {
|
|
122
|
-
|
|
155
|
+
context.logger.error(
|
|
156
|
+
"[Workflow pre-action]: sync workflow trigger failed before execution created",
|
|
157
|
+
syncLogMeta
|
|
158
|
+
);
|
|
159
|
+
return context.throw(500, "Workflow on your action failed, please contact the administrator");
|
|
123
160
|
}
|
|
124
161
|
const { lastSavedJob, nodesMap } = processor;
|
|
125
162
|
const lastNode = nodesMap.get(lastSavedJob == null ? void 0 : lastSavedJob.nodeId);
|
|
126
163
|
if (processor.execution.status === import_plugin_workflow.EXECUTION_STATUS.RESOLVED) {
|
|
127
164
|
if ((lastNode == null ? void 0 : lastNode.type) === "end") {
|
|
165
|
+
context.logger.debug("[Workflow pre-action]: sync workflow ended request chain on end node", {
|
|
166
|
+
...syncLogMeta,
|
|
167
|
+
...(0, import_plugin_workflow.getWorkflowExecutionLogMeta)(workflow, processor)
|
|
168
|
+
});
|
|
128
169
|
return;
|
|
129
170
|
}
|
|
171
|
+
context.logger.debug("[Workflow pre-action]: sync workflow finished successfully", {
|
|
172
|
+
...syncLogMeta,
|
|
173
|
+
...(0, import_plugin_workflow.getWorkflowExecutionLogMeta)(workflow, processor)
|
|
174
|
+
});
|
|
130
175
|
continue;
|
|
131
176
|
}
|
|
132
177
|
if (processor.execution.status < import_plugin_workflow.EXECUTION_STATUS.STARTED) {
|
|
133
178
|
if ((lastNode == null ? void 0 : lastNode.type) !== "end") {
|
|
179
|
+
context.logger.error("[Workflow pre-action]: sync workflow failed", {
|
|
180
|
+
...syncLogMeta,
|
|
181
|
+
...(0, import_plugin_workflow.getWorkflowExecutionLogMeta)(workflow, processor)
|
|
182
|
+
});
|
|
134
183
|
return context.throw(500, "Workflow on your action failed, please contact the administrator");
|
|
135
184
|
}
|
|
185
|
+
context.logger.warn("[Workflow pre-action]: sync workflow intercepted request on end node", {
|
|
186
|
+
...syncLogMeta,
|
|
187
|
+
...(0, import_plugin_workflow.getWorkflowExecutionLogMeta)(workflow, processor)
|
|
188
|
+
});
|
|
136
189
|
const err = new RequestInterceptionError("Request is intercepted by workflow");
|
|
137
190
|
err.status = 400;
|
|
138
191
|
err.messages = context.state.messages;
|
|
139
192
|
return context.throw(err.status, err);
|
|
140
193
|
}
|
|
194
|
+
context.logger.error("[Workflow pre-action]: sync workflow is still pending after trigger", {
|
|
195
|
+
...syncLogMeta,
|
|
196
|
+
...(0, import_plugin_workflow.getWorkflowExecutionLogMeta)(workflow, processor)
|
|
197
|
+
});
|
|
141
198
|
return context.throw(500, "Workflow on your action hangs, please contact the administrator");
|
|
142
199
|
}
|
|
143
200
|
await next();
|