Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore: upgrade dev dependencies and knex #237

Merged
merged 2 commits into from
Jun 4, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 4 additions & 8 deletions .github/workflows/docs.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,15 +9,11 @@ jobs:
deploy:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- uses: actions/setup-node@v1
- uses: actions/checkout@v4
- uses: actions/setup-node@v4
with:
node-version: 18.x
- name: Cache Node.js modules
uses: actions/cache@v1
with:
path: ${{ github.workspace }}/node_modules
key: ${{ runner.OS }}-node_modules-${{ hashFiles('yarn.lock') }}
cache: yarn
node-version-file: package.json
- run: yarn --frozen-lockfile
- run: yarn typedoc
- name: Deploy
Expand Down
12 changes: 4 additions & 8 deletions .github/workflows/tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,17 +9,13 @@ jobs:
build:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- uses: actions/checkout@v4
with:
ref: ${{ github.event.pull_request.head.sha }}
- uses: actions/setup-node@v1
- uses: actions/setup-node@v4
with:
node-version: 18.x
- name: Cache Node.js modules
uses: actions/cache@v1
with:
path: ${{ github.workspace }}/node_modules
key: ${{ runner.OS }}-node_modules-${{ hashFiles('yarn.lock') }}
cache: yarn
node-version-file: package.json
- run: yarn --frozen-lockfile
- run: yarn lint -- -- --max-warnings=0
- run: yarn test -- -- --coverage
Expand Down
29 changes: 16 additions & 13 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -19,27 +19,27 @@
"@expo/batcher": "^1.0.0",
"@expo/entity": "file:packages/entity",
"@expo/results": "^1.0.0",
"@types/invariant": "^2.2.33",
"@types/jest": "^29.5.2",
"@types/invariant": "^2.2.37",
"@types/jest": "^29.5.12",
"@types/jsbn": "^1.2.29",
"@types/lru-cache": "^5.1.1",
"@types/node": "^16.18.34",
"@types/node": "^20.14.1",
"@types/uuid": "^8.3.0",
"barrelsby": "^2.2.0",
"eslint": "^8.14.0",
"eslint-config-universe": "^11.2.0",
"eslint-plugin-tsdoc": "^0.2.17",
"ioredis": "^5.2.5",
"jest": "^29.1.2",
"eslint": "^8.56.0",
"eslint-config-universe": "^13.0.0",
"eslint-plugin-tsdoc": "^0.3.0",
"ioredis": "^5.4.1",
"jest": "^29.7.0",
"lerna": "^5.4.0",
"lru-cache": "^6.0.0",
"nullthrows": "^1.1.1",
"pg": "8.10.0",
"prettier": "^2.8.8",
"ts-jest": "^29.1.0",
"pg": "8.12.0",
"prettier": "^3.3.0",
"ts-jest": "^29.1.4",
"ts-mockito": "^2.6.1",
"typedoc": "^0.24.8",
"typescript": "^5.1.3",
"typedoc": "^0.25.13",
"typescript": "^5.4.5",
"uuid": "^8.3.0"
},
"dependencies": {
Expand All @@ -50,5 +50,8 @@
"@expo/entity-ip-address-field": "file:packages/entity-ip-address-field",
"@expo/entity-secondary-cache-local-memory": "file:packages/entity-secondary-cache-local-memory",
"@expo/entity-secondary-cache-redis": "file:packages/entity-secondary-cache-redis"
},
"volta": {
"node": "20.14.0"
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -18,11 +18,11 @@ export default class GenericLocalMemoryCacher<TFields extends Record<string, any
{
constructor(
private readonly entityConfiguration: EntityConfiguration<TFields>,
private readonly localMemoryCache: LocalMemoryCache<TFields>
private readonly localMemoryCache: LocalMemoryCache<TFields>,
) {}

static createLRUCache<TFields>(
options: { maxSize?: number; ttlSeconds?: number } = {}
options: { maxSize?: number; ttlSeconds?: number } = {},
): LocalMemoryCache<TFields> {
const DEFAULT_LRU_CACHE_MAX_AGE_SECONDS = 10;
const DEFAULT_LRU_CACHE_SIZE = 10000;
Expand All @@ -42,7 +42,7 @@ export default class GenericLocalMemoryCacher<TFields extends Record<string, any
}

public async loadManyAsync(
keys: readonly string[]
keys: readonly string[],
): Promise<ReadonlyMap<string, CacheLoadResult<TFields>>> {
const cacheResults = new Map<string, CacheLoadResult<TFields>>();
for (const key of keys) {
Expand Down Expand Up @@ -85,7 +85,7 @@ export default class GenericLocalMemoryCacher<TFields extends Record<string, any

public makeCacheKey<N extends keyof TFields>(
fieldName: N,
fieldValue: NonNullable<TFields[N]>
fieldValue: NonNullable<TFields[N]>,
): string {
const columnName = this.entityConfiguration.entityToDBFieldsKeyMapping.get(fieldName);
invariant(columnName, `database field mapping missing for ${String(fieldName)}`);
Expand All @@ -98,7 +98,7 @@ export default class GenericLocalMemoryCacher<TFields extends Record<string, any

const delimiter = ':';
const escapedParts = parts.map((part) =>
part.replace('\\', '\\\\').replace(delimiter, `\\${delimiter}`)
part.replace('\\', '\\\\').replace(delimiter, `\\${delimiter}`),
);
return escapedParts.join(delimiter);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,34 +18,34 @@ export default class LocalMemoryCacheAdapterProvider implements IEntityCacheAdap
*/
static createNoOpProvider(): IEntityCacheAdapterProvider {
return new LocalMemoryCacheAdapterProvider(<TFields>() =>
GenericLocalMemoryCacher.createNoOpCache<TFields>()
GenericLocalMemoryCacher.createNoOpCache<TFields>(),
);
}

/**
* @returns a local memory cache adapter provider configured with the supplied options.
*/
static createProviderWithOptions(
options: { maxSize?: number; ttlSeconds?: number } = {}
options: { maxSize?: number; ttlSeconds?: number } = {},
): IEntityCacheAdapterProvider {
return new LocalMemoryCacheAdapterProvider(<TFields>() =>
GenericLocalMemoryCacher.createLRUCache<TFields>(options)
GenericLocalMemoryCacher.createLRUCache<TFields>(options),
);
}

private localMemoryCacheAdapterMap = new Map<string, GenericEntityCacheAdapter<any>>();

private constructor(
private readonly localMemoryCacheCreator: <TFields>() => LocalMemoryCache<TFields>
private readonly localMemoryCacheCreator: <TFields>() => LocalMemoryCache<TFields>,
) {}

public getCacheAdapter<TFields extends Record<string, any>>(
entityConfiguration: EntityConfiguration<TFields>
entityConfiguration: EntityConfiguration<TFields>,
): IEntityCacheAdapter<TFields> {
return computeIfAbsent(this.localMemoryCacheAdapterMap, entityConfiguration.tableName, () => {
const localMemoryCache = this.localMemoryCacheCreator<TFields>();
return new GenericEntityCacheAdapter(
new GenericLocalMemoryCacher(entityConfiguration, localMemoryCache)
new GenericLocalMemoryCacher(entityConfiguration, localMemoryCache),
);
});
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ describe(GenericLocalMemoryCacher, () => {
'localMemoryCacheAdapterMap'
].get(
viewerContext.entityCompanionProvider.getCompanionForEntity(LocalMemoryTestEntity)
.entityCompanionDefinition.entityConfiguration.tableName
.entityCompanionDefinition.entityConfiguration.tableName,
)!['genericCacher'];
const cachedResult = await entitySpecificGenericCacher.loadManyAsync([
cacheKeyMaker('id', entity1.getID()),
Expand All @@ -63,9 +63,8 @@ describe(GenericLocalMemoryCacher, () => {
// simulate non existent db fetch, should write negative result ('') to cache
const nonExistentId = uuidv4();

const entityNonExistentResult = await LocalMemoryTestEntity.loader(viewerContext).loadByIDAsync(
nonExistentId
);
const entityNonExistentResult =
await LocalMemoryTestEntity.loader(viewerContext).loadByIDAsync(nonExistentId);
expect(entityNonExistentResult.ok).toBe(false);

const nonExistentCachedResult = await entitySpecificGenericCacher.loadManyAsync([
Expand All @@ -76,9 +75,8 @@ describe(GenericLocalMemoryCacher, () => {
});

// load again through entities framework to ensure it reads negative result
const entityNonExistentResult2 = await LocalMemoryTestEntity.loader(
viewerContext
).loadByIDAsync(nonExistentId);
const entityNonExistentResult2 =
await LocalMemoryTestEntity.loader(viewerContext).loadByIDAsync(nonExistentId);
expect(entityNonExistentResult2.ok).toBe(false);

// invalidate from cache to ensure it invalidates correctly
Expand Down Expand Up @@ -120,7 +118,7 @@ describe(GenericLocalMemoryCacher, () => {
'localMemoryCacheAdapterMap'
].get(
viewerContext.entityCompanionProvider.getCompanionForEntity(LocalMemoryTestEntity)
.entityCompanionDefinition.entityConfiguration.tableName
.entityCompanionDefinition.entityConfiguration.tableName,
)!['genericCacher'];
const cachedResult = await entitySpecificGenericCacher.loadManyAsync([
cacheKeyMaker('id', entity1.getID()),
Expand All @@ -133,9 +131,8 @@ describe(GenericLocalMemoryCacher, () => {
// a non existent db fetch should try to write negative result ('') but it's a noop cache, so it should be a miss
const nonExistentId = uuidv4();

const entityNonExistentResult = await LocalMemoryTestEntity.loader(viewerContext).loadByIDAsync(
nonExistentId
);
const entityNonExistentResult =
await LocalMemoryTestEntity.loader(viewerContext).loadByIDAsync(nonExistentId);
expect(entityNonExistentResult.ok).toBe(false);

const nonExistentCachedResult = await entitySpecificGenericCacher.loadManyAsync([
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,10 @@ describe('Use within GenericEntityCacheAdapter', () => {
describe('loadManyAsync', () => {
it('returns appropriate cache results', async () => {
const cacheAdapter = new GenericEntityCacheAdapter(
new GenericLocalMemoryCacher(entityConfiguration, GenericLocalMemoryCacher.createLRUCache())
new GenericLocalMemoryCacher(
entityConfiguration,
GenericLocalMemoryCacher.createLRUCache(),
),
);

const cacheHits = new Map<string, Readonly<BlahFields>>([['test-id-1', { id: 'test-id-1' }]]);
Expand All @@ -78,7 +81,10 @@ describe('Use within GenericEntityCacheAdapter', () => {

it('returns empty map when passed empty array of fieldValues', async () => {
const cacheAdapter = new GenericEntityCacheAdapter(
new GenericLocalMemoryCacher(entityConfiguration, GenericLocalMemoryCacher.createLRUCache())
new GenericLocalMemoryCacher(
entityConfiguration,
GenericLocalMemoryCacher.createLRUCache(),
),
);
const results = await cacheAdapter.loadManyAsync('id', []);
expect(results).toEqual(new Map());
Expand Down Expand Up @@ -118,7 +124,7 @@ describe('Use within GenericEntityCacheAdapter', () => {
const localMemoryCache = GenericLocalMemoryCacher.createLRUCache<BlahFields>({});

const cacheAdapter = new GenericEntityCacheAdapter(
new GenericLocalMemoryCacher(entityConfiguration, localMemoryCache)
new GenericLocalMemoryCacher(entityConfiguration, localMemoryCache),
);
await cacheAdapter.cacheManyAsync('id', new Map([['test-id-1', { id: 'test-id-1' }]]));
await cacheAdapter.cacheDBMissesAsync('id', ['test-id-2']);
Expand All @@ -133,8 +139,8 @@ describe('Use within GenericEntityCacheAdapter', () => {
const cacheAdapter = new GenericEntityCacheAdapter(
new GenericLocalMemoryCacher(
entityConfiguration,
GenericLocalMemoryCacher.createLRUCache<BlahFields>({})
)
GenericLocalMemoryCacher.createLRUCache<BlahFields>({}),
),
);
await cacheAdapter.invalidateManyAsync('id', []);
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import LocalMemoryCacheAdapterProvider from '../LocalMemoryCacheAdapterProvider'

export const createLocalMemoryTestEntityCompanionProvider = (
localMemoryOptions: { maxSize?: number; ttlSeconds?: number } = {},
metricsAdapter: IEntityMetricsAdapter = new NoOpEntityMetricsAdapter()
metricsAdapter: IEntityMetricsAdapter = new NoOpEntityMetricsAdapter(),
): EntityCompanionProvider => {
const localMemoryCacheAdapterProvider =
localMemoryOptions.maxSize === 0 && localMemoryOptions.ttlSeconds === 0
Expand All @@ -34,15 +34,15 @@ export const createLocalMemoryTestEntityCompanionProvider = (
cacheAdapterProvider: localMemoryCacheAdapterProvider,
},
],
])
]),
);
};

export const createNoOpLocalMemoryIntegrationTestEntityCompanionProvider = (
metricsAdapter: IEntityMetricsAdapter = new NoOpEntityMetricsAdapter()
metricsAdapter: IEntityMetricsAdapter = new NoOpEntityMetricsAdapter(),
): EntityCompanionProvider => {
return createLocalMemoryTestEntityCompanionProvider(
{ maxSize: 0, ttlSeconds: 0 },
metricsAdapter
metricsAdapter,
);
};
18 changes: 9 additions & 9 deletions packages/entity-cache-adapter-redis/src/GenericRedisCacher.ts
Original file line number Diff line number Diff line change
Expand Up @@ -62,18 +62,18 @@ export default class GenericRedisCacher<TFields extends Record<string, any>>
{
constructor(
private readonly context: GenericRedisCacheContext,
private readonly entityConfiguration: EntityConfiguration<TFields>
private readonly entityConfiguration: EntityConfiguration<TFields>,
) {}

public async loadManyAsync(
keys: readonly string[]
keys: readonly string[],
): Promise<ReadonlyMap<string, CacheLoadResult<TFields>>> {
if (keys.length === 0) {
return new Map();
}

const redisResults = await wrapNativeRedisCallAsync(() =>
this.context.redisClient.mget(...keys)
this.context.redisClient.mget(...keys),
);

const results = new Map<string, CacheLoadResult<TFields>>();
Expand All @@ -91,7 +91,7 @@ export default class GenericRedisCacher<TFields extends Record<string, any>>
item: transformCacheObjectToFields(
this.entityConfiguration,
redisTransformerMap,
JSON.parse(redisResult)
JSON.parse(redisResult),
),
});
} else {
Expand All @@ -113,10 +113,10 @@ export default class GenericRedisCacher<TFields extends Record<string, any>>
redisTransaction = redisTransaction.set(
key,
JSON.stringify(
transformFieldsToCacheObject(this.entityConfiguration, redisTransformerMap, object)
transformFieldsToCacheObject(this.entityConfiguration, redisTransformerMap, object),
),
'EX',
this.context.ttlSecondsPositive
this.context.ttlSecondsPositive,
);
});
await wrapNativeRedisCallAsync(() => redisTransaction.exec());
Expand All @@ -133,7 +133,7 @@ export default class GenericRedisCacher<TFields extends Record<string, any>>
key,
DOES_NOT_EXIST_REDIS,
'EX',
this.context.ttlSecondsNegative
this.context.ttlSecondsNegative,
);
});
await wrapNativeRedisCallAsync(() => redisTransaction.exec());
Expand All @@ -149,7 +149,7 @@ export default class GenericRedisCacher<TFields extends Record<string, any>>

public makeCacheKey<N extends keyof TFields>(
fieldName: N,
fieldValue: NonNullable<TFields[N]>
fieldValue: NonNullable<TFields[N]>,
): string {
const columnName = this.entityConfiguration.entityToDBFieldsKeyMapping.get(fieldName);
invariant(columnName, `database field mapping missing for ${String(fieldName)}`);
Expand All @@ -158,7 +158,7 @@ export default class GenericRedisCacher<TFields extends Record<string, any>>
this.entityConfiguration.tableName,
`v2.${this.entityConfiguration.cacheKeyVersion}`,
columnName,
String(fieldValue)
String(fieldValue),
);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ export default class RedisCacheAdapterProvider implements IEntityCacheAdapterPro
constructor(private readonly context: GenericRedisCacheContext) {}

getCacheAdapter<TFields extends Record<string, any>>(
entityConfiguration: EntityConfiguration<TFields>
entityConfiguration: EntityConfiguration<TFields>,
): IEntityCacheAdapter<TFields> {
return new GenericEntityCacheAdapter(new GenericRedisCacher(this.context, entityConfiguration));
}
Expand Down
Loading
Loading