@almadar/shell-runtime 0.1.0 → 1.0.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.
Files changed (167) hide show
  1. package/dist/chunk-57SBCUSM.js +62 -0
  2. package/dist/chunk-625EP7W2.js +108 -0
  3. package/dist/{chunk-NATGCIVM.js → chunk-7WB6VWRK.js} +344 -129
  4. package/dist/{chunk-Q2H75UYT.js → chunk-A2JJT4GA.js} +1 -37
  5. package/dist/chunk-BAS26HBN.js +10 -0
  6. package/dist/{chunk-REPX5QPI.js → chunk-BOVU4TCQ.js} +11 -3
  7. package/dist/chunk-BY5G4225.js +6 -0
  8. package/dist/chunk-DFDNHVDW.js +284 -0
  9. package/dist/chunk-I3TKINSO.js +398 -0
  10. package/dist/{chunk-DYOJGLIX.js → chunk-LKWYCYX5.js} +2 -5
  11. package/dist/chunk-LYFIQPXX.js +1 -0
  12. package/dist/{chunk-VNMG7NKY.js → chunk-MU335ZA4.js} +20 -26
  13. package/dist/{chunk-ODJCZ27I.js → chunk-N7HYNKK6.js} +35 -2
  14. package/dist/{chunk-4J2QEIUV.js → chunk-NTFQ36UN.js} +4 -30
  15. package/dist/chunk-NU6LVKGS.js +15 -0
  16. package/dist/chunk-P2N6K2IV.js +20 -0
  17. package/dist/{chunk-QQRDUMB2.js → chunk-QCJWPXLH.js} +11 -11
  18. package/dist/{chunk-QELZ6TEJ.js → chunk-UD2CXYSJ.js} +39 -3
  19. package/dist/{chunk-UJHOUZAL.js → chunk-V4EMDPCO.js} +2 -5
  20. package/dist/chunk-VNGXRYFF.js +9 -0
  21. package/dist/{chunk-HNOAZWFH.js → chunk-WGCWJOT2.js} +2 -0
  22. package/dist/chunk-X6W44WHO.js +26 -0
  23. package/dist/chunk-ZUSM4VW4.js +197 -0
  24. package/dist/client/EventTransport.d.ts +23 -7
  25. package/dist/client/EventTransport.js +1 -2
  26. package/dist/client/awaiting.js +0 -1
  27. package/dist/client/channel-transport.d.ts +6 -6
  28. package/dist/client/channel-transport.js +0 -1
  29. package/dist/client/circuit-store.d.ts +16 -5
  30. package/dist/client/circuit-store.js +2 -3
  31. package/dist/client/client-kernel.d.ts +36 -15
  32. package/dist/client/declared-input-dispatch.d.ts +19 -2
  33. package/dist/client/declared-input-dispatch.js +1 -2
  34. package/dist/client/inbound-dispatch.d.ts +21 -2
  35. package/dist/client/inbound-dispatch.js +1 -2
  36. package/dist/client/local-fold.d.ts +15 -8
  37. package/dist/client/local-fold.js +1 -2
  38. package/dist/client/render-sigils.js +0 -1
  39. package/dist/client/state-book.d.ts +9 -16
  40. package/dist/client/state-book.js +1 -2
  41. package/dist/client/trait-mount-error.js +0 -1
  42. package/dist/credentials/env-vars.d.ts +5 -1
  43. package/dist/credentials/env-vars.js +1 -3
  44. package/dist/credentials/scope.d.ts +8 -7
  45. package/dist/credentials/scope.js +0 -1
  46. package/dist/credentials/vault.d.ts +142 -0
  47. package/dist/credentials/vault.js +1 -0
  48. package/dist/effects/in-flight-calls.js +0 -1
  49. package/dist/effects/on-device-model.js +0 -1
  50. package/dist/events/EventBus.d.ts +1 -4
  51. package/dist/events/EventBus.js +0 -1
  52. package/dist/events/emit-stamp.js +0 -1
  53. package/dist/index.d.ts +25 -42
  54. package/dist/index.js +27 -45
  55. package/dist/kernel/decode.d.ts +8 -10
  56. package/dist/kernel/decode.js +1 -2
  57. package/dist/kernel/engine.d.ts +132 -31
  58. package/dist/kernel/engine.js +7 -9
  59. package/dist/kernel/frame-applier.d.ts +8 -7
  60. package/dist/kernel/frame-applier.js +1 -2
  61. package/dist/kernel/host.d.ts +127 -16
  62. package/dist/kernel/host.js +4 -7
  63. package/dist/kernel/lane.d.ts +1 -22
  64. package/dist/kernel/lane.js +1 -2
  65. package/dist/kernel/os-fetch-port.d.ts +7 -0
  66. package/dist/kernel/os-fetch-port.js +3 -0
  67. package/dist/kernel/os-port.d.ts +30 -8
  68. package/dist/kernel/os-port.js +1 -2
  69. package/dist/kernel/program-effects.d.ts +11 -28
  70. package/dist/kernel/program-effects.js +1 -2
  71. package/dist/kernel/secret-ports.d.ts +139 -0
  72. package/dist/kernel/secret-ports.js +2 -0
  73. package/dist/kernel/wire.d.ts +50 -12
  74. package/dist/loader/fetch-loader.d.ts +26 -0
  75. package/dist/loader/fetch-loader.js +1 -0
  76. package/dist/loader/lazy-page.js +0 -1
  77. package/dist/loader/schema-loader.d.ts +1 -17
  78. package/dist/persistence/native-memory.js +0 -1
  79. package/dist/runtime/entities/declaredCollections.d.ts +6 -0
  80. package/dist/runtime/entities/declaredCollections.js +1 -0
  81. package/dist/runtime/evaluation/local-store-transport.d.ts +14 -23
  82. package/dist/runtime/evaluation/local-store-transport.js +9 -13
  83. package/dist/runtime/evaluation/residence-transport.d.ts +3 -3
  84. package/dist/runtime/evaluation/residence-transport.js +1 -2
  85. package/dist/runtime/evaluation/routed-persistence.js +0 -1
  86. package/dist/runtime/events/identity/routing.d.ts +2 -53
  87. package/dist/runtime/events/identity/routing.js +1 -2
  88. package/dist/runtime/types.d.ts +5 -205
  89. package/dist/runtime/types.js +1 -2
  90. package/dist/service/default-call-service.js +0 -1
  91. package/dist/service/service-provider.js +0 -1
  92. package/package.json +8 -5
  93. package/dist/chunk-2JU7Y4KU.js +0 -21
  94. package/dist/chunk-46RWK2B5.js +0 -28
  95. package/dist/chunk-4ZICQ5PM.js +0 -192
  96. package/dist/chunk-53IPZXDP.js +0 -76
  97. package/dist/chunk-5D63EMO5.js +0 -16
  98. package/dist/chunk-CPSQXEJ6.js +0 -55
  99. package/dist/chunk-CQP5XAX6.js +0 -173
  100. package/dist/chunk-CROS2GEX.js +0 -49
  101. package/dist/chunk-D4XJTBLB.js +0 -217
  102. package/dist/chunk-D5USD2EX.js +0 -232
  103. package/dist/chunk-EV56K4GB.js +0 -63
  104. package/dist/chunk-FQ6IZMIU.js +0 -10
  105. package/dist/chunk-HMK6YMQS.js +0 -135
  106. package/dist/chunk-IHQLE5M7.js +0 -62
  107. package/dist/chunk-JFWFDUTR.js +0 -35
  108. package/dist/chunk-MHYSHSRG.js +0 -54
  109. package/dist/chunk-MLKGABMK.js +0 -7
  110. package/dist/chunk-NAECVIAR.js +0 -322
  111. package/dist/chunk-Q7JK4KY7.js +0 -9
  112. package/dist/chunk-RBUMDYFS.js +0 -681
  113. package/dist/chunk-SAS5KKCR.js +0 -43
  114. package/dist/chunk-SWPDU752.js +0 -28
  115. package/dist/chunk-T775TUCD.js +0 -18
  116. package/dist/chunk-VMOBW7RK.js +0 -21
  117. package/dist/chunk-WNPNNYXY.js +0 -22
  118. package/dist/chunk-XB5GYODW.js +0 -28
  119. package/dist/chunk-YL2SO5TP.js +0 -334
  120. package/dist/chunk-YO4LWS3I.js +0 -606
  121. package/dist/chunk-ZAQSS47X.js +0 -157
  122. package/dist/chunk-ZCQUUJIF.js +0 -129
  123. package/dist/client/ServerBridge.d.ts +0 -126
  124. package/dist/client/ServerBridge.js +0 -3
  125. package/dist/credentials/seed.d.ts +0 -21
  126. package/dist/credentials/seed.js +0 -2
  127. package/dist/credentials/store.d.ts +0 -110
  128. package/dist/credentials/store.js +0 -2
  129. package/dist/index-hT1xCdTq.d.ts +0 -46
  130. package/dist/kernel/beacon.d.ts +0 -32
  131. package/dist/kernel/beacon.js +0 -2
  132. package/dist/kernel/http.d.ts +0 -302
  133. package/dist/kernel/http.js +0 -6
  134. package/dist/kernel/oauth-effects.d.ts +0 -25
  135. package/dist/kernel/oauth-effects.js +0 -7
  136. package/dist/kernel/oauth-port.d.ts +0 -31
  137. package/dist/kernel/oauth-port.js +0 -2
  138. package/dist/loader/http-loader.d.ts +0 -111
  139. package/dist/loader/http-loader.js +0 -2
  140. package/dist/runtime/effects/composition/compose-behaviors.d.ts +0 -58
  141. package/dist/runtime/effects/composition/compose-behaviors.js +0 -4
  142. package/dist/runtime/effects/composition/event-wiring.d.ts +0 -38
  143. package/dist/runtime/effects/composition/event-wiring.js +0 -2
  144. package/dist/runtime/effects/composition/index.d.ts +0 -5
  145. package/dist/runtime/effects/composition/index.js +0 -6
  146. package/dist/runtime/effects/composition/layout-strategy.d.ts +0 -35
  147. package/dist/runtime/effects/composition/layout-strategy.js +0 -2
  148. package/dist/runtime/effects/composition/pipe.d.ts +0 -25
  149. package/dist/runtime/effects/composition/pipe.js +0 -2
  150. package/dist/runtime/entities/mockStoreSeed.d.ts +0 -56
  151. package/dist/runtime/entities/mockStoreSeed.js +0 -3
  152. package/dist/runtime/entities/seedBrowserStore.d.ts +0 -28
  153. package/dist/runtime/entities/seedBrowserStore.js +0 -2
  154. package/dist/runtime/entities/std-mock-seed.d.ts +0 -87
  155. package/dist/runtime/entities/std-mock-seed.js +0 -2
  156. package/dist/runtime/time/TickScheduler.d.ts +0 -77
  157. package/dist/runtime/time/TickScheduler.js +0 -3
  158. package/dist/runtime/time/cron.d.ts +0 -25
  159. package/dist/runtime/time/cron.js +0 -2
  160. package/dist/runtime/time/duration.d.ts +0 -20
  161. package/dist/runtime/time/duration.js +0 -2
  162. package/dist/runtime/traits/OrbitalTraitParsing.d.ts +0 -34
  163. package/dist/runtime/traits/OrbitalTraitParsing.js +0 -2
  164. package/dist/runtime/traits/listen-targets.d.ts +0 -16
  165. package/dist/runtime/traits/listen-targets.js +0 -3
  166. package/dist/runtime/traits/trait-index.d.ts +0 -35
  167. package/dist/runtime/traits/trait-index.js +0 -3
@@ -1,232 +0,0 @@
1
- import { createHttpTransport } from './chunk-QELZ6TEJ.js';
2
- import { createLogger } from '@almadar/logger';
3
-
4
- var log = createLogger("almadar:runtime:server-bridge");
5
- var ServerBridge = class {
6
- config;
7
- state = {
8
- connected: false,
9
- eventsForwarded: 0,
10
- eventsReceived: 0
11
- };
12
- unsubscribes = [];
13
- pollTimer;
14
- ws;
15
- fetchFn;
16
- /** The one HTTP request/response leg — shared with `@almadar/ui`'s transport (P5, EventTransport.ts). */
17
- transport;
18
- constructor(config) {
19
- this.config = {
20
- pollInterval: 5e3,
21
- ...config
22
- };
23
- this.fetchFn = config.fetch || fetch.bind(globalThis);
24
- this.transport = createHttpTransport({ serverUrl: config.serverUrl, fetch: this.fetchFn });
25
- }
26
- // ==========================================================================
27
- // Connection Management
28
- // ==========================================================================
29
- /**
30
- * Connect the bridge - start forwarding events
31
- */
32
- connect() {
33
- if (this.state.connected) {
34
- this.log("warn", "Already connected");
35
- return;
36
- }
37
- this.log("info", "Connecting bridge...");
38
- this.setupEventForwarding();
39
- if (this.config.useWebSocket) {
40
- this.setupWebSocket();
41
- } else if (this.config.pollInterval && this.config.pollInterval > 0) {
42
- this.setupPolling();
43
- }
44
- this.state.connected = true;
45
- this.log("info", "Bridge connected");
46
- }
47
- /**
48
- * Disconnect the bridge
49
- */
50
- disconnect() {
51
- for (const unsub of this.unsubscribes) {
52
- unsub();
53
- }
54
- this.unsubscribes = [];
55
- if (this.pollTimer) {
56
- clearInterval(this.pollTimer);
57
- this.pollTimer = void 0;
58
- }
59
- if (this.ws) {
60
- this.ws.close();
61
- this.ws = void 0;
62
- }
63
- this.state.connected = false;
64
- this.log("info", "Bridge disconnected");
65
- }
66
- /**
67
- * Get current bridge state
68
- */
69
- getState() {
70
- return { ...this.state };
71
- }
72
- // ==========================================================================
73
- // Event Forwarding (Client -> Server)
74
- // ==========================================================================
75
- setupEventForwarding() {
76
- const { eventBus, forwardEvents, forwardPattern } = this.config;
77
- if (forwardEvents && forwardEvents.length > 0) {
78
- for (const eventType of forwardEvents) {
79
- const unsub = eventBus.on(eventType, (event) => {
80
- this.forwardToServer(event);
81
- });
82
- this.unsubscribes.push(unsub);
83
- }
84
- } else if (forwardPattern) {
85
- if (forwardPattern === "*") {
86
- const unsub = eventBus.on("*", (event) => {
87
- if (!event.type.startsWith("UI:") && !event.type.startsWith("BRIDGE:")) {
88
- this.forwardToServer(event);
89
- }
90
- });
91
- this.unsubscribes.push(unsub);
92
- } else {
93
- const prefix = forwardPattern.replace("*", "");
94
- const unsub = eventBus.on("*", (event) => {
95
- if (event.type.startsWith(prefix)) {
96
- this.forwardToServer(event);
97
- }
98
- });
99
- this.unsubscribes.push(unsub);
100
- }
101
- }
102
- }
103
- async forwardToServer(event) {
104
- const { serverUrl, targetOrbital } = this.config;
105
- try {
106
- if (targetOrbital && targetOrbital !== "broadcast") {
107
- await this.sendEventToOrbital(targetOrbital, event);
108
- } else {
109
- const orbitals = await this.fetchOrbitals();
110
- for (const orbital of orbitals) {
111
- await this.sendEventToOrbital(orbital.name, event);
112
- }
113
- }
114
- this.state.eventsForwarded++;
115
- this.log("debug", `Forwarded event: ${event.type}`);
116
- } catch (error) {
117
- this.state.lastError = String(error);
118
- this.log("error", `Failed to forward event: ${event.type}`, error instanceof Error ? error : String(error));
119
- }
120
- }
121
- async sendEventToOrbital(orbitalName, event) {
122
- const request = { event: event.type, payload: event.payload };
123
- const result = await this.transport.send(orbitalName, request);
124
- if (result.emittedEvents && result.emittedEvents.length > 0) {
125
- for (const emitted of result.emittedEvents) {
126
- this.config.eventBus.emit(`SERVER:${emitted.event}`, emitted.payload);
127
- this.state.eventsReceived++;
128
- }
129
- }
130
- }
131
- async fetchOrbitals() {
132
- const response = await this.fetchFn(this.config.serverUrl);
133
- if (!response.ok) {
134
- throw new Error(`Failed to fetch orbitals: ${response.status}`);
135
- }
136
- const data = await response.json();
137
- return data.orbitals || [];
138
- }
139
- // ==========================================================================
140
- // Server -> Client (Polling)
141
- // ==========================================================================
142
- setupPolling() {
143
- this.log("debug", "Polling mode - events received via forward response");
144
- }
145
- // ==========================================================================
146
- // Server -> Client (WebSocket)
147
- // ==========================================================================
148
- setupWebSocket() {
149
- const { serverUrl } = this.config;
150
- const wsUrl = serverUrl.replace(/^http:/, "ws:").replace(/^https:/, "wss:").replace(/\/api\/orbitals$/, "/ws/orbitals");
151
- try {
152
- this.ws = new WebSocket(wsUrl);
153
- this.ws.onopen = () => {
154
- this.log("info", "WebSocket connected");
155
- };
156
- this.ws.onmessage = (msg) => {
157
- try {
158
- const data = JSON.parse(msg.data);
159
- if (data.type === "event") {
160
- this.config.eventBus.emit(`SERVER:${data.event}`, data.payload);
161
- this.state.eventsReceived++;
162
- this.log("debug", `Received server event: ${data.event}`);
163
- }
164
- } catch (error) {
165
- this.log("error", "Failed to parse WebSocket message", error instanceof Error ? error : String(error));
166
- }
167
- };
168
- this.ws.onerror = (error) => {
169
- this.state.lastError = "WebSocket error";
170
- this.log("error", "WebSocket error", error);
171
- };
172
- this.ws.onclose = () => {
173
- this.log("info", "WebSocket closed");
174
- };
175
- } catch (error) {
176
- this.log("error", "Failed to create WebSocket", error instanceof Error ? error : String(error));
177
- }
178
- }
179
- // ==========================================================================
180
- // Direct Methods
181
- // ==========================================================================
182
- /**
183
- * Send an event directly to a specific orbital (bypassing EventBus)
184
- */
185
- async sendEvent(orbitalName, event, payload) {
186
- try {
187
- const result = await this.transport.send(orbitalName, { event, payload });
188
- return {
189
- success: result.success,
190
- states: result.states,
191
- emittedEvents: result.emittedEvents,
192
- error: result.error
193
- };
194
- } catch (error) {
195
- return { success: false, error: String(error) };
196
- }
197
- }
198
- /**
199
- * Get current state of an orbital's traits
200
- */
201
- async getOrbitalState(orbitalName) {
202
- const { serverUrl } = this.config;
203
- const url = `${serverUrl}/${orbitalName}`;
204
- try {
205
- const response = await this.fetchFn(url);
206
- const data = await response.json();
207
- if (data.success && data.orbital) {
208
- const states = {};
209
- for (const trait of data.orbital.traits) {
210
- states[trait.name] = trait.currentState;
211
- }
212
- return { success: true, states };
213
- }
214
- return { success: false, error: data.error };
215
- } catch (error) {
216
- return { success: false, error: String(error) };
217
- }
218
- }
219
- // ==========================================================================
220
- // Utilities
221
- // ==========================================================================
222
- log(level, message, data) {
223
- if (!this.config.debug && level === "debug") return;
224
- const meta = data === void 0 ? {} : data instanceof Error ? { error: data } : { detail: typeof data === "string" ? data : JSON.stringify(data) };
225
- log[level](message, meta);
226
- }
227
- };
228
- function createServerBridge(config) {
229
- return new ServerBridge(config);
230
- }
231
-
232
- export { ServerBridge, createServerBridge };
@@ -1,63 +0,0 @@
1
- // src/runtime/effects/composition/layout-strategy.ts
2
- function hasSequentialChain(wiring) {
3
- if (wiring.length < 2) {
4
- return false;
5
- }
6
- const adjacency = /* @__PURE__ */ new Map();
7
- const allTargets = /* @__PURE__ */ new Set();
8
- for (const entry of wiring) {
9
- let targets = adjacency.get(entry.from);
10
- if (!targets) {
11
- targets = /* @__PURE__ */ new Set();
12
- adjacency.set(entry.from, targets);
13
- }
14
- targets.add(entry.to);
15
- allTargets.add(entry.to);
16
- }
17
- const roots = [];
18
- for (const from of adjacency.keys()) {
19
- if (!allTargets.has(from)) {
20
- roots.push(from);
21
- }
22
- }
23
- const starts = roots.length > 0 ? roots : [...adjacency.keys()];
24
- for (const start of starts) {
25
- let current = start;
26
- let length = 1;
27
- const visited = /* @__PURE__ */ new Set([current]);
28
- while (true) {
29
- const nexts = adjacency.get(current);
30
- if (!nexts || nexts.size === 0) break;
31
- let advanced = false;
32
- for (const next of nexts) {
33
- if (!visited.has(next)) {
34
- visited.add(next);
35
- current = next;
36
- length++;
37
- advanced = true;
38
- break;
39
- }
40
- }
41
- if (!advanced) break;
42
- }
43
- if (length >= 3) {
44
- return true;
45
- }
46
- }
47
- return false;
48
- }
49
- function detectLayoutStrategy(orbitals, eventWiring) {
50
- if (eventWiring && eventWiring.length > 0 && hasSequentialChain(eventWiring)) {
51
- return "wizard-flow";
52
- }
53
- const count = orbitals.length;
54
- if (count <= 1) {
55
- return "single";
56
- }
57
- if (count <= 4) {
58
- return "tabs";
59
- }
60
- return "sidebar";
61
- }
62
-
63
- export { detectLayoutStrategy };
@@ -1,10 +0,0 @@
1
- // src/runtime/effects/composition/pipe.ts
2
- function pipeBehaviors(seed, ...steps) {
3
- let current = seed;
4
- for (const step of steps) {
5
- current = step(current);
6
- }
7
- return current;
8
- }
9
-
10
- export { pipeBehaviors };
@@ -1,135 +0,0 @@
1
- import { eventPayloadOf, isInlineTrait, normalizeCallSiteConfigToValues, JsonValueSchema, isJsonObject, EntityRowSchema, orbitalInlineEntities } from '@almadar/core';
2
- import { ownerFieldsFromSchema } from '@almadar/core/mock';
3
-
4
- // src/runtime/entities/std-mock-seed.ts
5
- var SEED_ORBITAL = "MockSeedOrbital";
6
- var SEED_TRAIT = "MockSeed";
7
- function asJson(value) {
8
- return JsonValueSchema.parse(JSON.parse(JSON.stringify(value)));
9
- }
10
- function fieldOf(value, name, what) {
11
- if (value === void 0 || !isJsonObject(value)) throw new Error(`std-mock-seed: ${what} is not an object`);
12
- const found = value[name];
13
- if (found === void 0) throw new Error(`std-mock-seed: ${what} has no ${name}`);
14
- return found;
15
- }
16
- function textOf(value, what) {
17
- if (typeof value !== "string") throw new Error(`std-mock-seed: ${what} is not a string`);
18
- return value;
19
- }
20
- function cellOf(value) {
21
- return {
22
- store: textOf(fieldOf(value, "store", "owner cell"), "cell store"),
23
- id: textOf(fieldOf(value, "id", "owner cell"), "cell id"),
24
- column: textOf(fieldOf(value, "column", "owner cell"), "cell column")
25
- };
26
- }
27
- function cellsOf(value, what) {
28
- if (!Array.isArray(value)) throw new Error(`std-mock-seed: ${what} is not an array`);
29
- return value.map(cellOf);
30
- }
31
- function journalOf(value) {
32
- return {
33
- viewerId: textOf(fieldOf(value, "viewerId", "journal"), "journal viewerId"),
34
- stamped: cellsOf(fieldOf(value, "stamped", "journal"), "journal stamped"),
35
- deferred: cellsOf(fieldOf(value, "deferred", "journal"), "journal deferred")
36
- };
37
- }
38
- function changeOf(value) {
39
- const kind = fieldOf(value, "kind", "owner change");
40
- if (kind !== "set" && kind !== "rekey") throw new Error("std-mock-seed: owner change kind is neither set nor rekey");
41
- return { ...cellOf(value), kind, ownerId: textOf(fieldOf(value, "ownerId", "owner change"), "change ownerId") };
42
- }
43
- function storesOf(value) {
44
- if (!isJsonObject(value)) throw new Error("std-mock-seed: dataset stores is not an object");
45
- return Object.fromEntries(Object.entries(value).map(([store, rows]) => [store, EntityRowSchema.array().parse(rows)]));
46
- }
47
- function ownerPairsOf(schema) {
48
- return ownerFieldsFromSchema(schema).map((field) => {
49
- const dot = field.indexOf(".");
50
- if (dot <= 0 || dot === field.length - 1) throw new Error(`std-mock-seed: owner field ${field} is not Entity.column`);
51
- return { entity: field.slice(0, dot), column: field.slice(dot + 1) };
52
- });
53
- }
54
- var StdMockSeed = class {
55
- constructor(engine, config, user) {
56
- this.engine = engine;
57
- this.config = config;
58
- this.user = user;
59
- }
60
- engine;
61
- config;
62
- user;
63
- async ask(event, payload, done) {
64
- const response = await this.engine.evaluate(
65
- SEED_ORBITAL,
66
- { event, targetTrait: SEED_TRAIT, payload: eventPayloadOf(asJson(payload)) },
67
- { orbital: SEED_ORBITAL, ...this.user !== void 0 ? { user: this.user } : {} }
68
- );
69
- const failed = response.emittedEvents.find((emitted) => emitted.event === "DATASET_FAILED");
70
- if (failed !== void 0) throw new Error(`std-mock-seed: ${event} refused: ${JSON.stringify(failed.payload ?? {})}`);
71
- const answer = response.emittedEvents.find((emitted) => emitted.event === done);
72
- if (answer === void 0) throw new Error(`std-mock-seed: ${event} did not answer ${done}`);
73
- return asJson(answer.payload ?? {});
74
- }
75
- /** Sample the program's dataset (`DATASET_INPUT`). */
76
- async dataset(program, run) {
77
- const done = await this.ask("DATASET_INPUT", {
78
- program,
79
- count: this.config.count,
80
- seed: this.config.seed,
81
- nowMs: run.nowMs,
82
- viewerId: run.viewerId ?? "",
83
- ownerPairs: ownerPairsOf(program),
84
- ...run.locale !== void 0 ? { locale: run.locale } : {}
85
- }, "DATASET_DONE");
86
- return { stores: storesOf(fieldOf(done, "stores", "DATASET_DONE")), journal: journalOf(fieldOf(done, "journal", "DATASET_DONE")) };
87
- }
88
- /**
89
- * Re-point the dataset's tracked owner cells at `viewer` (`RESTAMP_INPUT`); `stores` are the current authoritative rows.
90
- * `firstOwner` marks the stamp right after seeding; a persona switch restamps only when the program's
91
- * `restampOnPersona` config says so, otherwise it answers no changes.
92
- */
93
- async restamp(program, stores, journal, viewer, firstOwner) {
94
- const done = await this.ask("RESTAMP_INPUT", { program, stores, journal, viewer, firstOwner, restampOnPersona: this.config.restampOnPersona }, "RESTAMP_DONE");
95
- const changes = fieldOf(done, "changes", "RESTAMP_DONE");
96
- if (!Array.isArray(changes)) throw new Error("std-mock-seed: RESTAMP_DONE changes is not an array");
97
- return { journal: journalOf(fieldOf(done, "journal", "RESTAMP_DONE")), changes: changes.map(changeOf) };
98
- }
99
- };
100
- var STD_MOCK_SEED_SOURCE = "std/behaviors/std-mock-seed";
101
- var SEED_TRAIT_REF = "traits.MockSeed";
102
- function declaredValue(values, key, is) {
103
- const value = values[key];
104
- if (value === void 0 || !is(value)) throw new Error(`std-mock-seed: config ${key} is not declared as expected`);
105
- return value;
106
- }
107
- function declaredSeedConfig(seedProgram, app) {
108
- const seedTrait = seedProgram.orbitals.flatMap((orbital) => orbital.traits ?? []).find((t) => isInlineTrait(t) && t.name === SEED_TRAIT);
109
- if (seedTrait === void 0 || !isInlineTrait(seedTrait)) throw new Error(`std-mock-seed: the seed program has no ${SEED_TRAIT} trait`);
110
- const composed = (app?.orbitals ?? []).flatMap((orbital) => {
111
- const aliases = (orbital.uses ?? []).filter((u) => u.from === STD_MOCK_SEED_SOURCE).map((u) => u.as);
112
- return (orbital.traits ?? []).flatMap((t) => typeof t !== "string" && !isInlineTrait(t) && aliases.some((alias) => t.ref === `${alias}.${SEED_TRAIT_REF}`) ? [normalizeCallSiteConfigToValues(t.config) ?? {}] : []);
113
- });
114
- const values = Object.assign({}, normalizeCallSiteConfigToValues(seedTrait.config) ?? {}, ...composed);
115
- return {
116
- count: declaredValue(values, "count", (v) => typeof v === "number"),
117
- seed: declaredValue(values, "seed", (v) => typeof v === "number"),
118
- defaultPersona: declaredValue(values, "defaultPersona", (v) => typeof v === "string"),
119
- restampOnPersona: declaredValue(values, "restampOnPersona", (v) => typeof v === "boolean")
120
- };
121
- }
122
- function entityByStore(program) {
123
- const byStore = /* @__PURE__ */ new Map();
124
- for (const entity of program.orbitals.flatMap(orbitalInlineEntities)) {
125
- if (entity.collection !== void 0 && entity.collection !== "") byStore.set(entity.collection, entity.name);
126
- }
127
- return byStore;
128
- }
129
- async function readSeededStores(persistence, program) {
130
- const stores = {};
131
- for (const [store, entityType] of entityByStore(program)) stores[store] = await persistence.list(entityType);
132
- return stores;
133
- }
134
-
135
- export { StdMockSeed, declaredSeedConfig, readSeededStores };
@@ -1,62 +0,0 @@
1
- // src/runtime/events/identity/routing.ts
2
- function eventRouteKey(eventName, eventId) {
3
- return eventId ? `@evt:${eventId}` : eventName;
4
- }
5
- function buildSourceMatcher(src, listenerOrbital) {
6
- if (src.kind === "any") return () => true;
7
- if (src.kind === "trait") {
8
- if (src.traitId !== void 0) {
9
- const wantedTraitId = src.traitId;
10
- return (source) => !!source && source.traitId === wantedTraitId;
11
- }
12
- const wantedTrait2 = src.trait;
13
- return (source) => !!source && source.orbital === listenerOrbital && source.trait === wantedTrait2;
14
- }
15
- if (src.orbitalId !== void 0 && src.traitId !== void 0) {
16
- const wantedOrbitalId = src.orbitalId;
17
- const wantedTraitId = src.traitId;
18
- return (source) => !!source && source.orbitalId === wantedOrbitalId && source.traitId === wantedTraitId;
19
- }
20
- const wantedOrbital = src.orbital;
21
- const wantedTrait = src.trait;
22
- return (source) => !!source && source.orbital === wantedOrbital && source.trait === wantedTrait;
23
- }
24
- function parseListenSource(listener, listenerOrbital) {
25
- const explicit = listener.source;
26
- if (explicit && typeof explicit === "object") {
27
- return {
28
- bareEvent: listener.event,
29
- matcher: buildSourceMatcher(explicit, listenerOrbital)
30
- };
31
- }
32
- const key = listener.event;
33
- const parts = key.split(".");
34
- if (parts.length === 1) {
35
- return { bareEvent: key, matcher: () => true };
36
- }
37
- if (parts.length === 2) {
38
- const [sourceOrStar, eventName] = parts;
39
- if (sourceOrStar === "*") {
40
- return { bareEvent: eventName, matcher: () => true };
41
- }
42
- return {
43
- bareEvent: eventName,
44
- matcher: buildSourceMatcher(
45
- { kind: "trait", trait: sourceOrStar },
46
- listenerOrbital
47
- )
48
- };
49
- }
50
- if (parts.length >= 3) {
51
- const eventName = parts[parts.length - 1];
52
- const trait = parts[parts.length - 2];
53
- const orbital = parts.slice(0, parts.length - 2).join(".");
54
- return {
55
- bareEvent: eventName,
56
- matcher: buildSourceMatcher({ kind: "orbital", orbital, trait }, listenerOrbital)
57
- };
58
- }
59
- return { bareEvent: key, matcher: () => true };
60
- }
61
-
62
- export { buildSourceMatcher, eventRouteKey, parseListenSource };
@@ -1,35 +0,0 @@
1
- import { readSeededStores } from './chunk-HMK6YMQS.js';
2
- import { orbitalInlineEntities, personaFromIdentityRow } from '@almadar/core';
3
- import { identityEntitiesOf } from '@almadar/core/mock';
4
- import { createLogger } from '@almadar/logger';
5
-
6
- var log = createLogger("almadar:shell-web:mock-seed");
7
- function bindDeclaredCollections(store, entities) {
8
- for (const entity of entities) {
9
- if (entity.name && entity.collection && entity.browser !== true && entity.persistence !== "runtime") {
10
- store.bindCollection?.(entity.name, entity.collection);
11
- }
12
- }
13
- }
14
- async function seedMockStore(host, schema, viewer) {
15
- bindDeclaredCollections(host.persistence, schema.orbitals.flatMap(orbitalInlineEntities));
16
- const named = viewer.namedByHost ? viewer.current() : void 0;
17
- const dataset = await host.seeder.dataset(schema, { nowMs: host.nowMs, ...named !== void 0 ? { viewerId: named.id } : {} });
18
- if (viewer.namedByHost) return { viewer: named, journal: dataset.journal };
19
- const declared = host.seeder.config.defaultPersona;
20
- if (declared === "") return { viewer: void 0, journal: dataset.journal };
21
- const identity = identityEntitiesOf(schema.orbitals)[0];
22
- const row = identity?.collection !== void 0 ? (dataset.stores[identity.collection] ?? []).find((r) => r.id === declared) : void 0;
23
- const resolved = row === void 0 ? void 0 : personaFromIdentityRow(row);
24
- if (resolved === void 0) throw new Error(`std-mock-seed: defaultPersona ${declared} names no ${identity?.name ?? "identity"} row of the seeded dataset`);
25
- const restamp = await host.seeder.restamp(schema, dataset.stores, dataset.journal, resolved, true);
26
- log.debug("seeded", { identity: identity?.name, viewer: resolved.id, changes: restamp.changes.length });
27
- return { viewer: resolved, journal: restamp.journal };
28
- }
29
- async function restampMockOwner(host, schema, journal, user) {
30
- const stores = await readSeededStores(host.persistence, schema);
31
- const restamp = await host.seeder.restamp(schema, stores, journal, user, false);
32
- return restamp.journal;
33
- }
34
-
35
- export { bindDeclaredCollections, restampMockOwner, seedMockStore };
@@ -1,54 +0,0 @@
1
- import { isInlineTrait } from '@almadar/core';
2
-
3
- // src/runtime/effects/composition/event-wiring.ts
4
- function findInlineTrait(orbitals, name) {
5
- for (const orbital of orbitals) {
6
- for (const traitRef of orbital.traits) {
7
- if (isInlineTrait(traitRef) && traitRef.name === name) {
8
- return traitRef;
9
- }
10
- }
11
- }
12
- return null;
13
- }
14
- function hasEmit(emits, event) {
15
- return emits.some((e) => e.event === event);
16
- }
17
- function hasListen(listens, event, triggers) {
18
- return listens.some((l) => l.event === event && l.triggers === triggers);
19
- }
20
- function applyEventWiring(orbitals, wiring) {
21
- const cloned = JSON.parse(
22
- JSON.stringify(orbitals)
23
- );
24
- for (const entry of wiring) {
25
- const sourceTrait = findInlineTrait(cloned, entry.from);
26
- if (sourceTrait) {
27
- if (!sourceTrait.emits) {
28
- sourceTrait.emits = [];
29
- }
30
- if (!hasEmit(sourceTrait.emits, entry.event)) {
31
- sourceTrait.emits.push({
32
- event: entry.event,
33
- scope: "external"
34
- });
35
- }
36
- }
37
- const targetTrait = findInlineTrait(cloned, entry.to);
38
- if (targetTrait) {
39
- if (!targetTrait.listens) {
40
- targetTrait.listens = [];
41
- }
42
- if (!hasListen(targetTrait.listens, entry.event, entry.triggers)) {
43
- targetTrait.listens.push({
44
- event: entry.event,
45
- triggers: entry.triggers,
46
- scope: "external"
47
- });
48
- }
49
- }
50
- }
51
- return cloned;
52
- }
53
-
54
- export { applyEventWiring };
@@ -1,7 +0,0 @@
1
- var __defProp = Object.defineProperty;
2
- var __export = (target, all) => {
3
- for (var name in all)
4
- __defProp(target, name, { get: all[name], enumerable: true });
5
- };
6
-
7
- export { __export };