@powerhousedao/reactor 4.1.0-dev.10 → 4.1.0-dev.100
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/dist/src/cache/buffer/ring-buffer.d.ts +37 -0
- package/dist/src/cache/buffer/ring-buffer.d.ts.map +1 -0
- package/dist/src/cache/buffer/ring-buffer.js +69 -0
- package/dist/src/cache/buffer/ring-buffer.js.map +1 -0
- package/dist/src/cache/kysely-write-cache.d.ts +133 -0
- package/dist/src/cache/kysely-write-cache.d.ts.map +1 -0
- package/dist/src/cache/kysely-write-cache.js +375 -0
- package/dist/src/cache/kysely-write-cache.js.map +1 -0
- package/dist/src/cache/lru/lru-tracker.d.ts +15 -0
- package/dist/src/cache/lru/lru-tracker.d.ts.map +1 -0
- package/dist/src/cache/lru/lru-tracker.js +96 -0
- package/dist/src/cache/lru/lru-tracker.js.map +1 -0
- package/dist/src/cache/types.d.ts +42 -0
- package/dist/src/cache/types.d.ts.map +1 -0
- package/dist/src/cache/types.js +2 -0
- package/dist/src/cache/types.js.map +1 -0
- package/dist/src/cache/write/interfaces.d.ts +83 -0
- package/dist/src/cache/write/interfaces.d.ts.map +1 -0
- package/dist/src/cache/write/interfaces.js +2 -0
- package/dist/src/cache/write/interfaces.js.map +1 -0
- package/dist/src/client/reactor-client.d.ts +103 -0
- package/dist/src/client/reactor-client.d.ts.map +1 -0
- package/dist/src/client/reactor-client.js +184 -0
- package/dist/src/client/reactor-client.js.map +1 -0
- package/dist/src/client/types.d.ts +213 -0
- package/dist/src/client/types.d.ts.map +1 -0
- package/dist/src/client/types.js +14 -0
- package/dist/src/client/types.js.map +1 -0
- package/dist/src/core/builder.d.ts +20 -0
- package/dist/src/core/builder.d.ts.map +1 -0
- package/dist/src/core/builder.js +47 -0
- package/dist/src/core/builder.js.map +1 -0
- package/dist/src/core/reactor-builder.d.ts +24 -0
- package/dist/src/core/reactor-builder.d.ts.map +1 -0
- package/dist/src/core/reactor-builder.js +152 -0
- package/dist/src/core/reactor-builder.js.map +1 -0
- package/dist/src/core/reactor.d.ts +96 -0
- package/dist/src/core/reactor.d.ts.map +1 -0
- package/dist/src/core/reactor.js +666 -0
- package/dist/src/core/reactor.js.map +1 -0
- package/dist/src/core/types.d.ts +168 -0
- package/dist/src/core/types.d.ts.map +1 -0
- package/dist/src/core/types.js +2 -0
- package/dist/src/core/types.js.map +1 -0
- package/dist/src/core/utils.d.ts +50 -0
- package/dist/src/core/utils.d.ts.map +1 -0
- package/dist/src/core/utils.js +133 -0
- package/dist/src/core/utils.js.map +1 -0
- package/dist/src/events/event-bus.d.ts +3 -3
- package/dist/src/events/event-bus.d.ts.map +1 -1
- package/dist/src/events/event-bus.js.map +1 -1
- package/dist/src/events/interfaces.d.ts +1 -1
- package/dist/src/events/interfaces.d.ts.map +1 -1
- package/dist/src/events/types.d.ts +15 -1
- package/dist/src/events/types.d.ts.map +1 -1
- package/dist/src/events/types.js +6 -0
- package/dist/src/events/types.js.map +1 -1
- package/dist/src/executor/interfaces.d.ts +31 -54
- package/dist/src/executor/interfaces.d.ts.map +1 -1
- package/dist/src/executor/simple-job-executor-manager.d.ts +32 -0
- package/dist/src/executor/simple-job-executor-manager.d.ts.map +1 -0
- package/dist/src/executor/simple-job-executor-manager.js +212 -0
- package/dist/src/executor/simple-job-executor-manager.js.map +1 -0
- package/dist/src/executor/simple-job-executor.d.ts +58 -0
- package/dist/src/executor/simple-job-executor.d.ts.map +1 -0
- package/dist/src/executor/simple-job-executor.js +516 -0
- package/dist/src/executor/simple-job-executor.js.map +1 -0
- package/dist/src/executor/types.d.ts +32 -8
- package/dist/src/executor/types.d.ts.map +1 -1
- package/dist/src/executor/types.js.map +1 -1
- package/dist/src/executor/util.d.ts +47 -0
- package/dist/src/executor/util.d.ts.map +1 -0
- package/dist/src/executor/util.js +113 -0
- package/dist/src/executor/util.js.map +1 -0
- package/dist/src/index.d.ts +32 -3
- package/dist/src/index.d.ts.map +1 -1
- package/dist/src/index.js +38 -2
- package/dist/src/index.js.map +1 -1
- package/dist/src/job-tracker/in-memory-job-tracker.d.ts +16 -0
- package/dist/src/job-tracker/in-memory-job-tracker.d.ts.map +1 -0
- package/dist/src/job-tracker/in-memory-job-tracker.js +78 -0
- package/dist/src/job-tracker/in-memory-job-tracker.js.map +1 -0
- package/dist/src/job-tracker/index.d.ts +3 -0
- package/dist/src/job-tracker/index.d.ts.map +1 -0
- package/dist/src/job-tracker/index.js +2 -0
- package/dist/src/job-tracker/index.js.map +1 -0
- package/dist/src/job-tracker/interfaces.d.ts +41 -0
- package/dist/src/job-tracker/interfaces.d.ts.map +1 -0
- package/dist/src/job-tracker/interfaces.js +2 -0
- package/dist/src/job-tracker/interfaces.js.map +1 -0
- package/dist/src/queue/interfaces.d.ts +46 -5
- package/dist/src/queue/interfaces.d.ts.map +1 -1
- package/dist/src/queue/job-execution-handle.d.ts +25 -0
- package/dist/src/queue/job-execution-handle.d.ts.map +1 -0
- package/dist/src/queue/job-execution-handle.js +62 -0
- package/dist/src/queue/job-execution-handle.js.map +1 -0
- package/dist/src/queue/queue.d.ts +56 -5
- package/dist/src/queue/queue.d.ts.map +1 -1
- package/dist/src/queue/queue.js +284 -36
- package/dist/src/queue/queue.js.map +1 -1
- package/dist/src/queue/types.d.ts +33 -5
- package/dist/src/queue/types.d.ts.map +1 -1
- package/dist/src/queue/types.js +12 -0
- package/dist/src/queue/types.js.map +1 -1
- package/dist/src/read-models/coordinator.d.ts +38 -0
- package/dist/src/read-models/coordinator.d.ts.map +1 -0
- package/dist/src/read-models/coordinator.js +62 -0
- package/dist/src/read-models/coordinator.js.map +1 -0
- package/dist/src/read-models/document-view.d.ts +20 -0
- package/dist/src/read-models/document-view.d.ts.map +1 -0
- package/dist/src/read-models/document-view.js +365 -0
- package/dist/src/read-models/document-view.js.map +1 -0
- package/dist/src/read-models/interfaces.d.ts +29 -0
- package/dist/src/read-models/interfaces.d.ts.map +1 -0
- package/dist/src/read-models/interfaces.js +2 -0
- package/dist/src/read-models/interfaces.js.map +1 -0
- package/dist/src/read-models/types.d.ts +46 -0
- package/dist/src/read-models/types.d.ts.map +1 -0
- package/dist/src/read-models/types.js +2 -0
- package/dist/src/read-models/types.js.map +1 -0
- package/dist/src/registry/implementation.d.ts +62 -0
- package/dist/src/registry/implementation.d.ts.map +1 -0
- package/dist/src/registry/implementation.js +96 -0
- package/dist/src/registry/implementation.js.map +1 -0
- package/dist/src/registry/index.d.ts +3 -0
- package/dist/src/registry/index.d.ts.map +1 -0
- package/dist/src/registry/index.js +2 -0
- package/dist/src/registry/index.js.map +1 -0
- package/dist/src/registry/interfaces.d.ts +39 -0
- package/dist/src/registry/interfaces.d.ts.map +1 -0
- package/dist/src/registry/interfaces.js +2 -0
- package/dist/src/registry/interfaces.js.map +1 -0
- package/dist/src/shared/awaiter.d.ts +32 -0
- package/dist/src/shared/awaiter.d.ts.map +1 -0
- package/dist/src/shared/awaiter.js +132 -0
- package/dist/src/shared/awaiter.js.map +1 -0
- package/dist/src/shared/errors.d.ts +17 -0
- package/dist/src/shared/errors.d.ts.map +1 -0
- package/dist/src/shared/errors.js +33 -0
- package/dist/src/shared/errors.js.map +1 -0
- package/dist/src/shared/factories.d.ts +16 -0
- package/dist/src/shared/factories.d.ts.map +1 -0
- package/dist/src/shared/factories.js +33 -0
- package/dist/src/shared/factories.js.map +1 -0
- package/dist/src/shared/types.d.ts +100 -20
- package/dist/src/shared/types.d.ts.map +1 -1
- package/dist/src/shared/types.js +35 -1
- package/dist/src/shared/types.js.map +1 -1
- package/dist/src/shared/utils.d.ts +3 -0
- package/dist/src/shared/utils.d.ts.map +1 -0
- package/dist/src/shared/utils.js +8 -0
- package/dist/src/shared/utils.js.map +1 -0
- package/dist/src/signer/passthrough-signer.d.ts +6 -0
- package/dist/src/signer/passthrough-signer.d.ts.map +1 -0
- package/dist/src/signer/passthrough-signer.js +6 -0
- package/dist/src/signer/passthrough-signer.js.map +1 -0
- package/dist/src/signer/types.d.ts +15 -0
- package/dist/src/signer/types.d.ts.map +1 -0
- package/dist/src/signer/types.js +2 -0
- package/dist/src/signer/types.js.map +1 -0
- package/dist/src/storage/interfaces.d.ts +209 -0
- package/dist/src/storage/interfaces.d.ts.map +1 -0
- package/dist/src/storage/interfaces.js +19 -0
- package/dist/src/storage/interfaces.js.map +1 -0
- package/dist/src/storage/kysely/document-indexer.d.ts +25 -0
- package/dist/src/storage/kysely/document-indexer.d.ts.map +1 -0
- package/dist/src/storage/kysely/document-indexer.js +345 -0
- package/dist/src/storage/kysely/document-indexer.js.map +1 -0
- package/dist/src/storage/kysely/keyframe-store.d.ts +15 -0
- package/dist/src/storage/kysely/keyframe-store.d.ts.map +1 -0
- package/dist/src/storage/kysely/keyframe-store.js +71 -0
- package/dist/src/storage/kysely/keyframe-store.js.map +1 -0
- package/dist/src/storage/kysely/store.d.ts +15 -0
- package/dist/src/storage/kysely/store.d.ts.map +1 -0
- package/dist/src/storage/kysely/store.js +196 -0
- package/dist/src/storage/kysely/store.js.map +1 -0
- package/dist/src/storage/kysely/types.d.ts +72 -0
- package/dist/src/storage/kysely/types.d.ts.map +1 -0
- package/dist/src/storage/kysely/types.js +2 -0
- package/dist/src/storage/kysely/types.js.map +1 -0
- package/dist/src/storage/txn.d.ts +15 -0
- package/dist/src/storage/txn.d.ts.map +1 -0
- package/dist/src/storage/txn.js +43 -0
- package/dist/src/storage/txn.js.map +1 -0
- package/dist/src/subs/default-error-handler.d.ts +13 -0
- package/dist/src/subs/default-error-handler.d.ts.map +1 -0
- package/dist/src/subs/default-error-handler.js +27 -0
- package/dist/src/subs/default-error-handler.js.map +1 -0
- package/dist/src/subs/react-subscription-manager.d.ts +45 -0
- package/dist/src/subs/react-subscription-manager.d.ts.map +1 -0
- package/dist/src/subs/react-subscription-manager.js +185 -0
- package/dist/src/subs/react-subscription-manager.js.map +1 -0
- package/dist/src/subs/types.d.ts +64 -0
- package/dist/src/subs/types.d.ts.map +1 -0
- package/dist/src/subs/types.js +2 -0
- package/dist/src/subs/types.js.map +1 -0
- package/dist/src/utils/reshuffle.d.ts +30 -0
- package/dist/src/utils/reshuffle.d.ts.map +1 -0
- package/dist/src/utils/reshuffle.js +47 -0
- package/dist/src/utils/reshuffle.js.map +1 -0
- package/package.json +18 -7
- package/dist/bench/end-to-end-flow.bench.d.ts +0 -2
- package/dist/bench/end-to-end-flow.bench.d.ts.map +0 -1
- package/dist/bench/end-to-end-flow.bench.js +0 -256
- package/dist/bench/end-to-end-flow.bench.js.map +0 -1
- package/dist/bench/event-bus.bench.d.ts +0 -2
- package/dist/bench/event-bus.bench.d.ts.map +0 -1
- package/dist/bench/event-bus.bench.js +0 -238
- package/dist/bench/event-bus.bench.js.map +0 -1
- package/dist/bench/queue-only.bench.d.ts +0 -2
- package/dist/bench/queue-only.bench.d.ts.map +0 -1
- package/dist/bench/queue-only.bench.js +0 -40
- package/dist/bench/queue-only.bench.js.map +0 -1
- package/dist/bench/reactor-throughput.bench.d.ts +0 -2
- package/dist/bench/reactor-throughput.bench.d.ts.map +0 -1
- package/dist/bench/reactor-throughput.bench.js +0 -137
- package/dist/bench/reactor-throughput.bench.js.map +0 -1
- package/dist/src/executor/job-executor.d.ts +0 -62
- package/dist/src/executor/job-executor.d.ts.map +0 -1
- package/dist/src/executor/job-executor.js +0 -325
- package/dist/src/executor/job-executor.js.map +0 -1
- package/dist/test/event-bus.test.d.ts +0 -2
- package/dist/test/event-bus.test.d.ts.map +0 -1
- package/dist/test/event-bus.test.js +0 -532
- package/dist/test/event-bus.test.js.map +0 -1
- package/dist/test/job-executor.test.d.ts +0 -2
- package/dist/test/job-executor.test.d.ts.map +0 -1
- package/dist/test/job-executor.test.js +0 -581
- package/dist/test/job-executor.test.js.map +0 -1
- package/dist/test/queue.test.d.ts +0 -2
- package/dist/test/queue.test.d.ts.map +0 -1
- package/dist/test/queue.test.js +0 -396
- package/dist/test/queue.test.js.map +0 -1
- package/dist/tsconfig.tsbuildinfo +0 -1
|
@@ -0,0 +1,196 @@
|
|
|
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 getSince(documentId, scope, branch, revision, paging, signal) {
|
|
61
|
+
if (signal?.aborted) {
|
|
62
|
+
throw new Error("Operation aborted");
|
|
63
|
+
}
|
|
64
|
+
let query = this.db
|
|
65
|
+
.selectFrom("Operation")
|
|
66
|
+
.selectAll()
|
|
67
|
+
.where("documentId", "=", documentId)
|
|
68
|
+
.where("scope", "=", scope)
|
|
69
|
+
.where("branch", "=", branch)
|
|
70
|
+
.where("index", ">", revision)
|
|
71
|
+
.orderBy("index", "asc");
|
|
72
|
+
// Handle cursor-based pagination
|
|
73
|
+
if (paging) {
|
|
74
|
+
// Cursor encodes the last seen index
|
|
75
|
+
if (paging.cursor) {
|
|
76
|
+
const lastIndex = Number.parseInt(paging.cursor, 10);
|
|
77
|
+
query = query.where("index", ">", lastIndex);
|
|
78
|
+
}
|
|
79
|
+
// Apply limit if specified (fetch one extra to determine hasMore)
|
|
80
|
+
if (paging.limit) {
|
|
81
|
+
query = query.limit(paging.limit + 1);
|
|
82
|
+
}
|
|
83
|
+
}
|
|
84
|
+
const rows = await query.execute();
|
|
85
|
+
// Determine if there are more results
|
|
86
|
+
let hasMore = false;
|
|
87
|
+
let items = rows;
|
|
88
|
+
if (paging?.limit && rows.length > paging.limit) {
|
|
89
|
+
hasMore = true;
|
|
90
|
+
items = rows.slice(0, paging.limit);
|
|
91
|
+
}
|
|
92
|
+
// Generate next cursor from last item's index
|
|
93
|
+
const nextCursor = hasMore && items.length > 0
|
|
94
|
+
? items[items.length - 1].index.toString()
|
|
95
|
+
: undefined;
|
|
96
|
+
return {
|
|
97
|
+
items: items.map((row) => this.rowToOperation(row)),
|
|
98
|
+
nextCursor,
|
|
99
|
+
hasMore,
|
|
100
|
+
};
|
|
101
|
+
}
|
|
102
|
+
async getSinceId(id, paging, signal) {
|
|
103
|
+
if (signal?.aborted) {
|
|
104
|
+
throw new Error("Operation aborted");
|
|
105
|
+
}
|
|
106
|
+
let query = this.db
|
|
107
|
+
.selectFrom("Operation")
|
|
108
|
+
.selectAll()
|
|
109
|
+
.where("id", ">", id)
|
|
110
|
+
.orderBy("id", "asc");
|
|
111
|
+
// Handle cursor-based pagination
|
|
112
|
+
if (paging) {
|
|
113
|
+
// Cursor encodes the last seen id
|
|
114
|
+
if (paging.cursor) {
|
|
115
|
+
const lastId = Number.parseInt(paging.cursor, 10);
|
|
116
|
+
query = query.where("id", ">", lastId);
|
|
117
|
+
}
|
|
118
|
+
// Apply limit if specified (fetch one extra to determine hasMore)
|
|
119
|
+
if (paging.limit) {
|
|
120
|
+
query = query.limit(paging.limit + 1);
|
|
121
|
+
}
|
|
122
|
+
}
|
|
123
|
+
const rows = await query.execute();
|
|
124
|
+
// Determine if there are more results
|
|
125
|
+
let hasMore = false;
|
|
126
|
+
let items = rows;
|
|
127
|
+
if (paging?.limit && rows.length > paging.limit) {
|
|
128
|
+
hasMore = true;
|
|
129
|
+
items = rows.slice(0, paging.limit);
|
|
130
|
+
}
|
|
131
|
+
// Generate next cursor from last item's id
|
|
132
|
+
const nextCursor = hasMore && items.length > 0
|
|
133
|
+
? items[items.length - 1].id.toString()
|
|
134
|
+
: undefined;
|
|
135
|
+
return {
|
|
136
|
+
items: items.map((row) => this.rowToOperationWithContext(row)),
|
|
137
|
+
nextCursor,
|
|
138
|
+
hasMore,
|
|
139
|
+
};
|
|
140
|
+
}
|
|
141
|
+
async getRevisions(documentId, branch, signal) {
|
|
142
|
+
if (signal?.aborted) {
|
|
143
|
+
throw new Error("Operation aborted");
|
|
144
|
+
}
|
|
145
|
+
// Get the latest operation for each scope in a single query
|
|
146
|
+
// Uses a subquery to find operations where the index equals the max index for that scope
|
|
147
|
+
const scopeRevisions = await this.db
|
|
148
|
+
.selectFrom("Operation as o1")
|
|
149
|
+
.select(["o1.scope", "o1.index", "o1.timestampUtcMs"])
|
|
150
|
+
.where("o1.documentId", "=", documentId)
|
|
151
|
+
.where("o1.branch", "=", branch)
|
|
152
|
+
.where((eb) => eb("o1.index", "=", eb
|
|
153
|
+
.selectFrom("Operation as o2")
|
|
154
|
+
.select((eb2) => eb2.fn.max("o2.index").as("maxIndex"))
|
|
155
|
+
.where("o2.documentId", "=", eb.ref("o1.documentId"))
|
|
156
|
+
.where("o2.branch", "=", eb.ref("o1.branch"))
|
|
157
|
+
.where("o2.scope", "=", eb.ref("o1.scope"))))
|
|
158
|
+
.execute();
|
|
159
|
+
const revision = {};
|
|
160
|
+
let latestTimestamp = new Date(0).toISOString();
|
|
161
|
+
for (const row of scopeRevisions) {
|
|
162
|
+
revision[row.scope] = row.index + 1;
|
|
163
|
+
const timestamp = row.timestampUtcMs.toISOString();
|
|
164
|
+
if (timestamp > latestTimestamp) {
|
|
165
|
+
latestTimestamp = timestamp;
|
|
166
|
+
}
|
|
167
|
+
}
|
|
168
|
+
return {
|
|
169
|
+
revision,
|
|
170
|
+
latestTimestamp,
|
|
171
|
+
};
|
|
172
|
+
}
|
|
173
|
+
rowToOperation(row) {
|
|
174
|
+
return {
|
|
175
|
+
index: row.index,
|
|
176
|
+
timestampUtcMs: row.timestampUtcMs.toISOString(),
|
|
177
|
+
hash: row.hash,
|
|
178
|
+
skip: row.skip,
|
|
179
|
+
error: row.error || undefined,
|
|
180
|
+
id: row.opId,
|
|
181
|
+
action: JSON.parse(row.action),
|
|
182
|
+
};
|
|
183
|
+
}
|
|
184
|
+
rowToOperationWithContext(row) {
|
|
185
|
+
return {
|
|
186
|
+
operation: this.rowToOperation(row),
|
|
187
|
+
context: {
|
|
188
|
+
documentId: row.documentId,
|
|
189
|
+
documentType: row.documentType,
|
|
190
|
+
scope: row.scope,
|
|
191
|
+
branch: row.branch,
|
|
192
|
+
},
|
|
193
|
+
};
|
|
194
|
+
}
|
|
195
|
+
}
|
|
196
|
+
//# sourceMappingURL=store.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"store.js","sourceRoot":"","sources":["../../../../src/storage/kysely/store.ts"],"names":[],"mappings":"AAAA,OAAO,EAAkB,MAAM,gBAAgB,CAAC;AAEhD,OAAO,EACL,uBAAuB,EACvB,qBAAqB,GAOtB,MAAM,kBAAkB,CAAC;AAC1B,OAAO,EAAE,iBAAiB,EAAE,MAAM,WAAW,CAAC;AAG9C,MAAM,OAAO,oBAAoB;IACX;IAApB,YAAoB,EAAoB;QAApB,OAAE,GAAF,EAAE,CAAkB;IAAG,CAAC;IAE5C,KAAK,CAAC,KAAK,CACT,UAAkB,EAClB,YAAoB,EACpB,KAAa,EACb,MAAc,EACd,QAAgB,EAChB,EAA4C,EAC5C,MAAoB;QAEpB,MAAM,IAAI,CAAC,EAAE,CAAC,WAAW,EAAE,CAAC,OAAO,CAAC,KAAK,EAAE,GAAG,EAAE,EAAE;YAChD,yBAAyB;YACzB,IAAI,MAAM,EAAE,OAAO,EAAE,CAAC;gBACpB,MAAM,IAAI,KAAK,CAAC,mBAAmB,CAAC,CAAC;YACvC,CAAC;YAED,8DAA8D;YAC9D,MAAM,QAAQ,GAAG,MAAM,GAAG;iBACvB,UAAU,CAAC,WAAW,CAAC;iBACvB,SAAS,EAAE;iBACX,KAAK,CAAC,YAAY,EAAE,GAAG,EAAE,UAAU,CAAC;iBACpC,KAAK,CAAC,OAAO,EAAE,GAAG,EAAE,KAAK,CAAC;iBAC1B,KAAK,CAAC,QAAQ,EAAE,GAAG,EAAE,MAAM,CAAC;iBAC5B,OAAO,CAAC,OAAO,EAAE,MAAM,CAAC;iBACxB,KAAK,CAAC,CAAC,CAAC;iBACR,gBAAgB,EAAE,CAAC;YAEtB,yBAAyB;YACzB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ACtC,OAAO;YACL,KAAK,EAAE,GAAG,CAAC,KAAK;YAChB,cAAc,EAAE,GAAG,CAAC,cAAc,CAAC,WAAW,EAAE;YAChD,IAAI,EAAE,GAAG,CAAC,IAAI;YACd,IAAI,EAAE,GAAG,CAAC,IAAI;YACd,KAAK,EAAE,GAAG,CAAC,KAAK,IAAI,SAAS;YAC7B,EAAE,EAAE,GAAG,CAAC,IAAI;YACZ,MAAM,EAAE,IAAI,CAAC,KAAK,CAAC,GAAG,CAAC,MAAM,CAAwB;SACtD,CAAC;IACJ,CAAC;IAEO,yBAAyB,CAAC,GAAiB;QACjD,OAAO;YACL,SAAS,EAAE,IAAI,CAAC,cAAc,CAAC,GAAG,CAAC;YACnC,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,72 @@
|
|
|
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
|
+
error?: string | null;
|
|
17
|
+
hash: string;
|
|
18
|
+
}
|
|
19
|
+
export interface KeyframeTable {
|
|
20
|
+
id: Generated<number>;
|
|
21
|
+
documentId: string;
|
|
22
|
+
documentType: string;
|
|
23
|
+
scope: string;
|
|
24
|
+
branch: string;
|
|
25
|
+
revision: number;
|
|
26
|
+
document: string;
|
|
27
|
+
createdAt: Generated<Date>;
|
|
28
|
+
}
|
|
29
|
+
export interface Database {
|
|
30
|
+
Operation: OperationTable;
|
|
31
|
+
Keyframe: KeyframeTable;
|
|
32
|
+
}
|
|
33
|
+
export type OperationRow = Selectable<OperationTable>;
|
|
34
|
+
export type InsertableOperation = Insertable<OperationTable>;
|
|
35
|
+
export type UpdateableOperation = Updateable<OperationTable>;
|
|
36
|
+
export type KeyframeRow = Selectable<KeyframeTable>;
|
|
37
|
+
export type InsertableKeyframe = Insertable<KeyframeTable>;
|
|
38
|
+
export type UpdateableKeyframe = Updateable<KeyframeTable>;
|
|
39
|
+
export interface DocumentTable {
|
|
40
|
+
id: string;
|
|
41
|
+
createdAt: Generated<Date>;
|
|
42
|
+
updatedAt: Generated<Date>;
|
|
43
|
+
}
|
|
44
|
+
export interface DocumentRelationshipTable {
|
|
45
|
+
id: Generated<string>;
|
|
46
|
+
sourceId: string;
|
|
47
|
+
targetId: string;
|
|
48
|
+
relationshipType: string;
|
|
49
|
+
metadata: string | null;
|
|
50
|
+
createdAt: Generated<Date>;
|
|
51
|
+
updatedAt: Generated<Date>;
|
|
52
|
+
}
|
|
53
|
+
export interface IndexerStateTable {
|
|
54
|
+
id: Generated<number>;
|
|
55
|
+
lastOperationId: number;
|
|
56
|
+
lastOperationTimestamp: Generated<Date>;
|
|
57
|
+
}
|
|
58
|
+
export interface DocumentIndexerDatabase {
|
|
59
|
+
Document: DocumentTable;
|
|
60
|
+
DocumentRelationship: DocumentRelationshipTable;
|
|
61
|
+
IndexerState: IndexerStateTable;
|
|
62
|
+
}
|
|
63
|
+
export type DocumentRow = Selectable<DocumentTable>;
|
|
64
|
+
export type InsertableDocument = Insertable<DocumentTable>;
|
|
65
|
+
export type UpdateableDocument = Updateable<DocumentTable>;
|
|
66
|
+
export type DocumentRelationshipRow = Selectable<DocumentRelationshipTable>;
|
|
67
|
+
export type InsertableDocumentRelationship = Insertable<DocumentRelationshipTable>;
|
|
68
|
+
export type UpdateableDocumentRelationship = Updateable<DocumentRelationshipTable>;
|
|
69
|
+
export type IndexerStateRow = Selectable<IndexerStateTable>;
|
|
70
|
+
export type InsertableIndexerState = Insertable<IndexerStateTable>;
|
|
71
|
+
export type UpdateableIndexerState = Updateable<IndexerStateTable>;
|
|
72
|
+
//# 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,KAAK,CAAC,EAAE,MAAM,GAAG,IAAI,CAAC;IACtB,IAAI,EAAE,MAAM,CAAC;CACd;AAED,MAAM,WAAW,aAAa;IAC5B,EAAE,EAAE,SAAS,CAAC,MAAM,CAAC,CAAC;IACtB,UAAU,EAAE,MAAM,CAAC;IACnB,YAAY,EAAE,MAAM,CAAC;IACrB,KAAK,EAAE,MAAM,CAAC;IACd,MAAM,EAAE,MAAM,CAAC;IACf,QAAQ,EAAE,MAAM,CAAC;IACjB,QAAQ,EAAE,MAAM,CAAC;IACjB,SAAS,EAAE,SAA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,YAAY,EAAE,iBAAiB,CAAC;CACjC;AAED,MAAM,MAAM,WAAW,GAAG,UAAU,CAAC,aAAa,CAAC,CAAC;AACpD,MAAM,MAAM,kBAAkB,GAAG,UAAU,CAAC,aAAa,CAAC,CAAC;AAC3D,MAAM,MAAM,kBAAkB,GAAG,UAAU,CAAC,aAAa,CAAC,CAAC;AAE3D,MAAM,MAAM,uBAAuB,GAAG,UAAU,CAAC,yBAAyB,CAAC,CAAC;AAC5E,MAAM,MAAM,8BAA8B,GACxC,UAAU,CAAC,yBAAyB,CAAC,CAAC;AACxC,MAAM,MAAM,8BAA8B,GACxC,UAAU,CAAC,yBAAyB,CAAC,CAAC;AAExC,MAAM,MAAM,eAAe,GAAG,UAAU,CAAC,iBAAiB,CAAC,CAAC;AAC5D,MAAM,MAAM,sBAAsB,GAAG,UAAU,CAAC,iBAAiB,CAAC,CAAC;AACnE,MAAM,MAAM,sBAAsB,GAAG,UAAU,CAAC,iBAAiB,CAAC,CAAC"}
|
|
@@ -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;IAsB/C,aAAa,IAAI,mBAAmB,EAAE;CAGvC"}
|
|
@@ -0,0 +1,43 @@
|
|
|
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
|
+
// WRONG
|
|
22
|
+
jobId: uuidv4(),
|
|
23
|
+
// WRONG
|
|
24
|
+
opId: op.id || uuidv4(),
|
|
25
|
+
prevOpId: "", // Will be set during apply
|
|
26
|
+
documentId: this.documentId,
|
|
27
|
+
documentType: this.documentType,
|
|
28
|
+
scope: this.scope,
|
|
29
|
+
branch: this.branch,
|
|
30
|
+
timestampUtcMs: new Date(op.timestampUtcMs),
|
|
31
|
+
index: op.index,
|
|
32
|
+
action: JSON.stringify(op.action),
|
|
33
|
+
skip: op.skip,
|
|
34
|
+
error: op.error || null,
|
|
35
|
+
hash: op.hash,
|
|
36
|
+
});
|
|
37
|
+
}
|
|
38
|
+
}
|
|
39
|
+
getOperations() {
|
|
40
|
+
return this.operations;
|
|
41
|
+
}
|
|
42
|
+
}
|
|
43
|
+
//# 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,QAAQ;gBACR,KAAK,EAAE,MAAM,EAAE;gBACf,QAAQ;gBACR,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,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"}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import type { ISubscriptionErrorHandler, SubscriptionErrorContext } from "./types.js";
|
|
2
|
+
/**
|
|
3
|
+
* Default error handler that re-throws subscription errors.
|
|
4
|
+
* This ensures that errors are not silently swallowed.
|
|
5
|
+
*/
|
|
6
|
+
export declare class DefaultSubscriptionErrorHandler implements ISubscriptionErrorHandler {
|
|
7
|
+
handleError(error: unknown, context: SubscriptionErrorContext): void;
|
|
8
|
+
}
|
|
9
|
+
/**
|
|
10
|
+
* Creates a default subscription error handler instance
|
|
11
|
+
*/
|
|
12
|
+
export declare function createDefaultSubscriptionErrorHandler(): ISubscriptionErrorHandler;
|
|
13
|
+
//# sourceMappingURL=default-error-handler.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"default-error-handler.d.ts","sourceRoot":"","sources":["../../../src/subs/default-error-handler.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EACV,yBAAyB,EACzB,wBAAwB,EACzB,MAAM,YAAY,CAAC;AAEpB;;;GAGG;AACH,qBAAa,+BACX,YAAW,yBAAyB;IAEpC,WAAW,CAAC,KAAK,EAAE,OAAO,EAAE,OAAO,EAAE,wBAAwB,GAAG,IAAI;CAcrE;AAED;;GAEG;AACH,wBAAgB,qCAAqC,IAAI,yBAAyB,CAEjF"}
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Default error handler that re-throws subscription errors.
|
|
3
|
+
* This ensures that errors are not silently swallowed.
|
|
4
|
+
*/
|
|
5
|
+
export class DefaultSubscriptionErrorHandler {
|
|
6
|
+
handleError(error, context) {
|
|
7
|
+
const errorMessage = `Subscription error in ${context.eventType} (${context.subscriptionId})`;
|
|
8
|
+
if (error instanceof Error) {
|
|
9
|
+
// Preserve the original error with additional context
|
|
10
|
+
const enhancedError = new Error(`${errorMessage}: ${error.message}`);
|
|
11
|
+
enhancedError.cause = error;
|
|
12
|
+
enhancedError.stack = error.stack;
|
|
13
|
+
throw enhancedError;
|
|
14
|
+
}
|
|
15
|
+
else {
|
|
16
|
+
// Handle non-Error objects
|
|
17
|
+
throw new Error(`${errorMessage}: ${String(error)}`);
|
|
18
|
+
}
|
|
19
|
+
}
|
|
20
|
+
}
|
|
21
|
+
/**
|
|
22
|
+
* Creates a default subscription error handler instance
|
|
23
|
+
*/
|
|
24
|
+
export function createDefaultSubscriptionErrorHandler() {
|
|
25
|
+
return new DefaultSubscriptionErrorHandler();
|
|
26
|
+
}
|
|
27
|
+
//# sourceMappingURL=default-error-handler.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"default-error-handler.js","sourceRoot":"","sources":["../../../src/subs/default-error-handler.ts"],"names":[],"mappings":"AAKA;;;GAGG;AACH,MAAM,OAAO,+BAA+B;IAG1C,WAAW,CAAC,KAAc,EAAE,OAAiC;QAC3D,MAAM,YAAY,GAAG,yBAAyB,OAAO,CAAC,SAAS,KAAK,OAAO,CAAC,cAAc,GAAG,CAAC;QAE9F,IAAI,KAAK,YAAY,KAAK,EAAE,CAAC;YAC3B,sDAAsD;YACtD,MAAM,aAAa,GAAG,IAAI,KAAK,CAAC,GAAG,YAAY,KAAK,KAAK,CAAC,OAAO,EAAE,CAAC,CAAC;YACrE,aAAa,CAAC,KAAK,GAAG,KAAK,CAAC;YAC5B,aAAa,CAAC,KAAK,GAAG,KAAK,CAAC,KAAK,CAAC;YAClC,MAAM,aAAa,CAAC;QACtB,CAAC;aAAM,CAAC;YACN,2BAA2B;YAC3B,MAAM,IAAI,KAAK,CAAC,GAAG,YAAY,KAAK,MAAM,CAAC,KAAK,CAAC,EAAE,CAAC,CAAC;QACvD,CAAC;IACH,CAAC;CACF;AAED;;GAEG;AACH,MAAM,UAAU,qCAAqC;IACnD,OAAO,IAAI,+BAA+B,EAAE,CAAC;AAC/C,CAAC"}
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
import type { PHDocument } from "document-model";
|
|
2
|
+
import type { PagedResults, RelationshipChangeType, SearchFilter, ViewFilter } from "../shared/types.js";
|
|
3
|
+
import type { IReactorSubscriptionManager, ISubscriptionErrorHandler } from "./types.js";
|
|
4
|
+
type DocumentCreatedCallback = (result: PagedResults<string>) => void;
|
|
5
|
+
type DocumentDeletedCallback = (documentIds: string[]) => void;
|
|
6
|
+
type DocumentStateUpdatedCallback = (result: PagedResults<PHDocument>) => void;
|
|
7
|
+
type RelationshipChangedCallback = (parentId: string, childId: string, changeType: RelationshipChangeType) => void;
|
|
8
|
+
export declare class ReactorSubscriptionManager implements IReactorSubscriptionManager {
|
|
9
|
+
private createdSubscriptions;
|
|
10
|
+
private deletedSubscriptions;
|
|
11
|
+
private updatedSubscriptions;
|
|
12
|
+
private relationshipSubscriptions;
|
|
13
|
+
private subscriptionCounter;
|
|
14
|
+
private errorHandler;
|
|
15
|
+
constructor(errorHandler: ISubscriptionErrorHandler);
|
|
16
|
+
onDocumentCreated(callback: DocumentCreatedCallback, search?: SearchFilter): () => void;
|
|
17
|
+
onDocumentDeleted(callback: DocumentDeletedCallback, search?: SearchFilter): () => void;
|
|
18
|
+
onDocumentStateUpdated(callback: DocumentStateUpdatedCallback, search?: SearchFilter, view?: ViewFilter): () => void;
|
|
19
|
+
onRelationshipChanged(callback: RelationshipChangedCallback, search?: SearchFilter): () => void;
|
|
20
|
+
/**
|
|
21
|
+
* Notify subscribers about created documents
|
|
22
|
+
*/
|
|
23
|
+
notifyDocumentsCreated(documentIds: string[], documentTypes?: Map<string, string>, parentIds?: Map<string, string | null>): void;
|
|
24
|
+
/**
|
|
25
|
+
* Notify subscribers about deleted documents
|
|
26
|
+
*/
|
|
27
|
+
notifyDocumentsDeleted(documentIds: string[], documentTypes?: Map<string, string>, parentIds?: Map<string, string | null>): void;
|
|
28
|
+
/**
|
|
29
|
+
* Notify subscribers about updated documents
|
|
30
|
+
*/
|
|
31
|
+
notifyDocumentsUpdated(documents: PHDocument[]): void;
|
|
32
|
+
/**
|
|
33
|
+
* Notify subscribers about relationship changes
|
|
34
|
+
*/
|
|
35
|
+
notifyRelationshipChanged(parentId: string, childId: string, changeType: RelationshipChangeType, childType?: string): void;
|
|
36
|
+
/**
|
|
37
|
+
* Clear all subscriptions
|
|
38
|
+
*/
|
|
39
|
+
clearAll(): void;
|
|
40
|
+
private filterDocumentIds;
|
|
41
|
+
private filterDocuments;
|
|
42
|
+
private matchesRelationshipFilter;
|
|
43
|
+
}
|
|
44
|
+
export {};
|
|
45
|
+
//# sourceMappingURL=react-subscription-manager.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"react-subscription-manager.d.ts","sourceRoot":"","sources":["../../../src/subs/react-subscription-manager.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,gBAAgB,CAAC;AACjD,OAAO,KAAK,EACV,YAAY,EACZ,sBAAsB,EACtB,YAAY,EACZ,UAAU,EACX,MAAM,oBAAoB,CAAC;AAC5B,OAAO,KAAK,EACV,2BAA2B,EAC3B,yBAAyB,EAC1B,MAA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AI;IA+BP;;OAEG;IACH,sBAAsB,CACpB,WAAW,EAAE,MAAM,EAAE,EACrB,aAAa,CAAC,EAAE,GAAG,CAAC,MAAM,EAAE,MAAM,CAAC,EACnC,SAAS,CAAC,EAAE,GAAG,CAAC,MAAM,EAAE,MAAM,GAAG,IAAI,CAAC,GACrC,IAAI;IAuBP;;OAEG;IACH,sBAAsB,CAAC,SAAS,EAAE,UAAU,EAAE,GAAG,IAAI;IA0BrD;;OAEG;IACH,yBAAyB,CACvB,QAAQ,EAAE,MAAM,EAChB,OAAO,EAAE,MAAM,EACf,UAAU,EAAE,sBAAsB,EAClC,SAAS,CAAC,EAAE,MAAM,GACjB,IAAI;IAuBP;;OAEG;IACH,QAAQ,IAAI,IAAI;IAOhB,OAAO,CAAC,iBAAiB;IAyBzB,OAAO,CAAC,eAAe;IAevB,OAAO,CAAC,yBAAyB;CAclC"}
|
|
@@ -0,0 +1,185 @@
|
|
|
1
|
+
export class ReactorSubscriptionManager {
|
|
2
|
+
createdSubscriptions = new Map();
|
|
3
|
+
deletedSubscriptions = new Map();
|
|
4
|
+
updatedSubscriptions = new Map();
|
|
5
|
+
relationshipSubscriptions = new Map();
|
|
6
|
+
subscriptionCounter = 0;
|
|
7
|
+
errorHandler;
|
|
8
|
+
constructor(errorHandler) {
|
|
9
|
+
this.errorHandler = errorHandler;
|
|
10
|
+
}
|
|
11
|
+
onDocumentCreated(callback, search) {
|
|
12
|
+
const id = `created-${++this.subscriptionCounter}`;
|
|
13
|
+
this.createdSubscriptions.set(id, { id, callback, search });
|
|
14
|
+
return () => {
|
|
15
|
+
this.createdSubscriptions.delete(id);
|
|
16
|
+
};
|
|
17
|
+
}
|
|
18
|
+
onDocumentDeleted(callback, search) {
|
|
19
|
+
const id = `deleted-${++this.subscriptionCounter}`;
|
|
20
|
+
this.deletedSubscriptions.set(id, { id, callback, search });
|
|
21
|
+
return () => {
|
|
22
|
+
this.deletedSubscriptions.delete(id);
|
|
23
|
+
};
|
|
24
|
+
}
|
|
25
|
+
onDocumentStateUpdated(callback, search, view) {
|
|
26
|
+
const id = `updated-${++this.subscriptionCounter}`;
|
|
27
|
+
this.updatedSubscriptions.set(id, { id, callback, search, view });
|
|
28
|
+
return () => {
|
|
29
|
+
this.updatedSubscriptions.delete(id);
|
|
30
|
+
};
|
|
31
|
+
}
|
|
32
|
+
onRelationshipChanged(callback, search) {
|
|
33
|
+
const id = `relationship-${++this.subscriptionCounter}`;
|
|
34
|
+
this.relationshipSubscriptions.set(id, { id, callback, search });
|
|
35
|
+
return () => {
|
|
36
|
+
this.relationshipSubscriptions.delete(id);
|
|
37
|
+
};
|
|
38
|
+
}
|
|
39
|
+
/**
|
|
40
|
+
* Notify subscribers about created documents
|
|
41
|
+
*/
|
|
42
|
+
notifyDocumentsCreated(documentIds, documentTypes, parentIds) {
|
|
43
|
+
const result = {
|
|
44
|
+
results: documentIds,
|
|
45
|
+
options: { cursor: "", limit: documentIds.length },
|
|
46
|
+
};
|
|
47
|
+
for (const subscription of this.createdSubscriptions.values()) {
|
|
48
|
+
const filteredIds = this.filterDocumentIds(documentIds, subscription.search, documentTypes, parentIds);
|
|
49
|
+
if (filteredIds.length > 0) {
|
|
50
|
+
try {
|
|
51
|
+
subscription.callback({
|
|
52
|
+
...result,
|
|
53
|
+
results: filteredIds,
|
|
54
|
+
});
|
|
55
|
+
}
|
|
56
|
+
catch (error) {
|
|
57
|
+
this.errorHandler.handleError(error, {
|
|
58
|
+
eventType: "created",
|
|
59
|
+
subscriptionId: subscription.id,
|
|
60
|
+
eventData: filteredIds,
|
|
61
|
+
});
|
|
62
|
+
}
|
|
63
|
+
}
|
|
64
|
+
}
|
|
65
|
+
}
|
|
66
|
+
/**
|
|
67
|
+
* Notify subscribers about deleted documents
|
|
68
|
+
*/
|
|
69
|
+
notifyDocumentsDeleted(documentIds, documentTypes, parentIds) {
|
|
70
|
+
for (const subscription of this.deletedSubscriptions.values()) {
|
|
71
|
+
const filteredIds = this.filterDocumentIds(documentIds, subscription.search, documentTypes, parentIds);
|
|
72
|
+
if (filteredIds.length > 0) {
|
|
73
|
+
try {
|
|
74
|
+
subscription.callback(filteredIds);
|
|
75
|
+
}
|
|
76
|
+
catch (error) {
|
|
77
|
+
this.errorHandler.handleError(error, {
|
|
78
|
+
eventType: "deleted",
|
|
79
|
+
subscriptionId: subscription.id,
|
|
80
|
+
eventData: filteredIds,
|
|
81
|
+
});
|
|
82
|
+
}
|
|
83
|
+
}
|
|
84
|
+
}
|
|
85
|
+
}
|
|
86
|
+
/**
|
|
87
|
+
* Notify subscribers about updated documents
|
|
88
|
+
*/
|
|
89
|
+
notifyDocumentsUpdated(documents) {
|
|
90
|
+
const result = {
|
|
91
|
+
results: documents,
|
|
92
|
+
options: { cursor: "", limit: documents.length },
|
|
93
|
+
};
|
|
94
|
+
for (const subscription of this.updatedSubscriptions.values()) {
|
|
95
|
+
const filteredDocs = this.filterDocuments(documents, subscription.search);
|
|
96
|
+
if (filteredDocs.length > 0) {
|
|
97
|
+
try {
|
|
98
|
+
subscription.callback({
|
|
99
|
+
...result,
|
|
100
|
+
results: filteredDocs,
|
|
101
|
+
});
|
|
102
|
+
}
|
|
103
|
+
catch (error) {
|
|
104
|
+
this.errorHandler.handleError(error, {
|
|
105
|
+
eventType: "updated",
|
|
106
|
+
subscriptionId: subscription.id,
|
|
107
|
+
eventData: filteredDocs,
|
|
108
|
+
});
|
|
109
|
+
}
|
|
110
|
+
}
|
|
111
|
+
}
|
|
112
|
+
}
|
|
113
|
+
/**
|
|
114
|
+
* Notify subscribers about relationship changes
|
|
115
|
+
*/
|
|
116
|
+
notifyRelationshipChanged(parentId, childId, changeType, childType) {
|
|
117
|
+
for (const subscription of this.relationshipSubscriptions.values()) {
|
|
118
|
+
if (this.matchesRelationshipFilter(parentId, childId, childType, subscription.search)) {
|
|
119
|
+
try {
|
|
120
|
+
subscription.callback(parentId, childId, changeType);
|
|
121
|
+
}
|
|
122
|
+
catch (error) {
|
|
123
|
+
this.errorHandler.handleError(error, {
|
|
124
|
+
eventType: "relationshipChanged",
|
|
125
|
+
subscriptionId: subscription.id,
|
|
126
|
+
eventData: { parentId, childId, changeType },
|
|
127
|
+
});
|
|
128
|
+
}
|
|
129
|
+
}
|
|
130
|
+
}
|
|
131
|
+
}
|
|
132
|
+
/**
|
|
133
|
+
* Clear all subscriptions
|
|
134
|
+
*/
|
|
135
|
+
clearAll() {
|
|
136
|
+
this.createdSubscriptions.clear();
|
|
137
|
+
this.deletedSubscriptions.clear();
|
|
138
|
+
this.updatedSubscriptions.clear();
|
|
139
|
+
this.relationshipSubscriptions.clear();
|
|
140
|
+
}
|
|
141
|
+
filterDocumentIds(documentIds, search, documentTypes, parentIds) {
|
|
142
|
+
if (!search)
|
|
143
|
+
return documentIds;
|
|
144
|
+
return documentIds.filter((id) => {
|
|
145
|
+
if (search.ids && !search.ids.includes(id))
|
|
146
|
+
return false;
|
|
147
|
+
if (search.type && documentTypes) {
|
|
148
|
+
const docType = documentTypes.get(id);
|
|
149
|
+
if (docType !== search.type)
|
|
150
|
+
return false;
|
|
151
|
+
}
|
|
152
|
+
if (search.parentId && parentIds) {
|
|
153
|
+
const parentId = parentIds.get(id);
|
|
154
|
+
if (parentId !== search.parentId)
|
|
155
|
+
return false;
|
|
156
|
+
}
|
|
157
|
+
return true;
|
|
158
|
+
});
|
|
159
|
+
}
|
|
160
|
+
filterDocuments(documents, search) {
|
|
161
|
+
if (!search)
|
|
162
|
+
return documents;
|
|
163
|
+
return documents.filter((doc) => {
|
|
164
|
+
if (search.ids && !search.ids.includes(doc.header.id))
|
|
165
|
+
return false;
|
|
166
|
+
if (search.type && doc.header.documentType !== search.type)
|
|
167
|
+
return false;
|
|
168
|
+
if (search.slugs && !search.slugs.includes(doc.header.slug))
|
|
169
|
+
return false;
|
|
170
|
+
return true;
|
|
171
|
+
});
|
|
172
|
+
}
|
|
173
|
+
matchesRelationshipFilter(parentId, childId, childType, search) {
|
|
174
|
+
if (!search)
|
|
175
|
+
return true;
|
|
176
|
+
if (search.parentId && parentId !== search.parentId)
|
|
177
|
+
return false;
|
|
178
|
+
if (search.ids && !search.ids.includes(childId))
|
|
179
|
+
return false;
|
|
180
|
+
if (search.type && childType && childType !== search.type)
|
|
181
|
+
return false;
|
|
182
|
+
return true;
|
|
183
|
+
}
|
|
184
|
+
}
|
|
185
|
+
//# sourceMappingURL=react-subscription-manager.js.map
|