/// 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: unknown[]) => unknown); 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): unknown; /** * Creates an object, throws an error if the object already exists */ add(object: T, directives?: PutDirectives): unknown; /** * 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): PromiseLike; /** * Stores an object */ put(object: T, directives?: PutDirectives): PromiseLike; /** * Creates an object, throws an error if the object already exists */ add(object: T, directives?: PutDirectives): PromiseLike; /** * Deletes an object by its identity */ remove(id: string | number): PromiseLike; } 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 | PromiseLike; /** * Stores an object */ put(object: T, directives?: PutDirectives): unknown; /** * Creates an object, throws an error if the object already exists */ add(object: T, directives?: PutDirectives): unknown; /** * Deletes an object by its identity */ remove(id: Identity): void | PromiseLike; } 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 { } } /* dojo/store/Cache */ interface CacheOptions { /** * This is a function that will be called for each item in a query response to determine * if it is cacheable. If isLoaded returns true, the item will be cached, otherwise it * will not be cached. If isLoaded is not provided, all items will be cached. */ isLoaded?: (item: T) => boolean; } interface CacheMixin { /** * Remove the object with the specific id. */ remove(id: api.Identity): PromiseLike; /** * Remove the object with the given id from the underlying caching store. */ evict(id: api.Identity): PromiseLike; } interface Cache { /** * The Cache store wrapper takes a master store and a caching store, * caches data from the master into the caching store for faster * lookup. Normally one would use a memory store for the caching * store and a server store like JsonRest for the master store. */ >(masterStore: S, cacheStore: api.Store, options?: CacheOptions): CacheMixin & S; } /* dojo/store/DataStore */ interface DataStoreOptions { idProperty?: keyof T; queryEngine?: api.QueryEngine; store?: data.api.Read | data.api.Write | data.api.Identity; } interface DataStore extends api.Store { /** * The object store to convert to a data store */ store: data.api.Read | data.api.Write | data.api.Identity; /** * Defines the query engine to use for querying the data store */ queryEngine: api.QueryEngine; _objectConverter(callback: (item: T) => any): (item: T) => any; } interface DataStoreConstructor extends _base.DeclareConstructor> { new (options?: DataStoreOptions): DataStore; } /* dojo/store/JsonRest */ interface Headers { [header: string]: string; } interface JsonRestPutDirectives extends api.PutDirectives { headers?: Headers; incremental?: boolean; timeout?: number } interface JsonRestQueryOptions extends api.QueryOptions { headers?: Headers; timeout?: number; } interface JsonRestOptions { idProperty?: keyof T; queryEngine?: api.QueryEngine; headers?: Headers; target?: string; rangeParam?: string; sortParam?: string; ascendingPrefix?: string; descendingPrefix?: string; accepts?: string; } interface JsonRest< T extends object, Q extends api.BaseQueryType = (Partial | string) & api.BaseQueryType, O extends JsonRestQueryOptions = JsonRestQueryOptions> extends api.AsyncStore { /** * Additional headers to pass in all requests to the server. These can be overridden * by passing additional headers to calls to the store. */ headers: Headers; /** * The target base URL to use for all requests to the server. This string will be * prepended to the id to generate the URL (relative or absolute) for requests * sent to the server */ target: string; /** * Use a query parameter for the requested range. If this is omitted, than the * Range header will be used. Independent of this, the X-Range header is always set. */ rangeParam?: string; /** * The query parameter to used for holding sort information. If this is omitted, than * the sort information is included in a functional query token to avoid colliding * with the set of name/value pairs. */ sortParam?: string; /** * The prefix to apply to sort attribute names that are ascending */ ascendingPrefix: string; /** * The prefix to apply to sort attribute names that are descending */ descendingPrefix: string; /** * If the target has no trailing '/', then append it. */ _getTarget(id: api.Identity): string; /** * Retrieves an object by its identity. This will trigger a GET request to the server using * the url `this.target + id`. */ get(id: api.Identity, options?: { headers: Headers } | Headers): PromiseLike; /** * Defines the Accept header to use on HTTP requests */ accepts: string; /** * Stores an object. This will trigger a PUT request to the server * if the object has an id, otherwise it will trigger a POST request. */ put(object: T, options?: JsonRestPutDirectives): PromiseLike; /** * Adds an object. This will trigger a PUT request to the server * if the object has an id, otherwise it will trigger a POST request. */ add(object: T, options?: JsonRestPutDirectives): PromiseLike; /** * Deletes an object by its identity. This will trigger a DELETE request to the server. */ remove(id: api.Identity, options?: { headers?: Headers }): PromiseLike; } interface JsonRestConstructor extends _base.DeclareConstructor> { new (options?: JsonRestOptions): JsonRest; } /* dojo/store/Memory */ interface MemoryOptions { data?: T[]; idProperty?: keyof T; queryEngine?: api.QueryEngine; setData?: (data: T[]) => void; } interface Memory extends api.SyncStore { /** * The array of all the objects in the memory store */ data: T[]; /** * An index of data indices into the data array by id */ index: { [id: string]: number }; /** * Sets the given data as the source for this store, and indexes it */ setData(data: T[]): void; } interface MemoryConstructor extends _base.DeclareConstructor> { /** * This is a basic in-memory object store. It implements dojo/store/api/Store. */ new (options?: MemoryOptions): Memory; } /* dojo/store/Observable */ interface ObservableQueryResultsMixin { /** * Allows observation of results */ observe(listener: (object: T, previousIndex: number, newIndex: number) => void, includeUpdates?: boolean): { remove(): void; cancel(): void; }; } type ObservableQueryResults = ObservableQueryResultsMixin & api.QueryResults; interface ObservableMixin = api.QueryResults > { notify(object: T, existingId?: api.Identity): void; /** * 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): ObservableQueryResultsMixin & R; } interface ResultsObserveMixin { /** * Allows observation of results */ observe(listener: (object: T, previousIndex: number, newIndex: number) => void, includeUpdates?: boolean): { remove(): void; cancel(): void; }; } interface Notifiable { notify(object: T, existingId?: api.Identity): void; } type ResultItem = R extends ArrayLike ? I1 : R extends PromiseLike> ? I2 : never; type ObservableStore any }> = S extends { query: (...params: infer P) => api.QueryResults } ? { [K in keyof S]: K extends "query" ? (...params: P) => ReturnType & ResultsObserveMixin : S[K]; } & Notifiable : S; interface Observable { new >(store: S): ObservableStore; } } }