@fjell/client-api 4.4.1 → 4.4.3
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/AItemAPI.js +8 -1
- package/dist/AItemAPI.js.map +1 -1
- package/dist/CItemAPI.d.ts +12 -9
- package/dist/CItemAPI.js +4 -1
- package/dist/CItemAPI.js.map +1 -1
- package/dist/ClientApi.d.ts +12 -10
- package/dist/ClientApiOptions.d.ts +5 -0
- package/dist/PItemAPI.d.ts +13 -10
- package/dist/PItemAPI.js +16 -10
- package/dist/PItemAPI.js.map +1 -1
- package/dist/index.cjs +173 -73
- package/dist/index.cjs.map +1 -1
- package/dist/ops/action.d.ts +2 -2
- package/dist/ops/action.js +6 -5
- package/dist/ops/action.js.map +1 -1
- package/dist/ops/all.d.ts +2 -2
- package/dist/ops/all.js +7 -6
- package/dist/ops/all.js.map +1 -1
- package/dist/ops/allAction.d.ts +2 -2
- package/dist/ops/allAction.js +6 -5
- package/dist/ops/allAction.js.map +1 -1
- package/dist/ops/allFacet.d.ts +5 -0
- package/dist/ops/allFacet.js +24 -0
- package/dist/ops/allFacet.js.map +1 -0
- package/dist/ops/create.d.ts +2 -2
- package/dist/ops/create.js +6 -5
- package/dist/ops/create.js.map +1 -1
- package/dist/ops/facet.d.ts +5 -0
- package/dist/ops/facet.js +34 -0
- package/dist/ops/facet.js.map +1 -0
- package/dist/ops/find.d.ts +2 -2
- package/dist/ops/find.js +10 -9
- package/dist/ops/find.js.map +1 -1
- package/dist/ops/findOne.d.ts +5 -0
- package/dist/ops/findOne.js +27 -0
- package/dist/ops/findOne.js.map +1 -0
- package/dist/ops/get.d.ts +2 -2
- package/dist/ops/get.js +6 -5
- package/dist/ops/get.js.map +1 -1
- package/dist/ops/index.js +6 -0
- package/dist/ops/index.js.map +1 -1
- package/dist/ops/one.d.ts +2 -2
- package/dist/ops/one.js +7 -6
- package/dist/ops/one.js.map +1 -1
- package/dist/ops/remove.d.ts +2 -2
- package/dist/ops/remove.js +6 -5
- package/dist/ops/remove.js.map +1 -1
- package/dist/ops/update.d.ts +2 -2
- package/dist/ops/update.js +6 -5
- package/dist/ops/update.js.map +1 -1
- package/dist/util/general.d.ts +4 -0
- package/package.json +6 -6
- package/src/AItemAPI.ts +17 -9
- package/src/CItemAPI.ts +22 -16
- package/src/ClientApi.ts +59 -54
- package/src/ClientApiOptions.ts +5 -0
- package/src/PItemAPI.ts +56 -42
- package/src/ops/action.ts +19 -23
- package/src/ops/all.ts +17 -19
- package/src/ops/allAction.ts +18 -21
- package/src/ops/allFacet.ts +46 -0
- package/src/ops/create.ts +21 -23
- package/src/ops/facet.ts +58 -0
- package/src/ops/find.ts +20 -23
- package/src/ops/findOne.ts +51 -0
- package/src/ops/get.ts +17 -20
- package/src/ops/index.ts +80 -61
- package/src/ops/one.ts +3 -5
- package/src/ops/remove.ts +17 -20
- package/src/ops/update.ts +17 -19
- package/src/util/general.ts +65 -0
package/src/ops/facet.ts
ADDED
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
import {
|
|
2
|
+
ComKey,
|
|
3
|
+
Item,
|
|
4
|
+
PriKey,
|
|
5
|
+
} from "@fjell/core";
|
|
6
|
+
import { HttpApi } from "@fjell/http-api";
|
|
7
|
+
|
|
8
|
+
import { ClientApiOptions } from "@/ClientApiOptions";
|
|
9
|
+
import LibLogger from "@/logger";
|
|
10
|
+
import { Utilities } from "@/Utilities";
|
|
11
|
+
|
|
12
|
+
const logger = LibLogger.get('client-api', 'ops', 'facet');
|
|
13
|
+
|
|
14
|
+
export const getFacetOperation = <
|
|
15
|
+
V extends Item<S, L1, L2, L3, L4, L5>,
|
|
16
|
+
S extends string,
|
|
17
|
+
L1 extends string = never,
|
|
18
|
+
L2 extends string = never,
|
|
19
|
+
L3 extends string = never,
|
|
20
|
+
L4 extends string = never,
|
|
21
|
+
L5 extends string = never>(
|
|
22
|
+
api: HttpApi,
|
|
23
|
+
apiOptions: ClientApiOptions,
|
|
24
|
+
utilities: Utilities<V, S, L1, L2, L3, L4, L5>
|
|
25
|
+
|
|
26
|
+
) => {
|
|
27
|
+
|
|
28
|
+
/**
|
|
29
|
+
* Executes a facet operation on an item.
|
|
30
|
+
*
|
|
31
|
+
* A facet is a piece of information that is related to an item - it represents
|
|
32
|
+
* a specific aspect or characteristic of the item. Unlike actions which may
|
|
33
|
+
* return items or perform operations, facets are informational queries that
|
|
34
|
+
* return data about a particular facet of an item.
|
|
35
|
+
*
|
|
36
|
+
* @param ik - The item key (composite or primary key) identifying the item
|
|
37
|
+
* @param facet - The name of the facet to query
|
|
38
|
+
* @param body - Optional request body for the facet operation
|
|
39
|
+
* @param options - Optional HTTP request options
|
|
40
|
+
* @returns Promise resolving to the facet data
|
|
41
|
+
*/
|
|
42
|
+
const facet = async (
|
|
43
|
+
ik: ComKey<S, L1, L2, L3, L4, L5> | PriKey<S>,
|
|
44
|
+
facet: string,
|
|
45
|
+
params: Record<string, string | number | boolean | Date | Array<string | number | boolean | Date>> = {},
|
|
46
|
+
): Promise<any> => {
|
|
47
|
+
const requestOptions = Object.assign({}, apiOptions.getOptions, { isAuthenticated: apiOptions.writeAuthenticated, params });
|
|
48
|
+
logger.default('facet', { ik, facet, requestOptions });
|
|
49
|
+
|
|
50
|
+
return api.httpGet<any>(
|
|
51
|
+
`${utilities.getPath(ik)}/${facet}`,
|
|
52
|
+
requestOptions,
|
|
53
|
+
);
|
|
54
|
+
|
|
55
|
+
};
|
|
56
|
+
|
|
57
|
+
return facet;
|
|
58
|
+
}
|
package/src/ops/find.ts
CHANGED
|
@@ -3,50 +3,47 @@ import {
|
|
|
3
3
|
LocKeyArray,
|
|
4
4
|
QueryParams
|
|
5
5
|
} from "@fjell/core";
|
|
6
|
-
import {
|
|
7
|
-
|
|
6
|
+
import { HttpApi } from "@fjell/http-api";
|
|
7
|
+
|
|
8
8
|
import { finderToParams } from "@/AItemAPI";
|
|
9
9
|
import { ClientApiOptions } from "@/ClientApiOptions";
|
|
10
10
|
import LibLogger from "@/logger";
|
|
11
11
|
import { Utilities } from "@/Utilities";
|
|
12
|
-
|
|
12
|
+
|
|
13
13
|
const logger = LibLogger.get('client-api', 'ops', 'find');
|
|
14
|
-
|
|
14
|
+
|
|
15
15
|
export const getFindOperation = <
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
16
|
+
V extends Item<S, L1, L2, L3, L4, L5>,
|
|
17
|
+
S extends string,
|
|
18
|
+
L1 extends string = never,
|
|
19
|
+
L2 extends string = never,
|
|
20
|
+
L3 extends string = never,
|
|
21
|
+
L4 extends string = never,
|
|
22
|
+
L5 extends string = never>(
|
|
23
23
|
api: HttpApi,
|
|
24
24
|
apiOptions: ClientApiOptions,
|
|
25
25
|
utilities: Utilities<V, S, L1, L2, L3, L4, L5>
|
|
26
|
-
|
|
26
|
+
|
|
27
27
|
) => {
|
|
28
|
-
|
|
28
|
+
|
|
29
29
|
const find = async (
|
|
30
30
|
finder: string,
|
|
31
|
-
finderParams: Record<string, string | number | boolean | Date | Array<string | number | boolean | Date
|
|
32
|
-
options: Partial<GetMethodOptions> = {},
|
|
31
|
+
finderParams: Record<string, string | number | boolean | Date | Array<string | number | boolean | Date>> = {},
|
|
33
32
|
locations: LocKeyArray<L1, L2, L3, L4, L5> | [] = []
|
|
34
33
|
): Promise<V[]> => {
|
|
35
|
-
logger.default('find', { finder, finderParams, locations });
|
|
36
34
|
utilities.verifyLocations(locations);
|
|
37
35
|
const loc: LocKeyArray<L1, L2, L3, L4, L5> | [] = locations;
|
|
38
|
-
|
|
39
|
-
const
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
36
|
+
|
|
37
|
+
const mergedParams: QueryParams = finderToParams(finder, finderParams);
|
|
38
|
+
const requestOptions = Object.assign({}, apiOptions.getOptions, { isAuthenticated: apiOptions.allAuthenticated, params: mergedParams });
|
|
39
|
+
logger.default('find', { finder, finderParams, locations, requestOptions });
|
|
40
|
+
|
|
43
41
|
return utilities.validatePK(await utilities.processArray(
|
|
44
42
|
api.httpGet<V[]>(
|
|
45
43
|
utilities.getPath(loc),
|
|
46
44
|
requestOptions,
|
|
47
45
|
))) as V[];
|
|
48
46
|
}
|
|
49
|
-
|
|
47
|
+
|
|
50
48
|
return find;
|
|
51
49
|
}
|
|
52
|
-
|
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
import {
|
|
2
|
+
Item,
|
|
3
|
+
LocKeyArray,
|
|
4
|
+
QueryParams
|
|
5
|
+
} from "@fjell/core";
|
|
6
|
+
import { HttpApi } from "@fjell/http-api";
|
|
7
|
+
|
|
8
|
+
import { finderToParams } from "@/AItemAPI";
|
|
9
|
+
import { ClientApiOptions } from "@/ClientApiOptions";
|
|
10
|
+
import LibLogger from "@/logger";
|
|
11
|
+
import { Utilities } from "@/Utilities";
|
|
12
|
+
|
|
13
|
+
const logger = LibLogger.get('client-api', 'ops', 'find');
|
|
14
|
+
|
|
15
|
+
export const getFindOneOperation = <
|
|
16
|
+
V extends Item<S, L1, L2, L3, L4, L5>,
|
|
17
|
+
S extends string,
|
|
18
|
+
L1 extends string = never,
|
|
19
|
+
L2 extends string = never,
|
|
20
|
+
L3 extends string = never,
|
|
21
|
+
L4 extends string = never,
|
|
22
|
+
L5 extends string = never>(
|
|
23
|
+
api: HttpApi,
|
|
24
|
+
apiOptions: ClientApiOptions,
|
|
25
|
+
utilities: Utilities<V, S, L1, L2, L3, L4, L5>
|
|
26
|
+
|
|
27
|
+
) => {
|
|
28
|
+
|
|
29
|
+
const findOne = async (
|
|
30
|
+
finder: string,
|
|
31
|
+
finderParams: Record<string, string | number | boolean | Date | Array<string | number | boolean | Date>> = {},
|
|
32
|
+
locations: LocKeyArray<L1, L2, L3, L4, L5> | [] = []
|
|
33
|
+
): Promise<V> => {
|
|
34
|
+
utilities.verifyLocations(locations);
|
|
35
|
+
const loc: LocKeyArray<L1, L2, L3, L4, L5> | [] = locations;
|
|
36
|
+
|
|
37
|
+
const params: QueryParams = finderToParams(finder, finderParams);
|
|
38
|
+
params.one = true;
|
|
39
|
+
|
|
40
|
+
const requestOptions = Object.assign({}, apiOptions.getOptions, { isAuthenticated: apiOptions.allAuthenticated, params });
|
|
41
|
+
logger.default('findOne', { finder, finderParams, locations, requestOptions });
|
|
42
|
+
|
|
43
|
+
return (utilities.validatePK(await utilities.processArray(
|
|
44
|
+
api.httpGet<V[]>(
|
|
45
|
+
utilities.getPath(loc),
|
|
46
|
+
requestOptions,
|
|
47
|
+
))) as V[])[0];
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
return findOne;
|
|
51
|
+
}
|
package/src/ops/get.ts
CHANGED
|
@@ -3,43 +3,40 @@ import {
|
|
|
3
3
|
Item,
|
|
4
4
|
PriKey,
|
|
5
5
|
} from "@fjell/core";
|
|
6
|
-
import {
|
|
7
|
-
|
|
6
|
+
import { HttpApi } from "@fjell/http-api";
|
|
7
|
+
|
|
8
8
|
import { ClientApiOptions } from "@/ClientApiOptions";
|
|
9
9
|
import LibLogger from "@/logger";
|
|
10
10
|
import { Utilities } from "@/Utilities";
|
|
11
|
-
|
|
11
|
+
|
|
12
12
|
const logger = LibLogger.get('client-api', 'ops', 'get');
|
|
13
|
-
|
|
13
|
+
|
|
14
14
|
export const getGetOperation = <
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
15
|
+
V extends Item<S, L1, L2, L3, L4, L5>,
|
|
16
|
+
S extends string,
|
|
17
|
+
L1 extends string = never,
|
|
18
|
+
L2 extends string = never,
|
|
19
|
+
L3 extends string = never,
|
|
20
|
+
L4 extends string = never,
|
|
21
|
+
L5 extends string = never>(
|
|
22
22
|
api: HttpApi,
|
|
23
23
|
apiOptions: ClientApiOptions,
|
|
24
24
|
utilities: Utilities<V, S, L1, L2, L3, L4, L5>
|
|
25
|
-
|
|
25
|
+
|
|
26
26
|
) => {
|
|
27
|
-
|
|
27
|
+
|
|
28
28
|
const get = async (
|
|
29
29
|
ik: PriKey<S> | ComKey<S, never, never, never, never, never>,
|
|
30
|
-
options: Partial<GetMethodOptions> = {},
|
|
31
30
|
): Promise<V | null> => {
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
31
|
+
const requestOptions = Object.assign({}, apiOptions.getOptions, { isAuthenticated: apiOptions.readAuthenticated });
|
|
32
|
+
logger.default('get', { ik, requestOptions });
|
|
33
|
+
|
|
36
34
|
return utilities.validatePK(await utilities.processOne(
|
|
37
35
|
api.httpGet<V>(
|
|
38
36
|
utilities.getPath(ik),
|
|
39
37
|
requestOptions,
|
|
40
38
|
))) as V;
|
|
41
39
|
}
|
|
42
|
-
|
|
40
|
+
|
|
43
41
|
return get;
|
|
44
42
|
}
|
|
45
|
-
|
package/src/ops/index.ts
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
/* eslint-disable indent */
|
|
1
2
|
import { Item } from "@fjell/core"
|
|
2
3
|
import { getAllOperation } from "./all"
|
|
3
4
|
import { getActionOperation } from "./action"
|
|
@@ -12,66 +13,84 @@ import { getRemoveOperation } from "./remove"
|
|
|
12
13
|
import { getFindOperation } from "./find"
|
|
13
14
|
import { ClientApiOptions } from "@/ClientApiOptions"
|
|
14
15
|
import { ClientApi } from "@/ClientApi"
|
|
16
|
+
import { getFindOneOperation } from "./findOne"
|
|
17
|
+
import { getFacetOperation } from "./facet"
|
|
18
|
+
import { getAllFacetOperation } from "./allFacet"
|
|
15
19
|
|
|
16
20
|
export const getOperations =
|
|
17
|
-
<
|
|
18
|
-
V extends Item<S, L1, L2, L3, L4, L5>,
|
|
19
|
-
S extends string,
|
|
20
|
-
L1 extends string = never,
|
|
21
|
-
L2 extends string = never,
|
|
22
|
-
L3 extends string = never,
|
|
23
|
-
L4 extends string = never,
|
|
24
|
-
L5 extends string = never>(
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
21
|
+
<
|
|
22
|
+
V extends Item<S, L1, L2, L3, L4, L5>,
|
|
23
|
+
S extends string,
|
|
24
|
+
L1 extends string = never,
|
|
25
|
+
L2 extends string = never,
|
|
26
|
+
L3 extends string = never,
|
|
27
|
+
L4 extends string = never,
|
|
28
|
+
L5 extends string = never>(
|
|
29
|
+
api: HttpApi,
|
|
30
|
+
apiOptions: ClientApiOptions,
|
|
31
|
+
utilities: Utilities<V, S, L1, L2, L3, L4, L5>,
|
|
32
|
+
|
|
33
|
+
): ClientApi<V, S, L1, L2, L3, L4, L5> => {
|
|
34
|
+
return {
|
|
35
|
+
action: getActionOperation<V, S, L1, L2, L3, L4, L5>(
|
|
36
|
+
api,
|
|
37
|
+
apiOptions,
|
|
38
|
+
utilities,
|
|
39
|
+
),
|
|
40
|
+
all: getAllOperation<V, S, L1, L2, L3, L4, L5>(
|
|
41
|
+
api,
|
|
42
|
+
apiOptions,
|
|
43
|
+
utilities,
|
|
44
|
+
),
|
|
45
|
+
allAction: getAllActionOperation<V, S, L1, L2, L3, L4, L5>(
|
|
46
|
+
api,
|
|
47
|
+
apiOptions,
|
|
48
|
+
utilities,
|
|
49
|
+
),
|
|
50
|
+
allFacet: getAllFacetOperation<V, S, L1, L2, L3, L4, L5>(
|
|
51
|
+
api,
|
|
52
|
+
apiOptions,
|
|
53
|
+
utilities,
|
|
54
|
+
),
|
|
55
|
+
create: getCreateOperation<V, S, L1, L2, L3, L4, L5>(
|
|
56
|
+
api,
|
|
57
|
+
apiOptions,
|
|
58
|
+
utilities,
|
|
59
|
+
),
|
|
60
|
+
facet: getFacetOperation<V, S, L1, L2, L3, L4, L5>(
|
|
61
|
+
api,
|
|
62
|
+
apiOptions,
|
|
63
|
+
utilities,
|
|
64
|
+
),
|
|
65
|
+
findOne: getFindOneOperation<V, S, L1, L2, L3, L4, L5>(
|
|
66
|
+
api,
|
|
67
|
+
apiOptions,
|
|
68
|
+
utilities,
|
|
69
|
+
),
|
|
70
|
+
find: getFindOperation<V, S, L1, L2, L3, L4, L5>(
|
|
71
|
+
api,
|
|
72
|
+
apiOptions,
|
|
73
|
+
utilities,
|
|
74
|
+
),
|
|
75
|
+
get: getGetOperation<V, S, L1, L2, L3, L4, L5>(
|
|
76
|
+
api,
|
|
77
|
+
apiOptions,
|
|
78
|
+
utilities,
|
|
79
|
+
),
|
|
80
|
+
one: getOneOperation<V, S, L1, L2, L3, L4, L5>(
|
|
81
|
+
api,
|
|
82
|
+
apiOptions,
|
|
83
|
+
utilities,
|
|
84
|
+
),
|
|
85
|
+
remove: getRemoveOperation<V, S, L1, L2, L3, L4, L5>(
|
|
86
|
+
api,
|
|
87
|
+
apiOptions,
|
|
88
|
+
utilities,
|
|
89
|
+
),
|
|
90
|
+
update: getUpdateOperation<V, S, L1, L2, L3, L4, L5>(
|
|
91
|
+
api,
|
|
92
|
+
apiOptions,
|
|
93
|
+
utilities,
|
|
94
|
+
),
|
|
95
|
+
}
|
|
96
|
+
}
|
package/src/ops/one.ts
CHANGED
|
@@ -5,7 +5,7 @@ import {
|
|
|
5
5
|
QueryParams,
|
|
6
6
|
queryToParams
|
|
7
7
|
} from "@fjell/core";
|
|
8
|
-
import {
|
|
8
|
+
import { HttpApi } from "@fjell/http-api";
|
|
9
9
|
|
|
10
10
|
import { ClientApiOptions } from "@/ClientApiOptions";
|
|
11
11
|
import LibLogger from "@/logger";
|
|
@@ -27,22 +27,20 @@ export const getOneOperation = <
|
|
|
27
27
|
|
|
28
28
|
): (
|
|
29
29
|
query: ItemQuery,
|
|
30
|
-
options?: Partial<GetMethodOptions>,
|
|
31
30
|
locations?: LocKeyArray<L1, L2, L3, L4, L5> | []
|
|
32
31
|
) => Promise<V | null> => {
|
|
33
32
|
|
|
34
33
|
const one = async (
|
|
35
34
|
query: ItemQuery = {} as ItemQuery,
|
|
36
|
-
options: Partial<GetMethodOptions> = {},
|
|
37
35
|
locations: LocKeyArray<L1, L2, L3, L4, L5> | [] = []
|
|
38
36
|
): Promise<V | null> => {
|
|
39
|
-
logger.default('one', { query, locations });
|
|
40
37
|
utilities.verifyLocations(locations);
|
|
41
38
|
|
|
42
39
|
const loc: LocKeyArray<L1, L2, L3, L4, L5> | [] = locations;
|
|
43
40
|
|
|
44
41
|
const params: QueryParams = queryToParams(query);
|
|
45
|
-
const requestOptions = Object.assign({},
|
|
42
|
+
const requestOptions = Object.assign({}, apiOptions.getOptions, { isAuthenticated: apiOptions.readAuthenticated, params });
|
|
43
|
+
logger.default('one', { query, locations, requestOptions });
|
|
46
44
|
|
|
47
45
|
let item: V | null = null;
|
|
48
46
|
|
package/src/ops/remove.ts
CHANGED
|
@@ -3,39 +3,36 @@ import {
|
|
|
3
3
|
Item,
|
|
4
4
|
PriKey,
|
|
5
5
|
} from "@fjell/core";
|
|
6
|
-
import {
|
|
7
|
-
|
|
6
|
+
import { HttpApi } from "@fjell/http-api";
|
|
7
|
+
|
|
8
8
|
import { ClientApiOptions } from "@/ClientApiOptions";
|
|
9
9
|
import LibLogger from "@/logger";
|
|
10
10
|
import { Utilities } from "@/Utilities";
|
|
11
|
-
|
|
11
|
+
|
|
12
12
|
const logger = LibLogger.get('client-api', 'ops', 'remove');
|
|
13
|
-
|
|
13
|
+
|
|
14
14
|
export const getRemoveOperation = <
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
15
|
+
V extends Item<S, L1, L2, L3, L4, L5>,
|
|
16
|
+
S extends string,
|
|
17
|
+
L1 extends string = never,
|
|
18
|
+
L2 extends string = never,
|
|
19
|
+
L3 extends string = never,
|
|
20
|
+
L4 extends string = never,
|
|
21
|
+
L5 extends string = never>(
|
|
22
22
|
api: HttpApi,
|
|
23
23
|
apiOptions: ClientApiOptions,
|
|
24
24
|
utilities: Utilities<V, S, L1, L2, L3, L4, L5>
|
|
25
|
-
|
|
25
|
+
|
|
26
26
|
) => {
|
|
27
|
-
|
|
27
|
+
|
|
28
28
|
const remove = async (
|
|
29
29
|
ik: PriKey<S> | ComKey<S, L1, L2, L3, L4, L5>,
|
|
30
|
-
options: Partial<DeleteMethodOptions> = {},
|
|
31
30
|
): Promise<boolean> => {
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
31
|
+
const requestOptions = Object.assign({}, apiOptions.deleteOptions, { isAuthenticated: apiOptions.writeAuthenticated });
|
|
32
|
+
logger.default('remove', { ik, requestOptions });
|
|
33
|
+
|
|
36
34
|
return api.httpDelete<boolean>(utilities.getPath(ik), requestOptions);
|
|
37
35
|
}
|
|
38
|
-
|
|
36
|
+
|
|
39
37
|
return remove;
|
|
40
38
|
}
|
|
41
|
-
|
package/src/ops/update.ts
CHANGED
|
@@ -4,36 +4,35 @@ import {
|
|
|
4
4
|
ItemProperties,
|
|
5
5
|
PriKey
|
|
6
6
|
} from "@fjell/core";
|
|
7
|
-
import { HttpApi
|
|
8
|
-
|
|
7
|
+
import { HttpApi } from "@fjell/http-api";
|
|
8
|
+
|
|
9
9
|
import { ClientApiOptions } from "@/ClientApiOptions";
|
|
10
10
|
import LibLogger from "@/logger";
|
|
11
11
|
import { Utilities } from "@/Utilities";
|
|
12
|
-
|
|
12
|
+
|
|
13
13
|
const logger = LibLogger.get('client-api', 'ops', 'update');
|
|
14
|
-
|
|
14
|
+
|
|
15
15
|
export const getUpdateOperation = <
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
16
|
+
V extends Item<S, L1, L2, L3, L4, L5>,
|
|
17
|
+
S extends string,
|
|
18
|
+
L1 extends string = never,
|
|
19
|
+
L2 extends string = never,
|
|
20
|
+
L3 extends string = never,
|
|
21
|
+
L4 extends string = never,
|
|
22
|
+
L5 extends string = never>(
|
|
23
23
|
api: HttpApi,
|
|
24
24
|
apiOptions: ClientApiOptions,
|
|
25
25
|
utilities: Utilities<V, S, L1, L2, L3, L4, L5>
|
|
26
|
-
|
|
26
|
+
|
|
27
27
|
) => {
|
|
28
|
-
|
|
28
|
+
|
|
29
29
|
const update = async (
|
|
30
30
|
ik: PriKey<S> | ComKey<S, L1, L2, L3, L4, L5>,
|
|
31
31
|
item: ItemProperties<S, L1, L2, L3, L4, L5>,
|
|
32
|
-
options: Partial<PutMethodOptions> = {},
|
|
33
32
|
): Promise<V> => {
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
33
|
+
const requestOptions = Object.assign({}, apiOptions.putOptions, { isAuthenticated: apiOptions.writeAuthenticated });
|
|
34
|
+
logger.default('update', { ik, item, requestOptions });
|
|
35
|
+
|
|
37
36
|
return utilities.validatePK(await utilities.processOne(
|
|
38
37
|
api.httpPut<V>(
|
|
39
38
|
utilities.getPath(ik),
|
|
@@ -41,7 +40,6 @@ export const getUpdateOperation = <
|
|
|
41
40
|
requestOptions,
|
|
42
41
|
))) as V;
|
|
43
42
|
}
|
|
44
|
-
|
|
43
|
+
|
|
45
44
|
return update;
|
|
46
45
|
}
|
|
47
|
-
|
|
@@ -0,0 +1,65 @@
|
|
|
1
|
+
/* eslint-disable @typescript-eslint/no-unused-vars */
|
|
2
|
+
/* eslint-disable no-undefined */
|
|
3
|
+
export const clean = (obj: any) => {
|
|
4
|
+
return Object.fromEntries(
|
|
5
|
+
Object.entries(obj).filter(([_, v]) => v !== undefined)
|
|
6
|
+
);
|
|
7
|
+
}
|
|
8
|
+
|
|
9
|
+
//Recursive implementation of jSON.stringify;
|
|
10
|
+
export const stringifyJSON = function (obj: any, visited: Set<any> = new Set()): string {
|
|
11
|
+
const arrOfKeyVals: string[] = [];
|
|
12
|
+
const arrVals: string[] = [];
|
|
13
|
+
let objKeys: string[] = [];
|
|
14
|
+
|
|
15
|
+
/*********CHECK FOR PRIMITIVE TYPES**********/
|
|
16
|
+
if (typeof obj === 'number' || typeof obj === 'boolean' || obj === null)
|
|
17
|
+
return '' + obj;
|
|
18
|
+
else if (typeof obj === 'string')
|
|
19
|
+
return '"' + obj + '"';
|
|
20
|
+
|
|
21
|
+
/*********DETECT CIRCULAR REFERENCES**********/
|
|
22
|
+
if (obj instanceof Object && visited.has(obj)) {
|
|
23
|
+
return '"(circular)"';
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
/*********CHECK FOR ARRAY**********/
|
|
27
|
+
else if (Array.isArray(obj)) {
|
|
28
|
+
//check for empty array
|
|
29
|
+
if (obj[0] === undefined)
|
|
30
|
+
return '[]';
|
|
31
|
+
else {
|
|
32
|
+
// Add array to visited before processing its elements
|
|
33
|
+
visited.add(obj);
|
|
34
|
+
obj.forEach(function (el) {
|
|
35
|
+
arrVals.push(stringifyJSON(el, visited));
|
|
36
|
+
});
|
|
37
|
+
return '[' + arrVals + ']';
|
|
38
|
+
}
|
|
39
|
+
}
|
|
40
|
+
/*********CHECK FOR OBJECT**********/
|
|
41
|
+
else if (obj instanceof Object) {
|
|
42
|
+
// Add object to visited before processing its properties
|
|
43
|
+
visited.add(obj);
|
|
44
|
+
//get object keys
|
|
45
|
+
objKeys = Object.keys(obj);
|
|
46
|
+
//set key output;
|
|
47
|
+
objKeys.forEach(function (key) {
|
|
48
|
+
const keyOut = '"' + key + '":';
|
|
49
|
+
const keyValOut = obj[key];
|
|
50
|
+
//skip functions and undefined properties
|
|
51
|
+
if (keyValOut instanceof Function || keyValOut === undefined)
|
|
52
|
+
return; // Skip this entry entirely instead of pushing an empty string
|
|
53
|
+
else if (typeof keyValOut === 'string')
|
|
54
|
+
arrOfKeyVals.push(keyOut + '"' + keyValOut + '"');
|
|
55
|
+
else if (typeof keyValOut === 'boolean' || typeof keyValOut === 'number' || keyValOut === null)
|
|
56
|
+
arrOfKeyVals.push(keyOut + keyValOut);
|
|
57
|
+
//check for nested objects, call recursively until no more objects
|
|
58
|
+
else if (keyValOut instanceof Object) {
|
|
59
|
+
arrOfKeyVals.push(keyOut + stringifyJSON(keyValOut, visited));
|
|
60
|
+
}
|
|
61
|
+
});
|
|
62
|
+
return '{' + arrOfKeyVals + '}';
|
|
63
|
+
}
|
|
64
|
+
return '';
|
|
65
|
+
};
|