Skip to content

Commit a27272d

Browse files
committed
[optimize] IndexedDB detection & NewData type value
[fix] 2 type bugs in Strapi wrapper
1 parent f2fd203 commit a27272d

File tree

7 files changed

+78
-68
lines changed

7 files changed

+78
-68
lines changed

package.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "mobx-restful",
3-
"version": "2.1.1",
3+
"version": "2.1.2",
44
"license": "LGPL-3.0",
55
"author": "[email protected]",
66
"description": "Common MobX abstract base Class & Decorator utilities for RESTful API",
@@ -43,7 +43,7 @@
4343
"@parcel/transformer-typescript-tsc": "~2.15.4",
4444
"@parcel/transformer-typescript-types": "~2.15.4",
4545
"@types/jest": "^29.5.14",
46-
"@types/node": "^22.18.5",
46+
"@types/node": "^22.18.6",
4747
"core-js": "^3.45.1",
4848
"dotenv": "^17.2.2",
4949
"fake-indexeddb": "^6.2.2",

pnpm-lock.yaml

Lines changed: 45 additions & 45 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

source/utility/decorator-stage3.ts

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -90,6 +90,13 @@ export class PersistNode<V = any, S = any> implements PersistMeta<V, S> {
9090
Object.assign(this, meta);
9191
}
9292

93+
private static readyIDB?: Promise<any>;
94+
95+
static detectIDB = () =>
96+
(this.readyIDB ||= import('idb-keyval').then(({ get }) =>
97+
get('ready')
98+
));
99+
93100
async save(storeKey: string, value?: V) {
94101
if (value != null)
95102
this.value = toJS((await this.set?.(value)) ?? value);
@@ -158,10 +165,13 @@ export async function restore<T extends object>(
158165
classInstance: T,
159166
storeKey: string
160167
) {
161-
if (!globalThis.indexedDB)
168+
try {
169+
await PersistNode.detectIDB();
170+
} catch {
162171
return console.warn(
163-
'IndexedDB is not found in this runtime engine, MobX-RESTful persistence is disabled.'
172+
'IndexedDB or its polyfill is not found in this runtime engine, MobX-RESTful persistence is disabled.'
164173
);
174+
}
165175
const list = PersistNodes.get(classInstance) || [],
166176
restoredData = {} as Partial<T>;
167177

0 commit comments

Comments
 (0)