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