@rotorsoft/act-diagram 1.2.4 → 1.4.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.cjs CHANGED
@@ -349,12 +349,16 @@ function build_state(model, st) {
349
349
  const emits = raw_actions[`__emits_${action_name}`] ?? [];
350
350
  const describe = (rule) => rule.description ?? "";
351
351
  const invariants = (st.given?.[action_name] ?? []).map(describe);
352
- const preconditions = (st.requires?.[action_name] ?? []).map(describe);
352
+ const preconditions = [
353
+ ...invariants,
354
+ ...(st.requires?.[action_name] ?? []).map(describe)
355
+ ];
353
356
  action_nodes.push({
354
357
  name: action_name,
355
358
  emits,
356
359
  invariants,
357
- ...preconditions.length ? { preconditions } : {}
360
+ ...preconditions.length ? { preconditions } : {},
361
+ zod: raw_actions[action_name]
358
362
  });
359
363
  }
360
364
  const node = {
@@ -362,7 +366,8 @@ function build_state(model, st) {
362
366
  varName: unique_key,
363
367
  events: event_nodes,
364
368
  actions: action_nodes,
365
- file: st._sourceFile
369
+ file: st._sourceFile,
370
+ zod: st.schema
366
371
  };
367
372
  model.states.push(node);
368
373
  st._modelKey = unique_key;
@@ -666,6 +671,7 @@ function mock_state(entry, on_build) {
666
671
  const name = Object.keys(entry)[0];
667
672
  const info = {
668
673
  name,
674
+ schema: entry[name],
669
675
  events: {},
670
676
  actions: {},
671
677
  given: {},
@@ -933,6 +939,12 @@ var InvariantError = class extends Error {
933
939
  this.name = "InvariantError";
934
940
  }
935
941
  };
942
+ var PreconditionError = class extends InvariantError {
943
+ constructor(message) {
944
+ super(message);
945
+ this.name = "PreconditionError";
946
+ }
947
+ };
936
948
  var crypto_mock = { randomUUID: () => "mock-uuid" };
937
949
  var MODULES = {
938
950
  "@rotorsoft/act": {
@@ -949,7 +961,8 @@ var MODULES = {
949
961
  }),
950
962
  dispose: () => () => Promise.resolve(),
951
963
  ZodEmpty: import_zod.z.record(import_zod.z.string(), import_zod.z.never()),
952
- InvariantError
964
+ InvariantError,
965
+ PreconditionError
953
966
  },
954
967
  zod: { z: import_zod.z, ...import_zod.z },
955
968
  crypto: crypto_mock,
@@ -1374,7 +1387,7 @@ function navigate_to_code(files, name, type, target_file) {
1374
1387
  const desc_match = desc_re.exec(c);
1375
1388
  if (desc_match) {
1376
1389
  const before = c.slice(0, desc_match.index);
1377
- const decl_re = /(?:export\s+)?(?:const|let|var)\s+(\w+)\s*(?::\s*Invariant[^=]*)?\s*=/g;
1390
+ const decl_re = /(?:export\s+)?(?:const|let|var)\s+(\w+)\s*(?::\s*(?:Invariant|Precondition)[^=]*)?\s*=/g;
1378
1391
  let last_decl = null;
1379
1392
  let m;
1380
1393
  while ((m = decl_re.exec(before)) !== null) {
@@ -1423,7 +1436,7 @@ function navigate_to_code(files, name, type, target_file) {
1423
1436
  const desc_match = desc_re.exec(c);
1424
1437
  if (desc_match) {
1425
1438
  const before = c.slice(0, desc_match.index);
1426
- const decl_re = /(?:export\s+)?(?:const|let|var)\s+(\w+)\s*(?::\s*Invariant[^=]*)?\s*=/g;
1439
+ const decl_re = /(?:export\s+)?(?:const|let|var)\s+(\w+)\s*(?::\s*(?:Invariant|Precondition)[^=]*)?\s*=/g;
1427
1440
  let last_decl = null;
1428
1441
  let m;
1429
1442
  while ((m = decl_re.exec(before)) !== null) last_decl = m;
@@ -1556,7 +1569,7 @@ var import_react2 = require("react");
1556
1569
 
1557
1570
  // src/client/lib/layout.ts
1558
1571
  function rules_of(action) {
1559
- const rules = [...action.invariants, ...action.preconditions ?? []];
1572
+ const rules = action.preconditions ?? action.invariants;
1560
1573
  return rules.length ? rules : void 0;
1561
1574
  }
1562
1575
  var W = 100;
@@ -2223,11 +2236,9 @@ function formatModelTree(model) {
2223
2236
  if (!st) continue;
2224
2237
  lines.push(` State: ${st.name}`);
2225
2238
  for (const a of st.actions) {
2239
+ const rules = a.preconditions ?? a.invariants;
2226
2240
  let line = ` ${a.name} \u2192 [${a.emits.join(", ")}]`;
2227
- if (a.invariants.length)
2228
- line += ` guards: [${a.invariants.join(", ")}]`;
2229
- if (a.preconditions?.length)
2230
- line += ` requires: [${a.preconditions.join(", ")}]`;
2241
+ if (rules.length) line += ` preconditions: [${rules.join(", ")}]`;
2231
2242
  lines.push(line);
2232
2243
  }
2233
2244
  }
@@ -2478,7 +2489,7 @@ function Diagram({
2478
2489
  title: "@rotorsoft/act-diagram version",
2479
2490
  children: [
2480
2491
  "v",
2481
- "1.2.3"
2492
+ "1.3.0"
2482
2493
  ]
2483
2494
  }
2484
2495
  )