1
0
Fork 0
mirror of https://github.com/denoland/deno.git synced 2024-12-22 23:34:47 -05:00
denoland-deno/Roadmap.md

367 lines
13 KiB
Markdown
Raw Normal View History

2018-06-15 07:33:23 -04:00
# Deno Roadmap
API and Feature requests should be submitted as PRs to this document.
2018-06-29 08:14:26 -04:00
## Target Use Cases
2018-09-22 08:43:44 -04:00
### Implementation of `cat`
#721
```ts
import * as deno from "deno";
for (let i = 1; i < deno.argv.length; i++) {
let filename = deno.argv[i];
let file = await deno.open(filename);
await deno.copy(deno.stdout, file);
2018-06-29 08:14:26 -04:00
}
```
2018-09-22 08:43:44 -04:00
### TCP Server
#725
2018-06-29 08:14:26 -04:00
2018-09-22 08:43:44 -04:00
```ts
import * as deno from "deno";
const listener = deno.listen("tcp", ":8080");
for await (const conn of listener.accept()) {
deno.copy(conn, conn);
}
2018-06-29 08:14:26 -04:00
```
2018-09-22 08:43:44 -04:00
### List deps (implemented)
```
% deno --deps http://gist.com/blah.js
2018-06-29 08:14:26 -04:00
http://gist.com/blah.js
http://gist.com/dep.js
2018-08-02 19:13:02 -04:00
https://github.com/denoland/deno/master/testing.js
2018-06-29 08:14:26 -04:00
%
```
2018-09-22 08:43:44 -04:00
## Security Model (partially implemented)
2018-06-29 08:14:26 -04:00
2018-10-04 05:01:21 -04:00
- We want to be secure by default; user should be able to run untrusted code,
2018-06-29 08:14:26 -04:00
like the web.
2018-10-04 05:01:21 -04:00
- Threat model:
- Modifiying/deleting local files
- Leaking private information
- Disallowed default:
- Network access
- Local write access
- Non-JS extensions
- Subprocesses
- Env access
- Allowed default:
- Local read access.
- argv, stdout, stderr, stdin access always allowed.
- Maybe: temp dir write access. (But what if they create symlinks there?)
- The user gets prompted when the software tries to do something it doesn't have
2018-06-29 08:14:26 -04:00
the privilege for.
2018-10-04 05:01:21 -04:00
- Have an option to get a stack trace when access is requested.
- Worried that granting access per file will give a false sense of security due
2018-06-29 08:14:26 -04:00
to monkey patching techniques. Access should be granted per program (js
context).
2018-07-03 15:18:42 -04:00
Example security prompts. Options are: YES, NO, PRINT STACK
2018-10-04 05:01:21 -04:00
2018-07-03 15:18:42 -04:00
```
Program requests write access to "~/.ssh/id_rsa". Grant? [yNs]
http://gist.github.com/asdfasd.js requests network access to "www.facebook.com". Grant? [yNs]
Program requests access to environment variables. Grant? [yNs]
Program requests to spawn `rm -rf /`. Grant? [yNs]
```
2018-06-29 08:14:26 -04:00
2018-10-04 05:01:21 -04:00
- cli flags to grant access ahead of time --allow-all --allow-write --allow-net
2018-06-29 08:14:26 -04:00
--allow-env --allow-exec
2018-10-04 05:01:21 -04:00
- in version two we will add ability to give finer grain access
2018-06-29 08:14:26 -04:00
--allow-net=facebook.com
2018-06-15 07:33:23 -04:00
## Milestone 1: Rust rewrite / V8 snapshot
2018-09-09 14:09:22 -04:00
Complete! https://github.com/denoland/deno/milestone/1
2018-06-15 07:33:23 -04:00
Go is a garbage collected language and we are worried that combining it with
V8's GC will lead to difficult contention problems down the road.
2018-06-15 07:33:23 -04:00
The V8Worker2 binding/concept is being ported to a new C++ library called
libdeno. libdeno will include the entire JS runtime as a V8 snapshot. It still
follows the message passing paradigm. Rust will be bound to this library to
implement the privileged part of Deno. See deno2/README.md for more details.
2018-10-04 05:01:21 -04:00
V8 Snapshots allow Deno to avoid recompiling the TypeScript compiler at startup.
This is already working.
2018-06-15 07:33:23 -04:00
When the rewrite is at feature parity with the Go prototype, we will release
binaries for people to try.
2018-09-09 14:09:22 -04:00
## Milestone 2: Scale binding infrastructure
2018-10-04 05:01:21 -04:00
ETA: October 2018 https://github.com/denoland/deno/milestone/2
2018-09-09 14:09:22 -04:00
We decided to use Tokio https://tokio.rs/ to provide asynchronous I/O, thread
pool execution, and as a base for high level support for various internet
2018-10-04 05:01:21 -04:00
protocols like HTTP. Tokio is strongly designed around the idea of Futures -
which map quite well onto JavaScript promises. We want to make it as easy as
2018-09-09 14:09:22 -04:00
possible to start a Tokio future from JavaScript and get a Promise for handling
it. We expect this to result in preliminary file system operations, fetch() for
http. Additionally we are working on CI, release, and benchmarking
infrastructure to scale development.
2018-06-29 08:14:26 -04:00
## libdeno C API.
2018-10-04 05:01:21 -04:00
Deno's privileged side will primarily be programmed in Rust. However there will
be a small C API that wraps V8 to 1) define the low-level message passing
2018-06-29 08:14:26 -04:00
semantics 2) provide a low-level test target 3) provide an ANSI C API binding
interface for Rust. V8 plus this C API is called libdeno and the important bits
of the API is specified here:
```c
// Data that gets transmitted.
typedef struct {
const char* data;
size_t len;
} deno_buf;
typedef void (*deno_sub_cb)(Deno* d, deno_buf bufs[], size_t nbufs)
2018-06-29 08:14:26 -04:00
void deno_set_callback(Deno* deno, deno_sub_cb cb);
// Executes javascript source code.
// Get error text with deno_last_exception().
// 0 = success, non-zero = failure.
// TODO(ry) Currently the return code has opposite semantics.
int deno_execute(Deno* d, const char* js_filename, const char* js_source);
// This call doesn't go into JS. This is thread-safe.
// TODO(ry) Currently this is called deno_pub. It should be renamed.
// deno_append is the desired name.
void deno_append(deno_buf buf);
// Should only be called at most once during the deno_sub_cb.
void deno_set_response(Deno* deno, deno_buf bufs[], size_t nbufs);
const char* deno_last_exception(Deno* d);
```
2018-06-15 07:33:23 -04:00
## TypeScript API.
2018-10-04 05:01:21 -04:00
This section will not attempt to over all of the APIs but give a general sense
of them.
2018-06-15 07:33:23 -04:00
2018-09-22 08:43:44 -04:00
### Internal: libdeno
2018-06-15 07:33:23 -04:00
2018-10-04 05:01:21 -04:00
This is the lowest-level interface to the privileged side. It provides little
more than passing ArrayBuffers in and out of the VM. The libdeno API is more or
less feature complete now. See
https://github.com/denoland/deno/blob/master/js/libdeno.ts
2018-06-15 07:33:23 -04:00
2018-09-22 08:43:44 -04:00
### Internal: Shared data between Rust and V8
2018-06-15 07:33:23 -04:00
2018-10-04 05:01:21 -04:00
We use Flatbuffers to define common structs and enums between TypeScript and
Rust. These common data structures are defined in
https://github.com/denoland/deno/blob/master/src/msg.fbs This is more or less
working.
2018-06-29 08:14:26 -04:00
2018-09-22 08:43:44 -04:00
### Public API
2018-06-29 08:14:26 -04:00
2018-10-04 05:01:21 -04:00
This is the global variables and various built-in modules, namely the `"deno"`
module.
2018-06-29 08:14:26 -04:00
2018-09-22 08:43:44 -04:00
Deno will provide common browser global utilities like `fetch()` and
`setTimeout()`.
2018-06-29 08:14:26 -04:00
2018-10-04 05:01:21 -04:00
Deno has typescript built-in. Users can access the built-in typescript using:
2018-09-22 08:43:44 -04:00
```ts
2018-10-04 05:01:21 -04:00
import * as ts from "typescript";
2018-06-29 08:14:26 -04:00
```
2018-10-04 05:01:21 -04:00
2018-09-22 08:43:44 -04:00
Deno has its own built-in module which is imported with:
2018-10-04 05:01:21 -04:00
2018-09-22 08:43:44 -04:00
```ts
2018-10-04 05:01:21 -04:00
import * as deno from "deno";
2018-09-22 08:43:44 -04:00
```
2018-10-04 05:01:21 -04:00
2018-09-22 08:43:44 -04:00
The rest of this section discusses what will be in the `deno` module.
2018-06-15 07:33:23 -04:00
2018-09-22 08:43:44 -04:00
Within Deno this is the high-level user facing API. However, the intention is to
expose functionality as simply as possible. There should be little or no
"ergonomics" APIs. (For example, `deno.readFileSync` only deals with
ArrayBuffers and does not have an encoding parameter to return strings.) The
intention is to make very easy to extend and link in external modules which can
then add this functionality.
2018-06-15 07:33:23 -04:00
Deno does not aim to be API compatible with Node in any respect. Deno will
export a single flat namespace "deno" under which all core functions are
2018-10-04 05:01:21 -04:00
defined. We leave it up to users to wrap Deno's namespace to provide some
2018-06-15 07:33:23 -04:00
compatibility with Node.
2018-09-22 08:43:44 -04:00
#### Top-level Await (Not Implemented)
2018-06-15 07:33:23 -04:00
2018-09-22 08:43:44 -04:00
#471
2018-06-15 07:33:23 -04:00
2018-10-04 05:01:21 -04:00
This will be put off until at least deno2 Milestone1 is complete. One of the
major problems is that top-level await calls are not syntactically valid
TypeScript.
2018-09-22 08:43:44 -04:00
#### I/O (Not Implemented) #721
2018-10-04 05:01:21 -04:00
There are many OS constructs that perform I/O: files, sockets, pipes. Deno aims
to provide a unified lowest common denominator interface to work with these
objects. Deno needs to operate on all of these asynchronously in order to not
block the event loop and it.
2018-10-04 05:01:21 -04:00
Sockets and pipes support non-blocking reads and write. Generally file I/O is
blocking but it can be done in a thread pool to avoid blocking the main thread.
Although file I/O can be made asynchronous, it does not support the same
non-blocking reads and writes that sockets and pipes do.
The following interfaces support files, socket, and pipes and are heavily
inspired by Go. The main difference in porting to JavaScript is that errors will
2018-10-04 05:01:21 -04:00
be handled by exceptions, modulo EOF, which is returned as part of `ReadResult`.
```ts
// The bytes read during an I/O call and a boolean indicating EOF.
interface ReadResult {
nread: number;
eof: boolean;
}
// Reader is the interface that wraps the basic read() method.
// https://golang.org/pkg/io/#Reader
interface Reader {
// read() reads up to p.byteLength bytes into p. It returns 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 == nil. The next read() should return 0, EOF.
//
// Callers should always process the n > 0 bytes returned before considering
// the error err. 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 nil error, except when p.byteLength == 0. Callers should treat a
// return of 0 and nil as indicating that nothing happened; in particular it
// does not indicate EOF.
//
// Implementations must not retain p.
2018-10-04 05:01:21 -04:00
read(p: ArrayBufferView): Promise<ReadResult>;
}
// Writer is the interface that wraps the basic write() method.
// https://golang.org/pkg/io/#Writer
interface Writer {
// write() writes p.byteLength bytes from p to the underlying data stream. It
// returns 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-nil error if it returns n < p.byteLength. write() must not modify the
// slice data, even temporarily.
//
// Implementations must not retain p.
2018-10-04 05:01:21 -04:00
write(p: ArrayBufferView): Promise<number>;
}
// https://golang.org/pkg/io/#Closer
interface Closer {
// The behavior of Close after the first call is undefined. Specific
// implementations may document their own behavior.
close(): void;
}
// https://golang.org/pkg/io/#Seeker
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.
2018-10-04 05:01:21 -04:00
seek(offset: number, whence: number): Promise<void>;
}
// https://golang.org/pkg/io/#ReadCloser
2018-10-04 05:01:21 -04:00
interface ReaderCloser extends Reader, Closer {}
// https://golang.org/pkg/io/#WriteCloser
2018-10-04 05:01:21 -04:00
interface WriteCloser extends Writer, Closer {}
// https://golang.org/pkg/io/#ReadSeeker
2018-10-04 05:01:21 -04:00
interface ReadSeeker extends Reader, Seeker {}
// https://golang.org/pkg/io/#WriteSeeker
2018-10-04 05:01:21 -04:00
interface WriteSeeker extends Writer, Seeker {}
// https://golang.org/pkg/io/#ReadWriteCloser
2018-10-04 05:01:21 -04:00
interface ReadWriteCloser extends Reader, Writer, Closer {}
// https://golang.org/pkg/io/#ReadWriteSeeker
2018-10-04 05:01:21 -04:00
interface ReadWriteSeeker extends Reader, Writer, Seeker {}
```
2018-10-04 05:01:21 -04:00
These interfaces are well specified, simple, and have very nice utility
functions that will be easy to port. Some example utilites:
2018-10-04 05:01:21 -04:00
```ts
// copy() 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.
//
// https://golang.org/pkg/io/#Copy
async function copy(dst: Writer, src: Reader): Promise<number> {
let n = 0;
const b = new ArrayBufferView(1024);
let got_eof = false;
while (got_eof === false) {
let result = await src.read(b);
if (result.eof) got_eof = true;
n += await dst.write(b.subarray(0, result.nread));
}
return n;
}
// MultiWriter creates a writer that duplicates its writes to all the provided
// writers, similar to the Unix tee(1) command.
//
// Each write is written to each listed writer, one at a time. If a listed
// writer returns an error, that overall write operation stops and returns the
// error; it does not continue down the list.
//
// https://golang.org/pkg/io/#MultiWriter
function multiWriter(writers: ...Writer): Writer {
return {
write: async (p: ArrayBufferView) => Promise<number> {
let n;
let nwritten = await Promise.all(writers.map((w) => w.write(p)));
return nwritten[0];
// TODO unsure of proper semantics for return value..
}
};
}
```
A utility function will be provided to make any `Reader` into an
`AsyncIterator`, which has very similar semanatics.
```ts
function readerIterator(r: deno.Reader): AsyncIterator<ArrayBufferView>;
// Example
for await (let buf of readerIterator(socket)) {
console.log(`read ${buf.byteLength} from socket`);
}
```