@fjell/client-api 4.4.1 → 4.4.3
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/dist/AItemAPI.js +8 -1
- package/dist/AItemAPI.js.map +1 -1
- package/dist/CItemAPI.d.ts +12 -9
- package/dist/CItemAPI.js +4 -1
- package/dist/CItemAPI.js.map +1 -1
- package/dist/ClientApi.d.ts +12 -10
- package/dist/ClientApiOptions.d.ts +5 -0
- package/dist/PItemAPI.d.ts +13 -10
- package/dist/PItemAPI.js +16 -10
- package/dist/PItemAPI.js.map +1 -1
- package/dist/index.cjs +173 -73
- package/dist/index.cjs.map +1 -1
- package/dist/ops/action.d.ts +2 -2
- package/dist/ops/action.js +6 -5
- package/dist/ops/action.js.map +1 -1
- package/dist/ops/all.d.ts +2 -2
- package/dist/ops/all.js +7 -6
- package/dist/ops/all.js.map +1 -1
- package/dist/ops/allAction.d.ts +2 -2
- package/dist/ops/allAction.js +6 -5
- package/dist/ops/allAction.js.map +1 -1
- package/dist/ops/allFacet.d.ts +5 -0
- package/dist/ops/allFacet.js +24 -0
- package/dist/ops/allFacet.js.map +1 -0
- package/dist/ops/create.d.ts +2 -2
- package/dist/ops/create.js +6 -5
- package/dist/ops/create.js.map +1 -1
- package/dist/ops/facet.d.ts +5 -0
- package/dist/ops/facet.js +34 -0
- package/dist/ops/facet.js.map +1 -0
- package/dist/ops/find.d.ts +2 -2
- package/dist/ops/find.js +10 -9
- package/dist/ops/find.js.map +1 -1
- package/dist/ops/findOne.d.ts +5 -0
- package/dist/ops/findOne.js +27 -0
- package/dist/ops/findOne.js.map +1 -0
- package/dist/ops/get.d.ts +2 -2
- package/dist/ops/get.js +6 -5
- package/dist/ops/get.js.map +1 -1
- package/dist/ops/index.js +6 -0
- package/dist/ops/index.js.map +1 -1
- package/dist/ops/one.d.ts +2 -2
- package/dist/ops/one.js +7 -6
- package/dist/ops/one.js.map +1 -1
- package/dist/ops/remove.d.ts +2 -2
- package/dist/ops/remove.js +6 -5
- package/dist/ops/remove.js.map +1 -1
- package/dist/ops/update.d.ts +2 -2
- package/dist/ops/update.js +6 -5
- package/dist/ops/update.js.map +1 -1
- package/dist/util/general.d.ts +4 -0
- package/package.json +6 -6
- package/src/AItemAPI.ts +17 -9
- package/src/CItemAPI.ts +22 -16
- package/src/ClientApi.ts +59 -54
- package/src/ClientApiOptions.ts +5 -0
- package/src/PItemAPI.ts +56 -42
- package/src/ops/action.ts +19 -23
- package/src/ops/all.ts +17 -19
- package/src/ops/allAction.ts +18 -21
- package/src/ops/allFacet.ts +46 -0
- package/src/ops/create.ts +21 -23
- package/src/ops/facet.ts +58 -0
- package/src/ops/find.ts +20 -23
- package/src/ops/findOne.ts +51 -0
- package/src/ops/get.ts +17 -20
- package/src/ops/index.ts +80 -61
- package/src/ops/one.ts +3 -5
- package/src/ops/remove.ts +17 -20
- package/src/ops/update.ts +17 -19
- package/src/util/general.ts +65 -0
package/src/ClientApi.ts
CHANGED
|
@@ -1,59 +1,64 @@
|
|
|
1
1
|
import { ComKey, Item, ItemQuery, LocKeyArray, PriKey, TypesProperties } from "@fjell/core";
|
|
2
|
-
import { DeleteMethodOptions, GetMethodOptions, PostMethodOptions, PutMethodOptions } from "@fjell/http-api";
|
|
3
2
|
|
|
4
3
|
export interface ClientApi<
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
4
|
+
V extends Item<S, L1, L2, L3, L4, L5>,
|
|
5
|
+
S extends string,
|
|
6
|
+
L1 extends string = never,
|
|
7
|
+
L2 extends string = never,
|
|
8
|
+
L3 extends string = never,
|
|
9
|
+
L4 extends string = never,
|
|
10
|
+
L5 extends string = never
|
|
12
11
|
> {
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
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
|
-
|
|
12
|
+
action: (
|
|
13
|
+
ik: ComKey<S, L1, L2, L3, L4, L5> | PriKey<S>,
|
|
14
|
+
action: string,
|
|
15
|
+
body?: any,
|
|
16
|
+
) => Promise<V>;
|
|
17
|
+
all: (
|
|
18
|
+
query: ItemQuery,
|
|
19
|
+
locations?: LocKeyArray<L1, L2, L3, L4, L5> | []
|
|
20
|
+
) => Promise<V[]>;
|
|
21
|
+
allAction: (
|
|
22
|
+
action: string,
|
|
23
|
+
body?: any,
|
|
24
|
+
locations?: LocKeyArray<L1, L2, L3, L4, L5> | []
|
|
25
|
+
) => Promise<V[]>;
|
|
26
|
+
allFacet: (
|
|
27
|
+
facet: string,
|
|
28
|
+
params?: Record<string, string | number | boolean | Date | Array<string | number | boolean | Date>>,
|
|
29
|
+
locations?: LocKeyArray<L1, L2, L3, L4, L5> | []
|
|
30
|
+
) => Promise<any>;
|
|
31
|
+
create: (
|
|
32
|
+
item: TypesProperties<V, S, L1, L2, L3, L4, L5>,
|
|
33
|
+
locations?: LocKeyArray<L1, L2, L3, L4, L5> | []
|
|
34
|
+
) => Promise<V>;
|
|
35
|
+
facet: (
|
|
36
|
+
ik: ComKey<S, L1, L2, L3, L4, L5> | PriKey<S>,
|
|
37
|
+
facet: string,
|
|
38
|
+
params?: Record<string, string | number | boolean | Date | Array<string | number | boolean | Date>>,
|
|
39
|
+
) => Promise<any>;
|
|
40
|
+
find: (
|
|
41
|
+
finder: string,
|
|
42
|
+
finderParams?: Record<string, string | number | boolean | Date | Array<string | number | boolean | Date>>,
|
|
43
|
+
locations?: LocKeyArray<L1, L2, L3, L4, L5> | []
|
|
44
|
+
) => Promise<V[]>;
|
|
45
|
+
findOne: (
|
|
46
|
+
finder: string,
|
|
47
|
+
finderParams?: Record<string, string | number | boolean | Date | Array<string | number | boolean | Date>>,
|
|
48
|
+
locations?: LocKeyArray<L1, L2, L3, L4, L5> | []
|
|
49
|
+
) => Promise<V>;
|
|
50
|
+
get: (
|
|
51
|
+
ik: ComKey<S, L1, L2, L3, L4, L5> | PriKey<S>,
|
|
52
|
+
) => Promise<V | null>;
|
|
53
|
+
one: (
|
|
54
|
+
query: ItemQuery,
|
|
55
|
+
locations?: LocKeyArray<L1, L2, L3, L4, L5> | []
|
|
56
|
+
) => Promise<V | null>;
|
|
57
|
+
remove: (
|
|
58
|
+
ik: ComKey<S, L1, L2, L3, L4, L5> | PriKey<S>,
|
|
59
|
+
) => Promise<boolean>;
|
|
60
|
+
update: (
|
|
61
|
+
ik: ComKey<S, L1, L2, L3, L4, L5> | PriKey<S>,
|
|
62
|
+
item: TypesProperties<V, S, L1, L2, L3, L4, L5>,
|
|
63
|
+
) => Promise<V>;
|
|
59
64
|
}
|
package/src/ClientApiOptions.ts
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { Item } from "@fjell/core";
|
|
2
2
|
import { ClientApi } from "./ClientApi";
|
|
3
|
+
import { DeleteMethodOptions, GetMethodOptions, PostMethodOptions, PutMethodOptions } from "@fjell/http-api";
|
|
3
4
|
|
|
4
5
|
export interface ClientApiOptions {
|
|
5
6
|
readAuthenticated?: boolean;
|
|
@@ -14,4 +15,8 @@ export interface ClientApiOptions {
|
|
|
14
15
|
string | never,
|
|
15
16
|
string | never
|
|
16
17
|
>;
|
|
18
|
+
getOptions?: Partial<GetMethodOptions>;
|
|
19
|
+
postOptions?: Partial<PostMethodOptions>;
|
|
20
|
+
putOptions?: Partial<PutMethodOptions>;
|
|
21
|
+
deleteOptions?: Partial<DeleteMethodOptions>;
|
|
17
22
|
}
|
package/src/PItemAPI.ts
CHANGED
|
@@ -1,13 +1,11 @@
|
|
|
1
|
-
/* eslint-disable @typescript-eslint/no-unused-vars */
|
|
2
1
|
|
|
3
|
-
import { ComKey, Item,
|
|
2
|
+
import { ComKey, Item, ItemQuery, PriKey, TypesProperties } from "@fjell/core";
|
|
4
3
|
import { HttpApi } from "@fjell/http-api";
|
|
5
|
-
import { createAItemAPI
|
|
4
|
+
import { createAItemAPI } from "./AItemAPI";
|
|
6
5
|
import { ClientApi } from "./ClientApi";
|
|
7
6
|
|
|
8
|
-
import { DeleteMethodOptions, GetMethodOptions, PostMethodOptions, PutMethodOptions } from "@fjell/http-api";
|
|
9
|
-
import { ClientApiOptions } from "./ClientApiOptions";
|
|
10
7
|
import LibLogger from "@/logger";
|
|
8
|
+
import { ClientApiOptions } from "./ClientApiOptions";
|
|
11
9
|
const logger = LibLogger.get('PItemAPI');
|
|
12
10
|
|
|
13
11
|
export interface PItemApi<
|
|
@@ -19,58 +17,58 @@ export interface PItemApi<
|
|
|
19
17
|
ik: PriKey<S> | ComKey<S, never, never, never, never, never>,
|
|
20
18
|
action: string,
|
|
21
19
|
body: any,
|
|
22
|
-
options?: Partial<PostMethodOptions>,
|
|
23
|
-
locations?: []
|
|
24
20
|
) => Promise<V>;
|
|
25
21
|
|
|
26
22
|
all: (
|
|
27
23
|
query: ItemQuery,
|
|
28
|
-
options?: Partial<GetMethodOptions>,
|
|
29
|
-
locations?: []
|
|
30
24
|
) => Promise<V[]>;
|
|
31
25
|
|
|
32
26
|
allAction: (
|
|
33
27
|
action: string,
|
|
34
|
-
body
|
|
35
|
-
options?: Partial<PostMethodOptions>
|
|
28
|
+
body?: any,
|
|
36
29
|
) => Promise<V[]>;
|
|
37
30
|
|
|
31
|
+
allFacet: (
|
|
32
|
+
facet: string,
|
|
33
|
+
params?: Record<string, string | number | boolean | Date | Array<string | number | boolean | Date>>,
|
|
34
|
+
) => Promise<any>;
|
|
35
|
+
|
|
38
36
|
one: (
|
|
39
37
|
query: ItemQuery,
|
|
40
|
-
options?: Partial<GetMethodOptions>
|
|
41
38
|
) => Promise<V | null>;
|
|
42
39
|
|
|
43
40
|
get: (
|
|
44
41
|
ik: PriKey<S> | ComKey<S, never, never, never, never, never>,
|
|
45
|
-
options?: Partial<GetMethodOptions>,
|
|
46
|
-
locations?: []
|
|
47
42
|
) => Promise<V | null>;
|
|
48
43
|
|
|
49
44
|
create: (
|
|
50
45
|
item: TypesProperties<V, S>,
|
|
51
|
-
options?: Partial<PostMethodOptions>,
|
|
52
|
-
locations?: []
|
|
53
46
|
) => Promise<V>;
|
|
54
47
|
|
|
55
48
|
remove: (
|
|
56
49
|
ik: PriKey<S> | ComKey<S, never, never, never, never, never>,
|
|
57
|
-
options?: Partial<DeleteMethodOptions>,
|
|
58
|
-
locations?: []
|
|
59
50
|
) => Promise<boolean>;
|
|
60
51
|
|
|
61
52
|
update: (
|
|
62
53
|
ik: PriKey<S> | ComKey<S, never, never, never, never, never>,
|
|
63
54
|
item: TypesProperties<V, S>,
|
|
64
|
-
options?: Partial<PutMethodOptions>,
|
|
65
|
-
locations?: []
|
|
66
55
|
) => Promise<V>;
|
|
67
56
|
|
|
57
|
+
facet: (
|
|
58
|
+
ik: PriKey<S> | ComKey<S, never, never, never, never, never>,
|
|
59
|
+
facet: string,
|
|
60
|
+
params?: Record<string, string | number | boolean | Date | Array<string | number | boolean | Date>>,
|
|
61
|
+
) => Promise<any>;
|
|
62
|
+
|
|
68
63
|
find: (
|
|
69
64
|
finder: string,
|
|
70
|
-
finderParams
|
|
71
|
-
options?: Partial<GetMethodOptions>,
|
|
72
|
-
locations?: []
|
|
65
|
+
finderParams?: Record<string, string | number | boolean | Date | Array<string | number | boolean | Date>>,
|
|
73
66
|
) => Promise<V[]>;
|
|
67
|
+
|
|
68
|
+
findOne: (
|
|
69
|
+
finder: string,
|
|
70
|
+
finderParams?: Record<string, string | number | boolean | Date | Array<string | number | boolean | Date>>,
|
|
71
|
+
) => Promise<V>;
|
|
74
72
|
}
|
|
75
73
|
|
|
76
74
|
export const createPItemApi = <V extends Item<S>, S extends string>(
|
|
@@ -89,80 +87,96 @@ export const createPItemApi = <V extends Item<S>, S extends string>(
|
|
|
89
87
|
ik: PriKey<S> | ComKey<S, never, never, never, never, never>,
|
|
90
88
|
action: string,
|
|
91
89
|
body: any = {},
|
|
92
|
-
options: Partial<PostMethodOptions> = {},
|
|
93
90
|
): Promise<V> =>
|
|
94
|
-
await aItemAPI.action(ik, action, body
|
|
91
|
+
await aItemAPI.action(ik, action, body) as V;
|
|
95
92
|
|
|
96
93
|
const all =
|
|
97
94
|
async (
|
|
98
95
|
query: ItemQuery = {} as ItemQuery,
|
|
99
|
-
options: Partial<GetMethodOptions> = {},
|
|
100
96
|
): Promise<V[]> =>
|
|
101
|
-
await aItemAPI.all(query,
|
|
97
|
+
await aItemAPI.all(query, []) as V[];
|
|
102
98
|
|
|
103
99
|
const allAction =
|
|
104
100
|
async (
|
|
105
101
|
action: string,
|
|
106
102
|
body: any = {},
|
|
107
|
-
options: Partial<PostMethodOptions> = {},
|
|
108
103
|
): Promise<V[]> =>
|
|
109
|
-
await aItemAPI.allAction(action, body,
|
|
104
|
+
await aItemAPI.allAction(action, body, []) as V[];
|
|
105
|
+
|
|
106
|
+
const allFacet =
|
|
107
|
+
async (
|
|
108
|
+
facet: string,
|
|
109
|
+
params: Record<string, string | number | boolean | Date | Array<string | number | boolean | Date>> = {},
|
|
110
|
+
): Promise<any> =>
|
|
111
|
+
await aItemAPI.allFacet(facet, params) as any;
|
|
110
112
|
|
|
111
113
|
const one =
|
|
112
114
|
async (
|
|
113
115
|
query: ItemQuery = {} as ItemQuery,
|
|
114
|
-
options: Partial<GetMethodOptions> = {},
|
|
115
116
|
): Promise<V | null> =>
|
|
116
|
-
await aItemAPI.one(query,
|
|
117
|
+
await aItemAPI.one(query, []) as V | null;
|
|
117
118
|
|
|
118
119
|
const get =
|
|
119
120
|
async (
|
|
120
121
|
ik: PriKey<S> | ComKey<S, never, never, never, never, never>,
|
|
121
|
-
options: Partial<GetMethodOptions> = {},
|
|
122
122
|
): Promise<V | null> =>
|
|
123
|
-
await aItemAPI.get(ik
|
|
123
|
+
await aItemAPI.get(ik) as V | null;
|
|
124
124
|
|
|
125
125
|
const create =
|
|
126
126
|
async (
|
|
127
127
|
item: TypesProperties<V, S>,
|
|
128
|
-
options: Partial<PostMethodOptions> = {},
|
|
129
128
|
): Promise<V> =>
|
|
130
|
-
await aItemAPI.create(item,
|
|
129
|
+
await aItemAPI.create(item, []) as V;
|
|
131
130
|
|
|
132
131
|
const remove =
|
|
133
132
|
async (
|
|
134
133
|
ik: PriKey<S> | ComKey<S, never, never, never, never, never>,
|
|
135
|
-
options: Partial<DeleteMethodOptions> = {},
|
|
136
134
|
): Promise<boolean> =>
|
|
137
|
-
await aItemAPI.remove(ik
|
|
135
|
+
await aItemAPI.remove(ik) as boolean;
|
|
138
136
|
|
|
139
137
|
const update =
|
|
140
138
|
async (
|
|
141
139
|
ik: PriKey<S> | ComKey<S, never, never, never, never, never>,
|
|
142
140
|
item: TypesProperties<V, S>,
|
|
143
|
-
options: Partial<PutMethodOptions> = {},
|
|
144
141
|
): Promise<V> =>
|
|
145
|
-
await aItemAPI.update(ik, item
|
|
142
|
+
await aItemAPI.update(ik, item) as V;
|
|
143
|
+
|
|
144
|
+
const facet =
|
|
145
|
+
async (
|
|
146
|
+
ik: PriKey<S> | ComKey<S, never, never, never, never, never>,
|
|
147
|
+
facet: string,
|
|
148
|
+
params: Record<string, string | number | boolean | Date | Array<string | number | boolean | Date>> = {},
|
|
149
|
+
): Promise<any> =>
|
|
150
|
+
await aItemAPI.facet(ik, facet, params) as any;
|
|
146
151
|
|
|
147
152
|
const find =
|
|
148
153
|
async (
|
|
149
154
|
finder: string,
|
|
150
|
-
finderParams: Record<string, string | number | boolean | Date | Array<string | number | boolean | Date
|
|
151
|
-
options: Partial<GetMethodOptions> = {},
|
|
155
|
+
finderParams: Record<string, string | number | boolean | Date | Array<string | number | boolean | Date>> = {},
|
|
152
156
|
): Promise<V[]> =>
|
|
153
|
-
await aItemAPI.find(finder, finderParams
|
|
157
|
+
await aItemAPI.find(finder, finderParams) as V[];
|
|
158
|
+
|
|
159
|
+
const findOne =
|
|
160
|
+
async (
|
|
161
|
+
finder: string,
|
|
162
|
+
finderParams: Record<string, string | number | boolean | Date | Array<string | number | boolean | Date>> = {},
|
|
163
|
+
): Promise<V> =>
|
|
164
|
+
await aItemAPI.findOne(finder, finderParams) as V;
|
|
154
165
|
|
|
155
166
|
return {
|
|
156
167
|
...aItemAPI,
|
|
157
168
|
action,
|
|
158
169
|
all,
|
|
159
170
|
allAction,
|
|
171
|
+
allFacet,
|
|
160
172
|
one,
|
|
161
173
|
get,
|
|
162
174
|
create,
|
|
163
175
|
remove,
|
|
164
176
|
update,
|
|
177
|
+
facet,
|
|
165
178
|
find,
|
|
179
|
+
findOne,
|
|
166
180
|
};
|
|
167
181
|
|
|
168
182
|
};
|
package/src/ops/action.ts
CHANGED
|
@@ -3,39 +3,36 @@ import {
|
|
|
3
3
|
Item,
|
|
4
4
|
PriKey,
|
|
5
5
|
} from "@fjell/core";
|
|
6
|
-
import { HttpApi
|
|
7
|
-
|
|
6
|
+
import { HttpApi } from "@fjell/http-api";
|
|
7
|
+
|
|
8
8
|
import { ClientApiOptions } from "@/ClientApiOptions";
|
|
9
9
|
import LibLogger from "@/logger";
|
|
10
10
|
import { Utilities } from "@/Utilities";
|
|
11
|
-
|
|
11
|
+
|
|
12
12
|
const logger = LibLogger.get('client-api', 'ops', 'action');
|
|
13
|
-
|
|
13
|
+
|
|
14
14
|
export const getActionOperation = <
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
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
22
|
api: HttpApi,
|
|
23
23
|
apiOptions: ClientApiOptions,
|
|
24
24
|
utilities: Utilities<V, S, L1, L2, L3, L4, L5>
|
|
25
|
-
|
|
25
|
+
|
|
26
26
|
) => {
|
|
27
|
-
|
|
27
|
+
|
|
28
28
|
const action = async (
|
|
29
29
|
ik: ComKey<S, L1, L2, L3, L4, L5> | PriKey<S>,
|
|
30
30
|
action: string,
|
|
31
31
|
body: any = {},
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
const requestOptions = Object.assign({}, options, { isAuthenticated: apiOptions.writeAuthenticated });
|
|
38
|
-
|
|
32
|
+
): Promise<V> => {
|
|
33
|
+
const requestOptions = Object.assign({}, apiOptions.postOptions, { isAuthenticated: apiOptions.writeAuthenticated });
|
|
34
|
+
logger.default('action', { ik, action, body, requestOptions });
|
|
35
|
+
|
|
39
36
|
return utilities.validatePK(
|
|
40
37
|
await utilities.processOne(
|
|
41
38
|
api.httpPost<V>(
|
|
@@ -44,9 +41,8 @@ export const getActionOperation = <
|
|
|
44
41
|
requestOptions,
|
|
45
42
|
)
|
|
46
43
|
)) as V;
|
|
47
|
-
|
|
44
|
+
|
|
48
45
|
};
|
|
49
|
-
|
|
46
|
+
|
|
50
47
|
return action;
|
|
51
48
|
}
|
|
52
|
-
|
package/src/ops/all.ts
CHANGED
|
@@ -5,41 +5,39 @@ import {
|
|
|
5
5
|
queryToParams,
|
|
6
6
|
} from "@fjell/core";
|
|
7
7
|
import { HttpApi, QueryParams } from "@fjell/http-api";
|
|
8
|
-
|
|
8
|
+
|
|
9
9
|
import { ClientApiOptions } from "@/ClientApiOptions";
|
|
10
10
|
import LibLogger from "@/logger";
|
|
11
11
|
import { Utilities } from "@/Utilities";
|
|
12
|
-
|
|
13
|
-
|
|
12
|
+
|
|
14
13
|
const logger = LibLogger.get('client-api', 'ops', 'all');
|
|
15
14
|
|
|
16
15
|
export const getAllOperation = <
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
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>(
|
|
24
23
|
api: HttpApi,
|
|
25
24
|
apiOptions: ClientApiOptions,
|
|
26
25
|
utilities: Utilities<V, S, L1, L2, L3, L4, L5>
|
|
27
|
-
|
|
26
|
+
|
|
28
27
|
) => {
|
|
29
|
-
|
|
28
|
+
|
|
30
29
|
const all = async (
|
|
31
30
|
query: ItemQuery = {} as ItemQuery,
|
|
32
|
-
options: Partial<GetMethodOptions> = {},
|
|
33
31
|
locations: LocKeyArray<L1, L2, L3, L4, L5> | [] = []
|
|
34
32
|
): Promise<V[]> => {
|
|
35
|
-
logger.default('all', { query, locations });
|
|
36
33
|
utilities.verifyLocations(locations);
|
|
37
34
|
const loc: LocKeyArray<L1, L2, L3, L4, L5> | [] = locations;
|
|
38
|
-
|
|
35
|
+
|
|
39
36
|
const params: QueryParams = queryToParams(query);
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
37
|
+
const requestOptions = Object.assign({}, apiOptions.getOptions, { isAuthenticated: apiOptions.allAuthenticated, params });
|
|
38
|
+
|
|
39
|
+
logger.default('all', { query, locations, requestOptions });
|
|
40
|
+
|
|
43
41
|
return utilities.validatePK(await utilities.processArray(
|
|
44
42
|
api.httpGet<V[]>(
|
|
45
43
|
utilities.getPath(loc),
|
|
@@ -49,4 +47,4 @@ export const getAllOperation = <
|
|
|
49
47
|
|
|
50
48
|
return all;
|
|
51
49
|
}
|
|
52
|
-
|
|
50
|
+
|
package/src/ops/allAction.ts
CHANGED
|
@@ -2,41 +2,39 @@ import {
|
|
|
2
2
|
Item,
|
|
3
3
|
LocKeyArray
|
|
4
4
|
} from "@fjell/core";
|
|
5
|
-
import { HttpApi
|
|
6
|
-
|
|
5
|
+
import { HttpApi } from "@fjell/http-api";
|
|
6
|
+
|
|
7
7
|
import { ClientApiOptions } from "@/ClientApiOptions";
|
|
8
8
|
import LibLogger from "@/logger";
|
|
9
9
|
import { Utilities } from "@/Utilities";
|
|
10
|
-
|
|
10
|
+
|
|
11
11
|
const logger = LibLogger.get('client-api', 'ops', 'allAction');
|
|
12
|
-
|
|
12
|
+
|
|
13
13
|
export const getAllActionOperation = <
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
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
21
|
api: HttpApi,
|
|
22
22
|
apiOptions: ClientApiOptions,
|
|
23
23
|
utilities: Utilities<V, S, L1, L2, L3, L4, L5>
|
|
24
|
-
|
|
24
|
+
|
|
25
25
|
) => {
|
|
26
|
-
|
|
26
|
+
|
|
27
27
|
const allAction = async (
|
|
28
28
|
action: string,
|
|
29
29
|
body: any = {},
|
|
30
|
-
options: Partial<PostMethodOptions> = {},
|
|
31
30
|
locations: LocKeyArray<L1, L2, L3, L4, L5> | [] = []
|
|
32
31
|
): Promise<V[]> => {
|
|
33
|
-
|
|
32
|
+
const requestOptions = Object.assign({}, apiOptions.postOptions, { isAuthenticated: apiOptions.writeAuthenticated });
|
|
33
|
+
logger.default('allAction', { action, body, locations, requestOptions });
|
|
34
34
|
utilities.verifyLocations(locations);
|
|
35
|
-
|
|
35
|
+
|
|
36
36
|
const loc: LocKeyArray<L1, L2, L3, L4, L5> | [] = locations;
|
|
37
|
-
|
|
38
|
-
const requestOptions = Object.assign({}, options, { isAuthenticated: apiOptions.writeAuthenticated });
|
|
39
|
-
|
|
37
|
+
|
|
40
38
|
// TODO: This should respond to either a single object, or multiple objects in an array.
|
|
41
39
|
return utilities.validatePK(
|
|
42
40
|
await utilities.processArray(
|
|
@@ -47,7 +45,6 @@ export const getAllActionOperation = <
|
|
|
47
45
|
)
|
|
48
46
|
)) as V[];
|
|
49
47
|
};
|
|
50
|
-
|
|
48
|
+
|
|
51
49
|
return allAction;
|
|
52
50
|
}
|
|
53
|
-
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
import {
|
|
2
|
+
Item,
|
|
3
|
+
LocKeyArray
|
|
4
|
+
} from "@fjell/core";
|
|
5
|
+
import { HttpApi } 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', 'allFacet');
|
|
12
|
+
|
|
13
|
+
export const getAllFacetOperation = <
|
|
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 allFacet = async (
|
|
28
|
+
facet: string,
|
|
29
|
+
params: Record<string, string | number | boolean | Date | Array<string | number | boolean | Date>> = {},
|
|
30
|
+
locations: LocKeyArray<L1, L2, L3, L4, L5> | [] = []
|
|
31
|
+
): Promise<V[]> => {
|
|
32
|
+
const requestOptions = Object.assign({}, apiOptions.getOptions, { isAuthenticated: apiOptions.writeAuthenticated, params });
|
|
33
|
+
logger.default('allFacet', { facet, locations, requestOptions });
|
|
34
|
+
utilities.verifyLocations(locations);
|
|
35
|
+
|
|
36
|
+
const loc: LocKeyArray<L1, L2, L3, L4, L5> | [] = locations;
|
|
37
|
+
|
|
38
|
+
// TODO: This should respond to either a single object, or multiple objects in an array.
|
|
39
|
+
return api.httpGet<V[]>(
|
|
40
|
+
utilities.getPath(loc),
|
|
41
|
+
requestOptions,
|
|
42
|
+
)
|
|
43
|
+
};
|
|
44
|
+
|
|
45
|
+
return allFacet;
|
|
46
|
+
}
|
package/src/ops/create.ts
CHANGED
|
@@ -3,48 +3,46 @@ import {
|
|
|
3
3
|
ItemProperties,
|
|
4
4
|
LocKeyArray
|
|
5
5
|
} from "@fjell/core";
|
|
6
|
-
import { HttpApi
|
|
7
|
-
|
|
6
|
+
import { HttpApi } from "@fjell/http-api";
|
|
7
|
+
|
|
8
8
|
import { ClientApiOptions } from "@/ClientApiOptions";
|
|
9
9
|
import LibLogger from "@/logger";
|
|
10
10
|
import { Utilities } from "@/Utilities";
|
|
11
|
-
|
|
11
|
+
|
|
12
12
|
const logger = LibLogger.get('client-api', 'ops', 'create');
|
|
13
13
|
|
|
14
14
|
export const getCreateOperation = <
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
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
22
|
api: HttpApi,
|
|
23
23
|
apiOptions: ClientApiOptions,
|
|
24
24
|
utilities: Utilities<V, S, L1, L2, L3, L4, L5>
|
|
25
|
-
|
|
25
|
+
|
|
26
26
|
) => {
|
|
27
|
-
|
|
27
|
+
|
|
28
28
|
const create = async (
|
|
29
29
|
item: ItemProperties<S, L1, L2, L3, L4, L5>,
|
|
30
|
-
options: Partial<PostMethodOptions> = {},
|
|
31
30
|
locations: LocKeyArray<L1, L2, L3, L4, L5> | [] = []
|
|
32
31
|
): Promise<V> => {
|
|
33
|
-
|
|
32
|
+
const requestOptions = Object.assign({}, apiOptions.postOptions, { isAuthenticated: apiOptions.writeAuthenticated });
|
|
33
|
+
logger.default('create', { item, locations, requestOptions });
|
|
34
34
|
utilities.verifyLocations(locations);
|
|
35
|
-
|
|
35
|
+
|
|
36
36
|
const loc: LocKeyArray<L1, L2, L3, L4, L5> | [] = locations;
|
|
37
|
-
|
|
38
|
-
|
|
37
|
+
|
|
39
38
|
const created: V =
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
39
|
+
utilities.validatePK(await utilities.processOne(api.httpPost<V>(
|
|
40
|
+
utilities.getPath(loc),
|
|
41
|
+
item,
|
|
42
|
+
requestOptions,
|
|
43
|
+
))) as V;
|
|
45
44
|
return created;
|
|
46
45
|
};
|
|
47
46
|
|
|
48
47
|
return create;
|
|
49
48
|
}
|
|
50
|
-
|