From 5497bf30cbd4aaff34a6032da685876ec55faedf Mon Sep 17 00:00:00 2001 From: Brian Crowell Date: Thu, 21 Feb 2019 22:38:59 -0600 Subject: [PATCH] [pg-copy-streams] New module --- types/pg-copy-streams/index.d.ts | 20 ++++++++++++++++ .../pg-copy-streams/pg-copy-streams-tests.ts | 19 +++++++++++++++ types/pg-copy-streams/tsconfig.json | 23 +++++++++++++++++++ types/pg-copy-streams/tslint.json | 1 + 4 files changed, 63 insertions(+) create mode 100644 types/pg-copy-streams/index.d.ts create mode 100644 types/pg-copy-streams/pg-copy-streams-tests.ts create mode 100644 types/pg-copy-streams/tsconfig.json create mode 100644 types/pg-copy-streams/tslint.json diff --git a/types/pg-copy-streams/index.d.ts b/types/pg-copy-streams/index.d.ts new file mode 100644 index 0000000000..4f468d5639 --- /dev/null +++ b/types/pg-copy-streams/index.d.ts @@ -0,0 +1,20 @@ +// Type definitions for pg-copy-streams 1.2 +// Project: https://github.com/brianc/node-pg-copy-streams +// Definitions by: Brian Crowell +// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped + +/// + +import { Submittable, Connection } from "pg"; +import { Transform, TransformOptions } from "stream"; + +export function from(txt: string, options?: TransformOptions): CopyStreamQuery; +export function to(txt: string, options?: TransformOptions): CopyToStreamQuery; + +export class CopyStreamQuery extends Transform implements Submittable { + submit(connection: Connection): void; +} + +export class CopyToStreamQuery extends Transform implements Submittable { + submit(connection: Connection): void; +} diff --git a/types/pg-copy-streams/pg-copy-streams-tests.ts b/types/pg-copy-streams/pg-copy-streams-tests.ts new file mode 100644 index 0000000000..41d960ab4e --- /dev/null +++ b/types/pg-copy-streams/pg-copy-streams-tests.ts @@ -0,0 +1,19 @@ +import { Client } from "pg"; +import { from, to } from "pg-copy-streams"; + +const client = new Client('fake-config-string'); + +const copyStream = client.query(from('copy data from stdin;')); + +copyStream.write('', err => { + if (err) { + console.error(err); + return; + } + + copyStream.end(); +}); + +const readStream = client.query(to('copy data to stdout;')); + +readStream.pipe(process.stdout); diff --git a/types/pg-copy-streams/tsconfig.json b/types/pg-copy-streams/tsconfig.json new file mode 100644 index 0000000000..6b8989eb58 --- /dev/null +++ b/types/pg-copy-streams/tsconfig.json @@ -0,0 +1,23 @@ +{ + "compilerOptions": { + "module": "commonjs", + "lib": [ + "es6" + ], + "noImplicitAny": true, + "noImplicitThis": true, + "strictNullChecks": true, + "strictFunctionTypes": true, + "baseUrl": "../", + "typeRoots": [ + "../" + ], + "types": [], + "noEmit": true, + "forceConsistentCasingInFileNames": true + }, + "files": [ + "index.d.ts", + "pg-copy-streams-tests.ts" + ] +} \ No newline at end of file diff --git a/types/pg-copy-streams/tslint.json b/types/pg-copy-streams/tslint.json new file mode 100644 index 0000000000..3db14f85ea --- /dev/null +++ b/types/pg-copy-streams/tslint.json @@ -0,0 +1 @@ +{ "extends": "dtslint/dt.json" }