@powerhousedao/reactor 4.1.0-dev.59 → 4.1.0-dev.60

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.
Files changed (44) hide show
  1. package/dist/src/core/reactor.d.ts.map +1 -1
  2. package/dist/src/core/reactor.js +33 -21
  3. package/dist/src/core/reactor.js.map +1 -1
  4. package/dist/src/executor/simple-job-executor.d.ts +5 -0
  5. package/dist/src/executor/simple-job-executor.d.ts.map +1 -1
  6. package/dist/src/executor/simple-job-executor.js +45 -0
  7. package/dist/src/executor/simple-job-executor.js.map +1 -1
  8. package/dist/src/index.d.ts +3 -0
  9. package/dist/src/index.d.ts.map +1 -1
  10. package/dist/src/index.js +3 -0
  11. package/dist/src/index.js.map +1 -1
  12. package/dist/src/queue/queue.js +8 -8
  13. package/dist/src/queue/queue.js.map +1 -1
  14. package/dist/src/read-models/document-view.d.ts +21 -0
  15. package/dist/src/read-models/document-view.d.ts.map +1 -0
  16. package/dist/src/read-models/document-view.js +285 -0
  17. package/dist/src/read-models/document-view.js.map +1 -0
  18. package/dist/src/read-models/types.d.ts +46 -0
  19. package/dist/src/read-models/types.d.ts.map +1 -0
  20. package/dist/src/read-models/types.js +2 -0
  21. package/dist/src/read-models/types.js.map +1 -0
  22. package/dist/src/shared/awaiter.js +3 -3
  23. package/dist/src/shared/awaiter.js.map +1 -1
  24. package/dist/src/shared/types.d.ts +5 -0
  25. package/dist/src/shared/types.d.ts.map +1 -1
  26. package/dist/src/shared/types.js +5 -0
  27. package/dist/src/shared/types.js.map +1 -1
  28. package/dist/src/storage/interfaces.d.ts +124 -0
  29. package/dist/src/storage/interfaces.d.ts.map +1 -0
  30. package/dist/src/storage/interfaces.js +19 -0
  31. package/dist/src/storage/interfaces.js.map +1 -0
  32. package/dist/src/storage/kysely/store.d.ts +15 -0
  33. package/dist/src/storage/kysely/store.d.ts.map +1 -0
  34. package/dist/src/storage/kysely/store.js +173 -0
  35. package/dist/src/storage/kysely/store.js.map +1 -0
  36. package/dist/src/storage/kysely/types.d.ts +26 -0
  37. package/dist/src/storage/kysely/types.d.ts.map +1 -0
  38. package/dist/src/storage/kysely/types.js +2 -0
  39. package/dist/src/storage/kysely/types.js.map +1 -0
  40. package/dist/src/storage/txn.d.ts +15 -0
  41. package/dist/src/storage/txn.d.ts.map +1 -0
  42. package/dist/src/storage/txn.js +42 -0
  43. package/dist/src/storage/txn.js.map +1 -0
  44. package/package.json +7 -4
@@ -0,0 +1,173 @@
1
+ import {} from "document-model";
2
+ import { DuplicateOperationError, RevisionMismatchError, } from "../interfaces.js";
3
+ import { AtomicTransaction } from "../txn.js";
4
+ export class KyselyOperationStore {
5
+ db;
6
+ constructor(db) {
7
+ this.db = db;
8
+ }
9
+ async apply(documentId, documentType, scope, branch, revision, fn, signal) {
10
+ await this.db.transaction().execute(async (trx) => {
11
+ // Check for abort signal
12
+ if (signal?.aborted) {
13
+ throw new Error("Operation aborted");
14
+ }
15
+ // Get the latest operation for this stream to verify revision
16
+ const latestOp = await trx
17
+ .selectFrom("Operation")
18
+ .selectAll()
19
+ .where("documentId", "=", documentId)
20
+ .where("scope", "=", scope)
21
+ .where("branch", "=", branch)
22
+ .orderBy("index", "desc")
23
+ .limit(1)
24
+ .executeTakeFirst();
25
+ // Check revision matches
26
+ const currentRevision = latestOp ? latestOp.index : -1;
27
+ if (currentRevision !== revision - 1) {
28
+ throw new RevisionMismatchError(revision - 1, currentRevision);
29
+ }
30
+ // Create atomic transaction
31
+ const atomicTxn = new AtomicTransaction(documentId, documentType, scope, branch, revision);
32
+ await fn(atomicTxn);
33
+ // Get operations and header updates
34
+ const operations = atomicTxn.getOperations();
35
+ // Insert operations
36
+ if (operations.length > 0) {
37
+ // Set prevOpId for each operation
38
+ let prevOpId = latestOp?.opId || "";
39
+ for (const op of operations) {
40
+ op.prevOpId = prevOpId;
41
+ prevOpId = op.opId;
42
+ }
43
+ try {
44
+ await trx.insertInto("Operation").values(operations).execute();
45
+ }
46
+ catch (error) {
47
+ if (error instanceof Error) {
48
+ if (error.message.includes("unique constraint")) {
49
+ // Extract the opId from the error if possible
50
+ const opId = operations[0]?.opId || "unknown";
51
+ throw new DuplicateOperationError(opId);
52
+ }
53
+ throw error;
54
+ }
55
+ throw error;
56
+ }
57
+ }
58
+ });
59
+ }
60
+ async get(documentId, scope, branch, index, signal) {
61
+ if (signal?.aborted) {
62
+ throw new Error("Operation aborted");
63
+ }
64
+ const row = await this.db
65
+ .selectFrom("Operation")
66
+ .selectAll()
67
+ .where("documentId", "=", documentId)
68
+ .where("scope", "=", scope)
69
+ .where("branch", "=", branch)
70
+ .where("index", "=", index)
71
+ .executeTakeFirst();
72
+ if (!row) {
73
+ throw new Error(`Operation not found: ${documentId}/${scope}/${branch}/${index}`);
74
+ }
75
+ return this.rowToOperationWithContext(row);
76
+ }
77
+ async getSince(documentId, scope, branch, index, signal) {
78
+ if (signal?.aborted) {
79
+ throw new Error("Operation aborted");
80
+ }
81
+ const rows = await this.db
82
+ .selectFrom("Operation")
83
+ .selectAll()
84
+ .where("documentId", "=", documentId)
85
+ .where("scope", "=", scope)
86
+ .where("branch", "=", branch)
87
+ .where("index", ">", index)
88
+ .orderBy("index", "asc")
89
+ .execute();
90
+ return rows.map((row) => this.rowToOperationWithContext(row));
91
+ }
92
+ async getSinceTimestamp(documentId, scope, branch, timestampUtcMs, signal) {
93
+ if (signal?.aborted) {
94
+ throw new Error("Operation aborted");
95
+ }
96
+ const rows = await this.db
97
+ .selectFrom("Operation")
98
+ .selectAll()
99
+ .where("documentId", "=", documentId)
100
+ .where("scope", "=", scope)
101
+ .where("branch", "=", branch)
102
+ .where("writeTimestampUtcMs", ">", new Date(timestampUtcMs))
103
+ .orderBy("index", "asc")
104
+ .execute();
105
+ return rows.map((row) => this.rowToOperationWithContext(row));
106
+ }
107
+ async getSinceId(id, signal) {
108
+ if (signal?.aborted) {
109
+ throw new Error("Operation aborted");
110
+ }
111
+ const rows = await this.db
112
+ .selectFrom("Operation")
113
+ .selectAll()
114
+ .where("id", ">", id)
115
+ .orderBy("id", "asc")
116
+ .execute();
117
+ return rows.map((row) => this.rowToOperationWithContext(row));
118
+ }
119
+ async getRevisions(documentId, branch, signal) {
120
+ if (signal?.aborted) {
121
+ throw new Error("Operation aborted");
122
+ }
123
+ // Get the latest operation for each scope in a single query
124
+ // Uses a subquery to find operations where the index equals the max index for that scope
125
+ const scopeRevisions = await this.db
126
+ .selectFrom("Operation as o1")
127
+ .select(["o1.scope", "o1.index", "o1.timestampUtcMs"])
128
+ .where("o1.documentId", "=", documentId)
129
+ .where("o1.branch", "=", branch)
130
+ .where((eb) => eb("o1.index", "=", eb
131
+ .selectFrom("Operation as o2")
132
+ .select((eb2) => eb2.fn.max("o2.index").as("maxIndex"))
133
+ .where("o2.documentId", "=", eb.ref("o1.documentId"))
134
+ .where("o2.branch", "=", eb.ref("o1.branch"))
135
+ .where("o2.scope", "=", eb.ref("o1.scope"))))
136
+ .execute();
137
+ // Build the revision map and find the latest timestamp
138
+ const revision = {};
139
+ let latestTimestamp = new Date(0).toISOString(); // Start with epoch
140
+ for (const row of scopeRevisions) {
141
+ revision[row.scope] = row.index;
142
+ const timestamp = row.timestampUtcMs.toISOString();
143
+ if (timestamp > latestTimestamp) {
144
+ latestTimestamp = timestamp;
145
+ }
146
+ }
147
+ return {
148
+ revision,
149
+ latestTimestamp,
150
+ };
151
+ }
152
+ rowToOperationWithContext(row) {
153
+ return {
154
+ operation: {
155
+ index: row.index,
156
+ timestampUtcMs: row.timestampUtcMs.toISOString(),
157
+ hash: row.hash,
158
+ skip: row.skip,
159
+ error: row.error || undefined,
160
+ resultingState: row.resultingState || undefined,
161
+ id: row.opId,
162
+ action: JSON.parse(row.action),
163
+ },
164
+ context: {
165
+ documentId: row.documentId,
166
+ documentType: row.documentType,
167
+ scope: row.scope,
168
+ branch: row.branch,
169
+ },
170
+ };
171
+ }
172
+ }
173
+ //# sourceMappingURL=store.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"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AW,EAAE,CAAC,CAAC,mBAAmB;QAEpE,KAAK,MAAM,GAAG,IAAI,cAAc,EAAE,CAAC;YACjC,QAAQ,CAAC,GAAG,CAAC,KAAK,CAAC,GAAG,GAAG,CAAC,KAAK,CAAC;YAChC,MAAM,SAAS,GAAG,GAAG,CAAC,cAAc,CAAC,WAAW,EAAE,CAAC;YACnD,IAAI,SAAS,GAAG,eAAe,EAAE,CAAC;gBAChC,eAAe,GAAG,SAAS,CAAC;YAC9B,CAAC;QACH,CAAC;QAED,OAAO;YACL,QAAQ;YACR,eAAe;SAChB,CAAC;IACJ,CAAC;IAEO,yBAAyB,CAAC,GAAiB;QACjD,OAAO;YACL,SAAS,EAAE;gBACT,KAAK,EAAE,GAAG,CAAC,KAAK;gBAChB,cAAc,EAAE,GAAG,CAAC,cAAc,CAAC,WAAW,EAAE;gBAChD,IAAI,EAAE,GAAG,CAAC,IAAI;gBACd,IAAI,EAAE,GAAG,CAAC,IAAI;gBACd,KAAK,EAAE,GAAG,CAAC,KAAK,IAAI,SAAS;gBAC7B,cAAc,EAAE,GAAG,CAAC,cAAc,IAAI,SAAS;gBAC/C,EAAE,EAAE,GAAG,CAAC,IAAI;gBACZ,MAAM,EAAE,IAAI,CAAC,KAAK,CAAC,GAAG,CAAC,MAAM,CAAwB;aACtD;YACD,OAAO,EAAE;gBACP,UAAU,EAAE,GAAG,CAAC,UAAU;gBAC1B,YAAY,EAAE,GAAG,CAAC,YAAY;gBAC9B,KAAK,EAAE,GAAG,CAAC,KAAK;gBAChB,MAAM,EAAE,GAAG,CAAC,MAAM;aACnB;SACF,CAAC;IACJ,CAAC;CACF"}
@@ -0,0 +1,26 @@
1
+ import type { Generated, Insertable, Selectable, Updateable } from "kysely";
2
+ export interface OperationTable {
3
+ id: Generated<number>;
4
+ jobId: string;
5
+ opId: string;
6
+ prevOpId: string;
7
+ writeTimestampUtcMs: Generated<Date>;
8
+ documentId: string;
9
+ documentType: string;
10
+ scope: string;
11
+ branch: string;
12
+ timestampUtcMs: Date;
13
+ index: number;
14
+ action: string;
15
+ skip: number;
16
+ resultingState?: string | null;
17
+ error?: string | null;
18
+ hash: string;
19
+ }
20
+ export interface Database {
21
+ Operation: OperationTable;
22
+ }
23
+ export type OperationRow = Selectable<OperationTable>;
24
+ export type InsertableOperation = Insertable<OperationTable>;
25
+ export type UpdateableOperation = Updateable<OperationTable>;
26
+ //# sourceMappingURL=types.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../../../src/storage/kysely/types.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,SAAS,EAAE,UAAU,EAAE,UAAU,EAAE,UAAU,EAAE,MAAM,QAAQ,CAAC;AAE5E,MAAM,WAAW,cAAc;IAC7B,EAAE,EAAE,SAAS,CAAC,MAAM,CAAC,CAAC;IACtB,KAAK,EAAE,MAAM,CAAC;IACd,IAAI,EAAE,MAAM,CAAC;IACb,QAAQ,EAAE,MAAM,CAAC;IACjB,mBAAmB,EAAE,SAAS,CAAC,IAAI,CAAC,CAAC;IACrC,UAAU,EAAE,MAAM,CAAC;IACnB,YAAY,EAAE,MAAM,CAAC;IACrB,KAAK,EAAE,MAAM,CAAC;IACd,MAAM,EAAE,MAAM,CAAC;IACf,cAAc,EAAE,IAAI,CAAC;IACrB,KAAK,EAAE,MAAM,CAAC;IACd,MAAM,EAAE,MAAM,CAAC;IACf,IAAI,EAAE,MAAM,CAAC;IACb,cAAc,CAAC,EAAE,MAAM,GAAG,IAAI,CAAC;IAC/B,KAAK,CAAC,EAAE,MAAM,GAAG,IAAI,CAAC;IACtB,IAAI,EAAE,MAAM,CAAC;CACd;AAED,MAAM,WAAW,QAAQ;IACvB,SAAS,EAAE,cAAc,CAAC;CAC3B;AAED,MAAM,MAAM,YAAY,GAAG,UAAU,CAAC,cAAc,CAAC,CAAC;AACtD,MAAM,MAAM,mBAAmB,GAAG,UAAU,CAAC,cAAc,CAAC,CAAC;AAC7D,MAAM,MAAM,mBAAmB,GAAG,UAAU,CAAC,cAAc,CAAC,CAAC"}
@@ -0,0 +1,2 @@
1
+ export {};
2
+ //# sourceMappingURL=types.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"types.js","sourceRoot":"","sources":["../../../../src/storage/kysely/types.ts"],"names":[],"mappings":""}
@@ -0,0 +1,15 @@
1
+ import type { Operation } from "document-model";
2
+ import { type AtomicTxn as IAtomicTxn } from "./interfaces.js";
3
+ import type { InsertableOperation } from "./kysely/types.js";
4
+ export declare class AtomicTransaction implements IAtomicTxn {
5
+ private documentId;
6
+ private documentType;
7
+ private scope;
8
+ private branch;
9
+ private baseRevision;
10
+ private operations;
11
+ constructor(documentId: string, documentType: string, scope: string, branch: string, baseRevision: number);
12
+ addOperations(...operations: Operation[]): void;
13
+ getOperations(): InsertableOperation[];
14
+ }
15
+ //# sourceMappingURL=txn.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"txn.d.ts","sourceRoot":"","sources":["../../../src/storage/txn.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,gBAAgB,CAAC;AAEhD,OAAO,EAAE,KAAK,SAAS,IAAI,UAAU,EAAE,MAAM,iBAAiB,CAAC;AAC/D,OAAO,KAAK,EAAE,mBAAmB,EAAE,MAAM,mBAAmB,CAAC;AAE7D,qBAAa,iBAAkB,YAAW,UAAU;IAIhD,OAAO,CAAC,UAAU;IAClB,OAAO,CAAC,YAAY;IACpB,OAAO,CAAC,KAAK;IACb,OAAO,CAAC,MAAM;IACd,OAAO,CAAC,YAAY;IAPtB,OAAO,CAAC,UAAU,CAA6B;gBAGrC,UAAU,EAAE,MAAM,EAClB,YAAY,EAAE,MAAM,EACpB,KAAK,EAAE,MAAM,EACb,MAAM,EAAE,MAAM,EACd,YAAY,EAAE,MAAM;IAK9B,aAAa,CAAC,GAAG,UAAU,EAAE,SAAS,EAAE,GAAG,IAAI;IAqB/C,aAAa,IAAI,mBAAmB,EAAE;CAGvC"}
@@ -0,0 +1,42 @@
1
+ import { v4 as uuidv4 } from "uuid";
2
+ import {} from "./interfaces.js";
3
+ export class AtomicTransaction {
4
+ documentId;
5
+ documentType;
6
+ scope;
7
+ branch;
8
+ baseRevision;
9
+ operations = [];
10
+ constructor(documentId, documentType, scope, branch, baseRevision) {
11
+ this.documentId = documentId;
12
+ this.documentType = documentType;
13
+ this.scope = scope;
14
+ this.branch = branch;
15
+ this.baseRevision = baseRevision;
16
+ //
17
+ }
18
+ addOperations(...operations) {
19
+ for (const op of operations) {
20
+ this.operations.push({
21
+ jobId: uuidv4(),
22
+ opId: op.id || uuidv4(),
23
+ prevOpId: "", // Will be set during apply
24
+ documentId: this.documentId,
25
+ documentType: this.documentType,
26
+ scope: this.scope,
27
+ branch: this.branch,
28
+ timestampUtcMs: new Date(op.timestampUtcMs),
29
+ index: op.index,
30
+ action: JSON.stringify(op.action),
31
+ skip: op.skip,
32
+ resultingState: op.resultingState || null,
33
+ error: op.error || null,
34
+ hash: op.hash,
35
+ });
36
+ }
37
+ }
38
+ getOperations() {
39
+ return this.operations;
40
+ }
41
+ }
42
+ //# sourceMappingURL=txn.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"txn.js","sourceRoot":"","sources":["../../../src/storage/txn.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,EAAE,IAAI,MAAM,EAAE,MAAM,MAAM,CAAC;AACpC,OAAO,EAAgC,MAAM,iBAAiB,CAAC;AAG/D,MAAM,OAAO,iBAAiB;IAIlB;IACA;IACA;IACA;IACA;IAPF,UAAU,GAA0B,EAAE,CAAC;IAE/C,YACU,UAAkB,EAClB,YAAoB,EACpB,KAAa,EACb,MAAc,EACd,YAAoB;QAJpB,eAAU,GAAV,UAAU,CAAQ;QAClB,iBAAY,GAAZ,YAAY,CAAQ;QACpB,UAAK,GAAL,KAAK,CAAQ;QACb,WAAM,GAAN,MAAM,CAAQ;QACd,iBAAY,GAAZ,YAAY,CAAQ;QAE5B,EAAE;IACJ,CAAC;IAED,aAAa,CAAC,GAAG,UAAuB;QACtC,KAAK,MAAM,EAAE,IAAI,UAAU,EAAE,CAAC;YAC5B,IAAI,CAAC,UAAU,CAAC,IAAI,CAAC;gBACnB,KAAK,EAAE,MAAM,EAAE;gBACf,IAAI,EAAE,EAAE,CAAC,EAAE,IAAI,MAAM,EAAE;gBACvB,QAAQ,EAAE,EAAE,EAAE,2BAA2B;gBACzC,UAAU,EAAE,IAAI,CAAC,UAAU;gBAC3B,YAAY,EAAE,IAAI,CAAC,YAAY;gBAC/B,KAAK,EAAE,IAAI,CAAC,KAAK;gBACjB,MAAM,EAAE,IAAI,CAAC,MAAM;gBACnB,cAAc,EAAE,IAAI,IAAI,CAAC,EAAE,CAAC,cAAc,CAAC;gBAC3C,KAAK,EAAE,EAAE,CAAC,KAAK;gBACf,MAAM,EAAE,IAAI,CAAC,SAAS,CAAC,EAAE,CAAC,MAAM,CAAC;gBACjC,IAAI,EAAE,EAAE,CAAC,IAAI;gBACb,cAAc,EAAE,EAAE,CAAC,cAAc,IAAI,IAAI;gBACzC,KAAK,EAAE,EAAE,CAAC,KAAK,IAAI,IAAI;gBACvB,IAAI,EAAE,EAAE,CAAC,IAAI;aACd,CAAC,CAAC;QACL,CAAC;IACH,CAAC;IAED,aAAa;QACX,OAAO,IAAI,CAAC,UAAU,CAAC;IACzB,CAAC;CACF"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@powerhousedao/reactor",
3
- "version": "4.1.0-dev.59",
3
+ "version": "4.1.0-dev.60",
4
4
  "description": "",
5
5
  "repository": {
6
6
  "url": "https://github.com/powerhouse-inc/powerhouse",
@@ -24,13 +24,16 @@
24
24
  "author": "",
25
25
  "license": "AGPL-3.0-only",
26
26
  "dependencies": {
27
+ "@electric-sql/pglite": "^0.3.10",
28
+ "kysely": "^0.28.2",
29
+ "kysely-pglite": "^0.6.1",
27
30
  "uuid": "^11.0.5",
28
- "document-drive": "4.1.0-dev.59",
29
- "document-model": "4.1.0-dev.59"
31
+ "document-drive": "4.1.0-dev.60",
32
+ "document-model": "4.1.0-dev.60"
30
33
  },
31
34
  "devDependencies": {
32
35
  "typescript": "^5.7.3",
33
- "vitest": "^3.1.2"
36
+ "vitest": "^3.2.4"
34
37
  },
35
38
  "scripts": {
36
39
  "build": "pnpm run build:tsc",