Skip to content

Commit

Permalink
Fill in some error types. (#58)
Browse files Browse the repository at this point in the history
* Write persist/persisted algos

* no backticks on true

* Fill in some error types.

* Indentation fixes

* Fix redundant step.

* Streamline delete bucket.

Co-authored-by: Evan Stade <estade@chromium.org>
  • Loading branch information
evanstade and Evan Stade authored Jan 9, 2023
1 parent 9aaa31c commit f93e40a
Showing 1 changed file with 65 additions and 67 deletions.
132 changes: 65 additions & 67 deletions index.bs
Original file line number Diff line number Diff line change
Expand Up @@ -69,79 +69,89 @@ dictionary StorageBucketOptions {

<div algorithm>

The <dfn method for="StorageBucketManager">open(|name|, |options|)</dfn> method steps are:
The <dfn method for="StorageBucketManager">open(|name|, |options|)</dfn> method steps are:

1. Let |environment| be [=/this=]'s [=/relevant settings object=].
1. Let |environment| be [=/this=]'s [=/relevant settings object=].

1. Let |storageKey| be the result of running [=obtain a storage key=] given |environment|.

1. Let |storageKey| be the result of running [=obtain a storage key=] given |environment|.
1. If |storageKey| is failure, then [=exception/throw=] a "{{SecurityError}}" {{DOMException}} and abort these steps.

1. If |storageKey| is failure, then [=exception/throw=] a "{{SecurityError}}" {{DOMException}} and abort these steps.
1. Let |p| be [=a new promise=].

1. Let |p| be [=a new promise=].
1. Run the following steps [=in parallel=]:

1. Run the following steps [=in parallel=]:
1. If the result of [=validate a bucket name=] with |name| is failure, then [=/reject=] |p| with an {{InvalidCharacterError}} and abort these steps.

1. Let |r| be the result of running [=open a bucket=] with |storageKey|, |name|, and |options|.
1. Let |r| be the result of running [=open a bucket=] with |storageKey|, |name|, and |options|.

1. If |r| is failure, then [=reject=] |p| with a {{TypeError}} and abort these steps.
1. If |r| is failure, then [=reject=] |p| with a {{TypeError}} and abort these steps.

1. [=/Resolve=] |p| with |r|.
1. [=/Resolve=] |p| with |r|.

1. Return |p|.
1. Return |p|.

</div>

<div algorithm>

To <dfn>open a bucket</dfn> for a |storageKey| given a bucket |name| and optional |options|, run the following steps:
To <dfn>open a bucket</dfn> for a |storageKey| given a bucket |name| and optional |options|, run the following steps:

1. Let |expires| be |options|["{{StorageBucketOptions/expires}}"] if it exists, otherwise undefined.

1. If |expires| is not undefined, and is less than or equal to now, then return failure.

1. Let |quota| be |options|["{{StorageBucketOptions/quota}}"] if it exists, otherwise undefined.

1. If |name| contain any character that is not [=ASCII lower alpha=], [=ASCII digit=], U+005F (_), or U+002D(-), then return failure.
1. If |quota| is less than or equal to zero, then return failure.

1. If |name| [=string/length=] is 0 or exceeds 64, then return failure.
1. Let |persisted| be false.

1. If |name| begins with U+005F (_) or U+002D(-), then return failure.
1. If |options|["{{StorageBucketOptions/persisted}}"] is true, then:

1. Let |expires| be |options|["{{StorageBucketOptions/expires}}"] if it exists, otherwise undefined.
1. Let |permission| be the result of [=/requesting permission to use=] "<code>persistent-storage</code>".

1. If |expires| is not undefined, and is less than or equal to now, then return failure.
1. If |permission| is "{{PermissionState/granted}}", then set |persisted| to true.

1. Let |quota| be |options|["{{StorageBucketOptions/quota}}"] if it exists, otherwise undefined.
1. Let |bucket| be the [=/storage bucket=] named |name| in |storageKey| or null otherwise.

1. If |quota| is less than or equal to zero, then return failure.
1. If |bucket| is non-null and |bucket|'s [=bucket expiration=] is less than or equal to now, then:

1. Let |persisted| be false.
1. Remove |bucket|.

1. If |options|["{{StorageBucketOptions/persisted}}"] is true, then:
1. Set |bucket| to null.

1. Let |permission| be the result of [=/requesting permission to use=] "<code>persistent-storage</code>".
1. If |bucket| is null, then:

1. If |permission| is "{{PermissionState/granted}}", then set |persisted| to true.
1. Let |bucket| be a new [=/storage bucket=] with name |name|

1. Let |bucket| be the [=/storage bucket=] named |name| in |storageKey| or null otherwise.
1. Set |bucket|'s [=bucket durability|durability=] to |options|["{{StorageBucketOptions/durability}}"] if it exists.

1. If |bucket| is non-null and |bucket|'s [=bucket expiration=] is less than or equal to now, then:
1. Set |bucket|'s [=bucket quota|quota=] to |quota|.

1. Remove |bucket|.
1. If |persisted| is true, set |bucket|'s [=/bucket mode=] to "<code>persistent</code>".

1. Set |bucket| to null.
1. Set |bucket|'s [=bucket expiration|expiration=] to |expires|.

1. If |bucket| is null, then:
1. Let |storageBucket| be a new {{StorageBucket}}.

1. Let |bucket| be a new [=/storage bucket=] with name |name|
1. Set |storageBucket|'s [=/storage bucket=] to |bucket|.

1. Set |bucket|'s [=bucket durability|durability=] to |options|["{{StorageBucketOptions/durability}}"] if it exists.
1. Return |storageBucket|.

1. Set |bucket|'s [=bucket quota|quota=] to |quota|.
</div>

<div algorithm>

1. If |persisted| is true, set |bucket|'s [=/bucket mode=] to "<code>persistent</code>".
To <dfn>validate a bucket name</dfn> given string |name|, run the following steps:

1. Set |bucket|'s [=bucket expiration|expiration=] to |expires|.
1. If |name| contains any character that is not [=ASCII lower alpha=], [=ASCII digit=], U+005F (_), or U+002D(-), then return failure.

1. Let |storageBucket| be a new {{StorageBucket}}.
1. If |name| [=string/length=] is 0 or exceeds 64, then return failure.

1. Set |storageBucket|'s [=/storage bucket=] to |bucket|.
1. If |name| begins with U+005F (_) or U+002D(-), then return failure.

1. Return |storageBucket|.
1. Return.

</div>

Expand All @@ -166,33 +176,19 @@ The <dfn method for="StorageBucketManager">delete(|name|)</dfn> method steps are

1. Run the following steps [=in parallel=]:

1. Let |r| be the result of running [=delete a bucket=] with |storageKey| and |name|
1. If the result of [=validate a bucket name=] with |name| is failure, then [=/reject=] |p| with an {{InvalidCharacterError}} and abort these steps.

1. If |r| is failure, then [=reject=] |p| with a {{TypeError}} and abort these steps.

1. [=/Resolve=] |p| with |r|.

1. Return |p|.

</div>
1. Let |bucket| be the [=/storage bucket=] named |name| in |storageKey| if one exists. Otherwise return.

<div algorithm>
1. Remove |bucket|.

To <dfn>delete a bucket</dfn> for a |storageKey| given a bucket |name|, run the following steps:
1. [=/Resolve=] |p|.

1. Let |bucket| be the [=/storage bucket=] named |name| in |storageKey| if one exists. Otherwise return.

1. Let |bottle map| be the result of running [=obtain a local storage bottle map=] for |bucket|.

1. Remove each |bottle| in |bottle map|. If this fails for any reason, return an appropriate error.

1. Remove |bucket|. If this fails for any reason, return an appropriate error.

1. Return.
1. Return |p|.

</div>

Issue: [[Storage]] needs to define bucket removal/clearing. The bucket needs to be internally marked as
Issue: [[Storage]] needs to define bucket removal. The bucket needs to be internally marked as
removed and subsequent attempts to access it (through associated storage endpoints) should fail.

<h3 id="storage-bucket-keys">Enumerating buckets</h3>
Expand All @@ -213,6 +209,8 @@ The <dfn method for="StorageBucketManager">keys()</dfn> method steps are:

1. Let |shelf| be the result of running [=obtain a local storage shelf=].

1. If |shelf| is failure, [=reject=] p with an {{UnknownError}} and abort these steps.

1. Let |keys| be a new [=/list=].

1. For each |key| in |shelf|'s [=bucket map=], run the following steps:
Expand Down Expand Up @@ -269,17 +267,17 @@ The <dfn method for="StorageBucket">persist()</dfn> method steps are:

1. Let |bucket| be [=this=]'s [=/storage bucket=].

1. If |bucket| has been cleared, [=reject=] |p| with an appropriate error.
1. If |bucket| has been removed, [=reject=] |p| with {{InvalidStateError}}.

1. Otherwise,

1. Let |environment| be [=/this=]'s [=/relevant settings object=].

1. Let |permission| be the result of [=getting the current permission state=] with `"persistent-storage"` and |environment|.

1. If |permission| is "{{PermissionState/granted}}", then set |bucket|'s [=bucket mode=] to `"persistent"` and [=resolve=] |p| with true.
1. If |permission| is "{{PermissionState/granted}}", then set |bucket|'s [=bucket mode=] to `"persistent"` and [=/resolve=] |p| with true.

1. Otherwise, [=resolve=] |p| with false.
1. Otherwise, [=/resolve=] |p| with false.

1. Return |p|.

Expand All @@ -295,13 +293,13 @@ The <dfn method for="StorageBucket">persisted()</dfn> method steps are:

1. Let |bucket| be [=this=]'s [=/storage bucket=].

1. If |bucket| has been cleared, [=reject=] |p| with an appropriate error.
1. If |bucket| has been removed, [=reject=] |p| with an {{InvalidStateError}}.

1. Otherwise,

1. If |bucket|'s [=bucket mode=] is `"persistent"` and [=resolve=] |p| with true.
1. If |bucket|'s [=bucket mode=] is `"persistent"` and [=/resolve=] |p| with true.

1. Otherwise, [=resolve=] |p| with false.
1. Otherwise, [=/resolve=] |p| with false.

1. Return |p|.

Expand All @@ -326,13 +324,13 @@ The <dfn method for="StorageBucket">estimate()</dfn> method steps are:

1. Let |shelf| be the result of running [=obtain a local storage shelf=] with |environment|.

1. If |shelf| is failure, [=reject=] p with a {{TypeError}}.
1. If |shelf| is failure, [=reject=] p with an {{UnknownError}}.

1. Otherwise, run the following steps [=in parallel=]:

1. Let |bucket| be [=this=]'s [=/storage bucket=].

1. If |bucket| has been cleared, [=reject=] |p| with an appropriate error.
1. If |bucket| has been removed, [=reject=] |p| with an {{InvalidStateError}}.

1. Otherwise,

Expand All @@ -344,7 +342,7 @@ The <dfn method for="StorageBucket">estimate()</dfn> method steps are:

1. Let |dictionary| be a new {{StorageEstimate}} dictionary whose {{StorageEstimate/usage}} member is |usage| and {{StorageEstimate/quota}} member is |quota|.

1. [=Resolve=] |p| with |dictionary|.
1. [=/Resolve=] |p| with |dictionary|.

1. Return |p|.

Expand Down Expand Up @@ -374,7 +372,7 @@ The <dfn method for="StorageBucket">durability()</dfn> method steps are:

1. Let |bucket| be [=this=]'s [=/storage bucket=].

1. If |bucket| has been cleared, [=reject=] |p| with an appropriate error.
1. If |bucket| has been removed, [=reject=] |p| with an {{InvalidStateError}}.

1. Otherwise, [=/resolve=] |p| with |bucket|'s [=bucket durability=].

Expand Down Expand Up @@ -416,7 +414,7 @@ The <dfn method for="StorageBucket">setExpires(|expires|)</dfn> method steps are

1. Let |bucket| be [=this=]'s [=/storage bucket=].

1. If |bucket| has been cleared, [=reject=] |p| with an appropriate error.
1. If |bucket| has been removed, [=reject=] |p| with an {{InvalidStateError}}.

1. Otherwise, set |bucket|'s [=bucket expiration=] to |expires| and [=/resolve=] |p|.

Expand All @@ -434,7 +432,7 @@ The <dfn method for="StorageBucket">expires()</dfn> method steps are:

1. Let |bucket| be [=this=]'s [=/storage bucket=].

1. If |bucket| has been cleared, [=reject=] |p| with an appropriate error.
1. If |bucket| has been removed, [=reject=] |p| with an {{InvalidStateError}}.

1. Otherwise, [=/resolve=] |p| with |bucket|'s [=bucket expiration=].

Expand Down

0 comments on commit f93e40a

Please sign in to comment.