@powerhousedao/reactor 6.2.0-dev.16 → 6.2.0-dev.17
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/{build-worker-executor-BqNFZX3J.js → build-worker-executor-DeJ2DW16.js} +2 -2
- package/dist/{build-worker-executor-BqNFZX3J.js.map → build-worker-executor-DeJ2DW16.js.map} +1 -1
- package/dist/{drive-container-types-CAhznKRr.js → drive-container-types-BxnXaOAp.js} +47 -8
- package/dist/drive-container-types-BxnXaOAp.js.map +1 -0
- package/dist/entry.js +2 -2
- package/dist/index.d.ts +53 -11
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +20 -12
- package/dist/index.js.map +1 -1
- package/dist/projection-entry.js +2 -2
- package/dist/{worker-Dq6cUr6a.js → worker-XYrQaEmt.js} +2 -2
- package/dist/{worker-Dq6cUr6a.js.map → worker-XYrQaEmt.js.map} +1 -1
- package/package.json +4 -4
- package/dist/drive-container-types-CAhznKRr.js.map +0 -1
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { S as CollectionMembershipCache, _ as KyselyWriteCache, d as KyselyKeyframeStore, f as DocumentModelRegistry, g as EventBus, h as KyselyExecutionScope, n as REACTOR_SCHEMA, p as SimpleJobExecutor, s as KyselyOperationStore, t as DEFAULT_DRIVE_CONTAINER_TYPES, v as KyselyOperationIndex, y as DocumentMetaCache } from "./drive-container-types-
|
|
1
|
+
import { S as CollectionMembershipCache, _ as KyselyWriteCache, d as KyselyKeyframeStore, f as DocumentModelRegistry, g as EventBus, h as KyselyExecutionScope, n as REACTOR_SCHEMA, p as SimpleJobExecutor, s as KyselyOperationStore, t as DEFAULT_DRIVE_CONTAINER_TYPES, v as KyselyOperationIndex, y as DocumentMetaCache } from "./drive-container-types-BxnXaOAp.js";
|
|
2
2
|
import { n as ReactorEventTypes } from "./types-CxSpmNGK.js";
|
|
3
3
|
//#region src/executor/worker/build-worker-executor.ts
|
|
4
4
|
async function defaultLoadFactory(spec) {
|
|
@@ -80,4 +80,4 @@ async function buildWorkerExecutor(options) {
|
|
|
80
80
|
//#endregion
|
|
81
81
|
export { defaultLoadFactory as n, buildWorkerExecutor as t };
|
|
82
82
|
|
|
83
|
-
//# sourceMappingURL=build-worker-executor-
|
|
83
|
+
//# sourceMappingURL=build-worker-executor-DeJ2DW16.js.map
|
package/dist/{build-worker-executor-BqNFZX3J.js.map → build-worker-executor-DeJ2DW16.js.map}
RENAMED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"build-worker-executor-
|
|
1
|
+
{"version":3,"file":"build-worker-executor-DeJ2DW16.js","names":[],"sources":["../src/executor/worker/build-worker-executor.ts"],"sourcesContent":["import type {\n DocumentModelModule,\n OperationWithContext,\n} from \"@powerhousedao/shared/document-model\";\nimport type { ILogger } from \"document-model\";\nimport type { Kysely } from \"kysely\";\nimport { CollectionMembershipCache } from \"../../cache/collection-membership-cache.js\";\nimport { DocumentMetaCache } from \"../../cache/document-meta-cache.js\";\nimport { KyselyOperationIndex } from \"../../cache/kysely-operation-index.js\";\nimport { KyselyWriteCache } from \"../../cache/kysely-write-cache.js\";\nimport type { WriteCacheConfig } from \"../../cache/write-cache-types.js\";\nimport { DEFAULT_DRIVE_CONTAINER_TYPES } from \"../../core/drive-container-types.js\";\nimport type { Database } from \"../../core/types.js\";\nimport { EventBus } from \"../../events/event-bus.js\";\nimport {\n ReactorEventTypes,\n type JobWriteReadyEvent,\n} from \"../../events/types.js\";\nimport { DocumentModelRegistry } from \"../../registry/implementation.js\";\nimport type { JobMeta } from \"../../shared/types.js\";\nimport type { SignatureVerificationHandler } from \"../../signer/types.js\";\nimport { KyselyKeyframeStore } from \"../../storage/kysely/keyframe-store.js\";\nimport { KyselyOperationStore } from \"../../storage/kysely/store.js\";\nimport type { Database as StorageDatabase } from \"../../storage/kysely/types.js\";\nimport { REACTOR_SCHEMA } from \"../../storage/migrations/migrator.js\";\nimport { KyselyExecutionScope } from \"../execution-scope.js\";\nimport { SimpleJobExecutor } from \"../simple-job-executor.js\";\nimport type { JobExecutorConfig } from \"../types.js\";\nimport type {\n FactorySpec,\n InitMessage,\n ModelManifestEntry,\n} from \"./protocol.js\";\n\n/**\n * In-worker capture of the JOB_WRITE_READY event emitted by the executor.\n * The worker forwards `operations` and `jobMeta` back to the parent; the\n * parent re-enriches `collectionMemberships` at emit time.\n */\nexport type WorkerWriteReadyCapture = {\n operations: OperationWithContext[];\n jobMeta: JobMeta;\n};\n\nexport type WorkerExecutorStack = {\n executor: SimpleJobExecutor;\n registry: DocumentModelRegistry;\n /**\n * Synchronously pops the most-recent JOB_WRITE_READY captured on this\n * worker's local event bus and clears it. Returns null if the executor\n * did not produce one for this job.\n */\n takeLastWriteReady(): WorkerWriteReadyCapture | null;\n};\n\nexport type BuildWorkerExecutorOptions = {\n init: InitMessage;\n database: Kysely<Database>;\n logger: ILogger;\n executorConfig?: JobExecutorConfig;\n driveContainerTypes?: ReadonlySet<string>;\n /**\n * Override the module loader used to materialize factory specs. Tests\n * can inject a deterministic resolver instead of touching the real\n * Node module loader.\n */\n loadFactory?: (spec: FactorySpec) => Promise<unknown>;\n};\n\nexport async function defaultLoadFactory(spec: FactorySpec): Promise<unknown> {\n const ref = spec.module;\n const specifier =\n \"filePath\" in ref\n ? new URL(`file://${ref.filePath}`).href\n : ref.packageName;\n const mod = (await import(specifier)) as Record<string, unknown>;\n const exported = mod[ref.exportName];\n if (typeof exported === \"function\") {\n return (exported as (args: unknown) => unknown)(spec.initArgs);\n }\n return exported;\n}\n\nasync function loadModelManifest(\n entries: ModelManifestEntry[],\n loadFactory: (spec: FactorySpec) => Promise<unknown>,\n registry: DocumentModelRegistry,\n logger: ILogger,\n): Promise<void> {\n for (const entry of entries) {\n let module: DocumentModelModule;\n try {\n module = (await loadFactory(entry.spec)) as DocumentModelModule;\n } catch (error) {\n logger.error(\n \"worker failed to load document model: @entry @error\",\n entry,\n error,\n );\n throw error;\n }\n const [result] = registry.registerModules(module);\n if (result.status === \"error\") {\n logger.error(\n \"worker failed to register document model: @entry @error\",\n entry,\n result.error,\n );\n throw result.error;\n }\n }\n}\n\n/**\n * Assembles the in-worker storage stack plus a {@link SimpleJobExecutor}\n * bound to a pre-built Kysely instance. The parent owns the wire protocol\n * and routing; the worker owns everything below `SimpleJobExecutor`.\n *\n * The local event bus exists only to satisfy the executor's contract: its\n * JOB_WRITE_READY emissions are captured here and shipped to the parent\n * via {@link WorkerExecutorStack.takeLastWriteReady}.\n */\nexport async function buildWorkerExecutor(\n options: BuildWorkerExecutorOptions,\n): Promise<WorkerExecutorStack> {\n const { init, database: baseDatabase, logger } = options;\n const driveContainerTypes =\n options.driveContainerTypes ?? DEFAULT_DRIVE_CONTAINER_TYPES;\n const loadFactory = options.loadFactory ?? defaultLoadFactory;\n\n const registry = new DocumentModelRegistry();\n await loadModelManifest(init.models, loadFactory, registry, logger);\n\n let signatureVerifier: SignatureVerificationHandler | undefined;\n try {\n signatureVerifier = (await loadFactory(\n init.signatureVerifier,\n )) as SignatureVerificationHandler;\n } catch (error) {\n logger.error(\n \"worker failed to load signature verifier: @spec @error\",\n init.signatureVerifier,\n error,\n );\n throw error;\n }\n\n const database = baseDatabase.withSchema(REACTOR_SCHEMA);\n const operationStore = new KyselyOperationStore(\n database as unknown as Kysely<StorageDatabase>,\n );\n const keyframeStore = new KyselyKeyframeStore(\n database as unknown as Kysely<StorageDatabase>,\n );\n\n const cacheConfig: WriteCacheConfig = {\n maxDocuments: 100,\n ringBufferSize: 10,\n keyframeInterval: 10,\n };\n const writeCache = new KyselyWriteCache(\n keyframeStore,\n operationStore,\n registry,\n cacheConfig,\n );\n await writeCache.startup();\n\n const operationIndex = new KyselyOperationIndex(\n database as unknown as Kysely<StorageDatabase>,\n );\n\n const documentMetaCache = new DocumentMetaCache(operationStore, {\n maxDocuments: 1000,\n });\n await documentMetaCache.startup();\n\n const collectionMembershipCache = new CollectionMembershipCache(\n operationIndex,\n );\n\n const executionScope = new KyselyExecutionScope(\n database as unknown as Kysely<StorageDatabase>,\n operationStore,\n operationIndex,\n keyframeStore,\n writeCache,\n documentMetaCache,\n collectionMembershipCache,\n );\n\n const eventBus = new EventBus();\n let lastWriteReady: WorkerWriteReadyCapture | null = null;\n eventBus.subscribe(\n ReactorEventTypes.JOB_WRITE_READY,\n (_t: number, event: JobWriteReadyEvent) => {\n lastWriteReady = {\n operations: event.operations,\n jobMeta: event.jobMeta,\n };\n },\n );\n\n const executorConfig = options.executorConfig ?? {};\n const executor = new SimpleJobExecutor(\n logger,\n registry,\n operationStore,\n eventBus,\n writeCache,\n operationIndex,\n documentMetaCache,\n collectionMembershipCache,\n driveContainerTypes,\n executorConfig,\n signatureVerifier,\n executionScope,\n );\n\n return {\n executor,\n registry,\n takeLastWriteReady(): WorkerWriteReadyCapture | null {\n const captured = lastWriteReady;\n lastWriteReady = null;\n return captured;\n },\n };\n}\n"],"mappings":";;;AAqEA,eAAsB,mBAAmB,MAAqC;CAC5E,MAAM,MAAM,KAAK;CAMjB,MAAM,YADO,OAHX,cAAc,MAAA,OACV,IAAI,IAAI,UAAU,IAAI,WAAW,CAAC,QAAA,OAClC,IAAI,eAEW,IAAI;AACzB,KAAI,OAAO,aAAa,WACtB,QAAQ,SAAwC,KAAK,SAAS;AAEhE,QAAO;;AAGT,eAAe,kBACb,SACA,aACA,UACA,QACe;AACf,MAAK,MAAM,SAAS,SAAS;EAC3B,IAAI;AACJ,MAAI;AACF,YAAU,MAAM,YAAY,MAAM,KAAK;WAChC,OAAO;AACd,UAAO,MACL,uDACA,OACA,MACD;AACD,SAAM;;EAER,MAAM,CAAC,UAAU,SAAS,gBAAgB,OAAO;AACjD,MAAI,OAAO,WAAW,SAAS;AAC7B,UAAO,MACL,2DACA,OACA,OAAO,MACR;AACD,SAAM,OAAO;;;;;;;;;;;;;AAcnB,eAAsB,oBACpB,SAC8B;CAC9B,MAAM,EAAE,MAAM,UAAU,cAAc,WAAW;CACjD,MAAM,sBACJ,QAAQ,uBAAuB;CACjC,MAAM,cAAc,QAAQ,eAAe;CAE3C,MAAM,WAAW,IAAI,uBAAuB;AAC5C,OAAM,kBAAkB,KAAK,QAAQ,aAAa,UAAU,OAAO;CAEnE,IAAI;AACJ,KAAI;AACF,sBAAqB,MAAM,YACzB,KAAK,kBACN;UACM,OAAO;AACd,SAAO,MACL,0DACA,KAAK,mBACL,MACD;AACD,QAAM;;CAGR,MAAM,WAAW,aAAa,WAAW,eAAe;CACxD,MAAM,iBAAiB,IAAI,qBACzB,SACD;CACD,MAAM,gBAAgB,IAAI,oBACxB,SACD;CAOD,MAAM,aAAa,IAAI,iBACrB,eACA,gBACA,UARoC;EACpC,cAAc;EACd,gBAAgB;EAChB,kBAAkB;EACnB,CAMA;AACD,OAAM,WAAW,SAAS;CAE1B,MAAM,iBAAiB,IAAI,qBACzB,SACD;CAED,MAAM,oBAAoB,IAAI,kBAAkB,gBAAgB,EAC9D,cAAc,KACf,CAAC;AACF,OAAM,kBAAkB,SAAS;CAEjC,MAAM,4BAA4B,IAAI,0BACpC,eACD;CAED,MAAM,iBAAiB,IAAI,qBACzB,UACA,gBACA,gBACA,eACA,YACA,mBACA,0BACD;CAED,MAAM,WAAW,IAAI,UAAU;CAC/B,IAAI,iBAAiD;AACrD,UAAS,UACP,kBAAkB,kBACjB,IAAY,UAA8B;AACzC,mBAAiB;GACf,YAAY,MAAM;GAClB,SAAS,MAAM;GAChB;GAEJ;AAkBD,QAAO;EACL,UAhBe,IAAI,kBACnB,QACA,UACA,gBACA,UACA,YACA,gBACA,mBACA,2BACA,qBAVqB,QAAQ,kBAAkB,EAAE,EAYjD,mBACA,eACD;EAIC;EACA,qBAAqD;GACnD,MAAM,WAAW;AACjB,oBAAiB;AACjB,UAAO;;EAEV"}
|
|
@@ -1441,9 +1441,48 @@ function reshuffleByTimestamp(startIndex, opsA, opsB) {
|
|
|
1441
1441
|
}
|
|
1442
1442
|
//#endregion
|
|
1443
1443
|
//#region src/cache/operation-index-types.ts
|
|
1444
|
-
|
|
1445
|
-
|
|
1446
|
-
|
|
1444
|
+
const DRIVE_COLLECTION_PREFIX = "drive.";
|
|
1445
|
+
/**
|
|
1446
|
+
* Identifies the collection a remote synchronizes. Collections are drive-level
|
|
1447
|
+
* abstractions (document-drive and reactor-drive), so a collection id is the
|
|
1448
|
+
* drive document id plus the branch it scopes to rather than an opaque string.
|
|
1449
|
+
*
|
|
1450
|
+
* The canonical string form (`drive.${branch}.${driveId}`) is produced only by
|
|
1451
|
+
* `key` and parsed only by `fromKey`; that string is the wire and storage
|
|
1452
|
+
* representation and is byte-for-byte identical to the legacy
|
|
1453
|
+
* `driveCollectionId(branch, driveId)` output, so existing `document_collections`
|
|
1454
|
+
* rows and persisted remotes remain valid without migration.
|
|
1455
|
+
*/
|
|
1456
|
+
var DriveCollectionId = class DriveCollectionId {
|
|
1457
|
+
constructor(driveId, branch) {
|
|
1458
|
+
this.driveId = driveId;
|
|
1459
|
+
this.branch = branch;
|
|
1460
|
+
}
|
|
1461
|
+
static forDrive(driveId, branch = "main") {
|
|
1462
|
+
return new DriveCollectionId(driveId, branch);
|
|
1463
|
+
}
|
|
1464
|
+
/**
|
|
1465
|
+
* The single deserializer for the wire/storage form. `branch` may contain
|
|
1466
|
+
* dots, while `driveId` is a dot-free document id, so the drive id is the
|
|
1467
|
+
* final dot-delimited segment.
|
|
1468
|
+
*/
|
|
1469
|
+
static fromKey(key) {
|
|
1470
|
+
if (!key.startsWith(DRIVE_COLLECTION_PREFIX)) throw new Error(`Unsupported collection id: ${key}`);
|
|
1471
|
+
const rest = key.slice(6);
|
|
1472
|
+
const lastDot = rest.lastIndexOf(".");
|
|
1473
|
+
if (lastDot === -1 || lastDot === rest.length - 1) throw new Error(`Malformed drive collection id: ${key}`);
|
|
1474
|
+
return new DriveCollectionId(rest.slice(lastDot + 1), rest.slice(0, lastDot));
|
|
1475
|
+
}
|
|
1476
|
+
get key() {
|
|
1477
|
+
return `${DRIVE_COLLECTION_PREFIX}${this.branch}.${this.driveId}`;
|
|
1478
|
+
}
|
|
1479
|
+
toString() {
|
|
1480
|
+
return this.key;
|
|
1481
|
+
}
|
|
1482
|
+
equals(other) {
|
|
1483
|
+
return this.driveId === other.driveId && this.branch === other.branch;
|
|
1484
|
+
}
|
|
1485
|
+
};
|
|
1447
1486
|
//#endregion
|
|
1448
1487
|
//#region src/executor/document-action-handler.ts
|
|
1449
1488
|
var DocumentActionHandler = class {
|
|
@@ -1499,7 +1538,7 @@ var DocumentActionHandler = class {
|
|
|
1499
1538
|
sourceRemote
|
|
1500
1539
|
}]);
|
|
1501
1540
|
if (this.driveContainerTypes.has(document.header.documentType)) {
|
|
1502
|
-
const collectionId =
|
|
1541
|
+
const collectionId = DriveCollectionId.forDrive(document.header.id, job.branch).key;
|
|
1503
1542
|
indexTxn.createCollection(collectionId);
|
|
1504
1543
|
indexTxn.addToCollection(collectionId, document.header.id);
|
|
1505
1544
|
}
|
|
@@ -1627,7 +1666,7 @@ var DocumentActionHandler = class {
|
|
|
1627
1666
|
executeAddRelationship(job, action, startTime, indexTxn, stores, sourceRemote = "", signal) {
|
|
1628
1667
|
return this.withRelationshipAction("ADD_RELATIONSHIP", job, action, startTime, indexTxn, stores, sourceRemote, signal, (input) => input.sourceId === input.targetId ? /* @__PURE__ */ new Error("ADD_RELATIONSHIP: sourceId and targetId cannot be the same (self-relationships not allowed)") : null, ({ indexTxn: txn, stores: s, sourceDoc, input, job: j }) => {
|
|
1629
1668
|
if (this.driveContainerTypes.has(sourceDoc.header.documentType)) {
|
|
1630
|
-
const collectionId =
|
|
1669
|
+
const collectionId = DriveCollectionId.forDrive(input.sourceId, j.branch).key;
|
|
1631
1670
|
txn.addToCollection(collectionId, input.targetId);
|
|
1632
1671
|
s.collectionMembershipCache.invalidate(input.targetId);
|
|
1633
1672
|
}
|
|
@@ -1636,7 +1675,7 @@ var DocumentActionHandler = class {
|
|
|
1636
1675
|
executeRemoveRelationship(job, action, startTime, indexTxn, stores, sourceRemote = "", signal) {
|
|
1637
1676
|
return this.withRelationshipAction("REMOVE_RELATIONSHIP", job, action, startTime, indexTxn, stores, sourceRemote, signal, null, ({ indexTxn: txn, stores: s, sourceDoc, input, job: j }) => {
|
|
1638
1677
|
if (this.driveContainerTypes.has(sourceDoc.header.documentType)) {
|
|
1639
|
-
const collectionId =
|
|
1678
|
+
const collectionId = DriveCollectionId.forDrive(input.sourceId, j.branch).key;
|
|
1640
1679
|
txn.removeFromCollection(collectionId, input.targetId);
|
|
1641
1680
|
s.collectionMembershipCache.invalidate(input.targetId);
|
|
1642
1681
|
}
|
|
@@ -2944,6 +2983,6 @@ async function getMigrationStatus(db, schema = REACTOR_SCHEMA) {
|
|
|
2944
2983
|
//#region src/core/drive-container-types.ts
|
|
2945
2984
|
const DEFAULT_DRIVE_CONTAINER_TYPES = new Set(["powerhouse/document-drive", "powerhouse/reactor-drive"]);
|
|
2946
2985
|
//#endregion
|
|
2947
|
-
export { parsePagingOptions as A, DuplicateManifestError as C, DocumentDeletedError as D, ModuleNotFoundError as E, __exportAll as M, DocumentNotFoundError as O, CollectionMembershipCache as S, InvalidModuleError as T, KyselyWriteCache as _, createForwardingPoolInstrumentation as a, createConsistencyToken as b, DuplicateOperationError as c, KyselyKeyframeStore as d, DocumentModelRegistry as f, EventBus as g, KyselyExecutionScope as h, runMigrations as i, throwIfAborted as j, matchesScope as k, OptimisticLockError as l,
|
|
2986
|
+
export { parsePagingOptions as A, DuplicateManifestError as C, DocumentDeletedError as D, ModuleNotFoundError as E, __exportAll as M, DocumentNotFoundError as O, CollectionMembershipCache as S, InvalidModuleError as T, KyselyWriteCache as _, createForwardingPoolInstrumentation as a, createConsistencyToken as b, DuplicateOperationError as c, KyselyKeyframeStore as d, DocumentModelRegistry as f, EventBus as g, KyselyExecutionScope as h, runMigrations as i, throwIfAborted as j, matchesScope as k, OptimisticLockError as l, DriveCollectionId as m, REACTOR_SCHEMA as n, instrumentPgPool as o, SimpleJobExecutor as p, getMigrationStatus as r, KyselyOperationStore as s, DEFAULT_DRIVE_CONTAINER_TYPES as t, RevisionMismatchError as u, KyselyOperationIndex as v, DuplicateModuleError as w, createEmptyConsistencyToken as x, DocumentMetaCache as y };
|
|
2948
2987
|
|
|
2949
|
-
//# sourceMappingURL=drive-container-types-
|
|
2988
|
+
//# sourceMappingURL=drive-container-types-BxnXaOAp.js.map
|