@medplum/fhir-router 3.0.3 → 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/cjs/index.cjs
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
"use strict";var qi=Object.create;var At=Object.defineProperty;var Yi=Object.getOwnPropertyDescriptor;var Ji=Object.getOwnPropertyNames;var Ki=Object.getPrototypeOf,Xi=Object.prototype.hasOwnProperty;var zi=(e,t)=>{for(var n in t)At(e,n,{get:t[n],enumerable:!0})},zr=(e,t,n,r)=>{if(t&&typeof t=="object"||typeof t=="function")for(let i of Ji(t))!Xi.call(e,i)&&i!==n&&At(e,i,{get:()=>t[i],enumerable:!(r=Yi(t,i))||r.enumerable});return e};var Hi=(e,t,n)=>(n=e!=null?qi(Ki(e)):{},zr(t||!e||!e.__esModule?At(n,"default",{value:e,enumerable:!0}):n,e)),Wi=e=>zr(At({},"__esModule",{value:!0}),e);var _a={};zi(_a,{BaseRepository:()=>Rn,FhirRouter:()=>Yr,MemoryRepository:()=>Jr,Router:()=>Lt});module.exports=Wi(_a);var U=require("@medplum/core");var S=require("@medplum/core");async function Hr(e,t,n){return new _n(e,t,n).processBatch()}var _n=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 S.OperationOutcomeError((0,S.badRequest)("Missing bundle type"));if(t!=="batch"&&t!=="transaction")throw new S.OperationOutcomeError((0,S.badRequest)("Unrecognized bundle type"));let n=this.bundle.entry;if(!n)throw new S.OperationOutcomeError((0,S.badRequest)("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(wt((0,S.normalizeOperationOutcome)(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
|
|
1
|
+
"use strict";var qi=Object.create;var At=Object.defineProperty;var Yi=Object.getOwnPropertyDescriptor;var Ji=Object.getOwnPropertyNames;var Ki=Object.getPrototypeOf,Xi=Object.prototype.hasOwnProperty;var zi=(e,t)=>{for(var n in t)At(e,n,{get:t[n],enumerable:!0})},zr=(e,t,n,r)=>{if(t&&typeof t=="object"||typeof t=="function")for(let i of Ji(t))!Xi.call(e,i)&&i!==n&&At(e,i,{get:()=>t[i],enumerable:!(r=Yi(t,i))||r.enumerable});return e};var Hi=(e,t,n)=>(n=e!=null?qi(Ki(e)):{},zr(t||!e||!e.__esModule?At(n,"default",{value:e,enumerable:!0}):n,e)),Wi=e=>zr(At({},"__esModule",{value:!0}),e);var _a={};zi(_a,{BaseRepository:()=>Rn,FhirRouter:()=>Yr,MemoryRepository:()=>Jr,Router:()=>Lt});module.exports=Wi(_a);var U=require("@medplum/core");var S=require("@medplum/core");async function Hr(e,t,n){return new _n(e,t,n).processBatch()}var _n=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 S.OperationOutcomeError((0,S.badRequest)("Missing bundle type"));if(t!=="batch"&&t!=="transaction")throw new S.OperationOutcomeError((0,S.badRequest)("Unrecognized bundle type"));let n=this.bundle.entry;if(!n)throw new S.OperationOutcomeError((0,S.badRequest)("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(wt((0,S.normalizeOperationOutcome)(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((0,S.parseSearchRequest)(`${t.resource.resourceType}?${n.ifNoneExist}`))).entry;if(a.length>1)return wt((0,S.badRequest)("Multiple matches"));if(a.length===1){let c=a[0].resource;return t.fullUrl&&this.addReplacementId(t.fullUrl,c),wt(S.allOk,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]),wt(o[0],o[1])}validateEntry(t){if(!t.request)throw new S.OperationOutcomeError((0,S.badRequest)("Missing entry.request"));if(!t.request.method)throw new S.OperationOutcomeError((0,S.badRequest)("Missing entry.request.method"));if(!t.request.url)throw new S.OperationOutcomeError((0,S.badRequest)("Missing entry.request.url"))}parsePatchBody(t){let n=t.resource;if(!n)throw new S.OperationOutcomeError((0,S.badRequest)("Missing entry.resource"));if(n.resourceType!=="Binary")throw new S.OperationOutcomeError((0,S.badRequest)("Patch resource must be a Binary"));if(!n.data)throw new S.OperationOutcomeError((0,S.badRequest)("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=(0,S.getReferenceString)(o);return n&&(s=(0,S.resolveId)({reference:s})),s?t.replaceAll(i,s):t}}return t}};function wt(e,t){return{response:{outcome:e,status:(0,S.getStatus)(e).toString(),location:(0,S.isOk)(e)&&t?.id?(0,S.getReferenceString)(t):void 0},resource:t}}var G=require("@medplum/core"),ji=Hi(require("dataloader"));function O(e,t){if(!!!e)throw new Error(t)}function ae(e){return typeof e?.then=="function"}function q(e){return typeof e=="object"&&e!==null}function V(e,t){if(!!!e)throw new Error(t??"Unexpected invariant triggered.")}var Zi=/\r\n|[\n\r]/g;function Qe(e,t){let n=0,r=1;for(let i of e.body.matchAll(Zi)){if(typeof i.index=="number"||V(!1),i.index>=t)break;n=i.index+i[0].length,r+=1}return{line:r,column:t+1-n}}function xn(e){return Dt(e.source,Qe(e.source,e.start))}function Dt(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 C=0;C<d.length;C+=80)N.push(d.slice(C,C+80));return p+Wr([[`${s} |`,N[0]],...N.slice(1,h+1).map(C=>["|",C]),["|","^".padStart(T)],["|",N[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 eo(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}=eo(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(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=>Qe(a,N)):h?.map(N=>Qe(N.source,N.start));let T=q(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
|
|