@midwayjs/core 3.0.0-alpha.9 → 3.0.0-beta.4

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (109) hide show
  1. package/CHANGELOG.md +60 -0
  2. package/dist/baseFramework.d.ts +55 -22
  3. package/dist/baseFramework.js +151 -232
  4. package/dist/{util → common}/fileDetector.d.ts +0 -0
  5. package/dist/{util → common}/fileDetector.js +16 -10
  6. package/dist/common/filterManager.d.ts +19 -0
  7. package/dist/common/filterManager.js +85 -0
  8. package/dist/common/middlewareManager.d.ts +11 -0
  9. package/dist/common/middlewareManager.js +48 -0
  10. package/dist/common/serviceFactory.d.ts +15 -0
  11. package/dist/{util → common}/serviceFactory.js +16 -6
  12. package/dist/{util → common}/triggerCollector.d.ts +0 -0
  13. package/dist/{util → common}/triggerCollector.js +0 -0
  14. package/dist/common/webGenerator.d.ts +27 -0
  15. package/dist/common/webGenerator.js +125 -0
  16. package/dist/{util → common}/webRouterCollector.d.ts +21 -2
  17. package/dist/{util → common}/webRouterCollector.js +115 -138
  18. package/dist/config/config.default.d.ts +7 -0
  19. package/dist/config/config.default.js +28 -0
  20. package/dist/context/container.d.ts +73 -43
  21. package/dist/context/container.js +277 -270
  22. package/dist/context/definitionRegistry.d.ts +26 -0
  23. package/dist/context/definitionRegistry.js +124 -0
  24. package/dist/context/managedResolverFactory.d.ts +15 -32
  25. package/dist/context/managedResolverFactory.js +88 -317
  26. package/dist/context/providerWrapper.d.ts +2 -3
  27. package/dist/context/requestContainer.d.ts +0 -2
  28. package/dist/context/requestContainer.js +9 -26
  29. package/dist/definitions/functionDefinition.d.ts +3 -4
  30. package/dist/definitions/functionDefinition.js +0 -6
  31. package/dist/definitions/objectCreator.js +6 -6
  32. package/dist/definitions/objectDefinition.d.ts +4 -6
  33. package/dist/definitions/objectDefinition.js +0 -8
  34. package/dist/definitions/properties.d.ts +2 -15
  35. package/dist/definitions/properties.js +3 -72
  36. package/dist/error/base.d.ts +13 -0
  37. package/dist/error/base.js +19 -0
  38. package/dist/error/code.d.ts +59 -0
  39. package/dist/error/code.js +64 -0
  40. package/dist/error/framework.d.ts +21 -0
  41. package/dist/error/framework.js +52 -0
  42. package/dist/error/http.d.ts +58 -0
  43. package/dist/error/http.js +82 -0
  44. package/dist/error/index.d.ts +4 -0
  45. package/dist/error/index.js +16 -0
  46. package/dist/functional/configuration.d.ts +4 -2
  47. package/dist/functional/configuration.js +12 -2
  48. package/dist/index.d.ts +23 -10
  49. package/dist/index.js +33 -33
  50. package/dist/interface.d.ts +263 -184
  51. package/dist/interface.js +9 -1
  52. package/dist/service/aspectService.d.ts +11 -14
  53. package/dist/service/aspectService.js +116 -172
  54. package/dist/service/configService.d.ts +10 -8
  55. package/dist/service/configService.js +61 -38
  56. package/dist/service/decoratorService.d.ts +23 -0
  57. package/dist/service/decoratorService.js +149 -0
  58. package/dist/service/environmentService.js +15 -4
  59. package/dist/service/frameworkService.d.ts +25 -0
  60. package/dist/service/frameworkService.js +171 -0
  61. package/dist/service/informationService.d.ts +4 -7
  62. package/dist/service/informationService.js +41 -10
  63. package/dist/service/lifeCycleService.d.ts +14 -0
  64. package/dist/service/lifeCycleService.js +130 -0
  65. package/dist/service/loggerService.d.ts +27 -0
  66. package/dist/service/loggerService.js +132 -0
  67. package/dist/service/middlewareService.d.ts +11 -0
  68. package/dist/service/middlewareService.js +119 -0
  69. package/dist/{features/pipeline.d.ts → service/pipelineService.d.ts} +56 -46
  70. package/dist/{features/pipeline.js → service/pipelineService.js} +54 -19
  71. package/dist/setup.d.ts +4 -0
  72. package/dist/setup.js +113 -0
  73. package/dist/util/contextUtil.d.ts +1 -1
  74. package/dist/util/contextUtil.js +2 -2
  75. package/dist/util/index.d.ts +55 -0
  76. package/dist/util/index.js +137 -7
  77. package/dist/util/pathFileUtil.js +2 -2
  78. package/dist/util/pathToRegexp.d.ts +17 -0
  79. package/dist/util/pathToRegexp.js +280 -0
  80. package/dist/util/webRouterParam.d.ts +2 -2
  81. package/dist/util/webRouterParam.js +19 -20
  82. package/package.json +8 -13
  83. package/dist/common/lodashWrap.d.ts +0 -9
  84. package/dist/common/lodashWrap.js +0 -18
  85. package/dist/common/notFoundError.d.ts +0 -8
  86. package/dist/common/notFoundError.js +0 -20
  87. package/dist/common/reflectTool.d.ts +0 -15
  88. package/dist/common/reflectTool.js +0 -83
  89. package/dist/context/applicationContext.d.ts +0 -81
  90. package/dist/context/applicationContext.js +0 -263
  91. package/dist/context/managed.d.ts +0 -45
  92. package/dist/context/managed.js +0 -69
  93. package/dist/context/resolverHandler.d.ts +0 -34
  94. package/dist/context/resolverHandler.js +0 -88
  95. package/dist/definitions/messageSource.d.ts +0 -13
  96. package/dist/definitions/messageSource.js +0 -74
  97. package/dist/definitions/resource.d.ts +0 -27
  98. package/dist/definitions/resource.js +0 -116
  99. package/dist/features/index.d.ts +0 -2
  100. package/dist/features/index.js +0 -3
  101. package/dist/logger.d.ts +0 -4
  102. package/dist/logger.js +0 -20
  103. package/dist/util/containerUtil.d.ts +0 -11
  104. package/dist/util/containerUtil.js +0 -26
  105. package/dist/util/emptyFramework.d.ts +0 -62
  106. package/dist/util/emptyFramework.js +0 -72
  107. package/dist/util/serviceFactory.d.ts +0 -13
  108. package/dist/util/staticConfig.d.ts +0 -10
  109. package/dist/util/staticConfig.js +0 -67
@@ -1,116 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.Resource = void 0;
4
- const fs_1 = require("fs");
5
- const path_1 = require("path");
6
- const url_1 = require("url");
7
- /* tslint:disable:variable-name */
8
- class Resource {
9
- constructor(baseDir, path) {
10
- this._baseDir = null;
11
- this._path = null;
12
- this.encoding = 'UTF-8';
13
- this._baseDir = baseDir;
14
- this._path = path || '.'; // baseDir 目录
15
- }
16
- getPath() {
17
- if (this._baseDir) {
18
- return path_1.resolve(this._baseDir, this._path);
19
- }
20
- return this._path;
21
- }
22
- exists() {
23
- return fs_1.existsSync(this.getPath());
24
- }
25
- isFile() {
26
- const stats = fs_1.lstatSync(this.getPath());
27
- return stats.isFile();
28
- }
29
- isDir() {
30
- const stats = fs_1.lstatSync(this.getPath());
31
- return stats.isDirectory();
32
- }
33
- isURL() {
34
- return this.getPath().indexOf('http') > -1;
35
- }
36
- getURL() {
37
- if (this.isURL()) {
38
- return new url_1.URL(this._path);
39
- }
40
- return null;
41
- }
42
- /**
43
- * 如果是文件则获取当前文件夹路径
44
- * 如果是文件夹则直接作为路径
45
- * @param path 相对路径
46
- */
47
- createRelative(path) {
48
- if (this.isFile()) {
49
- path = path_1.join(path_1.dirname(this.getPath()), path);
50
- }
51
- else {
52
- path = path_1.join(this.getPath(), path);
53
- }
54
- return new Resource(this._baseDir, path);
55
- }
56
- getSubResources() {
57
- if (this.isDir()) {
58
- const files = fs_1.readdirSync(this.getPath());
59
- const arr = files.map(file => {
60
- return new Resource(this.getPath(), file);
61
- });
62
- return arr;
63
- }
64
- return [];
65
- }
66
- getContent() {
67
- if (!this.exists()) {
68
- throw new Error(`${this.getPath()} not found!`);
69
- }
70
- if (!this.isFile()) {
71
- throw new Error(`${this.getPath()} is not a file!`);
72
- }
73
- return fs_1.readFileSync(this.getPath());
74
- }
75
- getContentAsJSON() {
76
- if (!this.exists()) {
77
- throw new Error(`${this.getPath()} not found!`);
78
- }
79
- if (!this.isFile()) {
80
- throw new Error(`${this.getPath()} is not a file!`);
81
- }
82
- if (path_1.parse(this.getPath()).ext === '.json') {
83
- const buf = fs_1.readFileSync(this.getPath());
84
- try {
85
- return JSON.parse(buf.toString());
86
- // eslint-disable-next-line no-empty
87
- }
88
- catch (e) { }
89
- return {};
90
- }
91
- return require(this.getPath());
92
- }
93
- get name() {
94
- if (this.exists()) {
95
- return path_1.parse(this.getPath()).name;
96
- }
97
- return null;
98
- }
99
- get contentLength() {
100
- if (this.exists()) {
101
- const buf = fs_1.readFileSync(this.getPath());
102
- return buf.length;
103
- }
104
- return 0;
105
- }
106
- get lastModified() {
107
- if (this.exists()) {
108
- const stats = fs_1.lstatSync(this.getPath());
109
- return stats.mtime.getTime();
110
- }
111
- return 0;
112
- }
113
- }
114
- exports.Resource = Resource;
115
- /* tslint:enable:variable-name */
116
- //# sourceMappingURL=resource.js.map
@@ -1,2 +0,0 @@
1
- export { IPipelineContext, IPipelineHandler, IPipelineOptions, IPipelineResult, IValveHandler, } from './pipeline';
2
- //# sourceMappingURL=index.d.ts.map
@@ -1,3 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- //# sourceMappingURL=index.js.map
package/dist/logger.d.ts DELETED
@@ -1,4 +0,0 @@
1
- import { LoggerOptions } from '@midwayjs/logger';
2
- import { IMidwayFramework } from './interface';
3
- export declare const createMidwayLogger: (framework: IMidwayFramework<any, any>, name: string, options?: LoggerOptions) => import("@midwayjs/logger").ILogger;
4
- //# sourceMappingURL=logger.d.ts.map
package/dist/logger.js DELETED
@@ -1,20 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.createMidwayLogger = void 0;
4
- const logger_1 = require("@midwayjs/logger");
5
- const interface_1 = require("./interface");
6
- const util_1 = require("./util");
7
- const path_1 = require("path");
8
- const createMidwayLogger = (framework, name, options = {}) => {
9
- const isDevelopmentEnv = util_1.isDevelopmentEnvironment(framework.getCurrentEnvironment());
10
- const loggerOptions = {
11
- dir: path_1.join(framework.getApplicationContext().getInformationService().getRoot(), 'logs', framework.getProjectName()),
12
- level: isDevelopmentEnv ? 'info' : 'warn',
13
- };
14
- if (process.env[interface_1.MIDWAY_LOGGER_WRITEABLE_DIR]) {
15
- loggerOptions.dir = path_1.join(process.env[interface_1.MIDWAY_LOGGER_WRITEABLE_DIR], 'logs', framework.getProjectName());
16
- }
17
- return logger_1.createLogger(name, Object.assign({}, loggerOptions, options));
18
- };
19
- exports.createMidwayLogger = createMidwayLogger;
20
- //# sourceMappingURL=logger.js.map
@@ -1,11 +0,0 @@
1
- import { MidwayContainer } from '../context/container';
2
- import { IMidwayContainer } from '../interface';
3
- export declare const createModuleContainer: (options: {
4
- container?: IMidwayContainer;
5
- modules: any[];
6
- entry: {
7
- Configuration: any;
8
- };
9
- }) => IMidwayContainer | MidwayContainer;
10
- export declare const createDirectoryGlobContainer: (options: any) => MidwayContainer;
11
- //# sourceMappingURL=containerUtil.d.ts.map
@@ -1,26 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.createDirectoryGlobContainer = exports.createModuleContainer = void 0;
4
- const container_1 = require("../context/container");
5
- const fileDetector_1 = require("./fileDetector");
6
- const path_1 = require("path");
7
- const index_1 = require("./index");
8
- const createModuleContainer = (options) => {
9
- const applicationContext = options.container || new container_1.MidwayContainer();
10
- applicationContext.setFileDetector(new fileDetector_1.CustomModuleDetector({
11
- modules: options.modules,
12
- }));
13
- applicationContext.load(options.entry);
14
- return applicationContext;
15
- };
16
- exports.createModuleContainer = createModuleContainer;
17
- const createDirectoryGlobContainer = options => {
18
- const applicationContext = new container_1.MidwayContainer(options.baseDir, undefined);
19
- applicationContext.setFileDetector(new fileDetector_1.DirectoryFileDetector({
20
- loadDir: options.baseDir,
21
- }));
22
- applicationContext.load(index_1.safeRequire(path_1.join(options.baseDir, 'configuration')));
23
- return applicationContext;
24
- };
25
- exports.createDirectoryGlobContainer = createDirectoryGlobContainer;
26
- //# sourceMappingURL=containerUtil.js.map
@@ -1,62 +0,0 @@
1
- import { BaseFramework } from '../baseFramework';
2
- import { IMidwayBootstrapOptions } from '../interface';
3
- import { MidwayFrameworkType } from '@midwayjs/decorator';
4
- /**
5
- * 一个不 ready 的空框架
6
- */
7
- export declare class EmptyFramework extends BaseFramework<any, any, any> {
8
- logger: {
9
- info(): void;
10
- warn(): void;
11
- error(): void;
12
- debug(): void;
13
- write(): void;
14
- };
15
- appLogger: {
16
- info(): void;
17
- warn(): void;
18
- error(): void;
19
- debug(): void;
20
- write(): void;
21
- };
22
- getFrameworkType(): MidwayFrameworkType;
23
- run(): Promise<void>;
24
- applicationInitialize(options: IMidwayBootstrapOptions): Promise<void>;
25
- containerReady(): Promise<void>;
26
- afterContainerReady(): Promise<void>;
27
- loadExtension(): Promise<void>;
28
- }
29
- /**
30
- * 一个只加载配置的框架
31
- */
32
- export declare class ConfigFramework extends BaseFramework<any, any, any> {
33
- logger: {
34
- info(): void;
35
- warn(): void;
36
- error(): void;
37
- debug(): void;
38
- write(): void;
39
- };
40
- appLogger: {
41
- info(): void;
42
- warn(): void;
43
- error(): void;
44
- debug(): void;
45
- write(): void;
46
- };
47
- getFrameworkType(): MidwayFrameworkType;
48
- run(): Promise<void>;
49
- applicationInitialize(options: IMidwayBootstrapOptions): Promise<void>;
50
- containerReady(): Promise<void>;
51
- afterContainerReady(): Promise<void>;
52
- loadExtension(): Promise<void>;
53
- }
54
- /**
55
- * 一个全量的空框架
56
- */
57
- export declare class LightFramework extends BaseFramework<any, any, any> {
58
- getFrameworkType(): MidwayFrameworkType;
59
- run(): Promise<void>;
60
- applicationInitialize(options: IMidwayBootstrapOptions): Promise<void>;
61
- }
62
- //# sourceMappingURL=emptyFramework.d.ts.map
@@ -1,72 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.LightFramework = exports.ConfigFramework = exports.EmptyFramework = void 0;
4
- const baseFramework_1 = require("../baseFramework");
5
- const decorator_1 = require("@midwayjs/decorator");
6
- const noop = {
7
- info() { },
8
- warn() { },
9
- error() { },
10
- debug() { },
11
- write() { },
12
- };
13
- /**
14
- * 一个不 ready 的空框架
15
- */
16
- class EmptyFramework extends baseFramework_1.BaseFramework {
17
- constructor() {
18
- super(...arguments);
19
- this.logger = noop;
20
- this.appLogger = noop;
21
- }
22
- getFrameworkType() {
23
- return decorator_1.MidwayFrameworkType.EMPTY;
24
- }
25
- async run() { }
26
- async applicationInitialize(options) {
27
- this.app = {};
28
- }
29
- async containerReady() { }
30
- async afterContainerReady() { }
31
- async loadExtension() { }
32
- }
33
- exports.EmptyFramework = EmptyFramework;
34
- /**
35
- * 一个只加载配置的框架
36
- */
37
- class ConfigFramework extends baseFramework_1.BaseFramework {
38
- constructor() {
39
- super(...arguments);
40
- this.logger = noop;
41
- this.appLogger = noop;
42
- }
43
- getFrameworkType() {
44
- return decorator_1.MidwayFrameworkType.EMPTY;
45
- }
46
- async run() { }
47
- async applicationInitialize(options) {
48
- this.app = {};
49
- this.defineApplicationProperties();
50
- }
51
- async containerReady() {
52
- await this.applicationContext.ready();
53
- }
54
- async afterContainerReady() { }
55
- async loadExtension() { }
56
- }
57
- exports.ConfigFramework = ConfigFramework;
58
- /**
59
- * 一个全量的空框架
60
- */
61
- class LightFramework extends baseFramework_1.BaseFramework {
62
- getFrameworkType() {
63
- return decorator_1.MidwayFrameworkType.LIGHT;
64
- }
65
- async run() { }
66
- async applicationInitialize(options) {
67
- this.app = {};
68
- this.defineApplicationProperties();
69
- }
70
- }
71
- exports.LightFramework = LightFramework;
72
- //# sourceMappingURL=emptyFramework.js.map
@@ -1,13 +0,0 @@
1
- /**
2
- * 多客户端工厂实现
3
- */
4
- export declare abstract class ServiceFactory<T> {
5
- private clients;
6
- private options;
7
- initClients(options: any): Promise<void>;
8
- get<U = T>(id?: string): U;
9
- createInstance(config: any, clientName: any): Promise<any>;
10
- abstract getName(): any;
11
- protected abstract createClient(config: any): any;
12
- }
13
- //# sourceMappingURL=serviceFactory.d.ts.map
@@ -1,10 +0,0 @@
1
- import { IConfigService } from '..';
2
- export declare class StaticConfigLoader {
3
- baseDir: string;
4
- configService: IConfigService;
5
- constructor(baseDir: string, currentEnvironment: string);
6
- getSerializeConfig(): Promise<string>;
7
- analyzeConfiguration(configurationModule: any): void;
8
- private getConfigurationExport;
9
- }
10
- //# sourceMappingURL=staticConfig.d.ts.map
@@ -1,67 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.StaticConfigLoader = void 0;
4
- const path_1 = require("path");
5
- const decorator_1 = require("@midwayjs/decorator");
6
- const __1 = require("..");
7
- const configService_1 = require("../service/configService");
8
- class StaticConfigLoader {
9
- constructor(baseDir, currentEnvironment) {
10
- this.baseDir = baseDir;
11
- this.configService = new configService_1.MidwayConfigService({
12
- getCurrentEnv() {
13
- return currentEnvironment;
14
- },
15
- });
16
- }
17
- async getSerializeConfig() {
18
- const mainModule = __1.safeRequire(this.baseDir);
19
- let mainConfiguration;
20
- if (mainModule && mainModule['Configuration']) {
21
- mainConfiguration = mainModule['Configuration'];
22
- }
23
- else {
24
- mainConfiguration = __1.safeRequire(path_1.join(this.baseDir, 'src', 'configuration.ts'));
25
- }
26
- const modules = this.getConfigurationExport(mainConfiguration);
27
- for (const module of modules) {
28
- this.analyzeConfiguration(module);
29
- }
30
- this.configService.load();
31
- return this.configService.getConfiguration();
32
- }
33
- analyzeConfiguration(configurationModule) {
34
- if (!configurationModule)
35
- return;
36
- const configurationOptions = decorator_1.getClassMetadata(decorator_1.CONFIGURATION_KEY, configurationModule);
37
- if (!configurationOptions)
38
- return;
39
- if (configurationOptions.imports) {
40
- for (const importModule of configurationOptions.imports) {
41
- if (typeof importModule !== 'string') {
42
- this.analyzeConfiguration(importModule['Configuration']);
43
- }
44
- }
45
- }
46
- if (configurationOptions === null || configurationOptions === void 0 ? void 0 : configurationOptions.importConfigs) {
47
- this.configService.add(configurationOptions.importConfigs);
48
- }
49
- }
50
- getConfigurationExport(exports) {
51
- const mods = [];
52
- if (decorator_1.isClass(exports) || decorator_1.isFunction(exports)) {
53
- mods.push(exports);
54
- }
55
- else {
56
- for (const m in exports) {
57
- const module = exports[m];
58
- if (decorator_1.isClass(module) || decorator_1.isFunction(module)) {
59
- mods.push(module);
60
- }
61
- }
62
- }
63
- return mods;
64
- }
65
- }
66
- exports.StaticConfigLoader = StaticConfigLoader;
67
- //# sourceMappingURL=staticConfig.js.map