@expo/entity-cache-adapter-local-memory 0.31.1 → 0.32.0

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.
Files changed (33) hide show
  1. package/build/GenericLocalMemoryCacher.d.ts +6 -5
  2. package/build/GenericLocalMemoryCacher.js +14 -5
  3. package/build/GenericLocalMemoryCacher.js.map +1 -1
  4. package/build/LocalMemoryCacheAdapterProvider.d.ts +3 -4
  5. package/build/LocalMemoryCacheAdapterProvider.js +5 -6
  6. package/build/LocalMemoryCacheAdapterProvider.js.map +1 -1
  7. package/build/__tests__/{LocalMemoryCacheAdapter-full-test.js → GenericLocalMemoryCacher-full-test.js} +17 -18
  8. package/build/__tests__/GenericLocalMemoryCacher-full-test.js.map +1 -0
  9. package/build/__tests__/GenericLocalMemoryCacher-test.js +98 -3
  10. package/build/__tests__/GenericLocalMemoryCacher-test.js.map +1 -1
  11. package/build/index.d.ts +0 -1
  12. package/build/index.js +1 -3
  13. package/build/index.js.map +1 -1
  14. package/build/testfixtures/LocalMemoryTestEntity.d.ts +2 -2
  15. package/build/testfixtures/LocalMemoryTestEntity.js +6 -7
  16. package/build/testfixtures/LocalMemoryTestEntity.js.map +1 -1
  17. package/package.json +4 -4
  18. package/src/GenericLocalMemoryCacher.ts +24 -3
  19. package/src/LocalMemoryCacheAdapterProvider.ts +7 -5
  20. package/src/__tests__/{LocalMemoryCacheAdapter-full-test.ts → GenericLocalMemoryCacher-full-test.ts} +33 -32
  21. package/src/__tests__/GenericLocalMemoryCacher-test.ts +115 -1
  22. package/src/index.ts +0 -1
  23. package/src/testfixtures/LocalMemoryTestEntity.ts +6 -8
  24. package/build/LocalMemoryCacheAdapter.d.ts +0 -11
  25. package/build/LocalMemoryCacheAdapter.js +0 -45
  26. package/build/LocalMemoryCacheAdapter.js.map +0 -1
  27. package/build/__tests__/LocalMemoryCacheAdapter-full-test.js.map +0 -1
  28. package/build/__tests__/LocalMemoryCacheAdapter-test.d.ts +0 -1
  29. package/build/__tests__/LocalMemoryCacheAdapter-test.js +0 -104
  30. package/build/__tests__/LocalMemoryCacheAdapter-test.js.map +0 -1
  31. package/src/LocalMemoryCacheAdapter.ts +0 -80
  32. package/src/__tests__/LocalMemoryCacheAdapter-test.ts +0 -107
  33. /package/build/__tests__/{LocalMemoryCacheAdapter-full-test.d.ts → GenericLocalMemoryCacher-full-test.d.ts} +0 -0
@@ -1,107 +0,0 @@
1
- import { CacheStatus, UUIDField, EntityConfiguration } from '@expo/entity';
2
-
3
- import GenericLocalMemoryCacher, {
4
- DOES_NOT_EXIST_LOCAL_MEMORY_CACHE,
5
- } from '../GenericLocalMemoryCacher';
6
- import LocalMemoryCacheAdapter from '../LocalMemoryCacheAdapter';
7
-
8
- type BlahFields = {
9
- id: string;
10
- };
11
-
12
- const entityConfiguration = new EntityConfiguration<BlahFields>({
13
- idField: 'id',
14
- tableName: 'blah',
15
- schema: {
16
- id: new UUIDField({ columnName: 'id', cache: true }),
17
- },
18
- databaseAdapterFlavor: 'postgres',
19
- cacheAdapterFlavor: 'local-memory',
20
- });
21
-
22
- describe(LocalMemoryCacheAdapter, () => {
23
- describe('loadManyAsync', () => {
24
- it('returns appropriate cache results', async () => {
25
- const cacheAdapter = new LocalMemoryCacheAdapter(
26
- entityConfiguration,
27
- GenericLocalMemoryCacher.createLRUCache()
28
- );
29
-
30
- const cacheHits = new Map<string, Readonly<BlahFields>>([['test-id-1', { id: 'test-id-1' }]]);
31
- await cacheAdapter.cacheManyAsync('id', cacheHits);
32
- await cacheAdapter.cacheDBMissesAsync('id', ['test-id-2']);
33
-
34
- const results = await cacheAdapter.loadManyAsync('id', [
35
- 'test-id-1',
36
- 'test-id-2',
37
- 'test-id-3',
38
- ]);
39
-
40
- expect(results.get('test-id-1')).toMatchObject({
41
- status: CacheStatus.HIT,
42
- item: { id: 'test-id-1' },
43
- });
44
- expect(results.get('test-id-2')).toMatchObject({ status: CacheStatus.NEGATIVE });
45
- expect(results.get('test-id-3')).toMatchObject({ status: CacheStatus.MISS });
46
- expect(results.size).toBe(3);
47
- });
48
-
49
- it('returns empty map when passed empty array of fieldValues', async () => {
50
- const cacheAdapter = new LocalMemoryCacheAdapter(
51
- entityConfiguration,
52
- GenericLocalMemoryCacher.createLRUCache()
53
- );
54
- const results = await cacheAdapter.loadManyAsync('id', []);
55
- expect(results).toEqual(new Map());
56
- });
57
- });
58
-
59
- describe('cacheManyAsync', () => {
60
- it('correctly caches all objects', async () => {
61
- const localMemoryCache = GenericLocalMemoryCacher.createLRUCache<BlahFields>({});
62
-
63
- const cacheAdapter = new LocalMemoryCacheAdapter(entityConfiguration, localMemoryCache);
64
- await cacheAdapter.cacheManyAsync('id', new Map([['test-id-1', { id: 'test-id-1' }]]));
65
-
66
- const cacheKey = cacheAdapter['makeCacheKey']('id', 'test-id-1');
67
- expect(localMemoryCache.get(cacheKey)).toMatchObject({
68
- id: 'test-id-1',
69
- });
70
- });
71
- });
72
-
73
- describe('cacheDBMissesAsync', () => {
74
- it('correctly caches misses', async () => {
75
- const localMemoryCache = GenericLocalMemoryCacher.createLRUCache<BlahFields>({});
76
-
77
- const cacheAdapter = new LocalMemoryCacheAdapter(entityConfiguration, localMemoryCache);
78
- await cacheAdapter.cacheDBMissesAsync('id', ['test-id-1']);
79
-
80
- const cacheKey = cacheAdapter['makeCacheKey']('id', 'test-id-1');
81
- expect(localMemoryCache.get(cacheKey)).toEqual(DOES_NOT_EXIST_LOCAL_MEMORY_CACHE);
82
- });
83
- });
84
-
85
- describe('invalidateManyAsync', () => {
86
- it('invalidates correctly', async () => {
87
- const localMemoryCache = GenericLocalMemoryCacher.createLRUCache<BlahFields>({});
88
-
89
- const cacheAdapter = new LocalMemoryCacheAdapter(entityConfiguration, localMemoryCache);
90
- await cacheAdapter.cacheManyAsync('id', new Map([['test-id-1', { id: 'test-id-1' }]]));
91
- await cacheAdapter.cacheDBMissesAsync('id', ['test-id-2']);
92
- await cacheAdapter.invalidateManyAsync('id', ['test-id-1', 'test-id-2']);
93
-
94
- const results = await cacheAdapter.loadManyAsync('id', ['test-id-1', 'test-id-2']);
95
- expect(results.get('test-id-1')).toMatchObject({ status: CacheStatus.MISS });
96
- expect(results.get('test-id-2')).toMatchObject({ status: CacheStatus.MISS });
97
- });
98
-
99
- it('returns when passed empty array of fieldValues', async () => {
100
- const cacheAdapter = new LocalMemoryCacheAdapter(
101
- entityConfiguration,
102
- GenericLocalMemoryCacher.createLRUCache<BlahFields>({})
103
- );
104
- await cacheAdapter.invalidateManyAsync('id', []);
105
- });
106
- });
107
- });