summaryrefslogtreecommitdiff
path: root/cli/js/lib.deno.ns.d.ts
diff options
context:
space:
mode:
authorKitson Kelly <me@kitsonkelly.com>2020-07-09 19:00:18 +1000
committerGitHub <noreply@github.com>2020-07-09 05:00:18 -0400
commit202e7fa6ad366ee56a6d070e94eaecb6dbc745bf (patch)
tree745481e627ff691e0c196c18c310e54a8794badf /cli/js/lib.deno.ns.d.ts
parente92cf5b9e8530f7edf5cb7b157e6334a013da10d (diff)
feat: move unstable Deno.permissions to navigator.permissions (#6244)
Diffstat (limited to 'cli/js/lib.deno.ns.d.ts')
-rw-r--r--cli/js/lib.deno.ns.d.ts93
1 files changed, 93 insertions, 0 deletions
diff --git a/cli/js/lib.deno.ns.d.ts b/cli/js/lib.deno.ns.d.ts
index 4a3417b5d..0b46a0c4d 100644
--- a/cli/js/lib.deno.ns.d.ts
+++ b/cli/js/lib.deno.ns.d.ts
@@ -19,6 +19,40 @@ declare interface ImportMeta {
main: boolean;
}
+declare interface Permissions {
+ /** Resolves to the current status of a permission.
+ *
+ * ```ts
+ * const status = await navigator.permissions.query({ name: "read", path: "/etc" });
+ * if (status.state === "granted") {
+ * data = await Deno.readFile("/etc/passwd");
+ * }
+ * ```
+ */
+ query(permissionDesc: Deno.PermissionDescriptor): Promise<PermissionStatus>;
+
+ /** Requests the permission, and resolves to the state of the permission.
+ *
+ * ```ts
+ * const status = await navigator.permissions.request({ name: "env" });
+ * if (status.state === "granted") {
+ * console.log(Deno.dir("home");
+ * } else {
+ * console.log("'env' permission is denied.");
+ * }
+ * ```
+ */
+ request(permissionDesc: Deno.PermissionDescriptor): Promise<PermissionStatus>;
+
+ /** Revokes a permission, and resolves to the state of the permission.
+ *
+ * ```ts
+ * const status = await Deno.revoke({ name: "run" });
+ * ```
+ */
+ revoke(permissionDesc: Deno.PermissionDescriptor): Promise<PermissionStatus>;
+}
+
declare namespace Deno {
/** A set of error constructors that are raised by Deno APIs. */
export const errors: {
@@ -1897,6 +1931,65 @@ declare namespace Deno {
* Requires `allow-run` permission. */
export function run<T extends RunOptions = RunOptions>(opt: T): Process<T>;
+ /** The name of a "powerful feature" which needs permission.
+ *
+ * See: https://w3c.github.io/permissions/#permission-registry
+ *
+ * Note that the definition of `PermissionName` in the above spec is swapped
+ * out for a set of Deno permissions which are not web-compatible. */
+ export type PermissionName =
+ | "run"
+ | "read"
+ | "write"
+ | "net"
+ | "env"
+ | "plugin"
+ | "hrtime";
+
+ export interface RunPermissionDescriptor {
+ name: "run";
+ }
+
+ export interface ReadPermissionDescriptor {
+ name: "read";
+ path?: string;
+ }
+
+ export interface WritePermissionDescriptor {
+ name: "write";
+ path?: string;
+ }
+
+ export interface NetPermissionDescriptor {
+ name: "net";
+ url?: string;
+ }
+
+ export interface EnvPermissionDescriptor {
+ name: "env";
+ }
+
+ export interface PluginPermissionDescriptor {
+ name: "plugin";
+ }
+
+ export interface HrtimePermissionDescriptor {
+ name: "hrtime";
+ }
+
+ /** Permission descriptors which define a permission and can be queried,
+ * requested, or revoked.
+ *
+ * See: https://w3c.github.io/permissions/#permission-descriptor */
+ export type PermissionDescriptor =
+ | RunPermissionDescriptor
+ | ReadPermissionDescriptor
+ | WritePermissionDescriptor
+ | NetPermissionDescriptor
+ | EnvPermissionDescriptor
+ | PluginPermissionDescriptor
+ | HrtimePermissionDescriptor;
+
interface InspectOptions {
depth?: number;
}