-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathdeno.d.ts
2254 lines (2237 loc) · 80.2 KB
/
deno.d.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
// Copyright 2018 the Deno authors. All rights reserved. MIT license.
/// <reference no-default-lib="true" />
/// <reference lib="esnext" />
declare module "deno" {
/** Exit the Deno process with optional exit code. */
export function exit(exitCode?: number): never;
/** Returns a snapshot of the environment variables at invocation. Mutating a
* property in the object will set that variable in the environment for
* the process. The environment object will only accept `string`s or `number`s
* as values.
*
* import { env } from "deno";
*
* const myEnv = env();
* console.log(myEnv.SHELL);
* myEnv.TEST_VAR = "HELLO";
* const newEnv = env();
* console.log(myEnv.TEST_VAR == newEnv.TEST_VAR);
*/
export function env(): {
[index: string]: string;
};
/**
* cwd() Return a string representing the current working directory.
* If the current directory can be reached via multiple paths
* (due to symbolic links), cwd() may return
* any one of them.
* throws NotFound exception if directory not available
*/
export function cwd(): string;
/**
* chdir() Change the current working directory to path.
* throws NotFound exception if directory not available
*/
export function chdir(directory: string): void;
export interface ReadResult {
nread: number;
eof: boolean;
}
export interface Reader {
/** Reads up to p.byteLength bytes into `p`. It resolves to the number
* of bytes read (`0` <= `n` <= `p.byteLength`) and any error encountered.
* Even if `read()` returns `n` < `p.byteLength`, it may use all of `p` as
* scratch space during the call. If some data is available but not
* `p.byteLength` bytes, `read()` conventionally returns what is available
* instead of waiting for more.
*
* When `read()` encounters an error or end-of-file condition after
* successfully reading `n` > `0` bytes, it returns the number of bytes read.
* It may return the (non-nil) error from the same call or return the error
* (and `n` == `0`) from a subsequent call. An instance of this general case
* is that a `Reader` returning a non-zero number of bytes at the end of the
* input stream may return either `err` == `EOF` or `err` == `null`. The next
* `read()` should return `0`, `EOF`.
*
* Callers should always process the `n` > `0` bytes returned before
* considering the `EOF`. Doing so correctly handles I/O errors that happen
* after reading some bytes and also both of the allowed `EOF` behaviors.
*
* Implementations of `read()` are discouraged from returning a zero byte
* count with a `null` error, except when `p.byteLength` == `0`. Callers
* should treat a return of `0` and `null` as indicating that nothing
* happened; in particular it does not indicate `EOF`.
*
* Implementations must not retain `p`.
*/
read(p: Uint8Array): Promise<ReadResult>;
}
export interface Writer {
/** Writes `p.byteLength` bytes from `p` to the underlying data
* stream. It resolves to the number of bytes written from `p` (`0` <= `n` <=
* `p.byteLength`) and any error encountered that caused the write to stop
* early. `write()` must return a non-null error if it returns `n` <
* `p.byteLength`. write() must not modify the slice data, even temporarily.
*
* Implementations must not retain `p`.
*/
write(p: Uint8Array): Promise<number>;
}
export interface Closer {
close(): void;
}
export interface Seeker {
/** Seek sets the offset for the next `read()` or `write()` to offset,
* interpreted according to `whence`: `SeekStart` means relative to the start
* of the file, `SeekCurrent` means relative to the current offset, and
* `SeekEnd` means relative to the end. Seek returns the new offset relative
* to the start of the file and an error, if any.
*
* Seeking to an offset before the start of the file is an error. Seeking to
* any positive offset is legal, but the behavior of subsequent I/O operations
* on the underlying object is implementation-dependent.
*/
seek(offset: number, whence: number): Promise<void>;
}
export interface ReadCloser extends Reader, Closer {}
export interface WriteCloser extends Writer, Closer {}
export interface ReadSeeker extends Reader, Seeker {}
export interface WriteSeeker extends Writer, Seeker {}
export interface ReadWriteCloser extends Reader, Writer, Closer {}
export interface ReadWriteSeeker extends Reader, Writer, Seeker {}
/** Copies from `src` to `dst` until either `EOF` is reached on `src`
* or an error occurs. It returns the number of bytes copied and the first
* error encountered while copying, if any.
*
* Because `copy()` is defined to read from `src` until `EOF`, it does not
* treat an `EOF` from `read()` as an error to be reported.
*/
export function copy(dst: Writer, src: Reader): Promise<number>;
/** Turns `r` into async iterator.
*
* for await (const chunk of readerIterator(reader)) {
* console.log(chunk)
* }
*/
export function toAsyncIterator(r: Reader): AsyncIterableIterator<Uint8Array>;
/** The Deno abstraction for reading and writing files. */
export class File implements Reader, Writer, Closer {
readonly rid: number;
constructor(rid: number);
write(p: Uint8Array): Promise<number>;
read(p: Uint8Array): Promise<ReadResult>;
close(): void;
}
/** An instance of `File` for stdin. */
export const stdin: File;
/** An instance of `File` for stdout. */
export const stdout: File;
/** An instance of `File` for stderr. */
export const stderr: File;
export type OpenMode =
| "r"
/** Read-write. Start at beginning of file. */
| "r+"
/** Write-only. Opens and truncates existing file or creates new one for
* writing only.
*/
| "w"
/** Read-write. Opens and truncates existing file or creates new one for
* writing and reading.
*/
| "w+"
/** Write-only. Opens existing file or creates new one. Each write appends
* content to the end of file.
*/
| "a"
/** Read-write. Behaves like "a" and allows to read from file. */
| "a+"
/** Write-only. Exclusive create - creates new file only if one doesn't exist
* already.
*/
| "x"
/** Read-write. Behaves like `x` and allows to read from file. */
| "x+";
/** A factory function for creating instances of `File` associated with the
* supplied file name.
*/
function create(filename: string): Promise<File>;
/** Open a file and return an instance of the `File` object.
*
* import * as deno from "deno";
* (async () => {
* const file = await deno.open("/foo/bar.txt");
* })();
*/
export function open(filename: string, mode?: OpenMode): Promise<File>;
/** Read from a file ID into an array buffer.
*
* Resolves with the `ReadResult` for the operation.
*/
export function read(rid: number, p: Uint8Array): Promise<ReadResult>;
/** Write to the file ID the contents of the array buffer.
*
* Resolves with the number of bytes written.
*/
export function write(rid: number, p: Uint8Array): Promise<number>;
/** Close the file ID. */
export function close(rid: number): void;
/** A Buffer is a variable-sized buffer of bytes with read() and write()
* methods. Based on https://golang.org/pkg/bytes/#Buffer
*/
export class Buffer implements Reader, Writer {
private buf;
private off;
constructor(ab?: ArrayBuffer);
/** bytes() returns a slice holding the unread portion of the buffer.
* The slice is valid for use only until the next buffer modification (that
* is, only until the next call to a method like read(), write(), reset(), or
* truncate()). The slice aliases the buffer content at least until the next
* buffer modification, so immediate changes to the slice will affect the
* result of future reads.
*/
bytes(): Uint8Array;
/** toString() returns the contents of the unread portion of the buffer
* as a string. Warning - if multibyte characters are present when data is
* flowing through the buffer, this method may result in incorrect strings
* due to a character being split.
*/
toString(): string;
/** empty() returns whether the unread portion of the buffer is empty. */
empty(): boolean;
/** length is a getter that returns the number of bytes of the unread
* portion of the buffer
*/
readonly length: number;
/** Returns the capacity of the buffer's underlying byte slice, that is,
* the total space allocated for the buffer's data.
*/
readonly capacity: number;
/** truncate() discards all but the first n unread bytes from the buffer but
* continues to use the same allocated storage. It throws if n is negative or
* greater than the length of the buffer.
*/
truncate(n: number): void;
/** reset() resets the buffer to be empty, but it retains the underlying
* storage for use by future writes. reset() is the same as truncate(0)
*/
reset(): void;
/** _tryGrowByReslice() is a version of grow for the fast-case
* where the internal buffer only needs to be resliced. It returns the index
* where bytes should be written and whether it succeeded.
* It returns -1 if a reslice was not needed.
*/
private _tryGrowByReslice;
private _reslice;
/** read() reads the next len(p) bytes from the buffer or until the buffer
* is drained. The return value n is the number of bytes read. If the
* buffer has no data to return, eof in the response will be true.
*/
read(p: Uint8Array): Promise<ReadResult>;
write(p: Uint8Array): Promise<number>;
/** _grow() grows the buffer to guarantee space for n more bytes.
* It returns the index where bytes should be written.
* If the buffer can't grow it will throw with ErrTooLarge.
*/
private _grow;
/** grow() grows the buffer's capacity, if necessary, to guarantee space for
* another n bytes. After grow(n), at least n bytes can be written to the
* buffer without another allocation. If n is negative, grow() will panic. If
* the buffer can't grow it will throw ErrTooLarge.
* Based on https://golang.org/pkg/bytes/#Buffer.Grow
*/
grow(n: number): void;
/** readFrom() reads data from r until EOF and appends it to the buffer,
* growing the buffer as needed. It returns the number of bytes read. If the
* buffer becomes too large, readFrom will panic with ErrTooLarge.
* Based on https://golang.org/pkg/bytes/#Buffer.ReadFrom
*/
readFrom(r: Reader): Promise<number>;
}
/** Read `r` until EOF and return the content as `Uint8Array`.
*/
export function readAll(r: Reader): Promise<Uint8Array>;
/** Creates a new directory with the specified path and permission
* synchronously.
*
* import { mkdirSync } from "deno";
* mkdirSync("new_dir");
*/
export function mkdirSync(path: string, mode?: number): void;
/** Creates a new directory with the specified path and permission.
*
* import { mkdir } from "deno";
* await mkdir("new_dir");
*/
export function mkdir(path: string, mode?: number): Promise<void>;
interface MakeTempDirOptions {
dir?: string;
prefix?: string;
suffix?: string;
}
/** makeTempDirSync is the synchronous version of `makeTempDir`.
*
* import { makeTempDirSync } from "deno";
* const tempDirName0 = makeTempDirSync();
* const tempDirName1 = makeTempDirSync({ prefix: 'my_temp' });
*/
export function makeTempDirSync(options?: MakeTempDirOptions): string;
/** makeTempDir creates a new temporary directory in the directory `dir`, its
* name beginning with `prefix` and ending with `suffix`.
* It returns the full path to the newly created directory.
* If `dir` is unspecified, tempDir uses the default directory for temporary
* files. Multiple programs calling tempDir simultaneously will not choose the
* same directory. It is the caller's responsibility to remove the directory
* when no longer needed.
*
* import { makeTempDir } from "deno";
* const tempDirName0 = await makeTempDir();
* const tempDirName1 = await makeTempDir({ prefix: 'my_temp' });
*/
export function makeTempDir(options?: MakeTempDirOptions): Promise<string>;
/** Changes the permission of a specific file/directory of specified path
* synchronously.
*
* import { chmodSync } from "deno";
* chmodSync("/path/to/file", 0o666);
*/
export function chmodSync(path: string, mode: number): void;
/** Changes the permission of a specific file/directory of specified path.
*
* import { chmod } from "deno";
* await chmod("/path/to/file", 0o666);
*/
export function chmod(path: string, mode: number): Promise<void>;
/** Removes the named file or (empty) directory synchronously. Would throw
* error if permission denied, not found, or directory not empty.
*
* import { removeSync } from "deno";
* removeSync("/path/to/empty_dir/or/file");
*/
export function removeSync(path: string): void;
/** Removes the named file or (empty) directory. Would throw error if
* permission denied, not found, or directory not empty.
*
* import { remove } from "deno";
* await remove("/path/to/empty_dir/or/file");
*/
export function remove(path: string): Promise<void>;
/** Recursively removes the named file or directory synchronously. Would throw
* error if permission denied or not found.
*
* import { removeAllSync } from "deno";
* removeAllSync("/path/to/dir/or/file");
*/
export function removeAllSync(path: string): void;
/** Recursively removes the named file or directory. Would throw error if
* permission denied or not found.
*
* import { removeAll } from "deno";
* await removeAll("/path/to/dir/or/file");
*/
export function removeAll(path: string): Promise<void>;
/** Synchronously renames (moves) `oldpath` to `newpath`. If `newpath` already
* exists and is not a directory, `renameSync()` replaces it. OS-specific
* restrictions may apply when `oldpath` and `newpath` are in different
* directories.
*
* import { renameSync } from "deno";
* renameSync("old/path", "new/path");
*/
export function renameSync(oldpath: string, newpath: string): void;
/** Renames (moves) `oldpath` to `newpath`. If `newpath` already exists and is
* not a directory, `rename()` replaces it. OS-specific restrictions may apply
* when `oldpath` and `newpath` are in different directories.
*
* import { rename } from "deno";
* await rename("old/path", "new/path");
*/
export function rename(oldpath: string, newpath: string): Promise<void>;
/** Read the entire contents of a file synchronously.
*
* import { readFileSync } from "deno";
* const decoder = new TextDecoder("utf-8");
* const data = readFileSync("hello.txt");
* console.log(decoder.decode(data));
*/
export function readFileSync(filename: string): Uint8Array;
/** Read the entire contents of a file.
*
* import { readFile } from "deno";
* const decoder = new TextDecoder("utf-8");
* const data = await readFile("hello.txt");
* console.log(decoder.decode(data));
*/
export function readFile(filename: string): Promise<Uint8Array>;
/** A FileInfo describes a file and is returned by `stat`, `lstat`,
* `statSync`, `lstatSync`.
*/
export interface FileInfo {
/** The size of the file, in bytes. */
len: number;
/** The last modification time of the file. This corresponds to the `mtime`
* field from `stat` on Unix and `ftLastWriteTime` on Windows. This may not
* be available on all platforms.
*/
modified: number | null;
/** The last access time of the file. This corresponds to the `atime`
* field from `stat` on Unix and `ftLastAccessTime` on Windows. This may not
* be available on all platforms.
*/
accessed: number | null;
/** The last access time of the file. This corresponds to the `birthtime`
* field from `stat` on Unix and `ftCreationTime` on Windows. This may not
* be available on all platforms.
*/
created: number | null;
/** The underlying raw st_mode bits that contain the standard Unix permissions
* for this file/directory. TODO Match behavior with Go on windows for mode.
*/
mode: number | null;
/** Returns the file or directory name. */
name: string | null;
/** Returns the file or directory path. */
path: string | null;
/** Returns whether this is info for a regular file. This result is mutually
* exclusive to `FileInfo.isDirectory` and `FileInfo.isSymlink`.
*/
isFile(): boolean;
/** Returns whether this is info for a regular directory. This result is
* mutually exclusive to `FileInfo.isFile` and `FileInfo.isSymlink`.
*/
isDirectory(): boolean;
/** Returns whether this is info for a symlink. This result is
* mutually exclusive to `FileInfo.isFile` and `FileInfo.isDirectory`.
*/
isSymlink(): boolean;
}
/** Reads the directory given by path and returns a list of file info
* synchronously.
*
* import { readDirSync } from "deno";
* const files = readDirSync("/");
*/
export function readDirSync(path: string): FileInfo[];
/** Reads the directory given by path and returns a list of file info.
*
* import { readDir } from "deno";
* const files = await readDir("/");
*/
export function readDir(path: string): Promise<FileInfo[]>;
/** Copies the contents of a file to another by name synchronously.
* Creates a new file if target does not exists, and if target exists,
* overwrites original content of the target file.
*
* It would also copy the permission of the original file
* to the destination.
*
* import { copyFileSync } from "deno";
* copyFileSync("from.txt", "to.txt");
*/
export function copyFileSync(from: string, to: string): void;
/** Copies the contents of a file to another by name.
*
* Creates a new file if target does not exists, and if target exists,
* overwrites original content of the target file.
*
* It would also copy the permission of the original file
* to the destination.
*
* import { copyFile } from "deno";
* await copyFile("from.txt", "to.txt");
*/
export function copyFile(from: string, to: string): Promise<void>;
/** Returns the destination of the named symbolic link synchronously.
*
* import { readlinkSync } from "deno";
* const targetPath = readlinkSync("symlink/path");
*/
export function readlinkSync(name: string): string;
/** Returns the destination of the named symbolic link.
*
* import { readlink } from "deno";
* const targetPath = await readlink("symlink/path");
*/
export function readlink(name: string): Promise<string>;
/** Queries the file system for information on the path provided. If the given
* path is a symlink information about the symlink will be returned.
*
* import { lstat } from "deno";
* const fileInfo = await lstat("hello.txt");
* assert(fileInfo.isFile());
*/
export function lstat(filename: string): Promise<FileInfo>;
/** Queries the file system for information on the path provided synchronously.
* If the given path is a symlink information about the symlink will be
* returned.
*
* import { lstatSync } from "deno";
* const fileInfo = lstatSync("hello.txt");
* assert(fileInfo.isFile());
*/
export function lstatSync(filename: string): FileInfo;
/** Queries the file system for information on the path provided. `stat` Will
* always follow symlinks.
*
* import { stat } from "deno";
* const fileInfo = await stat("hello.txt");
* assert(fileInfo.isFile());
*/
export function stat(filename: string): Promise<FileInfo>;
/** Queries the file system for information on the path provided synchronously.
* `statSync` Will always follow symlinks.
*
* import { statSync } from "deno";
* const fileInfo = statSync("hello.txt");
* assert(fileInfo.isFile());
*/
export function statSync(filename: string): FileInfo;
/** Synchronously creates `newname` as a symbolic link to `oldname`. The type
* argument can be set to `dir` or `file` and is only available on Windows
* (ignored on other platforms).
*
* import { symlinkSync } from "deno";
* symlinkSync("old/name", "new/name");
*/
export function symlinkSync(
oldname: string,
newname: string,
type?: string
): void;
/** Creates `newname` as a symbolic link to `oldname`. The type argument can be
* set to `dir` or `file` and is only available on Windows (ignored on other
* platforms).
*
* import { symlink } from "deno";
* await symlink("old/name", "new/name");
*/
export function symlink(
oldname: string,
newname: string,
type?: string
): Promise<void>;
/** Write a new file, with given filename and data synchronously.
*
* import { writeFileSync } from "deno";
*
* const encoder = new TextEncoder("utf-8");
* const data = encoder.encode("Hello world\n");
* writeFileSync("hello.txt", data);
*/
export function writeFileSync(
filename: string,
data: Uint8Array,
perm?: number
): void;
/** Write a new file, with given filename and data.
*
* import { writeFile } from "deno";
*
* const encoder = new TextEncoder("utf-8");
* const data = encoder.encode("Hello world\n");
* await writeFile("hello.txt", data);
*/
export function writeFile(
filename: string,
data: Uint8Array,
perm?: number
): Promise<void>;
export enum ErrorKind {
NoError = 0,
NotFound = 1,
PermissionDenied = 2,
ConnectionRefused = 3,
ConnectionReset = 4,
ConnectionAborted = 5,
NotConnected = 6,
AddrInUse = 7,
AddrNotAvailable = 8,
BrokenPipe = 9,
AlreadyExists = 10,
WouldBlock = 11,
InvalidInput = 12,
InvalidData = 13,
TimedOut = 14,
Interrupted = 15,
WriteZero = 16,
Other = 17,
UnexpectedEof = 18,
BadResource = 19,
CommandFailed = 20,
EmptyHost = 21,
IdnaError = 22,
InvalidPort = 23,
InvalidIpv4Address = 24,
InvalidIpv6Address = 25,
InvalidDomainCharacter = 26,
RelativeUrlWithoutBase = 27,
RelativeUrlWithCannotBeABaseBase = 28,
SetHostOnCannotBeABaseUrl = 29,
Overflow = 30,
HttpUser = 31,
HttpClosed = 32,
HttpCanceled = 33,
HttpParse = 34,
HttpOther = 35,
TooLarge = 36,
InvalidUri = 37
}
/** A Deno specific error. The `kind` property is set to a specific error code
* which can be used to in application logic.
*
* import { DenoError, ErrorKind } from "deno";
* try {
* somethingThatMightThrow();
* } catch (e) {
* if (e instanceof DenoError && e.kind === ErrorKind.Overflow) {
* console.error("Overflow error!");
* }
* }
*/
export class DenoError<T extends ErrorKind> extends Error {
readonly kind: T;
constructor(kind: T, msg: string);
}
type MessageCallback = (msg: Uint8Array) => void;
type PromiseRejectEvent =
| "RejectWithNoHandler"
| "HandlerAddedAfterReject"
| "ResolveAfterResolved"
| "RejectAfterResolved";
interface Libdeno {
recv(cb: MessageCallback): void;
send(control: ArrayBufferView, data?: ArrayBufferView): null | Uint8Array;
print(x: string, isErr?: boolean): void;
shared: ArrayBuffer;
setGlobalErrorHandler: (
handler: (
message: string,
source: string,
line: number,
col: number,
error: Error
) => void
) => void;
setPromiseRejectHandler: (
handler: (
error: Error | string,
event: PromiseRejectEvent,
promise: Promise<any>
) => void
) => void;
setPromiseErrorExaminer: (handler: () => boolean) => void;
}
export const libdeno: Libdeno;
export {};
interface Platform {
/** The operating system CPU architecture. */
arch: "x64";
/** The operating system platform. */
os: "mac" | "win" | "linux";
}
export const platform: Platform;
/** Truncates or extends the specified file synchronously, updating the size of
* this file to become size.
*
* import { truncateSync } from "deno";
*
* truncateSync("hello.txt", 10);
*/
export function truncateSync(name: string, len?: number): void;
/**
* Truncates or extends the specified file, updating the size of this file to
* become size.
*
* import { truncate } from "deno";
*
* await truncate("hello.txt", 10);
*/
export function truncate(name: string, len?: number): Promise<void>;
type Network = "tcp";
type Addr = string;
/** A Listener is a generic network listener for stream-oriented protocols. */
export interface Listener {
/** Waits for and resolves to the next connection to the `Listener`. */
accept(): Promise<Conn>;
/** Close closes the listener. Any pending accept promises will be rejected
* with errors.
*/
close(): void;
/** Return the address of the `Listener`. */
addr(): Addr;
}
export interface Conn extends Reader, Writer, Closer {
/** The local address of the connection. */
localAddr: string;
/** The remote address of the connection. */
remoteAddr: string;
/** Shuts down (`shutdown(2)`) the reading side of the TCP connection. Most
* callers should just use `close()`.
*/
closeRead(): void;
/** Shuts down (`shutdown(2)`) the writing side of the TCP connection. Most
* callers should just use `close()`.
*/
closeWrite(): void;
}
/** Listen announces on the local network address.
*
* The network must be `tcp`, `tcp4`, `tcp6`, `unix` or `unixpacket`.
*
* For TCP networks, if the host in the address parameter is empty or a literal
* unspecified IP address, `listen()` listens on all available unicast and
* anycast IP addresses of the local system. To only use IPv4, use network
* `tcp4`. The address can use a host name, but this is not recommended,
* because it will create a listener for at most one of the host's IP
* addresses. If the port in the address parameter is empty or `0`, as in
* `127.0.0.1:` or `[::1]:0`, a port number is automatically chosen. The
* `addr()` method of `Listener` can be used to discover the chosen port.
*
* See `dial()` for a description of the network and address parameters.
*/
export function listen(network: Network, address: string): Listener;
/** Dial connects to the address on the named network.
*
* Supported networks are only `tcp` currently.
*
* TODO: `tcp4` (IPv4-only), `tcp6` (IPv6-only), `udp`, `udp4` (IPv4-only),
* `udp6` (IPv6-only), `ip`, `ip4` (IPv4-only), `ip6` (IPv6-only), `unix`,
* `unixgram` and `unixpacket`.
*
* For TCP and UDP networks, the address has the form `host:port`. The host must
* be a literal IP address, or a host name that can be resolved to IP addresses.
* The port must be a literal port number or a service name. If the host is a
* literal IPv6 address it must be enclosed in square brackets, as in
* `[2001:db8::1]:80` or `[fe80::1%zone]:80`. The zone specifies the scope of
* the literal IPv6 address as defined in RFC 4007. The functions JoinHostPort
* and SplitHostPort manipulate a pair of host and port in this form. When using
* TCP, and the host resolves to multiple IP addresses, Dial will try each IP
* address in order until one succeeds.
*
* Examples:
*
* dial("tcp", "golang.org:http")
* dial("tcp", "192.0.2.1:http")
* dial("tcp", "198.51.100.1:80")
* dial("udp", "[2001:db8::1]:domain")
* dial("udp", "[fe80::1%lo0]:53")
* dial("tcp", ":80")
*/
export function dial(network: Network, address: string): Promise<Conn>;
/** **RESERVED** */
export function connect(network: Network, address: string): Promise<Conn>;
interface Metrics {
opsDispatched: number;
opsCompleted: number;
bytesSentControl: number;
bytesSentData: number;
bytesReceived: number;
}
/** Receive metrics from the privileged side of Deno. */
export function metrics(): Metrics;
export {};
type ResourceMap = {
[rid: number]: string;
};
/** Returns a map of open _file like_ resource ids along with their string
* representation.
*/
export function resources(): ResourceMap;
/** How to handle subsubprocess stdio.
*
* "inherit" The default if unspecified. The child inherits from the
* corresponding parent descriptor.
*
* "piped" A new pipe should be arranged to connect the parent and child
* subprocesses.
*
* "null" This stream will be ignored. This is the equivalent of attaching the
* stream to /dev/null.
*/
type ProcessStdio = "inherit" | "piped" | "null";
export interface RunOptions {
args: string[];
cwd?: string;
stdout?: ProcessStdio;
stderr?: ProcessStdio;
stdin?: ProcessStdio;
}
export class Process {
readonly rid: number;
readonly pid: number;
readonly stdin?: WriteCloser;
readonly stdout?: ReadCloser;
readonly stderr?: ReadCloser;
status(): Promise<ProcessStatus>;
/** Buffer the stdout and return it as Uint8Array after EOF.
* You must have set stdout to "piped" in when creating the process.
* This calls close() on stdout after its done.
*/
output(): Promise<Uint8Array>;
close(): void;
}
export interface ProcessStatus {
success: boolean;
code?: number;
signal?: number;
}
export function run(opt: RunOptions): Process;
type ConsoleOptions = Partial<{
showHidden: boolean;
depth: number;
colors: boolean;
}>;
/** TODO Do not expose this from "deno" namespace. */
export function stringifyArgs(args: any[], options?: ConsoleOptions): string;
type PrintFunc = (x: string, isErr?: boolean) => void;
/** TODO Do not expose this from "deno". */
export class Console {
private printFunc;
constructor(printFunc: PrintFunc);
/** Writes the arguments to stdout */
log: (...args: any[]) => void;
/** Writes the arguments to stdout */
debug: (...args: any[]) => void;
/** Writes the arguments to stdout */
info: (...args: any[]) => void;
/** Writes the properties of the supplied `obj` to stdout */
dir: (
obj: any,
options?: Partial<{
showHidden: boolean;
depth: number;
colors: boolean;
}>
) => void;
/** Writes the arguments to stdout */
warn: (...args: any[]) => void;
/** Writes the arguments to stdout */
error: (...args: any[]) => void;
/** Writes an error message to stdout if the assertion is `false`. If the
* assertion is `true`, nothing happens.
*
* ref: https://console.spec.whatwg.org/#assert
*/
assert: (condition?: boolean, ...args: any[]) => void;
count: (label?: string) => void;
countReset: (label?: string) => void;
time: (label?: string) => void;
timeLog: (label?: string, ...args: any[]) => void;
timeEnd: (label?: string) => void;
}
/**
* inspect() converts input into string that has the same format
* as printed by console.log(...);
*/
export function inspect(
value: any, // tslint:disable-line:no-any
options?: ConsoleOptions
): string;
export {};
/*! ****************************************************************************
Copyright (c) Microsoft Corporation. All rights reserved.
Licensed under the Apache License, Version 2.0 (the "License"); you may not use
this file except in compliance with the License. You may obtain a copy of the
License at http://www.apache.org/licenses/LICENSE-2.0
THIS CODE IS PROVIDED ON AN *AS IS* BASIS, WITHOUT WARRANTIES OR CONDITIONS OF
ANY KIND, EITHER EXPRESS OR IMPLIED, INCLUDING WITHOUT LIMITATION ANY IMPLIED
WARRANTIES OR CONDITIONS OF TITLE, FITNESS FOR A PARTICULAR PURPOSE,
MERCHANTABLITY OR NON-INFRINGEMENT.
See the Apache Version 2.0 License for specific language governing permissions
and limitations under the License.
*******************************************************************************/
type BufferSource = ArrayBufferView | ArrayBuffer;
type HeadersInit = Headers | Array<[string, string]> | Record<string, string>;
type URLSearchParamsInit = string | string[][] | Record<string, string>;
type BodyInit =
| Blob
| BufferSource
| FormData
| URLSearchParams
| ReadableStream
| string;
type RequestInfo = Request | string;
type ReferrerPolicy =
| ""
| "no-referrer"
| "no-referrer-when-downgrade"
| "origin-only"
| "origin-when-cross-origin"
| "unsafe-url";
type BlobPart = BufferSource | Blob | string;
type FormDataEntryValue = DomFile | string;
type EventListenerOrEventListenerObject = EventListener | EventListenerObject;
interface DomIterable<K, V> {
keys(): IterableIterator<K>;
values(): IterableIterator<V>;
entries(): IterableIterator<[K, V]>;
[Symbol.iterator](): IterableIterator<[K, V]>;
forEach(
callback: (value: V, key: K, parent: this) => void,
thisArg?: any
): void;
}
interface Element {}
interface HTMLFormElement {}
type EndingType = "transparent" | "native";
interface BlobPropertyBag {
type?: string;
ending?: EndingType;
}
interface AbortSignalEventMap {
abort: ProgressEvent;
}
interface EventTarget {
addEventListener(
type: string,
listener: EventListenerOrEventListenerObject | null,
options?: boolean | AddEventListenerOptions
): void;
dispatchEvent(evt: Event): boolean;
removeEventListener(
type: string,
listener?: EventListenerOrEventListenerObject | null,
options?: EventListenerOptions | boolean
): void;
}
interface ProgressEventInit extends EventInit {
lengthComputable?: boolean;
loaded?: number;
total?: number;
}
interface URLSearchParams {
/**
* Appends a specified key/value pair as a new search parameter.
*/
append(name: string, value: string): void;
/**
* Deletes the given search parameter, and its associated value,
* from the list of all search parameters.
*/
delete(name: string): void;
/**
* Returns the first value associated to the given search parameter.
*/
get(name: string): string | null;
/**
* Returns all the values association with a given search parameter.
*/
getAll(name: string): string[];
/**
* Returns a Boolean indicating if such a search parameter exists.
*/
has(name: string): boolean;
/**
* Sets the value associated to a given search parameter to the given value.
* If there were several values, delete the others.
*/
set(name: string, value: string): void;
/**
* Sort all key/value pairs contained in this object in place
* and return undefined. The sort order is according to Unicode
* code points of the keys.
*/
sort(): void;
/**
* Returns a query string suitable for use in a URL.
*/
toString(): string;
/**
* Iterates over each name-value pair in the query
* and invokes the given function.
*/
forEach(
callbackfn: (value: string, key: string, parent: URLSearchParams) => void,
thisArg?: any
): void;
}
interface EventListener {
(evt: Event): void;
}
interface EventInit {
bubbles?: boolean;
cancelable?: boolean;
composed?: boolean;
}
interface Event {
readonly bubbles: boolean;
cancelBubble: boolean;
readonly cancelable: boolean;
readonly composed: boolean;
readonly currentTarget: EventTarget | null;
readonly defaultPrevented: boolean;
readonly eventPhase: number;
readonly isTrusted: boolean;
returnValue: boolean;
readonly srcElement: Element | null;
readonly target: EventTarget | null;
readonly timeStamp: number;
readonly type: string;
deepPath(): EventTarget[];
initEvent(type: string, bubbles?: boolean, cancelable?: boolean): void;
preventDefault(): void;
stopImmediatePropagation(): void;
stopPropagation(): void;
readonly AT_TARGET: number;
readonly BUBBLING_PHASE: number;
readonly CAPTURING_PHASE: number;
readonly NONE: number;
}
interface DomFile extends Blob {
readonly lastModified: number;
readonly name: string;
}
interface FilePropertyBag extends BlobPropertyBag {
lastModified?: number;
}
interface ProgressEvent extends Event {
readonly lengthComputable: boolean;
readonly loaded: number;
readonly total: number;
}
interface EventListenerOptions {
capture?: boolean;
}
interface AddEventListenerOptions extends EventListenerOptions {
once?: boolean;