@mmmnt/cli 0.9.0 → 0.10.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/moment.mjs +257 -5
- package/dist/moment.mjs.map +3 -3
- package/package.json +9 -9
package/dist/moment.mjs
CHANGED
|
@@ -55439,6 +55439,9 @@ var PolicyDeclaration = {
|
|
|
55439
55439
|
$type: "PolicyDeclaration",
|
|
55440
55440
|
action: "action",
|
|
55441
55441
|
chainsTo: "chainsTo",
|
|
55442
|
+
conditionAfter: "conditionAfter",
|
|
55443
|
+
conditionField: "conditionField",
|
|
55444
|
+
conditionValue: "conditionValue",
|
|
55442
55445
|
gateways: "gateways",
|
|
55443
55446
|
name: "name",
|
|
55444
55447
|
trigger: "trigger"
|
|
@@ -56130,6 +56133,18 @@ var MomentAstReflection = class extends AbstractAstReflection {
|
|
|
56130
56133
|
chainsTo: {
|
|
56131
56134
|
name: PolicyDeclaration.chainsTo
|
|
56132
56135
|
},
|
|
56136
|
+
conditionAfter: {
|
|
56137
|
+
name: PolicyDeclaration.conditionAfter,
|
|
56138
|
+
optional: true
|
|
56139
|
+
},
|
|
56140
|
+
conditionField: {
|
|
56141
|
+
name: PolicyDeclaration.conditionField,
|
|
56142
|
+
optional: true
|
|
56143
|
+
},
|
|
56144
|
+
conditionValue: {
|
|
56145
|
+
name: PolicyDeclaration.conditionValue,
|
|
56146
|
+
optional: true
|
|
56147
|
+
},
|
|
56133
56148
|
gateways: {
|
|
56134
56149
|
name: PolicyDeclaration.gateways,
|
|
56135
56150
|
defaultValue: [],
|
|
@@ -58059,6 +58074,66 @@ var MomentGrammar = () => loadedMomentGrammar ?? (loadedMomentGrammar = loadGram
|
|
|
58059
58074
|
"arguments": []
|
|
58060
58075
|
}
|
|
58061
58076
|
},
|
|
58077
|
+
{
|
|
58078
|
+
"$type": "Group",
|
|
58079
|
+
"elements": [
|
|
58080
|
+
{
|
|
58081
|
+
"$type": "Keyword",
|
|
58082
|
+
"value": "when"
|
|
58083
|
+
},
|
|
58084
|
+
{
|
|
58085
|
+
"$type": "Assignment",
|
|
58086
|
+
"feature": "conditionField",
|
|
58087
|
+
"operator": "=",
|
|
58088
|
+
"terminal": {
|
|
58089
|
+
"$type": "RuleCall",
|
|
58090
|
+
"rule": {
|
|
58091
|
+
"$ref": "#/rules@50"
|
|
58092
|
+
},
|
|
58093
|
+
"arguments": []
|
|
58094
|
+
}
|
|
58095
|
+
},
|
|
58096
|
+
{
|
|
58097
|
+
"$type": "Keyword",
|
|
58098
|
+
"value": "="
|
|
58099
|
+
},
|
|
58100
|
+
{
|
|
58101
|
+
"$type": "Assignment",
|
|
58102
|
+
"feature": "conditionValue",
|
|
58103
|
+
"operator": "=",
|
|
58104
|
+
"terminal": {
|
|
58105
|
+
"$type": "RuleCall",
|
|
58106
|
+
"rule": {
|
|
58107
|
+
"$ref": "#/rules@10"
|
|
58108
|
+
},
|
|
58109
|
+
"arguments": []
|
|
58110
|
+
}
|
|
58111
|
+
}
|
|
58112
|
+
],
|
|
58113
|
+
"cardinality": "?"
|
|
58114
|
+
},
|
|
58115
|
+
{
|
|
58116
|
+
"$type": "Group",
|
|
58117
|
+
"elements": [
|
|
58118
|
+
{
|
|
58119
|
+
"$type": "Keyword",
|
|
58120
|
+
"value": "after"
|
|
58121
|
+
},
|
|
58122
|
+
{
|
|
58123
|
+
"$type": "Assignment",
|
|
58124
|
+
"feature": "conditionAfter",
|
|
58125
|
+
"operator": "=",
|
|
58126
|
+
"terminal": {
|
|
58127
|
+
"$type": "RuleCall",
|
|
58128
|
+
"rule": {
|
|
58129
|
+
"$ref": "#/rules@56"
|
|
58130
|
+
},
|
|
58131
|
+
"arguments": []
|
|
58132
|
+
}
|
|
58133
|
+
}
|
|
58134
|
+
],
|
|
58135
|
+
"cardinality": "?"
|
|
58136
|
+
},
|
|
58062
58137
|
{
|
|
58063
58138
|
"$type": "Keyword",
|
|
58064
58139
|
"value": "action"
|
|
@@ -59222,6 +59297,10 @@ var MomentGrammar = () => loadedMomentGrammar ?? (loadedMomentGrammar = loadGram
|
|
|
59222
59297
|
{
|
|
59223
59298
|
"$type": "Keyword",
|
|
59224
59299
|
"value": "outcome"
|
|
59300
|
+
},
|
|
59301
|
+
{
|
|
59302
|
+
"$type": "Keyword",
|
|
59303
|
+
"value": "after"
|
|
59225
59304
|
}
|
|
59226
59305
|
]
|
|
59227
59306
|
},
|
|
@@ -59777,6 +59856,10 @@ var MomentGrammar = () => loadedMomentGrammar ?? (loadedMomentGrammar = loadGram
|
|
|
59777
59856
|
{
|
|
59778
59857
|
"$type": "Keyword",
|
|
59779
59858
|
"value": "outcome"
|
|
59859
|
+
},
|
|
59860
|
+
{
|
|
59861
|
+
"$type": "Keyword",
|
|
59862
|
+
"value": "after"
|
|
59780
59863
|
}
|
|
59781
59864
|
]
|
|
59782
59865
|
},
|
|
@@ -61061,6 +61144,76 @@ function validateMultiEvent(ir, options = {}) {
|
|
|
61061
61144
|
];
|
|
61062
61145
|
}
|
|
61063
61146
|
|
|
61147
|
+
// ../core/dist/validation/policy-condition.js
|
|
61148
|
+
function placedOrder(flow) {
|
|
61149
|
+
return flow.moments.flatMap((m) => [
|
|
61150
|
+
...m.contextEntries.map((e) => e.nodeName),
|
|
61151
|
+
...(m.branches ?? []).flatMap((b) => b.entries.map((e) => e.nodeName))
|
|
61152
|
+
]);
|
|
61153
|
+
}
|
|
61154
|
+
function someFlowPlacesBefore(flows, cause, trigger) {
|
|
61155
|
+
let triggerPlaced = false;
|
|
61156
|
+
for (const flow of flows) {
|
|
61157
|
+
const order = placedOrder(flow);
|
|
61158
|
+
const firstCause = order.indexOf(cause);
|
|
61159
|
+
const lastTrigger = order.lastIndexOf(trigger);
|
|
61160
|
+
if (lastTrigger >= 0)
|
|
61161
|
+
triggerPlaced = true;
|
|
61162
|
+
if (firstCause >= 0 && lastTrigger > firstCause)
|
|
61163
|
+
return { reached: true, triggerPlaced };
|
|
61164
|
+
}
|
|
61165
|
+
return { reached: false, triggerPlaced };
|
|
61166
|
+
}
|
|
61167
|
+
function fieldsByEvent(ir) {
|
|
61168
|
+
const events = /* @__PURE__ */ new Map();
|
|
61169
|
+
for (const ctx of ir.contexts)
|
|
61170
|
+
for (const e of ctx.events) {
|
|
61171
|
+
const fields = events.get(e.name) ?? /* @__PURE__ */ new Set();
|
|
61172
|
+
for (const f of e.fields ?? [])
|
|
61173
|
+
fields.add(f.name);
|
|
61174
|
+
events.set(e.name, fields);
|
|
61175
|
+
}
|
|
61176
|
+
return events;
|
|
61177
|
+
}
|
|
61178
|
+
function v49(p, events) {
|
|
61179
|
+
const c = p.condition;
|
|
61180
|
+
const fields = events.get(p.trigger);
|
|
61181
|
+
if (c?.field === void 0 || fields === void 0 || fields.has(c.field))
|
|
61182
|
+
return [];
|
|
61183
|
+
return [
|
|
61184
|
+
{
|
|
61185
|
+
ruleId: "V49",
|
|
61186
|
+
message: `Policy '${p.name}' reacts when '${c.field}' of '${p.trigger}' is '${c.equals ?? ""}', but '${p.trigger}' has no field '${c.field}'.`
|
|
61187
|
+
}
|
|
61188
|
+
];
|
|
61189
|
+
}
|
|
61190
|
+
function v50v51(p, events, flows) {
|
|
61191
|
+
const after = p.condition?.after;
|
|
61192
|
+
if (after === void 0)
|
|
61193
|
+
return [];
|
|
61194
|
+
if (!events.has(after))
|
|
61195
|
+
return [
|
|
61196
|
+
{
|
|
61197
|
+
ruleId: "V50",
|
|
61198
|
+
message: `Policy '${p.name}' reacts after '${after}', which is no declared event.`
|
|
61199
|
+
}
|
|
61200
|
+
];
|
|
61201
|
+
const { reached, triggerPlaced } = someFlowPlacesBefore(flows, after, p.trigger);
|
|
61202
|
+
if (!triggerPlaced || reached)
|
|
61203
|
+
return [];
|
|
61204
|
+
return [
|
|
61205
|
+
{
|
|
61206
|
+
ruleId: "V51",
|
|
61207
|
+
severity: "warning",
|
|
61208
|
+
message: `Policy '${p.name}' reacts to '${p.trigger}' after '${after}', but no flow places '${after}' before '${p.trigger}'; the condition is never met.`
|
|
61209
|
+
}
|
|
61210
|
+
];
|
|
61211
|
+
}
|
|
61212
|
+
function validatePolicyConditions(ir) {
|
|
61213
|
+
const events = fieldsByEvent(ir);
|
|
61214
|
+
return ir.contexts.flatMap((ctx) => ctx.policies.filter((p) => p.condition !== void 0).flatMap((p) => [...v49(p, events), ...v50v51(p, events, ir.flows ?? [])]));
|
|
61215
|
+
}
|
|
61216
|
+
|
|
61064
61217
|
// ../core/dist/validation/palette-conformance.js
|
|
61065
61218
|
function namesOf2(ir) {
|
|
61066
61219
|
const contexts = ir.contexts;
|
|
@@ -61314,6 +61467,7 @@ function validatePaletteConformance(ir, options = {}) {
|
|
|
61314
61467
|
...v41v42Placements(ir, commands),
|
|
61315
61468
|
...v43(ir),
|
|
61316
61469
|
...validateMultiEvent(ir, options),
|
|
61470
|
+
...validatePolicyConditions(ir),
|
|
61317
61471
|
...(ir.externals ?? []).flatMap((e) => gatewayFindings(`external '${e.name}'`, e.gateways ?? [], known))
|
|
61318
61472
|
];
|
|
61319
61473
|
}
|
|
@@ -61623,6 +61777,12 @@ function transformPolicy(pol, annotations) {
|
|
|
61623
61777
|
trigger: pol.trigger,
|
|
61624
61778
|
action: pol.action,
|
|
61625
61779
|
chainsTo: pol.chainsTo,
|
|
61780
|
+
...pol.conditionField !== void 0 || pol.conditionAfter !== void 0 ? {
|
|
61781
|
+
condition: {
|
|
61782
|
+
...pol.conditionField !== void 0 ? { field: pol.conditionField, equals: pol.conditionValue } : {},
|
|
61783
|
+
...pol.conditionAfter !== void 0 ? { after: pol.conditionAfter } : {}
|
|
61784
|
+
}
|
|
61785
|
+
} : {},
|
|
61626
61786
|
...gatewaysOf(pol.gateways)
|
|
61627
61787
|
};
|
|
61628
61788
|
}
|
|
@@ -64850,6 +65010,7 @@ function multiEventPlacements(steps, commandOf) {
|
|
|
64850
65010
|
}
|
|
64851
65011
|
|
|
64852
65012
|
// ../derive/dist/engine/simulation-scenario-generator.js
|
|
65013
|
+
var BRANCH_KEY = "$branch";
|
|
64853
65014
|
function resolveNodeKind(nodeName, contextId, contextMap, declaredKind) {
|
|
64854
65015
|
const ctx = contextMap.get(contextId);
|
|
64855
65016
|
if (!ctx)
|
|
@@ -65118,6 +65279,7 @@ function generateEvents(nodes, flow, contextMap, sessionId, correlationId, baseT
|
|
|
65118
65279
|
const eventIds = nodes.map((_, i) => `evt-${String(i + 1).padStart(3, "0")}`);
|
|
65119
65280
|
const placements2 = placementsOf(nodes, contextMap);
|
|
65120
65281
|
const commandOfEvent = new Map(placements2.flatMap((p) => p.events.map((k) => [k, p.command])));
|
|
65282
|
+
const conditioned = policyConditionedOccurrences(nodes, flow, contextMap);
|
|
65121
65283
|
for (let i = 0; i < nodes.length; i++) {
|
|
65122
65284
|
const node = nodes[i];
|
|
65123
65285
|
const recordedBy = commandOfEvent.get(i);
|
|
@@ -65127,6 +65289,7 @@ function generateEvents(nodes, flow, contextMap, sessionId, correlationId, baseT
|
|
|
65127
65289
|
const eventType = resolveEventType(node, effectiveKind);
|
|
65128
65290
|
const productSource = resolveProductSource(node, effectiveKind, contextMap);
|
|
65129
65291
|
const payload = buildPayload(node, effectiveKind, contextMap, flow);
|
|
65292
|
+
applyPolicyConditions(payload, i, node, conditioned, contextMap);
|
|
65130
65293
|
const whenState = placements2.find((p) => p.command === i)?.whenState;
|
|
65131
65294
|
if (whenState !== void 0)
|
|
65132
65295
|
payload.whenState = whenState;
|
|
@@ -65144,6 +65307,89 @@ function generateEvents(nodes, flow, contextMap, sessionId, correlationId, baseT
|
|
|
65144
65307
|
}
|
|
65145
65308
|
return events;
|
|
65146
65309
|
}
|
|
65310
|
+
function guardedPolicies(contextMap) {
|
|
65311
|
+
const byTrigger = /* @__PURE__ */ new Map();
|
|
65312
|
+
for (const ctx of contextMap.values())
|
|
65313
|
+
for (const policy of ctx.policies) {
|
|
65314
|
+
if (policy.condition?.field === void 0)
|
|
65315
|
+
continue;
|
|
65316
|
+
byTrigger.set(policy.trigger, [...byTrigger.get(policy.trigger) ?? [], policy]);
|
|
65317
|
+
}
|
|
65318
|
+
return byTrigger;
|
|
65319
|
+
}
|
|
65320
|
+
function policyConditionedOccurrences(nodes, flow, contextMap) {
|
|
65321
|
+
const guarded = guardedPolicies(contextMap);
|
|
65322
|
+
const named = /* @__PURE__ */ new Map();
|
|
65323
|
+
if (guarded.size === 0)
|
|
65324
|
+
return named;
|
|
65325
|
+
nodes.forEach((node, index) => {
|
|
65326
|
+
for (const conn of flow.connections) {
|
|
65327
|
+
if (!isCausationConnectionFor(conn, node))
|
|
65328
|
+
continue;
|
|
65329
|
+
const triggerName = conn.sourceNodeName ?? conn.eventId.replace(/^evt-/, "");
|
|
65330
|
+
const policies = (guarded.get(triggerName) ?? []).filter((p) => p.chainsTo === node.nodeName);
|
|
65331
|
+
if (policies.length === 0)
|
|
65332
|
+
continue;
|
|
65333
|
+
for (let j = index - 1; j >= 0; j--) {
|
|
65334
|
+
if (nodes[j].nodeName !== triggerName)
|
|
65335
|
+
continue;
|
|
65336
|
+
named.set(j, [...named.get(j) ?? [], ...policies]);
|
|
65337
|
+
break;
|
|
65338
|
+
}
|
|
65339
|
+
}
|
|
65340
|
+
});
|
|
65341
|
+
return named;
|
|
65342
|
+
}
|
|
65343
|
+
function typedValue(type, value) {
|
|
65344
|
+
if (type === "number" && value.trim() !== "" && !Number.isNaN(Number(value)))
|
|
65345
|
+
return Number(value);
|
|
65346
|
+
if (type === "boolean" && (value === "true" || value === "false"))
|
|
65347
|
+
return value === "true";
|
|
65348
|
+
return value;
|
|
65349
|
+
}
|
|
65350
|
+
function otherThan(value) {
|
|
65351
|
+
if (typeof value === "number")
|
|
65352
|
+
return value + 1;
|
|
65353
|
+
if (typeof value === "boolean")
|
|
65354
|
+
return !value;
|
|
65355
|
+
return `${String(value)}-other`;
|
|
65356
|
+
}
|
|
65357
|
+
function guardedField(policy, payload) {
|
|
65358
|
+
const field = policy.condition?.field;
|
|
65359
|
+
return field !== void 0 && field in payload ? field : void 0;
|
|
65360
|
+
}
|
|
65361
|
+
function declaredValue(evt, policy) {
|
|
65362
|
+
const field = policy.condition?.field ?? "";
|
|
65363
|
+
const type = evt.fields.find((f) => f.name === field)?.type ?? "";
|
|
65364
|
+
return typedValue(type, policy.condition?.equals ?? "");
|
|
65365
|
+
}
|
|
65366
|
+
function moveOffDeclared(payload, guarded, evt, fixed) {
|
|
65367
|
+
for (const policy of guarded) {
|
|
65368
|
+
const field = guardedField(policy, payload);
|
|
65369
|
+
if (field === void 0 || fixed.has(field))
|
|
65370
|
+
continue;
|
|
65371
|
+
const declared = declaredValue(evt, policy);
|
|
65372
|
+
if (payload[field] === declared)
|
|
65373
|
+
payload[field] = otherThan(declared);
|
|
65374
|
+
}
|
|
65375
|
+
}
|
|
65376
|
+
function applyPolicyConditions(payload, index, node, conditioned, contextMap) {
|
|
65377
|
+
const ctx = contextMap.get(node.contextId);
|
|
65378
|
+
const evt = ctx ? findEvent(ctx, node.nodeName) : void 0;
|
|
65379
|
+
if (!evt)
|
|
65380
|
+
return;
|
|
65381
|
+
const guarded = [...contextMap.values()].flatMap((c) => c.policies.filter((p) => p.trigger === node.nodeName && p.condition?.field !== void 0));
|
|
65382
|
+
const naming = conditioned.get(index) ?? [];
|
|
65383
|
+
const fixed = /* @__PURE__ */ new Set();
|
|
65384
|
+
for (const policy of guarded.filter((p) => naming.includes(p))) {
|
|
65385
|
+
const field = guardedField(policy, payload);
|
|
65386
|
+
if (field === void 0 || fixed.has(field))
|
|
65387
|
+
continue;
|
|
65388
|
+
payload[field] = declaredValue(evt, policy);
|
|
65389
|
+
fixed.add(field);
|
|
65390
|
+
}
|
|
65391
|
+
moveOffDeclared(payload, guarded, evt, fixed);
|
|
65392
|
+
}
|
|
65147
65393
|
function findCausationEvents(node, allNodes, flow, eventIds, currentIndex, recordedBy) {
|
|
65148
65394
|
const causation = [];
|
|
65149
65395
|
for (const conn of flow.connections) {
|
|
@@ -65220,11 +65466,16 @@ function buildPayload(node, effectiveKind, contextMap, flow) {
|
|
|
65220
65466
|
}
|
|
65221
65467
|
}
|
|
65222
65468
|
addContractFields(payload, node, flow);
|
|
65223
|
-
|
|
65224
|
-
payload.outcome = node.outcome;
|
|
65225
|
-
}
|
|
65469
|
+
stampBranch(payload, node);
|
|
65226
65470
|
return payload;
|
|
65227
65471
|
}
|
|
65472
|
+
function stampBranch(payload, node) {
|
|
65473
|
+
if (node.outcome === void 0)
|
|
65474
|
+
return;
|
|
65475
|
+
payload[BRANCH_KEY] = node.outcome;
|
|
65476
|
+
if (!("outcome" in payload))
|
|
65477
|
+
payload.outcome = node.outcome;
|
|
65478
|
+
}
|
|
65228
65479
|
function addContractFields(payload, node, flow) {
|
|
65229
65480
|
for (const conn of flow.connections) {
|
|
65230
65481
|
if (conn.connectionType !== "crosses-to")
|
|
@@ -65604,7 +65855,8 @@ function generatePolicyDefinitions(ir) {
|
|
|
65604
65855
|
contextId: context.id,
|
|
65605
65856
|
trigger: policy.trigger,
|
|
65606
65857
|
...policy.action ? { actionDescription: policy.action } : {},
|
|
65607
|
-
chainsTo: normalizeChainsTo(policy.chainsTo)
|
|
65858
|
+
chainsTo: normalizeChainsTo(policy.chainsTo),
|
|
65859
|
+
...policy.condition ? { condition: { ...policy.condition } } : {}
|
|
65608
65860
|
});
|
|
65609
65861
|
}
|
|
65610
65862
|
}
|
|
@@ -66418,7 +66670,7 @@ function buildBranchPredicates(flow) {
|
|
|
66418
66670
|
routes[branch.condition] = branch.condition;
|
|
66419
66671
|
}
|
|
66420
66672
|
predicates[moment.id] = {
|
|
66421
|
-
field:
|
|
66673
|
+
field: BRANCH_KEY,
|
|
66422
66674
|
defaultRoute: moment.branches[0].condition,
|
|
66423
66675
|
routes
|
|
66424
66676
|
};
|