@medplum/fhir-router 3.0.4 → 3.0.5
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.cjs +1 -1
- package/dist/cjs/index.cjs.map +3 -3
- package/dist/esm/index.mjs +1 -1
- package/dist/esm/index.mjs.map +3 -3
- package/package.json +4 -4
package/dist/esm/index.mjs
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import{allOk as Ne,badRequest as bn,created as Ba,normalizeOperationOutcome as qa,notFound as Ya,parseSearchRequest as Ji}from"@medplum/core";import{allOk as Wi,badRequest as he,getReferenceString as Kr,getStatus as Zi,isOk as eo,normalizeOperationOutcome as to,OperationOutcomeError as Te,
|
|
1
|
+
import{allOk as Ne,badRequest as bn,created as Ba,normalizeOperationOutcome as qa,notFound as Ya,parseSearchRequest as Ji}from"@medplum/core";import{allOk as Wi,badRequest as he,getReferenceString as Kr,getStatus as Zi,isOk as eo,normalizeOperationOutcome as to,OperationOutcomeError as Te,parseSearchRequest as no,resolveId as ro}from"@medplum/core";async function Xr(e,t,n){return new Rn(e,t,n).processBatch()}var Rn=class{constructor(t,n,r){this.router=t;this.repo=n;this.bundle=r;this.ids={}}async processBatch(){let t=this.bundle.type;if(!t)throw new Te(he("Missing bundle type"));if(t!=="batch"&&t!=="transaction")throw new Te(he("Unrecognized bundle type"));let n=this.bundle.entry;if(!n)throw new Te(he("Missing bundle entry"));let r=[];for(let i of n){let o=this.rewriteIdsInObject(i);i.resource?.id&&(o.resource.id=this.rewriteIdsInString(i.resource.id,!0));try{r.push(await this.processBatchEntry(o))}catch(s){r.push(xt(to(s)))}}return{resourceType:"Bundle",type:t+"-response",entry:r}}async processBatchEntry(t){this.validateEntry(t);let n=t.request;if(t.resource?.resourceType&&n.ifNoneExist){let a=(await this.repo.search(no(`${t.resource.resourceType}?${n.ifNoneExist}`))).entry;if(a.length>1)return xt(he("Multiple matches"));if(a.length===1){let c=a[0].resource;return t.fullUrl&&this.addReplacementId(t.fullUrl,c),xt(Wi,c)}}let r=t.resource;n.method==="PATCH"&&(r=this.parsePatchBody(t));let i=new URL(n.url,"https://example.com/"),o=await this.router.handleRequest({method:n.method,pathname:i.pathname,params:Object.create(null),query:Object.fromEntries(i.searchParams),body:r},this.repo);return t.fullUrl&&o.length===2&&this.addReplacementId(t.fullUrl,o[1]),xt(o[0],o[1])}validateEntry(t){if(!t.request)throw new Te(he("Missing entry.request"));if(!t.request.method)throw new Te(he("Missing entry.request.method"));if(!t.request.url)throw new Te(he("Missing entry.request.url"))}parsePatchBody(t){let n=t.resource;if(!n)throw new Te(he("Missing entry.resource"));if(n.resourceType!=="Binary")throw new Te(he("Patch resource must be a Binary"));if(!n.data)throw new Te(he("Missing entry.resource.data"));return this.rewriteIdsInArray(JSON.parse(Buffer.from(n.data,"base64").toString("utf8")))}addReplacementId(t,n){t.startsWith("urn:uuid:")&&(this.ids[t]=n)}rewriteIds(t){return Array.isArray(t)?this.rewriteIdsInArray(t):typeof t=="string"?this.rewriteIdsInString(t):typeof t=="object"&&t!==null?this.rewriteIdsInObject(t):t}rewriteIdsInArray(t){return t.map(n=>this.rewriteIds(n))}rewriteIdsInObject(t){return Object.fromEntries(Object.entries(t).map(([n,r])=>[n,this.rewriteIds(r)]))}rewriteIdsInString(t,n=!1){let r=/urn:uuid:\w{8}-\w{4}-\w{4}-\w{4}-\w{12}/.exec(t);if(r){let i=r[0],o=this.ids[i];if(o){let s=Kr(o);return n&&(s=ro({reference:s})),s?t.replaceAll(i,s):t}}return t}};function xt(e,t){return{response:{outcome:e,status:Zi(e).toString(),location:eo(e)&&t?.id?Kr(t):void 0},resource:t}}import{allOk as Ia,badRequest as _t,DEFAULT_SEARCH_COUNT as ba,forbidden as Oa,getResourceTypes as Bi,LRUCache as Ra,normalizeOperationOutcome as Sa,OperationOutcomeError as _a}from"@medplum/core";import xa from"dataloader";function O(e,t){if(!!!e)throw new Error(t)}function ne(e){return typeof e?.then=="function"}function M(e){return typeof e=="object"&&e!==null}function k(e,t){if(!!!e)throw new Error(t??"Unexpected invariant triggered.")}var io=/\r\n|[\n\r]/g;function Me(e,t){let n=0,r=1;for(let i of e.body.matchAll(io)){if(typeof i.index=="number"||k(!1),i.index>=t)break;n=i.index+i[0].length,r+=1}return{line:r,column:t+1-n}}function Sn(e){return Lt(e.source,Me(e.source,e.start))}function Lt(e,t){let n=e.locationOffset.column-1,r="".padStart(n)+e.body,i=t.line-1,o=e.locationOffset.line-1,s=t.line+o,a=t.line===1?n:0,c=t.column+a,p=`${e.name}:${s}:${c}
|
|
2
2
|
`,l=r.split(/\r\n|[\n\r]/g),d=l[i];if(d.length>120){let h=Math.floor(c/80),T=c%80,N=[];for(let D=0;D<d.length;D+=80)N.push(d.slice(D,D+80));return p+zr([[`${s} |`,N[0]],...N.slice(1,h+1).map(D=>["|",D]),["|","^".padStart(T)],["|",N[h+1]]])}return p+zr([[`${s-1} |`,l[i-1]],[`${s} |`,d],["|","^".padStart(c)],[`${s+1} |`,l[i+1]]])}function zr(e){let t=e.filter(([r,i])=>i!==void 0),n=Math.max(...t.map(([r])=>r.length));return t.map(([r,i])=>r.padStart(n)+(i?" "+i:"")).join(`
|
|
3
3
|
`)}function oo(e){let t=e[0];return t==null||"kind"in t||"length"in t?{nodes:t,source:e[1],positions:e[2],path:e[3],originalError:e[4],extensions:e[5]}:t}var f=class e extends Error{constructor(t,...n){var r,i,o;let{nodes:s,source:a,positions:c,path:p,originalError:l,extensions:d}=oo(n);super(t),this.name="GraphQLError",this.path=p??void 0,this.originalError=l??void 0,this.nodes=Hr(Array.isArray(s)?s:s?[s]:void 0);let h=Hr((r=this.nodes)===null||r===void 0?void 0:r.map(N=>N.loc).filter(N=>N!=null));this.source=a??(h==null||(i=h[0])===null||i===void 0?void 0:i.source),this.positions=c??h?.map(N=>N.start),this.locations=c&&a?c.map(N=>Me(a,N)):h?.map(N=>Me(N.source,N.start));let T=M(l?.extensions)?l?.extensions:void 0;this.extensions=(o=d??T)!==null&&o!==void 0?o:Object.create(null),Object.defineProperties(this,{message:{writable:!0,enumerable:!0},name:{enumerable:!1},nodes:{enumerable:!1},source:{enumerable:!1},positions:{enumerable:!1},originalError:{enumerable:!1}}),l!=null&&l.stack?Object.defineProperty(this,"stack",{value:l.stack,writable:!0,configurable:!0}):Error.captureStackTrace?Error.captureStackTrace(this,e):Object.defineProperty(this,"stack",{value:Error().stack,writable:!0,configurable:!0})}get[Symbol.toStringTag](){return"GraphQLError"}toString(){let t=this.message;if(this.nodes)for(let n of this.nodes)n.loc&&(t+=`
|
|
4
4
|
|