mirror of
https://github.com/denoland/deno.git
synced 2025-01-03 12:58:54 -05:00
fix(cli): Move WorkerOptions::deno types to unstable (#9163)
This commit is contained in:
parent
f3122442db
commit
daad575825
3 changed files with 85 additions and 84 deletions
77
cli/dts/lib.deno.shared_globals.d.ts
vendored
77
cli/dts/lib.deno.shared_globals.d.ts
vendored
|
@ -487,83 +487,6 @@ interface WorkerEventMap extends AbstractWorkerEventMap {
|
||||||
interface WorkerOptions {
|
interface WorkerOptions {
|
||||||
type?: "classic" | "module";
|
type?: "classic" | "module";
|
||||||
name?: string;
|
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 {
|
declare class Worker extends EventTarget {
|
||||||
|
|
78
cli/dts/lib.deno.unstable.d.ts
vendored
78
cli/dts/lib.deno.unstable.d.ts
vendored
|
@ -1347,3 +1347,81 @@ declare function fetch(
|
||||||
input: Request | URL | string,
|
input: Request | URL | string,
|
||||||
init?: RequestInit & { client: Deno.HttpClient },
|
init?: RequestInit & { client: Deno.HttpClient },
|
||||||
): Promise<Response>;
|
): 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>;
|
||||||
|
};
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
|
@ -143,10 +143,10 @@
|
||||||
} = options;
|
} = options;
|
||||||
|
|
||||||
// TODO(Soremwar)
|
// TODO(Soremwar)
|
||||||
// `deno: true` is kept for backwards compatibility with the previous worker
|
// `deno: boolean` is kept for backwards compatibility with the previous
|
||||||
// options implementation. Remove for 2.0
|
// worker options implementation. Remove for 2.0
|
||||||
let workerDenoAttributes;
|
let workerDenoAttributes;
|
||||||
if (deno === true) {
|
if (typeof deno == "boolean") {
|
||||||
workerDenoAttributes = {
|
workerDenoAttributes = {
|
||||||
// Change this to enable the Deno namespace by default
|
// Change this to enable the Deno namespace by default
|
||||||
namespace: deno,
|
namespace: deno,
|
||||||
|
|
Loading…
Reference in a new issue