Skip to content

Commit 136dfa0

Browse files
committed
chore: update flow-bin dependency
In order to support specifying "this" type for a function
1 parent ef6d32f commit 136dfa0

File tree

6 files changed

+25
-21
lines changed

6 files changed

+25
-21
lines changed

Diff for: .flowconfig

-1
Original file line numberDiff line numberDiff line change
@@ -10,5 +10,4 @@
1010
[libs]
1111

1212
[options]
13-
suppress_comment=\\(.\\|\n\\)*\\$FlowExpectError
1413
include_warnings=true

Diff for: package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@
4747
"babel-eslint": "10.0.3",
4848
"coveralls": "3.0.7",
4949
"eslint": "6.6.0",
50-
"flow-bin": "0.112.0",
50+
"flow-bin": "0.167.0",
5151
"jest": "24.9.0",
5252
"sane": "4.1.0"
5353
}

Diff for: src/__tests__/abuse.test.js

+14-13
Original file line numberDiff line numberDiff line change
@@ -13,15 +13,15 @@ describe('Provides descriptive error messages for API abuse', () => {
1313

1414
it('Loader creation requires a function', () => {
1515
expect(() => {
16-
// $FlowExpectError
16+
// $FlowExpectedError[incompatible-call]
1717
new DataLoader(); // eslint-disable-line no-new
1818
}).toThrow(
1919
'DataLoader must be constructed with a function which accepts ' +
2020
'Array<key> and returns Promise<Array<value>>, but got: undefined.'
2121
);
2222

2323
expect(() => {
24-
// $FlowExpectError
24+
// $FlowExpectedError[prop-missing]
2525
new DataLoader({}); // eslint-disable-line no-new
2626
}).toThrow(
2727
'DataLoader must be constructed with a function which accepts ' +
@@ -33,15 +33,15 @@ describe('Provides descriptive error messages for API abuse', () => {
3333
const idLoader = new DataLoader<number, number>(async keys => keys);
3434

3535
expect(() => {
36-
// $FlowExpectError
36+
// $FlowExpectedError[incompatible-call]
3737
idLoader.load();
3838
}).toThrow(
3939
'The loader.load() function must be called with a value, ' +
4040
'but got: undefined.'
4141
);
4242

4343
expect(() => {
44-
// $FlowExpectError
44+
// $FlowExpectedError[incompatible-call]
4545
idLoader.load(null);
4646
}).toThrow(
4747
'The loader.load() function must be called with a value, ' +
@@ -58,15 +58,16 @@ describe('Provides descriptive error messages for API abuse', () => {
5858
const idLoader = new DataLoader<number, number>(async keys => keys);
5959

6060
expect(() => {
61-
// $FlowExpectError
61+
// $FlowExpectedError[incompatible-call]
6262
idLoader.loadMany();
6363
}).toThrow(
6464
'The loader.loadMany() function must be called with Array<key> ' +
6565
'but got: undefined.'
6666
);
6767

6868
expect(() => {
69-
// $FlowExpectError
69+
// $FlowExpectedError[incompatible-call]
70+
// $FlowExpectedError[extra-arg]
7071
idLoader.loadMany(1, 2, 3);
7172
}).toThrow(
7273
'The loader.loadMany() function must be called with Array<key> ' +
@@ -80,7 +81,7 @@ describe('Provides descriptive error messages for API abuse', () => {
8081
});
8182

8283
it('Batch function must return a Promise, not null', async () => {
83-
// $FlowExpectError
84+
// $FlowExpectedError[incompatible-call]
8485
const badLoader = new DataLoader<number, number>(() => null);
8586

8687
let caughtError;
@@ -99,7 +100,7 @@ describe('Provides descriptive error messages for API abuse', () => {
99100

100101
it('Batch function must return a Promise, not a value', async () => {
101102
// Note: this is returning the keys directly, rather than a promise to keys.
102-
// $FlowExpectError
103+
// $FlowExpectedError[incompatible-call]
103104
const badLoader = new DataLoader<number, number>(keys => keys);
104105

105106
let caughtError;
@@ -118,7 +119,7 @@ describe('Provides descriptive error messages for API abuse', () => {
118119

119120
it('Batch function must return a Promise of an Array, not null', async () => {
120121
// Note: this resolves to undefined
121-
// $FlowExpectError
122+
// $FlowExpectedError[incompatible-call]
122123
const badLoader = new DataLoader<number, number>(async () => null);
123124

124125
let caughtError;
@@ -162,9 +163,9 @@ describe('Provides descriptive error messages for API abuse', () => {
162163
}
163164

164165
expect(() => {
165-
// $FlowExpectError
166166
const incompleteMap = new IncompleteMap();
167167
const options = { cacheMap: incompleteMap };
168+
// $FlowExpectedError[incompatible-call]
168169
new DataLoader(async keys => keys, options); // eslint-disable-line no-new
169170
}).toThrow(
170171
'Custom cacheMap missing methods: set, delete, clear'
@@ -173,7 +174,7 @@ describe('Provides descriptive error messages for API abuse', () => {
173174

174175
it('Requires a number for maxBatchSize', () => {
175176
expect(() =>
176-
// $FlowExpectError
177+
// $FlowExpectedError[incompatible-call]
177178
new DataLoader(async keys => keys, { maxBatchSize: null })
178179
).toThrow('maxBatchSize must be a positive number: null');
179180
});
@@ -186,14 +187,14 @@ describe('Provides descriptive error messages for API abuse', () => {
186187

187188
it('Requires a function for cacheKeyFn', () => {
188189
expect(() =>
189-
// $FlowExpectError
190+
// $FlowExpectedError[incompatible-call]
190191
new DataLoader(async keys => keys, { cacheKeyFn: null })
191192
).toThrow('cacheKeyFn must be a function: null');
192193
});
193194

194195
it('Requires a function for batchScheduleFn', () => {
195196
expect(() =>
196-
// $FlowExpectError
197+
// $FlowExpectedError[incompatible-call]
197198
new DataLoader(async keys => keys, { batchScheduleFn: null })
198199
).toThrow('batchScheduleFn must be a function: null');
199200
});

Diff for: src/__tests__/dataloader.test.js

+1
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,7 @@ describe('Primary API', () => {
5050
let that;
5151
const loader = new DataLoader<number, number>(async keys => keys, {
5252
cacheKeyFn(key) {
53+
// $FlowIgnore[object-this-reference]
5354
that = this;
5455
return key;
5556
}

Diff for: src/index.js

+5-2
Original file line numberDiff line numberDiff line change
@@ -24,12 +24,12 @@ export type Options<K, V, C = K> = {
2424
};
2525

2626
// If a custom cache is provided, it must be of this type (a subset of ES6 Map).
27-
export type CacheMap<K, V> = {
27+
export interface CacheMap<K, V> {
2828
get(key: K): V | void;
2929
set(key: K, value: V): any;
3030
delete(key: K): any;
3131
clear(): any;
32-
};
32+
}
3333

3434
/**
3535
* A `DataLoader` creates a public API for loading data from a particular
@@ -303,6 +303,7 @@ function dispatchBatch<K, V>(
303303
var batchPromise = loader._batchLoadFn(batch.keys);
304304

305305
// Assert the expected response from batchLoadFn
306+
// $FlowIgnore[method-unbinding]
306307
if (!batchPromise || typeof batchPromise.then !== 'function') {
307308
return failedDispatch(loader, batch, new TypeError(
308309
'DataLoader must be constructed with a function which accepts ' +
@@ -435,6 +436,7 @@ function getValidCacheMap<K, V, C>(
435436
if (cacheMap !== null) {
436437
var cacheFunctions = [ 'get', 'set', 'delete', 'clear' ];
437438
var missingFunctions = cacheFunctions
439+
// $FlowIgnore[prop-missing]
438440
.filter(fnName => cacheMap && typeof cacheMap[fnName] !== 'function');
439441
if (missingFunctions.length !== 0) {
440442
throw new TypeError(
@@ -452,6 +454,7 @@ function isArrayLike(x: mixed): boolean {
452454
x !== null &&
453455
typeof x.length === 'number' &&
454456
(x.length === 0 ||
457+
// $FlowIgnore[method-unbinding]
455458
(x.length > 0 && Object.prototype.hasOwnProperty.call(x, x.length - 1)))
456459
);
457460
}

Diff for: yarn.lock

+4-4
Original file line numberDiff line numberDiff line change
@@ -2010,10 +2010,10 @@ flatted@^2.0.0:
20102010
resolved "https://registry.yarnpkg.com/flatted/-/flatted-2.0.1.tgz#69e57caa8f0eacbc281d2e2cb458d46fdb449e08"
20112011
integrity sha512-a1hQMktqW9Nmqr5aktAux3JMNqaucxGcjtjWnZLHX7yyPCmlSV3M54nGYbqT8K+0GhF3NBgmJCc3ma+WOgX8Jg==
20122012

2013-
flow-bin@0.112.0:
2014-
version "0.112.0"
2015-
resolved "https://registry.yarnpkg.com/flow-bin/-/flow-bin-0.112.0.tgz#6a21c31937c4a2f23a750056a364c598a95ea216"
2016-
integrity sha512-vdcuKv0UU55vjv0e2EVh1ZxlU+TSNT19SkE+6gT1vYzTKtzYE6dLuAmBIiS3Rg2N9D9HOI6TKSyl53zPtqZLrA==
2013+
flow-bin@0.167.0:
2014+
version "0.167.0"
2015+
resolved "https://registry.yarnpkg.com/flow-bin/-/flow-bin-0.167.0.tgz#65f42d962707b015f6165b2f3536c4a8701fa929"
2016+
integrity sha512-/J64i+BN1Y8xzpdzRsML/Mij/k2G1d0UGUnMBUxN8ALrClPTQOxsOgDlh9wpEzNM/5yY7iu6eQYw8TnLbw6H5Q==
20172017

20182018
for-in@^1.0.2:
20192019
version "1.0.2"

0 commit comments

Comments
 (0)