@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,17 @@
1
+ import { Item } from "@fjell/core";
2
+ import { ClientApi } from "./ClientApi";
3
+
4
+ export interface ClientApiOptions {
5
+ readAuthenticated?: boolean;
6
+ allAuthenticated?: boolean;
7
+ writeAuthenticated?: boolean;
8
+ parentApi?: ClientApi<
9
+ Item<string, string | never, string | never, string | never, string | never, string | never>,
10
+ string,
11
+ string | never,
12
+ string | never,
13
+ string | never,
14
+ string | never,
15
+ string | never
16
+ >;
17
+ }
@@ -0,0 +1,171 @@
1
+ /* eslint-disable @typescript-eslint/no-unused-vars */
2
+
3
+ import { ComKey, Item, ItemProperties, ItemQuery, PriKey, TypesProperties } from "@fjell/core";
4
+ import { HttpApi } from "@fjell/http-api";
5
+ import { createAItemAPI, PathNamesArray } from "./AItemAPI";
6
+ import { ClientApi } from "./ClientApi";
7
+
8
+ import { DeleteMethodOptions, GetMethodOptions, PostMethodOptions, PutMethodOptions } from "@fjell/http-api";
9
+ import { ClientApiOptions } from "./ClientApiOptions";
10
+ import LibLogger from "@/logger";
11
+ const logger = LibLogger.get('PItemAPI');
12
+
13
+ export interface PItemApi<
14
+ V extends Item<S>,
15
+ S extends string
16
+ > extends ClientApi<V, S> {
17
+
18
+ action: (
19
+ ik: PriKey<S> | ComKey<S, never, never, never, never, never>,
20
+ action: string,
21
+ body: any,
22
+ options: Partial<PostMethodOptions>,
23
+ locations?: []
24
+ ) => Promise<V>;
25
+
26
+ all: (
27
+ query: ItemQuery,
28
+ options: Partial<GetMethodOptions>,
29
+ locations?: []
30
+ ) => Promise<V[]>;
31
+
32
+ allAction: (
33
+ action: string,
34
+ body: any,
35
+ options: Partial<PostMethodOptions>
36
+ ) => Promise<V[]>;
37
+
38
+ one: (
39
+ query: ItemQuery,
40
+ options: Partial<GetMethodOptions>
41
+ ) => Promise<V | null>;
42
+
43
+ get: (
44
+ ik: PriKey<S> | ComKey<S, never, never, never, never, never>,
45
+ options: Partial<GetMethodOptions>,
46
+ locations?: []
47
+ ) => Promise<V | null>;
48
+
49
+ create: (
50
+ item: TypesProperties<V, S>,
51
+ options: Partial<PostMethodOptions>,
52
+ locations?: []
53
+ ) => Promise<V>;
54
+
55
+ remove: (
56
+ ik: PriKey<S> | ComKey<S, never, never, never, never, never>,
57
+ options: Partial<DeleteMethodOptions>,
58
+ locations?: []
59
+ ) => Promise<boolean>;
60
+
61
+ update: (
62
+ ik: PriKey<S> | ComKey<S, never, never, never, never, never>,
63
+ item: TypesProperties<V, S>,
64
+ options: Partial<PutMethodOptions>,
65
+ locations?: []
66
+ ) => Promise<V>;
67
+
68
+ find: (
69
+ finder: string,
70
+ finderParams: Record<string, string | number | boolean | Date | Array<string | number | boolean | Date>>,
71
+ options: Partial<GetMethodOptions>,
72
+ locations?: []
73
+ ) => Promise<V[]>;
74
+ }
75
+
76
+ export const createPItemApi = <
77
+ V extends Item<S>,
78
+ S extends string
79
+ >(
80
+ api: HttpApi,
81
+ type: S,
82
+ pathName: string,
83
+ options: ClientApiOptions
84
+ ): PItemApi<V, S> => {
85
+
86
+ logger.default('createPItemApi', { type, pathName, options });
87
+
88
+ const aItemAPI = createAItemAPI<V, S>(api, type, [pathName], options);
89
+
90
+ const action =
91
+ async (
92
+ ik: PriKey<S> | ComKey<S, never, never, never, never, never>,
93
+ action: string,
94
+ body: any = {},
95
+ options: Partial<PostMethodOptions> = {},
96
+ ): Promise<V> =>
97
+ await aItemAPI.action(ik, action, body, options) as V;
98
+
99
+ const all =
100
+ async (
101
+ query: ItemQuery = {} as ItemQuery,
102
+ options: Partial<GetMethodOptions> = {},
103
+ ): Promise<V[]> =>
104
+ await aItemAPI.all(query, options, []) as V[];
105
+
106
+ const allAction =
107
+ async (
108
+ action: string,
109
+ body: any = {},
110
+ options: Partial<PostMethodOptions> = {},
111
+ ): Promise<V[]> =>
112
+ await aItemAPI.allAction(action, body, options, []) as V[];
113
+
114
+ const one =
115
+ async (
116
+ query: ItemQuery = {} as ItemQuery,
117
+ options: Partial<GetMethodOptions> = {},
118
+ ): Promise<V | null> =>
119
+ await aItemAPI.one(query, options, []) as V | null;
120
+
121
+ const get =
122
+ async (
123
+ ik: PriKey<S> | ComKey<S, never, never, never, never, never>,
124
+ options: Partial<GetMethodOptions> = {},
125
+ ): Promise<V | null> =>
126
+ await aItemAPI.get(ik, options) as V | null;
127
+
128
+ const create =
129
+ async (
130
+ item: TypesProperties<V, S>,
131
+ options: Partial<PostMethodOptions> = {},
132
+ ): Promise<V> =>
133
+ await aItemAPI.create(item, options, []) as V;
134
+
135
+ const remove =
136
+ async (
137
+ ik: PriKey<S> | ComKey<S, never, never, never, never, never>,
138
+ options: Partial<DeleteMethodOptions> = {},
139
+ ): Promise<boolean> =>
140
+ await aItemAPI.remove(ik, options) as boolean;
141
+
142
+ const update =
143
+ async (
144
+ ik: PriKey<S> | ComKey<S, never, never, never, never, never>,
145
+ item: TypesProperties<V, S>,
146
+ options: Partial<PutMethodOptions> = {},
147
+ ): Promise<V> =>
148
+ await aItemAPI.update(ik, item, options) as V;
149
+
150
+ const find =
151
+ async (
152
+ finder: string,
153
+ finderParams: Record<string, string | number | boolean | Date | Array<string | number | boolean | Date>>,
154
+ options: Partial<GetMethodOptions> = {},
155
+ ): Promise<V[]> =>
156
+ await aItemAPI.find(finder, finderParams, options, []) as V[];
157
+
158
+ return {
159
+ ...aItemAPI,
160
+ action,
161
+ all,
162
+ allAction,
163
+ one,
164
+ get,
165
+ create,
166
+ remove,
167
+ update,
168
+ find,
169
+ };
170
+
171
+ };
@@ -0,0 +1,183 @@
1
+ import {
2
+ ComKey,
3
+ validatePK as coreValidatePK,
4
+ generateKeyArray,
5
+ isPriKey,
6
+ Item,
7
+ LocKey,
8
+ LocKeyArray,
9
+ PriKey,
10
+ } from "@fjell/core";
11
+
12
+ import LibLogger from "@/logger";
13
+ import deepmerge from "deepmerge";
14
+
15
+ const logger = LibLogger.get('client-api', 'Utility');
16
+
17
+ export interface Utilities<
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
+ verifyLocations: (locations: LocKeyArray<L1, L2, L3, L4, L5> | [] | never) => boolean;
27
+ processOne: (apiCall: Promise<V>) => Promise<V>;
28
+ processArray: (api: Promise<V[]>) => Promise<V[]>;
29
+ convertDoc: (doc: V) => V;
30
+ getPath: (key: ComKey<S, L1, L2, L3, L4, L5> | PriKey<S> | LocKeyArray<L1, L2, L3, L4, L5> | []) => string;
31
+ validatePK: (item: Item<S, L1, L2, L3, L4, L5> | Item<S, L1, L2, L3, L4, L5>[]) =>
32
+ Item<S, L1, L2, L3, L4, L5> | Item<S, L1, L2, L3, L4, L5>[];
33
+ }
34
+
35
+ export const createUtilities = <
36
+ V extends Item<S, L1, L2, L3, L4, L5>,
37
+ S extends string,
38
+ L1 extends string = never,
39
+ L2 extends string = never,
40
+ L3 extends string = never,
41
+ L4 extends string = never,
42
+ L5 extends string = never
43
+ >(pkType: S, pathNames: string[]): Utilities<V, S, L1, L2, L3, L4, L5> => {
44
+
45
+ logger.default('createUtilities', { pkType, pathNames });
46
+
47
+ const verifyLocations = (
48
+ locations: LocKeyArray<L1, L2, L3, L4, L5> | [] | never,
49
+ ): boolean => {
50
+
51
+ if (locations && locations.length < pathNames.length - 1) {
52
+ throw new Error('Not enough locations for pathNames: locations:'
53
+ + locations.length + ' pathNames:' + pathNames.length);
54
+ }
55
+ return true;
56
+ }
57
+
58
+ const processOne = async (
59
+ apiCall: Promise<V>,
60
+ ): Promise<V> => {
61
+ logger.default('processOne', { apiCall });
62
+ const response = await apiCall;
63
+ logger.default('processOne response', { response: JSON.stringify(response, null, 2) });
64
+ return convertDoc(response);
65
+ };
66
+
67
+ const processArray = async (
68
+ api: Promise<V[]>,
69
+ ): Promise<V[]> => {
70
+ logger.default('processArray', { api });
71
+ const response = await api;
72
+ logger.default('processArray response', { response: JSON.stringify(response, null, 2) });
73
+ if (response && Array.isArray(response)) {
74
+ return response.map((subjectChat: V) =>
75
+ convertDoc(subjectChat),
76
+ ) as unknown as V[];
77
+ } else {
78
+ logger.error('Response was not an array', { response });
79
+ throw new Error('Response was not an array');
80
+ }
81
+ };
82
+
83
+ const convertDoc = (doc: V): V => {
84
+ logger.default('convertDoc', { doc });
85
+ // console.log(JSON.stringify(doc, null, 2));
86
+ if (doc && doc.events) {
87
+ const events = doc.events;
88
+ for (const key in events) {
89
+ events[key] = deepmerge(events[key], { at: events[key].at ? new Date(events[key].at) : null });
90
+ }
91
+
92
+ return doc as unknown as V;
93
+ } else {
94
+ return doc;
95
+ }
96
+ };
97
+
98
+ const getPath =
99
+ (
100
+ key: ComKey<S, L1, L2, L3, L4, L5> | PriKey<S> | LocKeyArray<L1, L2, L3, L4, L5> | [],
101
+ ):
102
+ string => {
103
+
104
+ const localPathNames = [...pathNames];
105
+ logger.default('getPath', { key, pathNames: localPathNames });
106
+
107
+ // console.log('getPath key: ' + JSON.stringify(key));
108
+
109
+ const keys = generateKeyArray(key);
110
+
111
+ // console.log('getPath keys: ' + JSON.stringify(keys));
112
+ // console.log('getPath pathNames: ' + JSON.stringify(pathNames));
113
+
114
+ let path: string = addPath('', keys, localPathNames);
115
+
116
+ // If there is only one collection left in the collections array, this means that
117
+ // we received LocKeys and we need to add the last collection to the reference
118
+ if (localPathNames.length === 1) {
119
+ path = `${path}/${localPathNames[0]}`;
120
+ }
121
+
122
+ logger.default('getPath created', { key, path });
123
+
124
+ return path;
125
+ };
126
+
127
+ const addPath = (
128
+ base: string,
129
+ keys: Array<PriKey<S> | LocKey<L1 | L2 | L3 | L4 | L5>>,
130
+ localPathNames: string[],
131
+ ): string => {
132
+ logger.default('addPath', { base, keys, pathNames: localPathNames });
133
+ if (keys.length < localPathNames.length - 1) {
134
+ logger.error('addPath should never have keys with a length less than the length of pathNames - 1',
135
+ { keys, localPathNames });
136
+ throw new Error('addPath should never have keys with a length less than the length of pathNames - 1: '
137
+ + keys.length + ' ' + localPathNames.length + ' ' + JSON.stringify(keys, localPathNames));
138
+ } else if (keys.length > localPathNames.length) {
139
+ logger.error('addPath should never have keys with a length greater than the length of pathNames',
140
+ { keys, pathNames });
141
+ throw new Error('addPath should never have keys with a length greater than the length of pathNames: '
142
+ + keys.length + ' ' + localPathNames.length + ' ' + JSON.stringify(keys, localPathNames));
143
+ }
144
+ if (keys.length === 0) {
145
+ // If you've recursively consumed all of the keys, return the base.
146
+ logger.default('addPath returning base', { base });
147
+ return base;
148
+ } else {
149
+ // Retrieve the next key and collection, and create the next base
150
+ let nextBase: string;
151
+ const key = keys.pop();
152
+ const pathName = localPathNames.pop();
153
+ if (isPriKey(key)) {
154
+ const PriKey = key as PriKey<S>;
155
+ nextBase = `${base}/${pathName}/${PriKey.pk}`;
156
+ logger.default('Adding Path for PK', { pathName, PriKey, nextBase });
157
+ } else {
158
+ const LocKey = key as LocKey<L1 | L2 | L3 | L4 | L5>;
159
+ nextBase = `${base}/${pathName}/${LocKey.lk}`;
160
+ logger.default('Retrieving Collection for LK', { pathName, LocKey });
161
+ }
162
+
163
+ logger.default('calling addPath recursively', { nextBase, keys, localPathNames });
164
+ return addPath(nextBase, keys, localPathNames);
165
+ }
166
+
167
+ }
168
+
169
+ const validatePK = (
170
+ item: Item<S, L1, L2, L3, L4, L5> | Item<S, L1, L2, L3, L4, L5>[]):
171
+ Item<S, L1, L2, L3, L4, L5> | Item<S, L1, L2, L3, L4, L5>[] => {
172
+ return coreValidatePK<S, L1, L2, L3, L4, L5>(item, pkType);
173
+ }
174
+
175
+ return {
176
+ verifyLocations,
177
+ processOne,
178
+ convertDoc,
179
+ processArray,
180
+ getPath,
181
+ validatePK,
182
+ }
183
+ }
package/src/index.ts ADDED
@@ -0,0 +1,4 @@
1
+ export { createCItemApi, CItemApi } from "./CItemAPI";
2
+ export { createPItemApi, PItemApi } from "./PItemAPI";
3
+ export { ClientApi } from "./ClientApi";
4
+ export { ClientApiOptions } from "./ClientApiOptions";
package/src/logger.ts ADDED
@@ -0,0 +1,5 @@
1
+ import Logging from '@fjell/logging';
2
+
3
+ const LibLogger = Logging.getLogger('@fjellproject/client-api');
4
+
5
+ export default LibLogger;
@@ -0,0 +1,52 @@
1
+ import {
2
+ ComKey,
3
+ Item,
4
+ PriKey,
5
+ } from "@fjell/core";
6
+ import { HttpApi, PostMethodOptions } 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', 'action');
13
+
14
+ export const getActionOperation = <
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 action = async (
29
+ ik: ComKey<S, L1, L2, L3, L4, L5> | PriKey<S>,
30
+ action: string,
31
+ body: any = {},
32
+ options: Partial<PostMethodOptions> = {}
33
+ ):
34
+ Promise<V> => {
35
+ logger.default('action', { ik, action, body });
36
+
37
+ const requestOptions = Object.assign({}, options, { isAuthenticated: apiOptions.writeAuthenticated });
38
+
39
+ return utilities.validatePK(
40
+ await utilities.processOne(
41
+ api.httpPost<V>(
42
+ `${utilities.getPath(ik)}/${action}`,
43
+ body,
44
+ requestOptions,
45
+ )
46
+ )) as V;
47
+
48
+ };
49
+
50
+ return action;
51
+ }
52
+
package/src/ops/all.ts ADDED
@@ -0,0 +1,52 @@
1
+ import {
2
+ Item,
3
+ ItemQuery,
4
+ LocKeyArray,
5
+ queryToParams,
6
+ } from "@fjell/core";
7
+ import { HttpApi, QueryParams } from "@fjell/http-api";
8
+
9
+ import { ClientApiOptions } from "@/ClientApiOptions";
10
+ import LibLogger from "@/logger";
11
+ import { Utilities } from "@/Utilities";
12
+ import { GetMethodOptions } from "@fjell/http-api";
13
+
14
+ const logger = LibLogger.get('client-api', 'ops', 'all');
15
+
16
+ export const getAllOperation = <
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
+
30
+ const all = async (
31
+ query: ItemQuery = {} as ItemQuery,
32
+ options: Partial<GetMethodOptions> = {},
33
+ locations: LocKeyArray<L1, L2, L3, L4, L5> | [] = []
34
+ ): Promise<V[]> => {
35
+ logger.default('all', { query, locations });
36
+ utilities.verifyLocations(locations);
37
+ const loc: LocKeyArray<L1, L2, L3, L4, L5> | [] = locations;
38
+
39
+ const params: QueryParams = queryToParams(query);
40
+
41
+ const requestOptions = Object.assign({}, options, { isAuthenticated: apiOptions.allAuthenticated, params });
42
+
43
+ return utilities.validatePK(await utilities.processArray(
44
+ api.httpGet<V[]>(
45
+ utilities.getPath(loc),
46
+ requestOptions,
47
+ ))) as V[];
48
+ }
49
+
50
+ return all;
51
+ }
52
+
@@ -0,0 +1,53 @@
1
+ import {
2
+ Item,
3
+ LocKeyArray
4
+ } from "@fjell/core";
5
+ import { HttpApi, PostMethodOptions } from "@fjell/http-api";
6
+
7
+ import { ClientApiOptions } from "@/ClientApiOptions";
8
+ import LibLogger from "@/logger";
9
+ import { Utilities } from "@/Utilities";
10
+
11
+ const logger = LibLogger.get('client-api', 'ops', 'allAction');
12
+
13
+ export const getAllActionOperation = <
14
+ V extends Item<S, L1, L2, L3, L4, L5>,
15
+ S extends string,
16
+ L1 extends string = never,
17
+ L2 extends string = never,
18
+ L3 extends string = never,
19
+ L4 extends string = never,
20
+ L5 extends string = never>(
21
+ api: HttpApi,
22
+ apiOptions: ClientApiOptions,
23
+ utilities: Utilities<V, S, L1, L2, L3, L4, L5>
24
+
25
+ ) => {
26
+
27
+ const allAction = async (
28
+ action: string,
29
+ body: any = {},
30
+ options: Partial<PostMethodOptions> = {},
31
+ locations: LocKeyArray<L1, L2, L3, L4, L5> | [] = []
32
+ ): Promise<V[]> => {
33
+ logger.default('allAction', { action, body, locations });
34
+ utilities.verifyLocations(locations);
35
+
36
+ const loc: LocKeyArray<L1, L2, L3, L4, L5> | [] = locations;
37
+
38
+ const requestOptions = Object.assign({}, options, { isAuthenticated: apiOptions.writeAuthenticated });
39
+
40
+ // TODO: This should respond to either a single object, or multiple objects in an array.
41
+ return utilities.validatePK(
42
+ await utilities.processArray(
43
+ api.httpPost<V[]>(
44
+ utilities.getPath(loc),
45
+ body,
46
+ requestOptions,
47
+ )
48
+ )) as V[];
49
+ };
50
+
51
+ return allAction;
52
+ }
53
+
@@ -0,0 +1,50 @@
1
+ import {
2
+ Item,
3
+ ItemProperties,
4
+ LocKeyArray
5
+ } from "@fjell/core";
6
+ import { HttpApi, PostMethodOptions } 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', 'create');
13
+
14
+ export const getCreateOperation = <
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 create = async (
29
+ item: ItemProperties<S, L1, L2, L3, L4, L5>,
30
+ options: Partial<PostMethodOptions> = {},
31
+ locations: LocKeyArray<L1, L2, L3, L4, L5> | [] = []
32
+ ): Promise<V> => {
33
+ logger.default('create', { item, locations });
34
+ utilities.verifyLocations(locations);
35
+
36
+ const loc: LocKeyArray<L1, L2, L3, L4, L5> | [] = locations;
37
+ const requestOptions = Object.assign({}, options, { isAuthenticated: apiOptions.writeAuthenticated });
38
+
39
+ const created: V =
40
+ utilities.validatePK(await utilities.processOne(api.httpPost<V>(
41
+ utilities.getPath(loc),
42
+ item,
43
+ requestOptions,
44
+ ))) as V;
45
+ return created;
46
+ };
47
+
48
+ return create;
49
+ }
50
+
@@ -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 getFindOperation = <
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 find = 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('find', { 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
+
41
+ const requestOptions = Object.assign({}, options, { isAuthenticated: apiOptions.allAuthenticated, params });
42
+
43
+ return utilities.validatePK(await utilities.processArray(
44
+ api.httpGet<V[]>(
45
+ utilities.getPath(loc),
46
+ requestOptions,
47
+ ))) as V[];
48
+ }
49
+
50
+ return find;
51
+ }
52
+
package/src/ops/get.ts ADDED
@@ -0,0 +1,45 @@
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', 'get');
13
+
14
+ export const getGetOperation = <
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 get = async (
29
+ ik: PriKey<S> | ComKey<S, never, never, never, never, never>,
30
+ options: Partial<GetMethodOptions> = {},
31
+ ): Promise<V | null> => {
32
+ logger.default('get', { ik });
33
+
34
+ const requestOptions = Object.assign({}, options, { isAuthenticated: apiOptions.readAuthenticated });
35
+
36
+ return utilities.validatePK(await utilities.processOne(
37
+ api.httpGet<V>(
38
+ utilities.getPath(ik),
39
+ requestOptions,
40
+ ))) as V;
41
+ }
42
+
43
+ return get;
44
+ }
45
+