@etsoo/shared 1.1.81 → 1.1.82
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 +14 -0
- package/lib/cjs/ActionResult.d.ts +11 -0
- package/lib/cjs/ActionResult.js +30 -0
- package/lib/cjs/IActionResult.d.ts +59 -0
- package/lib/cjs/IActionResult.js +2 -0
- package/lib/mjs/ActionResult.d.ts +11 -0
- package/lib/mjs/ActionResult.js +26 -0
- package/lib/mjs/IActionResult.d.ts +59 -0
- package/lib/mjs/IActionResult.js +1 -0
- package/package.json +6 -6
- package/src/ActionResult.ts +31 -0
- package/src/IActionResult.ts +72 -0
package/README.md
CHANGED
|
@@ -15,6 +15,20 @@ Using yarn:
|
|
|
15
15
|
$ yarn add @etsoo/shared
|
|
16
16
|
```
|
|
17
17
|
|
|
18
|
+
## ActionResult / IActionResult, IdActionResult, DynamicActionResult
|
|
19
|
+
|Name|Description|
|
|
20
|
+
|---:|---|
|
|
21
|
+
|static create|Create a result from error|
|
|
22
|
+
|data|Result data|
|
|
23
|
+
|detail|Details|
|
|
24
|
+
|errors|Result errors|
|
|
25
|
+
|field|Related field|
|
|
26
|
+
|ok|Success or failure|
|
|
27
|
+
|status|Status code|
|
|
28
|
+
|title|Title|
|
|
29
|
+
|traceId|Trace id|
|
|
30
|
+
|type|Type|
|
|
31
|
+
|
|
18
32
|
## storage
|
|
19
33
|
Storage interface and browser storage implementation
|
|
20
34
|
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import { IActionResult } from './IActionResult';
|
|
2
|
+
/**
|
|
3
|
+
* Action result
|
|
4
|
+
*/
|
|
5
|
+
export declare class ActionResult {
|
|
6
|
+
/**
|
|
7
|
+
* Create a result from error
|
|
8
|
+
* @returns Action result interface
|
|
9
|
+
*/
|
|
10
|
+
static create<D extends object = {}>(error: Error): IActionResult<D>;
|
|
11
|
+
}
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.ActionResult = void 0;
|
|
4
|
+
/**
|
|
5
|
+
* Action result
|
|
6
|
+
*/
|
|
7
|
+
class ActionResult {
|
|
8
|
+
/**
|
|
9
|
+
* Create a result from error
|
|
10
|
+
* @returns Action result interface
|
|
11
|
+
*/
|
|
12
|
+
static create(error) {
|
|
13
|
+
// If the error has status / statusCode
|
|
14
|
+
const status = 'status' in error
|
|
15
|
+
? error.status
|
|
16
|
+
: 'statusCode' in error
|
|
17
|
+
? error.statusCode
|
|
18
|
+
: undefined;
|
|
19
|
+
// Result
|
|
20
|
+
const result = {
|
|
21
|
+
status: typeof status === 'number' ? status : undefined,
|
|
22
|
+
ok: false,
|
|
23
|
+
type: error.name,
|
|
24
|
+
title: error.message
|
|
25
|
+
};
|
|
26
|
+
// Return
|
|
27
|
+
return result;
|
|
28
|
+
}
|
|
29
|
+
}
|
|
30
|
+
exports.ActionResult = ActionResult;
|
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
import { DataTypes } from './DataTypes';
|
|
2
|
+
/**
|
|
3
|
+
* Result errors
|
|
4
|
+
* Indexable type
|
|
5
|
+
*/
|
|
6
|
+
export interface IResultErrors {
|
|
7
|
+
readonly [key: string]: string[];
|
|
8
|
+
}
|
|
9
|
+
/**
|
|
10
|
+
* Operation result interface
|
|
11
|
+
*/
|
|
12
|
+
export interface IActionResult<D extends object = {}> {
|
|
13
|
+
/**
|
|
14
|
+
* Status code
|
|
15
|
+
*/
|
|
16
|
+
readonly status?: number;
|
|
17
|
+
/**
|
|
18
|
+
* Result data
|
|
19
|
+
*/
|
|
20
|
+
readonly data?: D;
|
|
21
|
+
/**
|
|
22
|
+
* Result errors
|
|
23
|
+
*/
|
|
24
|
+
readonly errors?: IResultErrors;
|
|
25
|
+
/**
|
|
26
|
+
* Title
|
|
27
|
+
*/
|
|
28
|
+
title?: string;
|
|
29
|
+
/**
|
|
30
|
+
* Detail
|
|
31
|
+
*/
|
|
32
|
+
detail?: string;
|
|
33
|
+
/**
|
|
34
|
+
* Trace id
|
|
35
|
+
*/
|
|
36
|
+
traceId?: string;
|
|
37
|
+
/**
|
|
38
|
+
* Type
|
|
39
|
+
*/
|
|
40
|
+
type?: string;
|
|
41
|
+
/**
|
|
42
|
+
* Field name
|
|
43
|
+
*/
|
|
44
|
+
field?: string;
|
|
45
|
+
/**
|
|
46
|
+
* Success or not
|
|
47
|
+
*/
|
|
48
|
+
readonly ok: boolean;
|
|
49
|
+
}
|
|
50
|
+
/**
|
|
51
|
+
* Action result with id data
|
|
52
|
+
*/
|
|
53
|
+
export type IdActionResult<T extends DataTypes.IdType = number> = IActionResult<{
|
|
54
|
+
id: T;
|
|
55
|
+
}>;
|
|
56
|
+
/**
|
|
57
|
+
* Action result with dynamic data
|
|
58
|
+
*/
|
|
59
|
+
export type DynamicActionResult = IActionResult<Record<string, any>>;
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import { IActionResult } from './IActionResult';
|
|
2
|
+
/**
|
|
3
|
+
* Action result
|
|
4
|
+
*/
|
|
5
|
+
export declare class ActionResult {
|
|
6
|
+
/**
|
|
7
|
+
* Create a result from error
|
|
8
|
+
* @returns Action result interface
|
|
9
|
+
*/
|
|
10
|
+
static create<D extends object = {}>(error: Error): IActionResult<D>;
|
|
11
|
+
}
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Action result
|
|
3
|
+
*/
|
|
4
|
+
export class ActionResult {
|
|
5
|
+
/**
|
|
6
|
+
* Create a result from error
|
|
7
|
+
* @returns Action result interface
|
|
8
|
+
*/
|
|
9
|
+
static create(error) {
|
|
10
|
+
// If the error has status / statusCode
|
|
11
|
+
const status = 'status' in error
|
|
12
|
+
? error.status
|
|
13
|
+
: 'statusCode' in error
|
|
14
|
+
? error.statusCode
|
|
15
|
+
: undefined;
|
|
16
|
+
// Result
|
|
17
|
+
const result = {
|
|
18
|
+
status: typeof status === 'number' ? status : undefined,
|
|
19
|
+
ok: false,
|
|
20
|
+
type: error.name,
|
|
21
|
+
title: error.message
|
|
22
|
+
};
|
|
23
|
+
// Return
|
|
24
|
+
return result;
|
|
25
|
+
}
|
|
26
|
+
}
|
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
import { DataTypes } from './DataTypes';
|
|
2
|
+
/**
|
|
3
|
+
* Result errors
|
|
4
|
+
* Indexable type
|
|
5
|
+
*/
|
|
6
|
+
export interface IResultErrors {
|
|
7
|
+
readonly [key: string]: string[];
|
|
8
|
+
}
|
|
9
|
+
/**
|
|
10
|
+
* Operation result interface
|
|
11
|
+
*/
|
|
12
|
+
export interface IActionResult<D extends object = {}> {
|
|
13
|
+
/**
|
|
14
|
+
* Status code
|
|
15
|
+
*/
|
|
16
|
+
readonly status?: number;
|
|
17
|
+
/**
|
|
18
|
+
* Result data
|
|
19
|
+
*/
|
|
20
|
+
readonly data?: D;
|
|
21
|
+
/**
|
|
22
|
+
* Result errors
|
|
23
|
+
*/
|
|
24
|
+
readonly errors?: IResultErrors;
|
|
25
|
+
/**
|
|
26
|
+
* Title
|
|
27
|
+
*/
|
|
28
|
+
title?: string;
|
|
29
|
+
/**
|
|
30
|
+
* Detail
|
|
31
|
+
*/
|
|
32
|
+
detail?: string;
|
|
33
|
+
/**
|
|
34
|
+
* Trace id
|
|
35
|
+
*/
|
|
36
|
+
traceId?: string;
|
|
37
|
+
/**
|
|
38
|
+
* Type
|
|
39
|
+
*/
|
|
40
|
+
type?: string;
|
|
41
|
+
/**
|
|
42
|
+
* Field name
|
|
43
|
+
*/
|
|
44
|
+
field?: string;
|
|
45
|
+
/**
|
|
46
|
+
* Success or not
|
|
47
|
+
*/
|
|
48
|
+
readonly ok: boolean;
|
|
49
|
+
}
|
|
50
|
+
/**
|
|
51
|
+
* Action result with id data
|
|
52
|
+
*/
|
|
53
|
+
export type IdActionResult<T extends DataTypes.IdType = number> = IActionResult<{
|
|
54
|
+
id: T;
|
|
55
|
+
}>;
|
|
56
|
+
/**
|
|
57
|
+
* Action result with dynamic data
|
|
58
|
+
*/
|
|
59
|
+
export type DynamicActionResult = IActionResult<Record<string, any>>;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@etsoo/shared",
|
|
3
|
-
"version": "1.1.
|
|
3
|
+
"version": "1.1.82",
|
|
4
4
|
"description": "TypeScript shared utilities and functions",
|
|
5
5
|
"main": "lib/cjs/index.js",
|
|
6
6
|
"module": "lib/mjs/index.js",
|
|
@@ -54,17 +54,17 @@
|
|
|
54
54
|
},
|
|
55
55
|
"homepage": "https://github.com/ETSOO/Shared#readme",
|
|
56
56
|
"devDependencies": {
|
|
57
|
-
"@types/jest": "^29.2.
|
|
57
|
+
"@types/jest": "^29.2.4",
|
|
58
58
|
"@types/lodash.isequal": "^4.5.6",
|
|
59
|
-
"@typescript-eslint/eslint-plugin": "^5.
|
|
60
|
-
"@typescript-eslint/parser": "^5.
|
|
61
|
-
"eslint": "^8.
|
|
59
|
+
"@typescript-eslint/eslint-plugin": "^5.46.1",
|
|
60
|
+
"@typescript-eslint/parser": "^5.46.1",
|
|
61
|
+
"eslint": "^8.30.0",
|
|
62
62
|
"eslint-config-airbnb-base": "^15.0.0",
|
|
63
63
|
"eslint-plugin-import": "^2.26.0",
|
|
64
64
|
"jest": "^29.3.1",
|
|
65
65
|
"jest-environment-jsdom": "^29.3.1",
|
|
66
66
|
"ts-jest": "^29.0.3",
|
|
67
|
-
"typescript": "^4.9.
|
|
67
|
+
"typescript": "^4.9.4"
|
|
68
68
|
},
|
|
69
69
|
"dependencies": {
|
|
70
70
|
"lodash.isequal": "^4.5.0"
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
import { IActionResult } from './IActionResult';
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* Action result
|
|
5
|
+
*/
|
|
6
|
+
export class ActionResult {
|
|
7
|
+
/**
|
|
8
|
+
* Create a result from error
|
|
9
|
+
* @returns Action result interface
|
|
10
|
+
*/
|
|
11
|
+
static create<D extends object = {}>(error: Error) {
|
|
12
|
+
// If the error has status / statusCode
|
|
13
|
+
const status =
|
|
14
|
+
'status' in error
|
|
15
|
+
? error.status
|
|
16
|
+
: 'statusCode' in error
|
|
17
|
+
? error.statusCode
|
|
18
|
+
: undefined;
|
|
19
|
+
|
|
20
|
+
// Result
|
|
21
|
+
const result: IActionResult<D> = {
|
|
22
|
+
status: typeof status === 'number' ? status : undefined,
|
|
23
|
+
ok: false,
|
|
24
|
+
type: error.name,
|
|
25
|
+
title: error.message
|
|
26
|
+
};
|
|
27
|
+
|
|
28
|
+
// Return
|
|
29
|
+
return result;
|
|
30
|
+
}
|
|
31
|
+
}
|
|
@@ -0,0 +1,72 @@
|
|
|
1
|
+
import { DataTypes } from './DataTypes';
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* Result errors
|
|
5
|
+
* Indexable type
|
|
6
|
+
*/
|
|
7
|
+
export interface IResultErrors {
|
|
8
|
+
readonly [key: string]: string[];
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
/**
|
|
12
|
+
* Operation result interface
|
|
13
|
+
*/
|
|
14
|
+
export interface IActionResult<D extends object = {}> {
|
|
15
|
+
/**
|
|
16
|
+
* Status code
|
|
17
|
+
*/
|
|
18
|
+
readonly status?: number;
|
|
19
|
+
|
|
20
|
+
/**
|
|
21
|
+
* Result data
|
|
22
|
+
*/
|
|
23
|
+
readonly data?: D;
|
|
24
|
+
|
|
25
|
+
/**
|
|
26
|
+
* Result errors
|
|
27
|
+
*/
|
|
28
|
+
readonly errors?: IResultErrors;
|
|
29
|
+
|
|
30
|
+
/**
|
|
31
|
+
* Title
|
|
32
|
+
*/
|
|
33
|
+
title?: string;
|
|
34
|
+
|
|
35
|
+
/**
|
|
36
|
+
* Detail
|
|
37
|
+
*/
|
|
38
|
+
detail?: string;
|
|
39
|
+
|
|
40
|
+
/**
|
|
41
|
+
* Trace id
|
|
42
|
+
*/
|
|
43
|
+
traceId?: string;
|
|
44
|
+
|
|
45
|
+
/**
|
|
46
|
+
* Type
|
|
47
|
+
*/
|
|
48
|
+
type?: string;
|
|
49
|
+
|
|
50
|
+
/**
|
|
51
|
+
* Field name
|
|
52
|
+
*/
|
|
53
|
+
field?: string;
|
|
54
|
+
|
|
55
|
+
/**
|
|
56
|
+
* Success or not
|
|
57
|
+
*/
|
|
58
|
+
readonly ok: boolean;
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
/**
|
|
62
|
+
* Action result with id data
|
|
63
|
+
*/
|
|
64
|
+
export type IdActionResult<T extends DataTypes.IdType = number> =
|
|
65
|
+
IActionResult<{
|
|
66
|
+
id: T;
|
|
67
|
+
}>;
|
|
68
|
+
|
|
69
|
+
/**
|
|
70
|
+
* Action result with dynamic data
|
|
71
|
+
*/
|
|
72
|
+
export type DynamicActionResult = IActionResult<Record<string, any>>;
|