1
0
Fork 0
mirror of https://github.com/denoland/deno.git synced 2024-11-01 09:24:20 -04:00
denoland-deno/cli/js/permissions.ts

79 lines
1.8 KiB
TypeScript
Raw Normal View History

2020-01-02 15:13:47 -05:00
// Copyright 2018-2020 the Deno authors. All rights reserved. MIT license.
import * as permissionsOps from "./ops/permissions.ts";
export type PermissionName =
| "read"
| "write"
| "net"
| "env"
| "run"
| "plugin"
| "hrtime";
// NOTE: Keep in sync with cli/permissions.rs
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";
url?: string;
}
export interface EnvPermissionDescriptor {
name: "env";
}
export interface PluginPermissionDescriptor {
name: "plugin";
}
export interface HrtimePermissionDescriptor {
name: "hrtime";
}
export type PermissionDescriptor =
| RunPermissionDescriptor
| ReadPermissionDescriptor
| WritePermissionDescriptor
| NetPermissionDescriptor
| EnvPermissionDescriptor
| PluginPermissionDescriptor
| HrtimePermissionDescriptor;
export class PermissionStatus {
constructor(public state: PermissionState) {}
// TODO(kt3k): implement onchange handler
}
export class Permissions {
2020-03-20 09:38:34 -04:00
query(desc: PermissionDescriptor): Promise<PermissionStatus> {
const state = permissionsOps.query(desc);
2020-03-20 09:38:34 -04:00
return Promise.resolve(new PermissionStatus(state));
}
2020-03-20 09:38:34 -04:00
revoke(desc: PermissionDescriptor): Promise<PermissionStatus> {
const state = permissionsOps.revoke(desc);
2020-03-20 09:38:34 -04:00
return Promise.resolve(new PermissionStatus(state));
}
2019-11-11 10:33:29 -05:00
2020-03-20 09:38:34 -04:00
request(desc: PermissionDescriptor): Promise<PermissionStatus> {
const state = permissionsOps.request(desc);
2020-03-20 09:38:34 -04:00
return Promise.resolve(new PermissionStatus(state));
2019-11-11 10:33:29 -05:00
}
}
export const permissions = new Permissions();