@almadar/runtime 2.6.1 → 2.7.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 { I as IEventBus } from './types-DYcUvi4H.js';
1
+ import { I as IEventBus } from './types-CvYnmqkg.js';
2
2
  import { EventPayload } from '@almadar/core';
3
3
 
4
4
  /**
@@ -266,7 +266,7 @@ function extractBindings(value) {
266
266
  collect(value);
267
267
  return [...new Set(bindings)];
268
268
  }
269
- function createContextFromBindings(bindings, strictBindings) {
269
+ function createContextFromBindings(bindings, strictBindings, contextExtensions) {
270
270
  const ctx = createMinimalContext(
271
271
  bindings.entity || {},
272
272
  bindings.payload || {},
@@ -280,6 +280,9 @@ function createContextFromBindings(bindings, strictBindings) {
280
280
  ctx.singletons.set(key, value);
281
281
  }
282
282
  }
283
+ if (contextExtensions) {
284
+ Object.assign(ctx, contextExtensions);
285
+ }
283
286
  return ctx;
284
287
  }
285
288
  var smLog = createLogger("almadar:runtime:sm");
@@ -324,7 +327,8 @@ function processEvent(options) {
324
327
  payload,
325
328
  entityData,
326
329
  guardMode = "permissive",
327
- strictBindings = false
330
+ strictBindings = false,
331
+ contextExtensions
328
332
  } = options;
329
333
  const normalizedEvent = normalizeEventKey(eventKey);
330
334
  const transition = findTransition(trait, traitState.currentState, normalizedEvent);
@@ -343,7 +347,7 @@ function processEvent(options) {
343
347
  entity: entityData,
344
348
  payload,
345
349
  state: traitState.currentState
346
- }, strictBindings);
350
+ }, strictBindings, contextExtensions);
347
351
  try {
348
352
  const guardPasses = evaluateGuard(
349
353
  transition.guard,
@@ -474,7 +478,8 @@ var StateMachineManager = class {
474
478
  payload,
475
479
  entityData,
476
480
  guardMode: this.config.guardMode,
477
- strictBindings: this.config.strictBindings
481
+ strictBindings: this.config.strictBindings,
482
+ contextExtensions: this.config.contextExtensions
478
483
  });
479
484
  if (result.executed) {
480
485
  this.states.set(traitName, {
@@ -544,7 +549,8 @@ var StateMachineManager = class {
544
549
  payload: entry.payload,
545
550
  entityData: entry.entityData,
546
551
  guardMode: this.config.guardMode,
547
- strictBindings: this.config.strictBindings
552
+ strictBindings: this.config.strictBindings,
553
+ contextExtensions: this.config.contextExtensions
548
554
  });
549
555
  if (result.executed) {
550
556
  this.states.set(traitName, {
@@ -638,8 +644,8 @@ function parseEffect(effect) {
638
644
  }
639
645
  return { operator, args };
640
646
  }
641
- function resolveArgs(args, bindings, strictBindings) {
642
- const ctx = createContextFromBindings(bindings, strictBindings);
647
+ function resolveArgs(args, bindings, strictBindings, contextExtensions) {
648
+ const ctx = createContextFromBindings(bindings, strictBindings, contextExtensions);
643
649
  return args.map((arg) => interpolateValue(arg, ctx));
644
650
  }
645
651
  var EffectExecutor = class {
@@ -648,12 +654,14 @@ var EffectExecutor = class {
648
654
  context;
649
655
  debug;
650
656
  strictBindings;
657
+ contextExtensions;
651
658
  constructor(options) {
652
659
  this.handlers = options.handlers;
653
660
  this.bindings = options.bindings;
654
661
  this.context = options.context;
655
662
  this.debug = options.debug ?? false;
656
663
  this.strictBindings = options.strictBindings ?? false;
664
+ this.contextExtensions = options.contextExtensions;
657
665
  }
658
666
  // ==========================================================================
659
667
  // Handler Manifest Validation (RCG-03)
@@ -737,7 +745,7 @@ var EffectExecutor = class {
737
745
  }
738
746
  const { operator, args } = parsed;
739
747
  const isCompound = operator === "do" || operator === "when";
740
- const resolvedArgs = isCompound ? args : resolveArgs(args, this.bindings, this.strictBindings);
748
+ const resolvedArgs = isCompound ? args : resolveArgs(args, this.bindings, this.strictBindings, this.contextExtensions);
741
749
  effectLog.debug("execute", { operator, argCount: resolvedArgs.length, context: this.context.traitName });
742
750
  if (this.debug) {
743
751
  console.log("[EffectExecutor] Executing:", operator, resolvedArgs);
@@ -791,7 +799,7 @@ var EffectExecutor = class {
791
799
  const start = Date.now();
792
800
  const { operator, args: rawArgs } = parsed;
793
801
  const isCompound = operator === "do" || operator === "when";
794
- const resolvedArgs = isCompound ? rawArgs : resolveArgs(rawArgs, this.bindings, this.strictBindings);
802
+ const resolvedArgs = isCompound ? rawArgs : resolveArgs(rawArgs, this.bindings, this.strictBindings, this.contextExtensions);
795
803
  try {
796
804
  await this.dispatch(operator, resolvedArgs);
797
805
  results.push({
@@ -995,7 +1003,7 @@ var EffectExecutor = class {
995
1003
  break;
996
1004
  }
997
1005
  case "when": {
998
- const ctx = createContextFromBindings(this.bindings);
1006
+ const ctx = createContextFromBindings(this.bindings, false, this.contextExtensions);
999
1007
  const condition = interpolateValue(args[0], ctx);
1000
1008
  const thenEffect = args[1];
1001
1009
  const elseEffect = args[2];
@@ -2315,5 +2323,5 @@ function parseNamespacedEvent(eventName) {
2315
2323
  }
2316
2324
 
2317
2325
  export { EffectExecutor, EventBus, HANDLER_MANIFEST, StateMachineManager, containsBindings, createContextFromBindings, createInitialTraitState, createTestExecutor, createUnifiedLoader, extractBindings, findInitialState, findTransition, getIsolatedCollectionName, getNamespacedEvent, interpolateProps, interpolateValue, isNamespacedEvent, normalizeEventKey, parseNamespacedEvent, preprocessSchema, processEvent };
2318
- //# sourceMappingURL=chunk-ESNML4B4.js.map
2319
- //# sourceMappingURL=chunk-ESNML4B4.js.map
2326
+ //# sourceMappingURL=chunk-ZYH3XSOL.js.map
2327
+ //# sourceMappingURL=chunk-ZYH3XSOL.js.map