@asterflow/adapter 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 +64 -67
- package/dist/mjs/index.js +56 -55
- package/package.json +7 -8
package/README.md
CHANGED
|
@@ -2,14 +2,14 @@
|
|
|
2
2
|
|
|
3
3
|
# @asterflow/adapter
|
|
4
4
|
|
|
5
|
-

|
|
6
|
+

|
|
7
7
|
|
|
8
|
-

|
|
9
|
+

|
|
10
|
+

|
|
11
11
|
|
|
12
|
-

|
|
13
13
|

|
|
14
14
|
|
|
15
15
|
</div>
|
|
@@ -183,7 +183,8 @@ interface ErrorPayload {
|
|
|
183
183
|
- [@asterflow/router](https://www.npmjs.com/package/@asterflow/router) - Type-safe routing system
|
|
184
184
|
- [@asterflow/request](https://www.npmjs.com/package/@asterflow/request) - Unified HTTP request system
|
|
185
185
|
- [@asterflow/response](https://www.npmjs.com/package/@asterflow/response) - Type-safe HTTP response system
|
|
186
|
+
- [@asterflow/plugin](https://www.npmjs.com/package/@asterflow/plugin) - A modular and typed plugin system
|
|
186
187
|
|
|
187
188
|
## 📄 License
|
|
188
189
|
|
|
189
|
-
MIT - See [LICENSE](https://github.com/
|
|
190
|
+
MIT - See [LICENSE](https://github.com/AsterFlow/AsterFlow/blob/main/LICENSE) for more details.
|
package/dist/cjs/index.cjs
CHANGED
|
@@ -1,111 +1,108 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
var a = Object.defineProperty;
|
|
3
|
-
var
|
|
4
|
-
var
|
|
5
|
-
var
|
|
6
|
-
var
|
|
7
|
-
for (var
|
|
8
|
-
a(e,
|
|
9
|
-
},
|
|
3
|
+
var F = Object.getOwnPropertyDescriptor;
|
|
4
|
+
var O = Object.getOwnPropertyNames;
|
|
5
|
+
var C = Object.prototype.hasOwnProperty;
|
|
6
|
+
var L = (e, t) => {
|
|
7
|
+
for (var r in t)
|
|
8
|
+
a(e, r, { get: t[r], enumerable: !0 });
|
|
9
|
+
}, A = (e, t, r, o) => {
|
|
10
10
|
if (t && typeof t == "object" || typeof t == "function")
|
|
11
|
-
for (let
|
|
12
|
-
!
|
|
11
|
+
for (let s of O(t))
|
|
12
|
+
!C.call(e, s) && s !== r && a(e, s, { get: () => t[s], enumerable: !(o = F(t, s)) || o.enumerable });
|
|
13
13
|
return e;
|
|
14
14
|
};
|
|
15
|
-
var
|
|
16
|
-
|
|
15
|
+
var S = (e) => A(a({}, "__esModule", { value: !0 }), e);
|
|
17
16
|
// packages/adapter/src/index.ts
|
|
18
|
-
var
|
|
19
|
-
|
|
20
|
-
Adapter: () =>
|
|
21
|
-
Runtime: () =>
|
|
22
|
-
adapters: () =>
|
|
17
|
+
var I = {};
|
|
18
|
+
L(I, {
|
|
19
|
+
Adapter: () => n,
|
|
20
|
+
Runtime: () => p,
|
|
21
|
+
adapters: () => B
|
|
23
22
|
});
|
|
24
|
-
module.exports =
|
|
25
|
-
|
|
23
|
+
module.exports = S(I);
|
|
26
24
|
// packages/adapter/src/controllers/Adapter.ts
|
|
27
|
-
var
|
|
28
|
-
|
|
25
|
+
var N = require("@asterflow/response");
|
|
29
26
|
// packages/adapter/src/types/adapter.ts
|
|
30
|
-
var
|
|
31
|
-
|
|
27
|
+
var p = ((s) => (s.Bun = "bun", s.Express = "express", s.Node = "node", s.Fastify = "fastify", s))(p || {});
|
|
32
28
|
// packages/adapter/src/controllers/Adapter.ts
|
|
33
|
-
var
|
|
29
|
+
var n = class {
|
|
34
30
|
runtime;
|
|
35
31
|
listen;
|
|
36
32
|
onRequest = void 0;
|
|
37
|
-
constructor({ runtime: t, listen:
|
|
38
|
-
this.runtime = t, this.listen =
|
|
33
|
+
constructor({ runtime: t, listen: r }) {
|
|
34
|
+
this.runtime = t, this.listen = r;
|
|
39
35
|
}
|
|
40
36
|
};
|
|
41
|
-
|
|
42
37
|
// packages/adapter/src/adapters/bun.ts
|
|
43
|
-
var
|
|
44
|
-
var
|
|
38
|
+
var f = require("@asterflow/request"), d = require("@asterflow/response");
|
|
39
|
+
var l = new n({
|
|
45
40
|
runtime: "bun",
|
|
46
41
|
listen(e, t) {
|
|
47
42
|
try {
|
|
48
43
|
Bun.serve({
|
|
49
44
|
...e,
|
|
50
|
-
fetch: async (
|
|
45
|
+
fetch: async (r) => this.onRequest ? (await this.onRequest(new f.BunRequest(r))).toResponse() : new d.Response().notFound({
|
|
51
46
|
statusCode: 500,
|
|
52
47
|
error: "Internal Server Error",
|
|
53
48
|
message: "The onRequest() function must be defined before the listen() function."
|
|
54
49
|
}).toResponse()
|
|
55
50
|
}), t?.(null);
|
|
56
|
-
} catch (
|
|
57
|
-
t?.(
|
|
51
|
+
} catch (r) {
|
|
52
|
+
t?.(r);
|
|
58
53
|
}
|
|
59
54
|
}
|
|
60
55
|
});
|
|
61
|
-
|
|
62
56
|
// packages/adapter/src/adapters/express.ts
|
|
63
|
-
var
|
|
64
|
-
var
|
|
57
|
+
var y = require("@asterflow/request"), R = require("@asterflow/response"), H = require("express");
|
|
58
|
+
var c = new n({
|
|
65
59
|
runtime: "express",
|
|
66
60
|
listen(e, ...t) {
|
|
67
|
-
return e.all("/{*path}", async (
|
|
61
|
+
return e.all("/{*path}", async (r, o) => {
|
|
68
62
|
if (!this.onRequest) {
|
|
69
|
-
let
|
|
63
|
+
let i = new R.Response().notFound({
|
|
70
64
|
statusCode: 500,
|
|
71
65
|
error: "Internal Server Error",
|
|
72
66
|
message: "The onRequest() function must be defined before the listen() function."
|
|
73
67
|
}).toResponse();
|
|
74
|
-
|
|
68
|
+
o.status(i.status).set(Object.fromEntries(i.headers)).send(await i.text());
|
|
75
69
|
return;
|
|
76
70
|
}
|
|
77
|
-
let
|
|
78
|
-
|
|
79
|
-
}),
|
|
71
|
+
let s = (await this.onRequest(new y.ExpressRequest(r))).toResponse();
|
|
72
|
+
o.status(s.status).set(Object.fromEntries(s.headers)).send(await s.text());
|
|
73
|
+
}), new Promise((r, o) => {
|
|
74
|
+
e.listen(...t, () => r()).on("error", (i) => o(i));
|
|
75
|
+
});
|
|
80
76
|
}
|
|
81
77
|
});
|
|
82
|
-
|
|
83
78
|
// packages/adapter/src/adapters/fastify.ts
|
|
84
|
-
var
|
|
85
|
-
var
|
|
79
|
+
var x = require("@asterflow/request"), E = require("@asterflow/response");
|
|
80
|
+
var q = new n({
|
|
86
81
|
runtime: "fastify",
|
|
87
|
-
listen(e, t,
|
|
88
|
-
e.all("*", async (
|
|
82
|
+
async listen(e, t, r) {
|
|
83
|
+
e.all("*", async (o) => this.onRequest ? (await this.onRequest(new x.FastifyRequest(o))).toResponse() : new E.Response().notFound({
|
|
89
84
|
statusCode: 500,
|
|
90
85
|
error: "Internal Server Error",
|
|
91
86
|
message: "The onRequest() function must be defined before the listen() function."
|
|
92
|
-
}))
|
|
87
|
+
}));
|
|
88
|
+
try {
|
|
89
|
+
let o = await e.listen(t);
|
|
90
|
+
r?.(null, o);
|
|
91
|
+
} catch (o) {
|
|
92
|
+
r?.(o, "");
|
|
93
|
+
}
|
|
93
94
|
}
|
|
94
95
|
});
|
|
95
|
-
|
|
96
96
|
// packages/adapter/src/adapters/node.ts
|
|
97
|
-
var
|
|
98
|
-
var v = require("@asterflow/request");
|
|
99
|
-
|
|
97
|
+
var v = require("@asterflow/request"), w = require("@asterflow/response"), g = require("http");
|
|
100
98
|
// packages/adapter/src/utils/errorHandler.ts
|
|
101
99
|
var u = require("@asterflow/response");
|
|
102
|
-
function
|
|
100
|
+
function h(e) {
|
|
103
101
|
let t;
|
|
104
102
|
return e instanceof u.Response ? e : (e instanceof Error ? t = {
|
|
105
103
|
statusCode: 500,
|
|
106
104
|
error: e.name,
|
|
107
105
|
message: e.message,
|
|
108
|
-
// Optionally attach stack in non-prod
|
|
109
106
|
details: process.env.NODE_ENV !== "production" ? e.stack : void 0
|
|
110
107
|
} : t = {
|
|
111
108
|
statusCode: 500,
|
|
@@ -118,33 +115,33 @@ function q(e) {
|
|
|
118
115
|
...t.details ? { details: t.details } : {}
|
|
119
116
|
}));
|
|
120
117
|
}
|
|
121
|
-
|
|
122
118
|
// packages/adapter/src/adapters/node.ts
|
|
123
|
-
var b = new
|
|
119
|
+
var b = new n({
|
|
124
120
|
runtime: "node",
|
|
125
121
|
listen(e, t) {
|
|
126
|
-
|
|
127
|
-
(0,
|
|
128
|
-
if (!this.onRequest) return new
|
|
122
|
+
return new Promise((r, o) => {
|
|
123
|
+
let s = (0, g.createServer)(async (i, m) => {
|
|
124
|
+
if (!this.onRequest) return new w.Response().notFound({
|
|
129
125
|
statusCode: 500,
|
|
130
126
|
error: "Internal Server Error",
|
|
131
127
|
message: "The onRequest() function must be defined before the listen() function."
|
|
132
128
|
});
|
|
133
129
|
try {
|
|
134
|
-
return (await this.onRequest(new v.NodeRequest(
|
|
135
|
-
} catch (
|
|
136
|
-
return
|
|
130
|
+
return (await this.onRequest(new v.NodeRequest(i))).toServerResponse(m);
|
|
131
|
+
} catch (T) {
|
|
132
|
+
return h(T).toServerResponse(m);
|
|
137
133
|
}
|
|
138
|
-
})
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
134
|
+
});
|
|
135
|
+
s.on("error", (i) => {
|
|
136
|
+
t?.(i), o(i);
|
|
137
|
+
}), s.listen(e, () => {
|
|
138
|
+
t?.(null), r();
|
|
139
|
+
});
|
|
140
|
+
});
|
|
142
141
|
}
|
|
143
142
|
});
|
|
144
|
-
|
|
145
143
|
// packages/adapter/src/index.ts
|
|
146
|
-
var
|
|
147
|
-
// Annotate the CommonJS export names for ESM import in node:
|
|
144
|
+
var B = { bun: l, fastify: q, node: b, express: c };
|
|
148
145
|
0 && (module.exports = {
|
|
149
146
|
Adapter,
|
|
150
147
|
Runtime,
|
package/dist/mjs/index.js
CHANGED
|
@@ -1,131 +1,132 @@
|
|
|
1
1
|
// packages/adapter/src/controllers/Adapter.ts
|
|
2
2
|
import "@asterflow/response";
|
|
3
|
-
|
|
4
3
|
// packages/adapter/src/types/adapter.ts
|
|
5
|
-
var
|
|
6
|
-
|
|
4
|
+
var p = ((o) => (o.Bun = "bun", o.Express = "express", o.Node = "node", o.Fastify = "fastify", o))(p || {});
|
|
7
5
|
// packages/adapter/src/controllers/Adapter.ts
|
|
8
|
-
var
|
|
6
|
+
var i = class {
|
|
9
7
|
runtime;
|
|
10
8
|
listen;
|
|
11
9
|
onRequest = void 0;
|
|
12
|
-
constructor({ runtime: t, listen:
|
|
13
|
-
this.runtime = t, this.listen =
|
|
10
|
+
constructor({ runtime: t, listen: r }) {
|
|
11
|
+
this.runtime = t, this.listen = r;
|
|
14
12
|
}
|
|
15
13
|
};
|
|
16
|
-
|
|
17
14
|
// packages/adapter/src/adapters/bun.ts
|
|
18
|
-
import { BunRequest as
|
|
19
|
-
import { Response as
|
|
20
|
-
var
|
|
15
|
+
import { BunRequest as c } from "@asterflow/request";
|
|
16
|
+
import { Response as x } from "@asterflow/response";
|
|
17
|
+
var u = new i({
|
|
21
18
|
runtime: "bun",
|
|
22
19
|
listen(e, t) {
|
|
23
20
|
try {
|
|
24
21
|
Bun.serve({
|
|
25
22
|
...e,
|
|
26
|
-
fetch: async (
|
|
23
|
+
fetch: async (r) => this.onRequest ? (await this.onRequest(new c(r))).toResponse() : new x().notFound({
|
|
27
24
|
statusCode: 500,
|
|
28
25
|
error: "Internal Server Error",
|
|
29
26
|
message: "The onRequest() function must be defined before the listen() function."
|
|
30
27
|
}).toResponse()
|
|
31
28
|
}), t?.(null);
|
|
32
|
-
} catch (
|
|
33
|
-
t?.(
|
|
29
|
+
} catch (r) {
|
|
30
|
+
t?.(r);
|
|
34
31
|
}
|
|
35
32
|
}
|
|
36
33
|
});
|
|
37
|
-
|
|
38
34
|
// packages/adapter/src/adapters/express.ts
|
|
35
|
+
import { ExpressRequest as E } from "@asterflow/request";
|
|
36
|
+
import { Response as q } from "@asterflow/response";
|
|
39
37
|
import "express";
|
|
40
|
-
|
|
41
|
-
import { ExpressRequest as x } from "@asterflow/request";
|
|
42
|
-
var u = new o({
|
|
38
|
+
var m = new i({
|
|
43
39
|
runtime: "express",
|
|
44
40
|
listen(e, ...t) {
|
|
45
|
-
return e.all("/{*path}", async (
|
|
41
|
+
return e.all("/{*path}", async (r, s) => {
|
|
46
42
|
if (!this.onRequest) {
|
|
47
|
-
let
|
|
43
|
+
let n = new q().notFound({
|
|
48
44
|
statusCode: 500,
|
|
49
45
|
error: "Internal Server Error",
|
|
50
46
|
message: "The onRequest() function must be defined before the listen() function."
|
|
51
47
|
}).toResponse();
|
|
52
|
-
|
|
48
|
+
s.status(n.status).set(Object.fromEntries(n.headers)).send(await n.text());
|
|
53
49
|
return;
|
|
54
50
|
}
|
|
55
|
-
let
|
|
56
|
-
|
|
57
|
-
}),
|
|
51
|
+
let o = (await this.onRequest(new E(r))).toResponse();
|
|
52
|
+
s.status(o.status).set(Object.fromEntries(o.headers)).send(await o.text());
|
|
53
|
+
}), new Promise((r, s) => {
|
|
54
|
+
e.listen(...t, () => r()).on("error", (n) => s(n));
|
|
55
|
+
});
|
|
58
56
|
}
|
|
59
57
|
});
|
|
60
|
-
|
|
61
58
|
// packages/adapter/src/adapters/fastify.ts
|
|
62
|
-
import {
|
|
63
|
-
import {
|
|
64
|
-
var
|
|
59
|
+
import { FastifyRequest as h } from "@asterflow/request";
|
|
60
|
+
import { Response as v } from "@asterflow/response";
|
|
61
|
+
var f = new i({
|
|
65
62
|
runtime: "fastify",
|
|
66
|
-
listen(e, t,
|
|
67
|
-
e.all("*", async (
|
|
63
|
+
async listen(e, t, r) {
|
|
64
|
+
e.all("*", async (s) => this.onRequest ? (await this.onRequest(new h(s))).toResponse() : new v().notFound({
|
|
68
65
|
statusCode: 500,
|
|
69
66
|
error: "Internal Server Error",
|
|
70
67
|
message: "The onRequest() function must be defined before the listen() function."
|
|
71
|
-
}))
|
|
68
|
+
}));
|
|
69
|
+
try {
|
|
70
|
+
let s = await e.listen(t);
|
|
71
|
+
r?.(null, s);
|
|
72
|
+
} catch (s) {
|
|
73
|
+
r?.(s, "");
|
|
74
|
+
}
|
|
72
75
|
}
|
|
73
76
|
});
|
|
74
|
-
|
|
75
77
|
// packages/adapter/src/adapters/node.ts
|
|
76
|
-
import {
|
|
78
|
+
import { NodeRequest as w } from "@asterflow/request";
|
|
77
79
|
import { Response as g } from "@asterflow/response";
|
|
78
|
-
import {
|
|
79
|
-
|
|
80
|
+
import { createServer as b } from "http";
|
|
80
81
|
// packages/adapter/src/utils/errorHandler.ts
|
|
81
|
-
import { Response as
|
|
82
|
-
function
|
|
82
|
+
import { Response as d } from "@asterflow/response";
|
|
83
|
+
function l(e) {
|
|
83
84
|
let t;
|
|
84
|
-
return e instanceof
|
|
85
|
+
return e instanceof d ? e : (e instanceof Error ? t = {
|
|
85
86
|
statusCode: 500,
|
|
86
87
|
error: e.name,
|
|
87
88
|
message: e.message,
|
|
88
|
-
// Optionally attach stack in non-prod
|
|
89
89
|
details: process.env.NODE_ENV !== "production" ? e.stack : void 0
|
|
90
90
|
} : t = {
|
|
91
91
|
statusCode: 500,
|
|
92
92
|
error: "InternalServerError",
|
|
93
93
|
message: typeof e == "string" ? e : "An unexpected error occurred.",
|
|
94
94
|
details: e
|
|
95
|
-
}, console.error("Unhandled exception in adapter:", e), new
|
|
95
|
+
}, console.error("Unhandled exception in adapter:", e), new d().status(t.statusCode).json({
|
|
96
96
|
error: t.error,
|
|
97
97
|
message: t.message,
|
|
98
98
|
...t.details ? { details: t.details } : {}
|
|
99
99
|
}));
|
|
100
100
|
}
|
|
101
|
-
|
|
102
101
|
// packages/adapter/src/adapters/node.ts
|
|
103
|
-
var
|
|
102
|
+
var y = new i({
|
|
104
103
|
runtime: "node",
|
|
105
104
|
listen(e, t) {
|
|
106
|
-
|
|
107
|
-
|
|
105
|
+
return new Promise((r, s) => {
|
|
106
|
+
let o = b(async (n, a) => {
|
|
108
107
|
if (!this.onRequest) return new g().notFound({
|
|
109
108
|
statusCode: 500,
|
|
110
109
|
error: "Internal Server Error",
|
|
111
110
|
message: "The onRequest() function must be defined before the listen() function."
|
|
112
111
|
});
|
|
113
112
|
try {
|
|
114
|
-
return (await this.onRequest(new
|
|
115
|
-
} catch (
|
|
116
|
-
return
|
|
113
|
+
return (await this.onRequest(new w(n))).toServerResponse(a);
|
|
114
|
+
} catch (R) {
|
|
115
|
+
return l(R).toServerResponse(a);
|
|
117
116
|
}
|
|
118
|
-
})
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
117
|
+
});
|
|
118
|
+
o.on("error", (n) => {
|
|
119
|
+
t?.(n), s(n);
|
|
120
|
+
}), o.listen(e, () => {
|
|
121
|
+
t?.(null), r();
|
|
122
|
+
});
|
|
123
|
+
});
|
|
122
124
|
}
|
|
123
125
|
});
|
|
124
|
-
|
|
125
126
|
// packages/adapter/src/index.ts
|
|
126
|
-
var
|
|
127
|
+
var ie = { bun: u, fastify: f, node: y, express: m };
|
|
127
128
|
export {
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
129
|
+
i as Adapter,
|
|
130
|
+
p as Runtime,
|
|
131
|
+
ie as adapters
|
|
131
132
|
};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@asterflow/adapter",
|
|
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",
|
|
@@ -10,12 +10,12 @@
|
|
|
10
10
|
"author": "Ashu11-A",
|
|
11
11
|
"repository": {
|
|
12
12
|
"type": "git",
|
|
13
|
-
"url": "git+https://github.com/
|
|
13
|
+
"url": "git+https://github.com/AsterFlow/AsterFlow.git"
|
|
14
14
|
},
|
|
15
15
|
"bugs": {
|
|
16
|
-
"url": "https://github.com/
|
|
16
|
+
"url": "https://github.com/AsterFlow/AsterFlow/issues"
|
|
17
17
|
},
|
|
18
|
-
"homepage": "https://github.com/
|
|
18
|
+
"homepage": "https://github.com/AsterFlow/AsterFlow",
|
|
19
19
|
"exports": {
|
|
20
20
|
".": {
|
|
21
21
|
"types": "./dist/types/index.d.ts",
|
|
@@ -28,9 +28,7 @@
|
|
|
28
28
|
},
|
|
29
29
|
"devDependencies": {
|
|
30
30
|
"@types/express": "^5.0.3",
|
|
31
|
-
"@
|
|
32
|
-
"@asterflow/router": "1.0.4",
|
|
33
|
-
"@asterflow/request": "1.0.4"
|
|
31
|
+
"@asterflow/router": "1.0.5"
|
|
34
32
|
},
|
|
35
33
|
"peerDependencies": {
|
|
36
34
|
"fastify": "^5.3.3",
|
|
@@ -38,6 +36,7 @@
|
|
|
38
36
|
"typescript": "^5.8.3"
|
|
39
37
|
},
|
|
40
38
|
"dependencies": {
|
|
41
|
-
"@asterflow/response": "1.0.
|
|
39
|
+
"@asterflow/response": "1.0.2",
|
|
40
|
+
"@asterflow/request": "1.0.5"
|
|
42
41
|
}
|
|
43
42
|
}
|