libpetri 2.5.0 → 2.6.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.
@@ -1,4 +1,4 @@
1
- import { P as PetriNet } from '../petri-net-DXdpd0r5.js';
1
+ import { P as PetriNet } from '../petri-net-C3asscb4.js';
2
2
 
3
3
  /**
4
4
  * Format-agnostic typed graph model.
@@ -8,8 +8,8 @@ import {
8
8
  nodeStyle,
9
9
  renderDot,
10
10
  sanitize
11
- } from "../chunk-2GAZLDH3.js";
12
- import "../chunk-FN773SSE.js";
11
+ } from "../chunk-ULX3OG6H.js";
12
+ import "../chunk-ATT7U5H5.js";
13
13
  export {
14
14
  DEFAULT_DOT_CONFIG,
15
15
  FONT,
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-DXdpd0r5.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-DXdpd0r5.js';
3
- import { E as EventStore } from './event-store-z30VMn0T.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-z30VMn0T.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-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';
5
5
 
6
6
  /**
7
7
  * Discriminated sum-type abstraction over Petri nets, distinguishing **closed**
@@ -221,6 +221,13 @@ interface BitmapNetExecutorOptions {
221
221
  environmentPlaces?: Set<EnvironmentPlace<any>>;
222
222
  /** Provides execution context data for each transition firing. */
223
223
  executionContextProvider?: (transitionName: string, consumed: Token<any>[]) => Map<string, unknown>;
224
+ /**
225
+ * Grace band (ms) beyond a hard deadline (`deadline()` / `window()`) before a transition is
226
+ * force-disabled with a `transition-timed-out` event (TIME-013). Defaults to {@link DEADLINE_TOLERANCE_MS}
227
+ * (5ms); `0` gives strict enforcement. Must be non-negative. Does not affect `exact()` transitions,
228
+ * which are enforced softly (TIME-006).
229
+ */
230
+ deadlineToleranceMs?: number;
224
231
  }
225
232
  /**
226
233
  * Async bitmap-based executor for Coloured Time Petri Nets.
@@ -262,6 +269,10 @@ declare class BitmapNetExecutor implements PetriNetExecutor {
262
269
  private readonly enabledFlags;
263
270
  /** Precomputed: 1 if transition has a finite deadline, 0 otherwise. */
264
271
  private readonly hasDeadlineFlags;
272
+ /** Precomputed: 1 for exact() transitions — enforced softly, never force-disabled (TIME-006). */
273
+ private readonly isExactFlags;
274
+ /** Grace band (ms) before a hard deadline force-disables (TIME-013). */
275
+ private readonly deadlineToleranceMs;
265
276
  private enabledTransitionCount;
266
277
  private readonly inFlight;
267
278
  private readonly inFlightPromises;
@@ -394,6 +405,12 @@ declare class PrecompiledNet {
394
405
  readonly earliestMs: Float64Array;
395
406
  readonly latestMs: Float64Array;
396
407
  readonly hasDeadline: Uint8Array;
408
+ /**
409
+ * 1 for `exact()` transitions. Exact transitions fire at the first opportunity at/after their
410
+ * target time (delayed-style liveness) and are never force-disabled by deadline enforcement —
411
+ * their upper bound is observed, not enforced. See TIME-006.
412
+ */
413
+ readonly isExact: Uint8Array;
397
414
  readonly priorities: Int32Array;
398
415
  readonly transitionToPriorityIndex: Uint32Array;
399
416
  readonly priorityLevels: readonly number[];
@@ -456,6 +473,13 @@ interface PrecompiledNetExecutorOptions {
456
473
  skipOutputValidation?: boolean;
457
474
  /** Reuse a precompiled program (avoids recompilation). */
458
475
  program?: PrecompiledNet;
476
+ /**
477
+ * Grace band (ms) beyond a hard deadline (`deadline()` / `window()`) before a transition is
478
+ * force-disabled with a `transition-timed-out` event (TIME-013). Defaults to {@link DEADLINE_TOLERANCE_MS}
479
+ * (5ms); `0` gives strict enforcement. Must be non-negative. Does not affect `exact()` transitions,
480
+ * which are enforced softly (TIME-006).
481
+ */
482
+ deadlineToleranceMs?: number;
459
483
  }
460
484
  /**
461
485
  * High-performance executor using `PrecompiledNet`.
@@ -470,6 +494,7 @@ declare class PrecompiledNetExecutor implements PetriNetExecutor {
470
494
  private readonly hasEnvironmentPlaces;
471
495
  private readonly executionContextProvider?;
472
496
  private readonly skipOutputValidation;
497
+ private readonly deadlineToleranceMs;
473
498
  private readonly startMs;
474
499
  private readonly eventStoreEnabled;
475
500
  /** Per-place token arrays, indexed by pid. */
package/dist/index.js CHANGED
@@ -12,7 +12,7 @@ import {
12
12
  timeoutPlace,
13
13
  xor,
14
14
  xorPlaces
15
- } from "./chunk-H62Z76FY.js";
15
+ } from "./chunk-ETNHEAS6.js";
16
16
  import {
17
17
  eventTransitionName,
18
18
  isFailureEvent
@@ -27,7 +27,7 @@ import {
27
27
  immediate,
28
28
  latest,
29
29
  window
30
- } from "./chunk-FN773SSE.js";
30
+ } from "./chunk-ATT7U5H5.js";
31
31
 
32
32
  // src/core/token.ts
33
33
  var UNIT_TOKEN = Object.freeze({
@@ -2529,6 +2529,7 @@ var OutViolationError = class extends Error {
2529
2529
  };
2530
2530
 
2531
2531
  // src/runtime/executor-support.ts
2532
+ var DEADLINE_TOLERANCE_MS = 5;
2532
2533
  function validateOutSpec(tName, spec, producedPlaceNames) {
2533
2534
  switch (spec.type) {
2534
2535
  case "place":
@@ -2589,7 +2590,6 @@ function produceTimeoutOutput(context, timeoutChild) {
2589
2590
  }
2590
2591
 
2591
2592
  // src/runtime/bitmap-net-executor.ts
2592
- var DEADLINE_TOLERANCE_MS = 5;
2593
2593
  var BitmapNetExecutor = class {
2594
2594
  compiled;
2595
2595
  marking;
@@ -2614,6 +2614,10 @@ var BitmapNetExecutor = class {
2614
2614
  enabledFlags;
2615
2615
  /** Precomputed: 1 if transition has a finite deadline, 0 otherwise. */
2616
2616
  hasDeadlineFlags;
2617
+ /** Precomputed: 1 for exact() transitions — enforced softly, never force-disabled (TIME-006). */
2618
+ isExactFlags;
2619
+ /** Grace band (ms) before a hard deadline force-disables (TIME-013). */
2620
+ deadlineToleranceMs;
2617
2621
  enabledTransitionCount = 0;
2618
2622
  // In-flight tracking
2619
2623
  inFlight = /* @__PURE__ */ new Map();
@@ -2641,6 +2645,10 @@ var BitmapNetExecutor = class {
2641
2645
  );
2642
2646
  this.hasEnvironmentPlaces = this.environmentPlaces.size > 0;
2643
2647
  this.executionContextProvider = options.executionContextProvider;
2648
+ this.deadlineToleranceMs = options.deadlineToleranceMs ?? DEADLINE_TOLERANCE_MS;
2649
+ if (this.deadlineToleranceMs < 0) {
2650
+ throw new Error(`Deadline tolerance must be non-negative: ${this.deadlineToleranceMs}`);
2651
+ }
2644
2652
  this.startMs = performance.now();
2645
2653
  const wordCount = this.compiled.wordCount;
2646
2654
  this.markedPlaces = new Uint32Array(wordCount);
@@ -2654,6 +2662,7 @@ var BitmapNetExecutor = class {
2654
2662
  this.inFlightFlags = new Uint8Array(this.compiled.transitionCount);
2655
2663
  this.enabledFlags = new Uint8Array(this.compiled.transitionCount);
2656
2664
  this.hasDeadlineFlags = new Uint8Array(this.compiled.transitionCount);
2665
+ this.isExactFlags = new Uint8Array(this.compiled.transitionCount);
2657
2666
  let anyDeadlines = false;
2658
2667
  let allImm = true;
2659
2668
  let samePrio = true;
@@ -2664,6 +2673,7 @@ var BitmapNetExecutor = class {
2664
2673
  this.hasDeadlineFlags[tid] = 1;
2665
2674
  anyDeadlines = true;
2666
2675
  }
2676
+ if (t.timing.type === "exact") this.isExactFlags[tid] = 1;
2667
2677
  if (t.timing.type !== "immediate") allImm = false;
2668
2678
  if (t.priority !== firstPriority) samePrio = false;
2669
2679
  }
@@ -2843,11 +2853,12 @@ var BitmapNetExecutor = class {
2843
2853
  enforceDeadlines(nowMs) {
2844
2854
  for (let tid = 0; tid < this.compiled.transitionCount; tid++) {
2845
2855
  if (!this.hasDeadlineFlags[tid]) continue;
2856
+ if (this.isExactFlags[tid]) continue;
2846
2857
  if (!this.enabledFlags[tid] || this.inFlightFlags[tid]) continue;
2847
2858
  const t = this.compiled.transition(tid);
2848
2859
  const elapsed = nowMs - this.enabledAtMs[tid];
2849
2860
  const latestMs = latest(t.timing);
2850
- if (elapsed > latestMs + DEADLINE_TOLERANCE_MS) {
2861
+ if (elapsed > latestMs + this.deadlineToleranceMs) {
2851
2862
  this.enabledFlags[tid] = 0;
2852
2863
  this.enabledTransitionCount--;
2853
2864
  this.emitEvent({
@@ -3364,6 +3375,12 @@ var PrecompiledNet = class _PrecompiledNet {
3364
3375
  earliestMs;
3365
3376
  latestMs;
3366
3377
  hasDeadline;
3378
+ /**
3379
+ * 1 for `exact()` transitions. Exact transitions fire at the first opportunity at/after their
3380
+ * target time (delayed-style liveness) and are never force-disabled by deadline enforcement —
3381
+ * their upper bound is observed, not enforced. See TIME-006.
3382
+ */
3383
+ isExact;
3367
3384
  // ==================== Priority (CONC-023) ====================
3368
3385
  priorities;
3369
3386
  transitionToPriorityIndex;
@@ -3484,6 +3501,7 @@ var PrecompiledNet = class _PrecompiledNet {
3484
3501
  this.earliestMs = new Float64Array(tc);
3485
3502
  this.latestMs = new Float64Array(tc);
3486
3503
  this.hasDeadline = new Uint8Array(tc);
3504
+ this.isExact = new Uint8Array(tc);
3487
3505
  let anyDeadlines = false;
3488
3506
  let allImm = true;
3489
3507
  for (let tid = 0; tid < tc; tid++) {
@@ -3494,6 +3512,7 @@ var PrecompiledNet = class _PrecompiledNet {
3494
3512
  this.hasDeadline[tid] = 1;
3495
3513
  anyDeadlines = true;
3496
3514
  }
3515
+ if (t.timing.type === "exact") this.isExact[tid] = 1;
3497
3516
  if (t.timing.type !== "immediate") allImm = false;
3498
3517
  }
3499
3518
  this.anyDeadlines = anyDeadlines;
@@ -3661,7 +3680,6 @@ function simpleOutputPlace(spec, compiled) {
3661
3680
  }
3662
3681
 
3663
3682
  // src/runtime/precompiled-net-executor.ts
3664
- var DEADLINE_TOLERANCE_MS2 = 5;
3665
3683
  var PrecompiledNetExecutor = class {
3666
3684
  program;
3667
3685
  eventStore;
@@ -3669,6 +3687,7 @@ var PrecompiledNetExecutor = class {
3669
3687
  hasEnvironmentPlaces;
3670
3688
  executionContextProvider;
3671
3689
  skipOutputValidation;
3690
+ deadlineToleranceMs;
3672
3691
  startMs;
3673
3692
  eventStoreEnabled;
3674
3693
  // ==================== Token Storage ====================
@@ -3722,6 +3741,10 @@ var PrecompiledNetExecutor = class {
3722
3741
  this.hasEnvironmentPlaces = this.environmentPlaces.size > 0;
3723
3742
  this.executionContextProvider = options.executionContextProvider;
3724
3743
  this.skipOutputValidation = options.skipOutputValidation ?? false;
3744
+ this.deadlineToleranceMs = options.deadlineToleranceMs ?? DEADLINE_TOLERANCE_MS;
3745
+ if (this.deadlineToleranceMs < 0) {
3746
+ throw new Error(`Deadline tolerance must be non-negative: ${this.deadlineToleranceMs}`);
3747
+ }
3725
3748
  this.startMs = performance.now();
3726
3749
  this.eventStoreEnabled = this.eventStore.isEnabled();
3727
3750
  const prog = this.program;
@@ -3936,10 +3959,11 @@ var PrecompiledNetExecutor = class {
3936
3959
  const tc = prog.transitionCount;
3937
3960
  for (let tid = 0; tid < tc; tid++) {
3938
3961
  if (!prog.hasDeadline[tid]) continue;
3962
+ if (prog.isExact[tid]) continue;
3939
3963
  if (!this.enabledFlags[tid] || this.inFlightFlags[tid]) continue;
3940
3964
  const elapsed = nowMs - this.enabledAtMs[tid];
3941
3965
  const latestMs = prog.latestMs[tid];
3942
- if (elapsed > latestMs + DEADLINE_TOLERANCE_MS2) {
3966
+ if (elapsed > latestMs + this.deadlineToleranceMs) {
3943
3967
  this.enabledFlags[tid] = 0;
3944
3968
  this.enabledTransitionCount--;
3945
3969
  this.enabledAtMs[tid] = -Infinity;