mirror of
https://github.com/toeverything/AFFiNE.git
synced 2026-07-17 01:56:27 +08:00
refactor(server): standalone runtime module (#9120)
This commit is contained in:
@@ -3,7 +3,6 @@ import { merge } from 'lodash-es';
|
||||
|
||||
import { AFFiNEConfig } from './def';
|
||||
import { Config } from './provider';
|
||||
import { Runtime } from './runtime/service';
|
||||
|
||||
export * from './def';
|
||||
export * from './default';
|
||||
@@ -17,10 +16,10 @@ function createConfigProvider(
|
||||
): FactoryProvider<Config> {
|
||||
return {
|
||||
provide: Config,
|
||||
useFactory: (runtime: Runtime) => {
|
||||
return Object.freeze(merge({}, globalThis.AFFiNE, override, { runtime }));
|
||||
useFactory: () => {
|
||||
return Object.freeze(merge({}, globalThis.AFFiNE, override));
|
||||
},
|
||||
inject: [Runtime],
|
||||
inject: [],
|
||||
};
|
||||
}
|
||||
|
||||
@@ -31,10 +30,8 @@ export class ConfigModule {
|
||||
return {
|
||||
global: true,
|
||||
module: ConfigModule,
|
||||
providers: [provider, Runtime],
|
||||
providers: [provider],
|
||||
exports: [provider],
|
||||
};
|
||||
};
|
||||
}
|
||||
|
||||
export { Runtime };
|
||||
|
||||
@@ -1,6 +1,5 @@
|
||||
import { ApplyType } from '../utils/types';
|
||||
import { AFFiNEConfig } from './def';
|
||||
import type { Runtime } from './runtime/service';
|
||||
|
||||
/**
|
||||
* @example
|
||||
@@ -14,6 +13,4 @@ import type { Runtime } from './runtime/service';
|
||||
* }
|
||||
* }
|
||||
*/
|
||||
export class Config extends ApplyType<AFFiNEConfig>() {
|
||||
runtime!: Runtime;
|
||||
}
|
||||
export class Config extends ApplyType<AFFiNEConfig>() {}
|
||||
|
||||
@@ -30,6 +30,7 @@ export {
|
||||
OptionalModule,
|
||||
} from './nestjs';
|
||||
export { type PrismaTransaction } from './prisma';
|
||||
export { Runtime } from './runtime';
|
||||
export * from './storage';
|
||||
export { type StorageProvider, StorageProviderFactory } from './storage';
|
||||
export { CloudThrottlerGuard, SkipThrottle, Throttle } from './throttler';
|
||||
|
||||
+6
-6
@@ -1,10 +1,10 @@
|
||||
import { OnEvent } from '../../event';
|
||||
import { Payload } from '../../event/def';
|
||||
import { FlattenedAppRuntimeConfig } from '../types';
|
||||
import { FlattenedAppRuntimeConfig } from '../config/types';
|
||||
import { OnEvent } from '../event';
|
||||
import { Payload } from '../event/def';
|
||||
|
||||
declare module '../../event/def' {
|
||||
declare module '../event/def' {
|
||||
interface EventDefinitions {
|
||||
runtimeConfig: {
|
||||
runtime: {
|
||||
[K in keyof FlattenedAppRuntimeConfig]: {
|
||||
changed: Payload<FlattenedAppRuntimeConfig[K]>;
|
||||
};
|
||||
@@ -18,5 +18,5 @@ declare module '../../event/def' {
|
||||
export const OnRuntimeConfigChange_DO_NOT_USE = (
|
||||
nameWithModule: keyof FlattenedAppRuntimeConfig
|
||||
) => {
|
||||
return OnEvent(`runtimeConfig.${nameWithModule}.changed`);
|
||||
return OnEvent(`runtime.${nameWithModule}.changed`);
|
||||
};
|
||||
@@ -0,0 +1,11 @@
|
||||
import { Global, Module } from '@nestjs/common';
|
||||
|
||||
import { Runtime } from './service';
|
||||
|
||||
@Global()
|
||||
@Module({
|
||||
providers: [Runtime],
|
||||
exports: [Runtime],
|
||||
})
|
||||
export class RuntimeModule {}
|
||||
export { Runtime };
|
||||
+8
-5
@@ -8,11 +8,14 @@ import {
|
||||
import { PrismaClient } from '@prisma/client';
|
||||
import { difference, keyBy } from 'lodash-es';
|
||||
|
||||
import { Cache } from '../../cache';
|
||||
import { InvalidRuntimeConfigType, RuntimeConfigNotFound } from '../../error';
|
||||
import { defer } from '../../utils/promise';
|
||||
import { defaultRuntimeConfig, runtimeConfigType } from '../register';
|
||||
import { AppRuntimeConfigModules, FlattenedAppRuntimeConfig } from '../types';
|
||||
import { Cache } from '../cache';
|
||||
import { defaultRuntimeConfig, runtimeConfigType } from '../config/register';
|
||||
import {
|
||||
AppRuntimeConfigModules,
|
||||
FlattenedAppRuntimeConfig,
|
||||
} from '../config/types';
|
||||
import { InvalidRuntimeConfigType, RuntimeConfigNotFound } from '../error';
|
||||
import { defer } from '../utils/promise';
|
||||
|
||||
function validateConfigType<K extends keyof FlattenedAppRuntimeConfig>(
|
||||
key: K,
|
||||
Reference in New Issue
Block a user