@almadar/runtime 6.22.0 → 6.23.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,7 +1,6 @@
1
1
  import { Router } from 'express';
2
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-BA7GoDni.js';
3
3
  import { EventPayload, EntityRow, DeclaredTraitConfig, TraitConfig, Entity, OrbitalSchema, Orbital, Trait, PatternConfig, ResolvedPatternProps, SExpr, BusEventSource, OrbitalDefinition, TraitTick } from '@almadar/core';
4
- import { P as PersistenceAdapter } from './PersistenceAdapter-B6dQCbbU.js';
5
4
 
6
5
  /**
7
6
  * EventBus - Platform-Agnostic Pub/Sub Implementation
@@ -605,7 +604,7 @@ interface EntitySharingMap {
605
604
  /** The entity name */
606
605
  entityName: string;
607
606
  /** Persistence type */
608
- persistence: "persistent" | "runtime" | "singleton";
607
+ persistence: "persistent" | "runtime";
609
608
  /** Whether this entity is shared with other orbitals */
610
609
  isShared: boolean;
611
610
  /** Source orbital if imported */
@@ -680,7 +679,6 @@ declare function preprocessSchema(schema: OrbitalSchema, options: PreprocessOpti
680
679
  *
681
680
  * - `persistent` entities share the same collection
682
681
  * - `runtime` entities get isolated collections per orbital
683
- * - `singleton` entities share a single-record collection
684
682
  */
685
683
  declare function getIsolatedCollectionName(orbitalName: string, entitySharing: EntitySharingMap): string;
686
684
  /**
@@ -700,6 +698,69 @@ declare function parseNamespacedEvent(eventName: string): {
700
698
  event: string;
701
699
  };
702
700
 
701
+ /**
702
+ * PersistenceAdapter — the storage contract for runtime effect handlers.
703
+ *
704
+ * The server-side runtime and the in-browser mock runtime both invoke
705
+ * `fetch` / `persist` / `ref` / `deref` / `swap!` effects against an
706
+ * implementation of this interface. Extracted from
707
+ * `OrbitalServerRuntime.ts` so it can be imported by browser code that
708
+ * cannot depend on the server module (which pulls in express).
709
+ *
710
+ * @packageDocumentation
711
+ */
712
+
713
+ /**
714
+ * Storage contract for CRUD operations on runtime entity rows.
715
+ *
716
+ * Implementations:
717
+ * - `InMemoryPersistence` (this file) — simple Map-backed store, used by
718
+ * the browser mock runtime and as the default when an adapter is not
719
+ * supplied to `OrbitalServerRuntime`.
720
+ * - `MockPersistenceAdapter` — in-memory with faker-generated seed data
721
+ * for realistic preview content.
722
+ * - Consumer-provided (e.g. Firestore, Postgres) for production servers.
723
+ */
724
+ interface PersistenceAdapter {
725
+ create(entityType: string, data: EntityRow): Promise<{
726
+ id: string;
727
+ }>;
728
+ update(entityType: string, id: string, data: EntityRow): Promise<void>;
729
+ delete(entityType: string, id: string): Promise<void>;
730
+ getById(entityType: string, id: string): Promise<EntityRow | null>;
731
+ list(entityType: string): Promise<EntityRow[]>;
732
+ }
733
+ /**
734
+ * Simple in-memory persistence for dev/testing and offline previews.
735
+ * Keys each entity collection by type, rows by generated string id.
736
+ */
737
+ declare class InMemoryPersistence implements PersistenceAdapter {
738
+ private data;
739
+ private idCounter;
740
+ /**
741
+ * Seed the store with pre-existing rows.
742
+ *
743
+ * Accepts either a plain `Record<entityType, EntityRow[]>` or an iterable
744
+ * of `[entityType, EntityRow[]]` entries. Rows without an `id` get one
745
+ * generated at insert time; rows with an `id` keep it (so re-seeding
746
+ * after a schema rebuild preserves identities used in render bindings).
747
+ */
748
+ seed(seedData: Record<string, EntityRow[]> | Iterable<[string, EntityRow[]]>): void;
749
+ create(entityType: string, data: EntityRow): Promise<{
750
+ id: string;
751
+ }>;
752
+ update(entityType: string, id: string, data: EntityRow): Promise<void>;
753
+ delete(entityType: string, id: string): Promise<void>;
754
+ getById(entityType: string, id: string): Promise<EntityRow | null>;
755
+ list(entityType: string): Promise<EntityRow[]>;
756
+ /**
757
+ * Snapshot the entire store as a plain object (entityType → rows).
758
+ * Useful for feeding a fresh render-time binding layer with the
759
+ * current persistence view.
760
+ */
761
+ snapshot(): Record<string, EntityRow[]>;
762
+ }
763
+
703
764
  /**
704
765
  * OrbitalServerRuntime - Dynamic Server-Side Orbital Execution
705
766
  *
@@ -926,11 +987,6 @@ interface OrbitalServerRuntimeConfig {
926
987
  * Default: true
927
988
  */
928
989
  namespaceEvents?: boolean;
929
- /**
930
- * Root directory for `persistence: "local"` entities.
931
- * Default: ~/.orb/data/
932
- */
933
- localStorageRoot?: string;
934
990
  /**
935
991
  * Additional fields to spread onto every EvaluationContext.
936
992
  * Use this to inject module contexts (e.g., { agent: AgentContext }).
@@ -953,7 +1009,6 @@ declare class OrbitalServerRuntime {
953
1009
  private eventNamespaceMap;
954
1010
  private osHandlers;
955
1011
  private osHandlersPromise;
956
- private localPersistence;
957
1012
  private resolvedSchema;
958
1013
  constructor(config?: OrbitalServerRuntimeConfig);
959
1014
  /**
@@ -1197,4 +1252,4 @@ declare class OrbitalServerRuntime {
1197
1252
  */
1198
1253
  declare function createOrbitalServerRuntime(config?: OrbitalServerRuntimeConfig): OrbitalServerRuntime;
1199
1254
 
1200
- 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, OrbitalServerRuntime as K, type LoadResult as L, type RuntimeTraitTick as M, createOrbitalServerRuntime as N, type OrbitalEventRequest as O, type PreprocessOptions 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, type OrbitalEventResponse as e, type OrbitalServerRuntimeConfig as f, type PreprocessResult as g, type PreprocessedSchema as h, type ProcessEventOptions as i, type RuntimeOrbital as j, type RuntimeOrbitalSchema as k, type RuntimeTrait as l, StateMachineManager as m, collectDeclaredConfigDefaults as n, collectDeclaredEntityDefaults 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 };
1255
+ 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,5 +1,4 @@
1
1
  import 'express';
2
- export { C as ClientEffectTuple, D as ClientNavigateTuple, F as ClientNotifyTuple, G as ClientRenderUITuple, H as EffectResult, J as LoaderConfig, O as OrbitalEventRequest, e as OrbitalEventResponse, K as OrbitalServerRuntime, f as OrbitalServerRuntimeConfig, R as RegisteredOrbital, j as RuntimeOrbital, k as RuntimeOrbitalSchema, l as RuntimeTrait, M as RuntimeTraitTick, n as collectDeclaredConfigDefaults, N as createOrbitalServerRuntime } from './OrbitalServerRuntime-CO0rEx3p.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-h0NCwFuc.js';
3
3
  import './types-BA7GoDni.js';
4
4
  import '@almadar/core';
5
- export { I as InMemoryPersistence, P as PersistenceAdapter } from './PersistenceAdapter-B6dQCbbU.js';
@@ -1,5 +1,5 @@
1
- import { createTickScheduler, EventBus, createUnifiedLoader, MockPersistenceAdapter, InMemoryPersistence, preprocessSchema, StateMachineManager, parseDurationString, createContextFromBindings, validateEventPayload, formatPayloadValidationError, collectDeclaredConfigDefaults, collectDeclaredEntityDefaults, EffectExecutor } from './chunk-M7HMVDYF.js';
2
- export { InMemoryPersistence, collectDeclaredConfigDefaults } from './chunk-M7HMVDYF.js';
1
+ import { createTickScheduler, EventBus, createUnifiedLoader, MockPersistenceAdapter, InMemoryPersistence, preprocessSchema, StateMachineManager, parseDurationString, createContextFromBindings, validateEventPayload, formatPayloadValidationError, collectDeclaredConfigDefaults, collectDeclaredEntityDefaults, EffectExecutor } from './chunk-4SX6WJKY.js';
2
+ export { InMemoryPersistence, collectDeclaredConfigDefaults } from './chunk-4SX6WJKY.js';
3
3
  import { isValidCronExpression } from './chunk-U4PL237A.js';
4
4
  import './chunk-PZ5AY32C.js';
5
5
  import { createLogger } from '@almadar/logger';
@@ -25,7 +25,6 @@ function nodeRequire(modulePath) {
25
25
  }
26
26
  return _resolvedNodeRequire(modulePath);
27
27
  }
28
- var _nodeRequireExt = import.meta.url.endsWith(".ts") ? ".ts" : ".js";
29
28
  var effectLog = createLogger("almadar:runtime:effects");
30
29
  var busLog = createLogger("almadar:runtime:bus");
31
30
  var renderLog = createLogger("almadar:runtime:render-ui");
@@ -70,7 +69,6 @@ var OrbitalServerRuntime = class {
70
69
  eventNamespaceMap = {};
71
70
  osHandlers = null;
72
71
  osHandlersPromise = null;
73
- localPersistence = null;
74
72
  resolvedSchema = null;
75
73
  constructor(config = {}) {
76
74
  this.config = {
@@ -102,10 +100,6 @@ var OrbitalServerRuntime = class {
102
100
  } else {
103
101
  this.persistence = config.persistence || new InMemoryPersistence();
104
102
  }
105
- if (config.localStorageRoot && isNodeEnv()) {
106
- const { LocalPersistenceAdapter } = nodeRequire(`./LocalPersistenceAdapter${_nodeRequireExt}`);
107
- this.localPersistence = new LocalPersistenceAdapter(config.localStorageRoot);
108
- }
109
103
  this.osHandlers = { handlers: {}, cleanup: () => {
110
104
  } };
111
105
  }