@fjell/client-api 4.4.1 → 4.4.2

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,59 @@
1
+ import {
2
+ ComKey,
3
+ Item,
4
+ PriKey,
5
+ } from "@fjell/core";
6
+ import { GetMethodOptions, 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
+ options: Partial<GetMethodOptions> = {}
46
+ ): Promise<any> => {
47
+ logger.default('facet', { ik, facet });
48
+
49
+ const requestOptions = Object.assign({}, options, { isAuthenticated: apiOptions.writeAuthenticated });
50
+
51
+ return api.httpGet<any>(
52
+ `${utilities.getPath(ik)}/${facet}`,
53
+ requestOptions,
54
+ );
55
+
56
+ };
57
+
58
+ return facet;
59
+ }
@@ -0,0 +1,52 @@
1
+ import {
2
+ Item,
3
+ LocKeyArray,
4
+ QueryParams
5
+ } from "@fjell/core";
6
+ import { GetMethodOptions, 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
+ options: Partial<GetMethodOptions> = {},
33
+ locations: LocKeyArray<L1, L2, L3, L4, L5> | [] = []
34
+ ): Promise<V> => {
35
+ logger.default('findOne', { finder, finderParams, locations });
36
+ utilities.verifyLocations(locations);
37
+ const loc: LocKeyArray<L1, L2, L3, L4, L5> | [] = locations;
38
+
39
+ const params: QueryParams = finderToParams(finder, finderParams);
40
+ params.one = true;
41
+
42
+ const requestOptions = Object.assign({}, options, { isAuthenticated: apiOptions.allAuthenticated, params });
43
+
44
+ return (utilities.validatePK(await utilities.processArray(
45
+ api.httpGet<V[]>(
46
+ utilities.getPath(loc),
47
+ requestOptions,
48
+ ))) as V[])[0];
49
+ }
50
+
51
+ return findOne;
52
+ }
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,78 @@ 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"
15
18
 
16
19
  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
- api: HttpApi,
26
- apiOptions: ClientApiOptions,
27
- utilities: Utilities<V, S, L1, L2, L3, L4, L5>,
28
-
29
- ): ClientApi<V, S, L1, L2, L3, L4, L5> => {
30
- return {
31
- action: getActionOperation<V, S, L1, L2, L3, L4, L5>(
32
- api,
33
- apiOptions,
34
- utilities,
35
- ),
36
- all: getAllOperation<V, S, L1, L2, L3, L4, L5>(
37
- api,
38
- apiOptions,
39
- utilities,
40
- ),
41
- allAction: getAllActionOperation<V, S, L1, L2, L3, L4, L5>(
42
- api,
43
- apiOptions,
44
- utilities,
45
- ),
46
- create: getCreateOperation<V, S, L1, L2, L3, L4, L5>(
47
- api,
48
- apiOptions,
49
- utilities,
50
- ),
51
- find: getFindOperation<V, S, L1, L2, L3, L4, L5>(
52
- api,
53
- apiOptions,
54
- utilities,
55
- ),
56
- get: getGetOperation<V, S, L1, L2, L3, L4, L5>(
57
- api,
58
- apiOptions,
59
- utilities,
60
- ),
61
- one: getOneOperation<V, S, L1, L2, L3, L4, L5>(
62
- api,
63
- apiOptions,
64
- utilities,
65
- ),
66
- remove: getRemoveOperation<V, S, L1, L2, L3, L4, L5>(
67
- api,
68
- apiOptions,
69
- utilities,
70
- ),
71
- update: getUpdateOperation<V, S, L1, L2, L3, L4, L5>(
72
- api,
73
- apiOptions,
74
- utilities,
75
- ),
76
- }
77
- }
20
+ <
21
+ V extends Item<S, L1, L2, L3, L4, L5>,
22
+ S extends string,
23
+ L1 extends string = never,
24
+ L2 extends string = never,
25
+ L3 extends string = never,
26
+ L4 extends string = never,
27
+ L5 extends string = never>(
28
+ api: HttpApi,
29
+ apiOptions: ClientApiOptions,
30
+ utilities: Utilities<V, S, L1, L2, L3, L4, L5>,
31
+
32
+ ): ClientApi<V, S, L1, L2, L3, L4, L5> => {
33
+ return {
34
+ action: getActionOperation<V, S, L1, L2, L3, L4, L5>(
35
+ api,
36
+ apiOptions,
37
+ utilities,
38
+ ),
39
+ all: getAllOperation<V, S, L1, L2, L3, L4, L5>(
40
+ api,
41
+ apiOptions,
42
+ utilities,
43
+ ),
44
+ allAction: getAllActionOperation<V, S, L1, L2, L3, L4, L5>(
45
+ api,
46
+ apiOptions,
47
+ utilities,
48
+ ),
49
+ create: getCreateOperation<V, S, L1, L2, L3, L4, L5>(
50
+ api,
51
+ apiOptions,
52
+ utilities,
53
+ ),
54
+ facet: getFacetOperation<V, S, L1, L2, L3, L4, L5>(
55
+ api,
56
+ apiOptions,
57
+ utilities,
58
+ ),
59
+ findOne: getFindOneOperation<V, S, L1, L2, L3, L4, L5>(
60
+ api,
61
+ apiOptions,
62
+ utilities,
63
+ ),
64
+ find: getFindOperation<V, S, L1, L2, L3, L4, L5>(
65
+ api,
66
+ apiOptions,
67
+ utilities,
68
+ ),
69
+ get: getGetOperation<V, S, L1, L2, L3, L4, L5>(
70
+ api,
71
+ apiOptions,
72
+ utilities,
73
+ ),
74
+ one: getOneOperation<V, S, L1, L2, L3, L4, L5>(
75
+ api,
76
+ apiOptions,
77
+ utilities,
78
+ ),
79
+ remove: getRemoveOperation<V, S, L1, L2, L3, L4, L5>(
80
+ api,
81
+ apiOptions,
82
+ utilities,
83
+ ),
84
+ update: getUpdateOperation<V, S, L1, L2, L3, L4, L5>(
85
+ api,
86
+ apiOptions,
87
+ utilities,
88
+ ),
89
+ }
90
+ }