@flighthq/entity 0.5.0-next.1944.cd6b6e7 → 0.5.1-edge.638.d4dbd4e
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/contract.d.ts +2 -0
- package/dist/contract.d.ts.map +1 -1
- package/dist/contract.js +2 -0
- package/dist/contract.js.map +1 -1
- package/dist/entityUid.d.ts +4 -0
- package/dist/entityUid.d.ts.map +1 -0
- package/dist/entityUid.js +25 -0
- package/dist/entityUid.js.map +1 -0
- package/dist/host.d.ts +3 -0
- package/dist/host.d.ts.map +1 -0
- package/dist/host.js +33 -0
- package/dist/host.js.map +1 -0
- 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/package.json +3 -3
- package/src/entityUid.test.ts +64 -0
- package/src/host.test.ts +71 -0
package/README.md
CHANGED
|
@@ -13,5 +13,5 @@ Import the supported application-facing API from `@flighthq/entity`. The `@fligh
|
|
|
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/entity@0.5.
|
|
17
|
-
- [License](https://github.com/flighthq/flight/blob/
|
|
16
|
+
- [Source for @flighthq/entity@0.5.1-edge.638.d4dbd4e](https://github.com/flighthq/flight/tree/d4dbd4e347dc8be10b180c85a766ab50333dcb51/packages/entity)
|
|
17
|
+
- [License](https://github.com/flighthq/flight/blob/d4dbd4e347dc8be10b180c85a766ab50333dcb51/LICENSE.md)
|
package/dist/contract.d.ts
CHANGED
|
@@ -2,6 +2,8 @@ export * from './binding';
|
|
|
2
2
|
export * from './clone';
|
|
3
3
|
export * from './entity';
|
|
4
4
|
export * from './enableEntityRuntimeGuards';
|
|
5
|
+
export * from './entityUid';
|
|
5
6
|
export * from './guards';
|
|
7
|
+
export * from './host';
|
|
6
8
|
export * from './runtime';
|
|
7
9
|
//# sourceMappingURL=contract.d.ts.map
|
package/dist/contract.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"contract.d.ts","sourceRoot":"","sources":["../src/contract.ts"],"names":[],"mappings":"AAAA,cAAc,WAAW,CAAC;AAC1B,cAAc,SAAS,CAAC;AACxB,cAAc,UAAU,CAAC;AACzB,cAAc,6BAA6B,CAAC;AAC5C,cAAc,UAAU,CAAC;AACzB,cAAc,WAAW,CAAC"}
|
|
1
|
+
{"version":3,"file":"contract.d.ts","sourceRoot":"","sources":["../src/contract.ts"],"names":[],"mappings":"AAAA,cAAc,WAAW,CAAC;AAC1B,cAAc,SAAS,CAAC;AACxB,cAAc,UAAU,CAAC;AACzB,cAAc,6BAA6B,CAAC;AAC5C,cAAc,aAAa,CAAC;AAC5B,cAAc,UAAU,CAAC;AACzB,cAAc,QAAQ,CAAC;AACvB,cAAc,WAAW,CAAC"}
|
package/dist/contract.js
CHANGED
|
@@ -2,6 +2,8 @@ export * from './binding';
|
|
|
2
2
|
export * from './clone';
|
|
3
3
|
export * from './entity';
|
|
4
4
|
export * from './enableEntityRuntimeGuards';
|
|
5
|
+
export * from './entityUid';
|
|
5
6
|
export * from './guards';
|
|
7
|
+
export * from './host';
|
|
6
8
|
export * from './runtime';
|
|
7
9
|
//# sourceMappingURL=contract.js.map
|
package/dist/contract.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"contract.js","sourceRoot":"","sources":["../src/contract.ts"],"names":[],"mappings":"AAAA,cAAc,WAAW,CAAC;AAC1B,cAAc,SAAS,CAAC;AACxB,cAAc,UAAU,CAAC;AACzB,cAAc,6BAA6B,CAAC;AAC5C,cAAc,UAAU,CAAC;AACzB,cAAc,WAAW,CAAC"}
|
|
1
|
+
{"version":3,"file":"contract.js","sourceRoot":"","sources":["../src/contract.ts"],"names":[],"mappings":"AAAA,cAAc,WAAW,CAAC;AAC1B,cAAc,SAAS,CAAC;AACxB,cAAc,UAAU,CAAC;AACzB,cAAc,6BAA6B,CAAC;AAC5C,cAAc,aAAa,CAAC;AAC5B,cAAc,UAAU,CAAC;AACzB,cAAc,QAAQ,CAAC;AACvB,cAAc,WAAW,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"entityUid.d.ts","sourceRoot":"","sources":["../src/entityUid.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,MAAM,EAAiB,MAAM,0BAA0B,CAAC;AAKtE,wBAAgB,YAAY,CAAC,MAAM,EAAE,MAAM,GAAG,MAAM,CAMnD;AAED,wBAAgB,YAAY,CAAC,MAAM,EAAE,MAAM,EAAE,GAAG,EAAE,MAAM,GAAG,IAAI,CAG9D"}
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
import { EntityRuntimeKey } from '@flighthq/types/contract';
|
|
2
|
+
import { createEntityRuntime } from './runtime';
|
|
3
|
+
export function getEntityUid(source) {
|
|
4
|
+
const runtime = ensureEntityRuntime(source);
|
|
5
|
+
if (runtime.uid !== undefined)
|
|
6
|
+
return runtime.uid;
|
|
7
|
+
const uid = generateEntityUid();
|
|
8
|
+
runtime.uid = uid;
|
|
9
|
+
return uid;
|
|
10
|
+
}
|
|
11
|
+
export function setEntityUid(source, uid) {
|
|
12
|
+
const runtime = ensureEntityRuntime(source);
|
|
13
|
+
runtime.uid = uid;
|
|
14
|
+
}
|
|
15
|
+
function ensureEntityRuntime(source) {
|
|
16
|
+
if (source[EntityRuntimeKey] === undefined) {
|
|
17
|
+
source[EntityRuntimeKey] = createEntityRuntime();
|
|
18
|
+
}
|
|
19
|
+
return source[EntityRuntimeKey];
|
|
20
|
+
}
|
|
21
|
+
function generateEntityUid() {
|
|
22
|
+
return `entity-${_nextEntityUidCounter++}`;
|
|
23
|
+
}
|
|
24
|
+
let _nextEntityUidCounter = 1;
|
|
25
|
+
//# sourceMappingURL=entityUid.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"entityUid.js","sourceRoot":"","sources":["../src/entityUid.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,gBAAgB,EAAE,MAAM,0BAA0B,CAAC;AAE5D,OAAO,EAAE,mBAAmB,EAAE,MAAM,WAAW,CAAC;AAEhD,MAAM,UAAU,YAAY,CAAC,MAAc;IACzC,MAAM,OAAO,GAAG,mBAAmB,CAAC,MAAM,CAAC,CAAC;IAC5C,IAAI,OAAO,CAAC,GAAG,KAAK,SAAS;QAAE,OAAO,OAAO,CAAC,GAAG,CAAC;IAClD,MAAM,GAAG,GAAG,iBAAiB,EAAE,CAAC;IAChC,OAAO,CAAC,GAAG,GAAG,GAAG,CAAC;IAClB,OAAO,GAAG,CAAC;AACb,CAAC;AAED,MAAM,UAAU,YAAY,CAAC,MAAc,EAAE,GAAW;IACtD,MAAM,OAAO,GAAG,mBAAmB,CAAC,MAAM,CAAC,CAAC;IAC5C,OAAO,CAAC,GAAG,GAAG,GAAG,CAAC;AACpB,CAAC;AAED,SAAS,mBAAmB,CAAC,MAAc;IACzC,IAAI,MAAM,CAAC,gBAAgB,CAAC,KAAK,SAAS,EAAE,CAAC;QAC3C,MAAM,CAAC,gBAAgB,CAAC,GAAG,mBAAmB,EAAE,CAAC;IACnD,CAAC;IACD,OAAO,MAAM,CAAC,gBAAgB,CAAE,CAAC;AACnC,CAAC;AAED,SAAS,iBAAiB;IACxB,OAAO,UAAU,qBAAqB,EAAE,EAAE,CAAC;AAC7C,CAAC;AAED,IAAI,qBAAqB,GAAG,CAAC,CAAC"}
|
package/dist/host.d.ts
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"host.d.ts","sourceRoot":"","sources":["../src/host.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,oBAAoB,EAAE,IAAI,EAAE,MAAM,0BAA0B,CAAC;AAI3E,wBAAgB,UAAU,CAAC,YAAY,SAAS,OAAO,CAAC,oBAAoB,CAAC,IAAI,CAAC,CAAC,EACjF,YAAY,GAAE,QAAQ,CAAC,YAAY,CAAsB,GACxD,IAAI,GAAG,YAAY,CA8BrB"}
|
package/dist/host.js
ADDED
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
import { createEntity } from './entity';
|
|
2
|
+
export function createHost(capabilities = {}) {
|
|
3
|
+
return createEntity({
|
|
4
|
+
accessibility: {},
|
|
5
|
+
app: {},
|
|
6
|
+
clipboard: {},
|
|
7
|
+
connectivity: {},
|
|
8
|
+
dialog: {},
|
|
9
|
+
graphics: {},
|
|
10
|
+
input: {},
|
|
11
|
+
ipc: {},
|
|
12
|
+
media: {},
|
|
13
|
+
menu: {},
|
|
14
|
+
midi: {},
|
|
15
|
+
net: {},
|
|
16
|
+
notification: {},
|
|
17
|
+
power: {},
|
|
18
|
+
protocol: {},
|
|
19
|
+
screen: {},
|
|
20
|
+
share: {},
|
|
21
|
+
shell: {},
|
|
22
|
+
shortcut: {},
|
|
23
|
+
storage: {},
|
|
24
|
+
system: {},
|
|
25
|
+
text: {},
|
|
26
|
+
tray: {},
|
|
27
|
+
ui: {},
|
|
28
|
+
updater: {},
|
|
29
|
+
window: {},
|
|
30
|
+
...capabilities,
|
|
31
|
+
});
|
|
32
|
+
}
|
|
33
|
+
//# sourceMappingURL=host.js.map
|
package/dist/host.js.map
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"host.js","sourceRoot":"","sources":["../src/host.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,YAAY,EAAE,MAAM,UAAU,CAAC;AAExC,MAAM,UAAU,UAAU,CACxB,eAAuC,EAAkB;IAEzD,OAAO,YAAY,CAAC;QAClB,aAAa,EAAE,EAAE;QACjB,GAAG,EAAE,EAAE;QACP,SAAS,EAAE,EAAE;QACb,YAAY,EAAE,EAAE;QAChB,MAAM,EAAE,EAAE;QACV,QAAQ,EAAE,EAAE;QACZ,KAAK,EAAE,EAAE;QACT,GAAG,EAAE,EAAE;QACP,KAAK,EAAE,EAAE;QACT,IAAI,EAAE,EAAE;QACR,IAAI,EAAE,EAAE;QACR,GAAG,EAAE,EAAE;QACP,YAAY,EAAE,EAAE;QAChB,KAAK,EAAE,EAAE;QACT,QAAQ,EAAE,EAAE;QACZ,MAAM,EAAE,EAAE;QACV,KAAK,EAAE,EAAE;QACT,KAAK,EAAE,EAAE;QACT,QAAQ,EAAE,EAAE;QACZ,OAAO,EAAE,EAAE;QACX,MAAM,EAAE,EAAE;QACV,IAAI,EAAE,EAAE;QACR,IAAI,EAAE,EAAE;QACR,EAAE,EAAE,EAAE;QACN,OAAO,EAAE,EAAE;QACX,MAAM,EAAE,EAAE;QACV,GAAG,YAAY;KAChB,CAAC,CAAC;AACL,CAAC"}
|
package/dist/index.d.ts
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
export {} from './contract';
|
|
1
|
+
export { getEntityUid, setEntityUid } 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,EAAE,MAAM,YAAY,CAAC"}
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,YAAY,EAAE,YAAY,EAAE,MAAM,YAAY,CAAC"}
|
package/dist/index.js
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
export {};
|
|
1
|
+
export { getEntityUid, setEntityUid } 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":""}
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,YAAY,EAAE,YAAY,EAAE,MAAM,YAAY,CAAC"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@flighthq/entity",
|
|
3
|
-
"version": "0.5.
|
|
3
|
+
"version": "0.5.1-edge.638.d4dbd4e",
|
|
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/log": "0.5.
|
|
42
|
-
"@flighthq/types": "0.5.
|
|
41
|
+
"@flighthq/log": "0.5.1-edge.638.d4dbd4e",
|
|
42
|
+
"@flighthq/types": "0.5.1-edge.638.d4dbd4e"
|
|
43
43
|
},
|
|
44
44
|
"devDependencies": {
|
|
45
45
|
"typescript": "^5.3.0"
|
|
@@ -0,0 +1,64 @@
|
|
|
1
|
+
import { EntityRuntimeKey } from '@flighthq/types/contract';
|
|
2
|
+
|
|
3
|
+
import { createEntity } from './entity';
|
|
4
|
+
import { getEntityUid, setEntityUid } from './entityUid';
|
|
5
|
+
import { createEntityRuntime } from './runtime';
|
|
6
|
+
|
|
7
|
+
describe('getEntityUid', () => {
|
|
8
|
+
it('has no uid property on an untouched runtime before any access', () => {
|
|
9
|
+
const entity = createEntity();
|
|
10
|
+
entity[EntityRuntimeKey] = createEntityRuntime();
|
|
11
|
+
expect('uid' in entity[EntityRuntimeKey]!).toBe(false);
|
|
12
|
+
});
|
|
13
|
+
|
|
14
|
+
it('lazily generates a uid on first access', () => {
|
|
15
|
+
const entity = createEntity();
|
|
16
|
+
const uid = getEntityUid(entity);
|
|
17
|
+
expect(uid).toEqual(expect.any(String));
|
|
18
|
+
expect(uid.length).toBeGreaterThan(0);
|
|
19
|
+
});
|
|
20
|
+
|
|
21
|
+
it('returns the same uid on repeated access', () => {
|
|
22
|
+
const entity = createEntity();
|
|
23
|
+
const first = getEntityUid(entity);
|
|
24
|
+
const second = getEntityUid(entity);
|
|
25
|
+
expect(second).toBe(first);
|
|
26
|
+
});
|
|
27
|
+
|
|
28
|
+
it('generates distinct uids for different entities', () => {
|
|
29
|
+
const a = createEntity();
|
|
30
|
+
const b = createEntity();
|
|
31
|
+
expect(getEntityUid(a)).not.toBe(getEntityUid(b));
|
|
32
|
+
});
|
|
33
|
+
|
|
34
|
+
it('creates the runtime if the entity has none', () => {
|
|
35
|
+
const entity = createEntity();
|
|
36
|
+
expect(entity[EntityRuntimeKey]).toBeUndefined();
|
|
37
|
+
getEntityUid(entity);
|
|
38
|
+
expect(entity[EntityRuntimeKey]).toBeDefined();
|
|
39
|
+
});
|
|
40
|
+
});
|
|
41
|
+
|
|
42
|
+
describe('setEntityUid', () => {
|
|
43
|
+
it('sets a stable id before any get', () => {
|
|
44
|
+
const entity = createEntity();
|
|
45
|
+
setEntityUid(entity, 'my-stable-id');
|
|
46
|
+
expect(getEntityUid(entity)).toBe('my-stable-id');
|
|
47
|
+
});
|
|
48
|
+
|
|
49
|
+
it('replaces a previously generated uid', () => {
|
|
50
|
+
const entity = createEntity();
|
|
51
|
+
const generated = getEntityUid(entity);
|
|
52
|
+
setEntityUid(entity, 'override');
|
|
53
|
+
expect(getEntityUid(entity)).toBe('override');
|
|
54
|
+
expect(getEntityUid(entity)).not.toBe(generated);
|
|
55
|
+
});
|
|
56
|
+
|
|
57
|
+
it('creates the runtime if the entity has none', () => {
|
|
58
|
+
const entity = createEntity();
|
|
59
|
+
expect(entity[EntityRuntimeKey]).toBeUndefined();
|
|
60
|
+
setEntityUid(entity, 'pre-bind');
|
|
61
|
+
expect(entity[EntityRuntimeKey]).toBeDefined();
|
|
62
|
+
expect(getEntityUid(entity)).toBe('pre-bind');
|
|
63
|
+
});
|
|
64
|
+
});
|
package/src/host.test.ts
ADDED
|
@@ -0,0 +1,71 @@
|
|
|
1
|
+
import { EntityRuntimeKey } from '@flighthq/types/contract';
|
|
2
|
+
|
|
3
|
+
import * as entity from './contract';
|
|
4
|
+
|
|
5
|
+
const HOST_GROUPS = [
|
|
6
|
+
'accessibility',
|
|
7
|
+
'app',
|
|
8
|
+
'clipboard',
|
|
9
|
+
'connectivity',
|
|
10
|
+
'dialog',
|
|
11
|
+
'graphics',
|
|
12
|
+
'input',
|
|
13
|
+
'ipc',
|
|
14
|
+
'media',
|
|
15
|
+
'menu',
|
|
16
|
+
'midi',
|
|
17
|
+
'net',
|
|
18
|
+
'notification',
|
|
19
|
+
'power',
|
|
20
|
+
'protocol',
|
|
21
|
+
'screen',
|
|
22
|
+
'share',
|
|
23
|
+
'shell',
|
|
24
|
+
'shortcut',
|
|
25
|
+
'storage',
|
|
26
|
+
'system',
|
|
27
|
+
'text',
|
|
28
|
+
'tray',
|
|
29
|
+
'ui',
|
|
30
|
+
'updater',
|
|
31
|
+
'window',
|
|
32
|
+
] as const;
|
|
33
|
+
|
|
34
|
+
describe('createHost', () => {
|
|
35
|
+
it('creates an Entity immediately while leaving its runtime allocation lazy', () => {
|
|
36
|
+
const host = requiredFunction(entity, 'createHost')();
|
|
37
|
+
|
|
38
|
+
expect(EntityRuntimeKey in host).toBe(true);
|
|
39
|
+
expect(host[EntityRuntimeKey]).toBeUndefined();
|
|
40
|
+
});
|
|
41
|
+
|
|
42
|
+
it('materializes the complete stable Host shape with truthful empty groups', () => {
|
|
43
|
+
const host = requiredFunction(entity, 'createHost')();
|
|
44
|
+
|
|
45
|
+
expect(
|
|
46
|
+
Object.keys(host)
|
|
47
|
+
.filter((key) => key !== String(EntityRuntimeKey))
|
|
48
|
+
.sort(),
|
|
49
|
+
).toEqual(HOST_GROUPS);
|
|
50
|
+
for (const group of HOST_GROUPS) expect(host[group]).toEqual({});
|
|
51
|
+
});
|
|
52
|
+
|
|
53
|
+
it('preserves supplied capability-group and provider identities without populating another group', () => {
|
|
54
|
+
const provider = {};
|
|
55
|
+
const accessibility = { provider };
|
|
56
|
+
const host = requiredFunction(entity, 'createHost')({ accessibility });
|
|
57
|
+
|
|
58
|
+
expect(host.accessibility).toBe(accessibility);
|
|
59
|
+
expect(host.accessibility.provider).toBe(provider);
|
|
60
|
+
for (const group of HOST_GROUPS) {
|
|
61
|
+
if (group !== 'accessibility') expect(host[group]).toEqual({});
|
|
62
|
+
}
|
|
63
|
+
});
|
|
64
|
+
});
|
|
65
|
+
|
|
66
|
+
function requiredFunction(module: object, name: string): (...args: any[]) => any {
|
|
67
|
+
const value = Reflect.get(module, name);
|
|
68
|
+
expect(value, `${name} export`).toBeTypeOf('function');
|
|
69
|
+
if (typeof value !== 'function') throw new TypeError(`${name} is not exported`);
|
|
70
|
+
return value as (...args: any[]) => any;
|
|
71
|
+
}
|