chore(#10224): include docs for Datasource in site#11108
Conversation
|
@sugat009 please do not fear the line-count on this PR! 😅 🙏 I promise it is almost entirely just a very "basic" refactor of how we structure the Datasource code/docs in cht-datasource. (Not really any complexity.) All the details about the changes are up in the description... 👍 |
sugat009
left a comment
There was a problem hiding this comment.
Requesting changes since several findings affect docs site rendering (typos, missing examples on entry point pages, unclosed backticks merging @throws clauses). The rest are advisory questions and nitpicks.
Also worth fixing while you're cleaning up docs (already on master, small enough to bundle in this PR):
InvalidArrgumentErrortypo (extrar) atshared-libs/cht-datasource/src/contact.ts:103andshared-libs/cht-datasource/src/target.ts:121. Should beInvalidArgumentError.
Noticed while reviewing, flagging for awareness (not asks for this PR):
- Cyclic import between
shared-libs/cht-datasource/src/person.ts:6andshared-libs/cht-datasource/src/place.ts:2(lineage types reference each other; the cycle is purely at the type layer, soimport typewould break it). return await fn(qualifier)atshared-libs/cht-datasource/src/report.ts:204is the onlyreturn awaitin the curried functions; the rest of the area usesreturn fn(qualifier).
| * @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 |
There was a problem hiding this comment.
issue: The closing backtick after type is missing on this @throws line. The unclosed code span runs forward through the subsequent @throws lines until the next backtick (in `<=0`), merging multiple throw clauses into one garbled <code>-wrapped paragraph in the rendered docs.
| * @throws InvalidArgumentError if the `freetext` is empty or if the `type is invalid for a contact | |
| * @throws InvalidArgumentError if the `freetext` is empty or if the `type` is invalid for a contact |
Same pattern at three other locations in this file:
shared-libs/cht-datasource/src/contact.ts:195shared-libs/cht-datasource/src/contact.ts:229shared-libs/cht-datasource/src/contact.ts:238
Worth catching here since --treatWarningsAsErrors was just enabled on gen-docs in package.json:14 and the merged rendering is visible on the generated Contact.v1.Datasource.html page (getUuidsPageByFreetext and getUuidsPageByTypeFreetext properties).
| * @throws Error if the provided context is invalid | ||
| */ | ||
| export const getDatasource = (ctx: DataContext) => { | ||
| export const getDatasource = (ctx: DataContext): Datasource => { |
There was a problem hiding this comment.
question (non-blocking): Is it intentional that the published docs site has no usage examples on the getDatasource or Datasource pages now?
The three @example blocks moved from index.ts to the README, and gen-docs now runs with --readme none (package.json:14), so TypeDoc no longer renders those examples anywhere on the docs site.
If unintentional, would it be worth adding back at least the imperative example as an @example on getDatasource so visitors landing on the docs site entry point still see a usage snippet?
| export * as Report from './report'; | ||
| export * as Target from './target'; | ||
|
|
||
| /** |
There was a problem hiding this comment.
suggestion (non-blocking): Worth expanding this JSDoc to match the doc style of the other public interfaces in cht-datasource (DataContext and SettingsService in libs/data-context.ts both carry multi sentence descriptions explaining what they represent and how they're meant to be used).
Since this interface is the new docs site entry point, a few extra sentences here would give visitors landing on the Datasource page actual orientation. Something like:
/**
* The CHT datasource API. Provides access to the CHT data model through versioned
* sub APIs (e.g. `v1.person`, `v1.place`). Obtain an instance via {@link getDatasource}.
*/| */ | ||
| export type DataValue = DataPrimitive | DataArray | DataObject; | ||
| /** | ||
| * A privative value. |
There was a problem hiding this comment.
| * A privative value. | |
| * A primitive value. |
| /** | ||
| * The intersection of the specified types. | ||
| */ | ||
| export type UnionToIntersection<U> = ( |
There was a problem hiding this comment.
suggestion (non-blocking): UnionToIntersection is a TypeScript utility helper rather than part of the data model. Now that qualifier.ts is re-exported as Qualifier from the package root, this lands on the public surface as Qualifier.UnionToIntersection. Consider marking @internal so --excludeInternal strips it from the docs site.
/**
* The intersection of the specified types.
* @internal
*/| .map(opts => tsj.createGenerator(opts)) | ||
| .map(generator => generator.createSchema()) | ||
| .map(({ definitions }) => ({ ...definitions, '*': undefined })) | ||
| .map(({ definitions }) => ({ ...definitions, ...SCHEMAS_TO_SKIP })) |
There was a problem hiding this comment.
| .map(({ definitions }) => ({ ...definitions, ...SCHEMAS_TO_SKIP })) | |
| .map(({ definitions }) => ({ ...definitions, ...SCHEMAS_TO_SKIP })) |
Description
This is a bit of prep work ahead of #10224 being resolved. When UI Extensions are released, that will be the official first time these cht-datasource APIs are actually available/useful for external configuration code (since the custom UI Extensions have access to the APIs and can leverage the
asyncfunctionality! Access to these APIs is provided by injecting the result of getDatasource into the extensions atthis.cht.However, as you can see by looking at the docs in the link, we do not actually have very clean documentation for the imperative cht-datasource APIs. The function-level TS doc is not even pulled through into the docs site. 😞 This is because we have not really defined the returned "Datasource" as a formal type/interface (but it is just a return type).
The main goal of this PR is to add proper documentation for a
Datasourceinterface that gets included in the docs site. This involved several changes:Datasourceinterface to hold the documentation. ThegetDatasourcefunction returns this type.Datasourceinterfaces along with their own internalgetDatasourcefunctions and moved the code into the related files. Everything still rolls back up through the top-levelDatasource, but this is way more maintainable and scalable.@packageDocumentationannotation in theindex.tsfile to make that file's docs the entry-point for the cht-datasource docs site.Datasourceinterface, which is what most folks care about).generate-openapi.jsscript because the newDatasourceinterface is, of course, not referenced in any of our OpenAPI docs (as expected). The unreferenced schema was causing the OpenAPI json generation to fail.AI Disclosure
Claude was super useful for producing/implementing the
Datasourceinterfaces. However, if you look at my first commit, you can see that it has all these changes but leaves the unit tests totally untouched (and they still pass). This gave me high confidence that migration was properly executed.Beyond that, pretty much all of the other minor docs changes, etc are my own doing.
Code review checklist
License
The software is provided under AGPL-3.0. Contributions to this project are accepted under the same license.