@xube/kit-request 0.0.1

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.
@@ -0,0 +1 @@
1
+ export declare const suggestSupportRequest: (message: string) => string;
@@ -0,0 +1,5 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.suggestSupportRequest = void 0;
4
+ const suggestSupportRequest = (message) => message + " Please contact Xube support.";
5
+ exports.suggestSupportRequest = suggestSupportRequest;
@@ -0,0 +1,2 @@
1
+ export * from "./helpers";
2
+ export * from "./response/response";
package/dist/index.js ADDED
@@ -0,0 +1,18 @@
1
+ "use strict";
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ var desc = Object.getOwnPropertyDescriptor(m, k);
5
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
+ desc = { enumerable: true, get: function() { return m[k]; } };
7
+ }
8
+ Object.defineProperty(o, k2, desc);
9
+ }) : (function(o, m, k, k2) {
10
+ if (k2 === undefined) k2 = k;
11
+ o[k2] = m[k];
12
+ }));
13
+ var __exportStar = (this && this.__exportStar) || function(m, exports) {
14
+ for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
15
+ };
16
+ Object.defineProperty(exports, "__esModule", { value: true });
17
+ __exportStar(require("./helpers"), exports);
18
+ __exportStar(require("./response/response"), exports);
@@ -0,0 +1,18 @@
1
+ import { XubeLog } from "@xube/kit-log";
2
+ import { DATA, ERROR, STATUS_CODE, StatusCode } from "@xube/kit-constants";
3
+ export interface XubeResponseProps<TData> {
4
+ [STATUS_CODE]: StatusCode;
5
+ [ERROR]?: string;
6
+ [DATA]?: TData;
7
+ }
8
+ export declare class XubeResponse<TData> implements XubeResponseProps<TData> {
9
+ statusCode: StatusCode;
10
+ error?: string;
11
+ data?: TData;
12
+ constructor(props: XubeResponseProps<TData>);
13
+ isSuccessful: () => boolean;
14
+ hasFailed: () => boolean;
15
+ }
16
+ export declare const xubeResponseSucceeded: <TData>(xubeResponse: XubeResponse<TData>) => boolean;
17
+ export declare const xubeResponseFailed: <TData>(xubeResponse: XubeResponse<TData>) => boolean;
18
+ export declare const switchXubeResponseType: <TDATA_IN, TDATA_OUT>(inXubeResponse: XubeResponse<TDATA_IN>, log?: XubeLog) => XubeResponse<TDATA_OUT>;
@@ -0,0 +1,34 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.switchXubeResponseType = exports.xubeResponseFailed = exports.xubeResponseSucceeded = exports.XubeResponse = void 0;
4
+ const kit_log_1 = require("@xube/kit-log");
5
+ const kit_constants_1 = require("@xube/kit-constants");
6
+ const helpers_1 = require("../helpers");
7
+ class XubeResponse {
8
+ statusCode;
9
+ error;
10
+ data;
11
+ constructor(props) {
12
+ this.statusCode = props[kit_constants_1.STATUS_CODE];
13
+ this.error = props[kit_constants_1.ERROR] ? (0, helpers_1.suggestSupportRequest)(props[kit_constants_1.ERROR]) : undefined;
14
+ this.data = props[kit_constants_1.DATA];
15
+ }
16
+ isSuccessful = () => (0, exports.xubeResponseSucceeded)(this);
17
+ hasFailed = () => (0, exports.xubeResponseFailed)(this);
18
+ }
19
+ exports.XubeResponse = XubeResponse;
20
+ const xubeResponseSucceeded = (xubeResponse) => xubeResponse.statusCode <= 300;
21
+ exports.xubeResponseSucceeded = xubeResponseSucceeded;
22
+ const xubeResponseFailed = (xubeResponse) => !(0, exports.xubeResponseSucceeded)(xubeResponse);
23
+ exports.xubeResponseFailed = xubeResponseFailed;
24
+ const switchXubeResponseType = (inXubeResponse, log = kit_log_1.XubeLog.getInstance()) => {
25
+ if (inXubeResponse.data) {
26
+ log.warn("Requester Response had data. Removing, but this could be undesired");
27
+ delete inXubeResponse.data;
28
+ }
29
+ return new XubeResponse({
30
+ statusCode: inXubeResponse.statusCode,
31
+ error: inXubeResponse.error,
32
+ });
33
+ };
34
+ exports.switchXubeResponseType = switchXubeResponseType;
package/package.json ADDED
@@ -0,0 +1,22 @@
1
+ {
2
+ "name": "@xube/kit-request",
3
+ "version": "0.0.1",
4
+ "description": "",
5
+ "main": "dist/index.js",
6
+ "scripts": {
7
+ "test": "echo \"Error: no test specified\" && exit 1"
8
+ },
9
+ "repository": {
10
+ "type": "git",
11
+ "url": "git+ssh://git@github.com/XubeLtd/data-logger.git"
12
+ },
13
+ "author": "Xube Pty Ltd",
14
+ "license": "MIT",
15
+ "bugs": {
16
+ "url": "https://github.com/XubeLtd/data-logger/issues"
17
+ },
18
+ "homepage": "https://github.com/XubeLtd/data-logger#readme",
19
+ "dependencies": {
20
+ "@xube/kit-constants": "^0.0.1"
21
+ }
22
+ }
package/src/helpers.ts ADDED
@@ -0,0 +1 @@
1
+ export const suggestSupportRequest = (message: string) => message + " Please contact Xube support."
package/src/index.ts ADDED
@@ -0,0 +1,2 @@
1
+ export * from "./helpers";
2
+ export * from "./response/response";
@@ -0,0 +1,50 @@
1
+
2
+ import { XubeLog } from "@xube/kit-log";
3
+ import { DATA, ERROR, STATUS_CODE, StatusCode } from "@xube/kit-constants";
4
+ import { suggestSupportRequest } from "../helpers";
5
+
6
+ export interface XubeResponseProps<TData> {
7
+ [STATUS_CODE]: StatusCode;
8
+ [ERROR]?: string;
9
+ [DATA]?: TData;
10
+ }
11
+
12
+ export class XubeResponse<TData> implements XubeResponseProps<TData> {
13
+ public statusCode: StatusCode;
14
+ public error?: string;
15
+ public data?: TData;
16
+
17
+ constructor(props: XubeResponseProps<TData>) {
18
+ this.statusCode = props[STATUS_CODE];
19
+ this.error = props[ERROR] ? suggestSupportRequest(props[ERROR]) : undefined;
20
+ this.data = props[DATA];
21
+ }
22
+
23
+ isSuccessful = (): boolean => xubeResponseSucceeded(this);
24
+ hasFailed = (): boolean => xubeResponseFailed(this);
25
+ }
26
+
27
+ export const xubeResponseSucceeded = <TData>(
28
+ xubeResponse: XubeResponse<TData>
29
+ ): boolean => xubeResponse.statusCode <= 300;
30
+
31
+ export const xubeResponseFailed = <TData>(
32
+ xubeResponse: XubeResponse<TData>
33
+ ): boolean => !xubeResponseSucceeded(xubeResponse);
34
+
35
+ export const switchXubeResponseType = <TDATA_IN, TDATA_OUT>(
36
+ inXubeResponse: XubeResponse<TDATA_IN>,
37
+ log: XubeLog = XubeLog.getInstance()
38
+ ): XubeResponse<TDATA_OUT> => {
39
+ if (inXubeResponse.data) {
40
+ log.warn(
41
+ "Requester Response had data. Removing, but this could be undesired"
42
+ );
43
+ delete inXubeResponse.data;
44
+ }
45
+ return new XubeResponse<TDATA_OUT>({
46
+ statusCode: inXubeResponse.statusCode,
47
+ error: inXubeResponse.error,
48
+ });
49
+ };
50
+
package/tsconfig.json ADDED
@@ -0,0 +1,16 @@
1
+ {
2
+ "extends": "../kit-build/tsconfig.json",
3
+ "compilerOptions": {
4
+ "rootDir": "./src",
5
+ "outDir": "./dist"
6
+ },
7
+ "exclude": ["**/*.test.ts", "**/*.mock.ts", "dist", "./src/generator.ts"],
8
+ "references": [
9
+ {
10
+ "path": "../kit-generator"
11
+ },
12
+ {
13
+ "path": "../kit-constants"
14
+ }
15
+ ]
16
+ }