@8ms/helpers 2.4.10 → 2.4.11
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/_class/BaseClass.cjs +31 -21
- package/dist/_class/BaseClass.mjs +31 -21
- package/dist/_class/BaseNamespace.cjs +10 -9
- package/dist/_class/BaseNamespace.mjs +10 -9
- package/dist/api/ApiResponseClass.cjs +96 -96
- package/dist/api/ApiResponseClass.mjs +96 -96
- package/dist/aws/cloudWatchLog/server/AwsCloudWatchLogNamespace.cjs +70 -60
- package/dist/aws/cloudWatchLog/server/AwsCloudWatchLogNamespace.mjs +70 -60
- package/dist/aws/cloudWatchMetric/server/AwsCloudWatchMetricNamespace.cjs +30 -28
- package/dist/aws/cloudWatchMetric/server/AwsCloudWatchMetricNamespace.mjs +30 -28
- package/dist/aws/ec2/server/AwsEc2Namespace.cjs +29 -32
- package/dist/aws/ec2/server/AwsEc2Namespace.mjs +29 -32
- package/dist/aws/ecs/server/AwsEcsNamespace.cjs +92 -78
- package/dist/aws/ecs/server/AwsEcsNamespace.mjs +92 -78
- package/dist/aws/glue/server/AwsGlueNamespace.cjs +17 -17
- package/dist/aws/glue/server/AwsGlueNamespace.mjs +17 -17
- package/dist/aws/lambda/server/AwsLambdaNamespace.cjs +33 -31
- package/dist/aws/lambda/server/AwsLambdaNamespace.mjs +33 -31
- package/dist/aws/s3/server/AwsS3Namespace.cjs +280 -265
- package/dist/aws/s3/server/AwsS3Namespace.mjs +280 -265
- package/dist/aws/ses/server/AwsSesNamespace.cjs +27 -30
- package/dist/aws/ses/server/AwsSesNamespace.mjs +27 -30
- package/dist/aws/ses/server/SimpleEmail.cjs +202 -199
- package/dist/aws/ses/server/SimpleEmail.mjs +202 -199
- package/dist/aws/sqs/server/AwsSqsNamespace.cjs +35 -38
- package/dist/aws/sqs/server/AwsSqsNamespace.mjs +35 -38
- package/dist/aws/ssm/server/AwsSsmNamespace.cjs +24 -23
- package/dist/aws/ssm/server/AwsSsmNamespace.mjs +24 -23
- package/dist/date/index.cjs +1 -1
- package/dist/date/index.mjs +1 -1
- package/dist/drizzle/server/DrizzleNamespace.cjs +39 -42
- package/dist/drizzle/server/DrizzleNamespace.mjs +39 -42
- package/dist/googleAds/server/GoogleAdsNamespace.cjs +21 -24
- package/dist/googleAds/server/GoogleAdsNamespace.mjs +21 -24
- package/dist/googleCloud/bigquery/server/GoogleCloudBigqueryNamespace.cjs +86 -70
- package/dist/googleCloud/bigquery/server/GoogleCloudBigqueryNamespace.mjs +86 -70
- package/dist/googleCloud/sheets/server/GoogleCloudSheetsNamespace.cjs +22 -25
- package/dist/googleCloud/sheets/server/GoogleCloudSheetsNamespace.mjs +22 -25
- package/dist/googleCloud/storage/server/GoogleCloudStorageNamespace.cjs +44 -38
- package/dist/googleCloud/storage/server/GoogleCloudStorageNamespace.mjs +44 -38
- package/dist/googlePageSpeed/server/GooglePageSpeedNamespace.cjs +12 -15
- package/dist/googlePageSpeed/server/GooglePageSpeedNamespace.mjs +12 -15
- package/dist/littleWarden/server/LittleWardenNamespace.cjs +12 -15
- package/dist/littleWarden/server/LittleWardenNamespace.mjs +12 -15
- package/dist/onePassword/server/OnePasswordNamespace.cjs +30 -33
- package/dist/onePassword/server/OnePasswordNamespace.mjs +30 -33
- package/dist/openAi/server/OpenAiNamespace.cjs +20 -20
- package/dist/openAi/server/OpenAiNamespace.mjs +20 -20
- package/dist/prisma/server/PrismaNamespace.cjs +35 -38
- package/dist/prisma/server/PrismaNamespace.mjs +35 -38
- package/dist/snapchat/server/SnapchatNamespace.cjs +12 -12
- package/dist/snapchat/server/SnapchatNamespace.mjs +12 -12
- package/dist/upTimeRobot/server/UpTimeRobotNamespace.cjs +19 -19
- package/dist/upTimeRobot/server/UpTimeRobotNamespace.mjs +19 -19
- package/package.json +1 -1
|
@@ -3,27 +3,37 @@ const require_lodash_set = require("../lodash/set.cjs");
|
|
|
3
3
|
const require_util_defaultTo = require("../util/defaultTo.cjs");
|
|
4
4
|
//#region src/_class/BaseClass.ts
|
|
5
5
|
var BaseClass = class {
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
this
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
6
|
+
/**
|
|
7
|
+
* Shortcut to set a value to an array and return the instance.
|
|
8
|
+
*/
|
|
9
|
+
_setArray = (fields, input) => {
|
|
10
|
+
if (Array.isArray(input)) require_lodash_set.set(this, fields, input);
|
|
11
|
+
else require_lodash_set.set(this, fields, [input]);
|
|
12
|
+
return this;
|
|
13
|
+
};
|
|
14
|
+
/**
|
|
15
|
+
* Shortcut to set a value and return the instance.
|
|
16
|
+
*/
|
|
17
|
+
_setValue = (fields, input) => {
|
|
18
|
+
require_lodash_set.set(this, fields, input);
|
|
19
|
+
return this;
|
|
20
|
+
};
|
|
21
|
+
/**
|
|
22
|
+
* Shortcut to add a value to an existing array.
|
|
23
|
+
*/
|
|
24
|
+
_push = (fields, input) => {
|
|
25
|
+
let temp = this._get(fields, []);
|
|
26
|
+
if (Array.isArray(input)) temp = temp.concat(input);
|
|
27
|
+
else temp = temp.push(input);
|
|
28
|
+
require_lodash_set.set(this, fields, temp);
|
|
29
|
+
return this;
|
|
30
|
+
};
|
|
31
|
+
/**
|
|
32
|
+
* Shortcut to get a value, but default if the fields don't exist.
|
|
33
|
+
*/
|
|
34
|
+
_get = (fields, defaultValue = null) => {
|
|
35
|
+
return require_util_defaultTo.defaultTo(this, fields, defaultValue);
|
|
36
|
+
};
|
|
27
37
|
};
|
|
28
38
|
//#endregion
|
|
29
39
|
exports.BaseClass = BaseClass;
|
|
@@ -2,27 +2,37 @@ import { set } from "../lodash/set.mjs";
|
|
|
2
2
|
import { defaultTo } from "../util/defaultTo.mjs";
|
|
3
3
|
//#region src/_class/BaseClass.ts
|
|
4
4
|
var BaseClass = class {
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
this
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
5
|
+
/**
|
|
6
|
+
* Shortcut to set a value to an array and return the instance.
|
|
7
|
+
*/
|
|
8
|
+
_setArray = (fields, input) => {
|
|
9
|
+
if (Array.isArray(input)) set(this, fields, input);
|
|
10
|
+
else set(this, fields, [input]);
|
|
11
|
+
return this;
|
|
12
|
+
};
|
|
13
|
+
/**
|
|
14
|
+
* Shortcut to set a value and return the instance.
|
|
15
|
+
*/
|
|
16
|
+
_setValue = (fields, input) => {
|
|
17
|
+
set(this, fields, input);
|
|
18
|
+
return this;
|
|
19
|
+
};
|
|
20
|
+
/**
|
|
21
|
+
* Shortcut to add a value to an existing array.
|
|
22
|
+
*/
|
|
23
|
+
_push = (fields, input) => {
|
|
24
|
+
let temp = this._get(fields, []);
|
|
25
|
+
if (Array.isArray(input)) temp = temp.concat(input);
|
|
26
|
+
else temp = temp.push(input);
|
|
27
|
+
set(this, fields, temp);
|
|
28
|
+
return this;
|
|
29
|
+
};
|
|
30
|
+
/**
|
|
31
|
+
* Shortcut to get a value, but default if the fields don't exist.
|
|
32
|
+
*/
|
|
33
|
+
_get = (fields, defaultValue = null) => {
|
|
34
|
+
return defaultTo(this, fields, defaultValue);
|
|
35
|
+
};
|
|
26
36
|
};
|
|
27
37
|
//#endregion
|
|
28
38
|
export { BaseClass };
|
|
@@ -2,20 +2,21 @@ Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
|
|
2
2
|
const require_environment_environment = require("../environment/environment.cjs");
|
|
3
3
|
//#region src/_class/BaseNamespace.ts
|
|
4
4
|
var BaseNamespace = class {
|
|
5
|
+
client = null;
|
|
6
|
+
key;
|
|
7
|
+
config = null;
|
|
5
8
|
constructor(key, config) {
|
|
6
|
-
this.client = null;
|
|
7
|
-
this.config = null;
|
|
8
|
-
this.ensureInit = async () => {};
|
|
9
|
-
this.reset = () => {
|
|
10
|
-
this.client = null;
|
|
11
|
-
};
|
|
12
|
-
this.getClient = async () => {
|
|
13
|
-
return this.client();
|
|
14
|
-
};
|
|
15
9
|
if (!require_environment_environment.isServer) throw new Error("Server-side only class accessed from client");
|
|
16
10
|
this.key = key;
|
|
17
11
|
this.config = config;
|
|
18
12
|
}
|
|
13
|
+
ensureInit = async () => {};
|
|
14
|
+
reset = () => {
|
|
15
|
+
this.client = null;
|
|
16
|
+
};
|
|
17
|
+
getClient = async () => {
|
|
18
|
+
return this.client();
|
|
19
|
+
};
|
|
19
20
|
};
|
|
20
21
|
//#endregion
|
|
21
22
|
exports.BaseNamespace = BaseNamespace;
|
|
@@ -1,20 +1,21 @@
|
|
|
1
1
|
import { isServer } from "../environment/environment.mjs";
|
|
2
2
|
//#region src/_class/BaseNamespace.ts
|
|
3
3
|
var BaseNamespace = class {
|
|
4
|
+
client = null;
|
|
5
|
+
key;
|
|
6
|
+
config = null;
|
|
4
7
|
constructor(key, config) {
|
|
5
|
-
this.client = null;
|
|
6
|
-
this.config = null;
|
|
7
|
-
this.ensureInit = async () => {};
|
|
8
|
-
this.reset = () => {
|
|
9
|
-
this.client = null;
|
|
10
|
-
};
|
|
11
|
-
this.getClient = async () => {
|
|
12
|
-
return this.client();
|
|
13
|
-
};
|
|
14
8
|
if (!isServer) throw new Error("Server-side only class accessed from client");
|
|
15
9
|
this.key = key;
|
|
16
10
|
this.config = config;
|
|
17
11
|
}
|
|
12
|
+
ensureInit = async () => {};
|
|
13
|
+
reset = () => {
|
|
14
|
+
this.client = null;
|
|
15
|
+
};
|
|
16
|
+
getClient = async () => {
|
|
17
|
+
return this.client();
|
|
18
|
+
};
|
|
18
19
|
};
|
|
19
20
|
//#endregion
|
|
20
21
|
export { BaseNamespace };
|
|
@@ -6,108 +6,108 @@ const require_api_api = require("./api.cjs");
|
|
|
6
6
|
* Class version of the API to enable quicker instances.
|
|
7
7
|
*/
|
|
8
8
|
var ApiResponseClass = class ApiResponseClass {
|
|
9
|
+
state = require_api_api.apiState.IDLE;
|
|
10
|
+
body = null;
|
|
11
|
+
error = null;
|
|
9
12
|
constructor({ body, error, state } = {}) {
|
|
10
|
-
this.state = require_api_api.apiState.IDLE;
|
|
11
|
-
this.body = null;
|
|
12
|
-
this.error = null;
|
|
13
|
-
this.fromJson = (input) => {
|
|
14
|
-
this.body = input.body;
|
|
15
|
-
this.error = input.error;
|
|
16
|
-
this.state = input.state;
|
|
17
|
-
return this;
|
|
18
|
-
};
|
|
19
|
-
this.getBody = () => {
|
|
20
|
-
return this.body;
|
|
21
|
-
};
|
|
22
|
-
this.getBodyDefaultTo = (keys, defaultValue) => {
|
|
23
|
-
return require_util_defaultTo.defaultTo(this.body, keys, defaultValue);
|
|
24
|
-
};
|
|
25
|
-
this.getError = () => {
|
|
26
|
-
return this.error;
|
|
27
|
-
};
|
|
28
|
-
this.getJson = () => {
|
|
29
|
-
return {
|
|
30
|
-
body: this.body,
|
|
31
|
-
error: this.error,
|
|
32
|
-
state: this.state
|
|
33
|
-
};
|
|
34
|
-
};
|
|
35
|
-
this.getApiState = () => {
|
|
36
|
-
return this.state;
|
|
37
|
-
};
|
|
38
|
-
this.isError = () => {
|
|
39
|
-
return this.state === require_api_api.apiState.ERROR;
|
|
40
|
-
};
|
|
41
|
-
this.isIdle = () => {
|
|
42
|
-
return this.state === require_api_api.apiState.IDLE;
|
|
43
|
-
};
|
|
44
|
-
this.isPending = () => {
|
|
45
|
-
return this.state === require_api_api.apiState.PENDING;
|
|
46
|
-
};
|
|
47
|
-
this.isSuccess = () => {
|
|
48
|
-
return this.state === require_api_api.apiState.SUCCESS;
|
|
49
|
-
};
|
|
50
|
-
this.setToIdle = () => {
|
|
51
|
-
this.state = require_api_api.apiState.IDLE;
|
|
52
|
-
return this;
|
|
53
|
-
};
|
|
54
|
-
this.setToPending = () => {
|
|
55
|
-
this.state = require_api_api.apiState.PENDING;
|
|
56
|
-
return this;
|
|
57
|
-
};
|
|
58
|
-
this.setToError = (error, body) => {
|
|
59
|
-
this.body = body || null;
|
|
60
|
-
this.error = error;
|
|
61
|
-
this.state = require_api_api.apiState.ERROR;
|
|
62
|
-
return this;
|
|
63
|
-
};
|
|
64
|
-
this.setToZodSafeError = (zodResult, body) => {
|
|
65
|
-
let errors = [];
|
|
66
|
-
if (zodResult?.error?.issues) for (const singleError of zodResult.error.issues) {
|
|
67
|
-
const finalPath = singleError.path.map((singlePath) => singlePath.toString()).join(".");
|
|
68
|
-
errors.push(`${finalPath}: ${singleError.message}`);
|
|
69
|
-
}
|
|
70
|
-
else errors = ["An unexpected error occurred, please try again."];
|
|
71
|
-
this.body = body || null;
|
|
72
|
-
this.error = errors.join(", ");
|
|
73
|
-
this.state = require_api_api.apiState.ERROR;
|
|
74
|
-
return this;
|
|
75
|
-
};
|
|
76
|
-
this.setToSuccess = (body) => {
|
|
77
|
-
this.body = body;
|
|
78
|
-
this.state = require_api_api.apiState.SUCCESS;
|
|
79
|
-
return this;
|
|
80
|
-
};
|
|
81
|
-
this.setBody = (body) => {
|
|
82
|
-
this.body = body;
|
|
83
|
-
return this;
|
|
84
|
-
};
|
|
85
|
-
this.setError = (error) => {
|
|
86
|
-
this.error = error;
|
|
87
|
-
return this;
|
|
88
|
-
};
|
|
89
|
-
this.setApiState = (state) => {
|
|
90
|
-
this.state = state;
|
|
91
|
-
return this;
|
|
92
|
-
};
|
|
93
|
-
this.validateZod = (schema) => {
|
|
94
|
-
try {
|
|
95
|
-
return new ApiResponseClass({
|
|
96
|
-
body: schema.parse(this.body),
|
|
97
|
-
state: this.state
|
|
98
|
-
});
|
|
99
|
-
} catch (error) {
|
|
100
|
-
return new ApiResponseClass({
|
|
101
|
-
error,
|
|
102
|
-
state: require_api_api.apiState.ERROR
|
|
103
|
-
});
|
|
104
|
-
}
|
|
105
|
-
};
|
|
106
13
|
this.body = body || null;
|
|
107
14
|
this.error = error || null;
|
|
108
15
|
this.state = state || require_api_api.apiState.IDLE;
|
|
109
16
|
return this;
|
|
110
17
|
}
|
|
18
|
+
fromJson = (input) => {
|
|
19
|
+
this.body = input.body;
|
|
20
|
+
this.error = input.error;
|
|
21
|
+
this.state = input.state;
|
|
22
|
+
return this;
|
|
23
|
+
};
|
|
24
|
+
getBody = () => {
|
|
25
|
+
return this.body;
|
|
26
|
+
};
|
|
27
|
+
getBodyDefaultTo = (keys, defaultValue) => {
|
|
28
|
+
return require_util_defaultTo.defaultTo(this.body, keys, defaultValue);
|
|
29
|
+
};
|
|
30
|
+
getError = () => {
|
|
31
|
+
return this.error;
|
|
32
|
+
};
|
|
33
|
+
getJson = () => {
|
|
34
|
+
return {
|
|
35
|
+
body: this.body,
|
|
36
|
+
error: this.error,
|
|
37
|
+
state: this.state
|
|
38
|
+
};
|
|
39
|
+
};
|
|
40
|
+
getApiState = () => {
|
|
41
|
+
return this.state;
|
|
42
|
+
};
|
|
43
|
+
isError = () => {
|
|
44
|
+
return this.state === require_api_api.apiState.ERROR;
|
|
45
|
+
};
|
|
46
|
+
isIdle = () => {
|
|
47
|
+
return this.state === require_api_api.apiState.IDLE;
|
|
48
|
+
};
|
|
49
|
+
isPending = () => {
|
|
50
|
+
return this.state === require_api_api.apiState.PENDING;
|
|
51
|
+
};
|
|
52
|
+
isSuccess = () => {
|
|
53
|
+
return this.state === require_api_api.apiState.SUCCESS;
|
|
54
|
+
};
|
|
55
|
+
setToIdle = () => {
|
|
56
|
+
this.state = require_api_api.apiState.IDLE;
|
|
57
|
+
return this;
|
|
58
|
+
};
|
|
59
|
+
setToPending = () => {
|
|
60
|
+
this.state = require_api_api.apiState.PENDING;
|
|
61
|
+
return this;
|
|
62
|
+
};
|
|
63
|
+
setToError = (error, body) => {
|
|
64
|
+
this.body = body || null;
|
|
65
|
+
this.error = error;
|
|
66
|
+
this.state = require_api_api.apiState.ERROR;
|
|
67
|
+
return this;
|
|
68
|
+
};
|
|
69
|
+
setToZodSafeError = (zodResult, body) => {
|
|
70
|
+
let errors = [];
|
|
71
|
+
if (zodResult?.error?.issues) for (const singleError of zodResult.error.issues) {
|
|
72
|
+
const finalPath = singleError.path.map((singlePath) => singlePath.toString()).join(".");
|
|
73
|
+
errors.push(`${finalPath}: ${singleError.message}`);
|
|
74
|
+
}
|
|
75
|
+
else errors = ["An unexpected error occurred, please try again."];
|
|
76
|
+
this.body = body || null;
|
|
77
|
+
this.error = errors.join(", ");
|
|
78
|
+
this.state = require_api_api.apiState.ERROR;
|
|
79
|
+
return this;
|
|
80
|
+
};
|
|
81
|
+
setToSuccess = (body) => {
|
|
82
|
+
this.body = body;
|
|
83
|
+
this.state = require_api_api.apiState.SUCCESS;
|
|
84
|
+
return this;
|
|
85
|
+
};
|
|
86
|
+
setBody = (body) => {
|
|
87
|
+
this.body = body;
|
|
88
|
+
return this;
|
|
89
|
+
};
|
|
90
|
+
setError = (error) => {
|
|
91
|
+
this.error = error;
|
|
92
|
+
return this;
|
|
93
|
+
};
|
|
94
|
+
setApiState = (state) => {
|
|
95
|
+
this.state = state;
|
|
96
|
+
return this;
|
|
97
|
+
};
|
|
98
|
+
validateZod = (schema) => {
|
|
99
|
+
try {
|
|
100
|
+
return new ApiResponseClass({
|
|
101
|
+
body: schema.parse(this.body),
|
|
102
|
+
state: this.state
|
|
103
|
+
});
|
|
104
|
+
} catch (error) {
|
|
105
|
+
return new ApiResponseClass({
|
|
106
|
+
error,
|
|
107
|
+
state: require_api_api.apiState.ERROR
|
|
108
|
+
});
|
|
109
|
+
}
|
|
110
|
+
};
|
|
111
111
|
};
|
|
112
112
|
//#endregion
|
|
113
113
|
exports.ApiResponseClass = ApiResponseClass;
|
|
@@ -5,108 +5,108 @@ import { apiState } from "./api.mjs";
|
|
|
5
5
|
* Class version of the API to enable quicker instances.
|
|
6
6
|
*/
|
|
7
7
|
var ApiResponseClass = class ApiResponseClass {
|
|
8
|
+
state = apiState.IDLE;
|
|
9
|
+
body = null;
|
|
10
|
+
error = null;
|
|
8
11
|
constructor({ body, error, state } = {}) {
|
|
9
|
-
this.state = apiState.IDLE;
|
|
10
|
-
this.body = null;
|
|
11
|
-
this.error = null;
|
|
12
|
-
this.fromJson = (input) => {
|
|
13
|
-
this.body = input.body;
|
|
14
|
-
this.error = input.error;
|
|
15
|
-
this.state = input.state;
|
|
16
|
-
return this;
|
|
17
|
-
};
|
|
18
|
-
this.getBody = () => {
|
|
19
|
-
return this.body;
|
|
20
|
-
};
|
|
21
|
-
this.getBodyDefaultTo = (keys, defaultValue) => {
|
|
22
|
-
return defaultTo(this.body, keys, defaultValue);
|
|
23
|
-
};
|
|
24
|
-
this.getError = () => {
|
|
25
|
-
return this.error;
|
|
26
|
-
};
|
|
27
|
-
this.getJson = () => {
|
|
28
|
-
return {
|
|
29
|
-
body: this.body,
|
|
30
|
-
error: this.error,
|
|
31
|
-
state: this.state
|
|
32
|
-
};
|
|
33
|
-
};
|
|
34
|
-
this.getApiState = () => {
|
|
35
|
-
return this.state;
|
|
36
|
-
};
|
|
37
|
-
this.isError = () => {
|
|
38
|
-
return this.state === apiState.ERROR;
|
|
39
|
-
};
|
|
40
|
-
this.isIdle = () => {
|
|
41
|
-
return this.state === apiState.IDLE;
|
|
42
|
-
};
|
|
43
|
-
this.isPending = () => {
|
|
44
|
-
return this.state === apiState.PENDING;
|
|
45
|
-
};
|
|
46
|
-
this.isSuccess = () => {
|
|
47
|
-
return this.state === apiState.SUCCESS;
|
|
48
|
-
};
|
|
49
|
-
this.setToIdle = () => {
|
|
50
|
-
this.state = apiState.IDLE;
|
|
51
|
-
return this;
|
|
52
|
-
};
|
|
53
|
-
this.setToPending = () => {
|
|
54
|
-
this.state = apiState.PENDING;
|
|
55
|
-
return this;
|
|
56
|
-
};
|
|
57
|
-
this.setToError = (error, body) => {
|
|
58
|
-
this.body = body || null;
|
|
59
|
-
this.error = error;
|
|
60
|
-
this.state = apiState.ERROR;
|
|
61
|
-
return this;
|
|
62
|
-
};
|
|
63
|
-
this.setToZodSafeError = (zodResult, body) => {
|
|
64
|
-
let errors = [];
|
|
65
|
-
if (zodResult?.error?.issues) for (const singleError of zodResult.error.issues) {
|
|
66
|
-
const finalPath = singleError.path.map((singlePath) => singlePath.toString()).join(".");
|
|
67
|
-
errors.push(`${finalPath}: ${singleError.message}`);
|
|
68
|
-
}
|
|
69
|
-
else errors = ["An unexpected error occurred, please try again."];
|
|
70
|
-
this.body = body || null;
|
|
71
|
-
this.error = errors.join(", ");
|
|
72
|
-
this.state = apiState.ERROR;
|
|
73
|
-
return this;
|
|
74
|
-
};
|
|
75
|
-
this.setToSuccess = (body) => {
|
|
76
|
-
this.body = body;
|
|
77
|
-
this.state = apiState.SUCCESS;
|
|
78
|
-
return this;
|
|
79
|
-
};
|
|
80
|
-
this.setBody = (body) => {
|
|
81
|
-
this.body = body;
|
|
82
|
-
return this;
|
|
83
|
-
};
|
|
84
|
-
this.setError = (error) => {
|
|
85
|
-
this.error = error;
|
|
86
|
-
return this;
|
|
87
|
-
};
|
|
88
|
-
this.setApiState = (state) => {
|
|
89
|
-
this.state = state;
|
|
90
|
-
return this;
|
|
91
|
-
};
|
|
92
|
-
this.validateZod = (schema) => {
|
|
93
|
-
try {
|
|
94
|
-
return new ApiResponseClass({
|
|
95
|
-
body: schema.parse(this.body),
|
|
96
|
-
state: this.state
|
|
97
|
-
});
|
|
98
|
-
} catch (error) {
|
|
99
|
-
return new ApiResponseClass({
|
|
100
|
-
error,
|
|
101
|
-
state: apiState.ERROR
|
|
102
|
-
});
|
|
103
|
-
}
|
|
104
|
-
};
|
|
105
12
|
this.body = body || null;
|
|
106
13
|
this.error = error || null;
|
|
107
14
|
this.state = state || apiState.IDLE;
|
|
108
15
|
return this;
|
|
109
16
|
}
|
|
17
|
+
fromJson = (input) => {
|
|
18
|
+
this.body = input.body;
|
|
19
|
+
this.error = input.error;
|
|
20
|
+
this.state = input.state;
|
|
21
|
+
return this;
|
|
22
|
+
};
|
|
23
|
+
getBody = () => {
|
|
24
|
+
return this.body;
|
|
25
|
+
};
|
|
26
|
+
getBodyDefaultTo = (keys, defaultValue) => {
|
|
27
|
+
return defaultTo(this.body, keys, defaultValue);
|
|
28
|
+
};
|
|
29
|
+
getError = () => {
|
|
30
|
+
return this.error;
|
|
31
|
+
};
|
|
32
|
+
getJson = () => {
|
|
33
|
+
return {
|
|
34
|
+
body: this.body,
|
|
35
|
+
error: this.error,
|
|
36
|
+
state: this.state
|
|
37
|
+
};
|
|
38
|
+
};
|
|
39
|
+
getApiState = () => {
|
|
40
|
+
return this.state;
|
|
41
|
+
};
|
|
42
|
+
isError = () => {
|
|
43
|
+
return this.state === apiState.ERROR;
|
|
44
|
+
};
|
|
45
|
+
isIdle = () => {
|
|
46
|
+
return this.state === apiState.IDLE;
|
|
47
|
+
};
|
|
48
|
+
isPending = () => {
|
|
49
|
+
return this.state === apiState.PENDING;
|
|
50
|
+
};
|
|
51
|
+
isSuccess = () => {
|
|
52
|
+
return this.state === apiState.SUCCESS;
|
|
53
|
+
};
|
|
54
|
+
setToIdle = () => {
|
|
55
|
+
this.state = apiState.IDLE;
|
|
56
|
+
return this;
|
|
57
|
+
};
|
|
58
|
+
setToPending = () => {
|
|
59
|
+
this.state = apiState.PENDING;
|
|
60
|
+
return this;
|
|
61
|
+
};
|
|
62
|
+
setToError = (error, body) => {
|
|
63
|
+
this.body = body || null;
|
|
64
|
+
this.error = error;
|
|
65
|
+
this.state = apiState.ERROR;
|
|
66
|
+
return this;
|
|
67
|
+
};
|
|
68
|
+
setToZodSafeError = (zodResult, body) => {
|
|
69
|
+
let errors = [];
|
|
70
|
+
if (zodResult?.error?.issues) for (const singleError of zodResult.error.issues) {
|
|
71
|
+
const finalPath = singleError.path.map((singlePath) => singlePath.toString()).join(".");
|
|
72
|
+
errors.push(`${finalPath}: ${singleError.message}`);
|
|
73
|
+
}
|
|
74
|
+
else errors = ["An unexpected error occurred, please try again."];
|
|
75
|
+
this.body = body || null;
|
|
76
|
+
this.error = errors.join(", ");
|
|
77
|
+
this.state = apiState.ERROR;
|
|
78
|
+
return this;
|
|
79
|
+
};
|
|
80
|
+
setToSuccess = (body) => {
|
|
81
|
+
this.body = body;
|
|
82
|
+
this.state = apiState.SUCCESS;
|
|
83
|
+
return this;
|
|
84
|
+
};
|
|
85
|
+
setBody = (body) => {
|
|
86
|
+
this.body = body;
|
|
87
|
+
return this;
|
|
88
|
+
};
|
|
89
|
+
setError = (error) => {
|
|
90
|
+
this.error = error;
|
|
91
|
+
return this;
|
|
92
|
+
};
|
|
93
|
+
setApiState = (state) => {
|
|
94
|
+
this.state = state;
|
|
95
|
+
return this;
|
|
96
|
+
};
|
|
97
|
+
validateZod = (schema) => {
|
|
98
|
+
try {
|
|
99
|
+
return new ApiResponseClass({
|
|
100
|
+
body: schema.parse(this.body),
|
|
101
|
+
state: this.state
|
|
102
|
+
});
|
|
103
|
+
} catch (error) {
|
|
104
|
+
return new ApiResponseClass({
|
|
105
|
+
error,
|
|
106
|
+
state: apiState.ERROR
|
|
107
|
+
});
|
|
108
|
+
}
|
|
109
|
+
};
|
|
110
110
|
};
|
|
111
111
|
//#endregion
|
|
112
112
|
export { ApiResponseClass };
|