@adaptivestone/framework 5.0.0-alpha.5 → 5.0.0-alpha.6
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.
- package/CHANGELOG.md +4 -0
- package/commands/CreateUser.js +3 -1
- package/jsconfig.json +9 -0
- package/modules/AbstractCommand.js +2 -1
- package/modules/AbstractController.js +4 -0
- package/modules/AbstractModel.js +2 -2
- package/modules/Base.d.ts +4 -3
- package/package.json +1 -1
- package/server.d.ts +7 -5
- package/server.js +3 -3
- package/services/cache/Cache.d.ts +2 -2
- package/services/http/HttpServer.js +1 -1
- package/services/http/middleware/GetUserByToken.js +1 -1
- package/services/http/middleware/RequestParser.test.js +14 -5
- package/services/messaging/email/index.js +7 -15
package/CHANGELOG.md
CHANGED
package/commands/CreateUser.js
CHANGED
|
@@ -60,7 +60,9 @@ class CreateUser extends AbstractCommand {
|
|
|
60
60
|
|
|
61
61
|
await user.generateToken();
|
|
62
62
|
|
|
63
|
-
this.logger.info(
|
|
63
|
+
this.logger.info(
|
|
64
|
+
`User was created/updated ${JSON.stringify(user, null, 4)}`,
|
|
65
|
+
);
|
|
64
66
|
|
|
65
67
|
return user;
|
|
66
68
|
}
|
package/jsconfig.json
ADDED
|
@@ -13,10 +13,11 @@ class AbstractCommand extends Base {
|
|
|
13
13
|
|
|
14
14
|
/**
|
|
15
15
|
* Entry point to every command. This method should be overridden
|
|
16
|
-
* @
|
|
16
|
+
* @return {Promise<boolean>} resut
|
|
17
17
|
*/
|
|
18
18
|
async run() {
|
|
19
19
|
this.logger.error('You should implement run method');
|
|
20
|
+
return false;
|
|
20
21
|
}
|
|
21
22
|
|
|
22
23
|
static get loggerGroup() {
|
|
@@ -25,10 +25,12 @@ class AbstractController extends Base {
|
|
|
25
25
|
const { routes } = this;
|
|
26
26
|
let httpPath = this.getHttpPath();
|
|
27
27
|
|
|
28
|
+
// @ts-ignore
|
|
28
29
|
if (this.getExpressPath) {
|
|
29
30
|
this.logger.warn(
|
|
30
31
|
`getExpressPath deprecated. Please use getHttpPath instead. Will be removed on v5`,
|
|
31
32
|
);
|
|
33
|
+
// @ts-ignore
|
|
32
34
|
httpPath = this.getExpressPath();
|
|
33
35
|
}
|
|
34
36
|
|
|
@@ -58,6 +60,7 @@ class AbstractController extends Base {
|
|
|
58
60
|
httpPath,
|
|
59
61
|
);
|
|
60
62
|
const middlewaresInfo = this.parseMiddlewares(
|
|
63
|
+
// @ts-ignore
|
|
61
64
|
this.constructor.middleware,
|
|
62
65
|
httpPath,
|
|
63
66
|
);
|
|
@@ -370,6 +373,7 @@ class AbstractController extends Base {
|
|
|
370
373
|
* You should provide path relative to controller and then array of middlewares to apply.
|
|
371
374
|
* Order is matter.
|
|
372
375
|
* Be default path apply to ANY' method, but you can preattach 'METHOD' into patch to scope patch to this METHOD
|
|
376
|
+
* @returns {Map<string, Array<AbstractMiddleware | [Function, ...any]>>}
|
|
373
377
|
* @example
|
|
374
378
|
* return new Map([
|
|
375
379
|
* ['/*', [GetUserByToken]] // for any method for this controller
|
package/modules/AbstractModel.js
CHANGED
|
@@ -3,12 +3,12 @@ import Base from './Base.js';
|
|
|
3
3
|
|
|
4
4
|
class AbstractModel extends Base {
|
|
5
5
|
/**
|
|
6
|
-
* @param {import('../server')} app //TODO change to *.d.ts as this is a Server, not app
|
|
6
|
+
* @param {import('../server.js').default['app']} app //TODO change to *.d.ts as this is a Server, not app
|
|
7
7
|
* @param function callback optional callback when connection ready
|
|
8
8
|
*/
|
|
9
9
|
constructor(app, callback = () => {}) {
|
|
10
10
|
super(app);
|
|
11
|
-
this.mongooseSchema = mongoose.Schema(this.modelSchema);
|
|
11
|
+
this.mongooseSchema = new mongoose.Schema(this.modelSchema);
|
|
12
12
|
mongoose.set('strictQuery', true);
|
|
13
13
|
this.mongooseSchema.set('timestamps', true);
|
|
14
14
|
this.mongooseSchema.set('minimize', false);
|
package/modules/Base.d.ts
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import winston from 'winston';
|
|
2
|
-
import Server from '../server';
|
|
2
|
+
import Server from '../server.js';
|
|
3
|
+
import type { Dirent } from 'fs';
|
|
3
4
|
|
|
4
5
|
declare class Base {
|
|
5
6
|
app: Server['app'];
|
|
@@ -26,11 +27,11 @@ declare class Base {
|
|
|
26
27
|
getFilesPathWithInheritance(
|
|
27
28
|
internalFolder: string,
|
|
28
29
|
externalFolder: string,
|
|
29
|
-
): Promise<
|
|
30
|
+
): Promise<Dirent[]>;
|
|
30
31
|
|
|
31
32
|
/**
|
|
32
33
|
* Return logger group. Just to have all logs groupped logically
|
|
33
34
|
*/
|
|
34
35
|
static get loggerGroup(): string;
|
|
35
36
|
}
|
|
36
|
-
export
|
|
37
|
+
export default Base;
|
package/package.json
CHANGED
package/server.d.ts
CHANGED
|
@@ -9,6 +9,8 @@ import BaseCli from './modules/BaseCli';
|
|
|
9
9
|
import Cache from './services/cache/Cache';
|
|
10
10
|
import winston from 'winston';
|
|
11
11
|
|
|
12
|
+
import HttpServer from './services/http/HttpServer.js';
|
|
13
|
+
|
|
12
14
|
type ServerConfig = {
|
|
13
15
|
folders: ExpandDeep<TFolderConfig>;
|
|
14
16
|
};
|
|
@@ -24,7 +26,7 @@ declare class Server {
|
|
|
24
26
|
events: EventEmitter;
|
|
25
27
|
get cache(): Server['cacheService'];
|
|
26
28
|
get logger(): winston.Logger;
|
|
27
|
-
httpServer: null;
|
|
29
|
+
httpServer: HttpServer | null;
|
|
28
30
|
controllerManager: null;
|
|
29
31
|
};
|
|
30
32
|
cacheService: Cache;
|
|
@@ -33,7 +35,7 @@ declare class Server {
|
|
|
33
35
|
configs: Map<string, {}>;
|
|
34
36
|
models: Map<string, MongooseModel<any>>;
|
|
35
37
|
};
|
|
36
|
-
cli:
|
|
38
|
+
cli: null | BaseCli;
|
|
37
39
|
|
|
38
40
|
/**
|
|
39
41
|
* Construct new server
|
|
@@ -68,7 +70,7 @@ declare class Server {
|
|
|
68
70
|
* @see updateConfig
|
|
69
71
|
* @TODO generate that based on real data
|
|
70
72
|
*/
|
|
71
|
-
getConfig(configName: string): {};
|
|
73
|
+
getConfig(configName: string): { [key: string]: any };
|
|
72
74
|
|
|
73
75
|
/**
|
|
74
76
|
* Return or create new logger instance. This is a main logger instance
|
|
@@ -79,7 +81,7 @@ declare class Server {
|
|
|
79
81
|
* Primary designed for tests when we need to update some configs before start testing
|
|
80
82
|
* Should be called before any initialization was done
|
|
81
83
|
*/
|
|
82
|
-
updateConfig(configName: string, config: {}): {};
|
|
84
|
+
updateConfig(configName: string, config: {}): { [key: string]: any };
|
|
83
85
|
|
|
84
86
|
/**
|
|
85
87
|
* Return model from {modelName} (file name) on model folder.
|
|
@@ -93,4 +95,4 @@ declare class Server {
|
|
|
93
95
|
runCliCommand(commandName: string, args: {}): Promise<BaseCli['run']>;
|
|
94
96
|
}
|
|
95
97
|
|
|
96
|
-
export
|
|
98
|
+
export default Server;
|
package/server.js
CHANGED
|
@@ -19,6 +19,8 @@ class Server {
|
|
|
19
19
|
|
|
20
20
|
#isInited = false;
|
|
21
21
|
|
|
22
|
+
cli = null;
|
|
23
|
+
|
|
22
24
|
/**
|
|
23
25
|
* Construct new server
|
|
24
26
|
* @param {Object} config main config object
|
|
@@ -56,8 +58,6 @@ class Server {
|
|
|
56
58
|
models: new Map(),
|
|
57
59
|
modelConstructors: new Map(),
|
|
58
60
|
};
|
|
59
|
-
|
|
60
|
-
this.cli = false;
|
|
61
61
|
}
|
|
62
62
|
|
|
63
63
|
/**
|
|
@@ -350,7 +350,7 @@ class Server {
|
|
|
350
350
|
* Return model from {modelName} (file name) on model folder.
|
|
351
351
|
* Support cache
|
|
352
352
|
* @param {String} modelName name on config file to load
|
|
353
|
-
* @returns {import('mongoose').Model}
|
|
353
|
+
* @returns {import('mongoose').Model | false| {}}
|
|
354
354
|
*/
|
|
355
355
|
getModel(modelName) {
|
|
356
356
|
if (modelName.endsWith('s')) {
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import Base from '../../modules/Base';
|
|
2
|
-
import Server from '../../server';
|
|
2
|
+
import Server from '../../server.js';
|
|
3
3
|
|
|
4
4
|
declare class Cache extends Base {
|
|
5
5
|
app: Server['app'];
|
|
@@ -32,4 +32,4 @@ declare class Cache extends Base {
|
|
|
32
32
|
removeKey(key: string): Promise<number>;
|
|
33
33
|
}
|
|
34
34
|
|
|
35
|
-
export
|
|
35
|
+
export default Cache;
|
|
@@ -57,7 +57,7 @@ class HttpServer extends Base {
|
|
|
57
57
|
res.status(500).json({ message: 'Something broke!' });
|
|
58
58
|
});
|
|
59
59
|
|
|
60
|
-
this.httpServer = http.
|
|
60
|
+
this.httpServer = http.createServer(this.express);
|
|
61
61
|
|
|
62
62
|
const listener = this.httpServer.listen(
|
|
63
63
|
httpConfig.port,
|
|
@@ -79,12 +79,21 @@ d\r
|
|
|
79
79
|
const server = createServer(async (req, res) => {
|
|
80
80
|
req.appInfo = {};
|
|
81
81
|
const middleware = new RequestParser(global.server.app);
|
|
82
|
-
|
|
83
|
-
expect(err).toBeDefined();
|
|
82
|
+
let status;
|
|
84
83
|
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
84
|
+
const resp = {
|
|
85
|
+
status: (code) => {
|
|
86
|
+
status = code;
|
|
87
|
+
return resp;
|
|
88
|
+
},
|
|
89
|
+
json: () => resp,
|
|
90
|
+
};
|
|
91
|
+
await middleware.middleware(req, resp, () => {});
|
|
92
|
+
expect(status).toBe(400);
|
|
93
|
+
// expect(err).toBeDefined();
|
|
94
|
+
|
|
95
|
+
res.writeHead(200);
|
|
96
|
+
res.end('ok');
|
|
88
97
|
});
|
|
89
98
|
server.listen(null, async () => {
|
|
90
99
|
const chosenPort = server.address().port;
|
|
@@ -66,7 +66,8 @@ class Mail extends Base {
|
|
|
66
66
|
* @param {object} templateData
|
|
67
67
|
* @returns string
|
|
68
68
|
*/
|
|
69
|
-
|
|
69
|
+
// eslint-disable-next-line class-methods-use-this
|
|
70
|
+
async #renderTemplateFile({ type, fullPath } = {}, templateData = {}) {
|
|
70
71
|
if (!type) {
|
|
71
72
|
return null;
|
|
72
73
|
}
|
|
@@ -116,19 +117,10 @@ class Mail extends Base {
|
|
|
116
117
|
|
|
117
118
|
const [htmlRendered, subjectRendered, textRendered, extraCss] =
|
|
118
119
|
await Promise.all([
|
|
119
|
-
this
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
),
|
|
123
|
-
this.constructor.#renderTemplateFile(
|
|
124
|
-
templates.subject,
|
|
125
|
-
templateDataToRender,
|
|
126
|
-
),
|
|
127
|
-
this.constructor.#renderTemplateFile(
|
|
128
|
-
templates.text,
|
|
129
|
-
templateDataToRender,
|
|
130
|
-
),
|
|
131
|
-
this.constructor.#renderTemplateFile(templates.style),
|
|
120
|
+
this.#renderTemplateFile(templates.html, templateDataToRender),
|
|
121
|
+
this.#renderTemplateFile(templates.subject, templateDataToRender),
|
|
122
|
+
this.#renderTemplateFile(templates.text, templateDataToRender),
|
|
123
|
+
this.#renderTemplateFile(templates.style),
|
|
132
124
|
]);
|
|
133
125
|
|
|
134
126
|
juice.tableElements = ['TABLE'];
|
|
@@ -171,7 +163,7 @@ class Mail extends Base {
|
|
|
171
163
|
|
|
172
164
|
/**
|
|
173
165
|
* Send provided text (html) to email. Low level function. All data should be prepared before sending (like inline styles)
|
|
174
|
-
* @param {
|
|
166
|
+
* @param {import('../../../server.js').default['app']} app application
|
|
175
167
|
* @param {string} to send to
|
|
176
168
|
* @param {string} subject email topic
|
|
177
169
|
* @param {string} html hmlt body of emain
|