Skip to content

Commit

Permalink
fhir-ndr-et: fix typings (#812)
Browse files Browse the repository at this point in the history
* fhir-ndr-et: maybe fix ts build

* fhir-ndr-et: version bump

* remove log line

* revert unbused build change

* tools: fix build

* check in types and dont' clean them

* check in types

* tweak build stuff

* remove atutogen disclaimer
  • Loading branch information
josephjclark authored Nov 3, 2024
1 parent ed4f006 commit f465188
Show file tree
Hide file tree
Showing 13 changed files with 68 additions and 17 deletions.
3 changes: 2 additions & 1 deletion packages/fhir-ndr-et/.gitignore
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
spec/
spec/
!types
2 changes: 2 additions & 0 deletions packages/fhir-ndr-et/.prettierignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
types
src/builders.js
6 changes: 6 additions & 0 deletions packages/fhir-ndr-et/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,11 @@
# @openfn/language-fhir-ndr-et

## 0.1.7

### Patch Changes

- Fix typescript definitions

## 0.1.6

- Updated docs for each()
Expand Down
3 changes: 3 additions & 0 deletions packages/fhir-ndr-et/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.

Expand Down
29 changes: 20 additions & 9 deletions packages/fhir-ndr-et/build/build.ts
Original file line number Diff line number Diff line change
@@ -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';
Expand Down Expand Up @@ -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();
6 changes: 3 additions & 3 deletions packages/fhir-ndr-et/package.json
Original file line number Diff line number Diff line change
@@ -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": {
Expand All @@ -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"
},
Expand Down
2 changes: 1 addition & 1 deletion packages/fhir-ndr-et/src/Adaptor.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);

/**
Expand Down
2 changes: 2 additions & 0 deletions packages/fhir-ndr-et/types/Adaptor.d.ts
Original file line number Diff line number Diff line change
@@ -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";
File renamed without changes.
File renamed without changes.
4 changes: 4 additions & 0 deletions packages/fhir-ndr-et/types/index.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
import './builders';
export * as util from './utils';
export * as builders from './builders';
export * as b from './builders';
21 changes: 21 additions & 0 deletions packages/fhir-ndr-et/types/utils.d.ts
Original file line number Diff line number Diff line change
@@ -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;
7 changes: 4 additions & 3 deletions tools/build/src/cli.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,15 +7,16 @@ import run from './pipeline';

export const cmd = yargs(hideBin(process.argv))
.command(
'$0 <lang> [tasks]',
'$0 <lang> [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,
Expand All @@ -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'];
}

Expand Down

0 comments on commit f465188

Please sign in to comment.