@artus/core
Advanced tools
Comparing version 1.0.0-beta.14 to 1.0.0-beta.15
@@ -11,6 +11,5 @@ import 'reflect-metadata'; | ||
manifest?: Manifest; | ||
protected container: Container; | ||
container: Container; | ||
protected lifecycleManager: LifecycleManager; | ||
protected loaderFactory: LoaderFactory; | ||
protected defaultClazzLoaded: boolean; | ||
constructor(opts?: ApplicationInitOptions); | ||
@@ -24,4 +23,3 @@ get config(): Record<string, any>; | ||
get configurationHandler(): ConfigurationHandler; | ||
getContainer(): Container; | ||
loadDefaultClass(): Promise<void>; | ||
loadDefaultClass(): void; | ||
load(manifest: Manifest, root?: string): Promise<this>; | ||
@@ -28,0 +26,0 @@ run(): Promise<void>; |
@@ -17,6 +17,6 @@ "use strict"; | ||
var _a; | ||
this.defaultClazzLoaded = false; | ||
this.container = new injection_1.Container((_a = opts === null || opts === void 0 ? void 0 : opts.containerName) !== null && _a !== void 0 ? _a : constant_1.ArtusInjectEnum.DefaultContainerName); | ||
this.lifecycleManager = new lifecycle_1.LifecycleManager(this, this.container); | ||
this.loaderFactory = loader_1.LoaderFactory.create(this.container); | ||
this.loadDefaultClass(); | ||
process.on('SIGINT', () => this.close(true)); | ||
@@ -46,11 +46,7 @@ process.on('SIGTERM', () => this.close(true)); | ||
} | ||
// 兜底方法,不建议对外部使用 | ||
getContainer() { | ||
return this.container; | ||
} | ||
async loadDefaultClass() { | ||
loadDefaultClass() { | ||
// load Artus default clazz | ||
this.container.set({ id: injection_1.Container, value: this.container }); | ||
this.container.set({ id: constant_1.ArtusInjectEnum.Application, value: this }); | ||
this.container.set({ id: constant_1.ArtusInjectEnum.LifecycleManager, value: this.lifecycleManager }); | ||
// SEEME: 暂时使用 set 进行注入,后续考虑更改为 Loader | ||
this.container.set({ type: configuration_1.default }); | ||
@@ -60,8 +56,4 @@ this.container.set({ type: logger_1.ArtusLogger }); | ||
this.container.set({ type: exception_1.ExceptionHandler }); | ||
this.defaultClazzLoaded = true; | ||
} | ||
async load(manifest, root = process.cwd()) { | ||
if (!this.defaultClazzLoaded) { | ||
await this.loadDefaultClass(); | ||
} | ||
// Load user manifest | ||
@@ -68,0 +60,0 @@ this.manifest = manifest; |
@@ -37,1 +37,2 @@ export declare const DEFAULT_LOADER = "module"; | ||
export declare const DEFAULT_CONFIG_DIR = "src/config"; | ||
export declare const SHOULD_OVERWRITE_VALUE = "shouldOverwrite"; |
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.DEFAULT_CONFIG_DIR = exports.DEFAULT_LOADER_LIST_WITH_ORDER = exports.EXCEPTION_FILENAME = exports.PLUGIN_META_FILENAME = exports.PACKAGE_JSON = exports.CONFIG_PATTERN = exports.PLUGIN_CONFIG_PATTERN = exports.FRAMEWORK_PATTERN = exports.DEFAULT_EXCLUDES = exports.HOOK_CONFIG_HANDLE = exports.HOOK_FILE_LOADER = exports.CONSTRUCTOR_PARAMS_CONTEXT = exports.CONSTRUCTOR_PARAMS_CONTAINER = exports.CONSTRUCTOR_PARAMS_APP = exports.CONSTRUCTOR_PARAMS = exports.HOOK_NAME_META_PREFIX = exports.ARTUS_DEFAULT_CONFIG_ENV = exports.ARTUS_SERVER_ENV = exports.ARTUS_EXCEPTION_DEFAULT_LOCALE = exports.ArtusInjectEnum = exports.ArtusInjectPrefix = exports.LOADER_NAME_META = exports.DEFAULT_LOADER = void 0; | ||
exports.SHOULD_OVERWRITE_VALUE = exports.DEFAULT_CONFIG_DIR = exports.DEFAULT_LOADER_LIST_WITH_ORDER = exports.EXCEPTION_FILENAME = exports.PLUGIN_META_FILENAME = exports.PACKAGE_JSON = exports.CONFIG_PATTERN = exports.PLUGIN_CONFIG_PATTERN = exports.FRAMEWORK_PATTERN = exports.DEFAULT_EXCLUDES = exports.HOOK_CONFIG_HANDLE = exports.HOOK_FILE_LOADER = exports.CONSTRUCTOR_PARAMS_CONTEXT = exports.CONSTRUCTOR_PARAMS_CONTAINER = exports.CONSTRUCTOR_PARAMS_APP = exports.CONSTRUCTOR_PARAMS = exports.HOOK_NAME_META_PREFIX = exports.ARTUS_DEFAULT_CONFIG_ENV = exports.ARTUS_SERVER_ENV = exports.ARTUS_EXCEPTION_DEFAULT_LOCALE = exports.ArtusInjectEnum = exports.ArtusInjectPrefix = exports.LOADER_NAME_META = exports.DEFAULT_LOADER = void 0; | ||
exports.DEFAULT_LOADER = 'module'; | ||
@@ -60,2 +60,3 @@ exports.LOADER_NAME_META = 'loader:name'; | ||
exports.DEFAULT_CONFIG_DIR = 'src/config'; | ||
exports.SHOULD_OVERWRITE_VALUE = 'shouldOverwrite'; | ||
//# sourceMappingURL=constant.js.map |
@@ -6,2 +6,3 @@ "use strict"; | ||
const compatible_require_1 = tslib_1.__importDefault(require("../../utils/compatible_require")); | ||
const constant_1 = require("../../constant"); | ||
let ModuleLoader = class ModuleLoader { | ||
@@ -20,3 +21,4 @@ constructor(container) { | ||
} | ||
if (!this.container.hasValue(opts)) { | ||
const shouldOverwriteValue = Reflect.getMetadata(constant_1.SHOULD_OVERWRITE_VALUE, moduleClazz); | ||
if (shouldOverwriteValue || !this.container.hasValue(opts)) { | ||
this.container.set(opts); | ||
@@ -23,0 +25,0 @@ } |
import { LoggerLevel } from './level'; | ||
import { Logger, LoggerOptions, LogOptions } from './types'; | ||
export declare class BaseLogger implements Logger { | ||
private appConfig; | ||
private container; | ||
protected get loggerOpts(): LoggerOptions; | ||
@@ -6,0 +6,0 @@ protected checkLoggerLevel(level: LoggerLevel): boolean; |
@@ -10,4 +10,11 @@ "use strict"; | ||
get loggerOpts() { | ||
var _a, _b; | ||
return (_b = (_a = this.appConfig) === null || _a === void 0 ? void 0 : _a.logger) !== null && _b !== void 0 ? _b : {}; | ||
var _a; | ||
let appConfig = {}; | ||
try { | ||
appConfig = this.container.get(constant_1.ArtusInjectEnum.Config); | ||
} | ||
catch (e) { | ||
// do nothing | ||
} | ||
return (_a = appConfig === null || appConfig === void 0 ? void 0 : appConfig.logger) !== null && _a !== void 0 ? _a : {}; | ||
} | ||
@@ -45,6 +52,6 @@ checkLoggerLevel(level) { | ||
tslib_1.__decorate([ | ||
(0, injection_1.Inject)(constant_1.ArtusInjectEnum.Config), | ||
tslib_1.__metadata("design:type", Object) | ||
], BaseLogger.prototype, "appConfig", void 0); | ||
(0, injection_1.Inject)(), | ||
tslib_1.__metadata("design:type", injection_1.Container) | ||
], BaseLogger.prototype, "container", void 0); | ||
exports.BaseLogger = BaseLogger; | ||
//# sourceMappingURL=base.js.map |
@@ -7,5 +7,8 @@ "use strict"; | ||
const DefineLogger = (injectableOpts = {}) => { | ||
return (0, injection_1.Injectable)(Object.assign({ id: constant_1.ArtusInjectEnum.Logger, scope: injection_1.ScopeEnum.SINGLETON }, injectableOpts)); | ||
return (target) => { | ||
Reflect.defineMetadata(constant_1.SHOULD_OVERWRITE_VALUE, true, target); | ||
return (0, injection_1.Injectable)(Object.assign({ id: constant_1.ArtusInjectEnum.Logger, scope: injection_1.ScopeEnum.SINGLETON }, injectableOpts))(target); | ||
}; | ||
}; | ||
exports.DefineLogger = DefineLogger; | ||
//# sourceMappingURL=decorator.js.map |
@@ -7,8 +7,11 @@ "use strict"; | ||
function DefineTrigger() { | ||
return (target) => (0, injection_1.Injectable)({ | ||
id: constant_1.ArtusInjectEnum.Trigger, | ||
scope: injection_1.ScopeEnum.SINGLETON, | ||
})(target); | ||
return (target) => { | ||
Reflect.defineMetadata(constant_1.SHOULD_OVERWRITE_VALUE, true, target); | ||
return (0, injection_1.Injectable)({ | ||
id: constant_1.ArtusInjectEnum.Trigger, | ||
scope: injection_1.ScopeEnum.SINGLETON, | ||
})(target); | ||
}; | ||
} | ||
exports.DefineTrigger = DefineTrigger; | ||
//# sourceMappingURL=decorator.js.map |
@@ -18,3 +18,7 @@ "use strict"; | ||
const ctx = new pipeline_1.Context(input, output); | ||
ctx.container = new injection_1.ExecutionContainer(ctx, this.app.getContainer()); | ||
ctx.container = new injection_1.ExecutionContainer(ctx, this.app.container); | ||
ctx.container.set({ | ||
id: injection_1.ExecutionContainer, | ||
value: ctx.container, | ||
}); | ||
return ctx; | ||
@@ -21,0 +25,0 @@ } |
@@ -17,2 +17,3 @@ import { Container } from '@artus/injection'; | ||
export interface Application { | ||
container: Container; | ||
manifest?: Manifest; | ||
@@ -24,3 +25,2 @@ config?: Record<string, any>; | ||
registerHook(hookName: string, hookFn: HookFunction): void; | ||
getContainer(): Container; | ||
} | ||
@@ -27,0 +27,0 @@ export interface TriggerType { |
{ | ||
"name": "@artus/core", | ||
"version": "1.0.0-beta.14", | ||
"version": "1.0.0-beta.15", | ||
"description": "Core package of Artus", | ||
@@ -5,0 +5,0 @@ "main": "./lib/index.js", |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
153738
2360