ee-core 2.9.2-beta.1 → 2.10.0

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 (103) hide show
  1. package/LICENSE +21 -21
  2. package/README.md +65 -65
  3. package/addon/index.js +34 -34
  4. package/addon/window/index.js +98 -98
  5. package/bin/tools.js +8 -8
  6. package/config/cache.js +41 -38
  7. package/config/config.default.js +331 -330
  8. package/config/index.js +75 -73
  9. package/const/channel.js +17 -17
  10. package/const/index.js +8 -8
  11. package/controller/baseContextClass.js +34 -34
  12. package/controller/index.js +34 -34
  13. package/core/index.js +10 -10
  14. package/core/lib/ee.js +216 -216
  15. package/core/lib/loader/context_loader.js +106 -106
  16. package/core/lib/loader/ee_loader.js +435 -435
  17. package/core/lib/loader/file_loader.js +326 -326
  18. package/core/lib/loader/mixin/addon.js +32 -32
  19. package/core/lib/loader/mixin/config.js +130 -130
  20. package/core/lib/loader/mixin/controller.js +125 -125
  21. package/core/lib/loader/mixin/service.js +28 -28
  22. package/core/lib/utils/base_context_class.js +34 -34
  23. package/core/lib/utils/function.js +30 -30
  24. package/core/lib/utils/index.js +133 -133
  25. package/core/lib/utils/sequencify.js +59 -59
  26. package/core/lib/utils/timing.js +77 -77
  27. package/cross/index.js +183 -183
  28. package/cross/spawnProcess.js +183 -183
  29. package/ee/appLoader.js +48 -48
  30. package/ee/application.js +99 -99
  31. package/ee/baseApp.js +103 -102
  32. package/ee/eeApp.js +408 -408
  33. package/ee/index.js +57 -57
  34. package/electron/app/index.js +64 -58
  35. package/electron/index.js +19 -19
  36. package/electron/window/index.js +73 -73
  37. package/electron/window/winState.js +186 -186
  38. package/exception/index.js +112 -112
  39. package/html/boot.html +98 -98
  40. package/html/cross-failure.html +28 -28
  41. package/html/failure.html +28 -28
  42. package/html/index.js +13 -13
  43. package/httpclient/index.js +161 -161
  44. package/index.js +54 -54
  45. package/jobs/baseJobClass.js +16 -16
  46. package/jobs/child/app.js +65 -65
  47. package/jobs/child/forkProcess.js +145 -145
  48. package/jobs/child/index.js +82 -82
  49. package/jobs/child-pool/index.js +213 -213
  50. package/jobs/index.js +8 -8
  51. package/jobs/load-balancer/algorithm/index.js +11 -11
  52. package/jobs/load-balancer/algorithm/minimumConnection.js +18 -18
  53. package/jobs/load-balancer/algorithm/polling.js +11 -11
  54. package/jobs/load-balancer/algorithm/random.js +9 -9
  55. package/jobs/load-balancer/algorithm/specify.js +14 -14
  56. package/jobs/load-balancer/algorithm/weights.js +21 -21
  57. package/jobs/load-balancer/algorithm/weightsMinimumConnection.js +29 -29
  58. package/jobs/load-balancer/algorithm/weightsPolling.js +22 -22
  59. package/jobs/load-balancer/algorithm/weightsRandom.js +16 -16
  60. package/jobs/load-balancer/consts.js +9 -9
  61. package/jobs/load-balancer/index.js +201 -201
  62. package/jobs/load-balancer/scheduler.js +31 -31
  63. package/jobs/renderer/index.js +141 -141
  64. package/jobs/renderer/loadView.js +40 -40
  65. package/jobs/unification.js +63 -63
  66. package/loader/index.js +172 -172
  67. package/log/index.js +68 -68
  68. package/log/logger.js +86 -80
  69. package/main/index.js +56 -56
  70. package/message/childMessage.js +54 -54
  71. package/message/index.js +18 -18
  72. package/old-utils/index.js +91 -91
  73. package/package.json +38 -38
  74. package/ps/index.js +371 -371
  75. package/services/baseContextClass.js +34 -34
  76. package/services/index.js +40 -40
  77. package/socket/httpServer.js +147 -147
  78. package/socket/index.js +81 -81
  79. package/socket/io.js +27 -27
  80. package/socket/ipcServer.js +112 -112
  81. package/socket/socketServer.js +69 -65
  82. package/storage/index.js +38 -38
  83. package/storage/jsondb/adapters/Base.js +23 -23
  84. package/storage/jsondb/adapters/FileSync.js +64 -52
  85. package/storage/jsondb/main.js +55 -42
  86. package/storage/jsondbStorage.js +195 -195
  87. package/storage/sqliteStorage.js +123 -123
  88. package/utils/co.js +237 -237
  89. package/utils/copyto.js +160 -160
  90. package/utils/depd/index.js +538 -538
  91. package/utils/depd/lib/browser/index.js +77 -77
  92. package/utils/extend.js +73 -73
  93. package/utils/get-port/index.d.ts +64 -64
  94. package/utils/get-port/index.js +148 -148
  95. package/utils/helper.js +220 -220
  96. package/utils/index.js +160 -160
  97. package/utils/ip.js +261 -261
  98. package/utils/is.js +145 -145
  99. package/utils/json.js +72 -72
  100. package/utils/pargv.js +263 -263
  101. package/utils/time/index.js +19 -19
  102. package/utils/time/ms.js +162 -162
  103. package/utils/wrap.js +35 -35
@@ -1,32 +1,32 @@
1
- const path = require('path');
2
-
3
- module.exports = {
4
-
5
- /**
6
- * Load app/addon
7
- * @param {Object} opt - LoaderOptions
8
- * @function
9
- * @since 1.0.0
10
- */
11
- loadAddon(opt) {
12
- this.timing.start('Load Addon');
13
-
14
- // 加载ee-core的插件 和 用户插件
15
- const directorys = [
16
- path.join(this.options.framework, 'addon'),
17
- path.join(this.options.baseDir, 'addon'),
18
- ]
19
- opt = Object.assign({
20
- call: true,
21
- caseStyle: 'lower',
22
- directory: directorys
23
- }, opt);
24
-
25
- const addonPaths = opt.directory;
26
- this.loadToContext(addonPaths, 'addon', opt);
27
-
28
- this.timing.end('Load Addon');
29
- },
30
- };
31
-
32
-
1
+ const path = require('path');
2
+
3
+ module.exports = {
4
+
5
+ /**
6
+ * Load app/addon
7
+ * @param {Object} opt - LoaderOptions
8
+ * @function
9
+ * @since 1.0.0
10
+ */
11
+ loadAddon(opt) {
12
+ this.timing.start('Load Addon');
13
+
14
+ // 加载ee-core的插件 和 用户插件
15
+ const directorys = [
16
+ path.join(this.options.framework, 'addon'),
17
+ path.join(this.options.baseDir, 'addon'),
18
+ ]
19
+ opt = Object.assign({
20
+ call: true,
21
+ caseStyle: 'lower',
22
+ directory: directorys
23
+ }, opt);
24
+
25
+ const addonPaths = opt.directory;
26
+ this.loadToContext(addonPaths, 'addon', opt);
27
+
28
+ this.timing.end('Load Addon');
29
+ },
30
+ };
31
+
32
+
@@ -1,130 +1,130 @@
1
- 'use strict';
2
-
3
- const debug = require('debug')('ee-core:config');
4
- const path = require('path');
5
- const extend = require('../../../../utils/extend');
6
- const assert = require('assert');
7
- const { Console } = require('console');
8
-
9
- module.exports = {
10
-
11
- /**
12
- * Load config/config.js
13
- *
14
- * Will merge config.default.js 和 config.${env}.js
15
- *
16
- * @function EggLoader#loadConfig
17
- * @since 1.0.0
18
- */
19
- loadConfig() {
20
- this.timing.start('Load Config');
21
- this.configMeta = {};
22
-
23
- const target = {};
24
-
25
- // Load Application config first
26
- const appConfig = this._preloadAppConfig();
27
-
28
- for (const filename of this.getTypeFiles('config')) {
29
- for (const unit of this.getLoadUnits()) {
30
- const isApp = unit.type === 'app';
31
- const config = this._loadConfig(unit.path, filename, isApp ? undefined : appConfig, unit.type);
32
-
33
- if (!config) {
34
- continue;
35
- }
36
-
37
- debug('Loaded config %s, %s, %j', unit.path, filename, config);
38
- extend(true, target, config);
39
- }
40
- }
41
-
42
- // load env from process.env.EE_APP_CONFIG
43
- const envConfig = this._loadConfigFromEnv();
44
- debug('Loaded config from private env, %j', envConfig);
45
- extend(true, target, envConfig);
46
-
47
- // You can manipulate the order of app.config.coreMiddleware and app.config.appMiddleware in app.js
48
- target.coreMiddleware = target.coreMiddlewares = target.coreMiddleware || [];
49
- target.appMiddleware = target.appMiddlewares = target.middleware || [];
50
-
51
- this.config = target;
52
- this.timing.end('Load Config');
53
- },
54
-
55
- _preloadAppConfig() {
56
- const names = [
57
- 'config.default',
58
- `config.${this.serverEnv}`,
59
- ];
60
-
61
-
62
- const target = {};
63
- for (const filename of names) {
64
- const config = this._loadConfig(this.options.baseDir, filename, undefined, 'app');
65
- extend(true, target, config);
66
- }
67
- return target;
68
- },
69
-
70
- _loadConfig(dirpath, filename, extraInject, type) {
71
- const isPlugin = type === 'plugin';
72
- const isApp = type === 'app';
73
- let filepath = this.resolveModule(path.join(dirpath, 'config', filename));
74
-
75
- // let config.js compatible
76
- // if (filename === 'config.default' && !filepath) {
77
- // filepath = this.resolveModule(path.join(dirpath, 'config/config'));
78
- // }
79
-
80
- const config = this.loadFile(filepath, this.appInfo, extraInject);
81
-
82
- if (!config) return null;
83
-
84
- if (isPlugin || isApp) {
85
- assert(!config.coreMiddleware, 'Can not define coreMiddleware in app or plugin');
86
- }
87
- if (!isApp) {
88
- assert(!config.middleware, 'Can not define middleware in ' + filepath);
89
- }
90
-
91
- // store config meta, check where is the property of config come from.
92
- this._setConfigMeta(config, filepath);
93
-
94
- return config;
95
- },
96
-
97
- _loadConfigFromEnv() {
98
- const envConfigStr = process.env.EE_APP_CONFIG;
99
- if (!envConfigStr) return;
100
- try {
101
- const envConfig = JSON.parse(envConfigStr);
102
- this._setConfigMeta(envConfig, '<process.env.EE_APP_CONFIG>');
103
- return envConfig;
104
- } catch (err) {
105
- this.options.logger.warn('[ee-core] [core/.../config] process.env.EE_APP_CONFIG is not invalid JSON: %s', envConfigStr);
106
- }
107
- },
108
-
109
- _setConfigMeta(config, filepath) {
110
- config = extend(true, {}, config);
111
- setConfig(config, filepath);
112
- extend(true, this.configMeta, config);
113
- },
114
- };
115
-
116
- function setConfig(obj, filepath) {
117
- for (const key of Object.keys(obj)) {
118
- const val = obj[key];
119
- // ignore console
120
- if (key === 'console' && val && typeof val.Console === 'function' && val.Console === Console) {
121
- obj[key] = filepath;
122
- continue;
123
- }
124
- if (val && Object.getPrototypeOf(val) === Object.prototype && Object.keys(val).length > 0) {
125
- setConfig(val, filepath);
126
- continue;
127
- }
128
- obj[key] = filepath;
129
- }
130
- }
1
+ 'use strict';
2
+
3
+ const debug = require('debug')('ee-core:config');
4
+ const path = require('path');
5
+ const extend = require('../../../../utils/extend');
6
+ const assert = require('assert');
7
+ const { Console } = require('console');
8
+
9
+ module.exports = {
10
+
11
+ /**
12
+ * Load config/config.js
13
+ *
14
+ * Will merge config.default.js 和 config.${env}.js
15
+ *
16
+ * @function EggLoader#loadConfig
17
+ * @since 1.0.0
18
+ */
19
+ loadConfig() {
20
+ this.timing.start('Load Config');
21
+ this.configMeta = {};
22
+
23
+ const target = {};
24
+
25
+ // Load Application config first
26
+ const appConfig = this._preloadAppConfig();
27
+
28
+ for (const filename of this.getTypeFiles('config')) {
29
+ for (const unit of this.getLoadUnits()) {
30
+ const isApp = unit.type === 'app';
31
+ const config = this._loadConfig(unit.path, filename, isApp ? undefined : appConfig, unit.type);
32
+
33
+ if (!config) {
34
+ continue;
35
+ }
36
+
37
+ debug('Loaded config %s, %s, %j', unit.path, filename, config);
38
+ extend(true, target, config);
39
+ }
40
+ }
41
+
42
+ // load env from process.env.EE_APP_CONFIG
43
+ const envConfig = this._loadConfigFromEnv();
44
+ debug('Loaded config from private env, %j', envConfig);
45
+ extend(true, target, envConfig);
46
+
47
+ // You can manipulate the order of app.config.coreMiddleware and app.config.appMiddleware in app.js
48
+ target.coreMiddleware = target.coreMiddlewares = target.coreMiddleware || [];
49
+ target.appMiddleware = target.appMiddlewares = target.middleware || [];
50
+
51
+ this.config = target;
52
+ this.timing.end('Load Config');
53
+ },
54
+
55
+ _preloadAppConfig() {
56
+ const names = [
57
+ 'config.default',
58
+ `config.${this.serverEnv}`,
59
+ ];
60
+
61
+
62
+ const target = {};
63
+ for (const filename of names) {
64
+ const config = this._loadConfig(this.options.baseDir, filename, undefined, 'app');
65
+ extend(true, target, config);
66
+ }
67
+ return target;
68
+ },
69
+
70
+ _loadConfig(dirpath, filename, extraInject, type) {
71
+ const isPlugin = type === 'plugin';
72
+ const isApp = type === 'app';
73
+ let filepath = this.resolveModule(path.join(dirpath, 'config', filename));
74
+
75
+ // let config.js compatible
76
+ // if (filename === 'config.default' && !filepath) {
77
+ // filepath = this.resolveModule(path.join(dirpath, 'config/config'));
78
+ // }
79
+
80
+ const config = this.loadFile(filepath, this.appInfo, extraInject);
81
+
82
+ if (!config) return null;
83
+
84
+ if (isPlugin || isApp) {
85
+ assert(!config.coreMiddleware, 'Can not define coreMiddleware in app or plugin');
86
+ }
87
+ if (!isApp) {
88
+ assert(!config.middleware, 'Can not define middleware in ' + filepath);
89
+ }
90
+
91
+ // store config meta, check where is the property of config come from.
92
+ this._setConfigMeta(config, filepath);
93
+
94
+ return config;
95
+ },
96
+
97
+ _loadConfigFromEnv() {
98
+ const envConfigStr = process.env.EE_APP_CONFIG;
99
+ if (!envConfigStr) return;
100
+ try {
101
+ const envConfig = JSON.parse(envConfigStr);
102
+ this._setConfigMeta(envConfig, '<process.env.EE_APP_CONFIG>');
103
+ return envConfig;
104
+ } catch (err) {
105
+ this.options.logger.warn('[ee-core] [core/.../config] process.env.EE_APP_CONFIG is not invalid JSON: %s', envConfigStr);
106
+ }
107
+ },
108
+
109
+ _setConfigMeta(config, filepath) {
110
+ config = extend(true, {}, config);
111
+ setConfig(config, filepath);
112
+ extend(true, this.configMeta, config);
113
+ },
114
+ };
115
+
116
+ function setConfig(obj, filepath) {
117
+ for (const key of Object.keys(obj)) {
118
+ const val = obj[key];
119
+ // ignore console
120
+ if (key === 'console' && val && typeof val.Console === 'function' && val.Console === Console) {
121
+ obj[key] = filepath;
122
+ continue;
123
+ }
124
+ if (val && Object.getPrototypeOf(val) === Object.prototype && Object.keys(val).length > 0) {
125
+ setConfig(val, filepath);
126
+ continue;
127
+ }
128
+ obj[key] = filepath;
129
+ }
130
+ }
@@ -1,125 +1,125 @@
1
- 'use strict';
2
-
3
- const path = require('path');
4
- const is = require('is-type-of');
5
- const UtilsFn = require('../../utils/function');
6
- const Utils = require('../../utils');
7
- const FULLPATH = require('../file_loader').FULLPATH;
8
-
9
- module.exports = {
10
-
11
- /**
12
- * Load app/controller
13
- * @param {Object} opt - LoaderOptions
14
- * @since 1.0.0
15
- */
16
- loadController(opt) {
17
- this.timing.start('Load Controller');
18
- opt = Object.assign({
19
- caseStyle: 'lower',
20
- directory: path.join(this.options.baseDir, 'controller'),
21
- initializer: (obj, opt) => {
22
- // return class if it exports a function
23
- // ```js
24
- // module.exports = app => {
25
- // return class HomeController extends app.Controller {};
26
- // }
27
- // ```
28
-
29
- if (is.function(obj) && !is.generatorFunction(obj) && !is.class(obj) && !is.asyncFunction(obj) && !Utils.isBytecodeClass(obj)) {
30
- obj = obj(this.app);
31
- }
32
- if (is.class(obj) || Utils.isBytecodeClass(obj)) {
33
- obj.prototype.pathName = opt.pathName;
34
- obj.prototype.fullPath = opt.path;
35
- return wrapClass(obj);
36
- }
37
- if (is.object(obj)) {
38
- return wrapObject(obj, opt.path);
39
- }
40
- // support generatorFunction for forward compatbility
41
- if (is.generatorFunction(obj) || is.asyncFunction(obj)) {
42
- return wrapObject({ 'module.exports': obj }, opt.path)['module.exports'];
43
- }
44
- return obj;
45
- },
46
- }, opt);
47
- const controllerBase = opt.directory;
48
-
49
- this.loadToApp(controllerBase, 'controller', opt);
50
- //this.options.logger.info('[ee-core] [core/.../controller] loaded: %s', controllerBase);
51
- this.timing.end('Load Controller');
52
- },
53
-
54
- };
55
-
56
- // wrap the class, yield a object with middlewares
57
- function wrapClass(Controller) {
58
- let proto = Controller.prototype;
59
- const ret = {};
60
- // tracing the prototype chain
61
- while (proto !== Object.prototype) {
62
- const keys = Object.getOwnPropertyNames(proto);
63
- for (const key of keys) {
64
- // getOwnPropertyNames will return constructor
65
- // that should be ignored
66
- if (key === 'constructor') {
67
- continue;
68
- }
69
- // skip getter, setter & non-function properties
70
- const d = Object.getOwnPropertyDescriptor(proto, key);
71
- // prevent to override sub method
72
- if (is.function(d.value) && !ret.hasOwnProperty(key)) {
73
- ret[key] = methodToMiddleware(Controller, key);
74
- ret[key][FULLPATH] = Controller.prototype.fullPath + '#' + Controller.name + '.' + key + '()';
75
- }
76
- }
77
- proto = Object.getPrototypeOf(proto);
78
- }
79
-
80
- return ret;
81
-
82
- function methodToMiddleware(Controller, key) {
83
- return function classControllerMiddleware(...args) {
84
- const controller = new Controller(this);
85
- // if (!this.app.config.controller || !this.app.config.controller.supportParams) {
86
- // args = [ this ];
87
- // }
88
- //args = [ this ];
89
- return Utils.callFn(controller[key], args, controller);
90
- };
91
- }
92
- }
93
-
94
- // wrap the method of the object, method can receive ctx as it's first argument
95
- function wrapObject(obj, path, prefix) {
96
- const keys = Object.keys(obj);
97
- const ret = {};
98
- for (const key of keys) {
99
- if (is.function(obj[key])) {
100
- const names = UtilsFn.getParamNames(obj[key]);
101
- if (names[0] === 'next') {
102
- throw new Error(`controller \`${prefix || ''}${key}\` should not use next as argument from file ${path}`);
103
- }
104
- ret[key] = functionToMiddleware(obj[key]);
105
- ret[key][FULLPATH] = `${path}#${prefix || ''}${key}()`;
106
- } else if (is.object(obj[key])) {
107
- ret[key] = wrapObject(obj[key], path, `${prefix || ''}${key}.`);
108
- }
109
- }
110
- return ret;
111
-
112
- function functionToMiddleware(func) {
113
- const objectControllerMiddleware = async function(...args) {
114
- // if (!this.app.config.controller || !this.app.config.controller.supportParams) {
115
- // args = [ this ];
116
- // }
117
- return await Utils.callFn(func, args, this);
118
- };
119
- for (const key in func) {
120
- objectControllerMiddleware[key] = func[key];
121
- }
122
- return objectControllerMiddleware;
123
- }
124
- }
125
-
1
+ 'use strict';
2
+
3
+ const path = require('path');
4
+ const is = require('is-type-of');
5
+ const UtilsFn = require('../../utils/function');
6
+ const Utils = require('../../utils');
7
+ const FULLPATH = require('../file_loader').FULLPATH;
8
+
9
+ module.exports = {
10
+
11
+ /**
12
+ * Load app/controller
13
+ * @param {Object} opt - LoaderOptions
14
+ * @since 1.0.0
15
+ */
16
+ loadController(opt) {
17
+ this.timing.start('Load Controller');
18
+ opt = Object.assign({
19
+ caseStyle: 'lower',
20
+ directory: path.join(this.options.baseDir, 'controller'),
21
+ initializer: (obj, opt) => {
22
+ // return class if it exports a function
23
+ // ```js
24
+ // module.exports = app => {
25
+ // return class HomeController extends app.Controller {};
26
+ // }
27
+ // ```
28
+
29
+ if (is.function(obj) && !is.generatorFunction(obj) && !is.class(obj) && !is.asyncFunction(obj) && !Utils.isBytecodeClass(obj)) {
30
+ obj = obj(this.app);
31
+ }
32
+ if (is.class(obj) || Utils.isBytecodeClass(obj)) {
33
+ obj.prototype.pathName = opt.pathName;
34
+ obj.prototype.fullPath = opt.path;
35
+ return wrapClass(obj);
36
+ }
37
+ if (is.object(obj)) {
38
+ return wrapObject(obj, opt.path);
39
+ }
40
+ // support generatorFunction for forward compatbility
41
+ if (is.generatorFunction(obj) || is.asyncFunction(obj)) {
42
+ return wrapObject({ 'module.exports': obj }, opt.path)['module.exports'];
43
+ }
44
+ return obj;
45
+ },
46
+ }, opt);
47
+ const controllerBase = opt.directory;
48
+
49
+ this.loadToApp(controllerBase, 'controller', opt);
50
+ //this.options.logger.info('[ee-core] [core/.../controller] loaded: %s', controllerBase);
51
+ this.timing.end('Load Controller');
52
+ },
53
+
54
+ };
55
+
56
+ // wrap the class, yield a object with middlewares
57
+ function wrapClass(Controller) {
58
+ let proto = Controller.prototype;
59
+ const ret = {};
60
+ // tracing the prototype chain
61
+ while (proto !== Object.prototype) {
62
+ const keys = Object.getOwnPropertyNames(proto);
63
+ for (const key of keys) {
64
+ // getOwnPropertyNames will return constructor
65
+ // that should be ignored
66
+ if (key === 'constructor') {
67
+ continue;
68
+ }
69
+ // skip getter, setter & non-function properties
70
+ const d = Object.getOwnPropertyDescriptor(proto, key);
71
+ // prevent to override sub method
72
+ if (is.function(d.value) && !ret.hasOwnProperty(key)) {
73
+ ret[key] = methodToMiddleware(Controller, key);
74
+ ret[key][FULLPATH] = Controller.prototype.fullPath + '#' + Controller.name + '.' + key + '()';
75
+ }
76
+ }
77
+ proto = Object.getPrototypeOf(proto);
78
+ }
79
+
80
+ return ret;
81
+
82
+ function methodToMiddleware(Controller, key) {
83
+ return function classControllerMiddleware(...args) {
84
+ const controller = new Controller(this);
85
+ // if (!this.app.config.controller || !this.app.config.controller.supportParams) {
86
+ // args = [ this ];
87
+ // }
88
+ //args = [ this ];
89
+ return Utils.callFn(controller[key], args, controller);
90
+ };
91
+ }
92
+ }
93
+
94
+ // wrap the method of the object, method can receive ctx as it's first argument
95
+ function wrapObject(obj, path, prefix) {
96
+ const keys = Object.keys(obj);
97
+ const ret = {};
98
+ for (const key of keys) {
99
+ if (is.function(obj[key])) {
100
+ const names = UtilsFn.getParamNames(obj[key]);
101
+ if (names[0] === 'next') {
102
+ throw new Error(`controller \`${prefix || ''}${key}\` should not use next as argument from file ${path}`);
103
+ }
104
+ ret[key] = functionToMiddleware(obj[key]);
105
+ ret[key][FULLPATH] = `${path}#${prefix || ''}${key}()`;
106
+ } else if (is.object(obj[key])) {
107
+ ret[key] = wrapObject(obj[key], path, `${prefix || ''}${key}.`);
108
+ }
109
+ }
110
+ return ret;
111
+
112
+ function functionToMiddleware(func) {
113
+ const objectControllerMiddleware = async function(...args) {
114
+ // if (!this.app.config.controller || !this.app.config.controller.supportParams) {
115
+ // args = [ this ];
116
+ // }
117
+ return await Utils.callFn(func, args, this);
118
+ };
119
+ for (const key in func) {
120
+ objectControllerMiddleware[key] = func[key];
121
+ }
122
+ return objectControllerMiddleware;
123
+ }
124
+ }
125
+
@@ -1,28 +1,28 @@
1
- 'use strict';
2
-
3
- const path = require('path');
4
-
5
- module.exports = {
6
-
7
- /**
8
- * Load app/service
9
- * @function EeLoader#loadService
10
- * @param {Object} opt - LoaderOptions
11
- * @since 1.0.0
12
- */
13
- loadService(opt) {
14
- this.timing.start('Load Service');
15
- // 载入到 app.serviceClasses
16
- opt = Object.assign({
17
- call: true,
18
- caseStyle: 'lower',
19
- fieldClass: 'serviceClasses',
20
- directory: this.getLoadUnits().map(unit => path.join(unit.path, 'service')), // this.getLoadUnits().map(unit => path.join(unit.path, 'app/service'))
21
- }, opt);
22
-
23
- const servicePaths = opt.directory;
24
- this.loadToContext(servicePaths, 'service', opt);
25
- this.timing.end('Load Service');
26
- },
27
-
28
- };
1
+ 'use strict';
2
+
3
+ const path = require('path');
4
+
5
+ module.exports = {
6
+
7
+ /**
8
+ * Load app/service
9
+ * @function EeLoader#loadService
10
+ * @param {Object} opt - LoaderOptions
11
+ * @since 1.0.0
12
+ */
13
+ loadService(opt) {
14
+ this.timing.start('Load Service');
15
+ // 载入到 app.serviceClasses
16
+ opt = Object.assign({
17
+ call: true,
18
+ caseStyle: 'lower',
19
+ fieldClass: 'serviceClasses',
20
+ directory: this.getLoadUnits().map(unit => path.join(unit.path, 'service')), // this.getLoadUnits().map(unit => path.join(unit.path, 'app/service'))
21
+ }, opt);
22
+
23
+ const servicePaths = opt.directory;
24
+ this.loadToContext(servicePaths, 'service', opt);
25
+ this.timing.end('Load Service');
26
+ },
27
+
28
+ };