@powerhousedao/reactor 6.2.2-dev.43 → 6.2.2-dev.44

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.js CHANGED
@@ -1,10 +1,10 @@
1
- import { A as OptimisticLockError, B as ExcessiveReshuffleError, C as DocumentMetaCache, D as APPEND_CONDITION_FAILED_PREFIX, E as CollectionMembershipCache, F as ModuleNotFoundError, G as throwIfAborted, H as UpgradePreconditionFailedError, I as AuthTimestampNotMonotonicError, L as AuthorizationDeniedError, M as DuplicateManifestError, N as DuplicateModuleError, O as AppendConditionFailedError, P as InvalidModuleError, R as DocumentDeletedError, S as KyselyOperationIndex, T as createEmptyConsistencyToken, U as matchesScope, V as InvalidOperationTimestampError, W as parsePagingOptions, _ as KyselyExecutionScope, a as createForwardingPoolInstrumentation, b as EventBus, c as KyselyKeyframeStore, d as DriveCollectionId, f as decideAtHead, g as authDecisionModel, h as buildDecisionModel, i as runMigrations, j as RevisionMismatchError, k as DuplicateOperationError, l as DocumentModelRegistry, m as documentDecisionModel, n as REACTOR_SCHEMA, o as instrumentPgPool, p as selectDecisionModel, r as getMigrationStatus, s as KyselyOperationStore, t as DEFAULT_DRIVE_CONTAINER_TYPES, u as SimpleJobExecutor, v as FLAG_PREREQUISITES, w as createConsistencyToken, x as KyselyWriteCache, y as validateFeatureFlags, z as DocumentNotFoundError } from "./drive-container-types-CU1ZUfD1.js";
1
+ import { A as OptimisticLockError, B as ExcessiveReshuffleError, C as DocumentMetaCache, D as APPEND_CONDITION_FAILED_PREFIX, E as CollectionMembershipCache, F as ModuleNotFoundError, G as throwIfAborted, H as UpgradePreconditionFailedError, I as AuthTimestampNotMonotonicError, L as AuthorizationDeniedError, M as DuplicateManifestError, N as DuplicateModuleError, O as AppendConditionFailedError, P as InvalidModuleError, R as DocumentDeletedError, S as KyselyOperationIndex, T as createEmptyConsistencyToken, U as matchesScope, V as InvalidOperationTimestampError, W as parsePagingOptions, _ as KyselyExecutionScope, a as createForwardingPoolInstrumentation, b as EventBus, c as KyselyKeyframeStore, d as DriveCollectionId, f as decideAtHead, g as authDecisionModel, h as buildDecisionModel, i as runMigrations, j as RevisionMismatchError, k as DuplicateOperationError, l as DocumentModelRegistry, m as documentDecisionModel, n as REACTOR_SCHEMA, o as instrumentPgPool, p as selectDecisionModel, r as getMigrationStatus, s as KyselyOperationStore, t as DEFAULT_DRIVE_CONTAINER_TYPES, u as SimpleJobExecutor, v as FLAG_PREREQUISITES, w as createConsistencyToken, x as KyselyWriteCache, y as validateFeatureFlags, z as DocumentNotFoundError } from "./drive-container-types-h3M1AK3K.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-BfdCgjG-.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-CeW6WsVF.js";
7
- import { DowngradeNotSupportedError, UnsupportedDocumentModelVersionError, actions, actions as documentActions, createPresignedHeader, decide, garbageCollect, generateId, hashDocumentStateForScope, normalizeDocumentModelVersion, sortOperations } from "@powerhousedao/shared/document-model";
6
+ import { t as workerEntryPath } from "./worker-CbtYMIju.js";
7
+ import { DowngradeNotSupportedError, UnsupportedDocumentModelVersionError, actions, actions as documentActions, createPresignedHeader, decide, garbageCollect, generateId, groupDocumentType, groupMembershipActionTypes, hashDocumentStateForScope, normalizeDocumentModelVersion, sortOperations } 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";
10
10
  import { ConsoleLogger, childLogger } from "document-model";
@@ -3285,6 +3285,83 @@ var SubscriptionNotificationReadModel = class {
3285
3285
  }
3286
3286
  };
3287
3287
  //#endregion
3288
+ //#region src/core/group-reevaluation-trigger.ts
3289
+ /**
3290
+ * Watches committed writes for group membership changes and enqueues a
3291
+ * re-evaluation job for every document whose auth history references the
3292
+ * changed group, found through the reverse direction of the group-reference
3293
+ * relation. Each affected document is re-judged in its own job, so the work
3294
+ * runs under that document's execution slot rather than the group's.
3295
+ *
3296
+ * The job carries the earliest changed membership timestamp; the executor
3297
+ * skips the pass when everything the document holds sorts before it, which
3298
+ * keeps the common case (a membership write later than all history) free.
3299
+ */
3300
+ var GroupReevaluationTrigger = class {
3301
+ unsubscribe;
3302
+ constructor(logger, eventBus, queue, operationIndex) {
3303
+ this.logger = logger;
3304
+ this.eventBus = eventBus;
3305
+ this.queue = queue;
3306
+ this.operationIndex = operationIndex;
3307
+ }
3308
+ startup() {
3309
+ this.unsubscribe = this.eventBus.subscribe(ReactorEventTypes.JOB_WRITE_READY, async (_type, event) => this.onWriteReady(event));
3310
+ }
3311
+ shutdown() {
3312
+ this.unsubscribe?.();
3313
+ this.unsubscribe = void 0;
3314
+ }
3315
+ async onWriteReady(event) {
3316
+ const changed = /* @__PURE__ */ new Map();
3317
+ for (const { operation, context } of event.operations) {
3318
+ if (context.documentType !== groupDocumentType || context.scope !== "global" || !groupMembershipActionTypes.includes(operation.action.type)) continue;
3319
+ const existing = changed.get(context.documentId);
3320
+ if (existing === void 0 || Date.parse(operation.timestampUtcMs) < Date.parse(existing)) changed.set(context.documentId, operation.timestampUtcMs);
3321
+ }
3322
+ if (changed.size === 0) return;
3323
+ const affected = /* @__PURE__ */ new Map();
3324
+ for (const [groupId, timestamp] of changed) {
3325
+ let referencers;
3326
+ try {
3327
+ referencers = await this.operationIndex.getGroupReferencers(groupId);
3328
+ } catch (error) {
3329
+ this.logger.error("Failed to resolve referencers of group @groupId: @error", groupId, error);
3330
+ continue;
3331
+ }
3332
+ for (const documentId of referencers) {
3333
+ const existing = affected.get(documentId);
3334
+ if (existing === void 0 || Date.parse(timestamp) < Date.parse(existing)) affected.set(documentId, timestamp);
3335
+ }
3336
+ }
3337
+ for (const [documentId, timestamp] of affected) {
3338
+ const jobId = v4();
3339
+ const job = {
3340
+ id: jobId,
3341
+ kind: "reevaluation",
3342
+ documentId,
3343
+ scope: "global",
3344
+ branch: "main",
3345
+ actions: [],
3346
+ operations: [],
3347
+ createdAt: (/* @__PURE__ */ new Date()).toISOString(),
3348
+ queueHint: [],
3349
+ maxRetries: 3,
3350
+ errorHistory: [],
3351
+ meta: {
3352
+ ...buildSingleJobMeta(jobId),
3353
+ triggerTimestampUtcMs: timestamp
3354
+ }
3355
+ };
3356
+ try {
3357
+ await this.queue.enqueue(job);
3358
+ } catch (error) {
3359
+ this.logger.error("Failed to enqueue re-evaluation of @documentId: @error", documentId, error);
3360
+ }
3361
+ }
3362
+ }
3363
+ };
3364
+ //#endregion
3288
3365
  //#region src/sync/types.ts
3289
3366
  let ChannelScheme = /* @__PURE__ */ function(ChannelScheme) {
3290
3367
  ChannelScheme["CONNECT"] = "connect";
@@ -7142,6 +7219,11 @@ var ReactorBuilder = class {
7142
7219
  syncModule = this.syncBuilder.buildModule(reactor, this.logger, operationIndex, eventBus, database, this.driveContainerTypes);
7143
7220
  await syncModule.syncManager.startup();
7144
7221
  }
7222
+ let groupReevaluationTrigger;
7223
+ if (this.executorConfig.featureFlags?.authGroups) {
7224
+ groupReevaluationTrigger = new GroupReevaluationTrigger(this.logger, eventBus, queue, operationIndex);
7225
+ groupReevaluationTrigger.startup();
7226
+ }
7145
7227
  const module = {
7146
7228
  eventBus,
7147
7229
  documentModelRegistry,
@@ -7163,6 +7245,7 @@ var ReactorBuilder = class {
7163
7245
  processorManagerConsistencyTracker,
7164
7246
  syncModule,
7165
7247
  reactor,
7248
+ groupReevaluationTrigger,
7166
7249
  pools: this.instrumentedPools
7167
7250
  };
7168
7251
  if (this.signalHandlersEnabled) this.attachSignalHandlers(module);
@@ -7237,7 +7320,7 @@ var ReactorBuilder = class {
7237
7320
  const [{ WorkerHandle }, { createThreadTransport }, { workerEntryPath }] = await Promise.all([
7238
7321
  import("./worker-handle-CrERzl8s.js"),
7239
7322
  import("./transport-ByGviWdZ.js"),
7240
- import("./worker-CeW6WsVF.js").then((n) => n.n)
7323
+ import("./worker-CbtYMIju.js").then((n) => n.n)
7241
7324
  ]);
7242
7325
  const poolConfig = {
7243
7326
  enabled: true,