@fjell/client-api 4.2.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.
Files changed (76) hide show
  1. package/LICENSE +202 -0
  2. package/dist/src/AItemAPI.d.ts +34 -0
  3. package/dist/src/AItemAPI.js +39 -0
  4. package/dist/src/AItemAPI.js.map +1 -0
  5. package/dist/src/CItemAPI.d.ts +16 -0
  6. package/dist/src/CItemAPI.js +20 -0
  7. package/dist/src/CItemAPI.js.map +1 -0
  8. package/dist/src/ClientApi.d.ts +13 -0
  9. package/dist/src/ClientApi.js +2 -0
  10. package/dist/src/ClientApi.js.map +1 -0
  11. package/dist/src/ClientApiOptions.d.ts +8 -0
  12. package/dist/src/ClientApiOptions.js +2 -0
  13. package/dist/src/ClientApiOptions.js.map +1 -0
  14. package/dist/src/PItemAPI.d.ts +17 -0
  15. package/dist/src/PItemAPI.js +30 -0
  16. package/dist/src/PItemAPI.js.map +1 -0
  17. package/dist/src/Utilities.d.ts +10 -0
  18. package/dist/src/Utilities.js +110 -0
  19. package/dist/src/Utilities.js.map +1 -0
  20. package/dist/src/index.d.ts +4 -0
  21. package/dist/src/index.js +3 -0
  22. package/dist/src/index.js.map +1 -0
  23. package/dist/src/logger.d.ts +2 -0
  24. package/dist/src/logger.js +4 -0
  25. package/dist/src/logger.js.map +1 -0
  26. package/dist/src/ops/action.d.ts +5 -0
  27. package/dist/src/ops/action.js +11 -0
  28. package/dist/src/ops/action.js.map +1 -0
  29. package/dist/src/ops/all.d.ts +6 -0
  30. package/dist/src/ops/all.js +15 -0
  31. package/dist/src/ops/all.js.map +1 -0
  32. package/dist/src/ops/allAction.d.ts +5 -0
  33. package/dist/src/ops/allAction.js +14 -0
  34. package/dist/src/ops/allAction.js.map +1 -0
  35. package/dist/src/ops/create.d.ts +5 -0
  36. package/dist/src/ops/create.js +14 -0
  37. package/dist/src/ops/create.js.map +1 -0
  38. package/dist/src/ops/find.d.ts +5 -0
  39. package/dist/src/ops/find.js +15 -0
  40. package/dist/src/ops/find.js.map +1 -0
  41. package/dist/src/ops/get.d.ts +5 -0
  42. package/dist/src/ops/get.js +11 -0
  43. package/dist/src/ops/get.js.map +1 -0
  44. package/dist/src/ops/index.d.ts +6 -0
  45. package/dist/src/ops/index.js +23 -0
  46. package/dist/src/ops/index.js.map +1 -0
  47. package/dist/src/ops/one.d.ts +5 -0
  48. package/dist/src/ops/one.js +20 -0
  49. package/dist/src/ops/one.js.map +1 -0
  50. package/dist/src/ops/remove.d.ts +5 -0
  51. package/dist/src/ops/remove.js +11 -0
  52. package/dist/src/ops/remove.js.map +1 -0
  53. package/dist/src/ops/update.d.ts +5 -0
  54. package/dist/src/ops/update.js +11 -0
  55. package/dist/src/ops/update.js.map +1 -0
  56. package/dist/tsconfig.tsbuildinfo +1 -0
  57. package/eslint.config.mjs +70 -0
  58. package/package.json +51 -0
  59. package/src/AItemAPI.ts +87 -0
  60. package/src/CItemAPI.ts +107 -0
  61. package/src/ClientApi.ts +59 -0
  62. package/src/ClientApiOptions.ts +17 -0
  63. package/src/PItemAPI.ts +171 -0
  64. package/src/Utilities.ts +183 -0
  65. package/src/index.ts +4 -0
  66. package/src/logger.ts +5 -0
  67. package/src/ops/action.ts +52 -0
  68. package/src/ops/all.ts +52 -0
  69. package/src/ops/allAction.ts +53 -0
  70. package/src/ops/create.ts +50 -0
  71. package/src/ops/find.ts +52 -0
  72. package/src/ops/get.ts +45 -0
  73. package/src/ops/index.ts +77 -0
  74. package/src/ops/one.ts +64 -0
  75. package/src/ops/remove.ts +41 -0
  76. package/src/ops/update.ts +47 -0
@@ -0,0 +1,77 @@
1
+ import { Item } from "@fjell/core"
2
+ import { getAllOperation } from "./all"
3
+ import { getActionOperation } from "./action"
4
+ import { Utilities } from "@/Utilities"
5
+ import { HttpApi } from "@fjell/http-api"
6
+ import { getAllActionOperation } from "./allAction"
7
+ import { getOneOperation } from "./one"
8
+ import { getCreateOperation } from "./create"
9
+ import { getUpdateOperation } from "./update"
10
+ import { getGetOperation } from "./get"
11
+ import { getRemoveOperation } from "./remove"
12
+ import { getFindOperation } from "./find"
13
+ import { ClientApiOptions } from "@/ClientApiOptions"
14
+ import { ClientApi } from "@/ClientApi"
15
+
16
+ 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
+ }
package/src/ops/one.ts ADDED
@@ -0,0 +1,64 @@
1
+ import {
2
+ Item,
3
+ ItemQuery,
4
+ LocKeyArray,
5
+ QueryParams,
6
+ queryToParams
7
+ } from "@fjell/core";
8
+ import { GetMethodOptions, 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
+ options: Partial<GetMethodOptions>,
31
+ locations: LocKeyArray<L1, L2, L3, L4, L5> | []
32
+ ) => Promise<V | null> => {
33
+
34
+ const one = async (
35
+ query: ItemQuery = {} as ItemQuery,
36
+ options: Partial<GetMethodOptions> = {},
37
+ locations: LocKeyArray<L1, L2, L3, L4, L5> | []
38
+ ): Promise<V | null> => {
39
+ logger.default('one', { query, locations });
40
+ utilities.verifyLocations(locations);
41
+
42
+ const loc: LocKeyArray<L1, L2, L3, L4, L5> | [] = locations;
43
+
44
+ const params: QueryParams = queryToParams(query);
45
+ const requestOptions = Object.assign({}, options, { isAuthenticated: apiOptions.readAuthenticated, params });
46
+
47
+ let item: V | null = null;
48
+
49
+ const items = utilities.validatePK(await utilities.processArray(
50
+ api.httpGet<V[]>(
51
+ utilities.getPath(loc),
52
+ requestOptions,
53
+ ))) as V[];
54
+
55
+ if (items.length > 0) {
56
+ item = items[0];
57
+ }
58
+
59
+ return item as V;
60
+ }
61
+
62
+ return one;
63
+ }
64
+
@@ -0,0 +1,41 @@
1
+ import {
2
+ ComKey,
3
+ Item,
4
+ PriKey,
5
+ } from "@fjell/core";
6
+ import { DeleteMethodOptions, 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
+ options: Partial<DeleteMethodOptions> = {},
31
+ ): Promise<boolean> => {
32
+ logger.default('remove', { ik });
33
+
34
+ const requestOptions = Object.assign({}, options, { isAuthenticated: apiOptions.writeAuthenticated });
35
+
36
+ return api.httpDelete<boolean>(utilities.getPath(ik), requestOptions);
37
+ }
38
+
39
+ return remove;
40
+ }
41
+
@@ -0,0 +1,47 @@
1
+ import {
2
+ ComKey,
3
+ Item,
4
+ ItemProperties,
5
+ PriKey
6
+ } from "@fjell/core";
7
+ import { HttpApi, PutMethodOptions } from "@fjell/http-api";
8
+
9
+ import { ClientApiOptions } from "@/ClientApiOptions";
10
+ import LibLogger from "@/logger";
11
+ import { Utilities } from "@/Utilities";
12
+
13
+ const logger = LibLogger.get('client-api', 'ops', 'update');
14
+
15
+ export const getUpdateOperation = <
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 update = async (
30
+ ik: PriKey<S> | ComKey<S, L1, L2, L3, L4, L5>,
31
+ item: ItemProperties<S, L1, L2, L3, L4, L5>,
32
+ options: Partial<PutMethodOptions> = {},
33
+ ): Promise<V> => {
34
+ logger.default('update', { ik, item });
35
+ const requestOptions = Object.assign({}, options, { isAuthenticated: apiOptions.writeAuthenticated });
36
+
37
+ return utilities.validatePK(await utilities.processOne(
38
+ api.httpPut<V>(
39
+ utilities.getPath(ik),
40
+ item,
41
+ requestOptions,
42
+ ))) as V;
43
+ }
44
+
45
+ return update;
46
+ }
47
+