libpetri 2.6.0 → 2.7.1

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.
@@ -1,6 +1,6 @@
1
1
  import { Writable } from 'node:stream';
2
- import { P as PetriNet, b as Transition, T as Token } from '../petri-net-C3asscb4.js';
3
- import { E as EventStore, N as NetEvent } from '../event-store-E_ahsEc9.js';
2
+ import { P as PetriNet, b as Transition, T as Token } from '../petri-net-D73-PO6d.js';
3
+ import { E as EventStore, N as NetEvent } from '../event-store-8XkpYUeU.js';
4
4
 
5
5
  /**
6
6
  * Commands sent from debug UI client to server via WebSocket.
@@ -1,5 +1,5 @@
1
1
  import { Application } from 'typedoc';
2
- import { P as PetriNet, S as SubnetDef, o as Instance } from '../petri-net-C3asscb4.js';
2
+ import { P as PetriNet, S as SubnetDef, o as Instance } from '../petri-net-D73-PO6d.js';
3
3
 
4
4
  /**
5
5
  * TypeDoc plugin for `@petrinet` and `@subnet` tags — auto-generates
@@ -1,4 +1,4 @@
1
- import { T as Token } from './petri-net-C3asscb4.js';
1
+ import { T as Token } from './petri-net-D73-PO6d.js';
2
2
 
3
3
  /**
4
4
  * Events emitted during Petri Net execution.
@@ -1,4 +1,4 @@
1
- import { P as PetriNet } from '../petri-net-C3asscb4.js';
1
+ import { P as PetriNet } from '../petri-net-D73-PO6d.js';
2
2
 
3
3
  /**
4
4
  * Format-agnostic typed graph model.
package/dist/index.d.ts CHANGED
@@ -1,7 +1,7 @@
1
- import { P as PetriNet, S as SubnetDef, a as Place, T as Token, b as Transition, E as EnvironmentPlace, c as TransitionContext, O as Out } from './petri-net-C3asscb4.js';
2
- export { A as Arc, d as ArcInhibitor, e as ArcInput, f as ArcOutput, g as ArcRead, h as ArcReset, C as Channel, i as ComposeBindings, F as FusionSet, j as FusionSetBuilder, I as In, k as InAll, l as InAtLeast, m as InExactly, n as InOne, o as Instance, p as Interface, q as InterfaceBuilder, L as LogFn, M as MAX_DURATION_MS, r as OutAnd, s as OutForwardInput, t as OutPlace, u as OutTimeout, v as OutXor, w as OutputEntry, x as PetriNetBuilder, y as Port, z as PortDirection, B as SubnetDefBuilder, D as SubnetInstance, G as Timing, H as TimingDeadline, J as TimingDelayed, K as TimingExact, N as TimingImmediate, Q as TimingWindow, R as TokenInput, U as TokenOutput, V as TransitionAction, W as TransitionBuilder, X as VerificationHarness, Y as VerificationResult, Z as all, _ as allPlaces, $ as and, a0 as andPlaces, a1 as arcPlace, a2 as atLeast, a3 as consumptionCount, a4 as deadline, a5 as delayed, a6 as earliest, a7 as enumerateBranches, a8 as environmentPlace, a9 as exact, aa as exactly, ab as fork, ac as forwardInput, ad as hasDeadline, ae as hasGuard, af as immediate, ag as inhibitorArc, ah as inputArc, ai as isUnit, aj as latest, ak as matchesGuard, al as one, am as outPlace, an as outputArc, ao as passthrough, ap as place, aq as produce, ar as readArc, as as requiredCount, at as resetArc, au as timeout, av as timeoutPlace, aw as tokenAt, ax as tokenOf, ay as transform, az as transformAsync, aA as transformFrom, aB as unitToken, aC as window, aD as withTimeout, aE as xor, aF as xorPlaces } from './petri-net-C3asscb4.js';
3
- import { E as EventStore } from './event-store-E_ahsEc9.js';
4
- export { A as ActionTimedOut, a as ExecutionCompleted, b as ExecutionStarted, I as InMemoryEventStore, L as LogMessage, M as MarkingSnapshot, N as NetEvent, T as TokenAdded, c as TokenRemoved, d as TransitionClockRestarted, e as TransitionCompleted, f as TransitionEnabled, g as TransitionFailed, h as TransitionStarted, i as TransitionTimedOut, j as eventTransitionName, k as eventsOfType, l as failures, m as filterEvents, n as inMemoryEventStore, o as isFailureEvent, p as noopEventStore, t as transitionEvents } from './event-store-E_ahsEc9.js';
1
+ import { P as PetriNet, S as SubnetDef, a as Place, T as Token, b as Transition, E as EnvironmentPlace, c as TransitionContext, O as Out } from './petri-net-D73-PO6d.js';
2
+ export { A as Arc, d as ArcInhibitor, e as ArcInput, f as ArcOutput, g as ArcRead, h as ArcReset, C as Channel, i as ComposeBindings, F as FusionSet, j as FusionSetBuilder, I as In, k as InAll, l as InAtLeast, m as InExactly, n as InOne, o as Instance, p as Interface, q as InterfaceBuilder, L as LogFn, M as MAX_DURATION_MS, r as OutAnd, s as OutForwardInput, t as OutPlace, u as OutTimeout, v as OutXor, w as OutputEntry, x as PetriNetBuilder, y as Port, z as PortDirection, B as SubnetDefBuilder, D as SubnetInstance, G as Timing, H as TimingDeadline, J as TimingDelayed, K as TimingExact, N as TimingImmediate, Q as TimingWindow, R as TokenInput, U as TokenOutput, V as TransitionAction, W as TransitionBuilder, X as VerificationHarness, Y as VerificationResult, Z as all, _ as allPlaces, $ as and, a0 as andPlaces, a1 as arcPlace, a2 as atLeast, a3 as consumptionCount, a4 as deadline, a5 as delayed, a6 as earliest, a7 as enumerateBranches, a8 as environmentPlace, a9 as exact, aa as exactly, ab as fork, ac as forwardInput, ad as hasDeadline, ae as hasGuard, af as immediate, ag as inhibitorArc, ah as inputArc, ai as isUnit, aj as latest, ak as matchesGuard, al as one, am as outPlace, an as outputArc, ao as passthrough, ap as place, aq as produce, ar as readArc, as as requiredCount, at as resetArc, au as timeout, av as timeoutPlace, aw as tokenAt, ax as tokenOf, ay as transform, az as transformAsync, aA as transformFrom, aB as unitToken, aC as window, aD as withTimeout, aE as xor, aF as xorPlaces } from './petri-net-D73-PO6d.js';
3
+ import { E as EventStore } from './event-store-8XkpYUeU.js';
4
+ export { A as ActionTimedOut, a as ExecutionCompleted, b as ExecutionStarted, I as InMemoryEventStore, L as LogMessage, M as MarkingSnapshot, N as NetEvent, T as TokenAdded, c as TokenRemoved, d as TransitionClockRestarted, e as TransitionCompleted, f as TransitionEnabled, g as TransitionFailed, h as TransitionStarted, i as TransitionTimedOut, j as eventTransitionName, k as eventsOfType, l as failures, m as filterEvents, n as inMemoryEventStore, o as isFailureEvent, p as noopEventStore, t as transitionEvents } from './event-store-8XkpYUeU.js';
5
5
 
6
6
  /**
7
7
  * Discriminated sum-type abstraction over Petri nets, distinguishing **closed**
package/dist/index.js CHANGED
@@ -203,6 +203,7 @@ function withTimeout(action, timeoutMs, timeoutPlace2, timeoutValue) {
203
203
  }
204
204
 
205
205
  // src/core/transition-context.ts
206
+ var EMPTY_ALIAS = /* @__PURE__ */ new Map();
206
207
  var TransitionContext = class {
207
208
  rawInput;
208
209
  _rawOutput;
@@ -215,7 +216,8 @@ var TransitionContext = class {
215
216
  _transitionName;
216
217
  executionCtx;
217
218
  _logFn;
218
- constructor(transitionName, rawInput, rawOutput, inputPlaces, readPlaces, outputPlaces, executionContext, logFn) {
219
+ placeAlias;
220
+ constructor(transitionName, rawInput, rawOutput, inputPlaces, readPlaces, outputPlaces, executionContext, logFn, placeAlias) {
219
221
  this._transitionName = transitionName;
220
222
  this.rawInput = rawInput;
221
223
  this._rawOutput = rawOutput;
@@ -233,28 +235,45 @@ var TransitionContext = class {
233
235
  this.allowedOutputs = ao;
234
236
  this.executionCtx = executionContext ?? /* @__PURE__ */ new Map();
235
237
  this._logFn = logFn;
238
+ this.placeAlias = placeAlias ?? EMPTY_ALIAS;
239
+ }
240
+ /**
241
+ * Resolves a place key through the transition's declared→actual place
242
+ * correspondence (per **MOD-031**). For a hand-written or directly-composed
243
+ * transition the correspondence is the identity, so this returns `place`
244
+ * unchanged; after instancing / port binding it maps a *declared* place
245
+ * constant the action hardcodes to the *actual* composed place. The result
246
+ * feeds both the declared-set check and the token-store access (both keyed by
247
+ * `place.name`), so `inputPlaces()`/`outputPlaces()` discovery is unaffected.
248
+ */
249
+ resolve(place2) {
250
+ const actual = this.placeAlias.get(place2.name);
251
+ return actual !== void 0 ? actual : place2;
236
252
  }
237
253
  // ==================== Input Access (consumed) ====================
238
254
  /** Get single consumed input value. Throws if place not declared or multiple tokens. */
239
255
  input(place2) {
240
- this.requireInput(place2);
241
- const values = this.rawInput.values(place2);
256
+ const actual = this.resolve(place2);
257
+ this.requireInput(actual);
258
+ const values = this.rawInput.values(actual);
242
259
  if (values.length !== 1) {
243
260
  throw new Error(
244
- `Place '${place2.name}' consumed ${values.length} tokens, use inputs() for batched access`
261
+ `Place '${actual.name}' consumed ${values.length} tokens, use inputs() for batched access`
245
262
  );
246
263
  }
247
264
  return values[0];
248
265
  }
249
266
  /** Get all consumed input values for a place. */
250
267
  inputs(place2) {
251
- this.requireInput(place2);
252
- return this.rawInput.values(place2);
268
+ const actual = this.resolve(place2);
269
+ this.requireInput(actual);
270
+ return this.rawInput.values(actual);
253
271
  }
254
272
  /** Get consumed input token with metadata. */
255
273
  inputToken(place2) {
256
- this.requireInput(place2);
257
- return this.rawInput.get(place2);
274
+ const actual = this.resolve(place2);
275
+ this.requireInput(actual);
276
+ return this.rawInput.get(actual);
258
277
  }
259
278
  /** Returns declared input places (consumed). */
260
279
  inputPlaces() {
@@ -270,13 +289,15 @@ var TransitionContext = class {
270
289
  // ==================== Read Access (not consumed) ====================
271
290
  /** Get read-only context value. Throws if place not declared as read. */
272
291
  read(place2) {
273
- this.requireRead(place2);
274
- return this.rawInput.value(place2);
292
+ const actual = this.resolve(place2);
293
+ this.requireRead(actual);
294
+ return this.rawInput.value(actual);
275
295
  }
276
296
  /** Get all read-only context values for a place. */
277
297
  reads(place2) {
278
- this.requireRead(place2);
279
- return this.rawInput.values(place2);
298
+ const actual = this.resolve(place2);
299
+ this.requireRead(actual);
300
+ return this.rawInput.values(actual);
280
301
  }
281
302
  /** Returns declared read places (context, not consumed). */
282
303
  readPlaces() {
@@ -303,9 +324,10 @@ var TransitionContext = class {
303
324
  * @throws if place not declared as output.
304
325
  */
305
326
  output(place2, ...values) {
306
- this.requireOutput(place2);
327
+ const actual = this.resolve(place2);
328
+ this.requireOutput(actual);
307
329
  for (const value of values) {
308
- this._rawOutput.add(place2, value);
330
+ this._rawOutput.add(actual, value);
309
331
  }
310
332
  return this;
311
333
  }
@@ -318,9 +340,10 @@ var TransitionContext = class {
318
340
  * @throws if place not declared as output.
319
341
  */
320
342
  outputToken(place2, ...tokens) {
321
- this.requireOutput(place2);
343
+ const actual = this.resolve(place2);
344
+ this.requireOutput(actual);
322
345
  for (const token of tokens) {
323
- this._rawOutput.addToken(place2, token);
346
+ this._rawOutput.addToken(actual, token);
324
347
  }
325
348
  return this;
326
349
  }
@@ -437,6 +460,7 @@ var TokenOutput = class {
437
460
 
438
461
  // src/core/transition.ts
439
462
  var TRANSITION_KEY = /* @__PURE__ */ Symbol("Transition.internal");
463
+ var EMPTY_PLACE_ALIAS = /* @__PURE__ */ new Map();
440
464
  var Transition = class {
441
465
  name;
442
466
  inputSpecs;
@@ -448,11 +472,23 @@ var Transition = class {
448
472
  actionTimeout;
449
473
  action;
450
474
  priority;
475
+ /**
476
+ * Per-transition **declared → actual** place correspondence (per
477
+ * **MOD-031**), keyed by the author-original declared place **name** →
478
+ * actual composed place. Empty for a hand-written or directly-composed
479
+ * ([MOD-025]) transition (identity). Populated by the subnet rewriter after
480
+ * instantiation ([MOD-010]) / port binding ([MOD-020]) so an action that
481
+ * hardcodes a declared place constant resolves to the composed place via
482
+ * {@link import('./transition-context.js').TransitionContext}. Consumed only
483
+ * by the action-facing context I/O — never by enablement, firing, the
484
+ * verifier, the exporter, or events (so [MOD-023] is unaffected).
485
+ */
486
+ placeAlias;
451
487
  _inputPlaces;
452
488
  _readPlaces;
453
489
  _outputPlaces;
454
490
  /** @internal Use {@link Transition.builder} to create instances. */
455
- constructor(key, name, inputSpecs, outputSpec, inhibitors, reads, resets, timing, action, priority) {
491
+ constructor(key, name, inputSpecs, outputSpec, inhibitors, reads, resets, timing, action, priority, placeAlias = EMPTY_PLACE_ALIAS) {
456
492
  if (key !== TRANSITION_KEY) throw new Error("Use Transition.builder() to create instances");
457
493
  this.name = name;
458
494
  this.inputSpecs = inputSpecs;
@@ -464,6 +500,7 @@ var Transition = class {
464
500
  this.actionTimeout = findTimeout(outputSpec);
465
501
  this.action = action;
466
502
  this.priority = priority;
503
+ this.placeAlias = placeAlias.size === 0 ? EMPTY_PLACE_ALIAS : placeAlias;
467
504
  const inputPlaces = /* @__PURE__ */ new Set();
468
505
  for (const spec of inputSpecs) {
469
506
  inputPlaces.add(spec.place);
@@ -515,6 +552,7 @@ var TransitionBuilder = class {
515
552
  _timing = immediate();
516
553
  _action = passthrough();
517
554
  _priority = 0;
555
+ _placeAlias = EMPTY_PLACE_ALIAS;
518
556
  constructor(name) {
519
557
  this._name = name;
520
558
  }
@@ -579,6 +617,16 @@ var TransitionBuilder = class {
579
617
  this._priority = priority;
580
618
  return this;
581
619
  }
620
+ /**
621
+ * Sets the per-transition declared→actual place correspondence (per
622
+ * **MOD-031**). Populated by the subnet rewriter during the compose-time
623
+ * rewrite; not normally called by hand-written nets, whose correspondence is
624
+ * the identity (empty map).
625
+ */
626
+ placeAlias(alias) {
627
+ this._placeAlias = alias;
628
+ return this;
629
+ }
582
630
  build() {
583
631
  if (this._outputSpec !== null) {
584
632
  const inputPlaceNames = new Set(this._inputSpecs.map((s) => s.place.name));
@@ -600,7 +648,8 @@ var TransitionBuilder = class {
600
648
  [...this._resets],
601
649
  this._timing,
602
650
  this._action,
603
- this._priority
651
+ this._priority,
652
+ this._placeAlias
604
653
  );
605
654
  }
606
655
  };
@@ -895,6 +944,10 @@ function substitutePlaces(t, remap) {
895
944
  }
896
945
  function rebuildWithName(t, name, remap) {
897
946
  const builder = Transition.builder(name).timing(t.timing).priority(t.priority).action(t.action);
947
+ const alias = buildPlaceAlias(t, remap);
948
+ if (alias.size > 0) {
949
+ builder.placeAlias(alias);
950
+ }
898
951
  if (t.inputSpecs.length > 0) {
899
952
  const rewrittenInputs = new Array(t.inputSpecs.length);
900
953
  for (let i = 0; i < t.inputSpecs.length; i++) {
@@ -916,6 +969,39 @@ function rebuildWithName(t, name, remap) {
916
969
  }
917
970
  return builder.build();
918
971
  }
972
+ function buildPlaceAlias(t, remap) {
973
+ const prev = t.placeAlias;
974
+ if (remap.size === 0 && prev.size === 0) {
975
+ return EMPTY_ALIAS2;
976
+ }
977
+ const alias = /* @__PURE__ */ new Map();
978
+ if (prev.size > 0) {
979
+ for (const [declaredName, prevActual] of prev) {
980
+ const replaced = remap.get(prevActual.name);
981
+ const finalActual = replaced !== void 0 ? replaced : prevActual;
982
+ if (finalActual.name !== declaredName) {
983
+ alias.set(declaredName, finalActual);
984
+ }
985
+ }
986
+ return alias;
987
+ }
988
+ const record = (p) => {
989
+ if (alias.has(p.name)) return;
990
+ const replaced = remap.get(p.name);
991
+ if (replaced !== void 0 && replaced.name !== p.name) {
992
+ alias.set(p.name, replaced);
993
+ }
994
+ };
995
+ for (const spec of t.inputSpecs) record(spec.place);
996
+ for (const rd of t.reads) record(rd.place);
997
+ for (const inh of t.inhibitors) record(inh.place);
998
+ for (const rs of t.resets) record(rs.place);
999
+ if (t.outputSpec !== null) {
1000
+ for (const p of allPlaces(t.outputSpec)) record(p);
1001
+ }
1002
+ return alias;
1003
+ }
1004
+ var EMPTY_ALIAS2 = /* @__PURE__ */ new Map();
919
1005
  function rewriteIn(spec, remap) {
920
1006
  switch (spec.type) {
921
1007
  case "one":
@@ -2124,6 +2210,9 @@ var PetriNetBuilder = class _PetriNetBuilder {
2124
2210
  };
2125
2211
  function rebuildWithAction(t, action) {
2126
2212
  const builder = Transition.builder(t.name).timing(t.timing).priority(t.priority).action(action);
2213
+ if (t.placeAlias.size > 0) {
2214
+ builder.placeAlias(t.placeAlias);
2215
+ }
2127
2216
  if (t.inputSpecs.length > 0) {
2128
2217
  builder.inputs(...t.inputSpecs);
2129
2218
  }
@@ -3044,7 +3133,8 @@ var BitmapNetExecutor = class {
3044
3133
  t.readPlaces(),
3045
3134
  t.outputPlaces(),
3046
3135
  execCtx,
3047
- logFn
3136
+ logFn,
3137
+ t.placeAlias
3048
3138
  );
3049
3139
  let actionPromise = t.action(context);
3050
3140
  if (t.hasActionTimeout()) {
@@ -4215,7 +4305,8 @@ var PrecompiledNetExecutor = class {
4215
4305
  t.readPlaces(),
4216
4306
  t.outputPlaces(),
4217
4307
  execCtx,
4218
- logFn
4308
+ logFn,
4309
+ t.placeAlias
4219
4310
  );
4220
4311
  let actionPromise = t.action(context);
4221
4312
  if (t.hasActionTimeout()) {