@monorise/react 8.3.2 → 8.4.1
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/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 +277 -2
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +456 -196
- 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 +5 -1
package/dist/index.js
CHANGED
|
@@ -277,47 +277,10 @@ var initConfigActions = (store2) => {
|
|
|
277
277
|
|
|
278
278
|
// actions/core.action.ts
|
|
279
279
|
import { produce as produce4 } from "immer";
|
|
280
|
-
import { useEffect as useEffect2, useState as useState2 } from "react";
|
|
281
|
-
|
|
282
|
-
// lib/entity.ts
|
|
283
|
-
var constructLocal = (entityType, entityId, data) => {
|
|
284
|
-
return {
|
|
285
|
-
entityType,
|
|
286
|
-
entityId,
|
|
287
|
-
data,
|
|
288
|
-
createdAt: (/* @__PURE__ */ new Date()).toISOString(),
|
|
289
|
-
updatedAt: (/* @__PURE__ */ new Date()).toISOString()
|
|
290
|
-
};
|
|
291
|
-
};
|
|
292
|
-
var constructMutual = (byEntityType, byEntityId2, entityType, entityId, mutualData, data) => {
|
|
293
|
-
return {
|
|
294
|
-
mutualId: `${byEntityId2}-${entityId}`,
|
|
295
|
-
byEntityType,
|
|
296
|
-
byEntityId: byEntityId2,
|
|
297
|
-
entityType,
|
|
298
|
-
entityId,
|
|
299
|
-
mutualData,
|
|
300
|
-
data,
|
|
301
|
-
createdAt: (/* @__PURE__ */ new Date()).toISOString(),
|
|
302
|
-
updatedAt: (/* @__PURE__ */ new Date()).toISOString(),
|
|
303
|
-
mutualUpdatedAt: (/* @__PURE__ */ new Date()).toISOString()
|
|
304
|
-
};
|
|
305
|
-
};
|
|
306
|
-
var flipMutual = (mutual, byEntityData) => {
|
|
307
|
-
return __spreadProps(__spreadValues({}, mutual), {
|
|
308
|
-
entityId: mutual.byEntityId,
|
|
309
|
-
entityType: mutual.byEntityType,
|
|
310
|
-
byEntityId: mutual.entityId,
|
|
311
|
-
byEntityType: mutual.entityType,
|
|
312
|
-
data: byEntityData
|
|
313
|
-
});
|
|
314
|
-
};
|
|
315
|
-
var byEntityId = (a, b) => {
|
|
316
|
-
if (b.entityId < a.entityId) return -1;
|
|
317
|
-
return 1;
|
|
318
|
-
};
|
|
280
|
+
import { useCallback, useEffect as useEffect2, useMemo, useRef, useState as useState2 } from "react";
|
|
319
281
|
|
|
320
282
|
// lib/utils.ts
|
|
283
|
+
import { nanoid } from "nanoid";
|
|
321
284
|
var convertToMap = (data, mapKey) => {
|
|
322
285
|
const map = /* @__PURE__ */ new Map();
|
|
323
286
|
for (const i in data) {
|
|
@@ -352,6 +315,7 @@ var getUniqueFieldStateKey = (fieldName, fieldValue) => {
|
|
|
352
315
|
var getEntityRequestKey = (mode, entityType, entityId) => {
|
|
353
316
|
return `entity/${entityType}/${mode}${entityId ? `/${entityId}` : ""}`;
|
|
354
317
|
};
|
|
318
|
+
var createMutationCallRequestKey = (requestKey) => `${requestKey}#${nanoid()}`;
|
|
355
319
|
var getMutualRequestKey = (mode, byEntityType, entityType, byEntityId2, entityId, chainEntityQuery) => {
|
|
356
320
|
return `mutual/${getMutualStateKey(byEntityType, byEntityId2, entityType, entityId, chainEntityQuery)}/${mode}`;
|
|
357
321
|
};
|
|
@@ -363,7 +327,6 @@ var getUniqueFieldRequestKey = (entityType, fieldName, value) => {
|
|
|
363
327
|
};
|
|
364
328
|
|
|
365
329
|
// helpers/transactional.ts
|
|
366
|
-
import { nanoid } from "nanoid";
|
|
367
330
|
var getTransactionOperationRequestKey = (op) => {
|
|
368
331
|
switch (op.operation) {
|
|
369
332
|
case "createEntity":
|
|
@@ -381,7 +344,8 @@ var getTransactionOperationRequestKey = (op) => {
|
|
|
381
344
|
"create",
|
|
382
345
|
op.byEntityType,
|
|
383
346
|
op.entityType,
|
|
384
|
-
op.byEntityId
|
|
347
|
+
op.byEntityId,
|
|
348
|
+
op.entityId
|
|
385
349
|
);
|
|
386
350
|
case "updateMutual":
|
|
387
351
|
return getMutualRequestKey(
|
|
@@ -401,14 +365,21 @@ var getTransactionOperationRequestKey = (op) => {
|
|
|
401
365
|
);
|
|
402
366
|
}
|
|
403
367
|
};
|
|
404
|
-
var
|
|
405
|
-
|
|
406
|
-
op.
|
|
407
|
-
|
|
408
|
-
|
|
409
|
-
|
|
410
|
-
|
|
411
|
-
|
|
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));
|
|
412
383
|
var transactional = {
|
|
413
384
|
createEntity: (entityType, payload) => {
|
|
414
385
|
const _a = payload, { entityId } = _a, rest = __objRest(_a, ["entityId"]);
|
|
@@ -467,7 +438,46 @@ var transactional = {
|
|
|
467
438
|
})
|
|
468
439
|
};
|
|
469
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
|
+
|
|
470
479
|
// actions/core.action.ts
|
|
480
|
+
var EMPTY_MAP = /* @__PURE__ */ new Map();
|
|
471
481
|
var defaultOnError = (error) => {
|
|
472
482
|
if (!(error instanceof Error) && error.status >= 500) {
|
|
473
483
|
throw error;
|
|
@@ -816,18 +826,20 @@ var initCoreActions = (monoriseStore, appActions, coreService2) => {
|
|
|
816
826
|
if (keyParams.query) {
|
|
817
827
|
continue;
|
|
818
828
|
}
|
|
819
|
-
const matches = processorResults.some(
|
|
820
|
-
|
|
821
|
-
|
|
822
|
-
|
|
823
|
-
|
|
824
|
-
|
|
825
|
-
|
|
826
|
-
|
|
827
|
-
|
|
829
|
+
const matches = processorResults.some(
|
|
830
|
+
(result) => {
|
|
831
|
+
if (keyParams.group && result.group !== keyParams.group) {
|
|
832
|
+
return false;
|
|
833
|
+
}
|
|
834
|
+
if (keyParams.start && (!result.sortValue || result.sortValue < keyParams.start)) {
|
|
835
|
+
return false;
|
|
836
|
+
}
|
|
837
|
+
if (keyParams.end && (!result.sortValue || result.sortValue > keyParams.end)) {
|
|
838
|
+
return false;
|
|
839
|
+
}
|
|
840
|
+
return true;
|
|
828
841
|
}
|
|
829
|
-
|
|
830
|
-
});
|
|
842
|
+
);
|
|
831
843
|
if (matches) {
|
|
832
844
|
state.tag[tagKey].dataMap.set(data.entityId, data);
|
|
833
845
|
}
|
|
@@ -1035,22 +1047,27 @@ var initCoreActions = (monoriseStore, appActions, coreService2) => {
|
|
|
1035
1047
|
}
|
|
1036
1048
|
};
|
|
1037
1049
|
const executeTransaction2 = async (operations, opts = {}) => {
|
|
1038
|
-
var _a, _b, _c, _d;
|
|
1050
|
+
var _a, _b, _c, _d, _e;
|
|
1039
1051
|
const onError = (_a = opts.onError) != null ? _a : defaultOnError;
|
|
1040
1052
|
const isInterruptive = (_b = opts.isInterruptive) != null ? _b : true;
|
|
1041
|
-
const
|
|
1042
|
-
|
|
1053
|
+
const stateRequestKeys = Array.from(
|
|
1054
|
+
/* @__PURE__ */ new Set([
|
|
1055
|
+
getTransactionRequestKey(operations),
|
|
1056
|
+
...operations.flatMap(getTransactionOperationRequestKeys)
|
|
1057
|
+
])
|
|
1058
|
+
);
|
|
1059
|
+
const callRequestKey = (_c = opts.requestKey) != null ? _c : createTransactionCallRequestKey(operations);
|
|
1043
1060
|
const callPromise = coreService2.executeTransaction(operations, __spreadProps(__spreadValues({}, opts), {
|
|
1044
1061
|
requestKey: callRequestKey
|
|
1045
1062
|
}));
|
|
1046
|
-
const loadingMessage = (
|
|
1047
|
-
for (const requestKey of
|
|
1063
|
+
const loadingMessage = (_e = (_d = opts.feedback) == null ? void 0 : _d.loading) != null ? _e : "Processing transaction";
|
|
1064
|
+
for (const requestKey of stateRequestKeys) {
|
|
1048
1065
|
startLoading2({ requestKey, isInterruptive, message: loadingMessage });
|
|
1049
1066
|
}
|
|
1050
1067
|
let settled = false;
|
|
1051
1068
|
try {
|
|
1052
1069
|
const { data } = await callPromise;
|
|
1053
|
-
for (const requestKey of
|
|
1070
|
+
for (const requestKey of stateRequestKeys) {
|
|
1054
1071
|
endLoading2({ requestKey, isInterruptive, skipDedupe: true });
|
|
1055
1072
|
clearError2(requestKey);
|
|
1056
1073
|
}
|
|
@@ -1059,7 +1076,7 @@ var initCoreActions = (monoriseStore, appActions, coreService2) => {
|
|
|
1059
1076
|
monoriseStore.setState(
|
|
1060
1077
|
produce4((state) => {
|
|
1061
1078
|
data.results.forEach((entry, index) => {
|
|
1062
|
-
var _a2, _b2, _c2, _d2,
|
|
1079
|
+
var _a2, _b2, _c2, _d2, _e2, _f, _g, _h, _i, _j, _k, _l;
|
|
1063
1080
|
const { entityType, entityId } = entry;
|
|
1064
1081
|
if (entry.operation === "deleteEntity") {
|
|
1065
1082
|
deleteEntityFromStores(state, entityType, entityId);
|
|
@@ -1103,7 +1120,7 @@ var initCoreActions = (monoriseStore, appActions, coreService2) => {
|
|
|
1103
1120
|
state.mutual[bySide] = { dataMap: /* @__PURE__ */ new Map() };
|
|
1104
1121
|
}
|
|
1105
1122
|
state.mutual[bySide].dataMap = new Map(
|
|
1106
|
-
(
|
|
1123
|
+
(_e2 = state.mutual[bySide]) == null ? void 0 : _e2.dataMap
|
|
1107
1124
|
).set(entityId, mutual);
|
|
1108
1125
|
if (!state.mutual[side]) {
|
|
1109
1126
|
state.mutual[side] = { dataMap: /* @__PURE__ */ new Map() };
|
|
@@ -1167,7 +1184,7 @@ var initCoreActions = (monoriseStore, appActions, coreService2) => {
|
|
|
1167
1184
|
} catch (err) {
|
|
1168
1185
|
if (!settled) {
|
|
1169
1186
|
const callAppError = getError2(callRequestKey);
|
|
1170
|
-
for (const requestKey of
|
|
1187
|
+
for (const requestKey of stateRequestKeys) {
|
|
1171
1188
|
endLoading2({ requestKey, isInterruptive, skipDedupe: true });
|
|
1172
1189
|
if (callAppError) {
|
|
1173
1190
|
setError2({ requestKey, error: callAppError });
|
|
@@ -1617,6 +1634,192 @@ var initCoreActions = (monoriseStore, appActions, coreService2) => {
|
|
|
1617
1634
|
`mr/mutual/local-delete-by-entity/${entityType}/${id}`
|
|
1618
1635
|
);
|
|
1619
1636
|
};
|
|
1637
|
+
const mergeMutationOptions = (hookOptions, mutateOptions) => __spreadValues(__spreadValues(__spreadValues({}, hookOptions), mutateOptions), (hookOptions.feedback || mutateOptions.feedback) && {
|
|
1638
|
+
feedback: __spreadValues(__spreadValues({}, hookOptions.feedback), mutateOptions.feedback)
|
|
1639
|
+
});
|
|
1640
|
+
const useLatestRef = (value) => {
|
|
1641
|
+
const ref = useRef(value);
|
|
1642
|
+
ref.current = value;
|
|
1643
|
+
return ref;
|
|
1644
|
+
};
|
|
1645
|
+
const useMutationState = (requestKey) => {
|
|
1646
|
+
const isLoading = useLoadStore2(requestKey);
|
|
1647
|
+
const error = monoriseStore(
|
|
1648
|
+
(state) => state.app.errorStack.get(requestKey)
|
|
1649
|
+
);
|
|
1650
|
+
const clearMutationError = useCallback(
|
|
1651
|
+
() => clearError2(requestKey),
|
|
1652
|
+
[requestKey]
|
|
1653
|
+
);
|
|
1654
|
+
return {
|
|
1655
|
+
isLoading,
|
|
1656
|
+
error,
|
|
1657
|
+
requestKey,
|
|
1658
|
+
clearError: clearMutationError
|
|
1659
|
+
};
|
|
1660
|
+
};
|
|
1661
|
+
const useCreateEntity2 = (entityType, opts = {}) => {
|
|
1662
|
+
const optsRef = useLatestRef(opts);
|
|
1663
|
+
const mutation = useMutationState(
|
|
1664
|
+
getEntityRequestKey("create", entityType)
|
|
1665
|
+
);
|
|
1666
|
+
const mutate = useCallback(
|
|
1667
|
+
(entity, mutateOpts = {}) => createEntity2(
|
|
1668
|
+
entityType,
|
|
1669
|
+
entity,
|
|
1670
|
+
mergeMutationOptions(optsRef.current, mutateOpts)
|
|
1671
|
+
),
|
|
1672
|
+
[entityType, optsRef]
|
|
1673
|
+
);
|
|
1674
|
+
return __spreadValues({ mutate }, mutation);
|
|
1675
|
+
};
|
|
1676
|
+
const useUpsertEntity2 = (entityType, id, opts = {}) => {
|
|
1677
|
+
const optsRef = useLatestRef(opts);
|
|
1678
|
+
const mutation = useMutationState(
|
|
1679
|
+
getEntityRequestKey("upsert", entityType, id)
|
|
1680
|
+
);
|
|
1681
|
+
const mutate = useCallback(
|
|
1682
|
+
(entity, mutateOpts = {}) => upsertEntity2(
|
|
1683
|
+
entityType,
|
|
1684
|
+
id,
|
|
1685
|
+
entity,
|
|
1686
|
+
mergeMutationOptions(optsRef.current, mutateOpts)
|
|
1687
|
+
),
|
|
1688
|
+
[entityType, id, optsRef]
|
|
1689
|
+
);
|
|
1690
|
+
return __spreadValues({ mutate }, mutation);
|
|
1691
|
+
};
|
|
1692
|
+
const useEditEntity2 = (entityType, id, opts = {}) => {
|
|
1693
|
+
const optsRef = useLatestRef(opts);
|
|
1694
|
+
const mutation = useMutationState(
|
|
1695
|
+
getEntityRequestKey("edit", entityType, id)
|
|
1696
|
+
);
|
|
1697
|
+
const mutate = useCallback(
|
|
1698
|
+
(entity, mutateOpts = {}) => editEntity2(
|
|
1699
|
+
entityType,
|
|
1700
|
+
id,
|
|
1701
|
+
entity,
|
|
1702
|
+
mergeMutationOptions(optsRef.current, mutateOpts)
|
|
1703
|
+
),
|
|
1704
|
+
[entityType, id, optsRef]
|
|
1705
|
+
);
|
|
1706
|
+
return __spreadValues({ mutate }, mutation);
|
|
1707
|
+
};
|
|
1708
|
+
const useAdjustEntity2 = (entityType, id, opts = {}) => {
|
|
1709
|
+
const optsRef = useLatestRef(opts);
|
|
1710
|
+
const mutation = useMutationState(
|
|
1711
|
+
getEntityRequestKey("adjust", entityType, id)
|
|
1712
|
+
);
|
|
1713
|
+
const mutate = useCallback(
|
|
1714
|
+
(adjustments, mutateOpts = {}) => adjustEntity2(
|
|
1715
|
+
entityType,
|
|
1716
|
+
id,
|
|
1717
|
+
adjustments,
|
|
1718
|
+
mergeMutationOptions(optsRef.current, mutateOpts)
|
|
1719
|
+
),
|
|
1720
|
+
[entityType, id, optsRef]
|
|
1721
|
+
);
|
|
1722
|
+
return __spreadValues({ mutate }, mutation);
|
|
1723
|
+
};
|
|
1724
|
+
const useDeleteEntity2 = (entityType, id, opts = {}) => {
|
|
1725
|
+
const optsRef = useLatestRef(opts);
|
|
1726
|
+
const mutation = useMutationState(
|
|
1727
|
+
getEntityRequestKey("delete", entityType, id)
|
|
1728
|
+
);
|
|
1729
|
+
const mutate = useCallback(
|
|
1730
|
+
(mutateOpts = {}) => deleteEntity2(
|
|
1731
|
+
entityType,
|
|
1732
|
+
id,
|
|
1733
|
+
mergeMutationOptions(optsRef.current, mutateOpts)
|
|
1734
|
+
),
|
|
1735
|
+
[entityType, id, optsRef]
|
|
1736
|
+
);
|
|
1737
|
+
return __spreadValues({ mutate }, mutation);
|
|
1738
|
+
};
|
|
1739
|
+
const useCreateMutual2 = (byEntityType, entityType, byEntityId2, entityId, opts = {}) => {
|
|
1740
|
+
const optsRef = useLatestRef(opts);
|
|
1741
|
+
const mutation = useMutationState(
|
|
1742
|
+
getMutualRequestKey(
|
|
1743
|
+
"create",
|
|
1744
|
+
byEntityType,
|
|
1745
|
+
entityType,
|
|
1746
|
+
byEntityId2,
|
|
1747
|
+
entityId
|
|
1748
|
+
)
|
|
1749
|
+
);
|
|
1750
|
+
const mutate = useCallback(
|
|
1751
|
+
(payload = {}, mutateOpts = {}) => createMutual2(
|
|
1752
|
+
byEntityType,
|
|
1753
|
+
entityType,
|
|
1754
|
+
byEntityId2,
|
|
1755
|
+
entityId,
|
|
1756
|
+
payload,
|
|
1757
|
+
mergeMutationOptions(optsRef.current, mutateOpts)
|
|
1758
|
+
),
|
|
1759
|
+
[byEntityType, entityType, byEntityId2, entityId, optsRef]
|
|
1760
|
+
);
|
|
1761
|
+
return __spreadValues({ mutate }, mutation);
|
|
1762
|
+
};
|
|
1763
|
+
const useEditMutual2 = (byEntityType, entityType, byEntityId2, entityId, opts = {}) => {
|
|
1764
|
+
const optsRef = useLatestRef(opts);
|
|
1765
|
+
const mutation = useMutationState(
|
|
1766
|
+
getMutualRequestKey(
|
|
1767
|
+
"update",
|
|
1768
|
+
byEntityType,
|
|
1769
|
+
entityType,
|
|
1770
|
+
byEntityId2,
|
|
1771
|
+
entityId
|
|
1772
|
+
)
|
|
1773
|
+
);
|
|
1774
|
+
const mutate = useCallback(
|
|
1775
|
+
(payload = {}, mutateOpts = {}) => editMutual2(
|
|
1776
|
+
byEntityType,
|
|
1777
|
+
entityType,
|
|
1778
|
+
byEntityId2,
|
|
1779
|
+
entityId,
|
|
1780
|
+
payload,
|
|
1781
|
+
mergeMutationOptions(optsRef.current, mutateOpts)
|
|
1782
|
+
),
|
|
1783
|
+
[byEntityType, entityType, byEntityId2, entityId, optsRef]
|
|
1784
|
+
);
|
|
1785
|
+
return __spreadValues({ mutate }, mutation);
|
|
1786
|
+
};
|
|
1787
|
+
const useDeleteMutual2 = (byEntityType, entityType, byEntityId2, entityId, opts = {}) => {
|
|
1788
|
+
const optsRef = useLatestRef(opts);
|
|
1789
|
+
const mutation = useMutationState(
|
|
1790
|
+
getMutualRequestKey(
|
|
1791
|
+
"delete",
|
|
1792
|
+
byEntityType,
|
|
1793
|
+
entityType,
|
|
1794
|
+
byEntityId2,
|
|
1795
|
+
entityId
|
|
1796
|
+
)
|
|
1797
|
+
);
|
|
1798
|
+
const mutate = useCallback(
|
|
1799
|
+
(mutateOpts = {}) => deleteMutual2(
|
|
1800
|
+
byEntityType,
|
|
1801
|
+
entityType,
|
|
1802
|
+
byEntityId2,
|
|
1803
|
+
entityId,
|
|
1804
|
+
mergeMutationOptions(optsRef.current, mutateOpts)
|
|
1805
|
+
),
|
|
1806
|
+
[byEntityType, entityType, byEntityId2, entityId, optsRef]
|
|
1807
|
+
);
|
|
1808
|
+
return __spreadValues({ mutate }, mutation);
|
|
1809
|
+
};
|
|
1810
|
+
const useExecuteTransaction2 = (operations, opts = {}) => {
|
|
1811
|
+
const operationsRef = useLatestRef(operations);
|
|
1812
|
+
const optsRef = useLatestRef(opts);
|
|
1813
|
+
const mutation = useMutationState(getTransactionRequestKey(operations));
|
|
1814
|
+
const mutate = useCallback(
|
|
1815
|
+
(mutateOpts = {}) => executeTransaction2(
|
|
1816
|
+
operationsRef.current,
|
|
1817
|
+
mergeMutationOptions(optsRef.current, mutateOpts)
|
|
1818
|
+
),
|
|
1819
|
+
[operationsRef, optsRef]
|
|
1820
|
+
);
|
|
1821
|
+
return __spreadValues({ mutate }, mutation);
|
|
1822
|
+
};
|
|
1620
1823
|
const useEntity2 = (entityType, id, opts = {}) => {
|
|
1621
1824
|
const dataMap = monoriseStore(
|
|
1622
1825
|
(state) => {
|
|
@@ -1711,9 +1914,8 @@ var initCoreActions = (monoriseStore, appActions, coreService2) => {
|
|
|
1711
1914
|
const error = useErrorStore2(requestKey);
|
|
1712
1915
|
const state = monoriseStore((state2) => state2.entity[entityType]);
|
|
1713
1916
|
const { dataMap, searchResults, isFirstFetched, lastKey } = state != null ? state : {
|
|
1714
|
-
dataMap:
|
|
1917
|
+
dataMap: EMPTY_MAP
|
|
1715
1918
|
};
|
|
1716
|
-
const [entities, setEntities] = useState2();
|
|
1717
1919
|
const [query, setQuery] = useState2("");
|
|
1718
1920
|
const [skRange, setBetween] = useState2(params.skRange);
|
|
1719
1921
|
const [all, setAll] = useState2(params.all);
|
|
@@ -1742,40 +1944,22 @@ var initCoreActions = (monoriseStore, appActions, coreService2) => {
|
|
|
1742
1944
|
}, [all, entityType, skRange, opts, isFirstFetched, opts == null ? void 0 : opts.forceFetch, limit]);
|
|
1743
1945
|
useEffect2(() => {
|
|
1744
1946
|
var _a;
|
|
1745
|
-
|
|
1746
|
-
|
|
1747
|
-
|
|
1748
|
-
queryTimeout = setTimeout(async () => {
|
|
1749
|
-
await searchEntities(entityType, query);
|
|
1750
|
-
setIsSearching(false);
|
|
1751
|
-
}, (_a = opts.searchInterval) != null ? _a : 700);
|
|
1947
|
+
if (!(query == null ? void 0 : query.length)) {
|
|
1948
|
+
setIsSearching(false);
|
|
1949
|
+
return;
|
|
1752
1950
|
}
|
|
1753
|
-
|
|
1951
|
+
setIsSearching(true);
|
|
1952
|
+
const queryTimeout = setTimeout(async () => {
|
|
1953
|
+
await searchEntities(entityType, query);
|
|
1954
|
+
setIsSearching(false);
|
|
1955
|
+
}, (_a = opts.searchInterval) != null ? _a : 700);
|
|
1956
|
+
return () => clearTimeout(queryTimeout);
|
|
1754
1957
|
}, [entityType, query]);
|
|
1755
|
-
|
|
1756
|
-
|
|
1757
|
-
|
|
1758
|
-
|
|
1759
|
-
|
|
1760
|
-
if (dataMap.size !== (entities == null ? void 0 : entities.length) || dataMapArray.some(
|
|
1761
|
-
(item, index) => JSON.stringify(item) !== JSON.stringify(entities == null ? void 0 : entities[index])
|
|
1762
|
-
)) {
|
|
1763
|
-
setIsSearching(false);
|
|
1764
|
-
setEntities(dataMapArray);
|
|
1765
|
-
}
|
|
1766
|
-
}
|
|
1767
|
-
if (query) {
|
|
1768
|
-
setEntities(searchResults);
|
|
1769
|
-
}
|
|
1770
|
-
}, [
|
|
1771
|
-
dataMap,
|
|
1772
|
-
dataMap.size,
|
|
1773
|
-
entities,
|
|
1774
|
-
entities == null ? void 0 : entities.length,
|
|
1775
|
-
query,
|
|
1776
|
-
searchResults,
|
|
1777
|
-
searchResults == null ? void 0 : searchResults.length
|
|
1778
|
-
]);
|
|
1958
|
+
const listed = useMemo(
|
|
1959
|
+
() => Array.from(dataMap.values()).sort(byEntityId),
|
|
1960
|
+
[dataMap]
|
|
1961
|
+
);
|
|
1962
|
+
const entities = query ? searchResults : listed;
|
|
1779
1963
|
const handleQueryChange = (event) => {
|
|
1780
1964
|
setQuery(event.target.value);
|
|
1781
1965
|
};
|
|
@@ -1851,9 +2035,12 @@ var initCoreActions = (monoriseStore, appActions, coreService2) => {
|
|
|
1851
2035
|
);
|
|
1852
2036
|
const state = monoriseStore((state2) => state2.mutual[stateKey]);
|
|
1853
2037
|
const { dataMap, isFirstFetched, lastKey } = state || {
|
|
1854
|
-
dataMap:
|
|
2038
|
+
dataMap: EMPTY_MAP
|
|
1855
2039
|
};
|
|
1856
|
-
const
|
|
2040
|
+
const mutuals = useMemo(
|
|
2041
|
+
() => Array.from(dataMap.values()),
|
|
2042
|
+
[dataMap]
|
|
2043
|
+
);
|
|
1857
2044
|
const requestKey = getMutualRequestKey(
|
|
1858
2045
|
"list",
|
|
1859
2046
|
byEntityType,
|
|
@@ -1885,14 +2072,6 @@ var initCoreActions = (monoriseStore, appActions, coreService2) => {
|
|
|
1885
2072
|
opts == null ? void 0 : opts.forceFetch,
|
|
1886
2073
|
opts == null ? void 0 : opts.noData
|
|
1887
2074
|
]);
|
|
1888
|
-
useEffect2(() => {
|
|
1889
|
-
const dataMapArray = Array.from(dataMap.values());
|
|
1890
|
-
if (dataMap.size !== (mutuals == null ? void 0 : mutuals.length) || dataMapArray.some(
|
|
1891
|
-
(item, index) => JSON.stringify(item) !== JSON.stringify(mutuals[index])
|
|
1892
|
-
)) {
|
|
1893
|
-
setMutuals(dataMapArray);
|
|
1894
|
-
}
|
|
1895
|
-
}, [dataMap, dataMap.size, mutuals == null ? void 0 : mutuals.length]);
|
|
1896
2075
|
return __spreadValues({
|
|
1897
2076
|
mutuals,
|
|
1898
2077
|
mutualsMap: dataMap,
|
|
@@ -1952,9 +2131,18 @@ var initCoreActions = (monoriseStore, appActions, coreService2) => {
|
|
|
1952
2131
|
const stateKey = getTagStateKey(entityType, tagName, params);
|
|
1953
2132
|
const state = monoriseStore((state2) => state2.tag[stateKey]);
|
|
1954
2133
|
const { dataMap, isFirstFetched, lastKey } = state || {
|
|
1955
|
-
dataMap:
|
|
2134
|
+
dataMap: EMPTY_MAP
|
|
1956
2135
|
};
|
|
1957
|
-
const
|
|
2136
|
+
const group = params == null ? void 0 : params.group;
|
|
2137
|
+
const entities = useMemo(
|
|
2138
|
+
() => sortTaggedEntitiesLikeServer(
|
|
2139
|
+
Array.from(dataMap.values()),
|
|
2140
|
+
entityType,
|
|
2141
|
+
tagName,
|
|
2142
|
+
group
|
|
2143
|
+
),
|
|
2144
|
+
[dataMap, entityType, tagName, group]
|
|
2145
|
+
);
|
|
1958
2146
|
const requestKey = getTagRequestKey("list", entityType, tagName, params);
|
|
1959
2147
|
const isLoading = useLoadStore2(requestKey);
|
|
1960
2148
|
const error = useErrorStore2(requestKey);
|
|
@@ -1963,19 +2151,6 @@ var initCoreActions = (monoriseStore, appActions, coreService2) => {
|
|
|
1963
2151
|
listEntitiesByTag(entityType, tagName, opts);
|
|
1964
2152
|
}
|
|
1965
2153
|
}, [entityType, opts, tagName, params, opts == null ? void 0 : opts.forceFetch]);
|
|
1966
|
-
useEffect2(() => {
|
|
1967
|
-
const dataMapArray = sortTaggedEntitiesLikeServer(
|
|
1968
|
-
Array.from(dataMap.values()),
|
|
1969
|
-
entityType,
|
|
1970
|
-
tagName,
|
|
1971
|
-
params == null ? void 0 : params.group
|
|
1972
|
-
);
|
|
1973
|
-
if (dataMap.size !== (entities == null ? void 0 : entities.length) || dataMapArray.some(
|
|
1974
|
-
(item, index) => JSON.stringify(item) !== JSON.stringify(entities[index])
|
|
1975
|
-
)) {
|
|
1976
|
-
setEntities(dataMapArray);
|
|
1977
|
-
}
|
|
1978
|
-
}, [dataMap, dataMap.size, entities == null ? void 0 : entities.length]);
|
|
1979
2154
|
return {
|
|
1980
2155
|
entities,
|
|
1981
2156
|
entitiesMap: dataMap,
|
|
@@ -2058,6 +2233,15 @@ var initCoreActions = (monoriseStore, appActions, coreService2) => {
|
|
|
2058
2233
|
editMutual: editMutual2,
|
|
2059
2234
|
deleteMutual: deleteMutual2,
|
|
2060
2235
|
deleteLocalMutual: deleteLocalMutual2,
|
|
2236
|
+
useCreateEntity: useCreateEntity2,
|
|
2237
|
+
useUpsertEntity: useUpsertEntity2,
|
|
2238
|
+
useEditEntity: useEditEntity2,
|
|
2239
|
+
useAdjustEntity: useAdjustEntity2,
|
|
2240
|
+
useDeleteEntity: useDeleteEntity2,
|
|
2241
|
+
useExecuteTransaction: useExecuteTransaction2,
|
|
2242
|
+
useCreateMutual: useCreateMutual2,
|
|
2243
|
+
useEditMutual: useEditMutual2,
|
|
2244
|
+
useDeleteMutual: useDeleteMutual2,
|
|
2061
2245
|
useEntity: useEntity2,
|
|
2062
2246
|
useEntityByUniqueField: useEntityByUniqueField2,
|
|
2063
2247
|
useEntities: useEntities2,
|
|
@@ -2071,7 +2255,7 @@ var initCoreActions = (monoriseStore, appActions, coreService2) => {
|
|
|
2071
2255
|
};
|
|
2072
2256
|
|
|
2073
2257
|
// actions/websocket.action.ts
|
|
2074
|
-
import { useCallback, useEffect as useEffect3, useRef, useState as useState3 } from "react";
|
|
2258
|
+
import { useCallback as useCallback2, useEffect as useEffect3, useRef as useRef2, useState as useState3 } from "react";
|
|
2075
2259
|
import { produce as produce5 } from "immer";
|
|
2076
2260
|
var globalWsManager = null;
|
|
2077
2261
|
var wsEndpoint;
|
|
@@ -2092,8 +2276,8 @@ var initWebSocketActions = (monoriseStore, httpActions) => {
|
|
|
2092
2276
|
const [isSubscribed, setIsSubscribed] = useState3(false);
|
|
2093
2277
|
const [error, setError2] = useState3(null);
|
|
2094
2278
|
const [hasMore, setHasMore] = useState3(true);
|
|
2095
|
-
const lastKeyRef =
|
|
2096
|
-
const isFirstFetchRef =
|
|
2279
|
+
const lastKeyRef = useRef2(void 0);
|
|
2280
|
+
const isFirstFetchRef = useRef2(true);
|
|
2097
2281
|
const entities = monoriseStore((state) => {
|
|
2098
2282
|
var _a;
|
|
2099
2283
|
const entityState = state.entity[entityType];
|
|
@@ -2222,8 +2406,8 @@ var initWebSocketActions = (monoriseStore, httpActions) => {
|
|
|
2222
2406
|
const [isSubscribed, setIsSubscribed] = useState3(false);
|
|
2223
2407
|
const [error, setError2] = useState3(null);
|
|
2224
2408
|
const [hasMore, setHasMore] = useState3(true);
|
|
2225
|
-
const lastKeyRef =
|
|
2226
|
-
const isFirstFetchRef =
|
|
2409
|
+
const lastKeyRef = useRef2(void 0);
|
|
2410
|
+
const isFirstFetchRef = useRef2(true);
|
|
2227
2411
|
const mutualKey = byEntityId2 ? `${byEntityType}/${byEntityId2}/${mutualEntityType}` : "";
|
|
2228
2412
|
const mutuals = monoriseStore((state) => {
|
|
2229
2413
|
var _a, _b;
|
|
@@ -2388,7 +2572,7 @@ var initWebSocketActions = (monoriseStore, httpActions) => {
|
|
|
2388
2572
|
setIsSubscribed(false);
|
|
2389
2573
|
};
|
|
2390
2574
|
}, [channel]);
|
|
2391
|
-
const send =
|
|
2575
|
+
const send = useCallback2(
|
|
2392
2576
|
(data) => {
|
|
2393
2577
|
if (!globalWsManager || !channel) return;
|
|
2394
2578
|
globalWsManager.sendEphemeral(channel, data);
|
|
@@ -2401,8 +2585,8 @@ var initWebSocketActions = (monoriseStore, httpActions) => {
|
|
|
2401
2585
|
const { entityType, entityId, ticketEndpoint } = opts;
|
|
2402
2586
|
const [isConnected, setIsConnected] = useState3(false);
|
|
2403
2587
|
const [error, setError2] = useState3(null);
|
|
2404
|
-
const refreshTimerRef =
|
|
2405
|
-
const hasConnectedOnceRef =
|
|
2588
|
+
const refreshTimerRef = useRef2(null);
|
|
2589
|
+
const hasConnectedOnceRef = useRef2(false);
|
|
2406
2590
|
const resyncFromHttp = async () => {
|
|
2407
2591
|
var _a, _b;
|
|
2408
2592
|
if (!httpActions) return;
|
|
@@ -2435,14 +2619,14 @@ var initWebSocketActions = (monoriseStore, httpActions) => {
|
|
|
2435
2619
|
}
|
|
2436
2620
|
}
|
|
2437
2621
|
};
|
|
2438
|
-
const wsManagerRef =
|
|
2439
|
-
const isMountedRef =
|
|
2440
|
-
const connectingRef =
|
|
2441
|
-
const reconnectCountRef =
|
|
2442
|
-
const connectRef =
|
|
2622
|
+
const wsManagerRef = useRef2(null);
|
|
2623
|
+
const isMountedRef = useRef2(true);
|
|
2624
|
+
const connectingRef = useRef2(false);
|
|
2625
|
+
const reconnectCountRef = useRef2(0);
|
|
2626
|
+
const connectRef = useRef2(() => {
|
|
2443
2627
|
});
|
|
2444
|
-
const lastConnectedAtRef =
|
|
2445
|
-
const fetchTicket =
|
|
2628
|
+
const lastConnectedAtRef = useRef2(0);
|
|
2629
|
+
const fetchTicket = useCallback2(async () => {
|
|
2446
2630
|
try {
|
|
2447
2631
|
const url = ticketEndpoint || `/api/core/ws/ticket/${entityType}/${entityId}`;
|
|
2448
2632
|
const fetchOpts = {
|
|
@@ -2465,7 +2649,7 @@ var initWebSocketActions = (monoriseStore, httpActions) => {
|
|
|
2465
2649
|
return { error: { code: "TICKET_FAILED", message: err.message } };
|
|
2466
2650
|
}
|
|
2467
2651
|
}, [entityType, entityId, ticketEndpoint]);
|
|
2468
|
-
const connectWithTicket =
|
|
2652
|
+
const connectWithTicket = useCallback2(async () => {
|
|
2469
2653
|
if (connectingRef.current) return;
|
|
2470
2654
|
connectingRef.current = true;
|
|
2471
2655
|
let result = null;
|
|
@@ -2645,7 +2829,12 @@ var initAxiosInterceptor = (store2, appActions) => {
|
|
|
2645
2829
|
const { startLoading: startLoading2 } = appActions;
|
|
2646
2830
|
const axiosInstance = request.create();
|
|
2647
2831
|
function makeRequest(url, config, data) {
|
|
2648
|
-
const {
|
|
2832
|
+
const {
|
|
2833
|
+
requestKey,
|
|
2834
|
+
stateKeys = [],
|
|
2835
|
+
isInterruptive = false,
|
|
2836
|
+
feedback
|
|
2837
|
+
} = config;
|
|
2649
2838
|
const { ongoingRequests } = store2.getState().app;
|
|
2650
2839
|
if (ongoingRequests.has(requestKey)) {
|
|
2651
2840
|
return ongoingRequests.get(requestKey);
|
|
@@ -2663,6 +2852,15 @@ var initAxiosInterceptor = (store2, appActions) => {
|
|
|
2663
2852
|
message: feedback == null ? void 0 : feedback.loading,
|
|
2664
2853
|
request: promise
|
|
2665
2854
|
});
|
|
2855
|
+
for (const stateKey of new Set(stateKeys)) {
|
|
2856
|
+
if (stateKey !== requestKey) {
|
|
2857
|
+
startLoading2({
|
|
2858
|
+
requestKey: stateKey,
|
|
2859
|
+
isInterruptive,
|
|
2860
|
+
message: feedback == null ? void 0 : feedback.loading
|
|
2861
|
+
});
|
|
2862
|
+
}
|
|
2863
|
+
}
|
|
2666
2864
|
return promise;
|
|
2667
2865
|
}
|
|
2668
2866
|
const axios2 = __spreadProps(__spreadValues({}, axiosInstance), {
|
|
@@ -2683,12 +2881,31 @@ var injectAxiosInterceptor = (appActions, authActions, axios2, opts) => {
|
|
|
2683
2881
|
code: "UNKNOWN_EXCEPTION",
|
|
2684
2882
|
message: "Ops, something doesn't seems right"
|
|
2685
2883
|
};
|
|
2884
|
+
const settleLoading = (config) => {
|
|
2885
|
+
const { requestKey, stateKeys = [], isInterruptive } = config;
|
|
2886
|
+
endLoading2({ requestKey, isInterruptive });
|
|
2887
|
+
for (const stateKey of new Set(stateKeys)) {
|
|
2888
|
+
if (stateKey !== requestKey) {
|
|
2889
|
+
endLoading2({
|
|
2890
|
+
requestKey: stateKey,
|
|
2891
|
+
isInterruptive,
|
|
2892
|
+
skipDedupe: true
|
|
2893
|
+
});
|
|
2894
|
+
}
|
|
2895
|
+
}
|
|
2896
|
+
};
|
|
2897
|
+
const getErrorKeys = (config) => {
|
|
2898
|
+
const { requestKey, stateKeys = [] } = config;
|
|
2899
|
+
return stateKeys.length > 0 ? new Set(stateKeys) : /* @__PURE__ */ new Set([requestKey]);
|
|
2900
|
+
};
|
|
2686
2901
|
axios2.interceptors.response.use(
|
|
2687
2902
|
(response) => {
|
|
2688
2903
|
var _a;
|
|
2689
|
-
const {
|
|
2690
|
-
|
|
2691
|
-
|
|
2904
|
+
const { feedback } = response.config;
|
|
2905
|
+
settleLoading(response.config);
|
|
2906
|
+
for (const errorKey of getErrorKeys(response.config)) {
|
|
2907
|
+
clearError2(errorKey);
|
|
2908
|
+
}
|
|
2692
2909
|
if (feedback == null ? void 0 : feedback.success) {
|
|
2693
2910
|
(_a = options.onApiSuccess) == null ? void 0 : _a.call(options, response, feedback.success);
|
|
2694
2911
|
}
|
|
@@ -2696,14 +2913,16 @@ var injectAxiosInterceptor = (appActions, authActions, axios2, opts) => {
|
|
|
2696
2913
|
},
|
|
2697
2914
|
(error) => {
|
|
2698
2915
|
var _a, _b, _c, _d, _e;
|
|
2699
|
-
const
|
|
2700
|
-
|
|
2916
|
+
const config = error.config;
|
|
2917
|
+
settleLoading(config);
|
|
2701
2918
|
const appError = ((_a = error.response) == null ? void 0 : _a.data) ? {
|
|
2702
2919
|
code: (_b = error.response) == null ? void 0 : _b.statusText,
|
|
2703
2920
|
status: (_c = error.response) == null ? void 0 : _c.status,
|
|
2704
2921
|
message: (_d = error.response) == null ? void 0 : _d.data
|
|
2705
2922
|
} : unknownError;
|
|
2706
|
-
|
|
2923
|
+
for (const errorKey of getErrorKeys(config)) {
|
|
2924
|
+
setError2({ requestKey: errorKey, error: appError });
|
|
2925
|
+
}
|
|
2707
2926
|
if (((_e = error.response) == null ? void 0 : _e.status) === 401) {
|
|
2708
2927
|
setIsUnauthorized2(true);
|
|
2709
2928
|
}
|
|
@@ -2760,6 +2979,22 @@ var TAG_API_BASE_URL = "/api/core/tag";
|
|
|
2760
2979
|
var TRANSACTION_API_BASE_URL = "/api/core/transaction";
|
|
2761
2980
|
var initCoreService = (monoriseStore, axios2, opts) => {
|
|
2762
2981
|
let options = opts || {};
|
|
2982
|
+
const getMutationRequestConfig = (stateKey, opts2, compatibilityStateKeys = []) => {
|
|
2983
|
+
var _a;
|
|
2984
|
+
return {
|
|
2985
|
+
requestKey: (_a = opts2.requestKey) != null ? _a : createMutationCallRequestKey(stateKey),
|
|
2986
|
+
// Keep the stable mutation key reactive while requestKey remains unique
|
|
2987
|
+
// per write. An explicit key and any legacy observation keys remain
|
|
2988
|
+
// observable for backwards compatibility with useLoadStore/useErrorStore.
|
|
2989
|
+
stateKeys: Array.from(
|
|
2990
|
+
/* @__PURE__ */ new Set([
|
|
2991
|
+
stateKey,
|
|
2992
|
+
...compatibilityStateKeys,
|
|
2993
|
+
...opts2.requestKey ? [opts2.requestKey] : []
|
|
2994
|
+
])
|
|
2995
|
+
)
|
|
2996
|
+
};
|
|
2997
|
+
};
|
|
2763
2998
|
const listEntities = (entityType, payload, opts2 = {}) => {
|
|
2764
2999
|
const { entityApiBaseUrl = ENTITY_API_BASE_URL } = options;
|
|
2765
3000
|
return axios2.get(opts2.customUrl || `${entityApiBaseUrl}/${entityType}`, {
|
|
@@ -2823,89 +3058,89 @@ var initCoreService = (monoriseStore, axios2, opts) => {
|
|
|
2823
3058
|
var _a;
|
|
2824
3059
|
const { entityApiBaseUrl = ENTITY_API_BASE_URL } = options;
|
|
2825
3060
|
const entityConfig = monoriseStore.getState().config;
|
|
3061
|
+
const stateKey = getEntityRequestKey("create", entityType);
|
|
2826
3062
|
return axios2.post(
|
|
2827
3063
|
opts2.customUrl || `${entityApiBaseUrl}/${entityType}`,
|
|
2828
3064
|
__spreadValues(__spreadValues({}, values), opts2.entityId && { entityId: opts2.entityId }),
|
|
2829
|
-
{
|
|
2830
|
-
requestKey: opts2.requestKey || getEntityRequestKey("create", entityType),
|
|
3065
|
+
__spreadProps(__spreadValues({}, getMutationRequestConfig(stateKey, opts2)), {
|
|
2831
3066
|
isInterruptive: (_a = opts2.isInterruptive) != null ? _a : true,
|
|
2832
3067
|
feedback: __spreadValues({
|
|
2833
3068
|
loading: `Creating ${entityConfig[entityType].displayName}`,
|
|
2834
3069
|
success: `${entityConfig[entityType].displayName} created`
|
|
2835
3070
|
}, opts2.feedback || {})
|
|
2836
|
-
}
|
|
3071
|
+
})
|
|
2837
3072
|
);
|
|
2838
3073
|
};
|
|
2839
3074
|
const upsertEntity2 = (entityType, id, values, opts2 = {}) => {
|
|
2840
3075
|
var _a;
|
|
2841
3076
|
const { entityApiBaseUrl = ENTITY_API_BASE_URL } = options;
|
|
2842
3077
|
const entityConfig = monoriseStore.getState().config;
|
|
3078
|
+
const stateKey = getEntityRequestKey("upsert", entityType, id);
|
|
2843
3079
|
return axios2.put(
|
|
2844
3080
|
opts2.customUrl || `${entityApiBaseUrl}/${entityType}/${id}`,
|
|
2845
3081
|
values,
|
|
2846
|
-
{
|
|
2847
|
-
requestKey: getEntityRequestKey("upsert", entityType, id),
|
|
3082
|
+
__spreadProps(__spreadValues({}, getMutationRequestConfig(stateKey, opts2)), {
|
|
2848
3083
|
isInterruptive: (_a = opts2.isInterruptive) != null ? _a : true,
|
|
2849
3084
|
feedback: __spreadValues({
|
|
2850
3085
|
loading: `Updating ${entityConfig[entityType].displayName}`,
|
|
2851
3086
|
success: `${entityConfig[entityType].displayName} updated`
|
|
2852
3087
|
}, opts2.feedback || {})
|
|
2853
|
-
}
|
|
3088
|
+
})
|
|
2854
3089
|
);
|
|
2855
3090
|
};
|
|
2856
3091
|
const editEntity2 = (entityType, id, values, opts2 = {}) => {
|
|
2857
3092
|
var _a;
|
|
2858
3093
|
const { entityApiBaseUrl = ENTITY_API_BASE_URL } = options;
|
|
2859
3094
|
const entityConfig = monoriseStore.getState().config;
|
|
3095
|
+
const stateKey = getEntityRequestKey("edit", entityType, id);
|
|
2860
3096
|
return axios2.patch(
|
|
2861
3097
|
opts2.customUrl || `${entityApiBaseUrl}/${entityType}/${id}`,
|
|
2862
3098
|
values,
|
|
2863
|
-
{
|
|
2864
|
-
requestKey: getEntityRequestKey("edit", entityType, id),
|
|
3099
|
+
__spreadProps(__spreadValues({}, getMutationRequestConfig(stateKey, opts2)), {
|
|
2865
3100
|
isInterruptive: (_a = opts2.isInterruptive) != null ? _a : true,
|
|
2866
3101
|
feedback: __spreadValues({
|
|
2867
3102
|
loading: `Updating ${entityConfig[entityType].displayName}`,
|
|
2868
3103
|
success: `${entityConfig[entityType].displayName} updated`
|
|
2869
3104
|
}, opts2.feedback || {})
|
|
2870
|
-
}
|
|
3105
|
+
})
|
|
2871
3106
|
);
|
|
2872
3107
|
};
|
|
2873
3108
|
const adjustEntity2 = (entityType, id, adjustments, opts2 = {}) => {
|
|
2874
3109
|
var _a;
|
|
2875
3110
|
const { entityApiBaseUrl = ENTITY_API_BASE_URL } = options;
|
|
2876
3111
|
const entityConfig = monoriseStore.getState().config;
|
|
3112
|
+
const stateKey = getEntityRequestKey("adjust", entityType, id);
|
|
2877
3113
|
const body = opts2.condition ? __spreadProps(__spreadValues({}, adjustments), { $condition: opts2.condition }) : adjustments;
|
|
2878
3114
|
return axios2.post(
|
|
2879
3115
|
opts2.customUrl || `${entityApiBaseUrl}/${entityType}/${id}/adjust`,
|
|
2880
3116
|
body,
|
|
2881
|
-
{
|
|
2882
|
-
requestKey: getEntityRequestKey("adjust", entityType, id),
|
|
3117
|
+
__spreadProps(__spreadValues({}, getMutationRequestConfig(stateKey, opts2)), {
|
|
2883
3118
|
isInterruptive: (_a = opts2.isInterruptive) != null ? _a : true,
|
|
2884
3119
|
feedback: __spreadValues({
|
|
2885
3120
|
loading: `Updating ${entityConfig[entityType].displayName}`,
|
|
2886
3121
|
success: `${entityConfig[entityType].displayName} updated`
|
|
2887
3122
|
}, opts2.feedback || {})
|
|
2888
|
-
}
|
|
3123
|
+
})
|
|
2889
3124
|
);
|
|
2890
3125
|
};
|
|
2891
3126
|
const deleteEntity2 = (entityType, id, opts2 = {}) => {
|
|
2892
3127
|
var _a;
|
|
2893
3128
|
const { entityApiBaseUrl = ENTITY_API_BASE_URL } = options;
|
|
2894
3129
|
const entityConfig = monoriseStore.getState().config;
|
|
3130
|
+
const stateKey = getEntityRequestKey("delete", entityType, id);
|
|
2895
3131
|
return axios2.delete(
|
|
2896
3132
|
opts2.customUrl || `${entityApiBaseUrl}/${entityType}/${id}`,
|
|
2897
|
-
{
|
|
2898
|
-
requestKey: getEntityRequestKey("delete", entityType, id),
|
|
3133
|
+
__spreadProps(__spreadValues({}, getMutationRequestConfig(stateKey, opts2)), {
|
|
2899
3134
|
isInterruptive: (_a = opts2.isInterruptive) != null ? _a : true,
|
|
2900
3135
|
feedback: __spreadValues({
|
|
2901
3136
|
loading: `Deleting ${entityConfig[entityType].displayName}`,
|
|
2902
3137
|
success: `${entityConfig[entityType].displayName} deleted`
|
|
2903
3138
|
}, opts2.feedback || {})
|
|
2904
|
-
}
|
|
3139
|
+
})
|
|
2905
3140
|
);
|
|
2906
3141
|
};
|
|
2907
3142
|
const executeTransaction2 = (operations, opts2 = {}) => {
|
|
2908
|
-
var _a;
|
|
3143
|
+
var _a, _b;
|
|
2909
3144
|
const { transactionApiBaseUrl = TRANSACTION_API_BASE_URL } = options;
|
|
2910
3145
|
return axios2.post(
|
|
2911
3146
|
opts2.customUrl || transactionApiBaseUrl,
|
|
@@ -2920,8 +3155,8 @@ var initCoreService = (monoriseStore, axios2, opts) => {
|
|
|
2920
3155
|
// namespaced so it can never match a single-entity key and unique per
|
|
2921
3156
|
// call so non-idempotent transaction writes cannot be silently
|
|
2922
3157
|
// deduplicated. Callers can pass opts.requestKey to opt into dedupe.
|
|
2923
|
-
requestKey: opts2.requestKey
|
|
2924
|
-
isInterruptive: (
|
|
3158
|
+
requestKey: (_a = opts2.requestKey) != null ? _a : createTransactionCallRequestKey(operations),
|
|
3159
|
+
isInterruptive: (_b = opts2.isInterruptive) != null ? _b : true,
|
|
2925
3160
|
feedback: __spreadValues({
|
|
2926
3161
|
loading: "Processing transaction",
|
|
2927
3162
|
success: "Transaction completed"
|
|
@@ -2972,65 +3207,72 @@ var initCoreService = (monoriseStore, axios2, opts) => {
|
|
|
2972
3207
|
const createMutual2 = (byEntityType, entityType, byEntityId2, entityId, payload, opts2 = {}) => {
|
|
2973
3208
|
var _a;
|
|
2974
3209
|
const { mutualApiBaseUrl = MUTUAL_API_BASE_URL } = options;
|
|
3210
|
+
const stateKey = getMutualRequestKey(
|
|
3211
|
+
"create",
|
|
3212
|
+
byEntityType,
|
|
3213
|
+
entityType,
|
|
3214
|
+
byEntityId2,
|
|
3215
|
+
entityId
|
|
3216
|
+
);
|
|
3217
|
+
const legacyStateKey = getMutualRequestKey(
|
|
3218
|
+
"create",
|
|
3219
|
+
byEntityType,
|
|
3220
|
+
entityType,
|
|
3221
|
+
byEntityId2
|
|
3222
|
+
);
|
|
2975
3223
|
return axios2.post(
|
|
2976
3224
|
opts2.customUrl || `${mutualApiBaseUrl}/${getMutualStateKey(byEntityType, byEntityId2, entityType, entityId)}`,
|
|
2977
3225
|
payload,
|
|
2978
|
-
{
|
|
2979
|
-
requestKey: getMutualRequestKey(
|
|
2980
|
-
"create",
|
|
2981
|
-
byEntityType,
|
|
2982
|
-
entityType,
|
|
2983
|
-
byEntityId2
|
|
2984
|
-
),
|
|
3226
|
+
__spreadProps(__spreadValues({}, getMutationRequestConfig(stateKey, opts2, [legacyStateKey])), {
|
|
2985
3227
|
isInterruptive: (_a = opts2.isInterruptive) != null ? _a : true,
|
|
2986
3228
|
feedback: __spreadValues({
|
|
2987
3229
|
loading: "Creating linkage",
|
|
2988
3230
|
success: "Linkage created"
|
|
2989
3231
|
}, opts2.feedback || {})
|
|
2990
|
-
}
|
|
3232
|
+
})
|
|
2991
3233
|
);
|
|
2992
3234
|
};
|
|
2993
3235
|
const editMutual2 = (byEntityType, entityType, byEntityId2, entityId, payload, opts2 = {}) => {
|
|
2994
3236
|
var _a;
|
|
2995
3237
|
const { mutualApiBaseUrl = MUTUAL_API_BASE_URL } = options;
|
|
3238
|
+
const stateKey = getMutualRequestKey(
|
|
3239
|
+
"update",
|
|
3240
|
+
byEntityType,
|
|
3241
|
+
entityType,
|
|
3242
|
+
byEntityId2,
|
|
3243
|
+
entityId
|
|
3244
|
+
);
|
|
2996
3245
|
return axios2.patch(
|
|
2997
3246
|
opts2.customUrl || `${mutualApiBaseUrl}/${getMutualStateKey(byEntityType, byEntityId2, entityType, entityId)}`,
|
|
2998
3247
|
payload,
|
|
2999
|
-
{
|
|
3000
|
-
requestKey: getMutualRequestKey(
|
|
3001
|
-
"update",
|
|
3002
|
-
byEntityType,
|
|
3003
|
-
entityType,
|
|
3004
|
-
byEntityId2,
|
|
3005
|
-
entityId
|
|
3006
|
-
),
|
|
3248
|
+
__spreadProps(__spreadValues({}, getMutationRequestConfig(stateKey, opts2)), {
|
|
3007
3249
|
isInterruptive: (_a = opts2.isInterruptive) != null ? _a : true,
|
|
3008
3250
|
feedback: __spreadValues({
|
|
3009
3251
|
loading: "Updating linkage",
|
|
3010
3252
|
success: "Linkage updated"
|
|
3011
3253
|
}, opts2.feedback || {})
|
|
3012
|
-
}
|
|
3254
|
+
})
|
|
3013
3255
|
);
|
|
3014
3256
|
};
|
|
3015
3257
|
const deleteMutual2 = (byEntityType, entityType, byEntityId2, entityId, opts2 = {}) => {
|
|
3016
3258
|
var _a;
|
|
3017
3259
|
const { mutualApiBaseUrl = MUTUAL_API_BASE_URL } = options;
|
|
3260
|
+
const stateKey = getMutualRequestKey(
|
|
3261
|
+
"delete",
|
|
3262
|
+
byEntityType,
|
|
3263
|
+
entityType,
|
|
3264
|
+
byEntityId2,
|
|
3265
|
+
entityId
|
|
3266
|
+
);
|
|
3018
3267
|
return axios2.delete(
|
|
3019
3268
|
opts2.customUrl || `${mutualApiBaseUrl}/${getMutualStateKey(byEntityType, byEntityId2, entityType, entityId)}`,
|
|
3020
|
-
{
|
|
3021
|
-
requestKey: getMutualRequestKey(
|
|
3022
|
-
"delete",
|
|
3023
|
-
byEntityType,
|
|
3024
|
-
entityType,
|
|
3025
|
-
byEntityId2,
|
|
3026
|
-
entityId
|
|
3027
|
-
),
|
|
3269
|
+
__spreadProps(__spreadValues({}, getMutationRequestConfig(stateKey, opts2)), {
|
|
3028
3270
|
isInterruptive: (_a = opts2.isInterruptive) != null ? _a : true,
|
|
3029
3271
|
feedback: __spreadValues({
|
|
3030
3272
|
loading: "Removing linkage",
|
|
3031
3273
|
success: "Linkage removed"
|
|
3032
3274
|
}, opts2.feedback || {})
|
|
3033
|
-
}
|
|
3275
|
+
})
|
|
3034
3276
|
);
|
|
3035
3277
|
};
|
|
3036
3278
|
const makeEntityService = (entityType) => ({
|
|
@@ -3404,6 +3646,15 @@ var {
|
|
|
3404
3646
|
editMutual,
|
|
3405
3647
|
deleteMutual,
|
|
3406
3648
|
deleteLocalMutual,
|
|
3649
|
+
useCreateEntity,
|
|
3650
|
+
useUpsertEntity,
|
|
3651
|
+
useEditEntity,
|
|
3652
|
+
useAdjustEntity,
|
|
3653
|
+
useDeleteEntity,
|
|
3654
|
+
useExecuteTransaction,
|
|
3655
|
+
useCreateMutual,
|
|
3656
|
+
useEditMutual,
|
|
3657
|
+
useDeleteMutual,
|
|
3407
3658
|
useEntity,
|
|
3408
3659
|
useEntityByUniqueField,
|
|
3409
3660
|
useEntities,
|
|
@@ -3466,7 +3717,14 @@ export {
|
|
|
3466
3717
|
updateLocalTaggedEntity,
|
|
3467
3718
|
upsertEntity,
|
|
3468
3719
|
upsertLocalMutual,
|
|
3720
|
+
useAdjustEntity,
|
|
3469
3721
|
useConfig,
|
|
3722
|
+
useCreateEntity,
|
|
3723
|
+
useCreateMutual,
|
|
3724
|
+
useDeleteEntity,
|
|
3725
|
+
useDeleteMutual,
|
|
3726
|
+
useEditEntity,
|
|
3727
|
+
useEditMutual,
|
|
3470
3728
|
useEntities,
|
|
3471
3729
|
useEntity,
|
|
3472
3730
|
useEntityByUniqueField,
|
|
@@ -3475,6 +3733,7 @@ export {
|
|
|
3475
3733
|
useEntityState,
|
|
3476
3734
|
useEphemeralSocket,
|
|
3477
3735
|
useErrorStore,
|
|
3736
|
+
useExecuteTransaction,
|
|
3478
3737
|
useInterruptiveLoadStore,
|
|
3479
3738
|
useIsUnauthorized,
|
|
3480
3739
|
useLoadStore,
|
|
@@ -3483,6 +3742,7 @@ export {
|
|
|
3483
3742
|
useMutualSocket,
|
|
3484
3743
|
useMutuals,
|
|
3485
3744
|
useProfile,
|
|
3486
|
-
useTaggedEntities
|
|
3745
|
+
useTaggedEntities,
|
|
3746
|
+
useUpsertEntity
|
|
3487
3747
|
};
|
|
3488
3748
|
//# sourceMappingURL=index.js.map
|