@homedev/fields 1.2.20 → 1.2.22
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 +15 -1
- 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;
|
|
@@ -69,7 +72,18 @@ export declare interface ProcessFieldsOptions {
|
|
|
69
72
|
filters?: RegExp[];
|
|
70
73
|
root?: Record<any, any>;
|
|
71
74
|
globalContext?: any;
|
|
72
|
-
onSection?: (section: FieldProcessorSection,
|
|
75
|
+
onSection?: (section: FieldProcessorSection, context: {
|
|
76
|
+
content: string;
|
|
77
|
+
path: string;
|
|
78
|
+
root: Record<string, any>;
|
|
79
|
+
options: ProcessFieldsOptions;
|
|
80
|
+
}) => Promise<void | boolean | string> | void | boolean | string;
|
|
81
|
+
onSectionConfig?: (section: FieldProcessorSection, context: {
|
|
82
|
+
content: string;
|
|
83
|
+
path: string;
|
|
84
|
+
root: Record<string, any>;
|
|
85
|
+
options: ProcessFieldsOptions;
|
|
86
|
+
}) => Promise<boolean | void> | boolean | void;
|
|
73
87
|
}
|
|
74
88
|
|
|
75
89
|
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:R,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?R(f,"default",{value:P,enumerable:!0}):f;for(let M of P0(P))if(!f0.call(W,M))R(W,M,{get:()=>P[M],enumerable:!0});return W};var y0=(P,F)=>()=>(F||P((F={exports:{}}).exports,F),F.exports);var x=y0((z0,h)=>{var{defineProperty:z,getOwnPropertyNames:W0,getOwnPropertyDescriptor:_0}=Object,E0=Object.prototype.hasOwnProperty,q=new WeakMap,M0=(P)=>{var F=q.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 q.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:()=>Q0,splitNested:()=>C0});h.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},Q0=(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 Q=P[_++];while(_<W&&P[_]!==Q)y+=P[_++];if(_<W)_++}else{while(_<W&&!E(_)){let Q=P[_];if(Q==='"'||Q==="'"){y+=Q,_++;while(_<W&&P[_]!==Q)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 i=F0(x(),1);var U;((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"})(U||={});class Z{action;by;skipSiblings;reexplore;constructor(P,F,f,W){this.action=P,this.by=F,this.skipSiblings=f,this.reexplore=W}static _explore=new Z(0);static _noExplore=new Z(2);static _skipSiblings=new Z(1);static _deleteParent=new Z(4);static ReplaceParent(P,F){return new Z(3,P,void 0,F)}static SkipSiblings(){return Z._skipSiblings}static Explore(){return Z._explore}static NoExplore(){return Z._noExplore}static DeleteParent(){return Z._deleteParent}static MergeParent(P){return new Z(5,P)}static ReplaceItem(P,F){return new Z(6,P,F)}static DeleteItem(P){return new Z(7,void 0,P)}}var g=async(P,F)=>{let f=new WeakSet,W=[],M=[],_=async(y,D,Q)=>{let $=y===null,X=$?Z.Explore():await F({key:y,value:D,path:W,parent:Q,parents:M});if(D&&typeof D==="object"&&X.action===0){if(f.has(D))return X;if(f.add(D),!$)W.push(y),M.push(Q);let C=D;while(await E(C,y,Q))C=Q[y];if(!$)M.pop(),W.pop()}return X},E=async(y,D,Q)=>{let $=Object.keys(y),X=$.length;for(let C=0;C<X;C++){let k=$[C],J=y[k],O=await _(k,J,y),G=O.action;if(G===0||G===2)continue;if(G===6){if(y[k]=O.by,O.skipSiblings)return;continue}if(G===7){if(delete y[k],O.skipSiblings)return;continue}if(G===1)return;if(G===3){if(D===null)throw Error("Cannot replace root object");if(Q[D]=O.by,O.reexplore)return!0;return}if(G===4){if(D===null)throw Error("Cannot delete root object");delete Q[D];return}if(G===5)delete y[k],Object.assign(y,O.by)}};await _(null,P,null)};var j0=Object.create,{getPrototypeOf:k0,defineProperty:r,getOwnPropertyNames:O0}=Object,$0=Object.prototype.hasOwnProperty,X0=(P,F,f)=>{f=P!=null?j0(k0(P)):{};let W=F||!P||!P.__esModule?r(f,"default",{value:P,enumerable:!0}):f;for(let M of O0(P))if(!$0.call(W,M))r(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 k=E.get(C),J;if(k)return k;if(k=f({},"__esModule",{value:!0}),C&&typeof C==="object"||typeof C==="function")W(C).map((O)=>!_.call(k,O)&&f(k,O,{get:()=>C[O],enumerable:!(J=M(C,O))||J.enumerable}));return E.set(C,k),k},D=(C,k)=>{for(var J in k)f(C,J,{get:k[J],enumerable:!0,configurable:!0,set:(O)=>k[J]=()=>O})},Q={};D(Q,{splitWithQuotes:()=>X,splitNested:()=>$}),F.exports=y(Q);var $=(C,k,J="(",O=")")=>{let G=0,j="",S=[];for(let K of C){if(j+=K,K===J)G++;if(K===O)G--;if(G===0&&K===k)S.push(j.slice(0,-1)),j=""}if(j)S.push(j);return S},X=(C,k=",")=>{let J=[],O=C.length,G=k.length,j=0,S=(K)=>{if(K+G>O)return!1;for(let Y=0;Y<G;Y++)if(C[K+Y]!==k[Y])return!1;return!0};while(j<O){while(j<O&&C[j]===" ")j++;if(j>=O)break;let K="",Y=C[j]==='"'||C[j]==="'";if(Y){let T=C[j++];while(j<O&&C[j]!==T)K+=C[j++];if(j<O)j++}else{while(j<O&&!S(j)){let T=C[j];if(T==='"'||T==="'"){K+=T,j++;while(j<O&&C[j]!==T)K+=C[j++];if(j<O)K+=C[j++]}else K+=C[j++]}K=K.trim()}if(K)J.push({value:K,quoted:Y});if(S(j))j+=G}return J}}),G0=X0(J0(),1),K0=/^\[([^=\]]*)([=]*)([^\]]*)\]$/,S0=/^([^[\]]*)\[([^\]]*)]$/,A=(P,F,f,W)=>{if(P.startsWith("{")&&P.endsWith("}")){let M=P.substring(1,P.length-1);return L(F,M,f)?.toString()}return W?P:void 0},U0=(P,F,f,W)=>{let M=A(F,f,W);if(M)return L(P,M,W);let _=K0.exec(F);if(_){let[,y,D,Q]=_,$=A(y.trim(),f,W,!0),X=A(Q.trim(),f,W,!0);if(Array.isArray(P)&&(D==="="||D==="==")&&$)return P.find((C)=>C?.[$]==X)}let E=S0.exec(F);if(E){let[,y,D]=E;return P?.[y]?.[D]}return P?.[F]},L=(P,F,f)=>{let W=void 0,M=void 0,_=F??"",E=(X)=>{if(!X)return[X,!1];return X.endsWith("?")?[X.substring(0,X.length-1),!0]:[X,!1]},y=(X,C)=>{let[k,J]=E(C.pop());if(!k){if(f?.set!==void 0&&M!==void 0&&W!==void 0)W[M]=f.set;return X}let O=U0(X,k,P,f);if(O===void 0){if(J||f?.optional||f?.defaultValue!==void 0)return;throw Error(`Unknown path element: "${k}" in "${_}"`)}return W=X,M=k,y(O,C)},D=G0.splitNested(_,f?.separator??".","{","}"),Q=void 0;if(D.length>0&&D[D.length-1].startsWith("?="))Q=D.pop()?.substring(2);D.reverse();let $=y(P,D);if($===void 0)return Q??f?.defaultValue;return $};var V=(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=L(f,P),Q=M(D);if(Q[0])return Q[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 V(F,(y)=>L(f,y));let E=V(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 Z.ReplaceItem(null);if(F.value==="undefined")return Z.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}},l=(P)=>!P.quoted&&P.value.startsWith("."),Y0=(P)=>{let F={};for(let f of P){if(!l(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=i.splitWithQuotes(P??""),M=Y0(W),_=W.filter((y)=>!l(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},n=(P,F)=>F.keys!==void 0&&P.key.startsWith(".")&&F.keys[P.key.substring(1)]!==void 0,p=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:Z.ReplaceParent(y)};var d=(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},u=async(P,F,f)=>{for(let W=F.length-1;W>=0;W--){let[M,_]=F[W],E=P.slice(M+2,_),y=await u(E,d(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},c=async(P,F)=>u(P,d(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,Q]=f,$=f.index,X=$+y.length;if(P[X]===`
|
|
2
|
+
`)X++;M.push({start:$,end:X,name:D,body:Q})}let _=[],E=0;for(let{start:y,end:D,name:Q,body:$}of M){if(y>E)_.push(P.slice(E,y));E=D;let X={},C=$,k=/(^|\r?\n)[ \t]*---[ \t]*(\r?\n|$)/m.exec($);if(k){let O=$.slice(0,k.index),G=k.index+k[0].length;C=$.slice(G);let j=O.trim();if(j.length>0)try{X=Bun.YAML.parse(j)??{}}catch(S){throw Error(`Failed to parse YAML config for section ${Q}: ${S.message}`)}}else if(/^\r?\n/.test(C))C=C.replace(/^\r?\n/,"");if(/[ \t]*\r?\n$/.test(C))C=C.replace(/[\t]*\r?\n$/,"");let J=`__FIELD_SECTION_${W.length.toString()}__`;W.push({name:Q,config:X,content:C,placeholder:J}),_.push(J)}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 _={content:M.content,root:W,path:f,options:F};for(let E of M.sections){let y=await I(f,E.name,W,F);if(y.action===U.ReplaceItem)E.name=y.by;if(Object.keys(E.config).length>0){if(await F.onSectionConfig?.(E,_)!==!1)await B(E.config,F)}let D=await F.onSection(E,_);if(E.trim)E.content=E.content.trim();if(E.indent)E.content=E.content.split(`
|
|
3
|
+
`).map(($)=>" ".repeat(E.indent)+$).join(`
|
|
4
|
+
`);let Q="";if(D===!0||E.show)Q=E.content;else if(typeof D==="string")Q=D;_.content=_.content.replace(E.placeholder,Q)}return[_.content,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 L(F,P);let[E,y,D]=_,Q=b(W.sources,y),$=e(D,Q,F);return await Q.fn({args:$.parsedArgs,rawArgs:$.rawArgs,tags:$.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 c(M,(y)=>b0(y,f,P,W));if(N0(E))return E;if(E===M){if(_?.sections.length)return Z.ReplaceItem(E);return Z.Explore()}if(typeof E==="string"){let y=await I(P,E,f,W);if(y.action!==U.Explore)return y}return Z.ReplaceItem(E)};var B=async(P,F)=>{return F??={},await g(P,async(f)=>{let W=[...f.path,f.key].join(".");if(F?.filters?.length&&F.filters.some((y)=>y.test(W)))return Z.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 Z.NoExplore();let y=Z.Explore();if(typeof f.value==="string")switch(y=await I(W,f.value,E,F),y.action){case U.Explore:break;case U.ReplaceItem:f.value=y.by;break;default:return y}if(n(f,F))y=await p(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),kP=(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,kP as makeFieldProcessorList,s as makeFieldProcessor,b as getProcessor,e as getArgs};
|