Skip to content

Commit

Permalink
fix: remove cache and database adaptor flavor enums (#109)
Browse files Browse the repository at this point in the history
  • Loading branch information
wschurman authored Jan 20, 2021
1 parent b7309e1 commit 72a77f8
Show file tree
Hide file tree
Showing 38 changed files with 213 additions and 275 deletions.
2 changes: 1 addition & 1 deletion packages/entity-cache-adapter-redis/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ export const createDefaultEntityCompanionProvider = (
...
},
{
[CacheAdapterFlavor.REDIS]: {
['redis']: {
cacheAdapterProvider: new RedisCacheAdapterProvider(redisCacheAdapterContext),
},
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,4 @@
import {
CacheStatus,
UUIDField,
EntityConfiguration,
DatabaseAdapterFlavor,
CacheAdapterFlavor,
} from '@expo/entity';
import { CacheStatus, UUIDField, EntityConfiguration } from '@expo/entity';
import { Redis, Pipeline } from 'ioredis';
import { mock, when, instance, anything, verify } from 'ts-mockito';

Expand All @@ -20,8 +14,8 @@ const entityConfiguration = new EntityConfiguration<BlahFields>({
schema: {
id: new UUIDField({ columnName: 'id', cache: true }),
},
databaseAdapterFlavor: DatabaseAdapterFlavor.POSTGRES,
cacheAdapterFlavor: CacheAdapterFlavor.REDIS,
databaseAdapterFlavor: 'postgres',
cacheAdapterFlavor: 'redis',
});

describe(RedisCacheAdapter, () => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,6 @@ import {
DateField,
StringField,
EntityConfiguration,
DatabaseAdapterFlavor,
CacheAdapterFlavor,
EntityCompanionDefinition,
Entity,
} from '@expo/entity';
Expand Down Expand Up @@ -85,8 +83,8 @@ export const redisTestEntityConfiguration = new EntityConfiguration<RedisTestEnt
columnName: 'date_field',
}),
},
databaseAdapterFlavor: DatabaseAdapterFlavor.POSTGRES,
cacheAdapterFlavor: CacheAdapterFlavor.REDIS,
databaseAdapterFlavor: 'postgres',
cacheAdapterFlavor: 'redis',
});

const redisTestEntityCompanionDefinition = new EntityCompanionDefinition({
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,6 @@ import {
NoOpEntityMetricsAdapter,
IEntityMetricsAdapter,
EntityCompanionProvider,
CacheAdapterFlavor,
DatabaseAdapterFlavor,
StubQueryContextProvider,
StubDatabaseAdapterProvider,
} from '@expo/entity';
Expand All @@ -17,16 +15,22 @@ export const createRedisIntegrationTestEntityCompanionProvider = (
): EntityCompanionProvider => {
return new EntityCompanionProvider(
metricsAdapter,
{
[DatabaseAdapterFlavor.POSTGRES]: {
adapterProvider: new StubDatabaseAdapterProvider(),
queryContextProvider: StubQueryContextProvider,
},
},
{
[CacheAdapterFlavor.REDIS]: {
cacheAdapterProvider: new RedisCacheAdapterProvider(redisCacheAdapterContext),
},
}
new Map([
[
'postgres',
{
adapterProvider: new StubDatabaseAdapterProvider(),
queryContextProvider: StubQueryContextProvider,
},
],
]),
new Map([
[
'redis',
{
cacheAdapterProvider: new RedisCacheAdapterProvider(redisCacheAdapterContext),
},
],
])
);
};
2 changes: 1 addition & 1 deletion packages/entity-database-adapter-knex/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ export const createDefaultEntityCompanionProvider = (
metricsAdapter,
{
// add the knex database adapter flavor
[DatabaseAdapterFlavor.POSTGRES]: {
['postgres']: {
adapter: PostgresEntityDatabaseAdapter,
queryContextProvider: new PostgresEntityQueryContextProvider(knexInstance),
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ import {
createUnitTestEntityCompanionProvider,
enforceResultsAsync,
ViewerContext,
DatabaseAdapterFlavor,
} from '@expo/entity';
import { enforceAsyncResult } from '@expo/results';
import Knex from 'knex';
Expand Down Expand Up @@ -95,17 +94,14 @@ describe('postgres entity integration', () => {
const errorToThrow = new Error('Intentional error');

await expect(
vc1.runInTransactionForDatabaseAdaptorFlavorAsync(
DatabaseAdapterFlavor.POSTGRES,
async (queryContext) => {
// put another in the DB that will be rolled back due to error thrown
await enforceAsyncResult(
PostgresTestEntity.creator(vc1, queryContext).setField('name', 'hello').createAsync()
);
vc1.runInTransactionForDatabaseAdaptorFlavorAsync('postgres', async (queryContext) => {
// put another in the DB that will be rolled back due to error thrown
await enforceAsyncResult(
PostgresTestEntity.creator(vc1, queryContext).setField('name', 'hello').createAsync()
);

throw errorToThrow;
}
)
throw errorToThrow;
})
).rejects.toEqual(errorToThrow);

const entities = await enforceResultsAsync(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,6 @@ import {
ViewerContext,
StringField,
EntityConfiguration,
DatabaseAdapterFlavor,
CacheAdapterFlavor,
EntityCompanionDefinition,
Entity,
NumberField,
Expand Down Expand Up @@ -168,8 +166,8 @@ export const ErrorsTestEntityConfiguration = new EntityConfiguration<ErrorsTestE
columnName: 'non_existent_column',
}),
},
databaseAdapterFlavor: DatabaseAdapterFlavor.POSTGRES,
cacheAdapterFlavor: CacheAdapterFlavor.REDIS,
databaseAdapterFlavor: 'postgres',
cacheAdapterFlavor: 'redis',
});

const errorsTestEntityCompanionDefinition = new EntityCompanionDefinition({
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,6 @@ import {
ViewerContext,
StringField,
EntityConfiguration,
DatabaseAdapterFlavor,
CacheAdapterFlavor,
EntityCompanionDefinition,
Entity,
NumberField,
Expand Down Expand Up @@ -104,8 +102,8 @@ export const invalidTestEntityConfiguration = new EntityConfiguration<InvalidTes
columnName: 'name',
}),
},
databaseAdapterFlavor: DatabaseAdapterFlavor.POSTGRES,
cacheAdapterFlavor: CacheAdapterFlavor.REDIS,
databaseAdapterFlavor: 'postgres',
cacheAdapterFlavor: 'redis',
});

const invalidTestEntityCompanionDefinition = new EntityCompanionDefinition({
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,6 @@ import {
DateField,
MaybeJSONArrayField,
EntityConfiguration,
DatabaseAdapterFlavor,
CacheAdapterFlavor,
EntityCompanionDefinition,
Entity,
} from '@expo/entity';
Expand Down Expand Up @@ -150,8 +148,8 @@ export const postgresTestEntityConfiguration = new EntityConfiguration<PostgresT
columnName: 'maybe_json_array_field',
}),
},
databaseAdapterFlavor: DatabaseAdapterFlavor.POSTGRES,
cacheAdapterFlavor: CacheAdapterFlavor.REDIS,
databaseAdapterFlavor: 'postgres',
cacheAdapterFlavor: 'redis',
});

const postgresTestEntityCompanionDefinition = new EntityCompanionDefinition({
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,6 @@ import {
UUIDField,
StringField,
EntityConfiguration,
DatabaseAdapterFlavor,
CacheAdapterFlavor,
EntityCompanionDefinition,
Entity,
EntityMutationTrigger,
Expand Down Expand Up @@ -153,8 +151,8 @@ export const postgresTestEntityConfiguration = new EntityConfiguration<
columnName: 'name',
}),
},
databaseAdapterFlavor: DatabaseAdapterFlavor.POSTGRES,
cacheAdapterFlavor: CacheAdapterFlavor.REDIS,
databaseAdapterFlavor: 'postgres',
cacheAdapterFlavor: 'redis',
});

const postgresTestEntityCompanionDefinition = new EntityCompanionDefinition({
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,6 @@ import {
UUIDField,
StringField,
EntityConfiguration,
DatabaseAdapterFlavor,
CacheAdapterFlavor,
EntityCompanionDefinition,
Entity,
EntityMutationTrigger,
Expand Down Expand Up @@ -135,8 +133,8 @@ export const postgresTestEntityConfiguration = new EntityConfiguration<
columnName: 'name',
}),
},
databaseAdapterFlavor: DatabaseAdapterFlavor.POSTGRES,
cacheAdapterFlavor: CacheAdapterFlavor.REDIS,
databaseAdapterFlavor: 'postgres',
cacheAdapterFlavor: 'redis',
});

const postgresTestEntityCompanionDefinition = new EntityCompanionDefinition({
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,6 @@ import {
NoOpEntityMetricsAdapter,
IEntityMetricsAdapter,
EntityCompanionProvider,
CacheAdapterFlavor,
DatabaseAdapterFlavor,
InMemoryFullCacheStubCacheAdapterProvider,
} from '@expo/entity';
import Knex from 'knex';
Expand All @@ -17,16 +15,22 @@ export const createKnexIntegrationTestEntityCompanionProvider = (
): EntityCompanionProvider => {
return new EntityCompanionProvider(
metricsAdapter,
{
[DatabaseAdapterFlavor.POSTGRES]: {
adapterProvider: new PostgresEntityDatabaseAdapterProvider(),
queryContextProvider: new PostgresEntityQueryContextProvider(knex),
},
},
{
[CacheAdapterFlavor.REDIS]: {
cacheAdapterProvider: new InMemoryFullCacheStubCacheAdapterProvider(),
},
}
new Map([
[
'postgres',
{
adapterProvider: new PostgresEntityDatabaseAdapterProvider(),
queryContextProvider: new PostgresEntityQueryContextProvider(knex),
},
],
]),
new Map([
[
'redis',
{
cacheAdapterProvider: new InMemoryFullCacheStubCacheAdapterProvider(),
},
],
])
);
};
38 changes: 21 additions & 17 deletions packages/entity-example/src/data.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,6 @@ import {
NoOpEntityMetricsAdapter,
EntityCompanionProvider,
InMemoryFullCacheStubCacheAdapterProvider,
CacheAdapterFlavor,
DatabaseAdapterFlavor,
} from '@expo/entity';

import { InMemoryDatabaseAdapterProvider } from './adapters/InMemoryDatabaseAdapter';
Expand All @@ -21,20 +19,26 @@ export const createEntityCompanionProvider = (
): EntityCompanionProvider => {
return new EntityCompanionProvider(
metricsAdapter,
{
// An in-memory DB is used for demonstration purposes, but generally this would be
// instantiated with PostgresEntityDatabaseAdapter and PostgresEntityQueryContextProvider
[DatabaseAdapterFlavor.POSTGRES]: {
adapterProvider: new InMemoryDatabaseAdapterProvider(),
queryContextProvider: new InMemoryQueryContextProvider(),
},
},
{
// An in-memory cache is used for demonstration purposes, but generally this would be
// instantiated with a RedisCacheAdapterProvider
[CacheAdapterFlavor.REDIS]: {
cacheAdapterProvider: new InMemoryFullCacheStubCacheAdapterProvider(),
},
}
new Map([
[
'postgres',
// An in-memory DB is used for demonstration purposes, but generally this would be
// instantiated with PostgresEntityDatabaseAdapter and PostgresEntityQueryContextProvider
{
adapterProvider: new InMemoryDatabaseAdapterProvider(),
queryContextProvider: new InMemoryQueryContextProvider(),
},
],
]),
new Map([
[
'redis',
// An in-memory cache is used for demonstration purposes, but generally this would be
// instantiated with a RedisCacheAdapterProvider
{
cacheAdapterProvider: new InMemoryFullCacheStubCacheAdapterProvider(),
},
],
])
);
};
6 changes: 2 additions & 4 deletions packages/entity-example/src/entities/NoteEntity.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,6 @@ import {
EntityCompanionDefinition,
EntityConfiguration,
UUIDField,
DatabaseAdapterFlavor,
CacheAdapterFlavor,
StringField,
} from '@expo/entity';

Expand Down Expand Up @@ -57,8 +55,8 @@ export const noteEntityCompanion = new EntityCompanionDefinition({
columnName: 'body',
}),
},
databaseAdapterFlavor: DatabaseAdapterFlavor.POSTGRES,
cacheAdapterFlavor: CacheAdapterFlavor.REDIS,
databaseAdapterFlavor: 'postgres',
cacheAdapterFlavor: 'redis',
}),
privacyPolicyClass: NotePrivacyPolicy,
});
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,6 @@ import {
Entity,
EntityCompanionDefinition,
EntityConfiguration,
DatabaseAdapterFlavor,
CacheAdapterFlavor,
UUIDField,
} from '@expo/entity';
import { RedisCacheAdapterContext } from '@expo/entity-cache-adapter-redis';
Expand Down Expand Up @@ -70,8 +68,8 @@ const testEntityConfiguration = new EntityConfiguration<TestFields>({
columnName: 'third_string',
}),
},
databaseAdapterFlavor: DatabaseAdapterFlavor.POSTGRES,
cacheAdapterFlavor: CacheAdapterFlavor.REDIS,
databaseAdapterFlavor: 'postgres',
cacheAdapterFlavor: 'redis',
});

const testEntityCompanion = new EntityCompanionDefinition({
Expand Down Expand Up @@ -184,7 +182,7 @@ describe('Entity cache inconsistency', () => {
openBarrier2!();
})(),
viewerContext.runInTransactionForDatabaseAdaptorFlavorAsync(
DatabaseAdapterFlavor.POSTGRES,
'postgres',
async (queryContext) => {
await TestEntity.updater(entity1, queryContext)
.setField('third_string', 'updated')
Expand Down
Loading

0 comments on commit 72a77f8

Please sign in to comment.