@flighthq/connectivity 0.5.1-next.1069.554a2ac → 0.5.1-next.1201.9b49dee
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 +2 -2
- package/dist/connectivity.d.ts +8 -8
- package/dist/connectivity.d.ts.map +1 -1
- package/dist/connectivity.js +17 -17
- package/dist/connectivity.js.map +1 -1
- package/package.json +4 -4
- package/src/connectivity.test.ts +29 -21
package/README.md
CHANGED
|
@@ -13,5 +13,5 @@ Import the supported application-facing API from `@flighthq/connectivity`. The `
|
|
|
13
13
|
This package is part of the locked-version Flight SDK graph. Applications may instead install and import `@flighthq/sdk` when package-level tree shaking is sufficient.
|
|
14
14
|
|
|
15
15
|
- [Flight project](https://github.com/flighthq/flight)
|
|
16
|
-
- [Source for @flighthq/connectivity@0.5.1-next.
|
|
17
|
-
- [License](https://github.com/flighthq/flight/blob/
|
|
16
|
+
- [Source for @flighthq/connectivity@0.5.1-next.1201.9b49dee](https://github.com/flighthq/flight/tree/9b49dee3f22f6b2838c3d237edcc77bca65734f2/packages/connectivity)
|
|
17
|
+
- [License](https://github.com/flighthq/flight/blob/9b49dee3f22f6b2838c3d237edcc77bca65734f2/LICENSE.md)
|
package/dist/connectivity.d.ts
CHANGED
|
@@ -1,14 +1,14 @@
|
|
|
1
|
-
import type { Connectivity, ConnectivityReachability, ConnectivityReachabilityOptions, ConnectivityStatus, EntityConstruction,
|
|
2
|
-
export declare function attachConnectivity(
|
|
1
|
+
import type { Connectivity, ConnectivityReachability, ConnectivityReachabilityOptions, ConnectivityStatus, EntityConstruction, HostConnectivityChangeProvider, HostConnectivityReachabilityProvider, HostConnectivityStatusProvider } from '@flighthq/types/contract';
|
|
2
|
+
export declare function attachConnectivity(hostConnectivityStatus: Readonly<HostConnectivityStatusProvider>, hostConnectivityChange: Readonly<HostConnectivityChangeProvider>, connectivity: Connectivity): boolean;
|
|
3
3
|
export declare function createConnectivity(): Connectivity;
|
|
4
|
-
export declare function destroyConnectivity(
|
|
4
|
+
export declare function destroyConnectivity(hostConnectivityChange: Readonly<HostConnectivityChangeProvider>): void;
|
|
5
5
|
export declare function detachConnectivity(connectivity: Connectivity): void;
|
|
6
|
-
export declare function detectConnectivityReachability(
|
|
6
|
+
export declare function detectConnectivityReachability(hostConnectivityReachability: Readonly<HostConnectivityReachabilityProvider>, options: Readonly<ConnectivityReachabilityOptions>, out: ConnectivityReachability): Promise<ConnectivityReachability>;
|
|
7
7
|
export declare function disposeConnectivity(connectivity: Connectivity): void;
|
|
8
|
-
export declare function getConnectivityOnline(
|
|
9
|
-
export declare function getConnectivityStatus(
|
|
8
|
+
export declare function getConnectivityOnline(hostConnectivityStatus: Readonly<HostConnectivityStatusProvider>): boolean | null;
|
|
9
|
+
export declare function getConnectivityStatus(hostConnectivityStatus: Readonly<HostConnectivityStatusProvider>, out: ConnectivityStatus): ConnectivityStatus;
|
|
10
10
|
export declare function hasConnectivityStatusChanged(a: Readonly<ConnectivityStatus>, b: Readonly<ConnectivityStatus>): boolean;
|
|
11
11
|
export declare function initializeConnectivity(out: EntityConstruction<Connectivity>): void;
|
|
12
|
-
export declare function isConnectivityMetered(
|
|
13
|
-
export declare function isConnectivitySaveDataEnabled(
|
|
12
|
+
export declare function isConnectivityMetered(hostConnectivityStatus: Readonly<HostConnectivityStatusProvider>): boolean;
|
|
13
|
+
export declare function isConnectivitySaveDataEnabled(hostConnectivityStatus: Readonly<HostConnectivityStatusProvider>): boolean;
|
|
14
14
|
//# sourceMappingURL=connectivity.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"connectivity.d.ts","sourceRoot":"","sources":["../src/connectivity.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EACV,YAAY,EACZ,wBAAwB,EACxB,+BAA+B,EAC/B,kBAAkB,EAClB,kBAAkB,EAClB,
|
|
1
|
+
{"version":3,"file":"connectivity.d.ts","sourceRoot":"","sources":["../src/connectivity.ts"],"names":[],"mappings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,CAAC,sBAAsB,EAAE,QAAQ,CAAC,8BAA8B,CAAC,GAAG,OAAO,CAE/G;AAED,wBAAgB,6BAA6B,CAC3C,sBAAsB,EAAE,QAAQ,CAAC,8BAA8B,CAAC,GAC/D,OAAO,CAET"}
|
package/dist/connectivity.js
CHANGED
|
@@ -1,17 +1,17 @@
|
|
|
1
1
|
import { allocateEntity, finishEntity } from '@flighthq/entity/contract';
|
|
2
2
|
import { clearSignal, createSignal, emitSignal } from '@flighthq/signals/contract';
|
|
3
3
|
// Starts raw host-change delivery and turns it into the five core-owned diff signals. Status and
|
|
4
|
-
// change are separate
|
|
4
|
+
// change are separate providers: a snapshot command cannot stand in for an event subscription.
|
|
5
5
|
// Re-attaching always consumes the prior provider's exact unsubscribe before touching the new one.
|
|
6
6
|
// Returns false when the change provider cannot establish a real subscription.
|
|
7
|
-
export function attachConnectivity(
|
|
7
|
+
export function attachConnectivity(hostConnectivityStatus, hostConnectivityChange, connectivity) {
|
|
8
8
|
detachConnectivity(connectivity);
|
|
9
|
-
const statusBackend =
|
|
9
|
+
const statusBackend = hostConnectivityStatus;
|
|
10
10
|
const initial = statusBackend.getStatus(connectivityStatusOut());
|
|
11
11
|
let wasOnline = initial.online;
|
|
12
12
|
let wasType = initial.type;
|
|
13
13
|
let wasMetered = initial.metered;
|
|
14
|
-
const unsubscribe =
|
|
14
|
+
const unsubscribe = hostConnectivityChange.subscribe(() => {
|
|
15
15
|
const status = statusBackend.getStatus(connectivityStatusOut());
|
|
16
16
|
emitSignal(connectivity.onChange, status);
|
|
17
17
|
if (status.online !== wasOnline) {
|
|
@@ -42,8 +42,8 @@ export function createConnectivity() {
|
|
|
42
42
|
}
|
|
43
43
|
// Terminal provider teardown. This is deliberately separate from per-entity detach: a caller that
|
|
44
44
|
// releases one subscription must not destroy a shared host provider.
|
|
45
|
-
export function destroyConnectivity(
|
|
46
|
-
|
|
45
|
+
export function destroyConnectivity(hostConnectivityChange) {
|
|
46
|
+
hostConnectivityChange.destroy();
|
|
47
47
|
}
|
|
48
48
|
export function detachConnectivity(connectivity) {
|
|
49
49
|
const unsubscribe = _subscriptions.get(connectivity);
|
|
@@ -52,8 +52,8 @@ export function detachConnectivity(connectivity) {
|
|
|
52
52
|
_subscriptions.delete(connectivity);
|
|
53
53
|
unsubscribe();
|
|
54
54
|
}
|
|
55
|
-
export function detectConnectivityReachability(
|
|
56
|
-
return
|
|
55
|
+
export function detectConnectivityReachability(hostConnectivityReachability, options, out) {
|
|
56
|
+
return hostConnectivityReachability.detectReachability(options, out);
|
|
57
57
|
}
|
|
58
58
|
// Disposes only the caller-owned event entity. Provider teardown is terminal and explicit through
|
|
59
59
|
// destroyConnectivity because one provider can fan out to multiple Connectivity entities.
|
|
@@ -65,11 +65,11 @@ export function disposeConnectivity(connectivity) {
|
|
|
65
65
|
clearSignal(connectivity.onOffline);
|
|
66
66
|
clearSignal(connectivity.onOnline);
|
|
67
67
|
}
|
|
68
|
-
export function getConnectivityOnline(
|
|
69
|
-
return
|
|
68
|
+
export function getConnectivityOnline(hostConnectivityStatus) {
|
|
69
|
+
return hostConnectivityStatus.getStatus(connectivityStatusOut()).online;
|
|
70
70
|
}
|
|
71
|
-
export function getConnectivityStatus(
|
|
72
|
-
return
|
|
71
|
+
export function getConnectivityStatus(hostConnectivityStatus, out) {
|
|
72
|
+
return hostConnectivityStatus.getStatus(out);
|
|
73
73
|
}
|
|
74
74
|
export function hasConnectivityStatusChanged(a, b) {
|
|
75
75
|
return (a.online !== b.online ||
|
|
@@ -88,13 +88,13 @@ export function initializeConnectivity(out) {
|
|
|
88
88
|
out.onOffline = createSignal();
|
|
89
89
|
out.onOnline = createSignal();
|
|
90
90
|
}
|
|
91
|
-
export function isConnectivityMetered(
|
|
92
|
-
return
|
|
91
|
+
export function isConnectivityMetered(hostConnectivityStatus) {
|
|
92
|
+
return hostConnectivityStatus.getStatus(connectivityStatusOut()).metered;
|
|
93
93
|
}
|
|
94
|
-
export function isConnectivitySaveDataEnabled(
|
|
95
|
-
return
|
|
94
|
+
export function isConnectivitySaveDataEnabled(hostConnectivityStatus) {
|
|
95
|
+
return hostConnectivityStatus.getStatus(connectivityStatusOut()).saveData;
|
|
96
96
|
}
|
|
97
|
-
// ConnectivityStatus is a
|
|
97
|
+
// ConnectivityStatus is a provider-produced query/out snapshot, not a user-created identity. Keep its
|
|
98
98
|
// sentinel allocation package-private so the public create* vocabulary remains Entity-only.
|
|
99
99
|
function connectivityStatusOut() {
|
|
100
100
|
return {
|
package/dist/connectivity.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"connectivity.js","sourceRoot":"","sources":["../src/connectivity.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,cAAc,EAAE,YAAY,EAAE,MAAM,2BAA2B,CAAC;AACzE,OAAO,EAAE,WAAW,EAAE,YAAY,EAAE,UAAU,EAAE,MAAM,4BAA4B,CAAC;AAYnF,iGAAiG;AACjG
|
|
1
|
+
{"version":3,"file":"connectivity.js","sourceRoot":"","sources":["../src/connectivity.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,cAAc,EAAE,YAAY,EAAE,MAAM,2BAA2B,CAAC;AACzE,OAAO,EAAE,WAAW,EAAE,YAAY,EAAE,UAAU,EAAE,MAAM,4BAA4B,CAAC;AAYnF,iGAAiG;AACjG,+FAA+F;AAC/F,mGAAmG;AACnG,+EAA+E;AAC/E,MAAM,UAAU,kBAAkB,CAChC,sBAAgE,EAChE,sBAAgE,EAChE,YAA0B;IAE1B,kBAAkB,CAAC,YAAY,CAAC,CAAC;IACjC,MAAM,aAAa,GAAG,sBAAsB,CAAC;IAC7C,MAAM,OAAO,GAAG,aAAa,CAAC,SAAS,CAAC,qBAAqB,EAAE,CAAC,CAAC;IACjE,IAAI,SAAS,GAAG,OAAO,CAAC,MAAM,CAAC;IAC/B,IAAI,OAAO,GAAG,OAAO,CAAC,IAAI,CAAC;IAC3B,IAAI,UAAU,GAAG,OAAO,CAAC,OAAO,CAAC;IACjC,MAAM,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AAG,IAAI,OAAO,EAA4B,CAAC"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@flighthq/connectivity",
|
|
3
|
-
"version": "0.5.1-next.
|
|
3
|
+
"version": "0.5.1-next.1201.9b49dee",
|
|
4
4
|
"author": "Joshua Granick and other contributors",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"repository": {
|
|
@@ -38,9 +38,9 @@
|
|
|
38
38
|
"clean:dist": "tsx ../../scripts/clean-package-dist.ts"
|
|
39
39
|
},
|
|
40
40
|
"dependencies": {
|
|
41
|
-
"@flighthq/entity": "0.5.1-next.
|
|
42
|
-
"@flighthq/signals": "0.5.1-next.
|
|
43
|
-
"@flighthq/types": "0.5.1-next.
|
|
41
|
+
"@flighthq/entity": "0.5.1-next.1201.9b49dee",
|
|
42
|
+
"@flighthq/signals": "0.5.1-next.1201.9b49dee",
|
|
43
|
+
"@flighthq/types": "0.5.1-next.1201.9b49dee"
|
|
44
44
|
},
|
|
45
45
|
"devDependencies": {
|
|
46
46
|
"typescript": "^5.3.0"
|
package/src/connectivity.test.ts
CHANGED
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
import { allocateEntity, finishEntity } from '@flighthq/entity/contract';
|
|
2
2
|
import { connectSignal, hasSignalSlots } from '@flighthq/signals/contract';
|
|
3
3
|
import type {
|
|
4
|
-
|
|
5
|
-
|
|
4
|
+
HostConnectivityChangeProvider,
|
|
5
|
+
HostConnectivityReachabilityProvider,
|
|
6
6
|
ConnectivityStatus,
|
|
7
|
-
|
|
7
|
+
HostConnectivityStatusProvider,
|
|
8
8
|
} from '@flighthq/types/contract';
|
|
9
9
|
import { EntityRuntimeKey } from '@flighthq/types/contract';
|
|
10
10
|
|
|
@@ -23,7 +23,7 @@ import {
|
|
|
23
23
|
isConnectivitySaveDataEnabled,
|
|
24
24
|
} from './connectivity';
|
|
25
25
|
|
|
26
|
-
interface FakeConnectivityProvider extends
|
|
26
|
+
interface FakeConnectivityProvider extends HostConnectivityStatusProvider, HostConnectivityChangeProvider {
|
|
27
27
|
readonly activeSubscriptions: () => number;
|
|
28
28
|
readonly destroyCalls: () => number;
|
|
29
29
|
fire(): void;
|
|
@@ -117,7 +117,9 @@ describe('attachConnectivity', () => {
|
|
|
117
117
|
connectSignal(connectivity.onMeteredChange, (value) => metered.push(value));
|
|
118
118
|
connectSignal(connectivity.onOffline, () => offline++);
|
|
119
119
|
|
|
120
|
-
expect(
|
|
120
|
+
expect(
|
|
121
|
+
attachConnectivity(hostFor(provider).connectivity.status, hostFor(provider).connectivity.change, connectivity),
|
|
122
|
+
).toBe(true);
|
|
121
123
|
Object.assign(provider.status, { metered: true, online: false, type: 'cellular' as const });
|
|
122
124
|
provider.fire();
|
|
123
125
|
|
|
@@ -133,7 +135,7 @@ describe('attachConnectivity', () => {
|
|
|
133
135
|
const connectivity = createConnectivity();
|
|
134
136
|
let offline = 0;
|
|
135
137
|
connectSignal(connectivity.onOffline, () => offline++);
|
|
136
|
-
attachConnectivity(hostFor(provider), connectivity);
|
|
138
|
+
attachConnectivity(hostFor(provider).connectivity.status, hostFor(provider).connectivity.change, connectivity);
|
|
137
139
|
provider.fire();
|
|
138
140
|
expect(offline).toBe(0);
|
|
139
141
|
provider.status.online = false;
|
|
@@ -143,7 +145,13 @@ describe('attachConnectivity', () => {
|
|
|
143
145
|
|
|
144
146
|
it('returns false instead of retaining a silent no-op subscription', () => {
|
|
145
147
|
const provider = fakeProvider({}, false);
|
|
146
|
-
expect(
|
|
148
|
+
expect(
|
|
149
|
+
attachConnectivity(
|
|
150
|
+
hostFor(provider).connectivity.status,
|
|
151
|
+
hostFor(provider).connectivity.change,
|
|
152
|
+
createConnectivity(),
|
|
153
|
+
),
|
|
154
|
+
).toBe(false);
|
|
147
155
|
expect(provider.activeSubscriptions()).toBe(0);
|
|
148
156
|
});
|
|
149
157
|
|
|
@@ -153,8 +161,8 @@ describe('attachConnectivity', () => {
|
|
|
153
161
|
const connectivity = createConnectivity();
|
|
154
162
|
let changes = 0;
|
|
155
163
|
connectSignal(connectivity.onChange, () => changes++);
|
|
156
|
-
attachConnectivity(hostFor(a), connectivity);
|
|
157
|
-
attachConnectivity(hostFor(b), connectivity);
|
|
164
|
+
attachConnectivity(hostFor(a).connectivity.status, hostFor(a).connectivity.change, connectivity);
|
|
165
|
+
attachConnectivity(hostFor(b).connectivity.status, hostFor(b).connectivity.change, connectivity);
|
|
158
166
|
expect(a.unsubscribeCalls()).toBe(1);
|
|
159
167
|
expect(a.activeSubscriptions()).toBe(0);
|
|
160
168
|
expect(b.activeSubscriptions()).toBe(1);
|
|
@@ -169,7 +177,7 @@ describe('attachConnectivity', () => {
|
|
|
169
177
|
const connectivity = createConnectivity();
|
|
170
178
|
const changes: Readonly<ConnectivityStatus>[] = [];
|
|
171
179
|
connectSignal(connectivity.onChange, (value) => changes.push(value));
|
|
172
|
-
attachConnectivity(hostFor(provider), connectivity);
|
|
180
|
+
attachConnectivity(hostFor(provider).connectivity.status, hostFor(provider).connectivity.change, connectivity);
|
|
173
181
|
provider.fire();
|
|
174
182
|
provider.status.type = 'cellular';
|
|
175
183
|
provider.fire();
|
|
@@ -197,8 +205,8 @@ describe('destroyConnectivity', () => {
|
|
|
197
205
|
it('uses the supplied change provider and provider teardown is terminal/idempotent', () => {
|
|
198
206
|
const provider = fakeProvider();
|
|
199
207
|
const host = hostFor(provider);
|
|
200
|
-
destroyConnectivity(host);
|
|
201
|
-
destroyConnectivity(host);
|
|
208
|
+
destroyConnectivity(host.connectivity.change);
|
|
209
|
+
destroyConnectivity(host.connectivity.change);
|
|
202
210
|
expect(provider.destroyCalls()).toBe(1);
|
|
203
211
|
expect(provider.subscribe(() => {})).toBeNull();
|
|
204
212
|
});
|
|
@@ -208,7 +216,7 @@ describe('detachConnectivity', () => {
|
|
|
208
216
|
it('consumes the exact unsubscribe once', () => {
|
|
209
217
|
const provider = fakeProvider();
|
|
210
218
|
const connectivity = createConnectivity();
|
|
211
|
-
attachConnectivity(hostFor(provider), connectivity);
|
|
219
|
+
attachConnectivity(hostFor(provider).connectivity.status, hostFor(provider).connectivity.change, connectivity);
|
|
212
220
|
detachConnectivity(connectivity);
|
|
213
221
|
detachConnectivity(connectivity);
|
|
214
222
|
expect(provider.unsubscribeCalls()).toBe(1);
|
|
@@ -218,7 +226,7 @@ describe('detachConnectivity', () => {
|
|
|
218
226
|
describe('detectConnectivityReachability', () => {
|
|
219
227
|
it('dispatches reachability only to the supplied reachability slot', async () => {
|
|
220
228
|
let calls = 0;
|
|
221
|
-
const reachability = allocateEntity<
|
|
229
|
+
const reachability = allocateEntity<HostConnectivityReachabilityProvider>();
|
|
222
230
|
reachability.detectReachability = async (_options, out) => {
|
|
223
231
|
calls++;
|
|
224
232
|
out.latency = 7;
|
|
@@ -227,7 +235,7 @@ describe('detectConnectivityReachability', () => {
|
|
|
227
235
|
};
|
|
228
236
|
const out = { latency: -1, reachable: false };
|
|
229
237
|
const result = await detectConnectivityReachability(
|
|
230
|
-
{ connectivity: { reachability } },
|
|
238
|
+
{ connectivity: { reachability } }.connectivity.reachability,
|
|
231
239
|
{ url: 'https://example.invalid' },
|
|
232
240
|
out,
|
|
233
241
|
);
|
|
@@ -241,7 +249,7 @@ describe('disposeConnectivity', () => {
|
|
|
241
249
|
it('unsubscribes once and clears listeners from every signal', () => {
|
|
242
250
|
const provider = fakeProvider();
|
|
243
251
|
const connectivity = createConnectivity();
|
|
244
|
-
attachConnectivity(hostFor(provider), connectivity);
|
|
252
|
+
attachConnectivity(hostFor(provider).connectivity.status, hostFor(provider).connectivity.change, connectivity);
|
|
245
253
|
connectSignal(connectivity.onChange, () => {});
|
|
246
254
|
connectSignal(connectivity.onConnectionTypeChange, () => {});
|
|
247
255
|
connectSignal(connectivity.onMeteredChange, () => {});
|
|
@@ -262,8 +270,8 @@ describe('disposeConnectivity', () => {
|
|
|
262
270
|
|
|
263
271
|
describe('getConnectivityOnline', () => {
|
|
264
272
|
it('preserves unknown and measured online states', () => {
|
|
265
|
-
expect(getConnectivityOnline(hostFor(fakeProvider({ online: null })))).toBeNull();
|
|
266
|
-
expect(getConnectivityOnline(hostFor(fakeProvider({ online: true })))).toBe(true);
|
|
273
|
+
expect(getConnectivityOnline(hostFor(fakeProvider({ online: null })).connectivity.status)).toBeNull();
|
|
274
|
+
expect(getConnectivityOnline(hostFor(fakeProvider({ online: true })).connectivity.status)).toBe(true);
|
|
267
275
|
});
|
|
268
276
|
});
|
|
269
277
|
|
|
@@ -272,7 +280,7 @@ describe('getConnectivityStatus', () => {
|
|
|
272
280
|
const provider = fakeProvider({ metered: true, online: false, saveData: true });
|
|
273
281
|
const host = hostFor(provider);
|
|
274
282
|
const out = status();
|
|
275
|
-
expect(getConnectivityStatus(host, out)).toBe(out);
|
|
283
|
+
expect(getConnectivityStatus(host.connectivity.status, out)).toBe(out);
|
|
276
284
|
expect(out.type).toBe('wifi');
|
|
277
285
|
});
|
|
278
286
|
});
|
|
@@ -317,11 +325,11 @@ describe('initializeConnectivity', () => {
|
|
|
317
325
|
|
|
318
326
|
describe('isConnectivityMetered', () => {
|
|
319
327
|
it('reads the metered level from the supplied status witness', () => {
|
|
320
|
-
expect(isConnectivityMetered(hostFor(fakeProvider({ metered: true })))).toBe(true);
|
|
328
|
+
expect(isConnectivityMetered(hostFor(fakeProvider({ metered: true })).connectivity.status)).toBe(true);
|
|
321
329
|
});
|
|
322
330
|
});
|
|
323
331
|
describe('isConnectivitySaveDataEnabled', () => {
|
|
324
332
|
it('reads the save-data level from the supplied status witness', () => {
|
|
325
|
-
expect(isConnectivitySaveDataEnabled(hostFor(fakeProvider({ saveData: true })))).toBe(true);
|
|
333
|
+
expect(isConnectivitySaveDataEnabled(hostFor(fakeProvider({ saveData: true })).connectivity.status)).toBe(true);
|
|
326
334
|
});
|
|
327
335
|
});
|