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