@simplysm/capacitor-plugin-file-system 13.0.76 → 13.0.78
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/README.md +46 -53
- package/android/src/main/java/kr/co/simplysm/capacitor/filesystem/FileSystemPlugin.java +5 -5
- package/dist/FileSystem.d.ts +9 -12
- package/dist/FileSystem.d.ts.map +1 -1
- package/dist/FileSystem.js +24 -29
- package/dist/FileSystem.js.map +1 -1
- package/dist/{IFileSystemPlugin.d.ts → FileSystemPlugin.d.ts} +9 -9
- package/dist/FileSystemPlugin.d.ts.map +1 -0
- package/dist/FileSystemPlugin.js +1 -0
- package/dist/index.d.ts +1 -1
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +1 -1
- package/dist/web/FileSystemWeb.d.ts +7 -7
- package/dist/web/FileSystemWeb.d.ts.map +1 -1
- package/dist/web/FileSystemWeb.js +9 -35
- package/dist/web/FileSystemWeb.js.map +1 -1
- package/dist/web/VirtualFileSystem.d.ts +10 -10
- package/dist/web/VirtualFileSystem.d.ts.map +1 -1
- package/dist/web/VirtualFileSystem.js +8 -67
- package/dist/web/VirtualFileSystem.js.map +1 -1
- package/package.json +3 -2
- package/src/FileSystem.ts +30 -31
- package/src/{IFileSystemPlugin.ts → FileSystemPlugin.ts} +8 -8
- package/src/index.ts +1 -1
- package/src/web/FileSystemWeb.ts +13 -39
- package/src/web/VirtualFileSystem.ts +13 -77
- package/dist/IFileSystemPlugin.d.ts.map +0 -1
- package/dist/IFileSystemPlugin.js +0 -1
- package/dist/web/IndexedDbStore.d.ts +0 -16
- package/dist/web/IndexedDbStore.d.ts.map +0 -1
- package/dist/web/IndexedDbStore.js +0 -76
- package/dist/web/IndexedDbStore.js.map +0 -6
- package/src/web/IndexedDbStore.ts +0 -88
- /package/dist/{IFileSystemPlugin.js.map → FileSystemPlugin.js.map} +0 -0
|
@@ -1,76 +0,0 @@
|
|
|
1
|
-
class IndexedDbStore {
|
|
2
|
-
constructor(_dbName, _dbVersion, _storeConfigs) {
|
|
3
|
-
this._dbName = _dbName;
|
|
4
|
-
this._dbVersion = _dbVersion;
|
|
5
|
-
this._storeConfigs = _storeConfigs;
|
|
6
|
-
}
|
|
7
|
-
async open() {
|
|
8
|
-
return new Promise((resolve, reject) => {
|
|
9
|
-
const req = indexedDB.open(this._dbName, this._dbVersion);
|
|
10
|
-
req.onupgradeneeded = () => {
|
|
11
|
-
const db = req.result;
|
|
12
|
-
for (const config of this._storeConfigs) {
|
|
13
|
-
if (!db.objectStoreNames.contains(config.name)) {
|
|
14
|
-
db.createObjectStore(config.name, { keyPath: config.keyPath });
|
|
15
|
-
}
|
|
16
|
-
}
|
|
17
|
-
};
|
|
18
|
-
req.onsuccess = () => resolve(req.result);
|
|
19
|
-
req.onerror = () => reject(req.error);
|
|
20
|
-
req.onblocked = () => reject(new Error("Database blocked by another connection"));
|
|
21
|
-
});
|
|
22
|
-
}
|
|
23
|
-
async withStore(storeName, mode, fn) {
|
|
24
|
-
const db = await this.open();
|
|
25
|
-
return new Promise((resolve, reject) => {
|
|
26
|
-
const tx = db.transaction(storeName, mode);
|
|
27
|
-
const store = tx.objectStore(storeName);
|
|
28
|
-
let result;
|
|
29
|
-
Promise.resolve(fn(store)).then((r) => {
|
|
30
|
-
result = r;
|
|
31
|
-
}).catch((err) => {
|
|
32
|
-
db.close();
|
|
33
|
-
reject(err);
|
|
34
|
-
});
|
|
35
|
-
tx.oncomplete = () => {
|
|
36
|
-
db.close();
|
|
37
|
-
resolve(result);
|
|
38
|
-
};
|
|
39
|
-
tx.onerror = () => {
|
|
40
|
-
db.close();
|
|
41
|
-
reject(tx.error);
|
|
42
|
-
};
|
|
43
|
-
});
|
|
44
|
-
}
|
|
45
|
-
async get(storeName, key) {
|
|
46
|
-
return this.withStore(storeName, "readonly", async (store) => {
|
|
47
|
-
return new Promise((resolve, reject) => {
|
|
48
|
-
const req = store.get(key);
|
|
49
|
-
req.onsuccess = () => resolve(req.result);
|
|
50
|
-
req.onerror = () => reject(req.error);
|
|
51
|
-
});
|
|
52
|
-
});
|
|
53
|
-
}
|
|
54
|
-
async put(storeName, value) {
|
|
55
|
-
return this.withStore(storeName, "readwrite", async (store) => {
|
|
56
|
-
return new Promise((resolve, reject) => {
|
|
57
|
-
const req = store.put(value);
|
|
58
|
-
req.onsuccess = () => resolve();
|
|
59
|
-
req.onerror = () => reject(req.error);
|
|
60
|
-
});
|
|
61
|
-
});
|
|
62
|
-
}
|
|
63
|
-
async getAll(storeName) {
|
|
64
|
-
return this.withStore(storeName, "readonly", async (store) => {
|
|
65
|
-
return new Promise((resolve, reject) => {
|
|
66
|
-
const req = store.getAll();
|
|
67
|
-
req.onsuccess = () => resolve(req.result);
|
|
68
|
-
req.onerror = () => reject(req.error);
|
|
69
|
-
});
|
|
70
|
-
});
|
|
71
|
-
}
|
|
72
|
-
}
|
|
73
|
-
export {
|
|
74
|
-
IndexedDbStore
|
|
75
|
-
};
|
|
76
|
-
//# sourceMappingURL=IndexedDbStore.js.map
|
|
@@ -1,6 +0,0 @@
|
|
|
1
|
-
{
|
|
2
|
-
"version": 3,
|
|
3
|
-
"sources": ["../../src/web/IndexedDbStore.ts"],
|
|
4
|
-
"mappings": "AAKO,MAAM,eAAe;AAAA,EAC1B,YACmB,SACA,YACA,eACjB;AAHiB;AACA;AACA;AAAA,EAChB;AAAA,EAEH,MAAM,OAA6B;AACjC,WAAO,IAAI,QAAQ,CAAC,SAAS,WAAW;AACtC,YAAM,MAAM,UAAU,KAAK,KAAK,SAAS,KAAK,UAAU;AACxD,UAAI,kBAAkB,MAAM;AAC1B,cAAM,KAAK,IAAI;AACf,mBAAW,UAAU,KAAK,eAAe;AACvC,cAAI,CAAC,GAAG,iBAAiB,SAAS,OAAO,IAAI,GAAG;AAC9C,eAAG,kBAAkB,OAAO,MAAM,EAAE,SAAS,OAAO,QAAQ,CAAC;AAAA,UAC/D;AAAA,QACF;AAAA,MACF;AACA,UAAI,YAAY,MAAM,QAAQ,IAA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;AAAA,MACtC,CAAC;AAAA,IACH,CAAC;AAAA,EACH;AAAA,EAEA,MAAM,OAAU,WAAiC;AAC/C,WAAO,KAAK,UAAU,WAAW,YAAY,OAAO,UAAU;AAC5D,aAAO,IAAI,QAAQ,CAAC,SAAS,WAAW;AACtC,cAAM,MAAM,MAAM,OAAO;AACzB,YAAI,YAAY,MAAM,QAAQ,IAAI,MAAa;AAC/C,YAAI,UAAU,MAAM,OAAO,IAAI,KAAK;AAAA,MACtC,CAAC;AAAA,IACH,CAAC;AAAA,EACH;AACF;",
|
|
5
|
-
"names": []
|
|
6
|
-
}
|
|
@@ -1,88 +0,0 @@
|
|
|
1
|
-
export interface IStoreConfig {
|
|
2
|
-
name: string;
|
|
3
|
-
keyPath: string;
|
|
4
|
-
}
|
|
5
|
-
|
|
6
|
-
export class IndexedDbStore {
|
|
7
|
-
constructor(
|
|
8
|
-
private readonly _dbName: string,
|
|
9
|
-
private readonly _dbVersion: number,
|
|
10
|
-
private readonly _storeConfigs: IStoreConfig[],
|
|
11
|
-
) {}
|
|
12
|
-
|
|
13
|
-
async open(): Promise<IDBDatabase> {
|
|
14
|
-
return new Promise((resolve, reject) => {
|
|
15
|
-
const req = indexedDB.open(this._dbName, this._dbVersion);
|
|
16
|
-
req.onupgradeneeded = () => {
|
|
17
|
-
const db = req.result;
|
|
18
|
-
for (const config of this._storeConfigs) {
|
|
19
|
-
if (!db.objectStoreNames.contains(config.name)) {
|
|
20
|
-
db.createObjectStore(config.name, { keyPath: config.keyPath });
|
|
21
|
-
}
|
|
22
|
-
}
|
|
23
|
-
};
|
|
24
|
-
req.onsuccess = () => resolve(req.result);
|
|
25
|
-
req.onerror = () => reject(req.error);
|
|
26
|
-
req.onblocked = () => reject(new Error("Database blocked by another connection"));
|
|
27
|
-
});
|
|
28
|
-
}
|
|
29
|
-
|
|
30
|
-
async withStore<T>(
|
|
31
|
-
storeName: string,
|
|
32
|
-
mode: IDBTransactionMode,
|
|
33
|
-
fn: (store: IDBObjectStore) => Promise<T>,
|
|
34
|
-
): Promise<T> {
|
|
35
|
-
const db = await this.open();
|
|
36
|
-
return new Promise((resolve, reject) => {
|
|
37
|
-
const tx = db.transaction(storeName, mode);
|
|
38
|
-
const store = tx.objectStore(storeName);
|
|
39
|
-
let result: T;
|
|
40
|
-
Promise.resolve(fn(store))
|
|
41
|
-
.then((r) => {
|
|
42
|
-
result = r;
|
|
43
|
-
})
|
|
44
|
-
.catch((err) => {
|
|
45
|
-
db.close();
|
|
46
|
-
reject(err);
|
|
47
|
-
});
|
|
48
|
-
tx.oncomplete = () => {
|
|
49
|
-
db.close();
|
|
50
|
-
resolve(result);
|
|
51
|
-
};
|
|
52
|
-
tx.onerror = () => {
|
|
53
|
-
db.close();
|
|
54
|
-
reject(tx.error);
|
|
55
|
-
};
|
|
56
|
-
});
|
|
57
|
-
}
|
|
58
|
-
|
|
59
|
-
async get<T>(storeName: string, key: IDBValidKey): Promise<T | undefined> {
|
|
60
|
-
return this.withStore(storeName, "readonly", async (store) => {
|
|
61
|
-
return new Promise((resolve, reject) => {
|
|
62
|
-
const req = store.get(key);
|
|
63
|
-
req.onsuccess = () => resolve(req.result as T | undefined);
|
|
64
|
-
req.onerror = () => reject(req.error);
|
|
65
|
-
});
|
|
66
|
-
});
|
|
67
|
-
}
|
|
68
|
-
|
|
69
|
-
async put(storeName: string, value: unknown): Promise<void> {
|
|
70
|
-
return this.withStore(storeName, "readwrite", async (store) => {
|
|
71
|
-
return new Promise((resolve, reject) => {
|
|
72
|
-
const req = store.put(value);
|
|
73
|
-
req.onsuccess = () => resolve();
|
|
74
|
-
req.onerror = () => reject(req.error);
|
|
75
|
-
});
|
|
76
|
-
});
|
|
77
|
-
}
|
|
78
|
-
|
|
79
|
-
async getAll<T>(storeName: string): Promise<T[]> {
|
|
80
|
-
return this.withStore(storeName, "readonly", async (store) => {
|
|
81
|
-
return new Promise((resolve, reject) => {
|
|
82
|
-
const req = store.getAll();
|
|
83
|
-
req.onsuccess = () => resolve(req.result as T[]);
|
|
84
|
-
req.onerror = () => reject(req.error);
|
|
85
|
-
});
|
|
86
|
-
});
|
|
87
|
-
}
|
|
88
|
-
}
|
|
File without changes
|