@almadar/runtime 3.3.0 → 4.0.1
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.
- package/dist/{OrbitalServerRuntime-DMRvEfcT.d.ts → OrbitalServerRuntime-DMe0zqCc.d.ts} +8 -6
- package/dist/OrbitalServerRuntime.d.ts +2 -2
- package/dist/OrbitalServerRuntime.js +61 -36
- package/dist/OrbitalServerRuntime.js.map +1 -1
- package/dist/ServerBridge.d.ts +1 -1
- package/dist/{chunk-II3JSETH.js → chunk-7WP4AE6X.js} +13 -10
- package/dist/chunk-7WP4AE6X.js.map +1 -0
- package/dist/index.d.ts +6 -4
- package/dist/index.js +1 -1
- package/dist/{types-B8OfRFfV.d.ts → types-CVSBlnzV.d.ts} +15 -2
- package/package.json +2 -2
- package/dist/chunk-II3JSETH.js.map +0 -1
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { Router } from 'express';
|
|
2
|
-
import { I as IEventBus, g as RuntimeEvent, f as EventListener, U as Unsubscribe, T as TraitDefinition, R as RuntimeConfig, i as TransitionObserver, h as TraitState, j as TransitionResult, E as EvaluationContextExtensions, a as EffectHandlers } from './types-
|
|
2
|
+
import { I as IEventBus, g as RuntimeEvent, f as EventListener, U as Unsubscribe, T as TraitDefinition, R as RuntimeConfig, i as TransitionObserver, h as TraitState, j as TransitionResult, E as EvaluationContextExtensions, a as EffectHandlers } from './types-CVSBlnzV.js';
|
|
3
3
|
import { EventPayload, EntityRow, OrbitalSchema, Orbital, Trait, OrbitalDefinition, Entity, TraitTick } from '@almadar/core';
|
|
4
4
|
|
|
5
5
|
/**
|
|
@@ -748,14 +748,16 @@ interface OrbitalEventResponse {
|
|
|
748
748
|
success: boolean;
|
|
749
749
|
transitioned: boolean;
|
|
750
750
|
states: Record<string, string>;
|
|
751
|
+
/**
|
|
752
|
+
* Events emitted during processing, in declaration order. Payloads are
|
|
753
|
+
* typed against `@almadar/core`'s `EventPayload` — the recursive record of
|
|
754
|
+
* primitive + nested EventPayload values the state machine already uses
|
|
755
|
+
* internally. Kept as the single source of truth for emit-payload shape.
|
|
756
|
+
*/
|
|
751
757
|
emittedEvents: Array<{
|
|
752
758
|
event: string;
|
|
753
|
-
payload?:
|
|
759
|
+
payload?: EventPayload;
|
|
754
760
|
}>;
|
|
755
|
-
/** Entity data fetched by `fetch` effects - keyed by entity type */
|
|
756
|
-
data?: {
|
|
757
|
-
[entityType: string]: EntityRow | EntityRow[];
|
|
758
|
-
};
|
|
759
761
|
/** Client-side effects to execute (render-ui, navigate, notify) */
|
|
760
762
|
clientEffects?: Array<unknown>;
|
|
761
763
|
/**
|
|
@@ -1,4 +1,4 @@
|
|
|
1
1
|
import 'express';
|
|
2
|
-
export { B as EffectResult, C as LoaderConfig, D as LocalPersistenceAdapter, O as OrbitalEventRequest, e as OrbitalEventResponse, F as OrbitalServerRuntime, f as OrbitalServerRuntimeConfig, P as PersistenceAdapter, R as RegisteredOrbital, k as RuntimeOrbital, l as RuntimeOrbitalSchema, m as RuntimeTrait, G as RuntimeTraitTick, H as createOrbitalServerRuntime } from './OrbitalServerRuntime-
|
|
3
|
-
import './types-
|
|
2
|
+
export { B as EffectResult, C as LoaderConfig, D as LocalPersistenceAdapter, O as OrbitalEventRequest, e as OrbitalEventResponse, F as OrbitalServerRuntime, f as OrbitalServerRuntimeConfig, P as PersistenceAdapter, R as RegisteredOrbital, k as RuntimeOrbital, l as RuntimeOrbitalSchema, m as RuntimeTrait, G as RuntimeTraitTick, H as createOrbitalServerRuntime } from './OrbitalServerRuntime-DMe0zqCc.js';
|
|
3
|
+
import './types-CVSBlnzV.js';
|
|
4
4
|
import '@almadar/core';
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { EventBus, createUnifiedLoader, preprocessSchema, StateMachineManager, createContextFromBindings, EffectExecutor } from './chunk-
|
|
1
|
+
import { EventBus, createUnifiedLoader, preprocessSchema, StateMachineManager, createContextFromBindings, EffectExecutor } from './chunk-7WP4AE6X.js';
|
|
2
2
|
import './chunk-PZ5AY32C.js';
|
|
3
3
|
import { Router } from 'express';
|
|
4
4
|
import * as fs from 'fs';
|
|
@@ -953,10 +953,12 @@ var OrbitalServerRuntime = class {
|
|
|
953
953
|
for (const trait of registered.traits) {
|
|
954
954
|
if (!trait.listens) continue;
|
|
955
955
|
for (const listener of trait.listens) {
|
|
956
|
-
const
|
|
956
|
+
const { bareEvent, matcher } = parseListenSource(listener, orbitalName);
|
|
957
|
+
const cleanup = this.eventBus.on(bareEvent, async (event) => {
|
|
958
|
+
if (!matcher(event.source)) return;
|
|
957
959
|
if (this.config.debug) {
|
|
958
960
|
console.log(
|
|
959
|
-
`[OrbitalRuntime] ${orbitalName}.${trait.name} received: ${listener.event}`
|
|
961
|
+
`[OrbitalRuntime] ${orbitalName}.${trait.name} received: ${listener.event} (from ${event.source?.orbital ?? "?"}.${event.source?.trait ?? "?"})`
|
|
960
962
|
);
|
|
961
963
|
}
|
|
962
964
|
let mappedPayload = event.payload;
|
|
@@ -1223,32 +1225,6 @@ var OrbitalServerRuntime = class {
|
|
|
1223
1225
|
);
|
|
1224
1226
|
}
|
|
1225
1227
|
}
|
|
1226
|
-
const persistedTypes = /* @__PURE__ */ new Set();
|
|
1227
|
-
for (const er of effectResults) {
|
|
1228
|
-
if ((er.effect === "persist" || er.effect === "set" || er.effect === "swap") && er.success && er.entityType) {
|
|
1229
|
-
persistedTypes.add(er.entityType);
|
|
1230
|
-
}
|
|
1231
|
-
}
|
|
1232
|
-
const refTypes = /* @__PURE__ */ new Set();
|
|
1233
|
-
for (const trait of registered.traits) {
|
|
1234
|
-
const transitions = trait.stateMachine?.transitions ?? [];
|
|
1235
|
-
for (const trans of transitions) {
|
|
1236
|
-
for (const eff of trans.effects ?? []) {
|
|
1237
|
-
if (Array.isArray(eff) && eff[0] === "ref" && typeof eff[1] === "string") {
|
|
1238
|
-
refTypes.add(eff[1]);
|
|
1239
|
-
}
|
|
1240
|
-
}
|
|
1241
|
-
}
|
|
1242
|
-
}
|
|
1243
|
-
for (const mutatedEntityType of persistedTypes) {
|
|
1244
|
-
if (refTypes.has(mutatedEntityType)) {
|
|
1245
|
-
try {
|
|
1246
|
-
const fresh = await this.persistence.list(mutatedEntityType);
|
|
1247
|
-
fetchedData[mutatedEntityType] = fresh;
|
|
1248
|
-
} catch {
|
|
1249
|
-
}
|
|
1250
|
-
}
|
|
1251
|
-
}
|
|
1252
1228
|
const states = {};
|
|
1253
1229
|
for (const [name, state] of registered.manager.getAllStates()) {
|
|
1254
1230
|
states[name] = state.currentState;
|
|
@@ -1259,9 +1235,6 @@ var OrbitalServerRuntime = class {
|
|
|
1259
1235
|
states,
|
|
1260
1236
|
emittedEvents
|
|
1261
1237
|
};
|
|
1262
|
-
if (Object.keys(fetchedData).length > 0) {
|
|
1263
|
-
response.data = fetchedData;
|
|
1264
|
-
}
|
|
1265
1238
|
if (clientEffects.length > 0) {
|
|
1266
1239
|
response.clientEffects = clientEffects;
|
|
1267
1240
|
}
|
|
@@ -1285,11 +1258,15 @@ var OrbitalServerRuntime = class {
|
|
|
1285
1258
|
let bindingsRef = null;
|
|
1286
1259
|
let contextRef = null;
|
|
1287
1260
|
const handlers = {
|
|
1288
|
-
emit: (event, eventPayload) => {
|
|
1261
|
+
emit: (event, eventPayload, source) => {
|
|
1289
1262
|
if (this.config.debug) {
|
|
1290
|
-
console.log(`[OrbitalRuntime] Emitting: ${event}`, eventPayload);
|
|
1263
|
+
console.log(`[OrbitalRuntime] Emitting: ${event}`, eventPayload, source);
|
|
1291
1264
|
}
|
|
1292
|
-
|
|
1265
|
+
const stamp = source ?? {
|
|
1266
|
+
orbital: registered.schema.name,
|
|
1267
|
+
trait: traitName
|
|
1268
|
+
};
|
|
1269
|
+
this.eventBus.emit(event, eventPayload, stamp);
|
|
1293
1270
|
emittedEvents.push({ event, payload: eventPayload });
|
|
1294
1271
|
},
|
|
1295
1272
|
set: async (targetId, field, value) => {
|
|
@@ -1623,7 +1600,7 @@ var OrbitalServerRuntime = class {
|
|
|
1623
1600
|
const atomicExecutor = new EffectExecutor({
|
|
1624
1601
|
handlers,
|
|
1625
1602
|
bindings: bindingsRef ?? {},
|
|
1626
|
-
context: contextRef ?? { traitName, state: "unknown", transition: "unknown" },
|
|
1603
|
+
context: contextRef ?? { traitName, orbitalName: registered.schema.name, state: "unknown", transition: "unknown" },
|
|
1627
1604
|
debug: this.config.debug,
|
|
1628
1605
|
contextExtensions: this.config.contextExtensions
|
|
1629
1606
|
});
|
|
@@ -1684,6 +1661,7 @@ var OrbitalServerRuntime = class {
|
|
|
1684
1661
|
bindingsRef = bindings;
|
|
1685
1662
|
const context = {
|
|
1686
1663
|
traitName,
|
|
1664
|
+
orbitalName: registered.schema.name,
|
|
1687
1665
|
state: state?.currentState || "unknown",
|
|
1688
1666
|
transition: "unknown",
|
|
1689
1667
|
entityId
|
|
@@ -2029,6 +2007,53 @@ var OrbitalServerRuntime = class {
|
|
|
2029
2007
|
function createOrbitalServerRuntime(config) {
|
|
2030
2008
|
return new OrbitalServerRuntime(config);
|
|
2031
2009
|
}
|
|
2010
|
+
function parseListenSource(listener, listenerOrbital) {
|
|
2011
|
+
const explicit = listener.source;
|
|
2012
|
+
if (explicit && typeof explicit === "object") {
|
|
2013
|
+
return {
|
|
2014
|
+
bareEvent: listener.event,
|
|
2015
|
+
matcher: buildMatcher(explicit, listenerOrbital)
|
|
2016
|
+
};
|
|
2017
|
+
}
|
|
2018
|
+
const key = listener.event;
|
|
2019
|
+
const parts = key.split(".");
|
|
2020
|
+
if (parts.length === 1) {
|
|
2021
|
+
return { bareEvent: key, matcher: () => true };
|
|
2022
|
+
}
|
|
2023
|
+
if (parts.length === 2) {
|
|
2024
|
+
const [sourceOrStar, eventName] = parts;
|
|
2025
|
+
if (sourceOrStar === "*") {
|
|
2026
|
+
return { bareEvent: eventName, matcher: () => true };
|
|
2027
|
+
}
|
|
2028
|
+
return {
|
|
2029
|
+
bareEvent: eventName,
|
|
2030
|
+
matcher: buildMatcher(
|
|
2031
|
+
{ kind: "trait", trait: sourceOrStar },
|
|
2032
|
+
listenerOrbital
|
|
2033
|
+
)
|
|
2034
|
+
};
|
|
2035
|
+
}
|
|
2036
|
+
if (parts.length >= 3) {
|
|
2037
|
+
const eventName = parts[parts.length - 1];
|
|
2038
|
+
const trait = parts[parts.length - 2];
|
|
2039
|
+
const orbital = parts.slice(0, parts.length - 2).join(".");
|
|
2040
|
+
return {
|
|
2041
|
+
bareEvent: eventName,
|
|
2042
|
+
matcher: buildMatcher({ kind: "orbital", orbital, trait }, listenerOrbital)
|
|
2043
|
+
};
|
|
2044
|
+
}
|
|
2045
|
+
return { bareEvent: key, matcher: () => true };
|
|
2046
|
+
}
|
|
2047
|
+
function buildMatcher(src, listenerOrbital) {
|
|
2048
|
+
if (src.kind === "any") return () => true;
|
|
2049
|
+
if (src.kind === "trait") {
|
|
2050
|
+
const wantedTrait2 = src.trait;
|
|
2051
|
+
return (source) => !!source && source.orbital === listenerOrbital && source.trait === wantedTrait2;
|
|
2052
|
+
}
|
|
2053
|
+
const wantedOrbital = src.orbital;
|
|
2054
|
+
const wantedTrait = src.trait;
|
|
2055
|
+
return (source) => !!source && source.orbital === wantedOrbital && source.trait === wantedTrait;
|
|
2056
|
+
}
|
|
2032
2057
|
|
|
2033
2058
|
export { LocalPersistenceAdapter, OrbitalServerRuntime, createOrbitalServerRuntime };
|
|
2034
2059
|
//# sourceMappingURL=OrbitalServerRuntime.js.map
|