diff options
author | Bartek IwaĆczuk <biwanczuk@gmail.com> | 2022-03-11 01:35:33 +0100 |
---|---|---|
committer | GitHub <noreply@github.com> | 2022-03-11 01:35:33 +0100 |
commit | 8dc26971ecf2bac3d2448337cb5c8d6037cdcf8a (patch) | |
tree | 6e3a4ec9b4795e4fe5f365f5ee1b1b4eb969e5ec | |
parent | 99816ad5065295bdbc30406e01b3b44bc1c4257b (diff) |
types: add Deno.PermissionOptions and Deno.PermissionOptionsObject (#13892)
Co-authored-by: Kitson Kelly <me@kitsonkelly.com>
-rw-r--r-- | cli/dts/lib.deno.ns.d.ts | 268 | ||||
-rw-r--r-- | cli/dts/lib.deno.unstable.d.ts | 15 |
2 files changed, 137 insertions, 146 deletions
diff --git a/cli/dts/lib.deno.ns.d.ts b/cli/dts/lib.deno.ns.d.ts index 14cf2a316..6e15542bf 100644 --- a/cli/dts/lib.deno.ns.d.ts +++ b/cli/dts/lib.deno.ns.d.ts @@ -114,6 +114,141 @@ declare namespace Deno { * See: https://no-color.org/ */ export const noColor: boolean; + export type PermissionOptions = "inherit" | "none" | PermissionOptionsObject; + + export interface PermissionOptionsObject { + /** Specifies if the `net` permission should be requested or revoked. + * If set to `"inherit"`, the current `env` permission will be inherited. + * If set to `true`, the global `net` permission will be requested. + * If set to `false`, the global `net` permission will be revoked. + * + * Defaults to "inherit". + */ + env?: "inherit" | boolean | string[]; + + /** Specifies if the `hrtime` permission should be requested or revoked. + * If set to `"inherit"`, the current `hrtime` permission will be inherited. + * If set to `true`, the global `hrtime` permission will be requested. + * If set to `false`, the global `hrtime` permission will be revoked. + * + * Defaults to "inherit". + */ + hrtime?: "inherit" | boolean; + + /** Specifies if the `net` permission should be requested or revoked. + * if set to `"inherit"`, the current `net` permission will be inherited. + * if set to `true`, the global `net` permission will be requested. + * if set to `false`, the global `net` permission will be revoked. + * if set to `string[]`, the `net` permission will be requested with the + * specified host strings with the format `"<host>[:<port>]`. + * + * Defaults to "inherit". + * + * Examples: + * + * ```ts + * import { assertEquals } from "https://deno.land/std/testing/asserts.ts"; + * + * Deno.test({ + * name: "inherit", + * permissions: { + * net: "inherit", + * }, + * async fn() { + * const status = await Deno.permissions.query({ name: "net" }) + * assertEquals(status.state, "granted"); + * }, + * }); + * ``` + * + * ```ts + * import { assertEquals } from "https://deno.land/std/testing/asserts.ts"; + * + * Deno.test({ + * name: "true", + * permissions: { + * net: true, + * }, + * async fn() { + * const status = await Deno.permissions.query({ name: "net" }); + * assertEquals(status.state, "granted"); + * }, + * }); + * ``` + * + * ```ts + * import { assertEquals } from "https://deno.land/std/testing/asserts.ts"; + * + * Deno.test({ + * name: "false", + * permissions: { + * net: false, + * }, + * async fn() { + * const status = await Deno.permissions.query({ name: "net" }); + * assertEquals(status.state, "denied"); + * }, + * }); + * ``` + * + * ```ts + * import { assertEquals } from "https://deno.land/std/testing/asserts.ts"; + * + * Deno.test({ + * name: "localhost:8080", + * permissions: { + * net: ["localhost:8080"], + * }, + * async fn() { + * const status = await Deno.permissions.query({ name: "net", host: "localhost:8080" }); + * assertEquals(status.state, "granted"); + * }, + * }); + * ``` + */ + net?: "inherit" | boolean | string[]; + + /** Specifies if the `ffi` permission should be requested or revoked. + * If set to `"inherit"`, the current `ffi` permission will be inherited. + * If set to `true`, the global `ffi` permission will be requested. + * If set to `false`, the global `ffi` permission will be revoked. + * + * Defaults to "inherit". + */ + ffi?: "inherit" | boolean | Array<string | URL>; + + /** Specifies if the `read` permission should be requested or revoked. + * If set to `"inherit"`, the current `read` permission will be inherited. + * If set to `true`, the global `read` permission will be requested. + * If set to `false`, the global `read` permission will be revoked. + * If set to `Array<string | URL>`, the `read` permission will be requested with the + * specified file paths. + * + * Defaults to "inherit". + */ + read?: "inherit" | boolean | Array<string | URL>; + + /** Specifies if the `run` permission should be requested or revoked. + * If set to `"inherit"`, the current `run` permission will be inherited. + * If set to `true`, the global `run` permission will be requested. + * If set to `false`, the global `run` permission will be revoked. + * + * Defaults to "inherit". + */ + run?: "inherit" | boolean | Array<string | URL>; + + /** Specifies if the `write` permission should be requested or revoked. + * If set to `"inherit"`, the current `write` permission will be inherited. + * If set to `true`, the global `write` permission will be requested. + * If set to `false`, the global `write` permission will be revoked. + * If set to `Array<string | URL>`, the `write` permission will be requested with the + * specified file paths. + * + * Defaults to "inherit". + */ + write?: "inherit" | boolean | Array<string | URL>; + } + export interface TestContext { /** Run a sub step of the parent test or step. Returns a promise * that resolves to a boolean signifying if the step completed successfully. @@ -174,138 +309,7 @@ declare namespace Deno { * * Defaults to "inherit". */ - permissions?: "inherit" | "none" | { - /** Specifies if the `net` permission should be requested or revoked. - * If set to `"inherit"`, the current `env` permission will be inherited. - * If set to `true`, the global `net` permission will be requested. - * If set to `false`, the global `net` permission will be revoked. - * - * Defaults to "inherit". - */ - env?: "inherit" | boolean | string[]; - - /** Specifies if the `hrtime` permission should be requested or revoked. - * If set to `"inherit"`, the current `hrtime` permission will be inherited. - * If set to `true`, the global `hrtime` permission will be requested. - * If set to `false`, the global `hrtime` permission will be revoked. - * - * Defaults to "inherit". - */ - hrtime?: "inherit" | boolean; - - /** Specifies if the `net` permission should be requested or revoked. - * if set to `"inherit"`, the current `net` permission will be inherited. - * if set to `true`, the global `net` permission will be requested. - * if set to `false`, the global `net` permission will be revoked. - * if set to `string[]`, the `net` permission will be requested with the - * specified host strings with the format `"<host>[:<port>]`. - * - * Defaults to "inherit". - * - * Examples: - * - * ```ts - * import { assertEquals } from "https://deno.land/std/testing/asserts.ts"; - * - * Deno.test({ - * name: "inherit", - * permissions: { - * net: "inherit", - * }, - * async fn() { - * const status = await Deno.permissions.query({ name: "net" }) - * assertEquals(status.state, "granted"); - * }, - * }); - * ``` - * - * ```ts - * import { assertEquals } from "https://deno.land/std/testing/asserts.ts"; - * - * Deno.test({ - * name: "true", - * permissions: { - * net: true, - * }, - * async fn() { - * const status = await Deno.permissions.query({ name: "net" }); - * assertEquals(status.state, "granted"); - * }, - * }); - * ``` - * - * ```ts - * import { assertEquals } from "https://deno.land/std/testing/asserts.ts"; - * - * Deno.test({ - * name: "false", - * permissions: { - * net: false, - * }, - * async fn() { - * const status = await Deno.permissions.query({ name: "net" }); - * assertEquals(status.state, "denied"); - * }, - * }); - * ``` - * - * ```ts - * import { assertEquals } from "https://deno.land/std/testing/asserts.ts"; - * - * Deno.test({ - * name: "localhost:8080", - * permissions: { - * net: ["localhost:8080"], - * }, - * async fn() { - * const status = await Deno.permissions.query({ name: "net", host: "localhost:8080" }); - * assertEquals(status.state, "granted"); - * }, - * }); - * ``` - */ - net?: "inherit" | boolean | string[]; - - /** Specifies if the `ffi` permission should be requested or revoked. - * If set to `"inherit"`, the current `ffi` permission will be inherited. - * If set to `true`, the global `ffi` permission will be requested. - * If set to `false`, the global `ffi` permission will be revoked. - * - * Defaults to "inherit". - */ - ffi?: "inherit" | boolean | Array<string | URL>; - - /** Specifies if the `read` permission should be requested or revoked. - * If set to `"inherit"`, the current `read` permission will be inherited. - * If set to `true`, the global `read` permission will be requested. - * If set to `false`, the global `read` permission will be revoked. - * If set to `Array<string | URL>`, the `read` permission will be requested with the - * specified file paths. - * - * Defaults to "inherit". - */ - read?: "inherit" | boolean | Array<string | URL>; - - /** Specifies if the `run` permission should be requested or revoked. - * If set to `"inherit"`, the current `run` permission will be inherited. - * If set to `true`, the global `run` permission will be requested. - * If set to `false`, the global `run` permission will be revoked. - * - * Defaults to "inherit". - */ - run?: "inherit" | boolean | Array<string | URL>; - - /** Specifies if the `write` permission should be requested or revoked. - * If set to `"inherit"`, the current `write` permission will be inherited. - * If set to `true`, the global `write` permission will be requested. - * If set to `false`, the global `write` permission will be revoked. - * If set to `Array<string | URL>`, the `write` permission will be requested with the - * specified file paths. - * - * Defaults to "inherit". - */ - write?: "inherit" | boolean | Array<string | URL>; - }; + permissions?: PermissionOptions; } /** Register a test which will be run when `deno test` is used on the command diff --git a/cli/dts/lib.deno.unstable.d.ts b/cli/dts/lib.deno.unstable.d.ts index 8175e8dd9..e3def724c 100644 --- a/cli/dts/lib.deno.unstable.d.ts +++ b/cli/dts/lib.deno.unstable.d.ts @@ -1203,20 +1203,7 @@ declare interface WorkerOptions { deno?: boolean | { namespace?: boolean; /** Set to `"none"` to disable all the permissions in the worker. */ - permissions?: "inherit" | "none" | { - env?: "inherit" | boolean | string[]; - hrtime?: "inherit" | boolean; - /** The format of the net access list must be `hostname[:port]` - * in order to be resolved. - * - * For example: `["https://deno.land", "localhost:8080"]`. - */ - net?: "inherit" | boolean | string[]; - ffi?: "inherit" | boolean | Array<string | URL>; - read?: "inherit" | boolean | Array<string | URL>; - run?: "inherit" | boolean | Array<string | URL>; - write?: "inherit" | boolean | Array<string | URL>; - }; + permissions?: Deno.PermissionOptions; }; } |