@almadar/runtime 6.32.0 → 6.34.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,6 +1,6 @@
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, C as ConfigContext, h as TraitState, j as TransitionResult, E as EvaluationContextExtensions, a as EffectHandlers } from './types-D-9feVsj.js';
3
- import { EventPayload, EntityRow, Orbital, ServiceCallResult, TraitConfig, DeclaredTraitConfig, Entity, CallSiteConfig, OrbitalSchema, Trait, PatternConfig, ResolvedPatternProps, SExpr, BusEventSource, OrbitalDefinition, TraitTick } from '@almadar/core';
2
+ import { I as IEventBus, R as RuntimeEvent, a as EventListener, U as Unsubscribe, T as TraitDefinition, b as RuntimeConfig, c as TransitionObserver, d as TraitState, C as ConfigContext, e as TransitionResult, f as EvaluationContextExtensions, E as EffectHandlers } from './types-C8RsO0xa.js';
3
+ import { EventPayload, EventId, EntityRow, Orbital, ServiceCallResult, TraitConfig, DeclaredTraitConfig, Entity, OrbitalSchema, Trait, PatternConfig, ResolvedPatternProps, SExpr, BusEventSource, OrbitalDefinition, TraitTick } from '@almadar/core';
4
4
 
5
5
  /**
6
6
  * EventBus - Platform-Agnostic Pub/Sub Implementation
@@ -47,7 +47,7 @@ declare class EventBus implements IEventBus {
47
47
  * beyond `maxDepth`, the event is dropped and an error is logged.
48
48
  * This prevents infinite loops from circular emit/listen chains.
49
49
  */
50
- emit(type: string, payload?: EventPayload, source?: RuntimeEvent['source']): void;
50
+ emit(type: string, payload?: EventPayload, source?: RuntimeEvent['source'], routingKey?: string): void;
51
51
  /**
52
52
  * Subscribe to an event type
53
53
  */
@@ -101,7 +101,7 @@ declare function createInitialTraitState(trait: TraitDefinition): TraitState;
101
101
  * when multiple sibling transitions share the same `from`/`event` and
102
102
  * disambiguate by guard.
103
103
  */
104
- declare function findTransition(trait: TraitDefinition, currentState: string, eventKey: string): TraitDefinition['transitions'][0] | undefined;
104
+ declare function findTransition(trait: TraitDefinition, currentState: string, eventKey: string, eventId?: EventId): TraitDefinition['transitions'][0] | undefined;
105
105
  /**
106
106
  * Normalize event key - strip UI: prefix if present.
107
107
  */
@@ -116,6 +116,12 @@ interface ProcessEventOptions {
116
116
  trait: TraitDefinition;
117
117
  /** Event key to process */
118
118
  eventKey: string;
119
+ /**
120
+ * V4 dual-carry id sibling of `eventKey` — the id of the fired event,
121
+ * when known. Threaded to `findMatchingTransitions` for id-primary
122
+ * matching; absent means name-only dispatch (legacy).
123
+ */
124
+ eventId?: EventId;
119
125
  /** Event payload */
120
126
  payload?: EventPayload;
121
127
  /** Entity data for binding resolution */
@@ -179,6 +185,15 @@ interface ProcessEventOptions {
179
185
  declare function processEvent(options: ProcessEventOptions): TransitionResult;
180
186
  declare class StateMachineManager {
181
187
  private traits;
188
+ /**
189
+ * V4 identity index: trait id → trait name. Populated for traits that
190
+ * carry an `id` (ledger-backed schemas). Lets callers resolve a trait's
191
+ * state by its stable id, which survives a mid-session rename — the
192
+ * name-keyed maps are re-pointed on rename via {@link renameTrait}, but
193
+ * an id holder never has to observe the rename at all. Empty for legacy
194
+ * id-free schemas, where every lookup stays name-keyed (unchanged).
195
+ */
196
+ private traitIdToName;
182
197
  /**
183
198
  * Per-trait call-site config, surfaced to guard expressions so
184
199
  * `@config.X` resolves at runtime. Populated by the orbital's
@@ -217,6 +232,26 @@ declare class StateMachineManager {
217
232
  * Add a trait to the manager.
218
233
  */
219
234
  addTrait(trait: TraitDefinition): void;
235
+ /**
236
+ * Resolve a trait by its V4 id. Returns undefined when no trait carries
237
+ * that id (legacy schema, or unknown id). Exact-match only — no name
238
+ * similarity.
239
+ */
240
+ getTraitById(traitId: string): TraitDefinition | undefined;
241
+ /**
242
+ * Get a trait's current state by its V4 id (id-first lookup). Falls back
243
+ * to `undefined` when the id is unknown. The id survives a rename, so a
244
+ * holder of the id reads the right state without ever seeing the new name.
245
+ */
246
+ getStateById(traitId: string, entityId?: string): TraitState | undefined;
247
+ /**
248
+ * Apply a mid-session trait rename: re-point the name-keyed maps from
249
+ * `oldName` to `newName`, preserving live state, queues, and the id
250
+ * index. A no-op when the trait isn't registered under `oldName`. This
251
+ * is the interpreter-side of a ledger `curName` edit for the trait's own
252
+ * name-keyed storage; id-keyed references need no update.
253
+ */
254
+ renameTrait(oldName: string, newName: string): void;
220
255
  /**
221
256
  * Bind the call-site config for a trait so guard `@config.X`
222
257
  * resolves at runtime. Typically called by the orbital
@@ -256,7 +291,7 @@ declare class StateMachineManager {
256
291
  /**
257
292
  * Check if a trait can handle an event from its current state.
258
293
  */
259
- canHandleEvent(traitName: string, eventKey: string, entityId?: string): boolean;
294
+ canHandleEvent(traitName: string, eventKey: string, entityId?: string, eventId?: EventId): boolean;
260
295
  /**
261
296
  * Send an event to all traits.
262
297
  *
@@ -267,9 +302,13 @@ declare class StateMachineManager {
267
302
  * `@entity.X` see prior step writes — required for [runtime] entities
268
303
  * that have no persistence row to reload.
269
304
  *
305
+ * `eventId` is the V4 dual-carry id sibling of `eventKey` (see
306
+ * {@link ProcessEventOptions.eventId}) — additive and optional, threaded
307
+ * through to `processEvent` for id-primary transition matching.
308
+ *
270
309
  * @returns Array of transition results (one per trait that had a matching transition)
271
310
  */
272
- sendEvent(eventKey: string, payload?: EventPayload, entityData?: EntityRow, entityByTrait?: Record<string, EntityRow>): Array<{
311
+ sendEvent(eventKey: string, payload?: EventPayload, entityData?: EntityRow, entityByTrait?: Record<string, EntityRow>, eventId?: EventId): Array<{
273
312
  traitName: string;
274
313
  result: TransitionResult;
275
314
  }>;
@@ -280,7 +319,7 @@ declare class StateMachineManager {
280
319
  * trait to process them sequentially (actor-model guarantee: one event
281
320
  * at a time per trait, effects fully awaited before the next event).
282
321
  */
283
- enqueueEvent(eventKey: string, payload?: EventPayload, entityData?: EntityRow, entityByTrait?: Record<string, EntityRow>): void;
322
+ enqueueEvent(eventKey: string, payload?: EventPayload, entityData?: EntityRow, entityByTrait?: Record<string, EntityRow>, eventId?: EventId): void;
284
323
  /**
285
324
  * Drain a single (trait, entity) pair's event queue, processing
286
325
  * events sequentially. Pass `entityId` to drain a specific entity
@@ -358,17 +397,6 @@ interface SubstrateServices {
358
397
  declare function collectDeclaredConfigDefaults(trait: {
359
398
  config?: DeclaredTraitConfig;
360
399
  } | undefined): TraitConfig | undefined;
361
- /**
362
- * Convert a call-site config map into plain runtime values.
363
- *
364
- * A `CallSiteConfig` may contain either plain wiring values
365
- * (`TraitConfigValue`) or annotated `ConfigFieldDeclaration` objects
366
- * (`{ type, default, label, ... }`). The runtime binding context expects
367
- * only values, so this helper extracts `.default` from declarations and
368
- * passes plain values through unchanged. Entries that are not recognized as
369
- * declarations by `isCallSiteConfigDeclaration` are returned as-is.
370
- */
371
- declare function normalizeCallSiteConfigToValues(config: CallSiteConfig | undefined): TraitConfig | undefined;
372
400
  /**
373
401
  * Walk an entity's `fields` array and return a flat `{ fieldName: default, … }`
374
402
  * map. Seeds the `@entity` binding context with declared field defaults before
@@ -909,6 +937,12 @@ interface RegisteredOrbital {
909
937
  */
910
938
  interface OrbitalEventRequest {
911
939
  event: string;
940
+ /**
941
+ * V4 dual-carry id sibling of `event` — the fired event's id, when known
942
+ * (e.g. threaded from a `listens[].triggersId`). Optional; absent means
943
+ * the state machine dispatches by name only (legacy).
944
+ */
945
+ eventId?: EventId;
912
946
  payload?: EventPayload;
913
947
  entityId?: string;
914
948
  /** User context for @user bindings (from Firebase auth) */
@@ -1063,6 +1097,16 @@ declare class OrbitalServerRuntime {
1063
1097
  private substrateHandlers;
1064
1098
  private substrateHandlersPromise;
1065
1099
  private resolvedSchema;
1100
+ /**
1101
+ * Trait name -> resolved `TraitConfig`, computed once per `register()` via
1102
+ * `buildResolvedTraitConfigs` (`@almadar/core`). An embedded sub-trait's
1103
+ * OWN declared config schema (`registered.traits` / `collectDeclaredConfigDefaults`)
1104
+ * carries `@config.X` forwards verbatim — this map chains those through to
1105
+ * the trait that actually embeds it (see `embedded-trait-config.ts` for the
1106
+ * full rationale). Used as a fallback layer in `buildBindingContext` behind
1107
+ * `declaredDefaults` and ahead of `callSiteOverride`.
1108
+ */
1109
+ private resolvedTraitConfigs;
1066
1110
  constructor(config?: OrbitalServerRuntimeConfig);
1067
1111
  /**
1068
1112
  * Lazily wire the OS-level effect handlers (fs/net/child_process), merging
@@ -1311,4 +1355,4 @@ declare class OrbitalServerRuntime {
1311
1355
  */
1312
1356
  declare function createOrbitalServerRuntime(config?: OrbitalServerRuntimeConfig): OrbitalServerRuntime;
1313
1357
 
1314
- export { normalizeCallSiteConfigToValues as A, normalizeEventKey as B, parseNamespacedEvent as C, preprocessSchema as D, type EntitySharingMap as E, processEvent as F, type ClientEffectTuple as G, type ClientNavigateTuple as H, type ImportChainLike as I, type ClientNotifyTuple as J, type ClientRenderUITuple as K, type LoadResult as L, type EffectResult as M, type LoaderConfig as N, type OrbitalEventRequest as O, type PersistenceAdapter as P, OrbitalServerRuntime as Q, type RegisteredOrbital as R, type SchemaLoader as S, type RuntimeTraitTick as T, type UnifiedLoaderOptions as U, createOrbitalServerRuntime as V, type LoadedSchema as a, type LoadedOrbital as b, EventBus as c, type EventNamespaceMap as d, InMemoryPersistence as e, type OrbitalEventResponse as f, type OrbitalServerRuntimeConfig as g, type PreprocessOptions as h, type PreprocessResult as i, type PreprocessedSchema as j, type ProcessEventOptions as k, type RuntimeOrbital as l, type RuntimeOrbitalSchema as m, type RuntimeTrait as n, StateMachineManager as o, collectDeclaredConfigDefaults as p, collectDeclaredEntityDefaults as q, createInitialTraitState as r, findInitialState as s, findTransition as t, getIsolatedCollectionName as u, getNamespacedEvent as v, isBrowser as w, isElectron as x, isNamespacedEvent as y, isNode as z };
1358
+ export { normalizeEventKey as A, parseNamespacedEvent as B, preprocessSchema as C, processEvent as D, type EntitySharingMap as E, type ClientEffectTuple as F, type ClientNavigateTuple as G, type ClientNotifyTuple as H, type ImportChainLike as I, type ClientRenderUITuple as J, type EffectResult as K, type LoadResult as L, type LoaderConfig as M, OrbitalServerRuntime as N, type OrbitalEventRequest as O, type PersistenceAdapter as P, type RuntimeTraitTick as Q, type RegisteredOrbital as R, type SchemaLoader as S, createOrbitalServerRuntime as T, type UnifiedLoaderOptions as U, type LoadedSchema as a, type LoadedOrbital as b, EventBus as c, type EventNamespaceMap as d, InMemoryPersistence as e, type OrbitalEventResponse as f, type OrbitalServerRuntimeConfig as g, type PreprocessOptions as h, type PreprocessResult as i, type PreprocessedSchema as j, type ProcessEventOptions as k, type RuntimeOrbital as l, type RuntimeOrbitalSchema as m, type RuntimeTrait as n, StateMachineManager as o, collectDeclaredConfigDefaults as p, collectDeclaredEntityDefaults as q, createInitialTraitState as r, findInitialState as s, findTransition as t, getIsolatedCollectionName as u, getNamespacedEvent as v, isBrowser as w, isElectron as x, isNamespacedEvent as y, isNode as z };
@@ -1,4 +1,4 @@
1
1
  import 'express';
2
- export { G as ClientEffectTuple, H as ClientNavigateTuple, J as ClientNotifyTuple, K as ClientRenderUITuple, M as EffectResult, e as InMemoryPersistence, N as LoaderConfig, O as OrbitalEventRequest, f as OrbitalEventResponse, Q as OrbitalServerRuntime, g as OrbitalServerRuntimeConfig, P as PersistenceAdapter, R as RegisteredOrbital, l as RuntimeOrbital, m as RuntimeOrbitalSchema, n as RuntimeTrait, T as RuntimeTraitTick, p as collectDeclaredConfigDefaults, V as createOrbitalServerRuntime } from './OrbitalServerRuntime-DpAwIrmv.js';
3
- import './types-D-9feVsj.js';
2
+ export { F as ClientEffectTuple, G as ClientNavigateTuple, H as ClientNotifyTuple, J as ClientRenderUITuple, K as EffectResult, e as InMemoryPersistence, M as LoaderConfig, O as OrbitalEventRequest, f as OrbitalEventResponse, N as OrbitalServerRuntime, g as OrbitalServerRuntimeConfig, P as PersistenceAdapter, R as RegisteredOrbital, l as RuntimeOrbital, m as RuntimeOrbitalSchema, n as RuntimeTrait, Q as RuntimeTraitTick, p as collectDeclaredConfigDefaults, T as createOrbitalServerRuntime } from './OrbitalServerRuntime-BrHSXDfp.js';
3
+ import './types-C8RsO0xa.js';
4
4
  import '@almadar/core';