feat(infra): framework

This commit is contained in:
EYHN
2024-04-17 14:12:29 +08:00
parent ab17a05df3
commit 06fda3b62c
467 changed files with 9996 additions and 8697 deletions
@@ -0,0 +1,17 @@
export { GlobalCache, GlobalState } from './providers/global';
export { GlobalCacheService, GlobalStateService } from './services/global';
import type { Framework } from '../../framework';
import { MemoryMemento } from '../../storage';
import { GlobalCache, GlobalState } from './providers/global';
import { GlobalCacheService, GlobalStateService } from './services/global';
export const configureGlobalStorageModule = (framework: Framework) => {
framework.service(GlobalStateService, [GlobalState]);
framework.service(GlobalCacheService, [GlobalCache]);
};
export const configureTestingGlobalStorage = (framework: Framework) => {
framework.impl(GlobalCache, MemoryMemento);
framework.impl(GlobalState, MemoryMemento);
};
@@ -0,0 +1,20 @@
import { createIdentifier } from '../../../framework';
import type { Memento } from '../../../storage';
/**
* A memento object that stores the entire application state.
*
* State is persisted, even the application is closed.
*/
export interface GlobalState extends Memento {}
export const GlobalState = createIdentifier<GlobalState>('GlobalState');
/**
* A memento object that stores the entire application cache.
*
* Cache may be deleted from time to time, business logic should not rely on cache.
*/
export interface GlobalCache extends Memento {}
export const GlobalCache = createIdentifier<GlobalCache>('GlobalCache');
@@ -0,0 +1,14 @@
import { Service } from '../../../framework';
import type { GlobalCache, GlobalState } from '../providers/global';
export class GlobalStateService extends Service {
constructor(public readonly globalState: GlobalState) {
super();
}
}
export class GlobalCacheService extends Service {
constructor(public readonly globalCache: GlobalCache) {
super();
}
}