Add types for dexie-batch (#37160)

This commit is contained in:
Florian Keller 2019-08-03 01:09:43 +02:00 committed by Nathan Shively-Sanders
parent 388b2e06bd
commit bb36642c70
5 changed files with 88 additions and 0 deletions

View File

@ -0,0 +1,27 @@
import DexieBatch = require('dexie-batch');
import Dexie from 'dexie';
const db = new Dexie('MyDatabase');
const collection = db.table<string, number>('table').toCollection();
new DexieBatch({ batchSize: 10, limit: 10 }).each(collection, (item, index) => {
item; // $ExpectType string
index; // $ExpectType number
});
new DexieBatch({ batchSize: 10 }).eachBatch(collection, (items, index) => {
items; // $ExpectType string[]
index; // $ExpectType number
});
new DexieBatch({ batchSize: 10 }).eachBatchParallel(collection, (items, index) => {
items; // $ExpectType string[]
index; // $ExpectType number
});
new DexieBatch({ batchSize: 10 }).eachBatchSerial(collection, (items, index) => {
items; // $ExpectType string[]
index; // $ExpectType number
});
new DexieBatch({ batchSize: 10 }).isParallel(); // $ExpectType boolean

30
types/dexie-batch/index.d.ts vendored Normal file
View File

@ -0,0 +1,30 @@
// Type definitions for dexie-batch 0.4
// Project: https://github.com/raphinesse/dexie-batch#readme
// Definitions by: Florian Keller <https://github.com/ffflorian>
// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped
import { Dexie } from 'dexie';
declare namespace DexieBatch {
interface Options {
batchSize: number;
limit?: number;
}
type Callback<T> = (item: T, index: number) => void;
}
declare class DexieBatch {
private readonly opts: DexieBatch.Options;
constructor(opts: DexieBatch.Options);
isParallel(): boolean;
each<T>(collection: Dexie.Collection<T, any>, callback: DexieBatch.Callback<T>): Dexie.Promise<number>;
eachBatch<T>(collection: Dexie.Collection<T, any>, callback: DexieBatch.Callback<T[]>): Dexie.Promise<number>;
eachBatchParallel<T>(collection: Dexie.Collection<T, any>, callback: DexieBatch.Callback<T[]>): Dexie.Promise<number>;
eachBatchSerial<T>(collection: Dexie.Collection<T, any>, callback: DexieBatch.Callback<T[]>, batchIdx?: number): Dexie.Promise<number>;
}
export as namespace DexieBatch;
export = DexieBatch;

View File

@ -0,0 +1,6 @@
{
"private": true,
"dependencies": {
"dexie": "^2.0.0"
}
}

View File

@ -0,0 +1,24 @@
{
"compilerOptions": {
"module": "commonjs",
"lib": [
"dom",
"es6"
],
"noImplicitAny": true,
"noImplicitThis": true,
"strictFunctionTypes": true,
"strictNullChecks": true,
"baseUrl": "../",
"typeRoots": [
"../"
],
"types": [],
"noEmit": true,
"forceConsistentCasingInFileNames": true
},
"files": [
"index.d.ts",
"dexie-batch-tests.ts"
]
}

View File

@ -0,0 +1 @@
{ "extends": "dtslint/dt.json" }