@homedev/objector 1.3.7 → 1.3.8
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/index.d.ts +1 -1
- package/dist/index.js +1 -1
- package/package.json +1 -1
package/dist/index.d.ts
CHANGED
|
@@ -373,7 +373,7 @@ export declare class Objector {
|
|
|
373
373
|
keys(keys: FieldProcessorMap_2): this;
|
|
374
374
|
sources(sources: FieldProcessorMap_2): this;
|
|
375
375
|
sections(sections: Record<string, FieldProcessorSectionFunc_2>): this;
|
|
376
|
-
variables(vars: Record<string,
|
|
376
|
+
variables(vars: Record<string, any>): this;
|
|
377
377
|
functions(funcs: Record<string, AsyncFunction>): this;
|
|
378
378
|
getFunctions(): Record<string, AsyncFunction>;
|
|
379
379
|
getOutputs(): Output[];
|
package/dist/index.js
CHANGED
|
@@ -25,4 +25,4 @@ ${s.map(([a,p])=>`${i}${a} = ${cr(p,e+1,t)}`).join(`
|
|
|
25
25
|
${n}}`}else return String(r)},Z=(r)=>{if(!r)return r;return r.replaceAll("\\n",`
|
|
26
26
|
`).replaceAll("\\$","$").replaceAll("\\t","\t")};var he=()=>({...H({merge:(...r)=>r.flatMap((e)=>e)}),join:({args:[r],root:e,tags:t})=>{let n=defined(r,"Join source cannot be null or undefined"),i=t.key?.[0],s=t.separator?.[0]??t.sep?.[0],f=t.finalize?.length>0,a=Z(s);if(typeof n==="string"){if(f&&n.length&&a)return n+a;return n}if(!Array.isArray(n))throw Error("Object is not a list");let p=((i?.length)?n.map((O)=>Object.select({...e,...O},i)):n).join(a),y=t.pad?.[0]??"0",d=t.padChar?.[0]??" ",m=f&&p.length&&a?p+a:p;return y?m.padBlock(parseInt(y),`
|
|
27
27
|
`,d):m},range:({args:[r,e,t]})=>{let n=parseInt(r),i=parseInt(e),s=parseInt(t)||1;if(isNaN(n))throw Error("Invalid range: start value '"+String(r)+"' is not a number");if(isNaN(i))throw Error("Invalid range: end value '"+String(e)+"' is not a number");if(s===0)throw Error("Invalid range: step cannot be zero");if((i-n)/s<0)throw Error("Invalid range: step "+String(s)+" has wrong direction for range "+String(n)+" to "+String(i));return Array.from({length:Math.floor((i-n)/s)+1},(f,a)=>n+a*s)},filter:{types:(r,e,t)=>{switch(r){case 0:return"array";case 1:return Object.keys(R)}return ur[t[1].value]?.(r-2,e,t.slice(2))},fn:({args:[r,e,t],root:n,tags:i})=>{if(r===null||r===void 0)throw Error("Filter source cannot be null or undefined");if(!Array.isArray(r))throw Error("Filter source must be an array");let s=i.key?.[0],f=R[e];if(s){let p=Array(r.length);for(let d=0;d<r.length;d++)try{p[d]=Object.select({...n,...r[d]},s)}catch{p[d]=Symbol("invalid")}let y=[];for(let d=0;d<r.length;d++){let m=p[d];if(typeof m!=="symbol"&&t===void 0?f(m):f(m,t))y.push(r[d])}return y}let a=[];for(let p of r)if(t===void 0?f(p):f(p,t))a.push(p);return a}}});var de=()=>({each:{processArgs:!1,fn:async({rawArgs:[r,e,...t],root:n,options:i,tags:s})=>{let f=async(w)=>w.quoted?Z(w.value):await Object.select(n,w.value),a=await Object.select(n,r.value),p=await f(e),y=s.key?.[0],d=Array.isArray(a)?a:Object.toList(a,"name"),m=[],O=await t.mapAsync(async(w)=>await f(w)),b={...n,item:void 0,index:0,params:O,instance:void 0,parent:n.this,tags:s},P={...i,root:b};if(await d.forEachAsync(async(w,j)=>{let D=Object.deepClone(p),A={instance:D},F=typeof p==="string"?A:D;if(b.item=w,b.index=j,b.instance=D,s?.root?.[0])Object.assign(b,await Object.select(b,s.root[0]));if(await $(F,P),y!==void 0)m.push(await Object.select(A.instance,y));else m.push(A.instance)}),s.join?.length){if(m.length===0)return"";let w=Z(s.join[0]),j=s.pad?.[0]??"0",D=s.padChar?.[0]??" ",A=s.finalize?.length&&w?w:"",F=`${m.join(w)}${A}`;return j?F.padBlock(parseInt(j),`
|
|
28
|
-
`,D):F}return m}}});var Q=async(r,e,t)=>r.rawArgs[e].quoted?r.rawArgs[e].value:await Object.select(r.root,r.rawArgs[e].value,{defaultValue:t}),be=()=>({switch:{processArgs:!1,fn:async(r)=>{let e=await Q(r,0,!1),t=await Q(r,1);if(t[e]===void 0){if(r.rawArgs.length>2)return Q(r,2);throw Error(`Unhandled switch case: ${e}`)}return t[e]}}});var we=()=>({if:{types:{0:"boolean"},fn:(r)=>r.args[0]?r.args[1]:r.args[2]},check:{types:{0:Object.keys(R)},fn:(r)=>R[r.args[0]](...r.args.slice(1))},...H(R,{types:ur})});var Oe=(r)=>({default:{processArgs:!1,fn:async(e)=>{for(let t=0;t<e.rawArgs.length;t++)if(e.rawArgs[t]?.value!==void 0){let i=await Q(e,t,null);if(i!==null)return i}if(e.tags.nullable?.length)return g.DeleteItem();if(e.tags.fail?.length)throw Error(`No valid value found for default (${e.rawArgs.map((t)=>t.value).join(", ")})`);return""}},section:{types:["string","boolean"],fn:(e)=>{let t=e.args[0];if(!(e.args[1]??!0))return null;let i=r.getSection(t);if(!i)throw Error(`Section not found: ${t}`);return i.content}}});var Ae=()=>({convert:({args:[r,e,t]})=>{switch(e){case"string":return String(r);case"number":{let n=Number(r);if(!isNaN(n))return g.ReplaceItem(n);break}case"boolean":if(r==="true"||r===!0||r===1||r==="1"||r==="yes"||r==="on")return g.ReplaceItem(!0);else if(r==="false"||r===!1||r===0||r==="0"||r==="no"||r==="off")return g.ReplaceItem(!1);break;default:throw Error(`Unsupported type for convert: ${e}`)}if(t!==void 0)return g.ReplaceItem(t);throw Error(`Failed to convert value to ${e}`)},isType:({args:[r,e]})=>{let n=(()=>{switch(e){case"string":return typeof r==="string";case"number":return typeof r==="number";case"boolean":return typeof r==="boolean";case"object":return r!==null&&typeof r==="object"&&!Array.isArray(r);case"array":return Array.isArray(r);case"null":return r===null;case"undefined":return r===void 0;case"function":return typeof r==="function";default:throw Error(`Unknown type for isType: ${e}`)}})();return g.ReplaceItem(n)},typeOf:({args:[r]})=>{if(r===null)return"null";else if(Array.isArray(r))return"array";else return typeof r}});var je=(r)=>{var e,t,n,i,s,f,a,p,y,d,m,O,b,P,w,j,D,A,F,E,M,T,B,C,x,V,Mr,v,J,lr,rr,pr,Se,Ee,Fe,Me,$e,Pe,De,ke,Ce,Le,Re,Ie,Be,Ue,_e,We,Je,Ke,Ne,Ye,ze,qe,He,Ge,Ze,Qe,Xe,Te,xe,Ve,ve,rt,et,tt,nt,it,ot,st,at,ft,ut,ct,lt,pt,mt,gt,yt,ht,dt,bt,wt,Ot,At,jt,St,Et,Ft,Mt,$t,Pt,Dt,kt,Ct,Lt,Rt,It,Bt,Ut,_t,Wt,Jt,Kt,i,s,f,a,p,y,d,m,O,b,P,w,j,D,A,F,E,M,T,B,C,x,V,Mr,v,J,lr,rr,pr,Se,Ee,Fe,Me,$e,Pe,De,ke,Ce,Le,Re,Ie,Be,Ue,_e,We,Je,Ke,Ne,Ye,ze,qe,He,Ge,Ze,Qe,Xe,Te,xe,Ve,ve,rt,et,tt,nt,it,ot,st,at,ft,ut,ct,lt,pt,mt,gt,yt,ht,dt,bt,wt,Ot,At,jt,St,Et,Ft,Mt,$t,Pt,Dt,kt,Ct,Lt,Rt,It,Bt,Ut,_t,Wt,Jt,Kt;return r.use((n=z,i=[c()],s=[c()],f=[c()],a=[c()],p=[c()],y=[c()],d=[c()],m=[c()],O=[c()],b=[c()],P=[c()],w=[c()],j=[c()],D=[c()],A=[c()],F=[c()],E=[c()],M=[c()],T=[c()],B=[c()],C=[c()],x=[c()],V=[c()],Mr=[c()],v=[c()],J=[c()],lr=[c()],rr=[c()],pr=[c()],Se=[c()],Ee=[c()],Fe=[c()],Me=[c()],$e=[c()],Pe=[c()],De=[c()],ke=[c()],Ce=[c()],Le=[c()],Re=[c()],Ie=[c()],Be=[c()],Ue=[c()],_e=[c()],We=[c()],Je=[c()],Ke=[c()],Ne=[c()],Ye=[c()],ze=[c()],qe=[c()],He=[c()],Ge=[c()],Ze=[c()],Qe=[c()],Xe=[c()],Te=[c()],xe=[c()],Ve=[c()],ve=[c()],rt=[c()],et=[c()],tt=[c()],nt=[c()],it=[c()],ot=[c()],st=[c()],at=[c()],ft=[c()],ut=[c()],ct=[c()],lt=[c()],pt=[c()],mt=[c()],gt=[c()],yt=[c()],ht=[c()],dt=[c()],bt=[c()],wt=[c()],Ot=[c()],At=[c()],jt=[c()],St=[c()],Et=[c()],Ft=[c()],Mt=[c()],$t=[c()],Pt=[c()],Dt=[c()],kt=[c()],Ct=[c()],Lt=[c()],Rt=[c()],It=[c()],Bt=[c()],Ut=[c()],_t=[c()],Wt=[c()],Jt=[c()],Kt=[c()],t=Lr(n),e=class extends n{constructor(){super(...arguments);Ir(t,5,this)}env(o){return process.env[o]}uuid(){return crypto.randomUUID()}pascal(o){return o.toPascal()}camel(o){return o.toCamel()}capital(o){return o.capitalize()}snake(o,l="lower"){return o.changeCase(l).toSnake()}kebab(o,l="lower"){return o.changeCase(l).toKebab()}len(o){return o.length}reverse(o){return o.split("").reverse().join("")}concat(...o){return o.join("")}trim(o){return o.trim()}ltrim(o){return o.trimStart()}rtrim(o){return o.trimEnd()}lower(o){return o.toLowerCase()}upper(o){return o.toUpperCase()}encode(o,l){return Buffer.from(o).toString(l??"base64")}decode(o,l){return Buffer.from(o,l??"base64").toString()}list(o,l="name"){return Object.toList(o,l)}object(o,l="name"){return o.toObject((h)=>h[l],(h)=>{let{[l]:S,...k}=h;return k})}pathJoin(...o){return I.join(...o)}resolve(...o){return I.resolve(...o)}dirname(o){return I.dirname(o)}basename(o,l){return I.basename(o,l)}normalize(o){return I.normalize(o)}extname(o){return I.extname(o)}relative(o,l){return I.relative(o,l)}isAbsolute(o){return I.isAbsolute(o)}segments(o){return o.split("/").filter(Boolean)}log(...o){console.log(...o)}md5(o){return W("md5").update(o).digest("hex")}sha1(o){return W("sha1").update(o).digest("hex")}sha256(o){return W("sha256").update(o).digest("hex")}sha512(o){return W("sha512").update(o).digest("hex")}hash(o,l="sha256"){return W(l).update(o).digest("hex")}hmac(o,l,h="sha256"){return W(h).update(o).digest("hex")}base64Encode(o){return Buffer.from(o).toString("base64")}base64Decode(o){return Buffer.from(o,"base64").toString("utf-8")}hexEncode(o){return Buffer.from(o).toString("hex")}hexDecode(o){return Buffer.from(o,"hex").toString("utf-8")}add(...o){return o.reduce((l,h)=>l+h,0)}subtract(o,l){return o-l}multiply(...o){return o.reduce((l,h)=>l*h,1)}divide(o,l){if(l===0)throw Error("Division by zero");return o/l}modulo(o,l){return o%l}power(o,l){return Math.pow(o,l)}sqrt(o){return Math.sqrt(o)}abs(o){return Math.abs(o)}floor(o){return Math.floor(o)}ceil(o){return Math.ceil(o)}round(o,l){let h=Math.pow(10,l??0);return Math.round(o*h)/h}min(...o){return Math.min(...o)}max(...o){return Math.max(...o)}clamp(o,l,h){return Math.max(l,Math.min(h,o))}random(o,l){let h=o??0,S=l??1;return Math.random()*(S-h)+h}timestamp(o){return new Date(o).getTime()}iso(o){return new Date(o).toISOString()}utc(o){return new Date(o).toUTCString()}formatDate(o,l){let h=new Date(o),S=h.getFullYear(),k=String(h.getMonth()+1).padStart(2,"0"),er=String(h.getDate()).padStart(2,"0"),K=String(h.getHours()).padStart(2,"0"),Nt=String(h.getMinutes()).padStart(2,"0"),Yt=String(h.getSeconds()).padStart(2,"0");return l.replace("YYYY",String(S)).replace("MM",k).replace("DD",er).replace("HH",K).replace("mm",Nt).replace("ss",Yt)}parseDate(o){return new Date(o).getTime()}year(o){return new Date(o).getFullYear()}month(o){return new Date(o).getMonth()+1}day(o){return new Date(o).getDate()}dayOfWeek(o){return new Date(o).getDay()}hours(o){return new Date(o).getHours()}minutes(o){return new Date(o).getMinutes()}seconds(o){return new Date(o).getSeconds()}regexTest(o,l,h){return new RegExp(o,h).test(l)}regexMatch(o,l,h){return new RegExp(o,h).exec(l)}regexMatchAll(o,l,h){return Array.from(l.matchAll(new RegExp(o,h)))}regexReplace(o,l,h,S){return h.replace(new RegExp(o,S),l)}regexReplaceAll(o,l,h,S){return h.replace(new RegExp(o,S??"g"),l)}regexSplit(o,l,h){return l.split(new RegExp(o,h))}regexExec(o,l,h){return new RegExp(o,h).exec(l)}regexSearch(o,l,h){return l.search(new RegExp(o,h))}unique(o,l){if(!Array.isArray(o))return o;let h=new Set;return o.filter((S)=>{let k=l?S[l]:S;if(h.has(k))return!1;return h.add(k),!0})}groupBy(o,l){if(!Array.isArray(o))return o;let h={};return o.forEach((S)=>{let k=String(S[l]);if(!h[k])h[k]=[];h[k].push(S)}),h}chunk(o,l=1){if(!Array.isArray(o))return[];let h=[];for(let S=0;S<o.length;S+=l)h.push(o.slice(S,S+l));return h}flatten(o,l=1){if(!Array.isArray(o))return[o];let h=[],S=(k,er)=>{for(let K of k)if(Array.isArray(K)&&er>0)S(K,er-1);else h.push(K)};return S(o,l),h}compact(o){if(!Array.isArray(o))return o;return o.filter((l)=>l!==null&&l!==void 0)}head(o,l){if(!Array.isArray(o))return o;return l?o.slice(0,l):o[0]}tail(o,l){if(!Array.isArray(o))return o;return l?o.slice(-l):o[o.length-1]}isEmail(o){return/^[^\s@]+@[^\s@]+\.[^\s@]+$/.test(o)}isUrl(o){try{return new URL(o),!0}catch{return!1}}isJson(o){try{return JSON.parse(o),!0}catch{return!1}}isUuid(o){return/^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}$/i.test(o)}minLength(o,l){return o?.length>=l}maxLength(o,l){return o?.length<=l}lengthEquals(o,l){return o?.length===l}isNumber(o){return typeof o==="number"&&!isNaN(o)}isString(o){return typeof o==="string"}isBoolean(o){return typeof o==="boolean"}isArray(o){return Array.isArray(o)}isObject(o){return o!==null&&typeof o==="object"&&!Array.isArray(o)}isEmpty(o){if(o===null||o===void 0)return!0;if(typeof o==="string"||Array.isArray(o))return o.length===0;if(typeof o==="object")return Object.keys(o).length===0;return!1}isTruthy(o){return!!o}isFalsy(o){return!o}inRange(o,l,h){return o>=l&&o<=h}matchesPattern(o,l){return new RegExp(l).test(o)}includes(o,l){if(typeof o==="string")return o.includes(String(l));return Array.isArray(o)&&o.includes(l)}startsWith(o,l){return o.startsWith(l)}endsWith(o,l){return o.endsWith(l)}},u(t,1,"env",i,e),u(t,1,"uuid",s,e),u(t,1,"pascal",f,e),u(t,1,"camel",a,e),u(t,1,"capital",p,e),u(t,1,"snake",y,e),u(t,1,"kebab",d,e),u(t,1,"len",m,e),u(t,1,"reverse",O,e),u(t,1,"concat",b,e),u(t,1,"trim",P,e),u(t,1,"ltrim",w,e),u(t,1,"rtrim",j,e),u(t,1,"lower",D,e),u(t,1,"upper",A,e),u(t,1,"encode",F,e),u(t,1,"decode",E,e),u(t,1,"list",M,e),u(t,1,"object",T,e),u(t,1,"pathJoin",B,e),u(t,1,"resolve",C,e),u(t,1,"dirname",x,e),u(t,1,"basename",V,e),u(t,1,"normalize",Mr,e),u(t,1,"extname",v,e),u(t,1,"relative",J,e),u(t,1,"isAbsolute",lr,e),u(t,1,"segments",rr,e),u(t,1,"log",pr,e),u(t,1,"md5",Se,e),u(t,1,"sha1",Ee,e),u(t,1,"sha256",Fe,e),u(t,1,"sha512",Me,e),u(t,1,"hash",$e,e),u(t,1,"hmac",Pe,e),u(t,1,"base64Encode",De,e),u(t,1,"base64Decode",ke,e),u(t,1,"hexEncode",Ce,e),u(t,1,"hexDecode",Le,e),u(t,1,"add",Re,e),u(t,1,"subtract",Ie,e),u(t,1,"multiply",Be,e),u(t,1,"divide",Ue,e),u(t,1,"modulo",_e,e),u(t,1,"power",We,e),u(t,1,"sqrt",Je,e),u(t,1,"abs",Ke,e),u(t,1,"floor",Ne,e),u(t,1,"ceil",Ye,e),u(t,1,"round",ze,e),u(t,1,"min",qe,e),u(t,1,"max",He,e),u(t,1,"clamp",Ge,e),u(t,1,"random",Ze,e),u(t,1,"timestamp",Qe,e),u(t,1,"iso",Xe,e),u(t,1,"utc",Te,e),u(t,1,"formatDate",xe,e),u(t,1,"parseDate",Ve,e),u(t,1,"year",ve,e),u(t,1,"month",rt,e),u(t,1,"day",et,e),u(t,1,"dayOfWeek",tt,e),u(t,1,"hours",nt,e),u(t,1,"minutes",it,e),u(t,1,"seconds",ot,e),u(t,1,"regexTest",st,e),u(t,1,"regexMatch",at,e),u(t,1,"regexMatchAll",ft,e),u(t,1,"regexReplace",ut,e),u(t,1,"regexReplaceAll",ct,e),u(t,1,"regexSplit",lt,e),u(t,1,"regexExec",pt,e),u(t,1,"regexSearch",mt,e),u(t,1,"unique",gt,e),u(t,1,"groupBy",yt,e),u(t,1,"chunk",ht,e),u(t,1,"flatten",dt,e),u(t,1,"compact",bt,e),u(t,1,"head",wt,e),u(t,1,"tail",Ot,e),u(t,1,"isEmail",At,e),u(t,1,"isUrl",jt,e),u(t,1,"isJson",St,e),u(t,1,"isUuid",Et,e),u(t,1,"minLength",Ft,e),u(t,1,"maxLength",Mt,e),u(t,1,"lengthEquals",$t,e),u(t,1,"isNumber",Pt,e),u(t,1,"isString",Dt,e),u(t,1,"isBoolean",kt,e),u(t,1,"isArray",Ct,e),u(t,1,"isObject",Lt,e),u(t,1,"isEmpty",Rt,e),u(t,1,"isTruthy",It,e),u(t,1,"isFalsy",Bt,e),u(t,1,"inRange",Ut,e),u(t,1,"matchesPattern",_t,e),u(t,1,"includes",Wt,e),u(t,1,"startsWith",Jt,e),u(t,1,"endsWith",Kt,e),gr(t,e),e)).keys({...Yr(r),...zr(r),...re(),...ee(),...oe(),...te(),...ne(),...ie(r),...ae(r),...fe(),...ue(),...ce()}).sources({...ge(r),...ye(r),...Ae(),...he(),...de(),...be(),...we(),...Oe(r)}).sections(pe(r)).fieldOptions({configParser:Bun.YAML.parse,onSection:(o)=>{if(o.section.config.name)r.section(o.section)}}).decoders({yaml:{matching:["\\.yml$","\\.yaml$"],fn:Bun.YAML.parse}}).encoders({json:{fn:(o)=>JSON.stringify(o,null,2)},yaml:{fn:(o)=>Bun.YAML.stringify(o,null,2)},terraform:{options:{includeTags:!0},fn:(o,l)=>cr(o,0,{sortKeys:!!(l?.sort?.length??l?.sortKeys?.length)})}})};import wn from"fs/promises";import X from"path";class Er{includeDirectories=[];baseIncludeDirectories=[];includes=[];addDirectories(...r){this.includeDirectories.push(...r),this.baseIncludeDirectories.push(...r)}getDirectories(){return this.includeDirectories}reset(){this.includeDirectories=[...this.baseIncludeDirectories]}restore(r){this.includeDirectories=[...r]}snapshot(){return[...this.includeDirectories]}addFiles(...r){this.includes.push(...r)}getPendingAndClear(){let r=[...this.includes];return this.includes.length=0,r}async processPatterns(r,e,t){let n=[];for(let i of r)if(_.isGlobPattern(i)){let s=(await Array.fromAsync(wn.glob(i,{cwd:e}))).map((f)=>X.join(e,f));n.push(...s.filter((f)=>!t.included.includes(f)))}else if(_.isDirectoryPattern(i)){let s=X.isAbsolute(i)?i:X.join(e,i);if(!this.includeDirectories.includes(s))this.includeDirectories.push(s)}else n.push(i);return n.unique()}buildSearchDirs(r){let e=r?[r]:[];return e.push(...this.includeDirectories.map((t)=>X.isAbsolute(t)?t:X.join(r??process.cwd(),t))),e}}class Fr{includeManager;loadFn;constructor(r,e){this.includeManager=r;this.loadFn=e}async processIncludes(r,e,t){let n=[];if(r.content.includes)n.push(...r.content.includes),delete r.content.includes;n.push(...this.includeManager.getPendingAndClear());let i=await this.includeManager.processPatterns(n,r.folderPath,t);for(let s of i)Object.merge(await this.loadFn(s,r.folderPath,{parent:r.content,...e},!0,t),r.content)}}class On{includeManager=new Er;includeProcessor;cacheManager=new wr(100);outputs=[];vars={};funcs={};fields={sources:{},keys:{},sections:{}};objectMetadata={};currentContext=null;storedSections={};dataEncoders={};dataDecoders={};constructor(){this.includeProcessor=new Fr(this.includeManager,this.load.bind(this)),this.use(je)}use(r){if(r.prototype instanceof z)new r(this);else r(this);return this}includeDirectory(...r){return this.includeManager.addDirectories(...r),this}getIncludeDirectories(){return this.includeManager.getDirectories()}include(...r){return this.includeManager.addFiles(...r),this}keys(r){return Object.assign(this.fields.keys,{...this.fields.keys,...r}),this}sources(r){return Object.assign(this.fields.sources,{...this.fields.sources,...r}),this}sections(r){return Object.assign(this.fields.sections,{...this.fields.sections,...r}),this}variables(r){return Object.assign(this.vars,{...this.vars,...r}),this}functions(r){return Object.assign(this.funcs,{...this.funcs,...r}),this}getFunctions(){return this.funcs}getOutputs(){return this.outputs}output(r){return this.outputs.push(r),this}metadata(r,e){return this.objectMetadata[r]=e,this}getMetadata(r){return this.objectMetadata[r]}getAllMetadata(){return this.objectMetadata}setCacheMaxSize(r){return this.cacheManager.setMaxSize(r),this}clearCache(){return this.cacheManager.clear(),this}getCurrentContext(){return this.currentContext}fieldOptions(r){return Object.assign(this.fields,{...this.fields,...r}),this}section(r){return this.storedSections[r.config.name]=r,this}getSection(r){return this.storedSections[r]}encoders(r){return Object.assign(this.dataEncoders,{...this.dataEncoders,...r}),this}decoders(r){return Object.assign(this.dataDecoders,{...this.dataDecoders,...r}),this}getEncoder(r){return this.dataEncoders[r]}getDecoder(r){return this.dataDecoders[r]}filter(r){return this.fields.filters??=[],this.fields.filters.push(r),this}async loadObject(r,e,t){return $(r,{...this.fields,globalContext:{file:t?.fullPath??"@internal"},root:{...e,...this.fields.root,...this.vars,functions:this.funcs,context:this.currentContext,sections:this.storedSections,$document:{root:{content:r},fileName:t?.fileName??"@internal",folder:t?.folderPath??"@internal",fullPath:t?.fullPath??"@internal"}}})}async load(r,e,t,n,i){let s=this.includeManager.snapshot();try{this.includeManager.reset();let f=this.includeManager.buildSearchDirs(e);if(i)this.currentContext=i;this.currentContext??={included:[],document:null};let a=typeof r==="string"?await Wr(r,{dirs:f,parsers:this.dataDecoders,format:"yaml"}):{content:r,fullPath:"@internal",folderPath:"@internal"};if(typeof r==="string"){let y=_.normalize(a.fullPath);if(this.currentContext.included.push(y),!a.content)return null;let d=this.cacheManager.get(y),m;if(d)m=d.raw;else m=a.content,this.cacheManager.set(y,{raw:m,timestamp:Date.now()});let O=Object.deepClone(m);a.content=O}await this.includeProcessor.processIncludes(a,t,this.currentContext);let p;if(n!==!0)p=await this.loadObject(a.content,t,{fileName:a.fullPath,folderPath:a.folderPath,fullPath:a.fullPath});else p=a.content;return this.currentContext.document=p,p}catch(f){throw this.includeManager.restore(s),f}finally{this.includeManager.restore(s)}}async writeAll(r){await Nr(this.getOutputs(),r)}}export{Nr as writeOutputs,rn as writeOutput,Vt as writeFormat,_n as variable,Wn as sharedFunction,Bn as section,$ as processFields,H as makeFieldProcessorMap,Pi as makeFieldProcessorList,vr as makeFieldProcessor,c as macro,tr as locate,Wr as loadFormat,Un as key,tn as importList,Rn as importGlob,Jr as globMap,ar as getProcessor,Gr as getArgs,br as exists,Jn as encoder,Kn as decoder,R as conditionPredicates,q as StringBuilder,z as ObjectorPlugin,On as Objector,g as NavigateResult,L as NavigateAction,un as Markdown,fn as Logger};
|
|
28
|
+
`,D):F}return m}}});var Q=async(r,e,t)=>r.rawArgs[e].quoted?r.rawArgs[e].value:await Object.select(r.root,r.rawArgs[e].value,{defaultValue:t}),be=()=>({switch:{processArgs:!1,fn:async(r)=>{let e=await Q(r,0,!1),t=await Q(r,1);if(t[e]===void 0){if(r.rawArgs.length>2)return Q(r,2);throw Error(`Unhandled switch case: ${e}`)}return t[e]}}});var we=()=>({if:{types:{0:"boolean"},fn:(r)=>r.args[0]?r.args[1]:r.args[2]},check:{types:{0:Object.keys(R)},fn:(r)=>R[r.args[0]](...r.args.slice(1))},...H(R,{types:ur})});var Oe=(r)=>({default:{processArgs:!1,fn:async(e)=>{for(let t=0;t<e.rawArgs.length;t++)if(e.rawArgs[t]?.value!==void 0){let i=await Q(e,t,null);if(i!==null)return i}if(e.tags.nullable?.length)return g.DeleteItem();if(e.tags.fail?.length)throw Error(`No valid value found for default (${e.rawArgs.map((t)=>t.value).join(", ")})`);return""}},section:{types:["string","boolean"],fn:(e)=>{let t=e.args[0];if(!(e.args[1]??!0))return null;let i=r.getSection(t);if(!i)throw Error(`Section not found: ${t}`);return i.content}}});var Ae=()=>({convert:({args:[r,e,t]})=>{switch(e){case"string":return String(r);case"number":{let n=Number(r);if(!isNaN(n))return g.ReplaceItem(n);break}case"boolean":if(r==="true"||r===!0||r===1||r==="1"||r==="yes"||r==="on")return g.ReplaceItem(!0);else if(r==="false"||r===!1||r===0||r==="0"||r==="no"||r==="off")return g.ReplaceItem(!1);break;default:throw Error(`Unsupported type for convert: ${e}`)}if(t!==void 0)return g.ReplaceItem(t);throw Error(`Failed to convert value to ${e}`)},isType:({args:[r,e]})=>{let n=(()=>{switch(e){case"string":return typeof r==="string";case"number":return typeof r==="number";case"boolean":return typeof r==="boolean";case"object":return r!==null&&typeof r==="object"&&!Array.isArray(r);case"array":return Array.isArray(r);case"null":return r===null;case"undefined":return r===void 0;case"function":return typeof r==="function";default:throw Error(`Unknown type for isType: ${e}`)}})();return g.ReplaceItem(n)},typeOf:({args:[r]})=>{if(r===null)return"null";else if(Array.isArray(r))return"array";else return typeof r}});var je=(r)=>{var e,t,n,i,s,f,a,p,y,d,m,O,b,P,w,j,D,A,F,E,M,T,B,C,x,V,Mr,v,J,lr,rr,pr,Se,Ee,Fe,Me,$e,Pe,De,ke,Ce,Le,Re,Ie,Be,Ue,_e,We,Je,Ke,Ne,Ye,ze,qe,He,Ge,Ze,Qe,Xe,Te,xe,Ve,ve,rt,et,tt,nt,it,ot,st,at,ft,ut,ct,lt,pt,mt,gt,yt,ht,dt,bt,wt,Ot,At,jt,St,Et,Ft,Mt,$t,Pt,Dt,kt,Ct,Lt,Rt,It,Bt,Ut,_t,Wt,Jt,Kt,i,s,f,a,p,y,d,m,O,b,P,w,j,D,A,F,E,M,T,B,C,x,V,Mr,v,J,lr,rr,pr,Se,Ee,Fe,Me,$e,Pe,De,ke,Ce,Le,Re,Ie,Be,Ue,_e,We,Je,Ke,Ne,Ye,ze,qe,He,Ge,Ze,Qe,Xe,Te,xe,Ve,ve,rt,et,tt,nt,it,ot,st,at,ft,ut,ct,lt,pt,mt,gt,yt,ht,dt,bt,wt,Ot,At,jt,St,Et,Ft,Mt,$t,Pt,Dt,kt,Ct,Lt,Rt,It,Bt,Ut,_t,Wt,Jt,Kt;return r.use((n=z,i=[c()],s=[c()],f=[c()],a=[c()],p=[c()],y=[c()],d=[c()],m=[c()],O=[c()],b=[c()],P=[c()],w=[c()],j=[c()],D=[c()],A=[c()],F=[c()],E=[c()],M=[c()],T=[c()],B=[c()],C=[c()],x=[c()],V=[c()],Mr=[c()],v=[c()],J=[c()],lr=[c()],rr=[c()],pr=[c()],Se=[c()],Ee=[c()],Fe=[c()],Me=[c()],$e=[c()],Pe=[c()],De=[c()],ke=[c()],Ce=[c()],Le=[c()],Re=[c()],Ie=[c()],Be=[c()],Ue=[c()],_e=[c()],We=[c()],Je=[c()],Ke=[c()],Ne=[c()],Ye=[c()],ze=[c()],qe=[c()],He=[c()],Ge=[c()],Ze=[c()],Qe=[c()],Xe=[c()],Te=[c()],xe=[c()],Ve=[c()],ve=[c()],rt=[c()],et=[c()],tt=[c()],nt=[c()],it=[c()],ot=[c()],st=[c()],at=[c()],ft=[c()],ut=[c()],ct=[c()],lt=[c()],pt=[c()],mt=[c()],gt=[c()],yt=[c()],ht=[c()],dt=[c()],bt=[c()],wt=[c()],Ot=[c()],At=[c()],jt=[c()],St=[c()],Et=[c()],Ft=[c()],Mt=[c()],$t=[c()],Pt=[c()],Dt=[c()],kt=[c()],Ct=[c()],Lt=[c()],Rt=[c()],It=[c()],Bt=[c()],Ut=[c()],_t=[c()],Wt=[c()],Jt=[c()],Kt=[c()],t=Lr(n),e=class extends n{constructor(){super(...arguments);Ir(t,5,this)}env(o){return process.env[o]}uuid(){return crypto.randomUUID()}pascal(o){return o.toPascal()}camel(o){return o.toCamel()}capital(o){return o.capitalize()}snake(o,l="lower"){return o.changeCase(l).toSnake()}kebab(o,l="lower"){return o.changeCase(l).toKebab()}len(o){return o.length}reverse(o){return o.split("").reverse().join("")}concat(...o){return o.join("")}trim(o){return o.trim()}ltrim(o){return o.trimStart()}rtrim(o){return o.trimEnd()}lower(o){return o.toLowerCase()}upper(o){return o.toUpperCase()}encode(o,l){return Buffer.from(o).toString(l??"base64")}decode(o,l){return Buffer.from(o,l??"base64").toString()}list(o,l="name"){return Object.toList(o,l)}object(o,l="name"){return o.toObject((h)=>h[l],(h)=>{let{[l]:S,...k}=h;return k})}pathJoin(...o){return I.join(...o)}resolve(...o){return I.resolve(...o)}dirname(o){return I.dirname(o)}basename(o,l){return I.basename(o,l)}normalize(o){return I.normalize(o)}extname(o){return I.extname(o)}relative(o,l){return I.relative(o,l)}isAbsolute(o){return I.isAbsolute(o)}segments(o){return o.split("/").filter(Boolean)}log(...o){console.log(...o)}md5(o){return W("md5").update(o).digest("hex")}sha1(o){return W("sha1").update(o).digest("hex")}sha256(o){return W("sha256").update(o).digest("hex")}sha512(o){return W("sha512").update(o).digest("hex")}hash(o,l="sha256"){return W(l).update(o).digest("hex")}hmac(o,l,h="sha256"){return W(h).update(o).digest("hex")}base64Encode(o){return Buffer.from(o).toString("base64")}base64Decode(o){return Buffer.from(o,"base64").toString("utf-8")}hexEncode(o){return Buffer.from(o).toString("hex")}hexDecode(o){return Buffer.from(o,"hex").toString("utf-8")}add(...o){return o.reduce((l,h)=>l+h,0)}subtract(o,l){return o-l}multiply(...o){return o.reduce((l,h)=>l*h,1)}divide(o,l){if(l===0)throw Error("Division by zero");return o/l}modulo(o,l){return o%l}power(o,l){return Math.pow(o,l)}sqrt(o){return Math.sqrt(o)}abs(o){return Math.abs(o)}floor(o){return Math.floor(o)}ceil(o){return Math.ceil(o)}round(o,l){let h=Math.pow(10,l??0);return Math.round(o*h)/h}min(...o){return Math.min(...o)}max(...o){return Math.max(...o)}clamp(o,l,h){return Math.max(l,Math.min(h,o))}random(o,l){let h=o??0,S=l??1;return Math.random()*(S-h)+h}timestamp(o){return new Date(o).getTime()}iso(o){return new Date(o).toISOString()}utc(o){return new Date(o).toUTCString()}formatDate(o,l){let h=new Date(o),S=h.getFullYear(),k=String(h.getMonth()+1).padStart(2,"0"),er=String(h.getDate()).padStart(2,"0"),K=String(h.getHours()).padStart(2,"0"),Nt=String(h.getMinutes()).padStart(2,"0"),Yt=String(h.getSeconds()).padStart(2,"0");return l.replace("YYYY",String(S)).replace("MM",k).replace("DD",er).replace("HH",K).replace("mm",Nt).replace("ss",Yt)}parseDate(o){return new Date(o).getTime()}year(o){return new Date(o).getFullYear()}month(o){return new Date(o).getMonth()+1}day(o){return new Date(o).getDate()}dayOfWeek(o){return new Date(o).getDay()}hours(o){return new Date(o).getHours()}minutes(o){return new Date(o).getMinutes()}seconds(o){return new Date(o).getSeconds()}regexTest(o,l,h){return new RegExp(o,h).test(l)}regexMatch(o,l,h){return new RegExp(o,h).exec(l)}regexMatchAll(o,l,h){return Array.from(l.matchAll(new RegExp(o,h)))}regexReplace(o,l,h,S){return h.replace(new RegExp(o,S),l)}regexReplaceAll(o,l,h,S){return h.replace(new RegExp(o,S??"g"),l)}regexSplit(o,l,h){return l.split(new RegExp(o,h))}regexExec(o,l,h){return new RegExp(o,h).exec(l)}regexSearch(o,l,h){return l.search(new RegExp(o,h))}unique(o,l){if(!Array.isArray(o))return o;let h=new Set;return o.filter((S)=>{let k=l?S[l]:S;if(h.has(k))return!1;return h.add(k),!0})}groupBy(o,l){if(!Array.isArray(o))return o;let h={};return o.forEach((S)=>{let k=String(S[l]);if(!h[k])h[k]=[];h[k].push(S)}),h}chunk(o,l=1){if(!Array.isArray(o))return[];let h=[];for(let S=0;S<o.length;S+=l)h.push(o.slice(S,S+l));return h}flatten(o,l=1){if(!Array.isArray(o))return[o];let h=[],S=(k,er)=>{for(let K of k)if(Array.isArray(K)&&er>0)S(K,er-1);else h.push(K)};return S(o,l),h}compact(o){if(!Array.isArray(o))return o;return o.filter((l)=>l!==null&&l!==void 0)}head(o,l){if(!Array.isArray(o))return o;return l?o.slice(0,l):o[0]}tail(o,l){if(!Array.isArray(o))return o;return l?o.slice(-l):o[o.length-1]}isEmail(o){return/^[^\s@]+@[^\s@]+\.[^\s@]+$/.test(o)}isUrl(o){try{return new URL(o),!0}catch{return!1}}isJson(o){try{return JSON.parse(o),!0}catch{return!1}}isUuid(o){return/^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}$/i.test(o)}minLength(o,l){return o?.length>=l}maxLength(o,l){return o?.length<=l}lengthEquals(o,l){return o?.length===l}isNumber(o){return typeof o==="number"&&!isNaN(o)}isString(o){return typeof o==="string"}isBoolean(o){return typeof o==="boolean"}isArray(o){return Array.isArray(o)}isObject(o){return o!==null&&typeof o==="object"&&!Array.isArray(o)}isEmpty(o){if(o===null||o===void 0)return!0;if(typeof o==="string"||Array.isArray(o))return o.length===0;if(typeof o==="object")return Object.keys(o).length===0;return!1}isTruthy(o){return!!o}isFalsy(o){return!o}inRange(o,l,h){return o>=l&&o<=h}matchesPattern(o,l){return new RegExp(l).test(o)}includes(o,l){if(typeof o==="string")return o.includes(String(l));return Array.isArray(o)&&o.includes(l)}startsWith(o,l){return o.startsWith(l)}endsWith(o,l){return o.endsWith(l)}},u(t,1,"env",i,e),u(t,1,"uuid",s,e),u(t,1,"pascal",f,e),u(t,1,"camel",a,e),u(t,1,"capital",p,e),u(t,1,"snake",y,e),u(t,1,"kebab",d,e),u(t,1,"len",m,e),u(t,1,"reverse",O,e),u(t,1,"concat",b,e),u(t,1,"trim",P,e),u(t,1,"ltrim",w,e),u(t,1,"rtrim",j,e),u(t,1,"lower",D,e),u(t,1,"upper",A,e),u(t,1,"encode",F,e),u(t,1,"decode",E,e),u(t,1,"list",M,e),u(t,1,"object",T,e),u(t,1,"pathJoin",B,e),u(t,1,"resolve",C,e),u(t,1,"dirname",x,e),u(t,1,"basename",V,e),u(t,1,"normalize",Mr,e),u(t,1,"extname",v,e),u(t,1,"relative",J,e),u(t,1,"isAbsolute",lr,e),u(t,1,"segments",rr,e),u(t,1,"log",pr,e),u(t,1,"md5",Se,e),u(t,1,"sha1",Ee,e),u(t,1,"sha256",Fe,e),u(t,1,"sha512",Me,e),u(t,1,"hash",$e,e),u(t,1,"hmac",Pe,e),u(t,1,"base64Encode",De,e),u(t,1,"base64Decode",ke,e),u(t,1,"hexEncode",Ce,e),u(t,1,"hexDecode",Le,e),u(t,1,"add",Re,e),u(t,1,"subtract",Ie,e),u(t,1,"multiply",Be,e),u(t,1,"divide",Ue,e),u(t,1,"modulo",_e,e),u(t,1,"power",We,e),u(t,1,"sqrt",Je,e),u(t,1,"abs",Ke,e),u(t,1,"floor",Ne,e),u(t,1,"ceil",Ye,e),u(t,1,"round",ze,e),u(t,1,"min",qe,e),u(t,1,"max",He,e),u(t,1,"clamp",Ge,e),u(t,1,"random",Ze,e),u(t,1,"timestamp",Qe,e),u(t,1,"iso",Xe,e),u(t,1,"utc",Te,e),u(t,1,"formatDate",xe,e),u(t,1,"parseDate",Ve,e),u(t,1,"year",ve,e),u(t,1,"month",rt,e),u(t,1,"day",et,e),u(t,1,"dayOfWeek",tt,e),u(t,1,"hours",nt,e),u(t,1,"minutes",it,e),u(t,1,"seconds",ot,e),u(t,1,"regexTest",st,e),u(t,1,"regexMatch",at,e),u(t,1,"regexMatchAll",ft,e),u(t,1,"regexReplace",ut,e),u(t,1,"regexReplaceAll",ct,e),u(t,1,"regexSplit",lt,e),u(t,1,"regexExec",pt,e),u(t,1,"regexSearch",mt,e),u(t,1,"unique",gt,e),u(t,1,"groupBy",yt,e),u(t,1,"chunk",ht,e),u(t,1,"flatten",dt,e),u(t,1,"compact",bt,e),u(t,1,"head",wt,e),u(t,1,"tail",Ot,e),u(t,1,"isEmail",At,e),u(t,1,"isUrl",jt,e),u(t,1,"isJson",St,e),u(t,1,"isUuid",Et,e),u(t,1,"minLength",Ft,e),u(t,1,"maxLength",Mt,e),u(t,1,"lengthEquals",$t,e),u(t,1,"isNumber",Pt,e),u(t,1,"isString",Dt,e),u(t,1,"isBoolean",kt,e),u(t,1,"isArray",Ct,e),u(t,1,"isObject",Lt,e),u(t,1,"isEmpty",Rt,e),u(t,1,"isTruthy",It,e),u(t,1,"isFalsy",Bt,e),u(t,1,"inRange",Ut,e),u(t,1,"matchesPattern",_t,e),u(t,1,"includes",Wt,e),u(t,1,"startsWith",Jt,e),u(t,1,"endsWith",Kt,e),gr(t,e),e)).keys({...Yr(r),...zr(r),...re(),...ee(),...oe(),...te(),...ne(),...ie(r),...ae(r),...fe(),...ue(),...ce()}).sources({...ge(r),...ye(r),...Ae(),...he(),...de(),...be(),...we(),...Oe(r)}).sections(pe(r)).fieldOptions({configParser:Bun.YAML.parse,onSection:(o)=>{if(o.section.config.name)r.section(o.section)}}).decoders({yaml:{matching:["\\.yml$","\\.yaml$"],fn:Bun.YAML.parse}}).encoders({json:{fn:(o)=>JSON.stringify(o,null,2)},yaml:{fn:(o)=>Bun.YAML.stringify(o,null,2)},terraform:{options:{includeTags:!0},fn:(o,l)=>cr(o,0,{sortKeys:!!(l?.sort?.length??l?.sortKeys?.length)})}})};import wn from"fs/promises";import X from"path";class Er{includeDirectories=[];baseIncludeDirectories=[];includes=[];addDirectories(...r){this.includeDirectories.push(...r),this.baseIncludeDirectories.push(...r)}getDirectories(){return this.includeDirectories}reset(){this.includeDirectories=[...this.baseIncludeDirectories]}restore(r){this.includeDirectories=[...r]}snapshot(){return[...this.includeDirectories]}addFiles(...r){this.includes.push(...r)}getPendingAndClear(){let r=[...this.includes];return this.includes.length=0,r}async processPatterns(r,e,t){let n=[];for(let i of r)if(_.isGlobPattern(i)){let s=(await Array.fromAsync(wn.glob(i,{cwd:e}))).map((f)=>X.join(e,f));n.push(...s.filter((f)=>!t.included.includes(f)))}else if(_.isDirectoryPattern(i)){let s=X.isAbsolute(i)?i:X.join(e,i);if(!this.includeDirectories.includes(s))this.includeDirectories.push(s)}else n.push(i);return n.unique()}buildSearchDirs(r){let e=r?[r]:[];return e.push(...this.includeDirectories.map((t)=>X.isAbsolute(t)?t:X.join(r??process.cwd(),t))),e}}class Fr{includeManager;loadFn;constructor(r,e){this.includeManager=r;this.loadFn=e}async processIncludes(r,e,t){let n=[];if(r.content.includes)n.push(...r.content.includes),delete r.content.includes;n.push(...this.includeManager.getPendingAndClear());let i=await this.includeManager.processPatterns(n,r.folderPath,t);for(let s of i)Object.merge(await this.loadFn(s,r.folderPath,{parent:r.content,...e},!0,t),r.content)}}class On{includeManager=new Er;includeProcessor;cacheManager=new wr(100);outputs=[];vars={};funcs={};fields={sources:{},keys:{},sections:{}};objectMetadata={};currentContext=null;storedSections={};dataEncoders={};dataDecoders={};constructor(){this.includeProcessor=new Fr(this.includeManager,this.load.bind(this)),this.use(je)}use(r){if(r.prototype instanceof z)new r(this);else r(this);return this}includeDirectory(...r){return this.includeManager.addDirectories(...r),this}getIncludeDirectories(){return this.includeManager.getDirectories()}include(...r){return this.includeManager.addFiles(...r),this}keys(r){return Object.assign(this.fields.keys,{...this.fields.keys,...r}),this}sources(r){return Object.assign(this.fields.sources,{...this.fields.sources,...r}),this}sections(r){return Object.assign(this.fields.sections,{...this.fields.sections,...r}),this}variables(r){return Object.assign(this.vars,{...this.vars,...r}),this}functions(r){return Object.assign(this.funcs,{...this.funcs,...r}),this}getFunctions(){return this.funcs}getOutputs(){return this.outputs}output(r){return this.outputs.push(r),this}metadata(r,e){return this.objectMetadata[r]=e,this}getMetadata(r){return this.objectMetadata[r]}getAllMetadata(){return this.objectMetadata}setCacheMaxSize(r){return this.cacheManager.setMaxSize(r),this}clearCache(){return this.cacheManager.clear(),this}getCurrentContext(){return this.currentContext}fieldOptions(r){return Object.assign(this.fields,{...this.fields,...r}),this}section(r){return this.storedSections[r.config.name]=r,this}getSection(r){return this.storedSections[r]}encoders(r){return Object.assign(this.dataEncoders,{...this.dataEncoders,...r}),this}decoders(r){return Object.assign(this.dataDecoders,{...this.dataDecoders,...r}),this}getEncoder(r){return this.dataEncoders[r]}getDecoder(r){return this.dataDecoders[r]}filter(r){return this.fields.filters??=[],this.fields.filters.push(r),this}async loadObject(r,e,t){return $(r,{...this.fields,globalContext:{file:t?.fullPath??"@internal"},root:{...e,...this.fields.root,...this.vars,functions:this.funcs,context:this.currentContext,sections:this.storedSections,$document:{root:{content:r},fileName:t?.fileName??"@internal",folder:t?.folderPath??"@internal",fullPath:t?.fullPath??"@internal"}}})}async load(r,e,t,n,i){let s=this.includeManager.snapshot();try{this.includeManager.reset();let f=this.includeManager.buildSearchDirs(e);if(i)this.currentContext=i;this.currentContext??={included:[],document:null};let a=typeof r==="string"?await Wr(r,{dirs:f,parsers:this.dataDecoders,format:"yaml"}):{content:r,fullPath:"",folderPath:""};if(typeof r==="string"){let y=_.normalize(a.fullPath);if(this.currentContext.included.push(y),!a.content)return null;let d=this.cacheManager.get(y),m;if(d)m=d.raw;else m=a.content,this.cacheManager.set(y,{raw:m,timestamp:Date.now()});let O=Object.deepClone(m);a.content=O}await this.includeProcessor.processIncludes(a,t,this.currentContext);let p;if(n!==!0)p=await this.loadObject(a.content,t,{fileName:a.fullPath,folderPath:a.folderPath,fullPath:a.fullPath});else p=a.content;return this.currentContext.document=p,p}catch(f){throw this.includeManager.restore(s),f}finally{this.includeManager.restore(s)}}async writeAll(r){await Nr(this.getOutputs(),r)}}export{Nr as writeOutputs,rn as writeOutput,Vt as writeFormat,_n as variable,Wn as sharedFunction,Bn as section,$ as processFields,H as makeFieldProcessorMap,Pi as makeFieldProcessorList,vr as makeFieldProcessor,c as macro,tr as locate,Wr as loadFormat,Un as key,tn as importList,Rn as importGlob,Jr as globMap,ar as getProcessor,Gr as getArgs,br as exists,Jn as encoder,Kn as decoder,R as conditionPredicates,q as StringBuilder,z as ObjectorPlugin,On as Objector,g as NavigateResult,L as NavigateAction,un as Markdown,fn as Logger};
|