@almadar/runtime 5.9.2 → 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-LZYY2JJR.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
  }
@@ -3971,7 +3996,8 @@ var OrbitalServerRuntime = class {
3971
3996
  traits: inlineTraits,
3972
3997
  configByTrait,
3973
3998
  manager,
3974
- entityData: /* @__PURE__ */ new Map()
3999
+ entityData: /* @__PURE__ */ new Map(),
4000
+ dataCache: /* @__PURE__ */ new Map()
3975
4001
  });
3976
4002
  if (entity?.name && entity.instances && Array.isArray(entity.instances)) {
3977
4003
  const instances = entity.instances;
@@ -4670,6 +4696,17 @@ var OrbitalServerRuntime = class {
4670
4696
  },
4671
4697
  fetch: async (fetchEntityType, options) => {
4672
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
+ });
4673
4710
  let result = null;
4674
4711
  if (options?.id) {
4675
4712
  const entity = await this.persistence.getById(fetchEntityType, options.id);
@@ -4712,14 +4749,32 @@ var OrbitalServerRuntime = class {
4712
4749
  fetchedData[fetchEntityType] = entities;
4713
4750
  result = entities;
4714
4751
  }
4715
- if (bindingsRef && result) {
4752
+ if (result) {
4716
4753
  const records = Array.isArray(result) ? result : [result];
4717
4754
  if (records.length > 0) {
4718
- const merged = Object.assign([...records], records[0]);
4719
- bindingsRef[fetchEntityType] = merged;
4720
- if (fetchEntityType === entityType) {
4721
- 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
+ }
4722
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);
4723
4778
  }
4724
4779
  }
4725
4780
  return result;
@@ -4918,16 +4973,22 @@ var OrbitalServerRuntime = class {
4918
4973
  bindings.config = { ...declaredDefaults ?? {}, ...callSiteOverride ?? {} };
4919
4974
  }
4920
4975
  if (traitDef?.scope === "collection" && entityType && !entityId) {
4921
- try {
4922
- const all = await this.persistence.list(entityType);
4923
- if (Array.isArray(all) && all.length > 0) {
4924
- const merged = Object.assign(
4925
- [...all],
4926
- all[0]
4927
- );
4928
- 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 {
4929
4991
  }
4930
- } catch {
4931
4992
  }
4932
4993
  }
4933
4994
  if (entityType) {
@@ -5344,5 +5405,5 @@ function buildMatcher(src, listenerOrbital) {
5344
5405
  }
5345
5406
 
5346
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 };
5347
- //# sourceMappingURL=chunk-LZYY2JJR.js.map
5348
- //# sourceMappingURL=chunk-LZYY2JJR.js.map
5408
+ //# sourceMappingURL=chunk-6W6XCOLH.js.map
5409
+ //# sourceMappingURL=chunk-6W6XCOLH.js.map