summaryrefslogtreecommitdiff
path: root/cli/js/lib.deno.unstable.d.ts
diff options
context:
space:
mode:
authorBartek Iwańczuk <biwanczuk@gmail.com>2020-07-13 18:23:24 +0200
committerGitHub <noreply@github.com>2020-07-13 18:23:24 +0200
commit11560387bb056098c55049db22c63550358c953a (patch)
treeeb3a4704c2ee7f2ae36a035833e1b1962a594ba0 /cli/js/lib.deno.unstable.d.ts
parent44187c81f4a09dbec0ca83b91e5f378590c93cff (diff)
Revert "feat: move unstable Deno.permissions to navigator.permissions… (#6729)
* Revert "feat: move unstable Deno.permissions to navigator.permissions (#6244)" This reverts commit 202e7fa6ad366ee56a6d070e94eaecb6dbc745bf.
Diffstat (limited to 'cli/js/lib.deno.unstable.d.ts')
-rw-r--r--cli/js/lib.deno.unstable.d.ts114
1 files changed, 114 insertions, 0 deletions
diff --git a/cli/js/lib.deno.unstable.d.ts b/cli/js/lib.deno.unstable.d.ts
index a6547ebca..05508a363 100644
--- a/cli/js/lib.deno.unstable.d.ts
+++ b/cli/js/lib.deno.unstable.d.ts
@@ -971,6 +971,120 @@ declare namespace Deno {
* Requires `allow-run` permission. */
export function kill(pid: number, signo: number): void;
+ /** 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";
+
+ /** The current status of the permission.
+ *
+ * See: https://w3c.github.io/permissions/#status-of-a-permission */
+ export type PermissionState = "granted" | "denied" | "prompt";
+
+ export interface RunPermissionDescriptor {
+ name: "run";
+ }
+
+ export interface ReadPermissionDescriptor {
+ name: "read";
+ path?: string;
+ }
+
+ export interface WritePermissionDescriptor {
+ name: "write";
+ path?: string;
+ }
+
+ export interface NetPermissionDescriptor {
+ name: "net";
+ /** Optional url associated with this descriptor.
+ *
+ * If specified: must be a valid url. Expected format: <scheme>://<host_or_ip>[:port][/path]
+ * If the scheme is unknown, callers should specify some scheme, such as x:// na:// unknown://
+ *
+ * See: https://www.iana.org/assignments/uri-schemes/uri-schemes.xhtml */
+ 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;
+
+ export class Permissions {
+ /** Resolves to the current status of a permission.
+ *
+ * ```ts
+ * const status = await Deno.permissions.query({ name: "read", path: "/etc" });
+ * if (status.state === "granted") {
+ * data = await Deno.readFile("/etc/passwd");
+ * }
+ * ```
+ */
+ query(desc: PermissionDescriptor): Promise<PermissionStatus>;
+
+ /** Revokes a permission, and resolves to the state of the permission.
+ *
+ * const status = await Deno.permissions.revoke({ name: "run" });
+ * assert(status.state !== "granted")
+ */
+ revoke(desc: PermissionDescriptor): Promise<PermissionStatus>;
+
+ /** Requests the permission, and resolves to the state of the permission.
+ *
+ * ```ts
+ * const status = await Deno.permissions.request({ name: "env" });
+ * if (status.state === "granted") {
+ * console.log(Deno.dir("home");
+ * } else {
+ * console.log("'env' permission is denied.");
+ * }
+ * ```
+ */
+ request(desc: PermissionDescriptor): Promise<PermissionStatus>;
+ }
+
+ /** **UNSTABLE**: Under consideration to move to `navigator.permissions` to
+ * match web API. It could look like `navigator.permissions.query({ name: Deno.symbols.read })`.
+ */
+ export const permissions: Permissions;
+
+ /** see: https://w3c.github.io/permissions/#permissionstatus */
+ export class PermissionStatus {
+ state: PermissionState;
+ constructor(state: PermissionState);
+ }
+
/** **UNSTABLE**: New API, yet to be vetted. Additional consideration is still
* necessary around the permissions required.
*