@firtoz/drizzle-indexeddb 3.0.0 → 3.0.1
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/README.md +11 -4
- package/package.json +1 -1
- package/src/collections/drizzle-indexeddb-collection.ts +33 -3
- package/src/index.ts +2 -0
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,11 @@
|
|
|
1
1
|
# @firtoz/drizzle-indexeddb
|
|
2
2
|
|
|
3
|
+
## 3.0.1
|
|
4
|
+
|
|
5
|
+
### Patch Changes
|
|
6
|
+
|
|
7
|
+
- [`8b839f2`](https://github.com/firtoz/fullstack-toolkit/commit/8b839f2227f50409af649aab87178e039aad55dc) Thanks [@firtoz](https://github.com/firtoz)! - Export collection helper types for Drizzle-backed TanStack DB collections so users can declare collection variables with preserved select and insert inference from table schemas.
|
|
8
|
+
|
|
3
9
|
## 3.0.0
|
|
4
10
|
|
|
5
11
|
### Patch Changes
|
package/README.md
CHANGED
|
@@ -100,16 +100,23 @@ Create reactive collections backed by IndexedDB:
|
|
|
100
100
|
|
|
101
101
|
```typescript
|
|
102
102
|
import { createCollection } from "@tanstack/db";
|
|
103
|
-
import {
|
|
103
|
+
import {
|
|
104
|
+
drizzleIndexedDBCollectionOptions,
|
|
105
|
+
type DrizzleIndexedDBCollection,
|
|
106
|
+
} from "@firtoz/drizzle-indexeddb";
|
|
107
|
+
import * as schema from "./schema";
|
|
104
108
|
|
|
105
109
|
const todosCollection = createCollection(
|
|
106
|
-
|
|
107
|
-
db,
|
|
108
|
-
|
|
110
|
+
drizzleIndexedDBCollectionOptions({
|
|
111
|
+
indexedDBRef: { current: db },
|
|
112
|
+
table: schema.todoTable,
|
|
113
|
+
storeName: "todos",
|
|
109
114
|
syncMode: "on-demand", // or "realtime"
|
|
110
115
|
})
|
|
111
116
|
);
|
|
112
117
|
|
|
118
|
+
type TodosCollection = DrizzleIndexedDBCollection<typeof schema.todoTable>;
|
|
119
|
+
|
|
113
120
|
// Subscribe to changes
|
|
114
121
|
const unsubscribe = todosCollection.subscribe((todos) => {
|
|
115
122
|
console.log("Todos updated:", todos);
|
package/package.json
CHANGED
|
@@ -1,4 +1,10 @@
|
|
|
1
|
-
import type {
|
|
1
|
+
import type {
|
|
2
|
+
Collection,
|
|
3
|
+
CollectionConfig,
|
|
4
|
+
InferSchemaInput,
|
|
5
|
+
InferSchemaOutput,
|
|
6
|
+
SyncMode,
|
|
7
|
+
} from "@tanstack/db";
|
|
2
8
|
import type { IR } from "@tanstack/db";
|
|
3
9
|
import { parseOrderByExpression } from "@tanstack/db";
|
|
4
10
|
import type { Table } from "drizzle-orm";
|
|
@@ -6,6 +12,8 @@ import type { Table } from "drizzle-orm";
|
|
|
6
12
|
import {
|
|
7
13
|
type IdOf,
|
|
8
14
|
type SelectSchema,
|
|
15
|
+
type InsertToSelectSchema,
|
|
16
|
+
type TableWithRequiredFields,
|
|
9
17
|
type BaseSyncConfig,
|
|
10
18
|
type SyncBackend,
|
|
11
19
|
createSyncFunction,
|
|
@@ -13,7 +21,7 @@ import {
|
|
|
13
21
|
createGetKeyFunction,
|
|
14
22
|
createCollectionConfig,
|
|
15
23
|
} from "@firtoz/drizzle-utils";
|
|
16
|
-
import { evaluateExpression } from "@firtoz/db-helpers";
|
|
24
|
+
import { evaluateExpression, type CollectionUtils } from "@firtoz/db-helpers";
|
|
17
25
|
import { tryExtractIndexedQuery } from "@firtoz/idb-collections";
|
|
18
26
|
|
|
19
27
|
import type { IDBDatabaseLike } from "../idb-types";
|
|
@@ -59,6 +67,28 @@ export interface DrizzleIndexedDBCollectionConfig<TTable extends Table> {
|
|
|
59
67
|
debug?: boolean;
|
|
60
68
|
}
|
|
61
69
|
|
|
70
|
+
export type DrizzleIndexedDBCollectionConfigResult<TTable extends Table> = Omit<
|
|
71
|
+
CollectionConfig<
|
|
72
|
+
InferSchemaOutput<SelectSchema<TTable>>,
|
|
73
|
+
IdOf<TTable>,
|
|
74
|
+
InsertToSelectSchema<TTable>,
|
|
75
|
+
CollectionUtils<InferSchemaOutput<SelectSchema<TTable>>>
|
|
76
|
+
>,
|
|
77
|
+
"utils"
|
|
78
|
+
> & {
|
|
79
|
+
schema: InsertToSelectSchema<TTable>;
|
|
80
|
+
utils: CollectionUtils<InferSchemaOutput<SelectSchema<TTable>>>;
|
|
81
|
+
};
|
|
82
|
+
|
|
83
|
+
export type DrizzleIndexedDBCollection<TTable extends TableWithRequiredFields> =
|
|
84
|
+
Collection<
|
|
85
|
+
InferSchemaOutput<SelectSchema<TTable>>,
|
|
86
|
+
IdOf<TTable>,
|
|
87
|
+
CollectionUtils<InferSchemaOutput<SelectSchema<TTable>>>,
|
|
88
|
+
InsertToSelectSchema<TTable>,
|
|
89
|
+
InferSchemaInput<InsertToSelectSchema<TTable>>
|
|
90
|
+
>;
|
|
91
|
+
|
|
62
92
|
/**
|
|
63
93
|
* Auto-discovers indexes from the IndexedDB store.
|
|
64
94
|
* Returns a map of field names to index names for single-column indexes.
|
|
@@ -84,7 +114,7 @@ function discoverIndexes(
|
|
|
84
114
|
*/
|
|
85
115
|
export function drizzleIndexedDBCollectionOptions<const TTable extends Table>(
|
|
86
116
|
config: DrizzleIndexedDBCollectionConfig<TTable>,
|
|
87
|
-
) {
|
|
117
|
+
): DrizzleIndexedDBCollectionConfigResult<TTable> {
|
|
88
118
|
let discoveredIndexes: Record<string, string> = {};
|
|
89
119
|
let indexesDiscovered = false;
|
|
90
120
|
|
package/src/index.ts
CHANGED
|
@@ -35,6 +35,8 @@ export { createInstrumentedDbCreator } from "./instrumented-idb-database";
|
|
|
35
35
|
export {
|
|
36
36
|
drizzleIndexedDBCollectionOptions,
|
|
37
37
|
type DrizzleIndexedDBCollectionConfig,
|
|
38
|
+
type DrizzleIndexedDBCollectionConfigResult,
|
|
39
|
+
type DrizzleIndexedDBCollection,
|
|
38
40
|
type DrizzleIndexedDBSyncItem,
|
|
39
41
|
} from "./collections/drizzle-indexeddb-collection";
|
|
40
42
|
|