@inpageedit/core 0.9.2 → 0.9.3
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/dist/{index-CInRo1qR.js → index-BJ2aqva1.js} +2 -2
- package/dist/{index-CInRo1qR.js.map → index-BJ2aqva1.js.map} +1 -1
- package/dist/{index-Ek5d60jn.js → index-BKxuoVoX.js} +1567 -1412
- package/dist/index-BKxuoVoX.js.map +1 -0
- package/dist/{index-DxGjTpIn.js → index-CA_JNRF8.js} +2 -2
- package/dist/{index-DxGjTpIn.js.map → index-CA_JNRF8.js.map} +1 -1
- package/dist/{index-CaI9BFuB.js → index-CMuITxgX.js} +2 -2
- package/dist/{index-CaI9BFuB.js.map → index-CMuITxgX.js.map} +1 -1
- package/dist/{index-UjgKGkN2.js → index-CNsfHvio.js} +2 -2
- package/dist/{index-UjgKGkN2.js.map → index-CNsfHvio.js.map} +1 -1
- package/dist/{index-C-A3jSMx.js → index-CiceXP5j.js} +2 -2
- package/dist/{index-C-A3jSMx.js.map → index-CiceXP5j.js.map} +1 -1
- package/dist/{index-CWbHdYKu.js → index-D8zKl2eU.js} +2 -2
- package/dist/{index-CWbHdYKu.js.map → index-D8zKl2eU.js.map} +1 -1
- package/dist/{index-btJ_NMuF.js → index-D968kDLW.js} +2 -2
- package/dist/{index-btJ_NMuF.js.map → index-D968kDLW.js.map} +1 -1
- package/dist/{index-RFAZzS9C.js → index-DRaYlg2d.js} +2 -2
- package/dist/{index-RFAZzS9C.js.map → index-DRaYlg2d.js.map} +1 -1
- package/dist/{index-D6055L55.js → index-DtLiqtR8.js} +2 -2
- package/dist/{index-D6055L55.js.map → index-DtLiqtR8.js.map} +1 -1
- package/dist/index.js +1 -1
- package/dist/services/storage/IDBStorage.d.ts +69 -31
- package/dist/services/storage/index.d.ts +8 -8
- package/lib/index.umd.js +23 -23
- package/lib/index.umd.js.map +1 -1
- package/package.json +3 -3
- package/dist/index-Ek5d60jn.js.map +0 -1
package/dist/index.js
CHANGED
|
@@ -1,7 +1,21 @@
|
|
|
1
|
-
export interface
|
|
1
|
+
export interface IDBIndexDef {
|
|
2
|
+
name: string;
|
|
3
|
+
keyPath: string | string[];
|
|
4
|
+
options?: IDBIndexParameters;
|
|
5
|
+
}
|
|
6
|
+
export interface EnsureStoreOptions {
|
|
7
|
+
/** keyPath for objectStore; default undefined (out-of-line keys) */
|
|
8
|
+
keyPath?: string | string[] | null;
|
|
9
|
+
/** autoIncrement for objectStore; default false */
|
|
10
|
+
autoIncrement?: boolean;
|
|
11
|
+
/** indexes to ensure exist on the store (missing ones will be created on upgrade) */
|
|
12
|
+
indexes?: IDBIndexDef[];
|
|
13
|
+
}
|
|
14
|
+
export interface IDBStoreHandle {
|
|
2
15
|
dbName: string;
|
|
3
16
|
storeName: string;
|
|
4
|
-
|
|
17
|
+
/** Always returns a *current* connection; no stale db caching leaks to callers. */
|
|
18
|
+
getDb(): Promise<IDBDatabase>;
|
|
5
19
|
}
|
|
6
20
|
export declare namespace IDBHelper {
|
|
7
21
|
/** Promisify IDBRequest */
|
|
@@ -12,41 +26,65 @@ export declare namespace IDBHelper {
|
|
|
12
26
|
function closeDatabase(dbName: string): Promise<void>;
|
|
13
27
|
/** Close all cached database connections. */
|
|
14
28
|
function closeAllDatabases(): Promise<void>;
|
|
29
|
+
/** Delete a database completely (closes cached connection first). */
|
|
30
|
+
function deleteDatabase(dbName: string): Promise<void>;
|
|
15
31
|
/**
|
|
16
|
-
* Ensure an object store
|
|
32
|
+
* Ensure an object store (and optional indexes) exist. If missing, bump version to create.
|
|
17
33
|
* Concurrent calls are serialized per db to avoid racing upgrades.
|
|
18
34
|
*/
|
|
19
|
-
function
|
|
20
|
-
/** Convenience: open & ensure store, return a store
|
|
21
|
-
function
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
function
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
35
|
+
function ensureStore(dbName: string, storeName: string, opts?: EnsureStoreOptions): Promise<IDBDatabase>;
|
|
36
|
+
/** Convenience: open & ensure store, return a store handle. */
|
|
37
|
+
function createStore(dbName: string, storeName: string, opts?: EnsureStoreOptions): Promise<IDBStoreHandle>;
|
|
38
|
+
/**
|
|
39
|
+
* Run a function inside a transaction on one object store.
|
|
40
|
+
* Auto-recovers from transient IDB failures by reopening/ensuring and retrying (limited attempts).
|
|
41
|
+
*/
|
|
42
|
+
function withObjectStore<T>(handle: IDBStoreHandle, mode: IDBTransactionMode, fn: (os: IDBObjectStore) => Promise<T> | T,
|
|
43
|
+
/** customize retry attempts/backoff if needed */
|
|
44
|
+
retry?: {
|
|
45
|
+
attempts?: number;
|
|
46
|
+
baseDelayMs?: number;
|
|
47
|
+
}): Promise<T>;
|
|
48
|
+
function get<T = unknown>(handle: IDBStoreHandle, key: IDBValidKey): Promise<T | undefined>;
|
|
49
|
+
function set(handle: IDBStoreHandle, key: IDBValidKey, value: unknown): Promise<void>;
|
|
50
|
+
function del(handle: IDBStoreHandle, key: IDBValidKey): Promise<void>;
|
|
51
|
+
function clear(handle: IDBStoreHandle): Promise<void>;
|
|
52
|
+
function entries(handle: IDBStoreHandle, batchSize?: number): AsyncIterable<[IDBValidKey, any]>;
|
|
53
|
+
function keys(handle: IDBStoreHandle, batchSize?: number): AsyncIterable<IDBValidKey>;
|
|
54
|
+
}
|
|
55
|
+
export interface IDBStoreOptions {
|
|
56
|
+
/** 每次迭代拉取的批大小;兼容 iterBtch/iterBatch 两种写法 */
|
|
57
|
+
iterBatch?: number;
|
|
58
|
+
/** 建库/建表定义(可选)。若设置了 keyPath,则视为“内联主键”模式 */
|
|
59
|
+
ensure?: EnsureStoreOptions;
|
|
60
|
+
/** 重试参数(可选) */
|
|
61
|
+
retry?: {
|
|
62
|
+
attempts?: number;
|
|
63
|
+
baseDelayMs?: number;
|
|
64
|
+
};
|
|
31
65
|
}
|
|
32
|
-
export declare class IDBStorage<K extends IDBValidKey, V> implements AsyncIterable<[K, V]> {
|
|
33
|
-
|
|
66
|
+
export declare class IDBStorage<K extends IDBValidKey = IDBValidKey, V = any> implements AsyncIterable<[K, V]> {
|
|
67
|
+
readonly dbName: string;
|
|
68
|
+
readonly storeName: string;
|
|
34
69
|
private readonly iterBatch;
|
|
35
|
-
private
|
|
36
|
-
|
|
70
|
+
private readonly retry?;
|
|
71
|
+
private readonly inlineKey;
|
|
72
|
+
private readonly idbStoreHandle;
|
|
73
|
+
constructor(dbName: string, storeName: string, options?: IDBStoreOptions);
|
|
74
|
+
private handle;
|
|
37
75
|
get(key: K): Promise<V | undefined>;
|
|
38
|
-
set(key: K, value: V): Promise<
|
|
39
|
-
delete(key: K): Promise<
|
|
40
|
-
has(key: K): Promise<boolean>;
|
|
76
|
+
set(key: K, value: V): Promise<void>;
|
|
77
|
+
delete(key: K): Promise<void>;
|
|
41
78
|
clear(): Promise<void>;
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
keys(batchSize?: number): AsyncIterable<K>;
|
|
48
|
-
values(batchSize?: number): AsyncIterable<V>;
|
|
79
|
+
has(key: K): Promise<boolean>;
|
|
80
|
+
count(): Promise<number>;
|
|
81
|
+
entries(): AsyncIterable<[K, V]>;
|
|
82
|
+
keys(): AsyncIterable<K>;
|
|
83
|
+
values(): AsyncIterable<V>;
|
|
49
84
|
[Symbol.asyncIterator](): AsyncIterator<[K, V]>;
|
|
50
|
-
forEach(
|
|
51
|
-
|
|
85
|
+
forEach(cb: (value: V, key: K, store: IDBStorage<K, V>) => void | Promise<void>): Promise<void>;
|
|
86
|
+
setMany(entries: Iterable<[K, V]> | AsyncIterable<[K, V]>): Promise<void>;
|
|
87
|
+
deleteMany(keys: Iterable<K> | AsyncIterable<K>): Promise<void>;
|
|
88
|
+
tx<T>(mode: IDBTransactionMode, fn: (os: IDBObjectStore) => Promise<T> | T): Promise<T>;
|
|
89
|
+
close(): Promise<void>;
|
|
52
90
|
}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { InPageEdit, Service } from '../../InPageEdit.js';
|
|
2
|
-
import {
|
|
2
|
+
import { IDBStorage } from './IDBStorage.js';
|
|
3
3
|
declare module '../../InPageEdit' {
|
|
4
4
|
interface InPageEdit {
|
|
5
5
|
storage: StorageService;
|
|
@@ -23,8 +23,9 @@ export interface AbstactIPEStorageManager<T = unknown> {
|
|
|
23
23
|
set(key: string, value: T): Promise<IPEStorageRecord<T>>;
|
|
24
24
|
has(key: string, ttl?: number): Promise<boolean>;
|
|
25
25
|
delete(key: string): Promise<void>;
|
|
26
|
-
|
|
27
|
-
|
|
26
|
+
keys(): AsyncIterable<string>;
|
|
27
|
+
values(): AsyncIterable<IPEStorageRecord<T>>;
|
|
28
|
+
entries(): AsyncIterable<[string, IPEStorageRecord<T>]>;
|
|
28
29
|
clear(): Promise<this>;
|
|
29
30
|
}
|
|
30
31
|
export declare class IDBStorageManager<T = unknown> implements AbstactIPEStorageManager<T> {
|
|
@@ -32,17 +33,16 @@ export declare class IDBStorageManager<T = unknown> implements AbstactIPEStorage
|
|
|
32
33
|
readonly storeName: string;
|
|
33
34
|
ttl: number;
|
|
34
35
|
version?: number | undefined;
|
|
35
|
-
readonly
|
|
36
|
+
readonly db: IDBStorage<string, IPEStorageRecord<T>>;
|
|
37
|
+
keys: () => AsyncIterable<string>;
|
|
38
|
+
values: () => AsyncIterable<IPEStorageRecord<T>>;
|
|
39
|
+
entries: () => AsyncIterable<[string, IPEStorageRecord<T>]>;
|
|
36
40
|
constructor(dbName: string, storeName: string, ttl?: number, version?: number | undefined);
|
|
37
|
-
private static _cached_stores;
|
|
38
|
-
private static createStore;
|
|
39
|
-
keys(): Promise<string[]>;
|
|
40
41
|
get(key: string, ttl?: number, setter?: () => Promise<T> | T): Promise<T | null>;
|
|
41
42
|
set(key: string, value: null | undefined): Promise<void>;
|
|
42
43
|
set(key: string, value: T): Promise<IPEStorageRecord<T>>;
|
|
43
44
|
has(key: string, ttl?: number): Promise<boolean>;
|
|
44
45
|
delete(key: string): Promise<void>;
|
|
45
|
-
iterate(callback: (value: T, key: string) => void): Promise<void>;
|
|
46
46
|
private loadFromDB;
|
|
47
47
|
private checkIfExpired;
|
|
48
48
|
/**
|