@fjell/client-api 4.4.13 → 4.4.15
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.d.ts +4 -4
- package/dist/CItemAPI.d.ts +5 -5
- package/dist/ClientApi.d.ts +1 -1
- package/dist/ClientApiOptions.d.ts +3 -3
- package/dist/Instance.d.ts +3 -3
- package/dist/InstanceFactory.d.ts +3 -3
- package/dist/PItemAPI.d.ts +4 -4
- package/dist/Utilities.d.ts +1 -1
- package/dist/index.d.ts +6 -6
- package/dist/index.js +544 -5
- package/dist/index.js.map +7 -1
- package/dist/logger.d.ts +1 -1
- package/dist/ops/action.d.ts +4 -4
- package/dist/ops/all.d.ts +4 -4
- package/dist/ops/allAction.d.ts +4 -4
- package/dist/ops/allFacet.d.ts +4 -4
- package/dist/ops/create.d.ts +4 -4
- package/dist/ops/facet.d.ts +4 -4
- package/dist/ops/find.d.ts +4 -4
- package/dist/ops/findOne.d.ts +4 -4
- package/dist/ops/get.d.ts +4 -4
- package/dist/ops/index.d.ts +5 -5
- package/dist/ops/one.d.ts +4 -4
- package/dist/ops/remove.d.ts +4 -4
- package/dist/ops/update.d.ts +4 -4
- package/package.json +11 -14
- package/vitest.config.ts +25 -0
- package/dist/AItemAPI.js +0 -52
- package/dist/AItemAPI.js.map +0 -1
- package/dist/CItemAPI.js +0 -30
- package/dist/CItemAPI.js.map +0 -1
- package/dist/Instance.js +0 -19
- package/dist/Instance.js.map +0 -1
- package/dist/InstanceFactory.js +0 -19
- package/dist/InstanceFactory.js.map +0 -1
- package/dist/PItemAPI.js +0 -44
- package/dist/PItemAPI.js.map +0 -1
- package/dist/Registry.js +0 -31
- package/dist/Registry.js.map +0 -1
- package/dist/Utilities.js +0 -153
- package/dist/Utilities.js.map +0 -1
- package/dist/index.cjs +0 -586
- package/dist/index.cjs.map +0 -1
- package/dist/logger.js +0 -6
- package/dist/logger.js.map +0 -1
- package/dist/ops/action.js +0 -21
- package/dist/ops/action.js.map +0 -1
- package/dist/ops/all.js +0 -25
- package/dist/ops/all.js.map +0 -1
- package/dist/ops/allAction.js +0 -24
- package/dist/ops/allAction.js.map +0 -1
- package/dist/ops/allFacet.js +0 -24
- package/dist/ops/allFacet.js.map +0 -1
- package/dist/ops/create.js +0 -23
- package/dist/ops/create.js.map +0 -1
- package/dist/ops/facet.js +0 -34
- package/dist/ops/facet.js.map +0 -1
- package/dist/ops/find.js +0 -26
- package/dist/ops/find.js.map +0 -1
- package/dist/ops/findOne.js +0 -27
- package/dist/ops/findOne.js.map +0 -1
- package/dist/ops/get.js +0 -19
- package/dist/ops/get.js.map +0 -1
- package/dist/ops/index.js +0 -32
- package/dist/ops/index.js.map +0 -1
- package/dist/ops/one.js +0 -30
- package/dist/ops/one.js.map +0 -1
- package/dist/ops/remove.js +0 -19
- package/dist/ops/remove.js.map +0 -1
- package/dist/ops/update.js +0 -20
- package/dist/ops/update.js.map +0 -1
- package/docs/docs.config.ts +0 -77
- package/docs/index.html +0 -18
- package/docs/package.json +0 -34
- package/docs/public/README.md +0 -165
- package/docs/public/api-reference.md +0 -408
- package/docs/public/examples-README.md +0 -387
- package/docs/public/fjell-icon.svg +0 -1
- package/docs/public/package.json +0 -5
- package/docs/src/index.css +0 -34
- package/docs/src/main.tsx +0 -12
- package/docs/src/test/setup.ts +0 -1
- package/docs/src/types.d.ts +0 -44
- package/docs/tsconfig.node.json +0 -13
- package/docs/vitest.config.ts +0 -14
- package/examples/README.md +0 -387
- package/examples/enterprise-example.ts +0 -852
- package/examples/multi-level-keys.ts +0 -467
- package/examples/simple-example.ts +0 -346
package/dist/AItemAPI.d.ts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
import { Item, QueryParams } from
|
|
2
|
-
import { HttpApi } from
|
|
3
|
-
import { ClientApiOptions } from
|
|
4
|
-
import { ClientApi } from
|
|
1
|
+
import { Item, QueryParams } from "@fjell/core";
|
|
2
|
+
import { HttpApi } from "@fjell/http-api";
|
|
3
|
+
import { ClientApiOptions } from "./ClientApiOptions";
|
|
4
|
+
import { ClientApi } from "./ClientApi";
|
|
5
5
|
export type PathNamesArray<L1 extends string = never, L2 extends string = never, L3 extends string = never, L4 extends string = never, L5 extends string = never> = ([L5] extends [never] ? ([L4] extends [never] ? ([L3] extends [never] ? ([L2] extends [never] ? ([L1] extends [never] ? [
|
|
6
6
|
string
|
|
7
7
|
] : [
|
package/dist/CItemAPI.d.ts
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
|
-
import { ComKey, Item, ItemQuery, LocKeyArray, PriKey } from
|
|
2
|
-
import { HttpApi } from
|
|
3
|
-
import { PathNamesArray } from
|
|
4
|
-
import { ClientApi } from
|
|
5
|
-
import { ClientApiOptions } from
|
|
1
|
+
import { ComKey, Item, ItemQuery, LocKeyArray, PriKey } from "@fjell/core";
|
|
2
|
+
import { HttpApi } from "@fjell/http-api";
|
|
3
|
+
import { PathNamesArray } from "./AItemAPI";
|
|
4
|
+
import { ClientApi } from "./ClientApi";
|
|
5
|
+
import { ClientApiOptions } from "./ClientApiOptions";
|
|
6
6
|
export interface CItemApi<V extends Item<S, L1, L2, L3, L4, L5>, S extends string, L1 extends string, L2 extends string = never, L3 extends string = never, L4 extends string = never, L5 extends string = never> extends ClientApi<V, S, L1, L2, L3, L4, L5> {
|
|
7
7
|
action: (ik: ComKey<S, L1, L2, L3, L4, L5> | PriKey<S>, action: string, body: any) => Promise<V>;
|
|
8
8
|
all: (query: ItemQuery, locations?: LocKeyArray<L1, L2, L3, L4, L5> | []) => Promise<V[]>;
|
package/dist/ClientApi.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { ComKey, Item, ItemQuery, LocKeyArray, PriKey } from
|
|
1
|
+
import { ComKey, Item, ItemQuery, LocKeyArray, PriKey } from "@fjell/core";
|
|
2
2
|
export interface ClientApi<V extends Item<S, L1, L2, L3, L4, L5>, S extends string, L1 extends string = never, L2 extends string = never, L3 extends string = never, L4 extends string = never, L5 extends string = never> {
|
|
3
3
|
action: (ik: ComKey<S, L1, L2, L3, L4, L5> | PriKey<S>, action: string, body?: any) => Promise<V>;
|
|
4
4
|
all: (query: ItemQuery, locations?: LocKeyArray<L1, L2, L3, L4, L5> | []) => Promise<V[]>;
|
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import { Item } from
|
|
2
|
-
import { ClientApi } from
|
|
3
|
-
import { DeleteMethodOptions, GetMethodOptions, PostMethodOptions, PutMethodOptions } from
|
|
1
|
+
import { Item } from "@fjell/core";
|
|
2
|
+
import { ClientApi } from "./ClientApi";
|
|
3
|
+
import { DeleteMethodOptions, GetMethodOptions, PostMethodOptions, PutMethodOptions } from "@fjell/http-api";
|
|
4
4
|
export interface ClientApiOptions {
|
|
5
5
|
readAuthenticated?: boolean;
|
|
6
6
|
allAuthenticated?: boolean;
|
package/dist/Instance.d.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import { Item } from
|
|
2
|
-
import { Instance as BaseInstance, Coordinate, Registry } from
|
|
3
|
-
import { ClientApi } from
|
|
1
|
+
import { Item } from "@fjell/core";
|
|
2
|
+
import { Instance as BaseInstance, Coordinate, Registry } from "@fjell/registry";
|
|
3
|
+
import { ClientApi } from "./ClientApi";
|
|
4
4
|
/**
|
|
5
5
|
* The Client API Instance interface represents a client API model instance that extends the base Instance
|
|
6
6
|
* from @fjell/registry and adds client API operations for interacting with remote data.
|
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import { Item } from
|
|
2
|
-
import { ClientApi } from
|
|
3
|
-
import { InstanceFactory as BaseInstanceFactory } from
|
|
1
|
+
import { Item } from "@fjell/core";
|
|
2
|
+
import { ClientApi } from "./ClientApi";
|
|
3
|
+
import { InstanceFactory as BaseInstanceFactory } from "@fjell/registry";
|
|
4
4
|
export type InstanceFactory<V extends Item<S, L1, L2, L3, L4, L5>, S extends string, L1 extends string = never, L2 extends string = never, L3 extends string = never, L4 extends string = never, L5 extends string = never> = (clientApi: ClientApi<V, S, L1, L2, L3, L4, L5>) => BaseInstanceFactory<S, L1, L2, L3, L4, L5>;
|
|
5
5
|
/**
|
|
6
6
|
* Factory function for creating client-api instances
|
package/dist/PItemAPI.d.ts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
import { ComKey, Item, ItemQuery, PriKey } from
|
|
2
|
-
import { HttpApi } from
|
|
3
|
-
import { ClientApi } from
|
|
4
|
-
import { ClientApiOptions } from
|
|
1
|
+
import { ComKey, Item, ItemQuery, PriKey } from "@fjell/core";
|
|
2
|
+
import { HttpApi } from "@fjell/http-api";
|
|
3
|
+
import { ClientApi } from "./ClientApi";
|
|
4
|
+
import { ClientApiOptions } from "./ClientApiOptions";
|
|
5
5
|
export interface PItemApi<V extends Item<S>, S extends string> extends ClientApi<V, S> {
|
|
6
6
|
action: (ik: PriKey<S> | ComKey<S, never, never, never, never, never>, action: string, body: any) => Promise<V>;
|
|
7
7
|
all: (query: ItemQuery) => Promise<V[]>;
|
package/dist/Utilities.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { ComKey, Item, LocKeyArray, PriKey } from
|
|
1
|
+
import { ComKey, Item, LocKeyArray, PriKey } from "@fjell/core";
|
|
2
2
|
export interface Utilities<V extends Item<S, L1, L2, L3, L4, L5>, S extends string, L1 extends string = never, L2 extends string = never, L3 extends string = never, L4 extends string = never, L5 extends string = never> {
|
|
3
3
|
verifyLocations: (locations: LocKeyArray<L1, L2, L3, L4, L5> | [] | never) => boolean;
|
|
4
4
|
processOne: (apiCall: Promise<V>) => Promise<V>;
|
package/dist/index.d.ts
CHANGED
|
@@ -1,9 +1,9 @@
|
|
|
1
|
-
export type { CItemApi } from
|
|
2
|
-
export type { PItemApi } from
|
|
3
|
-
export type { ClientApi } from
|
|
4
|
-
export type { ClientApiOptions } from
|
|
5
|
-
export { createCItemApi } from
|
|
6
|
-
export { createPItemApi } from
|
|
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
|
+
export { createCItemApi } from "./CItemAPI";
|
|
6
|
+
export { createPItemApi } from "./PItemAPI";
|
|
7
7
|
export * from './Instance';
|
|
8
8
|
export * from './InstanceFactory';
|
|
9
9
|
export * from './Registry';
|
package/dist/index.js
CHANGED
|
@@ -1,6 +1,545 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
1
|
+
// src/ops/all.ts
|
|
2
|
+
import {
|
|
3
|
+
queryToParams
|
|
4
|
+
} from "@fjell/core";
|
|
5
|
+
|
|
6
|
+
// src/logger.ts
|
|
7
|
+
import Logging from "@fjell/logging";
|
|
8
|
+
var LibLogger = Logging.getLogger("@fjell/client-api");
|
|
9
|
+
var logger_default = LibLogger;
|
|
10
|
+
|
|
11
|
+
// src/ops/all.ts
|
|
12
|
+
var logger = logger_default.get("client-api", "ops", "all");
|
|
13
|
+
var getAllOperation = (api, apiOptions, utilities) => {
|
|
14
|
+
const all = async (query = {}, locations = []) => {
|
|
15
|
+
utilities.verifyLocations(locations);
|
|
16
|
+
const loc = locations;
|
|
17
|
+
const params = queryToParams(query);
|
|
18
|
+
const requestOptions = Object.assign({}, apiOptions.getOptions, { isAuthenticated: apiOptions.allAuthenticated, params });
|
|
19
|
+
logger.default("all", { query, locations, requestOptions });
|
|
20
|
+
return utilities.validatePK(await utilities.processArray(
|
|
21
|
+
api.httpGet(
|
|
22
|
+
utilities.getPath(loc),
|
|
23
|
+
requestOptions
|
|
24
|
+
)
|
|
25
|
+
));
|
|
26
|
+
};
|
|
27
|
+
return all;
|
|
28
|
+
};
|
|
29
|
+
|
|
30
|
+
// src/ops/action.ts
|
|
31
|
+
var logger2 = logger_default.get("client-api", "ops", "action");
|
|
32
|
+
var getActionOperation = (api, apiOptions, utilities) => {
|
|
33
|
+
const action = async (ik, action2, body = {}) => {
|
|
34
|
+
const requestOptions = Object.assign({}, apiOptions.postOptions, { isAuthenticated: apiOptions.writeAuthenticated });
|
|
35
|
+
logger2.default("action", { ik, action: action2, body, requestOptions });
|
|
36
|
+
return utilities.validatePK(
|
|
37
|
+
await utilities.processOne(
|
|
38
|
+
api.httpPost(
|
|
39
|
+
`${utilities.getPath(ik)}/${action2}`,
|
|
40
|
+
body,
|
|
41
|
+
requestOptions
|
|
42
|
+
)
|
|
43
|
+
)
|
|
44
|
+
);
|
|
45
|
+
};
|
|
46
|
+
return action;
|
|
47
|
+
};
|
|
48
|
+
|
|
49
|
+
// src/ops/allAction.ts
|
|
50
|
+
var logger3 = logger_default.get("client-api", "ops", "allAction");
|
|
51
|
+
var getAllActionOperation = (api, apiOptions, utilities) => {
|
|
52
|
+
const allAction = async (action, body = {}, locations = []) => {
|
|
53
|
+
const requestOptions = Object.assign({}, apiOptions.postOptions, { isAuthenticated: apiOptions.writeAuthenticated });
|
|
54
|
+
logger3.default("allAction", { action, body, locations, requestOptions });
|
|
55
|
+
utilities.verifyLocations(locations);
|
|
56
|
+
const loc = locations;
|
|
57
|
+
return utilities.validatePK(
|
|
58
|
+
await utilities.processArray(
|
|
59
|
+
api.httpPost(
|
|
60
|
+
utilities.getPath(loc),
|
|
61
|
+
body,
|
|
62
|
+
requestOptions
|
|
63
|
+
)
|
|
64
|
+
)
|
|
65
|
+
);
|
|
66
|
+
};
|
|
67
|
+
return allAction;
|
|
68
|
+
};
|
|
69
|
+
|
|
70
|
+
// src/ops/one.ts
|
|
71
|
+
import {
|
|
72
|
+
queryToParams as queryToParams2
|
|
73
|
+
} from "@fjell/core";
|
|
74
|
+
var logger4 = logger_default.get("client-api", "ops", "one");
|
|
75
|
+
var getOneOperation = (api, apiOptions, utilities) => {
|
|
76
|
+
const one = async (query = {}, locations = []) => {
|
|
77
|
+
utilities.verifyLocations(locations);
|
|
78
|
+
const loc = locations;
|
|
79
|
+
const params = queryToParams2(query);
|
|
80
|
+
const requestOptions = Object.assign({}, apiOptions.getOptions, { isAuthenticated: apiOptions.readAuthenticated, params });
|
|
81
|
+
logger4.default("one", { query, locations, requestOptions });
|
|
82
|
+
let item = null;
|
|
83
|
+
const items = utilities.validatePK(await utilities.processArray(
|
|
84
|
+
api.httpGet(
|
|
85
|
+
utilities.getPath(loc),
|
|
86
|
+
requestOptions
|
|
87
|
+
)
|
|
88
|
+
));
|
|
89
|
+
if (items.length > 0) {
|
|
90
|
+
item = items[0];
|
|
91
|
+
}
|
|
92
|
+
return item;
|
|
93
|
+
};
|
|
94
|
+
return one;
|
|
95
|
+
};
|
|
96
|
+
|
|
97
|
+
// src/ops/create.ts
|
|
98
|
+
var logger5 = logger_default.get("client-api", "ops", "create");
|
|
99
|
+
var getCreateOperation = (api, apiOptions, utilities) => {
|
|
100
|
+
const create = async (item, locations = []) => {
|
|
101
|
+
const requestOptions = Object.assign({}, apiOptions.postOptions, { isAuthenticated: apiOptions.writeAuthenticated });
|
|
102
|
+
logger5.default("create", { item, locations, requestOptions });
|
|
103
|
+
utilities.verifyLocations(locations);
|
|
104
|
+
const loc = locations;
|
|
105
|
+
const created = utilities.validatePK(await utilities.processOne(api.httpPost(
|
|
106
|
+
utilities.getPath(loc),
|
|
107
|
+
item,
|
|
108
|
+
requestOptions
|
|
109
|
+
)));
|
|
110
|
+
return created;
|
|
111
|
+
};
|
|
112
|
+
return create;
|
|
113
|
+
};
|
|
114
|
+
|
|
115
|
+
// src/ops/update.ts
|
|
116
|
+
var logger6 = logger_default.get("client-api", "ops", "update");
|
|
117
|
+
var getUpdateOperation = (api, apiOptions, utilities) => {
|
|
118
|
+
const update = async (ik, item) => {
|
|
119
|
+
const requestOptions = Object.assign({}, apiOptions.putOptions, { isAuthenticated: apiOptions.writeAuthenticated });
|
|
120
|
+
logger6.default("update", { ik, item, requestOptions });
|
|
121
|
+
return utilities.validatePK(await utilities.processOne(
|
|
122
|
+
api.httpPut(
|
|
123
|
+
utilities.getPath(ik),
|
|
124
|
+
item,
|
|
125
|
+
requestOptions
|
|
126
|
+
)
|
|
127
|
+
));
|
|
128
|
+
};
|
|
129
|
+
return update;
|
|
130
|
+
};
|
|
131
|
+
|
|
132
|
+
// src/ops/get.ts
|
|
133
|
+
var logger7 = logger_default.get("client-api", "ops", "get");
|
|
134
|
+
var getGetOperation = (api, apiOptions, utilities) => {
|
|
135
|
+
const get = async (ik) => {
|
|
136
|
+
const requestOptions = Object.assign({}, apiOptions.getOptions, { isAuthenticated: apiOptions.readAuthenticated });
|
|
137
|
+
logger7.default("get", { ik, requestOptions });
|
|
138
|
+
return utilities.validatePK(await utilities.processOne(
|
|
139
|
+
api.httpGet(
|
|
140
|
+
utilities.getPath(ik),
|
|
141
|
+
requestOptions
|
|
142
|
+
)
|
|
143
|
+
));
|
|
144
|
+
};
|
|
145
|
+
return get;
|
|
146
|
+
};
|
|
147
|
+
|
|
148
|
+
// src/ops/remove.ts
|
|
149
|
+
var logger8 = logger_default.get("client-api", "ops", "remove");
|
|
150
|
+
var getRemoveOperation = (api, apiOptions, utilities) => {
|
|
151
|
+
const remove = async (ik) => {
|
|
152
|
+
const requestOptions = Object.assign({}, apiOptions.deleteOptions, { isAuthenticated: apiOptions.writeAuthenticated });
|
|
153
|
+
logger8.default("remove", { ik, requestOptions });
|
|
154
|
+
return api.httpDelete(utilities.getPath(ik), requestOptions);
|
|
155
|
+
};
|
|
156
|
+
return remove;
|
|
157
|
+
};
|
|
158
|
+
|
|
159
|
+
// src/ops/find.ts
|
|
160
|
+
var logger9 = logger_default.get("client-api", "ops", "find");
|
|
161
|
+
var getFindOperation = (api, apiOptions, utilities) => {
|
|
162
|
+
const find = async (finder, finderParams = {}, locations = []) => {
|
|
163
|
+
utilities.verifyLocations(locations);
|
|
164
|
+
const loc = locations;
|
|
165
|
+
const mergedParams = finderToParams(finder, finderParams);
|
|
166
|
+
const requestOptions = Object.assign({}, apiOptions.getOptions, { isAuthenticated: apiOptions.allAuthenticated, params: mergedParams });
|
|
167
|
+
logger9.default("find", { finder, finderParams, locations, requestOptions });
|
|
168
|
+
return utilities.validatePK(await utilities.processArray(
|
|
169
|
+
api.httpGet(
|
|
170
|
+
utilities.getPath(loc),
|
|
171
|
+
requestOptions
|
|
172
|
+
)
|
|
173
|
+
));
|
|
174
|
+
};
|
|
175
|
+
return find;
|
|
176
|
+
};
|
|
177
|
+
|
|
178
|
+
// src/ops/findOne.ts
|
|
179
|
+
var logger10 = logger_default.get("client-api", "ops", "find");
|
|
180
|
+
var getFindOneOperation = (api, apiOptions, utilities) => {
|
|
181
|
+
const findOne = async (finder, finderParams = {}, locations = []) => {
|
|
182
|
+
utilities.verifyLocations(locations);
|
|
183
|
+
const loc = locations;
|
|
184
|
+
const params = finderToParams(finder, finderParams);
|
|
185
|
+
params.one = true;
|
|
186
|
+
const requestOptions = Object.assign({}, apiOptions.getOptions, { isAuthenticated: apiOptions.allAuthenticated, params });
|
|
187
|
+
logger10.default("findOne", { finder, finderParams, locations, requestOptions });
|
|
188
|
+
return utilities.validatePK(await utilities.processArray(
|
|
189
|
+
api.httpGet(
|
|
190
|
+
utilities.getPath(loc),
|
|
191
|
+
requestOptions
|
|
192
|
+
)
|
|
193
|
+
))[0];
|
|
194
|
+
};
|
|
195
|
+
return findOne;
|
|
196
|
+
};
|
|
197
|
+
|
|
198
|
+
// src/ops/facet.ts
|
|
199
|
+
var logger11 = logger_default.get("client-api", "ops", "facet");
|
|
200
|
+
var getFacetOperation = (api, apiOptions, utilities) => {
|
|
201
|
+
const facet = async (ik, facet2, params = {}) => {
|
|
202
|
+
const requestOptions = Object.assign({}, apiOptions.getOptions, { isAuthenticated: apiOptions.writeAuthenticated, params });
|
|
203
|
+
logger11.default("facet", { ik, facet: facet2, requestOptions });
|
|
204
|
+
return api.httpGet(
|
|
205
|
+
`${utilities.getPath(ik)}/${facet2}`,
|
|
206
|
+
requestOptions
|
|
207
|
+
);
|
|
208
|
+
};
|
|
209
|
+
return facet;
|
|
210
|
+
};
|
|
211
|
+
|
|
212
|
+
// src/ops/allFacet.ts
|
|
213
|
+
var logger12 = logger_default.get("client-api", "ops", "allFacet");
|
|
214
|
+
var getAllFacetOperation = (api, apiOptions, utilities) => {
|
|
215
|
+
const allFacet = async (facet, params = {}, locations = []) => {
|
|
216
|
+
const requestOptions = Object.assign({}, apiOptions.getOptions, { isAuthenticated: apiOptions.writeAuthenticated, params });
|
|
217
|
+
logger12.default("allFacet", { facet, locations, requestOptions });
|
|
218
|
+
utilities.verifyLocations(locations);
|
|
219
|
+
const loc = locations;
|
|
220
|
+
return api.httpGet(
|
|
221
|
+
utilities.getPath(loc),
|
|
222
|
+
requestOptions
|
|
223
|
+
);
|
|
224
|
+
};
|
|
225
|
+
return allFacet;
|
|
226
|
+
};
|
|
227
|
+
|
|
228
|
+
// src/ops/index.ts
|
|
229
|
+
var getOperations = (api, apiOptions, utilities) => {
|
|
230
|
+
return {
|
|
231
|
+
action: getActionOperation(
|
|
232
|
+
api,
|
|
233
|
+
apiOptions,
|
|
234
|
+
utilities
|
|
235
|
+
),
|
|
236
|
+
all: getAllOperation(
|
|
237
|
+
api,
|
|
238
|
+
apiOptions,
|
|
239
|
+
utilities
|
|
240
|
+
),
|
|
241
|
+
allAction: getAllActionOperation(
|
|
242
|
+
api,
|
|
243
|
+
apiOptions,
|
|
244
|
+
utilities
|
|
245
|
+
),
|
|
246
|
+
allFacet: getAllFacetOperation(
|
|
247
|
+
api,
|
|
248
|
+
apiOptions,
|
|
249
|
+
utilities
|
|
250
|
+
),
|
|
251
|
+
create: getCreateOperation(
|
|
252
|
+
api,
|
|
253
|
+
apiOptions,
|
|
254
|
+
utilities
|
|
255
|
+
),
|
|
256
|
+
facet: getFacetOperation(
|
|
257
|
+
api,
|
|
258
|
+
apiOptions,
|
|
259
|
+
utilities
|
|
260
|
+
),
|
|
261
|
+
findOne: getFindOneOperation(
|
|
262
|
+
api,
|
|
263
|
+
apiOptions,
|
|
264
|
+
utilities
|
|
265
|
+
),
|
|
266
|
+
find: getFindOperation(
|
|
267
|
+
api,
|
|
268
|
+
apiOptions,
|
|
269
|
+
utilities
|
|
270
|
+
),
|
|
271
|
+
get: getGetOperation(
|
|
272
|
+
api,
|
|
273
|
+
apiOptions,
|
|
274
|
+
utilities
|
|
275
|
+
),
|
|
276
|
+
one: getOneOperation(
|
|
277
|
+
api,
|
|
278
|
+
apiOptions,
|
|
279
|
+
utilities
|
|
280
|
+
),
|
|
281
|
+
remove: getRemoveOperation(
|
|
282
|
+
api,
|
|
283
|
+
apiOptions,
|
|
284
|
+
utilities
|
|
285
|
+
),
|
|
286
|
+
update: getUpdateOperation(
|
|
287
|
+
api,
|
|
288
|
+
apiOptions,
|
|
289
|
+
utilities
|
|
290
|
+
)
|
|
291
|
+
};
|
|
292
|
+
};
|
|
293
|
+
|
|
294
|
+
// src/Utilities.ts
|
|
295
|
+
import {
|
|
296
|
+
validatePK as coreValidatePK,
|
|
297
|
+
generateKeyArray,
|
|
298
|
+
isPriKey
|
|
299
|
+
} from "@fjell/core";
|
|
300
|
+
import deepmerge from "deepmerge";
|
|
301
|
+
var logger13 = logger_default.get("client-api", "Utility");
|
|
302
|
+
var createUtilities = (pkType, pathNames) => {
|
|
303
|
+
logger13.default("createUtilities", { pkType, pathNames });
|
|
304
|
+
const verifyLocations = (locations) => {
|
|
305
|
+
if (locations && locations.length < pathNames.length - 1) {
|
|
306
|
+
throw new Error("Not enough locations for pathNames: locations:" + locations.length + " pathNames:" + pathNames.length);
|
|
307
|
+
}
|
|
308
|
+
return true;
|
|
309
|
+
};
|
|
310
|
+
const processOne = async (apiCall) => {
|
|
311
|
+
logger13.default("processOne", { apiCall });
|
|
312
|
+
const response = await apiCall;
|
|
313
|
+
logger13.default("processOne response", { response: JSON.stringify(response, null, 2) });
|
|
314
|
+
return convertDoc(response);
|
|
315
|
+
};
|
|
316
|
+
const processArray = async (api) => {
|
|
317
|
+
logger13.default("processArray", { api });
|
|
318
|
+
const response = await api;
|
|
319
|
+
logger13.default("processArray response", { response: JSON.stringify(response, null, 2) });
|
|
320
|
+
if (response && Array.isArray(response)) {
|
|
321
|
+
return response.map(
|
|
322
|
+
(subjectChat) => convertDoc(subjectChat)
|
|
323
|
+
);
|
|
324
|
+
} else {
|
|
325
|
+
logger13.error("Response was not an array", { response });
|
|
326
|
+
throw new Error("Response was not an array");
|
|
327
|
+
}
|
|
328
|
+
};
|
|
329
|
+
const convertDoc = (doc) => {
|
|
330
|
+
logger13.default("convertDoc", { doc });
|
|
331
|
+
if (doc && doc.events) {
|
|
332
|
+
const events = doc.events;
|
|
333
|
+
for (const key in events) {
|
|
334
|
+
events[key] = deepmerge(events[key], { at: events[key].at ? new Date(events[key].at) : null });
|
|
335
|
+
}
|
|
336
|
+
return doc;
|
|
337
|
+
} else {
|
|
338
|
+
return doc;
|
|
339
|
+
}
|
|
340
|
+
};
|
|
341
|
+
const getPath = (key) => {
|
|
342
|
+
const localPathNames = [...pathNames];
|
|
343
|
+
logger13.default("getPath", { key, pathNames: localPathNames });
|
|
344
|
+
const keys = generateKeyArray(key);
|
|
345
|
+
let path = addPath("", keys, localPathNames);
|
|
346
|
+
if (localPathNames.length === 1) {
|
|
347
|
+
path = `${path}/${localPathNames[0]}`;
|
|
348
|
+
}
|
|
349
|
+
logger13.default("getPath created", { key, path });
|
|
350
|
+
return path;
|
|
351
|
+
};
|
|
352
|
+
const addPath = (base, keys, localPathNames) => {
|
|
353
|
+
logger13.default("addPath", { base, keys, pathNames: localPathNames });
|
|
354
|
+
if (keys.length < localPathNames.length - 1) {
|
|
355
|
+
logger13.error(
|
|
356
|
+
"addPath should never have keys with a length less than the length of pathNames - 1",
|
|
357
|
+
{ keys, localPathNames }
|
|
358
|
+
);
|
|
359
|
+
throw new Error("addPath should never have keys with a length less than the length of pathNames - 1: " + keys.length + " " + localPathNames.length + " " + JSON.stringify(keys, localPathNames));
|
|
360
|
+
} else if (keys.length > localPathNames.length) {
|
|
361
|
+
logger13.error(
|
|
362
|
+
"addPath should never have keys with a length greater than the length of pathNames",
|
|
363
|
+
{ keys, pathNames }
|
|
364
|
+
);
|
|
365
|
+
throw new Error("addPath should never have keys with a length greater than the length of pathNames: " + keys.length + " " + localPathNames.length + " " + JSON.stringify(keys, localPathNames));
|
|
366
|
+
}
|
|
367
|
+
if (keys.length === 0) {
|
|
368
|
+
logger13.default("addPath returning base", { base });
|
|
369
|
+
return base;
|
|
370
|
+
} else {
|
|
371
|
+
let nextBase;
|
|
372
|
+
const key = keys.pop();
|
|
373
|
+
const pathName = localPathNames.pop();
|
|
374
|
+
if (isPriKey(key)) {
|
|
375
|
+
const PriKey2 = key;
|
|
376
|
+
nextBase = `${base}/${pathName}/${PriKey2.pk}`;
|
|
377
|
+
logger13.default("Adding Path for PK", { pathName, PriKey: PriKey2, nextBase });
|
|
378
|
+
} else {
|
|
379
|
+
const LocKey2 = key;
|
|
380
|
+
nextBase = `${base}/${pathName}/${LocKey2.lk}`;
|
|
381
|
+
logger13.default("Retrieving Collection for LK", { pathName, LocKey: LocKey2 });
|
|
382
|
+
}
|
|
383
|
+
logger13.default("calling addPath recursively", { nextBase, keys, localPathNames });
|
|
384
|
+
return addPath(nextBase, keys, localPathNames);
|
|
385
|
+
}
|
|
386
|
+
};
|
|
387
|
+
const validatePK = (item) => {
|
|
388
|
+
return coreValidatePK(item, pkType);
|
|
389
|
+
};
|
|
390
|
+
return {
|
|
391
|
+
verifyLocations,
|
|
392
|
+
processOne,
|
|
393
|
+
convertDoc,
|
|
394
|
+
processArray,
|
|
395
|
+
getPath,
|
|
396
|
+
validatePK
|
|
397
|
+
};
|
|
398
|
+
};
|
|
399
|
+
|
|
400
|
+
// src/AItemAPI.ts
|
|
401
|
+
var logger14 = logger_default.get("AItemAPI");
|
|
402
|
+
var finderToParams = (finder, finderParams) => {
|
|
403
|
+
return {
|
|
404
|
+
finder,
|
|
405
|
+
finderParams: JSON.stringify(finderParams)
|
|
406
|
+
};
|
|
407
|
+
};
|
|
408
|
+
var createAItemAPI = (api, pkType, pathNames, options) => {
|
|
409
|
+
logger14.default("createAItemAPI", { pkType, pathNames, options });
|
|
410
|
+
let mergedOptions;
|
|
411
|
+
const defaultOptions = {
|
|
412
|
+
readAuthenticated: true,
|
|
413
|
+
allAuthenticated: true,
|
|
414
|
+
writeAuthenticated: true,
|
|
415
|
+
getOptions: {},
|
|
416
|
+
postOptions: {},
|
|
417
|
+
putOptions: {},
|
|
418
|
+
deleteOptions: {}
|
|
419
|
+
};
|
|
420
|
+
if (options) {
|
|
421
|
+
mergedOptions = Object.assign({}, defaultOptions, options);
|
|
422
|
+
} else {
|
|
423
|
+
mergedOptions = defaultOptions;
|
|
424
|
+
}
|
|
425
|
+
const utilities = createUtilities(pkType, pathNames);
|
|
426
|
+
const operations = getOperations(api, mergedOptions, utilities);
|
|
427
|
+
return {
|
|
428
|
+
action: operations.action,
|
|
429
|
+
all: operations.all,
|
|
430
|
+
allAction: operations.allAction,
|
|
431
|
+
allFacet: operations.allFacet,
|
|
432
|
+
create: operations.create,
|
|
433
|
+
facet: operations.facet,
|
|
434
|
+
find: operations.find,
|
|
435
|
+
findOne: operations.findOne,
|
|
436
|
+
get: operations.get,
|
|
437
|
+
one: operations.one,
|
|
438
|
+
remove: operations.remove,
|
|
439
|
+
update: operations.update
|
|
440
|
+
};
|
|
441
|
+
};
|
|
442
|
+
|
|
443
|
+
// src/CItemAPI.ts
|
|
444
|
+
var logger15 = logger_default.get("CItemAPI");
|
|
445
|
+
var createCItemApi = (api, type, pathNames, options) => {
|
|
446
|
+
logger15.default("createCItemApi", { api, type, pathNames, options });
|
|
447
|
+
const aItemAPI = createAItemAPI(api, type, pathNames, options);
|
|
448
|
+
return {
|
|
449
|
+
action: aItemAPI.action,
|
|
450
|
+
all: aItemAPI.all,
|
|
451
|
+
allAction: aItemAPI.allAction,
|
|
452
|
+
allFacet: aItemAPI.allFacet,
|
|
453
|
+
one: aItemAPI.one,
|
|
454
|
+
get: aItemAPI.get,
|
|
455
|
+
create: aItemAPI.create,
|
|
456
|
+
remove: aItemAPI.remove,
|
|
457
|
+
update: aItemAPI.update,
|
|
458
|
+
facet: aItemAPI.facet,
|
|
459
|
+
find: aItemAPI.find,
|
|
460
|
+
findOne: aItemAPI.findOne
|
|
461
|
+
};
|
|
462
|
+
};
|
|
463
|
+
|
|
464
|
+
// src/PItemAPI.ts
|
|
465
|
+
var logger16 = logger_default.get("PItemAPI");
|
|
466
|
+
var createPItemApi = (api, type, pathName, options) => {
|
|
467
|
+
logger16.default("createPItemApi", { type, pathName, options });
|
|
468
|
+
const aItemAPI = createAItemAPI(api, type, [pathName], options);
|
|
469
|
+
const action = async (ik, action2, body = {}) => await aItemAPI.action(ik, action2, body);
|
|
470
|
+
const all = async (query = {}) => await aItemAPI.all(query, []);
|
|
471
|
+
const allAction = async (action2, body = {}) => await aItemAPI.allAction(action2, body, []);
|
|
472
|
+
const allFacet = async (facet2, params = {}) => await aItemAPI.allFacet(facet2, params);
|
|
473
|
+
const one = async (query = {}) => await aItemAPI.one(query, []);
|
|
474
|
+
const get = async (ik) => await aItemAPI.get(ik);
|
|
475
|
+
const create = async (item) => await aItemAPI.create(item, []);
|
|
476
|
+
const remove = async (ik) => await aItemAPI.remove(ik);
|
|
477
|
+
const update = async (ik, item) => await aItemAPI.update(ik, item);
|
|
478
|
+
const facet = async (ik, facet2, params = {}) => await aItemAPI.facet(ik, facet2, params);
|
|
479
|
+
const find = async (finder, finderParams = {}) => await aItemAPI.find(finder, finderParams);
|
|
480
|
+
const findOne = async (finder, finderParams = {}) => await aItemAPI.findOne(finder, finderParams);
|
|
481
|
+
return {
|
|
482
|
+
...aItemAPI,
|
|
483
|
+
action,
|
|
484
|
+
all,
|
|
485
|
+
allAction,
|
|
486
|
+
allFacet,
|
|
487
|
+
one,
|
|
488
|
+
get,
|
|
489
|
+
create,
|
|
490
|
+
remove,
|
|
491
|
+
update,
|
|
492
|
+
facet,
|
|
493
|
+
find,
|
|
494
|
+
findOne
|
|
495
|
+
};
|
|
496
|
+
};
|
|
497
|
+
|
|
498
|
+
// src/Instance.ts
|
|
499
|
+
import { createInstance as createBaseInstance } from "@fjell/registry";
|
|
500
|
+
var logger17 = logger_default.get("Instance");
|
|
501
|
+
var createInstance = (registry, coordinate, clientApi) => {
|
|
502
|
+
logger17.debug("createInstance", { coordinate, clientApi, registry });
|
|
503
|
+
const baseInstance = createBaseInstance(registry, coordinate);
|
|
504
|
+
return { ...baseInstance, clientApi };
|
|
505
|
+
};
|
|
506
|
+
|
|
507
|
+
// src/InstanceFactory.ts
|
|
508
|
+
var logger18 = logger_default.get("InstanceFactory");
|
|
509
|
+
var createInstanceFactory = (clientApi) => {
|
|
510
|
+
return (coordinate, context) => {
|
|
511
|
+
logger18.debug("Creating client-api instance", { coordinate, registry: context.registry, clientApi });
|
|
512
|
+
return createInstance(context.registry, coordinate, clientApi);
|
|
513
|
+
};
|
|
514
|
+
};
|
|
515
|
+
|
|
516
|
+
// src/Registry.ts
|
|
517
|
+
import {
|
|
518
|
+
createRegistry as createBaseRegistry
|
|
519
|
+
} from "@fjell/registry";
|
|
520
|
+
var logger19 = logger_default.get("Registry");
|
|
521
|
+
var createRegistryFactory = () => {
|
|
522
|
+
return (type, registryHub) => {
|
|
523
|
+
if (type !== "client-api") {
|
|
524
|
+
throw new Error(`Client API registry factory can only create 'client-api' type registries, got: ${type}`);
|
|
525
|
+
}
|
|
526
|
+
logger19.debug("Creating client-api registry", { type, registryHub });
|
|
527
|
+
const baseRegistry = createBaseRegistry(type, registryHub);
|
|
528
|
+
return baseRegistry;
|
|
529
|
+
};
|
|
530
|
+
};
|
|
531
|
+
var createRegistry = (registryHub) => {
|
|
532
|
+
const baseRegistry = createBaseRegistry("client-api", registryHub);
|
|
533
|
+
return {
|
|
534
|
+
...baseRegistry
|
|
535
|
+
};
|
|
536
|
+
};
|
|
537
|
+
export {
|
|
538
|
+
createCItemApi,
|
|
539
|
+
createInstance,
|
|
540
|
+
createInstanceFactory,
|
|
541
|
+
createPItemApi,
|
|
542
|
+
createRegistry,
|
|
543
|
+
createRegistryFactory
|
|
544
|
+
};
|
|
6
545
|
//# sourceMappingURL=index.js.map
|