@almadar/runtime 6.9.3 → 6.9.5

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,7 +1,6 @@
1
- import * as _almadar_core from '@almadar/core';
2
- import { EventPayload, EntityRow, OrbitalSchema, Orbital, Trait, PatternConfig, ResolvedPatternProps, SExpr, BusEventSource, OrbitalDefinition, Entity, TraitConfig, TraitTick } from '@almadar/core';
3
1
  import { Router } from 'express';
4
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-cuy5gd29.js';
3
+ import { EventPayload, EntityRow, DeclaredTraitConfig, TraitConfig, OrbitalSchema, Orbital, Trait, PatternConfig, ResolvedPatternProps, SExpr, BusEventSource, OrbitalDefinition, Entity, TraitTick } from '@almadar/core';
5
4
  import { P as PersistenceAdapter } from './PersistenceAdapter-B6dQCbbU.js';
6
5
 
7
6
  /**
@@ -310,6 +309,23 @@ declare class StateMachineManager {
310
309
  resetAll(): void;
311
310
  }
312
311
 
312
+ /**
313
+ * Pure config-default extraction — kept OUT of `OrbitalServerRuntime.ts` so the
314
+ * package index can re-export it without dragging that module's node-only
315
+ * imports (`module`/`createRequire`, the external loader) into a browser bundle.
316
+ * This file has zero node dependencies (types only, from `@almadar/core`).
317
+ */
318
+
319
+ /**
320
+ * Walk a trait's declared `config { }` schema and return the flat
321
+ * `{ key: default, ... }` map. Seeds `@config.X` binding context with the
322
+ * atom's own declared defaults before any call-site override is applied.
323
+ * Mirrors the compiled path's `DEFAULT_<TRAIT>_CONFIG` constant (backend.rs).
324
+ */
325
+ declare function collectDeclaredConfigDefaults(trait: {
326
+ config?: DeclaredTraitConfig;
327
+ } | undefined): TraitConfig | undefined;
328
+
313
329
  /**
314
330
  * External Orbital Loader
315
331
  *
@@ -674,6 +690,41 @@ declare function parseNamespacedEvent(eventName: string): {
674
690
  event: string;
675
691
  };
676
692
 
693
+ /**
694
+ * OrbitalServerRuntime - Dynamic Server-Side Orbital Execution
695
+ *
696
+ * This runtime takes an OrbitalSchema and dynamically:
697
+ * 1. Registers all orbitals and their traits
698
+ * 2. Creates Express routes for trait communication
699
+ * 3. Executes state machines server-side
700
+ * 4. Handles cross-orbital event propagation
701
+ *
702
+ * This is the "interpreted" mode - no compilation needed.
703
+ * The compiler generates equivalent static code for production.
704
+ *
705
+ * @example
706
+ * ```typescript
707
+ * import { OrbitalServerRuntime } from '@kflow-builder/shared/runtime';
708
+ * import express from 'express';
709
+ *
710
+ * const app = express();
711
+ * const runtime = new OrbitalServerRuntime();
712
+ *
713
+ * // Register schema (can be loaded from file, API, etc.)
714
+ * runtime.register(orbitalSchema);
715
+ *
716
+ * // Mount orbital routes
717
+ * app.use('/api/orbitals', runtime.router());
718
+ *
719
+ * // Client can now:
720
+ * // POST /api/orbitals/:orbital/events - Send event to orbital
721
+ * // GET /api/orbitals/:orbital/state - Get current state
722
+ * // GET /api/orbitals - List registered orbitals
723
+ * ```
724
+ *
725
+ * @packageDocumentation
726
+ */
727
+
677
728
  /**
678
729
  * Client-side effect tuple shipped in `OrbitalEventResponse.clientEffects`.
679
730
  * Restricted to the three effect kinds the client knows how to apply to the
@@ -878,49 +929,6 @@ interface OrbitalServerRuntimeConfig {
878
929
  contextExtensions?: EvaluationContextExtensions;
879
930
  }
880
931
 
881
- /**
882
- * Check whether a schema needs preprocessing (has `uses` declarations or
883
- * un-inlined cross-orbital trait references).
884
- *
885
- * Cross-orbital refs are trait entries like
886
- * `{ ref: "Modal.traits.ModalRecordModal", ... }` with no inline
887
- * `stateMachine`. If these aren't resolved before `register()` runs, the
888
- * trait binder produces an empty state machine and all interactions
889
- * targeting the trait are silently dropped.
890
- */
891
- /**
892
- * Walk a trait's DECLARED config schema (`{ icon: { type, default }, ... }`)
893
- * and collect a flat `{ icon: <default>, ... }` map of just the default
894
- * values. Used to seed the `@config.X` binding context with the atom's
895
- * own declared defaults before any call-site override is applied. Mirrors
896
- * the compiled path's `DEFAULT_<TRAIT>_CONFIG` constant emitted by
897
- * backend.rs's Solution-1 plumbing.
898
- *
899
- * Returns `undefined` when the trait has no config schema or none of its
900
- * fields declare a default — keeps the caller's existing fast-path.
901
- */
902
- /**
903
- * Structural shape that both `@almadar/core`'s `Trait` and
904
- * `ResolvedTrait` satisfy: a `config?` map keyed by field name whose
905
- * values either carry a `default` (the declared-schema form loaded
906
- * from `.orb`) or are bare values (the runtime-resolved form).
907
- *
908
- * Widening to a structural parameter lets callers from the resolved
909
- * side (e.g., `@almadar/ui`'s `useTraitStateMachine`) pass their own
910
- * `ResolvedTrait` without an `as unknown as` cast.
911
- */
912
- /**
913
- * Read the `default` from each field of a trait's declared
914
- * `config { }` schema and return the flat `{ key: default, ... }`
915
- * map. Used to seed `@config.X` binding context with the atom's
916
- * own declared defaults before any call-site override is applied.
917
- *
918
- * Mirrors the compiled path's `DEFAULT_<TRAIT>_CONFIG` constant
919
- * emitted by `backend.rs` Solution-1.
920
- */
921
- declare function collectDeclaredConfigDefaults(trait: {
922
- config?: _almadar_core.DeclaredTraitConfig;
923
- } | undefined): TraitConfig | undefined;
924
932
  declare class OrbitalServerRuntime {
925
933
  protected orbitals: Map<string, RegisteredOrbital>;
926
934
  private eventBus;
@@ -933,9 +941,19 @@ declare class OrbitalServerRuntime {
933
941
  private entitySharingMap;
934
942
  private eventNamespaceMap;
935
943
  private osHandlers;
944
+ private osHandlersPromise;
936
945
  private localPersistence;
937
946
  private resolvedSchema;
938
947
  constructor(config?: OrbitalServerRuntimeConfig);
948
+ /**
949
+ * Lazily wire the OS-level effect handlers (fs/net/child_process), merging
950
+ * them UNDER any user-provided handlers. Deferred out of the constructor
951
+ * because `./createOsHandlers.js` is ESM and `require()`-ing it from a
952
+ * `type: module` package throws ERR_REQUIRE_ESM — so it is dynamic-import()ed
953
+ * here on the first event. Node-only, idempotent (single shared load), and a
954
+ * no-op in the browser (the import never runs behind the isNodeEnv guard).
955
+ */
956
+ private ensureOsHandlers;
939
957
  /**
940
958
  * Lazily construct a default loader when the caller didn't provide one
941
959
  * but `register()` needs to preprocess. Looks for `@almadar/std` in the
@@ -1,5 +1,5 @@
1
- import '@almadar/core';
2
1
  import 'express';
3
- export { C as ClientEffectTuple, B as ClientNavigateTuple, D as ClientNotifyTuple, F as ClientRenderUITuple, G as EffectResult, H as LoaderConfig, O as OrbitalEventRequest, e as OrbitalEventResponse, J as OrbitalServerRuntime, f as OrbitalServerRuntimeConfig, R as RegisteredOrbital, j as RuntimeOrbital, k as RuntimeOrbitalSchema, l as RuntimeTrait, K as RuntimeTraitTick, n as collectDeclaredConfigDefaults, M as createOrbitalServerRuntime } from './OrbitalServerRuntime-CvWqVb68.js';
2
+ export { C as ClientEffectTuple, B as ClientNavigateTuple, D as ClientNotifyTuple, F as ClientRenderUITuple, G as EffectResult, H as LoaderConfig, O as OrbitalEventRequest, e as OrbitalEventResponse, J as OrbitalServerRuntime, f as OrbitalServerRuntimeConfig, R as RegisteredOrbital, j as RuntimeOrbital, k as RuntimeOrbitalSchema, l as RuntimeTrait, K as RuntimeTraitTick, n as collectDeclaredConfigDefaults, M as createOrbitalServerRuntime } from './OrbitalServerRuntime-CpKcmAUY.js';
4
3
  import './types-cuy5gd29.js';
4
+ import '@almadar/core';
5
5
  export { I as InMemoryPersistence, P as PersistenceAdapter } from './PersistenceAdapter-B6dQCbbU.js';