tanstack-db-pglite 1.3.3 → 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 +11 -10
- package/dist/sql.js +9 -10
- 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
|
|
@@ -70,13 +71,8 @@ export function drizzleCollectionOptions({ startSync = true, ...config }) {
|
|
|
70
71
|
.from(config.table)
|
|
71
72
|
.where(eq(config.primaryColumn, m.key))));
|
|
72
73
|
}
|
|
73
|
-
const sync = async (
|
|
74
|
+
const sync = async () => {
|
|
74
75
|
const params = await syncParams;
|
|
75
|
-
if (force) {
|
|
76
|
-
params.begin();
|
|
77
|
-
params.truncate();
|
|
78
|
-
params.commit();
|
|
79
|
-
}
|
|
80
76
|
if (!config.sync) {
|
|
81
77
|
params.markReady();
|
|
82
78
|
return;
|
|
@@ -110,7 +106,6 @@ export function drizzleCollectionOptions({ startSync = true, ...config }) {
|
|
|
110
106
|
...(config.rowUpdateMode && { rowUpdateMode: config.rowUpdateMode }),
|
|
111
107
|
sync: (params) => {
|
|
112
108
|
resolveSyncParams(params);
|
|
113
|
-
let cleanup;
|
|
114
109
|
(async () => {
|
|
115
110
|
await config.prepare?.();
|
|
116
111
|
// @ts-expect-error drizzle types
|
|
@@ -123,7 +118,7 @@ export function drizzleCollectionOptions({ startSync = true, ...config }) {
|
|
|
123
118
|
if (startSync) {
|
|
124
119
|
const result = await sync();
|
|
125
120
|
if (typeof result === 'function') {
|
|
126
|
-
|
|
121
|
+
syncCleanup = result;
|
|
127
122
|
}
|
|
128
123
|
}
|
|
129
124
|
else {
|
|
@@ -131,7 +126,8 @@ export function drizzleCollectionOptions({ startSync = true, ...config }) {
|
|
|
131
126
|
}
|
|
132
127
|
})();
|
|
133
128
|
return () => {
|
|
134
|
-
|
|
129
|
+
syncCleanup?.();
|
|
130
|
+
syncCleanup = undefined;
|
|
135
131
|
};
|
|
136
132
|
},
|
|
137
133
|
},
|
|
@@ -172,9 +168,14 @@ export function drizzleCollectionOptions({ startSync = true, ...config }) {
|
|
|
172
168
|
if (!config.sync) {
|
|
173
169
|
throw new Error('Sync is not defined');
|
|
174
170
|
}
|
|
171
|
+
syncCleanup?.();
|
|
172
|
+
syncCleanup = undefined;
|
|
175
173
|
const params = await syncParams;
|
|
176
174
|
await params.collection.stateWhenReady();
|
|
177
|
-
await sync(
|
|
175
|
+
const result = await sync();
|
|
176
|
+
if (typeof result === 'function') {
|
|
177
|
+
syncCleanup = result;
|
|
178
|
+
}
|
|
178
179
|
},
|
|
179
180
|
},
|
|
180
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]));
|
|
@@ -57,13 +58,8 @@ export function sqlCollectionOptions({ startSync = true, ...config }) {
|
|
|
57
58
|
});
|
|
58
59
|
commit();
|
|
59
60
|
}
|
|
60
|
-
const sync = async (
|
|
61
|
+
const sync = async () => {
|
|
61
62
|
const params = await syncParams;
|
|
62
|
-
if (force) {
|
|
63
|
-
params.begin();
|
|
64
|
-
params.truncate();
|
|
65
|
-
params.commit();
|
|
66
|
-
}
|
|
67
63
|
if (!config.sync) {
|
|
68
64
|
params.markReady();
|
|
69
65
|
return;
|
|
@@ -97,7 +93,6 @@ export function sqlCollectionOptions({ startSync = true, ...config }) {
|
|
|
97
93
|
...(config.rowUpdateMode && { rowUpdateMode: config.rowUpdateMode }),
|
|
98
94
|
sync: (params) => {
|
|
99
95
|
resolveSyncParams(params);
|
|
100
|
-
let cleanup;
|
|
101
96
|
(async () => {
|
|
102
97
|
await config.prepare?.();
|
|
103
98
|
const rows = await runSelect(config.db);
|
|
@@ -109,7 +104,7 @@ export function sqlCollectionOptions({ startSync = true, ...config }) {
|
|
|
109
104
|
if (startSync) {
|
|
110
105
|
const result = await sync();
|
|
111
106
|
if (typeof result === 'function') {
|
|
112
|
-
|
|
107
|
+
syncCleanup = result;
|
|
113
108
|
}
|
|
114
109
|
}
|
|
115
110
|
else {
|
|
@@ -117,7 +112,8 @@ export function sqlCollectionOptions({ startSync = true, ...config }) {
|
|
|
117
112
|
}
|
|
118
113
|
})();
|
|
119
114
|
return () => {
|
|
120
|
-
|
|
115
|
+
syncCleanup?.();
|
|
116
|
+
syncCleanup = undefined;
|
|
121
117
|
};
|
|
122
118
|
},
|
|
123
119
|
},
|
|
@@ -157,7 +153,10 @@ export function sqlCollectionOptions({ startSync = true, ...config }) {
|
|
|
157
153
|
}
|
|
158
154
|
const params = await syncParams;
|
|
159
155
|
await params.collection.stateWhenReady();
|
|
160
|
-
await sync(
|
|
156
|
+
const result = await sync();
|
|
157
|
+
if (typeof result === 'function') {
|
|
158
|
+
syncCleanup = result;
|
|
159
|
+
}
|
|
161
160
|
},
|
|
162
161
|
},
|
|
163
162
|
};
|