@almadar/runtime 6.69.0 → 6.71.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.
@@ -1362,6 +1362,32 @@ declare class OrbitalServerRuntime {
1362
1362
  * Register a single orbital (sync wrapper for backward compatibility)
1363
1363
  */
1364
1364
  private registerOrbital;
1365
+ /**
1366
+ * The id of the SOURCE event a `listens {}` entry names, derived from the
1367
+ * emitting trait's own declared `emits[]` contract rather than trusted
1368
+ * from `listener.eventId` alone.
1369
+ *
1370
+ * `TraitEventListener.eventId` is "optional until the Phase-7 flip" (see
1371
+ * `@almadar/core`'s `trait.ts`) — the compose/resolve pipeline stamps a
1372
+ * V4 ledger id onto every `emits[]` entry (the emitter's own contract)
1373
+ * well before it stamps the matching id onto every `listens[]` entry that
1374
+ * names that event (source-qualified `Trait.EVENT -> X` listens compiled
1375
+ * from `uses`-resolved atoms carry `triggersId` for their OWN triggered
1376
+ * event but no `eventId` for the event they're listening to). The emit
1377
+ * handler (`executeEffects`'s `emit` closure below) always looks up and
1378
+ * stamps `emittingTrait.emits[].eventId` when present, so during that
1379
+ * transitional window the emit side routes under an id-qualified bus key
1380
+ * while the listen side — reading only its own possibly-absent
1381
+ * `eventId` — subscribes under the bare name, and the two never meet.
1382
+ *
1383
+ * Fix: derive the SAME id the emitter will stamp by resolving the
1384
+ * listener's declared `source` (trait/orbital, name or id) to the actual
1385
+ * registered trait and reading ITS `emits[]` contract for `listener.event`
1386
+ * — the single canonical place an event's id lives. `kind: "any"` sources
1387
+ * are left alone (no single emitter to resolve against; bare-name routing
1388
+ * is already the correct, safe default there).
1389
+ */
1390
+ private resolveSourceEmitEventId;
1365
1391
  /**
1366
1392
  * Set up event listeners for cross-orbital communication
1367
1393
  */
@@ -1553,6 +1579,12 @@ declare class OrbitalServerRuntime {
1553
1579
  interval: number | string;
1554
1580
  hasGuard: boolean;
1555
1581
  }>;
1582
+ /** Halt every registered tick's shared clock. Delegates to `TickScheduler.pause`. */
1583
+ pauseTicks(): void;
1584
+ /** Resume ticks halted by `pauseTicks()`. Delegates to `TickScheduler.resume`. */
1585
+ resumeTicks(): void;
1586
+ /** True while ticks are paused. Delegates to `TickScheduler.isPaused`. */
1587
+ areTicksPaused(): boolean;
1556
1588
  }
1557
1589
  /**
1558
1590
  * Factory function to create a runtime instance
@@ -1,4 +1,4 @@
1
1
  import 'express';
2
- export { F as ClientEffectTuple, G as ClientNavigateBackTuple, H as ClientNavigateTuple, J as ClientNotifyTuple, K as ClientRenderUITuple, M as EffectResult, e as InMemoryPersistence, N as LiveBroadcastItem, Q as LoaderConfig, O as OrbitalEventRequest, f as OrbitalEventResponse, T as OrbitalServerRuntime, g as OrbitalServerRuntimeConfig, P as PersistenceAdapter, R as RegisteredOrbital, l as RuntimeOrbital, m as RuntimeOrbitalSchema, n as RuntimeTrait, V as RuntimeTraitTick, p as collectDeclaredConfigDefaults, W as createOrbitalServerRuntime } from './OrbitalServerRuntime-DOJDoqXu.js';
2
+ export { F as ClientEffectTuple, G as ClientNavigateBackTuple, H as ClientNavigateTuple, J as ClientNotifyTuple, K as ClientRenderUITuple, M as EffectResult, e as InMemoryPersistence, N as LiveBroadcastItem, Q as LoaderConfig, O as OrbitalEventRequest, f as OrbitalEventResponse, T as OrbitalServerRuntime, g as OrbitalServerRuntimeConfig, P as PersistenceAdapter, R as RegisteredOrbital, l as RuntimeOrbital, m as RuntimeOrbitalSchema, n as RuntimeTrait, V as RuntimeTraitTick, p as collectDeclaredConfigDefaults, W as createOrbitalServerRuntime } from './OrbitalServerRuntime-DnDJhpLS.js';
3
3
  import './types-BaD_ox7e.js';
4
4
  import '@almadar/core';
@@ -1,5 +1,5 @@
1
- import { createTickScheduler, EventBus, createUnifiedLoader, MockPersistenceAdapter, InMemoryPersistence, preprocessSchema, normalizeCallSiteConfigToValues, StateMachineManager, parseDurationString, validateEventPayload, formatPayloadValidationError, collectDeclaredConfigDefaults, collectDeclaredEntityDefaults, EffectExecutor } from './chunk-XSWRK6DN.js';
2
- export { InMemoryPersistence, collectDeclaredConfigDefaults } from './chunk-XSWRK6DN.js';
1
+ import { createTickScheduler, EventBus, createUnifiedLoader, MockPersistenceAdapter, InMemoryPersistence, preprocessSchema, normalizeCallSiteConfigToValues, StateMachineManager, parseDurationString, validateEventPayload, formatPayloadValidationError, collectDeclaredConfigDefaults, collectDeclaredEntityDefaults, EffectExecutor } from './chunk-PAEMYGKV.js';
2
+ export { InMemoryPersistence, collectDeclaredConfigDefaults } from './chunk-PAEMYGKV.js';
3
3
  import { isValidCronExpression } from './chunk-OU3ITB5S.js';
4
4
  import { createContextFromBindings, checkMutationAccess, resolveCallSitePayloadCaptures, applyRowAccess, accessDeniedMessage } from './chunk-ZJ62H3ES.js';
5
5
  import './chunk-T4VDAB4C.js';
@@ -760,6 +760,40 @@ var OrbitalServerRuntime = class {
760
760
  });
761
761
  });
762
762
  }
763
+ /**
764
+ * The id of the SOURCE event a `listens {}` entry names, derived from the
765
+ * emitting trait's own declared `emits[]` contract rather than trusted
766
+ * from `listener.eventId` alone.
767
+ *
768
+ * `TraitEventListener.eventId` is "optional until the Phase-7 flip" (see
769
+ * `@almadar/core`'s `trait.ts`) — the compose/resolve pipeline stamps a
770
+ * V4 ledger id onto every `emits[]` entry (the emitter's own contract)
771
+ * well before it stamps the matching id onto every `listens[]` entry that
772
+ * names that event (source-qualified `Trait.EVENT -> X` listens compiled
773
+ * from `uses`-resolved atoms carry `triggersId` for their OWN triggered
774
+ * event but no `eventId` for the event they're listening to). The emit
775
+ * handler (`executeEffects`'s `emit` closure below) always looks up and
776
+ * stamps `emittingTrait.emits[].eventId` when present, so during that
777
+ * transitional window the emit side routes under an id-qualified bus key
778
+ * while the listen side — reading only its own possibly-absent
779
+ * `eventId` — subscribes under the bare name, and the two never meet.
780
+ *
781
+ * Fix: derive the SAME id the emitter will stamp by resolving the
782
+ * listener's declared `source` (trait/orbital, name or id) to the actual
783
+ * registered trait and reading ITS `emits[]` contract for `listener.event`
784
+ * — the single canonical place an event's id lives. `kind: "any"` sources
785
+ * are left alone (no single emitter to resolve against; bare-name routing
786
+ * is already the correct, safe default there).
787
+ */
788
+ resolveSourceEmitEventId(source, event, listenerOrbital) {
789
+ if (!source || source.kind === "any") return void 0;
790
+ const ownerOrbitalName = source.kind === "orbital" ? source.orbital : listenerOrbital;
791
+ const owner = this.orbitals.get(ownerOrbitalName);
792
+ if (!owner) return void 0;
793
+ const sourceTrait = source.traitId !== void 0 ? owner.traits.find((t) => t.id === source.traitId) : owner.traits.find((t) => t.name === source.trait);
794
+ if (!sourceTrait) return void 0;
795
+ return sourceTrait.emits?.find((e) => e.event === event)?.eventId;
796
+ }
763
797
  /**
764
798
  * Set up event listeners for cross-orbital communication
765
799
  */
@@ -773,7 +807,8 @@ var OrbitalServerRuntime = class {
773
807
  if (!trait.listens) continue;
774
808
  for (const listener of trait.listens) {
775
809
  const { bareEvent, matcher } = parseListenSource(listener, orbitalName);
776
- const routeKey = eventRouteKey(bareEvent, listener.eventId);
810
+ const effectiveEventId = listener.eventId ?? this.resolveSourceEmitEventId(listener.source, bareEvent, orbitalName);
811
+ const routeKey = eventRouteKey(bareEvent, effectiveEventId);
777
812
  const cleanup = this.eventBus.on(routeKey, async (event) => {
778
813
  if (!matcher(event.source)) return;
779
814
  if (event.source?.originClientId !== void 0) {
@@ -2418,6 +2453,18 @@ var OrbitalServerRuntime = class {
2418
2453
  hasGuard: !!binding.tick.guard
2419
2454
  }));
2420
2455
  }
2456
+ /** Halt every registered tick's shared clock. Delegates to `TickScheduler.pause`. */
2457
+ pauseTicks() {
2458
+ this.tickScheduler.pause();
2459
+ }
2460
+ /** Resume ticks halted by `pauseTicks()`. Delegates to `TickScheduler.resume`. */
2461
+ resumeTicks() {
2462
+ this.tickScheduler.resume();
2463
+ }
2464
+ /** True while ticks are paused. Delegates to `TickScheduler.isPaused`. */
2465
+ areTicksPaused() {
2466
+ return this.tickScheduler.isPaused;
2467
+ }
2421
2468
  };
2422
2469
  function createOrbitalServerRuntime(config) {
2423
2470
  return new OrbitalServerRuntime(config);
@@ -133,6 +133,7 @@ var TickScheduler = class {
133
133
  ticks = /* @__PURE__ */ new Map();
134
134
  nextId = 1;
135
135
  running = false;
136
+ paused = false;
136
137
  frameHandle = null;
137
138
  hasRaf;
138
139
  constructor() {
@@ -192,8 +193,38 @@ var TickScheduler = class {
192
193
  this.ticks.clear();
193
194
  this.maybeStop();
194
195
  }
196
+ /** True while the scheduler is paused (no tick callback fires and no backlog accumulates). */
197
+ get isPaused() {
198
+ return this.paused;
199
+ }
200
+ /**
201
+ * Halt the shared loop without dropping registered ticks. No `onDue`
202
+ * fires again until `resume()`. A no-op if already paused.
203
+ */
204
+ pause() {
205
+ if (this.paused) return;
206
+ this.paused = true;
207
+ this.stopLoop();
208
+ }
209
+ /**
210
+ * Restart the shared loop after `pause()`. Every registered tick's phase
211
+ * is reset (`lastTimestamp = null`) so the paused duration is never
212
+ * counted as elapsed time — the same "first pass just captures the
213
+ * timestamp" behavior a freshly `add()`-ed tick gets, which is what keeps
214
+ * resume from bursting a backlog of missed beats. A no-op if not paused.
215
+ */
216
+ resume() {
217
+ if (!this.paused) return;
218
+ this.paused = false;
219
+ for (const tick of this.ticks.values()) {
220
+ tick.lastTimestamp = null;
221
+ }
222
+ if (this.ticks.size > 0) {
223
+ this.ensureRunning();
224
+ }
225
+ }
195
226
  ensureRunning() {
196
- if (this.running) return;
227
+ if (this.running || this.paused) return;
197
228
  this.running = true;
198
229
  if (this.hasRaf) {
199
230
  const loop = (timestamp) => {
@@ -208,6 +239,10 @@ var TickScheduler = class {
208
239
  }
209
240
  maybeStop() {
210
241
  if (this.ticks.size > 0 || !this.running) return;
242
+ this.stopLoop();
243
+ }
244
+ /** Cancel the active rAF/interval loop, if any, and clear the running flag. */
245
+ stopLoop() {
211
246
  this.running = false;
212
247
  if (this.frameHandle !== null) {
213
248
  if (this.hasRaf) {
package/dist/index.d.ts CHANGED
@@ -1,7 +1,7 @@
1
1
  import { g as RuntimePatternValue, B as BindingContext, f as EvaluationContextExtensions, P as PatternProps, E as EffectHandlers, h as EffectContext, i as ExecutionEnvironment, j as EffectResult, S as ServiceCallContext, T as TraitDefinition } from './types-BaD_ox7e.js';
2
2
  export { k as BrowserFileMeta, l as BrowserFilePickerOptions, m as BrowserGeolocationOptions, n as BrowserGeolocationPosition, C as ConfigContext, o as Effect, a as EventListener, H as HANDLER_MANIFEST, I as IEventBus, b as RuntimeConfig, R as RuntimeEvent, d as TraitState, c as TransitionObserver, e as TransitionResult, U as Unsubscribe } from './types-BaD_ox7e.js';
3
- import { U as UnifiedLoaderOptions, S as SchemaLoader, I as ImportChainLike, L as LoadResult, a as LoadedSchema, b as LoadedOrbital, P as PersistenceAdapter } from './OrbitalServerRuntime-DOJDoqXu.js';
4
- export { E as EntitySharingMap, c as EventBus, d as EventNamespaceMap, e as InMemoryPersistence, O as OrbitalEventRequest, f as OrbitalEventResponse, g as OrbitalServerRuntimeConfig, h as PreprocessOptions, i as PreprocessResult, j as PreprocessedSchema, k as ProcessEventOptions, R as RegisteredOrbital, l as RuntimeOrbital, m as RuntimeOrbitalSchema, n as RuntimeTrait, o as StateMachineManager, p as collectDeclaredConfigDefaults, q as collectDeclaredEntityDefaults, r as createInitialTraitState, s as findInitialState, t as findTransition, u as getIsolatedCollectionName, v as getNamespacedEvent, w as isBrowser, x as isElectron, y as isNamespacedEvent, z as isNode, A as normalizeEventKey, B as parseNamespacedEvent, C as preprocessSchema, D as processEvent } from './OrbitalServerRuntime-DOJDoqXu.js';
3
+ import { U as UnifiedLoaderOptions, S as SchemaLoader, I as ImportChainLike, L as LoadResult, a as LoadedSchema, b as LoadedOrbital, P as PersistenceAdapter } from './OrbitalServerRuntime-DnDJhpLS.js';
4
+ export { E as EntitySharingMap, c as EventBus, d as EventNamespaceMap, e as InMemoryPersistence, O as OrbitalEventRequest, f as OrbitalEventResponse, g as OrbitalServerRuntimeConfig, h as PreprocessOptions, i as PreprocessResult, j as PreprocessedSchema, k as ProcessEventOptions, R as RegisteredOrbital, l as RuntimeOrbital, m as RuntimeOrbitalSchema, n as RuntimeTrait, o as StateMachineManager, p as collectDeclaredConfigDefaults, q as collectDeclaredEntityDefaults, r as createInitialTraitState, s as findInitialState, t as findTransition, u as getIsolatedCollectionName, v as getNamespacedEvent, w as isBrowser, x as isElectron, y as isNamespacedEvent, z as isNode, A as normalizeEventKey, B as parseNamespacedEvent, C as preprocessSchema, D as processEvent } from './OrbitalServerRuntime-DnDJhpLS.js';
5
5
  import { EvaluationContext, SExpressionEvaluator } from '@almadar/evaluator';
6
6
  export { EvaluationContext, createMinimalContext } from '@almadar/evaluator';
7
7
  import { RenderBindingMarker, SExpr, RuntimeValue, TraitConfigObject, EventPayload, PatternConfig, EntityId, EntityField, EntityRow, EntityPersistence, ServiceParams, EntityAccessPolicies, PayloadField, OrbitalDefinition, OrbitalSchema } from '@almadar/core';
@@ -168,6 +168,7 @@ declare class TickScheduler {
168
168
  private ticks;
169
169
  private nextId;
170
170
  private running;
171
+ private paused;
171
172
  private frameHandle;
172
173
  private readonly hasRaf;
173
174
  constructor();
@@ -187,8 +188,25 @@ declare class TickScheduler {
187
188
  addCron(expression: string, onDue: () => void): TickHandle;
188
189
  /** Stop every tick and the shared loop. */
189
190
  stopAll(): void;
191
+ /** True while the scheduler is paused (no tick callback fires and no backlog accumulates). */
192
+ get isPaused(): boolean;
193
+ /**
194
+ * Halt the shared loop without dropping registered ticks. No `onDue`
195
+ * fires again until `resume()`. A no-op if already paused.
196
+ */
197
+ pause(): void;
198
+ /**
199
+ * Restart the shared loop after `pause()`. Every registered tick's phase
200
+ * is reset (`lastTimestamp = null`) so the paused duration is never
201
+ * counted as elapsed time — the same "first pass just captures the
202
+ * timestamp" behavior a freshly `add()`-ed tick gets, which is what keeps
203
+ * resume from bursting a backlog of missed beats. A no-op if not paused.
204
+ */
205
+ resume(): void;
190
206
  private ensureRunning;
191
207
  private maybeStop;
208
+ /** Cancel the active rAF/interval loop, if any, and clear the running flag. */
209
+ private stopLoop;
192
210
  private advance;
193
211
  /** Cron ticks check calendar-match at most once a second, deduped per matching minute. */
194
212
  private advanceCron;
package/dist/index.js CHANGED
@@ -1,5 +1,5 @@
1
- import { EffectExecutor } from './chunk-XSWRK6DN.js';
2
- export { EffectExecutor, EventBus, HANDLER_MANIFEST, InMemoryPersistence, MockPersistenceAdapter, StateMachineManager, TickScheduler, buildEmitsFromTraits, collectDeclaredConfigDefaults, collectDeclaredEntityDefaults, createInitialTraitState, createMockPersistence, createTestExecutor, createTickScheduler, createUnifiedLoader, findInitialState, findTransition, formatPayloadValidationError, getIsolatedCollectionName, getNamespacedEvent, isBrowser, isElectron, isNamespacedEvent, isNode, isValidDurationString, normalizeCallSiteConfigToValues, normalizeEventKey, parseDurationString, parseNamespacedEvent, preprocessSchema, processEvent, validateEventPayload, validatePayloadShapes } from './chunk-XSWRK6DN.js';
1
+ import { EffectExecutor } from './chunk-PAEMYGKV.js';
2
+ export { EffectExecutor, EventBus, HANDLER_MANIFEST, InMemoryPersistence, MockPersistenceAdapter, StateMachineManager, TickScheduler, buildEmitsFromTraits, collectDeclaredConfigDefaults, collectDeclaredEntityDefaults, createInitialTraitState, createMockPersistence, createTestExecutor, createTickScheduler, createUnifiedLoader, findInitialState, findTransition, formatPayloadValidationError, getIsolatedCollectionName, getNamespacedEvent, isBrowser, isElectron, isNamespacedEvent, isNode, isValidDurationString, normalizeCallSiteConfigToValues, normalizeEventKey, parseDurationString, parseNamespacedEvent, preprocessSchema, processEvent, validateEventPayload, validatePayloadShapes } from './chunk-PAEMYGKV.js';
3
3
  export { cronMatches, cronMinuteKey, isValidCronExpression, parseCron, parseCronField } from './chunk-OU3ITB5S.js';
4
4
  import { createContextFromBindings, applyRowAccess, checkMutationAccess, accessDeniedMessage } from './chunk-ZJ62H3ES.js';
5
5
  export { CALLSITE_PAYLOAD_PREFIX, applyRowAccess, checkMutationAccess, containsBindings, createContextFromBindings, createMinimalContext, deferEntityBindings, extractBindings, interpolateProps, interpolateValue, resolveCallSitePayloadCaptures } from './chunk-ZJ62H3ES.js';
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@almadar/runtime",
3
- "version": "6.69.0",
3
+ "version": "6.71.0",
4
4
  "description": "Interpreted runtime for Almadar orbital applications (OrbitalServerRuntime)",
5
5
  "type": "module",
6
6
  "main": "./dist/index.js",
@@ -57,11 +57,11 @@
57
57
  "access": "public"
58
58
  },
59
59
  "dependencies": {
60
- "@almadar/core": "^10.79.0",
61
- "@almadar/evaluator": "^2.43.0",
60
+ "@almadar/core": "^10.84.0",
61
+ "@almadar/evaluator": "^2.44.0",
62
62
  "@almadar/logger": "^1.12.0",
63
63
  "@almadar/server": "^2.39.0",
64
- "@almadar/std": "^16.199.0"
64
+ "@almadar/std": "^16.204.0"
65
65
  },
66
66
  "peerDependencies": {
67
67
  "express": "^5.0.0"