@almadar/runtime 5.9.1 → 5.10.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.
@@ -713,6 +713,17 @@ interface RegisteredOrbital {
713
713
  configByTrait: Map<string, TraitConfig>;
714
714
  manager: StateMachineManager;
715
715
  entityData: Map<string, EntityRow>;
716
+ /**
717
+ * Last-fetched collection per entityType. Mirrors the compiled path's
718
+ * per-trait reducer `state.data[<EntityName>]`: the trait's `@entity`
719
+ * binding resolves from this cache so a filter narrows the rendered
720
+ * list across events. Without this, executeEffects re-reads the full
721
+ * persistence list on every event and clobbers the prior fetch's
722
+ * filtered subset. Populated by the fetch handler on success; seeded
723
+ * lazily from `persistence.list()` when a collection-scope binding is
724
+ * first read with no cache entry.
725
+ */
726
+ dataCache: Map<string, EntityRow | EntityRow[]>;
716
727
  }
717
728
  /**
718
729
  * Event sent from client to server
@@ -1,5 +1,5 @@
1
1
  import '@almadar/core';
2
2
  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-Bv8y7nIu.js';
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-VQBv8J8m.js';
4
4
  import './types-ByLpy6yj.js';
5
5
  export { I as InMemoryPersistence, P as PersistenceAdapter } from './PersistenceAdapter-B6dQCbbU.js';
@@ -1,4 +1,4 @@
1
- export { InMemoryPersistence, OrbitalServerRuntime, collectDeclaredConfigDefaults, createOrbitalServerRuntime } from './chunk-RONUCODN.js';
1
+ export { InMemoryPersistence, OrbitalServerRuntime, collectDeclaredConfigDefaults, createOrbitalServerRuntime } from './chunk-6W6XCOLH.js';
2
2
  import './chunk-PZ5AY32C.js';
3
3
  //# sourceMappingURL=OrbitalServerRuntime.js.map
4
4
  //# sourceMappingURL=OrbitalServerRuntime.js.map
@@ -288,7 +288,15 @@ function interpolateArray(value, ctx) {
288
288
  return value;
289
289
  }
290
290
  if (isSExpression(value)) {
291
- return evaluate(value, ctx);
291
+ const result = evaluate(value, ctx);
292
+ bindLog.info("sexpr:eval", {
293
+ operator: typeof value[0] === "string" ? value[0] : "<non-string>",
294
+ argCount: value.length - 1,
295
+ inputJson: JSON.stringify(value).slice(0, 300),
296
+ resultType: typeof result,
297
+ resultJson: typeof result === "object" && result !== null ? JSON.stringify(result).slice(0, 200) : String(result)
298
+ });
299
+ return result;
292
300
  }
293
301
  const mapped = [];
294
302
  let anyChanged = false;
@@ -988,12 +996,29 @@ var EffectExecutor = class {
988
996
  const { operator, args } = parsed;
989
997
  const isCompound = operator === "do" || operator === "when";
990
998
  const isSetPathForm = operator === "set" && args.length >= 2 && typeof args[0] === "string" && args[0].startsWith("@entity.");
999
+ const isFetchLike = (operator === "fetch" || operator === "ref" || operator === "deref" || operator === "os/watch-collection" || operator === "os/watch") && args.length >= 2 && args[1] !== null && typeof args[1] === "object" && !Array.isArray(args[1]);
991
1000
  let resolvedArgs;
992
1001
  if (isCompound) {
993
1002
  resolvedArgs = args;
994
1003
  } else if (isSetPathForm) {
995
1004
  const ctx = createContextFromBindings(this.bindings, this.strictBindings, this.contextExtensions);
996
1005
  resolvedArgs = [args[0], ...args.slice(1).map((a) => interpolateValue(a, ctx))];
1006
+ } else if (isFetchLike) {
1007
+ const ctx = createContextFromBindings(this.bindings, this.strictBindings, this.contextExtensions);
1008
+ const opts = args[1];
1009
+ const resolvedOpts = {
1010
+ ...opts.id !== void 0 && { id: interpolateValue(opts.id, ctx) },
1011
+ ...opts.filter !== void 0 && { filter: opts.filter },
1012
+ ...opts.limit !== void 0 && { limit: interpolateValue(opts.limit, ctx) },
1013
+ ...opts.offset !== void 0 && { offset: interpolateValue(opts.offset, ctx) },
1014
+ ...opts.include !== void 0 && { include: interpolateValue(opts.include, ctx) },
1015
+ ...opts.emit !== void 0 && { emit: interpolateValue(opts.emit, ctx) }
1016
+ };
1017
+ resolvedArgs = [
1018
+ interpolateValue(args[0], ctx),
1019
+ resolvedOpts,
1020
+ ...args.slice(2).map((a) => interpolateValue(a, ctx))
1021
+ ];
997
1022
  } else {
998
1023
  resolvedArgs = resolveArgs(args, this.bindings, this.strictBindings, this.contextExtensions);
999
1024
  }
@@ -3400,7 +3425,15 @@ async function preprocessSchema(schema, options) {
3400
3425
  // Preserve other fields
3401
3426
  exposes: resolvedOrbital.original.exposes,
3402
3427
  domainContext: resolvedOrbital.original.domainContext,
3403
- design: resolvedOrbital.original.design
3428
+ design: resolvedOrbital.original.design,
3429
+ // Gap #22: pass through auxiliary entities so OrbitalServerRuntime's
3430
+ // mock-seed branch registers SearchResult / FilterTarget / PagedItem
3431
+ // alongside the molecule's primary entity. Without this, an inlined
3432
+ // .orb that has `auxiliaryEntities` populated by the Rust inline
3433
+ // phase still loses them here, and `(set @entity.searchTerm ...)` /
3434
+ // `(fetch SearchResult ...)` from no-rebind imports hit unregistered
3435
+ // persistence and silently no-op.
3436
+ auxiliaryEntities: resolvedOrbital.original.auxiliaryEntities
3404
3437
  };
3405
3438
  preprocessedOrbitals.push(preprocessedOrbital);
3406
3439
  }
@@ -3963,7 +3996,8 @@ var OrbitalServerRuntime = class {
3963
3996
  traits: inlineTraits,
3964
3997
  configByTrait,
3965
3998
  manager,
3966
- entityData: /* @__PURE__ */ new Map()
3999
+ entityData: /* @__PURE__ */ new Map(),
4000
+ dataCache: /* @__PURE__ */ new Map()
3967
4001
  });
3968
4002
  if (entity?.name && entity.instances && Array.isArray(entity.instances)) {
3969
4003
  const instances = entity.instances;
@@ -4662,6 +4696,17 @@ var OrbitalServerRuntime = class {
4662
4696
  },
4663
4697
  fetch: async (fetchEntityType, options) => {
4664
4698
  try {
4699
+ xOrbitalLog.info("fetch:enter", {
4700
+ entityType: fetchEntityType,
4701
+ hasOptions: options !== void 0 && options !== null,
4702
+ optionsKeys: options && typeof options === "object" ? Object.keys(options).join(",") : "",
4703
+ filterType: typeof options?.filter,
4704
+ filterIsArray: Array.isArray(options?.filter),
4705
+ filterJson: JSON.stringify(
4706
+ options?.filter ?? null
4707
+ ).slice(0, 300),
4708
+ payloadJson: JSON.stringify(bindingsRef?.payload ?? null).slice(0, 300)
4709
+ });
4665
4710
  let result = null;
4666
4711
  if (options?.id) {
4667
4712
  const entity = await this.persistence.getById(fetchEntityType, options.id);
@@ -4704,14 +4749,32 @@ var OrbitalServerRuntime = class {
4704
4749
  fetchedData[fetchEntityType] = entities;
4705
4750
  result = entities;
4706
4751
  }
4707
- if (bindingsRef && result) {
4752
+ if (result) {
4708
4753
  const records = Array.isArray(result) ? result : [result];
4709
4754
  if (records.length > 0) {
4710
- const merged = Object.assign([...records], records[0]);
4711
- bindingsRef[fetchEntityType] = merged;
4712
- if (fetchEntityType === entityType) {
4713
- bindingsRef.entity = merged;
4755
+ const merged = Object.assign(
4756
+ [...records],
4757
+ records[0]
4758
+ );
4759
+ if (bindingsRef) {
4760
+ bindingsRef[fetchEntityType] = merged;
4761
+ if (fetchEntityType === entityType) {
4762
+ bindingsRef.entity = merged;
4763
+ }
4714
4764
  }
4765
+ registered.dataCache.set(fetchEntityType, merged);
4766
+ } else {
4767
+ const emptyCollection = Object.assign(
4768
+ [],
4769
+ {}
4770
+ );
4771
+ if (bindingsRef) {
4772
+ bindingsRef[fetchEntityType] = emptyCollection;
4773
+ if (fetchEntityType === entityType) {
4774
+ bindingsRef.entity = emptyCollection;
4775
+ }
4776
+ }
4777
+ registered.dataCache.set(fetchEntityType, emptyCollection);
4715
4778
  }
4716
4779
  }
4717
4780
  return result;
@@ -4910,16 +4973,22 @@ var OrbitalServerRuntime = class {
4910
4973
  bindings.config = { ...declaredDefaults ?? {}, ...callSiteOverride ?? {} };
4911
4974
  }
4912
4975
  if (traitDef?.scope === "collection" && entityType && !entityId) {
4913
- try {
4914
- const all = await this.persistence.list(entityType);
4915
- if (Array.isArray(all) && all.length > 0) {
4916
- const merged = Object.assign(
4917
- [...all],
4918
- all[0]
4919
- );
4920
- bindings.entity = merged;
4976
+ const cached = registered.dataCache.get(entityType);
4977
+ if (cached !== void 0) {
4978
+ bindings.entity = cached;
4979
+ } else {
4980
+ try {
4981
+ const all = await this.persistence.list(entityType);
4982
+ if (Array.isArray(all) && all.length > 0) {
4983
+ const merged = Object.assign(
4984
+ [...all],
4985
+ all[0]
4986
+ );
4987
+ bindings.entity = merged;
4988
+ registered.dataCache.set(entityType, merged);
4989
+ }
4990
+ } catch {
4921
4991
  }
4922
- } catch {
4923
4992
  }
4924
4993
  }
4925
4994
  if (entityType) {
@@ -5336,5 +5405,5 @@ function buildMatcher(src, listenerOrbital) {
5336
5405
  }
5337
5406
 
5338
5407
  export { EffectExecutor, EventBus, HANDLER_MANIFEST, InMemoryPersistence, MockPersistenceAdapter, OrbitalServerRuntime, StateMachineManager, buildEmitsFromTraits, collectDeclaredConfigDefaults, containsBindings, createContextFromBindings, createInitialTraitState, createLogger, createMockPersistence, createOrbitalServerRuntime, createTestExecutor, createUnifiedLoader, extractBindings, findInitialState, findTransition, formatPayloadValidationError, getIsolatedCollectionName, getNamespacedEvent, interpolateProps, interpolateValue, isBrowser, isElectron, isNamespacedEvent, isNode, normalizeEventKey, parseNamespacedEvent, preprocessSchema, processEvent, validateEventPayload, validatePayloadShapes };
5339
- //# sourceMappingURL=chunk-RONUCODN.js.map
5340
- //# sourceMappingURL=chunk-RONUCODN.js.map
5408
+ //# sourceMappingURL=chunk-6W6XCOLH.js.map
5409
+ //# sourceMappingURL=chunk-6W6XCOLH.js.map