@asterflow/router 1.0.7 → 1.0.9

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
@@ -4,12 +4,8 @@
4
4
 
5
5
  ![license-info](https://img.shields.io/github/license/AsterFlow/AsterFlow?style=for-the-badge&colorA=302D41&colorB=f9e2af&logoColor=f9e2af)
6
6
  ![stars-info](https://img.shields.io/github/stars/AsterFlow/AsterFlow?colorA=302D41&colorB=f9e2af&style=for-the-badge)
7
+ ![last-commit](https://img.shields.io/github/last-commit/AsterFlow/AsterFlow?path=packages%2Frequest&style=for-the-badge&colorA=302D41&colorB=b4befe)
7
8
 
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
-
12
- ![top-language](https://img.shields.io/github/languages/top/AsterFlow/AsterFlow?style=for-the-badge&colorA=302D41&colorB=90dceb)
13
9
  ![bundle-size](https://img.shields.io/bundlejs/size/@asterflow/request?style=for-the-badge&colorA=302D41&colorB=3ac97b)
14
10
 
15
11
  </div>
@@ -135,7 +131,7 @@ const router = new Router({
135
131
 
136
132
  ```typescript
137
133
  import { adapters } from '@asterflow/adapter'
138
- import { AsterFlow } from '@asterflow/core'
134
+ import { AsterFlow } from 'asterflow'
139
135
  import fastify from 'fastify'
140
136
 
141
137
  const server = fastify()
@@ -158,7 +154,7 @@ app.listen(server, { port: 3333 }, (err) => {
158
154
 
159
155
  ## 🔗 Related Packages
160
156
 
161
- - [@asterflow/core](https://www.npmjs.com/package/@asterflow/core) - Core framework
157
+ - [asterflow](https://www.npmjs.com/package/asterflow) - Core framework
162
158
  - [@asterflow/adapter](https://www.npmjs.com/package/@asterflow/adapter) - Adapters for different HTTP servers
163
159
  - [@asterflow/response](https://www.npmjs.com/package/@asterflow/response) - Type-safe HTTP response system
164
160
  - [@asterflow/request](https://www.npmjs.com/package/@asterflow/request) - Unified HTTP request system
@@ -1,44 +1,45 @@
1
1
  "use strict";
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) => {
2
+ var o = Object.defineProperty;
3
+ var c = Object.getOwnPropertyDescriptor;
4
+ var w = Object.getOwnPropertyNames;
5
+ var y = Object.prototype.hasOwnProperty;
6
+ var M = (t, e) => {
7
7
  for (var n in e)
8
- a(t, n, { get: e[n], enumerable: !0 });
9
- }, x = (t, e, n, d) => {
8
+ o(t, n, { get: e[n], enumerable: !0 });
9
+ }, u = (t, e, n, d) => {
10
10
  if (e && typeof e == "object" || typeof e == "function")
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 });
11
+ for (let s of w(e))
12
+ !y.call(t, s) && s !== n && o(t, s, { get: () => e[s], enumerable: !(d = c(e, s)) || d.enumerable });
13
13
  return t;
14
14
  };
15
- var f = (t) => x(a({}, "__esModule", { value: !0 }), t);
15
+ var x = (t) => u(o({}, "__esModule", { value: !0 }), t);
16
16
  // packages/router/src/index.ts
17
- var A = {};
18
- R(A, {
19
- Method: () => m,
20
- MethodType: () => l,
21
- Middleware: () => p,
22
- Router: () => o,
23
- createRouter: () => S
17
+ var R = {};
18
+ M(R, {
19
+ Method: () => p,
20
+ MethodType: () => m,
21
+ Middleware: () => i,
22
+ Router: () => a
24
23
  });
25
- module.exports = f(A);
24
+ module.exports = x(R);
26
25
  // packages/router/src/controllers/Router.ts
27
- var i = require("@asterflow/url-parser"), o = class {
26
+ var a = class t {
28
27
  name;
29
28
  path;
30
29
  schema;
31
30
  description;
32
31
  methods;
33
32
  use;
34
- url;
35
33
  constructor(e) {
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);
34
+ let { name: n, path: d, schema: s, description: h, methods: l } = e;
35
+ this.name = n, this.path = d, this.schema = s, this.description = h, this.methods = l, this.use = e.use;
36
+ }
37
+ static create() {
38
+ return (e) => new t(e);
38
39
  }
39
40
  };
40
41
  // packages/router/src/controllers/Middleware.ts
41
- var p = class {
42
+ var i = class {
42
43
  name;
43
44
  onRun;
44
45
  constructor(e) {
@@ -46,28 +47,22 @@ var p = class {
46
47
  }
47
48
  };
48
49
  // packages/router/src/controllers/Method.ts
49
- var h = require("@asterflow/url-parser"), m = class {
50
+ var p = class {
50
51
  path;
51
- url;
52
52
  method;
53
53
  schema;
54
54
  name;
55
55
  use;
56
56
  handler;
57
57
  constructor(e) {
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;
58
+ this.path = e.path, this.method = e.method, this.schema = e.schema, this.handler = e.handler, this.use = e.use;
59
59
  }
60
60
  };
61
- // packages/router/src/controllers/createRouter.ts
62
- function S() {
63
- return (t) => new o(t);
64
- }
65
61
  // packages/router/src/types/method.ts
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 || {});
62
+ var m = ((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))(m || {});
67
63
  0 && (module.exports = {
68
64
  Method,
69
65
  MethodType,
70
66
  Middleware,
71
- Router,
72
- createRouter
67
+ Router
73
68
  });
package/dist/mjs/index.js CHANGED
@@ -1,16 +1,17 @@
1
1
  // packages/router/src/controllers/Router.ts
2
- import { Analyze as h } from "@asterflow/url-parser";
3
- var s = class {
2
+ var s = class r {
4
3
  name;
5
4
  path;
6
5
  schema;
7
6
  description;
8
7
  methods;
9
8
  use;
10
- url;
11
9
  constructor(e) {
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);
10
+ let { name: o, path: a, schema: i, description: p, methods: m } = e;
11
+ this.name = o, this.path = a, this.schema = i, this.description = p, this.methods = m, this.use = e.use;
12
+ }
13
+ static create() {
14
+ return (e) => new r(e);
14
15
  }
15
16
  };
16
17
  // packages/router/src/controllers/Middleware.ts
@@ -22,29 +23,22 @@ var n = class {
22
23
  }
23
24
  };
24
25
  // packages/router/src/controllers/Method.ts
25
- import { Analyze as l } from "@asterflow/url-parser";
26
- var o = class {
26
+ var d = class {
27
27
  path;
28
- url;
29
28
  method;
30
29
  schema;
31
30
  name;
32
31
  use;
33
32
  handler;
34
33
  constructor(e) {
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;
34
+ this.path = e.path, this.method = e.method, this.schema = e.schema, this.handler = e.handler, this.use = e.use;
36
35
  }
37
36
  };
38
- // packages/router/src/controllers/createRouter.ts
39
- function f() {
40
- return (r) => new s(r);
41
- }
42
37
  // packages/router/src/types/method.ts
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 || {});
38
+ var h = ((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))(h || {});
44
39
  export {
45
- o as Method,
46
- c as MethodType,
40
+ d as Method,
41
+ h as MethodType,
47
42
  n as Middleware,
48
- s as Router,
49
- f as createRouter
43
+ s as Router
50
44
  };
@@ -1,17 +1,16 @@
1
- import type { AnyAsterflow } from '@asterflow/core';
1
+ import type { Runtime } from '@asterflow/adapter';
2
+ import type { AnyAsterflow } from 'asterflow';
2
3
  import type { Responders } from '@asterflow/response';
3
- import { Analyze } from '@asterflow/url-parser';
4
4
  import type { MethodHandler, MethodKeys, MethodOptions } from '../types/method';
5
5
  import type { MiddlewareOutput } from '../types/mindleware';
6
6
  import type { AnySchema } from '../types/schema';
7
7
  import type { Middleware } from './Middleware';
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
+ export declare class Method<Responder extends Responders, const Path extends string = string, const Drive extends Runtime = Runtime, 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, Drive, Responder, Schema, Middlewares, Context, Instance> = MethodHandler<Path, Drive, Responder, Schema, Middlewares, Context, Instance>> {
9
9
  path: Path;
10
- url: Analyze<Path>;
11
10
  method: Method;
12
11
  schema?: Schema;
13
12
  name?: string;
14
13
  use?: Middlewares;
15
14
  handler: Handler;
16
- constructor(options: MethodOptions<Responder, Path, Method, Schema, Middlewares, Context, Instance, Handler>);
15
+ constructor(options: MethodOptions<Responder, Path, Drive, Method, Schema, Middlewares, Context, Instance, Handler>);
17
16
  }
@@ -1,11 +1,11 @@
1
- import type { MiddlewareOptions } from '../types/mindleware';
2
1
  import type { Responders } from '@asterflow/response';
2
+ import type { MiddlewareOptions } from '../types/mindleware';
3
3
  import type { AnySchema } from '../types/schema';
4
4
  export declare class Middleware<Responder extends Responders, Schema extends AnySchema, const Name extends string = string, const Parameters extends Record<string, unknown> = Record<string, unknown>> {
5
5
  readonly name: Name;
6
- readonly onRun: <RequestType>(args: {
7
- response: import("@asterflow/response").Response<Responder, import("@asterflow/response").BodyMap<Responder>, keyof Responder, Map<string, string>, Map<string, string>>;
8
- request: import("@asterflow/request").Request<RequestType>;
6
+ readonly onRun: <RequestType extends import("@asterflow/adapter").Runtime>(args: {
7
+ response: import("@asterflow/response").AsterResponse<Responder, import("@asterflow/response").BodyMap<Responder>, keyof Responder, import("@asterflow/response").BaseContext>;
8
+ request: import("@asterflow/request").AsterRequest<RequestType, {}>;
9
9
  schema: import("..").InferSchema<Schema>;
10
10
  next: <Parameter extends Record<string, unknown>>(params: Parameter) => MiddlewareOptions<Responder, Schema, Name, Parameter>;
11
11
  }) => MiddlewareOptions<Responder, Schema, Name, Parameters>;
@@ -1,5 +1,4 @@
1
1
  import type { Responders } from '@asterflow/response';
2
- import { Analyze } from '@asterflow/url-parser';
3
2
  import type { MethodKeys } from '../types/method';
4
3
  import type { MiddlewareOutput } from '../types/mindleware';
5
4
  import type { RouteHandler, RouterOptions } from '../types/router';
@@ -16,6 +15,6 @@ export declare class Router<Responder extends Responders, const Path extends str
16
15
  description?: string;
17
16
  methods: Routers;
18
17
  use?: Middlewares;
19
- url: Analyze<Path>;
20
18
  constructor(options: RouterOptions<Path, Schema, Responder, Middlewares, Context, Routers>);
19
+ static create<Responder extends Responders>(): <const Path extends string, const Schema extends SchemaDynamic<MethodKeys>, const Middlewares extends readonly Middleware<Responder, AnySchema, string, Record<string, unknown>>[], const Context extends MiddlewareOutput<Middlewares>, const Routers extends { [Method in MethodKeys]?: RouteHandler<Path, Responder, Method, Schema, Middlewares, Context>; }>(options: RouterOptions<Path, Schema, Responder, Middlewares, Context, Routers>) => Router<Responder, Path, Schema, Middlewares, Context, Routers>;
21
20
  }
@@ -1,7 +1,6 @@
1
1
  export * from './controllers/Router';
2
2
  export * from './controllers/Middleware';
3
3
  export * from './controllers/Method';
4
- export * from './controllers/createRouter';
5
4
  export * from './types/router';
6
5
  export * from './types/schema';
7
6
  export * from './types/method';
@@ -1,6 +1,7 @@
1
- import type { AnyAsterflow, AsterFlow } from '@asterflow/core';
2
- import type { Request } from '@asterflow/request';
3
- import type { Responders, Response } from '@asterflow/response';
1
+ import type { Runtime } from '@asterflow/adapter';
2
+ import type { AnyAsterflow } from 'asterflow';
3
+ import type { AsterRequest } from '@asterflow/request';
4
+ import type { Responders, AsterResponse } from '@asterflow/response';
4
5
  import type { Analyze, ParsePath } from '@asterflow/url-parser';
5
6
  import type { Middleware } from '../controllers/Middleware';
6
7
  import type { AnyMiddleware, MiddlewareOutput } from './mindleware';
@@ -15,17 +16,17 @@ export declare enum MethodType {
15
16
  head = "head",
16
17
  patch = "patch"
17
18
  }
18
- export type AnyMethodHandler = MethodHandler<string, Responders, AnySchema, AnyMiddleware[], MiddlewareOutput<AnyMiddleware[]>, AsterFlow>;
19
+ export type AnyMethodHandler = MethodHandler<string, Runtime, Responders, AnySchema, AnyMiddleware[], MiddlewareOutput<AnyMiddleware[]>, AnyAsterflow>;
19
20
  export type MethodKeys = keyof typeof MethodType;
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
+ export type MethodHandler<Path extends string, Drive extends Runtime, Responder extends Responders, Schema extends AnySchema, Middlewares extends readonly Middleware<Responder, Schema, string, Record<string, unknown>>[], Context extends MiddlewareOutput<Middlewares>, Instance extends AnyAsterflow> = (args: {
21
22
  instance: Instance;
22
- request: Request<RequestType>;
23
- response: Response<Responder>;
23
+ request: AsterRequest<Drive>;
24
+ response: AsterResponse<Responder>;
24
25
  url: Analyze<Path, ParsePath<Path>, Analyze<Path>>;
25
26
  schema: InferSchema<Schema>;
26
27
  middleware: Context;
27
- }) => Promise<Response<Responder>> | Response<Responder>;
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>> = {
28
+ }) => Promise<AsterResponse<Responder>> | AsterResponse<Responder>;
29
+ export type MethodOptions<Responder extends Responders, Path extends string, Drive extends Runtime, 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, Drive, Responder, Schema, Middlewares, Context, Instance>> = {
29
30
  path: Path;
30
31
  name?: string;
31
32
  description?: string;
@@ -1,16 +1,18 @@
1
+ import type { Runtime } from '@asterflow/adapter';
1
2
  import type { Request } from '@asterflow/request';
3
+ import type { Responders, AsterResponse } from '@asterflow/response';
2
4
  import type { Middleware } from '../controllers/Middleware';
3
- import type { Response, Responders } from '@asterflow/response';
4
5
  import type { AnySchema, InferSchema } from './schema';
5
6
  export type AnyMiddleware = Middleware<any, any, any, any>;
7
+ export type AnyMiddlewares = readonly AnyMiddleware[];
6
8
  /**
7
9
  * Accumulate the output types (`P`) from an array of middlewares into a single object
8
10
  */
9
11
  export type MiddlewareOutput<Ms extends readonly AnyMiddleware[]> = Ms extends readonly [infer First, ...infer Rest] ? First extends Middleware<any, any, any, infer P> ? Rest extends readonly AnyMiddleware[] ? P & MiddlewareOutput<Rest> : P : unknown : unknown;
10
12
  export type MiddlewareOptions<Responder extends Responders = Responders, Schema extends AnySchema = AnySchema, Name extends string = string, Parameters extends Record<string, unknown> = Record<string, unknown>> = {
11
13
  name: Name;
12
- onRun<RequestType>(args: {
13
- response: Response<Responder>;
14
+ onRun<RequestType extends Runtime>(args: {
15
+ response: AsterResponse<Responder>;
14
16
  request: Request<RequestType>;
15
17
  schema: InferSchema<Schema>;
16
18
  next: <Parameter extends Record<string, unknown>>(params: Parameter) => MiddlewareOptions<Responder, Schema, Name, Parameter>;
@@ -1,5 +1,6 @@
1
+ import type { Runtime } from '@asterflow/adapter';
1
2
  import type { Request } from '@asterflow/request';
2
- import type { Responders, Response } from '@asterflow/response';
3
+ import type { AsterResponse, Responders } from '@asterflow/response';
3
4
  import type { Analyze, ParsePath } from '@asterflow/url-parser';
4
5
  import type { Method } from '../controllers/Method';
5
6
  import type { Middleware } from '../controllers/Middleware';
@@ -10,14 +11,14 @@ import type { AnySchema, InferredData, SchemaDynamic } from './schema';
10
11
  export type AnyRouteHandler = {
11
12
  [Method in MethodKeys]?: RouteHandler<string, Responders, Method, SchemaDynamic<Method>, AnyMiddleware[], MiddlewareOutput<AnyMiddleware[]>>;
12
13
  };
13
- export type AnyRouter = Router<any, any, any, any, any, any> | Method<any, any, any, any, any, any, any>;
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: {
14
+ export type AnyRouter = Router<any, any, any, any, any, any> | Method<any, any, any, any, any, any, any, any, any>;
15
+ 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 extends Runtime>(args: {
15
16
  request: Request<RequestType>;
16
- response: Response<Responder>;
17
+ response: AsterResponse<Responder>;
17
18
  url: Analyze<Path, ParsePath<Path>, Analyze<Path>>;
18
19
  schema: InferredData<Method, Schema>;
19
20
  middleware: Context;
20
- }) => Promise<Response> | Response;
21
+ }) => Promise<AsterResponse> | AsterResponse;
21
22
  export type RouterOptions<Path extends string, Schema extends SchemaDynamic<MethodKeys>, Responder extends Responders, Middlewares extends readonly Middleware<Responder, AnySchema, string, Record<string, unknown>>[], Context extends MiddlewareOutput<Middlewares>, Routers extends {
22
23
  [Method in MethodKeys]?: RouteHandler<Path, Responder, Method, Schema, Middlewares, Context>;
23
24
  }> = {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@asterflow/router",
3
- "version": "1.0.7",
3
+ "version": "1.0.9",
4
4
  "main": "dist/cjs/index.cjs",
5
5
  "module": "dist/mjs/index.js",
6
6
  "types": "dist/types/index.d.ts",
@@ -18,16 +18,13 @@
18
18
  "node": ">=20"
19
19
  },
20
20
  "devDependencies": {
21
- "@asterflow/request": "1.0.7",
22
- "@asterflow/response": "1.0.4",
23
- "@asterflow/core": "1.0.7"
21
+ "@asterflow/request": "1.0.9",
22
+ "@asterflow/response": "1.0.6",
23
+ "asterflow": "0.0.1"
24
24
  },
25
25
  "peerDependencies": {
26
26
  "@caeljs/tsh": "^1.1.3",
27
27
  "zod": "^3.25.63",
28
28
  "typescript": "^5.8.3"
29
- },
30
- "dependencies": {
31
- "@asterflow/url-parser": "^2.0.1"
32
29
  }
33
30
  }
@@ -1,12 +0,0 @@
1
- import type { Responders } from '@asterflow/response';
2
- import type { AnySchema, SchemaDynamic } from '../types/schema';
3
- import type { Middleware } from './Middleware';
4
- import type { MethodKeys } from '../types/method';
5
- import type { MiddlewareOutput } from '../types/mindleware';
6
- import type { RouteHandler, RouterOptions } from '../types/router';
7
- import { Router } from './Router';
8
- /**
9
- * Starts building a Router, setting the expected response types.
10
- * @returns An object with the `from` method to define the router options.
11
- */
12
- export declare function createRouter<Responder extends Responders>(): <const Path extends string, const Schema extends SchemaDynamic<MethodKeys>, const Middlewares extends readonly Middleware<Responder, AnySchema, string, Record<string, unknown>>[], const Context extends MiddlewareOutput<Middlewares>, const Routers extends { [Method in MethodKeys]?: RouteHandler<Path, Responder, Method, Schema, Middlewares, Context>; }>(options: RouterOptions<Path, Schema, Responder, Middlewares, Context, Routers>) => Router<Responder, Path, Schema, Middlewares, Context, Routers>;