@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.
Files changed (27) hide show
  1. package/dist/{index-CInRo1qR.js → index-BJ2aqva1.js} +2 -2
  2. package/dist/{index-CInRo1qR.js.map → index-BJ2aqva1.js.map} +1 -1
  3. package/dist/{index-Ek5d60jn.js → index-BKxuoVoX.js} +1567 -1412
  4. package/dist/index-BKxuoVoX.js.map +1 -0
  5. package/dist/{index-DxGjTpIn.js → index-CA_JNRF8.js} +2 -2
  6. package/dist/{index-DxGjTpIn.js.map → index-CA_JNRF8.js.map} +1 -1
  7. package/dist/{index-CaI9BFuB.js → index-CMuITxgX.js} +2 -2
  8. package/dist/{index-CaI9BFuB.js.map → index-CMuITxgX.js.map} +1 -1
  9. package/dist/{index-UjgKGkN2.js → index-CNsfHvio.js} +2 -2
  10. package/dist/{index-UjgKGkN2.js.map → index-CNsfHvio.js.map} +1 -1
  11. package/dist/{index-C-A3jSMx.js → index-CiceXP5j.js} +2 -2
  12. package/dist/{index-C-A3jSMx.js.map → index-CiceXP5j.js.map} +1 -1
  13. package/dist/{index-CWbHdYKu.js → index-D8zKl2eU.js} +2 -2
  14. package/dist/{index-CWbHdYKu.js.map → index-D8zKl2eU.js.map} +1 -1
  15. package/dist/{index-btJ_NMuF.js → index-D968kDLW.js} +2 -2
  16. package/dist/{index-btJ_NMuF.js.map → index-D968kDLW.js.map} +1 -1
  17. package/dist/{index-RFAZzS9C.js → index-DRaYlg2d.js} +2 -2
  18. package/dist/{index-RFAZzS9C.js.map → index-DRaYlg2d.js.map} +1 -1
  19. package/dist/{index-D6055L55.js → index-DtLiqtR8.js} +2 -2
  20. package/dist/{index-D6055L55.js.map → index-DtLiqtR8.js.map} +1 -1
  21. package/dist/index.js +1 -1
  22. package/dist/services/storage/IDBStorage.d.ts +69 -31
  23. package/dist/services/storage/index.d.ts +8 -8
  24. package/lib/index.umd.js +23 -23
  25. package/lib/index.umd.js.map +1 -1
  26. package/package.json +3 -3
  27. package/dist/index-Ek5d60jn.js.map +0 -1
package/dist/index.js CHANGED
@@ -1,4 +1,4 @@
1
- import { B as s, b as g, I as r, m as c, $ as o, S as t, a as L, c as i } from "./index-Ek5d60jn.js";
1
+ import { B as s, b as g, I as r, m as c, $ as o, S as t, a as L, c as i } from "./index-BKxuoVoX.js";
2
2
  export {
3
3
  s as BasePlugin,
4
4
  g as InPageEdit,
@@ -1,7 +1,21 @@
1
- export interface IDBStoreDefinition {
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
- dbPromise: Promise<IDBDatabase>;
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 exists. If missing, bump IDB version to create it.
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 createStore(dbName: string, storeName: string): Promise<IDBDatabase>;
20
- /** Convenience: open & ensure store, return a store definition. */
21
- function openStore(dbName: string, storeName: string): Promise<IDBStoreDefinition>;
22
- function withObjectStore<T>(store: IDBStoreDefinition, mode: IDBTransactionMode, fn: (os: IDBObjectStore) => Promise<T> | T): Promise<T>;
23
- function get<T = unknown>(store: IDBStoreDefinition, key: IDBValidKey): Promise<T | undefined>;
24
- function set(store: IDBStoreDefinition, key: IDBValidKey, value: unknown): Promise<void>;
25
- function del(store: IDBStoreDefinition, key: IDBValidKey): Promise<void>;
26
- function clear(store: IDBStoreDefinition): Promise<void>;
27
- function keys(store: IDBStoreDefinition): Promise<IDBValidKey[]>;
28
- function entries(store: IDBStoreDefinition): Promise<[IDBValidKey, any][]>;
29
- function entriesIter(store: IDBStoreDefinition, batchSize?: number): AsyncIterable<[IDBValidKey, any]>;
30
- function keysIter(store: IDBStoreDefinition, batchSize?: number): AsyncIterable<IDBValidKey>;
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
- private readonly store;
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 constructor();
36
- static open<K extends IDBValidKey, V>(dbName: string, storeName: string, iterBatch?: number): Promise<IDBStorage<K, V>>;
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<this>;
39
- delete(key: K): Promise<boolean>;
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
- * @note expensive operation: iterates all keys to count them
44
- */
45
- size(): Promise<number>;
46
- entries(batchSize?: number): AsyncIterable<[K, V]>;
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(callback: (value: V, key: K, map: IDBStorage<K, V>) => void | Promise<void>): Promise<void>;
51
- toArray(limit?: number): Promise<Array<[K, V]>>;
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 { IDBStoreDefinition } from './IDBStorage.js';
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
- iterate(callback: (value: T, key: string) => void): Promise<void>;
27
- keys(): Promise<string[]>;
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 store: IDBStoreDefinition;
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
  /**