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.
A
user
agent
has
an
associated
storage
bucket
manager
which
is
the
result
of
starting
a
new
parallel
queue
.
[Exposed =(Window ,Worker ),SecureContext ]interface {StorageBucketManager Promise <StorageBucket >open (DOMString ,name optional StorageBucketOptions = {});options Promise <sequence <DOMString >>keys ();Promise <undefined >delete (DOMString ); };name dictionary {StorageBucketOptions boolean =persisted false ;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 p be a new promise .
-
Enqueue the following steps to storage bucket manager :
-
Let r be the result of running open a bucket with shelf , name , and options .
-
If r is failure, then queue a storage task to reject p with a
TypeError. -
Otherwise, queue a storage task to resolve p with r .
-
-
Return p .
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:-
Set expires to 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:-
Set quota to options ["
quota"]. -
If quota is less than or equal to zero, then return failure.
-
-
Let persisted be false.
-
If options ["
persisted"] 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:
-
Set bucket to a new storage bucket with name name .
-
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 .
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 .
-
If the result of validate a bucket name with name is failure, then reject p with an
InvalidCharacterError. -
Otherwise, enqueue the following steps to storage bucket manager :
-
Run remove a bucket with shelf and name .
-
Queue a storage task to 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 .
-
Enqueue the following steps to storage bucket manager :
-
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 storage 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 <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, then queue a storage task to reject p with an
InvalidStateError. -
Let persisted be true if bucket ’s bucket mode is
"persistent". -
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 set persisted to true. -
Otherwise, set persisted to false.
-
-
Queue a storage task to resolve p with persisted .
-
-
Return p .
The
persisted()
method
steps
are:
-
Let p be a new promise .
-
Let bucket be this 's storage bucket .
-
Otherwise, run these steps in parallel :
-
If bucket ’s removed flag is true, then queue a storage task to reject p with an
InvalidStateError. -
Let persistent be true if bucket ’s bucket mode is
"persistent", otherwise false. -
Queue a storage task to resolve p with persistent .
-
-
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 bottle s.
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
StorageEstimatedictionary whoseusagemember is usage andquotamember is quota . -
Queue a storage task to resolve p with dictionary .
-
-
Return p .
2.3. 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 .
-
Otherwise, run these steps in parallel :
-
If bucket ’s removed flag is true, then queue a storage task to reject p with an
InvalidStateError. -
Otherwise, set bucket ’s expiration time to expires milliseconds after the Unix epoch .
-
Queue a storage task to resolve p .
-
-
Return p .
The
expires()
method
steps
are:
-
Let p be a new promise .
-
Let bucket be this 's storage bucket .
-
Otherwise, run these steps in parallel :
-
If bucket ’s removed flag is true, then queue a storage task to reject p with an
InvalidStateError. -
Otherwise, let expiration be bucket ’s expiration time .
-
Queue a storage task to resolve p with expiration .
-
-
Return p .
2.4. Using storage endpoints
Storage endpoints, i.e. storage bottles, can be accessed as described below.
2.4.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
indexedDBis 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
IDBFactoryobject. -
Set the storage bottle map for indexedDB to bottle map .
-
2.4.2. Using CacheStorage
A
StorageBucket
has
a
CacheStorage
object,
initially
null.
The
caches
getter
steps
are:
-
If this 's
cachesis 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
CacheStorageobject. -
Set the relevant name to cache map for cacheStorage to bottle map .
-
2.4.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
getDirectorywith map .
2.5. 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
TypeErrorand 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 .
-