@@ -1,33 +1,48 | |||||
1 | # dojo-typings |
|
1 | # dojo-typings | |
2 |
|
2 | |||
3 | This project is forked from the original `dojo-typings` package to |
|
3 | This project is forked from the original `dojo-typings` package to | |
4 | improve it with more tight and customizable type definitions. |
|
4 | improve it with more tight and customizable type definitions. | |
5 |
|
5 | |||
6 | The primary aims are |
|
6 | The primary aims are | |
7 |
|
7 | |||
8 | * Parametrize collections with items type. |
|
8 | * Parametrize collections with items type. | |
9 | * Distinguish sync and async methods in stores. |
|
9 | * Distinguish sync and async methods in stores. | |
10 | * Parametrize widget typings with event and attribute maps. |
|
10 | * Parametrize widget typings with event and attribute maps. | |
11 |
|
11 | |||
12 | ## Changes |
|
12 | ## Changes | |
13 |
|
13 | |||
|
14 | ### 1.0.3 | |||
|
15 | ||||
|
16 | Maintenance release | |||
|
17 | ||||
|
18 | * `dojo.store.api` replaced `dojo.promise.Promise<T>` with `PromiseLike<T>` type | |||
|
19 | ||||
|
20 | ### 1.0.2 | |||
|
21 | ||||
|
22 | Maintenance release | |||
|
23 | ||||
|
24 | * added type parameter to `Evented<T>`, `T` is the event map | |||
|
25 | * `_WidgetBase` `emit()` and `on()` are made more strict to accept only valid | |||
|
26 | event names, or explicit `any`. | |||
|
27 | * added `_setValueAttr` method to `_FormMixin` | |||
|
28 | ||||
14 | ### 1.0.1 |
|
29 | ### 1.0.1 | |
15 |
|
30 | |||
16 | Maintenance release |
|
31 | Maintenance release | |
17 |
|
32 | |||
18 | * `NodeList-fx` added overloads to all methods to distinguish returned values |
|
33 | * `NodeList-fx` added overloads to all methods to distinguish returned values | |
19 | of different types (`Animation | this`). |
|
34 | of different types (`Animation | this`). | |
20 | * Added missing signatures to `NodeList` constructor |
|
35 | * Added missing signatures to `NodeList` constructor | |
21 | * Improved `dijit.form._FormWidgetMixin` |
|
36 | * Improved `dijit.form._FormWidgetMixin` | |
22 | * Added module declarations `dijit/form/_FormWidgetMixin`, |
|
37 | * Added module declarations `dijit/form/_FormWidgetMixin`, | |
23 | `dijit/form/_FormValueMixin`, `dijit/_HasDropDown` |
|
38 | `dijit/form/_FormValueMixin`, `dijit/_HasDropDown` | |
24 |
|
39 | |||
25 | ### 1.0.0 |
|
40 | ### 1.0.0 | |
26 |
|
41 | |||
27 | Initial release |
|
42 | Initial release | |
28 |
|
43 | |||
29 | * Parametrized `dojo/Stateful`, `diji/_WidgetBase` |
|
44 | * Parametrized `dojo/Stateful`, `diji/_WidgetBase` | |
30 | * split `dojo.store.api.Store` in two `SyncStore` and `AsyncStore` interfaces |
|
45 | * split `dojo.store.api.Store` in two `SyncStore` and `AsyncStore` interfaces | |
31 | * `dojo/store/Memory` implements `SyncStore` and can be used synchronously, |
|
46 | * `dojo/store/Memory` implements `SyncStore` and can be used synchronously, | |
32 | * `dojo/store/Rest` implements `AsyncStore` and all its methods are |
|
47 | * `dojo/store/Rest` implements `AsyncStore` and all its methods are | |
33 | returning explicit promises. |
|
48 | returning explicit promises. |
@@ -1,591 +1,590 | |||||
1 | /// <reference path="promise.d.ts" /> |
|
|||
2 | /// <reference path="data.d.ts" /> |
|
1 | /// <reference path="data.d.ts" /> | |
3 |
|
2 | |||
4 |
|
3 | |||
5 | declare namespace dojo { |
|
4 | declare namespace dojo { | |
6 | namespace store { |
|
5 | namespace store { | |
7 | namespace api { |
|
6 | namespace api { | |
8 |
|
7 | |||
9 | type Identity = number | string; |
|
8 | type Identity = number | string; | |
10 |
|
9 | |||
11 | /* dojo/store/api/Store */ |
|
10 | /* dojo/store/api/Store */ | |
12 |
|
11 | |||
13 | interface SortInformation { |
|
12 | interface SortInformation { | |
14 |
|
13 | |||
15 | /** |
|
14 | /** | |
16 | * The name of the attribute to sort on. |
|
15 | * The name of the attribute to sort on. | |
17 | */ |
|
16 | */ | |
18 | attribute: string; |
|
17 | attribute: string; | |
19 |
|
18 | |||
20 | /** |
|
19 | /** | |
21 | * The direction of the sort. Default is false. |
|
20 | * The direction of the sort. Default is false. | |
22 | */ |
|
21 | */ | |
23 | descending?: boolean; |
|
22 | descending?: boolean; | |
24 | } |
|
23 | } | |
25 |
|
24 | |||
26 | interface QueryOptions { |
|
25 | interface QueryOptions { | |
27 | /** |
|
26 | /** | |
28 | * A list of attributes to sort on, as well as direction |
|
27 | * A list of attributes to sort on, as well as direction | |
29 | * For example: |
|
28 | * For example: | |
30 | * | [{attribute:"price", descending: true}]. |
|
29 | * | [{attribute:"price", descending: true}]. | |
31 | * If the sort parameter is omitted, then the natural order of the store may be |
|
30 | * If the sort parameter is omitted, then the natural order of the store may be | |
32 | * applied if there is a natural order. |
|
31 | * applied if there is a natural order. | |
33 | */ |
|
32 | */ | |
34 | sort?: SortInformation[]; |
|
33 | sort?: SortInformation[]; | |
35 |
|
34 | |||
36 | /** |
|
35 | /** | |
37 | * The first result to begin iteration on |
|
36 | * The first result to begin iteration on | |
38 | */ |
|
37 | */ | |
39 | start?: number; |
|
38 | start?: number; | |
40 |
|
39 | |||
41 | /** |
|
40 | /** | |
42 | * The number of how many results should be returned. |
|
41 | * The number of how many results should be returned. | |
43 | */ |
|
42 | */ | |
44 | count?: number; |
|
43 | count?: number; | |
45 | } |
|
44 | } | |
46 |
|
45 | |||
47 | interface QueryEngineFunction<T extends object> { |
|
46 | interface QueryEngineFunction<T extends object> { | |
48 | (array: T[]): T[]; |
|
47 | (array: T[]): T[]; | |
49 | matches(object: T): boolean; |
|
48 | matches(object: T): boolean; | |
50 | } |
|
49 | } | |
51 |
|
50 | |||
52 | type BaseQueryType = string | object | ((...params: any[]) => any); |
|
51 | type BaseQueryType = string | object | ((...params: any[]) => any); | |
53 |
|
52 | |||
54 | interface QueryEngine<T extends object, Q extends BaseQueryType> { |
|
53 | interface QueryEngine<T extends object, Q extends BaseQueryType> { | |
55 | <O extends QueryOptions>(query: Q, options?: O): QueryEngineFunction<T>; |
|
54 | <O extends QueryOptions>(query: Q, options?: O): QueryEngineFunction<T>; | |
56 | } |
|
55 | } | |
57 |
|
56 | |||
58 | interface PutDirectives<T extends object> { |
|
57 | interface PutDirectives<T extends object> { | |
59 |
|
58 | |||
60 | /** |
|
59 | /** | |
61 | * Indicates the identity of the object if a new object is created |
|
60 | * Indicates the identity of the object if a new object is created | |
62 | */ |
|
61 | */ | |
63 | id?: Identity; |
|
62 | id?: Identity; | |
64 |
|
63 | |||
65 | /** |
|
64 | /** | |
66 | * If the collection of objects in the store has a natural ordering, |
|
65 | * If the collection of objects in the store has a natural ordering, | |
67 | * this indicates that the created or updated object should be placed before the |
|
66 | * this indicates that the created or updated object should be placed before the | |
68 | * object specified by the value of this property. A value of null indicates that the |
|
67 | * object specified by the value of this property. A value of null indicates that the | |
69 | * object should be last. |
|
68 | * object should be last. | |
70 | */ |
|
69 | */ | |
71 | before?: T; |
|
70 | before?: T; | |
72 |
|
71 | |||
73 | /** |
|
72 | /** | |
74 | * If the store is hierarchical (with single parenting) this property indicates the |
|
73 | * If the store is hierarchical (with single parenting) this property indicates the | |
75 | * new parent of the created or updated object. |
|
74 | * new parent of the created or updated object. | |
76 | */ |
|
75 | */ | |
77 | parent?: T; |
|
76 | parent?: T; | |
78 |
|
77 | |||
79 | /** |
|
78 | /** | |
80 | * If this is provided as a boolean it indicates that the object should or should not |
|
79 | * If this is provided as a boolean it indicates that the object should or should not | |
81 | * overwrite an existing object. A value of true indicates that a new object |
|
80 | * overwrite an existing object. A value of true indicates that a new object | |
82 | * should not be created, the operation should update an existing object. A |
|
81 | * should not be created, the operation should update an existing object. A | |
83 | * value of false indicates that an existing object should not be updated, a new |
|
82 | * value of false indicates that an existing object should not be updated, a new | |
84 | * object should be created (which is the same as an add() operation). When |
|
83 | * object should be created (which is the same as an add() operation). When | |
85 | * this property is not provided, either an update or creation is acceptable. |
|
84 | * this property is not provided, either an update or creation is acceptable. | |
86 | */ |
|
85 | */ | |
87 | overwrite?: boolean; |
|
86 | overwrite?: boolean; | |
88 | } |
|
87 | } | |
89 |
|
88 | |||
90 | interface SyncQueryResults<T extends object> extends Array<T> { |
|
89 | interface SyncQueryResults<T extends object> extends Array<T> { | |
91 | total?: number; |
|
90 | total?: number; | |
92 | } |
|
91 | } | |
93 |
|
92 | |||
94 | interface AsyncQueryResults<T extends object> extends PromiseLike<Array<T>> { |
|
93 | interface AsyncQueryResults<T extends object> extends PromiseLike<Array<T>> { | |
95 | /** |
|
94 | /** | |
96 | * Iterates over the query results, based on |
|
95 | * Iterates over the query results, based on | |
97 | * https://developer.mozilla.org/en/Core_JavaScript_1.5_Reference/objects/Array/forEach. |
|
96 | * https://developer.mozilla.org/en/Core_JavaScript_1.5_Reference/objects/Array/forEach. | |
98 | * Note that this may executed asynchronously. The callback may be called |
|
97 | * Note that this may executed asynchronously. The callback may be called | |
99 | * after this function returns. |
|
98 | * after this function returns. | |
100 | */ |
|
99 | */ | |
101 | forEach(callback: (item: T, index: number, results: Array<T>) => void, thisObject?: object): PromiseLike<void>; |
|
100 | forEach(callback: (item: T, index: number, results: Array<T>) => void, thisObject?: object): PromiseLike<void>; | |
102 |
|
101 | |||
103 | /** |
|
102 | /** | |
104 | * Filters the query results, based on |
|
103 | * Filters the query results, based on | |
105 | * https://developer.mozilla.org/en/Core_JavaScript_1.5_Reference/Objects/Array/filter. |
|
104 | * https://developer.mozilla.org/en/Core_JavaScript_1.5_Reference/Objects/Array/filter. | |
106 | * Note that this may executed asynchronously. The callback may be called |
|
105 | * Note that this may executed asynchronously. The callback may be called | |
107 | * after this function returns. |
|
106 | * after this function returns. | |
108 | */ |
|
107 | */ | |
109 | filter(callback: (item: T, index: number, results: Array<T>) => boolean, thisObject?: object): PromiseLike<Array<T>>; |
|
108 | filter(callback: (item: T, index: number, results: Array<T>) => boolean, thisObject?: object): PromiseLike<Array<T>>; | |
110 |
|
109 | |||
111 | /** |
|
110 | /** | |
112 | * Maps the query results, based on |
|
111 | * Maps the query results, based on | |
113 | * https://developer.mozilla.org/en/Core_JavaScript_1.5_Reference/Objects/Array/map. |
|
112 | * https://developer.mozilla.org/en/Core_JavaScript_1.5_Reference/Objects/Array/map. | |
114 | * Note that this may executed asynchronously. The callback may be called |
|
113 | * Note that this may executed asynchronously. The callback may be called | |
115 | * after this function returns. |
|
114 | * after this function returns. | |
116 | */ |
|
115 | */ | |
117 | map<U>(callback: (item: T, index: number, results: Array<T>) => U, thisObject?: object): PromiseLike<Array<U>>; |
|
116 | map<U>(callback: (item: T, index: number, results: Array<T>) => U, thisObject?: object): PromiseLike<Array<U>>; | |
118 |
|
117 | |||
119 | /** Cancells the current query */ |
|
118 | /** Cancells the current query */ | |
120 | cancel(reason?: any): void; |
|
119 | cancel(reason?: any): void; | |
121 |
|
120 | |||
122 | total?: PromiseLike<number>; |
|
121 | total?: PromiseLike<number>; | |
123 | } |
|
122 | } | |
124 |
|
123 | |||
125 | type QueryResults<T extends object> = SyncQueryResults<T> | AsyncQueryResults<T>; |
|
124 | type QueryResults<T extends object> = SyncQueryResults<T> | AsyncQueryResults<T>; | |
126 |
|
125 | |||
127 | interface Transaction { |
|
126 | interface Transaction { | |
128 | /** |
|
127 | /** | |
129 | * Commits the transaction. This may throw an error if it fails. Of if the operation |
|
128 | * Commits the transaction. This may throw an error if it fails. Of if the operation | |
130 | * is asynchronous, it may return a promise that represents the eventual success |
|
129 | * is asynchronous, it may return a promise that represents the eventual success | |
131 | * or failure of the commit. |
|
130 | * or failure of the commit. | |
132 | */ |
|
131 | */ | |
133 | commit(): void; |
|
132 | commit(): void; | |
134 |
|
133 | |||
135 | /** |
|
134 | /** | |
136 | * Aborts the transaction. This may throw an error if it fails. Of if the operation |
|
135 | * Aborts the transaction. This may throw an error if it fails. Of if the operation | |
137 | * is asynchronous, it may return a promise that represents the eventual success |
|
136 | * is asynchronous, it may return a promise that represents the eventual success | |
138 | * or failure of the abort. |
|
137 | * or failure of the abort. | |
139 | */ |
|
138 | */ | |
140 | abort(): void; |
|
139 | abort(): void; | |
141 | } |
|
140 | } | |
142 |
|
141 | |||
143 | interface Transacted { |
|
142 | interface Transacted { | |
144 | /** |
|
143 | /** | |
145 | * Starts a new transaction. |
|
144 | * Starts a new transaction. | |
146 | * Note that a store user might not call transaction() prior to using put, |
|
145 | * Note that a store user might not call transaction() prior to using put, | |
147 | * delete, etc. in which case these operations effectively could be thought of |
|
146 | * delete, etc. in which case these operations effectively could be thought of | |
148 | * as "auto-commit" style actions. |
|
147 | * as "auto-commit" style actions. | |
149 | */ |
|
148 | */ | |
150 | transaction(): Transaction; |
|
149 | transaction(): Transaction; | |
151 | } |
|
150 | } | |
152 |
|
151 | |||
153 | interface MetadataProvider<T extends object> { |
|
152 | interface MetadataProvider<T extends object> { | |
154 | /** |
|
153 | /** | |
155 | * Returns any metadata about the object. This may include attribution, |
|
154 | * Returns any metadata about the object. This may include attribution, | |
156 | * cache directives, history, or version information. |
|
155 | * cache directives, history, or version information. | |
157 | */ |
|
156 | */ | |
158 | getMetadata(object: T): object; |
|
157 | getMetadata(object: T): object; | |
159 | } |
|
158 | } | |
160 |
|
159 | |||
161 | interface IdentityProvider<T extends object> { |
|
160 | interface IdentityProvider<T extends object> { | |
162 | /** |
|
161 | /** | |
163 | * If the store has a single primary key, this indicates the property to use as the |
|
162 | * If the store has a single primary key, this indicates the property to use as the | |
164 | * identity property. The values of this property should be unique. |
|
163 | * identity property. The values of this property should be unique. | |
165 | */ |
|
164 | */ | |
166 | idProperty: keyof T; |
|
165 | idProperty: keyof T; | |
167 |
|
166 | |||
168 | /** |
|
167 | /** | |
169 | * Returns an object's identity |
|
168 | * Returns an object's identity | |
170 | */ |
|
169 | */ | |
171 | getIdentity(object: T): Identity; |
|
170 | getIdentity(object: T): Identity; | |
172 | } |
|
171 | } | |
173 |
|
172 | |||
174 | interface Queryable< |
|
173 | interface Queryable< | |
175 | T extends object, |
|
174 | T extends object, | |
176 | Q extends BaseQueryType, |
|
175 | Q extends BaseQueryType, | |
177 | O extends QueryOptions, |
|
176 | O extends QueryOptions, | |
178 | R extends QueryResults<T> = QueryResults<T>> { |
|
177 | R extends QueryResults<T> = QueryResults<T>> { | |
179 |
|
178 | |||
180 | /** |
|
179 | /** | |
181 | * Queries the store for objects. This does not alter the store, but returns a |
|
180 | * Queries the store for objects. This does not alter the store, but returns a | |
182 | * set of data from the store. |
|
181 | * set of data from the store. | |
183 | */ |
|
182 | */ | |
184 | query(query?: Q, options?: O): R; |
|
183 | query(query?: Q, options?: O): R; | |
185 | } |
|
184 | } | |
186 |
|
185 | |||
187 | interface SyncStore<T extends object, Q extends BaseQueryType = Partial<T> | ((item: T) => boolean) | string, O extends QueryOptions = QueryOptions> |
|
186 | interface SyncStore<T extends object, Q extends BaseQueryType = Partial<T> | ((item: T) => boolean) | string, O extends QueryOptions = QueryOptions> | |
188 | extends IdentityProvider<T>, Queryable<T, Q, O, SyncQueryResults<T>> { |
|
187 | extends IdentityProvider<T>, Queryable<T, Q, O, SyncQueryResults<T>> { | |
189 |
|
188 | |||
190 | /** |
|
189 | /** | |
191 | * If the store can be queried locally (on the client side in JS), this defines |
|
190 | * If the store can be queried locally (on the client side in JS), this defines | |
192 | * the query engine to use for querying the data store. |
|
191 | * the query engine to use for querying the data store. | |
193 | * This takes a query and query options and returns a function that can execute |
|
192 | * This takes a query and query options and returns a function that can execute | |
194 | * the provided query on a JavaScript array. The queryEngine may be replace to |
|
193 | * the provided query on a JavaScript array. The queryEngine may be replace to | |
195 | * provide more sophisticated querying capabilities. For example: |
|
194 | * provide more sophisticated querying capabilities. For example: | |
196 | * | var query = store.queryEngine({foo:"bar"}, {count:10}); |
|
195 | * | var query = store.queryEngine({foo:"bar"}, {count:10}); | |
197 | * | query(someArray) -> filtered array |
|
196 | * | query(someArray) -> filtered array | |
198 | * The returned query function may have a "matches" property that can be |
|
197 | * The returned query function may have a "matches" property that can be | |
199 | * used to determine if an object matches the query. For example: |
|
198 | * used to determine if an object matches the query. For example: | |
200 | * | query.matches({id:"some-object", foo:"bar"}) -> true |
|
199 | * | query.matches({id:"some-object", foo:"bar"}) -> true | |
201 | * | query.matches({id:"some-object", foo:"something else"}) -> false |
|
200 | * | query.matches({id:"some-object", foo:"something else"}) -> false | |
202 | */ |
|
201 | */ | |
203 | queryEngine?: QueryEngine<T, Q>; |
|
202 | queryEngine?: QueryEngine<T, Q>; | |
204 |
|
203 | |||
205 | /** |
|
204 | /** | |
206 | * Retrieves an object by its identity |
|
205 | * Retrieves an object by its identity | |
207 | */ |
|
206 | */ | |
208 | get(id: Identity): T; |
|
207 | get(id: Identity): T; | |
209 |
|
208 | |||
210 | /** |
|
209 | /** | |
211 | * Stores an object |
|
210 | * Stores an object | |
212 | */ |
|
211 | */ | |
213 | put(object: T, directives?: PutDirectives<T>): any; |
|
212 | put(object: T, directives?: PutDirectives<T>): any; | |
214 |
|
213 | |||
215 | /** |
|
214 | /** | |
216 | * Creates an object, throws an error if the object already exists |
|
215 | * Creates an object, throws an error if the object already exists | |
217 | */ |
|
216 | */ | |
218 | add(object: T, directives?: PutDirectives<T>): any; |
|
217 | add(object: T, directives?: PutDirectives<T>): any; | |
219 |
|
218 | |||
220 | /** |
|
219 | /** | |
221 | * Deletes an object by its identity |
|
220 | * Deletes an object by its identity | |
222 | */ |
|
221 | */ | |
223 | remove(id: Identity): void; |
|
222 | remove(id: Identity): void; | |
224 |
|
223 | |||
225 | } |
|
224 | } | |
226 |
|
225 | |||
227 | interface AsyncStore<T extends object, Q extends BaseQueryType = Partial<T> | ((item: T) => boolean) | string, O extends QueryOptions = QueryOptions> |
|
226 | interface AsyncStore<T extends object, Q extends BaseQueryType = Partial<T> | ((item: T) => boolean) | string, O extends QueryOptions = QueryOptions> | |
228 | extends IdentityProvider<T>, Queryable<T, Q, O, AsyncQueryResults<T>> { |
|
227 | extends IdentityProvider<T>, Queryable<T, Q, O, AsyncQueryResults<T>> { | |
229 |
|
228 | |||
230 | /** |
|
229 | /** | |
231 | * If the store can be queried locally (on the client side in JS), this defines |
|
230 | * If the store can be queried locally (on the client side in JS), this defines | |
232 | * the query engine to use for querying the data store. |
|
231 | * the query engine to use for querying the data store. | |
233 | * This takes a query and query options and returns a function that can execute |
|
232 | * This takes a query and query options and returns a function that can execute | |
234 | * the provided query on a JavaScript array. The queryEngine may be replace to |
|
233 | * the provided query on a JavaScript array. The queryEngine may be replace to | |
235 | * provide more sophisticated querying capabilities. For example: |
|
234 | * provide more sophisticated querying capabilities. For example: | |
236 | * | var query = store.queryEngine({foo:"bar"}, {count:10}); |
|
235 | * | var query = store.queryEngine({foo:"bar"}, {count:10}); | |
237 | * | query(someArray) -> filtered array |
|
236 | * | query(someArray) -> filtered array | |
238 | * The returned query function may have a "matches" property that can be |
|
237 | * The returned query function may have a "matches" property that can be | |
239 | * used to determine if an object matches the query. For example: |
|
238 | * used to determine if an object matches the query. For example: | |
240 | * | query.matches({id:"some-object", foo:"bar"}) -> true |
|
239 | * | query.matches({id:"some-object", foo:"bar"}) -> true | |
241 | * | query.matches({id:"some-object", foo:"something else"}) -> false |
|
240 | * | query.matches({id:"some-object", foo:"something else"}) -> false | |
242 | */ |
|
241 | */ | |
243 | queryEngine?: QueryEngine<T, Q>; |
|
242 | queryEngine?: QueryEngine<T, Q>; | |
244 |
|
243 | |||
245 | /** |
|
244 | /** | |
246 | * Retrieves an object by its identity |
|
245 | * Retrieves an object by its identity | |
247 | */ |
|
246 | */ | |
248 |
get(id: Identity): |
|
247 | get(id: Identity): PromiseLike<T>; | |
249 |
|
248 | |||
250 | /** |
|
249 | /** | |
251 | * Stores an object |
|
250 | * Stores an object | |
252 | */ |
|
251 | */ | |
253 |
put(object: T, directives?: PutDirectives<T>): |
|
252 | put(object: T, directives?: PutDirectives<T>): PromiseLike<any>; | |
254 |
|
253 | |||
255 | /** |
|
254 | /** | |
256 | * Creates an object, throws an error if the object already exists |
|
255 | * Creates an object, throws an error if the object already exists | |
257 | */ |
|
256 | */ | |
258 |
add(object: T, directives?: PutDirectives<T>): |
|
257 | add(object: T, directives?: PutDirectives<T>): PromiseLike<any>; | |
259 |
|
258 | |||
260 | /** |
|
259 | /** | |
261 | * Deletes an object by its identity |
|
260 | * Deletes an object by its identity | |
262 | */ |
|
261 | */ | |
263 |
remove(id: string | number): |
|
262 | remove(id: string | number): PromiseLike<void>; | |
264 |
|
263 | |||
265 | } |
|
264 | } | |
266 |
|
265 | |||
267 | interface HierarchicalStore<T extends object, O extends QueryOptions = QueryOptions, R extends QueryResults<T> = QueryResults<T>> { |
|
266 | interface HierarchicalStore<T extends object, O extends QueryOptions = QueryOptions, R extends QueryResults<T> = QueryResults<T>> { | |
268 |
|
267 | |||
269 | /** |
|
268 | /** | |
270 | * Retrieves the children of an object. |
|
269 | * Retrieves the children of an object. | |
271 | */ |
|
270 | */ | |
272 | getChildren(parent: T, options?: O): R; |
|
271 | getChildren(parent: T, options?: O): R; | |
273 | } |
|
272 | } | |
274 |
|
273 | |||
275 | interface Store<T extends object, Q extends BaseQueryType = Partial<T> | ((item: T) => boolean) | string, O extends QueryOptions = QueryOptions> |
|
274 | interface Store<T extends object, Q extends BaseQueryType = Partial<T> | ((item: T) => boolean) | string, O extends QueryOptions = QueryOptions> | |
276 | extends IdentityProvider<T>, Queryable<T, Q, O> { |
|
275 | extends IdentityProvider<T>, Queryable<T, Q, O> { | |
277 |
|
276 | |||
278 | /** |
|
277 | /** | |
279 | * If the store can be queried locally (on the client side in JS), this defines |
|
278 | * If the store can be queried locally (on the client side in JS), this defines | |
280 | * the query engine to use for querying the data store. |
|
279 | * the query engine to use for querying the data store. | |
281 | * This takes a query and query options and returns a function that can execute |
|
280 | * This takes a query and query options and returns a function that can execute | |
282 | * the provided query on a JavaScript array. The queryEngine may be replace to |
|
281 | * the provided query on a JavaScript array. The queryEngine may be replace to | |
283 | * provide more sophisticated querying capabilities. For example: |
|
282 | * provide more sophisticated querying capabilities. For example: | |
284 | * | var query = store.queryEngine({foo:"bar"}, {count:10}); |
|
283 | * | var query = store.queryEngine({foo:"bar"}, {count:10}); | |
285 | * | query(someArray) -> filtered array |
|
284 | * | query(someArray) -> filtered array | |
286 | * The returned query function may have a "matches" property that can be |
|
285 | * The returned query function may have a "matches" property that can be | |
287 | * used to determine if an object matches the query. For example: |
|
286 | * used to determine if an object matches the query. For example: | |
288 | * | query.matches({id:"some-object", foo:"bar"}) -> true |
|
287 | * | query.matches({id:"some-object", foo:"bar"}) -> true | |
289 | * | query.matches({id:"some-object", foo:"something else"}) -> false |
|
288 | * | query.matches({id:"some-object", foo:"something else"}) -> false | |
290 | */ |
|
289 | */ | |
291 | queryEngine?: QueryEngine<T, Q>; |
|
290 | queryEngine?: QueryEngine<T, Q>; | |
292 |
|
291 | |||
293 | /** |
|
292 | /** | |
294 | * Retrieves an object by its identity |
|
293 | * Retrieves an object by its identity | |
295 | */ |
|
294 | */ | |
296 |
get(id: Identity): T | |
|
295 | get(id: Identity): T | PromiseLike<T>; | |
297 |
|
296 | |||
298 | /** |
|
297 | /** | |
299 | * Stores an object |
|
298 | * Stores an object | |
300 | */ |
|
299 | */ | |
301 | put(object: T, directives?: PutDirectives<T>): any; |
|
300 | put(object: T, directives?: PutDirectives<T>): any; | |
302 |
|
301 | |||
303 | /** |
|
302 | /** | |
304 | * Creates an object, throws an error if the object already exists |
|
303 | * Creates an object, throws an error if the object already exists | |
305 | */ |
|
304 | */ | |
306 | add(object: T, directives?: PutDirectives<T>): any; |
|
305 | add(object: T, directives?: PutDirectives<T>): any; | |
307 |
|
306 | |||
308 | /** |
|
307 | /** | |
309 | * Deletes an object by its identity |
|
308 | * Deletes an object by its identity | |
310 | */ |
|
309 | */ | |
311 |
remove(id: Identity): void | |
|
310 | remove(id: Identity): void | PromiseLike<void>; | |
312 |
|
311 | |||
313 | } |
|
312 | } | |
314 |
|
313 | |||
315 | interface StoreConstructor { |
|
314 | interface StoreConstructor { | |
316 | new <T extends object, Q extends BaseQueryType, O extends QueryOptions>(): Store<T, Q, O>; |
|
315 | new <T extends object, Q extends BaseQueryType, O extends QueryOptions>(): Store<T, Q, O>; | |
317 | } |
|
316 | } | |
318 | } |
|
317 | } | |
319 |
|
318 | |||
320 | namespace util { |
|
319 | namespace util { | |
321 |
|
320 | |||
322 | /* dojo/store/util/QueryResults */ |
|
321 | /* dojo/store/util/QueryResults */ | |
323 |
|
322 | |||
324 | interface QueryResultsFunction { |
|
323 | interface QueryResultsFunction { | |
325 | /** |
|
324 | /** | |
326 | * A function that wraps the results of a store query with additional |
|
325 | * A function that wraps the results of a store query with additional | |
327 | * methods. |
|
326 | * methods. | |
328 | */ |
|
327 | */ | |
329 | <T extends object>(results: T[]): api.SyncQueryResults<T>; |
|
328 | <T extends object>(results: T[]): api.SyncQueryResults<T>; | |
330 | <T extends object>(results: PromiseLike<T[]>): api.AsyncQueryResults<T>; |
|
329 | <T extends object>(results: PromiseLike<T[]>): api.AsyncQueryResults<T>; | |
331 | } |
|
330 | } | |
332 |
|
331 | |||
333 | /* dojo/store/util/SimpleQueryEngine */ |
|
332 | /* dojo/store/util/SimpleQueryEngine */ | |
334 | interface SimpleQueryEngine extends api.QueryEngine<object, api.BaseQueryType> { } |
|
333 | interface SimpleQueryEngine extends api.QueryEngine<object, api.BaseQueryType> { } | |
335 | } |
|
334 | } | |
336 |
|
335 | |||
337 | /* dojo/store/Cache */ |
|
336 | /* dojo/store/Cache */ | |
338 |
|
337 | |||
339 | interface CacheOptions<T extends object = any> { |
|
338 | interface CacheOptions<T extends object = any> { | |
340 | /** |
|
339 | /** | |
341 | * This is a function that will be called for each item in a query response to determine |
|
340 | * This is a function that will be called for each item in a query response to determine | |
342 | * if it is cacheable. If isLoaded returns true, the item will be cached, otherwise it |
|
341 | * if it is cacheable. If isLoaded returns true, the item will be cached, otherwise it | |
343 | * will not be cached. If isLoaded is not provided, all items will be cached. |
|
342 | * will not be cached. If isLoaded is not provided, all items will be cached. | |
344 | */ |
|
343 | */ | |
345 | isLoaded?: (item: T) => boolean; |
|
344 | isLoaded?: (item: T) => boolean; | |
346 | } |
|
345 | } | |
347 |
|
346 | |||
348 | interface CacheMixin { |
|
347 | interface CacheMixin { | |
349 | /** |
|
348 | /** | |
350 | * Remove the object with the specific id. |
|
349 | * Remove the object with the specific id. | |
351 | */ |
|
350 | */ | |
352 |
remove(id: api.Identity): |
|
351 | remove(id: api.Identity): PromiseLike<void>; | |
353 |
|
352 | |||
354 | /** |
|
353 | /** | |
355 | * Remove the object with the given id from the underlying caching store. |
|
354 | * Remove the object with the given id from the underlying caching store. | |
356 | */ |
|
355 | */ | |
357 |
evict(id: api.Identity): |
|
356 | evict(id: api.Identity): PromiseLike<void>; | |
358 | } |
|
357 | } | |
359 |
|
358 | |||
360 | interface Cache { |
|
359 | interface Cache { | |
361 | /** |
|
360 | /** | |
362 | * The Cache store wrapper takes a master store and a caching store, |
|
361 | * The Cache store wrapper takes a master store and a caching store, | |
363 | * caches data from the master into the caching store for faster |
|
362 | * caches data from the master into the caching store for faster | |
364 | * lookup. Normally one would use a memory store for the caching |
|
363 | * lookup. Normally one would use a memory store for the caching | |
365 | * store and a server store like JsonRest for the master store. |
|
364 | * store and a server store like JsonRest for the master store. | |
366 | */ |
|
365 | */ | |
367 | <T extends object, Q extends api.BaseQueryType, O extends api.QueryOptions, S extends api.Store<T, Q, O>>(masterStore: S, cacheStore: api.Store<T, Q, O>, options?: CacheOptions): CacheMixin & S; |
|
366 | <T extends object, Q extends api.BaseQueryType, O extends api.QueryOptions, S extends api.Store<T, Q, O>>(masterStore: S, cacheStore: api.Store<T, Q, O>, options?: CacheOptions): CacheMixin & S; | |
368 | } |
|
367 | } | |
369 |
|
368 | |||
370 | /* dojo/store/DataStore */ |
|
369 | /* dojo/store/DataStore */ | |
371 |
|
370 | |||
372 | interface DataStoreOptions<T extends object> { |
|
371 | interface DataStoreOptions<T extends object> { | |
373 | idProperty?: keyof T; |
|
372 | idProperty?: keyof T; | |
374 | queryEngine?: api.QueryEngine<T, api.QueryOptions>; |
|
373 | queryEngine?: api.QueryEngine<T, api.QueryOptions>; | |
375 | store?: data.api.Read<T> | data.api.Write<T> | data.api.Identity<T>; |
|
374 | store?: data.api.Read<T> | data.api.Write<T> | data.api.Identity<T>; | |
376 | } |
|
375 | } | |
377 |
|
376 | |||
378 | interface DataStore<T extends object> extends api.Store<T, api.BaseQueryType, api.QueryOptions> { |
|
377 | interface DataStore<T extends object> extends api.Store<T, api.BaseQueryType, api.QueryOptions> { | |
379 | /** |
|
378 | /** | |
380 | * The object store to convert to a data store |
|
379 | * The object store to convert to a data store | |
381 | */ |
|
380 | */ | |
382 | store: data.api.Read<T> | data.api.Write<T> | data.api.Identity<T>; |
|
381 | store: data.api.Read<T> | data.api.Write<T> | data.api.Identity<T>; | |
383 |
|
382 | |||
384 | /** |
|
383 | /** | |
385 | * Defines the query engine to use for querying the data store |
|
384 | * Defines the query engine to use for querying the data store | |
386 | */ |
|
385 | */ | |
387 | queryEngine: api.QueryEngine<T, api.BaseQueryType>; |
|
386 | queryEngine: api.QueryEngine<T, api.BaseQueryType>; | |
388 |
|
387 | |||
389 | _objectConverter(callback: (item: T) => any): (item: T) => any; |
|
388 | _objectConverter(callback: (item: T) => any): (item: T) => any; | |
390 | } |
|
389 | } | |
391 |
|
390 | |||
392 | interface DataStoreConstructor extends _base.DeclareConstructor<DataStore<object>> { |
|
391 | interface DataStoreConstructor extends _base.DeclareConstructor<DataStore<object>> { | |
393 | new <T extends object>(options?: DataStoreOptions<T>): DataStore<T>; |
|
392 | new <T extends object>(options?: DataStoreOptions<T>): DataStore<T>; | |
394 | } |
|
393 | } | |
395 |
|
394 | |||
396 | /* dojo/store/JsonRest */ |
|
395 | /* dojo/store/JsonRest */ | |
397 |
|
396 | |||
398 | interface Headers { |
|
397 | interface Headers { | |
399 | [header: string]: string; |
|
398 | [header: string]: string; | |
400 | } |
|
399 | } | |
401 |
|
400 | |||
402 | interface JsonRestPutDirectives<T extends object> extends api.PutDirectives<T> { |
|
401 | interface JsonRestPutDirectives<T extends object> extends api.PutDirectives<T> { | |
403 | headers?: Headers; |
|
402 | headers?: Headers; | |
404 |
|
403 | |||
405 | incremental?: boolean; |
|
404 | incremental?: boolean; | |
406 |
|
405 | |||
407 | timeout?: number |
|
406 | timeout?: number | |
408 | } |
|
407 | } | |
409 |
|
408 | |||
410 | interface JsonRestQueryOptions extends api.QueryOptions { |
|
409 | interface JsonRestQueryOptions extends api.QueryOptions { | |
411 | headers?: Headers; |
|
410 | headers?: Headers; | |
412 |
|
411 | |||
413 | timeout?: number; |
|
412 | timeout?: number; | |
414 | } |
|
413 | } | |
415 |
|
414 | |||
416 | interface JsonRestOptions<T extends object> { |
|
415 | interface JsonRestOptions<T extends object> { | |
417 | idProperty?: keyof T; |
|
416 | idProperty?: keyof T; | |
418 | queryEngine?: api.QueryEngine<T, JsonRestQueryOptions>; |
|
417 | queryEngine?: api.QueryEngine<T, JsonRestQueryOptions>; | |
419 | headers?: Headers; |
|
418 | headers?: Headers; | |
420 | target?: string; |
|
419 | target?: string; | |
421 | rangeParam?: string; |
|
420 | rangeParam?: string; | |
422 | sortParam?: string; |
|
421 | sortParam?: string; | |
423 | ascendingPrefix?: string; |
|
422 | ascendingPrefix?: string; | |
424 | descendingPrefix?: string; |
|
423 | descendingPrefix?: string; | |
425 | accepts?: string; |
|
424 | accepts?: string; | |
426 | } |
|
425 | } | |
427 |
|
426 | |||
428 | interface JsonRest< |
|
427 | interface JsonRest< | |
429 | T extends object, |
|
428 | T extends object, | |
430 | Q extends api.BaseQueryType = (Partial<T> | string) & api.BaseQueryType, |
|
429 | Q extends api.BaseQueryType = (Partial<T> | string) & api.BaseQueryType, | |
431 | O extends JsonRestQueryOptions = JsonRestQueryOptions> |
|
430 | O extends JsonRestQueryOptions = JsonRestQueryOptions> | |
432 | extends api.AsyncStore<T, Q, O> { |
|
431 | extends api.AsyncStore<T, Q, O> { | |
433 | /** |
|
432 | /** | |
434 | * Additional headers to pass in all requests to the server. These can be overridden |
|
433 | * Additional headers to pass in all requests to the server. These can be overridden | |
435 | * by passing additional headers to calls to the store. |
|
434 | * by passing additional headers to calls to the store. | |
436 | */ |
|
435 | */ | |
437 | headers: Headers; |
|
436 | headers: Headers; | |
438 |
|
437 | |||
439 | /** |
|
438 | /** | |
440 | * The target base URL to use for all requests to the server. This string will be |
|
439 | * The target base URL to use for all requests to the server. This string will be | |
441 | * prepended to the id to generate the URL (relative or absolute) for requests |
|
440 | * prepended to the id to generate the URL (relative or absolute) for requests | |
442 | * sent to the server |
|
441 | * sent to the server | |
443 | */ |
|
442 | */ | |
444 | target: string; |
|
443 | target: string; | |
445 |
|
444 | |||
446 | /** |
|
445 | /** | |
447 | * Use a query parameter for the requested range. If this is omitted, than the |
|
446 | * Use a query parameter for the requested range. If this is omitted, than the | |
448 | * Range header will be used. Independent of this, the X-Range header is always set. |
|
447 | * Range header will be used. Independent of this, the X-Range header is always set. | |
449 | */ |
|
448 | */ | |
450 | rangeParam?: string; |
|
449 | rangeParam?: string; | |
451 |
|
450 | |||
452 | /** |
|
451 | /** | |
453 | * The query parameter to used for holding sort information. If this is omitted, than |
|
452 | * The query parameter to used for holding sort information. If this is omitted, than | |
454 | * the sort information is included in a functional query token to avoid colliding |
|
453 | * the sort information is included in a functional query token to avoid colliding | |
455 | * with the set of name/value pairs. |
|
454 | * with the set of name/value pairs. | |
456 | */ |
|
455 | */ | |
457 | sortParam?: string; |
|
456 | sortParam?: string; | |
458 |
|
457 | |||
459 | /** |
|
458 | /** | |
460 | * The prefix to apply to sort attribute names that are ascending |
|
459 | * The prefix to apply to sort attribute names that are ascending | |
461 | */ |
|
460 | */ | |
462 | ascendingPrefix: string; |
|
461 | ascendingPrefix: string; | |
463 |
|
462 | |||
464 | /** |
|
463 | /** | |
465 | * The prefix to apply to sort attribute names that are descending |
|
464 | * The prefix to apply to sort attribute names that are descending | |
466 | */ |
|
465 | */ | |
467 | descendingPrefix: string; |
|
466 | descendingPrefix: string; | |
468 |
|
467 | |||
469 | /** |
|
468 | /** | |
470 | * If the target has no trailing '/', then append it. |
|
469 | * If the target has no trailing '/', then append it. | |
471 | */ |
|
470 | */ | |
472 | _getTarget(id: api.Identity): string; |
|
471 | _getTarget(id: api.Identity): string; | |
473 |
|
472 | |||
474 | /** |
|
473 | /** | |
475 | * Retrieves an object by its identity. This will trigger a GET request to the server using |
|
474 | * Retrieves an object by its identity. This will trigger a GET request to the server using | |
476 | * the url `this.target + id`. |
|
475 | * the url `this.target + id`. | |
477 | */ |
|
476 | */ | |
478 |
get(id: api.Identity, options?: { headers: Headers } | Headers): |
|
477 | get(id: api.Identity, options?: { headers: Headers } | Headers): PromiseLike<T>; | |
479 |
|
478 | |||
480 | /** |
|
479 | /** | |
481 | * Defines the Accept header to use on HTTP requests |
|
480 | * Defines the Accept header to use on HTTP requests | |
482 | */ |
|
481 | */ | |
483 | accepts: string; |
|
482 | accepts: string; | |
484 |
|
483 | |||
485 | /** |
|
484 | /** | |
486 | * Stores an object. This will trigger a PUT request to the server |
|
485 | * Stores an object. This will trigger a PUT request to the server | |
487 | * if the object has an id, otherwise it will trigger a POST request. |
|
486 | * if the object has an id, otherwise it will trigger a POST request. | |
488 | */ |
|
487 | */ | |
489 |
put(object: T, options?: JsonRestPutDirectives<T>): |
|
488 | put(object: T, options?: JsonRestPutDirectives<T>): PromiseLike<any>; | |
490 |
|
489 | |||
491 | /** |
|
490 | /** | |
492 | * Adds an object. This will trigger a PUT request to the server |
|
491 | * Adds an object. This will trigger a PUT request to the server | |
493 | * if the object has an id, otherwise it will trigger a POST request. |
|
492 | * if the object has an id, otherwise it will trigger a POST request. | |
494 | */ |
|
493 | */ | |
495 |
add(object: T, options?: JsonRestPutDirectives<T>): |
|
494 | add(object: T, options?: JsonRestPutDirectives<T>): PromiseLike<any>; | |
496 |
|
495 | |||
497 | /** |
|
496 | /** | |
498 | * Deletes an object by its identity. This will trigger a DELETE request to the server. |
|
497 | * Deletes an object by its identity. This will trigger a DELETE request to the server. | |
499 | */ |
|
498 | */ | |
500 |
remove(id: api.Identity, options?: { headers?: Headers }): |
|
499 | remove(id: api.Identity, options?: { headers?: Headers }): PromiseLike<void>; | |
501 |
|
500 | |||
502 | } |
|
501 | } | |
503 |
|
502 | |||
504 | interface JsonRestConstructor extends _base.DeclareConstructor<JsonRest<object, api.BaseQueryType, JsonRestQueryOptions>> { |
|
503 | interface JsonRestConstructor extends _base.DeclareConstructor<JsonRest<object, api.BaseQueryType, JsonRestQueryOptions>> { | |
505 | new <T extends object, Q extends api.BaseQueryType, O extends JsonRestQueryOptions>(options?: JsonRestOptions<T>): JsonRest<T, Q, O>; |
|
504 | new <T extends object, Q extends api.BaseQueryType, O extends JsonRestQueryOptions>(options?: JsonRestOptions<T>): JsonRest<T, Q, O>; | |
506 | } |
|
505 | } | |
507 |
|
506 | |||
508 | /* dojo/store/Memory */ |
|
507 | /* dojo/store/Memory */ | |
509 |
|
508 | |||
510 | interface MemoryOptions<T extends object> { |
|
509 | interface MemoryOptions<T extends object> { | |
511 | data?: T[]; |
|
510 | data?: T[]; | |
512 | idProperty?: keyof T; |
|
511 | idProperty?: keyof T; | |
513 | queryEngine?: api.QueryEngine<T, api.QueryOptions>; |
|
512 | queryEngine?: api.QueryEngine<T, api.QueryOptions>; | |
514 | setData?: (data: T[]) => void; |
|
513 | setData?: (data: T[]) => void; | |
515 | } |
|
514 | } | |
516 |
|
515 | |||
517 | interface Memory<T extends object> extends api.SyncStore<T> { |
|
516 | interface Memory<T extends object> extends api.SyncStore<T> { | |
518 | /** |
|
517 | /** | |
519 | * The array of all the objects in the memory store |
|
518 | * The array of all the objects in the memory store | |
520 | */ |
|
519 | */ | |
521 | data: T[]; |
|
520 | data: T[]; | |
522 |
|
521 | |||
523 | /** |
|
522 | /** | |
524 | * An index of data indices into the data array by id |
|
523 | * An index of data indices into the data array by id | |
525 | */ |
|
524 | */ | |
526 | index: { [id: string]: number }; |
|
525 | index: { [id: string]: number }; | |
527 |
|
526 | |||
528 | /** |
|
527 | /** | |
529 | * Sets the given data as the source for this store, and indexes it |
|
528 | * Sets the given data as the source for this store, and indexes it | |
530 | */ |
|
529 | */ | |
531 | setData(data: T[]): void; |
|
530 | setData(data: T[]): void; | |
532 | } |
|
531 | } | |
533 |
|
532 | |||
534 | interface MemoryConstructor extends _base.DeclareConstructor<Memory<any>> { |
|
533 | interface MemoryConstructor extends _base.DeclareConstructor<Memory<any>> { | |
535 | /** |
|
534 | /** | |
536 | * This is a basic in-memory object store. It implements dojo/store/api/Store. |
|
535 | * This is a basic in-memory object store. It implements dojo/store/api/Store. | |
537 | */ |
|
536 | */ | |
538 | new <T extends object>(options?: MemoryOptions<T>): Memory<T>; |
|
537 | new <T extends object>(options?: MemoryOptions<T>): Memory<T>; | |
539 | } |
|
538 | } | |
540 |
|
539 | |||
541 | /* dojo/store/Observable */ |
|
540 | /* dojo/store/Observable */ | |
542 |
|
541 | |||
543 | interface ObservableQueryResultsMixin<T extends object> { |
|
542 | interface ObservableQueryResultsMixin<T extends object> { | |
544 | /** |
|
543 | /** | |
545 | * Allows observation of results |
|
544 | * Allows observation of results | |
546 | */ |
|
545 | */ | |
547 | observe(listener: (object: T, previousIndex: number, newIndex: number) => void, includeUpdates?: boolean): { |
|
546 | observe(listener: (object: T, previousIndex: number, newIndex: number) => void, includeUpdates?: boolean): { | |
548 | remove(): void; |
|
547 | remove(): void; | |
549 | cancel(): void; |
|
548 | cancel(): void; | |
550 | }; |
|
549 | }; | |
551 | } |
|
550 | } | |
552 |
|
551 | |||
553 | type ObservableQueryResults<T extends object> = ObservableQueryResultsMixin<T> & api.QueryResults<T>; |
|
552 | type ObservableQueryResults<T extends object> = ObservableQueryResultsMixin<T> & api.QueryResults<T>; | |
554 |
|
553 | |||
555 | interface ObservableMixin<T extends object, Q extends api.BaseQueryType, O extends api.QueryOptions, R extends api.QueryResults<T> = api.QueryResults<T> > { |
|
554 | interface ObservableMixin<T extends object, Q extends api.BaseQueryType, O extends api.QueryOptions, R extends api.QueryResults<T> = api.QueryResults<T> > { | |
556 | notify(object: T, existingId?: api.Identity): void; |
|
555 | notify(object: T, existingId?: api.Identity): void; | |
557 |
|
556 | |||
558 | /** |
|
557 | /** | |
559 | * Queries the store for objects. This does not alter the store, but returns a |
|
558 | * Queries the store for objects. This does not alter the store, but returns a | |
560 | * set of data from the store. |
|
559 | * set of data from the store. | |
561 | */ |
|
560 | */ | |
562 | query(query: Q, options?: O): ObservableQueryResultsMixin<T> & R; |
|
561 | query(query: Q, options?: O): ObservableQueryResultsMixin<T> & R; | |
563 | } |
|
562 | } | |
564 |
|
563 | |||
565 | interface ResultsObserveMixin<T extends object> { |
|
564 | interface ResultsObserveMixin<T extends object> { | |
566 | /** |
|
565 | /** | |
567 | * Allows observation of results |
|
566 | * Allows observation of results | |
568 | */ |
|
567 | */ | |
569 | observe(listener: (object: T, previousIndex: number, newIndex: number) => void, includeUpdates?: boolean): { |
|
568 | observe(listener: (object: T, previousIndex: number, newIndex: number) => void, includeUpdates?: boolean): { | |
570 | remove(): void; |
|
569 | remove(): void; | |
571 | cancel(): void; |
|
570 | cancel(): void; | |
572 | }; |
|
571 | }; | |
573 | } |
|
572 | } | |
574 |
|
573 | |||
575 | interface Notifiable<T> { |
|
574 | interface Notifiable<T> { | |
576 | notify(object: T, existingId?: api.Identity): void; |
|
575 | notify(object: T, existingId?: api.Identity): void; | |
577 | } |
|
576 | } | |
578 |
|
577 | |||
579 | type ResultItem<R> = R extends ArrayLike<infer I1> ? I1 : |
|
578 | type ResultItem<R> = R extends ArrayLike<infer I1> ? I1 : | |
580 | R extends PromiseLike<ArrayLike<infer I2>> ? I2 : never; |
|
579 | R extends PromiseLike<ArrayLike<infer I2>> ? I2 : never; | |
581 |
|
580 | |||
582 | type ObservableStore<S extends { query: (...params: any) => any }> = |
|
581 | type ObservableStore<S extends { query: (...params: any) => any }> = | |
583 | S extends { query: (...params: infer P) => api.QueryResults<infer R> } ? { |
|
582 | S extends { query: (...params: infer P) => api.QueryResults<infer R> } ? { | |
584 | [K in keyof S]: K extends "query" ? (...params: P) => ReturnType<S[K]> & ResultsObserveMixin<R> : S[K]; |
|
583 | [K in keyof S]: K extends "query" ? (...params: P) => ReturnType<S[K]> & ResultsObserveMixin<R> : S[K]; | |
585 | } & Notifiable<R> : S; |
|
584 | } & Notifiable<R> : S; | |
586 |
|
585 | |||
587 | interface Observable { |
|
586 | interface Observable { | |
588 | new <S extends api.Store<any, any, any>>(store: S): ObservableStore<S>; |
|
587 | new <S extends api.Store<any, any, any>>(store: S): ObservableStore<S>; | |
589 | } |
|
588 | } | |
590 | } |
|
589 | } | |
591 | } |
|
590 | } |
General Comments 0
You need to be logged in to leave comments.
Login now