Skip to content

Commit d081f00

Browse files
committed
[types] SortedRowIdsArgs
1 parent 1d7155e commit d081f00

File tree

4 files changed

+84
-25
lines changed

4 files changed

+84
-25
lines changed

src/@types/store/docs.js

Lines changed: 47 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -526,6 +526,50 @@
526526
* @since v1.0.0
527527
*/
528528
/// DoRollback
529+
/**
530+
* The SortedRowIdsArgs type describes the arguments used to sort Row Ids using
531+
* the getSortedRowIds method.
532+
*
533+
* It's an object containing the Id of the Table in the Store, and optional
534+
* `cellId`, `descending`, `offset`, and `limit` parameters. See the
535+
* getSortedRowIds method for specific examples.
536+
* @category Store
537+
* @since v6.1.0
538+
*/
539+
/// SortedRowIdsArgs
540+
{
541+
/**
542+
* The Id of the Table in the Store, required.
543+
* @category Argument
544+
* @since v6.1.0
545+
*/
546+
/// SortedRowIdsArgs.tableId
547+
/**
548+
* The optional Id of the Cell whose values are used for the sorting, defaults
549+
* to sorting by the Row Id itself.
550+
* @category Argument
551+
* @since v6.1.0
552+
*/
553+
/// SortedRowIdsArgs.cellId
554+
/**
555+
* Whether the sorting should be in descending order, defaulting to false.
556+
* @category Argument
557+
* @since v6.1.0
558+
*/
559+
/// SortedRowIdsArgs.descending
560+
/**
561+
* The number of Row Ids to skip for pagination purposes, defaulting to 0.
562+
* @category Argument
563+
* @since v6.1.0
564+
*/
565+
/// SortedRowIdsArgs.offset
566+
/**
567+
* The maximum number of Row Ids to return, defaulting to all.
568+
* @category Argument
569+
* @since v6.1.0
570+
*/
571+
/// SortedRowIdsArgs.limit
572+
}
529573
/**
530574
* The TransactionListener type describes a function that is used to listen to
531575
* the completion of a transaction for the Store.
@@ -1977,8 +2021,9 @@
19772021
/**
19782022
* When called with one object argument, the getSortedRowIds method
19792023
* destructures it to make it easier to skip optional parameters.
1980-
* @param args An object containing the Id of the Table in the Store, and
1981-
* optional `cellId`, `descending`, `offset`, and `limit` parameters.
2024+
* @param args A SortedRowIdsArgs object containing the Id of the Table in the
2025+
* Store, and optional `cellId`, `descending`, `offset`, and `limit`
2026+
* parameters.
19822027
* @returns An array of the sorted Ids of appropriate Rows in the Table.
19832028
* @example
19842029
* This example retrieves the first sorted Row Id in a Table.

src/@types/store/index.d.ts

Lines changed: 15 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -115,6 +115,20 @@ export type ChangedValueIds = {[valueId: Id]: IdAddedOrRemoved};
115115
/// DoRollback
116116
export type DoRollback = (store: Store) => boolean;
117117

118+
/// SortedRowIdsArgs
119+
export type SortedRowIdsArgs = {
120+
/// SortedRowIdsArgs.tableId
121+
tableId: Id;
122+
/// SortedRowIdsArgs.cellId
123+
cellId?: Id;
124+
/// SortedRowIdsArgs.descending
125+
descending?: boolean;
126+
/// SortedRowIdsArgs.offset
127+
offset?: number;
128+
/// SortedRowIdsArgs.limit
129+
limit?: number;
130+
};
131+
118132
/// TransactionListener
119133
export type TransactionListener<Store extends StoreAlias = StoreAlias> = (
120134
store: Store,
@@ -445,13 +459,7 @@ export interface Store {
445459
): Ids;
446460

447461
/// Store.getSortedRowIds.2
448-
getSortedRowIds(args: {
449-
tableId: Id;
450-
cellId?: Id;
451-
descending?: boolean;
452-
offset?: number;
453-
limit?: number;
454-
}): Ids;
462+
getSortedRowIds(args: SortedRowIdsArgs): Ids;
455463

456464
/// Store.getRow
457465
getRow(tableId: Id, rowId: Id): Row;

src/@types/store/with-schemas/index.d.ts

Lines changed: 20 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -295,6 +295,23 @@ export type DoRollback<Schemas extends OptionalSchemas> = (
295295
store: Store<Schemas>,
296296
) => boolean;
297297

298+
/// SortedRowIdsArgs
299+
export type SortedRowIdsArgs<
300+
Schema extends OptionalTablesSchema,
301+
TableId extends TableIdFromSchema<Schema> = TableIdFromSchema<Schema>,
302+
> = {
303+
/// SortedRowIdsArgs.tableId
304+
tableId: TableId;
305+
/// SortedRowIdsArgs.cellId
306+
cellId?: CellIdFromSchema<Schema, TableId>;
307+
/// SortedRowIdsArgs.descending
308+
descending?: boolean;
309+
/// SortedRowIdsArgs.offset
310+
offset?: number;
311+
/// SortedRowIdsArgs.limit
312+
limit?: number;
313+
};
314+
298315
/// TransactionListener
299316
export type TransactionListener<
300317
Schemas extends OptionalSchemas,
@@ -942,13 +959,9 @@ export interface Store<in out Schemas extends OptionalSchemas> {
942959
): Ids;
943960

944961
/// Store.getSortedRowIds.2
945-
getSortedRowIds<TableId extends TableIdFromSchema<Schemas[0]>>(args: {
946-
tableId: TableId;
947-
cellId?: CellIdFromSchema<Schemas[0], TableId>;
948-
descending?: boolean;
949-
offset?: number;
950-
limit?: number;
951-
}): Ids;
962+
getSortedRowIds<TableId extends TableIdFromSchema<Schemas[0]>>(
963+
args: SortedRowIdsArgs<Schemas[0], TableId>,
964+
): Ids;
952965

953966
/// Store.getRow
954967
getRow<TableId extends TableIdFromSchema<Schemas[0]>>(

src/store/index.ts

Lines changed: 2 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ import type {
1616
MapCell,
1717
Row,
1818
RowCallback,
19+
SortedRowIdsArgs,
1920
SortedRowIdsListener,
2021
Store,
2122
StoreListenerStats,
@@ -1012,15 +1013,7 @@ export const createStore: typeof createStoreDecl = (): Store => {
10121013
mapKeys(mapGet(tablesMap, id(tableId)));
10131014

10141015
const getSortedRowIds = (
1015-
tableId:
1016-
| Id
1017-
| {
1018-
tableId: Id;
1019-
cellId?: Id;
1020-
descending?: boolean;
1021-
offset?: number;
1022-
limit?: number;
1023-
},
1016+
tableId: Id | SortedRowIdsArgs,
10241017
cellId?: Id,
10251018
descending?: boolean,
10261019
offset = 0,

0 commit comments

Comments
 (0)