@zuplo/core 6.19.4 → 6.19.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/index.minified.js CHANGED
@@ -589,7 +589,8 @@ globstar while`,s,Z,l,Re,Ae),this.matchOne(s.slice(Z),l.slice(Re),_))return this
589
589
  `?(A=0,M++):A++;this.column=A,this.line=M;return}}let{length:_}=s,{lineEnd:m}=this;_>0&&(this.lineEndSize>0&&(m.length===1?s[_-1]===m:s.endsWith(m))?(this.line+=this.lineEndSize,this.column=0):this.column+=_)}toString(){return this.output}};function Ymt(a,s){let l=new D8e(s);return l.generator[a.type](a,l),l.output}t(Ymt,"generate");import Xhr from"fs/promises";import Qhr from"path";async function k8e({oasFiles:a,sourceDirectory:s,logger:l}){let _=await Zhr({oasFiles:a,sourceDirectory:s,logger:l});return Ymt(_)}t(k8e,"generateRawRouteSource");async function Zhr({oasFiles:a,sourceDirectory:s,logger:l}){let _=new p3(s,l),m=[];for(let D of a){let A=Qhr.basename(D,".oas.json"),M=await _.resolve(D),U=[],ne=new Map,se=await Xhr.readFile(D,"utf-8"),Z=JSON.parse(se);for(let Re in Z.paths){let Ae=Z.paths[Re];for(let ke in Ae){if(ke.startsWith("x-"))continue;let{description:Ot,...kt}=Ae[ke],br=eG(A,Re,ke),Kr=ife(D,A,kt,M,U,ne);m.unshift(Qmt(br,Kr))}}m.unshift(...egr(A,M,U,ne).reverse())}return{type:"Program",body:m,sourceType:"module"}}t(Zhr,"generateAst");function ife(a,s,l,_,m,b){let D=[];for(let A in l){let M=l[A];if(A==="$ref")return RH(a,s,i3(a,M),_,m,b),{type:"Identifier",name:Zmt(s,b.get(i3(a,M)))};let U;switch(typeof M){case"string":case"number":case"boolean":U={type:"Literal",value:M};break;default:Array.isArray(M)?U=Xmt(M,a,s,_,m,b):typeof M=="object"&&M!==null&&(U={type:"ObjectExpression",properties:ife(a,s,M,_,m,b).properties||[]});break}if(U){let ne=/^[a-zA-Z_$][0-9a-zA-Z_$]*$/.test(A),se=ne?{type:"Identifier",name:A}:{type:"Literal",value:A};D.push({type:"Property",key:se,value:U,kind:"init",method:!1,shorthand:!1,computed:!ne})}}return{type:"ObjectExpression",properties:D}}t(ife,"processNode");function Xmt(a,s,l,_,m,b){return{type:"ArrayExpression",elements:a.map(D=>{if(Array.isArray(D))return Xmt(D,s,l,_,m,b);if(typeof D=="object"&&D!==null){let A=ife(s,l,D,_,m,b);return A.type==="Identifier"?A:{type:"ObjectExpression",properties:A.properties||[]}}else return{type:"Literal",value:D}})}}t(Xmt,"processArray");function Qmt(a,s){return{type:"ExportNamedDeclaration",declaration:{type:"VariableDeclaration",declarations:[{type:"VariableDeclarator",id:{type:"Identifier",name:a},init:s}],kind:"var"},specifiers:[],source:null}}t(Qmt,"createExportedConstAssignment");function egr(a,s,l,_){let m=[];for(let b=0;b<l.length;b++){let D=Zmt(a,b),A=s.get(l[b]),M=ife(U6e(l[b]),a,A,s,l,_);m.push(Qmt(D,M))}return m}t(egr,"generateRefs");function Zmt(a,s){return`${nA(a)}__ref__${s}`}t(Zmt,"getRefIdentifierName");import eht from"path";var tht=t(a=>{let s=null;if(a.value.type==="Object"&&a.value.members.length>0)for(let l of a.value.members){let _=tht(l);if(_!==null&&(s=_),l.name.value==="enum"&&l.value.type==="Array"&&l.value.elements.length===0){let m=l.value,b=m.loc.start.line,D=m.loc.start.column,A=m.loc.end.column;s={line:b,column:D,length:A-D,lineText:""}}}return s},"findEmptyEnums"),tgr=t(a=>{if(a.startsWith("schema with key or id")&&a.endsWith("already exists"))return"Update your schema's '$id' to be unique across your project.";if(a.includes("All JSON schemas must use version 2020-12"))return"All JSON schemas must use version 2020-12. See release notes for changes: https://json-schema.org/draft/2020-12/release-notes.html";if(a==='"nullable" cannot be used without "type"')return'Property "nullable" can only be used when property "type" value is "object".';if(a==='NOT SUPPORTED: keyword "id", use "$id" for schema ID')return'Replace keyword "id" with "$id" when defining a schema Id.';if(a.startsWith("can't resolve reference http"))return"Cannot resolve remote references, try adding them directly to the schema file or as a schema file in the project.";if(a.startsWith("can't resolve reference"))return"Make sure all references are defined in the schema.";if(a.includes("oneOf must NOT have fewer than 1 items"))return'Property "oneOf" must have at least 1 item configured.';if(a.includes("enum must have non-empty array"))return'Property "enum" must be configured with at least one value.';if(a.includes("Unexpected")&&a.includes("in JSON at position"))return"Update your schema to only use valid properties."},"getSuggestions"),w8e=t(async(a,s,l)=>{if(!a)return null;let _={file:eht.join(M6e,a),suggestion:tgr(l)},m=eht.join(s,M6e),b=cl.safePath(s).resolve(m,a),D=await Qce(b);if(l.includes("enum must have non-empty array")){if(D){let A=await LH(D);if(A&&A.body.members!==null)for(let M of A.body.members){let U=tht(M);U&&U!==null&&(_=Object.assign(_??{},U))}if(_){let M=_.line?_.line:0;_.lineText=FH(D,M)}}}else if(l.includes("Unexpected")&&l.includes("in JSON at position")&&D){let A=await LH(D);A&&"lineText"in A&&(_=Object.assign(_??{},A))}return _},"getLocation");import*as Wyt from"esbuild";import{performance as sfe,PerformanceObserver as rgr}from"perf_hooks";var P8e=[];async function ngr(a,s){let l=sfe.timerify(s),_=new rgr(m=>{let b=m.getEntries()[0];P8e.push({name:a,duration:b.duration}),_.disconnect()});return _.observe({entryTypes:["function"]}),l()}t(ngr,"timeFn");var igr={mark:t(a=>{sfe.mark(a)},"mark"),measure:t((a,s,l)=>{sfe.measure(a,s,l)},"measure"),timeFn:ngr,report:t(()=>{P8e.length>0&&console.table(P8e)},"report"),getDuration:t(a=>{let s=sfe.getEntriesByName(a);return s.length===0?0:s[0].duration},"getDuration")},hf=igr;var sgr=!1;function nj(a,s){return{open:`\x1B[${a.join(";")}m`,close:`\x1B[${s}m`,regexp:new RegExp(`\\x1b\\[${s}m`,"g")}}t(nj,"code");function ij(a,s){return sgr?`${s.open}${a.replace(s.regexp,s.open)}${s.close}`:a}t(ij,"run");function agr(a){return ij(a,nj([31],39))}t(agr,"red");function ogr(a){return ij(a,nj([32],39))}t(ogr,"green");function cgr(a){return ij(a,nj([33],39))}t(cgr,"yellow");function lgr(a){return ij(a,nj([34],39))}t(lgr,"blue");function ugr(a){return ij(a,nj([35],39))}t(ugr,"magenta");function fgr(a){return ij(a,nj([36],39))}t(fgr,"cyan");var mLr=new RegExp(["[\\u001B\\u009B][[\\]()#;?]*(?:(?:(?:[a-zA-Z\\d]*(?:;[-a-zA-Z\\d\\/#&.:=?%@~_]*)*)?\\u0007)","(?:(?:\\d{1,4}(?:;\\d{0,4})*)?[\\dA-PR-TZcf-ntqry=><~]))"].join("|"),"g");var rht=[agr,ogr,cgr,lgr,ugr,fgr];function _gr(a){let s=0,l=a.length,_=0;if(l>0)for(;_<l;)s=(s<<5)-s+a.charCodeAt(_++)|0;return s}t(_gr,"hashCode");function nht(a){let s=Math.abs(_gr(a));return rht[s%rht.length]}t(nht,"generateColor");import{inspect as pgr}from"util";function iht(a,s,...l){let _=0,m=l.length,b=String(s).replace(/%[sdjoO%]/g,D=>{if(D==="%%")return"%";if(_>=m)return D;switch(D){case"%s":return String(l[_++]);case"%d":return Number(l[_++]).toString();case"%o":return a(l[_++]).split(`
590
590
  `).map(A=>A.trim()).join(" ");case"%O":return a(l[_++]);case"%j":try{return JSON.stringify(l[_++])}catch{return"[Circular]"}default:return D}});for(let D of l.splice(_))D===null||!(typeof D=="object"&&D!==null)?b+=" "+D:b+=" "+a(D);return b}t(iht,"format");var sht=t((a,...s)=>iht(pgr,a,s),"format");var A8e=class{static{t(this,"Debugger")}manager;ns;color;last;enabled;constructor(s,l){this.manager=s,this.ns=l,this.color=nht(l),this.last=0,this.enabled=s.enabled.some(_=>_.test(l))}log(...s){if(!this.enabled)return;let l,_=s[0];typeof _=="function"?l=_():l=String(_);let m=Date.now()-(this.last||Date.now());l=sht(l,...s);let b=`${this.color(this.ns)} ${l} ${this.color(`+${m}ms`)}`;console.log(b),this.last=Date.now()}},N8e=class{static{t(this,"DebugManager")}debuggers;enabled;constructor(s){this.debuggers=new Map,this.enabled=s??[]}};function dgr(a){return!a||a.length===0?[]:(a=a.replace(/\s/g,"").replace(/\*/g,".+"),a.split(",").map(s=>new RegExp(`^${s}$`)))}t(dgr,"extract");var afe;function aht(a){afe||(afe=new N8e(dgr(process.env.DEBUG)));let s=new A8e(afe,a);return afe.debuggers.set(a,s),Object.assign(s.log.bind(s),{self:s})}t(aht,"debug");import t7e,{dirname as zyt}from"path";import{fileURLToPath as qyt}from"url";var I8e=class{static{t(this,"Environment")}get DEV_SERVER_PORT(){return process.env.DEV_SERVER_PORT?parseInt(process.env.DEV_SERVER_PORT):3e3}get DEBUG_BUILD_MODE(){return!!process.env.DEBUG_BUILD_MODE}get USE_MONOREPO_PACKAGES(){return process.env.USE_MONOREPO_PACKAGES==="true"}get EXPERIMENTAL_CODEGEN(){return!!process.env.EXPERIMENTAL_CODEGEN}get NODE_ENV(){return process.env.NODE_ENV}isProduction(){return this.NODE_ENV==="production"}isLocalDevelopment(){return process.env.ZUPLO_IS_LOCAL_DEVELOPMENT==="true"}},mgr=new I8e,Ym=mgr;var O8e="no-remote-module";function oht({logger:a}){return{name:O8e,async setup(s){s.onResolve({filter:/^https?:\/\//},l=>(a.error(l,"User attempted to load a remote module"),{errors:[{text:`Remote modules are not supported. Attempted to load module ${l.path}`,detail:"InvalidRemoteModule",pluginName:O8e,location:{line:0,column:0,file:""}}],pluginName:O8e}))}}}t(oht,"blockRemoteModulePlugin");import ygr from"fs/promises";import ofe from"path";import{writeFile as hgr}from"fs/promises";async function ok(a,s){await cl.mkdirForFilePathIfNotExits(a);let l=await import("prettier"),_=s;try{_=await l.format(s,{parser:"babel"})}catch{}await hgr(a,_,"utf-8")}t(ok,"writeDebugSourceFile");import cht from"path";var ggr=["zudoku.config.ts","zudoku.config.tsx","zudoku.config.js","zudoku.config.jsx","zudoku.config.mjs"];async function F8e(a){if(await cl.fileExists(`${a}/config/dev-portal.json`))return"dev-portal";for(let s of ggr)if(await cl.fileExists(`${a}/docs/${s}`))return"zudoku"}t(F8e,"getDevPortalType");function sj(a,s){let l=cht.relative(process.cwd(),cht.join(a,SO));return Object.keys(s?.outputs??{}).map(m=>`.${m.replace(l,"")}`)}t(sj,"getBuildModules");var lht="/docs",vgr="/__zuplo/dev-portal";function bgr(a){let s=a.trim().toLowerCase();return s.endsWith("/")&&(s=s.slice(0,-1)),s}t(bgr,"normalizePathname");function Sgr(a){let s={sitePathname:a?.sitePathname===vgr?lht:a?.sitePathname?bgr(a.sitePathname):lht,enabled:a?a.enabled??!0:!1,version:a?.version??"legacy"};return`const devPortal = ${JSON.stringify(s)};
591
591
  export default devPortal;`}t(Sgr,"generateSource");function uht(a){return{name:"dev-portal-config",setup(s){s.onResolve({filter:/dev-portal.json$/},l=>({namespace:"dev-portal-json",path:ofe.isAbsolute(l.path)?l.path:ofe.join(l.resolveDir,l.path),pluginName:"dev-portal"})),s.onLoad({filter:/.*/,namespace:"dev-portal-json"},async l=>hf.timeFn("Generating dev-portal.json data",async()=>{let _,m,b=[],D=await F8e(a.sourceDirectory);if(D==="zudoku")_={version:"zudoku",enabled:!0,sitePathname:"/docs"};else if(D==="dev-portal"){m=await ygr.readFile(l.path,"utf-8");try{_=JSON.parse(m)}catch{b.push({id:"dev-portal-build-error",text:"Could not parse dev-portal.json. Ensure that the file is valid JSON.",location:{file:"dev-portal.json",namespace:"dev-portal-json",line:1,column:0,length:0,lineText:"",suggestion:""},detail:"DevPortalValidationError",pluginName:"dev-portal",notes:[{text:"Could not parse dev-portal.json. Ensure that the file is valid JSON.",location:null}]})}}if(b&&b.length>0)throw b;let A;try{if(A=Sgr(_),Ym.DEBUG_BUILD_MODE&&A){let M=ofe.join(a.sourceDirectory,".zuplo","dev-portal.js");await ok(M,A)}if(b&&b.length>0)throw b}catch(M){M.length>0?M.forEach(U=>{let ne={id:"dev-portal-build-error",text:U.message,location:{file:"dev-portal.json",namespace:"dev-portal-json",line:1,column:0,length:0,lineText:"issue",suggestion:""},detail:"DevPortalValidationError",pluginName:"dev-portal",notes:[{text:U.message,location:null}]};b.push(ne)}):b.push({id:"dev-portal-build-error",text:M.message,location:{file:"dev-portal.json",namespace:"dev-portal-json",line:1,column:0,length:0,lineText:"issue",suggestion:""},detail:"DevPortalValidationError",pluginName:"dev-portal",notes:[{text:M.message,location:null}]})}return{contents:A,errors:b,pluginName:"dev-portal",loader:"js",resolveDir:ofe.dirname(l.path),watchFiles:[l.path]}}))}}}t(uht,"devPortalConfigPlugin");import fht from"path";var _ht="legacy-environment",pht="legacy-environment",Tgr=`import { environment } from "@zuplo/runtime";
592
- export default environment;`;function dht(a){return{name:"environment",setup(s){s.onResolve({filter:/@app\/environment$/},()=>({namespace:pht,pluginName:_ht,path:fht.join(a.sourceDirectory,e3,"environment.js")})),s.onLoad({filter:/.*/,namespace:pht},async l=>({contents:Tgr,loader:"ts",resolveDir:fht.dirname(l.path),pluginName:_ht}))}}}t(dht,"environmentPlugin");var Eyt=S_(xFe(),1),Dyt=S_(H0t(),1),kyt=S_(GFe(),1),wyt=S_(KFe(),1);import SSr from"fs/promises";import q2 from"path";var dk="schemas",zfe="json-schema";function Pyt(a){return{name:dk,async setup(s){let l=new kyt.Ajv2020({code:{source:!0},allErrors:!0,strict:!1,verbose:!0,meta:!0});(0,Dyt.default)(l,{mode:"fast"}),l.opts.code.formats=Eyt._`require("ajv-formats/dist/formats").fastFormats`;let _=q2.join(a.sourceDirectory,uH),m,b=[],D=[];if(await cl.dirExists(_)&&(l.addKeyword("faker"),m=await cl.listFolderContents(_,uH),await Promise.all(m.map(async A=>{try{let M=cl.safePath(a.sourceDirectory).resolve(_,A);if(!M.startsWith(_))throw new Error("All schemas must be in the schemas directory");let U=await SSr.readFile(M,"utf-8");if(U===""||U===void 0)throw new Error(`Schema 'schemas/${A}' is empty and will be ignored.`);let ne=JSON.parse(U);if(ne.$schema&&ne.$schema!=="https://json-schema.org/draft/2020-12/schema")throw new Error(`Error in ${A}: All JSON schemas must use version 2020-12. See release notes for changes: https://json-schema.org/draft/2020-12/release-notes.html`);if(l.$dataMetaSchema,l.addSchema(ne,A),l.errors?.length){let se=l.errors[0];b.push({id:"json-schema-validation-error",pluginName:dk,text:`Error: ${se.message}`,location:{file:q2.join(uH,A)},detail:{params:se.params,propertyName:se.propertyName,schemaPath:se.schemaPath,data:se.data}})}}catch(M){if(M.message.endsWith("is empty and will be ignored.")){D.push({id:"empty-json-schema-file",pluginName:dk,text:`Schema 'schemas/${A}' is empty and will be ignored.`,location:{file:`schemas/${A}`,suggestion:"Add schema details or remove the file from the project."},detail:"EmptyJSONSchemaFile",notes:[{text:`Schema 'schemas/${A}' is empty and will be ignored.`,location:{file:`schemas/${A}`,suggestion:"Add schema details or remove the file from the project."}}]});return}let U=await w8e(A,a.sourceDirectory,M.message);b.push({id:"json-schema-add-error",pluginName:dk,text:`Error: ${M.message}`,location:U,detail:"InvalidAddSchemaError",notes:[{text:M.message}]})}})),await Promise.all(m.map(async A=>{try{let M=l.getSchema(A);M&&l.compile(M.schema).errors?.forEach(ne=>{b.push({text:`Failed to compile ${A}: ${ne.message}`})})}catch(M){let U=await w8e(A,a.sourceDirectory,M.message);b.push({id:"json-schema-compile-error",pluginName:dk,text:`The schema file '${A}' is not valid. Error: ${M.message}`,location:U,detail:"InvalidSchemaError",notes:[{text:M.message}]})}})),Ym.DEBUG_BUILD_MODE)){let A=q2.resolve(a.outputDirectory,uH);await cl.mkdirIfNotExists(A)}s.onStart(async()=>{if(m)return{errors:b,warnings:D}}),s.onResolve({filter:/schemas\/.*\.json$/},async A=>{let M=q2.isAbsolute(A.path)?A.path:q2.join(A.resolveDir,A.path);if(A.importer&&A.importer!==q2.join(a.sourceDirectory,"config/routes.json"))return{path:M};if(!await cl.fileExists(M)){let U="policies.json";return{errors:[{id:"json-schema-build-error",text:`Unable to resolve reference to '${A.path}' from ${U}`,location:{file:q2.join(A.resolveDir,U),namespace:zfe,line:1,column:0,length:0,lineText:`Invalid JSON schema reference in ${U}`,suggestion:""},detail:"RouteReferenceError",pluginName:dk,notes:[{text:`Unable to resolve reference to '${A.path}' from ${U}`,location:null}]}],namespace:zfe,path:M,pluginName:dk}}return{path:M,namespace:zfe,pluginName:dk}}),s.onLoad({filter:/.*/,namespace:zfe},async A=>hf.timeFn(`Generating json schema data: ${q2.basename(A.path)}`,async()=>{let M=[],U;try{let ne=q2.relative(_,A.path),se=l.getSchema(ne);if(!se)throw new Error(`Could not load schema at ${A.path}`);U=se.source?.validateCode;let Z=l.compile(se.schema);U=(0,wyt.default)(l,Z)}catch(ne){M.push({pluginName:dk,text:`Cannot parse project's schemas/${q2.basename(A.path)} file. Error: ${ne.message}`,location:null,notes:[{text:ne.message,location:null}],detail:ne})}if(Ym.DEBUG_BUILD_MODE&&U){let ne=q2.relative(_,A.path),se=q2.join(a.sourceDirectory,".zuplo",`${ne}.js`);await ok(se,U)}return{contents:U,errors:M,pluginName:dk,resolveDir:q2.dirname(A.path),watchFiles:[A.path]}}))}}}t(Pyt,"jsonSchemaPlugin");import{relative as TSr}from"path";var Ayt=["node:assert","node:async_hooks","node:buffer","node:crypto","node:diagnostics_channel","node:events","node:path","node:process","node:stream","node:string_decoder","node:util"],xSr="nodejs-compat-plugin";function Nyt({sourceDirectory:a}){return{name:xSr,setup(s){let l=new Set;s.onStart(()=>{l.clear()}),s.onResolve({filter:/node:.*/},async({path:_,kind:m,resolveDir:b,...D})=>{let A=`${_}:${m}:${b}:${D.importer}`;if(l.has(A))return;l.add(A);let M=await s.resolve(_,{kind:m,resolveDir:b,importer:D.importer});return M.errors.length>0?Ayt.includes(_)||_.includes("/")&&Ayt.includes(_.split("/")[0])?{external:!0}:{external:!0,warnings:M.errors.map(ne=>({...ne,location:{file:TSr(a,D.importer),line:0,column:0,namespace:"",length:0,lineText:"",suggestion:"Remove the imported node module"},detail:`The package "${_}" wasn't found on the file system but is built into node. If this code is executed it will fail.`}))}:M})}}}t(Nyt,"nodejsCompatPlugin");import Iyt from"fs/promises";import tE from"path";var kj="open-api-routes-plugin",qfe="open-api-routes-json";function Oyt(a){return{name:"open-api-routes-plugin",setup(s){s.onResolve({filter:/routes.json$/},l=>({watchFiles:[...YFe(tE.join(a.sourceDirectory,Iy),[".oas.json"],!0),tE.join(a.sourceDirectory,Iy,bce)],namespace:qfe,path:tE.isAbsolute(l.path)?l.path:tE.join(l.resolveDir,l.path),pluginName:kj})),s.onResolve({filter:/^\.\.\/modules\/.*/,namespace:qfe},async l=>{let _=tE.join(l.resolveDir,`${l.path}.ts`);if(!await cl.fileExists(_)){let m=`$import(.${l.path.replace(/^../,"")})`,b=tE.resolve(a.sourceDirectory,"config"),D=await DO(b),A=await xot(D,m,"Update your route configuration to use code from the 'modules' folder");return{errors:[{id:"route-build-error",text:`Invalid handler reference in routes.json. Unable to resolve reference to '${m}' from routes.json`,location:A,detail:"RouteReferenceError",pluginName:kj}],namespace:qfe,path:l.path,pluginName:kj}}}),s.onLoad({filter:/.*/,namespace:qfe},async l=>hf.timeFn("Generating route.json data",async()=>{let _=tE.resolve(a.sourceDirectory,"config"),m=await DO(_),b=await Promise.all(m.map(async U=>({content:await Iyt.readFile(U,"utf-8"),fileName:U}))),D=tE.resolve(_,"policies.json");if(!await cl.fileExists(D))return{errors:[{text:"The project must include a policies file ('/config/policies.json')",detail:"OASPoliciesFileMissing",pluginName:kj,location:{line:0,column:0,file:"/config/policies.json"}}],pluginName:kj};let A={content:await Iyt.readFile(D,"utf-8"),fileName:D},M;try{M=await C8e({sourceDirectory:a.sourceDirectory,oasContent:b,policiesContent:A})}catch(U){throw new Error("Error compiling routes: "+U.message)}if(Ym.DEBUG_BUILD_MODE&&M.content){let U=tE.join(a.sourceDirectory,".zuplo"),ne=tE.resolve(U,"routes.js");await ok(ne,M.content)}return{contents:M.content,errors:M.errors,pluginName:kj,resolveDir:tE.dirname(l.path),watchFiles:[l.path]}}))}}}t(Oyt,"openApiRoutesPlugin");import Vfe from"path";var OK="raw-route-plugin",Fyt="raw-route";function Lyt(a){return{name:"raw-route-plugin",setup(s){s.onResolve({filter:/raw.json$/},l=>({namespace:Fyt,path:l.path,pluginName:OK})),s.onLoad({filter:/.*/,namespace:Fyt},async l=>{let _=Vfe.resolve(a.sourceDirectory,Iy);if(!await cl.dirExists(_))return{loader:"js",resolveDir:Vfe.dirname(l.path),pluginName:OK};let m=await DO(_);try{let b=await k8e({oasFiles:m,sourceDirectory:a.sourceDirectory,logger:a.logger});if(Ym.DEBUG_BUILD_MODE&&b){let D=Vfe.join(a.sourceDirectory,".zuplo","raw-routes.js");await ok(D,b)}return{contents:b,loader:"js",resolveDir:Vfe.dirname(l.path),pluginName:OK}}catch(b){if(b instanceof F0)return{contents:"",loader:"ts",errors:[{id:"route-build-error",text:b.issue.text,location:b.issue.location,detail:b.issue.detail,pluginName:OK}],pluginName:OK};throw b}})}}}t(Lyt,"rawRoutePlugin");import CSr from"fs/promises";import XFe from"path";var Wfe="runtime-config",Ryt="runtime-config-plugin";function Myt(){return{name:Wfe,setup(a){a.onResolve({filter:/^\.\.\/modules\/zuplo.runtime.ts$/},s=>({namespace:Ryt,path:XFe.isAbsolute(s.path)?s.path:XFe.join(s.resolveDir,s.path),pluginName:Wfe})),a.onLoad({filter:/.*/,namespace:Ryt},async s=>hf.timeFn("Generating zuplo.runtime.ts data",async()=>{let l="export const runtimeInit = undefined;",_=[];return await cl.fileExists(s.path)?(l=await CSr.readFile(s.path,"utf-8"),{contents:l,loader:"ts",resolveDir:XFe.dirname(s.path),errors:_,pluginName:Wfe,watchFiles:[s.path]}):{contents:l,loader:"ts",errors:_,pluginName:Wfe}}))}}}t(Myt,"runtimeConfigPlugin");var Byt=S_(GFe(),1),Uyt=S_(KFe(),1);import e7e from"fs/promises";import fF from"path";var QFe="schema-validation-plugin",jyt="schema-validation",ESr="module.exports = {}";function $yt(a){return{name:"schema-validation-plugin",setup(s){s.onResolve({filter:/ajv-schema.json$/},l=>({namespace:jyt,path:l.path,pluginName:QFe})),s.onLoad({filter:/.*/,namespace:jyt},async l=>{let _=fF.resolve(a.sourceDirectory,Iy,"policies.json");if(!await cl.fileExists(_))return{contents:ESr,loader:"js",resolveDir:fF.dirname(l.path),pluginName:QFe};let m=await kSr(a.sourceDirectory),b=fF.resolve(a.sourceDirectory,Iy),D=await DO(b),A=await NSr(D,m),M=await DSr({oasFiles:D,routesWithSchemaValidation:A,sourceDirectory:a.sourceDirectory,logger:a.logger});if(Ym.DEBUG_BUILD_MODE&&M){let U=fF.join(a.sourceDirectory,".zuplo","schema-validation.js");await ok(U,M)}return{contents:M,loader:"js",resolveDir:fF.dirname(l.path),pluginName:QFe}})}}}t($yt,"schemaValidationPlugin");async function DSr({oasFiles:a,routesWithSchemaValidation:s,sourceDirectory:l,logger:_}){let m="",b=new p3(l,_);if(s.length===0)return m;let D=new Byt.Ajv2020({code:{source:!0},allErrors:!0,strict:!1,verbose:!0,meta:!0});for(let A of a){let M=await e7e.readFile(A,"utf-8"),U=fF.basename(A,".oas.json"),ne=s.filter(ke=>ke.fileName===U),se=await b.resolve(A),Z=JSON.parse(M),Re=[],Ae=new Map;ne.forEach(ke=>{let Ot=Z.paths[ke.path][ke.method];if(Ot.requestBody){let kt;if(Ot.requestBody.$ref){let br=Ot.requestBody.$ref;kt=se.get(br)?.content}else Ot.requestBody.content&&(kt=Ot.requestBody.content);if(kt)for(let br in kt){let Kr=kt[br].schema,on=o3e(ke.path,ke.method,br);Kr.$id=on,D.addSchema(Kr),ZFe(Kr,A,U,D,se,Re,Ae)}}if(Ot.parameters)for(let kt of Ot.parameters){let br=kt.$ref?se.get(kt.$ref):kt,Kr=br.schema.$ref?se.get(br.schema.$ref):br.schema,on=a3e(ke.path,ke.method,br.in,br.name);Kr.$id=on,D.addSchema(Kr),ZFe(br,A,U,D,se,Re,Ae)}});for(let ke of Re){let Ot=se.get(ke),kt=tG(U,ke);D.addSchema(Ot,kt)}}return m=(0,Uyt.default)(D),m}t(DSr,"schemaValidationSource");function ZFe(a,s,l,_,m,b,D){for(let A in a){let M=a[A];if(A==="$ref"){let U=tG(l,i3(s,M));a[A]=U,RH(s,l,i3(s,M),m,b,D,(ne,se)=>tG(ne,i3(s,se)))}else typeof M=="object"&&ZFe(M,s,l,_,m,b,D)}}t(ZFe,"addRefsToSchema");async function kSr(a){let s=new Set(["RequestValidationInboundPolicy"]),l=await e7e.readFile(`${a}/config/policies.json`,"utf-8"),_=JSON.parse(l);return wSr(_,s)}t(kSr,"getPolicyNamesUsingSchemaValidationPolicies");function wSr(a,s){let l=new Set;a.policies?.forEach(m=>{m.handler?.export&&s.has(m.handler.export)&&m.handler.module==="$import(@zuplo/runtime)"&&l.add(m.name)});let _=PSr(a,l);return new Set([...l,..._])}t(wSr,"getPolicyNamesReferencingPolicyHandlers");function PSr(a,s){let l=new Set;return a.policies?.forEach(_=>{_.handler?.export==="CompositeInboundPolicy"&&_.handler?.options?.policies?.forEach(m=>{s.has(m)&&l.add(_.name)})}),l}t(PSr,"getCompositePoliciesContainingPolicy");function ASr(a,s){if(!a["x-zuplo-route"]||!a["x-zuplo-route"].policies)return!1;let l=a["x-zuplo-route"].policies.inbound;if(l){for(let m of l)if(s.has(m))return!0}let _=a["x-zuplo-route"].policies.outbound;if(_){for(let m of _)if(s.has(m))return!0}return!1}t(ASr,"isPolicyPresentInOperation");async function NSr(a,s){let l=[];for(let _ of a){let m=await e7e.readFile(_,"utf-8"),D=JSON.parse(m).paths;for(let A in D){let M=D[A];for(let U in M){let ne=M[U];ASr(ne,s)&&l.push({fileName:fF.basename(_,".oas.json"),path:A,method:U})}}}return l}t(NSr,"getRoutesContainingPolicies");import{mkdirSync as ISr,writeFileSync as OSr}from"fs";import FSr from"path";function Jyt(a){return{name:"write-modules-plugin",setup(s){s.onEnd(async l=>{if(l){let _=sj(a.sourceDirectory,l.metafile);ISr(a.outputDirectory,{recursive:!0}),OSr(FSr.join(a.outputDirectory,"modules.json"),JSON.stringify(_,null,2))}})}}}t(Jyt,"writeModulesPlugin");var LSr=aht("zuplo:core:build"),RSr=["workerd","worker","browser"],Vyt=[...process.env.GLOBAL_MODULE_LOCATION?[process.env.GLOBAL_MODULE_LOCATION]:[],t7e.resolve(zyt(qyt(import.meta.url)),"..","..","..","node_modules"),t7e.resolve(zyt(qyt(import.meta.url)),"..","..","..","..","..","node_modules")];async function FK({systemDirectory:a,outputDirectory:s,sourceDirectory:l,cacheDirectory:_,logger:m,minify:b=!0,command:D,flags:A}){let M=t7e.join(a,xce);LSr(`Building with node paths: ${Vyt.join(", ")}`);let U=b&&D!=="dev"&&!process.env.DEBUG_BUILD_DISABLE_MINIFY?{minify:!0,chunkNames:"[hash]"}:{minify:!1,keepNames:!0,chunkNames:"[name]-[hash]"},ne={sourceDirectory:l,outputDirectory:s,cacheDirectory:_,logger:m,debugMode:Ym.DEBUG_BUILD_MODE,flags:A};return{platform:"browser",target:"es2022",outdir:s,splitting:!0,metafile:!0,format:"esm",nodePaths:Vyt,entryPoints:[M],sourcemap:"linked",legalComments:"none",treeShaking:!0,bundle:!0,...U,external:[],logLevel:"silent",conditions:RSr,plugins:[dht(ne),oht(ne),Oyt(ne),Lyt(ne),$yt(ne),Myt(),uht(ne),Pyt(ne),Nyt(ne),Jyt(ne)]}}t(FK,"getBaseESBuildConfig");var _F="run-esbuild",Hyt=t(async function({systemDirectory:a,outputDirectory:s,sourceDirectory:l,cacheDirectory:_,buildId:m,logger:b,config:D,command:A,minify:M},U){return hf.timeFn("Running esbuild",async()=>{b.info(`Running build_id: ${m}`);let ne=await FK({command:A,minify:M,systemDirectory:a,outputDirectory:s,cacheDirectory:_,sourceDirectory:l,logger:b,flags:D.flags}),se;try{if(!await lM(l))throw new Error("Failed to build project because no open-api file was found on the 'config' folder");se=await Wyt.build(ne),U.set("metafile",se.metafile)}catch(Ae){if(b.error(Ae),Ae.errors||Ae.warnings)se=Ae;else if(Ae.message.includes("Failed to build project because no open-api file was found on the 'config' folder"))se={warnings:[],errors:[{id:"missing-open-api-file",text:"Failed to build project because no open-api file was found on the 'config' folder",pluginName:_F,location:null,notes:[],detail:"Failed to build project because no open-api file was found on the 'config' folder"}],outputFiles:void 0,metafile:void 0,mangleCache:void 0};else throw Ae}se.errors.length>0&&se.errors.length>1&&(se.errors.length=1);let{errors:Z,warnings:Re}=r7e({buildId:m,result:se});return{errors:Z,warnings:Re}})},"runEsbuild");function r7e({buildId:a,result:s}){return{status:s.errors.length>0?"Failed":s.warnings.length>0?"Warnings":"Good",runtimeVersion:"0.0.0",buildTime:"",buildTimeMs:0,buildId:a,warnings:s.warnings.map(_=>_.text==="Using direct eval with a bundler is not recommended and may cause problems"?{location:_.location,detail:_.detail,id:_.id,notes:_.notes,message:"We do not support the use of 'eval' or 'new Function(...)'",severity:hce,pluginName:_.pluginName||_F}:{location:_.location,detail:_.detail,id:_.id,notes:_.notes,message:_.text,severity:hce,pluginName:_.pluginName||_F}),errors:s.errors.map(_=>({location:_.location,detail:_.detail,id:_.id,notes:_.notes,message:_.text,severity:KAe,pluginName:_.pluginName||_F})),metafile:s.metafile}}t(r7e,"esbuildResultToBuildResult");var MSr=t((a,s)=>{let l=s;if(s.includes(a)){let _=new RegExp(`.*(${a})`,"g");l=s.replace(_,"")}return l.match(/^(\/)?(\.\.(\/)?)+/)&&(l=l.replace(/^(\/)?(\.\.(\/)?)+/,"/")),l},"removePrefixFromString"),jSr=t((a,s)=>{let l=s;if(l.includes(a)){let _=new RegExp(`[a-zA-Z0-9-_.\\/]+(${a})`,"g");l=l.replace(_,"")}return l},"cleanFilePathsInMessage"),Gyt=t((a,s,l)=>{if(!a||a.length<=0)return a;let _=a.filter(m=>m.message!=='Could not resolve "@zuplo/runtime"');return _&&_.length>0&&_.forEach(m=>{try{m.location&&m.location.file&&(m.location.file=MSr(s,m.location.file)),m.location&&m.location.lineText&&m.location.lineText.includes("@zuplo/core/index.minified.js")&&(m.location.lineText=m.location.lineText.substring(0,200)+"...<Truncated>"),m.message=jSr(s,m.message),m.notes&&m.notes.length>0&&delete m.notes,m.text&&delete m.text,m.pluginName===""&&(m.pluginName=l)}catch{}}),_},"cleanDataOnBuildIssue");function Kyt(a,s){let l=n7e.basename(s);a.errors&&(a.errors=Gyt(a.errors,l,_F)),a.warnings&&(a.warnings=Gyt(a.warnings,l,_F))}t(Kyt,"formatBuildResult");var BSr=t(a=>n7e.basename(a).startsWith("."),"isHiddenOnUnix"),USr=t((a,s=[])=>s.map(l=>l.startsWith(".")?l:`.${l}`).some(l=>a.endsWith(l)),"hasMatchingExtname");function YFe(a,s=[],l=!1){let _=[],m;if(!Hfe.existsSync(a)){let b;if(IH.hasMagic(a))b=a;else{let D=s.map(A=>A.startsWith(".")?A:`.${A}`).join("|");b=`${a}+(${D})`}if(_.push(...IH.sync(b,{nodir:!0})),!_.length)throw Error(`Cannot find any files matching pattern "${a}"`);return _}try{if(m=Hfe.statSync(a),m.isFile())return[a]}catch{return[]}return Hfe.readdirSync(a).forEach(b=>{let D=n7e.join(a,b),A;try{if(A=Hfe.statSync(D),A.isDirectory()){l&&_.push(...YFe(D,s,l));return}}catch{return}if(!s.length)throw Error(`Argument '${s}' required when argument '${a}' is a directory`);!A.isFile()||!USr(D,s)||BSr(D)||_.push(D)}),_}t(YFe,"lookupFiles");var JT=new wce({level:process.env.FORCE_BUILD_COLORS?2:void 0}),M3=` ${JT.gray("|")} `;function CUr(a,s){a.info(JT.green(s))}t(CUr,"outputSuccess");function EUr(a,s){a.warn(JT.yellow(s))}t(EUr,"outputWarning");function DUr(a,s){a.error(JT.red(s))}t(DUr,"outputCritical");function kUr(a,s,l){let _=l.sort((D,A)=>{let M=D.path.split("/").length,U=A.path.split("/").length;return M!==U?M-U:D.path.localeCompare(A.path)}),m=Math.max(..._.map(D=>D.path.length)),b=`${s}
592
+ export default environment;`;function dht(a){return{name:"environment",setup(s){s.onResolve({filter:/@app\/environment$/},()=>({namespace:pht,pluginName:_ht,path:fht.join(a.sourceDirectory,e3,"environment.js")})),s.onLoad({filter:/.*/,namespace:pht},async l=>({contents:Tgr,loader:"ts",resolveDir:fht.dirname(l.path),pluginName:_ht}))}}}t(dht,"environmentPlugin");var Eyt=S_(xFe(),1),Dyt=S_(H0t(),1),kyt=S_(GFe(),1),wyt=S_(KFe(),1);import SSr from"fs/promises";import q2 from"path";var dk="schemas",zfe="json-schema";function Pyt(a){return{name:dk,async setup(s){let l=new kyt.Ajv2020({code:{source:!0},allErrors:!0,strict:!1,verbose:!0,meta:!0});(0,Dyt.default)(l,{mode:"fast"}),l.opts.code.formats=Eyt._`require("ajv-formats/dist/formats").fastFormats`;let _=q2.join(a.sourceDirectory,uH),m,b=[],D=[];if(await cl.dirExists(_)&&(l.addKeyword("faker"),m=await cl.listFolderContents(_,uH),await Promise.all(m.map(async A=>{try{let M=cl.safePath(a.sourceDirectory).resolve(_,A);if(!M.startsWith(_))throw new Error("All schemas must be in the schemas directory");let U=await SSr.readFile(M,"utf-8");if(U===""||U===void 0)throw new Error(`Schema 'schemas/${A}' is empty and will be ignored.`);let ne=JSON.parse(U);if(ne.$schema&&ne.$schema!=="https://json-schema.org/draft/2020-12/schema")throw new Error(`Error in ${A}: All JSON schemas must use version 2020-12. See release notes for changes: https://json-schema.org/draft/2020-12/release-notes.html`);if(l.$dataMetaSchema,l.addSchema(ne,A),l.errors?.length){let se=l.errors[0];b.push({id:"json-schema-validation-error",pluginName:dk,text:`Error: ${se.message}`,location:{file:q2.join(uH,A)},detail:{params:se.params,propertyName:se.propertyName,schemaPath:se.schemaPath,data:se.data}})}}catch(M){if(M.message.endsWith("is empty and will be ignored.")){D.push({id:"empty-json-schema-file",pluginName:dk,text:`Schema 'schemas/${A}' is empty and will be ignored.`,location:{file:`schemas/${A}`,suggestion:"Add schema details or remove the file from the project."},detail:"EmptyJSONSchemaFile",notes:[{text:`Schema 'schemas/${A}' is empty and will be ignored.`,location:{file:`schemas/${A}`,suggestion:"Add schema details or remove the file from the project."}}]});return}let U=await w8e(A,a.sourceDirectory,M.message);b.push({id:"json-schema-add-error",pluginName:dk,text:`Error: ${M.message}`,location:U,detail:"InvalidAddSchemaError",notes:[{text:M.message}]})}})),await Promise.all(m.map(async A=>{try{let M=l.getSchema(A);M&&l.compile(M.schema).errors?.forEach(ne=>{b.push({text:`Failed to compile ${A}: ${ne.message}`})})}catch(M){let U=await w8e(A,a.sourceDirectory,M.message);b.push({id:"json-schema-compile-error",pluginName:dk,text:`The schema file '${A}' is not valid. Error: ${M.message}`,location:U,detail:"InvalidSchemaError",notes:[{text:M.message}]})}})),Ym.DEBUG_BUILD_MODE)){let A=q2.resolve(a.outputDirectory,uH);await cl.mkdirIfNotExists(A)}s.onStart(async()=>{if(m)return{errors:b,warnings:D}}),s.onResolve({filter:/schemas\/.*\.json$/},async A=>{let M=q2.isAbsolute(A.path)?A.path:q2.join(A.resolveDir,A.path);if(A.importer&&A.importer!==q2.join(a.sourceDirectory,"config/routes.json"))return{path:M};if(!await cl.fileExists(M)){let U="policies.json";return{errors:[{id:"json-schema-build-error",text:`Unable to resolve reference to '${A.path}' from ${U}`,location:{file:q2.join(A.resolveDir,U),namespace:zfe,line:1,column:0,length:0,lineText:`Invalid JSON schema reference in ${U}`,suggestion:""},detail:"RouteReferenceError",pluginName:dk,notes:[{text:`Unable to resolve reference to '${A.path}' from ${U}`,location:null}]}],namespace:zfe,path:M,pluginName:dk}}return{path:M,namespace:zfe,pluginName:dk}}),s.onLoad({filter:/.*/,namespace:zfe},async A=>hf.timeFn(`Generating json schema data: ${q2.basename(A.path)}`,async()=>{let M=[],U;try{let ne=q2.relative(_,A.path),se=l.getSchema(ne);if(!se)throw new Error(`Could not load schema at ${A.path}`);U=se.source?.validateCode;let Z=l.compile(se.schema);U=(0,wyt.default)(l,Z)}catch(ne){M.push({pluginName:dk,text:`Cannot parse project's schemas/${q2.basename(A.path)} file. Error: ${ne.message}`,location:null,notes:[{text:ne.message,location:null}],detail:ne})}if(Ym.DEBUG_BUILD_MODE&&U){let ne=q2.relative(_,A.path),se=q2.join(a.sourceDirectory,".zuplo",`${ne}.js`);await ok(se,U)}return{contents:U,errors:M,pluginName:dk,resolveDir:q2.dirname(A.path),watchFiles:[A.path]}}))}}}t(Pyt,"jsonSchemaPlugin");import{relative as TSr}from"path";var Ayt=["node:assert","node:async_hooks","node:buffer","node:crypto","node:diagnostics_channel","node:events","node:path","node:process","node:stream","node:string_decoder","node:util"],xSr="nodejs-compat-plugin";function Nyt({sourceDirectory:a}){return{name:xSr,setup(s){let l=new Set;s.onStart(()=>{l.clear()}),s.onResolve({filter:/node:.*/},async({path:_,kind:m,resolveDir:b,...D})=>{let A=`${_}:${m}:${b}:${D.importer}`;if(l.has(A))return;l.add(A);let M=await s.resolve(_,{kind:m,resolveDir:b,importer:D.importer});return M.errors.length>0?Ayt.includes(_)||_.includes("/")&&Ayt.includes(_.split("/")[0])?{external:!0}:{external:!0,warnings:M.errors.map(ne=>({...ne,location:{file:TSr(a,D.importer),line:0,column:0,namespace:"",length:0,lineText:"",suggestion:"Remove the imported node module"},detail:`The package "${_}" wasn't found on the file system but is built into node. If this code is executed it will fail.`}))}:M})}}}t(Nyt,"nodejsCompatPlugin");import Iyt from"fs/promises";import tE from"path";var kj="open-api-routes-plugin",qfe="open-api-routes-json";function Oyt(a){return{name:"open-api-routes-plugin",setup(s){s.onResolve({filter:/routes.json$/},l=>({watchFiles:[...YFe(tE.join(a.sourceDirectory,Iy),[".oas.json"],!0),tE.join(a.sourceDirectory,Iy,bce)],namespace:qfe,path:tE.isAbsolute(l.path)?l.path:tE.join(l.resolveDir,l.path),pluginName:kj})),s.onResolve({filter:/^\.\.\/modules\/.*/,namespace:qfe},async l=>{let _=tE.join(l.resolveDir,`${l.path}.ts`);if(!await cl.fileExists(_)){let m=`$import(.${l.path.replace(/^../,"")})`,b=tE.resolve(a.sourceDirectory,"config"),D=await DO(b),A=await xot(D,m,"Update your route configuration to use code from the 'modules' folder");return{errors:[{id:"route-build-error",text:`Invalid handler reference in routes.json. Unable to resolve reference to '${m}' from routes.json`,location:A,detail:"RouteReferenceError",pluginName:kj}],namespace:qfe,path:l.path,pluginName:kj}}}),s.onLoad({filter:/.*/,namespace:qfe},async l=>hf.timeFn("Generating route.json data",async()=>{let _=tE.resolve(a.sourceDirectory,"config"),m=await DO(_),b=await Promise.all(m.map(async U=>({content:await Iyt.readFile(U,"utf-8"),fileName:U}))),D=tE.resolve(_,"policies.json");if(!await cl.fileExists(D))return{errors:[{text:"The project must include a policies file ('/config/policies.json')",detail:"OASPoliciesFileMissing",pluginName:kj,location:{line:0,column:0,file:"/config/policies.json"}}],pluginName:kj};let A={content:await Iyt.readFile(D,"utf-8"),fileName:D},M;try{M=await C8e({sourceDirectory:a.sourceDirectory,oasContent:b,policiesContent:A})}catch(U){throw new Error("Error compiling routes: "+U.message)}if(Ym.DEBUG_BUILD_MODE&&M.content){let U=tE.join(a.sourceDirectory,".zuplo"),ne=tE.resolve(U,"routes.js");await ok(ne,M.content)}return{contents:M.content,errors:M.errors,pluginName:kj,resolveDir:tE.dirname(l.path),watchFiles:[l.path]}}))}}}t(Oyt,"openApiRoutesPlugin");import Vfe from"path";var OK="raw-route-plugin",Fyt="raw-route";function Lyt(a){return{name:"raw-route-plugin",setup(s){s.onResolve({filter:/raw.json$/},l=>({namespace:Fyt,path:l.path,pluginName:OK})),s.onLoad({filter:/.*/,namespace:Fyt},async l=>{let _=Vfe.resolve(a.sourceDirectory,Iy);if(!await cl.dirExists(_))return{loader:"js",resolveDir:Vfe.dirname(l.path),pluginName:OK};let m=await DO(_);try{let b=await k8e({oasFiles:m,sourceDirectory:a.sourceDirectory,logger:a.logger});if(Ym.DEBUG_BUILD_MODE&&b){let D=Vfe.join(a.sourceDirectory,".zuplo","raw-routes.js");await ok(D,b)}return{contents:b,loader:"js",resolveDir:Vfe.dirname(l.path),pluginName:OK}}catch(b){if(b instanceof F0)return{contents:"",loader:"ts",errors:[{id:"route-build-error",text:b.issue.text,location:b.issue.location,detail:b.issue.detail,pluginName:OK}],pluginName:OK};throw b}})}}}t(Lyt,"rawRoutePlugin");import CSr from"fs/promises";import XFe from"path";var Wfe="runtime-config",Ryt="runtime-config-plugin";function Myt(){return{name:Wfe,setup(a){a.onResolve({filter:/^\.\.\/modules\/zuplo.runtime.ts$/},s=>({namespace:Ryt,path:XFe.isAbsolute(s.path)?s.path:XFe.join(s.resolveDir,s.path),pluginName:Wfe})),a.onLoad({filter:/.*/,namespace:Ryt},async s=>hf.timeFn("Generating zuplo.runtime.ts data",async()=>{let l="export const runtimeInit = undefined;",_=[];return await cl.fileExists(s.path)?(l=await CSr.readFile(s.path,"utf-8"),{contents:l,loader:"ts",resolveDir:XFe.dirname(s.path),errors:_,pluginName:Wfe,watchFiles:[s.path]}):{contents:l,loader:"ts",errors:_,pluginName:Wfe}}))}}}t(Myt,"runtimeConfigPlugin");var Byt=S_(GFe(),1),Uyt=S_(KFe(),1);import e7e from"fs/promises";import fF from"path";var QFe="schema-validation-plugin",jyt="schema-validation",ESr="module.exports = {}";function $yt(a){return{name:"schema-validation-plugin",setup(s){s.onResolve({filter:/ajv-schema.json$/},l=>({namespace:jyt,path:l.path,pluginName:QFe})),s.onLoad({filter:/.*/,namespace:jyt},async l=>{let _=fF.resolve(a.sourceDirectory,Iy,"policies.json");if(!await cl.fileExists(_))return{contents:ESr,loader:"js",resolveDir:fF.dirname(l.path),pluginName:QFe};let m=await kSr(a.sourceDirectory),b=fF.resolve(a.sourceDirectory,Iy),D=await DO(b),A=await NSr(D,m),M=await DSr({oasFiles:D,routesWithSchemaValidation:A,sourceDirectory:a.sourceDirectory,logger:a.logger});if(Ym.DEBUG_BUILD_MODE&&M){let U=fF.join(a.sourceDirectory,".zuplo","schema-validation.js");await ok(U,M)}return{contents:M,loader:"js",resolveDir:fF.dirname(l.path),pluginName:QFe}})}}}t($yt,"schemaValidationPlugin");async function DSr({oasFiles:a,routesWithSchemaValidation:s,sourceDirectory:l,logger:_}){let m="",b=new p3(l,_);if(s.length===0)return m;let D=new Byt.Ajv2020({code:{source:!0},allErrors:!0,strict:!1,verbose:!0,meta:!0});for(let A of a){let M=await e7e.readFile(A,"utf-8"),U=fF.basename(A,".oas.json"),ne=s.filter(ke=>ke.fileName===U),se=await b.resolve(A),Z=JSON.parse(M),Re=[],Ae=new Map;ne.forEach(ke=>{let Ot=Z.paths[ke.path][ke.method];if(Ot.requestBody){let kt;if(Ot.requestBody.$ref){let br=Ot.requestBody.$ref;kt=se.get(br)?.content}else Ot.requestBody.content&&(kt=Ot.requestBody.content);if(kt)for(let br in kt){let Kr=kt[br].schema,on=o3e(ke.path,ke.method,br);Kr.$id=on,D.addSchema(Kr),ZFe(Kr,A,U,D,se,Re,Ae)}}if(Ot.parameters)for(let kt of Ot.parameters){let br=kt.$ref?se.get(kt.$ref):kt,Kr=br.schema.$ref?se.get(br.schema.$ref):br.schema,on=a3e(ke.path,ke.method,br.in,br.name);Kr.$id=on,D.addSchema(Kr),ZFe(br,A,U,D,se,Re,Ae)}});for(let ke of Re){let Ot=se.get(ke),kt=tG(U,ke);D.addSchema(Ot,kt)}}return m=(0,Uyt.default)(D),m}t(DSr,"schemaValidationSource");function ZFe(a,s,l,_,m,b,D){for(let A in a){let M=a[A];if(A==="$ref"){let U=tG(l,i3(s,M));a[A]=U,RH(s,l,i3(s,M),m,b,D,(ne,se)=>tG(ne,i3(s,se)))}else typeof M=="object"&&ZFe(M,s,l,_,m,b,D)}}t(ZFe,"addRefsToSchema");async function kSr(a){let s=new Set(["RequestValidationInboundPolicy"]),l=await e7e.readFile(`${a}/config/policies.json`,"utf-8"),_=JSON.parse(l);return wSr(_,s)}t(kSr,"getPolicyNamesUsingSchemaValidationPolicies");function wSr(a,s){let l=new Set;a.policies?.forEach(m=>{m.handler?.export&&s.has(m.handler.export)&&m.handler.module==="$import(@zuplo/runtime)"&&l.add(m.name)});let _=PSr(a,l);return new Set([...l,..._])}t(wSr,"getPolicyNamesReferencingPolicyHandlers");function PSr(a,s){let l=new Set;return a.policies?.forEach(_=>{_.handler?.export==="CompositeInboundPolicy"&&_.handler?.options?.policies?.forEach(m=>{s.has(m)&&l.add(_.name)})}),l}t(PSr,"getCompositePoliciesContainingPolicy");function ASr(a,s){if(!a["x-zuplo-route"]||!a["x-zuplo-route"].policies)return!1;let l=a["x-zuplo-route"].policies.inbound;if(l){for(let m of l)if(s.has(m))return!0}let _=a["x-zuplo-route"].policies.outbound;if(_){for(let m of _)if(s.has(m))return!0}return!1}t(ASr,"isPolicyPresentInOperation");async function NSr(a,s){let l=[];for(let _ of a){let m=await e7e.readFile(_,"utf-8"),D=JSON.parse(m).paths;for(let A in D){let M=D[A];for(let U in M){let ne=M[U];ASr(ne,s)&&l.push({fileName:fF.basename(_,".oas.json"),path:A,method:U})}}}return l}t(NSr,"getRoutesContainingPolicies");import{mkdirSync as ISr,writeFileSync as OSr}from"fs";import FSr from"path";function Jyt(a){return{name:"write-modules-plugin",setup(s){s.onEnd(async l=>{if(l){let _=sj(a.sourceDirectory,l.metafile);ISr(a.outputDirectory,{recursive:!0}),OSr(FSr.join(a.outputDirectory,"modules.json"),JSON.stringify(_,null,2))}})}}}t(Jyt,"writeModulesPlugin");var LSr=aht("zuplo:core:build"),RSr=["workerd","worker","browser"],Vyt=[...process.env.GLOBAL_MODULE_LOCATION?[process.env.GLOBAL_MODULE_LOCATION]:[],t7e.resolve(zyt(qyt(import.meta.url)),"..","..","..","node_modules"),t7e.resolve(zyt(qyt(import.meta.url)),"..","..","..","..","..","node_modules")];async function FK({systemDirectory:a,outputDirectory:s,sourceDirectory:l,cacheDirectory:_,logger:m,minify:b=!0,command:D,flags:A}){let M=t7e.join(a,xce);LSr(`Building with node paths: ${Vyt.join(", ")}`);let U=b&&D!=="dev"&&!process.env.DEBUG_BUILD_DISABLE_MINIFY?{minify:!0,chunkNames:"[hash]"}:{minify:!1,keepNames:!0,chunkNames:"[name]-[hash]"},ne={sourceDirectory:l,outputDirectory:s,cacheDirectory:_,logger:m,debugMode:Ym.DEBUG_BUILD_MODE,flags:A};return{platform:"browser",target:"es2022",outdir:s,splitting:!0,metafile:!0,format:"esm",nodePaths:Vyt,entryPoints:[M],sourcemap:"linked",legalComments:"none",treeShaking:!0,bundle:!0,...U,external:[],logLevel:"silent",conditions:RSr,plugins:[dht(ne),oht(ne),Oyt(ne),Lyt(ne),$yt(ne),Myt(),uht(ne),Pyt(ne),Nyt(ne),Jyt(ne)]}}t(FK,"getBaseESBuildConfig");var _F="run-esbuild",Hyt=t(async function({systemDirectory:a,outputDirectory:s,sourceDirectory:l,cacheDirectory:_,buildId:m,logger:b,config:D,command:A,minify:M},U){return hf.timeFn("Running esbuild",async()=>{b.info(`Running build_id: ${m}`);let ne=await FK({command:A,minify:M,systemDirectory:a,outputDirectory:s,cacheDirectory:_,sourceDirectory:l,logger:b,flags:D.flags}),se;try{if(!await lM(l))throw new Error("Failed to build project because no open-api file was found on the 'config' folder");se=await Wyt.build(ne),U.set("metafile",se.metafile)}catch(Ae){if(b.error(Ae),Ae.errors||Ae.warnings)se=Ae;else if(Ae.message.includes("Failed to build project because no open-api file was found on the 'config' folder"))se={warnings:[],errors:[{id:"missing-open-api-file",text:"Failed to build project because no open-api file was found on the 'config' folder",pluginName:_F,location:null,notes:[],detail:"Failed to build project because no open-api file was found on the 'config' folder"}],outputFiles:void 0,metafile:void 0,mangleCache:void 0};else throw Ae}se.errors.length>0&&se.errors.length>1&&(se.errors.length=1);let{errors:Z,warnings:Re}=r7e({buildId:m,result:se});return{errors:Z,warnings:Re}})},"runEsbuild");function r7e({buildId:a,result:s}){return{status:s.errors.length>0?"Failed":s.warnings.length>0?"Warnings":"Good",runtimeVersion:"0.0.0",buildTime:"",buildTimeMs:0,buildId:a,warnings:s.warnings.map(_=>_.text==="Using direct eval with a bundler is not recommended and may cause problems"?{location:_.location,detail:_.detail,id:_.id,notes:_.notes,message:"We do not support the use of 'eval' or 'new Function(...)'",severity:hce,pluginName:_.pluginName||_F}:{location:_.location,detail:_.detail,id:_.id,notes:_.notes,message:_.text,severity:hce,pluginName:_.pluginName||_F}),errors:s.errors.map(_=>({location:_.location,detail:_.detail,id:_.id,notes:_.notes,message:_.text,severity:KAe,pluginName:_.pluginName||_F})),metafile:s.metafile}}t(r7e,"esbuildResultToBuildResult");var MSr=t((a,s)=>{let l=s;if(s.includes(a)){let _=new RegExp(`.*(${a})`,"g");l=s.replace(_,"")}return l.match(/^(\/)?(\.\.(\/)?)+/)&&(l=l.replace(/^(\/)?(\.\.(\/)?)+/,"/")),l},"removePrefixFromString"),jSr=t((a,s)=>{let l=s;if(l.includes(a)){let _=new RegExp(`[a-zA-Z0-9-_.\\/]+(${a})`,"g");l=l.replace(_,"")}return l},"cleanFilePathsInMessage"),Gyt=t((a,s,l)=>{if(!a||a.length<=0)return a;let _=a.filter(m=>m.message!=='Could not resolve "@zuplo/runtime"');return _&&_.length>0&&_.forEach(m=>{try{m.location&&m.location.file&&(m.location.file=MSr(s,m.location.file)),m.location&&m.location.lineText&&m.location.lineText.includes("@zuplo/core/index.minified.js")&&(m.location.lineText=m.location.lineText.substring(0,200)+"...<Truncated>"),m.message=jSr(s,m.message),m.notes&&m.notes.length>0&&delete m.notes,m.text&&delete m.text,m.pluginName===""&&(m.pluginName=l)}catch{}}),_},"cleanDataOnBuildIssue");function Kyt(a,s){let l=n7e.basename(s);a.errors&&(a.errors=Gyt(a.errors,l,_F)),a.warnings&&(a.warnings=Gyt(a.warnings,l,_F))}t(Kyt,"formatBuildResult");var BSr=t(a=>n7e.basename(a).startsWith("."),"isHiddenOnUnix"),USr=t((a,s=[])=>s.map(l=>l.startsWith(".")?l:`.${l}`).some(l=>a.endsWith(l)),"hasMatchingExtname");function YFe(a,s=[],l=!1){let _=[],m;if(!Hfe.existsSync(a)){let b;if(IH.hasMagic(a))b=a;else{let D=s.map(A=>A.startsWith(".")?A:`.${A}`).join("|");b=`${a}+(${D})`}if(_.push(...IH.sync(b,{nodir:!0})),!_.length)throw Error(`Cannot find any files matching pattern "${a}"`);return _}try{if(m=Hfe.statSync(a),m.isFile())return[a]}catch{return[]}return Hfe.readdirSync(a).forEach(b=>{let D=n7e.join(a,b),A;try{if(A=Hfe.statSync(D),A.isDirectory()){l&&_.push(...YFe(D,s,l));return}}catch{return}if(!s.length)throw Error(`Argument '${s}' required when argument '${a}' is a directory`);!A.isFile()||!USr(D,s)||BSr(D)||_.push(D)}),_}t(YFe,"lookupFiles");var JT=new wce({level:process.env.FORCE_BUILD_COLORS?2:void 0}),M3=` ${JT.gray("|")} `;function CUr(a,s){a.info(JT.green(s))}t(CUr,"outputSuccess");function EUr(a,s){a.warn(JT.yellow(s))}t(EUr,"outputWarning");function DUr(a,s){a.error(`
593
+ ${JT.red(s)}`)}t(DUr,"outputCritical");function kUr(a,s,l){let _=l.sort((D,A)=>{let M=D.path.split("/").length,U=A.path.split("/").length;return M!==U?M-U:D.path.localeCompare(A.path)}),m=Math.max(..._.map(D=>D.path.length)),b=`${s}
593
594
  `;_.forEach(D=>{let A=" ".repeat(m-D.path.length),M=D.bytes/1024,U=` ${D.path}${A} ${M.toFixed(2)} KB
594
595
  `;b+=M>1024?JT.red(U):M>300?JT.yellow(U):U}),a.info(b)}t(kUr,"outputFileTree");function wUr(a,s){if(s.length===0)return"";let l=Object.keys(s[0]).length,_=Array.from({length:l},(D,A)=>Math.max(...s.map(M=>String(Object.values(M)[A]).length))),b=s.map(D=>Object.values(D).map((A,M)=>String(A).padEnd(_[M])).join(" ")).join(`
595
596
  `);a.info(b)}t(wUr,"outputTable");function i7e({output:a,buildId:s,runtimeVersion:l,compatibilityDate:_}){let m=["Building Zuplo API...",`${M3}Build ID: ${s}`,`${M3}Runtime Version: ${l}`];_&&m.push(`${M3}Compatibility Date: ${_}`),a.info(m.join(`
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@zuplo/core",
3
- "version": "6.19.4",
3
+ "version": "6.19.5",
4
4
  "repository": "https://github.com/zuplo/zuplo",
5
5
  "author": "Zuplo, Inc.",
6
6
  "type": "module",
@@ -40,8 +40,8 @@
40
40
  "prettier": "^3.3.3"
41
41
  },
42
42
  "peerDependencies": {
43
- "@zuplo/graphql": "^6.19.4",
44
- "@zuplo/otel": "^6.19.4",
45
- "@zuplo/runtime": "^6.19.4"
43
+ "@zuplo/graphql": "^6.19.5",
44
+ "@zuplo/otel": "^6.19.5",
45
+ "@zuplo/runtime": "^6.19.5"
46
46
  }
47
47
  }