Skip to content

Commit

Permalink
Creating a bucket (#48)
Browse files Browse the repository at this point in the history
* Spec for creating a bucket
* fix english
* Address comments
  • Loading branch information
ayuishii authored Jan 4, 2023
1 parent 21e394e commit ec8280e
Showing 1 changed file with 80 additions and 0 deletions.
80 changes: 80 additions & 0 deletions index.bs
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,14 @@ Abstract: The Storage Buckets API provides a way for sites to organize locally s
Markup Shorthands: css no, markdown yes
</pre>

<pre class=anchors>
spec: storage; urlPrefix: https://storage.spec.whatwg.org/
type: dfn
text: mode; url: bucket-mode
text: storage bucket; url: storage-bucket
text: storage key; url: storage-key
</pre>

<h2 id="storage-bucket-manager">The {{StorageBucketManager}} interface</h2>

<xmp class="idl">
Expand Down Expand Up @@ -54,6 +62,70 @@ dictionary StorageBucketOptions {

<h3 id="storage-bucket-open">Creating a bucket</h3>

<div algorithm>

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

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

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. Let |p| be [=a new promise=].

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

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. [=/Resolve=] |p| with |r|.

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:

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

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

1. If |name| begins with U+005F (_) or U+002D(-), then return failure.

1. Let |persisted| be false.

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

1. Let |permission| be the result of [=/requesting permission to use=] "<code>persistent-storage</code>".

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 |expires| be |options|["{{StorageBucketOptions/expires}}"] if it exists; otherwise undefined.

1. Let |bucket| be the [=/storage bucket=] named |name| in |storageKey| or null otherwise.

1. If |bucket| is null, then:

1. Let |bucket| be a new [=/storage bucket=] with name |name|

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

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

1. Set |bucket|'s [=bucket quota|quota=] to |quota|.

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

1. Return |bucket|.

</div>

When not null, {{StorageBucketOptions/durability}} is a hint to the user agent
specifying the desired {{StorageBucket/durability}}. The user agent MAY
create a new {{StorageBucket}} with this [=bucket durability=]. The user agent
Expand Down Expand Up @@ -85,6 +157,14 @@ interface StorageBucket {
};
</xmp>

A {{StorageBucket}} has a <dfn>bucket quota</dfn>, a number-or-null, initially null.
Specifies the upper limit of usage which can be used by the bucket. The user agent MAY further limit
the realized storage space.

A {{StorageBucket}} has a <dfn>bucket expiration</dfn>, a timestamp-or-null, initially null.
Specifies the upper limit of a bucket lifetime. The user agent MAY clear buckets whose [=/mode=] is
"<code>best-effort</code>" before the specified timestamp when faced with storage pressure.

<h3 id="storage-bucket-durability">Durability</h3>

A {{StorageBucket}} has a <dfn>bucket durability</dfn>. This reflects whether the user agent
Expand Down

0 comments on commit ec8280e

Please sign in to comment.