@trestleinc/replicate 0.1.0 → 1.1.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.
- package/README.md +356 -420
- package/dist/client/collection.d.ts +78 -76
- package/dist/client/errors.d.ts +59 -0
- package/dist/client/index.d.ts +22 -18
- package/dist/client/logger.d.ts +0 -1
- package/dist/client/merge.d.ts +77 -0
- package/dist/client/persistence/adapters/index.d.ts +8 -0
- package/dist/client/persistence/adapters/opsqlite.d.ts +46 -0
- package/dist/client/persistence/adapters/sqljs.d.ts +83 -0
- package/dist/client/persistence/index.d.ts +49 -0
- package/dist/client/persistence/indexeddb.d.ts +17 -0
- package/dist/client/persistence/memory.d.ts +16 -0
- package/dist/client/persistence/sqlite-browser.d.ts +51 -0
- package/dist/client/persistence/sqlite-level.d.ts +63 -0
- package/dist/client/persistence/sqlite-rn.d.ts +36 -0
- package/dist/client/persistence/sqlite.d.ts +47 -0
- package/dist/client/persistence/types.d.ts +42 -0
- package/dist/client/prose.d.ts +56 -0
- package/dist/client/replicate.d.ts +40 -0
- package/dist/client/services/checkpoint.d.ts +18 -0
- package/dist/client/services/reconciliation.d.ts +24 -0
- package/dist/component/_generated/api.d.ts +35 -0
- package/dist/component/_generated/api.js +3 -3
- package/dist/component/_generated/component.d.ts +89 -0
- package/dist/component/_generated/component.js +0 -0
- package/dist/component/_generated/dataModel.d.ts +45 -0
- package/dist/component/_generated/dataModel.js +0 -0
- package/{src → dist}/component/_generated/server.d.ts +9 -38
- package/dist/component/convex.config.d.ts +2 -2
- package/dist/component/convex.config.js +2 -1
- package/dist/component/logger.d.ts +8 -0
- package/dist/component/logger.js +30 -0
- package/dist/component/public.d.ts +36 -61
- package/dist/component/public.js +232 -58
- package/dist/component/schema.d.ts +32 -8
- package/dist/component/schema.js +19 -6
- package/dist/index.js +1553 -308
- package/dist/server/builder.d.ts +94 -0
- package/dist/server/index.d.ts +14 -17
- package/dist/server/schema.d.ts +17 -63
- package/dist/server/storage.d.ts +80 -0
- package/dist/server.js +268 -83
- package/dist/shared/index.d.ts +5 -0
- package/dist/shared/index.js +2 -0
- package/dist/shared/types.d.ts +50 -0
- package/dist/shared/types.js +6 -0
- package/dist/shared.js +6 -0
- package/package.json +59 -49
- package/src/client/collection.ts +877 -450
- package/src/client/errors.ts +45 -0
- package/src/client/index.ts +52 -26
- package/src/client/logger.ts +2 -28
- package/src/client/merge.ts +374 -0
- package/src/client/persistence/adapters/index.ts +8 -0
- package/src/client/persistence/adapters/opsqlite.ts +54 -0
- package/src/client/persistence/adapters/sqljs.ts +128 -0
- package/src/client/persistence/index.ts +54 -0
- package/src/client/persistence/indexeddb.ts +110 -0
- package/src/client/persistence/memory.ts +61 -0
- package/src/client/persistence/sqlite-browser.ts +107 -0
- package/src/client/persistence/sqlite-level.ts +407 -0
- package/src/client/persistence/sqlite-rn.ts +44 -0
- package/src/client/persistence/sqlite.ts +161 -0
- package/src/client/persistence/types.ts +49 -0
- package/src/client/prose.ts +369 -0
- package/src/client/replicate.ts +80 -0
- package/src/client/services/checkpoint.ts +86 -0
- package/src/client/services/reconciliation.ts +108 -0
- package/src/component/_generated/api.ts +52 -0
- package/src/component/_generated/component.ts +103 -0
- package/src/component/_generated/{dataModel.d.ts → dataModel.ts} +1 -1
- package/src/component/_generated/server.ts +161 -0
- package/src/component/convex.config.ts +3 -1
- package/src/component/logger.ts +36 -0
- package/src/component/public.ts +364 -111
- package/src/component/schema.ts +18 -5
- package/src/env.d.ts +31 -0
- package/src/server/builder.ts +85 -0
- package/src/server/index.ts +9 -24
- package/src/server/schema.ts +20 -76
- package/src/server/storage.ts +313 -0
- package/src/shared/index.ts +5 -0
- package/src/shared/types.ts +52 -0
- package/LICENSE.package +0 -201
- package/dist/client/storage.d.ts +0 -143
- package/dist/server/replication.d.ts +0 -122
- package/dist/server/ssr.d.ts +0 -79
- package/dist/ssr.js +0 -19
- package/src/client/storage.ts +0 -206
- package/src/component/_generated/api.d.ts +0 -95
- package/src/component/_generated/api.js +0 -23
- package/src/component/_generated/server.js +0 -90
- package/src/server/replication.ts +0 -244
- package/src/server/ssr.ts +0 -106
package/src/server/ssr.ts
DELETED
|
@@ -1,106 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Server-Side Rendering (SSR) Utilities
|
|
3
|
-
*
|
|
4
|
-
* This module provides utilities for loading collection data during
|
|
5
|
-
* server-side rendering. Use `loadCollection` with an explicit config
|
|
6
|
-
* object for clarity and type safety.
|
|
7
|
-
*
|
|
8
|
-
* @module ssr
|
|
9
|
-
* @example
|
|
10
|
-
* ```typescript
|
|
11
|
-
* import { loadCollection } from '@convex-replicate/core/ssr';
|
|
12
|
-
* import { api } from '../convex/_generated/api';
|
|
13
|
-
*
|
|
14
|
-
* const tasks = await loadCollection<Task>(httpClient, {
|
|
15
|
-
* api: api.tasks,
|
|
16
|
-
* collection: 'tasks',
|
|
17
|
-
* limit: 100,
|
|
18
|
-
* });
|
|
19
|
-
* ```
|
|
20
|
-
*/
|
|
21
|
-
|
|
22
|
-
import type { ConvexHttpClient } from 'convex/browser';
|
|
23
|
-
import type { FunctionReference } from 'convex/server';
|
|
24
|
-
|
|
25
|
-
/**
|
|
26
|
-
* API module shape expected by loadCollection.
|
|
27
|
-
*
|
|
28
|
-
* This should match the generated API module for your collection
|
|
29
|
-
* (e.g., api.tasks, api.users, etc.)
|
|
30
|
-
*/
|
|
31
|
-
export type CollectionAPI = {
|
|
32
|
-
stream: FunctionReference<'query', 'public' | 'internal'>;
|
|
33
|
-
};
|
|
34
|
-
|
|
35
|
-
/**
|
|
36
|
-
* Configuration for loading collection data during SSR.
|
|
37
|
-
*/
|
|
38
|
-
export interface LoadCollectionConfig {
|
|
39
|
-
/** The API module for the collection (e.g., api.tasks) */
|
|
40
|
-
api: CollectionAPI;
|
|
41
|
-
/** The collection name (should match the API module name) */
|
|
42
|
-
collection: string;
|
|
43
|
-
/** Maximum number of items to load (default: 100) */
|
|
44
|
-
limit?: number;
|
|
45
|
-
}
|
|
46
|
-
|
|
47
|
-
/**
|
|
48
|
-
* Load collection data for server-side rendering.
|
|
49
|
-
*
|
|
50
|
-
* **IMPORTANT**: This function is currently limited because `stream` only returns
|
|
51
|
-
* CRDT bytes, not materialized documents. For most SSR use cases, it's recommended to
|
|
52
|
-
* create a separate query that reads from your main table instead.
|
|
53
|
-
*
|
|
54
|
-
* @deprecated Consider creating a dedicated SSR query instead. See example below.
|
|
55
|
-
*
|
|
56
|
-
* @param httpClient - Convex HTTP client for server-side queries
|
|
57
|
-
* @param config - Configuration object with api, collection, and options
|
|
58
|
-
* @returns Promise resolving to array of items from the collection
|
|
59
|
-
*
|
|
60
|
-
* @example
|
|
61
|
-
* **Recommended SSR Pattern:**
|
|
62
|
-
* ```typescript
|
|
63
|
-
* // convex/tasks.ts
|
|
64
|
-
* export const list = query({
|
|
65
|
-
* handler: async (ctx) => {
|
|
66
|
-
* return await ctx.db
|
|
67
|
-
* .query('tasks')
|
|
68
|
-
* .filter((q) => q.neq(q.field('deleted'), true))
|
|
69
|
-
* .collect();
|
|
70
|
-
* },
|
|
71
|
-
* });
|
|
72
|
-
*
|
|
73
|
-
* // In your route loader
|
|
74
|
-
* import { ConvexHttpClient } from 'convex/browser';
|
|
75
|
-
* import { api } from '../convex/_generated/api';
|
|
76
|
-
*
|
|
77
|
-
* const httpClient = new ConvexHttpClient(import.meta.env.VITE_CONVEX_URL);
|
|
78
|
-
* const tasks = await httpClient.query(api.tasks.list);
|
|
79
|
-
* ```
|
|
80
|
-
*/
|
|
81
|
-
export async function loadCollection<TItem extends { id: string }>(
|
|
82
|
-
httpClient: ConvexHttpClient,
|
|
83
|
-
config: LoadCollectionConfig
|
|
84
|
-
): Promise<ReadonlyArray<TItem>> {
|
|
85
|
-
// NOTE: This implementation is limited because stream only returns CRDT bytes,
|
|
86
|
-
// not materialized documents. The code below attempts to construct items but
|
|
87
|
-
// `change.document` does not exist in the actual stream response.
|
|
88
|
-
//
|
|
89
|
-
// For production use, create a dedicated query that reads from your main table.
|
|
90
|
-
|
|
91
|
-
const result = await httpClient.query(config.api.stream as any, {
|
|
92
|
-
collectionName: config.collection,
|
|
93
|
-
checkpoint: { lastModified: 0 },
|
|
94
|
-
limit: config.limit ?? 100,
|
|
95
|
-
});
|
|
96
|
-
|
|
97
|
-
const items: TItem[] = [];
|
|
98
|
-
for (const change of result.changes) {
|
|
99
|
-
// FIXME: change.document doesn't exist - stream only returns crdtBytes
|
|
100
|
-
// This code is here for backwards compatibility but won't work correctly
|
|
101
|
-
const item = { id: change.documentId, ...change.document } as TItem;
|
|
102
|
-
items.push(item);
|
|
103
|
-
}
|
|
104
|
-
|
|
105
|
-
return items;
|
|
106
|
-
}
|