@almadar/runtime 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.
- package/LICENSE +72 -0
- package/dist/OrbitalServerRuntime-COj7K1yM.d.ts +736 -0
- package/dist/OrbitalServerRuntime.d.ts +4 -0
- package/dist/OrbitalServerRuntime.js +3185 -0
- package/dist/OrbitalServerRuntime.js.map +1 -0
- package/dist/ServerBridge.d.ts +118 -0
- package/dist/ServerBridge.js +242 -0
- package/dist/ServerBridge.js.map +1 -0
- package/dist/index.d.ts +291 -0
- package/dist/index.js +1556 -0
- package/dist/index.js.map +1 -0
- package/dist/types-JFCKD0FU.d.ts +175 -0
- package/package.json +65 -0
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,291 @@
|
|
|
1
|
+
import { B as BindingContext, T as TraitState, a as TraitDefinition, b as TransitionResult, E as EffectHandlers, c as EffectContext } from './types-JFCKD0FU.js';
|
|
2
|
+
export { d as Effect, e as EventListener, I as IEventBus, R as RuntimeEvent, U as Unsubscribe } from './types-JFCKD0FU.js';
|
|
3
|
+
export { E as EntitySharingMap, a as EventBus, b as EventNamespaceMap, O as OrbitalEventRequest, c as OrbitalEventResponse, d as OrbitalServerRuntimeConfig, P as PersistenceAdapter, e as PreprocessOptions, f as PreprocessResult, g as PreprocessedSchema, R as RuntimeOrbital, h as RuntimeOrbitalSchema, i as RuntimeTrait, j as getIsolatedCollectionName, k as getNamespacedEvent, l as isNamespacedEvent, p as parseNamespacedEvent, m as preprocessSchema } from './OrbitalServerRuntime-COj7K1yM.js';
|
|
4
|
+
import { EvaluationContext } from '@almadar/evaluator';
|
|
5
|
+
export { EvaluationContext, createMinimalContext } from '@almadar/evaluator';
|
|
6
|
+
export { ServerBridgeConfig, ServerBridgeState } from './ServerBridge.js';
|
|
7
|
+
import 'express';
|
|
8
|
+
import '@almadar/core';
|
|
9
|
+
|
|
10
|
+
/**
|
|
11
|
+
* BindingResolver - Platform-Agnostic Binding Resolution
|
|
12
|
+
*
|
|
13
|
+
* Resolves binding references like @entity.field, @payload.value, @state
|
|
14
|
+
* in props and values. Works on both client and server.
|
|
15
|
+
*
|
|
16
|
+
* Uses the shared S-expression evaluator for actual resolution.
|
|
17
|
+
*
|
|
18
|
+
* @packageDocumentation
|
|
19
|
+
*/
|
|
20
|
+
|
|
21
|
+
/**
|
|
22
|
+
* Interpolate binding references in props.
|
|
23
|
+
*
|
|
24
|
+
* @param props - Props object with potential binding references
|
|
25
|
+
* @param ctx - Evaluation context with bindings
|
|
26
|
+
* @returns New props object with resolved values
|
|
27
|
+
*
|
|
28
|
+
* @example
|
|
29
|
+
* ```ts
|
|
30
|
+
* const ctx = createContextFromBindings({ name: 'Project Alpha', count: 42 });
|
|
31
|
+
* const props = {
|
|
32
|
+
* title: '@entity.name',
|
|
33
|
+
* total: ['+', '@entity.count', 10],
|
|
34
|
+
* };
|
|
35
|
+
* const result = interpolateProps(props, ctx);
|
|
36
|
+
* // { title: 'Project Alpha', total: 52 }
|
|
37
|
+
* ```
|
|
38
|
+
*/
|
|
39
|
+
declare function interpolateProps(props: Record<string, unknown>, ctx: EvaluationContext): Record<string, unknown>;
|
|
40
|
+
/**
|
|
41
|
+
* Interpolate a single value.
|
|
42
|
+
*/
|
|
43
|
+
declare function interpolateValue(value: unknown, ctx: EvaluationContext): unknown;
|
|
44
|
+
/**
|
|
45
|
+
* Check if a value contains any binding references.
|
|
46
|
+
*/
|
|
47
|
+
declare function containsBindings(value: unknown): boolean;
|
|
48
|
+
/**
|
|
49
|
+
* Extract all binding references from a value.
|
|
50
|
+
*/
|
|
51
|
+
declare function extractBindings(value: unknown): string[];
|
|
52
|
+
/**
|
|
53
|
+
* Create an EvaluationContext from a BindingContext.
|
|
54
|
+
*/
|
|
55
|
+
declare function createContextFromBindings(bindings: BindingContext): EvaluationContext;
|
|
56
|
+
|
|
57
|
+
/**
|
|
58
|
+
* StateMachineCore - Platform-Agnostic State Machine Logic
|
|
59
|
+
*
|
|
60
|
+
* Pure TypeScript implementation of trait state machine execution.
|
|
61
|
+
* Extracts the core logic from useTraitStateMachine for use on
|
|
62
|
+
* both client and server.
|
|
63
|
+
*
|
|
64
|
+
* @packageDocumentation
|
|
65
|
+
*/
|
|
66
|
+
|
|
67
|
+
/**
|
|
68
|
+
* Find the initial state for a trait definition.
|
|
69
|
+
*/
|
|
70
|
+
declare function findInitialState(trait: TraitDefinition): string;
|
|
71
|
+
/**
|
|
72
|
+
* Create initial trait state for a trait definition.
|
|
73
|
+
*/
|
|
74
|
+
declare function createInitialTraitState(trait: TraitDefinition): TraitState;
|
|
75
|
+
/**
|
|
76
|
+
* Find a matching transition from the current state for the given event.
|
|
77
|
+
*/
|
|
78
|
+
declare function findTransition(trait: TraitDefinition, currentState: string, eventKey: string): TraitDefinition['transitions'][0] | undefined;
|
|
79
|
+
/**
|
|
80
|
+
* Normalize event key - strip UI: prefix if present.
|
|
81
|
+
*/
|
|
82
|
+
declare function normalizeEventKey(eventKey: string): string;
|
|
83
|
+
/**
|
|
84
|
+
* Options for processing an event through the state machine.
|
|
85
|
+
*/
|
|
86
|
+
interface ProcessEventOptions {
|
|
87
|
+
/** Current trait state */
|
|
88
|
+
traitState: TraitState;
|
|
89
|
+
/** Trait definition */
|
|
90
|
+
trait: TraitDefinition;
|
|
91
|
+
/** Event key to process */
|
|
92
|
+
eventKey: string;
|
|
93
|
+
/** Event payload */
|
|
94
|
+
payload?: Record<string, unknown>;
|
|
95
|
+
/** Entity data for binding resolution */
|
|
96
|
+
entityData?: Record<string, unknown>;
|
|
97
|
+
}
|
|
98
|
+
/**
|
|
99
|
+
* Process an event through a trait's state machine.
|
|
100
|
+
*
|
|
101
|
+
* This is a pure function that:
|
|
102
|
+
* 1. Finds matching transitions
|
|
103
|
+
* 2. Evaluates guards
|
|
104
|
+
* 3. Returns the transition result (but does not execute effects)
|
|
105
|
+
*
|
|
106
|
+
* @returns TransitionResult with effects to execute
|
|
107
|
+
*
|
|
108
|
+
* @example
|
|
109
|
+
* ```ts
|
|
110
|
+
* const result = processEvent({
|
|
111
|
+
* traitState: { traitName: 'Cart', currentState: 'empty', ... },
|
|
112
|
+
* trait: cartTraitDefinition,
|
|
113
|
+
* eventKey: 'ADD_ITEM',
|
|
114
|
+
* payload: { productId: '123' },
|
|
115
|
+
* });
|
|
116
|
+
*
|
|
117
|
+
* if (result.executed) {
|
|
118
|
+
* // Execute effects
|
|
119
|
+
* for (const effect of result.effects) {
|
|
120
|
+
* effectExecutor.execute(effect);
|
|
121
|
+
* }
|
|
122
|
+
* // Update state
|
|
123
|
+
* traitState.currentState = result.newState;
|
|
124
|
+
* }
|
|
125
|
+
* ```
|
|
126
|
+
*/
|
|
127
|
+
declare function processEvent(options: ProcessEventOptions): TransitionResult;
|
|
128
|
+
/**
|
|
129
|
+
* Stateful manager for multiple trait state machines.
|
|
130
|
+
*
|
|
131
|
+
* Platform-agnostic - can be used directly on server or wrapped
|
|
132
|
+
* in a React hook on client.
|
|
133
|
+
*
|
|
134
|
+
* @example
|
|
135
|
+
* ```ts
|
|
136
|
+
* const manager = new StateMachineManager([cartTrait, userTrait]);
|
|
137
|
+
*
|
|
138
|
+
* // Process event
|
|
139
|
+
* const results = manager.sendEvent('ADD_ITEM', { productId: '123' });
|
|
140
|
+
*
|
|
141
|
+
* // Get current states
|
|
142
|
+
* const cartState = manager.getState('Cart');
|
|
143
|
+
* ```
|
|
144
|
+
*/
|
|
145
|
+
declare class StateMachineManager {
|
|
146
|
+
private traits;
|
|
147
|
+
private states;
|
|
148
|
+
constructor(traits?: TraitDefinition[]);
|
|
149
|
+
/**
|
|
150
|
+
* Add a trait to the manager.
|
|
151
|
+
*/
|
|
152
|
+
addTrait(trait: TraitDefinition): void;
|
|
153
|
+
/**
|
|
154
|
+
* Remove a trait from the manager.
|
|
155
|
+
*/
|
|
156
|
+
removeTrait(traitName: string): void;
|
|
157
|
+
/**
|
|
158
|
+
* Get current state for a trait.
|
|
159
|
+
*/
|
|
160
|
+
getState(traitName: string): TraitState | undefined;
|
|
161
|
+
/**
|
|
162
|
+
* Get all current states.
|
|
163
|
+
*/
|
|
164
|
+
getAllStates(): Map<string, TraitState>;
|
|
165
|
+
/**
|
|
166
|
+
* Check if a trait can handle an event from its current state.
|
|
167
|
+
*/
|
|
168
|
+
canHandleEvent(traitName: string, eventKey: string): boolean;
|
|
169
|
+
/**
|
|
170
|
+
* Send an event to all traits.
|
|
171
|
+
*
|
|
172
|
+
* @returns Array of transition results (one per trait that had a matching transition)
|
|
173
|
+
*/
|
|
174
|
+
sendEvent(eventKey: string, payload?: Record<string, unknown>, entityData?: Record<string, unknown>): Array<{
|
|
175
|
+
traitName: string;
|
|
176
|
+
result: TransitionResult;
|
|
177
|
+
}>;
|
|
178
|
+
/**
|
|
179
|
+
* Reset a trait to its initial state.
|
|
180
|
+
*/
|
|
181
|
+
resetTrait(traitName: string): void;
|
|
182
|
+
/**
|
|
183
|
+
* Reset all traits to initial states.
|
|
184
|
+
*/
|
|
185
|
+
resetAll(): void;
|
|
186
|
+
}
|
|
187
|
+
|
|
188
|
+
/**
|
|
189
|
+
* EffectExecutor - Platform-Agnostic Effect Dispatch
|
|
190
|
+
*
|
|
191
|
+
* Routes S-expression effects to appropriate handlers.
|
|
192
|
+
* Platform-specific adapters provide handler implementations.
|
|
193
|
+
*
|
|
194
|
+
* @packageDocumentation
|
|
195
|
+
*/
|
|
196
|
+
|
|
197
|
+
/**
|
|
198
|
+
* Full executor options with handlers and context.
|
|
199
|
+
*/
|
|
200
|
+
interface EffectExecutorOptions {
|
|
201
|
+
/** Effect handlers (platform-specific) */
|
|
202
|
+
handlers: EffectHandlers;
|
|
203
|
+
/** Binding context for resolving @entity.field references */
|
|
204
|
+
bindings: BindingContext;
|
|
205
|
+
/** Effect execution context (trait name, state, etc.) */
|
|
206
|
+
context: EffectContext;
|
|
207
|
+
/** Enable debug logging */
|
|
208
|
+
debug?: boolean;
|
|
209
|
+
}
|
|
210
|
+
/**
|
|
211
|
+
* EffectExecutor - Routes effects to handlers.
|
|
212
|
+
*
|
|
213
|
+
* @example
|
|
214
|
+
* ```ts
|
|
215
|
+
* const executor = new EffectExecutor({
|
|
216
|
+
* handlers: {
|
|
217
|
+
* emit: (event, payload) => eventBus.emit(event, payload),
|
|
218
|
+
* persist: async (action, entity, data) => { ... },
|
|
219
|
+
* set: (id, field, value) => { ... },
|
|
220
|
+
* callService: async (service, action, params) => { ... },
|
|
221
|
+
* },
|
|
222
|
+
* bindings: { entity: { name: 'Product' }, payload: { id: '123' } },
|
|
223
|
+
* context: { traitName: 'Cart', state: 'active', transition: 'idle->active' },
|
|
224
|
+
* });
|
|
225
|
+
*
|
|
226
|
+
* // Execute a single effect
|
|
227
|
+
* executor.execute(['emit', 'ITEM_ADDED', { count: 1 }]);
|
|
228
|
+
*
|
|
229
|
+
* // Execute multiple effects
|
|
230
|
+
* executor.executeAll([
|
|
231
|
+
* ['set', 'item', 'quantity', 5],
|
|
232
|
+
* ['emit', 'QUANTITY_UPDATED'],
|
|
233
|
+
* ]);
|
|
234
|
+
* ```
|
|
235
|
+
*/
|
|
236
|
+
declare class EffectExecutor {
|
|
237
|
+
private handlers;
|
|
238
|
+
private bindings;
|
|
239
|
+
private context;
|
|
240
|
+
private debug;
|
|
241
|
+
constructor(options: EffectExecutorOptions);
|
|
242
|
+
/**
|
|
243
|
+
* Execute a single effect.
|
|
244
|
+
*/
|
|
245
|
+
execute(effect: unknown): Promise<void>;
|
|
246
|
+
/**
|
|
247
|
+
* Execute multiple effects in sequence.
|
|
248
|
+
*/
|
|
249
|
+
executeAll(effects: unknown[]): Promise<void>;
|
|
250
|
+
/**
|
|
251
|
+
* Execute multiple effects in parallel.
|
|
252
|
+
*/
|
|
253
|
+
executeParallel(effects: unknown[]): Promise<void>;
|
|
254
|
+
private dispatch;
|
|
255
|
+
private logUnsupported;
|
|
256
|
+
}
|
|
257
|
+
/**
|
|
258
|
+
* Create a minimal EffectExecutor for testing or simple scenarios.
|
|
259
|
+
*/
|
|
260
|
+
declare function createTestExecutor(overrides?: Partial<EffectHandlers>): EffectExecutor;
|
|
261
|
+
|
|
262
|
+
/**
|
|
263
|
+
* MockPersistenceAdapter - In-memory data store with faker-based mock generation
|
|
264
|
+
*
|
|
265
|
+
* Provides a stateful mock data layer that implements PersistenceAdapter.
|
|
266
|
+
* Uses @faker-js/faker for realistic data generation based on field types.
|
|
267
|
+
*
|
|
268
|
+
* @packageDocumentation
|
|
269
|
+
*/
|
|
270
|
+
|
|
271
|
+
interface EntityField {
|
|
272
|
+
name: string;
|
|
273
|
+
type: string;
|
|
274
|
+
required?: boolean;
|
|
275
|
+
values?: string[];
|
|
276
|
+
default?: unknown;
|
|
277
|
+
}
|
|
278
|
+
interface EntitySchema {
|
|
279
|
+
name: string;
|
|
280
|
+
fields: EntityField[];
|
|
281
|
+
}
|
|
282
|
+
interface MockPersistenceConfig {
|
|
283
|
+
/** Seed for deterministic generation */
|
|
284
|
+
seed?: number;
|
|
285
|
+
/** Default number of records to generate per entity */
|
|
286
|
+
defaultSeedCount?: number;
|
|
287
|
+
/** Enable debug logging */
|
|
288
|
+
debug?: boolean;
|
|
289
|
+
}
|
|
290
|
+
|
|
291
|
+
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 };
|