tanstack-db-pglite 1.3.6 → 1.4.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 +2 -6
- package/dist/drizzle.d.ts +3 -2
- package/dist/drizzle.js +4 -8
- package/dist/sql.d.ts +3 -2
- package/dist/sql.js +3 -4
- package/package.json +7 -7
package/README.md
CHANGED
|
@@ -38,14 +38,12 @@ export const chatsCollection = createCollection(drizzleCollectionOptions({
|
|
|
38
38
|
prepare: async () => {
|
|
39
39
|
await waitForMigrations()
|
|
40
40
|
},
|
|
41
|
-
sync: async ({
|
|
41
|
+
sync: async ({ write, 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
|
-
begin()
|
|
47
46
|
write(item)
|
|
48
|
-
commit()
|
|
49
47
|
}
|
|
50
48
|
|
|
51
49
|
eventSource.addEventListener('ready', () => markReady())
|
|
@@ -96,14 +94,12 @@ export const chatsCollection = createCollection(sqlCollectionOptions({
|
|
|
96
94
|
)
|
|
97
95
|
`)
|
|
98
96
|
},
|
|
99
|
-
sync: async ({
|
|
97
|
+
sync: async ({ write, markReady }) => {
|
|
100
98
|
const eventSource = new EventSource('/api/chats/sync')
|
|
101
99
|
|
|
102
100
|
eventSource.onmessage = (event) => {
|
|
103
101
|
const item = JSON.parse(event.data)
|
|
104
|
-
begin()
|
|
105
102
|
write(item)
|
|
106
|
-
commit()
|
|
107
103
|
}
|
|
108
104
|
|
|
109
105
|
eventSource.addEventListener('ready', () => markReady())
|
package/dist/drizzle.d.ts
CHANGED
|
@@ -16,10 +16,11 @@ type SyncParams<Table extends PgTable> = Parameters<SyncConfig<Table['$inferSele
|
|
|
16
16
|
export declare function drizzleCollectionOptions<Table extends PgTable>({ startSync, ...config }: {
|
|
17
17
|
db: PgliteDatabase<any>;
|
|
18
18
|
startSync?: boolean;
|
|
19
|
+
sync?: {
|
|
20
|
+
sync: (params: Pick<SyncParams<Table>, 'write' | 'collection' | 'markReady' | 'metadata'>) => Promise<(() => void) | void>;
|
|
21
|
+
} & Omit<SyncConfig, 'sync'>;
|
|
19
22
|
table: Table;
|
|
20
23
|
primaryColumn: IndexColumn;
|
|
21
|
-
rowUpdateMode?: 'partial' | 'full';
|
|
22
|
-
sync?: (params: SyncParams<Table>) => Promise<(() => void) | void>;
|
|
23
24
|
prepare?: () => Promise<unknown> | unknown;
|
|
24
25
|
onInsert?: (params: InsertMutationFnParams<Table['$inferSelect'], string>) => Promise<void>;
|
|
25
26
|
onUpdate?: (params: UpdateMutationFnParams<Table['$inferSelect'], string>) => Promise<void>;
|
package/dist/drizzle.js
CHANGED
|
@@ -77,7 +77,7 @@ export function drizzleCollectionOptions({ startSync = true, ...config }) {
|
|
|
77
77
|
params.markReady();
|
|
78
78
|
return;
|
|
79
79
|
}
|
|
80
|
-
return config.sync({
|
|
80
|
+
return config.sync.sync({
|
|
81
81
|
write: async (message) => {
|
|
82
82
|
if (message.type === 'insert') {
|
|
83
83
|
await onDrizzleInsert([message.value]);
|
|
@@ -89,13 +89,12 @@ export function drizzleCollectionOptions({ startSync = true, ...config }) {
|
|
|
89
89
|
const key = 'key' in message ? message.key : params.collection.getKeyFromItem(message.value);
|
|
90
90
|
await onDrizzleDelete([key]);
|
|
91
91
|
}
|
|
92
|
+
params.begin();
|
|
92
93
|
params.write(message);
|
|
94
|
+
params.commit();
|
|
93
95
|
},
|
|
94
96
|
collection: params.collection,
|
|
95
97
|
markReady: params.markReady,
|
|
96
|
-
begin: params.begin,
|
|
97
|
-
commit: params.commit,
|
|
98
|
-
truncate: params.truncate,
|
|
99
98
|
...(params.metadata && { metadata: params.metadata }),
|
|
100
99
|
});
|
|
101
100
|
};
|
|
@@ -104,7 +103,7 @@ export function drizzleCollectionOptions({ startSync = true, ...config }) {
|
|
|
104
103
|
autoIndex: 'eager',
|
|
105
104
|
defaultIndexType: BasicIndex,
|
|
106
105
|
sync: {
|
|
107
|
-
...
|
|
106
|
+
...config.sync,
|
|
108
107
|
sync: (params) => {
|
|
109
108
|
resolveSyncParams(params);
|
|
110
109
|
(async () => {
|
|
@@ -122,9 +121,6 @@ export function drizzleCollectionOptions({ startSync = true, ...config }) {
|
|
|
122
121
|
syncCleanup = result;
|
|
123
122
|
}
|
|
124
123
|
}
|
|
125
|
-
else {
|
|
126
|
-
params.markReady();
|
|
127
|
-
}
|
|
128
124
|
})();
|
|
129
125
|
return () => {
|
|
130
126
|
syncCleanup?.();
|
package/dist/sql.d.ts
CHANGED
|
@@ -16,13 +16,14 @@ type SyncParams<ItemType extends Record<string, unknown>> = Parameters<SyncConfi
|
|
|
16
16
|
export declare function sqlCollectionOptions<Schema extends StandardSchemaV1<Record<string, unknown>>>({ startSync, ...config }: {
|
|
17
17
|
db: PGlite | PGliteWorker;
|
|
18
18
|
startSync?: boolean;
|
|
19
|
+
sync?: {
|
|
20
|
+
sync: (params: Pick<SyncParams<Output<Schema>>, 'write' | 'collection' | 'markReady' | 'metadata'>) => Promise<(() => void) | void>;
|
|
21
|
+
} & Omit<SyncConfig, 'sync'>;
|
|
19
22
|
tableName: string;
|
|
20
23
|
primaryKeyColumn: Extract<keyof Output<Schema>, string>;
|
|
21
|
-
rowUpdateMode?: 'partial' | 'full';
|
|
22
24
|
schema: Schema;
|
|
23
25
|
getKey?: (row: Output<Schema>) => string;
|
|
24
26
|
prepare?: () => Promise<unknown> | unknown;
|
|
25
|
-
sync?: (params: Pick<SyncParams<Output<Schema>>, 'write' | 'collection' | 'markReady' | 'metadata'>) => Promise<(() => void) | void>;
|
|
26
27
|
onInsert?: (params: InsertMutationFnParams<Output<Schema>, string>) => Promise<void>;
|
|
27
28
|
onUpdate?: (params: UpdateMutationFnParams<Output<Schema>, string>) => Promise<void>;
|
|
28
29
|
onDelete?: (params: DeleteMutationFnParams<Output<Schema>, string>) => Promise<void>;
|
package/dist/sql.js
CHANGED
|
@@ -1,6 +1,5 @@
|
|
|
1
|
-
import { BasicIndex
|
|
1
|
+
import { BasicIndex } from '@tanstack/db';
|
|
2
2
|
function quoteId(name) {
|
|
3
|
-
// eslint-disable-next-line e18e/prefer-static-regex
|
|
4
3
|
return `"${String(name).replace(/"/g, '""')}"`;
|
|
5
4
|
}
|
|
6
5
|
/**
|
|
@@ -64,7 +63,7 @@ export function sqlCollectionOptions({ startSync = true, ...config }) {
|
|
|
64
63
|
params.markReady();
|
|
65
64
|
return;
|
|
66
65
|
}
|
|
67
|
-
return config.sync({
|
|
66
|
+
return config.sync.sync({
|
|
68
67
|
write: async (p) => {
|
|
69
68
|
if (p.type === 'insert') {
|
|
70
69
|
await runInsert(config.db, [p.value]);
|
|
@@ -90,7 +89,7 @@ export function sqlCollectionOptions({ startSync = true, ...config }) {
|
|
|
90
89
|
autoIndex: 'eager',
|
|
91
90
|
defaultIndexType: BasicIndex,
|
|
92
91
|
sync: {
|
|
93
|
-
...
|
|
92
|
+
...config.sync,
|
|
94
93
|
sync: (params) => {
|
|
95
94
|
resolveSyncParams(params);
|
|
96
95
|
(async () => {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "tanstack-db-pglite",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.4.0",
|
|
4
4
|
"author": "Valerii Strilets",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"repository": {
|
|
@@ -20,8 +20,8 @@
|
|
|
20
20
|
"dist"
|
|
21
21
|
],
|
|
22
22
|
"peerDependencies": {
|
|
23
|
-
"@electric-sql/pglite": ">=0.
|
|
24
|
-
"@tanstack/db": ">=0.5
|
|
23
|
+
"@electric-sql/pglite": ">=0.4.0",
|
|
24
|
+
"@tanstack/db": ">=0.6.5",
|
|
25
25
|
"drizzle-orm": ">=0.45.0"
|
|
26
26
|
},
|
|
27
27
|
"peerDependenciesMeta": {
|
|
@@ -33,11 +33,11 @@
|
|
|
33
33
|
"drizzle-zod": "^0.8.3"
|
|
34
34
|
},
|
|
35
35
|
"devDependencies": {
|
|
36
|
-
"@antfu/eslint-config": "^
|
|
36
|
+
"@antfu/eslint-config": "^9.0.0",
|
|
37
37
|
"@standard-schema/spec": "^1.1.0",
|
|
38
|
-
"eslint": "^10.
|
|
39
|
-
"jiti": "^2.
|
|
40
|
-
"taze": "^19.
|
|
38
|
+
"eslint": "^10.4.0",
|
|
39
|
+
"jiti": "^2.7.0",
|
|
40
|
+
"taze": "^19.13.0",
|
|
41
41
|
"typescript": "^6.0.3"
|
|
42
42
|
},
|
|
43
43
|
"scripts": {
|