monorise 1.1.0-dev.9 → 1.1.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/base/index.d.ts +54 -162
- package/dist/base/index.js +1 -51
- package/dist/base/index.js.map +1 -1
- package/dist/cli/cli.js +2 -8
- package/dist/cli/cli.js.map +1 -1
- package/dist/core/index.d.ts +60 -147
- package/dist/core/index.js +294 -1761
- package/dist/core/index.js.map +1 -1
- package/dist/react/actions/core.action.d.ts.map +1 -1
- package/dist/react/index.d.ts +4 -53
- package/dist/react/index.d.ts.map +1 -1
- package/dist/react/index.js +140 -624
- package/dist/react/index.js.map +1 -1
- package/dist/react/lib/entity.d.ts +1 -1
- package/dist/react/lib/entity.d.ts.map +1 -1
- package/dist/react/services/core.service.d.ts +1 -11
- package/dist/react/services/core.service.d.ts.map +1 -1
- package/dist/sst/components/monorise-core.d.ts +0 -12
- package/dist/sst/components/monorise-core.d.ts.map +1 -1
- package/dist/sst/components/single-table.d.ts +3 -3
- package/dist/sst/components/single-table.d.ts.map +1 -1
- package/dist/sst/index.js +13 -77
- package/dist/sst/index.js.map +1 -1
- package/package.json +6 -11
- package/dist/core/chunk-QV4Q5377.js +0 -76
- package/dist/core/chunk-QV4Q5377.js.map +0 -1
- package/dist/core/service.config-ZJEZ6EKA.js +0 -13
- package/dist/core/service.config-ZJEZ6EKA.js.map +0 -1
- package/dist/proxy/index.d.ts +0 -35
- package/dist/proxy/index.js +0 -75
- package/dist/proxy/index.js.map +0 -1
- package/dist/react/actions/websocket.action.d.ts +0 -71
- package/dist/react/actions/websocket.action.d.ts.map +0 -1
- package/dist/react/chunk-BIXAYYE4.js +0 -432
- package/dist/react/chunk-BIXAYYE4.js.map +0 -1
- package/dist/react/websocket/WebSocketManager.d.ts +0 -68
- package/dist/react/websocket/WebSocketManager.d.ts.map +0 -1
- package/dist/react/websocket/index.d.ts +0 -3
- package/dist/react/websocket/index.d.ts.map +0 -1
- package/dist/react/websocket/optimistic.d.ts +0 -51
- package/dist/react/websocket/optimistic.d.ts.map +0 -1
- package/dist/react/websocket-7MZ3ENOC.js +0 -9
- package/dist/react/websocket-7MZ3ENOC.js.map +0 -1
package/dist/react/index.js
CHANGED
|
@@ -1,9 +1,34 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
1
|
+
var __defProp = Object.defineProperty;
|
|
2
|
+
var __defProps = Object.defineProperties;
|
|
3
|
+
var __getOwnPropDescs = Object.getOwnPropertyDescriptors;
|
|
4
|
+
var __getOwnPropSymbols = Object.getOwnPropertySymbols;
|
|
5
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
6
|
+
var __propIsEnum = Object.prototype.propertyIsEnumerable;
|
|
7
|
+
var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
|
|
8
|
+
var __spreadValues = (a, b) => {
|
|
9
|
+
for (var prop in b || (b = {}))
|
|
10
|
+
if (__hasOwnProp.call(b, prop))
|
|
11
|
+
__defNormalProp(a, prop, b[prop]);
|
|
12
|
+
if (__getOwnPropSymbols)
|
|
13
|
+
for (var prop of __getOwnPropSymbols(b)) {
|
|
14
|
+
if (__propIsEnum.call(b, prop))
|
|
15
|
+
__defNormalProp(a, prop, b[prop]);
|
|
16
|
+
}
|
|
17
|
+
return a;
|
|
18
|
+
};
|
|
19
|
+
var __spreadProps = (a, b) => __defProps(a, __getOwnPropDescs(b));
|
|
20
|
+
var __objRest = (source, exclude) => {
|
|
21
|
+
var target = {};
|
|
22
|
+
for (var prop in source)
|
|
23
|
+
if (__hasOwnProp.call(source, prop) && exclude.indexOf(prop) < 0)
|
|
24
|
+
target[prop] = source[prop];
|
|
25
|
+
if (source != null && __getOwnPropSymbols)
|
|
26
|
+
for (var prop of __getOwnPropSymbols(source)) {
|
|
27
|
+
if (exclude.indexOf(prop) < 0 && __propIsEnum.call(source, prop))
|
|
28
|
+
target[prop] = source[prop];
|
|
29
|
+
}
|
|
30
|
+
return target;
|
|
31
|
+
};
|
|
7
32
|
|
|
8
33
|
// actions/app.action.ts
|
|
9
34
|
import { produce } from "immer";
|
|
@@ -289,13 +314,12 @@ var constructMutual = (byEntityType, byEntityId2, entityType, entityId, mutualDa
|
|
|
289
314
|
mutualUpdatedAt: (/* @__PURE__ */ new Date()).toISOString()
|
|
290
315
|
};
|
|
291
316
|
};
|
|
292
|
-
var flipMutual = (mutual
|
|
317
|
+
var flipMutual = (mutual) => {
|
|
293
318
|
return __spreadProps(__spreadValues({}, mutual), {
|
|
294
319
|
entityId: mutual.byEntityId,
|
|
295
320
|
entityType: mutual.byEntityType,
|
|
296
321
|
byEntityId: mutual.entityId,
|
|
297
|
-
byEntityType: mutual.entityType
|
|
298
|
-
data: byEntityData
|
|
322
|
+
byEntityType: mutual.entityType
|
|
299
323
|
});
|
|
300
324
|
};
|
|
301
325
|
var byEntityId = (a, b) => {
|
|
@@ -726,6 +750,61 @@ var initCoreActions = (monoriseStore, appActions, coreService2) => {
|
|
|
726
750
|
return { error };
|
|
727
751
|
}
|
|
728
752
|
};
|
|
753
|
+
const reconcileTaggedEntityStore = (state, entityType, id, data) => {
|
|
754
|
+
var _a;
|
|
755
|
+
const tagConfigs = (_a = state.config[entityType]) == null ? void 0 : _a.tags;
|
|
756
|
+
if (!tagConfigs) return;
|
|
757
|
+
for (const tagConfig of tagConfigs) {
|
|
758
|
+
const { name, processor } = tagConfig;
|
|
759
|
+
const processorResults = processor(data);
|
|
760
|
+
for (const tagKey of Object.keys(state.tag)) {
|
|
761
|
+
const [tagEntityType, tagName, ...paramParts] = tagKey.split("/");
|
|
762
|
+
if (tagEntityType !== entityType || tagName !== name) {
|
|
763
|
+
continue;
|
|
764
|
+
}
|
|
765
|
+
const slice = state.tag[tagKey];
|
|
766
|
+
if (!(slice == null ? void 0 : slice.dataMap)) {
|
|
767
|
+
continue;
|
|
768
|
+
}
|
|
769
|
+
const keyParams = {};
|
|
770
|
+
for (const part of paramParts) {
|
|
771
|
+
const colonIdx = part.indexOf(":");
|
|
772
|
+
if (colonIdx > 0) {
|
|
773
|
+
keyParams[part.substring(0, colonIdx)] = part.substring(
|
|
774
|
+
colonIdx + 1
|
|
775
|
+
);
|
|
776
|
+
}
|
|
777
|
+
}
|
|
778
|
+
if (keyParams.query) {
|
|
779
|
+
if (slice.dataMap.has(id)) {
|
|
780
|
+
slice.dataMap.set(id, data);
|
|
781
|
+
}
|
|
782
|
+
continue;
|
|
783
|
+
}
|
|
784
|
+
const matches = processorResults.some(
|
|
785
|
+
(result) => {
|
|
786
|
+
if (keyParams.group && result.group !== keyParams.group) {
|
|
787
|
+
return false;
|
|
788
|
+
}
|
|
789
|
+
if (keyParams.start && (!result.sortValue || result.sortValue < keyParams.start)) {
|
|
790
|
+
return false;
|
|
791
|
+
}
|
|
792
|
+
if (keyParams.end && (!result.sortValue || result.sortValue > keyParams.end)) {
|
|
793
|
+
return false;
|
|
794
|
+
}
|
|
795
|
+
return true;
|
|
796
|
+
}
|
|
797
|
+
);
|
|
798
|
+
if (matches) {
|
|
799
|
+
if (slice.isFirstFetched || slice.dataMap.has(id)) {
|
|
800
|
+
slice.dataMap.set(id, data);
|
|
801
|
+
}
|
|
802
|
+
} else if (slice.dataMap.has(id)) {
|
|
803
|
+
slice.dataMap.delete(id);
|
|
804
|
+
}
|
|
805
|
+
}
|
|
806
|
+
}
|
|
807
|
+
};
|
|
729
808
|
const editEntity2 = async (entityType, id, entity, opts = {}) => {
|
|
730
809
|
var _a;
|
|
731
810
|
const entityService = makeEntityService(entityType);
|
|
@@ -734,7 +813,6 @@ var initCoreActions = (monoriseStore, appActions, coreService2) => {
|
|
|
734
813
|
const { data } = await entityService.editEntity(id, entity, opts);
|
|
735
814
|
monoriseStore.setState(
|
|
736
815
|
produce4((state) => {
|
|
737
|
-
var _a2, _b;
|
|
738
816
|
state.entity[entityType].dataMap.set(data.entityId, data);
|
|
739
817
|
for (const key of Object.keys(state.mutual)) {
|
|
740
818
|
const [_byEntity, _byId, _entityType] = key.split("/");
|
|
@@ -757,14 +835,12 @@ var initCoreActions = (monoriseStore, appActions, coreService2) => {
|
|
|
757
835
|
state.mutual[key].dataMap = newDataMap;
|
|
758
836
|
}
|
|
759
837
|
}
|
|
760
|
-
|
|
761
|
-
|
|
762
|
-
|
|
763
|
-
|
|
764
|
-
|
|
765
|
-
|
|
766
|
-
}
|
|
767
|
-
}
|
|
838
|
+
reconcileTaggedEntityStore(
|
|
839
|
+
state,
|
|
840
|
+
entityType,
|
|
841
|
+
id,
|
|
842
|
+
data
|
|
843
|
+
);
|
|
768
844
|
}),
|
|
769
845
|
void 0,
|
|
770
846
|
`mr/entity/edit/${entityType}/${id}`
|
|
@@ -784,7 +860,6 @@ var initCoreActions = (monoriseStore, appActions, coreService2) => {
|
|
|
784
860
|
const { data } = await entityService.adjustEntity(id, adjustments, opts);
|
|
785
861
|
monoriseStore.setState(
|
|
786
862
|
produce4((state) => {
|
|
787
|
-
var _a2, _b2;
|
|
788
863
|
state.entity[entityType].dataMap.set(data.entityId, data);
|
|
789
864
|
for (const key of Object.keys(state.mutual)) {
|
|
790
865
|
const [_byEntity, _byId, _entityType] = key.split("/");
|
|
@@ -807,14 +882,12 @@ var initCoreActions = (monoriseStore, appActions, coreService2) => {
|
|
|
807
882
|
state.mutual[key].dataMap = newDataMap;
|
|
808
883
|
}
|
|
809
884
|
}
|
|
810
|
-
|
|
811
|
-
|
|
812
|
-
|
|
813
|
-
|
|
814
|
-
|
|
815
|
-
|
|
816
|
-
}
|
|
817
|
-
}
|
|
885
|
+
reconcileTaggedEntityStore(
|
|
886
|
+
state,
|
|
887
|
+
entityType,
|
|
888
|
+
id,
|
|
889
|
+
data
|
|
890
|
+
);
|
|
818
891
|
}),
|
|
819
892
|
void 0,
|
|
820
893
|
`mr/entity/adjust/${entityType}/${id}`
|
|
@@ -1038,7 +1111,7 @@ var initCoreActions = (monoriseStore, appActions, coreService2) => {
|
|
|
1038
1111
|
);
|
|
1039
1112
|
monoriseStore.setState(
|
|
1040
1113
|
produce4((state) => {
|
|
1041
|
-
var _a2, _b
|
|
1114
|
+
var _a2, _b;
|
|
1042
1115
|
const bySide = getMutualStateKey(
|
|
1043
1116
|
byEntityType,
|
|
1044
1117
|
byEntityId2,
|
|
@@ -1058,10 +1131,9 @@ var initCoreActions = (monoriseStore, appActions, coreService2) => {
|
|
|
1058
1131
|
dataMap: /* @__PURE__ */ new Map()
|
|
1059
1132
|
};
|
|
1060
1133
|
}
|
|
1061
|
-
|
|
1062
|
-
state.mutual[side].dataMap = new Map((_e = state.mutual[side]) == null ? void 0 : _e.dataMap).set(
|
|
1134
|
+
state.mutual[side].dataMap = new Map((_b = state.mutual[side]) == null ? void 0 : _b.dataMap).set(
|
|
1063
1135
|
mutual.byEntityId,
|
|
1064
|
-
flipMutual(mutual
|
|
1136
|
+
flipMutual(mutual)
|
|
1065
1137
|
);
|
|
1066
1138
|
}),
|
|
1067
1139
|
void 0,
|
|
@@ -1085,7 +1157,7 @@ var initCoreActions = (monoriseStore, appActions, coreService2) => {
|
|
|
1085
1157
|
);
|
|
1086
1158
|
monoriseStore.setState(
|
|
1087
1159
|
produce4((state) => {
|
|
1088
|
-
var _a, _b
|
|
1160
|
+
var _a, _b;
|
|
1089
1161
|
const bySide = getMutualStateKey(byEntityType, byEntityId2, entityType);
|
|
1090
1162
|
const side = getMutualStateKey(entityType, entityId, byEntityType);
|
|
1091
1163
|
if (!state.mutual[bySide]) {
|
|
@@ -1101,10 +1173,9 @@ var initCoreActions = (monoriseStore, appActions, coreService2) => {
|
|
|
1101
1173
|
dataMap: /* @__PURE__ */ new Map()
|
|
1102
1174
|
};
|
|
1103
1175
|
}
|
|
1104
|
-
|
|
1105
|
-
state.mutual[side].dataMap = new Map((_e = state.mutual[side]) == null ? void 0 : _e.dataMap).set(
|
|
1176
|
+
state.mutual[side].dataMap = new Map((_b = state.mutual[side]) == null ? void 0 : _b.dataMap).set(
|
|
1106
1177
|
mutual.byEntityId,
|
|
1107
|
-
flipMutual(mutual
|
|
1178
|
+
flipMutual(mutual)
|
|
1108
1179
|
);
|
|
1109
1180
|
}),
|
|
1110
1181
|
void 0,
|
|
@@ -1132,7 +1203,7 @@ var initCoreActions = (monoriseStore, appActions, coreService2) => {
|
|
|
1132
1203
|
);
|
|
1133
1204
|
monoriseStore.setState(
|
|
1134
1205
|
produce4((state) => {
|
|
1135
|
-
var _a, _b
|
|
1206
|
+
var _a, _b;
|
|
1136
1207
|
const bySide = getMutualStateKey(byEntityType, byEntityId2, entityType);
|
|
1137
1208
|
const side = getMutualStateKey(entityType, entityId, byEntityType);
|
|
1138
1209
|
if (!state.mutual[bySide]) {
|
|
@@ -1148,10 +1219,9 @@ var initCoreActions = (monoriseStore, appActions, coreService2) => {
|
|
|
1148
1219
|
dataMap: /* @__PURE__ */ new Map()
|
|
1149
1220
|
};
|
|
1150
1221
|
}
|
|
1151
|
-
|
|
1152
|
-
state.mutual[side].dataMap = new Map((_e = state.mutual[side]) == null ? void 0 : _e.dataMap).set(
|
|
1222
|
+
state.mutual[side].dataMap = new Map((_b = state.mutual[side]) == null ? void 0 : _b.dataMap).set(
|
|
1153
1223
|
byEntityId2,
|
|
1154
|
-
flipMutual(mutual
|
|
1224
|
+
flipMutual(mutual)
|
|
1155
1225
|
);
|
|
1156
1226
|
}),
|
|
1157
1227
|
void 0,
|
|
@@ -1171,7 +1241,7 @@ var initCoreActions = (monoriseStore, appActions, coreService2) => {
|
|
|
1171
1241
|
);
|
|
1172
1242
|
monoriseStore.setState(
|
|
1173
1243
|
produce4((state) => {
|
|
1174
|
-
var _a2, _b
|
|
1244
|
+
var _a2, _b;
|
|
1175
1245
|
const bySide = getMutualStateKey(
|
|
1176
1246
|
byEntityType,
|
|
1177
1247
|
byEntityId2,
|
|
@@ -1191,10 +1261,9 @@ var initCoreActions = (monoriseStore, appActions, coreService2) => {
|
|
|
1191
1261
|
dataMap: /* @__PURE__ */ new Map()
|
|
1192
1262
|
};
|
|
1193
1263
|
}
|
|
1194
|
-
|
|
1195
|
-
state.mutual[side].dataMap = new Map((_e = state.mutual[side]) == null ? void 0 : _e.dataMap).set(
|
|
1264
|
+
state.mutual[side].dataMap = new Map((_b = state.mutual[side]) == null ? void 0 : _b.dataMap).set(
|
|
1196
1265
|
mutual.byEntityId,
|
|
1197
|
-
flipMutual(mutual
|
|
1266
|
+
flipMutual(mutual)
|
|
1198
1267
|
);
|
|
1199
1268
|
}),
|
|
1200
1269
|
void 0,
|
|
@@ -1435,16 +1504,11 @@ var initCoreActions = (monoriseStore, appActions, coreService2) => {
|
|
|
1435
1504
|
return () => queryTimeout && clearTimeout(queryTimeout);
|
|
1436
1505
|
}, [entityType, query]);
|
|
1437
1506
|
useEffect2(() => {
|
|
1438
|
-
if (!query) {
|
|
1439
|
-
|
|
1440
|
-
|
|
1507
|
+
if (!query && dataMap.size !== (entities == null ? void 0 : entities.length)) {
|
|
1508
|
+
setIsSearching(false);
|
|
1509
|
+
setEntities(
|
|
1510
|
+
Array.from(dataMap.values()).sort(byEntityId)
|
|
1441
1511
|
);
|
|
1442
|
-
if (dataMap.size !== (entities == null ? void 0 : entities.length) || dataMapArray.some(
|
|
1443
|
-
(item, index) => JSON.stringify(item) !== JSON.stringify(entities == null ? void 0 : entities[index])
|
|
1444
|
-
)) {
|
|
1445
|
-
setIsSearching(false);
|
|
1446
|
-
setEntities(dataMapArray);
|
|
1447
|
-
}
|
|
1448
1512
|
}
|
|
1449
1513
|
if (query) {
|
|
1450
1514
|
setEntities(searchResults);
|
|
@@ -1452,7 +1516,6 @@ var initCoreActions = (monoriseStore, appActions, coreService2) => {
|
|
|
1452
1516
|
}, [
|
|
1453
1517
|
dataMap,
|
|
1454
1518
|
dataMap.size,
|
|
1455
|
-
entities,
|
|
1456
1519
|
entities == null ? void 0 : entities.length,
|
|
1457
1520
|
query,
|
|
1458
1521
|
searchResults,
|
|
@@ -1615,6 +1678,20 @@ var initCoreActions = (monoriseStore, appActions, coreService2) => {
|
|
|
1615
1678
|
}
|
|
1616
1679
|
});
|
|
1617
1680
|
};
|
|
1681
|
+
const sortTaggedEntitiesLikeServer = (arr, entityType, tagName, group) => {
|
|
1682
|
+
var _a, _b;
|
|
1683
|
+
const tagConfig = (_b = (_a = monoriseStore.getState().config[entityType]) == null ? void 0 : _a.tags) == null ? void 0 : _b.find((t) => t.name === tagName);
|
|
1684
|
+
const keyOf = (entity) => {
|
|
1685
|
+
let sortValue;
|
|
1686
|
+
if (tagConfig == null ? void 0 : tagConfig.processor) {
|
|
1687
|
+
const results = tagConfig.processor(entity);
|
|
1688
|
+
const match = group ? results.find((r) => r.group === group) : results[0];
|
|
1689
|
+
sortValue = match == null ? void 0 : match.sortValue;
|
|
1690
|
+
}
|
|
1691
|
+
return `${sortValue ? `${sortValue}#` : ""}${entityType}#${entity.entityId}`;
|
|
1692
|
+
};
|
|
1693
|
+
return arr.map((entity) => ({ entity, key: keyOf(entity) })).sort((a, b) => a.key === b.key ? 0 : a.key < b.key ? 1 : -1).map((x) => x.entity);
|
|
1694
|
+
};
|
|
1618
1695
|
const useTaggedEntities2 = (entityType, tagName, opts = {}) => {
|
|
1619
1696
|
const { params } = opts || {};
|
|
1620
1697
|
const stateKey = getTagStateKey(entityType, tagName, params);
|
|
@@ -1632,7 +1709,12 @@ var initCoreActions = (monoriseStore, appActions, coreService2) => {
|
|
|
1632
1709
|
}
|
|
1633
1710
|
}, [entityType, opts, tagName, params, opts == null ? void 0 : opts.forceFetch]);
|
|
1634
1711
|
useEffect2(() => {
|
|
1635
|
-
const dataMapArray =
|
|
1712
|
+
const dataMapArray = sortTaggedEntitiesLikeServer(
|
|
1713
|
+
Array.from(dataMap.values()),
|
|
1714
|
+
entityType,
|
|
1715
|
+
tagName,
|
|
1716
|
+
params == null ? void 0 : params.group
|
|
1717
|
+
);
|
|
1636
1718
|
if (dataMap.size !== (entities == null ? void 0 : entities.length) || dataMapArray.some(
|
|
1637
1719
|
(item, index) => JSON.stringify(item) !== JSON.stringify(entities[index])
|
|
1638
1720
|
)) {
|
|
@@ -1732,539 +1814,6 @@ var initCoreActions = (monoriseStore, appActions, coreService2) => {
|
|
|
1732
1814
|
};
|
|
1733
1815
|
};
|
|
1734
1816
|
|
|
1735
|
-
// actions/websocket.action.ts
|
|
1736
|
-
import { useCallback, useEffect as useEffect3, useRef, useState as useState3 } from "react";
|
|
1737
|
-
import { produce as produce5 } from "immer";
|
|
1738
|
-
var globalWsManager = null;
|
|
1739
|
-
var wsEndpoint;
|
|
1740
|
-
var initializeWebSocketManager = (WebSocketManagerClass, endpoint, token) => {
|
|
1741
|
-
if (globalWsManager) return globalWsManager;
|
|
1742
|
-
wsEndpoint = endpoint;
|
|
1743
|
-
globalWsManager = new WebSocketManagerClass(endpoint, token || "");
|
|
1744
|
-
globalWsManager.connect();
|
|
1745
|
-
return globalWsManager;
|
|
1746
|
-
};
|
|
1747
|
-
var getWebSocketManager = () => globalWsManager;
|
|
1748
|
-
var initWebSocketActions = (monoriseStore, httpActions) => {
|
|
1749
|
-
const useEntitySocket2 = (entityType, opts = {}) => {
|
|
1750
|
-
const { limit = 20, skipInitialFetch = false } = opts;
|
|
1751
|
-
const [isLoading, setIsLoading] = useState3(!skipInitialFetch);
|
|
1752
|
-
const [isFetchingMore, setIsFetchingMore] = useState3(false);
|
|
1753
|
-
const [isRefreshing, setIsRefreshing] = useState3(false);
|
|
1754
|
-
const [isSubscribed, setIsSubscribed] = useState3(false);
|
|
1755
|
-
const [error, setError2] = useState3(null);
|
|
1756
|
-
const [hasMore, setHasMore] = useState3(true);
|
|
1757
|
-
const lastKeyRef = useRef(void 0);
|
|
1758
|
-
const isFirstFetchRef = useRef(true);
|
|
1759
|
-
const entities = monoriseStore((state) => {
|
|
1760
|
-
var _a;
|
|
1761
|
-
const entityState = state.entity[entityType];
|
|
1762
|
-
return Array.from(((_a = entityState == null ? void 0 : entityState.dataMap) == null ? void 0 : _a.values()) || []);
|
|
1763
|
-
});
|
|
1764
|
-
const fetchData = async (type) => {
|
|
1765
|
-
if (!httpActions) return;
|
|
1766
|
-
if (type === "more") {
|
|
1767
|
-
setIsFetchingMore(true);
|
|
1768
|
-
} else if (type === "refresh") {
|
|
1769
|
-
setIsRefreshing(true);
|
|
1770
|
-
} else {
|
|
1771
|
-
setIsLoading(true);
|
|
1772
|
-
}
|
|
1773
|
-
setError2(null);
|
|
1774
|
-
try {
|
|
1775
|
-
const fetchLastKey = type === "refresh" ? void 0 : lastKeyRef.current;
|
|
1776
|
-
const result = await httpActions.listEntities(entityType, {
|
|
1777
|
-
limit,
|
|
1778
|
-
lastKey: fetchLastKey
|
|
1779
|
-
});
|
|
1780
|
-
monoriseStore.setState(
|
|
1781
|
-
produce5((state) => {
|
|
1782
|
-
if (type === "refresh") {
|
|
1783
|
-
state.entity[entityType].dataMap.clear();
|
|
1784
|
-
}
|
|
1785
|
-
for (const entity of result.data) {
|
|
1786
|
-
state.entity[entityType].dataMap.set(entity.entityId, entity);
|
|
1787
|
-
}
|
|
1788
|
-
state.entity[entityType].isFirstFetched = true;
|
|
1789
|
-
state.entity[entityType].lastKey = result.lastKey;
|
|
1790
|
-
})
|
|
1791
|
-
);
|
|
1792
|
-
lastKeyRef.current = result.lastKey;
|
|
1793
|
-
setHasMore(!!result.lastKey);
|
|
1794
|
-
} catch (err) {
|
|
1795
|
-
setError2(err instanceof Error ? err : new Error("Failed to fetch"));
|
|
1796
|
-
} finally {
|
|
1797
|
-
setIsLoading(false);
|
|
1798
|
-
setIsFetchingMore(false);
|
|
1799
|
-
setIsRefreshing(false);
|
|
1800
|
-
}
|
|
1801
|
-
};
|
|
1802
|
-
useEffect3(() => {
|
|
1803
|
-
if (skipInitialFetch) return;
|
|
1804
|
-
fetchData("initial");
|
|
1805
|
-
}, [entityType, limit, skipInitialFetch]);
|
|
1806
|
-
useEffect3(() => {
|
|
1807
|
-
if (!globalWsManager) {
|
|
1808
|
-
setIsSubscribed(false);
|
|
1809
|
-
return;
|
|
1810
|
-
}
|
|
1811
|
-
const subKey = globalWsManager.subscribeEntityType(entityType);
|
|
1812
|
-
setIsSubscribed(true);
|
|
1813
|
-
let wasConnected = false;
|
|
1814
|
-
const unsubscribeState = globalWsManager.onStateChange((state) => {
|
|
1815
|
-
if (state === "connected" && wasConnected === false && !isFirstFetchRef.current) {
|
|
1816
|
-
fetchData("refresh");
|
|
1817
|
-
}
|
|
1818
|
-
wasConnected = state === "connected";
|
|
1819
|
-
isFirstFetchRef.current = false;
|
|
1820
|
-
});
|
|
1821
|
-
const unsubscribeMessage = globalWsManager.onMessage(
|
|
1822
|
-
(msg) => {
|
|
1823
|
-
if (msg.type === "entity.created" || msg.type === "entity.updated" || msg.type === "entity.deleted") {
|
|
1824
|
-
const payload = msg.payload;
|
|
1825
|
-
if (payload.entityType !== entityType) return;
|
|
1826
|
-
if (msg.type === "entity.created" || msg.type === "entity.updated") {
|
|
1827
|
-
if (payload.data) {
|
|
1828
|
-
monoriseStore.setState(
|
|
1829
|
-
produce5((state) => {
|
|
1830
|
-
const key = entityType;
|
|
1831
|
-
if (!state.entity[key]) {
|
|
1832
|
-
state.entity[key] = { dataMap: /* @__PURE__ */ new Map(), isFirstFetched: false, lastKey: void 0 };
|
|
1833
|
-
}
|
|
1834
|
-
state.entity[key].dataMap.set(
|
|
1835
|
-
payload.entityId,
|
|
1836
|
-
payload.data
|
|
1837
|
-
);
|
|
1838
|
-
})
|
|
1839
|
-
);
|
|
1840
|
-
}
|
|
1841
|
-
} else if (msg.type === "entity.deleted") {
|
|
1842
|
-
monoriseStore.setState(
|
|
1843
|
-
produce5((state) => {
|
|
1844
|
-
var _a;
|
|
1845
|
-
const key = entityType;
|
|
1846
|
-
if ((_a = state.entity[key]) == null ? void 0 : _a.dataMap) {
|
|
1847
|
-
state.entity[key].dataMap.delete(payload.entityId);
|
|
1848
|
-
}
|
|
1849
|
-
})
|
|
1850
|
-
);
|
|
1851
|
-
}
|
|
1852
|
-
}
|
|
1853
|
-
}
|
|
1854
|
-
);
|
|
1855
|
-
return () => {
|
|
1856
|
-
globalWsManager == null ? void 0 : globalWsManager.unsubscribeEntityType(subKey);
|
|
1857
|
-
unsubscribeState();
|
|
1858
|
-
unsubscribeMessage();
|
|
1859
|
-
setIsSubscribed(false);
|
|
1860
|
-
};
|
|
1861
|
-
}, [entityType]);
|
|
1862
|
-
const fetchMore = async () => {
|
|
1863
|
-
if (!hasMore || isFetchingMore) return;
|
|
1864
|
-
await fetchData("more");
|
|
1865
|
-
};
|
|
1866
|
-
return {
|
|
1867
|
-
entities,
|
|
1868
|
-
isLoading,
|
|
1869
|
-
isFetchingMore,
|
|
1870
|
-
isSubscribed,
|
|
1871
|
-
error,
|
|
1872
|
-
isRefreshing,
|
|
1873
|
-
fetchMore,
|
|
1874
|
-
hasMore
|
|
1875
|
-
};
|
|
1876
|
-
};
|
|
1877
|
-
const useMutualSocket2 = (byEntityType, byEntityId2, mutualEntityType, opts = {}) => {
|
|
1878
|
-
const { limit = 20, skipInitialFetch = false } = opts;
|
|
1879
|
-
const [isLoading, setIsLoading] = useState3(
|
|
1880
|
-
!skipInitialFetch && !!byEntityId2
|
|
1881
|
-
);
|
|
1882
|
-
const [isFetchingMore, setIsFetchingMore] = useState3(false);
|
|
1883
|
-
const [isRefreshing, setIsRefreshing] = useState3(false);
|
|
1884
|
-
const [isSubscribed, setIsSubscribed] = useState3(false);
|
|
1885
|
-
const [error, setError2] = useState3(null);
|
|
1886
|
-
const [hasMore, setHasMore] = useState3(true);
|
|
1887
|
-
const lastKeyRef = useRef(void 0);
|
|
1888
|
-
const isFirstFetchRef = useRef(true);
|
|
1889
|
-
const mutualKey = byEntityId2 ? `${byEntityType}/${byEntityId2}/${mutualEntityType}` : "";
|
|
1890
|
-
const mutuals = monoriseStore((state) => {
|
|
1891
|
-
var _a, _b;
|
|
1892
|
-
return Array.from(((_b = (_a = state.mutual[mutualKey]) == null ? void 0 : _a.dataMap) == null ? void 0 : _b.values()) || []);
|
|
1893
|
-
});
|
|
1894
|
-
const fetchData = async (type) => {
|
|
1895
|
-
if (!byEntityId2 || !httpActions) return;
|
|
1896
|
-
if (type === "more") {
|
|
1897
|
-
setIsFetchingMore(true);
|
|
1898
|
-
} else if (type === "refresh") {
|
|
1899
|
-
setIsRefreshing(true);
|
|
1900
|
-
} else {
|
|
1901
|
-
setIsLoading(true);
|
|
1902
|
-
}
|
|
1903
|
-
setError2(null);
|
|
1904
|
-
try {
|
|
1905
|
-
const fetchLastKey = type === "refresh" ? void 0 : lastKeyRef.current;
|
|
1906
|
-
const result = await httpActions.listEntitiesByEntity(
|
|
1907
|
-
byEntityType,
|
|
1908
|
-
byEntityId2,
|
|
1909
|
-
mutualEntityType,
|
|
1910
|
-
{ limit, lastKey: fetchLastKey }
|
|
1911
|
-
);
|
|
1912
|
-
monoriseStore.setState(
|
|
1913
|
-
produce5((state) => {
|
|
1914
|
-
if (!state.mutual[mutualKey]) {
|
|
1915
|
-
state.mutual[mutualKey] = {
|
|
1916
|
-
dataMap: /* @__PURE__ */ new Map(),
|
|
1917
|
-
isFirstFetched: true,
|
|
1918
|
-
lastKey: void 0
|
|
1919
|
-
};
|
|
1920
|
-
}
|
|
1921
|
-
if (type === "refresh") {
|
|
1922
|
-
state.mutual[mutualKey].dataMap.clear();
|
|
1923
|
-
}
|
|
1924
|
-
for (const entity of result.entities) {
|
|
1925
|
-
const e = entity;
|
|
1926
|
-
state.mutual[mutualKey].dataMap.set(e.entityId, entity);
|
|
1927
|
-
}
|
|
1928
|
-
state.mutual[mutualKey].lastKey = result.lastKey;
|
|
1929
|
-
})
|
|
1930
|
-
);
|
|
1931
|
-
lastKeyRef.current = result.lastKey;
|
|
1932
|
-
setHasMore(!!result.lastKey);
|
|
1933
|
-
} catch (err) {
|
|
1934
|
-
setError2(err instanceof Error ? err : new Error("Failed to fetch"));
|
|
1935
|
-
} finally {
|
|
1936
|
-
setIsLoading(false);
|
|
1937
|
-
setIsFetchingMore(false);
|
|
1938
|
-
setIsRefreshing(false);
|
|
1939
|
-
}
|
|
1940
|
-
};
|
|
1941
|
-
useEffect3(() => {
|
|
1942
|
-
if (skipInitialFetch || !byEntityId2) {
|
|
1943
|
-
setIsLoading(false);
|
|
1944
|
-
return;
|
|
1945
|
-
}
|
|
1946
|
-
lastKeyRef.current = void 0;
|
|
1947
|
-
setHasMore(true);
|
|
1948
|
-
isFirstFetchRef.current = true;
|
|
1949
|
-
fetchData("initial");
|
|
1950
|
-
}, [byEntityType, byEntityId2, mutualEntityType, limit, skipInitialFetch]);
|
|
1951
|
-
useEffect3(() => {
|
|
1952
|
-
if (!globalWsManager || !byEntityId2) {
|
|
1953
|
-
setIsSubscribed(false);
|
|
1954
|
-
return;
|
|
1955
|
-
}
|
|
1956
|
-
const subKey = globalWsManager.subscribeMutualType(
|
|
1957
|
-
byEntityType,
|
|
1958
|
-
byEntityId2,
|
|
1959
|
-
mutualEntityType
|
|
1960
|
-
);
|
|
1961
|
-
setIsSubscribed(true);
|
|
1962
|
-
let wasConnected = false;
|
|
1963
|
-
const unsubscribeState = globalWsManager.onStateChange((state) => {
|
|
1964
|
-
if (state === "connected" && wasConnected === false && !isFirstFetchRef.current) {
|
|
1965
|
-
fetchData("refresh");
|
|
1966
|
-
}
|
|
1967
|
-
wasConnected = state === "connected";
|
|
1968
|
-
isFirstFetchRef.current = false;
|
|
1969
|
-
});
|
|
1970
|
-
const unsubscribeMessage = globalWsManager.onMessage(
|
|
1971
|
-
(msg) => {
|
|
1972
|
-
if (msg.type === "mutual.created" || msg.type === "mutual.updated" || msg.type === "mutual.deleted") {
|
|
1973
|
-
const payload = msg.payload;
|
|
1974
|
-
if (payload.byEntityType !== byEntityType || payload.byEntityId !== byEntityId2 || payload.mutualEntityType !== mutualEntityType) {
|
|
1975
|
-
return;
|
|
1976
|
-
}
|
|
1977
|
-
if (msg.type === "mutual.created" || msg.type === "mutual.updated") {
|
|
1978
|
-
if (payload.data) {
|
|
1979
|
-
monoriseStore.setState(
|
|
1980
|
-
produce5((state) => {
|
|
1981
|
-
if (!state.mutual[mutualKey]) {
|
|
1982
|
-
state.mutual[mutualKey] = {
|
|
1983
|
-
dataMap: /* @__PURE__ */ new Map(),
|
|
1984
|
-
isFirstFetched: true,
|
|
1985
|
-
lastKey: void 0
|
|
1986
|
-
};
|
|
1987
|
-
}
|
|
1988
|
-
state.mutual[mutualKey].dataMap.set(
|
|
1989
|
-
payload.entityId,
|
|
1990
|
-
payload.data
|
|
1991
|
-
);
|
|
1992
|
-
})
|
|
1993
|
-
);
|
|
1994
|
-
}
|
|
1995
|
-
} else if (msg.type === "mutual.deleted") {
|
|
1996
|
-
monoriseStore.setState(
|
|
1997
|
-
produce5((state) => {
|
|
1998
|
-
var _a;
|
|
1999
|
-
(_a = state.mutual[mutualKey]) == null ? void 0 : _a.dataMap.delete(payload.entityId);
|
|
2000
|
-
})
|
|
2001
|
-
);
|
|
2002
|
-
}
|
|
2003
|
-
}
|
|
2004
|
-
}
|
|
2005
|
-
);
|
|
2006
|
-
return () => {
|
|
2007
|
-
globalWsManager == null ? void 0 : globalWsManager.unsubscribeMutualType(subKey);
|
|
2008
|
-
unsubscribeState();
|
|
2009
|
-
unsubscribeMessage();
|
|
2010
|
-
setIsSubscribed(false);
|
|
2011
|
-
};
|
|
2012
|
-
}, [byEntityType, byEntityId2, mutualEntityType, mutualKey]);
|
|
2013
|
-
const fetchMore = async () => {
|
|
2014
|
-
if (!hasMore || isFetchingMore) return;
|
|
2015
|
-
await fetchData("more");
|
|
2016
|
-
};
|
|
2017
|
-
return {
|
|
2018
|
-
mutuals,
|
|
2019
|
-
isLoading,
|
|
2020
|
-
isFetchingMore,
|
|
2021
|
-
isSubscribed,
|
|
2022
|
-
error,
|
|
2023
|
-
isRefreshing,
|
|
2024
|
-
fetchMore,
|
|
2025
|
-
hasMore
|
|
2026
|
-
};
|
|
2027
|
-
};
|
|
2028
|
-
const useEphemeralSocket2 = (channel, opts) => {
|
|
2029
|
-
const [isSubscribed, setIsSubscribed] = useState3(false);
|
|
2030
|
-
useEffect3(() => {
|
|
2031
|
-
if (!globalWsManager || !channel) {
|
|
2032
|
-
setIsSubscribed(false);
|
|
2033
|
-
return;
|
|
2034
|
-
}
|
|
2035
|
-
const subKey = globalWsManager.subscribeEphemeral(channel);
|
|
2036
|
-
setIsSubscribed(true);
|
|
2037
|
-
const unsubscribeMessage = globalWsManager.onMessage(
|
|
2038
|
-
(msg) => {
|
|
2039
|
-
var _a;
|
|
2040
|
-
if (msg.type === "ephemeral") {
|
|
2041
|
-
const payload = msg.payload;
|
|
2042
|
-
if (payload.channel !== channel) return;
|
|
2043
|
-
(_a = opts == null ? void 0 : opts.onMessage) == null ? void 0 : _a.call(opts, payload.data, payload.senderId);
|
|
2044
|
-
}
|
|
2045
|
-
}
|
|
2046
|
-
);
|
|
2047
|
-
return () => {
|
|
2048
|
-
globalWsManager == null ? void 0 : globalWsManager.unsubscribeEphemeral(subKey);
|
|
2049
|
-
unsubscribeMessage();
|
|
2050
|
-
setIsSubscribed(false);
|
|
2051
|
-
};
|
|
2052
|
-
}, [channel]);
|
|
2053
|
-
const send = useCallback(
|
|
2054
|
-
(data) => {
|
|
2055
|
-
if (!globalWsManager || !channel) return;
|
|
2056
|
-
globalWsManager.sendEphemeral(channel, data);
|
|
2057
|
-
},
|
|
2058
|
-
[channel]
|
|
2059
|
-
);
|
|
2060
|
-
return { isSubscribed, send };
|
|
2061
|
-
};
|
|
2062
|
-
const useEntityFeed2 = (opts) => {
|
|
2063
|
-
const { entityType, entityId, ticketEndpoint } = opts;
|
|
2064
|
-
const [isConnected, setIsConnected] = useState3(false);
|
|
2065
|
-
const [error, setError2] = useState3(null);
|
|
2066
|
-
const refreshTimerRef = useRef(null);
|
|
2067
|
-
const wsManagerRef = useRef(null);
|
|
2068
|
-
const isMountedRef = useRef(true);
|
|
2069
|
-
const connectingRef = useRef(false);
|
|
2070
|
-
const reconnectCountRef = useRef(0);
|
|
2071
|
-
const connectRef = useRef(() => {
|
|
2072
|
-
});
|
|
2073
|
-
const lastConnectedAtRef = useRef(0);
|
|
2074
|
-
const fetchTicket = useCallback(async () => {
|
|
2075
|
-
try {
|
|
2076
|
-
const url = ticketEndpoint || `/api/core/ws/ticket/${entityType}/${entityId}`;
|
|
2077
|
-
const fetchOpts = {
|
|
2078
|
-
method: "POST",
|
|
2079
|
-
headers: { "Content-Type": "application/json" }
|
|
2080
|
-
};
|
|
2081
|
-
if (ticketEndpoint) {
|
|
2082
|
-
fetchOpts.body = JSON.stringify({ entityType, entityId });
|
|
2083
|
-
}
|
|
2084
|
-
const response = await fetch(url, fetchOpts);
|
|
2085
|
-
if (response.status === 401 || response.status === 403) {
|
|
2086
|
-
return { error: { code: "TICKET_UNAUTHORIZED", message: "Unauthorized" } };
|
|
2087
|
-
}
|
|
2088
|
-
if (!response.ok) {
|
|
2089
|
-
return { error: { code: "TICKET_FAILED", message: `HTTP ${response.status}` } };
|
|
2090
|
-
}
|
|
2091
|
-
const data = await response.json();
|
|
2092
|
-
return { data };
|
|
2093
|
-
} catch (err) {
|
|
2094
|
-
return { error: { code: "TICKET_FAILED", message: err.message } };
|
|
2095
|
-
}
|
|
2096
|
-
}, [entityType, entityId, ticketEndpoint]);
|
|
2097
|
-
const connectWithTicket = useCallback(async () => {
|
|
2098
|
-
if (connectingRef.current) return;
|
|
2099
|
-
connectingRef.current = true;
|
|
2100
|
-
let result = null;
|
|
2101
|
-
const maxRetries = 3;
|
|
2102
|
-
for (let attempt = 0; attempt <= maxRetries; attempt++) {
|
|
2103
|
-
result = await fetchTicket();
|
|
2104
|
-
if (!isMountedRef.current) {
|
|
2105
|
-
connectingRef.current = false;
|
|
2106
|
-
return;
|
|
2107
|
-
}
|
|
2108
|
-
if (!result.error) break;
|
|
2109
|
-
if (result.error.code === "TICKET_UNAUTHORIZED") break;
|
|
2110
|
-
if (attempt < maxRetries) {
|
|
2111
|
-
await new Promise((r) => setTimeout(r, 1e3 * Math.pow(2, attempt)));
|
|
2112
|
-
if (!isMountedRef.current) {
|
|
2113
|
-
connectingRef.current = false;
|
|
2114
|
-
return;
|
|
2115
|
-
}
|
|
2116
|
-
}
|
|
2117
|
-
}
|
|
2118
|
-
if (result.error) {
|
|
2119
|
-
setError2(result.error);
|
|
2120
|
-
setIsConnected(false);
|
|
2121
|
-
connectingRef.current = false;
|
|
2122
|
-
return;
|
|
2123
|
-
}
|
|
2124
|
-
setError2(null);
|
|
2125
|
-
const { ticket, wsUrl, expiresIn } = result.data;
|
|
2126
|
-
if (wsManagerRef.current) {
|
|
2127
|
-
wsManagerRef.current.disconnect();
|
|
2128
|
-
}
|
|
2129
|
-
const { WebSocketManager: WsManagerClass } = await import("./websocket-7MZ3ENOC.js");
|
|
2130
|
-
const wsUrlWithTicket = `${wsUrl}?ticket=${encodeURIComponent(ticket)}`;
|
|
2131
|
-
const manager = new WsManagerClass(wsUrlWithTicket, "");
|
|
2132
|
-
manager.disableAutoReconnect = true;
|
|
2133
|
-
wsManagerRef.current = manager;
|
|
2134
|
-
globalWsManager = manager;
|
|
2135
|
-
manager.onStateChange((state) => {
|
|
2136
|
-
if (!isMountedRef.current) return;
|
|
2137
|
-
if (wsManagerRef.current !== manager) return;
|
|
2138
|
-
if (state === "connected") {
|
|
2139
|
-
connectingRef.current = false;
|
|
2140
|
-
reconnectCountRef.current = 0;
|
|
2141
|
-
lastConnectedAtRef.current = Date.now();
|
|
2142
|
-
setIsConnected(true);
|
|
2143
|
-
setError2(null);
|
|
2144
|
-
} else if (state === "disconnected") {
|
|
2145
|
-
connectingRef.current = false;
|
|
2146
|
-
setIsConnected(false);
|
|
2147
|
-
const wasStable = Date.now() - lastConnectedAtRef.current > 5e3;
|
|
2148
|
-
if (wasStable && reconnectCountRef.current < 5) {
|
|
2149
|
-
reconnectCountRef.current++;
|
|
2150
|
-
const delay = 2e3 * Math.pow(2, reconnectCountRef.current - 1);
|
|
2151
|
-
setTimeout(() => {
|
|
2152
|
-
if (isMountedRef.current && !connectingRef.current) {
|
|
2153
|
-
connectRef.current();
|
|
2154
|
-
}
|
|
2155
|
-
}, delay);
|
|
2156
|
-
}
|
|
2157
|
-
}
|
|
2158
|
-
});
|
|
2159
|
-
manager.onMessage((msg) => {
|
|
2160
|
-
if (!isMountedRef.current) return;
|
|
2161
|
-
if (msg.type === "entity.created" || msg.type === "entity.updated") {
|
|
2162
|
-
const payload = msg.payload;
|
|
2163
|
-
if (payload.data) {
|
|
2164
|
-
monoriseStore.setState(
|
|
2165
|
-
produce5((state) => {
|
|
2166
|
-
const key = payload.entityType;
|
|
2167
|
-
if (!state.entity[key]) {
|
|
2168
|
-
state.entity[key] = { dataMap: /* @__PURE__ */ new Map(), isFirstFetched: false, lastKey: void 0 };
|
|
2169
|
-
}
|
|
2170
|
-
state.entity[key].dataMap.set(payload.entityId, payload.data);
|
|
2171
|
-
})
|
|
2172
|
-
);
|
|
2173
|
-
}
|
|
2174
|
-
} else if (msg.type === "entity.deleted") {
|
|
2175
|
-
const payload = msg.payload;
|
|
2176
|
-
monoriseStore.setState(
|
|
2177
|
-
produce5((state) => {
|
|
2178
|
-
var _a, _b;
|
|
2179
|
-
(_b = (_a = state.entity[payload.entityType]) == null ? void 0 : _a.dataMap) == null ? void 0 : _b.delete(payload.entityId);
|
|
2180
|
-
})
|
|
2181
|
-
);
|
|
2182
|
-
} else if (msg.type === "mutual.created" || msg.type === "mutual.updated") {
|
|
2183
|
-
const payload = msg.payload;
|
|
2184
|
-
if (payload.data) {
|
|
2185
|
-
const mutualKey = `${payload.byEntityType}/${payload.byEntityId}/${payload.mutualEntityType}`;
|
|
2186
|
-
monoriseStore.setState(
|
|
2187
|
-
produce5((state) => {
|
|
2188
|
-
if (!state.mutual[mutualKey]) {
|
|
2189
|
-
state.mutual[mutualKey] = { dataMap: /* @__PURE__ */ new Map(), isFirstFetched: false, lastKey: void 0 };
|
|
2190
|
-
}
|
|
2191
|
-
state.mutual[mutualKey].dataMap.set(payload.entityId, payload.data);
|
|
2192
|
-
})
|
|
2193
|
-
);
|
|
2194
|
-
}
|
|
2195
|
-
} else if (msg.type === "mutual.deleted") {
|
|
2196
|
-
const payload = msg.payload;
|
|
2197
|
-
const mutualKey = `${payload.byEntityType}/${payload.byEntityId}/${payload.mutualEntityType}`;
|
|
2198
|
-
monoriseStore.setState(
|
|
2199
|
-
produce5((state) => {
|
|
2200
|
-
var _a, _b;
|
|
2201
|
-
(_b = (_a = state.mutual[mutualKey]) == null ? void 0 : _a.dataMap) == null ? void 0 : _b.delete(payload.entityId);
|
|
2202
|
-
})
|
|
2203
|
-
);
|
|
2204
|
-
}
|
|
2205
|
-
});
|
|
2206
|
-
manager.connect();
|
|
2207
|
-
if (refreshTimerRef.current) {
|
|
2208
|
-
clearTimeout(refreshTimerRef.current);
|
|
2209
|
-
}
|
|
2210
|
-
const refreshMs = Math.max((expiresIn - 120) * 1e3, 6e4);
|
|
2211
|
-
refreshTimerRef.current = setTimeout(() => {
|
|
2212
|
-
if (isMountedRef.current) {
|
|
2213
|
-
connectRef.current();
|
|
2214
|
-
}
|
|
2215
|
-
}, refreshMs);
|
|
2216
|
-
}, [fetchTicket]);
|
|
2217
|
-
connectRef.current = connectWithTicket;
|
|
2218
|
-
useEffect3(() => {
|
|
2219
|
-
isMountedRef.current = true;
|
|
2220
|
-
if (entityId) {
|
|
2221
|
-
connectRef.current();
|
|
2222
|
-
}
|
|
2223
|
-
let lastCheckTime = Date.now();
|
|
2224
|
-
const sleepCheckInterval = setInterval(() => {
|
|
2225
|
-
const now = Date.now();
|
|
2226
|
-
const elapsed = now - lastCheckTime;
|
|
2227
|
-
lastCheckTime = now;
|
|
2228
|
-
if (elapsed > 3e4 && wsManagerRef.current) {
|
|
2229
|
-
wsManagerRef.current.disconnect();
|
|
2230
|
-
wsManagerRef.current = null;
|
|
2231
|
-
connectingRef.current = false;
|
|
2232
|
-
reconnectCountRef.current = 0;
|
|
2233
|
-
connectRef.current();
|
|
2234
|
-
}
|
|
2235
|
-
}, 5e3);
|
|
2236
|
-
const handleOnline = () => {
|
|
2237
|
-
var _a;
|
|
2238
|
-
if (!isMountedRef.current) return;
|
|
2239
|
-
if (((_a = wsManagerRef.current) == null ? void 0 : _a.getState()) === "connected") return;
|
|
2240
|
-
if (connectingRef.current) return;
|
|
2241
|
-
reconnectCountRef.current = 0;
|
|
2242
|
-
connectRef.current();
|
|
2243
|
-
};
|
|
2244
|
-
window.addEventListener("online", handleOnline);
|
|
2245
|
-
return () => {
|
|
2246
|
-
isMountedRef.current = false;
|
|
2247
|
-
clearInterval(sleepCheckInterval);
|
|
2248
|
-
window.removeEventListener("online", handleOnline);
|
|
2249
|
-
if (refreshTimerRef.current) {
|
|
2250
|
-
clearTimeout(refreshTimerRef.current);
|
|
2251
|
-
}
|
|
2252
|
-
if (wsManagerRef.current) {
|
|
2253
|
-
wsManagerRef.current.disconnect();
|
|
2254
|
-
wsManagerRef.current = null;
|
|
2255
|
-
}
|
|
2256
|
-
};
|
|
2257
|
-
}, [entityType, entityId]);
|
|
2258
|
-
return { isConnected, error };
|
|
2259
|
-
};
|
|
2260
|
-
return {
|
|
2261
|
-
useEntitySocket: useEntitySocket2,
|
|
2262
|
-
useMutualSocket: useMutualSocket2,
|
|
2263
|
-
useEphemeralSocket: useEphemeralSocket2,
|
|
2264
|
-
useEntityFeed: useEntityFeed2
|
|
2265
|
-
};
|
|
2266
|
-
};
|
|
2267
|
-
|
|
2268
1817
|
// lib/api.ts
|
|
2269
1818
|
import request from "axios";
|
|
2270
1819
|
var initAxiosInterceptor = (store2, appActions) => {
|
|
@@ -2383,7 +1932,6 @@ var auth_service_default = initAuthService;
|
|
|
2383
1932
|
var ENTITY_API_BASE_URL = "/api/core/entity";
|
|
2384
1933
|
var MUTUAL_API_BASE_URL = "/api/core/mutual";
|
|
2385
1934
|
var TAG_API_BASE_URL = "/api/core/tag";
|
|
2386
|
-
var TRANSACTION_API_BASE_URL = "/api/core/transaction";
|
|
2387
1935
|
var initCoreService = (monoriseStore, axios2, opts) => {
|
|
2388
1936
|
let options = opts || {};
|
|
2389
1937
|
const listEntities = (entityType, payload, opts2 = {}) => {
|
|
@@ -2500,10 +2048,9 @@ var initCoreService = (monoriseStore, axios2, opts) => {
|
|
|
2500
2048
|
var _a;
|
|
2501
2049
|
const { entityApiBaseUrl = ENTITY_API_BASE_URL } = options;
|
|
2502
2050
|
const entityConfig = monoriseStore.getState().config;
|
|
2503
|
-
const body = opts2.condition ? __spreadProps(__spreadValues({}, adjustments), { $condition: opts2.condition }) : adjustments;
|
|
2504
2051
|
return axios2.post(
|
|
2505
2052
|
opts2.customUrl || `${entityApiBaseUrl}/${entityType}/${id}/adjust`,
|
|
2506
|
-
|
|
2053
|
+
adjustments,
|
|
2507
2054
|
{
|
|
2508
2055
|
requestKey: getEntityRequestKey("adjust", entityType, id),
|
|
2509
2056
|
isInterruptive: (_a = opts2.isInterruptive) != null ? _a : true,
|
|
@@ -2530,22 +2077,6 @@ var initCoreService = (monoriseStore, axios2, opts) => {
|
|
|
2530
2077
|
}
|
|
2531
2078
|
);
|
|
2532
2079
|
};
|
|
2533
|
-
const transaction = (operations, opts2 = {}) => {
|
|
2534
|
-
var _a;
|
|
2535
|
-
const { transactionApiBaseUrl = TRANSACTION_API_BASE_URL } = options;
|
|
2536
|
-
return axios2.post(
|
|
2537
|
-
opts2.customUrl || transactionApiBaseUrl,
|
|
2538
|
-
{ operations },
|
|
2539
|
-
{
|
|
2540
|
-
requestKey: "transaction",
|
|
2541
|
-
isInterruptive: (_a = opts2.isInterruptive) != null ? _a : true,
|
|
2542
|
-
feedback: __spreadValues({
|
|
2543
|
-
loading: "Processing transaction",
|
|
2544
|
-
success: "Transaction completed"
|
|
2545
|
-
}, opts2.feedback || {})
|
|
2546
|
-
}
|
|
2547
|
-
);
|
|
2548
|
-
};
|
|
2549
2080
|
const listEntitiesByEntity = (byEntityType, entityType, byEntityId2, opts2 = {}, chainEntityQuery) => {
|
|
2550
2081
|
const { mutualApiBaseUrl = MUTUAL_API_BASE_URL } = options;
|
|
2551
2082
|
return axios2.get(
|
|
@@ -2689,7 +2220,6 @@ var initCoreService = (monoriseStore, axios2, opts) => {
|
|
|
2689
2220
|
return {
|
|
2690
2221
|
makeEntityService,
|
|
2691
2222
|
makeMutualService,
|
|
2692
|
-
transaction,
|
|
2693
2223
|
setOptions
|
|
2694
2224
|
};
|
|
2695
2225
|
};
|
|
@@ -2920,7 +2450,6 @@ var initMonoriseStore = () => {
|
|
|
2920
2450
|
};
|
|
2921
2451
|
|
|
2922
2452
|
// index.ts
|
|
2923
|
-
import { transactional } from "../base/index.js";
|
|
2924
2453
|
var initMonorise = () => {
|
|
2925
2454
|
const { monoriseStore: store2, setOptions: setMonoriseOptions } = initMonoriseStore();
|
|
2926
2455
|
const appActions = initAppActions(store2);
|
|
@@ -2931,7 +2460,6 @@ var initMonorise = () => {
|
|
|
2931
2460
|
const coreService2 = core_service_default(store2, axios2);
|
|
2932
2461
|
const authActions = initAuthActions(store2, authService2);
|
|
2933
2462
|
const coreActions = initCoreActions(store2, appActions, coreService2);
|
|
2934
|
-
const websocketActions = initWebSocketActions(store2);
|
|
2935
2463
|
const axiosInterceptor = injectAxiosInterceptor(
|
|
2936
2464
|
appActions,
|
|
2937
2465
|
authActions,
|
|
@@ -2957,14 +2485,14 @@ var initMonorise = () => {
|
|
|
2957
2485
|
onApiSuccess: opts.onApiSuccess
|
|
2958
2486
|
});
|
|
2959
2487
|
};
|
|
2960
|
-
return __spreadValues(__spreadValues(__spreadValues(__spreadValues(
|
|
2488
|
+
return __spreadValues(__spreadValues(__spreadValues(__spreadValues({
|
|
2961
2489
|
config,
|
|
2962
2490
|
store: store2,
|
|
2963
2491
|
axios: axios2,
|
|
2964
2492
|
authService: authService2,
|
|
2965
2493
|
filestoreService: filestoreService2,
|
|
2966
2494
|
coreService: coreService2
|
|
2967
|
-
}, configActions), appActions), authActions), coreActions)
|
|
2495
|
+
}, configActions), appActions), authActions), coreActions);
|
|
2968
2496
|
};
|
|
2969
2497
|
var Monorise = initMonorise();
|
|
2970
2498
|
var {
|
|
@@ -3016,15 +2544,10 @@ var {
|
|
|
3016
2544
|
useEntityState,
|
|
3017
2545
|
getEntity,
|
|
3018
2546
|
updateLocalTaggedEntity,
|
|
3019
|
-
deleteLocalTaggedEntity
|
|
3020
|
-
useEntitySocket,
|
|
3021
|
-
useMutualSocket,
|
|
3022
|
-
useEphemeralSocket,
|
|
3023
|
-
useEntityFeed
|
|
2547
|
+
deleteLocalTaggedEntity
|
|
3024
2548
|
} = Monorise;
|
|
3025
2549
|
var index_default = Monorise;
|
|
3026
2550
|
export {
|
|
3027
|
-
WebSocketManager,
|
|
3028
2551
|
adjustEntity,
|
|
3029
2552
|
authService,
|
|
3030
2553
|
axios,
|
|
@@ -3052,8 +2575,6 @@ export {
|
|
|
3052
2575
|
getProfile,
|
|
3053
2576
|
getTagRequestKey,
|
|
3054
2577
|
getUniqueFieldRequestKey,
|
|
3055
|
-
getWebSocketManager,
|
|
3056
|
-
initializeWebSocketManager,
|
|
3057
2578
|
listMoreEntities,
|
|
3058
2579
|
logout,
|
|
3059
2580
|
openModal,
|
|
@@ -3063,7 +2584,6 @@ export {
|
|
|
3063
2584
|
setIsUnauthorized,
|
|
3064
2585
|
startLoading,
|
|
3065
2586
|
store,
|
|
3066
|
-
transactional,
|
|
3067
2587
|
updateLocalEntity,
|
|
3068
2588
|
updateLocalTaggedEntity,
|
|
3069
2589
|
upsertEntity,
|
|
@@ -3072,17 +2592,13 @@ export {
|
|
|
3072
2592
|
useEntities,
|
|
3073
2593
|
useEntity,
|
|
3074
2594
|
useEntityByUniqueField,
|
|
3075
|
-
useEntityFeed,
|
|
3076
|
-
useEntitySocket,
|
|
3077
2595
|
useEntityState,
|
|
3078
|
-
useEphemeralSocket,
|
|
3079
2596
|
useErrorStore,
|
|
3080
2597
|
useInterruptiveLoadStore,
|
|
3081
2598
|
useIsUnauthorized,
|
|
3082
2599
|
useLoadStore,
|
|
3083
2600
|
useModalStore,
|
|
3084
2601
|
useMutual,
|
|
3085
|
-
useMutualSocket,
|
|
3086
2602
|
useMutuals,
|
|
3087
2603
|
useProfile,
|
|
3088
2604
|
useTaggedEntities
|