@arona/core 0.0.1-dev.ff9c398 → 0.0.1-nightly.20261203.1.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/LICENSE +21 -0
- package/README.md +86 -0
- package/dist/index-DROCSc-k.d.ts +1182 -0
- package/dist/index.d.ts +721 -0
- package/dist/index.js +1342 -0
- package/dist/node.d.ts +19 -0
- package/dist/node.js +17 -0
- package/dist/orphan.d.ts +1 -0
- package/dist/orphan.js +9 -0
- package/dist/rolldown-runtime-D8jQpDG7.js +12 -0
- package/dist/session-B5wwY-n5.js +1511 -0
- package/dist/vite.d.ts +24 -0
- package/dist/vite.js +196 -0
- package/package.json +33 -36
- package/bin/cli.js +0 -5
- package/biome.json +0 -32
- package/src/cli/build.ts +0 -46
- package/src/cli/dev.ts +0 -79
- package/src/cli/index.ts +0 -51
- package/src/cli/rspack.config.ts +0 -86
- package/src/helpers/asserts.ts +0 -7
- package/src/helpers/debounce.ts +0 -21
- package/src/index.ts +0 -8
- package/src/renderer/create-renderer.ts +0 -33
- package/src/renderer/helpers/define-component.ts +0 -48
- package/src/renderer/helpers/render-nodes.ts +0 -41
- package/src/renderer/helpers/render-text-content.ts +0 -26
- package/src/renderer/host-config.ts +0 -84
- package/src/renderer/nodes/node.ts +0 -76
- package/src/renderer/nodes/root.tsx +0 -87
- package/src/renderer/nodes/text.ts +0 -22
- package/src/renderer/root-node-provider.tsx +0 -42
- package/tsconfig.json +0 -31
|
@@ -0,0 +1,1182 @@
|
|
|
1
|
+
import { Context, Data, Effect, HashMap, Layer, Option, Schema } from "effect";
|
|
2
|
+
import { AnyStateMachine } from "xstate";
|
|
3
|
+
import { SqlClient } from "effect/sql";
|
|
4
|
+
import { Renderer } from "effect/ui";
|
|
5
|
+
import { FileSystem as FileSystem$1 } from "effect/FileSystem";
|
|
6
|
+
import { Path as Path$1 } from "effect/Path";
|
|
7
|
+
/**
|
|
8
|
+
* Explicit state machines for the parts of Arona whose correctness depends on
|
|
9
|
+
* ordering: a stored message session, its writer lease, and a message target.
|
|
10
|
+
*
|
|
11
|
+
* The machines are declared with XState 6 (`createMachine`) and hosted by
|
|
12
|
+
* `@xstate/effect` where they need to run. The pure tables consumed by stores
|
|
13
|
+
* are derived from those declarations with `deriveMachineTable` instead of
|
|
14
|
+
* being maintained by hand. `machines.test.ts` checks each table against its
|
|
15
|
+
* declaration, and `actor.test.ts` runs the session machine through
|
|
16
|
+
* `@xstate/effect`.
|
|
17
|
+
*
|
|
18
|
+
* The session/lease tables are also mirrored by the bounded TLA+ model in
|
|
19
|
+
* `specs/SessionStore.tla`.
|
|
20
|
+
*/
|
|
21
|
+
interface StateMachineTable<State extends string, Event extends string> {
|
|
22
|
+
/** The XState machine id, used in diagnostics. */
|
|
23
|
+
readonly id: string;
|
|
24
|
+
readonly initial: State;
|
|
25
|
+
readonly states: ReadonlyArray<State>;
|
|
26
|
+
readonly events: ReadonlyArray<Event>;
|
|
27
|
+
readonly terminal: ReadonlyArray<State>;
|
|
28
|
+
readonly edges: ReadonlyArray<{
|
|
29
|
+
readonly from: State;
|
|
30
|
+
readonly event: Event;
|
|
31
|
+
readonly to: State;
|
|
32
|
+
}>;
|
|
33
|
+
}
|
|
34
|
+
/** The state after `event`, or `undefined` when the event is illegal there. */
|
|
35
|
+
declare const transition: <State extends string, Event extends string>(machine: StateMachineTable<State, Event>, state: State, event: Event) => State | undefined;
|
|
36
|
+
declare const canTransition: <State extends string, Event extends string>(machine: StateMachineTable<State, Event>, state: State, event: Event) => boolean;
|
|
37
|
+
/**
|
|
38
|
+
* A caller asked for an edge the declaration does not allow.
|
|
39
|
+
*
|
|
40
|
+
* Silent coercion (`?? "closed"`) hides the mistake at the exact call site that
|
|
41
|
+
* made it. This error keeps the state and event, so a stack trace points at the
|
|
42
|
+
* transition that is missing from the machine.
|
|
43
|
+
*/
|
|
44
|
+
declare class IllegalTransitionError extends Error {
|
|
45
|
+
readonly machineName: string;
|
|
46
|
+
readonly from: string;
|
|
47
|
+
readonly event: string;
|
|
48
|
+
readonly code = "state-machine/illegal-transition";
|
|
49
|
+
constructor(machineName: string, from: string, event: string);
|
|
50
|
+
}
|
|
51
|
+
/** The next state, or an `IllegalTransitionError` when the edge is missing. */
|
|
52
|
+
declare const transitionOrThrow: <State extends string, Event extends string>(machine: StateMachineTable<State, Event>, state: State, event: Event) => State;
|
|
53
|
+
declare const isTerminal: <State extends string, Event extends string>(machine: StateMachineTable<State, Event>, state: State) => boolean;
|
|
54
|
+
/** Every state reachable from `machine.initial` by any sequence of events. */
|
|
55
|
+
declare const reachableStates: <State extends string, Event extends string>(machine: StateMachineTable<State, Event>) => ReadonlySet<State>;
|
|
56
|
+
/**
|
|
57
|
+
* Derives a runtime transition table from an XState 6 machine declaration.
|
|
58
|
+
* The table is a pure value, so consumers that cannot run an Effect (stores,
|
|
59
|
+
* synchronous lifecycle objects) still share the machine's single topology.
|
|
60
|
+
*
|
|
61
|
+
* Only the legal `from -> event -> to` edges are exposed. Guards and context
|
|
62
|
+
* assignment stay in Effect-side pure functions (see `leaseTransition`), which
|
|
63
|
+
* keeps the table cheap for synchronous callers.
|
|
64
|
+
*/
|
|
65
|
+
declare const deriveMachineTable: <State extends string, Event extends string>(options: {
|
|
66
|
+
readonly initial: State;
|
|
67
|
+
readonly states: ReadonlyArray<State>;
|
|
68
|
+
readonly events: ReadonlyArray<Event>;
|
|
69
|
+
readonly terminal: ReadonlyArray<State>;
|
|
70
|
+
readonly machine: AnyStateMachine;
|
|
71
|
+
}) => StateMachineTable<State, Event>;
|
|
72
|
+
type SessionStatus = "pending" | "active" | "closed";
|
|
73
|
+
/** A session that `sweep` has removed. It is not a stored status. */
|
|
74
|
+
declare const GONE: "gone";
|
|
75
|
+
type Gone = typeof GONE;
|
|
76
|
+
type SessionEvent = "stateStored" | "interactionStored" | "messageAttached" | "close" | "sweep";
|
|
77
|
+
/**
|
|
78
|
+
* Stored session lifecycle.
|
|
79
|
+
*
|
|
80
|
+
* ```
|
|
81
|
+
* stateStored / interactionStored
|
|
82
|
+
* pending ─────────────────────────────────▶ active
|
|
83
|
+
* │ messageAttached │ messageAttached
|
|
84
|
+
* └─────────────────┐ │
|
|
85
|
+
* ▼ │
|
|
86
|
+
* pending │
|
|
87
|
+
* │ close
|
|
88
|
+
* pending / active ───────────────────────────▶ closed
|
|
89
|
+
* pending / active / closed ──── sweep ───────▶ gone
|
|
90
|
+
* ```
|
|
91
|
+
*
|
|
92
|
+
* `close` is idempotent: closing a closed session stays closed. A closed
|
|
93
|
+
* session rejects every mutation except `close` and `sweep`; that is what
|
|
94
|
+
* makes "closed" terminal instead of a hint.
|
|
95
|
+
*/
|
|
96
|
+
declare const sessionModel: import("xstate").StateMachine<never, {
|
|
97
|
+
type: string;
|
|
98
|
+
}, {
|
|
99
|
+
[x: string]: import("xstate").AnyActor;
|
|
100
|
+
}, "pending" | "active" | "closed" | "gone", string, unknown, {}, {
|
|
101
|
+
type: string;
|
|
102
|
+
}, never, {
|
|
103
|
+
readonly id: "arona/session";
|
|
104
|
+
readonly initial: "pending";
|
|
105
|
+
readonly states: {
|
|
106
|
+
readonly pending: {
|
|
107
|
+
readonly on: {
|
|
108
|
+
readonly stateStored: {
|
|
109
|
+
readonly target: "active";
|
|
110
|
+
};
|
|
111
|
+
readonly interactionStored: {
|
|
112
|
+
readonly target: "active";
|
|
113
|
+
};
|
|
114
|
+
readonly messageAttached: {
|
|
115
|
+
readonly target: "pending";
|
|
116
|
+
};
|
|
117
|
+
readonly close: {
|
|
118
|
+
readonly target: "closed";
|
|
119
|
+
};
|
|
120
|
+
readonly sweep: {
|
|
121
|
+
readonly target: "gone";
|
|
122
|
+
};
|
|
123
|
+
};
|
|
124
|
+
};
|
|
125
|
+
readonly active: {
|
|
126
|
+
readonly on: {
|
|
127
|
+
readonly stateStored: {
|
|
128
|
+
readonly target: "active";
|
|
129
|
+
};
|
|
130
|
+
readonly interactionStored: {
|
|
131
|
+
readonly target: "active";
|
|
132
|
+
};
|
|
133
|
+
readonly messageAttached: {
|
|
134
|
+
readonly target: "active";
|
|
135
|
+
};
|
|
136
|
+
readonly close: {
|
|
137
|
+
readonly target: "closed";
|
|
138
|
+
};
|
|
139
|
+
readonly sweep: {
|
|
140
|
+
readonly target: "gone";
|
|
141
|
+
};
|
|
142
|
+
};
|
|
143
|
+
};
|
|
144
|
+
readonly closed: {
|
|
145
|
+
readonly on: {
|
|
146
|
+
readonly close: {
|
|
147
|
+
readonly target: "closed";
|
|
148
|
+
};
|
|
149
|
+
readonly sweep: {
|
|
150
|
+
readonly target: "gone";
|
|
151
|
+
};
|
|
152
|
+
};
|
|
153
|
+
};
|
|
154
|
+
readonly gone: {};
|
|
155
|
+
};
|
|
156
|
+
} & {
|
|
157
|
+
schemas: {
|
|
158
|
+
rejections: Record<string, import("xstate").StandardSchemaV1<unknown, unknown>>;
|
|
159
|
+
};
|
|
160
|
+
}, Record<string, (...args: any[]) => void | {
|
|
161
|
+
context?: any;
|
|
162
|
+
children?: any;
|
|
163
|
+
}>, Record<string, import("xstate").AnyActorLogic>, Record<string, Function>, Record<string, number | Function>, never, never> & {
|
|
164
|
+
states: {
|
|
165
|
+
readonly id: "arona/session";
|
|
166
|
+
readonly initial: "pending";
|
|
167
|
+
readonly states: {
|
|
168
|
+
readonly pending: {
|
|
169
|
+
readonly on: {
|
|
170
|
+
readonly stateStored: {
|
|
171
|
+
readonly target: "active";
|
|
172
|
+
};
|
|
173
|
+
readonly interactionStored: {
|
|
174
|
+
readonly target: "active";
|
|
175
|
+
};
|
|
176
|
+
readonly messageAttached: {
|
|
177
|
+
readonly target: "pending";
|
|
178
|
+
};
|
|
179
|
+
readonly close: {
|
|
180
|
+
readonly target: "closed";
|
|
181
|
+
};
|
|
182
|
+
readonly sweep: {
|
|
183
|
+
readonly target: "gone";
|
|
184
|
+
};
|
|
185
|
+
};
|
|
186
|
+
};
|
|
187
|
+
readonly active: {
|
|
188
|
+
readonly on: {
|
|
189
|
+
readonly stateStored: {
|
|
190
|
+
readonly target: "active";
|
|
191
|
+
};
|
|
192
|
+
readonly interactionStored: {
|
|
193
|
+
readonly target: "active";
|
|
194
|
+
};
|
|
195
|
+
readonly messageAttached: {
|
|
196
|
+
readonly target: "active";
|
|
197
|
+
};
|
|
198
|
+
readonly close: {
|
|
199
|
+
readonly target: "closed";
|
|
200
|
+
};
|
|
201
|
+
readonly sweep: {
|
|
202
|
+
readonly target: "gone";
|
|
203
|
+
};
|
|
204
|
+
};
|
|
205
|
+
};
|
|
206
|
+
readonly closed: {
|
|
207
|
+
readonly on: {
|
|
208
|
+
readonly close: {
|
|
209
|
+
readonly target: "closed";
|
|
210
|
+
};
|
|
211
|
+
readonly sweep: {
|
|
212
|
+
readonly target: "gone";
|
|
213
|
+
};
|
|
214
|
+
};
|
|
215
|
+
};
|
|
216
|
+
readonly gone: {};
|
|
217
|
+
};
|
|
218
|
+
};
|
|
219
|
+
} & {
|
|
220
|
+
readonly id: "arona/session";
|
|
221
|
+
readonly version: undefined;
|
|
222
|
+
};
|
|
223
|
+
declare const sessionMachine: StateMachineTable<SessionStatus | Gone, SessionEvent>;
|
|
224
|
+
/** Derived expiry: an expired session is logically `gone` even before sweep. */
|
|
225
|
+
declare const isExpired: (session: {
|
|
226
|
+
readonly expiresAt?: number | undefined;
|
|
227
|
+
}, now: number) => boolean;
|
|
228
|
+
/** The state a record is in at `now`, folding expiry into the machine. */
|
|
229
|
+
declare const sessionStateAt: (status: SessionStatus, expiresAt: number | undefined, now: number) => SessionStatus | Gone;
|
|
230
|
+
/** Whether `event` is legal in the record's state at `now`. */
|
|
231
|
+
declare const sessionAllows: (status: SessionStatus, expiresAt: number | undefined, now: number, event: SessionEvent) => boolean;
|
|
232
|
+
/** A lease as stored next to a session. */
|
|
233
|
+
interface Lease {
|
|
234
|
+
readonly owner: string;
|
|
235
|
+
readonly until: number;
|
|
236
|
+
}
|
|
237
|
+
type LeaseState = Data.TaggedEnum<{
|
|
238
|
+
free: {};
|
|
239
|
+
held: {
|
|
240
|
+
readonly owner: string;
|
|
241
|
+
readonly until: number;
|
|
242
|
+
};
|
|
243
|
+
}>;
|
|
244
|
+
declare const LeaseState: Data.TaggedEnum.Constructor<{
|
|
245
|
+
readonly _tag: "free";
|
|
246
|
+
} | {
|
|
247
|
+
readonly _tag: "held";
|
|
248
|
+
readonly owner: string;
|
|
249
|
+
readonly until: number;
|
|
250
|
+
}>;
|
|
251
|
+
declare const LEASE_FREE: LeaseState;
|
|
252
|
+
type LeaseEvent = Data.TaggedEnum<{
|
|
253
|
+
acquire: {
|
|
254
|
+
readonly owner: string;
|
|
255
|
+
readonly ttlMs: number;
|
|
256
|
+
readonly now: number;
|
|
257
|
+
};
|
|
258
|
+
renew: {
|
|
259
|
+
readonly owner: string;
|
|
260
|
+
readonly ttlMs: number;
|
|
261
|
+
readonly now: number;
|
|
262
|
+
};
|
|
263
|
+
release: {
|
|
264
|
+
readonly owner: string;
|
|
265
|
+
};
|
|
266
|
+
expire: {
|
|
267
|
+
readonly now: number;
|
|
268
|
+
};
|
|
269
|
+
}>;
|
|
270
|
+
declare const LeaseEvent: Data.TaggedEnum.Constructor<{
|
|
271
|
+
readonly _tag: "acquire";
|
|
272
|
+
readonly owner: string;
|
|
273
|
+
readonly ttlMs: number;
|
|
274
|
+
readonly now: number;
|
|
275
|
+
} | {
|
|
276
|
+
readonly _tag: "renew";
|
|
277
|
+
readonly owner: string;
|
|
278
|
+
readonly ttlMs: number;
|
|
279
|
+
readonly now: number;
|
|
280
|
+
} | {
|
|
281
|
+
readonly _tag: "release";
|
|
282
|
+
readonly owner: string;
|
|
283
|
+
} | {
|
|
284
|
+
readonly _tag: "expire";
|
|
285
|
+
readonly now: number;
|
|
286
|
+
}>;
|
|
287
|
+
interface LeaseTransition {
|
|
288
|
+
readonly state: LeaseState;
|
|
289
|
+
/** Whether the caller's request was granted. */
|
|
290
|
+
readonly ok: boolean;
|
|
291
|
+
/** Whether the stored lease must be written back. */
|
|
292
|
+
readonly changed: boolean;
|
|
293
|
+
}
|
|
294
|
+
/**
|
|
295
|
+
* The lease topology. Guards and next values live in the pure functions above
|
|
296
|
+
* and are applied by `leaseTransition`, so the table stays synchronous while
|
|
297
|
+
* XState owns the legal state graph.
|
|
298
|
+
*/
|
|
299
|
+
declare const leaseModel: import("xstate").StateMachine<never, {
|
|
300
|
+
type: string;
|
|
301
|
+
}, {
|
|
302
|
+
[x: string]: import("xstate").AnyActor;
|
|
303
|
+
}, "free" | "held", string, unknown, {}, {
|
|
304
|
+
type: string;
|
|
305
|
+
}, never, {
|
|
306
|
+
readonly id: "arona/lease";
|
|
307
|
+
readonly initial: "free";
|
|
308
|
+
readonly states: {
|
|
309
|
+
readonly free: {
|
|
310
|
+
readonly on: {
|
|
311
|
+
readonly acquire: {
|
|
312
|
+
readonly target: "held";
|
|
313
|
+
};
|
|
314
|
+
};
|
|
315
|
+
};
|
|
316
|
+
readonly held: {
|
|
317
|
+
readonly on: {
|
|
318
|
+
readonly acquire: {
|
|
319
|
+
readonly target: "held";
|
|
320
|
+
};
|
|
321
|
+
readonly renew: {
|
|
322
|
+
readonly target: "held";
|
|
323
|
+
};
|
|
324
|
+
readonly release: {
|
|
325
|
+
readonly target: "free";
|
|
326
|
+
};
|
|
327
|
+
readonly expire: {
|
|
328
|
+
readonly target: "free";
|
|
329
|
+
};
|
|
330
|
+
};
|
|
331
|
+
};
|
|
332
|
+
};
|
|
333
|
+
} & {
|
|
334
|
+
schemas: {
|
|
335
|
+
rejections: Record<string, import("xstate").StandardSchemaV1<unknown, unknown>>;
|
|
336
|
+
};
|
|
337
|
+
}, Record<string, (...args: any[]) => void | {
|
|
338
|
+
context?: any;
|
|
339
|
+
children?: any;
|
|
340
|
+
}>, Record<string, import("xstate").AnyActorLogic>, Record<string, Function>, Record<string, number | Function>, never, never> & {
|
|
341
|
+
states: {
|
|
342
|
+
readonly id: "arona/lease";
|
|
343
|
+
readonly initial: "free";
|
|
344
|
+
readonly states: {
|
|
345
|
+
readonly free: {
|
|
346
|
+
readonly on: {
|
|
347
|
+
readonly acquire: {
|
|
348
|
+
readonly target: "held";
|
|
349
|
+
};
|
|
350
|
+
};
|
|
351
|
+
};
|
|
352
|
+
readonly held: {
|
|
353
|
+
readonly on: {
|
|
354
|
+
readonly acquire: {
|
|
355
|
+
readonly target: "held";
|
|
356
|
+
};
|
|
357
|
+
readonly renew: {
|
|
358
|
+
readonly target: "held";
|
|
359
|
+
};
|
|
360
|
+
readonly release: {
|
|
361
|
+
readonly target: "free";
|
|
362
|
+
};
|
|
363
|
+
readonly expire: {
|
|
364
|
+
readonly target: "free";
|
|
365
|
+
};
|
|
366
|
+
};
|
|
367
|
+
};
|
|
368
|
+
};
|
|
369
|
+
};
|
|
370
|
+
} & {
|
|
371
|
+
readonly id: "arona/lease";
|
|
372
|
+
readonly version: undefined;
|
|
373
|
+
};
|
|
374
|
+
type LeaseStatus = "free" | "held";
|
|
375
|
+
type LeaseEventName = "acquire" | "renew" | "release" | "expire";
|
|
376
|
+
declare const leaseMachine: StateMachineTable<LeaseStatus, LeaseEventName>;
|
|
377
|
+
/**
|
|
378
|
+
* The single-writer lease protocol.
|
|
379
|
+
*
|
|
380
|
+
* Invariants (checked exhaustively in `machines.test.ts`, by the reference
|
|
381
|
+
* model in `invariants.property.test.ts` and by TLC in
|
|
382
|
+
* `specs/SessionStore.tla`):
|
|
383
|
+
*
|
|
384
|
+
* 1. A live lease (`until > now`) has exactly one owner.
|
|
385
|
+
* 2. `acquire` by a different owner never succeeds while another live lease
|
|
386
|
+
* exists.
|
|
387
|
+
* 3. `renew` never changes the owner and never resurrects an expired lease.
|
|
388
|
+
* 4. Only the owner can release.
|
|
389
|
+
* 5. TTL is measured from the caller's `now`; an expired lease is free.
|
|
390
|
+
*
|
|
391
|
+
* The legal source states come from `leaseMachine`; the guards and next values
|
|
392
|
+
* are the pure `may*` and `heldAfter*` functions above, shared with the model
|
|
393
|
+
* tests and the reference property model.
|
|
394
|
+
*/
|
|
395
|
+
declare const leaseTransition: (state: LeaseState, event: LeaseEvent) => LeaseTransition;
|
|
396
|
+
/** Whether `owner` may write at `now`. */
|
|
397
|
+
declare const leaseOwnerAt: (state: LeaseState, now: number) => string | undefined;
|
|
398
|
+
type TargetState = "idle" | "sending" | "closed";
|
|
399
|
+
type TargetEvent = "drain" | "sent" | "failed" | "close";
|
|
400
|
+
/**
|
|
401
|
+
* The target keeps at most one in-flight platform request.
|
|
402
|
+
*
|
|
403
|
+
* ```
|
|
404
|
+
* idle ──drain──▶ sending ──sent/failed──▶ idle
|
|
405
|
+
* │ │
|
|
406
|
+
* └──────close─────┴──────▶ closed
|
|
407
|
+
* ```
|
|
408
|
+
*
|
|
409
|
+
* `closed` is terminal. `sent`/`failed` always return to `idle` so a failed
|
|
410
|
+
* send can be retried; only a successful send may advance `lastSent`.
|
|
411
|
+
*/
|
|
412
|
+
declare const targetModel: import("xstate").StateMachine<never, {
|
|
413
|
+
type: string;
|
|
414
|
+
}, {
|
|
415
|
+
[x: string]: import("xstate").AnyActor;
|
|
416
|
+
}, "closed" | "idle" | "sending", string, unknown, {}, {
|
|
417
|
+
type: string;
|
|
418
|
+
}, never, {
|
|
419
|
+
readonly id: "arona/message-target";
|
|
420
|
+
readonly initial: "idle";
|
|
421
|
+
readonly states: {
|
|
422
|
+
readonly idle: {
|
|
423
|
+
readonly on: {
|
|
424
|
+
readonly drain: {
|
|
425
|
+
readonly target: "sending";
|
|
426
|
+
};
|
|
427
|
+
readonly close: {
|
|
428
|
+
readonly target: "closed";
|
|
429
|
+
};
|
|
430
|
+
};
|
|
431
|
+
};
|
|
432
|
+
readonly sending: {
|
|
433
|
+
readonly on: {
|
|
434
|
+
readonly sent: {
|
|
435
|
+
readonly target: "idle";
|
|
436
|
+
};
|
|
437
|
+
readonly failed: {
|
|
438
|
+
readonly target: "idle";
|
|
439
|
+
};
|
|
440
|
+
readonly close: {
|
|
441
|
+
readonly target: "closed";
|
|
442
|
+
};
|
|
443
|
+
};
|
|
444
|
+
};
|
|
445
|
+
readonly closed: {
|
|
446
|
+
readonly on: {
|
|
447
|
+
readonly close: {
|
|
448
|
+
readonly target: "closed";
|
|
449
|
+
};
|
|
450
|
+
};
|
|
451
|
+
};
|
|
452
|
+
};
|
|
453
|
+
} & {
|
|
454
|
+
schemas: {
|
|
455
|
+
rejections: Record<string, import("xstate").StandardSchemaV1<unknown, unknown>>;
|
|
456
|
+
};
|
|
457
|
+
}, Record<string, (...args: any[]) => void | {
|
|
458
|
+
context?: any;
|
|
459
|
+
children?: any;
|
|
460
|
+
}>, Record<string, import("xstate").AnyActorLogic>, Record<string, Function>, Record<string, number | Function>, never, never> & {
|
|
461
|
+
states: {
|
|
462
|
+
readonly id: "arona/message-target";
|
|
463
|
+
readonly initial: "idle";
|
|
464
|
+
readonly states: {
|
|
465
|
+
readonly idle: {
|
|
466
|
+
readonly on: {
|
|
467
|
+
readonly drain: {
|
|
468
|
+
readonly target: "sending";
|
|
469
|
+
};
|
|
470
|
+
readonly close: {
|
|
471
|
+
readonly target: "closed";
|
|
472
|
+
};
|
|
473
|
+
};
|
|
474
|
+
};
|
|
475
|
+
readonly sending: {
|
|
476
|
+
readonly on: {
|
|
477
|
+
readonly sent: {
|
|
478
|
+
readonly target: "idle";
|
|
479
|
+
};
|
|
480
|
+
readonly failed: {
|
|
481
|
+
readonly target: "idle";
|
|
482
|
+
};
|
|
483
|
+
readonly close: {
|
|
484
|
+
readonly target: "closed";
|
|
485
|
+
};
|
|
486
|
+
};
|
|
487
|
+
};
|
|
488
|
+
readonly closed: {
|
|
489
|
+
readonly on: {
|
|
490
|
+
readonly close: {
|
|
491
|
+
readonly target: "closed";
|
|
492
|
+
};
|
|
493
|
+
};
|
|
494
|
+
};
|
|
495
|
+
};
|
|
496
|
+
};
|
|
497
|
+
} & {
|
|
498
|
+
readonly id: "arona/message-target";
|
|
499
|
+
readonly version: undefined;
|
|
500
|
+
};
|
|
501
|
+
declare const targetMachine: StateMachineTable<TargetState, TargetEvent>;
|
|
502
|
+
type TargetMode = "live" | "paused";
|
|
503
|
+
type TargetModeEvent = "pause" | "resume";
|
|
504
|
+
/**
|
|
505
|
+
* Pausing is a mode beside the send lifecycle, not a fourth send state: a
|
|
506
|
+
* send already in flight still settles, and the target holds the queued
|
|
507
|
+
* snapshot once it is idle again.
|
|
508
|
+
*
|
|
509
|
+
* ```
|
|
510
|
+
* live ◀──resume──▶ paused
|
|
511
|
+
* ```
|
|
512
|
+
*/
|
|
513
|
+
declare const targetModeModel: import("xstate").StateMachine<never, {
|
|
514
|
+
type: string;
|
|
515
|
+
}, {
|
|
516
|
+
[x: string]: import("xstate").AnyActor;
|
|
517
|
+
}, "live" | "paused", string, unknown, {}, {
|
|
518
|
+
type: string;
|
|
519
|
+
}, never, {
|
|
520
|
+
readonly id: "arona/message-target-mode";
|
|
521
|
+
readonly initial: "live";
|
|
522
|
+
readonly states: {
|
|
523
|
+
readonly live: {
|
|
524
|
+
readonly on: {
|
|
525
|
+
readonly pause: {
|
|
526
|
+
readonly target: "paused";
|
|
527
|
+
};
|
|
528
|
+
};
|
|
529
|
+
};
|
|
530
|
+
readonly paused: {
|
|
531
|
+
readonly on: {
|
|
532
|
+
readonly resume: {
|
|
533
|
+
readonly target: "live";
|
|
534
|
+
};
|
|
535
|
+
};
|
|
536
|
+
};
|
|
537
|
+
};
|
|
538
|
+
} & {
|
|
539
|
+
schemas: {
|
|
540
|
+
rejections: Record<string, import("xstate").StandardSchemaV1<unknown, unknown>>;
|
|
541
|
+
};
|
|
542
|
+
}, Record<string, (...args: any[]) => void | {
|
|
543
|
+
context?: any;
|
|
544
|
+
children?: any;
|
|
545
|
+
}>, Record<string, import("xstate").AnyActorLogic>, Record<string, Function>, Record<string, number | Function>, never, never> & {
|
|
546
|
+
states: {
|
|
547
|
+
readonly id: "arona/message-target-mode";
|
|
548
|
+
readonly initial: "live";
|
|
549
|
+
readonly states: {
|
|
550
|
+
readonly live: {
|
|
551
|
+
readonly on: {
|
|
552
|
+
readonly pause: {
|
|
553
|
+
readonly target: "paused";
|
|
554
|
+
};
|
|
555
|
+
};
|
|
556
|
+
};
|
|
557
|
+
readonly paused: {
|
|
558
|
+
readonly on: {
|
|
559
|
+
readonly resume: {
|
|
560
|
+
readonly target: "live";
|
|
561
|
+
};
|
|
562
|
+
};
|
|
563
|
+
};
|
|
564
|
+
};
|
|
565
|
+
};
|
|
566
|
+
} & {
|
|
567
|
+
readonly id: "arona/message-target-mode";
|
|
568
|
+
readonly version: undefined;
|
|
569
|
+
};
|
|
570
|
+
declare const targetModeMachine: StateMachineTable<TargetMode, TargetModeEvent>;
|
|
571
|
+
type RootState = "open" | "closing" | "closed";
|
|
572
|
+
type RootEvent = "close" | "closed";
|
|
573
|
+
/**
|
|
574
|
+
* Closing a root is idempotent and single-flight.
|
|
575
|
+
*
|
|
576
|
+
* ```
|
|
577
|
+
* open ──close──▶ closing ──closed──▶ closed
|
|
578
|
+
* │ ▲
|
|
579
|
+
* └──────────────close───────────────┘
|
|
580
|
+
* ```
|
|
581
|
+
*/
|
|
582
|
+
declare const rootModel: import("xstate").StateMachine<never, {
|
|
583
|
+
type: string;
|
|
584
|
+
}, {
|
|
585
|
+
[x: string]: import("xstate").AnyActor;
|
|
586
|
+
}, "closed" | "open" | "closing", string, unknown, {}, {
|
|
587
|
+
type: string;
|
|
588
|
+
}, never, {
|
|
589
|
+
readonly id: "arona/message-root";
|
|
590
|
+
readonly initial: "open";
|
|
591
|
+
readonly states: {
|
|
592
|
+
readonly open: {
|
|
593
|
+
readonly on: {
|
|
594
|
+
readonly close: {
|
|
595
|
+
readonly target: "closing";
|
|
596
|
+
};
|
|
597
|
+
};
|
|
598
|
+
};
|
|
599
|
+
readonly closing: {
|
|
600
|
+
readonly on: {
|
|
601
|
+
readonly closed: {
|
|
602
|
+
readonly target: "closed";
|
|
603
|
+
};
|
|
604
|
+
};
|
|
605
|
+
};
|
|
606
|
+
readonly closed: {
|
|
607
|
+
readonly on: {
|
|
608
|
+
readonly close: {
|
|
609
|
+
readonly target: "closed";
|
|
610
|
+
};
|
|
611
|
+
};
|
|
612
|
+
};
|
|
613
|
+
};
|
|
614
|
+
} & {
|
|
615
|
+
schemas: {
|
|
616
|
+
rejections: Record<string, import("xstate").StandardSchemaV1<unknown, unknown>>;
|
|
617
|
+
};
|
|
618
|
+
}, Record<string, (...args: any[]) => void | {
|
|
619
|
+
context?: any;
|
|
620
|
+
children?: any;
|
|
621
|
+
}>, Record<string, import("xstate").AnyActorLogic>, Record<string, Function>, Record<string, number | Function>, never, never> & {
|
|
622
|
+
states: {
|
|
623
|
+
readonly id: "arona/message-root";
|
|
624
|
+
readonly initial: "open";
|
|
625
|
+
readonly states: {
|
|
626
|
+
readonly open: {
|
|
627
|
+
readonly on: {
|
|
628
|
+
readonly close: {
|
|
629
|
+
readonly target: "closing";
|
|
630
|
+
};
|
|
631
|
+
};
|
|
632
|
+
};
|
|
633
|
+
readonly closing: {
|
|
634
|
+
readonly on: {
|
|
635
|
+
readonly closed: {
|
|
636
|
+
readonly target: "closed";
|
|
637
|
+
};
|
|
638
|
+
};
|
|
639
|
+
};
|
|
640
|
+
readonly closed: {
|
|
641
|
+
readonly on: {
|
|
642
|
+
readonly close: {
|
|
643
|
+
readonly target: "closed";
|
|
644
|
+
};
|
|
645
|
+
};
|
|
646
|
+
};
|
|
647
|
+
};
|
|
648
|
+
};
|
|
649
|
+
} & {
|
|
650
|
+
readonly id: "arona/message-root";
|
|
651
|
+
readonly version: undefined;
|
|
652
|
+
};
|
|
653
|
+
declare const rootMachine: StateMachineTable<RootState, RootEvent>;
|
|
654
|
+
type RootMode = "live" | "paused";
|
|
655
|
+
type RootModeEvent = "pause" | "resume";
|
|
656
|
+
/**
|
|
657
|
+
* A root drops interactions and holds live edits while paused; closing the
|
|
658
|
+
* root is the separate lifecycle in `rootModel`.
|
|
659
|
+
*
|
|
660
|
+
* ```
|
|
661
|
+
* live ◀──resume──▶ paused
|
|
662
|
+
* ```
|
|
663
|
+
*/
|
|
664
|
+
declare const rootModeModel: import("xstate").StateMachine<never, {
|
|
665
|
+
type: string;
|
|
666
|
+
}, {
|
|
667
|
+
[x: string]: import("xstate").AnyActor;
|
|
668
|
+
}, "live" | "paused", string, unknown, {}, {
|
|
669
|
+
type: string;
|
|
670
|
+
}, never, {
|
|
671
|
+
readonly id: "arona/message-root-mode";
|
|
672
|
+
readonly initial: "live";
|
|
673
|
+
readonly states: {
|
|
674
|
+
readonly live: {
|
|
675
|
+
readonly on: {
|
|
676
|
+
readonly pause: {
|
|
677
|
+
readonly target: "paused";
|
|
678
|
+
};
|
|
679
|
+
};
|
|
680
|
+
};
|
|
681
|
+
readonly paused: {
|
|
682
|
+
readonly on: {
|
|
683
|
+
readonly resume: {
|
|
684
|
+
readonly target: "live";
|
|
685
|
+
};
|
|
686
|
+
};
|
|
687
|
+
};
|
|
688
|
+
};
|
|
689
|
+
} & {
|
|
690
|
+
schemas: {
|
|
691
|
+
rejections: Record<string, import("xstate").StandardSchemaV1<unknown, unknown>>;
|
|
692
|
+
};
|
|
693
|
+
}, Record<string, (...args: any[]) => void | {
|
|
694
|
+
context?: any;
|
|
695
|
+
children?: any;
|
|
696
|
+
}>, Record<string, import("xstate").AnyActorLogic>, Record<string, Function>, Record<string, number | Function>, never, never> & {
|
|
697
|
+
states: {
|
|
698
|
+
readonly id: "arona/message-root-mode";
|
|
699
|
+
readonly initial: "live";
|
|
700
|
+
readonly states: {
|
|
701
|
+
readonly live: {
|
|
702
|
+
readonly on: {
|
|
703
|
+
readonly pause: {
|
|
704
|
+
readonly target: "paused";
|
|
705
|
+
};
|
|
706
|
+
};
|
|
707
|
+
};
|
|
708
|
+
readonly paused: {
|
|
709
|
+
readonly on: {
|
|
710
|
+
readonly resume: {
|
|
711
|
+
readonly target: "live";
|
|
712
|
+
};
|
|
713
|
+
};
|
|
714
|
+
};
|
|
715
|
+
};
|
|
716
|
+
};
|
|
717
|
+
} & {
|
|
718
|
+
readonly id: "arona/message-root-mode";
|
|
719
|
+
readonly version: undefined;
|
|
720
|
+
};
|
|
721
|
+
declare const rootModeMachine: StateMachineTable<RootMode, RootModeEvent>;
|
|
722
|
+
type InteractionState = "idle" | "waiting";
|
|
723
|
+
type InteractionEvent = "arrive" | "start" | "expire";
|
|
724
|
+
/**
|
|
725
|
+
* A buffered interaction waiting for a writer lease.
|
|
726
|
+
*
|
|
727
|
+
* ```
|
|
728
|
+
* idle ──arrive──▶ waiting ──start──▶ idle
|
|
729
|
+
* │
|
|
730
|
+
* └──expire──▶ idle
|
|
731
|
+
* ```
|
|
732
|
+
*
|
|
733
|
+
* The wait is bounded by the caller's deadline: a press that loses the lease
|
|
734
|
+
* race waits briefly for the current writer, then either runs (`start`) or is
|
|
735
|
+
* dropped with an explicit `expire`. Both outcomes return to `idle`; the
|
|
736
|
+
* handler itself runs inside the lease and is not a state of this machine.
|
|
737
|
+
* This is the "coyote time" for a user action that arrives just outside the
|
|
738
|
+
* legal window.
|
|
739
|
+
*/
|
|
740
|
+
declare const interactionModel: import("xstate").StateMachine<never, {
|
|
741
|
+
type: string;
|
|
742
|
+
}, {
|
|
743
|
+
[x: string]: import("xstate").AnyActor;
|
|
744
|
+
}, "idle" | "waiting", string, unknown, {}, {
|
|
745
|
+
type: string;
|
|
746
|
+
}, never, {
|
|
747
|
+
readonly id: "arona/interaction";
|
|
748
|
+
readonly initial: "idle";
|
|
749
|
+
readonly states: {
|
|
750
|
+
readonly idle: {
|
|
751
|
+
readonly on: {
|
|
752
|
+
readonly arrive: {
|
|
753
|
+
readonly target: "waiting";
|
|
754
|
+
};
|
|
755
|
+
};
|
|
756
|
+
};
|
|
757
|
+
readonly waiting: {
|
|
758
|
+
readonly on: {
|
|
759
|
+
readonly start: {
|
|
760
|
+
readonly target: "idle";
|
|
761
|
+
};
|
|
762
|
+
readonly expire: {
|
|
763
|
+
readonly target: "idle";
|
|
764
|
+
};
|
|
765
|
+
};
|
|
766
|
+
};
|
|
767
|
+
};
|
|
768
|
+
} & {
|
|
769
|
+
schemas: {
|
|
770
|
+
rejections: Record<string, import("xstate").StandardSchemaV1<unknown, unknown>>;
|
|
771
|
+
};
|
|
772
|
+
}, Record<string, (...args: any[]) => void | {
|
|
773
|
+
context?: any;
|
|
774
|
+
children?: any;
|
|
775
|
+
}>, Record<string, import("xstate").AnyActorLogic>, Record<string, Function>, Record<string, number | Function>, never, never> & {
|
|
776
|
+
states: {
|
|
777
|
+
readonly id: "arona/interaction";
|
|
778
|
+
readonly initial: "idle";
|
|
779
|
+
readonly states: {
|
|
780
|
+
readonly idle: {
|
|
781
|
+
readonly on: {
|
|
782
|
+
readonly arrive: {
|
|
783
|
+
readonly target: "waiting";
|
|
784
|
+
};
|
|
785
|
+
};
|
|
786
|
+
};
|
|
787
|
+
readonly waiting: {
|
|
788
|
+
readonly on: {
|
|
789
|
+
readonly start: {
|
|
790
|
+
readonly target: "idle";
|
|
791
|
+
};
|
|
792
|
+
readonly expire: {
|
|
793
|
+
readonly target: "idle";
|
|
794
|
+
};
|
|
795
|
+
};
|
|
796
|
+
};
|
|
797
|
+
};
|
|
798
|
+
};
|
|
799
|
+
} & {
|
|
800
|
+
readonly id: "arona/interaction";
|
|
801
|
+
readonly version: undefined;
|
|
802
|
+
};
|
|
803
|
+
declare const interactionMachine: StateMachineTable<InteractionState, InteractionEvent>;
|
|
804
|
+
/** The prefix that marks an Arona interaction id. */
|
|
805
|
+
declare const INTERACTION_ID_PREFIX = "ar1";
|
|
806
|
+
/** Discord rejects a `custom_id` longer than this. */
|
|
807
|
+
declare const MAX_INTERACTION_ID_LENGTH = 100;
|
|
808
|
+
/** Where a resumed message lives on the platform. */
|
|
809
|
+
declare const SessionMessageRef: Schema.Struct<{
|
|
810
|
+
readonly id: Schema.String;
|
|
811
|
+
readonly channelId: Schema.optional<Schema.String>;
|
|
812
|
+
readonly guildId: Schema.optional<Schema.String>;
|
|
813
|
+
}>;
|
|
814
|
+
type SessionMessageRef = typeof SessionMessageRef.Type;
|
|
815
|
+
/** The encoded Effect UI model tree persisted for one message. */
|
|
816
|
+
declare const MessageSessionState: Schema.$Record<Schema.String, Schema.Unknown>;
|
|
817
|
+
/**
|
|
818
|
+
* Everything needed to rebuild one rendered message in another process.
|
|
819
|
+
*
|
|
820
|
+
* `state` is the encoded Effect UI model tree from `Root.snapshot`. `props`
|
|
821
|
+
* is caller-encoded and must be serialisable when the store is durable.
|
|
822
|
+
*/
|
|
823
|
+
declare const MessageSessionSchema: Schema.Struct<{
|
|
824
|
+
readonly id: Schema.String;
|
|
825
|
+
/** The state version the message on the platform shows. Bumped per interaction. */
|
|
826
|
+
readonly version: Schema.Int;
|
|
827
|
+
readonly status: Schema.Literals<readonly ["pending", "active", "closed"]>;
|
|
828
|
+
/** Registered component key, resolved by the platform integration. */
|
|
829
|
+
readonly component: Schema.String;
|
|
830
|
+
/** Application build fingerprint. Empty means "do not check". */
|
|
831
|
+
readonly build: Schema.String;
|
|
832
|
+
readonly props: Schema.Unknown;
|
|
833
|
+
readonly state: Schema.optional<Schema.$Record<Schema.String, Schema.Unknown>>;
|
|
834
|
+
readonly message: Schema.optional<Schema.Struct<{
|
|
835
|
+
readonly id: Schema.String;
|
|
836
|
+
readonly channelId: Schema.optional<Schema.String>;
|
|
837
|
+
readonly guildId: Schema.optional<Schema.String>;
|
|
838
|
+
}>>;
|
|
839
|
+
readonly ephemeral: Schema.Boolean;
|
|
840
|
+
readonly createdAt: Schema.Finite;
|
|
841
|
+
readonly updatedAt: Schema.Finite;
|
|
842
|
+
readonly expiresAt: Schema.optional<Schema.Finite>;
|
|
843
|
+
readonly lastInteractionId: Schema.optional<Schema.String>;
|
|
844
|
+
}>;
|
|
845
|
+
type MessageSession = typeof MessageSessionSchema.Type;
|
|
846
|
+
/** The session pieces encoded in every generated interaction id. */
|
|
847
|
+
declare const InteractionIdParts: Schema.Struct<{
|
|
848
|
+
readonly sessionId: Schema.String;
|
|
849
|
+
readonly version: Schema.Int;
|
|
850
|
+
/** The node's own key: an auto ordinal or the author's custom id. */
|
|
851
|
+
readonly key: Schema.String;
|
|
852
|
+
}>;
|
|
853
|
+
type InteractionIdParts = typeof InteractionIdParts.Type;
|
|
854
|
+
/**
|
|
855
|
+
* Stable, machine-readable codes for session failures.
|
|
856
|
+
*
|
|
857
|
+
* Codes are for logs, metrics and API responses; the tag names and messages
|
|
858
|
+
* stay free to change. Pair every code with {@link SessionRepair}.
|
|
859
|
+
*/
|
|
860
|
+
declare const SessionErrorCode: {
|
|
861
|
+
readonly store: "session/store";
|
|
862
|
+
readonly notFound: "session/not-found";
|
|
863
|
+
readonly conflict: "session/conflict";
|
|
864
|
+
readonly alreadyExists: "session/already-exists";
|
|
865
|
+
readonly closed: "session/closed";
|
|
866
|
+
readonly expired: "session/expired";
|
|
867
|
+
readonly leaseLost: "session/lease-lost";
|
|
868
|
+
readonly inconsistentStore: "session/inconsistent-store";
|
|
869
|
+
};
|
|
870
|
+
type SessionErrorCode = (typeof SessionErrorCode)[keyof typeof SessionErrorCode];
|
|
871
|
+
/**
|
|
872
|
+
* What a caller should do next. This is the "information scent" half of an
|
|
873
|
+
* error: the tag says what failed, this says where to go.
|
|
874
|
+
*/
|
|
875
|
+
declare const SessionRepair: {
|
|
876
|
+
readonly store: "Check the store connection and retry the operation.";
|
|
877
|
+
readonly notFound: "Start a new session or resume from the stored message id.";
|
|
878
|
+
readonly conflict: "Re-read the session and retry against the stored version; the client heals automatically.";
|
|
879
|
+
readonly alreadyExists: "Use a new session id or resume the existing session.";
|
|
880
|
+
readonly closed: "Mount a new message; a closed session cannot be mutated.";
|
|
881
|
+
readonly expired: "Start a new session; sweep may remove the expired record.";
|
|
882
|
+
readonly leaseLost: "Another writer holds the session; retry after its lease expires.";
|
|
883
|
+
readonly inconsistentStore: "Use a store with compare-and-set (SQLite or D1) for resumable sessions.";
|
|
884
|
+
};
|
|
885
|
+
declare const SessionStoreError_base: Schema.Class<SessionStoreError, Schema.TaggedStruct<"SessionStoreError", {
|
|
886
|
+
readonly code: Schema.optional<Schema.String>;
|
|
887
|
+
readonly repair: Schema.optional<Schema.String>;
|
|
888
|
+
readonly message: Schema.String;
|
|
889
|
+
readonly cause: Schema.optional<Schema.Defect>;
|
|
890
|
+
}>, import("effect/Cause").YieldableError & {
|
|
891
|
+
readonly brand: unique symbol;
|
|
892
|
+
}>;
|
|
893
|
+
/** A store could not complete an operation. */
|
|
894
|
+
declare class SessionStoreError extends SessionStoreError_base {}
|
|
895
|
+
declare const SessionNotFound_base: Schema.Class<SessionNotFound, Schema.TaggedStruct<"SessionNotFound", {
|
|
896
|
+
readonly code: Schema.optional<Schema.String>;
|
|
897
|
+
readonly repair: Schema.optional<Schema.String>;
|
|
898
|
+
readonly id: Schema.String;
|
|
899
|
+
}>, import("effect/Cause").YieldableError & {
|
|
900
|
+
readonly brand: unique symbol;
|
|
901
|
+
}>;
|
|
902
|
+
/** A session id was not found. */
|
|
903
|
+
declare class SessionNotFound extends SessionNotFound_base {}
|
|
904
|
+
declare const SessionConflict_base: Schema.Class<SessionConflict, Schema.TaggedStruct<"SessionConflict", {
|
|
905
|
+
readonly code: Schema.optional<Schema.String>;
|
|
906
|
+
readonly repair: Schema.optional<Schema.String>;
|
|
907
|
+
readonly id: Schema.String;
|
|
908
|
+
readonly expected: Schema.Int;
|
|
909
|
+
readonly actual: Schema.Int;
|
|
910
|
+
}>, import("effect/Cause").YieldableError & {
|
|
911
|
+
readonly brand: unique symbol;
|
|
912
|
+
}>;
|
|
913
|
+
/** The caller's expected version is not the stored version. */
|
|
914
|
+
declare class SessionConflict extends SessionConflict_base {}
|
|
915
|
+
declare const SessionAlreadyExists_base: Schema.Class<SessionAlreadyExists, Schema.TaggedStruct<"SessionAlreadyExists", {
|
|
916
|
+
readonly code: Schema.optional<Schema.String>;
|
|
917
|
+
readonly repair: Schema.optional<Schema.String>;
|
|
918
|
+
readonly id: Schema.String;
|
|
919
|
+
}>, import("effect/Cause").YieldableError & {
|
|
920
|
+
readonly brand: unique symbol;
|
|
921
|
+
}>;
|
|
922
|
+
/** A new session reused an existing id. */
|
|
923
|
+
declare class SessionAlreadyExists extends SessionAlreadyExists_base {}
|
|
924
|
+
declare const SessionClosed_base: Schema.Class<SessionClosed, Schema.TaggedStruct<"SessionClosed", {
|
|
925
|
+
readonly code: Schema.optional<Schema.String>;
|
|
926
|
+
readonly repair: Schema.optional<Schema.String>;
|
|
927
|
+
readonly id: Schema.String;
|
|
928
|
+
}>, import("effect/Cause").YieldableError & {
|
|
929
|
+
readonly brand: unique symbol;
|
|
930
|
+
}>;
|
|
931
|
+
/** The session is closed and rejects mutations. */
|
|
932
|
+
declare class SessionClosed extends SessionClosed_base {}
|
|
933
|
+
declare const SessionExpired_base: Schema.Class<SessionExpired, Schema.TaggedStruct<"SessionExpired", {
|
|
934
|
+
readonly code: Schema.optional<Schema.String>;
|
|
935
|
+
readonly repair: Schema.optional<Schema.String>;
|
|
936
|
+
readonly id: Schema.String;
|
|
937
|
+
readonly expiresAt: Schema.Finite;
|
|
938
|
+
}>, import("effect/Cause").YieldableError & {
|
|
939
|
+
readonly brand: unique symbol;
|
|
940
|
+
}>;
|
|
941
|
+
/** The session has expired but `sweep` has not removed it yet. */
|
|
942
|
+
declare class SessionExpired extends SessionExpired_base {}
|
|
943
|
+
declare const SessionLeaseLost_base: Schema.Class<SessionLeaseLost, Schema.TaggedStruct<"SessionLeaseLost", {
|
|
944
|
+
readonly code: Schema.optional<Schema.String>;
|
|
945
|
+
readonly repair: Schema.optional<Schema.String>;
|
|
946
|
+
readonly id: Schema.String;
|
|
947
|
+
readonly owner: Schema.String;
|
|
948
|
+
}>, import("effect/Cause").YieldableError & {
|
|
949
|
+
readonly brand: unique symbol;
|
|
950
|
+
}>;
|
|
951
|
+
/** The interaction lost its writer lease before it could store state. */
|
|
952
|
+
declare class SessionLeaseLost extends SessionLeaseLost_base {}
|
|
953
|
+
declare const SessionStoreInconsistent_base: Schema.Class<SessionStoreInconsistent, Schema.TaggedStruct<"SessionStoreInconsistent", {
|
|
954
|
+
readonly code: Schema.optional<Schema.String>;
|
|
955
|
+
readonly repair: Schema.optional<Schema.String>;
|
|
956
|
+
readonly consistency: Schema.String;
|
|
957
|
+
}>, import("effect/Cause").YieldableError & {
|
|
958
|
+
readonly brand: unique symbol;
|
|
959
|
+
}>;
|
|
960
|
+
/**
|
|
961
|
+
* The store cannot honor the session protocol.
|
|
962
|
+
*
|
|
963
|
+
* KV is eventually consistent and has no atomic compare-and-set, so a
|
|
964
|
+
* concurrent writer can overwrite another. Mounting a resumable session with
|
|
965
|
+
* leases on such a store is refused instead of silently corrupting state.
|
|
966
|
+
*/
|
|
967
|
+
declare class SessionStoreInconsistent extends SessionStoreInconsistent_base {}
|
|
968
|
+
type MutationError = SessionStoreError | SessionNotFound | SessionConflict | SessionClosed | SessionExpired | SessionLeaseLost;
|
|
969
|
+
/** The consistency a store can offer a concurrent writer. */
|
|
970
|
+
type Consistency = "strong" | "eventual";
|
|
971
|
+
/** Default rows returned by a session page. */
|
|
972
|
+
declare const DEFAULT_SESSION_PAGE_LIMIT = 100;
|
|
973
|
+
/** Hard cap so a caller cannot ask one page to materialize the whole store. */
|
|
974
|
+
declare const MAX_SESSION_PAGE_LIMIT = 1000;
|
|
975
|
+
/** A bounded session read or sweep. Cursors are opaque to callers. */
|
|
976
|
+
interface SessionPageOptions {
|
|
977
|
+
/** Maximum rows in this page. Clamped to 1..1000. Defaults to 100. */
|
|
978
|
+
readonly limit?: number | undefined;
|
|
979
|
+
/** The cursor returned by the previous page, passed back unchanged. */
|
|
980
|
+
readonly cursor?: string | undefined;
|
|
981
|
+
}
|
|
982
|
+
interface SessionPage {
|
|
983
|
+
readonly sessions: ReadonlyArray<MessageSession>;
|
|
984
|
+
/** Present when another page may exist. */
|
|
985
|
+
readonly cursor?: string | undefined;
|
|
986
|
+
}
|
|
987
|
+
interface SessionSweepPage {
|
|
988
|
+
readonly removed: number;
|
|
989
|
+
/** Present when another sweep page may exist. */
|
|
990
|
+
readonly cursor?: string | undefined;
|
|
991
|
+
}
|
|
992
|
+
/** Clamps an untrusted page limit before it reaches a query. */
|
|
993
|
+
declare const sessionPageLimit: (limit: number | undefined) => number;
|
|
994
|
+
/** The service shape of a message session store. */
|
|
995
|
+
interface MessageSessionStoreShape {
|
|
996
|
+
/**
|
|
997
|
+
* `strong` stores provide compare-and-set; `eventual` stores (KV) do not and
|
|
998
|
+
* must not be used for concurrent writers.
|
|
999
|
+
*/
|
|
1000
|
+
readonly consistency: Consistency;
|
|
1001
|
+
create(session: MessageSession): Effect.Effect<void, SessionStoreError | SessionAlreadyExists>;
|
|
1002
|
+
get(id: string): Effect.Effect<Option.Option<MessageSession>, SessionStoreError>;
|
|
1003
|
+
/**
|
|
1004
|
+
* Compares `expectedVersion`, applies `update`, bumps the version and
|
|
1005
|
+
* returns the stored record. The callback must not mutate the record.
|
|
1006
|
+
*/
|
|
1007
|
+
update(id: string, expectedVersion: number, update: (session: MessageSession) => MessageSession,
|
|
1008
|
+
/**
|
|
1009
|
+
* When set, the version check and the lease check commit together.
|
|
1010
|
+
* A missing or foreign lease fails with `SessionLeaseLost` and does not write.
|
|
1011
|
+
*/
|
|
1012
|
+
leaseOwner?: string): Effect.Effect<MessageSession, MutationError>;
|
|
1013
|
+
/** Stores the first state and marks the session active without bumping the version. */
|
|
1014
|
+
setState(id: string, expectedVersion: number, state: Renderer.State): Effect.Effect<MessageSession, MutationError>;
|
|
1015
|
+
/** Attaches the platform message without changing the interaction version. */
|
|
1016
|
+
attachMessage(id: string, message: SessionMessageRef): Effect.Effect<MessageSession, MutationError>;
|
|
1017
|
+
/** The session that owns a platform message, if one is known. */
|
|
1018
|
+
findByMessage(messageId: string): Effect.Effect<Option.Option<string>, SessionStoreError>;
|
|
1019
|
+
/** Marks a session closed. Closing a closed session is a no-op. */
|
|
1020
|
+
close(id: string): Effect.Effect<void, SessionStoreError | SessionNotFound>;
|
|
1021
|
+
/**
|
|
1022
|
+
* Removes one bounded page of closed and expired sessions, ordered by id.
|
|
1023
|
+
* Pass the returned cursor back until it is absent.
|
|
1024
|
+
*/
|
|
1025
|
+
sweep(now: number, options?: SessionPageOptions): Effect.Effect<SessionSweepPage, SessionStoreError>;
|
|
1026
|
+
/**
|
|
1027
|
+
* One bounded page of sessions a restart could resume eagerly, ordered by
|
|
1028
|
+
* id. Pass the returned cursor back until it is absent.
|
|
1029
|
+
*/
|
|
1030
|
+
listActive(options?: SessionPageOptions): Effect.Effect<SessionPage, SessionStoreError>;
|
|
1031
|
+
/**
|
|
1032
|
+
* Acquires a short lease for one writer. Returns `false` when another owner
|
|
1033
|
+
* holds an unexpired lease. Expired leases are taken over.
|
|
1034
|
+
*/
|
|
1035
|
+
acquire(id: string, owner: string, ttlMs: number): Effect.Effect<boolean, SessionStoreError | SessionNotFound | SessionClosed | SessionExpired>;
|
|
1036
|
+
/** Extends an unexpired lease held by `owner`; `false` means it was lost. */
|
|
1037
|
+
renew(id: string, owner: string, ttlMs: number): Effect.Effect<boolean, SessionStoreError | SessionNotFound | SessionClosed | SessionExpired>;
|
|
1038
|
+
/** Releases a lease only if `owner` still holds it. */
|
|
1039
|
+
release(id: string, owner: string): Effect.Effect<void, SessionStoreError>;
|
|
1040
|
+
}
|
|
1041
|
+
declare const MessageSessionStore_base: Context.ServiceClass<MessageSessionStore, "@arona/core/session/MessageSessionStore", MessageSessionStoreShape>;
|
|
1042
|
+
/** The session store service. */
|
|
1043
|
+
declare class MessageSessionStore extends MessageSessionStore_base {}
|
|
1044
|
+
/** A short, URL-safe id for one rendered message. */
|
|
1045
|
+
declare const makeSessionId: () => string;
|
|
1046
|
+
/**
|
|
1047
|
+
* Builds the id Arona sends as a Discord `custom_id`.
|
|
1048
|
+
*
|
|
1049
|
+
* The session and version let a cold process find the record before it has
|
|
1050
|
+
* rendered anything. `key` stays the author's custom id, or `a<n>` for an
|
|
1051
|
+
* auto-assigned interactive node.
|
|
1052
|
+
*/
|
|
1053
|
+
declare const encodeInteractionId: (sessionId: string, version: number, key: string) => string;
|
|
1054
|
+
/** Reads an Arona interaction id, or `undefined` for a foreign id. */
|
|
1055
|
+
declare const parseInteractionId: (value: string | null | undefined) => InteractionIdParts | undefined;
|
|
1056
|
+
declare const storeError: (message: string, cause: unknown) => SessionStoreError;
|
|
1057
|
+
/** A store that carries a strong consistency guarantee. */
|
|
1058
|
+
type StrongMessageSessionStore = MessageSessionStoreShape & {
|
|
1059
|
+
readonly consistency: "strong";
|
|
1060
|
+
};
|
|
1061
|
+
/** Whether the store can serialize concurrent writers. */
|
|
1062
|
+
declare const isStrongStore: (store: MessageSessionStoreShape) => store is StrongMessageSessionStore;
|
|
1063
|
+
/**
|
|
1064
|
+
* Narrows a store to one that supports the lease/CAS protocol.
|
|
1065
|
+
*
|
|
1066
|
+
* The lease path is typed against {@link StrongMessageSessionStore}, so a
|
|
1067
|
+
* direct caller with an eventual store gets a type error. This runtime check
|
|
1068
|
+
* covers stores read from the context, where the service type is wide.
|
|
1069
|
+
*/
|
|
1070
|
+
declare const asStrongStore: (store: MessageSessionStoreShape) => Effect.Effect<StrongMessageSessionStore, SessionStoreInconsistent>;
|
|
1071
|
+
/** Builds a session error with its code and repair hint. */
|
|
1072
|
+
declare const sessionNotFound: (id: string) => SessionNotFound;
|
|
1073
|
+
declare const sessionConflict: (id: string, expected: number, actual: number) => SessionConflict;
|
|
1074
|
+
declare const sessionAlreadyExists: (id: string) => SessionAlreadyExists;
|
|
1075
|
+
declare const sessionClosed: (id: string) => SessionClosed;
|
|
1076
|
+
declare const sessionExpired: (id: string, expiresAt: number) => SessionExpired;
|
|
1077
|
+
declare const sessionLeaseLost: (id: string, owner: string) => SessionLeaseLost;
|
|
1078
|
+
/** Uses Effect's DateTime module rather than the ambient `Date` clock. */
|
|
1079
|
+
declare const nowMillis: () => number;
|
|
1080
|
+
declare const checkSessionMutable: (session: MessageSession, now: number) => SessionClosed | SessionExpired | undefined;
|
|
1081
|
+
declare const isActive: (session: MessageSession, now: number) => boolean;
|
|
1082
|
+
/** A store mutation, with the timestamp chosen by the caller. */
|
|
1083
|
+
type SessionMutation = Data.TaggedEnum<{
|
|
1084
|
+
update: {
|
|
1085
|
+
readonly now: number;
|
|
1086
|
+
readonly update: (current: MessageSession) => MessageSession;
|
|
1087
|
+
};
|
|
1088
|
+
setState: {
|
|
1089
|
+
readonly now: number;
|
|
1090
|
+
readonly state: Renderer.State;
|
|
1091
|
+
};
|
|
1092
|
+
attachMessage: {
|
|
1093
|
+
readonly now: number;
|
|
1094
|
+
readonly message: SessionMessageRef;
|
|
1095
|
+
};
|
|
1096
|
+
close: {
|
|
1097
|
+
readonly now: number;
|
|
1098
|
+
};
|
|
1099
|
+
}>;
|
|
1100
|
+
declare const SessionMutation: Data.TaggedEnum.Constructor<{
|
|
1101
|
+
readonly _tag: "update";
|
|
1102
|
+
readonly now: number;
|
|
1103
|
+
readonly update: (current: MessageSession) => MessageSession;
|
|
1104
|
+
} | {
|
|
1105
|
+
readonly _tag: "setState";
|
|
1106
|
+
readonly now: number;
|
|
1107
|
+
readonly state: Renderer.State;
|
|
1108
|
+
} | {
|
|
1109
|
+
readonly _tag: "attachMessage";
|
|
1110
|
+
readonly now: number;
|
|
1111
|
+
readonly message: SessionMessageRef;
|
|
1112
|
+
} | {
|
|
1113
|
+
readonly _tag: "close";
|
|
1114
|
+
readonly now: number;
|
|
1115
|
+
}>;
|
|
1116
|
+
type SessionAdvance = Data.TaggedEnum<{
|
|
1117
|
+
ok: {
|
|
1118
|
+
readonly session: MessageSession;
|
|
1119
|
+
};
|
|
1120
|
+
closed: {};
|
|
1121
|
+
expired: {
|
|
1122
|
+
readonly expiresAt: number;
|
|
1123
|
+
};
|
|
1124
|
+
}>;
|
|
1125
|
+
declare const SessionAdvance: Data.TaggedEnum.Constructor<{
|
|
1126
|
+
readonly _tag: "closed";
|
|
1127
|
+
} | {
|
|
1128
|
+
readonly _tag: "ok";
|
|
1129
|
+
readonly session: MessageSession;
|
|
1130
|
+
} | {
|
|
1131
|
+
readonly _tag: "expired";
|
|
1132
|
+
readonly expiresAt: number;
|
|
1133
|
+
}>;
|
|
1134
|
+
declare const advanceSession: (current: MessageSession, mutation: SessionMutation) => SessionAdvance;
|
|
1135
|
+
type SessionAdvanceFailure = ReturnType<typeof SessionAdvance.closed> | ReturnType<typeof SessionAdvance.expired>;
|
|
1136
|
+
/** Converts an `advanceSession` failure into the store's tagged error. */
|
|
1137
|
+
declare const advanceError: (id: string, advance: SessionAdvanceFailure) => SessionClosed | SessionExpired;
|
|
1138
|
+
/**
|
|
1139
|
+
* Applies the session migrations through Effect SQL's `Migrator`.
|
|
1140
|
+
*
|
|
1141
|
+
* The migrations are supplied as effects rather than files, so a binding
|
|
1142
|
+
* without a filesystem can still use the migrator. Once a client supports
|
|
1143
|
+
* transactions, `Migrator` records each migration atomically.
|
|
1144
|
+
*/
|
|
1145
|
+
declare const migrateSqlSessionStore: (client: SqlClient.SqlClient) => Effect.Effect<void, SessionStoreError>;
|
|
1146
|
+
/**
|
|
1147
|
+
* Applies the schema without a transaction.
|
|
1148
|
+
*
|
|
1149
|
+
* D1 does not support transactions, and `Migrator` currently infers
|
|
1150
|
+
* transactionality from the dialect. Use this until `Migrator` can be told
|
|
1151
|
+
* that a client must run without a transaction. Every statement is
|
|
1152
|
+
* idempotent, so a repeated run is safe.
|
|
1153
|
+
*/
|
|
1154
|
+
declare const applySqlSessionSchema: (client: SqlClient.SqlClient) => Effect.Effect<void, SessionStoreError>;
|
|
1155
|
+
/**
|
|
1156
|
+
* The session store for a SQLite-compatible Effect SQL client.
|
|
1157
|
+
*
|
|
1158
|
+
* SQLite and D1 share the same compiler and placeholders, so both adapters get
|
|
1159
|
+
* the same compare-and-swap, pagination and lease rules from this one
|
|
1160
|
+
* implementation.
|
|
1161
|
+
*/
|
|
1162
|
+
declare const sqlSessionStore: (client: SqlClient.SqlClient, clock?: () => number) => StrongMessageSessionStore;
|
|
1163
|
+
declare namespace index_d_exports {
|
|
1164
|
+
export { Consistency, DEFAULT_SESSION_PAGE_LIMIT, FileStore, INTERACTION_ID_PREFIX, InteractionIdParts, MAX_INTERACTION_ID_LENGTH, MAX_SESSION_PAGE_LIMIT, MemoryStore, MessageSession, MessageSessionSchema, MessageSessionState, MessageSessionStore, MessageSessionStoreShape, SessionAdvance, SessionAlreadyExists, SessionClosed, SessionConflict, SessionErrorCode, SessionExpired, SessionLeaseLost, SessionMessageRef, SessionMutation, SessionNotFound, SessionPage, SessionPageOptions, SessionRepair, SessionStoreError, SessionStoreInconsistent, SessionSweepPage, StrongMessageSessionStore, advanceError, advanceSession, applySqlSessionSchema, asStrongStore, checkSessionMutable, encodeInteractionId, isActive, isStrongStore, makeSessionId, migrateSqlSessionStore, nowMillis, parseInteractionId, sessionAlreadyExists, sessionClosed, sessionConflict, sessionExpired, sessionLeaseLost, sessionNotFound, sessionPageLimit, sqlSessionStore, storeError };
|
|
1165
|
+
}
|
|
1166
|
+
/** A per-process store, useful for tests and a single gateway. */
|
|
1167
|
+
declare const MemoryStore: {
|
|
1168
|
+
readonly layer: (options?: {
|
|
1169
|
+
readonly clock?: (() => number) | undefined;
|
|
1170
|
+
}) => Layer.Layer<MessageSessionStore>;
|
|
1171
|
+
/** A memory store with an injected clock, for deterministic tests. */
|
|
1172
|
+
readonly make: (clock?: () => number) => Effect.Effect<StrongMessageSessionStore>;
|
|
1173
|
+
};
|
|
1174
|
+
/** A directory of JSON session files. */
|
|
1175
|
+
declare const FileStore: {
|
|
1176
|
+
readonly layer: (directory: string, options?: {
|
|
1177
|
+
readonly clock?: (() => number) | undefined;
|
|
1178
|
+
}) => Layer.Layer<MessageSessionStore, SessionStoreError, FileSystem$1 | Path$1>;
|
|
1179
|
+
/** A file store with an injected clock, for deterministic tests. */
|
|
1180
|
+
readonly make: (directory: string, clock?: () => number) => Effect.Effect<StrongMessageSessionStore, SessionStoreError, FileSystem$1 | Path$1>;
|
|
1181
|
+
};
|
|
1182
|
+
export { GONE as $, SessionMessageRef as A, leaseOwnerAt as At, encodeInteractionId as B, sessionStateAt as Bt, MessageSessionStoreShape as C, deriveMachineTable as Ct, SessionErrorCode as D, isTerminal as Dt, SessionConflict as E, isExpired as Et, SessionStoreError as F, rootModeModel as Ft, sessionAlreadyExists as G, transition as Gt, makeSessionId as H, targetModeMachine as Ht, SessionStoreInconsistent as I, rootModel as It, sessionExpired as J, sessionClosed as K, transitionOrThrow as Kt, SessionSweepPage as L, sessionAllows as Lt, SessionPage as M, reachableStates as Mt, SessionPageOptions as N, rootMachine as Nt, SessionExpired as O, leaseMachine as Ot, SessionRepair as P, rootModeMachine as Pt, storeError as Q, StrongMessageSessionStore as R, sessionMachine as Rt, MessageSessionStore as S, canTransition as St, SessionClosed as T, interactionModel as Tt, nowMillis as U, targetModeModel as Ut, isStrongStore as V, targetMachine as Vt, parseInteractionId as W, targetModel as Wt, sessionNotFound as X, sessionLeaseLost as Y, sessionPageLimit as Z, MAX_INTERACTION_ID_LENGTH as _, StateMachineTable as _t, migrateSqlSessionStore as a, Lease as at, MessageSessionSchema as b, TargetModeEvent as bt, SessionMutation as c, LeaseState as ct, checkSessionMutable as d, RootEvent as dt, Gone as et, isActive as f, RootMode as ft, InteractionIdParts as g, SessionStatus as gt, INTERACTION_ID_PREFIX as h, SessionEvent as ht, applySqlSessionSchema as i, LEASE_FREE as it, SessionNotFound as j, leaseTransition as jt, SessionLeaseLost as k, leaseModel as kt, advanceError as l, LeaseStatus as lt, DEFAULT_SESSION_PAGE_LIMIT as m, RootState as mt, MemoryStore as n, InteractionEvent as nt, sqlSessionStore as o, LeaseEvent as ot, Consistency as p, RootModeEvent as pt, sessionConflict as q, index_d_exports as r, InteractionState as rt, SessionAdvance as s, LeaseEventName as st, FileStore as t, IllegalTransitionError as tt, advanceSession as u, LeaseTransition as ut, MAX_SESSION_PAGE_LIMIT as v, TargetEvent as vt, SessionAlreadyExists as w, interactionMachine as wt, MessageSessionState as x, TargetState as xt, MessageSession as y, TargetMode as yt, asStrongStore as z, sessionModel as zt };
|