summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorNayeem Rahman <nayeemrmn99@gmail.com>2021-01-29 13:15:59 +0000
committerGitHub <noreply@github.com>2021-01-29 08:15:59 -0500
commitdaad575825ab82f1147d48c0e0e8963d5d29e879 (patch)
tree21e14ac7d146e3a839ced7b66e8bd09570e48606
parentf3122442db70d16f4861f39edf32d89ac2530aa2 (diff)
fix(cli): Move WorkerOptions::deno types to unstable (#9163)
-rw-r--r--cli/dts/lib.deno.shared_globals.d.ts77
-rw-r--r--cli/dts/lib.deno.unstable.d.ts86
-rw-r--r--runtime/js/11_workers.js6
3 files changed, 85 insertions, 84 deletions
diff --git a/cli/dts/lib.deno.shared_globals.d.ts b/cli/dts/lib.deno.shared_globals.d.ts
index 52ad132f7..9cfe45cfa 100644
--- a/cli/dts/lib.deno.shared_globals.d.ts
+++ b/cli/dts/lib.deno.shared_globals.d.ts
@@ -487,83 +487,6 @@ interface WorkerEventMap extends AbstractWorkerEventMap {
interface WorkerOptions {
type?: "classic" | "module";
name?: string;
- /** UNSTABLE: New API.
- *
- * Set deno.namespace to `true` to make `Deno` namespace and all of its methods
- * available to worker thread. The namespace is disabled by default.
- *
- * Configure deno.permissions options to change the level of access the worker will
- * have. By default it will inherit the permissions of its parent thread. The permissions
- * of a worker can't be extended beyond its parent's permissions reach.
- * - "inherit" will take the permissions of the thread the worker is created in
- * - You can disable/enable permissions all together by passing a boolean
- * - You can provide a list of routes relative to the file the worker
- * is created in to limit the access of the worker (read/write permissions only)
- *
- * Example:
- *
- * ```ts
- * // mod.ts
- * const worker = new Worker(
- * new URL("deno_worker.ts", import.meta.url).href, {
- * type: "module",
- * deno: {
- * namespace: true,
- * permissions: {
- * read: true,
- * },
- * },
- * }
- * );
- * worker.postMessage({ cmd: "readFile", fileName: "./log.txt" });
- *
- * // deno_worker.ts
- *
- *
- * self.onmessage = async function (e) {
- * const { cmd, fileName } = e.data;
- * if (cmd !== "readFile") {
- * throw new Error("Invalid command");
- * }
- * const buf = await Deno.readFile(fileName);
- * const fileContents = new TextDecoder().decode(buf);
- * console.log(fileContents);
- * }
- * ```
- *
- * // log.txt
- * hello world
- * hello world 2
- *
- * // run program
- * $ deno run --allow-read mod.ts
- * hello world
- * hello world2
- *
- */
- // TODO(Soremwar)
- // `deno: true` is kept for backwards compatibility with the previous worker
- // options implementation. Remove for 2.0.
- deno?: true | {
- namespace?: boolean;
- /** Set to `"none"` to disable all the permissions in the worker. */
- permissions?: "inherit" | "none" | {
- env?: "inherit" | boolean;
- hrtime?: "inherit" | boolean;
- /** The format of the net access list must be `hostname[:port]`
- * in order to be resolved.
- *
- * ```
- * net: ["https://deno.land", "localhost:8080"],
- * ```
- * */
- net?: "inherit" | boolean | string[];
- plugin?: "inherit" | boolean;
- read?: "inherit" | boolean | Array<string | URL>;
- run?: "inherit" | boolean;
- write?: "inherit" | boolean | Array<string | URL>;
- };
- };
}
declare class Worker extends EventTarget {
diff --git a/cli/dts/lib.deno.unstable.d.ts b/cli/dts/lib.deno.unstable.d.ts
index c73703368..0266dd750 100644
--- a/cli/dts/lib.deno.unstable.d.ts
+++ b/cli/dts/lib.deno.unstable.d.ts
@@ -503,7 +503,7 @@ declare namespace Deno {
/** If `true` then the sources will be typed checked, returning any
* diagnostic errors in the result. If `false` type checking will be
* skipped. Defaults to `true`.
- *
+ *
* *Note* by default, only TypeScript will be type checked, just like on
* the command line. Use the `compilerOptions` options of `checkJs` to
* enable type checking of JavaScript. */
@@ -543,15 +543,15 @@ declare namespace Deno {
/**
* **UNSTABLE**: new API, yet to be vetted.
- *
+ *
* Similar to the command line functionality of `deno run` or `deno cache`,
* `Deno.emit()` provides a way to provide Deno arbitrary JavaScript
* or TypeScript and have it return JavaScript based on the options and
* settings provided. The source code can either be provided or the modules
* can be fetched and resolved in line with the behavior of the command line.
- *
+ *
* Requires `allow-read` and/or `allow-net` if sources are not provided.
- *
+ *
* @param rootSpecifier The specifier that will be used as the entry point.
* If no sources are provided, then the specifier would
* be the same as if you typed it on the command line for
@@ -1347,3 +1347,81 @@ declare function fetch(
input: Request | URL | string,
init?: RequestInit & { client: Deno.HttpClient },
): Promise<Response>;
+
+declare interface WorkerOptions {
+ /** UNSTABLE: New API.
+ *
+ * Set deno.namespace to `true` to make `Deno` namespace and all of its
+ * methods available to the worker environment. Defaults to `false`.
+ *
+ * Configure deno.permissions options to change the level of access the worker will
+ * have. By default it will inherit the permissions of its parent thread. The permissions
+ * of a worker can't be extended beyond its parent's permissions reach.
+ * - "inherit" will take the permissions of the thread the worker is created in
+ * - You can disable/enable permissions all together by passing a boolean
+ * - You can provide a list of routes relative to the file the worker
+ * is created in to limit the access of the worker (read/write permissions only)
+ *
+ * Example:
+ *
+ * ```ts
+ * // mod.ts
+ * const worker = new Worker(
+ * new URL("deno_worker.ts", import.meta.url).href, {
+ * type: "module",
+ * deno: {
+ * namespace: true,
+ * permissions: {
+ * read: true,
+ * },
+ * },
+ * }
+ * );
+ * worker.postMessage({ cmd: "readFile", fileName: "./log.txt" });
+ *
+ * // deno_worker.ts
+ *
+ *
+ * self.onmessage = async function (e) {
+ * const { cmd, fileName } = e.data;
+ * if (cmd !== "readFile") {
+ * throw new Error("Invalid command");
+ * }
+ * const buf = await Deno.readFile(fileName);
+ * const fileContents = new TextDecoder().decode(buf);
+ * console.log(fileContents);
+ * }
+ *
+ * // $ cat log.txt
+ * // hello world
+ * // hello world 2
+ *
+ * // $ deno run --allow-read mod.ts
+ * // hello world
+ * // hello world2
+ * ```
+ */
+ // TODO(Soremwar)
+ // `deno: boolean` is kept for backwards compatibility with the previous
+ // worker options implementation. Remove for 2.0.
+ deno?: boolean | {
+ namespace?: boolean;
+ /** Set to `"none"` to disable all the permissions in the worker. */
+ permissions?: "inherit" | "none" | {
+ env?: "inherit" | boolean;
+ hrtime?: "inherit" | boolean;
+ /** The format of the net access list must be `hostname[:port]`
+ * in order to be resolved.
+ *
+ * ```
+ * net: ["https://deno.land", "localhost:8080"],
+ * ```
+ * */
+ net?: "inherit" | boolean | string[];
+ plugin?: "inherit" | boolean;
+ read?: "inherit" | boolean | Array<string | URL>;
+ run?: "inherit" | boolean;
+ write?: "inherit" | boolean | Array<string | URL>;
+ };
+ };
+}
diff --git a/runtime/js/11_workers.js b/runtime/js/11_workers.js
index 5be14d461..c78eee833 100644
--- a/runtime/js/11_workers.js
+++ b/runtime/js/11_workers.js
@@ -143,10 +143,10 @@
} = options;
// TODO(Soremwar)
- // `deno: true` is kept for backwards compatibility with the previous worker
- // options implementation. Remove for 2.0
+ // `deno: boolean` is kept for backwards compatibility with the previous
+ // worker options implementation. Remove for 2.0
let workerDenoAttributes;
- if (deno === true) {
+ if (typeof deno == "boolean") {
workerDenoAttributes = {
// Change this to enable the Deno namespace by default
namespace: deno,