@powerhousedao/reactor 6.2.3-dev.50 → 6.2.3-dev.51

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.
Files changed (30) hide show
  1. package/dist/{document-indexer-DwAMDVRI.js → document-indexer-3fkVWCaN.js} +26 -14
  2. package/dist/document-indexer-3fkVWCaN.js.map +1 -0
  3. package/dist/{drive-container-types-Ci1pdv4X.js → drive-container-types-BAfFzBOf.js} +133 -7
  4. package/dist/drive-container-types-BAfFzBOf.js.map +1 -0
  5. package/dist/entry.js +2 -2
  6. package/dist/{forwarding-logger-ByfBFgMS.js → forwarding-logger-B9LLXItm.js} +111 -79
  7. package/dist/forwarding-logger-B9LLXItm.js.map +1 -0
  8. package/dist/{index-CNhT69De.d.ts → index-dDm0fUBT.d.ts} +518 -68
  9. package/dist/index-dDm0fUBT.d.ts.map +1 -0
  10. package/dist/index.d.ts +1040 -138
  11. package/dist/index.d.ts.map +1 -1
  12. package/dist/index.js +3110 -776
  13. package/dist/index.js.map +1 -1
  14. package/dist/projection-entry.js +2 -2
  15. package/dist/{projection-shard-manager-CQ5FwQmv.js → projection-shard-manager-Drl9w8Eo.js} +3 -13
  16. package/dist/projection-shard-manager-Drl9w8Eo.js.map +1 -0
  17. package/dist/rpc.d.ts +32 -6
  18. package/dist/rpc.d.ts.map +1 -1
  19. package/dist/rpc.js +8 -4
  20. package/dist/rpc.js.map +1 -1
  21. package/dist/{worker-handle-CN2-oRv-.js → worker-handle-Nso8i5eU.js} +2 -2
  22. package/dist/{worker-handle-CN2-oRv-.js.map → worker-handle-Nso8i5eU.js.map} +1 -1
  23. package/dist/worker-pool-router-BROOEQSE.js +35 -0
  24. package/dist/worker-pool-router-BROOEQSE.js.map +1 -0
  25. package/package.json +3 -3
  26. package/dist/document-indexer-DwAMDVRI.js.map +0 -1
  27. package/dist/drive-container-types-Ci1pdv4X.js.map +0 -1
  28. package/dist/forwarding-logger-ByfBFgMS.js.map +0 -1
  29. package/dist/index-CNhT69De.d.ts.map +0 -1
  30. package/dist/projection-shard-manager-CQ5FwQmv.js.map +0 -1
package/dist/entry.js CHANGED
@@ -1,5 +1,5 @@
1
- import { D as CollectionMembershipCache, E as DocumentMetaCache, St as ReactorEventTypes, a as REACTOR_SCHEMA, d as KyselyKeyframeStore, f as EventBus, l as instrumentPgPool, m as KyselyOperationIndex, n as errorToInfo, p as KyselyWriteCache, t as createForwardingLogger, u as KyselyOperationStore } from "./forwarding-logger-ByfBFgMS.js";
2
- import { a as KyselyExecutionScope, n as SimpleJobExecutor, t as DEFAULT_DRIVE_CONTAINER_TYPES } from "./drive-container-types-Ci1pdv4X.js";
1
+ import { Ct as ReactorEventTypes, D as CollectionMembershipCache, E as DocumentMetaCache, a as REACTOR_SCHEMA, d as KyselyKeyframeStore, f as EventBus, l as instrumentPgPool, m as KyselyOperationIndex, n as errorToInfo, p as KyselyWriteCache, t as createForwardingLogger, u as KyselyOperationStore } from "./forwarding-logger-B9LLXItm.js";
2
+ import { n as SimpleJobExecutor, s as KyselyExecutionScope, t as DEFAULT_DRIVE_CONTAINER_TYPES } from "./drive-container-types-BAfFzBOf.js";
3
3
  import { n as loadDocumentModelSpec, r as DocumentModelRegistry, t as defaultLoadFactory } from "./load-spec-ZLjuyhxz.js";
4
4
  import { ConsoleLogger } from "document-model";
5
5
  import { isMainThread, parentPort } from "node:worker_threads";
@@ -27,6 +27,22 @@ const defaultAbortError = () => /* @__PURE__ */ new Error("Operation aborted");
27
27
  function throwIfAborted(signal, makeError = defaultAbortError) {
28
28
  if (signal?.aborted) throw makeError();
29
29
  }
30
+ const TIMED_OUT = Symbol("deadline-expired");
31
+ /** Races a call that cannot be cancelled; on {@link TIMED_OUT} the call may still settle later. */
32
+ async function withDeadline(pending, timeoutMs) {
33
+ let handle;
34
+ const expiry = new Promise((resolve) => {
35
+ handle = setTimeout(() => resolve(TIMED_OUT), timeoutMs);
36
+ });
37
+ try {
38
+ return await Promise.race([pending, expiry]);
39
+ } finally {
40
+ clearTimeout(handle);
41
+ }
42
+ }
43
+ function delay(ms) {
44
+ return new Promise((resolve) => setTimeout(resolve, ms));
45
+ }
30
46
  /**
31
47
  * Validates PagingOptions and returns a normalized offset and limit.
32
48
  * Throws if the cursor is not empty and not a non-negative integer, or if
@@ -87,6 +103,8 @@ const ReactorEventTypes = {
87
103
  /**
88
104
  * Error thrown when attempting to access a deleted document.
89
105
  */
106
+ /** The error name on a job the reactor does not know. */
107
+ const JOB_NOT_FOUND_ERROR_NAME = "JobNotFoundError";
90
108
  var DocumentDeletedError = class DocumentDeletedError extends Error {
91
109
  documentId;
92
110
  deletedAtUtcIso;
@@ -2998,8 +3016,8 @@ function createForwardingPoolInstrumentation(name) {
2998
3016
  }
2999
3017
  //#endregion
3000
3018
  //#region src/storage/migrations/001_create_operation_table.ts
3001
- var _001_create_operation_table_exports = /* @__PURE__ */ __exportAll({ up: () => up$25 });
3002
- async function up$25(db) {
3019
+ var _001_create_operation_table_exports = /* @__PURE__ */ __exportAll({ up: () => up$26 });
3020
+ async function up$26(db) {
3003
3021
  await db.schema.createTable("Operation").addColumn("id", "serial", (col) => col.primaryKey()).addColumn("jobId", "text", (col) => col.notNull()).addColumn("opId", "text", (col) => col.notNull()).addColumn("prevOpId", "text", (col) => col.notNull()).addColumn("writeTimestampUtcMs", "timestamptz", (col) => col.notNull().defaultTo(sql`NOW()`)).addColumn("documentId", "text", (col) => col.notNull()).addColumn("documentType", "text", (col) => col.notNull()).addColumn("scope", "text", (col) => col.notNull()).addColumn("branch", "text", (col) => col.notNull()).addColumn("timestampUtcMs", "timestamptz", (col) => col.notNull()).addColumn("index", "integer", (col) => col.notNull()).addColumn("action", "jsonb", (col) => col.notNull()).addColumn("skip", "integer", (col) => col.notNull()).addColumn("error", "text").addColumn("hash", "text", (col) => col.notNull()).addUniqueConstraint("unique_revision", [
3004
3022
  "documentId",
3005
3023
  "scope",
@@ -3024,8 +3042,8 @@ async function up$25(db) {
3024
3042
  }
3025
3043
  //#endregion
3026
3044
  //#region src/storage/migrations/002_create_keyframe_table.ts
3027
- var _002_create_keyframe_table_exports = /* @__PURE__ */ __exportAll({ up: () => up$24 });
3028
- async function up$24(db) {
3045
+ var _002_create_keyframe_table_exports = /* @__PURE__ */ __exportAll({ up: () => up$25 });
3046
+ async function up$25(db) {
3029
3047
  await db.schema.createTable("Keyframe").addColumn("id", "serial", (col) => col.primaryKey()).addColumn("documentId", "text", (col) => col.notNull()).addColumn("documentType", "text", (col) => col.notNull()).addColumn("scope", "text", (col) => col.notNull()).addColumn("branch", "text", (col) => col.notNull()).addColumn("revision", "integer", (col) => col.notNull()).addColumn("document", "jsonb", (col) => col.notNull()).addColumn("createdAt", "timestamptz", (col) => col.notNull().defaultTo(sql`NOW()`)).addUniqueConstraint("unique_keyframe", [
3030
3048
  "documentId",
3031
3049
  "scope",
@@ -3041,14 +3059,14 @@ async function up$24(db) {
3041
3059
  }
3042
3060
  //#endregion
3043
3061
  //#region src/storage/migrations/003_create_document_table.ts
3044
- var _003_create_document_table_exports = /* @__PURE__ */ __exportAll({ up: () => up$23 });
3045
- async function up$23(db) {
3062
+ var _003_create_document_table_exports = /* @__PURE__ */ __exportAll({ up: () => up$24 });
3063
+ async function up$24(db) {
3046
3064
  await db.schema.createTable("Document").addColumn("id", "text", (col) => col.primaryKey()).addColumn("createdAt", "timestamptz", (col) => col.notNull().defaultTo(sql`NOW()`)).addColumn("updatedAt", "timestamptz", (col) => col.notNull().defaultTo(sql`NOW()`)).execute();
3047
3065
  }
3048
3066
  //#endregion
3049
3067
  //#region src/storage/migrations/004_create_document_relationship_table.ts
3050
- var _004_create_document_relationship_table_exports = /* @__PURE__ */ __exportAll({ up: () => up$22 });
3051
- async function up$22(db) {
3068
+ var _004_create_document_relationship_table_exports = /* @__PURE__ */ __exportAll({ up: () => up$23 });
3069
+ async function up$23(db) {
3052
3070
  await db.schema.createTable("DocumentRelationship").addColumn("id", "text", (col) => col.primaryKey()).addColumn("sourceId", "text", (col) => col.notNull().references("Document.id").onDelete("cascade")).addColumn("targetId", "text", (col) => col.notNull().references("Document.id").onDelete("cascade")).addColumn("relationshipType", "text", (col) => col.notNull()).addColumn("metadata", "jsonb").addColumn("createdAt", "timestamptz", (col) => col.notNull().defaultTo(sql`NOW()`)).addColumn("updatedAt", "timestamptz", (col) => col.notNull().defaultTo(sql`NOW()`)).addUniqueConstraint("unique_source_target_type", [
3053
3071
  "sourceId",
3054
3072
  "targetId",
@@ -3060,14 +3078,14 @@ async function up$22(db) {
3060
3078
  }
3061
3079
  //#endregion
3062
3080
  //#region src/storage/migrations/005_create_indexer_state_table.ts
3063
- var _005_create_indexer_state_table_exports = /* @__PURE__ */ __exportAll({ up: () => up$21 });
3064
- async function up$21(db) {
3081
+ var _005_create_indexer_state_table_exports = /* @__PURE__ */ __exportAll({ up: () => up$22 });
3082
+ async function up$22(db) {
3065
3083
  await db.schema.createTable("IndexerState").addColumn("id", "integer", (col) => col.primaryKey().generatedAlwaysAsIdentity()).addColumn("lastOperationId", "integer", (col) => col.notNull()).addColumn("lastOperationTimestamp", "timestamptz", (col) => col.notNull().defaultTo(sql`NOW()`)).execute();
3066
3084
  }
3067
3085
  //#endregion
3068
3086
  //#region src/storage/migrations/006_create_document_snapshot_table.ts
3069
- var _006_create_document_snapshot_table_exports = /* @__PURE__ */ __exportAll({ up: () => up$20 });
3070
- async function up$20(db) {
3087
+ var _006_create_document_snapshot_table_exports = /* @__PURE__ */ __exportAll({ up: () => up$21 });
3088
+ async function up$21(db) {
3071
3089
  await db.schema.createTable("DocumentSnapshot").addColumn("id", "text", (col) => col.primaryKey()).addColumn("documentId", "text", (col) => col.notNull()).addColumn("slug", "text").addColumn("name", "text").addColumn("scope", "text", (col) => col.notNull()).addColumn("branch", "text", (col) => col.notNull()).addColumn("content", "jsonb", (col) => col.notNull()).addColumn("documentType", "text", (col) => col.notNull()).addColumn("lastOperationIndex", "integer", (col) => col.notNull()).addColumn("lastOperationHash", "text", (col) => col.notNull()).addColumn("lastUpdatedAt", "timestamptz", (col) => col.notNull().defaultTo(sql`NOW()`)).addColumn("snapshotVersion", "integer", (col) => col.notNull().defaultTo(1)).addColumn("identifiers", "jsonb").addColumn("metadata", "jsonb").addColumn("isDeleted", "boolean", (col) => col.notNull().defaultTo(false)).addColumn("deletedAt", "timestamptz").addUniqueConstraint("unique_doc_scope_branch", [
3072
3090
  "documentId",
3073
3091
  "scope",
@@ -3088,8 +3106,8 @@ async function up$20(db) {
3088
3106
  }
3089
3107
  //#endregion
3090
3108
  //#region src/storage/migrations/007_create_slug_mapping_table.ts
3091
- var _007_create_slug_mapping_table_exports = /* @__PURE__ */ __exportAll({ up: () => up$19 });
3092
- async function up$19(db) {
3109
+ var _007_create_slug_mapping_table_exports = /* @__PURE__ */ __exportAll({ up: () => up$20 });
3110
+ async function up$20(db) {
3093
3111
  await db.schema.createTable("SlugMapping").addColumn("slug", "text", (col) => col.primaryKey()).addColumn("documentId", "text", (col) => col.notNull()).addColumn("scope", "text", (col) => col.notNull()).addColumn("branch", "text", (col) => col.notNull()).addColumn("createdAt", "timestamptz", (col) => col.notNull().defaultTo(sql`NOW()`)).addColumn("updatedAt", "timestamptz", (col) => col.notNull().defaultTo(sql`NOW()`)).addUniqueConstraint("unique_docid_scope_branch", [
3094
3112
  "documentId",
3095
3113
  "scope",
@@ -3099,14 +3117,14 @@ async function up$19(db) {
3099
3117
  }
3100
3118
  //#endregion
3101
3119
  //#region src/storage/migrations/008_create_view_state_table.ts
3102
- var _008_create_view_state_table_exports = /* @__PURE__ */ __exportAll({ up: () => up$18 });
3103
- async function up$18(db) {
3120
+ var _008_create_view_state_table_exports = /* @__PURE__ */ __exportAll({ up: () => up$19 });
3121
+ async function up$19(db) {
3104
3122
  await db.schema.createTable("ViewState").addColumn("readModelId", "text", (col) => col.primaryKey()).addColumn("lastOrdinal", "integer", (col) => col.notNull().defaultTo(0)).addColumn("lastOperationTimestamp", "timestamptz", (col) => col.notNull().defaultTo(sql`NOW()`)).execute();
3105
3123
  }
3106
3124
  //#endregion
3107
3125
  //#region src/storage/migrations/009_create_operation_index_tables.ts
3108
- var _009_create_operation_index_tables_exports = /* @__PURE__ */ __exportAll({ up: () => up$17 });
3109
- async function up$17(db) {
3126
+ var _009_create_operation_index_tables_exports = /* @__PURE__ */ __exportAll({ up: () => up$18 });
3127
+ async function up$18(db) {
3110
3128
  await db.schema.createTable("document_collections").addColumn("documentId", "text", (col) => col.notNull()).addColumn("collectionId", "text", (col) => col.notNull()).addColumn("joinedOrdinal", "bigint", (col) => col.notNull().defaultTo(0)).addColumn("leftOrdinal", "bigint").addPrimaryKeyConstraint("document_collections_pkey", ["documentId", "collectionId"]).execute();
3111
3129
  await db.schema.createIndex("idx_document_collections_collectionId").on("document_collections").column("collectionId").execute();
3112
3130
  await db.schema.createIndex("idx_doc_collections_collection_range").on("document_collections").columns(["collectionId", "joinedOrdinal"]).execute();
@@ -3120,8 +3138,8 @@ async function up$17(db) {
3120
3138
  }
3121
3139
  //#endregion
3122
3140
  //#region src/storage/migrations/010_create_sync_tables.ts
3123
- var _010_create_sync_tables_exports = /* @__PURE__ */ __exportAll({ up: () => up$16 });
3124
- async function up$16(db) {
3141
+ var _010_create_sync_tables_exports = /* @__PURE__ */ __exportAll({ up: () => up$17 });
3142
+ async function up$17(db) {
3125
3143
  await db.schema.createTable("sync_remotes").addColumn("name", "text", (col) => col.primaryKey()).addColumn("collection_id", "text", (col) => col.notNull()).addColumn("channel_type", "text", (col) => col.notNull()).addColumn("channel_id", "text", (col) => col.notNull().defaultTo("")).addColumn("remote_name", "text", (col) => col.notNull().defaultTo("")).addColumn("channel_parameters", "jsonb", (col) => col.notNull().defaultTo(sql`'{}'::jsonb`)).addColumn("filter_document_ids", "jsonb").addColumn("filter_scopes", "jsonb").addColumn("filter_branch", "text", (col) => col.notNull().defaultTo("main")).addColumn("push_state", "text", (col) => col.notNull().defaultTo("idle")).addColumn("push_last_success_utc_ms", "text").addColumn("push_last_failure_utc_ms", "text").addColumn("push_failure_count", "integer", (col) => col.notNull().defaultTo(0)).addColumn("pull_state", "text", (col) => col.notNull().defaultTo("idle")).addColumn("pull_last_success_utc_ms", "text").addColumn("pull_last_failure_utc_ms", "text").addColumn("pull_failure_count", "integer", (col) => col.notNull().defaultTo(0)).addColumn("created_at", "timestamptz", (col) => col.notNull().defaultTo(sql`NOW()`)).addColumn("updated_at", "timestamptz", (col) => col.notNull().defaultTo(sql`NOW()`)).execute();
3126
3144
  await db.schema.createIndex("idx_sync_remotes_collection").on("sync_remotes").column("collection_id").execute();
3127
3145
  await db.schema.createTable("sync_cursors").addColumn("remote_name", "text", (col) => col.primaryKey().references("sync_remotes.name").onDelete("cascade")).addColumn("cursor_ordinal", "bigint", (col) => col.notNull().defaultTo(0)).addColumn("last_synced_at_utc_ms", "text").addColumn("updated_at", "timestamptz", (col) => col.notNull().defaultTo(sql`NOW()`)).execute();
@@ -3129,8 +3147,8 @@ async function up$16(db) {
3129
3147
  }
3130
3148
  //#endregion
3131
3149
  //#region src/storage/migrations/011_add_cursor_type_column.ts
3132
- var _011_add_cursor_type_column_exports = /* @__PURE__ */ __exportAll({ up: () => up$15 });
3133
- async function up$15(db) {
3150
+ var _011_add_cursor_type_column_exports = /* @__PURE__ */ __exportAll({ up: () => up$16 });
3151
+ async function up$16(db) {
3134
3152
  await db.deleteFrom("sync_cursors").where("remote_name", "like", "outbox::%").execute();
3135
3153
  await db.deleteFrom("sync_remotes").where("name", "like", "outbox::%").execute();
3136
3154
  await db.schema.dropTable("sync_cursors").execute();
@@ -3139,64 +3157,64 @@ async function up$15(db) {
3139
3157
  }
3140
3158
  //#endregion
3141
3159
  //#region src/storage/migrations/012_add_source_remote_column.ts
3142
- var _012_add_source_remote_column_exports = /* @__PURE__ */ __exportAll({ up: () => up$14 });
3143
- async function up$14(db) {
3160
+ var _012_add_source_remote_column_exports = /* @__PURE__ */ __exportAll({ up: () => up$15 });
3161
+ async function up$15(db) {
3144
3162
  await db.schema.alterTable("operation_index_operations").addColumn("sourceRemote", "text", (col) => col.notNull().defaultTo("")).execute();
3145
3163
  }
3146
3164
  //#endregion
3147
3165
  //#region src/storage/migrations/013_create_sync_dead_letters_table.ts
3148
- var _013_create_sync_dead_letters_table_exports = /* @__PURE__ */ __exportAll({ up: () => up$13 });
3149
- async function up$13(db) {
3166
+ var _013_create_sync_dead_letters_table_exports = /* @__PURE__ */ __exportAll({ up: () => up$14 });
3167
+ async function up$14(db) {
3150
3168
  await db.schema.createTable("sync_dead_letters").addColumn("ordinal", "serial", (col) => col.primaryKey()).addColumn("id", "text", (col) => col.unique().notNull()).addColumn("job_id", "text", (col) => col.notNull()).addColumn("job_dependencies", "jsonb", (col) => col.notNull().defaultTo(sql`'[]'::jsonb`)).addColumn("remote_name", "text", (col) => col.notNull().references("sync_remotes.name").onDelete("cascade")).addColumn("document_id", "text", (col) => col.notNull()).addColumn("scopes", "jsonb", (col) => col.notNull().defaultTo(sql`'[]'::jsonb`)).addColumn("branch", "text", (col) => col.notNull()).addColumn("operations", "jsonb", (col) => col.notNull().defaultTo(sql`'[]'::jsonb`)).addColumn("error_source", "text", (col) => col.notNull()).addColumn("error_message", "text", (col) => col.notNull()).addColumn("created_at", "timestamptz", (col) => col.notNull().defaultTo(sql`NOW()`)).execute();
3151
3169
  await db.schema.createIndex("idx_sync_dead_letters_remote").on("sync_dead_letters").column("remote_name").execute();
3152
3170
  }
3153
3171
  //#endregion
3154
3172
  //#region src/storage/migrations/014_create_processor_cursor_table.ts
3155
- var _014_create_processor_cursor_table_exports = /* @__PURE__ */ __exportAll({ up: () => up$12 });
3156
- async function up$12(db) {
3173
+ var _014_create_processor_cursor_table_exports = /* @__PURE__ */ __exportAll({ up: () => up$13 });
3174
+ async function up$13(db) {
3157
3175
  await db.schema.createTable("ProcessorCursor").addColumn("processorId", "text", (col) => col.primaryKey()).addColumn("factoryId", "text", (col) => col.notNull()).addColumn("driveId", "text", (col) => col.notNull()).addColumn("processorIndex", "integer", (col) => col.notNull()).addColumn("lastOrdinal", "integer", (col) => col.notNull().defaultTo(sql`0`)).addColumn("status", "text", (col) => col.notNull().defaultTo(sql`'active'`)).addColumn("lastError", "text").addColumn("lastErrorTimestamp", "timestamptz").addColumn("createdAt", "timestamptz", (col) => col.notNull().defaultTo(sql`NOW()`)).addColumn("updatedAt", "timestamptz", (col) => col.notNull().defaultTo(sql`NOW()`)).execute();
3158
3176
  }
3159
3177
  //#endregion
3160
3178
  //#region src/storage/migrations/015_add_operation_denied_reason.ts
3161
3179
  var _015_add_operation_denied_reason_exports = /* @__PURE__ */ __exportAll({
3162
- down: () => down$11,
3163
- up: () => up$11
3180
+ down: () => down$12,
3181
+ up: () => up$12
3164
3182
  });
3165
3183
  /**
3166
3184
  * Records why authorization refused an operation. Separate from `error` so a
3167
3185
  * denial is distinguishable from a reducer failure without matching on a
3168
3186
  * message. Null for every operation written before decisions were enforced.
3169
3187
  */
3170
- async function up$11(db) {
3188
+ async function up$12(db) {
3171
3189
  await db.schema.alterTable("Operation").addColumn("deniedReason", "text").execute();
3172
3190
  await db.schema.alterTable("operation_index_operations").addColumn("deniedReason", "text").execute();
3173
3191
  }
3174
- async function down$11(db) {
3192
+ async function down$12(db) {
3175
3193
  await db.schema.alterTable("operation_index_operations").dropColumn("deniedReason").execute();
3176
3194
  await db.schema.alterTable("Operation").dropColumn("deniedReason").execute();
3177
3195
  }
3178
3196
  //#endregion
3179
3197
  //#region src/storage/migrations/016_add_dead_letter_error_type.ts
3180
3198
  var _016_add_dead_letter_error_type_exports = /* @__PURE__ */ __exportAll({
3181
- down: () => down$10,
3182
- up: () => up$10
3199
+ down: () => down$11,
3200
+ up: () => up$11
3183
3201
  });
3184
3202
  /**
3185
3203
  * The classification a dead letter falls into, stored because it decides whether
3186
3204
  * the document stays quarantined and the in-memory error is gone after a restart.
3187
3205
  * Defaulted rather than nullable, so a pre-existing row rehydrates.
3188
3206
  */
3189
- async function up$10(db) {
3207
+ async function up$11(db) {
3190
3208
  await db.schema.alterTable("sync_dead_letters").addColumn("error_type", "text", (col) => col.notNull().defaultTo("UNCLASSIFIED")).execute();
3191
3209
  }
3192
- async function down$10(db) {
3210
+ async function down$11(db) {
3193
3211
  await db.schema.alterTable("sync_dead_letters").dropColumn("error_type").execute();
3194
3212
  }
3195
3213
  //#endregion
3196
3214
  //#region src/storage/migrations/017_create_group_references.ts
3197
3215
  var _017_create_group_references_exports = /* @__PURE__ */ __exportAll({
3198
- down: () => down$9,
3199
- up: () => up$9
3216
+ down: () => down$10,
3217
+ up: () => up$10
3200
3218
  });
3201
3219
  /**
3202
3220
  * One row per (document, group) reference ever discovered from an auth
@@ -3207,18 +3225,18 @@ var _017_create_group_references_exports = /* @__PURE__ */ __exportAll({
3207
3225
  * requires (sync), and by groupId for the documents a group change affects
3208
3226
  * (re-evaluation).
3209
3227
  */
3210
- async function up$9(db) {
3228
+ async function up$10(db) {
3211
3229
  await db.schema.createTable("group_references").addColumn("documentId", "text", (col) => col.notNull()).addColumn("groupId", "text", (col) => col.notNull()).addPrimaryKeyConstraint("group_references_pkey", ["documentId", "groupId"]).execute();
3212
3230
  await db.schema.createIndex("idx_group_references_groupId").on("group_references").column("groupId").execute();
3213
3231
  }
3214
- async function down$9(db) {
3232
+ async function down$10(db) {
3215
3233
  await db.schema.dropTable("group_references").execute();
3216
3234
  }
3217
3235
  //#endregion
3218
3236
  //#region src/storage/migrations/018_add_sync_remote_bound_address.ts
3219
3237
  var _018_add_sync_remote_bound_address_exports = /* @__PURE__ */ __exportAll({
3220
- down: () => down$8,
3221
- up: () => up$8
3238
+ down: () => down$9,
3239
+ up: () => up$9
3222
3240
  });
3223
3241
  /**
3224
3242
  * The address a sync channel is bound to, so a channel created by one subject
@@ -3229,17 +3247,17 @@ var _018_add_sync_remote_bound_address_exports = /* @__PURE__ */ __exportAll({
3229
3247
  * until its first authenticated poll adopts it. A default would claim them all
3230
3248
  * for one address.
3231
3249
  */
3232
- async function up$8(db) {
3250
+ async function up$9(db) {
3233
3251
  await db.schema.alterTable("sync_remotes").addColumn("bound_address", "text").execute();
3234
3252
  }
3235
- async function down$8(db) {
3253
+ async function down$9(db) {
3236
3254
  await db.schema.alterTable("sync_remotes").dropColumn("bound_address").execute();
3237
3255
  }
3238
3256
  //#endregion
3239
3257
  //#region src/storage/migrations/019_require_action_id.ts
3240
3258
  var _019_require_action_id_exports = /* @__PURE__ */ __exportAll({
3241
- down: () => down$7,
3242
- up: () => up$7
3259
+ down: () => down$8,
3260
+ up: () => up$8
3243
3261
  });
3244
3262
  /**
3245
3263
  * Makes an operation whose action carries no id physically unstorable.
@@ -3266,7 +3284,7 @@ var _019_require_action_id_exports = /* @__PURE__ */ __exportAll({
3266
3284
  * The empty string is rejected alongside null. It derives the same colliding
3267
3285
  * operation id as an absent id, so admitting it would leave the hole open.
3268
3286
  */
3269
- async function up$7(db) {
3287
+ async function up$8(db) {
3270
3288
  await db.updateTable("Operation").set({ action: sql`jsonb_set(action, '{id}', to_jsonb(gen_random_uuid()::text))` }).where(sql`jsonb_typeof(action) = 'object' and coalesce(action->>'id', '') = ''`).execute();
3271
3289
  await db.updateTable("operation_index_operations as oio").from("Operation as op").set({ action: sql`jsonb_set(oio.action, '{id}', to_jsonb(op.action->>'id'))` }).whereRef("oio.opId", "=", "op.opId").whereRef("oio.index", "=", "op.index").whereRef("oio.skip", "=", "op.skip").where(sql`jsonb_typeof(oio.action) = 'object' and coalesce(oio.action->>'id', '') = ''`).where(sql`coalesce(op.action->>'id', '') <> ''`).execute();
3272
3290
  await db.updateTable("operation_index_operations").set({ action: sql`jsonb_set(action, '{id}', to_jsonb(gen_random_uuid()::text))` }).where(sql`jsonb_typeof(action) = 'object' and coalesce(action->>'id', '') = ''`).execute();
@@ -3278,107 +3296,107 @@ async function up$7(db) {
3278
3296
  * their operations are now known by, and reverting them would reintroduce the
3279
3297
  * collision the migration removed.
3280
3298
  */
3281
- async function down$7(db) {
3299
+ async function down$8(db) {
3282
3300
  await db.schema.alterTable("operation_index_operations").dropConstraint("action_must_have_id").execute();
3283
3301
  await db.schema.alterTable("Operation").dropConstraint("action_must_have_id").execute();
3284
3302
  }
3285
3303
  //#endregion
3286
3304
  //#region src/storage/migrations/020_add_snapshot_operation_ordinal.ts
3287
3305
  var _020_add_snapshot_operation_ordinal_exports = /* @__PURE__ */ __exportAll({
3288
- down: () => down$6,
3289
- up: () => up$6
3306
+ down: () => down$7,
3307
+ up: () => up$7
3290
3308
  });
3291
3309
  /** Orders header row writes across scopes; `lastOperationIndex` is per scope. */
3292
- async function up$6(db) {
3310
+ async function up$7(db) {
3293
3311
  await db.schema.alterTable("DocumentSnapshot").addColumn("lastOperationOrdinal", "integer", (col) => col.notNull().defaultTo(0)).execute();
3294
3312
  }
3295
- async function down$6(db) {
3313
+ async function down$7(db) {
3296
3314
  await db.schema.alterTable("DocumentSnapshot").dropColumn("lastOperationOrdinal").execute();
3297
3315
  }
3298
3316
  //#endregion
3299
3317
  //#region src/storage/migrations/021_add_sync_remote_peer.ts
3300
3318
  var _021_add_sync_remote_peer_exports = /* @__PURE__ */ __exportAll({
3301
- down: () => down$5,
3302
- up: () => up$5
3319
+ down: () => down$6,
3320
+ up: () => up$6
3303
3321
  });
3304
3322
  /**
3305
3323
  * The peer's manifest as canonical JSON, and when it was heard. Both null: not
3306
3324
  * yet heard. A time with no manifest: a silent peer, which gets the baselines.
3307
3325
  */
3308
- async function up$5(db) {
3326
+ async function up$6(db) {
3309
3327
  await db.schema.alterTable("sync_remotes").addColumn("peer_manifest", "text").addColumn("peer_manifest_at_utc_ms", "bigint").execute();
3310
3328
  }
3311
- async function down$5(db) {
3329
+ async function down$6(db) {
3312
3330
  await db.schema.alterTable("sync_remotes").dropColumn("peer_manifest").dropColumn("peer_manifest_at_utc_ms").execute();
3313
3331
  }
3314
3332
  //#endregion
3315
3333
  //#region src/storage/migrations/022_create_sync_holds.ts
3316
3334
  var _022_create_sync_holds_exports = /* @__PURE__ */ __exportAll({
3317
- down: () => down$4,
3318
- up: () => up$4
3335
+ down: () => down$5,
3336
+ up: () => up$5
3319
3337
  });
3320
3338
  /** Documents held back from a remote whose peer cannot run their versions. */
3321
- async function up$4(db) {
3339
+ async function up$5(db) {
3322
3340
  await db.schema.createTable("sync_holds").addColumn("remote_name", "text", (col) => col.notNull().references("sync_remotes.name").onDelete("cascade")).addColumn("document_id", "text", (col) => col.notNull()).addColumn("branch", "text", (col) => col.notNull()).addColumn("protocol", "text", (col) => col.notNull()).addColumn("version", "integer", (col) => col.notNull()).addColumn("held_at_utc_ms", "bigint", (col) => col.notNull()).addPrimaryKeyConstraint("sync_holds_pkey", [
3323
3341
  "remote_name",
3324
3342
  "document_id",
3325
3343
  "branch"
3326
3344
  ]).execute();
3327
3345
  }
3328
- async function down$4(db) {
3346
+ async function down$5(db) {
3329
3347
  await db.schema.dropTable("sync_holds").execute();
3330
3348
  }
3331
3349
  //#endregion
3332
3350
  //#region src/storage/migrations/023_index_created_protocol_versions.ts
3333
3351
  var _023_index_created_protocol_versions_exports = /* @__PURE__ */ __exportAll({
3334
- down: () => down$3,
3335
- up: () => up$3
3352
+ down: () => down$4,
3353
+ up: () => up$4
3336
3354
  });
3337
3355
  /**
3338
3356
  * One entry per document created with protocolVersions, keyed by a hash so an
3339
3357
  * oversized header cannot make its creation unstorable. Startup reads the
3340
3358
  * distinct values without visiting every document.
3341
3359
  */
3342
- async function up$3(db) {
3360
+ async function up$4(db) {
3343
3361
  await db.schema.createIndex("idx_operation_created_protocol_versions").on("Operation").expression(sql`md5((action->'input'->'protocolVersions')::text)`).where(sql`scope = 'document' and "index" = 0 and (action->'input'->'protocolVersions') is not null`).execute();
3344
3362
  }
3345
- async function down$3(db) {
3363
+ async function down$4(db) {
3346
3364
  await db.schema.dropIndex("idx_operation_created_protocol_versions").execute();
3347
3365
  }
3348
3366
  //#endregion
3349
3367
  //#region src/storage/migrations/024_create_document_purges.ts
3350
3368
  var _024_create_document_purges_exports = /* @__PURE__ */ __exportAll({
3351
- down: () => down$2,
3352
- up: () => up$2
3369
+ down: () => down$3,
3370
+ up: () => up$3
3353
3371
  });
3354
3372
  /** One row per purged document: the tombstone. Written once, never deleted. */
3355
- async function up$2(db) {
3373
+ async function up$3(db) {
3356
3374
  await db.schema.createTable("document_purges").addColumn("documentId", "text", (col) => col.primaryKey()).addColumn("ordinal", "bigint", (col) => col.notNull()).addColumn("removedRows", "jsonb", (col) => col.notNull()).addColumn("purgedAtUtc", "timestamptz", (col) => col.notNull()).addColumn("requestId", "text", (col) => col.notNull()).execute();
3357
3375
  }
3358
- async function down$2(db) {
3376
+ async function down$3(db) {
3359
3377
  await db.schema.dropTable("document_purges").execute();
3360
3378
  }
3361
3379
  //#endregion
3362
3380
  //#region src/storage/migrations/025_create_sync_received_markers.ts
3363
3381
  var _025_create_sync_received_markers_exports = /* @__PURE__ */ __exportAll({
3364
- down: () => down$1,
3365
- up: () => up$1
3382
+ down: () => down$2,
3383
+ up: () => up$2
3366
3384
  });
3367
3385
  /** Received purge markers awaiting their outcome; removed with their remote. */
3368
- async function up$1(db) {
3386
+ async function up$2(db) {
3369
3387
  await db.schema.createTable("sync_received_markers").addColumn("remote_name", "text", (col) => col.notNull()).addColumn("marker_id", "text", (col) => col.notNull()).addColumn("document_id", "text", (col) => col.notNull()).addColumn("branch", "text", (col) => col.notNull()).addColumn("operation", "jsonb", (col) => col.notNull()).addColumn("received_at_utc_ms", "bigint", (col) => col.notNull()).addPrimaryKeyConstraint("sync_received_markers_pkey", ["remote_name", "marker_id"]).execute();
3370
3388
  }
3371
- async function down$1(db) {
3389
+ async function down$2(db) {
3372
3390
  await db.schema.dropTable("sync_received_markers").execute();
3373
3391
  }
3374
3392
  //#endregion
3375
3393
  //#region src/storage/migrations/026_create_sync_purge_refusals.ts
3376
3394
  var _026_create_sync_purge_refusals_exports = /* @__PURE__ */ __exportAll({
3377
- down: () => down,
3378
- up: () => up
3395
+ down: () => down$1,
3396
+ up: () => up$1
3379
3397
  });
3380
3398
  /** A remote's refusal of a purge marker; payload-free, kept like the tombstone. */
3381
- async function up(db) {
3399
+ async function up$1(db) {
3382
3400
  await db.schema.createTable("sync_purge_refusals").addColumn("remote_name", "text", (col) => col.notNull()).addColumn("document_id", "text", (col) => col.notNull()).addColumn("branch", "text", (col) => col.notNull()).addColumn("refused_at_utc_ms", "bigint", (col) => col.notNull()).addPrimaryKeyConstraint("sync_purge_refusals_pkey", [
3383
3401
  "remote_name",
3384
3402
  "document_id",
@@ -3386,10 +3404,23 @@ async function up(db) {
3386
3404
  ]).execute();
3387
3405
  await db.schema.createIndex("idx_sync_purge_refusals_document").on("sync_purge_refusals").column("document_id").execute();
3388
3406
  }
3389
- async function down(db) {
3407
+ async function down$1(db) {
3390
3408
  await db.schema.dropTable("sync_purge_refusals").execute();
3391
3409
  }
3392
3410
  //#endregion
3411
+ //#region src/storage/migrations/027_add_sync_remote_persistence.ts
3412
+ var _027_add_sync_remote_persistence_exports = /* @__PURE__ */ __exportAll({
3413
+ down: () => down,
3414
+ up: () => up
3415
+ });
3416
+ /** A session remote's row exists so its cursors, holds and dead letters have a parent. */
3417
+ async function up(db) {
3418
+ await db.schema.alterTable("sync_remotes").addColumn("persistence", "text", (col) => col.notNull().defaultTo("durable")).execute();
3419
+ }
3420
+ async function down(db) {
3421
+ await db.schema.alterTable("sync_remotes").dropColumn("persistence").execute();
3422
+ }
3423
+ //#endregion
3393
3424
  //#region src/storage/migrations/migrator.ts
3394
3425
  const REACTOR_SCHEMA = "reactor";
3395
3426
  const migrations = {
@@ -3418,7 +3449,8 @@ const migrations = {
3418
3449
  "023_index_created_protocol_versions": _023_index_created_protocol_versions_exports,
3419
3450
  "024_create_document_purges": _024_create_document_purges_exports,
3420
3451
  "025_create_sync_received_markers": _025_create_sync_received_markers_exports,
3421
- "026_create_sync_purge_refusals": _026_create_sync_purge_refusals_exports
3452
+ "026_create_sync_purge_refusals": _026_create_sync_purge_refusals_exports,
3453
+ "027_add_sync_remote_persistence": _027_add_sync_remote_persistence_exports
3422
3454
  };
3423
3455
  var ProgrammaticMigrationProvider = class {
3424
3456
  getMigrations() {
@@ -3630,6 +3662,6 @@ function createForwardingLogger(post, level = "info", tags = []) {
3630
3662
  };
3631
3663
  }
3632
3664
  //#endregion
3633
- export { DocumentExistence as $, GATED_DOCUMENT_ACTIONS as A, createOperation as B, describeWaitingSessions as C, matchesScope as Ct, CollectionMembershipCache as D, __exportAll as Dt, DocumentMetaCache as E, yieldToMain as Et, buildErrorResult as F, relationshipTarget as G, isGenesisOperation as H, buildSuccessResult as I, targetDocumentId as J, submittedActionIds as K, createConsistencyToken as L, TouchedStreams as M, applyDeleteDocumentAction$1 as N, DOCUMENT_SCOPE_ACTIONS as O, applyUpgradeDocumentAction$1 as P, DocumentAlreadyExistsError as Q, createDocumentFromAction as R, createKyselyWatermarkProbe as S, ReactorEventTypes as St, snapshotFunctionsFor as T, throwIfAborted as Tt, jobWriteIds as U, getNextIndexForScope as V, refusalError as W, APPEND_CONDITION_FAILED_PREFIX as X, updateDocumentRevision as Y, AppendConditionFailedError as Z, acquirePurgeLocks as _, ReservedActionError as _t, REACTOR_SCHEMA as a, AuthorizationDeniedError as at, ProbeSettler as b, UpgradePreconditionFailedError as bt, createForwardingPoolInstrumentation as c, DocumentNotDeletedError as ct, KyselyKeyframeStore as d, ExcessiveReshuffleError as dt, DuplicateOperationError as et, EventBus as f, GroupInUseError as ft, PURGE_NS as g, RelationshipNotFoundError as gt, PURGE_LOCK_BUCKETS as h, PurgeTooLargeError as ht, fromErrorInfo as i, AuthTimestampNotMonotonicError as it, PurgeFence as j, FencedWriteCache as k, instrumentPgPool as l, DocumentNotFoundError as lt, KyselyOperationIndex as m, InvalidSignatureError as mt, errorToInfo as n, RevisionMismatchError as nt, getMigrationStatus as o, BatchJobFailedError as ot, KyselyWriteCache as p, InvalidOperationTimestampError as pt, summarizeSubmittedActions as q, sanitizeArg as r, AuthEnforcementDisabledError as rt, runMigrations as s, DocumentDeletedError as st, createForwardingLogger as t, OptimisticLockError as tt, KyselyOperationStore as u, DocumentPurgedError as ut, findPurged as v, UnsupportedProtocolVersionError as vt, parseSnapshot as w, parsePagingOptions as wt, SettledWatermark as x, EventBusAggregateError as xt, listPurged as y, UnsupportedStoredProtocolError as yt, createEmptyConsistencyToken as z };
3665
+ export { DocumentExistence as $, GATED_DOCUMENT_ACTIONS as A, yieldToMain as At, createOperation as B, describeWaitingSessions as C, ReactorEventTypes as Ct, CollectionMembershipCache as D, parsePagingOptions as Dt, DocumentMetaCache as E, matchesScope as Et, buildErrorResult as F, relationshipTarget as G, isGenesisOperation as H, buildSuccessResult as I, targetDocumentId as J, submittedActionIds as K, createConsistencyToken as L, TouchedStreams as M, applyDeleteDocumentAction$1 as N, DOCUMENT_SCOPE_ACTIONS as O, throwIfAborted as Ot, applyUpgradeDocumentAction$1 as P, DocumentAlreadyExistsError as Q, createDocumentFromAction as R, createKyselyWatermarkProbe as S, EventBusAggregateError as St, snapshotFunctionsFor as T, delay as Tt, jobWriteIds as U, getNextIndexForScope as V, refusalError as W, APPEND_CONDITION_FAILED_PREFIX as X, updateDocumentRevision as Y, AppendConditionFailedError as Z, acquirePurgeLocks as _, RelationshipNotFoundError as _t, REACTOR_SCHEMA as a, AuthorizationDeniedError as at, ProbeSettler as b, UnsupportedStoredProtocolError as bt, createForwardingPoolInstrumentation as c, DocumentNotDeletedError as ct, KyselyKeyframeStore as d, ExcessiveReshuffleError as dt, DuplicateOperationError as et, EventBus as f, GroupInUseError as ft, PURGE_NS as g, PurgeTooLargeError as gt, PURGE_LOCK_BUCKETS as h, JOB_NOT_FOUND_ERROR_NAME as ht, fromErrorInfo as i, AuthTimestampNotMonotonicError as it, PurgeFence as j, __exportAll as jt, FencedWriteCache as k, withDeadline as kt, instrumentPgPool as l, DocumentNotFoundError as lt, KyselyOperationIndex as m, InvalidSignatureError as mt, errorToInfo as n, RevisionMismatchError as nt, getMigrationStatus as o, BatchJobFailedError as ot, KyselyWriteCache as p, InvalidOperationTimestampError as pt, summarizeSubmittedActions as q, sanitizeArg as r, AuthEnforcementDisabledError as rt, runMigrations as s, DocumentDeletedError as st, createForwardingLogger as t, OptimisticLockError as tt, KyselyOperationStore as u, DocumentPurgedError as ut, findPurged as v, ReservedActionError as vt, parseSnapshot as w, TIMED_OUT as wt, SettledWatermark as x, UpgradePreconditionFailedError as xt, listPurged as y, UnsupportedProtocolVersionError as yt, createEmptyConsistencyToken as z };
3634
3666
 
3635
- //# sourceMappingURL=forwarding-logger-ByfBFgMS.js.map
3667
+ //# sourceMappingURL=forwarding-logger-B9LLXItm.js.map