-
Notifications
You must be signed in to change notification settings - Fork 30
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
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
- Loading branch information
1 parent
0933148
commit ddd3320
Showing
2 changed files
with
51 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
import { Options } from 'csv-parse'; | ||
import { Stream, Transform } from 'stream'; | ||
|
||
declare module couchimport { | ||
type Delimiter = '?' | '\t' | ','; | ||
|
||
type ImportCallback = (err: Error, data: { total: number, totalFailed: number }) => void; | ||
type ExportCallback = (err: Error, data: never) => void; | ||
type UrlPreviewCallback = (err: Error, data: any, delimiter: Delimiter) => void; | ||
type StreamPreviewCallback = (err: Error, data: any, delimiter: Delimiter) => void; | ||
|
||
export interface Config { | ||
url?: string; | ||
database?: string; | ||
delimiter?: Options['delimiter']; | ||
type?: 'json' | 'jsonl' | 'text'; | ||
buffer?: number; | ||
jsonpath?: string; | ||
transform?: (data: any, meta: {}) => any; | ||
meta?: {}; | ||
parallelism?: number; | ||
preview?: boolean; | ||
ignorefields?: string[]; | ||
overwrite?: boolean; | ||
} | ||
|
||
function importStream(rs: Stream, callback: ImportCallback): Transform; | ||
function importStream(rs: Stream, opts: Config, callback: ImportCallback): Transform; | ||
|
||
function importFile(filename: string, callback: ImportCallback): Transform; | ||
function importFile(filename: string, opts: Config, callback: ImportCallback): Transform; | ||
|
||
function exportStream(ws: Stream, callback: ExportCallback): void; | ||
function exportStream(ws: Stream, opts: Config, callback: ExportCallback): void; | ||
|
||
function exportFile(filename: string, callback: ExportCallback): void; | ||
function exportFile(filename: string, opts: Config, callback: ExportCallback): void; | ||
|
||
function previewURL(u: string, opts: never, callback: UrlPreviewCallback): void; | ||
|
||
function previewStream(rs: Stream, callback: StreamPreviewCallback): void; | ||
function previewStream(rs: Stream, opts: Config, callback: StreamPreviewCallback): void; | ||
|
||
function previewCSVFile(filename: string, callback: StreamPreviewCallback): void; | ||
function previewCSVFile(filename: string, opts: Config, callback: StreamPreviewCallback): void; | ||
} | ||
|
||
declare module "couchimport" { | ||
export = couchimport; | ||
} |