Skip to content

Commit

Permalink
add async API Report.v1.getIds
Browse files Browse the repository at this point in the history
  • Loading branch information
sugat009 committed Nov 15, 2024
1 parent 192af16 commit bb98dcf
Show file tree
Hide file tree
Showing 2 changed files with 40 additions and 1 deletion.
5 changes: 5 additions & 0 deletions shared-libs/cht-datasource/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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)),
},
},
};
Expand Down
36 changes: 35 additions & 1 deletion shared-libs/cht-datasource/src/report.ts
Original file line number Diff line number Diff line change
@@ -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';
Expand Down Expand Up @@ -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<string, null> => {
assertFreetextQualifier(qualifier);

return getPagedGenerator(getPage, qualifier);
};
return curriedGen;
};
}

0 comments on commit bb98dcf

Please sign in to comment.