Skip to content

Commit

Permalink
Initial algorithms for putAll
Browse files Browse the repository at this point in the history
  • Loading branch information
inexorabletash committed Jul 23, 2020
1 parent 5f5597c commit be18ab3
Showing 1 changed file with 114 additions and 3 deletions.
117 changes: 114 additions & 3 deletions index.bs
Original file line number Diff line number Diff line change
Expand Up @@ -2911,13 +2911,13 @@ and false otherwise.
</div>


The <dfn method for=IDBObjectStore>put(|value|, |key|)</dfn> method steps are to return the result of running [=add or put=] with [=/this=], |value|, |key| and the |no-overwrite flag| false.
The <dfn method for=IDBObjectStore>put(|value|, |key|)</dfn> method steps are to return the result of running [=add or put a single record=] with [=/this=], |value|, |key| and the |no-overwrite flag| false.

The <dfn method for=IDBObjectStore>add(|value|, |key|)</dfn> method steps are to return the result of running [=add or put=] with [=/this=], |value|, |key| and the |no-overwrite flag| true.
The <dfn method for=IDBObjectStore>add(|value|, |key|)</dfn> method steps are to return the result of running [=add or put a single record=] with [=/this=], |value|, |key| and the |no-overwrite flag| true.

<div algorithm>

To <dfn>add or put</dfn> with |handle|, |value|, |key|, and |no-overwrite flag|, run these steps:
To <dfn>add or put a single record</dfn> with |handle|, |value|, |key|, and |no-overwrite flag|, run these steps:

1. Let |transaction| be |handle|'s
[=object-store-handle/transaction=].
Expand Down Expand Up @@ -2988,6 +2988,98 @@ To <dfn>add or put</dfn> with |handle|, |value|, |key|, and |no-overwrite flag|,

1. Return the result (an {{IDBRequest}}) of running [=asynchronously execute a request=] with |handle| and |operation|.

</div>


Issue: Define `putAll()` method(s) that use [=/add or put multiple records=].

<div algorithm>

To <dfn>add or put multiple records</dfn> with |handle|, |values|, |keys|, and |no-overwrite flag|, run these steps:

1. [=/Assert=]: If |keys| is given, |values| [=list/size=] equals |keys| [=list/size=].

1. Let |transaction| be |handle|'s
[=object-store-handle/transaction=].

1. Let |store| be |handle|'s
[=object-store-handle/object store=].

1. If |store| has been deleted,
[=throw=] an "{{InvalidStateError}}" {{DOMException}}.

1. If |transaction|'s [=transaction/state=] is not [=transaction/active=],
then [=throw=] a "{{TransactionInactiveError}}" {{DOMException}}.

1. If |transaction| is a [=read-only transaction=],
[=throw=] a "{{ReadOnlyError}}" {{DOMException}}.

1. If |store| uses [=in-line keys=] and |keys| were given,
[=throw=] a "{{DataError}}" {{DOMException}}.

1. If |store| uses [=out-of-line keys=] and has no [=key
generator=] and |keys| were not given, [=throw=] a
"{{DataError}}" {{DOMException}}.

1. If |keys| were given, then:

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

1. [=list/For each=] |key| of |keys|:

1. Let |r| be the result of running [=convert a value to a key=] with |key|. Rethrow any exceptions.

1. If |r| is invalid, [=throw=] a "{{DataError}}" {{DOMException}}.

1. [=list/Append=] |r| to |rs|.

1. Let |keys| be |rs|.

1. Let |targetRealm| be a user-agent defined [=Realm=].

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

1. [=list/For each=] |value| of |values|:

1. Let |clone| be a [=clone=] of |value| in |targetRealm| during |transaction|.
Rethrow any exceptions.

<details class=note>
<summary>Why create a copy of the value?</summary>
The value is serialized when stored. Treating it as a copy
here allows other algorithms in this specification to treat it as
an ECMAScript value, but implementations can optimize this
if the difference in behavior is not observable.
</details>

1. [=list/Append=] |clone| to |clones|.

1. If |store| uses [=in-line keys=], then:

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

1. [=list/For each=] |clone| of |clones|:

1. Let |key| be undefined.

1. Let |kpk| be the result of running [=extract a key from a value using a key path=] with |clone| and |store|'s [=object-store/key path=]. Rethrow any exceptions.

1. If |kpk| is invalid, [=throw=] a "{{DataError}}" {{DOMException}}.

1. If |kpk| is not failure, let |key| be |kpk|.

1. Otherwise (|kpk| is failure):

1. If |store| does not have a [=key generator=], [=throw=] a "{{DataError}}" {{DOMException}}.

1. Otherwise, if [=check that a key could be injected into a value=] with |clone| and |store|'s [=object-store/key path=] return false, [=throw=] a "{{DataError}}" {{DOMException}}.

1. [=list/Append=] |key| to |keys|.

1. Let |operation| be an algorithm to run [=store multiple records into an object store=] with |store|, |clones|, |keys|, and |no-overwrite flag|.

1. Return the result (an {{IDBRequest}}) of running [=asynchronously execute a request=] with |handle| and |operation|.


</div>

Expand Down Expand Up @@ -5698,6 +5790,25 @@ To <dfn>store a record into an object store</dfn> with

</div>

<div algorithm>

To <dfn>store multiple records into an object store</dfn> with |store|, |values|, |keys|, and a |no-overwrite flag|, run these steps:

1. [=/Assert=]: |values| [=list/size=] equals |keys| [=list/size=].

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

1. [=list/For each=] |value| of |values| and |key| of |keys|, respectively:

1. Let |r| be the result of running the steps [=store a record into an object store=] with |store|, |value|, |key|, and |no-overwrite flag|.

1. If |r| is an error, then undo any changes made to |store| or associated [=/indexes=] by this algorithm, and return |r|.

1. [=list/Append=] |r| to |results|.

1. Return |results|.

</div>

<!-- ============================================================ -->
## Object store retrieval operations ## {#object-store-retrieval-operation}
Expand Down

0 comments on commit be18ab3

Please sign in to comment.