@trestleinc/replicate 1.1.1 → 1.1.2-preview.0

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 (91) hide show
  1. package/README.md +395 -146
  2. package/dist/client/index.d.ts +311 -19
  3. package/dist/client/index.js +4027 -0
  4. package/dist/component/_generated/api.d.ts +13 -17
  5. package/dist/component/_generated/api.js +24 -4
  6. package/dist/component/_generated/component.d.ts +79 -77
  7. package/dist/component/_generated/component.js +1 -0
  8. package/dist/component/_generated/dataModel.d.ts +12 -15
  9. package/dist/component/_generated/dataModel.js +1 -0
  10. package/dist/component/_generated/server.d.ts +19 -22
  11. package/dist/component/_generated/server.js +65 -1
  12. package/dist/component/_virtual/rolldown_runtime.js +18 -0
  13. package/dist/component/convex.config.d.ts +6 -2
  14. package/dist/component/convex.config.js +7 -3
  15. package/dist/component/logger.d.ts +10 -6
  16. package/dist/component/logger.js +25 -28
  17. package/dist/component/public.d.ts +70 -61
  18. package/dist/component/public.js +311 -295
  19. package/dist/component/schema.d.ts +53 -45
  20. package/dist/component/schema.js +26 -32
  21. package/dist/component/shared/types.d.ts +9 -0
  22. package/dist/component/shared/types.js +15 -0
  23. package/dist/server/index.d.ts +134 -13
  24. package/dist/server/index.js +368 -0
  25. package/dist/shared/index.d.ts +27 -3
  26. package/dist/shared/index.js +1 -2
  27. package/package.json +34 -29
  28. package/src/client/collection.ts +339 -306
  29. package/src/client/errors.ts +9 -9
  30. package/src/client/index.ts +13 -32
  31. package/src/client/logger.ts +2 -2
  32. package/src/client/merge.ts +37 -34
  33. package/src/client/persistence/custom.ts +84 -0
  34. package/src/client/persistence/index.ts +9 -46
  35. package/src/client/persistence/indexeddb.ts +111 -84
  36. package/src/client/persistence/memory.ts +3 -3
  37. package/src/client/persistence/sqlite/browser.ts +168 -0
  38. package/src/client/persistence/sqlite/native.ts +29 -0
  39. package/src/client/persistence/sqlite/schema.ts +124 -0
  40. package/src/client/persistence/types.ts +32 -28
  41. package/src/client/prose-schema.ts +55 -0
  42. package/src/client/prose.ts +28 -25
  43. package/src/client/replicate.ts +5 -5
  44. package/src/client/services/cursor.ts +109 -0
  45. package/src/component/_generated/component.ts +31 -29
  46. package/src/component/convex.config.ts +2 -2
  47. package/src/component/logger.ts +7 -7
  48. package/src/component/public.ts +225 -237
  49. package/src/component/schema.ts +18 -15
  50. package/src/server/builder.ts +20 -7
  51. package/src/server/index.ts +3 -5
  52. package/src/server/schema.ts +5 -5
  53. package/src/server/storage.ts +113 -59
  54. package/src/shared/index.ts +5 -5
  55. package/src/shared/types.ts +51 -14
  56. package/dist/client/collection.d.ts +0 -96
  57. package/dist/client/errors.d.ts +0 -59
  58. package/dist/client/logger.d.ts +0 -2
  59. package/dist/client/merge.d.ts +0 -77
  60. package/dist/client/persistence/adapters/index.d.ts +0 -8
  61. package/dist/client/persistence/adapters/opsqlite.d.ts +0 -46
  62. package/dist/client/persistence/adapters/sqljs.d.ts +0 -83
  63. package/dist/client/persistence/index.d.ts +0 -49
  64. package/dist/client/persistence/indexeddb.d.ts +0 -17
  65. package/dist/client/persistence/memory.d.ts +0 -16
  66. package/dist/client/persistence/sqlite-browser.d.ts +0 -51
  67. package/dist/client/persistence/sqlite-level.d.ts +0 -63
  68. package/dist/client/persistence/sqlite-rn.d.ts +0 -36
  69. package/dist/client/persistence/sqlite.d.ts +0 -47
  70. package/dist/client/persistence/types.d.ts +0 -42
  71. package/dist/client/prose.d.ts +0 -56
  72. package/dist/client/replicate.d.ts +0 -40
  73. package/dist/client/services/checkpoint.d.ts +0 -18
  74. package/dist/client/services/reconciliation.d.ts +0 -24
  75. package/dist/index.js +0 -1618
  76. package/dist/server/builder.d.ts +0 -94
  77. package/dist/server/schema.d.ts +0 -27
  78. package/dist/server/storage.d.ts +0 -80
  79. package/dist/server.js +0 -281
  80. package/dist/shared/types.d.ts +0 -50
  81. package/dist/shared/types.js +0 -6
  82. package/dist/shared.js +0 -6
  83. package/src/client/persistence/adapters/index.ts +0 -8
  84. package/src/client/persistence/adapters/opsqlite.ts +0 -54
  85. package/src/client/persistence/adapters/sqljs.ts +0 -128
  86. package/src/client/persistence/sqlite-browser.ts +0 -107
  87. package/src/client/persistence/sqlite-level.ts +0 -407
  88. package/src/client/persistence/sqlite-rn.ts +0 -44
  89. package/src/client/persistence/sqlite.ts +0 -160
  90. package/src/client/services/checkpoint.ts +0 -86
  91. package/src/client/services/reconciliation.ts +0 -108
@@ -1,40 +0,0 @@
1
- /**
2
- * Replicate Helpers - Collection-bound functions for TanStack DB optimistic updates
3
- *
4
- * Each collection gets its own set of bound functions that operate on that
5
- * collection's TanStack DB instance. No global state - fully concurrent-safe.
6
- */
7
- export interface ReplicateParams {
8
- readonly begin: () => void;
9
- readonly write: (message: {
10
- type: 'insert' | 'update' | 'delete';
11
- value: unknown;
12
- }) => void;
13
- readonly commit: () => void;
14
- readonly truncate: () => void;
15
- }
16
- /**
17
- * Bound replicate operations for a specific collection.
18
- * These functions are already tied to the collection's TanStack DB params.
19
- */
20
- export interface BoundReplicateOps<T> {
21
- readonly insert: (items: T[]) => void;
22
- readonly delete: (items: T[]) => void;
23
- readonly upsert: (items: T[]) => void;
24
- readonly replace: (items: T[]) => void;
25
- }
26
- /**
27
- * Create bound replicate operations for a collection.
28
- * Returns functions that are already tied to the collection's params.
29
- * This is the proper way to handle multiple concurrent collections.
30
- *
31
- * @example
32
- * ```typescript
33
- * const ops = createReplicateOps<Task>(params);
34
- * ops.replace(items); // Always targets THIS collection's TanStack DB
35
- * ops.upsert([item]);
36
- * ops.delete([item]);
37
- * ```
38
- */
39
- export declare function createReplicateOps<T>(params: ReplicateParams): BoundReplicateOps<T>;
40
- export declare function _resetReplicateParams(): void;
@@ -1,18 +0,0 @@
1
- import { Effect, Context, Layer } from 'effect';
2
- import { IDBError, IDBWriteError } from '$/client/errors.js';
3
- import type { KeyValueStore } from '$/client/persistence/types.js';
4
- export interface CheckpointData {
5
- lastModified: number;
6
- }
7
- declare const Checkpoint_base: Context.TagClass<Checkpoint, "Checkpoint", {
8
- readonly loadCheckpoint: (collection: string) => Effect.Effect<CheckpointData, IDBError>;
9
- readonly saveCheckpoint: (collection: string, checkpoint: CheckpointData) => Effect.Effect<void, IDBWriteError>;
10
- readonly clearCheckpoint: (collection: string) => Effect.Effect<void, IDBError>;
11
- }>;
12
- export declare class Checkpoint extends Checkpoint_base {
13
- }
14
- /**
15
- * Create a Checkpoint service layer using the provided KeyValueStore.
16
- */
17
- export declare function createCheckpointLayer(kv: KeyValueStore): Layer.Layer<Checkpoint, never, never>;
18
- export {};
@@ -1,24 +0,0 @@
1
- import { Effect, Context, Layer } from 'effect';
2
- import * as Y from 'yjs';
3
- import { ReconciliationError as ReconciliationErrorImport } from '$/client/errors.js';
4
- declare const Reconciliation_base: Context.TagClass<Reconciliation, "Reconciliation", {
5
- /**
6
- * Reconciles local Yjs state with server state by removing phantom documents.
7
- * Uses an existing Yjs document and map instead of creating new ones.
8
- *
9
- * @param ydoc - Existing Yjs document
10
- * @param ymap - Existing Yjs map within the document
11
- * @param collection - Collection name for logging
12
- * @param serverDocs - Documents from server
13
- * @param getKey - Function to extract key from document
14
- */
15
- readonly reconcile: <T>(ydoc: Y.Doc, ymap: Y.Map<unknown>, collection: string, serverDocs: readonly T[], getKey: (doc: T) => string) => Effect.Effect<T[], ReconciliationErrorImport>;
16
- }>;
17
- /**
18
- * Reconciliation handles removal of phantom documents -
19
- * documents that exist locally but have been deleted on the server.
20
- */
21
- export declare class Reconciliation extends Reconciliation_base {
22
- }
23
- export declare const ReconciliationLive: Layer.Layer<Reconciliation, never, never>;
24
- export {};