@flighthq/power 0.5.1-next.704.19c91ec → 0.5.1-next.730.f29a5aa
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/package.json +4 -4
- package/src/power.test.ts +36 -20
package/README.md
CHANGED
|
@@ -13,5 +13,5 @@ Import the supported application-facing API from `@flighthq/power`. The `@flight
|
|
|
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/power@0.5.1-next.
|
|
17
|
-
- [License](https://github.com/flighthq/flight/blob/
|
|
16
|
+
- [Source for @flighthq/power@0.5.1-next.730.f29a5aa](https://github.com/flighthq/flight/tree/f29a5aab5db192284ce5cadf08ffae2649a598ea/packages/power)
|
|
17
|
+
- [License](https://github.com/flighthq/flight/blob/f29a5aab5db192284ce5cadf08ffae2649a598ea/LICENSE.md)
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@flighthq/power",
|
|
3
|
-
"version": "0.5.1-next.
|
|
3
|
+
"version": "0.5.1-next.730.f29a5aa",
|
|
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.730.f29a5aa",
|
|
42
|
+
"@flighthq/signals": "0.5.1-next.730.f29a5aa",
|
|
43
|
+
"@flighthq/types": "0.5.1-next.730.f29a5aa"
|
|
44
44
|
},
|
|
45
45
|
"devDependencies": {
|
|
46
46
|
"typescript": "^5.3.0"
|
package/src/power.test.ts
CHANGED
|
@@ -1,10 +1,18 @@
|
|
|
1
|
+
import { createEntity } from '@flighthq/entity/contract';
|
|
1
2
|
import { connectSignal } from '@flighthq/signals/contract';
|
|
2
3
|
import { EntityRuntimeKey } from '@flighthq/types/contract';
|
|
3
4
|
import type {
|
|
5
|
+
EntityWithoutRuntime,
|
|
4
6
|
HasPowerKeepAwake,
|
|
5
7
|
PowerAttachHost,
|
|
8
|
+
PowerChangeBackend,
|
|
6
9
|
PowerIdleState,
|
|
10
|
+
PowerIdleBackend,
|
|
11
|
+
PowerKeepAwakeBackend,
|
|
12
|
+
PowerSessionLockBackend,
|
|
7
13
|
PowerStatus,
|
|
14
|
+
PowerStatusBackend,
|
|
15
|
+
PowerThermalBackend,
|
|
8
16
|
PowerThermalState,
|
|
9
17
|
} from '@flighthq/types/contract';
|
|
10
18
|
|
|
@@ -38,17 +46,17 @@ function statusHost(status: Partial<PowerStatus>): PowerAttachHost & { emitChang
|
|
|
38
46
|
for (const l of listeners) l();
|
|
39
47
|
},
|
|
40
48
|
power: {
|
|
41
|
-
change: {
|
|
49
|
+
change: createEntity<EntityWithoutRuntime<PowerChangeBackend>>({
|
|
42
50
|
subscribe(listener: () => void): () => void {
|
|
43
51
|
listeners.add(listener);
|
|
44
52
|
return () => listeners.delete(listener);
|
|
45
53
|
},
|
|
46
|
-
},
|
|
47
|
-
status: {
|
|
54
|
+
}),
|
|
55
|
+
status: createEntity<EntityWithoutRuntime<PowerStatusBackend>>({
|
|
48
56
|
getStatus(out: PowerStatus): PowerStatus {
|
|
49
57
|
return Object.assign(out, status);
|
|
50
58
|
},
|
|
51
|
-
},
|
|
59
|
+
}),
|
|
52
60
|
},
|
|
53
61
|
};
|
|
54
62
|
}
|
|
@@ -56,12 +64,12 @@ function statusHost(status: Partial<PowerStatus>): PowerAttachHost & { emitChang
|
|
|
56
64
|
function keepAwakeHost(overrides: Partial<HasPowerKeepAwake['power']['keepAwake']> = {}): HasPowerKeepAwake {
|
|
57
65
|
return {
|
|
58
66
|
power: {
|
|
59
|
-
keepAwake: {
|
|
67
|
+
keepAwake: createEntity<EntityWithoutRuntime<PowerKeepAwakeBackend>>({
|
|
60
68
|
acquire: async () => ({ reason: 'ok' }) as const,
|
|
61
69
|
isActive: () => false,
|
|
62
70
|
release: async () => ({ reason: 'ok' }) as const,
|
|
63
71
|
...overrides,
|
|
64
|
-
},
|
|
72
|
+
}),
|
|
65
73
|
},
|
|
66
74
|
};
|
|
67
75
|
}
|
|
@@ -113,18 +121,18 @@ describe('attachPower', () => {
|
|
|
113
121
|
const listeners = new Set<() => void>();
|
|
114
122
|
const host: PowerAttachHost = {
|
|
115
123
|
power: {
|
|
116
|
-
change: {
|
|
124
|
+
change: createEntity<EntityWithoutRuntime<PowerChangeBackend>>({
|
|
117
125
|
subscribe(listener: () => void): () => void {
|
|
118
126
|
listeners.add(listener);
|
|
119
127
|
return () => listeners.delete(listener);
|
|
120
128
|
},
|
|
121
|
-
},
|
|
122
|
-
status: {
|
|
129
|
+
}),
|
|
130
|
+
status: createEntity<EntityWithoutRuntime<PowerStatusBackend>>({
|
|
123
131
|
getStatus(out: PowerStatus): PowerStatus {
|
|
124
132
|
out.isCharging = charging;
|
|
125
133
|
return out;
|
|
126
134
|
},
|
|
127
|
-
},
|
|
135
|
+
}),
|
|
128
136
|
},
|
|
129
137
|
};
|
|
130
138
|
const power = createPower();
|
|
@@ -146,13 +154,13 @@ describe('attachPower', () => {
|
|
|
146
154
|
const listeners = new Set<(state: PowerThermalState) => void>();
|
|
147
155
|
const host: PowerAttachHost = {
|
|
148
156
|
power: {
|
|
149
|
-
thermal: {
|
|
157
|
+
thermal: createEntity<EntityWithoutRuntime<PowerThermalBackend>>({
|
|
150
158
|
getThermalState: () => 'Serious',
|
|
151
159
|
subscribeThermalStateChange(listener: (state: PowerThermalState) => void): () => void {
|
|
152
160
|
listeners.add(listener);
|
|
153
161
|
return () => listeners.delete(listener);
|
|
154
162
|
},
|
|
155
|
-
},
|
|
163
|
+
}),
|
|
156
164
|
},
|
|
157
165
|
};
|
|
158
166
|
const power = createPower();
|
|
@@ -198,12 +206,12 @@ describe('destroyPowerKeepAwake', () => {
|
|
|
198
206
|
// Builds the provider ONCE so two hosts can genuinely alias the same object; spreading it per host
|
|
199
207
|
// would silently make them distinct and the alias assertion would prove nothing.
|
|
200
208
|
function keepAwakeProvider(destroy?: () => void): HasPowerKeepAwake['power']['keepAwake'] {
|
|
201
|
-
return {
|
|
209
|
+
return createEntity<EntityWithoutRuntime<PowerKeepAwakeBackend>>({
|
|
202
210
|
acquire: async () => ({ reason: 'ok' }) as const,
|
|
203
211
|
destroy,
|
|
204
212
|
isActive: () => false,
|
|
205
213
|
release: async () => ({ reason: 'ok' }) as const,
|
|
206
|
-
};
|
|
214
|
+
});
|
|
207
215
|
}
|
|
208
216
|
|
|
209
217
|
function keepAwakeHostWith(provider: HasPowerKeepAwake['power']['keepAwake']): HasPowerKeepAwake {
|
|
@@ -263,14 +271,14 @@ describe('detachPower', () => {
|
|
|
263
271
|
let unlockTornDown = false;
|
|
264
272
|
const host: PowerAttachHost = {
|
|
265
273
|
power: {
|
|
266
|
-
sessionLock: {
|
|
274
|
+
sessionLock: createEntity<EntityWithoutRuntime<PowerSessionLockBackend>>({
|
|
267
275
|
subscribeLock: () => () => {
|
|
268
276
|
throw new Error('lock teardown failed');
|
|
269
277
|
},
|
|
270
278
|
subscribeUnlock: () => () => {
|
|
271
279
|
unlockTornDown = true;
|
|
272
280
|
},
|
|
273
|
-
},
|
|
281
|
+
}),
|
|
274
282
|
},
|
|
275
283
|
};
|
|
276
284
|
const power = createPower();
|
|
@@ -359,13 +367,13 @@ describe('getPowerSystemIdleState', () => {
|
|
|
359
367
|
let seen = -1;
|
|
360
368
|
const host = {
|
|
361
369
|
power: {
|
|
362
|
-
idle: {
|
|
370
|
+
idle: createEntity<EntityWithoutRuntime<PowerIdleBackend>>({
|
|
363
371
|
getIdleState(t: number): PowerIdleState {
|
|
364
372
|
seen = t;
|
|
365
373
|
return 'Idle';
|
|
366
374
|
},
|
|
367
375
|
getIdleTimeSeconds: () => 0,
|
|
368
|
-
},
|
|
376
|
+
}),
|
|
369
377
|
},
|
|
370
378
|
};
|
|
371
379
|
expect(getPowerSystemIdleState(host, 90)).toBe('Idle');
|
|
@@ -376,7 +384,12 @@ describe('getPowerSystemIdleState', () => {
|
|
|
376
384
|
describe('getPowerSystemIdleTime', () => {
|
|
377
385
|
it('returns the provider value', () => {
|
|
378
386
|
const host = {
|
|
379
|
-
power: {
|
|
387
|
+
power: {
|
|
388
|
+
idle: createEntity<EntityWithoutRuntime<PowerIdleBackend>>({
|
|
389
|
+
getIdleState: (): PowerIdleState => 'Active',
|
|
390
|
+
getIdleTimeSeconds: () => 42,
|
|
391
|
+
}),
|
|
392
|
+
},
|
|
380
393
|
};
|
|
381
394
|
expect(getPowerSystemIdleTime(host)).toBe(42);
|
|
382
395
|
});
|
|
@@ -386,7 +399,10 @@ describe('getPowerThermalState', () => {
|
|
|
386
399
|
it('returns the provider value', () => {
|
|
387
400
|
const host = {
|
|
388
401
|
power: {
|
|
389
|
-
thermal:
|
|
402
|
+
thermal: createEntity<EntityWithoutRuntime<PowerThermalBackend>>({
|
|
403
|
+
getThermalState: (): PowerThermalState => 'Fair',
|
|
404
|
+
subscribeThermalStateChange: () => () => {},
|
|
405
|
+
}),
|
|
390
406
|
},
|
|
391
407
|
};
|
|
392
408
|
expect(getPowerThermalState(host)).toBe('Fair');
|