@medplum/mock 0.9.29 → 0.9.30
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/cjs/index.js +190 -161
- package/dist/cjs/index.js.map +1 -1
- package/dist/cjs/index.min.js +1 -1
- package/dist/cjs/index.min.js.map +1 -1
- package/dist/cjs/repo.d.ts +3 -2
- package/dist/esm/index.js +187 -159
- package/dist/esm/index.js.map +1 -1
- package/dist/esm/index.min.js +1 -1
- package/dist/esm/index.min.js.map +1 -1
- package/dist/esm/repo.d.ts +3 -2
- package/dist/types/repo.d.ts +3 -2
- package/package.json +4 -4
package/dist/esm/index.js
CHANGED
|
@@ -1,5 +1,42 @@
|
|
|
1
|
-
import { createReference, getReferenceString, deepClone, badRequest, notFound, evalFhirPath, Operator, MedplumClient,
|
|
2
|
-
|
|
1
|
+
import { createReference, getReferenceString, deepClone, badRequest, notFound, evalFhirPath, Operator, MedplumClient, allOk, isOk, parseSearchDefinition, getStatus } from '@medplum/core';
|
|
2
|
+
|
|
3
|
+
/******************************************************************************
|
|
4
|
+
Copyright (c) Microsoft Corporation.
|
|
5
|
+
|
|
6
|
+
Permission to use, copy, modify, and/or distribute this software for any
|
|
7
|
+
purpose with or without fee is hereby granted.
|
|
8
|
+
|
|
9
|
+
THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH
|
|
10
|
+
REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
|
|
11
|
+
AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT,
|
|
12
|
+
INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
|
|
13
|
+
LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR
|
|
14
|
+
OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
|
|
15
|
+
PERFORMANCE OF THIS SOFTWARE.
|
|
16
|
+
***************************************************************************** */
|
|
17
|
+
|
|
18
|
+
function __awaiter(thisArg, _arguments, P, generator) {
|
|
19
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
20
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
21
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
22
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
23
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
24
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
25
|
+
});
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
function __classPrivateFieldGet(receiver, state, kind, f) {
|
|
29
|
+
if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a getter");
|
|
30
|
+
if (typeof state === "function" ? receiver !== state || !f : !state.has(receiver)) throw new TypeError("Cannot read private member from an object whose class did not declare it");
|
|
31
|
+
return kind === "m" ? f : kind === "a" ? f.call(receiver) : f ? f.value : state.get(receiver);
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
function __classPrivateFieldSet(receiver, state, value, kind, f) {
|
|
35
|
+
if (kind === "m") throw new TypeError("Private method is not writable");
|
|
36
|
+
if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a setter");
|
|
37
|
+
if (typeof state === "function" ? receiver !== state || !f : !state.has(receiver)) throw new TypeError("Cannot write private member to an object whose class did not declare it");
|
|
38
|
+
return (kind === "a" ? f.call(receiver, value) : f ? f.value = value : state.set(receiver, value)), value;
|
|
39
|
+
}
|
|
3
40
|
|
|
4
41
|
const ExampleAccessPolicy = {
|
|
5
42
|
resourceType: 'AccessPolicy',
|
|
@@ -7096,34 +7133,6 @@ const ExampleWorkflowRequestGroup = {
|
|
|
7096
7133
|
],
|
|
7097
7134
|
};
|
|
7098
7135
|
|
|
7099
|
-
/******************************************************************************
|
|
7100
|
-
Copyright (c) Microsoft Corporation.
|
|
7101
|
-
|
|
7102
|
-
Permission to use, copy, modify, and/or distribute this software for any
|
|
7103
|
-
purpose with or without fee is hereby granted.
|
|
7104
|
-
|
|
7105
|
-
THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH
|
|
7106
|
-
REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
|
|
7107
|
-
AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT,
|
|
7108
|
-
INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
|
|
7109
|
-
LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR
|
|
7110
|
-
OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
|
|
7111
|
-
PERFORMANCE OF THIS SOFTWARE.
|
|
7112
|
-
***************************************************************************** */
|
|
7113
|
-
|
|
7114
|
-
function __classPrivateFieldGet(receiver, state, kind, f) {
|
|
7115
|
-
if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a getter");
|
|
7116
|
-
if (typeof state === "function" ? receiver !== state || !f : !state.has(receiver)) throw new TypeError("Cannot read private member from an object whose class did not declare it");
|
|
7117
|
-
return kind === "m" ? f : kind === "a" ? f.call(receiver) : f ? f.value : state.get(receiver);
|
|
7118
|
-
}
|
|
7119
|
-
|
|
7120
|
-
function __classPrivateFieldSet(receiver, state, value, kind, f) {
|
|
7121
|
-
if (kind === "m") throw new TypeError("Private method is not writable");
|
|
7122
|
-
if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a setter");
|
|
7123
|
-
if (typeof state === "function" ? receiver !== state || !f : !state.has(receiver)) throw new TypeError("Cannot write private member to an object whose class did not declare it");
|
|
7124
|
-
return (kind === "a" ? f.call(receiver, value) : f ? f.value = value : state.set(receiver, value)), value;
|
|
7125
|
-
}
|
|
7126
|
-
|
|
7127
7136
|
var _MemoryRepository_resources, _MemoryRepository_history;
|
|
7128
7137
|
class MemoryRepository {
|
|
7129
7138
|
constructor() {
|
|
@@ -7175,18 +7184,21 @@ class MemoryRepository {
|
|
|
7175
7184
|
}
|
|
7176
7185
|
patchResource(resourceType, id, patch) {
|
|
7177
7186
|
var _a, _b;
|
|
7178
|
-
|
|
7179
|
-
|
|
7180
|
-
|
|
7181
|
-
|
|
7182
|
-
|
|
7183
|
-
|
|
7184
|
-
|
|
7185
|
-
|
|
7186
|
-
|
|
7187
|
-
|
|
7188
|
-
|
|
7189
|
-
|
|
7187
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
7188
|
+
const resource = this.readResource(resourceType, id);
|
|
7189
|
+
let patchResult;
|
|
7190
|
+
try {
|
|
7191
|
+
const { applyPatch } = yield import('fast-json-patch');
|
|
7192
|
+
patchResult = applyPatch(resource, patch, true);
|
|
7193
|
+
}
|
|
7194
|
+
catch (err) {
|
|
7195
|
+
const patchError = err;
|
|
7196
|
+
const message = ((_b = (_a = patchError.message) === null || _a === void 0 ? void 0 : _a.split('\n')) === null || _b === void 0 ? void 0 : _b[0]) || 'JSONPatch error';
|
|
7197
|
+
throw badRequest(message);
|
|
7198
|
+
}
|
|
7199
|
+
const patchedResource = patchResult.newDocument;
|
|
7200
|
+
return this.updateResource(patchedResource);
|
|
7201
|
+
});
|
|
7190
7202
|
}
|
|
7191
7203
|
readResource(resourceType, id) {
|
|
7192
7204
|
var _a, _b;
|
|
@@ -7354,25 +7366,27 @@ class MockFetchClient {
|
|
|
7354
7366
|
this.initMockRepo();
|
|
7355
7367
|
}
|
|
7356
7368
|
mockFetch(url, options) {
|
|
7357
|
-
|
|
7358
|
-
|
|
7359
|
-
|
|
7360
|
-
|
|
7361
|
-
|
|
7362
|
-
|
|
7363
|
-
|
|
7364
|
-
|
|
7365
|
-
|
|
7366
|
-
|
|
7367
|
-
|
|
7368
|
-
|
|
7369
|
-
|
|
7370
|
-
|
|
7371
|
-
|
|
7372
|
-
|
|
7373
|
-
|
|
7374
|
-
|
|
7375
|
-
|
|
7369
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
7370
|
+
const method = options.method || 'GET';
|
|
7371
|
+
const path = url.replace('https://example.com/', '');
|
|
7372
|
+
if (this.debug) {
|
|
7373
|
+
console.log('MockClient', method, path);
|
|
7374
|
+
}
|
|
7375
|
+
const response = yield this.mockHandler(method, path, options);
|
|
7376
|
+
if (this.debug && !response) {
|
|
7377
|
+
console.log('MockClient: not found', method, path);
|
|
7378
|
+
}
|
|
7379
|
+
if (this.debug) {
|
|
7380
|
+
console.log('MockClient', JSON.stringify(response, null, 2));
|
|
7381
|
+
}
|
|
7382
|
+
if ((response === null || response === void 0 ? void 0 : response.resourceType) === 'OperationOutcome' && !isOk(response)) {
|
|
7383
|
+
return Promise.reject(response);
|
|
7384
|
+
}
|
|
7385
|
+
return Promise.resolve({
|
|
7386
|
+
ok: true,
|
|
7387
|
+
blob: () => Promise.resolve(response),
|
|
7388
|
+
json: () => Promise.resolve(response),
|
|
7389
|
+
});
|
|
7376
7390
|
});
|
|
7377
7391
|
}
|
|
7378
7392
|
mockCreatePdf(docDefinition, tableLayouts, fonts) {
|
|
@@ -7385,21 +7399,23 @@ class MockFetchClient {
|
|
|
7385
7399
|
return Promise.resolve({});
|
|
7386
7400
|
}
|
|
7387
7401
|
mockHandler(method, path, options) {
|
|
7388
|
-
|
|
7389
|
-
|
|
7390
|
-
|
|
7391
|
-
|
|
7392
|
-
|
|
7393
|
-
|
|
7394
|
-
|
|
7395
|
-
|
|
7396
|
-
|
|
7397
|
-
|
|
7398
|
-
|
|
7399
|
-
|
|
7400
|
-
|
|
7401
|
-
|
|
7402
|
-
|
|
7402
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
7403
|
+
if (path.startsWith('admin/')) {
|
|
7404
|
+
return this.mockAdminHandler(method, path);
|
|
7405
|
+
}
|
|
7406
|
+
else if (path.startsWith('auth/')) {
|
|
7407
|
+
return this.mockAuthHandler(method, path, options);
|
|
7408
|
+
}
|
|
7409
|
+
else if (path.startsWith('oauth2/')) {
|
|
7410
|
+
return this.mockOAuthHandler(method, path, options);
|
|
7411
|
+
}
|
|
7412
|
+
else if (path.startsWith('fhir/R4')) {
|
|
7413
|
+
return this.mockFhirHandler(method, path, options);
|
|
7414
|
+
}
|
|
7415
|
+
else {
|
|
7416
|
+
return null;
|
|
7417
|
+
}
|
|
7418
|
+
});
|
|
7403
7419
|
}
|
|
7404
7420
|
mockAdminHandler(_method, path) {
|
|
7405
7421
|
if (path.startsWith('admin/projects/123')) {
|
|
@@ -7594,64 +7610,66 @@ class MockFetchClient {
|
|
|
7594
7610
|
DrAliceSmithSlots.forEach((slot) => this.mockRepo.createResource(slot));
|
|
7595
7611
|
}
|
|
7596
7612
|
mockFhirHandler(method, url, options) {
|
|
7597
|
-
|
|
7598
|
-
|
|
7599
|
-
|
|
7600
|
-
|
|
7601
|
-
|
|
7602
|
-
|
|
7603
|
-
|
|
7604
|
-
|
|
7605
|
-
|
|
7606
|
-
else if (path === 'fhir/R4/$graphql') {
|
|
7607
|
-
return this.mockFhirGraphqlHandler(method, path, options);
|
|
7608
|
-
}
|
|
7609
|
-
else if (path === 'not-found' || id === 'not-found') {
|
|
7610
|
-
return notFound;
|
|
7611
|
-
}
|
|
7612
|
-
else if (method === 'POST') {
|
|
7613
|
-
if (resourceType && id && operation) {
|
|
7614
|
-
return allOk;
|
|
7613
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
7614
|
+
const path = url.includes('?') ? url.substring(0, url.indexOf('?')) : url;
|
|
7615
|
+
const match = /fhir\/R4\/?([^/]+)?\/?([^/]+)?\/?([^/]+)?\/?([^/]+)?/.exec(path);
|
|
7616
|
+
const resourceType = match === null || match === void 0 ? void 0 : match[1];
|
|
7617
|
+
const id = match === null || match === void 0 ? void 0 : match[2];
|
|
7618
|
+
const operation = match === null || match === void 0 ? void 0 : match[3];
|
|
7619
|
+
const versionId = match === null || match === void 0 ? void 0 : match[4];
|
|
7620
|
+
if (path.startsWith('fhir/R4/ValueSet/$expand')) {
|
|
7621
|
+
return exampleValueSet;
|
|
7615
7622
|
}
|
|
7616
|
-
else if (
|
|
7617
|
-
return this.
|
|
7623
|
+
else if (path === 'fhir/R4/$graphql') {
|
|
7624
|
+
return this.mockFhirGraphqlHandler(method, path, options);
|
|
7618
7625
|
}
|
|
7619
|
-
else {
|
|
7620
|
-
return
|
|
7626
|
+
else if (path === 'not-found' || id === 'not-found') {
|
|
7627
|
+
return notFound;
|
|
7621
7628
|
}
|
|
7622
|
-
|
|
7623
|
-
|
|
7624
|
-
|
|
7625
|
-
|
|
7626
|
-
|
|
7627
|
-
|
|
7628
|
-
|
|
7629
|
+
else if (method === 'POST') {
|
|
7630
|
+
if (resourceType && id && operation) {
|
|
7631
|
+
return allOk;
|
|
7632
|
+
}
|
|
7633
|
+
else if (resourceType) {
|
|
7634
|
+
return this.mockRepo.createResource(JSON.parse(options.body));
|
|
7635
|
+
}
|
|
7636
|
+
else {
|
|
7637
|
+
return this.mockFhirBatchHandler(method, path, options);
|
|
7638
|
+
}
|
|
7629
7639
|
}
|
|
7630
|
-
else if (
|
|
7631
|
-
|
|
7640
|
+
else if (method === 'GET') {
|
|
7641
|
+
if (resourceType && id && versionId) {
|
|
7642
|
+
return this.mockRepo.readVersion(resourceType, id, versionId);
|
|
7643
|
+
}
|
|
7644
|
+
else if (resourceType && id && operation === '_history') {
|
|
7645
|
+
return this.mockRepo.readHistory(resourceType, id);
|
|
7646
|
+
}
|
|
7647
|
+
else if (resourceType && id === '$csv') {
|
|
7648
|
+
return allOk;
|
|
7649
|
+
}
|
|
7650
|
+
else if (resourceType && id) {
|
|
7651
|
+
return this.mockRepo.readResource(resourceType, id);
|
|
7652
|
+
}
|
|
7653
|
+
else if (resourceType) {
|
|
7654
|
+
return this.mockRepo.search(parseSearchDefinition(url));
|
|
7655
|
+
}
|
|
7632
7656
|
}
|
|
7633
|
-
else if (
|
|
7634
|
-
return this.mockRepo.
|
|
7657
|
+
else if (method === 'PUT') {
|
|
7658
|
+
return this.mockRepo.updateResource(JSON.parse(options.body));
|
|
7635
7659
|
}
|
|
7636
|
-
else if (
|
|
7637
|
-
|
|
7638
|
-
|
|
7639
|
-
|
|
7640
|
-
else if (method === 'PUT') {
|
|
7641
|
-
return this.mockRepo.updateResource(JSON.parse(options.body));
|
|
7642
|
-
}
|
|
7643
|
-
else if (method === 'PATCH') {
|
|
7644
|
-
if (resourceType && id) {
|
|
7645
|
-
return this.mockRepo.patchResource(resourceType, id, JSON.parse(options.body));
|
|
7660
|
+
else if (method === 'PATCH') {
|
|
7661
|
+
if (resourceType && id) {
|
|
7662
|
+
return this.mockRepo.patchResource(resourceType, id, JSON.parse(options.body));
|
|
7663
|
+
}
|
|
7646
7664
|
}
|
|
7647
|
-
|
|
7648
|
-
|
|
7649
|
-
|
|
7650
|
-
|
|
7651
|
-
|
|
7665
|
+
else if (method === 'DELETE') {
|
|
7666
|
+
if (resourceType && id) {
|
|
7667
|
+
this.mockRepo.deleteResource(resourceType, id);
|
|
7668
|
+
return allOk;
|
|
7669
|
+
}
|
|
7652
7670
|
}
|
|
7653
|
-
|
|
7654
|
-
|
|
7671
|
+
throw notFound;
|
|
7672
|
+
});
|
|
7655
7673
|
}
|
|
7656
7674
|
mockFhirGraphqlHandler(_method, _path, options) {
|
|
7657
7675
|
const { body } = options;
|
|
@@ -7674,45 +7692,55 @@ class MockFetchClient {
|
|
|
7674
7692
|
return GraphQLSchemaResponse;
|
|
7675
7693
|
}
|
|
7676
7694
|
mockFhirBatchHandler(_method, _path, options) {
|
|
7677
|
-
|
|
7678
|
-
|
|
7679
|
-
|
|
7680
|
-
|
|
7681
|
-
|
|
7682
|
-
|
|
7683
|
-
|
|
7684
|
-
|
|
7695
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
7696
|
+
const { body } = options;
|
|
7697
|
+
const request = JSON.parse(body);
|
|
7698
|
+
let entry;
|
|
7699
|
+
if (request.entry) {
|
|
7700
|
+
entry = [];
|
|
7701
|
+
for (const input of request.entry) {
|
|
7702
|
+
entry.push(yield this.handleBatchEntry(input));
|
|
7703
|
+
}
|
|
7704
|
+
}
|
|
7705
|
+
return {
|
|
7706
|
+
resourceType: 'Bundle',
|
|
7707
|
+
type: 'batch-response',
|
|
7708
|
+
entry,
|
|
7709
|
+
};
|
|
7710
|
+
});
|
|
7685
7711
|
}
|
|
7686
7712
|
handleBatchEntry(input) {
|
|
7687
7713
|
var _a, _b;
|
|
7688
|
-
|
|
7689
|
-
|
|
7690
|
-
|
|
7691
|
-
|
|
7692
|
-
|
|
7693
|
-
|
|
7694
|
-
|
|
7714
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
7715
|
+
try {
|
|
7716
|
+
const url = 'fhir/R4/' + ((_a = input.request) === null || _a === void 0 ? void 0 : _a.url);
|
|
7717
|
+
const method = (_b = input.request) === null || _b === void 0 ? void 0 : _b.method;
|
|
7718
|
+
const resource = yield this.mockHandler(method, url, {
|
|
7719
|
+
body: input.resource ? JSON.stringify(input.resource) : undefined,
|
|
7720
|
+
});
|
|
7721
|
+
if ((resource === null || resource === void 0 ? void 0 : resource.resourceType) === 'OperationOutcome') {
|
|
7722
|
+
return {
|
|
7723
|
+
resource,
|
|
7724
|
+
response: { status: getStatus(resource).toString() },
|
|
7725
|
+
};
|
|
7726
|
+
}
|
|
7727
|
+
else if (resource) {
|
|
7728
|
+
return { resource, response: { status: '200' } };
|
|
7729
|
+
}
|
|
7730
|
+
else {
|
|
7731
|
+
return { resource: notFound, response: { status: '404' } };
|
|
7732
|
+
}
|
|
7733
|
+
}
|
|
7734
|
+
catch (err) {
|
|
7735
|
+
const outcome = err;
|
|
7695
7736
|
return {
|
|
7696
|
-
|
|
7697
|
-
|
|
7737
|
+
response: {
|
|
7738
|
+
status: getStatus(outcome).toString(),
|
|
7739
|
+
outcome,
|
|
7740
|
+
},
|
|
7698
7741
|
};
|
|
7699
7742
|
}
|
|
7700
|
-
|
|
7701
|
-
return { resource, response: { status: '200' } };
|
|
7702
|
-
}
|
|
7703
|
-
else {
|
|
7704
|
-
return { resource: notFound, response: { status: '404' } };
|
|
7705
|
-
}
|
|
7706
|
-
}
|
|
7707
|
-
catch (err) {
|
|
7708
|
-
const outcome = err;
|
|
7709
|
-
return {
|
|
7710
|
-
response: {
|
|
7711
|
-
status: getStatus(outcome).toString(),
|
|
7712
|
-
outcome,
|
|
7713
|
-
},
|
|
7714
|
-
};
|
|
7715
|
-
}
|
|
7743
|
+
});
|
|
7716
7744
|
}
|
|
7717
7745
|
}
|
|
7718
7746
|
|