burger-api 0.2.1 → 0.2.3

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.
@@ -74,4 +74,4 @@ export declare class Burger {
74
74
  serve(port?: number, cb?: () => void): Promise<void>;
75
75
  }
76
76
  export { setDir } from './utils/index.js';
77
- export type { ServerOptions, RequestHandler, BurgerRequest, BurgerResponse, BurgerNext, Middleware, openapi, } from '@burgerTypes';
77
+ export type { ServerOptions, RequestHandler, BurgerRequest, BurgerNext, Middleware, openapi, } from '@burgerTypes';
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "burger-api",
3
- "version": "0.2.1",
3
+ "version": "0.2.3",
4
4
  "author": "Isfhan Ahmed",
5
5
  "type": "module",
6
6
  "module": "dist/src/index.js",
@@ -58,7 +58,14 @@
58
58
  "contemporary-backend",
59
59
  "fast-javascript",
60
60
  "bun-js-framework",
61
- "bun-backend"
61
+ "bun-backend",
62
+ "bun-api-framework",
63
+ "pakistan-backend",
64
+ "pakistan-api-framework",
65
+ "pakistan-api-server",
66
+ "pakistan-backend-framework",
67
+ "pakistan-bunjs-framework",
68
+ "pakistan-javascript-framework"
62
69
  ],
63
70
  "license": "MIT",
64
71
  "repository": {
@@ -1,40 +0,0 @@
1
- export declare class HttpRequest {
2
- private _request;
3
- private _query?;
4
- /**
5
- * Creates a new HttpRequest object from the given Request object.
6
- * @param request - The Request object to wrap.
7
- */
8
- constructor(request: Request);
9
- /**
10
- * Retrieves the query parameters from the request URL.
11
- * Initializes the query parameters if they are not already set.
12
- * @returns The URLSearchParams object containing the query parameters.
13
- */
14
- get query(): URLSearchParams;
15
- /**
16
- * Gets the URL of the request.
17
- * @returns The URL as a string.
18
- */
19
- get url(): string;
20
- /**
21
- * Gets the HTTP method of the request.
22
- * @returns The HTTP method as a string.
23
- */
24
- get method(): string;
25
- /**
26
- * Gets the headers of the request.
27
- * @returns The headers as a Headers object.
28
- */
29
- get headers(): Headers;
30
- /**
31
- * Gets the body of the request as JSON.
32
- * @returns The body as a Promise of the parsed JSON.
33
- */
34
- json<T = any>(): Promise<T>;
35
- /**
36
- * Returns the original Request object.
37
- * @returns The original Request object.
38
- */
39
- get original(): Request;
40
- }
@@ -1,58 +0,0 @@
1
- export class HttpRequest {
2
- _request;
3
- _query;
4
- /**
5
- * Creates a new HttpRequest object from the given Request object.
6
- * @param request - The Request object to wrap.
7
- */
8
- constructor(request) {
9
- this._request = request;
10
- this._query = new URL(request.url).searchParams;
11
- }
12
- /**
13
- * Retrieves the query parameters from the request URL.
14
- * Initializes the query parameters if they are not already set.
15
- * @returns The URLSearchParams object containing the query parameters.
16
- */
17
- get query() {
18
- if (!this._query) {
19
- this._query = new URL(this._request.url).searchParams;
20
- }
21
- return this._query;
22
- }
23
- /**
24
- * Gets the URL of the request.
25
- * @returns The URL as a string.
26
- */
27
- get url() {
28
- return this._request.url;
29
- }
30
- /**
31
- * Gets the HTTP method of the request.
32
- * @returns The HTTP method as a string.
33
- */
34
- get method() {
35
- return this._request.method;
36
- }
37
- /**
38
- * Gets the headers of the request.
39
- * @returns The headers as a Headers object.
40
- */
41
- get headers() {
42
- return this._request.headers;
43
- }
44
- /**
45
- * Gets the body of the request as JSON.
46
- * @returns The body as a Promise of the parsed JSON.
47
- */
48
- async json() {
49
- return this._request.json();
50
- }
51
- /**
52
- * Returns the original Request object.
53
- * @returns The original Request object.
54
- */
55
- get original() {
56
- return this._request;
57
- }
58
- }
@@ -1,92 +0,0 @@
1
- export declare class HttpResponse {
2
- /**
3
- * The status code of the response, which defaults to 200 (OK). This
4
- * property can be modified before calling build() to construct the
5
- * Response object.
6
- */
7
- private _status;
8
- /**
9
- * The headers of the response, which can be modified before calling build()
10
- * to construct the Response object.
11
- */
12
- private _headers;
13
- /**
14
- * The body of the response, which can be any valid BodyInit type or null.
15
- */
16
- private _body;
17
- /**
18
- * Set a header on the response.
19
- * @param name - The header name.
20
- * @param value - The header value.
21
- * @returns The response object.
22
- */
23
- header(name: string, value: string): this;
24
- /**
25
- * Remove a header from the response.
26
- * @param name - The header name.
27
- * @returns The response object.
28
- */
29
- removeHeader(name: string): this;
30
- /**
31
- * Sets the HTTP status code of the response.
32
- * @param status - The status code.
33
- * @returns The response object.
34
- */
35
- status(status: number): this;
36
- /**
37
- * Sets the body of the response.
38
- * @param body - The content to be used as the response body.
39
- * @returns The response object for method chaining.
40
- */
41
- body(body: BodyInit): this;
42
- /**
43
- * Sets the content type to "application/json" and serializes the provided data
44
- * into a JSON string to set as the response body.
45
- * @param data - The data to be serialized and sent as the response body.
46
- * @returns The finalized Response object after building.
47
- */
48
- json(data: unknown): Response;
49
- /**
50
- * Sets the content type to "text/plain" and assigns the provided text data
51
- * as the response body.
52
- * @param data - The text to be sent as the response body.
53
- * @returns The finalized Response object after building.
54
- */
55
- text(data: string): Response;
56
- /**
57
- * Sets the content type to "text/html" and assigns the provided HTML data
58
- * as the response body.
59
- * @param data - The HTML string to be sent as the response body.
60
- * @returns The finalized Response object after building.
61
- */
62
- html(data: string): Response;
63
- /**
64
- * Sets the HTTP status code and removes the "Location" header from the
65
- * response.
66
- * @param status - The status code.
67
- * @returns The response object.
68
- */
69
- redirect(url: string, status?: number): this;
70
- /**
71
- * Convenience method to send a file response using Bun.file.
72
- * Attempts to serve the specified file and set it as the response body.
73
- * If the file cannot be found or an error occurs, logs the error and
74
- * returns a 404 response with "File not found" as the body.
75
- * @param filePath - The file path to serve.
76
- * @returns The finalized Response object.
77
- */
78
- file(filePath: string): Response;
79
- /**
80
- * Returns a Response directly using the provided body and init settings.
81
- * This bypasses the mutable state.
82
- * @param body - The response body.
83
- * @param init - Optional ResponseInit settings.
84
- * @returns A new Response object.
85
- */
86
- original(body?: BodyInit | null, init?: ResponseInit): Response;
87
- /**
88
- * Builds the final Response object using the current state.
89
- * @returns The finalized Response object.
90
- */
91
- build(): Response;
92
- }
@@ -1,140 +0,0 @@
1
- export class HttpResponse {
2
- /**
3
- * The status code of the response, which defaults to 200 (OK). This
4
- * property can be modified before calling build() to construct the
5
- * Response object.
6
- */
7
- _status = 200;
8
- /**
9
- * The headers of the response, which can be modified before calling build()
10
- * to construct the Response object.
11
- */
12
- _headers = new Headers();
13
- /**
14
- * The body of the response, which can be any valid BodyInit type or null.
15
- */
16
- _body = null;
17
- /**
18
- * Set a header on the response.
19
- * @param name - The header name.
20
- * @param value - The header value.
21
- * @returns The response object.
22
- */
23
- header(name, value) {
24
- this._headers.set(name, value);
25
- return this;
26
- }
27
- /**
28
- * Remove a header from the response.
29
- * @param name - The header name.
30
- * @returns The response object.
31
- */
32
- removeHeader(name) {
33
- this._headers.delete(name);
34
- return this;
35
- }
36
- /**
37
- * Sets the HTTP status code of the response.
38
- * @param status - The status code.
39
- * @returns The response object.
40
- */
41
- status(status) {
42
- this._status = status;
43
- return this;
44
- }
45
- /**
46
- * Sets the body of the response.
47
- * @param body - The content to be used as the response body.
48
- * @returns The response object for method chaining.
49
- */
50
- body(body) {
51
- this._body = body;
52
- return this;
53
- }
54
- /**
55
- * Sets the content type to "application/json" and serializes the provided data
56
- * into a JSON string to set as the response body.
57
- * @param data - The data to be serialized and sent as the response body.
58
- * @returns The finalized Response object after building.
59
- */
60
- json(data) {
61
- this.header('Content-Type', 'application/json');
62
- this._body = JSON.stringify(data);
63
- return this.build();
64
- }
65
- /**
66
- * Sets the content type to "text/plain" and assigns the provided text data
67
- * as the response body.
68
- * @param data - The text to be sent as the response body.
69
- * @returns The finalized Response object after building.
70
- */
71
- text(data) {
72
- this.header('Content-Type', 'text/plain');
73
- this._body = data;
74
- return this.build();
75
- }
76
- /**
77
- * Sets the content type to "text/html" and assigns the provided HTML data
78
- * as the response body.
79
- * @param data - The HTML string to be sent as the response body.
80
- * @returns The finalized Response object after building.
81
- */
82
- html(data) {
83
- this.header('Content-Type', 'text/html');
84
- this._body = data;
85
- return this.build();
86
- }
87
- /**
88
- * Sets the HTTP status code and removes the "Location" header from the
89
- * response.
90
- * @param status - The status code.
91
- * @returns The response object.
92
- */
93
- redirect(url, status = 302) {
94
- this.status(status);
95
- this.header('Location', url);
96
- this._body = null;
97
- return this;
98
- }
99
- /**
100
- * Convenience method to send a file response using Bun.file.
101
- * Attempts to serve the specified file and set it as the response body.
102
- * If the file cannot be found or an error occurs, logs the error and
103
- * returns a 404 response with "File not found" as the body.
104
- * @param filePath - The file path to serve.
105
- * @returns The finalized Response object.
106
- */
107
- file(filePath) {
108
- try {
109
- const file = Bun.file(filePath);
110
- this._body = file;
111
- return this.build();
112
- }
113
- catch (error) {
114
- console.error('Error serving file:', error);
115
- this.status(404);
116
- this._body = 'File not found';
117
- return this.build();
118
- }
119
- }
120
- /**
121
- * Returns a Response directly using the provided body and init settings.
122
- * This bypasses the mutable state.
123
- * @param body - The response body.
124
- * @param init - Optional ResponseInit settings.
125
- * @returns A new Response object.
126
- */
127
- original(body, init) {
128
- return new Response(body, init);
129
- }
130
- /**
131
- * Builds the final Response object using the current state.
132
- * @returns The finalized Response object.
133
- */
134
- build() {
135
- return new Response(this._body, {
136
- status: this._status,
137
- headers: this._headers,
138
- });
139
- }
140
- }