@almadar/runtime 5.4.0 → 5.5.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-SmmabGZk.js';
3
- import { EventPayload, EntityRow, OrbitalSchema, Orbital, Trait, OrbitalDefinition, Entity, TraitConfig, TraitTick } from '@almadar/core';
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-ByLpy6yj.js';
3
+ import { EventPayload, EntityRow, OrbitalSchema, Orbital, Trait, PatternConfig, ResolvedPatternProps, SExpr, BusEventSource, OrbitalDefinition, Entity, TraitConfig, TraitTick } from '@almadar/core';
4
4
 
5
5
  /**
6
6
  * EventBus - Platform-Agnostic Pub/Sub Implementation
@@ -797,6 +797,34 @@ declare class InMemoryPersistence implements PersistenceAdapter {
797
797
  * @packageDocumentation
798
798
  */
799
799
 
800
+ /**
801
+ * Client-side effect tuple shipped in `OrbitalEventResponse.clientEffects`.
802
+ * Restricted to the three effect kinds the client knows how to apply to the
803
+ * UI: render-ui (slot mutation), navigate (route change), notify (toast).
804
+ * Server-only effects (persist, set, fetch, ...) execute on the server and
805
+ * surface their results via `effectResults` and `emittedEvents`, not here.
806
+ *
807
+ * Shape note: the wire form is broader than `RenderUIEffect` /
808
+ * `NavigateEffect` / `NotifyEffect` from `@almadar/core/types/effect.ts` in
809
+ * two places — the runtime appends an interpolated `props` object plus an
810
+ * optional `priority` slot to render-ui (slot 4 + 5), and `navigate` /
811
+ * `notify` may surface their optional argument as `undefined` rather than
812
+ * absent. The local union spells those variants out explicitly so consumers
813
+ * (ServerBridge.tsx parser, debugger inspector) get accurate completions
814
+ * instead of `unknown[]`.
815
+ *
816
+ * `slot` is a plain `string` in this wire shape (not `UISlot`'s literal
817
+ * union) because the runtime forwards the raw string from the trait's
818
+ * `(render-ui slot ...)` SExpr without re-validating against the registry —
819
+ * registry validation lives in `orbital validate` / `lolo` parse, not here.
820
+ */
821
+ type ClientRenderUITuple = ['render-ui', string, PatternConfig | null] | ['render-ui', string, PatternConfig | null, ResolvedPatternProps] | ['render-ui', string, PatternConfig | null, ResolvedPatternProps | undefined, number | undefined];
822
+ type ClientNavigateTuple = ['navigate', string] | ['navigate', string, Record<string, string> | undefined];
823
+ type ClientNotifyTuple = ['notify', string, string | SExpr | undefined] | ['notify', string, string | SExpr | undefined, {
824
+ type?: string;
825
+ }];
826
+ type ClientEffectTuple = ClientRenderUITuple | ClientNavigateTuple | ClientNotifyTuple;
827
+
800
828
  /** @deprecated Use OrbitalSchema from @almadar/core */
801
829
  type RuntimeOrbitalSchema = OrbitalSchema;
802
830
  /** @deprecated Use OrbitalDefinition from @almadar/core */
@@ -852,13 +880,20 @@ interface OrbitalEventResponse {
852
880
  * typed against `@almadar/core`'s `EventPayload` — the recursive record of
853
881
  * primitive + nested EventPayload values the state machine already uses
854
882
  * internally. Kept as the single source of truth for emit-payload shape.
883
+ *
884
+ * Each entry carries a `source: BusEventSource` so the client-side
885
+ * ServerBridge can re-broadcast on the qualified `UI:Orbital.Trait.EVENT`
886
+ * bus key. Without source the re-broadcast skips the entry and downstream
887
+ * listeners (e.g. ContactBrowse waiting for ContactLoaded after a fetch)
888
+ * never fire — the dashboard-layout that ContactLoaded renders disappears.
855
889
  */
856
890
  emittedEvents: Array<{
857
891
  event: string;
858
892
  payload?: EventPayload;
893
+ source?: BusEventSource;
859
894
  }>;
860
895
  /** Client-side effects to execute (render-ui, navigate, notify) */
861
- clientEffects?: Array<unknown>;
896
+ clientEffects?: ClientEffectTuple[];
862
897
  /**
863
898
  * Same effects as `clientEffects`, paired with the producing trait name.
864
899
  * Consumers that need per-trait attribution (e.g. `<TraitFrame>` resolving
@@ -869,7 +904,7 @@ interface OrbitalEventResponse {
869
904
  */
870
905
  clientEffectsByTrait?: Array<{
871
906
  traitName: string;
872
- effect: unknown[];
907
+ effect: ClientEffectTuple;
873
908
  }>;
874
909
  /** Results from server-side effects (persist, call-service, set) */
875
910
  effectResults?: EffectResult[];
@@ -1196,4 +1231,4 @@ declare class OrbitalServerRuntime {
1196
1231
  */
1197
1232
  declare function createOrbitalServerRuntime(config?: OrbitalServerRuntimeConfig): OrbitalServerRuntime;
1198
1233
 
1199
- export { preprocessSchema as A, processEvent as B, type EffectResult as C, type LoaderConfig as D, type EntitySharingMap as E, LocalPersistenceAdapter as F, OrbitalServerRuntime as G, type RuntimeTraitTick as H, type ImportChainLike as I, createOrbitalServerRuntime as J, type LoadResult as L, type OrbitalEventRequest as O, type PersistenceAdapter as P, type RegisteredOrbital as R, type SchemaLoader as S, 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, createInitialTraitState as p, findInitialState as q, findTransition as r, getIsolatedCollectionName as s, getNamespacedEvent as t, isBrowser as u, isElectron as v, isNamespacedEvent as w, isNode as x, normalizeEventKey as y, parseNamespacedEvent as z };
1234
+ export { preprocessSchema as A, processEvent as B, type ClientEffectTuple as C, type ClientNavigateTuple as D, type EntitySharingMap as E, type ClientNotifyTuple as F, type ClientRenderUITuple as G, type EffectResult as H, type ImportChainLike as I, type LoaderConfig as J, LocalPersistenceAdapter as K, type LoadResult as L, OrbitalServerRuntime as M, type RuntimeTraitTick as N, type OrbitalEventRequest as O, type PersistenceAdapter as P, createOrbitalServerRuntime as Q, type RegisteredOrbital as R, type SchemaLoader as S, 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, createInitialTraitState as p, findInitialState as q, findTransition as r, getIsolatedCollectionName as s, getNamespacedEvent as t, isBrowser as u, isElectron as v, isNamespacedEvent as w, isNode as x, normalizeEventKey as y, parseNamespacedEvent as z };
@@ -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-BrJ7m0hz.js';
3
- import './types-SmmabGZk.js';
2
+ export { C as ClientEffectTuple, D as ClientNavigateTuple, F as ClientNotifyTuple, G as ClientRenderUITuple, H as EffectResult, e as InMemoryPersistence, J as LoaderConfig, K as LocalPersistenceAdapter, O as OrbitalEventRequest, f as OrbitalEventResponse, M as OrbitalServerRuntime, g as OrbitalServerRuntimeConfig, P as PersistenceAdapter, R as RegisteredOrbital, l as RuntimeOrbital, m as RuntimeOrbitalSchema, n as RuntimeTrait, N as RuntimeTraitTick, Q as createOrbitalServerRuntime } from './OrbitalServerRuntime-BMOr7miw.js';
3
+ import './types-ByLpy6yj.js';
4
4
  import '@almadar/core';
@@ -1,5 +1,5 @@
1
- import { createLogger, EventBus, createUnifiedLoader, MockPersistenceAdapter, InMemoryPersistence, preprocessSchema, StateMachineManager, createContextFromBindings, validateEventPayload, formatPayloadValidationError, EffectExecutor } from './chunk-62BIUDUH.js';
2
- export { InMemoryPersistence } from './chunk-62BIUDUH.js';
1
+ import { createLogger, EventBus, createUnifiedLoader, MockPersistenceAdapter, InMemoryPersistence, preprocessSchema, StateMachineManager, createContextFromBindings, validateEventPayload, formatPayloadValidationError, EffectExecutor } from './chunk-TJKK3BLO.js';
2
+ export { InMemoryPersistence } from './chunk-TJKK3BLO.js';
3
3
  import './chunk-PZ5AY32C.js';
4
4
  import { Router } from 'express';
5
5
  import * as fs from 'fs';
@@ -362,6 +362,7 @@ function createOsHandlers(ctx) {
362
362
  var effectLog = createLogger("almadar:runtime:effects");
363
363
  var busLog = createLogger("almadar:runtime:bus");
364
364
  var renderLog = createLogger("almadar:runtime:render-ui");
365
+ var xOrbitalLog = createLogger("almadar:runtime:cross-orbital");
365
366
  function collectDeclaredConfigDefaults(trait) {
366
367
  if (!trait) return void 0;
367
368
  const schema = trait.config;
@@ -1128,6 +1129,14 @@ var OrbitalServerRuntime = class {
1128
1129
  }))
1129
1130
  )
1130
1131
  });
1132
+ xOrbitalLog.info("processOrbitalEvent:enter", {
1133
+ orbital: orbitalName,
1134
+ event: request.event,
1135
+ traitsInOrbital: registered.traits.map((t) => t.name).join(","),
1136
+ payloadActiveTraits: JSON.stringify(
1137
+ request.payload?.["_activeTraits"] ?? null
1138
+ )
1139
+ });
1131
1140
  const { event, payload, entityId, user } = request;
1132
1141
  const validationFailures = [];
1133
1142
  for (const trait of registered.traits) {
@@ -1240,13 +1249,19 @@ var OrbitalServerRuntime = class {
1240
1249
  trait: traitName
1241
1250
  };
1242
1251
  this.eventBus.emit(event, eventPayload, stamp);
1243
- emittedEvents.push({ event, payload: eventPayload });
1252
+ emittedEvents.push({ event, payload: eventPayload, source: stamp });
1244
1253
  effectLog.debug("emit:push", {
1245
1254
  event,
1246
1255
  cumulativeEmittedCount: emittedEvents.length,
1247
1256
  sourceTrait: stamp.trait,
1248
1257
  sourceOrbital: stamp.orbital
1249
1258
  });
1259
+ xOrbitalLog.info("emit:server", {
1260
+ event,
1261
+ sourceOrbital: stamp.orbital,
1262
+ sourceTrait: stamp.trait,
1263
+ dispatchOrbital: registered.schema.name
1264
+ });
1250
1265
  },
1251
1266
  set: async (targetId, field, value) => {
1252
1267
  const id = targetId || entityId;