@tearleads/client-sdk 0.1.44 → 0.1.45

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 (113) hide show
  1. package/data/persistence/container-contents/containerContentsPersistence.js +2 -3
  2. package/data/persistence/container-contents/containerContentsPersistence.js.map +1 -1
  3. package/data/persistence/container-contents/containerCreateIntentSettlement.js +16 -16
  4. package/data/persistence/container-contents/containerCreateIntentSettlement.js.map +1 -1
  5. package/data/persistence/container-contents/containerDeletionPersistence.js +5 -11
  6. package/data/persistence/container-contents/containerDeletionPersistence.js.map +1 -1
  7. package/data/persistence/container-contents/containerDocumentReassignment.js +13 -13
  8. package/data/persistence/container-contents/containerDocumentReassignment.js.map +1 -1
  9. package/data/persistence/container-contents/containerHydrationPersistence.js +7 -4
  10. package/data/persistence/container-contents/containerHydrationPersistence.js.map +1 -1
  11. package/data/persistence/container-contents/containerIntentPersistence.js +43 -42
  12. package/data/persistence/container-contents/containerIntentPersistence.js.map +1 -1
  13. package/data/persistence/container-contents/containerMetadataMutationPersistence.js +15 -20
  14. package/data/persistence/container-contents/containerMetadataMutationPersistence.js.map +1 -1
  15. package/data/persistence/container-contents/containerMoveAbandonPersistence.js +1 -6
  16. package/data/persistence/container-contents/containerMoveAbandonPersistence.js.map +1 -1
  17. package/data/persistence/container-contents/containerMoveIntentRows.js +9 -8
  18. package/data/persistence/container-contents/containerMoveIntentRows.js.map +1 -1
  19. package/data/persistence/container-contents/containerReconcilePersistence.js +4 -8
  20. package/data/persistence/container-contents/containerReconcilePersistence.js.map +1 -1
  21. package/data/persistence/container-contents/containerRecoveryPersistence.js +20 -19
  22. package/data/persistence/container-contents/containerRecoveryPersistence.js.map +1 -1
  23. package/data/persistence/container-contents/containerRemovalWork.js +10 -10
  24. package/data/persistence/container-contents/containerRemovalWork.js.map +1 -1
  25. package/data/persistence/container-contents/containerStructuralRepair.js +21 -44
  26. package/data/persistence/container-contents/containerStructuralRepair.js.map +1 -1
  27. package/data/persistence/container-contents/documentLinkRemovalRepair.js +12 -11
  28. package/data/persistence/container-contents/documentLinkRemovalRepair.js.map +1 -1
  29. package/data/persistence/container-contents/documentMoveIntentPersistence.js +53 -28
  30. package/data/persistence/container-contents/documentMoveIntentPersistence.js.map +1 -1
  31. package/data/persistence/container-contents/documentPlacementIntentEnqueue.js +9 -8
  32. package/data/persistence/container-contents/documentPlacementIntentEnqueue.js.map +1 -1
  33. package/data/persistence/container-contents/documentPurgePlacement.js +6 -6
  34. package/data/persistence/container-contents/documentPurgePlacement.js.map +1 -1
  35. package/data/persistence/container-contents/dormantContainerMetadata.js +1 -5
  36. package/data/persistence/container-contents/dormantContainerMetadata.js.map +1 -1
  37. package/data/persistence/container-contents/pendingContainerCreate.js +5 -5
  38. package/data/persistence/container-contents/pendingContainerCreate.js.map +1 -1
  39. package/data/persistence/containers/containerPersistence.js +10 -27
  40. package/data/persistence/containers/containerPersistence.js.map +1 -1
  41. package/data/persistence/containers/documentContainerProjectionPersistence.js +2 -2
  42. package/data/persistence/containers/documentContainerProjectionPersistence.js.map +1 -1
  43. package/data/persistence/containers/documentPlacement.js +10 -10
  44. package/data/persistence/containers/documentPlacement.js.map +1 -1
  45. package/data/persistence/documents/internal/discardDocument.js +5 -5
  46. package/data/persistence/documents/internal/discardDocument.js.map +1 -1
  47. package/data/persistence/documents/internal/documentDeletionPersistence.js +7 -9
  48. package/data/persistence/documents/internal/documentDeletionPersistence.js.map +1 -1
  49. package/data/persistence/documents/internal/documentMutationPersistence.js +6 -8
  50. package/data/persistence/documents/internal/documentMutationPersistence.js.map +1 -1
  51. package/data/persistence/documents/internal/ensureDocumentsSchema.js +2 -2
  52. package/data/persistence/documents/internal/ensureDocumentsSchema.js.map +1 -1
  53. package/data/persistence/documents/internal/orphanSideRows.js +3 -22
  54. package/data/persistence/documents/internal/orphanSideRows.js.map +1 -1
  55. package/data/persistence/organizations/organizationDataUsagePersistence.js +31 -64
  56. package/data/persistence/organizations/organizationDataUsagePersistence.js.map +1 -1
  57. package/data/persistence/organizations/organizationReadModelPurge.js +1 -5
  58. package/data/persistence/organizations/organizationReadModelPurge.js.map +1 -1
  59. package/data/persistence/principalCurrentAcknowledgementPersistence.js +24 -17
  60. package/data/persistence/principalCurrentAcknowledgementPersistence.js.map +1 -1
  61. package/data/persistence/principalHistoryIncompleteRetention.js +3 -9
  62. package/data/persistence/principalHistoryIncompleteRetention.js.map +1 -1
  63. package/data/persistence/principalHistoryStagePersistence.d.ts +3 -9
  64. package/data/persistence/principalHistoryStagePersistence.js +15 -25
  65. package/data/persistence/principalHistoryStagePersistence.js.map +1 -1
  66. package/data/persistence/principalHistoryStageRetention.js +16 -15
  67. package/data/persistence/principalHistoryStageRetention.js.map +1 -1
  68. package/data/persistence/principalHistoryUnpublishedRetention.js +6 -13
  69. package/data/persistence/principalHistoryUnpublishedRetention.js.map +1 -1
  70. package/data/sqlite/containerSchema.d.ts +84 -180
  71. package/data/sqlite/containerSchema.js +14 -23
  72. package/data/sqlite/containerSchema.js.map +1 -1
  73. package/data/sqlite/documentPlacementIntentSchema.js +3 -50
  74. package/data/sqlite/documentPlacementIntentSchema.js.map +1 -1
  75. package/data/sqlite/documentSyncFailurePersistence.d.ts +16 -6
  76. package/data/sqlite/documentSyncFailurePersistence.js +44 -54
  77. package/data/sqlite/documentSyncFailurePersistence.js.map +1 -1
  78. package/data/sqlite/{documentPlacementIntentSchema.d.ts → localIntentSchema.d.ts} +162 -88
  79. package/data/sqlite/localIntentSchema.js +90 -0
  80. package/data/sqlite/localIntentSchema.js.map +1 -0
  81. package/data/sqlite/organizationDataUsageSchema.js +11 -17
  82. package/data/sqlite/organizationDataUsageSchema.js.map +1 -1
  83. package/data/sqlite/principalHistoryRetentionSchema.js +0 -15
  84. package/data/sqlite/principalHistoryRetentionSchema.js.map +1 -1
  85. package/data/sqlite/principalHistoryStageSchema.d.ts +44 -2
  86. package/data/sqlite/principalHistoryStageSchema.js +14 -2
  87. package/data/sqlite/principalHistoryStageSchema.js.map +1 -1
  88. package/data/sqlite/schema.d.ts +947 -2112
  89. package/data/sqlite/schema.js +26 -134
  90. package/data/sqlite/schema.js.map +1 -1
  91. package/package.json +1 -1
  92. package/workflows/container-contents/documentPriming.js +6 -10
  93. package/workflows/container-contents/documentPriming.js.map +1 -1
  94. package/workflows/container-contents/documentQueries/sql.js +11 -10
  95. package/workflows/container-contents/documentQueries/sql.js.map +1 -1
  96. package/workflows/container-contents/documentQueries.js +2 -2
  97. package/workflows/container-contents/documentQueries.js.map +1 -1
  98. package/workflows/container-contents/pendingDownloads.js +2 -5
  99. package/workflows/container-contents/pendingDownloads.js.map +1 -1
  100. package/workflows/container-contents/pendingWrites/deferredTails.js +3 -11
  101. package/workflows/container-contents/pendingWrites/deferredTails.js.map +1 -1
  102. package/workflows/container-contents/pendingWrites/sources.js +56 -80
  103. package/workflows/container-contents/pendingWrites/sources.js.map +1 -1
  104. package/workflows/container-contents/pendingWrites.js +6 -4
  105. package/workflows/container-contents/pendingWrites.js.map +1 -1
  106. package/workflows/container-contents/remoteContainerState.js +2 -1
  107. package/workflows/container-contents/remoteContainerState.js.map +1 -1
  108. package/workflows/sync/remoteReset.js +16 -23
  109. package/workflows/sync/remoteReset.js.map +1 -1
  110. package/workflows/sync/remoteResetPrincipalScope.js +1 -2
  111. package/workflows/sync/remoteResetPrincipalScope.js.map +1 -1
  112. package/workflows/sync/remoteResetScope.js +15 -8
  113. package/workflows/sync/remoteResetScope.js.map +1 -1
@@ -0,0 +1 @@
1
+ {"version":3,"file":"localIntentSchema.js","sourceRoot":"","sources":["localIntentSchema.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,EAAE,EAAE,OAAO,EAAY,MAAM,aAAa,CAAC;AACpD,OAAO,EACL,KAAK,EACL,OAAO,EACP,UAAU,EACV,WAAW,EACX,IAAI,EACJ,MAAM,GACP,MAAM,yBAAyB,CAAC;AAEjC;;;;GAIG;AACH,MAAM,CAAC,MAAM,kBAAkB,GAAG;IAChC,eAAe,EA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C;IACnC,MAAM,EAAE,CAAC,EAAE,CAAC,KAAK,CAAC,IAAI,EAAE,KAAK,CAAC,SAAS,CAAC;IACxC,KAAK,CAAC,uCAAuC,CAAC,CAAC,EAAE,CAC/C,KAAK,CAAC,IAAI,EACV,KAAK,CAAC,UAAU,EAChB,KAAK,CAAC,SAAS,CAChB;CACF,CACF,CAAC;AAEF,0EAA0E;AAC1E,MAAM,CAAC,MAAM,oBAAoB,GAAG,CAAC,YAAY,CAAC,IAAI,EAAE,YAAY,CAAC,SAAS,CAAC,CAAC;AAEhF,MAAM,UAAU,iBAAiB,CAAC,IAAqB;IACrD,OAAO,EAAE,CAAC,YAAY,CAAC,IAAI,EAAE,IAAI,CAAC,CAAC;AACrC,CAAC;AAED,8EAA8E;AAC9E,MAAM,UAAU,sBAAsB;IACpC,OAAO,OAAO,CAAC,YAAY,CAAC,IAAI,EAAE;QAChC,kBAAkB,CAAC,eAAe;QAClC,kBAAkB,CAAC,aAAa;KACjC,CAAC,CAAC;AACL,CAAC","sourcesContent":["import { eq, inArray, type SQL } from \"drizzle-orm\";\nimport {\n index,\n integer,\n primaryKey,\n sqliteTable,\n text,\n unique,\n} from \"drizzle-orm/sqlite-core\";\n\n/**\n * Lanes of the durable local outbox. Each lane keeps at most one intent per\n * subject: a container may hold a create and a move at once, while a\n * document's move and link coalesce into one placement intent.\n */\nexport const LOCAL_INTENT_LANES = {\n containerCreate: \"container.create\",\n containerMove: \"container.move\",\n documentPlacement: \"document.placement\",\n} as const;\n\nexport type LocalIntentLane =\n (typeof LOCAL_INTENT_LANES)[keyof typeof LOCAL_INTENT_LANES];\n\n/**\n * Device-first structural writes waiting for remote replay: container creates,\n * container moves, and document placement (move and link) intents.\n *\n * Every lane shares one revision protocol: `id` is rewritten on each enqueue or\n * repair, settlement compares `(id, updatedAt)` before acting, and replay runs\n * in `createdAt` order. Remote reset deletes the scoped intents of every lane\n * (and re-queues creates for surviving containers); nothing here survives a\n * reset. Durable requests that must survive reset (the principal mutation\n * journal and organization provisioning attempts) live in their own tables.\n *\n * Columns:\n * - `id`: Revision token and primary key.\n * - `lane`: One of `LOCAL_INTENT_LANES`.\n * - `intentType`: `container.create`, `container.move`, `document.move`, or\n * `document.link`. A placement intent switches between the last two in place.\n * - `subjectId`: Container id for container lanes, server document id for the\n * placement lane.\n * - `localId`: Local document row the placement intent updates; null for\n * container lanes.\n * - `targetContainerId`: Desired parent (container lanes) or target container\n * (placement lane).\n * - `sourceContainerId`: Parent observed when a container move was first\n * queued, or the source container a document move unlinks.\n * - `replaceLinkedContainers`: Placement only — the final remote link set is\n * only the target container.\n * - `remoteContainerId`, `remoteMetadataDocumentId`,\n * `remoteMetadataAccessStateHash`: Remote identities a container create\n * records once accepted.\n * - `syncStatus`: Lane-specific state (`pending`/`synced` for creates,\n * `pending`/`blocked` for container moves, `pending`/`blocked`/`denied`/\n * `unavailable` for placements).\n * - `lastError`, `lastAttemptedAt`: Replay diagnostics.\n * - `createdAt`: FIFO replay order; `updatedAt`: last target/status change.\n *\n * Indexes:\n * - `(lane, subjectId)` is unique so repeated enqueues coalesce per lane.\n * - `(lane, syncStatus, createdAt)` lists a lane's queue in order.\n */\nexport const localIntents = sqliteTable(\n \"local_intents\",\n {\n id: text(\"id\"),\n lane: text(\"lane\").notNull(),\n intentType: text(\"intent_type\").notNull(),\n subjectId: text(\"subject_id\").notNull(),\n localId: text(\"local_id\"),\n targetContainerId: text(\"target_container_id\").notNull(),\n sourceContainerId: text(\"source_container_id\"),\n replaceLinkedContainers: integer(\"replace_linked_containers\", {\n mode: \"boolean\",\n })\n .notNull()\n .default(false),\n remoteContainerId: text(\"remote_container_id\"),\n remoteMetadataDocumentId: text(\"remote_metadata_document_id\"),\n remoteMetadataAccessStateHash: text(\"remote_metadata_access_state_hash\"),\n syncStatus: text(\"sync_status\").notNull(),\n lastError: text(\"last_error\"),\n lastAttemptedAt: text(\"last_attempted_at\"),\n createdAt: text(\"created_at\").notNull(),\n updatedAt: text(\"updated_at\").notNull(),\n },\n (table) => [\n primaryKey({ columns: [table.id] }),\n unique().on(table.lane, table.subjectId),\n index(\"local_intents_lane_status_created_idx\").on(\n table.lane,\n table.syncStatus,\n table.createdAt,\n ),\n ],\n);\n\n/** The conflict target that coalesces repeated enqueues within a lane. */\nexport const LOCAL_INTENT_SUBJECT = [localIntents.lane, localIntents.subjectId];\n\nexport function inLocalIntentLane(lane: LocalIntentLane): SQL {\n return eq(localIntents.lane, lane);\n}\n\n/** Both container lanes: what a container's own removal or reset discards. */\nexport function inContainerIntentLanes(): SQL {\n return inArray(localIntents.lane, [\n LOCAL_INTENT_LANES.containerCreate,\n LOCAL_INTENT_LANES.containerMove,\n ]);\n}\n"]}
@@ -1,7 +1,12 @@
1
1
  import { integer, primaryKey, sqliteTable, text, } from "drizzle-orm/sqlite-core";
2
2
  import { defineSqlTableSchema } from "./sqlTableSchema.js";
3
3
  export const ORGANIZATION_DATA_USAGE_PROJECTION_VERSION = 1;
4
- /** One server-computed usage snapshot per organization requester. */
4
+ /**
5
+ * One server-computed usage snapshot per organization requester. The
6
+ * per-category document breakdown is the response's own array, stored as
7
+ * JSON in canonical category order in `categoryBreakdownJson` and re-validated
8
+ * against the response schema on every read; a row that fails is purged.
9
+ */
5
10
  export const organizationDataUsageSnapshots = sqliteTable("organization_data_usage_snapshots", {
6
11
  organizationId: text("organization_id").notNull(),
7
12
  requesterUserId: text("requester_user_id").notNull(),
@@ -12,29 +17,18 @@ export const organizationDataUsageSnapshots = sqliteTable("organization_data_usa
12
17
  documentCount: integer("document_count").notNull(),
13
18
  documentUpdateCount: integer("document_update_count").notNull(),
14
19
  totalByteLength: integer("total_byte_length").notNull(),
20
+ categoryBreakdownJson: text("category_breakdown_json").notNull(),
15
21
  refreshedAt: text("refreshed_at").notNull(),
16
22
  }, (table) => [
17
23
  primaryKey({ columns: [table.organizationId, table.requesterUserId] }),
18
24
  ]);
19
- /** Exact document-category rows belonging to a requester usage snapshot. */
20
- export const organizationDataUsageCategories = sqliteTable("organization_data_usage_categories", {
21
- organizationId: text("organization_id").notNull(),
22
- requesterUserId: text("requester_user_id").notNull(),
23
- category: text("category").notNull(),
24
- byteLength: integer("byte_length").notNull(),
25
- documentCount: integer("document_count").notNull(),
26
- updateCount: integer("update_count").notNull(),
27
- }, (table) => [
28
- primaryKey({
29
- columns: [table.organizationId, table.requesterUserId, table.category],
30
- }),
31
- ]);
32
25
  export const organizationDataUsageTables = [
33
- defineSqlTableSchema(organizationDataUsageSnapshots),
34
- defineSqlTableSchema(organizationDataUsageCategories),
26
+ {
27
+ ...defineSqlTableSchema(organizationDataUsageSnapshots),
28
+ requiredColumns: ["category_breakdown_json"],
29
+ },
35
30
  ];
36
31
  export const organizationDataUsageSQLiteSchema = {
37
32
  organizationDataUsageSnapshots,
38
- organizationDataUsageCategories,
39
33
  };
40
34
  //# sourceMappingURL=organizationDataUsageSchema.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"organizationDataUsageSchema.js","sourceRoot":"","sources":["organizationDataUsageSchema.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,OAAO,EACP,UAAU,EACV,WAAW,EACX,IAAI,GACL,MAAM,yBAAyB,CAAC;AACjC,OAAO,EAAE,oBAAoB,EAAuB,MAAM,kBAAkB,CAAC;AAE7E,MAAM,CAAC,MAAM,0CAA0C,GAAG,CAAU,CAAC;AAErE,qEAAqE;AACrE,MAAM,CAAC,MAAM,8BAA8B,GAAG,WAAW,CACvD,mCAAmC,EACnC;IACE,cAAc,EAAE,IAAI,CAAC,iBAAiB,CAAC,CAAC,OAAO,EAAE;IACjD,eAAe,EAAE,IAAI,CAAC,mBAAmB,CAAC,CAAC,OAAO,EAAE;IACpD,iBAAiB,EAAE,OAAO,CAAC,oBAAoB,CAAC,CAAC,OAAO,EAAE;IAC1D,SAAS,EAAE,OAAO,CAAC,YAAY,CAAC,CAAC,OAAO,EAAE;IAC1C,cAAc,EAAE,OAAO,CAAC,kBAAkB,CAAC,CAAC,OAAO,EAAE;IACrD,kBAAkB,EAA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MAAM,iCAAiC,GAAG;IAC/C,8BAA8B;IAC9B,+BAA+B;CAChC,CAAC","sourcesContent":["import {\n integer,\n primaryKey,\n sqliteTable,\n text,\n} from \"drizzle-orm/sqlite-core\";\nimport { defineSqlTableSchema, type SqlTableSchema } from \"./sqlTableSchema\";\n\nexport const ORGANIZATION_DATA_USAGE_PROJECTION_VERSION = 1 as const;\n\n/** One server-computed usage snapshot per organization requester. */\nexport const organizationDataUsageSnapshots = sqliteTable(\n \"organization_data_usage_snapshots\",\n {\n organizationId: text(\"organization_id\").notNull(),\n requesterUserId: text(\"requester_user_id\").notNull(),\n projectionVersion: integer(\"projection_version\").notNull(),\n blobCount: integer(\"blob_count\").notNull(),\n blobByteLength: integer(\"blob_byte_length\").notNull(),\n documentByteLength: integer(\"document_byte_length\").notNull(),\n documentCount: integer(\"document_count\").notNull(),\n documentUpdateCount: integer(\"document_update_count\").notNull(),\n totalByteLength: integer(\"total_byte_length\").notNull(),\n refreshedAt: text(\"refreshed_at\").notNull(),\n },\n (table) => [\n primaryKey({ columns: [table.organizationId, table.requesterUserId] }),\n ],\n);\n\n/** Exact document-category rows belonging to a requester usage snapshot. */\nexport const organizationDataUsageCategories = sqliteTable(\n \"organization_data_usage_categories\",\n {\n organizationId: text(\"organization_id\").notNull(),\n requesterUserId: text(\"requester_user_id\").notNull(),\n category: text(\"category\").notNull(),\n byteLength: integer(\"byte_length\").notNull(),\n documentCount: integer(\"document_count\").notNull(),\n updateCount: integer(\"update_count\").notNull(),\n },\n (table) => [\n primaryKey({\n columns: [table.organizationId, table.requesterUserId, table.category],\n }),\n ],\n);\n\nexport const organizationDataUsageTables: ReadonlyArray<SqlTableSchema> = [\n defineSqlTableSchema(organizationDataUsageSnapshots),\n defineSqlTableSchema(organizationDataUsageCategories),\n];\n\nexport const organizationDataUsageSQLiteSchema = {\n organizationDataUsageSnapshots,\n organizationDataUsageCategories,\n};\n"]}
1
+ {"version":3,"file":"organizationDataUsageSchema.js","sourceRoot":"","sources":["organ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B,CAAC;QACvD,eAAe,EAAE,CAAC,yBAAyB,CAAC;KAC7C;CACF,CAAC;AAEF,MAAM,CAAC,MAAM,iCAAiC,GAAG;IAC/C,8BAA8B;CAC/B,CAAC","sourcesContent":["import {\n integer,\n primaryKey,\n sqliteTable,\n text,\n} from \"drizzle-orm/sqlite-core\";\nimport { defineSqlTableSchema, type SqlTableSchema } from \"./sqlTableSchema\";\n\nexport const ORGANIZATION_DATA_USAGE_PROJECTION_VERSION = 1 as const;\n\n/**\n * One server-computed usage snapshot per organization requester. The\n * per-category document breakdown is the response's own array, stored as\n * JSON in canonical category order in `categoryBreakdownJson` and re-validated\n * against the response schema on every read; a row that fails is purged.\n */\nexport const organizationDataUsageSnapshots = sqliteTable(\n \"organization_data_usage_snapshots\",\n {\n organizationId: text(\"organization_id\").notNull(),\n requesterUserId: text(\"requester_user_id\").notNull(),\n projectionVersion: integer(\"projection_version\").notNull(),\n blobCount: integer(\"blob_count\").notNull(),\n blobByteLength: integer(\"blob_byte_length\").notNull(),\n documentByteLength: integer(\"document_byte_length\").notNull(),\n documentCount: integer(\"document_count\").notNull(),\n documentUpdateCount: integer(\"document_update_count\").notNull(),\n totalByteLength: integer(\"total_byte_length\").notNull(),\n categoryBreakdownJson: text(\"category_breakdown_json\").notNull(),\n refreshedAt: text(\"refreshed_at\").notNull(),\n },\n (table) => [\n primaryKey({ columns: [table.organizationId, table.requesterUserId] }),\n ],\n);\n\nexport const organizationDataUsageTables: ReadonlyArray<SqlTableSchema> = [\n {\n ...defineSqlTableSchema(organizationDataUsageSnapshots),\n requiredColumns: [\"category_breakdown_json\"],\n },\n];\n\nexport const organizationDataUsageSQLiteSchema = {\n organizationDataUsageSnapshots,\n};\n"]}
@@ -1,4 +1,3 @@
1
- import { desc } from "drizzle-orm";
2
1
  import { index, integer, primaryKey, sqliteTable, text, } from "drizzle-orm/sqlite-core";
3
2
  import { defineSqlTableSchema } from "./sqlTableSchema.js";
4
3
  /** Encrypted key candidates survive disposable progress reclamation. */
@@ -20,21 +19,7 @@ export const principalKeyEnvelopeArchive = sqliteTable("principal_key_envelope_a
20
19
  }),
21
20
  index("principal_key_envelope_archive_fingerprint_idx").on(table.keyFingerprint, table.version),
22
21
  ]);
23
- /** Scope and recency are eviction hints, never authenticated recovery state. */
24
- export const principalHistoryStageScopes = sqliteTable("principal_history_stage_scopes", {
25
- id: text("id").primaryKey(),
26
- organizationId: text("organization_id").notNull(),
27
- scopeId: text("scope_id").notNull(),
28
- afterVersion: integer("after_version").notNull(),
29
- complete: integer("complete", { mode: "boolean" }).notNull(),
30
- touchedAt: integer("touched_at").notNull(),
31
- }, (table) => [
32
- index("principal_history_stage_scopes_scope_idx").on(table.scopeId, table.organizationId, table.complete, desc(table.afterVersion), desc(table.touchedAt), table.id),
33
- index("principal_history_stage_scopes_organization_idx").on(table.organizationId),
34
- index("principal_history_stage_scopes_incomplete_idx").on(table.scopeId, table.organizationId, table.complete, desc(table.touchedAt), table.id),
35
- ]);
36
22
  export const principalHistoryRetentionTables = [
37
23
  defineSqlTableSchema(principalKeyEnvelopeArchive),
38
- defineSqlTableSchema(principalHistoryStageScopes),
39
24
  ];
40
25
  //# sourceMappingURL=principalHistoryRetentionSchema.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"principalHistoryRetentionSchema.js","sourceRoot":"","sources":["principalHistoryRetentionSchema.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,IAAI,EAAE,MAAM,aAAa,CAAC;AACnC,OAAO,EACL,KAAK,EACL,OAAO,EACP,UAAU,EACV,WAAW,EACX,IAAI,GACL,MAAM,yBAAyB,CAAC;AACjC,OAAO,EAAE,oBAAoB,EAAE,MAAM,kBAAkB,CAAC;AAExD,wEAAwE;AACxE,MAAM,CAAC,MAAM,2BAA2B,GAAG,WAAW,CACpD,gCAAgC,EAChC;IACE,cAAc,EAAE,IAAI,CAAC,iBAAiB,CAAC,CAAC,OAAO,EAAE;IACjD,aAAa,EAAE,IAAI,CAAC,gBAAgB,CAAC,CAA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Y,CAAC,EACxB,IAAI,CAAC,KAAK,CAAC,SAAS,CAAC,EACrB,KAAK,CAAC,EAAE,CACT;IACD,KAAK,CAAC,iDAAiD,CAAC,CAAC,EAAE,CACzD,KAAK,CAAC,cAAc,CACrB;IACD,KAAK,CAAC,+CAA+C,CAAC,CAAC,EAAE,CACvD,KAAK,CAAC,OAAO,EACb,KAAK,CAAC,cAAc,EACpB,KAAK,CAAC,QAAQ,EACd,IAAI,CAAC,KAAK,CAAC,SAAS,CAAC,EACrB,KAAK,CAAC,EAAE,CACT;CACF,CACF,CAAC;AAEF,MAAM,CAAC,MAAM,+BAA+B,GAAG;IAC7C,oBAAoB,CAAC,2BAA2B,CAAC;IACjD,oBAAoB,CAAC,2BAA2B,CAAC;CAClD,CAAC","sourcesContent":["import { desc } from \"drizzle-orm\";\nimport {\n index,\n integer,\n primaryKey,\n sqliteTable,\n text,\n} from \"drizzle-orm/sqlite-core\";\nimport { defineSqlTableSchema } from \"./sqlTableSchema\";\n\n/** Encrypted key candidates survive disposable progress reclamation. */\nexport const principalKeyEnvelopeArchive = sqliteTable(\n \"principal_key_envelope_archive\",\n {\n organizationId: text(\"organization_id\").notNull(),\n principalType: text(\"principal_type\").notNull(),\n principalId: text(\"principal_id\").notNull(),\n keyFingerprint: text(\"key_fingerprint\").notNull(),\n version: integer(\"version\").notNull(),\n envelopesJson: text(\"envelopes_json\").notNull(),\n },\n (table) => [\n primaryKey({\n columns: [\n table.organizationId,\n table.principalType,\n table.principalId,\n table.keyFingerprint,\n ],\n }),\n index(\"principal_key_envelope_archive_fingerprint_idx\").on(\n table.keyFingerprint,\n table.version,\n ),\n ],\n);\n\n/** Scope and recency are eviction hints, never authenticated recovery state. */\nexport const principalHistoryStageScopes = sqliteTable(\n \"principal_history_stage_scopes\",\n {\n id: text(\"id\").primaryKey(),\n organizationId: text(\"organization_id\").notNull(),\n scopeId: text(\"scope_id\").notNull(),\n afterVersion: integer(\"after_version\").notNull(),\n complete: integer(\"complete\", { mode: \"boolean\" }).notNull(),\n touchedAt: integer(\"touched_at\").notNull(),\n },\n (table) => [\n index(\"principal_history_stage_scopes_scope_idx\").on(\n table.scopeId,\n table.organizationId,\n table.complete,\n desc(table.afterVersion),\n desc(table.touchedAt),\n table.id,\n ),\n index(\"principal_history_stage_scopes_organization_idx\").on(\n table.organizationId,\n ),\n index(\"principal_history_stage_scopes_incomplete_idx\").on(\n table.scopeId,\n table.organizationId,\n table.complete,\n desc(table.touchedAt),\n table.id,\n ),\n ],\n);\n\nexport const principalHistoryRetentionTables = [\n defineSqlTableSchema(principalKeyEnvelopeArchive),\n defineSqlTableSchema(principalHistoryStageScopes),\n];\n"]}
1
+ {"version":3,"file":"principalHistoryRetentionSchema.js","sourceRoot":"","sources":["principalHistoryRetentionSchema.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,KAAK,EACL,OAAO,EACP,UAAU,EACV,WAAW,EACX,IAAI,GACL,MAAM,yBAAyB,CAAC;AACjC,OAAO,EAAE,oBAAoB,EAAE,MAAM,kBAAkB,CAAC;AAExD,wEAAwE;AACxE,MAAM,CAAC,MAAM,2BAA2B,GAAG,WAAW,CACpD,gCAAgC,EAChC;IACE,cAAc,EAAE,IAAI,CAAC,iBAAiB,CAAC,CAAC,OAAO,EAAE;IACjD,aAAa,EAAE,IAAI,CAAC,gBAAgB,CAAC,CAAC,OAAO,EAAE;IAC/C,WAAW,EAAE,IAAI,CAAC,cAAc,CAAC,CAAC,OAAO,EAAE;IAC3C,cAAc,EAAE,IAAI,CAAC,iBAAiB,CAAC,CAAC,OAAO,EAAE;IACjD,OAAO,EAAE,OAAO,CAAC,SAAS,CAAC,CAAC,OAAO,EAAE;IACrC,aAAa,EAAE,IAAI,CAAC,gBAAgB,CAAC,CAAC,OAAO,EAAE;CAChD,EACD,CAAC,KAAK,EAAE,EAAE,CAAC;IACT,UAAU,CAAC;QACT,OAAO,EAAE;YACP,KAAK,CAAC,cAAc;YACpB,KAAK,CAAC,aAAa;YACnB,KAAK,CAAC,WAAW;YACjB,KAAK,CAAC,cAAc;SACrB;KACF,CAAC;IACF,KAAK,CAAC,gDAAgD,CAAC,CAAC,EAAE,CACxD,KAAK,CAAC,cAAc,EACpB,KAAK,CAAC,OAAO,CACd;CACF,CACF,CAAC;AAEF,MAAM,CAAC,MAAM,+BAA+B,GAAG;IAC7C,oBAAoB,CAAC,2BAA2B,CAAC;CAClD,CAAC","sourcesContent":["import {\n index,\n integer,\n primaryKey,\n sqliteTable,\n text,\n} from \"drizzle-orm/sqlite-core\";\nimport { defineSqlTableSchema } from \"./sqlTableSchema\";\n\n/** Encrypted key candidates survive disposable progress reclamation. */\nexport const principalKeyEnvelopeArchive = sqliteTable(\n \"principal_key_envelope_archive\",\n {\n organizationId: text(\"organization_id\").notNull(),\n principalType: text(\"principal_type\").notNull(),\n principalId: text(\"principal_id\").notNull(),\n keyFingerprint: text(\"key_fingerprint\").notNull(),\n version: integer(\"version\").notNull(),\n envelopesJson: text(\"envelopes_json\").notNull(),\n },\n (table) => [\n primaryKey({\n columns: [\n table.organizationId,\n table.principalType,\n table.principalId,\n table.keyFingerprint,\n ],\n }),\n index(\"principal_key_envelope_archive_fingerprint_idx\").on(\n table.keyFingerprint,\n table.version,\n ),\n ],\n);\n\nexport const principalHistoryRetentionTables = [\n defineSqlTableSchema(principalKeyEnvelopeArchive),\n];\n"]}
@@ -1,4 +1,10 @@
1
- /** Provisional, locally authenticated verification work; never an app checkpoint. */
1
+ import { type SqlTableSchema } from "./sqlTableSchema.js";
2
+ /**
3
+ * Provisional, locally authenticated verification work; never an app
4
+ * checkpoint. `scopeId` and `touchedAt` are eviction hints for bounded
5
+ * retention (which principal history the stage belongs to, and when a writer
6
+ * last used it), never authenticated recovery state.
7
+ */
2
8
  export declare const principalHistoryStages: import("drizzle-orm/sqlite-core").SQLiteTableWithColumns<{
3
9
  name: "principal_history_stages";
4
10
  schema: undefined;
@@ -41,6 +47,25 @@ export declare const principalHistoryStages: import("drizzle-orm/sqlite-core").S
41
47
  }, {}, {
42
48
  length: number | undefined;
43
49
  }>;
50
+ scopeId: import("drizzle-orm/sqlite-core").SQLiteColumn<{
51
+ name: "scope_id";
52
+ tableName: "principal_history_stages";
53
+ dataType: "string";
54
+ columnType: "SQLiteText";
55
+ data: string;
56
+ driverParam: string;
57
+ notNull: true;
58
+ hasDefault: false;
59
+ isPrimaryKey: false;
60
+ isAutoincrement: false;
61
+ hasRuntimeDefault: false;
62
+ enumValues: [string, ...string[]];
63
+ baseColumn: never;
64
+ identity: undefined;
65
+ generated: undefined;
66
+ }, {}, {
67
+ length: number | undefined;
68
+ }>;
44
69
  currentJson: import("drizzle-orm/sqlite-core").SQLiteColumn<{
45
70
  name: "current_json";
46
71
  tableName: "principal_history_stages";
@@ -94,6 +119,23 @@ export declare const principalHistoryStages: import("drizzle-orm/sqlite-core").S
94
119
  identity: undefined;
95
120
  generated: undefined;
96
121
  }, {}, {}>;
122
+ touchedAt: import("drizzle-orm/sqlite-core").SQLiteColumn<{
123
+ name: "touched_at";
124
+ tableName: "principal_history_stages";
125
+ dataType: "number";
126
+ columnType: "SQLiteInteger";
127
+ data: number;
128
+ driverParam: number;
129
+ notNull: true;
130
+ hasDefault: false;
131
+ isPrimaryKey: false;
132
+ isAutoincrement: false;
133
+ hasRuntimeDefault: false;
134
+ enumValues: undefined;
135
+ baseColumn: never;
136
+ identity: undefined;
137
+ generated: undefined;
138
+ }, {}, {}>;
97
139
  progress: import("drizzle-orm/sqlite-core").SQLiteColumn<{
98
140
  name: "progress";
99
141
  tableName: "principal_history_stages";
@@ -116,4 +158,4 @@ export declare const principalHistoryStages: import("drizzle-orm/sqlite-core").S
116
158
  };
117
159
  dialect: "sqlite";
118
160
  }>;
119
- export declare const principalHistoryStageTables: import("./sqlTableSchema.js").SqlTableSchema[];
161
+ export declare const principalHistoryStageTables: ReadonlyArray<SqlTableSchema>;
@@ -3,20 +3,32 @@ import { index, integer, sqliteTable, text } from "drizzle-orm/sqlite-core";
3
3
  import { principalHistoryRetentionTables } from "./principalHistoryRetentionSchema.js";
4
4
  import { principalCurrentFingerprintJson } from "./principalKeyFingerprintJson.js";
5
5
  import { defineSqlTableSchema } from "./sqlTableSchema.js";
6
- /** Provisional, locally authenticated verification work; never an app checkpoint. */
6
+ /**
7
+ * Provisional, locally authenticated verification work; never an app
8
+ * checkpoint. `scopeId` and `touchedAt` are eviction hints for bounded
9
+ * retention (which principal history the stage belongs to, and when a writer
10
+ * last used it), never authenticated recovery state.
11
+ */
7
12
  export const principalHistoryStages = sqliteTable("principal_history_stages", {
8
13
  id: text("id").primaryKey(),
9
14
  organizationId: text("organization_id").notNull(),
15
+ scopeId: text("scope_id").notNull(),
10
16
  currentJson: text("current_json").notNull(),
11
17
  afterVersion: integer("after_version").notNull(),
12
18
  complete: integer("complete", { mode: "boolean" }).notNull(),
19
+ touchedAt: integer("touched_at").notNull(),
13
20
  progress: text("progress").notNull(),
14
21
  }, (table) => [
15
22
  index("principal_history_stages_key_fingerprint_idx").on(principalCurrentFingerprintJson(table.currentJson), table.complete, desc(table.afterVersion)),
16
23
  index("principal_history_stages_organization_idx").on(table.organizationId),
24
+ index("principal_history_stages_scope_idx").on(table.scopeId, table.organizationId, table.complete, desc(table.afterVersion), desc(table.touchedAt), table.id),
25
+ index("principal_history_stages_incomplete_idx").on(table.scopeId, table.organizationId, table.complete, desc(table.touchedAt), table.id),
17
26
  ]);
18
27
  export const principalHistoryStageTables = [
19
- defineSqlTableSchema(principalHistoryStages),
28
+ {
29
+ ...defineSqlTableSchema(principalHistoryStages),
30
+ requiredColumns: ["scope_id", "touched_at"],
31
+ },
20
32
  ...principalHistoryRetentionTables,
21
33
  ];
22
34
  //# sourceMappingURL=principalHistoryStageSchema.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"principalHistoryStageSchema.js","sourceRoot":"","sources":["principalHistoryStageSchema.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,IAAI,EAAE,MAAM,aAAa,CAAC;AACnC,OAAO,EAAE,KAAK,EAAE,OAAO,EAAE,WAAW,EAAE,IAAI,EAAE,MAAM,yBAAyB,CAAC;AAC5E,OAAO,EAAE,+BAA+B,EAAE,MAAM,mCAAmC,CAAC;AACpF,OAAO,EAAE,+BAA+B,EAAE,MAAM,+BAA+B,CAAC;AAChF,OAAO,EAAE,oBAAoB,EAAE,MAAM,kBAAkB,CAAC;AAExD,qFAAqF;AACrF,MAAM,CAAC,MAAM,sBAAsB,GAAG,WAAW,CAC/C,0BAA0B,EAC1B;IACE,EAAE,EAAE,IAAI,CAAC,IAAI,CAAC,CAAC,UAAU,EAAE;IAC3B,cAAc,EAAE,IAAI,CAAC,iBAAiB,CAAC,CAAC,OAAO,EAAE;IACjD,WAAW,EAAE,IAAI,CAAC,cAAc,CAAC,CAAC,OAAO,EAAE;IAC3C,YAAY,EAAE,OAAO,CAAC,eAAe,CAAC,CAAC,OAAO,EAAE;IAChD,QAAQ,EAAE,OAAO,CAAC,UAAU,EAAE,EAAE,IAAI,EAAE,SAAS,EAAE,CAAC,CAAC,OAAO,EAAE;IAC5D,QAAQ,EAAE,IAAI,CAAC,UAAU,CAAC,CAAC,OAAO,EAAE;CACrC,EACD,CAAC,KAAK,EAAE,EAAE,CAAC;IACT,KAAK,CAAC,8CAA8C,CAAC,CAAC,EAAE,CACtD,+BAA+B,CAAC,KAAK,CAAC,WAAW,CAAC,EAClD,KAAK,CAAC,QAAQ,EACd,IAAI,CAAC,KAAK,CAAC,YAAY,CAAC,CACzB;IACD,KAAK,CAAC,2CAA2C,CAAC,CAAC,EAAE,CAAC,KAAK,CAAC,cAAc,CAAC;CAC5E,CACF,CAAC;AAEF,MAAM,CAAC,MAAM,2BAA2B,GAAG;IACzC,oBAAoB,CAAC,sBAAsB,CAAC;IAC5C,GAAG,+BAA+B;CACnC,CAAC","sourcesContent":["import { desc } from \"drizzle-orm\";\nimport { index, integer, sqliteTable, text } from \"drizzle-orm/sqlite-core\";\nimport { principalHistoryRetentionTables } from \"./principalHistoryRetentionSchema\";\nimport { principalCurrentFingerprintJson } from \"./principalKeyFingerprintJson\";\nimport { defineSqlTableSchema } from \"./sqlTableSchema\";\n\n/** Provisional, locally authenticated verification work; never an app checkpoint. */\nexport const principalHistoryStages = sqliteTable(\n \"principal_history_stages\",\n {\n id: text(\"id\").primaryKey(),\n organizationId: text(\"organization_id\").notNull(),\n currentJson: text(\"current_json\").notNull(),\n afterVersion: integer(\"after_version\").notNull(),\n complete: integer(\"complete\", { mode: \"boolean\" }).notNull(),\n progress: text(\"progress\").notNull(),\n },\n (table) => [\n index(\"principal_history_stages_key_fingerprint_idx\").on(\n principalCurrentFingerprintJson(table.currentJson),\n table.complete,\n desc(table.afterVersion),\n ),\n index(\"principal_history_stages_organization_idx\").on(table.organizationId),\n ],\n);\n\nexport const principalHistoryStageTables = [\n defineSqlTableSchema(principalHistoryStages),\n ...principalHistoryRetentionTables,\n];\n"]}
1
+ {"version":3,"file":"principalHistoryStageSchema.js","sourceRoot":"","sources":["principalHistoryStageSchema.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,IAAI,EAAE,MAAM,aAAa,CAAC;AACnC,OAAO,EAAE,KAAK,EAAE,OAAO,EAAE,WAAW,EAAE,IAAI,EAAE,MAAM,yBAAyB,CAAC;AAC5E,OAAO,EAAE,+BAA+B,EAAE,MAAM,mCAAmC,CAAC;AACpF,OAAO,EAAE,+BAA+B,EAAE,MAAM,+BAA+B,CAAC;AAChF,OAAO,EAAE,oBAAoB,EAAuB,MAAM,kBAAkB,CAAC;AAE7E;;;;;GAKG;AACH,MAAM,CAAC,MAAM,sBAAsB,GAAG,WAAW,CAC/C,0BAA0B,EAC1B;IACE,EAAE,EAAE,IAAI,CAAC,IAAI,CAAC,CAAC,UAAU,EAAE;IAC3B,cAAc,EAAE,IAAI,CAAC,iBAAiB,CAAC,CAAC,OAAO,EAAE;IACjD,OAAO,EAAE,IAAI,CAAC,UAAU,CAAC,CAAC,OAAO,EAAE;IACnC,WAAW,EAAE,IAAI,CAAC,cAAc,CAAC,CAAC,O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zle-orm/sqlite-core\";\nimport { principalHistoryRetentionTables } from \"./principalHistoryRetentionSchema\";\nimport { principalCurrentFingerprintJson } from \"./principalKeyFingerprintJson\";\nimport { defineSqlTableSchema, type SqlTableSchema } from \"./sqlTableSchema\";\n\n/**\n * Provisional, locally authenticated verification work; never an app\n * checkpoint. `scopeId` and `touchedAt` are eviction hints for bounded\n * retention (which principal history the stage belongs to, and when a writer\n * last used it), never authenticated recovery state.\n */\nexport const principalHistoryStages = sqliteTable(\n \"principal_history_stages\",\n {\n id: text(\"id\").primaryKey(),\n organizationId: text(\"organization_id\").notNull(),\n scopeId: text(\"scope_id\").notNull(),\n currentJson: text(\"current_json\").notNull(),\n afterVersion: integer(\"after_version\").notNull(),\n complete: integer(\"complete\", { mode: \"boolean\" }).notNull(),\n touchedAt: integer(\"touched_at\").notNull(),\n progress: text(\"progress\").notNull(),\n },\n (table) => [\n index(\"principal_history_stages_key_fingerprint_idx\").on(\n principalCurrentFingerprintJson(table.currentJson),\n table.complete,\n desc(table.afterVersion),\n ),\n index(\"principal_history_stages_organization_idx\").on(table.organizationId),\n index(\"principal_history_stages_scope_idx\").on(\n table.scopeId,\n table.organizationId,\n table.complete,\n desc(table.afterVersion),\n desc(table.touchedAt),\n table.id,\n ),\n index(\"principal_history_stages_incomplete_idx\").on(\n table.scopeId,\n table.organizationId,\n table.complete,\n desc(table.touchedAt),\n table.id,\n ),\n ],\n);\n\nexport const principalHistoryStageTables: ReadonlyArray<SqlTableSchema> = [\n {\n ...defineSqlTableSchema(principalHistoryStages),\n requiredColumns: [\"scope_id\", \"touched_at\"],\n },\n ...principalHistoryRetentionTables,\n];\n"]}