@powerhousedao/powerhouse-vetra-packages 6.2.3-dev.44 → 6.2.3-dev.46
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.
|
@@ -1,7 +1,102 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import { n as
|
|
1
|
+
import { A as CollectionMembershipCache, _ as KyselyOperationIndex, d as instrumentPgPool, f as KyselyOperationStore, g as KyselyWriteCache, h as EventBus, i as errorToInfo, k as DocumentMetaCache, kt as ReactorEventTypes, m as DocumentModelRegistry, n as loadDocumentModelSpec, p as KyselyKeyframeStore, r as createForwardingLogger, s as REACTOR_SCHEMA, t as defaultLoadFactory } from "./load-spec-f2ppXyKZ.js";
|
|
2
|
+
import { a as KyselyExecutionScope, n as SimpleJobExecutor, t as DEFAULT_DRIVE_CONTAINER_TYPES } from "./drive-container-types-CifLQjd3.js";
|
|
3
3
|
import { ConsoleLogger } from "document-model";
|
|
4
4
|
import { isMainThread, parentPort } from "node:worker_threads";
|
|
5
|
+
//#region src/executor/worker/build-worker-executor.ts
|
|
6
|
+
async function loadModelManifest(entries, loadFactory, registry, logger) {
|
|
7
|
+
for (const entry of entries) {
|
|
8
|
+
let module;
|
|
9
|
+
try {
|
|
10
|
+
module = await loadFactory(entry.spec);
|
|
11
|
+
} catch (error) {
|
|
12
|
+
logger.error("worker failed to load document model: @entry @error", entry, error);
|
|
13
|
+
throw error;
|
|
14
|
+
}
|
|
15
|
+
const [result] = registry.registerModules(module);
|
|
16
|
+
if (result.status === "error") {
|
|
17
|
+
logger.error("worker failed to register document model: @entry @error", entry, result.error);
|
|
18
|
+
throw result.error;
|
|
19
|
+
}
|
|
20
|
+
}
|
|
21
|
+
}
|
|
22
|
+
/**
|
|
23
|
+
* Assembles the in-worker storage stack plus a {@link SimpleJobExecutor}
|
|
24
|
+
* bound to a pre-built Kysely instance. The parent owns the wire protocol
|
|
25
|
+
* and routing; the worker owns everything below `SimpleJobExecutor`.
|
|
26
|
+
*
|
|
27
|
+
* The local event bus exists only to satisfy the executor's contract: its
|
|
28
|
+
* JOB_WRITE_READY emissions are captured here and shipped to the parent
|
|
29
|
+
* via {@link WorkerExecutorStack.takeLastWriteReady}.
|
|
30
|
+
*/
|
|
31
|
+
async function buildWorkerExecutor(options) {
|
|
32
|
+
const { init, database: baseDatabase, logger } = options;
|
|
33
|
+
const driveContainerTypes = options.driveContainerTypes ?? DEFAULT_DRIVE_CONTAINER_TYPES;
|
|
34
|
+
const loadFactory = options.loadFactory ?? defaultLoadFactory;
|
|
35
|
+
const registry = new DocumentModelRegistry();
|
|
36
|
+
await loadModelManifest(init.models, loadFactory, registry, logger);
|
|
37
|
+
let signer;
|
|
38
|
+
if (init.signer) try {
|
|
39
|
+
signer = await loadFactory(init.signer);
|
|
40
|
+
} catch (error) {
|
|
41
|
+
logger.error("worker failed to load signer: @spec @error", init.signer.module, error);
|
|
42
|
+
throw error;
|
|
43
|
+
}
|
|
44
|
+
let trustPolicy;
|
|
45
|
+
if (init.trustPolicy) try {
|
|
46
|
+
trustPolicy = await loadFactory(init.trustPolicy);
|
|
47
|
+
} catch (error) {
|
|
48
|
+
logger.error("worker failed to load trust policy: @spec @error", init.trustPolicy.module, error);
|
|
49
|
+
throw error;
|
|
50
|
+
}
|
|
51
|
+
const database = baseDatabase.withSchema(REACTOR_SCHEMA);
|
|
52
|
+
const operationStore = new KyselyOperationStore(database);
|
|
53
|
+
const keyframeStore = new KyselyKeyframeStore(database);
|
|
54
|
+
const writeCache = new KyselyWriteCache(keyframeStore, operationStore, registry, {
|
|
55
|
+
maxDocuments: 100,
|
|
56
|
+
ringBufferSize: 10,
|
|
57
|
+
keyframeInterval: 10
|
|
58
|
+
});
|
|
59
|
+
await writeCache.startup();
|
|
60
|
+
const operationIndex = new KyselyOperationIndex(database);
|
|
61
|
+
const documentMetaCache = new DocumentMetaCache(operationStore, { maxDocuments: 1e3 });
|
|
62
|
+
await documentMetaCache.startup();
|
|
63
|
+
const collectionMembershipCache = new CollectionMembershipCache(operationIndex);
|
|
64
|
+
const executionScope = new KyselyExecutionScope(database, operationStore, operationIndex, keyframeStore, writeCache, documentMetaCache, collectionMembershipCache);
|
|
65
|
+
const eventBus = new EventBus();
|
|
66
|
+
let lastWriteReady = null;
|
|
67
|
+
eventBus.subscribe(ReactorEventTypes.JOB_WRITE_READY, (_t, event) => {
|
|
68
|
+
lastWriteReady = {
|
|
69
|
+
operations: event.operations,
|
|
70
|
+
jobMeta: event.jobMeta
|
|
71
|
+
};
|
|
72
|
+
});
|
|
73
|
+
let signatureRefusals = [];
|
|
74
|
+
eventBus.subscribe(ReactorEventTypes.SIGNATURE_REFUSED, (_t, event) => {
|
|
75
|
+
signatureRefusals.push(event);
|
|
76
|
+
});
|
|
77
|
+
const executorConfig = options.executorConfig ?? {};
|
|
78
|
+
return {
|
|
79
|
+
executor: new SimpleJobExecutor(logger, registry, operationStore, eventBus, writeCache, operationIndex, documentMetaCache, collectionMembershipCache, driveContainerTypes, executorConfig, executionScope, signer, trustPolicy),
|
|
80
|
+
registry,
|
|
81
|
+
takeLastWriteReady() {
|
|
82
|
+
const captured = lastWriteReady;
|
|
83
|
+
lastWriteReady = null;
|
|
84
|
+
return captured;
|
|
85
|
+
},
|
|
86
|
+
takeSignatureRefusals() {
|
|
87
|
+
const captured = signatureRefusals;
|
|
88
|
+
signatureRefusals = [];
|
|
89
|
+
return captured;
|
|
90
|
+
},
|
|
91
|
+
evictPurged(documentIds) {
|
|
92
|
+
for (const documentId of documentIds) {
|
|
93
|
+
writeCache.invalidate(documentId);
|
|
94
|
+
documentMetaCache.invalidate(documentId);
|
|
95
|
+
}
|
|
96
|
+
}
|
|
97
|
+
};
|
|
98
|
+
}
|
|
99
|
+
//#endregion
|
|
5
100
|
//#region src/executor/worker/run-worker.ts
|
|
6
101
|
const POOL_SAMPLE_INTERVAL_MS = 1e3;
|
|
7
102
|
async function defaultCreateDatabase(config, workerId) {
|
|
@@ -50,6 +145,7 @@ function runWorker(parentPort, overrides = {}) {
|
|
|
50
145
|
let pendingPoolSamples = [];
|
|
51
146
|
let detachPoolListener = null;
|
|
52
147
|
const activeLoadFactory = overrides.loadFactory ?? defaultLoadFactory;
|
|
148
|
+
const loadModelSpec = overrides.loadFactory ? async (spec) => await activeLoadFactory(spec) : loadDocumentModelSpec;
|
|
53
149
|
function post(msg) {
|
|
54
150
|
parentPort.postMessage(msg);
|
|
55
151
|
}
|
|
@@ -182,7 +278,7 @@ function runWorker(parentPort, overrides = {}) {
|
|
|
182
278
|
}
|
|
183
279
|
let module;
|
|
184
280
|
try {
|
|
185
|
-
module = await
|
|
281
|
+
module = await loadModelSpec(msg.model.spec);
|
|
186
282
|
} catch (error) {
|
|
187
283
|
post({
|
|
188
284
|
type: "model-load-failed",
|
|
@@ -1,6 +1,5 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import { a as KyselyDocumentView, c as ReadModelCoordinator, f as BaseReadModel, n as ConsistencyTracker, t as KyselyDocumentIndexer, y as CatchUpScheduler } from "./document-indexer-
|
|
3
|
-
import { n as defaultLoadFactory } from "./build-worker-executor-Bonu2jUB.js";
|
|
1
|
+
import { A as CollectionMembershipCache, T as createKyselyWatermarkProbe, _ as KyselyOperationIndex, d as instrumentPgPool, f as KyselyOperationStore, g as KyselyWriteCache, h as EventBus, i as errorToInfo, k as DocumentMetaCache, kt as ReactorEventTypes, m as DocumentModelRegistry, p as KyselyKeyframeStore, r as createForwardingLogger, s as REACTOR_SCHEMA, t as defaultLoadFactory, w as SettledWatermark, x as findPurged } from "./load-spec-f2ppXyKZ.js";
|
|
2
|
+
import { a as KyselyDocumentView, c as ReadModelCoordinator, f as BaseReadModel, n as ConsistencyTracker, t as KyselyDocumentIndexer, y as CatchUpScheduler } from "./document-indexer-lfgXu9ph.js";
|
|
4
3
|
import { isPurgeMarker } from "@powerhousedao/shared/document-model";
|
|
5
4
|
import { ConsoleLogger } from "document-model";
|
|
6
5
|
import { isMainThread, parentPort } from "node:worker_threads";
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@powerhousedao/powerhouse-vetra-packages",
|
|
3
|
-
"version": "6.2.3-dev.
|
|
3
|
+
"version": "6.2.3-dev.46",
|
|
4
4
|
"description": "",
|
|
5
5
|
"keywords": [],
|
|
6
6
|
"author": "",
|
|
@@ -81,12 +81,12 @@
|
|
|
81
81
|
"@codemirror/view": "6.36.7",
|
|
82
82
|
"@graphql-tools/utils": "11.0.0",
|
|
83
83
|
"@hookform/resolvers": "^5.0.1",
|
|
84
|
-
"@powerhousedao/design-system": "6.2.3-dev.
|
|
84
|
+
"@powerhousedao/design-system": "6.2.3-dev.46",
|
|
85
85
|
"@powerhousedao/document-engineering": "1.40.5",
|
|
86
|
-
"@powerhousedao/reactor-browser": "6.2.3-dev.
|
|
87
|
-
"@powerhousedao/reactor-drive": "6.2.3-dev.
|
|
88
|
-
"@powerhousedao/reactor-group": "6.2.3-dev.
|
|
89
|
-
"@powerhousedao/shared": "6.2.3-dev.
|
|
86
|
+
"@powerhousedao/reactor-browser": "6.2.3-dev.46",
|
|
87
|
+
"@powerhousedao/reactor-drive": "6.2.3-dev.46",
|
|
88
|
+
"@powerhousedao/reactor-group": "6.2.3-dev.46",
|
|
89
|
+
"@powerhousedao/shared": "6.2.3-dev.46",
|
|
90
90
|
"@radix-ui/react-label": "^2.1.4",
|
|
91
91
|
"@radix-ui/react-slot": "^1.2.0",
|
|
92
92
|
"@radix-ui/react-tabs": "^1.1.9",
|
|
@@ -98,7 +98,7 @@
|
|
|
98
98
|
"class-variance-authority": "0.7.0",
|
|
99
99
|
"clsx": "^2.1.1",
|
|
100
100
|
"cm6-graphql": "^0.2.1",
|
|
101
|
-
"document-model": "6.2.3-dev.
|
|
101
|
+
"document-model": "6.2.3-dev.46",
|
|
102
102
|
"graphql": "^16",
|
|
103
103
|
"react": "19.2.6",
|
|
104
104
|
"react-dom": "19.2.6",
|