@monorise/react 8.3.1 → 8.4.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/app.action.d.ts +7 -2
- package/dist/actions/app.action.d.ts.map +1 -1
- package/dist/actions/core.action.d.ts +138 -1
- package/dist/actions/core.action.d.ts.map +1 -1
- package/dist/helpers/transactional.d.ts +2 -0
- package/dist/helpers/transactional.d.ts.map +1 -1
- package/dist/index.d.ts +279 -4
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +440 -145
- package/dist/index.js.map +1 -1
- package/dist/lib/api.d.ts +1 -0
- package/dist/lib/api.d.ts.map +1 -1
- package/dist/lib/utils.d.ts +6 -0
- package/dist/lib/utils.d.ts.map +1 -1
- package/dist/services/core.service.d.ts.map +1 -1
- package/dist/types/axios.type.d.ts +2 -0
- package/dist/types/axios.type.d.ts.map +1 -1
- package/package.json +3 -1
package/dist/index.js
CHANGED
|
@@ -33,20 +33,28 @@ var initAppActions = (store2) => {
|
|
|
33
33
|
void 0,
|
|
34
34
|
`mr/start-loading/${requestKey}`
|
|
35
35
|
);
|
|
36
|
+
if (request2) {
|
|
37
|
+
const forget = () => {
|
|
38
|
+
if (store2.getState().app.ongoingRequests.get(requestKey) !== request2) {
|
|
39
|
+
return;
|
|
40
|
+
}
|
|
41
|
+
store2.setState(
|
|
42
|
+
produce((state) => {
|
|
43
|
+
state.app.ongoingRequests.delete(requestKey);
|
|
44
|
+
}),
|
|
45
|
+
void 0,
|
|
46
|
+
`mr/settle-request/${requestKey}`
|
|
47
|
+
);
|
|
48
|
+
};
|
|
49
|
+
request2.then(forget, forget);
|
|
50
|
+
}
|
|
36
51
|
};
|
|
37
|
-
const endLoading2 = ({
|
|
38
|
-
requestKey,
|
|
39
|
-
isInterruptive,
|
|
40
|
-
skipDedupe
|
|
41
|
-
}) => {
|
|
52
|
+
const endLoading2 = ({ requestKey, isInterruptive }) => {
|
|
42
53
|
setTimeout(() => {
|
|
43
54
|
store2.setState(
|
|
44
55
|
produce((state) => {
|
|
45
56
|
const stackType = isInterruptive ? "intLoadStack" : "loadStack";
|
|
46
57
|
const requestKeyCount = state.app[stackType].get(requestKey);
|
|
47
|
-
if (!skipDedupe && state.app.ongoingRequests.has(requestKey)) {
|
|
48
|
-
state.app.ongoingRequests.delete(requestKey);
|
|
49
|
-
}
|
|
50
58
|
if (typeof requestKeyCount === "number" && requestKeyCount > 1) {
|
|
51
59
|
state.app[stackType].set(requestKey, requestKeyCount - 1);
|
|
52
60
|
} else {
|
|
@@ -269,47 +277,10 @@ var initConfigActions = (store2) => {
|
|
|
269
277
|
|
|
270
278
|
// actions/core.action.ts
|
|
271
279
|
import { produce as produce4 } from "immer";
|
|
272
|
-
import { useEffect as useEffect2, useState as useState2 } from "react";
|
|
273
|
-
|
|
274
|
-
// lib/entity.ts
|
|
275
|
-
var constructLocal = (entityType, entityId, data) => {
|
|
276
|
-
return {
|
|
277
|
-
entityType,
|
|
278
|
-
entityId,
|
|
279
|
-
data,
|
|
280
|
-
createdAt: (/* @__PURE__ */ new Date()).toISOString(),
|
|
281
|
-
updatedAt: (/* @__PURE__ */ new Date()).toISOString()
|
|
282
|
-
};
|
|
283
|
-
};
|
|
284
|
-
var constructMutual = (byEntityType, byEntityId2, entityType, entityId, mutualData, data) => {
|
|
285
|
-
return {
|
|
286
|
-
mutualId: `${byEntityId2}-${entityId}`,
|
|
287
|
-
byEntityType,
|
|
288
|
-
byEntityId: byEntityId2,
|
|
289
|
-
entityType,
|
|
290
|
-
entityId,
|
|
291
|
-
mutualData,
|
|
292
|
-
data,
|
|
293
|
-
createdAt: (/* @__PURE__ */ new Date()).toISOString(),
|
|
294
|
-
updatedAt: (/* @__PURE__ */ new Date()).toISOString(),
|
|
295
|
-
mutualUpdatedAt: (/* @__PURE__ */ new Date()).toISOString()
|
|
296
|
-
};
|
|
297
|
-
};
|
|
298
|
-
var flipMutual = (mutual, byEntityData) => {
|
|
299
|
-
return __spreadProps(__spreadValues({}, mutual), {
|
|
300
|
-
entityId: mutual.byEntityId,
|
|
301
|
-
entityType: mutual.byEntityType,
|
|
302
|
-
byEntityId: mutual.entityId,
|
|
303
|
-
byEntityType: mutual.entityType,
|
|
304
|
-
data: byEntityData
|
|
305
|
-
});
|
|
306
|
-
};
|
|
307
|
-
var byEntityId = (a, b) => {
|
|
308
|
-
if (b.entityId < a.entityId) return -1;
|
|
309
|
-
return 1;
|
|
310
|
-
};
|
|
280
|
+
import { useCallback, useEffect as useEffect2, useRef, useState as useState2 } from "react";
|
|
311
281
|
|
|
312
282
|
// lib/utils.ts
|
|
283
|
+
import { nanoid } from "nanoid";
|
|
313
284
|
var convertToMap = (data, mapKey) => {
|
|
314
285
|
const map = /* @__PURE__ */ new Map();
|
|
315
286
|
for (const i in data) {
|
|
@@ -344,6 +315,7 @@ var getUniqueFieldStateKey = (fieldName, fieldValue) => {
|
|
|
344
315
|
var getEntityRequestKey = (mode, entityType, entityId) => {
|
|
345
316
|
return `entity/${entityType}/${mode}${entityId ? `/${entityId}` : ""}`;
|
|
346
317
|
};
|
|
318
|
+
var createMutationCallRequestKey = (requestKey) => `${requestKey}#${nanoid()}`;
|
|
347
319
|
var getMutualRequestKey = (mode, byEntityType, entityType, byEntityId2, entityId, chainEntityQuery) => {
|
|
348
320
|
return `mutual/${getMutualStateKey(byEntityType, byEntityId2, entityType, entityId, chainEntityQuery)}/${mode}`;
|
|
349
321
|
};
|
|
@@ -355,7 +327,6 @@ var getUniqueFieldRequestKey = (entityType, fieldName, value) => {
|
|
|
355
327
|
};
|
|
356
328
|
|
|
357
329
|
// helpers/transactional.ts
|
|
358
|
-
import { nanoid } from "nanoid";
|
|
359
330
|
var getTransactionOperationRequestKey = (op) => {
|
|
360
331
|
switch (op.operation) {
|
|
361
332
|
case "createEntity":
|
|
@@ -373,7 +344,8 @@ var getTransactionOperationRequestKey = (op) => {
|
|
|
373
344
|
"create",
|
|
374
345
|
op.byEntityType,
|
|
375
346
|
op.entityType,
|
|
376
|
-
op.byEntityId
|
|
347
|
+
op.byEntityId,
|
|
348
|
+
op.entityId
|
|
377
349
|
);
|
|
378
350
|
case "updateMutual":
|
|
379
351
|
return getMutualRequestKey(
|
|
@@ -393,14 +365,21 @@ var getTransactionOperationRequestKey = (op) => {
|
|
|
393
365
|
);
|
|
394
366
|
}
|
|
395
367
|
};
|
|
396
|
-
var
|
|
397
|
-
|
|
398
|
-
op.
|
|
399
|
-
|
|
400
|
-
|
|
401
|
-
|
|
402
|
-
|
|
403
|
-
|
|
368
|
+
var getTransactionOperationRequestKeys = (op) => {
|
|
369
|
+
const requestKey = getTransactionOperationRequestKey(op);
|
|
370
|
+
if (op.operation !== "createMutual") return [requestKey];
|
|
371
|
+
return [
|
|
372
|
+
requestKey,
|
|
373
|
+
getMutualRequestKey(
|
|
374
|
+
"create",
|
|
375
|
+
op.byEntityType,
|
|
376
|
+
op.entityType,
|
|
377
|
+
op.byEntityId
|
|
378
|
+
)
|
|
379
|
+
];
|
|
380
|
+
};
|
|
381
|
+
var getTransactionRequestKey = (operations) => `transaction/${operations.map(getTransactionOperationRequestKey).join("|")}`;
|
|
382
|
+
var createTransactionCallRequestKey = (operations) => createMutationCallRequestKey(getTransactionRequestKey(operations));
|
|
404
383
|
var transactional = {
|
|
405
384
|
createEntity: (entityType, payload) => {
|
|
406
385
|
const _a = payload, { entityId } = _a, rest = __objRest(_a, ["entityId"]);
|
|
@@ -459,6 +438,44 @@ var transactional = {
|
|
|
459
438
|
})
|
|
460
439
|
};
|
|
461
440
|
|
|
441
|
+
// lib/entity.ts
|
|
442
|
+
var constructLocal = (entityType, entityId, data) => {
|
|
443
|
+
return {
|
|
444
|
+
entityType,
|
|
445
|
+
entityId,
|
|
446
|
+
data,
|
|
447
|
+
createdAt: (/* @__PURE__ */ new Date()).toISOString(),
|
|
448
|
+
updatedAt: (/* @__PURE__ */ new Date()).toISOString()
|
|
449
|
+
};
|
|
450
|
+
};
|
|
451
|
+
var constructMutual = (byEntityType, byEntityId2, entityType, entityId, mutualData, data) => {
|
|
452
|
+
return {
|
|
453
|
+
mutualId: `${byEntityId2}-${entityId}`,
|
|
454
|
+
byEntityType,
|
|
455
|
+
byEntityId: byEntityId2,
|
|
456
|
+
entityType,
|
|
457
|
+
entityId,
|
|
458
|
+
mutualData,
|
|
459
|
+
data,
|
|
460
|
+
createdAt: (/* @__PURE__ */ new Date()).toISOString(),
|
|
461
|
+
updatedAt: (/* @__PURE__ */ new Date()).toISOString(),
|
|
462
|
+
mutualUpdatedAt: (/* @__PURE__ */ new Date()).toISOString()
|
|
463
|
+
};
|
|
464
|
+
};
|
|
465
|
+
var flipMutual = (mutual, byEntityData) => {
|
|
466
|
+
return __spreadProps(__spreadValues({}, mutual), {
|
|
467
|
+
entityId: mutual.byEntityId,
|
|
468
|
+
entityType: mutual.byEntityType,
|
|
469
|
+
byEntityId: mutual.entityId,
|
|
470
|
+
byEntityType: mutual.entityType,
|
|
471
|
+
data: byEntityData
|
|
472
|
+
});
|
|
473
|
+
};
|
|
474
|
+
var byEntityId = (a, b) => {
|
|
475
|
+
if (b.entityId < a.entityId) return -1;
|
|
476
|
+
return 1;
|
|
477
|
+
};
|
|
478
|
+
|
|
462
479
|
// actions/core.action.ts
|
|
463
480
|
var defaultOnError = (error) => {
|
|
464
481
|
if (!(error instanceof Error) && error.status >= 500) {
|
|
@@ -808,18 +825,20 @@ var initCoreActions = (monoriseStore, appActions, coreService2) => {
|
|
|
808
825
|
if (keyParams.query) {
|
|
809
826
|
continue;
|
|
810
827
|
}
|
|
811
|
-
const matches = processorResults.some(
|
|
812
|
-
|
|
813
|
-
|
|
814
|
-
|
|
815
|
-
|
|
816
|
-
|
|
817
|
-
|
|
818
|
-
|
|
819
|
-
|
|
828
|
+
const matches = processorResults.some(
|
|
829
|
+
(result) => {
|
|
830
|
+
if (keyParams.group && result.group !== keyParams.group) {
|
|
831
|
+
return false;
|
|
832
|
+
}
|
|
833
|
+
if (keyParams.start && (!result.sortValue || result.sortValue < keyParams.start)) {
|
|
834
|
+
return false;
|
|
835
|
+
}
|
|
836
|
+
if (keyParams.end && (!result.sortValue || result.sortValue > keyParams.end)) {
|
|
837
|
+
return false;
|
|
838
|
+
}
|
|
839
|
+
return true;
|
|
820
840
|
}
|
|
821
|
-
|
|
822
|
-
});
|
|
841
|
+
);
|
|
823
842
|
if (matches) {
|
|
824
843
|
state.tag[tagKey].dataMap.set(data.entityId, data);
|
|
825
844
|
}
|
|
@@ -1027,22 +1046,27 @@ var initCoreActions = (monoriseStore, appActions, coreService2) => {
|
|
|
1027
1046
|
}
|
|
1028
1047
|
};
|
|
1029
1048
|
const executeTransaction2 = async (operations, opts = {}) => {
|
|
1030
|
-
var _a, _b, _c, _d;
|
|
1049
|
+
var _a, _b, _c, _d, _e;
|
|
1031
1050
|
const onError = (_a = opts.onError) != null ? _a : defaultOnError;
|
|
1032
1051
|
const isInterruptive = (_b = opts.isInterruptive) != null ? _b : true;
|
|
1033
|
-
const
|
|
1034
|
-
|
|
1052
|
+
const stateRequestKeys = Array.from(
|
|
1053
|
+
/* @__PURE__ */ new Set([
|
|
1054
|
+
getTransactionRequestKey(operations),
|
|
1055
|
+
...operations.flatMap(getTransactionOperationRequestKeys)
|
|
1056
|
+
])
|
|
1057
|
+
);
|
|
1058
|
+
const callRequestKey = (_c = opts.requestKey) != null ? _c : createTransactionCallRequestKey(operations);
|
|
1035
1059
|
const callPromise = coreService2.executeTransaction(operations, __spreadProps(__spreadValues({}, opts), {
|
|
1036
1060
|
requestKey: callRequestKey
|
|
1037
1061
|
}));
|
|
1038
|
-
const loadingMessage = (
|
|
1039
|
-
for (const requestKey of
|
|
1062
|
+
const loadingMessage = (_e = (_d = opts.feedback) == null ? void 0 : _d.loading) != null ? _e : "Processing transaction";
|
|
1063
|
+
for (const requestKey of stateRequestKeys) {
|
|
1040
1064
|
startLoading2({ requestKey, isInterruptive, message: loadingMessage });
|
|
1041
1065
|
}
|
|
1042
1066
|
let settled = false;
|
|
1043
1067
|
try {
|
|
1044
1068
|
const { data } = await callPromise;
|
|
1045
|
-
for (const requestKey of
|
|
1069
|
+
for (const requestKey of stateRequestKeys) {
|
|
1046
1070
|
endLoading2({ requestKey, isInterruptive, skipDedupe: true });
|
|
1047
1071
|
clearError2(requestKey);
|
|
1048
1072
|
}
|
|
@@ -1051,7 +1075,7 @@ var initCoreActions = (monoriseStore, appActions, coreService2) => {
|
|
|
1051
1075
|
monoriseStore.setState(
|
|
1052
1076
|
produce4((state) => {
|
|
1053
1077
|
data.results.forEach((entry, index) => {
|
|
1054
|
-
var _a2, _b2, _c2, _d2,
|
|
1078
|
+
var _a2, _b2, _c2, _d2, _e2, _f, _g, _h, _i, _j, _k, _l;
|
|
1055
1079
|
const { entityType, entityId } = entry;
|
|
1056
1080
|
if (entry.operation === "deleteEntity") {
|
|
1057
1081
|
deleteEntityFromStores(state, entityType, entityId);
|
|
@@ -1095,7 +1119,7 @@ var initCoreActions = (monoriseStore, appActions, coreService2) => {
|
|
|
1095
1119
|
state.mutual[bySide] = { dataMap: /* @__PURE__ */ new Map() };
|
|
1096
1120
|
}
|
|
1097
1121
|
state.mutual[bySide].dataMap = new Map(
|
|
1098
|
-
(
|
|
1122
|
+
(_e2 = state.mutual[bySide]) == null ? void 0 : _e2.dataMap
|
|
1099
1123
|
).set(entityId, mutual);
|
|
1100
1124
|
if (!state.mutual[side]) {
|
|
1101
1125
|
state.mutual[side] = { dataMap: /* @__PURE__ */ new Map() };
|
|
@@ -1159,7 +1183,7 @@ var initCoreActions = (monoriseStore, appActions, coreService2) => {
|
|
|
1159
1183
|
} catch (err) {
|
|
1160
1184
|
if (!settled) {
|
|
1161
1185
|
const callAppError = getError2(callRequestKey);
|
|
1162
|
-
for (const requestKey of
|
|
1186
|
+
for (const requestKey of stateRequestKeys) {
|
|
1163
1187
|
endLoading2({ requestKey, isInterruptive, skipDedupe: true });
|
|
1164
1188
|
if (callAppError) {
|
|
1165
1189
|
setError2({ requestKey, error: callAppError });
|
|
@@ -1609,6 +1633,192 @@ var initCoreActions = (monoriseStore, appActions, coreService2) => {
|
|
|
1609
1633
|
`mr/mutual/local-delete-by-entity/${entityType}/${id}`
|
|
1610
1634
|
);
|
|
1611
1635
|
};
|
|
1636
|
+
const mergeMutationOptions = (hookOptions, mutateOptions) => __spreadValues(__spreadValues(__spreadValues({}, hookOptions), mutateOptions), (hookOptions.feedback || mutateOptions.feedback) && {
|
|
1637
|
+
feedback: __spreadValues(__spreadValues({}, hookOptions.feedback), mutateOptions.feedback)
|
|
1638
|
+
});
|
|
1639
|
+
const useLatestRef = (value) => {
|
|
1640
|
+
const ref = useRef(value);
|
|
1641
|
+
ref.current = value;
|
|
1642
|
+
return ref;
|
|
1643
|
+
};
|
|
1644
|
+
const useMutationState = (requestKey) => {
|
|
1645
|
+
const isLoading = useLoadStore2(requestKey);
|
|
1646
|
+
const error = monoriseStore(
|
|
1647
|
+
(state) => state.app.errorStack.get(requestKey)
|
|
1648
|
+
);
|
|
1649
|
+
const clearMutationError = useCallback(
|
|
1650
|
+
() => clearError2(requestKey),
|
|
1651
|
+
[requestKey]
|
|
1652
|
+
);
|
|
1653
|
+
return {
|
|
1654
|
+
isLoading,
|
|
1655
|
+
error,
|
|
1656
|
+
requestKey,
|
|
1657
|
+
clearError: clearMutationError
|
|
1658
|
+
};
|
|
1659
|
+
};
|
|
1660
|
+
const useCreateEntity2 = (entityType, opts = {}) => {
|
|
1661
|
+
const optsRef = useLatestRef(opts);
|
|
1662
|
+
const mutation = useMutationState(
|
|
1663
|
+
getEntityRequestKey("create", entityType)
|
|
1664
|
+
);
|
|
1665
|
+
const mutate = useCallback(
|
|
1666
|
+
(entity, mutateOpts = {}) => createEntity2(
|
|
1667
|
+
entityType,
|
|
1668
|
+
entity,
|
|
1669
|
+
mergeMutationOptions(optsRef.current, mutateOpts)
|
|
1670
|
+
),
|
|
1671
|
+
[entityType, optsRef]
|
|
1672
|
+
);
|
|
1673
|
+
return __spreadValues({ mutate }, mutation);
|
|
1674
|
+
};
|
|
1675
|
+
const useUpsertEntity2 = (entityType, id, opts = {}) => {
|
|
1676
|
+
const optsRef = useLatestRef(opts);
|
|
1677
|
+
const mutation = useMutationState(
|
|
1678
|
+
getEntityRequestKey("upsert", entityType, id)
|
|
1679
|
+
);
|
|
1680
|
+
const mutate = useCallback(
|
|
1681
|
+
(entity, mutateOpts = {}) => upsertEntity2(
|
|
1682
|
+
entityType,
|
|
1683
|
+
id,
|
|
1684
|
+
entity,
|
|
1685
|
+
mergeMutationOptions(optsRef.current, mutateOpts)
|
|
1686
|
+
),
|
|
1687
|
+
[entityType, id, optsRef]
|
|
1688
|
+
);
|
|
1689
|
+
return __spreadValues({ mutate }, mutation);
|
|
1690
|
+
};
|
|
1691
|
+
const useEditEntity2 = (entityType, id, opts = {}) => {
|
|
1692
|
+
const optsRef = useLatestRef(opts);
|
|
1693
|
+
const mutation = useMutationState(
|
|
1694
|
+
getEntityRequestKey("edit", entityType, id)
|
|
1695
|
+
);
|
|
1696
|
+
const mutate = useCallback(
|
|
1697
|
+
(entity, mutateOpts = {}) => editEntity2(
|
|
1698
|
+
entityType,
|
|
1699
|
+
id,
|
|
1700
|
+
entity,
|
|
1701
|
+
mergeMutationOptions(optsRef.current, mutateOpts)
|
|
1702
|
+
),
|
|
1703
|
+
[entityType, id, optsRef]
|
|
1704
|
+
);
|
|
1705
|
+
return __spreadValues({ mutate }, mutation);
|
|
1706
|
+
};
|
|
1707
|
+
const useAdjustEntity2 = (entityType, id, opts = {}) => {
|
|
1708
|
+
const optsRef = useLatestRef(opts);
|
|
1709
|
+
const mutation = useMutationState(
|
|
1710
|
+
getEntityRequestKey("adjust", entityType, id)
|
|
1711
|
+
);
|
|
1712
|
+
const mutate = useCallback(
|
|
1713
|
+
(adjustments, mutateOpts = {}) => adjustEntity2(
|
|
1714
|
+
entityType,
|
|
1715
|
+
id,
|
|
1716
|
+
adjustments,
|
|
1717
|
+
mergeMutationOptions(optsRef.current, mutateOpts)
|
|
1718
|
+
),
|
|
1719
|
+
[entityType, id, optsRef]
|
|
1720
|
+
);
|
|
1721
|
+
return __spreadValues({ mutate }, mutation);
|
|
1722
|
+
};
|
|
1723
|
+
const useDeleteEntity2 = (entityType, id, opts = {}) => {
|
|
1724
|
+
const optsRef = useLatestRef(opts);
|
|
1725
|
+
const mutation = useMutationState(
|
|
1726
|
+
getEntityRequestKey("delete", entityType, id)
|
|
1727
|
+
);
|
|
1728
|
+
const mutate = useCallback(
|
|
1729
|
+
(mutateOpts = {}) => deleteEntity2(
|
|
1730
|
+
entityType,
|
|
1731
|
+
id,
|
|
1732
|
+
mergeMutationOptions(optsRef.current, mutateOpts)
|
|
1733
|
+
),
|
|
1734
|
+
[entityType, id, optsRef]
|
|
1735
|
+
);
|
|
1736
|
+
return __spreadValues({ mutate }, mutation);
|
|
1737
|
+
};
|
|
1738
|
+
const useCreateMutual2 = (byEntityType, entityType, byEntityId2, entityId, opts = {}) => {
|
|
1739
|
+
const optsRef = useLatestRef(opts);
|
|
1740
|
+
const mutation = useMutationState(
|
|
1741
|
+
getMutualRequestKey(
|
|
1742
|
+
"create",
|
|
1743
|
+
byEntityType,
|
|
1744
|
+
entityType,
|
|
1745
|
+
byEntityId2,
|
|
1746
|
+
entityId
|
|
1747
|
+
)
|
|
1748
|
+
);
|
|
1749
|
+
const mutate = useCallback(
|
|
1750
|
+
(payload = {}, mutateOpts = {}) => createMutual2(
|
|
1751
|
+
byEntityType,
|
|
1752
|
+
entityType,
|
|
1753
|
+
byEntityId2,
|
|
1754
|
+
entityId,
|
|
1755
|
+
payload,
|
|
1756
|
+
mergeMutationOptions(optsRef.current, mutateOpts)
|
|
1757
|
+
),
|
|
1758
|
+
[byEntityType, entityType, byEntityId2, entityId, optsRef]
|
|
1759
|
+
);
|
|
1760
|
+
return __spreadValues({ mutate }, mutation);
|
|
1761
|
+
};
|
|
1762
|
+
const useEditMutual2 = (byEntityType, entityType, byEntityId2, entityId, opts = {}) => {
|
|
1763
|
+
const optsRef = useLatestRef(opts);
|
|
1764
|
+
const mutation = useMutationState(
|
|
1765
|
+
getMutualRequestKey(
|
|
1766
|
+
"update",
|
|
1767
|
+
byEntityType,
|
|
1768
|
+
entityType,
|
|
1769
|
+
byEntityId2,
|
|
1770
|
+
entityId
|
|
1771
|
+
)
|
|
1772
|
+
);
|
|
1773
|
+
const mutate = useCallback(
|
|
1774
|
+
(payload = {}, mutateOpts = {}) => editMutual2(
|
|
1775
|
+
byEntityType,
|
|
1776
|
+
entityType,
|
|
1777
|
+
byEntityId2,
|
|
1778
|
+
entityId,
|
|
1779
|
+
payload,
|
|
1780
|
+
mergeMutationOptions(optsRef.current, mutateOpts)
|
|
1781
|
+
),
|
|
1782
|
+
[byEntityType, entityType, byEntityId2, entityId, optsRef]
|
|
1783
|
+
);
|
|
1784
|
+
return __spreadValues({ mutate }, mutation);
|
|
1785
|
+
};
|
|
1786
|
+
const useDeleteMutual2 = (byEntityType, entityType, byEntityId2, entityId, opts = {}) => {
|
|
1787
|
+
const optsRef = useLatestRef(opts);
|
|
1788
|
+
const mutation = useMutationState(
|
|
1789
|
+
getMutualRequestKey(
|
|
1790
|
+
"delete",
|
|
1791
|
+
byEntityType,
|
|
1792
|
+
entityType,
|
|
1793
|
+
byEntityId2,
|
|
1794
|
+
entityId
|
|
1795
|
+
)
|
|
1796
|
+
);
|
|
1797
|
+
const mutate = useCallback(
|
|
1798
|
+
(mutateOpts = {}) => deleteMutual2(
|
|
1799
|
+
byEntityType,
|
|
1800
|
+
entityType,
|
|
1801
|
+
byEntityId2,
|
|
1802
|
+
entityId,
|
|
1803
|
+
mergeMutationOptions(optsRef.current, mutateOpts)
|
|
1804
|
+
),
|
|
1805
|
+
[byEntityType, entityType, byEntityId2, entityId, optsRef]
|
|
1806
|
+
);
|
|
1807
|
+
return __spreadValues({ mutate }, mutation);
|
|
1808
|
+
};
|
|
1809
|
+
const useExecuteTransaction2 = (operations, opts = {}) => {
|
|
1810
|
+
const operationsRef = useLatestRef(operations);
|
|
1811
|
+
const optsRef = useLatestRef(opts);
|
|
1812
|
+
const mutation = useMutationState(getTransactionRequestKey(operations));
|
|
1813
|
+
const mutate = useCallback(
|
|
1814
|
+
(mutateOpts = {}) => executeTransaction2(
|
|
1815
|
+
operationsRef.current,
|
|
1816
|
+
mergeMutationOptions(optsRef.current, mutateOpts)
|
|
1817
|
+
),
|
|
1818
|
+
[operationsRef, optsRef]
|
|
1819
|
+
);
|
|
1820
|
+
return __spreadValues({ mutate }, mutation);
|
|
1821
|
+
};
|
|
1612
1822
|
const useEntity2 = (entityType, id, opts = {}) => {
|
|
1613
1823
|
const dataMap = monoriseStore(
|
|
1614
1824
|
(state) => {
|
|
@@ -2050,6 +2260,15 @@ var initCoreActions = (monoriseStore, appActions, coreService2) => {
|
|
|
2050
2260
|
editMutual: editMutual2,
|
|
2051
2261
|
deleteMutual: deleteMutual2,
|
|
2052
2262
|
deleteLocalMutual: deleteLocalMutual2,
|
|
2263
|
+
useCreateEntity: useCreateEntity2,
|
|
2264
|
+
useUpsertEntity: useUpsertEntity2,
|
|
2265
|
+
useEditEntity: useEditEntity2,
|
|
2266
|
+
useAdjustEntity: useAdjustEntity2,
|
|
2267
|
+
useDeleteEntity: useDeleteEntity2,
|
|
2268
|
+
useExecuteTransaction: useExecuteTransaction2,
|
|
2269
|
+
useCreateMutual: useCreateMutual2,
|
|
2270
|
+
useEditMutual: useEditMutual2,
|
|
2271
|
+
useDeleteMutual: useDeleteMutual2,
|
|
2053
2272
|
useEntity: useEntity2,
|
|
2054
2273
|
useEntityByUniqueField: useEntityByUniqueField2,
|
|
2055
2274
|
useEntities: useEntities2,
|
|
@@ -2063,7 +2282,7 @@ var initCoreActions = (monoriseStore, appActions, coreService2) => {
|
|
|
2063
2282
|
};
|
|
2064
2283
|
|
|
2065
2284
|
// actions/websocket.action.ts
|
|
2066
|
-
import { useCallback, useEffect as useEffect3, useRef, useState as useState3 } from "react";
|
|
2285
|
+
import { useCallback as useCallback2, useEffect as useEffect3, useRef as useRef2, useState as useState3 } from "react";
|
|
2067
2286
|
import { produce as produce5 } from "immer";
|
|
2068
2287
|
var globalWsManager = null;
|
|
2069
2288
|
var wsEndpoint;
|
|
@@ -2084,8 +2303,8 @@ var initWebSocketActions = (monoriseStore, httpActions) => {
|
|
|
2084
2303
|
const [isSubscribed, setIsSubscribed] = useState3(false);
|
|
2085
2304
|
const [error, setError2] = useState3(null);
|
|
2086
2305
|
const [hasMore, setHasMore] = useState3(true);
|
|
2087
|
-
const lastKeyRef =
|
|
2088
|
-
const isFirstFetchRef =
|
|
2306
|
+
const lastKeyRef = useRef2(void 0);
|
|
2307
|
+
const isFirstFetchRef = useRef2(true);
|
|
2089
2308
|
const entities = monoriseStore((state) => {
|
|
2090
2309
|
var _a;
|
|
2091
2310
|
const entityState = state.entity[entityType];
|
|
@@ -2214,8 +2433,8 @@ var initWebSocketActions = (monoriseStore, httpActions) => {
|
|
|
2214
2433
|
const [isSubscribed, setIsSubscribed] = useState3(false);
|
|
2215
2434
|
const [error, setError2] = useState3(null);
|
|
2216
2435
|
const [hasMore, setHasMore] = useState3(true);
|
|
2217
|
-
const lastKeyRef =
|
|
2218
|
-
const isFirstFetchRef =
|
|
2436
|
+
const lastKeyRef = useRef2(void 0);
|
|
2437
|
+
const isFirstFetchRef = useRef2(true);
|
|
2219
2438
|
const mutualKey = byEntityId2 ? `${byEntityType}/${byEntityId2}/${mutualEntityType}` : "";
|
|
2220
2439
|
const mutuals = monoriseStore((state) => {
|
|
2221
2440
|
var _a, _b;
|
|
@@ -2380,7 +2599,7 @@ var initWebSocketActions = (monoriseStore, httpActions) => {
|
|
|
2380
2599
|
setIsSubscribed(false);
|
|
2381
2600
|
};
|
|
2382
2601
|
}, [channel]);
|
|
2383
|
-
const send =
|
|
2602
|
+
const send = useCallback2(
|
|
2384
2603
|
(data) => {
|
|
2385
2604
|
if (!globalWsManager || !channel) return;
|
|
2386
2605
|
globalWsManager.sendEphemeral(channel, data);
|
|
@@ -2393,8 +2612,8 @@ var initWebSocketActions = (monoriseStore, httpActions) => {
|
|
|
2393
2612
|
const { entityType, entityId, ticketEndpoint } = opts;
|
|
2394
2613
|
const [isConnected, setIsConnected] = useState3(false);
|
|
2395
2614
|
const [error, setError2] = useState3(null);
|
|
2396
|
-
const refreshTimerRef =
|
|
2397
|
-
const hasConnectedOnceRef =
|
|
2615
|
+
const refreshTimerRef = useRef2(null);
|
|
2616
|
+
const hasConnectedOnceRef = useRef2(false);
|
|
2398
2617
|
const resyncFromHttp = async () => {
|
|
2399
2618
|
var _a, _b;
|
|
2400
2619
|
if (!httpActions) return;
|
|
@@ -2427,14 +2646,14 @@ var initWebSocketActions = (monoriseStore, httpActions) => {
|
|
|
2427
2646
|
}
|
|
2428
2647
|
}
|
|
2429
2648
|
};
|
|
2430
|
-
const wsManagerRef =
|
|
2431
|
-
const isMountedRef =
|
|
2432
|
-
const connectingRef =
|
|
2433
|
-
const reconnectCountRef =
|
|
2434
|
-
const connectRef =
|
|
2649
|
+
const wsManagerRef = useRef2(null);
|
|
2650
|
+
const isMountedRef = useRef2(true);
|
|
2651
|
+
const connectingRef = useRef2(false);
|
|
2652
|
+
const reconnectCountRef = useRef2(0);
|
|
2653
|
+
const connectRef = useRef2(() => {
|
|
2435
2654
|
});
|
|
2436
|
-
const lastConnectedAtRef =
|
|
2437
|
-
const fetchTicket =
|
|
2655
|
+
const lastConnectedAtRef = useRef2(0);
|
|
2656
|
+
const fetchTicket = useCallback2(async () => {
|
|
2438
2657
|
try {
|
|
2439
2658
|
const url = ticketEndpoint || `/api/core/ws/ticket/${entityType}/${entityId}`;
|
|
2440
2659
|
const fetchOpts = {
|
|
@@ -2457,7 +2676,7 @@ var initWebSocketActions = (monoriseStore, httpActions) => {
|
|
|
2457
2676
|
return { error: { code: "TICKET_FAILED", message: err.message } };
|
|
2458
2677
|
}
|
|
2459
2678
|
}, [entityType, entityId, ticketEndpoint]);
|
|
2460
|
-
const connectWithTicket =
|
|
2679
|
+
const connectWithTicket = useCallback2(async () => {
|
|
2461
2680
|
if (connectingRef.current) return;
|
|
2462
2681
|
connectingRef.current = true;
|
|
2463
2682
|
let result = null;
|
|
@@ -2637,7 +2856,12 @@ var initAxiosInterceptor = (store2, appActions) => {
|
|
|
2637
2856
|
const { startLoading: startLoading2 } = appActions;
|
|
2638
2857
|
const axiosInstance = request.create();
|
|
2639
2858
|
function makeRequest(url, config, data) {
|
|
2640
|
-
const {
|
|
2859
|
+
const {
|
|
2860
|
+
requestKey,
|
|
2861
|
+
stateKeys = [],
|
|
2862
|
+
isInterruptive = false,
|
|
2863
|
+
feedback
|
|
2864
|
+
} = config;
|
|
2641
2865
|
const { ongoingRequests } = store2.getState().app;
|
|
2642
2866
|
if (ongoingRequests.has(requestKey)) {
|
|
2643
2867
|
return ongoingRequests.get(requestKey);
|
|
@@ -2655,6 +2879,15 @@ var initAxiosInterceptor = (store2, appActions) => {
|
|
|
2655
2879
|
message: feedback == null ? void 0 : feedback.loading,
|
|
2656
2880
|
request: promise
|
|
2657
2881
|
});
|
|
2882
|
+
for (const stateKey of new Set(stateKeys)) {
|
|
2883
|
+
if (stateKey !== requestKey) {
|
|
2884
|
+
startLoading2({
|
|
2885
|
+
requestKey: stateKey,
|
|
2886
|
+
isInterruptive,
|
|
2887
|
+
message: feedback == null ? void 0 : feedback.loading
|
|
2888
|
+
});
|
|
2889
|
+
}
|
|
2890
|
+
}
|
|
2658
2891
|
return promise;
|
|
2659
2892
|
}
|
|
2660
2893
|
const axios2 = __spreadProps(__spreadValues({}, axiosInstance), {
|
|
@@ -2675,12 +2908,31 @@ var injectAxiosInterceptor = (appActions, authActions, axios2, opts) => {
|
|
|
2675
2908
|
code: "UNKNOWN_EXCEPTION",
|
|
2676
2909
|
message: "Ops, something doesn't seems right"
|
|
2677
2910
|
};
|
|
2911
|
+
const settleLoading = (config) => {
|
|
2912
|
+
const { requestKey, stateKeys = [], isInterruptive } = config;
|
|
2913
|
+
endLoading2({ requestKey, isInterruptive });
|
|
2914
|
+
for (const stateKey of new Set(stateKeys)) {
|
|
2915
|
+
if (stateKey !== requestKey) {
|
|
2916
|
+
endLoading2({
|
|
2917
|
+
requestKey: stateKey,
|
|
2918
|
+
isInterruptive,
|
|
2919
|
+
skipDedupe: true
|
|
2920
|
+
});
|
|
2921
|
+
}
|
|
2922
|
+
}
|
|
2923
|
+
};
|
|
2924
|
+
const getErrorKeys = (config) => {
|
|
2925
|
+
const { requestKey, stateKeys = [] } = config;
|
|
2926
|
+
return stateKeys.length > 0 ? new Set(stateKeys) : /* @__PURE__ */ new Set([requestKey]);
|
|
2927
|
+
};
|
|
2678
2928
|
axios2.interceptors.response.use(
|
|
2679
2929
|
(response) => {
|
|
2680
2930
|
var _a;
|
|
2681
|
-
const {
|
|
2682
|
-
|
|
2683
|
-
|
|
2931
|
+
const { feedback } = response.config;
|
|
2932
|
+
settleLoading(response.config);
|
|
2933
|
+
for (const errorKey of getErrorKeys(response.config)) {
|
|
2934
|
+
clearError2(errorKey);
|
|
2935
|
+
}
|
|
2684
2936
|
if (feedback == null ? void 0 : feedback.success) {
|
|
2685
2937
|
(_a = options.onApiSuccess) == null ? void 0 : _a.call(options, response, feedback.success);
|
|
2686
2938
|
}
|
|
@@ -2688,14 +2940,16 @@ var injectAxiosInterceptor = (appActions, authActions, axios2, opts) => {
|
|
|
2688
2940
|
},
|
|
2689
2941
|
(error) => {
|
|
2690
2942
|
var _a, _b, _c, _d, _e;
|
|
2691
|
-
const
|
|
2692
|
-
|
|
2943
|
+
const config = error.config;
|
|
2944
|
+
settleLoading(config);
|
|
2693
2945
|
const appError = ((_a = error.response) == null ? void 0 : _a.data) ? {
|
|
2694
2946
|
code: (_b = error.response) == null ? void 0 : _b.statusText,
|
|
2695
2947
|
status: (_c = error.response) == null ? void 0 : _c.status,
|
|
2696
2948
|
message: (_d = error.response) == null ? void 0 : _d.data
|
|
2697
2949
|
} : unknownError;
|
|
2698
|
-
|
|
2950
|
+
for (const errorKey of getErrorKeys(config)) {
|
|
2951
|
+
setError2({ requestKey: errorKey, error: appError });
|
|
2952
|
+
}
|
|
2699
2953
|
if (((_e = error.response) == null ? void 0 : _e.status) === 401) {
|
|
2700
2954
|
setIsUnauthorized2(true);
|
|
2701
2955
|
}
|
|
@@ -2752,6 +3006,22 @@ var TAG_API_BASE_URL = "/api/core/tag";
|
|
|
2752
3006
|
var TRANSACTION_API_BASE_URL = "/api/core/transaction";
|
|
2753
3007
|
var initCoreService = (monoriseStore, axios2, opts) => {
|
|
2754
3008
|
let options = opts || {};
|
|
3009
|
+
const getMutationRequestConfig = (stateKey, opts2, compatibilityStateKeys = []) => {
|
|
3010
|
+
var _a;
|
|
3011
|
+
return {
|
|
3012
|
+
requestKey: (_a = opts2.requestKey) != null ? _a : createMutationCallRequestKey(stateKey),
|
|
3013
|
+
// Keep the stable mutation key reactive while requestKey remains unique
|
|
3014
|
+
// per write. An explicit key and any legacy observation keys remain
|
|
3015
|
+
// observable for backwards compatibility with useLoadStore/useErrorStore.
|
|
3016
|
+
stateKeys: Array.from(
|
|
3017
|
+
/* @__PURE__ */ new Set([
|
|
3018
|
+
stateKey,
|
|
3019
|
+
...compatibilityStateKeys,
|
|
3020
|
+
...opts2.requestKey ? [opts2.requestKey] : []
|
|
3021
|
+
])
|
|
3022
|
+
)
|
|
3023
|
+
};
|
|
3024
|
+
};
|
|
2755
3025
|
const listEntities = (entityType, payload, opts2 = {}) => {
|
|
2756
3026
|
const { entityApiBaseUrl = ENTITY_API_BASE_URL } = options;
|
|
2757
3027
|
return axios2.get(opts2.customUrl || `${entityApiBaseUrl}/${entityType}`, {
|
|
@@ -2815,89 +3085,89 @@ var initCoreService = (monoriseStore, axios2, opts) => {
|
|
|
2815
3085
|
var _a;
|
|
2816
3086
|
const { entityApiBaseUrl = ENTITY_API_BASE_URL } = options;
|
|
2817
3087
|
const entityConfig = monoriseStore.getState().config;
|
|
3088
|
+
const stateKey = getEntityRequestKey("create", entityType);
|
|
2818
3089
|
return axios2.post(
|
|
2819
3090
|
opts2.customUrl || `${entityApiBaseUrl}/${entityType}`,
|
|
2820
3091
|
__spreadValues(__spreadValues({}, values), opts2.entityId && { entityId: opts2.entityId }),
|
|
2821
|
-
{
|
|
2822
|
-
requestKey: opts2.requestKey || getEntityRequestKey("create", entityType),
|
|
3092
|
+
__spreadProps(__spreadValues({}, getMutationRequestConfig(stateKey, opts2)), {
|
|
2823
3093
|
isInterruptive: (_a = opts2.isInterruptive) != null ? _a : true,
|
|
2824
3094
|
feedback: __spreadValues({
|
|
2825
3095
|
loading: `Creating ${entityConfig[entityType].displayName}`,
|
|
2826
3096
|
success: `${entityConfig[entityType].displayName} created`
|
|
2827
3097
|
}, opts2.feedback || {})
|
|
2828
|
-
}
|
|
3098
|
+
})
|
|
2829
3099
|
);
|
|
2830
3100
|
};
|
|
2831
3101
|
const upsertEntity2 = (entityType, id, values, opts2 = {}) => {
|
|
2832
3102
|
var _a;
|
|
2833
3103
|
const { entityApiBaseUrl = ENTITY_API_BASE_URL } = options;
|
|
2834
3104
|
const entityConfig = monoriseStore.getState().config;
|
|
3105
|
+
const stateKey = getEntityRequestKey("upsert", entityType, id);
|
|
2835
3106
|
return axios2.put(
|
|
2836
3107
|
opts2.customUrl || `${entityApiBaseUrl}/${entityType}/${id}`,
|
|
2837
3108
|
values,
|
|
2838
|
-
{
|
|
2839
|
-
requestKey: getEntityRequestKey("upsert", entityType, id),
|
|
3109
|
+
__spreadProps(__spreadValues({}, getMutationRequestConfig(stateKey, opts2)), {
|
|
2840
3110
|
isInterruptive: (_a = opts2.isInterruptive) != null ? _a : true,
|
|
2841
3111
|
feedback: __spreadValues({
|
|
2842
3112
|
loading: `Updating ${entityConfig[entityType].displayName}`,
|
|
2843
3113
|
success: `${entityConfig[entityType].displayName} updated`
|
|
2844
3114
|
}, opts2.feedback || {})
|
|
2845
|
-
}
|
|
3115
|
+
})
|
|
2846
3116
|
);
|
|
2847
3117
|
};
|
|
2848
3118
|
const editEntity2 = (entityType, id, values, opts2 = {}) => {
|
|
2849
3119
|
var _a;
|
|
2850
3120
|
const { entityApiBaseUrl = ENTITY_API_BASE_URL } = options;
|
|
2851
3121
|
const entityConfig = monoriseStore.getState().config;
|
|
3122
|
+
const stateKey = getEntityRequestKey("edit", entityType, id);
|
|
2852
3123
|
return axios2.patch(
|
|
2853
3124
|
opts2.customUrl || `${entityApiBaseUrl}/${entityType}/${id}`,
|
|
2854
3125
|
values,
|
|
2855
|
-
{
|
|
2856
|
-
requestKey: getEntityRequestKey("edit", entityType, id),
|
|
3126
|
+
__spreadProps(__spreadValues({}, getMutationRequestConfig(stateKey, opts2)), {
|
|
2857
3127
|
isInterruptive: (_a = opts2.isInterruptive) != null ? _a : true,
|
|
2858
3128
|
feedback: __spreadValues({
|
|
2859
3129
|
loading: `Updating ${entityConfig[entityType].displayName}`,
|
|
2860
3130
|
success: `${entityConfig[entityType].displayName} updated`
|
|
2861
3131
|
}, opts2.feedback || {})
|
|
2862
|
-
}
|
|
3132
|
+
})
|
|
2863
3133
|
);
|
|
2864
3134
|
};
|
|
2865
3135
|
const adjustEntity2 = (entityType, id, adjustments, opts2 = {}) => {
|
|
2866
3136
|
var _a;
|
|
2867
3137
|
const { entityApiBaseUrl = ENTITY_API_BASE_URL } = options;
|
|
2868
3138
|
const entityConfig = monoriseStore.getState().config;
|
|
3139
|
+
const stateKey = getEntityRequestKey("adjust", entityType, id);
|
|
2869
3140
|
const body = opts2.condition ? __spreadProps(__spreadValues({}, adjustments), { $condition: opts2.condition }) : adjustments;
|
|
2870
3141
|
return axios2.post(
|
|
2871
3142
|
opts2.customUrl || `${entityApiBaseUrl}/${entityType}/${id}/adjust`,
|
|
2872
3143
|
body,
|
|
2873
|
-
{
|
|
2874
|
-
requestKey: getEntityRequestKey("adjust", entityType, id),
|
|
3144
|
+
__spreadProps(__spreadValues({}, getMutationRequestConfig(stateKey, opts2)), {
|
|
2875
3145
|
isInterruptive: (_a = opts2.isInterruptive) != null ? _a : true,
|
|
2876
3146
|
feedback: __spreadValues({
|
|
2877
3147
|
loading: `Updating ${entityConfig[entityType].displayName}`,
|
|
2878
3148
|
success: `${entityConfig[entityType].displayName} updated`
|
|
2879
3149
|
}, opts2.feedback || {})
|
|
2880
|
-
}
|
|
3150
|
+
})
|
|
2881
3151
|
);
|
|
2882
3152
|
};
|
|
2883
3153
|
const deleteEntity2 = (entityType, id, opts2 = {}) => {
|
|
2884
3154
|
var _a;
|
|
2885
3155
|
const { entityApiBaseUrl = ENTITY_API_BASE_URL } = options;
|
|
2886
3156
|
const entityConfig = monoriseStore.getState().config;
|
|
3157
|
+
const stateKey = getEntityRequestKey("delete", entityType, id);
|
|
2887
3158
|
return axios2.delete(
|
|
2888
3159
|
opts2.customUrl || `${entityApiBaseUrl}/${entityType}/${id}`,
|
|
2889
|
-
{
|
|
2890
|
-
requestKey: getEntityRequestKey("delete", entityType, id),
|
|
3160
|
+
__spreadProps(__spreadValues({}, getMutationRequestConfig(stateKey, opts2)), {
|
|
2891
3161
|
isInterruptive: (_a = opts2.isInterruptive) != null ? _a : true,
|
|
2892
3162
|
feedback: __spreadValues({
|
|
2893
3163
|
loading: `Deleting ${entityConfig[entityType].displayName}`,
|
|
2894
3164
|
success: `${entityConfig[entityType].displayName} deleted`
|
|
2895
3165
|
}, opts2.feedback || {})
|
|
2896
|
-
}
|
|
3166
|
+
})
|
|
2897
3167
|
);
|
|
2898
3168
|
};
|
|
2899
3169
|
const executeTransaction2 = (operations, opts2 = {}) => {
|
|
2900
|
-
var _a;
|
|
3170
|
+
var _a, _b;
|
|
2901
3171
|
const { transactionApiBaseUrl = TRANSACTION_API_BASE_URL } = options;
|
|
2902
3172
|
return axios2.post(
|
|
2903
3173
|
opts2.customUrl || transactionApiBaseUrl,
|
|
@@ -2912,8 +3182,8 @@ var initCoreService = (monoriseStore, axios2, opts) => {
|
|
|
2912
3182
|
// namespaced so it can never match a single-entity key and unique per
|
|
2913
3183
|
// call so non-idempotent transaction writes cannot be silently
|
|
2914
3184
|
// deduplicated. Callers can pass opts.requestKey to opt into dedupe.
|
|
2915
|
-
requestKey: opts2.requestKey
|
|
2916
|
-
isInterruptive: (
|
|
3185
|
+
requestKey: (_a = opts2.requestKey) != null ? _a : createTransactionCallRequestKey(operations),
|
|
3186
|
+
isInterruptive: (_b = opts2.isInterruptive) != null ? _b : true,
|
|
2917
3187
|
feedback: __spreadValues({
|
|
2918
3188
|
loading: "Processing transaction",
|
|
2919
3189
|
success: "Transaction completed"
|
|
@@ -2964,65 +3234,72 @@ var initCoreService = (monoriseStore, axios2, opts) => {
|
|
|
2964
3234
|
const createMutual2 = (byEntityType, entityType, byEntityId2, entityId, payload, opts2 = {}) => {
|
|
2965
3235
|
var _a;
|
|
2966
3236
|
const { mutualApiBaseUrl = MUTUAL_API_BASE_URL } = options;
|
|
3237
|
+
const stateKey = getMutualRequestKey(
|
|
3238
|
+
"create",
|
|
3239
|
+
byEntityType,
|
|
3240
|
+
entityType,
|
|
3241
|
+
byEntityId2,
|
|
3242
|
+
entityId
|
|
3243
|
+
);
|
|
3244
|
+
const legacyStateKey = getMutualRequestKey(
|
|
3245
|
+
"create",
|
|
3246
|
+
byEntityType,
|
|
3247
|
+
entityType,
|
|
3248
|
+
byEntityId2
|
|
3249
|
+
);
|
|
2967
3250
|
return axios2.post(
|
|
2968
3251
|
opts2.customUrl || `${mutualApiBaseUrl}/${getMutualStateKey(byEntityType, byEntityId2, entityType, entityId)}`,
|
|
2969
3252
|
payload,
|
|
2970
|
-
{
|
|
2971
|
-
requestKey: getMutualRequestKey(
|
|
2972
|
-
"create",
|
|
2973
|
-
byEntityType,
|
|
2974
|
-
entityType,
|
|
2975
|
-
byEntityId2
|
|
2976
|
-
),
|
|
3253
|
+
__spreadProps(__spreadValues({}, getMutationRequestConfig(stateKey, opts2, [legacyStateKey])), {
|
|
2977
3254
|
isInterruptive: (_a = opts2.isInterruptive) != null ? _a : true,
|
|
2978
3255
|
feedback: __spreadValues({
|
|
2979
3256
|
loading: "Creating linkage",
|
|
2980
3257
|
success: "Linkage created"
|
|
2981
3258
|
}, opts2.feedback || {})
|
|
2982
|
-
}
|
|
3259
|
+
})
|
|
2983
3260
|
);
|
|
2984
3261
|
};
|
|
2985
3262
|
const editMutual2 = (byEntityType, entityType, byEntityId2, entityId, payload, opts2 = {}) => {
|
|
2986
3263
|
var _a;
|
|
2987
3264
|
const { mutualApiBaseUrl = MUTUAL_API_BASE_URL } = options;
|
|
3265
|
+
const stateKey = getMutualRequestKey(
|
|
3266
|
+
"update",
|
|
3267
|
+
byEntityType,
|
|
3268
|
+
entityType,
|
|
3269
|
+
byEntityId2,
|
|
3270
|
+
entityId
|
|
3271
|
+
);
|
|
2988
3272
|
return axios2.patch(
|
|
2989
3273
|
opts2.customUrl || `${mutualApiBaseUrl}/${getMutualStateKey(byEntityType, byEntityId2, entityType, entityId)}`,
|
|
2990
3274
|
payload,
|
|
2991
|
-
{
|
|
2992
|
-
requestKey: getMutualRequestKey(
|
|
2993
|
-
"update",
|
|
2994
|
-
byEntityType,
|
|
2995
|
-
entityType,
|
|
2996
|
-
byEntityId2,
|
|
2997
|
-
entityId
|
|
2998
|
-
),
|
|
3275
|
+
__spreadProps(__spreadValues({}, getMutationRequestConfig(stateKey, opts2)), {
|
|
2999
3276
|
isInterruptive: (_a = opts2.isInterruptive) != null ? _a : true,
|
|
3000
3277
|
feedback: __spreadValues({
|
|
3001
3278
|
loading: "Updating linkage",
|
|
3002
3279
|
success: "Linkage updated"
|
|
3003
3280
|
}, opts2.feedback || {})
|
|
3004
|
-
}
|
|
3281
|
+
})
|
|
3005
3282
|
);
|
|
3006
3283
|
};
|
|
3007
3284
|
const deleteMutual2 = (byEntityType, entityType, byEntityId2, entityId, opts2 = {}) => {
|
|
3008
3285
|
var _a;
|
|
3009
3286
|
const { mutualApiBaseUrl = MUTUAL_API_BASE_URL } = options;
|
|
3287
|
+
const stateKey = getMutualRequestKey(
|
|
3288
|
+
"delete",
|
|
3289
|
+
byEntityType,
|
|
3290
|
+
entityType,
|
|
3291
|
+
byEntityId2,
|
|
3292
|
+
entityId
|
|
3293
|
+
);
|
|
3010
3294
|
return axios2.delete(
|
|
3011
3295
|
opts2.customUrl || `${mutualApiBaseUrl}/${getMutualStateKey(byEntityType, byEntityId2, entityType, entityId)}`,
|
|
3012
|
-
{
|
|
3013
|
-
requestKey: getMutualRequestKey(
|
|
3014
|
-
"delete",
|
|
3015
|
-
byEntityType,
|
|
3016
|
-
entityType,
|
|
3017
|
-
byEntityId2,
|
|
3018
|
-
entityId
|
|
3019
|
-
),
|
|
3296
|
+
__spreadProps(__spreadValues({}, getMutationRequestConfig(stateKey, opts2)), {
|
|
3020
3297
|
isInterruptive: (_a = opts2.isInterruptive) != null ? _a : true,
|
|
3021
3298
|
feedback: __spreadValues({
|
|
3022
3299
|
loading: "Removing linkage",
|
|
3023
3300
|
success: "Linkage removed"
|
|
3024
3301
|
}, opts2.feedback || {})
|
|
3025
|
-
}
|
|
3302
|
+
})
|
|
3026
3303
|
);
|
|
3027
3304
|
};
|
|
3028
3305
|
const makeEntityService = (entityType) => ({
|
|
@@ -3396,6 +3673,15 @@ var {
|
|
|
3396
3673
|
editMutual,
|
|
3397
3674
|
deleteMutual,
|
|
3398
3675
|
deleteLocalMutual,
|
|
3676
|
+
useCreateEntity,
|
|
3677
|
+
useUpsertEntity,
|
|
3678
|
+
useEditEntity,
|
|
3679
|
+
useAdjustEntity,
|
|
3680
|
+
useDeleteEntity,
|
|
3681
|
+
useExecuteTransaction,
|
|
3682
|
+
useCreateMutual,
|
|
3683
|
+
useEditMutual,
|
|
3684
|
+
useDeleteMutual,
|
|
3399
3685
|
useEntity,
|
|
3400
3686
|
useEntityByUniqueField,
|
|
3401
3687
|
useEntities,
|
|
@@ -3458,7 +3744,14 @@ export {
|
|
|
3458
3744
|
updateLocalTaggedEntity,
|
|
3459
3745
|
upsertEntity,
|
|
3460
3746
|
upsertLocalMutual,
|
|
3747
|
+
useAdjustEntity,
|
|
3461
3748
|
useConfig,
|
|
3749
|
+
useCreateEntity,
|
|
3750
|
+
useCreateMutual,
|
|
3751
|
+
useDeleteEntity,
|
|
3752
|
+
useDeleteMutual,
|
|
3753
|
+
useEditEntity,
|
|
3754
|
+
useEditMutual,
|
|
3462
3755
|
useEntities,
|
|
3463
3756
|
useEntity,
|
|
3464
3757
|
useEntityByUniqueField,
|
|
@@ -3467,6 +3760,7 @@ export {
|
|
|
3467
3760
|
useEntityState,
|
|
3468
3761
|
useEphemeralSocket,
|
|
3469
3762
|
useErrorStore,
|
|
3763
|
+
useExecuteTransaction,
|
|
3470
3764
|
useInterruptiveLoadStore,
|
|
3471
3765
|
useIsUnauthorized,
|
|
3472
3766
|
useLoadStore,
|
|
@@ -3475,6 +3769,7 @@ export {
|
|
|
3475
3769
|
useMutualSocket,
|
|
3476
3770
|
useMutuals,
|
|
3477
3771
|
useProfile,
|
|
3478
|
-
useTaggedEntities
|
|
3772
|
+
useTaggedEntities,
|
|
3773
|
+
useUpsertEntity
|
|
3479
3774
|
};
|
|
3480
3775
|
//# sourceMappingURL=index.js.map
|