nodester 0.0.5 → 0.0.7
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/package.json +2 -1
- package/docs/App.md +0 -13
- package/docs/GoalController.js +0 -62
- package/docs/Queries.md +0 -61
- package/docs/Readme.md +0 -2
- package/docs/Routing.md +0 -34
- package/docs/request-examples.js +0 -184
- package/examples/goal/index.js +0 -23
- package/examples/rest/controllers/orders.controller.js +0 -15
- package/examples/rest/index.js +0 -45
- package/examples/rest/node_modules/.package-lock.json +0 -42
- package/examples/rest/package.json +0 -14
- package/examples/rest/preprocessors/queries/orders.queries.js +0 -15
- package/examples/rest/router.js +0 -23
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "nodester",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.7",
|
|
4
4
|
"description": "A boilerplate framework for Node.js",
|
|
5
5
|
"exports": {
|
|
6
6
|
".": "./lib/application/index.js",
|
|
@@ -10,6 +10,7 @@
|
|
|
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/define": "./lib/models/define",
|
|
13
14
|
"./params": "./lib/params/Params.js",
|
|
14
15
|
"./ql/sequelize": "./lib/middlewares/ql/sequelize",
|
|
15
16
|
"./route": "./lib/router/route.js",
|
package/docs/App.md
DELETED
package/docs/GoalController.js
DELETED
|
@@ -1,62 +0,0 @@
|
|
|
1
|
-
const {
|
|
2
|
-
withDefaultCRUD
|
|
3
|
-
} = require('nodester/controllers/mixins');
|
|
4
|
-
const {
|
|
5
|
-
getOne,
|
|
6
|
-
getMany,
|
|
7
|
-
createOne,
|
|
8
|
-
updateOne,
|
|
9
|
-
deleteOne
|
|
10
|
-
} = require('nodester/controllers/methods');
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
#nodester
|
|
14
|
-
function withDefaultCRUD(instance, opts={}) {}
|
|
15
|
-
function getOne(req, res) {}
|
|
16
|
-
function getMany(req, res) {}
|
|
17
|
-
function createOne(req, res) {}
|
|
18
|
-
|
|
19
|
-
const with = (fn1, fn2) => {
|
|
20
|
-
const caller = this;
|
|
21
|
-
|
|
22
|
-
// If Async:
|
|
23
|
-
if (fn1.constructor.name === 'AsyncFunction')
|
|
24
|
-
return async (req, res) => {
|
|
25
|
-
await fn1.call(caller, req, res);
|
|
26
|
-
return fn2.call(caller, req, res);
|
|
27
|
-
}
|
|
28
|
-
|
|
29
|
-
// If Sync:
|
|
30
|
-
return (req, res) => {
|
|
31
|
-
fn1.call(caller, req, res);
|
|
32
|
-
return fn2.call(caller, req, res);
|
|
33
|
-
}
|
|
34
|
-
};
|
|
35
|
-
|
|
36
|
-
// Basic example
|
|
37
|
-
module.exports = function OrdersController() {
|
|
38
|
-
withDefaultCRUD(this, {
|
|
39
|
-
model: Order,
|
|
40
|
-
});
|
|
41
|
-
}
|
|
42
|
-
|
|
43
|
-
// Configurable
|
|
44
|
-
module.exports = function OrdersController() {
|
|
45
|
-
withDefaultCRUD(this, {
|
|
46
|
-
model: Order,
|
|
47
|
-
// Optional:
|
|
48
|
-
name: 'OrdersController',
|
|
49
|
-
only: [
|
|
50
|
-
'getOne',
|
|
51
|
-
'getMany'
|
|
52
|
-
]
|
|
53
|
-
});
|
|
54
|
-
};
|
|
55
|
-
|
|
56
|
-
// Or:
|
|
57
|
-
module.exports = function OrdersController() {
|
|
58
|
-
this.model = Order;
|
|
59
|
-
|
|
60
|
-
this.getOne = with(queryPreprocessor, getOne);
|
|
61
|
-
};
|
|
62
|
-
|
package/docs/Queries.md
DELETED
|
@@ -1,61 +0,0 @@
|
|
|
1
|
-
# nodester Queries API
|
|
2
|
-
|
|
3
|
-
## Like value
|
|
4
|
-
|
|
5
|
-
To emulate MySQL's `like %value% ` query in URL,
|
|
6
|
-
pass `?key=like(value)` in the query.
|
|
7
|
-
|
|
8
|
-
* Example:
|
|
9
|
-
`http://localhost:5001/api/v1/countries?name=like(Engl)`
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
## NotLike value
|
|
13
|
-
|
|
14
|
-
* Example:
|
|
15
|
-
`http://localhost:5001/api/v1/countries?name=notLike(Engl)`
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
## Or
|
|
19
|
-
|
|
20
|
-
To emulate MySQL's `where key=value or key=value` query in URL,
|
|
21
|
-
pass `?key=or(value1,value2)` in the query.
|
|
22
|
-
* ! Note: don't use `spaces` between values.
|
|
23
|
-
|
|
24
|
-
* Example:
|
|
25
|
-
`http://localhost:5001/api/v1/countries?name=or(England,Germany)`
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
## Count
|
|
29
|
-
|
|
30
|
-
MySQL's `select count(value)` query is run by default in facade's `getMany` function
|
|
31
|
-
|
|
32
|
-
* Response Example:
|
|
33
|
-
```JSON
|
|
34
|
-
{
|
|
35
|
-
"count": 10,
|
|
36
|
-
"countries": [ ... ],
|
|
37
|
-
"limit": 10,
|
|
38
|
-
"skip": 0,
|
|
39
|
-
"total_count": 195
|
|
40
|
-
}
|
|
41
|
-
```
|
|
42
|
-
|
|
43
|
-
## Order (Sorting)
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
#### Top level
|
|
47
|
-
|
|
48
|
-
`order_by` & `order` arguments can be set in `query`
|
|
49
|
-
`http://localhost:5001/api/v1/countries?order_by=id&order=desc`
|
|
50
|
-
|
|
51
|
-
Above `query` will sort Countries[] by it's id.
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
#### Nested (Includes)
|
|
55
|
-
|
|
56
|
-
`http://localhost:5001/api/v1/countries?includes=cities(order_by=id&order=desc)`
|
|
57
|
-
|
|
58
|
-
Above `query` will sort Cities[] by it's id inside every Country object.
|
|
59
|
-
|
|
60
|
-
It can also do this:
|
|
61
|
-
`http://localhost:5001/api/v1/countries?includes=cities(order_by=id&order=desc).areas`
|
package/docs/Readme.md
DELETED
package/docs/Routing.md
DELETED
|
@@ -1,34 +0,0 @@
|
|
|
1
|
-
# nodester Routing
|
|
2
|
-
|
|
3
|
-
1) Extend default `nodester` router
|
|
4
|
-
```js
|
|
5
|
-
const Router = require('nodester/router');
|
|
6
|
-
|
|
7
|
-
class apiRouter extends Router {
|
|
8
|
-
constructor() {
|
|
9
|
-
super(opts);
|
|
10
|
-
this.add.controllers(<path_to_your_controllers>);
|
|
11
|
-
this.add.controllers(<path_to_your_controllers>, { namespace: 'view' });
|
|
12
|
-
|
|
13
|
-
this.add.routes()
|
|
14
|
-
}
|
|
15
|
-
}
|
|
16
|
-
```
|
|
17
|
-
|
|
18
|
-
Root namespace is named `__root`
|
|
19
|
-
|
|
20
|
-
2) Define routes
|
|
21
|
-
```js
|
|
22
|
-
module.exports = {
|
|
23
|
-
'GET /posts': { controlledBy: 'PostsController.getMany' },
|
|
24
|
-
|
|
25
|
-
// For different namespace:
|
|
26
|
-
'GET /view/posts': { controlledBy: '@view PostsViewController.getMany' },
|
|
27
|
-
// Can also be written as:
|
|
28
|
-
'GET /view/posts': {
|
|
29
|
-
namespace: 'view',
|
|
30
|
-
controller: 'PostsViewController'
|
|
31
|
-
action: 'getMany'
|
|
32
|
-
},
|
|
33
|
-
}
|
|
34
|
-
```
|
package/docs/request-examples.js
DELETED
|
@@ -1,184 +0,0 @@
|
|
|
1
|
-
/posts?in=comments,comments.author,comments.likes.user
|
|
2
|
-
/posts?in=comments(in=author,likes.user)
|
|
3
|
-
|
|
4
|
-
/posts?id=100.0&in=comments(in=author.avatar&order=desc).user,likes&order_by=comments.id
|
|
5
|
-
/posts?id=not(100.0)&&order_by=comments.id
|
|
6
|
-
|
|
7
|
-
/orders?position=1&status=PUBLISHED&in=products(limit=20)
|
|
8
|
-
{
|
|
9
|
-
model: "orders",
|
|
10
|
-
where: {
|
|
11
|
-
and: [
|
|
12
|
-
{
|
|
13
|
-
status: ["PUBLISHED"]
|
|
14
|
-
},
|
|
15
|
-
{
|
|
16
|
-
position: [1]
|
|
17
|
-
}
|
|
18
|
-
]
|
|
19
|
-
},
|
|
20
|
-
includes: [
|
|
21
|
-
{
|
|
22
|
-
model: "products",
|
|
23
|
-
limit: 20,
|
|
24
|
-
skip: 0
|
|
25
|
-
}
|
|
26
|
-
],
|
|
27
|
-
limit: -1,
|
|
28
|
-
skip: 0
|
|
29
|
-
}
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
/orders?in=user(vk_user_id=like(john))&skip=10
|
|
33
|
-
|
|
34
|
-
{
|
|
35
|
-
model: "orders",
|
|
36
|
-
includes: [
|
|
37
|
-
{
|
|
38
|
-
model: "user",
|
|
39
|
-
where: {
|
|
40
|
-
vk_user_id: {
|
|
41
|
-
like: "john"
|
|
42
|
-
}
|
|
43
|
-
},
|
|
44
|
-
limit: -1,
|
|
45
|
-
skip: 0
|
|
46
|
-
}
|
|
47
|
-
],
|
|
48
|
-
limit: -1,
|
|
49
|
-
skip: 10
|
|
50
|
-
}
|
|
51
|
-
|
|
52
|
-
/orders?in=user&or(user.vk_user_id=like(),user.name=like())
|
|
53
|
-
|
|
54
|
-
{
|
|
55
|
-
model: "orders",
|
|
56
|
-
where: {
|
|
57
|
-
or: {
|
|
58
|
-
user.vk_user_id: like(),
|
|
59
|
-
user.name: like()
|
|
60
|
-
}
|
|
61
|
-
}
|
|
62
|
-
}
|
|
63
|
-
|
|
64
|
-
/orders?id=10
|
|
65
|
-
|
|
66
|
-
param: id,
|
|
67
|
-
value: {
|
|
68
|
-
token: 10,
|
|
69
|
-
value: 10
|
|
70
|
-
}
|
|
71
|
-
|
|
72
|
-
{
|
|
73
|
-
model: orders,
|
|
74
|
-
where: {
|
|
75
|
-
id: [10]
|
|
76
|
-
},
|
|
77
|
-
skip: -1,
|
|
78
|
-
limit: 0
|
|
79
|
-
}
|
|
80
|
-
|
|
81
|
-
/orders?id=[10,20]
|
|
82
|
-
|
|
83
|
-
param: id,
|
|
84
|
-
value: {
|
|
85
|
-
token: in,
|
|
86
|
-
value: [10,20]
|
|
87
|
-
}
|
|
88
|
-
|
|
89
|
-
/orders?id=or(10,100)
|
|
90
|
-
|
|
91
|
-
param: id,
|
|
92
|
-
value: {
|
|
93
|
-
token: or,
|
|
94
|
-
value: [10,100)
|
|
95
|
-
}
|
|
96
|
-
|
|
97
|
-
/orders?id=!(10,100)
|
|
98
|
-
|
|
99
|
-
param: id,
|
|
100
|
-
value: {
|
|
101
|
-
token: not,
|
|
102
|
-
value: [10,100)
|
|
103
|
-
}
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
/orders?or(user.name=leo,id=100)&in=user
|
|
107
|
-
|
|
108
|
-
param:
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
{
|
|
112
|
-
where: {
|
|
113
|
-
param: where,
|
|
114
|
-
value: { id: 100 }
|
|
115
|
-
children: {}
|
|
116
|
-
},
|
|
117
|
-
in: {
|
|
118
|
-
param: in
|
|
119
|
-
value: null,
|
|
120
|
-
children: {
|
|
121
|
-
|
|
122
|
-
}
|
|
123
|
-
}
|
|
124
|
-
}
|
|
125
|
-
|
|
126
|
-
{
|
|
127
|
-
param: id
|
|
128
|
-
value: 10
|
|
129
|
-
parent: root
|
|
130
|
-
children: {}
|
|
131
|
-
}
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
/posts?id=100.0&in=comments(in=author.avatar&order=desc).user.followers(id=gt(10)&limit=1),likes&order_by=comments.id
|
|
136
|
-
|
|
137
|
-
{
|
|
138
|
-
model: 'root',
|
|
139
|
-
where: {
|
|
140
|
-
id: [100.0]
|
|
141
|
-
},
|
|
142
|
-
includes: [
|
|
143
|
-
{
|
|
144
|
-
model: 'comments',
|
|
145
|
-
where: {},
|
|
146
|
-
includes: [
|
|
147
|
-
{
|
|
148
|
-
model: 'author',
|
|
149
|
-
where: {},
|
|
150
|
-
includes: [
|
|
151
|
-
{
|
|
152
|
-
model: 'avatar',
|
|
153
|
-
limit: -1,
|
|
154
|
-
skip: 0
|
|
155
|
-
}
|
|
156
|
-
],
|
|
157
|
-
limit: -1,
|
|
158
|
-
skip: 0
|
|
159
|
-
},
|
|
160
|
-
{
|
|
161
|
-
model: 'user',
|
|
162
|
-
includes: [
|
|
163
|
-
{
|
|
164
|
-
model: 'followers',
|
|
165
|
-
where: {
|
|
166
|
-
id: {
|
|
167
|
-
'gt': [10]
|
|
168
|
-
}
|
|
169
|
-
},
|
|
170
|
-
limit: 1,
|
|
171
|
-
skip: 0
|
|
172
|
-
}
|
|
173
|
-
],
|
|
174
|
-
limit: -1,
|
|
175
|
-
skip: 0
|
|
176
|
-
}
|
|
177
|
-
],
|
|
178
|
-
order: 'desc'
|
|
179
|
-
}
|
|
180
|
-
],
|
|
181
|
-
limit: -1,
|
|
182
|
-
skip: 0,
|
|
183
|
-
order_by: 'comments.id'
|
|
184
|
-
}
|
package/examples/goal/index.js
DELETED
|
@@ -1,23 +0,0 @@
|
|
|
1
|
-
const nodester = require('nodester');
|
|
2
|
-
const db = require('#db');
|
|
3
|
-
|
|
4
|
-
// Init.
|
|
5
|
-
const app = new nodester();
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
app.set.database(db);
|
|
9
|
-
|
|
10
|
-
app.extend('static')
|
|
11
|
-
|
|
12
|
-
app.static(<path/>);
|
|
13
|
-
|
|
14
|
-
// Markers.
|
|
15
|
-
app.add.marker('admin', (req)=>req.token.role === 'admin');
|
|
16
|
-
|
|
17
|
-
// Using Markers.
|
|
18
|
-
app.only('admin')
|
|
19
|
-
.route('get /payments', (req, res, next) => {});
|
|
20
|
-
|
|
21
|
-
app.listen(8080, function() {
|
|
22
|
-
console.log('listening on port', app.port);
|
|
23
|
-
});
|
|
@@ -1,15 +0,0 @@
|
|
|
1
|
-
|
|
2
|
-
function OrdersController() {
|
|
3
|
-
|
|
4
|
-
this.getMany = function(req, res) {
|
|
5
|
-
console.log({ query: req.query });
|
|
6
|
-
res.json({ controller: 'OrdersController', method: 'getMany' });
|
|
7
|
-
}
|
|
8
|
-
|
|
9
|
-
this.getOne = function(req, res) {
|
|
10
|
-
const { params } = req;
|
|
11
|
-
res.json({ controller: 'OrdersController', method: 'getOne', params });
|
|
12
|
-
}
|
|
13
|
-
}
|
|
14
|
-
|
|
15
|
-
module.exports = new OrdersController();
|
package/examples/rest/index.js
DELETED
|
@@ -1,45 +0,0 @@
|
|
|
1
|
-
'use strict'
|
|
2
|
-
|
|
3
|
-
const nodester = require('nodester');
|
|
4
|
-
const router = require('./router');
|
|
5
|
-
|
|
6
|
-
// Init.
|
|
7
|
-
const app = new nodester();
|
|
8
|
-
|
|
9
|
-
// app.setDatabase();
|
|
10
|
-
// app.set('database');
|
|
11
|
-
|
|
12
|
-
app.use(router());
|
|
13
|
-
|
|
14
|
-
// app.add.marker('GET_M', (req)=>req.method === 'GET');
|
|
15
|
-
|
|
16
|
-
// app.only('GET_M').use(async (req, res) => {
|
|
17
|
-
// res.json(req.nquery);
|
|
18
|
-
// });
|
|
19
|
-
|
|
20
|
-
// app.use((req, res)=>res.json({ msg: 'last' }));
|
|
21
|
-
|
|
22
|
-
// app.only('GET_M').route('get /orders', async (req, res) => {
|
|
23
|
-
// res.json({ route: 'orders' });
|
|
24
|
-
// });
|
|
25
|
-
|
|
26
|
-
// app.add.middleware((req, res, next)=>{
|
|
27
|
-
// console.log('1st', 'hello!');
|
|
28
|
-
// next();
|
|
29
|
-
// });
|
|
30
|
-
|
|
31
|
-
// app.add.middleware((req, res, next)=>{
|
|
32
|
-
// console.log('Last!');
|
|
33
|
-
|
|
34
|
-
// res.setHeader("Content-type", "text/html");
|
|
35
|
-
// res.write("Hello!<br/>...my friend");
|
|
36
|
-
// res.end();
|
|
37
|
-
// });
|
|
38
|
-
|
|
39
|
-
app.beforeStart(()=>{
|
|
40
|
-
console.log('Before start passed!');
|
|
41
|
-
});
|
|
42
|
-
|
|
43
|
-
app.listen(8080, function() {
|
|
44
|
-
console.log('listening on port', app.port);
|
|
45
|
-
});
|
|
@@ -1,42 +0,0 @@
|
|
|
1
|
-
{
|
|
2
|
-
"name": "nodester-example-rest",
|
|
3
|
-
"version": "1.0.0",
|
|
4
|
-
"lockfileVersion": 2,
|
|
5
|
-
"requires": true,
|
|
6
|
-
"packages": {
|
|
7
|
-
"../..": {
|
|
8
|
-
"version": "0.0.1",
|
|
9
|
-
"license": "MIT",
|
|
10
|
-
"dependencies": {
|
|
11
|
-
"accepts": "^1.3.8",
|
|
12
|
-
"content-disposition": "^0.5.4",
|
|
13
|
-
"content-type": "^1.0.5",
|
|
14
|
-
"cookie": "^0.5.0",
|
|
15
|
-
"cookie-signature": "^1.2.0",
|
|
16
|
-
"debug": "^4.3.4",
|
|
17
|
-
"finalhandler": "^1.2.0",
|
|
18
|
-
"formidable": "^1.2.6",
|
|
19
|
-
"fresh": "^0.5.2",
|
|
20
|
-
"http-errors": "^2.0.0",
|
|
21
|
-
"inflection": "^2.0.1",
|
|
22
|
-
"proxy-addr": "^2.0.7",
|
|
23
|
-
"qs": "^6.11.0",
|
|
24
|
-
"range-parser": "^1.2.1",
|
|
25
|
-
"send": "^0.18.0",
|
|
26
|
-
"sequelize": "^6.6.5",
|
|
27
|
-
"type-is": "^1.6.18",
|
|
28
|
-
"vary": "^1.1.2"
|
|
29
|
-
},
|
|
30
|
-
"devDependencies": {
|
|
31
|
-
"jest": "^29.4.2"
|
|
32
|
-
},
|
|
33
|
-
"engines": {
|
|
34
|
-
"node": ">= 12.17.0"
|
|
35
|
-
}
|
|
36
|
-
},
|
|
37
|
-
"node_modules/nodester": {
|
|
38
|
-
"resolved": "../..",
|
|
39
|
-
"link": true
|
|
40
|
-
}
|
|
41
|
-
}
|
|
42
|
-
}
|
|
@@ -1,14 +0,0 @@
|
|
|
1
|
-
{
|
|
2
|
-
"name": "nodester-example-rest",
|
|
3
|
-
"version": "1.0.0",
|
|
4
|
-
"description": "",
|
|
5
|
-
"main": "index.js",
|
|
6
|
-
"scripts": {
|
|
7
|
-
"test": "echo \"Error: no test specified\" && exit 1"
|
|
8
|
-
},
|
|
9
|
-
"author": "Mark Khramko",
|
|
10
|
-
"license": "MIT",
|
|
11
|
-
"dependencies": {
|
|
12
|
-
"nodester": "file:../../"
|
|
13
|
-
}
|
|
14
|
-
}
|
|
@@ -1,15 +0,0 @@
|
|
|
1
|
-
|
|
2
|
-
module.exports = function OrdersQueryPreprocessor(opts={}) {
|
|
3
|
-
return handle.bind(this);
|
|
4
|
-
}
|
|
5
|
-
|
|
6
|
-
async function handle(nquery, req, res) {
|
|
7
|
-
console.log("was called", { nquery });
|
|
8
|
-
|
|
9
|
-
// Get role or set "visitor".
|
|
10
|
-
// const _role = typeof role === 'string' && role.length > 1 ? role : VISITOR;
|
|
11
|
-
|
|
12
|
-
// const policy = this.policies[_role];
|
|
13
|
-
|
|
14
|
-
// const resultQuery = await traverse(nquery, policy, this.model);
|
|
15
|
-
}
|
package/examples/rest/router.js
DELETED
|
@@ -1,23 +0,0 @@
|
|
|
1
|
-
'use strict'
|
|
2
|
-
|
|
3
|
-
const Router = require('nodester/router');
|
|
4
|
-
// Preprocessors:
|
|
5
|
-
const preprocessOrdersQuery = require('./preprocessors/queries/orders.queries');
|
|
6
|
-
// Utils.
|
|
7
|
-
const Path = require('path');
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
module.exports = function initRouter() {
|
|
11
|
-
const controllersPath = Path.join(__dirname, 'controllers');
|
|
12
|
-
const router = new Router({ controllersPath });
|
|
13
|
-
|
|
14
|
-
// router.add.route('get /orders', async (req, res) => {
|
|
15
|
-
// res.json({ route: 'orders' });
|
|
16
|
-
// });
|
|
17
|
-
|
|
18
|
-
router.add.route('get /orders', { before: preprocessOrdersQuery(), controlledBy: 'orders.getMany' });
|
|
19
|
-
router.add.route('get /orders/*', { controlledBy: 'orders.getMany' });
|
|
20
|
-
router.add.route('get /orders/:id', { controlledBy: 'orders.getOne' });
|
|
21
|
-
|
|
22
|
-
return router.handle.bind(router);
|
|
23
|
-
}
|