From 5a77a8a133c00f01547b9c10c7a50f780ff1d2d2 Mon Sep 17 00:00:00 2001 From: Audrey Date: Mon, 26 May 2014 10:22:29 -0400 Subject: [PATCH 1/9] Update watchExpressions definition for $watchGroup Per https://docs.angularjs.org/api/ng/type/$rootScope.Scope, the watchExpressions is an array of string OR Function(scope). Array. --- angularjs/angular.d.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/angularjs/angular.d.ts b/angularjs/angular.d.ts index f4cc59a04..1ee9079d3 100755 --- a/angularjs/angular.d.ts +++ b/angularjs/angular.d.ts @@ -236,7 +236,7 @@ declare module ng { $watchCollection(watchExpression: string, listener: (newValue: any, oldValue: any, scope: IScope) => any): Function; $watchCollection(watchExpression: (scope: IScope) => any, listener: (newValue: any, oldValue: any, scope: IScope) => any): Function; - $watchGroup(watchExpressions: string[], listener: (newValue: any, oldValue: any, scope: IScope) => any): Function; + $watchGroup(watchExpressions: any[], listener: (newValue: any, oldValue: any, scope: IScope) => any): Function; $watchGroup(watchExpressions: {(scope: IScope) : any}[], listener: (newValue: any, oldValue: any, scope: IScope) => any): Function; $parent: IScope; From 518fbb37c72340c7867f39232a60a42148f0d47c Mon Sep 17 00:00:00 2001 From: Bart van der Schoor Date: Mon, 26 May 2014 20:39:20 +0200 Subject: [PATCH 2/9] added filter method to minimatch and options optional --- minimatch/minimatch-tests.ts | 2 ++ minimatch/minimatch.d.ts | 13 +++++++------ 2 files changed, 9 insertions(+), 6 deletions(-) diff --git a/minimatch/minimatch-tests.ts b/minimatch/minimatch-tests.ts index a9f4f7e92..a4892ef35 100644 --- a/minimatch/minimatch-tests.ts +++ b/minimatch/minimatch-tests.ts @@ -11,3 +11,5 @@ var r = m.makeRe(); var f = ["test.ts"]; mm.match(f, pattern, options); + +mm.filter('foo')('bar'); diff --git a/minimatch/minimatch.d.ts b/minimatch/minimatch.d.ts index baf246394..e83d976a8 100644 --- a/minimatch/minimatch.d.ts +++ b/minimatch/minimatch.d.ts @@ -8,7 +8,8 @@ declare module "minimatch" { function M(target:string, pattern:string, options?:M.IOptions):void; module M { - function match(filenames:string[], pattern:string, options:IOptions):string[]; + function match(filenames:string[], pattern:string, options?:IOptions):string[]; + function filter(pattern:string, options?:IOptions): (target: string) => boolean; var Minimatch:IMinimatchStatic; @@ -27,7 +28,7 @@ declare module "minimatch" { } interface IMinimatchStatic { - new (pattern:string, options:IOptions):IMinimatch; + new (pattern:string, options?:IOptions):IMinimatch; } interface IMinimatch { @@ -36,11 +37,11 @@ declare module "minimatch" { parseNegate():void; braceExpand(pattern:string, options:IOptions):void; parse(pattern:string, isSub?:boolean):void; - makeRe():any; // regexp or boolean - match(file:string, pattern:string, options:IOptions):boolean; - matchOne(file:string, pattern:string, partial:any):boolean; + makeRe():RegExp; // regexp or boolean + match(file:string):boolean; + matchOne(files:string[], pattern:string[], partial:any):boolean; } } - export = M; +export = M; } From 15bcf54deed1b5293fd9af22e9a576960a2772c0 Mon Sep 17 00:00:00 2001 From: Bart van der Schoor Date: Mon, 26 May 2014 22:54:16 +0200 Subject: [PATCH 3/9] fixed lingering typo in semver --- semver/semver-tests.ts | 12 ++++++------ semver/semver.d.ts | 26 +++++++++++++------------- 2 files changed, 19 insertions(+), 19 deletions(-) diff --git a/semver/semver-tests.ts b/semver/semver-tests.ts index 009a47daf..bf0e794bc 100644 --- a/semver/semver-tests.ts +++ b/semver/semver-tests.ts @@ -10,7 +10,7 @@ var exp:RegExp; var strArr:string[]; var numArr:string[]; -var mod:typeof SemverModule; +var mod:typeof SemVerModule; var v1:string, v2:string; var version:string; @@ -42,7 +42,7 @@ bool = mod.gtr(version, str, loose); bool = mod.ltr(version, str, loose); bool = mod.outside(version, str, str, loose); -var ver = new mod.Semver(str, bool); +var ver = new mod.SemVer(str, bool); str = ver.raw; bool = ver.loose; str = ver.format(); @@ -62,7 +62,7 @@ num = ver.comparePre(ver); ver = ver.inc(str); -var comp = new SemverModule.Comparator(str, bool); +var comp = new SemVerModule.Comparator(str, bool); str = comp.raw; bool = comp.loose; str = comp.format(); @@ -76,7 +76,7 @@ comp.parse(str); bool = comp.test(ver); -var range = new SemverModule.Range(str, bool); +var range = new SemVerModule.Range(str, bool); str = range.raw; bool = range.loose; str = range.format(); @@ -85,8 +85,8 @@ str = range.toString(); bool = range.test(ver); -var sets:SemverModule.Comparator[][]; +var sets:SemVerModule.Comparator[][]; sets = range.set(); -var lims:SemverModule.Comparator[]; +var lims:SemVerModule.Comparator[]; lims = range.parseRange(str); diff --git a/semver/semver.d.ts b/semver/semver.d.ts index 67f536af5..89755df37 100644 --- a/semver/semver.d.ts +++ b/semver/semver.d.ts @@ -3,7 +3,7 @@ // Definitions by: Bart van der Schoor // Definitions: https://github.com/borisyankov/DefinitelyTyped -declare module SemverModule { +declare module SemVerModule { function valid(v:string, loose?:boolean):string; // Return the parsed version, or null if it's not valid. //TODO maybe add an enum for release? @@ -28,7 +28,7 @@ declare module SemverModule { function ltr(version:string, range:string, loose?:boolean):boolean; // Return true if version is less than all the versions possible in the range. function outside(version:string, range:string, hilo:string, loose?:boolean):boolean; // Return true if the version is outside the bounds of the range in either the high or low direction. The hilo argument must be either the string '>' or '<'. (This is the function called by gtr and ltr.) - class SemverBase { + class SemVerBase { raw:string; loose:boolean; format():string; @@ -36,7 +36,7 @@ declare module SemverModule { toString():string; } - class Semver extends SemverBase { + class SemVer extends SemVerBase { constructor(version:string, loose?:boolean); major:number; @@ -46,30 +46,30 @@ declare module SemverModule { build:string[]; prerelease:string[]; - compare(other:Semver):number; - compareMain(other:Semver):number; - comparePre(other:Semver):number; - inc(release:string):Semver; + compare(other:SemVer):number; + compareMain(other:SemVer):number; + comparePre(other:SemVer):number; + inc(release:string):SemVer; } - class Comparator extends SemverBase { + class Comparator extends SemVerBase { constructor(comp:string, loose?:boolean); - semver:Semver; + semver:SemVer; operator:string; value:boolean; parse(comp:string) :void; - test(version:Semver):boolean; + test(version:SemVer):boolean; } - class Range extends SemverBase { + class Range extends SemVerBase { constructor(range:string, loose?:boolean); set():Comparator[][]; parseRange(range:string):Comparator[]; - test(version:Semver):boolean; + test(version:SemVer):boolean; } } declare module "semver" { -export = SemverModule; +export = SemVerModule; } From 0823eb6b58939cfaff8bd4b51b3319020a653e59 Mon Sep 17 00:00:00 2001 From: Bart van der Schoor Date: Mon, 26 May 2014 23:34:18 +0200 Subject: [PATCH 4/9] fixed semver.Comparator.set --- semver/semver-tests.ts | 2 +- semver/semver.d.ts | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/semver/semver-tests.ts b/semver/semver-tests.ts index bf0e794bc..f339be75b 100644 --- a/semver/semver-tests.ts +++ b/semver/semver-tests.ts @@ -86,7 +86,7 @@ str = range.toString(); bool = range.test(ver); var sets:SemVerModule.Comparator[][]; -sets = range.set(); +sets = range.set; var lims:SemVerModule.Comparator[]; lims = range.parseRange(str); diff --git a/semver/semver.d.ts b/semver/semver.d.ts index 89755df37..12909d90e 100644 --- a/semver/semver.d.ts +++ b/semver/semver.d.ts @@ -65,7 +65,7 @@ declare module SemVerModule { class Range extends SemVerBase { constructor(range:string, loose?:boolean); - set():Comparator[][]; + set:Comparator[][]; parseRange(range:string):Comparator[]; test(version:SemVer):boolean; } From fc0f486ed2b451b71ecfd7d6ba9e18c2ba92dccc Mon Sep 17 00:00:00 2001 From: Bart van der Schoor Date: Tue, 27 May 2014 00:24:00 +0200 Subject: [PATCH 5/9] added definition for bl (BufferList) --- bl/bl-tests.ts | 68 ++++++++++++++++++++++++++++++++++++++++++++++++++ bl/bl.d.ts | 40 +++++++++++++++++++++++++++++ 2 files changed, 108 insertions(+) create mode 100644 bl/bl-tests.ts create mode 100644 bl/bl.d.ts diff --git a/bl/bl-tests.ts b/bl/bl-tests.ts new file mode 100644 index 000000000..96bfb8e3b --- /dev/null +++ b/bl/bl-tests.ts @@ -0,0 +1,68 @@ +/// + +import BufferList = require('bl'); + +var bl: BufferList; +var buffer: Buffer; +var offset: number; +var num: number; +var str: string; +var noAssert: boolean; + +bl = new BufferList(); +bl = new BufferList((err:Error, buffer:Buffer) => { + +}); + +bl.append(buffer); +num = bl.get(num); + +buffer = bl.slice(num, num); +buffer = bl.slice(num); +buffer = bl.slice(); + +bl.copy(buffer, num, num, num); +bl.copy(buffer, num, num); +bl.copy(buffer, num); +bl.copy(buffer); + +bl = bl.duplicate(); + +bl.consume(); +bl.consume(num); + +str = bl.toString(str, num, num); +str = bl.toString(str, num); +str = bl.toString(str); +str = bl.toString(); + +num = bl.length; + +buffer = bl.readDoubleBE(offset, noAssert); +buffer = bl.readDoubleBE(offset); +buffer = bl.readDoubleLE(offset, noAssert); +buffer = bl.readDoubleLE(offset); +buffer = bl.readFloatBE(offset, noAssert); +buffer = bl.readFloatBE(offset); +buffer = bl.readFloatLE(offset, noAssert); +buffer = bl.readFloatLE(offset); +buffer = bl.readInt32BE(offset, noAssert); +buffer = bl.readInt32BE(offset); +buffer = bl.readInt32LE(offset, noAssert); +buffer = bl.readInt32LE(offset); +buffer = bl.readUInt32BE(offset, noAssert); +buffer = bl.readUInt32BE(offset); +buffer = bl.readUInt32LE(offset, noAssert); +buffer = bl.readUInt32LE(offset); +buffer = bl.readInt16BE(offset, noAssert); +buffer = bl.readInt16BE(offset); +buffer = bl.readInt16LE(offset, noAssert); +buffer = bl.readInt16LE(offset); +buffer = bl.readUInt16BE(offset, noAssert); +buffer = bl.readUInt16BE(offset); +buffer = bl.readUInt16LE(offset, noAssert); +buffer = bl.readUInt16LE(offset); +buffer = bl.readInt8(offset, noAssert); +buffer = bl.readInt8(offset); +buffer = bl.readUInt8(offset, noAssert); +buffer = bl.readUInt8(offset); diff --git a/bl/bl.d.ts b/bl/bl.d.ts new file mode 100644 index 000000000..c277ea44b --- /dev/null +++ b/bl/bl.d.ts @@ -0,0 +1,40 @@ +// Type definitions for BufferList v0.8.0 +// Project: https://github.com/rvagg/bl +// Definitions by: Bart van der Schoor +// Definitions: https://github.com/borisyankov/DefinitelyTyped + +/// + +declare module 'bl' { + import stream = require('stream'); + + class BufferList extends stream.Duplex { + new (callback?:(err:Error, buffer:Buffer) => void): void; + + append(buffer: Buffer):void; + get(index: number): number; + slice(start?: number, end?: number): Buffer; + copy(dest: Buffer, destStart?: number, srcStart?: number, srcEnd?: number): void; + duplicate(): BufferList; + consume(bytes?: number): void; + toString(encoding?: string, start?: number, end?: number): string; + length: number; + + readDoubleBE(offset: number, noAssert?: boolean): Buffer; + readDoubleLE(offset: number, noAssert?: boolean): Buffer; + readFloatBE(offset: number, noAssert?: boolean): Buffer; + readFloatLE(offset: number, noAssert?: boolean): Buffer; + readInt32BE(offset: number, noAssert?: boolean): Buffer; + readInt32LE(offset: number, noAssert?: boolean): Buffer; + readUInt32BE(offset: number, noAssert?: boolean): Buffer; + readUInt32LE(offset: number, noAssert?: boolean): Buffer; + readInt16BE(offset: number, noAssert?: boolean): Buffer; + readInt16LE(offset: number, noAssert?: boolean): Buffer; + readUInt16BE(offset: number, noAssert?: boolean): Buffer; + readUInt16LE(offset: number, noAssert?: boolean): Buffer; + readInt8(offset: number, noAssert?: boolean): Buffer; + readUInt8(offset: number, noAssert?: boolean): Buffer; + } + + export = BufferList; +} From 790e8660966028799a862f0baf8b03207d507525 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?D=C3=A9nes=20Harmath?= Date: Wed, 28 May 2014 13:16:20 +0200 Subject: [PATCH 6/9] Fix wrong space --- elm/elm.d.ts | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/elm/elm.d.ts b/elm/elm.d.ts index 1185394be..dbc330fcb 100644 --- a/elm/elm.d.ts +++ b/elm/elm.d.ts @@ -18,11 +18,11 @@ interface ElmComponent

{ ports: P; } -interface PortToElm { +interface PortToElm { send(value: V): void; } interface PortFromElm { subscribe(handler: (value: V) => void): void; unsubscribe(handler: (value: V) => void): void; -} \ No newline at end of file +} From c61e78e7b2c37ad6405aac9768a2bb04af912ee8 Mon Sep 17 00:00:00 2001 From: Horiuchi_H Date: Fri, 30 May 2014 17:02:45 +0900 Subject: [PATCH 7/9] add x2js type definitions --- x2js/xml2json-tests.ts | 300 +++++++++++++++++++++++++++++++++++++++++ x2js/xml2json.d.ts | 32 +++++ 2 files changed, 332 insertions(+) create mode 100644 x2js/xml2json-tests.ts create mode 100644 x2js/xml2json.d.ts diff --git a/x2js/xml2json-tests.ts b/x2js/xml2json-tests.ts new file mode 100644 index 000000000..d5a8568e8 --- /dev/null +++ b/x2js/xml2json-tests.ts @@ -0,0 +1,300 @@ +/// + +// Create x2js instance with default config +var x2js = new X2JS(); + +// JSON to DOM +var xmlDoc = x2js.json2xml( + { + MyRoot: { + MyChild: 'my_child_value', + MyAnotherChild: 10, + MyArray: [ 'test', 'test2' ], + MyArrayRecords: [ + { + ttt: 'vvvv' + }, + { + ttt: 'vvvv2' + } + ] + } + } +); + + +// JSON to XML string +var xmlDocStr = x2js.json2xml_str( + { + MyRoot: { + MyChild: 'my_child_value', + MyAnotherChild: 10, + MyArray: [ 'test', 'test2' ], + MyArrayRecords: [ + { + ttt: 'vvvv' + }, + { + ttt: 'vvvv2' + } + ] + } + } +); + +console.log(xmlDocStr); + +// JSON arrays to string +var xmlDocStr = x2js.json2xml_str( + { + MyRoot: { + namedItemArray: { + item: [ + { first: 'success1' } , + { first: 'success2' } + ] + }, + namedArray: [ + { first: 'success1' } , + { first: 'success2' } + ], + justArray: [ 'just success1', 'just success2' ], + arrayWithAttrs: [ + { + _test: 'successAttr', + __text: 'success', + temp: 'successTemp' + }, + { + _test: 'successAttr2', + __text: 'success2', + temp: 'successTemp2' + } + ] + } + } +); + +console.log(xmlDocStr); + +// XML string to JSON +var xmlText = "Successddsfgdsdgfdgfd"; +var jsonObj = x2js.xml_str2json(xmlText); +console.log(jsonObj.MyOperation.test); + +// Array access form examples +console.log(x2js.asArray(jsonObj.MyOperation.test)[0]); +// Or old style (1.0.+): +var x2jsOld = new X2JS({arrayAccessForm: "property"}); +jsonObj = x2jsOld.xml_str2json(xmlText); +console.log("Old is " + jsonObj.MyOperation.test_asArray[0]); + +// XML/DOM to JSON +var xmlText = " - Success - TestText ddsfg TestText2 dsdgfdgfd" +xmlDoc = x2js.parseXmlString(xmlText); + +var jsonObj = x2js.xml2json(xmlDoc); +console.log(jsonObj.MyOperation.test); + +// Parsing XML attrs +var xmlText = "SUCCESS TXTSuccessddsfgdsdgfdgfd"; +var jsonObj = x2js.xml_str2json(xmlText); +console.log(jsonObj.MyOperation._myAttr); +console.log(jsonObj.MyOperation.test2._myAttr); +console.log(jsonObj.MyOperation.txtAttrChild._sAttr); +console.log(jsonObj.MyOperation.txtAttrChild.__text); +console.log(jsonObj.MyOperation.txtAttrChild.toString()); + +// JSON to XML attrs +var xmlDocStr = x2js.json2xml_str( + { + TestAttrRoot: { + _myAttr: 'myAttrValue', + MyChild: 'my_child_value', + MyAnotherChild: 10, + MyTextAttrChild: { + _myTextAttr: 'myTextAttrValue', + __text: 'HelloText' + } + } + } +); + +console.log(xmlDocStr); + +//Change prefix for attributes +var x2jsChangedAttrs = new X2JS({ + // XML attributes. Default is "_" + attributePrefix: "$" +}); +jsonObj = x2jsChangedAttrs.xml_str2json(xmlText); +console.log(jsonObj.MyOperation.$myAttr); +console.log(jsonObj.MyOperation.test2.$myAttr); +console.log(jsonObj.MyOperation.txtAttrChild.$sAttr); + +xmlDocStr = x2jsChangedAttrs.json2xml_str({ + TestAttrRoot: { + _myAttr: 'myAttrValue', + MyChild: 'my_child_value', + MyAnotherChild: 10, + MyTextAttrChild: { + $myTextAttr: 'myTextAttrValue', + __text: 'HelloText' + } + } + } +); + +console.log(xmlDocStr); + + +// Parse XML with namespaces +var xmlText = "SuccessddsfgdsdgfdgfdtestArrSize"; +var jsonObj = x2js.xml_str2json(xmlText); +console.log(jsonObj.MyOperation.test); +if (jsonObj.MyOperation.test2.item.length > 2) + console.log("Error! Incorrect array len!"); + +var testObjC = { + 'm:TestAttrRoot': { + '_tns:m': 'http://www.example.org', + '_tns:cms': 'http://www.example.org', + MyChild: 'my_child_value', + 'cms:MyAnotherChild': 'vdfd' + } +} + +// Parse JSON object with namespaces +var xmlDocStr = x2js.json2xml_str( + testObjC +); + +console.log(xmlDocStr); + +// Parse JSON object constructed with another NS-style +var testObjNew = { + TestAttrRoot: { + __prefix: 'm', + '_tns:m': 'http://www.example.org', + '_tns:cms': 'http://www.example.org', + MyChild: 'my_child_value', + MyAnotherChild: { + __prefix: 'cms', + __text: 'vdfd' + } + } +} + +// Parse JSON object with namespaces +var xmlDocStr = x2js.json2xml_str( + testObjNew +); + +console.log(xmlDocStr); + +// Parse XML with header +var xmlText = "\n" + + "XML HEADER SUCCESS!"; + +var jsonObj = x2js.xml_str2json(xmlText); +console.log(jsonObj.test); + +// Parse XML with CDATA +var xmlText = "simple success]]> "; + +var jsonObj = x2js.xml_str2json(xmlText); +console.log(jsonObj.test.data.toString()); +console.log(jsonObj.test.data.__cdata); +console.log(jsonObj.test.simple); + + +// Parse JSON object with CDATA +var xmlDocStr = x2js.json2xml_str( + jsonObj +); +console.log(xmlDocStr); + +// Parse JSON with emtpy attributes +var xmlDocStr = x2js.json2xml_str( + { + MyRoot: { + MyNullChild: null, + MyNullChild2: undefined, + MyAnotherChild: 10, + MyEmptyChild: { + _attr: "test" + }, + MyEmptyChild2: { + _attr: "test", + __text: "Empty Nodes Test" + } + } + } +); + +console.log(xmlDocStr); + +// Escaping XML characters +xmlDocStr = x2js.json2xml_str( + { + MyRoot: { + MyEscapeXmlChild: " & \" ' / ", + MyEscapeXmlChild2: { + _attr: "success", + __text: " & \" ' / " + }, + MyEscapeXmlChildNonString: false + } + } +); + +console.log(xmlDocStr); + +jsonObj = x2js.xml_str2json(xmlDocStr); +console.log(jsonObj.MyRoot.MyEscapeXmlChild); +console.log(jsonObj.MyRoot.MyEscapeXmlChild2.toString()); + +console.log(x2js.getVersion()); + +// Array access path demos +x2js = new X2JS({ + arrayAccessFormPaths: [ + "MyArrays.test4.item", + /.*\.test3\.item/ + ] +}); + +xmlText = "" + + "successsecond" + + "success" + + "success" + + "success" + + ""; + + +jsonObj = x2js.xml_str2json(xmlText); +console.log(jsonObj.MyArrays.test3.item[0]); +console.log(jsonObj.MyArrays.test4.item[0]); +console.log(jsonObj.MyArrays.test5.item); + +// Working with datetimes +x2js = new X2JS({ + datetimeAccessFormPaths: [ + "MyDts.testds", + /.*\.testdt.*/ + ] +}); + +xmlText = "" + + "2002-10-10T12:00:00+04:00" + + "2002-10-10T12:00:00Z" + + "2002-10-10T12:00:00" + + "2002-10-10T12:00:00Z" + + ""; +jsonObj = x2js.xml_str2json(xmlText); + +console.log(jsonObj.MyDts.testds); +console.log(jsonObj.MyDts.testdt1); +console.log(jsonObj.MyDts.testdt2); +console.log(x2js.asDateTime(jsonObj.MyDts.testdc)); + diff --git a/x2js/xml2json.d.ts b/x2js/xml2json.d.ts new file mode 100644 index 000000000..c202eface --- /dev/null +++ b/x2js/xml2json.d.ts @@ -0,0 +1,32 @@ + +interface IX2JS { + new (config?: IX2JSOption): IX2JS; + + getVersion(): string; + + xml2json(dom: Node): T; + json2xml(json: T): Node; + xml_str2json(xml: string): T; + json2xml_str(json: T): string; + parseXmlString(xml: string): Node; + + asArray(prop: any): any[]; + asDateTime(key: string): string; + asXmlDateTime(date: Date): string; + asXmlDateTime(date: number): string; +} + +interface IX2JSOption { + escapeMode?: boolean; + attributePrefix?: string; + arrayAccessForm?: string; + emptyNodeForm?: string; + enableToStringFunc?: boolean; + arrayAccessFormPaths?: any[]; + skipEmptyTextNodesForObj?: boolean; + stripWhitespaces?: boolean; + datetimeAccessFormPaths?: any[]; +} + +declare var X2JS: IX2JS; + From 88cfb5390050716d61b5465dfbcd2e720a89d7d4 Mon Sep 17 00:00:00 2001 From: Horiuchi_H Date: Fri, 30 May 2014 17:05:19 +0900 Subject: [PATCH 8/9] append CONTRIBUTORS --- CONTRIBUTORS.md | 1 + 1 file changed, 1 insertion(+) diff --git a/CONTRIBUTORS.md b/CONTRIBUTORS.md index 355990539..532e0404e 100644 --- a/CONTRIBUTORS.md +++ b/CONTRIBUTORS.md @@ -324,6 +324,7 @@ All definitions files include a header with the author and editors, so at some p * [WinJS](http://msdn.microsoft.com/en-us/library/windows/apps/br229773.aspx) (from TypeScript samples) * [WinRT](http://msdn.microsoft.com/en-us/library/windows/apps/br211377.aspx) (from TypeScript samples) * [ws](http://einaros.github.io/ws/) (by [Paul Loyd](https://github.com/loyd)) +* [x2js](https://code.google.com/p/x2js/) (by [Hiroki Horiuchi](https://github.com/horiuchi/)) * [XRegExp](http://xregexp.com/) (by [Bart van der Schoor](https://github.com/Bartvds)) * [YouTube](https://developers.google.com/youtube/) (by [Daz Wilkin](https://github.com/DazWilkin/)) * [YouTube Analytics API](https://developers.google.com/youtube/analytics/) (by [Frank M](https://github.com/sgtfrankieboy)) From 8fb6309e8d96aefa1f2b2e6c9961d10cc136ae06 Mon Sep 17 00:00:00 2001 From: Phips Peter Date: Fri, 30 May 2014 12:34:46 -0700 Subject: [PATCH 9/9] Adding type definitions for pg This is heavily based on the definitions from sqlite3. The Connection class is not defined because pg says that it is private for most use cases. I left that work for people who need it. --- pg/pg-tests.ts | 36 +++++++++++++++++++++ pg/pg.d.ts | 88 ++++++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 124 insertions(+) create mode 100644 pg/pg-tests.ts create mode 100644 pg/pg.d.ts diff --git a/pg/pg-tests.ts b/pg/pg-tests.ts new file mode 100644 index 000000000..dd9c75378 --- /dev/null +++ b/pg/pg-tests.ts @@ -0,0 +1,36 @@ +/// +import pg = require("pg"); +var conString = "postgres://username:password@localhost/database"; + +// Client pooling +pg.connect(conString, (err, client, done) => { + if (err) { + return console.error("Error fetching client from pool", err); + } + client.query("SELECT $1::int AS number", ["1"], (err, result) => { + done(); + if (err) { + return console.error("Error running query", err); + } + console.log(result.rows[0]["number"]); + return null; + }); + return null; +}); + +// Simple +var client = new pg.Client(conString); +client.connect((err) => { + if (err) { + return console.error("Could not connect to postgres", err); + } + client.query("SELECT NOW() AS 'theTime'", (err, result) => { + if (err) { + return console.error("Error running query", err); + } + console.log(result.rows[0]["theTime"]); + client.end(); + return null; + }); + return null; +}); \ No newline at end of file diff --git a/pg/pg.d.ts b/pg/pg.d.ts new file mode 100644 index 000000000..efdda0e4a --- /dev/null +++ b/pg/pg.d.ts @@ -0,0 +1,88 @@ +// Type definitions for pg +// Project: https://github.com/brianc/node-postgres +// Definitions by: Phips Peter +// Definitions: https://github.com/borisyankov/DefinitelyTyped + +/// + +declare module "pg" { + import events = require("events"); + import stream = require("stream"); + + export function connect(connection: string, callback: (err: Error, client: Client, done: () => void) => void): void; + export function connect(config: ClientConfig, callback: (err: Error, client: Client, done: () => void) => void): void; + export function end(): void; + + export interface ConnectionConfig { + user?: string; + database?: string; + password?: string; + port?: number; + host?: string; + } + + export interface Defaults extends ConnectionConfig { + poolSize?: number; + poolIdleTimeout?: number; + reapIntervalMillis?: number; + binary?: boolean; + parseInt8?: boolean; + } + + export interface ClientConfig extends ConnectionConfig { + ssl?: boolean; + } + + export interface QueryConfig { + name?: string; + text: string; + values?: any[]; + } + + export interface QueryResult { + rows: any[]; + } + + export interface ResultBuilder extends QueryResult { + command: string; + rowCount: number; + oid: number; + addRow(row: any): void; + } + + export class Client extends events.EventEmitter { + constructor(connection: string); + constructor(config: ClientConfig); + + connect(callback?: (err:Error) => void): void; + end(): void; + + query(queryText: string, callback?: (err: Error, result: QueryResult) => void): Query; + query(config: QueryConfig, callback?: (err: Error, result: QueryResult) => void): Query; + query(queryText: string, values: any[], callback?: (err: Error, result: QueryResult) => void): Query; + + copyFrom(queryText: string): stream.Writable; + copyTo(queryText: string): stream.Readable; + + pauseDrain(): void; + resumeDrain(): void; + + public on(event: "drain", listener: () => void): Client; + public on(event: "error", listener: (err: Error) => void): Client; + public on(event: "notification", listener: (message: any) => void): Client; + public on(event: "notice", listener: (message: any) => void): Client; + public on(event: string, listener: Function): Client; + } + + export class Query extends events.EventEmitter { + public on(event: "row", listener: (row: any, result?: ResultBuilder) => void): Query; + public on(event: "error", listener: (err: Error) => void): Query; + public on(event: "end", listener: (result: ResultBuilder) => void): Query; + public on(event: string, listener: Function): Query; + } + + export class Events extends events.EventEmitter { + public on(event: "error", listener: (err: Error, client: Client) => void): Events; + public on(event: string, listener: Function): Events; + } +} \ No newline at end of file