@medplum/mock 2.0.0 → 2.0.2

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.
@@ -1,8 +1,8 @@
1
1
  (function (global, factory) {
2
- typeof exports === 'object' && typeof module !== 'undefined' ? factory(exports, require('@medplum/core'), require('fast-json-patch')) :
3
- typeof define === 'function' && define.amd ? define(['exports', '@medplum/core', 'fast-json-patch'], factory) :
4
- (global = typeof globalThis !== 'undefined' ? globalThis : global || self, factory((global.medplum = global.medplum || {}, global.medplum.mock = {}), global.medplum.core, global["fast-json-patch"]));
5
- })(this, (function (exports, core, fastJsonPatch) { 'use strict';
2
+ typeof exports === 'object' && typeof module !== 'undefined' ? factory(exports, require('@medplum/core'), require('rfc6902')) :
3
+ typeof define === 'function' && define.amd ? define(['exports', '@medplum/core', 'rfc6902'], factory) :
4
+ (global = typeof globalThis !== 'undefined' ? globalThis : global || self, factory((global.medplum = global.medplum || {}, global.medplum.mock = {}), global.medplum.core, global.rfc6902));
5
+ })(this, (function (exports, core, rfc6902) { 'use strict';
6
6
 
7
7
  const ExampleAccessPolicy = {
8
8
  resourceType: 'AccessPolicy',
@@ -16595,17 +16595,14 @@
16595
16595
  }
16596
16596
  async patchResource(resourceType, id, patch) {
16597
16597
  const resource = this.readResource(resourceType, id);
16598
- let patchResult;
16599
- try {
16600
- patchResult = fastJsonPatch.applyPatch(resource, patch, true);
16601
- }
16602
- catch (err) {
16603
- const patchError = err;
16604
- const message = patchError.message?.split('\n')?.[0] || 'JSONPatch error';
16605
- throw core.badRequest(message);
16598
+ const patchErrors = rfc6902.applyPatch(resource, patch);
16599
+ for (const error of patchErrors) {
16600
+ if (error) {
16601
+ const message = error.message?.split('\n')?.[0] || 'JSONPatch error';
16602
+ throw core.badRequest(message);
16603
+ }
16606
16604
  }
16607
- const patchedResource = patchResult.newDocument;
16608
- return this.updateResource(patchedResource);
16605
+ return this.updateResource(resource);
16609
16606
  }
16610
16607
  readResource(resourceType, id) {
16611
16608
  const resource = __classPrivateFieldGet(this, _MemoryRepository_resources, "f")?.[resourceType]?.[id];