@baseplate-dev/project-builder-web
Version:
Web interface for constructing project builder JSON
6 lines (5 loc) • 16.5 kB
JavaScript
import{s as L}from"../sortBy-C9bvycg5.js";import{i as P}from"../isEqual-C420KeG-.js";import{i as _}from"../_virtual___federation_fn_import-o6aKHb82.js";function v(t){return typeof t=="object"&&t!==null}function C(t,e,n){const r=Object.keys(e);for(let s=0;s<r.length;s++){const o=r[s],i=e[o],c=t[o],a=n(c,i,o,t,e);a!=null?t[o]=a:Array.isArray(i)?t[o]=C(c??[],i,n):v(c)&&v(i)?t[o]=C(c??{},i,n):(c===void 0||i!==void 0)&&(t[o]=i)}return t}function F(t){return typeof t=="string"?new TextEncoder().encode(t):t}async function xe(t){const e=F(t),n=await crypto.subtle.digest("SHA-256",e);return[...new Uint8Array(n)].map(s=>s.toString(16).padStart(2,"0")).join("")}function ke(t,e){const n=new Error(`${e}: ${t instanceof Error?t.message:String(t)}`,{cause:t});return t instanceof Error&&(n.stack=t.stack),n}class Z{listenerMap=new Map;eventEmitterAbortController=new AbortController;on(e,n,r){const{signal:s}=r??{},o=this.listenerMap.get(e)??[];this.listenerMap.set(e,[...o,n]);const i=()=>{const c=(this.listenerMap.get(e)??[]).filter(a=>a!==n);c.length>0?this.listenerMap.set(e,c):this.listenerMap.delete(e)};return s?.addEventListener("abort",i,{once:!0}),i}async*onAsync(e,n){const r=[];let s,o=!1;const i=this.eventEmitterAbortController.signal;if(n.signal?.aborted||i.aborted)return;function c(){o=!0,s?.(void 0)}for(n.signal?.addEventListener("abort",c,{once:!0}),i.addEventListener("abort",c,{once:!0}),this.on(e,a=>{s?(s(a),s=void 0):r.push(a)},{signal:n.signal});!o;){const a=r.shift()??await new Promise(u=>{s=u});if(o)break;yield a}}emit(e,n){const r=this.listenerMap.get(e)??[];for(const s of r)s(n)}clearListeners(){this.listenerMap.clear(),this.eventEmitterAbortController.abort()}abortEventEmitter(){this.eventEmitterAbortController.abort()}}function $e(){return new Z}class M{_value;defaultValue;isSet=!1;setBySource;getDynamicSource;constructor(e,n){this.defaultValue=e,this.getDynamicSource=n?.getDynamicSource}getValue(){return this._value===void 0?this.defaultValue:this._value}set(e,n){if(this.isSet)throw new Error(`Value has already been set by ${this.setBySource} and cannot be overwritten by ${n}`);this._value=e,this.isSet=!0,this.setBySource=n??this.getDynamicSource?.()??"unknown"}}class K{_stripDuplicates;_value;constructor(e,n){this._stripDuplicates=n?.stripDuplicates??!1,this._value=e??[]}push(...e){let n=this._value;this._stripDuplicates?n=[...new Set([...n,...e])]:n=[...n,...e],this._value=n}getValue(){return this._value}}class U{map;getDynamicSource;constructor(e,n){this.getDynamicSource=n?.getDynamicSource,this.map=new Map(Object.entries(e).map(([r,s])=>[r,{value:s,setBySource:this.getDynamicSource?.()}]))}set(e,n,r){const s=this.map.get(e);if(s?.setBySource)throw new Error(`Value for key ${e} has already been set by ${s.setBySource} and cannot be overwritten by ${r}`);this.map.set(e,{value:n,setBySource:r??this.getDynamicSource?.()})}merge(e,n){const r=n??this.getDynamicSource?.();for(const[s,o]of Object.entries(e))this.set(s,o,r)}getValue(){return Object.fromEntries([...this.map.entries()].map(([e,n])=>[e,n.value]))}}class B{_value;getDynamicSource;constructor(e,n){this.getDynamicSource=n?.getDynamicSource;const r=e??new Map;this._value=new Map([...r.entries()].map(([s,o])=>[s,{value:o,setBySource:this.getDynamicSource?.()}]))}set(e,n,r){const s=this._value.get(e);if(s?.setBySource)throw new Error(`Value for key ${e} has already been set by ${s.setBySource} and cannot be overwritten by ${r}`);this._value.set(e,{value:n,setBySource:r??this.getDynamicSource?.()})}merge(e,n){const r=n??this.getDynamicSource?.();for(const[s,o]of e.entries())this.set(s,o,r)}mergeObj(e,n){const r=n??this.getDynamicSource?.();for(const[s,o]of Object.entries(e))this.set(s,o,r)}getValue(){return new Map([...this._value.entries()].map(([e,n])=>[e,n.value]))}}class W{_value;getDynamicSource;constructor(e,n){this.getDynamicSource=n?.getDynamicSource;const r=e??[];this._value=new Map(r.map(s=>[s.name,{value:s,setBySource:this.getDynamicSource?.()}]))}add(e,n){const r=this._value.get(e.name);if(r?.setBySource)throw new Error(`Value for name ${e.name} has already been set by ${r.setBySource} and cannot be overwritten by ${n}`);this._value.set(e.name,{value:e,setBySource:n??this.getDynamicSource?.()})}addMany(e,n){for(const r of e)this.add(r,n)}getValue(){return L([...this._value.values()].map(e=>e.value),[e=>e.name])}}class V{_value;getDynamicSource;constructor(e,n){this.getDynamicSource=n?.getDynamicSource;const r=e??new Map;this._value=new Map([...r.entries()].map(([s,o])=>[s,{value:new Map([...o.entries()].map(([i,c])=>[i,{value:c,setBySource:this.getDynamicSource?.()}])),setBySource:this.getDynamicSource?.()}]))}set(e,n,r,s){const o=this._value.get(e),i=s??this.getDynamicSource?.()??"unknown";if(!o){const a=new Map;a.set(n,{value:r,setBySource:i}),this._value.set(e,{value:a,setBySource:i});return}const c=o.value.get(n);if(c?.setBySource)throw new Error(`Value for keys ${e}+${n} has already been set by ${c.setBySource} and cannot be overwritten by ${i}`);o.value.set(n,{value:r,setBySource:i})}merge(e,n,r){const s=r??this.getDynamicSource?.()??"unknown";for(const[o,i]of n.entries())this.set(e,o,i,s)}mergeObj(e,n,r){const s=r??this.getDynamicSource?.()??"unknown";for(const[o,i]of Object.entries(n))this.set(e,o,i,s)}getValue(){return new Map([...this._value.entries()].map(([e,n])=>[e,new Map([...n.value.entries()].map(([r,s])=>[r,s.value]))]))}}class J{options;constructor(e){this.options=e}scalar(e){return new M(e,this.options)}string(e){return new M(e,this.options)}number(e){return new M(e,this.options)}boolean(e){return new M(e,this.options)}array(e,n){return new K(e,n)}object(e){return new U(e,this.options)}map(e){return new B(e??new Map,this.options)}mapFromObj(e){return new B(new Map(Object.entries(e??{})),this.options)}namedArray(e){return new W(e,this.options)}mapOfMaps(e){return new V(e??new Map,this.options)}mapOfMapsFromObj(e){const n=new Map;if(e)for(const[r,s]of Object.entries(e))n.set(r,new Map(Object.entries(s)));return new V(n,this.options)}}function ve(t){return t}function Be(t,e){const n=t(new J(e));return{...n,getValues:()=>{const r={};for(const s of Object.keys(n)){const o=n[s];r[s]=o.getValue()}return r}}}function I(t){if(t==null||typeof t=="boolean"||typeof t=="string"||typeof t=="number")return t;if(typeof t=="object"){if(t instanceof Date||t instanceof RegExp)throw new TypeError(`Cannot clone value of unsupported type: ${t.constructor.name}`);if(Array.isArray(t)){const n=[];for(const[r,s]of t.entries())n[r]=I(s);return n}const e={};for(const n in t)if(Object.prototype.hasOwnProperty.call(t,n)){const r=t[n];e[n]=I(r)}return e}throw new Error(`Cannot clone value of unsupported type: ${typeof t}`)}function A(t){return typeof t=="object"&&t!==null}function q(t,e){if(Array.isArray(t))t.forEach(e);else if(A(t))for(const n of Object.keys(t)){const r=t[n];e(r,n)}}function T(t){let e=0;return Array.isArray(t)||A(t)?(q(t,n=>{if(Array.isArray(n)||A(n)){const r=T(n);r>e&&(e=r)}}),e+1):e}function d(t,e,n){return e in t?t[e]:n}const G=/("(?:[^\\"]|\\.)*")|[:,]|\{(?!})|(?<!\{)}|\[(?!])|(?<!\[)]/g;function X(t,e={}){const n={"{":"{","}":"}","[":"[","]":"]",",":", ",":":": "};return(e.addMargin||e.addObjectMargin)&&(n["{"]="{ ",n["}"]=" }"),(e.addMargin||e.addArrayMargin)&&(n["["]="[ ",n["]"]=" ]"),t.replaceAll(G,(r,s)=>s?r:n[r])}function H(t,e={}){const n=JSON.stringify([1],null,d(e,"indent",2)).slice(2,-3),r=d(e,"margins",!1),s=d(e,"arrayMargins",!1),o=d(e,"objectMargins",!0),i=n===""?1/0:d(e,"maxLength",80),c=d(e,"maxNesting",1/0);return function a(u,f,l){u&&typeof u=="object"&&typeof u.toJSON=="function"&&(u=u.toJSON());const h=JSON.stringify(u);if(h===void 0)return h;const g=i-f.length-l;if(T(u)<=c&&h.length<=g){const y=X(h,{addMargin:r,addArrayMargin:s,addObjectMargin:o});if(y.length<=g)return y}if(A(u)){const y=f+n,w=[];let S;const x=(p,b)=>b===p.length-1?0:1;if(Array.isArray(u)){for(let p=0;p<u.length;p+=1)w.push(a(u[p],y,x(u,p))||"null");S="[]"}else Object.keys(u).forEach((p,b,z)=>{const k=`${JSON.stringify(p)}: `,$=a(u[p],y,k.length+x(z,b));$!==void 0&&w.push(k+$)}),S="{}";if(w.length>0)return[S[0],n+w.join(`,
${y}`),S[1]].join(`
${f}`)}return h}(t,"",0)}function D(t){if(typeof t!="object"||t===null)return!1;const e=Object.getPrototypeOf(t);return(e===null||e===Object.prototype||Object.getPrototypeOf(e)===null)&&!(Symbol.toStringTag in t)&&!(Symbol.iterator in t)}function Q(t,e={}){if(!D(t)&&!Array.isArray(t))throw new TypeError("Expected a plain object or array");const{deep:n,compare:r}=e,s=new WeakMap,o=c=>{const a=s.get(c);if(a!==void 0)return a;const u=[];return s.set(c,u),u.push(...c.map(f=>Array.isArray(f)?o(f):D(f)?i(f):f)),u},i=c=>{const a=s.get(c);if(a!==void 0)return a;const u={},f=Object.keys(c).sort(r);s.set(c,u);for(const l of f){const h=c[l];let g;n&&Array.isArray(h)?g=o(h):g=n&&D(h)?i(h):h,Object.defineProperty(u,l,{...Object.getOwnPropertyDescriptor(c,l),value:g})}return u};return Array.isArray(t)?n?o(t):[...t]:i(t)}function Ve(t){const e=Q(t,{deep:!0});return`${H(e)}
`}function Ie(t,e){const n=new Map;for(const r of t){const s=e(r),o=n.get(s);o?o.push(r):n.set(s,[r])}return n}function Ne(t,e){const n=new Map;for(const r of t){const s=e(r);n.set(s,r)}return n}function Pe(t,e){const n=new Map;for(const[r,s]of t.entries())n.set(r,e(s,r,t));return n}function R(t,e={}){const n=new Map;for(const r of t)for(const[s,o]of r){if(n.has(s)){const i=n.get(s);if(!e.allowEqualValues||!P(i,o))throw new Error(`Cannot merge key ${String(s)} because it already exists.`)}n.set(s,o)}return n}function Te(t,e,n={}){return R([t,e],n)}function Re(...t){return R(t)}function Y(t,e,n={}){return C(t,e,(r,s,o)=>{if(o in t&&o in e){if(n.allowEqualValues&&P(r,s))return s;throw new Error(`Cannot merge key ${o} because it already exists.`)}return s})}function ee(t,e={}){const n={};for(const r of t.flat())Y(n,r,e);return n}function je(...t){return ee(t)}function N(t){return t===null||typeof t!="object"?t:Array.isArray(t)?t.map(N):Object.fromEntries(Object.entries(t).sort(([e],[n])=>e.localeCompare(n)).map(([e,n])=>[e,N(n)]))}function ze(t){return Object.fromEntries(Object.entries(t).sort(([e],[n])=>e.localeCompare(n)))}function Le(t,e){const n=new Set;for(const r of t)e.has(r)||n.add(r);return n}function Fe(t,e){if(!/[a-zA-Z0-9]/.test(t))return t;const r=/^([^a-zA-Z0-9]*)/.exec(t)?.[1]??"",o=/([^a-zA-Z0-9]*)$/.exec(t)?.[1]??"",i=r.length,c=t.length-o.length,a=t.slice(i,c),u=a&&/[a-zA-Z0-9]/.test(a)?e(a):a;return r+u+o}function Ze(t){return`'${t.replaceAll("'",String.raw`\'`)}'`}function Ke(t){return`"${t.replaceAll('"',String.raw`\"`)}"`}let te=t=>crypto.getRandomValues(new Uint8Array(t)),ne=(t,e,n)=>{let r=(2<<Math.log2(t.length-1))-1,s=-~(1.6*r*e/t.length);return(o=e)=>{let i="";for(;;){let c=n(s),a=s|0;for(;a--;)if(i+=t[c[a]&r]||"",i.length>=o)return i}}},re=(t,e=21)=>ne(t,e|0,te);const se="0123456789",oe="abcdefghijklmnopqrstuvwxyz",ie="ABCDEFGHIJKLMNOPQRSTUVWXYZ",ce=re(`${se}${oe}${ie}_`,12);function Ue(t=12){return ce(t)}class j extends Error{cyclePath;constructor(e){super(`Cyclical dependency detected: ${e.map(n=>JSON.stringify(n)).join(" -> ")}`),this.name="ToposortCyclicalDependencyError",this.cyclePath=e}}class O extends Error{unknownNode;constructor(e){super(`Unknown node referenced in edges: ${JSON.stringify(e)}`),this.name="ToposortUnknownNodeError",this.unknownNode=e}}function ae(t,e){const n=new Map;for(const r of e){const[s,o]=r,i=t.get(s),c=t.get(o);if(i===void 0)throw new O(s);if(c===void 0)throw new O(o);const a=n.get(c);a?a.add(i):n.set(c,new Set([i]))}return n}function ue(t,e){const n=Array.from({length:e},()=>0);for(const[,r]of t.entries())for(const s of r)n[s]++;return n}function fe(t,e,n){const r=new Set;for(let o=0;o<t.length;o++)if(!e.has(o)&&!r.has(o)){const a=s(o,[],new Set);if(a)return a.map(u=>t[u])}return[];function s(o,i,c){i.push(o),c.add(o),r.add(o);const a=n.get(o)??new Set;for(const u of a){if(c.has(u)){const f=i.indexOf(u),l=i.slice(f);return l.push(u),l}if(!r.has(u)){const f=s(u,i,c);if(f)return f}}return c.delete(o),i.pop(),null}}function le(t,e){return typeof t=="string"&&typeof e=="string"?t.localeCompare(e):t===e?0:t<e?-1:1}function We(t,e,n={}){const{compareFunc:r=le}=n,s=(l,h)=>r(t[l],t[h]),o=new Map(t.map((l,h)=>[l,h])),i=ae(o,e),c=ue(i,t.length),a=[];for(const[l,h]of c.entries())h===0&&a.push(l);a.sort(s);const u=[],f=new Set;for(;a.length>0;){const l=a.pop();if(l===void 0)break;f.add(l),u.push(t[l]);const h=i.get(l),g=[];if(h)for(const m of h)c[m]--,c[m]===0&&g.push(m);g.sort(s),a.push(...g)}if(u.length!==t.length){const l=fe(t,f,i);throw new j(l.toReversed())}return u.toReversed()}class he{constructor(e=[],n=(r,s)=>r<s?-1:r>s?1:0){if(this.data=e,this.length=this.data.length,this.compare=n,this.length>0)for(let r=(this.length>>1)-1;r>=0;r--)this._down(r)}push(e){this.data.push(e),this._up(this.length++)}pop(){if(this.length===0)return;const e=this.data[0],n=this.data.pop();return--this.length>0&&(this.data[0]=n,this._down(0)),e}peek(){return this.data[0]}_up(e){const{data:n,compare:r}=this,s=n[e];for(;e>0;){const o=e-1>>1,i=n[o];if(r(s,i)>=0)break;n[e]=i,e=o}n[e]=s}_down(e){const{data:n,compare:r}=this,s=this.length>>1,o=n[e];for(;e<s;){let i=(e<<1)+1;const c=i+1;if(c<this.length&&r(n[c],n[i])<0&&(i=c),r(n[i],o)>=0)break;n[e]=n[i],e=i}n[e]=o}}function ge(t,e){const n=new Map;for(const r of e){const[s,o]=r,i=t.get(s),c=t.get(o);if(i===void 0)throw new O(s);if(c===void 0)throw new O(o);const a=n.get(i);a?a.add(c):n.set(i,new Set([c]))}return n}function pe(t,e){const n=Array.from({length:e},()=>0);for(const[,r]of t.entries())for(const s of r)n[s]++;return n}function ye(t,e,n){if(e.size===t.length)return[];const r=[],s=new Set;function o(i){if(s.has(i))return r.push(i),!0;if(e.has(i))return!1;s.add(i),r.push(i);const c=n.get(i)??new Set;for(const a of c)if(o(a))return!0;return r.pop(),s.delete(i),!1}for(let i=0;i<t.length;i++)if(!e.has(i)&&(r.length=0,s.clear(),o(i)))return r.map(a=>t[a]);return[]}function de(t,e){return typeof t=="string"&&typeof e=="string"?t.localeCompare(e):t===e?0:t<e?-1:1}function me(t,e,n={}){const{compareFunc:r}=n,s=new Map(t.map((f,l)=>[f,l])),o=ge(s,e),i=pe(o,t.length),c=r?new he([],(f,l)=>r(t[f],t[l])):[];for(const[f,l]of i.entries())l===0&&c.push(f);const a=[],u=new Set;for(;c.length>0;){const f=c.pop();if(f===void 0)break;u.add(f),a.push(t[f]);const l=o.get(f);if(l)for(const h of l)i[h]--,i[h]===0&&c.push(h)}if(a.length!==t.length){const f=ye(t,u,o);throw new j(f)}return a}function Je(t,e,n=de){return me(t,e,{compareFunc:n})}function qe(t){return t!=null}const{z:E}=await _("zod"),we=/^[a-z0-9-]+$/,Se=/^[A-Z][a-zA-Z0-9]*$/,Me=/^[a-z][a-zA-Z0-9]*$/,Ee=/^[A-Z][A-Z0-9_]*$/,Ge={KEBAB_CASE:E.string().regex(we,{message:'Must be kebab case (e.g. "my-project")'}),PASCAL_CASE:E.string().regex(Se,{message:'Must be pascal case (e.g. "MyProject")'}),CAMEL_CASE:E.string().regex(Me,{message:'Must be camel case (e.g. "myProject")'}),CONSTANT_CASE:E.string().regex(Ee,{message:'Must be constant case (e.g. "MY_PROJECT")'})},{z:Ae}=await _("zod"),Oe=Ae.number().int().positive(),Xe={POSITIVE_INT:Oe},{z:be}=await _("zod");function He(t,e){return(n,r)=>{const s=t(n);if(!s)return n;const o=s.safeParse((e?n[e]:n)??void 0);if(!o.success){for(const i of o.error.issues)r.addIssue({...i,path:[...e?[e]:[],...i.path]});return be.NEVER}return e?{...n,[e]:o.data}:o.data}}export{K as ArrayContainer,Me as CAMEL_CASE_REGEX,Ge as CASE_VALIDATORS,Ee as CONSTANT_CASE_REGEX,J as FieldMapSchemaBuilder,we as KEBAB_CASE_REGEX,B as MapContainer,V as MapOfMapsContainer,Xe as NUMBER_VALIDATORS,W as NamedArrayFieldContainer,U as ObjectContainer,Se as PASCAL_CASE_REGEX,M as ScalarContainer,j as ToposortCyclicalDependencyError,O as ToposortUnknownNodeError,Z as TypedEventEmitter,Fe as convertCaseWithPrefix,Be as createFieldMap,ve as createFieldMapSchemaBuilder,$e as createTypedEventEmitter,Le as differenceSet,Ke as doubleQuot,ke as enhanceErrorWithContext,xe as hashWithSHA256,I as jsonDeepClone,Ie as mapGroupBy,Ne as mapKeyBy,Pe as mapValuesOfMap,qe as notEmpty,Ze as quot,Ue as randomKey,Y as safeMerge,je as safeMergeAll,ee as safeMergeAllWithOptions,Te as safeMergeMap,Re as safeMergeMaps,R as safeMergeMapsWithOptions,N as sortKeysRecursive,ze as sortObjectKeys,H as stringifyPrettyCompact,Ve as stringifyPrettyStable,me as toposort,We as toposortLocal,Je as toposortOrdered,He as transformWithDynamicSchema};
//# sourceMappingURL=utils-CgwfXMKN.js.map