@fjell/client-api 4.4.4 → 4.4.6
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.map +1 -1
- package/dist/Utilities.js.map +1 -1
- package/dist/index.cjs.map +1 -1
- package/dist/ops/action.js.map +1 -1
- package/dist/ops/all.js.map +1 -1
- package/dist/ops/allAction.js.map +1 -1
- package/dist/ops/allFacet.js.map +1 -1
- package/dist/ops/create.js.map +1 -1
- package/dist/ops/facet.js.map +1 -1
- package/dist/ops/find.js.map +1 -1
- package/dist/ops/findOne.js.map +1 -1
- package/dist/ops/get.js.map +1 -1
- package/dist/ops/one.js.map +1 -1
- package/dist/ops/remove.js.map +1 -1
- package/dist/ops/update.js.map +1 -1
- package/package.json +16 -16
- package/.kodrdriv/config.yaml +0 -14
- package/.kodrdriv/context/content.md +0 -1
- package/babel.config.cjs +0 -14
- package/commit.sh +0 -8
- package/release.sh +0 -89
- package/src/AItemAPI.ts +0 -95
- package/src/CItemAPI.ts +0 -107
- package/src/ClientApi.ts +0 -64
- package/src/ClientApiOptions.ts +0 -22
- package/src/PItemAPI.ts +0 -181
- package/src/Utilities.ts +0 -183
- package/src/index.ts +0 -7
- package/src/logger.ts +0 -5
- package/src/ops/action.ts +0 -48
- package/src/ops/all.ts +0 -50
- package/src/ops/allAction.ts +0 -50
- package/src/ops/allFacet.ts +0 -46
- package/src/ops/create.ts +0 -47
- package/src/ops/facet.ts +0 -58
- package/src/ops/find.ts +0 -49
- package/src/ops/findOne.ts +0 -51
- package/src/ops/get.ts +0 -42
- package/src/ops/index.ts +0 -96
- package/src/ops/one.ts +0 -61
- package/src/ops/remove.ts +0 -38
- package/src/ops/update.ts +0 -44
- package/src/util/general.ts +0 -65
package/src/Utilities.ts
DELETED
|
@@ -1,183 +0,0 @@
|
|
|
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
DELETED
|
@@ -1,7 +0,0 @@
|
|
|
1
|
-
export type { CItemApi } from "./CItemAPI";
|
|
2
|
-
export type { PItemApi } from "./PItemAPI";
|
|
3
|
-
export type { ClientApi } from "./ClientApi";
|
|
4
|
-
export type { ClientApiOptions } from "./ClientApiOptions";
|
|
5
|
-
|
|
6
|
-
export { createCItemApi } from "./CItemAPI";
|
|
7
|
-
export { createPItemApi } from "./PItemAPI";
|
package/src/logger.ts
DELETED
package/src/ops/action.ts
DELETED
|
@@ -1,48 +0,0 @@
|
|
|
1
|
-
import {
|
|
2
|
-
ComKey,
|
|
3
|
-
Item,
|
|
4
|
-
PriKey,
|
|
5
|
-
} from "@fjell/core";
|
|
6
|
-
import { 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', '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
|
-
): Promise<V> => {
|
|
33
|
-
const requestOptions = Object.assign({}, apiOptions.postOptions, { isAuthenticated: apiOptions.writeAuthenticated });
|
|
34
|
-
logger.default('action', { ik, action, body, requestOptions });
|
|
35
|
-
|
|
36
|
-
return utilities.validatePK(
|
|
37
|
-
await utilities.processOne(
|
|
38
|
-
api.httpPost<V>(
|
|
39
|
-
`${utilities.getPath(ik)}/${action}`,
|
|
40
|
-
body,
|
|
41
|
-
requestOptions,
|
|
42
|
-
)
|
|
43
|
-
)) as V;
|
|
44
|
-
|
|
45
|
-
};
|
|
46
|
-
|
|
47
|
-
return action;
|
|
48
|
-
}
|
package/src/ops/all.ts
DELETED
|
@@ -1,50 +0,0 @@
|
|
|
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
|
-
|
|
13
|
-
const logger = LibLogger.get('client-api', 'ops', 'all');
|
|
14
|
-
|
|
15
|
-
export const getAllOperation = <
|
|
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 all = async (
|
|
30
|
-
query: ItemQuery = {} as ItemQuery,
|
|
31
|
-
locations: LocKeyArray<L1, L2, L3, L4, L5> | [] = []
|
|
32
|
-
): Promise<V[]> => {
|
|
33
|
-
utilities.verifyLocations(locations);
|
|
34
|
-
const loc: LocKeyArray<L1, L2, L3, L4, L5> | [] = locations;
|
|
35
|
-
|
|
36
|
-
const params: QueryParams = queryToParams(query);
|
|
37
|
-
const requestOptions = Object.assign({}, apiOptions.getOptions, { isAuthenticated: apiOptions.allAuthenticated, params });
|
|
38
|
-
|
|
39
|
-
logger.default('all', { query, locations, requestOptions });
|
|
40
|
-
|
|
41
|
-
return utilities.validatePK(await utilities.processArray(
|
|
42
|
-
api.httpGet<V[]>(
|
|
43
|
-
utilities.getPath(loc),
|
|
44
|
-
requestOptions,
|
|
45
|
-
))) as V[];
|
|
46
|
-
}
|
|
47
|
-
|
|
48
|
-
return all;
|
|
49
|
-
}
|
|
50
|
-
|
package/src/ops/allAction.ts
DELETED
|
@@ -1,50 +0,0 @@
|
|
|
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', '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
|
-
locations: LocKeyArray<L1, L2, L3, L4, L5> | [] = []
|
|
31
|
-
): Promise<V[]> => {
|
|
32
|
-
const requestOptions = Object.assign({}, apiOptions.postOptions, { isAuthenticated: apiOptions.writeAuthenticated });
|
|
33
|
-
logger.default('allAction', { action, body, 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 utilities.validatePK(
|
|
40
|
-
await utilities.processArray(
|
|
41
|
-
api.httpPost<V[]>(
|
|
42
|
-
utilities.getPath(loc),
|
|
43
|
-
body,
|
|
44
|
-
requestOptions,
|
|
45
|
-
)
|
|
46
|
-
)) as V[];
|
|
47
|
-
};
|
|
48
|
-
|
|
49
|
-
return allAction;
|
|
50
|
-
}
|
package/src/ops/allFacet.ts
DELETED
|
@@ -1,46 +0,0 @@
|
|
|
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
DELETED
|
@@ -1,47 +0,0 @@
|
|
|
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', 'create');
|
|
12
|
-
|
|
13
|
-
export const getCreateOperation = <
|
|
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 create = async (
|
|
28
|
-
item: Partial<Item<S, L1, L2, L3, L4, L5>>,
|
|
29
|
-
locations: LocKeyArray<L1, L2, L3, L4, L5> | [] = []
|
|
30
|
-
): Promise<V> => {
|
|
31
|
-
const requestOptions = Object.assign({}, apiOptions.postOptions, { isAuthenticated: apiOptions.writeAuthenticated });
|
|
32
|
-
logger.default('create', { item, locations, requestOptions });
|
|
33
|
-
utilities.verifyLocations(locations);
|
|
34
|
-
|
|
35
|
-
const loc: LocKeyArray<L1, L2, L3, L4, L5> | [] = locations;
|
|
36
|
-
|
|
37
|
-
const created: V =
|
|
38
|
-
utilities.validatePK(await utilities.processOne(api.httpPost<V>(
|
|
39
|
-
utilities.getPath(loc),
|
|
40
|
-
item,
|
|
41
|
-
requestOptions,
|
|
42
|
-
))) as V;
|
|
43
|
-
return created;
|
|
44
|
-
};
|
|
45
|
-
|
|
46
|
-
return create;
|
|
47
|
-
}
|
package/src/ops/facet.ts
DELETED
|
@@ -1,58 +0,0 @@
|
|
|
1
|
-
import {
|
|
2
|
-
ComKey,
|
|
3
|
-
Item,
|
|
4
|
-
PriKey,
|
|
5
|
-
} from "@fjell/core";
|
|
6
|
-
import { 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
|
-
params: Record<string, string | number | boolean | Date | Array<string | number | boolean | Date>> = {},
|
|
46
|
-
): Promise<any> => {
|
|
47
|
-
const requestOptions = Object.assign({}, apiOptions.getOptions, { isAuthenticated: apiOptions.writeAuthenticated, params });
|
|
48
|
-
logger.default('facet', { ik, facet, requestOptions });
|
|
49
|
-
|
|
50
|
-
return api.httpGet<any>(
|
|
51
|
-
`${utilities.getPath(ik)}/${facet}`,
|
|
52
|
-
requestOptions,
|
|
53
|
-
);
|
|
54
|
-
|
|
55
|
-
};
|
|
56
|
-
|
|
57
|
-
return facet;
|
|
58
|
-
}
|
package/src/ops/find.ts
DELETED
|
@@ -1,49 +0,0 @@
|
|
|
1
|
-
import {
|
|
2
|
-
Item,
|
|
3
|
-
LocKeyArray,
|
|
4
|
-
QueryParams
|
|
5
|
-
} from "@fjell/core";
|
|
6
|
-
import { 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
|
-
locations: LocKeyArray<L1, L2, L3, L4, L5> | [] = []
|
|
33
|
-
): Promise<V[]> => {
|
|
34
|
-
utilities.verifyLocations(locations);
|
|
35
|
-
const loc: LocKeyArray<L1, L2, L3, L4, L5> | [] = locations;
|
|
36
|
-
|
|
37
|
-
const mergedParams: QueryParams = finderToParams(finder, finderParams);
|
|
38
|
-
const requestOptions = Object.assign({}, apiOptions.getOptions, { isAuthenticated: apiOptions.allAuthenticated, params: mergedParams });
|
|
39
|
-
logger.default('find', { finder, finderParams, locations, requestOptions });
|
|
40
|
-
|
|
41
|
-
return utilities.validatePK(await utilities.processArray(
|
|
42
|
-
api.httpGet<V[]>(
|
|
43
|
-
utilities.getPath(loc),
|
|
44
|
-
requestOptions,
|
|
45
|
-
))) as V[];
|
|
46
|
-
}
|
|
47
|
-
|
|
48
|
-
return find;
|
|
49
|
-
}
|
package/src/ops/findOne.ts
DELETED
|
@@ -1,51 +0,0 @@
|
|
|
1
|
-
import {
|
|
2
|
-
Item,
|
|
3
|
-
LocKeyArray,
|
|
4
|
-
QueryParams
|
|
5
|
-
} from "@fjell/core";
|
|
6
|
-
import { 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
|
-
locations: LocKeyArray<L1, L2, L3, L4, L5> | [] = []
|
|
33
|
-
): Promise<V> => {
|
|
34
|
-
utilities.verifyLocations(locations);
|
|
35
|
-
const loc: LocKeyArray<L1, L2, L3, L4, L5> | [] = locations;
|
|
36
|
-
|
|
37
|
-
const params: QueryParams = finderToParams(finder, finderParams);
|
|
38
|
-
params.one = true;
|
|
39
|
-
|
|
40
|
-
const requestOptions = Object.assign({}, apiOptions.getOptions, { isAuthenticated: apiOptions.allAuthenticated, params });
|
|
41
|
-
logger.default('findOne', { finder, finderParams, locations, requestOptions });
|
|
42
|
-
|
|
43
|
-
return (utilities.validatePK(await utilities.processArray(
|
|
44
|
-
api.httpGet<V[]>(
|
|
45
|
-
utilities.getPath(loc),
|
|
46
|
-
requestOptions,
|
|
47
|
-
))) as V[])[0];
|
|
48
|
-
}
|
|
49
|
-
|
|
50
|
-
return findOne;
|
|
51
|
-
}
|
package/src/ops/get.ts
DELETED
|
@@ -1,42 +0,0 @@
|
|
|
1
|
-
import {
|
|
2
|
-
ComKey,
|
|
3
|
-
Item,
|
|
4
|
-
PriKey,
|
|
5
|
-
} from "@fjell/core";
|
|
6
|
-
import { 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
|
-
): Promise<V | null> => {
|
|
31
|
-
const requestOptions = Object.assign({}, apiOptions.getOptions, { isAuthenticated: apiOptions.readAuthenticated });
|
|
32
|
-
logger.default('get', { ik, requestOptions });
|
|
33
|
-
|
|
34
|
-
return utilities.validatePK(await utilities.processOne(
|
|
35
|
-
api.httpGet<V>(
|
|
36
|
-
utilities.getPath(ik),
|
|
37
|
-
requestOptions,
|
|
38
|
-
))) as V;
|
|
39
|
-
}
|
|
40
|
-
|
|
41
|
-
return get;
|
|
42
|
-
}
|