@medplum/core 0.9.2 → 0.9.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.
@@ -8,4 +8,5 @@ export declare class LRUCache<T> {
8
8
  clear(): void;
9
9
  get(key: string): T | undefined;
10
10
  set(key: string, val: T): void;
11
+ delete(key: string): void;
11
12
  }
@@ -1,6 +1,7 @@
1
1
  import { Binary, Bundle, Project, ProjectMembership, Reference, Resource, UserConfiguration, ValueSet } from '@medplum/fhirtypes';
2
2
  import type { Operation } from 'fast-json-patch';
3
3
  import { EventTarget } from './eventtarget';
4
+ import { ReadablePromise } from './readablepromise';
4
5
  import { SearchRequest } from './search';
5
6
  import { IndexedStructureDefinition } from './types';
6
7
  import { ProfileResource } from './utils';
@@ -164,7 +165,7 @@ export declare class MedplumClient extends EventTarget {
164
165
  * @param options Optional fetch options.
165
166
  * @returns Promise to the response content.
166
167
  */
167
- get(url: string, options?: RequestInit): Promise<any>;
168
+ get<T = any>(url: string, options?: RequestInit): ReadablePromise<T>;
168
169
  /**
169
170
  * Makes an HTTP POST request to the specified URL.
170
171
  *
@@ -396,7 +397,7 @@ export declare class MedplumClient extends EventTarget {
396
397
  * @param id The resource ID.
397
398
  * @returns The resource if available; undefined otherwise.
398
399
  */
399
- readResource<T extends Resource>(resourceType: string, id: string): Promise<T>;
400
+ readResource<T extends Resource>(resourceType: string, id: string): ReadablePromise<T>;
400
401
  /**
401
402
  * Reads a resource by resource type and ID using the in-memory resource cache.
402
403
  *
@@ -415,7 +416,7 @@ export declare class MedplumClient extends EventTarget {
415
416
  * @param id The resource ID.
416
417
  * @returns The resource if available; undefined otherwise.
417
418
  */
418
- readCached<T extends Resource>(resourceType: string, id: string): Promise<T>;
419
+ readCached<T extends Resource>(resourceType: string, id: string): ReadablePromise<T>;
419
420
  /**
420
421
  * Reads a resource by `Reference`.
421
422
  *
@@ -434,7 +435,7 @@ export declare class MedplumClient extends EventTarget {
434
435
  * @param reference The FHIR reference object.
435
436
  * @returns The resource if available; undefined otherwise.
436
437
  */
437
- readReference<T extends Resource>(reference: Reference<T>): Promise<T>;
438
+ readReference<T extends Resource>(reference: Reference<T>): ReadablePromise<T>;
438
439
  /**
439
440
  * Reads a resource by `Reference` using the in-memory resource cache.
440
441
  *
@@ -455,7 +456,7 @@ export declare class MedplumClient extends EventTarget {
455
456
  * @param reference The FHIR reference object.
456
457
  * @returns The resource if available; undefined otherwise.
457
458
  */
458
- readCachedReference<T extends Resource>(reference: Reference<T>): Promise<T>;
459
+ readCachedReference<T extends Resource>(reference: Reference<T>): ReadablePromise<T>;
459
460
  /**
460
461
  * Returns a cached schema for a resource type.
461
462
  * If the schema is not cached, returns undefined.
@@ -550,10 +551,34 @@ export declare class MedplumClient extends EventTarget {
550
551
  *
551
552
  * See the FHIR "create" operation for full details: https://www.hl7.org/fhir/http.html#create
552
553
  *
553
- * @param resource The FHIR resource to create.
554
+ * @param data The binary data to upload.
555
+ * @param filename Optional filename for the binary.
556
+ * @param contentType Content type for the binary.
557
+ * @returns The result of the create operation.
558
+ */
559
+ createBinary(data: string | File, filename: string | undefined, contentType: string): Promise<Binary>;
560
+ /**
561
+ * Creates a PDF as a FHIR `Binary` resource based on pdfmake document definition.
562
+ *
563
+ * The return value is the newly created resource, including the ID and meta.
564
+ *
565
+ * The `docDefinition` parameter is a pdfmake document definition.
566
+ *
567
+ * Example:
568
+ *
569
+ * ```typescript
570
+ * const result = await medplum.createPdf({
571
+ * content: ['Hello world']
572
+ * });
573
+ * console.log(result.id);
574
+ * ```
575
+ *
576
+ * See the pdfmake document definition for full details: https://pdfmake.github.io/docs/0.1/document-definition-object/
577
+ *
578
+ * @param docDefinition The FHIR resource to create.
554
579
  * @returns The result of the create operation.
555
580
  */
556
- createBinary(data: any, filename: string, contentType: string): Promise<Binary>;
581
+ createPdf(docDefinition: Record<string, unknown>, filename?: string): Promise<Binary>;
557
582
  /**
558
583
  * Updates a FHIR resource.
559
584
  *
@@ -1,8 +1,9 @@
1
+ export * from './cache';
1
2
  export * from './client';
2
3
  export * from './format';
3
4
  export * from './hl7';
4
5
  export * from './outcomes';
5
- export * from './repo';
6
+ export * from './readablepromise';
6
7
  export * from './search';
7
8
  export * from './searchparams';
8
9
  export * from './types';
@@ -0,0 +1,43 @@
1
+ /**
2
+ * The ReadablePromise class wraps a request promise suitable for React Suspense.
3
+ * See: https://blog.logrocket.com/react-suspense-data-fetching/#wrappromise-js
4
+ * See: https://github.com/ovieokeh/suspense-data-fetching/blob/master/lib/api/wrapPromise.js
5
+ */
6
+ export declare class ReadablePromise<T> implements Promise<T> {
7
+ #private;
8
+ readonly [Symbol.toStringTag]: string;
9
+ constructor(requestPromise: Promise<T>);
10
+ /**
11
+ * Returns true if the promise is pending.
12
+ * @returns True if the Promise is pending.
13
+ */
14
+ isPending(): boolean;
15
+ /**
16
+ * Attempts to read the value of the promise.
17
+ * If the promise is pending, this method will throw a promise.
18
+ * If the promise rejected, this method will throw the rejection reason.
19
+ * If the promise resolved, this method will return the resolved value.
20
+ * @returns The resolved value of the Promise.
21
+ */
22
+ read(): T;
23
+ /**
24
+ * Attaches callbacks for the resolution and/or rejection of the Promise.
25
+ * @param onfulfilled The callback to execute when the Promise is resolved.
26
+ * @param onrejected The callback to execute when the Promise is rejected.
27
+ * @returns A Promise for the completion of which ever callback is executed.
28
+ */
29
+ then<TResult1 = T, TResult2 = never>(onfulfilled?: ((value: T) => TResult1 | PromiseLike<TResult1>) | undefined | null, onrejected?: ((reason: any) => TResult2 | PromiseLike<TResult2>) | undefined | null): Promise<TResult1 | TResult2>;
30
+ /**
31
+ * Attaches a callback for only the rejection of the Promise.
32
+ * @param onrejected The callback to execute when the Promise is rejected.
33
+ * @returns A Promise for the completion of the callback.
34
+ */
35
+ catch<TResult = never>(onrejected?: ((reason: any) => TResult | PromiseLike<TResult>) | undefined | null): Promise<T | TResult>;
36
+ /**
37
+ * Attaches a callback that is invoked when the Promise is settled (fulfilled or rejected). The
38
+ * resolved value cannot be modified from the callback.
39
+ * @param onfinally The callback to execute when the Promise is settled (fulfilled or rejected).
40
+ * @returns A Promise for the completion of the callback.
41
+ */
42
+ finally(onfinally?: (() => void) | undefined | null): Promise<T>;
43
+ }
@@ -96,6 +96,12 @@ export declare function stringify(value: any, pretty?: boolean): string;
96
96
  * @returns True if the objects are equal.
97
97
  */
98
98
  export declare function deepEquals(object1: unknown, object2: unknown, path?: string): boolean;
99
+ /**
100
+ * Returns true if the input string is a UUID.
101
+ * @param input The input string.
102
+ * @returns True if the input string matches the UUID format.
103
+ */
104
+ export declare function isUUID(input: string): boolean;
99
105
  /**
100
106
  * Returns true if the input is an object.
101
107
  * @param object The candidate object.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@medplum/core",
3
- "version": "0.9.2",
3
+ "version": "0.9.3",
4
4
  "description": "Medplum TS/JS Library",
5
5
  "author": "Medplum <hello@medplum.com>",
6
6
  "license": "Apache-2.0",
@@ -17,7 +17,7 @@
17
17
  "test": "jest"
18
18
  },
19
19
  "devDependencies": {
20
- "@medplum/fhirtypes": "0.9.2",
20
+ "@medplum/fhirtypes": "0.9.3",
21
21
  "fast-json-patch": "3.1.1"
22
22
  },
23
23
  "main": "dist/cjs/index.js",
@@ -1,116 +0,0 @@
1
- import { Bundle, OperationOutcome, Reference, Resource } from '@medplum/fhirtypes';
2
- import { Operation } from 'fast-json-patch';
3
- import { MedplumClient } from './client';
4
- import { SearchRequest } from './search';
5
- /**
6
- * The LegacyRepositoryResult type is a tuple of operation outcome and optional resource.
7
- * @deprecated
8
- */
9
- export declare type LegacyRepositoryResult<T extends Resource | undefined> = Promise<[OperationOutcome, T | undefined]>;
10
- /**
11
- * The LegacyRepositoryClient is a supplementary API client that matches the legacy "Repository" API.
12
- * The "Repository" API is deprecated and will be removed in a future release.
13
- * This LegacyRepositoryClient is also deprecated and will be removed in a future release.
14
- * @deprecated
15
- */
16
- export declare class LegacyRepositoryClient {
17
- #private;
18
- constructor(client: MedplumClient);
19
- /**
20
- * Creates a resource.
21
- *
22
- * See: https://www.hl7.org/fhir/http.html#create
23
- *
24
- * @param resource The resource to create.
25
- * @returns Operation outcome and the new resource.
26
- * @deprecated
27
- */
28
- createResource<T extends Resource>(resource: T): LegacyRepositoryResult<T>;
29
- /**
30
- * Returns a resource.
31
- *
32
- * See: https://www.hl7.org/fhir/http.html#read
33
- *
34
- * @param resourceType The FHIR resource type.
35
- * @param id The FHIR resource ID.
36
- * @returns Operation outcome and a resource.
37
- * @deprecated
38
- */
39
- readResource<T extends Resource>(resourceType: string, id: string): LegacyRepositoryResult<T>;
40
- /**
41
- * Returns a resource by FHIR reference.
42
- *
43
- * See: https://www.hl7.org/fhir/http.html#read
44
- *
45
- * @param reference The FHIR reference.
46
- * @returns Operation outcome and a resource.
47
- * @deprecated
48
- */
49
- readReference<T extends Resource>(reference: Reference<T>): LegacyRepositoryResult<T>;
50
- /**
51
- * Returns resource history.
52
- *
53
- * See: https://www.hl7.org/fhir/http.html#history
54
- *
55
- * @param resourceType The FHIR resource type.
56
- * @param id The FHIR resource ID.
57
- * @returns Operation outcome and a history bundle.
58
- * @deprecated
59
- */
60
- readHistory<T extends Resource>(resourceType: string, id: string): LegacyRepositoryResult<Bundle<T>>;
61
- /**
62
- * Returns a resource version.
63
- *
64
- * See: https://www.hl7.org/fhir/http.html#vread
65
- *
66
- * @param resourceType The FHIR resource type.
67
- * @param id The FHIR resource ID.
68
- * @param vid The version ID.
69
- * @returns Operation outcome and a resource.
70
- * @deprecated
71
- */
72
- readVersion<T extends Resource>(resourceType: string, id: string, vid: string): LegacyRepositoryResult<T>;
73
- /**
74
- * Updates a resource.
75
- *
76
- * See: https://www.hl7.org/fhir/http.html#update
77
- *
78
- * @param resource The resource to update.
79
- * @returns Operation outcome and the updated resource.
80
- * @deprecated
81
- */
82
- updateResource<T extends Resource>(resource: T): LegacyRepositoryResult<T>;
83
- /**
84
- * Deletes a resource.
85
- *
86
- * See: https://www.hl7.org/fhir/http.html#delete
87
- *
88
- * @param resourceType The FHIR resource type.
89
- * @param id The resource ID.
90
- * @returns Operation outcome.
91
- * @deprecated
92
- */
93
- deleteResource(resourceType: string, id: string): LegacyRepositoryResult<undefined>;
94
- /**
95
- * Patches a resource.
96
- *
97
- * See: https://www.hl7.org/fhir/http.html#patch
98
- *
99
- * @param resourceType The FHIR resource type.
100
- * @param id The resource ID.
101
- * @param patch Array of JSONPatch operations.
102
- * @returns Operation outcome and the resource.
103
- * @deprecated
104
- */
105
- patchResource(resourceType: string, id: string, patch: Operation[]): LegacyRepositoryResult<Resource>;
106
- /**
107
- * Searches for resources.
108
- *
109
- * See: https://www.hl7.org/fhir/http.html#search
110
- *
111
- * @param searchRequest The search request.
112
- * @returns The search result bundle.
113
- * @deprecated
114
- */
115
- search<T extends Resource>(query: SearchRequest | string): LegacyRepositoryResult<Bundle<T>>;
116
- }