@powerhousedao/reactor 6.2.2-dev.88 → 6.2.2-staging.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/dist/index.d.ts +14 -226
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +24 -244
- package/dist/index.js.map +1 -1
- package/dist/projection-entry.js +5 -3
- package/dist/projection-entry.js.map +1 -1
- package/dist/{projection-shard-manager-CPQc5XHL.js → projection-shard-manager-D6KYcEZi.js} +11 -53
- package/dist/projection-shard-manager-D6KYcEZi.js.map +1 -0
- package/package.json +4 -4
- package/dist/projection-shard-manager-CPQc5XHL.js.map +0 -1
package/dist/index.js
CHANGED
|
@@ -7611,20 +7611,6 @@ var Reactor = class {
|
|
|
7611
7611
|
function sameDatabaseTarget(a, b) {
|
|
7612
7612
|
return a.host === b.host && a.port === b.port && a.database === b.database;
|
|
7613
7613
|
}
|
|
7614
|
-
/**
|
|
7615
|
-
* Requires each built-in kind exactly once across both lists. A kind in
|
|
7616
|
-
* neither list is indexed by nobody (host copies never index under a
|
|
7617
|
-
* worker), so its reads go stale and its consistency-token waits never
|
|
7618
|
-
* resolve; a kind in both is indexed twice per operation.
|
|
7619
|
-
*/
|
|
7620
|
-
function validateBuiltInKindCoverage(preReadyKinds, postReadyKinds) {
|
|
7621
|
-
const named = [...preReadyKinds, ...postReadyKinds];
|
|
7622
|
-
const missing = BUILT_IN_READ_MODEL_KINDS.filter((kind) => !named.includes(kind));
|
|
7623
|
-
const duplicated = BUILT_IN_READ_MODEL_KINDS.filter((kind) => named.filter((entry) => entry === kind).length > 1);
|
|
7624
|
-
if (missing.length === 0 && duplicated.length === 0) return;
|
|
7625
|
-
const problems = [missing.length > 0 ? `never named: ${missing.join(", ")} (would be indexed by no shard, leaving those reads permanently stale and their consistency-token waits unresolvable)` : void 0, duplicated.length > 0 ? `named more than once: ${duplicated.join(", ")} (would be indexed twice per operation)` : void 0].filter((problem) => problem !== void 0);
|
|
7626
|
-
throw new Error(`withProjectionShards requires preReadyKinds and postReadyKinds to name each built-in read model (${BUILT_IN_READ_MODEL_KINDS.join(", ")}) exactly once between them; ${problems.join("; ")}`);
|
|
7627
|
-
}
|
|
7628
7614
|
var ReactorBuilder = class {
|
|
7629
7615
|
logger;
|
|
7630
7616
|
documentModelSources = [];
|
|
@@ -7642,7 +7628,6 @@ var ReactorBuilder = class {
|
|
|
7642
7628
|
syncBuilder;
|
|
7643
7629
|
eventBus;
|
|
7644
7630
|
readModelCoordinator;
|
|
7645
|
-
readModelCoordinatorFactory;
|
|
7646
7631
|
signatureVerifier;
|
|
7647
7632
|
kyselyInstance;
|
|
7648
7633
|
signalHandlersEnabled = false;
|
|
@@ -7654,7 +7639,6 @@ var ReactorBuilder = class {
|
|
|
7654
7639
|
driveContainerTypes = DEFAULT_DRIVE_CONTAINER_TYPES;
|
|
7655
7640
|
workerPool;
|
|
7656
7641
|
resolvedModelManifest;
|
|
7657
|
-
moduleOnlyModelKeys = [];
|
|
7658
7642
|
projectionShardConfig;
|
|
7659
7643
|
projectionWorkerFactory;
|
|
7660
7644
|
instrumentedPools = [];
|
|
@@ -7703,15 +7687,6 @@ var ReactorBuilder = class {
|
|
|
7703
7687
|
this.readModelCoordinator = readModelCoordinator;
|
|
7704
7688
|
return this;
|
|
7705
7689
|
}
|
|
7706
|
-
/**
|
|
7707
|
-
* Register a factory that builds the coordinator once the subscription
|
|
7708
|
-
* read model, processor manager and host read models exist. Use this, not
|
|
7709
|
-
* `withReadModelCoordinator`, for coordinators that compose those internals.
|
|
7710
|
-
*/
|
|
7711
|
-
withReadModelCoordinatorFactory(factory) {
|
|
7712
|
-
this.readModelCoordinatorFactory = factory;
|
|
7713
|
-
return this;
|
|
7714
|
-
}
|
|
7715
7690
|
withExecutor(executor) {
|
|
7716
7691
|
this.executorManager = executor;
|
|
7717
7692
|
return this;
|
|
@@ -7841,18 +7816,23 @@ var ReactorBuilder = class {
|
|
|
7841
7816
|
async buildModule() {
|
|
7842
7817
|
if (!this.logger) this.logger = new ConsoleLogger(["reactor"]);
|
|
7843
7818
|
const featureFlags = resolveFeatureFlags(this.executorConfig.featureFlags);
|
|
7844
|
-
if (this.readModelCoordinator !== void 0 && this.readModelCoordinatorFactory !== void 0) throw new Error("withReadModelCoordinator and withReadModelCoordinatorFactory are mutually exclusive; register one coordinator source");
|
|
7845
|
-
if (this.projectionShardConfig !== void 0 && this.readModelCoordinatorFactory !== void 0) throw new Error("withProjectionShards and withReadModelCoordinatorFactory are mutually exclusive; the factory owns the projection worker through its createProjectionShardManager dependency");
|
|
7846
7819
|
if (this.projectionShardConfig !== void 0 && this.readModelFactories.length > 0) throw new Error("withProjectionShards does not support read models registered through withReadModelFactory; projection workers cannot receive host-only factory dependencies");
|
|
7847
7820
|
if (this.projectionShardConfig !== void 0 && this.readModels.length > 0) throw new Error("withProjectionShards does not support read models registered through withReadModel; projection workers build their own read models from the shard config and would silently omit these");
|
|
7848
|
-
if (this.projectionShardConfig !== void 0)
|
|
7821
|
+
if (this.projectionShardConfig !== void 0) {
|
|
7822
|
+
const named = [...this.projectionShardConfig.preReadyKinds, ...this.projectionShardConfig.postReadyKinds];
|
|
7823
|
+
const missing = BUILT_IN_READ_MODEL_KINDS.filter((kind) => !named.includes(kind));
|
|
7824
|
+
const duplicated = BUILT_IN_READ_MODEL_KINDS.filter((kind) => named.filter((entry) => entry === kind).length > 1);
|
|
7825
|
+
if (missing.length > 0 || duplicated.length > 0) {
|
|
7826
|
+
const problems = [missing.length > 0 ? `never named: ${missing.join(", ")} (would be indexed by no shard, leaving those reads permanently stale and their consistency-token waits unresolvable)` : void 0, duplicated.length > 0 ? `named more than once: ${duplicated.join(", ")} (would be indexed twice per operation)` : void 0].filter((problem) => problem !== void 0);
|
|
7827
|
+
throw new Error(`withProjectionShards requires preReadyKinds and postReadyKinds to name each built-in read model (${BUILT_IN_READ_MODEL_KINDS.join(", ")}) exactly once between them; ${problems.join("; ")}`);
|
|
7828
|
+
}
|
|
7829
|
+
}
|
|
7849
7830
|
const resolvedSources = await resolveModelSources(this.documentModelSources);
|
|
7850
7831
|
if (this.workerPool) {
|
|
7851
7832
|
if (resolvedSources.manifest.length === 0) throw new Error("withWorkerPool requires at least one worker-importable document-model source ({ filePath } or { packageName }).");
|
|
7852
7833
|
if (resolvedSources.moduleOnlyKeys.length > 0) throw new Error(`withWorkerPool requires worker-importable sources, but these models were registered only as live modules: ${resolvedSources.moduleOnlyKeys.join(", ")}. Provide a { filePath } or { packageName } source for each.`);
|
|
7853
7834
|
}
|
|
7854
7835
|
this.resolvedModelManifest = resolvedSources.manifest.length > 0 ? resolvedSources.manifest : void 0;
|
|
7855
|
-
this.moduleOnlyModelKeys = resolvedSources.moduleOnlyKeys;
|
|
7856
7836
|
const documentModelRegistry = new DocumentModelRegistry();
|
|
7857
7837
|
if (this.upgradeManifests.length > 0) {
|
|
7858
7838
|
const results = documentModelRegistry.registerUpgradeManifests(...this.upgradeManifests);
|
|
@@ -7902,7 +7882,7 @@ var ReactorBuilder = class {
|
|
|
7902
7882
|
if (resolver instanceof DocumentModelResolver) resolver.setBroadcastHook((entry) => poolManager.loadModel(entry));
|
|
7903
7883
|
} else executorManager = new SimpleJobExecutorManager(() => new SimpleJobExecutor(this.logger, documentModelRegistry, operationStore, eventBus, writeCache, operationIndex, documentMetaCache, collectionMembershipCache, this.driveContainerTypes, this.executorConfig, this.signatureVerifier, executionScope), eventBus, queue, jobTracker, this.logger, resolver, this.executorConfig.jobTimeoutMs, this.executorConfig.deferredJobTtlMs);
|
|
7904
7884
|
await executorManager.start(executorStartCount);
|
|
7905
|
-
const
|
|
7885
|
+
const readModelInstances = Array.from(new Set([...this.readModels]));
|
|
7906
7886
|
const documentViewConsistencyTracker = new ConsistencyTracker();
|
|
7907
7887
|
const documentView = new KyselyDocumentView(database, operationStore, operationIndex, writeCache, documentViewConsistencyTracker, featureFlags.documentDecisions);
|
|
7908
7888
|
try {
|
|
@@ -7910,6 +7890,7 @@ var ReactorBuilder = class {
|
|
|
7910
7890
|
} catch (error) {
|
|
7911
7891
|
console.error("Error initializing document view", error);
|
|
7912
7892
|
}
|
|
7893
|
+
readModelInstances.push(documentView);
|
|
7913
7894
|
const documentIndexerConsistencyTracker = new ConsistencyTracker();
|
|
7914
7895
|
const documentIndexer = new KyselyDocumentIndexer(database, operationIndex, writeCache, documentIndexerConsistencyTracker);
|
|
7915
7896
|
try {
|
|
@@ -7917,6 +7898,7 @@ var ReactorBuilder = class {
|
|
|
7917
7898
|
} catch (error) {
|
|
7918
7899
|
console.error("Error initializing document indexer", error);
|
|
7919
7900
|
}
|
|
7901
|
+
readModelInstances.push(documentIndexer);
|
|
7920
7902
|
const subscriptionManager = new ReactorSubscriptionManager(new DefaultSubscriptionErrorHandler());
|
|
7921
7903
|
const subscriptionNotificationReadModel = new SubscriptionNotificationReadModel(subscriptionManager, documentView);
|
|
7922
7904
|
const processorManagerConsistencyTracker = new ConsistencyTracker();
|
|
@@ -7933,28 +7915,12 @@ var ReactorBuilder = class {
|
|
|
7933
7915
|
writeCache,
|
|
7934
7916
|
processorManagerConsistencyTracker
|
|
7935
7917
|
});
|
|
7936
|
-
|
|
7918
|
+
readModelInstances.push(readModel);
|
|
7937
7919
|
}
|
|
7938
|
-
const
|
|
7939
|
-
...callerReadModels,
|
|
7940
|
-
documentView,
|
|
7941
|
-
documentIndexer
|
|
7942
|
-
];
|
|
7943
|
-
const hostTrackers = {
|
|
7920
|
+
const readModelCoordinator = this.readModelCoordinator ? this.readModelCoordinator : this.projectionShardConfig ? await this.createProjectionShardManager(this.projectionShardConfig, eventBus, {
|
|
7944
7921
|
"document-view": documentViewConsistencyTracker,
|
|
7945
7922
|
"document-indexer": documentIndexerConsistencyTracker
|
|
7946
|
-
};
|
|
7947
|
-
const readModelCoordinator = this.readModelCoordinator ? this.readModelCoordinator : this.readModelCoordinatorFactory ? await this.readModelCoordinatorFactory({
|
|
7948
|
-
eventBus,
|
|
7949
|
-
logger: this.logger,
|
|
7950
|
-
readModels: callerReadModels,
|
|
7951
|
-
subscriptionNotificationReadModel,
|
|
7952
|
-
processorManager,
|
|
7953
|
-
documentView,
|
|
7954
|
-
documentIndexer,
|
|
7955
|
-
createProjectionShardManager: (config) => this.createProjectionShardManager(config, eventBus, hostTrackers, false),
|
|
7956
|
-
registerShutdownHook: (hook) => this.shutdownHooks.push(hook)
|
|
7957
|
-
}) : this.projectionShardConfig ? await this.createProjectionShardManager(this.projectionShardConfig, eventBus, hostTrackers, true) : new ReadModelCoordinator(eventBus, readModelInstances, [subscriptionNotificationReadModel, processorManager]);
|
|
7923
|
+
}) : new ReadModelCoordinator(eventBus, readModelInstances, [subscriptionNotificationReadModel, processorManager]);
|
|
7958
7924
|
const reactor = new Reactor(this.logger, documentModelRegistry, queue, jobTracker, readModelCoordinator, this.features, documentView, documentIndexer, operationStore, eventBus, executorManager);
|
|
7959
7925
|
let syncModule = void 0;
|
|
7960
7926
|
if (this.channelScheme) {
|
|
@@ -8023,28 +7989,15 @@ var ReactorBuilder = class {
|
|
|
8023
7989
|
* models never index an operation, so the manager advances these from the
|
|
8024
7990
|
* shards' relayed indexing reports; without them every read carrying a
|
|
8025
7991
|
* consistency token waits forever.
|
|
8026
|
-
* @param registerShutdownHook Whether the builder owns `manager.shutdown()`
|
|
8027
|
-
* at signal time. False for the coordinator-factory path, whose factory
|
|
8028
|
-
* registers its own hook so host chains drain before the worker stops.
|
|
8029
7992
|
*/
|
|
8030
|
-
async createProjectionShardManager(config, eventBus, consistencyTrackers
|
|
8031
|
-
const
|
|
8032
|
-
|
|
8033
|
-
const caller = this.projectionShardConfig !== void 0 ? "withProjectionShards" : "withReadModelCoordinatorFactory";
|
|
8034
|
-
if (!baseDb) throw new Error(`${caller} requires a db (or an executor worker pool configured with one); projection workers need connection info to open their own pools.`);
|
|
8035
|
-
const workerDb = this.workerPool?.db;
|
|
8036
|
-
if (config.db && workerDb && !sameDatabaseTarget(workerDb, config.db)) throw new Error("withWorkerPool({ db }) and the projection worker db must address the same Postgres database (same host, port, and database); the parent writes operations there and the projection shards read them.");
|
|
8037
|
-
if (config.db && this.kyselyInstance === void 0) {
|
|
8038
|
-
if (!parentDb) throw new Error(`The projection worker db passed to ${caller} must also be the parent reactor's database, but nothing configures the parent: it would fall back to the default embedded database while the worker projects into Postgres. Pass the same { db } to withWorkerPool, or give the parent its connection with withKysely.`);
|
|
8039
|
-
if (!sameDatabaseTarget(config.db, parentDb)) throw new Error(`The projection worker db passed to ${caller} and the parent reactor database must address the same Postgres database (same host, port, and database); the parent writes operations there and the projection shards read them.`);
|
|
8040
|
-
}
|
|
8041
|
-
validateBuiltInKindCoverage(config.preReadyKinds, config.postReadyKinds);
|
|
8042
|
-
if (this.moduleOnlyModelKeys.length > 0) throw new Error(`projection workers require worker-importable sources, but these models were registered only as live modules: ${this.moduleOnlyModelKeys.join(", ")}. Provide a { filePath } or { packageName } source for each.`);
|
|
7993
|
+
async createProjectionShardManager(config, eventBus, consistencyTrackers) {
|
|
7994
|
+
const baseDb = this.resolveReactorDbConfig();
|
|
7995
|
+
if (!baseDb) throw new Error("withProjectionShards requires a db (or an executor worker pool configured with one); projection workers need connection info to open their own pools.");
|
|
8043
7996
|
const models = this.resolvedModelManifest ?? [];
|
|
8044
7997
|
const db = {
|
|
8045
7998
|
...baseDb,
|
|
8046
7999
|
poolSize: config.poolSize ?? baseDb.poolSize,
|
|
8047
|
-
applicationName:
|
|
8000
|
+
applicationName: "reactor-projection-shard"
|
|
8048
8001
|
};
|
|
8049
8002
|
const factory = this.projectionWorkerFactory ?? await this.createDefaultProjectionWorkerFactory();
|
|
8050
8003
|
const poolInstrumentations = [];
|
|
@@ -8053,7 +8006,7 @@ var ReactorBuilder = class {
|
|
|
8053
8006
|
poolInstrumentations.push(forwarder);
|
|
8054
8007
|
this.instrumentedPools.push(forwarder);
|
|
8055
8008
|
}
|
|
8056
|
-
const { ProjectionShardManager } = await import("./projection-shard-manager-
|
|
8009
|
+
const { ProjectionShardManager } = await import("./projection-shard-manager-D6KYcEZi.js");
|
|
8057
8010
|
const manager = new ProjectionShardManager({
|
|
8058
8011
|
shardCount: config.shardCount,
|
|
8059
8012
|
db,
|
|
@@ -8068,21 +8021,10 @@ var ReactorBuilder = class {
|
|
|
8068
8021
|
drainTimeoutMs: config.drainTimeoutMs,
|
|
8069
8022
|
chainDepthReportIntervalMs: config.chainDepthReportIntervalMs,
|
|
8070
8023
|
poolInstrumentations,
|
|
8071
|
-
consistencyTrackers
|
|
8072
|
-
onReadReady: config.onReadReady,
|
|
8073
|
-
onShardFatal: config.onShardFatal
|
|
8024
|
+
consistencyTrackers
|
|
8074
8025
|
});
|
|
8075
|
-
|
|
8076
|
-
|
|
8077
|
-
} catch (error) {
|
|
8078
|
-
try {
|
|
8079
|
-
await manager.shutdown();
|
|
8080
|
-
} catch (shutdownError) {
|
|
8081
|
-
this.logger.warn("projection shard manager shutdown after a failed startup also failed: @error", shutdownError);
|
|
8082
|
-
}
|
|
8083
|
-
throw error;
|
|
8084
|
-
}
|
|
8085
|
-
if (registerShutdownHook) this.shutdownHooks.push(() => manager.shutdown());
|
|
8026
|
+
await manager.startup();
|
|
8027
|
+
this.shutdownHooks.push(() => manager.shutdown());
|
|
8086
8028
|
return manager;
|
|
8087
8029
|
}
|
|
8088
8030
|
async createDefaultProjectionWorkerFactory() {
|
|
@@ -8201,168 +8143,6 @@ var ReactorBuilder = class {
|
|
|
8201
8143
|
}
|
|
8202
8144
|
};
|
|
8203
8145
|
//#endregion
|
|
8204
|
-
//#region src/projection/hybrid-projection-coordinator.ts
|
|
8205
|
-
/** Host-side stages on a per-queueKey chain driven by the worker's read-ready. */
|
|
8206
|
-
var HybridProjectionCoordinator = class {
|
|
8207
|
-
/** One array, mutated in place: reactor-api captures it by reference once. */
|
|
8208
|
-
readModels;
|
|
8209
|
-
eventBus;
|
|
8210
|
-
logger;
|
|
8211
|
-
manager;
|
|
8212
|
-
preReady;
|
|
8213
|
-
postReady;
|
|
8214
|
-
chains = /* @__PURE__ */ new Map();
|
|
8215
|
-
constructor(options) {
|
|
8216
|
-
this.eventBus = options.eventBus;
|
|
8217
|
-
this.logger = options.logger;
|
|
8218
|
-
this.manager = options.manager;
|
|
8219
|
-
this.preReady = options.preReady;
|
|
8220
|
-
this.postReady = options.postReady;
|
|
8221
|
-
this.readModels = [
|
|
8222
|
-
...options.preReady,
|
|
8223
|
-
...options.postReady,
|
|
8224
|
-
...options.lookupOnly
|
|
8225
|
-
];
|
|
8226
|
-
}
|
|
8227
|
-
start() {
|
|
8228
|
-
this.manager.start();
|
|
8229
|
-
}
|
|
8230
|
-
stop() {
|
|
8231
|
-
this.manager.stop();
|
|
8232
|
-
}
|
|
8233
|
-
/** Wired as `onReadReady`; host trackers are already advanced (port FIFO). */
|
|
8234
|
-
acceptReadReady(event) {
|
|
8235
|
-
if (event.operations.length === 0) {
|
|
8236
|
-
this.manager.emitReadReady(event).catch((err) => this.logger.error("JOB_READ_READY emit failed for job @jobId: @Error", { jobId: event.jobId }, err));
|
|
8237
|
-
return;
|
|
8238
|
-
}
|
|
8239
|
-
const enqueuedAt = performance.now();
|
|
8240
|
-
const key = this.queueKeyFor(event);
|
|
8241
|
-
const current = (this.chains.get(key) ?? Promise.resolve()).then(() => this.runHostChain(event, enqueuedAt));
|
|
8242
|
-
this.chains.set(key, current);
|
|
8243
|
-
current.finally(() => {
|
|
8244
|
-
if (this.chains.get(key) === current) this.chains.delete(key);
|
|
8245
|
-
});
|
|
8246
|
-
}
|
|
8247
|
-
addReadModel(readModel, stage) {
|
|
8248
|
-
if (this.readModels.some(({ name }) => name === readModel.name)) throw new Error(`Read model "${readModel.name}" is already registered`);
|
|
8249
|
-
if (stage === "pre_ready") this.preReady.push(readModel);
|
|
8250
|
-
else this.postReady.push(readModel);
|
|
8251
|
-
this.readModels.push(readModel);
|
|
8252
|
-
}
|
|
8253
|
-
getChainDepth() {
|
|
8254
|
-
return this.manager.getChainDepth() + this.chains.size;
|
|
8255
|
-
}
|
|
8256
|
-
/** Worker chains flush first, so every relayed read-ready is in `chains`. */
|
|
8257
|
-
async drain() {
|
|
8258
|
-
await this.manager.drain();
|
|
8259
|
-
while (this.chains.size > 0) {
|
|
8260
|
-
const pending = Array.from(this.chains.values());
|
|
8261
|
-
await Promise.allSettled(pending);
|
|
8262
|
-
}
|
|
8263
|
-
}
|
|
8264
|
-
/** Builder shutdown hook; reaches `manager.shutdown()` even when drain fails. */
|
|
8265
|
-
async shutdown() {
|
|
8266
|
-
try {
|
|
8267
|
-
await this.drain();
|
|
8268
|
-
} catch (error) {
|
|
8269
|
-
this.logger.warn("hybrid coordinator drain failed during shutdown: @Error", error);
|
|
8270
|
-
}
|
|
8271
|
-
await this.manager.shutdown();
|
|
8272
|
-
}
|
|
8273
|
-
async runHostChain(event, enqueuedAt) {
|
|
8274
|
-
const chainWaitDurationMs = performance.now() - enqueuedAt;
|
|
8275
|
-
const preReadyStart = performance.now();
|
|
8276
|
-
try {
|
|
8277
|
-
await Promise.all(this.preReady.map((readModel) => this.indexWithTiming(readModel, "pre_ready", event)));
|
|
8278
|
-
} catch (error) {
|
|
8279
|
-
this.logger.error("Host pre-ready read model indexing failed for job @jobId: @Error", { jobId: event.jobId }, error);
|
|
8280
|
-
}
|
|
8281
|
-
const preReadyDurationMs = performance.now() - preReadyStart;
|
|
8282
|
-
const emitStart = performance.now();
|
|
8283
|
-
try {
|
|
8284
|
-
await this.manager.emitReadReady(event);
|
|
8285
|
-
} catch (error) {
|
|
8286
|
-
this.logger.error("JOB_READ_READY emit failed for job @jobId: @Error", { jobId: event.jobId }, error);
|
|
8287
|
-
}
|
|
8288
|
-
const emitDurationMs = performance.now() - emitStart;
|
|
8289
|
-
const postReadyStart = performance.now();
|
|
8290
|
-
try {
|
|
8291
|
-
await Promise.all(this.postReady.map((readModel) => this.indexWithTiming(readModel, "post_ready", event)));
|
|
8292
|
-
} catch (error) {
|
|
8293
|
-
this.logger.error("Host post-ready read model indexing failed for job @jobId: @Error", { jobId: event.jobId }, error);
|
|
8294
|
-
}
|
|
8295
|
-
const postReadyDurationMs = performance.now() - postReadyStart;
|
|
8296
|
-
this.emitBatchCompleted({
|
|
8297
|
-
jobId: event.jobId,
|
|
8298
|
-
batchSize: event.operations.length,
|
|
8299
|
-
chainWaitDurationMs,
|
|
8300
|
-
preReadyDurationMs,
|
|
8301
|
-
emitDurationMs,
|
|
8302
|
-
postReadyDurationMs
|
|
8303
|
-
});
|
|
8304
|
-
}
|
|
8305
|
-
async indexWithTiming(readModel, stage, event) {
|
|
8306
|
-
const start = performance.now();
|
|
8307
|
-
let success = false;
|
|
8308
|
-
try {
|
|
8309
|
-
await readModel.indexOperations(event.operations);
|
|
8310
|
-
success = true;
|
|
8311
|
-
} finally {
|
|
8312
|
-
this.emitReadModelIndexed({
|
|
8313
|
-
jobId: event.jobId,
|
|
8314
|
-
readModelName: readModel.name,
|
|
8315
|
-
stage,
|
|
8316
|
-
durationMs: performance.now() - start,
|
|
8317
|
-
operationCount: event.operations.length,
|
|
8318
|
-
success
|
|
8319
|
-
});
|
|
8320
|
-
}
|
|
8321
|
-
}
|
|
8322
|
-
emitBatchCompleted(payload) {
|
|
8323
|
-
this.eventBus.emit(ReactorEventTypes.READMODEL_BATCH_COMPLETED, payload).catch((err) => this.logger.error("READMODEL_BATCH_COMPLETED emit failed for job @jobId: @Error", { jobId: payload.jobId }, err));
|
|
8324
|
-
}
|
|
8325
|
-
emitReadModelIndexed(payload) {
|
|
8326
|
-
this.eventBus.emit(ReactorEventTypes.READMODEL_INDEXED, payload).catch((err) => this.logger.error("READMODEL_INDEXED emit failed for job @jobId: @Error", { jobId: payload.jobId }, err));
|
|
8327
|
-
}
|
|
8328
|
-
queueKeyFor(event) {
|
|
8329
|
-
const ctx = event.operations[0].context;
|
|
8330
|
-
return `${ctx.documentId}:${ctx.scope}:${ctx.branch}`;
|
|
8331
|
-
}
|
|
8332
|
-
};
|
|
8333
|
-
//#endregion
|
|
8334
|
-
//#region src/projection/create-hybrid-projection-coordinator.ts
|
|
8335
|
-
/** Built-ins in one projection worker; all other read models stay on the host. */
|
|
8336
|
-
function createHybridProjectionCoordinatorFactory(options = {}) {
|
|
8337
|
-
return async (deps) => {
|
|
8338
|
-
const ref = { current: void 0 };
|
|
8339
|
-
const manager = await deps.createProjectionShardManager({
|
|
8340
|
-
shardCount: options.shardCount ?? 1,
|
|
8341
|
-
preReadyKinds: ["document-view", "document-indexer"],
|
|
8342
|
-
postReadyKinds: [],
|
|
8343
|
-
db: options.db,
|
|
8344
|
-
poolSize: options.poolSize,
|
|
8345
|
-
initTimeoutMs: options.initTimeoutMs,
|
|
8346
|
-
shutdownGraceMs: options.shutdownGraceMs,
|
|
8347
|
-
drainTimeoutMs: options.drainTimeoutMs,
|
|
8348
|
-
chainDepthReportIntervalMs: options.chainDepthReportIntervalMs,
|
|
8349
|
-
onReadReady: (event) => ref.current.acceptReadReady(event),
|
|
8350
|
-
onShardFatal: options.onFatal
|
|
8351
|
-
});
|
|
8352
|
-
const coordinator = new HybridProjectionCoordinator({
|
|
8353
|
-
eventBus: deps.eventBus,
|
|
8354
|
-
logger: deps.logger,
|
|
8355
|
-
manager,
|
|
8356
|
-
preReady: deps.readModels,
|
|
8357
|
-
postReady: [deps.subscriptionNotificationReadModel, deps.processorManager],
|
|
8358
|
-
lookupOnly: [deps.documentView, deps.documentIndexer]
|
|
8359
|
-
});
|
|
8360
|
-
ref.current = coordinator;
|
|
8361
|
-
deps.registerShutdownHook(() => coordinator.shutdown());
|
|
8362
|
-
return coordinator;
|
|
8363
|
-
};
|
|
8364
|
-
}
|
|
8365
|
-
//#endregion
|
|
8366
8146
|
//#region src/signer/passthrough-signer.ts
|
|
8367
8147
|
/**
|
|
8368
8148
|
* A no-op signer that returns empty values for all methods.
|
|
@@ -8792,6 +8572,6 @@ var DocumentIntegrityService = class {
|
|
|
8792
8572
|
}
|
|
8793
8573
|
};
|
|
8794
8574
|
//#endregion
|
|
8795
|
-
export { ALWAYS_READABLE_SCOPES, APPEND_CONDITION_FAILED_PREFIX, AppendConditionFailedError, AuthEnforcementDisabledError, BareReadGate, BaseReadModel, ChannelError, ChannelErrorSource, ChannelScheme, ConsistencyTracker, DEFAULT_DRIVE_CONTAINER_TYPES, DOCUMENT_INDEXER_READ_MODEL, DOCUMENT_VIEW_READ_MODEL, DRIVE_AUTH_ERROR_MESSAGES, DefaultSubscriptionErrorHandler, DocumentAlreadyExistsError, DocumentChangeType, DocumentExistence, DocumentIntegrityService, DocumentModelRegistry, DocumentModelResolver, DriveClient, DriveCollectionId, DuplicateManifestError, DuplicateModuleError, DuplicateOperationError, EventBus, EventBusAggregateError, GqlRequestChannel, GqlRequestChannelFactory, GqlResponseChannel, GqlResponseChannelFactory,
|
|
8575
|
+
export { ALWAYS_READABLE_SCOPES, APPEND_CONDITION_FAILED_PREFIX, AppendConditionFailedError, AuthEnforcementDisabledError, BareReadGate, BaseReadModel, ChannelError, ChannelErrorSource, ChannelScheme, ConsistencyTracker, DEFAULT_DRIVE_CONTAINER_TYPES, DOCUMENT_INDEXER_READ_MODEL, DOCUMENT_VIEW_READ_MODEL, DRIVE_AUTH_ERROR_MESSAGES, DefaultSubscriptionErrorHandler, DocumentAlreadyExistsError, DocumentChangeType, DocumentExistence, DocumentIntegrityService, DocumentModelRegistry, DocumentModelResolver, DriveClient, DriveCollectionId, DuplicateManifestError, DuplicateModuleError, DuplicateOperationError, EventBus, EventBusAggregateError, GqlRequestChannel, GqlRequestChannelFactory, GqlResponseChannel, GqlResponseChannelFactory, SimpleJobExecutor as InMemoryJobExecutor, SimpleJobExecutor, InMemoryJobTracker, InMemoryQueue, IntervalPollTimer, InvalidModuleError, JobAwaiter, JobExecutorEventTypes, JobStatus, KyselyDocumentIndexer, KyselyDocumentView, KyselyKeyframeStore, KyselyOperationStore, KyselySyncCursorStorage, KyselySyncRemoteStorage, KyselyWriteCache, Mailbox, ModelReadGate, ModuleNotFoundError, NullDocumentModelResolver, OptimisticLockError, PollBehavior, PollingChannelError, ProcessorManager, PropagationMode, QueueEventTypes, REACTOR_SCHEMA, RECOVERABLE_GRAPHQL_ERROR_CODES, Reactor, ReactorBuilder, ReactorClient, ReactorClientBuilder, ReactorEventTypes, ReactorSubscriptionManager, ReadModelCoordinator, RelationalDbProcessor, RelationshipChangeType, RetryAccounting, RevisionMismatchError, SeededStateReader, SimpleJobExecutorManager, SyncBuilder, SyncEventTypes, SyncOperation, SyncOperationAggregateError, SyncOperationStatus, SyncScopeGate, SyncStatus, SyncStatusTracker, addRelationshipAction, authDecisionModel, batchOperationsByDocument, buildDecisionModel, classifyJobFailure, consolidateSyncOperations, createDocumentAction, createForwardingLogger, createMutableShutdownStatus, createReactorHostModuleBase, createRelationalDb, decideAtHead, deleteDocumentAction, documentActions, documentDecisionModel, driveIdFromUrl, envelopesToSyncOperations, errorToInfo, firstOutOfOrderPair, getMigrationStatus, instrumentPgPool, isDriveAuthError, isRecoverableGraphQLError, makeConsistencyKey, parseDriveUrl, parsePagingOptions, quarantinesDocument, readDecisionModel, removeRelationshipAction, runMigrations, sanitizeArg, selectDecisionModel, supportsLiveReadModelRegistration, syncOperationErrorType, trimMailboxFromAckOrdinal, updateRelationshipAction, upgradeDocumentAction, workerEntryPath };
|
|
8796
8576
|
|
|
8797
8577
|
//# sourceMappingURL=index.js.map
|