# HG changeset patch # User cin # Date 2023-09-16 22:28:08 # Node ID 1c7650c178560caafa6caac9f86e761055e88e4c # Parent 5657d35e9f296cb4534543a539375878b130b665 added type parameter to dojo.store.api.SortInformation, added sort function to query sort option diff --git a/dojo-typings/src/main/typings/dijit/form.d.ts b/dojo-typings/src/main/typings/dijit/form.d.ts --- a/dojo-typings/src/main/typings/dijit/form.d.ts +++ b/dojo-typings/src/main/typings/dijit/form.d.ts @@ -46,7 +46,7 @@ declare namespace dijit { /* dijit/form/_AutoCompleterMixin */ /* tslint:disable:class-name */ - interface _AutoCompleterMixin extends _SearchMixin { + interface _AutoCompleterMixin = dojo.store.api.QueryOptions> extends _SearchMixin { /** * This is the item returned by the dojo/store/api/Store implementation that * provides the data for this ComboBox, it's the currently selected item. @@ -250,7 +250,7 @@ declare namespace dijit { /** * Fills in the items in the drop down list */ - createOptions(results: T[], options: dojo.store.api.QueryOptions, labelFunc: (item: T) => { html: boolean; label: string; }): void; + createOptions(results: T[], options: dojo.store.api.QueryOptions, labelFunc: (item: T) => { html: boolean; label: string; }): void; /** * Clears the entries in the drop down list, but of course keeps the previous and next buttons. @@ -470,7 +470,7 @@ declare namespace dijit { disabled?: boolean; } - interface _FormSelectWidget extends _FormValueWidget { + interface _FormSelectWidget = dojo.store.api.QueryOptions> extends _FormValueWidget { /** * Whether or not we are multi-valued */ @@ -869,7 +869,7 @@ declare namespace dijit { /* dijit/form/_SearchMixin */ - interface _SearchMixin { + interface _SearchMixin = dojo.store.api.QueryOptions> { /** * Argument to data provider. * Specifies maximum number of search results to return per query @@ -1170,18 +1170,18 @@ declare namespace dijit { /* dijit/form/ComboBox */ - interface ComboBox extends ValidationTextBox, ComboBoxMixin { + interface ComboBox = dojo.store.api.QueryOptions, C extends Constraints = Constraints> extends ValidationTextBox, ComboBoxMixin { // set(name: string, value: any): this; // set(values: Object): this; } interface ComboBoxConstructor extends _WidgetBaseConstructor> { - new (params: Object, srcNodeRef: dojo.NodeOrString): ComboBox; + new = dojo.store.api.QueryOptions, C extends Constraints = Constraints>(params: Object, srcNodeRef: dojo.NodeOrString): ComboBox; } /* dijit/form/ComboBoxMixin */ - interface ComboBoxMixin extends _HasDropDown<_ComboBoxMenu>, _AutoCompleterMixin { + interface ComboBoxMixin = dojo.store.api.QueryOptions> extends _HasDropDown<_ComboBoxMenu>, _AutoCompleterMixin { /** * Dropdown widget class used to select a date/time. @@ -1315,7 +1315,7 @@ declare namespace dijit { /* dijit/form/FilteringSelect */ - interface FilteringSelect extends MappedTextBox, ComboBoxMixin { + interface FilteringSelect> extends MappedTextBox, ComboBoxMixin { /** * True (default) if user is required to enter a value into this field. */ @@ -1341,7 +1341,7 @@ declare namespace dijit { } interface FilteringSelectConstructor extends _WidgetBaseConstructor> { - new (params: Object, srcNodeRef: dojo.NodeOrString): FilteringSelect; + new >(params: Object, srcNodeRef: dojo.NodeOrString): FilteringSelect; } /* dijit/form/Form */ @@ -1691,7 +1691,7 @@ declare namespace dijit { /* dijit/form/Select */ - interface Select extends _FormSelectWidget, _HasDropDown, _KeyNavMixin { + interface Select, U extends dijit._WidgetBase> extends _FormSelectWidget, _HasDropDown, _KeyNavMixin { baseClass: string; /** diff --git a/dojo-typings/src/main/typings/dijit/modules.d.ts b/dojo-typings/src/main/typings/dijit/modules.d.ts --- a/dojo-typings/src/main/typings/dijit/modules.d.ts +++ b/dojo-typings/src/main/typings/dijit/modules.d.ts @@ -332,7 +332,7 @@ declare module 'dijit/form/DropDownButto } declare module 'dijit/form/FilteringSelect' { - type FilteringSelect = dijit.form.FilteringSelect; + type FilteringSelect = dojo.store.api.QueryOptions> = dijit.form.FilteringSelect; const FilteringSelect: dijit.form.FilteringSelectConstructor; export = FilteringSelect; } diff --git a/dojo-typings/src/main/typings/dojo/store.d.ts b/dojo-typings/src/main/typings/dojo/store.d.ts --- a/dojo-typings/src/main/typings/dojo/store.d.ts +++ b/dojo-typings/src/main/typings/dojo/store.d.ts @@ -9,12 +9,12 @@ declare namespace dojo { /* dojo/store/api/Store */ - interface SortInformation { + interface SortInformation { /** * The name of the attribute to sort on. */ - attribute: string; + attribute: K; /** * The direction of the sort. Default is false. @@ -22,7 +22,9 @@ declare namespace dojo { descending?: boolean; } - interface QueryOptions { + type SortFn = (left: T, right: T) => number; + + interface QueryOptions { /** * A list of attributes to sort on, as well as direction * For example: @@ -30,7 +32,7 @@ declare namespace dojo { * If the sort parameter is omitted, then the natural order of the store may be * applied if there is a natural order. */ - sort?: SortInformation[]; + sort?: SortFn | SortInformation[]; /** * The first result to begin iteration on @@ -51,7 +53,7 @@ declare namespace dojo { type BaseQueryType = string | object | ((...params: unknown[]) => boolean); interface QueryEngine { - (query: Q, options?: O): QueryEngineFunction; + >(query: Q, options?: O): QueryEngineFunction; } interface PutDirectives { @@ -173,7 +175,7 @@ declare namespace dojo { interface Queryable< T extends object, Q extends BaseQueryType, - O extends QueryOptions, + O extends QueryOptions, R extends QueryResults = QueryResults> { /** @@ -183,7 +185,7 @@ declare namespace dojo { query(query?: Q, options?: O): R; } - interface SyncStore | ((item: T) => boolean) | string, O extends QueryOptions = QueryOptions> + interface SyncStore | ((item: T) => boolean) | string, O extends QueryOptions = QueryOptions> extends IdentityProvider, Queryable> { /** @@ -223,7 +225,7 @@ declare namespace dojo { } - interface AsyncStore | ((item: T) => boolean) | string, O extends QueryOptions = QueryOptions> + interface AsyncStore | ((item: T) => boolean) | string, O extends QueryOptions = QueryOptions> extends IdentityProvider, Queryable> { /** @@ -263,7 +265,7 @@ declare namespace dojo { } - interface HierarchicalStore = QueryResults> { + interface HierarchicalStore = QueryOptions, R extends QueryResults = QueryResults> { /** * Retrieves the children of an object. @@ -271,7 +273,7 @@ declare namespace dojo { getChildren(parent: T, options?: O): R; } - interface Store | ((item: T) => boolean) | string, O extends QueryOptions = QueryOptions> + interface Store | ((item: T) => boolean) | string, O extends QueryOptions = QueryOptions> extends IdentityProvider, Queryable { /** @@ -370,11 +372,11 @@ declare namespace dojo { interface DataStoreOptions { idProperty?: keyof T; - queryEngine?: api.QueryEngine; + queryEngine?: api.QueryEngine>; store?: data.api.Read | data.api.Write | data.api.Identity; } - interface DataStore extends api.Store { + interface DataStore extends api.Store> { /** * The object store to convert to a data store */ @@ -406,7 +408,7 @@ declare namespace dojo { timeout?: number } - interface JsonRestQueryOptions extends api.QueryOptions { + interface JsonRestQueryOptions extends api.QueryOptions { headers?: Headers; timeout?: number; @@ -414,7 +416,7 @@ declare namespace dojo { interface JsonRestOptions { idProperty?: keyof T; - queryEngine?: api.QueryEngine; + queryEngine?: api.QueryEngine>; headers?: Headers; target?: string; rangeParam?: string; @@ -427,7 +429,7 @@ declare namespace dojo { interface JsonRest< T extends object, Q extends api.BaseQueryType = (Partial | string) & api.BaseQueryType, - O extends JsonRestQueryOptions = JsonRestQueryOptions> + O extends JsonRestQueryOptions = JsonRestQueryOptions> extends api.AsyncStore { /** * Additional headers to pass in all requests to the server. These can be overridden @@ -509,7 +511,7 @@ declare namespace dojo { interface MemoryOptions { data?: T[]; idProperty?: keyof T; - queryEngine?: api.QueryEngine; + queryEngine?: api.QueryEngine>; setData?: (data: T[]) => void; } @@ -551,7 +553,7 @@ declare namespace dojo { type ObservableQueryResults = ObservableQueryResultsMixin & api.QueryResults; - interface ObservableMixin = api.QueryResults > { + interface ObservableMixin, R extends api.QueryResults = api.QueryResults > { notify(object: T, existingId?: api.Identity): void; /** diff --git a/dojo-typings/src/test/ts/StoreTests.ts b/dojo-typings/src/test/ts/StoreTests.ts --- a/dojo-typings/src/test/ts/StoreTests.ts +++ b/dojo-typings/src/test/ts/StoreTests.ts @@ -19,7 +19,8 @@ const mem = new Memory(); observable.query().observe(() => { }); store.query().forEach(() => { }); const total = await store.query().total; -const result = await store.query(); +const res1 = await store.query(undefined, { sort: [{ attribute: "duration", descending: true }] }); +const res2 = await store.query(undefined, { sort: ({ duration: a }, { duration: b }) => a - b }); mem.query();