@arkyn/server 3.0.1-beta.10 → 3.0.1-beta.12

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.
@@ -1,4 +1,4 @@
1
- type ApiInstanceContructorProps = {
1
+ type ApiInstanceConstructorProps = {
2
2
  baseUrl: string;
3
3
  baseHeaders?: HeadersInit;
4
4
  baseToken?: string | null;
@@ -26,7 +26,7 @@ declare class ApiInstance {
26
26
  * @param props.baseHeaders - Optional base headers to include in all requests.
27
27
  * @param props.baseToken - Optional base token for authorization.
28
28
  */
29
- constructor(props: ApiInstanceContructorProps);
29
+ constructor(props: ApiInstanceConstructorProps);
30
30
  /**
31
31
  * Generates the full URL by appending the route to the base URL.
32
32
  * @param route - The route to append to the base URL.
@@ -41,40 +41,40 @@ declare class ApiInstance {
41
41
  */
42
42
  private generateHeaders;
43
43
  /**
44
- * Sends a GET request to the specified route.
45
- * @param route - The API route to send the GET request to.
44
+ * Sends a get request to the specified route.
45
+ * @param route - The API route to send the get request to.
46
46
  * @param data - The request data, including optional headers and token.
47
47
  * @returns The API response data.
48
48
  */
49
- GET(route: string, data?: ApiRequestDataWithoutBodyProps): Promise<import("../types/ApiResponseDTO").ApiResponseDTO<any>>;
49
+ get(route: string, data?: ApiRequestDataWithoutBodyProps): Promise<import("../types/ApiResponseDTO").ApiResponseDTO<any>>;
50
50
  /**
51
- * Sends a POST request to the specified route.
52
- * @param route - The API route to send the POST request to.
51
+ * Sends a post request to the specified route.
52
+ * @param route - The API route to send the post request to.
53
53
  * @param data - The request data, including body, optional headers, and token.
54
54
  * @returns The API response data.
55
55
  */
56
- POST(route: string, data?: ApiRequestDataWithBodyProps): Promise<import("../types/ApiResponseDTO").ApiResponseDTO<any>>;
56
+ post(route: string, data?: ApiRequestDataWithBodyProps): Promise<import("../types/ApiResponseDTO").ApiResponseDTO<any>>;
57
57
  /**
58
- * Sends a PUT request to the specified route.
59
- * @param route - The API route to send the PUT request to.
58
+ * Sends a put request to the specified route.
59
+ * @param route - The API route to send the put request to.
60
60
  * @param data - The request data, including body, optional headers, and token.
61
61
  * @returns The API response data.
62
62
  */
63
- PUT(route: string, data?: ApiRequestDataWithBodyProps): Promise<import("../types/ApiResponseDTO").ApiResponseDTO<any>>;
63
+ put(route: string, data?: ApiRequestDataWithBodyProps): Promise<import("../types/ApiResponseDTO").ApiResponseDTO<any>>;
64
64
  /**
65
- * Sends a PATCH request to the specified route.
66
- * @param route - The API route to send the PATCH request to.
65
+ * Sends a patch request to the specified route.
66
+ * @param route - The API route to send the patch request to.
67
67
  * @param data - The request data, including body, optional headers, and token.
68
68
  * @returns The API response data.
69
69
  */
70
- PATCH(route: string, data?: ApiRequestDataWithBodyProps): Promise<import("../types/ApiResponseDTO").ApiResponseDTO<any>>;
70
+ patch(route: string, data?: ApiRequestDataWithBodyProps): Promise<import("../types/ApiResponseDTO").ApiResponseDTO<any>>;
71
71
  /**
72
- * Sends a DELETE request to the specified route.
73
- * @param route - The API route to send the DELETE request to.
72
+ * Sends a delete request to the specified route.
73
+ * @param route - The API route to send the delete request to.
74
74
  * @param data - The request data, including body, optional headers, and token.
75
75
  * @returns The API response data.
76
76
  */
77
- DELETE(route: string, data?: ApiRequestDataWithBodyProps): Promise<import("../types/ApiResponseDTO").ApiResponseDTO<any>>;
77
+ delete(route: string, data?: ApiRequestDataWithBodyProps): Promise<import("../types/ApiResponseDTO").ApiResponseDTO<any>>;
78
78
  }
79
79
  export { ApiInstance };
80
80
  //# sourceMappingURL=apiInstance.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"apiInstance.d.ts","sourceRoot":"","sources":["../../src/config/apiInstance.ts"],"names":[],"mappings":"AAMA,KAAK,0BAA0B,GAAG;IAChC,OAAO,EAAE,MAAM,CAAC;IAChB,WAAW,CAAC,EAAE,WAAW,CAAC;IAC1B,SAAS,CAAC,EAAE,MAAM,GAAG,IAAI,CAAC;CAC3B,CAAC;AAEF,KAAK,8BAA8B,GAAG;IACpC,OAAO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C,EAAE,WAAW,CAAC;IACtB,KAAK,CAAC,EAAE,MAAM,CAAC;CAChB,CAAC;AAEF,KAAK,2BAA2B,GAAG;IACjC,IAAI,CAAC,EAAE,GAAG,CAAC;IACX,OAAO,CAAC,EAAE,WAAW,CAAC;IACtB,KAAK,CAAC,EAAE,MAAM,CAAC;CAChB,CAAC;AAEF;;GAEG;AAEH,cAAM,WAAW;IACf,OAAO,CAAC,OAAO,CAAS;IACxB,OAAO,CAAC,WAAW,CAAC,CAAc;IAClC,OAAO,CAAC,SAAS,CAAC,CAAS;IAE3B;;;;;;OAMG;gBAES,KAAK,EAAE,2BAA2B;IAM9C;;;;OAIG;IAEH,OAAO,CAAC,WAAW;IAInB;;;;;OAKG;IAEH,OAAO,CAAC,eAAe;IAcvB;;;;;OAKG;IAEG,GAAG,CAAC,KAAK,EAAE,MAAM,EAAE,IAAI,CAAC,EAAE,8BAA8B;IAM9D;;;;;OAKG;IAEG,IAAI,CAAC,KAAK,EAAE,MAAM,EAAE,IAAI,CAAC,EAAE,2BAA2B;IAO5D;;;;;OAKG;IAEG,GAAG,CAAC,KAAK,EAAE,MAAM,EAAE,IAAI,CAAC,EAAE,2BAA2B;IAO3D;;;;;OAKG;IAEG,KAAK,CAAC,KAAK,EAAE,MAAM,EAAE,IAAI,CAAC,EAAE,2BAA2B;IAO7D;;;;;OAKG;IAEG,MAAM,CAAC,KAAK,EAAE,MAAM,EAAE,IAAI,CAAC,EAAE,2BAA2B;CAM/D;AAED,OAAO,EAAE,WAAW,EAAE,CAAC"}
@@ -49,59 +49,59 @@ class ApiInstance {
49
49
  return headers;
50
50
  }
51
51
  /**
52
- * Sends a GET request to the specified route.
53
- * @param route - The API route to send the GET request to.
52
+ * Sends a get request to the specified route.
53
+ * @param route - The API route to send the get request to.
54
54
  * @param data - The request data, including optional headers and token.
55
55
  * @returns The API response data.
56
56
  */
57
- async GET(route, data) {
57
+ async get(route, data) {
58
58
  const url = this.generateURL(route);
59
59
  const headers = this.generateHeaders(data?.headers || {}, data?.token);
60
60
  return await getRequest(url, headers);
61
61
  }
62
62
  /**
63
- * Sends a POST request to the specified route.
64
- * @param route - The API route to send the POST request to.
63
+ * Sends a post request to the specified route.
64
+ * @param route - The API route to send the post request to.
65
65
  * @param data - The request data, including body, optional headers, and token.
66
66
  * @returns The API response data.
67
67
  */
68
- async POST(route, data) {
68
+ async post(route, data) {
69
69
  const url = this.generateURL(route);
70
70
  const headers = this.generateHeaders(data?.headers || {}, data?.token);
71
71
  const body = data?.body;
72
72
  return await postRequest(url, headers, body);
73
73
  }
74
74
  /**
75
- * Sends a PUT request to the specified route.
76
- * @param route - The API route to send the PUT request to.
75
+ * Sends a put request to the specified route.
76
+ * @param route - The API route to send the put request to.
77
77
  * @param data - The request data, including body, optional headers, and token.
78
78
  * @returns The API response data.
79
79
  */
80
- async PUT(route, data) {
80
+ async put(route, data) {
81
81
  const url = this.generateURL(route);
82
82
  const headers = this.generateHeaders(data?.headers || {}, data?.token);
83
83
  const body = data?.body;
84
84
  return await putRequest(url, headers, body);
85
85
  }
86
86
  /**
87
- * Sends a PATCH request to the specified route.
88
- * @param route - The API route to send the PATCH request to.
87
+ * Sends a patch request to the specified route.
88
+ * @param route - The API route to send the patch request to.
89
89
  * @param data - The request data, including body, optional headers, and token.
90
90
  * @returns The API response data.
91
91
  */
92
- async PATCH(route, data) {
92
+ async patch(route, data) {
93
93
  const url = this.generateURL(route);
94
94
  const headers = this.generateHeaders(data?.headers || {}, data?.token);
95
95
  const body = data?.body;
96
96
  return await patchRequest(url, headers, body);
97
97
  }
98
98
  /**
99
- * Sends a DELETE request to the specified route.
100
- * @param route - The API route to send the DELETE request to.
99
+ * Sends a delete request to the specified route.
100
+ * @param route - The API route to send the delete request to.
101
101
  * @param data - The request data, including body, optional headers, and token.
102
102
  * @returns The API response data.
103
103
  */
104
- async DELETE(route, data) {
104
+ async delete(route, data) {
105
105
  const url = this.generateURL(route);
106
106
  const headers = this.generateHeaders(data?.headers || {}, data?.token);
107
107
  const body = data?.body;
@@ -0,0 +1,3 @@
1
+ declare function measureRouteExecution<T = unknown>(handler: (props: any) => Promise<T>): (props: any) => Promise<T>;
2
+ export { measureRouteExecution };
3
+ //# sourceMappingURL=measureRouteExecution.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"measureRouteExecution.d.ts","sourceRoot":"","sources":["../../src/services/measureRouteExecution.ts"],"names":[],"mappings":"AAAA,iBAAS,qBAAqB,CAAC,CAAC,GAAG,OAAO,EACxC,OAAO,EAAE,CAAC,KAAK,EAAE,GAAG,KAAK,OAAO,CAAC,CAAC,CAAC,IAEG,OAAO,GAAG,KAAG,OAAO,CAAC,CAAC,CAAC,CAyB9D;AAED,OAAO,EAAE,qBAAqB,EAAE,CAAC"}
@@ -0,0 +1,24 @@
1
+ function measureRouteExecution(handler) {
2
+ return async function measuredHandler(props) {
3
+ const startTime = performance.now();
4
+ try {
5
+ const result = await handler(props);
6
+ const url = new URL(props.request.url);
7
+ const endTime = performance.now();
8
+ const duration = (endTime - startTime).toFixed(2);
9
+ console.log({
10
+ domain: url.hostname,
11
+ pathname: url.pathname,
12
+ method: props.request.method,
13
+ duration,
14
+ });
15
+ return result;
16
+ }
17
+ catch (error) {
18
+ const endTime = performance.now();
19
+ console.error("");
20
+ throw error;
21
+ }
22
+ };
23
+ }
24
+ export { measureRouteExecution };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@arkyn/server",
3
- "version": "3.0.1-beta.10",
3
+ "version": "3.0.1-beta.12",
4
4
  "author": "Arkyn | Lucas Gonçalves",
5
5
  "main": "./dist/bundle.js",
6
6
  "module": "./src/index.ts",
@@ -4,7 +4,7 @@ import { patchRequest } from "../api/patchRequest";
4
4
  import { postRequest } from "../api/postRequest";
5
5
  import { putRequest } from "../api/putRequest";
6
6
 
7
- type ApiInstanceContructorProps = {
7
+ type ApiInstanceConstructorProps = {
8
8
  baseUrl: string;
9
9
  baseHeaders?: HeadersInit;
10
10
  baseToken?: string | null;
@@ -38,7 +38,7 @@ class ApiInstance {
38
38
  * @param props.baseToken - Optional base token for authorization.
39
39
  */
40
40
 
41
- constructor(props: ApiInstanceContructorProps) {
41
+ constructor(props: ApiInstanceConstructorProps) {
42
42
  this.baseUrl = props.baseUrl;
43
43
  this.baseHeaders = props.baseHeaders || undefined;
44
44
  this.baseToken = props.baseToken || undefined;
@@ -76,26 +76,26 @@ class ApiInstance {
76
76
  }
77
77
 
78
78
  /**
79
- * Sends a GET request to the specified route.
80
- * @param route - The API route to send the GET request to.
79
+ * Sends a get request to the specified route.
80
+ * @param route - The API route to send the get request to.
81
81
  * @param data - The request data, including optional headers and token.
82
82
  * @returns The API response data.
83
83
  */
84
84
 
85
- async GET(route: string, data?: ApiRequestDataWithoutBodyProps) {
85
+ async get(route: string, data?: ApiRequestDataWithoutBodyProps) {
86
86
  const url = this.generateURL(route);
87
87
  const headers = this.generateHeaders(data?.headers || {}, data?.token);
88
88
  return await getRequest(url, headers);
89
89
  }
90
90
 
91
91
  /**
92
- * Sends a POST request to the specified route.
93
- * @param route - The API route to send the POST request to.
92
+ * Sends a post request to the specified route.
93
+ * @param route - The API route to send the post request to.
94
94
  * @param data - The request data, including body, optional headers, and token.
95
95
  * @returns The API response data.
96
96
  */
97
97
 
98
- async POST(route: string, data?: ApiRequestDataWithBodyProps) {
98
+ async post(route: string, data?: ApiRequestDataWithBodyProps) {
99
99
  const url = this.generateURL(route);
100
100
  const headers = this.generateHeaders(data?.headers || {}, data?.token);
101
101
  const body = data?.body;
@@ -103,13 +103,13 @@ class ApiInstance {
103
103
  }
104
104
 
105
105
  /**
106
- * Sends a PUT request to the specified route.
107
- * @param route - The API route to send the PUT request to.
106
+ * Sends a put request to the specified route.
107
+ * @param route - The API route to send the put request to.
108
108
  * @param data - The request data, including body, optional headers, and token.
109
109
  * @returns The API response data.
110
110
  */
111
111
 
112
- async PUT(route: string, data?: ApiRequestDataWithBodyProps) {
112
+ async put(route: string, data?: ApiRequestDataWithBodyProps) {
113
113
  const url = this.generateURL(route);
114
114
  const headers = this.generateHeaders(data?.headers || {}, data?.token);
115
115
  const body = data?.body;
@@ -117,13 +117,13 @@ class ApiInstance {
117
117
  }
118
118
 
119
119
  /**
120
- * Sends a PATCH request to the specified route.
121
- * @param route - The API route to send the PATCH request to.
120
+ * Sends a patch request to the specified route.
121
+ * @param route - The API route to send the patch request to.
122
122
  * @param data - The request data, including body, optional headers, and token.
123
123
  * @returns The API response data.
124
124
  */
125
125
 
126
- async PATCH(route: string, data?: ApiRequestDataWithBodyProps) {
126
+ async patch(route: string, data?: ApiRequestDataWithBodyProps) {
127
127
  const url = this.generateURL(route);
128
128
  const headers = this.generateHeaders(data?.headers || {}, data?.token);
129
129
  const body = data?.body;
@@ -131,13 +131,13 @@ class ApiInstance {
131
131
  }
132
132
 
133
133
  /**
134
- * Sends a DELETE request to the specified route.
135
- * @param route - The API route to send the DELETE request to.
134
+ * Sends a delete request to the specified route.
135
+ * @param route - The API route to send the delete request to.
136
136
  * @param data - The request data, including body, optional headers, and token.
137
137
  * @returns The API response data.
138
138
  */
139
139
 
140
- async DELETE(route: string, data?: ApiRequestDataWithBodyProps) {
140
+ async delete(route: string, data?: ApiRequestDataWithBodyProps) {
141
141
  const url = this.generateURL(route);
142
142
  const headers = this.generateHeaders(data?.headers || {}, data?.token);
143
143
  const body = data?.body;
@@ -0,0 +1,31 @@
1
+ function measureRouteExecution<T = unknown>(
2
+ handler: (props: any) => Promise<T>
3
+ ) {
4
+ return async function measuredHandler(props: any): Promise<T> {
5
+ const startTime = performance.now();
6
+
7
+ try {
8
+ const result = await handler(props);
9
+
10
+ const url = new URL(props.request.url);
11
+ const endTime = performance.now();
12
+
13
+ const duration = (endTime - startTime).toFixed(2);
14
+
15
+ console.log({
16
+ domain: url.hostname,
17
+ pathname: url.pathname,
18
+ method: props.request.method,
19
+ duration,
20
+ });
21
+
22
+ return result as T;
23
+ } catch (error) {
24
+ const endTime = performance.now();
25
+ console.error("");
26
+ throw error;
27
+ }
28
+ };
29
+ }
30
+
31
+ export { measureRouteExecution };