@expo/entity-cache-adapter-local-memory 0.41.0 → 0.42.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 (25) hide show
  1. package/build/GenericLocalMemoryCacher.d.ts +9 -8
  2. package/build/GenericLocalMemoryCacher.js +10 -6
  3. package/build/GenericLocalMemoryCacher.js.map +1 -1
  4. package/build/LocalMemoryCacheAdapterProvider.d.ts +1 -1
  5. package/build/LocalMemoryCacheAdapterProvider.js.map +1 -1
  6. package/build/tsconfig.build.tsbuildinfo +1 -0
  7. package/package.json +8 -6
  8. package/src/GenericLocalMemoryCacher.ts +33 -16
  9. package/src/LocalMemoryCacheAdapterProvider.ts +12 -7
  10. package/src/{testfixtures → __testfixtures__}/LocalMemoryTestEntity.ts +30 -28
  11. package/src/{testfixtures → __testfixtures__}/createLocalMemoryTestEntityCompanionProvider.ts +1 -2
  12. package/src/__tests__/GenericLocalMemoryCacher-full-test.ts +62 -27
  13. package/src/__tests__/GenericLocalMemoryCacher-test.ts +73 -27
  14. package/build/__tests__/GenericLocalMemoryCacher-full-test.d.ts +0 -1
  15. package/build/__tests__/GenericLocalMemoryCacher-full-test.js +0 -94
  16. package/build/__tests__/GenericLocalMemoryCacher-full-test.js.map +0 -1
  17. package/build/__tests__/GenericLocalMemoryCacher-test.d.ts +0 -1
  18. package/build/__tests__/GenericLocalMemoryCacher-test.js +0 -136
  19. package/build/__tests__/GenericLocalMemoryCacher-test.js.map +0 -1
  20. package/build/testfixtures/LocalMemoryTestEntity.d.ts +0 -16
  21. package/build/testfixtures/LocalMemoryTestEntity.js +0 -49
  22. package/build/testfixtures/LocalMemoryTestEntity.js.map +0 -1
  23. package/build/testfixtures/createLocalMemoryTestEntityCompanionProvider.d.ts +0 -6
  24. package/build/testfixtures/createLocalMemoryTestEntityCompanionProvider.js +0 -36
  25. package/build/testfixtures/createLocalMemoryTestEntityCompanionProvider.js.map +0 -1
@@ -1,20 +1,21 @@
1
- import { CacheLoadResult, EntityConfiguration, IEntityGenericCacher } from '@expo/entity';
1
+ import { CacheLoadResult, EntityConfiguration, IEntityGenericCacher, IEntityLoadKey, IEntityLoadValue } from '@expo/entity';
2
2
  import LRUCache from 'lru-cache';
3
3
  export declare const DOES_NOT_EXIST_LOCAL_MEMORY_CACHE: unique symbol;
4
- export type LocalMemoryCacheValue<TFields> = Readonly<TFields> | typeof DOES_NOT_EXIST_LOCAL_MEMORY_CACHE;
5
- export type LocalMemoryCache<TFields> = LRUCache<string, LocalMemoryCacheValue<TFields>>;
6
- export default class GenericLocalMemoryCacher<TFields extends Record<string, any>> implements IEntityGenericCacher<TFields> {
4
+ export type LocalMemoryCacheValue<TFields extends Record<string, any>> = Readonly<TFields> | typeof DOES_NOT_EXIST_LOCAL_MEMORY_CACHE;
5
+ export type LocalMemoryCache<TFields extends Record<string, any>> = LRUCache<string, LocalMemoryCacheValue<TFields>>;
6
+ export default class GenericLocalMemoryCacher<TFields extends Record<string, any>, TIDField extends keyof TFields> implements IEntityGenericCacher<TFields, TIDField> {
7
7
  private readonly entityConfiguration;
8
8
  private readonly localMemoryCache;
9
- constructor(entityConfiguration: EntityConfiguration<TFields>, localMemoryCache: LocalMemoryCache<TFields>);
10
- static createLRUCache<TFields>(options?: {
9
+ constructor(entityConfiguration: EntityConfiguration<TFields, TIDField>, localMemoryCache: LocalMemoryCache<TFields>);
10
+ static createLRUCache<TFields extends Record<string, any>>(options?: {
11
11
  maxSize?: number;
12
12
  ttlSeconds?: number;
13
13
  }): LocalMemoryCache<TFields>;
14
- static createNoOpCache<TFields>(): LocalMemoryCache<TFields>;
14
+ static createNoOpCache<TFields extends Record<string, any>>(): LocalMemoryCache<TFields>;
15
15
  loadManyAsync(keys: readonly string[]): Promise<ReadonlyMap<string, CacheLoadResult<TFields>>>;
16
16
  cacheManyAsync(objectMap: ReadonlyMap<string, Readonly<TFields>>): Promise<void>;
17
17
  cacheDBMissesAsync(keys: readonly string[]): Promise<void>;
18
18
  invalidateManyAsync(keys: readonly string[]): Promise<void>;
19
- makeCacheKey<N extends keyof TFields>(fieldName: N, fieldValue: NonNullable<TFields[N]>): string;
19
+ makeCacheKeyForStorage<TLoadKey extends IEntityLoadKey<TFields, TIDField, TSerializedLoadValue, TLoadValue>, TSerializedLoadValue, TLoadValue extends IEntityLoadValue<TSerializedLoadValue>>(key: TLoadKey, value: TLoadValue): string;
20
+ makeCacheKeysForInvalidation<TLoadKey extends IEntityLoadKey<TFields, TIDField, TSerializedLoadValue, TLoadValue>, TSerializedLoadValue, TLoadValue extends IEntityLoadValue<TSerializedLoadValue>>(key: TLoadKey, value: TLoadValue): readonly string[];
20
21
  }
@@ -5,7 +5,6 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
5
5
  Object.defineProperty(exports, "__esModule", { value: true });
6
6
  exports.DOES_NOT_EXIST_LOCAL_MEMORY_CACHE = void 0;
7
7
  const entity_1 = require("@expo/entity");
8
- const invariant_1 = __importDefault(require("invariant"));
9
8
  const lru_cache_1 = __importDefault(require("lru-cache"));
10
9
  // Sentinel value we store in local memory to negatively cache a database miss.
11
10
  // The sentinel value is distinct from any (positively) cached value.
@@ -71,19 +70,24 @@ class GenericLocalMemoryCacher {
71
70
  this.localMemoryCache.del(key);
72
71
  }
73
72
  }
74
- makeCacheKey(fieldName, fieldValue) {
75
- const columnName = this.entityConfiguration.entityToDBFieldsKeyMapping.get(fieldName);
76
- (0, invariant_1.default)(columnName, `database field mapping missing for ${String(fieldName)}`);
73
+ makeCacheKeyForStorage(key, value) {
74
+ const cacheKeyType = key.getLoadMethodType();
75
+ const keyAndValueParts = key.createCacheKeyPartsForLoadValue(this.entityConfiguration, value);
77
76
  const parts = [
78
77
  this.entityConfiguration.tableName,
78
+ cacheKeyType,
79
79
  `${this.entityConfiguration.cacheKeyVersion}`,
80
- columnName,
81
- String(fieldValue),
80
+ ...keyAndValueParts,
82
81
  ];
83
82
  const delimiter = ':';
84
83
  const escapedParts = parts.map((part) => part.replace('\\', '\\\\').replace(delimiter, `\\${delimiter}`));
85
84
  return escapedParts.join(delimiter);
86
85
  }
86
+ makeCacheKeysForInvalidation(key, value) {
87
+ // for local memory caches, we don't need to invalidate old versions of the cache keys
88
+ // since they are not persisted across deploys
89
+ return [this.makeCacheKeyForStorage(key, value)];
90
+ }
87
91
  }
88
92
  exports.default = GenericLocalMemoryCacher;
89
93
  //# sourceMappingURL=GenericLocalMemoryCacher.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"GenericLocalMemoryCacher.js","sourceRoot":"","sources":["../src/GenericLocalMemoryCacher.ts"],"names":[],"mappings":";;;;;;AAAA,yCAKsB;AACtB,0DAAkC;AAClC,0DAAiC;AAEjC,+EAA+E;AAC/E,qEAAqE;AACxD,QAAA,iCAAiC,GAAG,MAAM,CAAC,cAAc,CAAC,CAAC;AAMxE,MAAqB,wBAAwB;IAIxB;IACA;IAFnB,YACmB,mBAAiD,EACjD,gBAA2C;QAD3C,wBAAmB,GAAnB,mBAAmB,CAA8B;QACjD,qBAAgB,GAAhB,gBAAgB,CAA2B;IAC3D,CAAC;IAEJ,MAAM,CAAC,cAAc,CACnB,UAAqD,EAAE;QAEvD,MAAM,iCAAiC,GAAG,EAAE,CAAC;QAC7C,MAAM,sBAAsB,GAAG,KAAK,CAAC;QACrC,MAAM,aAAa,GAAG,OAAO,CAAC,UAAU,IAAI,iCAAiC,CAAC;QAC9E,OAAO,IAAI,mBAAQ,CAAyC;YAC1D,GAAG,EAAE,OAAO,CAAC,OAAO,IAAI,sBAAsB;YAC9C,MAAM,EAAE,CAAC,KAAK,EAAE,EAAE,CAAC,CAAC,KAAK,KAAK,yCAAiC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC;YACxE,MAAM,EAAE,aAAa,GAAG,IAAI,EAAE,gBAAgB;SAC/C,CAAC,CAAC;IACL,CAAC;IAED,MAAM,CAAC,eAAe;QACpB,OAAO,IAAI,mBAAQ,CAAyC;YAC1D,GAAG,EAAE,CAAC;Y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AC,IAAI,CAAC,SAAS,CAAC,CAAC;IACtC,CAAC;IAEM,4BAA4B,CAIjC,GAAa,EAAE,KAAiB;QAChC,sFAAsF;QACtF,8CAA8C;QAC9C,OAAO,CAAC,IAAI,CAAC,sBAAsB,CAAC,GAAG,EAAE,KAAK,CAAC,CAAC,CAAC;IACnD,CAAC;CACF;AAtGD,2CAsGC"}
@@ -18,5 +18,5 @@ export default class LocalMemoryCacheAdapterProvider implements IEntityCacheAdap
18
18
  }): IEntityCacheAdapterProvider;
19
19
  private readonly localMemoryCacheAdapterMap;
20
20
  private constructor();
21
- getCacheAdapter<TFields extends Record<string, any>>(entityConfiguration: EntityConfiguration<TFields>): IEntityCacheAdapter<TFields>;
21
+ getCacheAdapter<TFields extends Record<string, any>, TIDField extends keyof TFields>(entityConfiguration: EntityConfiguration<TFields, TIDField>): IEntityCacheAdapter<TFields, TIDField>;
22
22
  }
@@ -1 +1 @@
1
- {"version":3,"file":"LocalMemoryCacheAdapterProvider.js","sourceRoot":"","sources":["../src/LocalMemoryCacheAdapterProvider.ts"],"names":[],"mappings":";;;;;AAAA,yCAMsB;AAEtB,0FAAwF;AAExF;;;GAGG;AACH,MAAqB,+BAA+B;IAwB/B;IAvBnB;;OAEG;IACH,MAAM,CAAC,kBAAkB;QACvB,OAAO,IAAI,+BAA+B,CAAC,GAAY,EAAE,CACvD,kCAAwB,CAAC,eAAe,EAAW,CACpD,CAAC;IACJ,CAAC;IAED;;OAEG;IACH,MAAM,CAAC,yBAAyB,CAC9B,UAAqD,EAAE;QAEvD,OAAO,IAAI,+BAA+B,CAAC,GAAY,EAAE,CACvD,kCAAwB,CAAC,cAAc,CAAU,OAAO,CAAC,CAC1D,CAAC;IACJ,CAAC;IAEgB,0BAA0B,GAAG,IAAI,GAAG,EAA0C,CAAC;IAEhG,YACmB,uBAAiE;QAAjE,4BAAuB,GAAvB,uBAAuB,CAA0C;IACjF,CAAC;IAEG,eAAe,CACpB,mBAAiD;QAEjD,OAAO,IAAA,wB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
@@ -0,0 +1 @@
1
+ {"root":["../src/genericlocalmemorycacher.ts","../src/localmemorycacheadapterprovider.ts","../src/index.ts"],"version":"5.8.3"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@expo/entity-cache-adapter-local-memory",
3
- "version": "0.41.0",
3
+ "version": "0.42.0",
4
4
  "description": "Cross-request local memory cache adapter for @expo/entity",
5
5
  "files": [
6
6
  "build",
@@ -10,6 +10,7 @@
10
10
  "types": "build/index.d.ts",
11
11
  "scripts": {
12
12
  "tsc": "tsc",
13
+ "build": "tsc -b tsconfig.build.json",
13
14
  "clean": "rm -rf build coverage coverage-integration",
14
15
  "lint": "eslint src",
15
16
  "lint-fix": "eslint src --fix",
@@ -27,11 +28,12 @@
27
28
  "author": "Expo",
28
29
  "license": "MIT",
29
30
  "dependencies": {
30
- "@expo/entity": "^0.41.0",
31
+ "@expo/entity": "^0.42.0",
31
32
  "lru-cache": "^6.0.0"
32
33
  },
33
34
  "devDependencies": {
34
- "@types/jest": "^29.5.12",
35
+ "@expo/entity-testing-utils": "^0.42.0",
36
+ "@types/jest": "^29.5.14",
35
37
  "@types/lru-cache": "^5.1.1",
36
38
  "@types/node": "^20.14.1",
37
39
  "ctix": "^2.7.0",
@@ -41,9 +43,9 @@
41
43
  "jest": "^29.7.0",
42
44
  "prettier": "^3.3.3",
43
45
  "prettier-plugin-organize-imports": "^4.1.0",
44
- "ts-jest": "^29.2.5",
46
+ "ts-jest": "^29.3.1",
45
47
  "ts-mockito": "^2.6.1",
46
- "typescript": "^5.7.3"
48
+ "typescript": "^5.8.3"
47
49
  },
48
- "gitHead": "ee4be736a9a0ba580e9af0194e07c9cd36b1c599"
50
+ "gitHead": "8414d96d948882735687da146e84913397cd8368"
49
51
  }
@@ -3,27 +3,33 @@ import {
3
3
  CacheStatus,
4
4
  EntityConfiguration,
5
5
  IEntityGenericCacher,
6
+ IEntityLoadKey,
7
+ IEntityLoadValue,
6
8
  } from '@expo/entity';
7
- import invariant from 'invariant';
8
9
  import LRUCache from 'lru-cache';
9
10
 
10
11
  // Sentinel value we store in local memory to negatively cache a database miss.
11
12
  // The sentinel value is distinct from any (positively) cached value.
12
13
  export const DOES_NOT_EXIST_LOCAL_MEMORY_CACHE = Symbol('doesNotExist');
13
- export type LocalMemoryCacheValue<TFields> =
14
+ export type LocalMemoryCacheValue<TFields extends Record<string, any>> =
14
15
  | Readonly<TFields>
15
16
  | typeof DOES_NOT_EXIST_LOCAL_MEMORY_CACHE;
16
- export type LocalMemoryCache<TFields> = LRUCache<string, LocalMemoryCacheValue<TFields>>;
17
+ export type LocalMemoryCache<TFields extends Record<string, any>> = LRUCache<
18
+ string,
19
+ LocalMemoryCacheValue<TFields>
20
+ >;
17
21
 
18
- export default class GenericLocalMemoryCacher<TFields extends Record<string, any>>
19
- implements IEntityGenericCacher<TFields>
22
+ export default class GenericLocalMemoryCacher<
23
+ TFields extends Record<string, any>,
24
+ TIDField extends keyof TFields,
25
+ > implements IEntityGenericCacher<TFields, TIDField>
20
26
  {
21
27
  constructor(
22
- private readonly entityConfiguration: EntityConfiguration<TFields>,
28
+ private readonly entityConfiguration: EntityConfiguration<TFields, TIDField>,
23
29
  private readonly localMemoryCache: LocalMemoryCache<TFields>,
24
30
  ) {}
25
31
 
26
- static createLRUCache<TFields>(
32
+ static createLRUCache<TFields extends Record<string, any>>(
27
33
  options: { maxSize?: number; ttlSeconds?: number } = {},
28
34
  ): LocalMemoryCache<TFields> {
29
35
  const DEFAULT_LRU_CACHE_MAX_AGE_SECONDS = 10;
@@ -36,7 +42,7 @@ export default class GenericLocalMemoryCacher<TFields extends Record<string, any
36
42
  });
37
43
  }
38
44
 
39
- static createNoOpCache<TFields>(): LocalMemoryCache<TFields> {
45
+ static createNoOpCache<TFields extends Record<string, any>>(): LocalMemoryCache<TFields> {
40
46
  return new LRUCache<string, LocalMemoryCacheValue<TFields>>({
41
47
  max: 0,
42
48
  maxAge: -1,
@@ -85,17 +91,18 @@ export default class GenericLocalMemoryCacher<TFields extends Record<string, any
85
91
  }
86
92
  }
87
93
 
88
- public makeCacheKey<N extends keyof TFields>(
89
- fieldName: N,
90
- fieldValue: NonNullable<TFields[N]>,
91
- ): string {
92
- const columnName = this.entityConfiguration.entityToDBFieldsKeyMapping.get(fieldName);
93
- invariant(columnName, `database field mapping missing for ${String(fieldName)}`);
94
+ public makeCacheKeyForStorage<
95
+ TLoadKey extends IEntityLoadKey<TFields, TIDField, TSerializedLoadValue, TLoadValue>,
96
+ TSerializedLoadValue,
97
+ TLoadValue extends IEntityLoadValue<TSerializedLoadValue>,
98
+ >(key: TLoadKey, value: TLoadValue): string {
99
+ const cacheKeyType = key.getLoadMethodType();
100
+ const keyAndValueParts = key.createCacheKeyPartsForLoadValue(this.entityConfiguration, value);
94
101
  const parts = [
95
102
  this.entityConfiguration.tableName,
103
+ cacheKeyType,
96
104
  `${this.entityConfiguration.cacheKeyVersion}`,
97
- columnName,
98
- String(fieldValue),
105
+ ...keyAndValueParts,
99
106
  ];
100
107
 
101
108
  const delimiter = ':';
@@ -104,4 +111,14 @@ export default class GenericLocalMemoryCacher<TFields extends Record<string, any
104
111
  );
105
112
  return escapedParts.join(delimiter);
106
113
  }
114
+
115
+ public makeCacheKeysForInvalidation<
116
+ TLoadKey extends IEntityLoadKey<TFields, TIDField, TSerializedLoadValue, TLoadValue>,
117
+ TSerializedLoadValue,
118
+ TLoadValue extends IEntityLoadValue<TSerializedLoadValue>,
119
+ >(key: TLoadKey, value: TLoadValue): readonly string[] {
120
+ // for local memory caches, we don't need to invalidate old versions of the cache keys
121
+ // since they are not persisted across deploys
122
+ return [this.makeCacheKeyForStorage(key, value)];
123
+ }
107
124
  }
@@ -17,7 +17,7 @@ export default class LocalMemoryCacheAdapterProvider implements IEntityCacheAdap
17
17
  * @returns a no-op local memory cache adapter provider, or one that doesn't cache locally.
18
18
  */
19
19
  static createNoOpProvider(): IEntityCacheAdapterProvider {
20
- return new LocalMemoryCacheAdapterProvider(<TFields>() =>
20
+ return new LocalMemoryCacheAdapterProvider(<TFields extends Record<string, any>>() =>
21
21
  GenericLocalMemoryCacher.createNoOpCache<TFields>(),
22
22
  );
23
23
  }
@@ -28,20 +28,25 @@ export default class LocalMemoryCacheAdapterProvider implements IEntityCacheAdap
28
28
  static createProviderWithOptions(
29
29
  options: { maxSize?: number; ttlSeconds?: number } = {},
30
30
  ): IEntityCacheAdapterProvider {
31
- return new LocalMemoryCacheAdapterProvider(<TFields>() =>
31
+ return new LocalMemoryCacheAdapterProvider(<TFields extends Record<string, any>>() =>
32
32
  GenericLocalMemoryCacher.createLRUCache<TFields>(options),
33
33
  );
34
34
  }
35
35
 
36
- private readonly localMemoryCacheAdapterMap = new Map<string, GenericEntityCacheAdapter<any>>();
36
+ private readonly localMemoryCacheAdapterMap = new Map<
37
+ string,
38
+ GenericEntityCacheAdapter<any, any>
39
+ >();
37
40
 
38
41
  private constructor(
39
- private readonly localMemoryCacheCreator: <TFields>() => LocalMemoryCache<TFields>,
42
+ private readonly localMemoryCacheCreator: <
43
+ TFields extends Record<string, any>,
44
+ >() => LocalMemoryCache<TFields>,
40
45
  ) {}
41
46
 
42
- public getCacheAdapter<TFields extends Record<string, any>>(
43
- entityConfiguration: EntityConfiguration<TFields>,
44
- ): IEntityCacheAdapter<TFields> {
47
+ public getCacheAdapter<TFields extends Record<string, any>, TIDField extends keyof TFields>(
48
+ entityConfiguration: EntityConfiguration<TFields, TIDField>,
49
+ ): IEntityCacheAdapter<TFields, TIDField> {
45
50
  return computeIfAbsent(this.localMemoryCacheAdapterMap, entityConfiguration.tableName, () => {
46
51
  const localMemoryCache = this.localMemoryCacheCreator<TFields>();
47
52
  return new GenericEntityCacheAdapter(
@@ -2,12 +2,12 @@ import {
2
2
  AlwaysAllowPrivacyPolicyRule,
3
3
  EntityPrivacyPolicy,
4
4
  ViewerContext,
5
- UUIDField,
6
5
  DateField,
7
6
  StringField,
8
7
  EntityConfiguration,
9
8
  EntityCompanionDefinition,
10
9
  Entity,
10
+ UUIDField,
11
11
  } from '@expo/entity';
12
12
 
13
13
  export type LocalMemoryTestEntityFields = {
@@ -18,12 +18,12 @@ export type LocalMemoryTestEntityFields = {
18
18
 
19
19
  export default class LocalMemoryTestEntity extends Entity<
20
20
  LocalMemoryTestEntityFields,
21
- string,
21
+ 'id',
22
22
  ViewerContext
23
23
  > {
24
24
  static defineCompanionDefinition(): EntityCompanionDefinition<
25
25
  LocalMemoryTestEntityFields,
26
- string,
26
+ 'id',
27
27
  ViewerContext,
28
28
  LocalMemoryTestEntity,
29
29
  LocalMemoryTestEntityPrivacyPolicy
@@ -38,14 +38,14 @@ export default class LocalMemoryTestEntity extends Entity<
38
38
 
39
39
  export class LocalMemoryTestEntityPrivacyPolicy extends EntityPrivacyPolicy<
40
40
  LocalMemoryTestEntityFields,
41
- string,
41
+ 'id',
42
42
  ViewerContext,
43
43
  LocalMemoryTestEntity
44
44
  > {
45
45
  protected override readonly createRules = [
46
46
  new AlwaysAllowPrivacyPolicyRule<
47
47
  LocalMemoryTestEntityFields,
48
- string,
48
+ 'id',
49
49
  ViewerContext,
50
50
  LocalMemoryTestEntity
51
51
  >(),
@@ -53,7 +53,7 @@ export class LocalMemoryTestEntityPrivacyPolicy extends EntityPrivacyPolicy<
53
53
  protected override readonly readRules = [
54
54
  new AlwaysAllowPrivacyPolicyRule<
55
55
  LocalMemoryTestEntityFields,
56
- string,
56
+ 'id',
57
57
  ViewerContext,
58
58
  LocalMemoryTestEntity
59
59
  >(),
@@ -61,7 +61,7 @@ export class LocalMemoryTestEntityPrivacyPolicy extends EntityPrivacyPolicy<
61
61
  protected override readonly updateRules = [
62
62
  new AlwaysAllowPrivacyPolicyRule<
63
63
  LocalMemoryTestEntityFields,
64
- string,
64
+ 'id',
65
65
  ViewerContext,
66
66
  LocalMemoryTestEntity
67
67
  >(),
@@ -69,30 +69,32 @@ export class LocalMemoryTestEntityPrivacyPolicy extends EntityPrivacyPolicy<
69
69
  protected override readonly deleteRules = [
70
70
  new AlwaysAllowPrivacyPolicyRule<
71
71
  LocalMemoryTestEntityFields,
72
- string,
72
+ 'id',
73
73
  ViewerContext,
74
74
  LocalMemoryTestEntity
75
75
  >(),
76
76
  ];
77
77
  }
78
78
 
79
- export const localMemoryTestEntityConfiguration =
80
- new EntityConfiguration<LocalMemoryTestEntityFields>({
81
- idField: 'id',
82
- tableName: 'local_memory_test_entities',
83
- schema: {
84
- id: new UUIDField({
85
- columnName: 'id',
86
- cache: true,
87
- }),
88
- name: new StringField({
89
- columnName: 'name',
90
- cache: true,
91
- }),
92
- dateField: new DateField({
93
- columnName: 'date_field',
94
- }),
95
- },
96
- databaseAdapterFlavor: 'postgres',
97
- cacheAdapterFlavor: 'local-memory',
98
- });
79
+ export const localMemoryTestEntityConfiguration = new EntityConfiguration<
80
+ LocalMemoryTestEntityFields,
81
+ 'id'
82
+ >({
83
+ idField: 'id',
84
+ tableName: 'local_memory_test_entities',
85
+ schema: {
86
+ id: new UUIDField({
87
+ columnName: 'id',
88
+ cache: true,
89
+ }),
90
+ name: new StringField({
91
+ columnName: 'name',
92
+ cache: true,
93
+ }),
94
+ dateField: new DateField({
95
+ columnName: 'date_field',
96
+ }),
97
+ },
98
+ databaseAdapterFlavor: 'postgres',
99
+ cacheAdapterFlavor: 'local-memory',
100
+ });
@@ -2,9 +2,8 @@ import {
2
2
  NoOpEntityMetricsAdapter,
3
3
  IEntityMetricsAdapter,
4
4
  EntityCompanionProvider,
5
- StubQueryContextProvider,
6
- StubDatabaseAdapterProvider,
7
5
  } from '@expo/entity';
6
+ import { StubDatabaseAdapterProvider, StubQueryContextProvider } from '@expo/entity-testing-utils';
8
7
 
9
8
  import LocalMemoryCacheAdapterProvider from '../LocalMemoryCacheAdapterProvider';
10
9
 
@@ -2,27 +2,33 @@ import {
2
2
  CacheAdapterFlavor,
3
3
  CacheAdapterFlavorDefinition,
4
4
  CacheStatus,
5
+ IEntityGenericCacher,
6
+ SingleFieldHolder,
7
+ SingleFieldValueHolder,
5
8
  ViewerContext,
6
9
  } from '@expo/entity';
7
10
  import { v4 as uuidv4 } from 'uuid';
8
11
 
9
12
  import GenericLocalMemoryCacher from '../GenericLocalMemoryCacher';
10
13
  import LocalMemoryCacheAdapterProvider from '../LocalMemoryCacheAdapterProvider';
11
- import LocalMemoryTestEntity from '../testfixtures/LocalMemoryTestEntity';
14
+ import LocalMemoryTestEntity, {
15
+ LocalMemoryTestEntityFields,
16
+ } from '../__testfixtures__/LocalMemoryTestEntity';
12
17
  import {
13
18
  createLocalMemoryTestEntityCompanionProvider,
14
19
  createNoOpLocalMemoryIntegrationTestEntityCompanionProvider,
15
- } from '../testfixtures/createLocalMemoryTestEntityCompanionProvider';
20
+ } from '../__testfixtures__/createLocalMemoryTestEntityCompanionProvider';
16
21
 
17
22
  describe(GenericLocalMemoryCacher, () => {
18
23
  it('has correct caching behavior', async () => {
19
24
  const entityCompanionProvider = createLocalMemoryTestEntityCompanionProvider();
20
25
  const viewerContext = new ViewerContext(entityCompanionProvider);
21
- const genericCacher =
22
- viewerContext.entityCompanionProvider.getCompanionForEntity(LocalMemoryTestEntity)[
23
- 'tableDataCoordinator'
24
- ]['cacheAdapter']['genericCacher'];
25
- const cacheKeyMaker = genericCacher['makeCacheKey'].bind(genericCacher);
26
+ const genericCacher = viewerContext.entityCompanionProvider.getCompanionForEntity(
27
+ LocalMemoryTestEntity,
28
+ )['tableDataCoordinator']['cacheAdapter']['genericCacher'] as IEntityGenericCacher<
29
+ LocalMemoryTestEntityFields,
30
+ 'id'
31
+ >;
26
32
 
27
33
  const date = new Date();
28
34
  const entity1Created = await LocalMemoryTestEntity.creator(viewerContext)
@@ -46,11 +52,19 @@ describe(GenericLocalMemoryCacher, () => {
46
52
  ].get(
47
53
  viewerContext.entityCompanionProvider.getCompanionForEntity(LocalMemoryTestEntity)
48
54
  .entityCompanionDefinition.entityConfiguration.tableName,
49
- )!['genericCacher'];
55
+ )!['genericCacher'] as IEntityGenericCacher<LocalMemoryTestEntityFields, 'id'>;
50
56
  const cachedResult = await entitySpecificGenericCacher.loadManyAsync([
51
- cacheKeyMaker('id', entity1.getID()),
57
+ genericCacher.makeCacheKeyForStorage(
58
+ new SingleFieldHolder('id'),
59
+ new SingleFieldValueHolder(entity1.getID()),
60
+ ),
52
61
  ]);
53
- const cachedValue = cachedResult.get(cacheKeyMaker('id', entity1.getID()))!;
62
+ const cachedValue = cachedResult.get(
63
+ genericCacher.makeCacheKeyForStorage(
64
+ new SingleFieldHolder('id'),
65
+ new SingleFieldValueHolder(entity1.getID()),
66
+ ),
67
+ )!;
54
68
  expect(cachedValue).toMatchObject({
55
69
  status: CacheStatus.HIT,
56
70
  item: {
@@ -70,9 +84,19 @@ describe(GenericLocalMemoryCacher, () => {
70
84
  expect(entityNonExistentResult.ok).toBe(false);
71
85
 
72
86
  const nonExistentCachedResult = await entitySpecificGenericCacher.loadManyAsync([
73
- cacheKeyMaker('id', nonExistentId),
87
+ genericCacher.makeCacheKeyForStorage(
88
+ new SingleFieldHolder('id'),
89
+ new SingleFieldValueHolder(nonExistentId),
90
+ ),
74
91
  ]);
75
- expect(nonExistentCachedResult.get(cacheKeyMaker('id', nonExistentId))).toMatchObject({
92
+ expect(
93
+ nonExistentCachedResult.get(
94
+ genericCacher.makeCacheKeyForStorage(
95
+ new SingleFieldHolder('id'),
96
+ new SingleFieldValueHolder(nonExistentId),
97
+ ),
98
+ ),
99
+ ).toMatchObject({
76
100
  status: CacheStatus.NEGATIVE,
77
101
  });
78
102
 
@@ -87,21 +111,26 @@ describe(GenericLocalMemoryCacher, () => {
87
111
  await LocalMemoryTestEntity.loaderUtils(viewerContext).invalidateFieldsAsync(
88
112
  entity1.getAllFields(),
89
113
  );
90
- const cachedResultMiss = await entitySpecificGenericCacher.loadManyAsync([
91
- cacheKeyMaker('id', entity1.getID()),
92
- ]);
93
- const cachedValueMiss = cachedResultMiss.get(cacheKeyMaker('id', entity1.getID()));
94
- expect(cachedValueMiss).toMatchObject({ status: CacheStatus.MISS });
114
+ const keys = genericCacher.makeCacheKeysForInvalidation(
115
+ new SingleFieldHolder('id'),
116
+ new SingleFieldValueHolder(entity1.getID()),
117
+ );
118
+ const cachedResultMiss = await entitySpecificGenericCacher.loadManyAsync(keys);
119
+ expect(Array.from(cachedResultMiss.values()).every((v) => v.status === CacheStatus.MISS)).toBe(
120
+ true,
121
+ );
95
122
  });
96
123
 
97
124
  it('respects the parameters of a noop cache', async () => {
98
125
  const entityCompanionProvider = createNoOpLocalMemoryIntegrationTestEntityCompanionProvider();
99
126
  const viewerContext = new ViewerContext(entityCompanionProvider);
100
- const genericCacher =
101
- viewerContext.entityCompanionProvider.getCompanionForEntity(LocalMemoryTestEntity)[
102
- 'tableDataCoordinator'
103
- ]['cacheAdapter']['genericCacher'];
104
- const cacheKeyMaker = genericCacher['makeCacheKey'].bind(genericCacher);
127
+ const genericCacher = viewerContext.entityCompanionProvider.getCompanionForEntity(
128
+ LocalMemoryTestEntity,
129
+ )['tableDataCoordinator']['cacheAdapter']['genericCacher'] as IEntityGenericCacher<
130
+ LocalMemoryTestEntityFields,
131
+ 'id'
132
+ >;
133
+ const cacheKeyMaker = genericCacher['makeCacheKeyForStorage'].bind(genericCacher);
105
134
 
106
135
  const date = new Date();
107
136
  const entity1Created = await LocalMemoryTestEntity.creator(viewerContext)
@@ -125,11 +154,13 @@ describe(GenericLocalMemoryCacher, () => {
125
154
  ].get(
126
155
  viewerContext.entityCompanionProvider.getCompanionForEntity(LocalMemoryTestEntity)
127
156
  .entityCompanionDefinition.entityConfiguration.tableName,
128
- )!['genericCacher'];
157
+ )!['genericCacher'] as IEntityGenericCacher<LocalMemoryTestEntityFields, 'id'>;
129
158
  const cachedResult = await entitySpecificGenericCacher.loadManyAsync([
130
- cacheKeyMaker('id', entity1.getID()),
159
+ cacheKeyMaker(new SingleFieldHolder('id'), new SingleFieldValueHolder(entity1.getID())),
131
160
  ]);
132
- const cachedValue = cachedResult.get(cacheKeyMaker('id', entity1.getID()))!;
161
+ const cachedValue = cachedResult.get(
162
+ cacheKeyMaker(new SingleFieldHolder('id'), new SingleFieldValueHolder(entity1.getID())),
163
+ )!;
133
164
  expect(cachedValue).toMatchObject({
134
165
  status: CacheStatus.MISS,
135
166
  });
@@ -144,9 +175,13 @@ describe(GenericLocalMemoryCacher, () => {
144
175
  expect(entityNonExistentResult.ok).toBe(false);
145
176
 
146
177
  const nonExistentCachedResult = await entitySpecificGenericCacher.loadManyAsync([
147
- cacheKeyMaker('id', nonExistentId),
178
+ cacheKeyMaker(new SingleFieldHolder('id'), new SingleFieldValueHolder(nonExistentId)),
148
179
  ]);
149
- expect(nonExistentCachedResult.get(cacheKeyMaker('id', nonExistentId))).toMatchObject({
180
+ expect(
181
+ nonExistentCachedResult.get(
182
+ cacheKeyMaker(new SingleFieldHolder('id'), new SingleFieldValueHolder(nonExistentId)),
183
+ ),
184
+ ).toMatchObject({
150
185
  status: CacheStatus.MISS,
151
186
  });
152
187
  });
@@ -1,8 +1,11 @@
1
1
  import {
2
2
  CacheStatus,
3
- UUIDField,
4
3
  EntityConfiguration,
5
4
  GenericEntityCacheAdapter,
5
+ SingleFieldHolder,
6
+ SingleFieldValueHolder,
7
+ SingleFieldValueHolderMap,
8
+ UUIDField,
6
9
  } from '@expo/entity';
7
10
 
8
11
  import GenericLocalMemoryCacher, {
@@ -13,7 +16,7 @@ type BlahFields = {
13
16
  id: string;
14
17
  };
15
18
 
16
- const entityConfiguration = new EntityConfiguration<BlahFields>({
19
+ const entityConfiguration = new EntityConfiguration<BlahFields, 'id'>({
17
20
  idField: 'id',
18
21
  tableName: 'blah',
19
22
  schema: {
@@ -60,34 +63,48 @@ describe('Use within GenericEntityCacheAdapter', () => {
60
63
  ),
61
64
  );
62
65
 
63
- const cacheHits = new Map<string, Readonly<BlahFields>>([['test-id-1', { id: 'test-id-1' }]]);
64
- await cacheAdapter.cacheManyAsync('id', cacheHits);
65
- await cacheAdapter.cacheDBMissesAsync('id', ['test-id-2']);
66
+ const cacheHits = new Map<SingleFieldValueHolder<BlahFields, 'id'>, Readonly<BlahFields>>([
67
+ [new SingleFieldValueHolder('test-id-1'), { id: 'test-id-1' }],
68
+ ]);
69
+ await cacheAdapter.cacheManyAsync(
70
+ new SingleFieldHolder<BlahFields, 'id', 'id'>('id'),
71
+ cacheHits,
72
+ );
73
+ await cacheAdapter.cacheDBMissesAsync(new SingleFieldHolder('id'), [
74
+ new SingleFieldValueHolder('test-id-2'),
75
+ ]);
66
76
 
67
- const results = await cacheAdapter.loadManyAsync('id', [
68
- 'test-id-1',
69
- 'test-id-2',
70
- 'test-id-3',
77
+ const results = await cacheAdapter.loadManyAsync(new SingleFieldHolder('id'), [
78
+ new SingleFieldValueHolder('test-id-1'),
79
+ new SingleFieldValueHolder('test-id-2'),
80
+ new SingleFieldValueHolder('test-id-3'),
71
81
  ]);
72
82
 
73
- expect(results.get('test-id-1')).toMatchObject({
83
+ expect(results.get(new SingleFieldValueHolder('test-id-1'))).toMatchObject({
74
84
  status: CacheStatus.HIT,
75
85
  item: { id: 'test-id-1' },
76
86
  });
77
- expect(results.get('test-id-2')).toMatchObject({ status: CacheStatus.NEGATIVE });
78
- expect(results.get('test-id-3')).toMatchObject({ status: CacheStatus.MISS });
87
+ expect(results.get(new SingleFieldValueHolder('test-id-2'))).toMatchObject({
88
+ status: CacheStatus.NEGATIVE,
89
+ });
90
+ expect(results.get(new SingleFieldValueHolder('test-id-3'))).toMatchObject({
91
+ status: CacheStatus.MISS,
92
+ });
79
93
  expect(results.size).toBe(3);
80
94
  });
81
95
 
82
- it('returns empty map when passed empty array of fieldValues', async () => {
96
+ it('returns empty map when passed empty array of values', async () => {
83
97
  const cacheAdapter = new GenericEntityCacheAdapter(
84
98
  new GenericLocalMemoryCacher(
85
99
  entityConfiguration,
86
100
  GenericLocalMemoryCacher.createLRUCache(),
87
101
  ),
88
102
  );
89
- const results = await cacheAdapter.loadManyAsync('id', []);
90
- expect(results).toEqual(new Map());
103
+ const results = await cacheAdapter.loadManyAsync(
104
+ new SingleFieldHolder<BlahFields, 'id', 'id'>('id'),
105
+ [] as SingleFieldValueHolder<BlahFields, 'id'>[],
106
+ );
107
+ expect(results).toEqual(new SingleFieldValueHolderMap(new Map()));
91
108
  });
92
109
  });
93
110
 
@@ -97,9 +114,15 @@ describe('Use within GenericEntityCacheAdapter', () => {
97
114
 
98
115
  const localMemoryCacher = new GenericLocalMemoryCacher(entityConfiguration, localMemoryCache);
99
116
  const cacheAdapter = new GenericEntityCacheAdapter(localMemoryCacher);
100
- await cacheAdapter.cacheManyAsync('id', new Map([['test-id-1', { id: 'test-id-1' }]]));
117
+ await cacheAdapter.cacheManyAsync(
118
+ new SingleFieldHolder('id'),
119
+ new Map([[new SingleFieldValueHolder('test-id-1'), { id: 'test-id-1' }]]),
120
+ );
101
121
 
102
- const cacheKey = localMemoryCacher['makeCacheKey']('id', 'test-id-1');
122
+ const cacheKey = localMemoryCacher['makeCacheKeyForStorage'](
123
+ new SingleFieldHolder('id'),
124
+ new SingleFieldValueHolder('test-id-1'),
125
+ );
103
126
  expect(localMemoryCache.get(cacheKey)).toMatchObject({
104
127
  id: 'test-id-1',
105
128
  });
@@ -112,9 +135,14 @@ describe('Use within GenericEntityCacheAdapter', () => {
112
135
 
113
136
  const localMemoryCacher = new GenericLocalMemoryCacher(entityConfiguration, localMemoryCache);
114
137
  const cacheAdapter = new GenericEntityCacheAdapter(localMemoryCacher);
115
- await cacheAdapter.cacheDBMissesAsync('id', ['test-id-1']);
138
+ await cacheAdapter.cacheDBMissesAsync(new SingleFieldHolder('id'), [
139
+ new SingleFieldValueHolder('test-id-1'),
140
+ ]);
116
141
 
117
- const cacheKey = localMemoryCacher['makeCacheKey']('id', 'test-id-1');
142
+ const cacheKey = localMemoryCacher['makeCacheKeyForStorage'](
143
+ new SingleFieldHolder('id'),
144
+ new SingleFieldValueHolder('test-id-1'),
145
+ );
118
146
  expect(localMemoryCache.get(cacheKey)).toEqual(DOES_NOT_EXIST_LOCAL_MEMORY_CACHE);
119
147
  });
120
148
  });
@@ -126,23 +154,41 @@ describe('Use within GenericEntityCacheAdapter', () => {
126
154
  const cacheAdapter = new GenericEntityCacheAdapter(
127
155
  new GenericLocalMemoryCacher(entityConfiguration, localMemoryCache),
128
156
  );
129
- await cacheAdapter.cacheManyAsync('id', new Map([['test-id-1', { id: 'test-id-1' }]]));
130
- await cacheAdapter.cacheDBMissesAsync('id', ['test-id-2']);
131
- await cacheAdapter.invalidateManyAsync('id', ['test-id-1', 'test-id-2']);
157
+ await cacheAdapter.cacheManyAsync(
158
+ new SingleFieldHolder('id'),
159
+ new Map([[new SingleFieldValueHolder('test-id-1'), { id: 'test-id-1' }]]),
160
+ );
161
+ await cacheAdapter.cacheDBMissesAsync(new SingleFieldHolder('id'), [
162
+ new SingleFieldValueHolder('test-id-2'),
163
+ ]);
164
+ await cacheAdapter.invalidateManyAsync(new SingleFieldHolder('id'), [
165
+ new SingleFieldValueHolder('test-id-1'),
166
+ new SingleFieldValueHolder('test-id-2'),
167
+ ]);
132
168
 
133
- const results = await cacheAdapter.loadManyAsync('id', ['test-id-1', 'test-id-2']);
134
- expect(results.get('test-id-1')).toMatchObject({ status: CacheStatus.MISS });
135
- expect(results.get('test-id-2')).toMatchObject({ status: CacheStatus.MISS });
169
+ const results = await cacheAdapter.loadManyAsync(new SingleFieldHolder('id'), [
170
+ new SingleFieldValueHolder('test-id-1'),
171
+ new SingleFieldValueHolder('test-id-2'),
172
+ ]);
173
+ expect(results.get(new SingleFieldValueHolder('test-id-1'))).toMatchObject({
174
+ status: CacheStatus.MISS,
175
+ });
176
+ expect(results.get(new SingleFieldValueHolder('test-id-2'))).toMatchObject({
177
+ status: CacheStatus.MISS,
178
+ });
136
179
  });
137
180
 
138
- it('returns when passed empty array of fieldValues', async () => {
181
+ it('returns when passed empty array of values', async () => {
139
182
  const cacheAdapter = new GenericEntityCacheAdapter(
140
183
  new GenericLocalMemoryCacher(
141
184
  entityConfiguration,
142
185
  GenericLocalMemoryCacher.createLRUCache<BlahFields>({}),
143
186
  ),
144
187
  );
145
- await cacheAdapter.invalidateManyAsync('id', []);
188
+ await cacheAdapter.invalidateManyAsync(
189
+ new SingleFieldHolder<BlahFields, 'id', 'id'>('id'),
190
+ [] as SingleFieldValueHolder<BlahFields, 'id'>[],
191
+ );
146
192
  });
147
193
  });
148
194
  });
@@ -1,94 +0,0 @@
1
- "use strict";
2
- var __importDefault = (this && this.__importDefault) || function (mod) {
3
- return (mod && mod.__esModule) ? mod : { "default": mod };
4
- };
5
- Object.defineProperty(exports, "__esModule", { value: true });
6
- const entity_1 = require("@expo/entity");
7
- const uuid_1 = require("uuid");
8
- const GenericLocalMemoryCacher_1 = __importDefault(require("../GenericLocalMemoryCacher"));
9
- const LocalMemoryTestEntity_1 = __importDefault(require("../testfixtures/LocalMemoryTestEntity"));
10
- const createLocalMemoryTestEntityCompanionProvider_1 = require("../testfixtures/createLocalMemoryTestEntityCompanionProvider");
11
- describe(GenericLocalMemoryCacher_1.default, () => {
12
- it('has correct caching behavior', async () => {
13
- const entityCompanionProvider = (0, createLocalMemoryTestEntityCompanionProvider_1.createLocalMemoryTestEntityCompanionProvider)();
14
- const viewerContext = new entity_1.ViewerContext(entityCompanionProvider);
15
- const genericCacher = viewerContext.entityCompanionProvider.getCompanionForEntity(LocalMemoryTestEntity_1.default)['tableDataCoordinator']['cacheAdapter']['genericCacher'];
16
- const cacheKeyMaker = genericCacher['makeCacheKey'].bind(genericCacher);
17
- const date = new Date();
18
- const entity1Created = await LocalMemoryTestEntity_1.default.creator(viewerContext)
19
- .setField('name', 'blah')
20
- .setField('dateField', date)
21
- .createAsync();
22
- // loading an entity should put it in cache
23
- const entity1 = await LocalMemoryTestEntity_1.default.loader(viewerContext).loadByIDAsync(entity1Created.getID());
24
- const localMemoryCacheAdapterProvider = entityCompanionProvider['cacheAdapterFlavors'].get('local-memory').cacheAdapterProvider;
25
- const entitySpecificGenericCacher = localMemoryCacheAdapterProvider['localMemoryCacheAdapterMap'].get(viewerContext.entityCompanionProvider.getCompanionForEntity(LocalMemoryTestEntity_1.default)
26
- .entityCompanionDefinition.entityConfiguration.tableName)['genericCacher'];
27
- const cachedResult = await entitySpecificGenericCacher.loadManyAsync([
28
- cacheKeyMaker('id', entity1.getID()),
29
- ]);
30
- const cachedValue = cachedResult.get(cacheKeyMaker('id', entity1.getID()));
31
- expect(cachedValue).toMatchObject({
32
- status: entity_1.CacheStatus.HIT,
33
- item: {
34
- id: entity1.getID(),
35
- name: 'blah',
36
- dateField: date,
37
- },
38
- });
39
- // simulate non existent db fetch, should write negative result ('') to cache
40
- const nonExistentId = (0, uuid_1.v4)();
41
- const entityNonExistentResult = await LocalMemoryTestEntity_1.default.loaderWithAuthorizationResults(viewerContext).loadByIDAsync(nonExistentId);
42
- expect(entityNonExistentResult.ok).toBe(false);
43
- const nonExistentCachedResult = await entitySpecificGenericCacher.loadManyAsync([
44
- cacheKeyMaker('id', nonExistentId),
45
- ]);
46
- expect(nonExistentCachedResult.get(cacheKeyMaker('id', nonExistentId))).toMatchObject({
47
- status: entity_1.CacheStatus.NEGATIVE,
48
- });
49
- // load again through entities framework to ensure it reads negative result
50
- const entityNonExistentResult2 = await LocalMemoryTestEntity_1.default.loaderWithAuthorizationResults(viewerContext).loadByIDAsync(nonExistentId);
51
- expect(entityNonExistentResult2.ok).toBe(false);
52
- // invalidate from cache to ensure it invalidates correctly
53
- await LocalMemoryTestEntity_1.default.loaderUtils(viewerContext).invalidateFieldsAsync(entity1.getAllFields());
54
- const cachedResultMiss = await entitySpecificGenericCacher.loadManyAsync([
55
- cacheKeyMaker('id', entity1.getID()),
56
- ]);
57
- const cachedValueMiss = cachedResultMiss.get(cacheKeyMaker('id', entity1.getID()));
58
- expect(cachedValueMiss).toMatchObject({ status: entity_1.CacheStatus.MISS });
59
- });
60
- it('respects the parameters of a noop cache', async () => {
61
- const entityCompanionProvider = (0, createLocalMemoryTestEntityCompanionProvider_1.createNoOpLocalMemoryIntegrationTestEntityCompanionProvider)();
62
- const viewerContext = new entity_1.ViewerContext(entityCompanionProvider);
63
- const genericCacher = viewerContext.entityCompanionProvider.getCompanionForEntity(LocalMemoryTestEntity_1.default)['tableDataCoordinator']['cacheAdapter']['genericCacher'];
64
- const cacheKeyMaker = genericCacher['makeCacheKey'].bind(genericCacher);
65
- const date = new Date();
66
- const entity1Created = await LocalMemoryTestEntity_1.default.creator(viewerContext)
67
- .setField('name', 'blah')
68
- .setField('dateField', date)
69
- .createAsync();
70
- // loading an entity will try to put it in cache but it's a noop cache, so it should be a miss
71
- const entity1 = await LocalMemoryTestEntity_1.default.loader(viewerContext).loadByIDAsync(entity1Created.getID());
72
- const localMemoryCacheAdapterProvider = entityCompanionProvider['cacheAdapterFlavors'].get('local-memory').cacheAdapterProvider;
73
- const entitySpecificGenericCacher = localMemoryCacheAdapterProvider['localMemoryCacheAdapterMap'].get(viewerContext.entityCompanionProvider.getCompanionForEntity(LocalMemoryTestEntity_1.default)
74
- .entityCompanionDefinition.entityConfiguration.tableName)['genericCacher'];
75
- const cachedResult = await entitySpecificGenericCacher.loadManyAsync([
76
- cacheKeyMaker('id', entity1.getID()),
77
- ]);
78
- const cachedValue = cachedResult.get(cacheKeyMaker('id', entity1.getID()));
79
- expect(cachedValue).toMatchObject({
80
- status: entity_1.CacheStatus.MISS,
81
- });
82
- // a non existent db fetch should try to write negative result ('') but it's a noop cache, so it should be a miss
83
- const nonExistentId = (0, uuid_1.v4)();
84
- const entityNonExistentResult = await LocalMemoryTestEntity_1.default.loaderWithAuthorizationResults(viewerContext).loadByIDAsync(nonExistentId);
85
- expect(entityNonExistentResult.ok).toBe(false);
86
- const nonExistentCachedResult = await entitySpecificGenericCacher.loadManyAsync([
87
- cacheKeyMaker('id', nonExistentId),
88
- ]);
89
- expect(nonExistentCachedResult.get(cacheKeyMaker('id', nonExistentId))).toMatchObject({
90
- status: entity_1.CacheStatus.MISS,
91
- });
92
- });
93
- });
94
- //# sourceMappingURL=GenericLocalMemoryCacher-full-test.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"Gen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pF,MAAM,EAAE,oBAAW,CAAC,IAAI;SACzB,CAAC,CAAC;IACL,CAAC,CAAC,CAAC;AACL,CAAC,CAAC,CAAC"}
@@ -1 +0,0 @@
1
- export {};
@@ -1,136 +0,0 @@
1
- "use strict";
2
- var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
- if (k2 === undefined) k2 = k;
4
- var desc = Object.getOwnPropertyDescriptor(m, k);
5
- if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
- desc = { enumerable: true, get: function() { return m[k]; } };
7
- }
8
- Object.defineProperty(o, k2, desc);
9
- }) : (function(o, m, k, k2) {
10
- if (k2 === undefined) k2 = k;
11
- o[k2] = m[k];
12
- }));
13
- var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
14
- Object.defineProperty(o, "default", { enumerable: true, value: v });
15
- }) : function(o, v) {
16
- o["default"] = v;
17
- });
18
- var __importStar = (this && this.__importStar) || (function () {
19
- var ownKeys = function(o) {
20
- ownKeys = Object.getOwnPropertyNames || function (o) {
21
- var ar = [];
22
- for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
23
- return ar;
24
- };
25
- return ownKeys(o);
26
- };
27
- return function (mod) {
28
- if (mod && mod.__esModule) return mod;
29
- var result = {};
30
- if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
31
- __setModuleDefault(result, mod);
32
- return result;
33
- };
34
- })();
35
- Object.defineProperty(exports, "__esModule", { value: true });
36
- const entity_1 = require("@expo/entity");
37
- const GenericLocalMemoryCacher_1 = __importStar(require("../GenericLocalMemoryCacher"));
38
- const entityConfiguration = new entity_1.EntityConfiguration({
39
- idField: 'id',
40
- tableName: 'blah',
41
- schema: {
42
- id: new entity_1.UUIDField({ columnName: 'id', cache: true }),
43
- },
44
- databaseAdapterFlavor: 'postgres',
45
- cacheAdapterFlavor: 'local-memory',
46
- });
47
- describe(GenericLocalMemoryCacher_1.default, () => {
48
- describe(GenericLocalMemoryCacher_1.default.createLRUCache, () => {
49
- it('creates a cache with default options', () => {
50
- const cache = GenericLocalMemoryCacher_1.default.createLRUCache();
51
- expect(cache.max).toBe(10000);
52
- expect(cache.maxAge).toBe(10000);
53
- });
54
- it('respects specified options', () => {
55
- const cache = GenericLocalMemoryCacher_1.default.createLRUCache({
56
- ttlSeconds: 3,
57
- maxSize: 10,
58
- });
59
- expect(cache.max).toBe(10);
60
- expect(cache.maxAge).toBe(3000);
61
- });
62
- });
63
- describe(GenericLocalMemoryCacher_1.default.createNoOpCache, () => {
64
- it('creates a no-op cache', () => {
65
- const cache = GenericLocalMemoryCacher_1.default.createNoOpCache();
66
- cache.set('a', { hello: 'world' });
67
- expect(cache.get('a')).toBeUndefined();
68
- });
69
- });
70
- });
71
- describe('Use within GenericEntityCacheAdapter', () => {
72
- describe('loadManyAsync', () => {
73
- it('returns appropriate cache results', async () => {
74
- const cacheAdapter = new entity_1.GenericEntityCacheAdapter(new GenericLocalMemoryCacher_1.default(entityConfiguration, GenericLocalMemoryCacher_1.default.createLRUCache()));
75
- const cacheHits = new Map([['test-id-1', { id: 'test-id-1' }]]);
76
- await cacheAdapter.cacheManyAsync('id', cacheHits);
77
- await cacheAdapter.cacheDBMissesAsync('id', ['test-id-2']);
78
- const results = await cacheAdapter.loadManyAsync('id', [
79
- 'test-id-1',
80
- 'test-id-2',
81
- 'test-id-3',
82
- ]);
83
- expect(results.get('test-id-1')).toMatchObject({
84
- status: entity_1.CacheStatus.HIT,
85
- item: { id: 'test-id-1' },
86
- });
87
- expect(results.get('test-id-2')).toMatchObject({ status: entity_1.CacheStatus.NEGATIVE });
88
- expect(results.get('test-id-3')).toMatchObject({ status: entity_1.CacheStatus.MISS });
89
- expect(results.size).toBe(3);
90
- });
91
- it('returns empty map when passed empty array of fieldValues', async () => {
92
- const cacheAdapter = new entity_1.GenericEntityCacheAdapter(new GenericLocalMemoryCacher_1.default(entityConfiguration, GenericLocalMemoryCacher_1.default.createLRUCache()));
93
- const results = await cacheAdapter.loadManyAsync('id', []);
94
- expect(results).toEqual(new Map());
95
- });
96
- });
97
- describe('cacheManyAsync', () => {
98
- it('correctly caches all objects', async () => {
99
- const localMemoryCache = GenericLocalMemoryCacher_1.default.createLRUCache({});
100
- const localMemoryCacher = new GenericLocalMemoryCacher_1.default(entityConfiguration, localMemoryCache);
101
- const cacheAdapter = new entity_1.GenericEntityCacheAdapter(localMemoryCacher);
102
- await cacheAdapter.cacheManyAsync('id', new Map([['test-id-1', { id: 'test-id-1' }]]));
103
- const cacheKey = localMemoryCacher['makeCacheKey']('id', 'test-id-1');
104
- expect(localMemoryCache.get(cacheKey)).toMatchObject({
105
- id: 'test-id-1',
106
- });
107
- });
108
- });
109
- describe('cacheDBMissesAsync', () => {
110
- it('correctly caches misses', async () => {
111
- const localMemoryCache = GenericLocalMemoryCacher_1.default.createLRUCache({});
112
- const localMemoryCacher = new GenericLocalMemoryCacher_1.default(entityConfiguration, localMemoryCache);
113
- const cacheAdapter = new entity_1.GenericEntityCacheAdapter(localMemoryCacher);
114
- await cacheAdapter.cacheDBMissesAsync('id', ['test-id-1']);
115
- const cacheKey = localMemoryCacher['makeCacheKey']('id', 'test-id-1');
116
- expect(localMemoryCache.get(cacheKey)).toEqual(GenericLocalMemoryCacher_1.DOES_NOT_EXIST_LOCAL_MEMORY_CACHE);
117
- });
118
- });
119
- describe('invalidateManyAsync', () => {
120
- it('invalidates correctly', async () => {
121
- const localMemoryCache = GenericLocalMemoryCacher_1.default.createLRUCache({});
122
- const cacheAdapter = new entity_1.GenericEntityCacheAdapter(new GenericLocalMemoryCacher_1.default(entityConfiguration, localMemoryCache));
123
- await cacheAdapter.cacheManyAsync('id', new Map([['test-id-1', { id: 'test-id-1' }]]));
124
- await cacheAdapter.cacheDBMissesAsync('id', ['test-id-2']);
125
- await cacheAdapter.invalidateManyAsync('id', ['test-id-1', 'test-id-2']);
126
- const results = await cacheAdapter.loadManyAsync('id', ['test-id-1', 'test-id-2']);
127
- expect(results.get('test-id-1')).toMatchObject({ status: entity_1.CacheStatus.MISS });
128
- expect(results.get('test-id-2')).toMatchObject({ status: entity_1.CacheStatus.MISS });
129
- });
130
- it('returns when passed empty array of fieldValues', async () => {
131
- const cacheAdapter = new entity_1.GenericEntityCacheAdapter(new GenericLocalMemoryCacher_1.default(entityConfiguration, GenericLocalMemoryCacher_1.default.createLRUCache({})));
132
- await cacheAdapter.invalidateManyAsync('id', []);
133
- });
134
- });
135
- });
136
- //# sourceMappingURL=GenericLocalMemoryCacher-test.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"GenericLocalMemoryCacher-test.js","sourceRoot":"","sources":["../../src/__tests__/GenericLocalMemoryCacher-test.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,yCAKsB;AAEtB,wFAEqC;AAMrC,MAAM,mBAAmB,GAAG,IAAI,4BAAmB,CAAa;IAC9D,OAAO,EAAE,IAAI;IACb,SAAS,EAAE,MAAM;IACjB,MAAM,EAAE;QACN,EAAE,EAAE,IAAI,kBAAS,CAAC,EAAE,UAAU,EAAE,IAAI,EAAE,KAAK,EAAE,IAAI,EAAE,CAAC;KACrD;IACD,qBAAqB,EAAE,UAAU;IACjC,kBAAkB,EAAE,cAAc;CACnC,CAAC,CAAC;AAEH,QAAQ,CAAC,kCAAwB,EAAE,GAAG,EAAE;IACtC,QAAQ,CAAC,kCAAwB,CAAC,cAAc,EAAE,GAAG,EAAE;QACrD,EAAE,CAAC,sCAAsC,EAAE,GAAG,EAAE;YAC9C,MAAM,KAAK,GAAG,kCAAwB,CAAC,cAAc,EAAE,CAAC;YACxD,MAAM,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC;YAC9B,MAAM,CAAC,KAAK,CAAC,MAAM,CAAC,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC;QACnC,CAAC,CAAC,CA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,MAAM,YAAY,CAAC,mBAAmB,CAAC,IAAI,EAAE,EAAE,CAAC,CAAC;QACnD,CAAC,CAAC,CAAC;IACL,CAAC,CAAC,CAAC;AACL,CAAC,CAAC,CAAC"}
@@ -1,16 +0,0 @@
1
- import { AlwaysAllowPrivacyPolicyRule, EntityPrivacyPolicy, ViewerContext, EntityConfiguration, EntityCompanionDefinition, Entity } from '@expo/entity';
2
- export type LocalMemoryTestEntityFields = {
3
- id: string;
4
- name: string;
5
- dateField: Date | null;
6
- };
7
- export default class LocalMemoryTestEntity extends Entity<LocalMemoryTestEntityFields, string, ViewerContext> {
8
- static defineCompanionDefinition(): EntityCompanionDefinition<LocalMemoryTestEntityFields, string, ViewerContext, LocalMemoryTestEntity, LocalMemoryTestEntityPrivacyPolicy>;
9
- }
10
- export declare class LocalMemoryTestEntityPrivacyPolicy extends EntityPrivacyPolicy<LocalMemoryTestEntityFields, string, ViewerContext, LocalMemoryTestEntity> {
11
- protected readonly createRules: AlwaysAllowPrivacyPolicyRule<LocalMemoryTestEntityFields, string, ViewerContext, LocalMemoryTestEntity, keyof LocalMemoryTestEntityFields>[];
12
- protected readonly readRules: AlwaysAllowPrivacyPolicyRule<LocalMemoryTestEntityFields, string, ViewerContext, LocalMemoryTestEntity, keyof LocalMemoryTestEntityFields>[];
13
- protected readonly updateRules: AlwaysAllowPrivacyPolicyRule<LocalMemoryTestEntityFields, string, ViewerContext, LocalMemoryTestEntity, keyof LocalMemoryTestEntityFields>[];
14
- protected readonly deleteRules: AlwaysAllowPrivacyPolicyRule<LocalMemoryTestEntityFields, string, ViewerContext, LocalMemoryTestEntity, keyof LocalMemoryTestEntityFields>[];
15
- }
16
- export declare const localMemoryTestEntityConfiguration: EntityConfiguration<LocalMemoryTestEntityFields>;
@@ -1,49 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.localMemoryTestEntityConfiguration = exports.LocalMemoryTestEntityPrivacyPolicy = void 0;
4
- const entity_1 = require("@expo/entity");
5
- class LocalMemoryTestEntity extends entity_1.Entity {
6
- static defineCompanionDefinition() {
7
- return {
8
- entityClass: LocalMemoryTestEntity,
9
- entityConfiguration: exports.localMemoryTestEntityConfiguration,
10
- privacyPolicyClass: LocalMemoryTestEntityPrivacyPolicy,
11
- };
12
- }
13
- }
14
- exports.default = LocalMemoryTestEntity;
15
- class LocalMemoryTestEntityPrivacyPolicy extends entity_1.EntityPrivacyPolicy {
16
- createRules = [
17
- new entity_1.AlwaysAllowPrivacyPolicyRule(),
18
- ];
19
- readRules = [
20
- new entity_1.AlwaysAllowPrivacyPolicyRule(),
21
- ];
22
- updateRules = [
23
- new entity_1.AlwaysAllowPrivacyPolicyRule(),
24
- ];
25
- deleteRules = [
26
- new entity_1.AlwaysAllowPrivacyPolicyRule(),
27
- ];
28
- }
29
- exports.LocalMemoryTestEntityPrivacyPolicy = LocalMemoryTestEntityPrivacyPolicy;
30
- exports.localMemoryTestEntityConfiguration = new entity_1.EntityConfiguration({
31
- idField: 'id',
32
- tableName: 'local_memory_test_entities',
33
- schema: {
34
- id: new entity_1.UUIDField({
35
- columnName: 'id',
36
- cache: true,
37
- }),
38
- name: new entity_1.StringField({
39
- columnName: 'name',
40
- cache: true,
41
- }),
42
- dateField: new entity_1.DateField({
43
- columnName: 'date_field',
44
- }),
45
- },
46
- databaseAdapterFlavor: 'postgres',
47
- cacheAdapterFlavor: 'local-memory',
48
- });
49
- //# sourceMappingURL=LocalMemoryTestEntity.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"LocalMemoryTestEntity.js","sourceRoot":"","sources":["../../src/testfixtures/LocalMemoryTestEntity.ts"],"names":[],"mappings":";;;AAAA,yCAUsB;AAQtB,MAAqB,qBAAsB,SAAQ,eAIlD;IACC,MAAM,CAAC,yBAAyB;QAO9B,OAAO;YACL,WAAW,EAAE,qBAAqB;YAClC,mBAAmB,EAAE,0CAAkC;YACvD,kBAAkB,EAAE,kCAAkC;SACvD,CAAC;IACJ,CAAC;CACF;AAlBD,wCAkBC;AAED,MAAa,kCAAmC,SAAQ,4BAKvD;IAC6B,WAAW,GAAG;QACxC,IAAI,qCAA4B,EAK7B;KACJ,CAAC;IAC0B,SAAS,GAAG;QACtC,IAAI,qCAA4B,EAK7B;KACJ,CAAC;IAC0B,WAAW,GAAG;QACxC,IAAI,qCAA4B,EAK7B;KACJ,CAAC;IAC0B,WAAW,GAAG;QACxC,IAAI,qCAA4B,EAK7B;KACJ,CAAC;CACH;AAtCD,gFAsCC;AAEY,QAAA,kCAAkC,GAC7C,IAAI,4BAAmB,CAA8B;IACnD,OAAO,EAAE,IAAI;IACb,SAAS,EAAE,4BAA4B;IACvC,MAAM,EAAE;QACN,EAAE,EAAE,IAAI,kBAAS,CAAC;YAChB,UAAU,EAAE,IAAI;YAChB,KAAK,EAAE,IAAI;SACZ,CAAC;QACF,IAAI,EAAE,IAAI,oBAAW,CAAC;YACpB,UAAU,EAAE,MAAM;YAClB,KAAK,EAAE,IAAI;SACZ,CAAC;QACF,SAAS,EAAE,IAAI,kBAAS,CAAC;YACvB,UAAU,EAAE,YAAY;SACzB,CAAC;KACH;IACD,qBAAqB,EAAE,UAAU;IACjC,kBAAkB,EAAE,cAAc;CACnC,CAAC,CAAC"}
@@ -1,6 +0,0 @@
1
- import { IEntityMetricsAdapter, EntityCompanionProvider } from '@expo/entity';
2
- export declare const createLocalMemoryTestEntityCompanionProvider: (localMemoryOptions?: {
3
- maxSize?: number;
4
- ttlSeconds?: number;
5
- }, metricsAdapter?: IEntityMetricsAdapter) => EntityCompanionProvider;
6
- export declare const createNoOpLocalMemoryIntegrationTestEntityCompanionProvider: (metricsAdapter?: IEntityMetricsAdapter) => EntityCompanionProvider;
@@ -1,36 +0,0 @@
1
- "use strict";
2
- var __importDefault = (this && this.__importDefault) || function (mod) {
3
- return (mod && mod.__esModule) ? mod : { "default": mod };
4
- };
5
- Object.defineProperty(exports, "__esModule", { value: true });
6
- exports.createNoOpLocalMemoryIntegrationTestEntityCompanionProvider = exports.createLocalMemoryTestEntityCompanionProvider = void 0;
7
- const entity_1 = require("@expo/entity");
8
- const LocalMemoryCacheAdapterProvider_1 = __importDefault(require("../LocalMemoryCacheAdapterProvider"));
9
- const queryContextProvider = new entity_1.StubQueryContextProvider();
10
- const createLocalMemoryTestEntityCompanionProvider = (localMemoryOptions = {}, metricsAdapter = new entity_1.NoOpEntityMetricsAdapter()) => {
11
- const localMemoryCacheAdapterProvider = localMemoryOptions.maxSize === 0 && localMemoryOptions.ttlSeconds === 0
12
- ? LocalMemoryCacheAdapterProvider_1.default.createNoOpProvider()
13
- : LocalMemoryCacheAdapterProvider_1.default.createProviderWithOptions(localMemoryOptions);
14
- return new entity_1.EntityCompanionProvider(metricsAdapter, new Map([
15
- [
16
- 'postgres',
17
- {
18
- adapterProvider: new entity_1.StubDatabaseAdapterProvider(),
19
- queryContextProvider,
20
- },
21
- ],
22
- ]), new Map([
23
- [
24
- 'local-memory',
25
- {
26
- cacheAdapterProvider: localMemoryCacheAdapterProvider,
27
- },
28
- ],
29
- ]));
30
- };
31
- exports.createLocalMemoryTestEntityCompanionProvider = createLocalMemoryTestEntityCompanionProvider;
32
- const createNoOpLocalMemoryIntegrationTestEntityCompanionProvider = (metricsAdapter = new entity_1.NoOpEntityMetricsAdapter()) => {
33
- return (0, exports.createLocalMemoryTestEntityCompanionProvider)({ maxSize: 0, ttlSeconds: 0 }, metricsAdapter);
34
- };
35
- exports.createNoOpLocalMemoryIntegrationTestEntityCompanionProvider = createNoOpLocalMemoryIntegrationTestEntityCompanionProvider;
36
- //# sourceMappingURL=createLocalMemoryTestEntityCompanionProvider.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"createLocalMemoryTestEntityCompanionProvider.js","sourceRoot":"","sources":["../../src/testfixtures/createLocalMemoryTestEntityCompanionProvider.ts"],"names":[],"mappings":";;;;;;AAAA,yCAMsB;AAEtB,yGAAiF;AAEjF,MAAM,oBAAoB,GAAG,IAAI,iCAAwB,EAAE,CAAC;AAErD,MAAM,4CAA4C,GAAG,CAC1D,qBAAgE,EAAE,EAClE,iBAAwC,IAAI,iCAAwB,EAAE,EAC7C,EAAE;IAC3B,MAAM,+BAA+B,GACnC,kBAAkB,CAAC,OAAO,KAAK,CAAC,IAAI,kBAAkB,CAAC,UAAU,KAAK,CAAC;QACrE,CAAC,CAAC,yCAA+B,CAAC,kBAAkB,EAAE;QACtD,CAAC,CAAC,yCAA+B,CAAC,yBAAyB,CAAC,kBAAkB,CAAC,CAAC;IACpF,OAAO,IAAI,gCAAuB,CAChC,cAAc,EACd,IAAI,GAAG,CAAC;QACN;YACE,UAAU;YACV;gBACE,eAAe,EAAE,IAAI,oCAA2B,EAAE;gBAClD,oBAAoB;aACrB;SACF;KACF,CAAC,EACF,IAAI,GAAG,CAAC;QACN;YACE,cAAc;YACd;gBACE,oBAAoB,EAAE,+BAA+B;aACtD;SACF;KACF,CAAC,CACH,CAAC;AACJ,CAAC,CAAC;AA5BW,QAAA,4CAA4C,gDA4BvD;AAEK,MAAM,2DAA2D,GAAG,CACzE,iBAAwC,IAAI,iCAAwB,EAAE,EAC7C,EAAE;IAC3B,OAAO,IAAA,oDAA4C,EACjD,EAAE,OAAO,EAAE,CAAC,EAAE,UAAU,EAAE,CAAC,EAAE,EAC7B,cAAc,CACf,CAAC;AACJ,CAAC,CAAC;AAPW,QAAA,2DAA2D,+DAOtE"}