@expo/entity-cache-adapter-redis 0.34.0 → 0.36.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.
- package/build/GenericRedisCacher.d.ts +1 -1
- package/build/GenericRedisCacher.js +2 -0
- package/build/GenericRedisCacher.js.map +1 -1
- package/build/RedisCacheAdapterProvider.d.ts +1 -1
- package/build/RedisCacheAdapterProvider.js +1 -0
- package/build/RedisCacheAdapterProvider.js.map +1 -1
- package/build/__integration-tests__/BatchedRedisCacheAdapter-integration-test.js +19 -16
- package/build/__integration-tests__/BatchedRedisCacheAdapter-integration-test.js.map +1 -1
- package/build/__integration-tests__/GenericRedisCacher-full-integration-test.js +18 -18
- package/build/__integration-tests__/GenericRedisCacher-full-integration-test.js.map +1 -1
- package/build/__integration-tests__/GenericRedisCacher-integration-test.js +3 -3
- package/build/__integration-tests__/GenericRedisCacher-integration-test.js.map +1 -1
- package/build/__integration-tests__/errors-test.js +2 -4
- package/build/__integration-tests__/errors-test.js.map +1 -1
- package/build/errors/__tests__/wrapNativeRedisCallAsync-test.js.map +1 -1
- package/build/errors/wrapNativeRedisCallAsync.js.map +1 -1
- package/build/testfixtures/RedisTestEntity.js +12 -15
- package/build/testfixtures/RedisTestEntity.js.map +1 -1
- package/package.json +3 -3
- package/src/GenericRedisCacher.ts +12 -10
- package/src/RedisCacheAdapterProvider.ts +2 -2
- package/src/__integration-tests__/BatchedRedisCacheAdapter-integration-test.ts +21 -43
- package/src/__integration-tests__/GenericRedisCacher-full-integration-test.ts +26 -59
- package/src/__integration-tests__/GenericRedisCacher-integration-test.ts +8 -14
- package/src/__integration-tests__/errors-test.ts +3 -8
- package/src/__tests__/GenericRedisCacher-test.ts +9 -9
- package/src/testfixtures/createRedisIntegrationTestEntityCompanionProvider.ts +2 -2
|
@@ -34,7 +34,7 @@ export interface GenericRedisCacheContext {
|
|
|
34
34
|
*/
|
|
35
35
|
ttlSecondsNegative: number;
|
|
36
36
|
}
|
|
37
|
-
export default class GenericRedisCacher<TFields
|
|
37
|
+
export default class GenericRedisCacher<TFields extends Record<string, any>> implements IEntityGenericCacher<TFields> {
|
|
38
38
|
private readonly context;
|
|
39
39
|
private readonly entityConfiguration;
|
|
40
40
|
constructor(context: GenericRedisCacheContext, entityConfiguration: EntityConfiguration<TFields>);
|
|
@@ -11,6 +11,8 @@ const wrapNativeRedisCallAsync_1 = __importDefault(require("./errors/wrapNativeR
|
|
|
11
11
|
// The sentinel value is distinct from any (positively) cached value.
|
|
12
12
|
const DOES_NOT_EXIST_REDIS = '';
|
|
13
13
|
class GenericRedisCacher {
|
|
14
|
+
context;
|
|
15
|
+
entityConfiguration;
|
|
14
16
|
constructor(context, entityConfiguration) {
|
|
15
17
|
this.context = context;
|
|
16
18
|
this.entityConfiguration = entityConfiguration;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"GenericRedisCacher.js","sourceRoot":"","sources":["../src/GenericRedisCacher.ts"],"names":[],"mappings":";;;;;AAAA,yCAOsB;AACtB,0DAAkC;AAElC,+CAAoD;AACpD,iGAAyE;AAEzE,wEAAwE;AACxE,qEAAqE;AACrE,MAAM,oBAAoB,GAAG,EAAE,CAAC;AA4ChC,MAAqB,kBAAkB;
|
|
1
|
+
{"version":3,"file":"GenericRedisCacher.js","sourceRoot":"","sources":["../src/GenericRedisCacher.ts"],"names":[],"mappings":";;;;;AAAA,yCAOsB;AACtB,0DAAkC;AAElC,+CAAoD;AACpD,iGAAyE;AAEzE,wEAAwE;AACxE,qEAAqE;AACrE,MAAM,oBAAoB,GAAG,EAAE,CAAC;AA4ChC,MAAqB,kBAAkB;IAIlB;IACA;IAFnB,YACmB,OAAiC,EACjC,mBAAiD;QADjD,YAAO,GAAP,OAAO,CAA0B;QACjC,wBAAmB,GAAnB,mBAAmB,CAA8B;IACjE,CAAC;IAEG,KAAK,CAAC,aAAa,CACxB,IAAuB;QAEvB,IAAI,IAAI,CAAC,MAAM,KAAK,CAAC,EAAE,C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AAM,UAAU,GAAG,IAAI,CAAC,mBAAmB,CAAC,0BAA0B,CAAC,GAAG,CAAC,SAAS,CAAC,CAAC;QACtF,IAAA,mBAAS,EAAC,UAAU,EAAE,sCAAsC,MAAM,CAAC,SAAS,CAAC,EAAE,CAAC,CAAC;QACjF,OAAO,IAAI,CAAC,OAAO,CAAC,SAAS,CAC3B,IAAI,CAAC,OAAO,CAAC,cAAc,EAC3B,IAAI,CAAC,mBAAmB,CAAC,SAAS,EAClC,MAAM,IAAI,CAAC,mBAAmB,CAAC,eAAe,EAAE,EAChD,UAAU,EACV,MAAM,CAAC,UAAU,CAAC,CACnB,CAAC;IACJ,CAAC;CACF;AAxGD,qCAwGC"}
|
|
@@ -3,5 +3,5 @@ import { GenericRedisCacheContext } from './GenericRedisCacher';
|
|
|
3
3
|
export default class RedisCacheAdapterProvider implements IEntityCacheAdapterProvider {
|
|
4
4
|
private readonly context;
|
|
5
5
|
constructor(context: GenericRedisCacheContext);
|
|
6
|
-
getCacheAdapter<TFields
|
|
6
|
+
getCacheAdapter<TFields extends Record<string, any>>(entityConfiguration: EntityConfiguration<TFields>): IEntityCacheAdapter<TFields>;
|
|
7
7
|
}
|
|
@@ -6,6 +6,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
6
6
|
const entity_1 = require("@expo/entity");
|
|
7
7
|
const GenericRedisCacher_1 = __importDefault(require("./GenericRedisCacher"));
|
|
8
8
|
class RedisCacheAdapterProvider {
|
|
9
|
+
context;
|
|
9
10
|
constructor(context) {
|
|
10
11
|
this.context = context;
|
|
11
12
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"RedisCacheAdapterProvider.js","sourceRoot":"","sources":["../src/RedisCacheAdapterProvider.ts"],"names":[],"mappings":";;;;;AAAA,yCAKsB;AAEtB,8EAAoF;AAEpF,MAAqB,yBAAyB;
|
|
1
|
+
{"version":3,"file":"RedisCacheAdapterProvider.js","sourceRoot":"","sources":["../src/RedisCacheAdapterProvider.ts"],"names":[],"mappings":";;;;;AAAA,yCAKsB;AAEtB,8EAAoF;AAEpF,MAAqB,yBAAyB;IACf;IAA7B,YAA6B,OAAiC;QAAjC,YAAO,GAAP,OAAO,CAA0B;IAAG,CAAC;IAElE,eAAe,CACb,mBAAiD;QAEjD,OAAO,IAAI,kCAAyB,CAAC,IAAI,4BAAkB,CAAC,IAAI,CAAC,OAAO,EAAE,mBAAmB,CAAC,CAAC,CAAC;IAClG,CAAC;CACF;AARD,4CAQC"}
|
|
@@ -14,11 +14,12 @@ const GenericRedisCacher_1 = __importDefault(require("../GenericRedisCacher"));
|
|
|
14
14
|
const RedisTestEntity_1 = __importDefault(require("../testfixtures/RedisTestEntity"));
|
|
15
15
|
const createRedisIntegrationTestEntityCompanionProvider_1 = require("../testfixtures/createRedisIntegrationTestEntityCompanionProvider");
|
|
16
16
|
class BatchedRedis {
|
|
17
|
+
redis;
|
|
18
|
+
mgetBatcher = new batcher_1.Batcher(this.batchMgetAsync.bind(this), {
|
|
19
|
+
maxBatchInterval: 0,
|
|
20
|
+
});
|
|
17
21
|
constructor(redis) {
|
|
18
22
|
this.redis = redis;
|
|
19
|
-
this.mgetBatcher = new batcher_1.Batcher(this.batchMgetAsync.bind(this), {
|
|
20
|
-
maxBatchInterval: 0,
|
|
21
|
-
});
|
|
22
23
|
}
|
|
23
24
|
async batchMgetAsync(keySets) {
|
|
24
25
|
// ordered distinct keys to fetch
|
|
@@ -57,7 +58,7 @@ describe(GenericRedisCacher_1.default, () => {
|
|
|
57
58
|
return escapedParts.join(delimiter);
|
|
58
59
|
},
|
|
59
60
|
cacheKeyPrefix: 'test-',
|
|
60
|
-
ttlSecondsPositive: 86400,
|
|
61
|
+
ttlSecondsPositive: 86400, // 1 day
|
|
61
62
|
ttlSecondsNegative: 600, // 10 minutes
|
|
62
63
|
};
|
|
63
64
|
});
|
|
@@ -73,7 +74,7 @@ describe(GenericRedisCacher_1.default, () => {
|
|
|
73
74
|
const mgetSpy = jest.spyOn(redis, 'mget');
|
|
74
75
|
const genericCacher = viewerContext.entityCompanionProvider.getCompanionForEntity(RedisTestEntity_1.default)['tableDataCoordinator']['cacheAdapter']['genericCacher'];
|
|
75
76
|
const cacheKeyMaker = genericCacher['makeCacheKey'].bind(genericCacher);
|
|
76
|
-
const entity1Created = await RedisTestEntity_1.default.creator(viewerContext
|
|
77
|
+
const entity1Created = await RedisTestEntity_1.default.creator(viewerContext)
|
|
77
78
|
.setField('name', 'blah')
|
|
78
79
|
.enforceCreateAsync();
|
|
79
80
|
// loading an entity should put it in cache. load by multiple requests and multiple fields in same tick to ensure batch works
|
|
@@ -82,13 +83,9 @@ describe(GenericRedisCacher_1.default, () => {
|
|
|
82
83
|
const viewerContext2 = new entity_1.ViewerContext((0, createRedisIntegrationTestEntityCompanionProvider_1.createRedisIntegrationTestEntityCompanionProvider)(genericRedisCacheContext));
|
|
83
84
|
const viewerContext3 = new entity_1.ViewerContext((0, createRedisIntegrationTestEntityCompanionProvider_1.createRedisIntegrationTestEntityCompanionProvider)(genericRedisCacheContext));
|
|
84
85
|
const [entity1, entity2, entity3] = await Promise.all([
|
|
85
|
-
RedisTestEntity_1.default.loader(viewerContext1
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
RedisTestEntity_1.default.loader(viewerContext2, viewerContext2.getNonTransactionalQueryContextForDatabaseAdaptorFlavor('postgres'))
|
|
89
|
-
.enforcing()
|
|
90
|
-
.loadByIDAsync(entity1Created.getID()),
|
|
91
|
-
RedisTestEntity_1.default.loader(viewerContext3, viewerContext3.getNonTransactionalQueryContextForDatabaseAdaptorFlavor('postgres'))
|
|
86
|
+
RedisTestEntity_1.default.loader(viewerContext1).enforcing().loadByIDAsync(entity1Created.getID()),
|
|
87
|
+
RedisTestEntity_1.default.loader(viewerContext2).enforcing().loadByIDAsync(entity1Created.getID()),
|
|
88
|
+
RedisTestEntity_1.default.loader(viewerContext3)
|
|
92
89
|
.enforcing()
|
|
93
90
|
.loadByFieldEqualingAsync('name', entity1Created.getField('name')),
|
|
94
91
|
]);
|
|
@@ -104,22 +101,28 @@ describe(GenericRedisCacher_1.default, () => {
|
|
|
104
101
|
name: 'blah',
|
|
105
102
|
});
|
|
106
103
|
const cacheKeyEntity1NameField = cacheKeyMaker('name', entity1Created.getField('name'));
|
|
107
|
-
await RedisTestEntity_1.default.loader(viewerContext
|
|
104
|
+
await RedisTestEntity_1.default.loader(viewerContext)
|
|
108
105
|
.enforcing()
|
|
109
106
|
.loadByFieldEqualingAsync('name', entity1Created.getField('name'));
|
|
110
107
|
await expect(redis.get(cacheKeyEntity1NameField)).resolves.toEqual(cachedJSON);
|
|
111
108
|
// simulate non existent db fetch, should write negative result ('') to cache
|
|
112
109
|
const nonExistentId = (0, uuid_1.v4)();
|
|
113
|
-
const entityNonExistentResult = await RedisTestEntity_1.default.loader(viewerContext
|
|
110
|
+
const entityNonExistentResult = await RedisTestEntity_1.default.loader(viewerContext)
|
|
111
|
+
.withAuthorizationResults()
|
|
112
|
+
.loadByIDAsync(nonExistentId);
|
|
114
113
|
expect(entityNonExistentResult.ok).toBe(false);
|
|
115
114
|
const cacheKeyNonExistent = cacheKeyMaker('id', nonExistentId);
|
|
116
115
|
const nonExistentCachedValue = await redis.get(cacheKeyNonExistent);
|
|
117
116
|
expect(nonExistentCachedValue).toEqual('');
|
|
118
117
|
// load again through entities framework to ensure it reads negative result
|
|
119
|
-
const entityNonExistentResult2 = await RedisTestEntity_1.default.loader(viewerContext
|
|
118
|
+
const entityNonExistentResult2 = await RedisTestEntity_1.default.loader(viewerContext)
|
|
119
|
+
.withAuthorizationResults()
|
|
120
|
+
.loadByIDAsync(nonExistentId);
|
|
120
121
|
expect(entityNonExistentResult2.ok).toBe(false);
|
|
121
122
|
// invalidate from cache to ensure it invalidates correctly in both caches
|
|
122
|
-
await RedisTestEntity_1.default.loader(viewerContext
|
|
123
|
+
await RedisTestEntity_1.default.loader(viewerContext)
|
|
124
|
+
.utils()
|
|
125
|
+
.invalidateFieldsAsync(entity1.getAllFields());
|
|
123
126
|
await expect(redis.get(cacheKeyEntity1)).resolves.toBeNull();
|
|
124
127
|
await expect(redis.get(cacheKeyEntity1NameField)).resolves.toBeNull();
|
|
125
128
|
});
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"BatchedRedisCacheAdapter-integration-test.js","sourceRoot":"","sources":["../../src/__integration-tests__/BatchedRedisCacheAdapter-integration-test.ts"],"names":[],"mappings":";;;;;AAAA,2CAAwC;AACxC,yCAAuD;AACvD,0DAAkC;AAClC,sDAA4B;AAC5B,4DAAoC;AACpC,6BAA0B;AAC1B,+BAAoC;AAEpC,+EAI+B;AAC/B,sFAA8D;AAC9D,yIAAsI;AAEtI,MAAM,YAAY;
|
|
1
|
+
{"version":3,"file":"BatchedRedisCacheAdapter-integration-test.js","sourceRoot":"","sources":["../../src/__integration-tests__/BatchedRedisCacheAdapter-integration-test.ts"],"names":[],"mappings":";;;;;AAAA,2CAAwC;AACxC,yCAAuD;AACvD,0DAAkC;AAClC,sDAA4B;AAC5B,4DAAoC;AACpC,6BAA0B;AAC1B,+BAAoC;AAEpC,+EAI+B;AAC/B,sFAA8D;AAC9D,yIAAsI;AAEtI,MAAM,YAAY;IAQa;IAPZ,WAAW,GAAG,IAAI,iBAAO,CACxC,IAAI,CAAC,cAAc,CAAC,IAAI,CAAC,IAAI,CAAC,EAC9B;QACE,gBAAgB,EAAE,CAAC;KACpB,CACF,CAAC;IAEF,YAA6B,KAAY;QAAZ,UAAK,GAAL,KAAK,CAAO;IAAG,CAAC;IAErC,KAAK,CAAC,cAAc,CAAC,OAAmB;QAC9C,iCAAiC;QACjC,MAAM,cAAc,GAAG,CAAC,GAAG,IAAI,GAAG,CAAC,OAAO,CAAC,IAAI,EAAE,CAAC,CAAC,CAAC;QAEpD,0BAA0B;QAC1B,MAAM,UAAU,GAAG,MAAM,IAAI,CAAC,KAAK,CAAC,IAAI,CAAC,GAAG,cAAc,CAAC,CAAC;QAE5D,sCAAsC;QACtC,MAAM,aA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AC,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC;QAEhD,0EAA0E;QAC1E,MAAM,yBAAe,CAAC,MAAM,CAAC,aAAa,CAAC;aACxC,KAAK,EAAE;aACP,qBAAqB,CAAC,OAAO,CAAC,YAAY,EAAE,CAAC,CAAC;QACjD,MAAM,MAAM,CAAC,KAAK,CAAC,GAAG,CAAC,eAAe,CAAC,CAAC,CAAC,QAAQ,CAAC,QAAQ,EAAE,CAAC;QAC7D,MAAM,MAAM,CAAC,KAAK,CAAC,GAAG,CAAC,wBAAwB,CAAC,CAAC,CAAC,QAAQ,CAAC,QAAQ,EAAE,CAAC;IACxE,CAAC,CAAC,CAAC;AACL,CAAC,CAAC,CAAC"}
|
|
@@ -24,7 +24,7 @@ describe(GenericRedisCacher_1.default, () => {
|
|
|
24
24
|
return escapedParts.join(delimiter);
|
|
25
25
|
},
|
|
26
26
|
cacheKeyPrefix: 'test-',
|
|
27
|
-
ttlSecondsPositive: 86400,
|
|
27
|
+
ttlSecondsPositive: 86400, // 1 day
|
|
28
28
|
ttlSecondsNegative: 600, // 10 minutes
|
|
29
29
|
};
|
|
30
30
|
});
|
|
@@ -38,11 +38,11 @@ describe(GenericRedisCacher_1.default, () => {
|
|
|
38
38
|
const viewerContext = new TestViewerContext((0, createRedisIntegrationTestEntityCompanionProvider_1.createRedisIntegrationTestEntityCompanionProvider)(genericRedisCacheContext));
|
|
39
39
|
const genericCacher = viewerContext.entityCompanionProvider.getCompanionForEntity(RedisTestEntity_1.default)['tableDataCoordinator']['cacheAdapter']['genericCacher'];
|
|
40
40
|
const cacheKeyMaker = genericCacher['makeCacheKey'].bind(genericCacher);
|
|
41
|
-
const entity1Created = await RedisTestEntity_1.default.creator(viewerContext
|
|
41
|
+
const entity1Created = await RedisTestEntity_1.default.creator(viewerContext)
|
|
42
42
|
.setField('name', 'blah')
|
|
43
43
|
.enforceCreateAsync();
|
|
44
44
|
// loading an entity should put it in cache
|
|
45
|
-
const entity1 = await RedisTestEntity_1.default.loader(viewerContext
|
|
45
|
+
const entity1 = await RedisTestEntity_1.default.loader(viewerContext)
|
|
46
46
|
.enforcing()
|
|
47
47
|
.loadByIDAsync(entity1Created.getID());
|
|
48
48
|
const cachedJSON = await genericRedisCacheContext.redisClient.get(cacheKeyMaker('id', entity1.getID()));
|
|
@@ -53,48 +53,48 @@ describe(GenericRedisCacher_1.default, () => {
|
|
|
53
53
|
});
|
|
54
54
|
// simulate non existent db fetch, should write negative result ('') to cache
|
|
55
55
|
const nonExistentId = (0, uuid_1.v4)();
|
|
56
|
-
const entityNonExistentResult = await RedisTestEntity_1.default.loader(viewerContext
|
|
56
|
+
const entityNonExistentResult = await RedisTestEntity_1.default.loader(viewerContext)
|
|
57
|
+
.withAuthorizationResults()
|
|
58
|
+
.loadByIDAsync(nonExistentId);
|
|
57
59
|
expect(entityNonExistentResult.ok).toBe(false);
|
|
58
60
|
const nonExistentCachedValue = await genericRedisCacheContext.redisClient.get(cacheKeyMaker('id', nonExistentId));
|
|
59
61
|
expect(nonExistentCachedValue).toEqual('');
|
|
60
62
|
// load again through entities framework to ensure it reads negative result
|
|
61
|
-
const entityNonExistentResult2 = await RedisTestEntity_1.default.loader(viewerContext
|
|
63
|
+
const entityNonExistentResult2 = await RedisTestEntity_1.default.loader(viewerContext)
|
|
64
|
+
.withAuthorizationResults()
|
|
65
|
+
.loadByIDAsync(nonExistentId);
|
|
62
66
|
expect(entityNonExistentResult2.ok).toBe(false);
|
|
63
67
|
// invalidate from cache to ensure it invalidates correctly
|
|
64
|
-
await RedisTestEntity_1.default.loader(viewerContext
|
|
68
|
+
await RedisTestEntity_1.default.loader(viewerContext)
|
|
69
|
+
.utils()
|
|
70
|
+
.invalidateFieldsAsync(entity1.getAllFields());
|
|
65
71
|
const cachedValueNull = await genericRedisCacheContext.redisClient.get(cacheKeyMaker('id', entity1.getID()));
|
|
66
72
|
expect(cachedValueNull).toBe(null);
|
|
67
73
|
});
|
|
68
74
|
it('caches and restores date fields', async () => {
|
|
69
75
|
const viewerContext = new TestViewerContext((0, createRedisIntegrationTestEntityCompanionProvider_1.createRedisIntegrationTestEntityCompanionProvider)(genericRedisCacheContext));
|
|
70
76
|
const date = new Date();
|
|
71
|
-
const entity1 = await (0, results_1.enforceAsyncResult)(RedisTestEntity_1.default.creator(viewerContext
|
|
72
|
-
.setField('dateField', date)
|
|
73
|
-
.createAsync());
|
|
77
|
+
const entity1 = await (0, results_1.enforceAsyncResult)(RedisTestEntity_1.default.creator(viewerContext).setField('dateField', date).createAsync());
|
|
74
78
|
expect(entity1.getField('dateField')).toEqual(date);
|
|
75
|
-
const entity2 = await RedisTestEntity_1.default.loader(viewerContext
|
|
79
|
+
const entity2 = await RedisTestEntity_1.default.loader(viewerContext)
|
|
76
80
|
.enforcing()
|
|
77
81
|
.loadByIDAsync(entity1.getID());
|
|
78
82
|
expect(entity2.getField('dateField')).toEqual(date);
|
|
79
83
|
// simulate new request
|
|
80
84
|
const vc2 = new TestViewerContext((0, createRedisIntegrationTestEntityCompanionProvider_1.createRedisIntegrationTestEntityCompanionProvider)(genericRedisCacheContext));
|
|
81
|
-
const entity3 = await RedisTestEntity_1.default.loader(vc2
|
|
82
|
-
.enforcing()
|
|
83
|
-
.loadByIDAsync(entity1.getID());
|
|
85
|
+
const entity3 = await RedisTestEntity_1.default.loader(vc2).enforcing().loadByIDAsync(entity1.getID());
|
|
84
86
|
expect(entity3.getField('dateField')).toEqual(date);
|
|
85
87
|
});
|
|
86
88
|
it('caches and restores empty string field keys', async () => {
|
|
87
89
|
const viewerContext = new TestViewerContext((0, createRedisIntegrationTestEntityCompanionProvider_1.createRedisIntegrationTestEntityCompanionProvider)(genericRedisCacheContext));
|
|
88
|
-
const entity1 = await (0, results_1.enforceAsyncResult)(RedisTestEntity_1.default.creator(viewerContext
|
|
89
|
-
|
|
90
|
-
.createAsync());
|
|
91
|
-
const entity2 = await RedisTestEntity_1.default.loader(viewerContext, viewerContext.getNonTransactionalQueryContextForDatabaseAdaptorFlavor('postgres'))
|
|
90
|
+
const entity1 = await (0, results_1.enforceAsyncResult)(RedisTestEntity_1.default.creator(viewerContext).setField('name', '').createAsync());
|
|
91
|
+
const entity2 = await RedisTestEntity_1.default.loader(viewerContext)
|
|
92
92
|
.enforcing()
|
|
93
93
|
.loadByFieldEqualingAsync('name', '');
|
|
94
94
|
expect(entity2?.getID()).toEqual(entity1.getID());
|
|
95
95
|
// simulate new request
|
|
96
96
|
const vc2 = new TestViewerContext((0, createRedisIntegrationTestEntityCompanionProvider_1.createRedisIntegrationTestEntityCompanionProvider)(genericRedisCacheContext));
|
|
97
|
-
const entity3 = await RedisTestEntity_1.default.loader(vc2
|
|
97
|
+
const entity3 = await RedisTestEntity_1.default.loader(vc2)
|
|
98
98
|
.enforcing()
|
|
99
99
|
.loadByFieldEqualingAsync('name', '');
|
|
100
100
|
expect(entity3?.getID()).toEqual(entity1.getID());
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"GenericRedisCacher-full-integration-test.js","sourceRoot":"","sources":["../../src/__integration-tests__/GenericRedisCacher-full-integration-test.ts"],"names":[],"mappings":";;;;;AAAA,yCAA6C;AAC7C,2CAAmD;AACnD,sDAA4B;AAC5B,6BAA0B;AAC1B,+BAAoC;AAEpC,+EAAqF;AACrF,sFAA8D;AAC9D,yIAAsI;AAEtI,MAAM,iBAAkB,SAAQ,sBAAa;CAAG;AAEhD,QAAQ,CAAC,4BAAkB,EAAE,GAAG,EAAE;IAChC,IAAI,wBAAkD,CAAC;IAEvD,SAAS,CAAC,GAAG,EAAE;QACb,wBAAwB,GAAG;YACzB,WAAW,EAAE,IAAI,iBAAK,CAAC,IAAI,SAAG,CAAC,OAAO,CAAC,GAAG,CAAC,WAAW,CAAE,CAAC,CAAC,QAAQ,EAAE,CAAC;YACrE,SAAS,CAAC,GAAG,KAAe;gBAC1B,MAAM,SAAS,GAAG,GAAG,CAAC;gBACtB,MAAM,YAAY,GAAG,KAAK,CAAC,GAAG,CAAC,CAAC,IAAI,EAAE,EAAE,CACtC,IAAI,CAAC,OAAO,CAAC,IAAI,EAAE,MAAM,CAAC,CAAC,OAAO,CAAC,SAAS,EAAE,KAAK,SAAS,EAAE,CAAC,CAChE,CAAC;gBACF,OAAO,YAAY,CAAC,IAAI,CAAC,SAAS,CAAC,CAAC;YACtC,CAAC;YACD,cAAc,EAAE,OAAO;YACvB,kBAAkB,EAAE,KAAK;
|
|
1
|
+
{"version":3,"file":"GenericRedisCacher-full-integration-test.js","sourceRoot":"","sources":["../../src/__integration-tests__/GenericRedisCacher-full-integration-test.ts"],"names":[],"mappings":";;;;;AAAA,yCAA6C;AAC7C,2CAAmD;AACnD,sDAA4B;AAC5B,6BAA0B;AAC1B,+BAAoC;AAEpC,+EAAqF;AACrF,sFAA8D;AAC9D,yIAAsI;AAEtI,MAAM,iBAAkB,SAAQ,sBAAa;CAAG;AAEhD,QAAQ,CAAC,4BAAkB,EAAE,GAAG,EAAE;IAChC,IAAI,wBAAkD,CAAC;IAEvD,SAAS,CAAC,GAAG,EAAE;QACb,wBAAwB,GAAG;YACzB,WAAW,EAAE,IAAI,iBAAK,CAAC,IAAI,SAAG,CAAC,OAAO,CAAC,GAAG,CAAC,WAAW,CAAE,CAAC,CAAC,QAAQ,EAAE,CAAC;YACrE,SAAS,CAAC,GAAG,KAAe;gBAC1B,MAAM,SAAS,GAAG,GAAG,CAAC;gBACtB,MAAM,YAAY,GAAG,KAAK,CAAC,GAAG,CAAC,CAAC,IAAI,EAAE,EAAE,CACtC,IAAI,CAAC,OAAO,CAAC,IAAI,EAAE,MAAM,CAAC,CAAC,OAAO,CAAC,SAAS,EAAE,KAAK,SAAS,EAAE,CAAC,CAChE,CAAC;gBACF,OAAO,YAAY,CAAC,IAAI,CAAC,SAAS,CAAC,CAAC;YACtC,CAAC;YACD,cAAc,EAAE,OAAO;YACvB,kBAAkB,EAAE,KAAK,EAAE,QAAQ;YACnC,kBAAkB,EAAE,GAAG,EAAE,aAAa;SACvC,CAAC;IACJ,CAAC,CA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AM,CAAC,aAAa,CAAC;aACxD,SAAS,EAAE;aACX,wBAAwB,CAAC,MAAM,EAAE,EAAE,CAAC,CAAC;QACxC,MAAM,CAAC,OAAO,EAAE,KAAK,EAAE,CAAC,CAAC,OAAO,CAAC,OAAO,CAAC,KAAK,EAAE,CAAC,CAAC;QAElD,uBAAuB;QACvB,MAAM,GAAG,GAAG,IAAI,iBAAiB,CAC/B,IAAA,qGAAiD,EAAC,wBAAwB,CAAC,CAC5E,CAAC;QACF,MAAM,OAAO,GAAG,MAAM,yBAAe,CAAC,MAAM,CAAC,GAAG,CAAC;aAC9C,SAAS,EAAE;aACX,wBAAwB,CAAC,MAAM,EAAE,EAAE,CAAC,CAAC;QACxC,MAAM,CAAC,OAAO,EAAE,KAAK,EAAE,CAAC,CAAC,OAAO,CAAC,OAAO,CAAC,KAAK,EAAE,CAAC,CAAC;IACpD,CAAC,CAAC,CAAC;AACL,CAAC,CAAC,CAAC"}
|
|
@@ -45,7 +45,7 @@ describe(GenericRedisCacher_1.default, () => {
|
|
|
45
45
|
return escapedParts.join(delimiter);
|
|
46
46
|
},
|
|
47
47
|
cacheKeyPrefix: 'test-',
|
|
48
|
-
ttlSecondsPositive: 86400,
|
|
48
|
+
ttlSecondsPositive: 86400, // 1 day
|
|
49
49
|
ttlSecondsNegative: 600, // 10 minutes
|
|
50
50
|
};
|
|
51
51
|
});
|
|
@@ -59,7 +59,7 @@ describe(GenericRedisCacher_1.default, () => {
|
|
|
59
59
|
const viewerContext = new TestViewerContext((0, createRedisIntegrationTestEntityCompanionProvider_1.createRedisIntegrationTestEntityCompanionProvider)(genericRedisCacheContext));
|
|
60
60
|
const genericRedisCacher = new GenericRedisCacher_1.default(genericRedisCacheContext, RedisTestEntity_1.redisTestEntityConfiguration);
|
|
61
61
|
const date = new Date();
|
|
62
|
-
const entity1Created = await RedisTestEntity_1.default.creator(viewerContext
|
|
62
|
+
const entity1Created = await RedisTestEntity_1.default.creator(viewerContext)
|
|
63
63
|
.setField('name', 'blah')
|
|
64
64
|
.setField('dateField', date)
|
|
65
65
|
.enforceCreateAsync();
|
|
@@ -94,7 +94,7 @@ describe(GenericRedisCacher_1.default, () => {
|
|
|
94
94
|
const viewerContext = new TestViewerContext((0, createRedisIntegrationTestEntityCompanionProvider_1.createRedisIntegrationTestEntityCompanionProvider)(genericRedisCacheContext));
|
|
95
95
|
const genericRedisCacher = new GenericRedisCacher_1.default(genericRedisCacheContext, RedisTestEntity_1.redisTestEntityConfiguration);
|
|
96
96
|
const date = new Date();
|
|
97
|
-
const entity1Created = await RedisTestEntity_1.default.creator(viewerContext
|
|
97
|
+
const entity1Created = await RedisTestEntity_1.default.creator(viewerContext)
|
|
98
98
|
.setField('name', 'blah')
|
|
99
99
|
.setField('dateField', date)
|
|
100
100
|
.enforceCreateAsync();
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"GenericRedisCacher-integration-test.js","sourceRoot":"","sources":["../../src/__integration-tests__/GenericRedisCacher-integration-test.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,yCAA0D;AAC1D,sDAA4B;AAC5B,6BAA0B;AAE1B,+EAAqF;AACrF,mFAGyC;AACzC,yIAAsI;AAEtI,MAAM,iBAAkB,SAAQ,sBAAa;CAAG;AAEhD,QAAQ,CAAC,4BAAkB,EAAE,GAAG,EAAE;IAChC,IAAI,wBAAkD,CAAC;IAEvD,SAAS,CAAC,GAAG,EAAE;QACb,wBAAwB,GAAG;YACzB,WAAW,EAAE,IAAI,iBAAK,CAAC,IAAI,SAAG,CAAC,OAAO,CAAC,GAAG,CAAC,WAAW,CAAE,CAAC,CAAC,QAAQ,EAAE,CAAC;YACrE,SAAS,CAAC,GAAG,KAAe;gBAC1B,MAAM,SAAS,GAAG,GAAG,CAAC;gBACtB,MAAM,YAAY,GAAG,KAAK,CAAC,GAAG,CAAC,CAAC,IAAI,EAAE,EAAE,CACtC,IAAI,CAAC,OAAO,CAAC,IAAI,EAAE,MAAM,CAAC,CAAC,OAAO,CAAC,SAAS,EAAE,KAAK,SAAS,EAAE,CAAC,CAChE,CAAC;gBACF,OAAO,YAAY,CAAC,IAAI,CAAC,SAAS,CAAC,CAAC;YACtC,CAAC;YACD,cAAc,EAAE,OAAO;YACvB,kBAAkB,EAAE,KAAK;
|
|
1
|
+
{"version":3,"file":"GenericRedisCacher-integration-test.js","sourceRoot":"","sources":["../../src/__integration-tests__/GenericRedisCacher-integration-test.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,yCAA0D;AAC1D,sDAA4B;AAC5B,6BAA0B;AAE1B,+EAAqF;AACrF,mFAGyC;AACzC,yIAAsI;AAEtI,MAAM,iBAAkB,SAAQ,sBAAa;CAAG;AAEhD,QAAQ,CAAC,4BAAkB,EAAE,GAAG,EAAE;IAChC,IAAI,wBAAkD,CAAC;IAEvD,SAAS,CAAC,GAAG,EAAE;QACb,wBAAwB,GAAG;YACzB,WAAW,EAAE,IAAI,iBAAK,CAAC,IAAI,SAAG,CAAC,OAAO,CAAC,GAAG,CAAC,WAAW,CAAE,CAAC,CAAC,QAAQ,EAAE,CAAC;YACrE,SAAS,CAAC,GAAG,KAAe;gBAC1B,MAAM,SAAS,GAAG,GAAG,CAAC;gBACtB,MAAM,YAAY,GAAG,KAAK,CAAC,GAAG,CAAC,CAAC,IAAI,EAAE,EAAE,CACtC,IAAI,CAAC,OAAO,CAAC,IAAI,EAAE,MAAM,CAAC,CAAC,OAAO,CAAC,SAAS,EAAE,KAAK,SAAS,EAAE,CAAC,CAChE,CAAC;gBACF,OAAO,YAAY,CAAC,IAAI,CAAC,SAAS,CAAC,CAAC;YACtC,CAAC;YACD,cAAc,EAAE,OAAO;YACvB,kBAAkB,EAAE,KAAK,EAAE,QAAQ;YACnC,kBAAkB,EAAE,GAAG,EAAE,aAAa;SACvC,CAAC;IACJ,CAAC,CAAC,CAAC;IAEH,UAAU,CAAC,KAAK,IAAI,EAAE;QACpB,MAAO,wBAAwB,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AAM,CAAC;aACxB,QAAQ,CAAC,WAAW,EAAE,IAAI,CAAC;aAC3B,kBAAkB,EAAE,CAAC;QACxB,MAAM,OAAO,GAAG,eAAe,cAAc,CAAC,KAAK,EAAE,EAAE,CAAC;QACxD,MAAM,SAAS,GAAG,IAAI,GAAG,CAA0C;YACjE,CAAC,OAAO,EAAE,cAAc,CAAC,YAAY,EAAE,CAAC;SACzC,CAAC,CAAC;QACH,MAAM,kBAAkB,CAAC,cAAc,CAAC,SAAS,CAAC,CAAC;QAEnD,MAAM,kBAAkB,CAAC,mBAAmB,CAAC,CAAC,OAAO,CAAC,CAAC,CAAC;QAExD,MAAM,eAAe,GAAG,MAAM,kBAAkB,CAAC,aAAa,CAAC,CAAC,OAAO,CAAC,CAAC,CAAC;QAC1E,MAAM,eAAe,GAAG,eAAe,CAAC,GAAG,CAAC,OAAO,CAAE,CAAC;QACtD,MAAM,CAAC,eAAe,CAAC,MAAM,CAAC,CAAC,IAAI,CAAC,oBAAW,CAAC,IAAI,CAAC,CAAC;IACxD,CAAC,CAAC,CAAC;AACL,CAAC,CAAC,CAAC"}
|
|
@@ -23,7 +23,7 @@ describe(GenericRedisCacher_1.default, () => {
|
|
|
23
23
|
return escapedParts.join(delimiter);
|
|
24
24
|
},
|
|
25
25
|
cacheKeyPrefix: 'test-',
|
|
26
|
-
ttlSecondsPositive: 86400,
|
|
26
|
+
ttlSecondsPositive: 86400, // 1 day
|
|
27
27
|
ttlSecondsNegative: 600, // 10 minutes
|
|
28
28
|
};
|
|
29
29
|
});
|
|
@@ -33,9 +33,7 @@ describe(GenericRedisCacher_1.default, () => {
|
|
|
33
33
|
it('throws when redis is disconnected', async () => {
|
|
34
34
|
redisClient.disconnect();
|
|
35
35
|
const vc1 = new TestViewerContext((0, createRedisIntegrationTestEntityCompanionProvider_1.createRedisIntegrationTestEntityCompanionProvider)(genericRedisCacheContext));
|
|
36
|
-
await expect(RedisTestEntity_1.default.creator(vc1
|
|
37
|
-
.setField('name', 'blah')
|
|
38
|
-
.enforceCreateAsync()).rejects.toThrow(entity_1.EntityCacheAdapterTransientError);
|
|
36
|
+
await expect(RedisTestEntity_1.default.creator(vc1).setField('name', 'blah').enforceCreateAsync()).rejects.toThrow(entity_1.EntityCacheAdapterTransientError);
|
|
39
37
|
});
|
|
40
38
|
});
|
|
41
39
|
//# sourceMappingURL=errors-test.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"errors-test.js","sourceRoot":"","sources":["../../src/__integration-tests__/errors-test.ts"],"names":[],"mappings":";;;;;AAAA,yCAA+E;AAC/E,sDAA4B;AAC5B,6BAA0B;AAE1B,+EAAqF;AACrF,sFAA8D;AAC9D,yIAAsI;AAEtI,MAAM,iBAAkB,SAAQ,sBAAa;CAAG;AAEhD,QAAQ,CAAC,4BAAkB,EAAE,GAAG,EAAE;IAChC,MAAM,WAAW,GAAG,IAAI,iBAAK,CAAC,IAAI,SAAG,CAAC,OAAO,CAAC,GAAG,CAAC,WAAW,CAAE,CAAC,CAAC,QAAQ,EAAE,CAAC,CAAC;IAC7E,IAAI,wBAAkD,CAAC;IAEvD,SAAS,CAAC,GAAG,EAAE;QACb,wBAAwB,GAAG;YACzB,WAAW;YACX,SAAS,CAAC,GAAG,KAAe;gBAC1B,MAAM,SAAS,GAAG,GAAG,CAAC;gBACtB,MAAM,YAAY,GAAG,KAAK,CAAC,GAAG,CAAC,CAAC,IAAI,EAAE,EAAE,CACtC,IAAI,CAAC,OAAO,CAAC,IAAI,EAAE,MAAM,CAAC,CAAC,OAAO,CAAC,SAAS,EAAE,KAAK,SAAS,EAAE,CAAC,CAChE,CAAC;gBACF,OAAO,YAAY,CAAC,IAAI,CAAC,SAAS,CAAC,CAAC;YACtC,CAAC;YACD,cAAc,EAAE,OAAO;YACvB,kBAAkB,EAAE,KAAK;
|
|
1
|
+
{"version":3,"file":"errors-test.js","sourceRoot":"","sources":["../../src/__integration-tests__/errors-test.ts"],"names":[],"mappings":";;;;;AAAA,yCAA+E;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MAAM,CAAC,CAAC,kBAAkB,EAAE,CAC3E,CAAC,OAAO,CAAC,OAAO,CAAC,yCAAgC,CAAC,CAAC;IACtD,CAAC,CAAC,CAAC;AACL,CAAC,CAAC,CAAC"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"wrapNativeRedisCallAsync-test.js","sourceRoot":"","sources":["../../../src/errors/__tests__/wrapNativeRedisCallAsync-test.ts"],"names":[],"mappings":";;;;;AAAA,yCAAgE;AAEhE,2FAAmE;AAEnE,QAAQ,CAAC,kCAAwB,EAAE,GAAG,EAAE;IACtC,EAAE,CAAC,mBAAmB,EAAE,KAAK,IAAI,EAAE;QACjC,MAAM,UAAU,GAAG,KAAK,IAAmB,EAAE;YAC3C,gFAAgF;YAChF,MAAM,OAAO,CAAC;QAChB,CAAC,CAAC;QAEF,IAAI,mBAAwB,CAAC;QAC7B,IAAI;
|
|
1
|
+
{"version":3,"file":"wrapNativeRedisCallAsync-test.js","sourceRoot":"","sources":["../../../src/errors/__tests__/wrapNativeRedisCallAsync-test.ts"],"names":[],"mappings":";;;;;AAAA,yCAAgE;AAEhE,2FAAmE;AAEnE,QAAQ,CAAC,kCAAwB,EAAE,GAAG,EAAE;IACtC,EAAE,CAAC,mBAAmB,EAAE,KAAK,IAAI,EAAE;QACjC,MAAM,UAAU,GAAG,KAAK,IAAmB,EAAE;YAC3C,gFAAgF;YAChF,MAAM,OAAO,CAAC;QAChB,CAAC,CAAC;QAEF,IAAI,mBAAwB,CAAC;QAC7B,IAAI,CAAC;YACH,MAAM,IAAA,kCAAwB,EAAC,UAAU,CAAC,CAAC;QAC7C,CAAC;QAAC,OAAO,CAAC,EAAE,CAAC;YACX,mBAAmB,GAAG,CAAC,CAAC;QAC1B,CAAC;QACD,MAAM,CAAC,mBAAmB,CAAC,CAAC,GAAG,CAAC,cAAc,CAAC,KAAK,CAAC,CAAC;QACtD,MAAM,CAAC,mBAAmB,CAAC,CAAC,OAAO,CAAC,OAAO,CAAC,CAAC;IAC/C,CAAC,CAAC,CAAC;IAEH,EAAE,CAAC,0BAA0B,EAAE,KAAK,IAAI,EAAE;QACxC,MAAM,UAAU,GAAG,KAAK,IAAmB,EAAE;YAC3C,MAAM,CAAC,GAAG,IAAI,KAAK,CAAC,OAAO,CAAC,CAAC;YAC7B,CAAC,CAAC,KAAK,GAAG,OAAO,CAAC;YAClB,MAAM,CAAC,CAAC;QACV,CAAC,CAAC;QAEF,IAAI,mBAAwB,CAAC;QAC7B,IAAI,CAAC;YACH,MAAM,IAAA,kCAAwB,EAAC,UAAU,CAAC,CAAC;QAC7C,CAAC;QAAC,OAAO,CAAC,EAAE,CAAC;YACX,mBAAmB,GAAG,CAAC,CAAC;QAC1B,CAAC;QACD,MAAM,CAAC,mBAAmB,CAAC,CAAC,cAAc,CAAC,yCAAgC,CAAC,CAAC;QAC7E,MAAM,CAAC,mBAAmB,CAAC,OAAO,CAAC,CAAC,OAAO,CAAC,OAAO,CAAC,CAAC;QACrD,MAAM,CAAC,mBAAmB,CAAC,KAAK,CAAC,CAAC,OAAO,CAAC,OAAO,CAAC,CAAC;IACrD,CAAC,CAAC,CAAC;AACL,CAAC,CAAC,CAAC"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"wrapNativeRedisCallAsync.js","sourceRoot":"","sources":["../../src/errors/wrapNativeRedisCallAsync.ts"],"names":[],"mappings":";;AAAA,yCAAgE;AAEjD,KAAK,UAAU,wBAAwB,CAAI,EAAoB;IAC5E,IAAI;
|
|
1
|
+
{"version":3,"file":"wrapNativeRedisCallAsync.js","sourceRoot":"","sources":["../../src/errors/wrapNativeRedisCallAsync.ts"],"names":[],"mappings":";;AAAA,yCAAgE;AAEjD,KAAK,UAAU,wBAAwB,CAAI,EAAoB;IAC5E,IAAI,CAAC;QACH,OAAO,MAAM,EAAE,EAAE,CAAC;IACpB,CAAC;IAAC,OAAO,CAAC,EAAE,CAAC;QACX,IAAI,CAAC,CAAC,CAAC,YAAY,KAAK,CAAC,EAAE,CAAC;YAC1B,MAAM,CAAC,CAAC;QACV,CAAC;QAED,MAAM,KAAK,GAAG,IAAI,yCAAgC,CAAC,CAAC,CAAC,OAAO,EAAE,CAAC,CAAC,CAAC;QACjE,IAAI,CAAC,CAAC,KAAK,EAAE,CAAC;YACZ,KAAK,CAAC,KAAK,GAAG,CAAC,CAAC,KAAK,CAAC;QACxB,CAAC;QACD,MAAM,KAAK,CAAC;IACd,CAAC;AACH,CAAC;AAdD,2CAcC"}
|
|
@@ -13,21 +13,18 @@ class RedisTestEntity extends entity_1.Entity {
|
|
|
13
13
|
}
|
|
14
14
|
exports.default = RedisTestEntity;
|
|
15
15
|
class RedisTestEntityPrivacyPolicy extends entity_1.EntityPrivacyPolicy {
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
new entity_1.AlwaysAllowPrivacyPolicyRule(),
|
|
29
|
-
];
|
|
30
|
-
}
|
|
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
|
+
];
|
|
31
28
|
}
|
|
32
29
|
exports.RedisTestEntityPrivacyPolicy = RedisTestEntityPrivacyPolicy;
|
|
33
30
|
exports.redisTestEntityConfiguration = new entity_1.EntityConfiguration({
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"RedisTestEntity.js","sourceRoot":"","sources":["../../src/testfixtures/RedisTestEntity.ts"],"names":[],"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ACzB,CAAC;KACH;IACD,qBAAqB,EAAE,UAAU;IACjC,kBAAkB,EAAE,OAAO;CAC5B,CAAC,CAAC"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@expo/entity-cache-adapter-redis",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.36.0",
|
|
4
4
|
"description": "Redis cache adapter for @expo/entity",
|
|
5
5
|
"files": [
|
|
6
6
|
"build",
|
|
@@ -31,8 +31,8 @@
|
|
|
31
31
|
"ioredis": ">=5"
|
|
32
32
|
},
|
|
33
33
|
"devDependencies": {
|
|
34
|
-
"@expo/entity": "^0.
|
|
34
|
+
"@expo/entity": "^0.36.0",
|
|
35
35
|
"ioredis": "^5.2.5"
|
|
36
36
|
},
|
|
37
|
-
"gitHead": "
|
|
37
|
+
"gitHead": "f17a33c42874c0d9c46311d19847074ddafeb04e"
|
|
38
38
|
}
|
|
@@ -57,21 +57,23 @@ export interface GenericRedisCacheContext {
|
|
|
57
57
|
ttlSecondsNegative: number;
|
|
58
58
|
}
|
|
59
59
|
|
|
60
|
-
export default class GenericRedisCacher<TFields
|
|
60
|
+
export default class GenericRedisCacher<TFields extends Record<string, any>>
|
|
61
|
+
implements IEntityGenericCacher<TFields>
|
|
62
|
+
{
|
|
61
63
|
constructor(
|
|
62
64
|
private readonly context: GenericRedisCacheContext,
|
|
63
|
-
private readonly entityConfiguration: EntityConfiguration<TFields
|
|
65
|
+
private readonly entityConfiguration: EntityConfiguration<TFields>,
|
|
64
66
|
) {}
|
|
65
67
|
|
|
66
68
|
public async loadManyAsync(
|
|
67
|
-
keys: readonly string[]
|
|
69
|
+
keys: readonly string[],
|
|
68
70
|
): Promise<ReadonlyMap<string, CacheLoadResult<TFields>>> {
|
|
69
71
|
if (keys.length === 0) {
|
|
70
72
|
return new Map();
|
|
71
73
|
}
|
|
72
74
|
|
|
73
75
|
const redisResults = await wrapNativeRedisCallAsync(() =>
|
|
74
|
-
this.context.redisClient.mget(...keys)
|
|
76
|
+
this.context.redisClient.mget(...keys),
|
|
75
77
|
);
|
|
76
78
|
|
|
77
79
|
const results = new Map<string, CacheLoadResult<TFields>>();
|
|
@@ -89,7 +91,7 @@ export default class GenericRedisCacher<TFields> implements IEntityGenericCacher
|
|
|
89
91
|
item: transformCacheObjectToFields(
|
|
90
92
|
this.entityConfiguration,
|
|
91
93
|
redisTransformerMap,
|
|
92
|
-
JSON.parse(redisResult)
|
|
94
|
+
JSON.parse(redisResult),
|
|
93
95
|
),
|
|
94
96
|
});
|
|
95
97
|
} else {
|
|
@@ -111,10 +113,10 @@ export default class GenericRedisCacher<TFields> implements IEntityGenericCacher
|
|
|
111
113
|
redisTransaction = redisTransaction.set(
|
|
112
114
|
key,
|
|
113
115
|
JSON.stringify(
|
|
114
|
-
transformFieldsToCacheObject(this.entityConfiguration, redisTransformerMap, object)
|
|
116
|
+
transformFieldsToCacheObject(this.entityConfiguration, redisTransformerMap, object),
|
|
115
117
|
),
|
|
116
118
|
'EX',
|
|
117
|
-
this.context.ttlSecondsPositive
|
|
119
|
+
this.context.ttlSecondsPositive,
|
|
118
120
|
);
|
|
119
121
|
});
|
|
120
122
|
await wrapNativeRedisCallAsync(() => redisTransaction.exec());
|
|
@@ -131,7 +133,7 @@ export default class GenericRedisCacher<TFields> implements IEntityGenericCacher
|
|
|
131
133
|
key,
|
|
132
134
|
DOES_NOT_EXIST_REDIS,
|
|
133
135
|
'EX',
|
|
134
|
-
this.context.ttlSecondsNegative
|
|
136
|
+
this.context.ttlSecondsNegative,
|
|
135
137
|
);
|
|
136
138
|
});
|
|
137
139
|
await wrapNativeRedisCallAsync(() => redisTransaction.exec());
|
|
@@ -147,7 +149,7 @@ export default class GenericRedisCacher<TFields> implements IEntityGenericCacher
|
|
|
147
149
|
|
|
148
150
|
public makeCacheKey<N extends keyof TFields>(
|
|
149
151
|
fieldName: N,
|
|
150
|
-
fieldValue: NonNullable<TFields[N]
|
|
152
|
+
fieldValue: NonNullable<TFields[N]>,
|
|
151
153
|
): string {
|
|
152
154
|
const columnName = this.entityConfiguration.entityToDBFieldsKeyMapping.get(fieldName);
|
|
153
155
|
invariant(columnName, `database field mapping missing for ${String(fieldName)}`);
|
|
@@ -156,7 +158,7 @@ export default class GenericRedisCacher<TFields> implements IEntityGenericCacher
|
|
|
156
158
|
this.entityConfiguration.tableName,
|
|
157
159
|
`v2.${this.entityConfiguration.cacheKeyVersion}`,
|
|
158
160
|
columnName,
|
|
159
|
-
String(fieldValue)
|
|
161
|
+
String(fieldValue),
|
|
160
162
|
);
|
|
161
163
|
}
|
|
162
164
|
}
|
|
@@ -10,8 +10,8 @@ import GenericRedisCacher, { GenericRedisCacheContext } from './GenericRedisCach
|
|
|
10
10
|
export default class RedisCacheAdapterProvider implements IEntityCacheAdapterProvider {
|
|
11
11
|
constructor(private readonly context: GenericRedisCacheContext) {}
|
|
12
12
|
|
|
13
|
-
getCacheAdapter<TFields
|
|
14
|
-
entityConfiguration: EntityConfiguration<TFields
|
|
13
|
+
getCacheAdapter<TFields extends Record<string, any>>(
|
|
14
|
+
entityConfiguration: EntityConfiguration<TFields>,
|
|
15
15
|
): IEntityCacheAdapter<TFields> {
|
|
16
16
|
return new GenericEntityCacheAdapter(new GenericRedisCacher(this.context, entityConfiguration));
|
|
17
17
|
}
|
|
@@ -19,7 +19,7 @@ class BatchedRedis implements IRedis {
|
|
|
19
19
|
this.batchMgetAsync.bind(this),
|
|
20
20
|
{
|
|
21
21
|
maxBatchInterval: 0,
|
|
22
|
-
}
|
|
22
|
+
},
|
|
23
23
|
);
|
|
24
24
|
|
|
25
25
|
constructor(private readonly redis: Redis) {}
|
|
@@ -40,7 +40,7 @@ class BatchedRedis implements IRedis {
|
|
|
40
40
|
const result = keysToResults.get(key);
|
|
41
41
|
invariant(result !== undefined, 'result should not be undefined');
|
|
42
42
|
return result;
|
|
43
|
-
})
|
|
43
|
+
}),
|
|
44
44
|
);
|
|
45
45
|
}
|
|
46
46
|
|
|
@@ -69,7 +69,7 @@ describe(GenericRedisCacher, () => {
|
|
|
69
69
|
makeKeyFn(...parts: string[]): string {
|
|
70
70
|
const delimiter = ':';
|
|
71
71
|
const escapedParts = parts.map((part) =>
|
|
72
|
-
part.replace('\\', '\\\\').replace(delimiter, `\\${delimiter}`)
|
|
72
|
+
part.replace('\\', '\\\\').replace(delimiter, `\\${delimiter}`),
|
|
73
73
|
);
|
|
74
74
|
return escapedParts.join(delimiter);
|
|
75
75
|
},
|
|
@@ -90,7 +90,7 @@ describe(GenericRedisCacher, () => {
|
|
|
90
90
|
it('has correct caching behavior', async () => {
|
|
91
91
|
// simulate two requests
|
|
92
92
|
const viewerContext = new ViewerContext(
|
|
93
|
-
createRedisIntegrationTestEntityCompanionProvider(genericRedisCacheContext)
|
|
93
|
+
createRedisIntegrationTestEntityCompanionProvider(genericRedisCacheContext),
|
|
94
94
|
);
|
|
95
95
|
|
|
96
96
|
const mgetSpy = jest.spyOn(redis, 'mget');
|
|
@@ -101,41 +101,25 @@ describe(GenericRedisCacher, () => {
|
|
|
101
101
|
]['cacheAdapter']['genericCacher'];
|
|
102
102
|
const cacheKeyMaker = genericCacher['makeCacheKey'].bind(genericCacher);
|
|
103
103
|
|
|
104
|
-
const entity1Created = await RedisTestEntity.creator(
|
|
105
|
-
viewerContext,
|
|
106
|
-
viewerContext.getNonTransactionalQueryContextForDatabaseAdaptorFlavor('postgres')
|
|
107
|
-
)
|
|
104
|
+
const entity1Created = await RedisTestEntity.creator(viewerContext)
|
|
108
105
|
.setField('name', 'blah')
|
|
109
106
|
.enforceCreateAsync();
|
|
110
107
|
|
|
111
108
|
// loading an entity should put it in cache. load by multiple requests and multiple fields in same tick to ensure batch works
|
|
112
109
|
mgetSpy.mockClear();
|
|
113
110
|
const viewerContext1 = new ViewerContext(
|
|
114
|
-
createRedisIntegrationTestEntityCompanionProvider(genericRedisCacheContext)
|
|
111
|
+
createRedisIntegrationTestEntityCompanionProvider(genericRedisCacheContext),
|
|
115
112
|
);
|
|
116
113
|
const viewerContext2 = new ViewerContext(
|
|
117
|
-
createRedisIntegrationTestEntityCompanionProvider(genericRedisCacheContext)
|
|
114
|
+
createRedisIntegrationTestEntityCompanionProvider(genericRedisCacheContext),
|
|
118
115
|
);
|
|
119
116
|
const viewerContext3 = new ViewerContext(
|
|
120
|
-
createRedisIntegrationTestEntityCompanionProvider(genericRedisCacheContext)
|
|
117
|
+
createRedisIntegrationTestEntityCompanionProvider(genericRedisCacheContext),
|
|
121
118
|
);
|
|
122
119
|
const [entity1, entity2, entity3] = await Promise.all([
|
|
123
|
-
RedisTestEntity.loader(
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
)
|
|
127
|
-
.enforcing()
|
|
128
|
-
.loadByIDAsync(entity1Created.getID()),
|
|
129
|
-
RedisTestEntity.loader(
|
|
130
|
-
viewerContext2,
|
|
131
|
-
viewerContext2.getNonTransactionalQueryContextForDatabaseAdaptorFlavor('postgres')
|
|
132
|
-
)
|
|
133
|
-
.enforcing()
|
|
134
|
-
.loadByIDAsync(entity1Created.getID()),
|
|
135
|
-
RedisTestEntity.loader(
|
|
136
|
-
viewerContext3,
|
|
137
|
-
viewerContext3.getNonTransactionalQueryContextForDatabaseAdaptorFlavor('postgres')
|
|
138
|
-
)
|
|
120
|
+
RedisTestEntity.loader(viewerContext1).enforcing().loadByIDAsync(entity1Created.getID()),
|
|
121
|
+
RedisTestEntity.loader(viewerContext2).enforcing().loadByIDAsync(entity1Created.getID()),
|
|
122
|
+
RedisTestEntity.loader(viewerContext3)
|
|
139
123
|
.enforcing()
|
|
140
124
|
.loadByFieldEqualingAsync('name', entity1Created.getField('name')),
|
|
141
125
|
]);
|
|
@@ -154,36 +138,30 @@ describe(GenericRedisCacher, () => {
|
|
|
154
138
|
});
|
|
155
139
|
|
|
156
140
|
const cacheKeyEntity1NameField = cacheKeyMaker('name', entity1Created.getField('name'));
|
|
157
|
-
await RedisTestEntity.loader(
|
|
158
|
-
viewerContext,
|
|
159
|
-
viewerContext.getNonTransactionalQueryContextForDatabaseAdaptorFlavor('postgres')
|
|
160
|
-
)
|
|
141
|
+
await RedisTestEntity.loader(viewerContext)
|
|
161
142
|
.enforcing()
|
|
162
143
|
.loadByFieldEqualingAsync('name', entity1Created.getField('name'));
|
|
163
144
|
await expect(redis.get(cacheKeyEntity1NameField)).resolves.toEqual(cachedJSON);
|
|
164
145
|
|
|
165
146
|
// simulate non existent db fetch, should write negative result ('') to cache
|
|
166
147
|
const nonExistentId = uuidv4();
|
|
167
|
-
const entityNonExistentResult = await RedisTestEntity.loader(
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
).loadByIDAsync(nonExistentId);
|
|
148
|
+
const entityNonExistentResult = await RedisTestEntity.loader(viewerContext)
|
|
149
|
+
.withAuthorizationResults()
|
|
150
|
+
.loadByIDAsync(nonExistentId);
|
|
171
151
|
expect(entityNonExistentResult.ok).toBe(false);
|
|
172
152
|
const cacheKeyNonExistent = cacheKeyMaker('id', nonExistentId);
|
|
173
153
|
const nonExistentCachedValue = await redis.get(cacheKeyNonExistent);
|
|
174
154
|
expect(nonExistentCachedValue).toEqual('');
|
|
175
155
|
// load again through entities framework to ensure it reads negative result
|
|
176
|
-
const entityNonExistentResult2 = await RedisTestEntity.loader(
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
).loadByIDAsync(nonExistentId);
|
|
156
|
+
const entityNonExistentResult2 = await RedisTestEntity.loader(viewerContext)
|
|
157
|
+
.withAuthorizationResults()
|
|
158
|
+
.loadByIDAsync(nonExistentId);
|
|
180
159
|
expect(entityNonExistentResult2.ok).toBe(false);
|
|
181
160
|
|
|
182
161
|
// invalidate from cache to ensure it invalidates correctly in both caches
|
|
183
|
-
await RedisTestEntity.loader(
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
).invalidateFieldsAsync(entity1.getAllFields());
|
|
162
|
+
await RedisTestEntity.loader(viewerContext)
|
|
163
|
+
.utils()
|
|
164
|
+
.invalidateFieldsAsync(entity1.getAllFields());
|
|
187
165
|
await expect(redis.get(cacheKeyEntity1)).resolves.toBeNull();
|
|
188
166
|
await expect(redis.get(cacheKeyEntity1NameField)).resolves.toBeNull();
|
|
189
167
|
});
|
|
@@ -19,7 +19,7 @@ describe(GenericRedisCacher, () => {
|
|
|
19
19
|
makeKeyFn(...parts: string[]): string {
|
|
20
20
|
const delimiter = ':';
|
|
21
21
|
const escapedParts = parts.map((part) =>
|
|
22
|
-
part.replace('\\', '\\\\').replace(delimiter, `\\${delimiter}`)
|
|
22
|
+
part.replace('\\', '\\\\').replace(delimiter, `\\${delimiter}`),
|
|
23
23
|
);
|
|
24
24
|
return escapedParts.join(delimiter);
|
|
25
25
|
},
|
|
@@ -38,7 +38,7 @@ describe(GenericRedisCacher, () => {
|
|
|
38
38
|
|
|
39
39
|
it('has correct caching behavior', async () => {
|
|
40
40
|
const viewerContext = new TestViewerContext(
|
|
41
|
-
createRedisIntegrationTestEntityCompanionProvider(genericRedisCacheContext)
|
|
41
|
+
createRedisIntegrationTestEntityCompanionProvider(genericRedisCacheContext),
|
|
42
42
|
);
|
|
43
43
|
const genericCacher =
|
|
44
44
|
viewerContext.entityCompanionProvider.getCompanionForEntity(RedisTestEntity)[
|
|
@@ -46,23 +46,17 @@ describe(GenericRedisCacher, () => {
|
|
|
46
46
|
]['cacheAdapter']['genericCacher'];
|
|
47
47
|
const cacheKeyMaker = genericCacher['makeCacheKey'].bind(genericCacher);
|
|
48
48
|
|
|
49
|
-
const entity1Created = await RedisTestEntity.creator(
|
|
50
|
-
viewerContext,
|
|
51
|
-
viewerContext.getNonTransactionalQueryContextForDatabaseAdaptorFlavor('postgres')
|
|
52
|
-
)
|
|
49
|
+
const entity1Created = await RedisTestEntity.creator(viewerContext)
|
|
53
50
|
.setField('name', 'blah')
|
|
54
51
|
.enforceCreateAsync();
|
|
55
52
|
|
|
56
53
|
// loading an entity should put it in cache
|
|
57
|
-
const entity1 = await RedisTestEntity.loader(
|
|
58
|
-
viewerContext,
|
|
59
|
-
viewerContext.getNonTransactionalQueryContextForDatabaseAdaptorFlavor('postgres')
|
|
60
|
-
)
|
|
54
|
+
const entity1 = await RedisTestEntity.loader(viewerContext)
|
|
61
55
|
.enforcing()
|
|
62
56
|
.loadByIDAsync(entity1Created.getID());
|
|
63
57
|
|
|
64
58
|
const cachedJSON = await (genericRedisCacheContext.redisClient as Redis).get(
|
|
65
|
-
cacheKeyMaker('id', entity1.getID())
|
|
59
|
+
cacheKeyMaker('id', entity1.getID()),
|
|
66
60
|
);
|
|
67
61
|
const cachedValue = JSON.parse(cachedJSON!);
|
|
68
62
|
expect(cachedValue).toMatchObject({
|
|
@@ -73,99 +67,72 @@ describe(GenericRedisCacher, () => {
|
|
|
73
67
|
// simulate non existent db fetch, should write negative result ('') to cache
|
|
74
68
|
const nonExistentId = uuidv4();
|
|
75
69
|
|
|
76
|
-
const entityNonExistentResult = await RedisTestEntity.loader(
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
).loadByIDAsync(nonExistentId);
|
|
70
|
+
const entityNonExistentResult = await RedisTestEntity.loader(viewerContext)
|
|
71
|
+
.withAuthorizationResults()
|
|
72
|
+
.loadByIDAsync(nonExistentId);
|
|
80
73
|
expect(entityNonExistentResult.ok).toBe(false);
|
|
81
74
|
|
|
82
75
|
const nonExistentCachedValue = await (genericRedisCacheContext.redisClient as Redis).get(
|
|
83
|
-
cacheKeyMaker('id', nonExistentId)
|
|
76
|
+
cacheKeyMaker('id', nonExistentId),
|
|
84
77
|
);
|
|
85
78
|
expect(nonExistentCachedValue).toEqual('');
|
|
86
79
|
|
|
87
80
|
// load again through entities framework to ensure it reads negative result
|
|
88
|
-
const entityNonExistentResult2 = await RedisTestEntity.loader(
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
).loadByIDAsync(nonExistentId);
|
|
81
|
+
const entityNonExistentResult2 = await RedisTestEntity.loader(viewerContext)
|
|
82
|
+
.withAuthorizationResults()
|
|
83
|
+
.loadByIDAsync(nonExistentId);
|
|
92
84
|
expect(entityNonExistentResult2.ok).toBe(false);
|
|
93
85
|
|
|
94
86
|
// invalidate from cache to ensure it invalidates correctly
|
|
95
|
-
await RedisTestEntity.loader(
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
).invalidateFieldsAsync(entity1.getAllFields());
|
|
87
|
+
await RedisTestEntity.loader(viewerContext)
|
|
88
|
+
.utils()
|
|
89
|
+
.invalidateFieldsAsync(entity1.getAllFields());
|
|
99
90
|
const cachedValueNull = await (genericRedisCacheContext.redisClient as Redis).get(
|
|
100
|
-
cacheKeyMaker('id', entity1.getID())
|
|
91
|
+
cacheKeyMaker('id', entity1.getID()),
|
|
101
92
|
);
|
|
102
93
|
expect(cachedValueNull).toBe(null);
|
|
103
94
|
});
|
|
104
95
|
|
|
105
96
|
it('caches and restores date fields', async () => {
|
|
106
97
|
const viewerContext = new TestViewerContext(
|
|
107
|
-
createRedisIntegrationTestEntityCompanionProvider(genericRedisCacheContext)
|
|
98
|
+
createRedisIntegrationTestEntityCompanionProvider(genericRedisCacheContext),
|
|
108
99
|
);
|
|
109
100
|
const date = new Date();
|
|
110
101
|
const entity1 = await enforceAsyncResult(
|
|
111
|
-
RedisTestEntity.creator(
|
|
112
|
-
viewerContext,
|
|
113
|
-
viewerContext.getNonTransactionalQueryContextForDatabaseAdaptorFlavor('postgres')
|
|
114
|
-
)
|
|
115
|
-
.setField('dateField', date)
|
|
116
|
-
.createAsync()
|
|
102
|
+
RedisTestEntity.creator(viewerContext).setField('dateField', date).createAsync(),
|
|
117
103
|
);
|
|
118
104
|
expect(entity1.getField('dateField')).toEqual(date);
|
|
119
105
|
|
|
120
|
-
const entity2 = await RedisTestEntity.loader(
|
|
121
|
-
viewerContext,
|
|
122
|
-
viewerContext.getNonTransactionalQueryContextForDatabaseAdaptorFlavor('postgres')
|
|
123
|
-
)
|
|
106
|
+
const entity2 = await RedisTestEntity.loader(viewerContext)
|
|
124
107
|
.enforcing()
|
|
125
108
|
.loadByIDAsync(entity1.getID());
|
|
126
109
|
expect(entity2.getField('dateField')).toEqual(date);
|
|
127
110
|
|
|
128
111
|
// simulate new request
|
|
129
112
|
const vc2 = new TestViewerContext(
|
|
130
|
-
createRedisIntegrationTestEntityCompanionProvider(genericRedisCacheContext)
|
|
113
|
+
createRedisIntegrationTestEntityCompanionProvider(genericRedisCacheContext),
|
|
131
114
|
);
|
|
132
|
-
const entity3 = await RedisTestEntity.loader(
|
|
133
|
-
vc2,
|
|
134
|
-
vc2.getNonTransactionalQueryContextForDatabaseAdaptorFlavor('postgres')
|
|
135
|
-
)
|
|
136
|
-
.enforcing()
|
|
137
|
-
.loadByIDAsync(entity1.getID());
|
|
115
|
+
const entity3 = await RedisTestEntity.loader(vc2).enforcing().loadByIDAsync(entity1.getID());
|
|
138
116
|
expect(entity3.getField('dateField')).toEqual(date);
|
|
139
117
|
});
|
|
140
118
|
|
|
141
119
|
it('caches and restores empty string field keys', async () => {
|
|
142
120
|
const viewerContext = new TestViewerContext(
|
|
143
|
-
createRedisIntegrationTestEntityCompanionProvider(genericRedisCacheContext)
|
|
121
|
+
createRedisIntegrationTestEntityCompanionProvider(genericRedisCacheContext),
|
|
144
122
|
);
|
|
145
123
|
const entity1 = await enforceAsyncResult(
|
|
146
|
-
RedisTestEntity.creator(
|
|
147
|
-
viewerContext,
|
|
148
|
-
viewerContext.getNonTransactionalQueryContextForDatabaseAdaptorFlavor('postgres')
|
|
149
|
-
)
|
|
150
|
-
.setField('name', '')
|
|
151
|
-
.createAsync()
|
|
124
|
+
RedisTestEntity.creator(viewerContext).setField('name', '').createAsync(),
|
|
152
125
|
);
|
|
153
|
-
const entity2 = await RedisTestEntity.loader(
|
|
154
|
-
viewerContext,
|
|
155
|
-
viewerContext.getNonTransactionalQueryContextForDatabaseAdaptorFlavor('postgres')
|
|
156
|
-
)
|
|
126
|
+
const entity2 = await RedisTestEntity.loader(viewerContext)
|
|
157
127
|
.enforcing()
|
|
158
128
|
.loadByFieldEqualingAsync('name', '');
|
|
159
129
|
expect(entity2?.getID()).toEqual(entity1.getID());
|
|
160
130
|
|
|
161
131
|
// simulate new request
|
|
162
132
|
const vc2 = new TestViewerContext(
|
|
163
|
-
createRedisIntegrationTestEntityCompanionProvider(genericRedisCacheContext)
|
|
133
|
+
createRedisIntegrationTestEntityCompanionProvider(genericRedisCacheContext),
|
|
164
134
|
);
|
|
165
|
-
const entity3 = await RedisTestEntity.loader(
|
|
166
|
-
vc2,
|
|
167
|
-
vc2.getNonTransactionalQueryContextForDatabaseAdaptorFlavor('postgres')
|
|
168
|
-
)
|
|
135
|
+
const entity3 = await RedisTestEntity.loader(vc2)
|
|
169
136
|
.enforcing()
|
|
170
137
|
.loadByFieldEqualingAsync('name', '');
|
|
171
138
|
expect(entity3?.getID()).toEqual(entity1.getID());
|
|
@@ -20,7 +20,7 @@ describe(GenericRedisCacher, () => {
|
|
|
20
20
|
makeKeyFn(...parts: string[]): string {
|
|
21
21
|
const delimiter = ':';
|
|
22
22
|
const escapedParts = parts.map((part) =>
|
|
23
|
-
part.replace('\\', '\\\\').replace(delimiter, `\\${delimiter}`)
|
|
23
|
+
part.replace('\\', '\\\\').replace(delimiter, `\\${delimiter}`),
|
|
24
24
|
);
|
|
25
25
|
return escapedParts.join(delimiter);
|
|
26
26
|
},
|
|
@@ -39,17 +39,14 @@ describe(GenericRedisCacher, () => {
|
|
|
39
39
|
|
|
40
40
|
it('has correct caching and loading behavior', async () => {
|
|
41
41
|
const viewerContext = new TestViewerContext(
|
|
42
|
-
createRedisIntegrationTestEntityCompanionProvider(genericRedisCacheContext)
|
|
42
|
+
createRedisIntegrationTestEntityCompanionProvider(genericRedisCacheContext),
|
|
43
43
|
);
|
|
44
44
|
const genericRedisCacher = new GenericRedisCacher(
|
|
45
45
|
genericRedisCacheContext,
|
|
46
|
-
redisTestEntityConfiguration
|
|
46
|
+
redisTestEntityConfiguration,
|
|
47
47
|
);
|
|
48
48
|
const date = new Date();
|
|
49
|
-
const entity1Created = await RedisTestEntity.creator(
|
|
50
|
-
viewerContext,
|
|
51
|
-
viewerContext.getNonTransactionalQueryContextForDatabaseAdaptorFlavor('postgres')
|
|
52
|
-
)
|
|
49
|
+
const entity1Created = await RedisTestEntity.creator(viewerContext)
|
|
53
50
|
.setField('name', 'blah')
|
|
54
51
|
.setField('dateField', date)
|
|
55
52
|
.enforceCreateAsync();
|
|
@@ -77,7 +74,7 @@ describe(GenericRedisCacher, () => {
|
|
|
77
74
|
it('has correct negative caching behaviour', async () => {
|
|
78
75
|
const genericRedisCacher = new GenericRedisCacher(
|
|
79
76
|
genericRedisCacheContext,
|
|
80
|
-
redisTestEntityConfiguration
|
|
77
|
+
redisTestEntityConfiguration,
|
|
81
78
|
);
|
|
82
79
|
|
|
83
80
|
const testKey = `test-id-key-non-existent-id`;
|
|
@@ -88,17 +85,14 @@ describe(GenericRedisCacher, () => {
|
|
|
88
85
|
});
|
|
89
86
|
it('has correct invalidation behaviour', async () => {
|
|
90
87
|
const viewerContext = new TestViewerContext(
|
|
91
|
-
createRedisIntegrationTestEntityCompanionProvider(genericRedisCacheContext)
|
|
88
|
+
createRedisIntegrationTestEntityCompanionProvider(genericRedisCacheContext),
|
|
92
89
|
);
|
|
93
90
|
const genericRedisCacher = new GenericRedisCacher(
|
|
94
91
|
genericRedisCacheContext,
|
|
95
|
-
redisTestEntityConfiguration
|
|
92
|
+
redisTestEntityConfiguration,
|
|
96
93
|
);
|
|
97
94
|
const date = new Date();
|
|
98
|
-
const entity1Created = await RedisTestEntity.creator(
|
|
99
|
-
viewerContext,
|
|
100
|
-
viewerContext.getNonTransactionalQueryContextForDatabaseAdaptorFlavor('postgres')
|
|
101
|
-
)
|
|
95
|
+
const entity1Created = await RedisTestEntity.creator(viewerContext)
|
|
102
96
|
.setField('name', 'blah')
|
|
103
97
|
.setField('dateField', date)
|
|
104
98
|
.enforceCreateAsync();
|
|
@@ -18,7 +18,7 @@ describe(GenericRedisCacher, () => {
|
|
|
18
18
|
makeKeyFn(...parts: string[]): string {
|
|
19
19
|
const delimiter = ':';
|
|
20
20
|
const escapedParts = parts.map((part) =>
|
|
21
|
-
part.replace('\\', '\\\\').replace(delimiter, `\\${delimiter}`)
|
|
21
|
+
part.replace('\\', '\\\\').replace(delimiter, `\\${delimiter}`),
|
|
22
22
|
);
|
|
23
23
|
return escapedParts.join(delimiter);
|
|
24
24
|
},
|
|
@@ -36,16 +36,11 @@ describe(GenericRedisCacher, () => {
|
|
|
36
36
|
redisClient.disconnect();
|
|
37
37
|
|
|
38
38
|
const vc1 = new TestViewerContext(
|
|
39
|
-
createRedisIntegrationTestEntityCompanionProvider(genericRedisCacheContext)
|
|
39
|
+
createRedisIntegrationTestEntityCompanionProvider(genericRedisCacheContext),
|
|
40
40
|
);
|
|
41
41
|
|
|
42
42
|
await expect(
|
|
43
|
-
RedisTestEntity.creator(
|
|
44
|
-
vc1,
|
|
45
|
-
vc1.getNonTransactionalQueryContextForDatabaseAdaptorFlavor('postgres')
|
|
46
|
-
)
|
|
47
|
-
.setField('name', 'blah')
|
|
48
|
-
.enforceCreateAsync()
|
|
43
|
+
RedisTestEntity.creator(vc1).setField('name', 'blah').enforceCreateAsync(),
|
|
49
44
|
).rejects.toThrow(EntityCacheAdapterTransientError);
|
|
50
45
|
});
|
|
51
46
|
});
|
|
@@ -27,7 +27,7 @@ describe(GenericRedisCacher, () => {
|
|
|
27
27
|
|
|
28
28
|
// need to have one anything() for each element of spread, in this case 3
|
|
29
29
|
when(mockRedisClient.mget(anything(), anything(), anything())).thenCall(async (...keys) =>
|
|
30
|
-
keys.map((k) => redisResults.get(k) ?? null)
|
|
30
|
+
keys.map((k) => redisResults.get(k) ?? null),
|
|
31
31
|
);
|
|
32
32
|
|
|
33
33
|
const genericCacher = new GenericRedisCacher(
|
|
@@ -38,7 +38,7 @@ describe(GenericRedisCacher, () => {
|
|
|
38
38
|
ttlSecondsPositive: 1,
|
|
39
39
|
ttlSecondsNegative: 2,
|
|
40
40
|
},
|
|
41
|
-
entityConfiguration
|
|
41
|
+
entityConfiguration,
|
|
42
42
|
);
|
|
43
43
|
|
|
44
44
|
const cacheKeyWat = genericCacher['makeCacheKey']('id', 'wat');
|
|
@@ -68,7 +68,7 @@ describe(GenericRedisCacher, () => {
|
|
|
68
68
|
ttlSecondsPositive: 1,
|
|
69
69
|
ttlSecondsNegative: 2,
|
|
70
70
|
},
|
|
71
|
-
entityConfiguration
|
|
71
|
+
entityConfiguration,
|
|
72
72
|
);
|
|
73
73
|
const results = await genericCacher.loadManyAsync([]);
|
|
74
74
|
expect(results).toEqual(new Map());
|
|
@@ -84,7 +84,7 @@ describe(GenericRedisCacher, () => {
|
|
|
84
84
|
(key, value, code, ttl) => {
|
|
85
85
|
redisResults.set(key, { value, code, ttl });
|
|
86
86
|
return pipeline;
|
|
87
|
-
}
|
|
87
|
+
},
|
|
88
88
|
);
|
|
89
89
|
when(mockPipeline.exec()).thenResolve({} as any);
|
|
90
90
|
const pipeline = instance(mockPipeline);
|
|
@@ -100,7 +100,7 @@ describe(GenericRedisCacher, () => {
|
|
|
100
100
|
ttlSecondsPositive: 1,
|
|
101
101
|
ttlSecondsNegative: 2,
|
|
102
102
|
},
|
|
103
|
-
entityConfiguration
|
|
103
|
+
entityConfiguration,
|
|
104
104
|
);
|
|
105
105
|
|
|
106
106
|
const cacheKey = genericCacher['makeCacheKey']('id', 'wat');
|
|
@@ -123,7 +123,7 @@ describe(GenericRedisCacher, () => {
|
|
|
123
123
|
(key, value, code, ttl) => {
|
|
124
124
|
redisResults.set(key, { value, code, ttl });
|
|
125
125
|
return pipeline;
|
|
126
|
-
}
|
|
126
|
+
},
|
|
127
127
|
);
|
|
128
128
|
when(mockPipeline.exec()).thenResolve({} as any);
|
|
129
129
|
const pipeline = instance(mockPipeline);
|
|
@@ -139,7 +139,7 @@ describe(GenericRedisCacher, () => {
|
|
|
139
139
|
ttlSecondsPositive: 1,
|
|
140
140
|
ttlSecondsNegative: 2,
|
|
141
141
|
},
|
|
142
|
-
entityConfiguration
|
|
142
|
+
entityConfiguration,
|
|
143
143
|
);
|
|
144
144
|
|
|
145
145
|
const cacheKey = genericCacher['makeCacheKey']('id', 'wat');
|
|
@@ -167,7 +167,7 @@ describe(GenericRedisCacher, () => {
|
|
|
167
167
|
ttlSecondsPositive: 1,
|
|
168
168
|
ttlSecondsNegative: 2,
|
|
169
169
|
},
|
|
170
|
-
entityConfiguration
|
|
170
|
+
entityConfiguration,
|
|
171
171
|
);
|
|
172
172
|
const cacheKey = genericCacher['makeCacheKey']('id', 'wat');
|
|
173
173
|
|
|
@@ -185,7 +185,7 @@ describe(GenericRedisCacher, () => {
|
|
|
185
185
|
ttlSecondsPositive: 1,
|
|
186
186
|
ttlSecondsNegative: 2,
|
|
187
187
|
},
|
|
188
|
-
entityConfiguration
|
|
188
|
+
entityConfiguration,
|
|
189
189
|
);
|
|
190
190
|
await genericCacher.invalidateManyAsync([]);
|
|
191
191
|
});
|
|
@@ -14,7 +14,7 @@ const adapterProvider = new StubDatabaseAdapterProvider();
|
|
|
14
14
|
|
|
15
15
|
export const createRedisIntegrationTestEntityCompanionProvider = (
|
|
16
16
|
genericRedisCacheContext: GenericRedisCacheContext,
|
|
17
|
-
metricsAdapter: IEntityMetricsAdapter = new NoOpEntityMetricsAdapter()
|
|
17
|
+
metricsAdapter: IEntityMetricsAdapter = new NoOpEntityMetricsAdapter(),
|
|
18
18
|
): EntityCompanionProvider => {
|
|
19
19
|
return new EntityCompanionProvider(
|
|
20
20
|
metricsAdapter,
|
|
@@ -34,6 +34,6 @@ export const createRedisIntegrationTestEntityCompanionProvider = (
|
|
|
34
34
|
cacheAdapterProvider: new RedisCacheAdapterProvider(genericRedisCacheContext),
|
|
35
35
|
},
|
|
36
36
|
],
|
|
37
|
-
])
|
|
37
|
+
]),
|
|
38
38
|
);
|
|
39
39
|
};
|