@haste-health/codegen 0.127.1 → 0.127.3

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.
Files changed (2) hide show
  1. package/README.md +56 -1
  2. package/package.json +3 -3
package/README.md CHANGED
@@ -1 +1,56 @@
1
- # Codegen
1
+ # @haste-health/codegen
2
+
3
+ Code generators that turn FHIR StructureDefinitions and OperationDefinitions into the TypeScript the rest of the Haste Health SDK is built from: the resource types and type sets in [`@haste-health/fhir-types`](https://www.npmjs.com/package/@haste-health/fhir-types), the typed operations in [`@haste-health/generated-ops`](https://www.npmjs.com/package/@haste-health/generated-ops), and the element metadata and type-to-canonical maps in [`@haste-health/meta-value`](https://www.npmjs.com/package/@haste-health/meta-value). [`@haste-health/fhir-validation`](https://www.npmjs.com/package/@haste-health/fhir-validation) also uses its StructureDefinition traversal helpers at run time.
4
+
5
+ The `generate` commands of the Haste Health TypeScript CLI (`types-artifacts`, `operations`, `meta`, `type-to-canonical`) are thin wrappers around these functions. Each takes the StructureDefinitions or OperationDefinitions loaded with [`@haste-health/artifacts`](https://www.npmjs.com/package/@haste-health/artifacts) and returns generated source as a string.
6
+
7
+ ## Install
8
+
9
+ ```bash
10
+ npm install @haste-health/codegen @haste-health/artifacts
11
+ ```
12
+
13
+ ## Usage
14
+
15
+ ```ts
16
+ import { writeFileSync } from "node:fs";
17
+ import { fileURLToPath } from "node:url";
18
+ import { loadArtifacts } from "@haste-health/artifacts";
19
+ import { generateSets } from "@haste-health/codegen/generate/sets";
20
+ import { generateTypes } from "@haste-health/codegen/generate/typescript-types";
21
+ import { R4 } from "@haste-health/fhir-types/versions";
22
+
23
+ // StructureDefinitions from the FHIR packages in this project's dependencies.
24
+ const structureDefinitions = loadArtifacts({
25
+ fhirVersion: R4,
26
+ resourceType: "StructureDefinition",
27
+ currentDirectory: fileURLToPath(import.meta.url),
28
+ });
29
+
30
+ writeFileSync("types.ts", generateTypes(R4, structureDefinitions));
31
+ writeFileSync("sets.ts", generateSets(R4, structureDefinitions));
32
+ ```
33
+
34
+ Generate from a package of your own profiles the same way: add the FHIR package to your dependencies and the loader picks it up.
35
+
36
+ ## Generators
37
+
38
+ | Import | Function | Produces |
39
+ | ------------------------------------------------------ | ------------------------------------------------------------------------------ | --------------------------------------------------------------------------------------------------------------------------- |
40
+ | `@haste-health/codegen/generate/typescript-types` | `generateTypes(version, structureDefinitions)` | Interfaces for every primitive, complex and resource type, plus the `ResourceType`, `AResource` and `DataType` lookup types |
41
+ | `@haste-health/codegen/generate/sets` | `generateSets(version, structureDefinitions)` | The `resourceTypes`, `complexTypes` and `primitiveTypes` string sets |
42
+ | `@haste-health/codegen/generate/operation-definition` | default `operationGeneration(version, operationDefinitions)`, `generateOp(op)` | One namespace per OperationDefinition with `Input`, `Output`, `IOp` and `Op` (R4 only) |
43
+ | `@haste-health/codegen/generate/meta-data` | `generateMetaData(structureDefinitions)` | Compiled element metadata (`MetaV2Compiled`) that `@haste-health/meta-value` uses for type-aware FHIRPath and validation |
44
+ | `@haste-health/codegen/generate/type-to-canonical` | `generateTypeToCanonicalMap(structureDefinitions)` | A map from type name to canonical URL |
45
+ | `@haste-health/codegen/traversal/structure-definition` | `traversalBottomUp`, `eleIndexToChildIndices` | Walk a StructureDefinition snapshot as an element tree |
46
+
47
+ The root import, `@haste-health/codegen`, exposes the same modules as `generate.typescript`, `generate.searchParameter` (the sets), `generate.operationDefinition`, `generate.metaData` and `sdTraversal`. Generated files start with a `@generated` comment; change the artifacts or the generator and regenerate rather than editing them.
48
+
49
+ ## Links
50
+
51
+ - [API reference](https://typescript.haste.health/modules/_haste-health_codegen.html)
52
+ - [Source](https://github.com/HasteHealth/HasteHealth/tree/main/frontend/packages/codegen)
53
+ - [TypeScript SDK overview](https://haste.health/docs/api/sdks/typescript)
54
+ - Rust equivalent: [haste-codegen](https://crates.io/crates/haste-codegen), which generates the Rust model and operations
55
+
56
+ Part of [Haste Health](https://haste.health), licensed under [Apache-2.0](https://github.com/HasteHealth/HasteHealth/blob/main/LICENSE).
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@haste-health/codegen",
3
- "version": "0.127.1",
3
+ "version": "0.127.3",
4
4
  "homepage": "https://haste.health",
5
5
  "repository": {
6
6
  "type": "git",
@@ -17,8 +17,8 @@
17
17
  },
18
18
  "dependencies": {
19
19
  "commander": "^12.1.0",
20
- "@haste-health/artifacts": "^0.127.1",
21
- "@haste-health/fhir-types": "^0.127.1"
20
+ "@haste-health/artifacts": "^0.127.3",
21
+ "@haste-health/fhir-types": "^0.127.3"
22
22
  },
23
23
  "files": [
24
24
  "lib/**"