@tearleads/client-sdk 0.1.42 → 0.1.43

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 (161) hide show
  1. package/data/blobs/transferPool.js +35 -8
  2. package/data/blobs/transferPool.js.map +1 -1
  3. package/data/containers/shared/projection.js +12 -0
  4. package/data/containers/shared/projection.js.map +1 -1
  5. package/data/documents/blob/shared/types.d.ts +2 -3
  6. package/data/documents/blob/shared/types.js.map +1 -1
  7. package/data/documents/shared/events.js +0 -1
  8. package/data/documents/shared/events.js.map +1 -1
  9. package/data/persistence/container-contents/containerContentsPersistence.js +6 -22
  10. package/data/persistence/container-contents/containerContentsPersistence.js.map +1 -1
  11. package/data/persistence/container-contents/containerMetadataMutationPersistence.js +5 -15
  12. package/data/persistence/container-contents/containerMetadataMutationPersistence.js.map +1 -1
  13. package/data/persistence/container-contents/containerPendingUpdatePersistence.js +6 -15
  14. package/data/persistence/container-contents/containerPendingUpdatePersistence.js.map +1 -1
  15. package/data/persistence/container-contents/containerRecoveryPersistence.js +3 -4
  16. package/data/persistence/container-contents/containerRecoveryPersistence.js.map +1 -1
  17. package/data/persistence/container-contents/containerRemovalWork.js +3 -5
  18. package/data/persistence/container-contents/containerRemovalWork.js.map +1 -1
  19. package/data/persistence/container-contents/dormantContainerMetadata.js +1 -5
  20. package/data/persistence/container-contents/dormantContainerMetadata.js.map +1 -1
  21. package/data/persistence/documents/documentsPersistence.js +4 -9
  22. package/data/persistence/documents/documentsPersistence.js.map +1 -1
  23. package/data/persistence/documents/internal/discardDocument.js +1 -2
  24. package/data/persistence/documents/internal/discardDocument.js.map +1 -1
  25. package/data/persistence/documents/internal/documentDeletionPersistence.js +1 -2
  26. package/data/persistence/documents/internal/documentDeletionPersistence.js.map +1 -1
  27. package/data/persistence/documents/internal/documentMutationPersistence.js +17 -25
  28. package/data/persistence/documents/internal/documentMutationPersistence.js.map +1 -1
  29. package/data/persistence/documents/internal/orphanSideRows.js +2 -14
  30. package/data/persistence/documents/internal/orphanSideRows.js.map +1 -1
  31. package/data/persistence/documents/internal/syncQueuePersistence.js +3 -3
  32. package/data/persistence/documents/internal/syncQueuePersistence.js.map +1 -1
  33. package/data/sqlite/documentHistoryPersistence.d.ts +9 -3
  34. package/data/sqlite/documentHistoryPersistence.js +31 -8
  35. package/data/sqlite/documentHistoryPersistence.js.map +1 -1
  36. package/data/sqlite/documentPendingUpdatePersistence.d.ts +58 -11
  37. package/data/sqlite/documentPendingUpdatePersistence.js +137 -63
  38. package/data/sqlite/documentPendingUpdatePersistence.js.map +1 -1
  39. package/data/sqlite/documentPersistence.d.ts +1 -1
  40. package/data/sqlite/documentPersistence.js +1 -1
  41. package/data/sqlite/documentPersistence.js.map +1 -1
  42. package/data/sqlite/documentPersistenceTypes.d.ts +2 -2
  43. package/data/sqlite/documentPersistenceTypes.js.map +1 -1
  44. package/data/sqlite/documentRecordPersistence.js +5 -4
  45. package/data/sqlite/documentRecordPersistence.js.map +1 -1
  46. package/data/sqlite/schema.d.ts +127 -377
  47. package/data/sqlite/schema.js +46 -47
  48. package/data/sqlite/schema.js.map +1 -1
  49. package/internal/api-client/ApiClient.d.ts +13 -8
  50. package/internal/api-client/ApiClient.js +2 -5
  51. package/internal/api-client/ApiClient.js.map +1 -1
  52. package/internal/api-client/binaryRequestOperationTransport.d.ts +18 -0
  53. package/internal/api-client/index.d.ts +1 -0
  54. package/internal/api-client/index.js +1 -0
  55. package/internal/api-client/index.js.map +1 -1
  56. package/internal/api-client/operationTransportFactory.d.ts +6 -0
  57. package/internal/api-client/routes/blobs/get.d.ts +7 -0
  58. package/internal/api-client/routes/blobs/get.js.map +1 -1
  59. package/internal/api-client/routes/blobs/multipart.js +1 -11
  60. package/internal/api-client/routes/blobs/multipart.js.map +1 -1
  61. package/internal/api-client/routes/blobs/multipartUpload.d.ts +14 -0
  62. package/internal/api-client/routes/blobs/multipartUpload.js +94 -43
  63. package/internal/api-client/routes/blobs/multipartUpload.js.map +1 -1
  64. package/internal/validators/operation/attachments.d.ts +80 -160
  65. package/internal/validators/operation/auth.d.ts +760 -1664
  66. package/internal/validators/operation/blobDownloads.js +1 -1
  67. package/internal/validators/operation/blobDownloads.js.map +1 -1
  68. package/internal/validators/operation/containerMutations.d.ts +416 -856
  69. package/internal/validators/operation/documentMutations.d.ts +120 -264
  70. package/internal/validators/operation/documentSync.d.ts +40 -80
  71. package/internal/validators/operation/index.d.ts +1 -1
  72. package/internal/validators/operation/index.js +1 -1
  73. package/internal/validators/operation/index.js.map +1 -1
  74. package/internal/validators/operation/multipartBlobs.d.ts +70 -190
  75. package/internal/validators/operation/multipartBlobs.js +2 -24
  76. package/internal/validators/operation/multipartBlobs.js.map +1 -1
  77. package/internal/validators/operation/multipartPartUploads.d.ts +5 -5
  78. package/internal/validators/operation/multipartPartUploads.js +6 -20
  79. package/internal/validators/operation/multipartPartUploads.js.map +1 -1
  80. package/internal/validators/operation/organizations.d.ts +882 -1906
  81. package/internal/validators/operation/principals.d.ts +120 -240
  82. package/internal/validators/operation/registry.d.ts +1 -2
  83. package/internal/validators/operation/registry.js +1 -2
  84. package/internal/validators/operation/registry.js.map +1 -1
  85. package/internal/validators/request/blob.d.ts +100 -201
  86. package/internal/validators/request/blob.js +6 -13
  87. package/internal/validators/request/blob.js.map +1 -1
  88. package/internal/validators/request/container.d.ts +136 -272
  89. package/internal/validators/request/container.js +16 -10
  90. package/internal/validators/request/container.js.map +1 -1
  91. package/internal/validators/request/containerManifestRef.d.ts +54 -0
  92. package/internal/validators/request/containerManifestRef.js +28 -0
  93. package/internal/validators/request/containerManifestRef.js.map +1 -0
  94. package/internal/validators/request/containerMetadata.d.ts +160 -368
  95. package/internal/validators/request/document.d.ts +100 -245
  96. package/internal/validators/request/document.js +1 -2
  97. package/internal/validators/request/document.js.map +1 -1
  98. package/internal/validators/request/documentSyncSchema.d.ts +42 -109
  99. package/internal/validators/request/documentSyncSchema.js +8 -25
  100. package/internal/validators/request/documentSyncSchema.js.map +1 -1
  101. package/internal/validators/request/index.d.ts +1 -1
  102. package/internal/validators/request/index.js +1 -1
  103. package/internal/validators/request/index.js.map +1 -1
  104. package/internal/validators/request/organization.d.ts +160 -320
  105. package/internal/validators/request/organizationProvisioning.d.ts +2424 -5312
  106. package/internal/validators/request/principal.d.ts +160 -320
  107. package/internal/validators/request/registration.d.ts +760 -1664
  108. package/internal/validators/response/blob.d.ts +48 -27
  109. package/internal/validators/response/blob.js +3 -10
  110. package/internal/validators/response/blob.js.map +1 -1
  111. package/internal/validators/response/index.d.ts +1 -1
  112. package/internal/validators/response/index.js +1 -1
  113. package/internal/validators/response/index.js.map +1 -1
  114. package/internal/validators/util/blob.d.ts +7 -0
  115. package/internal/validators/util/blob.js +7 -0
  116. package/internal/validators/util/blob.js.map +1 -1
  117. package/internal/validators/util/blobTransferSchemas.d.ts +41 -0
  118. package/internal/validators/util/blobTransferSchemas.js +39 -0
  119. package/internal/validators/util/blobTransferSchemas.js.map +1 -0
  120. package/internal/validators/util/containerLimits.d.ts +7 -0
  121. package/internal/validators/util/containerLimits.js +7 -0
  122. package/internal/validators/util/containerLimits.js.map +1 -1
  123. package/internal/validators/util/index.d.ts +2 -1
  124. package/internal/validators/util/index.js +2 -1
  125. package/internal/validators/util/index.js.map +1 -1
  126. package/package.json +1 -1
  127. package/workflows/blobs/multipartFirstParts.js +82 -0
  128. package/workflows/blobs/multipartFirstParts.js.map +1 -0
  129. package/workflows/blobs/multipartStageResolution.js +83 -0
  130. package/workflows/blobs/multipartStageResolution.js.map +1 -0
  131. package/workflows/blobs/multipartUpload.js +45 -89
  132. package/workflows/blobs/multipartUpload.js.map +1 -1
  133. package/workflows/container-contents/documentPriming.js +2 -1
  134. package/workflows/container-contents/documentPriming.js.map +1 -1
  135. package/workflows/container-contents/documentQueries/sql.js +4 -4
  136. package/workflows/container-contents/documentQueries/sql.js.map +1 -1
  137. package/workflows/container-contents/pendingWrites/deferredTails.js +6 -3
  138. package/workflows/container-contents/pendingWrites/deferredTails.js.map +1 -1
  139. package/workflows/container-contents/pendingWrites/sources.js +2 -1
  140. package/workflows/container-contents/pendingWrites/sources.js.map +1 -1
  141. package/workflows/container-contents/pendingWrites.js +2 -1
  142. package/workflows/container-contents/pendingWrites.js.map +1 -1
  143. package/workflows/containers/child/create.js +3 -3
  144. package/workflows/containers/child/create.js.map +1 -1
  145. package/workflows/containers/child/move.js +2 -2
  146. package/workflows/containers/child/move.js.map +1 -1
  147. package/workflows/containers/child/mutationRequestCore.js +5 -4
  148. package/workflows/containers/child/mutationRequestCore.js.map +1 -1
  149. package/workflows/containers/child/recitePlan.js +3 -2
  150. package/workflows/containers/child/recitePlan.js.map +1 -1
  151. package/workflows/containers/child/sharePlanCore.js +2 -2
  152. package/workflows/containers/child/sharePlanCore.js.map +1 -1
  153. package/workflows/containers/root/create.js +2 -2
  154. package/workflows/containers/root/create.js.map +1 -1
  155. package/workflows/registration/provisioningBootstrapBuilders.d.ts +20 -46
  156. package/workflows/sync/remoteReset.js +9 -9
  157. package/workflows/sync/remoteReset.js.map +1 -1
  158. package/workflows/sync/remoteResetPlans.js +6 -3
  159. package/workflows/sync/remoteResetPlans.js.map +1 -1
  160. package/internal/validators/operation/blobTransferSchemas.js +0 -11
  161. package/internal/validators/operation/blobTransferSchemas.js.map +0 -1
@@ -358,210 +358,11 @@ export declare const documents: import("drizzle-orm/sqlite-core").SQLiteTableWit
358
358
  };
359
359
  dialect: "sqlite";
360
360
  }>;
361
- /**
362
- * Outbound Loro updates waiting to be accepted by sync.
363
- *
364
- * Each row stores one locally produced update for a document scope. The queue is
365
- * replayed in creation order and acknowledged rows are deleted after sync
366
- * writes the corresponding server commit or persisted document state.
367
- *
368
- * Columns:
369
- * - `id`: Client-generated queue id used for acknowledgement deletes.
370
- * - `appKind`: Local document namespace matching `documents.appKind`.
371
- * - `localId`: Local document id matching `documents.localId`.
372
- * - `updateData`: Serialized Loro update payload.
373
- * - `partialStartVersionVector`: Version vector before this partial update.
374
- * - `partialEndVersionVector`: Version vector after this partial update.
375
- * - `sourceVersionVector`: Optional source vector used to avoid re-enqueuing
376
- * updates that came from sync.
377
- * - `createdAt`: Queue insertion timestamp used for deterministic replay.
378
- *
379
- * Indexes:
380
- * - `id` is the primary key for targeted deletes.
381
- * - `(appKind, localId, createdAt)` supports ordered pending-update scans for a
382
- * document scope.
383
- */
384
- export declare const documentPendingUpdates: import("drizzle-orm/sqlite-core").SQLiteTableWithColumns<{
385
- name: "document_pending_updates";
386
- schema: undefined;
387
- columns: {
388
- id: import("drizzle-orm/sqlite-core").SQLiteColumn<{
389
- name: "id";
390
- tableName: "document_pending_updates";
391
- dataType: "string";
392
- columnType: "SQLiteText";
393
- data: string;
394
- driverParam: string;
395
- notNull: false;
396
- hasDefault: false;
397
- isPrimaryKey: false;
398
- isAutoincrement: false;
399
- hasRuntimeDefault: false;
400
- enumValues: [string, ...string[]];
401
- baseColumn: never;
402
- identity: undefined;
403
- generated: undefined;
404
- }, {}, {
405
- length: number | undefined;
406
- }>;
407
- appKind: import("drizzle-orm/sqlite-core").SQLiteColumn<{
408
- name: "app_kind";
409
- tableName: "document_pending_updates";
410
- dataType: "string";
411
- columnType: "SQLiteText";
412
- data: string;
413
- driverParam: string;
414
- notNull: true;
415
- hasDefault: false;
416
- isPrimaryKey: false;
417
- isAutoincrement: false;
418
- hasRuntimeDefault: false;
419
- enumValues: [string, ...string[]];
420
- baseColumn: never;
421
- identity: undefined;
422
- generated: undefined;
423
- }, {}, {
424
- length: number | undefined;
425
- }>;
426
- localId: import("drizzle-orm/sqlite-core").SQLiteColumn<{
427
- name: "local_id";
428
- tableName: "document_pending_updates";
429
- dataType: "string";
430
- columnType: "SQLiteText";
431
- data: string;
432
- driverParam: string;
433
- notNull: true;
434
- hasDefault: false;
435
- isPrimaryKey: false;
436
- isAutoincrement: false;
437
- hasRuntimeDefault: false;
438
- enumValues: [string, ...string[]];
439
- baseColumn: never;
440
- identity: undefined;
441
- generated: undefined;
442
- }, {}, {
443
- length: number | undefined;
444
- }>;
445
- updateData: import("drizzle-orm/sqlite-core").SQLiteColumn<{
446
- name: "update_data";
447
- tableName: "document_pending_updates";
448
- dataType: "string";
449
- columnType: "SQLiteText";
450
- data: string;
451
- driverParam: string;
452
- notNull: true;
453
- hasDefault: false;
454
- isPrimaryKey: false;
455
- isAutoincrement: false;
456
- hasRuntimeDefault: false;
457
- enumValues: [string, ...string[]];
458
- baseColumn: never;
459
- identity: undefined;
460
- generated: undefined;
461
- }, {}, {
462
- length: number | undefined;
463
- }>;
464
- partialStartVersionVector: import("drizzle-orm/sqlite-core").SQLiteColumn<{
465
- name: "partial_start_version_vector";
466
- tableName: "document_pending_updates";
467
- dataType: "string";
468
- columnType: "SQLiteText";
469
- data: string;
470
- driverParam: string;
471
- notNull: true;
472
- hasDefault: false;
473
- isPrimaryKey: false;
474
- isAutoincrement: false;
475
- hasRuntimeDefault: false;
476
- enumValues: [string, ...string[]];
477
- baseColumn: never;
478
- identity: undefined;
479
- generated: undefined;
480
- }, {}, {
481
- length: number | undefined;
482
- }>;
483
- partialEndVersionVector: import("drizzle-orm/sqlite-core").SQLiteColumn<{
484
- name: "partial_end_version_vector";
485
- tableName: "document_pending_updates";
486
- dataType: "string";
487
- columnType: "SQLiteText";
488
- data: string;
489
- driverParam: string;
490
- notNull: true;
491
- hasDefault: false;
492
- isPrimaryKey: false;
493
- isAutoincrement: false;
494
- hasRuntimeDefault: false;
495
- enumValues: [string, ...string[]];
496
- baseColumn: never;
497
- identity: undefined;
498
- generated: undefined;
499
- }, {}, {
500
- length: number | undefined;
501
- }>;
502
- sourceVersionVector: import("drizzle-orm/sqlite-core").SQLiteColumn<{
503
- name: "source_version_vector";
504
- tableName: "document_pending_updates";
505
- dataType: "string";
506
- columnType: "SQLiteText";
507
- data: string;
508
- driverParam: string;
509
- notNull: false;
510
- hasDefault: false;
511
- isPrimaryKey: false;
512
- isAutoincrement: false;
513
- hasRuntimeDefault: false;
514
- enumValues: [string, ...string[]];
515
- baseColumn: never;
516
- identity: undefined;
517
- generated: undefined;
518
- }, {}, {
519
- length: number | undefined;
520
- }>;
521
- createdAt: import("drizzle-orm/sqlite-core").SQLiteColumn<{
522
- name: "created_at";
523
- tableName: "document_pending_updates";
524
- dataType: "string";
525
- columnType: "SQLiteText";
526
- data: string;
527
- driverParam: string;
528
- notNull: true;
529
- hasDefault: false;
530
- isPrimaryKey: false;
531
- isAutoincrement: false;
532
- hasRuntimeDefault: false;
533
- enumValues: [string, ...string[]];
534
- baseColumn: never;
535
- identity: undefined;
536
- generated: undefined;
537
- }, {}, {
538
- length: number | undefined;
539
- }>;
540
- rekeyCount: import("drizzle-orm/sqlite-core").SQLiteColumn<{
541
- name: "rekey_count";
542
- tableName: "document_pending_updates";
543
- dataType: "number";
544
- columnType: "SQLiteInteger";
545
- data: number;
546
- driverParam: number;
547
- notNull: true;
548
- hasDefault: true;
549
- isPrimaryKey: false;
550
- isAutoincrement: false;
551
- hasRuntimeDefault: false;
552
- enumValues: undefined;
553
- baseColumn: never;
554
- identity: undefined;
555
- generated: undefined;
556
- }, {}, {}>;
557
- };
558
- dialect: "sqlite";
559
- }>;
560
361
  /**
561
362
  * Last terminal sync failure or quarantined incoming update per document scope.
562
363
  *
563
- * The durable write queue (`documentPendingUpdates`) has no status columns — a
564
- * row is either pending or settled-and-deleted. Terminal submissions and
364
+ * The durable write queue (queued rows of `documentHistoryUpdates`) has no
365
+ * status columns — a row is either queued or settled. Terminal submissions and
565
366
  * incoming updates that cannot be decrypted or imported are recorded here so
566
367
  * the write-queue view and footer can surface why the document is blocked.
567
368
  * Rows are upserted per scope and deleted only after a later fully validated
@@ -809,6 +610,38 @@ export declare const documentHistoryCheckpoints: import("drizzle-orm/sqlite-core
809
610
  };
810
611
  dialect: "sqlite";
811
612
  }>;
613
+ /**
614
+ * The local update log: one row per Loro update, serving as both the history
615
+ * tail (restore = checkpoint + tail) and the outbound write queue.
616
+ *
617
+ * Every locally authored update is stored once. While it waits for sync it
618
+ * carries an `updateId` (the id submitted to the server) and the version-vector
619
+ * metadata the submission needs; settlement clears them, leaving the row as
620
+ * ordinary tail history until compaction folds it into a checkpoint.
621
+ *
622
+ * Columns:
623
+ * - `id`: Row id; tail compaction deletes by it.
624
+ * - `appKind`, `localId`: Document scope matching `documents`.
625
+ * - `updateData`: Serialized Loro update payload.
626
+ * - `origin`: "local" (authored on this device) or "remote" (decrypted
627
+ * pulled update) for tail rows. Restores use it to advance the
628
+ * outgoing-delta marker across remote rows — their ops are already
629
+ * server-side — while a local row left behind by a crash stays below the
630
+ * marker so the next edit re-derives and sends it. "outbox" marks a queued
631
+ * update with no tail role (container metadata, whose content is its
632
+ * checkpoint, and full-state re-uploads after a remote reset); restores and
633
+ * compaction never see it and settlement deletes it.
634
+ * - `createdAt`: Insertion timestamp; with `rowid`, deterministic replay order.
635
+ * - `updateId`: Present exactly while the row is queued for sync; rekeyed
636
+ * after a lost acknowledgement poisons the submitted id.
637
+ * - `partialStartVersionVector` / `partialEndVersionVector`: Version vectors
638
+ * around a queued partial update.
639
+ * - `sourceVersionVector`: Present on a queued rotation baseline checkpoint.
640
+ * - `rekeyCount`: Durable bound on rekeys of a queued row.
641
+ *
642
+ * Invariant: compaction never deletes a queued row, so a checkpoint can cover
643
+ * a queued update's operations without removing it from the queue.
644
+ */
812
645
  export declare const documentHistoryUpdates: import("drizzle-orm/sqlite-core").SQLiteTableWithColumns<{
813
646
  name: "document_history_updates";
814
647
  schema: undefined;
@@ -927,6 +760,99 @@ export declare const documentHistoryUpdates: import("drizzle-orm/sqlite-core").S
927
760
  }, {}, {
928
761
  length: number | undefined;
929
762
  }>;
763
+ updateId: import("drizzle-orm/sqlite-core").SQLiteColumn<{
764
+ name: "update_id";
765
+ tableName: "document_history_updates";
766
+ dataType: "string";
767
+ columnType: "SQLiteText";
768
+ data: string;
769
+ driverParam: string;
770
+ notNull: false;
771
+ hasDefault: false;
772
+ isPrimaryKey: false;
773
+ isAutoincrement: false;
774
+ hasRuntimeDefault: false;
775
+ enumValues: [string, ...string[]];
776
+ baseColumn: never;
777
+ identity: undefined;
778
+ generated: undefined;
779
+ }, {}, {
780
+ length: number | undefined;
781
+ }>;
782
+ partialStartVersionVector: import("drizzle-orm/sqlite-core").SQLiteColumn<{
783
+ name: "partial_start_version_vector";
784
+ tableName: "document_history_updates";
785
+ dataType: "string";
786
+ columnType: "SQLiteText";
787
+ data: string;
788
+ driverParam: string;
789
+ notNull: false;
790
+ hasDefault: false;
791
+ isPrimaryKey: false;
792
+ isAutoincrement: false;
793
+ hasRuntimeDefault: false;
794
+ enumValues: [string, ...string[]];
795
+ baseColumn: never;
796
+ identity: undefined;
797
+ generated: undefined;
798
+ }, {}, {
799
+ length: number | undefined;
800
+ }>;
801
+ partialEndVersionVector: import("drizzle-orm/sqlite-core").SQLiteColumn<{
802
+ name: "partial_end_version_vector";
803
+ tableName: "document_history_updates";
804
+ dataType: "string";
805
+ columnType: "SQLiteText";
806
+ data: string;
807
+ driverParam: string;
808
+ notNull: false;
809
+ hasDefault: false;
810
+ isPrimaryKey: false;
811
+ isAutoincrement: false;
812
+ hasRuntimeDefault: false;
813
+ enumValues: [string, ...string[]];
814
+ baseColumn: never;
815
+ identity: undefined;
816
+ generated: undefined;
817
+ }, {}, {
818
+ length: number | undefined;
819
+ }>;
820
+ sourceVersionVector: import("drizzle-orm/sqlite-core").SQLiteColumn<{
821
+ name: "source_version_vector";
822
+ tableName: "document_history_updates";
823
+ dataType: "string";
824
+ columnType: "SQLiteText";
825
+ data: string;
826
+ driverParam: string;
827
+ notNull: false;
828
+ hasDefault: false;
829
+ isPrimaryKey: false;
830
+ isAutoincrement: false;
831
+ hasRuntimeDefault: false;
832
+ enumValues: [string, ...string[]];
833
+ baseColumn: never;
834
+ identity: undefined;
835
+ generated: undefined;
836
+ }, {}, {
837
+ length: number | undefined;
838
+ }>;
839
+ rekeyCount: import("drizzle-orm/sqlite-core").SQLiteColumn<{
840
+ name: "rekey_count";
841
+ tableName: "document_history_updates";
842
+ dataType: "number";
843
+ columnType: "SQLiteInteger";
844
+ data: number;
845
+ driverParam: number;
846
+ notNull: true;
847
+ hasDefault: true;
848
+ isPrimaryKey: false;
849
+ isAutoincrement: false;
850
+ hasRuntimeDefault: false;
851
+ enumValues: undefined;
852
+ baseColumn: never;
853
+ identity: undefined;
854
+ generated: undefined;
855
+ }, {}, {}>;
930
856
  };
931
857
  dialect: "sqlite";
932
858
  }>;
@@ -7793,182 +7719,6 @@ export declare const clientSQLiteSchema: {
7793
7719
  };
7794
7720
  dialect: "sqlite";
7795
7721
  }>;
7796
- documentPendingUpdates: import("drizzle-orm/sqlite-core").SQLiteTableWithColumns<{
7797
- name: "document_pending_updates";
7798
- schema: undefined;
7799
- columns: {
7800
- id: import("drizzle-orm/sqlite-core").SQLiteColumn<{
7801
- name: "id";
7802
- tableName: "document_pending_updates";
7803
- dataType: "string";
7804
- columnType: "SQLiteText";
7805
- data: string;
7806
- driverParam: string;
7807
- notNull: false;
7808
- hasDefault: false;
7809
- isPrimaryKey: false;
7810
- isAutoincrement: false;
7811
- hasRuntimeDefault: false;
7812
- enumValues: [string, ...string[]];
7813
- baseColumn: never;
7814
- identity: undefined;
7815
- generated: undefined;
7816
- }, {}, {
7817
- length: number | undefined;
7818
- }>;
7819
- appKind: import("drizzle-orm/sqlite-core").SQLiteColumn<{
7820
- name: "app_kind";
7821
- tableName: "document_pending_updates";
7822
- dataType: "string";
7823
- columnType: "SQLiteText";
7824
- data: string;
7825
- driverParam: string;
7826
- notNull: true;
7827
- hasDefault: false;
7828
- isPrimaryKey: false;
7829
- isAutoincrement: false;
7830
- hasRuntimeDefault: false;
7831
- enumValues: [string, ...string[]];
7832
- baseColumn: never;
7833
- identity: undefined;
7834
- generated: undefined;
7835
- }, {}, {
7836
- length: number | undefined;
7837
- }>;
7838
- localId: import("drizzle-orm/sqlite-core").SQLiteColumn<{
7839
- name: "local_id";
7840
- tableName: "document_pending_updates";
7841
- dataType: "string";
7842
- columnType: "SQLiteText";
7843
- data: string;
7844
- driverParam: string;
7845
- notNull: true;
7846
- hasDefault: false;
7847
- isPrimaryKey: false;
7848
- isAutoincrement: false;
7849
- hasRuntimeDefault: false;
7850
- enumValues: [string, ...string[]];
7851
- baseColumn: never;
7852
- identity: undefined;
7853
- generated: undefined;
7854
- }, {}, {
7855
- length: number | undefined;
7856
- }>;
7857
- updateData: import("drizzle-orm/sqlite-core").SQLiteColumn<{
7858
- name: "update_data";
7859
- tableName: "document_pending_updates";
7860
- dataType: "string";
7861
- columnType: "SQLiteText";
7862
- data: string;
7863
- driverParam: string;
7864
- notNull: true;
7865
- hasDefault: false;
7866
- isPrimaryKey: false;
7867
- isAutoincrement: false;
7868
- hasRuntimeDefault: false;
7869
- enumValues: [string, ...string[]];
7870
- baseColumn: never;
7871
- identity: undefined;
7872
- generated: undefined;
7873
- }, {}, {
7874
- length: number | undefined;
7875
- }>;
7876
- partialStartVersionVector: import("drizzle-orm/sqlite-core").SQLiteColumn<{
7877
- name: "partial_start_version_vector";
7878
- tableName: "document_pending_updates";
7879
- dataType: "string";
7880
- columnType: "SQLiteText";
7881
- data: string;
7882
- driverParam: string;
7883
- notNull: true;
7884
- hasDefault: false;
7885
- isPrimaryKey: false;
7886
- isAutoincrement: false;
7887
- hasRuntimeDefault: false;
7888
- enumValues: [string, ...string[]];
7889
- baseColumn: never;
7890
- identity: undefined;
7891
- generated: undefined;
7892
- }, {}, {
7893
- length: number | undefined;
7894
- }>;
7895
- partialEndVersionVector: import("drizzle-orm/sqlite-core").SQLiteColumn<{
7896
- name: "partial_end_version_vector";
7897
- tableName: "document_pending_updates";
7898
- dataType: "string";
7899
- columnType: "SQLiteText";
7900
- data: string;
7901
- driverParam: string;
7902
- notNull: true;
7903
- hasDefault: false;
7904
- isPrimaryKey: false;
7905
- isAutoincrement: false;
7906
- hasRuntimeDefault: false;
7907
- enumValues: [string, ...string[]];
7908
- baseColumn: never;
7909
- identity: undefined;
7910
- generated: undefined;
7911
- }, {}, {
7912
- length: number | undefined;
7913
- }>;
7914
- sourceVersionVector: import("drizzle-orm/sqlite-core").SQLiteColumn<{
7915
- name: "source_version_vector";
7916
- tableName: "document_pending_updates";
7917
- dataType: "string";
7918
- columnType: "SQLiteText";
7919
- data: string;
7920
- driverParam: string;
7921
- notNull: false;
7922
- hasDefault: false;
7923
- isPrimaryKey: false;
7924
- isAutoincrement: false;
7925
- hasRuntimeDefault: false;
7926
- enumValues: [string, ...string[]];
7927
- baseColumn: never;
7928
- identity: undefined;
7929
- generated: undefined;
7930
- }, {}, {
7931
- length: number | undefined;
7932
- }>;
7933
- createdAt: import("drizzle-orm/sqlite-core").SQLiteColumn<{
7934
- name: "created_at";
7935
- tableName: "document_pending_updates";
7936
- dataType: "string";
7937
- columnType: "SQLiteText";
7938
- data: string;
7939
- driverParam: string;
7940
- notNull: true;
7941
- hasDefault: false;
7942
- isPrimaryKey: false;
7943
- isAutoincrement: false;
7944
- hasRuntimeDefault: false;
7945
- enumValues: [string, ...string[]];
7946
- baseColumn: never;
7947
- identity: undefined;
7948
- generated: undefined;
7949
- }, {}, {
7950
- length: number | undefined;
7951
- }>;
7952
- rekeyCount: import("drizzle-orm/sqlite-core").SQLiteColumn<{
7953
- name: "rekey_count";
7954
- tableName: "document_pending_updates";
7955
- dataType: "number";
7956
- columnType: "SQLiteInteger";
7957
- data: number;
7958
- driverParam: number;
7959
- notNull: true;
7960
- hasDefault: true;
7961
- isPrimaryKey: false;
7962
- isAutoincrement: false;
7963
- hasRuntimeDefault: false;
7964
- enumValues: undefined;
7965
- baseColumn: never;
7966
- identity: undefined;
7967
- generated: undefined;
7968
- }, {}, {}>;
7969
- };
7970
- dialect: "sqlite";
7971
- }>;
7972
7722
  documentSyncFailures: import("drizzle-orm/sqlite-core").SQLiteTableWithColumns<{
7973
7723
  name: "document_sync_failures";
7974
7724
  schema: undefined;
@@ -94,48 +94,11 @@ export const documents = sqliteTable("documents", {
94
94
  .on(table.appKind, table.documentId)
95
95
  .where(sql `${table.documentId} IS NOT NULL`),
96
96
  ]);
97
- /**
98
- * Outbound Loro updates waiting to be accepted by sync.
99
- *
100
- * Each row stores one locally produced update for a document scope. The queue is
101
- * replayed in creation order and acknowledged rows are deleted after sync
102
- * writes the corresponding server commit or persisted document state.
103
- *
104
- * Columns:
105
- * - `id`: Client-generated queue id used for acknowledgement deletes.
106
- * - `appKind`: Local document namespace matching `documents.appKind`.
107
- * - `localId`: Local document id matching `documents.localId`.
108
- * - `updateData`: Serialized Loro update payload.
109
- * - `partialStartVersionVector`: Version vector before this partial update.
110
- * - `partialEndVersionVector`: Version vector after this partial update.
111
- * - `sourceVersionVector`: Optional source vector used to avoid re-enqueuing
112
- * updates that came from sync.
113
- * - `createdAt`: Queue insertion timestamp used for deterministic replay.
114
- *
115
- * Indexes:
116
- * - `id` is the primary key for targeted deletes.
117
- * - `(appKind, localId, createdAt)` supports ordered pending-update scans for a
118
- * document scope.
119
- */
120
- export const documentPendingUpdates = sqliteTable("document_pending_updates", {
121
- id: text("id"),
122
- appKind: text("app_kind").notNull(),
123
- localId: text("local_id").notNull(),
124
- updateData: text("update_data").notNull(),
125
- partialStartVersionVector: text("partial_start_version_vector").notNull(),
126
- partialEndVersionVector: text("partial_end_version_vector").notNull(),
127
- sourceVersionVector: text("source_version_vector"),
128
- createdAt: text("created_at").notNull(),
129
- rekeyCount: integer("rekey_count").notNull().default(0),
130
- }, (table) => [
131
- primaryKey({ columns: [table.id] }),
132
- index("document_pending_updates_scope_created_idx").on(table.appKind, table.localId, table.createdAt),
133
- ]);
134
97
  /**
135
98
  * Last terminal sync failure or quarantined incoming update per document scope.
136
99
  *
137
- * The durable write queue (`documentPendingUpdates`) has no status columns — a
138
- * row is either pending or settled-and-deleted. Terminal submissions and
100
+ * The durable write queue (queued rows of `documentHistoryUpdates`) has no
101
+ * status columns — a row is either queued or settled. Terminal submissions and
139
102
  * incoming updates that cannot be decrypted or imported are recorded here so
140
103
  * the write-queue view and footer can surface why the document is blocked.
141
104
  * Rows are upserted per scope and deleted only after a later fully validated
@@ -177,21 +140,56 @@ export const documentHistoryCheckpoints = sqliteTable("document_history_checkpoi
177
140
  revision: text("revision").notNull(),
178
141
  updatedAt: text("updated_at").notNull(),
179
142
  }, (table) => [primaryKey({ columns: [table.appKind, table.localId] })]);
143
+ /**
144
+ * The local update log: one row per Loro update, serving as both the history
145
+ * tail (restore = checkpoint + tail) and the outbound write queue.
146
+ *
147
+ * Every locally authored update is stored once. While it waits for sync it
148
+ * carries an `updateId` (the id submitted to the server) and the version-vector
149
+ * metadata the submission needs; settlement clears them, leaving the row as
150
+ * ordinary tail history until compaction folds it into a checkpoint.
151
+ *
152
+ * Columns:
153
+ * - `id`: Row id; tail compaction deletes by it.
154
+ * - `appKind`, `localId`: Document scope matching `documents`.
155
+ * - `updateData`: Serialized Loro update payload.
156
+ * - `origin`: "local" (authored on this device) or "remote" (decrypted
157
+ * pulled update) for tail rows. Restores use it to advance the
158
+ * outgoing-delta marker across remote rows — their ops are already
159
+ * server-side — while a local row left behind by a crash stays below the
160
+ * marker so the next edit re-derives and sends it. "outbox" marks a queued
161
+ * update with no tail role (container metadata, whose content is its
162
+ * checkpoint, and full-state re-uploads after a remote reset); restores and
163
+ * compaction never see it and settlement deletes it.
164
+ * - `createdAt`: Insertion timestamp; with `rowid`, deterministic replay order.
165
+ * - `updateId`: Present exactly while the row is queued for sync; rekeyed
166
+ * after a lost acknowledgement poisons the submitted id.
167
+ * - `partialStartVersionVector` / `partialEndVersionVector`: Version vectors
168
+ * around a queued partial update.
169
+ * - `sourceVersionVector`: Present on a queued rotation baseline checkpoint.
170
+ * - `rekeyCount`: Durable bound on rekeys of a queued row.
171
+ *
172
+ * Invariant: compaction never deletes a queued row, so a checkpoint can cover
173
+ * a queued update's operations without removing it from the queue.
174
+ */
180
175
  export const documentHistoryUpdates = sqliteTable("document_history_updates", {
181
176
  id: text("id"),
182
177
  appKind: text("app_kind").notNull(),
183
178
  localId: text("local_id").notNull(),
184
179
  updateData: text("update_data").notNull(),
185
- // Provenance: "local" (authored on this device) or "remote" (decrypted
186
- // pulled update). Restores use it to advance the outgoing-delta marker
187
- // across remote rows — their ops are already server-side — while a local
188
- // row left behind by a crash stays below the marker so the next edit
189
- // re-derives and sends it.
190
180
  origin: text("origin").notNull(),
191
181
  createdAt: text("created_at").notNull(),
182
+ updateId: text("update_id"),
183
+ partialStartVersionVector: text("partial_start_version_vector"),
184
+ partialEndVersionVector: text("partial_end_version_vector"),
185
+ sourceVersionVector: text("source_version_vector"),
186
+ rekeyCount: integer("rekey_count").notNull().default(0),
192
187
  }, (table) => [
193
188
  primaryKey({ columns: [table.id] }),
194
189
  index("document_history_updates_scope_created_idx").on(table.appKind, table.localId, table.createdAt),
190
+ uniqueIndex("document_history_updates_update_id_idx")
191
+ .on(table.updateId)
192
+ .where(sql `${table.updateId} IS NOT NULL`),
195
193
  ]);
196
194
  /**
197
195
  * Anti-rollback pin for verified access manifests.
@@ -511,10 +509,12 @@ export const documentTables = [
511
509
  "recovery_document_id",
512
510
  ],
513
511
  },
514
- defineSqlTableSchema(documentPendingUpdates),
515
512
  defineSqlTableSchema(documentSyncFailures),
516
513
  defineSqlTableSchema(documentHistoryCheckpoints),
517
- defineSqlTableSchema(documentHistoryUpdates),
514
+ {
515
+ ...defineSqlTableSchema(documentHistoryUpdates),
516
+ requiredColumns: ["update_id"],
517
+ },
518
518
  ];
519
519
  export const principalPolicyTables = [
520
520
  {
@@ -616,7 +616,6 @@ export const clientSQLiteSchema = {
616
616
  organizationFounders,
617
617
  principalGrantRetirements,
618
618
  documents,
619
- documentPendingUpdates,
620
619
  documentSyncFailures,
621
620
  principalPolicies,
622
621
  principalPolicyBundleHistory,