mirror of
https://github.com/toeverything/AFFiNE.git
synced 2026-02-13 04:48:53 +00:00
Co-authored-by: Hongtao Lye <codert.sn@gmail.com> Co-authored-by: liuyi <forehalo@gmail.com> Co-authored-by: LongYinan <lynweklm@gmail.com> Co-authored-by: X1a0t <405028157@qq.com> Co-authored-by: JimmFly <yangjinfei001@gmail.com> Co-authored-by: Peng Xiao <pengxiao@outlook.com> Co-authored-by: xiaodong zuo <53252747+zuoxiaodong0815@users.noreply.github.com> Co-authored-by: DarkSky <25152247+darkskygit@users.noreply.github.com> Co-authored-by: Qi <474021214@qq.com> Co-authored-by: danielchim <kahungchim@gmail.com>
37 lines
944 B
TypeScript
37 lines
944 B
TypeScript
import { createRequire } from 'node:module';
|
|
|
|
import { type DynamicModule, type FactoryProvider } from '@nestjs/common';
|
|
|
|
import { Config } from '../config';
|
|
|
|
export const StorageProvide = Symbol('Storage');
|
|
|
|
let storageModule: typeof import('@affine/storage');
|
|
try {
|
|
storageModule = await import('@affine/storage');
|
|
} catch {
|
|
const require = createRequire(import.meta.url);
|
|
storageModule = require('../../storage.node');
|
|
}
|
|
|
|
export class StorageModule {
|
|
static forRoot(): DynamicModule {
|
|
const storageProvider: FactoryProvider = {
|
|
provide: StorageProvide,
|
|
useFactory: async (config: Config) => {
|
|
return storageModule.Storage.connect(config.db.url);
|
|
},
|
|
inject: [Config],
|
|
};
|
|
|
|
return {
|
|
global: true,
|
|
module: StorageModule,
|
|
providers: [storageProvider],
|
|
exports: [storageProvider],
|
|
};
|
|
}
|
|
}
|
|
|
|
export const mergeUpdatesInApplyWay = storageModule.mergeUpdatesInApplyWay;
|