Skip to content

Commit

Permalink
fix lint errors
Browse files Browse the repository at this point in the history
  • Loading branch information
ForbesLindesay committed Jan 12, 2024
1 parent c1919e1 commit 94be291
Show file tree
Hide file tree
Showing 8 changed files with 29 additions and 12 deletions.
1 change: 0 additions & 1 deletion packages/dataloader/src/__tests__/MultiKeyMap.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,6 @@ test('twoLevels', () => {
expect(cache.get([1, 3])).toBe(undefined);
expect(cache.get([3, 1])).toBe(undefined);

debugger;
cache.delete([1, 1]);
expect(cache.size).toBe(3);
expect(cache.get([1, 1])).toBe(undefined);
Expand Down
20 changes: 14 additions & 6 deletions packages/dataloader/src/__tests__/dedupeAsync.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -42,8 +42,8 @@ test('dedupeAsync', async () => {
).toEqual([{source: 'hello'}, {source: 'world'}, 'Errored', undefined]);
});

expect(load.cache.get('hello')).resolves.toEqual({source: 'hello'});
expect(load.cache.get('world')).resolves.toEqual({source: 'world'});
await expect(load.cache.get('hello')).resolves.toEqual({source: 'hello'});
await expect(load.cache.get('world')).resolves.toEqual({source: 'world'});

load.cache.delete('hello');
load.cache.set('world', {source: 'from set'});
Expand Down Expand Up @@ -107,8 +107,12 @@ test('dedupeAsync - mapKey', async () => {
).toEqual([{source: 'hello'}, {source: 'world'}, 'Errored']);
});

expect(load.cache.get({id: 'hello'})).resolves.toEqual({source: 'hello'});
expect(load.cache.get({id: 'world'})).resolves.toEqual({source: 'world'});
await expect(load.cache.get({id: 'hello'})).resolves.toEqual({
source: 'hello',
});
await expect(load.cache.get({id: 'world'})).resolves.toEqual({
source: 'world',
});

load.cache.delete({id: 'hello'});
load.cache.set({id: 'world'}, {source: 'from set'});
Expand Down Expand Up @@ -219,8 +223,12 @@ test('dedupeAsync - WeakMap', async () => {
).toEqual([{source: 'hello'}, {source: 'world'}, 'Errored']);
});

expect(load.cache.get(HELLO_REQUEST)).resolves.toEqual({source: 'hello'});
expect(load.cache.get(WORLD_REQUEST)).resolves.toEqual({source: 'world'});
await expect(load.cache.get(HELLO_REQUEST)).resolves.toEqual({
source: 'hello',
});
await expect(load.cache.get(WORLD_REQUEST)).resolves.toEqual({
source: 'world',
});

load.cache.delete(HELLO_REQUEST);
load.cache.set(WORLD_REQUEST, {source: 'from set'});
Expand Down
1 change: 1 addition & 0 deletions packages/dataloader/src/__tests__/groupToMap.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ test('groupToMap', () => {
});

test('groupToMap - sparse array', () => {
/* tslint:disable:no-sparse-arrays*/
const result = groupBy([1, , 3], (x) => x);
expect(result(undefined)).toEqual([undefined]);
expect(result(1)).toEqual([1]);
Expand Down
1 change: 1 addition & 0 deletions packages/dataloader/src/__tests__/requestsTester.ts
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ export default function requestsTester<T>(): RequestsTester<T> {

requests = null;
};
/* tslint:disable:no-unbound-method */
if (fnResult && typeof fnResult.then === 'function') {
return fnResult.then(afterFn);
} else {
Expand Down
10 changes: 7 additions & 3 deletions packages/dataloader/src/batch.ts
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ class Batch<TKey, TResult> {
return this._requests.length;
}

loadOne(key: TKey): Promise<TResult> {
async loadOne(key: TKey): Promise<TResult> {
return new Promise<TResult>((resolve, reject) => {
if (this._started) {
reject(
Expand Down Expand Up @@ -93,10 +93,11 @@ export default function batch<TKey, TResult>(
): (key: TKey) => Promise<TResult> {
const {maxBatchSize, batchScheduleFn} = normalizeBatchOptions(options);
let batch: Batch<TKey, TResult> | null = null;
return (key: TKey): Promise<TResult> => {
return async (key: TKey): Promise<TResult> => {
if (batch === null) {
const newBatch = new Batch<TKey, TResult>(load);
batch = newBatch;
/* tslint:disable:no-floating-promises */
batchScheduleFn().then(() => {
if (batch === newBatch) {
newBatch.processBatch();
Expand Down Expand Up @@ -185,7 +186,10 @@ export function batchGroups<
options,
);

const batchedFunction = (group: TGroupKey, key: TKey): Promise<TResult> => {
const batchedFunction = async (
group: TGroupKey,
key: TKey,
): Promise<TResult> => {
const groupKey = mapGroupKey(group);
let batch = groupMap.get(groupKey);
if (batch === undefined) {
Expand Down
2 changes: 1 addition & 1 deletion packages/dataloader/src/dedupeAsync.ts
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ export default function dedupeAsync<TKey, TResult, TMappedKey = TKey>(
): DedupedAsyncFunction<TKey, TResult> {
const {cache, mapKey, shouldCache} = normalizeDedupeAsyncOptions(options);
return Object.assign(
(key: TKey): Promise<TResult> => {
async (key: TKey): Promise<TResult> => {
const cacheKey = mapKey(key);
const cached = cache.get(cacheKey);
if (cached !== undefined) return cached;
Expand Down
4 changes: 3 additions & 1 deletion packages/dataloader/src/dedupeSync.ts
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,9 @@ interface NormalizedDedupeSyncOptions<TKey, TResult, TMappedKey> {
}
const identityFn = <T>(arg: T): T => arg;
const trueFn = (): true => true;
const noop = () => {};
const noop = () => {
// noop
};
function normalizeDedupeSyncOptions<TKey, TResult, TMappedKey>(
options?: DedupeSyncOptions<TKey, TResult, TMappedKey>,
): NormalizedDedupeSyncOptions<TKey, TResult, TMappedKey> {
Expand Down
2 changes: 2 additions & 0 deletions packages/dataloader/src/enqueuePostPromiseJob.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
/* tslint:disable */

// This helper was adapted from Facebook's dataloader:
// https://github.com/graphql/dataloader/blob/249b2b966a8807c50e07746ff04acb8c48fa4357/src/index.js#L206-L245

Expand Down

0 comments on commit 94be291

Please sign in to comment.