@fjell/client-api 4.4.0 → 4.4.2
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 +3 -1
- package/dist/AItemAPI.js.map +1 -0
- package/dist/CItemAPI.d.ts +11 -9
- package/dist/CItemAPI.js +4 -2
- package/dist/CItemAPI.js.map +1 -0
- package/dist/ClientApi.d.ts +11 -9
- package/dist/PItemAPI.d.ts +12 -10
- package/dist/PItemAPI.js +6 -2
- package/dist/PItemAPI.js.map +1 -0
- package/dist/Utilities.js +1 -1
- package/dist/Utilities.js.map +1 -0
- package/dist/index.cjs +486 -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/facet.d.ts +5 -0
- package/dist/ops/facet.js +32 -0
- package/dist/ops/facet.js.map +1 -0
- package/dist/ops/find.js +1 -1
- package/dist/ops/find.js.map +1 -0
- package/dist/ops/findOne.d.ts +5 -0
- package/dist/ops/findOne.js +26 -0
- package/dist/ops/findOne.js.map +1 -0
- package/dist/ops/get.js +1 -1
- package/dist/ops/get.js.map +1 -0
- package/dist/ops/index.js +5 -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/AItemAPI.ts +12 -9
- package/src/CItemAPI.ts +27 -19
- package/src/ClientApi.ts +25 -14
- package/src/PItemAPI.ts +63 -35
- package/src/Utilities.ts +47 -47
- package/src/logger.ts +1 -1
- package/src/ops/facet.ts +59 -0
- package/src/ops/findOne.ts +52 -0
- package/src/ops/index.ts +74 -61
- 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,84 @@ 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
|
+
facet: (
|
|
69
|
+
ik: PriKey<S> | ComKey<S, never, never, never, never, never>,
|
|
70
|
+
facet: string,
|
|
71
|
+
options?: Partial<GetMethodOptions>,
|
|
72
|
+
) => Promise<any>;
|
|
73
|
+
|
|
68
74
|
find: (
|
|
69
75
|
finder: string,
|
|
70
76
|
finderParams: Record<string, string | number | boolean | Date | Array<string | number | boolean | Date>>,
|
|
71
|
-
options
|
|
77
|
+
options?: Partial<GetMethodOptions>,
|
|
72
78
|
locations?: []
|
|
73
79
|
) => Promise<V[]>;
|
|
80
|
+
|
|
81
|
+
findOne: (
|
|
82
|
+
finder: string,
|
|
83
|
+
finderParams: Record<string, string | number | boolean | Date | Array<string | number | boolean | Date>>,
|
|
84
|
+
options?: Partial<GetMethodOptions>,
|
|
85
|
+
locations?: []
|
|
86
|
+
) => Promise<V>;
|
|
74
87
|
}
|
|
75
88
|
|
|
76
|
-
export const createPItemApi = <
|
|
77
|
-
|
|
78
|
-
S
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
pathName: string,
|
|
83
|
-
options: ClientApiOptions
|
|
84
|
-
): PItemApi<V, S> => {
|
|
89
|
+
export const createPItemApi = <V extends Item<S>, S extends string>(
|
|
90
|
+
api: HttpApi,
|
|
91
|
+
type: S,
|
|
92
|
+
pathName: string,
|
|
93
|
+
options?: ClientApiOptions
|
|
94
|
+
): PItemApi<V, S> => {
|
|
85
95
|
|
|
86
96
|
logger.default('createPItemApi', { type, pathName, options });
|
|
87
97
|
|
|
@@ -94,14 +104,14 @@ export const createPItemApi = <
|
|
|
94
104
|
body: any = {},
|
|
95
105
|
options: Partial<PostMethodOptions> = {},
|
|
96
106
|
): Promise<V> =>
|
|
97
|
-
|
|
107
|
+
await aItemAPI.action(ik, action, body, options) as V;
|
|
98
108
|
|
|
99
109
|
const all =
|
|
100
110
|
async (
|
|
101
111
|
query: ItemQuery = {} as ItemQuery,
|
|
102
112
|
options: Partial<GetMethodOptions> = {},
|
|
103
113
|
): Promise<V[]> =>
|
|
104
|
-
|
|
114
|
+
await aItemAPI.all(query, options, []) as V[];
|
|
105
115
|
|
|
106
116
|
const allAction =
|
|
107
117
|
async (
|
|
@@ -109,51 +119,67 @@ export const createPItemApi = <
|
|
|
109
119
|
body: any = {},
|
|
110
120
|
options: Partial<PostMethodOptions> = {},
|
|
111
121
|
): Promise<V[]> =>
|
|
112
|
-
|
|
113
|
-
|
|
122
|
+
await aItemAPI.allAction(action, body, options, []) as V[];
|
|
123
|
+
|
|
114
124
|
const one =
|
|
115
125
|
async (
|
|
116
126
|
query: ItemQuery = {} as ItemQuery,
|
|
117
127
|
options: Partial<GetMethodOptions> = {},
|
|
118
128
|
): Promise<V | null> =>
|
|
119
|
-
|
|
120
|
-
|
|
129
|
+
await aItemAPI.one(query, options, []) as V | null;
|
|
130
|
+
|
|
121
131
|
const get =
|
|
122
132
|
async (
|
|
123
133
|
ik: PriKey<S> | ComKey<S, never, never, never, never, never>,
|
|
124
134
|
options: Partial<GetMethodOptions> = {},
|
|
125
135
|
): Promise<V | null> =>
|
|
126
|
-
|
|
127
|
-
|
|
136
|
+
await aItemAPI.get(ik, options) as V | null;
|
|
137
|
+
|
|
128
138
|
const create =
|
|
129
139
|
async (
|
|
130
140
|
item: TypesProperties<V, S>,
|
|
131
141
|
options: Partial<PostMethodOptions> = {},
|
|
132
142
|
): Promise<V> =>
|
|
133
|
-
|
|
134
|
-
|
|
143
|
+
await aItemAPI.create(item, options, []) as V;
|
|
144
|
+
|
|
135
145
|
const remove =
|
|
136
146
|
async (
|
|
137
147
|
ik: PriKey<S> | ComKey<S, never, never, never, never, never>,
|
|
138
148
|
options: Partial<DeleteMethodOptions> = {},
|
|
139
149
|
): Promise<boolean> =>
|
|
140
|
-
|
|
141
|
-
|
|
150
|
+
await aItemAPI.remove(ik, options) as boolean;
|
|
151
|
+
|
|
142
152
|
const update =
|
|
143
153
|
async (
|
|
144
154
|
ik: PriKey<S> | ComKey<S, never, never, never, never, never>,
|
|
145
155
|
item: TypesProperties<V, S>,
|
|
146
156
|
options: Partial<PutMethodOptions> = {},
|
|
147
157
|
): Promise<V> =>
|
|
148
|
-
|
|
149
|
-
|
|
158
|
+
await aItemAPI.update(ik, item, options) as V;
|
|
159
|
+
|
|
160
|
+
const facet =
|
|
161
|
+
async (
|
|
162
|
+
ik: PriKey<S> | ComKey<S, never, never, never, never, never>,
|
|
163
|
+
facet: string,
|
|
164
|
+
options: Partial<GetMethodOptions> = {},
|
|
165
|
+
): Promise<any> =>
|
|
166
|
+
await aItemAPI.facet(ik, facet, options) as any;
|
|
167
|
+
|
|
150
168
|
const find =
|
|
151
169
|
async (
|
|
152
170
|
finder: string,
|
|
153
171
|
finderParams: Record<string, string | number | boolean | Date | Array<string | number | boolean | Date>>,
|
|
154
172
|
options: Partial<GetMethodOptions> = {},
|
|
155
173
|
): Promise<V[]> =>
|
|
156
|
-
|
|
174
|
+
await aItemAPI.find(finder, finderParams, options, []) as V[];
|
|
175
|
+
|
|
176
|
+
const findOne =
|
|
177
|
+
async (
|
|
178
|
+
finder: string,
|
|
179
|
+
finderParams: Record<string, string | number | boolean | Date | Array<string | number | boolean | Date>>,
|
|
180
|
+
options: Partial<GetMethodOptions> = {},
|
|
181
|
+
): Promise<V> =>
|
|
182
|
+
await aItemAPI.findOne(finder, finderParams, options, []) as V;
|
|
157
183
|
|
|
158
184
|
return {
|
|
159
185
|
...aItemAPI,
|
|
@@ -165,7 +191,9 @@ export const createPItemApi = <
|
|
|
165
191
|
create,
|
|
166
192
|
remove,
|
|
167
193
|
update,
|
|
194
|
+
facet,
|
|
168
195
|
find,
|
|
196
|
+
findOne,
|
|
169
197
|
};
|
|
170
198
|
|
|
171
199
|
};
|
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/facet.ts
ADDED
|
@@ -0,0 +1,59 @@
|
|
|
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', 'facet');
|
|
13
|
+
|
|
14
|
+
export const getFacetOperation = <
|
|
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
|
+
/**
|
|
29
|
+
* Executes a facet operation on an item.
|
|
30
|
+
*
|
|
31
|
+
* A facet is a piece of information that is related to an item - it represents
|
|
32
|
+
* a specific aspect or characteristic of the item. Unlike actions which may
|
|
33
|
+
* return items or perform operations, facets are informational queries that
|
|
34
|
+
* return data about a particular facet of an item.
|
|
35
|
+
*
|
|
36
|
+
* @param ik - The item key (composite or primary key) identifying the item
|
|
37
|
+
* @param facet - The name of the facet to query
|
|
38
|
+
* @param body - Optional request body for the facet operation
|
|
39
|
+
* @param options - Optional HTTP request options
|
|
40
|
+
* @returns Promise resolving to the facet data
|
|
41
|
+
*/
|
|
42
|
+
const facet = async (
|
|
43
|
+
ik: ComKey<S, L1, L2, L3, L4, L5> | PriKey<S>,
|
|
44
|
+
facet: string,
|
|
45
|
+
options: Partial<GetMethodOptions> = {}
|
|
46
|
+
): Promise<any> => {
|
|
47
|
+
logger.default('facet', { ik, facet });
|
|
48
|
+
|
|
49
|
+
const requestOptions = Object.assign({}, options, { isAuthenticated: apiOptions.writeAuthenticated });
|
|
50
|
+
|
|
51
|
+
return api.httpGet<any>(
|
|
52
|
+
`${utilities.getPath(ik)}/${facet}`,
|
|
53
|
+
requestOptions,
|
|
54
|
+
);
|
|
55
|
+
|
|
56
|
+
};
|
|
57
|
+
|
|
58
|
+
return facet;
|
|
59
|
+
}
|
|
@@ -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 getFindOneOperation = <
|
|
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 findOne = 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('findOne', { 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
|
+
params.one = true;
|
|
41
|
+
|
|
42
|
+
const requestOptions = Object.assign({}, options, { isAuthenticated: apiOptions.allAuthenticated, params });
|
|
43
|
+
|
|
44
|
+
return (utilities.validatePK(await utilities.processArray(
|
|
45
|
+
api.httpGet<V[]>(
|
|
46
|
+
utilities.getPath(loc),
|
|
47
|
+
requestOptions,
|
|
48
|
+
))) as V[])[0];
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
return findOne;
|
|
52
|
+
}
|
package/src/ops/index.ts
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
/* eslint-disable indent */
|
|
1
2
|
import { Item } from "@fjell/core"
|
|
2
3
|
import { getAllOperation } from "./all"
|
|
3
4
|
import { getActionOperation } from "./action"
|
|
@@ -12,66 +13,78 @@ import { getRemoveOperation } from "./remove"
|
|
|
12
13
|
import { getFindOperation } from "./find"
|
|
13
14
|
import { ClientApiOptions } from "@/ClientApiOptions"
|
|
14
15
|
import { ClientApi } from "@/ClientApi"
|
|
16
|
+
import { getFindOneOperation } from "./findOne"
|
|
17
|
+
import { getFacetOperation } from "./facet"
|
|
15
18
|
|
|
16
19
|
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
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
20
|
+
<
|
|
21
|
+
V extends Item<S, L1, L2, L3, L4, L5>,
|
|
22
|
+
S extends string,
|
|
23
|
+
L1 extends string = never,
|
|
24
|
+
L2 extends string = never,
|
|
25
|
+
L3 extends string = never,
|
|
26
|
+
L4 extends string = never,
|
|
27
|
+
L5 extends string = never>(
|
|
28
|
+
api: HttpApi,
|
|
29
|
+
apiOptions: ClientApiOptions,
|
|
30
|
+
utilities: Utilities<V, S, L1, L2, L3, L4, L5>,
|
|
31
|
+
|
|
32
|
+
): ClientApi<V, S, L1, L2, L3, L4, L5> => {
|
|
33
|
+
return {
|
|
34
|
+
action: getActionOperation<V, S, L1, L2, L3, L4, L5>(
|
|
35
|
+
api,
|
|
36
|
+
apiOptions,
|
|
37
|
+
utilities,
|
|
38
|
+
),
|
|
39
|
+
all: getAllOperation<V, S, L1, L2, L3, L4, L5>(
|
|
40
|
+
api,
|
|
41
|
+
apiOptions,
|
|
42
|
+
utilities,
|
|
43
|
+
),
|
|
44
|
+
allAction: getAllActionOperation<V, S, L1, L2, L3, L4, L5>(
|
|
45
|
+
api,
|
|
46
|
+
apiOptions,
|
|
47
|
+
utilities,
|
|
48
|
+
),
|
|
49
|
+
create: getCreateOperation<V, S, L1, L2, L3, L4, L5>(
|
|
50
|
+
api,
|
|
51
|
+
apiOptions,
|
|
52
|
+
utilities,
|
|
53
|
+
),
|
|
54
|
+
facet: getFacetOperation<V, S, L1, L2, L3, L4, L5>(
|
|
55
|
+
api,
|
|
56
|
+
apiOptions,
|
|
57
|
+
utilities,
|
|
58
|
+
),
|
|
59
|
+
findOne: getFindOneOperation<V, S, L1, L2, L3, L4, L5>(
|
|
60
|
+
api,
|
|
61
|
+
apiOptions,
|
|
62
|
+
utilities,
|
|
63
|
+
),
|
|
64
|
+
find: getFindOperation<V, S, L1, L2, L3, L4, L5>(
|
|
65
|
+
api,
|
|
66
|
+
apiOptions,
|
|
67
|
+
utilities,
|
|
68
|
+
),
|
|
69
|
+
get: getGetOperation<V, S, L1, L2, L3, L4, L5>(
|
|
70
|
+
api,
|
|
71
|
+
apiOptions,
|
|
72
|
+
utilities,
|
|
73
|
+
),
|
|
74
|
+
one: getOneOperation<V, S, L1, L2, L3, L4, L5>(
|
|
75
|
+
api,
|
|
76
|
+
apiOptions,
|
|
77
|
+
utilities,
|
|
78
|
+
),
|
|
79
|
+
remove: getRemoveOperation<V, S, L1, L2, L3, L4, L5>(
|
|
80
|
+
api,
|
|
81
|
+
apiOptions,
|
|
82
|
+
utilities,
|
|
83
|
+
),
|
|
84
|
+
update: getUpdateOperation<V, S, L1, L2, L3, L4, L5>(
|
|
85
|
+
api,
|
|
86
|
+
apiOptions,
|
|
87
|
+
utilities,
|
|
88
|
+
),
|
|
89
|
+
}
|
|
90
|
+
}
|