tanstack-db-pglite 1.3.4 → 1.3.5
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/dist/drizzle.js +10 -4
- package/dist/sql.js +8 -4
- package/package.json +1 -1
package/dist/drizzle.js
CHANGED
|
@@ -12,6 +12,7 @@ import { createSelectSchema } from 'drizzle-zod';
|
|
|
12
12
|
export function drizzleCollectionOptions({ startSync = true, ...config }) {
|
|
13
13
|
// Sync params can be null while running PGLite migrations
|
|
14
14
|
const { promise: syncParams, resolve: resolveSyncParams } = Promise.withResolvers();
|
|
15
|
+
let syncCleanup;
|
|
15
16
|
// eslint-disable-next-line ts/no-explicit-any
|
|
16
17
|
async function onDrizzleInsert(data, tx) {
|
|
17
18
|
// @ts-expect-error drizzle types
|
|
@@ -105,7 +106,6 @@ export function drizzleCollectionOptions({ startSync = true, ...config }) {
|
|
|
105
106
|
...(config.rowUpdateMode && { rowUpdateMode: config.rowUpdateMode }),
|
|
106
107
|
sync: (params) => {
|
|
107
108
|
resolveSyncParams(params);
|
|
108
|
-
let cleanup;
|
|
109
109
|
(async () => {
|
|
110
110
|
await config.prepare?.();
|
|
111
111
|
// @ts-expect-error drizzle types
|
|
@@ -118,7 +118,7 @@ export function drizzleCollectionOptions({ startSync = true, ...config }) {
|
|
|
118
118
|
if (startSync) {
|
|
119
119
|
const result = await sync();
|
|
120
120
|
if (typeof result === 'function') {
|
|
121
|
-
|
|
121
|
+
syncCleanup = result;
|
|
122
122
|
}
|
|
123
123
|
}
|
|
124
124
|
else {
|
|
@@ -126,7 +126,8 @@ export function drizzleCollectionOptions({ startSync = true, ...config }) {
|
|
|
126
126
|
}
|
|
127
127
|
})();
|
|
128
128
|
return () => {
|
|
129
|
-
|
|
129
|
+
syncCleanup?.();
|
|
130
|
+
syncCleanup = undefined;
|
|
130
131
|
};
|
|
131
132
|
},
|
|
132
133
|
},
|
|
@@ -167,9 +168,14 @@ export function drizzleCollectionOptions({ startSync = true, ...config }) {
|
|
|
167
168
|
if (!config.sync) {
|
|
168
169
|
throw new Error('Sync is not defined');
|
|
169
170
|
}
|
|
171
|
+
syncCleanup?.();
|
|
172
|
+
syncCleanup = undefined;
|
|
170
173
|
const params = await syncParams;
|
|
171
174
|
await params.collection.stateWhenReady();
|
|
172
|
-
await sync();
|
|
175
|
+
const result = await sync();
|
|
176
|
+
if (typeof result === 'function') {
|
|
177
|
+
syncCleanup = result;
|
|
178
|
+
}
|
|
173
179
|
},
|
|
174
180
|
},
|
|
175
181
|
};
|
package/dist/sql.js
CHANGED
|
@@ -12,6 +12,7 @@ function quoteId(name) {
|
|
|
12
12
|
* until `markReady()` is called.
|
|
13
13
|
*/
|
|
14
14
|
export function sqlCollectionOptions({ startSync = true, ...config }) {
|
|
15
|
+
let syncCleanup;
|
|
15
16
|
const table = quoteId(config.tableName);
|
|
16
17
|
const primaryKey = quoteId(config.primaryKeyColumn);
|
|
17
18
|
const getKey = config.getKey ?? ((row) => String(row[config.primaryKeyColumn]));
|
|
@@ -92,7 +93,6 @@ export function sqlCollectionOptions({ startSync = true, ...config }) {
|
|
|
92
93
|
...(config.rowUpdateMode && { rowUpdateMode: config.rowUpdateMode }),
|
|
93
94
|
sync: (params) => {
|
|
94
95
|
resolveSyncParams(params);
|
|
95
|
-
let cleanup;
|
|
96
96
|
(async () => {
|
|
97
97
|
await config.prepare?.();
|
|
98
98
|
const rows = await runSelect(config.db);
|
|
@@ -104,7 +104,7 @@ export function sqlCollectionOptions({ startSync = true, ...config }) {
|
|
|
104
104
|
if (startSync) {
|
|
105
105
|
const result = await sync();
|
|
106
106
|
if (typeof result === 'function') {
|
|
107
|
-
|
|
107
|
+
syncCleanup = result;
|
|
108
108
|
}
|
|
109
109
|
}
|
|
110
110
|
else {
|
|
@@ -112,7 +112,8 @@ export function sqlCollectionOptions({ startSync = true, ...config }) {
|
|
|
112
112
|
}
|
|
113
113
|
})();
|
|
114
114
|
return () => {
|
|
115
|
-
|
|
115
|
+
syncCleanup?.();
|
|
116
|
+
syncCleanup = undefined;
|
|
116
117
|
};
|
|
117
118
|
},
|
|
118
119
|
},
|
|
@@ -152,7 +153,10 @@ export function sqlCollectionOptions({ startSync = true, ...config }) {
|
|
|
152
153
|
}
|
|
153
154
|
const params = await syncParams;
|
|
154
155
|
await params.collection.stateWhenReady();
|
|
155
|
-
await sync();
|
|
156
|
+
const result = await sync();
|
|
157
|
+
if (typeof result === 'function') {
|
|
158
|
+
syncCleanup = result;
|
|
159
|
+
}
|
|
156
160
|
},
|
|
157
161
|
},
|
|
158
162
|
};
|