diff --git a/shared-libs/cht-datasource/src/index.ts b/shared-libs/cht-datasource/src/index.ts index b40464ed04..39b8b024b6 100644 --- a/shared-libs/cht-datasource/src/index.ts +++ b/shared-libs/cht-datasource/src/index.ts @@ -183,6 +183,11 @@ export const getDatasource = (ctx: DataContext) => { ) => ctx.bind(Report.v1.getIdsPage)( Qualifier.byFreetext(qualifier), cursor, limit ), + + /** TODO */ + getIds: ( + qualifier: string, + ) => ctx.bind(Report.v1.getIdsAll)(Qualifier.byFreetext(qualifier)), }, }, }; diff --git a/shared-libs/cht-datasource/src/report.ts b/shared-libs/cht-datasource/src/report.ts index 05420daebb..958b496988 100644 --- a/shared-libs/cht-datasource/src/report.ts +++ b/shared-libs/cht-datasource/src/report.ts @@ -1,4 +1,12 @@ -import { assertCursor, assertFreetextQualifier, assertLimit, DataObject, Nullable, Page } from './libs/core'; +import { + assertCursor, + assertFreetextQualifier, + assertLimit, + DataObject, + getPagedGenerator, + Nullable, + Page +} from './libs/core'; import { adapt, assertDataContext, DataContext } from './libs/data-context'; import { Doc } from './libs/doc'; import { InvalidArgumentError } from './libs/error'; @@ -83,4 +91,30 @@ export namespace v1 { }; return curriedFn; }; + + /** + * Returns a function for getting a generator that fetches report identifiers from the given data context. + * @param context the current data context + * @returns a function for getting a generator that fetches report identifiers + * @throws Error if a data context is not provided + */ + export const getIdsAll = (context: DataContext): typeof curriedGen => { + assertDataContext(context); + const getPage = context.bind(v1.getIdsPage); + + /** + * Returns a generator for fetching all report identifiers that match the given qualifier + * @param qualifier the limiter defining which identifiers to return + * @returns a generator for fetching all report identifiers that match the given qualifier + * @throws Error if no qualifier is provided or if the qualifier is invalid + */ + const curriedGen = ( + qualifier: FreetextQualifier + ): AsyncGenerator => { + assertFreetextQualifier(qualifier); + + return getPagedGenerator(getPage, qualifier); + }; + return curriedGen; + }; }