@medplum/fhir-router 2.0.4 → 2.0.5

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.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@medplum/fhir-router",
3
- "version": "2.0.4",
3
+ "version": "2.0.5",
4
4
  "description": "Medplum FHIR Router",
5
5
  "author": "Medplum <hello@medplum.com>",
6
6
  "license": "Apache-2.0",
@@ -12,8 +12,7 @@
12
12
  },
13
13
  "scripts": {
14
14
  "clean": "rimraf dist",
15
- "build": "npm run clean && tsc && npm run rollup",
16
- "rollup": "rollup --config rollup.config.mjs",
15
+ "build": "npm run clean && tsc --project tsconfig.build.json && rollup --config rollup.config.mjs",
17
16
  "test": "jest"
18
17
  },
19
18
  "dependencies": {
@@ -26,11 +25,12 @@
26
25
  },
27
26
  "main": "dist/cjs/index.cjs",
28
27
  "module": "dist/esm/index.mjs",
28
+ "types": "dist/types/index.d.ts",
29
29
  "exports": {
30
+ "types": "./dist/types/index.d.ts",
30
31
  "require": "./dist/cjs/index.cjs",
31
32
  "import": "./dist/esm/index.mjs"
32
33
  },
33
- "types": "dist/types/index.d.ts",
34
34
  "sideEffects": false,
35
35
  "keywords": [
36
36
  "medplum",
@@ -0,0 +1,9 @@
1
+ {
2
+ "extends": "./tsconfig.json",
3
+ "compilerOptions": {
4
+ "outDir": "dist/types",
5
+ "noEmit": false,
6
+ "emitDeclarationOnly": true
7
+ },
8
+ "exclude": ["**/*.test.ts"]
9
+ }
@@ -1,14 +0,0 @@
1
- import { Bundle } from '@medplum/fhirtypes';
2
- import { FhirRouter } from './fhirrouter';
3
- import { FhirRepository } from './repo';
4
- /**
5
- * Processes a FHIR batch request.
6
- *
7
- * See: https://www.hl7.org/fhir/http.html#transaction
8
- *
9
- * @param router The FHIR router.
10
- * @param repo The FHIR repository.
11
- * @param bundle The input bundle.
12
- * @returns The bundle response.
13
- */
14
- export declare function processBatch(router: FhirRouter, repo: FhirRepository, bundle: Bundle): Promise<Bundle>;
@@ -1,17 +0,0 @@
1
- import { OperationOutcome, Resource } from '@medplum/fhirtypes';
2
- import { FhirRepository } from './repo';
3
- import { HttpMethod, Router } from './urlrouter';
4
- export type FhirRequest = {
5
- method: HttpMethod;
6
- pathname: string;
7
- body: any;
8
- params: Record<string, string>;
9
- query: Record<string, string>;
10
- };
11
- export type FhirResponse = [OperationOutcome] | [OperationOutcome, Resource];
12
- export type FhirRouteHandler = (req: FhirRequest, repo: FhirRepository, router: FhirRouter) => Promise<FhirResponse>;
13
- export declare class FhirRouter {
14
- readonly router: Router<FhirRouteHandler>;
15
- constructor();
16
- handleRequest(req: FhirRequest, repo: FhirRepository): Promise<FhirResponse>;
17
- }
@@ -1,10 +0,0 @@
1
- import { GraphQLSchema } from 'graphql';
2
- import { FhirRequest, FhirResponse } from './fhirrouter';
3
- import { FhirRepository } from './repo';
4
- /**
5
- * Handles FHIR GraphQL requests.
6
- *
7
- * See: https://www.hl7.org/fhir/graphql.html
8
- */
9
- export declare function graphqlHandler(req: FhirRequest, repo: FhirRepository): Promise<FhirResponse>;
10
- export declare function getRootSchema(): GraphQLSchema;
@@ -1,3 +0,0 @@
1
- export * from './fhirrouter';
2
- export * from './repo';
3
- export * from './urlrouter';
@@ -1,116 +0,0 @@
1
- import { OperationOutcomeError, SearchRequest } from '@medplum/core';
2
- import { Bundle, Reference, Resource } from '@medplum/fhirtypes';
3
- import { Operation } from 'rfc6902';
4
- export interface FhirRepository {
5
- /**
6
- * Creates a FHIR resource.
7
- *
8
- * See: https://www.hl7.org/fhir/http.html#create
9
- *
10
- * @param resource The FHIR resource to create.
11
- * @returns The created resource.
12
- */
13
- createResource<T extends Resource>(resource: T): Promise<T>;
14
- /**
15
- * Reads a FHIR resource by ID.
16
- *
17
- * See: https://www.hl7.org/fhir/http.html#read
18
- *
19
- * @param resourceType The FHIR resource type.
20
- * @param id The FHIR resource ID.
21
- * @returns The FHIR resource.
22
- */
23
- readResource<T extends Resource>(resourceType: string, id: string): Promise<T>;
24
- /**
25
- * Reads a FHIR resource by reference.
26
- *
27
- * See: https://www.hl7.org/fhir/http.html#read
28
- *
29
- * @param reference The FHIR reference.
30
- * @returns The FHIR resource.
31
- */
32
- readReference<T extends Resource>(reference: Reference<T>): Promise<T>;
33
- /**
34
- * Reads a collection of FHIR resources by reference.
35
- *
36
- * See: https://www.hl7.org/fhir/http.html#read
37
- *
38
- * @param references The FHIR references.
39
- * @returns The FHIR resources.
40
- */
41
- readReferences(references: readonly Reference[]): Promise<(Resource | Error)[]>;
42
- /**
43
- * Returns resource history.
44
- *
45
- * Results are sorted with oldest versions last
46
- *
47
- * See: https://www.hl7.org/fhir/http.html#history
48
- *
49
- * @param resourceType The FHIR resource type.
50
- * @param id The FHIR resource ID.
51
- * @returns Operation outcome and a history bundle.
52
- */
53
- readHistory<T extends Resource>(resourceType: string, id: string): Promise<Bundle<T>>;
54
- /**
55
- * Reads a FHIR resource version.
56
- *
57
- * See: https://www.hl7.org/fhir/http.html#vread
58
- *
59
- * @param resourceType The FHIR resource type.
60
- * @param id The FHIR resource ID.
61
- * @param vid The FHIR resource version ID.
62
- */
63
- readVersion<T extends Resource>(resourceType: string, id: string, vid: string): Promise<T>;
64
- /**
65
- * Updates a FHIR resource.
66
- *
67
- * See: https://www.hl7.org/fhir/http.html#update
68
- *
69
- * @param resource The FHIR resource to update.
70
- * @returns The updated resource.
71
- */
72
- updateResource<T extends Resource>(resource: T): Promise<T>;
73
- /**
74
- * Deletes a FHIR resource.
75
- *
76
- * See: https://www.hl7.org/fhir/http.html#delete
77
- *
78
- * @param resourceType The FHIR resource type.
79
- * @param id The FHIR resource ID.
80
- */
81
- deleteResource(resourceType: string, id: string): Promise<void>;
82
- /**
83
- * Patches a FHIR resource.
84
- *
85
- * See: https://www.hl7.org/fhir/http.html#patch
86
- *
87
- * @param resourceType The FHIR resource type.
88
- * @param id The FHIR resource ID.
89
- * @param patch The JSONPatch operations.
90
- * @returns The patched resource.
91
- */
92
- patchResource(resourceType: string, id: string, patch: Operation[]): Promise<Resource>;
93
- /**
94
- * Searches for FHIR resources.
95
- *
96
- * See: https://www.hl7.org/fhir/http.html#search
97
- *
98
- * @param searchRequest The FHIR search request.
99
- * @returns The search results.
100
- */
101
- search<T extends Resource>(searchRequest: SearchRequest): Promise<Bundle<T>>;
102
- }
103
- export declare class MemoryRepository implements FhirRepository {
104
- #private;
105
- constructor();
106
- createResource<T extends Resource>(resource: T): Promise<T>;
107
- updateResource<T extends Resource>(resource: T): Promise<T>;
108
- patchResource(resourceType: string, id: string, patch: Operation[]): Promise<Resource>;
109
- readResource<T extends Resource>(resourceType: string, id: string): Promise<T>;
110
- readReference<T extends Resource>(reference: Reference<T>): Promise<T>;
111
- readReferences(references: readonly Reference<Resource>[]): Promise<(Resource | OperationOutcomeError)[]>;
112
- readHistory<T extends Resource>(resourceType: string, id: string): Promise<Bundle<T>>;
113
- readVersion<T extends Resource>(resourceType: string, id: string, versionId: string): Promise<T>;
114
- search<T extends Resource>(searchRequest: SearchRequest): Promise<Bundle<T>>;
115
- deleteResource(resourceType: string, id: string): Promise<void>;
116
- }
@@ -1,19 +0,0 @@
1
- export type HttpMethod = 'GET' | 'POST' | 'PUT' | 'PATCH' | 'DELETE' | 'HEAD' | 'OPTIONS';
2
- export type PathSegment = {
3
- value: string;
4
- param?: boolean;
5
- };
6
- export type Route<T> = {
7
- method: HttpMethod;
8
- path: PathSegment[];
9
- handler: T;
10
- };
11
- export type RouteResult<T> = {
12
- handler: T;
13
- params: Record<string, string>;
14
- };
15
- export declare class Router<T> {
16
- readonly routes: Route<T>[];
17
- add(method: HttpMethod, pathStr: string, handler: T): void;
18
- find(method: HttpMethod, pathStr: string): RouteResult<T> | undefined;
19
- }
@@ -1,14 +0,0 @@
1
- import { Bundle } from '@medplum/fhirtypes';
2
- import { FhirRouter } from './fhirrouter';
3
- import { FhirRepository } from './repo';
4
- /**
5
- * Processes a FHIR batch request.
6
- *
7
- * See: https://www.hl7.org/fhir/http.html#transaction
8
- *
9
- * @param router The FHIR router.
10
- * @param repo The FHIR repository.
11
- * @param bundle The input bundle.
12
- * @returns The bundle response.
13
- */
14
- export declare function processBatch(router: FhirRouter, repo: FhirRepository, bundle: Bundle): Promise<Bundle>;
@@ -1,17 +0,0 @@
1
- import { OperationOutcome, Resource } from '@medplum/fhirtypes';
2
- import { FhirRepository } from './repo';
3
- import { HttpMethod, Router } from './urlrouter';
4
- export type FhirRequest = {
5
- method: HttpMethod;
6
- pathname: string;
7
- body: any;
8
- params: Record<string, string>;
9
- query: Record<string, string>;
10
- };
11
- export type FhirResponse = [OperationOutcome] | [OperationOutcome, Resource];
12
- export type FhirRouteHandler = (req: FhirRequest, repo: FhirRepository, router: FhirRouter) => Promise<FhirResponse>;
13
- export declare class FhirRouter {
14
- readonly router: Router<FhirRouteHandler>;
15
- constructor();
16
- handleRequest(req: FhirRequest, repo: FhirRepository): Promise<FhirResponse>;
17
- }
@@ -1,10 +0,0 @@
1
- import { GraphQLSchema } from 'graphql';
2
- import { FhirRequest, FhirResponse } from './fhirrouter';
3
- import { FhirRepository } from './repo';
4
- /**
5
- * Handles FHIR GraphQL requests.
6
- *
7
- * See: https://www.hl7.org/fhir/graphql.html
8
- */
9
- export declare function graphqlHandler(req: FhirRequest, repo: FhirRepository): Promise<FhirResponse>;
10
- export declare function getRootSchema(): GraphQLSchema;
@@ -1,3 +0,0 @@
1
- export * from './fhirrouter';
2
- export * from './repo';
3
- export * from './urlrouter';
@@ -1,116 +0,0 @@
1
- import { OperationOutcomeError, SearchRequest } from '@medplum/core';
2
- import { Bundle, Reference, Resource } from '@medplum/fhirtypes';
3
- import { Operation } from 'rfc6902';
4
- export interface FhirRepository {
5
- /**
6
- * Creates a FHIR resource.
7
- *
8
- * See: https://www.hl7.org/fhir/http.html#create
9
- *
10
- * @param resource The FHIR resource to create.
11
- * @returns The created resource.
12
- */
13
- createResource<T extends Resource>(resource: T): Promise<T>;
14
- /**
15
- * Reads a FHIR resource by ID.
16
- *
17
- * See: https://www.hl7.org/fhir/http.html#read
18
- *
19
- * @param resourceType The FHIR resource type.
20
- * @param id The FHIR resource ID.
21
- * @returns The FHIR resource.
22
- */
23
- readResource<T extends Resource>(resourceType: string, id: string): Promise<T>;
24
- /**
25
- * Reads a FHIR resource by reference.
26
- *
27
- * See: https://www.hl7.org/fhir/http.html#read
28
- *
29
- * @param reference The FHIR reference.
30
- * @returns The FHIR resource.
31
- */
32
- readReference<T extends Resource>(reference: Reference<T>): Promise<T>;
33
- /**
34
- * Reads a collection of FHIR resources by reference.
35
- *
36
- * See: https://www.hl7.org/fhir/http.html#read
37
- *
38
- * @param references The FHIR references.
39
- * @returns The FHIR resources.
40
- */
41
- readReferences(references: readonly Reference[]): Promise<(Resource | Error)[]>;
42
- /**
43
- * Returns resource history.
44
- *
45
- * Results are sorted with oldest versions last
46
- *
47
- * See: https://www.hl7.org/fhir/http.html#history
48
- *
49
- * @param resourceType The FHIR resource type.
50
- * @param id The FHIR resource ID.
51
- * @returns Operation outcome and a history bundle.
52
- */
53
- readHistory<T extends Resource>(resourceType: string, id: string): Promise<Bundle<T>>;
54
- /**
55
- * Reads a FHIR resource version.
56
- *
57
- * See: https://www.hl7.org/fhir/http.html#vread
58
- *
59
- * @param resourceType The FHIR resource type.
60
- * @param id The FHIR resource ID.
61
- * @param vid The FHIR resource version ID.
62
- */
63
- readVersion<T extends Resource>(resourceType: string, id: string, vid: string): Promise<T>;
64
- /**
65
- * Updates a FHIR resource.
66
- *
67
- * See: https://www.hl7.org/fhir/http.html#update
68
- *
69
- * @param resource The FHIR resource to update.
70
- * @returns The updated resource.
71
- */
72
- updateResource<T extends Resource>(resource: T): Promise<T>;
73
- /**
74
- * Deletes a FHIR resource.
75
- *
76
- * See: https://www.hl7.org/fhir/http.html#delete
77
- *
78
- * @param resourceType The FHIR resource type.
79
- * @param id The FHIR resource ID.
80
- */
81
- deleteResource(resourceType: string, id: string): Promise<void>;
82
- /**
83
- * Patches a FHIR resource.
84
- *
85
- * See: https://www.hl7.org/fhir/http.html#patch
86
- *
87
- * @param resourceType The FHIR resource type.
88
- * @param id The FHIR resource ID.
89
- * @param patch The JSONPatch operations.
90
- * @returns The patched resource.
91
- */
92
- patchResource(resourceType: string, id: string, patch: Operation[]): Promise<Resource>;
93
- /**
94
- * Searches for FHIR resources.
95
- *
96
- * See: https://www.hl7.org/fhir/http.html#search
97
- *
98
- * @param searchRequest The FHIR search request.
99
- * @returns The search results.
100
- */
101
- search<T extends Resource>(searchRequest: SearchRequest): Promise<Bundle<T>>;
102
- }
103
- export declare class MemoryRepository implements FhirRepository {
104
- #private;
105
- constructor();
106
- createResource<T extends Resource>(resource: T): Promise<T>;
107
- updateResource<T extends Resource>(resource: T): Promise<T>;
108
- patchResource(resourceType: string, id: string, patch: Operation[]): Promise<Resource>;
109
- readResource<T extends Resource>(resourceType: string, id: string): Promise<T>;
110
- readReference<T extends Resource>(reference: Reference<T>): Promise<T>;
111
- readReferences(references: readonly Reference<Resource>[]): Promise<(Resource | OperationOutcomeError)[]>;
112
- readHistory<T extends Resource>(resourceType: string, id: string): Promise<Bundle<T>>;
113
- readVersion<T extends Resource>(resourceType: string, id: string, versionId: string): Promise<T>;
114
- search<T extends Resource>(searchRequest: SearchRequest): Promise<Bundle<T>>;
115
- deleteResource(resourceType: string, id: string): Promise<void>;
116
- }
@@ -1,19 +0,0 @@
1
- export type HttpMethod = 'GET' | 'POST' | 'PUT' | 'PATCH' | 'DELETE' | 'HEAD' | 'OPTIONS';
2
- export type PathSegment = {
3
- value: string;
4
- param?: boolean;
5
- };
6
- export type Route<T> = {
7
- method: HttpMethod;
8
- path: PathSegment[];
9
- handler: T;
10
- };
11
- export type RouteResult<T> = {
12
- handler: T;
13
- params: Record<string, string>;
14
- };
15
- export declare class Router<T> {
16
- readonly routes: Route<T>[];
17
- add(method: HttpMethod, pathStr: string, handler: T): void;
18
- find(method: HttpMethod, pathStr: string): RouteResult<T> | undefined;
19
- }