diff --git a/shared-libs/cht-datasource/src/contact.ts b/shared-libs/cht-datasource/src/contact.ts index de03668a1f..921a96b4e8 100644 --- a/shared-libs/cht-datasource/src/contact.ts +++ b/shared-libs/cht-datasource/src/contact.ts @@ -34,17 +34,17 @@ export namespace v1 { readonly parent?: NormalizedParent; } - /** @internal */ + /** @ignore */ export const isNormalizedParent = (value: unknown): value is NormalizedParent => { return isDataObject(value) && isIdentifiable(value) && (!value.parent || isNormalizedParent(value.parent)); }; - /** @internal */ + /** @ignore */ export const isContactType = (value: ContactTypeQualifier | FreetextQualifier): value is ContactTypeQualifier => { return 'contactType' in value; }; - /** @internal */ + /** @ignore */ export const isFreetextType = (value: ContactTypeQualifier | FreetextQualifier): value is FreetextQualifier => { return 'freetext' in value; }; @@ -71,7 +71,7 @@ export namespace v1 { } }; - /** @internal */ + /** @ignore */ export const createQualifier = ( freetext: Nullable = null, type: Nullable = null @@ -151,9 +151,9 @@ export namespace v1 { * returned. Subsequent pages can be retrieved by providing the cursor returned with the previous page. * @param limit the maximum number of identifiers to return. Default is 10000. * @returns a page of contact identifiers for the provided specification - * @throws Error if no qualifier is provided or if the qualifier is invalid - * @throws Error if the provided `limit` value is `<=0` - * @throws Error if the provided cursor is not a valid page token or `null` + * @throws InvalidArrgumentError if no qualifier is provided or if the qualifier is invalid + * @throws InvalidArgumentError if the provided `limit` value is `<=0` + * @throws InvalidArgumentError if the provided cursor is not a valid page token or `null` */ const curriedFn = async ( qualifier: ContactTypeQualifier | FreetextQualifier, @@ -190,7 +190,7 @@ export namespace v1 { * Returns a generator for fetching all contact identifiers that match the given qualifier * @param qualifier the limiter defining which identifiers to return * @returns a generator for fetching all contact identifiers that match the given qualifier - * @throws Error if no qualifier is provided or if the qualifier is invalid + * @throws InvalidArgumentError if no qualifier is provided or if the qualifier is invalid */ const curriedGen = ( qualifier: ContactTypeQualifier | FreetextQualifier diff --git a/shared-libs/cht-datasource/src/index.ts b/shared-libs/cht-datasource/src/index.ts index 39b8b024b6..704c9ebe8c 100644 --- a/shared-libs/cht-datasource/src/index.ts +++ b/shared-libs/cht-datasource/src/index.ts @@ -59,13 +59,35 @@ export const getDatasource = (ctx: DataContext) => { hasPermissions, hasAnyPermission, contact: { - /** TODO */ + /** + * Returns a contact by their UUID. + * @param uuid the UUID of the contact to retrieve + * @returns the contact or `null` if no contact is found for the UUID + * @throws InvalidArgumentError if no UUID is provided + */ getByUuid: (uuid: string) => ctx.bind(Contact.v1.get)(Qualifier.byUuid(uuid)), - /** TODO */ + /** + * Returns a contact by their UUID along with the contact's parent lineage. + * @param uuid the UUID of the contact to retrieve + * @returns the contact or `null` if no contact is found the UUID + * @throws InvalidArgumentError if no UUID is provided + */ getByUuidWithLineage: (uuid: string) => ctx.bind(Contact.v1.getWithLineage)(Qualifier.byUuid(uuid)), - /** TODO */ + /** + * Returns an array of contact identifiers for the provided page specifications. + * @param freetext the search keyword(s) + * @param type the type of contact to search for + * @param cursor the token identifying which page to retrieve. A `null` value indicates the first page should be + * returned. Subsequent pages can be retrieved by providing the cursor returned with the previous page. + * @param limit the maximum number of identifiers to return. Default is 10000. + * @returns a page of contact identifiers for the provided specifications + * @throws InvalidArgumentError if either `freetext` or `type` is not provided + * @throws InvalidArgumentError if the `freetext` is empty or if the `type is invalid for a contact + * @throws InvalidArgumentError if the provided limit is `<= 0` + * @throws InvalidArgumentError if the provided cursor is not a valid page token or `null` + */ getIdsPage: ( freetext: Nullable = null, type: Nullable = null, @@ -75,7 +97,15 @@ export const getDatasource = (ctx: DataContext) => { Contact.v1.createQualifier(freetext, type), cursor, limit ), - /** TODO */ + /** + * Returns a generator for fetching all the contact identifiers for given + * `freetext` and `type`. + * @param freetext the search keyword(s) + * @param type the type of contact identifiers to return + * @returns a generator for fetching all the contact identifiers matching the given `freetext` and `type`. + * @throws InvalidArgumentError if either `freetext` or `type` is not provided + * @throws InvalidArgumentError if the `freetext` is empty or if the `type is invalid for a contact + */ getIds: ( freetext: Nullable = null, type: Nullable = null @@ -86,7 +116,7 @@ export const getDatasource = (ctx: DataContext) => { * Returns a place by its UUID. * @param uuid the UUID of the place to retrieve * @returns the place or `null` if no place is found for the UUID - * @throws Error if no UUID is provided + * @throws InvalidArgumentError if no UUID is provided */ getByUuid: (uuid: string) => ctx.bind(Place.v1.get)(Qualifier.byUuid(uuid)), @@ -94,7 +124,7 @@ export const getDatasource = (ctx: DataContext) => { * Returns a place by its UUID along with the place's parent lineage. * @param uuid the UUID of the place to retrieve * @returns the place or `null` if no place is found for the UUID - * @throws Error if no UUID is provided + * @throws InvalidArgumentError if no UUID is provided */ getByUuidWithLineage: (uuid: string) => ctx.bind(Place.v1.getWithLineage)(Qualifier.byUuid(uuid)), @@ -131,7 +161,7 @@ export const getDatasource = (ctx: DataContext) => { * Returns a person by their UUID. * @param uuid the UUID of the person to retrieve * @returns the person or `null` if no person is found for the UUID - * @throws Error if no UUID is provided + * @throws InvalidArgumentError if no UUID is provided */ getByUuid: (uuid: string) => ctx.bind(Person.v1.get)(Qualifier.byUuid(uuid)), @@ -139,7 +169,7 @@ export const getDatasource = (ctx: DataContext) => { * Returns a person by their UUID along with the person's parent lineage. * @param uuid the UUID of the person to retrieve * @returns the person or `null` if no person is found for the UUID - * @throws Error if no UUID is provided + * @throws InvalidArgumentError if no UUID is provided */ getByUuidWithLineage: (uuid: string) => ctx.bind(Person.v1.getWithLineage)(Qualifier.byUuid(uuid)), @@ -172,21 +202,44 @@ export const getDatasource = (ctx: DataContext) => { getByType: (personType: string) => ctx.bind(Person.v1.getAll)(Qualifier.byContactType(personType)), }, report: { - /** TODO */ + /** + * Returns a report by their UUID. + * @param uuid the UUID of the report to retrieve + * @returns the report or `null` if no report is found for the UUID + * @throws InvalidArgumentError if no UUID is provided + */ + // eslint-disable-next-line compat/compat getByUuid: (uuid: string) => ctx.bind(Report.v1.get)(Qualifier.byUuid(uuid)), - /** TODO */ + /** + * Returns a paged array of report identifiers from the given data context. + * @param qualifier the limiter defining which identifiers to return + * @param cursor the token identifying which page to retrieve. A `null` value indicates the first page should be + * returned. Subsequent pages can be retrieved by providing the cursor returned with the previous page. + * @param limit the maximum number of identifiers to return. Default is 10000. + * @returns a page of report identifiers for the provided specification + * @throws InvalidArgumentError if no qualifier is provided or if the qualifier is invalid + * @throws InvalidArgumentError if the provided `limit` value is `<=0` + * @throws InvalidArgumentError if the provided cursor is not a valid page token or `null` + */ getIdsPage: ( qualifier: string, cursor: Nullable = null, limit = 100 + // eslint-disable-next-line compat/compat ) => ctx.bind(Report.v1.getIdsPage)( Qualifier.byFreetext(qualifier), cursor, limit ), - /** TODO */ + /** + * Returns a generator for fetching all the contact identifiers for 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 InvalidArgumentError if no qualifier is provided or if the qualifier is invalid + */ getIds: ( qualifier: string, + // eslint-disable-next-line compat/compat ) => ctx.bind(Report.v1.getIdsAll)(Qualifier.byFreetext(qualifier)), }, }, diff --git a/shared-libs/cht-datasource/src/person.ts b/shared-libs/cht-datasource/src/person.ts index 789b7704c4..174baf9ef8 100644 --- a/shared-libs/cht-datasource/src/person.ts +++ b/shared-libs/cht-datasource/src/person.ts @@ -81,9 +81,9 @@ export namespace v1 { * returned. Subsequent pages can be retrieved by providing the cursor returned with the previous page. * @param limit the maximum number of people to return. Default is 100. * @returns a page of people for the provided specification - * @throws Error if no type is provided or if the type is not for a person - * @throws Error if the provided `limit` value is `<=0` - * @throws Error if the provided cursor is not a valid page token or `null` + * @throws InvalidArgumentError if no type is provided or if the type is not for a person + * @throws InvalidArgumentError if the provided `limit` value is `<=0` + * @throws InvalidArgumentError if the provided cursor is not a valid page token or `null` */ const curriedFn = async ( personType: ContactTypeQualifier, @@ -113,7 +113,7 @@ export namespace v1 { * Returns a generator for fetching all people with the given type * @param personType the type of people to return * @returns a generator for fetching all people with the given type - * @throws Error if no type is provided or if the type is not for a person + * @throws InvalidArgumentError if no type is provided or if the type is not for a person */ const curriedGen = (personType: ContactTypeQualifier): AsyncGenerator => { assertTypeQualifier(personType); diff --git a/shared-libs/cht-datasource/src/place.ts b/shared-libs/cht-datasource/src/place.ts index 8f55ee6e4c..ff599e17c4 100644 --- a/shared-libs/cht-datasource/src/place.ts +++ b/shared-libs/cht-datasource/src/place.ts @@ -7,6 +7,7 @@ import { adapt, assertDataContext, DataContext } from './libs/data-context'; import * as Local from './local'; import * as Remote from './remote'; import { assertCursor, assertLimit, assertTypeQualifier, getPagedGenerator, Nullable, Page } from './libs/core'; +import { InvalidArgumentError } from './libs/error'; /** */ export namespace v1 { @@ -29,7 +30,7 @@ export namespace v1 { const assertPlaceQualifier: (qualifier: unknown) => asserts qualifier is UuidQualifier = (qualifier: unknown) => { if (!isUuidQualifier(qualifier)) { - throw new Error(`Invalid identifier [${JSON.stringify(qualifier)}].`); + throw new InvalidArgumentError(`Invalid identifier [${JSON.stringify(qualifier)}].`); } }; @@ -80,9 +81,9 @@ export namespace v1 { * returned. Subsequent pages can be retrieved by providing the cursor returned with the previous page. * @param limit the maximum number of places to return. Default is 100. * @returns a page of places for the provided specification - * @throws Error if no type is provided or if the type is not for a place - * @throws Error if the provided `limit` value is `<=0` - * @throws Error if the provided cursor is not a valid page token or `null` + * @throws InvalidArgumentError if no type is provided or if the type is not for a place + * @throws InvalidArgumentError if the provided `limit` value is `<=0` + * @throws InvalidArgumentError if the provided cursor is not a valid page token or `null` */ const curriedFn = async ( placeType: ContactTypeQualifier, @@ -112,7 +113,7 @@ export namespace v1 { * Returns a generator for fetching all places with the given type * @param placeType the type of places to return * @returns a generator for fetching all places with the given type - * @throws Error if no type is provided or if the type is not for a place + * @throws InvaidArgumentError if no type is provided or if the type is not for a place */ const curriedGen = (placeType: ContactTypeQualifier) => { assertTypeQualifier(placeType); diff --git a/shared-libs/cht-datasource/src/report.ts b/shared-libs/cht-datasource/src/report.ts index 958b496988..017f772b5d 100644 --- a/shared-libs/cht-datasource/src/report.ts +++ b/shared-libs/cht-datasource/src/report.ts @@ -74,9 +74,9 @@ export namespace v1 { * returned. Subsequent pages can be retrieved by providing the cursor returned with the previous page. * @param limit the maximum number of identifiers to return. Default is 10000. * @returns a page of report identifiers for the provided specification - * @throws Error if no qualifier is provided or if the qualifier is invalid - * @throws Error if the provided `limit` value is `<=0` - * @throws Error if the provided cursor is not a valid page token or `null` + * @throws InvalidArgumentError if no qualifier is provided or if the qualifier is invalid + * @throws InvalidArgumentError if the provided `limit` value is `<=0` + * @throws InvalidArgumentError if the provided cursor is not a valid page token or `null` */ const curriedFn = async ( qualifier: FreetextQualifier, @@ -106,7 +106,7 @@ export namespace v1 { * 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 + * @throws InvalidArgumentError if no qualifier is provided or if the qualifier is invalid */ const curriedGen = ( qualifier: FreetextQualifier