@flighthq/platform 0.3.1-next.975.01aea94 → 0.4.0-edge.1908.751021c
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/index.d.ts +1 -1
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +1 -1
- package/dist/index.js.map +1 -1
- package/dist/platform.d.ts +5 -0
- package/dist/platform.d.ts.map +1 -1
- package/dist/platform.js +63 -9
- package/dist/platform.js.map +1 -1
- package/package.json +3 -3
- package/src/platform.test.ts +81 -0
package/dist/index.d.ts
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
export { comparePlatformVersions, getPlatformEngine, getPlatformInfo, getPlatformKind, getPlatformName, isPlatformDesktop, isPlatformMobile, isPlatformNative, isPlatformTouch, isPlatformVersionAtLeast, isPlatformWeb, } from './contract';
|
|
1
|
+
export { explainPlatformBackend, comparePlatformVersions, getPlatformEngine, getPlatformInfo, getPlatformKind, getPlatformName, isPlatformDesktop, isPlatformMobile, isPlatformNative, isPlatformTouch, isPlatformVersionAtLeast, isPlatformWeb, } from './contract';
|
|
2
2
|
//# sourceMappingURL=index.d.ts.map
|
package/dist/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,uBAAuB,EACvB,iBAAiB,EACjB,eAAe,EACf,eAAe,EACf,eAAe,EACf,iBAAiB,EACjB,gBAAgB,EAChB,gBAAgB,EAChB,eAAe,EACf,wBAAwB,EACxB,aAAa,GACd,MAAM,YAAY,CAAC"}
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,sBAAsB,EACtB,uBAAuB,EACvB,iBAAiB,EACjB,eAAe,EACf,eAAe,EACf,eAAe,EACf,iBAAiB,EACjB,gBAAgB,EAChB,gBAAgB,EAChB,eAAe,EACf,wBAAwB,EACxB,aAAa,GACd,MAAM,YAAY,CAAC"}
|
package/dist/index.js
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
export { comparePlatformVersions, getPlatformEngine, getPlatformInfo, getPlatformKind, getPlatformName, isPlatformDesktop, isPlatformMobile, isPlatformNative, isPlatformTouch, isPlatformVersionAtLeast, isPlatformWeb, } from './contract';
|
|
1
|
+
export { explainPlatformBackend, comparePlatformVersions, getPlatformEngine, getPlatformInfo, getPlatformKind, getPlatformName, isPlatformDesktop, isPlatformMobile, isPlatformNative, isPlatformTouch, isPlatformVersionAtLeast, isPlatformWeb, } from './contract';
|
|
2
2
|
//# sourceMappingURL=index.js.map
|
package/dist/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,uBAAuB,EACvB,iBAAiB,EACjB,eAAe,EACf,eAAe,EACf,eAAe,EACf,iBAAiB,EACjB,gBAAgB,EAChB,gBAAgB,EAChB,eAAe,EACf,wBAAwB,EACxB,aAAa,GACd,MAAM,YAAY,CAAC"}
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,sBAAsB,EACtB,uBAAuB,EACvB,iBAAiB,EACjB,eAAe,EACf,eAAe,EACf,eAAe,EACf,iBAAiB,EACjB,gBAAgB,EAChB,gBAAgB,EAChB,eAAe,EACf,wBAAwB,EACxB,aAAa,GACd,MAAM,YAAY,CAAC"}
|
package/dist/platform.d.ts
CHANGED
|
@@ -1,18 +1,23 @@
|
|
|
1
|
+
import type { BackendExplanation } from '@flighthq/types/contract';
|
|
1
2
|
import type { PlatformBackend, PlatformEngine, PlatformInfo, PlatformKind, PlatformName, PlatformRuntime } from '@flighthq/types/contract';
|
|
2
3
|
export declare function comparePlatformVersions(a: string, b: string): -1 | 0 | 1;
|
|
3
4
|
export declare function createPlatformInfo(): PlatformInfo;
|
|
4
5
|
export declare function createWebPlatformBackend(): PlatformBackend;
|
|
6
|
+
export declare function explainPlatformBackend(): BackendExplanation;
|
|
5
7
|
export declare function getPlatformBackend(): PlatformBackend;
|
|
6
8
|
export declare function getPlatformEngine(): PlatformEngine;
|
|
7
9
|
export declare function getPlatformInfo(out: PlatformInfo): PlatformInfo;
|
|
8
10
|
export declare function getPlatformKind(): PlatformKind;
|
|
9
11
|
export declare function getPlatformName(): PlatformName;
|
|
10
12
|
export declare function getPlatformRuntime(): PlatformRuntime;
|
|
13
|
+
export declare function installPlatformHostBackend(backend: PlatformBackend): void;
|
|
11
14
|
export declare function isPlatformDesktop(): boolean;
|
|
12
15
|
export declare function isPlatformMobile(): boolean;
|
|
13
16
|
export declare function isPlatformNative(): boolean;
|
|
14
17
|
export declare function isPlatformTouch(): boolean;
|
|
15
18
|
export declare function isPlatformVersionAtLeast(minimum: string): boolean;
|
|
16
19
|
export declare function isPlatformWeb(): boolean;
|
|
20
|
+
export declare function observePlatformHostResult(operation: string, succeeded: boolean): void;
|
|
21
|
+
export declare function resetPlatformBackendForTest(): void;
|
|
17
22
|
export declare function setPlatformBackend(backend: PlatformBackend | null): void;
|
|
18
23
|
//# sourceMappingURL=platform.d.ts.map
|
package/dist/platform.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"platform.d.ts","sourceRoot":"","sources":["../src/platform.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EACV,eAAe,EACf,cAAc,EACd,YAAY,EACZ,YAAY,EACZ,YAAY,EACZ,eAAe,EAChB,MAAM,0BAA0B,CAAC;AAgBlC,wBAAgB,uBAAuB,CAAC,CAAC,EAAE,MAAM,EAAE,CAAC,EAAE,MAAM,GAAG,CAAC,CAAC,GAAG,CAAC,GAAG,CAAC,CAcxE;AAGD,wBAAgB,kBAAkB,IAAI,YAAY,CAiBjD;AAID,wBAAgB,wBAAwB,IAAI,eAAe,CAE1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AgB,2BAA2B,IAAI,IAAI,CAKlD;AAID,wBAAgB,kBAAkB,CAAC,OAAO,EAAE,eAAe,GAAG,IAAI,GAAG,IAAI,CAExE"}
|
package/dist/platform.js
CHANGED
|
@@ -44,12 +44,24 @@ export function createPlatformInfo() {
|
|
|
44
44
|
export function createWebPlatformBackend() {
|
|
45
45
|
return { getInfo: getWebPlatformInfo };
|
|
46
46
|
}
|
|
47
|
-
|
|
48
|
-
|
|
47
|
+
export function explainPlatformBackend() {
|
|
48
|
+
if (_custom !== null) {
|
|
49
|
+
return { conflict: _hostConflict, layer: 'custom', operation: null, viability: 'unobserved' };
|
|
50
|
+
}
|
|
51
|
+
if (_host !== null) {
|
|
52
|
+
return {
|
|
53
|
+
conflict: _hostConflict,
|
|
54
|
+
layer: 'host',
|
|
55
|
+
operation: _hostObservation !== null ? _hostObservation.operation : null,
|
|
56
|
+
viability: _hostObservation !== null ? _hostObservation.viability : 'unobserved',
|
|
57
|
+
};
|
|
58
|
+
}
|
|
59
|
+
return { conflict: false, layer: 'host-not-enabled', operation: null, viability: 'unobserved' };
|
|
60
|
+
}
|
|
61
|
+
// The active platform backend. Capability packages call their own get*Backend; this is the root
|
|
62
|
+
// one for environment identification.
|
|
49
63
|
export function getPlatformBackend() {
|
|
50
|
-
|
|
51
|
-
_backend = createWebPlatformBackend();
|
|
52
|
-
return _backend;
|
|
64
|
+
return _custom ?? _host ?? _sentinel;
|
|
53
65
|
}
|
|
54
66
|
// The browser rendering engine — 'blink' | 'gecko' | 'webkit' | 'unknown'. Convenience over
|
|
55
67
|
// getPlatformInfo. 'unknown' on native hosts where no browser engine is present.
|
|
@@ -73,6 +85,14 @@ export function getPlatformName() {
|
|
|
73
85
|
export function getPlatformRuntime() {
|
|
74
86
|
return getPlatformInfo(_scratch).runtime;
|
|
75
87
|
}
|
|
88
|
+
export function installPlatformHostBackend(backend) {
|
|
89
|
+
if (_host !== null) {
|
|
90
|
+
if (_host !== backend)
|
|
91
|
+
_hostConflict = true;
|
|
92
|
+
return;
|
|
93
|
+
}
|
|
94
|
+
_host = backend;
|
|
95
|
+
}
|
|
76
96
|
// True on a desktop host (Electron/Tauri/native window shell). False on mobile and plain web.
|
|
77
97
|
export function isPlatformDesktop() {
|
|
78
98
|
return getPlatformKind() === 'desktop';
|
|
@@ -104,15 +124,49 @@ export function isPlatformVersionAtLeast(minimum) {
|
|
|
104
124
|
export function isPlatformWeb() {
|
|
105
125
|
return getPlatformKind() === 'web';
|
|
106
126
|
}
|
|
107
|
-
|
|
108
|
-
|
|
127
|
+
export function observePlatformHostResult(operation, succeeded) {
|
|
128
|
+
_hostObservation = {
|
|
129
|
+
operation,
|
|
130
|
+
viability: succeeded ? 'available' : 'runtime-api-unavailable',
|
|
131
|
+
};
|
|
132
|
+
}
|
|
133
|
+
export function resetPlatformBackendForTest() {
|
|
134
|
+
_custom = null;
|
|
135
|
+
_host = null;
|
|
136
|
+
_hostConflict = false;
|
|
137
|
+
_hostObservation = null;
|
|
138
|
+
}
|
|
139
|
+
// Installs a native host backend (Electron/Tauri/Capacitor/native). Pass null to fall back to
|
|
140
|
+
// the host or sentinel layer.
|
|
109
141
|
export function setPlatformBackend(backend) {
|
|
110
|
-
|
|
142
|
+
_custom = backend;
|
|
111
143
|
}
|
|
112
|
-
let
|
|
144
|
+
let _custom = null;
|
|
145
|
+
let _host = null;
|
|
146
|
+
let _hostConflict = false;
|
|
147
|
+
let _hostObservation = null;
|
|
113
148
|
// Single-threaded JS no-alloc scratch for scalar convenience reads (getPlatformKind, etc.).
|
|
114
149
|
// Rust/native mirror uses a per-call local or thread-local instead.
|
|
115
150
|
const _scratch = createPlatformInfo();
|
|
151
|
+
const _sentinel = {
|
|
152
|
+
getInfo(out) {
|
|
153
|
+
out.arch = '';
|
|
154
|
+
out.distro = '';
|
|
155
|
+
out.distroVersion = '';
|
|
156
|
+
out.endianness = 'unknown';
|
|
157
|
+
out.engine = 'unknown';
|
|
158
|
+
out.engineVersion = '';
|
|
159
|
+
out.isTouch = false;
|
|
160
|
+
out.kind = 'unknown';
|
|
161
|
+
out.locale = '';
|
|
162
|
+
out.name = 'unknown';
|
|
163
|
+
out.osBuild = '';
|
|
164
|
+
out.pointerWidth = -1;
|
|
165
|
+
out.runtime = 'unknown';
|
|
166
|
+
out.version = '';
|
|
167
|
+
return out;
|
|
168
|
+
},
|
|
169
|
+
};
|
|
116
170
|
function getWebPlatformInfo(out) {
|
|
117
171
|
const nav = typeof navigator !== 'undefined' ? navigator : null;
|
|
118
172
|
const ua = nav?.userAgent ?? '';
|
package/dist/platform.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"platform.js","sourceRoot":"","sources":["../src/platform.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"platform.js","sourceRoot":"","sources":["../src/platform.ts"],"names":[],"mappings":"AASA,OAAO,EACL,gBAAgB,EAChB,kBAAkB,EAClB,oBAAoB,EACpB,2BAA2B,EAC3B,kBAAkB,EAClB,kBAAkB,EAClB,0BAA0B,EAC1B,qBAAqB,EACrB,qBAAqB,GACtB,MAAM,8BAA8B,CAAC;AAEtC,4FAA4F;AAC5F,6FAA6F;AAC7F,gEAAgE;AAChE,MAAM,UAAU,uBAAuB,CAAC,CAAS,EAAE,CAAS;IAC1D,IAAI,CAAC,KAAK,CAAC;QAAE,OAAO,CAAC,CAAC;IACtB,MAAM,MAAM,GAAG,CAAC,KAAK,EAAE,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,CAAC,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC;IAC5C,MAAM,MAAM,GAAG,CAAC,KAAK,EAAE,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,CAAC,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC;IAC5C,MAAM,GAAG,GAAG,IAAI,CAAC,GAAG,CAAC,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,MAAM,CAAC,CAAC;IACnD,KAAK,IAAI,CAAC,GAAG,CAAC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AI,CAAC,CAAC;IACxD,yEAAyE;IACzE,GAAG,CAAC,OAAO,GAAG,EAAE,CAAC;IACjB,GAAG,CAAC,MAAM,GAAG,EAAE,CAAC;IAChB,GAAG,CAAC,aAAa,GAAG,EAAE,CAAC;IACvB,OAAO,GAAG,CAAC;AACb,CAAC"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@flighthq/platform",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.4.0-edge.1908.751021c",
|
|
4
4
|
"author": "Joshua Granick and other contributors",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"repository": {
|
|
@@ -38,8 +38,8 @@
|
|
|
38
38
|
"clean:dist": "tsx ../../scripts/clean-package-dist.ts"
|
|
39
39
|
},
|
|
40
40
|
"dependencies": {
|
|
41
|
-
"@flighthq/types": "0.
|
|
42
|
-
"@flighthq/useragent": "0.
|
|
41
|
+
"@flighthq/types": "0.4.0-edge.1908.751021c",
|
|
42
|
+
"@flighthq/useragent": "0.4.0-edge.1908.751021c"
|
|
43
43
|
},
|
|
44
44
|
"devDependencies": {
|
|
45
45
|
"typescript": "^5.3.0"
|
package/src/platform.test.ts
CHANGED
|
@@ -17,6 +17,10 @@ import {
|
|
|
17
17
|
isPlatformVersionAtLeast,
|
|
18
18
|
isPlatformWeb,
|
|
19
19
|
setPlatformBackend,
|
|
20
|
+
explainPlatformBackend,
|
|
21
|
+
installPlatformHostBackend,
|
|
22
|
+
observePlatformHostResult,
|
|
23
|
+
resetPlatformBackendForTest,
|
|
20
24
|
} from './platform';
|
|
21
25
|
|
|
22
26
|
function fakeBackend(info: Partial<PlatformInfo>): PlatformBackend {
|
|
@@ -141,6 +145,34 @@ describe('createWebPlatformBackend', () => {
|
|
|
141
145
|
});
|
|
142
146
|
});
|
|
143
147
|
|
|
148
|
+
describe('explainPlatformBackend', () => {
|
|
149
|
+
afterEach(() => resetPlatformBackendForTest());
|
|
150
|
+
|
|
151
|
+
it('reports host-not-enabled when no backend is installed', () => {
|
|
152
|
+
resetPlatformBackendForTest();
|
|
153
|
+
const explanation = explainPlatformBackend();
|
|
154
|
+
expect(explanation.layer).toBe('host-not-enabled');
|
|
155
|
+
expect(explanation.conflict).toBe(false);
|
|
156
|
+
expect(explanation.viability).toBe('unobserved');
|
|
157
|
+
});
|
|
158
|
+
|
|
159
|
+
it('reports custom layer when a custom backend is set', () => {
|
|
160
|
+
setPlatformBackend(fakeBackend({}));
|
|
161
|
+
expect(explainPlatformBackend().layer).toBe('custom');
|
|
162
|
+
});
|
|
163
|
+
|
|
164
|
+
it('reports host layer when a host backend is installed', () => {
|
|
165
|
+
installPlatformHostBackend(fakeBackend({}));
|
|
166
|
+
expect(explainPlatformBackend().layer).toBe('host');
|
|
167
|
+
});
|
|
168
|
+
|
|
169
|
+
it('reports conflict when two different host backends are installed', () => {
|
|
170
|
+
installPlatformHostBackend(fakeBackend({}));
|
|
171
|
+
installPlatformHostBackend(fakeBackend({}));
|
|
172
|
+
expect(explainPlatformBackend().conflict).toBe(true);
|
|
173
|
+
});
|
|
174
|
+
});
|
|
175
|
+
|
|
144
176
|
describe('getPlatformBackend', () => {
|
|
145
177
|
it('falls back to a web backend when none is registered', () => {
|
|
146
178
|
expect(getPlatformBackend()).not.toBeNull();
|
|
@@ -226,6 +258,25 @@ describe('getPlatformRuntime', () => {
|
|
|
226
258
|
});
|
|
227
259
|
});
|
|
228
260
|
|
|
261
|
+
describe('installPlatformHostBackend', () => {
|
|
262
|
+
afterEach(() => resetPlatformBackendForTest());
|
|
263
|
+
|
|
264
|
+
it('installs a host backend that getPlatformBackend returns', () => {
|
|
265
|
+
const backend = fakeBackend({});
|
|
266
|
+
installPlatformHostBackend(backend);
|
|
267
|
+
expect(getPlatformBackend()).toBe(backend);
|
|
268
|
+
});
|
|
269
|
+
|
|
270
|
+
it('is first-host-wins: a second different backend sets conflict', () => {
|
|
271
|
+
const first = fakeBackend({});
|
|
272
|
+
const second = fakeBackend({});
|
|
273
|
+
installPlatformHostBackend(first);
|
|
274
|
+
installPlatformHostBackend(second);
|
|
275
|
+
expect(getPlatformBackend()).toBe(first);
|
|
276
|
+
expect(explainPlatformBackend().conflict).toBe(true);
|
|
277
|
+
});
|
|
278
|
+
});
|
|
279
|
+
|
|
229
280
|
describe('isPlatformDesktop', () => {
|
|
230
281
|
it('is true only for desktop kind', () => {
|
|
231
282
|
setPlatformBackend(fakeBackend({ kind: 'desktop' }));
|
|
@@ -317,6 +368,36 @@ describe('isPlatformWeb', () => {
|
|
|
317
368
|
});
|
|
318
369
|
});
|
|
319
370
|
|
|
371
|
+
describe('observePlatformHostResult', () => {
|
|
372
|
+
afterEach(() => resetPlatformBackendForTest());
|
|
373
|
+
|
|
374
|
+
it('records a successful observation', () => {
|
|
375
|
+
installPlatformHostBackend(fakeBackend({}));
|
|
376
|
+
observePlatformHostResult('getInfo', true);
|
|
377
|
+
const explanation = explainPlatformBackend();
|
|
378
|
+
expect(explanation.operation).toBe('getInfo');
|
|
379
|
+
expect(explanation.viability).toBe('available');
|
|
380
|
+
});
|
|
381
|
+
|
|
382
|
+
it('records a failed observation', () => {
|
|
383
|
+
installPlatformHostBackend(fakeBackend({}));
|
|
384
|
+
observePlatformHostResult('getInfo', false);
|
|
385
|
+
expect(explainPlatformBackend().viability).toBe('runtime-api-unavailable');
|
|
386
|
+
});
|
|
387
|
+
});
|
|
388
|
+
|
|
389
|
+
describe('resetPlatformBackendForTest', () => {
|
|
390
|
+
it('clears all backend slots', () => {
|
|
391
|
+
setPlatformBackend(fakeBackend({}));
|
|
392
|
+
installPlatformHostBackend(fakeBackend({}));
|
|
393
|
+
observePlatformHostResult('getInfo', true);
|
|
394
|
+
resetPlatformBackendForTest();
|
|
395
|
+
expect(explainPlatformBackend().layer).toBe('host-not-enabled');
|
|
396
|
+
expect(explainPlatformBackend().conflict).toBe(false);
|
|
397
|
+
expect(explainPlatformBackend().viability).toBe('unobserved');
|
|
398
|
+
});
|
|
399
|
+
});
|
|
400
|
+
|
|
320
401
|
describe('setPlatformBackend', () => {
|
|
321
402
|
it('clears back to the web fallback when passed null', () => {
|
|
322
403
|
setPlatformBackend(fakeBackend({ name: 'linux' }));
|