@medplum/fhir-router 2.0.4 → 2.0.6

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.
@@ -74,14 +74,14 @@
74
74
  async processBatch() {
75
75
  const bundleType = this.bundle.type;
76
76
  if (!bundleType) {
77
- throw core.badRequest('Missing bundle type');
77
+ throw new core.OperationOutcomeError(core.badRequest('Missing bundle type'));
78
78
  }
79
79
  if (bundleType !== 'batch' && bundleType !== 'transaction') {
80
- throw core.badRequest('Unrecognized bundle type');
80
+ throw new core.OperationOutcomeError(core.badRequest('Unrecognized bundle type'));
81
81
  }
82
82
  const entries = this.bundle.entry;
83
83
  if (!entries) {
84
- throw core.badRequest('Missing bundle entry');
84
+ throw new core.OperationOutcomeError(core.badRequest('Missing bundle entry'));
85
85
  }
86
86
  const resultEntries = [];
87
87
  for (const entry of entries) {
@@ -90,12 +90,12 @@
90
90
  resultEntries.push(await __classPrivateFieldGet(this, _BatchProcessor_instances, "m", _BatchProcessor_processBatchEntry).call(this, rewritten));
91
91
  }
92
92
  catch (err) {
93
- resultEntries.push(buildBundleResponse(err));
93
+ resultEntries.push(buildBundleResponse(core.normalizeOperationOutcome(err)));
94
94
  }
95
95
  }
96
96
  return {
97
97
  resourceType: 'Bundle',
98
- type: 'batch-response',
98
+ type: (bundleType + '-response'),
99
99
  entry: resultEntries,
100
100
  };
101
101
  }
@@ -118,7 +118,11 @@
118
118
  return buildBundleResponse(core.badRequest('Multiple matches'));
119
119
  }
120
120
  if (entries.length === 1) {
121
- return buildBundleResponse(core.allOk, entries[0].resource);
121
+ const matchingResource = entries[0].resource;
122
+ if (entry.fullUrl) {
123
+ __classPrivateFieldGet(this, _BatchProcessor_instances, "m", _BatchProcessor_addReplacementId).call(this, entry.fullUrl, matchingResource);
124
+ }
125
+ return buildBundleResponse(core.allOk, matchingResource);
122
126
  }
123
127
  }
124
128
  let body = entry.resource;
@@ -141,24 +145,24 @@
141
145
  return buildBundleResponse(result[0], result[1]);
142
146
  }, _BatchProcessor_validateEntry = function _BatchProcessor_validateEntry(entry) {
143
147
  if (!entry.request) {
144
- throw core.badRequest('Missing entry.request');
148
+ throw new core.OperationOutcomeError(core.badRequest('Missing entry.request'));
145
149
  }
146
150
  if (!entry.request.method) {
147
- throw core.badRequest('Missing entry.request.method');
151
+ throw new core.OperationOutcomeError(core.badRequest('Missing entry.request.method'));
148
152
  }
149
153
  if (!entry.request.url) {
150
- throw core.badRequest('Missing entry.request.url');
154
+ throw new core.OperationOutcomeError(core.badRequest('Missing entry.request.url'));
151
155
  }
152
156
  }, _BatchProcessor_parsePatchBody = function _BatchProcessor_parsePatchBody(entry) {
153
157
  const patchResource = entry.resource;
154
158
  if (!patchResource) {
155
- throw core.badRequest('Missing entry.resource');
159
+ throw new core.OperationOutcomeError(core.badRequest('Missing entry.resource'));
156
160
  }
157
161
  if (patchResource.resourceType !== 'Binary') {
158
- throw core.badRequest('Patch resource must be a Binary');
162
+ throw new core.OperationOutcomeError(core.badRequest('Patch resource must be a Binary'));
159
163
  }
160
164
  if (!patchResource.data) {
161
- throw core.badRequest('Missing entry.resource.data');
165
+ throw new core.OperationOutcomeError(core.badRequest('Missing entry.resource.data'));
162
166
  }
163
167
  return JSON.parse(Buffer.from(patchResource.data, 'base64').toString('utf8'));
164
168
  }, _BatchProcessor_addReplacementId = function _BatchProcessor_addReplacementId(fullUrl, resource) {
@@ -13529,7 +13533,7 @@ spurious results.`);
13529
13533
  function buildPropertyFields(resourceType, fields) {
13530
13534
  const schema = core.getResourceTypeSchema(resourceType);
13531
13535
  const properties = schema.properties;
13532
- if (core.isResourceType(schema)) {
13536
+ if (core.isResourceTypeSchema(schema)) {
13533
13537
  fields.resourceType = {
13534
13538
  type: new GraphQLNonNull(GraphQLString),
13535
13539
  description: 'Resource Type',
@@ -13695,7 +13699,7 @@ spurious results.`);
13695
13699
  return await ctx.dataLoader.load({ reference: `${info.fieldName}/${args.id}` });
13696
13700
  }
13697
13701
  catch (err) {
13698
- throw new Error(core.normalizeErrorString(err));
13702
+ throw new core.OperationOutcomeError(core.normalizeOperationOutcome(err), err);
13699
13703
  }
13700
13704
  }
13701
13705
  /**
@@ -13712,7 +13716,7 @@ spurious results.`);
13712
13716
  return await ctx.dataLoader.load(source);
13713
13717
  }
13714
13718
  catch (err) {
13715
- throw new Error(core.normalizeErrorString(err));
13719
+ throw new core.OperationOutcomeError(core.normalizeOperationOutcome(err), err);
13716
13720
  }
13717
13721
  }
13718
13722
  /**
@@ -14020,25 +14024,25 @@ spurious results.`);
14020
14024
  try {
14021
14025
  const patchResult = rfc6902.applyPatch(resource, patch).filter(Boolean);
14022
14026
  if (patchResult.length > 0) {
14023
- throw core.badRequest(patchResult.map((e) => e.message).join('\n'));
14027
+ throw new core.OperationOutcomeError(core.badRequest(patchResult.map((e) => e.message).join('\n')));
14024
14028
  }
14025
14029
  }
14026
14030
  catch (err) {
14027
- throw core.badRequest(core.normalizeErrorString(err));
14031
+ throw new core.OperationOutcomeError(core.normalizeOperationOutcome(err));
14028
14032
  }
14029
14033
  return this.updateResource(resource);
14030
14034
  }
14031
14035
  async readResource(resourceType, id) {
14032
14036
  const resource = __classPrivateFieldGet(this, _MemoryRepository_resources, "f")?.[resourceType]?.[id];
14033
14037
  if (!resource) {
14034
- throw core.notFound;
14038
+ throw new core.OperationOutcomeError(core.notFound);
14035
14039
  }
14036
14040
  return core.deepClone(resource);
14037
14041
  }
14038
14042
  async readReference(reference) {
14039
14043
  const parts = reference.reference?.split('/');
14040
14044
  if (!parts || parts.length !== 2) {
14041
- throw core.badRequest('Invalid reference');
14045
+ throw new core.OperationOutcomeError(core.badRequest('Invalid reference'));
14042
14046
  }
14043
14047
  return this.readResource(parts[0], parts[1]);
14044
14048
  }
@@ -14059,7 +14063,7 @@ spurious results.`);
14059
14063
  await this.readResource(resourceType, id);
14060
14064
  const version = __classPrivateFieldGet(this, _MemoryRepository_history, "f")?.[resourceType]?.[id]?.find((v) => v.meta?.versionId === versionId);
14061
14065
  if (!version) {
14062
- throw core.notFound;
14066
+ throw new core.OperationOutcomeError(core.notFound);
14063
14067
  }
14064
14068
  return core.deepClone(version);
14065
14069
  }
@@ -14088,7 +14092,7 @@ spurious results.`);
14088
14092
  }
14089
14093
  async deleteResource(resourceType, id) {
14090
14094
  if (!__classPrivateFieldGet(this, _MemoryRepository_resources, "f")?.[resourceType]?.[id]) {
14091
- throw core.notFound;
14095
+ throw new core.OperationOutcomeError(core.notFound);
14092
14096
  }
14093
14097
  delete __classPrivateFieldGet(this, _MemoryRepository_resources, "f")[resourceType][id];
14094
14098
  }