@fjell/client-api 4.4.4 → 4.4.6

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/src/ops/index.ts DELETED
@@ -1,96 +0,0 @@
1
- /* eslint-disable indent */
2
- import { Item } from "@fjell/core"
3
- import { getAllOperation } from "./all"
4
- import { getActionOperation } from "./action"
5
- import { Utilities } from "@/Utilities"
6
- import { HttpApi } from "@fjell/http-api"
7
- import { getAllActionOperation } from "./allAction"
8
- import { getOneOperation } from "./one"
9
- import { getCreateOperation } from "./create"
10
- import { getUpdateOperation } from "./update"
11
- import { getGetOperation } from "./get"
12
- import { getRemoveOperation } from "./remove"
13
- import { getFindOperation } from "./find"
14
- import { ClientApiOptions } from "@/ClientApiOptions"
15
- import { ClientApi } from "@/ClientApi"
16
- import { getFindOneOperation } from "./findOne"
17
- import { getFacetOperation } from "./facet"
18
- import { getAllFacetOperation } from "./allFacet"
19
-
20
- export const getOperations =
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 DELETED
@@ -1,61 +0,0 @@
1
- import {
2
- Item,
3
- ItemQuery,
4
- LocKeyArray,
5
- QueryParams,
6
- queryToParams
7
- } from "@fjell/core";
8
- import { HttpApi } from "@fjell/http-api";
9
-
10
- import { ClientApiOptions } from "@/ClientApiOptions";
11
- import LibLogger from "@/logger";
12
- import { Utilities } from "@/Utilities";
13
-
14
- const logger = LibLogger.get('client-api', 'ops', 'one');
15
-
16
- export const getOneOperation = <
17
- V extends Item<S, L1, L2, L3, L4, L5>,
18
- S extends string,
19
- L1 extends string = never,
20
- L2 extends string = never,
21
- L3 extends string = never,
22
- L4 extends string = never,
23
- L5 extends string = never>(
24
- api: HttpApi,
25
- apiOptions: ClientApiOptions,
26
- utilities: Utilities<V, S, L1, L2, L3, L4, L5>
27
-
28
- ): (
29
- query: ItemQuery,
30
- locations?: LocKeyArray<L1, L2, L3, L4, L5> | []
31
- ) => Promise<V | null> => {
32
-
33
- const one = async (
34
- query: ItemQuery = {} as ItemQuery,
35
- locations: LocKeyArray<L1, L2, L3, L4, L5> | [] = []
36
- ): Promise<V | null> => {
37
- utilities.verifyLocations(locations);
38
-
39
- const loc: LocKeyArray<L1, L2, L3, L4, L5> | [] = locations;
40
-
41
- const params: QueryParams = queryToParams(query);
42
- const requestOptions = Object.assign({}, apiOptions.getOptions, { isAuthenticated: apiOptions.readAuthenticated, params });
43
- logger.default('one', { query, locations, requestOptions });
44
-
45
- let item: V | null = null;
46
-
47
- const items = utilities.validatePK(await utilities.processArray(
48
- api.httpGet<V[]>(
49
- utilities.getPath(loc),
50
- requestOptions,
51
- ))) as V[];
52
-
53
- if (items.length > 0) {
54
- item = items[0];
55
- }
56
-
57
- return item as V;
58
- }
59
-
60
- return one;
61
- }
package/src/ops/remove.ts DELETED
@@ -1,38 +0,0 @@
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', 'remove');
13
-
14
- export const getRemoveOperation = <
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
- const remove = async (
29
- ik: PriKey<S> | ComKey<S, L1, L2, L3, L4, L5>,
30
- ): Promise<boolean> => {
31
- const requestOptions = Object.assign({}, apiOptions.deleteOptions, { isAuthenticated: apiOptions.writeAuthenticated });
32
- logger.default('remove', { ik, requestOptions });
33
-
34
- return api.httpDelete<boolean>(utilities.getPath(ik), requestOptions);
35
- }
36
-
37
- return remove;
38
- }
package/src/ops/update.ts DELETED
@@ -1,44 +0,0 @@
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', 'update');
13
-
14
- export const getUpdateOperation = <
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
- const update = async (
29
- ik: PriKey<S> | ComKey<S, L1, L2, L3, L4, L5>,
30
- item: Partial<Item<S, L1, L2, L3, L4, L5>>,
31
- ): Promise<V> => {
32
- const requestOptions = Object.assign({}, apiOptions.putOptions, { isAuthenticated: apiOptions.writeAuthenticated });
33
- logger.default('update', { ik, item, requestOptions });
34
-
35
- return utilities.validatePK(await utilities.processOne(
36
- api.httpPut<V>(
37
- utilities.getPath(ik),
38
- item,
39
- requestOptions,
40
- ))) as V;
41
- }
42
-
43
- return update;
44
- }
@@ -1,65 +0,0 @@
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
- };