mirror of
https://github.com/denoland/deno.git
synced 2024-11-22 15:06:54 -05:00
parent
54d897c140
commit
1437838ea1
1 changed files with 19 additions and 19 deletions
|
@ -16,26 +16,26 @@ On the CLI, read permission for `/foo/bar` is represented as
|
|||
`--allow-read=/foo/bar`. In runtime JS, it is represented as the following:
|
||||
|
||||
```ts
|
||||
const desc = { name: "read", path: "/foo/bar" };
|
||||
const desc = { name: "read", path: "/foo/bar" } as const;
|
||||
```
|
||||
|
||||
Other examples:
|
||||
|
||||
```ts
|
||||
// Global write permission.
|
||||
const desc1 = { name: "write" };
|
||||
const desc1 = { name: "write" } as const;
|
||||
|
||||
// Write permission to `$PWD/foo/bar`.
|
||||
const desc2 = { name: "write", path: "foo/bar" };
|
||||
const desc2 = { name: "write", path: "foo/bar" } as const;
|
||||
|
||||
// Global net permission.
|
||||
const desc3 = { name: "net" };
|
||||
const desc3 = { name: "net" } as const;
|
||||
|
||||
// Net permission to 127.0.0.1:8000.
|
||||
const desc4 = { name: "net", url: "127.0.0.1:8000" };
|
||||
const desc4 = { name: "net", url: "127.0.0.1:8000" } as const;
|
||||
|
||||
// High-resolution time permission.
|
||||
const desc5 = { name: "hrtime" };
|
||||
const desc5 = { name: "hrtime" } as const;
|
||||
```
|
||||
|
||||
### Query permissions
|
||||
|
@ -45,15 +45,15 @@ Check, by descriptor, if a permission is granted or not.
|
|||
```ts
|
||||
// deno run --unstable --allow-read=/foo main.ts
|
||||
|
||||
const desc1 = { name: "read", path: "/foo" };
|
||||
const desc1 = { name: "read", path: "/foo" } as const;
|
||||
console.log(await Deno.permissions.query(desc1));
|
||||
// PermissionStatus { state: "granted" }
|
||||
|
||||
const desc2 = { name: "read", path: "/foo/bar" };
|
||||
const desc2 = { name: "read", path: "/foo/bar" } as const;
|
||||
console.log(await Deno.permissions.query(desc2));
|
||||
// PermissionStatus { state: "granted" }
|
||||
|
||||
const desc3 = { name: "read", path: "/bar" };
|
||||
const desc3 = { name: "read", path: "/bar" } as const;
|
||||
console.log(await Deno.permissions.query(desc3));
|
||||
// PermissionStatus { state: "prompt" }
|
||||
```
|
||||
|
@ -82,13 +82,13 @@ _[stronger than](https://www.w3.org/TR/permissions/#ref-for-permissiondescriptor
|
|||
More examples:
|
||||
|
||||
```ts
|
||||
const desc1 = { name: "write" };
|
||||
const desc1 = { name: "write" } as const;
|
||||
// is stronger than
|
||||
const desc2 = { name: "write", path: "/foo" };
|
||||
const desc2 = { name: "write", path: "/foo" } as const;
|
||||
|
||||
const desc3 = { name: "net" };
|
||||
const desc3 = { name: "net" } as const;
|
||||
// is stronger than
|
||||
const desc4 = { name: "net", url: "127.0.0.1:8000" };
|
||||
const desc4 = { name: "net", url: "127.0.0.1:8000" } as const;
|
||||
```
|
||||
|
||||
### Request permissions
|
||||
|
@ -98,13 +98,13 @@ Request an ungranted permission from the user via CLI prompt.
|
|||
```ts
|
||||
// deno run --unstable main.ts
|
||||
|
||||
const desc1 = { name: "read", path: "/foo" };
|
||||
const desc1 = { name: "read", path: "/foo" } as const;
|
||||
const status1 = await Deno.permissions.request(desc1);
|
||||
// ⚠️ Deno requests read access to "/foo". Grant? [g/d (g = grant, d = deny)] g
|
||||
console.log(status1);
|
||||
// PermissionStatus { state: "granted" }
|
||||
|
||||
const desc2 = { name: "read", path: "/bar" };
|
||||
const desc2 = { name: "read", path: "/bar" } as const;
|
||||
const status2 = await Deno.permissions.request(desc2);
|
||||
// ⚠️ Deno requests read access to "/bar". Grant? [g/d (g = grant, d = deny)] d
|
||||
console.log(status2);
|
||||
|
@ -129,7 +129,7 @@ Downgrade a permission from "granted" to "prompt".
|
|||
```ts
|
||||
// deno run --unstable --allow-read=/foo main.ts
|
||||
|
||||
const desc = { name: "read", path: "/foo" };
|
||||
const desc = { name: "read", path: "/foo" } as const;
|
||||
console.log(await Deno.permissions.revoke(desc));
|
||||
// PermissionStatus { state: "prompt" }
|
||||
```
|
||||
|
@ -140,7 +140,7 @@ one granted on the CLI?
|
|||
```ts
|
||||
// deno run --unstable --allow-read=/foo main.ts
|
||||
|
||||
const desc = { name: "read", path: "/foo/bar" };
|
||||
const desc = { name: "read", path: "/foo/bar" } as const;
|
||||
console.log(await Deno.permissions.revoke(desc));
|
||||
// PermissionStatus { state: "granted" }
|
||||
```
|
||||
|
@ -177,11 +177,11 @@ whichever _explicitly granted permission descriptor_ is _stronger than_ `desc`.
|
|||
```ts
|
||||
// deno run --unstable --allow-read=/foo main.ts
|
||||
|
||||
const desc = { name: "read", path: "/foo/bar" };
|
||||
const desc = { name: "read", path: "/foo/bar" } as const;
|
||||
console.log(await Deno.permissions.revoke(desc)); // Insufficient.
|
||||
// PermissionStatus { state: "granted" }
|
||||
|
||||
const strongDesc = { name: "read", path: "/foo" };
|
||||
const strongDesc = { name: "read", path: "/foo" } as const;
|
||||
await Deno.permissions.revoke(strongDesc); // Good.
|
||||
|
||||
console.log(await Deno.permissions.query(desc));
|
||||
|
|
Loading…
Reference in a new issue