akeyless-client-commons 1.1.36 → 1.1.38
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/components/index.css.map +1 -1
- package/dist/hooks/index.d.mts +11 -1
- package/dist/hooks/index.d.ts +11 -1
- package/dist/hooks/index.js +245 -60
- package/dist/hooks/index.mjs +242 -61
- package/package.json +1 -1
package/dist/hooks/index.js
CHANGED
|
@@ -7,9 +7,6 @@ function _array_like_to_array(arr, len) {
|
|
|
7
7
|
function _array_with_holes(arr) {
|
|
8
8
|
if (Array.isArray(arr)) return arr;
|
|
9
9
|
}
|
|
10
|
-
function _array_without_holes(arr) {
|
|
11
|
-
if (Array.isArray(arr)) return _array_like_to_array(arr);
|
|
12
|
-
}
|
|
13
10
|
function asyncGeneratorStep(gen, resolve, reject, _next, _throw, key, arg) {
|
|
14
11
|
try {
|
|
15
12
|
var info = gen[key](arg);
|
|
@@ -78,9 +75,6 @@ function _instanceof(left, right) {
|
|
|
78
75
|
return left instanceof right;
|
|
79
76
|
}
|
|
80
77
|
}
|
|
81
|
-
function _iterable_to_array(iter) {
|
|
82
|
-
if (typeof Symbol !== "undefined" && iter[Symbol.iterator] != null || iter["@@iterator"] != null) return Array.from(iter);
|
|
83
|
-
}
|
|
84
78
|
function _iterable_to_array_limit(arr, i) {
|
|
85
79
|
var _i = arr == null ? null : typeof Symbol !== "undefined" && arr[Symbol.iterator] || arr["@@iterator"];
|
|
86
80
|
if (_i == null) return;
|
|
@@ -108,9 +102,6 @@ function _iterable_to_array_limit(arr, i) {
|
|
|
108
102
|
function _non_iterable_rest() {
|
|
109
103
|
throw new TypeError("Invalid attempt to destructure non-iterable instance.\\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.");
|
|
110
104
|
}
|
|
111
|
-
function _non_iterable_spread() {
|
|
112
|
-
throw new TypeError("Invalid attempt to spread non-iterable instance.\\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.");
|
|
113
|
-
}
|
|
114
105
|
function _object_spread(target) {
|
|
115
106
|
for(var i = 1; i < arguments.length; i++){
|
|
116
107
|
var source = arguments[i] != null ? arguments[i] : {};
|
|
@@ -153,9 +144,6 @@ function _object_spread_props(target, source) {
|
|
|
153
144
|
function _sliced_to_array(arr, i) {
|
|
154
145
|
return _array_with_holes(arr) || _iterable_to_array_limit(arr, i) || _unsupported_iterable_to_array(arr, i) || _non_iterable_rest();
|
|
155
146
|
}
|
|
156
|
-
function _to_consumable_array(arr) {
|
|
157
|
-
return _array_without_holes(arr) || _iterable_to_array(arr) || _unsupported_iterable_to_array(arr) || _non_iterable_spread();
|
|
158
|
-
}
|
|
159
147
|
function _type_of(obj) {
|
|
160
148
|
"@swc/helpers - typeof";
|
|
161
149
|
return obj && typeof Symbol !== "undefined" && obj.constructor === Symbol ? "symbol" : typeof obj;
|
|
@@ -347,6 +335,9 @@ __export(index_exports, {
|
|
|
347
335
|
},
|
|
348
336
|
useSocketSnapshots: function() {
|
|
349
337
|
return useSocketSnapshots;
|
|
338
|
+
},
|
|
339
|
+
useWebWorker: function() {
|
|
340
|
+
return useWebWorker;
|
|
350
341
|
}
|
|
351
342
|
});
|
|
352
343
|
module.exports = __toCommonJS(index_exports);
|
|
@@ -1048,6 +1039,37 @@ var useWebWorker = function(fn, options) {
|
|
|
1048
1039
|
if (!isSupportedRef.current) {
|
|
1049
1040
|
return function() {};
|
|
1050
1041
|
}
|
|
1042
|
+
if (options === null || options === void 0 ? void 0 : options.warmStart) {
|
|
1043
|
+
try {
|
|
1044
|
+
ensureWorker();
|
|
1045
|
+
} catch (error) {
|
|
1046
|
+
console.error("Error creating worker", error);
|
|
1047
|
+
}
|
|
1048
|
+
}
|
|
1049
|
+
return function() {
|
|
1050
|
+
if (workerRef.current) {
|
|
1051
|
+
workerRef.current.terminate();
|
|
1052
|
+
workerRef.current = null;
|
|
1053
|
+
}
|
|
1054
|
+
if (workerUrlRef.current) {
|
|
1055
|
+
URL.revokeObjectURL(workerUrlRef.current);
|
|
1056
|
+
workerUrlRef.current = null;
|
|
1057
|
+
}
|
|
1058
|
+
pendingJobsRef.current.forEach(function(job) {
|
|
1059
|
+
job.reject(new Error("Worker terminated"));
|
|
1060
|
+
});
|
|
1061
|
+
pendingJobsRef.current.clear();
|
|
1062
|
+
isReadyRef.current = false;
|
|
1063
|
+
};
|
|
1064
|
+
}, [
|
|
1065
|
+
fn,
|
|
1066
|
+
options === null || options === void 0 ? void 0 : options.debug,
|
|
1067
|
+
options === null || options === void 0 ? void 0 : options.name,
|
|
1068
|
+
options === null || options === void 0 ? void 0 : options.onError
|
|
1069
|
+
]);
|
|
1070
|
+
var ensureWorker = (0, import_react4.useCallback)(function() {
|
|
1071
|
+
if (!isSupportedRef.current) return;
|
|
1072
|
+
if (workerRef.current) return;
|
|
1051
1073
|
var functionString = fn.toString();
|
|
1052
1074
|
var workerSource = [
|
|
1053
1075
|
"const userFn = (".concat(functionString, ");"),
|
|
@@ -1101,30 +1123,23 @@ var useWebWorker = function(fn, options) {
|
|
|
1101
1123
|
job.reject(err);
|
|
1102
1124
|
});
|
|
1103
1125
|
pendingJobsRef.current.clear();
|
|
1104
|
-
|
|
1105
|
-
|
|
1106
|
-
|
|
1107
|
-
|
|
1108
|
-
|
|
1109
|
-
URL.revokeObjectURL(workerUrlRef.current);
|
|
1110
|
-
}
|
|
1111
|
-
workerRef.current = worker;
|
|
1112
|
-
workerUrlRef.current = url;
|
|
1113
|
-
return function() {
|
|
1114
|
-
if (workerRef.current) {
|
|
1115
|
-
workerRef.current.terminate();
|
|
1126
|
+
if (options === null || options === void 0 ? void 0 : options.recreateOnError) {
|
|
1127
|
+
try {
|
|
1128
|
+
var _workerRef_current;
|
|
1129
|
+
(_workerRef_current = workerRef.current) === null || _workerRef_current === void 0 ? void 0 : _workerRef_current.terminate();
|
|
1130
|
+
} catch (_) {}
|
|
1116
1131
|
workerRef.current = null;
|
|
1132
|
+
if (workerUrlRef.current) {
|
|
1133
|
+
try {
|
|
1134
|
+
URL.revokeObjectURL(workerUrlRef.current);
|
|
1135
|
+
} catch (_) {}
|
|
1136
|
+
workerUrlRef.current = null;
|
|
1137
|
+
}
|
|
1138
|
+
isReadyRef.current = false;
|
|
1117
1139
|
}
|
|
1118
|
-
if (workerUrlRef.current) {
|
|
1119
|
-
URL.revokeObjectURL(workerUrlRef.current);
|
|
1120
|
-
workerUrlRef.current = null;
|
|
1121
|
-
}
|
|
1122
|
-
pendingJobsRef.current.forEach(function(job) {
|
|
1123
|
-
job.reject(new Error("Worker terminated"));
|
|
1124
|
-
});
|
|
1125
|
-
pendingJobsRef.current.clear();
|
|
1126
|
-
isReadyRef.current = false;
|
|
1127
1140
|
};
|
|
1141
|
+
workerRef.current = worker;
|
|
1142
|
+
workerUrlRef.current = url;
|
|
1128
1143
|
}, [
|
|
1129
1144
|
fn,
|
|
1130
1145
|
options === null || options === void 0 ? void 0 : options.debug,
|
|
@@ -1133,6 +1148,7 @@ var useWebWorker = function(fn, options) {
|
|
|
1133
1148
|
]);
|
|
1134
1149
|
var runWorkerBase = (0, import_react4.useCallback)(function(data, transfer) {
|
|
1135
1150
|
if (!workerRef.current) {
|
|
1151
|
+
ensureWorker();
|
|
1136
1152
|
if (options === null || options === void 0 ? void 0 : options.debug) {
|
|
1137
1153
|
console.warn("[WebWorker".concat((options === null || options === void 0 ? void 0 : options.name) ? ":" + options.name : "", "] fallback to main thread"));
|
|
1138
1154
|
}
|
|
@@ -1191,11 +1207,24 @@ var useWebWorker = function(fn, options) {
|
|
|
1191
1207
|
reject: reject
|
|
1192
1208
|
});
|
|
1193
1209
|
try {
|
|
1194
|
-
|
|
1210
|
+
var shouldTransfer = Array.isArray(transfer) ? transfer : [];
|
|
1211
|
+
if (!shouldTransfer.length) {
|
|
1212
|
+
var maybeArrayBuffer = _instanceof(data === null || data === void 0 ? void 0 : data.buffer, ArrayBuffer) ? data.buffer : void 0;
|
|
1213
|
+
if (maybeArrayBuffer) {
|
|
1214
|
+
workerRef.current.postMessage({
|
|
1215
|
+
id: id,
|
|
1216
|
+
payload: data
|
|
1217
|
+
}, [
|
|
1218
|
+
maybeArrayBuffer
|
|
1219
|
+
]);
|
|
1220
|
+
return;
|
|
1221
|
+
}
|
|
1222
|
+
}
|
|
1223
|
+
if (shouldTransfer.length) {
|
|
1195
1224
|
workerRef.current.postMessage({
|
|
1196
1225
|
id: id,
|
|
1197
1226
|
payload: data
|
|
1198
|
-
},
|
|
1227
|
+
}, shouldTransfer);
|
|
1199
1228
|
} else {
|
|
1200
1229
|
workerRef.current.postMessage({
|
|
1201
1230
|
id: id,
|
|
@@ -1215,7 +1244,8 @@ var useWebWorker = function(fn, options) {
|
|
|
1215
1244
|
fn,
|
|
1216
1245
|
options === null || options === void 0 ? void 0 : options.debug,
|
|
1217
1246
|
options === null || options === void 0 ? void 0 : options.name,
|
|
1218
|
-
options === null || options === void 0 ? void 0 : options.onError
|
|
1247
|
+
options === null || options === void 0 ? void 0 : options.onError,
|
|
1248
|
+
ensureWorker
|
|
1219
1249
|
]);
|
|
1220
1250
|
var runWorker = runWorkerBase;
|
|
1221
1251
|
runWorker.isSupported = function() {
|
|
@@ -1230,18 +1260,89 @@ var useWebWorker = function(fn, options) {
|
|
|
1230
1260
|
runWorker.lastError = function() {
|
|
1231
1261
|
return lastErrorRef.current;
|
|
1232
1262
|
};
|
|
1263
|
+
runWorker.terminate = function() {
|
|
1264
|
+
if (workerRef.current) {
|
|
1265
|
+
try {
|
|
1266
|
+
workerRef.current.terminate();
|
|
1267
|
+
} catch (error) {
|
|
1268
|
+
console.error("Error terminating worker", error);
|
|
1269
|
+
}
|
|
1270
|
+
workerRef.current = null;
|
|
1271
|
+
}
|
|
1272
|
+
if (workerUrlRef.current) {
|
|
1273
|
+
try {
|
|
1274
|
+
URL.revokeObjectURL(workerUrlRef.current);
|
|
1275
|
+
} catch (error) {
|
|
1276
|
+
console.error("Error revoking worker URL", error);
|
|
1277
|
+
}
|
|
1278
|
+
workerUrlRef.current = null;
|
|
1279
|
+
}
|
|
1280
|
+
pendingJobsRef.current.forEach(function(job) {
|
|
1281
|
+
return job.reject(new Error("Worker terminated"));
|
|
1282
|
+
});
|
|
1283
|
+
pendingJobsRef.current.clear();
|
|
1284
|
+
isReadyRef.current = false;
|
|
1285
|
+
};
|
|
1233
1286
|
return runWorker;
|
|
1234
1287
|
};
|
|
1235
|
-
var WebWorker_default = useWebWorker;
|
|
1236
1288
|
// src/hooks/snapshots.ts
|
|
1237
1289
|
var import_react5 = require("react");
|
|
1238
1290
|
// src/hooks/snapshotWorker.ts
|
|
1239
|
-
var wrapConfigsWithWorker = function(cfgs, runProcessor) {
|
|
1291
|
+
var wrapConfigsWithWorker = function(cfgs, runProcessor, options) {
|
|
1292
|
+
var recentEvents = /* @__PURE__ */ new Map();
|
|
1293
|
+
var _options_eventTtlMs;
|
|
1294
|
+
var EVENT_TTL_MS = (_options_eventTtlMs = options === null || options === void 0 ? void 0 : options.eventTtlMs) !== null && _options_eventTtlMs !== void 0 ? _options_eventTtlMs : 1500;
|
|
1295
|
+
var _options_maxRecentEvents;
|
|
1296
|
+
var MAX_RECENT = (_options_maxRecentEvents = options === null || options === void 0 ? void 0 : options.maxRecentEvents) !== null && _options_maxRecentEvents !== void 0 ? _options_maxRecentEvents : 500;
|
|
1297
|
+
var now = function() {
|
|
1298
|
+
return Date.now();
|
|
1299
|
+
};
|
|
1300
|
+
var makeKey = function(op, docs, collectionName) {
|
|
1301
|
+
try {
|
|
1302
|
+
var ids = (docs || []).map(function(d) {
|
|
1303
|
+
return d === null || d === void 0 ? void 0 : d.id;
|
|
1304
|
+
}).filter(Boolean).sort().join(",");
|
|
1305
|
+
return "".concat(collectionName || "unknown", ":").concat(op, ":").concat(ids);
|
|
1306
|
+
} catch (e) {
|
|
1307
|
+
return "".concat(collectionName || "unknown", ":").concat(op, ":*");
|
|
1308
|
+
}
|
|
1309
|
+
};
|
|
1310
|
+
var shouldProcess = function(key) {
|
|
1311
|
+
var ts = recentEvents.get(key);
|
|
1312
|
+
if (ts && now() - ts < EVENT_TTL_MS) {
|
|
1313
|
+
return false;
|
|
1314
|
+
}
|
|
1315
|
+
if (recentEvents.size > MAX_RECENT) {
|
|
1316
|
+
var cutoff = now() - EVENT_TTL_MS;
|
|
1317
|
+
var _iteratorNormalCompletion = true, _didIteratorError = false, _iteratorError = undefined;
|
|
1318
|
+
try {
|
|
1319
|
+
for(var _iterator = Array.from(recentEvents.entries())[Symbol.iterator](), _step; !(_iteratorNormalCompletion = (_step = _iterator.next()).done); _iteratorNormalCompletion = true){
|
|
1320
|
+
var _step_value = _sliced_to_array(_step.value, 2), k = _step_value[0], v = _step_value[1];
|
|
1321
|
+
if (v < cutoff) recentEvents.delete(k);
|
|
1322
|
+
}
|
|
1323
|
+
} catch (err) {
|
|
1324
|
+
_didIteratorError = true;
|
|
1325
|
+
_iteratorError = err;
|
|
1326
|
+
} finally{
|
|
1327
|
+
try {
|
|
1328
|
+
if (!_iteratorNormalCompletion && _iterator.return != null) {
|
|
1329
|
+
_iterator.return();
|
|
1330
|
+
}
|
|
1331
|
+
} finally{
|
|
1332
|
+
if (_didIteratorError) {
|
|
1333
|
+
throw _iteratorError;
|
|
1334
|
+
}
|
|
1335
|
+
}
|
|
1336
|
+
}
|
|
1337
|
+
}
|
|
1338
|
+
recentEvents.set(key, now());
|
|
1339
|
+
return true;
|
|
1340
|
+
};
|
|
1240
1341
|
var wrapCb = function(cb, op, run) {
|
|
1241
1342
|
if (!cb) return void 0;
|
|
1242
1343
|
return /*#__PURE__*/ function() {
|
|
1243
1344
|
var _ref = _async_to_generator(function(docs, config) {
|
|
1244
|
-
var safeDocs, _ref, processed, e;
|
|
1345
|
+
var key, safeDocs, _ref, processed, e;
|
|
1245
1346
|
return _ts_generator(this, function(_state) {
|
|
1246
1347
|
switch(_state.label){
|
|
1247
1348
|
case 0:
|
|
@@ -1251,7 +1352,13 @@ var wrapConfigsWithWorker = function(cfgs, runProcessor) {
|
|
|
1251
1352
|
,
|
|
1252
1353
|
3
|
|
1253
1354
|
]);
|
|
1254
|
-
|
|
1355
|
+
key = makeKey(op, docs, config === null || config === void 0 ? void 0 : config.collectionName);
|
|
1356
|
+
if (!shouldProcess(key)) {
|
|
1357
|
+
return [
|
|
1358
|
+
2
|
|
1359
|
+
];
|
|
1360
|
+
}
|
|
1361
|
+
safeDocs = (options === null || options === void 0 ? void 0 : options.jsonClone) === false ? docs : JSON.parse(JSON.stringify(docs));
|
|
1255
1362
|
return [
|
|
1256
1363
|
4,
|
|
1257
1364
|
run({
|
|
@@ -1308,11 +1415,13 @@ var wrapConfigsWithWorker = function(cfgs, runProcessor) {
|
|
|
1308
1415
|
var useDbSnapshots = function(configs, label, settings) {
|
|
1309
1416
|
var snapshotsFirstTime = (0, import_react5.useRef)([]);
|
|
1310
1417
|
var unsubscribeFunctions = (0, import_react5.useRef)([]);
|
|
1311
|
-
var
|
|
1418
|
+
var lastDbCollectionsRef = (0, import_react5.useRef)([]);
|
|
1419
|
+
var workerProcessorDb = (0, import_react5.useCallback)(function(payload) {
|
|
1312
1420
|
return {
|
|
1313
1421
|
docs: payload.docs
|
|
1314
1422
|
};
|
|
1315
|
-
},
|
|
1423
|
+
}, []);
|
|
1424
|
+
var runProcessor = useWebWorker(workerProcessorDb, settings === null || settings === void 0 ? void 0 : settings.worker);
|
|
1316
1425
|
var wrapConfigsForWorker = function(cfgs) {
|
|
1317
1426
|
return wrapConfigsWithWorker(cfgs, function(payload) {
|
|
1318
1427
|
return runProcessor(payload);
|
|
@@ -1324,6 +1433,9 @@ var useDbSnapshots = function(configs, label, settings) {
|
|
|
1324
1433
|
console.log("==> ".concat(label || "DB snapshots", " started from db... "));
|
|
1325
1434
|
}
|
|
1326
1435
|
var wrappedConfigs = wrapConfigsForWorker(configs);
|
|
1436
|
+
lastDbCollectionsRef.current = configs.map(function(c) {
|
|
1437
|
+
return c.collectionName;
|
|
1438
|
+
});
|
|
1327
1439
|
var snapshotResults = wrappedConfigs.map(function(config) {
|
|
1328
1440
|
return snapshot(config, snapshotsFirstTime.current, settings);
|
|
1329
1441
|
});
|
|
@@ -1339,11 +1451,15 @@ var useDbSnapshots = function(configs, label, settings) {
|
|
|
1339
1451
|
});
|
|
1340
1452
|
if (settings === null || settings === void 0 ? void 0 : settings.cleanupForConfigChange) {
|
|
1341
1453
|
return function() {
|
|
1454
|
+
var _settings_worker;
|
|
1342
1455
|
unsubscribeFunctions.current.forEach(function(unsubscribe) {
|
|
1343
1456
|
if (unsubscribe) {
|
|
1344
1457
|
unsubscribe();
|
|
1345
1458
|
}
|
|
1346
1459
|
});
|
|
1460
|
+
if ((settings === null || settings === void 0 ? void 0 : (_settings_worker = settings.worker) === null || _settings_worker === void 0 ? void 0 : _settings_worker.debug) && lastDbCollectionsRef.current.length) {
|
|
1461
|
+
console.log("==> ".concat(label || "DB snapshots", " cleanup: cleaned previous subscriptions for [").concat(lastDbCollectionsRef.current.join(", "), "]"));
|
|
1462
|
+
}
|
|
1347
1463
|
if (!(settings === null || settings === void 0 ? void 0 : settings.disableLogs) && configs.length > 0) {
|
|
1348
1464
|
console.log("==> ".concat(label || "DB snapshots", " unsubscribed from db"));
|
|
1349
1465
|
}
|
|
@@ -1356,11 +1472,15 @@ var useDbSnapshots = function(configs, label, settings) {
|
|
|
1356
1472
|
]);
|
|
1357
1473
|
(0, import_react5.useEffect)(function() {
|
|
1358
1474
|
return function() {
|
|
1475
|
+
var _settings_worker;
|
|
1359
1476
|
unsubscribeFunctions.current.forEach(function(unsubscribe) {
|
|
1360
1477
|
if (unsubscribe) {
|
|
1361
1478
|
unsubscribe();
|
|
1362
1479
|
}
|
|
1363
1480
|
});
|
|
1481
|
+
if ((settings === null || settings === void 0 ? void 0 : (_settings_worker = settings.worker) === null || _settings_worker === void 0 ? void 0 : _settings_worker.debug) && lastDbCollectionsRef.current.length) {
|
|
1482
|
+
console.log("==> ".concat(label || "DB snapshots", " cleanup: cleaned previous subscriptions for [").concat(lastDbCollectionsRef.current.join(", "), "]"));
|
|
1483
|
+
}
|
|
1364
1484
|
if (!(settings === null || settings === void 0 ? void 0 : settings.disableLogs)) {
|
|
1365
1485
|
console.log("==> ".concat(label || "DB snapshots", " unsubscribed"));
|
|
1366
1486
|
}
|
|
@@ -1394,6 +1514,10 @@ var useSmartSnapshots = function(configs, label, settings) {
|
|
|
1394
1514
|
configForDb.push(cfg);
|
|
1395
1515
|
}
|
|
1396
1516
|
});
|
|
1517
|
+
if (!(settings === null || settings === void 0 ? void 0 : settings.disableLogs)) {
|
|
1518
|
+
console.log("configForDb", configForDb);
|
|
1519
|
+
console.log("configForCache", configForCache);
|
|
1520
|
+
}
|
|
1397
1521
|
return {
|
|
1398
1522
|
configForDb: configForDb,
|
|
1399
1523
|
configForCache: configForCache
|
|
@@ -1412,36 +1536,70 @@ var useSmartSnapshots = function(configs, label, settings) {
|
|
|
1412
1536
|
var useSocketSnapshots = function(configs, label, settings) {
|
|
1413
1537
|
var _auth_currentUser;
|
|
1414
1538
|
var _ref = _sliced_to_array((0, import_react5.useState)(socketServiceInstance.isConnected()), 2), socketConnected = _ref[0], setSocketConnected = _ref[1];
|
|
1415
|
-
var
|
|
1539
|
+
var cleanupSubscriptionsRef = (0, import_react5.useRef)([]);
|
|
1416
1540
|
var socketStarted = (0, import_react5.useRef)(false);
|
|
1417
|
-
var
|
|
1541
|
+
var activeSubscriptionKeyRef = (0, import_react5.useRef)(null);
|
|
1542
|
+
var activeCollectionsRef = (0, import_react5.useRef)(/* @__PURE__ */ new Set());
|
|
1543
|
+
var offConnectRef = (0, import_react5.useRef)(null);
|
|
1544
|
+
var offDisconnectRef = (0, import_react5.useRef)(null);
|
|
1545
|
+
var workerProcessorSocket = (0, import_react5.useCallback)(function(payload) {
|
|
1418
1546
|
return {
|
|
1419
1547
|
docs: payload.docs
|
|
1420
1548
|
};
|
|
1421
|
-
},
|
|
1549
|
+
}, []);
|
|
1550
|
+
var runProcessor = useWebWorker(workerProcessorSocket, settings === null || settings === void 0 ? void 0 : settings.worker);
|
|
1422
1551
|
var wrapConfigsForWorker = function(cfgs) {
|
|
1423
1552
|
return wrapConfigsWithWorker(cfgs, function(payload) {
|
|
1424
1553
|
return runProcessor(payload);
|
|
1425
1554
|
});
|
|
1426
1555
|
};
|
|
1427
1556
|
useDeepCompareEffect(function() {
|
|
1557
|
+
var _offConnectRef_current, _offDisconnectRef_current;
|
|
1428
1558
|
if (!auth.currentUser) {
|
|
1429
1559
|
return;
|
|
1430
1560
|
}
|
|
1431
1561
|
var subscribe = function() {
|
|
1432
|
-
|
|
1562
|
+
var desiredNames = new Set(configs.map(function(c) {
|
|
1563
|
+
return c.collectionName;
|
|
1564
|
+
}));
|
|
1565
|
+
var key = JSON.stringify(Array.from(desiredNames).sort());
|
|
1566
|
+
if (settings === null || settings === void 0 ? void 0 : settings.cleanupForConfigChange) {
|
|
1567
|
+
if (activeSubscriptionKeyRef.current === key) return;
|
|
1568
|
+
if (cleanupSubscriptionsRef.current.length) {
|
|
1569
|
+
cleanupSubscriptionsRef.current.forEach(function(cleanup) {
|
|
1570
|
+
return cleanup();
|
|
1571
|
+
});
|
|
1572
|
+
cleanupSubscriptionsRef.current = [];
|
|
1573
|
+
}
|
|
1574
|
+
if (configs.length === 0) return;
|
|
1575
|
+
var disposer2 = socketServiceInstance.subscribeToCollections(wrapConfigsForWorker(configs));
|
|
1576
|
+
cleanupSubscriptionsRef.current.push(disposer2);
|
|
1577
|
+
activeCollectionsRef.current = new Set(desiredNames);
|
|
1578
|
+
activeSubscriptionKeyRef.current = key;
|
|
1579
|
+
if (!(settings === null || settings === void 0 ? void 0 : settings.disableLogs)) {
|
|
1580
|
+
console.log("==> ".concat(label || "Cache snapshots", " subscribed to ").concat(configs.map(function(c) {
|
|
1581
|
+
return c.collectionName;
|
|
1582
|
+
}).join(", ")));
|
|
1583
|
+
}
|
|
1433
1584
|
return;
|
|
1434
1585
|
}
|
|
1435
|
-
var
|
|
1436
|
-
|
|
1437
|
-
return _to_consumable_array(prev).concat([
|
|
1438
|
-
disposer
|
|
1439
|
-
]);
|
|
1586
|
+
var toAdd = Array.from(desiredNames).filter(function(name) {
|
|
1587
|
+
return !activeCollectionsRef.current.has(name);
|
|
1440
1588
|
});
|
|
1589
|
+
if (toAdd.length === 0) {
|
|
1590
|
+
return;
|
|
1591
|
+
}
|
|
1592
|
+
var configsToAdd = configs.filter(function(c) {
|
|
1593
|
+
return toAdd.includes(c.collectionName);
|
|
1594
|
+
});
|
|
1595
|
+
var disposer = socketServiceInstance.subscribeToCollections(wrapConfigsForWorker(configsToAdd));
|
|
1596
|
+
cleanupSubscriptionsRef.current.push(disposer);
|
|
1597
|
+
toAdd.forEach(function(n) {
|
|
1598
|
+
return activeCollectionsRef.current.add(n);
|
|
1599
|
+
});
|
|
1600
|
+
activeSubscriptionKeyRef.current = JSON.stringify(Array.from(activeCollectionsRef.current).sort());
|
|
1441
1601
|
if (!(settings === null || settings === void 0 ? void 0 : settings.disableLogs)) {
|
|
1442
|
-
console.log("==> ".concat(label || "Cache snapshots", "
|
|
1443
|
-
return c.collectionName;
|
|
1444
|
-
}).join(", ")));
|
|
1602
|
+
console.log("==> ".concat(label || "Cache snapshots", " appended subscriptions for ").concat(toAdd.join(", ")));
|
|
1445
1603
|
}
|
|
1446
1604
|
};
|
|
1447
1605
|
if (socketServiceInstance.isConnected()) {
|
|
@@ -1454,24 +1612,42 @@ var useSocketSnapshots = function(configs, label, settings) {
|
|
|
1454
1612
|
if (!(settings === null || settings === void 0 ? void 0 : settings.disableLogs)) {
|
|
1455
1613
|
console.log("==> ".concat(label || "Cache snapshots", " started... "));
|
|
1456
1614
|
}
|
|
1615
|
+
}).catch(function(err) {
|
|
1616
|
+
socketStarted.current = false;
|
|
1617
|
+
if (!(settings === null || settings === void 0 ? void 0 : settings.disableLogs)) {
|
|
1618
|
+
console.error("==> ".concat(label || "Cache snapshots", " failed to acquire token:"), err);
|
|
1619
|
+
}
|
|
1457
1620
|
});
|
|
1458
1621
|
}
|
|
1459
|
-
|
|
1622
|
+
(_offConnectRef_current = offConnectRef.current) === null || _offConnectRef_current === void 0 ? void 0 : _offConnectRef_current.call(offConnectRef);
|
|
1623
|
+
(_offDisconnectRef_current = offDisconnectRef.current) === null || _offDisconnectRef_current === void 0 ? void 0 : _offDisconnectRef_current.call(offDisconnectRef);
|
|
1624
|
+
offConnectRef.current = socketServiceInstance.onConnect(function() {
|
|
1460
1625
|
setSocketConnected(true);
|
|
1461
1626
|
socketStarted.current = false;
|
|
1462
1627
|
subscribe();
|
|
1463
1628
|
});
|
|
1464
|
-
|
|
1629
|
+
offDisconnectRef.current = socketServiceInstance.onDisconnect(function() {
|
|
1465
1630
|
setSocketConnected(false);
|
|
1466
|
-
|
|
1631
|
+
cleanupSubscriptionsRef.current.forEach(function(cleanup) {
|
|
1467
1632
|
return cleanup();
|
|
1468
1633
|
});
|
|
1634
|
+
cleanupSubscriptionsRef.current = [];
|
|
1635
|
+
activeSubscriptionKeyRef.current = null;
|
|
1636
|
+
activeCollectionsRef.current = /* @__PURE__ */ new Set();
|
|
1469
1637
|
});
|
|
1470
1638
|
if (settings === null || settings === void 0 ? void 0 : settings.cleanupForConfigChange) {
|
|
1471
1639
|
return function() {
|
|
1472
|
-
|
|
1640
|
+
var _offConnectRef_current, _offDisconnectRef_current;
|
|
1641
|
+
cleanupSubscriptionsRef.current.forEach(function(cleanup) {
|
|
1473
1642
|
return cleanup();
|
|
1474
1643
|
});
|
|
1644
|
+
cleanupSubscriptionsRef.current = [];
|
|
1645
|
+
activeSubscriptionKeyRef.current = null;
|
|
1646
|
+
activeCollectionsRef.current = /* @__PURE__ */ new Set();
|
|
1647
|
+
(_offConnectRef_current = offConnectRef.current) === null || _offConnectRef_current === void 0 ? void 0 : _offConnectRef_current.call(offConnectRef);
|
|
1648
|
+
offConnectRef.current = null;
|
|
1649
|
+
(_offDisconnectRef_current = offDisconnectRef.current) === null || _offDisconnectRef_current === void 0 ? void 0 : _offDisconnectRef_current.call(offDisconnectRef);
|
|
1650
|
+
offDisconnectRef.current = null;
|
|
1475
1651
|
if (!(settings === null || settings === void 0 ? void 0 : settings.disableLogs) && configs.length > 0) {
|
|
1476
1652
|
console.log("==> ".concat(label || "Cache snapshots", " unsubscribed. "));
|
|
1477
1653
|
}
|
|
@@ -1483,9 +1659,17 @@ var useSocketSnapshots = function(configs, label, settings) {
|
|
|
1483
1659
|
]);
|
|
1484
1660
|
(0, import_react5.useEffect)(function() {
|
|
1485
1661
|
return function() {
|
|
1486
|
-
|
|
1662
|
+
var _offConnectRef_current, _offDisconnectRef_current;
|
|
1663
|
+
cleanupSubscriptionsRef.current.forEach(function(cleanup) {
|
|
1487
1664
|
return cleanup();
|
|
1488
1665
|
});
|
|
1666
|
+
cleanupSubscriptionsRef.current = [];
|
|
1667
|
+
activeSubscriptionKeyRef.current = null;
|
|
1668
|
+
activeCollectionsRef.current = /* @__PURE__ */ new Set();
|
|
1669
|
+
(_offConnectRef_current = offConnectRef.current) === null || _offConnectRef_current === void 0 ? void 0 : _offConnectRef_current.call(offConnectRef);
|
|
1670
|
+
offConnectRef.current = null;
|
|
1671
|
+
(_offDisconnectRef_current = offDisconnectRef.current) === null || _offDisconnectRef_current === void 0 ? void 0 : _offDisconnectRef_current.call(offDisconnectRef);
|
|
1672
|
+
offDisconnectRef.current = null;
|
|
1489
1673
|
if (!(settings === null || settings === void 0 ? void 0 : settings.disableLogs) && configs.length > 0) {
|
|
1490
1674
|
console.log("==> ".concat(label || "Cache snapshots", " unsubscribed. "));
|
|
1491
1675
|
}
|
|
@@ -1504,6 +1688,7 @@ var useSocketSnapshots = function(configs, label, settings) {
|
|
|
1504
1688
|
useSafeEffect: useSafeEffect,
|
|
1505
1689
|
useSetUserCountry: useSetUserCountry,
|
|
1506
1690
|
useSmartSnapshots: useSmartSnapshots,
|
|
1507
|
-
useSocketSnapshots: useSocketSnapshots
|
|
1691
|
+
useSocketSnapshots: useSocketSnapshots,
|
|
1692
|
+
useWebWorker: useWebWorker
|
|
1508
1693
|
});
|
|
1509
1694
|
//# sourceMappingURL=index.js.map
|