@homedev/fields 1.2.19 → 1.2.20
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.js +3 -2
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -1,2 +1,3 @@
|
|
|
1
|
-
var s=Object.create;var{getPrototypeOf:o,defineProperty:A,getOwnPropertyNames:a}=Object;var P0=Object.prototype.hasOwnProperty;var f0=(P,y,f)=>{f=P!=null?s(o(P)):{};let M=y||!P||!P.__esModule?A(f,"default",{value:P,enumerable:!0}):f;for(let E of a(P))if(!P0.call(M,E))A(M,E,{get:()=>P[E],enumerable:!0});return M};var y0=(P,y)=>()=>(y||P((y={exports:{}}).exports,y),y.exports);var i=y0((H0,h)=>{var{defineProperty:d,getOwnPropertyNames:F0,getOwnPropertyDescriptor:M0}=Object,W0=Object.prototype.hasOwnProperty,R=new WeakMap,E0=(P)=>{var y=R.get(P),f;if(y)return y;if(y=d({},"__esModule",{value:!0}),P&&typeof P==="object"||typeof P==="function")F0(P).map((M)=>!W0.call(y,M)&&d(y,M,{get:()=>P[M],enumerable:!(f=M0(P,M))||f.enumerable}));return R.set(P,y),y},_0=(P,y)=>{for(var f in y)d(P,f,{get:y[f],enumerable:!0,configurable:!0,set:(M)=>y[f]=()=>M})},w={};_0(w,{splitWithQuotes:()=>D0,splitNested:()=>C0});h.exports=E0(w);var C0=(P,y,f="(",M=")")=>{let E=0,W="",_=[];for(let F of P){if(W+=F,F===f)E++;if(F===M)E--;if(E===0&&F===y)_.push(W.slice(0,-1)),W=""}if(W)_.push(W);return _},D0=(P,y=",")=>{let f=[],M=P.length,E=y.length,W=0,_=(F)=>{if(F+E>M)return!1;for(let C=0;C<E;C++)if(P[F+C]!==y[C])return!1;return!0};while(W<M){while(W<M&&P[W]===" ")W++;if(W>=M)break;let F="",C=P[W]==='"'||P[W]==="'";if(C){let S=P[W++];while(W<M&&P[W]!==S)F+=P[W++];if(W<M)W++}else{while(W<M&&!_(W)){let S=P[W];if(S==='"'||S==="'"){F+=S,W++;while(W<M&&P[W]!==S)F+=P[W++];if(W<M)F+=P[W++]}else F+=P[W++]}F=F.trim()}if(F)f.push({value:F,quoted:C});if(_(W))W+=E}return f}});var g=f0(i(),1);var Y;((P)=>{P[P.Explore=0]="Explore",P[P.SkipSiblings=1]="SkipSiblings",P[P.NoExplore=2]="NoExplore",P[P.ReplaceParent=3]="ReplaceParent",P[P.DeleteParent=4]="DeleteParent",P[P.MergeParent=5]="MergeParent",P[P.ReplaceItem=6]="ReplaceItem",P[P.DeleteItem=7]="DeleteItem"})(Y||={});class j{action;by;skipSiblings;reexplore;constructor(P,y,f,M){this.action=P,this.by=y,this.skipSiblings=f,this.reexplore=M}static _explore=new j(0);static _noExplore=new j(2);static _skipSiblings=new j(1);static _deleteParent=new j(4);static ReplaceParent(P,y){return new j(3,P,void 0,y)}static SkipSiblings(){return j._skipSiblings}static Explore(){return j._explore}static NoExplore(){return j._noExplore}static DeleteParent(){return j._deleteParent}static MergeParent(P){return new j(5,P)}static ReplaceItem(P,y){return new j(6,P,y)}static DeleteItem(P){return new j(7,void 0,P)}}var q=async(P,y)=>{let f=new WeakSet,M=[],E=[],W=async(F,C,S)=>{let $=F===null,X=$?j.Explore():await y({key:F,value:C,path:M,parent:S,parents:E});if(C&&typeof C==="object"&&X.action===0){if(f.has(C))return X;if(f.add(C),!$)M.push(F),E.push(S);let D=C;while(await _(D,F,S))D=S[F];if(!$)E.pop(),M.pop()}return X},_=async(F,C,S)=>{let $=Object.keys(F),X=$.length;for(let D=0;D<X;D++){let O=$[D],G=F[O],Q=await W(O,G,F),J=Q.action;if(J===0||J===2)continue;if(J===6){if(F[O]=Q.by,Q.skipSiblings)return;continue}if(J===7){if(delete F[O],Q.skipSiblings)return;continue}if(J===1)return;if(J===3){if(C===null)throw Error("Cannot replace root object");if(S[C]=Q.by,Q.reexplore)return!0;return}if(J===4){if(C===null)throw Error("Cannot delete root object");delete S[C];return}if(J===5)delete F[O],Object.assign(F,Q.by)}};await W(null,P,null)};var S0=Object.create,{getPrototypeOf:k0,defineProperty:x,getOwnPropertyNames:O0}=Object,Q0=Object.prototype.hasOwnProperty,j0=(P,y,f)=>{f=P!=null?S0(k0(P)):{};let M=y||!P||!P.__esModule?x(f,"default",{value:P,enumerable:!0}):f;for(let E of O0(P))if(!Q0.call(M,E))x(M,E,{get:()=>P[E],enumerable:!0});return M},$0=(P,y)=>()=>(y||P((y={exports:{}}).exports,y),y.exports),X0=$0((P,y)=>{var{defineProperty:f,getOwnPropertyNames:M,getOwnPropertyDescriptor:E}=Object,W=Object.prototype.hasOwnProperty,_=new WeakMap,F=(D)=>{var O=_.get(D),G;if(O)return O;if(O=f({},"__esModule",{value:!0}),D&&typeof D==="object"||typeof D==="function")M(D).map((Q)=>!W.call(O,Q)&&f(O,Q,{get:()=>D[Q],enumerable:!(G=E(D,Q))||G.enumerable}));return _.set(D,O),O},C=(D,O)=>{for(var G in O)f(D,G,{get:O[G],enumerable:!0,configurable:!0,set:(Q)=>O[G]=()=>Q})},S={};C(S,{splitWithQuotes:()=>X,splitNested:()=>$}),y.exports=F(S);var $=(D,O,G="(",Q=")")=>{let J=0,k="",U=[];for(let Z of D){if(k+=Z,Z===G)J++;if(Z===Q)J--;if(J===0&&Z===O)U.push(k.slice(0,-1)),k=""}if(k)U.push(k);return U},X=(D,O=",")=>{let G=[],Q=D.length,J=O.length,k=0,U=(Z)=>{if(Z+J>Q)return!1;for(let K=0;K<J;K++)if(D[Z+K]!==O[K])return!1;return!0};while(k<Q){while(k<Q&&D[k]===" ")k++;if(k>=Q)break;let Z="",K=D[k]==='"'||D[k]==="'";if(K){let N=D[k++];while(k<Q&&D[k]!==N)Z+=D[k++];if(k<Q)k++}else{while(k<Q&&!U(k)){let N=D[k];if(N==='"'||N==="'"){Z+=N,k++;while(k<Q&&D[k]!==N)Z+=D[k++];if(k<Q)Z+=D[k++]}else Z+=D[k++]}Z=Z.trim()}if(Z)G.push({value:Z,quoted:K});if(U(k))k+=J}return G}}),Z0=j0(X0(),1),J0=/^\[([^=\]]*)([=]*)([^\]]*)\]$/,G0=/^([^[\]]*)\[([^\]]*)]$/,r=(P,y,f,M)=>{if(P.startsWith("{")&&P.endsWith("}")){let E=P.substring(1,P.length-1);return T(y,E,f)?.toString()}return M?P:void 0},K0=(P,y,f,M)=>{let E=r(y,f,M);if(E)return T(P,E,M);let W=J0.exec(y);if(W){let[,F,C,S]=W,$=r(F.trim(),f,M,!0),X=r(S.trim(),f,M,!0);if(Array.isArray(P)&&(C==="="||C==="==")&&$)return P.find((D)=>D?.[$]==X)}let _=G0.exec(y);if(_){let[,F,C]=_;return P?.[F]?.[C]}return P?.[y]},T=(P,y,f)=>{let M=void 0,E=void 0,W=y??"",_=(X)=>{if(!X)return[X,!1];return X.endsWith("?")?[X.substring(0,X.length-1),!0]:[X,!1]},F=(X,D)=>{let[O,G]=_(D.pop());if(!O){if(f?.set!==void 0&&E!==void 0&&M!==void 0)M[E]=f.set;return X}let Q=K0(X,O,P,f);if(Q===void 0){if(G||f?.optional||f?.defaultValue!==void 0)return;throw Error(`Unknown path element: "${O}" in "${W}"`)}return M=X,E=O,F(Q,D)},C=Z0.splitNested(W,f?.separator??".","{","}"),S=void 0;if(C.length>0&&C[C.length-1].startsWith("?="))S=C.pop()?.substring(2);C.reverse();let $=F(P,C);if($===void 0)return S??f?.defaultValue;return $};var e=(P,y)=>{if(typeof P.value==="string"){if(P.quoted)return P.value;if(P.value.startsWith("[")&&P.value.endsWith("]")){let f=P.value.slice(1,-1);if(f.trim()==="")return[];return f.split(";").map((M)=>{let E=M.trim();if(!isNaN(+E))return+E;return E})}if(P.value.startsWith("{")&&P.value.endsWith("}")){if(P.value.slice(1,-1).trim()==="")return{}}if(P.value==="null")return null;if(P.value==="undefined")return;if(P.value.startsWith("@"))return P.value.slice(1);if(!isNaN(+P.value))return+P.value}return y(P.value)},I=(P,y,f,M,E,W)=>{let _=M?.(P)??P,F=E(_);if(F[0])return F[1];if(!y){let C=T(f,P),S=E(C);if(S[0])return S[1]}throw Error(W)},L=(P,y,f,M,E)=>{let W=typeof P.types==="function"?P.types(M,y.value,E):P.types?.[M];if(!W||W==="ref")return e(y,(F)=>T(f,F));let _=e(y,()=>y.value);if(Array.isArray(W)){if(!W.includes(_))throw Error(`Argument ${M.toString()} must be one of [${W.join(", ")}]: ${_}`);return _}if(typeof W==="string"){if(W.endsWith("?")){let F=W.slice(0,-1);if(y.value==="null")return j.ReplaceItem(null);if(y.value==="undefined")return j.ReplaceItem(void 0);if(y.value==="")return"";W=F}switch(W){case"any":return _;case"array":return I(_,y.quoted,f,null,(F)=>[Array.isArray(F),F],`Argument ${M.toString()} must be an array: ${_}`);case"object":return I(_,y.quoted,f,null,(F)=>[typeof F==="object"&&F!==null,F],`Argument ${M.toString()} must be an object: ${_}`);case"number":return I(_,y.quoted,f,(F)=>Number(F),(F)=>[!isNaN(F),F],`Argument ${M.toString()} must be a number: ${_}`);case"boolean":return I(_,y.quoted,f,null,(F)=>{if([!0,"true","1",1,"yes","on"].includes(F))return[!0,!0];if([!1,"false","0",0,"no","off"].includes(F))return[!0,!1];if([null,"null","undefined",void 0,""].includes(F))return[!0,!1];if(Array.isArray(F))return[!0,F.length>0];return[!1,!1]},`Argument ${M.toString()} must be a boolean: ${_}`);case"string":return _.toString();default:throw Error(`Unknown type for argument ${M.toString()}: ${W}`)}}return W(_,f,M,y.quoted)};var b=(P,y)=>{let f=P?.[y];if(f===void 0)throw Error(`Unhandled field processor type: ${y}`);return typeof f==="function"?{options:{},fn:f}:{options:f,fn:f.fn}},n=(P)=>!P.quoted&&P.value.startsWith("."),T0=(P)=>{let y={};for(let f of P){if(!n(f))continue;let M=f.value.indexOf("="),E=M>-1?f.value.slice(1,M):f.value.slice(1),W=M>-1?f.value.slice(M+1):"";if(W.length>=2){let _=W[0],F=W[W.length-1];if(_==='"'&&F==='"'||_==="'"&&F==="'")W=W.slice(1,-1)}if(!y[E])y[E]=[];y[E].push(W)}return y},l=(P,y,f)=>{let M=g.splitWithQuotes(P??""),E=T0(M),W=M.filter((F)=>!n(F)),_=y.options.processArgs===!1?[]:W.map((F,C)=>L(y.options,F,f,C,W));return{rawArgs:W,parsedArgs:_,tags:E}};var U0=(P)=>{return P!==null&&typeof P==="object"&&"action"in P},V=(P,y)=>y.keys!==void 0&&P.key.startsWith(".")&&y.keys[P.key.substring(1)]!==void 0,p=async(P,y,f,M)=>{let{key:E,parent:W}=P,_=b(M.keys,E.substring(1));if(_.options.processArgs!==!1&&(typeof _.options.types==="function"||_.options.types?.[0]!==void 0))P.value=L(_.options,{value:P.value,quoted:!1},f,0,[]);if(typeof P.value!=="string")await H(P.value,{...M,root:{...f,parent:P.parent,parents:P.parents},filters:[...M.filters??[],..._.options.filters??[]]});let F=await _.fn({path:y,root:f,parent:W,key:E,options:M,value:P.value,args:[],rawArgs:[],tags:{}});return U0(F)?F:j.ReplaceParent(F)};var B=(P)=>{let y=[],f=0;while(f<P.length)if(P[f]==="$"&&P[f+1]==="("&&(f===0||P[f-1]!=="\\")){let M=f;f+=2;let E=1;for(;f<P.length;f++)if(P[f]==="(")E++;else if(P[f]===")"){if(E--,E===0){y.push([M,f]);break}}if(E!==0)throw Error(`Unmatched opening $( at position ${M.toString()}`);f++}else f++;return y};var z=Symbol.for("@homedev/fields:OverrideResult"),c=(P)=>({[z]:!0,value:P}),N0=(P)=>{return P!==null&&typeof P==="object"&&z in P&&P[z]===!0},v=async(P,y,f)=>{for(let M=y.length-1;M>=0;M--){let[E,W]=y[M],_=P.slice(E+2,W),F=await v(_,B(_),f);if(typeof F==="object")return F;let C=await f(F,P);if(N0(C))return C.value;P=P.slice(0,E)+C+P.slice(W+1)}return P},t=async(P,y)=>v(P,B(P),y);var Y0=(P)=>{return P!==null&&typeof P==="object"&&"action"in P},I0=async(P,y,f,M)=>{let E=await(async()=>{let W=/([\w\d.-_/]+):(.+)/.exec(P);if(!W)return await T(y,P);let[_,F,C]=W,S=b(M.sources,F),$=l(C,S,y);return await S.fn({args:$.parsedArgs,rawArgs:$.rawArgs,tags:$.tags,key:F,options:M,root:y,path:f,value:null})})();if(E===null||E===void 0)return"";if(typeof E==="object")return c(E);return E},L0=(P)=>{let y=/{%\s*section\s+([\w\d_-]+)\s*%}([\s\S]*?){%\s*endsection\s+\1\s*%}/g,f,M=[],E=[];while((f=y.exec(P))!==null){let[_,F,C]=f;E.push({fullMatch:_,name:F,body:C})}let W=P;for(let{fullMatch:_,name:F,body:C}of E){let S={},$=C.trim(),X=$.indexOf("---");if(X!==-1){let D=$.slice(0,X).trim();$=$.slice(X+3).trim();try{S=Bun.YAML.parse(D)??{}}catch(O){throw Error(`Failed to parse YAML config for section ${F}: ${O.message}`)}}M.push({name:F,config:S,content:$}),W=W.replace(_,"")}return{sections:M,content:W.trim()}},m=async(P,y,f,M)=>{let E=M?.onSection?L0(y):null,W=y;if(E){W=E.content;for(let F of E.sections){if(Object.keys(F.config).length>0)await H(F.config,M);let C=await M.onSection(F,P,f,M);if(C===!0)W=W+F.content;else if(typeof C==="string")W=W+C}}let _=await t(W,(F)=>I0(F,f,P,M));if(Y0(_))return _;if(_===W){if(E?.sections.length)return j.ReplaceItem(_);return j.Explore()}if(typeof _==="string"){let F=await m(P,_,f,M);if(F.action!==Y.Explore)return F}return j.ReplaceItem(_)};var H=async(P,y)=>{return y??={},await q(P,async(f)=>{let M=[...f.path,f.key].join(".");if(y?.filters?.length&&y.filters.some((F)=>F.test(M)))return j.NoExplore();let E=f.path.length===0,W=f.parents.length>0?f.parents.toReversed():[];if(E){if(W.length>0)throw Error("Root object should not have a parent");W=y?.root?.parents?[y.root.parent,...y.root.parents.toReversed()]:[]}let _={...P,...y.root,this:f.parent,parent:W.length>0?W[0]:null,parents:W};try{if(f.key.startsWith("$"))return j.NoExplore();let F=j.Explore();if(typeof f.value==="string")switch(F=await m(M,f.value,_,y),F.action){case Y.Explore:break;case Y.ReplaceItem:f.value=F.by;break;default:return F}if(V(f,y))F=await p(f,M,_,y);return F}catch(F){throw Error(`${F.message}
|
|
2
|
-
|
|
1
|
+
var s=Object.create;var{getPrototypeOf:o,defineProperty:h,getOwnPropertyNames:a}=Object;var P0=Object.prototype.hasOwnProperty;var f0=(P,y,f)=>{f=P!=null?s(o(P)):{};let M=y||!P||!P.__esModule?h(f,"default",{value:P,enumerable:!0}):f;for(let _ of a(P))if(!P0.call(M,_))h(M,_,{get:()=>P[_],enumerable:!0});return M};var y0=(P,y)=>()=>(y||P((y={exports:{}}).exports,y),y.exports);var i=y0((d0,R)=>{var{defineProperty:d,getOwnPropertyNames:F0,getOwnPropertyDescriptor:M0}=Object,W0=Object.prototype.hasOwnProperty,r=new WeakMap,_0=(P)=>{var y=r.get(P),f;if(y)return y;if(y=d({},"__esModule",{value:!0}),P&&typeof P==="object"||typeof P==="function")F0(P).map((M)=>!W0.call(y,M)&&d(y,M,{get:()=>P[M],enumerable:!(f=M0(P,M))||f.enumerable}));return r.set(P,y),y},E0=(P,y)=>{for(var f in y)d(P,f,{get:y[f],enumerable:!0,configurable:!0,set:(M)=>y[f]=()=>M})},w={};E0(w,{splitWithQuotes:()=>C0,splitNested:()=>D0});R.exports=_0(w);var D0=(P,y,f="(",M=")")=>{let _=0,W="",E=[];for(let F of P){if(W+=F,F===f)_++;if(F===M)_--;if(_===0&&F===y)E.push(W.slice(0,-1)),W=""}if(W)E.push(W);return E},C0=(P,y=",")=>{let f=[],M=P.length,_=y.length,W=0,E=(F)=>{if(F+_>M)return!1;for(let D=0;D<_;D++)if(P[F+D]!==y[D])return!1;return!0};while(W<M){while(W<M&&P[W]===" ")W++;if(W>=M)break;let F="",D=P[W]==='"'||P[W]==="'";if(D){let k=P[W++];while(W<M&&P[W]!==k)F+=P[W++];if(W<M)W++}else{while(W<M&&!E(W)){let k=P[W];if(k==='"'||k==="'"){F+=k,W++;while(W<M&&P[W]!==k)F+=P[W++];if(W<M)F+=P[W++]}else F+=P[W++]}F=F.trim()}if(F)f.push({value:F,quoted:D});if(E(W))W+=_}return f}});var g=f0(i(),1);var T;((P)=>{P[P.Explore=0]="Explore",P[P.SkipSiblings=1]="SkipSiblings",P[P.NoExplore=2]="NoExplore",P[P.ReplaceParent=3]="ReplaceParent",P[P.DeleteParent=4]="DeleteParent",P[P.MergeParent=5]="MergeParent",P[P.ReplaceItem=6]="ReplaceItem",P[P.DeleteItem=7]="DeleteItem"})(T||={});class ${action;by;skipSiblings;reexplore;constructor(P,y,f,M){this.action=P,this.by=y,this.skipSiblings=f,this.reexplore=M}static _explore=new $(0);static _noExplore=new $(2);static _skipSiblings=new $(1);static _deleteParent=new $(4);static ReplaceParent(P,y){return new $(3,P,void 0,y)}static SkipSiblings(){return $._skipSiblings}static Explore(){return $._explore}static NoExplore(){return $._noExplore}static DeleteParent(){return $._deleteParent}static MergeParent(P){return new $(5,P)}static ReplaceItem(P,y){return new $(6,P,y)}static DeleteItem(P){return new $(7,void 0,P)}}var q=async(P,y)=>{let f=new WeakSet,M=[],_=[],W=async(F,D,k)=>{let X=F===null,O=X?$.Explore():await y({key:F,value:D,path:M,parent:k,parents:_});if(D&&typeof D==="object"&&O.action===0){if(f.has(D))return O;if(f.add(D),!X)M.push(F),_.push(k);let C=D;while(await E(C,F,k))C=k[F];if(!X)_.pop(),M.pop()}return O},E=async(F,D,k)=>{let X=Object.keys(F),O=X.length;for(let C=0;C<O;C++){let Q=X[C],Z=F[Q],S=await W(Q,Z,F),G=S.action;if(G===0||G===2)continue;if(G===6){if(F[Q]=S.by,S.skipSiblings)return;continue}if(G===7){if(delete F[Q],S.skipSiblings)return;continue}if(G===1)return;if(G===3){if(D===null)throw Error("Cannot replace root object");if(k[D]=S.by,S.reexplore)return!0;return}if(G===4){if(D===null)throw Error("Cannot delete root object");delete k[D];return}if(G===5)delete F[Q],Object.assign(F,S.by)}};await W(null,P,null)};var k0=Object.create,{getPrototypeOf:Q0,defineProperty:x,getOwnPropertyNames:S0}=Object,j0=Object.prototype.hasOwnProperty,O0=(P,y,f)=>{f=P!=null?k0(Q0(P)):{};let M=y||!P||!P.__esModule?x(f,"default",{value:P,enumerable:!0}):f;for(let _ of S0(P))if(!j0.call(M,_))x(M,_,{get:()=>P[_],enumerable:!0});return M},$0=(P,y)=>()=>(y||P((y={exports:{}}).exports,y),y.exports),X0=$0((P,y)=>{var{defineProperty:f,getOwnPropertyNames:M,getOwnPropertyDescriptor:_}=Object,W=Object.prototype.hasOwnProperty,E=new WeakMap,F=(C)=>{var Q=E.get(C),Z;if(Q)return Q;if(Q=f({},"__esModule",{value:!0}),C&&typeof C==="object"||typeof C==="function")M(C).map((S)=>!W.call(Q,S)&&f(Q,S,{get:()=>C[S],enumerable:!(Z=_(C,S))||Z.enumerable}));return E.set(C,Q),Q},D=(C,Q)=>{for(var Z in Q)f(C,Z,{get:Q[Z],enumerable:!0,configurable:!0,set:(S)=>Q[Z]=()=>S})},k={};D(k,{splitWithQuotes:()=>O,splitNested:()=>X}),y.exports=F(k);var X=(C,Q,Z="(",S=")")=>{let G=0,j="",Y=[];for(let J of C){if(j+=J,J===Z)G++;if(J===S)G--;if(G===0&&J===Q)Y.push(j.slice(0,-1)),j=""}if(j)Y.push(j);return Y},O=(C,Q=",")=>{let Z=[],S=C.length,G=Q.length,j=0,Y=(J)=>{if(J+G>S)return!1;for(let K=0;K<G;K++)if(C[J+K]!==Q[K])return!1;return!0};while(j<S){while(j<S&&C[j]===" ")j++;if(j>=S)break;let J="",K=C[j]==='"'||C[j]==="'";if(K){let N=C[j++];while(j<S&&C[j]!==N)J+=C[j++];if(j<S)j++}else{while(j<S&&!Y(j)){let N=C[j];if(N==='"'||N==="'"){J+=N,j++;while(j<S&&C[j]!==N)J+=C[j++];if(j<S)J+=C[j++]}else J+=C[j++]}J=J.trim()}if(J)Z.push({value:J,quoted:K});if(Y(j))j+=G}return Z}}),Z0=O0(X0(),1),J0=/^\[([^=\]]*)([=]*)([^\]]*)\]$/,G0=/^([^[\]]*)\[([^\]]*)]$/,B=(P,y,f,M)=>{if(P.startsWith("{")&&P.endsWith("}")){let _=P.substring(1,P.length-1);return U(y,_,f)?.toString()}return M?P:void 0},K0=(P,y,f,M)=>{let _=B(y,f,M);if(_)return U(P,_,M);let W=J0.exec(y);if(W){let[,F,D,k]=W,X=B(F.trim(),f,M,!0),O=B(k.trim(),f,M,!0);if(Array.isArray(P)&&(D==="="||D==="==")&&X)return P.find((C)=>C?.[X]==O)}let E=G0.exec(y);if(E){let[,F,D]=E;return P?.[F]?.[D]}return P?.[y]},U=(P,y,f)=>{let M=void 0,_=void 0,W=y??"",E=(O)=>{if(!O)return[O,!1];return O.endsWith("?")?[O.substring(0,O.length-1),!0]:[O,!1]},F=(O,C)=>{let[Q,Z]=E(C.pop());if(!Q){if(f?.set!==void 0&&_!==void 0&&M!==void 0)M[_]=f.set;return O}let S=K0(O,Q,P,f);if(S===void 0){if(Z||f?.optional||f?.defaultValue!==void 0)return;throw Error(`Unknown path element: "${Q}" in "${W}"`)}return M=O,_=Q,F(S,C)},D=Z0.splitNested(W,f?.separator??".","{","}"),k=void 0;if(D.length>0&&D[D.length-1].startsWith("?="))k=D.pop()?.substring(2);D.reverse();let X=F(P,D);if(X===void 0)return k??f?.defaultValue;return X};var e=(P,y)=>{if(typeof P.value==="string"){if(P.quoted)return P.value;if(P.value.startsWith("[")&&P.value.endsWith("]")){let f=P.value.slice(1,-1);if(f.trim()==="")return[];return f.split(";").map((M)=>{let _=M.trim();if(!isNaN(+_))return+_;return _})}if(P.value.startsWith("{")&&P.value.endsWith("}")){if(P.value.slice(1,-1).trim()==="")return{}}if(P.value==="null")return null;if(P.value==="undefined")return;if(P.value.startsWith("@"))return P.value.slice(1);if(!isNaN(+P.value))return+P.value}return y(P.value)},L=(P,y,f,M,_,W)=>{let E=M?.(P)??P,F=_(E);if(F[0])return F[1];if(!y){let D=U(f,P),k=_(D);if(k[0])return k[1]}throw Error(W)},b=(P,y,f,M,_)=>{let W=typeof P.types==="function"?P.types(M,y.value,_):P.types?.[M];if(!W||W==="ref")return e(y,(F)=>U(f,F));let E=e(y,()=>y.value);if(Array.isArray(W)){if(!W.includes(E))throw Error(`Argument ${M.toString()} must be one of [${W.join(", ")}]: ${E}`);return E}if(typeof W==="string"){if(W.endsWith("?")){let F=W.slice(0,-1);if(y.value==="null")return $.ReplaceItem(null);if(y.value==="undefined")return $.ReplaceItem(void 0);if(y.value==="")return"";W=F}switch(W){case"any":return E;case"array":return L(E,y.quoted,f,null,(F)=>[Array.isArray(F),F],`Argument ${M.toString()} must be an array: ${E}`);case"object":return L(E,y.quoted,f,null,(F)=>[typeof F==="object"&&F!==null,F],`Argument ${M.toString()} must be an object: ${E}`);case"number":return L(E,y.quoted,f,(F)=>Number(F),(F)=>[!isNaN(F),F],`Argument ${M.toString()} must be a number: ${E}`);case"boolean":return L(E,y.quoted,f,null,(F)=>{if([!0,"true","1",1,"yes","on"].includes(F))return[!0,!0];if([!1,"false","0",0,"no","off"].includes(F))return[!0,!1];if([null,"null","undefined",void 0,""].includes(F))return[!0,!1];if(Array.isArray(F))return[!0,F.length>0];return[!1,!1]},`Argument ${M.toString()} must be a boolean: ${E}`);case"string":return E.toString();default:throw Error(`Unknown type for argument ${M.toString()}: ${W}`)}}return W(E,f,M,y.quoted)};var H=(P,y)=>{let f=P?.[y];if(f===void 0)throw Error(`Unhandled field processor type: ${y}`);return typeof f==="function"?{options:{},fn:f}:{options:f,fn:f.fn}},l=(P)=>!P.quoted&&P.value.startsWith("."),U0=(P)=>{let y={};for(let f of P){if(!l(f))continue;let M=f.value.indexOf("="),_=M>-1?f.value.slice(1,M):f.value.slice(1),W=M>-1?f.value.slice(M+1):"";if(W.length>=2){let E=W[0],F=W[W.length-1];if(E==='"'&&F==='"'||E==="'"&&F==="'")W=W.slice(1,-1)}if(!y[_])y[_]=[];y[_].push(W)}return y},V=(P,y,f)=>{let M=g.splitWithQuotes(P??""),_=U0(M),W=M.filter((F)=>!l(F)),E=y.options.processArgs===!1?[]:W.map((F,D)=>b(y.options,F,f,D,W));return{rawArgs:W,parsedArgs:E,tags:_}};var Y0=(P)=>{return P!==null&&typeof P==="object"&&"action"in P},n=(P,y)=>y.keys!==void 0&&P.key.startsWith(".")&&y.keys[P.key.substring(1)]!==void 0,c=async(P,y,f,M)=>{let{key:_,parent:W}=P,E=H(M.keys,_.substring(1));if(E.options.processArgs!==!1&&(typeof E.options.types==="function"||E.options.types?.[0]!==void 0))P.value=b(E.options,{value:P.value,quoted:!1},f,0,[]);if(typeof P.value!=="string")await I(P.value,{...M,root:{...f,parent:P.parent,parents:P.parents},filters:[...M.filters??[],...E.options.filters??[]]});let F=await E.fn({path:y,root:f,parent:W,key:_,options:M,value:P.value,args:[],rawArgs:[],tags:{}});return Y0(F)?F:$.ReplaceParent(F)};var z=(P)=>{let y=[],f=0;while(f<P.length)if(P[f]==="$"&&P[f+1]==="("&&(f===0||P[f-1]!=="\\")){let M=f;f+=2;let _=1;for(;f<P.length;f++)if(P[f]==="(")_++;else if(P[f]===")"){if(_--,_===0){y.push([M,f]);break}}if(_!==0)throw Error(`Unmatched opening $( at position ${M.toString()}`);f++}else f++;return y};var A=Symbol.for("@homedev/fields:OverrideResult"),p=(P)=>({[A]:!0,value:P}),N0=(P)=>{return P!==null&&typeof P==="object"&&A in P&&P[A]===!0},v=async(P,y,f)=>{for(let M=y.length-1;M>=0;M--){let[_,W]=y[M],E=P.slice(_+2,W),F=await v(E,z(E),f);if(typeof F==="object")return F;let D=await f(F,P);if(N0(D))return D.value;P=P.slice(0,_)+D+P.slice(W+1)}return P},u=async(P,y)=>v(P,z(P),y);var T0=(P)=>{return P!==null&&typeof P==="object"&&"action"in P},L0=/([\w\d.-_/]+):(.+)/,b0=async(P,y,f,M)=>{let _=await(async()=>{let W=L0.exec(P);if(!W)return await U(y,P);let[E,F,D]=W,k=H(M.sources,F),X=V(D,k,y);return await k.fn({args:X.parsedArgs,rawArgs:X.rawArgs,tags:X.tags,key:F,options:M,root:y,path:f,value:null})})();if(_===null||_===void 0)return"";if(typeof _==="object")return p(_);return _},H0=(P)=>{let y=/{%\s*section\s+([\w\d_-]+)\s*%}([\s\S]*?){%\s*endsection\s+\1\s*%}/g,f,M=[],_=[];while((f=y.exec(P))!==null){let[F,D,k]=f,X=f.index,O=X+F.length;if(P[O]===`
|
|
2
|
+
`)O++;_.push({start:X,end:O,name:D,body:k})}let W=[],E=0;for(let{start:F,end:D,name:k,body:X}of _){if(F>E)W.push(P.slice(E,F));E=D;let O={},C=X.trim(),Q=C.indexOf("---");if(Q!==-1){let Z=C.slice(0,Q).trim();C=C.slice(Q+3).trim();try{O=Bun.YAML.parse(Z)??{}}catch(S){throw Error(`Failed to parse YAML config for section ${k}: ${S.message}`)}}M.push({name:k,config:O,content:C})}if(E<P.length)W.push(P.slice(E));return{sections:M,content:W.join("")}},m=async(P,y,f,M)=>{let _=M?.onSection?H0(y):null,W=y;if(_){W=_.content;for(let F of _.sections){if(Object.keys(F.config).length>0)await I(F.config,M);let D=await M.onSection(F,P,f,M);if(D===!0)W=W+F.content;else if(typeof D==="string")W=W+D}}let E=await u(W,(F)=>b0(F,f,P,M));if(T0(E))return E;if(E===W){if(_?.sections.length)return $.ReplaceItem(E);return $.Explore()}if(typeof E==="string"){let F=await m(P,E,f,M);if(F.action!==T.Explore)return F}return $.ReplaceItem(E)};var I=async(P,y)=>{return y??={},await q(P,async(f)=>{let M=[...f.path,f.key].join(".");if(y?.filters?.length&&y.filters.some((F)=>F.test(M)))return $.NoExplore();let _=f.path.length===0,W=f.parents.length>0?f.parents.toReversed():[];if(_){if(W.length>0)throw Error("Root object should not have a parent");W=y?.root?.parents?[y.root.parent,...y.root.parents.toReversed()]:[]}let E={...P,...y.root,this:f.parent,parent:W.length>0?W[0]:null,parents:W};try{if(f.key.startsWith("$"))return $.NoExplore();let F=$.Explore();if(typeof f.value==="string")switch(F=await m(M,f.value,E,y),F.action){case T.Explore:break;case T.ReplaceItem:f.value=F.by;break;default:return F}if(n(f,y))F=await c(f,M,E,y);return F}catch(F){throw Error(`${F.message}
|
|
3
|
+
(${M})`)}}),P};var t=(P,y)=>y?{fn:(f)=>P(...f.args),types:y}:(f)=>P(...f.args),DP=(P,y)=>Object.fromEntries(P.map((f)=>[f.name,t(f,y?.types?.[f.name])])),CP=(P,y)=>Object.fromEntries((y?.keys??Object.keys(P)).map((f)=>[f,t(P[f],y?.types?.[f])]));export{I as processFields,CP as makeFieldProcessorMap,DP as makeFieldProcessorList,t as makeFieldProcessor,H as getProcessor,V as getArgs};
|