@firtoz/drizzle-indexeddb 2.0.1 → 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 +15 -0
- package/README.md +11 -4
- package/package.json +3 -3
- package/src/collections/drizzle-indexeddb-collection.ts +33 -3
- package/src/index.ts +2 -0
- package/src/standalone-collection.ts +9 -4
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,20 @@
|
|
|
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
|
+
|
|
9
|
+
## 3.0.0
|
|
10
|
+
|
|
11
|
+
### Patch Changes
|
|
12
|
+
|
|
13
|
+
- [`b714ebb`](https://github.com/firtoz/fullstack-toolkit/commit/b714ebbb62ec0e3c3aa56c4105e7499fac11d1e5) Thanks [@firtoz](https://github.com/firtoz)! - Extract shared SQLite TanStack sync backend (`createSqliteTableSyncBackend`, IR→Drizzle helpers, `SQLOperation` types) into `@firtoz/drizzle-utils`. Add `@firtoz/drizzle-durable-sqlite` for Durable Object SQLite collections (`durableSqliteCollectionOptions`). Refactor `@firtoz/drizzle-sqlite-wasm` to use the shared backend with `driverMode: "async"`. `durableSqliteCollectionOptions` accepts optional `readyPromise` (defaults to immediate readiness). README documents the class-field Hono pattern, `app.fetch(request, env)` for bindings, optional `on-demand` + `preload` vs eager + `onFirstReady`, and `honoDoFetcherWithName` without a separate exported app type. Restore JSDoc on `DrizzleSqliteCollectionConfig` (`debug`, `checkpoint`, `interceptor`) for editor tooltips. Align `createStandaloneCollection` generics with `InsertToSelectSchema` from `@firtoz/drizzle-utils`.
|
|
14
|
+
|
|
15
|
+
- Updated dependencies [[`b714ebb`](https://github.com/firtoz/fullstack-toolkit/commit/b714ebbb62ec0e3c3aa56c4105e7499fac11d1e5)]:
|
|
16
|
+
- @firtoz/drizzle-utils@1.1.0
|
|
17
|
+
|
|
3
18
|
## 2.0.1
|
|
4
19
|
|
|
5
20
|
### 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,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@firtoz/drizzle-indexeddb",
|
|
3
|
-
"version": "
|
|
3
|
+
"version": "3.0.1",
|
|
4
4
|
"description": "IndexedDB migrations powered by Drizzle ORM",
|
|
5
5
|
"main": "./src/index.ts",
|
|
6
6
|
"module": "./src/index.ts",
|
|
@@ -68,7 +68,7 @@
|
|
|
68
68
|
"access": "public"
|
|
69
69
|
},
|
|
70
70
|
"peerDependencies": {
|
|
71
|
-
"@firtoz/drizzle-utils": ">=1.0
|
|
71
|
+
"@firtoz/drizzle-utils": ">=1.1.0",
|
|
72
72
|
"@tanstack/db": ">=0.5.33",
|
|
73
73
|
"drizzle-orm": ">=0.45.1",
|
|
74
74
|
"drizzle-valibot": ">=0.4.0",
|
|
@@ -76,7 +76,7 @@
|
|
|
76
76
|
"valibot": ">=1.3.1"
|
|
77
77
|
},
|
|
78
78
|
"devDependencies": {
|
|
79
|
-
"@firtoz/drizzle-utils": "^1.0
|
|
79
|
+
"@firtoz/drizzle-utils": "^1.1.0",
|
|
80
80
|
"@tanstack/db": "^0.5.33",
|
|
81
81
|
"@types/react": "^19.2.14",
|
|
82
82
|
"drizzle-orm": "^0.45.1",
|
|
@@ -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
|
|
|
@@ -9,7 +9,12 @@ import {
|
|
|
9
9
|
} from "@tanstack/db";
|
|
10
10
|
import type { Table } from "drizzle-orm";
|
|
11
11
|
import type { CollectionUtils } from "@firtoz/db-helpers";
|
|
12
|
-
import type {
|
|
12
|
+
import type {
|
|
13
|
+
IdOf,
|
|
14
|
+
InsertSchema,
|
|
15
|
+
InsertToSelectSchema,
|
|
16
|
+
SelectSchema,
|
|
17
|
+
} from "@firtoz/drizzle-utils";
|
|
13
18
|
import {
|
|
14
19
|
drizzleIndexedDBCollectionOptions,
|
|
15
20
|
type DrizzleIndexedDBCollectionConfig,
|
|
@@ -62,7 +67,7 @@ type InternalCollection<TTable extends Table> = Collection<
|
|
|
62
67
|
InferSchemaOutput<SelectSchema<TTable>>,
|
|
63
68
|
IdOf<TTable>,
|
|
64
69
|
CollectionUtils<InferSchemaOutput<SelectSchema<TTable>>>,
|
|
65
|
-
|
|
70
|
+
InsertToSelectSchema<TTable>,
|
|
66
71
|
InferSchemaInput<InsertSchema<TTable>>
|
|
67
72
|
>;
|
|
68
73
|
|
|
@@ -271,9 +276,9 @@ export function createStandaloneCollection<TTable extends Table>(
|
|
|
271
276
|
syncMode,
|
|
272
277
|
} as DrizzleIndexedDBCollectionConfig<TTable>);
|
|
273
278
|
|
|
274
|
-
//
|
|
279
|
+
// biome-ignore lint/suspicious/noExplicitAny: createCollection overloads can't resolve InsertToSelectSchema for generic TTable; collection is re-typed below
|
|
275
280
|
const collection = createCollection(
|
|
276
|
-
collectionConfig,
|
|
281
|
+
collectionConfig as any,
|
|
277
282
|
) as unknown as InternalCollection<TTable>;
|
|
278
283
|
|
|
279
284
|
// Wait for collection to be ready
|