nodester 0.0.7 → 0.0.9
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/Readme.md +9 -63
- package/lib/models/associate.js +17 -0
- package/lib/models/define.js +1 -0
- package/lib/models/mixins.js +5 -5
- package/package.json +3 -2
- package/lib/models/DisabledRefreshToken.js +0 -68
package/Readme.md
CHANGED
|
@@ -4,13 +4,13 @@
|
|
|
4
4
|
## Table of Contents
|
|
5
5
|
|
|
6
6
|
- [Usage](#usage)
|
|
7
|
-
- [
|
|
8
|
-
- [Router](#router)
|
|
7
|
+
- [Documentation](#documentation)
|
|
9
8
|
- [Extending App](#extending-application-functionality)
|
|
10
9
|
- [Philosophy](#philosophy)
|
|
11
10
|
- [License](#license)
|
|
12
11
|
- [Copyright](#copyright)
|
|
13
12
|
|
|
13
|
+
|
|
14
14
|
## Usage
|
|
15
15
|
|
|
16
16
|
```js
|
|
@@ -25,72 +25,17 @@ app.listen(8080, function() {
|
|
|
25
25
|
});
|
|
26
26
|
```
|
|
27
27
|
|
|
28
|
-
## Markers
|
|
29
|
-
|
|
30
|
-
Marker is a functional condition that returns `true | false`, based on data in request/response.
|
|
31
28
|
|
|
32
|
-
|
|
29
|
+
## Documentation
|
|
33
30
|
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
`api.awesomeapp.com`
|
|
31
|
+
### Core concepts
|
|
32
|
+
[Go to core concepts documentaion](docs/CoreConcepts.md)
|
|
37
33
|
|
|
38
|
-
You add markers and handlers specifically for those domains:
|
|
39
|
-
|
|
40
|
-
```js
|
|
41
|
-
app.add.marker('ADMIN', (req) => req.hostname === 'admin.awesomeapp.com');
|
|
42
|
-
app.add.marker('API', (req) => req.hostname === 'api.awesomeapp.com');
|
|
43
|
-
```
|
|
44
34
|
|
|
45
|
-
|
|
35
|
+
### Extending Application functionality
|
|
46
36
|
|
|
47
|
-
```js
|
|
48
|
-
app.only('ADMIN').route('get /payments', <handler/>);
|
|
49
|
-
app.only('API').route('get /payments', <handler/>);
|
|
50
|
-
// Or:
|
|
51
|
-
app.only('ADMIN').use(<handler/>);
|
|
52
|
-
app.only('API').use(<handler/>);
|
|
53
|
-
```
|
|
54
37
|
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
```js
|
|
58
|
-
app.add.marker('admin_role', (req) => req.role === 'admin');
|
|
59
|
-
app.only('admin_role').route('get /secrets', <handler/>);
|
|
60
|
-
app.only('admin_role').use(<handler/>);
|
|
61
|
-
```
|
|
62
|
-
|
|
63
|
-
## Router
|
|
64
|
-
|
|
65
|
-
Router is a built-in middleware.
|
|
66
|
-
|
|
67
|
-
```js
|
|
68
|
-
const Router = require('nodester/router');
|
|
69
|
-
|
|
70
|
-
const controllersPath = <path_to_controllers_directory/>;
|
|
71
|
-
const router = new Router({ controllersPath });
|
|
72
|
-
|
|
73
|
-
router.add.route('get /books', function(req, res) { ... } );
|
|
74
|
-
// Or:
|
|
75
|
-
router.add.route('get /books', { controlledBy: 'BooksController.getMany' } );
|
|
76
|
-
router.add.route('get /books/:id', { controlledBy: 'BooksController.getOne' } );
|
|
77
|
-
```
|
|
78
|
-
|
|
79
|
-
### Using Router:
|
|
80
|
-
|
|
81
|
-
```js
|
|
82
|
-
const nodester = require('nodester');
|
|
83
|
-
const router = require(<path_to_router_definition/>);
|
|
84
|
-
|
|
85
|
-
const app = new nodester();
|
|
86
|
-
app.use(router());
|
|
87
|
-
```
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
## Extending Application functionality
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
### Extending instance (safe way):
|
|
38
|
+
#### Extending instance (safe way):
|
|
94
39
|
|
|
95
40
|
```js
|
|
96
41
|
const serveStatic = require('serve-static');
|
|
@@ -124,7 +69,7 @@ app.static = serveStatic;
|
|
|
124
69
|
But you'll never know if you did override any of the app's properties or did not.
|
|
125
70
|
|
|
126
71
|
|
|
127
|
-
|
|
72
|
+
#### Extending class:
|
|
128
73
|
|
|
129
74
|
If you really want to override properties or use `nodester` as a boilerplate, you should extend default Application class:
|
|
130
75
|
|
|
@@ -143,6 +88,7 @@ class MyApp extends NodesterApp {
|
|
|
143
88
|
module.exports = MyApp;
|
|
144
89
|
```
|
|
145
90
|
|
|
91
|
+
|
|
146
92
|
## Philosophy
|
|
147
93
|
|
|
148
94
|
The Philosophy of `nodester` is to provide a developer with a tool that can build an app (or feature) in hours and scale it with ease for years.
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
|
|
2
|
+
module.exports = async function associateModels(databaseConnection) {
|
|
3
|
+
try {
|
|
4
|
+
const models = databaseConnection.models;
|
|
5
|
+
|
|
6
|
+
const modelNames = Object.keys(models);
|
|
7
|
+
|
|
8
|
+
for (let modelName of modelNames) {
|
|
9
|
+
await models[modelName].associate(models);
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
return Promise.resolve(models);
|
|
13
|
+
}
|
|
14
|
+
catch(error) {
|
|
15
|
+
return Promise.reject(error);
|
|
16
|
+
}
|
|
17
|
+
}
|
package/lib/models/define.js
CHANGED
package/lib/models/mixins.js
CHANGED
|
@@ -6,7 +6,7 @@ const {
|
|
|
6
6
|
modelHasAssociations,
|
|
7
7
|
getModelAssociationProps,
|
|
8
8
|
compileModelAssociationData,
|
|
9
|
-
} = require('
|
|
9
|
+
} = require('../utils/modelAssociations.util');
|
|
10
10
|
|
|
11
11
|
|
|
12
12
|
module.exports = {
|
|
@@ -17,15 +17,15 @@ module.exports = {
|
|
|
17
17
|
/**
|
|
18
18
|
* Sets all of CRUD methods to Model.
|
|
19
19
|
*
|
|
20
|
-
* @param {Object}
|
|
20
|
+
* @param {Object} modelDefinition
|
|
21
21
|
*
|
|
22
22
|
*
|
|
23
23
|
* @api public
|
|
24
24
|
* @alias implementsCRUD
|
|
25
25
|
*/
|
|
26
|
-
function _implementsCRUD(
|
|
27
|
-
if (!
|
|
28
|
-
const err = new TypeError(`
|
|
26
|
+
function _implementsCRUD(modelDefinition) {
|
|
27
|
+
if (!modelDefinition) {
|
|
28
|
+
const err = new TypeError(`"modelDefinition" argument is not provided.`);
|
|
29
29
|
throw err;
|
|
30
30
|
}
|
|
31
31
|
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "nodester",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.9",
|
|
4
4
|
"description": "A boilerplate framework for Node.js",
|
|
5
5
|
"exports": {
|
|
6
6
|
".": "./lib/application/index.js",
|
|
@@ -10,7 +10,8 @@
|
|
|
10
10
|
"./factories/errors": "./lib/factories/errors/index.js",
|
|
11
11
|
"./factories/responses/rest": "./lib/factories/responses/rest/index.js",
|
|
12
12
|
"./http/codes": "./lib/http/codes/index.js",
|
|
13
|
-
"./models/
|
|
13
|
+
"./models/associate": "./lib/models/associate.js",
|
|
14
|
+
"./models/define": "./lib/models/define.js",
|
|
14
15
|
"./params": "./lib/params/Params.js",
|
|
15
16
|
"./ql/sequelize": "./lib/middlewares/ql/sequelize",
|
|
16
17
|
"./route": "./lib/router/route.js",
|
|
@@ -1,68 +0,0 @@
|
|
|
1
|
-
const defineModel = require('./define');
|
|
2
|
-
// ORM.
|
|
3
|
-
const { DataTypes } = require('sequelize');
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
module.exports = _defineDisabledRefreshToken;
|
|
7
|
-
|
|
8
|
-
function _defineDisabledRefreshToken(
|
|
9
|
-
database,
|
|
10
|
-
roleIds=[],
|
|
11
|
-
options={}
|
|
12
|
-
) {
|
|
13
|
-
|
|
14
|
-
const fields = {
|
|
15
|
-
id: {
|
|
16
|
-
type: DataTypes.INTEGER.UNSIGNED,
|
|
17
|
-
allowNull: false,
|
|
18
|
-
primaryKey: true,
|
|
19
|
-
autoIncrement: true,
|
|
20
|
-
_autoGenerated: true
|
|
21
|
-
},
|
|
22
|
-
|
|
23
|
-
token: {
|
|
24
|
-
type: DataTypes.STRING,
|
|
25
|
-
required: true,
|
|
26
|
-
allowNull: false,
|
|
27
|
-
unique: true
|
|
28
|
-
}
|
|
29
|
-
};
|
|
30
|
-
|
|
31
|
-
roleIds.forEach(roleId => fields[roleId] = {
|
|
32
|
-
type: DataTypes.INTEGER.UNSIGNED,
|
|
33
|
-
allowNull: true
|
|
34
|
-
});
|
|
35
|
-
|
|
36
|
-
const disabledRefreshToken = defineModel(database, 'DisabledRefreshToken',
|
|
37
|
-
(DataTypes) => ( fields ),
|
|
38
|
-
{ ...options }
|
|
39
|
-
);
|
|
40
|
-
|
|
41
|
-
disabledRefreshToken.createOrFind = function({
|
|
42
|
-
token,
|
|
43
|
-
...roleInfo
|
|
44
|
-
}) {
|
|
45
|
-
const where = {
|
|
46
|
-
token
|
|
47
|
-
};
|
|
48
|
-
|
|
49
|
-
const defaults = {
|
|
50
|
-
token: token,
|
|
51
|
-
...roleInfo
|
|
52
|
-
};
|
|
53
|
-
|
|
54
|
-
const query = {
|
|
55
|
-
where,
|
|
56
|
-
defaults
|
|
57
|
-
};
|
|
58
|
-
return this.findOrCreate(query);
|
|
59
|
-
}
|
|
60
|
-
|
|
61
|
-
disabledRefreshToken.selectAll = function({ token }) {
|
|
62
|
-
const where = { token };
|
|
63
|
-
const query = { where };
|
|
64
|
-
return this.findAll(query);
|
|
65
|
-
}
|
|
66
|
-
|
|
67
|
-
return disabledRefreshToken;
|
|
68
|
-
}
|