@asterflow/response 1.0.1 → 1.0.2

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/response
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/response?style=for-the-badge&colorA=302D41&colorB=3ac97b)
14
14
 
15
15
  </div>
@@ -208,7 +208,8 @@ const response = new Response()
208
208
  - [@asterflow/router](https://www.npmjs.com/package/@asterflow/router) - Type-safe routing system
209
209
  - [@asterflow/adapter](https://www.npmjs.com/package/@asterflow/adapter) - HTTP adapters for different runtimes
210
210
  - [@asterflow/request](https://www.npmjs.com/package/@asterflow/request) - Unified HTTP request system
211
+ - [@asterflow/plugin](https://www.npmjs.com/package/@asterflow/plugin) - A modular and typed plugin system
211
212
 
212
213
  ## 📄 License
213
214
 
214
- MIT - See [LICENSE](https://github.com/Ashu11-A/AsterFlow/blob/main/LICENSE) for more details.
215
+ MIT - See [LICENSE](https://github.com/AsterFlow/AsterFlow/blob/main/LICENSE) for more details.
@@ -1,26 +1,24 @@
1
1
  "use strict";
2
- var r = Object.defineProperty;
2
+ var a = Object.defineProperty;
3
3
  var d = Object.getOwnPropertyDescriptor;
4
4
  var p = Object.getOwnPropertyNames;
5
5
  var c = Object.prototype.hasOwnProperty;
6
6
  var h = (n, e) => {
7
7
  for (var t in e)
8
- r(n, t, { get: e[t], enumerable: !0 });
8
+ a(n, t, { get: e[t], enumerable: !0 });
9
9
  }, u = (n, e, t, s) => {
10
10
  if (e && typeof e == "object" || typeof e == "function")
11
11
  for (let o of p(e))
12
- !c.call(n, o) && o !== t && r(n, o, { get: () => e[o], enumerable: !(s = d(e, o)) || s.enumerable });
12
+ !c.call(n, o) && o !== t && a(n, o, { get: () => e[o], enumerable: !(s = d(e, o)) || s.enumerable });
13
13
  return n;
14
14
  };
15
- var M = (n) => u(r({}, "__esModule", { value: !0 }), n);
16
-
15
+ var M = (n) => u(a({}, "__esModule", { value: !0 }), n);
17
16
  // packages/response/src/index.ts
18
17
  var y = {};
19
18
  h(y, {
20
19
  Response: () => i
21
20
  });
22
21
  module.exports = M(y);
23
-
24
22
  // packages/response/src/controllers/Response.ts
25
23
  var i = class n {
26
24
  _status;
@@ -28,7 +26,7 @@ var i = class n {
28
26
  header;
29
27
  cookies;
30
28
  constructor(e) {
31
- this._status = e?.code ?? 200, this.body = e?.data, this.header = e?.header ?? /* @__PURE__ */ new Map(), this.cookies = e?.cookies ?? /* @__PURE__ */ new Map();
29
+ this._status = e?.code ?? 200, this.body = e?.data, this.header = e?.header ?? new Map(), this.cookies = e?.cookies ?? new Map();
32
30
  }
33
31
  clone(e) {
34
32
  return new n({
@@ -38,7 +36,6 @@ var i = class n {
38
36
  cookies: e.cookies !== void 0 ? e.cookies : this.cookies
39
37
  });
40
38
  }
41
- // --- Core Methods ---
42
39
  status(e) {
43
40
  return this.clone({ code: e });
44
41
  }
@@ -55,7 +52,6 @@ var i = class n {
55
52
  let t = new Map(this.header);
56
53
  return t.set("Content-Type", "application/json"), this.clone({ data: e, header: t });
57
54
  }
58
- // --- Response Helpers ---
59
55
  success(e) {
60
56
  return this.clone({ code: 200, data: e });
61
57
  }
@@ -68,9 +64,6 @@ var i = class n {
68
64
  badRequest(e) {
69
65
  return this.clone({ code: 400, data: e });
70
66
  }
71
- zodError(e) {
72
- return this.clone({ code: 422, data: e });
73
- }
74
67
  unauthorized(e) {
75
68
  return this.clone({ code: 401, data: e });
76
69
  }
@@ -80,6 +73,12 @@ var i = class n {
80
73
  notFound(e) {
81
74
  return this.clone({ code: 404, data: e });
82
75
  }
76
+ validationError(e) {
77
+ return this.clone({ code: 422, data: e });
78
+ }
79
+ internalServerError(e) {
80
+ return this.clone({ code: 500, data: e });
81
+ }
83
82
  setHeader(e, t) {
84
83
  let s = new Map(this.header);
85
84
  return s.set(e, t), this.clone({ header: s });
@@ -103,14 +102,13 @@ var i = class n {
103
102
  toServerResponse(e) {
104
103
  let t = new Headers();
105
104
  t.set("Content-Type", "text/plain");
106
- for (let [o, a] of this.header) t.set(o, a);
105
+ for (let [o, r] of this.header) t.set(o, r);
107
106
  (typeof this.body == "object" || Array.isArray(this.body)) && t.set("Content-Type", "application/json");
108
- for (let [o, a] of this.cookies) t.append("Set-Cookie", `${o}=${a}`);
107
+ for (let [o, r] of this.cookies) t.append("Set-Cookie", `${o}=${r}`);
109
108
  let s = t.get("Content-Type") === "application/json" ? JSON.stringify(this.body) : String(this.body);
110
109
  e.writeHead(this._status, Object.fromEntries(t)), e.end(s);
111
110
  }
112
111
  };
113
- // Annotate the CommonJS export names for ESM import in node:
114
112
  0 && (module.exports = {
115
113
  Response
116
114
  });
package/dist/mjs/index.js CHANGED
@@ -1,21 +1,20 @@
1
1
  // packages/response/src/controllers/Response.ts
2
- var a = class r {
2
+ var r = class a {
3
3
  _status;
4
4
  body;
5
5
  header;
6
6
  cookies;
7
7
  constructor(e) {
8
- this._status = e?.code ?? 200, this.body = e?.data, this.header = e?.header ?? /* @__PURE__ */ new Map(), this.cookies = e?.cookies ?? /* @__PURE__ */ new Map();
8
+ this._status = e?.code ?? 200, this.body = e?.data, this.header = e?.header ?? new Map(), this.cookies = e?.cookies ?? new Map();
9
9
  }
10
10
  clone(e) {
11
- return new r({
11
+ return new a({
12
12
  code: e.code !== void 0 ? e.code : this._status,
13
13
  data: e.data !== void 0 ? e.data : this.body,
14
14
  header: e.header !== void 0 ? e.header : this.header,
15
15
  cookies: e.cookies !== void 0 ? e.cookies : this.cookies
16
16
  });
17
17
  }
18
- // --- Core Methods ---
19
18
  status(e) {
20
19
  return this.clone({ code: e });
21
20
  }
@@ -32,7 +31,6 @@ var a = class r {
32
31
  let t = new Map(this.header);
33
32
  return t.set("Content-Type", "application/json"), this.clone({ data: e, header: t });
34
33
  }
35
- // --- Response Helpers ---
36
34
  success(e) {
37
35
  return this.clone({ code: 200, data: e });
38
36
  }
@@ -45,9 +43,6 @@ var a = class r {
45
43
  badRequest(e) {
46
44
  return this.clone({ code: 400, data: e });
47
45
  }
48
- zodError(e) {
49
- return this.clone({ code: 422, data: e });
50
- }
51
46
  unauthorized(e) {
52
47
  return this.clone({ code: 401, data: e });
53
48
  }
@@ -57,6 +52,12 @@ var a = class r {
57
52
  notFound(e) {
58
53
  return this.clone({ code: 404, data: e });
59
54
  }
55
+ validationError(e) {
56
+ return this.clone({ code: 422, data: e });
57
+ }
58
+ internalServerError(e) {
59
+ return this.clone({ code: 500, data: e });
60
+ }
60
61
  setHeader(e, t) {
61
62
  let s = new Map(this.header);
62
63
  return s.set(e, t), this.clone({ header: s });
@@ -88,5 +89,5 @@ var a = class r {
88
89
  }
89
90
  };
90
91
  export {
91
- a as Response
92
+ r as Response
92
93
  };
@@ -26,10 +26,11 @@ export declare class Response<Responder extends Responders = Responders, BM exte
26
26
  created(data: BM[201]): Response<Responder, BM, 201, Header, Cookies>;
27
27
  noContent(data: BM[204]): Response<Responder, BM, 204, Header, Cookies>;
28
28
  badRequest(data: BM[400]): Response<Responder, BM, 400, Header, Cookies>;
29
- zodError(data: BM[422]): Response<Responder, BM, 422, Header, Cookies>;
30
29
  unauthorized(data: BM[401]): Response<Responder, BM, 401, Header, Cookies>;
31
30
  forbidden(data: BM[403]): Response<Responder, BM, 403, Header, Cookies>;
32
31
  notFound(data: BM[404]): Response<Responder, BM, 404, Header, Cookies>;
32
+ validationError(data: BM[422]): Response<Responder, BM, 422, Header, Cookies>;
33
+ internalServerError(data: BM[500]): Response<Responder, BM, 500, Header, Cookies>;
33
34
  setHeader<Name extends string, Value extends string>(name: Name, value: Value): Response<Responder, BM, Status, Header & Map<Name, Value>, Cookies>;
34
35
  setCookie<Name extends string, Value extends string>(name: Name, value: Value): Response<Responder, BM, Status, Header, Cookies & Map<Name, Value>>;
35
36
  toResponse(): globalThis.Response;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@asterflow/response",
3
- "version": "1.0.1",
3
+ "version": "1.0.2",
4
4
  "main": "dist/cjs/index.cjs",
5
5
  "module": "dist/mjs/index.js",
6
6
  "types": "dist/types/index.d.ts",