diff --git a/packages/fhir-ndr-et/.gitignore b/packages/fhir-ndr-et/.gitignore index c785c3796..ad69f66f9 100644 --- a/packages/fhir-ndr-et/.gitignore +++ b/packages/fhir-ndr-et/.gitignore @@ -1 +1,2 @@ -spec/ \ No newline at end of file +spec/ +!types \ No newline at end of file diff --git a/packages/fhir-ndr-et/.prettierignore b/packages/fhir-ndr-et/.prettierignore new file mode 100644 index 000000000..0411e7253 --- /dev/null +++ b/packages/fhir-ndr-et/.prettierignore @@ -0,0 +1,2 @@ +types +src/builders.js \ No newline at end of file diff --git a/packages/fhir-ndr-et/CHANGELOG.md b/packages/fhir-ndr-et/CHANGELOG.md index 6a500bea7..8b5a3ef19 100644 --- a/packages/fhir-ndr-et/CHANGELOG.md +++ b/packages/fhir-ndr-et/CHANGELOG.md @@ -1,5 +1,11 @@ # @openfn/language-fhir-ndr-et +## 0.1.7 + +### Patch Changes + +- Fix typescript definitions + ## 0.1.6 - Updated docs for each() diff --git a/packages/fhir-ndr-et/README.md b/packages/fhir-ndr-et/README.md index c47632a47..3dd1a5b52 100644 --- a/packages/fhir-ndr-et/README.md +++ b/packages/fhir-ndr-et/README.md @@ -13,6 +13,9 @@ We **strongly** recommend not editing generated source files by hand! Better to update the spec, mappings, or code generation rules. Otherwise your changes will be lost. +Unlike most adaptors, types are checked-in (because they are largely +autogenerated). A custom dts build is used. + View the [docs site](https://docs.openfn.org/adaptors/packages/fhir-ndr-et-docs) for full technical documentation. diff --git a/packages/fhir-ndr-et/build/build.ts b/packages/fhir-ndr-et/build/build.ts index f602b85a7..01a3d8025 100644 --- a/packages/fhir-ndr-et/build/build.ts +++ b/packages/fhir-ndr-et/build/build.ts @@ -1,4 +1,7 @@ +import path from 'node:path'; import { access, readFile, writeFile, mkdir } from 'node:fs/promises'; +import { exec } from 'node:child_process'; + import generateSchema from './generate-schema'; import generateDTS from './generate-dts'; import generateCode from './generate-code'; @@ -27,16 +30,24 @@ const generate = async () => { await mkdir('dist', { recursive: true }); await mkdir('types', { recursive: true }); - await writeFile('src/builders.d.ts', withDisclaimer(dts)); - await writeFile('types/builders.d.ts', withDisclaimer(dts)); - + await writeFile('src/builders.js', withDisclaimer(src)); + + const args = [ + '--allowJs', + '--declaration', + '--emitDeclarationOnly', + '--lib es2020', + `--declarationDir ${path.resolve('types')}`, + ]; + + // Now build typings for index and utils + exec(`pnpm exec tsc ${args.join(' ')} src/index.ts`, {}, () => { + setTimeout(async () => { + // Overwrite builders.d.ts because typescript makes a mess of it + await writeFile('types/builders.d.ts', withDisclaimer(dts)); + }, 500) + }); - // tbh this code is on the wrong place - just need to get this working! - const globals = await readFile('src/globals.d.ts', 'utf8'); - await writeFile('types/globals.d.ts', withDisclaimer(globals)); - - // const utils = await readFile('src/utils.d.ts', 'utf8'); - // await writeFile('types/utils.d.ts', withDisclaimer(utils)); }; generate(); diff --git a/packages/fhir-ndr-et/package.json b/packages/fhir-ndr-et/package.json index 90b42c2c5..3b4f18b5b 100644 --- a/packages/fhir-ndr-et/package.json +++ b/packages/fhir-ndr-et/package.json @@ -1,6 +1,6 @@ { "name": "@openfn/language-fhir-ndr-et", - "version": "0.1.6", + "version": "0.1.7", "description": "OpenFn fhir adaptor for NDR HIV in Ehtiopia", "type": "module", "exports": { @@ -20,14 +20,14 @@ "./package.json": "./package.json" }, "scripts": { - "build": "pnpm clean && pnpm build-adaptor fhir-ndr-et", + "build": "pnpm clean && pnpm build-adaptor fhir-ndr-et src ast docs", "build:src": "esno build/build.ts", "build:adaptor": "pnpm build-adaptor fhir-ndr-et", "build:schema": "esno build/generate-schema.ts", "load-schema": "esno build/fetch-schema.ts", "test": "mocha --experimental-specifier-resolution=node --no-warnings", "test:watch": "mocha -w --experimental-specifier-resolution=node --no-warnings", - "clean": "rimraf dist types docs", + "clean": "rimraf dist docs", "pack": "pnpm pack --pack-destination ../../dist", "lint": "eslint src" }, diff --git a/packages/fhir-ndr-et/src/Adaptor.js b/packages/fhir-ndr-et/src/Adaptor.js index 27cf3435f..f14beed6a 100644 --- a/packages/fhir-ndr-et/src/Adaptor.js +++ b/packages/fhir-ndr-et/src/Adaptor.js @@ -5,7 +5,7 @@ import * as util from './utils'; // @ts-ignore import * as builders from './builders'; -export const getBuilderName = resourceName => +const getBuilderName = resourceName => resourceName[0].toLowerCase() + resourceName.slice(1); /** diff --git a/packages/fhir-ndr-et/types/Adaptor.d.ts b/packages/fhir-ndr-et/types/Adaptor.d.ts new file mode 100644 index 000000000..634feef7f --- /dev/null +++ b/packages/fhir-ndr-et/types/Adaptor.d.ts @@ -0,0 +1,2 @@ +export function create(resourceType: FhirResourceTypes, resource: FhirResource, params: object, callback?: Function): Operation; +export { dataPath, dataValue, cursor, each, field, fields, fn, lastReferenceValue, merge, sourceValue } from "@openfn/language-common"; diff --git a/packages/fhir-ndr-et/src/builders.d.ts b/packages/fhir-ndr-et/types/builders.d.ts similarity index 100% rename from packages/fhir-ndr-et/src/builders.d.ts rename to packages/fhir-ndr-et/types/builders.d.ts diff --git a/packages/fhir-ndr-et/src/globals.d.ts b/packages/fhir-ndr-et/types/globals.d.ts similarity index 100% rename from packages/fhir-ndr-et/src/globals.d.ts rename to packages/fhir-ndr-et/types/globals.d.ts diff --git a/packages/fhir-ndr-et/types/index.d.ts b/packages/fhir-ndr-et/types/index.d.ts new file mode 100644 index 000000000..a0ee975e2 --- /dev/null +++ b/packages/fhir-ndr-et/types/index.d.ts @@ -0,0 +1,4 @@ +import './builders'; +export * as util from './utils'; +export * as builders from './builders'; +export * as b from './builders'; diff --git a/packages/fhir-ndr-et/types/utils.d.ts b/packages/fhir-ndr-et/types/utils.d.ts new file mode 100644 index 000000000..c7eb0238d --- /dev/null +++ b/packages/fhir-ndr-et/types/utils.d.ts @@ -0,0 +1,21 @@ +export function mapSystems(obj: any): any; +export function setSystemMap(newMappings: any): void; +export function identifier(input: any, system?: string): any; +export function id(input: any, system?: string): any; +export function addExtension(resource: any, url: string, value: any): void; +export function findExtension(obj: any, targetUrl: string, path?: string): any; +export function coding(code: string, system: string): { + code: string; + system: any; +}; +export function concept(text: any, ...codings: any[]): { + text: string; + coding: any[]; +}; +export function cc(text: any, ...codings: any[]): { + text: string; + coding: any[]; +}; +export function reference(ref: any, opts: any): any; +export function ref(ref: any, opts: any): any; +export function composite(object: any, key: string, value: any): void; diff --git a/tools/build/src/cli.ts b/tools/build/src/cli.ts index a486b59ab..2e968d11b 100755 --- a/tools/build/src/cli.ts +++ b/tools/build/src/cli.ts @@ -7,15 +7,16 @@ import run from './pipeline'; export const cmd = yargs(hideBin(process.argv)) .command( - '$0 [tasks]', + '$0 [tasks...]', 'Build an adaptor. You must pass in the adaptor name, and you may pass a list of build steps.' ) .example('$0 http', 'build everything for http') .example('$0 http src ast', 'run src and ast builds for http') .demand('lang') - .option('tasks', { + .positional('tasks', { array: true, description: 'src, ast, docs, dts', + default: [], }) .option('watch', { boolean: true, @@ -24,7 +25,7 @@ export const cmd = yargs(hideBin(process.argv)) }) .parse(); -if (!cmd.tasks) { +if (!cmd.tasks.length) { cmd.tasks = ['src', 'dts', 'docs', 'ast']; }