@buoy-gg/network 7.0.41 → 7.0.43
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/README.md +11 -85
- package/lib/commonjs/index.js +1 -332
- package/lib/commonjs/index.web.js +1 -420
- package/lib/commonjs/network/components/DataViewer.web.js +1 -879
- package/lib/commonjs/network/components/NetworkCopyScreen.web.js +1 -48
- package/lib/commonjs/network/components/NetworkCopySettingsView.js +27 -755
- package/lib/commonjs/network/components/NetworkCopySettingsView.web.js +14 -1242
- package/lib/commonjs/network/components/NetworkDetailScreen.web.js +1 -101
- package/lib/commonjs/network/components/NetworkDetailStepper.js +1 -108
- package/lib/commonjs/network/components/NetworkDetailStepper.web.js +1 -298
- package/lib/commonjs/network/components/NetworkEventDetailView.js +15 -1130
- package/lib/commonjs/network/components/NetworkEventDetailView.web.js +15 -1484
- package/lib/commonjs/network/components/NetworkEventItemCompact.js +2 -401
- package/lib/commonjs/network/components/NetworkEventItemCompact.web.js +2 -820
- package/lib/commonjs/network/components/NetworkFilterScreen.web.js +1 -55
- package/lib/commonjs/network/components/NetworkFilterViewV3.js +1 -442
- package/lib/commonjs/network/components/NetworkFilterViewV3.web.js +1 -1310
- package/lib/commonjs/network/components/NetworkHeaderLive.js +1 -375
- package/lib/commonjs/network/components/NetworkHeaderLive.web.js +1 -623
- package/lib/commonjs/network/components/NetworkHeaderMenu.js +1 -190
- package/lib/commonjs/network/components/NetworkListScreen.js +1 -403
- package/lib/commonjs/network/components/NetworkListScreen.web.js +1 -624
- package/lib/commonjs/network/components/NetworkModal.js +1 -786
- package/lib/commonjs/network/components/NetworkNumberPrompt.js +1 -178
- package/lib/commonjs/network/components/NetworkNumberPrompt.web.js +1 -232
- package/lib/commonjs/network/components/NetworkOverrideEditor.js +1 -814
- package/lib/commonjs/network/components/NetworkOverrideEditor.web.js +1 -942
- package/lib/commonjs/network/components/NetworkOverrideHeaderButton.js +1 -107
- package/lib/commonjs/network/components/NetworkOverrideHeaderButton.web.js +1 -133
- package/lib/commonjs/network/components/NetworkOverridesButton.js +1 -90
- package/lib/commonjs/network/components/NetworkOverridesButton.web.js +1 -143
- package/lib/commonjs/network/components/NetworkOverridesScreen.js +1 -543
- package/lib/commonjs/network/components/NetworkOverridesScreen.web.js +1 -830
- package/lib/commonjs/network/components/NetworkSavedScreen.js +1 -226
- package/lib/commonjs/network/components/NetworkSavedScreen.web.js +1 -463
- package/lib/commonjs/network/components/NetworkUpgradeBanner.js +1 -76
- package/lib/commonjs/network/components/response-editor/Explorer.js +1 -973
- package/lib/commonjs/network/components/response-editor/Explorer.web.js +1 -1136
- package/lib/commonjs/network/components/response-editor/deleteNestedDataByPath.js +1 -56
- package/lib/commonjs/network/components/response-editor/editorContext.js +1 -33
- package/lib/commonjs/network/components/response-editor/updateNestedDataByPath.js +1 -61
- package/lib/commonjs/network/conditions/NetworkConditionsControl.js +1 -235
- package/lib/commonjs/network/conditions/NetworkConditionsControl.test.js +1 -136
- package/lib/commonjs/network/conditions/NetworkConditionsIcon.js +1 -33
- package/lib/commonjs/network/conditions/NetworkFloatingTool.js +1 -310
- package/lib/commonjs/network/conditions/NetworkFloatingTool.test.js +1 -219
- package/lib/commonjs/network/conditions/store.js +1 -75
- package/lib/commonjs/network/conditions/wait.js +1 -43
- package/lib/commonjs/network/conditions/xhr.js +1 -135
- package/lib/commonjs/network/hooks/useLiveNetworkEvent.js +1 -62
- package/lib/commonjs/network/hooks/useNetworkBadgeCounts.js +1 -83
- package/lib/commonjs/network/hooks/useNetworkEventList.js +1 -108
- package/lib/commonjs/network/hooks/useNetworkEvents.js +1 -318
- package/lib/commonjs/network/hooks/useNetworkHasMatches.js +1 -56
- package/lib/commonjs/network/hooks/useNetworkSaved.js +1 -38
- package/lib/commonjs/network/hooks/useNetworkSelection.js +1 -53
- package/lib/commonjs/network/hooks/useOverrideRules.js +1 -36
- package/lib/commonjs/network/hooks/useTickEveryMinute.js +1 -21
- package/lib/commonjs/network/overrides/applyToFetch.js +1 -80
- package/lib/commonjs/network/overrides/applyToXhr.js +2 -510
- package/lib/commonjs/network/overrides/engine.js +1 -93
- package/lib/commonjs/network/overrides/matchRule.js +1 -87
- package/lib/commonjs/network/overrides/overriddenRows.js +1 -37
- package/lib/commonjs/network/overrides/overrideRulesStore.js +1 -550
- package/lib/commonjs/network/overrides/presets.js +1 -70
- package/lib/commonjs/network/overrides/resolveOverride.js +1 -158
- package/lib/commonjs/network/overrides/types.js +1 -90
- package/lib/commonjs/network/sync/networkBodyResolver.js +1 -39
- package/lib/commonjs/network/sync/networkSyncAdapter.js +1 -882
- package/lib/commonjs/network/sync/overrideHonesty.release.test.js +1 -36
- package/lib/commonjs/network/types/index.js +1 -5
- package/lib/commonjs/network/utils/extractOperationName.js +1 -80
- package/lib/commonjs/network/utils/filterNetworkEvents.js +1 -96
- package/lib/commonjs/network/utils/formatGraphQLVariables.js +1 -219
- package/lib/commonjs/network/utils/formatting.js +1 -30
- package/lib/commonjs/network/utils/generateCurl.js +2 -71
- package/lib/commonjs/network/utils/generateNetworkCopyText.js +37 -166
- package/lib/commonjs/network/utils/httpCompletion.js +1 -37
- package/lib/commonjs/network/utils/networkEventStore.js +1 -411
- package/lib/commonjs/network/utils/networkListener.js +4 -1352
- package/lib/commonjs/network/utils/networkSavedStore.js +3 -577
- package/lib/commonjs/network/utils/networkSelectionStore.js +1 -193
- package/lib/commonjs/network/utils/realNow.js +1 -0
- package/lib/commonjs/network/utils/requestId.js +1 -16
- package/lib/commonjs/network/utils/resolveRequestUrl.js +1 -15
- package/lib/commonjs/network/utils/selectSavedEvents.js +1 -39
- package/lib/commonjs/network/utils/startNetworkCapture.js +1 -24
- package/lib/commonjs/network/utils/withPinnedFirst.js +1 -32
- package/lib/commonjs/preset.js +1 -93
- package/lib/module/index.js +1 -104
- package/lib/module/index.web.js +1 -82
- package/lib/module/network/components/DataViewer.web.js +1 -875
- package/lib/module/network/components/NetworkCopyScreen.web.js +1 -44
- package/lib/module/network/components/NetworkCopySettingsView.js +27 -750
- package/lib/module/network/components/NetworkCopySettingsView.web.js +14 -1237
- package/lib/module/network/components/NetworkDetailScreen.web.js +1 -97
- package/lib/module/network/components/NetworkDetailStepper.js +1 -104
- package/lib/module/network/components/NetworkDetailStepper.web.js +1 -296
- package/lib/module/network/components/NetworkEventDetailView.js +15 -1129
- package/lib/module/network/components/NetworkEventDetailView.web.js +15 -1482
- package/lib/module/network/components/NetworkEventItemCompact.js +2 -398
- package/lib/module/network/components/NetworkEventItemCompact.web.js +2 -818
- package/lib/module/network/components/NetworkFilterScreen.web.js +1 -51
- package/lib/module/network/components/NetworkFilterViewV3.js +1 -438
- package/lib/module/network/components/NetworkFilterViewV3.web.js +1 -1306
- package/lib/module/network/components/NetworkHeaderLive.js +1 -366
- package/lib/module/network/components/NetworkHeaderLive.web.js +1 -617
- package/lib/module/network/components/NetworkHeaderMenu.js +1 -184
- package/lib/module/network/components/NetworkListScreen.js +1 -399
- package/lib/module/network/components/NetworkListScreen.web.js +1 -622
- package/lib/module/network/components/NetworkModal.js +1 -781
- package/lib/module/network/components/NetworkNumberPrompt.js +1 -174
- package/lib/module/network/components/NetworkNumberPrompt.web.js +1 -230
- package/lib/module/network/components/NetworkOverrideEditor.js +1 -811
- package/lib/module/network/components/NetworkOverrideEditor.web.js +1 -939
- package/lib/module/network/components/NetworkOverrideHeaderButton.js +1 -104
- package/lib/module/network/components/NetworkOverrideHeaderButton.web.js +1 -131
- package/lib/module/network/components/NetworkOverridesButton.js +1 -87
- package/lib/module/network/components/NetworkOverridesButton.web.js +1 -141
- package/lib/module/network/components/NetworkOverridesScreen.js +1 -539
- package/lib/module/network/components/NetworkOverridesScreen.web.js +1 -826
- package/lib/module/network/components/NetworkSavedScreen.js +1 -222
- package/lib/module/network/components/NetworkSavedScreen.web.js +1 -461
- package/lib/module/network/components/NetworkUpgradeBanner.js +1 -72
- package/lib/module/network/components/response-editor/Explorer.js +1 -972
- package/lib/module/network/components/response-editor/Explorer.web.js +1 -1133
- package/lib/module/network/components/response-editor/deleteNestedDataByPath.js +1 -51
- package/lib/module/network/components/response-editor/editorContext.js +1 -29
- package/lib/module/network/components/response-editor/updateNestedDataByPath.js +1 -56
- package/lib/module/network/conditions/NetworkConditionsControl.js +1 -231
- package/lib/module/network/conditions/NetworkConditionsControl.test.js +1 -135
- package/lib/module/network/conditions/NetworkConditionsIcon.js +1 -29
- package/lib/module/network/conditions/NetworkFloatingTool.js +1 -304
- package/lib/module/network/conditions/NetworkFloatingTool.test.js +1 -218
- package/lib/module/network/conditions/store.js +1 -65
- package/lib/module/network/conditions/wait.js +1 -38
- package/lib/module/network/conditions/xhr.js +1 -131
- package/lib/module/network/hooks/useLiveNetworkEvent.js +1 -58
- package/lib/module/network/hooks/useNetworkBadgeCounts.js +1 -79
- package/lib/module/network/hooks/useNetworkEventList.js +1 -104
- package/lib/module/network/hooks/useNetworkEvents.js +1 -314
- package/lib/module/network/hooks/useNetworkHasMatches.js +1 -52
- package/lib/module/network/hooks/useNetworkSaved.js +1 -34
- package/lib/module/network/hooks/useNetworkSelection.js +1 -46
- package/lib/module/network/hooks/useOverrideRules.js +1 -32
- package/lib/module/network/hooks/useTickEveryMinute.js +1 -11
- package/lib/module/network/overrides/applyToFetch.js +1 -72
- package/lib/module/network/overrides/applyToXhr.js +2 -502
- package/lib/module/network/overrides/engine.js +1 -85
- package/lib/module/network/overrides/matchRule.js +1 -81
- package/lib/module/network/overrides/overriddenRows.js +1 -33
- package/lib/module/network/overrides/overrideRulesStore.js +1 -547
- package/lib/module/network/overrides/presets.js +1 -65
- package/lib/module/network/overrides/resolveOverride.js +1 -152
- package/lib/module/network/overrides/types.js +1 -86
- package/lib/module/network/sync/networkBodyResolver.js +1 -34
- package/lib/module/network/sync/networkSyncAdapter.js +1 -880
- package/lib/module/network/sync/overrideHonesty.release.test.js +1 -35
- package/lib/module/network/types/index.js +1 -3
- package/lib/module/network/utils/extractOperationName.js +1 -76
- package/lib/module/network/utils/filterNetworkEvents.js +1 -92
- package/lib/module/network/utils/formatGraphQLVariables.js +1 -213
- package/lib/module/network/utils/formatting.js +1 -9
- package/lib/module/network/utils/generateCurl.js +2 -67
- package/lib/module/network/utils/generateNetworkCopyText.js +37 -162
- package/lib/module/network/utils/httpCompletion.js +1 -32
- package/lib/module/network/utils/networkEventStore.js +1 -409
- package/lib/module/network/utils/networkListener.js +4 -1341
- package/lib/module/network/utils/networkSavedStore.js +3 -572
- package/lib/module/network/utils/networkSelectionStore.js +1 -188
- package/lib/module/network/utils/realNow.js +1 -0
- package/lib/module/network/utils/requestId.js +1 -12
- package/lib/module/network/utils/resolveRequestUrl.js +1 -11
- package/lib/module/network/utils/selectSavedEvents.js +1 -35
- package/lib/module/network/utils/startNetworkCapture.js +1 -21
- package/lib/module/network/utils/withPinnedFirst.js +1 -28
- package/lib/module/preset.js +1 -91
- package/lib/typescript/network/overrides/engine.d.ts +1 -1
- package/lib/typescript/network/overrides/matchRule.d.ts +1 -1
- package/lib/typescript/network/overrides/resolveOverride.d.ts +2 -2
- package/lib/typescript/network/overrides/types.d.ts +9 -0
- package/lib/typescript/network/utils/networkListener.d.ts +11 -0
- package/lib/typescript/network/utils/realNow.d.ts +18 -0
- package/lib/web/index.mjs +73 -74
- package/package.json +3 -6
- package/lib/typescript/index.d.ts.map +0 -1
- package/lib/typescript/index.web.d.ts.map +0 -1
- package/lib/typescript/network/components/DataViewer.web.d.ts.map +0 -1
- package/lib/typescript/network/components/NetworkCopyScreen.web.d.ts.map +0 -1
- package/lib/typescript/network/components/NetworkCopySettingsView.d.ts.map +0 -1
- package/lib/typescript/network/components/NetworkCopySettingsView.web.d.ts.map +0 -1
- package/lib/typescript/network/components/NetworkDetailScreen.web.d.ts.map +0 -1
- package/lib/typescript/network/components/NetworkDetailStepper.d.ts.map +0 -1
- package/lib/typescript/network/components/NetworkDetailStepper.web.d.ts.map +0 -1
- package/lib/typescript/network/components/NetworkEventDetailView.d.ts.map +0 -1
- package/lib/typescript/network/components/NetworkEventDetailView.web.d.ts.map +0 -1
- package/lib/typescript/network/components/NetworkEventItemCompact.d.ts.map +0 -1
- package/lib/typescript/network/components/NetworkEventItemCompact.web.d.ts.map +0 -1
- package/lib/typescript/network/components/NetworkFilterScreen.web.d.ts.map +0 -1
- package/lib/typescript/network/components/NetworkFilterViewV3.d.ts.map +0 -1
- package/lib/typescript/network/components/NetworkFilterViewV3.web.d.ts.map +0 -1
- package/lib/typescript/network/components/NetworkHeaderLive.d.ts.map +0 -1
- package/lib/typescript/network/components/NetworkHeaderLive.web.d.ts.map +0 -1
- package/lib/typescript/network/components/NetworkHeaderMenu.d.ts.map +0 -1
- package/lib/typescript/network/components/NetworkListScreen.d.ts.map +0 -1
- package/lib/typescript/network/components/NetworkListScreen.web.d.ts.map +0 -1
- package/lib/typescript/network/components/NetworkModal.d.ts.map +0 -1
- package/lib/typescript/network/components/NetworkNumberPrompt.d.ts.map +0 -1
- package/lib/typescript/network/components/NetworkNumberPrompt.web.d.ts.map +0 -1
- package/lib/typescript/network/components/NetworkOverrideEditor.d.ts.map +0 -1
- package/lib/typescript/network/components/NetworkOverrideEditor.web.d.ts.map +0 -1
- package/lib/typescript/network/components/NetworkOverrideHeaderButton.d.ts.map +0 -1
- package/lib/typescript/network/components/NetworkOverrideHeaderButton.web.d.ts.map +0 -1
- package/lib/typescript/network/components/NetworkOverridesButton.d.ts.map +0 -1
- package/lib/typescript/network/components/NetworkOverridesButton.web.d.ts.map +0 -1
- package/lib/typescript/network/components/NetworkOverridesScreen.d.ts.map +0 -1
- package/lib/typescript/network/components/NetworkOverridesScreen.web.d.ts.map +0 -1
- package/lib/typescript/network/components/NetworkSavedScreen.d.ts.map +0 -1
- package/lib/typescript/network/components/NetworkSavedScreen.web.d.ts.map +0 -1
- package/lib/typescript/network/components/NetworkUpgradeBanner.d.ts.map +0 -1
- package/lib/typescript/network/components/response-editor/Explorer.d.ts.map +0 -1
- package/lib/typescript/network/components/response-editor/Explorer.web.d.ts.map +0 -1
- package/lib/typescript/network/components/response-editor/deleteNestedDataByPath.d.ts.map +0 -1
- package/lib/typescript/network/components/response-editor/editorContext.d.ts.map +0 -1
- package/lib/typescript/network/components/response-editor/updateNestedDataByPath.d.ts.map +0 -1
- package/lib/typescript/network/conditions/NetworkConditionsControl.d.ts.map +0 -1
- package/lib/typescript/network/conditions/NetworkConditionsControl.test.d.ts.map +0 -1
- package/lib/typescript/network/conditions/NetworkConditionsIcon.d.ts.map +0 -1
- package/lib/typescript/network/conditions/NetworkFloatingTool.d.ts.map +0 -1
- package/lib/typescript/network/conditions/NetworkFloatingTool.test.d.ts.map +0 -1
- package/lib/typescript/network/conditions/store.d.ts.map +0 -1
- package/lib/typescript/network/conditions/wait.d.ts.map +0 -1
- package/lib/typescript/network/conditions/xhr.d.ts.map +0 -1
- package/lib/typescript/network/hooks/useLiveNetworkEvent.d.ts.map +0 -1
- package/lib/typescript/network/hooks/useNetworkBadgeCounts.d.ts.map +0 -1
- package/lib/typescript/network/hooks/useNetworkEventList.d.ts.map +0 -1
- package/lib/typescript/network/hooks/useNetworkEvents.d.ts.map +0 -1
- package/lib/typescript/network/hooks/useNetworkHasMatches.d.ts.map +0 -1
- package/lib/typescript/network/hooks/useNetworkSaved.d.ts.map +0 -1
- package/lib/typescript/network/hooks/useNetworkSelection.d.ts.map +0 -1
- package/lib/typescript/network/hooks/useOverrideRules.d.ts.map +0 -1
- package/lib/typescript/network/hooks/useTickEveryMinute.d.ts.map +0 -1
- package/lib/typescript/network/overrides/applyToFetch.d.ts.map +0 -1
- package/lib/typescript/network/overrides/applyToXhr.d.ts.map +0 -1
- package/lib/typescript/network/overrides/engine.d.ts.map +0 -1
- package/lib/typescript/network/overrides/matchRule.d.ts.map +0 -1
- package/lib/typescript/network/overrides/overriddenRows.d.ts.map +0 -1
- package/lib/typescript/network/overrides/overrideRulesStore.d.ts.map +0 -1
- package/lib/typescript/network/overrides/presets.d.ts.map +0 -1
- package/lib/typescript/network/overrides/resolveOverride.d.ts.map +0 -1
- package/lib/typescript/network/overrides/types.d.ts.map +0 -1
- package/lib/typescript/network/sync/networkBodyResolver.d.ts.map +0 -1
- package/lib/typescript/network/sync/networkSyncAdapter.d.ts.map +0 -1
- package/lib/typescript/network/sync/overrideHonesty.release.test.d.ts.map +0 -1
- package/lib/typescript/network/types/index.d.ts.map +0 -1
- package/lib/typescript/network/utils/extractOperationName.d.ts.map +0 -1
- package/lib/typescript/network/utils/filterNetworkEvents.d.ts.map +0 -1
- package/lib/typescript/network/utils/formatGraphQLVariables.d.ts.map +0 -1
- package/lib/typescript/network/utils/formatting.d.ts.map +0 -1
- package/lib/typescript/network/utils/generateCurl.d.ts.map +0 -1
- package/lib/typescript/network/utils/generateNetworkCopyText.d.ts.map +0 -1
- package/lib/typescript/network/utils/httpCompletion.d.ts.map +0 -1
- package/lib/typescript/network/utils/networkEventStore.d.ts.map +0 -1
- package/lib/typescript/network/utils/networkListener.d.ts.map +0 -1
- package/lib/typescript/network/utils/networkSavedStore.d.ts.map +0 -1
- package/lib/typescript/network/utils/networkSelectionStore.d.ts.map +0 -1
- package/lib/typescript/network/utils/requestId.d.ts.map +0 -1
- package/lib/typescript/network/utils/resolveRequestUrl.d.ts.map +0 -1
- package/lib/typescript/network/utils/selectSavedEvents.d.ts.map +0 -1
- package/lib/typescript/network/utils/startNetworkCapture.d.ts.map +0 -1
- package/lib/typescript/network/utils/withPinnedFirst.d.ts.map +0 -1
- package/lib/typescript/preset.d.ts.map +0 -1
|
@@ -1,310 +1 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
|
|
3
|
-
Object.defineProperty(exports, "__esModule", {
|
|
4
|
-
value: true
|
|
5
|
-
});
|
|
6
|
-
exports.NetworkFloatingTool = NetworkFloatingTool;
|
|
7
|
-
exports.createRemoteConditionsSource = createRemoteConditionsSource;
|
|
8
|
-
exports.openNetworkFloatingTool = openNetworkFloatingTool;
|
|
9
|
-
var _react = require("react");
|
|
10
|
-
var _reactNative = require("react-native");
|
|
11
|
-
var _sharedUi = require("@buoy-gg/shared-ui");
|
|
12
|
-
var _store = require("./store");
|
|
13
|
-
var _jsxRuntime = require("react/jsx-runtime");
|
|
14
|
-
/** A live source keeps the desktop strip current after its launching panel closes. */
|
|
15
|
-
function createRemoteConditionsSource() {
|
|
16
|
-
let value;
|
|
17
|
-
const listeners = new Set();
|
|
18
|
-
return {
|
|
19
|
-
getSnapshot: () => value,
|
|
20
|
-
subscribe: listener => {
|
|
21
|
-
listeners.add(listener);
|
|
22
|
-
return () => {
|
|
23
|
-
listeners.delete(listener);
|
|
24
|
-
};
|
|
25
|
-
},
|
|
26
|
-
update(next) {
|
|
27
|
-
value = next;
|
|
28
|
-
listeners.forEach(listener => listener());
|
|
29
|
-
}
|
|
30
|
-
};
|
|
31
|
-
}
|
|
32
|
-
const noSubscribe = () => () => {};
|
|
33
|
-
const noRemote = () => undefined;
|
|
34
|
-
const options = [{
|
|
35
|
-
id: "normal",
|
|
36
|
-
label: "No throttling",
|
|
37
|
-
detail: "No added delay"
|
|
38
|
-
}, {
|
|
39
|
-
id: "slow",
|
|
40
|
-
label: "Slow",
|
|
41
|
-
detail: "+500 ms before sending"
|
|
42
|
-
}, {
|
|
43
|
-
id: "verySlow",
|
|
44
|
-
label: "Very slow",
|
|
45
|
-
detail: "+2 seconds before sending"
|
|
46
|
-
}, {
|
|
47
|
-
id: "offline",
|
|
48
|
-
label: "Offline",
|
|
49
|
-
detail: "New requests fail"
|
|
50
|
-
}];
|
|
51
|
-
const localRegistration = {
|
|
52
|
-
id: "network-throttling",
|
|
53
|
-
render: context => /*#__PURE__*/(0, _jsxRuntime.jsx)(NetworkFloatingTool, {
|
|
54
|
-
...context
|
|
55
|
-
})
|
|
56
|
-
};
|
|
57
|
-
if (typeof __DEV__ !== "undefined" && __DEV__ && typeof navigator !== "undefined" && navigator.product === "ReactNative") {
|
|
58
|
-
(0, _sharedUi.registerPersistentFloatingTool)(localRegistration, _sharedUi.persistentStorage);
|
|
59
|
-
}
|
|
60
|
-
function openNetworkFloatingTool(source) {
|
|
61
|
-
(0, _sharedUi.openFloatingTool)({
|
|
62
|
-
id: "network-throttling",
|
|
63
|
-
render: context => /*#__PURE__*/(0, _jsxRuntime.jsx)(NetworkFloatingTool, {
|
|
64
|
-
...context,
|
|
65
|
-
source: source
|
|
66
|
-
})
|
|
67
|
-
});
|
|
68
|
-
}
|
|
69
|
-
function NetworkFloatingTool({
|
|
70
|
-
id,
|
|
71
|
-
revealToken,
|
|
72
|
-
dismiss,
|
|
73
|
-
source
|
|
74
|
-
}) {
|
|
75
|
-
const local = (0, _react.useSyncExternalStore)(_store.subscribeNetworkConditions, _store.getNetworkCondition, _store.getNetworkCondition);
|
|
76
|
-
const localAvailable = (0, _react.useSyncExternalStore)(_store.subscribeNetworkConditions, _store.conditionsCanApply, _store.conditionsCanApply);
|
|
77
|
-
const remote = (0, _react.useSyncExternalStore)(source?.subscribe ?? noSubscribe, source?.getSnapshot ?? noRemote, noRemote);
|
|
78
|
-
const profile = source ? remote?.profile ?? null : local;
|
|
79
|
-
const available = source ? remote?.available === true : localAvailable;
|
|
80
|
-
const [pending, setPending] = (0, _react.useState)(false);
|
|
81
|
-
const [error, setError] = (0, _react.useState)();
|
|
82
|
-
const busy = (0, _react.useRef)(false);
|
|
83
|
-
const operation = (0, _react.useRef)(0);
|
|
84
|
-
const mounted = (0, _react.useRef)(true);
|
|
85
|
-
const {
|
|
86
|
-
width
|
|
87
|
-
} = (0, _reactNative.useWindowDimensions)();
|
|
88
|
-
(0, _react.useEffect)(() => {
|
|
89
|
-
mounted.current = true;
|
|
90
|
-
return () => {
|
|
91
|
-
mounted.current = false;
|
|
92
|
-
};
|
|
93
|
-
}, []);
|
|
94
|
-
(0, _react.useEffect)(() => {
|
|
95
|
-
operation.current += 1;
|
|
96
|
-
busy.current = false;
|
|
97
|
-
setPending(false);
|
|
98
|
-
setError(undefined);
|
|
99
|
-
}, [source, remote?.targetId]);
|
|
100
|
-
const active = profile !== null && profile !== "normal";
|
|
101
|
-
const selected = profile ?? "normal";
|
|
102
|
-
const choice = options.find(option => option.id === selected);
|
|
103
|
-
const next = options[(options.findIndex(option => option.id === selected) + 1) % options.length];
|
|
104
|
-
const bars = !available || selected === "offline" ? 0 : selected === "verySlow" ? 1 : selected === "slow" ? 2 : 4;
|
|
105
|
-
const detail = pending ? "Applying…" : !available ? "Unavailable" : selected === "normal" ? "0 ms" : selected === "slow" ? "+500 ms" : selected === "verySlow" ? "+2000 ms" : "Blocked";
|
|
106
|
-
async function apply(next, close = false) {
|
|
107
|
-
if (busy.current) return;
|
|
108
|
-
const currentOperation = ++operation.current;
|
|
109
|
-
busy.current = true;
|
|
110
|
-
setPending(true);
|
|
111
|
-
setError(undefined);
|
|
112
|
-
const startingRemote = source?.getSnapshot();
|
|
113
|
-
try {
|
|
114
|
-
if (source) {
|
|
115
|
-
if (!startingRemote?.available) throw new Error("Device unavailable. Open Network again to reconnect these controls.");
|
|
116
|
-
await startingRemote.onChange(next);
|
|
117
|
-
} else (0, _store.setNetworkCondition)(next);
|
|
118
|
-
if (mounted.current && operation.current === currentOperation) {
|
|
119
|
-
if (close) dismiss();
|
|
120
|
-
}
|
|
121
|
-
} catch (failure) {
|
|
122
|
-
if (mounted.current && operation.current === currentOperation) setError(failure instanceof Error ? failure.message : String(failure));
|
|
123
|
-
} finally {
|
|
124
|
-
if (operation.current === currentOperation) {
|
|
125
|
-
busy.current = false;
|
|
126
|
-
if (mounted.current) setPending(false);
|
|
127
|
-
}
|
|
128
|
-
}
|
|
129
|
-
}
|
|
130
|
-
const accessory = error ? /*#__PURE__*/(0, _jsxRuntime.jsx)(_reactNative.View, {
|
|
131
|
-
style: styles.menu,
|
|
132
|
-
children: /*#__PURE__*/(0, _jsxRuntime.jsx)(_reactNative.Text, {
|
|
133
|
-
accessibilityRole: "alert",
|
|
134
|
-
style: styles.error,
|
|
135
|
-
children: error
|
|
136
|
-
})
|
|
137
|
-
}) : undefined;
|
|
138
|
-
return /*#__PURE__*/(0, _jsxRuntime.jsx)(_sharedUi.FloatingTool, {
|
|
139
|
-
id: id,
|
|
140
|
-
revealToken: revealToken,
|
|
141
|
-
variant: "strip",
|
|
142
|
-
dragFromSurface: true,
|
|
143
|
-
accessibilityLabel: `Move or hide network throttling. ${active ? "Active" : "Off"}`,
|
|
144
|
-
accessory: accessory,
|
|
145
|
-
children: /*#__PURE__*/(0, _jsxRuntime.jsxs)(_reactNative.View, {
|
|
146
|
-
style: [styles.row, {
|
|
147
|
-
width: Math.max(220, Math.min(292, width - 64))
|
|
148
|
-
}],
|
|
149
|
-
children: [/*#__PURE__*/(0, _jsxRuntime.jsx)(_reactNative.TouchableOpacity, {
|
|
150
|
-
testID: "throttling-cycle",
|
|
151
|
-
accessibilityRole: "button",
|
|
152
|
-
accessibilityLabel: `Network: ${choice.label}. Switch to ${next.label}`,
|
|
153
|
-
accessibilityState: {
|
|
154
|
-
disabled: pending || !available
|
|
155
|
-
},
|
|
156
|
-
disabled: pending || !available,
|
|
157
|
-
onPress: () => void apply(next.id),
|
|
158
|
-
style: styles.signalButton,
|
|
159
|
-
children: pending ? /*#__PURE__*/(0, _jsxRuntime.jsx)(_reactNative.ActivityIndicator, {
|
|
160
|
-
size: "small",
|
|
161
|
-
color: _sharedUi.night.color.accent
|
|
162
|
-
}) : /*#__PURE__*/(0, _jsxRuntime.jsxs)(_reactNative.View, {
|
|
163
|
-
testID: `throttling-signal-${selected}`,
|
|
164
|
-
style: styles.signal,
|
|
165
|
-
children: [[7, 12, 18, 24].map((height, index) => /*#__PURE__*/(0, _jsxRuntime.jsx)(_reactNative.View, {
|
|
166
|
-
style: {
|
|
167
|
-
width: 4,
|
|
168
|
-
height,
|
|
169
|
-
borderRadius: 2,
|
|
170
|
-
backgroundColor: index < bars ? selected === "offline" ? _sharedUi.night.color.danger : _sharedUi.night.color.accent : _sharedUi.night.color.fillTertiary
|
|
171
|
-
}
|
|
172
|
-
}, height)), selected === "offline" && /*#__PURE__*/(0, _jsxRuntime.jsx)(_reactNative.View, {
|
|
173
|
-
style: styles.slash
|
|
174
|
-
})]
|
|
175
|
-
})
|
|
176
|
-
}), /*#__PURE__*/(0, _jsxRuntime.jsx)(_reactNative.View, {
|
|
177
|
-
style: styles.profile,
|
|
178
|
-
children: /*#__PURE__*/(0, _jsxRuntime.jsx)(_reactNative.Text, {
|
|
179
|
-
testID: "throttling-profile",
|
|
180
|
-
accessibilityLabel: `Connection profile: ${choice.label}`,
|
|
181
|
-
accessibilityLiveRegion: "polite",
|
|
182
|
-
numberOfLines: 1,
|
|
183
|
-
style: styles.profileLabel,
|
|
184
|
-
children: choice.label
|
|
185
|
-
})
|
|
186
|
-
}), /*#__PURE__*/(0, _jsxRuntime.jsx)(_reactNative.Text, {
|
|
187
|
-
testID: "throttling-status",
|
|
188
|
-
numberOfLines: 1,
|
|
189
|
-
accessibilityLiveRegion: "polite",
|
|
190
|
-
style: styles.status,
|
|
191
|
-
children: detail
|
|
192
|
-
}), /*#__PURE__*/(0, _jsxRuntime.jsx)(_reactNative.View, {
|
|
193
|
-
style: styles.separator
|
|
194
|
-
}), /*#__PURE__*/(0, _jsxRuntime.jsx)(_reactNative.TouchableOpacity, {
|
|
195
|
-
testID: "throttling-close",
|
|
196
|
-
accessibilityRole: "button",
|
|
197
|
-
accessibilityLabel: "Close and turn off throttling",
|
|
198
|
-
disabled: pending,
|
|
199
|
-
accessibilityState: {
|
|
200
|
-
disabled: pending
|
|
201
|
-
},
|
|
202
|
-
onPress: () => {
|
|
203
|
-
if (profile === "normal") dismiss();else void apply("normal", true);
|
|
204
|
-
},
|
|
205
|
-
style: [styles.action, pending && styles.disabled],
|
|
206
|
-
children: /*#__PURE__*/(0, _jsxRuntime.jsx)(_reactNative.Text, {
|
|
207
|
-
style: styles.actionText,
|
|
208
|
-
children: "Close"
|
|
209
|
-
})
|
|
210
|
-
})]
|
|
211
|
-
})
|
|
212
|
-
});
|
|
213
|
-
}
|
|
214
|
-
const styles = _reactNative.StyleSheet.create({
|
|
215
|
-
row: {
|
|
216
|
-
flexDirection: "row",
|
|
217
|
-
alignItems: "center",
|
|
218
|
-
gap: 6,
|
|
219
|
-
paddingVertical: 4,
|
|
220
|
-
minHeight: 48
|
|
221
|
-
},
|
|
222
|
-
signalButton: {
|
|
223
|
-
width: 36,
|
|
224
|
-
minHeight: 44,
|
|
225
|
-
alignItems: "center",
|
|
226
|
-
justifyContent: "center"
|
|
227
|
-
},
|
|
228
|
-
signal: {
|
|
229
|
-
flexDirection: "row",
|
|
230
|
-
alignItems: "flex-end",
|
|
231
|
-
gap: 3,
|
|
232
|
-
height: 24
|
|
233
|
-
},
|
|
234
|
-
slash: {
|
|
235
|
-
position: "absolute",
|
|
236
|
-
width: 30,
|
|
237
|
-
height: 2,
|
|
238
|
-
backgroundColor: _sharedUi.night.color.danger,
|
|
239
|
-
top: 11,
|
|
240
|
-
left: -2,
|
|
241
|
-
transform: [{
|
|
242
|
-
rotate: "-45deg"
|
|
243
|
-
}]
|
|
244
|
-
},
|
|
245
|
-
separator: {
|
|
246
|
-
height: 20,
|
|
247
|
-
width: 1,
|
|
248
|
-
backgroundColor: _sharedUi.night.color.separator,
|
|
249
|
-
marginHorizontal: 2
|
|
250
|
-
},
|
|
251
|
-
status: {
|
|
252
|
-
color: _sharedUi.night.color.textSecondary,
|
|
253
|
-
fontSize: 10,
|
|
254
|
-
lineHeight: 15,
|
|
255
|
-
flexShrink: 1
|
|
256
|
-
},
|
|
257
|
-
profile: {
|
|
258
|
-
flex: 1,
|
|
259
|
-
flexDirection: "row",
|
|
260
|
-
alignItems: "center",
|
|
261
|
-
gap: 6,
|
|
262
|
-
minHeight: 44
|
|
263
|
-
},
|
|
264
|
-
profileLabel: {
|
|
265
|
-
color: _sharedUi.night.color.text,
|
|
266
|
-
fontSize: 13,
|
|
267
|
-
fontWeight: "500",
|
|
268
|
-
flexShrink: 1
|
|
269
|
-
},
|
|
270
|
-
action: {
|
|
271
|
-
minHeight: 36,
|
|
272
|
-
minWidth: 52,
|
|
273
|
-
borderRadius: _sharedUi.night.radius.input,
|
|
274
|
-
borderWidth: 1,
|
|
275
|
-
borderColor: _sharedUi.night.color.accentBorderStrong,
|
|
276
|
-
alignItems: "center",
|
|
277
|
-
justifyContent: "center",
|
|
278
|
-
paddingHorizontal: 10
|
|
279
|
-
},
|
|
280
|
-
actionText: {
|
|
281
|
-
color: _sharedUi.night.color.accent,
|
|
282
|
-
fontSize: 12,
|
|
283
|
-
fontWeight: "600"
|
|
284
|
-
},
|
|
285
|
-
disabled: {
|
|
286
|
-
opacity: 0.4
|
|
287
|
-
},
|
|
288
|
-
menu: {
|
|
289
|
-
marginVertical: 8,
|
|
290
|
-
padding: 6,
|
|
291
|
-
borderRadius: _sharedUi.night.radius.card,
|
|
292
|
-
borderWidth: 1,
|
|
293
|
-
borderColor: _sharedUi.night.color.separator,
|
|
294
|
-
backgroundColor: _sharedUi.night.color.surface,
|
|
295
|
-
shadowColor: "#000",
|
|
296
|
-
shadowOffset: {
|
|
297
|
-
width: 0,
|
|
298
|
-
height: 6
|
|
299
|
-
},
|
|
300
|
-
shadowOpacity: 0.25,
|
|
301
|
-
shadowRadius: 16,
|
|
302
|
-
elevation: 8
|
|
303
|
-
},
|
|
304
|
-
error: {
|
|
305
|
-
color: _sharedUi.night.color.danger,
|
|
306
|
-
fontSize: 12,
|
|
307
|
-
lineHeight: 18,
|
|
308
|
-
padding: 10
|
|
309
|
-
}
|
|
310
|
-
});
|
|
1
|
+
"use strict";Object.defineProperty(exports,"__esModule",{value:true});exports.NetworkFloatingTool=NetworkFloatingTool;exports.createRemoteConditionsSource=createRemoteConditionsSource;exports.openNetworkFloatingTool=openNetworkFloatingTool;var _react=require("react");var _reactNative=require("react-native");var _sharedUi=require("@buoy-gg/shared-ui");var _store=require("./store");var _jsxRuntime=require("react/jsx-runtime");function createRemoteConditionsSource(){let i;const n=new Set;return{getSnapshot:()=>i,subscribe:r=>{n.add(r);return()=>{n.delete(r)}},update(r){i=r;n.forEach(t=>t())}}}const noSubscribe=()=>()=>{};const noRemote=()=>void 0;const options=[{id:"normal",label:"No throttling",detail:"No added delay"},{id:"slow",label:"Slow",detail:"+500 ms before sending"},{id:"verySlow",label:"Very slow",detail:"+2 seconds before sending"},{id:"offline",label:"Offline",detail:"New requests fail"}];const localRegistration={id:"network-throttling",render:i=>(0,_jsxRuntime.jsx)(NetworkFloatingTool,{...i})};if(typeof __DEV__!=="undefined"&&__DEV__&&typeof navigator!=="undefined"&&navigator.product==="ReactNative"){(0,_sharedUi.registerPersistentFloatingTool)(localRegistration,_sharedUi.persistentStorage)}function openNetworkFloatingTool(i){(0,_sharedUi.openFloatingTool)({id:"network-throttling",render:n=>(0,_jsxRuntime.jsx)(NetworkFloatingTool,{...n,source:i})})}function NetworkFloatingTool({id:i,revealToken:n,dismiss:r,source:t}){const j=(0,_react.useSyncExternalStore)(_store.subscribeNetworkConditions,_store.getNetworkCondition,_store.getNetworkCondition);const k=(0,_react.useSyncExternalStore)(_store.subscribeNetworkConditions,_store.conditionsCanApply,_store.conditionsCanApply);const g=(0,_react.useSyncExternalStore)(t?.subscribe??noSubscribe,t?.getSnapshot??noRemote,noRemote);const c=t?g?.profile??null:j;const d=t?g?.available===true:k;const[l,f]=(0,_react.useState)(false);const[x,h]=(0,_react.useState)();const u=(0,_react.useRef)(false);const s=(0,_react.useRef)(0);const a=(0,_react.useRef)(true);const{width:C}=(0,_reactNative.useWindowDimensions)();(0,_react.useEffect)(()=>{a.current=true;return()=>{a.current=false}},[]);(0,_react.useEffect)(()=>{s.current+=1;u.current=false;f(false);h(void 0)},[t,g?.targetId]);const R=c!==null&&c!=="normal";const e=c??"normal";const b=options.find(o=>o.id===e);const m=options[(options.findIndex(o=>o.id===e)+1)%options.length];const T=!d||e==="offline"?0:e==="verySlow"?1:e==="slow"?2:4;const N=l?"Applying\u2026":!d?"Unavailable":e==="normal"?"0 ms":e==="slow"?"+500 ms":e==="verySlow"?"+2000 ms":"Blocked";async function S(o,p=false){if(u.current)return;const y=++s.current;u.current=true;f(true);h(void 0);const v=t?.getSnapshot();try{if(t){if(!v?.available)throw new Error("Device unavailable. Open Network again to reconnect these controls.");await v.onChange(o)}else(0,_store.setNetworkCondition)(o);if(a.current&&s.current===y){if(p)r()}}catch(w){if(a.current&&s.current===y)h(w instanceof Error?w.message:String(w))}finally{if(s.current===y){u.current=false;if(a.current)f(false)}}}const _=x?(0,_jsxRuntime.jsx)(_reactNative.View,{style:styles.menu,children:(0,_jsxRuntime.jsx)(_reactNative.Text,{accessibilityRole:"alert",style:styles.error,children:x})}):void 0;return(0,_jsxRuntime.jsx)(_sharedUi.FloatingTool,{id:i,revealToken:n,variant:"strip",dragFromSurface:true,accessibilityLabel:`Move or hide network throttling. ${R?"Active":"Off"}`,accessory:_,children:(0,_jsxRuntime.jsxs)(_reactNative.View,{style:[styles.row,{width:Math.max(220,Math.min(292,C-64))}],children:[(0,_jsxRuntime.jsx)(_reactNative.TouchableOpacity,{testID:"throttling-cycle",accessibilityRole:"button",accessibilityLabel:`Network: ${b.label}. Switch to ${m.label}`,accessibilityState:{disabled:l||!d},disabled:l||!d,onPress:()=>void S(m.id),style:styles.signalButton,children:l?(0,_jsxRuntime.jsx)(_reactNative.ActivityIndicator,{size:"small",color:_sharedUi.night.color.accent}):(0,_jsxRuntime.jsxs)(_reactNative.View,{testID:`throttling-signal-${e}`,style:styles.signal,children:[[7,12,18,24].map((o,p)=>(0,_jsxRuntime.jsx)(_reactNative.View,{style:{width:4,height:o,borderRadius:2,backgroundColor:p<T?e==="offline"?_sharedUi.night.color.danger:_sharedUi.night.color.accent:_sharedUi.night.color.fillTertiary}},o)),e==="offline"&&(0,_jsxRuntime.jsx)(_reactNative.View,{style:styles.slash})]})}),(0,_jsxRuntime.jsx)(_reactNative.View,{style:styles.profile,children:(0,_jsxRuntime.jsx)(_reactNative.Text,{testID:"throttling-profile",accessibilityLabel:`Connection profile: ${b.label}`,accessibilityLiveRegion:"polite",numberOfLines:1,style:styles.profileLabel,children:b.label})}),(0,_jsxRuntime.jsx)(_reactNative.Text,{testID:"throttling-status",numberOfLines:1,accessibilityLiveRegion:"polite",style:styles.status,children:N}),(0,_jsxRuntime.jsx)(_reactNative.View,{style:styles.separator}),(0,_jsxRuntime.jsx)(_reactNative.TouchableOpacity,{testID:"throttling-close",accessibilityRole:"button",accessibilityLabel:"Close and turn off throttling",disabled:l,accessibilityState:{disabled:l},onPress:()=>{if(c==="normal")r();else void S("normal",true)},style:[styles.action,l&&styles.disabled],children:(0,_jsxRuntime.jsx)(_reactNative.Text,{style:styles.actionText,children:"Close"})})]})})}const styles=_reactNative.StyleSheet.create({row:{flexDirection:"row",alignItems:"center",gap:6,paddingVertical:4,minHeight:48},signalButton:{width:36,minHeight:44,alignItems:"center",justifyContent:"center"},signal:{flexDirection:"row",alignItems:"flex-end",gap:3,height:24},slash:{position:"absolute",width:30,height:2,backgroundColor:_sharedUi.night.color.danger,top:11,left:-2,transform:[{rotate:"-45deg"}]},separator:{height:20,width:1,backgroundColor:_sharedUi.night.color.separator,marginHorizontal:2},status:{color:_sharedUi.night.color.textSecondary,fontSize:10,lineHeight:15,flexShrink:1},profile:{flex:1,flexDirection:"row",alignItems:"center",gap:6,minHeight:44},profileLabel:{color:_sharedUi.night.color.text,fontSize:13,fontWeight:"500",flexShrink:1},action:{minHeight:36,minWidth:52,borderRadius:_sharedUi.night.radius.input,borderWidth:1,borderColor:_sharedUi.night.color.accentBorderStrong,alignItems:"center",justifyContent:"center",paddingHorizontal:10},actionText:{color:_sharedUi.night.color.accent,fontSize:12,fontWeight:"600"},disabled:{opacity:.4},menu:{marginVertical:8,padding:6,borderRadius:_sharedUi.night.radius.card,borderWidth:1,borderColor:_sharedUi.night.color.separator,backgroundColor:_sharedUi.night.color.surface,shadowColor:"#000",shadowOffset:{width:0,height:6},shadowOpacity:.25,shadowRadius:16,elevation:8},error:{color:_sharedUi.night.color.danger,fontSize:12,lineHeight:18,padding:10}});
|
|
@@ -1,219 +1 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
|
|
3
|
-
var _react = require("react");
|
|
4
|
-
var _client = require("react-dom/client");
|
|
5
|
-
var _vitest = require("vitest");
|
|
6
|
-
var _NetworkFloatingTool = require("./NetworkFloatingTool");
|
|
7
|
-
// @vitest-environment jsdom
|
|
8
|
-
|
|
9
|
-
const state = _vitest.vi.hoisted(() => ({
|
|
10
|
-
profile: "normal",
|
|
11
|
-
available: true,
|
|
12
|
-
listeners: new Set(),
|
|
13
|
-
set: _vitest.vi.fn()
|
|
14
|
-
}));
|
|
15
|
-
_vitest.vi.mock("./store", () => ({
|
|
16
|
-
getNetworkCondition: () => state.profile,
|
|
17
|
-
conditionsCanApply: () => state.available,
|
|
18
|
-
subscribeNetworkConditions: listener => {
|
|
19
|
-
state.listeners.add(listener);
|
|
20
|
-
return () => state.listeners.delete(listener);
|
|
21
|
-
},
|
|
22
|
-
setNetworkCondition: profile => {
|
|
23
|
-
state.set(profile);
|
|
24
|
-
state.profile = profile;
|
|
25
|
-
state.listeners.forEach(listener => listener());
|
|
26
|
-
}
|
|
27
|
-
}));
|
|
28
|
-
_vitest.vi.mock("@buoy-gg/shared-ui", async () => ({
|
|
29
|
-
night: (await _vitest.vi.importActual("../../../../shared/src/ui/night/nightTheme")).night,
|
|
30
|
-
ChevronDown: () => null,
|
|
31
|
-
Check: () => null,
|
|
32
|
-
openFloatingTool: _vitest.vi.fn(),
|
|
33
|
-
FloatingTool: ({
|
|
34
|
-
children,
|
|
35
|
-
accessory
|
|
36
|
-
}) => /*#__PURE__*/(0, _react.createElement)("div", null, children, accessory)
|
|
37
|
-
}));
|
|
38
|
-
_vitest.vi.mock("react-native", () => ({
|
|
39
|
-
StyleSheet: {
|
|
40
|
-
create: value => value
|
|
41
|
-
},
|
|
42
|
-
useWindowDimensions: () => ({
|
|
43
|
-
width: 390,
|
|
44
|
-
height: 844
|
|
45
|
-
}),
|
|
46
|
-
View: ({
|
|
47
|
-
children,
|
|
48
|
-
testID
|
|
49
|
-
}) => /*#__PURE__*/(0, _react.createElement)("div", {
|
|
50
|
-
"data-testid": testID
|
|
51
|
-
}, children),
|
|
52
|
-
Text: ({
|
|
53
|
-
children,
|
|
54
|
-
testID
|
|
55
|
-
}) => /*#__PURE__*/(0, _react.createElement)("span", {
|
|
56
|
-
"data-testid": testID
|
|
57
|
-
}, children),
|
|
58
|
-
ActivityIndicator: () => null,
|
|
59
|
-
TouchableOpacity: ({
|
|
60
|
-
children,
|
|
61
|
-
onPress,
|
|
62
|
-
disabled,
|
|
63
|
-
testID,
|
|
64
|
-
accessibilityLabel
|
|
65
|
-
}) => /*#__PURE__*/(0, _react.createElement)("button", {
|
|
66
|
-
onClick: onPress,
|
|
67
|
-
disabled,
|
|
68
|
-
"data-testid": testID,
|
|
69
|
-
"aria-label": accessibilityLabel
|
|
70
|
-
}, children)
|
|
71
|
-
}));
|
|
72
|
-
let root;
|
|
73
|
-
let container;
|
|
74
|
-
const dismiss = _vitest.vi.fn();
|
|
75
|
-
(0, _vitest.beforeEach)(() => {
|
|
76
|
-
globalThis.IS_REACT_ACT_ENVIRONMENT = true;
|
|
77
|
-
state.profile = "normal";
|
|
78
|
-
state.available = true;
|
|
79
|
-
state.set.mockClear();
|
|
80
|
-
dismiss.mockClear();
|
|
81
|
-
container = document.createElement("div");
|
|
82
|
-
root = (0, _client.createRoot)(container);
|
|
83
|
-
});
|
|
84
|
-
(0, _vitest.afterEach)(() => (0, _react.act)(() => root.unmount()));
|
|
85
|
-
const button = id => container.querySelector(`[data-testid="${id}"]`);
|
|
86
|
-
const tap = async id => (0, _react.act)(async () => button(id).click());
|
|
87
|
-
const status = () => container.querySelector('[data-testid="throttling-status"]')?.textContent;
|
|
88
|
-
function render(source) {
|
|
89
|
-
(0, _react.act)(() => root.render(/*#__PURE__*/(0, _react.createElement)(_NetworkFloatingTool.NetworkFloatingTool, {
|
|
90
|
-
id: "network-throttling",
|
|
91
|
-
revealToken: 1,
|
|
92
|
-
dismiss,
|
|
93
|
-
source
|
|
94
|
-
})));
|
|
95
|
-
}
|
|
96
|
-
async function choose(value) {
|
|
97
|
-
const order = ["normal", "slow", "verySlow", "offline"];
|
|
98
|
-
const count = (order.indexOf(value) - order.indexOf(state.profile) + order.length) % order.length;
|
|
99
|
-
for (let i = 0; i < count; i++) await tap("throttling-cycle");
|
|
100
|
-
}
|
|
101
|
-
(0, _vitest.it)("cycles and applies every profile immediately, including wrapping to normal", async () => {
|
|
102
|
-
render();
|
|
103
|
-
for (const [profile, label] of [["slow", "+500 ms"], ["verySlow", "+2000 ms"], ["offline", "Blocked"], ["normal", "0 ms"]]) {
|
|
104
|
-
await tap("throttling-cycle");
|
|
105
|
-
(0, _vitest.expect)(state.profile).toBe(profile);
|
|
106
|
-
(0, _vitest.expect)(container.querySelector(`[data-testid="throttling-signal-${profile}"]`)).not.toBeNull();
|
|
107
|
-
(0, _vitest.expect)(status()).toBe(label);
|
|
108
|
-
}
|
|
109
|
-
(0, _vitest.expect)(state.set).toHaveBeenCalledTimes(4);
|
|
110
|
-
});
|
|
111
|
-
(0, _vitest.it)("keeps the profile label informational when tapped", async () => {
|
|
112
|
-
render();
|
|
113
|
-
await tap("throttling-profile");
|
|
114
|
-
(0, _vitest.expect)(state.set).not.toHaveBeenCalled();
|
|
115
|
-
(0, _vitest.expect)(state.profile).toBe("normal");
|
|
116
|
-
(0, _vitest.expect)(button("throttling-profile").closest("button")).toBeNull();
|
|
117
|
-
});
|
|
118
|
-
(0, _vitest.it)("changes active profiles and stops before dismissal", async () => {
|
|
119
|
-
state.profile = "slow";
|
|
120
|
-
render();
|
|
121
|
-
await choose("offline");
|
|
122
|
-
(0, _vitest.expect)(state.profile).toBe("offline");
|
|
123
|
-
await tap("throttling-close");
|
|
124
|
-
(0, _vitest.expect)(state.profile).toBe("normal");
|
|
125
|
-
(0, _vitest.expect)(dismiss).toHaveBeenCalledOnce();
|
|
126
|
-
});
|
|
127
|
-
(0, _vitest.it)("reflects external changes and disables cycling when account admission is revoked", () => {
|
|
128
|
-
render();
|
|
129
|
-
(0, _react.act)(() => {
|
|
130
|
-
state.profile = "offline";
|
|
131
|
-
state.listeners.forEach(listener => listener());
|
|
132
|
-
});
|
|
133
|
-
(0, _vitest.expect)(status()).toBe("Blocked");
|
|
134
|
-
(0, _react.act)(() => {
|
|
135
|
-
state.profile = "normal";
|
|
136
|
-
state.available = false;
|
|
137
|
-
state.listeners.forEach(listener => listener());
|
|
138
|
-
});
|
|
139
|
-
(0, _vitest.expect)(status()).toBe("Unavailable");
|
|
140
|
-
(0, _vitest.expect)(button("throttling-cycle").disabled).toBe(true);
|
|
141
|
-
});
|
|
142
|
-
(0, _vitest.it)("keeps remote failures visible and does not claim a profile was applied", async () => {
|
|
143
|
-
const source = (0, _NetworkFloatingTool.createRemoteConditionsSource)();
|
|
144
|
-
const onChange = _vitest.vi.fn().mockRejectedValue(new Error("Connection lost"));
|
|
145
|
-
source.update({
|
|
146
|
-
profile: "normal",
|
|
147
|
-
available: true,
|
|
148
|
-
onChange
|
|
149
|
-
});
|
|
150
|
-
render(source);
|
|
151
|
-
await choose("slow");
|
|
152
|
-
(0, _vitest.expect)(container.textContent).toContain("Connection lost");
|
|
153
|
-
(0, _vitest.expect)(status()).toBe("0 ms");
|
|
154
|
-
(0, _vitest.expect)(state.set).not.toHaveBeenCalled();
|
|
155
|
-
});
|
|
156
|
-
(0, _vitest.it)("prevents duplicate remote operations and follows confirmed snapshots", async () => {
|
|
157
|
-
const source = (0, _NetworkFloatingTool.createRemoteConditionsSource)();
|
|
158
|
-
let resolve;
|
|
159
|
-
const onChange = _vitest.vi.fn(() => new Promise(done => {
|
|
160
|
-
resolve = done;
|
|
161
|
-
}));
|
|
162
|
-
source.update({
|
|
163
|
-
profile: "normal",
|
|
164
|
-
available: true,
|
|
165
|
-
onChange
|
|
166
|
-
});
|
|
167
|
-
render(source);
|
|
168
|
-
await tap("throttling-cycle");
|
|
169
|
-
await tap("throttling-cycle");
|
|
170
|
-
(0, _vitest.expect)(onChange).toHaveBeenCalledOnce();
|
|
171
|
-
(0, _vitest.expect)(status()).toBe("Applying…");
|
|
172
|
-
await (0, _react.act)(async () => resolve());
|
|
173
|
-
(0, _vitest.expect)(status()).toBe("0 ms");
|
|
174
|
-
(0, _react.act)(() => source.update({
|
|
175
|
-
profile: "slow",
|
|
176
|
-
available: true,
|
|
177
|
-
onChange
|
|
178
|
-
}));
|
|
179
|
-
(0, _vitest.expect)(status()).toBe("+500 ms");
|
|
180
|
-
(0, _react.act)(() => source.update(undefined));
|
|
181
|
-
(0, _vitest.expect)(status()).toBe("Unavailable");
|
|
182
|
-
});
|
|
183
|
-
(0, _vitest.it)("ignores a previous device's completion after switching devices", async () => {
|
|
184
|
-
const source = (0, _NetworkFloatingTool.createRemoteConditionsSource)();
|
|
185
|
-
let reject;
|
|
186
|
-
source.update({
|
|
187
|
-
targetId: "first",
|
|
188
|
-
profile: "normal",
|
|
189
|
-
available: true,
|
|
190
|
-
onChange: () => new Promise((_resolve, fail) => {
|
|
191
|
-
reject = fail;
|
|
192
|
-
})
|
|
193
|
-
});
|
|
194
|
-
render(source);
|
|
195
|
-
await choose("slow");
|
|
196
|
-
(0, _react.act)(() => source.update({
|
|
197
|
-
targetId: "second",
|
|
198
|
-
profile: "normal",
|
|
199
|
-
available: true,
|
|
200
|
-
onChange: _vitest.vi.fn()
|
|
201
|
-
}));
|
|
202
|
-
await (0, _react.act)(async () => reject(new Error("Old device failed")));
|
|
203
|
-
(0, _vitest.expect)(container.textContent).not.toContain("Old device failed");
|
|
204
|
-
(0, _vitest.expect)(status()).toBe("0 ms");
|
|
205
|
-
(0, _vitest.expect)(button("throttling-profile").textContent).toBe("No throttling");
|
|
206
|
-
});
|
|
207
|
-
(0, _vitest.it)("keeps the strip open when stopping a remote device fails", async () => {
|
|
208
|
-
const source = (0, _NetworkFloatingTool.createRemoteConditionsSource)();
|
|
209
|
-
source.update({
|
|
210
|
-
profile: "offline",
|
|
211
|
-
available: true,
|
|
212
|
-
onChange: _vitest.vi.fn().mockRejectedValue(new Error("Could not stop"))
|
|
213
|
-
});
|
|
214
|
-
render(source);
|
|
215
|
-
await tap("throttling-close");
|
|
216
|
-
(0, _vitest.expect)(dismiss).not.toHaveBeenCalled();
|
|
217
|
-
(0, _vitest.expect)(status()).toBe("Blocked");
|
|
218
|
-
(0, _vitest.expect)(container.textContent).toContain("Could not stop");
|
|
219
|
-
});
|
|
1
|
+
"use strict";var _react=require("react");var _client=require("react-dom/client");var _vitest=require("vitest");var _NetworkFloatingTool=require("./NetworkFloatingTool");const state=_vitest.vi.hoisted(()=>({profile:"normal",available:true,listeners:new Set,set:_vitest.vi.fn()}));_vitest.vi.mock("./store",()=>({getNetworkCondition:()=>state.profile,conditionsCanApply:()=>state.available,subscribeNetworkConditions:e=>{state.listeners.add(e);return()=>state.listeners.delete(e)},setNetworkCondition:e=>{state.set(e);state.profile=e;state.listeners.forEach(t=>t())}}));_vitest.vi.mock("@buoy-gg/shared-ui",async()=>({night:(await _vitest.vi.importActual("../../../../shared/src/ui/night/nightTheme")).night,ChevronDown:()=>null,Check:()=>null,openFloatingTool:_vitest.vi.fn(),FloatingTool:({children:e,accessory:t})=>(0,_react.createElement)("div",null,e,t)}));_vitest.vi.mock("react-native",()=>({StyleSheet:{create:e=>e},useWindowDimensions:()=>({width:390,height:844}),View:({children:e,testID:t})=>(0,_react.createElement)("div",{"data-testid":t},e),Text:({children:e,testID:t})=>(0,_react.createElement)("span",{"data-testid":t},e),ActivityIndicator:()=>null,TouchableOpacity:({children:e,onPress:t,disabled:o,testID:a,accessibilityLabel:n})=>(0,_react.createElement)("button",{onClick:t,disabled:o,"data-testid":a,"aria-label":n},e)}));let root;let container;const dismiss=_vitest.vi.fn();(0,_vitest.beforeEach)(()=>{globalThis.IS_REACT_ACT_ENVIRONMENT=true;state.profile="normal";state.available=true;state.set.mockClear();dismiss.mockClear();container=document.createElement("div");root=(0,_client.createRoot)(container)});(0,_vitest.afterEach)(()=>(0,_react.act)(()=>root.unmount()));const button=e=>container.querySelector(`[data-testid="${e}"]`);const tap=async e=>(0,_react.act)(async()=>button(e).click());const status=()=>container.querySelector('[data-testid="throttling-status"]')?.textContent;function render(e){(0,_react.act)(()=>root.render((0,_react.createElement)(_NetworkFloatingTool.NetworkFloatingTool,{id:"network-throttling",revealToken:1,dismiss,source:e})))}async function choose(e){const t=["normal","slow","verySlow","offline"];const o=(t.indexOf(e)-t.indexOf(state.profile)+t.length)%t.length;for(let a=0;a<o;a++)await tap("throttling-cycle")}(0,_vitest.it)("cycles and applies every profile immediately, including wrapping to normal",async()=>{render();for(const[e,t]of[["slow","+500 ms"],["verySlow","+2000 ms"],["offline","Blocked"],["normal","0 ms"]]){await tap("throttling-cycle");(0,_vitest.expect)(state.profile).toBe(e);(0,_vitest.expect)(container.querySelector(`[data-testid="throttling-signal-${e}"]`)).not.toBeNull();(0,_vitest.expect)(status()).toBe(t)}(0,_vitest.expect)(state.set).toHaveBeenCalledTimes(4)});(0,_vitest.it)("keeps the profile label informational when tapped",async()=>{render();await tap("throttling-profile");(0,_vitest.expect)(state.set).not.toHaveBeenCalled();(0,_vitest.expect)(state.profile).toBe("normal");(0,_vitest.expect)(button("throttling-profile").closest("button")).toBeNull()});(0,_vitest.it)("changes active profiles and stops before dismissal",async()=>{state.profile="slow";render();await choose("offline");(0,_vitest.expect)(state.profile).toBe("offline");await tap("throttling-close");(0,_vitest.expect)(state.profile).toBe("normal");(0,_vitest.expect)(dismiss).toHaveBeenCalledOnce()});(0,_vitest.it)("reflects external changes and disables cycling when account admission is revoked",()=>{render();(0,_react.act)(()=>{state.profile="offline";state.listeners.forEach(e=>e())});(0,_vitest.expect)(status()).toBe("Blocked");(0,_react.act)(()=>{state.profile="normal";state.available=false;state.listeners.forEach(e=>e())});(0,_vitest.expect)(status()).toBe("Unavailable");(0,_vitest.expect)(button("throttling-cycle").disabled).toBe(true)});(0,_vitest.it)("keeps remote failures visible and does not claim a profile was applied",async()=>{const e=(0,_NetworkFloatingTool.createRemoteConditionsSource)();const t=_vitest.vi.fn().mockRejectedValue(new Error("Connection lost"));e.update({profile:"normal",available:true,onChange:t});render(e);await choose("slow");(0,_vitest.expect)(container.textContent).toContain("Connection lost");(0,_vitest.expect)(status()).toBe("0 ms");(0,_vitest.expect)(state.set).not.toHaveBeenCalled()});(0,_vitest.it)("prevents duplicate remote operations and follows confirmed snapshots",async()=>{const e=(0,_NetworkFloatingTool.createRemoteConditionsSource)();let t;const o=_vitest.vi.fn(()=>new Promise(a=>{t=a}));e.update({profile:"normal",available:true,onChange:o});render(e);await tap("throttling-cycle");await tap("throttling-cycle");(0,_vitest.expect)(o).toHaveBeenCalledOnce();(0,_vitest.expect)(status()).toBe("Applying\u2026");await(0,_react.act)(async()=>t());(0,_vitest.expect)(status()).toBe("0 ms");(0,_react.act)(()=>e.update({profile:"slow",available:true,onChange:o}));(0,_vitest.expect)(status()).toBe("+500 ms");(0,_react.act)(()=>e.update(void 0));(0,_vitest.expect)(status()).toBe("Unavailable")});(0,_vitest.it)("ignores a previous device's completion after switching devices",async()=>{const e=(0,_NetworkFloatingTool.createRemoteConditionsSource)();let t;e.update({targetId:"first",profile:"normal",available:true,onChange:()=>new Promise((o,a)=>{t=a})});render(e);await choose("slow");(0,_react.act)(()=>e.update({targetId:"second",profile:"normal",available:true,onChange:_vitest.vi.fn()}));await(0,_react.act)(async()=>t(new Error("Old device failed")));(0,_vitest.expect)(container.textContent).not.toContain("Old device failed");(0,_vitest.expect)(status()).toBe("0 ms");(0,_vitest.expect)(button("throttling-profile").textContent).toBe("No throttling")});(0,_vitest.it)("keeps the strip open when stopping a remote device fails",async()=>{const e=(0,_NetworkFloatingTool.createRemoteConditionsSource)();e.update({profile:"offline",available:true,onChange:_vitest.vi.fn().mockRejectedValue(new Error("Could not stop"))});render(e);await tap("throttling-close");(0,_vitest.expect)(dismiss).not.toHaveBeenCalled();(0,_vitest.expect)(status()).toBe("Blocked");(0,_vitest.expect)(container.textContent).toContain("Could not stop")});
|
|
@@ -1,75 +1 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
|
|
3
|
-
Object.defineProperty(exports, "__esModule", {
|
|
4
|
-
value: true
|
|
5
|
-
});
|
|
6
|
-
exports.networkConditionsRuntimeId = exports.getNetworkCondition = exports.conditionsCanApply = exports.NETWORK_CONDITIONS = void 0;
|
|
7
|
-
exports.setNetworkCondition = setNetworkCondition;
|
|
8
|
-
exports.snapshotNetworkCondition = snapshotNetworkCondition;
|
|
9
|
-
exports.subscribeNetworkConditions = void 0;
|
|
10
|
-
var _sharedUi = require("@buoy-gg/shared-ui");
|
|
11
|
-
var _networkListener = require("../utils/networkListener");
|
|
12
|
-
const NETWORK_CONDITIONS = exports.NETWORK_CONDITIONS = {
|
|
13
|
-
normal: {
|
|
14
|
-
label: "Normal",
|
|
15
|
-
delayMs: 0
|
|
16
|
-
},
|
|
17
|
-
offline: {
|
|
18
|
-
label: "Offline (requests)",
|
|
19
|
-
delayMs: 0
|
|
20
|
-
},
|
|
21
|
-
slow: {
|
|
22
|
-
label: "Slow (+500 ms)",
|
|
23
|
-
delayMs: 500
|
|
24
|
-
},
|
|
25
|
-
verySlow: {
|
|
26
|
-
label: "Very slow (+2000 ms)",
|
|
27
|
-
delayMs: 2000
|
|
28
|
-
}
|
|
29
|
-
};
|
|
30
|
-
const networkConditionsRuntimeId = exports.networkConditionsRuntimeId = `${Date.now()}-${Math.random().toString(36).slice(2)}`;
|
|
31
|
-
let profile = "normal";
|
|
32
|
-
let keepAlive;
|
|
33
|
-
const listeners = new Set();
|
|
34
|
-
const conditionsCanApply = () => typeof __DEV__ !== "undefined" && __DEV__ && (0, _sharedUi.hasAccountAccess)();
|
|
35
|
-
exports.conditionsCanApply = conditionsCanApply;
|
|
36
|
-
const getNetworkCondition = () => profile;
|
|
37
|
-
exports.getNetworkCondition = getNetworkCondition;
|
|
38
|
-
const subscribeNetworkConditions = listener => {
|
|
39
|
-
listeners.add(listener);
|
|
40
|
-
return () => {
|
|
41
|
-
listeners.delete(listener);
|
|
42
|
-
};
|
|
43
|
-
};
|
|
44
|
-
exports.subscribeNetworkConditions = subscribeNetworkConditions;
|
|
45
|
-
function setNetworkCondition(value) {
|
|
46
|
-
if (typeof value !== "string" || !Object.prototype.hasOwnProperty.call(NETWORK_CONDITIONS, value)) {
|
|
47
|
-
throw new Error("Choose normal, offline, slow, or verySlow.");
|
|
48
|
-
}
|
|
49
|
-
if (value !== "normal" && !conditionsCanApply()) {
|
|
50
|
-
throw new Error("Network conditions require an admitted account and a development build.");
|
|
51
|
-
}
|
|
52
|
-
if (value === profile) return profile;
|
|
53
|
-
if (value !== "normal" && !keepAlive) {
|
|
54
|
-
(0, _networkListener.startNetworkListener)();
|
|
55
|
-
keepAlive = (0, _networkListener.addNetworkListener)(() => {});
|
|
56
|
-
} else if (value === "normal") {
|
|
57
|
-
keepAlive?.();
|
|
58
|
-
keepAlive = undefined;
|
|
59
|
-
if ((0, _networkListener.getNetworkListenerCount)() === 0) (0, _networkListener.stopNetworkListener)();
|
|
60
|
-
}
|
|
61
|
-
profile = value;
|
|
62
|
-
listeners.forEach(listener => listener());
|
|
63
|
-
return profile;
|
|
64
|
-
}
|
|
65
|
-
function snapshotNetworkCondition(url) {
|
|
66
|
-
if (profile === "normal" || !conditionsCanApply() || !/^https?:\/\//i.test(url)) return;
|
|
67
|
-
return Object.freeze({
|
|
68
|
-
profile,
|
|
69
|
-
delayMs: NETWORK_CONDITIONS[profile].delayMs
|
|
70
|
-
});
|
|
71
|
-
}
|
|
72
|
-
(0, _sharedUi.subscribeAccountAccess)(() => {
|
|
73
|
-
if (!(0, _sharedUi.hasAccountAccess)()) setNetworkCondition("normal");
|
|
74
|
-
listeners.forEach(listener => listener());
|
|
75
|
-
});
|
|
1
|
+
"use strict";Object.defineProperty(exports,"__esModule",{value:true});exports.networkConditionsRuntimeId=exports.getNetworkCondition=exports.conditionsCanApply=exports.NETWORK_CONDITIONS=void 0;exports.setNetworkCondition=setNetworkCondition;exports.snapshotNetworkCondition=snapshotNetworkCondition;exports.subscribeNetworkConditions=void 0;var _sharedUi=require("@buoy-gg/shared-ui");var _networkListener=require("../utils/networkListener");const NETWORK_CONDITIONS=exports.NETWORK_CONDITIONS={normal:{label:"Normal",delayMs:0},offline:{label:"Offline (requests)",delayMs:0},slow:{label:"Slow (+500 ms)",delayMs:500},verySlow:{label:"Very slow (+2000 ms)",delayMs:2e3}};const networkConditionsRuntimeId=exports.networkConditionsRuntimeId=`${Date.now()}-${Math.random().toString(36).slice(2)}`;let profile="normal";let keepAlive;const listeners=new Set;const conditionsCanApply=()=>typeof __DEV__!=="undefined"&&__DEV__&&(0,_sharedUi.hasAccountAccess)();exports.conditionsCanApply=conditionsCanApply;const getNetworkCondition=()=>profile;exports.getNetworkCondition=getNetworkCondition;const subscribeNetworkConditions=e=>{listeners.add(e);return()=>{listeners.delete(e)}};exports.subscribeNetworkConditions=subscribeNetworkConditions;function setNetworkCondition(e){if(typeof e!=="string"||!Object.prototype.hasOwnProperty.call(NETWORK_CONDITIONS,e)){throw new Error("Choose normal, offline, slow, or verySlow.")}if(e!=="normal"&&!conditionsCanApply()){throw new Error("Network conditions require an admitted account and a development build.")}if(e===profile)return profile;if(e!=="normal"&&!keepAlive){(0,_networkListener.startNetworkListener)();keepAlive=(0,_networkListener.addNetworkListener)(()=>{})}else if(e==="normal"){keepAlive?.();keepAlive=void 0;if((0,_networkListener.getNetworkListenerCount)()===0)(0,_networkListener.stopNetworkListener)()}profile=e;listeners.forEach(o=>o());return profile}function snapshotNetworkCondition(e){if(profile==="normal"||!conditionsCanApply()||!/^https?:\/\//i.test(e))return;return Object.freeze({profile,delayMs:NETWORK_CONDITIONS[profile].delayMs})}(0,_sharedUi.subscribeAccountAccess)(()=>{if(!(0,_sharedUi.hasAccountAccess)())setNetworkCondition("normal");listeners.forEach(e=>e())});
|
|
@@ -1,43 +1 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
|
|
3
|
-
Object.defineProperty(exports, "__esModule", {
|
|
4
|
-
value: true
|
|
5
|
-
});
|
|
6
|
-
exports.throwIfAborted = throwIfAborted;
|
|
7
|
-
exports.waitBeforeDispatch = waitBeforeDispatch;
|
|
8
|
-
function throwIfAborted(signal) {
|
|
9
|
-
if (!signal?.aborted) return;
|
|
10
|
-
if (signal.reason !== undefined) throw signal.reason;
|
|
11
|
-
const error = new Error("The request was aborted.");
|
|
12
|
-
error.name = "AbortError";
|
|
13
|
-
throw error;
|
|
14
|
-
}
|
|
15
|
-
|
|
16
|
-
/** Wait before dispatch, releasing the timer and listener on cancellation. */
|
|
17
|
-
function waitBeforeDispatch(ms, signal) {
|
|
18
|
-
return new Promise((resolve, reject) => {
|
|
19
|
-
try {
|
|
20
|
-
throwIfAborted(signal);
|
|
21
|
-
} catch (error) {
|
|
22
|
-
reject(error);
|
|
23
|
-
return;
|
|
24
|
-
}
|
|
25
|
-
const cleanup = () => signal?.removeEventListener("abort", abort);
|
|
26
|
-
const abort = () => {
|
|
27
|
-
clearTimeout(timer);
|
|
28
|
-
cleanup();
|
|
29
|
-
try {
|
|
30
|
-
throwIfAborted(signal);
|
|
31
|
-
} catch (error) {
|
|
32
|
-
reject(error);
|
|
33
|
-
}
|
|
34
|
-
};
|
|
35
|
-
const timer = setTimeout(() => {
|
|
36
|
-
cleanup();
|
|
37
|
-
resolve();
|
|
38
|
-
}, ms);
|
|
39
|
-
signal?.addEventListener("abort", abort, {
|
|
40
|
-
once: true
|
|
41
|
-
});
|
|
42
|
-
});
|
|
43
|
-
}
|
|
1
|
+
"use strict";Object.defineProperty(exports,"__esModule",{value:true});exports.throwIfAborted=throwIfAborted;exports.waitBeforeDispatch=waitBeforeDispatch;function throwIfAborted(e){if(!e?.aborted)return;if(e.reason!==void 0)throw e.reason;const r=new Error("The request was aborted.");r.name="AbortError";throw r}function waitBeforeDispatch(e,r){return new Promise((s,o)=>{try{throwIfAborted(r)}catch(t){o(t);return}const n=()=>r?.removeEventListener("abort",c);const c=()=>{clearTimeout(u);n();try{throwIfAborted(r)}catch(t){o(t)}};const u=setTimeout(()=>{n();s()},e);r?.addEventListener("abort",c,{once:true})})}
|