-
Notifications
You must be signed in to change notification settings - Fork 2
/
index.html
1186 lines (1101 loc) · 45.4 KB
/
index.html
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
<!DOCTYPE html>
<html>
<head>
<title>Data Store API</title>
<meta charset='utf-8'>
<script src='https://www.w3.org/Tools/respec/respec-w3c-common'
async class='remove'></script>
<script class="remove">
var respecConfig = {
specStatus: "unofficial", // "ED",
shortName: "Data Store API", // needed for generated URLs
editors: [{
name: "Gene Lian",
company: "Mozilla",
companyURL: "http://www.mozilla.org",
// mailto: "[email protected]"
}],
publishDate: "", // no needed for "ED" or "unofficial"
edDraftURI: "http://airpingu.github.io/data-store-api/index.html", // needed for "ED"
previousPublishDate: "", // needed for "WD", "LC", "CR"
previousMaturity: "", // needed for "WD", "LC", "CR"
lcEnd: "", // needed for "LC"
crEnd: "", // needed for "CR"
// wg: "System Applications Working Group",
// wgURI: "http://www.w3.org/2012/sysapps/",
// wgPublicList: "public-sysapps",
// wgPatentURI: "http://www.w3.org/2004/01/pp-impl/43696/status",
otherLinks: [{
key: "Repository",
data: [{
value: "We are on GitHub.",
href: "https://github.com/airpingu/data-store-api/"
}, {
value: "File a bug.",
href: "https://github.com/airpingu/data-store-api/issues"
}, {
value: "Commit history.",
href: "https://github.com/airpingu/data-store-api/commits/gh-pages"
}]
}],
inlineCSS: true,
noIDLIn: true,
noIDLSorting: true
};
</script>
</head>
<!-----------------------------------------------------------------------------
Style guide to contributors:
============================
- this document uses ReSpec, see
http://dev.w3.org/2009/dap/ReSpec.js/documentation.html
- use 80 characters wide lines, whenever possible (except long links)
- keep sections 2 empty lines apart
- put comments in front of sections, for better readability with syntax coloring
editors
- use indentation with care: it may improve readability, but at the expense of
line lenght
- when descriptions of attributes is short, use the <dd> elements even when
the text also contains conformance statements (e.g. MUST, SHOULD, MAY).
No use repeating the same information in a separate paragraph.
------------------------------------------------------------------------------>
<body>
<!-- - - - - - - - - - - - - - - Abstract - - - - - - - - - - - - - - - - - -->
<section id="abstract">
The Data Store API allows an application to manage a data store that can
be shared with other applications and provides a mechanism to allow
multiple applications to concurrently synchronize data from the data store
into the application-local cache.
</section>
<!-- - - - - - - - - - - - - - - Status of this document - - - - - - - - - - -->
<section id="sotd">
</section>
<!-- - - - - - - - - - - - - - - Introduction - - - - - - - - - - - - - - - -->
<section class="informative">
<h2>Introduction</h2>
<p>
The Data Store API allows an application to create and maintain a data
store that can be shared with other applications. To make multiple
applications keep their local storages up-to-date with the data store,
this API supports a mechanism to allow an application to concurrently
synchronize data from the data store into the application-local storage
which can be indexed, grouped or sorted in whatever format the
application needs in order to support its UI.
</p>
<section>
<h3>Motivation</h3>
<p>
The Contacts Manager API and the Messaging API were originally
designed to support richer querying, like filtering, sorting and
grouping data. However, they both have the severe shortcoming that the
consumers are forced to live with the limitations of what querying
capabilities those APIs can have.
</p>
<p>
That's why we are constantly having to revise these APIs because it
turns out that the querying capabilities aren't matching what our
applications need, which is not a workable long-term solution. Also,
it's not even a workable short-term solution for third-party
applications since we cannot revise the APIs to support the
capabilities that every third-party application developer needs.
</p>
<p>
Therefore, we've been figuring out such a generic Data Store API to
allow applications to synchronize and save data into their own
application-local storages which can be managed in various formats
than we could think of and bake into APIs, thus supporting richer
querying capabilities that the application really needs.
</p>
<p>
Note that the Data Store API is still in charge of maintaining a
central storage to keep data which can be added, retrieved or deleted
by applications through a bunch of methods provided by the Data Store
API. This implies the application doesn't need to duplicate the whole
data in its own local storage. Instead, it can simply synchronize the
data that is actively required to construct the needed indexes for its
own querying purpose.
</p>
</section>
<section>
<h3>More than IndexedDB API</h3>
<p>
Similar to the IndexedDB API, the Data Store API provides some
database-like methods to add, retrieve and delete data records but it
doesn't expose methods for building indexes or searching data.
Instead, it provides a synchronizing mechanism for applications to
keep their local storages up-to-date and accordingly update the
local indexes needed for filtering data.
</p>
<p>
The other difference from the IndexedDB API is the Data Store API
provides a central data storage which can be concurrently accessed and
modified by multiple applications. Also, it provides a permission
model to allow different applications to have different types of
priviledges to change the data store or listen to the change of the
data store.
</p>
</section>
<section>
<h3>Examples</h3>
<p>
If an application has the privilege to modify the content of the data
store, it can use a bunch of basic methods defined in the
<a>DataStore</a> to manage the data records in the data store, which is
shown as the following example.
</p>
<pre class="example highlight">
// Retrieve a list of data stores named as 'fb-contacts'.
navigator.getDataStores('fb-contacts').then(function(stores) {
if (!stores.length) {
return;
}
// Check if the application is allowed to modify the data store.
if (stores[0].readOnly) {
return;
}
// Retrieve an object.
stores[0].get(42).then(function(obj) {
// Update the object
obj.name = 'foo';
stores[0].update(42, obj).then(function(id) {
// The object has been updated.
}, function(error) {
// The object fails to be updated.
});
});
// Delete an object.
stores[0].remove(23).then(function(success) {
if (success) {
// The object has been deleted.
} else {
// The object fails to be deleted.
}
});
// Add a new object.
stores[0].insert({ name: "bar" }).then(function(id) {
// The object has been added.
}, function(error) {
// The object fails to be added.
});
});
</pre>
<p>
An application can call the <code>sync()</code> method defined in the
<a>DataStore</a> to keep its local storage synchronized with the data
store, which creates a <a>DataStoreCursor</a> to retrieve the change
history starting from a certain revision kept in the application to the
current revision of the data store, which is shown as the following
example.
</p>
<pre class="example highlight">
var appLocalRevisionId = "revision_id_kept_by_app";
// Retrieve a list of data stores named as 'fb-contacts'.
navagiator.getDataStores('fb-contacts').then(functions(stores) {
if (!stores.length) {
return;
}
// Check if the application's local storage is out-of-date.
if (appLocalRevisionId == stores[0].revisionId) {
dump("The app's local storage is already in sync.\n");
return;
}
var cursor = stores[0].sync(appLocalRevisionId);
function cursorResolve(task) {
switch (task.operation) {
case 'done':
// All the data are in sync. Update the local revision ID.
dump("The current revision ID: " + task.revisionId + "\n");
appLocalRevisionId = task.revisionId;
return;
case 'clear':
// All the data have to be deleted in the local storage.
break;
case 'add':
// A new object has to be added in the local storage.
dump("Add ID: " + task.id + " data: " + task.data + "\n");
break;
case 'update':
// An object has to be updated in the local storage.
dump("Update ID: " + task.id + " data: " + task.data + "\n");
break;
case 'remove':
// An object has to be deleted in the local storage.
dump("Remove ID: " + task.id + " data: " + task.data + "\n");
break;
}
cursor.next().then(cursorResolve);
}
// Start to sync.
cursor.next().then(cursorResolve);
});
</pre>
</section>
</section>
<!-- - - - - - - - - - - - - - - Conformance - - - - - - - - - - - - - - - - -->
<section id="conformance">
<p>
This specification defines conformance criteria that apply to a single
product: the <dfn>user agent</dfn> that implements the interfaces that
it contains.
</p>
<p>
Implementations that use ECMAScript to implement the APIs defined in
this specification MUST implement them in a manner consistent with the
ECMAScript Bindings defined in the Web IDL specification [[!WEBIDL]], as
this specification uses that specification and terminology.
</p>
</section>
<!-- - - - - - - - - - - - - - - Terminology - - - - - - - - - - - - - - - -->
<section>
<h2>Terminology</h2>
<p>
The <dfn><a
href="http://dev.w3.org/html5/spec/webappapis.html#eventhandler">
EventHandler</a></dfn> interface represents a callback used for event
handlers as defined in [[!HTML5]].
</p>
<p>
The concepts <dfn><a
href="http://dev.w3.org/html5/spec/webappapis.html#queue-a-task"> queue
a task</a></dfn> and <dfn><a
href="http://dev.w3.org/html5/spec/webappapis.html#fire-a-simple-event">
fire an event</a></dfn> are defined in [[!HTML5]].
</p>
<p>
The terms <a
href="http://dev.w3.org/html5/spec/webappapis.html#event-handlers"><dfn
id="dfn-eventhandler">event handler</dfn></a> and <a
href="http://dev.w3.org/html5/spec/webappapis.html#event-handler-event-type">
<dfn id="dfn-eventtypes"> event handler event types</dfn></a> are
defined in [[!HTML5]].
</p>
<p>
The <dfn><a href="http://dom.spec.whatwg.org/#promise">Promise</a></dfn>
interface, the concepts of a <a href=
"http://dom.spec.whatwg.org/#concept-resolver"><dfn>resolver</dfn></a>, a
<dfn id="dfn-fulfill-algorithm"><a
href="http://dom.spec.whatwg.org/#concept-resolver-fulfill"> resolver's
fulfill algorithm</a></dfn> and a <dfn id="dfn-reject-algorithm"><a
href="http://dom.spec.whatwg.org/#concept-resolver-reject"> resolver's
reject algorithm</a></dfn> are defined in [[DOM4]].
</p>
</section>
<!-- - - - - - - - - - - - - - - Security and privacy - - - - - - - - - - - -->
<section>
<h2>Security and privacy considerations</h2>
<section>
<h3>Application Manifest</h3>
<p>
For the application that provides the data store, its manifest MUST be
claimed to own the data store by <code>datastores-owned</code>, where
the JSON object can contain multiple properties representing different
names of data stores respectively. Each data store can use
<code>readonly</code> to specify whether the data store can be read by
other applications and <code>description</code> to describe the
purpose.
</p>
<p>
As shown as the following example, if a Facebook applicaton wants to
provide a read-only <em>fb-contacts</em> data store, its manifest MUST
be claimed to own the data store by setting the attribute
<code>readonly</code> to <em>true</em>.
</p>
<pre class="example highlight">
{
datastores-owned: {
"fb-contacts": {
"readonly": true,
"description": "own the Facebook contacts data store"
}
}
}
</pre>
<p>
For the application that wants to access the data store, its manifest
MUST be claimed to access the data store by
<code>datastores-access</code>, where the JSON object can contain
multiple properties representing different names of data stores
respectively. Each data store can use <code>access</code> to specify
the application's accessibility and <code>description</code> to
describe the purpose.
</p>
<p>
As shown as the following example, if the application wants to read or
modify (e.g., add, update, remove, clear... etc) the content of the
<em>fb-contacts</em> data store, its manifest MUST be claimed to access
the <em>fb-contacts</em> data store by setting the attribute
<code>access</code> to <em>readwrite</em>.
</p>
<pre class="example highlight">
{
datastores-access: {
"fb-contacts": {
"access": "readwrite",
"description": "access (read and write) the Facebook contacts data stores"
}
}
}
</pre>
<p>
As shown as the following example, if the application simply wants to
read the content of the <em>fb-contacts</em> data store without the
need of modifying it, its manifest MUST be claimed to access the
<em>fb-contacts</em> data store by setting the attribute
<code>access</code> to <em>readonly</em>.
</p>
<pre class="example highlight">
{
datastores-access: {
"fb-contacts": {
"access": "readonly",
"description": "access (read only) the Facebook contacts data store"
}
}
}
</pre>
</section>
<section>
<h3>Permission Model</h3>
<p>
The Data Store API can be exposed to trusted or untrusted contents.
</p>
<div class='note'>
Need to define the permission model of how the privileged and the
third-party applications can be allowed to use the Data Store API to
access the data store.
</div>
</section>
</section>
<!-- - - - - - - - - - - - - Extended Interface Navigator - - - - - - - - - -->
<section>
<h2><a>Navigator</a> Interface</h2>
<dl title="partial interface Navigator" class="idl">
<dt>Promise getDataStores ()</dt>
<dd>
This method makes a request to retrieve the data stores by the
<code>name</code> parameter. It returns a new
<code>Promise</code> that will be used to notify the caller about
the result of the operation, which is an array of <a>DataStore</a>
elements to access the data stores which have the same name equal
to the <code>name</code>.
<dl class='parameters'>
<dt>DOMString name</dt>
<dd>Specifies the name of the data store.</dd>
</dl>
</dd>
</dl>
<section>
<h3>Steps</h3>
<p>
The <dfn><code>getDataStores</code></dfn> method when invoked MUST run
the following steps:
</p>
<ol>
<li>
Let <var>promise</var> be a new <code>Promise</code> object and
<var>resolver</var> be its associated <code>resolver</code>.
</li>
<li>
Return <var>promise</var> to the caller.
</li>
<li>
Make a request to the system to retrieve the data store(s) with the
name equal to the <code>name</code> parameter passed in the
request, where the caller application has claimed the data store
access by <code>datastores-access</code> in its manifest.
</li>
<li>
If an <var>error</var> occurs invoke <em>resolver</em>'s <a
class="internalDFN" href="#dfn-reject-algorithm">reject algorithm</a>
with <em>error</em> as the <code>value</code> argument.
</li>
<li>
When the request has been successfully completed:
</li>
<ol>
<li>
Let <var>dataStores</var> be the array of the retrieved
<a>DataStore</a> elements.
</li>
<li>
Invoke <em>resolver</em>'s <a
class="internalDFN" href="#dfn-fulfill-algorithm"> fulfill algorithm</a>
with <em>dataStores</em> as the <code>value</code> argument.
</li>
</ol>
</ol>
</section>
</section>
<!-- - - - - - - - - - - - - Interface DataStore - - - - - - - - - - - - - -->
<section>
<h2><a>DataStore</a> Interface</h2>
<p>
The <a>DataStore</a> interface represents a bunch of properties of the
data store and a set of operations that can be used to manage and
synchronize the content of the data store.
</p>
<div title="typedef (DOMString or unsigned long) DataStoreKey" class='idl'></div>
<dl title="interface DataStore : EventTarget" class="idl">
<dt>readonly attribute DOMString <a>name</a></dt>
<dd>
MUST return the name of the data store. Note that different data
stores can share the same name as long as they have the same
database schema/format.
</dd>
<dt>readonly attribute DOMString owner</dt>
<dd>
MUST return the owner of the data store, which can be the manifest
URL of the owner application.
</dd>
<dt>readonly attribute boolean readOnly</dt>
<dd>
MUST return whether the content of the data store can be changed or
not by the caller.
</dd>
<dt>readonly attribute DOMString revisionId</dt>
<dd>
MUST return the current revision of the data store, which can be a
UUID string.
</dd>
<dt>Promise get ()</dt>
<dd>
This method makes a request to retrieve the data record(s) by the
<code>id</code> parameter. It returns a new <code>Promise</code>
that will be used to notify the caller about the result of the
operation, which is an arbitrary object to represent the data
record if <code>id</code> is a single value, or a set of data
records if <code>id</code> is an array of values.
<dl class='parameters'>
<dt>DataStoreKey... id</dt>
<dd>
Identifies the data record(s) that is requested to be
retrieved.
</dd>
</dl>
</dd>
<dt>Promise update ()</dt>
<dd>
This method makes a request to update the existing data record by
the <code>id</code> and the <code>data</code> parameters. It returns
a new <code>Promise</code> that will be used to notify the caller
about the result of the operation.
<dl class='parameters'>
<dt>DataStoreKey id</dt>
<dd>
Identifies the data record that is requested to be updated.
</dd>
<dt>any data</dt>
<dd>
Specifies the content of the data record to update.
</dd>
</dl>
</dd>
<dt>Promise insert ()</dt>
<dd>
This method makes a request to add a new data record by the
<code>data</code> parameter. It returns a new <code>Promise</code>
that will be used to notify the caller about the result of the
operation, which is an identifier to access the data record that is
added.
<dl class='parameters'>
<dt>any data</dt>
<dd>
Specifies the content of the data record to add.
</dd>
</dl>
</dd>
<dt>Promise remove ()</dt>
<dd>
This method makes a request to delete the data record(s) by the
<code>id</code> parameter. It returns a new <code>Promise</code>
that will be used to notify the caller about the result of the
operation, which is a boolean value to indicate whether the data
record(s) is successfully deleted or not.
<dl class='parameters'>
<dt>DataStoreKey... id</dt>
<dd>
Identifies the data record(s) that is requested to be deleted.
</dd>
</dl>
</dd>
<dt>Promise clear ()</dt>
<dd>
This method makes a request to clear all the data records in the
data store. It returns a new <code>Promise</code> that will be used
to notify the caller about the result of the operation.
</dd>
<dt>Promise getLength ()</dt>
<dd>
This method makes a request to retrieve the total number of data
records saved in the data store. It returns a new
<code>Promise</code> that will be used to notify the caller about
the result of the operation, which is a numeric value to indicate
the total number of data records saved in the data store.
</dd>
<dt>DataStoreCursor sync ()</dt>
<dd>
This method makes a request to retrieve the change history between a
particular revision and the current revision of the data store by the
<code>revisionId</code> parameter. It returns a new
<a>DataStoreCursor</a> that will be used to iteratively access a set
of <a>DataStoreTask</a> elements.
<dl class='parameters'>
<dt>optional DOMString revisionId</dt>
<dd>
Identifies the revision of the data store that the application
currently keeps. If this parameter is absent or cannot be
identified, this method will return a <a>DataStoreCursor</a>
iterating through all the existing data records currently
saved in the data store.
</dd>
</dl>
</dd>
<dt class="no-docs">
attribute EventHandler onchange
</dt>
<dd>
Handles the <code>change</code> event of type
<a>DataStoreChangeEvent</a>, fired when a data record is added,
updated or deleted in the data store. Note that if some data change
in the data store when the <a>DataStoreCursor</a> is still
synchronizing data and the cursor's <a><code>close</code></a> method
has not yet been called, all the change events will not be
dispatched to the application's <code>onchange</code> event handler.
Instead, all the changes will be managed by the cursor's
<a><code>next</code></a> method as additional operations.
</dd>
</dl>
<section>
<h3>Steps</h3>
<p>
The <dfn><code>get</code></dfn> method when invoked MUST run the
following steps:
</p>
<ol>
<li>
Let <var>promise</var> be a new <code>Promise</code> object and
<var>resolver</var> be its associated <code>resolver</code>.
</li>
<li>
Return <var>promise</var> to the caller.
</li>
<li>
Make a request to the data store to retrieve the data record(s) with
the identifier equal to the <code>id</code> parameter passed in the
request.
</li>
<li>
If an <var>error</var> occurs invoke <em>resolver</em>'s <a
class="internalDFN" href="#dfn-reject-algorithm">reject algorithm</a>
with <em>error</em> as the <code>value</code> argument.
</li>
<li>
When the request has been successfully completed:
</li>
<ol>
<li>
Let <var>dataRecord</var> be the retrieved data record(s).
</li>
<li>
Invoke <em>resolver</em>'s <a
class="internalDFN" href="#dfn-fulfill-algorithm"> fulfill algorithm</a>
with <em>dataRecord</em> as the <code>value</code> argument.
</li>
</ol>
</ol>
<p>
The <dfn><code>update</code></dfn> method when invoked MUST run the
following steps:
</p>
<ol>
<li>
Let <var>promise</var> be a new <code>Promise</code> object and
<var>resolver</var> be its associated <code>resolver</code>.
</li>
<li>
Return <var>promise</var> to the caller.
</li>
<li>
If the <code>readOnly</code> attribute of the current data store is
<em>true</em> to the caller, invoke <em>resolver</em>'s <a
class="internalDFN" href="#dfn-reject-algorithm">reject algorithm</a>
without assigning a value to the <code>value</code> argument.
</li>
<li>
Make a request to the data store to retrieve the data record with
the identifier equal to the <code>id</code> parameter passed in the
request.
</li>
<li>
If an <var>error</var> occurs invoke <em>resolver</em>'s <a
class="internalDFN" href="#dfn-reject-algorithm">reject algorithm</a>
with <em>error</em> as the <code>value</code> argument.
</li>
<li>
When the request has been successfully completed:
</li>
<ol>
<li>
Let <var>dataRecord</var> be the retrieved data record.
</li>
<li>
Replace <em>dataRecord</em> by the <code>data</code> parameter
passed in the request.
</li>
<li>
Make a request to the data store to save <em>dataRecord</em> back
to the data store.
</li>
<li>
If an <var>error</var> occurs invoke <em>resolver</em>'s <a
class="internalDFN" href="#dfn-reject-algorithm">reject algorithm</a>
with <em>error</em> as the <code>value</code> argument.
</li>
<li>
When the request has been successfully completed:
</li>
<ol>
<li>
Invoke <em>resolver</em>'s <a
class="internalDFN" href="#dfn-fulfill-algorithm"> fulfill algorithm</a>
without assigning a value to the <code>value</code> argument.
</li>
</ol>
</ol>
</ol>
<p>
The <dfn><code>insert</code></dfn> method when invoked MUST run the
following steps:
</p>
<ol>
<li>
Let <var>promise</var> be a new <code>Promise</code> object and
<var>resolver</var> be its associated <code>resolver</code>.
</li>
<li>
Return <var>promise</var> to the caller.
</li>
<li>
If the <code>readOnly</code> attribute of the current data store is
<em>true</em> to the caller, invoke <em>resolver</em>'s <a
class="internalDFN" href="#dfn-reject-algorithm">reject algorithm</a>
without assigning a value to the <code>value</code> argument.
</li>
<li>
Make a request to the data store to add the <code>data</code>
parameter passed in the request.
</li>
<li>
If an <var>error</var> occurs invoke <em>resolver</em>'s <a
class="internalDFN" href="#dfn-reject-algorithm">reject algorithm</a>
with <em>error</em> as the <code>value</code> argument.
</li>
<li>
When the request has been successfully completed:
</li>
<ol>
<li>
Let <var>id</var> be the generated identifier of the added data
record.
</li>
<li>
Invoke <em>resolver</em>'s <a
class="internalDFN" href="#dfn-fulfill-algorithm"> fulfill algorithm</a>
with <em>id</em> as the <code>value</code> argument.
</li>
</ol>
</ol>
<p>
The <dfn><code>remove</code></dfn> method when invoked MUST run the
following steps:
</p>
<ol>
<li>
Let <var>promise</var> be a new <code>Promise</code> object and
<var>resolver</var> be its associated <code>resolver</code>.
</li>
<li>
Return <var>promise</var> to the caller.
</li>
<li>
If the <code>readOnly</code> attribute of the current data store is
<em>true</em> to the caller, invoke <em>resolver</em>'s <a
class="internalDFN" href="#dfn-reject-algorithm">reject algorithm</a>
with <em>false</em> as the <code>value</code> argument.
</li>
<li>
Make a request to the data store to retrieve the data record(s) with
the identifier equal to the <code>id</code> parameter passed in the
request.
</li>
<li>
If an <var>error</var> occurs invoke <em>resolver</em>'s <a
class="internalDFN" href="#dfn-reject-algorithm">reject algorithm</a>
with <em>false</em> as the <code>value</code> argument.
</li>
<li>
When the request has been successfully completed:
</li>
<ol>
<li>
Make a request to the data store to delete the data record(s) with
the identifier equal to the <code>id</code> parameter passed in
the request.
</li>
<li>
If an <var>error</var> occurs invoke <em>resolver</em>'s <a
class="internalDFN" href="#dfn-reject-algorithm">reject algorithm</a>
with <em>false</em> as the <code>value</code> argument.
</li>
<li>
When the request has been successfully completed:
</li>
<ol>
<li>
Invoke <em>resolver</em>'s <a
class="internalDFN" href="#dfn-fulfill-algorithm"> fulfill algorithm</a>
with <em>true</em> as the <code>value</code> argument.
</li>
</ol>
</ol>
</ol>
<p>
The <dfn><code>clear</code></dfn> method when invoked MUST run the
following steps:
</p>
<ol>
<li>
Let <var>promise</var> be a new <code>Promise</code> object and
<var>resolver</var> be its associated <code>resolver</code>.
</li>
<li>
Return <var>promise</var> to the caller.
</li>
<li>
If the <code>readOnly</code> attribute of the current data store is
<em>true</em> to the caller, invoke <em>resolver</em>'s <a
class="internalDFN" href="#dfn-reject-algorithm">reject algorithm</a>
without assigning a value to the <code>value</code> argument.
</li>
<li>
Make a request to the data store to clear all the data records.
</li>
<li>
If an <var>error</var> occurs invoke <em>resolver</em>'s <a
class="internalDFN" href="#dfn-reject-algorithm">reject algorithm</a>
with <em>error</em> as the <code>value</code> argument.
</li>
<li>
When the request has been successfully completed:
</li>
<ol>
<li>
Invoke <em>resolver</em>'s <a
class="internalDFN" href="#dfn-fulfill-algorithm"> fulfill algorithm</a>
without assigning a value to the <code>value</code> argument.
</li>
</ol>
</ol>
<p>
The <dfn><code>getLength</code></dfn> method when invoked MUST run the
following steps:
</p>
<ol>
<li>
Let <var>promise</var> be a new <code>Promise</code> object and
<var>resolver</var> be its associated <code>resolver</code>.
</li>
<li>
Return <var>promise</var> to the caller.
</li>
<li>
Make a request to the data store to get the total number of data
records.
</li>
<li>
If an <var>error</var> occurs invoke <em>resolver</em>'s <a
class="internalDFN" href="#dfn-reject-algorithm">reject algorithm</a>
with <em>error</em> as the <code>value</code> argument.
</li>
<li>
When the request has been successfully completed:
</li>
<ol>
<li>
Let <var>length</var> be the total number of data records saved in
the data store.
</li>
<li>
Invoke <em>resolver</em>'s <a
class="internalDFN" href="#dfn-fulfill-algorithm"> fulfill algorithm</a>
with <em>length</em> as the <code>value</code> argument.
</li>
</ol>
</ol>
<p>
The <dfn><code>sync</code></dfn> method when invoked MUST run the
following steps:
</p>
<ol>
<li>
Make a request to the system to retrieve a cursor that can iterate
through the change history of the current data store.
</li>
<li>
When the request has been successfully completed:
</li>
<ol>
<li>
Let <var>dataStoreCursor</var> be a new instance of
<a>DataStoreCursor</a>.
</li>
<li>
Set the <code>store</code> of <em>dataStoreCursor</em> to the
current data store.
</li>
<li>
Return <em>dataStoreCursor</em>.
</li>
</ol>
</ol>
</section>
<section>
<h2>Event handlers</h2>
<p>The following are the <a class="internalDFN"
href="#dfn-eventhandler">event handlers</a> (and their corresponding <a
class="internalDFN" href="#dfn-eventtypes">event types</a>) that MUST be
supported as attributes by the <a>DataStore</a> object.
<table class="simple">
<thead>
<tr>
<th>Event handler</th>
<th>Event name</th>
<th>Event type</th>
<th>Short description</th>
</tr>
</thead>
<tbody>
<tr>
<td><strong><code>onchange</code></strong></td>
<td><code><dfn id="dfn-change-event">change</dfn></code></td>
<td><a><code>DataStoreChangeEvent</code></a></td>
<td>
Handles the information of the data record changed in the data
store.
</td>
</tr>
</tbody>
</table>
</section>
</section>
<!-- - - - - - - - - - - - Interface DataStoreCursor - - - - - - - - - - - - - - -->
<section>
<h2><a>DataStoreCursor</a> Interface</h2>
<p>
The <a>DataStoreCursor</a> interface allows the application to iterate
through a list of <a>DataStoreTask</a> elements that represents the
change history of the data store.
</p>
<dl title="interface DataStoreCursor" class="idl">
<dt>readonly attribute DataStore store</dt>
<dd>
MUST return the data store that is currently iterated by the cursor.
</dd>
<dt>Promise next ()</dt>
<dd>
This method makes a request to retrieve the information of the next
operation that changes a data record in the data store. It returns a
new <code>Promise</code> that will be used to notify the caller
about the result of the operation, which is a <a>DataStoreTask</a>
to represent the information of the change operation.
</dd>
<dt>void close ()</dt>
<dd>
This method makes a request to terminate the cursor iterating
through the change history of the data store. Note that this method
has to be explicitly called when the cursor completes its tasks.
Otherwise, if some data changes in the data store when the cursor is
still synchronizing data, all the changes will be managed by the
cursor's <a><code>next</code></a> method as additional operations,
which means when the cursor completes its tasks, the application
will be in synchronization with the current revision of the data
store.
</dd>
</dl>
<section>
<h3>Steps</h3>
<p>
The <dfn><code>next</code></dfn> method when invoked MUST run the
following steps:
</p>
<ol>
<li>