@medplum/fhir-router 2.2.4 → 2.2.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.
- package/dist/cjs/index.cjs +1 -1
- package/dist/cjs/index.cjs.map +2 -2
- package/dist/esm/index.mjs +1 -1
- package/dist/esm/index.mjs.map +2 -2
- package/package.json +2 -2
package/dist/esm/index.mjs
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import{allOk as Ne,badRequest as On,created as Ba,normalizeOperationOutcome as qa,notFound as Ya,parseSearchRequest as Ki}from"@medplum/core";import{allOk as Zi,badRequest as he,getReferenceString as zr,getStatus as eo,isOk as to,normalizeOperationOutcome as no,OperationOutcomeError as Te,parseSearchUrl as ro,resolveId as io}from"@medplum/core";async function Hr(e,t,n){return new Sn(e,t,n).processBatch()}var Sn=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(no(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 s=`https://example.com/${t.resource.resourceType}`,a=new URL("?"+n.ifNoneExist,s),p=(await this.repo.search(ro(a))).entry;if(p.length>1)return xt(he("Multiple matches"));if(p.length===1){let l=p[0].resource;return t.fullUrl&&this.addReplacementId(t.fullUrl,l),xt(Zi,l)}}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"?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=zr(o);return n&&(s=io({reference:s})),s?t.replaceAll(i,s):t}}return t}};function xt(e,t){return{response:{outcome:e,status:eo(e).toString(),location:to(e)&&t?.id?zr(t):void 0},resource:t}}import{allOk as Ia,badRequest as _t,DEFAULT_SEARCH_COUNT as ba,forbidden as Oa,getResourceTypes as qi,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 oo=/\r\n|[\n\r]/g;function Me(e,t){let n=0,r=1;for(let i of e.body.matchAll(oo)){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 _n(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}
|
|
1
|
+
import{allOk as Ne,badRequest as On,created as Ba,normalizeOperationOutcome as qa,notFound as Ya,parseSearchRequest as Ki}from"@medplum/core";import{allOk as Zi,badRequest as he,getReferenceString as zr,getStatus as eo,isOk as to,normalizeOperationOutcome as no,OperationOutcomeError as Te,parseSearchUrl as ro,resolveId as io}from"@medplum/core";async function Hr(e,t,n){return new Sn(e,t,n).processBatch()}var Sn=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(no(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 s=`https://example.com/${t.resource.resourceType}`,a=new URL("?"+n.ifNoneExist,s),p=(await this.repo.search(ro(a))).entry;if(p.length>1)return xt(he("Multiple matches"));if(p.length===1){let l=p[0].resource;return t.fullUrl&&this.addReplacementId(t.fullUrl,l),xt(Zi,l)}}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=zr(o);return n&&(s=io({reference:s})),s?t.replaceAll(i,s):t}}return t}};function xt(e,t){return{response:{outcome:e,status:eo(e).toString(),location:to(e)&&t?.id?zr(t):void 0},resource:t}}import{allOk as Ia,badRequest as _t,DEFAULT_SEARCH_COUNT as ba,forbidden as Oa,getResourceTypes as qi,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 oo=/\r\n|[\n\r]/g;function Me(e,t){let n=0,r=1;for(let i of e.body.matchAll(oo)){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 _n(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,E=[];for(let w=0;w<d.length;w+=80)E.push(d.slice(w,w+80));return p+Wr([[`${s} |`,E[0]],...E.slice(1,h+1).map(w=>["|",w]),["|","^".padStart(T)],["|",E[h+1]]])}return p+Wr([[`${s-1} |`,l[i-1]],[`${s} |`,d],["|","^".padStart(c)],[`${s+1} |`,l[i+1]]])}function Wr(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 so(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}=so(n);super(t),this.name="GraphQLError",this.path=p??void 0,this.originalError=l??void 0,this.nodes=Zr(Array.isArray(s)?s:s?[s]:void 0);let h=Zr((r=this.nodes)===null||r===void 0?void 0:r.map(E=>E.loc).filter(E=>E!=null));this.source=a??(h==null||(i=h[0])===null||i===void 0?void 0:i.source),this.positions=c??h?.map(E=>E.start),this.locations=c&&a?c.map(E=>Me(a,E)):h?.map(E=>Me(E.source,E.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
|
|