@almadar/runtime 6.3.1 → 6.4.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.
@@ -34,7 +34,6 @@ import { P as PersistenceAdapter } from './PersistenceAdapter-B6dQCbbU.js';
34
34
  */
35
35
  declare class EventBus implements IEventBus {
36
36
  private listeners;
37
- private debug;
38
37
  /** Maximum recursion depth before circuit breaker activates (RCG-05) */
39
38
  private maxDepth;
40
39
  /** Current emission depth for circular loop detection */
@@ -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-BMRm0DUS.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-BtG18R0H.js';
4
4
  import './types-cuy5gd29.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-E2YFJ6YP.js';
1
+ export { InMemoryPersistence, OrbitalServerRuntime, collectDeclaredConfigDefaults, createOrbitalServerRuntime } from './chunk-ODKFBOQG.js';
2
2
  import './chunk-PZ5AY32C.js';
3
3
  //# sourceMappingURL=OrbitalServerRuntime.js.map
4
4
  //# sourceMappingURL=OrbitalServerRuntime.js.map
@@ -1,3 +1,4 @@
1
+ import { createLogger } from '@almadar/logger';
1
2
  import { resolveBinding, evaluate, createMinimalContext, evaluateGuard } from '@almadar/evaluator';
2
3
  export { createMinimalContext } from '@almadar/evaluator';
3
4
  import { isKnownOperator } from '@almadar/std';
@@ -6,15 +7,15 @@ import { isInlineTrait, isEntityCall, OrbitalSchemaSchema, isEntityReference, pa
6
7
  import { faker } from '@faker-js/faker';
7
8
 
8
9
  // src/EventBus.ts
10
+ var log = createLogger("almadar:runtime:eventbus");
9
11
  var EventBus = class {
10
12
  listeners = /* @__PURE__ */ new Map();
11
- debug;
12
13
  /** Maximum recursion depth before circuit breaker activates (RCG-05) */
13
14
  maxDepth;
14
15
  /** Current emission depth for circular loop detection */
15
16
  depth = 0;
16
17
  constructor(options = {}) {
17
- this.debug = options.debug ?? false;
18
+ void options.debug;
18
19
  this.maxDepth = options.maxDepth ?? 10;
19
20
  }
20
21
  /**
@@ -26,9 +27,7 @@ var EventBus = class {
26
27
  */
27
28
  emit(type, payload, source) {
28
29
  if (this.depth >= this.maxDepth) {
29
- console.error(
30
- `[EventBus] Circular event loop detected: "${type}" at depth ${this.depth}. Event dropped to prevent infinite recursion. Increase maxDepth (currently ${this.maxDepth}) if this is intentional.`
31
- );
30
+ log.error("circular event loop dropped", { type, depth: this.depth, maxDepth: this.maxDepth });
32
31
  return;
33
32
  }
34
33
  const event = {
@@ -39,12 +38,10 @@ var EventBus = class {
39
38
  };
40
39
  const listeners = this.listeners.get(type);
41
40
  const listenerCount = listeners?.size ?? 0;
42
- if (this.debug) {
43
- if (listenerCount > 0) {
44
- console.log(`[EventBus] Emit: ${type} \u2192 ${listenerCount} listener(s) (depth: ${this.depth})`, payload);
45
- } else {
46
- console.warn(`[EventBus] Emit: ${type} (NO LISTENERS)`, payload);
47
- }
41
+ if (listenerCount > 0) {
42
+ log.debug("emit", { type, listenerCount, depth: this.depth });
43
+ } else {
44
+ log.warn("emit no listeners", { type });
48
45
  }
49
46
  this.depth++;
50
47
  try {
@@ -54,7 +51,7 @@ var EventBus = class {
54
51
  try {
55
52
  listener(event);
56
53
  } catch (error) {
57
- console.error(`[EventBus] Error in listener for '${type}':`, error);
54
+ log.error("listener threw", { type, error: error instanceof Error ? error : String(error) });
58
55
  }
59
56
  }
60
57
  }
@@ -65,7 +62,7 @@ var EventBus = class {
65
62
  try {
66
63
  listener(event);
67
64
  } catch (error) {
68
- console.error(`[EventBus] Error in wildcard listener:`, error);
65
+ log.error("wildcard listener threw", { error: error instanceof Error ? error : String(error) });
69
66
  }
70
67
  }
71
68
  }
@@ -83,14 +80,10 @@ var EventBus = class {
83
80
  }
84
81
  const listeners = this.listeners.get(type);
85
82
  listeners.add(listener);
86
- if (this.debug) {
87
- console.log(`[EventBus] Subscribed to '${type}', total: ${listeners.size}`);
88
- }
83
+ log.debug("subscribe", { type, total: listeners.size });
89
84
  return () => {
90
85
  listeners.delete(listener);
91
- if (this.debug) {
92
- console.log(`[EventBus] Unsubscribed from '${type}', remaining: ${listeners.size}`);
93
- }
86
+ log.debug("unsubscribe", { type, remaining: listeners.size });
94
87
  if (listeners.size === 0) {
95
88
  this.listeners.delete(type);
96
89
  }
@@ -120,9 +113,7 @@ var EventBus = class {
120
113
  * Clear all listeners
121
114
  */
122
115
  clear() {
123
- if (this.debug) {
124
- console.log(`[EventBus] Clearing all listeners (${this.listeners.size} event types)`);
125
- }
116
+ log.debug("clear", { eventTypeCount: this.listeners.size });
126
117
  this.listeners.clear();
127
118
  }
128
119
  /**
@@ -132,52 +123,6 @@ var EventBus = class {
132
123
  return this.listeners.get(type)?.size ?? 0;
133
124
  }
134
125
  };
135
-
136
- // src/logger.ts
137
- var LEVEL_PRIORITY = { DEBUG: 0, INFO: 1, WARN: 2, ERROR: 3 };
138
- var ENV = typeof process !== "undefined" && process.env ? process.env : {};
139
- var NODE_ENV = ENV.NODE_ENV ?? "development";
140
- var CONFIGURED_LEVEL = (ENV.LOG_LEVEL ?? (NODE_ENV === "production" ? "info" : "debug")).toUpperCase();
141
- var MIN_PRIORITY = LEVEL_PRIORITY[CONFIGURED_LEVEL] ?? 0;
142
- var DEBUG_FILTER = (ENV.ALMADAR_DEBUG ?? "").split(",").map((s) => s.trim()).filter(Boolean);
143
- function matchesNamespace(namespace) {
144
- if (DEBUG_FILTER.length === 0) return true;
145
- return DEBUG_FILTER.some((pattern) => {
146
- if (pattern === "*" || pattern === "almadar:*") return true;
147
- if (pattern.endsWith(":*")) return namespace.startsWith(pattern.slice(0, -1));
148
- return namespace === pattern;
149
- });
150
- }
151
- function createLogger(namespace) {
152
- const nsAllowed = matchesNamespace(namespace);
153
- const log = (level, message, data) => {
154
- if (LEVEL_PRIORITY[level] < MIN_PRIORITY) return;
155
- if (level === "DEBUG" && !nsAllowed) return;
156
- const prefix = `[${namespace}]`;
157
- switch (level) {
158
- case "DEBUG":
159
- console.debug(prefix, message, data ?? "");
160
- break;
161
- case "INFO":
162
- console.info(prefix, message, data ?? "");
163
- break;
164
- case "WARN":
165
- console.warn(prefix, message, data ?? "");
166
- break;
167
- case "ERROR":
168
- console.error(prefix, message, data ?? "");
169
- break;
170
- }
171
- };
172
- return {
173
- debug: (msg, data) => log("DEBUG", msg, data),
174
- info: (msg, data) => log("INFO", msg, data),
175
- warn: (msg, data) => log("WARN", msg, data),
176
- error: (msg, data) => log("ERROR", msg, data)
177
- };
178
- }
179
-
180
- // src/BindingResolver.ts
181
126
  var bindLog = createLogger("almadar:runtime:bindings");
182
127
  var renderLog = createLogger("almadar:runtime:render-ui");
183
128
  var CLIENT_ONLY_BINDING_ROOTS = /* @__PURE__ */ new Set(["trait"]);
@@ -200,40 +145,44 @@ function interpolateProps(props, ctx) {
200
145
  const typeBindingRaw = props["type"];
201
146
  const patternType = typeof typeBindingRaw === "string" ? typeBindingRaw : void 0;
202
147
  if (typeof entityBindingRaw === "string") {
203
- const resolvedEntity = result["entity"];
204
- const resolvedRow = resolvedEntity !== null && typeof resolvedEntity === "object" && !Array.isArray(resolvedEntity) ? resolvedEntity : null;
205
- const ctxRow = ctx.payload["row"];
206
- const ctxPayloadKeys = Object.keys(ctx.payload).join(",");
207
- const payloadDataRaw = ctx.payload["data"];
208
- const payloadDataLen = Array.isArray(payloadDataRaw) ? payloadDataRaw.length : null;
209
- const ctxEntityRaw = ctx.entity;
210
- const ctxEntityLen = Array.isArray(ctxEntityRaw) ? ctxEntityRaw.length : null;
211
- const resolvedLen = Array.isArray(resolvedEntity) ? resolvedEntity.length : null;
212
- renderLog.debug("interpolateProps:entity", {
213
- patternType,
214
- entityBinding: entityBindingRaw,
215
- resolvedIsObject: resolvedRow !== null,
216
- resolvedIsArray: Array.isArray(resolvedEntity),
217
- resolvedLen,
218
- resolvedEqualsCtxRow: ctxRow !== void 0 && resolvedRow !== null && resolvedRow === ctxRow,
219
- resolvedRowId: resolvedRow?.id,
220
- ctxPayloadKeys,
221
- ctxPayloadDataLen: payloadDataLen,
222
- ctxEntityIsArray: Array.isArray(ctxEntityRaw),
223
- ctxEntityLen
148
+ renderLog.debug("interpolateProps:entity", () => {
149
+ const resolvedEntity = result["entity"];
150
+ const resolvedRow = resolvedEntity !== null && typeof resolvedEntity === "object" && !Array.isArray(resolvedEntity) ? resolvedEntity : null;
151
+ const ctxRow = ctx.payload["row"];
152
+ const ctxPayloadKeys = Object.keys(ctx.payload).join(",");
153
+ const payloadDataRaw = ctx.payload["data"];
154
+ const payloadDataLen = Array.isArray(payloadDataRaw) ? payloadDataRaw.length : null;
155
+ const ctxEntityRaw = ctx.entity;
156
+ const ctxEntityLen = Array.isArray(ctxEntityRaw) ? ctxEntityRaw.length : null;
157
+ const resolvedLen = Array.isArray(resolvedEntity) ? resolvedEntity.length : null;
158
+ return {
159
+ patternType,
160
+ entityBinding: entityBindingRaw,
161
+ resolvedIsObject: resolvedRow !== null,
162
+ resolvedIsArray: Array.isArray(resolvedEntity),
163
+ resolvedLen,
164
+ resolvedEqualsCtxRow: ctxRow !== void 0 && resolvedRow !== null && resolvedRow === ctxRow,
165
+ resolvedRowId: resolvedRow?.id,
166
+ ctxPayloadKeys,
167
+ ctxPayloadDataLen: payloadDataLen,
168
+ ctxEntityIsArray: Array.isArray(ctxEntityRaw),
169
+ ctxEntityLen
170
+ };
224
171
  });
225
172
  }
226
173
  if (patternType === "form-section" || patternType === "form") {
227
- const modeRaw = result["mode"];
228
- const submitRaw = result["submitEvent"];
229
- const cancelRaw = result["cancelEvent"];
230
- bindLog.debug("form-binding", {
231
- patternType,
232
- mode: typeof modeRaw === "string" ? modeRaw : void 0,
233
- submitEvent: typeof submitRaw === "string" ? submitRaw : void 0,
234
- cancelEvent: typeof cancelRaw === "string" ? cancelRaw : void 0,
235
- entity: JSON.stringify(result["entity"] ?? null),
236
- fields: JSON.stringify(result["fields"] ?? null)
174
+ bindLog.debug("form-binding", () => {
175
+ const modeRaw = result["mode"];
176
+ const submitRaw = result["submitEvent"];
177
+ const cancelRaw = result["cancelEvent"];
178
+ return {
179
+ patternType,
180
+ mode: typeof modeRaw === "string" ? modeRaw : void 0,
181
+ submitEvent: typeof submitRaw === "string" ? submitRaw : void 0,
182
+ cancelEvent: typeof cancelRaw === "string" ? cancelRaw : void 0,
183
+ entity: JSON.stringify(result["entity"] ?? null),
184
+ fields: JSON.stringify(result["fields"] ?? null)
185
+ };
237
186
  });
238
187
  }
239
188
  return anyChanged ? result : props;
@@ -289,13 +238,13 @@ function interpolateArray(value, ctx) {
289
238
  }
290
239
  if (isSExpression(value)) {
291
240
  const result = evaluate(value, ctx);
292
- bindLog.info("sexpr:eval", {
241
+ bindLog.debug("sexpr:eval", () => ({
293
242
  operator: typeof value[0] === "string" ? value[0] : "<non-string>",
294
243
  argCount: value.length - 1,
295
244
  inputJson: JSON.stringify(value).slice(0, 300),
296
245
  resultType: typeof result,
297
246
  resultJson: typeof result === "object" && result !== null ? JSON.stringify(result).slice(0, 2e3) : String(result)
298
- });
247
+ }));
299
248
  return result;
300
249
  }
301
250
  const mapped = [];
@@ -886,8 +835,6 @@ var HANDLER_MANIFEST = {
886
835
  ],
887
836
  ssr: ["render-ui", "render", "fetch", "emit", "set", "log", "ref", "deref"]
888
837
  };
889
-
890
- // src/EffectExecutor.ts
891
838
  var effectLog = createLogger("almadar:runtime:effects");
892
839
  function parseEffect(effect) {
893
840
  if (!Array.isArray(effect) || effect.length === 0) {
@@ -1846,7 +1793,7 @@ var MockPersistenceAdapter = class {
1846
1793
  updatedAt: typeof item.updatedAt === "string" ? item.updatedAt : ""
1847
1794
  });
1848
1795
  }
1849
- mockLog.debug("mock:seed", { entityName, count, idsAndTimestamps: JSON.stringify(generated) });
1796
+ mockLog.debug("mock:seed", () => ({ entityName, count, idsAndTimestamps: JSON.stringify(generated) }));
1850
1797
  }
1851
1798
  /**
1852
1799
  * Generate a single mock item based on field schemas.
@@ -4380,7 +4327,7 @@ var OrbitalServerRuntime = class {
4380
4327
  payloadRowId: typeof payloadRowId === "string" || typeof payloadRowId === "number" ? payloadRowId : void 0,
4381
4328
  entityId: request.entityId
4382
4329
  });
4383
- busLog.debug("bus:incoming", {
4330
+ busLog.debug("bus:incoming", () => ({
4384
4331
  orbital: orbitalName,
4385
4332
  event: request.event,
4386
4333
  payload: JSON.stringify(request.payload ?? null),
@@ -4391,15 +4338,15 @@ var OrbitalServerRuntime = class {
4391
4338
  currentState: state.currentState
4392
4339
  }))
4393
4340
  )
4394
- });
4395
- xOrbitalLog.info("processOrbitalEvent:enter", {
4341
+ }));
4342
+ xOrbitalLog.info("processOrbitalEvent:enter", () => ({
4396
4343
  orbital: orbitalName,
4397
4344
  event: request.event,
4398
4345
  traitsInOrbital: registered.traits.map((t) => t.name).join(","),
4399
4346
  payloadActiveTraits: JSON.stringify(
4400
4347
  request.payload?.["_activeTraits"] ?? null
4401
4348
  )
4402
- });
4349
+ }));
4403
4350
  const { event, payload, entityId, user } = request;
4404
4351
  const validationFailures = [];
4405
4352
  for (const trait of registered.traits) {
@@ -4730,7 +4677,7 @@ var OrbitalServerRuntime = class {
4730
4677
  },
4731
4678
  fetch: async (fetchEntityType, options) => {
4732
4679
  try {
4733
- xOrbitalLog.info("fetch:enter", {
4680
+ xOrbitalLog.info("fetch:enter", () => ({
4734
4681
  entityType: fetchEntityType,
4735
4682
  hasOptions: options !== void 0 && options !== null,
4736
4683
  optionsKeys: options ? Object.keys(options).join(",") : "",
@@ -4738,7 +4685,7 @@ var OrbitalServerRuntime = class {
4738
4685
  filterIsArray: Array.isArray(options?.filter),
4739
4686
  filterJson: JSON.stringify(options?.filter ?? null).slice(0, 300),
4740
4687
  payloadJson: JSON.stringify(bindingsRef?.payload ?? null).slice(0, 300)
4741
- });
4688
+ }));
4742
4689
  let result = null;
4743
4690
  let total = 0;
4744
4691
  if (options?.id) {
@@ -5389,6 +5336,6 @@ function buildMatcher(src, listenerOrbital) {
5389
5336
  return (source) => !!source && source.orbital === wantedOrbital && source.trait === wantedTrait;
5390
5337
  }
5391
5338
 
5392
- 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 };
5393
- //# sourceMappingURL=chunk-E2YFJ6YP.js.map
5394
- //# sourceMappingURL=chunk-E2YFJ6YP.js.map
5339
+ export { EffectExecutor, EventBus, HANDLER_MANIFEST, InMemoryPersistence, MockPersistenceAdapter, OrbitalServerRuntime, StateMachineManager, buildEmitsFromTraits, collectDeclaredConfigDefaults, containsBindings, createContextFromBindings, createInitialTraitState, createMockPersistence, createOrbitalServerRuntime, createTestExecutor, createUnifiedLoader, extractBindings, findInitialState, findTransition, formatPayloadValidationError, getIsolatedCollectionName, getNamespacedEvent, interpolateProps, interpolateValue, isBrowser, isElectron, isNamespacedEvent, isNode, normalizeEventKey, parseNamespacedEvent, preprocessSchema, processEvent, validateEventPayload, validatePayloadShapes };
5340
+ //# sourceMappingURL=chunk-ODKFBOQG.js.map
5341
+ //# sourceMappingURL=chunk-ODKFBOQG.js.map