@flighthq/entity 0.5.1-next.601.e6e16ba → 0.5.1-next.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 +1 -0
- package/dist/contract.d.ts.map +1 -1
- package/dist/contract.js +1 -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/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/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.1-next.
|
|
17
|
-
- [License](https://github.com/flighthq/flight/blob/
|
|
16
|
+
- [Source for @flighthq/entity@0.5.1-next.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
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,QAAQ,CAAC;AACvB,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
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,QAAQ,CAAC;AACvB,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/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.1-next.
|
|
3
|
+
"version": "0.5.1-next.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.1-next.
|
|
42
|
-
"@flighthq/types": "0.5.1-next.
|
|
41
|
+
"@flighthq/log": "0.5.1-next.638.d4dbd4e",
|
|
42
|
+
"@flighthq/types": "0.5.1-next.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
|
+
});
|