@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.
- package/.kodrdriv/config.yaml +10 -0
- package/.kodrdriv/context/content.md +1 -0
- package/dist/AItemAPI.js +1 -1
- package/dist/AItemAPI.js.map +1 -0
- package/dist/CItemAPI.d.ts +9 -9
- package/dist/CItemAPI.js +1 -1
- package/dist/CItemAPI.js.map +1 -0
- package/dist/ClientApi.d.ts +9 -9
- package/dist/PItemAPI.d.ts +10 -10
- package/dist/PItemAPI.js +1 -1
- package/dist/PItemAPI.js.map +1 -0
- package/dist/Utilities.js +1 -1
- package/dist/Utilities.js.map +1 -0
- package/dist/index.cjs +427 -0
- package/dist/index.cjs.map +1 -0
- package/dist/index.js +1 -1
- package/dist/index.js.map +1 -0
- package/dist/logger.js +2 -2
- package/dist/logger.js.map +1 -0
- package/dist/ops/action.js +1 -1
- package/dist/ops/action.js.map +1 -0
- package/dist/ops/all.js +1 -1
- package/dist/ops/all.js.map +1 -0
- package/dist/ops/allAction.js +1 -1
- package/dist/ops/allAction.js.map +1 -0
- package/dist/ops/create.js +1 -1
- package/dist/ops/create.js.map +1 -0
- package/dist/ops/find.js +1 -1
- package/dist/ops/find.js.map +1 -0
- package/dist/ops/get.js +1 -1
- package/dist/ops/get.js.map +1 -0
- package/dist/ops/index.js +1 -1
- package/dist/ops/index.js.map +1 -0
- package/dist/ops/one.d.ts +1 -1
- package/dist/ops/one.js +2 -2
- package/dist/ops/one.js.map +1 -0
- package/dist/ops/remove.js +1 -1
- package/dist/ops/remove.js.map +1 -0
- package/dist/ops/update.js +1 -1
- package/dist/ops/update.js.map +1 -0
- package/package.json +25 -25
- package/src/CItemAPI.ts +14 -19
- package/src/ClientApi.ts +14 -14
- package/src/PItemAPI.ts +32 -35
- package/src/Utilities.ts +47 -47
- package/src/logger.ts +1 -1
- 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
|
|
22
|
+
options?: Partial<PostMethodOptions>,
|
|
23
23
|
locations?: []
|
|
24
24
|
) => Promise<V>;
|
|
25
25
|
|
|
26
26
|
all: (
|
|
27
27
|
query: ItemQuery,
|
|
28
|
-
options
|
|
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
|
|
35
|
+
options?: Partial<PostMethodOptions>
|
|
36
36
|
) => Promise<V[]>;
|
|
37
37
|
|
|
38
38
|
one: (
|
|
39
39
|
query: ItemQuery,
|
|
40
|
-
options
|
|
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
|
|
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
|
|
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
|
|
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
|
|
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
|
|
71
|
+
options?: Partial<GetMethodOptions>,
|
|
72
72
|
locations?: []
|
|
73
73
|
) => Promise<V[]>;
|
|
74
74
|
}
|
|
75
75
|
|
|
76
|
-
export const createPItemApi = <
|
|
77
|
-
|
|
78
|
-
S
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
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
|
-
|
|
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
|
-
|
|
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
|
-
|
|
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
|
-
|
|
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
|
-
|
|
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
|
-
|
|
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
|
-
|
|
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
|
-
|
|
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
|
-
|
|
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
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
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
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
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
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
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
|
-
|
|
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
|
-
|
|
101
|
-
|
|
102
|
-
|
|
99
|
+
(
|
|
100
|
+
key: ComKey<S, L1, L2, L3, L4, L5> | PriKey<S> | LocKeyArray<L1, L2, L3, L4, L5> | [],
|
|
101
|
+
):
|
|
102
|
+
string => {
|
|
103
103
|
|
|
104
|
-
|
|
105
|
-
|
|
104
|
+
const localPathNames = [...pathNames];
|
|
105
|
+
logger.default('getPath', { key, pathNames: localPathNames });
|
|
106
106
|
|
|
107
|
-
|
|
107
|
+
// console.log('getPath key: ' + JSON.stringify(key));
|
|
108
108
|
|
|
109
|
-
|
|
109
|
+
const keys = generateKeyArray(key);
|
|
110
110
|
|
|
111
|
-
|
|
112
|
-
|
|
111
|
+
// console.log('getPath keys: ' + JSON.stringify(keys));
|
|
112
|
+
// console.log('getPath pathNames: ' + JSON.stringify(pathNames));
|
|
113
113
|
|
|
114
|
-
|
|
114
|
+
let path: string = addPath('', keys, localPathNames);
|
|
115
115
|
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
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
|
-
|
|
122
|
+
logger.default('getPath created', { key, path });
|
|
123
123
|
|
|
124
|
-
|
|
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
|
-
|
|
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
|
-
|
|
142
|
+
+ keys.length + ' ' + localPathNames.length + ' ' + JSON.stringify(keys, localPathNames));
|
|
143
143
|
}
|
|
144
144
|
if (keys.length === 0) {
|
|
145
|
-
|
|
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
|
-
|
|
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
|
-
|
|
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
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
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
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
|
|
31
|
-
locations
|
|
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
|
-
|