@firtoz/drizzle-indexeddb 4.0.1 → 5.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 +26 -0
- package/README.md +9 -1
- package/dist/bin/generate-migrations.d.ts +15 -0
- package/dist/bin/generate-migrations.js +184 -0
- package/dist/bin/generate-migrations.js.map +1 -0
- package/dist/chunk-5KCMKETG.js +212 -0
- package/dist/chunk-5KCMKETG.js.map +1 -0
- package/dist/chunk-7X4EIKN4.js +128 -0
- package/dist/chunk-7X4EIKN4.js.map +1 -0
- package/dist/chunk-CPLA7X66.js +129 -0
- package/dist/chunk-CPLA7X66.js.map +1 -0
- package/dist/chunk-HJFI7QKW.js +28 -0
- package/dist/chunk-HJFI7QKW.js.map +1 -0
- package/dist/chunk-JVUF63L6.js +27 -0
- package/dist/chunk-JVUF63L6.js.map +1 -0
- package/dist/chunk-OSOLYU2M.js +126 -0
- package/dist/chunk-OSOLYU2M.js.map +1 -0
- package/dist/chunk-WMCUJFEC.js +311 -0
- package/dist/chunk-WMCUJFEC.js.map +1 -0
- package/dist/chunk-Y6XE3FVT.js +147 -0
- package/dist/chunk-Y6XE3FVT.js.map +1 -0
- package/dist/collections/drizzle-indexeddb-collection.d.ts +62 -0
- package/dist/collections/drizzle-indexeddb-collection.js +3 -0
- package/dist/collections/drizzle-indexeddb-collection.js.map +1 -0
- package/dist/context/DrizzleIndexedDBProvider.d.ts +35 -0
- package/dist/context/DrizzleIndexedDBProvider.js +7 -0
- package/dist/context/DrizzleIndexedDBProvider.js.map +1 -0
- package/dist/context/useDrizzleIndexedDB.d.ts +17 -0
- package/dist/context/useDrizzleIndexedDB.js +8 -0
- package/dist/context/useDrizzleIndexedDB.js.map +1 -0
- package/dist/function-migrator.d.ts +56 -0
- package/dist/function-migrator.js +5 -0
- package/dist/function-migrator.js.map +1 -0
- package/dist/idb-interceptor.d.ts +68 -0
- package/dist/idb-interceptor.js +3 -0
- package/dist/idb-interceptor.js.map +1 -0
- package/dist/idb-operations.d.ts +13 -0
- package/dist/idb-operations.js +4 -0
- package/dist/idb-operations.js.map +1 -0
- package/dist/idb-types.d.ts +82 -0
- package/dist/idb-types.js +3 -0
- package/dist/idb-types.js.map +1 -0
- package/dist/index.d.ts +17 -0
- package/dist/index.js +10 -0
- package/dist/index.js.map +1 -0
- package/dist/instrumented-idb-database.d.ts +17 -0
- package/dist/instrumented-idb-database.js +4 -0
- package/dist/instrumented-idb-database.js.map +1 -0
- package/dist/native-idb-database.d.ts +9 -0
- package/dist/native-idb-database.js +3 -0
- package/dist/native-idb-database.js.map +1 -0
- package/dist/standalone-collection.d.ts +154 -0
- package/dist/standalone-collection.js +7 -0
- package/dist/standalone-collection.js.map +1 -0
- package/package.json +34 -29
- package/src/collections/drizzle-indexeddb-collection.ts +4 -4
- package/src/context/DrizzleIndexedDBProvider.tsx +1 -1
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import { useIndexedDBCollection } from './DrizzleIndexedDBProvider.js';
|
|
2
|
+
import { IDBDatabaseLike } from '../idb-types.js';
|
|
3
|
+
import 'react/jsx-runtime';
|
|
4
|
+
import 'react';
|
|
5
|
+
import '@tanstack/db';
|
|
6
|
+
import '@firtoz/db-helpers';
|
|
7
|
+
import '@firtoz/drizzle-utils';
|
|
8
|
+
import '../function-migrator.js';
|
|
9
|
+
import '@firtoz/idb-collections';
|
|
10
|
+
|
|
11
|
+
type UseDrizzleIndexedDBContextReturn<TSchema extends Record<string, unknown>> = {
|
|
12
|
+
useCollection: <TTableName extends keyof TSchema & string>(tableName: TTableName) => ReturnType<typeof useIndexedDBCollection<TSchema, TTableName>>;
|
|
13
|
+
indexedDB: IDBDatabaseLike | null;
|
|
14
|
+
};
|
|
15
|
+
declare function useDrizzleIndexedDB<TSchema extends Record<string, unknown>>(): UseDrizzleIndexedDBContextReturn<TSchema>;
|
|
16
|
+
|
|
17
|
+
export { type UseDrizzleIndexedDBContextReturn, useDrizzleIndexedDB };
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
export { useDrizzleIndexedDB } from '../chunk-HJFI7QKW.js';
|
|
2
|
+
import '../chunk-Y6XE3FVT.js';
|
|
3
|
+
import '../chunk-5KCMKETG.js';
|
|
4
|
+
import '../chunk-7X4EIKN4.js';
|
|
5
|
+
import '../chunk-JVUF63L6.js';
|
|
6
|
+
import '../chunk-WMCUJFEC.js';
|
|
7
|
+
//# sourceMappingURL=useDrizzleIndexedDB.js.map
|
|
8
|
+
//# sourceMappingURL=useDrizzleIndexedDB.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":[],"names":[],"mappings":"","file":"useDrizzleIndexedDB.js"}
|
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
import { IDBCreator, IDBDatabaseLike } from './idb-types.js';
|
|
2
|
+
import '@firtoz/idb-collections';
|
|
3
|
+
|
|
4
|
+
interface CreateTableOperation {
|
|
5
|
+
type: "createTable";
|
|
6
|
+
name: string;
|
|
7
|
+
keyPath?: string;
|
|
8
|
+
autoIncrement?: boolean;
|
|
9
|
+
indexes?: Array<{
|
|
10
|
+
name: string;
|
|
11
|
+
keyPath: string | string[];
|
|
12
|
+
unique?: boolean;
|
|
13
|
+
}>;
|
|
14
|
+
}
|
|
15
|
+
interface DeleteTableOperation {
|
|
16
|
+
type: "deleteTable";
|
|
17
|
+
name: string;
|
|
18
|
+
}
|
|
19
|
+
interface CreateIndexOperation {
|
|
20
|
+
type: "createIndex";
|
|
21
|
+
tableName: string;
|
|
22
|
+
indexName: string;
|
|
23
|
+
keyPath: string | string[];
|
|
24
|
+
unique?: boolean;
|
|
25
|
+
}
|
|
26
|
+
interface DeleteIndexOperation {
|
|
27
|
+
type: "deleteIndex";
|
|
28
|
+
tableName: string;
|
|
29
|
+
indexName: string;
|
|
30
|
+
}
|
|
31
|
+
type MigrationOperation = CreateTableOperation | DeleteTableOperation | CreateIndexOperation | DeleteIndexOperation;
|
|
32
|
+
/** A migration is an array of operations to perform */
|
|
33
|
+
type Migration = MigrationOperation[];
|
|
34
|
+
/**
|
|
35
|
+
* Runs IndexedDB migrations using declarative migration arrays.
|
|
36
|
+
* Version = total migrations + 1.
|
|
37
|
+
*
|
|
38
|
+
* Example usage:
|
|
39
|
+
* ```typescript
|
|
40
|
+
* const migrations: Migration[] = [
|
|
41
|
+
* [
|
|
42
|
+
* { type: "createTable", name: "todo", keyPath: "id", indexes: [
|
|
43
|
+
* { name: "todo_user_id", keyPath: "user_id" }
|
|
44
|
+
* ]}
|
|
45
|
+
* ],
|
|
46
|
+
* [
|
|
47
|
+
* { type: "createTable", name: "user", keyPath: "id" }
|
|
48
|
+
* ]
|
|
49
|
+
* ];
|
|
50
|
+
*
|
|
51
|
+
* const db = await migrateIndexedDBWithFunctions('my-db', migrations);
|
|
52
|
+
* ```
|
|
53
|
+
*/
|
|
54
|
+
declare function migrateIndexedDBWithFunctions(dbName: string, migrations: Migration[], debug?: boolean, dbCreator?: IDBCreator): Promise<IDBDatabaseLike>;
|
|
55
|
+
|
|
56
|
+
export { type CreateIndexOperation, type CreateTableOperation, type DeleteIndexOperation, type DeleteTableOperation, type Migration, type MigrationOperation, migrateIndexedDBWithFunctions };
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":[],"names":[],"mappings":"","file":"function-migrator.js"}
|
|
@@ -0,0 +1,68 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Operation tracking for IndexedDB queries
|
|
3
|
+
* Useful for testing and debugging to verify what operations are actually performed
|
|
4
|
+
*
|
|
5
|
+
* Uses discriminated unions for type safety - TypeScript can narrow the type based on the 'type' field
|
|
6
|
+
*/
|
|
7
|
+
type IDBOperation = {
|
|
8
|
+
type: "getAll";
|
|
9
|
+
storeName: string;
|
|
10
|
+
itemsReturned: unknown[];
|
|
11
|
+
itemCount: number;
|
|
12
|
+
context?: string;
|
|
13
|
+
timestamp: number;
|
|
14
|
+
} | {
|
|
15
|
+
type: "index-getAll";
|
|
16
|
+
storeName: string;
|
|
17
|
+
indexName: string;
|
|
18
|
+
keyRange?: IDBKeyRange;
|
|
19
|
+
itemsReturned: unknown[];
|
|
20
|
+
itemCount: number;
|
|
21
|
+
context?: string;
|
|
22
|
+
timestamp: number;
|
|
23
|
+
} | {
|
|
24
|
+
type: "write";
|
|
25
|
+
storeName: string;
|
|
26
|
+
itemsWritten: unknown[];
|
|
27
|
+
writeCount: number;
|
|
28
|
+
context?: string;
|
|
29
|
+
timestamp: number;
|
|
30
|
+
} | {
|
|
31
|
+
type: "get";
|
|
32
|
+
storeName: string;
|
|
33
|
+
key: IDBValidKey;
|
|
34
|
+
itemReturned?: unknown;
|
|
35
|
+
timestamp: number;
|
|
36
|
+
} | {
|
|
37
|
+
type: "put";
|
|
38
|
+
storeName: string;
|
|
39
|
+
items: unknown[];
|
|
40
|
+
itemCount: number;
|
|
41
|
+
timestamp: number;
|
|
42
|
+
} | {
|
|
43
|
+
type: "add";
|
|
44
|
+
storeName: string;
|
|
45
|
+
items: unknown[];
|
|
46
|
+
itemCount: number;
|
|
47
|
+
timestamp: number;
|
|
48
|
+
} | {
|
|
49
|
+
type: "delete";
|
|
50
|
+
storeName: string;
|
|
51
|
+
keys: IDBValidKey[];
|
|
52
|
+
keyCount: number;
|
|
53
|
+
timestamp: number;
|
|
54
|
+
} | {
|
|
55
|
+
type: "clear";
|
|
56
|
+
storeName: string;
|
|
57
|
+
timestamp: number;
|
|
58
|
+
};
|
|
59
|
+
/**
|
|
60
|
+
* Interceptor interface for tracking IndexedDB operations
|
|
61
|
+
* Allows tests and debugging tools to observe what operations are performed
|
|
62
|
+
*/
|
|
63
|
+
interface IDBInterceptor {
|
|
64
|
+
/** Called when any IndexedDB operation is performed */
|
|
65
|
+
onOperation?: (operation: IDBOperation) => void;
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
export type { IDBInterceptor, IDBOperation };
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":[],"names":[],"mappings":"","file":"idb-interceptor.js"}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import { IDBCreator, IDBOpenOptions, IDBDatabaseLike, IDBDeleter } from './idb-types.js';
|
|
2
|
+
import '@firtoz/idb-collections';
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
* Opens an IndexedDB database using the provided creator or the default native implementation.
|
|
6
|
+
*/
|
|
7
|
+
declare function openIndexedDb(name: string, dbCreator?: IDBCreator, options?: IDBOpenOptions): Promise<IDBDatabaseLike>;
|
|
8
|
+
/**
|
|
9
|
+
* Deletes an IndexedDB database (useful for testing)
|
|
10
|
+
*/
|
|
11
|
+
declare function deleteIndexedDB(dbName: string, dbDeleter?: IDBDeleter): Promise<void>;
|
|
12
|
+
|
|
13
|
+
export { deleteIndexedDB, openIndexedDb };
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":[],"names":[],"mappings":"","file":"idb-operations.js"}
|
|
@@ -0,0 +1,82 @@
|
|
|
1
|
+
import { KeyRangeSpec } from '@firtoz/idb-collections';
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* Index information returned by getStoreIndexes
|
|
5
|
+
*/
|
|
6
|
+
interface IndexInfo {
|
|
7
|
+
name: string;
|
|
8
|
+
keyPath: string | string[];
|
|
9
|
+
}
|
|
10
|
+
/**
|
|
11
|
+
* Options for creating an object store
|
|
12
|
+
*/
|
|
13
|
+
interface CreateStoreOptions {
|
|
14
|
+
keyPath?: string;
|
|
15
|
+
autoIncrement?: boolean;
|
|
16
|
+
}
|
|
17
|
+
/**
|
|
18
|
+
* Options for creating an index
|
|
19
|
+
*/
|
|
20
|
+
interface CreateIndexOptions {
|
|
21
|
+
unique?: boolean;
|
|
22
|
+
}
|
|
23
|
+
/**
|
|
24
|
+
* Minimal database interface with high-level async operations.
|
|
25
|
+
* This is the interface that custom implementations (mocks, Chrome extension proxies, etc.) need to implement.
|
|
26
|
+
*
|
|
27
|
+
* All operations are simple async functions - no transactions, requests, or callbacks to deal with.
|
|
28
|
+
*/
|
|
29
|
+
interface IDBDatabaseLike {
|
|
30
|
+
/** Database version number */
|
|
31
|
+
readonly version: number;
|
|
32
|
+
/** Check if a store exists */
|
|
33
|
+
hasStore(storeName: string): boolean;
|
|
34
|
+
/** Get list of all store names */
|
|
35
|
+
getStoreNames(): string[];
|
|
36
|
+
/** Create an object store (only valid during migrations) */
|
|
37
|
+
createStore(storeName: string, options?: CreateStoreOptions): void;
|
|
38
|
+
/** Delete an object store (only valid during migrations) */
|
|
39
|
+
deleteStore(storeName: string): void;
|
|
40
|
+
/** Create an index on a store (only valid during migrations) */
|
|
41
|
+
createIndex(storeName: string, indexName: string, keyPath: string | string[], options?: CreateIndexOptions): void;
|
|
42
|
+
/** Delete an index from a store (only valid during migrations) */
|
|
43
|
+
deleteIndex(storeName: string, indexName: string): void;
|
|
44
|
+
/** Get all indexes for a store (for index discovery) */
|
|
45
|
+
getStoreIndexes(storeName: string): IndexInfo[];
|
|
46
|
+
/** Get all items from a store */
|
|
47
|
+
getAll<T = unknown>(storeName: string): Promise<T[]>;
|
|
48
|
+
/** Get items from a store using an index with optional key range */
|
|
49
|
+
getAllByIndex<T = unknown>(storeName: string, indexName: string, keyRange?: KeyRangeSpec): Promise<T[]>;
|
|
50
|
+
/** Get a single item by key */
|
|
51
|
+
get<T = unknown>(storeName: string, key: IDBValidKey): Promise<T | undefined>;
|
|
52
|
+
/** Add items to a store (batch operation) */
|
|
53
|
+
add(storeName: string, items: unknown[]): Promise<void>;
|
|
54
|
+
/** Update items in a store (batch operation, uses put) */
|
|
55
|
+
put(storeName: string, items: unknown[]): Promise<void>;
|
|
56
|
+
/** Delete items from a store by keys (batch operation) */
|
|
57
|
+
delete(storeName: string, keys: IDBValidKey[]): Promise<void>;
|
|
58
|
+
/** Clear all items from a store */
|
|
59
|
+
clear(storeName: string): Promise<void>;
|
|
60
|
+
/** Close the database connection */
|
|
61
|
+
close(): void;
|
|
62
|
+
}
|
|
63
|
+
/**
|
|
64
|
+
* Options for opening a database with version upgrade support.
|
|
65
|
+
*/
|
|
66
|
+
interface IDBOpenOptions {
|
|
67
|
+
/** Target version for the database. If higher than current, triggers upgrade. */
|
|
68
|
+
version?: number;
|
|
69
|
+
/** Called during version upgrade - this is where schema changes (createStore, createIndex) are allowed. */
|
|
70
|
+
onUpgrade?: (db: IDBDatabaseLike) => void;
|
|
71
|
+
}
|
|
72
|
+
/**
|
|
73
|
+
* Function type for creating/opening an IndexedDB-like database.
|
|
74
|
+
* Custom implementations can use this to provide proxy/mock/alternative backends.
|
|
75
|
+
*/
|
|
76
|
+
type IDBCreator = (name: string, options?: IDBOpenOptions) => Promise<IDBDatabaseLike>;
|
|
77
|
+
/**
|
|
78
|
+
* Function type for deleting an IndexedDB database.
|
|
79
|
+
*/
|
|
80
|
+
type IDBDeleter = (name: string) => Promise<void>;
|
|
81
|
+
|
|
82
|
+
export type { CreateIndexOptions, CreateStoreOptions, IDBCreator, IDBDatabaseLike, IDBDeleter, IDBOpenOptions, IndexInfo };
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":[],"names":[],"mappings":"","file":"idb-types.js"}
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
export { CreateIndexOperation, CreateTableOperation, DeleteIndexOperation, DeleteTableOperation, Migration, MigrationOperation, migrateIndexedDBWithFunctions } from './function-migrator.js';
|
|
2
|
+
export { CreateIndexOptions, CreateStoreOptions, IDBCreator, IDBDatabaseLike, IDBDeleter, IDBOpenOptions, IndexInfo } from './idb-types.js';
|
|
3
|
+
export { IDBInterceptor, IDBOperation } from './idb-interceptor.js';
|
|
4
|
+
export { deleteIndexedDB, openIndexedDb } from './idb-operations.js';
|
|
5
|
+
export { defaultIDBCreator } from './native-idb-database.js';
|
|
6
|
+
export { createInstrumentedDbCreator } from './instrumented-idb-database.js';
|
|
7
|
+
export { DrizzleIndexedDBCollection, DrizzleIndexedDBCollectionConfig, DrizzleIndexedDBCollectionConfigResult, DrizzleIndexedDBSyncItem, drizzleIndexedDBCollectionOptions } from './collections/drizzle-indexeddb-collection.js';
|
|
8
|
+
export { StandaloneCollection, StandaloneCollectionConfig, createStandaloneCollection } from './standalone-collection.js';
|
|
9
|
+
export { DrizzleIndexedDBContext, DrizzleIndexedDBContextValue, DrizzleIndexedDBProvider, IndexedDbCollection, useIndexedDBCollection } from './context/DrizzleIndexedDBProvider.js';
|
|
10
|
+
export { UseDrizzleIndexedDBContextReturn, useDrizzleIndexedDB } from './context/useDrizzleIndexedDB.js';
|
|
11
|
+
import '@firtoz/idb-collections';
|
|
12
|
+
import '@tanstack/db';
|
|
13
|
+
import 'drizzle-orm';
|
|
14
|
+
import '@firtoz/drizzle-utils';
|
|
15
|
+
import '@firtoz/db-helpers';
|
|
16
|
+
import 'react/jsx-runtime';
|
|
17
|
+
import 'react';
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
export { createInstrumentedDbCreator } from './chunk-OSOLYU2M.js';
|
|
2
|
+
export { createStandaloneCollection } from './chunk-CPLA7X66.js';
|
|
3
|
+
export { useDrizzleIndexedDB } from './chunk-HJFI7QKW.js';
|
|
4
|
+
export { DrizzleIndexedDBContext, DrizzleIndexedDBProvider, useIndexedDBCollection } from './chunk-Y6XE3FVT.js';
|
|
5
|
+
export { drizzleIndexedDBCollectionOptions } from './chunk-5KCMKETG.js';
|
|
6
|
+
export { migrateIndexedDBWithFunctions } from './chunk-7X4EIKN4.js';
|
|
7
|
+
export { deleteIndexedDB, openIndexedDb } from './chunk-JVUF63L6.js';
|
|
8
|
+
export { defaultIDBCreator } from './chunk-WMCUJFEC.js';
|
|
9
|
+
//# sourceMappingURL=index.js.map
|
|
10
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":[],"names":[],"mappings":"","file":"index.js"}
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import { IDBCreator } from './idb-types.js';
|
|
2
|
+
import { IDBInterceptor } from './idb-interceptor.js';
|
|
3
|
+
import '@firtoz/idb-collections';
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
* Creates an instrumented database creator that wraps operations with interception.
|
|
7
|
+
* Use this for testing to verify what IndexedDB operations are performed.
|
|
8
|
+
*
|
|
9
|
+
* @example
|
|
10
|
+
* const interceptor = { onOperation: (op) => console.log(op) };
|
|
11
|
+
* const dbCreator = createInstrumentedDbCreator(interceptor);
|
|
12
|
+
*
|
|
13
|
+
* <DrizzleIndexedDBProvider dbCreator={dbCreator} ... />
|
|
14
|
+
*/
|
|
15
|
+
declare function createInstrumentedDbCreator(interceptor: IDBInterceptor, baseCreator?: IDBCreator): IDBCreator;
|
|
16
|
+
|
|
17
|
+
export { createInstrumentedDbCreator };
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":[],"names":[],"mappings":"","file":"instrumented-idb-database.js"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":[],"names":[],"mappings":"","file":"native-idb-database.js"}
|
|
@@ -0,0 +1,154 @@
|
|
|
1
|
+
import { SyncMode, InferSchemaOutput, InferSchemaInput, Transaction, WritableDeep, Collection } from '@tanstack/db';
|
|
2
|
+
import { Table } from 'drizzle-orm';
|
|
3
|
+
import { CollectionUtils } from '@firtoz/db-helpers';
|
|
4
|
+
import { SelectSchema, IdOf, InsertSchema, InsertToSelectSchema } from '@firtoz/drizzle-utils';
|
|
5
|
+
import { Migration } from './function-migrator.js';
|
|
6
|
+
import { IDBCreator, IDBDatabaseLike } from './idb-types.js';
|
|
7
|
+
import '@firtoz/idb-collections';
|
|
8
|
+
|
|
9
|
+
/**
|
|
10
|
+
* Configuration for creating a standalone IndexedDB collection
|
|
11
|
+
*/
|
|
12
|
+
interface StandaloneCollectionConfig<TTable extends Table> {
|
|
13
|
+
/**
|
|
14
|
+
* Name of the IndexedDB database
|
|
15
|
+
*/
|
|
16
|
+
dbName: string;
|
|
17
|
+
/**
|
|
18
|
+
* The Drizzle table definition
|
|
19
|
+
*/
|
|
20
|
+
table: TTable;
|
|
21
|
+
/**
|
|
22
|
+
* The name of the IndexedDB object store (defaults to table name)
|
|
23
|
+
*/
|
|
24
|
+
storeName?: string;
|
|
25
|
+
/**
|
|
26
|
+
* Migrations to apply (optional)
|
|
27
|
+
*/
|
|
28
|
+
migrations?: Migration[];
|
|
29
|
+
/**
|
|
30
|
+
* Custom database creator (for testing/mocking)
|
|
31
|
+
*/
|
|
32
|
+
dbCreator?: IDBCreator;
|
|
33
|
+
/**
|
|
34
|
+
* Enable debug logging
|
|
35
|
+
*/
|
|
36
|
+
debug?: boolean;
|
|
37
|
+
/**
|
|
38
|
+
* Sync mode: 'eager' (immediate) or 'lazy' (on-demand)
|
|
39
|
+
*/
|
|
40
|
+
syncMode?: SyncMode;
|
|
41
|
+
}
|
|
42
|
+
/**
|
|
43
|
+
* Type for the underlying collection
|
|
44
|
+
*/
|
|
45
|
+
type InternalCollection<TTable extends Table> = Collection<InferSchemaOutput<SelectSchema<TTable>>, IdOf<TTable>, CollectionUtils<InferSchemaOutput<SelectSchema<TTable>>>, InsertToSelectSchema<TTable>, InferSchemaInput<InsertSchema<TTable>>>;
|
|
46
|
+
/**
|
|
47
|
+
* Transaction type for mutations
|
|
48
|
+
*/
|
|
49
|
+
type MutationTransaction<TTable extends Table> = Transaction<InferSchemaOutput<SelectSchema<TTable>>>;
|
|
50
|
+
/**
|
|
51
|
+
* Insert input type (what you pass to insert)
|
|
52
|
+
*/
|
|
53
|
+
type InsertInput<TTable extends Table> = InferSchemaInput<InsertSchema<TTable>>;
|
|
54
|
+
/**
|
|
55
|
+
* Item type (what you get back from getAll, etc.)
|
|
56
|
+
*/
|
|
57
|
+
type ItemType<TTable extends Table> = InferSchemaOutput<SelectSchema<TTable>>;
|
|
58
|
+
/**
|
|
59
|
+
* Writable draft type for update callbacks
|
|
60
|
+
*/
|
|
61
|
+
type DraftType<TTable extends Table> = WritableDeep<InsertInput<TTable>>;
|
|
62
|
+
/**
|
|
63
|
+
* Standalone IndexedDB collection API
|
|
64
|
+
*/
|
|
65
|
+
interface StandaloneCollection<TTable extends Table> {
|
|
66
|
+
/**
|
|
67
|
+
* Promise that resolves when the collection is ready
|
|
68
|
+
*/
|
|
69
|
+
ready: Promise<void>;
|
|
70
|
+
/**
|
|
71
|
+
* Check if the collection is ready (sync)
|
|
72
|
+
*/
|
|
73
|
+
isReady(): boolean;
|
|
74
|
+
/**
|
|
75
|
+
* Get all items (sync - returns current state)
|
|
76
|
+
*/
|
|
77
|
+
getAll(): ItemType<TTable>[];
|
|
78
|
+
/**
|
|
79
|
+
* Get an item by key (sync)
|
|
80
|
+
*/
|
|
81
|
+
get(key: IdOf<TTable>): ItemType<TTable> | undefined;
|
|
82
|
+
/**
|
|
83
|
+
* Insert item(s)
|
|
84
|
+
* @returns Promise that resolves when persisted
|
|
85
|
+
*/
|
|
86
|
+
insert(data: InsertInput<TTable> | InsertInput<TTable>[], callback?: (transaction: MutationTransaction<TTable>) => void): Promise<MutationTransaction<TTable>>;
|
|
87
|
+
/**
|
|
88
|
+
* Update an item by key using a callback that receives a draft
|
|
89
|
+
* @returns Promise that resolves when persisted
|
|
90
|
+
*/
|
|
91
|
+
update(key: IdOf<TTable>, updater: (draft: DraftType<TTable>) => void, callback?: (transaction: MutationTransaction<TTable>) => void): Promise<MutationTransaction<TTable>>;
|
|
92
|
+
/**
|
|
93
|
+
* Delete item(s) by key
|
|
94
|
+
* @returns Promise that resolves when persisted
|
|
95
|
+
*/
|
|
96
|
+
delete(key: IdOf<TTable> | IdOf<TTable>[], callback?: (transaction: MutationTransaction<TTable>) => void): Promise<MutationTransaction<TTable>>;
|
|
97
|
+
/**
|
|
98
|
+
* Clear all items from the store
|
|
99
|
+
* @returns Promise that resolves when truncate is complete
|
|
100
|
+
*/
|
|
101
|
+
truncate(): Promise<void>;
|
|
102
|
+
/**
|
|
103
|
+
* Access to collection utils (truncate, receiveSync)
|
|
104
|
+
*/
|
|
105
|
+
utils: CollectionUtils<ItemType<TTable>>;
|
|
106
|
+
/**
|
|
107
|
+
* The underlying TanStack DB collection (for advanced usage)
|
|
108
|
+
*/
|
|
109
|
+
collection: InternalCollection<TTable>;
|
|
110
|
+
/**
|
|
111
|
+
* The IndexedDB database instance (available after ready)
|
|
112
|
+
*/
|
|
113
|
+
db: IDBDatabaseLike | null;
|
|
114
|
+
/**
|
|
115
|
+
* Close the database connection
|
|
116
|
+
*/
|
|
117
|
+
close(): void;
|
|
118
|
+
}
|
|
119
|
+
/**
|
|
120
|
+
* Create a standalone IndexedDB collection for use outside of React.
|
|
121
|
+
*
|
|
122
|
+
* @example
|
|
123
|
+
* ```ts
|
|
124
|
+
* const db = await createStandaloneCollection({
|
|
125
|
+
* dbName: "myapp.db",
|
|
126
|
+
* table: schema.todos,
|
|
127
|
+
* migrations,
|
|
128
|
+
* });
|
|
129
|
+
*
|
|
130
|
+
* // Wait for ready
|
|
131
|
+
* await db.ready;
|
|
132
|
+
*
|
|
133
|
+
* // Get all items
|
|
134
|
+
* const items = db.getAll();
|
|
135
|
+
*
|
|
136
|
+
* // Insert
|
|
137
|
+
* await db.insert({ title: "New todo" });
|
|
138
|
+
*
|
|
139
|
+
* // Update
|
|
140
|
+
* await db.update(itemId, { title: "Updated" });
|
|
141
|
+
*
|
|
142
|
+
* // Delete
|
|
143
|
+
* await db.delete(itemId);
|
|
144
|
+
*
|
|
145
|
+
* // Truncate
|
|
146
|
+
* await db.truncate();
|
|
147
|
+
*
|
|
148
|
+
* // Clean up
|
|
149
|
+
* db.close();
|
|
150
|
+
* ```
|
|
151
|
+
*/
|
|
152
|
+
declare function createStandaloneCollection<TTable extends Table>(config: StandaloneCollectionConfig<TTable>): StandaloneCollection<TTable>;
|
|
153
|
+
|
|
154
|
+
export { type StandaloneCollection, type StandaloneCollectionConfig, createStandaloneCollection };
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
export { createStandaloneCollection } from './chunk-CPLA7X66.js';
|
|
2
|
+
import './chunk-5KCMKETG.js';
|
|
3
|
+
import './chunk-7X4EIKN4.js';
|
|
4
|
+
import './chunk-JVUF63L6.js';
|
|
5
|
+
import './chunk-WMCUJFEC.js';
|
|
6
|
+
//# sourceMappingURL=standalone-collection.js.map
|
|
7
|
+
//# sourceMappingURL=standalone-collection.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":[],"names":[],"mappings":"","file":"standalone-collection.js"}
|
package/package.json
CHANGED
|
@@ -1,37 +1,40 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@firtoz/drizzle-indexeddb",
|
|
3
|
-
"version": "
|
|
3
|
+
"version": "5.0.1",
|
|
4
4
|
"description": "IndexedDB migrations powered by Drizzle ORM",
|
|
5
|
-
"main": "./
|
|
6
|
-
"module": "./
|
|
7
|
-
"types": "./
|
|
5
|
+
"main": "./dist/index.js",
|
|
6
|
+
"module": "./dist/index.js",
|
|
7
|
+
"types": "./dist/index.d.ts",
|
|
8
8
|
"type": "module",
|
|
9
9
|
"bin": {
|
|
10
|
-
"drizzle-indexeddb-generate": "./
|
|
10
|
+
"drizzle-indexeddb-generate": "./dist/bin/generate-migrations.js"
|
|
11
11
|
},
|
|
12
12
|
"exports": {
|
|
13
13
|
".": {
|
|
14
|
-
"types": "./
|
|
15
|
-
"import": "./
|
|
16
|
-
"require": "./src/index.ts"
|
|
14
|
+
"types": "./dist/index.d.ts",
|
|
15
|
+
"import": "./dist/index.js"
|
|
17
16
|
},
|
|
18
17
|
"./generate": {
|
|
19
|
-
"types": "./
|
|
20
|
-
"import": "./
|
|
21
|
-
"require": "./src/bin/generate-migrations.ts"
|
|
18
|
+
"types": "./dist/bin/generate-migrations.d.ts",
|
|
19
|
+
"import": "./dist/bin/generate-migrations.js"
|
|
22
20
|
},
|
|
23
|
-
"
|
|
24
|
-
"types": "./
|
|
25
|
-
"import": "./
|
|
26
|
-
|
|
21
|
+
"./collections/*": {
|
|
22
|
+
"types": "./dist/collections/*.d.ts",
|
|
23
|
+
"import": "./dist/collections/*.js"
|
|
24
|
+
},
|
|
25
|
+
"./context/*": {
|
|
26
|
+
"types": "./dist/context/*.d.ts",
|
|
27
|
+
"import": "./dist/context/*.js"
|
|
27
28
|
},
|
|
28
|
-
"
|
|
29
|
-
"types": "./
|
|
30
|
-
"import": "./
|
|
31
|
-
"require": "./src/*.tsx"
|
|
29
|
+
"./*": {
|
|
30
|
+
"types": "./dist/*.d.ts",
|
|
31
|
+
"import": "./dist/*.js"
|
|
32
32
|
}
|
|
33
33
|
},
|
|
34
34
|
"files": [
|
|
35
|
+
"dist/**/*.js",
|
|
36
|
+
"dist/**/*.js.map",
|
|
37
|
+
"dist/**/*.d.ts",
|
|
35
38
|
"src/**/*.ts",
|
|
36
39
|
"src/**/*.tsx",
|
|
37
40
|
"!src/**/*.test.ts",
|
|
@@ -39,6 +42,8 @@
|
|
|
39
42
|
"CHANGELOG.md"
|
|
40
43
|
],
|
|
41
44
|
"scripts": {
|
|
45
|
+
"build": "tsup && bun ../../scripts/add-node-shebang.ts dist/bin/generate-migrations.js",
|
|
46
|
+
"prepack": "bun run build",
|
|
42
47
|
"typecheck": "tsgo --noEmit -p ./tsconfig.json",
|
|
43
48
|
"lint": "biome check --write src",
|
|
44
49
|
"lint:ci": "biome ci src",
|
|
@@ -68,26 +73,26 @@
|
|
|
68
73
|
"access": "public"
|
|
69
74
|
},
|
|
70
75
|
"peerDependencies": {
|
|
71
|
-
"@firtoz/drizzle-utils": ">=1.
|
|
72
|
-
"@tanstack/db": ">=0.6.
|
|
76
|
+
"@firtoz/drizzle-utils": ">=1.3.1",
|
|
77
|
+
"@tanstack/db": ">=0.6.5",
|
|
73
78
|
"drizzle-orm": ">=0.45.2",
|
|
74
79
|
"drizzle-valibot": ">=0.4.0",
|
|
75
|
-
"react": ">=19.2.
|
|
80
|
+
"react": ">=19.2.5",
|
|
76
81
|
"valibot": ">=1.3.1"
|
|
77
82
|
},
|
|
78
83
|
"devDependencies": {
|
|
79
|
-
"@firtoz/drizzle-utils": "^1.
|
|
80
|
-
"@tanstack/db": "^0.6.
|
|
84
|
+
"@firtoz/drizzle-utils": "^1.3.1",
|
|
85
|
+
"@tanstack/db": "^0.6.5",
|
|
81
86
|
"@types/react": "^19.2.14",
|
|
82
87
|
"drizzle-orm": "^0.45.2",
|
|
83
88
|
"drizzle-valibot": "^0.4.2",
|
|
84
|
-
"react": "^19.2.
|
|
89
|
+
"react": "^19.2.5",
|
|
85
90
|
"valibot": "^1.3.1"
|
|
86
91
|
},
|
|
87
92
|
"dependencies": {
|
|
88
|
-
"@firtoz/db-helpers": "^2.
|
|
89
|
-
"@firtoz/idb-collections": "^0.
|
|
90
|
-
"@firtoz/maybe-error": "^1.
|
|
91
|
-
"citty": "^0.2.
|
|
93
|
+
"@firtoz/db-helpers": "^2.2.1",
|
|
94
|
+
"@firtoz/idb-collections": "^0.3.1",
|
|
95
|
+
"@firtoz/maybe-error": "^1.6.1",
|
|
96
|
+
"citty": "^0.2.2"
|
|
92
97
|
}
|
|
93
98
|
}
|