@powerhousedao/reactor 6.2.2-dev.63 → 6.2.2-dev.64
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-DymEQNP9.js → build-worker-executor-F755haxr.js} +2 -2
- package/dist/{build-worker-executor-DymEQNP9.js.map → build-worker-executor-F755haxr.js.map} +1 -1
- package/dist/{drive-container-types-CruMdXue.js → drive-container-types-yzXFiYNp.js} +246 -124
- package/dist/drive-container-types-yzXFiYNp.js.map +1 -0
- package/dist/entry.js +2 -2
- package/dist/index.d.ts +77 -10
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +31 -38
- package/dist/index.js.map +1 -1
- package/dist/projection-entry.js +2 -2
- package/dist/{worker-Dz9lit5F.js → worker-BVKRdUCq.js} +2 -2
- package/dist/{worker-Dz9lit5F.js.map → worker-BVKRdUCq.js.map} +1 -1
- package/package.json +4 -4
- package/dist/drive-container-types-CruMdXue.js.map +0 -1
package/dist/index.js
CHANGED
|
@@ -1,9 +1,9 @@
|
|
|
1
|
-
import { A as GATED_DOCUMENT_ACTIONS, B as AuthTimestampNotMonotonicError, C as DuplicateOperationError, D as DuplicateModuleError, E as DuplicateManifestError, F as selectDecisionModel, G as InvalidOperationTimestampError, H as DocumentDeletedError, I as documentDecisionModel, J as parsePagingOptions, K as UpgradePreconditionFailedError, L as authDecisionModel, M as createEmptyConsistencyToken, N as targetDocumentId, O as InvalidModuleError, P as decideAtHead, R as buildDecisionModel, S as AppendConditionFailedError, T as RevisionMismatchError, U as DocumentNotFoundError, V as AuthorizationDeniedError, W as ExcessiveReshuffleError, Y as throwIfAborted, _ as DocumentMetaCache, a as createForwardingPoolInstrumentation, b as JobExecutorEventTypes, c as KyselyKeyframeStore, d as DriveCollectionId, f as KyselyExecutionScope, g as KyselyOperationIndex, h as KyselyWriteCache, i as runMigrations, j as createConsistencyToken, k as ModuleNotFoundError, l as DocumentModelRegistry, m as EventBus, n as REACTOR_SCHEMA, o as instrumentPgPool, p as resolveFeatureFlags, q as matchesScope, r as getMigrationStatus, s as KyselyOperationStore, t as DEFAULT_DRIVE_CONTAINER_TYPES, u as SimpleJobExecutor, v as CollectionMembershipCache, w as OptimisticLockError, x as APPEND_CONDITION_FAILED_PREFIX, y as DEFAULT_DEFERRED_JOB_TTL_MS, z as AuthEnforcementDisabledError } from "./drive-container-types-
|
|
1
|
+
import { A as GATED_DOCUMENT_ACTIONS, B as AuthTimestampNotMonotonicError, C as DuplicateOperationError, D as DuplicateModuleError, E as DuplicateManifestError, F as selectDecisionModel, G as InvalidOperationTimestampError, H as DocumentDeletedError, I as documentDecisionModel, J as parsePagingOptions, K as UpgradePreconditionFailedError, L as authDecisionModel, M as createEmptyConsistencyToken, N as targetDocumentId, O as InvalidModuleError, P as decideAtHead, R as buildDecisionModel, S as AppendConditionFailedError, T as RevisionMismatchError, U as DocumentNotFoundError, V as AuthorizationDeniedError, W as ExcessiveReshuffleError, Y as throwIfAborted, _ as DocumentMetaCache, a as createForwardingPoolInstrumentation, b as JobExecutorEventTypes, c as KyselyKeyframeStore, d as DriveCollectionId, f as KyselyExecutionScope, g as KyselyOperationIndex, h as KyselyWriteCache, i as runMigrations, j as createConsistencyToken, k as ModuleNotFoundError, l as DocumentModelRegistry, m as EventBus, n as REACTOR_SCHEMA, o as instrumentPgPool, p as resolveFeatureFlags, q as matchesScope, r as getMigrationStatus, s as KyselyOperationStore, t as DEFAULT_DRIVE_CONTAINER_TYPES, u as SimpleJobExecutor, v as CollectionMembershipCache, w as OptimisticLockError, x as APPEND_CONDITION_FAILED_PREFIX, y as DEFAULT_DEFERRED_JOB_TTL_MS, z as AuthEnforcementDisabledError } from "./drive-container-types-yzXFiYNp.js";
|
|
2
2
|
import { n as ReactorEventTypes, t as EventBusAggregateError } from "./types-DMKLa0Ok.js";
|
|
3
3
|
import { i as WorkerInitFailedError, r as WorkerExitedError, t as WorkerAbortTimeoutError } from "./errors-D3S6Eysd.js";
|
|
4
4
|
import { a as ReadModelCoordinator, i as KyselyDocumentView, n as ConsistencyTracker, o as BaseReadModel, r as makeConsistencyKey, t as KyselyDocumentIndexer } from "./document-indexer-DlpJB8AK.js";
|
|
5
5
|
import { n as errorToInfo, r as sanitizeArg, t as createForwardingLogger } from "./forwarding-logger-BBkMSxuJ.js";
|
|
6
|
-
import { t as workerEntryPath } from "./worker-
|
|
6
|
+
import { t as workerEntryPath } from "./worker-BVKRdUCq.js";
|
|
7
7
|
import { DowngradeNotSupportedError, MAX_AUTH_GRANTS, UnsupportedDocumentModelVersionError, actions, actions as documentActions, createPresignedHeader, decide, deserializeSignature, garbageCollect, generateId, groupDocumentType, groupMembershipActionTypes, hashDocumentStateForScope, normalizeDocumentModelVersion, sortOperations, toTransportAction } from "@powerhousedao/shared/document-model";
|
|
8
8
|
import { addFile, addFolder, copyNode, deleteNode, driveCreateDocument, generateNodesCopy, getDescendants, handleTargetNameCollisions, isFileNode, isFolderNode, moveNode, updateNode } from "@powerhousedao/shared/document-drive";
|
|
9
9
|
import { v4 } from "uuid";
|
|
@@ -1981,18 +1981,6 @@ function bucketFor(documentId, numWorkers) {
|
|
|
1981
1981
|
//#endregion
|
|
1982
1982
|
//#region src/executor/worker-pool-job-executor-manager.ts
|
|
1983
1983
|
/**
|
|
1984
|
-
* Action types whose application invalidates the parent's collection
|
|
1985
|
-
* membership cache. Mirrors the in-process invalidation pattern in
|
|
1986
|
-
* `document-action-handler.ts` (the worker pool relocates that work to
|
|
1987
|
-
* the parent because the cache lives there).
|
|
1988
|
-
*/
|
|
1989
|
-
const MEMBERSHIP_INVALIDATING_ACTIONS = new Set([
|
|
1990
|
-
"ADD_RELATIONSHIP",
|
|
1991
|
-
"REMOVE_RELATIONSHIP",
|
|
1992
|
-
"UPDATE_RELATIONSHIP",
|
|
1993
|
-
"DELETE_DOCUMENT"
|
|
1994
|
-
]);
|
|
1995
|
-
/**
|
|
1996
1984
|
* Manages a pool of executor workers and dispatches jobs across them with
|
|
1997
1985
|
* sticky-by-documentId routing. Replaces `SimpleJobExecutorManager` when
|
|
1998
1986
|
* the worker pool is enabled.
|
|
@@ -2002,10 +1990,19 @@ const MEMBERSHIP_INVALIDATING_ACTIONS = new Set([
|
|
|
2002
1990
|
* - Emitting `JOB_RUNNING` and `JOB_WRITE_READY` events; the worker's
|
|
2003
1991
|
* local event bus is a no-op stub.
|
|
2004
1992
|
* - Maintaining the deferred-jobs map for `DocumentNotFoundError`.
|
|
2005
|
-
* -
|
|
2006
|
-
*
|
|
2007
|
-
*
|
|
2008
|
-
*
|
|
1993
|
+
* - Enriching the outgoing `JOB_WRITE_READY` with
|
|
1994
|
+
* `collectionMemberships`, read from the operation index after the
|
|
1995
|
+
* worker has committed. It takes the whole index rather than a
|
|
1996
|
+
* narrower read interface so that handing it a cache does not
|
|
1997
|
+
* compile: which documents a commit moves between collections is not
|
|
1998
|
+
* derivable from action shape, because joining a collection also
|
|
1999
|
+
* joins every group the joining document has referenced and that set
|
|
2000
|
+
* comes from selects run inside the commit. A parent-side cache
|
|
2001
|
+
* cannot learn it went stale, and a stale entry silently drops the
|
|
2002
|
+
* document's operations from the outbox of every remote subscribed to
|
|
2003
|
+
* the omitted collection. Costs one primary-key-prefix lookup on
|
|
2004
|
+
* `document_collections` per job that produced operations, on a
|
|
2005
|
+
* fire-and-forget path.
|
|
2009
2006
|
*
|
|
2010
2007
|
* @see Executor Worker Pool Design wiki page
|
|
2011
2008
|
* (Powerhouse board wiki id: d400d711-f07e-4389-a226-4e9fdd4fa8ba)
|
|
@@ -2019,14 +2016,14 @@ var WorkerPoolJobExecutorManager = class {
|
|
|
2019
2016
|
deferredJobs;
|
|
2020
2017
|
resultHandler;
|
|
2021
2018
|
jobTimeoutMs;
|
|
2022
|
-
constructor(workerFactory, eventBus, queue, jobTracker, logger, resolver,
|
|
2019
|
+
constructor(workerFactory, eventBus, queue, jobTracker, logger, resolver, operationIndex, jobTimeoutMs = 3e4, deferredJobTtlMs = DEFAULT_DEFERRED_JOB_TTL_MS) {
|
|
2023
2020
|
this.workerFactory = workerFactory;
|
|
2024
2021
|
this.eventBus = eventBus;
|
|
2025
2022
|
this.queue = queue;
|
|
2026
2023
|
this.jobTracker = jobTracker;
|
|
2027
2024
|
this.logger = logger;
|
|
2028
2025
|
this.resolver = resolver;
|
|
2029
|
-
this.
|
|
2026
|
+
this.operationIndex = operationIndex;
|
|
2030
2027
|
this.jobTimeoutMs = jobTimeoutMs;
|
|
2031
2028
|
this.deferredJobs = new DeferredJobs(queue, jobTracker, eventBus, logger, deferredJobTtlMs, () => this.tryDispatchAll());
|
|
2032
2029
|
this.resultHandler = new JobResultHandler(queue, jobTracker, eventBus, resolver, logger);
|
|
@@ -2178,11 +2175,10 @@ var WorkerPoolJobExecutorManager = class {
|
|
|
2178
2175
|
await this.tryDispatchFor(worker);
|
|
2179
2176
|
}
|
|
2180
2177
|
async emitWriteReady(job, payload) {
|
|
2181
|
-
this.invalidateMembershipsFor(payload.operations);
|
|
2182
2178
|
const documentIds = [...new Set(payload.operations.map((op) => op.context.documentId))];
|
|
2183
2179
|
let collectionMemberships = {};
|
|
2184
|
-
try {
|
|
2185
|
-
collectionMemberships = await this.
|
|
2180
|
+
if (documentIds.length > 0) try {
|
|
2181
|
+
collectionMemberships = fillMissingMemberships(documentIds, await this.operationIndex.getCollectionsForDocuments(documentIds));
|
|
2186
2182
|
} catch (error) {
|
|
2187
2183
|
this.logger.error("Failed to load collection memberships for JOB_WRITE_READY: @Error", error);
|
|
2188
2184
|
}
|
|
@@ -2198,14 +2194,6 @@ var WorkerPoolJobExecutorManager = class {
|
|
|
2198
2194
|
this.logger.error("Failed to emit JOB_WRITE_READY event: @Error", error);
|
|
2199
2195
|
}
|
|
2200
2196
|
}
|
|
2201
|
-
invalidateMembershipsFor(operations) {
|
|
2202
|
-
for (const op of operations) {
|
|
2203
|
-
const actionType = op.operation.action.type;
|
|
2204
|
-
if (!MEMBERSHIP_INVALIDATING_ACTIONS.has(actionType)) continue;
|
|
2205
|
-
const target = extractMembershipTarget(op);
|
|
2206
|
-
if (target) this.collectionMembershipCache.invalidate(target);
|
|
2207
|
-
}
|
|
2208
|
-
}
|
|
2209
2197
|
/**
|
|
2210
2198
|
* Handle a worker-transport failure (worker exited / init failed / abort
|
|
2211
2199
|
* timed out) detected while `worker.execute` was in flight. Re-enqueues
|
|
@@ -2264,11 +2252,16 @@ function isDuplicateModuleFailure(reason) {
|
|
|
2264
2252
|
const cause = reason.cause;
|
|
2265
2253
|
return cause instanceof Error && cause.name === "DuplicateModuleError";
|
|
2266
2254
|
}
|
|
2267
|
-
|
|
2268
|
-
|
|
2269
|
-
|
|
2270
|
-
|
|
2271
|
-
|
|
2255
|
+
/**
|
|
2256
|
+
* Gives every requested document a key, empty when it belongs to no
|
|
2257
|
+
* collection. The operation index omits documents with no rows while the
|
|
2258
|
+
* membership cache defaulted them to `[]`, so this keeps the emitted
|
|
2259
|
+
* `JobWriteReadyEvent.collectionMemberships` shape unchanged.
|
|
2260
|
+
*/
|
|
2261
|
+
function fillMissingMemberships(documentIds, found) {
|
|
2262
|
+
const result = {};
|
|
2263
|
+
for (const documentId of documentIds) result[documentId] = found[documentId] ?? [];
|
|
2264
|
+
return result;
|
|
2272
2265
|
}
|
|
2273
2266
|
//#endregion
|
|
2274
2267
|
//#region src/executor/simple-job-executor-manager.ts
|
|
@@ -7834,7 +7827,7 @@ var ReactorBuilder = class {
|
|
|
7834
7827
|
if (pool.db === void 0) throw new Error("unreachable: worker pool configured without db or factory");
|
|
7835
7828
|
factory = await this.createDefaultWorkerFactory(pool.numWorkers, pool.db, pool.verifier);
|
|
7836
7829
|
}
|
|
7837
|
-
const poolManager = new WorkerPoolJobExecutorManager(factory, eventBus, queue, jobTracker, this.logger, resolver,
|
|
7830
|
+
const poolManager = new WorkerPoolJobExecutorManager(factory, eventBus, queue, jobTracker, this.logger, resolver, operationIndex, this.executorConfig.jobTimeoutMs, this.executorConfig.deferredJobTtlMs);
|
|
7838
7831
|
executorManager = poolManager;
|
|
7839
7832
|
executorStartCount = pool.numWorkers;
|
|
7840
7833
|
if (resolver instanceof DocumentModelResolver) resolver.setBroadcastHook((entry) => poolManager.loadModel(entry));
|
|
@@ -7988,7 +7981,7 @@ var ReactorBuilder = class {
|
|
|
7988
7981
|
const [{ WorkerHandle }, { createThreadTransport }, { workerEntryPath }] = await Promise.all([
|
|
7989
7982
|
import("./worker-handle-CrERzl8s.js"),
|
|
7990
7983
|
import("./transport-ByGviWdZ.js"),
|
|
7991
|
-
import("./worker-
|
|
7984
|
+
import("./worker-BVKRdUCq.js").then((n) => n.n)
|
|
7992
7985
|
]);
|
|
7993
7986
|
const poolConfig = {
|
|
7994
7987
|
enabled: true,
|