@qnx/client 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.
package/README.md ADDED
@@ -0,0 +1,58 @@
1
+ # @qnx/client
2
+
3
+ @qnx/client is providing components to simplify your codes.
4
+
5
+ ## Installation
6
+
7
+ Use the package manager [npm](https://www.npmjs.com/) to install @qnx/client.
8
+
9
+ ```bash
10
+ npm install @qnx/client
11
+ ```
12
+
13
+ You can also use [yarn](https://yarnpkg.com/) & [pnpm](https://pnpm.io/)
14
+
15
+ ```bash
16
+ yarn add @qnx/client
17
+ ```
18
+
19
+ ```bash
20
+ pnpm install @qnx/client
21
+ ```
22
+
23
+ ## Usage
24
+
25
+ ```bash
26
+ import { ApiResponse } from '@qnx/client'
27
+
28
+ const res = {
29
+ data: {
30
+ user: {
31
+ name: "User",
32
+ email: "test@gmail.com",
33
+ },
34
+ },
35
+ errorCode: null,
36
+ errors: null,
37
+ error: null,
38
+ message: null,
39
+ serverError: null,
40
+ };
41
+
42
+ const apiRes = ApiResponse(res)
43
+
44
+ const data = apiRes.getData()
45
+ const message = apiRes.getMessage()
46
+
47
+ ```
48
+
49
+ ## Contributing
50
+
51
+ Pull requests are welcome. For major changes, please open an issue first
52
+ to discuss what you would like to change.
53
+
54
+ Please make sure to update tests as appropriate.
55
+
56
+ ## License
57
+
58
+ [MIT License](https://github.com/yatendra121/client/blob/main/LICENSE.md) © 2023-PRESENT [Yatendra Kushwaha](https://github.com/yatendra121)
@@ -0,0 +1 @@
1
+ "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});class s{constructor(e={}){this.response=e}getErrorCode(){return this.response.errorCode}getErrors(){return this.response.errors}getError(){return this.response.error}getMessage(){return this.response.message}getData(){return this.response.data}}class t{constructor(e){this.response=e}getData(){return this.response.data}getMessage(){return this.response.message}}class o{constructor(e){this.response=e}getError(){return this.response.error}getErrors(){return this.response.errors}getErrorCode(){return this.response.errorCode}}exports.ApiErrorResponse=o;exports.ApiResponse=s;exports.ApiSuccessResponse=t;
@@ -0,0 +1 @@
1
+ var client=function(r){"use strict";class t{constructor(e={}){this.response=e}getErrorCode(){return this.response.errorCode}getErrors(){return this.response.errors}getError(){return this.response.error}getMessage(){return this.response.message}getData(){return this.response.data}}class o{constructor(e){this.response=e}getData(){return this.response.data}getMessage(){return this.response.message}}class n{constructor(e){this.response=e}getError(){return this.response.error}getErrors(){return this.response.errors}getErrorCode(){return this.response.errorCode}}return r.ApiErrorResponse=n,r.ApiResponse=t,r.ApiSuccessResponse=o,Object.defineProperty(r,Symbol.toStringTag,{value:"Module"}),r}({});
@@ -0,0 +1,50 @@
1
+ class s {
2
+ constructor(r = {}) {
3
+ this.response = r;
4
+ }
5
+ getErrorCode() {
6
+ return this.response.errorCode;
7
+ }
8
+ getErrors() {
9
+ return this.response.errors;
10
+ }
11
+ getError() {
12
+ return this.response.error;
13
+ }
14
+ getMessage() {
15
+ return this.response.message;
16
+ }
17
+ getData() {
18
+ return this.response.data;
19
+ }
20
+ }
21
+ class t {
22
+ constructor(r) {
23
+ this.response = r;
24
+ }
25
+ getData() {
26
+ return this.response.data;
27
+ }
28
+ getMessage() {
29
+ return this.response.message;
30
+ }
31
+ }
32
+ class o {
33
+ constructor(r) {
34
+ this.response = r;
35
+ }
36
+ getError() {
37
+ return this.response.error;
38
+ }
39
+ getErrors() {
40
+ return this.response.errors;
41
+ }
42
+ getErrorCode() {
43
+ return this.response.errorCode;
44
+ }
45
+ }
46
+ export {
47
+ o as ApiErrorResponse,
48
+ s as ApiResponse,
49
+ t as ApiSuccessResponse
50
+ };
@@ -0,0 +1,65 @@
1
+ // Generated by dts-bundle-generator v8.0.1
2
+
3
+ export type ApiErrorCode = string;
4
+ export type ApiErrors = Record<string, string[]>;
5
+ export type ApiMessage = string;
6
+ export type ApiError = string;
7
+ export interface ApiResponseInterface<T> {
8
+ getData: () => T | undefined;
9
+ getMessage: () => ApiMessage | undefined;
10
+ getErrorCode(): ApiErrorCode | undefined;
11
+ getErrors(): ApiErrors | undefined;
12
+ getError(): ApiError | undefined;
13
+ }
14
+ export interface ApiResponseValue<T = any> {
15
+ readonly data?: T;
16
+ readonly errorCode?: ApiErrorCode;
17
+ readonly error?: ApiError;
18
+ readonly errors?: ApiErrors;
19
+ readonly message?: ApiMessage;
20
+ readonly serverError?: any;
21
+ }
22
+ /**
23
+ * Will use collect data from api response
24
+ */
25
+ export declare class ApiResponse<T = any> implements ApiResponseInterface<T> {
26
+ private readonly response;
27
+ constructor(response?: ApiResponseValue<T>);
28
+ getErrorCode(): ApiErrorCode | undefined;
29
+ getErrors(): ApiErrors | undefined;
30
+ getError(): ApiError | undefined;
31
+ getMessage(): ApiMessage | undefined;
32
+ getData(): T | undefined;
33
+ }
34
+ export interface ApiSuccessResponseInterface<T> {
35
+ getData: () => T;
36
+ getMessage: () => ApiMessage;
37
+ }
38
+ export type ApiSuccessResponseValue<T> = Pick<Required<ApiResponseValue<T>>, "data" | "message">;
39
+ /**
40
+ * Will use collect data from success api response
41
+ */
42
+ export declare class ApiSuccessResponse<T> implements ApiSuccessResponseInterface<T> {
43
+ private readonly response;
44
+ constructor(response: ApiSuccessResponseValue<T>);
45
+ getData(): T;
46
+ getMessage(): ApiMessage;
47
+ }
48
+ export interface ApiErrorResponseInterface {
49
+ getError: () => string;
50
+ getErrors: () => Record<string, string[]> | undefined;
51
+ getErrorCode: () => string | undefined;
52
+ }
53
+ export type ApiErrorResponseValue = Pick<Required<ApiResponseValue<unknown>>, "errors" | "error"> & Pick<ApiResponseValue<unknown>, "errorCode">;
54
+ /**
55
+ * Will use collect data from error api response
56
+ */
57
+ export declare class ApiErrorResponse implements ApiErrorResponseInterface {
58
+ private readonly response;
59
+ constructor(response: ApiErrorResponseValue);
60
+ getError(): string;
61
+ getErrors(): ApiErrors;
62
+ getErrorCode(): string | undefined;
63
+ }
64
+
65
+ export {};
package/package.json ADDED
@@ -0,0 +1,36 @@
1
+ {
2
+ "name": "@qnx/client",
3
+ "description": "QNX client for handling response",
4
+ "author": "Yatendra Kushwaha <https://github.com/yatendra121>",
5
+ "version": "0.0.1",
6
+ "license": "MIT",
7
+ "files": [
8
+ "dist"
9
+ ],
10
+ "keywords": [],
11
+ "repository": {
12
+ "type": "git",
13
+ "url": "https://github.com/yatendra121/qnx.git",
14
+ "directory": "packages/client"
15
+ },
16
+ "main": "./dist/client.cjs",
17
+ "module": "./dist/client.mjs",
18
+ "types": "./dist/index.d.ts",
19
+ "exports": {
20
+ ".": {
21
+ "require": "./dist/client.cjs",
22
+ "import": "./dist/client.mjs"
23
+ }
24
+ },
25
+ "unpkg": "./client.iife.js",
26
+ "jsdelivr": "./client.iife.js",
27
+ "scripts": {
28
+ "dev": "vite --host",
29
+ "build": "tsc && vite build && dts-bundle-generator --config ./dts-bundle-generator.config.ts",
30
+ "test": "vitest",
31
+ "test:coverage": "jest --runInBand --coverage",
32
+ "lint:scripts": "eslint . --ext .ts",
33
+ "format:scripts": "prettier . --write",
34
+ "format": "npm run format:scripts"
35
+ }
36
+ }