diff --git a/types/dexie-batch/dexie-batch-tests.ts b/types/dexie-batch/dexie-batch-tests.ts new file mode 100644 index 0000000000..c1e96169a9 --- /dev/null +++ b/types/dexie-batch/dexie-batch-tests.ts @@ -0,0 +1,27 @@ +import DexieBatch = require('dexie-batch'); +import Dexie from 'dexie'; + +const db = new Dexie('MyDatabase'); +const collection = db.table('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 diff --git a/types/dexie-batch/index.d.ts b/types/dexie-batch/index.d.ts new file mode 100644 index 0000000000..c63d75fb51 --- /dev/null +++ b/types/dexie-batch/index.d.ts @@ -0,0 +1,30 @@ +// Type definitions for dexie-batch 0.4 +// Project: https://github.com/raphinesse/dexie-batch#readme +// Definitions by: Florian Keller +// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped + +import { Dexie } from 'dexie'; + +declare namespace DexieBatch { + interface Options { + batchSize: number; + limit?: number; + } + type Callback = (item: T, index: number) => void; +} + +declare class DexieBatch { + private readonly opts: DexieBatch.Options; + + constructor(opts: DexieBatch.Options); + + isParallel(): boolean; + + each(collection: Dexie.Collection, callback: DexieBatch.Callback): Dexie.Promise; + eachBatch(collection: Dexie.Collection, callback: DexieBatch.Callback): Dexie.Promise; + eachBatchParallel(collection: Dexie.Collection, callback: DexieBatch.Callback): Dexie.Promise; + eachBatchSerial(collection: Dexie.Collection, callback: DexieBatch.Callback, batchIdx?: number): Dexie.Promise; +} + +export as namespace DexieBatch; +export = DexieBatch; diff --git a/types/dexie-batch/package.json b/types/dexie-batch/package.json new file mode 100644 index 0000000000..5e6b66b1ad --- /dev/null +++ b/types/dexie-batch/package.json @@ -0,0 +1,6 @@ +{ + "private": true, + "dependencies": { + "dexie": "^2.0.0" + } +} diff --git a/types/dexie-batch/tsconfig.json b/types/dexie-batch/tsconfig.json new file mode 100644 index 0000000000..fe8525e8f6 --- /dev/null +++ b/types/dexie-batch/tsconfig.json @@ -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" + ] +} diff --git a/types/dexie-batch/tslint.json b/types/dexie-batch/tslint.json new file mode 100644 index 0000000000..3db14f85ea --- /dev/null +++ b/types/dexie-batch/tslint.json @@ -0,0 +1 @@ +{ "extends": "dtslint/dt.json" }