@tearleads/client-sdk 0.1.238 → 0.1.240

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 (31) hide show
  1. package/data/documents/shared/types.d.ts +5 -1
  2. package/data/documents/shared/types.js.map +1 -1
  3. package/data/persistence/documents/documentAttachmentPresence.js +44 -0
  4. package/data/persistence/documents/documentAttachmentPresence.js.map +1 -0
  5. package/data/persistence/documents/records/documentSyncFailurePersistence.d.ts +0 -2
  6. package/data/persistence/documents/records/documentSyncFailurePersistence.js +0 -2
  7. package/data/persistence/documents/records/documentSyncFailurePersistence.js.map +1 -1
  8. package/data/sqlite/migrations/localSchemaMigrations.js +14 -0
  9. package/data/sqlite/migrations/localSchemaMigrations.js.map +1 -1
  10. package/data/sqlite/schema/documentRecordSchema.js +4 -6
  11. package/data/sqlite/schema/documentRecordSchema.js.map +1 -1
  12. package/data/sqlite/schema/index.d.ts +0 -17
  13. package/internal/validators/operation/containerMutations.d.ts +16 -16
  14. package/internal/validators/operation/documentMutations.d.ts +20 -20
  15. package/internal/validators/response/containerMutationError.d.ts +2 -2
  16. package/internal/validators/response/documentMutationError.d.ts +3 -2
  17. package/internal/validators/response/documentMutationError.js +5 -0
  18. package/internal/validators/response/documentMutationError.js.map +1 -1
  19. package/package.json +1 -1
  20. package/stores/documents/documentStore/sync/attachmentUploadFailure.js +0 -1
  21. package/stores/documents/documentStore/sync/attachmentUploadFailure.js.map +1 -1
  22. package/stores/documents/documentStore/sync/syncShared.js +0 -1
  23. package/stores/documents/documentStore/sync/syncShared.js.map +1 -1
  24. package/workflows/documents/linkSet/linkSetBlobRewraps.d.ts +10 -4
  25. package/workflows/documents/linkSet/linkSetBlobRewraps.js +23 -11
  26. package/workflows/documents/linkSet/linkSetBlobRewraps.js.map +1 -1
  27. package/workflows/documents/linkSet/linkSetLegMachine.js +74 -0
  28. package/workflows/documents/linkSet/linkSetLegMachine.js.map +1 -0
  29. package/workflows/documents/linkSet/linkSetRemote.d.ts +4 -4
  30. package/workflows/documents/linkSet/linkSetRemote.js +96 -52
  31. package/workflows/documents/linkSet/linkSetRemote.js.map +1 -1
@@ -126,10 +126,14 @@ type DocumentLinkSetMutationResult = {
126
126
  readonly ok: true;
127
127
  } | (DocumentLinkSetMutationFailure & {
128
128
  readonly ok: false;
129
+ /** The host report a `reportErrors: false` request withheld. */
130
+ readonly report?: (() => void) | undefined;
129
131
  });
130
132
  export interface DocumentLinkSetMutationApi {
131
133
  getBlobBytes(blobId: string): Promise<BlobBytesResponse | null>;
132
- listDocumentAttachments(documentId: string): Promise<ListDocumentAttachmentsResponse | null>;
134
+ listDocumentAttachments(documentId: string, options?: {
135
+ readonly refresh?: boolean;
136
+ }): Promise<ListDocumentAttachmentsResponse | null>;
133
137
  getContainerWriterProjection(containerId: string): Promise<ContainerWriterProjectionResponse | null>;
134
138
  getContainerWriterProjectionResult(containerId: string, options?: DocumentSyncRequestResultOptions | undefined): Promise<{
135
139
  readonly data: ContainerWriterProjectionResponse;
@@ -1 +1 @@
1
- {"version":3,"file":"types.js","sourceRoot":"","sources":["types.ts"],"names":[],"mappings":"AA2BA,MAAM,CAAC,MAAM,qCAAqC,GAChD,gCAAgC,CAAC;AACnC,MAAM,CAAC,MAAM,uCAAuC,GAClD,4CAA4C,CAAC;AAC/C,MAAM,CAAC,MAAM,sDAAsD,GACjE,2DAA2D,CAAC;AAC9D,MAAM,CAAC,MAAM,kCAAkC,GAC7C,uCAAuC,CAAC;AAC1C,MAAM,CAAC,MAAM,iCAAiC,GAC5C,IAAI,WAAW,EAAE,CAAC,MAAM,CAAC,6CAA6C,CAAC,CAAC;AAC1E,MAAM,CAAC,MAAM,8BAA8B,GAAG,IAAI,GAAG,CAAC;IACpD,YAAY;IACZ,iBAAiB;IACjB,iBAAiB;IACjB,iBAAiB;IACjB,QAAQ;IACR,IAAI;IACJ,cAAc;IACd,iBAAiB;IACjB,SAAS;CACV,CAAC,CAAC;AACH,MAAM,CAAC,MAAM,YAAY,GAAG,IAAI,WAAW,EAAE,CAAC","sourcesContent":["import type { BlobBytesResponse } from \"@tearleads/api-client\";\nimport type {\n AccessEvent,\n AccessManifest,\n DocumentContentKeyTarget,\n DocumentLinkAccessEventBody,\n DocumentLinkSetManifestState,\n DocumentUnlinkAccessEventBody,\n} from \"@tearleads/crypto\";\nimport type {\n ContainerManifestRef,\n DocumentContentKeyTargetEnvelope,\n DocumentCreateRequest,\n DocumentLinkSetMutationRequest,\n DocumentSyncRequest,\n} from \"@tearleads/validators/request\";\nimport type {\n ContainerWriterProjectionResponse,\n DocumentCreateResponse,\n DocumentLinkSetMutationResponse,\n DocumentWriterProjectionResponse,\n ListDocumentAttachmentsResponse,\n} from \"@tearleads/validators/response\";\nimport type { ContainerMutationAuthor } from \"../../containers/shared/types\";\nimport type { DocumentRecord } from \"../../persistence/documents/records\";\nimport type { DocumentSyncSubmitFailure } from \"./sync/syncSubmitFailure\";\n\nexport const DOCUMENT_ENCRYPTED_LORO_UPDATE_FORMAT =\n \"tearleads.document.loro-update\";\nexport const DOCUMENT_CONTENT_RECORD_KEY_INFO_DOMAIN =\n \"tearleads.document.content-record-key-info\";\nexport const DOCUMENT_CONTENT_RECORD_PLAINTEXT_HASH_KEY_INFO_DOMAIN =\n \"tearleads.document.content-record-plaintext-hash-key-info\";\nexport const DOCUMENT_CONTENT_RECORD_AAD_DOMAIN =\n \"tearleads.document.content-record-aad\";\nexport const DOCUMENT_CONTENT_RECORD_HKDF_SALT: Uint8Array<ArrayBuffer> =\n new TextEncoder().encode(\"tearleads.document.content-record-hkdf-salt\");\nexport const DOCUMENT_ENCRYPTED_UPDATE_KEYS = new Set([\n \"ciphertext\",\n \"contentKeyEpoch\",\n \"contentRecordId\",\n \"encryptionSuite\",\n \"format\",\n \"iv\",\n \"metadataHash\",\n \"nonceDomainHash\",\n \"version\",\n]);\nexport const TEXT_ENCODER = new TextEncoder();\n\nexport type DocumentCreateAuthor = ContainerMutationAuthor;\n\nexport interface BuildDocumentCreatePlanInput {\n author: DocumentCreateAuthor;\n containerProjection: ContainerWriterProjectionResponse;\n contentKeyEpoch?: number;\n documentId?: string;\n eventId?: string;\n signedAt?: string;\n targetEnvelopes: readonly DocumentContentKeyTargetEnvelope[];\n}\n\nexport interface DocumentCreatePlan {\n body: DocumentLinkAccessEventBody;\n documentId: string;\n event: AccessEvent;\n eventHash: string;\n manifest: AccessManifest;\n manifestHash: string;\n request: DocumentCreateRequest;\n state: DocumentLinkSetManifestState;\n targetHash: string;\n targets: DocumentContentKeyTarget[];\n}\n\nexport interface MaterializedDocumentCreatePlan {\n contentKey: Uint8Array;\n plan: DocumentCreatePlan;\n}\n\nexport interface DocumentCreateApi {\n // Lets idempotent create inspect an expected already-exists conflict.\n createDocumentResult(\n input: DocumentCreateRequest,\n options?: DocumentSyncRequestResultOptions | undefined,\n ): Promise<\n | {\n readonly data: DocumentCreateResponse;\n readonly ok: true;\n }\n | DocumentSyncSubmitFailure\n >;\n getContainerWriterProjection(\n containerId: string,\n ): Promise<ContainerWriterProjectionResponse | null>;\n // Result-returning variant used by the create path so a terminal projection\n // fetch failure (e.g. a 402 billing block or a 403 after access revocation)\n // can be persisted to the write queue instead of collapsing to a silent\n // null.\n getContainerWriterProjectionResult(\n containerId: string,\n options?: DocumentSyncRequestResultOptions | undefined,\n ): Promise<\n | {\n readonly data: ContainerWriterProjectionResponse;\n readonly ok: true;\n }\n | DocumentSyncSubmitFailure\n >;\n // Needed to adopt an existing remote document on a create conflict: the\n // committed manifest, content-key bundle and KEK targets are refetched here\n // (the create response that carried them was lost).\n getDocumentWriterProjection(\n documentId: string,\n ): Promise<DocumentWriterProjectionResponse | null>;\n evictContainerWriterProjection(containerId: string): void;\n primeDocumentWriterProjection(\n documentId: string,\n projection: DocumentWriterProjectionResponse,\n ): void;\n}\n\nexport interface CreateRemoteDocumentResult {\n contentKey: Uint8Array;\n /** The requested `deferredSeedUpdate`, signed but unsent, for a bind. */\n deferredSeed?: DocumentSyncRequest | undefined;\n documentId: string;\n persistedState: PersistedDocumentCreateState;\n // `plan` and `response` are absent when the result was adopted from an\n // existing remote document on a create conflict: there is no fresh create\n // response, and the local plan does not match the committed manifest (the\n // first attempt used a different content key). Consumers read only\n // documentId/writerProjection/persistedState.\n plan?: DocumentCreatePlan | undefined;\n response?: DocumentCreateResponse | undefined;\n writerProjection: DocumentWriterProjectionResponse;\n}\n\nexport type DocumentLinkSetMutationOperation = \"link\" | \"unlink\";\nexport type DocumentLinkSetMutationBody =\n | DocumentLinkAccessEventBody\n | DocumentUnlinkAccessEventBody;\n\nexport interface DocumentLinkSetTargetState {\n readonly currentTargets: readonly DocumentContentKeyTarget[];\n readonly linkedContainerIds: readonly string[];\n readonly target: DocumentContentKeyTarget;\n readonly targets: readonly DocumentContentKeyTarget[];\n}\n\nexport interface BuildDocumentLinkSetMutationPlanInput {\n blobRewraps: DocumentLinkAccessEventBody[\"blobRewraps\"];\n author: DocumentCreateAuthor;\n contentKeyEpoch: number;\n eventId?: string | undefined;\n operation: DocumentLinkSetMutationOperation;\n signedAt?: string | undefined;\n targetContainerProjection: ContainerWriterProjectionResponse;\n targetEnvelopes: readonly DocumentContentKeyTargetEnvelope[];\n writerProjection: DocumentWriterProjectionResponse;\n}\n\nexport interface DocumentLinkSetMutationPlan {\n body: DocumentLinkSetMutationBody;\n contentKeyEpoch: number;\n documentId: string;\n event: AccessEvent;\n eventHash: string;\n manifest: AccessManifest;\n manifestHash: string;\n operation: DocumentLinkSetMutationOperation;\n request: DocumentLinkSetMutationRequest;\n state: DocumentLinkSetManifestState;\n targetHash: string;\n targets: DocumentContentKeyTarget[];\n}\n\nexport interface MaterializedDocumentLinkSetMutationPlan {\n contentKey: Uint8Array;\n contentKeyRotated: boolean;\n plan: DocumentLinkSetMutationPlan;\n}\n\nexport interface DocumentLinkSetEventPlan {\n authorizingContainerPathRefs: ContainerManifestRef[][];\n body: DocumentLinkSetMutationBody;\n event: AccessEvent;\n eventHash: string;\n}\n\n/**\n * What a failed link-set mutation could tell the caller: the HTTP status (or\n * null for network/local failures) and a short message. Threaded up to the\n * move-intent queue so a permission failure reads as one, instead of the\n * generic \"rejected or unavailable\".\n */\nexport type DocumentLinkSetMutationFailure = Pick<\n DocumentSyncSubmitFailure,\n \"code\" | \"message\" | \"status\"\n>;\n\nexport type DocumentLinkSetFailureHandler = (\n failure: DocumentLinkSetMutationFailure,\n) => void;\n\n/**\n * `prove` pulls and verifies the document's full history. `reuse` returns the\n * store's last completed proof while the same local document still sits at\n * that proof's version vector, and proves otherwise; only a caller the server\n * re-checks (an unlink's rotation baseline) may reuse.\n */\nexport type DocumentRotationProofMode = \"prove\" | \"reuse\";\n\ntype DocumentLinkSetMutationResult =\n | { readonly data: DocumentLinkSetMutationResponse; readonly ok: true }\n | (DocumentLinkSetMutationFailure & { readonly ok: false });\n\nexport interface DocumentLinkSetMutationApi {\n getBlobBytes(blobId: string): Promise<BlobBytesResponse | null>;\n listDocumentAttachments(\n documentId: string,\n ): Promise<ListDocumentAttachmentsResponse | null>;\n getContainerWriterProjection(\n containerId: string,\n ): Promise<ContainerWriterProjectionResponse | null>;\n getContainerWriterProjectionResult(\n containerId: string,\n options?: DocumentSyncRequestResultOptions | undefined,\n ): Promise<\n | {\n readonly data: ContainerWriterProjectionResponse;\n readonly ok: true;\n }\n | DocumentSyncSubmitFailure\n >;\n getDocumentWriterProjection(\n documentId: string,\n ): Promise<DocumentWriterProjectionResponse | null>;\n getDocumentWriterProjectionResult(\n documentId: string,\n options?: DocumentSyncRequestResultOptions | undefined,\n ): Promise<\n | {\n readonly data: DocumentWriterProjectionResponse;\n readonly ok: true;\n }\n | DocumentSyncSubmitFailure\n >;\n primeDocumentWriterProjection(\n documentId: string,\n projection: DocumentWriterProjectionResponse,\n ): void;\n linkDocumentResult(\n documentId: string,\n input: DocumentLinkSetMutationRequest,\n options?: DocumentSyncRequestResultOptions,\n ): Promise<DocumentLinkSetMutationResult>;\n unlinkDocumentResult(\n documentId: string,\n input: DocumentLinkSetMutationRequest,\n options?: DocumentSyncRequestResultOptions,\n ): Promise<DocumentLinkSetMutationResult>;\n}\n\nexport interface RelinkRemoteDocumentResult {\n contentKey: Uint8Array;\n contentKeyRotated: boolean;\n documentId: string;\n linkedContainerIds: readonly string[];\n persistedState: PersistedDocumentCreateState;\n plan: DocumentLinkSetMutationPlan;\n response: DocumentLinkSetMutationResponse;\n}\n\nexport interface DocumentSyncRequestResultOptions {\n readonly expectedPaymentRequiredOrganizationId?: string | undefined;\n readonly reportErrors?: boolean | undefined;\n}\n\nexport type DocumentWriterPublicKeyResolver = (input: {\n writerSigningKeyFingerprint: string;\n writerUserId: string;\n}) => Promise<Uint8Array | null>;\n\nexport type PersistedDocumentCreateState = Pick<\n DocumentRecord,\n | \"documentId\"\n | \"contentKeyBundle\"\n | \"documentKekTargets\"\n | \"documentManifestBundle\"\n>;\n\nexport type PersistedDocumentSyncState = PersistedDocumentCreateState;\n\nexport interface UnwrappedContainerKek {\n containerId: string;\n /**\n * Null for keyring-recovered historical keys, which carry key material and\n * the epoch id committing to it but no epoch record to hash.\n *\n * Such a key still satisfies a parent wrap: the epoch-record fingerprint is\n * a selector for choosing among envelopes, not the security boundary, so a\n * null hash falls back to selecting on the epoch id while AEAD authenticates\n * (see `containerKekPath.ts`). That is what lets a descendant pinned to a\n * rotated parent be opened rather than stranded.\n */\n keyEpochHash: string | null;\n keyMaterial: Uint8Array;\n}\n"]}
1
+ {"version":3,"file":"types.js","sourceRoot":"","sources":["types.ts"],"names":[],"mappings":"AA2BA,MAAM,CAAC,MAAM,qCAAqC,GAChD,gCAAgC,CAAC;AACnC,MAAM,CAAC,MAAM,uCAAuC,GAClD,4CAA4C,CAAC;AAC/C,MAAM,CAAC,MAAM,sDAAsD,GACjE,2DAA2D,CAAC;AAC9D,MAAM,CAAC,MAAM,kCAAkC,GAC7C,uCAAuC,CAAC;AAC1C,MAAM,CAAC,MAAM,iCAAiC,GAC5C,IAAI,WAAW,EAAE,CAAC,MAAM,CAAC,6CAA6C,CAAC,CAAC;AAC1E,MAAM,CAAC,MAAM,8BAA8B,GAAG,IAAI,GAAG,CAAC;IACpD,YAAY;IACZ,iBAAiB;IACjB,iBAAiB;IACjB,iBAAiB;IACjB,QAAQ;IACR,IAAI;IACJ,cAAc;IACd,iBAAiB;IACjB,SAAS;CACV,CAAC,CAAC;AACH,MAAM,CAAC,MAAM,YAAY,GAAG,IAAI,WAAW,EAAE,CAAC","sourcesContent":["import type { BlobBytesResponse } from \"@tearleads/api-client\";\nimport type {\n AccessEvent,\n AccessManifest,\n DocumentContentKeyTarget,\n DocumentLinkAccessEventBody,\n DocumentLinkSetManifestState,\n DocumentUnlinkAccessEventBody,\n} from \"@tearleads/crypto\";\nimport type {\n ContainerManifestRef,\n DocumentContentKeyTargetEnvelope,\n DocumentCreateRequest,\n DocumentLinkSetMutationRequest,\n DocumentSyncRequest,\n} from \"@tearleads/validators/request\";\nimport type {\n ContainerWriterProjectionResponse,\n DocumentCreateResponse,\n DocumentLinkSetMutationResponse,\n DocumentWriterProjectionResponse,\n ListDocumentAttachmentsResponse,\n} from \"@tearleads/validators/response\";\nimport type { ContainerMutationAuthor } from \"../../containers/shared/types\";\nimport type { DocumentRecord } from \"../../persistence/documents/records\";\nimport type { DocumentSyncSubmitFailure } from \"./sync/syncSubmitFailure\";\n\nexport const DOCUMENT_ENCRYPTED_LORO_UPDATE_FORMAT =\n \"tearleads.document.loro-update\";\nexport const DOCUMENT_CONTENT_RECORD_KEY_INFO_DOMAIN =\n \"tearleads.document.content-record-key-info\";\nexport const DOCUMENT_CONTENT_RECORD_PLAINTEXT_HASH_KEY_INFO_DOMAIN =\n \"tearleads.document.content-record-plaintext-hash-key-info\";\nexport const DOCUMENT_CONTENT_RECORD_AAD_DOMAIN =\n \"tearleads.document.content-record-aad\";\nexport const DOCUMENT_CONTENT_RECORD_HKDF_SALT: Uint8Array<ArrayBuffer> =\n new TextEncoder().encode(\"tearleads.document.content-record-hkdf-salt\");\nexport const DOCUMENT_ENCRYPTED_UPDATE_KEYS = new Set([\n \"ciphertext\",\n \"contentKeyEpoch\",\n \"contentRecordId\",\n \"encryptionSuite\",\n \"format\",\n \"iv\",\n \"metadataHash\",\n \"nonceDomainHash\",\n \"version\",\n]);\nexport const TEXT_ENCODER = new TextEncoder();\n\nexport type DocumentCreateAuthor = ContainerMutationAuthor;\n\nexport interface BuildDocumentCreatePlanInput {\n author: DocumentCreateAuthor;\n containerProjection: ContainerWriterProjectionResponse;\n contentKeyEpoch?: number;\n documentId?: string;\n eventId?: string;\n signedAt?: string;\n targetEnvelopes: readonly DocumentContentKeyTargetEnvelope[];\n}\n\nexport interface DocumentCreatePlan {\n body: DocumentLinkAccessEventBody;\n documentId: string;\n event: AccessEvent;\n eventHash: string;\n manifest: AccessManifest;\n manifestHash: string;\n request: DocumentCreateRequest;\n state: DocumentLinkSetManifestState;\n targetHash: string;\n targets: DocumentContentKeyTarget[];\n}\n\nexport interface MaterializedDocumentCreatePlan {\n contentKey: Uint8Array;\n plan: DocumentCreatePlan;\n}\n\nexport interface DocumentCreateApi {\n // Lets idempotent create inspect an expected already-exists conflict.\n createDocumentResult(\n input: DocumentCreateRequest,\n options?: DocumentSyncRequestResultOptions | undefined,\n ): Promise<\n | {\n readonly data: DocumentCreateResponse;\n readonly ok: true;\n }\n | DocumentSyncSubmitFailure\n >;\n getContainerWriterProjection(\n containerId: string,\n ): Promise<ContainerWriterProjectionResponse | null>;\n // Result-returning variant used by the create path so a terminal projection\n // fetch failure (e.g. a 402 billing block or a 403 after access revocation)\n // can be persisted to the write queue instead of collapsing to a silent\n // null.\n getContainerWriterProjectionResult(\n containerId: string,\n options?: DocumentSyncRequestResultOptions | undefined,\n ): Promise<\n | {\n readonly data: ContainerWriterProjectionResponse;\n readonly ok: true;\n }\n | DocumentSyncSubmitFailure\n >;\n // Needed to adopt an existing remote document on a create conflict: the\n // committed manifest, content-key bundle and KEK targets are refetched here\n // (the create response that carried them was lost).\n getDocumentWriterProjection(\n documentId: string,\n ): Promise<DocumentWriterProjectionResponse | null>;\n evictContainerWriterProjection(containerId: string): void;\n primeDocumentWriterProjection(\n documentId: string,\n projection: DocumentWriterProjectionResponse,\n ): void;\n}\n\nexport interface CreateRemoteDocumentResult {\n contentKey: Uint8Array;\n /** The requested `deferredSeedUpdate`, signed but unsent, for a bind. */\n deferredSeed?: DocumentSyncRequest | undefined;\n documentId: string;\n persistedState: PersistedDocumentCreateState;\n // `plan` and `response` are absent when the result was adopted from an\n // existing remote document on a create conflict: there is no fresh create\n // response, and the local plan does not match the committed manifest (the\n // first attempt used a different content key). Consumers read only\n // documentId/writerProjection/persistedState.\n plan?: DocumentCreatePlan | undefined;\n response?: DocumentCreateResponse | undefined;\n writerProjection: DocumentWriterProjectionResponse;\n}\n\nexport type DocumentLinkSetMutationOperation = \"link\" | \"unlink\";\nexport type DocumentLinkSetMutationBody =\n | DocumentLinkAccessEventBody\n | DocumentUnlinkAccessEventBody;\n\nexport interface DocumentLinkSetTargetState {\n readonly currentTargets: readonly DocumentContentKeyTarget[];\n readonly linkedContainerIds: readonly string[];\n readonly target: DocumentContentKeyTarget;\n readonly targets: readonly DocumentContentKeyTarget[];\n}\n\nexport interface BuildDocumentLinkSetMutationPlanInput {\n blobRewraps: DocumentLinkAccessEventBody[\"blobRewraps\"];\n author: DocumentCreateAuthor;\n contentKeyEpoch: number;\n eventId?: string | undefined;\n operation: DocumentLinkSetMutationOperation;\n signedAt?: string | undefined;\n targetContainerProjection: ContainerWriterProjectionResponse;\n targetEnvelopes: readonly DocumentContentKeyTargetEnvelope[];\n writerProjection: DocumentWriterProjectionResponse;\n}\n\nexport interface DocumentLinkSetMutationPlan {\n body: DocumentLinkSetMutationBody;\n contentKeyEpoch: number;\n documentId: string;\n event: AccessEvent;\n eventHash: string;\n manifest: AccessManifest;\n manifestHash: string;\n operation: DocumentLinkSetMutationOperation;\n request: DocumentLinkSetMutationRequest;\n state: DocumentLinkSetManifestState;\n targetHash: string;\n targets: DocumentContentKeyTarget[];\n}\n\nexport interface MaterializedDocumentLinkSetMutationPlan {\n contentKey: Uint8Array;\n contentKeyRotated: boolean;\n plan: DocumentLinkSetMutationPlan;\n}\n\nexport interface DocumentLinkSetEventPlan {\n authorizingContainerPathRefs: ContainerManifestRef[][];\n body: DocumentLinkSetMutationBody;\n event: AccessEvent;\n eventHash: string;\n}\n\n/**\n * What a failed link-set mutation could tell the caller: the HTTP status (or\n * null for network/local failures) and a short message. Threaded up to the\n * move-intent queue so a permission failure reads as one, instead of the\n * generic \"rejected or unavailable\".\n */\nexport type DocumentLinkSetMutationFailure = Pick<\n DocumentSyncSubmitFailure,\n \"code\" | \"message\" | \"status\"\n>;\n\nexport type DocumentLinkSetFailureHandler = (\n failure: DocumentLinkSetMutationFailure,\n) => void;\n\n/**\n * `prove` pulls and verifies the document's full history. `reuse` returns the\n * store's last completed proof while the same local document still sits at\n * that proof's version vector, and proves otherwise; only a caller the server\n * re-checks (an unlink's rotation baseline) may reuse.\n */\nexport type DocumentRotationProofMode = \"prove\" | \"reuse\";\n\ntype DocumentLinkSetMutationResult =\n | { readonly data: DocumentLinkSetMutationResponse; readonly ok: true }\n | (DocumentLinkSetMutationFailure & {\n readonly ok: false;\n /** The host report a `reportErrors: false` request withheld. */\n readonly report?: (() => void) | undefined;\n });\n\nexport interface DocumentLinkSetMutationApi {\n getBlobBytes(blobId: string): Promise<BlobBytesResponse | null>;\n listDocumentAttachments(\n documentId: string,\n options?: { readonly refresh?: boolean },\n ): Promise<ListDocumentAttachmentsResponse | null>;\n getContainerWriterProjection(\n containerId: string,\n ): Promise<ContainerWriterProjectionResponse | null>;\n getContainerWriterProjectionResult(\n containerId: string,\n options?: DocumentSyncRequestResultOptions | undefined,\n ): Promise<\n | {\n readonly data: ContainerWriterProjectionResponse;\n readonly ok: true;\n }\n | DocumentSyncSubmitFailure\n >;\n getDocumentWriterProjection(\n documentId: string,\n ): Promise<DocumentWriterProjectionResponse | null>;\n getDocumentWriterProjectionResult(\n documentId: string,\n options?: DocumentSyncRequestResultOptions | undefined,\n ): Promise<\n | {\n readonly data: DocumentWriterProjectionResponse;\n readonly ok: true;\n }\n | DocumentSyncSubmitFailure\n >;\n primeDocumentWriterProjection(\n documentId: string,\n projection: DocumentWriterProjectionResponse,\n ): void;\n linkDocumentResult(\n documentId: string,\n input: DocumentLinkSetMutationRequest,\n options?: DocumentSyncRequestResultOptions,\n ): Promise<DocumentLinkSetMutationResult>;\n unlinkDocumentResult(\n documentId: string,\n input: DocumentLinkSetMutationRequest,\n options?: DocumentSyncRequestResultOptions,\n ): Promise<DocumentLinkSetMutationResult>;\n}\n\nexport interface RelinkRemoteDocumentResult {\n contentKey: Uint8Array;\n contentKeyRotated: boolean;\n documentId: string;\n linkedContainerIds: readonly string[];\n persistedState: PersistedDocumentCreateState;\n plan: DocumentLinkSetMutationPlan;\n response: DocumentLinkSetMutationResponse;\n}\n\nexport interface DocumentSyncRequestResultOptions {\n readonly expectedPaymentRequiredOrganizationId?: string | undefined;\n readonly reportErrors?: boolean | undefined;\n}\n\nexport type DocumentWriterPublicKeyResolver = (input: {\n writerSigningKeyFingerprint: string;\n writerUserId: string;\n}) => Promise<Uint8Array | null>;\n\nexport type PersistedDocumentCreateState = Pick<\n DocumentRecord,\n | \"documentId\"\n | \"contentKeyBundle\"\n | \"documentKekTargets\"\n | \"documentManifestBundle\"\n>;\n\nexport type PersistedDocumentSyncState = PersistedDocumentCreateState;\n\nexport interface UnwrappedContainerKek {\n containerId: string;\n /**\n * Null for keyring-recovered historical keys, which carry key material and\n * the epoch id committing to it but no epoch record to hash.\n *\n * Such a key still satisfies a parent wrap: the epoch-record fingerprint is\n * a selector for choosing among envelopes, not the security boundary, so a\n * null hash falls back to selecting on the epoch id while AEAD authenticates\n * (see `containerKekPath.ts`). That is what lets a descendant pinned to a\n * rotated parent be opened rather than stranded.\n */\n keyEpochHash: string | null;\n keyMaterial: Uint8Array;\n}\n"]}
@@ -0,0 +1,44 @@
1
+ import { and, eq, inArray } from "drizzle-orm";
2
+ import { DOCUMENTS_APP_KIND } from "../../documents/documentConstants.js";
3
+ import { documentAttachmentBlobProjection, documentPendingAttachments, } from "../../sqlite/schema/documentAttachmentSchema.js";
4
+ import { documents } from "../../sqlite/schema/documentRecordSchema.js";
5
+ import { getClientSQLitePersistenceRuntime } from "../../sqlite/sqlitePersistenceRuntime.js";
6
+ import { ensureDocumentsSchema } from "./internal/ensureDocumentsSchema.js";
7
+ /**
8
+ * Whether this device's local view of a server document may include an active
9
+ * attachment binding. It is false only when the device holds the document and
10
+ * no attachment row names it: no held or downloaded copy, no slot detached
11
+ * locally whose remote detach is still queued, and no pending upload. A
12
+ * document the device does not hold as a `documents` record is answered true,
13
+ * since it has no view.
14
+ *
15
+ * Callers may skip the server's attachment listing on false, because the
16
+ * server re-checks the binding frontier at commit and refuses a stale view.
17
+ */
18
+ export async function documentMayHaveAttachments(execSql, documentId) {
19
+ await ensureDocumentsSchema(execSql);
20
+ const { db } = getClientSQLitePersistenceRuntime(execSql);
21
+ const records = await db
22
+ .select({ localId: documents.localId })
23
+ .from(documents)
24
+ // `documents_app_document_idx` serves this lookup. Other app kinds (a
25
+ // container's metadata document) find no row and keep listing.
26
+ .where(and(eq(documents.appKind, DOCUMENTS_APP_KIND), eq(documents.documentId, documentId)));
27
+ if (records.length === 0)
28
+ return true;
29
+ const localIds = records.map((record) => record.localId);
30
+ const [held] = await db
31
+ .select({ localId: documentAttachmentBlobProjection.localId })
32
+ .from(documentAttachmentBlobProjection)
33
+ .where(inArray(documentAttachmentBlobProjection.localId, localIds))
34
+ .limit(1);
35
+ if (held)
36
+ return true;
37
+ const [pending] = await db
38
+ .select({ localId: documentPendingAttachments.localId })
39
+ .from(documentPendingAttachments)
40
+ .where(inArray(documentPendingAttachments.localId, localIds))
41
+ .limit(1);
42
+ return pending !== undefined;
43
+ }
44
+ //# sourceMappingURL=documentAttachmentPresence.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"documentAttachmentPresence.js","sourceRoot":"","sources":["documentAttachmentPresence.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AO,CAAC,gCAAgC,CAAC,OAAO,EAAE,QAAQ,CAAC,CAAC;SAClE,KAAK,CAAC,CAAC,CAAC,CAAC;IACZ,IAAI,IAAI;QAAE,OAAO,IAAI,CAAC;IACtB,MAAM,CAAC,OAAO,CAAC,GAAG,MAAM,EAAE;SACvB,MAAM,CAAC,EAAE,OAAO,EAAE,0BAA0B,CAAC,OAAO,EAAE,CAAC;SACvD,IAAI,CAAC,0BAA0B,CAAC;SAChC,KAAK,CAAC,OAAO,CAAC,0BAA0B,CAAC,OAAO,EAAE,QAAQ,CAAC,CAAC;SAC5D,KAAK,CAAC,CAAC,CAAC,CAAC;IACZ,OAAO,OAAO,KAAK,SAAS,CAAC;AAC/B,CAAC","sourcesContent":["import { and, eq, inArray } from \"drizzle-orm\";\nimport { DOCUMENTS_APP_KIND } from \"../../documents/documentConstants\";\nimport {\n documentAttachmentBlobProjection,\n documentPendingAttachments,\n} from \"../../sqlite/schema/documentAttachmentSchema\";\nimport { documents } from \"../../sqlite/schema/documentRecordSchema\";\nimport { getClientSQLitePersistenceRuntime } from \"../../sqlite/sqlitePersistenceRuntime\";\nimport type { ExecSql } from \"../../sqlite/sqlSchema\";\nimport { ensureDocumentsSchema } from \"./internal/ensureDocumentsSchema\";\n\n/**\n * Whether this device's local view of a server document may include an active\n * attachment binding. It is false only when the device holds the document and\n * no attachment row names it: no held or downloaded copy, no slot detached\n * locally whose remote detach is still queued, and no pending upload. A\n * document the device does not hold as a `documents` record is answered true,\n * since it has no view.\n *\n * Callers may skip the server's attachment listing on false, because the\n * server re-checks the binding frontier at commit and refuses a stale view.\n */\nexport async function documentMayHaveAttachments(\n execSql: ExecSql,\n documentId: string,\n): Promise<boolean> {\n await ensureDocumentsSchema(execSql);\n const { db } = getClientSQLitePersistenceRuntime(execSql);\n const records = await db\n .select({ localId: documents.localId })\n .from(documents)\n // `documents_app_document_idx` serves this lookup. Other app kinds (a\n // container's metadata document) find no row and keep listing.\n .where(\n and(\n eq(documents.appKind, DOCUMENTS_APP_KIND),\n eq(documents.documentId, documentId),\n ),\n );\n if (records.length === 0) return true;\n const localIds = records.map((record) => record.localId);\n const [held] = await db\n .select({ localId: documentAttachmentBlobProjection.localId })\n .from(documentAttachmentBlobProjection)\n .where(inArray(documentAttachmentBlobProjection.localId, localIds))\n .limit(1);\n if (held) return true;\n const [pending] = await db\n .select({ localId: documentPendingAttachments.localId })\n .from(documentPendingAttachments)\n .where(inArray(documentPendingAttachments.localId, localIds))\n .limit(1);\n return pending !== undefined;\n}\n"]}
@@ -3,13 +3,11 @@ import type { DocumentScope } from "./documentPersistenceTypes.js";
3
3
  export interface DocumentSyncFailureFields {
4
4
  readonly attemptedAt: string;
5
5
  readonly message: string;
6
- readonly status: number | null;
7
6
  }
8
7
  /** The `documents` column values of a scope with no recorded failure. */
9
8
  export declare const CLEARED_DOCUMENT_SYNC_FAILURE: {
10
9
  readonly syncFailureAttemptedAt: null;
11
10
  readonly syncFailureMessage: null;
12
- readonly syncFailureStatus: null;
13
11
  };
14
12
  /**
15
13
  * Record the last terminal failure or incoming-update quarantine on a document
@@ -5,7 +5,6 @@ import { documents } from "../../../sqlite/schema/documentRecordSchema.js";
5
5
  export const CLEARED_DOCUMENT_SYNC_FAILURE = {
6
6
  syncFailureAttemptedAt: null,
7
7
  syncFailureMessage: null,
8
- syncFailureStatus: null,
9
8
  };
10
9
  function scopeWhere(scope) {
11
10
  return and(eq(documents.appKind, scope.appKind), eq(documents.localId, scope.localId));
@@ -23,7 +22,6 @@ export async function recordDocumentSyncFailureInTransaction(tx, scope, failure)
23
22
  .set({
24
23
  syncFailureAttemptedAt: failure.attemptedAt,
25
24
  syncFailureMessage: failure.message,
26
- syncFailureStatus: failure.status,
27
25
  })
28
26
  .where(scopeWhere(scope))
29
27
  .run();
@@ -1 +1 @@
1
- {"version":3,"file":"documentSyncFailurePersistence.js","sourceRoot":"","sources":["documentSyncFailurePersistence.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,GAAG,EAAE,EAAE,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C;IACD,MAAM,CAAC,MAAM,CAAC,GAAG,MAAM,EAAE;SACtB,MAAM,CAAC,EAAE,EAAE,EAAE,YAAY,CAAC,EAAE,EAAE,CAAC;SAC/B,IAAI,CAAC,YAAY,CAAC;SAClB,KAAK,CAAC,SAAS,CAAC,YAAY,CAAC,SAAS,CAAC,CAAC;SACxC,KAAK,CAAC,CAAC,CAAC,CAAC;IACZ,OAAO,MAAM,KAAK,SAAS,CAAC;AAC9B,CAAC;AAED;;;;;GAKG;AACH,MAAM,CAAC,KAAK,UAAU,qCAAqC,CACzD,EAAgC,EAChC,KAAoB;IAEpB,MAAM,EAAE;SACL,MAAM,CAAC,SAAS,CAAC;SACjB,GAAG,CAAC,6BAA6B,CAAC;SAClC,KAAK,CAAC,UAAU,CAAC,KAAK,CAAC,CAAC;SACxB,GAAG,EAAE,CAAC;AACX,CAAC","sourcesContent":["import { and, eq, isNotNull } from \"drizzle-orm\";\nimport { localIntents } from \"../../../sqlite/schema\";\nimport { documents } from \"../../../sqlite/schema/documentRecordSchema\";\nimport type { ClientSQLiteTransactionScope } from \"../../../sqlite/sqlitePersistenceRuntime\";\nimport type { DocumentScope } from \"./documentPersistenceTypes\";\n\nexport interface DocumentSyncFailureFields {\n readonly attemptedAt: string;\n readonly message: string;\n readonly status: number | null;\n}\n\n/** The `documents` column values of a scope with no recorded failure. */\nexport const CLEARED_DOCUMENT_SYNC_FAILURE = {\n syncFailureAttemptedAt: null,\n syncFailureMessage: null,\n syncFailureStatus: null,\n} as const;\n\nfunction scopeWhere(scope: DocumentScope) {\n return and(\n eq(documents.appKind, scope.appKind),\n eq(documents.localId, scope.localId),\n );\n}\n\n/**\n * Record the last terminal failure or incoming-update quarantine on a document\n * scope's row. The durable pending-update queue has no status columns, so\n * these columns let the write-queue view explain a blocked document. A newer\n * failure replaces the old. A scope with no `documents` row has nothing left\n * to explain, so the update is a no-op there.\n */\nexport async function recordDocumentSyncFailureInTransaction(\n tx: ClientSQLiteTransactionScope,\n scope: DocumentScope,\n failure: DocumentSyncFailureFields,\n): Promise<void> {\n await tx\n .update(documents)\n .set({\n syncFailureAttemptedAt: failure.attemptedAt,\n syncFailureMessage: failure.message,\n syncFailureStatus: failure.status,\n })\n .where(scopeWhere(scope))\n .run();\n}\n\n/**\n * Whether any queued local write has recorded a terminal failure — a document\n * row carrying a sync failure or an intent row carrying `last_error`. This is\n * the evidence gate for recovery triggers (e.g. re-arming write lanes when org\n * access is restored): without it a transient denial during bootstrap would\n * fire recovery work with nothing to recover, racing the startup sync passes.\n */\nexport async function selectHasRecordedTerminalSyncFailures(\n db: Pick<ClientSQLiteTransactionScope, \"select\">,\n): Promise<boolean> {\n const [failure] = await db\n .select({ localId: documents.localId })\n .from(documents)\n .where(isNotNull(documents.syncFailureMessage))\n .limit(1);\n if (failure) {\n return true;\n }\n const [intent] = await db\n .select({ id: localIntents.id })\n .from(localIntents)\n .where(isNotNull(localIntents.lastError))\n .limit(1);\n return intent !== undefined;\n}\n\n/**\n * Clear a scope's recorded failure inside a caller's transaction. Called when\n * a later sync pass for the scope succeeds and whenever the scope's local sync\n * state is torn down, so a stale failure never outlives the condition it\n * describes.\n */\nexport async function clearDocumentSyncFailureInTransaction(\n tx: ClientSQLiteTransactionScope,\n scope: DocumentScope,\n): Promise<void> {\n await tx\n .update(documents)\n .set(CLEARED_DOCUMENT_SYNC_FAILURE)\n .where(scopeWhere(scope))\n .run();\n}\n"]}
1
+ {"version":3,"file":"documentSyncFailurePersistence.js","sourceRoot":"","sources":["documentSyncFailurePersistence.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,GAAG,EAAE,EAAE,EAAE,SAAS,EAAE,MAAM,aAAa,CAAC;AACjD,OAAO,EAAE,YAAY,EAAE,MAAM,wBAAwB,CAAC;AACtD,OAAO,EAAE,SAAS,EAAE,MAAM,6CAA6C,CAAC;AASxE,yEAAyE;AACzE,MAAM,CAAC,MAAM,6BAA6B,GAAG;IAC3C,sBAAsB,EAAE,IAAI;IAC5B,kBAAkB,E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;;GAKG;AACH,MAAM,CAAC,KAAK,UAAU,qCAAqC,CACzD,EAAgC,EAChC,KAAoB;IAEpB,MAAM,EAAE;SACL,MAAM,CAAC,SAAS,CAAC;SACjB,GAAG,CAAC,6BAA6B,CAAC;SAClC,KAAK,CAAC,UAAU,CAAC,KAAK,CAAC,CAAC;SACxB,GAAG,EAAE,CAAC;AACX,CAAC","sourcesContent":["import { and, eq, isNotNull } from \"drizzle-orm\";\nimport { localIntents } from \"../../../sqlite/schema\";\nimport { documents } from \"../../../sqlite/schema/documentRecordSchema\";\nimport type { ClientSQLiteTransactionScope } from \"../../../sqlite/sqlitePersistenceRuntime\";\nimport type { DocumentScope } from \"./documentPersistenceTypes\";\n\nexport interface DocumentSyncFailureFields {\n readonly attemptedAt: string;\n readonly message: string;\n}\n\n/** The `documents` column values of a scope with no recorded failure. */\nexport const CLEARED_DOCUMENT_SYNC_FAILURE = {\n syncFailureAttemptedAt: null,\n syncFailureMessage: null,\n} as const;\n\nfunction scopeWhere(scope: DocumentScope) {\n return and(\n eq(documents.appKind, scope.appKind),\n eq(documents.localId, scope.localId),\n );\n}\n\n/**\n * Record the last terminal failure or incoming-update quarantine on a document\n * scope's row. The durable pending-update queue has no status columns, so\n * these columns let the write-queue view explain a blocked document. A newer\n * failure replaces the old. A scope with no `documents` row has nothing left\n * to explain, so the update is a no-op there.\n */\nexport async function recordDocumentSyncFailureInTransaction(\n tx: ClientSQLiteTransactionScope,\n scope: DocumentScope,\n failure: DocumentSyncFailureFields,\n): Promise<void> {\n await tx\n .update(documents)\n .set({\n syncFailureAttemptedAt: failure.attemptedAt,\n syncFailureMessage: failure.message,\n })\n .where(scopeWhere(scope))\n .run();\n}\n\n/**\n * Whether any queued local write has recorded a terminal failure — a document\n * row carrying a sync failure or an intent row carrying `last_error`. This is\n * the evidence gate for recovery triggers (e.g. re-arming write lanes when org\n * access is restored): without it a transient denial during bootstrap would\n * fire recovery work with nothing to recover, racing the startup sync passes.\n */\nexport async function selectHasRecordedTerminalSyncFailures(\n db: Pick<ClientSQLiteTransactionScope, \"select\">,\n): Promise<boolean> {\n const [failure] = await db\n .select({ localId: documents.localId })\n .from(documents)\n .where(isNotNull(documents.syncFailureMessage))\n .limit(1);\n if (failure) {\n return true;\n }\n const [intent] = await db\n .select({ id: localIntents.id })\n .from(localIntents)\n .where(isNotNull(localIntents.lastError))\n .limit(1);\n return intent !== undefined;\n}\n\n/**\n * Clear a scope's recorded failure inside a caller's transaction. Called when\n * a later sync pass for the scope succeeds and whenever the scope's local sync\n * state is torn down, so a stale failure never outlives the condition it\n * describes.\n */\nexport async function clearDocumentSyncFailureInTransaction(\n tx: ClientSQLiteTransactionScope,\n scope: DocumentScope,\n): Promise<void> {\n await tx\n .update(documents)\n .set(CLEARED_DOCUMENT_SYNC_FAILURE)\n .where(scopeWhere(scope))\n .run();\n}\n"]}
@@ -27,6 +27,20 @@ export const localSchemaMigrations = [
27
27
  },
28
28
  version: 2,
29
29
  },
30
+ {
31
+ // No reader ever used a recorded failure's HTTP status; the message and
32
+ // attempt time explain a blocked document. The column is unindexed. A
33
+ // documents table without it (never created, or not this SDK's table in a
34
+ // restored backup) has nothing to drop.
35
+ name: "drop_document_sync_failure_status",
36
+ up: async (execSql) => {
37
+ const column = await execSql("SELECT name FROM pragma_table_info('documents') WHERE name = 'sync_failure_status'");
38
+ if (column.length === 0)
39
+ return;
40
+ await execSql('ALTER TABLE "documents" DROP COLUMN "sync_failure_status"');
41
+ },
42
+ version: 3,
43
+ },
30
44
  ];
31
45
  const STEP_NAME_PATTERN = /^[a-z0-9_]+$/;
32
46
  /** Rejects a registry whose versions are not consecutive from 2. */
@@ -1 +1 @@
1
- {"version":3,"file":"localSchemaMigrations.js","sourceRoot":"","sources":["localSchemaMigrations.ts"],"names":[],"mappings":"AA0BA;;;;;GAKG;AACH,MAAM,CAAC,MAAM,qBAAqB,GAAoB;IACpD,IAAI,EAAE,UAAU;IAChB,OAAO,EAAE,CAAC;CACX,CAAC;AAEF,MAAM,q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AU,CAAC,GAAG,CAAC,CAAC,EAAE,IAAI,EAAE,OAAO,EAAE,EAAE,EAAE,CAAC,CAAC,EAAE,IAAI,EAAE,OAAO,EAAE,CAAC,CAAC;KAC9D,CAAC;AACJ,CAAC","sourcesContent":["import type { ExecSql } from \"../sqlExec\";\n\nexport interface LocalSchemaMigrationContext {\n /**\n * Whether a table exists. Features create their tables lazily, so a\n * migration must skip a table this database never created: the table's\n * ensure creates it later in the current shape.\n */\n hasTable(name: string): Promise<boolean>;\n}\n\nexport interface LocalSchemaStep {\n readonly version: number;\n readonly name: string;\n}\n\nexport interface LocalSchemaMigration extends LocalSchemaStep {\n /**\n * Upgrades the local database from `version - 1` to `version`. It runs on\n * the locked executor inside the migration savepoint, so it must not BEGIN,\n * COMMIT, or change `PRAGMA foreign_keys`. Write it against the shape at\n * `version - 1`, never by importing current table definitions.\n */\n up(execSql: ExecSql, context: LocalSchemaMigrationContext): Promise<void>;\n}\n\n/**\n * Version 1 is the shape the SDK's table definitions created when local\n * migrations began. It has no steps: a database from before the ledger is\n * recorded at this version, and an older shape still fails its tables'\n * required-column check.\n */\nexport const LOCAL_SCHEMA_BASELINE: LocalSchemaStep = {\n name: \"baseline\",\n version: 1,\n};\n\nconst DIRECTORY_USERS_TABLE = \"organization_read_model_directory_users\";\n\n/**\n * Ordered and append-only: version 2 first, each one after the last. Never\n * edit or remove a shipped step; a correction is a new step.\n */\nexport const localSchemaMigrations: ReadonlyArray<LocalSchemaMigration> = [\n {\n // Directory rows carry key fingerprints only; public keys come from the\n // trusted identity store. Neither column is indexed or constrained.\n name: \"drop_directory_user_public_keys\",\n up: async (execSql, context) => {\n if (!(await context.hasTable(DIRECTORY_USERS_TABLE))) return;\n for (const column of [\"signing_public_key\", \"encapsulation_public_key\"]) {\n await execSql(\n `ALTER TABLE \"${DIRECTORY_USERS_TABLE}\" DROP COLUMN \"${column}\"`,\n );\n }\n },\n version: 2,\n },\n];\n\nconst STEP_NAME_PATTERN = /^[a-z0-9_]+$/;\n\n/** Rejects a registry whose versions are not consecutive from 2. */\nexport function assertLocalSchemaMigrations(\n migrations: ReadonlyArray<LocalSchemaMigration>,\n): void {\n for (const [index, migration] of migrations.entries()) {\n const expected = LOCAL_SCHEMA_BASELINE.version + index + 1;\n if (migration.version !== expected) {\n throw new Error(\n `Local schema migration ${migration.name} has version ${migration.version}; expected ${expected}`,\n );\n }\n if (!STEP_NAME_PATTERN.test(migration.name)) {\n throw new Error(\n `Local schema migration ${migration.version} needs a snake_case name`,\n );\n }\n }\n}\n\n/** The steps a database at the newest version has recorded, in order. */\nexport function localSchemaSteps(\n migrations: ReadonlyArray<LocalSchemaMigration>,\n): ReadonlyArray<LocalSchemaStep> {\n return [\n LOCAL_SCHEMA_BASELINE,\n ...migrations.map(({ name, version }) => ({ name, version })),\n ];\n}\n"]}
1
+ {"version":3,"file":"localSchemaMigrations.js","sourceRoot":"","sources":["localSchemaMigrations.ts"],"names":[],"mappings":"AA0BA;;;;;GAKG;AACH,MAAM,CAAC,MAAM,qBAAqB,GAAoB;IACpD,IAAI,EAAE,UAAU;IAChB,OAAO,EAAE,CAAC;CACX,CAAC;AAEF,MAAM,qBAAqB,GAAG,yCAAyC,CAAC;AAExE;;;GAGG;AACH,MAAM,CAAC,MAAM,qBAAqB,GAAwC;IACxE;QACE,wEAAwE;QACxE,oEAAoE;QACpE,IAAI,EAAE,iCAAiC;QACvC,EAAE,EAAE,KAAK,EAAE,OAAO,EAAE,OAAO,EAAE,EAAE;YAC7B,IAAI,CAAC,CAAC,MAAM,OAAO,CAAC,QAAQ,CAAC,qBAAqB,CAAC,CAAC;gBAAE,OAAO;YAC7D,KAAK,MAAM,MAAM,IAAI,CAAC,oBAAoB,EAAE,0BAA0B,CAAC,EAAE,CAAC;gBACxE,MAAM,OAAO,CACX,gBAAgB,qBAAqB,kBAAkB,MAAM,GAAG,CACjE,CAAC;YACJ,CAAC;QACH,CAAC;QACD,OAAO,EAAE,CAAC;KACX;IACD;QACE,wEAAwE;QACxE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lExec\";\n\nexport interface LocalSchemaMigrationContext {\n /**\n * Whether a table exists. Features create their tables lazily, so a\n * migration must skip a table this database never created: the table's\n * ensure creates it later in the current shape.\n */\n hasTable(name: string): Promise<boolean>;\n}\n\nexport interface LocalSchemaStep {\n readonly version: number;\n readonly name: string;\n}\n\nexport interface LocalSchemaMigration extends LocalSchemaStep {\n /**\n * Upgrades the local database from `version - 1` to `version`. It runs on\n * the locked executor inside the migration savepoint, so it must not BEGIN,\n * COMMIT, or change `PRAGMA foreign_keys`. Write it against the shape at\n * `version - 1`, never by importing current table definitions.\n */\n up(execSql: ExecSql, context: LocalSchemaMigrationContext): Promise<void>;\n}\n\n/**\n * Version 1 is the shape the SDK's table definitions created when local\n * migrations began. It has no steps: a database from before the ledger is\n * recorded at this version, and an older shape still fails its tables'\n * required-column check.\n */\nexport const LOCAL_SCHEMA_BASELINE: LocalSchemaStep = {\n name: \"baseline\",\n version: 1,\n};\n\nconst DIRECTORY_USERS_TABLE = \"organization_read_model_directory_users\";\n\n/**\n * Ordered and append-only: version 2 first, each one after the last. Never\n * edit or remove a shipped step; a correction is a new step.\n */\nexport const localSchemaMigrations: ReadonlyArray<LocalSchemaMigration> = [\n {\n // Directory rows carry key fingerprints only; public keys come from the\n // trusted identity store. Neither column is indexed or constrained.\n name: \"drop_directory_user_public_keys\",\n up: async (execSql, context) => {\n if (!(await context.hasTable(DIRECTORY_USERS_TABLE))) return;\n for (const column of [\"signing_public_key\", \"encapsulation_public_key\"]) {\n await execSql(\n `ALTER TABLE \"${DIRECTORY_USERS_TABLE}\" DROP COLUMN \"${column}\"`,\n );\n }\n },\n version: 2,\n },\n {\n // No reader ever used a recorded failure's HTTP status; the message and\n // attempt time explain a blocked document. The column is unindexed. A\n // documents table without it (never created, or not this SDK's table in a\n // restored backup) has nothing to drop.\n name: \"drop_document_sync_failure_status\",\n up: async (execSql) => {\n const column = await execSql(\n \"SELECT name FROM pragma_table_info('documents') WHERE name = 'sync_failure_status'\",\n );\n if (column.length === 0) return;\n await execSql(\n 'ALTER TABLE \"documents\" DROP COLUMN \"sync_failure_status\"',\n );\n },\n version: 3,\n },\n];\n\nconst STEP_NAME_PATTERN = /^[a-z0-9_]+$/;\n\n/** Rejects a registry whose versions are not consecutive from 2. */\nexport function assertLocalSchemaMigrations(\n migrations: ReadonlyArray<LocalSchemaMigration>,\n): void {\n for (const [index, migration] of migrations.entries()) {\n const expected = LOCAL_SCHEMA_BASELINE.version + index + 1;\n if (migration.version !== expected) {\n throw new Error(\n `Local schema migration ${migration.name} has version ${migration.version}; expected ${expected}`,\n );\n }\n if (!STEP_NAME_PATTERN.test(migration.name)) {\n throw new Error(\n `Local schema migration ${migration.version} needs a snake_case name`,\n );\n }\n }\n}\n\n/** The steps a database at the newest version has recorded, in order. */\nexport function localSchemaSteps(\n migrations: ReadonlyArray<LocalSchemaMigration>,\n): ReadonlyArray<LocalSchemaStep> {\n return [\n LOCAL_SCHEMA_BASELINE,\n ...migrations.map(({ name, version }) => ({ name, version })),\n ];\n}\n"]}
@@ -39,14 +39,14 @@ const accessLevelColumn = "effective_access_level";
39
39
  * - `recoveryGeneration`: Atomic raw-history recovery writer fence.
40
40
  * - `recoveryDocumentId`: Former server id for cross-client post-purge recreation.
41
41
  * - `pullContinuation`: Durable progress for the next bounded remote pull.
42
- * - `syncFailureStatus`, `syncFailureMessage`, `syncFailureAttemptedAt`: The
43
- * last terminal sync failure or quarantined incoming update for this scope.
42
+ * - `syncFailureMessage`, `syncFailureAttemptedAt`: The last terminal sync
43
+ * failure or quarantined incoming update for this scope.
44
44
  * The durable write queue (queued rows of `documentHistoryUpdates`) has no
45
45
  * status columns, so these let the write-queue view and footer explain why
46
46
  * the document is blocked. `syncFailureMessage` is non-null exactly when a
47
47
  * failure is recorded; a newer failure replaces the old, and a later fully
48
- * validated sync pass, a remote reset, or the scope's teardown clears all
49
- * three.
48
+ * validated sync pass, a remote reset, or the scope's teardown clears
49
+ * both.
50
50
  * - `updatedAt`: Local timestamp for the last persisted runtime-state update.
51
51
  *
52
52
  * Indexes:
@@ -74,7 +74,6 @@ export const documents = sqliteTable("documents", {
74
74
  recoveryGeneration: integer("recovery_generation").notNull().default(0),
75
75
  recoveryDocumentId: text("recovery_document_id"),
76
76
  snapshotEndVersion: text("snapshot_end_version").notNull().default(""),
77
- syncFailureStatus: integer("sync_failure_status"),
78
77
  syncFailureMessage: text("sync_failure_message"),
79
78
  syncFailureAttemptedAt: text("sync_failure_attempted_at"),
80
79
  updatedAt: text("updated_at").notNull(),
@@ -174,7 +173,6 @@ export const documentTables = [
174
173
  "pull_continuation",
175
174
  "recovery_generation",
176
175
  "recovery_document_id",
177
- "sync_failure_status",
178
176
  "sync_failure_message",
179
177
  "sync_failure_attempted_at",
180
178
  ],
@@ -1 +1 @@
1
- {"version":3,"file":"documentRecordSchema.js","sourceRoot":"","sources":["documentRecordSchema.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,GAAG,EAAE,MAAM,aAAa,CAAC;AAClC,OAAO,EACL,KAAK,EACL,OAAO,EACP,UAAU,EACV,WAAW,EACX,IAAI,EACJ,WAAW,GACZ,MAAM,yBAAyB,CAAC;AACjC,OAAO,EAAE,oBAAoB,EAAuB,MAAM,mBAAmB,CAAC;AAE9E,MAAM,iBAAiB,GAAG,wBAAwB,CAAC;AACnD;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAuDG;AACH,MAAM,CAAC,MAAM,SAAS,GAAG,WAAW,CAClC,WAAW,EACX;IACE,OAAO,EAAE,IAAI,CAAC,UAAU,CAAC,CAAC,OAAO,EAAE;IACnC,OAAO,EAAE,IAAI,CAAC,UAAU,CAAC,CAAC,OAAO,EAAE;IACnC,UAAU,EAAE,IAAI,CAAC,aAAa,CAAC;IAC/B,WAAW,EAAE,OAAO,CAAC,cAAc,CAAC,CAAC,OAAO,EAAE,CAAC,OAAO,CAAC,CAAC,CAAC;IACzD,eAAe,EAAE,IAAI,CAAC,mBAAmB,CAA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{\n index,\n integer,\n primaryKey,\n sqliteTable,\n text,\n uniqueIndex,\n} from \"drizzle-orm/sqlite-core\";\nimport { defineSqlTableSchema, type SqlTableSchema } from \"../sqlTableSchema\";\n\nconst accessLevelColumn = \"effective_access_level\";\n/**\n * Durable Loro-backed document records shared by app features.\n *\n * This table stores encrypted document runtime state for multiple app domains.\n * `appKind` namespaces records for documents and container metadata. User-facing\n * list data is projected into feature-specific read models.\n *\n * Columns:\n * - `appKind`: Local domain namespace for the row, such as `documents` or\n * `container-metadata`.\n * - `localId`: Stable local id inside `appKind`. It may be created before a\n * server `documentId` exists.\n * - `documentId`: Server document id once the record is known remotely, or\n * `null` while the document is local-only.\n * - `accessEpoch`: Latest access epoch persisted for the document. Defaults to\n * the initial epoch.\n * - `accessStateHash`: Current document access/manifest state hash returned by\n * sync, when known.\n * - `lastCommitLsn`: Last remote commit cursor applied to this local document.\n * - `documentManifestBundle`: Serialized document manifest bundle used for\n * encrypted document sync.\n * - `contentKeyBundle`: Serialized content-key material needed to open the\n * local document.\n * - `documentKekTargets`: Serialized KEK target state for document key wraps.\n * - `pendingBaseVersion`: Encoded oplog version through which every persisted\n * op is already enqueued or synced. Persisted so a restart restores the\n * outgoing-delta marker instead of re-seeding it past a device-first\n * `deferRemoteSync` write's un-advanced op. `null` when unset.\n * - `snapshotEndVersion`: Encoded end version vector of the persisted content\n * (which lives in the durable-history tables, never on this row), written on\n * every content persist. Lets the pending-write queue's deferred-tail scan\n * compare version coverage without loading content. Empty string when the\n * document has never hydrated content, which readers treat as \"no deferred\n * tail claimable\".\n * - `recoveryGeneration`: Atomic raw-history recovery writer fence.\n * - `recoveryDocumentId`: Former server id for cross-client post-purge recreation.\n * - `pullContinuation`: Durable progress for the next bounded remote pull.\n * - `syncFailureStatus`, `syncFailureMessage`, `syncFailureAttemptedAt`: The\n * last terminal sync failure or quarantined incoming update for this scope.\n * The durable write queue (queued rows of `documentHistoryUpdates`) has no\n * status columns, so these let the write-queue view and footer explain why\n * the document is blocked. `syncFailureMessage` is non-null exactly when a\n * failure is recorded; a newer failure replaces the old, and a later fully\n * validated sync pass, a remote reset, or the scope's teardown clears all\n * three.\n * - `updatedAt`: Local timestamp for the last persisted runtime-state update.\n *\n * Indexes:\n * - `(appKind, localId)` is the primary key and scopes local document lookups.\n * - `(appKind, documentId) where documentId is not null` supports resolving a\n * server document id back to the local row during discovery and relinking.\n * - `(appKind, localId)` over records whose `pendingBaseVersion` differs from\n * a non-empty `snapshotEndVersion` serves the pending-write queue's\n * deferred-tail scan, which repeats that condition, so it reads only\n * unsettled records instead of every synced one.\n */\nexport const documents = sqliteTable(\n \"documents\",\n {\n appKind: text(\"app_kind\").notNull(),\n localId: text(\"local_id\").notNull(),\n documentId: text(\"document_id\"),\n accessEpoch: integer(\"access_epoch\").notNull().default(1),\n accessStateHash: text(\"access_state_hash\"),\n effectiveAccessLevel: text(accessLevelColumn).notNull().default(\"read\"),\n lastCommitLsn: text(\"last_commit_lsn\"),\n documentManifestBundle: text(\"document_manifest_bundle\"),\n contentKeyBundle: text(\"content_key_bundle\"),\n documentKekTargets: text(\"document_kek_targets\"),\n pendingBaseVersion: text(\"pending_base_version\"),\n pullContinuation: text(\"pull_continuation\"),\n recoveryGeneration: integer(\"recovery_generation\").notNull().default(0),\n recoveryDocumentId: text(\"recovery_document_id\"),\n snapshotEndVersion: text(\"snapshot_end_version\").notNull().default(\"\"),\n syncFailureStatus: integer(\"sync_failure_status\"),\n syncFailureMessage: text(\"sync_failure_message\"),\n syncFailureAttemptedAt: text(\"sync_failure_attempted_at\"),\n updatedAt: text(\"updated_at\").notNull(),\n },\n (table) => [\n primaryKey({ columns: [table.appKind, table.localId] }),\n index(\"documents_app_document_idx\")\n .on(table.appKind, table.documentId)\n .where(sql`${table.documentId} IS NOT NULL`),\n index(\"documents_deferred_tail_idx\")\n .on(table.appKind, table.localId)\n .where(\n sql`${table.snapshotEndVersion} <> '' AND ${table.pendingBaseVersion} IS NOT ${table.snapshotEndVersion}`,\n ),\n ],\n);\n\n/**\n * Full-history persistence for local documents (checkpoint + tail) — the ONLY\n * durable content source. Record rows in `documents` carry runtime metadata\n * and the content frontier (`snapshotEndVersion`), never content. The\n * checkpoint holds a full-history snapshot refreshed only at compaction, and\n * the tail appends every update (local deltas and decrypted remote updates)\n * written since. Restore = import checkpoint + replay tail; compaction =\n * export full history from the live doc, replace the checkpoint, clear the\n * tail — all bounded and amortized. Container metadata stores its content (an\n * exported-updates blob) as its checkpoint row, with no tail.\n */\nexport const documentHistoryCheckpoints = sqliteTable(\n \"document_history_checkpoints\",\n {\n appKind: text(\"app_kind\").notNull(),\n localId: text(\"local_id\").notNull(),\n snapshot: text(\"snapshot\").notNull(),\n endVersionVector: text(\"end_version_vector\").notNull(),\n revision: text(\"revision\").notNull(),\n updatedAt: text(\"updated_at\").notNull(),\n },\n (table) => [primaryKey({ columns: [table.appKind, table.localId] })],\n);\n\n/**\n * The local update log: one row per Loro update, serving as both the history\n * tail (restore = checkpoint + tail) and the outbound write queue.\n *\n * Every locally authored update is stored once. While it waits for sync it\n * carries an `updateId` (the id submitted to the server) and the version-vector\n * metadata the submission needs; settlement clears them, leaving the row as\n * ordinary tail history until compaction folds it into a checkpoint. Before a\n * send, a contiguous run of queued local rows may be replaced by one merged\n * row holding exactly their operations: the first row is updated in place\n * (same `id`, `createdAt` and `rowid`, so the same queue and replay position)\n * under a fresh `updateId`, and the other rows are deleted.\n *\n * Columns:\n * - `id`: Row id; tail compaction deletes by it.\n * - `appKind`, `localId`: Document scope matching `documents`.\n * - `updateData`: Serialized Loro update payload.\n * - `origin`: \"local\" (authored on this device) or \"remote\" (decrypted\n * pulled update) for tail rows. Restores use it to advance the\n * outgoing-delta marker across remote rows — their ops are already\n * server-side — while a local row left behind by a crash stays below the\n * marker so the next edit re-derives and sends it. \"outbox\" marks a queued\n * update with no tail role (container metadata, whose content is its\n * checkpoint, and full-state re-uploads after a remote reset); restores and\n * compaction never see it and settlement deletes it.\n * - `createdAt`: Insertion timestamp; with `rowid`, deterministic replay order.\n * - `updateId`: Present exactly while the row is queued for sync; rekeyed\n * after a lost acknowledgement poisons the submitted id, and replaced by a\n * fresh id when queued rows merge. An id never names two payloads.\n * - `partialStartVersionVector` / `partialEndVersionVector`: Version vectors\n * around a queued partial update.\n * - `sourceVersionVector`: Present on a queued rotation baseline checkpoint.\n * - `rekeyCount`: Durable bound on rekeys of a queued row; a merged row takes\n * the largest count among the rows it replaces.\n *\n * Invariant: compaction never deletes a queued row, so a checkpoint can cover\n * a queued update's operations without removing it from the queue.\n */\nexport const documentHistoryUpdates = sqliteTable(\n \"document_history_updates\",\n {\n id: text(\"id\"),\n appKind: text(\"app_kind\").notNull(),\n localId: text(\"local_id\").notNull(),\n updateData: text(\"update_data\").notNull(),\n origin: text(\"origin\").notNull(),\n createdAt: text(\"created_at\").notNull(),\n updateId: text(\"update_id\"),\n partialStartVersionVector: text(\"partial_start_version_vector\"),\n partialEndVersionVector: text(\"partial_end_version_vector\"),\n sourceVersionVector: text(\"source_version_vector\"),\n rekeyCount: integer(\"rekey_count\").notNull().default(0),\n },\n (table) => [\n primaryKey({ columns: [table.id] }),\n index(\"document_history_updates_scope_created_idx\").on(\n table.appKind,\n table.localId,\n table.createdAt,\n ),\n uniqueIndex(\"document_history_updates_update_id_idx\")\n .on(table.updateId)\n .where(sql`${table.updateId} IS NOT NULL`),\n // Queued rows only: pending counts and pending loads skip settled history.\n index(\"document_history_updates_queued_scope_idx\")\n .on(table.appKind, table.localId, table.createdAt)\n .where(sql`${table.updateId} IS NOT NULL`),\n ],\n);\n\nexport const documentTables: ReadonlyArray<SqlTableSchema> = [\n {\n ...defineSqlTableSchema(documents),\n requiredColumns: [\n \"pull_continuation\",\n \"recovery_generation\",\n \"recovery_document_id\",\n \"sync_failure_status\",\n \"sync_failure_message\",\n \"sync_failure_attempted_at\",\n ],\n },\n defineSqlTableSchema(documentHistoryCheckpoints),\n {\n ...defineSqlTableSchema(documentHistoryUpdates),\n requiredColumns: [\"update_id\"],\n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,wCAAwC,CAAC;SAClD,EAAE,CAAC,KAAK,CAAC,QAAQ,CAAC;SAClB,KAAK,CAAC,GAAG,CAAA,GAAG,KAAK,CAAC,QAAQ,cAAc,CAAC;IAC5C,2EAA2E;IAC3E,KAAK,CAAC,2CAA2C,CAAC;SAC/C,EAAE,CAAC,KAAK,CAAC,OAAO,EAAE,KAAK,CAAC,OAAO,EAAE,KAAK,CAAC,SAAS,CAAC;SACjD,KAAK,CAAC,GAAG,CAAA,GAAG,KAAK,CAAC,QAAQ,cAAc,CAAC;CAC7C,CACF,CAAC;AAEF,MAAM,CAAC,MAAM,cAAc,GAAkC;IAC3D;QACE,GAAG,oBAAoB,CAAC,SAAS,CAAC;QAClC,eAAe,EAAE;YACf,mBAAmB;YACnB,qBAAqB;YACrB,sBAAsB;YACtB,sBAAsB;YACtB,2BAA2B;SAC5B;KACF;IACD,oBAAoB,CAAC,0BAA0B,CAAC;IAChD;QACE,GAAG,oBAAoB,CAAC,sBAAsB,CAAC;QAC/C,eAAe,EAAE,CAAC,WAAW,CAAC;KAC/B;CACF,CAAC","sourcesContent":["import { sql } from \"drizzle-orm\";\nimport {\n index,\n integer,\n primaryKey,\n sqliteTable,\n text,\n uniqueIndex,\n} from \"drizzle-orm/sqlite-core\";\nimport { defineSqlTableSchema, type SqlTableSchema } from \"../sqlTableSchema\";\n\nconst accessLevelColumn = \"effective_access_level\";\n/**\n * Durable Loro-backed document records shared by app features.\n *\n * This table stores encrypted document runtime state for multiple app domains.\n * `appKind` namespaces records for documents and container metadata. User-facing\n * list data is projected into feature-specific read models.\n *\n * Columns:\n * - `appKind`: Local domain namespace for the row, such as `documents` or\n * `container-metadata`.\n * - `localId`: Stable local id inside `appKind`. It may be created before a\n * server `documentId` exists.\n * - `documentId`: Server document id once the record is known remotely, or\n * `null` while the document is local-only.\n * - `accessEpoch`: Latest access epoch persisted for the document. Defaults to\n * the initial epoch.\n * - `accessStateHash`: Current document access/manifest state hash returned by\n * sync, when known.\n * - `lastCommitLsn`: Last remote commit cursor applied to this local document.\n * - `documentManifestBundle`: Serialized document manifest bundle used for\n * encrypted document sync.\n * - `contentKeyBundle`: Serialized content-key material needed to open the\n * local document.\n * - `documentKekTargets`: Serialized KEK target state for document key wraps.\n * - `pendingBaseVersion`: Encoded oplog version through which every persisted\n * op is already enqueued or synced. Persisted so a restart restores the\n * outgoing-delta marker instead of re-seeding it past a device-first\n * `deferRemoteSync` write's un-advanced op. `null` when unset.\n * - `snapshotEndVersion`: Encoded end version vector of the persisted content\n * (which lives in the durable-history tables, never on this row), written on\n * every content persist. Lets the pending-write queue's deferred-tail scan\n * compare version coverage without loading content. Empty string when the\n * document has never hydrated content, which readers treat as \"no deferred\n * tail claimable\".\n * - `recoveryGeneration`: Atomic raw-history recovery writer fence.\n * - `recoveryDocumentId`: Former server id for cross-client post-purge recreation.\n * - `pullContinuation`: Durable progress for the next bounded remote pull.\n * - `syncFailureMessage`, `syncFailureAttemptedAt`: The last terminal sync\n * failure or quarantined incoming update for this scope.\n * The durable write queue (queued rows of `documentHistoryUpdates`) has no\n * status columns, so these let the write-queue view and footer explain why\n * the document is blocked. `syncFailureMessage` is non-null exactly when a\n * failure is recorded; a newer failure replaces the old, and a later fully\n * validated sync pass, a remote reset, or the scope's teardown clears\n * both.\n * - `updatedAt`: Local timestamp for the last persisted runtime-state update.\n *\n * Indexes:\n * - `(appKind, localId)` is the primary key and scopes local document lookups.\n * - `(appKind, documentId) where documentId is not null` supports resolving a\n * server document id back to the local row during discovery and relinking.\n * - `(appKind, localId)` over records whose `pendingBaseVersion` differs from\n * a non-empty `snapshotEndVersion` serves the pending-write queue's\n * deferred-tail scan, which repeats that condition, so it reads only\n * unsettled records instead of every synced one.\n */\nexport const documents = sqliteTable(\n \"documents\",\n {\n appKind: text(\"app_kind\").notNull(),\n localId: text(\"local_id\").notNull(),\n documentId: text(\"document_id\"),\n accessEpoch: integer(\"access_epoch\").notNull().default(1),\n accessStateHash: text(\"access_state_hash\"),\n effectiveAccessLevel: text(accessLevelColumn).notNull().default(\"read\"),\n lastCommitLsn: text(\"last_commit_lsn\"),\n documentManifestBundle: text(\"document_manifest_bundle\"),\n contentKeyBundle: text(\"content_key_bundle\"),\n documentKekTargets: text(\"document_kek_targets\"),\n pendingBaseVersion: text(\"pending_base_version\"),\n pullContinuation: text(\"pull_continuation\"),\n recoveryGeneration: integer(\"recovery_generation\").notNull().default(0),\n recoveryDocumentId: text(\"recovery_document_id\"),\n snapshotEndVersion: text(\"snapshot_end_version\").notNull().default(\"\"),\n syncFailureMessage: text(\"sync_failure_message\"),\n syncFailureAttemptedAt: text(\"sync_failure_attempted_at\"),\n updatedAt: text(\"updated_at\").notNull(),\n },\n (table) => [\n primaryKey({ columns: [table.appKind, table.localId] }),\n index(\"documents_app_document_idx\")\n .on(table.appKind, table.documentId)\n .where(sql`${table.documentId} IS NOT NULL`),\n index(\"documents_deferred_tail_idx\")\n .on(table.appKind, table.localId)\n .where(\n sql`${table.snapshotEndVersion} <> '' AND ${table.pendingBaseVersion} IS NOT ${table.snapshotEndVersion}`,\n ),\n ],\n);\n\n/**\n * Full-history persistence for local documents (checkpoint + tail) — the ONLY\n * durable content source. Record rows in `documents` carry runtime metadata\n * and the content frontier (`snapshotEndVersion`), never content. The\n * checkpoint holds a full-history snapshot refreshed only at compaction, and\n * the tail appends every update (local deltas and decrypted remote updates)\n * written since. Restore = import checkpoint + replay tail; compaction =\n * export full history from the live doc, replace the checkpoint, clear the\n * tail — all bounded and amortized. Container metadata stores its content (an\n * exported-updates blob) as its checkpoint row, with no tail.\n */\nexport const documentHistoryCheckpoints = sqliteTable(\n \"document_history_checkpoints\",\n {\n appKind: text(\"app_kind\").notNull(),\n localId: text(\"local_id\").notNull(),\n snapshot: text(\"snapshot\").notNull(),\n endVersionVector: text(\"end_version_vector\").notNull(),\n revision: text(\"revision\").notNull(),\n updatedAt: text(\"updated_at\").notNull(),\n },\n (table) => [primaryKey({ columns: [table.appKind, table.localId] })],\n);\n\n/**\n * The local update log: one row per Loro update, serving as both the history\n * tail (restore = checkpoint + tail) and the outbound write queue.\n *\n * Every locally authored update is stored once. While it waits for sync it\n * carries an `updateId` (the id submitted to the server) and the version-vector\n * metadata the submission needs; settlement clears them, leaving the row as\n * ordinary tail history until compaction folds it into a checkpoint. Before a\n * send, a contiguous run of queued local rows may be replaced by one merged\n * row holding exactly their operations: the first row is updated in place\n * (same `id`, `createdAt` and `rowid`, so the same queue and replay position)\n * under a fresh `updateId`, and the other rows are deleted.\n *\n * Columns:\n * - `id`: Row id; tail compaction deletes by it.\n * - `appKind`, `localId`: Document scope matching `documents`.\n * - `updateData`: Serialized Loro update payload.\n * - `origin`: \"local\" (authored on this device) or \"remote\" (decrypted\n * pulled update) for tail rows. Restores use it to advance the\n * outgoing-delta marker across remote rows — their ops are already\n * server-side — while a local row left behind by a crash stays below the\n * marker so the next edit re-derives and sends it. \"outbox\" marks a queued\n * update with no tail role (container metadata, whose content is its\n * checkpoint, and full-state re-uploads after a remote reset); restores and\n * compaction never see it and settlement deletes it.\n * - `createdAt`: Insertion timestamp; with `rowid`, deterministic replay order.\n * - `updateId`: Present exactly while the row is queued for sync; rekeyed\n * after a lost acknowledgement poisons the submitted id, and replaced by a\n * fresh id when queued rows merge. An id never names two payloads.\n * - `partialStartVersionVector` / `partialEndVersionVector`: Version vectors\n * around a queued partial update.\n * - `sourceVersionVector`: Present on a queued rotation baseline checkpoint.\n * - `rekeyCount`: Durable bound on rekeys of a queued row; a merged row takes\n * the largest count among the rows it replaces.\n *\n * Invariant: compaction never deletes a queued row, so a checkpoint can cover\n * a queued update's operations without removing it from the queue.\n */\nexport const documentHistoryUpdates = sqliteTable(\n \"document_history_updates\",\n {\n id: text(\"id\"),\n appKind: text(\"app_kind\").notNull(),\n localId: text(\"local_id\").notNull(),\n updateData: text(\"update_data\").notNull(),\n origin: text(\"origin\").notNull(),\n createdAt: text(\"created_at\").notNull(),\n updateId: text(\"update_id\"),\n partialStartVersionVector: text(\"partial_start_version_vector\"),\n partialEndVersionVector: text(\"partial_end_version_vector\"),\n sourceVersionVector: text(\"source_version_vector\"),\n rekeyCount: integer(\"rekey_count\").notNull().default(0),\n },\n (table) => [\n primaryKey({ columns: [table.id] }),\n index(\"document_history_updates_scope_created_idx\").on(\n table.appKind,\n table.localId,\n table.createdAt,\n ),\n uniqueIndex(\"document_history_updates_update_id_idx\")\n .on(table.updateId)\n .where(sql`${table.updateId} IS NOT NULL`),\n // Queued rows only: pending counts and pending loads skip settled history.\n index(\"document_history_updates_queued_scope_idx\")\n .on(table.appKind, table.localId, table.createdAt)\n .where(sql`${table.updateId} IS NOT NULL`),\n ],\n);\n\nexport const documentTables: ReadonlyArray<SqlTableSchema> = [\n {\n ...defineSqlTableSchema(documents),\n requiredColumns: [\n \"pull_continuation\",\n \"recovery_generation\",\n \"recovery_document_id\",\n \"sync_failure_message\",\n \"sync_failure_attempted_at\",\n ],\n },\n defineSqlTableSchema(documentHistoryCheckpoints),\n {\n ...defineSqlTableSchema(documentHistoryUpdates),\n requiredColumns: [\"update_id\"],\n },\n];\n"]}
@@ -4739,23 +4739,6 @@ export declare const clientSQLiteSchema: {
4739
4739
  }, {}, {
4740
4740
  length: number | undefined;
4741
4741
  }>;
4742
- syncFailureStatus: import("drizzle-orm/sqlite-core").SQLiteColumn<{
4743
- name: "sync_failure_status";
4744
- tableName: "documents";
4745
- dataType: "number";
4746
- columnType: "SQLiteInteger";
4747
- data: number;
4748
- driverParam: number;
4749
- notNull: false;
4750
- hasDefault: false;
4751
- isPrimaryKey: false;
4752
- isAutoincrement: false;
4753
- hasRuntimeDefault: false;
4754
- enumValues: undefined;
4755
- baseColumn: never;
4756
- identity: undefined;
4757
- generated: undefined;
4758
- }, {}, {}>;
4759
4742
  syncFailureMessage: import("drizzle-orm/sqlite-core").SQLiteColumn<{
4760
4743
  name: "sync_failure_message";
4761
4744
  tableName: "documents";
@@ -231,7 +231,7 @@ export declare const createContainerOperation: Omit<{
231
231
  error: string;
232
232
  }>>;
233
233
  readonly 409: z.ZodUnion<readonly [z.ZodObject<{
234
- code: z.ZodOptional<z.ZodUnion<readonly [z.ZodLiteral<"container_mutation_state_stale" | "container_descendant_rekeys_required" | "container_ancestor_rekeys_required" | "container_descendant_rekeys_inaccessible" | "container_manifest_already_exists" | "container_path_too_deep">, z.ZodUnion<readonly [z.ZodLiteral<"document_manifest_already_exists">, z.ZodLiteral<"document_sync_checkpoint_coverage_conflict" | "document_sync_conflict" | "document_sync_descendant_rekeys_required" | "document_sync_state_stale" | "document_sync_update_id_conflict">, z.ZodLiteral<"document_not_found">, z.ZodLiteral<"container_unavailable">, z.ZodLiteral<"document_unlink_rotation_baseline_stale">]>]>>;
234
+ code: z.ZodOptional<z.ZodUnion<readonly [z.ZodLiteral<"container_mutation_state_stale" | "container_descendant_rekeys_required" | "container_ancestor_rekeys_required" | "container_descendant_rekeys_inaccessible" | "container_manifest_already_exists" | "container_path_too_deep">, z.ZodUnion<readonly [z.ZodLiteral<"document_manifest_already_exists">, z.ZodLiteral<"document_sync_checkpoint_coverage_conflict" | "document_sync_conflict" | "document_sync_descendant_rekeys_required" | "document_sync_state_stale" | "document_sync_update_id_conflict">, z.ZodLiteral<"document_not_found">, z.ZodLiteral<"container_unavailable">, z.ZodLiteral<"document_link_attachments_changed">, z.ZodLiteral<"document_unlink_rotation_baseline_stale">]>]>>;
235
235
  error: z.ZodString;
236
236
  requiredContainerIds: z.ZodOptional<z.ZodCustom<string[], string[]>>;
237
237
  }, z.core.$loose>, z.ZodType<{
@@ -443,7 +443,7 @@ export declare const createContainerOperation: Omit<{
443
443
  error: string;
444
444
  }>>;
445
445
  readonly 409: z.ZodUnion<readonly [z.ZodObject<{
446
- code: z.ZodOptional<z.ZodUnion<readonly [z.ZodLiteral<"container_mutation_state_stale" | "container_descendant_rekeys_required" | "container_ancestor_rekeys_required" | "container_descendant_rekeys_inaccessible" | "container_manifest_already_exists" | "container_path_too_deep">, z.ZodUnion<readonly [z.ZodLiteral<"document_manifest_already_exists">, z.ZodLiteral<"document_sync_checkpoint_coverage_conflict" | "document_sync_conflict" | "document_sync_descendant_rekeys_required" | "document_sync_state_stale" | "document_sync_update_id_conflict">, z.ZodLiteral<"document_not_found">, z.ZodLiteral<"container_unavailable">, z.ZodLiteral<"document_unlink_rotation_baseline_stale">]>]>>;
446
+ code: z.ZodOptional<z.ZodUnion<readonly [z.ZodLiteral<"container_mutation_state_stale" | "container_descendant_rekeys_required" | "container_ancestor_rekeys_required" | "container_descendant_rekeys_inaccessible" | "container_manifest_already_exists" | "container_path_too_deep">, z.ZodUnion<readonly [z.ZodLiteral<"document_manifest_already_exists">, z.ZodLiteral<"document_sync_checkpoint_coverage_conflict" | "document_sync_conflict" | "document_sync_descendant_rekeys_required" | "document_sync_state_stale" | "document_sync_update_id_conflict">, z.ZodLiteral<"document_not_found">, z.ZodLiteral<"container_unavailable">, z.ZodLiteral<"document_link_attachments_changed">, z.ZodLiteral<"document_unlink_rotation_baseline_stale">]>]>>;
447
447
  error: z.ZodString;
448
448
  requiredContainerIds: z.ZodOptional<z.ZodCustom<string[], string[]>>;
449
449
  }, z.core.$loose>, z.ZodType<{
@@ -1352,7 +1352,7 @@ export declare const createContainerWithMetadataDocumentOperation: Omit<{
1352
1352
  error: string;
1353
1353
  }>>;
1354
1354
  readonly 409: z.ZodUnion<readonly [z.ZodObject<{
1355
- code: z.ZodOptional<z.ZodUnion<readonly [z.ZodLiteral<"container_mutation_state_stale" | "container_descendant_rekeys_required" | "container_ancestor_rekeys_required" | "container_descendant_rekeys_inaccessible" | "container_manifest_already_exists" | "container_path_too_deep">, z.ZodUnion<readonly [z.ZodLiteral<"document_manifest_already_exists">, z.ZodLiteral<"document_sync_checkpoint_coverage_conflict" | "document_sync_conflict" | "document_sync_descendant_rekeys_required" | "document_sync_state_stale" | "document_sync_update_id_conflict">, z.ZodLiteral<"document_not_found">, z.ZodLiteral<"container_unavailable">, z.ZodLiteral<"document_unlink_rotation_baseline_stale">]>]>>;
1355
+ code: z.ZodOptional<z.ZodUnion<readonly [z.ZodLiteral<"container_mutation_state_stale" | "container_descendant_rekeys_required" | "container_ancestor_rekeys_required" | "container_descendant_rekeys_inaccessible" | "container_manifest_already_exists" | "container_path_too_deep">, z.ZodUnion<readonly [z.ZodLiteral<"document_manifest_already_exists">, z.ZodLiteral<"document_sync_checkpoint_coverage_conflict" | "document_sync_conflict" | "document_sync_descendant_rekeys_required" | "document_sync_state_stale" | "document_sync_update_id_conflict">, z.ZodLiteral<"document_not_found">, z.ZodLiteral<"container_unavailable">, z.ZodLiteral<"document_link_attachments_changed">, z.ZodLiteral<"document_unlink_rotation_baseline_stale">]>]>>;
1356
1356
  error: z.ZodString;
1357
1357
  requiredContainerIds: z.ZodOptional<z.ZodCustom<string[], string[]>>;
1358
1358
  }, z.core.$loose>, z.ZodType<{
@@ -1660,7 +1660,7 @@ export declare const createContainerWithMetadataDocumentOperation: Omit<{
1660
1660
  error: string;
1661
1661
  }>>;
1662
1662
  readonly 409: z.ZodUnion<readonly [z.ZodObject<{
1663
- code: z.ZodOptional<z.ZodUnion<readonly [z.ZodLiteral<"container_mutation_state_stale" | "container_descendant_rekeys_required" | "container_ancestor_rekeys_required" | "container_descendant_rekeys_inaccessible" | "container_manifest_already_exists" | "container_path_too_deep">, z.ZodUnion<readonly [z.ZodLiteral<"document_manifest_already_exists">, z.ZodLiteral<"document_sync_checkpoint_coverage_conflict" | "document_sync_conflict" | "document_sync_descendant_rekeys_required" | "document_sync_state_stale" | "document_sync_update_id_conflict">, z.ZodLiteral<"document_not_found">, z.ZodLiteral<"container_unavailable">, z.ZodLiteral<"document_unlink_rotation_baseline_stale">]>]>>;
1663
+ code: z.ZodOptional<z.ZodUnion<readonly [z.ZodLiteral<"container_mutation_state_stale" | "container_descendant_rekeys_required" | "container_ancestor_rekeys_required" | "container_descendant_rekeys_inaccessible" | "container_manifest_already_exists" | "container_path_too_deep">, z.ZodUnion<readonly [z.ZodLiteral<"document_manifest_already_exists">, z.ZodLiteral<"document_sync_checkpoint_coverage_conflict" | "document_sync_conflict" | "document_sync_descendant_rekeys_required" | "document_sync_state_stale" | "document_sync_update_id_conflict">, z.ZodLiteral<"document_not_found">, z.ZodLiteral<"container_unavailable">, z.ZodLiteral<"document_link_attachments_changed">, z.ZodLiteral<"document_unlink_rotation_baseline_stale">]>]>>;
1664
1664
  error: z.ZodString;
1665
1665
  requiredContainerIds: z.ZodOptional<z.ZodCustom<string[], string[]>>;
1666
1666
  }, z.core.$loose>, z.ZodType<{
@@ -1948,7 +1948,7 @@ export declare const shareContainerOperation: Omit<{
1948
1948
  error: string;
1949
1949
  }>>;
1950
1950
  readonly 409: z.ZodUnion<readonly [z.ZodObject<{
1951
- code: z.ZodOptional<z.ZodUnion<readonly [z.ZodLiteral<"container_mutation_state_stale" | "container_descendant_rekeys_required" | "container_ancestor_rekeys_required" | "container_descendant_rekeys_inaccessible" | "container_manifest_already_exists" | "container_path_too_deep">, z.ZodUnion<readonly [z.ZodLiteral<"document_manifest_already_exists">, z.ZodLiteral<"document_sync_checkpoint_coverage_conflict" | "document_sync_conflict" | "document_sync_descendant_rekeys_required" | "document_sync_state_stale" | "document_sync_update_id_conflict">, z.ZodLiteral<"document_not_found">, z.ZodLiteral<"container_unavailable">, z.ZodLiteral<"document_unlink_rotation_baseline_stale">]>]>>;
1951
+ code: z.ZodOptional<z.ZodUnion<readonly [z.ZodLiteral<"container_mutation_state_stale" | "container_descendant_rekeys_required" | "container_ancestor_rekeys_required" | "container_descendant_rekeys_inaccessible" | "container_manifest_already_exists" | "container_path_too_deep">, z.ZodUnion<readonly [z.ZodLiteral<"document_manifest_already_exists">, z.ZodLiteral<"document_sync_checkpoint_coverage_conflict" | "document_sync_conflict" | "document_sync_descendant_rekeys_required" | "document_sync_state_stale" | "document_sync_update_id_conflict">, z.ZodLiteral<"document_not_found">, z.ZodLiteral<"container_unavailable">, z.ZodLiteral<"document_link_attachments_changed">, z.ZodLiteral<"document_unlink_rotation_baseline_stale">]>]>>;
1952
1952
  error: z.ZodString;
1953
1953
  requiredContainerIds: z.ZodOptional<z.ZodCustom<string[], string[]>>;
1954
1954
  }, z.core.$loose>, z.ZodType<{
@@ -2162,7 +2162,7 @@ export declare const shareContainerOperation: Omit<{
2162
2162
  error: string;
2163
2163
  }>>;
2164
2164
  readonly 409: z.ZodUnion<readonly [z.ZodObject<{
2165
- code: z.ZodOptional<z.ZodUnion<readonly [z.ZodLiteral<"container_mutation_state_stale" | "container_descendant_rekeys_required" | "container_ancestor_rekeys_required" | "container_descendant_rekeys_inaccessible" | "container_manifest_already_exists" | "container_path_too_deep">, z.ZodUnion<readonly [z.ZodLiteral<"document_manifest_already_exists">, z.ZodLiteral<"document_sync_checkpoint_coverage_conflict" | "document_sync_conflict" | "document_sync_descendant_rekeys_required" | "document_sync_state_stale" | "document_sync_update_id_conflict">, z.ZodLiteral<"document_not_found">, z.ZodLiteral<"container_unavailable">, z.ZodLiteral<"document_unlink_rotation_baseline_stale">]>]>>;
2165
+ code: z.ZodOptional<z.ZodUnion<readonly [z.ZodLiteral<"container_mutation_state_stale" | "container_descendant_rekeys_required" | "container_ancestor_rekeys_required" | "container_descendant_rekeys_inaccessible" | "container_manifest_already_exists" | "container_path_too_deep">, z.ZodUnion<readonly [z.ZodLiteral<"document_manifest_already_exists">, z.ZodLiteral<"document_sync_checkpoint_coverage_conflict" | "document_sync_conflict" | "document_sync_descendant_rekeys_required" | "document_sync_state_stale" | "document_sync_update_id_conflict">, z.ZodLiteral<"document_not_found">, z.ZodLiteral<"container_unavailable">, z.ZodLiteral<"document_link_attachments_changed">, z.ZodLiteral<"document_unlink_rotation_baseline_stale">]>]>>;
2166
2166
  error: z.ZodString;
2167
2167
  requiredContainerIds: z.ZodOptional<z.ZodCustom<string[], string[]>>;
2168
2168
  }, z.core.$loose>, z.ZodType<{
@@ -2362,7 +2362,7 @@ export declare const reciteContainerOperation: Omit<{
2362
2362
  error: string;
2363
2363
  }>>;
2364
2364
  readonly 409: z.ZodUnion<readonly [z.ZodObject<{
2365
- code: z.ZodOptional<z.ZodUnion<readonly [z.ZodLiteral<"container_mutation_state_stale" | "container_descendant_rekeys_required" | "container_ancestor_rekeys_required" | "container_descendant_rekeys_inaccessible" | "container_manifest_already_exists" | "container_path_too_deep">, z.ZodUnion<readonly [z.ZodLiteral<"document_manifest_already_exists">, z.ZodLiteral<"document_sync_checkpoint_coverage_conflict" | "document_sync_conflict" | "document_sync_descendant_rekeys_required" | "document_sync_state_stale" | "document_sync_update_id_conflict">, z.ZodLiteral<"document_not_found">, z.ZodLiteral<"container_unavailable">, z.ZodLiteral<"document_unlink_rotation_baseline_stale">]>]>>;
2365
+ code: z.ZodOptional<z.ZodUnion<readonly [z.ZodLiteral<"container_mutation_state_stale" | "container_descendant_rekeys_required" | "container_ancestor_rekeys_required" | "container_descendant_rekeys_inaccessible" | "container_manifest_already_exists" | "container_path_too_deep">, z.ZodUnion<readonly [z.ZodLiteral<"document_manifest_already_exists">, z.ZodLiteral<"document_sync_checkpoint_coverage_conflict" | "document_sync_conflict" | "document_sync_descendant_rekeys_required" | "document_sync_state_stale" | "document_sync_update_id_conflict">, z.ZodLiteral<"document_not_found">, z.ZodLiteral<"container_unavailable">, z.ZodLiteral<"document_link_attachments_changed">, z.ZodLiteral<"document_unlink_rotation_baseline_stale">]>]>>;
2366
2366
  error: z.ZodString;
2367
2367
  requiredContainerIds: z.ZodOptional<z.ZodCustom<string[], string[]>>;
2368
2368
  }, z.core.$loose>, z.ZodType<{
@@ -2540,7 +2540,7 @@ export declare const reciteContainerOperation: Omit<{
2540
2540
  error: string;
2541
2541
  }>>;
2542
2542
  readonly 409: z.ZodUnion<readonly [z.ZodObject<{
2543
- code: z.ZodOptional<z.ZodUnion<readonly [z.ZodLiteral<"container_mutation_state_stale" | "container_descendant_rekeys_required" | "container_ancestor_rekeys_required" | "container_descendant_rekeys_inaccessible" | "container_manifest_already_exists" | "container_path_too_deep">, z.ZodUnion<readonly [z.ZodLiteral<"document_manifest_already_exists">, z.ZodLiteral<"document_sync_checkpoint_coverage_conflict" | "document_sync_conflict" | "document_sync_descendant_rekeys_required" | "document_sync_state_stale" | "document_sync_update_id_conflict">, z.ZodLiteral<"document_not_found">, z.ZodLiteral<"container_unavailable">, z.ZodLiteral<"document_unlink_rotation_baseline_stale">]>]>>;
2543
+ code: z.ZodOptional<z.ZodUnion<readonly [z.ZodLiteral<"container_mutation_state_stale" | "container_descendant_rekeys_required" | "container_ancestor_rekeys_required" | "container_descendant_rekeys_inaccessible" | "container_manifest_already_exists" | "container_path_too_deep">, z.ZodUnion<readonly [z.ZodLiteral<"document_manifest_already_exists">, z.ZodLiteral<"document_sync_checkpoint_coverage_conflict" | "document_sync_conflict" | "document_sync_descendant_rekeys_required" | "document_sync_state_stale" | "document_sync_update_id_conflict">, z.ZodLiteral<"document_not_found">, z.ZodLiteral<"container_unavailable">, z.ZodLiteral<"document_link_attachments_changed">, z.ZodLiteral<"document_unlink_rotation_baseline_stale">]>]>>;
2544
2544
  error: z.ZodString;
2545
2545
  requiredContainerIds: z.ZodOptional<z.ZodCustom<string[], string[]>>;
2546
2546
  }, z.core.$loose>, z.ZodType<{
@@ -2996,7 +2996,7 @@ export declare const revokeContainerOperation: Omit<{
2996
2996
  error: string;
2997
2997
  }>>;
2998
2998
  readonly 409: z.ZodUnion<readonly [z.ZodObject<{
2999
- code: z.ZodOptional<z.ZodUnion<readonly [z.ZodLiteral<"container_mutation_state_stale" | "container_descendant_rekeys_required" | "container_ancestor_rekeys_required" | "container_descendant_rekeys_inaccessible" | "container_manifest_already_exists" | "container_path_too_deep">, z.ZodUnion<readonly [z.ZodLiteral<"document_manifest_already_exists">, z.ZodLiteral<"document_sync_checkpoint_coverage_conflict" | "document_sync_conflict" | "document_sync_descendant_rekeys_required" | "document_sync_state_stale" | "document_sync_update_id_conflict">, z.ZodLiteral<"document_not_found">, z.ZodLiteral<"container_unavailable">, z.ZodLiteral<"document_unlink_rotation_baseline_stale">]>]>>;
2999
+ code: z.ZodOptional<z.ZodUnion<readonly [z.ZodLiteral<"container_mutation_state_stale" | "container_descendant_rekeys_required" | "container_ancestor_rekeys_required" | "container_descendant_rekeys_inaccessible" | "container_manifest_already_exists" | "container_path_too_deep">, z.ZodUnion<readonly [z.ZodLiteral<"document_manifest_already_exists">, z.ZodLiteral<"document_sync_checkpoint_coverage_conflict" | "document_sync_conflict" | "document_sync_descendant_rekeys_required" | "document_sync_state_stale" | "document_sync_update_id_conflict">, z.ZodLiteral<"document_not_found">, z.ZodLiteral<"container_unavailable">, z.ZodLiteral<"document_link_attachments_changed">, z.ZodLiteral<"document_unlink_rotation_baseline_stale">]>]>>;
3000
3000
  error: z.ZodString;
3001
3001
  requiredContainerIds: z.ZodOptional<z.ZodCustom<string[], string[]>>;
3002
3002
  }, z.core.$loose>, z.ZodType<{
@@ -3294,7 +3294,7 @@ export declare const revokeContainerOperation: Omit<{
3294
3294
  error: string;
3295
3295
  }>>;
3296
3296
  readonly 409: z.ZodUnion<readonly [z.ZodObject<{
3297
- code: z.ZodOptional<z.ZodUnion<readonly [z.ZodLiteral<"container_mutation_state_stale" | "container_descendant_rekeys_required" | "container_ancestor_rekeys_required" | "container_descendant_rekeys_inaccessible" | "container_manifest_already_exists" | "container_path_too_deep">, z.ZodUnion<readonly [z.ZodLiteral<"document_manifest_already_exists">, z.ZodLiteral<"document_sync_checkpoint_coverage_conflict" | "document_sync_conflict" | "document_sync_descendant_rekeys_required" | "document_sync_state_stale" | "document_sync_update_id_conflict">, z.ZodLiteral<"document_not_found">, z.ZodLiteral<"container_unavailable">, z.ZodLiteral<"document_unlink_rotation_baseline_stale">]>]>>;
3297
+ code: z.ZodOptional<z.ZodUnion<readonly [z.ZodLiteral<"container_mutation_state_stale" | "container_descendant_rekeys_required" | "container_ancestor_rekeys_required" | "container_descendant_rekeys_inaccessible" | "container_manifest_already_exists" | "container_path_too_deep">, z.ZodUnion<readonly [z.ZodLiteral<"document_manifest_already_exists">, z.ZodLiteral<"document_sync_checkpoint_coverage_conflict" | "document_sync_conflict" | "document_sync_descendant_rekeys_required" | "document_sync_state_stale" | "document_sync_update_id_conflict">, z.ZodLiteral<"document_not_found">, z.ZodLiteral<"container_unavailable">, z.ZodLiteral<"document_link_attachments_changed">, z.ZodLiteral<"document_unlink_rotation_baseline_stale">]>]>>;
3298
3298
  error: z.ZodString;
3299
3299
  requiredContainerIds: z.ZodOptional<z.ZodCustom<string[], string[]>>;
3300
3300
  }, z.core.$loose>, z.ZodType<{
@@ -3750,7 +3750,7 @@ export declare const rekeyContainerOperation: Omit<{
3750
3750
  error: string;
3751
3751
  }>>;
3752
3752
  readonly 409: z.ZodUnion<readonly [z.ZodObject<{
3753
- code: z.ZodOptional<z.ZodUnion<readonly [z.ZodLiteral<"container_mutation_state_stale" | "container_descendant_rekeys_required" | "container_ancestor_rekeys_required" | "container_descendant_rekeys_inaccessible" | "container_manifest_already_exists" | "container_path_too_deep">, z.ZodUnion<readonly [z.ZodLiteral<"document_manifest_already_exists">, z.ZodLiteral<"document_sync_checkpoint_coverage_conflict" | "document_sync_conflict" | "document_sync_descendant_rekeys_required" | "document_sync_state_stale" | "document_sync_update_id_conflict">, z.ZodLiteral<"document_not_found">, z.ZodLiteral<"container_unavailable">, z.ZodLiteral<"document_unlink_rotation_baseline_stale">]>]>>;
3753
+ code: z.ZodOptional<z.ZodUnion<readonly [z.ZodLiteral<"container_mutation_state_stale" | "container_descendant_rekeys_required" | "container_ancestor_rekeys_required" | "container_descendant_rekeys_inaccessible" | "container_manifest_already_exists" | "container_path_too_deep">, z.ZodUnion<readonly [z.ZodLiteral<"document_manifest_already_exists">, z.ZodLiteral<"document_sync_checkpoint_coverage_conflict" | "document_sync_conflict" | "document_sync_descendant_rekeys_required" | "document_sync_state_stale" | "document_sync_update_id_conflict">, z.ZodLiteral<"document_not_found">, z.ZodLiteral<"container_unavailable">, z.ZodLiteral<"document_link_attachments_changed">, z.ZodLiteral<"document_unlink_rotation_baseline_stale">]>]>>;
3754
3754
  error: z.ZodString;
3755
3755
  requiredContainerIds: z.ZodOptional<z.ZodCustom<string[], string[]>>;
3756
3756
  }, z.core.$loose>, z.ZodType<{
@@ -4048,7 +4048,7 @@ export declare const rekeyContainerOperation: Omit<{
4048
4048
  error: string;
4049
4049
  }>>;
4050
4050
  readonly 409: z.ZodUnion<readonly [z.ZodObject<{
4051
- code: z.ZodOptional<z.ZodUnion<readonly [z.ZodLiteral<"container_mutation_state_stale" | "container_descendant_rekeys_required" | "container_ancestor_rekeys_required" | "container_descendant_rekeys_inaccessible" | "container_manifest_already_exists" | "container_path_too_deep">, z.ZodUnion<readonly [z.ZodLiteral<"document_manifest_already_exists">, z.ZodLiteral<"document_sync_checkpoint_coverage_conflict" | "document_sync_conflict" | "document_sync_descendant_rekeys_required" | "document_sync_state_stale" | "document_sync_update_id_conflict">, z.ZodLiteral<"document_not_found">, z.ZodLiteral<"container_unavailable">, z.ZodLiteral<"document_unlink_rotation_baseline_stale">]>]>>;
4051
+ code: z.ZodOptional<z.ZodUnion<readonly [z.ZodLiteral<"container_mutation_state_stale" | "container_descendant_rekeys_required" | "container_ancestor_rekeys_required" | "container_descendant_rekeys_inaccessible" | "container_manifest_already_exists" | "container_path_too_deep">, z.ZodUnion<readonly [z.ZodLiteral<"document_manifest_already_exists">, z.ZodLiteral<"document_sync_checkpoint_coverage_conflict" | "document_sync_conflict" | "document_sync_descendant_rekeys_required" | "document_sync_state_stale" | "document_sync_update_id_conflict">, z.ZodLiteral<"document_not_found">, z.ZodLiteral<"container_unavailable">, z.ZodLiteral<"document_link_attachments_changed">, z.ZodLiteral<"document_unlink_rotation_baseline_stale">]>]>>;
4052
4052
  error: z.ZodString;
4053
4053
  requiredContainerIds: z.ZodOptional<z.ZodCustom<string[], string[]>>;
4054
4054
  }, z.core.$loose>, z.ZodType<{
@@ -4504,7 +4504,7 @@ export declare const moveContainerOperation: Omit<{
4504
4504
  error: string;
4505
4505
  }>>;
4506
4506
  readonly 409: z.ZodUnion<readonly [z.ZodObject<{
4507
- code: z.ZodOptional<z.ZodUnion<readonly [z.ZodLiteral<"container_mutation_state_stale" | "container_descendant_rekeys_required" | "container_ancestor_rekeys_required" | "container_descendant_rekeys_inaccessible" | "container_manifest_already_exists" | "container_path_too_deep">, z.ZodUnion<readonly [z.ZodLiteral<"document_manifest_already_exists">, z.ZodLiteral<"document_sync_checkpoint_coverage_conflict" | "document_sync_conflict" | "document_sync_descendant_rekeys_required" | "document_sync_state_stale" | "document_sync_update_id_conflict">, z.ZodLiteral<"document_not_found">, z.ZodLiteral<"container_unavailable">, z.ZodLiteral<"document_unlink_rotation_baseline_stale">]>]>>;
4507
+ code: z.ZodOptional<z.ZodUnion<readonly [z.ZodLiteral<"container_mutation_state_stale" | "container_descendant_rekeys_required" | "container_ancestor_rekeys_required" | "container_descendant_rekeys_inaccessible" | "container_manifest_already_exists" | "container_path_too_deep">, z.ZodUnion<readonly [z.ZodLiteral<"document_manifest_already_exists">, z.ZodLiteral<"document_sync_checkpoint_coverage_conflict" | "document_sync_conflict" | "document_sync_descendant_rekeys_required" | "document_sync_state_stale" | "document_sync_update_id_conflict">, z.ZodLiteral<"document_not_found">, z.ZodLiteral<"container_unavailable">, z.ZodLiteral<"document_link_attachments_changed">, z.ZodLiteral<"document_unlink_rotation_baseline_stale">]>]>>;
4508
4508
  error: z.ZodString;
4509
4509
  requiredContainerIds: z.ZodOptional<z.ZodCustom<string[], string[]>>;
4510
4510
  }, z.core.$loose>, z.ZodType<{
@@ -4802,7 +4802,7 @@ export declare const moveContainerOperation: Omit<{
4802
4802
  error: string;
4803
4803
  }>>;
4804
4804
  readonly 409: z.ZodUnion<readonly [z.ZodObject<{
4805
- code: z.ZodOptional<z.ZodUnion<readonly [z.ZodLiteral<"container_mutation_state_stale" | "container_descendant_rekeys_required" | "container_ancestor_rekeys_required" | "container_descendant_rekeys_inaccessible" | "container_manifest_already_exists" | "container_path_too_deep">, z.ZodUnion<readonly [z.ZodLiteral<"document_manifest_already_exists">, z.ZodLiteral<"document_sync_checkpoint_coverage_conflict" | "document_sync_conflict" | "document_sync_descendant_rekeys_required" | "document_sync_state_stale" | "document_sync_update_id_conflict">, z.ZodLiteral<"document_not_found">, z.ZodLiteral<"container_unavailable">, z.ZodLiteral<"document_unlink_rotation_baseline_stale">]>]>>;
4805
+ code: z.ZodOptional<z.ZodUnion<readonly [z.ZodLiteral<"container_mutation_state_stale" | "container_descendant_rekeys_required" | "container_ancestor_rekeys_required" | "container_descendant_rekeys_inaccessible" | "container_manifest_already_exists" | "container_path_too_deep">, z.ZodUnion<readonly [z.ZodLiteral<"document_manifest_already_exists">, z.ZodLiteral<"document_sync_checkpoint_coverage_conflict" | "document_sync_conflict" | "document_sync_descendant_rekeys_required" | "document_sync_state_stale" | "document_sync_update_id_conflict">, z.ZodLiteral<"document_not_found">, z.ZodLiteral<"container_unavailable">, z.ZodLiteral<"document_link_attachments_changed">, z.ZodLiteral<"document_unlink_rotation_baseline_stale">]>]>>;
4806
4806
  error: z.ZodString;
4807
4807
  requiredContainerIds: z.ZodOptional<z.ZodCustom<string[], string[]>>;
4808
4808
  }, z.core.$loose>, z.ZodType<{
@@ -4920,7 +4920,7 @@ export declare const deleteContainerOperation: Omit<{
4920
4920
  error: string;
4921
4921
  }>>;
4922
4922
  readonly 409: z.ZodUnion<readonly [z.ZodObject<{
4923
- code: z.ZodOptional<z.ZodUnion<readonly [z.ZodLiteral<"container_mutation_state_stale" | "container_descendant_rekeys_required" | "container_ancestor_rekeys_required" | "container_descendant_rekeys_inaccessible" | "container_manifest_already_exists" | "container_path_too_deep">, z.ZodUnion<readonly [z.ZodLiteral<"document_manifest_already_exists">, z.ZodLiteral<"document_sync_checkpoint_coverage_conflict" | "document_sync_conflict" | "document_sync_descendant_rekeys_required" | "document_sync_state_stale" | "document_sync_update_id_conflict">, z.ZodLiteral<"document_not_found">, z.ZodLiteral<"container_unavailable">, z.ZodLiteral<"document_unlink_rotation_baseline_stale">]>]>>;
4923
+ code: z.ZodOptional<z.ZodUnion<readonly [z.ZodLiteral<"container_mutation_state_stale" | "container_descendant_rekeys_required" | "container_ancestor_rekeys_required" | "container_descendant_rekeys_inaccessible" | "container_manifest_already_exists" | "container_path_too_deep">, z.ZodUnion<readonly [z.ZodLiteral<"document_manifest_already_exists">, z.ZodLiteral<"document_sync_checkpoint_coverage_conflict" | "document_sync_conflict" | "document_sync_descendant_rekeys_required" | "document_sync_state_stale" | "document_sync_update_id_conflict">, z.ZodLiteral<"document_not_found">, z.ZodLiteral<"container_unavailable">, z.ZodLiteral<"document_link_attachments_changed">, z.ZodLiteral<"document_unlink_rotation_baseline_stale">]>]>>;
4924
4924
  error: z.ZodString;
4925
4925
  requiredContainerIds: z.ZodOptional<z.ZodCustom<string[], string[]>>;
4926
4926
  }, z.core.$loose>, z.ZodType<{
@@ -5060,7 +5060,7 @@ export declare const deleteContainerOperation: Omit<{
5060
5060
  error: string;
5061
5061
  }>>;
5062
5062
  readonly 409: z.ZodUnion<readonly [z.ZodObject<{
5063
- code: z.ZodOptional<z.ZodUnion<readonly [z.ZodLiteral<"container_mutation_state_stale" | "container_descendant_rekeys_required" | "container_ancestor_rekeys_required" | "container_descendant_rekeys_inaccessible" | "container_manifest_already_exists" | "container_path_too_deep">, z.ZodUnion<readonly [z.ZodLiteral<"document_manifest_already_exists">, z.ZodLiteral<"document_sync_checkpoint_coverage_conflict" | "document_sync_conflict" | "document_sync_descendant_rekeys_required" | "document_sync_state_stale" | "document_sync_update_id_conflict">, z.ZodLiteral<"document_not_found">, z.ZodLiteral<"container_unavailable">, z.ZodLiteral<"document_unlink_rotation_baseline_stale">]>]>>;
5063
+ code: z.ZodOptional<z.ZodUnion<readonly [z.ZodLiteral<"container_mutation_state_stale" | "container_descendant_rekeys_required" | "container_ancestor_rekeys_required" | "container_descendant_rekeys_inaccessible" | "container_manifest_already_exists" | "container_path_too_deep">, z.ZodUnion<readonly [z.ZodLiteral<"document_manifest_already_exists">, z.ZodLiteral<"document_sync_checkpoint_coverage_conflict" | "document_sync_conflict" | "document_sync_descendant_rekeys_required" | "document_sync_state_stale" | "document_sync_update_id_conflict">, z.ZodLiteral<"document_not_found">, z.ZodLiteral<"container_unavailable">, z.ZodLiteral<"document_link_attachments_changed">, z.ZodLiteral<"document_unlink_rotation_baseline_stale">]>]>>;
5064
5064
  error: z.ZodString;
5065
5065
  requiredContainerIds: z.ZodOptional<z.ZodCustom<string[], string[]>>;
5066
5066
  }, z.core.$loose>, z.ZodType<{