Skip to content

Commit

Permalink
Refactor to support getAllEntries
Browse files Browse the repository at this point in the history
linkfy appending

IDL this and other rebasing
  • Loading branch information
inexorabletash committed Nov 26, 2019
1 parent 95d8712 commit 2887d8c
Showing 1 changed file with 175 additions and 73 deletions.
248 changes: 175 additions & 73 deletions index.bs
Original file line number Diff line number Diff line change
Expand Up @@ -2754,6 +2754,8 @@ interface IDBObjectStore {
optional [EnforceRange] unsigned long count);
[NewObject] IDBRequest getAllKeys(optional any query,
optional [EnforceRange] unsigned long count);
[NewObject] IDBRequest getAllEntries(optional any query,
optional [EnforceRange] unsigned long count);
[NewObject] IDBRequest count(optional any query);

[NewObject] IDBRequest openCursor(optional any query,
Expand Down Expand Up @@ -3134,6 +3136,17 @@ must run these steps:
If successful, |request|'s {{IDBRequest/result}} will
be an [=Array=] of the [=/keys=].

: |request| = |store| .
{{IDBObjectStore/getAllEntries()|getAllEntries}}(<var>query</var> [,
|count|])
::
Retrieves the [=/keys=] and [=/values=] of [=object-store/records=] matching the
given [=/key=] or [=key range=] in |query| (up to |count| if given).

If successful, |request|'s {{IDBRequest/result}} will
be an [=Array=], with each member being an [=Array=] with a [=/key=]
[=/value=] pair.

: |request| = |store| .
{{IDBObjectStore/count()|count}}(|query|)
::
Expand Down Expand Up @@ -3240,14 +3253,14 @@ method, when invoked, must run these steps:
1. Return the result (an {{IDBRequest}}) of running
[=asynchronously execute a request=]
with **this** as |source| and
[=retrieve multiple values from an object store=]
[=retrieve multiple items from an object store=]
as |operation|, using the [=current Realm=] as |targetRealm|,
|store|, |range|, and |count| if given.
|store|, |range|, "value" as |kind|, and |count| if given.

</div>

The |query| parameter may be a [=/key=] or [=key range=] (an {{IDBKeyRange}})
identifying the [=object-store/records=] to be retrieved. If null or not given,
identifying the [=object-store/record=] values to be retrieved. If null or not given,
an [=unbounded key range=] is used. If |count| is specified and
there are more than |count| records in range, only the first |count|
will be retrieved.
Expand Down Expand Up @@ -3275,17 +3288,59 @@ method, when invoked, must run these steps:
1. Return the result (an {{IDBRequest}}) of running
[=asynchronously execute a request=]
with **this** as |source| and
[=retrieve multiple keys from an object store=] as
|operation|, using |store|, |range|, and |count| if given.
[=retrieve multiple items from an object store=] as
|operation|, using the [=current Realm=] as |targetRealm|,
|store|, |range|, "key" as |kind|, and |count| if given.

</div>

The |query| parameter may be a [=/key=] or [=key range=] (an {{IDBKeyRange}})
identifying the [=object-store/record=] keys to be retrieved. If null or not
given, an [=unbounded key range=] is used. If |count| is specified
and there are more than |count| keys in range, only the first |count|
will be retrieved.


<div class=algorithm>

The <dfn method for=IDBObjectStore>getAllEntries(|query|, |count|)</dfn>
method, when invoked, must run these steps:

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

1. Let |store| be **this**'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. Let |range| be the result of running the steps to
[=convert a value to a key range=] with |query|.
Rethrow any exceptions.

1. Return the result (an {{IDBRequest}}) of running
[=asynchronously execute a request=]
with **this** as |source| and
[=retrieve multiple items from an object store=] as
|operation|, using the [=current Realm=] as |targetRealm|,
|store|, |range|, "key+value", and |count| if given.

</div>

The |query| parameter may be a [=/key=] or [=key range=] (an {{IDBKeyRange}})
identifying the [=object-store/records=] keys to be retrieved. If null or not
identifying the [=object-store/records=] to be retrieved. If null or not
given, an [=unbounded key range=] is used. If |count| is specified
and there are more than |count| keys in range, only the first |count|
will be retrieved.

<aside class=advisement>
&#x1F6A7;
The {{IDBObjectStore/getAllEntries()}} method is new in this edition.
&#x1F6A7;
</aside>


<div class=algorithm>

Expand Down Expand Up @@ -3666,6 +3721,8 @@ interface IDBIndex {
optional [EnforceRange] unsigned long count);
[NewObject] IDBRequest getAllKeys(optional any query,
optional [EnforceRange] unsigned long count);
[NewObject] IDBRequest getAllEntries(optional any query,
optional [EnforceRange] unsigned long count);
[NewObject] IDBRequest count(optional any query);

[NewObject] IDBRequest openCursor(optional any query,
Expand Down Expand Up @@ -3813,6 +3870,18 @@ return **this**'s [=index-handle/index=]'s [=unique flag=].
If successful, |request|'s {{IDBRequest/result}} will be an
[=Array=] of the [=/keys=].


: |request| = |index| .
{{IDBIndex/getAllEntries()|getAllEntries}}(<var>query</var> [,
|count|])
::
Retrieves the [=/keys=] and [=/values=] of [=object-store/records=] matching the given
[=/key=] or [=key range=] in |query| (up to |count| if given).

If successful, |request|'s {{IDBRequest/result}} will be an
[=Array=], with each member being an [=Array=] with a [=/key=]
[=/value=] pair.

: |request| = |index| .
{{IDBIndex/count()|count}}(|query|)
::
Expand Down Expand Up @@ -3923,14 +3992,14 @@ when invoked, must run these steps:
1. Return the result (an {{IDBRequest}}) of running
[=asynchronously execute a request=]
with **this** as |source| and
[=retrieve multiple referenced values from an index=] as
[=retrieve multiple items from an index=] as
|operation|, using the [=current Realm=] as |targetRealm|,
|index|, |range|, and |count| if given.
|index|, |range|, "value" as |kind|, and |count| if given.

</div>

The |query| parameter may be a [=/key=] or [=key range=] (an {{IDBKeyRange}})
identifying the [=object-store/records=] to be retrieved. If null or not given,
identifying the [=object-store/record=] values to be retrieved. If null or not given,
an [=unbounded key range=] is used. If |count| is specified and
there are more than |count| records in range, only the first |count|
will be retrieved.
Expand Down Expand Up @@ -3958,18 +4027,60 @@ method, when invoked, must run these steps:
1. Return the result (an {{IDBRequest}}) of running
[=asynchronously execute a request=]
with **this** as |source| and
[=retrieve multiple values from an index=] as |operation|, using
|index|, |range|, and |count| if given.
[=retrieve multiple items from an index=] as |operation|, using
the [=current Realm=] as |targetRealm|,
|index|, |range|, "key" as |kind|, and |count| if given.

</div>

The |query| parameter may be a [=/key=] or [=key range=] (an {{IDBKeyRange}})
identifying the [=object-store/records=] keys to be retrieved. If null or not
identifying the [=object-store/record=] keys to be retrieved. If null or not
given, an [=unbounded key range=] is used. If |count| is specified
and there are more than |count| keys in range, only the first |count|
will be retrieved.


<div class=algorithm>

The <dfn method for=IDBIndex>getAllEntries(|query|, |count|)</dfn>
method, when invoked, must run these steps:

1. Let |transaction| be **this**'s [=index-handle/transaction=].

1. Let |index| be **this**'s [=index-handle/index=].

1. If |index| or |index|'s [=/object store=] has
been deleted, [=throw=] an "{{InvalidStateError}}" {{DOMException}}.

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

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

1. Return the result (an {{IDBRequest}}) of running
[=asynchronously execute a request=]
with **this** as |source| and
[=retrieve multiple items from an index=] as |operation|, using
the [=current Realm=] as |targetRealm|,
|index|, |range|, "key+value" as |kind|, and |count| if given.

</div>

The |query| parameter may be a [=/key=] or [=key range=] (an {{IDBKeyRange}})
identifying the [=object-store/records=] to be retrieved. If null or not
given, an [=unbounded key range=] is used. If |count| is specified
and there are more than |count| keys in range, only the first |count|
will be retrieved.

<aside class=advisement>
&#x1F6A7;
The {{IDBIndex/getAllEntries()}} method is new in this edition.
&#x1F6A7;
</aside>


<div class=algorithm>

The <dfn method for=IDBIndex>count(|query|)</dfn> method, when
Expand Down Expand Up @@ -5785,30 +5896,6 @@ To <dfn>retrieve a value from an object store</dfn> with
</div>


<div class=algorithm>

To <dfn>retrieve multiple values from an object
store</dfn> with |targetRealm|, |store|, |range| and optional |count|, run these steps:

1. If |count| is not given or is 0 (zero), let |count| be infinity.

1. Let |records| be a [=/list=] containing the first |count| [=object-store/records=]
in |store|'s [=object-store/list of records=] whose [=/key=] is
[=in=] |range|.

1. Let |list| be an empty list.

1. [=list/For each=] |record| of |records|:

1. Let |serialized| be |record|'s [=/value=].
1. Let |entry| be [=!=] <a abstract-op>StructuredDeserialize</a>(|serialized|, |targetRealm|).
1. Append |entry| to |list|.

1. Return |list| converted to a [=sequence&lt;any&gt;=].

</div>


<div class=algorithm>

To <dfn>retrieve a key from an object store</dfn>
Expand All @@ -5828,8 +5915,8 @@ with |store| and |range|, run these steps:

<div class=algorithm>

To <dfn>retrieve multiple keys from an object store</dfn>
with |store|, |range| and optional |count|, run these steps:
To <dfn>retrieve multiple items from an object store</dfn>
with |targetRealm|, |store|, |range|, |kind| and optional |count|, run these steps:

1. If |count| is not given or is 0 (zero), let |count| be infinity.

Expand All @@ -5839,11 +5926,29 @@ with |store|, |range| and optional |count|, run these steps:

1. Let |list| be an empty [=/list=].

1. [=list/For each=] |record| of |records|:
1. [=list/For each=] |record| of |records|, switching on |kind|:

1. Let |entry| be the result of running [=convert a
key to a value=] with |record|'s key.
1. Append |entry| to |list|.
<dl class=switch>
: "key"
::
1. Let |key| be the result of running [=convert a key to a value=] with |record|'s key.
1. [=list/Append=] |key| to |list|.

: "value"
::
1. Let |serialized| be |record|'s [=/value=].
1. Let |value| be [=!=] <a abstract-op>StructuredDeserialize</a>(|serialized|, |targetRealm|).
1. [=list/Append=] |value| to |list|.

: "key+value"
::
1. Let |key| be the result of running [=convert a key to a value=] with |record|'s key.
1. Let |serialized| be |record|'s [=/value=].
1. Let |value| be [=!=] <a abstract-op>StructuredDeserialize</a>(|serialized|, |targetRealm|).
1. Let |pair| be a [=/list=] containing |key| and |value|.
1. [=list/Append=] |pair| convered to a [=sequence&lt;any&gt;=] to |list|.

</dl>

1. Return |list| converted to a [=sequence&lt;any&gt;=].

Expand Down Expand Up @@ -5871,30 +5976,8 @@ with |targetRealm|, |index| and |range|, run these steps:
</div>


<div class=algorithm>

To <dfn>retrieve multiple referenced values from an
index</dfn> with |targetRealm|, |index|, |range| and optional |count|, run these steps:

1. If |count| is not given or is 0 (zero), let |count| be infinity.

1. Let |records| be a list containing the first |count| [=object-store/records=]
in |index|'s [=index/list of records=] whose [=index/key=] is [=in=] |range|.

1. Let |list| be an empty [=/list=].

1. [=list/For each=] |record| of |records|:

1. Let |serialized| be |record|'s [=referenced value=].
1. Let |entry| be [=!=] <a abstract-op>StructuredDeserialize</a>(|serialized|, |targetRealm|).
1. Append |entry| to |list|.

1. Return |list| converted to a [=sequence&lt;any&gt;=].

</div>

<aside class=note>
The [=index/values=] of an [=index/record=] in an index are the keys of
The [=index/values=] of [=index/records=] in an index are the keys of
[=object-store/records=] in the [=index/referenced=] object store.
</aside>

Expand All @@ -5916,21 +5999,39 @@ To <dfn>retrieve a value from an index</dfn> with

<div class=algorithm>

To <dfn>retrieve multiple values from an index</dfn> with
|index|, |range| and optional |count|, run these steps:
To <dfn>retrieve multiple items from an index</dfn> with
|targetRealm|, |index|, |range|, |kind| and optional |count|, run these steps:

1. If |count| is not given or is 0 (zero), let |count| be infinity.

1. Let |records| be a list containing the first |count| [=index/records=] in
|index|'s [=index/list of records=] whose [=index/key=] is [=in=] |range|.
1. Let |records| be a list containing the first |count| [=object-store/records=]
in |index|'s [=index/list of records=] whose [=index/key=] is [=in=] |range|.

1. Let |list| be an empty [=/list=].

1. [=list/For each=] |record| of |records|:
1. [=list/For each=] |record| of |records|, switching on |kind|:

1. Let |entry| be the result of running [=convert a
key to a value=] with |record|'s value.
1. Append |entry| to |list|.
<dl class=switch>
: "key"
::
1. Let |key| be the result of running [=convert a key to a value=] with |record|'s value.
1. [=list/Append=] |key| to |list|.

: "value"
::
1. Let |serialized| be |record|'s [=referenced value=].
1. Let |value| be [=!=] <a abstract-op>StructuredDeserialize</a>(|serialized|, |targetRealm|).
1. [=list/Append=] |value| to |list|.

: "key+value"
::
1. Let |key| be the result of running [=convert a key to a value=] with |record|'s value.
1. Let |serialized| be |record|'s [=referenced value=].
1. Let |value| be [=!=] <a abstract-op>StructuredDeserialize</a>(|serialized|, |targetRealm|).
1. Let |pair| be a [=/list=] containing |key| and |value|.
1. [=list/Append=] |pair| convered to a [=sequence&lt;any&gt;=] to |list|.

</dl>

1. Return |list| converted to a [=sequence&lt;any&gt;=].

Expand Down Expand Up @@ -6824,6 +6925,7 @@ For the revision history of the second edition, see [that document's Revision Hi
* Remove escaping {{IDBKeyRange/includes()}} method. ([Issue #294](https://github.com/w3c/IndexedDB/issues/294))
* Restrict array keys to [=/Array exotic objects=] (i.e. disallow proxies). ([Issue #309](https://github.com/w3c/IndexedDB/issues/309])
* Transactions are now temporarily made inactive during clone operations.
* Added object store {{IDBObjectStore/getAllEntries()}} and index {{IDBObjectStore/getAllEntries()}} methods. ([Issue #206](https://github.com/w3c/IndexedDB/issues/206))

<!-- ============================================================ -->
# Acknowledgements # {#acknowledgements}
Expand Down

0 comments on commit 2887d8c

Please sign in to comment.