@asterflow/adapter 1.0.2 → 1.0.4

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
@@ -177,51 +177,12 @@ interface ErrorPayload {
177
177
  }
178
178
  ```
179
179
 
180
- ## 📚 API Reference
181
-
182
- ### Main Types
183
-
184
- ```typescript
185
- enum Runtime {
186
- Bun = 'bun',
187
- Express = 'express',
188
- Node = 'node',
189
- Fastify = 'fastify'
190
- }
191
-
192
- interface OptionsDriver<Type extends Runtime> {
193
- runtime: Type
194
- listen: (...params: ListenParams<Type>) => void
195
- onRequest?: (request: Request, response?: Response) => Response | Promise<Response>
196
- }
197
- ```
198
-
199
- ### Configuration Options
200
-
201
- Each adapter accepts runtime-specific options while maintaining proper typing:
202
-
203
- ```typescript
204
- // Node/Bun
205
- interface ListenOptions {
206
- port: number
207
- host?: string
208
- backlog?: number
209
- }
210
-
211
- // Fastify
212
- interface FastifyOptions extends FastifyListenOptions {
213
- // Fastify-specific options
214
- }
215
-
216
- // Express
217
- type ExpressOptions = Express.Application
218
- ```
219
-
220
180
  ## 🔗 Related Packages
221
181
 
222
- - [@asterflow/core](https://github.com/Ashu11-A/AsterFlow/tree/main/core) - Core framework
223
- - [@asterflow/router](https://github.com/Ashu11-A/AsterFlow/tree/main/packages/router) - Routing system
224
- - [@asterflow/request](https://github.com/Ashu11-A/AsterFlow/tree/main/packages/request) - Unified HTTP request system
182
+ - [@asterflow/core](https://www.npmjs.com/package/@asterflow/core) - Core framework
183
+ - [@asterflow/router](https://www.npmjs.com/package/@asterflow/router) - Type-safe routing system
184
+ - [@asterflow/request](https://www.npmjs.com/package/@asterflow/request) - Unified HTTP request system
185
+ - [@asterflow/response](https://www.npmjs.com/package/@asterflow/response) - Type-safe HTTP response system
225
186
 
226
187
  ## 📄 License
227
188
 
@@ -4,12 +4,12 @@ var w = Object.getOwnPropertyDescriptor;
4
4
  var T = Object.getOwnPropertyNames;
5
5
  var F = Object.prototype.hasOwnProperty;
6
6
  var O = (e, t) => {
7
- for (var r in t)
8
- a(e, r, { get: t[r], enumerable: !0 });
9
- }, C = (e, t, r, n) => {
7
+ for (var s in t)
8
+ a(e, s, { get: t[s], enumerable: !0 });
9
+ }, C = (e, t, s, n) => {
10
10
  if (t && typeof t == "object" || typeof t == "function")
11
- for (let s of T(t))
12
- !F.call(e, s) && s !== r && a(e, s, { get: () => t[s], enumerable: !(n = w(t, s)) || n.enumerable });
11
+ for (let r of T(t))
12
+ !F.call(e, r) && r !== s && a(e, r, { get: () => t[r], enumerable: !(n = w(t, r)) || n.enumerable });
13
13
  return e;
14
14
  };
15
15
  var L = (e) => C(a({}, "__esModule", { value: !0 }), e);
@@ -23,59 +23,83 @@ O(S, {
23
23
  });
24
24
  module.exports = L(S);
25
25
 
26
+ // packages/adapter/src/controllers/Adapter.ts
27
+ var I = require("@asterflow/response");
28
+
26
29
  // packages/adapter/src/types/adapter.ts
27
- var B = require("@asterflow/router"), N = require("express"), i = /* @__PURE__ */ ((s) => (s.Bun = "bun", s.Express = "express", s.Node = "node", s.Fastify = "fastify", s))(i || {});
30
+ var i = /* @__PURE__ */ ((r) => (r.Bun = "bun", r.Express = "express", r.Node = "node", r.Fastify = "fastify", r))(i || {});
28
31
 
29
32
  // packages/adapter/src/controllers/Adapter.ts
30
- var U = require("@asterflow/router"), o = class {
33
+ var o = class {
31
34
  runtime;
32
35
  listen;
33
36
  onRequest = void 0;
34
- constructor({ runtime: t, listen: r }) {
35
- this.runtime = t, this.listen = r;
37
+ constructor({ runtime: t, listen: s }) {
38
+ this.runtime = t, this.listen = s;
36
39
  }
37
40
  };
38
41
 
39
42
  // packages/adapter/src/adapters/bun.ts
40
43
  var m = require("@asterflow/request");
41
- var f = require("@asterflow/router"), d = new o({
44
+ var f = require("@asterflow/response"), d = new o({
42
45
  runtime: "bun",
43
46
  listen(e, t) {
44
47
  try {
45
48
  Bun.serve({
46
49
  ...e,
47
- fetch: async (r) => this.onRequest ? (await this.onRequest(new m.BunRequest(r))).toResponse() : new f.Response().notFound({
50
+ fetch: async (s) => this.onRequest ? (await this.onRequest(new m.BunRequest(s))).toResponse() : new f.Response().notFound({
48
51
  statusCode: 500,
49
52
  error: "Internal Server Error",
50
53
  message: "The onRequest() function must be defined before the listen() function."
51
54
  }).toResponse()
52
55
  }), t?.(null);
53
- } catch (r) {
54
- t?.(r);
56
+ } catch (s) {
57
+ t?.(s);
55
58
  }
56
59
  }
57
60
  });
58
61
 
62
+ // packages/adapter/src/adapters/express.ts
63
+ var z = require("express"), l = require("@asterflow/response");
64
+ var y = require("@asterflow/request"), R = new o({
65
+ runtime: "express",
66
+ listen(e, ...t) {
67
+ return e.all("/{*path}", async (s, n) => {
68
+ if (!this.onRequest) {
69
+ let p = new l.Response().notFound({
70
+ statusCode: 500,
71
+ error: "Internal Server Error",
72
+ message: "The onRequest() function must be defined before the listen() function."
73
+ }).toResponse();
74
+ n.status(p.status).set(Object.fromEntries(p.headers)).send(await p.text());
75
+ return;
76
+ }
77
+ let r = (await this.onRequest(new y.ExpressRequest(s))).toResponse();
78
+ n.status(r.status).set(Object.fromEntries(r.headers)).send(await r.text());
79
+ }), e.listen(...t), e;
80
+ }
81
+ });
82
+
59
83
  // packages/adapter/src/adapters/fastify.ts
60
- var l = require("@asterflow/router");
61
- var R = require("@asterflow/request"), y = new o({
84
+ var c = require("@asterflow/response");
85
+ var x = require("@asterflow/request"), E = new o({
62
86
  runtime: "fastify",
63
- listen(e, t, r) {
64
- e.all("*", async (n) => this.onRequest ? (await this.onRequest(new R.FastifyRequest(n))).toResponse() : new l.Response().notFound({
87
+ listen(e, t, s) {
88
+ e.all("*", async (n) => this.onRequest ? (await this.onRequest(new x.FastifyRequest(n))).toResponse() : new c.Response().notFound({
65
89
  statusCode: 500,
66
90
  error: "Internal Server Error",
67
91
  message: "The onRequest() function must be defined before the listen() function."
68
- })), e.listen(t, r);
92
+ })), e.listen(t, s);
69
93
  }
70
94
  });
71
95
 
72
96
  // packages/adapter/src/adapters/node.ts
73
- var x = require("http"), E = require("@asterflow/router");
74
- var q = require("@asterflow/request");
97
+ var h = require("http"), g = require("@asterflow/response");
98
+ var v = require("@asterflow/request");
75
99
 
76
100
  // packages/adapter/src/utils/errorHandler.ts
77
- var u = require("@asterflow/router");
78
- function c(e) {
101
+ var u = require("@asterflow/response");
102
+ function q(e) {
79
103
  let t;
80
104
  return e instanceof u.Response ? e : (e instanceof Error ? t = {
81
105
  statusCode: 500,
@@ -96,51 +120,30 @@ function c(e) {
96
120
  }
97
121
 
98
122
  // packages/adapter/src/adapters/node.ts
99
- var h = new o({
123
+ var b = new o({
100
124
  runtime: "node",
101
125
  listen(e, t) {
102
126
  try {
103
- (0, x.createServer)(async (r, n) => {
104
- if (!this.onRequest) return new E.Response().notFound({
127
+ (0, h.createServer)(async (s, n) => {
128
+ if (!this.onRequest) return new g.Response().notFound({
105
129
  statusCode: 500,
106
130
  error: "Internal Server Error",
107
131
  message: "The onRequest() function must be defined before the listen() function."
108
132
  });
109
133
  try {
110
- return (await this.onRequest(new q.NodeRequest(r))).toServerResponse(n);
111
- } catch (s) {
112
- return c(s).toServerResponse(n);
134
+ return (await this.onRequest(new v.NodeRequest(s))).toServerResponse(n);
135
+ } catch (r) {
136
+ return q(r).toServerResponse(n);
113
137
  }
114
138
  }).listen(e), t?.(null);
115
- } catch (r) {
116
- t?.(r);
139
+ } catch (s) {
140
+ t?.(s);
117
141
  }
118
142
  }
119
143
  });
120
144
 
121
- // packages/adapter/src/adapters/express.ts
122
- var $ = require("express"), g = require("@asterflow/router");
123
- var v = require("@asterflow/request"), b = new o({
124
- runtime: "express",
125
- listen(e, ...t) {
126
- return e.all("/{*path}", async (r, n) => {
127
- if (!this.onRequest) {
128
- let p = new g.Response().notFound({
129
- statusCode: 500,
130
- error: "Internal Server Error",
131
- message: "The onRequest() function must be defined before the listen() function."
132
- }).toResponse();
133
- n.status(p.status).set(Object.fromEntries(p.headers)).send(await p.text());
134
- return;
135
- }
136
- let s = (await this.onRequest(new v.ExpressRequest(r))).toResponse();
137
- n.status(s.status).set(Object.fromEntries(s.headers)).send(await s.text());
138
- }), e.listen(...t), e;
139
- }
140
- });
141
-
142
145
  // packages/adapter/src/index.ts
143
- var A = { bun: d, fastify: y, node: h, express: b };
146
+ var A = { bun: d, fastify: E, node: b, express: R };
144
147
  // Annotate the CommonJS export names for ESM import in node:
145
148
  0 && (module.exports = {
146
149
  Adapter,
package/dist/mjs/index.js CHANGED
@@ -1,64 +1,87 @@
1
+ // packages/adapter/src/controllers/Adapter.ts
2
+ import "@asterflow/response";
3
+
1
4
  // packages/adapter/src/types/adapter.ts
2
- import "@asterflow/router";
3
- import "express";
4
- var i = /* @__PURE__ */ ((s) => (s.Bun = "bun", s.Express = "express", s.Node = "node", s.Fastify = "fastify", s))(i || {});
5
+ var i = /* @__PURE__ */ ((r) => (r.Bun = "bun", r.Express = "express", r.Node = "node", r.Fastify = "fastify", r))(i || {});
5
6
 
6
7
  // packages/adapter/src/controllers/Adapter.ts
7
- import "@asterflow/router";
8
8
  var o = class {
9
9
  runtime;
10
10
  listen;
11
11
  onRequest = void 0;
12
- constructor({ runtime: t, listen: r }) {
13
- this.runtime = t, this.listen = r;
12
+ constructor({ runtime: t, listen: s }) {
13
+ this.runtime = t, this.listen = s;
14
14
  }
15
15
  };
16
16
 
17
17
  // packages/adapter/src/adapters/bun.ts
18
- import { BunRequest as R } from "@asterflow/request";
19
- import { Response as y } from "@asterflow/router";
18
+ import { BunRequest as y } from "@asterflow/request";
19
+ import { Response as R } from "@asterflow/response";
20
20
  var a = new o({
21
21
  runtime: "bun",
22
22
  listen(e, t) {
23
23
  try {
24
24
  Bun.serve({
25
25
  ...e,
26
- fetch: async (r) => this.onRequest ? (await this.onRequest(new R(r))).toResponse() : new y().notFound({
26
+ fetch: async (s) => this.onRequest ? (await this.onRequest(new y(s))).toResponse() : new R().notFound({
27
27
  statusCode: 500,
28
28
  error: "Internal Server Error",
29
29
  message: "The onRequest() function must be defined before the listen() function."
30
30
  }).toResponse()
31
31
  }), t?.(null);
32
- } catch (r) {
33
- t?.(r);
32
+ } catch (s) {
33
+ t?.(s);
34
34
  }
35
35
  }
36
36
  });
37
37
 
38
- // packages/adapter/src/adapters/fastify.ts
39
- import { Response as c } from "@asterflow/router";
40
- import { FastifyRequest as x } from "@asterflow/request";
38
+ // packages/adapter/src/adapters/express.ts
39
+ import "express";
40
+ import { Response as c } from "@asterflow/response";
41
+ import { ExpressRequest as x } from "@asterflow/request";
41
42
  var u = new o({
43
+ runtime: "express",
44
+ listen(e, ...t) {
45
+ return e.all("/{*path}", async (s, n) => {
46
+ if (!this.onRequest) {
47
+ let p = new c().notFound({
48
+ statusCode: 500,
49
+ error: "Internal Server Error",
50
+ message: "The onRequest() function must be defined before the listen() function."
51
+ }).toResponse();
52
+ n.status(p.status).set(Object.fromEntries(p.headers)).send(await p.text());
53
+ return;
54
+ }
55
+ let r = (await this.onRequest(new x(s))).toResponse();
56
+ n.status(r.status).set(Object.fromEntries(r.headers)).send(await r.text());
57
+ }), e.listen(...t), e;
58
+ }
59
+ });
60
+
61
+ // packages/adapter/src/adapters/fastify.ts
62
+ import { Response as E } from "@asterflow/response";
63
+ import { FastifyRequest as q } from "@asterflow/request";
64
+ var m = new o({
42
65
  runtime: "fastify",
43
- listen(e, t, r) {
44
- e.all("*", async (n) => this.onRequest ? (await this.onRequest(new x(n))).toResponse() : new c().notFound({
66
+ listen(e, t, s) {
67
+ e.all("*", async (n) => this.onRequest ? (await this.onRequest(new q(n))).toResponse() : new E().notFound({
45
68
  statusCode: 500,
46
69
  error: "Internal Server Error",
47
70
  message: "The onRequest() function must be defined before the listen() function."
48
- })), e.listen(t, r);
71
+ })), e.listen(t, s);
49
72
  }
50
73
  });
51
74
 
52
75
  // packages/adapter/src/adapters/node.ts
53
- import { createServer as E } from "http";
54
- import { Response as q } from "@asterflow/router";
55
- import { NodeRequest as h } from "@asterflow/request";
76
+ import { createServer as h } from "http";
77
+ import { Response as g } from "@asterflow/response";
78
+ import { NodeRequest as v } from "@asterflow/request";
56
79
 
57
80
  // packages/adapter/src/utils/errorHandler.ts
58
- import { Response as m } from "@asterflow/router";
59
- function f(e) {
81
+ import { Response as f } from "@asterflow/response";
82
+ function d(e) {
60
83
  let t;
61
- return e instanceof m ? e : (e instanceof Error ? t = {
84
+ return e instanceof f ? e : (e instanceof Error ? t = {
62
85
  statusCode: 500,
63
86
  error: e.name,
64
87
  message: e.message,
@@ -69,7 +92,7 @@ function f(e) {
69
92
  error: "InternalServerError",
70
93
  message: typeof e == "string" ? e : "An unexpected error occurred.",
71
94
  details: e
72
- }, console.error("Unhandled exception in adapter:", e), new m().status(t.statusCode).json({
95
+ }, console.error("Unhandled exception in adapter:", e), new f().status(t.statusCode).json({
73
96
  error: t.error,
74
97
  message: t.message,
75
98
  ...t.details ? { details: t.details } : {}
@@ -77,55 +100,32 @@ function f(e) {
77
100
  }
78
101
 
79
102
  // packages/adapter/src/adapters/node.ts
80
- var d = new o({
103
+ var l = new o({
81
104
  runtime: "node",
82
105
  listen(e, t) {
83
106
  try {
84
- E(async (r, n) => {
85
- if (!this.onRequest) return new q().notFound({
107
+ h(async (s, n) => {
108
+ if (!this.onRequest) return new g().notFound({
86
109
  statusCode: 500,
87
110
  error: "Internal Server Error",
88
111
  message: "The onRequest() function must be defined before the listen() function."
89
112
  });
90
113
  try {
91
- return (await this.onRequest(new h(r))).toServerResponse(n);
92
- } catch (s) {
93
- return f(s).toServerResponse(n);
114
+ return (await this.onRequest(new v(s))).toServerResponse(n);
115
+ } catch (r) {
116
+ return d(r).toServerResponse(n);
94
117
  }
95
118
  }).listen(e), t?.(null);
96
- } catch (r) {
97
- t?.(r);
119
+ } catch (s) {
120
+ t?.(s);
98
121
  }
99
122
  }
100
123
  });
101
124
 
102
- // packages/adapter/src/adapters/express.ts
103
- import "express";
104
- import { Response as g } from "@asterflow/router";
105
- import { ExpressRequest as v } from "@asterflow/request";
106
- var l = new o({
107
- runtime: "express",
108
- listen(e, ...t) {
109
- return e.all("/{*path}", async (r, n) => {
110
- if (!this.onRequest) {
111
- let p = new g().notFound({
112
- statusCode: 500,
113
- error: "Internal Server Error",
114
- message: "The onRequest() function must be defined before the listen() function."
115
- }).toResponse();
116
- n.status(p.status).set(Object.fromEntries(p.headers)).send(await p.text());
117
- return;
118
- }
119
- let s = (await this.onRequest(new v(r))).toResponse();
120
- n.status(s.status).set(Object.fromEntries(s.headers)).send(await s.text());
121
- }), e.listen(...t), e;
122
- }
123
- });
124
-
125
125
  // packages/adapter/src/index.ts
126
- var pe = { bun: a, fastify: u, node: d, express: l };
126
+ var oe = { bun: a, fastify: m, node: l, express: u };
127
127
  export {
128
128
  o as Adapter,
129
129
  i as Runtime,
130
- pe as adapters
130
+ oe as adapters
131
131
  };
@@ -1,6 +1,6 @@
1
1
  import type { Request } from '@asterflow/request';
2
+ import { Response as ResponseCustom } from '@asterflow/response';
2
3
  import { Runtime, type OptionsDriver } from '../types/adapter';
3
- import { Response as ResponseCustom } from '@asterflow/router';
4
4
  export declare class Adapter<Type extends Runtime> {
5
5
  readonly runtime: Type;
6
6
  readonly listen: OptionsDriver<Type>['listen'];
@@ -1,7 +1,7 @@
1
1
  import type { Request } from '@asterflow/request';
2
- import { Response as ResponseCustom } from '@asterflow/router';
2
+ import type { Response as ResponseCustom } from '@asterflow/response';
3
3
  import type { ServeOptions as BunServeOptions } from 'bun';
4
- import { type Express } from 'express';
4
+ import type { Express } from 'express';
5
5
  import type { FastifyInstance, FastifyListenOptions } from 'fastify';
6
6
  import type { ListenOptions } from 'net';
7
7
  export declare enum Runtime {
@@ -1,4 +1,4 @@
1
- import { Response } from '@asterflow/router';
1
+ import { Response } from '@asterflow/response';
2
2
  /**
3
3
  * Turn any thrown value into a Response.
4
4
  */
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@asterflow/adapter",
3
- "version": "1.0.2",
3
+ "version": "1.0.4",
4
4
  "main": "dist/cjs/index.cjs",
5
5
  "module": "dist/mjs/index.js",
6
6
  "types": "dist/types/index.d.ts",
@@ -27,16 +27,17 @@
27
27
  "node": ">=20"
28
28
  },
29
29
  "devDependencies": {
30
+ "@types/express": "^5.0.3",
30
31
  "@types/bun": "^1.2.15",
31
- "fastify": "^5.3.3",
32
- "@asterflow/router": "1.0.2",
33
- "@asterflow/request": "1.0.2"
32
+ "@asterflow/router": "1.0.4",
33
+ "@asterflow/request": "1.0.4"
34
34
  },
35
35
  "peerDependencies": {
36
+ "fastify": "^5.3.3",
37
+ "express": "^5.1.0",
36
38
  "typescript": "^5.8.3"
37
39
  },
38
40
  "dependencies": {
39
- "@types/express": "^5.0.3",
40
- "express": "^5.1.0"
41
+ "@asterflow/response": "1.0.1"
41
42
  }
42
43
  }