@budgetbuddyde/types 1.0.32 → 1.0.33
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/lib/ApiResponse.type.d.ts +8 -0
- package/lib/ApiResponse.type.js +10 -0
- package/package.json +1 -1
|
@@ -7,6 +7,7 @@ export type TApiResponse<T> = {
|
|
|
7
7
|
status: number | HTTPStatusCode;
|
|
8
8
|
message: string | null;
|
|
9
9
|
data: T | null;
|
|
10
|
+
from: 'db' | 'cache';
|
|
10
11
|
};
|
|
11
12
|
/**
|
|
12
13
|
* Represents an API response.
|
|
@@ -26,6 +27,7 @@ export declare class ApiResponse<T> {
|
|
|
26
27
|
status: number | HTTPStatusCode;
|
|
27
28
|
message: string | null;
|
|
28
29
|
data: T | null;
|
|
30
|
+
from: 'db' | 'cache';
|
|
29
31
|
private constructor();
|
|
30
32
|
/**
|
|
31
33
|
* Creates a new instance of ApiResponseBuilder.
|
|
@@ -57,6 +59,12 @@ export declare class ApiResponseBuilder<T> {
|
|
|
57
59
|
* @returns The ApiResponseBuilder instance.
|
|
58
60
|
*/
|
|
59
61
|
withData(data: T | null): ApiResponseBuilder<T>;
|
|
62
|
+
/**
|
|
63
|
+
* Sets the source of the response data.
|
|
64
|
+
* @param from The source of the response data. Must be either "db" or "cache".
|
|
65
|
+
* @returns The ApiResponseBuilder instance.
|
|
66
|
+
*/
|
|
67
|
+
withFrom(from: 'db' | 'cache'): ApiResponseBuilder<T>;
|
|
60
68
|
/**
|
|
61
69
|
* Builds the API response.
|
|
62
70
|
* @returns The built ApiResponse instance.
|
package/lib/ApiResponse.type.js
CHANGED
|
@@ -20,6 +20,7 @@ class ApiResponse {
|
|
|
20
20
|
this.status = 200;
|
|
21
21
|
this.message = null;
|
|
22
22
|
this.data = null;
|
|
23
|
+
this.from = 'db';
|
|
23
24
|
}
|
|
24
25
|
/**
|
|
25
26
|
* Creates a new instance of ApiResponseBuilder.
|
|
@@ -66,6 +67,15 @@ class ApiResponseBuilder {
|
|
|
66
67
|
this.response.data = data;
|
|
67
68
|
return this;
|
|
68
69
|
}
|
|
70
|
+
/**
|
|
71
|
+
* Sets the source of the response data.
|
|
72
|
+
* @param from The source of the response data. Must be either "db" or "cache".
|
|
73
|
+
* @returns The ApiResponseBuilder instance.
|
|
74
|
+
*/
|
|
75
|
+
withFrom(from) {
|
|
76
|
+
this.response.from = from;
|
|
77
|
+
return this;
|
|
78
|
+
}
|
|
69
79
|
/**
|
|
70
80
|
* Builds the API response.
|
|
71
81
|
* @returns The built ApiResponse instance.
|