tanstack-db-pglite 1.4.1 → 1.5.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 +4 -4
- package/dist/drizzle.d.ts +8 -2
- package/dist/drizzle.js +1 -1
- package/dist/sql.d.ts +8 -2
- package/dist/sql.js +1 -1
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -38,12 +38,12 @@ export const chatsCollection = createCollection(drizzleCollectionOptions({
|
|
|
38
38
|
prepare: async () => {
|
|
39
39
|
await waitForMigrations()
|
|
40
40
|
},
|
|
41
|
-
sync: async ({
|
|
41
|
+
sync: async ({ writeAsync, markReady }) => {
|
|
42
42
|
const eventSource = new EventSource('/api/chats/sync')
|
|
43
43
|
|
|
44
44
|
eventSource.onmessage = (event) => {
|
|
45
45
|
const item = JSON.parse(event.data)
|
|
46
|
-
|
|
46
|
+
writeAsync(item)
|
|
47
47
|
}
|
|
48
48
|
|
|
49
49
|
eventSource.addEventListener('ready', () => markReady())
|
|
@@ -94,12 +94,12 @@ export const chatsCollection = createCollection(sqlCollectionOptions({
|
|
|
94
94
|
)
|
|
95
95
|
`)
|
|
96
96
|
},
|
|
97
|
-
sync: async ({
|
|
97
|
+
sync: async ({ writeAsync, markReady }) => {
|
|
98
98
|
const eventSource = new EventSource('/api/chats/sync')
|
|
99
99
|
|
|
100
100
|
eventSource.onmessage = (event) => {
|
|
101
101
|
const item = JSON.parse(event.data)
|
|
102
|
-
|
|
102
|
+
writeAsync(item)
|
|
103
103
|
}
|
|
104
104
|
|
|
105
105
|
eventSource.addEventListener('ready', () => markReady())
|
package/dist/drizzle.d.ts
CHANGED
|
@@ -1,10 +1,16 @@
|
|
|
1
1
|
import type { StandardSchemaV1 } from '@standard-schema/spec';
|
|
2
|
-
import type { CollectionConfig, DeleteMutationFnParams, InsertMutationFnParams, SyncConfig, UpdateMutationFnParams } from '@tanstack/db';
|
|
2
|
+
import type { ChangeMessageOrDeleteKeyMessage, CollectionConfig, DeleteMutationFnParams, InsertMutationFnParams, SyncConfig, UpdateMutationFnParams } from '@tanstack/db';
|
|
3
3
|
import type { IndexColumn, PgTable } from 'drizzle-orm/pg-core';
|
|
4
4
|
import type { PgliteDatabase } from 'drizzle-orm/pglite';
|
|
5
5
|
import type { PgliteUtils } from './utils';
|
|
6
6
|
type Schema<Table extends PgTable> = StandardSchemaV1<Table['$inferSelect'], Table['$inferSelect']>;
|
|
7
7
|
type SyncParams<Table extends PgTable> = Parameters<SyncConfig<Table['$inferSelect'], string>['sync']>[0];
|
|
8
|
+
type CustomSyncParams<Table extends PgTable> = Pick<SyncParams<Table>, 'collection' | 'markReady' | 'metadata'> & {
|
|
9
|
+
/**
|
|
10
|
+
* We created async version of "write" callback due to synchronization with PGLite
|
|
11
|
+
*/
|
|
12
|
+
writeAsync: (message: ChangeMessageOrDeleteKeyMessage<Table['$inferSelect'], string>) => Promise<void>;
|
|
13
|
+
};
|
|
8
14
|
/**
|
|
9
15
|
* Creates collection options backed by Drizzle ORM on PGlite.
|
|
10
16
|
*
|
|
@@ -17,7 +23,7 @@ export declare function drizzleCollectionOptions<Table extends PgTable>({ startS
|
|
|
17
23
|
db: PgliteDatabase<any>;
|
|
18
24
|
startSync?: boolean;
|
|
19
25
|
sync?: {
|
|
20
|
-
sync: (params:
|
|
26
|
+
sync: (params: CustomSyncParams<Table>) => Promise<(() => void) | void>;
|
|
21
27
|
} & Omit<SyncConfig, 'sync'>;
|
|
22
28
|
table: Table;
|
|
23
29
|
primaryColumn: IndexColumn;
|
package/dist/drizzle.js
CHANGED
|
@@ -78,7 +78,7 @@ export function drizzleCollectionOptions({ startSync = true, ...config }) {
|
|
|
78
78
|
return;
|
|
79
79
|
}
|
|
80
80
|
return config.sync.sync({
|
|
81
|
-
|
|
81
|
+
writeAsync: async (message) => {
|
|
82
82
|
if (message.type === 'insert') {
|
|
83
83
|
await onDrizzleInsert([message.value]);
|
|
84
84
|
}
|
package/dist/sql.d.ts
CHANGED
|
@@ -1,10 +1,16 @@
|
|
|
1
1
|
import type { PGlite } from '@electric-sql/pglite';
|
|
2
2
|
import type { PGliteWorker } from '@electric-sql/pglite/worker';
|
|
3
3
|
import type { StandardSchemaV1 } from '@standard-schema/spec';
|
|
4
|
-
import type { CollectionConfig, DeleteMutationFnParams, InsertMutationFnParams, SyncConfig, UpdateMutationFnParams } from '@tanstack/db';
|
|
4
|
+
import type { ChangeMessageOrDeleteKeyMessage, CollectionConfig, DeleteMutationFnParams, InsertMutationFnParams, SyncConfig, UpdateMutationFnParams } from '@tanstack/db';
|
|
5
5
|
import type { PgliteUtils } from './utils';
|
|
6
6
|
type Output<T extends StandardSchemaV1> = StandardSchemaV1.InferOutput<T>;
|
|
7
7
|
type SyncParams<ItemType extends Record<string, unknown>> = Parameters<SyncConfig<ItemType, string>['sync']>[0];
|
|
8
|
+
type CustomSyncParams<ItemType extends Record<string, unknown>> = Pick<SyncParams<ItemType>, 'collection' | 'markReady' | 'metadata'> & {
|
|
9
|
+
/**
|
|
10
|
+
* We created async version of "write" callback due to synchronization with PGLite
|
|
11
|
+
*/
|
|
12
|
+
writeAsync: (message: ChangeMessageOrDeleteKeyMessage<ItemType, string>) => Promise<void>;
|
|
13
|
+
};
|
|
8
14
|
/**
|
|
9
15
|
* Creates collection options backed by raw SQL on PGlite.
|
|
10
16
|
*
|
|
@@ -17,7 +23,7 @@ export declare function sqlCollectionOptions<Schema extends StandardSchemaV1<Rec
|
|
|
17
23
|
db: PGlite | PGliteWorker;
|
|
18
24
|
startSync?: boolean;
|
|
19
25
|
sync?: {
|
|
20
|
-
sync: (params:
|
|
26
|
+
sync: (params: CustomSyncParams<Output<Schema>>) => Promise<(() => void) | void>;
|
|
21
27
|
} & Omit<SyncConfig, 'sync'>;
|
|
22
28
|
tableName: string;
|
|
23
29
|
primaryKeyColumn: Extract<keyof Output<Schema>, string>;
|
package/dist/sql.js
CHANGED