@firtoz/drizzle-utils 0.3.1 → 0.3.2
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/CHANGELOG.md +6 -0
- package/package.json +3 -3
- package/src/collection-utils.ts +18 -23
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,11 @@
|
|
|
1
1
|
# @firtoz/drizzle-utils
|
|
2
2
|
|
|
3
|
+
## 0.3.2
|
|
4
|
+
|
|
5
|
+
### Patch Changes
|
|
6
|
+
|
|
7
|
+
- [`2725815`](https://github.com/firtoz/fullstack-toolkit/commit/27258158dd318b34b44ed77b88b2ac9b2b4b6a3d) Thanks [@firtoz](https://github.com/firtoz)! - Updated @tanstack/db peer dependency to >=0.5.23 for compatibility with latest versions
|
|
8
|
+
|
|
3
9
|
## 0.3.1
|
|
4
10
|
|
|
5
11
|
### Patch Changes
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@firtoz/drizzle-utils",
|
|
3
|
-
"version": "0.3.
|
|
3
|
+
"version": "0.3.2",
|
|
4
4
|
"description": "Shared utilities and types for Drizzle-based packages",
|
|
5
5
|
"main": "./src/index.ts",
|
|
6
6
|
"module": "./src/index.ts",
|
|
@@ -53,13 +53,13 @@
|
|
|
53
53
|
"access": "public"
|
|
54
54
|
},
|
|
55
55
|
"peerDependencies": {
|
|
56
|
-
"@tanstack/db": ">=0.5.
|
|
56
|
+
"@tanstack/db": ">=0.5.23",
|
|
57
57
|
"drizzle-orm": ">=0.45.1",
|
|
58
58
|
"drizzle-valibot": ">=0.4.0",
|
|
59
59
|
"valibot": ">=1.0.0"
|
|
60
60
|
},
|
|
61
61
|
"devDependencies": {
|
|
62
|
-
"@tanstack/db": "^0.5.
|
|
62
|
+
"@tanstack/db": "^0.5.23",
|
|
63
63
|
"drizzle-orm": "^0.45.1",
|
|
64
64
|
"drizzle-valibot": "^0.4.2",
|
|
65
65
|
"valibot": "^1.2.0"
|
package/src/collection-utils.ts
CHANGED
|
@@ -122,23 +122,18 @@ export interface SyncBackend<TTable extends Table> {
|
|
|
122
122
|
/**
|
|
123
123
|
* Initial data load - should call write() for each item
|
|
124
124
|
*/
|
|
125
|
-
initialLoad: (
|
|
126
|
-
write: (value: InferSchemaOutput<SelectSchema<TTable>>) => void,
|
|
127
|
-
) => Promise<void>;
|
|
125
|
+
initialLoad: () => Promise<Array<InferSchemaOutput<SelectSchema<TTable>>>>;
|
|
128
126
|
/**
|
|
129
127
|
* Load a subset of data based on query options
|
|
130
128
|
*/
|
|
131
129
|
loadSubset: (
|
|
132
130
|
options: LoadSubsetOptions,
|
|
133
|
-
|
|
134
|
-
) => Promise<void>;
|
|
131
|
+
) => Promise<Array<InferSchemaOutput<SelectSchema<TTable>>>>;
|
|
135
132
|
/**
|
|
136
133
|
* Handle insert mutations
|
|
137
134
|
*/
|
|
138
135
|
handleInsert: (
|
|
139
|
-
|
|
140
|
-
modified: InferSchemaOutput<SelectSchema<TTable>>;
|
|
141
|
-
}>,
|
|
136
|
+
items: Array<InferSchemaOutput<SelectSchema<TTable>>>,
|
|
142
137
|
) => Promise<Array<InferSchemaOutput<SelectSchema<TTable>>>>;
|
|
143
138
|
/**
|
|
144
139
|
* Handle update mutations
|
|
@@ -269,13 +264,17 @@ export function createSyncFunction<TTable extends Table>(
|
|
|
269
264
|
await config.readyPromise;
|
|
270
265
|
|
|
271
266
|
try {
|
|
267
|
+
const items = await backend.initialLoad();
|
|
268
|
+
|
|
272
269
|
begin();
|
|
273
|
-
|
|
270
|
+
|
|
271
|
+
for (const item of items) {
|
|
274
272
|
write({
|
|
275
273
|
type: "insert",
|
|
276
274
|
value: item,
|
|
277
275
|
});
|
|
278
|
-
}
|
|
276
|
+
}
|
|
277
|
+
|
|
279
278
|
commit();
|
|
280
279
|
} finally {
|
|
281
280
|
markReady();
|
|
@@ -290,9 +289,7 @@ export function createSyncFunction<TTable extends Table>(
|
|
|
290
289
|
|
|
291
290
|
insertListener = async (params) => {
|
|
292
291
|
const results = await backend.handleInsert(
|
|
293
|
-
params.transaction.mutations.map((m) =>
|
|
294
|
-
modified: m.modified,
|
|
295
|
-
})),
|
|
292
|
+
params.transaction.mutations.map((m) => m.modified),
|
|
296
293
|
);
|
|
297
294
|
|
|
298
295
|
begin();
|
|
@@ -334,20 +331,18 @@ export function createSyncFunction<TTable extends Table>(
|
|
|
334
331
|
const loadSubset = async (options: LoadSubsetOptions) => {
|
|
335
332
|
await config.readyPromise;
|
|
336
333
|
|
|
334
|
+
const items = await backend.loadSubset(options);
|
|
335
|
+
|
|
337
336
|
begin();
|
|
338
337
|
|
|
339
|
-
|
|
340
|
-
|
|
341
|
-
|
|
342
|
-
|
|
343
|
-
value: item,
|
|
344
|
-
});
|
|
338
|
+
for (const item of items) {
|
|
339
|
+
write({
|
|
340
|
+
type: "insert",
|
|
341
|
+
value: item,
|
|
345
342
|
});
|
|
346
|
-
commit();
|
|
347
|
-
} catch (error) {
|
|
348
|
-
commit();
|
|
349
|
-
throw error;
|
|
350
343
|
}
|
|
344
|
+
|
|
345
|
+
commit();
|
|
351
346
|
};
|
|
352
347
|
|
|
353
348
|
// Create deduplicated loadSubset wrapper to avoid redundant queries
|