@asterflow/router 1.0.4 → 1.0.5
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 +8 -7
- package/dist/cjs/index.cjs +27 -34
- package/dist/mjs/index.js +11 -15
- package/dist/types/types/method.d.ts +6 -4
- package/dist/types/types/router.d.ts +1 -1
- package/package.json +3 -4
package/README.md
CHANGED
|
@@ -2,14 +2,14 @@
|
|
|
2
2
|
|
|
3
3
|
# @asterflow/router
|
|
4
4
|
|
|
5
|
-

|
|
6
|
+

|
|
7
7
|
|
|
8
|
-

|
|
9
|
+

|
|
10
|
+

|
|
11
11
|
|
|
12
|
-

|
|
13
13
|

|
|
14
14
|
|
|
15
15
|
</div>
|
|
@@ -162,7 +162,8 @@ app.listen(server, { port: 3333 }, (err) => {
|
|
|
162
162
|
- [@asterflow/adapter](https://www.npmjs.com/package/@asterflow/adapter) - Adapters for different HTTP servers
|
|
163
163
|
- [@asterflow/response](https://www.npmjs.com/package/@asterflow/response) - Type-safe HTTP response system
|
|
164
164
|
- [@asterflow/request](https://www.npmjs.com/package/@asterflow/request) - Unified HTTP request system
|
|
165
|
+
- [@asterflow/plugin](https://www.npmjs.com/package/@asterflow/plugin) - A modular and typed plugin system
|
|
165
166
|
|
|
166
167
|
## 📄 License
|
|
167
168
|
|
|
168
|
-
MIT - See [LICENSE](https://github.com/
|
|
169
|
+
MIT - See [LICENSE](https://github.com/AsterFlow/AsterFlow/blob/main/LICENSE) for more details.
|
package/dist/cjs/index.cjs
CHANGED
|
@@ -1,32 +1,30 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
var
|
|
3
|
-
var
|
|
2
|
+
var a = Object.defineProperty;
|
|
3
|
+
var u = Object.getOwnPropertyDescriptor;
|
|
4
4
|
var M = Object.getOwnPropertyNames;
|
|
5
|
-
var
|
|
6
|
-
var
|
|
7
|
-
for (var
|
|
8
|
-
|
|
9
|
-
},
|
|
5
|
+
var w = Object.prototype.hasOwnProperty;
|
|
6
|
+
var R = (t, e) => {
|
|
7
|
+
for (var o in e)
|
|
8
|
+
a(t, o, { get: e[o], enumerable: !0 });
|
|
9
|
+
}, x = (t, e, o, d) => {
|
|
10
10
|
if (e && typeof e == "object" || typeof e == "function")
|
|
11
|
-
for (let
|
|
12
|
-
!
|
|
11
|
+
for (let s of M(e))
|
|
12
|
+
!w.call(t, s) && s !== o && a(t, s, { get: () => e[s], enumerable: !(d = u(e, s)) || d.enumerable });
|
|
13
13
|
return t;
|
|
14
14
|
};
|
|
15
|
-
var
|
|
16
|
-
|
|
15
|
+
var f = (t) => x(a({}, "__esModule", { value: !0 }), t);
|
|
17
16
|
// packages/router/src/index.ts
|
|
18
|
-
var
|
|
19
|
-
|
|
20
|
-
Method: () =>
|
|
21
|
-
MethodType: () =>
|
|
22
|
-
Middleware: () =>
|
|
23
|
-
Router: () =>
|
|
24
|
-
createRouter: () =>
|
|
17
|
+
var g = {};
|
|
18
|
+
R(g, {
|
|
19
|
+
Method: () => m,
|
|
20
|
+
MethodType: () => l,
|
|
21
|
+
Middleware: () => p,
|
|
22
|
+
Router: () => n,
|
|
23
|
+
createRouter: () => S
|
|
25
24
|
});
|
|
26
|
-
module.exports =
|
|
27
|
-
|
|
25
|
+
module.exports = f(g);
|
|
28
26
|
// packages/router/src/controllers/Router.ts
|
|
29
|
-
var
|
|
27
|
+
var i = require("url-ast"), n = class {
|
|
30
28
|
name;
|
|
31
29
|
path;
|
|
32
30
|
schema;
|
|
@@ -35,22 +33,20 @@ var m = require("url-ast"), o = class {
|
|
|
35
33
|
use;
|
|
36
34
|
url;
|
|
37
35
|
constructor(e) {
|
|
38
|
-
let { name:
|
|
39
|
-
this.name =
|
|
36
|
+
let { name: o, path: d, schema: s, description: c, methods: y } = e;
|
|
37
|
+
this.name = o, this.path = d, this.schema = s, this.description = c, this.methods = y, this.use = e.use, this.url = new i.Analyze(this.path);
|
|
40
38
|
}
|
|
41
39
|
};
|
|
42
|
-
|
|
43
40
|
// packages/router/src/controllers/Middleware.ts
|
|
44
|
-
var
|
|
41
|
+
var p = class {
|
|
45
42
|
name;
|
|
46
43
|
onRun;
|
|
47
44
|
constructor(e) {
|
|
48
45
|
this.name = e.name, this.onRun = e.onRun;
|
|
49
46
|
}
|
|
50
47
|
};
|
|
51
|
-
|
|
52
48
|
// packages/router/src/controllers/Method.ts
|
|
53
|
-
var
|
|
49
|
+
var h = require("url-ast"), m = class {
|
|
54
50
|
path;
|
|
55
51
|
url;
|
|
56
52
|
method;
|
|
@@ -59,18 +55,15 @@ var i = require("url-ast"), p = class {
|
|
|
59
55
|
use;
|
|
60
56
|
handler;
|
|
61
57
|
constructor(e) {
|
|
62
|
-
this.path = e.path, this.url = new
|
|
58
|
+
this.path = e.path, this.url = new h.Analyze(this.path), this.method = e.method, this.schema = e.schema, this.handler = e.handler, this.use = e.use;
|
|
63
59
|
}
|
|
64
60
|
};
|
|
65
|
-
|
|
66
61
|
// packages/router/src/controllers/createRouter.ts
|
|
67
|
-
function
|
|
68
|
-
return (t) => new
|
|
62
|
+
function S() {
|
|
63
|
+
return (t) => new n(t);
|
|
69
64
|
}
|
|
70
|
-
|
|
71
65
|
// packages/router/src/types/method.ts
|
|
72
|
-
var
|
|
73
|
-
// Annotate the CommonJS export names for ESM import in node:
|
|
66
|
+
var l = ((r) => (r.all = "all", r.get = "get", r.post = "post", r.put = "put", r.delete = "delete", r.options = "options", r.head = "head", r.patch = "patch", r))(l || {});
|
|
74
67
|
0 && (module.exports = {
|
|
75
68
|
Method,
|
|
76
69
|
MethodType,
|
package/dist/mjs/index.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
// packages/router/src/controllers/Router.ts
|
|
2
|
-
import { Analyze as
|
|
2
|
+
import { Analyze as h } from "url-ast";
|
|
3
3
|
var s = class {
|
|
4
4
|
name;
|
|
5
5
|
path;
|
|
@@ -9,11 +9,10 @@ var s = class {
|
|
|
9
9
|
use;
|
|
10
10
|
url;
|
|
11
11
|
constructor(e) {
|
|
12
|
-
let { name:
|
|
13
|
-
this.name =
|
|
12
|
+
let { name: d, path: a, schema: p, description: m, methods: i } = e;
|
|
13
|
+
this.name = d, this.path = a, this.schema = p, this.description = m, this.methods = i, this.use = e.use, this.url = new h(this.path);
|
|
14
14
|
}
|
|
15
15
|
};
|
|
16
|
-
|
|
17
16
|
// packages/router/src/controllers/Middleware.ts
|
|
18
17
|
var o = class {
|
|
19
18
|
name;
|
|
@@ -22,10 +21,9 @@ var o = class {
|
|
|
22
21
|
this.name = e.name, this.onRun = e.onRun;
|
|
23
22
|
}
|
|
24
23
|
};
|
|
25
|
-
|
|
26
24
|
// packages/router/src/controllers/Method.ts
|
|
27
|
-
import { Analyze as
|
|
28
|
-
var
|
|
25
|
+
import { Analyze as l } from "url-ast";
|
|
26
|
+
var n = class {
|
|
29
27
|
path;
|
|
30
28
|
url;
|
|
31
29
|
method;
|
|
@@ -34,21 +32,19 @@ var d = class {
|
|
|
34
32
|
use;
|
|
35
33
|
handler;
|
|
36
34
|
constructor(e) {
|
|
37
|
-
this.path = e.path, this.url = new
|
|
35
|
+
this.path = e.path, this.url = new l(this.path), this.method = e.method, this.schema = e.schema, this.handler = e.handler, this.use = e.use;
|
|
38
36
|
}
|
|
39
37
|
};
|
|
40
|
-
|
|
41
38
|
// packages/router/src/controllers/createRouter.ts
|
|
42
|
-
function
|
|
39
|
+
function f() {
|
|
43
40
|
return (r) => new s(r);
|
|
44
41
|
}
|
|
45
|
-
|
|
46
42
|
// packages/router/src/types/method.ts
|
|
47
|
-
var
|
|
43
|
+
var c = ((t) => (t.all = "all", t.get = "get", t.post = "post", t.put = "put", t.delete = "delete", t.options = "options", t.head = "head", t.patch = "patch", t))(c || {});
|
|
48
44
|
export {
|
|
49
|
-
|
|
50
|
-
|
|
45
|
+
n as Method,
|
|
46
|
+
c as MethodType,
|
|
51
47
|
o as Middleware,
|
|
52
48
|
s as Router,
|
|
53
|
-
|
|
49
|
+
f as createRouter
|
|
54
50
|
};
|
|
@@ -5,15 +5,17 @@ import type { Middleware } from '../controllers/Middleware';
|
|
|
5
5
|
import type { AnyMiddleware, MiddlewareOutput } from './mindleware';
|
|
6
6
|
import type { AnySchema, InferSchema } from './schema';
|
|
7
7
|
export declare enum MethodType {
|
|
8
|
+
all = "all",
|
|
8
9
|
get = "get",
|
|
9
10
|
post = "post",
|
|
10
11
|
put = "put",
|
|
11
|
-
delete = "delete"
|
|
12
|
+
delete = "delete",
|
|
13
|
+
options = "options",
|
|
14
|
+
head = "head",
|
|
15
|
+
patch = "patch"
|
|
12
16
|
}
|
|
17
|
+
export type AnyMethodHandler = MethodHandler<string, Responders, AnySchema, AnyMiddleware[], MiddlewareOutput<AnyMiddleware[]>>;
|
|
13
18
|
export type MethodKeys = keyof typeof MethodType;
|
|
14
|
-
export type AnyMethodHandler = {
|
|
15
|
-
[Method in MethodKeys]?: MethodHandler<string, Responders, AnySchema, AnyMiddleware[], MiddlewareOutput<AnyMiddleware[]>>;
|
|
16
|
-
};
|
|
17
19
|
export type MethodHandler<Path extends string, Responder extends Responders, Schema extends AnySchema, Middlewares extends readonly Middleware<Responder, Schema, string, Record<string, unknown>>[], Context extends MiddlewareOutput<Middlewares>> = <RequestType>(args: {
|
|
18
20
|
request: Request<RequestType>;
|
|
19
21
|
response: Response<Responder>;
|
|
@@ -10,7 +10,7 @@ import type { AnySchema, InferredData, SchemaDynamic } from './schema';
|
|
|
10
10
|
export type AnyRouteHandler = {
|
|
11
11
|
[Method in MethodKeys]?: RouteHandler<string, Responders, Method, SchemaDynamic<Method>, AnyMiddleware[], MiddlewareOutput<AnyMiddleware[]>>;
|
|
12
12
|
};
|
|
13
|
-
export type AnyRouter = Router<
|
|
13
|
+
export type AnyRouter = Router<any, any, any, any, any, any> | Method<any, any, any, any, any, any, any>;
|
|
14
14
|
export type RouteHandler<Path extends string, Responder extends Responders, Method extends MethodKeys, Schema extends SchemaDynamic<Method>, Middlewares extends readonly Middleware<Responder, AnySchema, string, Record<string, unknown>>[], Context extends MiddlewareOutput<Middlewares>> = <RequestType>(args: {
|
|
15
15
|
request: Request<RequestType>;
|
|
16
16
|
response: Response<Responder>;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@asterflow/router",
|
|
3
|
-
"version": "1.0.
|
|
3
|
+
"version": "1.0.5",
|
|
4
4
|
"main": "dist/cjs/index.cjs",
|
|
5
5
|
"module": "dist/mjs/index.js",
|
|
6
6
|
"types": "dist/types/index.d.ts",
|
|
@@ -18,10 +18,9 @@
|
|
|
18
18
|
"node": ">=20"
|
|
19
19
|
},
|
|
20
20
|
"devDependencies": {
|
|
21
|
-
"@asterflow/request": "1.0.
|
|
22
|
-
"@asterflow/response": "1.0.
|
|
21
|
+
"@asterflow/request": "1.0.5",
|
|
22
|
+
"@asterflow/response": "1.0.2",
|
|
23
23
|
"@caeljs/tsh": "^1.1.3",
|
|
24
|
-
"@types/bun": "latest",
|
|
25
24
|
"fastify": "^5.3.3",
|
|
26
25
|
"zod": "^3.25.62"
|
|
27
26
|
},
|