ee-core 1.2.7 → 1.2.8-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 (43) hide show
  1. package/LICENSE +21 -21
  2. package/README.md +2 -2
  3. package/bin/tools.js +22 -22
  4. package/config/config.default.js +250 -247
  5. package/core/index.js +12 -12
  6. package/core/lib/ee.js +209 -209
  7. package/core/lib/loader/context_loader.js +105 -105
  8. package/core/lib/loader/ee_loader.js +451 -451
  9. package/core/lib/loader/file_loader.js +262 -262
  10. package/core/lib/loader/mixin/config.js +138 -138
  11. package/core/lib/loader/mixin/controller.js +123 -123
  12. package/core/lib/loader/mixin/service.js +29 -29
  13. package/core/lib/utils/base_context_class.js +34 -34
  14. package/core/lib/utils/index.js +100 -100
  15. package/core/lib/utils/sequencify.js +59 -59
  16. package/core/lib/utils/timing.js +77 -77
  17. package/index.js +49 -49
  18. package/lib/appLoader.js +45 -45
  19. package/lib/application.js +80 -80
  20. package/lib/baseApp.js +118 -118
  21. package/lib/constant.js +28 -28
  22. package/lib/eeApp.js +326 -326
  23. package/lib/helper.js +51 -51
  24. package/lib/httpclient.js +136 -136
  25. package/lib/logger.js +46 -46
  26. package/lib/socket/httpServer.js +102 -104
  27. package/lib/socket/io.js +23 -23
  28. package/lib/socket/ipcServer.js +128 -128
  29. package/lib/socket/socketClient.js +50 -50
  30. package/lib/socket/socketServer.js +76 -76
  31. package/lib/socket/start.js +22 -22
  32. package/lib/storage/index.js +33 -21
  33. package/lib/storage/lowdbStorage.js +98 -143
  34. package/lib/storage/sqliteStorage.js +59 -0
  35. package/package.json +45 -45
  36. package/resource/loading.html +21 -21
  37. package/resource/view_example.html +21 -21
  38. package/tools/codeCompress.js +204 -204
  39. package/tools/replaceDist.js +76 -76
  40. package/utils/common.js +91 -30
  41. package/utils/index.js +207 -207
  42. package/utils/wrap.js +37 -37
  43. package/lib/storage/appStorage.js +0 -14
@@ -1,100 +1,100 @@
1
- 'use strict';
2
-
3
- const convert = require('koa-convert');
4
- const is = require('is-type-of');
5
- const path = require('path');
6
- const fs = require('fs');
7
- const co = require('co');
8
- const BuiltinModule = require('module');
9
-
10
- // Guard against poorly mocked module constructors.
11
- const Module = module.constructor.length > 1
12
- ? module.constructor
13
- /* istanbul ignore next */
14
- : BuiltinModule;
15
-
16
- module.exports = {
17
- extensions: Module._extensions,
18
-
19
- loadFile(filepath) {
20
- try {
21
- // if not js module, just return content buffer
22
- const extname = path.extname(filepath);
23
- if (extname && !Module._extensions[extname]) {
24
- return fs.readFileSync(filepath);
25
- }
26
- // require js module
27
- const obj = require(filepath);
28
- if (!obj) return obj;
29
- // it's es module
30
- if (obj.__esModule) return 'default' in obj ? obj.default : obj;
31
- return obj;
32
- } catch (err) {
33
- err.message = `[egg-core] load file: ${filepath}, error: ${err.message}`;
34
- throw err;
35
- }
36
- },
37
-
38
- methods: [ 'head', 'options', 'get', 'put', 'patch', 'post', 'delete' ],
39
-
40
- async callFn(fn, args, ctx) {
41
- args = args || [];
42
- if (!is.function(fn)) return;
43
- if (is.generatorFunction(fn)) fn = co.wrap(fn);
44
- return ctx ? fn.call(ctx, ...args) : fn(...args);
45
- },
46
-
47
- middleware(fn) {
48
- return is.generatorFunction(fn) ? convert(fn) : fn;
49
- },
50
-
51
- getCalleeFromStack(withLine, stackIndex) {
52
- stackIndex = stackIndex === undefined ? 2 : stackIndex;
53
- const limit = Error.stackTraceLimit;
54
- const prep = Error.prepareStackTrace;
55
-
56
- Error.prepareStackTrace = prepareObjectStackTrace;
57
- Error.stackTraceLimit = 5;
58
-
59
- // capture the stack
60
- const obj = {};
61
- Error.captureStackTrace(obj);
62
- let callSite = obj.stack[stackIndex];
63
- let fileName;
64
- /* istanbul ignore else */
65
- if (callSite) {
66
- // egg-mock will create a proxy
67
- // https://github.com/eggjs/egg-mock/blob/master/lib/app.js#L174
68
- fileName = callSite.getFileName();
69
- /* istanbul ignore if */
70
- if (fileName && fileName.endsWith('egg-mock/lib/app.js')) {
71
- // TODO: add test
72
- callSite = obj.stack[stackIndex + 1];
73
- fileName = callSite.getFileName();
74
- }
75
- }
76
-
77
- Error.prepareStackTrace = prep;
78
- Error.stackTraceLimit = limit;
79
-
80
- /* istanbul ignore if */
81
- if (!callSite || !fileName) return '<anonymous>';
82
- if (!withLine) return fileName;
83
- return `${fileName}:${callSite.getLineNumber()}:${callSite.getColumnNumber()}`;
84
- },
85
-
86
- getResolvedFilename(filepath, baseDir) {
87
- const reg = /[/\\]/g;
88
- return filepath.replace(baseDir + path.sep, '').replace(reg, '/');
89
- },
90
- };
91
-
92
-
93
- /**
94
- * Capture call site stack from v8.
95
- * https://github.com/v8/v8/wiki/Stack-Trace-API
96
- */
97
-
98
- function prepareObjectStackTrace(obj, stack) {
99
- return stack;
100
- }
1
+ 'use strict';
2
+
3
+ const convert = require('koa-convert');
4
+ const is = require('is-type-of');
5
+ const path = require('path');
6
+ const fs = require('fs');
7
+ const co = require('co');
8
+ const BuiltinModule = require('module');
9
+
10
+ // Guard against poorly mocked module constructors.
11
+ const Module = module.constructor.length > 1
12
+ ? module.constructor
13
+ /* istanbul ignore next */
14
+ : BuiltinModule;
15
+
16
+ module.exports = {
17
+ extensions: Module._extensions,
18
+
19
+ loadFile(filepath) {
20
+ try {
21
+ // if not js module, just return content buffer
22
+ const extname = path.extname(filepath);
23
+ if (extname && !Module._extensions[extname]) {
24
+ return fs.readFileSync(filepath);
25
+ }
26
+ // require js module
27
+ const obj = require(filepath);
28
+ if (!obj) return obj;
29
+ // it's es module
30
+ if (obj.__esModule) return 'default' in obj ? obj.default : obj;
31
+ return obj;
32
+ } catch (err) {
33
+ err.message = `[egg-core] load file: ${filepath}, error: ${err.message}`;
34
+ throw err;
35
+ }
36
+ },
37
+
38
+ methods: [ 'head', 'options', 'get', 'put', 'patch', 'post', 'delete' ],
39
+
40
+ async callFn(fn, args, ctx) {
41
+ args = args || [];
42
+ if (!is.function(fn)) return;
43
+ if (is.generatorFunction(fn)) fn = co.wrap(fn);
44
+ return ctx ? fn.call(ctx, ...args) : fn(...args);
45
+ },
46
+
47
+ middleware(fn) {
48
+ return is.generatorFunction(fn) ? convert(fn) : fn;
49
+ },
50
+
51
+ getCalleeFromStack(withLine, stackIndex) {
52
+ stackIndex = stackIndex === undefined ? 2 : stackIndex;
53
+ const limit = Error.stackTraceLimit;
54
+ const prep = Error.prepareStackTrace;
55
+
56
+ Error.prepareStackTrace = prepareObjectStackTrace;
57
+ Error.stackTraceLimit = 5;
58
+
59
+ // capture the stack
60
+ const obj = {};
61
+ Error.captureStackTrace(obj);
62
+ let callSite = obj.stack[stackIndex];
63
+ let fileName;
64
+ /* istanbul ignore else */
65
+ if (callSite) {
66
+ // egg-mock will create a proxy
67
+ // https://github.com/eggjs/egg-mock/blob/master/lib/app.js#L174
68
+ fileName = callSite.getFileName();
69
+ /* istanbul ignore if */
70
+ if (fileName && fileName.endsWith('egg-mock/lib/app.js')) {
71
+ // TODO: add test
72
+ callSite = obj.stack[stackIndex + 1];
73
+ fileName = callSite.getFileName();
74
+ }
75
+ }
76
+
77
+ Error.prepareStackTrace = prep;
78
+ Error.stackTraceLimit = limit;
79
+
80
+ /* istanbul ignore if */
81
+ if (!callSite || !fileName) return '<anonymous>';
82
+ if (!withLine) return fileName;
83
+ return `${fileName}:${callSite.getLineNumber()}:${callSite.getColumnNumber()}`;
84
+ },
85
+
86
+ getResolvedFilename(filepath, baseDir) {
87
+ const reg = /[/\\]/g;
88
+ return filepath.replace(baseDir + path.sep, '').replace(reg, '/');
89
+ },
90
+ };
91
+
92
+
93
+ /**
94
+ * Capture call site stack from v8.
95
+ * https://github.com/v8/v8/wiki/Stack-Trace-API
96
+ */
97
+
98
+ function prepareObjectStackTrace(obj, stack) {
99
+ return stack;
100
+ }
@@ -1,59 +1,59 @@
1
- 'use strict';
2
-
3
- const debug = require('debug')('egg-core#sequencify');
4
-
5
- function sequence(tasks, names, results, missing, recursive, nest, optional, parent) {
6
- names.forEach(function(name) {
7
- if (results.requires[name]) return;
8
-
9
- const node = tasks[name];
10
-
11
- if (!node) {
12
- if (optional === true) return;
13
- missing.push(name);
14
- } else if (nest.includes(name)) {
15
- nest.push(name);
16
- recursive.push(nest.slice(0));
17
- nest.pop(name);
18
- } else if (node.dependencies.length || node.optionalDependencies.length) {
19
- nest.push(name);
20
- if (node.dependencies.length) {
21
- sequence(tasks, node.dependencies, results, missing, recursive, nest, optional, name);
22
- }
23
- if (node.optionalDependencies.length) {
24
- sequence(tasks, node.optionalDependencies, results, missing, recursive, nest, true, name);
25
- }
26
- nest.pop(name);
27
- }
28
- if (!optional) {
29
- results.requires[name] = true;
30
- debug('task: %s is enabled by %s', name, parent);
31
- }
32
- if (!results.sequence.includes(name)) {
33
- results.sequence.push(name);
34
- }
35
- });
36
- }
37
-
38
- // tasks: object with keys as task names
39
- // names: array of task names
40
- module.exports = function(tasks, names) {
41
- const results = {
42
- sequence: [],
43
- requires: {},
44
- }; // the final sequence
45
- const missing = []; // missing tasks
46
- const recursive = []; // recursive task dependencies
47
-
48
- sequence(tasks, names, results, missing, recursive, [], false, 'app');
49
-
50
- if (missing.length || recursive.length) {
51
- results.sequence = []; // results are incomplete at best, completely wrong at worst, remove them to avoid confusion
52
- }
53
-
54
- return {
55
- sequence: results.sequence.filter(item => results.requires[item]),
56
- missingTasks: missing,
57
- recursiveDependencies: recursive,
58
- };
59
- };
1
+ 'use strict';
2
+
3
+ const debug = require('debug')('egg-core#sequencify');
4
+
5
+ function sequence(tasks, names, results, missing, recursive, nest, optional, parent) {
6
+ names.forEach(function(name) {
7
+ if (results.requires[name]) return;
8
+
9
+ const node = tasks[name];
10
+
11
+ if (!node) {
12
+ if (optional === true) return;
13
+ missing.push(name);
14
+ } else if (nest.includes(name)) {
15
+ nest.push(name);
16
+ recursive.push(nest.slice(0));
17
+ nest.pop(name);
18
+ } else if (node.dependencies.length || node.optionalDependencies.length) {
19
+ nest.push(name);
20
+ if (node.dependencies.length) {
21
+ sequence(tasks, node.dependencies, results, missing, recursive, nest, optional, name);
22
+ }
23
+ if (node.optionalDependencies.length) {
24
+ sequence(tasks, node.optionalDependencies, results, missing, recursive, nest, true, name);
25
+ }
26
+ nest.pop(name);
27
+ }
28
+ if (!optional) {
29
+ results.requires[name] = true;
30
+ debug('task: %s is enabled by %s', name, parent);
31
+ }
32
+ if (!results.sequence.includes(name)) {
33
+ results.sequence.push(name);
34
+ }
35
+ });
36
+ }
37
+
38
+ // tasks: object with keys as task names
39
+ // names: array of task names
40
+ module.exports = function(tasks, names) {
41
+ const results = {
42
+ sequence: [],
43
+ requires: {},
44
+ }; // the final sequence
45
+ const missing = []; // missing tasks
46
+ const recursive = []; // recursive task dependencies
47
+
48
+ sequence(tasks, names, results, missing, recursive, [], false, 'app');
49
+
50
+ if (missing.length || recursive.length) {
51
+ results.sequence = []; // results are incomplete at best, completely wrong at worst, remove them to avoid confusion
52
+ }
53
+
54
+ return {
55
+ sequence: results.sequence.filter(item => results.requires[item]),
56
+ missingTasks: missing,
57
+ recursiveDependencies: recursive,
58
+ };
59
+ };
@@ -1,77 +1,77 @@
1
- 'use strict';
2
-
3
- const assert = require('assert');
4
- const MAP = Symbol('Timing#map');
5
- const LIST = Symbol('Timing#list');
6
-
7
-
8
- class Timing {
9
-
10
- constructor() {
11
- this._enable = true;
12
- this[MAP] = new Map();
13
- this[LIST] = [];
14
-
15
- this.init();
16
- }
17
-
18
- init() {
19
- // process start time
20
- this.start('Process Start', Date.now() - Math.floor((process.uptime() * 1000)));
21
- this.end('Process Start');
22
-
23
- if (typeof process.scriptStartTime === 'number') {
24
- // js script start execute time
25
- this.start('Script Start', process.scriptStartTime);
26
- this.end('Script Start');
27
- }
28
- }
29
-
30
- start(name, start) {
31
- if (!name || !this._enable) return;
32
-
33
- if (this[MAP].has(name)) this.end(name);
34
-
35
- start = start || Date.now();
36
- const item = {
37
- name,
38
- start,
39
- end: undefined,
40
- duration: undefined,
41
- pid: process.pid,
42
- index: this[LIST].length,
43
- };
44
- this[MAP].set(name, item);
45
- this[LIST].push(item);
46
- return item;
47
- }
48
-
49
- end(name) {
50
- if (!name || !this._enable) return;
51
- assert(this[MAP].has(name), `should run timing.start('${name}') first`);
52
-
53
- const item = this[MAP].get(name);
54
- item.end = Date.now();
55
- item.duration = item.end - item.start;
56
- return item;
57
- }
58
-
59
- enable() {
60
- this._enable = true;
61
- }
62
-
63
- disable() {
64
- this._enable = false;
65
- }
66
-
67
- clear() {
68
- this[MAP].clear();
69
- this[LIST] = [];
70
- }
71
-
72
- toJSON() {
73
- return this[LIST];
74
- }
75
- }
76
-
77
- module.exports = Timing;
1
+ 'use strict';
2
+
3
+ const assert = require('assert');
4
+ const MAP = Symbol('Timing#map');
5
+ const LIST = Symbol('Timing#list');
6
+
7
+
8
+ class Timing {
9
+
10
+ constructor() {
11
+ this._enable = true;
12
+ this[MAP] = new Map();
13
+ this[LIST] = [];
14
+
15
+ this.init();
16
+ }
17
+
18
+ init() {
19
+ // process start time
20
+ this.start('Process Start', Date.now() - Math.floor((process.uptime() * 1000)));
21
+ this.end('Process Start');
22
+
23
+ if (typeof process.scriptStartTime === 'number') {
24
+ // js script start execute time
25
+ this.start('Script Start', process.scriptStartTime);
26
+ this.end('Script Start');
27
+ }
28
+ }
29
+
30
+ start(name, start) {
31
+ if (!name || !this._enable) return;
32
+
33
+ if (this[MAP].has(name)) this.end(name);
34
+
35
+ start = start || Date.now();
36
+ const item = {
37
+ name,
38
+ start,
39
+ end: undefined,
40
+ duration: undefined,
41
+ pid: process.pid,
42
+ index: this[LIST].length,
43
+ };
44
+ this[MAP].set(name, item);
45
+ this[LIST].push(item);
46
+ return item;
47
+ }
48
+
49
+ end(name) {
50
+ if (!name || !this._enable) return;
51
+ assert(this[MAP].has(name), `should run timing.start('${name}') first`);
52
+
53
+ const item = this[MAP].get(name);
54
+ item.end = Date.now();
55
+ item.duration = item.end - item.start;
56
+ return item;
57
+ }
58
+
59
+ enable() {
60
+ this._enable = true;
61
+ }
62
+
63
+ disable() {
64
+ this._enable = false;
65
+ }
66
+
67
+ clear() {
68
+ this[MAP].clear();
69
+ this[LIST] = [];
70
+ }
71
+
72
+ toJSON() {
73
+ return this[LIST];
74
+ }
75
+ }
76
+
77
+ module.exports = Timing;
package/index.js CHANGED
@@ -1,50 +1,50 @@
1
- 'use strict';
2
-
3
- /**
4
- * @namespace EeCore
5
- */
6
-
7
- /**
8
- * @member {Appliaction} EeCore#Appliaction
9
- * @since 1.0.0
10
- */
11
- const Appliaction = require('./lib/application');
12
-
13
- /**
14
- * @member {Controller} EeCore#Controller
15
- * @since 1.0.0
16
- */
17
- const Controller = require('./core/lib/utils/base_context_class');
18
-
19
- /**
20
- * @member {Service} EeCore#Service
21
- * @since 1.0.0
22
- */
23
- const Service = require('./core/lib/utils/base_context_class');
24
-
25
- /**
26
- * @member {Storage}
27
- * @since 1.0.0
28
- */
29
- const Storage = require('./lib/storage/index');
30
-
31
- /**
32
- * @member {Utils}
33
- * @since 1.0.0
34
- */
35
- const Utils = require('./utils/index');
36
-
37
- /**
38
- * @member {Socket}
39
- * @since 1.0.0
40
- */
41
- const Socket = require('./lib/socket/io');
42
-
43
- module.exports = {
44
- Appliaction,
45
- Controller,
46
- Service,
47
- Storage,
48
- Socket,
49
- Utils
1
+ 'use strict';
2
+
3
+ /**
4
+ * @namespace EeCore
5
+ */
6
+
7
+ /**
8
+ * @member {Appliaction} EeCore#Appliaction
9
+ * @since 1.0.0
10
+ */
11
+ const Appliaction = require('./lib/application');
12
+
13
+ /**
14
+ * @member {Controller} EeCore#Controller
15
+ * @since 1.0.0
16
+ */
17
+ const Controller = require('./core/lib/utils/base_context_class');
18
+
19
+ /**
20
+ * @member {Service} EeCore#Service
21
+ * @since 1.0.0
22
+ */
23
+ const Service = require('./core/lib/utils/base_context_class');
24
+
25
+ /**
26
+ * @member {Storage}
27
+ * @since 1.0.0
28
+ */
29
+ const Storage = require('./lib/storage/index');
30
+
31
+ /**
32
+ * @member {Utils}
33
+ * @since 1.0.0
34
+ */
35
+ const Utils = require('./utils/index');
36
+
37
+ /**
38
+ * @member {Socket}
39
+ * @since 1.0.0
40
+ */
41
+ const Socket = require('./lib/socket/io');
42
+
43
+ module.exports = {
44
+ Appliaction,
45
+ Controller,
46
+ Service,
47
+ Storage,
48
+ Socket,
49
+ Utils
50
50
  };
package/lib/appLoader.js CHANGED
@@ -1,45 +1,45 @@
1
- 'use strict';
2
-
3
- const EeLoader = require('../core/index').EeLoader;
4
-
5
- /**
6
- * App Loader
7
- * @see
8
- */
9
- class AppLoader extends EeLoader {
10
-
11
- /**
12
- * loadPlugin first, then loadConfig
13
- * @since 1.0.0
14
- */
15
- loadConfig() {
16
- super.loadConfig();
17
- }
18
-
19
- /**
20
- * Load all directories in convention
21
- * @since 1.0.0
22
- */
23
- load() {
24
-
25
- // app > plugin
26
- this.loadService();
27
-
28
- // app
29
- this.loadController();
30
-
31
- }
32
-
33
- /**
34
- * load electron modules
35
- * @since 1.0.0
36
- */
37
- loadElectron() {
38
-
39
- // 预加载功能模块
40
- //this.loadPreload();
41
-
42
- }
43
- }
44
-
45
- module.exports = AppLoader;
1
+ 'use strict';
2
+
3
+ const EeLoader = require('../core/index').EeLoader;
4
+
5
+ /**
6
+ * App Loader
7
+ * @see
8
+ */
9
+ class AppLoader extends EeLoader {
10
+
11
+ /**
12
+ * loadPlugin first, then loadConfig
13
+ * @since 1.0.0
14
+ */
15
+ loadConfig() {
16
+ super.loadConfig();
17
+ }
18
+
19
+ /**
20
+ * Load all directories in convention
21
+ * @since 1.0.0
22
+ */
23
+ load() {
24
+
25
+ // app > plugin
26
+ this.loadService();
27
+
28
+ // app
29
+ this.loadController();
30
+
31
+ }
32
+
33
+ /**
34
+ * load electron modules
35
+ * @since 1.0.0
36
+ */
37
+ loadElectron() {
38
+
39
+ // 预加载功能模块
40
+ //this.loadPreload();
41
+
42
+ }
43
+ }
44
+
45
+ module.exports = AppLoader;