Commit Graph

68 Commits

Author SHA1 Message Date
John Vilk
cddd0b7aab [Node] Node attaches errno information to some exceptions.
This is valuable information for Node applications that need to figure out why a particular system call failed.

Note that errno can either be a string or a number, which is why I have typed it as 'any'.

While this is undocumented, it is tested:
Code property: https://github.com/joyent/node/blob/v0.10.23-release/test/simple/test-fs-open.js#L34
Errno property [string]: https://github.com/joyent/node/blob/v0.10.23-release/test/internet/test-dns.js#L148
Errno property [number]: https://github.com/joyent/node/blob/v0.10.23-release/test/simple/test-domain-implicit-fs.js#L43
Syscall property: https://github.com/joyent/node/blob/v0.10.23-release/test/simple/test-stdout-close-catch.js#L38
Path property (I can’t find a test, but many examples have this line): https://github.com/joyent/node/blob/v0.10.23-release/deps/npm/node_modules/fstream-npm/example/bundle.js#L6

..and well supported in the code for all platforms (this is where I got the name 'ErrnoException' from):
*nix: https://github.com/joyent/node/blob/v0.10.23-release/src/node.cc#L719
Windows: https://github.com/joyent/node/blob/v0.10.23-release/src/node.cc#L856

Unfortunately, while every errno exception is guaranteed to have the ‘errno’ and ‘code’ properties (see the logic in the source code in node.cc), there is no hard guarantee that particular library functions will always pass an ErrnoException to the callback. I cannot find a counterexample at this moment, though. Since we can’t have union types in TypeScript, I simply made all of the properties on ErrnoException optional as a compromise.

I am only adding modifications to the fs module, which definitely throws ErrnoExceptions. But according to the examples above, other modules (e.g. dns) also pass errno information back to applications. People familiar with those other modules can update their typings to reference this interface when applicable; I lack the experience with those modules to update their typings.

Further proof:
```javascript
$ node
> var fs = require('fs');
undefined
> fs.open('doesntexistlol', 'r', function(e) { console.log(Object.keys(e)); console.log(e.code); console.log(e.errno); console.log(e.path); });
undefined
> [ 'errno', 'code', 'path' ]
ENOENT
34
doesntexistlol
```
2013-12-17 16:36:08 -05:00
John Vilk
f1c040b378 [Node] Removing incorrect typing for buffer.INSPECT_MAX_BYTES.
From http://nodejs.org/api/buffer.html#buffer_buffer_inspect_max_bytes:

"...this is a property on the buffer module returned by require('buffer'), not on the Buffer global, or a buffer instance."

The Node typings do not have a notion of a buffer module, and introducing one would be more work than might be useful. It contains a reference to `Buffer` and `SlowBuffer`, which are currently defined as variables in the typings. I believe I would need
 to redefine these in the module definition.

If anyone has any ideas for how to efficiently restructure this, let me know.
2013-12-12 14:41:23 -05:00
Paul Loyd
20065c967a Rename Timer to NodeTimer 2013-12-08 12:44:52 +04:00
Mike H. Hawley
8f9ac50d4b Fix fs interface 2013-12-06 17:42:57 +03:00
Nick Howes
073000951d Update util.inspect API.
Latest API has an options object as the second parameter
instead of separate parameters. The old API is still supported
so have added the new signature as an overload.

Updated node-tests.ts
2013-12-05 12:45:17 +00:00
Basarat Ali Syed
9f3be188ac Merge pull request #1368 from halfninja/halfninja-node-url
Fix Node url.format() param type
2013-12-03 13:02:58 -08:00
Nick Howes
04ddf4ba31 Fix url.format() param type. 2013-12-03 13:20:56 +00:00
Paul Loyd
1e3efb6e24 Add worker's "send" method to NodeProcess 2013-11-25 23:57:04 +03:00
Basarat Ali Syed
d7968354c2 Merge pull request #1327 from ctaggart/nodejsBugStream
node bug fix, make ReadableStream the same as stream.ReadableStream
2013-11-24 14:24:04 -08:00
Cameron Taggart
ee21e8494b makes ReadableStream the same as stream.ReadableStream by applying the pipe change
from commit d0139df89d
2013-11-24 15:36:02 -06:00
Paul Loyd
70a2f13438 Fix assert module 2013-11-24 18:00:30 +04:00
Paul Loyd
f2a4348c20 Correct domain module 2013-11-24 17:38:56 +04:00
Paul Loyd
c3541fe0b9 Correct assert module 2013-11-24 17:38:56 +04:00
Chris Cowan
5b9620556e Fixes for node definitions.
setTimeout, setInterval, setImmediate are fixed to accept more
arguments.

setTimeout, setInterval, clearTimeout, clearInterval are changed to
return and accept objects of the new Timer interface, which exposes the
ref() and unref() methods.

fs.readFileSync is changed so that it returns a string if it is passed
an options parameter with an "encoding" property, and returns a
NodeBuffer otherwise.

fs.watchFile and fs.unwatchFile listener parameters are fixed. listener
is a callback with two parameters, not an object with two properties.

fs.watch is fixed so a listener parameter can be given without an
options parameter.

crypto.randomBytes is fixed so that it can be called synchronously,
returning a NodeBuffer.

crypto.pseudoRandomBytes is added.
2013-11-23 16:31:40 -06:00
Paul Loyd
5ddb5b9c3e Correct cluster and add events.EventEmitter.listenerCount 2013-11-20 18:12:31 +03:00
Paul Loyd
1b027b44e1 Update node.d.ts
Update signature of EventEmitter#emit
2013-11-15 20:57:49 +03:00
John Vilk
b6f524aa2f Buffer.copy() returns the number of bytes copied.
I know it's not mentioned in the documentation, but the Node unit tests check for this behavior, e.g. https://github.com/joyent/node/blob/master/test/simple/test-buffer.js#L54
2013-11-03 04:17:31 -05:00
Duncan Mak
d9735793e9 Update signatures for EventEmitter.
Allow for method chaining in addListener/removeListener, on/once,
and removeAllListeners.

Fix return type for 'emit'.

This patch mirrors the changes made to the API docs in this commit:
41cbdc5e64
2013-10-22 11:22:35 -04:00
vvakame
2708bc05cd Fixed tsc failed on Node.js v0.8.25 2013-10-03 11:23:38 +09:00
vvakame
3fe1f6bc4e Fixed to CI test passing 2013-10-03 10:18:58 +09:00
John Vilk
baa367d1b3 stat/lstat/fstat are asynchronous and return void.
Also tidying up a few callback signatures for fun.
2013-09-28 17:48:26 -04:00
John Vilk
0b306aaef6 'mode' can be a number or a string.
I realize this could be considered pedantic, but the typings do not even consistently use one or the other. Previously, certain functions assumed string, others assumed number. This way, you can use either.
2013-09-27 15:50:03 -04:00
John Vilk
666cd33fe8 In many fs functions, mode is optional, which means that the argument that takes its slot becomes the callback.
Adding alternative definitions to account for this.
2013-09-27 15:43:28 -04:00
John Vilk
d39e7a3125 In fs's truncate functions, 'len' is optional (and defaults to 0). 2013-09-27 15:20:58 -04:00
John Vilk
b6874ee014 fs.realpath's cache is an *object literal*, not a string or a boolean. 2013-09-27 15:00:04 -04:00
John Vilk
e442870348 Whoops. fd is a *string*, not a *number*. 2013-09-27 14:51:25 -04:00
John Vilk
aed3e0fc50 Adding missing method signatures and fixing incorrect method signatures.
The following missing methods were added:
* fs.readlinkSync
* fs.ftruncate
* fs.ftruncateSync

The following method signatures were fixed:
* path.resolve: Takes an array of arbitrary length. This does not necessarily need to be a string array; resolve skips any non-string elements.
* process.cwd: Returns a string, not void.
2013-09-27 14:46:39 -04:00
basarat
d0139df89d node : readable stream pipe can be piped further closes #1030 2013-09-10 19:32:21 +10:00
damianog
1c1e096228 options is optional
http://nodejs.org/api/zlib.html#zlib_options
2013-09-09 19:57:57 +02:00
damianog
7b74efd634 ServerRequest headers is an object
http://nodejs.org/api/http.html#http_message_headers
2013-09-07 20:31:45 +02:00
Chris Scribner
95b783e972 Update node type definitions to compile under -noImplicitAny 2013-09-04 18:11:20 -04:00
anti.veeranna
c1d25c84f1 describe stream.Readable class 2013-09-04 06:17:10 -04:00
damianog
0ad9432d61 Node.js util.inspect must return a string
As explained here:

http://nodejs.org/api/util.html#util_util_inspect_object_options

util.inspect return a string
2013-08-29 21:16:11 +02:00
Diullei Gomes
7234449d22 Merge pull request #914 from cybrown/master
Extending EventEmitter interface on FSWatcher interface
2013-08-24 20:50:24 -07:00
Jed Hunsaker
8c6e74ce37 Untabify 2013-08-22 21:56:17 -07:00
Cy Brown
bd9fc8c260 Extending EventEmitter interface on FSWatcher interface 2013-08-22 22:47:06 +02:00
Hans Malherbe
59c20e38fd Add optional time argument for process.hrtime 2013-08-21 17:45:32 +02:00
Cary Haynie
1a95e29af3 update connect() calls to correctly return NodeSocket object. 2013-08-19 10:49:44 -04:00
Ty
c2a7c36945 Fixed type mistake 2013-08-17 15:22:54 -07:00
Boris Yankov
9c636325ef Fix node 0.8 definitions 2013-08-07 20:05:33 +03:00
Panu Pitkämäki
dc5453adbd Fixed typo in listener removal method, now conforms to interface. 2013-08-07 18:00:11 +03:00
Panu Pitkämäki
bd6ddbdce2 Migrated a breaking change between Typescript 0.8 and 0.9: Syntax of external module imports now uses 'require'. 2013-08-07 15:49:36 +03:00
Boris Yankov
d1f801dd39 Fix node removeAllListeners method definition 2013-08-06 22:02:46 +03:00
basarat
79dc2f4c35 path.resolve
It can take a single "to" parameter : http://nodejs.org/docs/latest/api/path.html#path_path_resolve_from_to and in fact that is *the* way you get "Absolute paths" in node
2013-08-04 16:07:49 +10:00
Diullei Gomes
274667b760 bug fix - node test 2013-07-19 12:11:20 -03:00
Boris Yankov
b691f37cb5 Merge pull request #750 from NN---/patch-2
Update according to TS 0.9
2013-07-06 02:48:13 -07:00
NN
64092006cf Update according to TS 0.9
'export = internal' is illegal.
2013-07-05 22:05:28 +03:00
NN
184bda7faf Update according to TS 0.9
'export = internal' is illegal.
2013-07-05 22:05:25 +03:00
Neil Stalker
26d671ccbd Fix definitions for TS 0.9 2013-06-28 22:14:33 +01:00
Poul Sørensen
bb5d20d333 Update node.d.ts 2013-06-24 23:39:56 +02:00