@anfenn/dync 1.0.0
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/LICENSE +21 -0
- package/README.md +212 -0
- package/dist/capacitor.cjs +228 -0
- package/dist/capacitor.cjs.map +1 -0
- package/dist/capacitor.d.cts +62 -0
- package/dist/capacitor.d.ts +62 -0
- package/dist/capacitor.js +9 -0
- package/dist/capacitor.js.map +1 -0
- package/dist/chunk-LGHOZECP.js +3884 -0
- package/dist/chunk-LGHOZECP.js.map +1 -0
- package/dist/chunk-SQB6E7V2.js +191 -0
- package/dist/chunk-SQB6E7V2.js.map +1 -0
- package/dist/dexie-Bv-fV10P.d.cts +444 -0
- package/dist/dexie-DJFApKsM.d.ts +444 -0
- package/dist/dexie.cjs +381 -0
- package/dist/dexie.cjs.map +1 -0
- package/dist/dexie.d.cts +3 -0
- package/dist/dexie.d.ts +3 -0
- package/dist/dexie.js +343 -0
- package/dist/dexie.js.map +1 -0
- package/dist/expoSqlite.cjs +98 -0
- package/dist/expoSqlite.cjs.map +1 -0
- package/dist/expoSqlite.d.cts +17 -0
- package/dist/expoSqlite.d.ts +17 -0
- package/dist/expoSqlite.js +61 -0
- package/dist/expoSqlite.js.map +1 -0
- package/dist/index.cjs +3916 -0
- package/dist/index.cjs.map +1 -0
- package/dist/index.d.cts +8 -0
- package/dist/index.d.ts +8 -0
- package/dist/index.js +20 -0
- package/dist/index.js.map +1 -0
- package/dist/index.shared-CPIge2ZM.d.ts +234 -0
- package/dist/index.shared-YSn6c01d.d.cts +234 -0
- package/dist/node.cjs +126 -0
- package/dist/node.cjs.map +1 -0
- package/dist/node.d.cts +80 -0
- package/dist/node.d.ts +80 -0
- package/dist/node.js +89 -0
- package/dist/node.js.map +1 -0
- package/dist/react/index.cjs +1754 -0
- package/dist/react/index.cjs.map +1 -0
- package/dist/react/index.d.cts +40 -0
- package/dist/react/index.d.ts +40 -0
- package/dist/react/index.js +78 -0
- package/dist/react/index.js.map +1 -0
- package/dist/types-CSbIAfu2.d.cts +46 -0
- package/dist/types-CSbIAfu2.d.ts +46 -0
- package/dist/wa-sqlite.cjs +318 -0
- package/dist/wa-sqlite.cjs.map +1 -0
- package/dist/wa-sqlite.d.cts +175 -0
- package/dist/wa-sqlite.d.ts +175 -0
- package/dist/wa-sqlite.js +281 -0
- package/dist/wa-sqlite.js.map +1 -0
- package/package.json +171 -0
- package/src/addVisibilityChangeListener.native.ts +33 -0
- package/src/addVisibilityChangeListener.ts +24 -0
- package/src/capacitor.ts +4 -0
- package/src/core/StateManager.ts +272 -0
- package/src/core/firstLoad.ts +332 -0
- package/src/core/pullOperations.ts +212 -0
- package/src/core/pushOperations.ts +290 -0
- package/src/core/tableEnhancers.ts +457 -0
- package/src/core/types.ts +3 -0
- package/src/createLocalId.native.ts +8 -0
- package/src/createLocalId.ts +6 -0
- package/src/dexie.ts +2 -0
- package/src/expoSqlite.ts +2 -0
- package/src/helpers.ts +87 -0
- package/src/index.native.ts +28 -0
- package/src/index.shared.ts +613 -0
- package/src/index.ts +28 -0
- package/src/logger.ts +26 -0
- package/src/node.ts +4 -0
- package/src/react/index.ts +2 -0
- package/src/react/useDync.ts +156 -0
- package/src/storage/dexie/DexieAdapter.ts +72 -0
- package/src/storage/dexie/DexieQueryContext.ts +14 -0
- package/src/storage/dexie/DexieStorageCollection.ts +124 -0
- package/src/storage/dexie/DexieStorageTable.ts +123 -0
- package/src/storage/dexie/DexieStorageWhereClause.ts +103 -0
- package/src/storage/dexie/helpers.ts +1 -0
- package/src/storage/dexie/index.ts +7 -0
- package/src/storage/memory/MemoryAdapter.ts +55 -0
- package/src/storage/memory/MemoryCollection.ts +215 -0
- package/src/storage/memory/MemoryQueryContext.ts +14 -0
- package/src/storage/memory/MemoryTable.ts +336 -0
- package/src/storage/memory/MemoryWhereClause.ts +134 -0
- package/src/storage/memory/index.ts +7 -0
- package/src/storage/memory/types.ts +24 -0
- package/src/storage/sqlite/SQLiteAdapter.ts +564 -0
- package/src/storage/sqlite/SQLiteCollection.ts +294 -0
- package/src/storage/sqlite/SQLiteTable.ts +604 -0
- package/src/storage/sqlite/SQLiteWhereClause.ts +341 -0
- package/src/storage/sqlite/SqliteQueryContext.ts +30 -0
- package/src/storage/sqlite/drivers/BetterSqlite3Driver.ts +156 -0
- package/src/storage/sqlite/drivers/CapacitorFastSqlDriver.ts +114 -0
- package/src/storage/sqlite/drivers/CapacitorSQLiteDriver.ts +137 -0
- package/src/storage/sqlite/drivers/ExpoSQLiteDriver.native.ts +67 -0
- package/src/storage/sqlite/drivers/WaSqliteDriver.ts +537 -0
- package/src/storage/sqlite/drivers/wa-sqlite-vfs.d.ts +46 -0
- package/src/storage/sqlite/helpers.ts +144 -0
- package/src/storage/sqlite/index.ts +11 -0
- package/src/storage/sqlite/schema.ts +44 -0
- package/src/storage/sqlite/types.ts +164 -0
- package/src/storage/types.ts +112 -0
- package/src/types.ts +186 -0
- package/src/wa-sqlite.ts +4 -0
|
@@ -0,0 +1,444 @@
|
|
|
1
|
+
import dexie from 'dexie';
|
|
2
|
+
import { d as StorageSchemaDefinitionOptions, S as SQLiteDatabaseDriver, e as SQLiteAdapterOptions, a as SQLiteRunResult, b as SQLiteQueryResult } from './types-CSbIAfu2.js';
|
|
3
|
+
|
|
4
|
+
type TableSchemaDefinition = string | SQLiteTableDefinition;
|
|
5
|
+
interface SQLiteTableDefinition {
|
|
6
|
+
columns: Record<string, SQLiteColumnDefinition>;
|
|
7
|
+
indexes?: SQLiteIndexDefinition[];
|
|
8
|
+
tableConstraints?: string[];
|
|
9
|
+
withoutRowId?: boolean;
|
|
10
|
+
strict?: boolean;
|
|
11
|
+
}
|
|
12
|
+
interface SQLiteColumnDefinition {
|
|
13
|
+
type?: string;
|
|
14
|
+
length?: number;
|
|
15
|
+
nullable?: boolean;
|
|
16
|
+
unique?: boolean;
|
|
17
|
+
default?: SQLiteDefaultValue;
|
|
18
|
+
check?: string;
|
|
19
|
+
references?: SQLiteForeignKeyReference | string;
|
|
20
|
+
collate?: string;
|
|
21
|
+
generatedAlwaysAs?: string;
|
|
22
|
+
stored?: boolean;
|
|
23
|
+
constraints?: string[];
|
|
24
|
+
}
|
|
25
|
+
type SQLiteDefaultValue = string | number | boolean | null;
|
|
26
|
+
interface SQLiteForeignKeyReference {
|
|
27
|
+
table: string;
|
|
28
|
+
column?: string;
|
|
29
|
+
onDelete?: SQLiteForeignKeyAction;
|
|
30
|
+
onUpdate?: SQLiteForeignKeyAction;
|
|
31
|
+
match?: string;
|
|
32
|
+
}
|
|
33
|
+
type SQLiteForeignKeyAction = 'SET NULL' | 'SET DEFAULT' | 'RESTRICT' | 'NO ACTION' | 'CASCADE';
|
|
34
|
+
interface SQLiteIndexDefinition {
|
|
35
|
+
name?: string;
|
|
36
|
+
columns: string[];
|
|
37
|
+
unique?: boolean;
|
|
38
|
+
where?: string;
|
|
39
|
+
collate?: string;
|
|
40
|
+
orders?: Array<'ASC' | 'DESC'>;
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
declare class DexieQueryContext {
|
|
44
|
+
private readonly adapter;
|
|
45
|
+
constructor(adapter: DexieAdapter);
|
|
46
|
+
table<T = any>(name: string): StorageTable<T>;
|
|
47
|
+
transaction<T>(mode: TransactionMode, tableNames: string[], callback: (context: StorageTransactionContext) => Promise<T>): Promise<T>;
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
interface MemoryRecord {
|
|
51
|
+
_localId?: string;
|
|
52
|
+
id?: unknown;
|
|
53
|
+
updated_at?: string;
|
|
54
|
+
[key: string]: unknown;
|
|
55
|
+
}
|
|
56
|
+
interface MemoryCollectionState<T extends MemoryRecord> {
|
|
57
|
+
predicate: (record: T, key: string) => boolean;
|
|
58
|
+
orderBy?: {
|
|
59
|
+
index: string | string[];
|
|
60
|
+
direction: 'asc' | 'desc';
|
|
61
|
+
};
|
|
62
|
+
reverse: boolean;
|
|
63
|
+
offset: number;
|
|
64
|
+
limit?: number;
|
|
65
|
+
distinct: boolean;
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
declare class MemoryCollection<T extends MemoryRecord = MemoryRecord> implements StorageCollection<T> {
|
|
69
|
+
private readonly table;
|
|
70
|
+
private readonly state;
|
|
71
|
+
constructor(table: MemoryTable<T>, state: MemoryCollectionState<T>);
|
|
72
|
+
getState(): MemoryCollectionState<T>;
|
|
73
|
+
matches(record: T, key: string): boolean;
|
|
74
|
+
clone(_props?: Record<string, unknown>): StorageCollection<T>;
|
|
75
|
+
reverse(): StorageCollection<T>;
|
|
76
|
+
offset(offset: number): StorageCollection<T>;
|
|
77
|
+
limit(count: number): StorageCollection<T>;
|
|
78
|
+
toCollection(): StorageCollection<T>;
|
|
79
|
+
distinct(): StorageCollection<T>;
|
|
80
|
+
jsFilter(predicate: (item: T) => boolean): StorageCollection<T>;
|
|
81
|
+
or(index: string): StorageWhereClause<T>;
|
|
82
|
+
first(): Promise<T | undefined>;
|
|
83
|
+
last(): Promise<T | undefined>;
|
|
84
|
+
each(callback: (item: T, index: number) => void | Promise<void>): Promise<void>;
|
|
85
|
+
eachKey(callback: (key: unknown, index: number) => void | Promise<void>): Promise<void>;
|
|
86
|
+
eachPrimaryKey(callback: (key: unknown, index: number) => void | Promise<void>): Promise<void>;
|
|
87
|
+
eachUniqueKey(callback: (key: unknown, index: number) => void | Promise<void>): Promise<void>;
|
|
88
|
+
keys(): Promise<unknown[]>;
|
|
89
|
+
primaryKeys(): Promise<unknown[]>;
|
|
90
|
+
uniqueKeys(): Promise<unknown[]>;
|
|
91
|
+
count(): Promise<number>;
|
|
92
|
+
sortBy(key: string): Promise<T[]>;
|
|
93
|
+
delete(): Promise<number>;
|
|
94
|
+
modify(changes: Partial<T> | ((item: T) => void | Promise<void>)): Promise<number>;
|
|
95
|
+
toArray(): Promise<T[]>;
|
|
96
|
+
private withState;
|
|
97
|
+
private combinePredicate;
|
|
98
|
+
private materializeEntries;
|
|
99
|
+
}
|
|
100
|
+
|
|
101
|
+
declare class MemoryWhereClause<T extends MemoryRecord = MemoryRecord> implements StorageWhereClause<T> {
|
|
102
|
+
private readonly table;
|
|
103
|
+
private readonly index;
|
|
104
|
+
private readonly baseCollection?;
|
|
105
|
+
constructor(table: MemoryTable<T>, index: string | string[], baseCollection?: MemoryCollection<T>);
|
|
106
|
+
equals(value: any): StorageCollection<T>;
|
|
107
|
+
above(value: any): StorageCollection<T>;
|
|
108
|
+
aboveOrEqual(value: any): StorageCollection<T>;
|
|
109
|
+
below(value: any): StorageCollection<T>;
|
|
110
|
+
belowOrEqual(value: any): StorageCollection<T>;
|
|
111
|
+
between(lower: any, upper: any, includeLower?: boolean, includeUpper?: boolean): StorageCollection<T>;
|
|
112
|
+
inAnyRange(ranges: Array<[any, any]>, options?: {
|
|
113
|
+
includeLower?: boolean;
|
|
114
|
+
includeUpper?: boolean;
|
|
115
|
+
}): StorageCollection<T>;
|
|
116
|
+
startsWith(prefix: string): StorageCollection<T>;
|
|
117
|
+
startsWithIgnoreCase(prefix: string): StorageCollection<T>;
|
|
118
|
+
startsWithAnyOf(...prefixes: string[]): StorageCollection<T>;
|
|
119
|
+
startsWithAnyOf(prefixes: string[]): StorageCollection<T>;
|
|
120
|
+
startsWithAnyOfIgnoreCase(...prefixes: string[]): StorageCollection<T>;
|
|
121
|
+
startsWithAnyOfIgnoreCase(prefixes: string[]): StorageCollection<T>;
|
|
122
|
+
equalsIgnoreCase(value: string): StorageCollection<T>;
|
|
123
|
+
anyOf(...values: any[]): StorageCollection<T>;
|
|
124
|
+
anyOf(values: any[]): StorageCollection<T>;
|
|
125
|
+
anyOfIgnoreCase(...values: string[]): StorageCollection<T>;
|
|
126
|
+
anyOfIgnoreCase(values: string[]): StorageCollection<T>;
|
|
127
|
+
noneOf(...values: any[]): StorageCollection<T>;
|
|
128
|
+
noneOf(values: any[]): StorageCollection<T>;
|
|
129
|
+
notEqual(value: any): StorageCollection<T>;
|
|
130
|
+
private createCollection;
|
|
131
|
+
private flattenArgs;
|
|
132
|
+
}
|
|
133
|
+
|
|
134
|
+
declare class MemoryTable<T extends MemoryRecord = MemoryRecord> implements StorageTable<T> {
|
|
135
|
+
readonly name: string;
|
|
136
|
+
readonly schema: unknown;
|
|
137
|
+
readonly primaryKey: unknown;
|
|
138
|
+
readonly hook: unknown;
|
|
139
|
+
readonly raw: {
|
|
140
|
+
add: (item: T) => Promise<unknown>;
|
|
141
|
+
put: (item: T) => Promise<unknown>;
|
|
142
|
+
update: (key: unknown, changes: Partial<T>) => Promise<number>;
|
|
143
|
+
delete: (key: unknown) => Promise<void>;
|
|
144
|
+
get: (key: unknown) => Promise<T | undefined>;
|
|
145
|
+
bulkAdd: (items: T[]) => Promise<unknown>;
|
|
146
|
+
bulkPut: (items: T[]) => Promise<unknown>;
|
|
147
|
+
bulkUpdate: (keysAndChanges: Array<{
|
|
148
|
+
key: unknown;
|
|
149
|
+
changes: Partial<T>;
|
|
150
|
+
}>) => Promise<number>;
|
|
151
|
+
bulkDelete: (keys: Array<unknown>) => Promise<void>;
|
|
152
|
+
clear: () => Promise<void>;
|
|
153
|
+
};
|
|
154
|
+
private readonly records;
|
|
155
|
+
constructor(name: string);
|
|
156
|
+
add(item: T): Promise<unknown>;
|
|
157
|
+
put(item: T): Promise<unknown>;
|
|
158
|
+
update(key: unknown, changes: Partial<T>): Promise<number>;
|
|
159
|
+
delete(key: unknown): Promise<void>;
|
|
160
|
+
clear(): Promise<void>;
|
|
161
|
+
private baseClear;
|
|
162
|
+
get(key: unknown): Promise<T | undefined>;
|
|
163
|
+
toArray(): Promise<T[]>;
|
|
164
|
+
count(): Promise<number>;
|
|
165
|
+
bulkAdd(items: T[]): Promise<unknown>;
|
|
166
|
+
private baseBulkAdd;
|
|
167
|
+
bulkPut(items: T[]): Promise<unknown>;
|
|
168
|
+
private baseBulkPut;
|
|
169
|
+
bulkGet(keys: Array<unknown>): Promise<Array<T | undefined>>;
|
|
170
|
+
bulkUpdate(keysAndChanges: Array<{
|
|
171
|
+
key: unknown;
|
|
172
|
+
changes: Partial<T>;
|
|
173
|
+
}>): Promise<number>;
|
|
174
|
+
private baseBulkUpdate;
|
|
175
|
+
bulkDelete(keys: Array<unknown>): Promise<void>;
|
|
176
|
+
private baseBulkDelete;
|
|
177
|
+
where(index: string | string[]): StorageWhereClause<T>;
|
|
178
|
+
orderBy(index: string | string[]): StorageCollection<T>;
|
|
179
|
+
reverse(): StorageCollection<T>;
|
|
180
|
+
offset(offset: number): StorageCollection<T>;
|
|
181
|
+
limit(count: number): StorageCollection<T>;
|
|
182
|
+
mapToClass(_ctor: new (...args: any[]) => any): StorageTable<T>;
|
|
183
|
+
each(callback: (item: T) => void | Promise<void>): Promise<void>;
|
|
184
|
+
jsFilter(predicate: (item: T) => boolean): StorageCollection<T>;
|
|
185
|
+
private createCollection;
|
|
186
|
+
createCollectionFromPredicate(predicate: (record: T, key: string) => boolean, template?: MemoryCollection<T>): MemoryCollection<T>;
|
|
187
|
+
createWhereClause(index: string | string[], baseCollection?: MemoryCollection<T>): MemoryWhereClause<T>;
|
|
188
|
+
entries(): Array<[string, T]>;
|
|
189
|
+
cloneRecord(record: T): T;
|
|
190
|
+
deleteByKey(key: string): void;
|
|
191
|
+
getMutableRecord(key: string): T | undefined;
|
|
192
|
+
setMutableRecord(key: string, record: T): void;
|
|
193
|
+
resolvePublicKey(record: T, key: string): unknown;
|
|
194
|
+
getIndexValue(record: T, index: string | string[]): unknown;
|
|
195
|
+
compareEntries(left: T, right: T, index: string | string[]): number;
|
|
196
|
+
compareValues(left: unknown, right: unknown): number;
|
|
197
|
+
private normalizeComparableValue;
|
|
198
|
+
private baseAdd;
|
|
199
|
+
private basePut;
|
|
200
|
+
private baseUpdate;
|
|
201
|
+
private baseDelete;
|
|
202
|
+
private baseGet;
|
|
203
|
+
private createPrimaryKey;
|
|
204
|
+
private resolveKey;
|
|
205
|
+
}
|
|
206
|
+
|
|
207
|
+
declare class MemoryAdapter implements StorageAdapter {
|
|
208
|
+
readonly type = "MemoryAdapter";
|
|
209
|
+
readonly name: string;
|
|
210
|
+
readonly tables: Map<string, MemoryTable<any>>;
|
|
211
|
+
constructor(name: string);
|
|
212
|
+
open(): Promise<void>;
|
|
213
|
+
close(): Promise<void>;
|
|
214
|
+
delete(): Promise<void>;
|
|
215
|
+
query<R>(callback: (ctx: MemoryQueryContext) => Promise<R>): Promise<R>;
|
|
216
|
+
defineSchema(_version: number, schema: Record<string, string>, _options?: StorageSchemaDefinitionOptions): void;
|
|
217
|
+
table<T = any>(name: string): StorageTable<T>;
|
|
218
|
+
transaction<T>(_mode: TransactionMode, tableNames: string[], callback: (context: StorageTransactionContext) => Promise<T>): Promise<T>;
|
|
219
|
+
private ensureTable;
|
|
220
|
+
}
|
|
221
|
+
|
|
222
|
+
declare class MemoryQueryContext {
|
|
223
|
+
private readonly adapter;
|
|
224
|
+
constructor(adapter: MemoryAdapter);
|
|
225
|
+
table<T = any>(name: string): StorageTable<T>;
|
|
226
|
+
transaction<T>(mode: TransactionMode, tableNames: string[], callback: (context: StorageTransactionContext) => Promise<T>): Promise<T>;
|
|
227
|
+
}
|
|
228
|
+
|
|
229
|
+
declare class SQLiteAdapter implements StorageAdapter {
|
|
230
|
+
readonly type = "SQLiteAdapter";
|
|
231
|
+
readonly name: string;
|
|
232
|
+
private readonly options;
|
|
233
|
+
private readonly schemas;
|
|
234
|
+
private readonly versionSchemas;
|
|
235
|
+
private readonly versionOptions;
|
|
236
|
+
private readonly tableCache;
|
|
237
|
+
private driver;
|
|
238
|
+
private openPromise?;
|
|
239
|
+
private isOpen;
|
|
240
|
+
private schemaApplied;
|
|
241
|
+
private transactionDepth;
|
|
242
|
+
private targetVersion;
|
|
243
|
+
constructor(driver: SQLiteDatabaseDriver, options?: SQLiteAdapterOptions);
|
|
244
|
+
get driverType(): string;
|
|
245
|
+
/**
|
|
246
|
+
* Opens the database connection and applies schema.
|
|
247
|
+
* This is called automatically when performing operations,
|
|
248
|
+
* so explicit calls are optional but safe (idempotent).
|
|
249
|
+
* When called explicitly after schema changes, it will run any pending migrations.
|
|
250
|
+
*/
|
|
251
|
+
open(): Promise<void>;
|
|
252
|
+
private ensureOpen;
|
|
253
|
+
private performOpen;
|
|
254
|
+
close(): Promise<void>;
|
|
255
|
+
delete(): Promise<void>;
|
|
256
|
+
defineSchema(version: number, schema: Record<string, TableSchemaDefinition>, options?: StorageSchemaDefinitionOptions): void;
|
|
257
|
+
private refreshActiveSchema;
|
|
258
|
+
table<T = any>(name: string): StorageTable<T>;
|
|
259
|
+
transaction<T>(_mode: TransactionMode, tableNames: string[], callback: (context: StorageTransactionContext) => Promise<T>): Promise<T>;
|
|
260
|
+
execute(statement: string, values?: any[]): Promise<void>;
|
|
261
|
+
run(statement: string, values?: any[]): Promise<SQLiteRunResult>;
|
|
262
|
+
query<R>(callback: (ctx: SqliteQueryContext) => Promise<R>): Promise<R>;
|
|
263
|
+
query(statement: string, values?: any[]): Promise<SQLiteQueryResult>;
|
|
264
|
+
queryRows(statement: string, values?: any[]): Promise<Array<Record<string, any>>>;
|
|
265
|
+
/**
|
|
266
|
+
* Ensures the database is open and returns the driver.
|
|
267
|
+
* This is the main entry point for all public database operations.
|
|
268
|
+
*/
|
|
269
|
+
private getDriver;
|
|
270
|
+
/**
|
|
271
|
+
* Internal execute that uses driver directly.
|
|
272
|
+
* Used during the open process to avoid recursion.
|
|
273
|
+
*/
|
|
274
|
+
private internalExecute;
|
|
275
|
+
/**
|
|
276
|
+
* Internal run that uses driver directly.
|
|
277
|
+
* Used during the open process to avoid recursion.
|
|
278
|
+
*/
|
|
279
|
+
private internalRun;
|
|
280
|
+
/**
|
|
281
|
+
* Internal queryRows that uses driver directly.
|
|
282
|
+
* Used during the open process to avoid recursion.
|
|
283
|
+
*/
|
|
284
|
+
private internalQueryRows;
|
|
285
|
+
/**
|
|
286
|
+
* Internal query that uses driver directly.
|
|
287
|
+
* Used during migrations to avoid recursion.
|
|
288
|
+
*/
|
|
289
|
+
private internalQuery;
|
|
290
|
+
private logSql;
|
|
291
|
+
private getStoredSchemaVersion;
|
|
292
|
+
private setStoredSchemaVersion;
|
|
293
|
+
private runPendingMigrations;
|
|
294
|
+
private runMigrationStep;
|
|
295
|
+
private getMigrationHandler;
|
|
296
|
+
private applySchema;
|
|
297
|
+
private buildCreateTableStatement;
|
|
298
|
+
private buildStructuredColumnDefinition;
|
|
299
|
+
private formatColumnType;
|
|
300
|
+
private formatDefaultValue;
|
|
301
|
+
private buildReferencesClause;
|
|
302
|
+
private buildIndexStatements;
|
|
303
|
+
private generateIndexName;
|
|
304
|
+
private parseStructuredSchema;
|
|
305
|
+
private normalizeColumns;
|
|
306
|
+
}
|
|
307
|
+
|
|
308
|
+
declare class SqliteQueryContext {
|
|
309
|
+
private readonly driver;
|
|
310
|
+
private readonly adapter;
|
|
311
|
+
constructor(driver: SQLiteDatabaseDriver, adapter: SQLiteAdapter);
|
|
312
|
+
table<T = any>(name: string): StorageTable<T>;
|
|
313
|
+
transaction<T>(mode: TransactionMode, tableNames: string[], callback: (context: StorageTransactionContext) => Promise<T>): Promise<T>;
|
|
314
|
+
execute(statement: string): Promise<void>;
|
|
315
|
+
run(statement: string, values?: any[]): Promise<SQLiteRunResult>;
|
|
316
|
+
queryRows(statement: string, values?: any[]): Promise<Array<Record<string, any>>>;
|
|
317
|
+
}
|
|
318
|
+
|
|
319
|
+
type TransactionMode = 'r' | 'rw';
|
|
320
|
+
interface StorageAdapter {
|
|
321
|
+
readonly type: string;
|
|
322
|
+
readonly name: string;
|
|
323
|
+
open(): Promise<void>;
|
|
324
|
+
close(): Promise<void>;
|
|
325
|
+
delete(): Promise<void>;
|
|
326
|
+
defineSchema(version: number, schema: Record<string, TableSchemaDefinition>, options?: StorageSchemaDefinitionOptions): void;
|
|
327
|
+
table<T = any>(name: string): StorageTable<T>;
|
|
328
|
+
transaction<T>(mode: TransactionMode, tableNames: string[], callback: (context: StorageTransactionContext) => Promise<T>): Promise<T>;
|
|
329
|
+
query<R>(callback: (ctx: DexieQueryContext | SqliteQueryContext | MemoryQueryContext) => Promise<R>): Promise<R>;
|
|
330
|
+
}
|
|
331
|
+
interface StorageTransactionContext {
|
|
332
|
+
tables: Record<string, StorageTable<any>>;
|
|
333
|
+
}
|
|
334
|
+
interface StorageCollection<T = any> {
|
|
335
|
+
first(): Promise<T | undefined>;
|
|
336
|
+
last(): Promise<T | undefined>;
|
|
337
|
+
each(callback: (item: T, index: number) => void | Promise<void>): Promise<void>;
|
|
338
|
+
eachKey(callback: (key: unknown, index: number) => void | Promise<void>): Promise<void>;
|
|
339
|
+
eachPrimaryKey(callback: (key: unknown, index: number) => void | Promise<void>): Promise<void>;
|
|
340
|
+
eachUniqueKey(callback: (key: unknown, index: number) => void | Promise<void>): Promise<void>;
|
|
341
|
+
keys(): Promise<unknown[]>;
|
|
342
|
+
primaryKeys(): Promise<unknown[]>;
|
|
343
|
+
uniqueKeys(): Promise<unknown[]>;
|
|
344
|
+
count(): Promise<number>;
|
|
345
|
+
sortBy(key: string): Promise<T[]>;
|
|
346
|
+
distinct(): StorageCollection<T>;
|
|
347
|
+
jsFilter(predicate: (item: T) => boolean): StorageCollection<T>;
|
|
348
|
+
or(index: string): StorageWhereClause<T>;
|
|
349
|
+
clone(props?: Record<string, unknown>): StorageCollection<T>;
|
|
350
|
+
reverse(): StorageCollection<T>;
|
|
351
|
+
offset(offset: number): StorageCollection<T>;
|
|
352
|
+
limit(count: number): StorageCollection<T>;
|
|
353
|
+
toCollection(): StorageCollection<T>;
|
|
354
|
+
delete(): Promise<number>;
|
|
355
|
+
modify(changes: Partial<T> | ((item: T) => void | Promise<void>)): Promise<number>;
|
|
356
|
+
toArray(): Promise<T[]>;
|
|
357
|
+
}
|
|
358
|
+
interface StorageWhereClause<T = any> {
|
|
359
|
+
equals(value: any): StorageCollection<T>;
|
|
360
|
+
above(value: any): StorageCollection<T>;
|
|
361
|
+
aboveOrEqual(value: any): StorageCollection<T>;
|
|
362
|
+
below(value: any): StorageCollection<T>;
|
|
363
|
+
belowOrEqual(value: any): StorageCollection<T>;
|
|
364
|
+
between(lower: any, upper: any, includeLower?: boolean, includeUpper?: boolean): StorageCollection<T>;
|
|
365
|
+
inAnyRange(ranges: Array<[any, any]>, options?: {
|
|
366
|
+
includeLower?: boolean;
|
|
367
|
+
includeUpper?: boolean;
|
|
368
|
+
}): StorageCollection<T>;
|
|
369
|
+
startsWith(prefix: string): StorageCollection<T>;
|
|
370
|
+
startsWithIgnoreCase(prefix: string): StorageCollection<T>;
|
|
371
|
+
startsWithAnyOf(...prefixes: string[]): StorageCollection<T>;
|
|
372
|
+
startsWithAnyOf(prefixes: string[]): StorageCollection<T>;
|
|
373
|
+
startsWithAnyOfIgnoreCase(...prefixes: string[]): StorageCollection<T>;
|
|
374
|
+
startsWithAnyOfIgnoreCase(prefixes: string[]): StorageCollection<T>;
|
|
375
|
+
equalsIgnoreCase(value: string): StorageCollection<T>;
|
|
376
|
+
anyOf(...values: any[]): StorageCollection<T>;
|
|
377
|
+
anyOf(values: any[]): StorageCollection<T>;
|
|
378
|
+
anyOfIgnoreCase(...values: string[]): StorageCollection<T>;
|
|
379
|
+
anyOfIgnoreCase(values: string[]): StorageCollection<T>;
|
|
380
|
+
noneOf(...values: any[]): StorageCollection<T>;
|
|
381
|
+
noneOf(values: any[]): StorageCollection<T>;
|
|
382
|
+
notEqual(value: any): StorageCollection<T>;
|
|
383
|
+
}
|
|
384
|
+
interface StorageTable<T = any> {
|
|
385
|
+
readonly name: string;
|
|
386
|
+
readonly schema: unknown;
|
|
387
|
+
readonly hook: unknown;
|
|
388
|
+
add(item: T): Promise<unknown>;
|
|
389
|
+
put(item: T): Promise<unknown>;
|
|
390
|
+
update(key: unknown, changes: Partial<T>): Promise<number>;
|
|
391
|
+
delete(key: unknown): Promise<void>;
|
|
392
|
+
clear(): Promise<void>;
|
|
393
|
+
get(key: unknown): Promise<T | undefined>;
|
|
394
|
+
toArray(): Promise<T[]>;
|
|
395
|
+
count(): Promise<number>;
|
|
396
|
+
bulkAdd(items: T[]): Promise<unknown>;
|
|
397
|
+
bulkPut(items: T[]): Promise<unknown>;
|
|
398
|
+
bulkGet(keys: Array<unknown>): Promise<Array<T | undefined>>;
|
|
399
|
+
bulkUpdate(keysAndChanges: Array<{
|
|
400
|
+
key: unknown;
|
|
401
|
+
changes: Partial<T>;
|
|
402
|
+
}>): Promise<number>;
|
|
403
|
+
bulkDelete(keys: Array<unknown>): Promise<void>;
|
|
404
|
+
where(index: string | string[]): StorageWhereClause<T>;
|
|
405
|
+
orderBy(index: string | string[]): StorageCollection<T>;
|
|
406
|
+
reverse(): StorageCollection<T>;
|
|
407
|
+
offset(offset: number): StorageCollection<T>;
|
|
408
|
+
limit(count: number): StorageCollection<T>;
|
|
409
|
+
mapToClass(ctor: new (...args: any[]) => any): StorageTable<T>;
|
|
410
|
+
each(callback: (item: T) => void | Promise<void>): Promise<void>;
|
|
411
|
+
jsFilter(predicate: (item: T) => boolean): StorageCollection<T>;
|
|
412
|
+
readonly raw: {
|
|
413
|
+
add(item: T): Promise<unknown>;
|
|
414
|
+
put(item: T): Promise<unknown>;
|
|
415
|
+
update(key: unknown, changes: Partial<T>): Promise<number>;
|
|
416
|
+
delete(key: unknown): Promise<void>;
|
|
417
|
+
get(key: unknown): Promise<T | undefined>;
|
|
418
|
+
bulkAdd(items: T[]): Promise<unknown>;
|
|
419
|
+
bulkPut(items: T[]): Promise<unknown>;
|
|
420
|
+
bulkUpdate(keysAndChanges: Array<{
|
|
421
|
+
key: unknown;
|
|
422
|
+
changes: Partial<T>;
|
|
423
|
+
}>): Promise<number>;
|
|
424
|
+
bulkDelete(keys: Array<unknown>): Promise<void>;
|
|
425
|
+
clear(): Promise<void>;
|
|
426
|
+
};
|
|
427
|
+
}
|
|
428
|
+
|
|
429
|
+
declare class DexieAdapter implements StorageAdapter {
|
|
430
|
+
readonly type = "DexieAdapter";
|
|
431
|
+
readonly name: string;
|
|
432
|
+
readonly db: dexie;
|
|
433
|
+
private readonly tableCache;
|
|
434
|
+
constructor(databaseName: string);
|
|
435
|
+
open(): Promise<void>;
|
|
436
|
+
close(): Promise<void>;
|
|
437
|
+
delete(): Promise<void>;
|
|
438
|
+
query<R>(callback: (ctx: DexieQueryContext) => Promise<R>): Promise<R>;
|
|
439
|
+
defineSchema(version: number, schema: Record<string, TableSchemaDefinition>, _options?: StorageSchemaDefinitionOptions): void;
|
|
440
|
+
table<T = any>(name: string): StorageTable<T>;
|
|
441
|
+
transaction<T>(mode: TransactionMode, tableNames: string[], callback: (context: StorageTransactionContext) => Promise<T>): Promise<T>;
|
|
442
|
+
}
|
|
443
|
+
|
|
444
|
+
export { DexieQueryContext as D, MemoryAdapter as M, SQLiteAdapter as S, type TableSchemaDefinition as T, MemoryQueryContext as a, SqliteQueryContext as b, type StorageAdapter as c, type StorageTable as d, DexieAdapter as e };
|