@tearleads/client-sdk 0.1.18 → 0.1.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.
Files changed (214) hide show
  1. package/client/organizations/index.js +2 -2
  2. package/client/organizations/index.js.map +1 -1
  3. package/client/organizations/organizationHistory.js +66 -0
  4. package/client/organizations/organizationHistory.js.map +1 -0
  5. package/client/organizations/organizationReadModels.d.ts +1 -1
  6. package/client/organizations/organizationReadModels.js +7 -27
  7. package/client/organizations/organizationReadModels.js.map +1 -1
  8. package/client/organizations/organizationsTypes.d.ts +1 -1
  9. package/client/organizations/organizationsTypes.js.map +1 -1
  10. package/data/containers/shared/types.d.ts +2 -2
  11. package/data/containers/shared/types.js.map +1 -1
  12. package/data/documents/shared/syncSubmitFailure.d.ts +2 -2
  13. package/data/documents/shared/syncSubmitFailure.js.map +1 -1
  14. package/data/keyingProjectionVerification/documentPurgeCheckpointCurrency.js +34 -8
  15. package/data/keyingProjectionVerification/documentPurgeCheckpointCurrency.js.map +1 -1
  16. package/data/keyingProjectionVerification/documentPurgeDocumentChainVerification.js.map +1 -1
  17. package/data/keyingProjectionVerification/documentPurgePolicyCheckpoints.js +17 -0
  18. package/data/keyingProjectionVerification/documentPurgePolicyCheckpoints.js.map +1 -0
  19. package/data/keyingProjectionVerification/documentPurgePolicyCurrency.js +55 -0
  20. package/data/keyingProjectionVerification/documentPurgePolicyCurrency.js.map +1 -0
  21. package/data/keyingProjectionVerification/documentPurgePrincipalEvidence.js +25 -13
  22. package/data/keyingProjectionVerification/documentPurgePrincipalEvidence.js.map +1 -1
  23. package/data/keyingProjectionVerification/documentPurgeProofVerification.d.ts +5 -3
  24. package/data/keyingProjectionVerification/documentPurgeProofVerification.js +52 -8
  25. package/data/keyingProjectionVerification/documentPurgeProofVerification.js.map +1 -1
  26. package/data/keyingProjectionVerification/projectionPolicyEvidence.js.map +1 -1
  27. package/data/keyingProjectionVerification/types.d.ts +4 -0
  28. package/data/keyingProjectionVerification/types.js.map +1 -1
  29. package/data/persistence/container-contents/documentMoveIntentPersistence.js.map +1 -1
  30. package/data/persistence/principalAuthorizationCheckpoints.js +1 -1
  31. package/data/persistence/principalAuthorizationCheckpoints.js.map +1 -1
  32. package/data/persistence/principalCurrentAcknowledgementPersistence.d.ts +1 -0
  33. package/data/persistence/principalCurrentAcknowledgementPersistence.js +58 -12
  34. package/data/persistence/principalCurrentAcknowledgementPersistence.js.map +1 -1
  35. package/data/persistence/principalHistoryEvidencePersistence.d.ts +2 -0
  36. package/data/persistence/principalHistoryEvidencePersistence.js +2 -0
  37. package/data/persistence/principalHistoryEvidencePersistence.js.map +1 -1
  38. package/data/persistence/principalHistoryIncompleteRetention.js +32 -0
  39. package/data/persistence/principalHistoryIncompleteRetention.js.map +1 -0
  40. package/data/persistence/principalHistoryNodeRetention.js +76 -0
  41. package/data/persistence/principalHistoryNodeRetention.js.map +1 -0
  42. package/data/persistence/principalHistoryPrefixPersistence.d.ts +1 -0
  43. package/data/persistence/principalHistoryPrefixPersistence.js +30 -1
  44. package/data/persistence/principalHistoryPrefixPersistence.js.map +1 -1
  45. package/data/persistence/principalHistoryRootOwnership.js +71 -0
  46. package/data/persistence/principalHistoryRootOwnership.js.map +1 -0
  47. package/data/persistence/principalHistoryStagePersistence.js +45 -0
  48. package/data/persistence/principalHistoryStagePersistence.js.map +1 -1
  49. package/data/persistence/principalHistoryStageRetention.js +44 -0
  50. package/data/persistence/principalHistoryStageRetention.js.map +1 -0
  51. package/data/persistence/principalHistoryUnpublishedRetention.js +71 -0
  52. package/data/persistence/principalHistoryUnpublishedRetention.js.map +1 -0
  53. package/data/persistence/principalKeyEnvelopeArchivePersistence.js +63 -0
  54. package/data/persistence/principalKeyEnvelopeArchivePersistence.js.map +1 -0
  55. package/data/persistence/principalKeyEnvelopeCandidates.js +10 -1
  56. package/data/persistence/principalKeyEnvelopeCandidates.js.map +1 -1
  57. package/data/sqlite/principalHistoryEvidenceSchema.js +2 -0
  58. package/data/sqlite/principalHistoryEvidenceSchema.js.map +1 -1
  59. package/data/sqlite/principalHistoryNodeRetentionSchema.js +30 -0
  60. package/data/sqlite/principalHistoryNodeRetentionSchema.js.map +1 -0
  61. package/data/sqlite/principalHistoryRetentionSchema.js +40 -0
  62. package/data/sqlite/principalHistoryRetentionSchema.js.map +1 -0
  63. package/data/sqlite/principalHistoryStageSchema.js +2 -0
  64. package/data/sqlite/principalHistoryStageSchema.js.map +1 -1
  65. package/data/sqlite/schema.d.ts +453 -0
  66. package/data/sqlite/schema.js +6 -0
  67. package/data/sqlite/schema.js.map +1 -1
  68. package/data/sqlite/sqliteCommitGuards.js +49 -0
  69. package/data/sqlite/sqliteCommitGuards.js.map +1 -0
  70. package/data/sqlite/sqlitePersistenceRuntime.js +14 -2
  71. package/data/sqlite/sqlitePersistenceRuntime.js.map +1 -1
  72. package/index.d.ts +3 -1
  73. package/index.js.map +1 -1
  74. package/internal/api-client/ApiClient.d.ts +60 -137
  75. package/internal/api-client/ApiClient.js +7 -5
  76. package/internal/api-client/ApiClient.js.map +1 -1
  77. package/internal/api-client/apiRequestRuntime.js +7 -7
  78. package/internal/api-client/apiRequestRuntime.js.map +1 -1
  79. package/internal/api-client/documentPurge.js +25 -0
  80. package/internal/api-client/documentPurge.js.map +1 -0
  81. package/internal/api-client/organizationPolicyHistory.d.ts +53 -0
  82. package/internal/api-client/organizationPolicyHistory.js +15 -0
  83. package/internal/api-client/organizationPolicyHistory.js.map +1 -0
  84. package/internal/api-client/requestInternals.js +4 -4
  85. package/internal/api-client/requestInternals.js.map +1 -1
  86. package/internal/api-client/types.d.ts +2 -2
  87. package/internal/api-client/types.js.map +1 -1
  88. package/internal/crypto/keying/principalPolicyHistory.js +4 -0
  89. package/internal/crypto/keying/principalPolicyHistory.js.map +1 -1
  90. package/internal/crypto/keying/principalPolicyHistoryTypes.d.ts +2 -0
  91. package/internal/crypto/keying/principalPolicyHistoryTypes.js.map +1 -1
  92. package/internal/loro/document.js +8 -11
  93. package/internal/loro/document.js.map +1 -1
  94. package/internal/validators/operation/containerMutations.d.ts +448 -6528
  95. package/internal/validators/operation/documentMutations.d.ts +323 -579
  96. package/internal/validators/operation/documentMutations.js +22 -4
  97. package/internal/validators/operation/documentMutations.js.map +1 -1
  98. package/internal/validators/operation/documentSync.d.ts +26 -406
  99. package/internal/validators/operation/organizationPolicyHistory.d.ts +188 -310
  100. package/internal/validators/operation/organizationPolicyHistory.js +17 -3
  101. package/internal/validators/operation/organizationPolicyHistory.js.map +1 -1
  102. package/internal/validators/response/containerMutationError.d.ts +28 -408
  103. package/internal/validators/response/documentMutation.d.ts +232 -544
  104. package/internal/validators/response/documentMutation.js +1 -2
  105. package/internal/validators/response/documentMutation.js.map +1 -1
  106. package/internal/validators/response/documentSyncError.d.ts +26 -406
  107. package/internal/validators/response/documentSyncError.js +4 -3
  108. package/internal/validators/response/documentSyncError.js.map +1 -1
  109. package/internal/validators/response/index.d.ts +1 -1
  110. package/internal/validators/response/index.js +1 -1
  111. package/internal/validators/response/index.js.map +1 -1
  112. package/internal/validators/response/organizationPolicyHistory.d.ts +127 -309
  113. package/internal/validators/response/organizationPolicyHistory.js +10 -4
  114. package/internal/validators/response/organizationPolicyHistory.js.map +1 -1
  115. package/internal/validators/response/principal.d.ts +28 -408
  116. package/internal/validators/response/principal.js +3 -1
  117. package/internal/validators/response/principal.js.map +1 -1
  118. package/internal/validators/util/index.d.ts +1 -1
  119. package/internal/validators/util/index.js +1 -1
  120. package/internal/validators/util/index.js.map +1 -1
  121. package/internal/validators/util/principalHistoryWire.d.ts +2 -0
  122. package/internal/validators/util/principalHistoryWire.js +2 -0
  123. package/internal/validators/util/principalHistoryWire.js.map +1 -1
  124. package/package.json +4 -4
  125. package/workflows/container-contents/container-state/createWithMetadata.js +19 -49
  126. package/workflows/container-contents/container-state/createWithMetadata.js.map +1 -1
  127. package/workflows/container-contents/container-state/groupGrantVerification.js +29 -0
  128. package/workflows/container-contents/container-state/groupGrantVerification.js.map +1 -1
  129. package/workflows/container-contents/container-state/groupShareEpoch.js +33 -0
  130. package/workflows/container-contents/container-state/groupShareEpoch.js.map +1 -0
  131. package/workflows/container-contents/container-state/remote.js +4 -1
  132. package/workflows/container-contents/container-state/remote.js.map +1 -1
  133. package/workflows/container-contents/container-state/share.js +2 -24
  134. package/workflows/container-contents/container-state/share.js.map +1 -1
  135. package/workflows/container-contents/documentTombstoneEvidence.js +23 -12
  136. package/workflows/container-contents/documentTombstoneEvidence.js.map +1 -1
  137. package/workflows/containers/child/create.js +1 -3
  138. package/workflows/containers/child/create.js.map +1 -1
  139. package/workflows/containers/child/createSubmission.d.ts +1 -3
  140. package/workflows/containers/child/createSubmission.js +13 -15
  141. package/workflows/containers/child/createSubmission.js.map +1 -1
  142. package/workflows/containers/child/currentShareGrantMutation.js +82 -0
  143. package/workflows/containers/child/currentShareGrantMutation.js.map +1 -0
  144. package/workflows/containers/child/currentSharePrincipalPolicy.js +83 -0
  145. package/workflows/containers/child/currentSharePrincipalPolicy.js.map +1 -0
  146. package/workflows/containers/child/mutationSubmit.js +1 -1
  147. package/workflows/containers/child/mutationSubmit.js.map +1 -1
  148. package/workflows/containers/child/runtimeCurrentGroupShare.js +82 -0
  149. package/workflows/containers/child/runtimeCurrentGroupShare.js.map +1 -0
  150. package/workflows/containers/child/share.js +1 -14
  151. package/workflows/containers/child/share.js.map +1 -1
  152. package/workflows/containers/child/shareProjection.js +15 -0
  153. package/workflows/containers/child/shareProjection.js.map +1 -0
  154. package/workflows/documents/purge.d.ts +3 -0
  155. package/workflows/documents/purge.js +13 -0
  156. package/workflows/documents/purge.js.map +1 -1
  157. package/workflows/documents/sync.js +2 -0
  158. package/workflows/documents/sync.js.map +1 -1
  159. package/workflows/documents/syncFailures.js +2 -2
  160. package/workflows/documents/syncFailures.js.map +1 -1
  161. package/workflows/documents/syncPolicyRepair.js +15 -13
  162. package/workflows/documents/syncPolicyRepair.js.map +1 -1
  163. package/workflows/organizations/initialPrincipalCurrentPublication.js +2 -0
  164. package/workflows/organizations/initialPrincipalCurrentPublication.js.map +1 -1
  165. package/workflows/organizations/loadPolicyHistoryDetails.js +31 -32
  166. package/workflows/organizations/loadPolicyHistoryDetails.js.map +1 -1
  167. package/workflows/organizations/organizationPolicyHistoryDetails.js +37 -15
  168. package/workflows/organizations/organizationPolicyHistoryDetails.js.map +1 -1
  169. package/workflows/organizations/organizationPolicyHistoryVerification.js +56 -69
  170. package/workflows/organizations/organizationPolicyHistoryVerification.js.map +1 -1
  171. package/workflows/organizations/policyHistoryCache.js +5 -2
  172. package/workflows/organizations/policyHistoryCache.js.map +1 -1
  173. package/workflows/organizations/policyHistoryTypes.d.ts +1 -0
  174. package/workflows/organizations/policyHistoryTypes.js.map +1 -1
  175. package/workflows/organizations/retainAcknowledgedPrincipalCurrents.js +4 -1
  176. package/workflows/organizations/retainAcknowledgedPrincipalCurrents.js.map +1 -1
  177. package/workflows/principals/loadRecoveredPrincipalHistoryPage.d.ts +0 -1
  178. package/workflows/principals/loadRecoveredPrincipalHistoryPage.js +1 -2
  179. package/workflows/principals/loadRecoveredPrincipalHistoryPage.js.map +1 -1
  180. package/workflows/principals/policyRepair.js +38 -0
  181. package/workflows/principals/policyRepair.js.map +1 -0
  182. package/workflows/principals/policyRepairBudget.d.ts +2 -2
  183. package/workflows/principals/policyRepairBudget.js +3 -3
  184. package/workflows/principals/policyRepairBudget.js.map +1 -1
  185. package/workflows/principals/principalHistoryRecoveryPrefix.js +4 -0
  186. package/workflows/principals/principalHistoryRecoveryPrefix.js.map +1 -1
  187. package/workflows/principals/principalRecoveryLocalPreference.js +3 -2
  188. package/workflows/principals/principalRecoveryLocalPreference.js.map +1 -1
  189. package/workflows/principals/publicPrincipalHistoryPage.js +1 -0
  190. package/workflows/principals/publicPrincipalHistoryPage.js.map +1 -1
  191. package/workflows/principals/publicPrincipalHistoryProgress.js +1 -0
  192. package/workflows/principals/publicPrincipalHistoryProgress.js.map +1 -1
  193. package/workflows/principals/publicPrincipalHistoryTypes.d.ts +2 -0
  194. package/workflows/principals/publicPrincipalHistoryTypes.js.map +1 -1
  195. package/workflows/principals/publicProjectionPrincipal.js +1 -0
  196. package/workflows/principals/publicProjectionPrincipal.js.map +1 -1
  197. package/workflows/principals/recoverPrincipalHistoryPage.js +2 -1
  198. package/workflows/principals/recoverPrincipalHistoryPage.js.map +1 -1
  199. package/workflows/principals/recoverPrincipalPolicyHistory.js +1 -0
  200. package/workflows/principals/recoverPrincipalPolicyHistory.js.map +1 -1
  201. package/workflows/principals/recoverPublicPrincipalHistory.js +2 -0
  202. package/workflows/principals/recoverPublicPrincipalHistory.js.map +1 -1
  203. package/workflows/principals/runtimePolicyRecovery.js +2 -1
  204. package/workflows/principals/runtimePolicyRecovery.js.map +1 -1
  205. package/workflows/principals/selectPublicPrincipalHistory.js +21 -15
  206. package/workflows/principals/selectPublicPrincipalHistory.js.map +1 -1
  207. package/workflows/sync/remoteResetPrincipalScope.js +6 -0
  208. package/workflows/sync/remoteResetPrincipalScope.js.map +1 -1
  209. package/data/keyingProjectionVerification/principalPolicySnapshotVerification.js +0 -208
  210. package/data/keyingProjectionVerification/principalPolicySnapshotVerification.js.map +0 -1
  211. package/data/keyingProjectionVerification/snapshotVerificationCache.js +0 -39
  212. package/data/keyingProjectionVerification/snapshotVerificationCache.js.map +0 -1
  213. package/workflows/containers/child/policyRepair.js +0 -23
  214. package/workflows/containers/child/policyRepair.js.map +0 -1
@@ -1 +1 @@
1
- {"version":3,"file":"principalKeyEnvelopeCandidates.js","sourceRoot":"","sources":["principalKeyEnvelopeCandidates.ts"],"names":[],"mappings":"AAAA,OAAO,EAEL,yCAAyC,GAC1C,MAAM,gCAAgC,CAAC;AACxC,OAAO,EAAE,GAAG,EAAE,IAAI,EAAE,EAAE,EAAE,GAAG,EAAE,MAAM,aAAa,CAAC;AACjD,OAAO,EACL,8BAA8B,EAC9B,wBAAwB,GACzB,MAAM,0CAA0C,CAAC;AAClD,OAAO,EAAE,sBAAsB,EAAE,MAAM,uCAAuC,CAAC;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BACd,YAAY,EAAE;oBACZ,aAAa,EAAE,SAAS,CAAC,aAAa;oBACtC,WAAW,EAAE,SAAS,CAAC,WAAW;oBAClC,SAAS,EAAE,SAAS,CAAC,SAAS;oBAC9B,cAAc,EAAE,WAAW;iBAC5B;gBACD,sBAAsB,EAAE,SAAS;aAClC,CAAC,CAAC;QACL,CAAC;IACH,CAAC;IACD,OAAO,UAAU,CAAC;AACpB,CAAC","sourcesContent":["import {\n type CurrentPrincipalMemberEnvelopesResponse,\n isCurrentPrincipalMemberEnvelopesResponse,\n} from \"@tearleads/validators/response\";\nimport { and, desc, eq, sql } from \"drizzle-orm\";\nimport {\n principalHistoryEvidenceTables,\n principalHistoryPrefixes,\n} from \"../sqlite/principalHistoryEvidenceSchema\";\nimport { principalHistoryStages } from \"../sqlite/principalHistoryStageSchema\";\nimport {\n principalCurrentFingerprintJson,\n principalStateFingerprintJson,\n} from \"../sqlite/principalKeyFingerprintJson\";\nimport {\n principalPolicies,\n principalPolicyBundleHistory,\n} from \"../sqlite/principalPolicySchema\";\nimport { principalPolicyTables } from \"../sqlite/schema\";\nimport { getClientSQLitePersistenceRuntime } from \"../sqlite/sqlitePersistenceRuntime\";\nimport { type ExecSql, ensureSqlTables } from \"../sqlite/sqlSchema\";\n\nexport interface PrincipalKeyEnvelopeCandidate {\n readonly currentState: {\n readonly principalType: \"group\" | \"organization\";\n readonly principalId: string;\n readonly stateHash: string;\n readonly keyFingerprint: string;\n };\n readonly currentMemberEnvelopes: CurrentPrincipalMemberEnvelopesResponse;\n}\n\n/**\n * Untrusted encrypted key candidates, never authorization evidence. The actual\n * private key must open the requested recipient wrap; the projection verifier\n * separately checks the signed KEK material identity and all policy authority.\n * Read only envelopes for the requested fingerprints, never signed histories.\n */\nexport async function loadPrincipalKeyEnvelopeCandidates(\n execSql: ExecSql,\n fingerprints: readonly string[],\n): Promise<PrincipalKeyEnvelopeCandidate[]> {\n await ensureSqlTables(execSql, [\n ...principalPolicyTables,\n ...principalHistoryEvidenceTables,\n ]);\n const { db } = getClientSQLitePersistenceRuntime(execSql);\n const candidates: PrincipalKeyEnvelopeCandidate[] = [];\n for (const fingerprint of new Set(fingerprints)) {\n const encoded: string[] = [];\n for (const table of [principalPolicies, principalPolicyBundleHistory]) {\n const [row] = await db\n .select({ envelopes: table.currentMemberEnvelopesJson })\n .from(table)\n .where(\n eq(\n principalStateFingerprintJson(table.currentStateJson),\n fingerprint,\n ),\n )\n .orderBy(desc(table.updatedAt))\n .limit(1);\n if (row) encoded.push(row.envelopes);\n }\n const [prefix] = await db\n .select({\n envelopes: sql<string>`json_extract(${principalHistoryPrefixes.currentJson}, '$.currentMemberEnvelopes')`,\n })\n .from(principalHistoryPrefixes)\n .where(\n eq(\n principalCurrentFingerprintJson(principalHistoryPrefixes.currentJson),\n fingerprint,\n ),\n )\n .orderBy(desc(principalHistoryPrefixes.version))\n .limit(1);\n if (prefix) encoded.push(prefix.envelopes);\n const [stage] = await db\n .select({\n envelopes: sql<string>`json_extract(${principalHistoryStages.currentJson}, '$.currentMemberEnvelopes')`,\n })\n .from(principalHistoryStages)\n .where(\n and(\n eq(\n principalCurrentFingerprintJson(principalHistoryStages.currentJson),\n fingerprint,\n ),\n eq(principalHistoryStages.complete, true),\n ),\n )\n .orderBy(desc(principalHistoryStages.afterVersion))\n .limit(1);\n if (stage) encoded.push(stage.envelopes);\n for (const json of encoded) {\n let envelopes: unknown;\n try {\n envelopes = JSON.parse(json);\n } catch {\n continue;\n }\n if (!isCurrentPrincipalMemberEnvelopesResponse(envelopes)) continue;\n candidates.push({\n currentState: {\n principalType: envelopes.principalType,\n principalId: envelopes.principalId,\n stateHash: envelopes.stateHash,\n keyFingerprint: fingerprint,\n },\n currentMemberEnvelopes: envelopes,\n });\n }\n }\n return candidates;\n}\n"]}
1
+ {"version":3,"file":"principalKeyEnvelopeCandidates.js","sourceRoot":"","sources":["principalKeyEnvelopeCandidates.ts"],"names":[],"mappings":"AAAA,OAAO,EAEL,yCAAyC,GAC1C,MAA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xG,CAAC;aACD,IAAI,CAAC,sBAAsB,CAAC;aAC5B,KAAK,CACJ,GAAG,CACD,EAAE,CACA,+BAA+B,CAAC,sBAAsB,CAAC,WAAW,CAAC,EACnE,WAAW,CACZ,EACD,EAAE,CAAC,sBAAsB,CAAC,QAAQ,EAAE,IAAI,CAAC,CAC1C,CACF;aACA,OAAO,CAAC,IAAI,CAAC,sBAAsB,CAAC,YAAY,CAAC,CAAC;aAClD,KAAK,CAAC,CAAC,CAAC,CAAC;QACZ,IAAI,KAAK;YAAE,OAAO,CAAC,IAAI,CAAC,KAAK,CAAC,SAAS,CAAC,CAAC;QACzC,KAAK,MAAM,IAAI,IAAI,IAAI,GAAG,CAAC,OAAO,CAAC,EAAE,CAAC;YACpC,IAAI,SAAkB,CAAC;YACvB,IAAI,CAAC;gBACH,SAAS,GAAG,IAAI,CAAC,KAAK,CAAC,IAAI,CAAC,CAAC;YAC/B,CAAC;YAAC,MAAM,CAAC;gBACP,SAAS;YACX,CAAC;YACD,IAAI,CAAC,yCAAyC,CAAC,SAAS,CAAC;gBAAE,SAAS;YACpE,UAAU,CAAC,IAAI,CAAC;gBACd,YAAY,EAAE;oBACZ,aAAa,EAAE,SAAS,CAAC,aAAa;oBACtC,WAAW,EAAE,SAAS,CAAC,WAAW;oBAClC,SAAS,EAAE,SAAS,CAAC,SAAS;oBAC9B,cAAc,EAAE,WAAW;iBAC5B;gBACD,sBAAsB,EAAE,SAAS;aAClC,CAAC,CAAC;QACL,CAAC;IACH,CAAC;IACD,OAAO,UAAU,CAAC;AACpB,CAAC","sourcesContent":["import {\n type CurrentPrincipalMemberEnvelopesResponse,\n isCurrentPrincipalMemberEnvelopesResponse,\n} from \"@tearleads/validators/response\";\nimport { and, desc, eq, sql } from \"drizzle-orm\";\nimport {\n principalHistoryEvidenceTables,\n principalHistoryPrefixes,\n} from \"../sqlite/principalHistoryEvidenceSchema\";\nimport { principalKeyEnvelopeArchive } from \"../sqlite/principalHistoryRetentionSchema\";\nimport { principalHistoryStages } from \"../sqlite/principalHistoryStageSchema\";\nimport {\n principalCurrentFingerprintJson,\n principalStateFingerprintJson,\n} from \"../sqlite/principalKeyFingerprintJson\";\nimport {\n principalPolicies,\n principalPolicyBundleHistory,\n} from \"../sqlite/principalPolicySchema\";\nimport { principalPolicyTables } from \"../sqlite/schema\";\nimport { getClientSQLitePersistenceRuntime } from \"../sqlite/sqlitePersistenceRuntime\";\nimport { type ExecSql, ensureSqlTables } from \"../sqlite/sqlSchema\";\n\nexport interface PrincipalKeyEnvelopeCandidate {\n readonly currentState: {\n readonly principalType: \"group\" | \"organization\";\n readonly principalId: string;\n readonly stateHash: string;\n readonly keyFingerprint: string;\n };\n readonly currentMemberEnvelopes: CurrentPrincipalMemberEnvelopesResponse;\n}\n\n/**\n * Untrusted encrypted key candidates, never authorization evidence. The actual\n * private key must open the requested recipient wrap; the projection verifier\n * separately checks the signed KEK material identity and all policy authority.\n * Read only envelopes for the requested fingerprints, never signed histories.\n */\nexport async function loadPrincipalKeyEnvelopeCandidates(\n execSql: ExecSql,\n fingerprints: readonly string[],\n): Promise<PrincipalKeyEnvelopeCandidate[]> {\n await ensureSqlTables(execSql, [\n ...principalPolicyTables,\n ...principalHistoryEvidenceTables,\n ]);\n const { db } = getClientSQLitePersistenceRuntime(execSql);\n const candidates: PrincipalKeyEnvelopeCandidate[] = [];\n for (const fingerprint of new Set(fingerprints)) {\n const encoded: string[] = [];\n const [archived] = await db\n .select({ envelopes: principalKeyEnvelopeArchive.envelopesJson })\n .from(principalKeyEnvelopeArchive)\n .where(eq(principalKeyEnvelopeArchive.keyFingerprint, fingerprint))\n .orderBy(desc(principalKeyEnvelopeArchive.version))\n .limit(1);\n if (archived) encoded.push(archived.envelopes);\n for (const table of [principalPolicies, principalPolicyBundleHistory]) {\n const [row] = await db\n .select({ envelopes: table.currentMemberEnvelopesJson })\n .from(table)\n .where(\n eq(\n principalStateFingerprintJson(table.currentStateJson),\n fingerprint,\n ),\n )\n .orderBy(desc(table.updatedAt))\n .limit(1);\n if (row) encoded.push(row.envelopes);\n }\n const [prefix] = await db\n .select({\n envelopes: sql<string>`json_extract(${principalHistoryPrefixes.currentJson}, '$.currentMemberEnvelopes')`,\n })\n .from(principalHistoryPrefixes)\n .where(\n eq(\n principalCurrentFingerprintJson(principalHistoryPrefixes.currentJson),\n fingerprint,\n ),\n )\n .orderBy(desc(principalHistoryPrefixes.version))\n .limit(1);\n if (prefix) encoded.push(prefix.envelopes);\n const [stage] = await db\n .select({\n envelopes: sql<string>`json_extract(${principalHistoryStages.currentJson}, '$.currentMemberEnvelopes')`,\n })\n .from(principalHistoryStages)\n .where(\n and(\n eq(\n principalCurrentFingerprintJson(principalHistoryStages.currentJson),\n fingerprint,\n ),\n eq(principalHistoryStages.complete, true),\n ),\n )\n .orderBy(desc(principalHistoryStages.afterVersion))\n .limit(1);\n if (stage) encoded.push(stage.envelopes);\n for (const json of new Set(encoded)) {\n let envelopes: unknown;\n try {\n envelopes = JSON.parse(json);\n } catch {\n continue;\n }\n if (!isCurrentPrincipalMemberEnvelopesResponse(envelopes)) continue;\n candidates.push({\n currentState: {\n principalType: envelopes.principalType,\n principalId: envelopes.principalId,\n stateHash: envelopes.stateHash,\n keyFingerprint: fingerprint,\n },\n currentMemberEnvelopes: envelopes,\n });\n }\n }\n return candidates;\n}\n"]}
@@ -1,5 +1,6 @@
1
1
  import { desc } from "drizzle-orm";
2
2
  import { index, integer, primaryKey, sqliteTable, text, } from "drizzle-orm/sqlite-core";
3
+ import { principalHistoryNodeRetentionTables } from "./principalHistoryNodeRetentionSchema.js";
3
4
  import { principalCurrentFingerprintJson } from "./principalKeyFingerprintJson.js";
4
5
  import { defineSqlTableSchema } from "./sqlTableSchema.js";
5
6
  /** A completed, locally authenticated prefix; never an application trust pin. */
@@ -36,6 +37,7 @@ export const principalHistoryNodes = sqliteTable("principal_history_nodes", {
36
37
  index("principal_history_nodes_organization_idx").on(table.organizationId),
37
38
  ]);
38
39
  export const principalHistoryEvidenceTables = [
40
+ ...principalHistoryNodeRetentionTables,
39
41
  {
40
42
  ...defineSqlTableSchema(principalHistoryPrefixes),
41
43
  requiredColumns: ["current_json"],
@@ -1 +1 @@
1
- {"version":3,"file":"principalHistoryEvidenceSchema.js","sourceRoot":"","sources":["principalHistoryEvidenceSchema.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,+BAA+B,EAAE,MAAM,+BAA+B,CAAC;AAChF,OAAO,EAAE,oBAAoB,EAAE,MAAM,kBAAkB,CAAC;AAExD,iFAAiF;AACjF,MAAM,CAAC,MAAM,wBAAwB,GAAG,WAAW,CACjD,4BAA4B,EAC5B;IACE,OAAO,EAAE,IAAI,CAAC,UAAU,CAAC,CAAC,UAAU,EAAE;IACtC,cAAc,EAAE,IAAI,CAAC,iBAAiB,CAAC,CAAC,OAAO,EAAE;IACjD,OAAO,EAAE,OAAO,CAAC,SAAS,CAAC,CAAC,OAAO,EAAE;IACrC,QAAQ,EAAE,IAAI,CAAC,WAAW,CAAC,CAAC,OAAO,EAAE;IACrC,WAAW,EAAE,IAAI,CAAC,cAAc,CAAC,CAAC,OAAO,EAAE;IAC3C,QAAQ,EAAE,IAAI,CAAC,UAAU,CAAC,CAAC,OAAO,EAAE;CACrC,EACD,CAAC,KAAK,EAAE,EAAE,CAAC;IACT,KAAK,CAAC,gDAAgD,CAAC,CAAC,EAAE,CACxD,+BAA+B,CAAC,KAAK,CAAC,WAAW,CAAC,EAClD,IAAI,CAAC,KAAK,CAAC,OAAO,CAAC,CACpB;IACD,KAAK,CAAC,6CAA6C,CAAC,CAAC,EAAE,CACrD,KAAK,CAAC,cAAc,CACrB;CACF,CACF,CAAC;AAEF,kFAAkF;AAClF,MAAM,CAAC,MAAM,uBAAuB,GAAG,WAAW,CAChD,2BAA2B,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ACD,oBAAoB,CAAC,uBAAuB,CAAC;IAC7C,oBAAoB,CAAC,qBAAqB,CAAC;CAC5C,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 { principalCurrentFingerprintJson } from \"./principalKeyFingerprintJson\";\nimport { defineSqlTableSchema } from \"./sqlTableSchema\";\n\n/** A completed, locally authenticated prefix; never an application trust pin. */\nexport const principalHistoryPrefixes = sqliteTable(\n \"principal_history_prefixes\",\n {\n scopeId: text(\"scope_id\").primaryKey(),\n organizationId: text(\"organization_id\").notNull(),\n version: integer(\"version\").notNull(),\n headJson: text(\"head_json\").notNull(),\n currentJson: text(\"current_json\").notNull(),\n progress: text(\"progress\").notNull(),\n },\n (table) => [\n index(\"principal_history_prefixes_key_fingerprint_idx\").on(\n principalCurrentFingerprintJson(table.currentJson),\n desc(table.version),\n ),\n index(\"principal_history_prefixes_organization_idx\").on(\n table.organizationId,\n ),\n ],\n);\n\n/** Entries are selected by their exact signed leaf, including signature bytes. */\nexport const principalHistoryEntries = sqliteTable(\n \"principal_history_entries\",\n {\n scopeId: text(\"scope_id\").notNull(),\n organizationId: text(\"organization_id\").notNull(),\n leafHash: text(\"leaf_hash\").notNull(),\n entryJson: text(\"entry_json\").notNull(),\n },\n (table) => [\n primaryKey({ columns: [table.scopeId, table.leafHash] }),\n index(\"principal_history_entries_organization_idx\").on(\n table.organizationId,\n ),\n ],\n);\n\n/** Untrusted proof material, checked against a locally restored private root. */\nexport const principalHistoryNodes = sqliteTable(\n \"principal_history_nodes\",\n {\n scopeId: text(\"scope_id\").notNull(),\n organizationId: text(\"organization_id\").notNull(),\n hash: text(\"hash\").notNull(),\n leftHash: text(\"left_hash\").notNull(),\n rightHash: text(\"right_hash\").notNull(),\n },\n (table) => [\n primaryKey({ columns: [table.scopeId, table.hash] }),\n index(\"principal_history_nodes_organization_idx\").on(table.organizationId),\n ],\n);\n\nexport const principalHistoryEvidenceTables = [\n {\n ...defineSqlTableSchema(principalHistoryPrefixes),\n requiredColumns: [\"current_json\"],\n },\n defineSqlTableSchema(principalHistoryEntries),\n defineSqlTableSchema(principalHistoryNodes),\n];\n"]}
1
+ {"version":3,"file":"principalHistoryEvidenceSchema.js","sourceRoot":"","sources":["principalHistoryEvidenceSchema.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,mCAAmC,EAAE,MAAM,uCAAuC,CAAC;AAC5F,OAAO,EAAE,+BAA+B,EAAE,MAAM,+BAA+B,CAAC;AAChF,OAAO,EAAE,oBAAoB,EAAE,MAAM,kBAAkB,CAAC;AAExD,iFAAiF;AACjF,MAAM,CAAC,MAAM,wBAAwB,GAAG,WAAW,CACjD,4BAA4B,EAC5B;IACE,OAAO,EAAE,IAAI,CAAC,UAAU,CAAC,CAAC,UAAU,EAAE;IACtC,cAAc,EAAE,IAAI,CAAC,iBAAiB,CAAC,CAAC,OAAO,EAAE;IACjD,OAAO,EAAE,OAAO,CAAC,SAAS,CAAC,CAAC,OAAO,EAAE;IACrC,QAAQ,EAAE,IAAI,CAAC,WAAW,CAAC,CAAC,OAAO,EAAE;IACrC,WAAW,EAAE,IAAI,CAAC,cAAc,CAAC,CAAC,OAAO,EAAE;IAC3C,QAAQ,EAAE,IAAI,CAAC,UAAU,CAAC,CAAC,OAAO,EAAE;CACrC,EACD,CAAC,KAAK,EAAE,EAAE,CAAC;IACT,KAAK,CAAC,gDAAgD,CAAC,CAAC,EAAE,CACxD,+BAA+B,CAAC,KAAK,CAAC,WAAW,CAAC,EAClD,IAAI,CAAC,KAAK,CAAC,OAAO,CAAC,CACpB;IACD,KAAK,CAAC,6CAA6C,CAAC,CAAC,EAAE,CACrD,KAAK,CAAC,cAAc,CACrB;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AC5C,GAAG,mCAAmC;IACtC;QACE,GAAG,oBAAoB,CAAC,wBAAwB,CAAC;QACjD,eAAe,EAAE,CAAC,cAAc,CAAC;KAClC;IACD,oBAAoB,CAAC,uBAAuB,CAAC;IAC7C,oBAAoB,CAAC,qBAAqB,CAAC;CAC5C,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 { principalHistoryNodeRetentionTables } from \"./principalHistoryNodeRetentionSchema\";\nimport { principalCurrentFingerprintJson } from \"./principalKeyFingerprintJson\";\nimport { defineSqlTableSchema } from \"./sqlTableSchema\";\n\n/** A completed, locally authenticated prefix; never an application trust pin. */\nexport const principalHistoryPrefixes = sqliteTable(\n \"principal_history_prefixes\",\n {\n scopeId: text(\"scope_id\").primaryKey(),\n organizationId: text(\"organization_id\").notNull(),\n version: integer(\"version\").notNull(),\n headJson: text(\"head_json\").notNull(),\n currentJson: text(\"current_json\").notNull(),\n progress: text(\"progress\").notNull(),\n },\n (table) => [\n index(\"principal_history_prefixes_key_fingerprint_idx\").on(\n principalCurrentFingerprintJson(table.currentJson),\n desc(table.version),\n ),\n index(\"principal_history_prefixes_organization_idx\").on(\n table.organizationId,\n ),\n ],\n);\n\n/** Entries are selected by their exact signed leaf, including signature bytes. */\nexport const principalHistoryEntries = sqliteTable(\n \"principal_history_entries\",\n {\n scopeId: text(\"scope_id\").notNull(),\n organizationId: text(\"organization_id\").notNull(),\n leafHash: text(\"leaf_hash\").notNull(),\n entryJson: text(\"entry_json\").notNull(),\n },\n (table) => [\n primaryKey({ columns: [table.scopeId, table.leafHash] }),\n index(\"principal_history_entries_organization_idx\").on(\n table.organizationId,\n ),\n ],\n);\n\n/** Untrusted proof material, checked against a locally restored private root. */\nexport const principalHistoryNodes = sqliteTable(\n \"principal_history_nodes\",\n {\n scopeId: text(\"scope_id\").notNull(),\n organizationId: text(\"organization_id\").notNull(),\n hash: text(\"hash\").notNull(),\n leftHash: text(\"left_hash\").notNull(),\n rightHash: text(\"right_hash\").notNull(),\n },\n (table) => [\n primaryKey({ columns: [table.scopeId, table.hash] }),\n index(\"principal_history_nodes_organization_idx\").on(table.organizationId),\n ],\n);\n\nexport const principalHistoryEvidenceTables = [\n ...principalHistoryNodeRetentionTables,\n {\n ...defineSqlTableSchema(principalHistoryPrefixes),\n requiredColumns: [\"current_json\"],\n },\n defineSqlTableSchema(principalHistoryEntries),\n defineSqlTableSchema(principalHistoryNodes),\n];\n"]}
@@ -0,0 +1,30 @@
1
+ import { index, integer, primaryKey, sqliteTable, text, } from "drizzle-orm/sqlite-core";
2
+ import { defineSqlTableSchema } from "./sqlTableSchema.js";
3
+ /** Disposable graph liveness hints. Proof verification still authenticates every node. */
4
+ export const principalHistoryNodeReferences = sqliteTable("principal_history_node_references", {
5
+ scopeId: text("scope_id").notNull(),
6
+ organizationId: text("organization_id").notNull(),
7
+ hash: text("hash").notNull(),
8
+ referenceCount: integer("reference_count").notNull(),
9
+ managed: integer("managed", { mode: "boolean" }).notNull(),
10
+ leftHash: text("left_hash"),
11
+ rightHash: text("right_hash"),
12
+ }, (table) => [
13
+ primaryKey({ columns: [table.scopeId, table.hash] }),
14
+ index("principal_history_node_references_reclaim_idx").on(table.scopeId, table.organizationId, table.managed, table.referenceCount, table.hash),
15
+ index("principal_history_node_references_organization_idx").on(table.organizationId),
16
+ ]);
17
+ /** A saved stage or prefix keeps its proof root live until its guarded replacement. */
18
+ export const principalHistoryRootOwners = sqliteTable("principal_history_root_owners", {
19
+ id: text("id").primaryKey(),
20
+ scopeId: text("scope_id").notNull(),
21
+ organizationId: text("organization_id").notNull(),
22
+ rootHash: text("root_hash").notNull(),
23
+ }, (table) => [
24
+ index("principal_history_root_owners_organization_idx").on(table.organizationId),
25
+ ]);
26
+ export const principalHistoryNodeRetentionTables = [
27
+ defineSqlTableSchema(principalHistoryNodeReferences),
28
+ defineSqlTableSchema(principalHistoryRootOwners),
29
+ ];
30
+ //# sourceMappingURL=principalHistoryNodeRetentionSchema.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"principalHistoryNodeRetentionSchema.js","sourceRoot":"","sources":["principalHistoryNodeRetentionSchema.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,0FAA0F;AAC1F,MAAM,CAAC,MAAM,8BAA8B,GAAG,WAAW,CACvD,mCAAmC,EACnC;IACE,OAAO,EAAE,IAAI,CAAC,UAAU,CAAC,CAAC,OAAO,EAAE;IACnC,cAAc,EAAE,IAAI,CAAC,iBAAiB,CAAC,CAAC,OAAO,EAAE;IACjD,IAAI,EAAE,IAAI,CAAC,MAAM,CAAC,CAAC,OAAO,EAAE;IAC5B,cAAc,EAAE,OAAO,CAAC,iBAAiB,CAAC,CAAC,OAAO,EAAE;IACpD,OAAO,EAAE,OAAO,CAAC,SAAS,EAAE,EAAE,IAAI,EAAE,SAAS,EAAE,CAAC,CAAC,OAAO,EAAE;IAC1D,QAAQ,EAAE,IAAI,CAAC,WAAW,CAAC;IAC3B,SAAS,EAAE,IAAI,CAAC,YAAY,CAAC;CAC9B,EACD,CAAC,KAAK,EAAE,EAAE,CAAC;IACT,UAAU,CAAC,EAAE,OAAO,EAAE,CAAC,KAAK,CAAC,OAAO,EAAE,KAAK,CAAC,IAAI,CAAC,EAAE,CAAC;IACpD,KAAK,CAAC,+CAA+C,CAAC,CAAC,EAAE,CACvD,KAAK,CAAC,OAAO,EACb,KAAK,CAAC,cAAc,EACpB,KAAK,CAAC,OAAO,EACb,KAAK,CAAC,cAAc,EACpB,KAAK,CAAC,IAAI,CACX;IACD,KAAK,CAAC,oDAAoD,CAAC,CAAC,EAAE,CAC5D,KAAK,CAAC,cAAc,CACrB;CACF,CACF,CAAC;AAEF,uFAAuF;AACvF,MAAM,CAAC,MAAM,0BAA0B,GAAG,WAAW,CACnD,+BAA+B,EAC/B;IACE,EAAE,EAAE,IAAI,CAAC,IAAI,CAAC,CAAC,UAAU,EAAE;IAC3B,OAAO,EAAE,IAAI,CAAC,UAAU,CAAC,CAAC,OAAO,EAAE;IACnC,cAAc,EAAE,IAAI,CAAC,iBAAiB,CAAC,CAAC,OAAO,EAAE;IACjD,QAAQ,EAAE,IAAI,CAAC,WAAW,CAAC,CAAC,OAAO,EAAE;CACtC,EACD,CAAC,KAAK,EAAE,EAAE,CAAC;IACT,KAAK,CAAC,gDAAgD,CAAC,CAAC,EAAE,CACxD,KAAK,CAAC,cAAc,CACrB;CACF,CACF,CAAC;AAEF,MAAM,CAAC,MAAM,mCAAmC,GAAG;IACjD,oBAAoB,CAAC,8BAA8B,CAAC;IACpD,oBAAoB,CAAC,0BAA0B,CAAC;CACjD,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/** Disposable graph liveness hints. Proof verification still authenticates every node. */\nexport const principalHistoryNodeReferences = sqliteTable(\n \"principal_history_node_references\",\n {\n scopeId: text(\"scope_id\").notNull(),\n organizationId: text(\"organization_id\").notNull(),\n hash: text(\"hash\").notNull(),\n referenceCount: integer(\"reference_count\").notNull(),\n managed: integer(\"managed\", { mode: \"boolean\" }).notNull(),\n leftHash: text(\"left_hash\"),\n rightHash: text(\"right_hash\"),\n },\n (table) => [\n primaryKey({ columns: [table.scopeId, table.hash] }),\n index(\"principal_history_node_references_reclaim_idx\").on(\n table.scopeId,\n table.organizationId,\n table.managed,\n table.referenceCount,\n table.hash,\n ),\n index(\"principal_history_node_references_organization_idx\").on(\n table.organizationId,\n ),\n ],\n);\n\n/** A saved stage or prefix keeps its proof root live until its guarded replacement. */\nexport const principalHistoryRootOwners = sqliteTable(\n \"principal_history_root_owners\",\n {\n id: text(\"id\").primaryKey(),\n scopeId: text(\"scope_id\").notNull(),\n organizationId: text(\"organization_id\").notNull(),\n rootHash: text(\"root_hash\").notNull(),\n },\n (table) => [\n index(\"principal_history_root_owners_organization_idx\").on(\n table.organizationId,\n ),\n ],\n);\n\nexport const principalHistoryNodeRetentionTables = [\n defineSqlTableSchema(principalHistoryNodeReferences),\n defineSqlTableSchema(principalHistoryRootOwners),\n];\n"]}
@@ -0,0 +1,40 @@
1
+ import { desc } from "drizzle-orm";
2
+ import { index, integer, primaryKey, sqliteTable, text, } from "drizzle-orm/sqlite-core";
3
+ import { defineSqlTableSchema } from "./sqlTableSchema.js";
4
+ /** Encrypted key candidates survive disposable progress reclamation. */
5
+ export const principalKeyEnvelopeArchive = sqliteTable("principal_key_envelope_archive", {
6
+ organizationId: text("organization_id").notNull(),
7
+ principalType: text("principal_type").notNull(),
8
+ principalId: text("principal_id").notNull(),
9
+ keyFingerprint: text("key_fingerprint").notNull(),
10
+ version: integer("version").notNull(),
11
+ envelopesJson: text("envelopes_json").notNull(),
12
+ }, (table) => [
13
+ primaryKey({
14
+ columns: [
15
+ table.organizationId,
16
+ table.principalType,
17
+ table.principalId,
18
+ table.keyFingerprint,
19
+ ],
20
+ }),
21
+ index("principal_key_envelope_archive_fingerprint_idx").on(table.keyFingerprint, table.version),
22
+ ]);
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
+ export const principalHistoryRetentionTables = [
37
+ defineSqlTableSchema(principalKeyEnvelopeArchive),
38
+ defineSqlTableSchema(principalHistoryStageScopes),
39
+ ];
40
+ //# sourceMappingURL=principalHistoryRetentionSchema.js.map
@@ -0,0 +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,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;C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,\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,5 +1,6 @@
1
1
  import { desc } from "drizzle-orm";
2
2
  import { index, integer, sqliteTable, text } from "drizzle-orm/sqlite-core";
3
+ import { principalHistoryRetentionTables } from "./principalHistoryRetentionSchema.js";
3
4
  import { principalCurrentFingerprintJson } from "./principalKeyFingerprintJson.js";
4
5
  import { defineSqlTableSchema } from "./sqlTableSchema.js";
5
6
  /** Provisional, locally authenticated verification work; never an app checkpoint. */
@@ -16,5 +17,6 @@ export const principalHistoryStages = sqliteTable("principal_history_stages", {
16
17
  ]);
17
18
  export const principalHistoryStageTables = [
18
19
  defineSqlTableSchema(principalHistoryStages),
20
+ ...principalHistoryRetentionTables,
19
21
  ];
20
22
  //# 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,+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;CAC7C,CAAC","sourcesContent":["import { desc } from \"drizzle-orm\";\nimport { index, integer, sqliteTable, text } from \"drizzle-orm/sqlite-core\";\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];\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,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"]}
@@ -6510,6 +6510,459 @@ export declare const clientSQLiteSchema: {
6510
6510
  };
6511
6511
  dialect: "sqlite";
6512
6512
  }>;
6513
+ principalHistoryNodeReferences: import("drizzle-orm/sqlite-core").SQLiteTableWithColumns<{
6514
+ name: "principal_history_node_references";
6515
+ schema: undefined;
6516
+ columns: {
6517
+ scopeId: import("drizzle-orm/sqlite-core").SQLiteColumn<{
6518
+ name: "scope_id";
6519
+ tableName: "principal_history_node_references";
6520
+ dataType: "string";
6521
+ columnType: "SQLiteText";
6522
+ data: string;
6523
+ driverParam: string;
6524
+ notNull: true;
6525
+ hasDefault: false;
6526
+ isPrimaryKey: false;
6527
+ isAutoincrement: false;
6528
+ hasRuntimeDefault: false;
6529
+ enumValues: [string, ...string[]];
6530
+ baseColumn: never;
6531
+ identity: undefined;
6532
+ generated: undefined;
6533
+ }, {}, {
6534
+ length: number | undefined;
6535
+ }>;
6536
+ organizationId: import("drizzle-orm/sqlite-core").SQLiteColumn<{
6537
+ name: "organization_id";
6538
+ tableName: "principal_history_node_references";
6539
+ dataType: "string";
6540
+ columnType: "SQLiteText";
6541
+ data: string;
6542
+ driverParam: string;
6543
+ notNull: true;
6544
+ hasDefault: false;
6545
+ isPrimaryKey: false;
6546
+ isAutoincrement: false;
6547
+ hasRuntimeDefault: false;
6548
+ enumValues: [string, ...string[]];
6549
+ baseColumn: never;
6550
+ identity: undefined;
6551
+ generated: undefined;
6552
+ }, {}, {
6553
+ length: number | undefined;
6554
+ }>;
6555
+ hash: import("drizzle-orm/sqlite-core").SQLiteColumn<{
6556
+ name: "hash";
6557
+ tableName: "principal_history_node_references";
6558
+ dataType: "string";
6559
+ columnType: "SQLiteText";
6560
+ data: string;
6561
+ driverParam: string;
6562
+ notNull: true;
6563
+ hasDefault: false;
6564
+ isPrimaryKey: false;
6565
+ isAutoincrement: false;
6566
+ hasRuntimeDefault: false;
6567
+ enumValues: [string, ...string[]];
6568
+ baseColumn: never;
6569
+ identity: undefined;
6570
+ generated: undefined;
6571
+ }, {}, {
6572
+ length: number | undefined;
6573
+ }>;
6574
+ referenceCount: import("drizzle-orm/sqlite-core").SQLiteColumn<{
6575
+ name: "reference_count";
6576
+ tableName: "principal_history_node_references";
6577
+ dataType: "number";
6578
+ columnType: "SQLiteInteger";
6579
+ data: number;
6580
+ driverParam: number;
6581
+ notNull: true;
6582
+ hasDefault: false;
6583
+ isPrimaryKey: false;
6584
+ isAutoincrement: false;
6585
+ hasRuntimeDefault: false;
6586
+ enumValues: undefined;
6587
+ baseColumn: never;
6588
+ identity: undefined;
6589
+ generated: undefined;
6590
+ }, {}, {}>;
6591
+ managed: import("drizzle-orm/sqlite-core").SQLiteColumn<{
6592
+ name: "managed";
6593
+ tableName: "principal_history_node_references";
6594
+ dataType: "boolean";
6595
+ columnType: "SQLiteBoolean";
6596
+ data: boolean;
6597
+ driverParam: number;
6598
+ notNull: true;
6599
+ hasDefault: false;
6600
+ isPrimaryKey: false;
6601
+ isAutoincrement: false;
6602
+ hasRuntimeDefault: false;
6603
+ enumValues: undefined;
6604
+ baseColumn: never;
6605
+ identity: undefined;
6606
+ generated: undefined;
6607
+ }, {}, {}>;
6608
+ leftHash: import("drizzle-orm/sqlite-core").SQLiteColumn<{
6609
+ name: "left_hash";
6610
+ tableName: "principal_history_node_references";
6611
+ dataType: "string";
6612
+ columnType: "SQLiteText";
6613
+ data: string;
6614
+ driverParam: string;
6615
+ notNull: false;
6616
+ hasDefault: false;
6617
+ isPrimaryKey: false;
6618
+ isAutoincrement: false;
6619
+ hasRuntimeDefault: false;
6620
+ enumValues: [string, ...string[]];
6621
+ baseColumn: never;
6622
+ identity: undefined;
6623
+ generated: undefined;
6624
+ }, {}, {
6625
+ length: number | undefined;
6626
+ }>;
6627
+ rightHash: import("drizzle-orm/sqlite-core").SQLiteColumn<{
6628
+ name: "right_hash";
6629
+ tableName: "principal_history_node_references";
6630
+ dataType: "string";
6631
+ columnType: "SQLiteText";
6632
+ data: string;
6633
+ driverParam: string;
6634
+ notNull: false;
6635
+ hasDefault: false;
6636
+ isPrimaryKey: false;
6637
+ isAutoincrement: false;
6638
+ hasRuntimeDefault: false;
6639
+ enumValues: [string, ...string[]];
6640
+ baseColumn: never;
6641
+ identity: undefined;
6642
+ generated: undefined;
6643
+ }, {}, {
6644
+ length: number | undefined;
6645
+ }>;
6646
+ };
6647
+ dialect: "sqlite";
6648
+ }>;
6649
+ principalHistoryRootOwners: import("drizzle-orm/sqlite-core").SQLiteTableWithColumns<{
6650
+ name: "principal_history_root_owners";
6651
+ schema: undefined;
6652
+ columns: {
6653
+ id: import("drizzle-orm/sqlite-core").SQLiteColumn<{
6654
+ name: "id";
6655
+ tableName: "principal_history_root_owners";
6656
+ dataType: "string";
6657
+ columnType: "SQLiteText";
6658
+ data: string;
6659
+ driverParam: string;
6660
+ notNull: true;
6661
+ hasDefault: false;
6662
+ isPrimaryKey: true;
6663
+ isAutoincrement: false;
6664
+ hasRuntimeDefault: false;
6665
+ enumValues: [string, ...string[]];
6666
+ baseColumn: never;
6667
+ identity: undefined;
6668
+ generated: undefined;
6669
+ }, {}, {
6670
+ length: number | undefined;
6671
+ }>;
6672
+ scopeId: import("drizzle-orm/sqlite-core").SQLiteColumn<{
6673
+ name: "scope_id";
6674
+ tableName: "principal_history_root_owners";
6675
+ dataType: "string";
6676
+ columnType: "SQLiteText";
6677
+ data: string;
6678
+ driverParam: string;
6679
+ notNull: true;
6680
+ hasDefault: false;
6681
+ isPrimaryKey: false;
6682
+ isAutoincrement: false;
6683
+ hasRuntimeDefault: false;
6684
+ enumValues: [string, ...string[]];
6685
+ baseColumn: never;
6686
+ identity: undefined;
6687
+ generated: undefined;
6688
+ }, {}, {
6689
+ length: number | undefined;
6690
+ }>;
6691
+ organizationId: import("drizzle-orm/sqlite-core").SQLiteColumn<{
6692
+ name: "organization_id";
6693
+ tableName: "principal_history_root_owners";
6694
+ dataType: "string";
6695
+ columnType: "SQLiteText";
6696
+ data: string;
6697
+ driverParam: string;
6698
+ notNull: true;
6699
+ hasDefault: false;
6700
+ isPrimaryKey: false;
6701
+ isAutoincrement: false;
6702
+ hasRuntimeDefault: false;
6703
+ enumValues: [string, ...string[]];
6704
+ baseColumn: never;
6705
+ identity: undefined;
6706
+ generated: undefined;
6707
+ }, {}, {
6708
+ length: number | undefined;
6709
+ }>;
6710
+ rootHash: import("drizzle-orm/sqlite-core").SQLiteColumn<{
6711
+ name: "root_hash";
6712
+ tableName: "principal_history_root_owners";
6713
+ dataType: "string";
6714
+ columnType: "SQLiteText";
6715
+ data: string;
6716
+ driverParam: string;
6717
+ notNull: true;
6718
+ hasDefault: false;
6719
+ isPrimaryKey: false;
6720
+ isAutoincrement: false;
6721
+ hasRuntimeDefault: false;
6722
+ enumValues: [string, ...string[]];
6723
+ baseColumn: never;
6724
+ identity: undefined;
6725
+ generated: undefined;
6726
+ }, {}, {
6727
+ length: number | undefined;
6728
+ }>;
6729
+ };
6730
+ dialect: "sqlite";
6731
+ }>;
6732
+ principalHistoryStageScopes: import("drizzle-orm/sqlite-core").SQLiteTableWithColumns<{
6733
+ name: "principal_history_stage_scopes";
6734
+ schema: undefined;
6735
+ columns: {
6736
+ id: import("drizzle-orm/sqlite-core").SQLiteColumn<{
6737
+ name: "id";
6738
+ tableName: "principal_history_stage_scopes";
6739
+ dataType: "string";
6740
+ columnType: "SQLiteText";
6741
+ data: string;
6742
+ driverParam: string;
6743
+ notNull: true;
6744
+ hasDefault: false;
6745
+ isPrimaryKey: true;
6746
+ isAutoincrement: false;
6747
+ hasRuntimeDefault: false;
6748
+ enumValues: [string, ...string[]];
6749
+ baseColumn: never;
6750
+ identity: undefined;
6751
+ generated: undefined;
6752
+ }, {}, {
6753
+ length: number | undefined;
6754
+ }>;
6755
+ organizationId: import("drizzle-orm/sqlite-core").SQLiteColumn<{
6756
+ name: "organization_id";
6757
+ tableName: "principal_history_stage_scopes";
6758
+ dataType: "string";
6759
+ columnType: "SQLiteText";
6760
+ data: string;
6761
+ driverParam: string;
6762
+ notNull: true;
6763
+ hasDefault: false;
6764
+ isPrimaryKey: false;
6765
+ isAutoincrement: false;
6766
+ hasRuntimeDefault: false;
6767
+ enumValues: [string, ...string[]];
6768
+ baseColumn: never;
6769
+ identity: undefined;
6770
+ generated: undefined;
6771
+ }, {}, {
6772
+ length: number | undefined;
6773
+ }>;
6774
+ scopeId: import("drizzle-orm/sqlite-core").SQLiteColumn<{
6775
+ name: "scope_id";
6776
+ tableName: "principal_history_stage_scopes";
6777
+ dataType: "string";
6778
+ columnType: "SQLiteText";
6779
+ data: string;
6780
+ driverParam: string;
6781
+ notNull: true;
6782
+ hasDefault: false;
6783
+ isPrimaryKey: false;
6784
+ isAutoincrement: false;
6785
+ hasRuntimeDefault: false;
6786
+ enumValues: [string, ...string[]];
6787
+ baseColumn: never;
6788
+ identity: undefined;
6789
+ generated: undefined;
6790
+ }, {}, {
6791
+ length: number | undefined;
6792
+ }>;
6793
+ afterVersion: import("drizzle-orm/sqlite-core").SQLiteColumn<{
6794
+ name: "after_version";
6795
+ tableName: "principal_history_stage_scopes";
6796
+ dataType: "number";
6797
+ columnType: "SQLiteInteger";
6798
+ data: number;
6799
+ driverParam: number;
6800
+ notNull: true;
6801
+ hasDefault: false;
6802
+ isPrimaryKey: false;
6803
+ isAutoincrement: false;
6804
+ hasRuntimeDefault: false;
6805
+ enumValues: undefined;
6806
+ baseColumn: never;
6807
+ identity: undefined;
6808
+ generated: undefined;
6809
+ }, {}, {}>;
6810
+ complete: import("drizzle-orm/sqlite-core").SQLiteColumn<{
6811
+ name: "complete";
6812
+ tableName: "principal_history_stage_scopes";
6813
+ dataType: "boolean";
6814
+ columnType: "SQLiteBoolean";
6815
+ data: boolean;
6816
+ driverParam: number;
6817
+ notNull: true;
6818
+ hasDefault: false;
6819
+ isPrimaryKey: false;
6820
+ isAutoincrement: false;
6821
+ hasRuntimeDefault: false;
6822
+ enumValues: undefined;
6823
+ baseColumn: never;
6824
+ identity: undefined;
6825
+ generated: undefined;
6826
+ }, {}, {}>;
6827
+ touchedAt: import("drizzle-orm/sqlite-core").SQLiteColumn<{
6828
+ name: "touched_at";
6829
+ tableName: "principal_history_stage_scopes";
6830
+ dataType: "number";
6831
+ columnType: "SQLiteInteger";
6832
+ data: number;
6833
+ driverParam: number;
6834
+ notNull: true;
6835
+ hasDefault: false;
6836
+ isPrimaryKey: false;
6837
+ isAutoincrement: false;
6838
+ hasRuntimeDefault: false;
6839
+ enumValues: undefined;
6840
+ baseColumn: never;
6841
+ identity: undefined;
6842
+ generated: undefined;
6843
+ }, {}, {}>;
6844
+ };
6845
+ dialect: "sqlite";
6846
+ }>;
6847
+ principalKeyEnvelopeArchive: import("drizzle-orm/sqlite-core").SQLiteTableWithColumns<{
6848
+ name: "principal_key_envelope_archive";
6849
+ schema: undefined;
6850
+ columns: {
6851
+ organizationId: import("drizzle-orm/sqlite-core").SQLiteColumn<{
6852
+ name: "organization_id";
6853
+ tableName: "principal_key_envelope_archive";
6854
+ dataType: "string";
6855
+ columnType: "SQLiteText";
6856
+ data: string;
6857
+ driverParam: string;
6858
+ notNull: true;
6859
+ hasDefault: false;
6860
+ isPrimaryKey: false;
6861
+ isAutoincrement: false;
6862
+ hasRuntimeDefault: false;
6863
+ enumValues: [string, ...string[]];
6864
+ baseColumn: never;
6865
+ identity: undefined;
6866
+ generated: undefined;
6867
+ }, {}, {
6868
+ length: number | undefined;
6869
+ }>;
6870
+ principalType: import("drizzle-orm/sqlite-core").SQLiteColumn<{
6871
+ name: "principal_type";
6872
+ tableName: "principal_key_envelope_archive";
6873
+ dataType: "string";
6874
+ columnType: "SQLiteText";
6875
+ data: string;
6876
+ driverParam: string;
6877
+ notNull: true;
6878
+ hasDefault: false;
6879
+ isPrimaryKey: false;
6880
+ isAutoincrement: false;
6881
+ hasRuntimeDefault: false;
6882
+ enumValues: [string, ...string[]];
6883
+ baseColumn: never;
6884
+ identity: undefined;
6885
+ generated: undefined;
6886
+ }, {}, {
6887
+ length: number | undefined;
6888
+ }>;
6889
+ principalId: import("drizzle-orm/sqlite-core").SQLiteColumn<{
6890
+ name: "principal_id";
6891
+ tableName: "principal_key_envelope_archive";
6892
+ dataType: "string";
6893
+ columnType: "SQLiteText";
6894
+ data: string;
6895
+ driverParam: string;
6896
+ notNull: true;
6897
+ hasDefault: false;
6898
+ isPrimaryKey: false;
6899
+ isAutoincrement: false;
6900
+ hasRuntimeDefault: false;
6901
+ enumValues: [string, ...string[]];
6902
+ baseColumn: never;
6903
+ identity: undefined;
6904
+ generated: undefined;
6905
+ }, {}, {
6906
+ length: number | undefined;
6907
+ }>;
6908
+ keyFingerprint: import("drizzle-orm/sqlite-core").SQLiteColumn<{
6909
+ name: "key_fingerprint";
6910
+ tableName: "principal_key_envelope_archive";
6911
+ dataType: "string";
6912
+ columnType: "SQLiteText";
6913
+ data: string;
6914
+ driverParam: string;
6915
+ notNull: true;
6916
+ hasDefault: false;
6917
+ isPrimaryKey: false;
6918
+ isAutoincrement: false;
6919
+ hasRuntimeDefault: false;
6920
+ enumValues: [string, ...string[]];
6921
+ baseColumn: never;
6922
+ identity: undefined;
6923
+ generated: undefined;
6924
+ }, {}, {
6925
+ length: number | undefined;
6926
+ }>;
6927
+ version: import("drizzle-orm/sqlite-core").SQLiteColumn<{
6928
+ name: "version";
6929
+ tableName: "principal_key_envelope_archive";
6930
+ dataType: "number";
6931
+ columnType: "SQLiteInteger";
6932
+ data: number;
6933
+ driverParam: number;
6934
+ notNull: true;
6935
+ hasDefault: false;
6936
+ isPrimaryKey: false;
6937
+ isAutoincrement: false;
6938
+ hasRuntimeDefault: false;
6939
+ enumValues: undefined;
6940
+ baseColumn: never;
6941
+ identity: undefined;
6942
+ generated: undefined;
6943
+ }, {}, {}>;
6944
+ envelopesJson: import("drizzle-orm/sqlite-core").SQLiteColumn<{
6945
+ name: "envelopes_json";
6946
+ tableName: "principal_key_envelope_archive";
6947
+ dataType: "string";
6948
+ columnType: "SQLiteText";
6949
+ data: string;
6950
+ driverParam: string;
6951
+ notNull: true;
6952
+ hasDefault: false;
6953
+ isPrimaryKey: false;
6954
+ isAutoincrement: false;
6955
+ hasRuntimeDefault: false;
6956
+ enumValues: [string, ...string[]];
6957
+ baseColumn: never;
6958
+ identity: undefined;
6959
+ generated: undefined;
6960
+ }, {}, {
6961
+ length: number | undefined;
6962
+ }>;
6963
+ };
6964
+ dialect: "sqlite";
6965
+ }>;
6513
6966
  principalMutationJournal: import("drizzle-orm/sqlite-core").SQLiteTableWithColumns<{
6514
6967
  name: "principal_mutation_journal";
6515
6968
  schema: undefined;