@fjell/client-api 4.4.0 → 4.4.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 (47) hide show
  1. package/.kodrdriv/config.yaml +10 -0
  2. package/.kodrdriv/context/content.md +1 -0
  3. package/dist/AItemAPI.js +1 -1
  4. package/dist/AItemAPI.js.map +1 -0
  5. package/dist/CItemAPI.d.ts +9 -9
  6. package/dist/CItemAPI.js +1 -1
  7. package/dist/CItemAPI.js.map +1 -0
  8. package/dist/ClientApi.d.ts +9 -9
  9. package/dist/PItemAPI.d.ts +10 -10
  10. package/dist/PItemAPI.js +1 -1
  11. package/dist/PItemAPI.js.map +1 -0
  12. package/dist/Utilities.js +1 -1
  13. package/dist/Utilities.js.map +1 -0
  14. package/dist/index.cjs +427 -0
  15. package/dist/index.cjs.map +1 -0
  16. package/dist/index.js +1 -1
  17. package/dist/index.js.map +1 -0
  18. package/dist/logger.js +2 -2
  19. package/dist/logger.js.map +1 -0
  20. package/dist/ops/action.js +1 -1
  21. package/dist/ops/action.js.map +1 -0
  22. package/dist/ops/all.js +1 -1
  23. package/dist/ops/all.js.map +1 -0
  24. package/dist/ops/allAction.js +1 -1
  25. package/dist/ops/allAction.js.map +1 -0
  26. package/dist/ops/create.js +1 -1
  27. package/dist/ops/create.js.map +1 -0
  28. package/dist/ops/find.js +1 -1
  29. package/dist/ops/find.js.map +1 -0
  30. package/dist/ops/get.js +1 -1
  31. package/dist/ops/get.js.map +1 -0
  32. package/dist/ops/index.js +1 -1
  33. package/dist/ops/index.js.map +1 -0
  34. package/dist/ops/one.d.ts +1 -1
  35. package/dist/ops/one.js +2 -2
  36. package/dist/ops/one.js.map +1 -0
  37. package/dist/ops/remove.js +1 -1
  38. package/dist/ops/remove.js.map +1 -0
  39. package/dist/ops/update.js +1 -1
  40. package/dist/ops/update.js.map +1 -0
  41. package/package.json +25 -25
  42. package/src/CItemAPI.ts +14 -19
  43. package/src/ClientApi.ts +14 -14
  44. package/src/PItemAPI.ts +32 -35
  45. package/src/Utilities.ts +47 -47
  46. package/src/logger.ts +1 -1
  47. package/src/ops/one.ts +22 -23
package/src/PItemAPI.ts CHANGED
@@ -1,5 +1,5 @@
1
1
  /* eslint-disable @typescript-eslint/no-unused-vars */
2
-
2
+
3
3
  import { ComKey, Item, ItemProperties, ItemQuery, PriKey, TypesProperties } from "@fjell/core";
4
4
  import { HttpApi } from "@fjell/http-api";
5
5
  import { createAItemAPI, PathNamesArray } from "./AItemAPI";
@@ -14,74 +14,71 @@ export interface PItemApi<
14
14
  V extends Item<S>,
15
15
  S extends string
16
16
  > extends ClientApi<V, S> {
17
-
17
+
18
18
  action: (
19
19
  ik: PriKey<S> | ComKey<S, never, never, never, never, never>,
20
20
  action: string,
21
21
  body: any,
22
- options: Partial<PostMethodOptions>,
22
+ options?: Partial<PostMethodOptions>,
23
23
  locations?: []
24
24
  ) => Promise<V>;
25
25
 
26
26
  all: (
27
27
  query: ItemQuery,
28
- options: Partial<GetMethodOptions>,
28
+ options?: Partial<GetMethodOptions>,
29
29
  locations?: []
30
30
  ) => Promise<V[]>;
31
31
 
32
32
  allAction: (
33
33
  action: string,
34
34
  body: any,
35
- options: Partial<PostMethodOptions>
35
+ options?: Partial<PostMethodOptions>
36
36
  ) => Promise<V[]>;
37
37
 
38
38
  one: (
39
39
  query: ItemQuery,
40
- options: Partial<GetMethodOptions>
40
+ options?: Partial<GetMethodOptions>
41
41
  ) => Promise<V | null>;
42
42
 
43
43
  get: (
44
44
  ik: PriKey<S> | ComKey<S, never, never, never, never, never>,
45
- options: Partial<GetMethodOptions>,
45
+ options?: Partial<GetMethodOptions>,
46
46
  locations?: []
47
47
  ) => Promise<V | null>;
48
48
 
49
49
  create: (
50
50
  item: TypesProperties<V, S>,
51
- options: Partial<PostMethodOptions>,
51
+ options?: Partial<PostMethodOptions>,
52
52
  locations?: []
53
53
  ) => Promise<V>;
54
54
 
55
55
  remove: (
56
56
  ik: PriKey<S> | ComKey<S, never, never, never, never, never>,
57
- options: Partial<DeleteMethodOptions>,
57
+ options?: Partial<DeleteMethodOptions>,
58
58
  locations?: []
59
59
  ) => Promise<boolean>;
60
60
 
61
61
  update: (
62
62
  ik: PriKey<S> | ComKey<S, never, never, never, never, never>,
63
63
  item: TypesProperties<V, S>,
64
- options: Partial<PutMethodOptions>,
64
+ options?: Partial<PutMethodOptions>,
65
65
  locations?: []
66
66
  ) => Promise<V>;
67
67
 
68
68
  find: (
69
69
  finder: string,
70
70
  finderParams: Record<string, string | number | boolean | Date | Array<string | number | boolean | Date>>,
71
- options: Partial<GetMethodOptions>,
71
+ options?: Partial<GetMethodOptions>,
72
72
  locations?: []
73
73
  ) => Promise<V[]>;
74
74
  }
75
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> => {
76
+ export const createPItemApi = <V extends Item<S>, S extends string>(
77
+ api: HttpApi,
78
+ type: S,
79
+ pathName: string,
80
+ options?: ClientApiOptions
81
+ ): PItemApi<V, S> => {
85
82
 
86
83
  logger.default('createPItemApi', { type, pathName, options });
87
84
 
@@ -94,14 +91,14 @@ export const createPItemApi = <
94
91
  body: any = {},
95
92
  options: Partial<PostMethodOptions> = {},
96
93
  ): Promise<V> =>
97
- await aItemAPI.action(ik, action, body, options) as V;
94
+ await aItemAPI.action(ik, action, body, options) as V;
98
95
 
99
96
  const all =
100
97
  async (
101
98
  query: ItemQuery = {} as ItemQuery,
102
99
  options: Partial<GetMethodOptions> = {},
103
100
  ): Promise<V[]> =>
104
- await aItemAPI.all(query, options, []) as V[];
101
+ await aItemAPI.all(query, options, []) as V[];
105
102
 
106
103
  const allAction =
107
104
  async (
@@ -109,51 +106,51 @@ export const createPItemApi = <
109
106
  body: any = {},
110
107
  options: Partial<PostMethodOptions> = {},
111
108
  ): Promise<V[]> =>
112
- await aItemAPI.allAction(action, body, options, []) as V[];
113
-
109
+ await aItemAPI.allAction(action, body, options, []) as V[];
110
+
114
111
  const one =
115
112
  async (
116
113
  query: ItemQuery = {} as ItemQuery,
117
114
  options: Partial<GetMethodOptions> = {},
118
115
  ): Promise<V | null> =>
119
- await aItemAPI.one(query, options, []) as V | null;
120
-
116
+ await aItemAPI.one(query, options, []) as V | null;
117
+
121
118
  const get =
122
119
  async (
123
120
  ik: PriKey<S> | ComKey<S, never, never, never, never, never>,
124
121
  options: Partial<GetMethodOptions> = {},
125
122
  ): Promise<V | null> =>
126
- await aItemAPI.get(ik, options) as V | null;
127
-
123
+ await aItemAPI.get(ik, options) as V | null;
124
+
128
125
  const create =
129
126
  async (
130
127
  item: TypesProperties<V, S>,
131
128
  options: Partial<PostMethodOptions> = {},
132
129
  ): Promise<V> =>
133
- await aItemAPI.create(item, options, []) as V;
134
-
130
+ await aItemAPI.create(item, options, []) as V;
131
+
135
132
  const remove =
136
133
  async (
137
134
  ik: PriKey<S> | ComKey<S, never, never, never, never, never>,
138
135
  options: Partial<DeleteMethodOptions> = {},
139
136
  ): Promise<boolean> =>
140
- await aItemAPI.remove(ik, options) as boolean;
141
-
137
+ await aItemAPI.remove(ik, options) as boolean;
138
+
142
139
  const update =
143
140
  async (
144
141
  ik: PriKey<S> | ComKey<S, never, never, never, never, never>,
145
142
  item: TypesProperties<V, S>,
146
143
  options: Partial<PutMethodOptions> = {},
147
144
  ): Promise<V> =>
148
- await aItemAPI.update(ik, item, options) as V;
149
-
145
+ await aItemAPI.update(ik, item, options) as V;
146
+
150
147
  const find =
151
148
  async (
152
149
  finder: string,
153
150
  finderParams: Record<string, string | number | boolean | Date | Array<string | number | boolean | Date>>,
154
151
  options: Partial<GetMethodOptions> = {},
155
152
  ): Promise<V[]> =>
156
- await aItemAPI.find(finder, finderParams, options, []) as V[];
153
+ await aItemAPI.find(finder, finderParams, options, []) as V[];
157
154
 
158
155
  return {
159
156
  ...aItemAPI,
package/src/Utilities.ts CHANGED
@@ -15,31 +15,31 @@ import deepmerge from "deepmerge";
15
15
  const logger = LibLogger.get('client-api', 'Utility');
16
16
 
17
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
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
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>[];
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
33
  }
34
34
 
35
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
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
43
  >(pkType: S, pathNames: string[]): Utilities<V, S, L1, L2, L3, L4, L5> => {
44
44
 
45
45
  logger.default('createUtilities', { pkType, pathNames });
@@ -47,10 +47,10 @@ export const createUtilities = <
47
47
  const verifyLocations = (
48
48
  locations: LocKeyArray<L1, L2, L3, L4, L5> | [] | never,
49
49
  ): boolean => {
50
-
50
+
51
51
  if (locations && locations.length < pathNames.length - 1) {
52
52
  throw new Error('Not enough locations for pathNames: locations:'
53
- + locations.length + ' pathNames:' + pathNames.length);
53
+ + locations.length + ' pathNames:' + pathNames.length);
54
54
  }
55
55
  return true;
56
56
  }
@@ -96,33 +96,33 @@ export const createUtilities = <
96
96
  };
97
97
 
98
98
  const getPath =
99
- (
100
- key: ComKey<S, L1, L2, L3, L4, L5> | PriKey<S> | LocKeyArray<L1, L2, L3, L4, L5> | [],
101
- ):
102
- string => {
99
+ (
100
+ key: ComKey<S, L1, L2, L3, L4, L5> | PriKey<S> | LocKeyArray<L1, L2, L3, L4, L5> | [],
101
+ ):
102
+ string => {
103
103
 
104
- const localPathNames = [...pathNames];
105
- logger.default('getPath', { key, pathNames: localPathNames });
104
+ const localPathNames = [...pathNames];
105
+ logger.default('getPath', { key, pathNames: localPathNames });
106
106
 
107
- // console.log('getPath key: ' + JSON.stringify(key));
107
+ // console.log('getPath key: ' + JSON.stringify(key));
108
108
 
109
- const keys = generateKeyArray(key);
109
+ const keys = generateKeyArray(key);
110
110
 
111
- // console.log('getPath keys: ' + JSON.stringify(keys));
112
- // console.log('getPath pathNames: ' + JSON.stringify(pathNames));
111
+ // console.log('getPath keys: ' + JSON.stringify(keys));
112
+ // console.log('getPath pathNames: ' + JSON.stringify(pathNames));
113
113
 
114
- let path: string = addPath('', keys, localPathNames);
114
+ let path: string = addPath('', keys, localPathNames);
115
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
- }
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
121
 
122
- logger.default('getPath created', { key, path });
122
+ logger.default('getPath created', { key, path });
123
123
 
124
- return path;
125
- };
124
+ return path;
125
+ };
126
126
 
127
127
  const addPath = (
128
128
  base: string,
@@ -134,19 +134,19 @@ export const createUtilities = <
134
134
  logger.error('addPath should never have keys with a length less than the length of pathNames - 1',
135
135
  { keys, localPathNames });
136
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));
137
+ + keys.length + ' ' + localPathNames.length + ' ' + JSON.stringify(keys, localPathNames));
138
138
  } else if (keys.length > localPathNames.length) {
139
139
  logger.error('addPath should never have keys with a length greater than the length of pathNames',
140
140
  { keys, pathNames });
141
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));
142
+ + keys.length + ' ' + localPathNames.length + ' ' + JSON.stringify(keys, localPathNames));
143
143
  }
144
144
  if (keys.length === 0) {
145
- // If you've recursively consumed all of the keys, return the base.
145
+ // If you've recursively consumed all of the keys, return the base.
146
146
  logger.default('addPath returning base', { base });
147
147
  return base;
148
148
  } else {
149
- // Retrieve the next key and collection, and create the next base
149
+ // Retrieve the next key and collection, and create the next base
150
150
  let nextBase: string;
151
151
  const key = keys.pop();
152
152
  const pathName = localPathNames.pop();
@@ -168,7 +168,7 @@ export const createUtilities = <
168
168
 
169
169
  const validatePK = (
170
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>[] => {
171
+ Item<S, L1, L2, L3, L4, L5> | Item<S, L1, L2, L3, L4, L5>[] => {
172
172
  return coreValidatePK<S, L1, L2, L3, L4, L5>(item, pkType);
173
173
  }
174
174
 
package/src/logger.ts CHANGED
@@ -1,5 +1,5 @@
1
1
  import Logging from '@fjell/logging';
2
2
 
3
- const LibLogger = Logging.getLogger('@fjellproject/client-api');
3
+ const LibLogger = Logging.getLogger('@fjell/client-api');
4
4
 
5
5
  export default LibLogger;
package/src/ops/one.ts CHANGED
@@ -6,59 +6,58 @@ import {
6
6
  queryToParams
7
7
  } from "@fjell/core";
8
8
  import { GetMethodOptions, HttpApi } from "@fjell/http-api";
9
-
9
+
10
10
  import { ClientApiOptions } from "@/ClientApiOptions";
11
11
  import LibLogger from "@/logger";
12
12
  import { Utilities } from "@/Utilities";
13
-
13
+
14
14
  const logger = LibLogger.get('client-api', 'ops', 'one');
15
-
15
+
16
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>(
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
24
  api: HttpApi,
25
25
  apiOptions: ClientApiOptions,
26
26
  utilities: Utilities<V, S, L1, L2, L3, L4, L5>
27
-
27
+
28
28
  ): (
29
29
  query: ItemQuery,
30
- options: Partial<GetMethodOptions>,
31
- locations: LocKeyArray<L1, L2, L3, L4, L5> | []
30
+ options?: Partial<GetMethodOptions>,
31
+ locations?: LocKeyArray<L1, L2, L3, L4, L5> | []
32
32
  ) => Promise<V | null> => {
33
-
33
+
34
34
  const one = async (
35
35
  query: ItemQuery = {} as ItemQuery,
36
36
  options: Partial<GetMethodOptions> = {},
37
- locations: LocKeyArray<L1, L2, L3, L4, L5> | []
37
+ locations: LocKeyArray<L1, L2, L3, L4, L5> | [] = []
38
38
  ): Promise<V | null> => {
39
39
  logger.default('one', { query, locations });
40
40
  utilities.verifyLocations(locations);
41
-
41
+
42
42
  const loc: LocKeyArray<L1, L2, L3, L4, L5> | [] = locations;
43
-
43
+
44
44
  const params: QueryParams = queryToParams(query);
45
45
  const requestOptions = Object.assign({}, options, { isAuthenticated: apiOptions.readAuthenticated, params });
46
-
46
+
47
47
  let item: V | null = null;
48
-
48
+
49
49
  const items = utilities.validatePK(await utilities.processArray(
50
50
  api.httpGet<V[]>(
51
51
  utilities.getPath(loc),
52
52
  requestOptions,
53
53
  ))) as V[];
54
-
54
+
55
55
  if (items.length > 0) {
56
56
  item = items[0];
57
57
  }
58
-
58
+
59
59
  return item as V;
60
60
  }
61
-
61
+
62
62
  return one;
63
63
  }
64
-