Type of the items, inferred from the reader.
Record of the extensions by key, inferred from extensions.
Resolves the payload into the items; receives the signal of the read as second argument.
Extensions by key, run in this order; {} for none.
the data source, typed with the extensions of the record.
const users = createDataSource(readUsers, { filtering, pagination, distinct });
// IDataSource<User, { filtering: FilterExtension<User>; pagination: PaginationExtension<User>; distinct: DistinctExtension<User> }>
users.filtering.addFilter(adult);
users.distinct; // a custom key, typed
const maybeSorting: SortExtension<User> | undefined = options.sortable
? new SortExtension<User>()
: undefined;
const products = createDataSource(readProducts, { filtering, sorting: maybeSorting });
products.sorting; // SortExtension<User> | undefined: a value that may be undefined is optional
Builds a data source whose type carries its extensions: the record given here, key by key (IDataSource). It is the way to build a source: the DataSource class behind it cannot type its members from a generic record, so
new DataSource(reader, { filtering })exposes no key in its type. The class is exported to be extended, by a subclass that declares its keys.The extensions run in the order of the keys of the record, the order you write them in:
filteringbeforepagination, so the count reader receives the filters.