express-speed 1.0.1

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/LICENSE ADDED
@@ -0,0 +1,23 @@
1
+ MIT License + Trademark Notice
2
+
3
+ Copyright (c) 2026 F10tme
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ 1. The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ 2. The software is provided "AS IS", without warranty of any kind.
16
+
17
+ ---
18
+
19
+ Trademark Notice:
20
+
21
+ The name "express-speed" and its logo (if any) are registered trademarks of the author.
22
+ No one is allowed to use the "express-speed" name or logo for derivative works,
23
+ forks, or other projects without the explicit permission of the author.
package/README.md ADDED
@@ -0,0 +1,286 @@
1
+ # express-speed
2
+
3
+ `express-speed` Express uygulamalarında route oluşturmayı daha düzenli ve zincirleme (chainable) hale getiren basit bir pager sistemidir.
4
+
5
+ Amaç:
6
+
7
+ - Route tanımlamayı sadeleştirmek
8
+ - Sayfaları modüler hale getirmek
9
+ - Middleware ve rol kontrolünü kolaylaştırmak
10
+ - API ve sayfa route'larını aynı yapı içinde yönetmek
11
+
12
+ ---
13
+
14
+ # Installation
15
+
16
+ ```bash
17
+ npm install express-speed
18
+ ```
19
+
20
+ ---
21
+
22
+ # Basic Usage
23
+
24
+ Basit bir sayfa oluşturma:
25
+
26
+ ```js
27
+ import { pager } from "express-speed";
28
+
29
+ let page = pager
30
+ .url("/")
31
+ .role("user")
32
+ .get((req, res) => {
33
+ res.send("Simple Page");
34
+ })
35
+ .build();
36
+
37
+ export default page;
38
+ ```
39
+
40
+ ---
41
+
42
+ # Multiple GET Handlers
43
+
44
+ Aynı route içinde birden fazla handler tanımlayabilirsin.
45
+
46
+ ```js
47
+ import { pager } from "express-speed";
48
+
49
+ export default pager
50
+ .url("/example")
51
+ .get((req, res, next) => {
52
+ console.log("first handler");
53
+ next();
54
+ })
55
+ .get((req, res) => {
56
+ res.send("final response");
57
+ })
58
+ .build();
59
+ ```
60
+
61
+ Bu yapı Express middleware mantığıyla çalışır.
62
+
63
+ ---
64
+
65
+ # Sub Path Routes
66
+
67
+ `get(path, handler)` kullanarak aynı pager içinde farklı endpointler oluşturabilirsin.
68
+
69
+ ```js
70
+ import { pager } from "express-speed";
71
+
72
+ export default pager
73
+ .url("/blog")
74
+
75
+ .get((req, res) => {
76
+ res.send("Blog Home");
77
+ })
78
+
79
+ .get("/post/:id", (req, res) => {
80
+ res.send(`Post ${req.params.id}`);
81
+ })
82
+
83
+ .get("/latest", (req, res) => {
84
+ res.send("Latest posts");
85
+ })
86
+
87
+ .build();
88
+ ```
89
+
90
+ Oluşan route'lar:
91
+
92
+ ```
93
+ /blog
94
+ /blog/post/:id
95
+ /blog/latest
96
+ ```
97
+
98
+ ---
99
+
100
+ # Middleware Usage
101
+
102
+ Pager içine middleware ekleyebilirsin.
103
+
104
+ ```js
105
+ import { pager } from "express-speed";
106
+
107
+ function logger(req, res, next) {
108
+ console.log("page visited");
109
+ next();
110
+ }
111
+
112
+ export default pager
113
+ .url("/profile")
114
+ .use(logger)
115
+ .get((req, res) => {
116
+ res.send("Profile page");
117
+ })
118
+ .build();
119
+ ```
120
+
121
+ ---
122
+
123
+ # Role Based Access
124
+
125
+ Role kullanarak sayfaya erişimi sınırlandırabilirsin.
126
+
127
+ ```js
128
+ import { pager } from "express-speed";
129
+
130
+ export default pager
131
+ .url("/admin")
132
+ .role("admin")
133
+ .get((req, res) => {
134
+ res.send("Admin Panel");
135
+ })
136
+ .build();
137
+ ```
138
+
139
+ ---
140
+
141
+ # API Endpoint Example
142
+
143
+ Pager API endpointleri için de kullanılabilir.
144
+
145
+ ```js
146
+ import { pager } from "express-speed";
147
+
148
+ export default pager
149
+ .url("/api/user")
150
+ .get((req, res) => {
151
+ res.json({
152
+ name: "Murat",
153
+ role: "user",
154
+ });
155
+ })
156
+ .build();
157
+ ```
158
+
159
+ ---
160
+
161
+ # GraphQL Integration
162
+
163
+ `express-speed` GraphQL endpointlerini de destekler.
164
+
165
+ Bunun için projede şu paketler kurulu olmalıdır:
166
+
167
+ ```bash
168
+ npm install express-graphql graphql
169
+ ```
170
+
171
+ ---
172
+
173
+ ## Basic GraphQL Example
174
+
175
+ ```js
176
+ import { pager } from "express-speed";
177
+ import { graphqlHTTP } from "express-graphql";
178
+ import { buildSchema } from "graphql";
179
+
180
+ const schema = buildSchema(`
181
+ type Query {
182
+ hello: String
183
+ }
184
+ `);
185
+
186
+ const root = {
187
+ hello: () => "Hello GraphQL",
188
+ };
189
+
190
+ export default pager
191
+ .url("/graphql")
192
+ .use(
193
+ graphqlHTTP({
194
+ schema,
195
+ rootValue: root,
196
+ graphiql: true,
197
+ }),
198
+ )
199
+ .build();
200
+ ```
201
+
202
+ ---
203
+
204
+ ## GraphQLObjectType Schema Example
205
+
206
+ `express-speed` ayrıca klasik GraphQL schema yapısını da destekler.
207
+
208
+ ```js
209
+ import { pager } from "express-speed";
210
+ import { graphqlHTTP } from "express-graphql";
211
+ import { GraphQLObjectType, GraphQLString, GraphQLSchema } from "graphql";
212
+
213
+ const UserType = new GraphQLObjectType({
214
+ name: "User",
215
+ fields: {
216
+ name: { type: GraphQLString },
217
+ surname: { type: GraphQLString },
218
+ },
219
+ });
220
+
221
+ const RootQuery = new GraphQLObjectType({
222
+ name: "RootQueryType",
223
+ fields: {
224
+ user: {
225
+ type: UserType,
226
+ resolve() {
227
+ return {
228
+ name: "Ali",
229
+ surname: "Yılmaz",
230
+ };
231
+ },
232
+ },
233
+ },
234
+ });
235
+
236
+ const schema = new GraphQLSchema({
237
+ query: RootQuery,
238
+ });
239
+
240
+ export default pager
241
+ .url("/graphql")
242
+ .use(
243
+ graphqlHTTP({
244
+ schema: schema,
245
+ graphiql: true,
246
+ }),
247
+ )
248
+ .build();
249
+ ```
250
+
251
+ ---
252
+
253
+ # Router Style Usage
254
+
255
+ Pager küçük bir router gibi kullanılabilir.
256
+
257
+ ```js
258
+ import { pager } from "express-speed";
259
+
260
+ export default pager
261
+ .url("/api")
262
+
263
+ .get("/users", (req, res) => {
264
+ res.json(["user1", "user2"]);
265
+ })
266
+
267
+ .get("/products", (req, res) => {
268
+ res.json(["product1", "product2"]);
269
+ })
270
+
271
+ .build();
272
+ ```
273
+
274
+ ---
275
+
276
+ # Features
277
+
278
+ - Chainable route API
279
+ - Express middleware uyumu
280
+ - Role based access
281
+ - Multiple route handlers
282
+ - Sub path routing
283
+ - GraphQL integration
284
+ - API ve sayfa route desteği
285
+
286
+ ---
package/index.js ADDED
@@ -0,0 +1,4 @@
1
+ import expressSpeed from "./src/expressSpeed.js";
2
+ import pager from "./src/pager.js";
3
+
4
+ export { expressSpeed, pager };
package/package.json ADDED
@@ -0,0 +1,30 @@
1
+ {
2
+ "name": "express-speed",
3
+ "description": "A simple pager system for Express apps",
4
+ "version": "1.0.1",
5
+ "main": "index.js",
6
+ "type": "module",
7
+ "files": [
8
+ "src",
9
+ "index.js",
10
+ "app.js"
11
+ ],
12
+ "author": "f10tme",
13
+ "license": "MIT",
14
+ "repository": {
15
+ "type": "git",
16
+ "url": "https://github.com/f10tme/express-speed"
17
+ },
18
+ "keywords": [
19
+ "express",
20
+ "pager",
21
+ "routing",
22
+ "middleware",
23
+ "graphql"
24
+ ],
25
+ "dependencies": {
26
+ "express": "^4.22.1",
27
+ "fs-extra": "^11.3.3",
28
+ "glob": "^10.5.0"
29
+ }
30
+ }
@@ -0,0 +1,123 @@
1
+ // * ExpressSpeed mvc yapısına uygun daha hızlı şekilde kullanılabilir formatta
2
+ // * Sayfalara özel Rol kontrol özelliği
3
+ // * Graphql Uyumlu
4
+
5
+ import express from "express";
6
+ import { globSync } from "glob";
7
+ import pager from "./pager.js";
8
+
9
+ let expressSpeed = {
10
+ app: express(),
11
+ config: {
12
+ port: 80,
13
+ path: {
14
+ page: {
15
+ render: [],
16
+ exclude: [],
17
+ nodir: true,
18
+ },
19
+ },
20
+ use: [],
21
+ settings: {},
22
+ },
23
+ trigger: {
24
+ start: {
25
+ },
26
+ end: {
27
+ }
28
+ },
29
+ complier: {
30
+ pagesMap(renderPathArrayValue, pageExcludeArrayValue, nodirBooleanValue) {
31
+ const pageFiles = renderPathArrayValue.flatMap((pathValue) =>
32
+ globSync(pathValue, {
33
+ nodir: nodirBooleanValue || true,
34
+ ignore: pageExcludeArrayValue,
35
+ })
36
+ .map((e) => "file:///" + process.cwd().replaceAll("\\", "/") + "/" + e.replaceAll("\\", "/"))
37
+ );
38
+ return pageFiles;
39
+ },
40
+ async pagesImport(pagePathArrayValue) {
41
+ const pages = await Promise.all(pagePathArrayValue.map(async (pathValue) => {
42
+ if (pathValue) {
43
+ let page = (await import(pathValue)).default;
44
+ if (page) {
45
+ page._path = pathValue;
46
+ return page;
47
+ } else console.log("@ERROR", pathValue);
48
+ }
49
+ }));
50
+ return pages;
51
+ },
52
+ pageRender(pageObjectValue) {
53
+ if (!pageObjectValue) {
54
+ return false;
55
+ }
56
+ const app = expressSpeed.app;
57
+ for (const router of pageObjectValue.methods) {
58
+ let parameters = ("string" == typeof router.parameters[0]) ? [...router.parameters] : [router.url, ...router.parameters];
59
+ switch (router.method.toString().toLowerCase()) {
60
+ case "use":
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;
84
+ }
85
+ }
86
+ },
87
+ async load() {
88
+ for (const useValue of expressSpeed.config.use) expressSpeed.app.use(useValue);
89
+ for (let [setKey, setValue] of Object.entries(expressSpeed.config.settings)) expressSpeed.app.set(setKey, setValue);
90
+ let pagesMap = expressSpeed.complier.pagesMap(expressSpeed.config.path.page.render, expressSpeed.config.path.page.exclude);
91
+ let pages = await expressSpeed.complier.pagesImport(pagesMap);
92
+ for (let page of pages) expressSpeed.complier.pageRender(page);
93
+ }
94
+ },
95
+ async listen(port = 80, config = {
96
+ port: null,
97
+ page: {},
98
+ use: [],
99
+ usings: [],
100
+ settings: {},
101
+ go: null,
102
+ }) {
103
+ if (typeof config.go == "function") config.go(expressSpeed);
104
+ config.port = port;
105
+ console.log(typeof config);
106
+ if (typeof config == "object") {
107
+ }
108
+ expressSpeed.config.path.page = {
109
+ ...expressSpeed.config.path.page,
110
+ ...config.page
111
+ } || {};
112
+ expressSpeed.config.port = config.port || 80;
113
+ expressSpeed.config.use = config.use || [];
114
+ expressSpeed.config.settings = config.settings || {};
115
+
116
+ expressSpeed.complier.load();
117
+ expressSpeed.app.listen(expressSpeed.config.port);
118
+ },
119
+ }
120
+
121
+ expressSpeed.pager = pager;
122
+
123
+ export default expressSpeed;
package/src/pager.js ADDED
@@ -0,0 +1,126 @@
1
+ // * Sayfa yapısını oluşturan obje haline getiren zincir fonksiyonlar
2
+
3
+ const pager = {
4
+ _id: 0,
5
+ _config: {
6
+ url: null,
7
+ role: null,
8
+ usings: null,
9
+ 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
+ },
22
+ url(urlStringValue) {
23
+ pager._config.url = urlStringValue;
24
+ return pager;
25
+ },
26
+ role(roleStringAndArrayValue) {
27
+ pager._config.role = roleStringAndArrayValue;
28
+ return pager;
29
+ },
30
+ usings(usingsArrayValue) {
31
+ pager._config.usings = usingsArrayValue;
32
+ return pager;
33
+ },
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
+ build() {
103
+ const data = { ...pager._config }
104
+ pager._config = {
105
+ url: null,
106
+ role: null,
107
+ usings: [],
108
+ settings: [],
109
+ 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
+ };
122
+ return data;
123
+ },
124
+ }
125
+
126
+ export default pager;