express-speed 1.0.5 → 1.0.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/README.md +48 -101
- package/package.json +1 -1
- package/src/expressSpeed.js +3 -34
- package/src/pager.d.ts +47 -0
- package/src/pager.js +20 -92
package/README.md
CHANGED
|
@@ -23,8 +23,6 @@ npm install express-speed
|
|
|
23
23
|
|
|
24
24
|
## Basic Usage
|
|
25
25
|
|
|
26
|
-
Creating a simple page:
|
|
27
|
-
|
|
28
26
|
```js
|
|
29
27
|
import { pager } from "express-speed";
|
|
30
28
|
|
|
@@ -41,7 +39,7 @@ export default page;
|
|
|
41
39
|
|
|
42
40
|
---
|
|
43
41
|
|
|
44
|
-
## Multiple
|
|
42
|
+
## Multiple Handlers
|
|
45
43
|
|
|
46
44
|
You can define multiple handlers for the same route.
|
|
47
45
|
|
|
@@ -60,32 +58,26 @@ export default pager
|
|
|
60
58
|
.build();
|
|
61
59
|
```
|
|
62
60
|
|
|
63
|
-
This pattern works in line with Express middleware logic.
|
|
64
|
-
|
|
65
61
|
---
|
|
66
62
|
|
|
67
63
|
## Sub Path Routes
|
|
68
64
|
|
|
69
|
-
Use `get(path, handler)` to create different endpoints within the same pager.
|
|
65
|
+
Use `get(path, handler)` to create different endpoints within the same pager.
|
|
70
66
|
|
|
71
67
|
```js
|
|
72
68
|
import { pager } from "express-speed";
|
|
73
69
|
|
|
74
70
|
export default pager
|
|
75
71
|
.url("/blog")
|
|
76
|
-
|
|
77
72
|
.get((req, res) => {
|
|
78
73
|
res.send("Blog Home");
|
|
79
74
|
})
|
|
80
|
-
|
|
81
75
|
.get("/blog/post/:id", (req, res) => {
|
|
82
76
|
res.send(`Post ${req.params.id}`);
|
|
83
77
|
})
|
|
84
|
-
|
|
85
78
|
.get("/blog/latest", (req, res) => {
|
|
86
79
|
res.send("Latest posts");
|
|
87
80
|
})
|
|
88
|
-
|
|
89
81
|
.build();
|
|
90
82
|
```
|
|
91
83
|
|
|
@@ -101,8 +93,6 @@ Generated routes:
|
|
|
101
93
|
|
|
102
94
|
## Middleware Usage
|
|
103
95
|
|
|
104
|
-
You can add middleware inside a pager.
|
|
105
|
-
|
|
106
96
|
```js
|
|
107
97
|
import { pager } from "express-speed";
|
|
108
98
|
|
|
@@ -124,8 +114,6 @@ export default pager
|
|
|
124
114
|
|
|
125
115
|
## Role Based Access
|
|
126
116
|
|
|
127
|
-
Restrict page access using roles.
|
|
128
|
-
|
|
129
117
|
```js
|
|
130
118
|
import { pager } from "express-speed";
|
|
131
119
|
|
|
@@ -140,38 +128,68 @@ export default pager
|
|
|
140
128
|
|
|
141
129
|
---
|
|
142
130
|
|
|
143
|
-
##
|
|
144
|
-
|
|
145
|
-
Pager can also be used for API endpoints.
|
|
131
|
+
## Router Style Usage
|
|
146
132
|
|
|
147
133
|
```js
|
|
148
134
|
import { pager } from "express-speed";
|
|
149
135
|
|
|
150
136
|
export default pager
|
|
151
|
-
.url("/api
|
|
152
|
-
.get((req, res) => {
|
|
153
|
-
res.json(
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
137
|
+
.url("/api")
|
|
138
|
+
.get("/users", (req, res) => {
|
|
139
|
+
res.json(["user1", "user2"]);
|
|
140
|
+
})
|
|
141
|
+
.get("/products", (req, res) => {
|
|
142
|
+
res.json(["product1", "product2"]);
|
|
157
143
|
})
|
|
158
144
|
.build();
|
|
159
145
|
```
|
|
160
146
|
|
|
161
147
|
---
|
|
162
148
|
|
|
163
|
-
##
|
|
149
|
+
## expressSpeed.listen
|
|
150
|
+
|
|
151
|
+
`expressSpeed.listen` starts the server and loads all pages automatically using glob patterns.
|
|
152
|
+
|
|
153
|
+
```js
|
|
154
|
+
import { expressSpeed } from "express-speed";
|
|
155
|
+
|
|
156
|
+
expressSpeed.listen(80, {
|
|
157
|
+
page: {
|
|
158
|
+
render: ["./page/**/*.js"],
|
|
159
|
+
exclude: [],
|
|
160
|
+
nodir: true,
|
|
161
|
+
},
|
|
162
|
+
use: [
|
|
163
|
+
(req, res, next) => {
|
|
164
|
+
console.log("request received");
|
|
165
|
+
next();
|
|
166
|
+
},
|
|
167
|
+
],
|
|
168
|
+
settings: {
|
|
169
|
+
"view engine": "pug",
|
|
170
|
+
views: "./pug",
|
|
171
|
+
},
|
|
172
|
+
});
|
|
173
|
+
```
|
|
174
|
+
|
|
175
|
+
### Options
|
|
164
176
|
|
|
165
|
-
|
|
177
|
+
| Key | Type | Description |
|
|
178
|
+
|-----|------|-------------|
|
|
179
|
+
| `page.render` | `string[]` | Glob patterns to match page files |
|
|
180
|
+
| `page.exclude` | `string[]` | Glob patterns to exclude |
|
|
181
|
+
| `page.nodir` | `boolean` | Skip directories |
|
|
182
|
+
| `use` | `function[]` | Global middleware applied to all routes |
|
|
183
|
+
| `settings` | `object` | Express app settings (`view engine`, `views`, etc.) |
|
|
184
|
+
|
|
185
|
+
---
|
|
166
186
|
|
|
167
|
-
|
|
187
|
+
## GraphQL Integration
|
|
168
188
|
|
|
169
189
|
```bash
|
|
170
190
|
npm install express-graphql graphql
|
|
171
191
|
```
|
|
172
192
|
|
|
173
|
-
### Basic GraphQL Example
|
|
174
|
-
|
|
175
193
|
```js
|
|
176
194
|
import { pager } from "express-speed";
|
|
177
195
|
import { graphqlHTTP } from "express-graphql";
|
|
@@ -199,76 +217,6 @@ export default pager
|
|
|
199
217
|
.build();
|
|
200
218
|
```
|
|
201
219
|
|
|
202
|
-
### GraphQLObjectType Schema Example
|
|
203
|
-
|
|
204
|
-
`express-speed` also supports the classic GraphQL schema structure.
|
|
205
|
-
|
|
206
|
-
```js
|
|
207
|
-
import { pager } from "express-speed";
|
|
208
|
-
import { graphqlHTTP } from "express-graphql";
|
|
209
|
-
import { GraphQLObjectType, GraphQLString, GraphQLSchema } from "graphql";
|
|
210
|
-
|
|
211
|
-
const UserType = new GraphQLObjectType({
|
|
212
|
-
name: "User",
|
|
213
|
-
fields: {
|
|
214
|
-
name: { type: GraphQLString },
|
|
215
|
-
surname: { type: GraphQLString },
|
|
216
|
-
},
|
|
217
|
-
});
|
|
218
|
-
|
|
219
|
-
const RootQuery = new GraphQLObjectType({
|
|
220
|
-
name: "RootQueryType",
|
|
221
|
-
fields: {
|
|
222
|
-
user: {
|
|
223
|
-
type: UserType,
|
|
224
|
-
resolve() {
|
|
225
|
-
return {
|
|
226
|
-
name: "Ali",
|
|
227
|
-
surname: "Yılmaz",
|
|
228
|
-
};
|
|
229
|
-
},
|
|
230
|
-
},
|
|
231
|
-
},
|
|
232
|
-
});
|
|
233
|
-
|
|
234
|
-
const schema = new GraphQLSchema({
|
|
235
|
-
query: RootQuery,
|
|
236
|
-
});
|
|
237
|
-
|
|
238
|
-
export default pager
|
|
239
|
-
.url("/graphql")
|
|
240
|
-
.use(
|
|
241
|
-
graphqlHTTP({
|
|
242
|
-
schema: schema,
|
|
243
|
-
graphiql: true,
|
|
244
|
-
}),
|
|
245
|
-
)
|
|
246
|
-
.build();
|
|
247
|
-
```
|
|
248
|
-
|
|
249
|
-
---
|
|
250
|
-
|
|
251
|
-
## Router Style Usage
|
|
252
|
-
|
|
253
|
-
Pager can be used like a mini router.
|
|
254
|
-
|
|
255
|
-
```js
|
|
256
|
-
import { pager } from "express-speed";
|
|
257
|
-
|
|
258
|
-
export default pager
|
|
259
|
-
.url("/api")
|
|
260
|
-
|
|
261
|
-
.get("/users", (req, res) => {
|
|
262
|
-
res.json(["user1", "user2"]);
|
|
263
|
-
})
|
|
264
|
-
|
|
265
|
-
.get("/products", (req, res) => {
|
|
266
|
-
res.json(["product1", "product2"]);
|
|
267
|
-
})
|
|
268
|
-
|
|
269
|
-
.build();
|
|
270
|
-
```
|
|
271
|
-
|
|
272
220
|
---
|
|
273
221
|
|
|
274
222
|
## Features
|
|
@@ -278,7 +226,6 @@ export default pager
|
|
|
278
226
|
- Role based access control
|
|
279
227
|
- Multiple route handlers
|
|
280
228
|
- Sub path routing
|
|
229
|
+
- Global middleware and settings via `listen`
|
|
281
230
|
- GraphQL integration
|
|
282
|
-
- API and page route support
|
|
283
|
-
|
|
284
|
-
---
|
|
231
|
+
- API and page route support
|
package/package.json
CHANGED
package/src/expressSpeed.js
CHANGED
|
@@ -1,7 +1,6 @@
|
|
|
1
1
|
// * ExpressSpeed mvc yapısına uygun daha hızlı şekilde kullanılabilir formatta
|
|
2
2
|
// * Sayfalara özel Rol kontrol özelliği
|
|
3
3
|
// * Graphql Uyumlu
|
|
4
|
-
|
|
5
4
|
import express from "express";
|
|
6
5
|
import { globSync } from "glob";
|
|
7
6
|
import pager from "./pager.js";
|
|
@@ -20,12 +19,6 @@ let expressSpeed = {
|
|
|
20
19
|
use: [],
|
|
21
20
|
settings: {},
|
|
22
21
|
},
|
|
23
|
-
trigger: {
|
|
24
|
-
start: {
|
|
25
|
-
},
|
|
26
|
-
end: {
|
|
27
|
-
}
|
|
28
|
-
},
|
|
29
22
|
complier: {
|
|
30
23
|
pagesMap(renderPathArrayValue, pageExcludeArrayValue, nodirBooleanValue) {
|
|
31
24
|
const pageFiles = renderPathArrayValue.flatMap((pathValue) =>
|
|
@@ -56,31 +49,8 @@ let expressSpeed = {
|
|
|
56
49
|
const app = expressSpeed.app;
|
|
57
50
|
for (const router of pageObjectValue.methods) {
|
|
58
51
|
let parameters = ("string" == typeof router.parameters[0]) ? [...router.parameters] : [router.url, ...router.parameters];
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
app.use(...parameters);
|
|
62
|
-
break;
|
|
63
|
-
case "all":
|
|
64
|
-
app.all(...parameters);
|
|
65
|
-
break;
|
|
66
|
-
case "param":
|
|
67
|
-
app.param(...parameters);
|
|
68
|
-
break;
|
|
69
|
-
case "get":
|
|
70
|
-
app.get(...parameters);
|
|
71
|
-
break;
|
|
72
|
-
case "post":
|
|
73
|
-
app.post(...parameters);
|
|
74
|
-
break;
|
|
75
|
-
case "put":
|
|
76
|
-
app.put(...parameters);
|
|
77
|
-
break;
|
|
78
|
-
case "delete":
|
|
79
|
-
app.delete(...parameters);
|
|
80
|
-
break;
|
|
81
|
-
|
|
82
|
-
default:
|
|
83
|
-
break;
|
|
52
|
+
if (app[router.method.toString().toLowerCase()]) {
|
|
53
|
+
app[router.method.toString().toLowerCase()](...parameters)
|
|
84
54
|
}
|
|
85
55
|
}
|
|
86
56
|
},
|
|
@@ -102,8 +72,6 @@ let expressSpeed = {
|
|
|
102
72
|
}) {
|
|
103
73
|
if (typeof config.go == "function") config.go(expressSpeed);
|
|
104
74
|
config.port = port;
|
|
105
|
-
if (typeof config == "object") {
|
|
106
|
-
}
|
|
107
75
|
expressSpeed.config.path.page = {
|
|
108
76
|
...expressSpeed.config.path.page,
|
|
109
77
|
...config.page
|
|
@@ -117,6 +85,7 @@ let expressSpeed = {
|
|
|
117
85
|
},
|
|
118
86
|
}
|
|
119
87
|
|
|
88
|
+
|
|
120
89
|
expressSpeed.pager = pager;
|
|
121
90
|
|
|
122
91
|
export default expressSpeed;
|
package/src/pager.d.ts
ADDED
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
type MethodHandler = (...args: any[]) => typeof pager;
|
|
2
|
+
|
|
3
|
+
declare const pager: {
|
|
4
|
+
_id: number;
|
|
5
|
+
_config: {
|
|
6
|
+
url: string | null;
|
|
7
|
+
role: string | string[] | null;
|
|
8
|
+
usings: any[] | null;
|
|
9
|
+
methods: Array<{ url: string, method: string, parameters: any[] }>;
|
|
10
|
+
};
|
|
11
|
+
url(value: string): typeof pager;
|
|
12
|
+
role(value: string | string[]): typeof pager;
|
|
13
|
+
usings(value: any[]): typeof pager;
|
|
14
|
+
build(): object;
|
|
15
|
+
|
|
16
|
+
// Standart
|
|
17
|
+
use: MethodHandler;
|
|
18
|
+
param: MethodHandler;
|
|
19
|
+
all: MethodHandler;
|
|
20
|
+
get: MethodHandler;
|
|
21
|
+
post: MethodHandler;
|
|
22
|
+
put: MethodHandler;
|
|
23
|
+
delete: MethodHandler;
|
|
24
|
+
patch: MethodHandler;
|
|
25
|
+
head: MethodHandler;
|
|
26
|
+
options: MethodHandler;
|
|
27
|
+
// WebDAV
|
|
28
|
+
checkout: MethodHandler;
|
|
29
|
+
copy: MethodHandler;
|
|
30
|
+
lock: MethodHandler;
|
|
31
|
+
merge: MethodHandler;
|
|
32
|
+
mkactivity: MethodHandler;
|
|
33
|
+
mkcol: MethodHandler;
|
|
34
|
+
move: MethodHandler;
|
|
35
|
+
notify: MethodHandler;
|
|
36
|
+
propfind: MethodHandler;
|
|
37
|
+
proppatch: MethodHandler;
|
|
38
|
+
purge: MethodHandler;
|
|
39
|
+
report: MethodHandler;
|
|
40
|
+
search: MethodHandler;
|
|
41
|
+
subscribe: MethodHandler;
|
|
42
|
+
trace: MethodHandler;
|
|
43
|
+
unlock: MethodHandler;
|
|
44
|
+
unsubscribe: MethodHandler;
|
|
45
|
+
};
|
|
46
|
+
|
|
47
|
+
export default pager;
|
package/src/pager.js
CHANGED
|
@@ -1,4 +1,11 @@
|
|
|
1
|
-
|
|
1
|
+
const HTTP_METHODS = [
|
|
2
|
+
"use", "param", "all",
|
|
3
|
+
"get", "post", "put", "delete", "patch", "head", "options",
|
|
4
|
+
"checkout", "copy", "lock", "merge", "mkactivity",
|
|
5
|
+
"mkcol", "move", "notify", "propfind", "proppatch",
|
|
6
|
+
"purge", "report", "search", "subscribe", "trace",
|
|
7
|
+
"unlock", "unsubscribe"
|
|
8
|
+
];
|
|
2
9
|
|
|
3
10
|
const pager = {
|
|
4
11
|
_id: 0,
|
|
@@ -7,17 +14,6 @@ const pager = {
|
|
|
7
14
|
role: null,
|
|
8
15
|
usings: null,
|
|
9
16
|
methods: [],
|
|
10
|
-
// method: {
|
|
11
|
-
// use: null,
|
|
12
|
-
// all: null,
|
|
13
|
-
// param: null,
|
|
14
|
-
// get: null,
|
|
15
|
-
// post: null,
|
|
16
|
-
// put: null,
|
|
17
|
-
// delete: null,
|
|
18
|
-
// },
|
|
19
|
-
render: null,
|
|
20
|
-
renderConfig: null,
|
|
21
17
|
},
|
|
22
18
|
url(urlStringValue) {
|
|
23
19
|
pager._config.url = urlStringValue;
|
|
@@ -31,74 +27,6 @@ const pager = {
|
|
|
31
27
|
pager._config.usings = usingsArrayValue;
|
|
32
28
|
return pager;
|
|
33
29
|
},
|
|
34
|
-
use(...useVariableValue) {
|
|
35
|
-
pager._config.methods.push({
|
|
36
|
-
url: pager._config.url,
|
|
37
|
-
method: "use",
|
|
38
|
-
parameters: [...useVariableValue],
|
|
39
|
-
});
|
|
40
|
-
// ? delete pager.url;
|
|
41
|
-
return pager;
|
|
42
|
-
},
|
|
43
|
-
param(...paramVariableValue) {
|
|
44
|
-
pager._config.methods.push({
|
|
45
|
-
url: pager._config.url,
|
|
46
|
-
method: "param",
|
|
47
|
-
parameters: [...paramVariableValue],
|
|
48
|
-
});
|
|
49
|
-
// ? delete pager.url;
|
|
50
|
-
return pager;
|
|
51
|
-
},
|
|
52
|
-
all(...allFunctionValue) {
|
|
53
|
-
pager._config.methods.push({
|
|
54
|
-
url: pager._config.url,
|
|
55
|
-
method: "all",
|
|
56
|
-
parameters: [...allFunctionValue],
|
|
57
|
-
});
|
|
58
|
-
// ? delete pager.url;
|
|
59
|
-
return pager;
|
|
60
|
-
},
|
|
61
|
-
get(...getFunctionValue) {
|
|
62
|
-
pager._config.methods.push({
|
|
63
|
-
url: pager._config.url,
|
|
64
|
-
method: "get",
|
|
65
|
-
parameters: [...getFunctionValue],
|
|
66
|
-
});
|
|
67
|
-
// ? delete pager.url;
|
|
68
|
-
return pager;
|
|
69
|
-
},
|
|
70
|
-
post(...postFunctionValue) {
|
|
71
|
-
pager._config.methods.push({
|
|
72
|
-
url: pager._config.url,
|
|
73
|
-
method: "post",
|
|
74
|
-
parameters: [...postFunctionValue],
|
|
75
|
-
});
|
|
76
|
-
// ? delete pager.url;
|
|
77
|
-
return pager;
|
|
78
|
-
},
|
|
79
|
-
put(...putFunctionValue) {
|
|
80
|
-
pager._config.methods.push({
|
|
81
|
-
url: pager._config.url,
|
|
82
|
-
method: "put",
|
|
83
|
-
parameters: [...putFunctionValue],
|
|
84
|
-
});
|
|
85
|
-
// ? delete pager.url;
|
|
86
|
-
return pager;
|
|
87
|
-
},
|
|
88
|
-
delete(...deleteFunctionValue) {
|
|
89
|
-
pager._config.methods.push({
|
|
90
|
-
url: pager._config.url,
|
|
91
|
-
method: "delete",
|
|
92
|
-
parameters: [...deleteFunctionValue],
|
|
93
|
-
});
|
|
94
|
-
// ? delete pager.url;
|
|
95
|
-
return pager;
|
|
96
|
-
},
|
|
97
|
-
// render(renderStringValue, renderObjectConfiguration = {}) {
|
|
98
|
-
// pager._config.render = renderStringValue;
|
|
99
|
-
// pager._config.renderConfig = renderObjectConfiguration;
|
|
100
|
-
// return pager;
|
|
101
|
-
// },
|
|
102
30
|
build() {
|
|
103
31
|
const data = { ...pager._config }
|
|
104
32
|
pager._config = {
|
|
@@ -107,20 +35,20 @@ const pager = {
|
|
|
107
35
|
usings: [],
|
|
108
36
|
settings: [],
|
|
109
37
|
methods: [],
|
|
110
|
-
// method: {
|
|
111
|
-
// use: null,
|
|
112
|
-
// all: null,
|
|
113
|
-
// param: null,
|
|
114
|
-
// get: null,
|
|
115
|
-
// post: null,
|
|
116
|
-
// put: null,
|
|
117
|
-
// delete: null,
|
|
118
|
-
// },
|
|
119
|
-
render: null,
|
|
120
|
-
renderConfig: null,
|
|
121
38
|
};
|
|
122
39
|
return data;
|
|
123
40
|
},
|
|
124
|
-
}
|
|
41
|
+
};
|
|
42
|
+
|
|
43
|
+
HTTP_METHODS.forEach(method => {
|
|
44
|
+
pager[method] = (...args) => {
|
|
45
|
+
pager._config.methods.push({
|
|
46
|
+
url: pager._config.url,
|
|
47
|
+
method,
|
|
48
|
+
parameters: [...args],
|
|
49
|
+
});
|
|
50
|
+
return pager;
|
|
51
|
+
};
|
|
52
|
+
});
|
|
125
53
|
|
|
126
54
|
export default pager;
|