@medplum/core 5.2.3 → 5.2.4

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.
@@ -2489,6 +2489,30 @@ export declare interface GenerateSmartHealthLinkParams {
2489
2489
  includeQrCode?: boolean;
2490
2490
  }
2491
2491
 
2492
+ /**
2493
+ * Generates the contents of a TypeScript definition (`.d.ts`) file for a FHIR type schema,
2494
+ * including its inner (backbone element) types.
2495
+ *
2496
+ * The schema can be a base FHIR type or a profile, as returned by `parseStructureDefinition` or `tryGetProfile`.
2497
+ * @param fhirType - The type schema to generate an interface for.
2498
+ * @param options - Optional generator options.
2499
+ * @returns The TypeScript file contents, or undefined if the type has no elements.
2500
+ */
2501
+ export declare function generateTypeScriptDefinition(fhirType: InternalTypeSchema, options?: TypeScriptGeneratorOptions): string | undefined;
2502
+
2503
+ /**
2504
+ * Generates TypeScript definitions for FHIR StructureDefinitions, such as profiles.
2505
+ *
2506
+ * Returns one `.d.ts` file per StructureDefinition, plus an `index.d.ts` that exports them all.
2507
+ * Types that are not generated, such as base FHIR data types, are imported from `@medplum/fhirtypes` by default.
2508
+ *
2509
+ * The StructureDefinitions must include a `snapshot`, and are indexed as a side effect.
2510
+ * @param structureDefinitions - The StructureDefinitions to generate types for.
2511
+ * @param options - Optional generator options.
2512
+ * @returns A map of file names to TypeScript file contents.
2513
+ */
2514
+ export declare function generateTypeScriptDefinitions(structureDefinitions: StructureDefinition[], options?: TypeScriptGeneratorOptions): Record<string, string>;
2515
+
2492
2516
  export declare function getAllDataTypes(): DataTypesMap;
2493
2517
 
2494
2518
  /**
@@ -9380,6 +9404,13 @@ export declare class ParserBuilder {
9380
9404
 
9381
9405
  export declare function tryGetProfile(profileUrl: string): InternalTypeSchema | undefined;
9382
9406
 
9407
+ /**
9408
+ * Parses a reference and returns a tuple of [ResourceType, ID], or undefined if the reference cannot be parsed.
9409
+ * @param reference - A reference to a FHIR resource.
9410
+ * @returns A tuple containing the `ResourceType` and the ID of the resource, or undefined if the reference cannot be parsed.
9411
+ */
9412
+ export declare function tryParseReference<T extends Resource>(reference: Reference<T> | undefined): [T['resourceType'], string] | undefined;
9413
+
9383
9414
  export declare class TypedEventTarget<TEvents extends Record<string, Event_2>> {
9384
9415
  private readonly emitter;
9385
9416
  dispatchEvent<TEventType extends keyof TEvents>(event: TEvents[TEventType]): void;
@@ -9426,6 +9457,19 @@ export declare class ParserBuilder {
9426
9457
 
9427
9458
  export declare type TypeName<T> = T extends string ? 'string' : T extends number ? 'number' : T extends boolean ? 'boolean' : T extends undefined ? 'undefined' : 'object';
9428
9459
 
9460
+ export declare interface TypeScriptGeneratorOptions {
9461
+ /**
9462
+ * Returns the codes in a ValueSet, used to narrow bound string properties to a union of string literals.
9463
+ * If not provided, or if no codes are returned, bound properties are typed as `string`.
9464
+ */
9465
+ getValueSetValues?: (url: string) => string[] | undefined;
9466
+ /**
9467
+ * Returns the module specifier used to import a referenced type.
9468
+ * Defaults to a sibling file, e.g. `./Patient.d.ts`.
9469
+ */
9470
+ getImportPath?: (typeName: string) => string;
9471
+ }
9472
+
9429
9473
  export declare const UCUM = "http://unitsofmeasure.org";
9430
9474
 
9431
9475
  export declare class UnaryOperatorAtom extends PrefixOperatorAtom {
@@ -2489,6 +2489,30 @@ export declare interface GenerateSmartHealthLinkParams {
2489
2489
  includeQrCode?: boolean;
2490
2490
  }
2491
2491
 
2492
+ /**
2493
+ * Generates the contents of a TypeScript definition (`.d.ts`) file for a FHIR type schema,
2494
+ * including its inner (backbone element) types.
2495
+ *
2496
+ * The schema can be a base FHIR type or a profile, as returned by `parseStructureDefinition` or `tryGetProfile`.
2497
+ * @param fhirType - The type schema to generate an interface for.
2498
+ * @param options - Optional generator options.
2499
+ * @returns The TypeScript file contents, or undefined if the type has no elements.
2500
+ */
2501
+ export declare function generateTypeScriptDefinition(fhirType: InternalTypeSchema, options?: TypeScriptGeneratorOptions): string | undefined;
2502
+
2503
+ /**
2504
+ * Generates TypeScript definitions for FHIR StructureDefinitions, such as profiles.
2505
+ *
2506
+ * Returns one `.d.ts` file per StructureDefinition, plus an `index.d.ts` that exports them all.
2507
+ * Types that are not generated, such as base FHIR data types, are imported from `@medplum/fhirtypes` by default.
2508
+ *
2509
+ * The StructureDefinitions must include a `snapshot`, and are indexed as a side effect.
2510
+ * @param structureDefinitions - The StructureDefinitions to generate types for.
2511
+ * @param options - Optional generator options.
2512
+ * @returns A map of file names to TypeScript file contents.
2513
+ */
2514
+ export declare function generateTypeScriptDefinitions(structureDefinitions: StructureDefinition[], options?: TypeScriptGeneratorOptions): Record<string, string>;
2515
+
2492
2516
  export declare function getAllDataTypes(): DataTypesMap;
2493
2517
 
2494
2518
  /**
@@ -9380,6 +9404,13 @@ export declare class ParserBuilder {
9380
9404
 
9381
9405
  export declare function tryGetProfile(profileUrl: string): InternalTypeSchema | undefined;
9382
9406
 
9407
+ /**
9408
+ * Parses a reference and returns a tuple of [ResourceType, ID], or undefined if the reference cannot be parsed.
9409
+ * @param reference - A reference to a FHIR resource.
9410
+ * @returns A tuple containing the `ResourceType` and the ID of the resource, or undefined if the reference cannot be parsed.
9411
+ */
9412
+ export declare function tryParseReference<T extends Resource>(reference: Reference<T> | undefined): [T['resourceType'], string] | undefined;
9413
+
9383
9414
  export declare class TypedEventTarget<TEvents extends Record<string, Event_2>> {
9384
9415
  private readonly emitter;
9385
9416
  dispatchEvent<TEventType extends keyof TEvents>(event: TEvents[TEventType]): void;
@@ -9426,6 +9457,19 @@ export declare class ParserBuilder {
9426
9457
 
9427
9458
  export declare type TypeName<T> = T extends string ? 'string' : T extends number ? 'number' : T extends boolean ? 'boolean' : T extends undefined ? 'undefined' : 'object';
9428
9459
 
9460
+ export declare interface TypeScriptGeneratorOptions {
9461
+ /**
9462
+ * Returns the codes in a ValueSet, used to narrow bound string properties to a union of string literals.
9463
+ * If not provided, or if no codes are returned, bound properties are typed as `string`.
9464
+ */
9465
+ getValueSetValues?: (url: string) => string[] | undefined;
9466
+ /**
9467
+ * Returns the module specifier used to import a referenced type.
9468
+ * Defaults to a sibling file, e.g. `./Patient.d.ts`.
9469
+ */
9470
+ getImportPath?: (typeName: string) => string;
9471
+ }
9472
+
9429
9473
  export declare const UCUM = "http://unitsofmeasure.org";
9430
9474
 
9431
9475
  export declare class UnaryOperatorAtom extends PrefixOperatorAtom {