fix(lib/plugins): use defineLazyProperty to define plugin storage API
This commit is contained in:
parent
e8fb54c19a
commit
aba4fa7242
1 changed files with 8 additions and 12 deletions
|
|
@ -1,4 +1,5 @@
|
||||||
import { type StorageOptions, getStorage } from '@revenge-mod/storage'
|
import { getStorage, type StorageOptions } from '@revenge-mod/storage'
|
||||||
|
import { defineLazyProperty } from '@revenge-mod/utils/objects'
|
||||||
import { allSettled, sleepReject } from '@revenge-mod/utils/promises'
|
import { allSettled, sleepReject } from '@revenge-mod/utils/promises'
|
||||||
|
|
||||||
import { _uapi as uapi } from './apis'
|
import { _uapi as uapi } from './apis'
|
||||||
|
|
@ -98,18 +99,13 @@ function preparePluginInit(plugin: InternalPlugin, storageOptions?: StorageOptio
|
||||||
const meta = _metas.get(plugin.manifest.id)!
|
const meta = _metas.get(plugin.manifest.id)!
|
||||||
const api = meta[0] as InitPluginApi
|
const api = meta[0] as InitPluginApi
|
||||||
|
|
||||||
Object.defineProperty(api, 'storage', {
|
defineLazyProperty(api, 'storage', () => getStorage(
|
||||||
configurable: true,
|
`${PluginsStorageDirectory}/${plugin.manifest.id}.json`,
|
||||||
get() {
|
{
|
||||||
// @ts-expect-error
|
...storageOptions,
|
||||||
// biome-ignore lint/performance/noDelete: <explanation>
|
directory: 'documents',
|
||||||
delete api.storage
|
|
||||||
return (api.storage = getStorage(`${PluginsStorageDirectory}/${plugin.manifest.id}.json`, {
|
|
||||||
...storageOptions,
|
|
||||||
directory: 'documents',
|
|
||||||
}))
|
|
||||||
},
|
},
|
||||||
})
|
))
|
||||||
|
|
||||||
for (const ext of _initExts) ext(api, plugin)
|
for (const ext of _initExts) ext(api, plugin)
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue