@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
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
<!doctype html>
|
|
2
|
+
<html lang="en">
|
|
3
|
+
<head>
|
|
4
|
+
<meta charset="UTF-8" />
|
|
5
|
+
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
|
|
6
|
+
<title>Backstage · Troupe</title>
|
|
7
|
+
<script type="module" crossorigin src="./assets/index-CeefBsDh.js"></script>
|
|
8
|
+
<link rel="stylesheet" crossorigin href="./assets/index-Bg0MCiqs.css">
|
|
9
|
+
</head>
|
|
10
|
+
<body>
|
|
11
|
+
<div id="root"></div>
|
|
12
|
+
</body>
|
|
13
|
+
</html>
|
package/dist/cell.d.ts
ADDED
|
@@ -0,0 +1,129 @@
|
|
|
1
|
+
import type { Dispatcher, Runnable } from './dispatcher.js';
|
|
2
|
+
import type { EventBus } from './events.js';
|
|
3
|
+
import { type CellInspection } from './internal.js';
|
|
4
|
+
import { type Logger } from './logger.js';
|
|
5
|
+
import { Names } from './names.js';
|
|
6
|
+
import { type SupervisorStrategy } from './supervision.js';
|
|
7
|
+
import type { ActorDef, ActorRef, AnyRef, Result, SpawnOptions } from './types.js';
|
|
8
|
+
/** A failure, kept with a flag because `throw undefined` is legal. */
|
|
9
|
+
type Failure = {
|
|
10
|
+
readonly error: unknown;
|
|
11
|
+
} | undefined;
|
|
12
|
+
/** Something told when a watched cell terminates: another cell, or a testkit probe. */
|
|
13
|
+
export interface Watcher {
|
|
14
|
+
/** Tells the watcher that `target` has terminated. It must not throw. */
|
|
15
|
+
notifyTerminated(target: CellNode): void;
|
|
16
|
+
}
|
|
17
|
+
/** What other cells, the guardian and the system see of a cell, whatever its types. */
|
|
18
|
+
export interface CellNode extends Watcher {
|
|
19
|
+
readonly ref: AnyRef;
|
|
20
|
+
readonly name: string;
|
|
21
|
+
readonly parent: ParentNode;
|
|
22
|
+
readonly terminated: boolean;
|
|
23
|
+
readonly failure: Failure;
|
|
24
|
+
/** Asks the cell to stop after its current message, ahead of its queued messages. */
|
|
25
|
+
requestStop(): void;
|
|
26
|
+
/** Watchers of this cell, kept so it can notify them when it terminates. */
|
|
27
|
+
readonly watchers: Set<Watcher>;
|
|
28
|
+
/** Its children that haven't terminated, in spawn order. */
|
|
29
|
+
readonly childCells: Map<string, CellNode>;
|
|
30
|
+
/** What an inspector sees of it, read-only. */
|
|
31
|
+
inspect(): CellInspection;
|
|
32
|
+
}
|
|
33
|
+
/** Something that has children: a cell, or the `/user` guardian. */
|
|
34
|
+
export interface ParentNode {
|
|
35
|
+
readonly path: string;
|
|
36
|
+
readonly names: Names;
|
|
37
|
+
readonly childCells: Map<string, CellNode>;
|
|
38
|
+
/** Called by a child once it has fully terminated, after its `postStop`. */
|
|
39
|
+
removeChild(child: CellNode): void;
|
|
40
|
+
}
|
|
41
|
+
/** What a cell needs from its system. */
|
|
42
|
+
export interface CellHost {
|
|
43
|
+
readonly dispatcher: Dispatcher;
|
|
44
|
+
readonly events: EventBus;
|
|
45
|
+
readonly log: Logger;
|
|
46
|
+
/**
|
|
47
|
+
* The path of the actor whose code is running outside a dispatcher turn, for `delivered`'s
|
|
48
|
+
* `from` (decision 0020). A cell sets it around code it runs after a promise settles. Inside a
|
|
49
|
+
* turn, the dispatcher's `current` says who's running.
|
|
50
|
+
*/
|
|
51
|
+
senderOverride: string | undefined;
|
|
52
|
+
now(): number;
|
|
53
|
+
/** The system's source of chance, for backoff jitter (decision 0003). */
|
|
54
|
+
random(): number;
|
|
55
|
+
/** The system scheduler's `setTimer`. */
|
|
56
|
+
setTimer(task: () => void, delayMs: number): () => void;
|
|
57
|
+
/**
|
|
58
|
+
* Called with +1 when a cell starts waiting on a promise, from an async handler or
|
|
59
|
+
* `pipeToSelf`, and -1 when it settles. The testkit's `settle` waits for the count to reach 0.
|
|
60
|
+
*/
|
|
61
|
+
trackBusy(delta: 1 | -1): void;
|
|
62
|
+
/** Makes a ref with the system's `ask`. */
|
|
63
|
+
makeRef<M>(path: string, tell: (msg: M) => void): ActorRef<M>;
|
|
64
|
+
/**
|
|
65
|
+
* Calls `listener` synchronously when `promise` settles, if it's one of the system's asks.
|
|
66
|
+
* @returns False if it isn't, so the caller must wait on the promise itself.
|
|
67
|
+
*/
|
|
68
|
+
onAskSettled(promise: unknown, listener: (result: Result<unknown>) => void): boolean;
|
|
69
|
+
/** True once `terminate()` has been called. */
|
|
70
|
+
terminating(): boolean;
|
|
71
|
+
/** Spawns an actor under `parent`, with every check `spawn` makes. */
|
|
72
|
+
spawn<M, S>(parent: ParentNode, def: ActorDef<M, S>, name: string | undefined, opts: SpawnOptions | undefined): ActorRef<M>;
|
|
73
|
+
/** The cell behind a ref, if it belongs to this system. */
|
|
74
|
+
cellOf(ref: unknown): CellNode | undefined;
|
|
75
|
+
}
|
|
76
|
+
/** A cell's checked spawn options. */
|
|
77
|
+
export interface CellOptions {
|
|
78
|
+
readonly capacity: number;
|
|
79
|
+
readonly supervision: SupervisorStrategy;
|
|
80
|
+
}
|
|
81
|
+
/**
|
|
82
|
+
* One actor: its state, mailbox and lifecycle. The dispatcher gives it turns, and it runs one
|
|
83
|
+
* message at a time, holding its mailbox while an async `receive` or `onSignal` is pending
|
|
84
|
+
* (decision 0002).
|
|
85
|
+
*
|
|
86
|
+
* It has two queues. The system queue holds stop requests, `terminated` notices and restart
|
|
87
|
+
* steps, and is always read before the user queue, so a stop jumps ahead of queued messages.
|
|
88
|
+
*
|
|
89
|
+
* The user queue holds messages, plus timer and `pipeToSelf` messages in envelopes that are
|
|
90
|
+
* unwrapped when they're dequeued. A timer's envelope is checked against its timer's current
|
|
91
|
+
* generation then, so a cancelled timer's message is never received.
|
|
92
|
+
*
|
|
93
|
+
* While a subscriber wants message events (decision 0020), each message is wrapped with an id as
|
|
94
|
+
* it goes in, publishing `delivered`, and ends with exactly one `processed` or dead letter with
|
|
95
|
+
* that id. While none does, nothing is wrapped or built. The cell names itself as the sender of
|
|
96
|
+
* every `tell` during its turn, and around code it runs once an awaited handler settles.
|
|
97
|
+
*
|
|
98
|
+
* A definition may carry an internal start hook (`src/internal.ts`), which runs after `initial` and
|
|
99
|
+
* holds the mailbox until it settles. Persistent actors recover there (decision 0011).
|
|
100
|
+
*
|
|
101
|
+
* Stopping goes: cancel the timers, dead-letter the user queue, stop every child and wait for them, run `postStop`,
|
|
102
|
+
* then terminate, which frees the name, notifies watchers and publishes `stopped`.
|
|
103
|
+
*
|
|
104
|
+
* A failure goes to the strategy the parent chose (decision 0006). A restart makes a new
|
|
105
|
+
* incarnation behind the same ref (decision 0008): run `preRestart`, drop the actor's own watches,
|
|
106
|
+
* stop the children and wait for them and for any backoff delay, then run `initial` with a new
|
|
107
|
+
* `ctx`. The mailbox, the ref and the watchers carry over.
|
|
108
|
+
*/
|
|
109
|
+
export declare class Cell<M, S> implements Runnable, CellNode, ParentNode {
|
|
110
|
+
#private;
|
|
111
|
+
readonly ref: ActorRef<M>;
|
|
112
|
+
readonly name: string;
|
|
113
|
+
readonly path: string;
|
|
114
|
+
readonly parent: ParentNode;
|
|
115
|
+
readonly names: Names;
|
|
116
|
+
readonly childCells: Map<string, CellNode>;
|
|
117
|
+
readonly watchers: Set<Watcher>;
|
|
118
|
+
constructor(name: string, path: string, def: ActorDef<M, S>, host: CellHost, opts: CellOptions, parent: ParentNode);
|
|
119
|
+
get terminated(): boolean;
|
|
120
|
+
get failure(): Failure;
|
|
121
|
+
inspect(): CellInspection;
|
|
122
|
+
/** Queues the actor's first step, which runs `initial`. */
|
|
123
|
+
start(): void;
|
|
124
|
+
requestStop(): void;
|
|
125
|
+
notifyTerminated(target: CellNode): void;
|
|
126
|
+
removeChild(child: CellNode): void;
|
|
127
|
+
run(max: number): number;
|
|
128
|
+
}
|
|
129
|
+
export {};
|