@monorise/react 3.0.2 → 3.0.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/index.js +2341 -50
- package/dist/index.js.map +1 -1
- package/dist/tsup.config.d.ts +3 -0
- package/dist/tsup.config.d.ts.map +1 -0
- package/package.json +5 -4
- package/dist/actions/app.action.js +0 -122
- package/dist/actions/app.action.js.map +0 -1
- package/dist/actions/auth.action.js +0 -63
- package/dist/actions/auth.action.js.map +0 -1
- package/dist/actions/config.action.js +0 -31
- package/dist/actions/config.action.js.map +0 -1
- package/dist/actions/core.action.js +0 -944
- package/dist/actions/core.action.js.map +0 -1
- package/dist/lib/api.js +0 -81
- package/dist/lib/api.js.map +0 -1
- package/dist/lib/constant.js +0 -2
- package/dist/lib/constant.js.map +0 -1
- package/dist/lib/entity.js +0 -42
- package/dist/lib/entity.js.map +0 -1
- package/dist/lib/utils.js +0 -44
- package/dist/lib/utils.js.map +0 -1
- package/dist/services/auth.service.js +0 -32
- package/dist/services/auth.service.js.map +0 -1
- package/dist/services/core.service.js +0 -171
- package/dist/services/core.service.js.map +0 -1
- package/dist/services/filestore.service.js +0 -135
- package/dist/services/filestore.service.js.map +0 -1
- package/dist/store/monorise.store.js +0 -52
- package/dist/store/monorise.store.js.map +0 -1
- package/dist/tsconfig.tsbuildinfo +0 -1
- package/dist/types/api.type.js +0 -11
- package/dist/types/api.type.js.map +0 -1
- package/dist/types/axios.type.js +0 -3
- package/dist/types/axios.type.js.map +0 -1
- package/dist/types/monorise.type.js +0 -2
- package/dist/types/monorise.type.js.map +0 -1
- package/dist/types/mutual.type.js +0 -2
- package/dist/types/mutual.type.js.map +0 -1
package/dist/index.js
CHANGED
|
@@ -1,53 +1,2344 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
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
|
-
|
|
1
|
+
var __defProp = Object.defineProperty;
|
|
2
|
+
var __defProps = Object.defineProperties;
|
|
3
|
+
var __getOwnPropDescs = Object.getOwnPropertyDescriptors;
|
|
4
|
+
var __getOwnPropSymbols = Object.getOwnPropertySymbols;
|
|
5
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
6
|
+
var __propIsEnum = Object.prototype.propertyIsEnumerable;
|
|
7
|
+
var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
|
|
8
|
+
var __spreadValues = (a, b) => {
|
|
9
|
+
for (var prop in b || (b = {}))
|
|
10
|
+
if (__hasOwnProp.call(b, prop))
|
|
11
|
+
__defNormalProp(a, prop, b[prop]);
|
|
12
|
+
if (__getOwnPropSymbols)
|
|
13
|
+
for (var prop of __getOwnPropSymbols(b)) {
|
|
14
|
+
if (__propIsEnum.call(b, prop))
|
|
15
|
+
__defNormalProp(a, prop, b[prop]);
|
|
16
|
+
}
|
|
17
|
+
return a;
|
|
18
|
+
};
|
|
19
|
+
var __spreadProps = (a, b) => __defProps(a, __getOwnPropDescs(b));
|
|
20
|
+
var __objRest = (source, exclude) => {
|
|
21
|
+
var target = {};
|
|
22
|
+
for (var prop in source)
|
|
23
|
+
if (__hasOwnProp.call(source, prop) && exclude.indexOf(prop) < 0)
|
|
24
|
+
target[prop] = source[prop];
|
|
25
|
+
if (source != null && __getOwnPropSymbols)
|
|
26
|
+
for (var prop of __getOwnPropSymbols(source)) {
|
|
27
|
+
if (exclude.indexOf(prop) < 0 && __propIsEnum.call(source, prop))
|
|
28
|
+
target[prop] = source[prop];
|
|
29
|
+
}
|
|
30
|
+
return target;
|
|
31
|
+
};
|
|
32
|
+
|
|
33
|
+
// actions/app.action.ts
|
|
34
|
+
import { produce } from "immer";
|
|
35
|
+
import { useEffect, useState } from "react";
|
|
36
|
+
var initAppActions = (store2) => {
|
|
37
|
+
let options = {};
|
|
38
|
+
const { modals = {} } = options;
|
|
39
|
+
const startLoading2 = ({
|
|
40
|
+
requestKey,
|
|
41
|
+
isInterruptive,
|
|
42
|
+
message,
|
|
43
|
+
request: request2
|
|
44
|
+
}) => {
|
|
45
|
+
store2.setState(
|
|
46
|
+
produce((state) => {
|
|
47
|
+
const stackType = isInterruptive ? "intLoadStack" : "loadStack";
|
|
48
|
+
const requestKeyCount = state.app[stackType].get(requestKey);
|
|
49
|
+
state.app.loadingMessage = typeof message === "string" ? message : "Loading";
|
|
50
|
+
state.app.ongoingRequests.set(requestKey, request2);
|
|
51
|
+
state.app[stackType].set(
|
|
52
|
+
requestKey,
|
|
53
|
+
requestKeyCount ? requestKeyCount + 1 : 1
|
|
54
|
+
);
|
|
55
|
+
}),
|
|
56
|
+
void 0,
|
|
57
|
+
`mr/start-loading/${requestKey}`
|
|
58
|
+
);
|
|
59
|
+
};
|
|
60
|
+
const endLoading2 = ({ requestKey, isInterruptive }) => {
|
|
61
|
+
setTimeout(() => {
|
|
62
|
+
store2.setState(
|
|
63
|
+
produce((state) => {
|
|
64
|
+
const stackType = isInterruptive ? "intLoadStack" : "loadStack";
|
|
65
|
+
const requestKeyCount = state.app[stackType].get(requestKey);
|
|
66
|
+
if (state.app.ongoingRequests.has(requestKey)) {
|
|
67
|
+
state.app.ongoingRequests.delete(requestKey);
|
|
68
|
+
}
|
|
69
|
+
if (typeof requestKeyCount === "number" && requestKeyCount > 1) {
|
|
70
|
+
state.app[stackType].set(requestKey, requestKeyCount - 1);
|
|
71
|
+
} else {
|
|
72
|
+
state.app[stackType].delete(requestKey);
|
|
73
|
+
}
|
|
74
|
+
}),
|
|
75
|
+
void 0,
|
|
76
|
+
`mr/end-loading/${requestKey}`
|
|
77
|
+
);
|
|
78
|
+
}, 500);
|
|
79
|
+
};
|
|
80
|
+
const checkIsLoading = (requestKey) => {
|
|
81
|
+
const { intLoadStack, loadStack } = store2.getState().app;
|
|
82
|
+
if (!requestKey) {
|
|
83
|
+
return intLoadStack.size > 0 || loadStack.size > 0;
|
|
84
|
+
}
|
|
85
|
+
const activeIntLoadingCount = intLoadStack.get(requestKey);
|
|
86
|
+
const isIntLoading = typeof activeIntLoadingCount === "number" && activeIntLoadingCount > 0;
|
|
87
|
+
const activeLoadingCount = loadStack.get(requestKey);
|
|
88
|
+
const isLoading = typeof activeLoadingCount === "number" && activeLoadingCount > 0;
|
|
89
|
+
return isIntLoading || isLoading;
|
|
90
|
+
};
|
|
91
|
+
const setError2 = ({ requestKey, error }) => store2.setState(
|
|
92
|
+
produce((state) => {
|
|
93
|
+
state.app.errorStack.set(requestKey, error);
|
|
94
|
+
}),
|
|
95
|
+
void 0,
|
|
96
|
+
`mr/set-error/${requestKey}`
|
|
97
|
+
);
|
|
98
|
+
const getError2 = (requestKey) => {
|
|
99
|
+
const { errorStack } = store2.getState().app;
|
|
100
|
+
return errorStack.get(requestKey);
|
|
101
|
+
};
|
|
102
|
+
const clearError2 = (requestKey) => {
|
|
103
|
+
const { errorStack } = store2.getState().app;
|
|
104
|
+
if (errorStack.has(requestKey)) {
|
|
105
|
+
store2.setState(
|
|
106
|
+
produce((state) => {
|
|
107
|
+
state.app.errorStack.delete(requestKey);
|
|
108
|
+
}),
|
|
109
|
+
void 0,
|
|
110
|
+
`mr/clear-error/${requestKey}`
|
|
111
|
+
);
|
|
112
|
+
}
|
|
113
|
+
};
|
|
114
|
+
const openModal2 = (modal) => store2.setState(
|
|
115
|
+
produce((state) => {
|
|
116
|
+
state.app.modal = modal;
|
|
117
|
+
}),
|
|
118
|
+
void 0,
|
|
119
|
+
`mr/open-modal/${modal.name}`
|
|
120
|
+
);
|
|
121
|
+
const closeModal2 = () => store2.setState(
|
|
122
|
+
produce((state) => {
|
|
123
|
+
state.app.modal = { name: null };
|
|
124
|
+
}),
|
|
125
|
+
void 0,
|
|
126
|
+
"mr/close-modal"
|
|
127
|
+
);
|
|
128
|
+
const useLoadStore2 = (requestKey) => {
|
|
129
|
+
const { loadStack, intLoadStack } = store2((state) => ({
|
|
130
|
+
loadStack: state.app.loadStack,
|
|
131
|
+
intLoadStack: state.app.intLoadStack
|
|
132
|
+
}));
|
|
133
|
+
const [isLoading, setIsLoading] = useState(false);
|
|
134
|
+
useEffect(() => {
|
|
135
|
+
if (loadStack && intLoadStack && requestKey) {
|
|
136
|
+
setIsLoading(checkIsLoading(requestKey));
|
|
137
|
+
}
|
|
138
|
+
}, [loadStack, intLoadStack, requestKey]);
|
|
139
|
+
return isLoading;
|
|
140
|
+
};
|
|
141
|
+
const useInterruptiveLoadStore2 = () => {
|
|
142
|
+
const { intLoadStack, loadingMessage } = store2((state) => ({
|
|
143
|
+
intLoadStack: state.app.intLoadStack,
|
|
144
|
+
loadingMessage: state.app.loadingMessage
|
|
145
|
+
}));
|
|
146
|
+
return {
|
|
147
|
+
isLoading: intLoadStack.size > 0,
|
|
148
|
+
message: loadingMessage
|
|
149
|
+
};
|
|
150
|
+
};
|
|
151
|
+
const useErrorStore2 = (requestKey) => {
|
|
152
|
+
const error = store2((state) => state.app.errorStack.get(requestKey));
|
|
153
|
+
useEffect(() => {
|
|
154
|
+
if (error) {
|
|
155
|
+
return () => {
|
|
156
|
+
clearError2(requestKey);
|
|
157
|
+
};
|
|
158
|
+
}
|
|
159
|
+
}, [error, requestKey]);
|
|
160
|
+
return error;
|
|
161
|
+
};
|
|
162
|
+
const useModalStore2 = () => {
|
|
163
|
+
return store2((state) => state.app.modal);
|
|
164
|
+
};
|
|
165
|
+
const setOptions = (opts) => {
|
|
166
|
+
options = __spreadValues(__spreadValues({}, options), opts);
|
|
167
|
+
};
|
|
168
|
+
return {
|
|
169
|
+
startLoading: startLoading2,
|
|
170
|
+
endLoading: endLoading2,
|
|
171
|
+
setError: setError2,
|
|
172
|
+
getError: getError2,
|
|
173
|
+
clearError: clearError2,
|
|
174
|
+
openModal: openModal2,
|
|
175
|
+
closeModal: closeModal2,
|
|
176
|
+
checkIsLoading,
|
|
177
|
+
useLoadStore: useLoadStore2,
|
|
178
|
+
useInterruptiveLoadStore: useInterruptiveLoadStore2,
|
|
179
|
+
useErrorStore: useErrorStore2,
|
|
180
|
+
useModalStore: useModalStore2,
|
|
181
|
+
setOptions
|
|
182
|
+
};
|
|
183
|
+
};
|
|
184
|
+
|
|
185
|
+
// actions/auth.action.ts
|
|
186
|
+
import { produce as produce2 } from "immer";
|
|
187
|
+
var initAuthActions = (store2, authService2) => {
|
|
188
|
+
const requestLogin2 = async (entityType, payload) => {
|
|
189
|
+
const { data } = await authService2.requestLoginMagicLink(
|
|
190
|
+
entityType,
|
|
191
|
+
payload
|
|
192
|
+
);
|
|
193
|
+
return data;
|
|
194
|
+
};
|
|
195
|
+
const useProfile2 = () => {
|
|
196
|
+
const profile = store2((state) => state.auth.profile);
|
|
197
|
+
return profile;
|
|
198
|
+
};
|
|
199
|
+
const getProfile2 = async () => {
|
|
200
|
+
try {
|
|
201
|
+
const {
|
|
202
|
+
data: _a
|
|
203
|
+
} = await authService2.getSessionProfile(), _b = _a, { displayName, email, accountId } = _b, rest = __objRest(_b, ["displayName", "email", "accountId"]);
|
|
204
|
+
store2.setState(
|
|
205
|
+
produce2((state) => {
|
|
206
|
+
state.auth.profile = __spreadValues({ displayName, email, accountId }, rest);
|
|
207
|
+
state.auth.isUnauthorized = false;
|
|
208
|
+
state.auth.isLoading = false;
|
|
209
|
+
}),
|
|
210
|
+
void 0,
|
|
211
|
+
"mr/auth/get-profile"
|
|
212
|
+
);
|
|
213
|
+
} catch (e) {
|
|
214
|
+
store2.setState(
|
|
215
|
+
produce2((state) => {
|
|
216
|
+
state.auth.profile = {};
|
|
217
|
+
state.auth.isUnauthorized = true;
|
|
218
|
+
state.auth.isLoading = false;
|
|
219
|
+
}),
|
|
220
|
+
void 0,
|
|
221
|
+
"mr/auth/get-profile"
|
|
222
|
+
);
|
|
223
|
+
}
|
|
224
|
+
};
|
|
225
|
+
const useIsUnauthorized2 = () => {
|
|
226
|
+
const { isUnauthorized, profile, isLoading } = store2((state) => state.auth);
|
|
227
|
+
return { isUnauthorized: isUnauthorized && !profile.accountId, isLoading };
|
|
228
|
+
};
|
|
229
|
+
const setIsUnauthorized2 = (isUnauthorized) => store2.setState(
|
|
230
|
+
produce2((state) => {
|
|
231
|
+
state.auth.isUnauthorized = isUnauthorized;
|
|
232
|
+
})
|
|
233
|
+
);
|
|
234
|
+
const logout2 = () => {
|
|
235
|
+
authService2.logout();
|
|
236
|
+
store2.setState(
|
|
237
|
+
produce2((state) => {
|
|
238
|
+
state.auth.isUnauthorized = true;
|
|
239
|
+
state.auth.profile = {};
|
|
240
|
+
})
|
|
241
|
+
);
|
|
242
|
+
};
|
|
243
|
+
return {
|
|
244
|
+
requestLogin: requestLogin2,
|
|
245
|
+
useProfile: useProfile2,
|
|
246
|
+
getProfile: getProfile2,
|
|
247
|
+
useIsUnauthorized: useIsUnauthorized2,
|
|
248
|
+
setIsUnauthorized: setIsUnauthorized2,
|
|
249
|
+
logout: logout2
|
|
250
|
+
};
|
|
251
|
+
};
|
|
252
|
+
|
|
253
|
+
// actions/config.action.ts
|
|
254
|
+
import { produce as produce3 } from "immer";
|
|
255
|
+
var initConfigActions = (store2) => {
|
|
256
|
+
const setConfig2 = (config) => {
|
|
257
|
+
const entityMaps = Object.keys(config).reduce(
|
|
258
|
+
(acc, entity) => {
|
|
259
|
+
acc[entity] = {
|
|
260
|
+
dataMap: /* @__PURE__ */ new Map(),
|
|
261
|
+
isFirstFetched: false,
|
|
262
|
+
lastKey: ""
|
|
263
|
+
};
|
|
264
|
+
return acc;
|
|
265
|
+
},
|
|
266
|
+
{}
|
|
267
|
+
);
|
|
268
|
+
store2.setState(
|
|
269
|
+
produce3((state) => {
|
|
270
|
+
state.config = config;
|
|
271
|
+
state.entity = entityMaps;
|
|
272
|
+
})
|
|
273
|
+
);
|
|
274
|
+
};
|
|
275
|
+
const getConfig2 = () => {
|
|
276
|
+
return store2.getState().config;
|
|
277
|
+
};
|
|
278
|
+
const useConfig2 = () => {
|
|
279
|
+
const config = store2((state) => state.config);
|
|
280
|
+
return config;
|
|
281
|
+
};
|
|
282
|
+
return {
|
|
283
|
+
setConfig: setConfig2,
|
|
284
|
+
getConfig: getConfig2,
|
|
285
|
+
useConfig: useConfig2
|
|
286
|
+
};
|
|
287
|
+
};
|
|
288
|
+
|
|
289
|
+
// actions/core.action.ts
|
|
290
|
+
import { produce as produce4 } from "immer";
|
|
291
|
+
import { useEffect as useEffect2, useState as useState2 } from "react";
|
|
292
|
+
|
|
293
|
+
// lib/entity.ts
|
|
294
|
+
var constructLocal = (entityType, entityId, data) => {
|
|
295
|
+
return {
|
|
296
|
+
entityType,
|
|
297
|
+
entityId,
|
|
298
|
+
data,
|
|
299
|
+
createdAt: (/* @__PURE__ */ new Date()).toISOString(),
|
|
300
|
+
updatedAt: (/* @__PURE__ */ new Date()).toISOString()
|
|
301
|
+
};
|
|
302
|
+
};
|
|
303
|
+
var constructMutual = (byEntityType, byEntityId2, entityType, entityId, mutualData, data) => {
|
|
304
|
+
return {
|
|
305
|
+
mutualId: `${byEntityId2}-${entityId}`,
|
|
306
|
+
byEntityType,
|
|
307
|
+
byEntityId: byEntityId2,
|
|
308
|
+
entityType,
|
|
309
|
+
entityId,
|
|
310
|
+
mutualData,
|
|
311
|
+
data,
|
|
312
|
+
createdAt: (/* @__PURE__ */ new Date()).toISOString(),
|
|
313
|
+
updatedAt: (/* @__PURE__ */ new Date()).toISOString(),
|
|
314
|
+
mutualUpdatedAt: (/* @__PURE__ */ new Date()).toISOString()
|
|
315
|
+
};
|
|
316
|
+
};
|
|
317
|
+
var flipMutual = (mutual) => {
|
|
318
|
+
return __spreadProps(__spreadValues({}, mutual), {
|
|
319
|
+
entityId: mutual.byEntityId,
|
|
320
|
+
entityType: mutual.byEntityType,
|
|
321
|
+
byEntityId: mutual.entityId,
|
|
322
|
+
byEntityType: mutual.entityType
|
|
323
|
+
});
|
|
324
|
+
};
|
|
325
|
+
var byEntityId = (a, b) => {
|
|
326
|
+
if (b.entityId < a.entityId) return -1;
|
|
327
|
+
return 1;
|
|
328
|
+
};
|
|
329
|
+
|
|
330
|
+
// lib/utils.ts
|
|
331
|
+
var convertToMap = (data, mapKey) => {
|
|
332
|
+
const map = /* @__PURE__ */ new Map();
|
|
333
|
+
for (const i in data) {
|
|
334
|
+
map.set(data[i][mapKey], data[i]);
|
|
335
|
+
}
|
|
336
|
+
return map;
|
|
337
|
+
};
|
|
338
|
+
var getMutualStateKey = (byEntity, byEntityId2, entity, entityId, chainEntityQuery) => {
|
|
339
|
+
return `${byEntity}/${byEntityId2}/${entity}${entityId ? `/${entityId}` : ""}${chainEntityQuery ? `?${chainEntityQuery}` : ""}`;
|
|
340
|
+
};
|
|
341
|
+
var getTagStateKey = (entityType, tagName, params = {}) => {
|
|
342
|
+
const _a = params, { lastKey } = _a, stateParams = __objRest(_a, ["lastKey"]);
|
|
343
|
+
const paramsKey = Object.keys(stateParams).map((key) => `${key}:${stateParams[key]}`).join("/");
|
|
344
|
+
return `${entityType}/${tagName}/${paramsKey}`;
|
|
345
|
+
};
|
|
346
|
+
var getUniqueFieldStateKey = (fieldName, fieldValue) => {
|
|
347
|
+
return `${fieldName}/${fieldValue}`;
|
|
348
|
+
};
|
|
349
|
+
var getEntityRequestKey = (mode, entityType, entityId) => {
|
|
350
|
+
return `entity/${entityType}/${mode}${entityId ? `/${entityId}` : ""}`;
|
|
351
|
+
};
|
|
352
|
+
var getMutualRequestKey = (mode, byEntityType, entityType, byEntityId2, entityId, chainEntityQuery) => {
|
|
353
|
+
return `mutual/${getMutualStateKey(byEntityType, byEntityId2, entityType, entityId, chainEntityQuery)}/${mode}`;
|
|
354
|
+
};
|
|
355
|
+
var getTagRequestKey = (mode, entityType, tagName, params = {}) => {
|
|
356
|
+
return `tag/${getTagStateKey(entityType, tagName, params)}/${mode}`;
|
|
357
|
+
};
|
|
358
|
+
var getUniqueFieldRequestKey = (entityType, fieldName, value) => {
|
|
359
|
+
return `entity/${entityType}/unique/${getUniqueFieldStateKey(fieldName, value)}`;
|
|
360
|
+
};
|
|
361
|
+
|
|
362
|
+
// actions/core.action.ts
|
|
363
|
+
var defaultOnError = (error) => {
|
|
364
|
+
if (!(error instanceof Error) && error.status >= 500) {
|
|
365
|
+
throw error;
|
|
366
|
+
}
|
|
367
|
+
};
|
|
368
|
+
var initCoreActions = (monoriseStore, appActions, coreService2) => {
|
|
369
|
+
const { makeEntityService, makeMutualService } = coreService2;
|
|
370
|
+
const { checkIsLoading, getError: getError2, useLoadStore: useLoadStore2, useErrorStore: useErrorStore2 } = appActions;
|
|
371
|
+
const listEntities = async (entityType, params = {}, opts = {}) => {
|
|
372
|
+
var _a, _b;
|
|
373
|
+
const store2 = monoriseStore.getState();
|
|
374
|
+
const entityState = (_a = store2.entity[entityType]) != null ? _a : {};
|
|
375
|
+
const { isFirstFetched } = entityState;
|
|
376
|
+
const entityService = makeEntityService(entityType);
|
|
377
|
+
const { skRange } = params;
|
|
378
|
+
const requestKey = getEntityRequestKey("list", entityType);
|
|
379
|
+
const isLoading = checkIsLoading(requestKey);
|
|
380
|
+
const error = getError2(requestKey);
|
|
381
|
+
const onError = (_b = opts.onError) != null ? _b : defaultOnError;
|
|
382
|
+
if (error) {
|
|
383
|
+
onError(error);
|
|
384
|
+
return;
|
|
385
|
+
}
|
|
386
|
+
if (!opts.forceFetch && (isFirstFetched && !params.skRange || isLoading)) {
|
|
387
|
+
return;
|
|
388
|
+
}
|
|
389
|
+
try {
|
|
390
|
+
const { data: result } = await entityService.listEntities(
|
|
391
|
+
__spreadProps(__spreadValues({}, (params == null ? void 0 : params.all) ? {} : { limit: 20 }), {
|
|
392
|
+
start: skRange == null ? void 0 : skRange.start,
|
|
393
|
+
end: skRange == null ? void 0 : skRange.end
|
|
394
|
+
}),
|
|
395
|
+
opts
|
|
396
|
+
);
|
|
397
|
+
const newEntityMap = convertToMap(
|
|
398
|
+
result.data,
|
|
399
|
+
"entityId"
|
|
400
|
+
);
|
|
401
|
+
const mergedMap = new Map([
|
|
402
|
+
...newEntityMap,
|
|
403
|
+
...store2.entity[entityType].dataMap
|
|
404
|
+
]);
|
|
405
|
+
monoriseStore.setState(
|
|
406
|
+
produce4((state) => {
|
|
407
|
+
state.entity[entityType] = {
|
|
408
|
+
dataMap: params.skRange ? newEntityMap : mergedMap,
|
|
409
|
+
isFirstFetched: true,
|
|
410
|
+
lastKey: result.lastKey
|
|
411
|
+
};
|
|
412
|
+
}),
|
|
413
|
+
void 0,
|
|
414
|
+
`mr/entity/list/${entityType}`
|
|
415
|
+
);
|
|
416
|
+
} catch (err) {
|
|
417
|
+
const error2 = err instanceof Error ? err : new Error("Unknown error occurred");
|
|
418
|
+
return { error: error2 };
|
|
419
|
+
}
|
|
420
|
+
};
|
|
421
|
+
const listMoreEntities2 = async (entityType, opts = {}) => {
|
|
422
|
+
var _a;
|
|
423
|
+
const requestKey = getEntityRequestKey("list", entityType);
|
|
424
|
+
const store2 = monoriseStore.getState();
|
|
425
|
+
const entityState = store2.entity[entityType];
|
|
426
|
+
const { dataMap, lastKey } = entityState;
|
|
427
|
+
const entityService = makeEntityService(entityType);
|
|
428
|
+
const error = getError2(requestKey);
|
|
429
|
+
const onError = (_a = opts.onError) != null ? _a : defaultOnError;
|
|
430
|
+
if (!lastKey) {
|
|
431
|
+
return;
|
|
432
|
+
}
|
|
433
|
+
if (error) {
|
|
434
|
+
onError(error);
|
|
435
|
+
return;
|
|
436
|
+
}
|
|
437
|
+
try {
|
|
438
|
+
const { data: result } = await entityService.listEntities(
|
|
439
|
+
{
|
|
440
|
+
limit: 20,
|
|
441
|
+
lastKey
|
|
442
|
+
},
|
|
443
|
+
opts
|
|
444
|
+
);
|
|
445
|
+
monoriseStore.setState(
|
|
446
|
+
produce4((state) => {
|
|
447
|
+
state.entity[entityType].isFirstFetched = true;
|
|
448
|
+
state.entity[entityType].lastKey = result.lastKey;
|
|
449
|
+
for (const i in result.data) {
|
|
450
|
+
state.entity[entityType].dataMap.set(
|
|
451
|
+
result.data[i].entityId,
|
|
452
|
+
result.data[i]
|
|
453
|
+
);
|
|
454
|
+
}
|
|
455
|
+
}),
|
|
456
|
+
void 0,
|
|
457
|
+
`mr/entity/list-more/${entityType}`
|
|
458
|
+
);
|
|
459
|
+
} catch (err) {
|
|
460
|
+
const error2 = err instanceof Error ? err : new Error("Unknown error occurred");
|
|
461
|
+
return { error: error2 };
|
|
462
|
+
}
|
|
463
|
+
};
|
|
464
|
+
const searchEntities = async (entityType, query, opts = {}) => {
|
|
465
|
+
var _a;
|
|
466
|
+
const requestKey = getEntityRequestKey("search", entityType);
|
|
467
|
+
const entityService = makeEntityService(entityType);
|
|
468
|
+
const error = getError2(requestKey);
|
|
469
|
+
const onError = (_a = opts.onError) != null ? _a : defaultOnError;
|
|
470
|
+
if (error) {
|
|
471
|
+
onError(error);
|
|
472
|
+
return;
|
|
473
|
+
}
|
|
474
|
+
try {
|
|
475
|
+
const { data: result } = await entityService.searchEntities(query, opts);
|
|
476
|
+
monoriseStore.setState(
|
|
477
|
+
produce4((state) => {
|
|
478
|
+
state.entity[entityType].searchResults = result.data;
|
|
479
|
+
for (const i in result.data) {
|
|
480
|
+
state.entity[entityType].dataMap.set(
|
|
481
|
+
result.data[i].entityId,
|
|
482
|
+
result.data[i]
|
|
483
|
+
);
|
|
484
|
+
}
|
|
485
|
+
})
|
|
486
|
+
);
|
|
487
|
+
} catch (err) {
|
|
488
|
+
const error2 = err instanceof Error ? err : new Error("Unknown error occurred");
|
|
489
|
+
return { error: error2 };
|
|
490
|
+
}
|
|
491
|
+
};
|
|
492
|
+
const listEntitiesByTag = async (entityType, tagName, opts = {}) => {
|
|
493
|
+
var _a;
|
|
494
|
+
const tagKey = getTagStateKey(entityType, tagName, opts.params);
|
|
495
|
+
const state = monoriseStore.getState();
|
|
496
|
+
const tagState = state.tag[tagKey] || {};
|
|
497
|
+
const { isFirstFetched, dataMap } = tagState;
|
|
498
|
+
const entityService = makeEntityService(entityType);
|
|
499
|
+
const { forceFetch } = opts;
|
|
500
|
+
const requestKey = getTagRequestKey(
|
|
501
|
+
"list",
|
|
502
|
+
entityType,
|
|
503
|
+
tagName,
|
|
504
|
+
opts.params
|
|
505
|
+
);
|
|
506
|
+
const isLoading = checkIsLoading(requestKey);
|
|
507
|
+
const error = getError2(requestKey);
|
|
508
|
+
const onError = (_a = opts.onError) != null ? _a : defaultOnError;
|
|
509
|
+
if (!forceFetch) {
|
|
510
|
+
if (error) {
|
|
511
|
+
onError(error);
|
|
512
|
+
return { error };
|
|
513
|
+
}
|
|
514
|
+
if (isFirstFetched || isLoading) {
|
|
515
|
+
return {
|
|
516
|
+
data: {
|
|
517
|
+
entities: Array.from((dataMap == null ? void 0 : dataMap.values()) || []),
|
|
518
|
+
lastKey: null
|
|
519
|
+
}
|
|
520
|
+
};
|
|
521
|
+
}
|
|
522
|
+
}
|
|
523
|
+
try {
|
|
524
|
+
const { data } = await entityService.listEntitiesByTag(tagName, __spreadProps(__spreadValues({}, opts), {
|
|
525
|
+
requestKey
|
|
526
|
+
}));
|
|
527
|
+
const { entities, lastKey } = data;
|
|
528
|
+
monoriseStore.setState(
|
|
529
|
+
produce4((state2) => {
|
|
530
|
+
for (const entity of entities) {
|
|
531
|
+
state2.entity[entityType].dataMap.set(entity.entityId, entity);
|
|
532
|
+
}
|
|
533
|
+
})
|
|
534
|
+
);
|
|
535
|
+
monoriseStore.setState(
|
|
536
|
+
produce4((state2) => {
|
|
537
|
+
if (!state2.tag[tagKey]) {
|
|
538
|
+
state2.tag[tagKey] = {
|
|
539
|
+
dataMap: /* @__PURE__ */ new Map(),
|
|
540
|
+
isFirstFetched: false
|
|
541
|
+
};
|
|
542
|
+
}
|
|
543
|
+
for (const entity of entities) {
|
|
544
|
+
state2.tag[tagKey].dataMap.set(entity.entityId, entity);
|
|
545
|
+
}
|
|
546
|
+
state2.tag[tagKey].isFirstFetched = true;
|
|
547
|
+
state2.tag[tagKey].lastKey = lastKey;
|
|
548
|
+
})
|
|
549
|
+
);
|
|
550
|
+
return { data };
|
|
551
|
+
} catch (err) {
|
|
552
|
+
const error2 = err instanceof Error ? err : new Error("Unknown error occurred");
|
|
553
|
+
return { error: error2 };
|
|
554
|
+
}
|
|
555
|
+
};
|
|
556
|
+
const getEntity2 = async (entityType, id, opts = {}) => {
|
|
557
|
+
var _a;
|
|
558
|
+
const store2 = monoriseStore.getState();
|
|
559
|
+
const entityState = store2.entity[entityType];
|
|
560
|
+
const { dataMap } = entityState;
|
|
561
|
+
const entityService = makeEntityService(entityType);
|
|
562
|
+
let entity = dataMap.get(id);
|
|
563
|
+
const requestKey = getEntityRequestKey("get", entityType, id);
|
|
564
|
+
const isLoading = checkIsLoading(requestKey);
|
|
565
|
+
const error = getError2(requestKey);
|
|
566
|
+
const { forceFetch } = opts;
|
|
567
|
+
const onError = (_a = opts.onError) != null ? _a : defaultOnError;
|
|
568
|
+
if (!forceFetch) {
|
|
569
|
+
if (error) {
|
|
570
|
+
onError == null ? void 0 : onError(error);
|
|
571
|
+
return { error };
|
|
572
|
+
}
|
|
573
|
+
if (entity) {
|
|
574
|
+
return { data: entity };
|
|
575
|
+
}
|
|
576
|
+
if (isLoading) {
|
|
577
|
+
return {};
|
|
578
|
+
}
|
|
579
|
+
}
|
|
580
|
+
try {
|
|
581
|
+
({ data: entity } = await entityService.getEntity(id, opts));
|
|
582
|
+
monoriseStore.setState(
|
|
583
|
+
produce4((state) => {
|
|
584
|
+
state.entity[entityType].dataMap.set(entity == null ? void 0 : entity.entityId, entity);
|
|
585
|
+
}),
|
|
586
|
+
void 0,
|
|
587
|
+
`mr/entity/get/${entityType}/${id}`
|
|
588
|
+
);
|
|
589
|
+
return { data: entity };
|
|
590
|
+
} catch (err) {
|
|
591
|
+
const error2 = err instanceof Error ? err : new Error("Unknown error occurred");
|
|
592
|
+
return { error: error2 };
|
|
593
|
+
}
|
|
594
|
+
};
|
|
595
|
+
const getEntityByUniqueField = async (entityType, fieldName, value, opts = {}) => {
|
|
596
|
+
var _a;
|
|
597
|
+
const store2 = monoriseStore.getState();
|
|
598
|
+
const entityState = store2.entity[entityType];
|
|
599
|
+
const { dataMap } = entityState;
|
|
600
|
+
const entityService = makeEntityService(entityType);
|
|
601
|
+
const stateKey = getUniqueFieldStateKey(fieldName, value);
|
|
602
|
+
let entity = dataMap.get(stateKey);
|
|
603
|
+
const requestKey = getUniqueFieldRequestKey(entityType, fieldName, value);
|
|
604
|
+
const isLoading = checkIsLoading(requestKey);
|
|
605
|
+
const error = getError2(requestKey);
|
|
606
|
+
const { forceFetch } = opts;
|
|
607
|
+
const onError = (_a = opts.onError) != null ? _a : defaultOnError;
|
|
608
|
+
if (!forceFetch) {
|
|
609
|
+
if (error) {
|
|
610
|
+
onError == null ? void 0 : onError(error);
|
|
611
|
+
return { error };
|
|
612
|
+
}
|
|
613
|
+
if (entity) {
|
|
614
|
+
return { data: entity };
|
|
615
|
+
}
|
|
616
|
+
if (isLoading) {
|
|
617
|
+
return {};
|
|
618
|
+
}
|
|
619
|
+
}
|
|
620
|
+
try {
|
|
621
|
+
({ data: entity } = await entityService.getEntityByUniqueField(
|
|
622
|
+
fieldName,
|
|
623
|
+
value,
|
|
624
|
+
opts
|
|
625
|
+
));
|
|
626
|
+
monoriseStore.setState(
|
|
627
|
+
produce4((state) => {
|
|
628
|
+
state.entity[entityType].dataMap.set(entity == null ? void 0 : entity.entityId, entity);
|
|
629
|
+
state.entity[entityType].dataMap.set(`${stateKey}`, entity);
|
|
630
|
+
}),
|
|
631
|
+
void 0,
|
|
632
|
+
`mr/entity/unique/${entityType}/${stateKey}`
|
|
633
|
+
);
|
|
634
|
+
return { data: entity };
|
|
635
|
+
} catch (err) {
|
|
636
|
+
const error2 = err instanceof Error ? err : new Error("Unknown error occurred");
|
|
637
|
+
return { error: error2 };
|
|
638
|
+
}
|
|
639
|
+
};
|
|
640
|
+
const createEntity2 = async (entityType, entity, opts = {}) => {
|
|
641
|
+
var _a;
|
|
642
|
+
const entityService = makeEntityService(entityType);
|
|
643
|
+
const onError = (_a = opts.onError) != null ? _a : defaultOnError;
|
|
644
|
+
try {
|
|
645
|
+
const { data } = await entityService.createEntity(entity, opts);
|
|
646
|
+
monoriseStore.setState(
|
|
647
|
+
produce4((state) => {
|
|
648
|
+
state.entity[entityType].dataMap.set(data.entityId, data);
|
|
649
|
+
}),
|
|
650
|
+
void 0,
|
|
651
|
+
`mr/entity/create/${entityType}`
|
|
652
|
+
);
|
|
653
|
+
return { data };
|
|
654
|
+
} catch (err) {
|
|
655
|
+
const error = err instanceof Error ? err : new Error("Unknown error occurred");
|
|
656
|
+
onError == null ? void 0 : onError(error);
|
|
657
|
+
return { error };
|
|
658
|
+
}
|
|
659
|
+
};
|
|
660
|
+
const upsertEntity2 = async (entityType, id, entity, opts = {}) => {
|
|
661
|
+
var _a;
|
|
662
|
+
const entityService = makeEntityService(entityType);
|
|
663
|
+
const onError = (_a = opts.onError) != null ? _a : defaultOnError;
|
|
664
|
+
try {
|
|
665
|
+
const { data } = await entityService.upsertEntity(id, entity, opts);
|
|
666
|
+
monoriseStore.setState(
|
|
667
|
+
produce4((state) => {
|
|
668
|
+
state.entity[entityType].dataMap.set(data.entityId, data);
|
|
669
|
+
}),
|
|
670
|
+
void 0,
|
|
671
|
+
`mr/entity/upsert/${entityType}/${id}`
|
|
672
|
+
);
|
|
673
|
+
return { data };
|
|
674
|
+
} catch (err) {
|
|
675
|
+
const error = err instanceof Error ? err : new Error("Unknown error occurred");
|
|
676
|
+
onError(error);
|
|
677
|
+
return { error };
|
|
678
|
+
}
|
|
679
|
+
};
|
|
680
|
+
const editEntity2 = async (entityType, id, entity, opts = {}) => {
|
|
681
|
+
var _a;
|
|
682
|
+
const entityService = makeEntityService(entityType);
|
|
683
|
+
const onError = (_a = opts.onError) != null ? _a : defaultOnError;
|
|
684
|
+
try {
|
|
685
|
+
const { data } = await entityService.editEntity(id, entity, opts);
|
|
686
|
+
monoriseStore.setState(
|
|
687
|
+
produce4((state) => {
|
|
688
|
+
state.entity[entityType].dataMap.set(data.entityId, data);
|
|
689
|
+
for (const key of Object.keys(state.mutual)) {
|
|
690
|
+
const [_byEntity, _byId, _entityType] = key.split("/");
|
|
691
|
+
if (_entityType === entityType) {
|
|
692
|
+
const mutual = state.mutual[key].dataMap.get(id);
|
|
693
|
+
if (mutual) {
|
|
694
|
+
state.mutual[key].dataMap = new Map(
|
|
695
|
+
state.mutual[key].dataMap
|
|
696
|
+
).set(id, __spreadProps(__spreadValues({}, mutual), { data: data.data }));
|
|
697
|
+
}
|
|
698
|
+
}
|
|
699
|
+
}
|
|
700
|
+
}),
|
|
701
|
+
void 0,
|
|
702
|
+
`mr/entity/edit/${entityType}/${id}`
|
|
703
|
+
);
|
|
704
|
+
return { data };
|
|
705
|
+
} catch (err) {
|
|
706
|
+
const error = err instanceof Error ? err : new Error("Unknown error occurred");
|
|
707
|
+
onError(error);
|
|
708
|
+
return { error };
|
|
709
|
+
}
|
|
710
|
+
};
|
|
711
|
+
const deleteEntity2 = async (entityType, id, opts = {}) => {
|
|
712
|
+
var _a;
|
|
713
|
+
const entityService = makeEntityService(entityType);
|
|
714
|
+
const onError = (_a = opts.onError) != null ? _a : defaultOnError;
|
|
715
|
+
try {
|
|
716
|
+
await entityService.deleteEntity(id, opts);
|
|
717
|
+
deleteLocalMutualsByEntity(entityType, id);
|
|
718
|
+
monoriseStore.setState(
|
|
719
|
+
produce4((state) => {
|
|
720
|
+
state.entity[entityType].dataMap.delete(id);
|
|
721
|
+
for (const key of Object.keys(state.mutual)) {
|
|
722
|
+
const [_byEntity, _byId, _entityType] = key.split("/");
|
|
723
|
+
if (_entityType === entityType) {
|
|
724
|
+
state.mutual[key].dataMap.delete(id);
|
|
725
|
+
}
|
|
726
|
+
}
|
|
727
|
+
}),
|
|
728
|
+
void 0,
|
|
729
|
+
`mr/entity/delete/${entityType}/${id}`
|
|
730
|
+
);
|
|
731
|
+
return { data: { entityId: id } };
|
|
732
|
+
} catch (err) {
|
|
733
|
+
const error = err instanceof Error ? err : new Error("Unknown error occurred");
|
|
734
|
+
onError(error);
|
|
735
|
+
return { error };
|
|
736
|
+
}
|
|
737
|
+
};
|
|
738
|
+
const listEntitiesByEntity = async (byEntityType, entityType, id, opts = {}, chainEntityQuery) => {
|
|
739
|
+
var _a, _b, _c;
|
|
740
|
+
const onError = (_a = opts.onError) != null ? _a : defaultOnError;
|
|
741
|
+
const selfKey = (_b = opts.stateKey) != null ? _b : getMutualStateKey(
|
|
742
|
+
byEntityType,
|
|
743
|
+
id,
|
|
744
|
+
entityType,
|
|
745
|
+
void 0,
|
|
746
|
+
chainEntityQuery
|
|
747
|
+
);
|
|
748
|
+
const mutualService = makeMutualService(byEntityType, entityType);
|
|
749
|
+
const store2 = monoriseStore.getState();
|
|
750
|
+
const mutualState = store2.mutual[selfKey] || {};
|
|
751
|
+
const { isFirstFetched } = mutualState;
|
|
752
|
+
const requestKey = getMutualRequestKey(
|
|
753
|
+
"list",
|
|
754
|
+
byEntityType,
|
|
755
|
+
entityType,
|
|
756
|
+
id,
|
|
757
|
+
void 0,
|
|
758
|
+
chainEntityQuery
|
|
759
|
+
);
|
|
760
|
+
const isLoading = checkIsLoading(requestKey);
|
|
761
|
+
const error = getError2(requestKey);
|
|
762
|
+
const { forceFetch } = opts;
|
|
763
|
+
if (!forceFetch) {
|
|
764
|
+
if (error) {
|
|
765
|
+
onError(error);
|
|
766
|
+
return { error };
|
|
767
|
+
}
|
|
768
|
+
if (isFirstFetched || isLoading) {
|
|
769
|
+
return {
|
|
770
|
+
data: {
|
|
771
|
+
entities: Array.from(((_c = mutualState.dataMap) == null ? void 0 : _c.values()) || []),
|
|
772
|
+
lastKey: mutualState.lastKey
|
|
773
|
+
}
|
|
774
|
+
};
|
|
775
|
+
}
|
|
776
|
+
}
|
|
777
|
+
try {
|
|
778
|
+
const { data } = await mutualService.listEntitiesByEntity(
|
|
779
|
+
id,
|
|
780
|
+
opts,
|
|
781
|
+
chainEntityQuery
|
|
782
|
+
);
|
|
783
|
+
const { entities, lastKey } = data;
|
|
784
|
+
const newEntityDataMap = /* @__PURE__ */ new Map();
|
|
785
|
+
for (const i in entities) {
|
|
786
|
+
newEntityDataMap.set(entities[i].entityId, entities[i]);
|
|
787
|
+
}
|
|
788
|
+
monoriseStore.setState(
|
|
789
|
+
produce4((state) => {
|
|
790
|
+
var _a2;
|
|
791
|
+
for (const [key, value] of newEntityDataMap) {
|
|
792
|
+
(_a2 = state.entity[entityType]) == null ? void 0 : _a2.dataMap.set(key, value);
|
|
793
|
+
}
|
|
794
|
+
const existing = state.mutual[selfKey];
|
|
795
|
+
if (existing) {
|
|
796
|
+
const incoming = convertToMap(entities, "entityId");
|
|
797
|
+
for (const [k, v] of incoming) {
|
|
798
|
+
existing.dataMap.set(k, v);
|
|
799
|
+
}
|
|
800
|
+
existing.isFirstFetched = true;
|
|
801
|
+
existing.lastKey = lastKey;
|
|
802
|
+
} else {
|
|
803
|
+
state.mutual[selfKey] = {
|
|
804
|
+
dataMap: convertToMap(entities, "entityId"),
|
|
805
|
+
isFirstFetched: true,
|
|
806
|
+
lastKey
|
|
807
|
+
};
|
|
808
|
+
}
|
|
809
|
+
}),
|
|
810
|
+
void 0,
|
|
811
|
+
`mr/mutual/list/${selfKey}`
|
|
812
|
+
);
|
|
813
|
+
return { data };
|
|
814
|
+
} catch (err) {
|
|
815
|
+
const error2 = err instanceof Error ? err : new Error("Unknown error occurred");
|
|
816
|
+
return { error: error2 };
|
|
817
|
+
}
|
|
818
|
+
};
|
|
819
|
+
const getMutual2 = async (byEntityType, entityType, byEntityId2, entityId, opts = {}) => {
|
|
820
|
+
var _a, _b, _c, _d;
|
|
821
|
+
const selfKey = getMutualStateKey(byEntityType, byEntityId2, entityType);
|
|
822
|
+
const mutualService = makeMutualService(byEntityType, entityType);
|
|
823
|
+
const store2 = monoriseStore.getState();
|
|
824
|
+
const mutualState = store2.mutual[selfKey] || {};
|
|
825
|
+
const requestKey = getMutualRequestKey(
|
|
826
|
+
"get",
|
|
827
|
+
byEntityType,
|
|
828
|
+
entityType,
|
|
829
|
+
byEntityId2,
|
|
830
|
+
entityId
|
|
831
|
+
);
|
|
832
|
+
const isLoading = checkIsLoading(requestKey);
|
|
833
|
+
const error = getError2(requestKey);
|
|
834
|
+
const onError = (_a = opts.onError) != null ? _a : defaultOnError;
|
|
835
|
+
if (error) {
|
|
836
|
+
onError == null ? void 0 : onError(error);
|
|
837
|
+
return { error };
|
|
838
|
+
}
|
|
839
|
+
if (!byEntityId2 || isLoading) {
|
|
840
|
+
return {
|
|
841
|
+
data: (_b = mutualState.dataMap) == null ? void 0 : _b.get(entityId)
|
|
842
|
+
};
|
|
843
|
+
}
|
|
844
|
+
if ((_c = mutualState.dataMap) == null ? void 0 : _c.get(entityId)) {
|
|
845
|
+
return {
|
|
846
|
+
data: mutualState.dataMap.get(entityId)
|
|
847
|
+
};
|
|
848
|
+
}
|
|
849
|
+
let mutual;
|
|
850
|
+
let hasRequestFailed = false;
|
|
851
|
+
try {
|
|
852
|
+
({ data: mutual } = await mutualService.getMutual(
|
|
853
|
+
byEntityId2,
|
|
854
|
+
entityId,
|
|
855
|
+
opts
|
|
856
|
+
));
|
|
857
|
+
} catch (err) {
|
|
858
|
+
if (!opts.defaultMutualData) {
|
|
859
|
+
const error2 = err instanceof Error ? err : new Error("Unknown error occurred");
|
|
860
|
+
return { error: error2 };
|
|
861
|
+
}
|
|
862
|
+
hasRequestFailed = true;
|
|
863
|
+
mutual = {
|
|
864
|
+
createdAt: (/* @__PURE__ */ new Date()).toISOString(),
|
|
865
|
+
updatedAt: (/* @__PURE__ */ new Date()).toISOString(),
|
|
866
|
+
mutualId: `${byEntityId2}-${entityId}`,
|
|
867
|
+
mutualUpdatedAt: (/* @__PURE__ */ new Date()).toISOString(),
|
|
868
|
+
byEntityType,
|
|
869
|
+
byEntityId: byEntityId2,
|
|
870
|
+
entityType,
|
|
871
|
+
entityId,
|
|
872
|
+
mutualData: opts.defaultMutualData
|
|
873
|
+
};
|
|
874
|
+
}
|
|
875
|
+
const newMutualDataMap = new Map((_d = store2.mutual[selfKey]) == null ? void 0 : _d.dataMap);
|
|
876
|
+
newMutualDataMap.set(mutual.entityId, mutual);
|
|
877
|
+
if (!hasRequestFailed) {
|
|
878
|
+
const entityState = store2.entity[entityType];
|
|
879
|
+
const { dataMap: entityDataMap } = entityState;
|
|
880
|
+
const newEntityDataMap = new Map(entityDataMap);
|
|
881
|
+
newEntityDataMap.set(mutual.entityId, mutual);
|
|
882
|
+
monoriseStore.setState(
|
|
883
|
+
produce4((state) => {
|
|
884
|
+
state.mutual[selfKey] = __spreadProps(__spreadValues({}, state.mutual[selfKey] || {}), {
|
|
885
|
+
dataMap: newMutualDataMap
|
|
886
|
+
});
|
|
887
|
+
state.entity[entityType].dataMap = newEntityDataMap;
|
|
888
|
+
}),
|
|
889
|
+
void 0,
|
|
890
|
+
`mr/mutual/get/${getMutualStateKey(
|
|
891
|
+
byEntityType,
|
|
892
|
+
byEntityId2,
|
|
893
|
+
entityType,
|
|
894
|
+
entityId
|
|
895
|
+
)}`
|
|
896
|
+
);
|
|
897
|
+
}
|
|
898
|
+
return { data: mutual };
|
|
899
|
+
};
|
|
900
|
+
const createMutual2 = async (byEntityType, entityType, byEntityId2, entityId, payload = {}, opts = {}) => {
|
|
901
|
+
var _a;
|
|
902
|
+
const mutualService = makeMutualService(byEntityType, entityType);
|
|
903
|
+
const onError = (_a = opts.onError) != null ? _a : defaultOnError;
|
|
904
|
+
try {
|
|
905
|
+
const { data: mutual } = await mutualService.createMutual(
|
|
906
|
+
byEntityId2,
|
|
907
|
+
entityId,
|
|
908
|
+
payload,
|
|
909
|
+
opts
|
|
910
|
+
);
|
|
911
|
+
monoriseStore.setState(
|
|
912
|
+
produce4((state) => {
|
|
913
|
+
var _a2, _b;
|
|
914
|
+
const bySide = getMutualStateKey(
|
|
915
|
+
byEntityType,
|
|
916
|
+
byEntityId2,
|
|
917
|
+
entityType
|
|
918
|
+
);
|
|
919
|
+
const side = getMutualStateKey(entityType, entityId, byEntityType);
|
|
920
|
+
if (!state.mutual[bySide]) {
|
|
921
|
+
state.mutual[bySide] = {
|
|
922
|
+
dataMap: /* @__PURE__ */ new Map()
|
|
923
|
+
};
|
|
924
|
+
}
|
|
925
|
+
state.mutual[bySide].dataMap = new Map(
|
|
926
|
+
(_a2 = state.mutual[bySide]) == null ? void 0 : _a2.dataMap
|
|
927
|
+
).set(mutual.entityId, mutual);
|
|
928
|
+
if (!state.mutual[side]) {
|
|
929
|
+
state.mutual[side] = {
|
|
930
|
+
dataMap: /* @__PURE__ */ new Map()
|
|
931
|
+
};
|
|
932
|
+
}
|
|
933
|
+
state.mutual[side].dataMap = new Map((_b = state.mutual[side]) == null ? void 0 : _b.dataMap).set(
|
|
934
|
+
mutual.byEntityId,
|
|
935
|
+
flipMutual(mutual)
|
|
936
|
+
);
|
|
937
|
+
}),
|
|
938
|
+
void 0,
|
|
939
|
+
`mr/mutual/create/${getMutualStateKey(byEntityType, byEntityId2, entityType, entityId)}`
|
|
940
|
+
);
|
|
941
|
+
return { data: mutual };
|
|
942
|
+
} catch (err) {
|
|
943
|
+
const error = err instanceof Error ? err : new Error("Unknown error occurred");
|
|
944
|
+
onError(error);
|
|
945
|
+
return { error };
|
|
946
|
+
}
|
|
947
|
+
};
|
|
948
|
+
const createLocalMutual2 = async (byEntityType, entityType, byEntityId2, entityId, mutualData, data) => {
|
|
949
|
+
const mutual = constructMutual(
|
|
950
|
+
byEntityType,
|
|
951
|
+
byEntityId2,
|
|
952
|
+
entityType,
|
|
953
|
+
entityId,
|
|
954
|
+
mutualData,
|
|
955
|
+
data
|
|
956
|
+
);
|
|
957
|
+
monoriseStore.setState(
|
|
958
|
+
produce4((state) => {
|
|
959
|
+
var _a, _b;
|
|
960
|
+
const bySide = getMutualStateKey(byEntityType, byEntityId2, entityType);
|
|
961
|
+
const side = getMutualStateKey(entityType, entityId, byEntityType);
|
|
962
|
+
if (!state.mutual[bySide]) {
|
|
963
|
+
state.mutual[bySide] = {
|
|
964
|
+
dataMap: /* @__PURE__ */ new Map()
|
|
965
|
+
};
|
|
966
|
+
}
|
|
967
|
+
state.mutual[bySide].dataMap = new Map(
|
|
968
|
+
(_a = state.mutual[bySide]) == null ? void 0 : _a.dataMap
|
|
969
|
+
).set(mutual.entityId, mutual);
|
|
970
|
+
if (!state.mutual[side]) {
|
|
971
|
+
state.mutual[side] = {
|
|
972
|
+
dataMap: /* @__PURE__ */ new Map()
|
|
973
|
+
};
|
|
974
|
+
}
|
|
975
|
+
state.mutual[side].dataMap = new Map((_b = state.mutual[side]) == null ? void 0 : _b.dataMap).set(
|
|
976
|
+
mutual.byEntityId,
|
|
977
|
+
flipMutual(mutual)
|
|
978
|
+
);
|
|
979
|
+
}),
|
|
980
|
+
void 0,
|
|
981
|
+
`mr/mutual/create/${getMutualStateKey(byEntityType, byEntityId2, entityType, entityId)}`
|
|
982
|
+
);
|
|
983
|
+
};
|
|
984
|
+
const updateLocalEntity2 = async (entityType, entityId, data = {}) => {
|
|
985
|
+
const createdEntity = constructLocal(entityType, entityId, data);
|
|
986
|
+
monoriseStore.setState(
|
|
987
|
+
produce4((state) => {
|
|
988
|
+
state.entity[entityType].dataMap.set(entityId, createdEntity);
|
|
989
|
+
}),
|
|
990
|
+
void 0,
|
|
991
|
+
`mr/entity/local-update/${entityType}/${entityId}`
|
|
992
|
+
);
|
|
993
|
+
};
|
|
994
|
+
const upsertLocalMutual2 = async (byEntityType, entityType, byEntityId2, entityId, mutualData, data = {}) => {
|
|
995
|
+
const mutual = constructMutual(
|
|
996
|
+
byEntityType,
|
|
997
|
+
byEntityId2,
|
|
998
|
+
entityType,
|
|
999
|
+
entityId,
|
|
1000
|
+
mutualData,
|
|
1001
|
+
data
|
|
1002
|
+
);
|
|
1003
|
+
monoriseStore.setState(
|
|
1004
|
+
produce4((state) => {
|
|
1005
|
+
var _a, _b;
|
|
1006
|
+
const bySide = getMutualStateKey(byEntityType, byEntityId2, entityType);
|
|
1007
|
+
const side = getMutualStateKey(entityType, entityId, byEntityType);
|
|
1008
|
+
if (!state.mutual[bySide]) {
|
|
1009
|
+
state.mutual[bySide] = {
|
|
1010
|
+
dataMap: /* @__PURE__ */ new Map()
|
|
1011
|
+
};
|
|
1012
|
+
}
|
|
1013
|
+
state.mutual[bySide].dataMap = new Map(
|
|
1014
|
+
(_a = state.mutual[bySide]) == null ? void 0 : _a.dataMap
|
|
1015
|
+
).set(entityId, mutual);
|
|
1016
|
+
if (!state.mutual[side]) {
|
|
1017
|
+
state.mutual[side] = {
|
|
1018
|
+
dataMap: /* @__PURE__ */ new Map()
|
|
1019
|
+
};
|
|
1020
|
+
}
|
|
1021
|
+
state.mutual[side].dataMap = new Map((_b = state.mutual[side]) == null ? void 0 : _b.dataMap).set(
|
|
1022
|
+
byEntityId2,
|
|
1023
|
+
flipMutual(mutual)
|
|
1024
|
+
);
|
|
1025
|
+
}),
|
|
1026
|
+
void 0,
|
|
1027
|
+
`mr/mutual/local-update/${getMutualStateKey(byEntityType, byEntityId2, entityType, entityId)}`
|
|
1028
|
+
);
|
|
1029
|
+
};
|
|
1030
|
+
const editMutual2 = async (byEntityType, entityType, byEntityId2, entityId, payload = {}, opts = {}) => {
|
|
1031
|
+
var _a;
|
|
1032
|
+
const mutualService = makeMutualService(byEntityType, entityType);
|
|
1033
|
+
const onError = (_a = opts.onError) != null ? _a : defaultOnError;
|
|
1034
|
+
try {
|
|
1035
|
+
const { data: mutual } = await mutualService.editMutual(
|
|
1036
|
+
byEntityId2,
|
|
1037
|
+
entityId,
|
|
1038
|
+
payload,
|
|
1039
|
+
opts
|
|
1040
|
+
);
|
|
1041
|
+
monoriseStore.setState(
|
|
1042
|
+
produce4((state) => {
|
|
1043
|
+
var _a2, _b;
|
|
1044
|
+
const bySide = getMutualStateKey(
|
|
1045
|
+
byEntityType,
|
|
1046
|
+
byEntityId2,
|
|
1047
|
+
entityType
|
|
1048
|
+
);
|
|
1049
|
+
const side = getMutualStateKey(entityType, entityId, byEntityType);
|
|
1050
|
+
if (!state.mutual[bySide]) {
|
|
1051
|
+
state.mutual[bySide] = {
|
|
1052
|
+
dataMap: /* @__PURE__ */ new Map()
|
|
1053
|
+
};
|
|
1054
|
+
}
|
|
1055
|
+
state.mutual[bySide].dataMap = new Map(
|
|
1056
|
+
(_a2 = state.mutual[bySide]) == null ? void 0 : _a2.dataMap
|
|
1057
|
+
).set(mutual.entityId, mutual);
|
|
1058
|
+
if (!state.mutual[side]) {
|
|
1059
|
+
state.mutual[side] = {
|
|
1060
|
+
dataMap: /* @__PURE__ */ new Map()
|
|
1061
|
+
};
|
|
1062
|
+
}
|
|
1063
|
+
state.mutual[side].dataMap = new Map((_b = state.mutual[side]) == null ? void 0 : _b.dataMap).set(
|
|
1064
|
+
mutual.byEntityId,
|
|
1065
|
+
flipMutual(mutual)
|
|
1066
|
+
);
|
|
1067
|
+
}),
|
|
1068
|
+
void 0,
|
|
1069
|
+
`mr/mutual/edit/${getMutualStateKey(byEntityType, byEntityId2, entityType, entityId)}`
|
|
1070
|
+
);
|
|
1071
|
+
return { data: mutual };
|
|
1072
|
+
} catch (err) {
|
|
1073
|
+
const error = err instanceof Error ? err : new Error("Unknown error occurred");
|
|
1074
|
+
onError(error);
|
|
1075
|
+
return { error };
|
|
1076
|
+
}
|
|
1077
|
+
};
|
|
1078
|
+
const deleteMutual2 = async (byEntityType, entityType, byEntityId2, entityId = "", opts = {}) => {
|
|
1079
|
+
var _a;
|
|
1080
|
+
const mutualService = makeMutualService(byEntityType, entityType);
|
|
1081
|
+
const onError = (_a = opts.onError) != null ? _a : defaultOnError;
|
|
1082
|
+
try {
|
|
1083
|
+
const { data } = await mutualService.deleteMutual(
|
|
1084
|
+
byEntityId2,
|
|
1085
|
+
entityId,
|
|
1086
|
+
opts
|
|
1087
|
+
);
|
|
1088
|
+
monoriseStore.setState(
|
|
1089
|
+
produce4((state) => {
|
|
1090
|
+
const bySide = getMutualStateKey(
|
|
1091
|
+
byEntityType,
|
|
1092
|
+
byEntityId2,
|
|
1093
|
+
entityType
|
|
1094
|
+
);
|
|
1095
|
+
const side = getMutualStateKey(entityType, entityId, byEntityType);
|
|
1096
|
+
state.mutual[bySide].dataMap.delete(data.entityId);
|
|
1097
|
+
if (state.mutual[side]) {
|
|
1098
|
+
state.mutual[side].dataMap.delete(data.byEntityId);
|
|
1099
|
+
}
|
|
1100
|
+
}),
|
|
1101
|
+
void 0,
|
|
1102
|
+
`mr/mutual/delete/${getMutualStateKey(byEntityType, byEntityId2, entityType, entityId)}`
|
|
1103
|
+
);
|
|
1104
|
+
return { data };
|
|
1105
|
+
} catch (err) {
|
|
1106
|
+
const error = err instanceof Error ? err : new Error("Unknown error occurred");
|
|
1107
|
+
onError(error);
|
|
1108
|
+
return { error };
|
|
1109
|
+
}
|
|
1110
|
+
};
|
|
1111
|
+
const deleteLocalMutual2 = (byEntityType, entityType, byEntityId2, entityId) => {
|
|
1112
|
+
monoriseStore.setState(
|
|
1113
|
+
produce4((state) => {
|
|
1114
|
+
var _a, _b;
|
|
1115
|
+
const bySide = getMutualStateKey(byEntityType, byEntityId2, entityType);
|
|
1116
|
+
const side = getMutualStateKey(entityType, entityId, byEntityType);
|
|
1117
|
+
const bySideDataMap = new Map((_a = state.mutual[bySide]) == null ? void 0 : _a.dataMap);
|
|
1118
|
+
const sideDataMap = new Map((_b = state.mutual[side]) == null ? void 0 : _b.dataMap);
|
|
1119
|
+
bySideDataMap.delete(entityId);
|
|
1120
|
+
sideDataMap.delete(byEntityId2);
|
|
1121
|
+
if (state.mutual[bySide]) {
|
|
1122
|
+
state.mutual[bySide].dataMap.delete(entityId);
|
|
1123
|
+
}
|
|
1124
|
+
if (state.mutual[side]) {
|
|
1125
|
+
state.mutual[side].dataMap.delete(byEntityId2);
|
|
1126
|
+
}
|
|
1127
|
+
}),
|
|
1128
|
+
void 0,
|
|
1129
|
+
`mr/mutual/local-delete/${getMutualStateKey(byEntityType, byEntityId2, entityType, entityId)}`
|
|
1130
|
+
);
|
|
1131
|
+
};
|
|
1132
|
+
const deleteLocalMutualsByEntity = (entityType, id) => {
|
|
1133
|
+
const store2 = monoriseStore.getState();
|
|
1134
|
+
const entityConfig = store2.config;
|
|
1135
|
+
let mutuals = [];
|
|
1136
|
+
for (const i of Object.keys(entityConfig)) {
|
|
1137
|
+
const mutualState = store2.mutual[`${entityType}/${id}/${i}`];
|
|
1138
|
+
mutuals = [
|
|
1139
|
+
...mutuals,
|
|
1140
|
+
...Array.from((mutualState == null ? void 0 : mutualState.dataMap.values()) || [])
|
|
1141
|
+
];
|
|
1142
|
+
}
|
|
1143
|
+
const updatedState = mutuals.reduce(
|
|
1144
|
+
(acc, mutual) => {
|
|
1145
|
+
var _a;
|
|
1146
|
+
const side = getMutualStateKey(
|
|
1147
|
+
mutual.entityType,
|
|
1148
|
+
mutual.entityId,
|
|
1149
|
+
mutual.byEntityType
|
|
1150
|
+
);
|
|
1151
|
+
const dataMap = new Map((_a = store2.mutual[side]) == null ? void 0 : _a.dataMap);
|
|
1152
|
+
dataMap.delete(id);
|
|
1153
|
+
acc[side] = __spreadProps(__spreadValues({}, store2.mutual[side]), {
|
|
1154
|
+
dataMap
|
|
40
1155
|
});
|
|
1156
|
+
return acc;
|
|
1157
|
+
},
|
|
1158
|
+
{}
|
|
1159
|
+
);
|
|
1160
|
+
monoriseStore.setState(
|
|
1161
|
+
produce4((state) => {
|
|
1162
|
+
for (const key in updatedState) {
|
|
1163
|
+
state.mutual[key] = updatedState[key];
|
|
1164
|
+
}
|
|
1165
|
+
}),
|
|
1166
|
+
void 0,
|
|
1167
|
+
`mr/mutual/local-delete-by-entity/${entityType}/${id}`
|
|
1168
|
+
);
|
|
1169
|
+
};
|
|
1170
|
+
const useEntity2 = (entityType, id, opts = {}) => {
|
|
1171
|
+
const dataMap = monoriseStore(
|
|
1172
|
+
(state) => {
|
|
1173
|
+
var _a;
|
|
1174
|
+
return ((_a = state.entity[entityType]) == null ? void 0 : _a.dataMap) || /* @__PURE__ */ new Map();
|
|
1175
|
+
}
|
|
1176
|
+
);
|
|
1177
|
+
const isFirstFetched = monoriseStore(
|
|
1178
|
+
(state) => {
|
|
1179
|
+
var _a;
|
|
1180
|
+
return (_a = state.entity[entityType]) == null ? void 0 : _a.isFirstFetched;
|
|
1181
|
+
}
|
|
1182
|
+
);
|
|
1183
|
+
const requestKey = getEntityRequestKey("get", entityType, id);
|
|
1184
|
+
const isLoading = useLoadStore2(requestKey);
|
|
1185
|
+
const error = useErrorStore2(requestKey);
|
|
1186
|
+
useEffect2(() => {
|
|
1187
|
+
if (id) {
|
|
1188
|
+
getEntity2(entityType, id, opts);
|
|
1189
|
+
}
|
|
1190
|
+
}, [id, entityType, opts]);
|
|
1191
|
+
return {
|
|
1192
|
+
entity: id ? dataMap.get(id) : void 0,
|
|
1193
|
+
isLoading,
|
|
1194
|
+
error,
|
|
1195
|
+
requestKey,
|
|
1196
|
+
isFirstFetched,
|
|
1197
|
+
refetch: async () => {
|
|
1198
|
+
if (id) {
|
|
1199
|
+
const { data, error: fetchError } = await getEntity2(entityType, id, __spreadProps(__spreadValues({}, opts), {
|
|
1200
|
+
forceFetch: true
|
|
1201
|
+
}));
|
|
1202
|
+
if (fetchError) {
|
|
1203
|
+
}
|
|
1204
|
+
return data;
|
|
1205
|
+
}
|
|
1206
|
+
}
|
|
1207
|
+
};
|
|
1208
|
+
};
|
|
1209
|
+
const useEntityByUniqueField2 = (entityType, fieldName, value, opts = {}) => {
|
|
1210
|
+
const dataMap = monoriseStore(
|
|
1211
|
+
(state) => {
|
|
1212
|
+
var _a;
|
|
1213
|
+
return ((_a = state.entity[entityType]) == null ? void 0 : _a.dataMap) || /* @__PURE__ */ new Map();
|
|
1214
|
+
}
|
|
1215
|
+
);
|
|
1216
|
+
const isFirstFetched = monoriseStore(
|
|
1217
|
+
(state) => {
|
|
1218
|
+
var _a;
|
|
1219
|
+
return (_a = state.entity[entityType]) == null ? void 0 : _a.isFirstFetched;
|
|
1220
|
+
}
|
|
1221
|
+
);
|
|
1222
|
+
const stateKey = getUniqueFieldStateKey(fieldName, value || "");
|
|
1223
|
+
const requestKey = getUniqueFieldRequestKey(
|
|
1224
|
+
entityType,
|
|
1225
|
+
fieldName,
|
|
1226
|
+
value || ""
|
|
1227
|
+
);
|
|
1228
|
+
const isLoading = useLoadStore2(requestKey);
|
|
1229
|
+
const error = useErrorStore2(requestKey);
|
|
1230
|
+
useEffect2(() => {
|
|
1231
|
+
if (value) {
|
|
1232
|
+
getEntityByUniqueField(entityType, fieldName, value, opts);
|
|
1233
|
+
}
|
|
1234
|
+
}, [fieldName, value, entityType, opts]);
|
|
1235
|
+
return {
|
|
1236
|
+
entity: value ? dataMap.get(`${stateKey}`) : void 0,
|
|
1237
|
+
isLoading,
|
|
1238
|
+
error,
|
|
1239
|
+
requestKey,
|
|
1240
|
+
isFirstFetched,
|
|
1241
|
+
refetch: async () => {
|
|
1242
|
+
if (value) {
|
|
1243
|
+
const { data, error: fetchError } = await getEntityByUniqueField(
|
|
1244
|
+
entityType,
|
|
1245
|
+
fieldName,
|
|
1246
|
+
value,
|
|
1247
|
+
__spreadProps(__spreadValues({}, opts), {
|
|
1248
|
+
forceFetch: true
|
|
1249
|
+
})
|
|
1250
|
+
);
|
|
1251
|
+
if (fetchError) {
|
|
1252
|
+
}
|
|
1253
|
+
return data;
|
|
1254
|
+
}
|
|
1255
|
+
}
|
|
1256
|
+
};
|
|
1257
|
+
};
|
|
1258
|
+
const useEntities2 = (entityType, params = {}, opts = {}) => {
|
|
1259
|
+
const requestKey = getEntityRequestKey("list", entityType);
|
|
1260
|
+
const isListing = useLoadStore2(requestKey);
|
|
1261
|
+
const error = useErrorStore2(requestKey);
|
|
1262
|
+
const state = monoriseStore((state2) => state2.entity[entityType]);
|
|
1263
|
+
const { dataMap, searchResults, isFirstFetched, lastKey } = state != null ? state : {
|
|
1264
|
+
dataMap: /* @__PURE__ */ new Map()
|
|
1265
|
+
};
|
|
1266
|
+
const [entities, setEntities] = useState2();
|
|
1267
|
+
const [query, setQuery] = useState2("");
|
|
1268
|
+
const [skRange, setBetween] = useState2(params.skRange);
|
|
1269
|
+
const [all, setAll] = useState2(params.all);
|
|
1270
|
+
const [isSearching, setIsSearching] = useState2(false);
|
|
1271
|
+
const isLoading = isListing || isSearching;
|
|
1272
|
+
useEffect2(() => {
|
|
1273
|
+
if ((params == null ? void 0 : params.skRange) && (skRange == null ? void 0 : skRange.start) !== params.skRange.start && (skRange == null ? void 0 : skRange.end) !== params.skRange.end) {
|
|
1274
|
+
setBetween(params.skRange);
|
|
1275
|
+
}
|
|
1276
|
+
}, [skRange == null ? void 0 : skRange.end, skRange == null ? void 0 : skRange.start, params.skRange]);
|
|
1277
|
+
useEffect2(() => {
|
|
1278
|
+
if ((params == null ? void 0 : params.all) !== all) {
|
|
1279
|
+
setAll(params.all);
|
|
1280
|
+
}
|
|
1281
|
+
}, [all, params.all]);
|
|
1282
|
+
useEffect2(() => {
|
|
1283
|
+
if (!isFirstFetched) {
|
|
1284
|
+
listEntities(entityType, { skRange, all }, opts);
|
|
1285
|
+
}
|
|
1286
|
+
}, [all, entityType, skRange, opts, isFirstFetched]);
|
|
1287
|
+
useEffect2(() => {
|
|
1288
|
+
var _a;
|
|
1289
|
+
let queryTimeout;
|
|
1290
|
+
if (query == null ? void 0 : query.length) {
|
|
1291
|
+
setIsSearching(true);
|
|
1292
|
+
queryTimeout = setTimeout(async () => {
|
|
1293
|
+
await searchEntities(entityType, query);
|
|
1294
|
+
setIsSearching(false);
|
|
1295
|
+
}, (_a = opts.searchInterval) != null ? _a : 700);
|
|
1296
|
+
}
|
|
1297
|
+
return () => queryTimeout && clearTimeout(queryTimeout);
|
|
1298
|
+
}, [entityType, query]);
|
|
1299
|
+
useEffect2(() => {
|
|
1300
|
+
if (!query && dataMap.size !== (entities == null ? void 0 : entities.length)) {
|
|
1301
|
+
setIsSearching(false);
|
|
1302
|
+
setEntities(
|
|
1303
|
+
Array.from(dataMap.values()).sort(byEntityId)
|
|
1304
|
+
);
|
|
1305
|
+
}
|
|
1306
|
+
if (query) {
|
|
1307
|
+
setEntities(searchResults);
|
|
1308
|
+
}
|
|
1309
|
+
}, [
|
|
1310
|
+
dataMap,
|
|
1311
|
+
dataMap.size,
|
|
1312
|
+
entities == null ? void 0 : entities.length,
|
|
1313
|
+
query,
|
|
1314
|
+
searchResults,
|
|
1315
|
+
searchResults == null ? void 0 : searchResults.length
|
|
1316
|
+
]);
|
|
1317
|
+
const handleQueryChange = (event) => {
|
|
1318
|
+
setQuery(event.target.value);
|
|
1319
|
+
};
|
|
1320
|
+
const searchField = {
|
|
1321
|
+
value: query,
|
|
1322
|
+
onChange: handleQueryChange
|
|
1323
|
+
};
|
|
1324
|
+
return {
|
|
1325
|
+
entities,
|
|
1326
|
+
entitiesMap: dataMap,
|
|
1327
|
+
searchField,
|
|
1328
|
+
isLoading,
|
|
1329
|
+
error,
|
|
1330
|
+
requestKey,
|
|
1331
|
+
isFirstFetched,
|
|
1332
|
+
lastKey,
|
|
1333
|
+
refetch: async () => {
|
|
1334
|
+
if (entityType && query) {
|
|
1335
|
+
await searchEntities(entityType, query);
|
|
1336
|
+
return;
|
|
1337
|
+
}
|
|
1338
|
+
await listEntities(
|
|
1339
|
+
entityType,
|
|
1340
|
+
{ skRange, all },
|
|
1341
|
+
__spreadProps(__spreadValues({}, opts), {
|
|
1342
|
+
forceFetch: true
|
|
1343
|
+
})
|
|
1344
|
+
);
|
|
1345
|
+
},
|
|
1346
|
+
listMore: async () => {
|
|
1347
|
+
if (!lastKey) return;
|
|
1348
|
+
await listMoreEntities2(entityType, __spreadProps(__spreadValues({}, opts), {
|
|
1349
|
+
forceFetch: true
|
|
1350
|
+
}));
|
|
1351
|
+
}
|
|
1352
|
+
};
|
|
1353
|
+
};
|
|
1354
|
+
const useMutual2 = (byEntityType, entityType, byId, id, opts = {}) => {
|
|
1355
|
+
const stateKey = getMutualStateKey(byEntityType, byId, entityType);
|
|
1356
|
+
const state = monoriseStore((state2) => state2.mutual[stateKey]);
|
|
1357
|
+
const requestKey = getMutualRequestKey(
|
|
1358
|
+
"get",
|
|
1359
|
+
byEntityType,
|
|
1360
|
+
entityType,
|
|
1361
|
+
byId,
|
|
1362
|
+
id
|
|
1363
|
+
);
|
|
1364
|
+
const isLoading = useLoadStore2(requestKey);
|
|
1365
|
+
const error = useErrorStore2(requestKey);
|
|
1366
|
+
const { dataMap } = state || {
|
|
1367
|
+
dataMap: /* @__PURE__ */ new Map()
|
|
1368
|
+
};
|
|
1369
|
+
useEffect2(() => {
|
|
1370
|
+
if (!dataMap.get(id)) {
|
|
1371
|
+
getMutual2(byEntityType, entityType, byId, id, opts);
|
|
1372
|
+
}
|
|
1373
|
+
}, [byEntityType, byId, entityType, id, opts, dataMap]);
|
|
1374
|
+
return {
|
|
1375
|
+
mutual: dataMap.get(id),
|
|
1376
|
+
isLoading,
|
|
1377
|
+
error,
|
|
1378
|
+
requestKey
|
|
1379
|
+
};
|
|
1380
|
+
};
|
|
1381
|
+
const useMutuals2 = (byEntityType, entityType, byId, opts = {}, chainEntityQuery) => {
|
|
1382
|
+
const stateKey = getMutualStateKey(
|
|
1383
|
+
byEntityType,
|
|
1384
|
+
byId || "",
|
|
1385
|
+
entityType,
|
|
1386
|
+
void 0,
|
|
1387
|
+
chainEntityQuery
|
|
1388
|
+
);
|
|
1389
|
+
const state = monoriseStore((state2) => state2.mutual[stateKey]);
|
|
1390
|
+
const { dataMap, isFirstFetched, lastKey } = state || {
|
|
1391
|
+
dataMap: /* @__PURE__ */ new Map()
|
|
1392
|
+
};
|
|
1393
|
+
const [mutuals, setMutuals] = useState2([]);
|
|
1394
|
+
const requestKey = getMutualRequestKey(
|
|
1395
|
+
"list",
|
|
1396
|
+
byEntityType,
|
|
1397
|
+
entityType,
|
|
1398
|
+
byId || "",
|
|
1399
|
+
void 0,
|
|
1400
|
+
chainEntityQuery
|
|
1401
|
+
);
|
|
1402
|
+
const isLoading = useLoadStore2(requestKey);
|
|
1403
|
+
const error = useErrorStore2(requestKey);
|
|
1404
|
+
useEffect2(() => {
|
|
1405
|
+
if (!isFirstFetched && byEntityType && entityType && byId) {
|
|
1406
|
+
listEntitiesByEntity(
|
|
1407
|
+
byEntityType,
|
|
1408
|
+
entityType,
|
|
1409
|
+
byId,
|
|
1410
|
+
__spreadProps(__spreadValues({}, opts), { stateKey }),
|
|
1411
|
+
chainEntityQuery
|
|
1412
|
+
);
|
|
1413
|
+
}
|
|
1414
|
+
}, [
|
|
1415
|
+
isFirstFetched,
|
|
1416
|
+
byEntityType,
|
|
1417
|
+
byId,
|
|
1418
|
+
entityType,
|
|
1419
|
+
opts,
|
|
1420
|
+
chainEntityQuery,
|
|
1421
|
+
stateKey,
|
|
1422
|
+
opts == null ? void 0 : opts.forceFetch,
|
|
1423
|
+
opts == null ? void 0 : opts.noData
|
|
1424
|
+
]);
|
|
1425
|
+
useEffect2(() => {
|
|
1426
|
+
const dataMapArray = Array.from(dataMap.values());
|
|
1427
|
+
if (dataMap.size !== (mutuals == null ? void 0 : mutuals.length) || dataMapArray.some(
|
|
1428
|
+
(item, index) => JSON.stringify(item) !== JSON.stringify(mutuals[index])
|
|
1429
|
+
)) {
|
|
1430
|
+
setMutuals(dataMapArray);
|
|
1431
|
+
}
|
|
1432
|
+
}, [dataMap, dataMap.size, mutuals == null ? void 0 : mutuals.length]);
|
|
1433
|
+
return __spreadValues({
|
|
1434
|
+
mutuals,
|
|
1435
|
+
mutualsMap: dataMap,
|
|
1436
|
+
isLoading,
|
|
1437
|
+
requestKey,
|
|
1438
|
+
error,
|
|
1439
|
+
isFirstFetched,
|
|
1440
|
+
lastKey
|
|
1441
|
+
}, lastKey && {
|
|
1442
|
+
listMore: () => {
|
|
1443
|
+
if (byEntityType && entityType && byId) {
|
|
1444
|
+
listEntitiesByEntity(
|
|
1445
|
+
byEntityType,
|
|
1446
|
+
entityType,
|
|
1447
|
+
byId,
|
|
1448
|
+
__spreadProps(__spreadValues({}, opts), {
|
|
1449
|
+
forceFetch: true,
|
|
1450
|
+
params: __spreadProps(__spreadValues({}, opts.params), { lastKey }),
|
|
1451
|
+
stateKey
|
|
1452
|
+
}),
|
|
1453
|
+
chainEntityQuery
|
|
1454
|
+
);
|
|
1455
|
+
}
|
|
1456
|
+
}
|
|
1457
|
+
});
|
|
1458
|
+
};
|
|
1459
|
+
const useTaggedEntities2 = (entityType, tagName, opts = {}) => {
|
|
1460
|
+
const { params } = opts || {};
|
|
1461
|
+
const stateKey = getTagStateKey(entityType, tagName, params);
|
|
1462
|
+
const state = monoriseStore((state2) => state2.tag[stateKey]);
|
|
1463
|
+
const { dataMap, isFirstFetched, lastKey } = state || {
|
|
1464
|
+
dataMap: /* @__PURE__ */ new Map()
|
|
1465
|
+
};
|
|
1466
|
+
const [entities, setEntities] = useState2([]);
|
|
1467
|
+
const requestKey = getTagRequestKey("list", entityType, tagName, params);
|
|
1468
|
+
const isLoading = useLoadStore2(requestKey);
|
|
1469
|
+
const error = useErrorStore2(requestKey);
|
|
1470
|
+
useEffect2(() => {
|
|
1471
|
+
if (entityType && tagName && Object.keys(params).length > 0) {
|
|
1472
|
+
listEntitiesByTag(entityType, tagName, opts);
|
|
1473
|
+
}
|
|
1474
|
+
}, [entityType, opts, tagName, params, opts == null ? void 0 : opts.forceFetch]);
|
|
1475
|
+
useEffect2(() => {
|
|
1476
|
+
const dataMapArray = Array.from(dataMap.values());
|
|
1477
|
+
if (dataMap.size !== (entities == null ? void 0 : entities.length) || dataMapArray.some(
|
|
1478
|
+
(item, index) => JSON.stringify(item) !== JSON.stringify(entities[index])
|
|
1479
|
+
)) {
|
|
1480
|
+
setEntities(dataMapArray);
|
|
1481
|
+
}
|
|
1482
|
+
}, [dataMap, dataMap.size, entities == null ? void 0 : entities.length]);
|
|
1483
|
+
return {
|
|
1484
|
+
entities,
|
|
1485
|
+
entitiesMap: dataMap,
|
|
1486
|
+
isLoading,
|
|
1487
|
+
requestKey,
|
|
1488
|
+
error,
|
|
1489
|
+
isFirstFetched,
|
|
1490
|
+
lastKey,
|
|
1491
|
+
refetch: async () => {
|
|
1492
|
+
if (entityType && tagName && (params == null ? void 0 : params.group)) {
|
|
1493
|
+
return await listEntitiesByTag(entityType, tagName, __spreadProps(__spreadValues({}, opts), {
|
|
1494
|
+
forceFetch: true
|
|
1495
|
+
}));
|
|
1496
|
+
}
|
|
1497
|
+
},
|
|
1498
|
+
listMore: async () => {
|
|
1499
|
+
if (entityType && tagName && (params == null ? void 0 : params.group)) {
|
|
1500
|
+
return await listEntitiesByTag(entityType, tagName, __spreadProps(__spreadValues({}, opts), {
|
|
1501
|
+
forceFetch: true,
|
|
1502
|
+
params: __spreadProps(__spreadValues({}, params), { lastKey })
|
|
1503
|
+
}));
|
|
1504
|
+
}
|
|
1505
|
+
}
|
|
41
1506
|
};
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
1507
|
+
};
|
|
1508
|
+
const useEntityState2 = (entityType) => {
|
|
1509
|
+
return monoriseStore((state) => state.entity[entityType]);
|
|
1510
|
+
};
|
|
1511
|
+
const updateLocalTaggedEntity2 = (entityType, entityId, tagName, data = {}, params) => {
|
|
1512
|
+
const tagKey = getTagStateKey(
|
|
1513
|
+
entityType,
|
|
1514
|
+
tagName,
|
|
1515
|
+
params
|
|
1516
|
+
);
|
|
1517
|
+
monoriseStore.setState(
|
|
1518
|
+
produce4((state) => {
|
|
1519
|
+
var _a, _b;
|
|
1520
|
+
const entity = (_b = (_a = state.tag[tagKey]) == null ? void 0 : _a.dataMap) == null ? void 0 : _b.get(entityId);
|
|
1521
|
+
if (entity) {
|
|
1522
|
+
state.tag[tagKey].dataMap.set(entityId, __spreadProps(__spreadValues({}, entity), {
|
|
1523
|
+
data: __spreadValues(__spreadValues({}, entity.data), data)
|
|
1524
|
+
}));
|
|
1525
|
+
}
|
|
1526
|
+
}),
|
|
1527
|
+
void 0,
|
|
1528
|
+
`mr/tag/local-update/${entityType}/${entityId}`
|
|
1529
|
+
);
|
|
1530
|
+
};
|
|
1531
|
+
const deleteLocalTaggedEntity2 = (entityType, entityId, tagName, params) => {
|
|
1532
|
+
const tagKey = getTagStateKey(
|
|
1533
|
+
entityType,
|
|
1534
|
+
tagName,
|
|
1535
|
+
params
|
|
1536
|
+
);
|
|
1537
|
+
monoriseStore.setState(
|
|
1538
|
+
produce4((state) => {
|
|
1539
|
+
var _a, _b;
|
|
1540
|
+
if ((_b = (_a = state.tag[tagKey]) == null ? void 0 : _a.dataMap) == null ? void 0 : _b.has(entityId)) {
|
|
1541
|
+
state.tag[tagKey].dataMap.delete(entityId);
|
|
1542
|
+
}
|
|
1543
|
+
}),
|
|
1544
|
+
void 0,
|
|
1545
|
+
`mr/tag/local-delete/${entityType}/${entityId}`
|
|
1546
|
+
);
|
|
1547
|
+
};
|
|
1548
|
+
return {
|
|
1549
|
+
listMoreEntities: listMoreEntities2,
|
|
1550
|
+
createEntity: createEntity2,
|
|
1551
|
+
upsertEntity: upsertEntity2,
|
|
1552
|
+
getEntity: getEntity2,
|
|
1553
|
+
editEntity: editEntity2,
|
|
1554
|
+
deleteEntity: deleteEntity2,
|
|
1555
|
+
getMutual: getMutual2,
|
|
1556
|
+
updateLocalEntity: updateLocalEntity2,
|
|
1557
|
+
createMutual: createMutual2,
|
|
1558
|
+
createLocalMutual: createLocalMutual2,
|
|
1559
|
+
upsertLocalMutual: upsertLocalMutual2,
|
|
1560
|
+
editMutual: editMutual2,
|
|
1561
|
+
deleteMutual: deleteMutual2,
|
|
1562
|
+
deleteLocalMutual: deleteLocalMutual2,
|
|
1563
|
+
useEntity: useEntity2,
|
|
1564
|
+
useEntityByUniqueField: useEntityByUniqueField2,
|
|
1565
|
+
useEntities: useEntities2,
|
|
1566
|
+
useMutual: useMutual2,
|
|
1567
|
+
useMutuals: useMutuals2,
|
|
1568
|
+
useTaggedEntities: useTaggedEntities2,
|
|
1569
|
+
useEntityState: useEntityState2,
|
|
1570
|
+
updateLocalTaggedEntity: updateLocalTaggedEntity2,
|
|
1571
|
+
deleteLocalTaggedEntity: deleteLocalTaggedEntity2
|
|
1572
|
+
};
|
|
1573
|
+
};
|
|
1574
|
+
|
|
1575
|
+
// lib/api.ts
|
|
1576
|
+
import request from "axios";
|
|
1577
|
+
var initAxiosInterceptor = (store2, appActions) => {
|
|
1578
|
+
const { startLoading: startLoading2 } = appActions;
|
|
1579
|
+
const axiosInstance = request.create();
|
|
1580
|
+
function makeRequest(url, config, data) {
|
|
1581
|
+
const { requestKey, isInterruptive = false, feedback } = config;
|
|
1582
|
+
const { ongoingRequests } = store2.getState().app;
|
|
1583
|
+
if (ongoingRequests.has(requestKey)) {
|
|
1584
|
+
return ongoingRequests.get(requestKey);
|
|
1585
|
+
}
|
|
1586
|
+
const promise = axiosInstance.request(__spreadProps(__spreadValues({}, config), {
|
|
1587
|
+
url,
|
|
1588
|
+
data,
|
|
1589
|
+
headers: __spreadProps(__spreadValues({}, config.headers || {}), {
|
|
1590
|
+
"Mr-Interruptive": String(isInterruptive)
|
|
1591
|
+
})
|
|
1592
|
+
}));
|
|
1593
|
+
startLoading2({
|
|
1594
|
+
requestKey,
|
|
1595
|
+
isInterruptive,
|
|
1596
|
+
message: feedback == null ? void 0 : feedback.loading,
|
|
1597
|
+
request: promise
|
|
1598
|
+
});
|
|
1599
|
+
return promise;
|
|
1600
|
+
}
|
|
1601
|
+
const axios2 = __spreadProps(__spreadValues({}, axiosInstance), {
|
|
1602
|
+
post: (url, data, config) => makeRequest(url, __spreadProps(__spreadValues({}, config), { method: "POST" }), data),
|
|
1603
|
+
put: (url, data, config) => makeRequest(url, __spreadProps(__spreadValues({}, config), { method: "PUT" }), data),
|
|
1604
|
+
patch: (url, data, config) => makeRequest(url, __spreadProps(__spreadValues({}, config), { method: "PATCH" }), data),
|
|
1605
|
+
delete: (url, config) => makeRequest(url, __spreadProps(__spreadValues({}, config), { method: "DELETE" })),
|
|
1606
|
+
get: (url, config) => makeRequest(url, __spreadProps(__spreadValues({}, config), { method: "GET" }))
|
|
1607
|
+
});
|
|
1608
|
+
return axios2;
|
|
1609
|
+
};
|
|
1610
|
+
var injectAxiosInterceptor = (appActions, authActions, axios2, opts) => {
|
|
1611
|
+
let options = opts || {};
|
|
1612
|
+
const { endLoading: endLoading2, setError: setError2, clearError: clearError2 } = appActions;
|
|
1613
|
+
const { setIsUnauthorized: setIsUnauthorized2 } = authActions;
|
|
1614
|
+
const unknownError = {
|
|
1615
|
+
status: 500,
|
|
1616
|
+
code: "UNKNOWN_EXCEPTION",
|
|
1617
|
+
message: "Ops, something doesn't seems right"
|
|
1618
|
+
};
|
|
1619
|
+
axios2.interceptors.response.use(
|
|
1620
|
+
(response) => {
|
|
1621
|
+
var _a;
|
|
1622
|
+
const { requestKey, isInterruptive, feedback } = response.config;
|
|
1623
|
+
endLoading2({ requestKey, isInterruptive });
|
|
1624
|
+
clearError2(requestKey);
|
|
1625
|
+
if (feedback == null ? void 0 : feedback.success) {
|
|
1626
|
+
(_a = options.onApiSuccess) == null ? void 0 : _a.call(options, response, feedback.success);
|
|
1627
|
+
}
|
|
1628
|
+
return Promise.resolve(response);
|
|
1629
|
+
},
|
|
1630
|
+
(error) => {
|
|
1631
|
+
var _a, _b, _c, _d, _e;
|
|
1632
|
+
const { requestKey, isInterruptive } = error.config;
|
|
1633
|
+
endLoading2({ requestKey, isInterruptive });
|
|
1634
|
+
const appError = ((_a = error.response) == null ? void 0 : _a.data) ? {
|
|
1635
|
+
code: (_b = error.response) == null ? void 0 : _b.statusText,
|
|
1636
|
+
status: (_c = error.response) == null ? void 0 : _c.status,
|
|
1637
|
+
message: (_d = error.response) == null ? void 0 : _d.data
|
|
1638
|
+
} : unknownError;
|
|
1639
|
+
setError2({ requestKey, error: appError });
|
|
1640
|
+
if (((_e = error.response) == null ? void 0 : _e.status) === 401) {
|
|
1641
|
+
setIsUnauthorized2(true);
|
|
1642
|
+
}
|
|
1643
|
+
return Promise.reject(error);
|
|
1644
|
+
}
|
|
1645
|
+
);
|
|
1646
|
+
const setOptions = (opts2) => {
|
|
1647
|
+
options = __spreadValues(__spreadValues({}, options), opts2);
|
|
1648
|
+
};
|
|
1649
|
+
return { setOptions };
|
|
1650
|
+
};
|
|
1651
|
+
|
|
1652
|
+
// services/auth.service.ts
|
|
1653
|
+
var initAuthService = (axios2) => {
|
|
1654
|
+
let options = {};
|
|
1655
|
+
const { apiBaseUrl = "/api/auth" } = options;
|
|
1656
|
+
const requestLoginMagicLink = (entityType, payload) => {
|
|
1657
|
+
return axios2.post(
|
|
1658
|
+
`${apiBaseUrl}/${entityType}`,
|
|
1659
|
+
{
|
|
1660
|
+
body: __spreadValues({}, payload)
|
|
1661
|
+
},
|
|
1662
|
+
{
|
|
1663
|
+
requestKey: `auth/${entityType}/request-login`,
|
|
1664
|
+
isInterruptive: true,
|
|
1665
|
+
feedback: {
|
|
1666
|
+
loading: "Requesting login link"
|
|
1667
|
+
}
|
|
1668
|
+
}
|
|
1669
|
+
);
|
|
1670
|
+
};
|
|
1671
|
+
const getSessionProfile = () => axios2.get("/session", {
|
|
1672
|
+
requestKey: "auth/session"
|
|
1673
|
+
});
|
|
1674
|
+
const logout2 = () => axios2.get("/logout", {
|
|
1675
|
+
requestKey: "auth/logout"
|
|
1676
|
+
});
|
|
1677
|
+
const setOptions = (opts) => {
|
|
1678
|
+
options = __spreadValues(__spreadValues({}, options), opts);
|
|
1679
|
+
};
|
|
1680
|
+
return {
|
|
1681
|
+
requestLoginMagicLink,
|
|
1682
|
+
getSessionProfile,
|
|
1683
|
+
logout: logout2,
|
|
1684
|
+
setOptions
|
|
1685
|
+
};
|
|
1686
|
+
};
|
|
1687
|
+
var auth_service_default = initAuthService;
|
|
1688
|
+
|
|
1689
|
+
// services/core.service.ts
|
|
1690
|
+
var ENTITY_API_BASE_URL = "/api/core/entity";
|
|
1691
|
+
var MUTUAL_API_BASE_URL = "/api/core/mutual";
|
|
1692
|
+
var TAG_API_BASE_URL = "/api/core/tag";
|
|
1693
|
+
var initCoreService = (monoriseStore, axios2, opts) => {
|
|
1694
|
+
let options = opts || {};
|
|
1695
|
+
const listEntities = (entityType, payload, opts2 = {}) => {
|
|
1696
|
+
const { entityApiBaseUrl = ENTITY_API_BASE_URL } = options;
|
|
1697
|
+
return axios2.get(opts2.customUrl || `${entityApiBaseUrl}/${entityType}`, {
|
|
1698
|
+
requestKey: getEntityRequestKey("list", entityType),
|
|
1699
|
+
params: payload != null ? payload : void 0,
|
|
1700
|
+
isInterruptive: opts2.isInterruptive,
|
|
1701
|
+
feedback: opts2.feedback
|
|
1702
|
+
});
|
|
1703
|
+
};
|
|
1704
|
+
const searchEntities = (entityType, query, opts2 = {}) => {
|
|
1705
|
+
const { entityApiBaseUrl = ENTITY_API_BASE_URL } = options;
|
|
1706
|
+
return axios2.get(
|
|
1707
|
+
opts2.customUrl || `${entityApiBaseUrl}/${entityType}`,
|
|
1708
|
+
{
|
|
1709
|
+
requestKey: getEntityRequestKey("search", entityType),
|
|
1710
|
+
params: { query },
|
|
1711
|
+
isInterruptive: opts2.isInterruptive,
|
|
1712
|
+
feedback: opts2.feedback
|
|
1713
|
+
}
|
|
1714
|
+
);
|
|
1715
|
+
};
|
|
1716
|
+
const listEntitiesByTag = (entityType, tagName, opts2 = {}) => {
|
|
1717
|
+
const { tagApiBaseUrl = TAG_API_BASE_URL } = options;
|
|
1718
|
+
return axios2.get(
|
|
1719
|
+
opts2.customUrl || `${tagApiBaseUrl}/${entityType}/${tagName}`,
|
|
1720
|
+
{
|
|
1721
|
+
requestKey: opts2.requestKey || getTagRequestKey("list", entityType, tagName, opts2.params),
|
|
1722
|
+
params: opts2.params,
|
|
1723
|
+
isInterruptive: opts2.isInterruptive,
|
|
1724
|
+
feedback: opts2.feedback
|
|
1725
|
+
}
|
|
1726
|
+
);
|
|
1727
|
+
};
|
|
1728
|
+
const getEntity2 = (entityType, id, opts2 = {}) => {
|
|
1729
|
+
const { entityApiBaseUrl = ENTITY_API_BASE_URL } = options;
|
|
1730
|
+
return axios2.get(
|
|
1731
|
+
opts2.customUrl || `${entityApiBaseUrl}/${entityType}/${id}`,
|
|
1732
|
+
{
|
|
1733
|
+
requestKey: getEntityRequestKey("get", entityType, id),
|
|
1734
|
+
isInterruptive: opts2.isInterruptive,
|
|
1735
|
+
feedback: __spreadValues({
|
|
1736
|
+
loading: `Retrieving ${entityType}`
|
|
1737
|
+
}, opts2.feedback || {})
|
|
1738
|
+
}
|
|
1739
|
+
);
|
|
1740
|
+
};
|
|
1741
|
+
const getEntityByUniqueField = (entityType, fieldName, value, opts2 = {}) => {
|
|
1742
|
+
const { entityApiBaseUrl = ENTITY_API_BASE_URL } = options;
|
|
1743
|
+
return axios2.get(
|
|
1744
|
+
opts2.customUrl || `${entityApiBaseUrl}/${entityType}/unique/${getUniqueFieldStateKey(fieldName, value)}`,
|
|
1745
|
+
{
|
|
1746
|
+
requestKey: getUniqueFieldRequestKey(entityType, fieldName, value),
|
|
1747
|
+
isInterruptive: opts2.isInterruptive,
|
|
1748
|
+
feedback: __spreadValues({
|
|
1749
|
+
loading: `Retrieving ${entityType}`
|
|
1750
|
+
}, opts2.feedback || {})
|
|
1751
|
+
}
|
|
1752
|
+
);
|
|
1753
|
+
};
|
|
1754
|
+
const createEntity2 = (entityType, values, opts2 = {}) => {
|
|
1755
|
+
var _a;
|
|
1756
|
+
const { entityApiBaseUrl = ENTITY_API_BASE_URL } = options;
|
|
1757
|
+
const entityConfig = monoriseStore.getState().config;
|
|
1758
|
+
return axios2.post(
|
|
1759
|
+
opts2.customUrl || `${entityApiBaseUrl}/${entityType}`,
|
|
1760
|
+
values,
|
|
1761
|
+
{
|
|
1762
|
+
requestKey: opts2.requestKey || getEntityRequestKey("create", entityType),
|
|
1763
|
+
isInterruptive: (_a = opts2.isInterruptive) != null ? _a : true,
|
|
1764
|
+
feedback: __spreadValues({
|
|
1765
|
+
loading: `Creating ${entityConfig[entityType].displayName}`,
|
|
1766
|
+
success: `${entityConfig[entityType].displayName} created`
|
|
1767
|
+
}, opts2.feedback || {})
|
|
1768
|
+
}
|
|
1769
|
+
);
|
|
1770
|
+
};
|
|
1771
|
+
const upsertEntity2 = (entityType, id, values, opts2 = {}) => {
|
|
1772
|
+
var _a;
|
|
1773
|
+
const { entityApiBaseUrl = ENTITY_API_BASE_URL } = options;
|
|
1774
|
+
const entityConfig = monoriseStore.getState().config;
|
|
1775
|
+
return axios2.put(
|
|
1776
|
+
opts2.customUrl || `${entityApiBaseUrl}/${entityType}/${id}`,
|
|
1777
|
+
values,
|
|
1778
|
+
{
|
|
1779
|
+
requestKey: getEntityRequestKey("upsert", entityType, id),
|
|
1780
|
+
isInterruptive: (_a = opts2.isInterruptive) != null ? _a : true,
|
|
1781
|
+
feedback: __spreadValues({
|
|
1782
|
+
loading: `Updating ${entityConfig[entityType].displayName}`,
|
|
1783
|
+
success: `${entityConfig[entityType].displayName} updated`
|
|
1784
|
+
}, opts2.feedback || {})
|
|
1785
|
+
}
|
|
1786
|
+
);
|
|
1787
|
+
};
|
|
1788
|
+
const editEntity2 = (entityType, id, values, opts2 = {}) => {
|
|
1789
|
+
var _a;
|
|
1790
|
+
const { entityApiBaseUrl = ENTITY_API_BASE_URL } = options;
|
|
1791
|
+
const entityConfig = monoriseStore.getState().config;
|
|
1792
|
+
return axios2.patch(
|
|
1793
|
+
opts2.customUrl || `${entityApiBaseUrl}/${entityType}/${id}`,
|
|
1794
|
+
values,
|
|
1795
|
+
{
|
|
1796
|
+
requestKey: getEntityRequestKey("edit", entityType, id),
|
|
1797
|
+
isInterruptive: (_a = opts2.isInterruptive) != null ? _a : true,
|
|
1798
|
+
feedback: __spreadValues({
|
|
1799
|
+
loading: `Updating ${entityConfig[entityType].displayName}`,
|
|
1800
|
+
success: `${entityConfig[entityType].displayName} updated`
|
|
1801
|
+
}, opts2.feedback || {})
|
|
1802
|
+
}
|
|
1803
|
+
);
|
|
1804
|
+
};
|
|
1805
|
+
const deleteEntity2 = (entityType, id, opts2 = {}) => {
|
|
1806
|
+
var _a;
|
|
1807
|
+
const { entityApiBaseUrl = ENTITY_API_BASE_URL } = options;
|
|
1808
|
+
const entityConfig = monoriseStore.getState().config;
|
|
1809
|
+
return axios2.delete(
|
|
1810
|
+
opts2.customUrl || `${entityApiBaseUrl}/${entityType}/${id}`,
|
|
1811
|
+
{
|
|
1812
|
+
requestKey: getEntityRequestKey("delete", entityType, id),
|
|
1813
|
+
isInterruptive: (_a = opts2.isInterruptive) != null ? _a : true,
|
|
1814
|
+
feedback: __spreadValues({
|
|
1815
|
+
loading: `Deleting ${entityConfig[entityType].displayName}`,
|
|
1816
|
+
success: `${entityConfig[entityType].displayName} deleted`
|
|
1817
|
+
}, opts2.feedback || {})
|
|
1818
|
+
}
|
|
1819
|
+
);
|
|
1820
|
+
};
|
|
1821
|
+
const listEntitiesByEntity = (byEntityType, entityType, byEntityId2, opts2 = {}, chainEntityQuery) => {
|
|
1822
|
+
const { mutualApiBaseUrl = MUTUAL_API_BASE_URL } = options;
|
|
1823
|
+
return axios2.get(
|
|
1824
|
+
opts2.customUrl || `${mutualApiBaseUrl}/${byEntityType}/${byEntityId2}/${entityType}`,
|
|
1825
|
+
{
|
|
1826
|
+
requestKey: getMutualRequestKey(
|
|
1827
|
+
"list",
|
|
1828
|
+
byEntityType,
|
|
1829
|
+
entityType,
|
|
1830
|
+
byEntityId2,
|
|
1831
|
+
void 0,
|
|
1832
|
+
chainEntityQuery
|
|
1833
|
+
),
|
|
1834
|
+
isInterruptive: opts2.isInterruptive,
|
|
1835
|
+
feedback: opts2.feedback,
|
|
1836
|
+
params: __spreadValues(__spreadValues({
|
|
1837
|
+
chainEntityQuery,
|
|
1838
|
+
limit: opts2.limit
|
|
1839
|
+
}, opts2.params), opts2.noData && { projection: "no-data" })
|
|
1840
|
+
}
|
|
1841
|
+
);
|
|
1842
|
+
};
|
|
1843
|
+
const getMutual2 = (byEntityType, entityType, byEntityId2, entityId, opts2 = {}) => {
|
|
1844
|
+
var _a;
|
|
1845
|
+
const { mutualApiBaseUrl = MUTUAL_API_BASE_URL } = options;
|
|
1846
|
+
return axios2.get(
|
|
1847
|
+
opts2.customUrl || `${mutualApiBaseUrl}/${getMutualStateKey(byEntityType, byEntityId2, entityType, entityId)}`,
|
|
1848
|
+
{
|
|
1849
|
+
requestKey: getMutualRequestKey(
|
|
1850
|
+
"get",
|
|
1851
|
+
byEntityType,
|
|
1852
|
+
entityType,
|
|
1853
|
+
byEntityId2,
|
|
1854
|
+
entityId
|
|
1855
|
+
),
|
|
1856
|
+
isInterruptive: (_a = opts2.isInterruptive) != null ? _a : false,
|
|
1857
|
+
feedback: opts2.feedback
|
|
1858
|
+
}
|
|
1859
|
+
);
|
|
1860
|
+
};
|
|
1861
|
+
const createMutual2 = (byEntityType, entityType, byEntityId2, entityId, payload, opts2 = {}) => {
|
|
1862
|
+
var _a;
|
|
1863
|
+
const { mutualApiBaseUrl = MUTUAL_API_BASE_URL } = options;
|
|
1864
|
+
return axios2.post(
|
|
1865
|
+
opts2.customUrl || `${mutualApiBaseUrl}/${getMutualStateKey(byEntityType, byEntityId2, entityType, entityId)}`,
|
|
1866
|
+
payload,
|
|
1867
|
+
{
|
|
1868
|
+
requestKey: getMutualRequestKey(
|
|
1869
|
+
"create",
|
|
1870
|
+
byEntityType,
|
|
1871
|
+
entityType,
|
|
1872
|
+
byEntityId2
|
|
1873
|
+
),
|
|
1874
|
+
isInterruptive: (_a = opts2.isInterruptive) != null ? _a : true,
|
|
1875
|
+
feedback: __spreadValues({
|
|
1876
|
+
loading: "Creating linkage",
|
|
1877
|
+
success: "Linkage created"
|
|
1878
|
+
}, opts2.feedback || {})
|
|
1879
|
+
}
|
|
1880
|
+
);
|
|
1881
|
+
};
|
|
1882
|
+
const editMutual2 = (byEntityType, entityType, byEntityId2, entityId, payload, opts2 = {}) => {
|
|
1883
|
+
var _a;
|
|
1884
|
+
const { mutualApiBaseUrl = MUTUAL_API_BASE_URL } = options;
|
|
1885
|
+
return axios2.patch(
|
|
1886
|
+
opts2.customUrl || `${mutualApiBaseUrl}/${getMutualStateKey(byEntityType, byEntityId2, entityType, entityId)}`,
|
|
1887
|
+
payload,
|
|
1888
|
+
{
|
|
1889
|
+
requestKey: getMutualRequestKey(
|
|
1890
|
+
"update",
|
|
1891
|
+
byEntityType,
|
|
1892
|
+
entityType,
|
|
1893
|
+
byEntityId2,
|
|
1894
|
+
entityId
|
|
1895
|
+
),
|
|
1896
|
+
isInterruptive: (_a = opts2.isInterruptive) != null ? _a : true,
|
|
1897
|
+
feedback: __spreadValues({
|
|
1898
|
+
loading: "Updating linkage",
|
|
1899
|
+
success: "Linkage updated"
|
|
1900
|
+
}, opts2.feedback || {})
|
|
1901
|
+
}
|
|
1902
|
+
);
|
|
1903
|
+
};
|
|
1904
|
+
const deleteMutual2 = (byEntityType, entityType, byEntityId2, entityId, opts2 = {}) => {
|
|
1905
|
+
var _a;
|
|
1906
|
+
const { mutualApiBaseUrl = MUTUAL_API_BASE_URL } = options;
|
|
1907
|
+
return axios2.delete(
|
|
1908
|
+
opts2.customUrl || `${mutualApiBaseUrl}/${getMutualStateKey(byEntityType, byEntityId2, entityType, entityId)}`,
|
|
1909
|
+
{
|
|
1910
|
+
requestKey: getMutualRequestKey(
|
|
1911
|
+
"delete",
|
|
1912
|
+
byEntityType,
|
|
1913
|
+
entityType,
|
|
1914
|
+
byEntityId2,
|
|
1915
|
+
entityId
|
|
1916
|
+
),
|
|
1917
|
+
isInterruptive: (_a = opts2.isInterruptive) != null ? _a : true,
|
|
1918
|
+
feedback: __spreadValues({
|
|
1919
|
+
loading: "Removing linkage",
|
|
1920
|
+
success: "Linkage removed"
|
|
1921
|
+
}, opts2.feedback || {})
|
|
1922
|
+
}
|
|
1923
|
+
);
|
|
1924
|
+
};
|
|
1925
|
+
const makeEntityService = (entityType) => ({
|
|
1926
|
+
listEntities: (payload, opts2 = {}) => listEntities(entityType, payload, opts2),
|
|
1927
|
+
searchEntities: (query, opts2 = {}) => searchEntities(entityType, query, opts2),
|
|
1928
|
+
listEntitiesByTag: (tagName, opts2 = {}) => listEntitiesByTag(entityType, tagName, opts2),
|
|
1929
|
+
getEntity: (id, opts2 = {}) => getEntity2(entityType, id, opts2),
|
|
1930
|
+
getEntityByUniqueField: (fieldName, value, opts2 = {}) => getEntityByUniqueField(entityType, fieldName, value, opts2),
|
|
1931
|
+
createEntity: (values, opts2 = {}) => createEntity2(entityType, values, opts2),
|
|
1932
|
+
upsertEntity: (id, values, opts2 = {}) => upsertEntity2(entityType, id, values, opts2),
|
|
1933
|
+
editEntity: (id, values, opts2 = {}) => editEntity2(entityType, id, values, opts2),
|
|
1934
|
+
updateEntity: (id, values, opts2 = {}) => editEntity2(entityType, id, values, opts2),
|
|
1935
|
+
deleteEntity: (id, opts2 = {}) => deleteEntity2(entityType, id, opts2)
|
|
1936
|
+
});
|
|
1937
|
+
const makeMutualService = (byEntityType, entityType) => ({
|
|
1938
|
+
listEntitiesByEntity: (byEntityId2, opts2 = {}, chainEntityQuery) => listEntitiesByEntity(
|
|
1939
|
+
byEntityType,
|
|
1940
|
+
entityType,
|
|
1941
|
+
byEntityId2,
|
|
1942
|
+
opts2,
|
|
1943
|
+
chainEntityQuery
|
|
1944
|
+
),
|
|
1945
|
+
getMutual: (byEntityId2, entityId, opts2 = {}) => getMutual2(byEntityType, entityType, byEntityId2, entityId, opts2),
|
|
1946
|
+
createMutual: (byEntityId2, entityId, payload, opts2 = {}) => createMutual2(
|
|
1947
|
+
byEntityType,
|
|
1948
|
+
entityType,
|
|
1949
|
+
byEntityId2,
|
|
1950
|
+
entityId,
|
|
1951
|
+
payload,
|
|
1952
|
+
opts2
|
|
1953
|
+
),
|
|
1954
|
+
editMutual: (byEntityId2, entityId, payload, opts2 = {}) => editMutual2(byEntityType, entityType, byEntityId2, entityId, payload, opts2),
|
|
1955
|
+
deleteMutual: (byEntityId2, entityId, opts2 = {}) => deleteMutual2(byEntityType, entityType, byEntityId2, entityId, opts2)
|
|
1956
|
+
});
|
|
1957
|
+
const setOptions = (opts2) => {
|
|
1958
|
+
options = __spreadValues(__spreadValues({}, options), opts2);
|
|
1959
|
+
};
|
|
1960
|
+
return {
|
|
1961
|
+
makeEntityService,
|
|
1962
|
+
makeMutualService,
|
|
1963
|
+
setOptions
|
|
1964
|
+
};
|
|
1965
|
+
};
|
|
1966
|
+
var core_service_default = initCoreService;
|
|
1967
|
+
|
|
1968
|
+
// services/filestore.service.ts
|
|
1969
|
+
var initFilestoreService = (axios2) => {
|
|
1970
|
+
let options = {};
|
|
1971
|
+
const { apiBaseUrl = "/api/file" } = options;
|
|
1972
|
+
const uploadFile = async ({
|
|
1973
|
+
file,
|
|
1974
|
+
scope,
|
|
1975
|
+
directory,
|
|
1976
|
+
name,
|
|
1977
|
+
disableLoading,
|
|
1978
|
+
onProgress
|
|
1979
|
+
}) => {
|
|
1980
|
+
const { data } = await axios2.get(`${apiBaseUrl}/upload`, {
|
|
1981
|
+
requestKey: `filestore/presign/file/${name}`,
|
|
1982
|
+
isInterruptive: !disableLoading,
|
|
1983
|
+
feedback: {
|
|
1984
|
+
loading: "Preparing upload"
|
|
1985
|
+
},
|
|
1986
|
+
params: {
|
|
1987
|
+
scope,
|
|
1988
|
+
directory,
|
|
1989
|
+
filename: name
|
|
1990
|
+
}
|
|
1991
|
+
});
|
|
1992
|
+
return axios2.put(data.url, file, {
|
|
1993
|
+
requestKey: `filestore/upload/${name}`,
|
|
1994
|
+
isInterruptive: !disableLoading,
|
|
1995
|
+
feedback: {
|
|
1996
|
+
loading: "Uploading file"
|
|
1997
|
+
},
|
|
1998
|
+
headers: {
|
|
1999
|
+
"Content-Type": file.type,
|
|
2000
|
+
"Content-Disposition": "inline"
|
|
2001
|
+
},
|
|
2002
|
+
onUploadProgress: (progressEvent) => {
|
|
2003
|
+
if (onProgress && progressEvent.total) {
|
|
2004
|
+
const progress = Math.round(
|
|
2005
|
+
progressEvent.loaded / progressEvent.total * 100
|
|
2006
|
+
);
|
|
2007
|
+
onProgress(progress);
|
|
2008
|
+
}
|
|
2009
|
+
}
|
|
2010
|
+
});
|
|
2011
|
+
};
|
|
2012
|
+
const deleteFiles = async (keys) => {
|
|
2013
|
+
console.log("Deleting files", keys);
|
|
2014
|
+
const { data } = await axios2.post(
|
|
2015
|
+
`${apiBaseUrl}/delete`,
|
|
2016
|
+
{
|
|
2017
|
+
keys
|
|
2018
|
+
},
|
|
2019
|
+
{
|
|
2020
|
+
requestKey: "filestore/delete"
|
|
2021
|
+
}
|
|
2022
|
+
);
|
|
2023
|
+
return data;
|
|
2024
|
+
};
|
|
2025
|
+
const uploadVideo = async ({
|
|
2026
|
+
file,
|
|
2027
|
+
scope,
|
|
2028
|
+
directory,
|
|
2029
|
+
name
|
|
2030
|
+
}) => {
|
|
2031
|
+
const { data: presign } = await axios2.get(`${apiBaseUrl}/upload`, {
|
|
2032
|
+
requestKey: `filestore/presign/video/${name}`,
|
|
2033
|
+
isInterruptive: true,
|
|
2034
|
+
feedback: {
|
|
2035
|
+
loading: "Preparing upload"
|
|
2036
|
+
},
|
|
2037
|
+
params: {
|
|
2038
|
+
scope,
|
|
2039
|
+
directory,
|
|
2040
|
+
filename: name
|
|
2041
|
+
}
|
|
2042
|
+
});
|
|
2043
|
+
await axios2.put(presign.url, file, {
|
|
2044
|
+
requestKey: `filestore/upload/video/${name}`,
|
|
2045
|
+
isInterruptive: true,
|
|
2046
|
+
feedback: {
|
|
2047
|
+
loading: "Uploading video"
|
|
2048
|
+
},
|
|
2049
|
+
headers: {
|
|
2050
|
+
"Content-Type": file.type
|
|
2051
|
+
}
|
|
2052
|
+
});
|
|
2053
|
+
const { data } = await axios2.post(
|
|
2054
|
+
`${apiBaseUrl}/video/convert`,
|
|
2055
|
+
{
|
|
2056
|
+
scope,
|
|
2057
|
+
directory,
|
|
2058
|
+
filename: name
|
|
2059
|
+
},
|
|
2060
|
+
{
|
|
2061
|
+
requestKey: "filestore/convert/video",
|
|
2062
|
+
isInterruptive: true,
|
|
2063
|
+
feedback: {
|
|
2064
|
+
loading: "Triggering video conversion"
|
|
2065
|
+
}
|
|
2066
|
+
}
|
|
2067
|
+
);
|
|
2068
|
+
return data;
|
|
2069
|
+
};
|
|
2070
|
+
const uploadAudio = async ({
|
|
2071
|
+
file,
|
|
2072
|
+
scope,
|
|
2073
|
+
directory,
|
|
2074
|
+
name
|
|
2075
|
+
}) => {
|
|
2076
|
+
const { data: presign } = await axios2.get(`${apiBaseUrl}/upload`, {
|
|
2077
|
+
requestKey: `filestore/presign/audio/${name}`,
|
|
2078
|
+
isInterruptive: true,
|
|
2079
|
+
feedback: {
|
|
2080
|
+
loading: "Preparing upload"
|
|
2081
|
+
},
|
|
2082
|
+
params: {
|
|
2083
|
+
scope,
|
|
2084
|
+
directory,
|
|
2085
|
+
filename: name
|
|
2086
|
+
}
|
|
2087
|
+
});
|
|
2088
|
+
await axios2.put(presign.url, file, {
|
|
2089
|
+
requestKey: `filestore/upload/audio/${name}`,
|
|
2090
|
+
isInterruptive: true,
|
|
2091
|
+
feedback: {
|
|
2092
|
+
loading: "Uploading audio"
|
|
2093
|
+
},
|
|
2094
|
+
headers: {
|
|
2095
|
+
"Content-Type": file.type
|
|
2096
|
+
}
|
|
2097
|
+
});
|
|
2098
|
+
const { data } = await axios2.post(
|
|
2099
|
+
`${apiBaseUrl}/audio/convert`,
|
|
2100
|
+
{
|
|
2101
|
+
scope,
|
|
2102
|
+
directory,
|
|
2103
|
+
filename: name
|
|
2104
|
+
},
|
|
2105
|
+
{
|
|
2106
|
+
requestKey: "filestore/convert/audio",
|
|
2107
|
+
isInterruptive: true,
|
|
2108
|
+
feedback: {
|
|
2109
|
+
loading: "Triggering audio conversion"
|
|
2110
|
+
}
|
|
2111
|
+
}
|
|
2112
|
+
);
|
|
2113
|
+
return data;
|
|
2114
|
+
};
|
|
2115
|
+
const getJobStatus = async (id) => {
|
|
2116
|
+
const { data } = await axios2.get(`${apiBaseUrl}/job/${id}`, {
|
|
2117
|
+
requestKey: `filestore/get-job/${id}`
|
|
2118
|
+
});
|
|
2119
|
+
return data;
|
|
2120
|
+
};
|
|
2121
|
+
const setOptions = (opts) => {
|
|
2122
|
+
options = __spreadValues(__spreadValues({}, options), opts);
|
|
2123
|
+
};
|
|
2124
|
+
return {
|
|
2125
|
+
uploadFile,
|
|
2126
|
+
deleteFiles,
|
|
2127
|
+
uploadVideo,
|
|
2128
|
+
uploadAudio,
|
|
2129
|
+
getJobStatus,
|
|
2130
|
+
setOptions
|
|
2131
|
+
};
|
|
2132
|
+
};
|
|
2133
|
+
var filestore_service_default = initFilestoreService;
|
|
2134
|
+
|
|
2135
|
+
// store/monorise.store.ts
|
|
2136
|
+
import { enableMapSet } from "immer";
|
|
2137
|
+
import { create } from "zustand";
|
|
2138
|
+
import { devtools } from "zustand/middleware";
|
|
2139
|
+
enableMapSet();
|
|
2140
|
+
var configureDevtools = (storeName) => {
|
|
2141
|
+
var _a;
|
|
2142
|
+
return {
|
|
2143
|
+
name: `${storeName} Store`,
|
|
2144
|
+
anonymousActionType: `${storeName.toLowerCase()}/action`,
|
|
2145
|
+
enabled: !["prod", "dev"].includes((_a = process.env.NEXT_PUBLIC_ENVIRONMENT) != null ? _a : ""),
|
|
2146
|
+
serialize: {
|
|
2147
|
+
options: {
|
|
2148
|
+
map: true
|
|
2149
|
+
}
|
|
2150
|
+
}
|
|
2151
|
+
};
|
|
2152
|
+
};
|
|
2153
|
+
var initMonoriseStore = () => {
|
|
2154
|
+
let options = {};
|
|
2155
|
+
const { modals = {} } = options;
|
|
2156
|
+
const monoriseStore = create(
|
|
2157
|
+
devtools(
|
|
2158
|
+
() => ({
|
|
2159
|
+
app: {
|
|
2160
|
+
ongoingRequests: /* @__PURE__ */ new Map(),
|
|
2161
|
+
loadStack: /* @__PURE__ */ new Map(),
|
|
2162
|
+
intLoadStack: /* @__PURE__ */ new Map(),
|
|
2163
|
+
loadingMessage: "",
|
|
2164
|
+
errorStack: /* @__PURE__ */ new Map(),
|
|
2165
|
+
modal: {
|
|
2166
|
+
name: null
|
|
2167
|
+
}
|
|
2168
|
+
},
|
|
2169
|
+
config: {},
|
|
2170
|
+
entity: {},
|
|
2171
|
+
mutual: {},
|
|
2172
|
+
tag: {},
|
|
2173
|
+
auth: {
|
|
2174
|
+
isUnauthorized: false,
|
|
2175
|
+
profile: {
|
|
2176
|
+
displayName: "",
|
|
2177
|
+
email: "",
|
|
2178
|
+
accountId: ""
|
|
2179
|
+
},
|
|
2180
|
+
isLoading: true
|
|
2181
|
+
}
|
|
2182
|
+
}),
|
|
2183
|
+
configureDevtools("monorise")
|
|
2184
|
+
)
|
|
2185
|
+
);
|
|
2186
|
+
const setOptions = (opts) => {
|
|
2187
|
+
options = __spreadValues(__spreadValues({}, options), opts);
|
|
2188
|
+
};
|
|
2189
|
+
return { setOptions, monoriseStore };
|
|
2190
|
+
};
|
|
2191
|
+
|
|
2192
|
+
// index.ts
|
|
2193
|
+
var initMonorise = () => {
|
|
2194
|
+
const { monoriseStore: store2, setOptions: setMonoriseOptions } = initMonoriseStore();
|
|
2195
|
+
const appActions = initAppActions(store2);
|
|
2196
|
+
const configActions = initConfigActions(store2);
|
|
2197
|
+
const axios2 = initAxiosInterceptor(store2, appActions);
|
|
2198
|
+
const authService2 = auth_service_default(axios2);
|
|
2199
|
+
const filestoreService2 = filestore_service_default(axios2);
|
|
2200
|
+
const coreService2 = core_service_default(store2, axios2);
|
|
2201
|
+
const authActions = initAuthActions(store2, authService2);
|
|
2202
|
+
const coreActions = initCoreActions(store2, appActions, coreService2);
|
|
2203
|
+
const axiosInterceptor = injectAxiosInterceptor(
|
|
2204
|
+
appActions,
|
|
2205
|
+
authActions,
|
|
2206
|
+
axios2
|
|
2207
|
+
);
|
|
2208
|
+
const config = (opts) => {
|
|
2209
|
+
setMonoriseOptions({
|
|
2210
|
+
modals: opts.modals
|
|
2211
|
+
});
|
|
2212
|
+
configActions.setConfig(opts.entityConfig);
|
|
2213
|
+
authService2.setOptions({
|
|
2214
|
+
apiBaseUrl: opts.authBaseUrl
|
|
2215
|
+
});
|
|
2216
|
+
filestoreService2.setOptions({
|
|
2217
|
+
apiBaseUrl: opts.filestoreBaseUrl
|
|
2218
|
+
});
|
|
2219
|
+
coreService2.setOptions({
|
|
2220
|
+
entityApiBaseUrl: opts.entityBaseUrl,
|
|
2221
|
+
mutualApiBaseUrl: opts.mutualBaseUrl,
|
|
2222
|
+
tagApiBaseUrl: opts.tagBaseUrl
|
|
2223
|
+
});
|
|
2224
|
+
axiosInterceptor.setOptions({
|
|
2225
|
+
onApiSuccess: opts.onApiSuccess
|
|
2226
|
+
});
|
|
2227
|
+
};
|
|
2228
|
+
return __spreadValues(__spreadValues(__spreadValues(__spreadValues({
|
|
2229
|
+
config,
|
|
2230
|
+
store: store2,
|
|
2231
|
+
axios: axios2,
|
|
2232
|
+
authService: authService2,
|
|
2233
|
+
filestoreService: filestoreService2,
|
|
2234
|
+
coreService: coreService2
|
|
2235
|
+
}, configActions), appActions), authActions), coreActions);
|
|
2236
|
+
};
|
|
2237
|
+
var Monorise = initMonorise();
|
|
2238
|
+
var {
|
|
2239
|
+
store,
|
|
2240
|
+
axios,
|
|
2241
|
+
authService,
|
|
2242
|
+
filestoreService,
|
|
2243
|
+
coreService,
|
|
2244
|
+
setConfig,
|
|
2245
|
+
getConfig,
|
|
2246
|
+
useConfig,
|
|
2247
|
+
startLoading,
|
|
2248
|
+
endLoading,
|
|
2249
|
+
setError,
|
|
2250
|
+
getError,
|
|
2251
|
+
clearError,
|
|
2252
|
+
openModal,
|
|
2253
|
+
closeModal,
|
|
2254
|
+
useLoadStore,
|
|
2255
|
+
useInterruptiveLoadStore,
|
|
2256
|
+
useErrorStore,
|
|
2257
|
+
useModalStore,
|
|
2258
|
+
requestLogin,
|
|
2259
|
+
useProfile,
|
|
2260
|
+
getProfile,
|
|
2261
|
+
useIsUnauthorized,
|
|
2262
|
+
setIsUnauthorized,
|
|
2263
|
+
logout,
|
|
2264
|
+
listMoreEntities,
|
|
2265
|
+
createEntity,
|
|
2266
|
+
upsertEntity,
|
|
2267
|
+
editEntity,
|
|
2268
|
+
updateLocalEntity,
|
|
2269
|
+
deleteEntity,
|
|
2270
|
+
getMutual,
|
|
2271
|
+
createMutual,
|
|
2272
|
+
createLocalMutual,
|
|
2273
|
+
upsertLocalMutual,
|
|
2274
|
+
editMutual,
|
|
2275
|
+
deleteMutual,
|
|
2276
|
+
deleteLocalMutual,
|
|
2277
|
+
useEntity,
|
|
2278
|
+
useEntityByUniqueField,
|
|
2279
|
+
useEntities,
|
|
2280
|
+
useMutual,
|
|
2281
|
+
useMutuals,
|
|
2282
|
+
useTaggedEntities,
|
|
2283
|
+
useEntityState,
|
|
2284
|
+
getEntity,
|
|
2285
|
+
updateLocalTaggedEntity,
|
|
2286
|
+
deleteLocalTaggedEntity
|
|
2287
|
+
} = Monorise;
|
|
2288
|
+
var index_default = Monorise;
|
|
2289
|
+
export {
|
|
2290
|
+
authService,
|
|
2291
|
+
axios,
|
|
2292
|
+
clearError,
|
|
2293
|
+
closeModal,
|
|
2294
|
+
coreService,
|
|
2295
|
+
createEntity,
|
|
2296
|
+
createLocalMutual,
|
|
2297
|
+
createMutual,
|
|
2298
|
+
index_default as default,
|
|
2299
|
+
deleteEntity,
|
|
2300
|
+
deleteLocalMutual,
|
|
2301
|
+
deleteLocalTaggedEntity,
|
|
2302
|
+
deleteMutual,
|
|
2303
|
+
editEntity,
|
|
2304
|
+
editMutual,
|
|
2305
|
+
endLoading,
|
|
2306
|
+
filestoreService,
|
|
2307
|
+
getConfig,
|
|
2308
|
+
getEntity,
|
|
2309
|
+
getEntityRequestKey,
|
|
2310
|
+
getError,
|
|
2311
|
+
getMutual,
|
|
2312
|
+
getMutualRequestKey,
|
|
2313
|
+
getProfile,
|
|
2314
|
+
getTagRequestKey,
|
|
2315
|
+
getUniqueFieldRequestKey,
|
|
2316
|
+
listMoreEntities,
|
|
2317
|
+
logout,
|
|
2318
|
+
openModal,
|
|
2319
|
+
requestLogin,
|
|
2320
|
+
setConfig,
|
|
2321
|
+
setError,
|
|
2322
|
+
setIsUnauthorized,
|
|
2323
|
+
startLoading,
|
|
2324
|
+
store,
|
|
2325
|
+
updateLocalEntity,
|
|
2326
|
+
updateLocalTaggedEntity,
|
|
2327
|
+
upsertEntity,
|
|
2328
|
+
upsertLocalMutual,
|
|
2329
|
+
useConfig,
|
|
2330
|
+
useEntities,
|
|
2331
|
+
useEntity,
|
|
2332
|
+
useEntityByUniqueField,
|
|
2333
|
+
useEntityState,
|
|
2334
|
+
useErrorStore,
|
|
2335
|
+
useInterruptiveLoadStore,
|
|
2336
|
+
useIsUnauthorized,
|
|
2337
|
+
useLoadStore,
|
|
2338
|
+
useModalStore,
|
|
2339
|
+
useMutual,
|
|
2340
|
+
useMutuals,
|
|
2341
|
+
useProfile,
|
|
2342
|
+
useTaggedEntities
|
|
2343
|
+
};
|
|
53
2344
|
//# sourceMappingURL=index.js.map
|