@pulsecharterconnect/types 0.0.4 → 0.0.5
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/dist/types/index.d.ts
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
export * from './
|
|
1
|
+
export * from './ApiResult';
|
package/dist/types/index.js
CHANGED
|
@@ -14,4 +14,4 @@ var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
|
14
14
|
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
15
15
|
};
|
|
16
16
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
|
-
__exportStar(require("./
|
|
17
|
+
__exportStar(require("./ApiResult"), exports);
|
package/package.json
CHANGED
package/dist/models/ApiResult.js
DELETED
|
@@ -1,68 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.ApiResultWithError = exports.ApiResultStatus = void 0;
|
|
4
|
-
var ApiResultStatus;
|
|
5
|
-
(function (ApiResultStatus) {
|
|
6
|
-
ApiResultStatus["Success"] = "success";
|
|
7
|
-
ApiResultStatus["Failed"] = "failed";
|
|
8
|
-
})(ApiResultStatus = exports.ApiResultStatus || (exports.ApiResultStatus = {}));
|
|
9
|
-
class ApiResult {
|
|
10
|
-
/** Create a failed API result */
|
|
11
|
-
static failure(message = "", data = undefined) {
|
|
12
|
-
return new ApiResult({
|
|
13
|
-
status: ApiResultStatus.Failed,
|
|
14
|
-
message,
|
|
15
|
-
data
|
|
16
|
-
});
|
|
17
|
-
}
|
|
18
|
-
/** Create a successful API result */
|
|
19
|
-
static success(data = undefined, message = undefined) {
|
|
20
|
-
return new ApiResult({
|
|
21
|
-
status: ApiResultStatus.Success,
|
|
22
|
-
data,
|
|
23
|
-
message
|
|
24
|
-
});
|
|
25
|
-
}
|
|
26
|
-
/** Reconstruct an API result from JSON */
|
|
27
|
-
static fromJson(json) {
|
|
28
|
-
return new ApiResult(json);
|
|
29
|
-
}
|
|
30
|
-
static isApiResult(resultData) {
|
|
31
|
-
if (!resultData)
|
|
32
|
-
return false;
|
|
33
|
-
return resultData.status && (resultData.status === ApiResultStatus.Success) || (resultData.status === ApiResultStatus.Failed);
|
|
34
|
-
}
|
|
35
|
-
constructor(resultJson = {}) {
|
|
36
|
-
this.status = ApiResultStatus.Success;
|
|
37
|
-
Object.assign(this, resultJson);
|
|
38
|
-
}
|
|
39
|
-
get isSuccess() {
|
|
40
|
-
return this.status === ApiResultStatus.Success;
|
|
41
|
-
}
|
|
42
|
-
get isFailure() {
|
|
43
|
-
return this.status === ApiResultStatus.Failed;
|
|
44
|
-
}
|
|
45
|
-
get asJson() {
|
|
46
|
-
return {
|
|
47
|
-
status: this.status,
|
|
48
|
-
data: this.data
|
|
49
|
-
};
|
|
50
|
-
}
|
|
51
|
-
}
|
|
52
|
-
exports.default = ApiResult;
|
|
53
|
-
/**
|
|
54
|
-
* Use this as a base class when the API returns a different data struct for an Error then a Success response.
|
|
55
|
-
*/
|
|
56
|
-
class ApiResultWithError extends ApiResult {
|
|
57
|
-
constructor(resultJson = {}, error) {
|
|
58
|
-
super(resultJson);
|
|
59
|
-
this.error = error;
|
|
60
|
-
}
|
|
61
|
-
static failure(message = "", error = undefined) {
|
|
62
|
-
return new ApiResultWithError({
|
|
63
|
-
status: ApiResultStatus.Failed,
|
|
64
|
-
message,
|
|
65
|
-
}, error);
|
|
66
|
-
}
|
|
67
|
-
}
|
|
68
|
-
exports.ApiResultWithError = ApiResultWithError;
|
|
@@ -1,5 +0,0 @@
|
|
|
1
|
-
import { Response } from "express";
|
|
2
|
-
import ApiResult from "../models/ApiResult";
|
|
3
|
-
/** alias for an express.js Response that returns an ApiResult with a given type for the data property (TData) */
|
|
4
|
-
type ApiResultResponse<TData = any> = Response<ApiResult<TData>>;
|
|
5
|
-
export default ApiResultResponse;
|
|
File without changes
|