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