@flighthq/entity 0.5.1-next.693.478551c → 0.5.1-next.729.2aeb707

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 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.693.478551c](https://github.com/flighthq/flight/tree/478551cf7887f05c42c11f75e59034c715c8495f/packages/entity)
17
- - [License](https://github.com/flighthq/flight/blob/478551cf7887f05c42c11f75e59034c715c8495f/LICENSE.md)
16
+ - [Source for @flighthq/entity@0.5.1-next.729.2aeb707](https://github.com/flighthq/flight/tree/2aeb707259007d61c5aaf2e31fe47447a260fe2a/packages/entity)
17
+ - [License](https://github.com/flighthq/flight/blob/2aeb707259007d61c5aaf2e31fe47447a260fe2a/LICENSE.md)
package/dist/binding.d.ts CHANGED
@@ -1,4 +1,7 @@
1
1
  import type { Entity } from '@flighthq/types/contract';
2
2
  export declare function attachEntityBinding(entity: Entity, binding: object): void;
3
- export declare function getEntityBinding(source: Entity): object | null;
3
+ export declare function detachEntityBinding(entity: Entity): void;
4
+ export declare function getEntityBinding(source: Readonly<Entity>): object | null;
5
+ export declare function getEntityBindingAs<Type>(source: Readonly<Entity>): Type | null;
6
+ export declare function hasEntityBinding(source: Readonly<Entity>): boolean;
4
7
  //# sourceMappingURL=binding.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"binding.d.ts","sourceRoot":"","sources":["../src/binding.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,0BAA0B,CAAC;AAKvD,wBAAgB,mBAAmB,CAAC,MAAM,EAAE,MAAM,EAAE,OAAO,EAAE,MAAM,GAAG,IAAI,CAKzE;AAED,wBAAgB,gBAAgB,CAAC,MAAM,EAAE,MAAM,GAAG,MAAM,GAAG,IAAI,CAG9D"}
1
+ {"version":3,"file":"binding.d.ts","sourceRoot":"","sources":["../src/binding.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,0BAA0B,CAAC;AAKvD,wBAAgB,mBAAmB,CAAC,MAAM,EAAE,MAAM,EAAE,OAAO,EAAE,MAAM,GAAG,IAAI,CAKzE;AAED,wBAAgB,mBAAmB,CAAC,MAAM,EAAE,MAAM,GAAG,IAAI,CAGxD;AAED,wBAAgB,gBAAgB,CAAC,MAAM,EAAE,QAAQ,CAAC,MAAM,CAAC,GAAG,MAAM,GAAG,IAAI,CAExE;AAED,wBAAgB,kBAAkB,CAAC,IAAI,EAAE,MAAM,EAAE,QAAQ,CAAC,MAAM,CAAC,GAAG,IAAI,GAAG,IAAI,CAE9E;AAED,wBAAgB,gBAAgB,CAAC,MAAM,EAAE,QAAQ,CAAC,MAAM,CAAC,GAAG,OAAO,CAElE"}
package/dist/binding.js CHANGED
@@ -1,13 +1,23 @@
1
1
  import { EntityRuntimeKey } from '@flighthq/types/contract';
2
- import { createEntityRuntime, getEntityRuntime } from './runtime';
2
+ import { createEntityRuntime } from './runtime';
3
3
  export function attachEntityBinding(entity, binding) {
4
4
  if (entity[EntityRuntimeKey] === undefined) {
5
5
  entity[EntityRuntimeKey] = createEntityRuntime();
6
6
  }
7
7
  entity[EntityRuntimeKey].binding = binding;
8
8
  }
9
+ export function detachEntityBinding(entity) {
10
+ const runtime = entity[EntityRuntimeKey];
11
+ if (runtime !== undefined)
12
+ runtime.binding = null;
13
+ }
9
14
  export function getEntityBinding(source) {
10
- const runtime = getEntityRuntime(source);
11
- return runtime?.binding ?? null;
15
+ return source[EntityRuntimeKey]?.binding ?? null;
16
+ }
17
+ export function getEntityBindingAs(source) {
18
+ return getEntityBinding(source);
19
+ }
20
+ export function hasEntityBinding(source) {
21
+ return getEntityBinding(source) !== null;
12
22
  }
13
23
  //# sourceMappingURL=binding.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"binding.js","sourceRoot":"","sources":["../src/binding.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,gBAAgB,EAAE,MAAM,0BAA0B,CAAC;AAE5D,OAAO,EAAE,mBAAmB,EAAE,gBAAgB,EAAE,MAAM,WAAW,CAAC;AAElE,MAAM,UAAU,mBAAmB,CAAC,MAAc,EAAE,OAAe;IACjE,IAAI,MAAM,CAAC,gBAAgB,CAAC,KAAK,SAAS,EAAE,CAAC;QAC3C,MAAM,CAAC,gBAAgB,CAAC,GAAG,mBAAmB,EAAE,CAAC;IACnD,CAAC;IACD,MAAM,CAAC,gBAAgB,CAAC,CAAC,OAAO,GAAG,OAAO,CAAC;AAC7C,CAAC;AAED,MAAM,UAAU,gBAAgB,CAAC,MAAc;IAC7C,MAAM,OAAO,GAAG,gBAAgB,CAAC,MAAM,CAAC,CAAC;IACzC,OAAO,OAAO,EAAE,OAAO,IAAI,IAAI,CAAC;AAClC,CAAC"}
1
+ {"version":3,"file":"binding.js","sourceRoot":"","sources":["../src/binding.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,gBAAgB,EAAE,MAAM,0BAA0B,CAAC;AAE5D,OAAO,EAAE,mBAAmB,EAAE,MAAM,WAAW,CAAC;AAEhD,MAAM,UAAU,mBAAmB,CAAC,MAAc,EAAE,OAAe;IACjE,IAAI,MAAM,CAAC,gBAAgB,CAAC,KAAK,SAAS,EAAE,CAAC;QAC3C,MAAM,CAAC,gBAAgB,CAAC,GAAG,mBAAmB,EAAE,CAAC;IACnD,CAAC;IACD,MAAM,CAAC,gBAAgB,CAAC,CAAC,OAAO,GAAG,OAAO,CAAC;AAC7C,CAAC;AAED,MAAM,UAAU,mBAAmB,CAAC,MAAc;IAChD,MAAM,OAAO,GAAG,MAAM,CAAC,gBAAgB,CAAC,CAAC;IACzC,IAAI,OAAO,KAAK,SAAS;QAAE,OAAO,CAAC,OAAO,GAAG,IAAI,CAAC;AACpD,CAAC;AAED,MAAM,UAAU,gBAAgB,CAAC,MAAwB;IACvD,OAAO,MAAM,CAAC,gBAAgB,CAAC,EAAE,OAAO,IAAI,IAAI,CAAC;AACnD,CAAC;AAED,MAAM,UAAU,kBAAkB,CAAO,MAAwB;IAC/D,OAAO,gBAAgB,CAAC,MAAM,CAAgB,CAAC;AACjD,CAAC;AAED,MAAM,UAAU,gBAAgB,CAAC,MAAwB;IACvD,OAAO,gBAAgB,CAAC,MAAM,CAAC,KAAK,IAAI,CAAC;AAC3C,CAAC"}
package/dist/guards.js CHANGED
@@ -4,7 +4,7 @@ export function areEntityRuntimeGuardsEnabled() {
4
4
  return _guardsEnabled;
5
5
  }
6
6
  // Creates a guarded entity that warns when the runtime slot is written directly rather
7
- // than through ensureEntityRuntime or attachEntityBinding. Only active when guards are
7
+ // than through a public helper such as attachEntityBinding. Only active when guards are
8
8
  // enabled via enableEntityRuntimeGuards.
9
9
  export function createGuardedEntity(entity) {
10
10
  if (!_guardsEnabled || typeof Proxy === 'undefined')
@@ -13,9 +13,9 @@ export function createGuardedEntity(entity) {
13
13
  set(target, prop, value) {
14
14
  if (prop === EntityRuntimeKey && _guardsEnabled) {
15
15
  // The write is reported and then ALLOWED: the stack cannot be inspected reliably across
16
- // environments, so trusted callers (ensureEntityRuntime, attachEntityBinding) cannot be told apart
17
- // from a raw poke. Reporting goes through the seam rather than the console so it uses the standard
18
- // sink — see enableEntityRuntimeGuards.
16
+ // environments, so trusted callers such as attachEntityBinding cannot be told apart from a raw
17
+ // poke. Reporting goes through the seam rather than the console so it uses the standard sink — see
18
+ // enableEntityRuntimeGuards.
19
19
  _writeGuard?.('runtime-slot');
20
20
  }
21
21
  target[prop] = value;
@@ -1 +1 @@
1
- {"version":3,"file":"guards.js","sourceRoot":"","sources":["../src/guards.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,gBAAgB,EAAE,MAAM,0BAA0B,CAAC;AAE5D,yFAAyF;AACzF,MAAM,UAAU,6BAA6B;IAC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C,cAAc,CAAC,CAAC;YAChC,CAAC;YACA,MAAkD,CAAC,IAAI,CAAC,GAAG,KAAK,CAAC;YAClE,OAAO,IAAI,CAAC;QACd,CAAC;KACF,CAAC,CAAC;AACL,CAAC;AAED,wGAAwG;AACxG,4FAA4F;AAC5F,MAAM,UAAU,yBAAyB,CAAC,OAAgB;IACxD,IAAI,OAAO,IAAI,OAAO,KAAK,KAAK,WAAW;QAAE,OAAO;IACpD,cAAc,GAAG,OAAO,CAAC;AAC3B,CAAC;AAED,wGAAwG;AACxG,0GAA0G;AAC1G,MAAM,UAAU,0BAA0B,CAAC,KAAqC;IAC9E,WAAW,GAAG,KAAK,CAAC;AACtB,CAAC;AAED,IAAI,cAAc,GAAG,KAAK,CAAC;AAC3B,IAAI,WAAW,GAAmC,IAAI,CAAC"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@flighthq/entity",
3
- "version": "0.5.1-next.693.478551c",
3
+ "version": "0.5.1-next.729.2aeb707",
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.693.478551c",
42
- "@flighthq/types": "0.5.1-next.693.478551c"
41
+ "@flighthq/log": "0.5.1-next.729.2aeb707",
42
+ "@flighthq/types": "0.5.1-next.729.2aeb707"
43
43
  },
44
44
  "devDependencies": {
45
45
  "typescript": "^5.3.0"
@@ -1,6 +1,12 @@
1
1
  import { EntityRuntimeKey } from '@flighthq/types/contract';
2
2
 
3
- import { attachEntityBinding, getEntityBinding } from './binding';
3
+ import {
4
+ attachEntityBinding,
5
+ detachEntityBinding,
6
+ getEntityBinding,
7
+ getEntityBindingAs,
8
+ hasEntityBinding,
9
+ } from './binding';
4
10
  import { createEntity } from './entity';
5
11
  import { createEntityRuntime, getEntityRuntime } from './runtime';
6
12
 
@@ -32,6 +38,28 @@ describe('attachEntityBinding', () => {
32
38
  });
33
39
  });
34
40
 
41
+ describe('detachEntityBinding', () => {
42
+ it('clears the binding while preserving the runtime', () => {
43
+ const entity = createEntity();
44
+ const runtime = createEntityRuntime();
45
+ runtime.binding = {};
46
+ entity[EntityRuntimeKey] = runtime;
47
+
48
+ detachEntityBinding(entity);
49
+
50
+ expect(entity[EntityRuntimeKey]).toBe(runtime);
51
+ expect(runtime.binding).toBeNull();
52
+ });
53
+
54
+ it('does not allocate a runtime when no binding exists', () => {
55
+ const entity = createEntity();
56
+
57
+ detachEntityBinding(entity);
58
+
59
+ expect(entity[EntityRuntimeKey]).toBeUndefined();
60
+ });
61
+ });
62
+
35
63
  describe('getEntityBinding', () => {
36
64
  it('returns null if the entity has no runtime', () => {
37
65
  const entity = createEntity();
@@ -51,4 +79,46 @@ describe('getEntityBinding', () => {
51
79
  entity[EntityRuntimeKey] = runtime;
52
80
  expect(getEntityBinding(entity)).toStrictEqual(runtime.binding);
53
81
  });
82
+
83
+ it('accepts a readonly entity', () => {
84
+ const entity: Readonly<ReturnType<typeof createEntity>> = createEntity();
85
+ expect(getEntityBinding(entity)).toBeNull();
86
+ });
87
+ });
88
+
89
+ describe('getEntityBindingAs', () => {
90
+ it('returns the binding with the caller-owned type', () => {
91
+ const entity = createEntity();
92
+ const binding = { name: 'wrapper' };
93
+ attachEntityBinding(entity, binding);
94
+
95
+ const result = getEntityBindingAs<{ name: string }>(entity);
96
+
97
+ expectTypeOf(result).toEqualTypeOf<{ name: string } | null>();
98
+ expect(result).toBe(binding);
99
+ });
100
+
101
+ it('returns null if no binding exists', () => {
102
+ const entity: Readonly<ReturnType<typeof createEntity>> = createEntity();
103
+ expect(getEntityBindingAs<{ name: string }>(entity)).toBeNull();
104
+ });
105
+ });
106
+
107
+ describe('hasEntityBinding', () => {
108
+ it('returns false if the entity has no runtime', () => {
109
+ const entity: Readonly<ReturnType<typeof createEntity>> = createEntity();
110
+ expect(hasEntityBinding(entity)).toBe(false);
111
+ });
112
+
113
+ it('returns false if the binding slot is empty', () => {
114
+ const entity = createEntity();
115
+ entity[EntityRuntimeKey] = createEntityRuntime();
116
+ expect(hasEntityBinding(entity)).toBe(false);
117
+ });
118
+
119
+ it('returns true if a binding exists', () => {
120
+ const entity = createEntity();
121
+ attachEntityBinding(entity, {});
122
+ expect(hasEntityBinding(entity)).toBe(true);
123
+ });
54
124
  });
@@ -46,8 +46,7 @@ describe('enableEntityRuntimeGuards', () => {
46
46
  }
47
47
  });
48
48
  expect(entries.length).toBe(1);
49
- // Names a function that actually exists: the point of the warning is that the caller can act on it,
50
- // and this guard spent its life directing readers to `ensureEntityRuntime`, which never existed.
49
+ // Names a function that actually exists: the point of the warning is that the caller can act on it.
51
50
  expect(messageOf(entries[0])).toContain('attachEntityBinding');
52
51
  });
53
52
 
@@ -62,6 +61,7 @@ describe('enableEntityRuntimeGuards', () => {
62
61
  });
63
62
  expect(entries.length).toBe(1);
64
63
  expect(messageOf(entries[0])).toContain('attachEntityBinding');
64
+ expect(messageOf(entries[0])).toContain('detachEntityBinding');
65
65
  });
66
66
 
67
67
  it('stays SILENT without the guard — the production default', () => {