@budgetbuddyde/types 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/lib/ApiResponse.type.d.ts +61 -2
- package/lib/ApiResponse.type.js +75 -0
- package/lib/HttpStatusCode.type.d.ts +26 -0
- package/lib/HttpStatusCode.type.js +30 -0
- package/lib/index.d.ts +1 -0
- package/lib/index.js +1 -0
- package/package.json +4 -4
|
@@ -1,9 +1,68 @@
|
|
|
1
|
+
import { HTTPStatusCode } from './HttpStatusCode.type';
|
|
2
|
+
/**
|
|
3
|
+
* @deprecated Use ApiResponse and ApiResponseBuilder instead.
|
|
4
|
+
*/
|
|
1
5
|
export type TApiResponse<T> = {
|
|
2
|
-
status: 200;
|
|
6
|
+
status: 200 | HTTPStatusCode.Ok;
|
|
3
7
|
message: null;
|
|
4
8
|
data: T | null;
|
|
5
9
|
} & {
|
|
6
|
-
status: number;
|
|
10
|
+
status: number | HTTPStatusCode;
|
|
7
11
|
message: string | null;
|
|
8
12
|
data: T | null;
|
|
9
13
|
};
|
|
14
|
+
/**
|
|
15
|
+
* Represents an API response.
|
|
16
|
+
* @template T - The type of the data in the response.
|
|
17
|
+
*
|
|
18
|
+
* Usage
|
|
19
|
+
* ```typescript
|
|
20
|
+
* const response: ApiResponse<string> = ApiResponse
|
|
21
|
+
* .builder<string>()
|
|
22
|
+
* .withStatus(200)
|
|
23
|
+
* .withMessage('Hello World')
|
|
24
|
+
* .withData('Hello World')
|
|
25
|
+
* .build();
|
|
26
|
+
* ```
|
|
27
|
+
*/
|
|
28
|
+
export declare class ApiResponse<T> {
|
|
29
|
+
status: number | HTTPStatusCode;
|
|
30
|
+
message: string | null;
|
|
31
|
+
data: T | null;
|
|
32
|
+
private constructor();
|
|
33
|
+
/**
|
|
34
|
+
* Creates a new instance of ApiResponseBuilder.
|
|
35
|
+
* @returns An instance of ApiResponseBuilder.
|
|
36
|
+
*/
|
|
37
|
+
static builder<T>(): ApiResponseBuilder<T>;
|
|
38
|
+
}
|
|
39
|
+
/**
|
|
40
|
+
* Builder class for ApiResponse.
|
|
41
|
+
* @template T - The type of the data in the response.
|
|
42
|
+
*/
|
|
43
|
+
export declare class ApiResponseBuilder<T> {
|
|
44
|
+
private response;
|
|
45
|
+
/**
|
|
46
|
+
* Sets the status of the API response.
|
|
47
|
+
* @param status - The status code.
|
|
48
|
+
* @returns The ApiResponseBuilder instance.
|
|
49
|
+
*/
|
|
50
|
+
withStatus(status: number | HTTPStatusCode): ApiResponseBuilder<T>;
|
|
51
|
+
/**
|
|
52
|
+
* Sets the message of the API response.
|
|
53
|
+
* @param message - The message.
|
|
54
|
+
* @returns The ApiResponseBuilder instance.
|
|
55
|
+
*/
|
|
56
|
+
withMessage(message: string | null): ApiResponseBuilder<T>;
|
|
57
|
+
/**
|
|
58
|
+
* Sets the data of the API response.
|
|
59
|
+
* @param data - The data.
|
|
60
|
+
* @returns The ApiResponseBuilder instance.
|
|
61
|
+
*/
|
|
62
|
+
withData(data: T | null): ApiResponseBuilder<T>;
|
|
63
|
+
/**
|
|
64
|
+
* Builds the API response.
|
|
65
|
+
* @returns The built ApiResponse instance.
|
|
66
|
+
*/
|
|
67
|
+
build(): ApiResponse<T>;
|
|
68
|
+
}
|
package/lib/ApiResponse.type.js
CHANGED
|
@@ -1,2 +1,77 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.ApiResponseBuilder = exports.ApiResponse = void 0;
|
|
4
|
+
/**
|
|
5
|
+
* Represents an API response.
|
|
6
|
+
* @template T - The type of the data in the response.
|
|
7
|
+
*
|
|
8
|
+
* Usage
|
|
9
|
+
* ```typescript
|
|
10
|
+
* const response: ApiResponse<string> = ApiResponse
|
|
11
|
+
* .builder<string>()
|
|
12
|
+
* .withStatus(200)
|
|
13
|
+
* .withMessage('Hello World')
|
|
14
|
+
* .withData('Hello World')
|
|
15
|
+
* .build();
|
|
16
|
+
* ```
|
|
17
|
+
*/
|
|
18
|
+
class ApiResponse {
|
|
19
|
+
constructor() {
|
|
20
|
+
this.status = 200;
|
|
21
|
+
this.message = null;
|
|
22
|
+
this.data = null;
|
|
23
|
+
}
|
|
24
|
+
/**
|
|
25
|
+
* Creates a new instance of ApiResponseBuilder.
|
|
26
|
+
* @returns An instance of ApiResponseBuilder.
|
|
27
|
+
*/
|
|
28
|
+
static builder() {
|
|
29
|
+
return new ApiResponseBuilder();
|
|
30
|
+
}
|
|
31
|
+
}
|
|
32
|
+
exports.ApiResponse = ApiResponse;
|
|
33
|
+
/**
|
|
34
|
+
* Builder class for ApiResponse.
|
|
35
|
+
* @template T - The type of the data in the response.
|
|
36
|
+
*/
|
|
37
|
+
class ApiResponseBuilder {
|
|
38
|
+
constructor() {
|
|
39
|
+
// @ts-expect-error can be private, because it can be accessed via the build method
|
|
40
|
+
this.response = new ApiResponse();
|
|
41
|
+
}
|
|
42
|
+
/**
|
|
43
|
+
* Sets the status of the API response.
|
|
44
|
+
* @param status - The status code.
|
|
45
|
+
* @returns The ApiResponseBuilder instance.
|
|
46
|
+
*/
|
|
47
|
+
withStatus(status) {
|
|
48
|
+
this.response.status = status;
|
|
49
|
+
return this;
|
|
50
|
+
}
|
|
51
|
+
/**
|
|
52
|
+
* Sets the message of the API response.
|
|
53
|
+
* @param message - The message.
|
|
54
|
+
* @returns The ApiResponseBuilder instance.
|
|
55
|
+
*/
|
|
56
|
+
withMessage(message) {
|
|
57
|
+
this.response.message = message;
|
|
58
|
+
return this;
|
|
59
|
+
}
|
|
60
|
+
/**
|
|
61
|
+
* Sets the data of the API response.
|
|
62
|
+
* @param data - The data.
|
|
63
|
+
* @returns The ApiResponseBuilder instance.
|
|
64
|
+
*/
|
|
65
|
+
withData(data) {
|
|
66
|
+
this.response.data = data;
|
|
67
|
+
return this;
|
|
68
|
+
}
|
|
69
|
+
/**
|
|
70
|
+
* Builds the API response.
|
|
71
|
+
* @returns The built ApiResponse instance.
|
|
72
|
+
*/
|
|
73
|
+
build() {
|
|
74
|
+
return this.response;
|
|
75
|
+
}
|
|
76
|
+
}
|
|
77
|
+
exports.ApiResponseBuilder = ApiResponseBuilder;
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
export declare enum HTTPStatusCode {
|
|
2
|
+
Ok = 200,
|
|
3
|
+
Created = 201,
|
|
4
|
+
Accepted = 202,
|
|
5
|
+
NoContent = 204,
|
|
6
|
+
PartialContent = 206,
|
|
7
|
+
MultipleChoices = 300,
|
|
8
|
+
MovedPermanently = 301,
|
|
9
|
+
Found = 302,
|
|
10
|
+
BadRequest = 400,
|
|
11
|
+
Unauthorized = 401,
|
|
12
|
+
PaymentRequired = 402,
|
|
13
|
+
Forbidden = 403,
|
|
14
|
+
NotFound = 404,
|
|
15
|
+
MethodNotAllowed = 405,
|
|
16
|
+
RequestTimeout = 408,
|
|
17
|
+
Conflict = 409,
|
|
18
|
+
Gone = 410,
|
|
19
|
+
UnprocessableEntity = 422,
|
|
20
|
+
TooManyRequests = 429,
|
|
21
|
+
InternalServerError = 500,
|
|
22
|
+
NotImplemented = 501,
|
|
23
|
+
BadGateway = 502,
|
|
24
|
+
ServiceUnavailable = 503,
|
|
25
|
+
GatewayTiemout = 504
|
|
26
|
+
}
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.HTTPStatusCode = void 0;
|
|
4
|
+
var HTTPStatusCode;
|
|
5
|
+
(function (HTTPStatusCode) {
|
|
6
|
+
HTTPStatusCode[HTTPStatusCode["Ok"] = 200] = "Ok";
|
|
7
|
+
HTTPStatusCode[HTTPStatusCode["Created"] = 201] = "Created";
|
|
8
|
+
HTTPStatusCode[HTTPStatusCode["Accepted"] = 202] = "Accepted";
|
|
9
|
+
HTTPStatusCode[HTTPStatusCode["NoContent"] = 204] = "NoContent";
|
|
10
|
+
HTTPStatusCode[HTTPStatusCode["PartialContent"] = 206] = "PartialContent";
|
|
11
|
+
HTTPStatusCode[HTTPStatusCode["MultipleChoices"] = 300] = "MultipleChoices";
|
|
12
|
+
HTTPStatusCode[HTTPStatusCode["MovedPermanently"] = 301] = "MovedPermanently";
|
|
13
|
+
HTTPStatusCode[HTTPStatusCode["Found"] = 302] = "Found";
|
|
14
|
+
HTTPStatusCode[HTTPStatusCode["BadRequest"] = 400] = "BadRequest";
|
|
15
|
+
HTTPStatusCode[HTTPStatusCode["Unauthorized"] = 401] = "Unauthorized";
|
|
16
|
+
HTTPStatusCode[HTTPStatusCode["PaymentRequired"] = 402] = "PaymentRequired";
|
|
17
|
+
HTTPStatusCode[HTTPStatusCode["Forbidden"] = 403] = "Forbidden";
|
|
18
|
+
HTTPStatusCode[HTTPStatusCode["NotFound"] = 404] = "NotFound";
|
|
19
|
+
HTTPStatusCode[HTTPStatusCode["MethodNotAllowed"] = 405] = "MethodNotAllowed";
|
|
20
|
+
HTTPStatusCode[HTTPStatusCode["RequestTimeout"] = 408] = "RequestTimeout";
|
|
21
|
+
HTTPStatusCode[HTTPStatusCode["Conflict"] = 409] = "Conflict";
|
|
22
|
+
HTTPStatusCode[HTTPStatusCode["Gone"] = 410] = "Gone";
|
|
23
|
+
HTTPStatusCode[HTTPStatusCode["UnprocessableEntity"] = 422] = "UnprocessableEntity";
|
|
24
|
+
HTTPStatusCode[HTTPStatusCode["TooManyRequests"] = 429] = "TooManyRequests";
|
|
25
|
+
HTTPStatusCode[HTTPStatusCode["InternalServerError"] = 500] = "InternalServerError";
|
|
26
|
+
HTTPStatusCode[HTTPStatusCode["NotImplemented"] = 501] = "NotImplemented";
|
|
27
|
+
HTTPStatusCode[HTTPStatusCode["BadGateway"] = 502] = "BadGateway";
|
|
28
|
+
HTTPStatusCode[HTTPStatusCode["ServiceUnavailable"] = 503] = "ServiceUnavailable";
|
|
29
|
+
HTTPStatusCode[HTTPStatusCode["GatewayTiemout"] = 504] = "GatewayTiemout";
|
|
30
|
+
})(HTTPStatusCode = exports.HTTPStatusCode || (exports.HTTPStatusCode = {}));
|
package/lib/index.d.ts
CHANGED
package/lib/index.js
CHANGED
|
@@ -25,3 +25,4 @@ __exportStar(require("./Subscription.type"), exports);
|
|
|
25
25
|
__exportStar(require("./Budget.type"), exports);
|
|
26
26
|
__exportStar(require("./DailyTransaction.type"), exports);
|
|
27
27
|
__exportStar(require("./Role.type"), exports);
|
|
28
|
+
__exportStar(require("./HttpStatusCode.type"), exports);
|
package/package.json
CHANGED
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@budgetbuddyde/types",
|
|
3
|
-
"version": "1.0.
|
|
3
|
+
"version": "1.0.2",
|
|
4
4
|
"main": "lib/index.js",
|
|
5
5
|
"types": "lib/index.d.ts",
|
|
6
|
-
"description": "
|
|
6
|
+
"description": "Budget Buddy Typescript Types",
|
|
7
7
|
"keywords": [
|
|
8
8
|
"typescript",
|
|
9
9
|
"types",
|
|
@@ -16,10 +16,10 @@
|
|
|
16
16
|
},
|
|
17
17
|
"author": "Thorben",
|
|
18
18
|
"license": "MIT",
|
|
19
|
-
"homepage": "https://github.com/
|
|
19
|
+
"homepage": "https://github.com/BudgetBuddyDE",
|
|
20
20
|
"repository": {
|
|
21
21
|
"type": "git",
|
|
22
|
-
"url": "https://github.com/
|
|
22
|
+
"url": "https://github.com/BudgetBuddyDE/types.git"
|
|
23
23
|
},
|
|
24
24
|
"bugs": {
|
|
25
25
|
"url": "https://github.com/BudgetBuddyDE/types/issues"
|