From 062f190a6a90d4abc5982058adbc8f10ba9e34e2 Mon Sep 17 00:00:00 2001 From: Noah Gao Date: Tue, 31 May 2022 10:14:58 +0800 Subject: [PATCH] fix: constant naming & remove const enum (#86) --- src/application.ts | 2 +- src/configuration/decorator.ts | 2 +- src/configuration/index.ts | 2 +- src/{constraints.ts => constant.ts} | 2 +- src/decorator.ts | 2 +- src/exception/error.ts | 2 +- src/index.ts | 4 ++-- src/lifecycle/index.ts | 2 +- src/loader/decorator.ts | 2 +- src/loader/factory.ts | 2 +- src/loader/impl/config.ts | 2 +- src/loader/impl/exception.ts | 2 +- src/loader/impl/framework_config.ts | 2 +- src/loader/impl/lifecycle.ts | 2 +- src/loader/impl/package.ts | 2 +- src/loader/impl/plugin_config.ts | 2 +- src/logger/base.ts | 2 +- src/logger/decorator.ts | 2 +- src/logger/level.ts | 2 +- src/plugin/types.ts | 2 +- src/scanner/scan.ts | 2 +- src/scanner/utils.ts | 2 +- src/trigger/decorator.ts | 2 +- src/trigger/index.ts | 2 +- test/config.test.ts | 2 +- test/fixtures/frameworks/bar/src/http.ts | 2 +- test/framework.test.ts | 2 +- 27 files changed, 28 insertions(+), 28 deletions(-) rename src/{constraints.ts => constant.ts} (98%) diff --git a/src/application.ts b/src/application.ts index ede1909..3ce379e 100644 --- a/src/application.ts +++ b/src/application.ts @@ -1,6 +1,6 @@ import 'reflect-metadata'; import { Container } from '@artus/injection'; -import { ArtusInjectEnum } from './constraints'; +import { ArtusInjectEnum } from './constant'; import { ArtusStdError, ExceptionHandler } from './exception'; import { HookFunction, LifecycleManager } from './lifecycle'; import { LoaderFactory, Manifest } from './loader'; diff --git a/src/configuration/decorator.ts b/src/configuration/decorator.ts index ae87407..6f51576 100644 --- a/src/configuration/decorator.ts +++ b/src/configuration/decorator.ts @@ -1,4 +1,4 @@ -import { HOOK_CONFIG_HANDLE } from "../constraints"; +import { HOOK_CONFIG_HANDLE } from "../constant"; export function DefineConfigHandle(handleName?: string): PropertyDecorator { return (target: any, propertyKey: string | symbol) => { diff --git a/src/configuration/index.ts b/src/configuration/index.ts index 3780745..b4a6727 100644 --- a/src/configuration/index.ts +++ b/src/configuration/index.ts @@ -1,5 +1,5 @@ import { Injectable } from '@artus/injection'; -import { ARTUS_DEFAULT_CONFIG_ENV, ARTUS_SERVER_ENV } from '../constraints'; +import { ARTUS_DEFAULT_CONFIG_ENV, ARTUS_SERVER_ENV } from '../constant'; import { ManifestItem } from '../loader'; import { mergeConfig } from '../loader/utils/merge'; import compatibleRequire from '../utils/compatible_require'; diff --git a/src/constraints.ts b/src/constant.ts similarity index 98% rename from src/constraints.ts rename to src/constant.ts index 75be88a..59a92bd 100644 --- a/src/constraints.ts +++ b/src/constant.ts @@ -3,7 +3,7 @@ export const LOADER_NAME_META = 'loader:name'; export const ArtusInjectPrefix = 'artus#'; -export const enum ArtusInjectEnum { +export enum ArtusInjectEnum { Application = 'artus#application', Config = 'artus#config', DefaultContainerName = 'artus#default_container', diff --git a/src/decorator.ts b/src/decorator.ts index 7ecfd13..77cf655 100644 --- a/src/decorator.ts +++ b/src/decorator.ts @@ -5,7 +5,7 @@ import { HOOK_NAME_META_PREFIX, CONSTRUCTOR_PARAMS_CONTEXT, HOOK_FILE_LOADER, -} from './constraints'; +} from './constant'; export function LifecycleHookUnit(): ClassDecorator { return (target: any) => { diff --git a/src/exception/error.ts b/src/exception/error.ts index 57700d6..7bffa9b 100644 --- a/src/exception/error.ts +++ b/src/exception/error.ts @@ -1,4 +1,4 @@ -import { ARTUS_EXCEPTION_DEFAULT_LOCALE } from '../constraints'; +import { ARTUS_EXCEPTION_DEFAULT_LOCALE } from '../constant'; import { ExceptionItem } from './types'; export const ErrorCodeUtils = { diff --git a/src/index.ts b/src/index.ts index 85d242b..39856b6 100644 --- a/src/index.ts +++ b/src/index.ts @@ -7,7 +7,7 @@ export { export { ArtusInjectEnum -} from './constraints'; +} from './constant'; export * from './loader'; export * from './logger'; export * from './lifecycle'; @@ -17,7 +17,7 @@ export * from './application'; export * from './scanner'; export * from './decorator'; export * from './types'; -export * from './constraints'; +export * from './constant'; import ConfigurationHandler from './configuration'; export { ConfigurationHandler }; diff --git a/src/lifecycle/index.ts b/src/lifecycle/index.ts index 3ba0421..f149f9c 100644 --- a/src/lifecycle/index.ts +++ b/src/lifecycle/index.ts @@ -5,7 +5,7 @@ import { CONSTRUCTOR_PARAMS_APP, CONSTRUCTOR_PARAMS_CONTAINER, HOOK_NAME_META_PREFIX -} from '../constraints'; +} from '../constant'; export type HookFunction = (hookProps : { app: Application, diff --git a/src/loader/decorator.ts b/src/loader/decorator.ts index 57635e8..1a2e381 100644 --- a/src/loader/decorator.ts +++ b/src/loader/decorator.ts @@ -1,4 +1,4 @@ -import { LOADER_NAME_META } from '../constraints'; +import { LOADER_NAME_META } from '../constant'; export const DefineLoader = (loaderName: string): ClassDecorator => (target: Function) => { diff --git a/src/loader/factory.ts b/src/loader/factory.ts index 35f99aa..c0edc7b 100644 --- a/src/loader/factory.ts +++ b/src/loader/factory.ts @@ -1,6 +1,6 @@ import * as path from 'path'; import { Container } from '@artus/injection'; -import { ArtusInjectEnum, DEFAULT_LOADER, HOOK_FILE_LOADER, LOADER_NAME_META } from '../constraints'; +import { ArtusInjectEnum, DEFAULT_LOADER, HOOK_FILE_LOADER, LOADER_NAME_META } from '../constant'; import { Manifest, ManifestItem, LoaderConstructor, LoaderHookUnit, LoaderCheckOptions } from './types'; import ConfigurationHandler from '../configuration'; import { LifecycleManager } from '../lifecycle'; diff --git a/src/loader/impl/config.ts b/src/loader/impl/config.ts index f1a3045..877df9c 100644 --- a/src/loader/impl/config.ts +++ b/src/loader/impl/config.ts @@ -1,7 +1,7 @@ import * as path from 'path'; import { Container } from '@artus/injection'; import ConfigurationHandler from '../../configuration'; -import { ArtusInjectEnum, ARTUS_DEFAULT_CONFIG_ENV, CONFIG_PATTERN } from '../../constraints'; +import { ArtusInjectEnum, ARTUS_DEFAULT_CONFIG_ENV, CONFIG_PATTERN } from '../../constant'; import { DefineLoader } from '../decorator'; import { ManifestItem, Loader, LoaderCheckOptions } from '../types'; import compatibleRequire from '../../utils/compatible_require'; diff --git a/src/loader/impl/exception.ts b/src/loader/impl/exception.ts index c3f7d28..78d1eb8 100644 --- a/src/loader/impl/exception.ts +++ b/src/loader/impl/exception.ts @@ -4,7 +4,7 @@ import { ManifestItem, Loader, LoaderCheckOptions } from '../types'; import { ExceptionItem } from '../../exception/types'; import { ExceptionHandler } from '../../exception'; import { loadMetaFile } from '../../utils/load_meta_file'; -import { EXCEPTION_FILE } from '../../constraints'; +import { EXCEPTION_FILE } from '../../constant'; import { isMatch } from '../../utils'; @DefineLoader('exception') diff --git a/src/loader/impl/framework_config.ts b/src/loader/impl/framework_config.ts index 3802b08..e814a40 100644 --- a/src/loader/impl/framework_config.ts +++ b/src/loader/impl/framework_config.ts @@ -2,7 +2,7 @@ import ConfigurationHandler from '../../configuration'; import { DefineLoader } from '../decorator'; import { ManifestItem, Loader, LoaderCheckOptions } from '../types'; import compatibleRequire from '../../utils/compatible_require'; -import { ArtusInjectEnum, ARTUS_DEFAULT_CONFIG_ENV, FRAMEWORK_PATTERN } from '../../constraints'; +import { ArtusInjectEnum, ARTUS_DEFAULT_CONFIG_ENV, FRAMEWORK_PATTERN } from '../../constant'; import ConfigLoader from './config'; import { isMatch } from '../../utils'; diff --git a/src/loader/impl/lifecycle.ts b/src/loader/impl/lifecycle.ts index 0e474e9..7565883 100644 --- a/src/loader/impl/lifecycle.ts +++ b/src/loader/impl/lifecycle.ts @@ -1,5 +1,5 @@ import { Constructable, Container } from '@artus/injection'; -import { ArtusInjectEnum } from '../../constraints'; +import { ArtusInjectEnum } from '../../constant'; import { LifecycleManager } from '../../lifecycle'; import { ApplicationLifecycle } from '../../types'; import { DefineLoader } from '../decorator'; diff --git a/src/loader/impl/package.ts b/src/loader/impl/package.ts index a1dfdab..ce9a354 100644 --- a/src/loader/impl/package.ts +++ b/src/loader/impl/package.ts @@ -3,7 +3,7 @@ import ConfigurationHandler from '../../configuration'; import { DefineLoader } from '../decorator'; import { ManifestItem, Loader, LoaderCheckOptions } from '../types'; import compatibleRequire from '../../utils/compatible_require'; -import { PACKAGE_JSON } from '../../constraints'; +import { PACKAGE_JSON } from '../../constant'; import { isMatch } from '../../utils'; @DefineLoader('package-json') diff --git a/src/loader/impl/plugin_config.ts b/src/loader/impl/plugin_config.ts index 2799800..0f0b7c2 100644 --- a/src/loader/impl/plugin_config.ts +++ b/src/loader/impl/plugin_config.ts @@ -1,4 +1,4 @@ -import { PLUGIN_CONFIG_PATTERN } from '../../constraints'; +import { PLUGIN_CONFIG_PATTERN } from '../../constant'; import { isMatch } from '../../utils'; import { DefineLoader } from '../decorator'; import { ManifestItem, Loader, LoaderCheckOptions } from '../types'; diff --git a/src/logger/base.ts b/src/logger/base.ts index 99a946e..f227194 100644 --- a/src/logger/base.ts +++ b/src/logger/base.ts @@ -1,5 +1,5 @@ import { Inject } from '@artus/injection'; -import { ArtusInjectEnum } from '../constraints'; +import { ArtusInjectEnum } from '../constant'; import { LoggerLevel, LOGGER_LEVEL_MAP } from './level'; import { Logger, LoggerOptions, LogOptions } from './types'; diff --git a/src/logger/decorator.ts b/src/logger/decorator.ts index b469d06..890a28d 100644 --- a/src/logger/decorator.ts +++ b/src/logger/decorator.ts @@ -1,5 +1,5 @@ import { Injectable, InjectableOption, ScopeEnum } from '@artus/injection'; -import { ArtusInjectEnum } from '../constraints'; +import { ArtusInjectEnum } from '../constant'; export const DefineLogger = (injectableOpts: InjectableOption = {}): ClassDecorator => { return Injectable({ diff --git a/src/logger/level.ts b/src/logger/level.ts index aec9937..b42242d 100644 --- a/src/logger/level.ts +++ b/src/logger/level.ts @@ -1,4 +1,4 @@ -export const enum LoggerLevel { +export enum LoggerLevel { TRACE = 'TRACE', DEBUG = 'DEBUG', INFO = 'INFO', diff --git a/src/plugin/types.ts b/src/plugin/types.ts index 43ca761..aeef934 100644 --- a/src/plugin/types.ts +++ b/src/plugin/types.ts @@ -1,4 +1,4 @@ -export const enum PluginType { +export enum PluginType { simple = 'simple', module = 'module', } diff --git a/src/scanner/scan.ts b/src/scanner/scan.ts index 6a8cb90..8bc967b 100644 --- a/src/scanner/scan.ts +++ b/src/scanner/scan.ts @@ -9,7 +9,7 @@ import { DEFAULT_EXCLUDES, DEFAULT_LOADER_LIST_WITH_ORDER, LOADER_NAME_META, -} from '../constraints'; +} from '../constant'; import { Manifest, ManifestItem } from '../loader'; import { ScannerOptions, WalkOptions } from './types'; import ConfigurationHandler, { ConfigObject } from '../configuration'; diff --git a/src/scanner/utils.ts b/src/scanner/utils.ts index cbdbcb6..d4bbad7 100644 --- a/src/scanner/utils.ts +++ b/src/scanner/utils.ts @@ -7,7 +7,7 @@ import { ArtusInjectEnum, DEFAULT_LOADER, PLUGIN_META -} from '../constraints'; +} from '../constant'; import { LoaderFactory, ManifestItem } from '../loader'; import { WalkOptions } from './types'; import { isMatch } from '../utils'; diff --git a/src/trigger/decorator.ts b/src/trigger/decorator.ts index 32daf87..b9bfd5b 100644 --- a/src/trigger/decorator.ts +++ b/src/trigger/decorator.ts @@ -1,5 +1,5 @@ import { Injectable, ScopeEnum } from '@artus/injection'; -import { ArtusInjectEnum } from '../constraints'; +import { ArtusInjectEnum } from '../constant'; export function DefineTrigger(): ClassDecorator { return (target:any) => Injectable({ diff --git a/src/trigger/index.ts b/src/trigger/index.ts index 8eb3da6..02e46aa 100644 --- a/src/trigger/index.ts +++ b/src/trigger/index.ts @@ -1,6 +1,6 @@ import { ExecutionContainer, Inject } from '@artus/injection'; import { Input, Context, MiddlewareInput, Pipeline, Output } from '@artus/pipeline'; -import { ArtusInjectEnum } from '../constraints'; +import { ArtusInjectEnum } from '../constant'; import { Application } from '../types'; import { DefineTrigger } from './decorator'; diff --git a/test/config.test.ts b/test/config.test.ts index b0f3f55..00830fa 100644 --- a/test/config.test.ts +++ b/test/config.test.ts @@ -1,5 +1,5 @@ import 'reflect-metadata'; -import { ARTUS_SERVER_ENV } from '../src/constraints'; +import { ARTUS_SERVER_ENV } from '../src/constant'; describe('test/app.test.ts', () => { describe('app with config', () => { diff --git a/test/fixtures/frameworks/bar/src/http.ts b/test/fixtures/frameworks/bar/src/http.ts index 49a4cbe..36375a1 100644 --- a/test/fixtures/frameworks/bar/src/http.ts +++ b/test/fixtures/frameworks/bar/src/http.ts @@ -1,7 +1,7 @@ import 'reflect-metadata'; import { Context, Next } from '@artus/pipeline'; import { Constructable } from '@artus/injection'; -import { CONSTRUCTOR_PARAMS, CONSTRUCTOR_PARAMS_CONTEXT } from '../../../../../src/constraints'; +import { CONSTRUCTOR_PARAMS, CONSTRUCTOR_PARAMS_CONTEXT } from '../../../../../src/constant'; import { HttpTrigger } from '../../abstract/foo'; import { Injectable, ScopeEnum } from '@artus/injection'; diff --git a/test/framework.test.ts b/test/framework.test.ts index b121e5f..cc80f6a 100644 --- a/test/framework.test.ts +++ b/test/framework.test.ts @@ -3,7 +3,7 @@ import { Scanner } from '../src/scanner'; import path from 'path'; import axios from 'axios'; import assert from 'assert'; -import { ARTUS_SERVER_ENV } from '../src/constraints'; +import { ARTUS_SERVER_ENV } from '../src/constant'; describe('test/framework.test.ts', () => { beforeEach(async function () {