@asterflow/router 1.0.4 → 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 CHANGED
@@ -2,14 +2,14 @@
2
2
 
3
3
  # @asterflow/router
4
4
 
5
- ![license-info](https://img.shields.io/github/license/Ashu11-A/AsterFlow?style=for-the-badge&colorA=302D41&colorB=f9e2af&logoColor=f9e2af)
6
- ![stars-info](https://img.shields.io/github/stars/Ashu11-A/AsterFlow?colorA=302D41&colorB=f9e2af&style=for-the-badge)
5
+ ![license-info](https://img.shields.io/github/license/AsterFlow/AsterFlow?style=for-the-badge&colorA=302D41&colorB=f9e2af&logoColor=f9e2af)
6
+ ![stars-info](https://img.shields.io/github/stars/AsterFlow/AsterFlow?colorA=302D41&colorB=f9e2af&style=for-the-badge)
7
7
 
8
- ![last-commit](https://img.shields.io/github/last-commit/Ashu11-A/AsterFlow?style=for-the-badge&colorA=302D41&colorB=b4befe)
9
- ![commit-activity](https://img.shields.io/github/commit-activity/y/Ashu11-A/AsterFlow?style=for-the-badge&colorA=302D41&colorB=f9e2af)
10
- ![code-size](https://img.shields.io/github/languages/code-size/Ashu11-A/AsterFlow?style=for-the-badge&colorA=302D41&colorB=90dceb)
8
+ ![last-commit](https://img.shields.io/github/last-commit/AsterFlow/AsterFlow?style=for-the-badge&colorA=302D41&colorB=b4befe)
9
+ ![commit-activity](https://img.shields.io/github/commit-activity/y/AsterFlow/AsterFlow?style=for-the-badge&colorA=302D41&colorB=f9e2af)
10
+ ![code-size](https://img.shields.io/github/languages/code-size/AsterFlow/AsterFlow?style=for-the-badge&colorA=302D41&colorB=90dceb)
11
11
 
12
- ![top-language](https://img.shields.io/github/languages/top/Ashu11-A/AsterFlow?style=for-the-badge&colorA=302D41&colorB=90dceb)
12
+ ![top-language](https://img.shields.io/github/languages/top/AsterFlow/AsterFlow?style=for-the-badge&colorA=302D41&colorB=90dceb)
13
13
  ![bundle-size](https://img.shields.io/bundlejs/size/@asterflow/request?style=for-the-badge&colorA=302D41&colorB=3ac97b)
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/Ashu11-A/AsterFlow/blob/main/LICENSE) for more details.
169
+ MIT - See [LICENSE](https://github.com/AsterFlow/AsterFlow/blob/main/LICENSE) for more details.
@@ -1,32 +1,30 @@
1
1
  "use strict";
2
- var n = Object.defineProperty;
3
- var y = Object.getOwnPropertyDescriptor;
4
- var M = Object.getOwnPropertyNames;
5
- var u = Object.prototype.hasOwnProperty;
6
- var w = (t, e) => {
7
- for (var s in e)
8
- n(t, s, { get: e[s], enumerable: !0 });
9
- }, R = (t, e, s, d) => {
2
+ var a = Object.defineProperty;
3
+ var w = Object.getOwnPropertyDescriptor;
4
+ var u = Object.getOwnPropertyNames;
5
+ var M = Object.prototype.hasOwnProperty;
6
+ var R = (t, e) => {
7
+ for (var n in e)
8
+ a(t, n, { get: e[n], enumerable: !0 });
9
+ }, x = (t, e, n, d) => {
10
10
  if (e && typeof e == "object" || typeof e == "function")
11
- for (let r of M(e))
12
- !u.call(t, r) && r !== s && n(t, r, { get: () => e[r], enumerable: !(d = y(e, r)) || d.enumerable });
11
+ for (let s of u(e))
12
+ !M.call(t, s) && s !== n && a(t, s, { get: () => e[s], enumerable: !(d = w(e, s)) || d.enumerable });
13
13
  return t;
14
14
  };
15
- var x = (t) => R(n({}, "__esModule", { value: !0 }), t);
16
-
15
+ var f = (t) => x(a({}, "__esModule", { value: !0 }), t);
17
16
  // packages/router/src/index.ts
18
- var S = {};
19
- w(S, {
20
- Method: () => p,
21
- MethodType: () => h,
22
- Middleware: () => a,
17
+ var A = {};
18
+ R(A, {
19
+ Method: () => m,
20
+ MethodType: () => l,
21
+ Middleware: () => p,
23
22
  Router: () => o,
24
- createRouter: () => f
23
+ createRouter: () => S
25
24
  });
26
- module.exports = x(S);
27
-
25
+ module.exports = f(A);
28
26
  // packages/router/src/controllers/Router.ts
29
- var m = require("url-ast"), o = class {
27
+ var i = require("@asterflow/url-parser"), o = 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: s, path: d, schema: r, description: l, methods: c } = e;
39
- this.name = s, this.path = d, this.schema = r, this.description = l, this.methods = c, this.use = e.use, this.url = new m.Analyze(this.path);
36
+ let { name: n, path: d, schema: s, description: c, methods: y } = e;
37
+ this.name = n, 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 a = class {
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 i = require("url-ast"), p = class {
49
+ var h = require("@asterflow/url-parser"), 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 i.Analyze(this.path), this.method = e.method, this.schema = e.schema, this.handler = e.handler, this.use = e.use;
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 f() {
62
+ function S() {
68
63
  return (t) => new o(t);
69
64
  }
70
-
71
65
  // packages/router/src/types/method.ts
72
- var h = /* @__PURE__ */ ((r) => (r.get = "get", r.post = "post", r.put = "put", r.delete = "delete", r))(h || {});
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 i } from "url-ast";
2
+ import { Analyze as h } from "@asterflow/url-parser";
3
3
  var s = class {
4
4
  name;
5
5
  path;
@@ -9,23 +9,21 @@ var s = class {
9
9
  use;
10
10
  url;
11
11
  constructor(e) {
12
- let { name: n, path: a, schema: t, description: p, methods: m } = e;
13
- this.name = n, this.path = a, this.schema = t, this.description = p, this.methods = m, this.use = e.use, this.url = new i(this.path);
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
- var o = class {
17
+ var n = class {
19
18
  name;
20
19
  onRun;
21
20
  constructor(e) {
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 h } from "url-ast";
28
- var d = class {
25
+ import { Analyze as l } from "@asterflow/url-parser";
26
+ var o = 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 h(this.path), this.method = e.method, this.schema = e.schema, this.handler = e.handler, this.use = e.use;
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 x() {
39
+ function f() {
43
40
  return (r) => new s(r);
44
41
  }
45
-
46
42
  // packages/router/src/types/method.ts
47
- var l = /* @__PURE__ */ ((t) => (t.get = "get", t.post = "post", t.put = "put", t.delete = "delete", t))(l || {});
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
- d as Method,
50
- l as MethodType,
51
- o as Middleware,
45
+ o as Method,
46
+ c as MethodType,
47
+ n as Middleware,
52
48
  s as Router,
53
- x as createRouter
49
+ f as createRouter
54
50
  };
@@ -1,10 +1,11 @@
1
+ import type { AnyAsterflow } from '@asterflow/core';
1
2
  import type { Responders } from '@asterflow/response';
2
- import { Analyze } from 'url-ast';
3
+ import { Analyze } from '@asterflow/url-parser';
3
4
  import type { MethodHandler, MethodKeys, MethodOptions } from '../types/method';
4
5
  import type { MiddlewareOutput } from '../types/mindleware';
5
6
  import type { AnySchema } from '../types/schema';
6
7
  import type { Middleware } from './Middleware';
7
- export declare class Method<Responder extends Responders, const Path extends string = string, const Method extends MethodKeys = MethodKeys, const Schema extends AnySchema = AnySchema, const Middlewares extends readonly Middleware<Responder, Schema, string, Record<string, unknown>>[] = [], const Context extends MiddlewareOutput<Middlewares> = MiddlewareOutput<Middlewares>, const Handler extends MethodHandler<Path, Responder, Schema, Middlewares, Context> = MethodHandler<Path, Responder, Schema, Middlewares, Context>> {
8
+ export declare class Method<Responder extends Responders, const Path extends string = string, const Method extends MethodKeys = MethodKeys, const Schema extends AnySchema = AnySchema, const Middlewares extends readonly Middleware<Responder, Schema, string, Record<string, unknown>>[] = [], const Context extends MiddlewareOutput<Middlewares> = MiddlewareOutput<Middlewares>, const Instance extends AnyAsterflow = AnyAsterflow, const Handler extends MethodHandler<Path, Responder, Schema, Middlewares, Context, Instance> = MethodHandler<Path, Responder, Schema, Middlewares, Context, Instance>> {
8
9
  path: Path;
9
10
  url: Analyze<Path>;
10
11
  method: Method;
@@ -12,5 +13,5 @@ export declare class Method<Responder extends Responders, const Path extends str
12
13
  name?: string;
13
14
  use?: Middlewares;
14
15
  handler: Handler;
15
- constructor(options: MethodOptions<Responder, Path, Method, Schema, Middlewares, Context, Handler>);
16
+ constructor(options: MethodOptions<Responder, Path, Method, Schema, Middlewares, Context, Instance, Handler>);
16
17
  }
@@ -1,5 +1,5 @@
1
1
  import type { Responders } from '@asterflow/response';
2
- import { Analyze } from 'url-ast';
2
+ import { Analyze } from '@asterflow/url-parser';
3
3
  import type { MethodKeys } from '../types/method';
4
4
  import type { MiddlewareOutput } from '../types/mindleware';
5
5
  import type { RouteHandler, RouterOptions } from '../types/router';
@@ -1,27 +1,31 @@
1
+ import type { AnyAsterflow, AsterFlow } from '@asterflow/core';
1
2
  import type { Request } from '@asterflow/request';
2
3
  import type { Responders, Response } from '@asterflow/response';
3
- import type { Analyze, ParsePath } from 'url-ast';
4
+ import type { Analyze, ParsePath } from '@asterflow/url-parser';
4
5
  import type { Middleware } from '../controllers/Middleware';
5
6
  import type { AnyMiddleware, MiddlewareOutput } from './mindleware';
6
7
  import type { AnySchema, InferSchema } from './schema';
7
8
  export declare enum MethodType {
9
+ all = "all",
8
10
  get = "get",
9
11
  post = "post",
10
12
  put = "put",
11
- delete = "delete"
13
+ delete = "delete",
14
+ options = "options",
15
+ head = "head",
16
+ patch = "patch"
12
17
  }
18
+ export type AnyMethodHandler = MethodHandler<string, Responders, AnySchema, AnyMiddleware[], MiddlewareOutput<AnyMiddleware[]>, AsterFlow>;
13
19
  export type MethodKeys = keyof typeof MethodType;
14
- export type AnyMethodHandler = {
15
- [Method in MethodKeys]?: MethodHandler<string, Responders, AnySchema, AnyMiddleware[], MiddlewareOutput<AnyMiddleware[]>>;
16
- };
17
- 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: {
20
+ 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>, Instance extends AnyAsterflow> = <RequestType>(args: {
21
+ instance: Instance;
18
22
  request: Request<RequestType>;
19
23
  response: Response<Responder>;
20
24
  url: Analyze<Path, ParsePath<Path>, Analyze<Path>>;
21
25
  schema: InferSchema<Schema>;
22
26
  middleware: Context;
23
27
  }) => Promise<Response<Responder>> | Response<Responder>;
24
- export type MethodOptions<Responder extends Responders, Path extends string, Method extends MethodKeys, Schema extends AnySchema, Middlewares extends readonly Middleware<Responder, Schema, string, Record<string, unknown>>[], Context extends MiddlewareOutput<Middlewares>, Handler extends MethodHandler<Path, Responder, Schema, Middlewares, Context>> = {
28
+ export type MethodOptions<Responder extends Responders, Path extends string, Method extends MethodKeys, Schema extends AnySchema, Middlewares extends readonly Middleware<Responder, Schema, string, Record<string, unknown>>[], Context extends MiddlewareOutput<Middlewares>, Instance extends AnyAsterflow, Handler extends MethodHandler<Path, Responder, Schema, Middlewares, Context, Instance>> = {
25
29
  path: Path;
26
30
  name?: string;
27
31
  description?: string;
@@ -1,6 +1,6 @@
1
1
  import type { Request } from '@asterflow/request';
2
2
  import type { Responders, Response } from '@asterflow/response';
3
- import type { Analyze, ParsePath } from 'url-ast';
3
+ import type { Analyze, ParsePath } from '@asterflow/url-parser';
4
4
  import type { Method } from '../controllers/Method';
5
5
  import type { Middleware } from '../controllers/Middleware';
6
6
  import type { Router } from '../controllers/Router';
@@ -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<Responders, string, SchemaDynamic<MethodKeys>, AnyMiddleware[], MiddlewareOutput<AnyMiddleware[]>, AnyRouteHandler> | Method<Responders, string, MethodKeys, AnySchema, AnyMiddleware[], MiddlewareOutput<AnyMiddleware[]>, any>;
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.4",
3
+ "version": "1.0.6",
4
4
  "main": "dist/cjs/index.cjs",
5
5
  "module": "dist/mjs/index.js",
6
6
  "types": "dist/types/index.d.ts",
@@ -18,17 +18,16 @@
18
18
  "node": ">=20"
19
19
  },
20
20
  "devDependencies": {
21
- "@asterflow/request": "1.0.4",
22
- "@asterflow/response": "1.0.1",
23
- "@caeljs/tsh": "^1.1.3",
24
- "@types/bun": "latest",
25
- "fastify": "^5.3.3",
26
- "zod": "^3.25.62"
21
+ "@asterflow/request": "1.0.6",
22
+ "@asterflow/response": "1.0.3",
23
+ "@asterflow/core": "1.0.6"
27
24
  },
28
25
  "peerDependencies": {
26
+ "@caeljs/tsh": "^1.1.3",
27
+ "zod": "^3.25.63",
29
28
  "typescript": "^5.8.3"
30
29
  },
31
30
  "dependencies": {
32
- "url-ast": "^1.0.3"
31
+ "@asterflow/url-parser": "^2.0.1"
33
32
  }
34
33
  }