@flighthq/entity 0.3.1-next.625.675880d → 0.3.1-next.704.69286f6

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@flighthq/entity",
3
- "version": "0.3.1-next.625.675880d",
3
+ "version": "0.3.1-next.704.69286f6",
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.3.1-next.625.675880d",
42
- "@flighthq/types": "0.3.1-next.625.675880d"
41
+ "@flighthq/log": "0.3.1-next.704.69286f6",
42
+ "@flighthq/types": "0.3.1-next.704.69286f6"
43
43
  },
44
44
  "devDependencies": {
45
45
  "typescript": "^5.3.0"
@@ -18,6 +18,18 @@ describe('attachEntityBinding', () => {
18
18
  attachEntityBinding(entity, binding);
19
19
  expect(getEntityRuntime(entity).binding).toStrictEqual(binding);
20
20
  });
21
+
22
+ it('preserves an existing runtime while assigning its binding', () => {
23
+ const entity = createEntity();
24
+ const runtime = createEntityRuntime();
25
+ const binding = {};
26
+ entity[EntityRuntimeKey] = runtime;
27
+
28
+ attachEntityBinding(entity, binding);
29
+
30
+ expect(getEntityRuntime(entity)).toBe(runtime);
31
+ expect(runtime.binding).toBe(binding);
32
+ });
21
33
  });
22
34
 
23
35
  describe('getEntityBinding', () => {
@@ -45,6 +45,41 @@ describe('setEntityRuntimeGuardMode', () => {
45
45
  }
46
46
  expect(areEntityRuntimeGuardsEnabled()).toBe(false);
47
47
  });
48
+
49
+ it('stays disabled when Proxy is unavailable', () => {
50
+ const originalProxy = globalThis.Proxy;
51
+ let enabled: boolean;
52
+ Object.defineProperty(globalThis, 'Proxy', { configurable: true, value: undefined, writable: true });
53
+ try {
54
+ setEntityRuntimeGuardMode(true);
55
+ enabled = areEntityRuntimeGuardsEnabled();
56
+ } finally {
57
+ Object.defineProperty(globalThis, 'Proxy', { configurable: true, value: originalProxy, writable: true });
58
+ setEntityRuntimeGuardMode(false);
59
+ }
60
+
61
+ expect(enabled!).toBe(false);
62
+ });
63
+
64
+ it('returns the original values when Proxy disappears after guards are enabled', () => {
65
+ const entity = createEntity({ x: 1 });
66
+ const runtime = createEntityRuntime();
67
+ const originalProxy = globalThis.Proxy;
68
+ let guardedEntity: typeof entity;
69
+ let guardedRuntime: typeof runtime;
70
+ setEntityRuntimeGuardMode(true);
71
+ Object.defineProperty(globalThis, 'Proxy', { configurable: true, value: undefined, writable: true });
72
+ try {
73
+ guardedEntity = createGuardedEntity(entity);
74
+ guardedRuntime = createGuardedEntityRuntime(runtime);
75
+ } finally {
76
+ Object.defineProperty(globalThis, 'Proxy', { configurable: true, value: originalProxy, writable: true });
77
+ setEntityRuntimeGuardMode(false);
78
+ }
79
+
80
+ expect(guardedEntity!).toBe(entity);
81
+ expect(guardedRuntime!).toBe(runtime);
82
+ });
48
83
  });
49
84
 
50
85
  describe('setEntityRuntimeWriteGuard', () => {
@@ -78,4 +113,42 @@ describe('setEntityRuntimeWriteGuard', () => {
78
113
  setEntityRuntimeGuardMode(false);
79
114
  }
80
115
  });
116
+
117
+ it('ignores writes to ordinary properties', () => {
118
+ const slots: EntityRuntimeWriteSlot[] = [];
119
+ setEntityRuntimeGuardMode(true);
120
+ setEntityRuntimeWriteGuard((slot) => slots.push(slot));
121
+ try {
122
+ const guardedEntity = createGuardedEntity(createEntity({ x: 1 }));
123
+ guardedEntity.x = 2;
124
+ const guardedRuntime = createGuardedEntityRuntime(createEntityRuntime()) as ReturnType<
125
+ typeof createEntityRuntime
126
+ > & { other?: number };
127
+ guardedRuntime.other = 3;
128
+ expect(guardedEntity.x).toBe(2);
129
+ expect(guardedRuntime.other).toBe(3);
130
+ expect(slots).toEqual([]);
131
+ } finally {
132
+ setEntityRuntimeWriteGuard(null);
133
+ setEntityRuntimeGuardMode(false);
134
+ }
135
+ });
136
+
137
+ it('keeps existing proxies silent after guard mode is disabled', () => {
138
+ const slots: EntityRuntimeWriteSlot[] = [];
139
+ setEntityRuntimeGuardMode(true);
140
+ setEntityRuntimeWriteGuard((slot) => slots.push(slot));
141
+ const guardedEntity = createGuardedEntity(createEntity());
142
+ const guardedRuntime = createGuardedEntityRuntime(createEntityRuntime());
143
+ setEntityRuntimeGuardMode(false);
144
+ try {
145
+ guardedEntity[EntityRuntimeKey] = undefined;
146
+ guardedRuntime.binding = {};
147
+ expect(slots).toEqual([]);
148
+ expect(guardedRuntime.binding).toEqual({});
149
+ } finally {
150
+ setEntityRuntimeWriteGuard(null);
151
+ setEntityRuntimeGuardMode(false);
152
+ }
153
+ });
81
154
  });