@kylewillett/troupe 0.0.0-stage → 0.1.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/CHANGELOG.md +36 -0
- package/LICENSE +21 -0
- package/README.md +376 -2
- package/dist/actor.d.ts +13 -0
- package/dist/actor.js +14 -0
- package/dist/ask.d.ts +39 -0
- package/dist/ask.js +135 -0
- package/dist/backstage/encode.d.ts +36 -0
- package/dist/backstage/encode.js +183 -0
- package/dist/backstage/index.d.ts +4 -0
- package/dist/backstage/index.js +4 -0
- package/dist/backstage/requests.d.ts +8 -0
- package/dist/backstage/requests.js +137 -0
- package/dist/backstage/source.d.ts +10 -0
- package/dist/backstage/source.js +143 -0
- package/dist/backstage/types.d.ts +135 -0
- package/dist/backstage/types.js +3 -0
- package/dist/backstage-ui/assets/index-Bg0MCiqs.css +1 -0
- package/dist/backstage-ui/assets/index-CeefBsDh.js +9 -0
- package/dist/backstage-ui/index.html +13 -0
- package/dist/cell.d.ts +129 -0
- package/dist/cell.js +763 -0
- package/dist/checks.d.ts +9 -0
- package/dist/checks.js +25 -0
- package/dist/dispatcher.d.ts +36 -0
- package/dist/dispatcher.js +65 -0
- package/dist/errors.d.ts +37 -0
- package/dist/errors.js +41 -0
- package/dist/events.d.ts +37 -0
- package/dist/events.js +88 -0
- package/dist/index.d.ts +7 -0
- package/dist/index.js +7 -0
- package/dist/internal.d.ts +81 -0
- package/dist/internal.js +36 -0
- package/dist/logger.d.ts +31 -0
- package/dist/logger.js +56 -0
- package/dist/names.d.ts +20 -0
- package/dist/names.js +50 -0
- package/dist/node/backstage/index.d.ts +1 -0
- package/dist/node/backstage/index.js +2 -0
- package/dist/node/backstage/server.d.ts +60 -0
- package/dist/node/backstage/server.js +342 -0
- package/dist/node/sqlite/index.d.ts +1 -0
- package/dist/node/sqlite/index.js +2 -0
- package/dist/node/sqlite/schema.d.ts +2 -0
- package/dist/node/sqlite/schema.js +36 -0
- package/dist/node/sqlite/schema.sql +32 -0
- package/dist/node/sqlite/sqlite.d.ts +24 -0
- package/dist/node/sqlite/sqlite.js +183 -0
- package/dist/persistence/actor.d.ts +158 -0
- package/dist/persistence/actor.js +454 -0
- package/dist/persistence/backend.d.ts +32 -0
- package/dist/persistence/backend.js +96 -0
- package/dist/persistence/errors.d.ts +60 -0
- package/dist/persistence/errors.js +82 -0
- package/dist/persistence/index.d.ts +6 -0
- package/dist/persistence/index.js +5 -0
- package/dist/persistence/json.d.ts +7 -0
- package/dist/persistence/json.js +75 -0
- package/dist/persistence/memory.d.ts +18 -0
- package/dist/persistence/memory.js +143 -0
- package/dist/persistence/postgres/index.d.ts +1 -0
- package/dist/persistence/postgres/index.js +3 -0
- package/dist/persistence/postgres/postgres.d.ts +66 -0
- package/dist/persistence/postgres/postgres.js +236 -0
- package/dist/persistence/postgres/schema.d.ts +12 -0
- package/dist/persistence/postgres/schema.js +57 -0
- package/dist/persistence/postgres/schema.sql +35 -0
- package/dist/persistence/projection.d.ts +48 -0
- package/dist/persistence/projection.js +102 -0
- package/dist/persistence/standard-schema.d.ts +63 -0
- package/dist/persistence/standard-schema.js +7 -0
- package/dist/persistence/types.d.ts +73 -0
- package/dist/persistence/types.js +3 -0
- package/dist/queue.d.ts +11 -0
- package/dist/queue.js +31 -0
- package/dist/scheduler.d.ts +24 -0
- package/dist/scheduler.js +23 -0
- package/dist/supervision.d.ts +91 -0
- package/dist/supervision.js +120 -0
- package/dist/system.d.ts +28 -0
- package/dist/system.js +216 -0
- package/dist/testkit/index.d.ts +4 -0
- package/dist/testkit/index.js +4 -0
- package/dist/testkit/kit.d.ts +63 -0
- package/dist/testkit/kit.js +93 -0
- package/dist/testkit/manual-scheduler.d.ts +58 -0
- package/dist/testkit/manual-scheduler.js +187 -0
- package/dist/testkit/probe.d.ts +50 -0
- package/dist/testkit/probe.js +124 -0
- package/dist/testkit/random.d.ts +11 -0
- package/dist/testkit/random.js +23 -0
- package/dist/timers.d.ts +37 -0
- package/dist/timers.js +110 -0
- package/dist/types.d.ts +364 -0
- package/dist/types.js +1 -0
- package/package.json +110 -4
package/dist/types.d.ts
ADDED
|
@@ -0,0 +1,364 @@
|
|
|
1
|
+
import type { Logger } from './logger.js';
|
|
2
|
+
import type { Scheduler } from './scheduler.js';
|
|
3
|
+
import type { SupervisorStrategy } from './supervision.js';
|
|
4
|
+
/**
|
|
5
|
+
* A handle for sending messages to one actor. It's the only way to reach an actor: you never hold
|
|
6
|
+
* the actor itself, which is what lets a ref point at another process in milestone 4.
|
|
7
|
+
*
|
|
8
|
+
* `tell` is a property, not a method, so `ActorRef` is contravariant in `M`: a ref that accepts
|
|
9
|
+
* more messages can stand in for one that accepts fewer, never the other way round.
|
|
10
|
+
*/
|
|
11
|
+
export interface ActorRef<M> {
|
|
12
|
+
/** Where the actor lives in the hierarchy, for example `/user/box-office`. */
|
|
13
|
+
readonly path: string;
|
|
14
|
+
/**
|
|
15
|
+
* Sends `msg` to the actor's mailbox and returns at once. Never throws: a message that can't be
|
|
16
|
+
* delivered becomes a dead letter.
|
|
17
|
+
*/
|
|
18
|
+
readonly tell: (msg: M) => void;
|
|
19
|
+
/**
|
|
20
|
+
* Sends a request and waits for one reply. `build` gets a temporary ref under `/temp` and
|
|
21
|
+
* returns the message to send, which usually carries that ref as its `replyTo`. The first reply
|
|
22
|
+
* resolves the promise. Later replies become `askCompleted` dead letters.
|
|
23
|
+
*
|
|
24
|
+
* `R` can't be inferred from the protocol, so give it: `ref.ask<number>((replyTo) => ...)`, or
|
|
25
|
+
* annotate `replyTo` as `ActorRef<number>`.
|
|
26
|
+
*
|
|
27
|
+
* Asking an actor that has stopped times out rather than failing fast, because a remote ref
|
|
28
|
+
* can't know either (decision 0009).
|
|
29
|
+
* @returns A promise of the first reply. It rejects with `AskTimeoutError` if none arrives in
|
|
30
|
+
* time, with whatever `build` threw if it throws (and then nothing is sent), and with
|
|
31
|
+
* `ActorSystemTerminatedError` once the system is terminating.
|
|
32
|
+
* @throws TypeError for options that can't be used.
|
|
33
|
+
*/
|
|
34
|
+
readonly ask: <R>(build: (replyTo: ActorRef<R>) => M, opts?: AskOptions) => Promise<R>;
|
|
35
|
+
}
|
|
36
|
+
/** Options for one `ask`. */
|
|
37
|
+
export interface AskOptions {
|
|
38
|
+
/** How long to wait for the reply, in ms. Default: the system's `askTimeoutMs`. */
|
|
39
|
+
timeoutMs?: number;
|
|
40
|
+
}
|
|
41
|
+
/** A ref to an actor of any protocol, for watching, stopping and comparing. */
|
|
42
|
+
export type AnyRef = ActorRef<never>;
|
|
43
|
+
/** How a promise settled, as `pipeToSelf` delivers it. */
|
|
44
|
+
export type Result<T> = {
|
|
45
|
+
readonly ok: true;
|
|
46
|
+
readonly value: T;
|
|
47
|
+
} | {
|
|
48
|
+
readonly ok: false;
|
|
49
|
+
readonly error: unknown;
|
|
50
|
+
};
|
|
51
|
+
/**
|
|
52
|
+
* Keyed timers that send the actor a message. They belong to one incarnation: every timer is
|
|
53
|
+
* cancelled when the actor stops or restarts, and a stale context's timer methods do nothing.
|
|
54
|
+
*/
|
|
55
|
+
export interface Timers<M> {
|
|
56
|
+
/**
|
|
57
|
+
* Sends `msg` once, after `delayMs`. Replaces any timer with the same key.
|
|
58
|
+
* @throws TypeError unless `key` is a string and `delayMs` an integer of at least 0.
|
|
59
|
+
*/
|
|
60
|
+
startSingle(key: string, msg: M, delayMs: number): void;
|
|
61
|
+
/**
|
|
62
|
+
* Sends `msg` every `intervalMs`, measured from each firing, until cancelled. Replaces any timer
|
|
63
|
+
* with the same key.
|
|
64
|
+
* @throws TypeError unless `key` is a string and `intervalMs` a positive integer.
|
|
65
|
+
*/
|
|
66
|
+
startPeriodic(key: string, msg: M, intervalMs: number): void;
|
|
67
|
+
/**
|
|
68
|
+
* Cancels the timer with this key, if there is one. Its message is never received, even if it's
|
|
69
|
+
* already in the mailbox.
|
|
70
|
+
*/
|
|
71
|
+
cancel(key: string): void;
|
|
72
|
+
/** Cancels every timer. */
|
|
73
|
+
cancelAll(): void;
|
|
74
|
+
/**
|
|
75
|
+
* True while the timer with this key can still deliver: a periodic one until it's cancelled, a
|
|
76
|
+
* single one until its message has been received.
|
|
77
|
+
*/
|
|
78
|
+
isActive(key: string): boolean;
|
|
79
|
+
}
|
|
80
|
+
/**
|
|
81
|
+
* What an actor can see and do while it runs. Passed to `initial`, `receive` and `onSignal`. It
|
|
82
|
+
* belongs to one incarnation of the actor: once that has stopped or restarted, `spawn` throws and
|
|
83
|
+
* `watch` does nothing. A restart gets a new context, with the same `self`.
|
|
84
|
+
*/
|
|
85
|
+
export interface ActorContext<M> {
|
|
86
|
+
/** This actor's own ref. The same object `spawn` returned. */
|
|
87
|
+
readonly self: ActorRef<M>;
|
|
88
|
+
/** The system logger, with `{ path }` added to every entry. */
|
|
89
|
+
readonly log: Logger;
|
|
90
|
+
/** The scheduler's current time, in ms. */
|
|
91
|
+
now(): number;
|
|
92
|
+
/**
|
|
93
|
+
* Starts a child actor under this one and returns its ref at once.
|
|
94
|
+
* @param name Optional. Generated as `$1`, `$2` and so on when omitted.
|
|
95
|
+
* @throws ActorNameError for an invalid, reserved or taken name.
|
|
96
|
+
* @throws ActorStoppedError once this incarnation is stopping, restarting or has stopped.
|
|
97
|
+
* @throws ActorSystemTerminatedError once the system is terminating.
|
|
98
|
+
* @throws TypeError for a definition or options that can't be used.
|
|
99
|
+
*/
|
|
100
|
+
spawn<C, CS>(def: ActorDef<C, CS>, name?: string, opts?: SpawnOptions): ActorRef<C>;
|
|
101
|
+
/**
|
|
102
|
+
* Stops this actor after its current message, or stops a child after its current message,
|
|
103
|
+
* ahead of anything else in its mailbox. Stopping a child that has already terminated does
|
|
104
|
+
* nothing.
|
|
105
|
+
* @param ref Omit, or pass `ctx.self`, to stop this actor.
|
|
106
|
+
* @throws NotAChildError if `ref` is neither this actor nor one of its children.
|
|
107
|
+
*/
|
|
108
|
+
stop(ref?: AnyRef): void;
|
|
109
|
+
/**
|
|
110
|
+
* Asks to be told when `ref` stops, with a `terminated` signal. Watching twice is the same as
|
|
111
|
+
* once, and watching an actor that has already terminated signals at once.
|
|
112
|
+
* @throws TypeError if `ref` isn't an actor of this system.
|
|
113
|
+
*/
|
|
114
|
+
watch(ref: AnyRef): void;
|
|
115
|
+
/**
|
|
116
|
+
* Stops watching `ref`. No `terminated` for it arrives afterwards, even one already queued.
|
|
117
|
+
* @throws TypeError if `ref` isn't an actor of this system.
|
|
118
|
+
*/
|
|
119
|
+
unwatch(ref: AnyRef): void;
|
|
120
|
+
/** The child with this name, until it has terminated. */
|
|
121
|
+
child(name: string): AnyRef | undefined;
|
|
122
|
+
/** The children that haven't terminated yet, in spawn order. */
|
|
123
|
+
children(): readonly AnyRef[];
|
|
124
|
+
/** This incarnation's timers. */
|
|
125
|
+
readonly timers: Timers<M>;
|
|
126
|
+
/**
|
|
127
|
+
* Waits for `promise` without holding the mailbox, then sends the actor `map(result)`. `map`
|
|
128
|
+
* runs inside the actor when that message is taken, so a mapper that throws is a failure for
|
|
129
|
+
* supervision. If the actor has stopped by then, the raw `Result` becomes a dead letter. Unlike
|
|
130
|
+
* timers, a result still arrives after a restart, as a `self.tell` would.
|
|
131
|
+
* @throws TypeError if `map` isn't a function.
|
|
132
|
+
*/
|
|
133
|
+
pipeToSelf<T>(promise: PromiseLike<T>, map: (result: Result<T>) => M): void;
|
|
134
|
+
}
|
|
135
|
+
/** A lifecycle event, delivered to `onSignal`. */
|
|
136
|
+
export type Signal =
|
|
137
|
+
/**
|
|
138
|
+
* The actor failed and is about to restart. Runs with the old state, before the children are
|
|
139
|
+
* stopped. Skipped when `initial` failed, since there's no state.
|
|
140
|
+
*/
|
|
141
|
+
{
|
|
142
|
+
readonly type: 'preRestart';
|
|
143
|
+
readonly error: unknown;
|
|
144
|
+
}
|
|
145
|
+
/** The actor has stopped, after all its children. The last thing it runs. */
|
|
146
|
+
| {
|
|
147
|
+
readonly type: 'postStop';
|
|
148
|
+
}
|
|
149
|
+
/**
|
|
150
|
+
* An actor this one watches has terminated. `failure` is present when it stopped because it
|
|
151
|
+
* failed.
|
|
152
|
+
*/
|
|
153
|
+
| {
|
|
154
|
+
readonly type: 'terminated';
|
|
155
|
+
readonly ref: AnyRef;
|
|
156
|
+
readonly failure?: unknown;
|
|
157
|
+
};
|
|
158
|
+
/**
|
|
159
|
+
* An actor definition: an initial state and a reducer. Create one with `actor()`, and spawn it
|
|
160
|
+
* as often as you like. State should be plain data (decision 0001).
|
|
161
|
+
*/
|
|
162
|
+
export interface ActorDef<M, S> {
|
|
163
|
+
/**
|
|
164
|
+
* The starting state, or a factory for it. It runs as the actor's first step, after `spawn`
|
|
165
|
+
* returns and before any message. A function is always called as a factory.
|
|
166
|
+
*/
|
|
167
|
+
initial: S | ((ctx: ActorContext<M>) => S);
|
|
168
|
+
/**
|
|
169
|
+
* Handles one message and returns the next state. If it returns a promise, the actor takes no
|
|
170
|
+
* other message until the promise settles (decision 0002).
|
|
171
|
+
*/
|
|
172
|
+
receive(state: S, msg: M, ctx: ActorContext<M>): S | Promise<S>;
|
|
173
|
+
/**
|
|
174
|
+
* Handles lifecycle signals. Optional. The state returned from `terminated` becomes the new
|
|
175
|
+
* state, and anything returned from `preRestart` or `postStop` is ignored. A promise holds the
|
|
176
|
+
* mailbox, as in `receive`. A throw in `preRestart` or `postStop` is logged, and the restart or
|
|
177
|
+
* stop goes ahead.
|
|
178
|
+
*/
|
|
179
|
+
onSignal?(state: S, signal: Signal, ctx: ActorContext<M>): S | Promise<S>;
|
|
180
|
+
}
|
|
181
|
+
/** Options for one `spawn`. */
|
|
182
|
+
export interface SpawnOptions {
|
|
183
|
+
/** What happens when the actor fails (decision 0006). Default `supervise.stop()`. */
|
|
184
|
+
supervision?: SupervisorStrategy;
|
|
185
|
+
/** Mailbox limits. Default: unbounded. */
|
|
186
|
+
mailbox?: {
|
|
187
|
+
/** The most messages the mailbox holds. A `tell` past it becomes a `mailboxFull` dead letter. */
|
|
188
|
+
capacity?: number;
|
|
189
|
+
};
|
|
190
|
+
}
|
|
191
|
+
/** Options for `createActorSystem`. Every field is optional. */
|
|
192
|
+
export interface ActorSystemOptions {
|
|
193
|
+
/** The system's name: lower-case letters, digits and `-`. Default `"troupe"`. */
|
|
194
|
+
name?: string;
|
|
195
|
+
/** Where time and scheduling come from (decision 0003). Default `realScheduler()`. */
|
|
196
|
+
scheduler?: Scheduler;
|
|
197
|
+
/** Where chance comes from, for backoff jitter (decision 0003). Default `Math.random`. */
|
|
198
|
+
random?: () => number;
|
|
199
|
+
/** Where logs go. Default `consoleLogger("warn")`. */
|
|
200
|
+
logger?: Logger;
|
|
201
|
+
/** How long `ask` waits for a reply when it isn't given `timeoutMs`, in ms. Default 5,000. */
|
|
202
|
+
askTimeoutMs?: number;
|
|
203
|
+
/** How many messages one actor runs per turn before others get a go. Default 10. */
|
|
204
|
+
throughput?: number;
|
|
205
|
+
/** How many messages run in a row before the dispatcher yields to the event loop. Default 1,000. */
|
|
206
|
+
yieldAfter?: number;
|
|
207
|
+
}
|
|
208
|
+
type Timestamped<E> = E extends unknown ? {
|
|
209
|
+
readonly seq: number;
|
|
210
|
+
readonly at: number;
|
|
211
|
+
} & E : never;
|
|
212
|
+
/**
|
|
213
|
+
* Something that happened in the system. `seq` orders events across the system: each event takes
|
|
214
|
+
* the next one. It doesn't count a subscriber's events, since one that didn't ask for message
|
|
215
|
+
* events sees gaps while another subscriber did. `at` is the scheduler's time.
|
|
216
|
+
*/
|
|
217
|
+
export type SystemEvent = Timestamped<{
|
|
218
|
+
readonly type: 'spawned';
|
|
219
|
+
readonly path: string;
|
|
220
|
+
}
|
|
221
|
+
/** An actor has terminated. `failure` is present when it stopped because it failed. */
|
|
222
|
+
| {
|
|
223
|
+
readonly type: 'stopped';
|
|
224
|
+
readonly path: string;
|
|
225
|
+
readonly failure?: unknown;
|
|
226
|
+
}
|
|
227
|
+
/** An actor failed, and supervision chose `directive`. */
|
|
228
|
+
| {
|
|
229
|
+
readonly type: 'failed';
|
|
230
|
+
readonly path: string;
|
|
231
|
+
readonly error: unknown;
|
|
232
|
+
readonly directive: 'stop' | 'resume' | 'restart';
|
|
233
|
+
}
|
|
234
|
+
/**
|
|
235
|
+
* An actor is about to run `initial` again. `attempt` counts restarts from 1, since the
|
|
236
|
+
* restart window or the backoff last reset. `delayMs` is the backoff it waited, 0 for a restart.
|
|
237
|
+
*/
|
|
238
|
+
| {
|
|
239
|
+
readonly type: 'restarted';
|
|
240
|
+
readonly path: string;
|
|
241
|
+
readonly attempt: number;
|
|
242
|
+
readonly delayMs: number;
|
|
243
|
+
}
|
|
244
|
+
/**
|
|
245
|
+
* A persistent actor's journal append succeeded and its events were applied. They hold sequence
|
|
246
|
+
* numbers `fromSeq` to `toSeq`.
|
|
247
|
+
*/
|
|
248
|
+
| {
|
|
249
|
+
readonly type: 'persisted';
|
|
250
|
+
readonly path: string;
|
|
251
|
+
readonly persistenceId: string;
|
|
252
|
+
readonly fromSeq: number;
|
|
253
|
+
readonly toSeq: number;
|
|
254
|
+
}
|
|
255
|
+
/**
|
|
256
|
+
* A persistent actor finished recovering, with `lastSeq` the sequence number of its last event.
|
|
257
|
+
* `snapshotSeq` is where its snapshot left off, 0 without one, so `lastSeq - snapshotSeq` events
|
|
258
|
+
* were replayed. (Not `seq`, which every event already has: its place in the event stream.)
|
|
259
|
+
*/
|
|
260
|
+
| {
|
|
261
|
+
readonly type: 'recovered';
|
|
262
|
+
readonly path: string;
|
|
263
|
+
readonly persistenceId: string;
|
|
264
|
+
readonly snapshotSeq: number;
|
|
265
|
+
readonly lastSeq: number;
|
|
266
|
+
}
|
|
267
|
+
/**
|
|
268
|
+
* A message went into an actor's mailbox. Published only to subscribers that asked for
|
|
269
|
+
* messages. Every one ends with exactly one `processed`, or a `deadLetter` with its `id`.
|
|
270
|
+
*/
|
|
271
|
+
| {
|
|
272
|
+
readonly type: 'delivered';
|
|
273
|
+
readonly path: string;
|
|
274
|
+
/** Unique per message in this system, so the event that ends it can be matched to it. */
|
|
275
|
+
readonly id: number;
|
|
276
|
+
/**
|
|
277
|
+
* The sending actor's path, when it's known: the actor whose handler was running when the
|
|
278
|
+
* message was sent, before any `await` (decision 0020). Absent for a send after an `await`,
|
|
279
|
+
* from a timer, or from outside any actor.
|
|
280
|
+
*/
|
|
281
|
+
readonly from?: string;
|
|
282
|
+
/** The message itself, not a copy. */
|
|
283
|
+
readonly message: unknown;
|
|
284
|
+
/** The mailbox's size after this message went in. */
|
|
285
|
+
readonly depth: number;
|
|
286
|
+
}
|
|
287
|
+
/**
|
|
288
|
+
* An actor finished handling a message, including any async work it awaited. Published only to
|
|
289
|
+
* subscribers that asked for messages. When the handler fails, this comes before the `failed`.
|
|
290
|
+
*/
|
|
291
|
+
| {
|
|
292
|
+
readonly type: 'processed';
|
|
293
|
+
readonly path: string;
|
|
294
|
+
/** The `id` of the message's `delivered`. */
|
|
295
|
+
readonly id: number;
|
|
296
|
+
/** Scheduler time from taking the message to settling. 0 under virtual time for sync work. */
|
|
297
|
+
readonly durationMs: number;
|
|
298
|
+
/** The mailbox's size after this message came out. */
|
|
299
|
+
readonly depth: number;
|
|
300
|
+
/** Whether the handler returned a different state object. */
|
|
301
|
+
readonly stateChanged: boolean;
|
|
302
|
+
/** Present, and true, for a cancelled timer's message, which no handler saw. */
|
|
303
|
+
readonly skipped?: true;
|
|
304
|
+
} | {
|
|
305
|
+
readonly type: 'deadLetter';
|
|
306
|
+
readonly recipient: string;
|
|
307
|
+
readonly message: unknown;
|
|
308
|
+
/**
|
|
309
|
+
* The `id` of the message's `delivered`, when it had one: it was in the mailbox while
|
|
310
|
+
* message events were on, and a stop drained it.
|
|
311
|
+
*/
|
|
312
|
+
readonly id?: number;
|
|
313
|
+
/**
|
|
314
|
+
* `mailboxFull`: a bounded mailbox was full. `stopped`: the actor was stopping or had
|
|
315
|
+
* stopped. `askCompleted`: a reply to an `ask` that had already been answered or had timed
|
|
316
|
+
* out. `terminated`: the system was terminating.
|
|
317
|
+
*/
|
|
318
|
+
readonly reason: 'mailboxFull' | 'stopped' | 'askCompleted' | 'terminated';
|
|
319
|
+
}>;
|
|
320
|
+
/** The system's events, delivered synchronously, in order, as they happen. */
|
|
321
|
+
export interface EventStream {
|
|
322
|
+
/**
|
|
323
|
+
* Calls `listener` with every event from now on. A listener that throws is logged and skipped.
|
|
324
|
+
*
|
|
325
|
+
* `delivered` and `processed` go only to listeners that pass `{ messages: true }`. While none
|
|
326
|
+
* has, the system doesn't build them at all (decision 0020).
|
|
327
|
+
* @returns A function that unsubscribes.
|
|
328
|
+
* @throws TypeError unless `listener` is a function, and `opts` an object whose `messages`, if
|
|
329
|
+
* set, is a boolean.
|
|
330
|
+
*/
|
|
331
|
+
subscribe(listener: (event: SystemEvent) => void, opts?: {
|
|
332
|
+
messages?: boolean;
|
|
333
|
+
}): () => void;
|
|
334
|
+
}
|
|
335
|
+
/** A running actor system: the root of an actor hierarchy. */
|
|
336
|
+
export interface ActorSystem {
|
|
337
|
+
/** The name it was created with. */
|
|
338
|
+
readonly name: string;
|
|
339
|
+
/**
|
|
340
|
+
* Starts a top-level actor under `/user` and returns its ref at once.
|
|
341
|
+
* @param name Optional. Generated as `$1`, `$2` and so on when omitted.
|
|
342
|
+
* @throws ActorNameError for an invalid, reserved or taken name.
|
|
343
|
+
* @throws ActorSystemTerminatedError once `terminate()` has been called.
|
|
344
|
+
* @throws TypeError for a definition or options that can't be used.
|
|
345
|
+
*/
|
|
346
|
+
spawn<M, S>(def: ActorDef<M, S>, name?: string, opts?: SpawnOptions): ActorRef<M>;
|
|
347
|
+
/**
|
|
348
|
+
* Stops a top-level actor after its current message. Stopping one that has already terminated
|
|
349
|
+
* does nothing.
|
|
350
|
+
* @throws NotAChildError if `ref` isn't a top-level actor of this system.
|
|
351
|
+
*/
|
|
352
|
+
stop(ref: AnyRef): void;
|
|
353
|
+
/** The system's event stream. */
|
|
354
|
+
readonly events: EventStream;
|
|
355
|
+
/**
|
|
356
|
+
* Stops every actor, children first, and resolves once the last one has terminated. After it's
|
|
357
|
+
* called, `spawn` throws and every `tell` becomes a `terminated` dead letter. Calling it again
|
|
358
|
+
* returns the same promise.
|
|
359
|
+
*/
|
|
360
|
+
terminate(): Promise<void>;
|
|
361
|
+
/** Resolves once the system has terminated. */
|
|
362
|
+
readonly whenTerminated: Promise<void>;
|
|
363
|
+
}
|
|
364
|
+
export {};
|
package/dist/types.js
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
package/package.json
CHANGED
|
@@ -1,6 +1,112 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@kylewillett/troupe",
|
|
3
|
-
"version": "0.
|
|
4
|
-
"
|
|
5
|
-
"
|
|
6
|
-
|
|
3
|
+
"version": "0.1.0",
|
|
4
|
+
"description": "Typed actors for TypeScript: supervision, event-sourced persistent actors, and (later) cluster sharding.",
|
|
5
|
+
"license": "MIT",
|
|
6
|
+
"author": "Kyle Willett",
|
|
7
|
+
"homepage": "https://github.com/Fours/troupe#readme",
|
|
8
|
+
"repository": {
|
|
9
|
+
"type": "git",
|
|
10
|
+
"url": "git+https://github.com/Fours/troupe.git"
|
|
11
|
+
},
|
|
12
|
+
"bugs": {
|
|
13
|
+
"url": "https://github.com/Fours/troupe/issues"
|
|
14
|
+
},
|
|
15
|
+
"keywords": [
|
|
16
|
+
"actor",
|
|
17
|
+
"actors",
|
|
18
|
+
"actor-model",
|
|
19
|
+
"akka",
|
|
20
|
+
"supervision",
|
|
21
|
+
"event-sourcing",
|
|
22
|
+
"typescript"
|
|
23
|
+
],
|
|
24
|
+
"type": "module",
|
|
25
|
+
"engines": {
|
|
26
|
+
"node": ">=22.18"
|
|
27
|
+
},
|
|
28
|
+
"publishConfig": {
|
|
29
|
+
"access": "public"
|
|
30
|
+
},
|
|
31
|
+
"files": [
|
|
32
|
+
"dist",
|
|
33
|
+
"CHANGELOG.md"
|
|
34
|
+
],
|
|
35
|
+
"main": "./dist/index.js",
|
|
36
|
+
"types": "./dist/index.d.ts",
|
|
37
|
+
"exports": {
|
|
38
|
+
".": {
|
|
39
|
+
"types": "./dist/index.d.ts",
|
|
40
|
+
"import": "./dist/index.js"
|
|
41
|
+
},
|
|
42
|
+
"./testkit": {
|
|
43
|
+
"types": "./dist/testkit/index.d.ts",
|
|
44
|
+
"import": "./dist/testkit/index.js"
|
|
45
|
+
},
|
|
46
|
+
"./persistence": {
|
|
47
|
+
"types": "./dist/persistence/index.d.ts",
|
|
48
|
+
"import": "./dist/persistence/index.js"
|
|
49
|
+
},
|
|
50
|
+
"./persistence/sqlite": {
|
|
51
|
+
"types": "./dist/node/sqlite/index.d.ts",
|
|
52
|
+
"import": "./dist/node/sqlite/index.js"
|
|
53
|
+
},
|
|
54
|
+
"./persistence/postgres": {
|
|
55
|
+
"types": "./dist/persistence/postgres/index.d.ts",
|
|
56
|
+
"import": "./dist/persistence/postgres/index.js"
|
|
57
|
+
},
|
|
58
|
+
"./backstage": {
|
|
59
|
+
"types": "./dist/backstage/index.d.ts",
|
|
60
|
+
"import": "./dist/backstage/index.js"
|
|
61
|
+
},
|
|
62
|
+
"./backstage/server": {
|
|
63
|
+
"types": "./dist/node/backstage/index.d.ts",
|
|
64
|
+
"import": "./dist/node/backstage/index.js"
|
|
65
|
+
}
|
|
66
|
+
},
|
|
67
|
+
"sideEffects": false,
|
|
68
|
+
"scripts": {
|
|
69
|
+
"build": "tsc -p tsconfig.build.json && tsc -p tsconfig.build.node.json && node scripts/write-sql.ts && vite build --config backstage/vite.config.ts",
|
|
70
|
+
"typecheck": "tsc -p tsconfig.json --noEmit && tsc -p tsconfig.build.json --noEmit && tsc -p tsconfig.build.node.json --noEmit && tsc -p demo/tsconfig.json && tsc -p backstage/tsconfig.json && tsc -p e2e/tsconfig.json",
|
|
71
|
+
"lint": "eslint . && prettier --check .",
|
|
72
|
+
"format": "prettier --write .",
|
|
73
|
+
"test": "vitest run --project unit",
|
|
74
|
+
"test:watch": "vitest --project unit",
|
|
75
|
+
"test:integration": "vitest run --project integration",
|
|
76
|
+
"coverage": "vitest run --coverage --project unit --project integration",
|
|
77
|
+
"postgres:up": "docker compose -f docker-compose.test.yml up -d --wait",
|
|
78
|
+
"postgres:down": "docker compose -f docker-compose.test.yml down",
|
|
79
|
+
"example": "npm run build && node examples/box-office/main.ts",
|
|
80
|
+
"example:backstage": "npm run build && node examples/backstage/main.ts",
|
|
81
|
+
"bench": "node --expose-gc bench/run.ts",
|
|
82
|
+
"demo:dev": "vite --config demo/vite.config.ts",
|
|
83
|
+
"demo:build": "vite build --config demo/vite.config.ts",
|
|
84
|
+
"demo:preview": "vite preview --config demo/vite.config.ts",
|
|
85
|
+
"test:e2e": "npm run build && npm run demo:build && playwright test",
|
|
86
|
+
"check:package": "node scripts/check-pack.ts && publint && attw --pack --profile esm-only"
|
|
87
|
+
},
|
|
88
|
+
"devDependencies": {
|
|
89
|
+
"@arethetypeswrong/cli": "^0.18.5",
|
|
90
|
+
"@eslint/js": "^10.0.1",
|
|
91
|
+
"@playwright/test": "^1.65.1",
|
|
92
|
+
"@types/node": "^22.20.5",
|
|
93
|
+
"@types/pg": "^8.23.1",
|
|
94
|
+
"@types/react": "^19.3.0",
|
|
95
|
+
"@types/react-dom": "^19.3.0",
|
|
96
|
+
"@vitejs/plugin-react": "^6.3.0",
|
|
97
|
+
"@vitest/coverage-v8": "^4.1.12",
|
|
98
|
+
"eslint": "^10.14.0",
|
|
99
|
+
"eslint-config-prettier": "^10.1.8",
|
|
100
|
+
"eslint-plugin-react-hooks": "^7.1.1",
|
|
101
|
+
"pg": "^8.23.1",
|
|
102
|
+
"prettier": "^3.9.10",
|
|
103
|
+
"publint": "^0.3.25",
|
|
104
|
+
"react": "^19.3.1",
|
|
105
|
+
"react-dom": "^19.3.1",
|
|
106
|
+
"typescript": "^6.0.3",
|
|
107
|
+
"typescript-eslint": "^8.72.1",
|
|
108
|
+
"vite": "^8.3.8",
|
|
109
|
+
"vitest": "^4.1.12",
|
|
110
|
+
"zod": "^4.6.7"
|
|
111
|
+
}
|
|
112
|
+
}
|