///
///
declare namespace dojo {
namespace store {
namespace api {
type Identity = number | string;
/* dojo/store/api/Store */
interface SortInformation {
/**
* The name of the attribute to sort on.
*/
attribute: string;
/**
* The direction of the sort. Default is false.
*/
descending?: boolean;
}
interface QueryOptions {
/**
* A list of attributes to sort on, as well as direction
* For example:
* | [{attribute:"price", descending: true}].
* If the sort parameter is omitted, then the natural order of the store may be
* applied if there is a natural order.
*/
sort?: SortInformation[];
/**
* The first result to begin iteration on
*/
start?: number;
/**
* The number of how many results should be returned.
*/
count?: number;
}
interface QueryEngineFunction {
(array: T[]): T[];
matches(object: T): boolean;
}
type BaseQueryType = string | object | ((...params: any[]) => any);
interface QueryEngine {
(query: Q, options?: O): QueryEngineFunction;
}
interface PutDirectives {
/**
* Indicates the identity of the object if a new object is created
*/
id?: Identity;
/**
* If the collection of objects in the store has a natural ordering,
* this indicates that the created or updated object should be placed before the
* object specified by the value of this property. A value of null indicates that the
* object should be last.
*/
before?: T;
/**
* If the store is hierarchical (with single parenting) this property indicates the
* new parent of the created or updated object.
*/
parent?: T;
/**
* If this is provided as a boolean it indicates that the object should or should not
* overwrite an existing object. A value of true indicates that a new object
* should not be created, the operation should update an existing object. A
* value of false indicates that an existing object should not be updated, a new
* object should be created (which is the same as an add() operation). When
* this property is not provided, either an update or creation is acceptable.
*/
overwrite?: boolean;
}
interface SyncQueryResults extends Array {
total?: number;
}
interface AsyncQueryResults extends PromiseLike> {
/**
* Iterates over the query results, based on
* https://developer.mozilla.org/en/Core_JavaScript_1.5_Reference/objects/Array/forEach.
* Note that this may executed asynchronously. The callback may be called
* after this function returns.
*/
forEach(callback: (item: T, index: number, results: Array) => void, thisObject?: object): PromiseLike;
/**
* Filters the query results, based on
* https://developer.mozilla.org/en/Core_JavaScript_1.5_Reference/Objects/Array/filter.
* Note that this may executed asynchronously. The callback may be called
* after this function returns.
*/
filter(callback: (item: T, index: number, results: Array) => boolean, thisObject?: object): PromiseLike>;
/**
* Maps the query results, based on
* https://developer.mozilla.org/en/Core_JavaScript_1.5_Reference/Objects/Array/map.
* Note that this may executed asynchronously. The callback may be called
* after this function returns.
*/
map(callback: (item: T, index: number, results: Array) => U, thisObject?: object): PromiseLike>;
/** Cancells the current query */
cancel(reason?: any): void;
total?: PromiseLike;
}
type QueryResults = SyncQueryResults | AsyncQueryResults;
interface Transaction {
/**
* Commits the transaction. This may throw an error if it fails. Of if the operation
* is asynchronous, it may return a promise that represents the eventual success
* or failure of the commit.
*/
commit(): void;
/**
* Aborts the transaction. This may throw an error if it fails. Of if the operation
* is asynchronous, it may return a promise that represents the eventual success
* or failure of the abort.
*/
abort(): void;
}
interface Transacted {
/**
* Starts a new transaction.
* Note that a store user might not call transaction() prior to using put,
* delete, etc. in which case these operations effectively could be thought of
* as "auto-commit" style actions.
*/
transaction(): Transaction;
}
interface MetadataProvider {
/**
* Returns any metadata about the object. This may include attribution,
* cache directives, history, or version information.
*/
getMetadata(object: T): object;
}
interface IdentityProvider {
/**
* If the store has a single primary key, this indicates the property to use as the
* identity property. The values of this property should be unique.
*/
idProperty: keyof T;
/**
* Returns an object's identity
*/
getIdentity(object: T): Identity;
}
interface Queryable<
T extends object,
Q extends BaseQueryType,
O extends QueryOptions,
R extends QueryResults = QueryResults> {
/**
* Queries the store for objects. This does not alter the store, but returns a
* set of data from the store.
*/
query(query?: Q, options?: O): R;
}
interface SyncStore | ((item: T) => boolean) | string, O extends QueryOptions = QueryOptions>
extends IdentityProvider, Queryable> {
/**
* If the store can be queried locally (on the client side in JS), this defines
* the query engine to use for querying the data store.
* This takes a query and query options and returns a function that can execute
* the provided query on a JavaScript array. The queryEngine may be replace to
* provide more sophisticated querying capabilities. For example:
* | var query = store.queryEngine({foo:"bar"}, {count:10});
* | query(someArray) -> filtered array
* The returned query function may have a "matches" property that can be
* used to determine if an object matches the query. For example:
* | query.matches({id:"some-object", foo:"bar"}) -> true
* | query.matches({id:"some-object", foo:"something else"}) -> false
*/
queryEngine?: QueryEngine;
/**
* Retrieves an object by its identity
*/
get(id: Identity): T;
/**
* Stores an object
*/
put(object: T, directives?: PutDirectives): any;
/**
* Creates an object, throws an error if the object already exists
*/
add(object: T, directives?: PutDirectives): any;
/**
* Deletes an object by its identity
*/
remove(id: Identity): void;
}
interface AsyncStore | ((item: T) => boolean) | string, O extends QueryOptions = QueryOptions>
extends IdentityProvider, Queryable> {
/**
* If the store can be queried locally (on the client side in JS), this defines
* the query engine to use for querying the data store.
* This takes a query and query options and returns a function that can execute
* the provided query on a JavaScript array. The queryEngine may be replace to
* provide more sophisticated querying capabilities. For example:
* | var query = store.queryEngine({foo:"bar"}, {count:10});
* | query(someArray) -> filtered array
* The returned query function may have a "matches" property that can be
* used to determine if an object matches the query. For example:
* | query.matches({id:"some-object", foo:"bar"}) -> true
* | query.matches({id:"some-object", foo:"something else"}) -> false
*/
queryEngine?: QueryEngine;
/**
* Retrieves an object by its identity
*/
get(id: Identity): promise.Promise;
/**
* Stores an object
*/
put(object: T, directives?: PutDirectives): promise.Promise;
/**
* Creates an object, throws an error if the object already exists
*/
add(object: T, directives?: PutDirectives): promise.Promise;
/**
* Deletes an object by its identity
*/
remove(id: string | number): promise.Promise;
}
interface HierarchicalStore = QueryResults> {
/**
* Retrieves the children of an object.
*/
getChildren(parent: T, options?: O): R;
}
interface Store | ((item: T) => boolean) | string, O extends QueryOptions = QueryOptions>
extends IdentityProvider, Queryable {
/**
* If the store can be queried locally (on the client side in JS), this defines
* the query engine to use for querying the data store.
* This takes a query and query options and returns a function that can execute
* the provided query on a JavaScript array. The queryEngine may be replace to
* provide more sophisticated querying capabilities. For example:
* | var query = store.queryEngine({foo:"bar"}, {count:10});
* | query(someArray) -> filtered array
* The returned query function may have a "matches" property that can be
* used to determine if an object matches the query. For example:
* | query.matches({id:"some-object", foo:"bar"}) -> true
* | query.matches({id:"some-object", foo:"something else"}) -> false
*/
queryEngine?: QueryEngine;
/**
* Retrieves an object by its identity
*/
get(id: Identity): T | promise.Promise;
/**
* Stores an object
*/
put(object: T, directives?: PutDirectives): any;
/**
* Creates an object, throws an error if the object already exists
*/
add(object: T, directives?: PutDirectives): any;
/**
* Deletes an object by its identity
*/
remove(id: Identity): void | promise.Promise;
}
interface StoreConstructor {
new (): Store;
}
}
namespace util {
/* dojo/store/util/QueryResults */
interface QueryResultsFunction {
/**
* A function that wraps the results of a store query with additional
* methods.
*/
(results: T[]): api.SyncQueryResults;
(results: PromiseLike): api.AsyncQueryResults;
}
/* dojo/store/util/SimpleQueryEngine */
interface SimpleQueryEngine extends api.QueryEngine