@xmachines/play-actor 1.0.0-beta.1 → 1.0.0-beta.2

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@xmachines/play-actor",
3
- "version": "1.0.0-beta.1",
3
+ "version": "1.0.0-beta.2",
4
4
  "private": false,
5
5
  "description": "Abstract Actor base class for XMachines Play Architecture",
6
6
  "keywords": [
@@ -14,8 +14,8 @@
14
14
  "author": "XMachines Contributors",
15
15
  "files": [
16
16
  "dist",
17
- "src",
18
- "README.md"
17
+ "README.md",
18
+ "LICENSE"
19
19
  ],
20
20
  "type": "module",
21
21
  "exports": {
@@ -40,8 +40,8 @@
40
40
  "xstate": "^5.28.0"
41
41
  },
42
42
  "peerDependencies": {
43
- "@xmachines/play": "1.0.0-beta.1",
44
- "@xmachines/play-signals": "1.0.0-beta.1",
43
+ "@xmachines/play": "1.0.0-beta.2",
44
+ "@xmachines/play-signals": "1.0.0-beta.2",
45
45
  "xstate": "^5.28.0"
46
46
  },
47
47
  "engines": {
@@ -1,207 +0,0 @@
1
- /**
2
- * AbstractActor base class for Play Architecture
3
- *
4
- * Extends XState Actor to maintain ecosystem compatibility (inspection, devtools)
5
- * while enforcing signal protocol for Actor ↔ Infrastructure communication.
6
- *
7
- * Per RFC section 5.3, the Actor exposes a minimal protocol:
8
- * - state: Current machine state snapshot
9
- * - send: Event dispatch method
10
- *
11
- * Optional capabilities are provided via interfaces:
12
- * - Routable: For actors that support routing
13
- * - Viewable: For actors that support view rendering
14
- *
15
- * Concrete implementations are created by adapters (e.g., @xmachines/play-xstate).
16
- *
17
- * @packageDocumentation
18
- */
19
-
20
- import { Actor, type AnyActorLogic } from "xstate";
21
- import type { Signal } from "@xmachines/play-signals";
22
-
23
- /**
24
- * Optional capability: Routing support
25
- *
26
- * Actors implementing this interface can derive a route from their state.
27
- * Router adapters observe the currentRoute signal to sync browser URLs.
28
- *
29
- * @example
30
- * ```typescript
31
- * class MyActor extends AbstractActor implements Routable {
32
- * currentRoute = new Signal.Computed(() => deriveRoute(this.state.get()));
33
- * }
34
- *
35
- * // Router requires Routable
36
- * function connectRouter<T extends AbstractActor & Routable>(actor: T) {
37
- * watcher.watch(actor.currentRoute);
38
- * }
39
- * ```
40
- */
41
- export interface Routable {
42
- /**
43
- * Current route signal
44
- *
45
- * Computed signal derived from state machine. Infrastructure observes to sync browser URL.
46
- *
47
- * Invariant: Passive Infrastructure - Infrastructure reflects route, never decides.
48
- *
49
- * @example
50
- * ```typescript
51
- * const watcher = new Signal.subtle.Watcher(() => {
52
- * const route = actor.currentRoute.get();
53
- * console.log('Route changed:', route);
54
- * });
55
- * watcher.watch(actor.currentRoute);
56
- * ```
57
- */
58
- readonly currentRoute: Signal.Computed<string | null>;
59
- }
60
-
61
- /**
62
- * Optional capability: View rendering support
63
- *
64
- * Actors implementing this interface can derive view structures from their state.
65
- * Renderers observe the currentView signal to update the UI.
66
- *
67
- * @example
68
- * ```typescript
69
- * class MyActor extends AbstractActor implements Viewable {
70
- * currentView = new Signal.State(null);
71
- * catalog = { HomePage: HomeComponent };
72
- * }
73
- *
74
- * // Renderer requires Viewable
75
- * function renderView<T extends AbstractActor & Viewable>(actor: T) {
76
- * const view = actor.currentView.get();
77
- * return catalog[view.component];
78
- * }
79
- * ```
80
- */
81
- export interface Viewable {
82
- /**
83
- * Current view signal
84
- *
85
- * State signal containing UI structure schema from meta.view. Infrastructure renders view.
86
- *
87
- * Invariant: Logic-Driven UI - View structure is defined by business logic, not JSX.
88
- *
89
- * @example
90
- * ```typescript
91
- * const watcher = new Signal.subtle.Watcher(() => {
92
- * const view = actor.currentView.get();
93
- * console.log('View changed:', view);
94
- * });
95
- * watcher.watch(actor.currentView);
96
- * ```
97
- */
98
- readonly currentView: Signal.State<any>;
99
-
100
- /**
101
- * Component catalog for view resolution
102
- *
103
- * Maps component names to actual component implementations.
104
- * Used by renderers to resolve view.component to actual UI components.
105
- */
106
- readonly catalog: any;
107
- }
108
-
109
- /**
110
- * Abstract base class for Play Architecture actors.
111
- *
112
- * Extends XState Actor to maintain ecosystem compatibility (inspection, devtools)
113
- * while enforcing minimal signal protocol for Actor ↔ Infrastructure communication.
114
- *
115
- * The core protocol contains only:
116
- * - state: Reactive state snapshot
117
- * - send: Event dispatch method
118
- *
119
- * Optional capabilities (routing, view rendering) are provided via interfaces:
120
- * - Implement Routable for routing support
121
- * - Implement Viewable for view rendering support
122
- *
123
- * Concrete implementations created by @xmachines/play-xstate adapter.
124
- *
125
- * @typeParam TLogic - XState actor logic type (maintains type safety)
126
- *
127
- * Invariant: Actor Authority - Actor is the sole source of truth for state transitions.
128
- * Invariant: Signal-Only Reactivity - Infrastructure observes via TC39 Signals.
129
- * Invariant: Passive Infrastructure - Infrastructure reflects, never decides.
130
- *
131
- * @example
132
- * Simple actor (no routing, no view)
133
- * ```typescript
134
- * class SimpleActor extends AbstractActor<any> {
135
- * state = new Signal.State({...});
136
- * send(event) { ... }
137
- * }
138
- * ```
139
- *
140
- * @example
141
- * Routable actor
142
- * ```typescript
143
- * class RoutableActor extends AbstractActor<any> implements Routable {
144
- * state = new Signal.State({...});
145
- * currentRoute = new Signal.Computed(() => deriveRoute(this.state.get()));
146
- * send(event) { ... }
147
- * }
148
- * ```
149
- *
150
- * @example
151
- * Full-featured actor (routing + view)
152
- * ```typescript
153
- * class PlayerActor extends AbstractActor<any> implements Routable, Viewable {
154
- * state = new Signal.State({...});
155
- * currentRoute = new Signal.Computed(() => deriveRoute(this.state.get()));
156
- * currentView = new Signal.State(null);
157
- * catalog = {};
158
- * send(event) { ... }
159
- * }
160
- * ```
161
- *
162
- * @see {@link https://gitlab.com/xmachin-es/rfc/-/blob/main/src/play-v1.md#53-actor-protocol | RFC Play v1 Section 5.3}
163
- * @see {@link Routable} for routing capability
164
- * @see {@link Viewable} for view rendering capability
165
- */
166
- export abstract class AbstractActor<TLogic extends AnyActorLogic> extends Actor<TLogic> {
167
- /**
168
- * Reactive snapshot of current actor state.
169
- *
170
- * Infrastructure observes this signal to react to state changes without
171
- * directly coupling to the Actor's internal state machine implementation.
172
- *
173
- * @example
174
- * ```typescript
175
- * // Infrastructure observes state signal
176
- * const watcher = new Signal.subtle.Watcher(() => {
177
- * console.log('Actor state changed:', actor.state.get());
178
- * });
179
- * watcher.watch(actor.state);
180
- * ```
181
- */
182
- public abstract state: Signal.State<any>;
183
-
184
- /**
185
- * Send event to Actor
186
- *
187
- * Infrastructure forwards user intents (navigation, domain events, custom events)
188
- * as events to the Actor. The Actor's state machine guards determine whether
189
- * each event is valid from the current state.
190
- *
191
- * @param event - Event object with type property (e.g., PlayEvent, PlayRouteEvent)
192
- *
193
- * Invariant: Actor Authority - Only Actor decides whether an event is valid.
194
- *
195
- * @example
196
- * ```typescript
197
- * // Infrastructure forwards user intent
198
- * actor.send({ type: 'auth.login', userId: '123' });
199
- * // Actor's guards determine if event is allowed
200
- * ```
201
- *
202
- * @remarks
203
- * Accepts any event object with a type property. Core events (PlayEvent) are in
204
- * @xmachines/play, routing events (PlayRouteEvent) are in @xmachines/play-router.
205
- */
206
- public abstract override send(event: { readonly type: string } & Record<string, any>): void;
207
- }
package/src/index.ts DELETED
@@ -1,19 +0,0 @@
1
- /**
2
- * @xmachines/play-actor - Abstract Actor base class for Play Architecture
3
- *
4
- * This package provides AbstractActor, a minimal base class that extends XState Actor
5
- * while enforcing the Play Architecture's signal protocol (RFC section 5.3).
6
- *
7
- * The core protocol is minimal (state + send). Optional capabilities are provided
8
- * via interfaces:
9
- * - Routable: For actors that support routing
10
- * - Viewable: For actors that support view rendering
11
- *
12
- * Maintains XState ecosystem compatibility (inspection, devtools) while exposing
13
- * reactive signals for Infrastructure layer communication.
14
- *
15
- * @packageDocumentation
16
- * @see {@link https://gitlab.com/xmachin-es/rfc/-/blob/main/src/play-v1.md#53-actor-protocol | RFC Play v1 Section 5.3}
17
- */
18
-
19
- export { AbstractActor, type Routable, type Viewable } from "./abstract-actor.js";