babelfhir-ts 1.0.39 → 1.0.41
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
|
@@ -32,6 +32,8 @@ export function generateClient(options) {
|
|
|
32
32
|
generateSmartClient(clientDir, resourceTypes);
|
|
33
33
|
generateIndex(clientDir, resourceTypes);
|
|
34
34
|
generateReadme(clientDir);
|
|
35
|
+
// Install base client type declarations so tsc can resolve @babelfhir-ts/client-r4
|
|
36
|
+
installBaseClientTypes(options.outputDir);
|
|
35
37
|
log.success(`Generated FHIR client with ${resourceTypes.length} resource types + SMART auth`);
|
|
36
38
|
}
|
|
37
39
|
/**
|
|
@@ -525,64 +527,50 @@ export function parseBundle(bundle: Bundle<FhirResource>): BundleParser {
|
|
|
525
527
|
* Generate fhir-client.ts
|
|
526
528
|
*/
|
|
527
529
|
function generateFhirClient(clientDir, resourceTypes) {
|
|
528
|
-
const readerImports = resourceTypes
|
|
529
|
-
.map((rt) => ` type ${rt.profileName}Reader,`)
|
|
530
|
-
.join("\n");
|
|
531
|
-
const writerImports = resourceTypes
|
|
532
|
-
.map((rt) => ` type ${rt.profileName}Writer,`)
|
|
533
|
-
.join("\n");
|
|
534
530
|
const readerMethods = resourceTypes
|
|
535
531
|
.map((rt) => {
|
|
536
532
|
const methodName = rt.profileName.charAt(0).toLowerCase() + rt.profileName.slice(1);
|
|
537
|
-
return ` ${methodName}()
|
|
538
|
-
return
|
|
533
|
+
return ` ${methodName}() {
|
|
534
|
+
return this.forType<GeneratedTypes.${rt.profileName}>("${rt.baseResourceType}");
|
|
539
535
|
}`;
|
|
540
536
|
})
|
|
541
537
|
.join("\n\n");
|
|
542
538
|
const writerMethods = resourceTypes
|
|
543
539
|
.map((rt) => {
|
|
544
540
|
const methodName = rt.profileName.charAt(0).toLowerCase() + rt.profileName.slice(1);
|
|
545
|
-
return ` ${methodName}()
|
|
546
|
-
return
|
|
541
|
+
return ` ${methodName}() {
|
|
542
|
+
return this.forType<GeneratedTypes.${rt.profileName}>("${rt.baseResourceType}");
|
|
547
543
|
}`;
|
|
548
544
|
})
|
|
549
545
|
.join("\n\n");
|
|
550
546
|
const content = `import {
|
|
551
|
-
|
|
552
|
-
|
|
547
|
+
FhirReadClient as BaseFhirReadClient,
|
|
548
|
+
FhirWriteClient as BaseFhirWriteClient,
|
|
553
549
|
type FetchFn,
|
|
554
|
-
} from "
|
|
555
|
-
import
|
|
556
|
-
${writerImports}
|
|
557
|
-
FhirResourceWriterImpl,
|
|
558
|
-
} from "./resource-writer.js";
|
|
550
|
+
} from "@babelfhir-ts/client-r4";
|
|
551
|
+
import type * as GeneratedTypes from "../index.js";
|
|
559
552
|
|
|
560
553
|
/**
|
|
561
|
-
* FHIR Client
|
|
554
|
+
* Profile-specific FHIR Read Client.
|
|
555
|
+
* Extends the base R4 read client with typed profile accessors.
|
|
556
|
+
* Inherits all base R4 resource methods from @babelfhir-ts/client-r4.
|
|
562
557
|
*/
|
|
563
|
-
export class FhirReadClient {
|
|
564
|
-
constructor(
|
|
565
|
-
private readonly baseUrl: string,
|
|
566
|
-
private readonly fetchFn?: FetchFn,
|
|
567
|
-
) {}
|
|
568
|
-
|
|
558
|
+
export class FhirReadClient extends BaseFhirReadClient {
|
|
569
559
|
${readerMethods}
|
|
570
560
|
}
|
|
571
561
|
|
|
572
562
|
/**
|
|
573
|
-
* FHIR Client
|
|
563
|
+
* Profile-specific FHIR Write Client.
|
|
564
|
+
* Extends the base R4 write client with typed profile accessors.
|
|
565
|
+
* Inherits all base R4 resource methods from @babelfhir-ts/client-r4.
|
|
574
566
|
*/
|
|
575
|
-
export class FhirWriteClient {
|
|
576
|
-
constructor(
|
|
577
|
-
private readonly baseUrl: string,
|
|
578
|
-
private readonly fetchFn?: FetchFn,
|
|
579
|
-
) {}
|
|
580
|
-
|
|
567
|
+
export class FhirWriteClient extends BaseFhirWriteClient {
|
|
581
568
|
${writerMethods}
|
|
582
569
|
}
|
|
583
570
|
|
|
584
571
|
/**
|
|
585
572
|
* Main FHIR Client — works with plain fetch or an authenticated fetch wrapper.
|
|
573
|
+
* Provides both base R4 accessors (inherited) and profile-specific accessors.
|
|
586
574
|
*
|
|
587
575
|
* @example
|
|
588
576
|
* // Unauthenticated
|
|
@@ -590,6 +578,12 @@ ${writerMethods}
|
|
|
590
578
|
*
|
|
591
579
|
* // With custom fetch (e.g. from SmartFhirClient)
|
|
592
580
|
* const client = new FhirClient("https://fhir.example.com", authenticatedFetch);
|
|
581
|
+
*
|
|
582
|
+
* // Base R4 methods (inherited from @babelfhir-ts/client-r4)
|
|
583
|
+
* const pt = await client.read().patient().read("123");
|
|
584
|
+
*
|
|
585
|
+
* // Profile-specific methods (generated)
|
|
586
|
+
* const claim = await client.read().pASClaim().search({ status: "active" });
|
|
593
587
|
*/
|
|
594
588
|
export class FhirClient {
|
|
595
589
|
private readonly readClient: FhirReadClient;
|
|
@@ -1437,3 +1431,73 @@ const client = new FhirClient('https://fhir.example.com/fhir', loggingFetch);
|
|
|
1437
1431
|
`;
|
|
1438
1432
|
fs.writeFileSync(path.join(clientDir, "README.md"), content);
|
|
1439
1433
|
}
|
|
1434
|
+
/**
|
|
1435
|
+
* Install @babelfhir-ts/client-r4 type declarations into the generated output's
|
|
1436
|
+
* node_modules so tsc can resolve the import during compilation.
|
|
1437
|
+
* At runtime, the consumer installs the actual package via npm.
|
|
1438
|
+
*/
|
|
1439
|
+
function installBaseClientTypes(outputDir) {
|
|
1440
|
+
const pkgDir = path.join(outputDir, "node_modules", "@babelfhir-ts", "client-r4");
|
|
1441
|
+
fs.mkdirSync(pkgDir, { recursive: true });
|
|
1442
|
+
// Minimal package.json
|
|
1443
|
+
fs.writeFileSync(path.join(pkgDir, "package.json"), JSON.stringify({
|
|
1444
|
+
name: "@babelfhir-ts/client-r4",
|
|
1445
|
+
version: "0.0.0-types",
|
|
1446
|
+
types: "index.d.ts"
|
|
1447
|
+
}, null, 2));
|
|
1448
|
+
// Type declarations matching the base package's public API
|
|
1449
|
+
const dts = `/// <reference types="@types/fhir" />
|
|
1450
|
+
|
|
1451
|
+
export type FetchFn = typeof globalThis.fetch;
|
|
1452
|
+
|
|
1453
|
+
export type WithId<T> = T & { id: string };
|
|
1454
|
+
|
|
1455
|
+
export type SearchParams = Record<string, boolean | number | string | string[] | undefined>;
|
|
1456
|
+
|
|
1457
|
+
export interface Bundle<T = fhir4.Resource> {
|
|
1458
|
+
resourceType: "Bundle";
|
|
1459
|
+
type: "collection" | "searchset" | "transaction-response" | "transaction" | "batch" | "batch-response" | "document" | "message" | "history";
|
|
1460
|
+
total?: number;
|
|
1461
|
+
link?: { relation: string; url: string }[];
|
|
1462
|
+
entry?: { resource?: T; fullUrl?: string; search?: { mode?: string; score?: number }; request?: { method: string; url: string }; response?: { status: string } }[];
|
|
1463
|
+
}
|
|
1464
|
+
|
|
1465
|
+
export declare class FhirResourceReader<T extends fhir4.Resource> {
|
|
1466
|
+
readonly baseUrl: string;
|
|
1467
|
+
readonly resourceType: string;
|
|
1468
|
+
constructor(baseUrl: string, resourceType: string, fetchFn?: FetchFn);
|
|
1469
|
+
read(id: string): Promise<WithId<T>>;
|
|
1470
|
+
search(params?: SearchParams): Promise<Bundle<WithId<T>>>;
|
|
1471
|
+
searchOne(params?: SearchParams): Promise<WithId<T> | undefined>;
|
|
1472
|
+
searchAll(params?: SearchParams): Promise<WithId<T>[]>;
|
|
1473
|
+
}
|
|
1474
|
+
|
|
1475
|
+
export declare class FhirResourceWriter<T extends fhir4.Resource> {
|
|
1476
|
+
readonly baseUrl: string;
|
|
1477
|
+
readonly resourceType: string;
|
|
1478
|
+
constructor(baseUrl: string, resourceType: string, fetchFn?: FetchFn);
|
|
1479
|
+
create(resource: T): Promise<WithId<T>>;
|
|
1480
|
+
update(resource: WithId<T>): Promise<WithId<T>>;
|
|
1481
|
+
delete(id: string): Promise<void>;
|
|
1482
|
+
createOrUpdate(resource: WithId<T>): Promise<WithId<T>>;
|
|
1483
|
+
}
|
|
1484
|
+
|
|
1485
|
+
export declare class FhirReadClient {
|
|
1486
|
+
constructor(baseUrl: string, fetchFn?: FetchFn);
|
|
1487
|
+
protected forType<T extends fhir4.Resource>(resourceType: string): FhirResourceReader<T>;
|
|
1488
|
+
}
|
|
1489
|
+
|
|
1490
|
+
export declare class FhirWriteClient {
|
|
1491
|
+
constructor(baseUrl: string, fetchFn?: FetchFn);
|
|
1492
|
+
protected forType<T extends fhir4.Resource>(resourceType: string): FhirResourceWriter<T>;
|
|
1493
|
+
}
|
|
1494
|
+
|
|
1495
|
+
export declare class FhirClient {
|
|
1496
|
+
readonly baseUrl: string;
|
|
1497
|
+
constructor(baseUrl: string, fetchFn?: FetchFn);
|
|
1498
|
+
read(): FhirReadClient;
|
|
1499
|
+
write(): FhirWriteClient;
|
|
1500
|
+
}
|
|
1501
|
+
`;
|
|
1502
|
+
fs.writeFileSync(path.join(pkgDir, "index.d.ts"), dts);
|
|
1503
|
+
}
|
|
@@ -1295,11 +1295,9 @@ export async function generateIntoPackage(packageArchivePath, outArchivePath, fl
|
|
|
1295
1295
|
'@types/fhir': '^0.0.41'
|
|
1296
1296
|
}
|
|
1297
1297
|
};
|
|
1298
|
-
// When client is generated, add @babelfhir-ts/client-r4 as
|
|
1298
|
+
// When client is generated, add @babelfhir-ts/client-r4 as dependency (generated client extends base)
|
|
1299
1299
|
if (!flags?.noClient) {
|
|
1300
|
-
generatedPackageJson.
|
|
1301
|
-
'@babelfhir-ts/client-r4': '^0.1.0'
|
|
1302
|
-
};
|
|
1300
|
+
generatedPackageJson.dependencies['@babelfhir-ts/client-r4'] = '^0.2.0';
|
|
1303
1301
|
}
|
|
1304
1302
|
const generatedPackageJsonPath = path.join(outputDir, 'package.json');
|
|
1305
1303
|
fs.writeFileSync(generatedPackageJsonPath, JSON.stringify(generatedPackageJson, null, 2));
|
|
@@ -1334,6 +1332,20 @@ export async function generateIntoPackage(packageArchivePath, outArchivePath, fl
|
|
|
1334
1332
|
// Compile TypeScript to JavaScript
|
|
1335
1333
|
logger.log('Compiling TypeScript to JavaScript...');
|
|
1336
1334
|
await compileTypeScriptToJS(outputDir);
|
|
1335
|
+
// Remove base client type stubs — they were only needed for tsc to resolve
|
|
1336
|
+
// @babelfhir-ts/client-r4 imports during compilation. The real package is
|
|
1337
|
+
// installed by the consumer via npm.
|
|
1338
|
+
const stubDir = path.join(outputDir, 'node_modules', '@babelfhir-ts');
|
|
1339
|
+
try {
|
|
1340
|
+
fs.rmSync(stubDir, { recursive: true, force: true });
|
|
1341
|
+
}
|
|
1342
|
+
catch { /* ignore */ }
|
|
1343
|
+
// Clean up empty node_modules if nothing else is in it
|
|
1344
|
+
const nodeModulesDir = path.join(outputDir, 'node_modules');
|
|
1345
|
+
try {
|
|
1346
|
+
fs.rmdirSync(nodeModulesDir);
|
|
1347
|
+
}
|
|
1348
|
+
catch { /* not empty or doesn't exist — fine */ }
|
|
1337
1349
|
// Copy package.json to root of extractedRoot so it's at the tarball root
|
|
1338
1350
|
const rootPackageJsonPath = path.join(extractedRoot, 'package.json');
|
|
1339
1351
|
fs.copyFileSync(generatedPackageJsonPath, rootPackageJsonPath);
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "babelfhir-ts",
|
|
3
|
-
"version": "1.0.
|
|
3
|
+
"version": "1.0.41",
|
|
4
4
|
"description": "BabelFHIR-TS: generate TypeScript interfaces, validators, and helper classes from FHIR R4 StructureDefinitions (profiles) directly inside package archives.",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "out/src/main.js",
|