Skip to content

Commit ddd3320

Browse files
authored
Add Typescript declarations for couchimport (#177)
* Add initial types for app.js * Consolidate types into index.d.ts * Add more specific types for delimiters * Add return type for stream import * Rename callback types * Remove auto-generated declaration file * Add EOL newline * Add types to package.json
1 parent 0933148 commit ddd3320

File tree

2 files changed

+51
-0
lines changed

2 files changed

+51
-0
lines changed

package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@
2929
"standard": "^14.3.1"
3030
},
3131
"main": "./app.js",
32+
"types": "./types/index.d.ts",
3233
"bin": {
3334
"couchimport": "bin/couchimport.bin.js",
3435
"couchexport": "bin/couchexport.bin.js"

types/index.d.ts

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
import { Options } from 'csv-parse';
2+
import { Stream, Transform } from 'stream';
3+
4+
declare module couchimport {
5+
type Delimiter = '?' | '\t' | ',';
6+
7+
type ImportCallback = (err: Error, data: { total: number, totalFailed: number }) => void;
8+
type ExportCallback = (err: Error, data: never) => void;
9+
type UrlPreviewCallback = (err: Error, data: any, delimiter: Delimiter) => void;
10+
type StreamPreviewCallback = (err: Error, data: any, delimiter: Delimiter) => void;
11+
12+
export interface Config {
13+
url?: string;
14+
database?: string;
15+
delimiter?: Options['delimiter'];
16+
type?: 'json' | 'jsonl' | 'text';
17+
buffer?: number;
18+
jsonpath?: string;
19+
transform?: (data: any, meta: {}) => any;
20+
meta?: {};
21+
parallelism?: number;
22+
preview?: boolean;
23+
ignorefields?: string[];
24+
overwrite?: boolean;
25+
}
26+
27+
function importStream(rs: Stream, callback: ImportCallback): Transform;
28+
function importStream(rs: Stream, opts: Config, callback: ImportCallback): Transform;
29+
30+
function importFile(filename: string, callback: ImportCallback): Transform;
31+
function importFile(filename: string, opts: Config, callback: ImportCallback): Transform;
32+
33+
function exportStream(ws: Stream, callback: ExportCallback): void;
34+
function exportStream(ws: Stream, opts: Config, callback: ExportCallback): void;
35+
36+
function exportFile(filename: string, callback: ExportCallback): void;
37+
function exportFile(filename: string, opts: Config, callback: ExportCallback): void;
38+
39+
function previewURL(u: string, opts: never, callback: UrlPreviewCallback): void;
40+
41+
function previewStream(rs: Stream, callback: StreamPreviewCallback): void;
42+
function previewStream(rs: Stream, opts: Config, callback: StreamPreviewCallback): void;
43+
44+
function previewCSVFile(filename: string, callback: StreamPreviewCallback): void;
45+
function previewCSVFile(filename: string, opts: Config, callback: StreamPreviewCallback): void;
46+
}
47+
48+
declare module "couchimport" {
49+
export = couchimport;
50+
}

0 commit comments

Comments
 (0)