]> git.wh0rd.org Git - tt-rss.git/blob - lib/dojo/store/api/Store.js.uncompressed.js
update dojo to 1.7.3
[tt-rss.git] / lib / dojo / store / api / Store.js.uncompressed.js
1 define("dojo/store/api/Store", ["dojo/_base/declare"], function(declare) {
2         // module:
3         //              dojo/store/api/Store
4         // summary:
5         //              The module defines the Dojo object store interface.
6
7 var Store = declare("dojo.store.api.Store", null, {
8         // summary:
9         //              This is an abstract API that data provider implementations conform to.
10         //              This file defines methods signatures and intentionally leaves all the
11         //              methods unimplemented.  For more information on the dojo.store APIs,
12         //              please visit: http://dojotoolkit.org/reference-guide/dojo/store.html
13         //              Every method and property is optional, and is only needed if the functionality
14         //              it provides is required.
15         //              Every method may return a promise for the specified return value if the
16         //              execution of the operation is asynchronous (except
17         //              for query() which already defines an async return value).
18
19         // idProperty: String
20         //              If the store has a single primary key, this tndicates the property to use as the
21         //              identity property. The values of this property should be unique.
22         idProperty: "id",
23
24         // queryEngine: Function
25         //              If the store can be queried locally (on the client side in JS), this defines
26         //              the query engine to use for querying the data store.
27         //              This takes a query and query options and returns a function that can execute
28         //              the provided query on a JavaScript array. The queryEngine may be replace to
29         //              provide more sophisticated querying capabilities. For example:
30         //              | var query = store.queryEngine({foo:"bar"}, {count:10});
31         //              | query(someArray) -> filtered array
32         //              The returned query function may have a "matches" property that can be
33         //              used to determine if an object matches the query. For example:
34         //              | query.matches({id:"some-object", foo:"bar"}) -> true
35         //              | query.matches({id:"some-object", foo:"something else"}) -> false
36         queryEngine: null,
37
38         get: function(id){
39                 // summary:
40                 //              Retrieves an object by its identity
41                 // id: Number
42                 //              The identity to use to lookup the object
43                 // returns: Object
44                 //              The object in the store that matches the given id.
45         },
46         getIdentity: function(object){
47                 // summary:
48                 //              Returns an object's identity
49                 // object: Object
50                 //              The object to get the identity from
51                 // returns: String|Number
52         },
53         put: function(object, directives){
54                 // summary:
55                 //              Stores an object
56                 // object: Object
57                 //              The object to store.
58                 // directives: dojo.store.api.Store.PutDirectives?
59                 //              Additional directives for storing objects.
60                 // returns: Number|String
61         },
62         add: function(object, directives){
63                 // summary:
64                 //              Creates an object, throws an error if the object already exists
65                 // object: Object
66                 //              The object to store.
67                 // directives: dojo.store.api.Store.PutDirectives?
68                 //              Additional directives for creating objects.
69                 // returns: Number|String
70         },
71         remove: function(id){
72                 // summary:
73                 //              Deletes an object by its identity
74                 // id: Number
75                 //              The identity to use to delete the object
76                 delete this.index[id];
77                 var data = this.data,
78                         idProperty = this.idProperty;
79                 for(var i = 0, l = data.length; i < l; i++){
80                         if(data[i][idProperty] == id){
81                                 data.splice(i, 1);
82                                 return;
83                         }
84                 }
85         },
86         query: function(query, options){
87                 // summary:
88                 //              Queries the store for objects. This does not alter the store, but returns a
89                 //              set of data from the store.
90                 // query: String|Object|Function
91                 //              The query to use for retrieving objects from the store.
92                 // options: dojo.store.api.Store.QueryOptions
93                 //              The optional arguments to apply to the resultset.
94                 // returns: dojo.store.api.Store.QueryResults
95                 //              The results of the query, extended with iterative methods.
96                 //
97                 // example:
98                 //              Given the following store:
99                 //
100                 //      ...find all items where "prime" is true:
101                 //
102                 //      |       store.query({ prime: true }).forEach(function(object){
103                 //      |               // handle each object
104                 //      |       });
105         },
106         transaction: function(){
107                 // summary:
108                 //              Starts a new transaction.
109                 //              Note that a store user might not call transaction() prior to using put,
110                 //              delete, etc. in which case these operations effectively could be thought of
111                 //              as "auto-commit" style actions.
112                 // returns: dojo.store.api.Store.Transaction
113                 //              This represents the new current transaction.
114         },
115         getChildren: function(parent, options){
116                 // summary:
117                 //              Retrieves the children of an object.
118                 // parent: Object
119                 //              The object to find the children of.
120                 // options: dojo.store.api.Store.QueryOptions?
121                 //              Additional options to apply to the retrieval of the children.
122                 // returns: dojo.store.api.Store.QueryResults
123                 //              A result set of the children of the parent object.
124         },
125         getMetadata: function(object){
126                 // summary:
127                 //              Returns any metadata about the object. This may include attribution,
128                 //              cache directives, history, or version information.
129                 // object: Object
130                 //              The object to return metadata for.
131                 // returns: Object
132                 //              An object containing metadata.
133         }
134 });
135
136 Store.PutDirectives = function(id, before, parent, overwrite){
137         // summary:
138         //              Directives passed to put() and add() handlers for guiding the update and
139         //              creation of stored objects.
140         // id: String|Number?
141         //              Indicates the identity of the object if a new object is created
142         // before: Object?
143         //              If the collection of objects in the store has a natural ordering,
144         //              this indicates that the created or updated object should be placed before the
145         //              object specified by the value of this property. A value of null indicates that the
146         //              object should be last.
147         // parent: Object?,
148         //              If the store is hierarchical (with single parenting) this property indicates the
149         //              new parent of the created or updated object.
150         // overwrite: Boolean?
151         //              If this is provided as a boolean it indicates that the object should or should not
152         //              overwrite an existing object. A value of true indicates that a new object
153         //              should not be created, the operation should update an existing object. A
154         //              value of false indicates that an existing object should not be updated, a new
155         //              object should be created (which is the same as an add() operation). When
156         //              this property is not provided, either an update or creation is acceptable.
157         this.id = id;
158         this.before = before;
159         this.parent = parent;
160         this.overwrite = overwrite;
161 };
162
163 Store.SortInformation = function(attribute, descending){
164         // summary:
165         //              An object describing what attribute to sort on, and the direction of the sort.
166         // attribute: String
167         //              The name of the attribute to sort on.
168         // descending: Boolean
169         //              The direction of the sort.  Default is false.
170         this.attribute = attribute;
171         this.descending = descending;
172 };
173
174 Store.QueryOptions = function(sort, start, count){
175         // summary:
176         //              Optional object with additional parameters for query results.
177         // sort: dojo.store.api.Store.SortInformation[]?
178         //              A list of attributes to sort on, as well as direction
179         //              For example:
180         //              | [{attribute:"price, descending: true}].
181         //              If the sort parameter is omitted, then the natural order of the store may be
182         //              applied if there is a natural order.
183         // start: Number?
184         //              The first result to begin iteration on
185         // count: Number?
186         //              The number of how many results should be returned.
187         this.sort = sort;
188         this.start = start;
189         this.count = count;
190 };
191
192 declare("dojo.store.api.Store.QueryResults", null, {
193         // summary:
194         //              This is an object returned from query() calls that provides access to the results
195         //              of a query. Queries may be executed asynchronously.
196
197         forEach: function(callback, thisObject){
198                 // summary:
199                 //              Iterates over the query results, based on
200                 //              https://developer.mozilla.org/en/Core_JavaScript_1.5_Reference/Objects/Array/forEach.
201                 //              Note that this may executed asynchronously. The callback may be called
202                 //              after this function returns.
203                 // callback:
204                 //              Function that is called for each object in the query results
205                 // thisObject:
206                 //              The object to use as |this| in the callback.
207
208         },
209         filter: function(callback, thisObject){
210                 // summary:
211                 //              Filters the query results, based on
212                 //              https://developer.mozilla.org/en/Core_JavaScript_1.5_Reference/Objects/Array/filter.
213                 //              Note that this may executed asynchronously. The callback may be called
214                 //              after this function returns.
215                 // callback:
216                 //              Function that is called for each object in the query results
217                 // thisObject:
218                 //              The object to use as |this| in the callback.
219                 // returns: dojo.store.api.Store.QueryResults
220         },
221         map: function(callback, thisObject){
222                 // summary:
223                 //              Maps the query results, based on
224                 //              https://developer.mozilla.org/en/Core_JavaScript_1.5_Reference/Objects/Array/map.
225                 //              Note that this may executed asynchronously. The callback may be called
226                 //              after this function returns.
227                 // callback:
228                 //              Function that is called for each object in the query results
229                 // thisObject:
230                 //              The object to use as |this| in the callback.
231                 // returns: dojo.store.api.Store.QueryResults
232         },
233         then: function(callback, errorHandler){
234                 // summary:
235                 //              This registers a callback for when the query is complete, if the query is asynchronous.
236                 //              This is an optional method, and may not be present for synchronous queries.
237                 // callback:
238                 //              This is called when the query is completed successfully, and is passed a single argument
239                 //              that is an array representing the query results.
240                 // errorHandler:
241                 //              This is called if the query failed, and is passed a single argument that is the error
242                 //              for the failure.
243         },
244         observe: function(listener, includeAllUpdates){
245                 // summary:
246                 //              This registers a callback for notification of when data is modified in the query results.
247                 //              This is an optional method, and is usually provided by dojo.store.Observable.
248                 // listener: Function
249                 //              The listener function is called when objects in the query results are modified
250                 //              to affect the query result. The listener function is called with the following
251                 // arguments:
252                 //              | listener(object, removedFrom, insertedInto);
253                 //              * The object parameter indicates the object that was create, modified, or deleted.
254                 //              * The removedFrom parameter indicates the index in the result array where
255                 //              the object used to be. If the value is -1, then the object is an addition to
256                 //              this result set (due to a new object being created, or changed such that it
257                 //              is a part of the result set).
258                 //              * The insertedInto parameter indicates the index in the result array where
259                 //              the object should be now. If the value is -1, then the object is a removal
260                 //              from this result set (due to an object being deleted, or changed such that it
261                 //              is not a part of the result set).
262                 // includeAllUpdates:
263                 //              This indicates whether or not to include object updates that do not affect
264                 //              the inclusion or order of the object in the query results. By default this is false,
265                 //              which means that if any object is updated in such a way that it remains
266                 //              in the result set and it's position in result sets is not affected, then the listener
267                 //              will not be fired.
268
269         },
270         // total: Number|Promise?
271         //              This property should be included in if the query options included the "count"
272         //              property limiting the result set. This property indicates the total number of objects
273         //              matching the query (as if "start" and "count" weren't present). This may be
274         //              a promise if the query is asynchronous.
275         total: 0
276 });
277
278 declare("dojo.store.api.Store.Transaction", null, {
279         // summary:
280         //              This is an object returned from transaction() calls that represents the current
281         //              transaction.
282
283         commit: function(){
284                 // summary:
285                 //              Commits the transaction. This may throw an error if it fails. Of if the operation
286                 //              is asynchronous, it may return a promise that represents the eventual success
287                 //              or failure of the commit.
288         },
289         abort: function(callback, thisObject){
290                 // summary:
291                 //              Aborts the transaction. This may throw an error if it fails. Of if the operation
292                 //              is asynchronous, it may return a promise that represents the eventual success
293                 //              or failure of the abort.
294         }
295 });
296 return Store;
297 });