@blue-labs/document-processor 1.35.1 → 1.37.0
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/index.js +5 -5
- package/dist/index.mjs +517 -573
- package/dist/processors/ChannelEventCheckpointProcessor.d.ts +1 -1
- package/dist/processors/CompositeTimelineChannelProcessor.d.ts +1 -1
- package/dist/processors/DocumentUpdateChannelProcessor.d.ts +1 -1
- package/dist/processors/EmbeddedNodeChannelProcessor.d.ts +1 -1
- package/dist/processors/MyOSAgentChannelProcessor.d.ts +1 -1
- package/dist/processors/MyOSTimelineChannelProcessor.d.ts +1 -1
- package/dist/processors/OperationProcessor.d.ts +1 -1
- package/dist/processors/ProcessEmbeddedProcessor.d.ts +1 -1
- package/dist/processors/SequentialWorkflowOperationProcessor.d.ts +1 -1
- package/dist/processors/SequentialWorkflowProcessor/SequentialWorkflowProcessor.d.ts +1 -1
- package/dist/processors/SequentialWorkflowProcessor/SequentialWorkflowProcessor.d.ts.map +1 -1
- package/dist/processors/TimelineChannelProcessor.d.ts +1 -1
- package/dist/processors/TimelineChannelProcessor.d.ts.map +1 -1
- package/dist/queue/TaskKey.d.ts.map +1 -1
- package/dist/testUtils.d.ts.map +1 -1
- package/dist/utils/expressionUtils.d.ts.map +1 -1
- package/dist/utils/logPatchError.d.ts.map +1 -1
- package/dist/utils/path.d.ts.map +1 -1
- package/package.json +5 -5
package/dist/index.mjs
CHANGED
|
@@ -1,23 +1,20 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
import {
|
|
5
|
-
|
|
6
|
-
import { deepFreeze as Be, isNonNullable as M, deepContains as Oe, isNullable as _ } from "@blue-labs/shared-utils";
|
|
7
|
-
import { blueIds as ne, MyOSTimelineEntrySchema as oe, MyOSTimelineChannelSchema as Me, MyOSAgentEventSchema as $e, MyOSAgentChannelSchema as qe } from "@blue-repository/myos-dev";
|
|
8
|
-
const b = (...a) => a.map((e, t) => {
|
|
1
|
+
import { ProcessEmbeddedSchema as V, ChannelEventCheckpointSchema as de, blueIds as f, InitializedMarkerSchema as pe, CompositeTimelineChannelSchema as fe, DocumentUpdateChannelSchema as me, EmbeddedNodeChannelSchema as U, LifecycleEventSchema as ge, TimelineEntrySchema as k, OperationSchema as ye, OperationRequestSchema as Ee, UpdateDocumentSchema as A, TriggerEventSchema as D, JavaScriptCodeSchema as j, SequentialWorkflowSchema as ve, SequentialWorkflowOperationSchema as we, TimelineChannelSchema as Te } from "@blue-repository/core-dev";
|
|
2
|
+
import { applyBlueNodePatch as Y, BlueNode as be, isBigNumber as _, BlueNodeTypeSchema as b, ResolvedBlueNode as Pe, MergingProcessors as C } from "@blue-labs/language";
|
|
3
|
+
import { deepFreeze as Se, isNonNullable as I, deepContains as Ce, isNullable as x } from "@blue-labs/shared-utils";
|
|
4
|
+
import { blueIds as Z, MyOSTimelineEntrySchema as ee, MyOSTimelineChannelSchema as Ne, MyOSAgentEventSchema as ke, MyOSAgentChannelSchema as Ie } from "@blue-repository/myos-dev";
|
|
5
|
+
const T = (...a) => a.map((e, t) => {
|
|
9
6
|
if (typeof e != "string") return "";
|
|
10
7
|
if (t === 0 && e === "/") return "/";
|
|
11
8
|
const n = t > 0 ? e.replace(/^\/+/, "") : e;
|
|
12
9
|
return t < a.length - 1 ? n.replace(/\/+$/, "") : n;
|
|
13
10
|
}).filter(Boolean).join("/").replace(/\/{2,}/g, "/");
|
|
14
|
-
class
|
|
11
|
+
class te {
|
|
15
12
|
constructor(e, t, n, o) {
|
|
16
|
-
l(this, "actions", []);
|
|
17
13
|
this.getDocument = e, this.taskInfo = t, this.blue = n, this.onFlush = o;
|
|
18
14
|
}
|
|
15
|
+
actions = [];
|
|
19
16
|
get(e) {
|
|
20
|
-
const t = this.getDocument(), n =
|
|
17
|
+
const t = this.getDocument(), n = T(this.taskInfo.nodePath, e);
|
|
21
18
|
return t.get(n);
|
|
22
19
|
}
|
|
23
20
|
addPatch(e) {
|
|
@@ -25,7 +22,7 @@ class re {
|
|
|
25
22
|
kind: "patch",
|
|
26
23
|
patch: {
|
|
27
24
|
...e,
|
|
28
|
-
path:
|
|
25
|
+
path: T(this.taskInfo.nodePath, e.path)
|
|
29
26
|
}
|
|
30
27
|
});
|
|
31
28
|
}
|
|
@@ -41,16 +38,15 @@ class re {
|
|
|
41
38
|
this.actions.push({ kind: "event", event: o });
|
|
42
39
|
}
|
|
43
40
|
async flush() {
|
|
44
|
-
var t;
|
|
45
41
|
if (!this.actions.length) return [];
|
|
46
42
|
const e = [...this.actions];
|
|
47
|
-
return this.actions.length = 0, await
|
|
43
|
+
return this.actions.length = 0, await this.onFlush?.(e), e;
|
|
48
44
|
}
|
|
49
45
|
getNodePath() {
|
|
50
46
|
return this.taskInfo.nodePath;
|
|
51
47
|
}
|
|
52
48
|
resolvePath(e) {
|
|
53
|
-
return
|
|
49
|
+
return T(this.taskInfo.nodePath, e);
|
|
54
50
|
}
|
|
55
51
|
getTaskInfo() {
|
|
56
52
|
return this.taskInfo;
|
|
@@ -69,82 +65,82 @@ class re {
|
|
|
69
65
|
return Promise.resolve(JSON.stringify(this.blue.nodeToJson(t)));
|
|
70
66
|
}
|
|
71
67
|
}
|
|
72
|
-
class
|
|
68
|
+
class ne extends Error {
|
|
73
69
|
constructor(e, t) {
|
|
74
70
|
super(`Cannot apply patch ${JSON.stringify(e)}`), this.patch = e, this.cause = t, this.name = "PatchApplicationError";
|
|
75
71
|
}
|
|
76
72
|
}
|
|
77
|
-
class
|
|
73
|
+
class oe extends Error {
|
|
78
74
|
constructor(e, t, n) {
|
|
79
75
|
super(
|
|
80
76
|
`Patch ${JSON.stringify(e)} touches "${e.op === "move" || e.op === "copy" ? `${e.from} → ${e.path}` : e.path}" which is inside embedded document "${t}" (Process Embedded @ "${n}")`
|
|
81
77
|
), this.patch = e, this.offendingPath = t, this.contractNodePath = n, this.name = "EmbeddedDocumentModificationError";
|
|
82
78
|
}
|
|
83
79
|
}
|
|
84
|
-
class
|
|
80
|
+
class Be extends Error {
|
|
85
81
|
constructor(e, t) {
|
|
86
82
|
super(`Failed to evaluate expression "${e}"`), this.code = e, this.cause = t, this.name = "ExpressionEvaluationError";
|
|
87
83
|
}
|
|
88
84
|
}
|
|
89
|
-
class
|
|
85
|
+
class Oe extends Error {
|
|
90
86
|
constructor(e, t) {
|
|
91
87
|
super(`Failed to evaluate code block "${e}"`), this.code = e, this.cause = t, this.name = "CodeBlockEvaluationError";
|
|
92
88
|
}
|
|
93
89
|
}
|
|
94
|
-
function
|
|
95
|
-
return
|
|
90
|
+
function N(a) {
|
|
91
|
+
return Se(a);
|
|
96
92
|
}
|
|
97
|
-
function
|
|
93
|
+
function B(a) {
|
|
98
94
|
return a.clone();
|
|
99
95
|
}
|
|
100
|
-
function
|
|
96
|
+
function W(a, e, t = "/", n = []) {
|
|
101
97
|
const o = a.getContracts() ?? {};
|
|
102
98
|
for (const [r, s] of Object.entries(o))
|
|
103
|
-
if (e.isTypeOf(s,
|
|
104
|
-
const
|
|
99
|
+
if (e.isTypeOf(s, V)) {
|
|
100
|
+
const u = e.nodeToSchemaOutput(
|
|
105
101
|
s,
|
|
106
|
-
|
|
102
|
+
V
|
|
107
103
|
).paths ?? [];
|
|
108
|
-
for (const
|
|
104
|
+
for (const l of u)
|
|
109
105
|
n.push({
|
|
110
|
-
absPath:
|
|
111
|
-
contractPath:
|
|
106
|
+
absPath: T(t, l),
|
|
107
|
+
contractPath: T(t, `contracts/${r}`)
|
|
112
108
|
});
|
|
113
109
|
}
|
|
114
110
|
for (const [r, s] of Object.entries(a.getProperties() ?? {}))
|
|
115
|
-
|
|
111
|
+
W(
|
|
116
112
|
s,
|
|
117
113
|
e,
|
|
118
|
-
|
|
114
|
+
T(t, r),
|
|
119
115
|
n
|
|
120
116
|
);
|
|
121
117
|
return n;
|
|
122
118
|
}
|
|
123
|
-
function
|
|
119
|
+
function z(a, e) {
|
|
124
120
|
return a === e || a.startsWith(e.endsWith("/") ? e : e + "/");
|
|
125
121
|
}
|
|
126
|
-
function
|
|
122
|
+
function H(a, e) {
|
|
127
123
|
if (!e.length) return a;
|
|
128
|
-
let t =
|
|
124
|
+
let t = B(a);
|
|
129
125
|
for (const n of e)
|
|
130
126
|
try {
|
|
131
|
-
t =
|
|
127
|
+
t = Y(t, n, !0);
|
|
132
128
|
} catch (o) {
|
|
133
|
-
throw new
|
|
129
|
+
throw new ne(n, o);
|
|
134
130
|
}
|
|
135
|
-
return
|
|
131
|
+
return N(t);
|
|
136
132
|
}
|
|
137
|
-
function
|
|
133
|
+
function y(a) {
|
|
138
134
|
return a != null;
|
|
139
135
|
}
|
|
140
|
-
function
|
|
141
|
-
return a instanceof
|
|
136
|
+
function P(a) {
|
|
137
|
+
return a instanceof be;
|
|
142
138
|
}
|
|
143
|
-
class
|
|
139
|
+
class Me {
|
|
140
|
+
data;
|
|
141
|
+
length;
|
|
142
|
+
compare;
|
|
144
143
|
constructor(e = [], t = (n, o) => n < o ? -1 : n > o ? 1 : 0) {
|
|
145
|
-
l(this, "data");
|
|
146
|
-
l(this, "length");
|
|
147
|
-
l(this, "compare");
|
|
148
144
|
if (this.data = e, this.length = this.data.length, this.compare = t, this.length > 0)
|
|
149
145
|
for (let n = (this.length >> 1) - 1; n >= 0; n--) this._down(n);
|
|
150
146
|
}
|
|
@@ -179,14 +175,14 @@ class je {
|
|
|
179
175
|
t[e] = r;
|
|
180
176
|
}
|
|
181
177
|
}
|
|
182
|
-
const
|
|
178
|
+
const qe = (a, e, t, n, o, r) => [
|
|
183
179
|
-a,
|
|
184
180
|
e,
|
|
185
181
|
t,
|
|
186
182
|
n,
|
|
187
183
|
o,
|
|
188
184
|
r
|
|
189
|
-
],
|
|
185
|
+
], $e = (a, e) => {
|
|
190
186
|
for (let t = 0; t < a.key.length; t++) {
|
|
191
187
|
const n = a.key[t], o = e.key[t];
|
|
192
188
|
if (n !== o)
|
|
@@ -194,13 +190,13 @@ const xe = (a, e, t, n, o, r) => [
|
|
|
194
190
|
}
|
|
195
191
|
return 0;
|
|
196
192
|
};
|
|
197
|
-
class
|
|
193
|
+
class Ae {
|
|
194
|
+
queue;
|
|
198
195
|
/**
|
|
199
196
|
* Creates a new task queue with the task key comparator
|
|
200
197
|
*/
|
|
201
198
|
constructor() {
|
|
202
|
-
|
|
203
|
-
this.queue = new je([], Ve);
|
|
199
|
+
this.queue = new Me([], $e);
|
|
204
200
|
}
|
|
205
201
|
/**
|
|
206
202
|
* Adds a task to the queue
|
|
@@ -225,15 +221,15 @@ class _e {
|
|
|
225
221
|
return this.queue.length;
|
|
226
222
|
}
|
|
227
223
|
}
|
|
228
|
-
class
|
|
224
|
+
class De {
|
|
225
|
+
processors = /* @__PURE__ */ new Map();
|
|
226
|
+
typeOrder = /* @__PURE__ */ new Map();
|
|
229
227
|
/**
|
|
230
228
|
* Creates a new contract registry
|
|
231
229
|
*
|
|
232
230
|
* @param list - Initial list of processors to register
|
|
233
231
|
*/
|
|
234
232
|
constructor(e = []) {
|
|
235
|
-
l(this, "processors", /* @__PURE__ */ new Map());
|
|
236
|
-
l(this, "typeOrder", /* @__PURE__ */ new Map());
|
|
237
233
|
e.forEach((t, n) => this.register(t, n));
|
|
238
234
|
}
|
|
239
235
|
/**
|
|
@@ -280,9 +276,10 @@ class We {
|
|
|
280
276
|
return this.processors.values();
|
|
281
277
|
}
|
|
282
278
|
}
|
|
283
|
-
|
|
279
|
+
class q {
|
|
280
|
+
isEnabled;
|
|
281
|
+
static MAX_TRACE_LENGTH = 128;
|
|
284
282
|
constructor() {
|
|
285
|
-
l(this, "isEnabled");
|
|
286
283
|
this.isEnabled = process.env.TRACE_BLUE_ENABLED !== "false";
|
|
287
284
|
}
|
|
288
285
|
/**
|
|
@@ -311,7 +308,7 @@ const B = class B {
|
|
|
311
308
|
addHop(e, t, n) {
|
|
312
309
|
if (!this.shouldTrace())
|
|
313
310
|
return { ...e };
|
|
314
|
-
const o = e.trace ?? [], s = [...o.length >=
|
|
311
|
+
const o = e.trace ?? [], s = [...o.length >= q.MAX_TRACE_LENGTH ? o.slice(o.length - (q.MAX_TRACE_LENGTH - 1)) : o, this.makeHop(t, n)];
|
|
315
312
|
return {
|
|
316
313
|
...e,
|
|
317
314
|
trace: s
|
|
@@ -343,14 +340,12 @@ const B = class B {
|
|
|
343
340
|
isTracingEnabled() {
|
|
344
341
|
return this.isEnabled;
|
|
345
342
|
}
|
|
346
|
-
}
|
|
347
|
-
|
|
348
|
-
let L = B;
|
|
349
|
-
function Je(a) {
|
|
343
|
+
}
|
|
344
|
+
function je(a) {
|
|
350
345
|
return Object.entries(a.getContracts() ?? {});
|
|
351
346
|
}
|
|
352
|
-
const
|
|
353
|
-
class
|
|
347
|
+
const xe = 64;
|
|
348
|
+
class Ve {
|
|
354
349
|
/**
|
|
355
350
|
* Creates a new event router
|
|
356
351
|
*
|
|
@@ -360,9 +355,9 @@ class Ue {
|
|
|
360
355
|
* @param getNextEventSeq - Function to get the next event sequence number
|
|
361
356
|
*/
|
|
362
357
|
constructor(e, t, n, o, r) {
|
|
363
|
-
|
|
364
|
-
this.blue = e, this.registry = t, this.queue = n, this.getNextTaskId = o, this.getNextEventSeq = r, this.traceManager = new L();
|
|
358
|
+
this.blue = e, this.registry = t, this.queue = n, this.getNextTaskId = o, this.getNextEventSeq = r, this.traceManager = new q();
|
|
365
359
|
}
|
|
360
|
+
traceManager;
|
|
366
361
|
/**
|
|
367
362
|
* Routes an event to matching contracts in the document
|
|
368
363
|
*
|
|
@@ -373,19 +368,18 @@ class Ue {
|
|
|
373
368
|
* @param inlineDepth - Current adapter recursion depth
|
|
374
369
|
*/
|
|
375
370
|
async route(e, t, n, o, r = 0) {
|
|
376
|
-
var c;
|
|
377
371
|
if (n.seq === void 0 && (n.seq = this.getNextEventSeq()), t.length === 0) {
|
|
378
372
|
if (n.dispatchPath) {
|
|
379
|
-
const
|
|
380
|
-
return delete u.dispatchPath, this.route(e,
|
|
373
|
+
const c = n.dispatchPath.split("/").filter(Boolean), u = { ...n };
|
|
374
|
+
return delete u.dispatchPath, this.route(e, c, u, o, r);
|
|
381
375
|
}
|
|
382
376
|
if (n.source === "channel" && n.originNodePath && n.originNodePath !== "/") {
|
|
383
|
-
const
|
|
384
|
-
return this.route(e,
|
|
377
|
+
const c = n.originNodePath?.split("/").filter(Boolean) ?? [];
|
|
378
|
+
return this.route(e, c, n, o, r);
|
|
385
379
|
}
|
|
386
380
|
}
|
|
387
|
-
const s =
|
|
388
|
-
|
|
381
|
+
const s = T("/", t.join("/")), i = e.get(s);
|
|
382
|
+
P(i) && await this.traverseContracts({
|
|
389
383
|
doc: e,
|
|
390
384
|
node: i,
|
|
391
385
|
nodePath: s,
|
|
@@ -409,28 +403,28 @@ class Ue {
|
|
|
409
403
|
inlineDepth: c
|
|
410
404
|
} = e;
|
|
411
405
|
if (!this.shouldSkipForChannel(r, o))
|
|
412
|
-
for (const [
|
|
413
|
-
if (!
|
|
414
|
-
const
|
|
415
|
-
if (!
|
|
416
|
-
console.warn(`No processor registered for contract: ${
|
|
406
|
+
for (const [u, l] of je(n)) {
|
|
407
|
+
if (!l.getType()) continue;
|
|
408
|
+
const h = this.registry.get(l.getType());
|
|
409
|
+
if (!h) {
|
|
410
|
+
console.warn(`No processor registered for contract: ${u}`);
|
|
417
411
|
continue;
|
|
418
412
|
}
|
|
419
|
-
const
|
|
413
|
+
const g = {
|
|
420
414
|
nodePath: o,
|
|
421
|
-
contractName:
|
|
422
|
-
contractNode:
|
|
415
|
+
contractName: u,
|
|
416
|
+
contractNode: l,
|
|
423
417
|
event: r
|
|
424
|
-
},
|
|
425
|
-
if (
|
|
426
|
-
switch (
|
|
418
|
+
}, p = new te(() => t, g, this.blue);
|
|
419
|
+
if (h.supports(r, l, p, u))
|
|
420
|
+
switch (h.role) {
|
|
427
421
|
case "adapter":
|
|
428
422
|
await this.processAdapter({
|
|
429
|
-
cp:
|
|
423
|
+
cp: h,
|
|
430
424
|
event: r,
|
|
431
|
-
contractNode:
|
|
432
|
-
ctx:
|
|
433
|
-
contractName:
|
|
425
|
+
contractNode: l,
|
|
426
|
+
ctx: p,
|
|
427
|
+
contractName: u,
|
|
434
428
|
doc: t,
|
|
435
429
|
afterTaskId: s,
|
|
436
430
|
inlineDepth: c
|
|
@@ -438,8 +432,8 @@ class Ue {
|
|
|
438
432
|
break;
|
|
439
433
|
case "handler":
|
|
440
434
|
this.scheduleHandler({
|
|
441
|
-
contractNode:
|
|
442
|
-
contractName:
|
|
435
|
+
contractNode: l,
|
|
436
|
+
contractName: u,
|
|
443
437
|
nodePath: o,
|
|
444
438
|
event: r,
|
|
445
439
|
depth: i.length,
|
|
@@ -453,7 +447,6 @@ class Ue {
|
|
|
453
447
|
* Processes an adapter contract and routes any emitted events
|
|
454
448
|
*/
|
|
455
449
|
async processAdapter(e) {
|
|
456
|
-
var v;
|
|
457
450
|
const {
|
|
458
451
|
cp: t,
|
|
459
452
|
event: n,
|
|
@@ -462,24 +455,24 @@ class Ue {
|
|
|
462
455
|
contractName: s,
|
|
463
456
|
doc: i,
|
|
464
457
|
afterTaskId: c,
|
|
465
|
-
inlineDepth:
|
|
458
|
+
inlineDepth: u
|
|
466
459
|
} = e;
|
|
467
|
-
if (
|
|
460
|
+
if (u >= xe)
|
|
468
461
|
throw new Error("Adapter recursion limit reached");
|
|
469
|
-
const
|
|
462
|
+
const l = this.traceManager.addHop(
|
|
470
463
|
n,
|
|
471
|
-
|
|
464
|
+
r.getTaskInfo()?.nodePath ?? "",
|
|
472
465
|
s
|
|
473
466
|
);
|
|
474
|
-
await t.handle(
|
|
475
|
-
const
|
|
476
|
-
if (
|
|
467
|
+
await t.handle(l, o, r, s);
|
|
468
|
+
const h = await r.flush();
|
|
469
|
+
if (h.find((E) => E.kind === "patch"))
|
|
477
470
|
throw new Error(
|
|
478
471
|
`Contract "${s}" (adapter) attempted to patch the document`
|
|
479
472
|
);
|
|
480
|
-
const
|
|
481
|
-
for (const
|
|
482
|
-
await this.route(i, [],
|
|
473
|
+
const p = h.filter((E) => E.kind === "event");
|
|
474
|
+
for (const E of p)
|
|
475
|
+
await this.route(i, [], E.event, c, u + 1);
|
|
483
476
|
}
|
|
484
477
|
/**
|
|
485
478
|
* Schedules a handler contract for future execution
|
|
@@ -490,31 +483,31 @@ class Ue {
|
|
|
490
483
|
console.warn(`Contract node type is not defined for: ${n}`);
|
|
491
484
|
return;
|
|
492
485
|
}
|
|
493
|
-
const
|
|
494
|
-
if (
|
|
486
|
+
const u = this.registry.orderOf(c), l = t.get("/order"), h = _(l) ? l.toNumber() : 0, g = this.getNextTaskId() + i, p = r.seq;
|
|
487
|
+
if (p === void 0)
|
|
495
488
|
throw new Error("Event sequence missing");
|
|
496
|
-
const
|
|
489
|
+
const E = qe(
|
|
497
490
|
s,
|
|
498
|
-
|
|
491
|
+
p,
|
|
492
|
+
u,
|
|
499
493
|
h,
|
|
500
|
-
d,
|
|
501
494
|
n,
|
|
502
|
-
|
|
495
|
+
g
|
|
503
496
|
);
|
|
504
497
|
{
|
|
505
|
-
const
|
|
506
|
-
if (r.source !== "external" &&
|
|
498
|
+
const O = `${o}#${n}`, v = r.trace ?? [];
|
|
499
|
+
if (r.source !== "external" && v.includes(O))
|
|
507
500
|
throw new Error(
|
|
508
|
-
`Loop detected: repeated hop ${
|
|
501
|
+
`Loop detected: repeated hop ${O} within the same event chain`
|
|
509
502
|
);
|
|
510
503
|
}
|
|
511
|
-
const
|
|
504
|
+
const m = this.traceManager.addHop(r, o, n);
|
|
512
505
|
this.queue.push({
|
|
513
|
-
key:
|
|
506
|
+
key: E,
|
|
514
507
|
nodePath: o,
|
|
515
508
|
contractName: n,
|
|
516
509
|
contractNode: t,
|
|
517
|
-
event:
|
|
510
|
+
event: m
|
|
518
511
|
});
|
|
519
512
|
}
|
|
520
513
|
/**
|
|
@@ -524,93 +517,88 @@ class Ue {
|
|
|
524
517
|
return e.source === "channel" && !!e.originNodePath && e.originNodePath !== t;
|
|
525
518
|
}
|
|
526
519
|
}
|
|
527
|
-
const
|
|
528
|
-
(t instanceof
|
|
520
|
+
const _e = (a, e, t) => {
|
|
521
|
+
(t instanceof ne || t instanceof oe) && console.error(
|
|
529
522
|
`[Blue] Failed to apply patches for contract "${a}" on event ${JSON.stringify(e)}`,
|
|
530
523
|
t
|
|
531
524
|
);
|
|
532
525
|
};
|
|
533
|
-
function
|
|
534
|
-
const t =
|
|
535
|
-
if (!
|
|
526
|
+
function F(a, e) {
|
|
527
|
+
const t = B(a), n = (o) => {
|
|
528
|
+
if (!P(o)) return;
|
|
536
529
|
const r = o.getContracts();
|
|
537
|
-
(!
|
|
530
|
+
(!r?.checkpoint || !b.isTypeOf(
|
|
538
531
|
r.checkpoint,
|
|
539
|
-
|
|
532
|
+
de
|
|
540
533
|
)) && o.addContract(
|
|
541
534
|
"checkpoint",
|
|
542
535
|
e.jsonValueToNode({
|
|
543
536
|
type: {
|
|
544
537
|
name: "Channel Event Checkpoint",
|
|
545
|
-
blueId:
|
|
538
|
+
blueId: f["Channel Event Checkpoint"]
|
|
546
539
|
},
|
|
547
540
|
lastEvents: {}
|
|
548
541
|
})
|
|
549
542
|
);
|
|
550
543
|
};
|
|
551
544
|
n(t);
|
|
552
|
-
for (const { absPath: o } of
|
|
545
|
+
for (const { absPath: o } of W(t, e)) {
|
|
553
546
|
const r = t.get(o);
|
|
554
|
-
|
|
547
|
+
P(r) && n(r);
|
|
555
548
|
}
|
|
556
|
-
return
|
|
549
|
+
return N(t);
|
|
557
550
|
}
|
|
558
551
|
function Re(a, e) {
|
|
559
|
-
const t =
|
|
560
|
-
return
|
|
552
|
+
const t = B(a);
|
|
553
|
+
return P(t) && (re(t, e) || t.addContract(
|
|
561
554
|
"initialized",
|
|
562
555
|
e.jsonValueToNode({
|
|
563
556
|
type: {
|
|
564
557
|
name: "Initialized Marker",
|
|
565
|
-
blueId:
|
|
558
|
+
blueId: f["Initialized Marker"]
|
|
566
559
|
}
|
|
567
560
|
})
|
|
568
|
-
)),
|
|
561
|
+
)), N(t);
|
|
569
562
|
}
|
|
570
|
-
function
|
|
563
|
+
function re(a, e) {
|
|
571
564
|
const t = a.getContracts();
|
|
572
565
|
return Object.values(t ?? {}).some(
|
|
573
|
-
(n) => e.isTypeOf(n,
|
|
566
|
+
(n) => e.isTypeOf(n, pe, {
|
|
574
567
|
checkSchemaExtensions: !0
|
|
575
568
|
})
|
|
576
569
|
);
|
|
577
570
|
}
|
|
578
|
-
class
|
|
571
|
+
class We {
|
|
579
572
|
constructor(e) {
|
|
580
|
-
l(this, "contractType", "Channel Event Checkpoint");
|
|
581
|
-
l(this, "contractBlueId", y["Channel Event Checkpoint"]);
|
|
582
|
-
l(this, "role", "handler");
|
|
583
573
|
this.cache = e;
|
|
584
574
|
}
|
|
575
|
+
contractType = "Channel Event Checkpoint";
|
|
576
|
+
contractBlueId = f["Channel Event Checkpoint"];
|
|
577
|
+
role = "handler";
|
|
585
578
|
supports(e) {
|
|
586
|
-
|
|
587
|
-
return e.source === "channel" && ((t = e.rootEvent) == null ? void 0 : t.payload) === e.payload && ((n = e.rootEvent) == null ? void 0 : n.source) === "external";
|
|
579
|
+
return e.source === "channel" && e.rootEvent?.payload === e.payload && e.rootEvent?.source === "external";
|
|
588
580
|
}
|
|
589
581
|
async getEventBlueId(e, t) {
|
|
590
|
-
|
|
591
|
-
const n = (o = e.rootEvent) == null ? void 0 : o.payload;
|
|
582
|
+
const n = e.rootEvent?.payload;
|
|
592
583
|
if (!n)
|
|
593
584
|
throw new Error(
|
|
594
585
|
"Cannot calculate blueId for checkpoint: missing root event payload"
|
|
595
586
|
);
|
|
596
|
-
if (n instanceof
|
|
597
|
-
const
|
|
598
|
-
return await t.getBlue().calculateBlueId(
|
|
587
|
+
if (n instanceof Pe) {
|
|
588
|
+
const o = n.getMinimalNode();
|
|
589
|
+
return await t.getBlue().calculateBlueId(o);
|
|
599
590
|
}
|
|
600
591
|
return await t.getBlue().calculateBlueId(n);
|
|
601
592
|
}
|
|
602
593
|
async handle(e, t, n) {
|
|
603
|
-
|
|
604
|
-
if (!e.channelName || !((s = e.rootEvent) != null && s.seq)) return;
|
|
594
|
+
if (!e.channelName || !e.rootEvent?.seq) return;
|
|
605
595
|
const o = await this.getEventBlueId(e, n), r = n.getNodePath().replace(/\/contracts\/checkpoint$/, "");
|
|
606
596
|
this.cache.record(r, e, o);
|
|
607
597
|
}
|
|
608
598
|
}
|
|
609
|
-
const
|
|
610
|
-
class
|
|
611
|
-
|
|
612
|
-
l(this, "firstSeen", /* @__PURE__ */ new Map());
|
|
613
|
-
}
|
|
599
|
+
const X = (a, e) => a.get(e) !== void 0;
|
|
600
|
+
class Je {
|
|
601
|
+
firstSeen = /* @__PURE__ */ new Map();
|
|
614
602
|
record(e, t, n) {
|
|
615
603
|
const o = e;
|
|
616
604
|
this.firstSeen.has(o) || this.firstSeen.set(o, { docBase: e, event: t, eventBlueId: n });
|
|
@@ -620,13 +608,13 @@ class Fe {
|
|
|
620
608
|
const t = [];
|
|
621
609
|
for (const { docBase: n, event: o, eventBlueId: r } of this.firstSeen.values()) {
|
|
622
610
|
if (!o.channelName) continue;
|
|
623
|
-
const s =
|
|
611
|
+
const s = T(
|
|
624
612
|
n,
|
|
625
613
|
"contracts/checkpoint/lastEvents",
|
|
626
614
|
o.channelName
|
|
627
615
|
), i = `${s}/blueId`;
|
|
628
|
-
|
|
629
|
-
op:
|
|
616
|
+
X(e, s) ? t.push({
|
|
617
|
+
op: X(e, i) ? "replace" : "add",
|
|
630
618
|
path: i,
|
|
631
619
|
val: r
|
|
632
620
|
}) : t.push({
|
|
@@ -641,14 +629,12 @@ class Fe {
|
|
|
641
629
|
this.firstSeen.clear();
|
|
642
630
|
}
|
|
643
631
|
}
|
|
644
|
-
class
|
|
645
|
-
|
|
646
|
-
|
|
647
|
-
|
|
648
|
-
l(this, "role", "adapter");
|
|
649
|
-
}
|
|
632
|
+
class Le {
|
|
633
|
+
contractType = "Composite Timeline Channel";
|
|
634
|
+
contractBlueId = f["Composite Timeline Channel"];
|
|
635
|
+
role = "adapter";
|
|
650
636
|
supports(e, t, n) {
|
|
651
|
-
const o = n.getBlue().nodeToSchemaOutput(t,
|
|
637
|
+
const o = n.getBlue().nodeToSchemaOutput(t, fe);
|
|
652
638
|
return !o.channels || !e.channelName ? !1 : o.channels.includes(e.channelName);
|
|
653
639
|
}
|
|
654
640
|
handle(e, t, n, o) {
|
|
@@ -659,10 +645,8 @@ class Xe {
|
|
|
659
645
|
});
|
|
660
646
|
}
|
|
661
647
|
}
|
|
662
|
-
class
|
|
663
|
-
|
|
664
|
-
l(this, "role", "adapter");
|
|
665
|
-
}
|
|
648
|
+
class S {
|
|
649
|
+
role = "adapter";
|
|
666
650
|
/**
|
|
667
651
|
* Base implementation of supports that checks if the event is not from a channel
|
|
668
652
|
* Derived classes should call this method first in their supports implementation
|
|
@@ -671,151 +655,132 @@ class C {
|
|
|
671
655
|
return e.source !== "channel";
|
|
672
656
|
}
|
|
673
657
|
}
|
|
674
|
-
class
|
|
675
|
-
|
|
676
|
-
|
|
677
|
-
|
|
678
|
-
|
|
679
|
-
|
|
680
|
-
|
|
681
|
-
|
|
682
|
-
|
|
683
|
-
|
|
684
|
-
|
|
685
|
-
|
|
686
|
-
|
|
687
|
-
|
|
688
|
-
o.emitEvent({
|
|
689
|
-
payload: t.payload,
|
|
690
|
-
channelName: r,
|
|
658
|
+
class Ue extends S {
|
|
659
|
+
contractType = "Document Update Channel";
|
|
660
|
+
contractBlueId = f["Document Update Channel"];
|
|
661
|
+
supports(e, t, n) {
|
|
662
|
+
if (!this.baseSupports(e) || e.emissionType !== "update") return !1;
|
|
663
|
+
const o = n.getBlue().nodeToSchemaOutput(t, me), r = e.payload.get("/path");
|
|
664
|
+
if (!r) return !1;
|
|
665
|
+
const s = o.path;
|
|
666
|
+
return I(s) && r === n.resolvePath(s);
|
|
667
|
+
}
|
|
668
|
+
handle(e, t, n, o) {
|
|
669
|
+
n.emitEvent({
|
|
670
|
+
payload: e.payload,
|
|
671
|
+
channelName: o,
|
|
691
672
|
source: "channel"
|
|
692
673
|
});
|
|
693
674
|
}
|
|
694
675
|
}
|
|
695
|
-
class
|
|
696
|
-
|
|
697
|
-
|
|
698
|
-
|
|
699
|
-
|
|
700
|
-
|
|
701
|
-
|
|
702
|
-
|
|
703
|
-
|
|
704
|
-
|
|
705
|
-
|
|
706
|
-
|
|
707
|
-
|
|
708
|
-
E(s.path) && i === o.resolvePath(s.path) && o.emitEvent({
|
|
709
|
-
payload: c,
|
|
710
|
-
channelName: r,
|
|
676
|
+
class ze extends S {
|
|
677
|
+
contractType = "Embedded Node Channel";
|
|
678
|
+
contractBlueId = f["Embedded Node Channel"];
|
|
679
|
+
supports(e, t, n) {
|
|
680
|
+
if (!this.baseSupports(e)) return !1;
|
|
681
|
+
const o = n.getBlue().nodeToSchemaOutput(t, U);
|
|
682
|
+
return y(e.originNodePath) && y(o.path) && e.originNodePath === n.resolvePath(o.path);
|
|
683
|
+
}
|
|
684
|
+
handle(e, t, n, o) {
|
|
685
|
+
const r = n.getBlue().nodeToSchemaOutput(t, U), { originNodePath: s, payload: i } = e;
|
|
686
|
+
y(r.path) && s === n.resolvePath(r.path) && n.emitEvent({
|
|
687
|
+
payload: i,
|
|
688
|
+
channelName: o,
|
|
711
689
|
source: "channel"
|
|
712
690
|
});
|
|
713
691
|
}
|
|
714
692
|
}
|
|
715
|
-
class
|
|
716
|
-
|
|
717
|
-
|
|
718
|
-
|
|
719
|
-
l(this, "role", "marker");
|
|
720
|
-
}
|
|
693
|
+
class He {
|
|
694
|
+
contractType = "Initialized Marker";
|
|
695
|
+
contractBlueId = f["Initialized Marker"];
|
|
696
|
+
role = "marker";
|
|
721
697
|
supports() {
|
|
722
698
|
return !1;
|
|
723
699
|
}
|
|
724
700
|
handle() {
|
|
725
701
|
}
|
|
726
702
|
}
|
|
727
|
-
class
|
|
728
|
-
|
|
729
|
-
|
|
730
|
-
|
|
731
|
-
|
|
732
|
-
}
|
|
733
|
-
supports(t, n, o) {
|
|
734
|
-
return !this.baseSupports(t) || t.emissionType !== "lifecycle" || !this.isLifecycleEvent(t, o) ? !1 : this.isEventPatternMatch(t, n, o);
|
|
703
|
+
class Fe extends S {
|
|
704
|
+
contractType = "Lifecycle Event Channel";
|
|
705
|
+
contractBlueId = f["Lifecycle Event Channel"];
|
|
706
|
+
supports(e, t, n) {
|
|
707
|
+
return !this.baseSupports(e) || e.emissionType !== "lifecycle" || !this.isLifecycleEvent(e, n) ? !1 : this.isEventPatternMatch(e, t, n);
|
|
735
708
|
}
|
|
736
|
-
handle(t, n, o
|
|
737
|
-
|
|
738
|
-
payload:
|
|
739
|
-
channelName:
|
|
709
|
+
handle(e, t, n, o) {
|
|
710
|
+
n.emitEvent({
|
|
711
|
+
payload: e.payload,
|
|
712
|
+
channelName: o,
|
|
740
713
|
source: "channel",
|
|
741
|
-
emissionType:
|
|
714
|
+
emissionType: e.emissionType
|
|
742
715
|
});
|
|
743
716
|
}
|
|
744
717
|
/**
|
|
745
718
|
* Checks if the event is a supported lifecycle event type
|
|
746
719
|
*/
|
|
747
|
-
isLifecycleEvent(
|
|
748
|
-
const
|
|
749
|
-
return
|
|
720
|
+
isLifecycleEvent(e, t) {
|
|
721
|
+
const n = t.getBlue(), o = e.payload;
|
|
722
|
+
return n.isTypeOf(o, ge, {
|
|
750
723
|
checkSchemaExtensions: !0
|
|
751
724
|
});
|
|
752
725
|
}
|
|
753
726
|
/**
|
|
754
727
|
* Checks if the event matches the channel's event pattern (if specified)
|
|
755
728
|
*/
|
|
756
|
-
isEventPatternMatch(t, n
|
|
757
|
-
|
|
758
|
-
|
|
759
|
-
if (!r)
|
|
729
|
+
isEventPatternMatch(e, t, n) {
|
|
730
|
+
const o = t.getProperties()?.event;
|
|
731
|
+
if (!o)
|
|
760
732
|
return !0;
|
|
761
733
|
try {
|
|
762
|
-
const
|
|
763
|
-
return
|
|
764
|
-
} catch (
|
|
765
|
-
return console.warn("Error during lifecycle event pattern matching:",
|
|
734
|
+
const r = n.getBlue(), s = r.resolve(e.payload);
|
|
735
|
+
return r.isTypeOfNode(s, o);
|
|
736
|
+
} catch (r) {
|
|
737
|
+
return console.warn("Error during lifecycle event pattern matching:", r), !1;
|
|
766
738
|
}
|
|
767
739
|
}
|
|
768
740
|
}
|
|
769
|
-
const
|
|
741
|
+
const Q = (a, e) => {
|
|
770
742
|
const t = e.getBlue();
|
|
771
|
-
return t.isTypeOf(a.payload,
|
|
743
|
+
return t.isTypeOf(a.payload, k) || t.isTypeOf(a.payload, ee);
|
|
772
744
|
};
|
|
773
|
-
class
|
|
774
|
-
|
|
775
|
-
|
|
776
|
-
|
|
777
|
-
|
|
778
|
-
|
|
779
|
-
|
|
780
|
-
|
|
781
|
-
|
|
782
|
-
|
|
783
|
-
|
|
784
|
-
|
|
785
|
-
|
|
786
|
-
|
|
787
|
-
|
|
788
|
-
handle(t, n, o, r) {
|
|
789
|
-
Y(t, o) && o.emitEvent({
|
|
790
|
-
payload: t.payload,
|
|
791
|
-
channelName: r,
|
|
745
|
+
class Xe extends S {
|
|
746
|
+
contractType = "MyOS Timeline Channel";
|
|
747
|
+
contractBlueId = Z["MyOS Timeline Channel"];
|
|
748
|
+
supports(e, t, n) {
|
|
749
|
+
if (!this.baseSupports(e) || !Q(e, n)) return !1;
|
|
750
|
+
const r = n.getBlue().nodeToSchemaOutput(
|
|
751
|
+
e.payload,
|
|
752
|
+
ee
|
|
753
|
+
), s = n.getBlue().nodeToSchemaOutput(t, Ne), i = r.timeline?.timelineId;
|
|
754
|
+
return y(s.timelineId) && y(i) && i === s.timelineId;
|
|
755
|
+
}
|
|
756
|
+
handle(e, t, n, o) {
|
|
757
|
+
Q(e, n) && n.emitEvent({
|
|
758
|
+
payload: e.payload,
|
|
759
|
+
channelName: o,
|
|
792
760
|
source: "channel"
|
|
793
761
|
});
|
|
794
762
|
}
|
|
795
763
|
}
|
|
796
|
-
class
|
|
797
|
-
|
|
798
|
-
|
|
799
|
-
|
|
800
|
-
|
|
801
|
-
}
|
|
802
|
-
supports(t, n, o) {
|
|
803
|
-
if (!this.baseSupports(t)) return !1;
|
|
764
|
+
class Qe extends S {
|
|
765
|
+
contractType = "MyOS Agent Channel";
|
|
766
|
+
contractBlueId = Z["MyOS Agent Channel"];
|
|
767
|
+
supports(e, t, n) {
|
|
768
|
+
if (!this.baseSupports(e)) return !1;
|
|
804
769
|
try {
|
|
805
|
-
const { myosAgentEvent:
|
|
770
|
+
const { myosAgentEvent: o, myosAgentChannel: r } = this.parseEventAndChannel(
|
|
771
|
+
e,
|
|
806
772
|
t,
|
|
807
|
-
n
|
|
808
|
-
o
|
|
773
|
+
n
|
|
809
774
|
);
|
|
810
|
-
return this.isAgentMatch(
|
|
811
|
-
} catch (
|
|
812
|
-
return console.warn("Error in MyOSAgentChannelProcessor.supports:",
|
|
775
|
+
return this.isAgentMatch(o, r) && this.isEventPatternMatch(o, r, n);
|
|
776
|
+
} catch (o) {
|
|
777
|
+
return console.warn("Error in MyOSAgentChannelProcessor.supports:", o), !1;
|
|
813
778
|
}
|
|
814
779
|
}
|
|
815
|
-
handle(t, n, o
|
|
816
|
-
|
|
817
|
-
payload:
|
|
818
|
-
channelName:
|
|
780
|
+
handle(e, t, n, o) {
|
|
781
|
+
n.emitEvent({
|
|
782
|
+
payload: e.payload,
|
|
783
|
+
channelName: o,
|
|
819
784
|
source: "channel"
|
|
820
785
|
});
|
|
821
786
|
}
|
|
@@ -823,15 +788,15 @@ class et extends C {
|
|
|
823
788
|
* Parses and validates the event payload and channel configuration
|
|
824
789
|
* @throws {Error} If schema validation fails
|
|
825
790
|
*/
|
|
826
|
-
parseEventAndChannel(t, n
|
|
827
|
-
const
|
|
828
|
-
|
|
829
|
-
|
|
830
|
-
),
|
|
831
|
-
|
|
832
|
-
|
|
791
|
+
parseEventAndChannel(e, t, n) {
|
|
792
|
+
const o = n.getBlue(), r = o.nodeToSchemaOutput(
|
|
793
|
+
e.payload,
|
|
794
|
+
ke
|
|
795
|
+
), s = o.nodeToSchemaOutput(
|
|
796
|
+
t,
|
|
797
|
+
Ie
|
|
833
798
|
);
|
|
834
|
-
return { myosAgentEvent:
|
|
799
|
+
return { myosAgentEvent: r, myosAgentChannel: s };
|
|
835
800
|
}
|
|
836
801
|
/**
|
|
837
802
|
* Checks if the agent IDs match between event and channel
|
|
@@ -839,10 +804,9 @@ class et extends C {
|
|
|
839
804
|
* @param myosAgentChannel - The parsed agent channel configuration
|
|
840
805
|
* @returns true if both have valid agent IDs and they match
|
|
841
806
|
*/
|
|
842
|
-
isAgentMatch(
|
|
843
|
-
|
|
844
|
-
|
|
845
|
-
return E(o) && E(r) && o === r;
|
|
807
|
+
isAgentMatch(e, t) {
|
|
808
|
+
const n = e.agentId, o = t.agent?.agentId;
|
|
809
|
+
return y(n) && y(o) && n === o;
|
|
846
810
|
}
|
|
847
811
|
/**
|
|
848
812
|
* Checks if the event pattern matches the channel's event filter
|
|
@@ -857,40 +821,38 @@ class et extends C {
|
|
|
857
821
|
* - If channel has event pattern but incoming event has no event data → no match
|
|
858
822
|
* - Otherwise → uses deep containment matching (event must contain all channel pattern fields)
|
|
859
823
|
*/
|
|
860
|
-
isEventPatternMatch(t, n
|
|
861
|
-
const
|
|
862
|
-
if (!
|
|
824
|
+
isEventPatternMatch(e, t, n) {
|
|
825
|
+
const o = t.event;
|
|
826
|
+
if (!o)
|
|
863
827
|
return !0;
|
|
864
|
-
const
|
|
865
|
-
if (!
|
|
828
|
+
const r = e.event;
|
|
829
|
+
if (!r)
|
|
866
830
|
return !1;
|
|
867
831
|
try {
|
|
868
|
-
const
|
|
869
|
-
return
|
|
870
|
-
} catch (
|
|
871
|
-
return console.warn("Error during event pattern matching:",
|
|
832
|
+
const s = n.getBlue(), i = s.nodeToJson(r), c = s.nodeToJson(o);
|
|
833
|
+
return Ce(i, c);
|
|
834
|
+
} catch (s) {
|
|
835
|
+
return console.warn("Error during event pattern matching:", s), !1;
|
|
872
836
|
}
|
|
873
837
|
}
|
|
874
838
|
}
|
|
875
|
-
class
|
|
876
|
-
|
|
877
|
-
|
|
878
|
-
|
|
879
|
-
l(this, "role", "adapter");
|
|
880
|
-
}
|
|
839
|
+
class Ge {
|
|
840
|
+
contractType = "Operation";
|
|
841
|
+
contractBlueId = f.Operation;
|
|
842
|
+
role = "adapter";
|
|
881
843
|
supports(e, t, n, o) {
|
|
882
|
-
const s = n.getBlue().nodeToSchemaOutput(t,
|
|
844
|
+
const s = n.getBlue().nodeToSchemaOutput(t, ye), i = this.parseEventPayload(e, n), c = this.isOperationNameMatch(
|
|
883
845
|
i,
|
|
884
846
|
o
|
|
885
|
-
),
|
|
847
|
+
), u = this.isOperationChannelMatch(
|
|
886
848
|
e,
|
|
887
849
|
s
|
|
888
|
-
),
|
|
850
|
+
), l = this.isRequestPatternMatch(
|
|
889
851
|
i,
|
|
890
852
|
s,
|
|
891
853
|
n
|
|
892
854
|
);
|
|
893
|
-
return c &&
|
|
855
|
+
return c && u && l;
|
|
894
856
|
}
|
|
895
857
|
async handle(e, t, n, o) {
|
|
896
858
|
n.emitEvent({
|
|
@@ -901,50 +863,48 @@ class tt {
|
|
|
901
863
|
}
|
|
902
864
|
parseEventPayload(e, t) {
|
|
903
865
|
const n = t.getBlue();
|
|
904
|
-
if (n.isTypeOf(e.payload,
|
|
866
|
+
if (n.isTypeOf(e.payload, k, {
|
|
905
867
|
checkSchemaExtensions: !0
|
|
906
868
|
})) {
|
|
907
869
|
const o = n.nodeToSchemaOutput(
|
|
908
870
|
e.payload,
|
|
909
|
-
|
|
871
|
+
k
|
|
910
872
|
);
|
|
911
873
|
if (o.message)
|
|
912
874
|
return n.nodeToSchemaOutput(
|
|
913
875
|
o.message,
|
|
914
|
-
|
|
876
|
+
Ee
|
|
915
877
|
);
|
|
916
878
|
}
|
|
917
879
|
return null;
|
|
918
880
|
}
|
|
919
881
|
isOperationNameMatch(e, t) {
|
|
920
|
-
return
|
|
882
|
+
return y(e?.operation) && e?.operation === t;
|
|
921
883
|
}
|
|
922
884
|
isOperationChannelMatch(e, t) {
|
|
923
885
|
const n = t.channel;
|
|
924
|
-
return
|
|
886
|
+
return x(n) ? !0 : e.source === "channel" && e.channelName === n;
|
|
925
887
|
}
|
|
926
888
|
isRequestPatternMatch(e, t, n) {
|
|
927
889
|
const o = t.request;
|
|
928
|
-
if (
|
|
890
|
+
if (x(o))
|
|
929
891
|
return !0;
|
|
930
|
-
const r = n.getBlue(), s = e
|
|
931
|
-
if (
|
|
892
|
+
const r = n.getBlue(), s = e?.request;
|
|
893
|
+
if (x(s))
|
|
932
894
|
return !1;
|
|
933
895
|
const i = r.resolve(s);
|
|
934
896
|
return r.isTypeOfNode(i, o);
|
|
935
897
|
}
|
|
936
898
|
}
|
|
937
|
-
class
|
|
938
|
-
|
|
939
|
-
|
|
940
|
-
|
|
941
|
-
l(this, "contractBlueId", y["Process Embedded"]);
|
|
942
|
-
}
|
|
899
|
+
class Ke {
|
|
900
|
+
contractType = "Process Embedded";
|
|
901
|
+
role = "adapter";
|
|
902
|
+
contractBlueId = f["Process Embedded"];
|
|
943
903
|
supports(e) {
|
|
944
904
|
return e.source !== "channel";
|
|
945
905
|
}
|
|
946
906
|
handle(e, t, n) {
|
|
947
|
-
const o = n.getBlue().nodeToSchemaOutput(t,
|
|
907
|
+
const o = n.getBlue().nodeToSchemaOutput(t, V);
|
|
948
908
|
for (const r of o.paths ?? [])
|
|
949
909
|
n.emitEvent({
|
|
950
910
|
...e,
|
|
@@ -952,18 +912,18 @@ class nt {
|
|
|
952
912
|
});
|
|
953
913
|
}
|
|
954
914
|
}
|
|
955
|
-
const
|
|
956
|
-
let
|
|
957
|
-
if (
|
|
915
|
+
const Ye = !process.env.SKIP_ISOLATED_VM;
|
|
916
|
+
let d = null;
|
|
917
|
+
if (Ye)
|
|
958
918
|
try {
|
|
959
|
-
|
|
919
|
+
d = require("isolated-vm");
|
|
960
920
|
} catch {
|
|
961
921
|
console.warn("isolated-vm not available, using fallback evaluation method");
|
|
962
922
|
}
|
|
963
|
-
function
|
|
923
|
+
function Ze(a) {
|
|
964
924
|
return /\bimport\s.+\sfrom\s+['"][^'"]+['"]/.test(a) || /\bexport\s+/.test(a);
|
|
965
925
|
}
|
|
966
|
-
class
|
|
926
|
+
class $ {
|
|
967
927
|
static getIvmUnavailableMessage() {
|
|
968
928
|
const e = typeof process < "u" && process.version ? process.version : "unknown", t = typeof process < "u" && process.platform ? process.platform : "unknown", n = typeof process < "u" && process.arch ? process.arch : "unknown";
|
|
969
929
|
return [
|
|
@@ -985,14 +945,14 @@ class A {
|
|
|
985
945
|
`);
|
|
986
946
|
}
|
|
987
947
|
static async ensureIvm() {
|
|
988
|
-
if (
|
|
989
|
-
return
|
|
948
|
+
if (d)
|
|
949
|
+
return d;
|
|
990
950
|
try {
|
|
991
|
-
typeof require == "function" ?
|
|
951
|
+
typeof require == "function" ? d = require("isolated-vm") : d = (await import("isolated-vm")).default ?? await import("isolated-vm");
|
|
992
952
|
} catch (e) {
|
|
993
|
-
console.error(e),
|
|
953
|
+
console.error(e), d = null;
|
|
994
954
|
}
|
|
995
|
-
return
|
|
955
|
+
return d;
|
|
996
956
|
}
|
|
997
957
|
/**
|
|
998
958
|
* Main evaluation method - chooses between secure and simple evaluation strategies
|
|
@@ -1003,7 +963,7 @@ class A {
|
|
|
1003
963
|
bindings: n = {},
|
|
1004
964
|
options: o = {}
|
|
1005
965
|
}) {
|
|
1006
|
-
if (await this.ensureIvm(), !
|
|
966
|
+
if (await this.ensureIvm(), !d)
|
|
1007
967
|
throw new Error(this.getIvmUnavailableMessage());
|
|
1008
968
|
return this.evaluateSecure(e, n, t, o);
|
|
1009
969
|
}
|
|
@@ -1011,32 +971,32 @@ class A {
|
|
|
1011
971
|
* Secure evaluation using isolated-vm with support for ES modules
|
|
1012
972
|
*/
|
|
1013
973
|
static async evaluateSecure(e, t, n, o = {}) {
|
|
1014
|
-
if (!
|
|
1015
|
-
const r = new
|
|
974
|
+
if (!d) throw new Error(this.getIvmUnavailableMessage());
|
|
975
|
+
const r = new d.Isolate({ memoryLimit: 32 }), s = await r.createContext(), i = s.global;
|
|
1016
976
|
try {
|
|
1017
977
|
await this.setupIsolateEnvironment(i, t);
|
|
1018
|
-
const c = /* @__PURE__ */ new Map(),
|
|
978
|
+
const c = /* @__PURE__ */ new Map(), u = this.createModuleResolver(
|
|
1019
979
|
r,
|
|
1020
980
|
s,
|
|
1021
981
|
c,
|
|
1022
982
|
n
|
|
1023
983
|
);
|
|
1024
|
-
let
|
|
1025
|
-
return
|
|
984
|
+
let l;
|
|
985
|
+
return Ze(e) ? l = await this.evaluateESModule(
|
|
1026
986
|
r,
|
|
1027
987
|
s,
|
|
1028
988
|
e,
|
|
1029
989
|
o,
|
|
1030
|
-
|
|
1031
|
-
) :
|
|
990
|
+
u
|
|
991
|
+
) : l = await this.evaluateSimpleScript(
|
|
1032
992
|
r,
|
|
1033
993
|
s,
|
|
1034
994
|
e,
|
|
1035
995
|
t,
|
|
1036
996
|
o
|
|
1037
|
-
), this.deepClone(
|
|
997
|
+
), this.deepClone(l);
|
|
1038
998
|
} catch (c) {
|
|
1039
|
-
throw o.isCodeBlock ? new
|
|
999
|
+
throw o.isCodeBlock ? new Oe(e, c) : new Be(e, c);
|
|
1040
1000
|
} finally {
|
|
1041
1001
|
s.release(), r.dispose();
|
|
1042
1002
|
}
|
|
@@ -1045,18 +1005,18 @@ class A {
|
|
|
1045
1005
|
* Setup the isolated VM environment with necessary host functions and data
|
|
1046
1006
|
*/
|
|
1047
1007
|
static async setupIsolateEnvironment(e, t) {
|
|
1048
|
-
if (!
|
|
1049
|
-
const n = new
|
|
1008
|
+
if (!d) throw new Error("isolated-vm not available");
|
|
1009
|
+
const n = new d.Callback(
|
|
1050
1010
|
(...r) => console.log(...r)
|
|
1051
|
-
), o = new
|
|
1011
|
+
), o = new d.ExternalCopy({
|
|
1052
1012
|
log: n
|
|
1053
1013
|
}).copyInto();
|
|
1054
1014
|
await e.set("console", o);
|
|
1055
1015
|
for (const [r, s] of Object.entries(t))
|
|
1056
1016
|
typeof s == "function" ? await e.set(
|
|
1057
1017
|
r,
|
|
1058
|
-
new
|
|
1059
|
-
) : await e.set(r, new
|
|
1018
|
+
new d.Callback(s)
|
|
1019
|
+
) : await e.set(r, new d.ExternalCopy(s).copyInto());
|
|
1060
1020
|
}
|
|
1061
1021
|
/**
|
|
1062
1022
|
* Create module resolver function for handling imports
|
|
@@ -1070,11 +1030,11 @@ class A {
|
|
|
1070
1030
|
throw new Error(
|
|
1071
1031
|
`ProcessingContext is missing a loadBlueContent(blueId) implementation (needed for ${r})`
|
|
1072
1032
|
);
|
|
1073
|
-
const c = await i(s),
|
|
1074
|
-
return n.set(r,
|
|
1033
|
+
const c = await i(s), u = await e.compileModule(c);
|
|
1034
|
+
return n.set(r, u), await u.instantiate(
|
|
1075
1035
|
t,
|
|
1076
1036
|
this.createModuleResolver(e, t, n, o)
|
|
1077
|
-
),
|
|
1037
|
+
), u;
|
|
1078
1038
|
}
|
|
1079
1039
|
if (/^https?:\/\//.test(r)) {
|
|
1080
1040
|
let s;
|
|
@@ -1097,7 +1057,7 @@ class A {
|
|
|
1097
1057
|
* Evaluate code as a simple script (no imports/exports)
|
|
1098
1058
|
*/
|
|
1099
1059
|
static async evaluateSimpleScript(e, t, n, o, r) {
|
|
1100
|
-
const s = Object.keys(o).join(", "), i = Object.keys(o).map((
|
|
1060
|
+
const s = Object.keys(o).join(", "), i = Object.keys(o).map((l) => l), c = `(async (${s}) => { ${r.isCodeBlock ? n : `return (${n});`} })(${i.join(", ")})`;
|
|
1101
1061
|
return await (await e.compileScript(c)).run(t, {
|
|
1102
1062
|
timeout: r.timeout ?? 500,
|
|
1103
1063
|
promise: !0,
|
|
@@ -1111,14 +1071,14 @@ class A {
|
|
|
1111
1071
|
static async evaluateESModule(e, t, n, o, r) {
|
|
1112
1072
|
let s = n;
|
|
1113
1073
|
if (o.isCodeBlock) {
|
|
1114
|
-
const
|
|
1074
|
+
const u = /^\s*(import\s.+?;|export\s.+?;)/gm, l = (n.match(u) || []).join(
|
|
1115
1075
|
`
|
|
1116
1076
|
`
|
|
1117
|
-
),
|
|
1077
|
+
), h = n.replace(u, "").trim();
|
|
1118
1078
|
s = `
|
|
1119
|
-
${
|
|
1079
|
+
${l}
|
|
1120
1080
|
const run = function() {
|
|
1121
|
-
${
|
|
1081
|
+
${h}
|
|
1122
1082
|
};
|
|
1123
1083
|
export default run();
|
|
1124
1084
|
`;
|
|
@@ -1144,43 +1104,43 @@ class A {
|
|
|
1144
1104
|
return typeof e > "u" ? e : JSON.parse(JSON.stringify(e));
|
|
1145
1105
|
}
|
|
1146
1106
|
}
|
|
1147
|
-
class
|
|
1107
|
+
class J {
|
|
1148
1108
|
/**
|
|
1149
1109
|
* Creates standard bindings for workflow step execution
|
|
1150
1110
|
*/
|
|
1151
1111
|
static createStandardBindings(e, t, n) {
|
|
1152
|
-
const o = e.getBlue(), r = o.nodeToJson(t.payload, "simple"), s =
|
|
1112
|
+
const o = e.getBlue(), r = o.nodeToJson(t.payload, "simple"), s = _(r) ? r.toNumber() : r;
|
|
1153
1113
|
return {
|
|
1154
1114
|
document: (i) => {
|
|
1155
1115
|
const c = e.get(i);
|
|
1156
|
-
return
|
|
1116
|
+
return _(c) ? c.toNumber() : P(c) ? o.nodeToJson(c, "original") : c;
|
|
1157
1117
|
},
|
|
1158
1118
|
event: s,
|
|
1159
1119
|
steps: n
|
|
1160
1120
|
};
|
|
1161
1121
|
}
|
|
1162
1122
|
}
|
|
1163
|
-
const
|
|
1164
|
-
if (!
|
|
1123
|
+
const et = /^\$\{([\s\S]*)\}$/, tt = /\$\{([\s\S]*?)\}/, w = (a) => typeof a != "string" ? !1 : et.test(a), R = (a) => typeof a != "string" ? !1 : tt.test(a), se = (a) => {
|
|
1124
|
+
if (!w(a))
|
|
1165
1125
|
throw new Error(`Invalid expression: ${a}`);
|
|
1166
1126
|
return a.slice(2, -1);
|
|
1167
1127
|
};
|
|
1168
|
-
class
|
|
1128
|
+
class M {
|
|
1169
1129
|
static createBindings(e, t, n) {
|
|
1170
|
-
return
|
|
1130
|
+
return J.createStandardBindings(e, t, n);
|
|
1171
1131
|
}
|
|
1172
1132
|
static async evaluate(e, t, n, o) {
|
|
1173
1133
|
const { coerceToString: r } = o;
|
|
1174
|
-
if (
|
|
1175
|
-
const s =
|
|
1134
|
+
if (w(e)) {
|
|
1135
|
+
const s = se(e), i = await $.evaluate({
|
|
1176
1136
|
code: s,
|
|
1177
1137
|
ctx: t,
|
|
1178
1138
|
bindings: n
|
|
1179
1139
|
});
|
|
1180
1140
|
return r ? String(i ?? "") : i;
|
|
1181
1141
|
}
|
|
1182
|
-
if (
|
|
1183
|
-
const i = `\`${String(e).replace(/`/g, "\\`")}\``, c = await
|
|
1142
|
+
if (R(e)) {
|
|
1143
|
+
const i = `\`${String(e).replace(/`/g, "\\`")}\``, c = await $.evaluate({
|
|
1184
1144
|
code: i,
|
|
1185
1145
|
ctx: t,
|
|
1186
1146
|
bindings: n
|
|
@@ -1190,7 +1150,7 @@ class q {
|
|
|
1190
1150
|
return r ? String(e) : e;
|
|
1191
1151
|
}
|
|
1192
1152
|
}
|
|
1193
|
-
function
|
|
1153
|
+
function G(a, e) {
|
|
1194
1154
|
const { op: t, path: n, val: o, from: r } = a;
|
|
1195
1155
|
if ((t === "move" || t === "copy") && !r)
|
|
1196
1156
|
throw new Error(`${t} operation requires 'from' path`);
|
|
@@ -1203,67 +1163,65 @@ function Z(a, e) {
|
|
|
1203
1163
|
};
|
|
1204
1164
|
return o !== void 0 && (s.val = o), r !== void 0 && (s.from = r), e.jsonValueToNode(s);
|
|
1205
1165
|
}
|
|
1206
|
-
function
|
|
1166
|
+
function nt(a) {
|
|
1207
1167
|
return a.jsonValueToNode({
|
|
1208
1168
|
type: "Document Processing Initiated"
|
|
1209
1169
|
});
|
|
1210
1170
|
}
|
|
1211
|
-
class
|
|
1212
|
-
|
|
1213
|
-
l(this, "stepType", "Update Document");
|
|
1214
|
-
}
|
|
1171
|
+
class ot {
|
|
1172
|
+
stepType = "Update Document";
|
|
1215
1173
|
supports(e) {
|
|
1216
|
-
return
|
|
1174
|
+
return b.isTypeOf(e, A);
|
|
1217
1175
|
}
|
|
1218
1176
|
async execute(e, t, n, o, r) {
|
|
1219
1177
|
const s = n.getBlue();
|
|
1220
|
-
if (!
|
|
1178
|
+
if (!b.isTypeOf(e, A)) return;
|
|
1221
1179
|
const i = await this.evaluateChangeset(
|
|
1222
1180
|
e.get("/changeset"),
|
|
1223
1181
|
n,
|
|
1224
1182
|
t,
|
|
1225
1183
|
r
|
|
1226
|
-
), c =
|
|
1184
|
+
), c = Y(e, {
|
|
1227
1185
|
op: "replace",
|
|
1228
1186
|
path: "/changeset",
|
|
1229
1187
|
val: i
|
|
1230
|
-
}),
|
|
1231
|
-
for (const
|
|
1232
|
-
if (!
|
|
1233
|
-
const
|
|
1234
|
-
|
|
1188
|
+
}), u = n.getBlue().nodeToSchemaOutput(c, A);
|
|
1189
|
+
for (const l of u.changeset ?? []) {
|
|
1190
|
+
if (!l.path) continue;
|
|
1191
|
+
const h = await this.evaluateChangePath(
|
|
1192
|
+
l.path,
|
|
1235
1193
|
n,
|
|
1236
1194
|
t,
|
|
1237
1195
|
r
|
|
1238
|
-
),
|
|
1239
|
-
if ((
|
|
1240
|
-
const
|
|
1241
|
-
|
|
1196
|
+
), g = l.val;
|
|
1197
|
+
if ((l.op === "replace" || l.op === "add") && I(g)) {
|
|
1198
|
+
const p = await this.evaluateChangeValue(
|
|
1199
|
+
g,
|
|
1242
1200
|
n,
|
|
1243
1201
|
t,
|
|
1244
1202
|
r
|
|
1245
1203
|
);
|
|
1246
1204
|
n.addPatch({
|
|
1247
|
-
op:
|
|
1248
|
-
path:
|
|
1249
|
-
val:
|
|
1205
|
+
op: l.op,
|
|
1206
|
+
path: h,
|
|
1207
|
+
val: p
|
|
1250
1208
|
}), n.emitEvent({
|
|
1251
|
-
payload:
|
|
1209
|
+
payload: G(
|
|
1252
1210
|
{
|
|
1253
|
-
op:
|
|
1254
|
-
path: n.resolvePath(
|
|
1255
|
-
val: s.nodeToJson(
|
|
1211
|
+
op: l.op,
|
|
1212
|
+
path: n.resolvePath(h),
|
|
1213
|
+
val: s.nodeToJson(p, "original")
|
|
1256
1214
|
},
|
|
1257
1215
|
s
|
|
1258
1216
|
),
|
|
1259
1217
|
emissionType: "update"
|
|
1260
1218
|
});
|
|
1261
1219
|
}
|
|
1262
|
-
|
|
1263
|
-
payload:
|
|
1220
|
+
l.op === "remove" && (n.addPatch({ op: l.op, path: h }), n.emitEvent({
|
|
1221
|
+
payload: G(
|
|
1264
1222
|
{
|
|
1265
|
-
op:
|
|
1266
|
-
path: n.resolvePath(
|
|
1223
|
+
op: l.op,
|
|
1224
|
+
path: n.resolvePath(h),
|
|
1267
1225
|
val: null
|
|
1268
1226
|
},
|
|
1269
1227
|
s
|
|
@@ -1274,11 +1232,11 @@ class ct {
|
|
|
1274
1232
|
}
|
|
1275
1233
|
async evaluateChangeset(e, t, n, o) {
|
|
1276
1234
|
const r = t.getBlue();
|
|
1277
|
-
if (
|
|
1278
|
-
const s =
|
|
1235
|
+
if (w(e)) {
|
|
1236
|
+
const s = se(e), i = await $.evaluate({
|
|
1279
1237
|
code: s,
|
|
1280
1238
|
ctx: t,
|
|
1281
|
-
bindings:
|
|
1239
|
+
bindings: J.createStandardBindings(
|
|
1282
1240
|
t,
|
|
1283
1241
|
n,
|
|
1284
1242
|
o
|
|
@@ -1286,31 +1244,31 @@ class ct {
|
|
|
1286
1244
|
});
|
|
1287
1245
|
return r.jsonValueToNode(i ?? null);
|
|
1288
1246
|
}
|
|
1289
|
-
if (
|
|
1247
|
+
if (P(e))
|
|
1290
1248
|
return e;
|
|
1291
1249
|
throw new Error("Invalid changeset: expected a string or document node");
|
|
1292
1250
|
}
|
|
1293
1251
|
async evaluateChangeValue(e, t, n, o) {
|
|
1294
1252
|
const r = e.getValue(), s = t.getBlue();
|
|
1295
|
-
if (
|
|
1296
|
-
const i =
|
|
1253
|
+
if (w(r) || typeof r == "string" && R(r)) {
|
|
1254
|
+
const i = M.createBindings(
|
|
1297
1255
|
t,
|
|
1298
1256
|
n,
|
|
1299
1257
|
o
|
|
1300
|
-
), c = await
|
|
1258
|
+
), c = await M.evaluate(
|
|
1301
1259
|
String(r),
|
|
1302
1260
|
t,
|
|
1303
1261
|
i,
|
|
1304
|
-
{ coerceToString: !
|
|
1262
|
+
{ coerceToString: !w(r) }
|
|
1305
1263
|
);
|
|
1306
1264
|
return s.jsonValueToNode(c ?? null);
|
|
1307
1265
|
}
|
|
1308
1266
|
return e;
|
|
1309
1267
|
}
|
|
1310
1268
|
async evaluateChangePath(e, t, n, o) {
|
|
1311
|
-
const r =
|
|
1312
|
-
if (
|
|
1313
|
-
const s = await
|
|
1269
|
+
const r = M.createBindings(t, n, o);
|
|
1270
|
+
if (w(e) || R(e)) {
|
|
1271
|
+
const s = await M.evaluate(e, t, r, {
|
|
1314
1272
|
coerceToString: !0
|
|
1315
1273
|
});
|
|
1316
1274
|
return String(s ?? "");
|
|
@@ -1318,70 +1276,66 @@ class ct {
|
|
|
1318
1276
|
return e;
|
|
1319
1277
|
}
|
|
1320
1278
|
}
|
|
1321
|
-
class
|
|
1322
|
-
|
|
1323
|
-
l(this, "stepType", "Trigger Event");
|
|
1324
|
-
}
|
|
1279
|
+
class rt {
|
|
1280
|
+
stepType = "Trigger Event";
|
|
1325
1281
|
supports(e) {
|
|
1326
|
-
return
|
|
1282
|
+
return b.isTypeOf(e, D);
|
|
1327
1283
|
}
|
|
1328
1284
|
async execute(e, t, n) {
|
|
1329
1285
|
const o = n.getBlue();
|
|
1330
|
-
if (!
|
|
1331
|
-
const r = o.nodeToSchemaOutput(e,
|
|
1286
|
+
if (!b.isTypeOf(e, D)) return;
|
|
1287
|
+
const r = o.nodeToSchemaOutput(e, D);
|
|
1332
1288
|
r.event && n.emitEvent({
|
|
1333
1289
|
payload: r.event,
|
|
1334
1290
|
emissionType: "triggered"
|
|
1335
1291
|
});
|
|
1336
1292
|
}
|
|
1337
1293
|
}
|
|
1338
|
-
class
|
|
1339
|
-
|
|
1340
|
-
l(this, "stepType", "JavaScript Code");
|
|
1341
|
-
}
|
|
1294
|
+
class st {
|
|
1295
|
+
stepType = "JavaScript Code";
|
|
1342
1296
|
supports(e) {
|
|
1343
|
-
return
|
|
1297
|
+
return b.isTypeOf(e, j);
|
|
1344
1298
|
}
|
|
1345
1299
|
async execute(e, t, n, o, r) {
|
|
1346
|
-
if (!
|
|
1300
|
+
if (!b.isTypeOf(e, j)) return;
|
|
1347
1301
|
const s = n.getBlue(), i = s.nodeToSchemaOutput(
|
|
1348
1302
|
e,
|
|
1349
|
-
|
|
1303
|
+
j
|
|
1350
1304
|
);
|
|
1351
1305
|
if (!i.code)
|
|
1352
1306
|
throw new Error("JavaScript code is required");
|
|
1353
|
-
const c = await
|
|
1307
|
+
const c = await $.evaluate({
|
|
1354
1308
|
code: i.code,
|
|
1355
1309
|
ctx: n,
|
|
1356
|
-
bindings:
|
|
1310
|
+
bindings: J.createStandardBindings(n, t, r),
|
|
1357
1311
|
options: {
|
|
1358
1312
|
isCodeBlock: !0,
|
|
1359
1313
|
timeout: 500
|
|
1360
1314
|
}
|
|
1361
1315
|
});
|
|
1362
1316
|
if (c && typeof c == "object" && "events" in c) {
|
|
1363
|
-
const
|
|
1364
|
-
if (Array.isArray(
|
|
1365
|
-
for (const
|
|
1317
|
+
const u = c;
|
|
1318
|
+
if (Array.isArray(u.events))
|
|
1319
|
+
for (const l of u.events)
|
|
1366
1320
|
n.emitEvent({
|
|
1367
|
-
payload: s.jsonValueToNode(
|
|
1321
|
+
payload: s.jsonValueToNode(l),
|
|
1368
1322
|
emissionType: "triggered"
|
|
1369
1323
|
});
|
|
1370
1324
|
}
|
|
1371
1325
|
return c;
|
|
1372
1326
|
}
|
|
1373
1327
|
}
|
|
1374
|
-
const
|
|
1375
|
-
new
|
|
1376
|
-
new
|
|
1377
|
-
new
|
|
1328
|
+
const at = [
|
|
1329
|
+
new ot(),
|
|
1330
|
+
new rt(),
|
|
1331
|
+
new st()
|
|
1378
1332
|
];
|
|
1379
|
-
class
|
|
1380
|
-
|
|
1381
|
-
|
|
1382
|
-
|
|
1383
|
-
|
|
1384
|
-
|
|
1333
|
+
class ae {
|
|
1334
|
+
contractType = "Sequential Workflow";
|
|
1335
|
+
contractBlueId = f["Sequential Workflow"];
|
|
1336
|
+
role = "handler";
|
|
1337
|
+
executors = [];
|
|
1338
|
+
constructor(e = at) {
|
|
1385
1339
|
this.executors = e;
|
|
1386
1340
|
}
|
|
1387
1341
|
/** allow registering custom step executors */
|
|
@@ -1391,65 +1345,63 @@ class le {
|
|
|
1391
1345
|
supports(e, t, n) {
|
|
1392
1346
|
const r = n.getBlue().nodeToSchemaOutput(
|
|
1393
1347
|
t,
|
|
1394
|
-
|
|
1348
|
+
ve
|
|
1395
1349
|
), s = this.isChannelNameMatch(e, r), i = this.isEventPatternMatch(e, t, n);
|
|
1396
1350
|
return s && i;
|
|
1397
1351
|
}
|
|
1398
1352
|
async handle(e, t, n, o) {
|
|
1399
|
-
|
|
1400
|
-
const
|
|
1401
|
-
|
|
1402
|
-
const u = this.executors.find((p) => p.supports(h));
|
|
1353
|
+
const r = {}, s = t.getProperties()?.steps.getItems();
|
|
1354
|
+
for (const [i, c] of (s ?? []).entries()) {
|
|
1355
|
+
const u = this.executors.find((h) => h.supports(c));
|
|
1403
1356
|
if (!u)
|
|
1404
|
-
throw new Error(`Unsupported workflow step type "${
|
|
1405
|
-
const
|
|
1406
|
-
|
|
1357
|
+
throw new Error(`Unsupported workflow step type "${c.getType()}"`);
|
|
1358
|
+
const l = await u.execute(
|
|
1359
|
+
c,
|
|
1407
1360
|
e,
|
|
1408
1361
|
n,
|
|
1409
1362
|
o,
|
|
1410
1363
|
r
|
|
1411
1364
|
);
|
|
1412
|
-
if (
|
|
1413
|
-
const
|
|
1414
|
-
r[
|
|
1365
|
+
if (l !== void 0) {
|
|
1366
|
+
const h = c.getName(), g = typeof h == "string" ? h : `Step${i + 1}`;
|
|
1367
|
+
r[g] = l;
|
|
1415
1368
|
}
|
|
1416
1369
|
await n.flush();
|
|
1417
1370
|
}
|
|
1418
1371
|
}
|
|
1419
1372
|
isChannelNameMatch(e, t) {
|
|
1420
1373
|
const n = t.channel;
|
|
1421
|
-
return
|
|
1374
|
+
return I(n) && e.source === "channel" && e.channelName === n;
|
|
1422
1375
|
}
|
|
1423
1376
|
/**
|
|
1424
1377
|
* Checks if the event matches the channel's event pattern (if specified)
|
|
1425
1378
|
*/
|
|
1426
1379
|
isEventPatternMatch(e, t, n) {
|
|
1427
|
-
|
|
1428
|
-
const o = (r = t.getProperties()) == null ? void 0 : r.event;
|
|
1380
|
+
const o = t.getProperties()?.event;
|
|
1429
1381
|
if (!o)
|
|
1430
1382
|
return !0;
|
|
1431
1383
|
try {
|
|
1432
|
-
const
|
|
1433
|
-
return
|
|
1434
|
-
} catch (
|
|
1435
|
-
return console.warn("Error during event pattern matching:",
|
|
1384
|
+
const r = n.getBlue(), s = r.resolve(e.payload);
|
|
1385
|
+
return r.isTypeOfNode(s, o);
|
|
1386
|
+
} catch (r) {
|
|
1387
|
+
return console.warn("Error during event pattern matching:", r), !1;
|
|
1436
1388
|
}
|
|
1437
1389
|
}
|
|
1438
1390
|
}
|
|
1439
|
-
class
|
|
1391
|
+
class it {
|
|
1392
|
+
contractType = "Sequential Workflow Operation";
|
|
1393
|
+
contractBlueId = f["Sequential Workflow Operation"];
|
|
1394
|
+
role = "handler";
|
|
1395
|
+
sequentialWorkflowProcessor;
|
|
1440
1396
|
constructor(e) {
|
|
1441
|
-
|
|
1442
|
-
l(this, "contractBlueId", y["Sequential Workflow Operation"]);
|
|
1443
|
-
l(this, "role", "handler");
|
|
1444
|
-
l(this, "sequentialWorkflowProcessor");
|
|
1445
|
-
this.sequentialWorkflowProcessor = e || new le();
|
|
1397
|
+
this.sequentialWorkflowProcessor = e || new ae();
|
|
1446
1398
|
}
|
|
1447
1399
|
supports(e, t, n) {
|
|
1448
1400
|
const s = n.getBlue().nodeToSchemaOutput(
|
|
1449
1401
|
t,
|
|
1450
|
-
|
|
1402
|
+
we
|
|
1451
1403
|
).operation, i = e.channelName;
|
|
1452
|
-
return e.source === "channel" &&
|
|
1404
|
+
return e.source === "channel" && I(i) && I(s) && i === s;
|
|
1453
1405
|
}
|
|
1454
1406
|
async handle(e, t, n, o) {
|
|
1455
1407
|
try {
|
|
@@ -1462,89 +1414,82 @@ class dt {
|
|
|
1462
1414
|
}
|
|
1463
1415
|
}
|
|
1464
1416
|
}
|
|
1465
|
-
const
|
|
1466
|
-
class
|
|
1467
|
-
|
|
1468
|
-
|
|
1469
|
-
|
|
1470
|
-
|
|
1471
|
-
|
|
1472
|
-
|
|
1473
|
-
|
|
1474
|
-
|
|
1475
|
-
|
|
1476
|
-
|
|
1477
|
-
|
|
1478
|
-
)
|
|
1479
|
-
|
|
1480
|
-
|
|
1481
|
-
handle(t, n, o, r) {
|
|
1482
|
-
ee(t) && o.emitEvent({
|
|
1483
|
-
payload: t.payload,
|
|
1484
|
-
channelName: r,
|
|
1417
|
+
const K = (a) => b.isTypeOf(a.payload, k);
|
|
1418
|
+
class ct extends S {
|
|
1419
|
+
contractType = "Timeline Channel";
|
|
1420
|
+
contractBlueId = f["Timeline Channel"];
|
|
1421
|
+
supports(e, t, n) {
|
|
1422
|
+
if (!this.baseSupports(e) || !K(e)) return !1;
|
|
1423
|
+
const r = n.getBlue().nodeToSchemaOutput(
|
|
1424
|
+
e.payload,
|
|
1425
|
+
k
|
|
1426
|
+
), s = n.getBlue().nodeToSchemaOutput(t, Te), i = r.timeline?.timelineId;
|
|
1427
|
+
return y(s.timelineId) && y(i) && i === s.timelineId;
|
|
1428
|
+
}
|
|
1429
|
+
handle(e, t, n, o) {
|
|
1430
|
+
K(e) && n.emitEvent({
|
|
1431
|
+
payload: e.payload,
|
|
1432
|
+
channelName: o,
|
|
1485
1433
|
source: "channel"
|
|
1486
1434
|
});
|
|
1487
1435
|
}
|
|
1488
1436
|
}
|
|
1489
|
-
class
|
|
1490
|
-
|
|
1491
|
-
|
|
1492
|
-
|
|
1493
|
-
|
|
1494
|
-
}
|
|
1495
|
-
supports(t) {
|
|
1496
|
-
return this.baseSupports(t) ? t.emissionType === "triggered" : !1;
|
|
1437
|
+
class lt extends S {
|
|
1438
|
+
contractType = "Triggered Event Channel";
|
|
1439
|
+
contractBlueId = f["Triggered Event Channel"];
|
|
1440
|
+
supports(e) {
|
|
1441
|
+
return this.baseSupports(e) ? e.emissionType === "triggered" : !1;
|
|
1497
1442
|
}
|
|
1498
|
-
handle(t, n, o
|
|
1499
|
-
|
|
1500
|
-
payload:
|
|
1501
|
-
channelName:
|
|
1443
|
+
handle(e, t, n, o) {
|
|
1444
|
+
n.emitEvent({
|
|
1445
|
+
payload: e.payload,
|
|
1446
|
+
channelName: o,
|
|
1502
1447
|
source: "channel"
|
|
1503
1448
|
});
|
|
1504
1449
|
}
|
|
1505
1450
|
}
|
|
1506
|
-
const
|
|
1507
|
-
new
|
|
1451
|
+
const ut = [
|
|
1452
|
+
new Ke(),
|
|
1508
1453
|
// channels
|
|
1509
|
-
new
|
|
1510
|
-
new
|
|
1511
|
-
new
|
|
1512
|
-
new Ze(),
|
|
1513
|
-
new et(),
|
|
1454
|
+
new ze(),
|
|
1455
|
+
new Ue(),
|
|
1456
|
+
new ct(),
|
|
1514
1457
|
new Xe(),
|
|
1515
|
-
new
|
|
1516
|
-
new
|
|
1517
|
-
new
|
|
1458
|
+
new Qe(),
|
|
1459
|
+
new Le(),
|
|
1460
|
+
new Fe(),
|
|
1461
|
+
new lt(),
|
|
1462
|
+
new Ge(),
|
|
1518
1463
|
// sequential workflows
|
|
1519
|
-
new
|
|
1520
|
-
new
|
|
1464
|
+
new ae(),
|
|
1465
|
+
new it(),
|
|
1521
1466
|
// markers
|
|
1522
|
-
new
|
|
1467
|
+
new He()
|
|
1523
1468
|
];
|
|
1524
|
-
class
|
|
1469
|
+
class gt {
|
|
1525
1470
|
/**
|
|
1526
1471
|
* Creates a new document processor
|
|
1527
1472
|
*
|
|
1528
1473
|
* @param processors - Initial list of processors to register
|
|
1529
1474
|
*/
|
|
1530
|
-
constructor(e, t =
|
|
1531
|
-
|
|
1532
|
-
l(this, "eventCounter", 0);
|
|
1533
|
-
l(this, "registry");
|
|
1534
|
-
l(this, "queue");
|
|
1535
|
-
l(this, "router");
|
|
1536
|
-
l(this, "checkpointCache", new Fe());
|
|
1537
|
-
this.blue = e, this.registry = new We(t), this.queue = new _e(), this.router = new Ue(
|
|
1475
|
+
constructor(e, t = ut) {
|
|
1476
|
+
this.blue = e, this.registry = new De(t), this.queue = new Ae(), this.router = new Ve(
|
|
1538
1477
|
this.blue,
|
|
1539
1478
|
this.registry,
|
|
1540
1479
|
this.queue,
|
|
1541
1480
|
() => ++this.taskCounter,
|
|
1542
1481
|
() => ++this.eventCounter
|
|
1543
1482
|
), this.register(
|
|
1544
|
-
new
|
|
1483
|
+
new We(this.checkpointCache),
|
|
1545
1484
|
9999
|
|
1546
1485
|
);
|
|
1547
1486
|
}
|
|
1487
|
+
taskCounter = 0;
|
|
1488
|
+
eventCounter = 0;
|
|
1489
|
+
registry;
|
|
1490
|
+
queue;
|
|
1491
|
+
router;
|
|
1492
|
+
checkpointCache = new Je();
|
|
1548
1493
|
/**
|
|
1549
1494
|
* Registers a new contract processor
|
|
1550
1495
|
*
|
|
@@ -1561,15 +1506,15 @@ class bt {
|
|
|
1561
1506
|
* @returns Processing result with final state and emitted events
|
|
1562
1507
|
*/
|
|
1563
1508
|
async initialize(e) {
|
|
1564
|
-
let t =
|
|
1509
|
+
let t = F(N(e), this.blue);
|
|
1565
1510
|
const n = {
|
|
1566
|
-
payload:
|
|
1511
|
+
payload: nt(this.blue),
|
|
1567
1512
|
source: "internal",
|
|
1568
1513
|
emissionType: "lifecycle"
|
|
1569
1514
|
}, o = [n.payload];
|
|
1570
1515
|
await this.router.route(t, [], n, 0);
|
|
1571
1516
|
const r = await this.drainQueue(t);
|
|
1572
|
-
return t = r.state, o.push(...r.emitted), t = Re(t, this.blue), { state:
|
|
1517
|
+
return t = r.state, o.push(...r.emitted), t = Re(t, this.blue), { state: B(t), emitted: o };
|
|
1573
1518
|
}
|
|
1574
1519
|
/**
|
|
1575
1520
|
* Processes a batch of events against the document
|
|
@@ -1579,9 +1524,9 @@ class bt {
|
|
|
1579
1524
|
* @returns Processing result with final state and emitted events
|
|
1580
1525
|
*/
|
|
1581
1526
|
async processEvents(e, t) {
|
|
1582
|
-
let n =
|
|
1527
|
+
let n = F(N(e), this.blue);
|
|
1583
1528
|
const o = [];
|
|
1584
|
-
if (!
|
|
1529
|
+
if (!re(n, this.blue))
|
|
1585
1530
|
throw new Error("Document is not initialized");
|
|
1586
1531
|
for (const r of t)
|
|
1587
1532
|
try {
|
|
@@ -1590,72 +1535,71 @@ class bt {
|
|
|
1590
1535
|
const i = await this.drainQueue(n);
|
|
1591
1536
|
n = i.state, o.push(...i.emitted);
|
|
1592
1537
|
const c = this.checkpointCache.flush(n);
|
|
1593
|
-
c.length && (n =
|
|
1538
|
+
c.length && (n = H(n, c));
|
|
1594
1539
|
} finally {
|
|
1595
1540
|
this.checkpointCache.clear();
|
|
1596
1541
|
}
|
|
1597
|
-
return { state:
|
|
1542
|
+
return { state: B(n), emitted: o };
|
|
1598
1543
|
}
|
|
1599
1544
|
/**
|
|
1600
1545
|
* Drains the task queue and applies all actions
|
|
1601
1546
|
*/
|
|
1602
1547
|
async drainQueue(e) {
|
|
1603
|
-
var s;
|
|
1604
1548
|
let t = e;
|
|
1605
1549
|
const n = [], o = 1e4;
|
|
1606
1550
|
let r = 0;
|
|
1607
1551
|
for (; this.queue.length; ) {
|
|
1608
1552
|
if (++r > o)
|
|
1609
1553
|
throw new Error("Possible cycle – too many iterations");
|
|
1610
|
-
const
|
|
1611
|
-
if (!
|
|
1612
|
-
const
|
|
1613
|
-
if (!
|
|
1614
|
-
console.warn(`No processor registered for contract: ${
|
|
1554
|
+
const s = this.queue.pop(), { nodePath: i, contractName: c, contractNode: u, event: l } = s, h = t.get(i);
|
|
1555
|
+
if (!P(h) || !h.getContracts()?.[c] || !u.getType()) continue;
|
|
1556
|
+
const g = this.registry.get(u.getType());
|
|
1557
|
+
if (!g) {
|
|
1558
|
+
console.warn(`No processor registered for contract: ${c}`);
|
|
1615
1559
|
continue;
|
|
1616
1560
|
}
|
|
1617
|
-
const
|
|
1561
|
+
const p = new te(
|
|
1618
1562
|
() => t,
|
|
1619
|
-
|
|
1563
|
+
s,
|
|
1620
1564
|
this.blue,
|
|
1621
|
-
async (
|
|
1622
|
-
for (const
|
|
1623
|
-
if (
|
|
1624
|
-
const
|
|
1565
|
+
async (E) => {
|
|
1566
|
+
for (const m of E)
|
|
1567
|
+
if (m.kind === "patch") {
|
|
1568
|
+
const O = W(
|
|
1625
1569
|
t,
|
|
1626
1570
|
this.blue
|
|
1627
1571
|
);
|
|
1628
|
-
for (const
|
|
1629
|
-
const
|
|
1630
|
-
(
|
|
1631
|
-
),
|
|
1632
|
-
|
|
1633
|
-
|
|
1572
|
+
for (const v of O) {
|
|
1573
|
+
const ce = m.patch.op === "move" || m.patch.op === "copy" ? [m.patch.from, m.patch.path] : [m.patch.path], L = p.getNodePath(), le = ce.some(
|
|
1574
|
+
(he) => z(he, v.absPath)
|
|
1575
|
+
), ue = z(
|
|
1576
|
+
L,
|
|
1577
|
+
v.absPath
|
|
1634
1578
|
);
|
|
1635
|
-
if (
|
|
1636
|
-
throw new
|
|
1637
|
-
|
|
1638
|
-
|
|
1639
|
-
|
|
1579
|
+
if (le && !ue)
|
|
1580
|
+
throw new oe(
|
|
1581
|
+
m.patch,
|
|
1582
|
+
v.absPath,
|
|
1583
|
+
L
|
|
1640
1584
|
);
|
|
1641
1585
|
}
|
|
1642
1586
|
try {
|
|
1643
|
-
t =
|
|
1644
|
-
} catch (
|
|
1645
|
-
throw
|
|
1587
|
+
t = H(t, [m.patch]);
|
|
1588
|
+
} catch (v) {
|
|
1589
|
+
throw _e(c, l, v), v;
|
|
1646
1590
|
}
|
|
1647
|
-
} else
|
|
1591
|
+
} else m.kind === "event" && (n.push(m.event.payload), await this.router.route(t, [], m.event, s.key[5]));
|
|
1648
1592
|
}
|
|
1649
1593
|
);
|
|
1650
|
-
await
|
|
1594
|
+
await g.handle(l, u, p, c), await p.flush();
|
|
1651
1595
|
}
|
|
1652
1596
|
return { state: t, emitted: n };
|
|
1653
1597
|
}
|
|
1654
1598
|
}
|
|
1655
|
-
class
|
|
1599
|
+
class ie {
|
|
1656
1600
|
process(e, t) {
|
|
1657
1601
|
const n = t.getValue();
|
|
1658
|
-
if (
|
|
1602
|
+
if (w(n)) {
|
|
1659
1603
|
const o = t.clone();
|
|
1660
1604
|
return o.setValue(n), o.setProperties(void 0), o.setItems(void 0), o.setType(void 0), o;
|
|
1661
1605
|
}
|
|
@@ -1666,48 +1610,48 @@ class ue {
|
|
|
1666
1610
|
*/
|
|
1667
1611
|
postProcess(e, t) {
|
|
1668
1612
|
const n = t.getValue();
|
|
1669
|
-
if (
|
|
1613
|
+
if (w(n) && e.getValue() !== n && n !== void 0) {
|
|
1670
1614
|
const o = e.clone();
|
|
1671
1615
|
return o.setValue(n), o;
|
|
1672
1616
|
}
|
|
1673
1617
|
return e;
|
|
1674
1618
|
}
|
|
1675
1619
|
}
|
|
1676
|
-
const
|
|
1620
|
+
const yt = /* @__PURE__ */ Object.freeze(/* @__PURE__ */ Object.defineProperty({
|
|
1677
1621
|
__proto__: null,
|
|
1678
|
-
ExpressionPreserver:
|
|
1622
|
+
ExpressionPreserver: ie
|
|
1679
1623
|
}, Symbol.toStringTag, { value: "Module" }));
|
|
1680
|
-
function
|
|
1681
|
-
return new
|
|
1682
|
-
new
|
|
1683
|
-
new
|
|
1684
|
-
new
|
|
1685
|
-
new
|
|
1686
|
-
new
|
|
1687
|
-
new
|
|
1624
|
+
function Et() {
|
|
1625
|
+
return new C.SequentialMergingProcessor([
|
|
1626
|
+
new C.ValuePropagator(),
|
|
1627
|
+
new ie(),
|
|
1628
|
+
new C.TypeAssigner(),
|
|
1629
|
+
new C.ListProcessor(),
|
|
1630
|
+
new C.DictionaryProcessor(),
|
|
1631
|
+
new C.BasicTypesVerifier()
|
|
1688
1632
|
]);
|
|
1689
1633
|
}
|
|
1690
1634
|
export {
|
|
1691
|
-
|
|
1692
|
-
|
|
1693
|
-
|
|
1694
|
-
|
|
1695
|
-
|
|
1696
|
-
|
|
1697
|
-
|
|
1698
|
-
|
|
1699
|
-
|
|
1700
|
-
|
|
1701
|
-
|
|
1702
|
-
|
|
1703
|
-
|
|
1704
|
-
|
|
1705
|
-
|
|
1706
|
-
|
|
1707
|
-
|
|
1708
|
-
|
|
1709
|
-
|
|
1710
|
-
|
|
1711
|
-
|
|
1712
|
-
|
|
1635
|
+
gt as BlueDocumentProcessor,
|
|
1636
|
+
We as ChannelEventCheckpointProcessor,
|
|
1637
|
+
Oe as CodeBlockEvaluationError,
|
|
1638
|
+
Le as CompositeTimelineChannelProcessor,
|
|
1639
|
+
Ue as DocumentUpdateChannelProcessor,
|
|
1640
|
+
oe as EmbeddedDocumentModificationError,
|
|
1641
|
+
ze as EmbeddedNodeChannelProcessor,
|
|
1642
|
+
Be as ExpressionEvaluationError,
|
|
1643
|
+
He as InitializedMarkerProcessor,
|
|
1644
|
+
Fe as LifecycleEventChannelProcessor,
|
|
1645
|
+
yt as MergingProcessors,
|
|
1646
|
+
Qe as MyOSAgentChannelProcessor,
|
|
1647
|
+
Xe as MyOSTimelineChannelProcessor,
|
|
1648
|
+
Ge as OperationProcessor,
|
|
1649
|
+
ne as PatchApplicationError,
|
|
1650
|
+
Ke as ProcessEmbeddedProcessor,
|
|
1651
|
+
it as SequentialWorkflowOperationProcessor,
|
|
1652
|
+
ae as SequentialWorkflowProcessor,
|
|
1653
|
+
ct as TimelineChannelProcessor,
|
|
1654
|
+
lt as TriggeredEventChannelProcessor,
|
|
1655
|
+
W as collectEmbeddedPathSpecs,
|
|
1656
|
+
Et as createDefaultMergingProcessor
|
|
1713
1657
|
};
|