@powerhousedao/reactor 6.2.0-dev.2 → 6.2.0-dev.20

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,9 +1,9 @@
1
- import { A as parsePagingOptions, C as DuplicateManifestError, D as DocumentDeletedError, E as ModuleNotFoundError, O as DocumentNotFoundError, S as CollectionMembershipCache, T as InvalidModuleError, _ as KyselyWriteCache, a as createForwardingPoolInstrumentation, b as createConsistencyToken, c as DuplicateOperationError, d as KyselyKeyframeStore, f as DocumentModelRegistry, g as EventBus, h as KyselyExecutionScope, i as runMigrations, j as throwIfAborted, k as matchesScope, l as OptimisticLockError, m as driveCollectionId, n as REACTOR_SCHEMA, o as instrumentPgPool, p as SimpleJobExecutor, r as getMigrationStatus, s as KyselyOperationStore, t as DEFAULT_DRIVE_CONTAINER_TYPES, u as RevisionMismatchError, v as KyselyOperationIndex, w as DuplicateModuleError, x as createEmptyConsistencyToken, y as DocumentMetaCache } from "./drive-container-types-BNpMlgT_.js";
1
+ import { A as parsePagingOptions, C as DuplicateManifestError, D as DocumentDeletedError, E as ModuleNotFoundError, O as DocumentNotFoundError, S as CollectionMembershipCache, T as InvalidModuleError, _ as KyselyWriteCache, a as createForwardingPoolInstrumentation, b as createConsistencyToken, c as DuplicateOperationError, d as KyselyKeyframeStore, f as DocumentModelRegistry, g as EventBus, h as KyselyExecutionScope, i as runMigrations, j as throwIfAborted, k as matchesScope, l as OptimisticLockError, m as DriveCollectionId, n as REACTOR_SCHEMA, o as instrumentPgPool, p as SimpleJobExecutor, r as getMigrationStatus, s as KyselyOperationStore, t as DEFAULT_DRIVE_CONTAINER_TYPES, u as RevisionMismatchError, v as KyselyOperationIndex, w as DuplicateModuleError, x as createEmptyConsistencyToken, y as DocumentMetaCache } from "./drive-container-types-BxnXaOAp.js";
2
2
  import { n as ReactorEventTypes, t as EventBusAggregateError } from "./types-CxSpmNGK.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-B2iLRB0o.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-SUoDhurA.js";
6
+ import { t as workerEntryPath } from "./worker-XYrQaEmt.js";
7
7
  import { actions, actions as documentActions, createPresignedHeader, generateId, hashDocumentStateForScope, replayDocument } 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";
@@ -737,6 +737,14 @@ var ReactorClient = class {
737
737
  return await this.reactor.getByIdOrSlug(identifier, view, void 0, signal);
738
738
  }
739
739
  /**
740
+ * Resolves an identifier (id or slug) to the canonical document id, using the
741
+ * same lookup as the data path. Resolves against the "main" branch. Throws if
742
+ * the identifier cannot be resolved or is ambiguous.
743
+ */
744
+ async resolveIdOrSlug(identifier, signal) {
745
+ return this.documentView.resolveIdOrSlug(identifier, void 0, void 0, signal);
746
+ }
747
+ /**
740
748
  * Retrieves operations for a document
741
749
  */
742
750
  async getOperations(documentIdentifier, view, filter, paging, signal) {
@@ -1858,6 +1866,7 @@ var InMemoryJobTracker = class {
1858
1866
  if (!job) {
1859
1867
  this.jobs.set(jobId, {
1860
1868
  id: jobId,
1869
+ documentId: "",
1861
1870
  status: JobStatus.RUNNING,
1862
1871
  createdAtUtcIso: (/* @__PURE__ */ new Date()).toISOString(),
1863
1872
  consistencyToken: createEmptyConsistencyToken(),
@@ -1878,6 +1887,7 @@ var InMemoryJobTracker = class {
1878
1887
  if (!existing) {
1879
1888
  this.jobs.set(jobId, {
1880
1889
  id: jobId,
1890
+ documentId: job?.documentId ?? "",
1881
1891
  status: JobStatus.FAILED,
1882
1892
  createdAtUtcIso: (/* @__PURE__ */ new Date()).toISOString(),
1883
1893
  completedAtUtcIso: (/* @__PURE__ */ new Date()).toISOString(),
@@ -3792,12 +3802,27 @@ var IntervalPollTimer = class {
3792
3802
  let syncOpCounter = 0;
3793
3803
  /**
3794
3804
  * Serializes an action for GraphQL transport, converting signature tuples to strings.
3805
+ *
3806
+ * Only the fields declared by the GraphQL `ActionInput` type are forwarded. This
3807
+ * guards against stale runtime-only fields (e.g. a legacy `attachments` array on
3808
+ * operations persisted before the attachment-system removal) leaking into the
3809
+ * mutation variables, where the tightened schema would reject them.
3795
3810
  */
3796
3811
  function serializeAction(action) {
3812
+ const base = {
3813
+ id: action.id,
3814
+ type: action.type,
3815
+ timestampUtcMs: action.timestampUtcMs,
3816
+ input: action.input,
3817
+ scope: action.scope
3818
+ };
3797
3819
  const signer = action.context?.signer;
3798
- if (!signer?.signatures) return action;
3820
+ if (!signer?.signatures) return action.context ? {
3821
+ ...base,
3822
+ context: action.context
3823
+ } : base;
3799
3824
  return {
3800
- ...action,
3825
+ ...base,
3801
3826
  context: {
3802
3827
  ...action.context,
3803
3828
  signer: {
@@ -4192,13 +4217,6 @@ var GqlRequestChannel = class {
4192
4217
  timestampUtcMs
4193
4218
  input
4194
4219
  scope
4195
- attachments {
4196
- data
4197
- mimeType
4198
- hash
4199
- extension
4200
- fileName
4201
- }
4202
4220
  context {
4203
4221
  signer {
4204
4222
  user {
@@ -4264,7 +4282,7 @@ var GqlRequestChannel = class {
4264
4282
  async touchRemoteChannel() {
4265
4283
  let sinceTimestampUtcMs = "0";
4266
4284
  try {
4267
- const result = await this.operationIndex.getLatestTimestampForCollection(this.config.collectionId);
4285
+ const result = await this.operationIndex.getLatestTimestampForCollection(this.config.collectionId.key);
4268
4286
  if (result) sinceTimestampUtcMs = result;
4269
4287
  } catch {}
4270
4288
  const mutation = `
@@ -4278,7 +4296,7 @@ var GqlRequestChannel = class {
4278
4296
  const variables = { input: {
4279
4297
  id: this.channelId,
4280
4298
  name: this.channelId,
4281
- collectionId: this.config.collectionId,
4299
+ collectionId: this.config.collectionId.key,
4282
4300
  filter: {
4283
4301
  documentId: this.config.filter.documentId,
4284
4302
  scope: this.config.filter.scope,
@@ -4811,7 +4829,7 @@ function rowToRemoteRecord(row) {
4811
4829
  return {
4812
4830
  id: row.channel_id,
4813
4831
  name: row.name,
4814
- collectionId: row.collection_id,
4832
+ collectionId: DriveCollectionId.fromKey(row.collection_id),
4815
4833
  channelConfig: {
4816
4834
  type: row.channel_type,
4817
4835
  parameters: row.channel_parameters ?? {}
@@ -4841,7 +4859,7 @@ function rowToRemoteRecord(row) {
4841
4859
  function remoteRecordToRow(remote) {
4842
4860
  return {
4843
4861
  name: remote.name,
4844
- collection_id: remote.collectionId,
4862
+ collection_id: remote.collectionId.key,
4845
4863
  channel_type: remote.channelConfig.type,
4846
4864
  channel_id: remote.id,
4847
4865
  remote_name: remote.name,
@@ -4994,7 +5012,7 @@ var BatchAggregator = class {
4994
5012
  if (!this.driveContainerTypes.has(op.context.documentType)) continue;
4995
5013
  const input = action.input;
4996
5014
  if (!input?.sourceId || !input.targetId) continue;
4997
- const collectionId = driveCollectionId(op.context.branch, input.sourceId);
5015
+ const collectionId = DriveCollectionId.forDrive(input.sourceId, op.context.branch).key;
4998
5016
  if (!(input.targetId in mergedMemberships)) mergedMemberships[input.targetId] = [];
4999
5017
  if (!mergedMemberships[input.targetId].includes(collectionId)) mergedMemberships[input.targetId].push(collectionId);
5000
5018
  }
@@ -5361,7 +5379,7 @@ var SyncManager = class {
5361
5379
  }, options = { sinceTimestampUtcMs: "0" }, id) {
5362
5380
  if (this.isShutdown) throw new Error("SyncManager is shutdown and cannot add remotes");
5363
5381
  if (this.remotes.has(name)) throw new Error(`Remote with name '${name}' already exists`);
5364
- this.logger.debug("Adding remote (@name, @collectionId, @channelConfig, @filter, @options, @id)", name, collectionId, channelConfig, filter, options, id);
5382
+ this.logger.debug("Adding remote (@name, @collectionId, @channelConfig, @filter, @options, @id)", name, collectionId.key, channelConfig, filter, options, id);
5365
5383
  const remoteId = id ?? crypto.randomUUID();
5366
5384
  const remoteRecord = {
5367
5385
  id: remoteId,
@@ -5519,7 +5537,7 @@ var SyncManager = class {
5519
5537
  this.logger.debug("Loaded @count persisted dead letters for remote @name", records.length, remote.name);
5520
5538
  }
5521
5539
  getRemotesForCollection(collectionId) {
5522
- return Array.from(this.remotes.values()).filter((remote) => remote.collectionId === collectionId);
5540
+ return Array.from(this.remotes.values()).filter((remote) => remote.collectionId.key === collectionId);
5523
5541
  }
5524
5542
  async processCompleteBatch(batch) {
5525
5543
  if (this.isShutdown) return;
@@ -5702,7 +5720,7 @@ var SyncManager = class {
5702
5720
  }
5703
5721
  remote.channel.outbox.add(...syncOps);
5704
5722
  };
5705
- let page = await this.operationIndex.find(remote.collectionId, ackOrdinal, { excludeSourceRemote: remote.name }, void 0, composedSignal);
5723
+ let page = await this.operationIndex.find(remote.collectionId.key, ackOrdinal, { excludeSourceRemote: remote.name }, void 0, composedSignal);
5706
5724
  let carry = [];
5707
5725
  let hasMore;
5708
5726
  do {
@@ -6021,6 +6039,7 @@ var Reactor = class {
6021
6039
  };
6022
6040
  const jobInfo = {
6023
6041
  id: jobId,
6042
+ documentId: job.documentId,
6024
6043
  status: JobStatus.PENDING,
6025
6044
  createdAtUtcIso,
6026
6045
  consistencyToken: {
@@ -6059,6 +6078,7 @@ var Reactor = class {
6059
6078
  };
6060
6079
  const jobInfo = {
6061
6080
  id: jobId,
6081
+ documentId: job.documentId,
6062
6082
  status: JobStatus.PENDING,
6063
6083
  createdAtUtcIso,
6064
6084
  consistencyToken: {
@@ -6096,6 +6116,7 @@ var Reactor = class {
6096
6116
  };
6097
6117
  const jobInfo = {
6098
6118
  id: jobId,
6119
+ documentId: job.documentId,
6099
6120
  status: JobStatus.PENDING,
6100
6121
  createdAtUtcIso,
6101
6122
  consistencyToken: {
@@ -6135,6 +6156,7 @@ var Reactor = class {
6135
6156
  };
6136
6157
  const jobInfo = {
6137
6158
  id: jobId,
6159
+ documentId: job.documentId,
6138
6160
  status: JobStatus.PENDING,
6139
6161
  createdAtUtcIso,
6140
6162
  consistencyToken: {
@@ -6169,6 +6191,7 @@ var Reactor = class {
6169
6191
  for (const jobPlan of request.jobs) {
6170
6192
  const jobInfo = {
6171
6193
  id: planKeyToJobId.get(jobPlan.key),
6194
+ documentId: jobPlan.documentId,
6172
6195
  status: JobStatus.PENDING,
6173
6196
  createdAtUtcIso,
6174
6197
  consistencyToken: {
@@ -6238,6 +6261,7 @@ var Reactor = class {
6238
6261
  for (const jobPlan of request.jobs) {
6239
6262
  const jobInfo = {
6240
6263
  id: planKeyToJobId.get(jobPlan.key),
6264
+ documentId: jobPlan.documentId,
6241
6265
  status: JobStatus.PENDING,
6242
6266
  createdAtUtcIso,
6243
6267
  consistencyToken: {
@@ -6310,6 +6334,7 @@ var Reactor = class {
6310
6334
  const now = (/* @__PURE__ */ new Date()).toISOString();
6311
6335
  return Promise.resolve({
6312
6336
  id: jobId,
6337
+ documentId: "",
6313
6338
  status: JobStatus.FAILED,
6314
6339
  createdAtUtcIso: now,
6315
6340
  completedAtUtcIso: now,
@@ -6785,7 +6810,7 @@ var ReactorBuilder = class {
6785
6810
  const [{ WorkerHandle }, { createThreadTransport }, { workerEntryPath }] = await Promise.all([
6786
6811
  import("./worker-handle-B1w03nRA.js"),
6787
6812
  import("./transport-ByGviWdZ.js"),
6788
- import("./worker-SUoDhurA.js").then((n) => n.n)
6813
+ import("./worker-XYrQaEmt.js").then((n) => n.n)
6789
6814
  ]);
6790
6815
  const db = this.workerDbConfig;
6791
6816
  const signatureVerifier = this.workerSignatureVerifierSpec;
@@ -7152,6 +7177,6 @@ var DocumentIntegrityService = class {
7152
7177
  }
7153
7178
  };
7154
7179
  //#endregion
7155
- export { BaseReadModel, ChannelError, ChannelErrorSource, ChannelScheme, ConsistencyTracker, DEFAULT_DRIVE_CONTAINER_TYPES, DefaultSubscriptionErrorHandler, DocumentChangeType, DocumentIntegrityService, DocumentModelRegistry, DocumentModelResolver, DriveClient, 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, ModuleNotFoundError, NullDocumentModelResolver, OptimisticLockError, PollBehavior, PollingChannelError, ProcessorManager, PropagationMode, QueueEventTypes, REACTOR_SCHEMA, Reactor, ReactorBuilder, ReactorClient, ReactorClientBuilder, ReactorEventTypes, ReactorSubscriptionManager, ReadModelCoordinator, RelationalDbProcessor, RelationshipChangeType, RevisionMismatchError, SimpleJobExecutorManager, SyncBuilder, SyncEventTypes, SyncOperation, SyncOperationAggregateError, SyncOperationStatus, SyncStatus, SyncStatusTracker, addRelationshipAction, batchOperationsByDocument, consolidateSyncOperations, createDocumentAction, createForwardingLogger, createMutableShutdownStatus, createRelationalDb, deleteDocumentAction, documentActions, driveCollectionId, driveIdFromUrl, envelopesToSyncOperations, errorToInfo, getMigrationStatus, instrumentPgPool, makeConsistencyKey, parseDriveUrl, parsePagingOptions, removeRelationshipAction, runMigrations, sanitizeArg, trimMailboxFromAckOrdinal, updateRelationshipAction, upgradeDocumentAction, workerEntryPath };
7180
+ export { BaseReadModel, ChannelError, ChannelErrorSource, ChannelScheme, ConsistencyTracker, DEFAULT_DRIVE_CONTAINER_TYPES, DefaultSubscriptionErrorHandler, DocumentChangeType, 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, ModuleNotFoundError, NullDocumentModelResolver, OptimisticLockError, PollBehavior, PollingChannelError, ProcessorManager, PropagationMode, QueueEventTypes, REACTOR_SCHEMA, Reactor, ReactorBuilder, ReactorClient, ReactorClientBuilder, ReactorEventTypes, ReactorSubscriptionManager, ReadModelCoordinator, RelationalDbProcessor, RelationshipChangeType, RevisionMismatchError, SimpleJobExecutorManager, SyncBuilder, SyncEventTypes, SyncOperation, SyncOperationAggregateError, SyncOperationStatus, SyncStatus, SyncStatusTracker, addRelationshipAction, batchOperationsByDocument, consolidateSyncOperations, createDocumentAction, createForwardingLogger, createMutableShutdownStatus, createRelationalDb, deleteDocumentAction, documentActions, driveIdFromUrl, envelopesToSyncOperations, errorToInfo, getMigrationStatus, instrumentPgPool, makeConsistencyKey, parseDriveUrl, parsePagingOptions, removeRelationshipAction, runMigrations, sanitizeArg, trimMailboxFromAckOrdinal, updateRelationshipAction, upgradeDocumentAction, workerEntryPath };
7156
7181
 
7157
7182
  //# sourceMappingURL=index.js.map