@almadar/runtime 1.0.15 → 1.0.17

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/index.d.ts CHANGED
@@ -259,6 +259,67 @@ declare class EffectExecutor {
259
259
  */
260
260
  declare function createTestExecutor(overrides?: Partial<EffectHandlers>): EffectExecutor;
261
261
 
262
+ /**
263
+ * Client Effect Handlers Factory
264
+ *
265
+ * Creates the standard effect handler set for client-side trait execution.
266
+ * Platform-agnostic — works with any UI framework that provides the required interfaces.
267
+ *
268
+ * @packageDocumentation
269
+ */
270
+
271
+ /**
272
+ * Minimal event bus interface required by the factory.
273
+ */
274
+ interface ClientEventBus {
275
+ emit: (type: string, payload?: Record<string, unknown>) => void;
276
+ }
277
+ /**
278
+ * Slot setter interface for render-ui effects.
279
+ * The factory doesn't know about React state — it just calls this function.
280
+ */
281
+ interface SlotSetter {
282
+ /** Accumulate a pattern into the pending slot map */
283
+ addPattern: (slot: string, pattern: unknown, props?: Record<string, unknown>) => void;
284
+ /** Mark a slot for clearing */
285
+ clearSlot: (slot: string) => void;
286
+ }
287
+ /**
288
+ * Options for creating client effect handlers.
289
+ */
290
+ interface CreateClientEffectHandlersOptions {
291
+ /** Event bus for emit effects */
292
+ eventBus: ClientEventBus;
293
+ /** Slot setter for render-ui effects */
294
+ slotSetter: SlotSetter;
295
+ /** Navigate function for navigate effects */
296
+ navigate?: (path: string, params?: Record<string, unknown>) => void;
297
+ /** Notify function for notification effects */
298
+ notify?: (message: string, type: 'success' | 'error' | 'warning' | 'info') => void;
299
+ /** Entity enrichment: inject linkedEntity into entity-aware patterns */
300
+ enrichPattern?: (pattern: unknown) => unknown;
301
+ }
302
+ /**
303
+ * Create client-side effect handlers for trait state machine execution.
304
+ *
305
+ * Client handles: emit, renderUI, navigate, notify
306
+ * Server handles: persist, set, callService (logged as warnings on client)
307
+ *
308
+ * @example
309
+ * ```ts
310
+ * const handlers = createClientEffectHandlers({
311
+ * eventBus,
312
+ * slotSetter: {
313
+ * addPattern: (slot, pattern, props) => pendingSlots.get(slot)?.push({ pattern, props }),
314
+ * clearSlot: (slot) => pendingSlots.set(slot, []),
315
+ * },
316
+ * navigate: (path) => router.push(path),
317
+ * notify: (msg, type) => toast[type](msg),
318
+ * });
319
+ * ```
320
+ */
321
+ declare function createClientEffectHandlers(options: CreateClientEffectHandlersOptions): EffectHandlers;
322
+
262
323
  /**
263
324
  * MockPersistenceAdapter - In-memory data store with faker-based mock generation
264
325
  *
@@ -290,4 +351,4 @@ interface MockPersistenceConfig {
290
351
  debug?: boolean;
291
352
  }
292
353
 
293
- export { BindingContext, EffectContext, EffectExecutor, type EffectExecutorOptions, EffectHandlers, type EntityField, type EntitySchema, type MockPersistenceConfig, type ProcessEventOptions, StateMachineManager, TraitDefinition, TraitState, TransitionResult, containsBindings, createContextFromBindings, createInitialTraitState, createTestExecutor, extractBindings, findInitialState, findTransition, interpolateProps, interpolateValue, normalizeEventKey, processEvent };
354
+ export { BindingContext, type ClientEventBus, type CreateClientEffectHandlersOptions, EffectContext, EffectExecutor, type EffectExecutorOptions, EffectHandlers, type EntityField, type EntitySchema, type MockPersistenceConfig, type ProcessEventOptions, type SlotSetter, StateMachineManager, TraitDefinition, TraitState, TransitionResult, containsBindings, createClientEffectHandlers, createContextFromBindings, createInitialTraitState, createTestExecutor, extractBindings, findInitialState, findTransition, interpolateProps, interpolateValue, normalizeEventKey, processEvent };
package/dist/index.js CHANGED
@@ -1,3 +1,40 @@
1
1
  export { EffectExecutor, EventBus, StateMachineManager, containsBindings, createContextFromBindings, createInitialTraitState, createMinimalContext, createTestExecutor, extractBindings, findInitialState, findTransition, getIsolatedCollectionName, getNamespacedEvent, interpolateProps, interpolateValue, isNamespacedEvent, normalizeEventKey, parseNamespacedEvent, preprocessSchema, processEvent } from './chunk-KUL6GQI5.js';
2
+
3
+ // src/ClientEffectHandlers.ts
4
+ function createClientEffectHandlers(options) {
5
+ const { eventBus, slotSetter, navigate, notify, enrichPattern } = options;
6
+ return {
7
+ emit: (event, payload) => {
8
+ const prefixedEvent = event.startsWith("UI:") ? event : `UI:${event}`;
9
+ eventBus.emit(prefixedEvent, { payload });
10
+ },
11
+ persist: async () => {
12
+ console.warn("[ClientEffectHandlers] persist is server-side only, ignored on client");
13
+ },
14
+ set: () => {
15
+ console.warn("[ClientEffectHandlers] set is server-side only, ignored on client");
16
+ },
17
+ callService: async () => {
18
+ console.warn("[ClientEffectHandlers] callService is server-side only, ignored on client");
19
+ return {};
20
+ },
21
+ renderUI: (slot, pattern, props) => {
22
+ if (pattern === null) {
23
+ slotSetter.clearSlot(slot);
24
+ return;
25
+ }
26
+ const enriched = enrichPattern ? enrichPattern(pattern) : pattern;
27
+ slotSetter.addPattern(slot, enriched, props);
28
+ },
29
+ navigate: navigate ?? ((path) => {
30
+ console.warn("[ClientEffectHandlers] No navigate handler, ignoring:", path);
31
+ }),
32
+ notify: notify ?? ((msg, type) => {
33
+ console.log(`[ClientEffectHandlers] notify (${type}):`, msg);
34
+ })
35
+ };
36
+ }
37
+
38
+ export { createClientEffectHandlers };
2
39
  //# sourceMappingURL=index.js.map
3
40
  //# sourceMappingURL=index.js.map
package/dist/index.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"sources":[],"names":[],"mappings":"","file":"index.js"}
1
+ {"version":3,"sources":["../src/ClientEffectHandlers.ts"],"names":[],"mappings":";;;AAwEO,SAAS,2BACZ,OAAA,EACc;AACd,EAAA,MAAM,EAAE,QAAA,EAAU,UAAA,EAAY,QAAA,EAAU,MAAA,EAAQ,eAAc,GAAI,OAAA;AAElE,EAAA,OAAO;AAAA,IACH,IAAA,EAAM,CAAC,KAAA,EAAe,OAAA,KAAsC;AACxD,MAAA,MAAM,gBAAgB,KAAA,CAAM,UAAA,CAAW,KAAK,CAAA,GAAI,KAAA,GAAQ,MAAM,KAAK,CAAA,CAAA;AACnE,MAAA,QAAA,CAAS,IAAA,CAAK,aAAA,EAAe,EAAE,OAAA,EAAS,CAAA;AAAA,IAC5C,CAAA;AAAA,IAEA,SAAS,YAAY;AACjB,MAAA,OAAA,CAAQ,KAAK,uEAAuE,CAAA;AAAA,IACxF,CAAA;AAAA,IAEA,KAAK,MAAM;AACP,MAAA,OAAA,CAAQ,KAAK,mEAAmE,CAAA;AAAA,IACpF,CAAA;AAAA,IAEA,aAAa,YAAY;AACrB,MAAA,OAAA,CAAQ,KAAK,2EAA2E,CAAA;AACxF,MAAA,OAAO,EAAC;AAAA,IACZ,CAAA;AAAA,IAEA,QAAA,EAAU,CAAC,IAAA,EAAc,OAAA,EAAkB,KAAA,KAAoC;AAC3E,MAAA,IAAI,YAAY,IAAA,EAAM;AAClB,QAAA,UAAA,CAAW,UAAU,IAAI,CAAA;AACzB,QAAA;AAAA,MACJ;AACA,MAAA,MAAM,QAAA,GAAW,aAAA,GAAgB,aAAA,CAAc,OAAO,CAAA,GAAI,OAAA;AAC1D,MAAA,UAAA,CAAW,UAAA,CAAW,IAAA,EAAM,QAAA,EAAU,KAAK,CAAA;AAAA,IAC/C,CAAA;AAAA,IAEA,QAAA,EAAU,QAAA,KAAa,CAAC,IAAA,KAAiB;AACrC,MAAA,OAAA,CAAQ,IAAA,CAAK,yDAAyD,IAAI,CAAA;AAAA,IAC9E,CAAA,CAAA;AAAA,IAEA,MAAA,EAAQ,MAAA,KAAW,CAAC,GAAA,EAAa,IAAA,KAAkB;AAC/C,MAAA,OAAA,CAAQ,GAAA,CAAI,CAAA,+BAAA,EAAkC,IAAI,CAAA,EAAA,CAAA,EAAM,GAAG,CAAA;AAAA,IAC/D,CAAA;AAAA,GACJ;AACJ","file":"index.js","sourcesContent":["/**\n * Client Effect Handlers Factory\n *\n * Creates the standard effect handler set for client-side trait execution.\n * Platform-agnostic — works with any UI framework that provides the required interfaces.\n *\n * @packageDocumentation\n */\n\nimport type { EffectHandlers } from './types.js';\n\n// ============================================================================\n// Types\n// ============================================================================\n\n/**\n * Minimal event bus interface required by the factory.\n */\nexport interface ClientEventBus {\n emit: (type: string, payload?: Record<string, unknown>) => void;\n}\n\n/**\n * Slot setter interface for render-ui effects.\n * The factory doesn't know about React state — it just calls this function.\n */\nexport interface SlotSetter {\n /** Accumulate a pattern into the pending slot map */\n addPattern: (slot: string, pattern: unknown, props?: Record<string, unknown>) => void;\n /** Mark a slot for clearing */\n clearSlot: (slot: string) => void;\n}\n\n/**\n * Options for creating client effect handlers.\n */\nexport interface CreateClientEffectHandlersOptions {\n /** Event bus for emit effects */\n eventBus: ClientEventBus;\n /** Slot setter for render-ui effects */\n slotSetter: SlotSetter;\n /** Navigate function for navigate effects */\n navigate?: (path: string, params?: Record<string, unknown>) => void;\n /** Notify function for notification effects */\n notify?: (message: string, type: 'success' | 'error' | 'warning' | 'info') => void;\n /** Entity enrichment: inject linkedEntity into entity-aware patterns */\n enrichPattern?: (pattern: unknown) => unknown;\n}\n\n// ============================================================================\n// Factory\n// ============================================================================\n\n/**\n * Create client-side effect handlers for trait state machine execution.\n *\n * Client handles: emit, renderUI, navigate, notify\n * Server handles: persist, set, callService (logged as warnings on client)\n *\n * @example\n * ```ts\n * const handlers = createClientEffectHandlers({\n * eventBus,\n * slotSetter: {\n * addPattern: (slot, pattern, props) => pendingSlots.get(slot)?.push({ pattern, props }),\n * clearSlot: (slot) => pendingSlots.set(slot, []),\n * },\n * navigate: (path) => router.push(path),\n * notify: (msg, type) => toast[type](msg),\n * });\n * ```\n */\nexport function createClientEffectHandlers(\n options: CreateClientEffectHandlersOptions\n): EffectHandlers {\n const { eventBus, slotSetter, navigate, notify, enrichPattern } = options;\n\n return {\n emit: (event: string, payload?: Record<string, unknown>) => {\n const prefixedEvent = event.startsWith('UI:') ? event : `UI:${event}`;\n eventBus.emit(prefixedEvent, { payload });\n },\n\n persist: async () => {\n console.warn('[ClientEffectHandlers] persist is server-side only, ignored on client');\n },\n\n set: () => {\n console.warn('[ClientEffectHandlers] set is server-side only, ignored on client');\n },\n\n callService: async () => {\n console.warn('[ClientEffectHandlers] callService is server-side only, ignored on client');\n return {};\n },\n\n renderUI: (slot: string, pattern: unknown, props?: Record<string, unknown>) => {\n if (pattern === null) {\n slotSetter.clearSlot(slot);\n return;\n }\n const enriched = enrichPattern ? enrichPattern(pattern) : pattern;\n slotSetter.addPattern(slot, enriched, props);\n },\n\n navigate: navigate ?? ((path: string) => {\n console.warn('[ClientEffectHandlers] No navigate handler, ignoring:', path);\n }),\n\n notify: notify ?? ((msg: string, type?: string) => {\n console.log(`[ClientEffectHandlers] notify (${type}):`, msg);\n }),\n };\n}\n"]}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@almadar/runtime",
3
- "version": "1.0.15",
3
+ "version": "1.0.17",
4
4
  "description": "Interpreted runtime for Almadar orbital applications (OrbitalServerRuntime)",
5
5
  "type": "module",
6
6
  "main": "./dist/index.js",
@@ -28,9 +28,9 @@
28
28
  },
29
29
  "dependencies": {
30
30
  "@faker-js/faker": "^9.3.0",
31
- "@almadar/server": "1.0.14",
31
+ "@almadar/server": "1.0.16",
32
32
  "@almadar/evaluator": "1.0.13",
33
- "@almadar/core": "1.0.14"
33
+ "@almadar/core": "1.0.16"
34
34
  },
35
35
  "peerDependencies": {
36
36
  "express": "^4.0.0"