@medplum/fhir-router 2.1.15 → 2.1.17
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/dist/esm/index.d.mts +229 -0
- package/package.json +3 -4
- package/api-extractor.json +0 -3
- package/tsdoc.json +0 -4
- /package/dist/{types.d.ts → cjs/index.d.cts} +0 -0
|
@@ -0,0 +1,229 @@
|
|
|
1
|
+
import { Bundle } from '@medplum/fhirtypes';
|
|
2
|
+
import { Operation } from 'rfc6902';
|
|
3
|
+
import { OperationOutcome } from '@medplum/fhirtypes';
|
|
4
|
+
import { OperationOutcomeError } from '@medplum/core';
|
|
5
|
+
import { Reference } from '@medplum/fhirtypes';
|
|
6
|
+
import { Resource } from '@medplum/fhirtypes';
|
|
7
|
+
import { SearchRequest } from '@medplum/core';
|
|
8
|
+
|
|
9
|
+
export declare abstract class BaseRepository {
|
|
10
|
+
/**
|
|
11
|
+
* Searches for FHIR resources.
|
|
12
|
+
*
|
|
13
|
+
* See: https://www.hl7.org/fhir/http.html#search
|
|
14
|
+
* @param searchRequest - The FHIR search request.
|
|
15
|
+
* @returns The search results.
|
|
16
|
+
*/
|
|
17
|
+
abstract search<T extends Resource>(searchRequest: SearchRequest<T>): Promise<Bundle<T>>;
|
|
18
|
+
/**
|
|
19
|
+
* Searches for a single FHIR resource.
|
|
20
|
+
*
|
|
21
|
+
* This is a convenience method for `search()` that returns the first resource rather than a `Bundle`.
|
|
22
|
+
*
|
|
23
|
+
* The return value is the resource, if available; otherwise, undefined.
|
|
24
|
+
*
|
|
25
|
+
* See FHIR search for full details: https://www.hl7.org/fhir/search.html
|
|
26
|
+
* @param searchRequest - The FHIR search request.
|
|
27
|
+
* @returns Promise to the first search result or undefined.
|
|
28
|
+
*/
|
|
29
|
+
searchOne<T extends Resource>(searchRequest: SearchRequest<T>): Promise<T | undefined>;
|
|
30
|
+
/**
|
|
31
|
+
* Sends a FHIR search request for an array of resources.
|
|
32
|
+
*
|
|
33
|
+
* This is a convenience method for `search()` that returns the resources as an array rather than a `Bundle`.
|
|
34
|
+
*
|
|
35
|
+
* The return value is an array of resources.
|
|
36
|
+
*
|
|
37
|
+
* See FHIR search for full details: https://www.hl7.org/fhir/search.html
|
|
38
|
+
* @param searchRequest - The FHIR search request.
|
|
39
|
+
* @returns Promise to the array of search results.
|
|
40
|
+
*/
|
|
41
|
+
searchResources<T extends Resource>(searchRequest: SearchRequest<T>): Promise<T[]>;
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
export declare interface FhirOptions {
|
|
45
|
+
introspectionEnabled?: boolean;
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
/**
|
|
49
|
+
* The FhirRepository interface defines the methods that are required to implement a FHIR repository.
|
|
50
|
+
* A FHIR repository is responsible for storing and retrieving FHIR resources.
|
|
51
|
+
* It is used by the FHIR router to implement the FHIR REST API.
|
|
52
|
+
* The primary implementations at this time are:
|
|
53
|
+
* 1. MemoryRepository - A repository that stores resources in memory.
|
|
54
|
+
* 2. Server Repository - A repository that stores resources in a relational database.
|
|
55
|
+
*/
|
|
56
|
+
export declare interface FhirRepository {
|
|
57
|
+
/**
|
|
58
|
+
* Creates a FHIR resource.
|
|
59
|
+
*
|
|
60
|
+
* See: https://www.hl7.org/fhir/http.html#create
|
|
61
|
+
* @param resource - The FHIR resource to create.
|
|
62
|
+
* @returns The created resource.
|
|
63
|
+
*/
|
|
64
|
+
createResource<T extends Resource>(resource: T): Promise<T>;
|
|
65
|
+
/**
|
|
66
|
+
* Reads a FHIR resource by ID.
|
|
67
|
+
*
|
|
68
|
+
* See: https://www.hl7.org/fhir/http.html#read
|
|
69
|
+
* @param resourceType - The FHIR resource type.
|
|
70
|
+
* @param id - The FHIR resource ID.
|
|
71
|
+
* @returns The FHIR resource.
|
|
72
|
+
*/
|
|
73
|
+
readResource<T extends Resource>(resourceType: string, id: string): Promise<T>;
|
|
74
|
+
/**
|
|
75
|
+
* Reads a FHIR resource by reference.
|
|
76
|
+
*
|
|
77
|
+
* See: https://www.hl7.org/fhir/http.html#read
|
|
78
|
+
* @param reference - The FHIR reference.
|
|
79
|
+
* @returns The FHIR resource.
|
|
80
|
+
*/
|
|
81
|
+
readReference<T extends Resource>(reference: Reference<T>): Promise<T>;
|
|
82
|
+
/**
|
|
83
|
+
* Reads a collection of FHIR resources by reference.
|
|
84
|
+
*
|
|
85
|
+
* See: https://www.hl7.org/fhir/http.html#read
|
|
86
|
+
* @param references - The FHIR references.
|
|
87
|
+
* @returns The FHIR resources.
|
|
88
|
+
*/
|
|
89
|
+
readReferences(references: readonly Reference[]): Promise<(Resource | Error)[]>;
|
|
90
|
+
/**
|
|
91
|
+
* Returns resource history.
|
|
92
|
+
*
|
|
93
|
+
* Results are sorted with oldest versions last
|
|
94
|
+
*
|
|
95
|
+
* See: https://www.hl7.org/fhir/http.html#history
|
|
96
|
+
* @param resourceType - The FHIR resource type.
|
|
97
|
+
* @param id - The FHIR resource ID.
|
|
98
|
+
* @returns Operation outcome and a history bundle.
|
|
99
|
+
*/
|
|
100
|
+
readHistory<T extends Resource>(resourceType: string, id: string): Promise<Bundle<T>>;
|
|
101
|
+
/**
|
|
102
|
+
* Reads a FHIR resource version.
|
|
103
|
+
*
|
|
104
|
+
* See: https://www.hl7.org/fhir/http.html#vread
|
|
105
|
+
* @param resourceType - The FHIR resource type.
|
|
106
|
+
* @param id - The FHIR resource ID.
|
|
107
|
+
* @param vid - The FHIR resource version ID.
|
|
108
|
+
*/
|
|
109
|
+
readVersion<T extends Resource>(resourceType: string, id: string, vid: string): Promise<T>;
|
|
110
|
+
/**
|
|
111
|
+
* Updates a FHIR resource.
|
|
112
|
+
*
|
|
113
|
+
* See: https://www.hl7.org/fhir/http.html#update
|
|
114
|
+
* @param resource - The FHIR resource to update.
|
|
115
|
+
* @returns The updated resource.
|
|
116
|
+
*/
|
|
117
|
+
updateResource<T extends Resource>(resource: T): Promise<T>;
|
|
118
|
+
/**
|
|
119
|
+
* Deletes a FHIR resource.
|
|
120
|
+
*
|
|
121
|
+
* See: https://www.hl7.org/fhir/http.html#delete
|
|
122
|
+
* @param resourceType - The FHIR resource type.
|
|
123
|
+
* @param id - The FHIR resource ID.
|
|
124
|
+
*/
|
|
125
|
+
deleteResource(resourceType: string, id: string): Promise<void>;
|
|
126
|
+
/**
|
|
127
|
+
* Patches a FHIR resource.
|
|
128
|
+
*
|
|
129
|
+
* See: https://www.hl7.org/fhir/http.html#patch
|
|
130
|
+
* @param resourceType - The FHIR resource type.
|
|
131
|
+
* @param id - The FHIR resource ID.
|
|
132
|
+
* @param patch - The JSONPatch operations.
|
|
133
|
+
* @returns The patched resource.
|
|
134
|
+
*/
|
|
135
|
+
patchResource(resourceType: string, id: string, patch: Operation[]): Promise<Resource>;
|
|
136
|
+
/**
|
|
137
|
+
* Searches for FHIR resources.
|
|
138
|
+
*
|
|
139
|
+
* See: https://www.hl7.org/fhir/http.html#search
|
|
140
|
+
* @param searchRequest - The FHIR search request.
|
|
141
|
+
* @returns The search results.
|
|
142
|
+
*/
|
|
143
|
+
search<T extends Resource>(searchRequest: SearchRequest<T>): Promise<Bundle<T>>;
|
|
144
|
+
/**
|
|
145
|
+
* Searches for a single FHIR resource.
|
|
146
|
+
*
|
|
147
|
+
* This is a convenience method for `search()` that returns the first resource rather than a `Bundle`.
|
|
148
|
+
*
|
|
149
|
+
* The return value is the resource, if available; otherwise, undefined.
|
|
150
|
+
*
|
|
151
|
+
* See FHIR search for full details: https://www.hl7.org/fhir/search.html
|
|
152
|
+
* @param searchRequest - The FHIR search request.
|
|
153
|
+
* @returns Promise to the first search result or undefined.
|
|
154
|
+
*/
|
|
155
|
+
searchOne<T extends Resource>(searchRequest: SearchRequest<T>): Promise<T | undefined>;
|
|
156
|
+
/**
|
|
157
|
+
* Sends a FHIR search request for an array of resources.
|
|
158
|
+
*
|
|
159
|
+
* This is a convenience method for `search()` that returns the resources as an array rather than a `Bundle`.
|
|
160
|
+
*
|
|
161
|
+
* The return value is an array of resources.
|
|
162
|
+
*
|
|
163
|
+
* See FHIR search for full details: https://www.hl7.org/fhir/search.html
|
|
164
|
+
* @param searchRequest - The FHIR search request.
|
|
165
|
+
* @returns Promise to the array of search results.
|
|
166
|
+
*/
|
|
167
|
+
searchResources<T extends Resource>(searchRequest: SearchRequest<T>): Promise<T[]>;
|
|
168
|
+
}
|
|
169
|
+
|
|
170
|
+
export declare type FhirRequest = {
|
|
171
|
+
method: HttpMethod;
|
|
172
|
+
pathname: string;
|
|
173
|
+
body: any;
|
|
174
|
+
params: Record<string, string>;
|
|
175
|
+
query: Record<string, string>;
|
|
176
|
+
};
|
|
177
|
+
|
|
178
|
+
export declare type FhirResponse = [OperationOutcome] | [OperationOutcome, Resource];
|
|
179
|
+
|
|
180
|
+
export declare type FhirRouteHandler = (req: FhirRequest, repo: FhirRepository, router: FhirRouter) => Promise<FhirResponse>;
|
|
181
|
+
|
|
182
|
+
export declare class FhirRouter {
|
|
183
|
+
readonly router: Router<FhirRouteHandler>;
|
|
184
|
+
readonly options: FhirOptions;
|
|
185
|
+
constructor(options?: {});
|
|
186
|
+
handleRequest(req: FhirRequest, repo: FhirRepository): Promise<FhirResponse>;
|
|
187
|
+
}
|
|
188
|
+
|
|
189
|
+
export declare type HttpMethod = 'GET' | 'POST' | 'PUT' | 'PATCH' | 'DELETE' | 'HEAD' | 'OPTIONS';
|
|
190
|
+
|
|
191
|
+
export declare class MemoryRepository extends BaseRepository implements FhirRepository {
|
|
192
|
+
private readonly resources;
|
|
193
|
+
private readonly history;
|
|
194
|
+
constructor();
|
|
195
|
+
createResource<T extends Resource>(resource: T): Promise<T>;
|
|
196
|
+
updateResource<T extends Resource>(resource: T): Promise<T>;
|
|
197
|
+
patchResource(resourceType: string, id: string, patch: Operation[]): Promise<Resource>;
|
|
198
|
+
readResource<T extends Resource>(resourceType: string, id: string): Promise<T>;
|
|
199
|
+
readReference<T extends Resource>(reference: Reference<T>): Promise<T>;
|
|
200
|
+
readReferences(references: readonly Reference[]): Promise<(Resource | OperationOutcomeError)[]>;
|
|
201
|
+
readHistory<T extends Resource>(resourceType: string, id: string): Promise<Bundle<T>>;
|
|
202
|
+
readVersion<T extends Resource>(resourceType: string, id: string, versionId: string): Promise<T>;
|
|
203
|
+
search<T extends Resource>(searchRequest: SearchRequest<T>): Promise<Bundle<T>>;
|
|
204
|
+
deleteResource(resourceType: string, id: string): Promise<void>;
|
|
205
|
+
}
|
|
206
|
+
|
|
207
|
+
export declare type PathSegment = {
|
|
208
|
+
value: string;
|
|
209
|
+
param?: boolean;
|
|
210
|
+
};
|
|
211
|
+
|
|
212
|
+
export declare type Route<T> = {
|
|
213
|
+
method: HttpMethod;
|
|
214
|
+
path: PathSegment[];
|
|
215
|
+
handler: T;
|
|
216
|
+
};
|
|
217
|
+
|
|
218
|
+
export declare class Router<T> {
|
|
219
|
+
readonly routes: Route<T>[];
|
|
220
|
+
add(method: HttpMethod, pathStr: string, handler: T): void;
|
|
221
|
+
find(method: HttpMethod, pathStr: string): RouteResult<T> | undefined;
|
|
222
|
+
}
|
|
223
|
+
|
|
224
|
+
export declare type RouteResult<T> = {
|
|
225
|
+
handler: T;
|
|
226
|
+
params: Record<string, string>;
|
|
227
|
+
};
|
|
228
|
+
|
|
229
|
+
export { }
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@medplum/fhir-router",
|
|
3
|
-
"version": "2.1.
|
|
3
|
+
"version": "2.1.17",
|
|
4
4
|
"description": "Medplum FHIR Router",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"medplum",
|
|
@@ -27,15 +27,14 @@
|
|
|
27
27
|
"author": "Medplum <hello@medplum.com>",
|
|
28
28
|
"sideEffects": false,
|
|
29
29
|
"exports": {
|
|
30
|
-
"types": "./dist/types.d.ts",
|
|
31
30
|
"require": "./dist/cjs/index.cjs",
|
|
32
31
|
"import": "./dist/esm/index.mjs"
|
|
33
32
|
},
|
|
34
33
|
"main": "dist/cjs/index.cjs",
|
|
35
34
|
"module": "dist/esm/index.mjs",
|
|
36
|
-
"types": "dist/types.d.ts",
|
|
37
35
|
"scripts": {
|
|
38
|
-
"
|
|
36
|
+
"api-extractor": "api-extractor run --local && cp dist/types.d.ts dist/cjs/index.d.cts && cp dist/types.d.ts dist/esm/index.d.mts",
|
|
37
|
+
"build": "npm run clean && tsc --project tsconfig.build.json && node esbuild.mjs && npm run api-extractor",
|
|
39
38
|
"clean": "rimraf dist",
|
|
40
39
|
"test": "jest"
|
|
41
40
|
},
|
package/api-extractor.json
DELETED
package/tsdoc.json
DELETED
|
File without changes
|