WebAPI/DataStore

From MozillaWiki
< WebAPI
Revision as of 16:32, 12 April 2013 by Mounir.lamouri (talk | contribs) (Created page with "= Data Store API = This is the snapshot of a discussion between Mounir Lamouri, Thinker Lee, Gene Lian, Jonas Sicking and Hsin-Yi Tsai.<br> The work drafting happened on http...")
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to navigation Jump to search

Data Store API

This is the snapshot of a discussion between Mounir Lamouri, Thinker Lee, Gene Lian, Jonas Sicking and Hsin-Yi Tsai.
The work drafting happened on https://etherpad.mozilla.org/whatever-you-want

Use Cases

Allow an application to create data that can be shared with multiple other applications.
Allow multiple applications supply data to the same data store.
Support read-only stores like facebook contacts.
Support read/write stores like built-in contacts.
Support keeping a application-local cache of a data store. I.e. enable getting notified about changes to a data store so that the local cache can be kept up-to-date.
Enforce types of attributes (avoid to break other applications).

Interface

 interface DataStore {
   // Returns the label of the DataSource.
   readonly attribute DOMString name;
   // Returns the origin of the DataSource (e.g., 'facebook.com').
   // TODO: defines what the value should be if owned by 'system'.
   readonly attribute DOMString owner;
   // is readOnly a F(current_app, datastore) function? yes
   readonly attribute boolean readOnly;
   // TODO: id should be incremental.
   Future<Object>  get(int id);
   Future<void>    update(int id, Object obj);
   Future<int>     add(Object obj);
   Future<boolean> remove(int id);
   Future<void>    clear();
   readonly attribute DOMString revisionId;
   attribute EventHandler onchange;
   Future<DataStoreChanges> getChanges(DOMString revisionId);
   // TODO: getAll(), getLength().
 };
 
 interface DataStoreChanges {
   readonly attribute DOMString revisionId;
   readonly attribute int[] addedIds;
   readonly attribute int[] updatedIds;
   readonly attribute int[] removedIds;
 }
 partial interface Navigator {
   Future<DataStore[]> getDataStores(DOMString name);
 };

Manifest

For the application that provides the datastore

 {
   ...
   datastores-owned: {
     "contacts": {
       "readonly": true,
       "name": "Facebook contacts",
     }
   },
   ...
 }

For the application that wants to access the datastore

 {
   ...
   datastores-access: {
     "contacts": {
       "access": "readonly",
       "description": ...
     }
   },
   ...
 }

Issues

* {name, owner, value} is a complicated key.
* UI: what to do when we have multiple access requests?
* What's happening if the central gets changes during the process of local updates?
* |addedIds|, |removedIds| and |updatedIds| arrays should be synchronized. For example, the ID of record that has been updated and removed should only show up in the |removedIds| array. Need to define the behaviours.