@monorise/react 1.0.12 → 3.0.0
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/actions/auth.action.d.ts +4 -1
- package/dist/actions/auth.action.d.ts.map +1 -1
- package/dist/actions/auth.action.js +7 -6
- package/dist/actions/auth.action.js.map +1 -1
- package/dist/actions/core.action.d.ts +163 -12
- package/dist/actions/core.action.d.ts.map +1 -1
- package/dist/actions/core.action.js +592 -168
- package/dist/actions/core.action.js.map +1 -1
- package/dist/index.d.ts +456 -30
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +3 -2
- package/dist/index.js.map +1 -1
- package/dist/lib/api.d.ts +15 -5
- package/dist/lib/api.d.ts.map +1 -1
- package/dist/lib/api.js +12 -6
- package/dist/lib/api.js.map +1 -1
- package/dist/lib/utils.d.ts +8 -0
- package/dist/lib/utils.d.ts.map +1 -1
- package/dist/lib/utils.js +24 -0
- package/dist/lib/utils.js.map +1 -1
- package/dist/services/core.service.d.ts +9 -1
- package/dist/services/core.service.d.ts.map +1 -1
- package/dist/services/core.service.js +32 -20
- package/dist/services/core.service.js.map +1 -1
- package/dist/services/filestore.service.d.ts +4 -1
- package/dist/services/filestore.service.d.ts.map +1 -1
- package/dist/services/filestore.service.js +49 -4
- package/dist/services/filestore.service.js.map +1 -1
- package/dist/store/monorise.store.d.ts +6 -0
- package/dist/store/monorise.store.d.ts.map +1 -1
- package/dist/store/monorise.store.js +1 -0
- package/dist/store/monorise.store.js.map +1 -1
- package/dist/tsconfig.tsbuildinfo +1 -0
- package/dist/types/api.type.d.ts +2 -0
- package/dist/types/api.type.d.ts.map +1 -1
- package/dist/types/api.type.js.map +1 -1
- package/package.json +20 -10
- package/actions/app.action.ts +0 -218
- package/actions/auth.action.ts +0 -94
- package/actions/config.action.ts +0 -51
- package/actions/core.action.ts +0 -940
- package/dist/index.esm.js +0 -1601
- package/dist/index.jsx +0 -48
- package/dist/index.jsx.map +0 -1
- package/dist/lib/api.jsx +0 -70
- package/dist/lib/api.jsx.map +0 -1
- package/dist/lib/config.d.ts +0 -5
- package/dist/lib/config.d.ts.map +0 -1
- package/dist/lib/config.js +0 -24
- package/dist/lib/config.js.map +0 -1
- package/index.ts +0 -194
- package/lib/api.ts +0 -150
- package/lib/constant.ts +0 -1
- package/lib/entity.ts +0 -76
- package/lib/utils.ts +0 -12
- package/services/auth.service.ts +0 -65
- package/services/core.service.ts +0 -415
- package/services/filestore.service.ts +0 -136
- package/store/monorise.store.ts +0 -105
- package/tsconfig.json +0 -118
- package/types/api.type.ts +0 -57
- package/types/axios.type.ts +0 -14
- package/types/monorise.type.ts +0 -8
- package/types/mutual.type.ts +0 -32
package/dist/index.esm.js
DELETED
|
@@ -1,1601 +0,0 @@
|
|
|
1
|
-
// actions/app.action.ts
|
|
2
|
-
import { produce } from "immer";
|
|
3
|
-
import { useEffect, useState } from "react";
|
|
4
|
-
var initAppActions = (store2) => {
|
|
5
|
-
let options = {};
|
|
6
|
-
const { modals = {} } = options;
|
|
7
|
-
const startLoading2 = ({
|
|
8
|
-
requestKey,
|
|
9
|
-
isInterruptive,
|
|
10
|
-
message,
|
|
11
|
-
request: request2
|
|
12
|
-
}) => {
|
|
13
|
-
store2.setState(
|
|
14
|
-
produce((state) => {
|
|
15
|
-
const stackType = isInterruptive ? "intLoadStack" : "loadStack";
|
|
16
|
-
const requestKeyCount = state.app[stackType].get(requestKey);
|
|
17
|
-
state.app.loadingMessage = typeof message === "string" ? message : "Loading";
|
|
18
|
-
state.app.ongoingRequests.set(requestKey, request2);
|
|
19
|
-
state.app[stackType].set(
|
|
20
|
-
requestKey,
|
|
21
|
-
requestKeyCount ? requestKeyCount + 1 : 1
|
|
22
|
-
);
|
|
23
|
-
}),
|
|
24
|
-
void 0,
|
|
25
|
-
`mr/start-loading/${requestKey}`
|
|
26
|
-
);
|
|
27
|
-
};
|
|
28
|
-
const endLoading2 = ({ requestKey, isInterruptive }) => {
|
|
29
|
-
setTimeout(() => {
|
|
30
|
-
store2.setState(
|
|
31
|
-
produce((state) => {
|
|
32
|
-
const stackType = isInterruptive ? "intLoadStack" : "loadStack";
|
|
33
|
-
const requestKeyCount = state.app[stackType].get(requestKey);
|
|
34
|
-
if (state.app.ongoingRequests.has(requestKey)) {
|
|
35
|
-
state.app.ongoingRequests.delete(requestKey);
|
|
36
|
-
}
|
|
37
|
-
if (typeof requestKeyCount === "number" && requestKeyCount > 1) {
|
|
38
|
-
state.app[stackType].set(requestKey, requestKeyCount - 1);
|
|
39
|
-
} else {
|
|
40
|
-
state.app[stackType].delete(requestKey);
|
|
41
|
-
}
|
|
42
|
-
}),
|
|
43
|
-
void 0,
|
|
44
|
-
`mr/end-loading/${requestKey}`
|
|
45
|
-
);
|
|
46
|
-
}, 500);
|
|
47
|
-
};
|
|
48
|
-
const checkIsLoading = (requestKey) => {
|
|
49
|
-
const { intLoadStack, loadStack } = store2.getState().app;
|
|
50
|
-
if (!requestKey) {
|
|
51
|
-
return intLoadStack.size > 0 || loadStack.size > 0;
|
|
52
|
-
}
|
|
53
|
-
const activeIntLoadingCount = intLoadStack.get(requestKey);
|
|
54
|
-
const isIntLoading = typeof activeIntLoadingCount === "number" && activeIntLoadingCount > 0;
|
|
55
|
-
const activeLoadingCount = loadStack.get(requestKey);
|
|
56
|
-
const isLoading = typeof activeLoadingCount === "number" && activeLoadingCount > 0;
|
|
57
|
-
return isIntLoading || isLoading;
|
|
58
|
-
};
|
|
59
|
-
const setError2 = ({ requestKey, error }) => store2.setState(
|
|
60
|
-
produce((state) => {
|
|
61
|
-
state.app.errorStack.set(requestKey, error);
|
|
62
|
-
}),
|
|
63
|
-
void 0,
|
|
64
|
-
`mr/set-error/${requestKey}`
|
|
65
|
-
);
|
|
66
|
-
const getError2 = (requestKey) => {
|
|
67
|
-
const { errorStack } = store2.getState().app;
|
|
68
|
-
return errorStack.get(requestKey);
|
|
69
|
-
};
|
|
70
|
-
const clearError2 = (requestKey) => {
|
|
71
|
-
const { errorStack } = store2.getState().app;
|
|
72
|
-
if (errorStack.has(requestKey)) {
|
|
73
|
-
store2.setState(
|
|
74
|
-
produce((state) => {
|
|
75
|
-
state.app.errorStack.delete(requestKey);
|
|
76
|
-
}),
|
|
77
|
-
void 0,
|
|
78
|
-
`mr/clear-error/${requestKey}`
|
|
79
|
-
);
|
|
80
|
-
}
|
|
81
|
-
};
|
|
82
|
-
const openModal2 = (modal) => store2.setState(
|
|
83
|
-
produce((state) => {
|
|
84
|
-
state.app.modal = modal;
|
|
85
|
-
}),
|
|
86
|
-
void 0,
|
|
87
|
-
`mr/open-modal/${modal.name}`
|
|
88
|
-
);
|
|
89
|
-
const closeModal2 = () => store2.setState(
|
|
90
|
-
produce((state) => {
|
|
91
|
-
state.app.modal = { name: null };
|
|
92
|
-
}),
|
|
93
|
-
void 0,
|
|
94
|
-
"mr/close-modal"
|
|
95
|
-
);
|
|
96
|
-
const useLoadStore2 = (requestKey) => {
|
|
97
|
-
const { loadStack, intLoadStack } = store2((state) => ({
|
|
98
|
-
loadStack: state.app.loadStack,
|
|
99
|
-
intLoadStack: state.app.intLoadStack
|
|
100
|
-
}));
|
|
101
|
-
const [isLoading, setIsLoading] = useState(false);
|
|
102
|
-
useEffect(() => {
|
|
103
|
-
if (loadStack && intLoadStack && requestKey) {
|
|
104
|
-
setIsLoading(checkIsLoading(requestKey));
|
|
105
|
-
}
|
|
106
|
-
}, [loadStack, intLoadStack, requestKey]);
|
|
107
|
-
return isLoading;
|
|
108
|
-
};
|
|
109
|
-
const useInterruptiveLoadStore2 = () => {
|
|
110
|
-
const { intLoadStack, loadingMessage } = store2((state) => ({
|
|
111
|
-
intLoadStack: state.app.intLoadStack,
|
|
112
|
-
loadingMessage: state.app.loadingMessage
|
|
113
|
-
}));
|
|
114
|
-
return {
|
|
115
|
-
isLoading: intLoadStack.size > 0,
|
|
116
|
-
message: loadingMessage
|
|
117
|
-
};
|
|
118
|
-
};
|
|
119
|
-
const useErrorStore2 = (requestKey) => {
|
|
120
|
-
const error = store2((state) => state.app.errorStack.get(requestKey));
|
|
121
|
-
useEffect(() => {
|
|
122
|
-
if (error) {
|
|
123
|
-
return () => {
|
|
124
|
-
clearError2(requestKey);
|
|
125
|
-
};
|
|
126
|
-
}
|
|
127
|
-
}, [error, requestKey]);
|
|
128
|
-
return error;
|
|
129
|
-
};
|
|
130
|
-
const useModalStore2 = () => {
|
|
131
|
-
return store2((state) => state.app.modal);
|
|
132
|
-
};
|
|
133
|
-
const setOptions = (opts) => {
|
|
134
|
-
options = {
|
|
135
|
-
...options,
|
|
136
|
-
...opts
|
|
137
|
-
};
|
|
138
|
-
};
|
|
139
|
-
return {
|
|
140
|
-
startLoading: startLoading2,
|
|
141
|
-
endLoading: endLoading2,
|
|
142
|
-
setError: setError2,
|
|
143
|
-
getError: getError2,
|
|
144
|
-
clearError: clearError2,
|
|
145
|
-
openModal: openModal2,
|
|
146
|
-
closeModal: closeModal2,
|
|
147
|
-
checkIsLoading,
|
|
148
|
-
useLoadStore: useLoadStore2,
|
|
149
|
-
useInterruptiveLoadStore: useInterruptiveLoadStore2,
|
|
150
|
-
useErrorStore: useErrorStore2,
|
|
151
|
-
useModalStore: useModalStore2,
|
|
152
|
-
setOptions
|
|
153
|
-
};
|
|
154
|
-
};
|
|
155
|
-
|
|
156
|
-
// actions/auth.action.ts
|
|
157
|
-
import { produce as produce2 } from "immer";
|
|
158
|
-
var initAuthActions = (store2, authService2) => {
|
|
159
|
-
const requestLogin2 = async (entityType, payload) => {
|
|
160
|
-
const { data } = await authService2.requestLoginMagicLink(
|
|
161
|
-
entityType,
|
|
162
|
-
payload
|
|
163
|
-
);
|
|
164
|
-
return data;
|
|
165
|
-
};
|
|
166
|
-
const useProfile2 = () => {
|
|
167
|
-
const profile = store2((state) => state.auth.profile);
|
|
168
|
-
return profile;
|
|
169
|
-
};
|
|
170
|
-
const getProfile2 = async () => {
|
|
171
|
-
try {
|
|
172
|
-
const {
|
|
173
|
-
data: { displayName, email, accountId, ...rest }
|
|
174
|
-
} = await authService2.getSessionProfile();
|
|
175
|
-
store2.setState(
|
|
176
|
-
produce2((state) => {
|
|
177
|
-
state.auth.isUnauthorized = false;
|
|
178
|
-
state.auth.profile = {
|
|
179
|
-
displayName,
|
|
180
|
-
email,
|
|
181
|
-
accountId,
|
|
182
|
-
...rest
|
|
183
|
-
};
|
|
184
|
-
}),
|
|
185
|
-
void 0,
|
|
186
|
-
"mr/auth/get-profile"
|
|
187
|
-
);
|
|
188
|
-
} catch (err) {
|
|
189
|
-
store2.setState(
|
|
190
|
-
produce2((state) => {
|
|
191
|
-
state.auth.isUnauthorized = true;
|
|
192
|
-
state.auth.profile = {};
|
|
193
|
-
}),
|
|
194
|
-
void 0,
|
|
195
|
-
"mr/auth/get-profile"
|
|
196
|
-
);
|
|
197
|
-
}
|
|
198
|
-
};
|
|
199
|
-
const useIsUnauthorized2 = () => {
|
|
200
|
-
return store2((state) => state.auth.isUnauthorized);
|
|
201
|
-
};
|
|
202
|
-
const setIsUnauthorized2 = (isUnauthorized) => store2.setState(
|
|
203
|
-
produce2((state) => {
|
|
204
|
-
state.auth.isUnauthorized = isUnauthorized;
|
|
205
|
-
})
|
|
206
|
-
);
|
|
207
|
-
const logout2 = () => {
|
|
208
|
-
authService2.logout();
|
|
209
|
-
store2.setState(
|
|
210
|
-
produce2((state) => {
|
|
211
|
-
state.auth.isUnauthorized = true;
|
|
212
|
-
state.auth.profile = {};
|
|
213
|
-
})
|
|
214
|
-
);
|
|
215
|
-
};
|
|
216
|
-
return {
|
|
217
|
-
requestLogin: requestLogin2,
|
|
218
|
-
useProfile: useProfile2,
|
|
219
|
-
getProfile: getProfile2,
|
|
220
|
-
useIsUnauthorized: useIsUnauthorized2,
|
|
221
|
-
setIsUnauthorized: setIsUnauthorized2,
|
|
222
|
-
logout: logout2
|
|
223
|
-
};
|
|
224
|
-
};
|
|
225
|
-
|
|
226
|
-
// actions/config.action.ts
|
|
227
|
-
import { produce as produce3 } from "immer";
|
|
228
|
-
var initConfigActions = (store2) => {
|
|
229
|
-
const setConfig2 = (config) => {
|
|
230
|
-
const entityMaps = Object.keys(config).reduce(
|
|
231
|
-
(acc, entity) => {
|
|
232
|
-
acc[entity] = {
|
|
233
|
-
dataMap: /* @__PURE__ */ new Map(),
|
|
234
|
-
isFirstFetched: false,
|
|
235
|
-
lastKey: ""
|
|
236
|
-
};
|
|
237
|
-
return acc;
|
|
238
|
-
},
|
|
239
|
-
{}
|
|
240
|
-
);
|
|
241
|
-
store2.setState(
|
|
242
|
-
produce3((state) => {
|
|
243
|
-
state.config = config;
|
|
244
|
-
state.entity = entityMaps;
|
|
245
|
-
})
|
|
246
|
-
);
|
|
247
|
-
};
|
|
248
|
-
const getConfig2 = () => {
|
|
249
|
-
return store2.getState().config;
|
|
250
|
-
};
|
|
251
|
-
const useConfig2 = () => {
|
|
252
|
-
const config = store2((state) => state.config);
|
|
253
|
-
return config;
|
|
254
|
-
};
|
|
255
|
-
return {
|
|
256
|
-
setConfig: setConfig2,
|
|
257
|
-
getConfig: getConfig2,
|
|
258
|
-
useConfig: useConfig2
|
|
259
|
-
};
|
|
260
|
-
};
|
|
261
|
-
|
|
262
|
-
// actions/core.action.ts
|
|
263
|
-
import { produce as produce4 } from "immer";
|
|
264
|
-
import { useEffect as useEffect2, useState as useState2 } from "react";
|
|
265
|
-
|
|
266
|
-
// lib/entity.ts
|
|
267
|
-
var constructLocal = (entityType, entityId, data) => {
|
|
268
|
-
return {
|
|
269
|
-
entityType,
|
|
270
|
-
entityId,
|
|
271
|
-
data,
|
|
272
|
-
createdAt: (/* @__PURE__ */ new Date()).toISOString(),
|
|
273
|
-
updatedAt: (/* @__PURE__ */ new Date()).toISOString()
|
|
274
|
-
};
|
|
275
|
-
};
|
|
276
|
-
var constructMutual = (byEntityType, byEntityId2, entityType, entityId, mutualData, data) => {
|
|
277
|
-
return {
|
|
278
|
-
mutualId: `${byEntityId2}-${entityId}`,
|
|
279
|
-
byEntityType,
|
|
280
|
-
byEntityId: byEntityId2,
|
|
281
|
-
entityType,
|
|
282
|
-
entityId,
|
|
283
|
-
mutualData,
|
|
284
|
-
data,
|
|
285
|
-
createdAt: (/* @__PURE__ */ new Date()).toISOString(),
|
|
286
|
-
updatedAt: (/* @__PURE__ */ new Date()).toISOString(),
|
|
287
|
-
mutualUpdatedAt: (/* @__PURE__ */ new Date()).toISOString()
|
|
288
|
-
};
|
|
289
|
-
};
|
|
290
|
-
var flipMutual = (mutual) => {
|
|
291
|
-
return {
|
|
292
|
-
...mutual,
|
|
293
|
-
entityId: mutual.byEntityId,
|
|
294
|
-
entityType: mutual.byEntityType,
|
|
295
|
-
byEntityId: mutual.entityId,
|
|
296
|
-
byEntityType: mutual.entityType
|
|
297
|
-
};
|
|
298
|
-
};
|
|
299
|
-
var byEntityId = (a, b) => {
|
|
300
|
-
if (b.entityId < a.entityId) return -1;
|
|
301
|
-
return 1;
|
|
302
|
-
};
|
|
303
|
-
|
|
304
|
-
// lib/utils.ts
|
|
305
|
-
var convertToMap = (data, mapKey) => {
|
|
306
|
-
const map = /* @__PURE__ */ new Map();
|
|
307
|
-
for (const i in data) {
|
|
308
|
-
map.set(data[i][mapKey], data[i]);
|
|
309
|
-
}
|
|
310
|
-
return map;
|
|
311
|
-
};
|
|
312
|
-
|
|
313
|
-
// actions/core.action.ts
|
|
314
|
-
var initCoreActions = (monoriseStore, appActions, coreService2) => {
|
|
315
|
-
const { makeEntityService, makeMutualService } = coreService2;
|
|
316
|
-
const { checkIsLoading, getError: getError2, useLoadStore: useLoadStore2, useErrorStore: useErrorStore2 } = appActions;
|
|
317
|
-
const listEntities = async (entityType, params = {}, opts = {}) => {
|
|
318
|
-
const store2 = monoriseStore.getState();
|
|
319
|
-
const entityState = store2.entity[entityType];
|
|
320
|
-
const { isFirstFetched } = entityState;
|
|
321
|
-
const entityService = makeEntityService(entityType);
|
|
322
|
-
const { skRange } = params;
|
|
323
|
-
const requestKey = `entity/${entityType}/list`;
|
|
324
|
-
const isLoading = checkIsLoading(requestKey);
|
|
325
|
-
const error = getError2(requestKey);
|
|
326
|
-
if (isFirstFetched && !params.skRange || isLoading || error) {
|
|
327
|
-
return;
|
|
328
|
-
}
|
|
329
|
-
const { data: result } = await entityService.listEntities(
|
|
330
|
-
{
|
|
331
|
-
...params?.all ? {} : { limit: 20 },
|
|
332
|
-
start: skRange?.start,
|
|
333
|
-
end: skRange?.end
|
|
334
|
-
},
|
|
335
|
-
opts
|
|
336
|
-
);
|
|
337
|
-
const newEntityMap = convertToMap(
|
|
338
|
-
result.data,
|
|
339
|
-
"entityId"
|
|
340
|
-
);
|
|
341
|
-
const mergedMap = new Map([
|
|
342
|
-
...newEntityMap,
|
|
343
|
-
...store2.entity[entityType].dataMap
|
|
344
|
-
]);
|
|
345
|
-
monoriseStore.setState(
|
|
346
|
-
produce4((state) => {
|
|
347
|
-
state.entity[entityType] = {
|
|
348
|
-
dataMap: params.skRange ? newEntityMap : mergedMap,
|
|
349
|
-
isFirstFetched: true,
|
|
350
|
-
lastKey: result.lastKey
|
|
351
|
-
};
|
|
352
|
-
}),
|
|
353
|
-
void 0,
|
|
354
|
-
`mr/entity/list/${entityType}`
|
|
355
|
-
);
|
|
356
|
-
};
|
|
357
|
-
const listMoreEntities2 = async (entityType, opts = {}) => {
|
|
358
|
-
const store2 = monoriseStore.getState();
|
|
359
|
-
const entityState = store2.entity[entityType];
|
|
360
|
-
const { dataMap, lastKey } = entityState;
|
|
361
|
-
const entityService = makeEntityService(entityType);
|
|
362
|
-
if (!lastKey) {
|
|
363
|
-
return;
|
|
364
|
-
}
|
|
365
|
-
const { data: result } = await entityService.listEntities(
|
|
366
|
-
{
|
|
367
|
-
limit: 20,
|
|
368
|
-
lastKey
|
|
369
|
-
},
|
|
370
|
-
opts
|
|
371
|
-
);
|
|
372
|
-
monoriseStore.setState(
|
|
373
|
-
produce4((state) => {
|
|
374
|
-
state.entity[entityType].isFirstFetched = true;
|
|
375
|
-
state.entity[entityType].lastKey = result.lastKey;
|
|
376
|
-
for (const i in result.data) {
|
|
377
|
-
state.entity[entityType].dataMap.set(
|
|
378
|
-
result.data[i].entityId,
|
|
379
|
-
result.data[i]
|
|
380
|
-
);
|
|
381
|
-
}
|
|
382
|
-
}),
|
|
383
|
-
void 0,
|
|
384
|
-
`mr/entity/list-more/${entityType}`
|
|
385
|
-
);
|
|
386
|
-
};
|
|
387
|
-
const searchEntities = async (entityType, query, opts = {}) => {
|
|
388
|
-
const entityService = makeEntityService(entityType);
|
|
389
|
-
const { data: result } = await entityService.searchEntities(query, opts);
|
|
390
|
-
monoriseStore.setState(
|
|
391
|
-
produce4((state) => {
|
|
392
|
-
state.entity[entityType].searchResults = result.data;
|
|
393
|
-
for (const i in result.data) {
|
|
394
|
-
state.entity[entityType].dataMap.set(
|
|
395
|
-
result.data[i].entityId,
|
|
396
|
-
result.data[i]
|
|
397
|
-
);
|
|
398
|
-
}
|
|
399
|
-
})
|
|
400
|
-
);
|
|
401
|
-
};
|
|
402
|
-
const listEntitiesByTag = async (entityType, tagName, opts = {}) => {
|
|
403
|
-
const tagKey = `${entityType}/${tagName}/${opts.params?.group || ""}`;
|
|
404
|
-
const store2 = monoriseStore.getState();
|
|
405
|
-
const tagState = store2.tag[tagKey] || {};
|
|
406
|
-
const { isFirstFetched, dataMap } = tagState;
|
|
407
|
-
const entityService = makeEntityService(entityType);
|
|
408
|
-
if (isFirstFetched) {
|
|
409
|
-
return;
|
|
410
|
-
}
|
|
411
|
-
const { data } = await entityService.listEntitiesByTag(tagName, opts);
|
|
412
|
-
const { entities, lastKey } = data;
|
|
413
|
-
monoriseStore.setState(
|
|
414
|
-
produce4((state) => {
|
|
415
|
-
for (const entity of entities) {
|
|
416
|
-
state.entity[entityType].dataMap.set(entity.entityId, entity);
|
|
417
|
-
}
|
|
418
|
-
})
|
|
419
|
-
);
|
|
420
|
-
monoriseStore.setState(
|
|
421
|
-
produce4((state) => {
|
|
422
|
-
state.tag[tagKey] = {
|
|
423
|
-
dataMap: convertToMap(entities, "entityId"),
|
|
424
|
-
isFirstFetched: true,
|
|
425
|
-
lastKey
|
|
426
|
-
};
|
|
427
|
-
})
|
|
428
|
-
);
|
|
429
|
-
};
|
|
430
|
-
const getEntity = async (entityType, id, opts = {}) => {
|
|
431
|
-
const store2 = monoriseStore.getState();
|
|
432
|
-
const entityState = store2.entity[entityType];
|
|
433
|
-
const { dataMap } = entityState;
|
|
434
|
-
const entityService = makeEntityService(entityType);
|
|
435
|
-
let entity = dataMap.get(id);
|
|
436
|
-
const requestKey = `entity/${entityType}/get/${id}`;
|
|
437
|
-
const isLoading = checkIsLoading(requestKey);
|
|
438
|
-
const error = getError2(requestKey);
|
|
439
|
-
if (entity || isLoading || error) {
|
|
440
|
-
return;
|
|
441
|
-
}
|
|
442
|
-
({ data: entity } = await entityService.getEntity(id, opts));
|
|
443
|
-
monoriseStore.setState(
|
|
444
|
-
produce4((state) => {
|
|
445
|
-
state.entity[entityType].dataMap.set(entity?.entityId, entity);
|
|
446
|
-
}),
|
|
447
|
-
void 0,
|
|
448
|
-
`mr/entity/get/${entityType}/${id}`
|
|
449
|
-
);
|
|
450
|
-
};
|
|
451
|
-
const createEntity2 = async (entityType, entity, opts = {}) => {
|
|
452
|
-
const entityService = makeEntityService(entityType);
|
|
453
|
-
const { data } = await entityService.createEntity(entity, opts);
|
|
454
|
-
monoriseStore.setState(
|
|
455
|
-
produce4((state) => {
|
|
456
|
-
state.entity[entityType].dataMap.set(data.entityId, data);
|
|
457
|
-
}),
|
|
458
|
-
void 0,
|
|
459
|
-
`mr/entity/create/${entityType}`
|
|
460
|
-
);
|
|
461
|
-
return data;
|
|
462
|
-
};
|
|
463
|
-
const upsertEntity2 = async (entityType, id, entity, opts = {}) => {
|
|
464
|
-
const entityService = makeEntityService(entityType);
|
|
465
|
-
const { data } = await entityService.upsertEntity(id, entity, opts);
|
|
466
|
-
monoriseStore.setState(
|
|
467
|
-
produce4((state) => {
|
|
468
|
-
state.entity[entityType].dataMap.set(data.entityId, data);
|
|
469
|
-
}),
|
|
470
|
-
void 0,
|
|
471
|
-
`mr/entity/upser/${entityType}/${id}`
|
|
472
|
-
);
|
|
473
|
-
};
|
|
474
|
-
const editEntity2 = async (entityType, id, entity, opts = {}) => {
|
|
475
|
-
const entityService = makeEntityService(entityType);
|
|
476
|
-
const { data } = await entityService.editEntity(id, entity, opts);
|
|
477
|
-
monoriseStore.setState(
|
|
478
|
-
produce4((state) => {
|
|
479
|
-
state.entity[entityType].dataMap.set(data.entityId, data);
|
|
480
|
-
}),
|
|
481
|
-
void 0,
|
|
482
|
-
`mr/entity/edit/${entityType}/${id}`
|
|
483
|
-
);
|
|
484
|
-
};
|
|
485
|
-
const deleteEntity2 = async (entityType, id, opts = {}) => {
|
|
486
|
-
const entityService = makeEntityService(entityType);
|
|
487
|
-
await entityService.deleteEntity(id, opts);
|
|
488
|
-
deleteLocalMutualsByEntity(entityType, id);
|
|
489
|
-
monoriseStore.setState(
|
|
490
|
-
produce4((state) => {
|
|
491
|
-
state.entity[entityType].dataMap.delete(id);
|
|
492
|
-
}),
|
|
493
|
-
void 0,
|
|
494
|
-
`mr/entity/delete/${entityType}/${id}`
|
|
495
|
-
);
|
|
496
|
-
};
|
|
497
|
-
const listEntitiesByEntity = async (byEntityType, entityType, id, opts = {}, chainEntityQuery) => {
|
|
498
|
-
const selfKey = `${byEntityType}/${id}/${entityType}`;
|
|
499
|
-
const mutualService = makeMutualService(byEntityType, entityType);
|
|
500
|
-
const store2 = monoriseStore.getState();
|
|
501
|
-
const mutualState = store2.mutual[selfKey] || {};
|
|
502
|
-
const { isFirstFetched } = mutualState;
|
|
503
|
-
const requestKey = `mutual/${selfKey}/list`;
|
|
504
|
-
const isLoading = checkIsLoading(requestKey);
|
|
505
|
-
const error = getError2(requestKey);
|
|
506
|
-
if (isFirstFetched || isLoading || error) {
|
|
507
|
-
return;
|
|
508
|
-
}
|
|
509
|
-
const { data } = await mutualService.listEntitiesByEntity(
|
|
510
|
-
id,
|
|
511
|
-
opts,
|
|
512
|
-
chainEntityQuery
|
|
513
|
-
);
|
|
514
|
-
const { entities, lastKey } = data;
|
|
515
|
-
const newEntityDataMap = /* @__PURE__ */ new Map();
|
|
516
|
-
for (const i in entities) {
|
|
517
|
-
newEntityDataMap.set(entities[i].entityId, entities[i]);
|
|
518
|
-
}
|
|
519
|
-
monoriseStore.setState(
|
|
520
|
-
produce4((state) => {
|
|
521
|
-
for (const [key, value] of newEntityDataMap) {
|
|
522
|
-
state.entity[entityType].dataMap.set(key, value);
|
|
523
|
-
}
|
|
524
|
-
state.mutual[selfKey] = {
|
|
525
|
-
dataMap: convertToMap(entities, "entityId"),
|
|
526
|
-
isFirstFetched: true,
|
|
527
|
-
lastKey
|
|
528
|
-
};
|
|
529
|
-
}),
|
|
530
|
-
void 0,
|
|
531
|
-
`mr/mutual/list/${byEntityType}/${id}/${entityType}`
|
|
532
|
-
);
|
|
533
|
-
};
|
|
534
|
-
const getMutual2 = async (byEntityType, entityType, byEntityId2, entityId, opts = {}) => {
|
|
535
|
-
const selfKey = `${byEntityType}/${byEntityId2}/${entityType}`;
|
|
536
|
-
const mutualService = makeMutualService(byEntityType, entityType);
|
|
537
|
-
const store2 = monoriseStore.getState();
|
|
538
|
-
const mutualState = store2.mutual[selfKey] || {};
|
|
539
|
-
const requestKey = `mutual/${byEntityType}/${byEntityId2}/${entityType}/${entityId}/get`;
|
|
540
|
-
const isLoading = checkIsLoading(requestKey);
|
|
541
|
-
const error = getError2(requestKey);
|
|
542
|
-
if (!byEntityId2 || isLoading || error) {
|
|
543
|
-
return;
|
|
544
|
-
}
|
|
545
|
-
if (mutualState.dataMap?.get(entityId)) {
|
|
546
|
-
return mutualState.dataMap.get(entityId);
|
|
547
|
-
}
|
|
548
|
-
let mutual;
|
|
549
|
-
let hasRequestFailed = false;
|
|
550
|
-
try {
|
|
551
|
-
({ data: mutual } = await mutualService.getMutual(
|
|
552
|
-
byEntityId2,
|
|
553
|
-
entityId,
|
|
554
|
-
opts
|
|
555
|
-
));
|
|
556
|
-
} catch (err) {
|
|
557
|
-
if (!opts.defaultMutualData) {
|
|
558
|
-
throw err;
|
|
559
|
-
}
|
|
560
|
-
hasRequestFailed = true;
|
|
561
|
-
mutual = {
|
|
562
|
-
createdAt: (/* @__PURE__ */ new Date()).toISOString(),
|
|
563
|
-
updatedAt: (/* @__PURE__ */ new Date()).toISOString(),
|
|
564
|
-
mutualId: `${byEntityId2}-${entityId}`,
|
|
565
|
-
mutualUpdatedAt: (/* @__PURE__ */ new Date()).toISOString(),
|
|
566
|
-
byEntityType,
|
|
567
|
-
byEntityId: byEntityId2,
|
|
568
|
-
entityType,
|
|
569
|
-
entityId,
|
|
570
|
-
mutualData: opts.defaultMutualData
|
|
571
|
-
};
|
|
572
|
-
}
|
|
573
|
-
const newMutualDataMap = new Map(store2.mutual[selfKey]?.dataMap);
|
|
574
|
-
newMutualDataMap.set(mutual.entityId, mutual);
|
|
575
|
-
if (!hasRequestFailed) {
|
|
576
|
-
const entityState = store2.entity[entityType];
|
|
577
|
-
const { dataMap: entityDataMap } = entityState;
|
|
578
|
-
const newEntityDataMap = new Map(entityDataMap);
|
|
579
|
-
newEntityDataMap.set(mutual.entityId, mutual);
|
|
580
|
-
monoriseStore.setState(
|
|
581
|
-
produce4((state) => {
|
|
582
|
-
state.mutual[selfKey] = {
|
|
583
|
-
...state.mutual[selfKey] || {},
|
|
584
|
-
dataMap: newMutualDataMap
|
|
585
|
-
};
|
|
586
|
-
state.entity[entityType].dataMap = newEntityDataMap;
|
|
587
|
-
}),
|
|
588
|
-
void 0,
|
|
589
|
-
`mr/mutual/get/${byEntityType}/${byEntityId2}/${entityType}/${entityId}`
|
|
590
|
-
);
|
|
591
|
-
}
|
|
592
|
-
};
|
|
593
|
-
const createMutual2 = async (byEntityType, entityType, byEntityId2, entityId, payload = {}, opts = {}) => {
|
|
594
|
-
const mutualService = makeMutualService(byEntityType, entityType);
|
|
595
|
-
const { data: mutual } = await mutualService.createMutual(
|
|
596
|
-
byEntityId2,
|
|
597
|
-
entityId,
|
|
598
|
-
payload,
|
|
599
|
-
opts
|
|
600
|
-
);
|
|
601
|
-
monoriseStore.setState(
|
|
602
|
-
produce4((state) => {
|
|
603
|
-
const bySide = `${byEntityType}/${byEntityId2}/${entityType}`;
|
|
604
|
-
const side = `${entityType}/${entityId}/${byEntityType}`;
|
|
605
|
-
state.mutual[bySide].dataMap = new Map(
|
|
606
|
-
state.mutual[bySide]?.dataMap
|
|
607
|
-
).set(mutual.entityId, mutual);
|
|
608
|
-
if (!state.mutual[side]) {
|
|
609
|
-
state.mutual[side] = {
|
|
610
|
-
dataMap: /* @__PURE__ */ new Map()
|
|
611
|
-
};
|
|
612
|
-
}
|
|
613
|
-
state.mutual[side].dataMap = new Map(state.mutual[side]?.dataMap).set(
|
|
614
|
-
mutual.byEntityId,
|
|
615
|
-
flipMutual(mutual)
|
|
616
|
-
);
|
|
617
|
-
}),
|
|
618
|
-
void 0,
|
|
619
|
-
`mr/mutual/create/${byEntityType}/${byEntityId2}/${entityType}/${entityId}`
|
|
620
|
-
);
|
|
621
|
-
};
|
|
622
|
-
const updateLocalEntity2 = async (entityType, entityId, data = {}) => {
|
|
623
|
-
const createdEntity = constructLocal(entityType, entityId, data);
|
|
624
|
-
monoriseStore.setState(
|
|
625
|
-
produce4((state) => {
|
|
626
|
-
state.entity[entityType].dataMap.set(entityId, createdEntity);
|
|
627
|
-
}),
|
|
628
|
-
void 0,
|
|
629
|
-
`mr/entity/local-update/${entityType}/${entityId}`
|
|
630
|
-
);
|
|
631
|
-
};
|
|
632
|
-
const upsertLocalMutual2 = async (byEntityType, entityType, byEntityId2, entityId, mutualData, data = {}) => {
|
|
633
|
-
const mutual = constructMutual(
|
|
634
|
-
byEntityType,
|
|
635
|
-
byEntityId2,
|
|
636
|
-
entityType,
|
|
637
|
-
entityId,
|
|
638
|
-
mutualData,
|
|
639
|
-
data
|
|
640
|
-
);
|
|
641
|
-
monoriseStore.setState(
|
|
642
|
-
produce4((state) => {
|
|
643
|
-
const bySide = `${byEntityType}/${byEntityId2}/${entityType}`;
|
|
644
|
-
const side = `${entityType}/${entityId}/${byEntityType}`;
|
|
645
|
-
state.mutual[bySide].dataMap = new Map(
|
|
646
|
-
state.mutual[bySide]?.dataMap
|
|
647
|
-
).set(entityId, mutual);
|
|
648
|
-
if (!state.mutual[side]) {
|
|
649
|
-
state.mutual[side] = {
|
|
650
|
-
dataMap: /* @__PURE__ */ new Map()
|
|
651
|
-
};
|
|
652
|
-
}
|
|
653
|
-
state.mutual[side].dataMap = new Map(state.mutual[side]?.dataMap).set(
|
|
654
|
-
byEntityId2,
|
|
655
|
-
flipMutual(mutual)
|
|
656
|
-
);
|
|
657
|
-
}),
|
|
658
|
-
void 0,
|
|
659
|
-
`mr/mutual/local-update/${byEntityType}/${byEntityId2}/${entityType}/${entityId}`
|
|
660
|
-
);
|
|
661
|
-
};
|
|
662
|
-
const editMutual2 = async (byEntityType, entityType, byEntityId2, entityId, payload = {}, opts = {}) => {
|
|
663
|
-
const mutualService = makeMutualService(byEntityType, entityType);
|
|
664
|
-
const { data: mutual } = await mutualService.editMutual(
|
|
665
|
-
byEntityId2,
|
|
666
|
-
entityId,
|
|
667
|
-
payload,
|
|
668
|
-
opts
|
|
669
|
-
);
|
|
670
|
-
monoriseStore.setState(
|
|
671
|
-
produce4((state) => {
|
|
672
|
-
const bySide = `${byEntityType}/${byEntityId2}/${entityType}`;
|
|
673
|
-
const side = `${entityType}/${entityId}/${byEntityType}`;
|
|
674
|
-
state.mutual[bySide].dataMap = new Map(
|
|
675
|
-
state.mutual[bySide]?.dataMap
|
|
676
|
-
).set(mutual.entityId, mutual);
|
|
677
|
-
if (!state.mutual[side]) {
|
|
678
|
-
state.mutual[side] = {
|
|
679
|
-
dataMap: /* @__PURE__ */ new Map()
|
|
680
|
-
};
|
|
681
|
-
}
|
|
682
|
-
state.mutual[side].dataMap = new Map(state.mutual[side]?.dataMap).set(
|
|
683
|
-
mutual.byEntityId,
|
|
684
|
-
flipMutual(mutual)
|
|
685
|
-
);
|
|
686
|
-
}),
|
|
687
|
-
void 0,
|
|
688
|
-
`mr/mutual/edit/${byEntityType}/${byEntityId2}/${entityType}/${entityId}`
|
|
689
|
-
);
|
|
690
|
-
};
|
|
691
|
-
const deleteMutual2 = async (byEntityType, entityType, byEntityId2, entityId = "", opts = {}) => {
|
|
692
|
-
const mutualService = makeMutualService(byEntityType, entityType);
|
|
693
|
-
const { data } = await mutualService.deleteMutual(
|
|
694
|
-
byEntityId2,
|
|
695
|
-
entityId,
|
|
696
|
-
opts
|
|
697
|
-
);
|
|
698
|
-
monoriseStore.setState(
|
|
699
|
-
produce4((state) => {
|
|
700
|
-
const bySide = `${byEntityType}/${byEntityId2}/${entityType}`;
|
|
701
|
-
const side = `${entityType}/${entityId}/${byEntityType}`;
|
|
702
|
-
state.mutual[bySide].dataMap.delete(data.entityId);
|
|
703
|
-
if (state.mutual[side]) {
|
|
704
|
-
state.mutual[side].dataMap.delete(data.byEntityId);
|
|
705
|
-
}
|
|
706
|
-
}),
|
|
707
|
-
void 0,
|
|
708
|
-
`mr/mutual/delete/${byEntityType}/${byEntityId2}/${entityType}/${entityId}`
|
|
709
|
-
);
|
|
710
|
-
};
|
|
711
|
-
const deleteLocalMutual2 = (byEntityType, entityType, byEntityId2, entityId) => {
|
|
712
|
-
monoriseStore.setState(
|
|
713
|
-
produce4((state) => {
|
|
714
|
-
const bySide = `${byEntityType}/${byEntityId2}/${entityType}`;
|
|
715
|
-
const side = `${entityType}/${entityId}/${byEntityType}`;
|
|
716
|
-
const bySideDataMap = new Map(state[bySide]?.dataMap);
|
|
717
|
-
const sideDataMap = new Map(state[side]?.dataMap);
|
|
718
|
-
bySideDataMap.delete(entityId);
|
|
719
|
-
sideDataMap.delete(byEntityId2);
|
|
720
|
-
state.mutual[bySide].dataMap.delete(entityId);
|
|
721
|
-
state.mutual[side].dataMap.delete(byEntityId2);
|
|
722
|
-
}),
|
|
723
|
-
void 0,
|
|
724
|
-
`mr/mutual/local-delete/${byEntityType}/${byEntityId2}/${entityType}/${entityId}`
|
|
725
|
-
);
|
|
726
|
-
};
|
|
727
|
-
const deleteLocalMutualsByEntity = (entityType, id) => {
|
|
728
|
-
const store2 = monoriseStore.getState();
|
|
729
|
-
const entityConfig = store2.config;
|
|
730
|
-
let mutuals = [];
|
|
731
|
-
for (const i of Object.keys(entityConfig)) {
|
|
732
|
-
const mutualState = store2.mutual[`${entityType}/${id}/${i}`];
|
|
733
|
-
mutuals = [
|
|
734
|
-
...mutuals,
|
|
735
|
-
...Array.from(mutualState?.dataMap.values() || [])
|
|
736
|
-
];
|
|
737
|
-
}
|
|
738
|
-
const updatedState = mutuals.reduce(
|
|
739
|
-
(acc, mutual) => {
|
|
740
|
-
const side = `${mutual.entityType}/${mutual.entityId}/${mutual.byEntityType}`;
|
|
741
|
-
const dataMap = new Map(store2.mutual[side].dataMap);
|
|
742
|
-
dataMap.delete(id);
|
|
743
|
-
acc[side] = {
|
|
744
|
-
...store2.mutual[side],
|
|
745
|
-
dataMap
|
|
746
|
-
};
|
|
747
|
-
return acc;
|
|
748
|
-
},
|
|
749
|
-
{}
|
|
750
|
-
);
|
|
751
|
-
monoriseStore.setState(
|
|
752
|
-
produce4((state) => {
|
|
753
|
-
state.mutual = updatedState;
|
|
754
|
-
}),
|
|
755
|
-
void 0,
|
|
756
|
-
`mr/mutual/local-delete-by-entity/${entityType}/${id}`
|
|
757
|
-
);
|
|
758
|
-
};
|
|
759
|
-
const useEntity2 = (entityType, id, opts = {}) => {
|
|
760
|
-
const dataMap = monoriseStore(
|
|
761
|
-
(state) => state.entity[entityType]?.dataMap || /* @__PURE__ */ new Map()
|
|
762
|
-
);
|
|
763
|
-
const requestKey = `entity/${entityType}/get/${id}`;
|
|
764
|
-
const isLoading = useLoadStore2(requestKey);
|
|
765
|
-
const error = useErrorStore2(requestKey);
|
|
766
|
-
useEffect2(() => {
|
|
767
|
-
if (id) {
|
|
768
|
-
getEntity(entityType, id, opts);
|
|
769
|
-
}
|
|
770
|
-
}, [id, entityType, opts]);
|
|
771
|
-
return {
|
|
772
|
-
entity: id ? dataMap.get(id) : void 0,
|
|
773
|
-
isLoading,
|
|
774
|
-
error,
|
|
775
|
-
requestKey
|
|
776
|
-
};
|
|
777
|
-
};
|
|
778
|
-
const useEntities2 = (entityType, params = {}, opts = {}) => {
|
|
779
|
-
const requestKey = `entity/${entityType}/list`;
|
|
780
|
-
const isListing = useLoadStore2(requestKey);
|
|
781
|
-
const error = useErrorStore2(requestKey);
|
|
782
|
-
const state = monoriseStore((state2) => state2.entity[entityType]);
|
|
783
|
-
const { dataMap, searchResults, isFirstFetched } = state ?? {
|
|
784
|
-
dataMap: /* @__PURE__ */ new Map()
|
|
785
|
-
};
|
|
786
|
-
const [entities, setEntities] = useState2();
|
|
787
|
-
const [query, setQuery] = useState2("");
|
|
788
|
-
const [skRange, setBetween] = useState2(params.skRange);
|
|
789
|
-
const [all, setAll] = useState2(params.all);
|
|
790
|
-
const [isSearching, setIsSearching] = useState2(false);
|
|
791
|
-
const isLoading = isListing || isSearching;
|
|
792
|
-
useEffect2(() => {
|
|
793
|
-
if (params?.skRange && skRange?.start !== params.skRange.start && skRange?.end !== params.skRange.end) {
|
|
794
|
-
setBetween(params.skRange);
|
|
795
|
-
}
|
|
796
|
-
}, [skRange?.end, skRange?.start, params.skRange]);
|
|
797
|
-
useEffect2(() => {
|
|
798
|
-
if (params?.all !== all) {
|
|
799
|
-
setAll(params.all);
|
|
800
|
-
}
|
|
801
|
-
}, [all, params.all]);
|
|
802
|
-
useEffect2(() => {
|
|
803
|
-
if (!isFirstFetched) {
|
|
804
|
-
listEntities(entityType, { skRange, all }, opts);
|
|
805
|
-
}
|
|
806
|
-
}, [all, entityType, skRange, opts, isFirstFetched]);
|
|
807
|
-
useEffect2(() => {
|
|
808
|
-
let queryTimeout;
|
|
809
|
-
if (query?.length) {
|
|
810
|
-
setIsSearching(true);
|
|
811
|
-
queryTimeout = setTimeout(async () => {
|
|
812
|
-
await searchEntities(entityType, query);
|
|
813
|
-
setIsSearching(false);
|
|
814
|
-
}, 700);
|
|
815
|
-
}
|
|
816
|
-
return () => queryTimeout && clearTimeout(queryTimeout);
|
|
817
|
-
}, [entityType, query]);
|
|
818
|
-
useEffect2(() => {
|
|
819
|
-
if (!query && dataMap.size !== entities?.length) {
|
|
820
|
-
setIsSearching(false);
|
|
821
|
-
setEntities(
|
|
822
|
-
Array.from(dataMap.values()).sort(byEntityId)
|
|
823
|
-
);
|
|
824
|
-
}
|
|
825
|
-
if (query) {
|
|
826
|
-
setEntities(searchResults);
|
|
827
|
-
}
|
|
828
|
-
}, [
|
|
829
|
-
dataMap,
|
|
830
|
-
dataMap.size,
|
|
831
|
-
entities?.length,
|
|
832
|
-
query,
|
|
833
|
-
searchResults,
|
|
834
|
-
searchResults?.length
|
|
835
|
-
]);
|
|
836
|
-
const handleQueryChange = (event) => {
|
|
837
|
-
setQuery(event.target.value);
|
|
838
|
-
};
|
|
839
|
-
const searchField = {
|
|
840
|
-
value: query,
|
|
841
|
-
onChange: handleQueryChange
|
|
842
|
-
};
|
|
843
|
-
return {
|
|
844
|
-
entities,
|
|
845
|
-
entitiesMap: dataMap,
|
|
846
|
-
searchField,
|
|
847
|
-
isLoading,
|
|
848
|
-
error,
|
|
849
|
-
requestKey
|
|
850
|
-
};
|
|
851
|
-
};
|
|
852
|
-
const useMutual2 = (byEntityType, entityType, byId, id, opts = {}) => {
|
|
853
|
-
const state = monoriseStore(
|
|
854
|
-
(state2) => state2.mutual[`${byEntityType}/${byId}/${entityType}`]
|
|
855
|
-
);
|
|
856
|
-
const requestKey = `mutual/${byEntityType}/${byId}/${entityType}/${id}/get`;
|
|
857
|
-
const isLoading = useLoadStore2(requestKey);
|
|
858
|
-
const error = useErrorStore2(requestKey);
|
|
859
|
-
const { dataMap } = state || {
|
|
860
|
-
dataMap: /* @__PURE__ */ new Map()
|
|
861
|
-
};
|
|
862
|
-
useEffect2(() => {
|
|
863
|
-
if (!dataMap.get(id)) {
|
|
864
|
-
getMutual2(byEntityType, entityType, byId, id, opts);
|
|
865
|
-
}
|
|
866
|
-
}, [byEntityType, byId, entityType, id, opts, dataMap]);
|
|
867
|
-
return {
|
|
868
|
-
mutual: dataMap.get(id),
|
|
869
|
-
isLoading,
|
|
870
|
-
error,
|
|
871
|
-
requestKey
|
|
872
|
-
};
|
|
873
|
-
};
|
|
874
|
-
const useMutuals2 = (byEntityType, entityType, byId, opts = {}, chainEntityQuery) => {
|
|
875
|
-
const state = monoriseStore(
|
|
876
|
-
(state2) => state2.mutual[`${byEntityType}/${byId}/${entityType}`]
|
|
877
|
-
);
|
|
878
|
-
const { dataMap, isFirstFetched } = state || {
|
|
879
|
-
dataMap: /* @__PURE__ */ new Map()
|
|
880
|
-
};
|
|
881
|
-
const [mutuals, setMutuals] = useState2([]);
|
|
882
|
-
const requestKey = `mutual/${byEntityType}/${entityType}/${byId}/list${chainEntityQuery ? `?${chainEntityQuery}` : ""}`;
|
|
883
|
-
const isLoading = useLoadStore2(requestKey);
|
|
884
|
-
const error = useErrorStore2(requestKey);
|
|
885
|
-
useEffect2(() => {
|
|
886
|
-
if (!isFirstFetched && byEntityType && entityType && byId) {
|
|
887
|
-
listEntitiesByEntity(
|
|
888
|
-
byEntityType,
|
|
889
|
-
entityType,
|
|
890
|
-
byId,
|
|
891
|
-
opts,
|
|
892
|
-
chainEntityQuery
|
|
893
|
-
);
|
|
894
|
-
}
|
|
895
|
-
}, [
|
|
896
|
-
isFirstFetched,
|
|
897
|
-
byEntityType,
|
|
898
|
-
byId,
|
|
899
|
-
entityType,
|
|
900
|
-
opts,
|
|
901
|
-
chainEntityQuery
|
|
902
|
-
]);
|
|
903
|
-
useEffect2(() => {
|
|
904
|
-
if (dataMap.size !== mutuals?.length) {
|
|
905
|
-
setMutuals(Array.from(dataMap.values()));
|
|
906
|
-
}
|
|
907
|
-
}, [dataMap, dataMap.size, mutuals?.length]);
|
|
908
|
-
return {
|
|
909
|
-
mutuals,
|
|
910
|
-
mutualsMap: dataMap,
|
|
911
|
-
isLoading,
|
|
912
|
-
requestKey,
|
|
913
|
-
error
|
|
914
|
-
};
|
|
915
|
-
};
|
|
916
|
-
const useEntityState2 = (entityType) => {
|
|
917
|
-
return monoriseStore((state) => state.entity[entityType]);
|
|
918
|
-
};
|
|
919
|
-
return {
|
|
920
|
-
listMoreEntities: listMoreEntities2,
|
|
921
|
-
createEntity: createEntity2,
|
|
922
|
-
upsertEntity: upsertEntity2,
|
|
923
|
-
editEntity: editEntity2,
|
|
924
|
-
deleteEntity: deleteEntity2,
|
|
925
|
-
getMutual: getMutual2,
|
|
926
|
-
updateLocalEntity: updateLocalEntity2,
|
|
927
|
-
createMutual: createMutual2,
|
|
928
|
-
upsertLocalMutual: upsertLocalMutual2,
|
|
929
|
-
editMutual: editMutual2,
|
|
930
|
-
deleteMutual: deleteMutual2,
|
|
931
|
-
deleteLocalMutual: deleteLocalMutual2,
|
|
932
|
-
useEntity: useEntity2,
|
|
933
|
-
useEntities: useEntities2,
|
|
934
|
-
useMutual: useMutual2,
|
|
935
|
-
useMutuals: useMutuals2,
|
|
936
|
-
listEntitiesByTag,
|
|
937
|
-
useEntityState: useEntityState2
|
|
938
|
-
};
|
|
939
|
-
};
|
|
940
|
-
|
|
941
|
-
// lib/api.tsx
|
|
942
|
-
import { IconCircleCheckFilled } from "@tabler/icons-react";
|
|
943
|
-
import request from "axios";
|
|
944
|
-
import { Fragment } from "react";
|
|
945
|
-
import { toast } from "sonner";
|
|
946
|
-
import { jsx, jsxs } from "react/jsx-runtime";
|
|
947
|
-
var initAxiosInterceptor = (store2, appActions) => {
|
|
948
|
-
const { startLoading: startLoading2 } = appActions;
|
|
949
|
-
const axiosInstance = request.create();
|
|
950
|
-
function makeRequest(url, config, data) {
|
|
951
|
-
const { requestKey, isInterruptive = false, feedback } = config;
|
|
952
|
-
const { ongoingRequests } = store2.getState().app;
|
|
953
|
-
if (ongoingRequests.has(requestKey)) {
|
|
954
|
-
return ongoingRequests.get(requestKey);
|
|
955
|
-
}
|
|
956
|
-
const promise = axiosInstance.request({
|
|
957
|
-
...config,
|
|
958
|
-
url,
|
|
959
|
-
data,
|
|
960
|
-
headers: {
|
|
961
|
-
"Mr-Interruptive": String(isInterruptive)
|
|
962
|
-
}
|
|
963
|
-
});
|
|
964
|
-
startLoading2({
|
|
965
|
-
requestKey,
|
|
966
|
-
isInterruptive,
|
|
967
|
-
message: feedback?.loading,
|
|
968
|
-
request: promise
|
|
969
|
-
});
|
|
970
|
-
return promise;
|
|
971
|
-
}
|
|
972
|
-
const axios2 = {
|
|
973
|
-
...axiosInstance,
|
|
974
|
-
post: (url, data, config) => makeRequest(url, { ...config, method: "POST" }, data),
|
|
975
|
-
put: (url, data, config) => makeRequest(url, { ...config, method: "PUT" }, data),
|
|
976
|
-
patch: (url, data, config) => makeRequest(url, { ...config, method: "PATCH" }, data),
|
|
977
|
-
delete: (url, config) => makeRequest(url, { ...config, method: "DELETE" }),
|
|
978
|
-
get: (url, config) => makeRequest(url, { ...config, method: "GET" })
|
|
979
|
-
};
|
|
980
|
-
return axios2;
|
|
981
|
-
};
|
|
982
|
-
var injectAxiosInterceptor = (appActions, authActions, axios2) => {
|
|
983
|
-
const { endLoading: endLoading2, setError: setError2, clearError: clearError2 } = appActions;
|
|
984
|
-
const { setIsUnauthorized: setIsUnauthorized2 } = authActions;
|
|
985
|
-
const unknownError = {
|
|
986
|
-
code: "UNKNOWN_EXCEPTION",
|
|
987
|
-
message: "Ops, something doesn't seems right"
|
|
988
|
-
};
|
|
989
|
-
axios2.interceptors.response.use(
|
|
990
|
-
(response) => {
|
|
991
|
-
const { requestKey, isInterruptive, feedback } = response.config;
|
|
992
|
-
endLoading2({ requestKey, isInterruptive });
|
|
993
|
-
clearError2(requestKey);
|
|
994
|
-
if (!feedback?.success) {
|
|
995
|
-
return Promise.resolve(response);
|
|
996
|
-
}
|
|
997
|
-
switch (typeof feedback.success) {
|
|
998
|
-
case "function":
|
|
999
|
-
toast(feedback.success(response.data));
|
|
1000
|
-
break;
|
|
1001
|
-
case "string":
|
|
1002
|
-
toast(
|
|
1003
|
-
/* @__PURE__ */ jsxs(Fragment, { children: [
|
|
1004
|
-
/* @__PURE__ */ jsx(IconCircleCheckFilled, { color: "rgb(34 197 94)" }),
|
|
1005
|
-
feedback.success
|
|
1006
|
-
] })
|
|
1007
|
-
);
|
|
1008
|
-
break;
|
|
1009
|
-
case "boolean":
|
|
1010
|
-
toast("Request success");
|
|
1011
|
-
break;
|
|
1012
|
-
}
|
|
1013
|
-
return Promise.resolve(response);
|
|
1014
|
-
},
|
|
1015
|
-
(error) => {
|
|
1016
|
-
const { requestKey, isInterruptive } = error.config;
|
|
1017
|
-
endLoading2({ requestKey, isInterruptive });
|
|
1018
|
-
setError2({ requestKey, error: error.response?.data || unknownError });
|
|
1019
|
-
if (error.response?.status === 401) {
|
|
1020
|
-
setIsUnauthorized2(true);
|
|
1021
|
-
}
|
|
1022
|
-
return Promise.reject(error);
|
|
1023
|
-
}
|
|
1024
|
-
);
|
|
1025
|
-
};
|
|
1026
|
-
|
|
1027
|
-
// services/auth.service.ts
|
|
1028
|
-
var initAuthService = (axios2) => {
|
|
1029
|
-
let options = {};
|
|
1030
|
-
const { apiBaseUrl = "/api/auth" } = options;
|
|
1031
|
-
const requestLoginMagicLink = (entityType, payload) => {
|
|
1032
|
-
return axios2.post(
|
|
1033
|
-
`${apiBaseUrl}/${entityType}`,
|
|
1034
|
-
{
|
|
1035
|
-
body: { ...payload }
|
|
1036
|
-
},
|
|
1037
|
-
{
|
|
1038
|
-
requestKey: `auth/${entityType}/request-login`,
|
|
1039
|
-
isInterruptive: true,
|
|
1040
|
-
feedback: {
|
|
1041
|
-
loading: "Requesting login link"
|
|
1042
|
-
}
|
|
1043
|
-
}
|
|
1044
|
-
);
|
|
1045
|
-
};
|
|
1046
|
-
const getSessionProfile = () => axios2.get("/session", {
|
|
1047
|
-
requestKey: "auth/session"
|
|
1048
|
-
});
|
|
1049
|
-
const logout2 = () => axios2.get("/logout", {
|
|
1050
|
-
requestKey: "auth/logout"
|
|
1051
|
-
});
|
|
1052
|
-
const setOptions = (opts) => {
|
|
1053
|
-
options = {
|
|
1054
|
-
...options,
|
|
1055
|
-
...opts
|
|
1056
|
-
};
|
|
1057
|
-
};
|
|
1058
|
-
return {
|
|
1059
|
-
requestLoginMagicLink,
|
|
1060
|
-
getSessionProfile,
|
|
1061
|
-
logout: logout2,
|
|
1062
|
-
setOptions
|
|
1063
|
-
};
|
|
1064
|
-
};
|
|
1065
|
-
var auth_service_default = initAuthService;
|
|
1066
|
-
|
|
1067
|
-
// services/core.service.ts
|
|
1068
|
-
var ENTITY_API_BASE_URL = "/api/core/entity";
|
|
1069
|
-
var MUTUAL_API_BASE_URL = "/api/core/mutual";
|
|
1070
|
-
var TAG_API_BASE_URL = "/api/core/tag";
|
|
1071
|
-
var initCoreService = (monoriseStore, axios2, opts) => {
|
|
1072
|
-
let options = opts || {};
|
|
1073
|
-
const listEntities = (entityType, payload, opts2 = {}) => {
|
|
1074
|
-
const { entityApiBaseUrl = ENTITY_API_BASE_URL } = options;
|
|
1075
|
-
return axios2.get(opts2.customUrl || `${entityApiBaseUrl}/${entityType}`, {
|
|
1076
|
-
requestKey: `entity/${entityType}/list`,
|
|
1077
|
-
params: payload ?? void 0,
|
|
1078
|
-
isInterruptive: opts2.isInterruptive,
|
|
1079
|
-
feedback: opts2.feedback
|
|
1080
|
-
});
|
|
1081
|
-
};
|
|
1082
|
-
const searchEntities = (entityType, query, opts2 = {}) => {
|
|
1083
|
-
const { entityApiBaseUrl = ENTITY_API_BASE_URL } = options;
|
|
1084
|
-
return axios2.get(
|
|
1085
|
-
opts2.customUrl || `${entityApiBaseUrl}/${entityType}`,
|
|
1086
|
-
{
|
|
1087
|
-
requestKey: `entity/${entityType}/search`,
|
|
1088
|
-
params: { query },
|
|
1089
|
-
isInterruptive: opts2.isInterruptive,
|
|
1090
|
-
feedback: opts2.feedback
|
|
1091
|
-
}
|
|
1092
|
-
);
|
|
1093
|
-
};
|
|
1094
|
-
const listEntitiesByTag = (entityType, tagName, opts2 = {}) => {
|
|
1095
|
-
const { tagApiBaseUrl = TAG_API_BASE_URL } = options;
|
|
1096
|
-
return axios2.get(
|
|
1097
|
-
opts2.customUrl || `${tagApiBaseUrl}/${entityType}/${tagName}`,
|
|
1098
|
-
{
|
|
1099
|
-
requestKey: `tag/${entityType}/${tagName}/${opts2.params?.group || ""}/list`,
|
|
1100
|
-
params: opts2.params,
|
|
1101
|
-
isInterruptive: opts2.isInterruptive,
|
|
1102
|
-
feedback: opts2.feedback
|
|
1103
|
-
}
|
|
1104
|
-
);
|
|
1105
|
-
};
|
|
1106
|
-
const getEntity = (entityType, id, opts2 = {}) => {
|
|
1107
|
-
const { entityApiBaseUrl = ENTITY_API_BASE_URL } = options;
|
|
1108
|
-
return axios2.get(
|
|
1109
|
-
opts2.customUrl || `${entityApiBaseUrl}/${entityType}/${id}`,
|
|
1110
|
-
{
|
|
1111
|
-
requestKey: `entity/${entityType}/get/${id}`,
|
|
1112
|
-
isInterruptive: opts2.isInterruptive,
|
|
1113
|
-
feedback: {
|
|
1114
|
-
loading: `Retrieving ${entityType}`,
|
|
1115
|
-
...opts2.feedback || {}
|
|
1116
|
-
}
|
|
1117
|
-
}
|
|
1118
|
-
);
|
|
1119
|
-
};
|
|
1120
|
-
const createEntity2 = (entityType, values, opts2 = {}) => {
|
|
1121
|
-
const { entityApiBaseUrl = ENTITY_API_BASE_URL } = options;
|
|
1122
|
-
const entityConfig = monoriseStore.getState().config;
|
|
1123
|
-
return axios2.post(
|
|
1124
|
-
opts2.customUrl || `${entityApiBaseUrl}/${entityType}`,
|
|
1125
|
-
values,
|
|
1126
|
-
{
|
|
1127
|
-
requestKey: `entity/${entityType}/create`,
|
|
1128
|
-
isInterruptive: opts2.isInterruptive ?? true,
|
|
1129
|
-
feedback: {
|
|
1130
|
-
loading: `Creating ${entityConfig[entityType].displayName}`,
|
|
1131
|
-
success: `${entityConfig[entityType].displayName} created`,
|
|
1132
|
-
...opts2.feedback || {}
|
|
1133
|
-
}
|
|
1134
|
-
}
|
|
1135
|
-
);
|
|
1136
|
-
};
|
|
1137
|
-
const upsertEntity2 = (entityType, id, values, opts2 = {}) => {
|
|
1138
|
-
const { entityApiBaseUrl = ENTITY_API_BASE_URL } = options;
|
|
1139
|
-
const entityConfig = monoriseStore.getState().config;
|
|
1140
|
-
return axios2.put(
|
|
1141
|
-
opts2.customUrl || `${entityApiBaseUrl}/${entityType}/${id}`,
|
|
1142
|
-
values,
|
|
1143
|
-
{
|
|
1144
|
-
requestKey: `entity/${entityType}/upsert/${id}`,
|
|
1145
|
-
isInterruptive: opts2.isInterruptive ?? true,
|
|
1146
|
-
feedback: {
|
|
1147
|
-
loading: `Updating ${entityConfig[entityType].displayName}`,
|
|
1148
|
-
success: `${entityConfig[entityType].displayName} updated`,
|
|
1149
|
-
...opts2.feedback || {}
|
|
1150
|
-
}
|
|
1151
|
-
}
|
|
1152
|
-
);
|
|
1153
|
-
};
|
|
1154
|
-
const editEntity2 = (entityType, id, values, opts2 = {}) => {
|
|
1155
|
-
const { entityApiBaseUrl = ENTITY_API_BASE_URL } = options;
|
|
1156
|
-
const entityConfig = monoriseStore.getState().config;
|
|
1157
|
-
return axios2.patch(
|
|
1158
|
-
opts2.customUrl || `${entityApiBaseUrl}/${entityType}/${id}`,
|
|
1159
|
-
values,
|
|
1160
|
-
{
|
|
1161
|
-
requestKey: `entity/${entityType}/edit/${id}`,
|
|
1162
|
-
isInterruptive: opts2.isInterruptive ?? true,
|
|
1163
|
-
feedback: {
|
|
1164
|
-
loading: `Updating ${entityConfig[entityType].displayName}`,
|
|
1165
|
-
success: `${entityConfig[entityType].displayName} updated`,
|
|
1166
|
-
...opts2.feedback || {}
|
|
1167
|
-
}
|
|
1168
|
-
}
|
|
1169
|
-
);
|
|
1170
|
-
};
|
|
1171
|
-
const deleteEntity2 = (entityType, id, opts2 = {}) => {
|
|
1172
|
-
const { entityApiBaseUrl = ENTITY_API_BASE_URL } = options;
|
|
1173
|
-
const entityConfig = monoriseStore.getState().config;
|
|
1174
|
-
return axios2.delete(
|
|
1175
|
-
opts2.customUrl || `${entityApiBaseUrl}/${entityType}/${id}`,
|
|
1176
|
-
{
|
|
1177
|
-
requestKey: `entity/${entityType}/delete/${id}`,
|
|
1178
|
-
isInterruptive: opts2.isInterruptive ?? true,
|
|
1179
|
-
feedback: {
|
|
1180
|
-
loading: `Deleting ${entityConfig[entityType].displayName}`,
|
|
1181
|
-
success: `${entityConfig[entityType].displayName} deleted`,
|
|
1182
|
-
...opts2.feedback || {}
|
|
1183
|
-
}
|
|
1184
|
-
}
|
|
1185
|
-
);
|
|
1186
|
-
};
|
|
1187
|
-
const listEntitiesByEntity = (byEntityType, entityType, byEntityId2, opts2 = {}, chainEntityQuery) => {
|
|
1188
|
-
const { mutualApiBaseUrl = MUTUAL_API_BASE_URL } = options;
|
|
1189
|
-
return axios2.get(
|
|
1190
|
-
opts2.customUrl || `${mutualApiBaseUrl}/${byEntityType}/${byEntityId2}/${entityType}${chainEntityQuery ? `?chainEntityQuery=${chainEntityQuery}` : ""}`,
|
|
1191
|
-
{
|
|
1192
|
-
requestKey: `mutual/${byEntityType}/${byEntityId2}/${entityType}/list${chainEntityQuery ? `?${chainEntityQuery}` : ""}`,
|
|
1193
|
-
isInterruptive: opts2.isInterruptive,
|
|
1194
|
-
feedback: opts2.feedback
|
|
1195
|
-
}
|
|
1196
|
-
);
|
|
1197
|
-
};
|
|
1198
|
-
const getMutual2 = (byEntityType, entityType, byEntityId2, entityId, opts2 = {}) => {
|
|
1199
|
-
const { mutualApiBaseUrl = MUTUAL_API_BASE_URL } = options;
|
|
1200
|
-
return axios2.get(
|
|
1201
|
-
opts2.customUrl || `${mutualApiBaseUrl}/${byEntityType}/${byEntityId2}/${entityType}/${entityId}`,
|
|
1202
|
-
{
|
|
1203
|
-
requestKey: `mutual/${byEntityType}/${byEntityId2}/${entityType}/${entityId}/get`,
|
|
1204
|
-
isInterruptive: opts2.isInterruptive ?? false,
|
|
1205
|
-
feedback: opts2.feedback
|
|
1206
|
-
}
|
|
1207
|
-
);
|
|
1208
|
-
};
|
|
1209
|
-
const createMutual2 = (byEntityType, entityType, byEntityId2, entityId, payload, opts2 = {}) => {
|
|
1210
|
-
const { mutualApiBaseUrl = MUTUAL_API_BASE_URL } = options;
|
|
1211
|
-
return axios2.post(
|
|
1212
|
-
opts2.customUrl || `${mutualApiBaseUrl}/${byEntityType}/${byEntityId2}/${entityType}/${entityId}`,
|
|
1213
|
-
payload,
|
|
1214
|
-
{
|
|
1215
|
-
requestKey: `mutual/${byEntityType}/${byEntityId2}/${entityType}/create`,
|
|
1216
|
-
isInterruptive: opts2.isInterruptive ?? true,
|
|
1217
|
-
feedback: {
|
|
1218
|
-
loading: "Creating linkage",
|
|
1219
|
-
success: "Linkage created",
|
|
1220
|
-
...opts2.feedback || {}
|
|
1221
|
-
}
|
|
1222
|
-
}
|
|
1223
|
-
);
|
|
1224
|
-
};
|
|
1225
|
-
const editMutual2 = (byEntityType, entityType, byEntityId2, entityId, payload, opts2 = {}) => {
|
|
1226
|
-
const { mutualApiBaseUrl = MUTUAL_API_BASE_URL } = options;
|
|
1227
|
-
return axios2.put(
|
|
1228
|
-
opts2.customUrl || `${mutualApiBaseUrl}/${byEntityType}/${byEntityId2}/${entityType}/${entityId}`,
|
|
1229
|
-
payload,
|
|
1230
|
-
{
|
|
1231
|
-
requestKey: `mutual/${byEntityType}/${byEntityId2}/${entityType}/${entityId}/update`,
|
|
1232
|
-
isInterruptive: opts2.isInterruptive ?? true,
|
|
1233
|
-
feedback: {
|
|
1234
|
-
loading: "Updating linkage",
|
|
1235
|
-
success: "Linkage updated",
|
|
1236
|
-
...opts2.feedback || {}
|
|
1237
|
-
}
|
|
1238
|
-
}
|
|
1239
|
-
);
|
|
1240
|
-
};
|
|
1241
|
-
const deleteMutual2 = (byEntityType, entityType, byEntityId2, entityId, opts2 = {}) => {
|
|
1242
|
-
const { mutualApiBaseUrl = MUTUAL_API_BASE_URL } = options;
|
|
1243
|
-
return axios2.delete(
|
|
1244
|
-
opts2.customUrl || `${mutualApiBaseUrl}/${byEntityType}/${byEntityId2}/${entityType}/${entityId}`,
|
|
1245
|
-
{
|
|
1246
|
-
requestKey: `mutual/${byEntityType}/${byEntityId2}/${entityType}/${entityId}/delete`,
|
|
1247
|
-
isInterruptive: opts2.isInterruptive ?? true,
|
|
1248
|
-
feedback: {
|
|
1249
|
-
loading: "Removing linkage",
|
|
1250
|
-
success: "Linkage removed",
|
|
1251
|
-
...opts2.feedback || {}
|
|
1252
|
-
}
|
|
1253
|
-
}
|
|
1254
|
-
);
|
|
1255
|
-
};
|
|
1256
|
-
const makeEntityService = (entityType) => ({
|
|
1257
|
-
listEntities: (payload, opts2 = {}) => listEntities(entityType, payload, opts2),
|
|
1258
|
-
searchEntities: (query, opts2 = {}) => searchEntities(entityType, query, opts2),
|
|
1259
|
-
listEntitiesByTag: (tagName, opts2 = {}) => listEntitiesByTag(entityType, tagName, opts2),
|
|
1260
|
-
getEntity: (id, opts2 = {}) => getEntity(entityType, id, opts2),
|
|
1261
|
-
createEntity: (values, opts2 = {}) => createEntity2(entityType, values, opts2),
|
|
1262
|
-
upsertEntity: (id, values, opts2 = {}) => upsertEntity2(entityType, id, values, opts2),
|
|
1263
|
-
editEntity: (id, values, opts2 = {}) => editEntity2(entityType, id, values, opts2),
|
|
1264
|
-
updateEntity: (id, values, opts2 = {}) => editEntity2(entityType, id, values, opts2),
|
|
1265
|
-
deleteEntity: (id, opts2 = {}) => deleteEntity2(entityType, id, opts2)
|
|
1266
|
-
});
|
|
1267
|
-
const makeMutualService = (byEntityType, entityType) => ({
|
|
1268
|
-
listEntitiesByEntity: (byEntityId2, opts2 = {}, chainEntityQuery) => listEntitiesByEntity(
|
|
1269
|
-
byEntityType,
|
|
1270
|
-
entityType,
|
|
1271
|
-
byEntityId2,
|
|
1272
|
-
opts2,
|
|
1273
|
-
chainEntityQuery
|
|
1274
|
-
),
|
|
1275
|
-
getMutual: (byEntityId2, entityId, opts2 = {}) => getMutual2(byEntityType, entityType, byEntityId2, entityId, opts2),
|
|
1276
|
-
createMutual: (byEntityId2, entityId, payload, opts2 = {}) => createMutual2(
|
|
1277
|
-
byEntityType,
|
|
1278
|
-
entityType,
|
|
1279
|
-
byEntityId2,
|
|
1280
|
-
entityId,
|
|
1281
|
-
payload,
|
|
1282
|
-
opts2
|
|
1283
|
-
),
|
|
1284
|
-
editMutual: (byEntityId2, entityId, payload, opts2 = {}) => editMutual2(byEntityType, entityType, byEntityId2, entityId, payload, opts2),
|
|
1285
|
-
deleteMutual: (byEntityId2, entityId, opts2 = {}) => deleteMutual2(byEntityType, entityType, byEntityId2, entityId, opts2)
|
|
1286
|
-
});
|
|
1287
|
-
const setOptions = (opts2) => {
|
|
1288
|
-
options = {
|
|
1289
|
-
...options,
|
|
1290
|
-
...opts2
|
|
1291
|
-
};
|
|
1292
|
-
};
|
|
1293
|
-
return {
|
|
1294
|
-
makeEntityService,
|
|
1295
|
-
makeMutualService,
|
|
1296
|
-
setOptions
|
|
1297
|
-
};
|
|
1298
|
-
};
|
|
1299
|
-
var core_service_default = initCoreService;
|
|
1300
|
-
|
|
1301
|
-
// services/filestore.service.ts
|
|
1302
|
-
var initFilestoreService = (axios2) => {
|
|
1303
|
-
let options = {};
|
|
1304
|
-
const { apiBaseUrl = "/api/file" } = options;
|
|
1305
|
-
const uploadFile = async ({
|
|
1306
|
-
file,
|
|
1307
|
-
scope,
|
|
1308
|
-
directory,
|
|
1309
|
-
name
|
|
1310
|
-
}) => {
|
|
1311
|
-
const { data } = await axios2.get(`${apiBaseUrl}/upload`, {
|
|
1312
|
-
requestKey: `filestore/presign/file/${name}`,
|
|
1313
|
-
isInterruptive: true,
|
|
1314
|
-
feedback: {
|
|
1315
|
-
loading: "Preparing upload"
|
|
1316
|
-
},
|
|
1317
|
-
params: {
|
|
1318
|
-
scope,
|
|
1319
|
-
directory,
|
|
1320
|
-
filename: name
|
|
1321
|
-
}
|
|
1322
|
-
});
|
|
1323
|
-
return axios2.put(data.url, file, {
|
|
1324
|
-
requestKey: `filestore/upload/${name}`,
|
|
1325
|
-
isInterruptive: true,
|
|
1326
|
-
feedback: {
|
|
1327
|
-
loading: "Uploading file"
|
|
1328
|
-
},
|
|
1329
|
-
headers: {
|
|
1330
|
-
"Content-Type": file.type
|
|
1331
|
-
}
|
|
1332
|
-
});
|
|
1333
|
-
};
|
|
1334
|
-
const deleteFiles = async (keys) => {
|
|
1335
|
-
const { data } = await axios2.post(
|
|
1336
|
-
"/file/delete",
|
|
1337
|
-
{
|
|
1338
|
-
keys
|
|
1339
|
-
},
|
|
1340
|
-
{
|
|
1341
|
-
requestKey: "filestore/delete"
|
|
1342
|
-
}
|
|
1343
|
-
);
|
|
1344
|
-
return data;
|
|
1345
|
-
};
|
|
1346
|
-
const uploadVideo = async ({
|
|
1347
|
-
file,
|
|
1348
|
-
scope,
|
|
1349
|
-
directory,
|
|
1350
|
-
name
|
|
1351
|
-
}) => {
|
|
1352
|
-
const { data: presign } = await axios2.get(`${apiBaseUrl}/upload`, {
|
|
1353
|
-
requestKey: `filestore/presign/video/${name}`,
|
|
1354
|
-
isInterruptive: true,
|
|
1355
|
-
feedback: {
|
|
1356
|
-
loading: "Preparing upload"
|
|
1357
|
-
},
|
|
1358
|
-
params: {
|
|
1359
|
-
scope,
|
|
1360
|
-
directory,
|
|
1361
|
-
filename: name
|
|
1362
|
-
}
|
|
1363
|
-
});
|
|
1364
|
-
await axios2.put(presign.url, file, {
|
|
1365
|
-
requestKey: `filestore/upload/video/${name}`,
|
|
1366
|
-
isInterruptive: true,
|
|
1367
|
-
feedback: {
|
|
1368
|
-
loading: "Uploading video"
|
|
1369
|
-
},
|
|
1370
|
-
headers: {
|
|
1371
|
-
"Content-Type": file.type
|
|
1372
|
-
}
|
|
1373
|
-
});
|
|
1374
|
-
const { data } = await axios2.post(
|
|
1375
|
-
`${apiBaseUrl}/video/convert`,
|
|
1376
|
-
{
|
|
1377
|
-
scope,
|
|
1378
|
-
directory,
|
|
1379
|
-
filename: name
|
|
1380
|
-
},
|
|
1381
|
-
{
|
|
1382
|
-
requestKey: "filestore/convert/video",
|
|
1383
|
-
isInterruptive: true,
|
|
1384
|
-
feedback: {
|
|
1385
|
-
loading: "Triggering video conversion"
|
|
1386
|
-
}
|
|
1387
|
-
}
|
|
1388
|
-
);
|
|
1389
|
-
return data;
|
|
1390
|
-
};
|
|
1391
|
-
const getJobStatus = async (id) => {
|
|
1392
|
-
const { data } = await axios2.get(`${apiBaseUrl}/job/${id}`, {
|
|
1393
|
-
requestKey: `filestore/get-job/${id}`
|
|
1394
|
-
});
|
|
1395
|
-
return data;
|
|
1396
|
-
};
|
|
1397
|
-
const setOptions = (opts) => {
|
|
1398
|
-
options = {
|
|
1399
|
-
...options,
|
|
1400
|
-
...opts
|
|
1401
|
-
};
|
|
1402
|
-
};
|
|
1403
|
-
return {
|
|
1404
|
-
uploadFile,
|
|
1405
|
-
deleteFiles,
|
|
1406
|
-
uploadVideo,
|
|
1407
|
-
getJobStatus,
|
|
1408
|
-
setOptions
|
|
1409
|
-
};
|
|
1410
|
-
};
|
|
1411
|
-
var filestore_service_default = initFilestoreService;
|
|
1412
|
-
|
|
1413
|
-
// store/monorise.store.ts
|
|
1414
|
-
import { enableMapSet } from "immer";
|
|
1415
|
-
import { create } from "zustand";
|
|
1416
|
-
import { devtools } from "zustand/middleware";
|
|
1417
|
-
enableMapSet();
|
|
1418
|
-
var configureDevtools = (storeName) => ({
|
|
1419
|
-
name: `${storeName} Store`,
|
|
1420
|
-
anonymousActionType: `${storeName.toLowerCase()}/action`,
|
|
1421
|
-
enabled: !["prod", "dev"].includes(process.env.NEXT_PUBLIC_ENVIRONMENT ?? ""),
|
|
1422
|
-
serialize: {
|
|
1423
|
-
options: {
|
|
1424
|
-
map: true
|
|
1425
|
-
}
|
|
1426
|
-
}
|
|
1427
|
-
});
|
|
1428
|
-
var initMonoriseStore = () => {
|
|
1429
|
-
let options = {};
|
|
1430
|
-
const { modals = {} } = options;
|
|
1431
|
-
const monoriseStore = create(
|
|
1432
|
-
devtools(
|
|
1433
|
-
() => ({
|
|
1434
|
-
app: {
|
|
1435
|
-
ongoingRequests: /* @__PURE__ */ new Map(),
|
|
1436
|
-
loadStack: /* @__PURE__ */ new Map(),
|
|
1437
|
-
intLoadStack: /* @__PURE__ */ new Map(),
|
|
1438
|
-
loadingMessage: "",
|
|
1439
|
-
errorStack: /* @__PURE__ */ new Map(),
|
|
1440
|
-
modal: {
|
|
1441
|
-
name: null
|
|
1442
|
-
}
|
|
1443
|
-
},
|
|
1444
|
-
config: {},
|
|
1445
|
-
entity: {},
|
|
1446
|
-
mutual: {},
|
|
1447
|
-
tag: {},
|
|
1448
|
-
auth: {
|
|
1449
|
-
isUnauthorized: false,
|
|
1450
|
-
profile: {
|
|
1451
|
-
displayName: "",
|
|
1452
|
-
email: "",
|
|
1453
|
-
accountId: ""
|
|
1454
|
-
}
|
|
1455
|
-
}
|
|
1456
|
-
}),
|
|
1457
|
-
configureDevtools("monorise")
|
|
1458
|
-
)
|
|
1459
|
-
);
|
|
1460
|
-
const setOptions = (opts) => {
|
|
1461
|
-
options = {
|
|
1462
|
-
...options,
|
|
1463
|
-
...opts
|
|
1464
|
-
};
|
|
1465
|
-
};
|
|
1466
|
-
return { setOptions, monoriseStore };
|
|
1467
|
-
};
|
|
1468
|
-
|
|
1469
|
-
// index.ts
|
|
1470
|
-
var initMonorise = () => {
|
|
1471
|
-
const { monoriseStore: store2, setOptions: setMonoriseOptions } = initMonoriseStore();
|
|
1472
|
-
const appActions = initAppActions(store2);
|
|
1473
|
-
const configActions = initConfigActions(store2);
|
|
1474
|
-
const axios2 = initAxiosInterceptor(store2, appActions);
|
|
1475
|
-
const authService2 = auth_service_default(axios2);
|
|
1476
|
-
const filestoreService2 = filestore_service_default(axios2);
|
|
1477
|
-
const coreService2 = core_service_default(store2, axios2);
|
|
1478
|
-
const authActions = initAuthActions(store2, authService2);
|
|
1479
|
-
const coreActions = initCoreActions(store2, appActions, coreService2);
|
|
1480
|
-
injectAxiosInterceptor(appActions, authActions, axios2);
|
|
1481
|
-
const config = (opts) => {
|
|
1482
|
-
setMonoriseOptions({
|
|
1483
|
-
modals: opts.modals
|
|
1484
|
-
});
|
|
1485
|
-
configActions.setConfig(opts.entityConfig);
|
|
1486
|
-
authService2.setOptions({
|
|
1487
|
-
apiBaseUrl: opts.authBaseUrl
|
|
1488
|
-
});
|
|
1489
|
-
filestoreService2.setOptions({
|
|
1490
|
-
apiBaseUrl: opts.filestoreBaseUrl
|
|
1491
|
-
});
|
|
1492
|
-
coreService2.setOptions({
|
|
1493
|
-
entityApiBaseUrl: opts.entityBaseUrl,
|
|
1494
|
-
mutualApiBaseUrl: opts.mutualBaseUrl,
|
|
1495
|
-
tagApiBaseUrl: opts.tagBaseUrl
|
|
1496
|
-
});
|
|
1497
|
-
};
|
|
1498
|
-
return {
|
|
1499
|
-
config,
|
|
1500
|
-
store: store2,
|
|
1501
|
-
axios: axios2,
|
|
1502
|
-
authService: authService2,
|
|
1503
|
-
filestoreService: filestoreService2,
|
|
1504
|
-
coreService: coreService2,
|
|
1505
|
-
...configActions,
|
|
1506
|
-
...appActions,
|
|
1507
|
-
...authActions,
|
|
1508
|
-
...coreActions
|
|
1509
|
-
};
|
|
1510
|
-
};
|
|
1511
|
-
var Monorise = initMonorise();
|
|
1512
|
-
var {
|
|
1513
|
-
store,
|
|
1514
|
-
axios,
|
|
1515
|
-
authService,
|
|
1516
|
-
filestoreService,
|
|
1517
|
-
coreService,
|
|
1518
|
-
setConfig,
|
|
1519
|
-
getConfig,
|
|
1520
|
-
useConfig,
|
|
1521
|
-
startLoading,
|
|
1522
|
-
endLoading,
|
|
1523
|
-
setError,
|
|
1524
|
-
getError,
|
|
1525
|
-
clearError,
|
|
1526
|
-
openModal,
|
|
1527
|
-
closeModal,
|
|
1528
|
-
useLoadStore,
|
|
1529
|
-
useInterruptiveLoadStore,
|
|
1530
|
-
useErrorStore,
|
|
1531
|
-
useModalStore,
|
|
1532
|
-
requestLogin,
|
|
1533
|
-
useProfile,
|
|
1534
|
-
getProfile,
|
|
1535
|
-
useIsUnauthorized,
|
|
1536
|
-
setIsUnauthorized,
|
|
1537
|
-
logout,
|
|
1538
|
-
listMoreEntities,
|
|
1539
|
-
createEntity,
|
|
1540
|
-
upsertEntity,
|
|
1541
|
-
editEntity,
|
|
1542
|
-
updateLocalEntity,
|
|
1543
|
-
deleteEntity,
|
|
1544
|
-
getMutual,
|
|
1545
|
-
createMutual,
|
|
1546
|
-
upsertLocalMutual,
|
|
1547
|
-
editMutual,
|
|
1548
|
-
deleteMutual,
|
|
1549
|
-
deleteLocalMutual,
|
|
1550
|
-
useEntity,
|
|
1551
|
-
useEntities,
|
|
1552
|
-
useMutual,
|
|
1553
|
-
useMutuals,
|
|
1554
|
-
useEntityState
|
|
1555
|
-
} = Monorise;
|
|
1556
|
-
var index_default = Monorise;
|
|
1557
|
-
export {
|
|
1558
|
-
authService,
|
|
1559
|
-
axios,
|
|
1560
|
-
clearError,
|
|
1561
|
-
closeModal,
|
|
1562
|
-
coreService,
|
|
1563
|
-
createEntity,
|
|
1564
|
-
createMutual,
|
|
1565
|
-
index_default as default,
|
|
1566
|
-
deleteEntity,
|
|
1567
|
-
deleteLocalMutual,
|
|
1568
|
-
deleteMutual,
|
|
1569
|
-
editEntity,
|
|
1570
|
-
editMutual,
|
|
1571
|
-
endLoading,
|
|
1572
|
-
filestoreService,
|
|
1573
|
-
getConfig,
|
|
1574
|
-
getError,
|
|
1575
|
-
getMutual,
|
|
1576
|
-
getProfile,
|
|
1577
|
-
listMoreEntities,
|
|
1578
|
-
logout,
|
|
1579
|
-
openModal,
|
|
1580
|
-
requestLogin,
|
|
1581
|
-
setConfig,
|
|
1582
|
-
setError,
|
|
1583
|
-
setIsUnauthorized,
|
|
1584
|
-
startLoading,
|
|
1585
|
-
store,
|
|
1586
|
-
updateLocalEntity,
|
|
1587
|
-
upsertEntity,
|
|
1588
|
-
upsertLocalMutual,
|
|
1589
|
-
useConfig,
|
|
1590
|
-
useEntities,
|
|
1591
|
-
useEntity,
|
|
1592
|
-
useEntityState,
|
|
1593
|
-
useErrorStore,
|
|
1594
|
-
useInterruptiveLoadStore,
|
|
1595
|
-
useIsUnauthorized,
|
|
1596
|
-
useLoadStore,
|
|
1597
|
-
useModalStore,
|
|
1598
|
-
useMutual,
|
|
1599
|
-
useMutuals,
|
|
1600
|
-
useProfile
|
|
1601
|
-
};
|