@rotorsoft/act-diagram 1.2.4 → 1.3.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 CHANGED
@@ -310,7 +310,10 @@ function build_state(model, st) {
310
310
  const emits = raw_actions[`__emits_${action_name}`] ?? [];
311
311
  const describe = (rule) => rule.description ?? "";
312
312
  const invariants = (st.given?.[action_name] ?? []).map(describe);
313
- const preconditions = (st.requires?.[action_name] ?? []).map(describe);
313
+ const preconditions = [
314
+ ...invariants,
315
+ ...(st.requires?.[action_name] ?? []).map(describe)
316
+ ];
314
317
  action_nodes.push({
315
318
  name: action_name,
316
319
  emits,
@@ -894,6 +897,12 @@ var InvariantError = class extends Error {
894
897
  this.name = "InvariantError";
895
898
  }
896
899
  };
900
+ var PreconditionError = class extends InvariantError {
901
+ constructor(message) {
902
+ super(message);
903
+ this.name = "PreconditionError";
904
+ }
905
+ };
897
906
  var crypto_mock = { randomUUID: () => "mock-uuid" };
898
907
  var MODULES = {
899
908
  "@rotorsoft/act": {
@@ -910,7 +919,8 @@ var MODULES = {
910
919
  }),
911
920
  dispose: () => () => Promise.resolve(),
912
921
  ZodEmpty: z.record(z.string(), z.never()),
913
- InvariantError
922
+ InvariantError,
923
+ PreconditionError
914
924
  },
915
925
  zod: { z, ...z },
916
926
  crypto: crypto_mock,
@@ -1335,7 +1345,7 @@ function navigate_to_code(files, name, type, target_file) {
1335
1345
  const desc_match = desc_re.exec(c);
1336
1346
  if (desc_match) {
1337
1347
  const before = c.slice(0, desc_match.index);
1338
- const decl_re = /(?:export\s+)?(?:const|let|var)\s+(\w+)\s*(?::\s*Invariant[^=]*)?\s*=/g;
1348
+ const decl_re = /(?:export\s+)?(?:const|let|var)\s+(\w+)\s*(?::\s*(?:Invariant|Precondition)[^=]*)?\s*=/g;
1339
1349
  let last_decl = null;
1340
1350
  let m;
1341
1351
  while ((m = decl_re.exec(before)) !== null) {
@@ -1384,7 +1394,7 @@ function navigate_to_code(files, name, type, target_file) {
1384
1394
  const desc_match = desc_re.exec(c);
1385
1395
  if (desc_match) {
1386
1396
  const before = c.slice(0, desc_match.index);
1387
- const decl_re = /(?:export\s+)?(?:const|let|var)\s+(\w+)\s*(?::\s*Invariant[^=]*)?\s*=/g;
1397
+ const decl_re = /(?:export\s+)?(?:const|let|var)\s+(\w+)\s*(?::\s*(?:Invariant|Precondition)[^=]*)?\s*=/g;
1388
1398
  let last_decl = null;
1389
1399
  let m;
1390
1400
  while ((m = decl_re.exec(before)) !== null) last_decl = m;
@@ -1525,7 +1535,7 @@ import { useCallback, useEffect, useMemo, useRef, useState as useState2 } from "
1525
1535
 
1526
1536
  // src/client/lib/layout.ts
1527
1537
  function rules_of(action) {
1528
- const rules = [...action.invariants, ...action.preconditions ?? []];
1538
+ const rules = action.preconditions ?? action.invariants;
1529
1539
  return rules.length ? rules : void 0;
1530
1540
  }
1531
1541
  var W = 100;
@@ -2192,11 +2202,9 @@ function formatModelTree(model) {
2192
2202
  if (!st) continue;
2193
2203
  lines.push(` State: ${st.name}`);
2194
2204
  for (const a of st.actions) {
2205
+ const rules = a.preconditions ?? a.invariants;
2195
2206
  let line = ` ${a.name} \u2192 [${a.emits.join(", ")}]`;
2196
- if (a.invariants.length)
2197
- line += ` guards: [${a.invariants.join(", ")}]`;
2198
- if (a.preconditions?.length)
2199
- line += ` requires: [${a.preconditions.join(", ")}]`;
2207
+ if (rules.length) line += ` preconditions: [${rules.join(", ")}]`;
2200
2208
  lines.push(line);
2201
2209
  }
2202
2210
  }
@@ -2447,7 +2455,7 @@ function Diagram({
2447
2455
  title: "@rotorsoft/act-diagram version",
2448
2456
  children: [
2449
2457
  "v",
2450
- "1.2.3"
2458
+ "1.2.4"
2451
2459
  ]
2452
2460
  }
2453
2461
  )