@flighthq/storage 0.4.0-next.1903.50bfa67 → 0.4.0-next.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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@flighthq/storage",
3
- "version": "0.4.0-next.1903.50bfa67",
3
+ "version": "0.4.0-next.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/signals": "0.4.0-next.1903.50bfa67",
42
- "@flighthq/types": "0.4.0-next.1903.50bfa67"
41
+ "@flighthq/signals": "0.4.0-next.1908.751021c",
42
+ "@flighthq/types": "0.4.0-next.1908.751021c"
43
43
  },
44
44
  "devDependencies": {
45
45
  "typescript": "^5.3.0"
@@ -40,6 +40,10 @@ import {
40
40
  setStorageItems,
41
41
  setStorageJSON,
42
42
  setStorageNumber,
43
+ explainStorageBackend,
44
+ installStorageHostBackend,
45
+ observeStorageHostResult,
46
+ resetStorageBackendForTest,
43
47
  } from './storage';
44
48
 
45
49
  function fakeBackend(): StorageBackend {
@@ -207,6 +211,34 @@ describe('enableStorageSignals', () => {
207
211
  });
208
212
  });
209
213
 
214
+ describe('explainStorageBackend', () => {
215
+ afterEach(() => resetStorageBackendForTest());
216
+
217
+ it('reports host-not-enabled when no backend is installed', () => {
218
+ resetStorageBackendForTest();
219
+ const explanation = explainStorageBackend();
220
+ expect(explanation.layer).toBe('host-not-enabled');
221
+ expect(explanation.conflict).toBe(false);
222
+ expect(explanation.viability).toBe('unobserved');
223
+ });
224
+
225
+ it('reports custom layer when a custom backend is set', () => {
226
+ setStorageBackend(fakeBackend());
227
+ expect(explainStorageBackend().layer).toBe('custom');
228
+ });
229
+
230
+ it('reports host layer when a host backend is installed', () => {
231
+ installStorageHostBackend(fakeBackend());
232
+ expect(explainStorageBackend().layer).toBe('host');
233
+ });
234
+
235
+ it('reports conflict when two different host backends are installed', () => {
236
+ installStorageHostBackend(fakeBackend());
237
+ installStorageHostBackend(fakeBackend());
238
+ expect(explainStorageBackend().conflict).toBe(true);
239
+ });
240
+ });
241
+
210
242
  describe('getNamespacedStorageByteSize', () => {
211
243
  it('counts only namespaced keys', () => {
212
244
  setStorageBackend(fakeBackend());
@@ -565,6 +597,25 @@ describe('hasStorageItem', () => {
565
597
  });
566
598
  });
567
599
 
600
+ describe('installStorageHostBackend', () => {
601
+ afterEach(() => resetStorageBackendForTest());
602
+
603
+ it('installs a host backend that getStorageBackend returns', () => {
604
+ const backend = fakeBackend();
605
+ installStorageHostBackend(backend);
606
+ expect(getStorageBackend()).toBe(backend);
607
+ });
608
+
609
+ it('is first-host-wins: a second different backend sets conflict', () => {
610
+ const first = fakeBackend();
611
+ const second = fakeBackend();
612
+ installStorageHostBackend(first);
613
+ installStorageHostBackend(second);
614
+ expect(getStorageBackend()).toBe(first);
615
+ expect(explainStorageBackend().conflict).toBe(true);
616
+ });
617
+ });
618
+
568
619
  describe('migrateStorage', () => {
569
620
  it('runs migrations in version order', () => {
570
621
  setStorageBackend(fakeBackend());
@@ -649,6 +700,24 @@ describe('migrateStorage', () => {
649
700
  });
650
701
  });
651
702
 
703
+ describe('observeStorageHostResult', () => {
704
+ afterEach(() => resetStorageBackendForTest());
705
+
706
+ it('records a successful observation', () => {
707
+ installStorageHostBackend(fakeBackend());
708
+ observeStorageHostResult('getItem', true);
709
+ const explanation = explainStorageBackend();
710
+ expect(explanation.operation).toBe('getItem');
711
+ expect(explanation.viability).toBe('available');
712
+ });
713
+
714
+ it('records a failed observation', () => {
715
+ installStorageHostBackend(fakeBackend());
716
+ observeStorageHostResult('getItem', false);
717
+ expect(explainStorageBackend().viability).toBe('runtime-api-unavailable');
718
+ });
719
+ });
720
+
652
721
  describe('removeNamespacedStorageItem', () => {
653
722
  it('removes a namespaced key', () => {
654
723
  setStorageBackend(fakeBackend());
@@ -684,6 +753,18 @@ describe('removeStorageItems', () => {
684
753
  });
685
754
  });
686
755
 
756
+ describe('resetStorageBackendForTest', () => {
757
+ it('clears all backend slots', () => {
758
+ setStorageBackend(fakeBackend());
759
+ installStorageHostBackend(fakeBackend());
760
+ observeStorageHostResult('getItem', true);
761
+ resetStorageBackendForTest();
762
+ expect(explainStorageBackend().layer).toBe('host-not-enabled');
763
+ expect(explainStorageBackend().conflict).toBe(false);
764
+ expect(explainStorageBackend().viability).toBe('unobserved');
765
+ });
766
+ });
767
+
687
768
  describe('setNamespacedStorageItem', () => {
688
769
  it('stores under the prefixed key', () => {
689
770
  setStorageBackend(fakeBackend());