@medplum/fhir-router 5.1.26 → 5.1.27

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.
@@ -11,6 +11,7 @@ import { OperationOutcomeError } from '@medplum/core';
11
11
  import type { Parameters as Parameters_2 } from '@medplum/fhirtypes';
12
12
  import type { Reference } from '@medplum/fhirtypes';
13
13
  import type { Resource } from '@medplum/fhirtypes';
14
+ import type { ResourceType } from '@medplum/fhirtypes';
14
15
  import type { SearchRequest } from '@medplum/core';
15
16
  import type { WithId } from '@medplum/core';
16
17
 
@@ -73,13 +74,8 @@ export declare class BatchProcessor {
73
74
  private readonly req;
74
75
  private resolvedIdentities;
75
76
  private bundleInfo;
76
- private resultEntries;
77
- /** Index into `bundleInfo.ordering` of the next entry to process. */
78
- private position;
79
- /** Indices (into the original bundle) of results produced since the last {@link BatchProcessor.takePendingResults} call. */
80
- private pendingIndices;
81
- /** Error messages accumulated across processed entries, for the post-batch telemetry event. */
82
- private readonly errors;
77
+ /** The state mutated through processing (and preprocessing) */
78
+ private state;
83
79
  /**
84
80
  * Creates a batch processor.
85
81
  * @param router - The FHIR router.
@@ -157,7 +153,6 @@ export declare class BatchProcessor {
157
153
  * Scans the Bundle in order to ensure entries are processed in the correct sequence,
158
154
  * as well as to identify any operations that might require specific handling.
159
155
  *
160
- * @param results - The array of result entries, to track partial results.
161
156
  * @returns The information gathered from scanning the Bundle.
162
157
  */
163
158
  private preprocessBundle;
@@ -232,11 +227,12 @@ export declare class BatchProcessor {
232
227
  */
233
228
  export declare function buildBatchResponseBundle(bundleType: Bundle['type'], entryCount: number, results: Record<number, BundleEntry>): Bundle;
234
229
 
235
- export declare type BundlePreprocessInfo = {
230
+ export declare interface BundlePreprocessInfo {
236
231
  ordering: number[];
237
232
  requiresStrongTransaction: boolean;
238
233
  updates: number;
239
- };
234
+ resourceTypes: Set<ResourceType>;
235
+ }
240
236
 
241
237
  export declare function createResourceImpl<T extends Resource>(resourceType: T['resourceType'], resource: T, repo: FhirRepository, options?: CreateResourceOptions): Promise<FhirResponse>;
242
238
 
@@ -377,10 +373,10 @@ export declare abstract class FhirRepository {
377
373
  * Runs a callback function within a transaction.
378
374
  *
379
375
  * @param callback - The callback function to be run within a transaction.
376
+ * @param options - The transaction options.
377
+ * @returns The result of the callback function.
380
378
  */
381
- abstract withTransaction<TResult>(callback: (txRepo: this) => Promise<TResult>, options?: {
382
- serializable?: boolean;
383
- }): Promise<TResult>;
379
+ abstract withTransaction<TResult>(callback: (txRepo: this) => Promise<TResult>, options: TransactionOptions): Promise<TResult>;
384
380
  /**
385
381
  * Searches for a single FHIR resource.
386
382
  *
@@ -483,7 +479,9 @@ export declare type FhirRequestConfig = {
483
479
  transactions?: boolean;
484
480
  };
485
481
 
486
- export declare type FhirResponse = [OperationOutcome] | [OperationOutcome, Resource] | [OperationOutcome, Resource, FhirResponseOptions];
482
+ export declare type FhirResponse = [
483
+ OperationOutcome
484
+ ] | [OperationOutcome, Resource] | [OperationOutcome, Resource, FhirResponseOptions];
487
485
 
488
486
  export declare type FhirResponseOptions = {
489
487
  contentType?: string;
@@ -527,6 +525,7 @@ export declare class MemoryRepository extends FhirRepository {
527
525
  withSeeding<T>(fn: () => T | Promise<T>): Promise<T>;
528
526
  clear(): void;
529
527
  setMode(_mode: RepositoryMode): void;
528
+ private createResourceSync;
530
529
  createResource<T extends Resource>(resource: T, options?: CreateResourceOptions, update?: boolean): Promise<WithId<T>>;
531
530
  generateId(): string;
532
531
  updateResource<T extends Resource>(resource: T, options?: UpdateResourceOptions): Promise<WithId<T>>;
@@ -536,7 +535,12 @@ export declare class MemoryRepository extends FhirRepository {
536
535
  readReferences<T extends Resource>(references: readonly Reference<T>[]): Promise<(T | OperationOutcomeError)[]>;
537
536
  readHistory<T extends Resource>(resourceType: string, id: string): Promise<Bundle<T>>;
538
537
  readVersion<T extends Resource>(resourceType: string, id: string, versionId: string): Promise<T>;
538
+ private searchSync;
539
539
  search<T extends Resource>(searchRequest: SearchRequest<T>): Promise<Bundle<WithId<T>>>;
540
+ conditionalCreate<T extends Resource>(resource: T, search: SearchRequest<T>, options?: CreateResourceOptions): Promise<{
541
+ resource: WithId<T>;
542
+ outcome: OperationOutcome;
543
+ }>;
540
544
  searchByReference<T extends Resource>(searchRequest: SearchRequest<T>, referenceField: string, references: string[]): Promise<Record<string, WithId<T>[]>>;
541
545
  deleteResource(resourceType: string, id: string): Promise<void>;
542
546
  withTransaction<TResult>(callback: (repo: this) => Promise<TResult>): Promise<TResult>;
@@ -571,6 +575,8 @@ export declare const RepositoryMode: {
571
575
 
572
576
  export declare type RepositoryMode = (typeof RepositoryMode)[keyof typeof RepositoryMode];
573
577
 
578
+ declare type ResourceTypeInput = ResourceType | readonly ResourceType[] | ReadonlySet<ResourceType>;
579
+
574
580
  /** @see http://hl7.org/fhir/R4/codesystem-restful-interaction.html */
575
581
  export declare type RestInteraction = CapabilityStatementRestInteraction['code'] | CapabilityStatementRestResourceInteraction['code'] | 'operation';
576
582
 
@@ -595,6 +601,11 @@ export declare type RouteResult<Handler, Metadata> = {
595
601
  data?: Metadata;
596
602
  };
597
603
 
604
+ export declare interface TransactionOptions {
605
+ readonly resourceTypes: ResourceTypeInput;
606
+ readonly serializable?: boolean;
607
+ }
608
+
598
609
  export declare function updateResourceImpl<T extends Resource>(resourceType: T['resourceType'], id: string, resource: T, repo: FhirRepository, options?: UpdateResourceOptions): Promise<FhirResponse>;
599
610
 
600
611
  export declare type UpdateResourceOptions = {
@@ -11,6 +11,7 @@ import { OperationOutcomeError } from '@medplum/core';
11
11
  import type { Parameters as Parameters_2 } from '@medplum/fhirtypes';
12
12
  import type { Reference } from '@medplum/fhirtypes';
13
13
  import type { Resource } from '@medplum/fhirtypes';
14
+ import type { ResourceType } from '@medplum/fhirtypes';
14
15
  import type { SearchRequest } from '@medplum/core';
15
16
  import type { WithId } from '@medplum/core';
16
17
 
@@ -73,13 +74,8 @@ export declare class BatchProcessor {
73
74
  private readonly req;
74
75
  private resolvedIdentities;
75
76
  private bundleInfo;
76
- private resultEntries;
77
- /** Index into `bundleInfo.ordering` of the next entry to process. */
78
- private position;
79
- /** Indices (into the original bundle) of results produced since the last {@link BatchProcessor.takePendingResults} call. */
80
- private pendingIndices;
81
- /** Error messages accumulated across processed entries, for the post-batch telemetry event. */
82
- private readonly errors;
77
+ /** The state mutated through processing (and preprocessing) */
78
+ private state;
83
79
  /**
84
80
  * Creates a batch processor.
85
81
  * @param router - The FHIR router.
@@ -157,7 +153,6 @@ export declare class BatchProcessor {
157
153
  * Scans the Bundle in order to ensure entries are processed in the correct sequence,
158
154
  * as well as to identify any operations that might require specific handling.
159
155
  *
160
- * @param results - The array of result entries, to track partial results.
161
156
  * @returns The information gathered from scanning the Bundle.
162
157
  */
163
158
  private preprocessBundle;
@@ -232,11 +227,12 @@ export declare class BatchProcessor {
232
227
  */
233
228
  export declare function buildBatchResponseBundle(bundleType: Bundle['type'], entryCount: number, results: Record<number, BundleEntry>): Bundle;
234
229
 
235
- export declare type BundlePreprocessInfo = {
230
+ export declare interface BundlePreprocessInfo {
236
231
  ordering: number[];
237
232
  requiresStrongTransaction: boolean;
238
233
  updates: number;
239
- };
234
+ resourceTypes: Set<ResourceType>;
235
+ }
240
236
 
241
237
  export declare function createResourceImpl<T extends Resource>(resourceType: T['resourceType'], resource: T, repo: FhirRepository, options?: CreateResourceOptions): Promise<FhirResponse>;
242
238
 
@@ -377,10 +373,10 @@ export declare abstract class FhirRepository {
377
373
  * Runs a callback function within a transaction.
378
374
  *
379
375
  * @param callback - The callback function to be run within a transaction.
376
+ * @param options - The transaction options.
377
+ * @returns The result of the callback function.
380
378
  */
381
- abstract withTransaction<TResult>(callback: (txRepo: this) => Promise<TResult>, options?: {
382
- serializable?: boolean;
383
- }): Promise<TResult>;
379
+ abstract withTransaction<TResult>(callback: (txRepo: this) => Promise<TResult>, options: TransactionOptions): Promise<TResult>;
384
380
  /**
385
381
  * Searches for a single FHIR resource.
386
382
  *
@@ -483,7 +479,9 @@ export declare type FhirRequestConfig = {
483
479
  transactions?: boolean;
484
480
  };
485
481
 
486
- export declare type FhirResponse = [OperationOutcome] | [OperationOutcome, Resource] | [OperationOutcome, Resource, FhirResponseOptions];
482
+ export declare type FhirResponse = [
483
+ OperationOutcome
484
+ ] | [OperationOutcome, Resource] | [OperationOutcome, Resource, FhirResponseOptions];
487
485
 
488
486
  export declare type FhirResponseOptions = {
489
487
  contentType?: string;
@@ -527,6 +525,7 @@ export declare class MemoryRepository extends FhirRepository {
527
525
  withSeeding<T>(fn: () => T | Promise<T>): Promise<T>;
528
526
  clear(): void;
529
527
  setMode(_mode: RepositoryMode): void;
528
+ private createResourceSync;
530
529
  createResource<T extends Resource>(resource: T, options?: CreateResourceOptions, update?: boolean): Promise<WithId<T>>;
531
530
  generateId(): string;
532
531
  updateResource<T extends Resource>(resource: T, options?: UpdateResourceOptions): Promise<WithId<T>>;
@@ -536,7 +535,12 @@ export declare class MemoryRepository extends FhirRepository {
536
535
  readReferences<T extends Resource>(references: readonly Reference<T>[]): Promise<(T | OperationOutcomeError)[]>;
537
536
  readHistory<T extends Resource>(resourceType: string, id: string): Promise<Bundle<T>>;
538
537
  readVersion<T extends Resource>(resourceType: string, id: string, versionId: string): Promise<T>;
538
+ private searchSync;
539
539
  search<T extends Resource>(searchRequest: SearchRequest<T>): Promise<Bundle<WithId<T>>>;
540
+ conditionalCreate<T extends Resource>(resource: T, search: SearchRequest<T>, options?: CreateResourceOptions): Promise<{
541
+ resource: WithId<T>;
542
+ outcome: OperationOutcome;
543
+ }>;
540
544
  searchByReference<T extends Resource>(searchRequest: SearchRequest<T>, referenceField: string, references: string[]): Promise<Record<string, WithId<T>[]>>;
541
545
  deleteResource(resourceType: string, id: string): Promise<void>;
542
546
  withTransaction<TResult>(callback: (repo: this) => Promise<TResult>): Promise<TResult>;
@@ -571,6 +575,8 @@ export declare const RepositoryMode: {
571
575
 
572
576
  export declare type RepositoryMode = (typeof RepositoryMode)[keyof typeof RepositoryMode];
573
577
 
578
+ declare type ResourceTypeInput = ResourceType | readonly ResourceType[] | ReadonlySet<ResourceType>;
579
+
574
580
  /** @see http://hl7.org/fhir/R4/codesystem-restful-interaction.html */
575
581
  export declare type RestInteraction = CapabilityStatementRestInteraction['code'] | CapabilityStatementRestResourceInteraction['code'] | 'operation';
576
582
 
@@ -595,6 +601,11 @@ export declare type RouteResult<Handler, Metadata> = {
595
601
  data?: Metadata;
596
602
  };
597
603
 
604
+ export declare interface TransactionOptions {
605
+ readonly resourceTypes: ResourceTypeInput;
606
+ readonly serializable?: boolean;
607
+ }
608
+
598
609
  export declare function updateResourceImpl<T extends Resource>(resourceType: T['resourceType'], id: string, resource: T, repo: FhirRepository, options?: UpdateResourceOptions): Promise<FhirResponse>;
599
610
 
600
611
  export declare type UpdateResourceOptions = {