From ff15cff4ddcd0fd895f65f89ebeac084536094a4 Mon Sep 17 00:00:00 2001 From: Kavan Shaban Date: Sat, 13 May 2017 07:53:46 -0400 Subject: [PATCH] Initial release --- .gitignore | 37 +++++++ README.md | 27 +++++ index.d.ts | 305 +++++++++++++++++++++++++++++++++++++++++++++++++++ package.json | 32 ++++++ 4 files changed, 401 insertions(+) create mode 100644 .gitignore create mode 100644 README.md create mode 100644 index.d.ts create mode 100644 package.json diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..5148e52 --- /dev/null +++ b/.gitignore @@ -0,0 +1,37 @@ +# Logs +logs +*.log +npm-debug.log* + +# Runtime data +pids +*.pid +*.seed + +# Directory for instrumented libs generated by jscoverage/JSCover +lib-cov + +# Coverage directory used by tools like istanbul +coverage + +# nyc test coverage +.nyc_output + +# Grunt intermediate storage (http://gruntjs.com/creating-plugins#storing-task-files) +.grunt + +# node-waf configuration +.lock-wscript + +# Compiled binary addons (http://nodejs.org/api/addons.html) +build/Release + +# Dependency directories +node_modules +jspm_packages + +# Optional npm cache directory +.npm + +# Optional REPL history +.node_repl_history diff --git a/README.md b/README.md new file mode 100644 index 0000000..57b832b --- /dev/null +++ b/README.md @@ -0,0 +1,27 @@ +# Installation + +> First, run `npm install --save @cw-types/mssql` + + +>Then, you must add `node_modules/@cw-types` to your `tsconifg.json` file, like so: +```javascript + "typeRoots": [ + "node_modules/@cw-types", + "node_modules/@types" + ] +``` +> This will enable the Typescript compiler to find and use this typing since it is not installed under `node_modules/@types`. + +> Please note the order is important of the entries in `typeRoots`. If you want `node_modules/@types` to resolve first then move it up top. + +# Summary + Typescript typings for `mssql` `4.0.4` that support bluebird. + + This package contains type definitions for [mssql](https://github.com/patriksimek/node-mssql). + + +# Credits +Starting definitions were written by COLSA Corporation , Ben Farr , Vitor Buzinaro , Matt Richardson , Jørgen Elgaard Larsen , Peter Keuter . + +# Maintainers +This project is mainted by [Kavan J. Shaban](https://github.com/kavanshaban) at [Cycloware](https://github.com/cycloware) diff --git a/index.d.ts b/index.d.ts new file mode 100644 index 0000000..5ae6393 --- /dev/null +++ b/index.d.ts @@ -0,0 +1,305 @@ +/** + * Modified type definitions for `mssql` + * that support `bluebird` + */ + +// Type definitions for mssql 4.0.1 +// Project: https://www.npmjs.com/package/mssql +// Definitions by: COLSA Corporation , Ben Farr , Vitor Buzinaro , Matt Richardson , Jørgen Elgaard Larsen , Peter Keuter +// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped + +/// +/// + +import events = require('events'); +import * as Promise from 'bluebird'; + +export interface ISqlType { + type: ISqlTypeFactory; +} +export interface ISqlTypeWithNoParams extends ISqlType { type: ISqlTypeFactoryWithNoParams } +export interface ISqlTypeWithLength extends ISqlType { type: ISqlTypeFactoryWithLength; length: number } +export interface ISqlTypeWithScale extends ISqlType { type: ISqlTypeFactoryWithScale; scale: number } +export interface ISqlTypeWithPrecisionScale extends ISqlType { type: ISqlTypeFactoryWithPrecisionScale; precision: number, scale: number } +export interface ISqlTypeWithTvpType extends ISqlType { type: ISqlTypeFactoryWithTvpType; tvpType: any } + +export interface ISqlTypeFactory { +} +export interface ISqlTypeFactoryWithNoParams extends ISqlTypeFactory { (): ISqlTypeWithNoParams; } +export interface ISqlTypeFactoryWithLength extends ISqlTypeFactory { (length?: number): ISqlTypeWithLength } +export interface ISqlTypeFactoryWithScale extends ISqlTypeFactory { (scale?: number): ISqlTypeWithScale } +export interface ISqlTypeFactoryWithPrecisionScale extends ISqlTypeFactory { (precision?: number, scale?: number): ISqlTypeWithPrecisionScale; } +export interface ISqlTypeFactoryWithTvpType extends ISqlTypeFactory { (tvpType: any): ISqlTypeWithTvpType } + + +export declare var VarChar: ISqlTypeFactoryWithLength; +export declare var NVarChar: ISqlTypeFactoryWithLength; +export declare var Text: ISqlTypeFactoryWithNoParams; +export declare var Int: ISqlTypeFactoryWithNoParams; +export declare var BigInt: ISqlTypeFactoryWithNoParams; +export declare var TinyInt: ISqlTypeFactoryWithNoParams; +export declare var SmallInt: ISqlTypeFactoryWithNoParams; +export declare var Bit: ISqlTypeFactoryWithNoParams; +export declare var Float: ISqlTypeFactoryWithNoParams; +export declare var Numeric: ISqlTypeFactoryWithPrecisionScale; +export declare var Decimal: ISqlTypeFactoryWithPrecisionScale; +export declare var Real: ISqlTypeFactoryWithNoParams; +export declare var Date: ISqlTypeFactoryWithNoParams; +export declare var DateTime: ISqlTypeFactoryWithNoParams; +export declare var DateTime2: ISqlTypeFactoryWithScale; +export declare var DateTimeOffset: ISqlTypeFactoryWithScale; +export declare var SmallDateTime: ISqlTypeFactoryWithNoParams; +export declare var Time: ISqlTypeFactoryWithScale; +export declare var UniqueIdentifier: ISqlTypeFactoryWithNoParams; +export declare var SmallMoney: ISqlTypeFactoryWithNoParams; +export declare var Money: ISqlTypeFactoryWithNoParams; +export declare var Binary: ISqlTypeFactoryWithNoParams; +export declare var VarBinary: ISqlTypeFactoryWithLength; +export declare var Image: ISqlTypeFactoryWithNoParams; +export declare var Xml: ISqlTypeFactoryWithNoParams; +export declare var Char: ISqlTypeFactoryWithLength; +export declare var NChar: ISqlTypeFactoryWithLength; +export declare var NText: ISqlTypeFactoryWithNoParams; +export declare var TVP: ISqlTypeFactoryWithTvpType; +export declare var UDT: ISqlTypeFactoryWithNoParams; +export declare var Geography: ISqlTypeFactoryWithNoParams; +export declare var Geometry: ISqlTypeFactoryWithNoParams; + +export declare var TYPES: { + VarChar: ISqlTypeFactoryWithLength; + NVarChar: ISqlTypeFactoryWithLength; + Text: ISqlTypeFactoryWithNoParams; + Int: ISqlTypeFactoryWithNoParams; + BigInt: ISqlTypeFactoryWithNoParams; + TinyInt: ISqlTypeFactoryWithNoParams; + SmallInt: ISqlTypeFactoryWithNoParams; + Bit: ISqlTypeFactoryWithNoParams; + Float: ISqlTypeFactoryWithNoParams; + Numeric: ISqlTypeFactoryWithPrecisionScale; + Decimal: ISqlTypeFactoryWithPrecisionScale; + Real: ISqlTypeFactoryWithNoParams; + Date: ISqlTypeFactoryWithNoParams; + DateTime: ISqlTypeFactoryWithNoParams; + DateTime2: ISqlTypeFactoryWithScale; + DateTimeOffset: ISqlTypeFactoryWithScale; + SmallDateTime: ISqlTypeFactoryWithNoParams; + Time: ISqlTypeFactoryWithScale; + UniqueIdentifier: ISqlTypeFactoryWithNoParams; + SmallMoney: ISqlTypeFactoryWithNoParams; + Money: ISqlTypeFactoryWithNoParams; + Binary: ISqlTypeFactoryWithNoParams; + VarBinary: ISqlTypeFactoryWithLength; + Image: ISqlTypeFactoryWithNoParams; + Xml: ISqlTypeFactoryWithNoParams; + Char: ISqlTypeFactoryWithLength; + NChar: ISqlTypeFactoryWithLength; + NText: ISqlTypeFactoryWithNoParams; + TVP: ISqlTypeFactoryWithTvpType; + UDT: ISqlTypeFactoryWithNoParams; + Geography: ISqlTypeFactoryWithNoParams; + Geometry: ISqlTypeFactoryWithNoParams; +}; + +export declare var MAX: number; +export declare var fix: boolean; +// export declare var Promise: any; + +interface IMap extends Array<{ js: any, sql: any }> { + register(jstype: any, sql: any): void; +} + +export declare var map: IMap; + +export declare var DRIVERS: string[]; +export interface IColumnMetadata { + [name: string]: { + index: number; + name: string; + length: number; + type: ISqlType; + udt?: any; + } +} +export interface IResult { + recordsets: IRecordSet[]; + recordset: IRecordSet; + rowsAffected: number[], + output: { [key: string]: any }; +} +export interface IProcedureResult extends IResult { + returnValue: any; +} +export interface IRecordSet extends Array { + columns: IColumnMetadata; +} + +type IIsolationLevel = number; + +export declare var ISOLATION_LEVEL: { + READ_UNCOMMITTED: IIsolationLevel + READ_COMMITTED: IIsolationLevel + REPEATABLE_READ: IIsolationLevel + SERIALIZABLE: IIsolationLevel + SNAPSHOT: IIsolationLevel +} + +export interface IOptions { + encrypt?: boolean; + instanceName?: string; + useUTC?: boolean; + tdsVersion?: string; + appName?: string; + abortTransactionOnError?: boolean; + trustedConnection?: boolean; +} + + +export interface IPool { + min: number; + max: number; + idleTimeoutMillis: number; +} + +export declare var pool: IPool; + +export interface config { + driver?: string; + user?: string; + password?: string; + server: string; + port?: number; + domain?: string; + database: string; + connectionTimeout?: number; + requestTimeout?: number; + stream?: boolean; + options?: IOptions; + pool?: IPool; +} + +export declare class ConnectionPool extends events.EventEmitter { + public connected: boolean; + public connecting: boolean; + public driver: string; + public constructor(config: config, callback?: (err?: any) => void); + public constructor(connectionString: string, callback?: (err?: any) => void); + public query(strings: TemplateStringsArray, ...interpolations: any[]): Promise>; + public connect(): Promise; + public connect(callback: (err: any) => void): void; + public close(): Promise; + public close(callback: (err: any) => void): void; + public request(): Request; +} + +export declare class ConnectionError implements Error { + constructor(message: string, code?: any) + public name: string; + public message: string; + public code: string; +} + +declare class columns { + public add(name: string, type: any, options: any): void; +} + +declare class rows { + public add(...row: any[]): void; +} + +export declare class Table { + public create: boolean; + public columns: columns; + public rows: rows; + public constructor(tableName: string); +} + +interface IRequestParameters { + [name: string]: { + name: string; + type: any; + io: number; + value: any; + length: number; + scale: number; + precision: number; + tvpType: any; + } +} + +export declare class Request extends events.EventEmitter { + public transaction: Transaction; + public pstatement: PreparedStatement; + public parameters: IRequestParameters; + public verbose: boolean; + public canceled: boolean; + public stream: any; + public constructor(connection?: ConnectionPool); + public constructor(transaction: Transaction); + public constructor(preparedStatement: PreparedStatement); + public execute(procedure: string): Promise>; + public execute(procedure: string): Promise>; + public execute(procedure: string, callback: (err?: any, recordsets?: IProcedureResult, returnValue?: any) => void): void; + public input(name: string, value: any): Request; + public input(name: string, type: any, value: any): Request; + public output(name: string, type: any, value?: any): Request; + public pipe(stream: NodeJS.WritableStream): NodeJS.WritableStream; + public query(command: string): Promise>; + public query(command: string): Promise>; + public query(command: string, callback: (err?: Error, recordset?: IResult) => void): void; + public batch(batch: string): Promise>; + public batch(batch: string): Promise>; + public batch(batch: string, callback: (err?: Error, recordset?: IResult) => void): void; + public batch(batch: string, callback: (err?: any, recordset?: IResult) => void): void; + public bulk(table: Table): Promise; + public bulk(table: Table, callback: (err: Error, rowCount: any) => void): void; + public cancel(): void; +} + +export declare class RequestError implements Error { + constructor(message: string, code?: any) + public name: string; + public message: string; + public code: string; +} + +export declare class Transaction extends events.EventEmitter { + public isolationLevel: IIsolationLevel; + public constructor(connection?: ConnectionPool); + public begin(isolationLevel?: IIsolationLevel): Promise; + public begin(isolationLevel?: IIsolationLevel, callback?: (err?: any) => void): void; + public commit(): Promise; + public commit(callback: (err?: any) => void): void; + public rollback(): Promise; + public rollback(callback: (err?: any) => void): void; +} + +export declare class TransactionError implements Error { + constructor(message: string, code?: any) + public name: string; + public message: string; + public code: string; +} + +export declare class PreparedStatement extends events.EventEmitter { + public transaction: Transaction; + public prepared: boolean; + public statement: string; + public parameters: IRequestParameters; + public stream: any; + public constructor(connection?: ConnectionPool); + public input(name: string, type: ISqlType): PreparedStatement; + public output(name: string, type: ISqlType): PreparedStatement; + public prepare(statement?: string): Promise; + public prepare(statement?: string, callback?: (err?: Error) => void): PreparedStatement; + public execute(values: Object): Promise; + public execute(values: Object, callback: (err?: Error) => void): Request; + public unprepare(): Promise; + public unprepare(callback: (err?: Error) => void): PreparedStatement; +} + +export declare class PreparedStatementError implements Error { + constructor(message: string, code?: any) + public name: string; + public message: string; + public code: string; +} diff --git a/package.json b/package.json new file mode 100644 index 0000000..095354b --- /dev/null +++ b/package.json @@ -0,0 +1,32 @@ +{ + "name": "@cw-types/mssql", + "version": "1.0.0", + "author": "Kavan J. Shaban (Cycloware, LLC)", + "description": "Typescript typings for `mssql` `4.0.4` that support bluebird", + "homepage": "https://github.com/Cycloware/cw-types-bluebird", + "repository": { + "type": "git", + "url": "https://github.com/Cycloware/cw-types-bluebird.git" + }, + "contributors": [ + { + "name": "Kavan Shaban", + "url": "https://github.com/kavanshaban" + }, + { + "name": "Cycloware", + "url": "https://github.com/cycloware" + } + ], + "main": "", + "dependencies": { + "@cw-types/bluebird": "*" + }, + "scripts": {}, + "keywords": [ + "@types", + "mssql", + "bluebird", + "typescript" + ] +} \ No newline at end of file