1. The StorageBucketManager
interface
[SecureContext ]interface mixin { [
NavigatorStorageBuckets SameObject ]readonly attribute StorageBucketManager storageBuckets ; };Navigator includes NavigatorStorageBuckets ;WorkerNavigator includes NavigatorStorageBuckets ;
Each environment settings object has an associated StorageBucketManager
object.
The storageBuckets
getter steps are to return this's relevant settings object's StorageBucketManager
object.
[Exposed =(Window ,Worker ),SecureContext ]interface {
StorageBucketManager Promise <StorageBucket >open (DOMString ,
name optional StorageBucketOptions = {});
options Promise <sequence <DOMString >>keys ();Promise <undefined >delete (DOMString ); };
name enum {
StorageBucketDurability ,
"strict" };
"relaxed" dictionary {
StorageBucketOptions boolean ?=
persisted null ;StorageBucketDurability ?=
durability null ;unsigned long long ?=
quota null ;DOMHighResTimeStamp ?=
expires null ; };
1.1. Creating a bucket
The open(name, options)
method steps are:
-
Let environment be this's relevant settings object.
-
Let shelf be the result of running obtain a local storage shelf given environment.
-
If shelf is failure, then return a promise rejected with a
TypeError
. -
If the result of validate a bucket name with name is failure, then return a promise rejected with a
TypeError
. -
Let r be the result of running open a bucket with shelf, name, and options.
-
If r is failure, then return a promise rejected with a
TypeError
. -
Return a promise resolved with with r.
To open a bucket for a shelf given a bucket name and optional options, run the following steps:
-
Let expires be undefined.
-
If options["
expires
"] exists, then:-
Let expires be options["
expires
"]. -
If expires milliseconds after the Unix epoch is before the relevant settings object's current wall time, then return failure.
-
-
Let quota be undefined.
-
If options["
quota
"] exists, then:-
Let quota be options["
quota
"]. -
If quota is less than or equal to zero, then return failure.
-
-
Let persisted be false.
-
If options["
persisted
"] exists and is true, then:-
Let permission be the result of requesting permission to use
"persistent-storage"
. -
If permission is "
granted
", then set persisted to true.
-
-
Let bucket be the result of running get or expire a bucket with shelf and name.
-
If bucket is null, then:
-
Let bucket be a new storage bucket with name name.
-
Set bucket’s durability value to options["
durability
"] if it exists. -
Set bucket’s quota value to quota.
-
Set shelf’s bucket map[name] to bucket.
-
-
If persisted is true, set bucket’s bucket mode to
"persistent"
. -
Set bucket’s expiration to expires milliseconds after the Unix epoch.
-
Let storageBucket be a new
StorageBucket
. -
Set storageBucket’s storage bucket to bucket.
-
Return storageBucket.
To validate a bucket name given string name, run the following steps:
-
If name contains any code point that is not ASCII lower alpha, ASCII digit, U+005F (_), or U+002D(-), then return failure.
-
If name code point length is 0 or exceeds 64, then return failure.
-
If name begins with U+005F (_) or U+002D(-), then return failure.
-
Return.
To get or expire a bucket on a shelf given string name, run the following steps:
-
Let bucket be shelf’s bucket map[name] if exists. Otherwise return null.
-
If bucket’s expiration time is non-null and before the relevant settings object's current wall time, then:
-
Set bucket’s removed to true.
-
Return null.
-
-
Return bucket.
When not null or undefined, durability
is a hint to the user agent
specifying the desired durability
. The user agent MAY
create a new StorageBucket
with this durability value. The user agent
MUST NOT modify the durability value of an existing bucket.
1.2. Deleting a bucket
The delete(name)
method steps are:
-
Let environment be this's relevant settings object.
-
Let shelf be the result of running obtain a local storage shelf given environment.
-
If shelf is failure, then return a promise rejected with a
TypeError
. -
Let p be a new promise.
-
Run the following steps in parallel:
-
If the result of validate a bucket name with name is failure, then reject p with an
InvalidCharacterError
and abort these steps. -
Let r be the result of running remove a bucket with shelf and name.
-
Otherwise, resolve p.
-
-
Return p.
To remove a bucket on a shelf given a bucket name, run the following steps:
-
Let bucket be shelf’s bucket map[name] if exists. Otherwise return.
-
Remove key name in shelf’s bucket map.
-
Set bucket’s removed to true.
-
Return.
[IndexedDB-3] needs to define how deletion occurs when data is evicted by quota.
[FS] needs to define how deletion occurs for Origin Private File System when data is evicted by quota.
[Service-Workers] needs to define how deletion occurs for CacheStorage and Service Workers when data is evicted by quota.
1.3. Enumerating buckets
The keys()
method steps are:
-
Let shelf be the result of running obtain a local storage shelf.
-
If shelf is failure, then return a promise rejected with a
TypeError
. -
Let p be a new promise.
-
Let keys be a new list.
-
For each key in shelf’s bucket map, run the following steps:
-
Let bucket be the result of running get or expire a bucket with shelf and key.
-
If bucket is non-null, append key to keys.
-
-
Queue a task to resolve p with keys.
-
Return p.
2. The StorageBucket
interface
[Exposed =(Window ,Worker ),SecureContext ]interface {
StorageBucket readonly attribute DOMString name ; [Exposed =Window ]Promise <boolean >persist ();Promise <boolean >persisted ();Promise <StorageEstimate >estimate ();Promise <StorageBucketDurability >durability ();Promise <undefined >setExpires (DOMHighResTimeStamp );
expires Promise <DOMHighResTimeStamp ?>expires (); [SameObject ]readonly attribute IDBFactory indexedDB ; [SameObject ]readonly attribute CacheStorage caches ;Promise <FileSystemDirectoryHandle >getDirectory (); };
A StorageBucket
has an associated storage bucket.
A storage bucket has an associated removed flag, which is a boolean, initially false. Set as true when a storage bucket is deleted.
A StorageBucket
has a DOMString
object name
which is the key in the bucket map that maps to the storage bucket.
2.1. Persistence
Merge with Storage § 4.5 Storage buckets which already defines bucket mode.
The persist()
method steps are:
-
Let bucket be this's storage bucket.
-
Let environment be this's relevant settings object.
-
Let p be a new promise.
-
Run the following steps in parallel:
-
If bucket’s removed flag is true, reject p with
InvalidStateError
. -
If bucket’s bucket mode is
"persistent"
, resolve p with true. -
Otherwise,
-
Let permission be the result of getting the current permission state with
"persistent-storage"
and environment. -
If permission is "
granted
", then set bucket’s bucket mode to"persistent"
and queue a task to resolve p with true. -
Otherwise, resolve p with false.
-
-
-
Return p.
The persisted()
method steps are:
-
Let p be a new promise.
-
Let bucket be this's storage bucket.
-
If bucket’s removed flag is true, then queue a task to reject p with an
InvalidStateError
. -
Otherwise,
-
If bucket’s bucket mode is
"persistent"
, then queue a task to resolve p with true. -
Otherwise, queue a task to resolve p with false.
-
-
Return p.
2.2. Quota
A storage bucket has a quota value, a number-or-null, initially null. Specifies the upper limit of usage in bytes which can be used by the bucket. The user agent MAY further limit the realized storage space.
The storage usage of a storage bucket is an implementation-defined rough estimate of the number of bytes used by all of its storage bottles.
The estimate()
method steps are:
-
Let environment be this's relevant settings object.
-
Let shelf be the result of running obtain a local storage shelf with environment.
-
If shelf is failure, then return a promise rejected with a
TypeError
. -
Let bucket be this's storage bucket.
-
If bucket’s removed flag is true, then return a promise rejected with an
InvalidStateError
. -
Let p be a new promise.
-
Otherwise, run the following steps in parallel:
-
Let quota be storage quota for shelf.
-
Set quota to bucket’s quota value if it is non-null.
-
Let usage be storage usage for bucket.
-
Let dictionary be a new
StorageEstimate
dictionary whoseusage
member is usage andquota
member is quota. -
Resolve p with dictionary.
-
-
Return p.
2.3. Durability
A storage bucket has a durability value, a StorageBucketDurability
.
The user agent MAY initialize this value to "strict
" or
"relaxed
". The user agent SHOULD ignore the durability value for operations that otherwise specify durability behavior.
The durability()
method steps are:
-
Let p be a new promise.
-
Let bucket be this's storage bucket.
-
If bucket’s removed flag is true, queue a task to reject p with an
InvalidStateError
. -
Otherwise, queue a task to resolve p with bucket’s durability value.
-
Return p.
2.4. Expiration
A storage bucket has an expiration time, which is either null or a moment on the wall clock, initially null. Specifies the upper limit of a bucket lifetime.
The get or expire a bucket algorithm removes expired buckets when keys()
or open()
is called.
User agents MAY clear buckets whose bucket mode is "best-effort"
before their expiration time when faced with storage pressure.
User agents MAY remove any buckets before open()
or keys()
is called when the expiration is reached regardless of the bucket mode
The setExpires(expires)
method steps are:
-
Let p be a new promise.
-
Let bucket be this's storage bucket.
-
If bucket’s removed flag is true, queue a task to reject p with an
InvalidStateError
. -
Otherwise, set bucket’s expiration time to expires milliseconds after the Unix epoch and queue a task to resolve p.
-
Return p.
The expires()
method steps are:
-
Let p be a new promise.
-
Let bucket be this's storage bucket.
-
If bucket’s removed flag is true, queue a task to reject p with an
InvalidStateError
. -
Otherwise, queue a task to resolve p with bucket’s expiration time.
-
Return p.
2.5. Using storage endpoints
Storage endpoints, i.e. storage bottles, can be accessed as described below.
2.5.1. Using Indexed Database
IDBFactory
methods need to take a storage bottle map rather than a storageKey.
A StorageBucket
has an IDBFactory
object, initially null. The indexedDB
getter steps are:
-
If this's
indexedDB
is null, run the following steps:-
Let bucket be this's storage bucket.
-
Let bottle map be the result of obtain a local storage bottle map with bucket and
"indexedDB"
. -
Let indexedDB be an
IDBFactory
object. -
Set the storage bottle map for indexedDB to bottle map.
-
The user agent MUST consider the durability value when evaluating the durability hint durability of an IDBTransaction
transaction. To calculate the effective durability hint for transaction with associated bucket:
-
If durability is not "
default
", then return durability. -
If bucket’s durability value is "
strict
", then return "strict
". -
Return "
relaxed
".
2.5.2. Using CacheStorage
A StorageBucket
has a CacheStorage
object, initially null. The caches
getter steps are:
-
If this's
caches
is null, run the following steps:-
Let bucket be this's storage bucket.
-
Let bottle map be the result of obtain a local storage bottle map with bucket and
"cacheStorage"
. -
Let cacheStorage be a
CacheStorage
object. -
Set the relevant name to cache map for cacheStorage to bottle map.
-
2.5.3. Using an Origin Private File System
[Storage] needs to define helpers to retrieve the bottle map for a given (non-default) bucket.
[FS] needs to define a helper to retrieve an OPFS given a bottle map.
The getDirectory()
steps are:
-
Let map be the result of obtain a local storage bottle map with this's storage bucket and
"fileSystem"
. -
Return the result of
getDirectory
with map.
2.6. Clear Site Data integration
Update Clear Site Data § 3.1 The Clear-Site-Data HTTP Response Header Field.
- "
storage:bucket-name
" -
If the type string starts with "
storage:
" then the remaining characters after the:
will be taken to refer to a specific storage bucket in the origin of a particular response’s URL.
add the steps below to the algorithm in Clear Site Data § 4.1 Parsing.
To parse a Clear-Site-Data header with buckets, execute the following steps:
-
For each type in header, execute the following steps:
-
If type does not start with
"storage:"
, abort these steps. -
Let bucket name be the code unit substring from 8 to end of type.
-
If the result of validate a bucket name with bucket name is failure, then abort these steps.
-
Append a tuple consisting of (
"storage-bucket"
, bucket name) to types
-
add the steps below to the algorithm in Clear Site Data § 4.2 Clear data for response.
To clear data with buckets given a bucket name, execute the following steps:
-
Let environment be this's relevant settings object.
-
Let shelf be the result of running obtain a local storage shelf given environment.
-
If shelf is failure, then throw a
TypeError
and abort these steps. -
For each type in types, execute the following steps:
-
If type is not a tuple or type[0] is not
"storage-bucket"
, abort these steps. -
Let bucket be shelf’s bucket map[bucket name] if one exists. Otherwise abort these steps
-
Remove bucket.
-