@blue-labs/document-processor 1.24.3 → 1.26.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 +2 -2
- package/dist/index.mjs +415 -409
- package/dist/processors/ChannelEventCheckpointProcessor.d.ts.map +1 -1
- package/dist/processors/LifecycleEventChannelProcessor.d.ts.map +1 -1
- package/dist/processors/MyOSAgentChannelProcessor.d.ts.map +1 -1
- package/dist/processors/MyOSTimelineChannelProcessor.d.ts.map +1 -1
- package/dist/processors/OperationProcessor.d.ts.map +1 -1
- package/dist/processors/SequentialWorkflowProcessor/steps/JavaScriptCodeExecutor.d.ts +1 -1
- package/dist/processors/SequentialWorkflowProcessor/steps/JavaScriptCodeExecutor.d.ts.map +1 -1
- package/dist/processors/SequentialWorkflowProcessor/steps/TriggerEventExecutor.d.ts.map +1 -1
- package/dist/processors/SequentialWorkflowProcessor/steps/UpdateDocumentExecutor.d.ts.map +1 -1
- package/dist/processors/SequentialWorkflowProcessor/utils/BindingsFactory.d.ts.map +1 -1
- package/dist/processors/TimelineChannelProcessor.d.ts.map +1 -1
- package/dist/types.d.ts +1 -4
- package/dist/types.d.ts.map +1 -1
- package/dist/utils/eventFactories.d.ts +5 -5
- package/dist/utils/eventFactories.d.ts.map +1 -1
- package/package.json +5 -5
package/dist/index.mjs
CHANGED
|
@@ -1,31 +1,31 @@
|
|
|
1
|
-
var
|
|
2
|
-
var
|
|
3
|
-
var l = (c, e, t) =>
|
|
4
|
-
import { ProcessEmbeddedSchema as
|
|
5
|
-
import { applyBlueNodePatch as
|
|
6
|
-
import { deepFreeze as
|
|
7
|
-
import { blueIds as Y, MyOSTimelineEntrySchema as
|
|
8
|
-
const
|
|
1
|
+
var ue = Object.defineProperty;
|
|
2
|
+
var he = (c, e, t) => e in c ? ue(c, e, { enumerable: !0, configurable: !0, writable: !0, value: t }) : c[e] = t;
|
|
3
|
+
var l = (c, e, t) => he(c, typeof e != "symbol" ? e + "" : e, t);
|
|
4
|
+
import { ProcessEmbeddedSchema as $, ChannelEventCheckpointSchema as de, blueIds as f, InitializedMarkerSchema as pe, CompositeTimelineChannelSchema as me, DocumentUpdateChannelSchema as fe, EmbeddedNodeChannelSchema as x, LifecycleEventSchema as ye, TimelineEntrySchema as k, OperationSchema as ge, OperationRequestSchema as Ee, UpdateDocumentSchema as O, TriggerEventSchema as B, JavaScriptCodeSchema as M, SequentialWorkflowSchema as we, SequentialWorkflowOperationSchema as ve, TimelineChannelSchema as Te } from "@blue-repository/core-dev";
|
|
5
|
+
import { applyBlueNodePatch as K, BlueNodeTypeSchema as E, BlueNode as be, isBigNumber as q } from "@blue-labs/language";
|
|
6
|
+
import { deepFreeze as I, isNonNullable as N, deepContains as X } from "@blue-labs/shared-utils";
|
|
7
|
+
import { blueIds as Y, MyOSTimelineEntrySchema as Z, MyOSTimelineChannelSchema as Se, MyOSAgentEventSchema as Pe, MyOSAgentChannelSchema as Ce } from "@blue-repository/myos-dev";
|
|
8
|
+
const ke = (c, e) => ({
|
|
9
9
|
on: (t, n) => ({ end: () => n(null) })
|
|
10
10
|
});
|
|
11
|
-
async function
|
|
11
|
+
async function Ie(c) {
|
|
12
12
|
return new Promise((e, t) => {
|
|
13
|
-
|
|
13
|
+
ke().on("error", t).end();
|
|
14
14
|
});
|
|
15
15
|
}
|
|
16
|
-
const
|
|
16
|
+
const T = (...c) => c.map((e, t) => {
|
|
17
17
|
if (typeof e != "string") return "";
|
|
18
18
|
if (t === 0 && e === "/") return "/";
|
|
19
19
|
const n = t > 0 ? e.replace(/^\/+/, "") : e;
|
|
20
20
|
return t < c.length - 1 ? n.replace(/\/+$/, "") : n;
|
|
21
21
|
}).filter(Boolean).join("/").replace(/\/{2,}/g, "/");
|
|
22
|
-
class
|
|
22
|
+
class G {
|
|
23
23
|
constructor(e, t, n, o) {
|
|
24
24
|
l(this, "actions", []);
|
|
25
25
|
this.getDocument = e, this.taskInfo = t, this.blue = n, this.onFlush = o;
|
|
26
26
|
}
|
|
27
27
|
get(e) {
|
|
28
|
-
const t = this.getDocument(), n =
|
|
28
|
+
const t = this.getDocument(), n = T(this.taskInfo.nodePath, e);
|
|
29
29
|
return t.get(n);
|
|
30
30
|
}
|
|
31
31
|
addPatch(e) {
|
|
@@ -33,7 +33,7 @@ class Z {
|
|
|
33
33
|
kind: "patch",
|
|
34
34
|
patch: {
|
|
35
35
|
...e,
|
|
36
|
-
path:
|
|
36
|
+
path: T(this.taskInfo.nodePath, e.path)
|
|
37
37
|
}
|
|
38
38
|
});
|
|
39
39
|
}
|
|
@@ -56,7 +56,7 @@ class Z {
|
|
|
56
56
|
return this.taskInfo.nodePath;
|
|
57
57
|
}
|
|
58
58
|
resolvePath(e) {
|
|
59
|
-
return
|
|
59
|
+
return T(this.taskInfo.nodePath, e);
|
|
60
60
|
}
|
|
61
61
|
getTaskInfo() {
|
|
62
62
|
return this.taskInfo;
|
|
@@ -68,25 +68,25 @@ class Z {
|
|
|
68
68
|
loadExternalModule(e) {
|
|
69
69
|
if (!/^https?:\/\//.test(e))
|
|
70
70
|
throw new Error("Only http/https URLs are allowed");
|
|
71
|
-
return
|
|
71
|
+
return Ie();
|
|
72
72
|
}
|
|
73
73
|
loadBlueContent(e) {
|
|
74
74
|
throw new Error("Not implemented");
|
|
75
75
|
}
|
|
76
76
|
}
|
|
77
|
-
class
|
|
77
|
+
class ee extends Error {
|
|
78
78
|
constructor(e, t) {
|
|
79
79
|
super(`Cannot apply patch ${JSON.stringify(e)}`), this.patch = e, this.cause = t, this.name = "PatchApplicationError";
|
|
80
80
|
}
|
|
81
81
|
}
|
|
82
|
-
class
|
|
82
|
+
class te extends Error {
|
|
83
83
|
constructor(e, t, n) {
|
|
84
84
|
super(
|
|
85
85
|
`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}")`
|
|
86
86
|
), this.patch = e, this.offendingPath = t, this.contractNodePath = n, this.name = "EmbeddedDocumentModificationError";
|
|
87
87
|
}
|
|
88
88
|
}
|
|
89
|
-
class
|
|
89
|
+
class J extends Error {
|
|
90
90
|
constructor(e, t) {
|
|
91
91
|
super(`Failed to evaluate expression "${e}"`), this.code = e, this.cause = t, this.name = "ExpressionEvaluationError";
|
|
92
92
|
}
|
|
@@ -96,48 +96,48 @@ class V extends Error {
|
|
|
96
96
|
super(`Failed to evaluate code block "${e}"`), this.code = e, this.cause = t, this.name = "CodeBlockEvaluationError";
|
|
97
97
|
}
|
|
98
98
|
}
|
|
99
|
-
function
|
|
99
|
+
function W(c, e, t = "/", n = []) {
|
|
100
100
|
const o = c.getContracts() ?? {};
|
|
101
|
-
for (const [
|
|
102
|
-
if (
|
|
103
|
-
|
|
104
|
-
|
|
101
|
+
for (const [r, a] of Object.entries(o))
|
|
102
|
+
if (E.isTypeOf(
|
|
103
|
+
a,
|
|
104
|
+
$
|
|
105
105
|
)) {
|
|
106
106
|
const u = e.nodeToSchemaOutput(
|
|
107
|
-
|
|
108
|
-
|
|
107
|
+
a,
|
|
108
|
+
$
|
|
109
109
|
).paths ?? [];
|
|
110
110
|
for (const h of u)
|
|
111
111
|
n.push({
|
|
112
|
-
absPath:
|
|
113
|
-
contractPath:
|
|
112
|
+
absPath: T(t, h),
|
|
113
|
+
contractPath: T(t, `contracts/${r}`)
|
|
114
114
|
});
|
|
115
115
|
}
|
|
116
|
-
for (const [
|
|
117
|
-
|
|
116
|
+
for (const [r, a] of Object.entries(c.getProperties() ?? {}))
|
|
117
|
+
W(a, e, T(t, r), n);
|
|
118
118
|
return n;
|
|
119
119
|
}
|
|
120
120
|
function F(c, e) {
|
|
121
121
|
return c === e || c.startsWith(e.endsWith("/") ? e : e + "/");
|
|
122
122
|
}
|
|
123
|
-
function
|
|
123
|
+
function L(c, e) {
|
|
124
124
|
if (!e.length) return c;
|
|
125
125
|
let t = c.clone();
|
|
126
126
|
for (const n of e)
|
|
127
127
|
try {
|
|
128
|
-
t =
|
|
128
|
+
t = K(t, n, !0);
|
|
129
129
|
} catch (o) {
|
|
130
|
-
throw new
|
|
130
|
+
throw new ee(n, o);
|
|
131
131
|
}
|
|
132
|
-
return
|
|
132
|
+
return I(t);
|
|
133
133
|
}
|
|
134
|
-
function
|
|
134
|
+
function m(c) {
|
|
135
135
|
return c != null;
|
|
136
136
|
}
|
|
137
|
-
function
|
|
138
|
-
return c instanceof
|
|
137
|
+
function S(c) {
|
|
138
|
+
return c instanceof be;
|
|
139
139
|
}
|
|
140
|
-
class
|
|
140
|
+
class Ne {
|
|
141
141
|
constructor(e = [], t = (n, o) => n < o ? -1 : n > o ? 1 : 0) {
|
|
142
142
|
l(this, "data");
|
|
143
143
|
l(this, "length");
|
|
@@ -159,30 +159,30 @@ class Ie {
|
|
|
159
159
|
_up(e) {
|
|
160
160
|
const { data: t, compare: n } = this, o = t[e];
|
|
161
161
|
for (; e > 0; ) {
|
|
162
|
-
const
|
|
163
|
-
if (n(o,
|
|
164
|
-
t[e] =
|
|
162
|
+
const r = e - 1 >> 1, a = t[r];
|
|
163
|
+
if (n(o, a) >= 0) break;
|
|
164
|
+
t[e] = a, e = r;
|
|
165
165
|
}
|
|
166
166
|
t[e] = o;
|
|
167
167
|
}
|
|
168
168
|
_down(e) {
|
|
169
|
-
const { data: t, compare: n } = this, o = this.length >> 1,
|
|
169
|
+
const { data: t, compare: n } = this, o = this.length >> 1, r = t[e];
|
|
170
170
|
for (; e < o; ) {
|
|
171
|
-
let
|
|
172
|
-
const s =
|
|
173
|
-
if (s < this.length && n(t[s], t[
|
|
174
|
-
t[e] = t[
|
|
171
|
+
let a = (e << 1) + 1;
|
|
172
|
+
const s = a + 1;
|
|
173
|
+
if (s < this.length && n(t[s], t[a]) < 0 && (a = s), n(t[a], r) >= 0) break;
|
|
174
|
+
t[e] = t[a], e = a;
|
|
175
175
|
}
|
|
176
|
-
t[e] =
|
|
176
|
+
t[e] = r;
|
|
177
177
|
}
|
|
178
178
|
}
|
|
179
|
-
const
|
|
179
|
+
const Oe = (c, e, t, n, o, r) => [
|
|
180
180
|
-c,
|
|
181
181
|
e,
|
|
182
182
|
t,
|
|
183
183
|
n,
|
|
184
184
|
o,
|
|
185
|
-
|
|
185
|
+
r
|
|
186
186
|
], Be = (c, e) => {
|
|
187
187
|
for (let t = 0; t < c.key.length; t++) {
|
|
188
188
|
const n = c.key[t], o = e.key[t];
|
|
@@ -191,13 +191,13 @@ const Ne = (c, e, t, n, o, a) => [
|
|
|
191
191
|
}
|
|
192
192
|
return 0;
|
|
193
193
|
};
|
|
194
|
-
class
|
|
194
|
+
class Me {
|
|
195
195
|
/**
|
|
196
196
|
* Creates a new task queue with the task key comparator
|
|
197
197
|
*/
|
|
198
198
|
constructor() {
|
|
199
199
|
l(this, "queue");
|
|
200
|
-
this.queue = new
|
|
200
|
+
this.queue = new Ne([], Be);
|
|
201
201
|
}
|
|
202
202
|
/**
|
|
203
203
|
* Adds a task to the queue
|
|
@@ -222,7 +222,7 @@ class Oe {
|
|
|
222
222
|
return this.queue.length;
|
|
223
223
|
}
|
|
224
224
|
}
|
|
225
|
-
class
|
|
225
|
+
class $e {
|
|
226
226
|
/**
|
|
227
227
|
* Creates a new contract registry
|
|
228
228
|
*
|
|
@@ -277,7 +277,7 @@ class Me {
|
|
|
277
277
|
return this.processors.values();
|
|
278
278
|
}
|
|
279
279
|
}
|
|
280
|
-
class
|
|
280
|
+
class qe {
|
|
281
281
|
constructor() {
|
|
282
282
|
l(this, "isEnabled");
|
|
283
283
|
this.isEnabled = process.env.TRACE_BLUE_ENABLED === "true";
|
|
@@ -344,8 +344,8 @@ class $e {
|
|
|
344
344
|
return this.isEnabled;
|
|
345
345
|
}
|
|
346
346
|
}
|
|
347
|
-
const
|
|
348
|
-
class
|
|
347
|
+
const Ae = 64;
|
|
348
|
+
class De {
|
|
349
349
|
/**
|
|
350
350
|
* Creates a new event router
|
|
351
351
|
*
|
|
@@ -354,9 +354,9 @@ class Ae {
|
|
|
354
354
|
* @param getNextTaskId - Function to get the next task ID
|
|
355
355
|
* @param getNextEventSeq - Function to get the next event sequence number
|
|
356
356
|
*/
|
|
357
|
-
constructor(e, t, n, o,
|
|
357
|
+
constructor(e, t, n, o, r) {
|
|
358
358
|
l(this, "traceManager");
|
|
359
|
-
this.blue = e, this.registry = t, this.queue = n, this.getNextTaskId = o, this.getNextEventSeq =
|
|
359
|
+
this.blue = e, this.registry = t, this.queue = n, this.getNextTaskId = o, this.getNextEventSeq = r, this.traceManager = new qe();
|
|
360
360
|
}
|
|
361
361
|
/**
|
|
362
362
|
* Routes an event to matching contracts in the document
|
|
@@ -367,27 +367,27 @@ class Ae {
|
|
|
367
367
|
* @param afterTaskId - Minimum task ID to use
|
|
368
368
|
* @param inlineDepth - Current adapter recursion depth
|
|
369
369
|
*/
|
|
370
|
-
async route(e, t, n, o,
|
|
370
|
+
async route(e, t, n, o, r = 0) {
|
|
371
371
|
var i;
|
|
372
372
|
if (n.seq === void 0 && (n.seq = this.getNextEventSeq()), t.length === 0) {
|
|
373
373
|
if (n.dispatchPath) {
|
|
374
374
|
const u = n.dispatchPath.split("/").filter(Boolean), h = { ...n };
|
|
375
|
-
return delete h.dispatchPath, this.route(e, u, h, o,
|
|
375
|
+
return delete h.dispatchPath, this.route(e, u, h, o, r);
|
|
376
376
|
}
|
|
377
377
|
if (n.source === "channel" && n.originNodePath && n.originNodePath !== "/") {
|
|
378
378
|
const u = ((i = n.originNodePath) == null ? void 0 : i.split("/").filter(Boolean)) ?? [];
|
|
379
|
-
return this.route(e, u, n, o,
|
|
379
|
+
return this.route(e, u, n, o, r);
|
|
380
380
|
}
|
|
381
381
|
}
|
|
382
|
-
const
|
|
383
|
-
|
|
382
|
+
const a = T("/", t.join("/")), s = e.get(a);
|
|
383
|
+
S(s) && await this.traverseContracts({
|
|
384
384
|
doc: e,
|
|
385
385
|
node: s,
|
|
386
|
-
nodePath:
|
|
386
|
+
nodePath: a,
|
|
387
387
|
event: n,
|
|
388
388
|
afterTaskId: o,
|
|
389
389
|
pathSegments: t,
|
|
390
|
-
inlineDepth:
|
|
390
|
+
inlineDepth: r
|
|
391
391
|
});
|
|
392
392
|
}
|
|
393
393
|
/**
|
|
@@ -398,12 +398,12 @@ class Ae {
|
|
|
398
398
|
doc: t,
|
|
399
399
|
node: n,
|
|
400
400
|
nodePath: o,
|
|
401
|
-
event:
|
|
402
|
-
afterTaskId:
|
|
401
|
+
event: r,
|
|
402
|
+
afterTaskId: a,
|
|
403
403
|
pathSegments: s,
|
|
404
404
|
inlineDepth: i
|
|
405
405
|
} = e;
|
|
406
|
-
if (!this.shouldSkipForChannel(
|
|
406
|
+
if (!this.shouldSkipForChannel(r, o))
|
|
407
407
|
for (const [u, h] of Object.entries(
|
|
408
408
|
n.getContracts() ?? {}
|
|
409
409
|
)) {
|
|
@@ -417,19 +417,19 @@ class Ae {
|
|
|
417
417
|
nodePath: o,
|
|
418
418
|
contractName: u,
|
|
419
419
|
contractNode: h,
|
|
420
|
-
event:
|
|
421
|
-
},
|
|
422
|
-
if (d.supports(
|
|
420
|
+
event: r
|
|
421
|
+
}, y = new G(() => t, p, this.blue);
|
|
422
|
+
if (d.supports(r, h, y, u))
|
|
423
423
|
switch (d.role) {
|
|
424
424
|
case "adapter":
|
|
425
425
|
await this.processAdapter({
|
|
426
426
|
cp: d,
|
|
427
|
-
event:
|
|
427
|
+
event: r,
|
|
428
428
|
contractNode: h,
|
|
429
|
-
ctx:
|
|
429
|
+
ctx: y,
|
|
430
430
|
contractName: u,
|
|
431
431
|
doc: t,
|
|
432
|
-
afterTaskId:
|
|
432
|
+
afterTaskId: a,
|
|
433
433
|
inlineDepth: i
|
|
434
434
|
});
|
|
435
435
|
break;
|
|
@@ -438,9 +438,9 @@ class Ae {
|
|
|
438
438
|
contractNode: h,
|
|
439
439
|
contractName: u,
|
|
440
440
|
nodePath: o,
|
|
441
|
-
event:
|
|
441
|
+
event: r,
|
|
442
442
|
depth: s.length,
|
|
443
|
-
afterTaskId:
|
|
443
|
+
afterTaskId: a
|
|
444
444
|
});
|
|
445
445
|
break;
|
|
446
446
|
}
|
|
@@ -450,57 +450,57 @@ class Ae {
|
|
|
450
450
|
* Processes an adapter contract and routes any emitted events
|
|
451
451
|
*/
|
|
452
452
|
async processAdapter(e) {
|
|
453
|
-
var
|
|
453
|
+
var w;
|
|
454
454
|
const {
|
|
455
455
|
cp: t,
|
|
456
456
|
event: n,
|
|
457
457
|
contractNode: o,
|
|
458
|
-
ctx:
|
|
459
|
-
contractName:
|
|
458
|
+
ctx: r,
|
|
459
|
+
contractName: a,
|
|
460
460
|
doc: s,
|
|
461
461
|
afterTaskId: i,
|
|
462
462
|
inlineDepth: u
|
|
463
463
|
} = e;
|
|
464
|
-
if (u >=
|
|
464
|
+
if (u >= Ae)
|
|
465
465
|
throw new Error("Adapter recursion limit reached");
|
|
466
466
|
const h = this.traceManager.addHop(
|
|
467
467
|
n,
|
|
468
|
-
((
|
|
469
|
-
|
|
468
|
+
((w = r.getTaskInfo()) == null ? void 0 : w.nodePath) ?? "",
|
|
469
|
+
a
|
|
470
470
|
);
|
|
471
|
-
await t.handle(h, o,
|
|
472
|
-
const d = await
|
|
471
|
+
await t.handle(h, o, r, a);
|
|
472
|
+
const d = await r.flush();
|
|
473
473
|
if (d.find((b) => b.kind === "patch"))
|
|
474
474
|
throw new Error(
|
|
475
|
-
`Contract "${
|
|
475
|
+
`Contract "${a}" (adapter) attempted to patch the document`
|
|
476
476
|
);
|
|
477
|
-
const
|
|
478
|
-
for (const b of
|
|
477
|
+
const y = d.filter((b) => b.kind === "event");
|
|
478
|
+
for (const b of y)
|
|
479
479
|
await this.route(s, [], b.event, i, u + 1);
|
|
480
480
|
}
|
|
481
481
|
/**
|
|
482
482
|
* Schedules a handler contract for future execution
|
|
483
483
|
*/
|
|
484
484
|
scheduleHandler(e) {
|
|
485
|
-
const { contractNode: t, contractName: n, nodePath: o, event:
|
|
485
|
+
const { contractNode: t, contractName: n, nodePath: o, event: r, depth: a, afterTaskId: s } = e, i = t.getType();
|
|
486
486
|
if (!i) {
|
|
487
487
|
console.warn(`Contract node type is not defined for: ${n}`);
|
|
488
488
|
return;
|
|
489
489
|
}
|
|
490
|
-
const u = this.registry.orderOf(i), h = t.get("/order"), d =
|
|
491
|
-
|
|
492
|
-
|
|
490
|
+
const u = this.registry.orderOf(i), h = t.get("/order"), d = q(h) ? h.toNumber() : 0, p = this.getNextTaskId() + s, y = Oe(
|
|
491
|
+
a,
|
|
492
|
+
r.seq,
|
|
493
493
|
u,
|
|
494
494
|
d,
|
|
495
495
|
n,
|
|
496
496
|
p
|
|
497
|
-
),
|
|
497
|
+
), w = this.traceManager.addHop(r, o, n);
|
|
498
498
|
this.queue.push({
|
|
499
|
-
key:
|
|
499
|
+
key: y,
|
|
500
500
|
nodePath: o,
|
|
501
501
|
contractName: n,
|
|
502
502
|
contractNode: t,
|
|
503
|
-
event:
|
|
503
|
+
event: w
|
|
504
504
|
});
|
|
505
505
|
}
|
|
506
506
|
/**
|
|
@@ -510,53 +510,53 @@ class Ae {
|
|
|
510
510
|
return e.source === "channel" && !!e.originNodePath && e.originNodePath !== t;
|
|
511
511
|
}
|
|
512
512
|
}
|
|
513
|
-
const
|
|
514
|
-
(t instanceof
|
|
513
|
+
const We = (c, e, t) => {
|
|
514
|
+
(t instanceof ee || t instanceof te) && console.error(
|
|
515
515
|
`[Blue] Failed to apply patches for contract "${c}" on event ${JSON.stringify(e)}`,
|
|
516
516
|
t
|
|
517
517
|
);
|
|
518
518
|
};
|
|
519
|
-
function
|
|
519
|
+
function U(c, e) {
|
|
520
520
|
const t = c.clone(), n = (o) => {
|
|
521
|
-
if (!
|
|
522
|
-
const
|
|
523
|
-
(!(
|
|
524
|
-
|
|
525
|
-
|
|
521
|
+
if (!S(o)) return;
|
|
522
|
+
const r = o.getContracts();
|
|
523
|
+
(!(r != null && r.checkpoint) || !E.isTypeOf(
|
|
524
|
+
r.checkpoint,
|
|
525
|
+
de
|
|
526
526
|
)) && o.addContract(
|
|
527
527
|
"checkpoint",
|
|
528
528
|
e.jsonValueToNode({
|
|
529
529
|
type: {
|
|
530
530
|
name: "Channel Event Checkpoint",
|
|
531
|
-
blueId:
|
|
531
|
+
blueId: f["Channel Event Checkpoint"]
|
|
532
532
|
},
|
|
533
533
|
lastEvents: {}
|
|
534
534
|
})
|
|
535
535
|
);
|
|
536
536
|
};
|
|
537
537
|
n(t);
|
|
538
|
-
for (const { absPath: o } of
|
|
539
|
-
const
|
|
540
|
-
|
|
538
|
+
for (const { absPath: o } of W(t, e)) {
|
|
539
|
+
const r = t.get(o);
|
|
540
|
+
S(r) && n(r);
|
|
541
541
|
}
|
|
542
|
-
return
|
|
542
|
+
return I(t);
|
|
543
543
|
}
|
|
544
544
|
function je(c, e) {
|
|
545
545
|
const t = c.clone();
|
|
546
|
-
return
|
|
546
|
+
return S(t) ? (ne(t, e) || t.addContract(
|
|
547
547
|
"initialized",
|
|
548
548
|
e.jsonValueToNode({
|
|
549
549
|
type: {
|
|
550
550
|
name: "Initialized Marker",
|
|
551
|
-
blueId:
|
|
551
|
+
blueId: f["Initialized Marker"]
|
|
552
552
|
}
|
|
553
553
|
})
|
|
554
|
-
),
|
|
554
|
+
), I(t)) : I(t);
|
|
555
555
|
}
|
|
556
|
-
function
|
|
556
|
+
function ne(c, e) {
|
|
557
557
|
const t = c.getContracts();
|
|
558
558
|
return Object.values(t ?? {}).some(
|
|
559
|
-
(n) => e.isTypeOf(n,
|
|
559
|
+
(n) => e.isTypeOf(n, pe, {
|
|
560
560
|
checkSchemaExtensions: !0
|
|
561
561
|
})
|
|
562
562
|
);
|
|
@@ -564,7 +564,7 @@ function te(c, e) {
|
|
|
564
564
|
class xe {
|
|
565
565
|
constructor(e) {
|
|
566
566
|
l(this, "contractType", "Channel Event Checkpoint");
|
|
567
|
-
l(this, "contractBlueId",
|
|
567
|
+
l(this, "contractBlueId", f["Channel Event Checkpoint"]);
|
|
568
568
|
l(this, "role", "handler");
|
|
569
569
|
this.cache = e;
|
|
570
570
|
}
|
|
@@ -573,14 +573,14 @@ class xe {
|
|
|
573
573
|
return e.source === "channel" && ((t = e.rootEvent) == null ? void 0 : t.payload) === e.payload && ((n = e.rootEvent) == null ? void 0 : n.source) === "external";
|
|
574
574
|
}
|
|
575
575
|
async handle(e, t, n) {
|
|
576
|
-
var
|
|
577
|
-
if (!e.channelName || !((
|
|
578
|
-
const o = await n.getBlue().calculateBlueId(e.rootEvent.payload),
|
|
579
|
-
this.cache.record(
|
|
576
|
+
var a;
|
|
577
|
+
if (!e.channelName || !((a = e.rootEvent) != null && a.seq)) return;
|
|
578
|
+
const o = await n.getBlue().calculateBlueId(e.rootEvent.payload), r = n.getNodePath().replace(/\/contracts\/checkpoint$/, "");
|
|
579
|
+
this.cache.record(r, e, o);
|
|
580
580
|
}
|
|
581
581
|
}
|
|
582
582
|
const _ = (c, e) => c.get(e) !== void 0;
|
|
583
|
-
class
|
|
583
|
+
class Je {
|
|
584
584
|
constructor() {
|
|
585
585
|
l(this, "firstSeen", /* @__PURE__ */ new Map());
|
|
586
586
|
}
|
|
@@ -591,21 +591,21 @@ class We {
|
|
|
591
591
|
/** Turn cached data into JSON-Patch ops */
|
|
592
592
|
flush(e) {
|
|
593
593
|
const t = [];
|
|
594
|
-
for (const { docBase: n, event: o, eventBlueId:
|
|
594
|
+
for (const { docBase: n, event: o, eventBlueId: r } of this.firstSeen.values()) {
|
|
595
595
|
if (!o.channelName) continue;
|
|
596
|
-
const
|
|
596
|
+
const a = T(
|
|
597
597
|
n,
|
|
598
598
|
"contracts/checkpoint/lastEvents",
|
|
599
599
|
o.channelName
|
|
600
|
-
), s = `${
|
|
601
|
-
_(e,
|
|
600
|
+
), s = `${a}/blueId`;
|
|
601
|
+
_(e, a) ? t.push({
|
|
602
602
|
op: _(e, s) ? "replace" : "add",
|
|
603
603
|
path: s,
|
|
604
|
-
val:
|
|
604
|
+
val: r
|
|
605
605
|
}) : t.push({
|
|
606
606
|
op: "add",
|
|
607
|
-
path:
|
|
608
|
-
val: { blueId:
|
|
607
|
+
path: a,
|
|
608
|
+
val: { blueId: r }
|
|
609
609
|
});
|
|
610
610
|
}
|
|
611
611
|
return t;
|
|
@@ -614,7 +614,7 @@ class We {
|
|
|
614
614
|
this.firstSeen.clear();
|
|
615
615
|
}
|
|
616
616
|
}
|
|
617
|
-
class
|
|
617
|
+
class P {
|
|
618
618
|
constructor() {
|
|
619
619
|
l(this, "role", "adapter");
|
|
620
620
|
}
|
|
@@ -626,70 +626,70 @@ class S {
|
|
|
626
626
|
return e.source !== "channel";
|
|
627
627
|
}
|
|
628
628
|
}
|
|
629
|
-
class Ve extends
|
|
629
|
+
class Ve extends P {
|
|
630
630
|
constructor() {
|
|
631
631
|
super(...arguments);
|
|
632
632
|
l(this, "contractType", "Composite Timeline Channel");
|
|
633
|
-
l(this, "contractBlueId",
|
|
633
|
+
l(this, "contractBlueId", f["Composite Timeline Channel"]);
|
|
634
634
|
}
|
|
635
635
|
supports(t, n, o) {
|
|
636
|
-
const
|
|
637
|
-
return !
|
|
636
|
+
const r = o.getBlue().nodeToSchemaOutput(n, me);
|
|
637
|
+
return !r.channels || !t.channelName ? !1 : r.channels.includes(t.channelName);
|
|
638
638
|
}
|
|
639
|
-
handle(t, n, o,
|
|
639
|
+
handle(t, n, o, r) {
|
|
640
640
|
o.emitEvent({
|
|
641
641
|
payload: t.payload,
|
|
642
|
-
channelName:
|
|
642
|
+
channelName: r,
|
|
643
643
|
source: "channel"
|
|
644
644
|
});
|
|
645
645
|
}
|
|
646
646
|
}
|
|
647
|
-
class Fe extends
|
|
647
|
+
class Fe extends P {
|
|
648
648
|
constructor() {
|
|
649
649
|
super(...arguments);
|
|
650
650
|
l(this, "contractType", "Document Update Channel");
|
|
651
|
-
l(this, "contractBlueId",
|
|
651
|
+
l(this, "contractBlueId", f["Document Update Channel"]);
|
|
652
652
|
}
|
|
653
|
-
supports(t, n, o,
|
|
653
|
+
supports(t, n, o, r) {
|
|
654
654
|
if (!this.baseSupports(t)) return !1;
|
|
655
|
-
const
|
|
656
|
-
if (!s || t.channelName ===
|
|
657
|
-
const i =
|
|
658
|
-
return
|
|
659
|
-
}
|
|
660
|
-
handle(t, n, o,
|
|
661
|
-
const
|
|
662
|
-
|
|
663
|
-
payload:
|
|
664
|
-
channelName:
|
|
655
|
+
const a = o.getBlue().nodeToSchemaOutput(n, fe), s = t.payload.get("/path");
|
|
656
|
+
if (!s || t.channelName === r) return !1;
|
|
657
|
+
const i = a.path;
|
|
658
|
+
return N(i) && s === o.resolvePath(i);
|
|
659
|
+
}
|
|
660
|
+
handle(t, n, o, r) {
|
|
661
|
+
const a = t.payload;
|
|
662
|
+
a && o.emitEvent({
|
|
663
|
+
payload: a,
|
|
664
|
+
channelName: r,
|
|
665
665
|
source: "channel"
|
|
666
666
|
});
|
|
667
667
|
}
|
|
668
668
|
}
|
|
669
|
-
class
|
|
669
|
+
class Le extends P {
|
|
670
670
|
constructor() {
|
|
671
671
|
super(...arguments);
|
|
672
672
|
l(this, "contractType", "Embedded Node Channel");
|
|
673
|
-
l(this, "contractBlueId",
|
|
673
|
+
l(this, "contractBlueId", f["Embedded Node Channel"]);
|
|
674
674
|
}
|
|
675
675
|
supports(t, n, o) {
|
|
676
676
|
if (!this.baseSupports(t)) return !1;
|
|
677
|
-
const
|
|
678
|
-
return
|
|
677
|
+
const r = o.getBlue().nodeToSchemaOutput(n, x);
|
|
678
|
+
return m(t.originNodePath) && m(r.path) && t.originNodePath === o.resolvePath(r.path);
|
|
679
679
|
}
|
|
680
|
-
handle(t, n, o,
|
|
681
|
-
const
|
|
682
|
-
|
|
680
|
+
handle(t, n, o, r) {
|
|
681
|
+
const a = o.getBlue().nodeToSchemaOutput(n, x), { originNodePath: s, payload: i } = t;
|
|
682
|
+
m(a.path) && s === o.resolvePath(a.path) && o.emitEvent({
|
|
683
683
|
payload: i,
|
|
684
|
-
channelName:
|
|
684
|
+
channelName: r,
|
|
685
685
|
source: "channel"
|
|
686
686
|
});
|
|
687
687
|
}
|
|
688
688
|
}
|
|
689
|
-
class
|
|
689
|
+
class Ue {
|
|
690
690
|
constructor() {
|
|
691
691
|
l(this, "contractType", "Initialized Marker");
|
|
692
|
-
l(this, "contractBlueId",
|
|
692
|
+
l(this, "contractBlueId", f["Initialized Marker"]);
|
|
693
693
|
l(this, "role", "marker");
|
|
694
694
|
}
|
|
695
695
|
supports() {
|
|
@@ -698,77 +698,75 @@ class Le {
|
|
|
698
698
|
handle() {
|
|
699
699
|
}
|
|
700
700
|
}
|
|
701
|
-
|
|
702
|
-
"Document Processing Initiated"
|
|
703
|
-
// Add more lifecycle events here as needed
|
|
704
|
-
// 'Document Processing Completed',
|
|
705
|
-
// 'Document Processing Failed',
|
|
706
|
-
]);
|
|
707
|
-
class Ue extends S {
|
|
701
|
+
class _e extends P {
|
|
708
702
|
constructor() {
|
|
709
703
|
super(...arguments);
|
|
710
704
|
l(this, "contractType", "Lifecycle Event Channel");
|
|
711
|
-
l(this, "contractBlueId",
|
|
705
|
+
l(this, "contractBlueId", f["Lifecycle Event Channel"]);
|
|
712
706
|
}
|
|
713
707
|
supports(t, n, o) {
|
|
714
|
-
return !this.baseSupports(t) || !this.isLifecycleEvent(t) ? !1 : this.isEventPatternMatch(t, n, o);
|
|
708
|
+
return !this.baseSupports(t) || !this.isLifecycleEvent(t, o) ? !1 : this.isEventPatternMatch(t, n, o);
|
|
715
709
|
}
|
|
716
|
-
handle(t, n, o,
|
|
710
|
+
handle(t, n, o, r) {
|
|
717
711
|
o.emitEvent({
|
|
718
712
|
payload: t.payload,
|
|
719
|
-
channelName:
|
|
713
|
+
channelName: r,
|
|
720
714
|
source: "channel"
|
|
721
715
|
});
|
|
722
716
|
}
|
|
723
717
|
/**
|
|
724
718
|
* Checks if the event is a supported lifecycle event type
|
|
725
719
|
*/
|
|
726
|
-
isLifecycleEvent(t) {
|
|
727
|
-
|
|
720
|
+
isLifecycleEvent(t, n) {
|
|
721
|
+
const o = n.getBlue(), r = t.payload;
|
|
722
|
+
return o.isTypeOf(r, ye, {
|
|
723
|
+
checkSchemaExtensions: !0
|
|
724
|
+
});
|
|
728
725
|
}
|
|
729
726
|
/**
|
|
730
727
|
* Checks if the event matches the channel's event pattern (if specified)
|
|
731
728
|
*/
|
|
732
729
|
isEventPatternMatch(t, n, o) {
|
|
733
|
-
var
|
|
734
|
-
const
|
|
735
|
-
if (!
|
|
730
|
+
var a;
|
|
731
|
+
const r = (a = n.getProperties()) == null ? void 0 : a.event;
|
|
732
|
+
if (!r)
|
|
736
733
|
return !0;
|
|
737
734
|
try {
|
|
738
|
-
const s = o.getBlue(), i = s.nodeToJson(
|
|
739
|
-
s.jsonValueToNode(t.payload)
|
|
740
|
-
), u = s.nodeToJson(a);
|
|
735
|
+
const s = o.getBlue(), i = s.nodeToJson(t.payload), u = s.nodeToJson(r);
|
|
741
736
|
return X(i, u);
|
|
742
737
|
} catch (s) {
|
|
743
738
|
return console.warn("Error during lifecycle event pattern matching:", s), !1;
|
|
744
739
|
}
|
|
745
740
|
}
|
|
746
741
|
}
|
|
747
|
-
const
|
|
748
|
-
|
|
742
|
+
const z = (c, e) => {
|
|
743
|
+
const t = e.getBlue();
|
|
744
|
+
return t.isTypeOf(c.payload, k) || t.isTypeOf(c.payload, Z);
|
|
745
|
+
};
|
|
746
|
+
class ze extends P {
|
|
749
747
|
constructor() {
|
|
750
748
|
super(...arguments);
|
|
751
749
|
l(this, "contractType", "MyOS Timeline Channel");
|
|
752
750
|
l(this, "contractBlueId", Y["MyOS Timeline Channel"]);
|
|
753
751
|
}
|
|
754
752
|
supports(t, n, o) {
|
|
755
|
-
var
|
|
756
|
-
if (!this.baseSupports(t) || !
|
|
757
|
-
const a = o.getBlue()
|
|
758
|
-
|
|
759
|
-
|
|
760
|
-
),
|
|
761
|
-
return
|
|
762
|
-
}
|
|
763
|
-
handle(t, n, o,
|
|
764
|
-
|
|
753
|
+
var p;
|
|
754
|
+
if (!this.baseSupports(t) || !z(t, o)) return !1;
|
|
755
|
+
const a = o.getBlue().nodeToSchemaOutput(
|
|
756
|
+
t.payload,
|
|
757
|
+
Z
|
|
758
|
+
), s = o.getBlue().nodeToSchemaOutput(n, Se), i = (p = a.timeline) == null ? void 0 : p.timelineId, u = m(s.timelineId) && m(i), h = m(s.account) && m(a.account), d = m(s.email) && m(a.email);
|
|
759
|
+
return u && i === s.timelineId || h && a.account === s.account || d && a.email === s.email;
|
|
760
|
+
}
|
|
761
|
+
handle(t, n, o, r) {
|
|
762
|
+
z(t, o) && o.emitEvent({
|
|
765
763
|
payload: t.payload,
|
|
766
|
-
channelName:
|
|
764
|
+
channelName: r,
|
|
767
765
|
source: "channel"
|
|
768
766
|
});
|
|
769
767
|
}
|
|
770
768
|
}
|
|
771
|
-
class He extends
|
|
769
|
+
class He extends P {
|
|
772
770
|
constructor() {
|
|
773
771
|
super(...arguments);
|
|
774
772
|
l(this, "contractType", "MyOS Agent Channel");
|
|
@@ -777,20 +775,20 @@ class He extends S {
|
|
|
777
775
|
supports(t, n, o) {
|
|
778
776
|
if (!this.baseSupports(t)) return !1;
|
|
779
777
|
try {
|
|
780
|
-
const { myosAgentEvent:
|
|
778
|
+
const { myosAgentEvent: r, myosAgentChannel: a } = this.parseEventAndChannel(
|
|
781
779
|
t,
|
|
782
780
|
n,
|
|
783
781
|
o
|
|
784
782
|
);
|
|
785
|
-
return this.isAgentMatch(
|
|
786
|
-
} catch (
|
|
787
|
-
return console.warn("Error in MyOSAgentChannelProcessor.supports:",
|
|
783
|
+
return this.isAgentMatch(r, a) && this.isEventPatternMatch(r, a, o);
|
|
784
|
+
} catch (r) {
|
|
785
|
+
return console.warn("Error in MyOSAgentChannelProcessor.supports:", r), !1;
|
|
788
786
|
}
|
|
789
787
|
}
|
|
790
|
-
handle(t, n, o,
|
|
788
|
+
handle(t, n, o, r) {
|
|
791
789
|
o.emitEvent({
|
|
792
790
|
payload: t.payload,
|
|
793
|
-
channelName:
|
|
791
|
+
channelName: r,
|
|
794
792
|
source: "channel"
|
|
795
793
|
});
|
|
796
794
|
}
|
|
@@ -799,14 +797,14 @@ class He extends S {
|
|
|
799
797
|
* @throws {Error} If schema validation fails
|
|
800
798
|
*/
|
|
801
799
|
parseEventAndChannel(t, n, o) {
|
|
802
|
-
const
|
|
803
|
-
|
|
800
|
+
const r = o.getBlue(), a = r.nodeToSchemaOutput(
|
|
801
|
+
t.payload,
|
|
804
802
|
Pe
|
|
805
|
-
),
|
|
803
|
+
), s = r.nodeToSchemaOutput(
|
|
806
804
|
n,
|
|
807
|
-
|
|
805
|
+
Ce
|
|
808
806
|
);
|
|
809
|
-
return { myosAgentEvent:
|
|
807
|
+
return { myosAgentEvent: a, myosAgentChannel: s };
|
|
810
808
|
}
|
|
811
809
|
/**
|
|
812
810
|
* Checks if the agent IDs match between event and channel
|
|
@@ -815,9 +813,9 @@ class He extends S {
|
|
|
815
813
|
* @returns true if both have valid agent IDs and they match
|
|
816
814
|
*/
|
|
817
815
|
isAgentMatch(t, n) {
|
|
818
|
-
var
|
|
819
|
-
const o = t.agentId,
|
|
820
|
-
return
|
|
816
|
+
var a;
|
|
817
|
+
const o = t.agentId, r = (a = n.agent) == null ? void 0 : a.agentId;
|
|
818
|
+
return m(o) && m(r) && o === r;
|
|
821
819
|
}
|
|
822
820
|
/**
|
|
823
821
|
* Checks if the event pattern matches the channel's event filter
|
|
@@ -833,14 +831,14 @@ class He extends S {
|
|
|
833
831
|
* - Otherwise → uses deep containment matching (event must contain all channel pattern fields)
|
|
834
832
|
*/
|
|
835
833
|
isEventPatternMatch(t, n, o) {
|
|
836
|
-
const
|
|
837
|
-
if (!a)
|
|
838
|
-
return !0;
|
|
839
|
-
const r = t.event;
|
|
834
|
+
const r = n.event;
|
|
840
835
|
if (!r)
|
|
836
|
+
return !0;
|
|
837
|
+
const a = t.event;
|
|
838
|
+
if (!a)
|
|
841
839
|
return !1;
|
|
842
840
|
try {
|
|
843
|
-
const s = o.getBlue(), i = s.nodeToJson(
|
|
841
|
+
const s = o.getBlue(), i = s.nodeToJson(a), u = s.nodeToJson(r);
|
|
844
842
|
return X(i, u);
|
|
845
843
|
} catch (s) {
|
|
846
844
|
return console.warn("Error during event pattern matching:", s), !1;
|
|
@@ -850,12 +848,12 @@ class He extends S {
|
|
|
850
848
|
class Re {
|
|
851
849
|
constructor() {
|
|
852
850
|
l(this, "contractType", "Operation");
|
|
853
|
-
l(this, "contractBlueId",
|
|
851
|
+
l(this, "contractBlueId", f.Operation);
|
|
854
852
|
l(this, "role", "adapter");
|
|
855
853
|
}
|
|
856
854
|
supports(e, t, n, o) {
|
|
857
|
-
const
|
|
858
|
-
return
|
|
855
|
+
const a = n.getBlue().nodeToSchemaOutput(t, ge), s = this.parseEventPayload(e, n);
|
|
856
|
+
return m(s == null ? void 0 : s.operation) && s.operation === o && e.source === "channel" && e.channelName === a.channel;
|
|
859
857
|
}
|
|
860
858
|
async handle(e, t, n, o) {
|
|
861
859
|
n.emitEvent({
|
|
@@ -865,18 +863,18 @@ class Re {
|
|
|
865
863
|
});
|
|
866
864
|
}
|
|
867
865
|
parseEventPayload(e, t) {
|
|
868
|
-
const n = t.getBlue()
|
|
869
|
-
if (n.isTypeOf(
|
|
866
|
+
const n = t.getBlue();
|
|
867
|
+
if (n.isTypeOf(e.payload, k, {
|
|
870
868
|
checkSchemaExtensions: !0
|
|
871
869
|
})) {
|
|
872
|
-
const
|
|
873
|
-
|
|
874
|
-
|
|
870
|
+
const o = n.nodeToSchemaOutput(
|
|
871
|
+
e.payload,
|
|
872
|
+
k
|
|
875
873
|
);
|
|
876
|
-
if (
|
|
874
|
+
if (o.message)
|
|
877
875
|
return n.nodeToSchemaOutput(
|
|
878
|
-
|
|
879
|
-
|
|
876
|
+
o.message,
|
|
877
|
+
Ee
|
|
880
878
|
);
|
|
881
879
|
}
|
|
882
880
|
return null;
|
|
@@ -886,32 +884,32 @@ class Qe {
|
|
|
886
884
|
constructor() {
|
|
887
885
|
l(this, "contractType", "Process Embedded");
|
|
888
886
|
l(this, "role", "adapter");
|
|
889
|
-
l(this, "contractBlueId",
|
|
887
|
+
l(this, "contractBlueId", f["Process Embedded"]);
|
|
890
888
|
}
|
|
891
889
|
supports(e) {
|
|
892
890
|
return e.source !== "channel";
|
|
893
891
|
}
|
|
894
892
|
handle(e, t, n) {
|
|
895
|
-
const o = n.getBlue().nodeToSchemaOutput(t,
|
|
896
|
-
for (const
|
|
893
|
+
const o = n.getBlue().nodeToSchemaOutput(t, $);
|
|
894
|
+
for (const r of o.paths ?? [])
|
|
897
895
|
n.emitEvent({
|
|
898
896
|
...e,
|
|
899
|
-
dispatchPath: n.resolvePath(
|
|
897
|
+
dispatchPath: n.resolvePath(r)
|
|
900
898
|
});
|
|
901
899
|
}
|
|
902
900
|
}
|
|
903
|
-
const
|
|
904
|
-
let
|
|
905
|
-
if (
|
|
901
|
+
const oe = !process.env.SKIP_ISOLATED_VM;
|
|
902
|
+
let v = null;
|
|
903
|
+
if (oe)
|
|
906
904
|
try {
|
|
907
|
-
|
|
905
|
+
v = require("isolated-vm");
|
|
908
906
|
} catch {
|
|
909
907
|
console.warn("isolated-vm not available, using fallback evaluation method");
|
|
910
908
|
}
|
|
911
|
-
function
|
|
909
|
+
function H(c) {
|
|
912
910
|
return /\bimport\s.+\sfrom\s+['"][^'"]+['"]/.test(c) || /\bexport\s+/.test(c);
|
|
913
911
|
}
|
|
914
|
-
class
|
|
912
|
+
class A {
|
|
915
913
|
/**
|
|
916
914
|
* Main evaluation method - chooses between secure and simple evaluation strategies
|
|
917
915
|
*/
|
|
@@ -921,14 +919,14 @@ class q {
|
|
|
921
919
|
bindings: n = {},
|
|
922
920
|
options: o = {}
|
|
923
921
|
}) {
|
|
924
|
-
return !
|
|
922
|
+
return !v || !oe ? this.evaluateSimple(e, n, o) : this.evaluateSecure(e, n, t, o);
|
|
925
923
|
}
|
|
926
924
|
/**
|
|
927
925
|
* Fallback evaluation using Node's Function constructor
|
|
928
926
|
* Used when isolated-vm is not available
|
|
929
927
|
*/
|
|
930
928
|
static async evaluateSimple(e, t, n = {}) {
|
|
931
|
-
if (
|
|
929
|
+
if (H(e))
|
|
932
930
|
throw new Error(
|
|
933
931
|
"Static import/export syntax requires isolated-vm – start Node without SKIP_ISOLATED_VM."
|
|
934
932
|
);
|
|
@@ -949,99 +947,99 @@ class q {
|
|
|
949
947
|
`return ${e};`
|
|
950
948
|
)(...Object.values(t));
|
|
951
949
|
} catch (o) {
|
|
952
|
-
throw n.isCodeBlock ? new V(e, o) : new
|
|
950
|
+
throw n.isCodeBlock ? new V(e, o) : new J(e, o);
|
|
953
951
|
}
|
|
954
952
|
}
|
|
955
953
|
/**
|
|
956
954
|
* Secure evaluation using isolated-vm with support for ES modules
|
|
957
955
|
*/
|
|
958
956
|
static async evaluateSecure(e, t, n, o = {}) {
|
|
959
|
-
if (!
|
|
960
|
-
const
|
|
957
|
+
if (!v) throw new Error("isolated-vm not available");
|
|
958
|
+
const r = new v.Isolate({ memoryLimit: 32 }), a = await r.createContext(), s = a.global;
|
|
961
959
|
try {
|
|
962
960
|
await this.setupIsolateEnvironment(s, t);
|
|
963
961
|
const i = /* @__PURE__ */ new Map(), u = this.createModuleResolver(
|
|
964
|
-
a,
|
|
965
962
|
r,
|
|
963
|
+
a,
|
|
966
964
|
i,
|
|
967
965
|
n
|
|
968
966
|
);
|
|
969
|
-
return
|
|
970
|
-
a,
|
|
967
|
+
return H(e) ? await this.evaluateESModule(
|
|
971
968
|
r,
|
|
969
|
+
a,
|
|
972
970
|
e,
|
|
973
971
|
o,
|
|
974
972
|
u
|
|
975
973
|
) : await this.evaluateSimpleScript(
|
|
976
|
-
a,
|
|
977
974
|
r,
|
|
975
|
+
a,
|
|
978
976
|
e,
|
|
979
977
|
t,
|
|
980
978
|
o
|
|
981
979
|
);
|
|
982
980
|
} catch (i) {
|
|
983
|
-
throw o.isCodeBlock ? new V(e, i) : new
|
|
981
|
+
throw o.isCodeBlock ? new V(e, i) : new J(e, i);
|
|
984
982
|
} finally {
|
|
985
|
-
|
|
983
|
+
a.release(), r.dispose();
|
|
986
984
|
}
|
|
987
985
|
}
|
|
988
986
|
/**
|
|
989
987
|
* Setup the isolated VM environment with necessary host functions and data
|
|
990
988
|
*/
|
|
991
989
|
static async setupIsolateEnvironment(e, t) {
|
|
992
|
-
if (!
|
|
993
|
-
const n = new
|
|
990
|
+
if (!v) throw new Error("isolated-vm not available");
|
|
991
|
+
const n = new v.Callback(
|
|
994
992
|
(...o) => console.log(...o)
|
|
995
993
|
);
|
|
996
994
|
await e.set("log", n);
|
|
997
|
-
for (const [o,
|
|
998
|
-
typeof
|
|
995
|
+
for (const [o, r] of Object.entries(t))
|
|
996
|
+
typeof r == "function" ? await e.set(
|
|
999
997
|
o,
|
|
1000
|
-
new
|
|
1001
|
-
) : await e.set(o, new
|
|
998
|
+
new v.Callback(r)
|
|
999
|
+
) : await e.set(o, new v.ExternalCopy(r).copyInto());
|
|
1002
1000
|
}
|
|
1003
1001
|
/**
|
|
1004
1002
|
* Create module resolver function for handling imports
|
|
1005
1003
|
*/
|
|
1006
1004
|
static createModuleResolver(e, t, n, o) {
|
|
1007
|
-
return async (
|
|
1008
|
-
if (n.has(
|
|
1009
|
-
if (
|
|
1010
|
-
const
|
|
1005
|
+
return async (r) => {
|
|
1006
|
+
if (n.has(r)) return n.get(r);
|
|
1007
|
+
if (r.startsWith("blue:")) {
|
|
1008
|
+
const a = r.slice(5), s = o.loadBlueContent;
|
|
1011
1009
|
if (typeof s != "function")
|
|
1012
1010
|
throw new Error(
|
|
1013
|
-
`ProcessingContext is missing a loadBlueContent(blueId) implementation (needed for ${
|
|
1011
|
+
`ProcessingContext is missing a loadBlueContent(blueId) implementation (needed for ${r})`
|
|
1014
1012
|
);
|
|
1015
|
-
const i = await s(
|
|
1016
|
-
return n.set(
|
|
1013
|
+
const i = await s(a), u = await e.compileModule(i);
|
|
1014
|
+
return n.set(r, u), await u.instantiate(
|
|
1017
1015
|
t,
|
|
1018
1016
|
this.createModuleResolver(e, t, n, o)
|
|
1019
1017
|
), u;
|
|
1020
1018
|
}
|
|
1021
|
-
if (/^https?:\/\//.test(
|
|
1022
|
-
let
|
|
1019
|
+
if (/^https?:\/\//.test(r)) {
|
|
1020
|
+
let a;
|
|
1023
1021
|
if (typeof o.loadExternalModule == "function")
|
|
1024
|
-
|
|
1022
|
+
a = await o.loadExternalModule(r);
|
|
1025
1023
|
else
|
|
1026
1024
|
throw new Error(
|
|
1027
|
-
`ProcessingContext is missing a loadExternalModule(url) implementation (needed for ${
|
|
1025
|
+
`ProcessingContext is missing a loadExternalModule(url) implementation (needed for ${r})`
|
|
1028
1026
|
);
|
|
1029
|
-
const s = await e.compileModule(
|
|
1030
|
-
return n.set(
|
|
1027
|
+
const s = await e.compileModule(a);
|
|
1028
|
+
return n.set(r, s), await s.instantiate(
|
|
1031
1029
|
t,
|
|
1032
1030
|
this.createModuleResolver(e, t, n, o)
|
|
1033
1031
|
), s;
|
|
1034
1032
|
}
|
|
1035
|
-
throw new Error(`Unsupported module specifier "${
|
|
1033
|
+
throw new Error(`Unsupported module specifier "${r}"`);
|
|
1036
1034
|
};
|
|
1037
1035
|
}
|
|
1038
1036
|
/**
|
|
1039
1037
|
* Evaluate code as a simple script (no imports/exports)
|
|
1040
1038
|
*/
|
|
1041
|
-
static async evaluateSimpleScript(e, t, n, o,
|
|
1042
|
-
const
|
|
1039
|
+
static async evaluateSimpleScript(e, t, n, o, r) {
|
|
1040
|
+
const a = Object.keys(o).join(", "), s = Object.keys(o).map((h) => h), i = `(async (${a}) => { ${r.isCodeBlock ? n : `return (${n});`} })(${s.join(", ")})`;
|
|
1043
1041
|
return await (await e.compileScript(i)).run(t, {
|
|
1044
|
-
timeout:
|
|
1042
|
+
timeout: r.timeout ?? 500,
|
|
1045
1043
|
promise: !0,
|
|
1046
1044
|
copy: !0,
|
|
1047
1045
|
release: !0
|
|
@@ -1050,14 +1048,14 @@ class q {
|
|
|
1050
1048
|
/**
|
|
1051
1049
|
* Evaluate code as an ES module with import/export support
|
|
1052
1050
|
*/
|
|
1053
|
-
static async evaluateESModule(e, t, n, o,
|
|
1054
|
-
let
|
|
1051
|
+
static async evaluateESModule(e, t, n, o, r) {
|
|
1052
|
+
let a = n;
|
|
1055
1053
|
if (o.isCodeBlock) {
|
|
1056
1054
|
const u = /^\s*(import\s.+?;|export\s.+?;)/gm, h = (n.match(u) || []).join(
|
|
1057
1055
|
`
|
|
1058
1056
|
`
|
|
1059
1057
|
), d = n.replace(u, "").trim();
|
|
1060
|
-
|
|
1058
|
+
a = `
|
|
1061
1059
|
${h}
|
|
1062
1060
|
const run = function() {
|
|
1063
1061
|
${d}
|
|
@@ -1065,8 +1063,8 @@ class q {
|
|
|
1065
1063
|
export default run();
|
|
1066
1064
|
`;
|
|
1067
1065
|
}
|
|
1068
|
-
const s = await e.compileModule(
|
|
1069
|
-
return await s.instantiate(t,
|
|
1066
|
+
const s = await e.compileModule(a);
|
|
1067
|
+
return await s.instantiate(t, r), await s.evaluate({
|
|
1070
1068
|
timeout: o.timeout ?? 500,
|
|
1071
1069
|
promise: !0,
|
|
1072
1070
|
reference: !0,
|
|
@@ -1079,118 +1077,128 @@ class q {
|
|
|
1079
1077
|
});
|
|
1080
1078
|
}
|
|
1081
1079
|
}
|
|
1082
|
-
class
|
|
1080
|
+
class D {
|
|
1083
1081
|
/**
|
|
1084
1082
|
* Creates standard bindings for workflow step execution
|
|
1085
1083
|
*/
|
|
1086
1084
|
static createStandardBindings(e, t, n) {
|
|
1087
|
-
const o = e.getBlue();
|
|
1085
|
+
const o = e.getBlue(), r = o.nodeToJson(t.payload, "simple"), a = q(r) ? r.toNumber() : r;
|
|
1088
1086
|
return {
|
|
1089
|
-
document: (
|
|
1090
|
-
const
|
|
1091
|
-
return
|
|
1087
|
+
document: (s) => {
|
|
1088
|
+
const i = e.get(s);
|
|
1089
|
+
return q(i) ? i.toNumber() : S(i) ? o.nodeToJson(i, "original") : i;
|
|
1092
1090
|
},
|
|
1093
|
-
event:
|
|
1091
|
+
event: a,
|
|
1094
1092
|
steps: n
|
|
1095
1093
|
};
|
|
1096
1094
|
}
|
|
1097
1095
|
}
|
|
1098
|
-
function
|
|
1099
|
-
const { op:
|
|
1100
|
-
if ((
|
|
1101
|
-
throw new Error(`${
|
|
1102
|
-
if ((
|
|
1103
|
-
throw new Error(`${
|
|
1104
|
-
const a = {
|
|
1105
|
-
|
|
1096
|
+
function R(c, e) {
|
|
1097
|
+
const { op: t, path: n, val: o, from: r } = c;
|
|
1098
|
+
if ((t === "move" || t === "copy") && !r)
|
|
1099
|
+
throw new Error(`${t} operation requires 'from' path`);
|
|
1100
|
+
if ((t === "add" || t === "replace") && o === void 0)
|
|
1101
|
+
throw new Error(`${t} operation requires 'val' property`);
|
|
1102
|
+
const a = {
|
|
1103
|
+
type: "Document Update",
|
|
1104
|
+
op: t,
|
|
1105
|
+
path: n
|
|
1106
|
+
};
|
|
1107
|
+
return o !== void 0 && (a.val = o), r !== void 0 && (a.from = r), e.jsonValueToNode(a);
|
|
1106
1108
|
}
|
|
1107
|
-
function Ke() {
|
|
1108
|
-
return {
|
|
1109
|
+
function Ke(c) {
|
|
1110
|
+
return c.jsonValueToNode({
|
|
1109
1111
|
type: "Document Processing Initiated"
|
|
1110
|
-
};
|
|
1112
|
+
});
|
|
1111
1113
|
}
|
|
1112
1114
|
class Xe {
|
|
1113
1115
|
constructor() {
|
|
1114
1116
|
l(this, "stepType", "Update Document");
|
|
1115
1117
|
}
|
|
1116
1118
|
supports(e) {
|
|
1117
|
-
return
|
|
1119
|
+
return E.isTypeOf(e, O);
|
|
1118
1120
|
}
|
|
1119
|
-
async execute(e, t, n, o,
|
|
1120
|
-
const
|
|
1121
|
-
if (!
|
|
1121
|
+
async execute(e, t, n, o, r) {
|
|
1122
|
+
const a = n.getBlue();
|
|
1123
|
+
if (!E.isTypeOf(e, O)) return;
|
|
1122
1124
|
const s = await this.evaluateChangeset(
|
|
1123
1125
|
e.get("/changeset"),
|
|
1124
1126
|
n,
|
|
1125
1127
|
t,
|
|
1126
|
-
|
|
1127
|
-
), i =
|
|
1128
|
+
r
|
|
1129
|
+
), i = K(e, {
|
|
1128
1130
|
op: "replace",
|
|
1129
1131
|
path: "/changeset",
|
|
1130
1132
|
val: s
|
|
1131
|
-
}), u = n.getBlue().nodeToSchemaOutput(i,
|
|
1133
|
+
}), u = n.getBlue().nodeToSchemaOutput(i, O);
|
|
1132
1134
|
for (const h of u.changeset ?? []) {
|
|
1133
1135
|
if (!h.path) continue;
|
|
1134
1136
|
const d = h.val;
|
|
1135
|
-
if ((h.op === "replace" || h.op === "add") &&
|
|
1137
|
+
if ((h.op === "replace" || h.op === "add") && N(d)) {
|
|
1136
1138
|
const p = await this.evaluateChangeValue(
|
|
1137
1139
|
d,
|
|
1138
1140
|
n,
|
|
1139
1141
|
t,
|
|
1140
|
-
|
|
1142
|
+
r
|
|
1141
1143
|
);
|
|
1142
1144
|
n.addPatch({
|
|
1143
1145
|
op: h.op,
|
|
1144
1146
|
path: h.path,
|
|
1145
1147
|
val: p
|
|
1146
1148
|
}), n.emitEvent({
|
|
1147
|
-
payload:
|
|
1148
|
-
|
|
1149
|
-
|
|
1150
|
-
|
|
1151
|
-
|
|
1149
|
+
payload: R(
|
|
1150
|
+
{
|
|
1151
|
+
op: h.op,
|
|
1152
|
+
path: n.resolvePath(h.path),
|
|
1153
|
+
val: a.nodeToJson(p, "original")
|
|
1154
|
+
},
|
|
1155
|
+
a
|
|
1156
|
+
)
|
|
1152
1157
|
});
|
|
1153
1158
|
}
|
|
1154
1159
|
h.op === "remove" && (n.addPatch({ op: h.op, path: h.path }), n.emitEvent({
|
|
1155
|
-
payload:
|
|
1156
|
-
|
|
1157
|
-
|
|
1158
|
-
|
|
1159
|
-
|
|
1160
|
+
payload: R(
|
|
1161
|
+
{
|
|
1162
|
+
op: h.op,
|
|
1163
|
+
path: n.resolvePath(h.path),
|
|
1164
|
+
val: null
|
|
1165
|
+
},
|
|
1166
|
+
a
|
|
1167
|
+
)
|
|
1160
1168
|
}));
|
|
1161
1169
|
}
|
|
1162
1170
|
}
|
|
1163
1171
|
async evaluateChangeset(e, t, n, o) {
|
|
1164
|
-
const
|
|
1172
|
+
const r = t.getBlue();
|
|
1165
1173
|
if (typeof e == "string" && e.startsWith("${") && e.endsWith("}")) {
|
|
1166
|
-
const
|
|
1167
|
-
code:
|
|
1174
|
+
const a = e.slice(2, -1), s = await A.evaluate({
|
|
1175
|
+
code: a,
|
|
1168
1176
|
ctx: t,
|
|
1169
|
-
bindings:
|
|
1177
|
+
bindings: D.createStandardBindings(
|
|
1170
1178
|
t,
|
|
1171
1179
|
n,
|
|
1172
1180
|
o
|
|
1173
1181
|
)
|
|
1174
1182
|
});
|
|
1175
|
-
return
|
|
1183
|
+
return r.jsonValueToNode(s ?? null);
|
|
1176
1184
|
}
|
|
1177
|
-
if (
|
|
1185
|
+
if (S(e))
|
|
1178
1186
|
return e;
|
|
1179
1187
|
throw new Error("Invalid changeset: expected a string or document node");
|
|
1180
1188
|
}
|
|
1181
1189
|
async evaluateChangeValue(e, t, n, o) {
|
|
1182
|
-
const
|
|
1183
|
-
if (typeof
|
|
1184
|
-
const s =
|
|
1190
|
+
const r = e.getValue(), a = t.getBlue();
|
|
1191
|
+
if (typeof r == "string" && r.startsWith("${") && r.endsWith("}")) {
|
|
1192
|
+
const s = r.slice(2, -1), i = await A.evaluate({
|
|
1185
1193
|
code: s,
|
|
1186
1194
|
ctx: t,
|
|
1187
|
-
bindings:
|
|
1195
|
+
bindings: D.createStandardBindings(
|
|
1188
1196
|
t,
|
|
1189
1197
|
n,
|
|
1190
1198
|
o
|
|
1191
1199
|
)
|
|
1192
1200
|
});
|
|
1193
|
-
return
|
|
1201
|
+
return a.jsonValueToNode(i ?? null);
|
|
1194
1202
|
}
|
|
1195
1203
|
return e;
|
|
1196
1204
|
}
|
|
@@ -1200,19 +1208,14 @@ class Ye {
|
|
|
1200
1208
|
l(this, "stepType", "Trigger Event");
|
|
1201
1209
|
}
|
|
1202
1210
|
supports(e) {
|
|
1203
|
-
return
|
|
1211
|
+
return E.isTypeOf(e, B);
|
|
1204
1212
|
}
|
|
1205
1213
|
async execute(e, t, n) {
|
|
1206
1214
|
const o = n.getBlue();
|
|
1207
|
-
if (!
|
|
1208
|
-
const
|
|
1209
|
-
|
|
1210
|
-
|
|
1211
|
-
a.event,
|
|
1212
|
-
"original"
|
|
1213
|
-
);
|
|
1214
|
-
n.emitEvent({
|
|
1215
|
-
payload: r
|
|
1215
|
+
if (!E.isTypeOf(e, B)) return;
|
|
1216
|
+
const r = o.nodeToSchemaOutput(e, B);
|
|
1217
|
+
r.event && n.emitEvent({
|
|
1218
|
+
payload: r.event
|
|
1216
1219
|
});
|
|
1217
1220
|
}
|
|
1218
1221
|
}
|
|
@@ -1221,20 +1224,20 @@ class Ze {
|
|
|
1221
1224
|
l(this, "stepType", "JavaScript Code");
|
|
1222
1225
|
}
|
|
1223
1226
|
supports(e) {
|
|
1224
|
-
return
|
|
1227
|
+
return E.isTypeOf(e, M);
|
|
1225
1228
|
}
|
|
1226
|
-
async execute(e, t, n, o,
|
|
1227
|
-
if (!
|
|
1228
|
-
const
|
|
1229
|
+
async execute(e, t, n, o, r) {
|
|
1230
|
+
if (!E.isTypeOf(e, M)) return;
|
|
1231
|
+
const a = n.getBlue(), s = a.nodeToSchemaOutput(
|
|
1229
1232
|
e,
|
|
1230
|
-
|
|
1233
|
+
M
|
|
1231
1234
|
);
|
|
1232
1235
|
if (!s.code)
|
|
1233
1236
|
throw new Error("JavaScript code is required");
|
|
1234
|
-
const i = await
|
|
1237
|
+
const i = await A.evaluate({
|
|
1235
1238
|
code: s.code,
|
|
1236
1239
|
ctx: n,
|
|
1237
|
-
bindings:
|
|
1240
|
+
bindings: D.createStandardBindings(n, t, r),
|
|
1238
1241
|
options: {
|
|
1239
1242
|
isCodeBlock: !0,
|
|
1240
1243
|
timeout: 500
|
|
@@ -1245,21 +1248,24 @@ class Ze {
|
|
|
1245
1248
|
if (Array.isArray(u.events))
|
|
1246
1249
|
for (const h of u.events)
|
|
1247
1250
|
n.emitEvent({
|
|
1248
|
-
payload: h
|
|
1251
|
+
payload: a.jsonValueToNode(Ge(h))
|
|
1249
1252
|
});
|
|
1250
1253
|
}
|
|
1251
1254
|
return i;
|
|
1252
1255
|
}
|
|
1253
1256
|
}
|
|
1254
|
-
|
|
1257
|
+
function Ge(c) {
|
|
1258
|
+
return JSON.parse(JSON.stringify(c));
|
|
1259
|
+
}
|
|
1260
|
+
const et = [
|
|
1255
1261
|
new Xe(),
|
|
1256
1262
|
new Ye(),
|
|
1257
1263
|
new Ze()
|
|
1258
1264
|
];
|
|
1259
|
-
class
|
|
1260
|
-
constructor(e =
|
|
1265
|
+
class re {
|
|
1266
|
+
constructor(e = et) {
|
|
1261
1267
|
l(this, "contractType", "Sequential Workflow");
|
|
1262
|
-
l(this, "contractBlueId",
|
|
1268
|
+
l(this, "contractBlueId", f["Sequential Workflow"]);
|
|
1263
1269
|
l(this, "role", "handler");
|
|
1264
1270
|
l(this, "executors", []);
|
|
1265
1271
|
this.executors = e;
|
|
@@ -1269,16 +1275,16 @@ class oe {
|
|
|
1269
1275
|
this.executors.push(e);
|
|
1270
1276
|
}
|
|
1271
1277
|
supports(e, t, n) {
|
|
1272
|
-
const
|
|
1278
|
+
const a = n.getBlue().nodeToSchemaOutput(
|
|
1273
1279
|
t,
|
|
1274
|
-
|
|
1280
|
+
we
|
|
1275
1281
|
).channel;
|
|
1276
|
-
return e.source === "channel" && e.channelName ===
|
|
1282
|
+
return e.source === "channel" && e.channelName === a;
|
|
1277
1283
|
}
|
|
1278
1284
|
async handle(e, t, n, o) {
|
|
1279
1285
|
var s;
|
|
1280
|
-
const
|
|
1281
|
-
for (const [i, u] of (
|
|
1286
|
+
const r = {}, a = (s = t.getProperties()) == null ? void 0 : s.steps.getItems();
|
|
1287
|
+
for (const [i, u] of (a ?? []).entries()) {
|
|
1282
1288
|
const h = this.executors.find((p) => p.supports(u));
|
|
1283
1289
|
if (!h)
|
|
1284
1290
|
throw new Error(`Unsupported workflow step type "${u.getType()}"`);
|
|
@@ -1287,97 +1293,97 @@ class oe {
|
|
|
1287
1293
|
e,
|
|
1288
1294
|
n,
|
|
1289
1295
|
o,
|
|
1290
|
-
|
|
1296
|
+
r
|
|
1291
1297
|
);
|
|
1292
1298
|
if (d !== void 0) {
|
|
1293
|
-
const p = u.getName(),
|
|
1294
|
-
|
|
1299
|
+
const p = u.getName(), y = typeof p == "string" ? p : `Step${i + 1}`;
|
|
1300
|
+
r[y] = d;
|
|
1295
1301
|
}
|
|
1296
1302
|
await n.flush();
|
|
1297
1303
|
}
|
|
1298
1304
|
}
|
|
1299
1305
|
}
|
|
1300
|
-
class
|
|
1306
|
+
class tt {
|
|
1301
1307
|
constructor(e) {
|
|
1302
1308
|
l(this, "contractType", "Sequential Workflow Operation");
|
|
1303
|
-
l(this, "contractBlueId",
|
|
1309
|
+
l(this, "contractBlueId", f["Sequential Workflow Operation"]);
|
|
1304
1310
|
l(this, "role", "handler");
|
|
1305
1311
|
l(this, "sequentialWorkflowProcessor");
|
|
1306
|
-
this.sequentialWorkflowProcessor = e || new
|
|
1312
|
+
this.sequentialWorkflowProcessor = e || new re();
|
|
1307
1313
|
}
|
|
1308
1314
|
supports(e, t, n) {
|
|
1309
|
-
const
|
|
1315
|
+
const a = n.getBlue().nodeToSchemaOutput(
|
|
1310
1316
|
t,
|
|
1311
|
-
|
|
1317
|
+
ve
|
|
1312
1318
|
).operation, s = e.channelName;
|
|
1313
|
-
return e.source === "channel" &&
|
|
1319
|
+
return e.source === "channel" && N(s) && N(a) && s === a;
|
|
1314
1320
|
}
|
|
1315
1321
|
async handle(e, t, n, o) {
|
|
1316
1322
|
try {
|
|
1317
1323
|
await this.sequentialWorkflowProcessor.handle(e, t, n, o);
|
|
1318
|
-
} catch (
|
|
1324
|
+
} catch (r) {
|
|
1319
1325
|
throw console.error(
|
|
1320
1326
|
"Error in SequentialWorkflowOperationProcessor.handle:",
|
|
1321
|
-
|
|
1322
|
-
),
|
|
1327
|
+
r
|
|
1328
|
+
), r;
|
|
1323
1329
|
}
|
|
1324
1330
|
}
|
|
1325
1331
|
}
|
|
1326
|
-
const
|
|
1327
|
-
class
|
|
1332
|
+
const Q = (c) => E.isTypeOf(c.payload, k);
|
|
1333
|
+
class nt extends P {
|
|
1328
1334
|
constructor() {
|
|
1329
1335
|
super(...arguments);
|
|
1330
1336
|
l(this, "contractType", "Timeline Channel");
|
|
1331
|
-
l(this, "contractBlueId",
|
|
1337
|
+
l(this, "contractBlueId", f["Timeline Channel"]);
|
|
1332
1338
|
}
|
|
1333
1339
|
supports(t, n, o) {
|
|
1334
1340
|
var h;
|
|
1335
|
-
if (!this.baseSupports(t) || !
|
|
1336
|
-
const a = o.getBlue()
|
|
1337
|
-
|
|
1338
|
-
|
|
1339
|
-
), s = o.getBlue().nodeToSchemaOutput(n,
|
|
1340
|
-
return
|
|
1341
|
-
}
|
|
1342
|
-
handle(t, n, o,
|
|
1343
|
-
|
|
1341
|
+
if (!this.baseSupports(t) || !Q(t)) return !1;
|
|
1342
|
+
const a = o.getBlue().nodeToSchemaOutput(
|
|
1343
|
+
t.payload,
|
|
1344
|
+
k
|
|
1345
|
+
), s = o.getBlue().nodeToSchemaOutput(n, Te), i = (h = a.timeline) == null ? void 0 : h.timelineId;
|
|
1346
|
+
return m(s.timelineId) && m(i) && i === s.timelineId;
|
|
1347
|
+
}
|
|
1348
|
+
handle(t, n, o, r) {
|
|
1349
|
+
Q(t) && o.emitEvent({
|
|
1344
1350
|
payload: t.payload,
|
|
1345
|
-
channelName:
|
|
1351
|
+
channelName: r,
|
|
1346
1352
|
source: "channel"
|
|
1347
1353
|
});
|
|
1348
1354
|
}
|
|
1349
1355
|
}
|
|
1350
|
-
const
|
|
1356
|
+
const ot = [
|
|
1351
1357
|
new Qe(),
|
|
1352
1358
|
// channels
|
|
1353
|
-
new
|
|
1359
|
+
new Le(),
|
|
1354
1360
|
new Fe(),
|
|
1355
|
-
new
|
|
1361
|
+
new nt(),
|
|
1356
1362
|
new ze(),
|
|
1357
1363
|
new He(),
|
|
1358
1364
|
new Ve(),
|
|
1359
|
-
new
|
|
1365
|
+
new _e(),
|
|
1360
1366
|
new Re(),
|
|
1361
1367
|
// sequential workflows
|
|
1362
|
-
new
|
|
1363
|
-
new
|
|
1368
|
+
new re(),
|
|
1369
|
+
new tt(),
|
|
1364
1370
|
// markers
|
|
1365
|
-
new
|
|
1371
|
+
new Ue()
|
|
1366
1372
|
];
|
|
1367
|
-
class
|
|
1373
|
+
class ut {
|
|
1368
1374
|
/**
|
|
1369
1375
|
* Creates a new document processor
|
|
1370
1376
|
*
|
|
1371
1377
|
* @param processors - Initial list of processors to register
|
|
1372
1378
|
*/
|
|
1373
|
-
constructor(e, t =
|
|
1379
|
+
constructor(e, t = ot) {
|
|
1374
1380
|
l(this, "taskCounter", 0);
|
|
1375
1381
|
l(this, "eventCounter", 0);
|
|
1376
1382
|
l(this, "registry");
|
|
1377
1383
|
l(this, "queue");
|
|
1378
1384
|
l(this, "router");
|
|
1379
|
-
l(this, "checkpointCache", new
|
|
1380
|
-
this.blue = e, this.registry = new
|
|
1385
|
+
l(this, "checkpointCache", new Je());
|
|
1386
|
+
this.blue = e, this.registry = new $e(t), this.queue = new Me(), this.router = new De(
|
|
1381
1387
|
this.blue,
|
|
1382
1388
|
this.registry,
|
|
1383
1389
|
this.queue,
|
|
@@ -1404,13 +1410,13 @@ class lt {
|
|
|
1404
1410
|
* @returns Processing result with final state and emitted events
|
|
1405
1411
|
*/
|
|
1406
1412
|
async initialize(e) {
|
|
1407
|
-
let t =
|
|
1413
|
+
let t = U(e, this.blue);
|
|
1408
1414
|
const n = {
|
|
1409
|
-
payload: Ke()
|
|
1415
|
+
payload: Ke(this.blue)
|
|
1410
1416
|
}, o = [n.payload];
|
|
1411
1417
|
await this.router.route(t, [], n, 0);
|
|
1412
|
-
const
|
|
1413
|
-
return t =
|
|
1418
|
+
const r = await this.drainQueue(t);
|
|
1419
|
+
return t = r.state, o.push(...r.emitted), t = je(t, this.blue), { state: t, emitted: o };
|
|
1414
1420
|
}
|
|
1415
1421
|
/**
|
|
1416
1422
|
* Processes a batch of events against the document
|
|
@@ -1420,18 +1426,18 @@ class lt {
|
|
|
1420
1426
|
* @returns Processing result with final state and emitted events
|
|
1421
1427
|
*/
|
|
1422
1428
|
async processEvents(e, t) {
|
|
1423
|
-
let n =
|
|
1429
|
+
let n = U(e, this.blue);
|
|
1424
1430
|
const o = [];
|
|
1425
|
-
if (!
|
|
1431
|
+
if (!ne(n, this.blue))
|
|
1426
1432
|
throw new Error("Document is not initialized");
|
|
1427
|
-
for (const
|
|
1433
|
+
for (const r of t)
|
|
1428
1434
|
try {
|
|
1429
|
-
const
|
|
1430
|
-
await this.router.route(n, [],
|
|
1435
|
+
const a = { payload: r, source: "external" };
|
|
1436
|
+
await this.router.route(n, [], a, 0);
|
|
1431
1437
|
const s = await this.drainQueue(n);
|
|
1432
1438
|
n = s.state, o.push(...s.emitted);
|
|
1433
1439
|
const i = this.checkpointCache.flush(n);
|
|
1434
|
-
i.length && (n =
|
|
1440
|
+
i.length && (n = L(n, i));
|
|
1435
1441
|
} finally {
|
|
1436
1442
|
this.checkpointCache.clear();
|
|
1437
1443
|
}
|
|
@@ -1441,68 +1447,68 @@ class lt {
|
|
|
1441
1447
|
* Drains the task queue and applies all actions
|
|
1442
1448
|
*/
|
|
1443
1449
|
async drainQueue(e) {
|
|
1444
|
-
var
|
|
1450
|
+
var a;
|
|
1445
1451
|
let t = e;
|
|
1446
1452
|
const n = [], o = 1e4;
|
|
1447
|
-
let
|
|
1453
|
+
let r = 0;
|
|
1448
1454
|
for (; this.queue.length; ) {
|
|
1449
|
-
if (++
|
|
1455
|
+
if (++r > o)
|
|
1450
1456
|
throw new Error("Possible cycle – too many iterations");
|
|
1451
1457
|
const s = this.queue.pop(), { nodePath: i, contractName: u, contractNode: h, event: d } = s, p = t.get(i);
|
|
1452
|
-
if (!
|
|
1453
|
-
const
|
|
1454
|
-
if (!
|
|
1458
|
+
if (!S(p) || !((a = p.getContracts()) != null && a[u]) || !h.getType()) continue;
|
|
1459
|
+
const y = this.registry.get(h.getType());
|
|
1460
|
+
if (!y) {
|
|
1455
1461
|
console.warn(`No processor registered for contract: ${u}`);
|
|
1456
1462
|
continue;
|
|
1457
1463
|
}
|
|
1458
|
-
const
|
|
1464
|
+
const w = new G(
|
|
1459
1465
|
() => t,
|
|
1460
1466
|
s,
|
|
1461
1467
|
this.blue,
|
|
1462
1468
|
async (b) => {
|
|
1463
1469
|
for (const g of b)
|
|
1464
1470
|
if (g.kind === "patch") {
|
|
1465
|
-
const ae =
|
|
1471
|
+
const ae = W(t, this.blue);
|
|
1466
1472
|
for (const C of ae) {
|
|
1467
|
-
const
|
|
1468
|
-
(
|
|
1469
|
-
),
|
|
1473
|
+
const se = g.patch.op === "move" || g.patch.op === "copy" ? [g.patch.from, g.patch.path] : [g.patch.path], j = w.getNodePath(), ce = se.some(
|
|
1474
|
+
(le) => F(le, C.absPath)
|
|
1475
|
+
), ie = F(
|
|
1470
1476
|
j,
|
|
1471
1477
|
C.absPath
|
|
1472
1478
|
);
|
|
1473
|
-
if (
|
|
1474
|
-
throw new
|
|
1479
|
+
if (ce && !ie)
|
|
1480
|
+
throw new te(
|
|
1475
1481
|
g.patch,
|
|
1476
1482
|
C.absPath,
|
|
1477
1483
|
j
|
|
1478
1484
|
);
|
|
1479
1485
|
}
|
|
1480
1486
|
try {
|
|
1481
|
-
t =
|
|
1487
|
+
t = L(t, [g.patch]);
|
|
1482
1488
|
} catch (C) {
|
|
1483
|
-
throw
|
|
1489
|
+
throw We(u, d, C), C;
|
|
1484
1490
|
}
|
|
1485
1491
|
} else g.kind === "event" && (n.push(g.event.payload), await this.router.route(t, [], g.event, s.key[5]));
|
|
1486
1492
|
}
|
|
1487
1493
|
);
|
|
1488
|
-
await
|
|
1494
|
+
await y.handle(d, h, w, u), await w.flush();
|
|
1489
1495
|
}
|
|
1490
1496
|
return { state: t, emitted: n };
|
|
1491
1497
|
}
|
|
1492
1498
|
}
|
|
1493
1499
|
export {
|
|
1494
|
-
|
|
1500
|
+
ut as BlueDocumentProcessor,
|
|
1495
1501
|
xe as ChannelEventCheckpointProcessor,
|
|
1496
1502
|
Ve as CompositeTimelineChannelProcessor,
|
|
1497
1503
|
Fe as DocumentUpdateChannelProcessor,
|
|
1498
|
-
|
|
1499
|
-
|
|
1500
|
-
|
|
1504
|
+
Le as EmbeddedNodeChannelProcessor,
|
|
1505
|
+
Ue as InitializedMarkerProcessor,
|
|
1506
|
+
_e as LifecycleEventChannelProcessor,
|
|
1501
1507
|
He as MyOSAgentChannelProcessor,
|
|
1502
1508
|
ze as MyOSTimelineChannelProcessor,
|
|
1503
1509
|
Re as OperationProcessor,
|
|
1504
1510
|
Qe as ProcessEmbeddedProcessor,
|
|
1505
|
-
|
|
1506
|
-
|
|
1507
|
-
|
|
1511
|
+
tt as SequentialWorkflowOperationProcessor,
|
|
1512
|
+
re as SequentialWorkflowProcessor,
|
|
1513
|
+
nt as TimelineChannelProcessor
|
|
1508
1514
|
};
|