1
0
Fork 0
mirror of https://github.com/denoland/deno.git synced 2024-12-22 15:24:46 -05:00

refactor(cli/js/permissions): Split read and write permission descriptors (#4774)

This commit is contained in:
Nayeem Rahman 2020-04-28 15:43:58 +01:00 committed by GitHub
parent 927a771fa4
commit 76ee6fb335
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 44 additions and 23 deletions

View file

@ -1667,11 +1667,12 @@ declare namespace Deno {
Busy: ErrorConstructor;
};
/** **UNSTABLE**: potentially want names to overlap more with browser.
/** The name of a "powerful feature" which needs permission.
*
* The permissions as granted by the caller.
* See: https://w3c.github.io/permissions/#permission-registry
*
* 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"
@ -1686,39 +1687,45 @@ declare namespace Deno {
* See: https://w3c.github.io/permissions/#status-of-a-permission */
export type PermissionState = "granted" | "denied" | "prompt";
interface RunPermissionDescriptor {
export interface RunPermissionDescriptor {
name: "run";
}
interface ReadWritePermissionDescriptor {
name: "read" | "write";
export interface ReadPermissionDescriptor {
name: "read";
path?: string;
}
interface NetPermissionDescriptor {
export interface WritePermissionDescriptor {
name: "write";
path?: string;
}
export interface NetPermissionDescriptor {
name: "net";
url?: string;
}
interface EnvPermissionDescriptor {
export interface EnvPermissionDescriptor {
name: "env";
}
interface PluginPermissionDescriptor {
export interface PluginPermissionDescriptor {
name: "plugin";
}
interface HrtimePermissionDescriptor {
export interface HrtimePermissionDescriptor {
name: "hrtime";
}
/** Permission descriptors which define a permission which can be queried,
/** Permission descriptors which define a permission and can be queried,
* requested, or revoked.
*
* See: https://w3c.github.io/permissions/#permission-descriptor */
type PermissionDescriptor =
export type PermissionDescriptor =
| RunPermissionDescriptor
| ReadWritePermissionDescriptor
| ReadPermissionDescriptor
| WritePermissionDescriptor
| NetPermissionDescriptor
| EnvPermissionDescriptor
| PluginPermissionDescriptor
@ -1753,7 +1760,9 @@ declare namespace Deno {
request(desc: PermissionDescriptor): Promise<PermissionStatus>;
}
/** **UNSTABLE**: maybe move to `navigator.permissions` to match web API. */
/** **UNSTABLE**: maybe 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 */

View file

@ -13,29 +13,41 @@ export type PermissionName =
export type PermissionState = "granted" | "denied" | "prompt";
interface RunPermissionDescriptor {
export interface RunPermissionDescriptor {
name: "run";
}
interface ReadWritePermissionDescriptor {
name: "read" | "write";
export interface ReadPermissionDescriptor {
name: "read";
path?: string;
}
interface NetPermissionDescriptor {
export interface WritePermissionDescriptor {
name: "write";
path?: string;
}
export interface NetPermissionDescriptor {
name: "net";
url?: string;
}
interface EnvPermissionDescriptor {
export interface EnvPermissionDescriptor {
name: "env";
}
interface PluginPermissionDescriptor {
export interface PluginPermissionDescriptor {
name: "plugin";
}
interface HrtimePermissionDescriptor {
export interface HrtimePermissionDescriptor {
name: "hrtime";
}
type PermissionDescriptor =
export type PermissionDescriptor =
| RunPermissionDescriptor
| ReadWritePermissionDescriptor
| ReadPermissionDescriptor
| WritePermissionDescriptor
| NetPermissionDescriptor
| EnvPermissionDescriptor
| PluginPermissionDescriptor