Skip to content

Commit

Permalink
permissions: use discriminated union type for PermissionDescriptor
Browse files Browse the repository at this point in the history
  • Loading branch information
kt3k committed Oct 26, 2019
1 parent 5024f1c commit 3505437
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 5 deletions.
16 changes: 13 additions & 3 deletions cli/js/lib.deno_runtime.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -891,11 +891,21 @@ declare namespace Deno {
| "env"
| "hrtime";
export type PermissionState = "granted" | "denied" | "prompt";
interface PermissionDescriptor {
name: PermissionName;
url?: string;
interface SimplePermissionDescriptor {
name: "run" | "env" | "hrtime";
}
interface PathPermissionDescriptor {
name: "read" | "write";
path?: string;
}
interface NetPermissionDescriptor {
name: "net";
url?: string;
}
type PermissionDescriptor =
| SimplePermissionDescriptor
| PathPermissionDescriptor
| NetPermissionDescriptor
export class Permissions {
query(d: PermissionDescriptor): Promise<PermissionStatus>;
revoke(d: PermissionDescriptor): Promise<PermissionStatus>;
Expand Down
17 changes: 15 additions & 2 deletions cli/js/permissions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,12 +18,25 @@ export type PermissionName =
export type PermissionState = "granted" | "denied" | "prompt";

/** See: https://w3c.github.io/permissions/#permission-descriptor */
interface PermissionDescriptor {
name: PermissionName;
interface SimplePermissionDescriptor {
name: "env" | "run" | "hrtime";
}

interface NetPermissionDescriptor {
name: "net";
url?: string;
}

interface PathPermissionDescriptor {
name: "read" | "write";
path?: string;
}

type PermissionDescriptor =
| SimplePermissionDescriptor
| PathPermissionDescriptor
| NetPermissionDescriptor

/** https://w3c.github.io/permissions/#permissionstatus */
export class PermissionStatus {
constructor(public state: PermissionState) {}
Expand Down

0 comments on commit 3505437

Please sign in to comment.