@arki/journal 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/LICENSE +21 -0
- package/README.md +541 -2
- package/dist/api.d.ts +336 -0
- package/dist/api.d.ts.map +1 -0
- package/dist/api.js +2 -0
- package/dist/api.js.map +1 -0
- package/dist/command.d.ts +27 -0
- package/dist/command.d.ts.map +1 -0
- package/dist/command.js +157 -0
- package/dist/command.js.map +1 -0
- package/dist/debug.d.ts +7 -0
- package/dist/debug.d.ts.map +1 -0
- package/dist/debug.js +8 -0
- package/dist/debug.js.map +1 -0
- package/dist/dot.d.ts +102 -0
- package/dist/dot.d.ts.map +1 -0
- package/dist/dot.js +159 -0
- package/dist/dot.js.map +1 -0
- package/dist/entity.d.ts +56 -0
- package/dist/entity.d.ts.map +1 -0
- package/dist/entity.js +174 -0
- package/dist/entity.js.map +1 -0
- package/dist/errors.d.ts +47 -0
- package/dist/errors.d.ts.map +1 -0
- package/dist/errors.js +112 -0
- package/dist/errors.js.map +1 -0
- package/dist/event.d.ts +9 -0
- package/dist/event.d.ts.map +1 -0
- package/dist/event.js +19 -0
- package/dist/event.js.map +1 -0
- package/dist/fold.d.ts +29 -0
- package/dist/fold.d.ts.map +1 -0
- package/dist/fold.js +49 -0
- package/dist/fold.js.map +1 -0
- package/dist/handlers.d.ts +26 -0
- package/dist/handlers.d.ts.map +1 -0
- package/dist/handlers.js +130 -0
- package/dist/handlers.js.map +1 -0
- package/dist/history.d.ts +49 -0
- package/dist/history.d.ts.map +1 -0
- package/dist/history.js +259 -0
- package/dist/history.js.map +1 -0
- package/dist/hooks.d.ts +14 -0
- package/dist/hooks.d.ts.map +1 -0
- package/dist/hooks.js +67 -0
- package/dist/hooks.js.map +1 -0
- package/dist/id.d.ts +18 -0
- package/dist/id.d.ts.map +1 -0
- package/dist/id.js +41 -0
- package/dist/id.js.map +1 -0
- package/dist/index.d.ts +12 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +5 -0
- package/dist/index.js.map +1 -0
- package/dist/journal.d.ts +51 -0
- package/dist/journal.d.ts.map +1 -0
- package/dist/journal.js +181 -0
- package/dist/journal.js.map +1 -0
- package/dist/listen.d.ts +37 -0
- package/dist/listen.d.ts.map +1 -0
- package/dist/listen.js +90 -0
- package/dist/listen.js.map +1 -0
- package/dist/orpc.d.ts +21 -0
- package/dist/orpc.d.ts.map +1 -0
- package/dist/orpc.js +57 -0
- package/dist/orpc.js.map +1 -0
- package/dist/pg.d.ts +537 -0
- package/dist/pg.d.ts.map +1 -0
- package/dist/pg.js +80 -0
- package/dist/pg.js.map +1 -0
- package/dist/storage.d.ts +52 -0
- package/dist/storage.d.ts.map +1 -0
- package/dist/storage.js +221 -0
- package/dist/storage.js.map +1 -0
- package/dist/testing.d.ts +19 -0
- package/dist/testing.d.ts.map +1 -0
- package/dist/testing.js +23 -0
- package/dist/testing.js.map +1 -0
- package/dist/transaction-guard.d.ts +2 -0
- package/dist/transaction-guard.d.ts.map +1 -0
- package/dist/transaction-guard.js +39 -0
- package/dist/transaction-guard.js.map +1 -0
- package/dist/types.d.ts +414 -0
- package/dist/types.d.ts.map +1 -0
- package/dist/types.js +2 -0
- package/dist/types.js.map +1 -0
- package/dist/worker.d.ts +109 -0
- package/dist/worker.d.ts.map +1 -0
- package/dist/worker.js +459 -0
- package/dist/worker.js.map +1 -0
- package/dist/write.d.ts +39 -0
- package/dist/write.d.ts.map +1 -0
- package/dist/write.js +287 -0
- package/dist/write.js.map +1 -0
- package/docs/agent-guide.md +324 -0
- package/llms.txt +40 -0
- package/package.json +99 -4
- package/src/api.ts +465 -0
- package/src/command.ts +242 -0
- package/src/debug.ts +8 -0
- package/src/dot.ts +296 -0
- package/src/entity.ts +377 -0
- package/src/errors.ts +134 -0
- package/src/event.ts +26 -0
- package/src/fold.ts +97 -0
- package/src/handlers.ts +262 -0
- package/src/history.ts +390 -0
- package/src/hooks.ts +85 -0
- package/src/id.ts +54 -0
- package/src/index.ts +76 -0
- package/src/journal.ts +256 -0
- package/src/listen.ts +109 -0
- package/src/orpc.ts +59 -0
- package/src/pg.ts +107 -0
- package/src/storage.ts +277 -0
- package/src/test-support.ts +82 -0
- package/src/testing.ts +23 -0
- package/src/transaction-guard.ts +41 -0
- package/src/types.ts +439 -0
- package/src/worker.ts +610 -0
- package/src/write.ts +434 -0
package/dist/types.d.ts
ADDED
|
@@ -0,0 +1,414 @@
|
|
|
1
|
+
import type { AnyRelations } from 'drizzle-orm';
|
|
2
|
+
import type { AnyPgColumn, PgAsyncDatabase, PgQueryResultHKT, PgTableWithColumns } from 'drizzle-orm/pg-core';
|
|
3
|
+
import type { z } from 'zod';
|
|
4
|
+
/**
|
|
5
|
+
* A function type whose parameters are checked bivariantly.
|
|
6
|
+
*
|
|
7
|
+
* TypeScript only relaxes parameter variance for method signatures. Reading
|
|
8
|
+
* the method back out of an object type keeps that relaxation on a plain
|
|
9
|
+
* function type. This is how a registry can hold handlers written for one
|
|
10
|
+
* event type under a common `Recorded` parameter without a cast.
|
|
11
|
+
*/
|
|
12
|
+
export type BivariantFn<Args extends unknown[], R> = {
|
|
13
|
+
bivarianceHack(...args: Args): R;
|
|
14
|
+
}['bivarianceHack'];
|
|
15
|
+
type AnyDb = PgAsyncDatabase<PgQueryResultHKT, AnyRelations>;
|
|
16
|
+
/** A key's longest id, and whether the key column or the journal's own `entity_id` column sets it. */
|
|
17
|
+
export type KeyLimit = {
|
|
18
|
+
readonly max: number;
|
|
19
|
+
readonly source: 'column' | 'journal';
|
|
20
|
+
};
|
|
21
|
+
/**
|
|
22
|
+
* The Drizzle surface the journal needs. Structural: a Drizzle database and a
|
|
23
|
+
* Drizzle transaction both fit. The journal never touches `db.query`, so the
|
|
24
|
+
* app's relations do not matter here.
|
|
25
|
+
*/
|
|
26
|
+
export type DbHandle = {
|
|
27
|
+
readonly select: AnyDb['select'];
|
|
28
|
+
readonly insert: AnyDb['insert'];
|
|
29
|
+
readonly update: AnyDb['update'];
|
|
30
|
+
readonly delete: AnyDb['delete'];
|
|
31
|
+
readonly execute: AnyDb['execute'];
|
|
32
|
+
transaction<T>(run: (tx: DbHandle) => Promise<T>): Promise<T>;
|
|
33
|
+
};
|
|
34
|
+
/**
|
|
35
|
+
* The root database only. A Drizzle transaction has `rollback()`, so it does
|
|
36
|
+
* not fit. `drain` and `worker` need this: inside a transaction their claim
|
|
37
|
+
* would be a savepoint and handlers would run before the outer commit.
|
|
38
|
+
*/
|
|
39
|
+
export type RootDb = DbHandle & {
|
|
40
|
+
readonly rollback?: undefined;
|
|
41
|
+
};
|
|
42
|
+
/**
|
|
43
|
+
* A database or transaction whose nested transactions have type `Tx`. The
|
|
44
|
+
* app's Drizzle transaction type fits `TransactionSource<itself>`: a savepoint has
|
|
45
|
+
* the same type as its parent. The root database fits `TransactionSource<AppTx>`.
|
|
46
|
+
* `DbHandle` fits `TransactionSource<DbHandle>`, which is the default everywhere.
|
|
47
|
+
*/
|
|
48
|
+
export type TransactionSource<Tx> = {
|
|
49
|
+
transaction<T>(run: (tx: Tx) => Promise<T>): Promise<T>;
|
|
50
|
+
} & DbHandle;
|
|
51
|
+
/** A column that can hold an entity's key: a non-null string column. */
|
|
52
|
+
export type KeyColumn = AnyPgColumn<{
|
|
53
|
+
data: string;
|
|
54
|
+
notNull: true;
|
|
55
|
+
}>;
|
|
56
|
+
export type VersionColumn = AnyPgColumn<{
|
|
57
|
+
data: number;
|
|
58
|
+
notNull: true;
|
|
59
|
+
}>;
|
|
60
|
+
/**
|
|
61
|
+
* A Drizzle table qualifies as an entity table when it has an integer
|
|
62
|
+
* `version` and a string key column. The key column is `id` unless the entity
|
|
63
|
+
* names another one. Every other column is the app's business.
|
|
64
|
+
*/
|
|
65
|
+
export type EntityTable = PgTableWithColumns<{
|
|
66
|
+
name: string;
|
|
67
|
+
schema: string | undefined;
|
|
68
|
+
dialect: 'pg';
|
|
69
|
+
columns: {
|
|
70
|
+
version: VersionColumn;
|
|
71
|
+
};
|
|
72
|
+
}>;
|
|
73
|
+
/** An entity table whose key column is called `id`. The default for `j.entity(kind, table)`. */
|
|
74
|
+
export type IdTable = PgTableWithColumns<{
|
|
75
|
+
name: string;
|
|
76
|
+
schema: string | undefined;
|
|
77
|
+
dialect: 'pg';
|
|
78
|
+
columns: {
|
|
79
|
+
id: KeyColumn;
|
|
80
|
+
version: VersionColumn;
|
|
81
|
+
};
|
|
82
|
+
}>;
|
|
83
|
+
/** The property names of the columns of `Tbl` that can hold the key: non-null string columns. */
|
|
84
|
+
export type KeyName<Tbl extends EntityTable> = string & {
|
|
85
|
+
[K in keyof Tbl['_']['columns']]: Tbl['_']['columns'][K] extends KeyColumn ? K : never;
|
|
86
|
+
}[keyof Tbl['_']['columns']];
|
|
87
|
+
/** `true` when `T` is a union of two or more members. */
|
|
88
|
+
type IsUnion<T, U = T> = T extends unknown ? ([U] extends [T] ? false : true) : never;
|
|
89
|
+
/**
|
|
90
|
+
* `Key` when it is one property name, `never` for a union. A union key would make
|
|
91
|
+
* `ReducerValues` omit every member, so a reducer could leave required columns unset.
|
|
92
|
+
*/
|
|
93
|
+
export type SingleKey<Key extends string> = IsUnion<Key> extends true ? never : Key;
|
|
94
|
+
/** The current state of one entity. A plain Drizzle select row. */
|
|
95
|
+
export type Row<Tbl extends EntityTable> = Tbl['$inferSelect'];
|
|
96
|
+
/** What reducers return. The library sets the key column and `version`. */
|
|
97
|
+
export type ReducerValues<Tbl extends EntityTable, Key extends string = 'id'> = Omit<Tbl['$inferInsert'], Key | 'version'>;
|
|
98
|
+
/** The key type of an entity table, as the key column declares it. */
|
|
99
|
+
export type EntityId<Tbl extends EntityTable, Key extends string = 'id'> = Extract<Row<Tbl>[Key & keyof Row<Tbl>], string>;
|
|
100
|
+
/**
|
|
101
|
+
* A row rebuilt in memory from events: a reducer result plus the key column
|
|
102
|
+
* and `version`. Columns a reducer leaves out are absent here even when the
|
|
103
|
+
* database would fill them with a default.
|
|
104
|
+
*/
|
|
105
|
+
export type ReducerRow<Tbl extends EntityTable, Key extends string = 'id'> = ReducerValues<Tbl, Key> & Readonly<Record<Key, EntityId<Tbl, Key>>> & {
|
|
106
|
+
readonly version: number;
|
|
107
|
+
};
|
|
108
|
+
/** A validated event that has not been written yet. */
|
|
109
|
+
export type Pending<T extends string = string, Data = unknown> = {
|
|
110
|
+
readonly type: T;
|
|
111
|
+
readonly data: Data;
|
|
112
|
+
};
|
|
113
|
+
/** What the log adds to a pending event when it is written. `Id` is the entity's key type. */
|
|
114
|
+
export type RecordedStamp<Meta = unknown, Id extends string = string> = {
|
|
115
|
+
readonly seq: number;
|
|
116
|
+
readonly id: string;
|
|
117
|
+
readonly kind: string;
|
|
118
|
+
readonly entityId: Id;
|
|
119
|
+
readonly version: number;
|
|
120
|
+
readonly meta: Meta;
|
|
121
|
+
readonly recordedAt: Date;
|
|
122
|
+
/** The `cmd_` id of the command run that wrote it. Null for a bare `journal.write`, and on rows older than the column. */
|
|
123
|
+
readonly commandId: string | null;
|
|
124
|
+
/** The seq of the event whose effect ran the command that wrote it. Null outside an effect, and on rows older than the column. */
|
|
125
|
+
readonly causeSeq: number | null;
|
|
126
|
+
/** Shared by every event of one chain. Null only on rows older than the column. */
|
|
127
|
+
readonly correlationId: string | null;
|
|
128
|
+
/** When `forget` rewrote `data` to the event's erased form. Null if it never did. */
|
|
129
|
+
readonly erasedAt: Date | null;
|
|
130
|
+
};
|
|
131
|
+
/**
|
|
132
|
+
* Where a write comes from. The library fills it: a command run stamps its own id, an
|
|
133
|
+
* effect's `ctx.run` passes the event it is for, a root `run` may be seeded with a
|
|
134
|
+
* correlation id from the request. A bare `journal.write` has no command and no cause.
|
|
135
|
+
*/
|
|
136
|
+
export type Trace = {
|
|
137
|
+
readonly commandId: string | null;
|
|
138
|
+
readonly causeSeq: number | null;
|
|
139
|
+
readonly correlationId: string;
|
|
140
|
+
};
|
|
141
|
+
/** What reducers and handlers receive: the event as stored in the log. */
|
|
142
|
+
export type Recorded<T extends string = string, Data = unknown, Meta = unknown, Id extends string = string> = Pending<T, Data> & RecordedStamp<Meta, Id>;
|
|
143
|
+
/**
|
|
144
|
+
* An event definition. Calling it validates the data and returns a pending
|
|
145
|
+
* event. `type` and `schema` are read by the entity builder and by replay.
|
|
146
|
+
*/
|
|
147
|
+
export type EventDef<T extends string, S extends z.ZodType> = BivariantFn<[
|
|
148
|
+
data: z.input<S>
|
|
149
|
+
], Pending<T, z.output<S>>> & {
|
|
150
|
+
readonly type: T;
|
|
151
|
+
readonly schema: S;
|
|
152
|
+
/**
|
|
153
|
+
* The event's erased form, for `forget`: the same data with the personal parts
|
|
154
|
+
* removed. It must still fit `schema`. Absent on an event that holds no personal data.
|
|
155
|
+
* A method signature, so every `EventDef` is an `AnyEventDef`; see `BivariantFn`.
|
|
156
|
+
*/
|
|
157
|
+
erased?(data: z.output<S>): z.input<S>;
|
|
158
|
+
/**
|
|
159
|
+
* The schema version new events are stored at: one more than the number of upcasters.
|
|
160
|
+
* Rows record it in `schema_version`; a row at an older version is upcast on read.
|
|
161
|
+
*/
|
|
162
|
+
readonly version: number;
|
|
163
|
+
/** Lifts stored data one version up. `upcasters[0]` takes version 1 to 2. Empty for most events. */
|
|
164
|
+
readonly upcasters: readonly Upcaster[];
|
|
165
|
+
};
|
|
166
|
+
/**
|
|
167
|
+
* One step of an event's history: the schema its data had at one version, and how to
|
|
168
|
+
* lift that data to the next. Replay parses with `from` first, so `up` sees valid old data.
|
|
169
|
+
* `up` is a method signature, so a typed step is an `Upcaster`; see `BivariantFn`.
|
|
170
|
+
*/
|
|
171
|
+
export type Upcaster = {
|
|
172
|
+
readonly from: z.ZodType;
|
|
173
|
+
up(data: unknown): unknown;
|
|
174
|
+
};
|
|
175
|
+
/** Typed upcaster steps: each `up` receives the output of its own `from`. */
|
|
176
|
+
export type UpcasterSteps<U extends readonly z.ZodType[]> = {
|
|
177
|
+
readonly [K in keyof U]: {
|
|
178
|
+
readonly from: U[K];
|
|
179
|
+
readonly up: (data: z.output<U[K]>) => unknown;
|
|
180
|
+
};
|
|
181
|
+
};
|
|
182
|
+
/** The third argument of `j.event`. */
|
|
183
|
+
export type EventOptions<S extends z.ZodType, U extends readonly z.ZodType[] = readonly []> = {
|
|
184
|
+
/** See `EventDef.erased`. */
|
|
185
|
+
readonly erased?: (data: z.output<S>) => z.input<S>;
|
|
186
|
+
/**
|
|
187
|
+
* Older shapes of this event, oldest first: `{ from: schemaV1, up: v1 => v2 }`, then
|
|
188
|
+
* `{ from: schemaV2, up: v2 => v3 }`. The last step's result must fit the current schema.
|
|
189
|
+
* Append a step when the event's data changes incompatibly; never edit or remove one.
|
|
190
|
+
*/
|
|
191
|
+
readonly upcasters?: UpcasterSteps<U>;
|
|
192
|
+
};
|
|
193
|
+
export type AnyEventDef = EventDef<string, z.ZodType>;
|
|
194
|
+
/** The pending form of one or more event definitions. Distributes over unions. */
|
|
195
|
+
export type PendingOf<D> = D extends AnyEventDef ? Pending<D['type'], z.output<D['schema']>> : never;
|
|
196
|
+
/** The recorded form of one or more event definitions. */
|
|
197
|
+
export type RecordedOf<D, Meta, Id extends string = string> = PendingOf<D> & RecordedStamp<Meta, Id>;
|
|
198
|
+
/**
|
|
199
|
+
* What an `.on` reducer returns: the columns that changed. `null` deletes the
|
|
200
|
+
* row. A key set to `undefined` means "unchanged".
|
|
201
|
+
*/
|
|
202
|
+
export type Patch<Tbl extends EntityTable, Key extends string = 'id'> = Partial<ReducerValues<Tbl, Key>>;
|
|
203
|
+
/** A create reducer receives no row. It builds the first row from the event. */
|
|
204
|
+
export type CreateReducer<Tbl extends EntityTable, Meta, Key extends string = 'id'> = BivariantFn<[
|
|
205
|
+
event: Recorded<string, unknown, Meta>
|
|
206
|
+
], ReducerValues<Tbl, Key>>;
|
|
207
|
+
/**
|
|
208
|
+
* An `.on` reducer may receive a row loaded from the table or a row rebuilt in
|
|
209
|
+
* memory by an earlier reducer in the same write or replay. Both are
|
|
210
|
+
* `ReducerRow` at runtime; the union is here because TypeScript cannot relate a
|
|
211
|
+
* generic select row to the insert shape.
|
|
212
|
+
*/
|
|
213
|
+
export type OnReducer<Tbl extends EntityTable, Meta, Key extends string = 'id'> = BivariantFn<[
|
|
214
|
+
row: Row<Tbl> | ReducerRow<Tbl, Key>,
|
|
215
|
+
event: Recorded<string, unknown, Meta>
|
|
216
|
+
], Patch<Tbl, Key> | null>;
|
|
217
|
+
/** The reducers declared for one event type. Both may be set: the fold picks by state. */
|
|
218
|
+
export type Reducers<Tbl extends EntityTable, Meta, Key extends string = 'id'> = {
|
|
219
|
+
readonly create?: CreateReducer<Tbl, Meta, Key>;
|
|
220
|
+
readonly on?: OnReducer<Tbl, Meta, Key>;
|
|
221
|
+
};
|
|
222
|
+
/** An entity: a kind, its table and key column, and the events and reducers declared so far. */
|
|
223
|
+
export type EntityDef<K extends string, Tbl extends EntityTable, E extends AnyEventDef, Meta, Key extends string = 'id'> = {
|
|
224
|
+
readonly kind: K;
|
|
225
|
+
readonly table: Tbl;
|
|
226
|
+
/** The property name of the key column on the table and its rows. */
|
|
227
|
+
readonly key: Key;
|
|
228
|
+
/** The key column. Lock-and-load, update and delete filter on it. */
|
|
229
|
+
readonly keyColumn: KeyColumn;
|
|
230
|
+
/** Whether the key column is a `uuid`, decided once when the entity is defined. Such ids must be canonical. */
|
|
231
|
+
readonly uuidKey: boolean;
|
|
232
|
+
/** The longest id the key holds, in code points, decided once when the entity is defined. */
|
|
233
|
+
readonly keyLimit: KeyLimit;
|
|
234
|
+
readonly events: ReadonlyMap<string, AnyEventDef>;
|
|
235
|
+
readonly reducers: ReadonlyMap<string, Reducers<Tbl, Meta, Key>>;
|
|
236
|
+
/** Phantom: the union of event definitions this entity accepts. Never set at runtime. */
|
|
237
|
+
readonly $events?: E;
|
|
238
|
+
};
|
|
239
|
+
export type AnyEntity<Meta = unknown> = EntityDef<string, EntityTable, AnyEventDef, Meta, string>;
|
|
240
|
+
/** The event definitions an entity accepts, read from its phantom `$events`. */
|
|
241
|
+
export type EventsOf<E> = E extends {
|
|
242
|
+
readonly $events?: infer D;
|
|
243
|
+
} ? Extract<NonNullable<D>, AnyEventDef> : never;
|
|
244
|
+
/** The key type of one or more entities, read from their table and key. */
|
|
245
|
+
export type EntityIdOf<E> = E extends {
|
|
246
|
+
readonly table: infer Tbl extends EntityTable;
|
|
247
|
+
readonly key: infer Key extends string;
|
|
248
|
+
} ? EntityId<Tbl, Key> : never;
|
|
249
|
+
/** Keys are event types; each handler sees the event typed for that key. */
|
|
250
|
+
export type ProjectionHandlers<E, Meta, Tx = DbHandle> = {
|
|
251
|
+
readonly [D in EventsOf<E> as D['type']]?: BivariantFn<[tx: Tx, event: RecordedOf<D, Meta, EntityIdOf<E>>], unknown>;
|
|
252
|
+
};
|
|
253
|
+
/** An effect handler also gets one value for each of the effect's needs `N`, under the need's name. */
|
|
254
|
+
export type EffectHandlers<E, Meta, AppDb = RootDb, Run = unknown, N extends Needs = NoNeeds> = {
|
|
255
|
+
readonly [D in EventsOf<E> as D['type']]?: BivariantFn<[
|
|
256
|
+
event: RecordedOf<D, Meta, EntityIdOf<E>>,
|
|
257
|
+
ctx: EffectContext<AppDb, Run> & Needed<N>
|
|
258
|
+
], unknown>;
|
|
259
|
+
};
|
|
260
|
+
/** Inline handler. Runs inside the write's transaction. */
|
|
261
|
+
export type Projection<Meta = unknown, Tx = DbHandle> = {
|
|
262
|
+
readonly name: string;
|
|
263
|
+
readonly entities: readonly AnyEntity<Meta>[];
|
|
264
|
+
readonly types: ReadonlySet<string>;
|
|
265
|
+
/**
|
|
266
|
+
* `inline`: runs inside the write's transaction, so the read model is exact. `async`: the
|
|
267
|
+
* worker applies it later, in batches, with a cursor in `journal_cursors` committed in the
|
|
268
|
+
* same transaction as the handlers; exactly once for database writes, eventually consistent.
|
|
269
|
+
*/
|
|
270
|
+
readonly lane: 'inline' | 'async';
|
|
271
|
+
readonly run: BivariantFn<[tx: Tx, event: Recorded<string, unknown, Meta>], Promise<void>>;
|
|
272
|
+
};
|
|
273
|
+
/** The fourth argument of `j.projection`. */
|
|
274
|
+
export type ProjectionOptions = {
|
|
275
|
+
readonly lane?: 'inline' | 'async';
|
|
276
|
+
};
|
|
277
|
+
/**
|
|
278
|
+
* `db` is the root database that was given to `drain` or `worker`: the same object.
|
|
279
|
+
* `run` is `journal.run` on that database. A journal types it as `RootCommandRunner`
|
|
280
|
+
* (in `api.ts`). This file cannot name a command, so the type comes in as `Run`.
|
|
281
|
+
*/
|
|
282
|
+
export type EffectContext<AppDb = RootDb, Run = unknown> = {
|
|
283
|
+
readonly jobId: string;
|
|
284
|
+
readonly signal: AbortSignal;
|
|
285
|
+
readonly db: AppDb;
|
|
286
|
+
readonly run: Run;
|
|
287
|
+
};
|
|
288
|
+
declare const needType: unique symbol;
|
|
289
|
+
/**
|
|
290
|
+
* A marker for one thing an effect needs, such as a mailer. `need<Mailer>()` makes one.
|
|
291
|
+
* It holds the type only. The real value comes later: from `services` in `j.compose`,
|
|
292
|
+
* or from the services of the Dot feature that lists the effect.
|
|
293
|
+
*/
|
|
294
|
+
export type Need<T> = {
|
|
295
|
+
readonly [needType]?: T;
|
|
296
|
+
};
|
|
297
|
+
/** The needs of one effect, by the name its handlers read them under. */
|
|
298
|
+
export type Needs = Readonly<Record<string, Need<unknown>>>;
|
|
299
|
+
export type NoNeeds = Readonly<Record<never, Need<unknown>>>;
|
|
300
|
+
/** What the handlers get for the needs `N`: one value per name. */
|
|
301
|
+
export type Needed<N extends Needs> = {
|
|
302
|
+
readonly [K in keyof N]: N[K] extends Need<infer T> ? T : never;
|
|
303
|
+
};
|
|
304
|
+
/** Real services by name, as an app or a Dot feature hands them over. */
|
|
305
|
+
export type Services = Readonly<Record<string, unknown>>;
|
|
306
|
+
type UnionToIntersection<U> = (U extends unknown ? (member: U) => void : never) extends (all: infer I) => void ? I : never;
|
|
307
|
+
/** The needs of each effect in a union. An effect that needs nothing adds nothing. */
|
|
308
|
+
type DeclaredNeeds<E> = E extends {
|
|
309
|
+
readonly needs: infer N extends Needs;
|
|
310
|
+
} ? keyof N extends never ? never : N : never;
|
|
311
|
+
/**
|
|
312
|
+
* Every need of every effect in a list, as one object of services. Two effects that
|
|
313
|
+
* use the same name get the same service. `unknown` when no effect needs anything.
|
|
314
|
+
*/
|
|
315
|
+
export type ServicesFor<E extends readonly {
|
|
316
|
+
readonly needs: Needs;
|
|
317
|
+
}[]> = UnionToIntersection<Needed<DeclaredNeeds<E[number]>>>;
|
|
318
|
+
/** Async handler. Runs after commit, at least once. */
|
|
319
|
+
/**
|
|
320
|
+
* When an effect's jobs run. `priority`: higher first among due jobs; strict, so a
|
|
321
|
+
* steady stream of high-priority jobs can starve lower ones. `delaySeconds`: due that
|
|
322
|
+
* long after the write's transaction started (`now()` in Postgres). `runAt`: due at the
|
|
323
|
+
* time the event names, from the app's clock. Retries keep their backoff and priority.
|
|
324
|
+
*/
|
|
325
|
+
export type EffectSchedule<Meta = unknown> = {
|
|
326
|
+
readonly priority?: number;
|
|
327
|
+
readonly delaySeconds?: number;
|
|
328
|
+
/** A method signature, so an effect of one meta type is still an `Effect<unknown>`; see `BivariantFn`. */
|
|
329
|
+
runAt?(event: Recorded<string, unknown, Meta>): Date;
|
|
330
|
+
};
|
|
331
|
+
export type Effect<Meta = unknown, AppDb = RootDb, Run = unknown, N extends Needs = NoNeeds> = {
|
|
332
|
+
readonly name: string;
|
|
333
|
+
readonly entities: readonly AnyEntity<Meta>[];
|
|
334
|
+
readonly types: ReadonlySet<string>;
|
|
335
|
+
/** What the handlers need on top of `EffectContext`. Empty for an effect that already has its services. */
|
|
336
|
+
readonly needs: N;
|
|
337
|
+
readonly schedule: EffectSchedule<Meta>;
|
|
338
|
+
/** The same effect with this schedule. `j.effect('mail', order, handlers).withSchedule({ priority: 5 })`. */
|
|
339
|
+
withSchedule(schedule: EffectSchedule<Meta>): Effect<Meta, AppDb, Run, N>;
|
|
340
|
+
readonly run: BivariantFn<[
|
|
341
|
+
event: Recorded<string, unknown, Meta>,
|
|
342
|
+
ctx: EffectContext<AppDb, Run> & Needed<N>
|
|
343
|
+
], Promise<void>>;
|
|
344
|
+
};
|
|
345
|
+
export type EntityInfo = {
|
|
346
|
+
readonly kind: string;
|
|
347
|
+
readonly table: string;
|
|
348
|
+
readonly events: readonly string[];
|
|
349
|
+
};
|
|
350
|
+
/** What a tap handler gets: the root database, plus its needs. No `run`: a tap may not issue commands. */
|
|
351
|
+
export type TapContext<AppDb = RootDb> = {
|
|
352
|
+
readonly db: AppDb;
|
|
353
|
+
};
|
|
354
|
+
export type TapHandlers<E, Meta, AppDb = RootDb, N extends Needs = NoNeeds> = {
|
|
355
|
+
readonly [D in EventsOf<E> as D['type']]?: BivariantFn<[
|
|
356
|
+
event: RecordedOf<D, Meta, EntityIdOf<E>>,
|
|
357
|
+
ctx: TapContext<AppDb> & Needed<N>
|
|
358
|
+
], unknown>;
|
|
359
|
+
};
|
|
360
|
+
/**
|
|
361
|
+
* A tap: in-process, after commit, lossy. No job row, no retry, no ordering promise across
|
|
362
|
+
* entities. It fires in every process whose worker listens on the wake channel, from the
|
|
363
|
+
* seq range the commit announced. For a live page, a cache, a metric. Never for work that
|
|
364
|
+
* must happen: that is an effect.
|
|
365
|
+
*/
|
|
366
|
+
export type Tap<Meta = unknown, AppDb = RootDb, N extends Needs = NoNeeds> = {
|
|
367
|
+
readonly name: string;
|
|
368
|
+
readonly entities: readonly AnyEntity<Meta>[];
|
|
369
|
+
readonly types: ReadonlySet<string>;
|
|
370
|
+
readonly needs: N;
|
|
371
|
+
readonly run: BivariantFn<[
|
|
372
|
+
event: Recorded<string, unknown, Meta>,
|
|
373
|
+
ctx: TapContext<AppDb> & Needed<N>
|
|
374
|
+
], Promise<void>>;
|
|
375
|
+
};
|
|
376
|
+
/** Stops listening. May be async. */
|
|
377
|
+
export type Unlisten = () => void | Promise<void>;
|
|
378
|
+
/**
|
|
379
|
+
* How a worker hears the wake channel. The app wires its own client: for `pg`, a dedicated
|
|
380
|
+
* client that runs `LISTEN <channel>` and calls `onMessage(payload)` on each notification; for
|
|
381
|
+
* PGlite, `client.listen(channel, onMessage)`. Start it before `worker.start()` resolves work
|
|
382
|
+
* you care about: `LISTEN` only hears what is sent after it ran, and the worker still polls.
|
|
383
|
+
*/
|
|
384
|
+
export type WakeListener = (onMessage: (payload: string) => void) => Unlisten | Promise<Unlisten>;
|
|
385
|
+
/** `wake()` runs a drain pass now instead of at the next poll. It does nothing unless the worker is running. */
|
|
386
|
+
export type JournalWorker = {
|
|
387
|
+
start(): Promise<void>;
|
|
388
|
+
stop(): Promise<void>;
|
|
389
|
+
wake(): void;
|
|
390
|
+
};
|
|
391
|
+
/** What a command hook sees. Frozen. `input` is the parsed input; a hook may read it, not change it. */
|
|
392
|
+
export type CommandHookContext<MetaOut = unknown> = {
|
|
393
|
+
readonly name: string;
|
|
394
|
+
readonly input: unknown;
|
|
395
|
+
readonly meta: MetaOut;
|
|
396
|
+
readonly commandId: string;
|
|
397
|
+
readonly correlationId: string;
|
|
398
|
+
/** The idempotency key of this call, or null. A hook sees a replayed call too: its handler does not run. */
|
|
399
|
+
readonly idempotencyKey: string | null;
|
|
400
|
+
};
|
|
401
|
+
/** What an effect hook sees. Frozen. `attempt` counts from 1. */
|
|
402
|
+
export type EffectHookContext<Meta = unknown> = {
|
|
403
|
+
readonly name: string;
|
|
404
|
+
readonly event: Recorded<string, unknown, Meta>;
|
|
405
|
+
readonly jobId: string;
|
|
406
|
+
readonly attempt: number;
|
|
407
|
+
};
|
|
408
|
+
/** Pending jobs for one effect name that the journal has no effect for. */
|
|
409
|
+
export type StrandedJobs = {
|
|
410
|
+
readonly effect: string;
|
|
411
|
+
readonly jobs: number;
|
|
412
|
+
};
|
|
413
|
+
export {};
|
|
414
|
+
//# sourceMappingURL=types.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,aAAa,CAAC;AAChD,OAAO,KAAK,EAAE,WAA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,CAAC;IAChD,QAAQ,CAAC,KAAK,EAAE,MAAM,CAAC;IACvB,QAAQ,CAAC,OAAO,EAAE,MAAM,CAAC;CAC1B,CAAC;AAEF,2EAA2E;AAC3E,MAAM,MAAM,YAAY,GAAG;IAAE,QAAQ,CAAC,MAAM,EAAE,MAAM,CAAC;IAAC,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAA;CAAE,CAAC"}
|
package/dist/types.js
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"types.js","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":""}
|
package/dist/worker.d.ts
ADDED
|
@@ -0,0 +1,109 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The async lane: job claims under a lease, the retry policy, `drain` (one batch),
|
|
3
|
+
* the worker loop around it, waking sleeping workers, and counting jobs no
|
|
4
|
+
* effect of this journal can claim.
|
|
5
|
+
* May import `fold`, `history`, `storage` and leaf files.
|
|
6
|
+
* Must not import `journal`, `api`, `write` or `command`.
|
|
7
|
+
*/
|
|
8
|
+
import type { z } from 'zod';
|
|
9
|
+
import type { History } from './history.js';
|
|
10
|
+
import type { HookPointInternal } from './hooks.js';
|
|
11
|
+
import type { JournalTables } from './pg.js';
|
|
12
|
+
import type { DbHandle, Effect, EffectHookContext, JournalWorker, Projection, RootDb, StrandedJobs, Tap, TransactionSource, WakeListener } from './types.js';
|
|
13
|
+
export type JobRow = JournalTables['jobs']['$inferSelect'];
|
|
14
|
+
/** What `drain` needs from the journal. `Run` is the type of an effect's `ctx.run`. */
|
|
15
|
+
export type DrainDeps<Meta extends z.ZodObject, AppDb extends RootDb, Run> = {
|
|
16
|
+
readonly tables: JournalTables;
|
|
17
|
+
/** The effect hooks. Frozen by the first drain. */
|
|
18
|
+
readonly hooks: HookPointInternal<EffectHookContext<z.output<Meta>>>;
|
|
19
|
+
readonly effects: readonly Effect<z.output<Meta>, AppDb, Run>[];
|
|
20
|
+
readonly history: Pick<History<Meta>, 'decodeStoredEvent'>;
|
|
21
|
+
/** Makes an effect's `ctx.run`: the journal's `run`, bound to the root database this drain was given and to the event the job is for. */
|
|
22
|
+
readonly runOn: (db: AppDb & RootDb, cause: {
|
|
23
|
+
readonly seq: number;
|
|
24
|
+
readonly correlationId: string | null;
|
|
25
|
+
}) => Run;
|
|
26
|
+
};
|
|
27
|
+
export declare function createDrain<Meta extends z.ZodObject, AppDb extends RootDb, Run>(deps: DrainDeps<Meta, AppDb, Run>): (db: AppDb & RootDb, opts?: {
|
|
28
|
+
readonly batchSize?: number;
|
|
29
|
+
readonly signal?: AbortSignal;
|
|
30
|
+
readonly leaseSeconds?: number;
|
|
31
|
+
}) => Promise<number>;
|
|
32
|
+
/**
|
|
33
|
+
* Counts pending jobs whose effect this journal does not have. `drain` never
|
|
34
|
+
* claims them, on purpose: during a rolling deploy an older worker may still
|
|
35
|
+
* have that effect. But once every worker runs the new code, a renamed or
|
|
36
|
+
* removed effect leaves its jobs here for good, so they must be visible.
|
|
37
|
+
*/
|
|
38
|
+
export declare function createStrandedJobs(deps: {
|
|
39
|
+
readonly tables: JournalTables;
|
|
40
|
+
readonly effectNames: readonly string[];
|
|
41
|
+
}): (db: DbHandle) => Promise<readonly StrandedJobs[]>;
|
|
42
|
+
/** The job verbs an operator uses: list, retry a dead job, discard a dead job. */
|
|
43
|
+
export declare function createAdmin(deps: {
|
|
44
|
+
readonly tables: JournalTables;
|
|
45
|
+
readonly wake: () => void;
|
|
46
|
+
}): {
|
|
47
|
+
jobs: (db: DbHandle, opts?: {
|
|
48
|
+
readonly status?: 'pending' | 'dead' | 'all';
|
|
49
|
+
readonly effect?: string;
|
|
50
|
+
readonly limit?: number;
|
|
51
|
+
}) => Promise<JobRow[]>;
|
|
52
|
+
retry: (db: DbHandle, jobId: string) => Promise<void>;
|
|
53
|
+
discard: (db: DbHandle, jobId: string) => Promise<void>;
|
|
54
|
+
};
|
|
55
|
+
/** What the worker loop needs from the journal. */
|
|
56
|
+
export type WorkerDeps<AppDb extends RootDb> = {
|
|
57
|
+
/** Runs one batch. The journal passes its own `drain` method, looked up on each call. */
|
|
58
|
+
readonly drain: (db: AppDb & RootDb, opts?: {
|
|
59
|
+
readonly batchSize?: number;
|
|
60
|
+
readonly signal?: AbortSignal;
|
|
61
|
+
readonly leaseSeconds?: number;
|
|
62
|
+
}) => Promise<number>;
|
|
63
|
+
/** One batch per async projection. Returns how many events were scanned. */
|
|
64
|
+
readonly catchUp: (db: AppDb & RootDb, opts?: {
|
|
65
|
+
readonly batchSize?: number;
|
|
66
|
+
}) => Promise<{
|
|
67
|
+
readonly scanned: number;
|
|
68
|
+
}>;
|
|
69
|
+
/** Fire the taps for one wake payload. */
|
|
70
|
+
readonly dispatch: (db: AppDb & RootDb, payload: string) => Promise<void>;
|
|
71
|
+
readonly tapNames: readonly string[];
|
|
72
|
+
};
|
|
73
|
+
/** What the async lane of projections needs from the journal. */
|
|
74
|
+
export type CatchUpDeps<Meta extends z.ZodObject, Tx extends TransactionSource<Tx>> = {
|
|
75
|
+
readonly tables: JournalTables;
|
|
76
|
+
readonly projections: readonly Projection<z.output<Meta>, Tx>[];
|
|
77
|
+
readonly history: Pick<History<Meta>, 'decodeStoredEvent'>;
|
|
78
|
+
};
|
|
79
|
+
export declare function createCatchUp<Meta extends z.ZodObject, Tx extends TransactionSource<Tx>>(deps: CatchUpDeps<Meta, Tx>): {
|
|
80
|
+
catchUp: (db: RootDb & TransactionSource<Tx>, opts?: {
|
|
81
|
+
readonly batchSize?: number;
|
|
82
|
+
}) => Promise<{
|
|
83
|
+
readonly scanned: number;
|
|
84
|
+
}>;
|
|
85
|
+
reset: (db: RootDb & TransactionSource<Tx>, projection: Projection<z.output<Meta>, Tx>, clear?: (tx: Tx) => Promise<void>) => Promise<void>;
|
|
86
|
+
cursors: (db: DbHandle) => Promise<readonly {
|
|
87
|
+
readonly name: string;
|
|
88
|
+
readonly seq: number;
|
|
89
|
+
readonly lag: number;
|
|
90
|
+
}[]>;
|
|
91
|
+
};
|
|
92
|
+
/** What tap dispatch needs from the journal. */
|
|
93
|
+
export type TapDispatchDeps<Meta extends z.ZodObject, AppDb extends RootDb> = {
|
|
94
|
+
readonly tables: Pick<JournalTables, 'events'>;
|
|
95
|
+
readonly taps: readonly Tap<z.output<Meta>, AppDb>[];
|
|
96
|
+
readonly history: Pick<History<Meta>, 'decodeStoredEvent'>;
|
|
97
|
+
};
|
|
98
|
+
export declare function createTapDispatch<Meta extends z.ZodObject, AppDb extends RootDb>(deps: TapDispatchDeps<Meta, AppDb>): (db: AppDb & RootDb, payload: string) => Promise<void>;
|
|
99
|
+
export declare function createWorkers<AppDb extends RootDb>(deps: WorkerDeps<AppDb>): {
|
|
100
|
+
worker: (db: AppDb & RootDb, opts?: {
|
|
101
|
+
readonly pollMs?: number;
|
|
102
|
+
readonly batchSize?: number;
|
|
103
|
+
readonly leaseSeconds?: number;
|
|
104
|
+
readonly listen?: WakeListener;
|
|
105
|
+
readonly taps?: boolean;
|
|
106
|
+
}) => JournalWorker;
|
|
107
|
+
wakeAll: () => void;
|
|
108
|
+
};
|
|
109
|
+
//# sourceMappingURL=worker.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"worker.d.ts","sourceRoot":"","sources":["../src/worker.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AACH,OAAO,KAAK,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AAG7B,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,cAAc,CAAC;AAC5C,OAAO,KAAK,EAAE,iBAAiB,EAAE,MAAM,YAAY,CAAC;AACpD,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,SAAS,CAAC;AAC7C,OAAO,KAAK,EACV,QAAQ,EACR,MAAM,EACN,iBAAiB,EACjB,aAAa,EACb,UAAU,EACV,MAAM,EACN,YAAY,EACZ,GAAG,EACH,iBAAiB,EAEjB,YAAY,EACb,MAAM,YAAY,CAAC;AA2BpB,MAAM,MAAM,MAAM,GAAG,aAAa,C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