@almadar/runtime 5.1.0 → 5.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.
@@ -1,5 +1,5 @@
1
1
  import { Router } from 'express';
2
- import { I as IEventBus, g as RuntimeEvent, f as EventListener, U as Unsubscribe, T as TraitDefinition, R as RuntimeConfig, i as TransitionObserver, h as TraitState, j as TransitionResult, E as EvaluationContextExtensions, a as EffectHandlers } from './types-DwDhc9Jt.js';
2
+ import { I as IEventBus, g as RuntimeEvent, f as EventListener, U as Unsubscribe, T as TraitDefinition, R as RuntimeConfig, i as TransitionObserver, C as ConfigContext, h as TraitState, j as TransitionResult, E as EvaluationContextExtensions, a as EffectHandlers } from './types-SmmabGZk.js';
3
3
  import { EventPayload, EntityRow, OrbitalSchema, Orbital, Trait, OrbitalDefinition, Entity, TraitConfig, TraitTick } from '@almadar/core';
4
4
 
5
5
  /**
@@ -121,6 +121,17 @@ interface ProcessEventOptions {
121
121
  payload?: EventPayload;
122
122
  /** Entity data for binding resolution */
123
123
  entityData?: EntityRow;
124
+ /**
125
+ * Trait config for `@config.X` resolution inside guard expressions.
126
+ * Surfaced on the EvaluationContext so guards can write mode-aware
127
+ * predicates — e.g. std-modal's OPEN can require `@payload.row` only
128
+ * when `@config.mode === "edit"`. The validator (sigil_context.rs)
129
+ * allows `@config` in guard context as of v3.12.0; this field is
130
+ * the runtime side of the same contract. Threaded by the caller
131
+ * (typically `OrbitalServerRuntime.processEvent` reading from the
132
+ * trait's `RegisteredOrbital.configByTrait`).
133
+ */
134
+ config?: ConfigContext;
124
135
  /**
125
136
  * Guard evaluation error handling mode. (RCG-02)
126
137
  * - "permissive": Guard errors allow the transition (default, backwards-compatible)
@@ -169,6 +180,15 @@ interface ProcessEventOptions {
169
180
  declare function processEvent(options: ProcessEventOptions): TransitionResult;
170
181
  declare class StateMachineManager {
171
182
  private traits;
183
+ /**
184
+ * Per-trait call-site config, surfaced to guard expressions so
185
+ * `@config.X` resolves at runtime. Populated by the orbital's
186
+ * registration step (see `OrbitalServerRuntime.registerOrbital`'s
187
+ * `configByTrait` projection). Empty for atom-scope traits whose
188
+ * call-site config wasn't supplied — guards that read `@config.X`
189
+ * in that case will see `undefined` and short-circuit accordingly.
190
+ */
191
+ private traitConfigs;
172
192
  /**
173
193
  * State map keyed by `${traitName}::${entityId | __singleton__}`.
174
194
  *
@@ -198,6 +218,13 @@ declare class StateMachineManager {
198
218
  * Add a trait to the manager.
199
219
  */
200
220
  addTrait(trait: TraitDefinition): void;
221
+ /**
222
+ * Bind the call-site config for a trait so guard `@config.X`
223
+ * resolves at runtime. Typically called by the orbital
224
+ * registration step right after `addTrait`. Idempotent; passing
225
+ * `undefined` clears the binding.
226
+ */
227
+ setTraitConfig(traitName: string, config: ConfigContext | undefined): void;
201
228
  /**
202
229
  * Remove a trait from the manager.
203
230
  */
@@ -1,4 +1,4 @@
1
1
  import 'express';
2
- export { C as EffectResult, e as InMemoryPersistence, D as LoaderConfig, F as LocalPersistenceAdapter, O as OrbitalEventRequest, f as OrbitalEventResponse, G as OrbitalServerRuntime, g as OrbitalServerRuntimeConfig, P as PersistenceAdapter, R as RegisteredOrbital, l as RuntimeOrbital, m as RuntimeOrbitalSchema, n as RuntimeTrait, H as RuntimeTraitTick, J as createOrbitalServerRuntime } from './OrbitalServerRuntime-D-b_dg8I.js';
3
- import './types-DwDhc9Jt.js';
2
+ export { C as EffectResult, e as InMemoryPersistence, D as LoaderConfig, F as LocalPersistenceAdapter, O as OrbitalEventRequest, f as OrbitalEventResponse, G as OrbitalServerRuntime, g as OrbitalServerRuntimeConfig, P as PersistenceAdapter, R as RegisteredOrbital, l as RuntimeOrbital, m as RuntimeOrbitalSchema, n as RuntimeTrait, H as RuntimeTraitTick, J as createOrbitalServerRuntime } from './OrbitalServerRuntime-BrJ7m0hz.js';
3
+ import './types-SmmabGZk.js';
4
4
  import '@almadar/core';
@@ -1,5 +1,5 @@
1
- import { createLogger, EventBus, createUnifiedLoader, MockPersistenceAdapter, InMemoryPersistence, preprocessSchema, StateMachineManager, createContextFromBindings, EffectExecutor } from './chunk-T343XTYB.js';
2
- export { InMemoryPersistence } from './chunk-T343XTYB.js';
1
+ import { createLogger, EventBus, createUnifiedLoader, MockPersistenceAdapter, InMemoryPersistence, preprocessSchema, StateMachineManager, createContextFromBindings, validateEventPayload, formatPayloadValidationError, EffectExecutor } from './chunk-FAWWBERN.js';
2
+ export { InMemoryPersistence } from './chunk-FAWWBERN.js';
3
3
  import './chunk-PZ5AY32C.js';
4
4
  import { Router } from 'express';
5
5
  import * as fs from 'fs';
@@ -360,6 +360,8 @@ function createOsHandlers(ctx) {
360
360
 
361
361
  // src/OrbitalServerRuntime.ts
362
362
  var effectLog = createLogger("almadar:runtime:effects");
363
+ var busLog = createLogger("almadar:runtime:bus");
364
+ var renderLog = createLogger("almadar:runtime:render-ui");
363
365
  function collectDeclaredConfigDefaults(trait) {
364
366
  if (!trait) return void 0;
365
367
  const schema = trait.config;
@@ -752,6 +754,9 @@ var OrbitalServerRuntime = class {
752
754
  const manager = new StateMachineManager(traitDefs, {
753
755
  contextExtensions: this.config.contextExtensions
754
756
  });
757
+ for (const [traitName, traitConfig] of configByTrait) {
758
+ manager.setTraitConfig(traitName, traitConfig);
759
+ }
755
760
  const entityRef = orbital.entity;
756
761
  let entity;
757
762
  if (typeof entityRef === "string") {
@@ -1097,7 +1102,47 @@ var OrbitalServerRuntime = class {
1097
1102
  error: `Orbital not found: ${orbitalName}`
1098
1103
  };
1099
1104
  }
1105
+ const payloadRow = request.payload?.["row"];
1106
+ const payloadRowAsPayload = payloadRow !== null && typeof payloadRow === "object" && !Array.isArray(payloadRow) ? payloadRow : void 0;
1107
+ const payloadRowId = payloadRowAsPayload?.["id"];
1108
+ renderLog.debug("processOrbitalEvent:enter", {
1109
+ orbital: orbitalName,
1110
+ event: request.event,
1111
+ hasPayloadRow: payloadRowAsPayload !== void 0,
1112
+ payloadRowId: typeof payloadRowId === "string" || typeof payloadRowId === "number" ? payloadRowId : void 0,
1113
+ entityId: request.entityId
1114
+ });
1115
+ busLog.debug("bus:incoming", {
1116
+ orbital: orbitalName,
1117
+ event: request.event,
1118
+ payload: JSON.stringify(request.payload ?? null),
1119
+ entityId: request.entityId,
1120
+ traitStates: JSON.stringify(
1121
+ Array.from(registered.manager.getAllStates().entries()).map(([traitName, state]) => ({
1122
+ traitName,
1123
+ currentState: state.currentState
1124
+ }))
1125
+ )
1126
+ });
1100
1127
  const { event, payload, entityId, user } = request;
1128
+ const validationFailures = [];
1129
+ for (const trait of registered.traits) {
1130
+ const eventSchema = trait.stateMachine?.events?.find((e) => e.key === event);
1131
+ if (eventSchema?.payloadSchema && eventSchema.payloadSchema.length > 0) {
1132
+ validationFailures.push(
1133
+ ...validateEventPayload(event, payload, eventSchema.payloadSchema)
1134
+ );
1135
+ }
1136
+ }
1137
+ if (validationFailures.length > 0) {
1138
+ return {
1139
+ success: false,
1140
+ transitioned: false,
1141
+ states: {},
1142
+ emittedEvents: [],
1143
+ error: formatPayloadValidationError(validationFailures)
1144
+ };
1145
+ }
1101
1146
  const emittedEvents = [];
1102
1147
  const fetchedData = {};
1103
1148
  const clientEffects = [];
@@ -1577,6 +1622,17 @@ var OrbitalServerRuntime = class {
1577
1622
  },
1578
1623
  // Client-side effects - collect for forwarding to client
1579
1624
  renderUI: (slot, pattern, props, priority) => {
1625
+ const patternNode = pattern !== null && typeof pattern === "object" && !Array.isArray(pattern) ? pattern : null;
1626
+ const patternEntity = patternNode?.entity;
1627
+ const entityRow = patternEntity !== null && typeof patternEntity === "object" && !Array.isArray(patternEntity) ? patternEntity : null;
1628
+ const patternTypeRaw = patternNode?.["type"];
1629
+ renderLog.debug("renderUI:push", {
1630
+ trait: traitName,
1631
+ slot,
1632
+ patternType: typeof patternTypeRaw === "string" ? patternTypeRaw : void 0,
1633
+ entityRowId: typeof entityRow?.id === "string" ? entityRow.id : void 0,
1634
+ entityIsObject: entityRow !== null
1635
+ });
1580
1636
  pushClientEffect(["render-ui", slot, pattern, props, priority]);
1581
1637
  },
1582
1638
  navigate: (path2, params) => {