mirror of
https://github.com/wassname/DefinitelyTyped.git
synced 2026-09-09 11:13:57 +08:00
merge upstream
This commit is contained in:
@@ -125,7 +125,11 @@ All definitions files include a header with the author and editors, so at some p
|
||||
* [highlight.js](https://github.com/isagalaev/highlight.js) (by [Niklas Mollenhauer](https://github.com/nikeee))
|
||||
* [History.js](https://github.com/browserstate/history.js) (by [Boris Yankov](https://github.com/borisyankov))
|
||||
* [Html2Canvas.js](https://github.com/niklasvh/html2canvas/) (by [Richard Hepburn](https://github.com/rwhepburn))
|
||||
<<<<<<< HEAD
|
||||
* [htmlparser2](https://github.com/fb55/htmlparser2/) (by [James Roland Cabresos](https://github.com/staticfunction))
|
||||
=======
|
||||
* [http-string-parser](https://github.com/apiaryio/http-string-parser) (by [MIZUNE Pine](https://github.com/pine613))
|
||||
>>>>>>> upstream/master
|
||||
* [Humane.js](http://wavded.github.com/humane-js/) (by [John Vrbanac](https://github.com/jmvrbanac))
|
||||
* [i18next](http://i18next.com/) (by [Maarten Docter](https://github.com/mdocter))
|
||||
* [iCheck](http://damirfoy.com/iCheck/) (by [Dániel Tar](https://github.com/qcz))
|
||||
@@ -195,6 +199,7 @@ All definitions files include a header with the author and editors, so at some p
|
||||
* [js-git](https://github.com/creationix/js-git) (by [Bart van der Schoor](https://github.com/Bartvds))
|
||||
* [js-url](https://github.com/websanova/js-url) (by [MIZUNE Pine](https://github.com/pine613))
|
||||
* [js-yaml](https://github.com/nodeca/js-yaml) (by [Bart van der Schoor](https://github.com/Bartvds/))
|
||||
* [jsbn](http://www-cs-students.stanford.edu/%7Etjw/jsbn/) (by [Eugene Chernyshov](https://github.com/Evgenus))
|
||||
* [jScrollPane](http://jscrollpane.kelvinluck.com) (by [Dániel Tar](https://github.com/qcz))
|
||||
* [JSDeferred](http://cho45.stfuawsc.com/jsdeferred/) (by [Daisuke Mino](https://github.com/minodisk))
|
||||
* [JSONEditorOnline](https://github.com/josdejong/jsoneditoronline) (by [Vincent Bortone](https://github.com/vbortone/))
|
||||
@@ -250,7 +255,9 @@ All definitions files include a header with the author and editors, so at some p
|
||||
* [Mousetrap](http://craig.is/killing/mice) (by [Dániel Tar](https://github.com/qcz))
|
||||
* [msgpack.js](https://github.com/uupaa/msgpack.js) (by [Shinya Mochizuki](https://github.com/enrapt-mochizuki))
|
||||
* [Mustache.js](https://github.com/janl/mustache.js) (by [Boris Yankov](https://github.com/borisyankov))
|
||||
* [mysql](https://github.com/felixge/node-mysql) (by [William Johnston](https://github.com/wjohnsto))
|
||||
* [nconf](https://github.com/flatiron/nconf) (by [Jeff Goddard](https://github.com/jedigo))
|
||||
* [needle](https://github.com/tomas/needle) (by [San Chen](https://github.com/bigsan))
|
||||
* [noble](https://github.com/sandeepmistry/noble) (by [Seon-Wook Park](https://github.com/swook))
|
||||
* [nock](https://github.com/pgte/nock) (by [bonnici](https://github.com/bonnici))
|
||||
* [Node.js](http://nodejs.org/) (from TypeScript samples)
|
||||
|
||||
+3
-2
@@ -33,13 +33,14 @@ declare module ng.translate {
|
||||
}
|
||||
|
||||
interface ITranslateService {
|
||||
(key: string, ...params: string[]): ng.IPromise<string>;
|
||||
(translationId: string, interpolateParams?: any, interpolationId?: string): ng.IPromise<string>;
|
||||
(translationId: string[], interpolateParams?: any, interpolationId?: string): ng.IPromise<{ [key: string]: string }>;
|
||||
cloakClassName(): string;
|
||||
cloakClassName(name: string): ITranslateProvider;
|
||||
fallbackLanguage(langKey?: string): string;
|
||||
fallbackLanguage(langKey?: string[]): string;
|
||||
instant(translationId: string, interpolateParams?: any, interpolationId?: string): string;
|
||||
instant(translationId: string[], interpolateParams?: any, interpolationId?: string): string;
|
||||
instant(translationId: string[], interpolateParams?: any, interpolationId?: string): { [key: string]: string };
|
||||
isPostCompilingEnabled(): boolean;
|
||||
preferredLanguage(): string;
|
||||
proposedLanguage(): string;
|
||||
|
||||
Vendored
+33
-5
@@ -243,7 +243,7 @@ declare module D3 {
|
||||
*
|
||||
* @param map Array of objects to get the values from
|
||||
*/
|
||||
values(map: any[]): any[];
|
||||
values(map: any): any[];
|
||||
/**
|
||||
* List the key-value entries of an associative array.
|
||||
*
|
||||
@@ -1159,6 +1159,19 @@ declare module D3 {
|
||||
*/
|
||||
(size: Array<number>): TreeLayout;
|
||||
};
|
||||
/**
|
||||
* Gets or sets the available node size
|
||||
*/
|
||||
nodeSize: {
|
||||
/**
|
||||
* Gets the available node size
|
||||
*/
|
||||
(): Array<number>;
|
||||
/**
|
||||
* Sets the available node size
|
||||
*/
|
||||
(size: Array<number>): TreeLayout;
|
||||
};
|
||||
}
|
||||
|
||||
export interface PieLayout {
|
||||
@@ -1720,10 +1733,21 @@ declare module D3 {
|
||||
(): any[];
|
||||
(values: any[]): Axis;
|
||||
};
|
||||
|
||||
tickSubdivide(count: number): Axis;
|
||||
tickSize(major?: number, minor?: number, end?: number): Axis;
|
||||
tickSize: {
|
||||
(): number;
|
||||
(inner: number, outer?: number): Axis;
|
||||
}
|
||||
innerTickSize: {
|
||||
(): number;
|
||||
(value: number): Axis;
|
||||
}
|
||||
outerTickSize: {
|
||||
(): number;
|
||||
(value: number): Axis;
|
||||
}
|
||||
tickFormat(formatter: (value: any) => string): Axis;
|
||||
nice(count?: number): Axis;
|
||||
}
|
||||
|
||||
export interface Arc {
|
||||
@@ -2569,7 +2593,10 @@ declare module D3 {
|
||||
*
|
||||
* @param clamp Enable or disable
|
||||
*/
|
||||
clamp(clamp: boolean): QuantitativeScale;
|
||||
clamp: {
|
||||
(): boolean;
|
||||
(clamp: boolean): QuantitativeScale;
|
||||
}
|
||||
/**
|
||||
* extend the scale domain to nice round numbers.
|
||||
*
|
||||
@@ -2587,7 +2614,7 @@ declare module D3 {
|
||||
*
|
||||
* @param count Aproximate representative values to return
|
||||
*/
|
||||
tickFormat(count: number): (n: number) => string;
|
||||
tickFormat(count: number, format?: string): (n: number) => string;
|
||||
/**
|
||||
* create a new scale from an existing scale..
|
||||
*/
|
||||
@@ -2768,6 +2795,7 @@ declare module D3 {
|
||||
};
|
||||
tickFormat(count: number): (n: number) => string;
|
||||
copy(): TimeScale;
|
||||
nice(count?: number): TimeScale;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -73,3 +73,46 @@ exports = (grunt: IGrunt) => {
|
||||
fileMaps[0].src.length;
|
||||
fileMaps[0].dest;
|
||||
};
|
||||
|
||||
// Official grunt task template from
|
||||
// https://github.com/gruntjs/grunt-init-gruntplugin/blob/master/root/tasks/name.js
|
||||
exports.exports = function(grunt: IGrunt) {
|
||||
|
||||
// Please see the Grunt documentation for more information regarding task
|
||||
// creation: http://gruntjs.com/creating-tasks
|
||||
|
||||
grunt.registerMultiTask('taskName', 'task description', function() {
|
||||
// Merge task-specific and/or target-specific options with these defaults.
|
||||
var options = this.options({
|
||||
punctuation: '.',
|
||||
separator: ', '
|
||||
});
|
||||
|
||||
// Iterate over all specified file groups.
|
||||
this.files.forEach(function(f: grunt.file.IFilesConfig) {
|
||||
// Concat specified files.
|
||||
var src = f.src.filter(function(filepath: string) {
|
||||
// Warn on and remove invalid source files (if nonull was set).
|
||||
if (!grunt.file.exists(filepath)) {
|
||||
grunt.log.warn('Source file "' + filepath + '" not found.');
|
||||
return false;
|
||||
} else {
|
||||
return true;
|
||||
}
|
||||
}).map(function(filepath) {
|
||||
// Read file source.
|
||||
return grunt.file.read(filepath);
|
||||
}).join(grunt.util.normalizelf(options.separator));
|
||||
|
||||
// Handle options.
|
||||
src += options.punctuation;
|
||||
|
||||
// Write the destination file.
|
||||
grunt.file.write(f.dest, src);
|
||||
|
||||
// Print a success message.
|
||||
grunt.log.writeln('File "' + f.dest + '" created.');
|
||||
});
|
||||
});
|
||||
|
||||
};
|
||||
Vendored
+5
@@ -690,6 +690,11 @@ declare module grunt {
|
||||
* Log a list of obj properties (good for debugging flags).
|
||||
*/
|
||||
writeflags(obj: any): T
|
||||
|
||||
/**
|
||||
* Log an warning with grunt.log.warn
|
||||
*/
|
||||
warn(msg: string): T
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -0,0 +1,42 @@
|
||||
/// <reference path="http-string-parser.d.ts" />
|
||||
|
||||
import parser = require("http-string-parser");
|
||||
|
||||
function test_request(): void {
|
||||
var result = parser.parseRequest("HTTP/1.1 GET /\r\nHost: www.example.com\r\n\r\n");
|
||||
|
||||
var body: string = result.body;
|
||||
var headers: { [key: string]: string } = result.headers;
|
||||
var method: string = result.method;
|
||||
var uri: string = result.uri;
|
||||
}
|
||||
|
||||
function test_response(): void {
|
||||
var response = parser.parseResponse("HTTP/1.1 200 OK\r\n\r\n");
|
||||
|
||||
var body: string = response.body;
|
||||
var headers: { [key: string]: string } = response.headers;
|
||||
var statusCode: string = response.statusCode;
|
||||
var statusMessage: string = response.statusMessage;
|
||||
}
|
||||
|
||||
function test_requestLine(): void {
|
||||
var result = parser.parseRequestLine("HTTP/1.1 GET /");
|
||||
|
||||
var method: string = result.method;
|
||||
var protocol: string = result.protocol;
|
||||
var uri: string = result.uri;
|
||||
}
|
||||
|
||||
function test_statusLine(): void {
|
||||
var result = parser.parseStatusLine("HTTP/1.1 200 OK");
|
||||
|
||||
var protocol: string = result.protocol;
|
||||
var statusCode: string = result.statusCode;
|
||||
var statusMessage: string = result.statusMessage;
|
||||
}
|
||||
|
||||
function test_headers(): void {
|
||||
var result: { [key: string]: string } =
|
||||
parser.parseHeaders("Content-Type: text/html; charset=utf-8\r\nContent-Length: 256\r\n");
|
||||
}
|
||||
+38
@@ -0,0 +1,38 @@
|
||||
// Type definitions for http-string-parser
|
||||
// Project: https://github.com/apiaryio/http-string-parser
|
||||
// Definitions by: MIZUNE Pine <https://github.com/pine613>
|
||||
// Definitions: https://github.com/borisyankov/DefinitelyTyped
|
||||
|
||||
declare module "http-string-parser" {
|
||||
interface ParseRequestResult {
|
||||
method: string;
|
||||
uri: string;
|
||||
headers: { [key: string]: string };
|
||||
body: string;
|
||||
}
|
||||
|
||||
interface ParseResponseResult {
|
||||
statusCode: string;
|
||||
statusMessage: string;
|
||||
headers: { [key: string]: string };
|
||||
body: string;
|
||||
}
|
||||
|
||||
interface ParseRequestLineResult {
|
||||
method: string;
|
||||
uri: string;
|
||||
protocol: string;
|
||||
}
|
||||
|
||||
interface ParseStatusLineResult {
|
||||
protocol: string;
|
||||
statusCode: string;
|
||||
statusMessage: string;
|
||||
}
|
||||
|
||||
export function parseRequest(requestString: string): ParseRequestResult;
|
||||
export function parseResponse(responseString: string): ParseResponseResult;
|
||||
export function parseRequestLine(requestLineString: string): ParseRequestLineResult;
|
||||
export function parseStatusLine(statusLine: string): ParseStatusLineResult;
|
||||
export function parseHeaders(headerLines: string): { [key: string]: string };
|
||||
}
|
||||
Vendored
+1
-5
@@ -1,6 +1,6 @@
|
||||
// Type definitions for jQuery 1.10.x / 2.0.x
|
||||
// Project: http://jquery.com/
|
||||
// Definitions by: Boris Yankov <https://github.com/borisyankov/>, Christian Hoffmeister <https://github.com/choffmeister>, Steve Fenton <https://github.com/Steve-Fenton>, Diullei Gomes <https://github.com/Diullei>, Tass Iliopoulos <https://github.com/tasoili>, Jason Swearingen <https://github.com/jasons-novaleaf>, Sean Hill <https://github.com/seanski>, Guus Goossens <https://github.com/Guuz>, Kelly Summerlin <https://github.com/ksummerlin>, Basarat Ali Syed <https://github.com/basarat>, Nicholas Wolverson <https://github.com/nwolverson>, Derek Cicerone <https://github.com/derekcicerone>, Andrew Gaspar <https://github.com/AndrewGaspar>, James Harrison Fisher <https://github.com/jameshfisher>, Seikichi Kondo <https://github.com/seikichi>, Benjamin Jackman <https://github.com/benjaminjackman>, Poul Sorensen <https://github.com/s093294>, Josh Strobl <https://github.com/JoshStrobl>, John Reilly <https://github.com/johnnyreilly/>
|
||||
// Definitions by: Boris Yankov <https://github.com/borisyankov/>, Christian Hoffmeister <https://github.com/choffmeister>, Steve Fenton <https://github.com/Steve-Fenton>, Diullei Gomes <https://github.com/Diullei>, Tass Iliopoulos <https://github.com/tasoili>, Jason Swearingen <https://github.com/jasons-novaleaf>, Sean Hill <https://github.com/seanski>, Guus Goossens <https://github.com/Guuz>, Kelly Summerlin <https://github.com/ksummerlin>, Basarat Ali Syed <https://github.com/basarat>, Nicholas Wolverson <https://github.com/nwolverson>, Derek Cicerone <https://github.com/derekcicerone>, Andrew Gaspar <https://github.com/AndrewGaspar>, James Harrison Fisher <https://github.com/jameshfisher>, Seikichi Kondo <https://github.com/seikichi>, Benjamin Jackman <https://github.com/benjaminjackman>, Poul Sorensen <https://github.com/s093294>, Josh Strobl <https://github.com/JoshStrobl>, John Reilly <https://github.com/johnnyreilly/>, Dick van den Brink <https://github.com/DickvdBrink>
|
||||
// Definitions: https://github.com/borisyankov/DefinitelyTyped
|
||||
|
||||
/* *****************************************************************************
|
||||
@@ -525,10 +525,6 @@ interface JQueryDeferred<T> extends JQueryPromise<T> {
|
||||
* @param args An optional array of arguments that are passed to the doneCallbacks.
|
||||
*/
|
||||
resolveWith(context: any, ...args: any[]): JQueryDeferred<T>;
|
||||
/**
|
||||
* Determine the current state of a Deferred object.
|
||||
*/
|
||||
state(): string;
|
||||
|
||||
/**
|
||||
* Return a Deferred's Promise object.
|
||||
|
||||
@@ -0,0 +1,93 @@
|
||||
/// <reference path="jsbn.d.ts" />
|
||||
var BigInteger = jsbn.BigInteger;
|
||||
|
||||
// constructor tests
|
||||
var x = new BigInteger("AABB", 16);
|
||||
x = new BigInteger("75643564363473453456342378564387956906736546456235345");
|
||||
|
||||
// method tests
|
||||
var isBigInteger: jsbn.BigInteger;
|
||||
var isNumber: number;
|
||||
var isBoolean: boolean;
|
||||
var isString: string;
|
||||
var isDivmod: jsbn.BigInteger[];
|
||||
var isByteArray: number[];
|
||||
|
||||
x.copyTo(x);
|
||||
x.fromInt(0);
|
||||
x.fromString("CAFEBABE", 16);
|
||||
x.clamp();
|
||||
isString = x.toString();
|
||||
isString = x.toString(16);
|
||||
isBigInteger = x.negate();
|
||||
isBigInteger = x.abs();
|
||||
isNumber = x.compareTo(x);
|
||||
isNumber = x.bitLength();
|
||||
x.dlShiftTo(0, isBigInteger);
|
||||
x.drShiftTo(0, isBigInteger);
|
||||
x.lShiftTo(0, isBigInteger);
|
||||
x.rShiftTo(0, isBigInteger);
|
||||
x.subTo(x, isBigInteger);
|
||||
x.multiplyTo(x, isBigInteger);
|
||||
x.squareTo(isBigInteger);
|
||||
x.divRemTo(x, isBigInteger, isBigInteger);
|
||||
isBigInteger = x.mod(x);
|
||||
isNumber = x.invDigit();
|
||||
isBoolean = x.isEven();
|
||||
isBigInteger = x.exp(0, {
|
||||
convert: (x) => x,
|
||||
revert: (x) => x,
|
||||
reduce: (x) => x,
|
||||
mulTo: (x) => x,
|
||||
sqrTo: (x) => x
|
||||
});
|
||||
isBigInteger = x.modPowInt(0, x);
|
||||
isBigInteger = x.clone();
|
||||
isNumber = x.intValue();
|
||||
isNumber = x.byteValue();
|
||||
isNumber = x.shortValue();
|
||||
isNumber = x.chunkSize(0);
|
||||
isNumber = x.signum();
|
||||
isString = x.toRadix(10);
|
||||
x.fromRadix("123", 10);
|
||||
x.fromNumber(1);
|
||||
x.fromNumber(1, 2);
|
||||
x.fromNumber(1, 2, 3);
|
||||
isByteArray = x.toByteArray();
|
||||
isBoolean = x.equals(x);
|
||||
isBigInteger = x.min(x);
|
||||
isBigInteger = x.max(x);
|
||||
x.bitwiseTo(x, (x, y) => x + y, isBigInteger);
|
||||
isBigInteger = x.and(x);
|
||||
isBigInteger = x.or(x);
|
||||
isBigInteger = x.xor(x);
|
||||
isBigInteger = x.andNot(x);
|
||||
isBigInteger = x.not();
|
||||
isBigInteger = x.shiftLeft(0);
|
||||
isBigInteger = x.shiftRight(0);
|
||||
isNumber = x.getLowestSetBit();
|
||||
isNumber = x.bitCount();
|
||||
isBoolean = x.testBit(0);
|
||||
isBigInteger = x.changeBit(0, (x, y) => x * y);
|
||||
isBigInteger = x.setBit(0);
|
||||
isBigInteger = x.clearBit(0);
|
||||
isBigInteger = x.flipBit(0);
|
||||
x.addTo(x, isBigInteger);
|
||||
isBigInteger = x.add(x);
|
||||
isBigInteger = x.subtract(x);
|
||||
isBigInteger = x.multiply(x);
|
||||
isBigInteger = x.square();
|
||||
isBigInteger = x.divide(x);
|
||||
isBigInteger = x.remainder(x);
|
||||
isDivmod = x.divideAndRemainder(x);
|
||||
x.dMultiply(0);
|
||||
x.dAddOffset(0, 0);
|
||||
isBigInteger = x.pow(0);
|
||||
x.multiplyLowerTo(x, 0, isBigInteger);
|
||||
x.multiplyUpperTo(x, 0, isBigInteger);
|
||||
isBigInteger = x.modPow(x, x);
|
||||
isBigInteger = x.gcd(x);
|
||||
isNumber = x.modInt(0);
|
||||
isBigInteger = x.modInverse(x);
|
||||
isBoolean = x.isProbablePrime(0);
|
||||
isBoolean = x.millerRabin(0);
|
||||
Vendored
+250
@@ -0,0 +1,250 @@
|
||||
// Type definitions for jsbn v1.2
|
||||
// Project: http://www-cs-students.stanford.edu/%7Etjw/jsbn/
|
||||
// Definitions by: Eugene Chernyshov <https://github.com/Evgenus>
|
||||
// Definitions: https://github.com/borisyankov/DefinitelyTyped
|
||||
|
||||
declare module jsbn {
|
||||
|
||||
interface RandomGenerator {
|
||||
nextBytes(bytes: number[]): void;
|
||||
}
|
||||
|
||||
export class BigInteger {
|
||||
constructor(a: number, c: RandomGenerator);
|
||||
constructor(a: number, b: number, c: RandomGenerator);
|
||||
constructor(a: string, b?: number);
|
||||
constructor(a: number[], b?: number);
|
||||
constructor(a: BigInteger);
|
||||
|
||||
s: number;
|
||||
t: number;
|
||||
data: number[]; // forge specific
|
||||
|
||||
DB: number;
|
||||
DM: number;
|
||||
DV: number;
|
||||
|
||||
FV: number;
|
||||
F1: number;
|
||||
F2: number;
|
||||
|
||||
// am: Compute w_j += (x*this_i), propagate carries,
|
||||
am(i: number, x: number, w: BigInteger, j: number, c: number, n: number): number;
|
||||
|
||||
// (protected) copy this to r
|
||||
copyTo(r: BigInteger): void;
|
||||
|
||||
// (protected) set from integer value x, -DV <= x < DV
|
||||
fromInt(x: number): void;
|
||||
|
||||
// (protected) set from string and radix
|
||||
fromString(x: string, b: number): void;
|
||||
|
||||
// (protected) clamp off excess high words
|
||||
clamp(): void;
|
||||
|
||||
// (public) return string representation in given radix
|
||||
toString(b?: number): string;
|
||||
|
||||
// (public) -this
|
||||
negate(): BigInteger;
|
||||
|
||||
// (public) |this|
|
||||
abs(): BigInteger;
|
||||
|
||||
// (public) return + if this > a, - if this < a, 0 if equal
|
||||
compareTo(a: BigInteger): number;
|
||||
|
||||
// (public) return the number of bits in "this"
|
||||
bitLength(): number;
|
||||
|
||||
// (protected) r = this << n*DB
|
||||
dlShiftTo(n: number, r: BigInteger): void;
|
||||
|
||||
// (protected) r = this >> n*DB
|
||||
drShiftTo(n: number, r: BigInteger): void;
|
||||
|
||||
// (protected) r = this << n
|
||||
lShiftTo(n: number, r: BigInteger): void;
|
||||
|
||||
// (protected) r = this >> n
|
||||
rShiftTo(n: number, r: BigInteger): void;
|
||||
|
||||
// (protected) r = this - a
|
||||
subTo(a: BigInteger, r: BigInteger): void;
|
||||
|
||||
// (protected) r = this * a, r != this,a (HAC 14.12)
|
||||
multiplyTo(a: BigInteger, r: BigInteger): void;
|
||||
|
||||
// (protected) r = this^2, r != this (HAC 14.16)
|
||||
squareTo(r: BigInteger): void;
|
||||
|
||||
// (protected) divide this by m, quotient and remainder to q, r (HAC 14.20)
|
||||
// r != q, this != m. q or r may be null.
|
||||
divRemTo(m: BigInteger, q: BigInteger, r: BigInteger): void;
|
||||
|
||||
// (public) this mod a
|
||||
mod(a: BigInteger): BigInteger;
|
||||
|
||||
// (protected) return "-1/this % 2^DB"; useful for Mont. reduction
|
||||
invDigit(): number;
|
||||
|
||||
// (protected) true iff this is even
|
||||
isEven(): boolean;
|
||||
|
||||
// (protected) this^e, e < 2^32, doing sqr and mul with "r" (HAC 14.79)
|
||||
exp(e: number, z: Reduction): BigInteger;
|
||||
|
||||
// (public) this^e % m, 0 <= e < 2^32
|
||||
modPowInt(e: number, m: BigInteger): BigInteger;
|
||||
|
||||
// (public)
|
||||
clone(): BigInteger;
|
||||
|
||||
// (public) return value as integer
|
||||
intValue(): number;
|
||||
|
||||
// (public) return value as byte
|
||||
byteValue(): number;
|
||||
|
||||
// (public) return value as short (assumes DB>=16)
|
||||
shortValue(): number;
|
||||
|
||||
// (protected) return x s.t. r^x < DV
|
||||
chunkSize(r: number): number;
|
||||
|
||||
// (public) 0 if this == 0, 1 if this > 0
|
||||
signum(): number;
|
||||
|
||||
// (protected) convert to radix string
|
||||
toRadix(b: number): string;
|
||||
|
||||
// (protected) convert from radix string
|
||||
fromRadix(s: string, b: number): void;
|
||||
|
||||
// (protected) alternate constructor
|
||||
fromNumber(a: number, b?: number, c?: number): void;
|
||||
|
||||
// (public) convert to bigendian byte array
|
||||
toByteArray(): number[];
|
||||
|
||||
equals(a: BigInteger): boolean;
|
||||
|
||||
min(a: BigInteger): BigInteger;
|
||||
|
||||
max(a: BigInteger): BigInteger;
|
||||
|
||||
// (protected) r = this op a (bitwise)
|
||||
bitwiseTo(a: BigInteger, op: (x: number, y: number) => number, r: BigInteger): void;
|
||||
|
||||
// (public) this & a
|
||||
and(a: BigInteger): BigInteger;
|
||||
|
||||
// (public) this | a
|
||||
or(a: BigInteger): BigInteger;
|
||||
|
||||
// (public) this ^ a
|
||||
xor(a: BigInteger): BigInteger;
|
||||
|
||||
// (public) this & ~a
|
||||
andNot(a: BigInteger): BigInteger;
|
||||
|
||||
// (public) ~this
|
||||
not(): BigInteger;
|
||||
|
||||
// (public) this << n
|
||||
shiftLeft(n: number): BigInteger;
|
||||
|
||||
// (public) this >> n
|
||||
shiftRight(n: number): BigInteger;
|
||||
|
||||
// (public) returns index of lowest 1-bit (or -1 if none)
|
||||
getLowestSetBit(): number;
|
||||
|
||||
// (public) return number of set bits
|
||||
bitCount(): number;
|
||||
|
||||
// (public) true iff nth bit is set
|
||||
testBit(n: number): boolean;
|
||||
|
||||
// (protected) this op (1<<n)
|
||||
changeBit(n: number, op: (x: number, y: number) => number): BigInteger;
|
||||
|
||||
// (protected) this op (1<<n)
|
||||
setBit(n: number): BigInteger;
|
||||
|
||||
// (public) this & ~(1<<n)
|
||||
clearBit(n: number): BigInteger
|
||||
|
||||
// (public) this ^ (1<<n)
|
||||
flipBit(n: number): BigInteger
|
||||
|
||||
// (protected) r = this + a
|
||||
addTo(a: BigInteger, r: BigInteger): void;
|
||||
|
||||
// (public) this + a
|
||||
add(a: BigInteger): BigInteger;
|
||||
|
||||
// (public) this - a
|
||||
subtract(a: BigInteger): BigInteger;
|
||||
|
||||
// (public) this * a
|
||||
multiply(a: BigInteger): BigInteger;
|
||||
|
||||
// (public) this^2
|
||||
square(): BigInteger;
|
||||
|
||||
// (public) this / a
|
||||
divide(a: BigInteger): BigInteger;
|
||||
|
||||
// (public) this % a
|
||||
remainder(a: BigInteger): BigInteger;
|
||||
|
||||
// (public) [this/a,this%a]
|
||||
divideAndRemainder(a: BigInteger): BigInteger[]; // Array of 2 items
|
||||
|
||||
// (protected) this *= n, this >= 0, 1 < n < DV
|
||||
dMultiply(n: number): void;
|
||||
|
||||
// (protected) this += n << w words, this >= 0
|
||||
dAddOffset(n: number, w: number): void;
|
||||
|
||||
// (public) this^e
|
||||
pow(e: number): BigInteger;
|
||||
|
||||
// (protected) r = lower n words of "this * a", a.t <= n
|
||||
multiplyLowerTo(a: BigInteger, n: number, r: BigInteger): void;
|
||||
|
||||
// (protected) r = "this * a" without lower n words, n > 0
|
||||
multiplyUpperTo(a: BigInteger, n: number, r: BigInteger): void;
|
||||
|
||||
// (public) this^e % m (HAC 14.85)
|
||||
modPow(e: BigInteger, m: BigInteger): BigInteger;
|
||||
|
||||
// (public) gcd(this,a) (HAC 14.54)
|
||||
gcd(a: BigInteger): BigInteger;
|
||||
|
||||
// (protected) this % n, n < 2^26
|
||||
modInt(n: number): number;
|
||||
|
||||
// (public) 1/this % m (HAC 14.61)
|
||||
modInverse(m: BigInteger): BigInteger;
|
||||
|
||||
// (public) test primality with certainty >= 1-.5^t
|
||||
isProbablePrime(t: number): boolean;
|
||||
|
||||
// (protected) true if probably prime (HAC 4.24, Miller-Rabin)
|
||||
millerRabin(t: number): boolean;
|
||||
|
||||
static ZERO: BigInteger;
|
||||
static ONE: BigInteger;
|
||||
}
|
||||
|
||||
interface Reduction {
|
||||
convert(x: BigInteger): BigInteger;
|
||||
revert(x: BigInteger): BigInteger;
|
||||
reduce(x: BigInteger): void;
|
||||
mulTo(x: BigInteger, y: BigInteger, r: BigInteger): void;
|
||||
sqrTo(x: BigInteger, r: BigInteger): void;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,381 @@
|
||||
/// <reference path="mysql.d.ts" />
|
||||
|
||||
import mysql = require('mysql');
|
||||
|
||||
/// Connections
|
||||
var connection = mysql.createConnection({
|
||||
host: 'localhost',
|
||||
user: 'me',
|
||||
password: 'secret'
|
||||
});
|
||||
|
||||
connection.connect();
|
||||
|
||||
connection.query('SELECT 1 + 1 AS solution', function (err, rows, fields) {
|
||||
if (err) throw err;
|
||||
|
||||
console.log('The solution is: ', rows[0].solution);
|
||||
});
|
||||
|
||||
connection.end();
|
||||
|
||||
connection = mysql.createConnection({
|
||||
host: 'example.org',
|
||||
user: 'bob',
|
||||
password: 'secret'
|
||||
});
|
||||
|
||||
connection.connect(function (err) {
|
||||
if (err) {
|
||||
console.error('error connecting: ' + err.stack);
|
||||
return;
|
||||
}
|
||||
|
||||
console.log('connected as id ' + connection.threadId);
|
||||
});
|
||||
|
||||
connection.query('SELECT 1', function (err, rows) {
|
||||
// connected! (unless `err` is set)
|
||||
});
|
||||
|
||||
connection = mysql.createConnection({
|
||||
host: 'localhost',
|
||||
ssl: {
|
||||
ca: ''
|
||||
}
|
||||
});
|
||||
|
||||
connection = mysql.createConnection({
|
||||
host: 'localhost',
|
||||
ssl: {
|
||||
// DO NOT DO THIS
|
||||
// set up your ca correctly to trust the connection
|
||||
rejectUnauthorized: false
|
||||
}
|
||||
});
|
||||
|
||||
connection.end(function (err) {
|
||||
// The connection is terminated now
|
||||
});
|
||||
|
||||
connection.destroy();
|
||||
|
||||
connection.changeUser({ user: 'john' }, function (err) {
|
||||
if (err) throw err;
|
||||
});
|
||||
|
||||
var userId = 'some user provided value';
|
||||
var sql = 'SELECT * FROM users WHERE id = ' + connection.escape(userId);
|
||||
connection.query(sql, function (err, results) {
|
||||
// ...
|
||||
});
|
||||
connection.query('SELECT * FROM users WHERE id = ?', [userId], function (err, results) {
|
||||
// ...
|
||||
});
|
||||
|
||||
var post = { id: 1, title: 'Hello MySQL' };
|
||||
var query = connection.query('INSERT INTO posts SET ?', post, function (err, result) {
|
||||
// Neat!
|
||||
});
|
||||
console.log(query.sql); // INSERT INTO posts SET `id` = 1, `title` = 'Hello MySQL'
|
||||
|
||||
var queryStr = "SELECT * FROM posts WHERE title=" + mysql.escape("Hello MySQL");
|
||||
|
||||
console.log(queryStr); // SELECT * FROM posts WHERE title='Hello MySQL'
|
||||
|
||||
var sorter = 'date';
|
||||
var sql = 'SELECT * FROM posts ORDER BY ' + connection.escapeId(sorter);
|
||||
connection.query(sql, function (err, results) {
|
||||
// ...
|
||||
});
|
||||
|
||||
var sorter = 'date';
|
||||
var sql = 'SELECT * FROM posts ORDER BY ' + connection.escapeId('posts.' + sorter);
|
||||
connection.query(sql, function (err, results) {
|
||||
// ...
|
||||
});
|
||||
|
||||
var userIdNum = 1;
|
||||
var columns = ['username', 'email'];
|
||||
var query = connection.query('SELECT ?? FROM ?? WHERE id = ?', [columns, 'users', userIdNum], function (err, results) {
|
||||
// ...
|
||||
});
|
||||
|
||||
console.log(query.sql); // SELECT `username`, `email` FROM `users` WHERE id = 1
|
||||
|
||||
var sql = "SELECT * FROM ?? WHERE ?? = ?";
|
||||
var inserts = ['users', 'id', userId];
|
||||
sql = mysql.format(sql, inserts);
|
||||
|
||||
connection.config.queryFormat = function (query, values) {
|
||||
if (!values) return query;
|
||||
return query.replace(/\:(\w+)/g, function (txt: string, key: string) {
|
||||
if (values.hasOwnProperty(key)) {
|
||||
return this.escape(values[key]);
|
||||
}
|
||||
return txt;
|
||||
}.bind(this));
|
||||
};
|
||||
|
||||
connection.query("UPDATE posts SET title = :title", { title: "Hello MySQL" });
|
||||
|
||||
connection.query('INSERT INTO posts SET ?', { title: 'test' }, function (err, result) {
|
||||
if (err) throw err;
|
||||
|
||||
console.log(result.insertId);
|
||||
});
|
||||
|
||||
connection.query('DELETE FROM posts WHERE title = "wrong"', function (err, result) {
|
||||
if (err) throw err;
|
||||
|
||||
console.log('deleted ' + result.affectedRows + ' rows');
|
||||
});
|
||||
|
||||
connection.query('UPDATE posts SET ...', function (err, result) {
|
||||
if (err) throw err;
|
||||
|
||||
console.log('changed ' + result.changedRows + ' rows');
|
||||
});
|
||||
|
||||
connection.connect(function (err) {
|
||||
if (err) throw err;
|
||||
console.log('connected as id ' + connection.threadId);
|
||||
});
|
||||
|
||||
/// Pools
|
||||
|
||||
var poolConfig = {
|
||||
connectionLimit: 10,
|
||||
host: 'example.org',
|
||||
user: 'bob',
|
||||
password: 'secret'
|
||||
};
|
||||
|
||||
var pool = mysql.createPool(poolConfig);
|
||||
|
||||
pool.query('SELECT 1 + 1 AS solution', function (err, rows, fields) {
|
||||
if (err) throw err;
|
||||
|
||||
console.log('The solution is: ', rows[0].solution);
|
||||
});
|
||||
|
||||
pool = mysql.createPool({
|
||||
host: 'example.org',
|
||||
user: 'bob',
|
||||
password: 'secret'
|
||||
});
|
||||
|
||||
pool.getConnection(function (err, connection) {
|
||||
// connected! (unless `err` is set)
|
||||
});
|
||||
|
||||
pool.on('connection', function (connection) {
|
||||
connection.query('SET SESSION auto_increment_increment=1')
|
||||
});
|
||||
|
||||
pool.getConnection(function (err, connection) {
|
||||
// Use the connection
|
||||
connection.query('SELECT something FROM sometable', function (err, rows) {
|
||||
// And done with the connection.
|
||||
connection.release();
|
||||
|
||||
// Don't use the connection here, it has been returned to the pool.
|
||||
});
|
||||
});
|
||||
|
||||
/// PoolClusters
|
||||
|
||||
// create
|
||||
var poolCluster = mysql.createPoolCluster();
|
||||
|
||||
poolCluster.add(poolConfig); // anonymous group
|
||||
poolCluster.add('MASTER', poolConfig);
|
||||
poolCluster.add('SLAVE1', poolConfig);
|
||||
poolCluster.add('SLAVE2', poolConfig);
|
||||
|
||||
// Target Group : ALL(anonymous, MASTER, SLAVE1-2), Selector : round-robin(default)
|
||||
poolCluster.getConnection(function (err, connection) { });
|
||||
|
||||
// Target Group : MASTER, Selector : round-robin
|
||||
poolCluster.getConnection('MASTER', function (err, connection) { });
|
||||
|
||||
// Target Group : SLAVE1-2, Selector : order
|
||||
// If can't connect to SLAVE1, return SLAVE2. (remove SLAVE1 in the cluster)
|
||||
poolCluster.on('remove', function (nodeId) {
|
||||
console.log('REMOVED NODE : ' + nodeId); // nodeId = SLAVE1
|
||||
});
|
||||
|
||||
poolCluster.getConnection('SLAVE*', 'ORDER', function (err, connection) { });
|
||||
|
||||
// of namespace : of(pattern, selector)
|
||||
poolCluster.of('*').getConnection(function (err, connection) { });
|
||||
|
||||
var pool = poolCluster.of('SLAVE*', 'RANDOM');
|
||||
pool.getConnection(function (err, connection) { });
|
||||
pool.getConnection(function (err, connection) { });
|
||||
|
||||
// destroy
|
||||
poolCluster.end();
|
||||
|
||||
/// Queries
|
||||
|
||||
var query = connection.query('SELECT * FROM posts');
|
||||
query
|
||||
.on('error', function (err) {
|
||||
// Handle error, an 'end' event will be emitted after this as well
|
||||
})
|
||||
.on('fields', function (fields) {
|
||||
// the field packets for the rows to follow
|
||||
})
|
||||
.on('result', function (row) {
|
||||
// Pausing the connnection is useful if your processing involves I/O
|
||||
connection.pause();
|
||||
|
||||
var processRow = (row: any, cb: () => void) => {
|
||||
cb();
|
||||
};
|
||||
|
||||
processRow(row, function () {
|
||||
connection.resume();
|
||||
});
|
||||
})
|
||||
.on('end', function () {
|
||||
// all rows have been received
|
||||
});
|
||||
|
||||
connection.query('SELECT * FROM posts')
|
||||
.stream({ highWaterMark: 5 })
|
||||
.pipe(() => { });
|
||||
|
||||
connection = mysql.createConnection({ multipleStatements: true });
|
||||
|
||||
connection.query('SELECT 1; SELECT 2', function (err, results) {
|
||||
if (err) throw err;
|
||||
|
||||
// `results` is an array with one element for every statement in the query:
|
||||
console.log(results[0]); // [{1: 1}]
|
||||
console.log(results[1]); // [{2: 2}]
|
||||
});
|
||||
|
||||
var query = connection.query('SELECT 1; SELECT 2');
|
||||
|
||||
query
|
||||
.on('fields', function (fields, index) {
|
||||
// the fields for the result rows that follow
|
||||
})
|
||||
.on('result', function (row, index) {
|
||||
// index refers to the statement this result belongs to (starts at 0)
|
||||
});
|
||||
|
||||
var options = { sql: '...', nestTables: true };
|
||||
|
||||
connection.query(options, function (err, results) {
|
||||
/* results will be an array like this now:
|
||||
[{
|
||||
table1: {
|
||||
fieldA: '...',
|
||||
fieldB: '...',
|
||||
},
|
||||
table2: {
|
||||
fieldA: '...',
|
||||
fieldB: '...',
|
||||
},
|
||||
}, ...]
|
||||
*/
|
||||
});
|
||||
|
||||
connection.beginTransaction(function (err) {
|
||||
var title = 'title';
|
||||
|
||||
if (err) { throw err; }
|
||||
connection.query('INSERT INTO posts SET title=?', title, function (err, result) {
|
||||
if (err) {
|
||||
connection.rollback(function () {
|
||||
throw err;
|
||||
});
|
||||
}
|
||||
|
||||
var log = 'Post ' + result.insertId + ' added';
|
||||
|
||||
connection.query('INSERT INTO log SET data=?', log, function (err, result) {
|
||||
if (err) {
|
||||
connection.rollback(function () {
|
||||
throw err;
|
||||
});
|
||||
}
|
||||
connection.commit(function (err) {
|
||||
if (err) {
|
||||
connection.rollback(function () {
|
||||
throw err;
|
||||
});
|
||||
}
|
||||
console.log('success!');
|
||||
});
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
// Kill query after 60s
|
||||
connection.query({ sql: 'SELECT COUNT(*) AS count FROM big_table', timeout: 60000 }, function (err, rows) {
|
||||
if (err && err.code === 'PROTOCOL_SEQUENCE_TIMEOUT') {
|
||||
throw new Error('too long to count table rows!');
|
||||
}
|
||||
|
||||
if (err) {
|
||||
throw err;
|
||||
}
|
||||
|
||||
console.log(rows[0].count + ' rows');
|
||||
});
|
||||
|
||||
connection = mysql.createConnection({
|
||||
port: 84943, // WRONG PORT
|
||||
});
|
||||
|
||||
connection.connect(function (err) {
|
||||
console.log(err.code); // 'ECONNREFUSED'
|
||||
console.log(err.fatal); // true
|
||||
});
|
||||
|
||||
connection.query('SELECT 1', function (err) {
|
||||
console.log(err.code); // 'ECONNREFUSED'
|
||||
console.log(err.fatal); // true
|
||||
});
|
||||
|
||||
connection.query('USE name_of_db_that_does_not_exist', function (err, rows) {
|
||||
console.log(err.code); // 'ER_BAD_DB_ERROR'
|
||||
});
|
||||
|
||||
connection.query('SELECT 1', function (err, rows) {
|
||||
console.log(err); // null
|
||||
console.log(rows.length); // 1
|
||||
});
|
||||
|
||||
connection.on('error', function (err) {
|
||||
console.log(err.code); // 'ER_BAD_DB_ERROR'
|
||||
});
|
||||
|
||||
connection.query('USE name_of_db_that_does_not_exist');
|
||||
|
||||
// I am Chuck Norris:
|
||||
connection.on('error', function () { });
|
||||
|
||||
connection = mysql.createConnection({ typeCast: false });
|
||||
|
||||
var query = connection.query({ sql: '...', typeCast: false }, function (err, results) {
|
||||
|
||||
});
|
||||
|
||||
connection.query({
|
||||
sql: '...',
|
||||
typeCast: function (field: any, next: Function) {
|
||||
if (field.type == 'TINY' && field.length == 1) {
|
||||
return (field.string() == '1'); // 1 = true, 0 = false
|
||||
}
|
||||
return next();
|
||||
}
|
||||
});
|
||||
|
||||
connection = mysql.createConnection("mysql://localhost/test?flags=-FOUND_ROWS");
|
||||
connection = mysql.createConnection({ debug: true });
|
||||
connection = mysql.createConnection({ debug: ['ComQueryPacket', 'RowDataPacket'] });
|
||||
Vendored
+487
@@ -0,0 +1,487 @@
|
||||
// Type definitions for node-mysql
|
||||
// Project: https://github.com/felixge/node-mysql
|
||||
// Definitions by: William Johnston <https://github.com/wjohnsto>
|
||||
// Definitions: https://github.com/borisyankov/DefinitelyTyped
|
||||
|
||||
declare module mysql {
|
||||
export interface IMySql {
|
||||
createConnection(connectionUri: string): IConnection;
|
||||
createConnection(config: IConnectionConfig): IConnection;
|
||||
|
||||
createPool(config: IPoolConfig): IPool;
|
||||
|
||||
createPoolCluster(config?: IPoolClusterConfig): IPoolCluster;
|
||||
|
||||
escape(value: any): string;
|
||||
|
||||
format(sql: string): string;
|
||||
format(sql: string, values: Array<any>): string;
|
||||
}
|
||||
|
||||
export interface IConnectionStatic {
|
||||
createQuery(sql: string): IQuery;
|
||||
createQuery(sql: string, callback: (err: IError, ...args: any[]) => void): IQuery;
|
||||
createQuery(sql: string, values: Array<any>): IQuery;
|
||||
createQuery(sql: string, values: Array<any>, callback: (err: IError, ...args: any[]) => void): IQuery;
|
||||
}
|
||||
|
||||
export interface IConnection {
|
||||
config: IConnectionConfig;
|
||||
|
||||
threadId: number;
|
||||
|
||||
beginTransaction(callback: (err: IError) => void): void;
|
||||
|
||||
connect(): void;
|
||||
connect(callback: (err: IError, ...args: any[]) => void): void;
|
||||
connect(options: any, callback?: (err: IError, ...args: any[]) => void): void;
|
||||
|
||||
commit(callback: (err: IError) => void): void;
|
||||
|
||||
changeUser(options: IConnectionOptions): void;
|
||||
changeUser(options: IConnectionOptions, callback: (err: IError) => void): void;
|
||||
|
||||
query: IQueryFunction;
|
||||
|
||||
end(): void;
|
||||
end(callback: (err: IError, ...args: any[]) => void): void;
|
||||
end(options: any, callback: (err: IError, ...args: any[]) => void): void;
|
||||
|
||||
destroy(): void;
|
||||
|
||||
pause(): void;
|
||||
|
||||
release(): void;
|
||||
resume(): void;
|
||||
|
||||
escape(value: any): string;
|
||||
|
||||
escapeId(value: string): string;
|
||||
escapeId(values: Array<string>): string;
|
||||
|
||||
format(sql: string): string;
|
||||
format(sql: string, values: Array<any>): string;
|
||||
|
||||
on(ev: string, callback: (...args: any[]) => void): IConnection;
|
||||
on(ev: 'error', callback: (err: IError) => void): IConnection;
|
||||
|
||||
rollback(callback: () => void): void;
|
||||
}
|
||||
|
||||
export interface IPool {
|
||||
config: IPoolConfig;
|
||||
|
||||
getConnection(callback: (err: IError, connection: IConnection) => void): void;
|
||||
|
||||
query: IQueryFunction;
|
||||
|
||||
on(ev: string, callback: (...args: any[]) => void): IPool;
|
||||
on(ev: 'connection', callback: (connection: IConnection) => void): IPool;
|
||||
on(ev: 'error', callback: (err: IError) => void): IPool;
|
||||
}
|
||||
|
||||
export interface IPoolCluster {
|
||||
config: IPoolClusterConfig;
|
||||
|
||||
add(config: IPoolConfig): void;
|
||||
add(group: string, config: IPoolConfig): void;
|
||||
|
||||
end(): void;
|
||||
|
||||
getConnection(callback: (err: IError, connection: IConnection) => void): void;
|
||||
getConnection(group: string, callback: (err: IError, connection: IConnection) => void): void;
|
||||
getConnection(group: string, selector: string, callback: (err: IError, connection: IConnection) => void): void;
|
||||
|
||||
of(pattern: string): IPool;
|
||||
of(pattern: string, selector: string): IPool;
|
||||
|
||||
on(ev: string, callback: (...args: any[]) => void): IPoolCluster;
|
||||
on(ev: 'remove', callback: (nodeId: number) => void): IPoolCluster;
|
||||
on(ev: 'connection', callback: (connection: IConnection) => void): IPoolCluster;
|
||||
on(ev: 'error', callback: (err: IError) => void): IPoolCluster;
|
||||
}
|
||||
|
||||
export interface IQuery {
|
||||
/**
|
||||
* The SQL for a constructed query
|
||||
*/
|
||||
sql: string;
|
||||
|
||||
/**
|
||||
* Emits a query packet to start the query
|
||||
*/
|
||||
start(): void;
|
||||
|
||||
/**
|
||||
* Determines the packet class to use given the first byte of the packet.
|
||||
*
|
||||
* @param firstByte The first byte of the packet
|
||||
* @param parser The packet parser
|
||||
*/
|
||||
determinePacket(firstByte: number, parser: any): any;
|
||||
|
||||
/**
|
||||
* Creates a Readable stream with the given options
|
||||
*
|
||||
* @param options The options for the stream.
|
||||
*/
|
||||
stream(options: IStreamOptions): IQuery;
|
||||
|
||||
/**
|
||||
* Pipes a stream downstream, providing automatic pause/resume based on the
|
||||
* options sent to the stream.
|
||||
*
|
||||
* @param options The options for the stream.
|
||||
*/
|
||||
pipe(callback: (...args: any[]) => void): IQuery;
|
||||
|
||||
on(ev: string, callback: (...args: any[]) => void): IQuery;
|
||||
on(ev: 'error', callback: (err: IError) => void): IQuery;
|
||||
on(ev: 'fields', callback: (fields: any, index: number) => void): IQuery;
|
||||
on(ev: 'result', callback: (row: any, index: number) => void): IQuery;
|
||||
on(ev: 'end', callback: () => void): IQuery;
|
||||
}
|
||||
|
||||
export interface IQueryFunction {
|
||||
(sql: string): IQuery;
|
||||
(sql: string, callback: (err: IError, ...args: any[]) => void): IQuery;
|
||||
(sql: string, values: Array<any>): IQuery;
|
||||
(sql: string, values: Array<any>, callback: (err: IError, ...args: any[]) => void): IQuery;
|
||||
(sql: string, values: any): IQuery;
|
||||
(sql: string, values: any, callback: (err: IError, ...args: any[]) => void): IQuery;
|
||||
(options: IQueryOptions): IQuery;
|
||||
(options: IQueryOptions, callback: (err: IError, ...args: any[]) => void): IQuery;
|
||||
(options: IQueryOptions, values: Array<any>): IQuery;
|
||||
(options: IQueryOptions, values: Array<any>, callback: (err: IError, ...args: any[]) => void): IQuery;
|
||||
(options: IQueryOptions, values: any): IQuery;
|
||||
(options: IQueryOptions, values: any, callback: (err: IError, ...args: any[]) => void): IQuery;
|
||||
}
|
||||
|
||||
export interface IQueryOptions {
|
||||
/**
|
||||
* The SQL for the query
|
||||
*/
|
||||
sql: string;
|
||||
|
||||
/**
|
||||
* Every operation takes an optional inactivity timeout option. This allows you to specify appropriate timeouts for
|
||||
* operations. It is important to note that these timeouts are not part of the MySQL protocol, and rather timeout
|
||||
* operations through the client. This means that when a timeout is reached, the connection it occurred on will be
|
||||
* destroyed and no further operations can be performed.
|
||||
*/
|
||||
timeout?: number;
|
||||
|
||||
/**
|
||||
* Either a boolean or string. If true, tables will be nested objects. If string (e.g. '_'), tables will be
|
||||
* nested as tableName_fieldName
|
||||
*/
|
||||
nestTables?: any;
|
||||
|
||||
/**
|
||||
* Determines if column values should be converted to native JavaScript types. It is not recommended (and may go away / change in the future)
|
||||
* to disable type casting, but you can currently do so on either the connection or query level. (Default: true)
|
||||
*
|
||||
* You can also specify a function (field: any, next: () => void) => {} to do the type casting yourself.
|
||||
*
|
||||
* WARNING: YOU MUST INVOKE the parser using one of these three field functions in your custom typeCast callback. They can only be called once.
|
||||
*
|
||||
* field.string()
|
||||
* field.buffer()
|
||||
* field.geometry()
|
||||
*
|
||||
* are aliases for
|
||||
*
|
||||
* parser.parseLengthCodedString()
|
||||
* parser.parseLengthCodedBuffer()
|
||||
* parser.parseGeometryValue()
|
||||
*
|
||||
* You can find which field function you need to use by looking at: RowDataPacket.prototype._typeCast
|
||||
*/
|
||||
typeCast?: any;
|
||||
}
|
||||
|
||||
export interface IStreamOptions {
|
||||
/**
|
||||
* Sets the max buffer size in objects of a stream
|
||||
*/
|
||||
highWaterMark?: number;
|
||||
|
||||
/**
|
||||
* The object mode of the stream (Default: true)
|
||||
*/
|
||||
objectMode?: any;
|
||||
}
|
||||
|
||||
export interface IConnectionOptions {
|
||||
/**
|
||||
* The MySQL user to authenticate as
|
||||
*/
|
||||
user?: string;
|
||||
|
||||
/**
|
||||
* The password of that MySQL user
|
||||
*/
|
||||
password?: string;
|
||||
|
||||
/**
|
||||
* Name of the database to use for this connection
|
||||
*/
|
||||
database?: string;
|
||||
|
||||
/**
|
||||
* The charset for the connection. This is called "collation" in the SQL-level of MySQL (like utf8_general_ci).
|
||||
* If a SQL-level charset is specified (like utf8mb4) then the default collation for that charset is used.
|
||||
* (Default: 'UTF8_GENERAL_CI')
|
||||
*/
|
||||
charset?: string;
|
||||
}
|
||||
|
||||
export interface IConnectionConfig extends IConnectionOptions {
|
||||
/**
|
||||
* The hostname of the database you are connecting to. (Default: localhost)
|
||||
*/
|
||||
host?: string;
|
||||
|
||||
/**
|
||||
* The port number to connect to. (Default: 3306)
|
||||
*/
|
||||
port?: number;
|
||||
|
||||
/**
|
||||
* The source IP address to use for TCP connection
|
||||
*/
|
||||
localAddress?: string;
|
||||
|
||||
/**
|
||||
* The path to a unix domain socket to connect to. When used host and port are ignored
|
||||
*/
|
||||
socketPath?: string;
|
||||
|
||||
/**
|
||||
* The timezone used to store local dates. (Default: 'local')
|
||||
*/
|
||||
timezone?: string;
|
||||
|
||||
/**
|
||||
* The milliseconds before a timeout occurs during the initial connection to the MySQL server. (Default: 10 seconds)
|
||||
*/
|
||||
connectTimeout?: number;
|
||||
|
||||
/**
|
||||
* Stringify objects instead of converting to values. (Default: 'false')
|
||||
*/
|
||||
stringifyObjects?: boolean;
|
||||
|
||||
/**
|
||||
* Allow connecting to MySQL instances that ask for the old (insecure) authentication method. (Default: false)
|
||||
*/
|
||||
insecureAuth?: boolean;
|
||||
|
||||
/**
|
||||
* Determines if column values should be converted to native JavaScript types. It is not recommended (and may go away / change in the future)
|
||||
* to disable type casting, but you can currently do so on either the connection or query level. (Default: true)
|
||||
*
|
||||
* You can also specify a function (field: any, next: () => void) => {} to do the type casting yourself.
|
||||
*
|
||||
* WARNING: YOU MUST INVOKE the parser using one of these three field functions in your custom typeCast callback. They can only be called once.
|
||||
*
|
||||
* field.string()
|
||||
* field.buffer()
|
||||
* field.geometry()
|
||||
*
|
||||
* are aliases for
|
||||
*
|
||||
* parser.parseLengthCodedString()
|
||||
* parser.parseLengthCodedBuffer()
|
||||
* parser.parseGeometryValue()
|
||||
*
|
||||
* You can find which field function you need to use by looking at: RowDataPacket.prototype._typeCast
|
||||
*/
|
||||
typeCast?: any;
|
||||
|
||||
/**
|
||||
* A custom query format function
|
||||
*/
|
||||
queryFormat?: (query: string, values: any) => void;
|
||||
|
||||
/**
|
||||
* When dealing with big numbers (BIGINT and DECIMAL columns) in the database, you should enable this option
|
||||
* (Default: false)
|
||||
*/
|
||||
supportBigNumbers?: boolean;
|
||||
|
||||
/**
|
||||
* Enabling both supportBigNumbers and bigNumberStrings forces big numbers (BIGINT and DECIMAL columns) to be
|
||||
* always returned as JavaScript String objects (Default: false). Enabling supportBigNumbers but leaving
|
||||
* bigNumberStrings disabled will return big numbers as String objects only when they cannot be accurately
|
||||
* represented with [JavaScript Number objects] (http://ecma262-5.com/ELS5_HTML.htm#Section_8.5)
|
||||
* (which happens when they exceed the [-2^53, +2^53] range), otherwise they will be returned as Number objects.
|
||||
* This option is ignored if supportBigNumbers is disabled.
|
||||
*/
|
||||
bigNumberStrings?: boolean;
|
||||
|
||||
/**
|
||||
* Force date types (TIMESTAMP, DATETIME, DATE) to be returned as strings rather then inflated into JavaScript Date
|
||||
* objects. (Default: false)
|
||||
*/
|
||||
dateStrings?: boolean;
|
||||
|
||||
/**
|
||||
* This will print all incoming and outgoing packets on stdout.
|
||||
* You can also restrict debugging to packet types by passing an array of types (strings) to debug;
|
||||
*
|
||||
* (Default: false)
|
||||
*/
|
||||
debug?: any;
|
||||
|
||||
/**
|
||||
* Generates stack traces on Error to include call site of library entrance ("long stack traces"). Slight
|
||||
* performance penalty for most calls. (Default: true)
|
||||
*/
|
||||
trace?: boolean;
|
||||
|
||||
/**
|
||||
* Allow multiple mysql statements per query. Be careful with this, it exposes you to SQL injection attacks. (Default: false)
|
||||
*/
|
||||
multipleStatements?: boolean;
|
||||
|
||||
/**
|
||||
* List of connection flags to use other than the default ones. It is also possible to blacklist default ones
|
||||
*/
|
||||
flags?: Array<string>;
|
||||
|
||||
/**
|
||||
* object with ssl parameters or a string containing name of ssl profile
|
||||
*/
|
||||
ssl?: any;
|
||||
}
|
||||
|
||||
export interface IPoolConfig extends IConnectionConfig {
|
||||
/**
|
||||
* The milliseconds before a timeout occurs during the connection acquisition. This is slightly different from connectTimeout,
|
||||
* because acquiring a pool connection does not always involve making a connection. (Default: 10 seconds)
|
||||
*/
|
||||
acquireTimeout?: number;
|
||||
|
||||
/**
|
||||
* Determines the pool's action when no connections are available and the limit has been reached. If true, the pool will queue
|
||||
* the connection request and call it when one becomes available. If false, the pool will immediately call back with an error.
|
||||
* (Default: true)
|
||||
*/
|
||||
waitForConnections?: boolean;
|
||||
|
||||
/**
|
||||
* The maximum number of connections to create at once. (Default: 10)
|
||||
*/
|
||||
connectionLimit?: number;
|
||||
|
||||
/**
|
||||
* The maximum number of connection requests the pool will queue before returning an error from getConnection. If set to 0, there
|
||||
* is no limit to the number of queued connection requests. (Default: 0)
|
||||
*/
|
||||
queueLimit?: number;
|
||||
}
|
||||
|
||||
export interface IPoolClusterConfig {
|
||||
/**
|
||||
* If true, PoolCluster will attempt to reconnect when connection fails. (Default: true)
|
||||
*/
|
||||
canRetry?: boolean;
|
||||
|
||||
/**
|
||||
* If connection fails, node's errorCount increases. When errorCount is greater than removeNodeErrorCount,
|
||||
* remove a node in the PoolCluster. (Default: 5)
|
||||
*/
|
||||
removeNodeErrorCount?: number;
|
||||
|
||||
/**
|
||||
* The default selector. (Default: RR)
|
||||
* RR: Select one alternately. (Round-Robin)
|
||||
* RANDOM: Select the node by random function.
|
||||
* ORDER: Select the first node available unconditionally.
|
||||
*/
|
||||
defaultSelector?: string;
|
||||
}
|
||||
|
||||
export interface ISslCredentials {
|
||||
/**
|
||||
* A string or buffer holding the PFX or PKCS12 encoded private key, certificate and CA certificates
|
||||
*/
|
||||
pfx?: string;
|
||||
|
||||
/**
|
||||
* A string holding the PEM encoded private key
|
||||
*/
|
||||
key?: string;
|
||||
|
||||
/**
|
||||
* A string of passphrase for the private key or pfx
|
||||
*/
|
||||
passphrase?: string;
|
||||
|
||||
/**
|
||||
* A string holding the PEM encoded certificate
|
||||
*/
|
||||
cert?: string;
|
||||
|
||||
/**
|
||||
* Either a string or list of strings of PEM encoded CA certificates to trust.
|
||||
*/
|
||||
ca?: Array<string>;
|
||||
|
||||
/**
|
||||
* Either a string or list of strings of PEM encoded CRLs (Certificate Revocation List)
|
||||
*/
|
||||
crl?: Array<string>;
|
||||
|
||||
/**
|
||||
* A string describing the ciphers to use or exclude
|
||||
*/
|
||||
ciphers?: string;
|
||||
}
|
||||
|
||||
export interface IError extends Error {
|
||||
/**
|
||||
* Either a MySQL server error (e.g. 'ER_ACCESS_DENIED_ERROR'),
|
||||
* a node.js error (e.g. 'ECONNREFUSED') or an internal error
|
||||
* (e.g. 'PROTOCOL_CONNECTION_LOST').
|
||||
*/
|
||||
code: string;
|
||||
|
||||
/**
|
||||
* The error number for the error code
|
||||
*/
|
||||
errno: number;
|
||||
|
||||
/**
|
||||
* The sql state marker
|
||||
*/
|
||||
sqlStateMarker?: string;
|
||||
|
||||
/**
|
||||
* The sql state
|
||||
*/
|
||||
sqlState?: string;
|
||||
|
||||
/**
|
||||
* The field count
|
||||
*/
|
||||
fieldCount?: number;
|
||||
|
||||
/**
|
||||
* The stack trace for the error
|
||||
*/
|
||||
stack?: string;
|
||||
|
||||
/**
|
||||
* Boolean, indicating if this error is terminal to the connection object.
|
||||
*/
|
||||
fatal: boolean;
|
||||
}
|
||||
}
|
||||
|
||||
declare module 'mysql' {
|
||||
var mysql: mysql.IMySql;
|
||||
|
||||
export = mysql;
|
||||
}
|
||||
@@ -0,0 +1,108 @@
|
||||
/// <reference path="needle.d.ts" />
|
||||
|
||||
import needle = require("needle");
|
||||
|
||||
function Usage() {
|
||||
// using callback
|
||||
needle.get('http://ifconfig.me/all.json', function (error, response) {
|
||||
if (!error)
|
||||
console.log(response.body.ip_addr); // JSON decoding magic. :)
|
||||
});
|
||||
|
||||
// using streams
|
||||
var out: any; // = fs.createWriteStream('logo.png');
|
||||
needle.get('https://google.com/images/logo.png').pipe(out);
|
||||
}
|
||||
|
||||
function ResponsePipeline() {
|
||||
needle.get('http://stackoverflow.com/feeds', { compressed: true }, function (err, resp) {
|
||||
console.log(resp.body); // this little guy won't be a Gzipped binary blob
|
||||
// but a nice object containing all the latest entries
|
||||
});
|
||||
|
||||
var options = {
|
||||
compressed: true,
|
||||
follow: true,
|
||||
rejectUnauthorized: true
|
||||
};
|
||||
|
||||
// in this case, we'll ask Needle to follow redirects (disabled by default),
|
||||
// but also to verify their SSL certificates when connecting.
|
||||
var stream = needle.get('https://backend.server.com/everything.html', options);
|
||||
|
||||
stream.on('readable', function () {
|
||||
var data: any;
|
||||
while (data = this.read()) {
|
||||
console.log(data.toString());
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
function API_head() {
|
||||
var options = {
|
||||
timeout: 5000 // if we don't get a response in 5 seconds, boom.
|
||||
};
|
||||
|
||||
needle.head('https://my.backend.server.com', function (err, resp) {
|
||||
if (err) {
|
||||
console.log('Shoot! Something is wrong: ' + err.message);
|
||||
}
|
||||
else {
|
||||
console.log('Yup, still alive.');
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
function API_get() {
|
||||
needle.get('google.com/search?q=syd+barrett', function (err, resp) {
|
||||
// if no http:// is found, Needle will automagically prepend it.
|
||||
});
|
||||
}
|
||||
|
||||
function API_post() {
|
||||
var options = {
|
||||
headers: { 'X-Custom-Header': 'Bumbaway atuna' }
|
||||
};
|
||||
|
||||
needle.post('https://my.app.com/endpoint', 'foo=bar', options, function (err, resp) {
|
||||
// you can pass params as a string or as an object.
|
||||
});
|
||||
}
|
||||
|
||||
function API_put() {
|
||||
var nested = {
|
||||
params: {
|
||||
are: {
|
||||
also: 'supported'
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
needle.put('https://api.app.com/v2', nested, function (err, resp) {
|
||||
console.log('Got ' + resp.bytes + ' bytes.') // another nice treat from this handsome fella.
|
||||
});
|
||||
}
|
||||
|
||||
function API_delete() {
|
||||
var options = {
|
||||
username: 'fidelio',
|
||||
password: 'x'
|
||||
};
|
||||
|
||||
needle.delete('https://api.app.com/messages/123', null, options, function (err, resp) {
|
||||
// in this case, data may be null, but you need to explicity pass it.
|
||||
});
|
||||
}
|
||||
|
||||
function API_request() {
|
||||
var data = {
|
||||
q: 'a very smart query',
|
||||
page: 2,
|
||||
format: 'json'
|
||||
};
|
||||
|
||||
needle.request('get', 'forum.com/search', data, function (err, resp) {
|
||||
if (!err && resp.statusCode == 200)
|
||||
console.log(resp.body); // here you go, mister.
|
||||
});
|
||||
}
|
||||
Vendored
+88
@@ -0,0 +1,88 @@
|
||||
// Type definitions for needle 0.7.8
|
||||
// Project: https://github.com/tomas/needle
|
||||
// Definitions by: San Chen <https://github.com/bigsan>
|
||||
// Definitions: https://github.com/borisyankov/DefinitelyTyped
|
||||
|
||||
/// <reference path="../node/node.d.ts" />
|
||||
|
||||
declare module Needle {
|
||||
interface ReadableStream extends NodeJS.ReadableStream {
|
||||
}
|
||||
|
||||
interface Callback {
|
||||
(error: Error, response: any, body: any): void;
|
||||
}
|
||||
|
||||
interface RequestOptions {
|
||||
timeout?: number;
|
||||
follow?: any; // number | string
|
||||
multipart?: boolean;
|
||||
proxy?: string;
|
||||
agent?: string;
|
||||
headers?: any;
|
||||
auth?: string; // auto | digest | basic (default)
|
||||
json?: boolean;
|
||||
}
|
||||
|
||||
interface ResponseOptions {
|
||||
decode?: boolean;
|
||||
parse?: boolean;
|
||||
output?: any;
|
||||
}
|
||||
|
||||
interface HttpHeaderOptions {
|
||||
compressed?: boolean;
|
||||
username?: string;
|
||||
password?: string;
|
||||
accept?: string;
|
||||
connection?: string;
|
||||
user_agent?: string;
|
||||
}
|
||||
|
||||
interface TLSOptions {
|
||||
pfx?: any;
|
||||
key?: any;
|
||||
passphrase?: string;
|
||||
cert?: any;
|
||||
ca?: any;
|
||||
ciphers?: any;
|
||||
rejectUnauthorized?: boolean;
|
||||
secureProtocol?: any;
|
||||
}
|
||||
|
||||
interface NeedleOptions extends RequestOptions, ResponseOptions, HttpHeaderOptions, TLSOptions {
|
||||
}
|
||||
|
||||
interface NeedleStatic {
|
||||
defaults(options?: any): void;
|
||||
|
||||
head(url: string): ReadableStream;
|
||||
head(url: string, callback?: Callback): ReadableStream;
|
||||
head(url: string, options?: RequestOptions, callback?: Callback): ReadableStream;
|
||||
|
||||
get(url: string): ReadableStream;
|
||||
get(url: string, callback?: Callback): ReadableStream;
|
||||
get(url: string, options?: RequestOptions, callback?: Callback): ReadableStream;
|
||||
|
||||
post(url: string, data: any): ReadableStream;
|
||||
post(url: string, data: any, callback?: Callback): ReadableStream;
|
||||
post(url: string, data: any, options?: RequestOptions, callback?: Callback): ReadableStream;
|
||||
|
||||
put(url: string, data: any): ReadableStream;
|
||||
put(url: string, data: any, callback?: Callback): ReadableStream;
|
||||
put(url: string, data: any, options?: RequestOptions, callback?: Callback): ReadableStream;
|
||||
|
||||
delete(url: string, data: any): ReadableStream;
|
||||
delete(url: string, data: any, callback?: Callback): ReadableStream;
|
||||
delete(url: string, data: any, options?: RequestOptions, callback?: Callback): ReadableStream;
|
||||
|
||||
request(method: string, url: string, data: any): ReadableStream;
|
||||
request(method: string, url: string, data: any, callback?: Callback): ReadableStream;
|
||||
request(method: string, url: string, data: any, options?: RequestOptions, callback?: Callback): ReadableStream;
|
||||
}
|
||||
}
|
||||
|
||||
declare module "needle" {
|
||||
var needle: Needle.NeedleStatic;
|
||||
export = needle;
|
||||
}
|
||||
Vendored
+32
-2
@@ -1,6 +1,6 @@
|
||||
// Type definitions for PhoneGap 2.3
|
||||
// Project: http://phonegap.com
|
||||
// Definitions by: Boris Yankov <https://github.com/borisyankov/>
|
||||
// Definitions by: Boris Yankov <https://github.com/borisyankov/>, Dick van den Brink <https://github.com/DickvdBrink>
|
||||
// Definitions: https://github.com/borisyankov/DefinitelyTyped
|
||||
|
||||
interface GeolocationError {
|
||||
@@ -367,7 +367,7 @@ interface FileUploadResult {
|
||||
|
||||
interface Flags {
|
||||
create: boolean;
|
||||
exclusive: boolean;
|
||||
exclusive?: boolean;
|
||||
}
|
||||
|
||||
/*
|
||||
@@ -575,6 +575,36 @@ interface LocalStorage {
|
||||
}
|
||||
*/
|
||||
|
||||
interface StatusBar {
|
||||
isVisible: boolean;
|
||||
|
||||
overlaysWebView(doOverlay: boolean): void;
|
||||
styleDefault(): void;
|
||||
styleLightContent(): void;
|
||||
styleBlackTranslucent(): void;
|
||||
styleBlackOpaque(): void;
|
||||
backgroundColorByName(colorname: string): void;
|
||||
backgroundColorByHexString(hexString: string): void;
|
||||
hide(): void;
|
||||
show(): void;
|
||||
}
|
||||
declare var StatusBar: StatusBar;
|
||||
|
||||
interface Keyboard {
|
||||
automaticScrollToTopOnHiding: boolean;
|
||||
isVisible: boolean;
|
||||
|
||||
onshow: Function;
|
||||
onhide: Function;
|
||||
onshowing: Function;
|
||||
onhiding: Function;
|
||||
|
||||
disableScrollingInShrinkView(disable: boolean): void;
|
||||
hideFormAccessoryBar(hide: boolean): void;
|
||||
shrinkView(shrink: boolean): void;
|
||||
}
|
||||
declare var Keyboard: Keyboard;
|
||||
|
||||
interface /*PhoneGapNavigator extends*/ Navigator {
|
||||
accelerometer: Accelerometer;
|
||||
camera: Camera;
|
||||
|
||||
Vendored
+3
-2
@@ -1472,8 +1472,9 @@ interface UnderscoreStatic {
|
||||
* @param settings Settings to use while compiling.
|
||||
* @return Returns the compiled Underscore HTML template.
|
||||
**/
|
||||
template(templateString: string, data?: any, settings?: _.TemplateSettings): (...data: any[]) => string;
|
||||
|
||||
template(templateString: string): (...data: any[]) => string;
|
||||
template(templateString: string, data: any, settings?: _.TemplateSettings): string;
|
||||
|
||||
/**
|
||||
* By default, Underscore uses ERB-style template delimiters, change the
|
||||
* following template settings to use alternative delimiters.
|
||||
|
||||
Reference in New Issue
Block a user