@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.js CHANGED
@@ -310,12 +310,16 @@ 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,
317
320
  invariants,
318
- ...preconditions.length ? { preconditions } : {}
321
+ ...preconditions.length ? { preconditions } : {},
322
+ zod: raw_actions[action_name]
319
323
  });
320
324
  }
321
325
  const node = {
@@ -323,7 +327,8 @@ function build_state(model, st) {
323
327
  varName: unique_key,
324
328
  events: event_nodes,
325
329
  actions: action_nodes,
326
- file: st._sourceFile
330
+ file: st._sourceFile,
331
+ zod: st.schema
327
332
  };
328
333
  model.states.push(node);
329
334
  st._modelKey = unique_key;
@@ -627,6 +632,7 @@ function mock_state(entry, on_build) {
627
632
  const name = Object.keys(entry)[0];
628
633
  const info = {
629
634
  name,
635
+ schema: entry[name],
630
636
  events: {},
631
637
  actions: {},
632
638
  given: {},
@@ -894,6 +900,12 @@ var InvariantError = class extends Error {
894
900
  this.name = "InvariantError";
895
901
  }
896
902
  };
903
+ var PreconditionError = class extends InvariantError {
904
+ constructor(message) {
905
+ super(message);
906
+ this.name = "PreconditionError";
907
+ }
908
+ };
897
909
  var crypto_mock = { randomUUID: () => "mock-uuid" };
898
910
  var MODULES = {
899
911
  "@rotorsoft/act": {
@@ -910,7 +922,8 @@ var MODULES = {
910
922
  }),
911
923
  dispose: () => () => Promise.resolve(),
912
924
  ZodEmpty: z.record(z.string(), z.never()),
913
- InvariantError
925
+ InvariantError,
926
+ PreconditionError
914
927
  },
915
928
  zod: { z, ...z },
916
929
  crypto: crypto_mock,
@@ -1335,7 +1348,7 @@ function navigate_to_code(files, name, type, target_file) {
1335
1348
  const desc_match = desc_re.exec(c);
1336
1349
  if (desc_match) {
1337
1350
  const before = c.slice(0, desc_match.index);
1338
- const decl_re = /(?:export\s+)?(?:const|let|var)\s+(\w+)\s*(?::\s*Invariant[^=]*)?\s*=/g;
1351
+ const decl_re = /(?:export\s+)?(?:const|let|var)\s+(\w+)\s*(?::\s*(?:Invariant|Precondition)[^=]*)?\s*=/g;
1339
1352
  let last_decl = null;
1340
1353
  let m;
1341
1354
  while ((m = decl_re.exec(before)) !== null) {
@@ -1384,7 +1397,7 @@ function navigate_to_code(files, name, type, target_file) {
1384
1397
  const desc_match = desc_re.exec(c);
1385
1398
  if (desc_match) {
1386
1399
  const before = c.slice(0, desc_match.index);
1387
- const decl_re = /(?:export\s+)?(?:const|let|var)\s+(\w+)\s*(?::\s*Invariant[^=]*)?\s*=/g;
1400
+ const decl_re = /(?:export\s+)?(?:const|let|var)\s+(\w+)\s*(?::\s*(?:Invariant|Precondition)[^=]*)?\s*=/g;
1388
1401
  let last_decl = null;
1389
1402
  let m;
1390
1403
  while ((m = decl_re.exec(before)) !== null) last_decl = m;
@@ -1525,7 +1538,7 @@ import { useCallback, useEffect, useMemo, useRef, useState as useState2 } from "
1525
1538
 
1526
1539
  // src/client/lib/layout.ts
1527
1540
  function rules_of(action) {
1528
- const rules = [...action.invariants, ...action.preconditions ?? []];
1541
+ const rules = action.preconditions ?? action.invariants;
1529
1542
  return rules.length ? rules : void 0;
1530
1543
  }
1531
1544
  var W = 100;
@@ -2192,11 +2205,9 @@ function formatModelTree(model) {
2192
2205
  if (!st) continue;
2193
2206
  lines.push(` State: ${st.name}`);
2194
2207
  for (const a of st.actions) {
2208
+ const rules = a.preconditions ?? a.invariants;
2195
2209
  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(", ")}]`;
2210
+ if (rules.length) line += ` preconditions: [${rules.join(", ")}]`;
2200
2211
  lines.push(line);
2201
2212
  }
2202
2213
  }
@@ -2447,7 +2458,7 @@ function Diagram({
2447
2458
  title: "@rotorsoft/act-diagram version",
2448
2459
  children: [
2449
2460
  "v",
2450
- "1.2.3"
2461
+ "1.3.0"
2451
2462
  ]
2452
2463
  }
2453
2464
  )