@nice2dev/ui-forms 1.4.12 → 1.4.14

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/studio.cjs CHANGED
@@ -1,16 +1,16 @@
1
- "use strict";var ze=Object.defineProperty;var We=(e,t,n)=>t in e?ze(e,t,{enumerable:!0,configurable:!0,writable:!0,value:n}):e[t]=n;var se=(e,t,n)=>We(e,typeof t!="symbol"?t+"":t,n);Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const P=()=>({version:1,sections:[],folders:[],placement:{}}),Be=(e,t)=>`${e}:${t}`,B=".studio.json",He=/^([^/]+?)\.(manifest|entities|views|workflows|permissions|rbac|seeds|datasources|scripts)\.json$/i,ae=e=>!e.includes("/")&&e.toLowerCase().endsWith(B);function Xe(e){const t=e.find(n=>ae(n.path));if(t)return t.path;for(const n of e){const s=He.exec(n.path);if(s)return`${s[1]}${B}`}return`module${B}`}const N=e=>typeof e=="object"&&e!==null&&!Array.isArray(e),b=e=>typeof e=="string"&&e?e:void 0;function Ze(e){if(!e)return P();let t;try{t=JSON.parse(e.replace(/^\uFEFF/,""))}catch{return P()}if(!N(t))return P();const n=(Array.isArray(t.sections)?t.sections:[]).filter(N).map(r=>({id:b(r.id),label:b(r.label)??b(r.id)})).filter(r=>!!r.id&&!!r.label),s=(Array.isArray(t.folders)?t.folders:[]).filter(N).map(r=>({id:b(r.id),label:b(r.label)??b(r.id),group:b(r.group),...b(r.parent)?{parent:b(r.parent)}:{},...b(r.section)?{section:b(r.section)}:{}})).filter(r=>!!r.id&&!!r.label&&!!r.group),i={};if(N(t.placement))for(const[r,a]of Object.entries(t.placement)){if(!N(a))continue;const l={};b(a.section)&&(l.section=b(a.section)),b(a.folder)&&(l.folder=b(a.folder)),typeof a.order=="number"&&Number.isFinite(a.order)&&(l.order=a.order),(l.section||l.folder||l.order!==void 0)&&(i[r]=l)}return{version:1,sections:n,folders:s,placement:i}}const Ge=e=>e.sections.length===0&&e.folders.length===0&&Object.keys(e.placement).length===0;function Ye(e,t){const n=JSON.stringify(e,null,2)+`
1
+ "use strict";var nt=Object.defineProperty;var st=(e,t,n)=>t in e?nt(e,t,{enumerable:!0,configurable:!0,writable:!0,value:n}):e[t]=n;var fe=(e,t,n)=>st(e,typeof t!="symbol"?t+"":t,n);Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const q=()=>({version:1,sections:[],folders:[],placement:{}}),it=(e,t)=>`${e}:${t}`,G=".studio.json",rt=/^([^/]+?)\.(manifest|entities|views|workflows|permissions|rbac|seeds|datasources|scripts)\.json$/i,me=e=>!e.includes("/")&&e.toLowerCase().endsWith(G);function ot(e){const t=e.find(n=>me(n.path));if(t)return t.path;for(const n of e){const s=rt.exec(n.path);if(s)return`${s[1]}${G}`}return`module${G}`}const T=e=>typeof e=="object"&&e!==null&&!Array.isArray(e),k=e=>typeof e=="string"&&e?e:void 0;function at(e){if(!e)return q();let t;try{t=JSON.parse(e.replace(/^\uFEFF/,""))}catch{return q()}if(!T(t))return q();const n=(Array.isArray(t.sections)?t.sections:[]).filter(T).map(r=>({id:k(r.id),label:k(r.label)??k(r.id)})).filter(r=>!!r.id&&!!r.label),s=(Array.isArray(t.folders)?t.folders:[]).filter(T).map(r=>({id:k(r.id),label:k(r.label)??k(r.id),group:k(r.group),...k(r.parent)?{parent:k(r.parent)}:{},...k(r.section)?{section:k(r.section)}:{}})).filter(r=>!!r.id&&!!r.label&&!!r.group),i={};if(T(t.placement))for(const[r,o]of Object.entries(t.placement)){if(!T(o))continue;const l={};k(o.section)&&(l.section=k(o.section)),k(o.folder)&&(l.folder=k(o.folder)),typeof o.order=="number"&&Number.isFinite(o.order)&&(l.order=o.order),(l.section||l.folder||l.order!==void 0)&&(i[r]=l)}return{version:1,sections:n,folders:s,placement:i}}const ct=e=>e.sections.length===0&&e.folders.length===0&&Object.keys(e.placement).length===0;function lt(e,t){const n=JSON.stringify(e,null,2)+`
2
2
  `;return t!=null&&t.includes(`\r
3
3
  `)?n.replace(/\n/g,`\r
4
- `):n}const Qe=e=>e.toLowerCase().normalize("NFKD").replace(/[̀-ͯ]/g,"").replace(/[^a-z0-9]+/g,"-").replace(/^-+|-+$/g,"")||"item";function ce(e,t){const n=Qe(e);let s=n;for(let i=2;t.has(s);i++)s=`${n}-${i}`;return s}function et(e,t){const n=ce(t,new Set(e.sections.map(s=>s.id)));return{layout:{...e,sections:[...e.sections,{id:n,label:t}]},id:n}}function tt(e,t){const n=ce(t.label,new Set(e.folders.map(i=>i.id))),s={id:n,label:t.label,group:t.group};return t.parent&&(s.parent=t.parent),t.section&&(s.section=t.section),{layout:{...e,folders:[...e.folders,s]},id:n}}function nt(e,t,n){return t.kind==="section"?{...e,sections:e.sections.map(s=>s.id===t.id?{...s,label:n}:s)}:{...e,folders:e.folders.map(s=>s.id===t.id?{...s,label:n}:s)}}function st(e,t){const n={};if(t.kind==="folder"){const s=e.folders.find(i=>i.id===t.id);for(const[i,r]of Object.entries(e.placement))n[i]=r.folder===t.id?{...r,folder:s==null?void 0:s.parent}:r,n[i].folder||delete n[i].folder;return{...e,folders:e.folders.filter(i=>i.id!==t.id).map(i=>i.parent===t.id?{...i,parent:s==null?void 0:s.parent}:i).map(i=>{if(!i.parent){const{parent:r,...a}=i;return a}return i}),placement:H(n)}}for(const[s,i]of Object.entries(e.placement))if(i.section===t.id){const{section:r,...a}=i;n[s]=a}else n[s]=i;return{...e,sections:e.sections.filter(s=>s.id!==t.id),folders:e.folders.map(s=>{if(s.section===t.id){const{section:i,...r}=s;return r}return s}),placement:H(n)}}function H(e){const t={};for(const[n,s]of Object.entries(e))(s.section||s.folder||s.order!==void 0)&&(t[n]=s);return t}function it(e,t,n){var r;const s=(r=e.placement[t])==null?void 0:r.order,i={};if(n.folder){i.folder=n.folder;const a=e.folders.find(l=>l.id===n.folder);a!=null&&a.section&&(i.section=a.section)}else n.section&&(i.section=n.section);return s!==void 0&&(i.order=s),{...e,placement:H({...e.placement,[t]:i})}}function rt(e,t,n){if(t===n||!e.placement[t])return e;const s={...e.placement,[n]:e.placement[t]};return delete s[t],{...e,placement:s}}const le="\uFEFF",de={bom:!1,eol:`
5
- `,indent:" ",finalNewline:!0,colonSpace:!0};function V(e){const t=e.charCodeAt(0)===65279,n=e.includes(`\r
4
+ `):n}const dt=e=>e.toLowerCase().normalize("NFKD").replace(/[̀-ͯ]/g,"").replace(/[^a-z0-9]+/g,"-").replace(/^-+|-+$/g,"")||"item";function he(e,t){const n=dt(e);let s=n;for(let i=2;t.has(s);i++)s=`${n}-${i}`;return s}function ft(e,t){const n=he(t,new Set(e.sections.map(s=>s.id)));return{layout:{...e,sections:[...e.sections,{id:n,label:t}]},id:n}}function ut(e,t){const n=he(t.label,new Set(e.folders.map(i=>i.id))),s={id:n,label:t.label,group:t.group};return t.parent&&(s.parent=t.parent),t.section&&(s.section=t.section),{layout:{...e,folders:[...e.folders,s]},id:n}}function pt(e,t,n){return t.kind==="section"?{...e,sections:e.sections.map(s=>s.id===t.id?{...s,label:n}:s)}:{...e,folders:e.folders.map(s=>s.id===t.id?{...s,label:n}:s)}}function mt(e,t){const n={};if(t.kind==="folder"){const s=e.folders.find(i=>i.id===t.id);for(const[i,r]of Object.entries(e.placement))n[i]=r.folder===t.id?{...r,folder:s==null?void 0:s.parent}:r,n[i].folder||delete n[i].folder;return{...e,folders:e.folders.filter(i=>i.id!==t.id).map(i=>i.parent===t.id?{...i,parent:s==null?void 0:s.parent}:i).map(i=>{if(!i.parent){const{parent:r,...o}=i;return o}return i}),placement:L(n)}}for(const[s,i]of Object.entries(e.placement))if(i.section===t.id){const{section:r,...o}=i;n[s]=o}else n[s]=i;return{...e,sections:e.sections.filter(s=>s.id!==t.id),folders:e.folders.map(s=>{if(s.section===t.id){const{section:i,...r}=s;return r}return s}),placement:L(n)}}function L(e){const t={};for(const[n,s]of Object.entries(e))(s.section||s.folder||s.order!==void 0)&&(t[n]=s);return t}const ht=e=>e.slice(0,Math.max(0,e.indexOf(":")));function yt(e,t,n){var r;const s=(r=e.placement[t])==null?void 0:r.order,i={};if(n.folder){const o=e.folders.find(l=>l.id===n.folder);if(o&&o.group!==ht(t))return e;i.folder=n.folder,o!=null&&o.section&&(i.section=o.section)}else n.section&&(i.section=n.section);return s!==void 0&&(i.order=s),{...e,placement:L({...e.placement,[t]:i})}}function gt(e,t){const n={...e.placement};return t.forEach((s,i)=>{n[s]={...n[s],order:i}}),{...e,placement:L(n)}}function Y(e,t,n){var r;const s=new Map(e.folders.map(o=>[o.id,o])),i=new Set;for(let o=t;o&&!i.has(o);o=(r=s.get(o))==null?void 0:r.parent){if(o===n)return!0;i.add(o)}return!1}function bt(e,t,n){const s=e.folders.find(d=>d.id===t);if(!s)return e;let i=n.section;if(n.parent){const d=e.folders.find(a=>a.id===n.parent);if(!d||d.group!==s.group||Y(e,d.id,t))return e;i=d.section}const r=new Set(e.folders.filter(d=>Y(e,d.id,t)).map(d=>d.id)),o=e.folders.map(d=>{if(!r.has(d.id))return d;const a={id:d.id,label:d.label,group:d.group},c=d.id===t?n.parent:d.parent;return c&&(a.parent=c),i&&(a.section=i),a}),l={};for(const[d,a]of Object.entries(e.placement))if(a.folder&&r.has(a.folder)){const{section:c,...u}=a;l[d]=i?{...u,section:i}:u}else l[d]=a;return{...e,folders:o,placement:L(l)}}function vt(e,t,n){if(t===n||!e.placement[t])return e;const s={...e.placement,[n]:e.placement[t]};return delete s[t],{...e,placement:s}}const ye="\uFEFF",ge={bom:!1,eol:`
5
+ `,indent:" ",finalNewline:!0,colonSpace:!0};function H(e){const t=e.charCodeAt(0)===65279,n=e.includes(`\r
6
6
  `)?`\r
7
7
  `:`
8
- `;let s=de.indent;const i=e.split(/\r?\n/);for(let a=1;a<i.length;a++){const l=/^([ \t]+)\S/.exec(i[a]);if(l){s=l[1];break}}const r=/"\s*:(\s?)/.exec(e);return{bom:t,eol:n,indent:s,finalNewline:/\n$/.test(e),colonSpace:r?r[1]!=="":!0}}function O(e){const t=V(e);return{value:JSON.parse(t.bom?e.slice(1):e),format:t}}function v(e,t){const n={...de,...t},s=A(e,n,"");return(n.bom?le:"")+s+(n.finalNewline?n.eol:"")}function fe(e,t){if(t===void 0)return e;let n=t.includes(`\r
8
+ `;let s=ge.indent;const i=e.split(/\r?\n/);for(let o=1;o<i.length;o++){const l=/^([ \t]+)\S/.exec(i[o]);if(l){s=l[1];break}}const r=/"\s*:(\s?)/.exec(e);return{bom:t,eol:n,indent:s,finalNewline:/\n$/.test(e),colonSpace:r?r[1]!=="":!0}}function O(e){const t=H(e);return{value:JSON.parse(t.bom?e.slice(1):e),format:t}}function $(e,t){const n={...ge,...t},s=N(e,n,"");return(n.bom?ye:"")+s+(n.finalNewline?n.eol:"")}function be(e,t){if(t===void 0)return e;let n=t.includes(`\r
9
9
  `)?e.replace(/\r?\n/g,`\r
10
- `):e;return t.charCodeAt(0)===65279&&n.charCodeAt(0)!==65279&&(n=le+n),n}function F(e,t){if(e===t)return!0;if(typeof e!=typeof t||e===null||t===null||typeof e!="object"||Array.isArray(e)!==Array.isArray(t))return!1;if(Array.isArray(e)){const r=t;return e.length===r.length&&e.every((a,l)=>F(a,r[l]))}const n=e,s=t,i=Object.keys(n);return i.length!==Object.keys(s).length?!1:i.every(r=>Object.prototype.hasOwnProperty.call(s,r)&&F(n[r],s[r]))}function Q(e,t,n){return ue(e,t,n).text}function ue(e,t,n){const s=V(e),i=o=>({text:v(t,s),exact:!1,reason:o});let r;try{r=new ot(e).parseDocument()}catch(o){return i(o instanceof Error?o.message:String(o))}if(X(r))return i("duplicate keys");const a=[],l={text:e,format:s,edits:a,options:n,compact:!e.trimEnd().includes(`
11
- `)};te(l,r,t,"",!1);const f=at(e,a);try{const o=JSON.parse(s.bom?f.slice(1):f);if(!F(o,t))return i("patch did not read back")}catch{return i("patch was not valid JSON")}return{text:f,exact:!0}}class ot{constructor(t){se(this,"pos",0);this.text=t}parseDocument(){this.text.charCodeAt(0)===65279&&(this.pos=1);const t=this.value();if(this.ws(),this.pos<this.text.length)throw new Error(`Unexpected text at ${this.pos}`);return t}ws(){for(;this.pos<this.text.length&&/\s/.test(this.text[this.pos]);)this.pos++}value(){this.ws();const t=this.text[this.pos];if(t==="{")return this.object();if(t==="[")return this.array();const n=this.pos;if(t==='"')return{kind:"scalar",start:n,end:this.stringEnd(),value:JSON.parse(this.slice(n))};const s=/^(?:-?\d+(?:\.\d+)?(?:[eE][+-]?\d+)?|true|false|null)/.exec(this.text.slice(n,n+64));if(!s)throw new Error(`Unexpected token at ${n}`);return this.pos=n+s[0].length,{kind:"scalar",start:n,end:this.pos,value:JSON.parse(s[0])}}slice(t){return this.text.slice(t,this.pos)}stringEnd(){for(this.pos++;this.pos<this.text.length;){const t=this.text[this.pos];if(t==="\\"){this.pos+=2;continue}if(this.pos++,t==='"')return this.pos}throw new Error("Unterminated string")}object(){const t=this.pos++,n=[];if(this.ws(),this.text[this.pos]==="}")return{kind:"object",start:t,end:++this.pos,members:n};for(;;){this.ws();const s=this.pos;if(this.text[this.pos]!=='"')throw new Error(`Expected a key at ${this.pos}`);const i=JSON.parse(this.text.slice(s,this.stringEnd()));if(this.ws(),this.text[this.pos]!==":")throw new Error(`Expected ':' at ${this.pos}`);this.pos++,n.push({key:i,start:s,value:this.value()}),this.ws();const r=this.text[this.pos++];if(r==="}")return{kind:"object",start:t,end:this.pos,members:n};if(r!==",")throw new Error(`Expected ',' or '}' at ${this.pos-1}`)}}array(){const t=this.pos++,n=[];if(this.ws(),this.text[this.pos]==="]")return{kind:"array",start:t,end:++this.pos,items:n};for(;;){n.push(this.value()),this.ws();const s=this.text[this.pos++];if(s==="]")return{kind:"array",start:t,end:this.pos,items:n};if(s!==",")throw new Error(`Expected ',' or ']' at ${this.pos-1}`)}}}function X(e){if(e.kind==="object"){const t=new Set;for(const n of e.members){if(t.has(n.key)||X(n.value))return!0;t.add(n.key)}}else if(e.kind==="array")return e.items.some(X);return!1}function J(e){if(e.kind==="scalar")return e.value;if(e.kind==="array")return e.items.map(J);const t={};for(const n of e.members)t[n.key]=J(n.value);return t}function A(e,t,n){if(e===null||typeof e!="object")return e===void 0?"null":JSON.stringify(e);const s=n+t.indent,i=t.colonSpace?": ":":";if(Array.isArray(e))return e.length===0?"[]":`[${t.eol}${e.map(a=>s+A(a,t,s)).join(`,${t.eol}`)}${t.eol}${n}]`;const r=Object.entries(e).filter(([,a])=>a!==void 0);return r.length===0?"{}":`{${t.eol}${r.map(([a,l])=>`${s}${JSON.stringify(a)}${i}${A(l,t,s)}`).join(`,${t.eol}`)}${t.eol}${n}}`}function I(e,t,n=!1){if(e===null||typeof e!="object")return e===void 0?"null":JSON.stringify(e);const s=t.colonSpace?": ":":",i=n?",":", ";if(Array.isArray(e))return`[${e.map(l=>I(l,t,n)).join(i)}]`;const r=Object.entries(e).filter(([,l])=>l!==void 0),a=n?"":" ";return r.length===0?"{}":`{${a}${r.map(([l,f])=>`${JSON.stringify(l)}${s}${I(f,t,n)}`).join(i)}${a}}`}const pe=e=>e.compact?",":", ";function at(e,t){let n=e;for(const s of[...t].sort((i,r)=>r.start-i.start))n=n.slice(0,s.start)+s.text+n.slice(s.end);return n}function D(e,t){var s;const n=e.lastIndexOf(`
12
- `,t-1)+1;return((s=/^[ \t]*/.exec(e.slice(n,t)))==null?void 0:s[0])??""}function me(e,t){return!e.slice(t.start,t.end).includes(`
13
- `)}function ee(e,t,n){return e.compact?!0:t.kind==="scalar"||(t.kind==="object"?t.members.length===0:t.items.length===0)?n:me(e.text,t)}function x(e,t,n,s){const i=ee(e,t,s);e.edits.push({start:t.start,end:t.end,text:i?I(n,e.format,e.compact):A(n,e.format,D(e.text,t.start))})}const ye=e=>typeof e=="object"&&e!==null&&!Array.isArray(e);function te(e,t,n,s,i){if(t.kind==="scalar"){if(t.value===n)return;x(e,t,n,i);return}F(J(t),n)||(t.kind==="object"&&ye(n)?ct(e,t,n,s,i):t.kind==="array"&&Array.isArray(n)?ft(e,t,n,s,i):x(e,t,n,i))}function he(e,t,n){return n!==void 0?D(e.text,n):D(e.text,t.start)+e.format.indent}function ct(e,t,n,s,i){var d;const r=ee(e,t,i),a=t.members.filter(u=>Object.prototype.hasOwnProperty.call(n,u.key)&&n[u.key]!==void 0),l=Object.keys(n).filter(u=>n[u]!==void 0&&!t.members.some(y=>y.key===u));if(a.length===0&&t.members.length>0){x(e,t,n,i);return}for(const u of a)te(e,u.value,n[u.key],`${s}/${mt(u.key)}`,r);if(ge(e,t.members.map(u=>({start:u.start,end:u.value.end})),t.members.map(u=>a.includes(u))),l.length===0)return;const f=e.format.colonSpace?": ":":";if(r){const u=l.map(y=>`${JSON.stringify(y)}${f}${I(n[y],e.format,e.compact)}`);Se(e,t,a.length>0?a[a.length-1].value.end:void 0,u);return}const o=he(e,t,(d=t.members[0])==null?void 0:d.start),c=l.map(u=>`${o}${JSON.stringify(u)}${f}${A(n[u],e.format,o)}`);be(e,t,a.length>0?a[a.length-1].value.end:void 0,c)}const lt=["name","id","code","key","slug","state","Id"];function dt(e,t,n,s){var f,o;const i=[...n,...s];if(i.length===0||!i.every(ye))return;const r=(c,d)=>{const u=c.map(y=>y[d]);return u.every(y=>typeof y=="string"||typeof y=="number")&&new Set(u).size===u.length},a=(o=(f=e.options)==null?void 0:f.arrayKey)==null?void 0:o.call(f,t);return(a?[a]:lt).find(c=>r(n,c)&&r(s,c))}function ft(e,t,n,s,i){var g;const r=ee(e,t,i),a=t.items.map(J),l=dt(e,s,a,n),f=p=>p[l],o=l!==void 0?a.map(p=>{const m=f(p);return n.findIndex(S=>f(S)===m)}):pt(a,n);{const p=new Set(o.filter(m=>m>=0));for(let m=0;m<o.length;m++){if(o[m]>=0)continue;let S=-1;for(let h=m-1;h>=0;h--)if(o[h]>=0){S=o[h];break}let j=n.length;for(let h=m+1;h<o.length;h++)if(o[h]>=0){j=o[h];break}for(let h=S+1;h<j;h++)if(!p.has(h)){o[m]=h,p.add(h);break}}}const c=o.filter(p=>p>=0);if(c.some((p,m)=>m>0&&p<c[m-1])){x(e,t,n,i);return}if(c.length===0&&t.items.length>0){x(e,t,n,i);return}t.items.forEach((p,m)=>{o[m]>=0&&te(e,p,n[o[m]],`${s}/${o[m]}`,r)}),ge(e,t.items.map(p=>({start:p.start,end:p.end})),o.map(p=>p>=0));const d=t.items.length>0&&t.items.every(p=>p.kind!=="scalar"&&me(e.text,p)),u=he(e,t,(g=t.items[0])==null?void 0:g.start),y=new Map;n.forEach((p,m)=>{if(o.includes(m))return;let S;for(let K=t.items.length-1;K>=0;K--)if(o[K]>=0&&o[K]<m){S=K;break}const j=r?I(p,e.format,e.compact):d?`${u}${I(p,e.format)}`:`${u}${A(p,e.format,u)}`,h=y.get(S)??[];h.push(j),y.set(S,h)});for(const[p,m]of y){const S=p===void 0?void 0:t.items[p].end;if(p===void 0&&c.length>0){const j=t.items[o.findIndex(K=>K>=0)],h=r?pe(e):`,${e.format.eol}`;e.edits.push({start:j.start,end:j.start,text:r?m.join(h)+h:m.join(h).trimStart()+h+u});continue}r?Se(e,t,S,m):be(e,t,S,m)}}const ut=4e6;function pt(e,t){const n=e.length,s=t.length;if(n*s>ut)return e.map((c,d)=>d<s?d:-1);const i=e.map(c=>JSON.stringify(c)),r=t.map(c=>JSON.stringify(c)),a=Array.from({length:n+1},()=>new Uint32Array(s+1));for(let c=n-1;c>=0;c--)for(let d=s-1;d>=0;d--)a[c][d]=i[c]===r[d]?a[c+1][d+1]+1:Math.max(a[c+1][d],a[c][d+1]);const l=new Array(n).fill(-1);let f=0,o=0;for(;f<n&&o<s;)i[f]===r[o]?l[f++]=o++:a[f+1][o]>=a[f][o+1]?f++:o++;return l}function ge(e,t,n){for(let s=0;s<t.length;s++){if(n[s])continue;let i=s;for(;i+1<t.length&&!n[i+1];)i++;i+1<t.length?e.edits.push({start:t[s].start,end:t[i+1].start,text:""}):s>0?e.edits.push({start:t[s-1].end,end:t[i].end,text:""}):e.edits.push({start:t[s].start,end:t[i].end,text:""}),s=i}}function be(e,t,n,s){const i=e.format.eol;if(n!==void 0){e.edits.push({start:n,end:n,text:`,${i}${s.join(`,${i}`)}`});return}const r=t.end-1;if((t.kind==="object"?t.members.length:t.items.length)===0)e.edits.push({start:t.start+1,end:r,text:`${i}${s.join(`,${i}`)}${i}${D(e.text,t.start)}`});else{const l=t.kind==="object"?t.members[0].start:t.items[0].start;e.edits.push({start:l,end:l,text:`${s.join(`,${i}`).trimStart()}`})}}function Se(e,t,n,s){const i=pe(e);if(n!==void 0){e.edits.push({start:n,end:n,text:`${i}${s.join(i)}`});return}const r=t.kind==="object"&&!e.compact?" ":"";e.edits.push({start:t.start+1,end:t.end-1,text:`${r}${s.join(i)}${r}`})}function mt(e){return e.replace(/~/g,"~0").replace(/\//g,"~1")}const E=e=>e.slice(e.lastIndexOf("/")+1),yt=e=>e.charCodeAt(0)===65279?e.slice(1):e;function L(e){return{id:e.id,label:e.label,labelKey:e.labelKey,icon:e.icon,match:e.match,editor:e.editor,decode(t,n){return e.select(O(t[0].text).value,n)},encode(t,n,s){const i=n[0].text,r=O(i).value,a=e.assign(r,t,s);return{files:[{path:n[0].path,text:Q(i,a,{arrayKey:e.arrayKey})}]}}}}const _=L({id:"json",label:"JSON",labelKey:"devStudio.kind.json",icon:"code",match:e=>e.toLowerCase().endsWith(".json"),editor:"json",select:e=>e,assign:(e,t)=>t}),R={id:"text",label:"Text",labelKey:"devStudio.kind.text",icon:"file",match:()=>!0,editor:"text",decode:e=>e[0].text,encode:(e,t)=>({files:[{path:t[0].path,text:fe(e,t[0].text)}]})};function ke(e,t){return e.find(n=>n.match(t))??(_.match(t)?_:R)}function ht(e,t,n){for(const s of[_,R])if(s.match(e.path))try{const i=s.decode([e],n);return{key:`${s.id}:${e.path}`,kind:s,paths:[e.path],label:E(e.path),model:i,error:t}}catch{}return{key:`text:${e.path}`,kind:R,paths:[e.path],label:E(e.path),model:e.text,error:t}}function gt(e,t,n,s){var l,f;const i=e.encode(t,n,s),r=new Map(n.map(o=>[o.path,o.text])),a=((l=i.files.find(o=>r.get(o.path)!==o.text))==null?void 0:l.path)??((f=i.deleted)==null?void 0:f.find(o=>r.has(o)));if(a!==void 0)throw new Error(`${E(a)} would not be stored as it is`)}function bt(e,t,n){const s=new Map;for(const r of t){const a=ke(e,r.path),l=a.group?a.group(r.path):r.path,f=`${a.id}:${l}`,o=s.get(f)??{kind:a,group:l,files:[]};o.files.push(r),s.set(f,o)}const i=[];for(const[r,{kind:a,group:l,files:f}]of s){const o=f.map(d=>d.path).sort(),c=E(a.group?l:o[0]);try{const d=a.decode(f,n);gt(a,d,f,n),i.push({key:r,kind:a,paths:o,label:c,model:d})}catch(d){const u=d instanceof Error?d.message:String(d);for(const y of f)i.push(ht(y,u,n))}}return i.sort((r,a)=>r.label.localeCompare(a.label))}function St(e,t,n,s){const i=n.filter(f=>e.paths.includes(f.path)),r=e.kind.encode(t,i,s),a=new Map(n.map(f=>[f.path,f])),l=[];for(const f of r.files){const o=a.get(f.path);o&&o.text===f.text||l.push({type:"write",path:f.path,text:f.text,baseVersion:o==null?void 0:o.version})}for(const f of r.deleted??[]){const o=a.get(f);o&&l.push({type:"delete",path:f,baseVersion:o.version})}return l}function ve(e,t){try{return JSON.parse(yt(e))}catch{return t}}const w=e=>typeof e=="object"&&e!==null&&!Array.isArray(e),k=(...e)=>t=>{const n=t.toLowerCase();return e.some(s=>n.endsWith(s.toLowerCase()))};function C(e){return L({id:e.id,label:e.label,labelKey:e.labelKey,icon:e.icon,editor:e.editor,match:e.match,select:t=>{if(Array.isArray(t))return t;const n=w(t)?t[e.property]:void 0;return Array.isArray(n)?n:[]},assign:(t,n)=>Array.isArray(t)?n:w(t)&&!(e.property in t)&&n.length===0?t:{...w(t)?t:{},[e.property]:n},arrayKey:e.itemKey?()=>e.itemKey:void 0})}function ne(e){const t=C(e);return{...t,decode:(n,s)=>t.decode(n,s).map((i,r)=>e.toItem(i,r)),encode:(n,s,i)=>t.encode(n.map(r=>e.fromItem(r)),s,i)}}function M(e){return L({...e,select:t=>w(t)?t:{},assign:(t,n)=>n})}const kt=/^(.*)\.([a-z]{2,3}(?:-[A-Za-z]{2,4})?)\.i18n\.json$/i,vt=e=>{const t=kt.exec(e);return t?{group:t[1],locale:t[2]}:null},Z=e=>w(e)&&Object.values(e).every(t=>typeof t=="string");function we(e){if(w(e)){for(const t of["translations","keys"])if(t in e){if(Z(e[t]))return e[t];throw new Error(`"${t}" is not a flat map of texts`)}if(Z(e))return e}throw new Error("no translations in this file")}function G(e,t){return w(e)?w(e.translations)?{...e,translations:t}:w(e.keys)?{...e,keys:t}:Z(e)?t:{...e,translations:t}:{translations:t}}function $e(e={}){const t=e.parse??vt,n=e.pathFor??((s,i)=>`${s}.${i}.i18n.json`);return{id:e.id??"i18n",label:e.label??"Translations",labelKey:e.labelKey??"devStudio.kind.i18n",icon:"globe",editor:"i18n",match:s=>t(s)!==null,group:s=>{var i;return((i=t(s))==null?void 0:i.group)??s},decode(s){const i={};for(const r of s){const a=t(r.path);a&&(i[a.locale]={...we(O(r.text).value)})}return i},encode(s,i){const r=new Map;let a="";for(const c of i){const d=t(c.path);d&&(r.set(d.locale,c),a=d.group)}const l=r.get("en")??i[0],f=[];for(const[c,d]of Object.entries(s)){const u=r.get(c);if(u){const g=O(u.text).value;f.push({path:u.path,text:Q(u.text,G(g,d))});continue}const y=n(a||E((l==null?void 0:l.path)??"module"),c);if(l){const g=O(l.text).value,p=w(g)&&"locale"in g?{...g,locale:c}:g;f.push({path:y,text:v(G(p,d),V(l.text))})}else f.push({path:y,text:v({locale:c,translations:d})})}const o=[...r.entries()].filter(([c])=>!(c in s)).map(([,c])=>c.path);return{files:f,deleted:o}}}}const $=e=>typeof e=="object"&&e!==null&&!Array.isArray(e),je=["frontend","backend","noCode","sql"],wt=["preInstall","postInstall","preUninstall","postUninstall"];function Ke(e){switch(e){case"frontend":return["typescript","javascript"];case"backend":return["csharp","javascript"];case"sql":return["sql"];case"noCode":return[]}}const $t=new Set(["read","filter","map","aggregate","set","if","forEach","write","callScript","return"]),Ee=e=>Array.isArray(e)&&e.every(t=>$(t)&&typeof t.id=="string"&&$t.has(String(t.type)));function U(e){if(je.includes(e.kind))return e.kind;if(e.source===void 0&&Ee(e.steps))return"noCode";const t=typeof e.language=="string"?e.language.toLowerCase():"";return t.endsWith("sql")||e.source===void 0&&typeof e.sql=="string"?"sql":/^(csharp|c#|cs\b)/.test(t)?"backend":"frontend"}const Oe=["id","displayName","description","language","category","trigger","returnType","source","sourcePath"],jt=e=>Array.isArray(e)&&e.every(t=>$(t)&&typeof t.name=="string");function Ae(e,t){const n=`#${t+1}`;if(!$(e)||typeof e.name!="string"||!e.name){const l=$(e)&&typeof e.displayName=="string"?e.displayName:n;return{key:`#${t}`,label:l,rawReason:"no name",source:e}}const s=e.name,i=typeof e.displayName=="string"&&e.displayName?e.displayName:s,r=l=>({key:s,label:i,rawReason:l,source:e}),a={name:s,kind:U(e)};for(const l of Oe){const f=e[l];if(f!==void 0){if(typeof f!="string")return r(`"${l}" is not text`);a[l]=f}}if(e.parameters!==void 0){if(!jt(e.parameters))return r('"parameters" is not a list of named parameters');a.parameters=e.parameters}if(a.kind==="noCode"){if(e.steps!==void 0&&!Ee(e.steps))return r('"steps" are not no-code steps');a.steps=e.steps??[]}return{key:s,label:i,definition:a,source:e}}function Ie(e){const t=e.definition;if(!t)return e.source;const n=$(e.source)?e.source:{},s={...n,name:t.name};for(const i of Oe)t[i]===void 0?delete s[i]:s[i]=t[i];return t.parameters===void 0?delete s.parameters:s.parameters=t.parameters,t.kind==="noCode"?s.steps=t.steps??[]:U(n)==="noCode"&&delete s.steps,delete s.kind,("kind"in n||U(s)!==t.kind)&&(s.kind=t.kind),s}function W(e){const t=new Set;return e.map((n,s)=>{const i=Ae(n,s);return t.has(i.key)&&(i.key=`${i.key}#${s}`),t.add(i.key),i})}function ie(e,t){if(!$(e)||!Object.values(e).every(n=>Array.isArray(n)&&n.every(s=>typeof s=="string")))throw new Error(`"${t}" is not lists of SQL statements per phase`);return e}function Ne(e){const t=e.property??"scripts",n=e.phasesProperty??"phases",s=t===n,i=r=>r.scripts.map(Ie);return L({id:e.id??"scripts",label:e.label??"Scripts",labelKey:e.labelKey??"devStudio.kind.scripts",icon:e.icon??"code",editor:"scriptList",match:e.match,select:r=>{if(Array.isArray(r))return{scripts:W(r),...s?{holds:"scripts"}:{}};if(!$(r)||r[t]===void 0&&r[n]===void 0)throw new Error(`no "${t}" in this file`);const a=r[t];if(s)return Array.isArray(a)?{scripts:W(a),holds:"scripts"}:{scripts:[],phases:ie(a,t),holds:"phases"};if(a!==void 0&&!Array.isArray(a))throw new Error(`"${t}" is not a list`);const l=r[n];return{scripts:W(a??[]),...l!==void 0?{phases:ie(l,n)}:{}}},assign:(r,a)=>{if(a.holds==="phases"&&a.scripts.length>0)throw new Error("This file holds database scripts only; add scripts to another file.");if(Array.isArray(r)&&a.phases===void 0)return i(a);const l=$(r)?r:{};if(s)return{...l,[t]:a.holds==="phases"?a.phases??{}:i(a)};const f={...l};return(t in l||a.scripts.length>0)&&(f[t]=i(a)),a.phases===void 0?delete f[n]:f[n]=a.phases,f},arrayKey:r=>r===`/${t}`?"name":void 0})}function Te(e){const n=e.normalize("NFKD").replace(/[\u0300-\u036f]/g,"").split(/[^A-Za-z0-9]+/).filter(Boolean).map((s,i)=>i===0?s[0].toLowerCase()+s.slice(1):s[0].toUpperCase()+s.slice(1)).join("");return/^[A-Za-z_]/.test(n)?n:`script${n}`}function Kt(e){const t=Te(e.name),n=e.language??Ke(e.kind)[0],s={name:t,kind:e.kind,...e.name!==t?{displayName:e.name}:{},...n?{language:n}:{},...e.category?{category:e.category}:{},...e.trigger?{trigger:e.trigger}:{},parameters:[]},i=t[0].toUpperCase()+t.slice(1);switch(e.kind){case"noCode":return{...s,steps:[]};case"sql":return{...s,source:`-- ${e.name}
10
+ `):e;return t.charCodeAt(0)===65279&&n.charCodeAt(0)!==65279&&(n=ye+n),n}function P(e,t){if(e===t)return!0;if(typeof e!=typeof t||e===null||t===null||typeof e!="object"||Array.isArray(e)!==Array.isArray(t))return!1;if(Array.isArray(e)){const r=t;return e.length===r.length&&e.every((o,l)=>P(o,r[l]))}const n=e,s=t,i=Object.keys(n);return i.length!==Object.keys(s).length?!1:i.every(r=>Object.prototype.hasOwnProperty.call(s,r)&&P(n[r],s[r]))}function X(e,t,n){return ve(e,t,n).text}function ve(e,t,n){const s=H(e),i=a=>({text:$(t,s),exact:!1,reason:a});let r;try{r=new St(e).parseDocument()}catch(a){return i(a instanceof Error?a.message:String(a))}if(ee(r))return i("duplicate keys");const o=[],l={text:e,format:s,edits:o,options:n,compact:!e.trimEnd().includes(`
11
+ `)};oe(l,r,t,"",!1);const d=kt(e,o);try{const a=JSON.parse(s.bom?d.slice(1):d);if(!P(a,t))return i("patch did not read back")}catch{return i("patch was not valid JSON")}return{text:d,exact:!0}}class St{constructor(t){fe(this,"pos",0);this.text=t}parseDocument(){this.text.charCodeAt(0)===65279&&(this.pos=1);const t=this.value();if(this.ws(),this.pos<this.text.length)throw new Error(`Unexpected text at ${this.pos}`);return t}ws(){for(;this.pos<this.text.length&&/\s/.test(this.text[this.pos]);)this.pos++}value(){this.ws();const t=this.text[this.pos];if(t==="{")return this.object();if(t==="[")return this.array();const n=this.pos;if(t==='"')return{kind:"scalar",start:n,end:this.stringEnd(),value:JSON.parse(this.slice(n))};const s=/^(?:-?\d+(?:\.\d+)?(?:[eE][+-]?\d+)?|true|false|null)/.exec(this.text.slice(n,n+64));if(!s)throw new Error(`Unexpected token at ${n}`);return this.pos=n+s[0].length,{kind:"scalar",start:n,end:this.pos,value:JSON.parse(s[0])}}slice(t){return this.text.slice(t,this.pos)}stringEnd(){for(this.pos++;this.pos<this.text.length;){const t=this.text[this.pos];if(t==="\\"){this.pos+=2;continue}if(this.pos++,t==='"')return this.pos}throw new Error("Unterminated string")}object(){const t=this.pos++,n=[];if(this.ws(),this.text[this.pos]==="}")return{kind:"object",start:t,end:++this.pos,members:n};for(;;){this.ws();const s=this.pos;if(this.text[this.pos]!=='"')throw new Error(`Expected a key at ${this.pos}`);const i=JSON.parse(this.text.slice(s,this.stringEnd()));if(this.ws(),this.text[this.pos]!==":")throw new Error(`Expected ':' at ${this.pos}`);this.pos++,n.push({key:i,start:s,value:this.value()}),this.ws();const r=this.text[this.pos++];if(r==="}")return{kind:"object",start:t,end:this.pos,members:n};if(r!==",")throw new Error(`Expected ',' or '}' at ${this.pos-1}`)}}array(){const t=this.pos++,n=[];if(this.ws(),this.text[this.pos]==="]")return{kind:"array",start:t,end:++this.pos,items:n};for(;;){n.push(this.value()),this.ws();const s=this.text[this.pos++];if(s==="]")return{kind:"array",start:t,end:this.pos,items:n};if(s!==",")throw new Error(`Expected ',' or ']' at ${this.pos-1}`)}}}function ee(e){if(e.kind==="object"){const t=new Set;for(const n of e.members){if(t.has(n.key)||ee(n.value))return!0;t.add(n.key)}}else if(e.kind==="array")return e.items.some(ee);return!1}function _(e){if(e.kind==="scalar")return e.value;if(e.kind==="array")return e.items.map(_);const t={};for(const n of e.members)t[n.key]=_(n.value);return t}function N(e,t,n){if(e===null||typeof e!="object")return e===void 0?"null":JSON.stringify(e);const s=n+t.indent,i=t.colonSpace?": ":":";if(Array.isArray(e))return e.length===0?"[]":`[${t.eol}${e.map(o=>s+N(o,t,s)).join(`,${t.eol}`)}${t.eol}${n}]`;const r=Object.entries(e).filter(([,o])=>o!==void 0);return r.length===0?"{}":`{${t.eol}${r.map(([o,l])=>`${s}${JSON.stringify(o)}${i}${N(l,t,s)}`).join(`,${t.eol}`)}${t.eol}${n}}`}function x(e,t,n=!1){if(e===null||typeof e!="object")return e===void 0?"null":JSON.stringify(e);const s=t.colonSpace?": ":":",i=n?",":", ";if(Array.isArray(e))return`[${e.map(l=>x(l,t,n)).join(i)}]`;const r=Object.entries(e).filter(([,l])=>l!==void 0),o=n?"":" ";return r.length===0?"{}":`{${o}${r.map(([l,d])=>`${JSON.stringify(l)}${s}${x(d,t,n)}`).join(i)}${o}}`}const Se=e=>e.compact?",":", ";function kt(e,t){let n=e;for(const s of[...t].sort((i,r)=>r.start-i.start))n=n.slice(0,s.start)+s.text+n.slice(s.end);return n}function U(e,t){var s;const n=e.lastIndexOf(`
12
+ `,t-1)+1;return((s=/^[ \t]*/.exec(e.slice(n,t)))==null?void 0:s[0])??""}function ke(e,t){return!e.slice(t.start,t.end).includes(`
13
+ `)}function re(e,t,n){return e.compact?!0:t.kind==="scalar"||(t.kind==="object"?t.members.length===0:t.items.length===0)?n:ke(e.text,t)}function C(e,t,n,s){const i=re(e,t,s);e.edits.push({start:t.start,end:t.end,text:i?x(n,e.format,e.compact):N(n,e.format,U(e.text,t.start))})}const we=e=>typeof e=="object"&&e!==null&&!Array.isArray(e);function oe(e,t,n,s,i){if(t.kind==="scalar"){if(t.value===n)return;C(e,t,n,i);return}P(_(t),n)||(t.kind==="object"&&we(n)?$t(e,t,n,s,i):t.kind==="array"&&Array.isArray(n)?Kt(e,t,n,s,i):C(e,t,n,i))}function $e(e,t,n){return n!==void 0?U(e.text,n):U(e.text,t.start)+e.format.indent}function wt(e,t){for(let n=t+1;n<e.length;n++)if(e[n]==="\\")n++;else if(e[n]==='"')return n+1;return e.length}function $t(e,t,n,s,i){var p;const r=re(e,t,i),o=f=>Object.prototype.hasOwnProperty.call(n,f)&&n[f]!==void 0,l=Object.keys(n).filter(o),d=new Map;t.members.forEach((f,y)=>{const v=l[y];v!==void 0&&!o(f.key)&&!t.members.some(g=>g.key===v)&&d.set(f,v)});const a=f=>d.get(f)??f.key,c=t.members.filter(f=>o(f.key)||d.has(f)),u=l.filter(f=>!t.members.some(y=>y.key===f)&&![...d.values()].includes(f));if(c.length===0&&t.members.length>0){C(e,t,n,i);return}for(const f of c){const y=a(f);y!==f.key&&e.edits.push({start:f.start,end:wt(e.text,f.start),text:JSON.stringify(y)}),oe(e,f.value,n[y],`${s}/${It(y)}`,r)}if(je(e,t.members.map(f=>({start:f.start,end:f.value.end})),t.members.map(f=>c.includes(f))),u.length===0)return;const m=e.format.colonSpace?": ":":";if(r){const f=u.map(y=>`${JSON.stringify(y)}${m}${x(n[y],e.format,e.compact)}`);Ke(e,t,c.length>0?c[c.length-1].value.end:void 0,f);return}const h=$e(e,t,(p=t.members[0])==null?void 0:p.start),b=u.map(f=>`${h}${JSON.stringify(f)}${m}${N(n[f],e.format,h)}`);Oe(e,t,c.length>0?c[c.length-1].value.end:void 0,b)}const jt=["name","id","code","key","slug","state","Id"];function Ot(e,t,n,s){var d,a;const i=[...n,...s];if(i.length===0||!i.every(we))return;const r=(c,u)=>{const m=c.map(h=>h[u]);return m.every(h=>typeof h=="string"||typeof h=="number")&&new Set(m).size===m.length},o=(a=(d=e.options)==null?void 0:d.arrayKey)==null?void 0:a.call(d,t);return(o?[o]:jt).find(c=>r(n,c)&&r(s,c))}function Kt(e,t,n,s,i){var b;const r=re(e,t,i),o=t.items.map(_),l=Ot(e,s,o,n),d=p=>p[l],a=l!==void 0?o.map(p=>{const f=d(p);return n.findIndex(y=>d(y)===f)}):At(o,n);{const p=new Set(a.filter(f=>f>=0));for(let f=0;f<a.length;f++){if(a[f]>=0)continue;let y=-1;for(let g=f-1;g>=0;g--)if(a[g]>=0){y=a[g];break}let v=n.length;for(let g=f+1;g<a.length;g++)if(a[g]>=0){v=a[g];break}for(let g=y+1;g<v;g++)if(!p.has(g)){a[f]=g,p.add(g);break}}}const c=a.filter(p=>p>=0);if(c.some((p,f)=>f>0&&p<c[f-1])){C(e,t,n,i);return}if(c.length===0&&t.items.length>0){C(e,t,n,i);return}t.items.forEach((p,f)=>{a[f]>=0&&oe(e,p,n[a[f]],`${s}/${a[f]}`,r)}),je(e,t.items.map(p=>({start:p.start,end:p.end})),a.map(p=>p>=0));const u=t.items.length>0&&t.items.every(p=>p.kind!=="scalar"&&ke(e.text,p)),m=$e(e,t,(b=t.items[0])==null?void 0:b.start),h=new Map;n.forEach((p,f)=>{if(a.includes(f))return;let y;for(let S=t.items.length-1;S>=0;S--)if(a[S]>=0&&a[S]<f){y=S;break}const v=r?x(p,e.format,e.compact):u?`${m}${x(p,e.format)}`:`${m}${N(p,e.format,m)}`,g=h.get(y)??[];g.push(v),h.set(y,g)});for(const[p,f]of h){const y=p===void 0?void 0:t.items[p].end;if(p===void 0&&c.length>0){const v=t.items[a.findIndex(S=>S>=0)],g=r?Se(e):`,${e.format.eol}`;e.edits.push({start:v.start,end:v.start,text:r?f.join(g)+g:f.join(g).trimStart()+g+m});continue}r?Ke(e,t,y,f):Oe(e,t,y,f)}}const Et=4e6;function At(e,t){const n=e.length,s=t.length;if(n*s>Et)return e.map((c,u)=>u<s?u:-1);const i=e.map(c=>JSON.stringify(c)),r=t.map(c=>JSON.stringify(c)),o=Array.from({length:n+1},()=>new Uint32Array(s+1));for(let c=n-1;c>=0;c--)for(let u=s-1;u>=0;u--)o[c][u]=i[c]===r[u]?o[c+1][u+1]+1:Math.max(o[c+1][u],o[c][u+1]);const l=new Array(n).fill(-1);let d=0,a=0;for(;d<n&&a<s;)i[d]===r[a]?l[d++]=a++:o[d+1][a]>=o[d][a+1]?d++:a++;return l}function je(e,t,n){for(let s=0;s<t.length;s++){if(n[s])continue;let i=s;for(;i+1<t.length&&!n[i+1];)i++;i+1<t.length?e.edits.push({start:t[s].start,end:t[i+1].start,text:""}):s>0?e.edits.push({start:t[s-1].end,end:t[i].end,text:""}):e.edits.push({start:t[s].start,end:t[i].end,text:""}),s=i}}function Oe(e,t,n,s){const i=e.format.eol;if(n!==void 0){e.edits.push({start:n,end:n,text:`,${i}${s.join(`,${i}`)}`});return}const r=t.end-1;if((t.kind==="object"?t.members.length:t.items.length)===0)e.edits.push({start:t.start+1,end:r,text:`${i}${s.join(`,${i}`)}${i}${U(e.text,t.start)}`});else{const l=t.kind==="object"?t.members[0].start:t.items[0].start;e.edits.push({start:l,end:l,text:`${s.join(`,${i}`).trimStart()}`})}}function Ke(e,t,n,s){const i=Se(e);if(n!==void 0){e.edits.push({start:n,end:n,text:`${i}${s.join(i)}`});return}const r=t.kind==="object"&&!e.compact?" ":"";e.edits.push({start:t.start+1,end:t.end-1,text:`${r}${s.join(i)}${r}`})}function It(e){return e.replace(/~/g,"~0").replace(/\//g,"~1")}function Nt(e,t,n,s,i){const r=t.prefix??"";if(!e.startsWith(r))return null;const o=e.slice(r.length),l=t.part??"whole";if(!i.qualifiedOnly&&o===n)return r+s;switch(l){case"head":return!i.qualifiedOnly&&o.startsWith(`${n}.`)?r+s+o.slice(n.length):null;case"query":return!i.qualifiedOnly&&o.startsWith(`${n}?`)?r+s+o.slice(n.length):null;case"tail":for(const d of i.qualifiers??[])for(const a of[".","/"])if(o===`${d}${a}${n}`)return`${r}${d}${a}${s}`;return null;default:return null}}const xt=(e,t,n)=>(!e.files||e.files.test(t))&&!("table"in e&&e.table&&n.ownTable),Ft=(e,t)=>{const n=t.split(".");return n.length>e.length?!1:n.every((s,i)=>s==="*"||e[e.length-n.length+i]===s)};function Ee(e,t,n,s,i){let r=0;const o=t.filter(f=>"prop"in f),l=t.flatMap(f=>"value"in f?[[f.value.replace("{name}",n),f.value.replace("{name}",s)]]:[]),d=t.filter(f=>"keysOf"in f),a=t.flatMap(f=>"keyPattern"in f?[[f.keyPattern.replace("{name}",n),f.keyPattern.replace("{name}",s)]]:[]),c=new Set(t.flatMap(f=>"jsonIn"in f?[f.jsonIn]:[])),u=f=>{for(const[y,v]of l)if(f===y)return v;return null},m=(f,y,v)=>{if(y!==null){for(const S of o)if(S.prop===y&&(!S.within||S.within===v)){const E=Nt(f,S,n,s,i);if(E!==null)return r++,E}if(c.has(y))try{const S=Ee(JSON.parse(f),t,n,s,i);if(S.count>0)return r+=S.count,JSON.stringify(S.value)}catch{}}const g=i.qualifiedOnly?null:u(f);return g!==null?(r++,g):f},h=(f,y)=>{if(i.qualifiedOnly)return f;for(const v of d){const g=v.prefix??"";if(f===g+n&&Ft(y,v.keysOf))return r++,g+s}for(const[v,g]of a)if(f.startsWith(v))return r++,g+f.slice(v.length);return f},b=(f,y,v,g)=>{if(typeof f=="string")return m(f,y,v);if(Array.isArray(f)){let S=!1;const E=f.map(A=>{const F=b(A,y,y??v,g);return S||(S=F!==A),F});return S?E:f}if(f&&typeof f=="object"){let S=!1;const E={};for(const[A,F]of Object.entries(f)){const le=h(A,g),de=b(F,A,y,[...g,A]);S||(S=le!==A||de!==F),E[le]=de}return S?E:f}return f};return{value:b(e,null,null,[]),count:r}}function Ae(e,t,n,s,i={}){const r=[];let o=0;if(!n||!s||n===s)return{files:r,count:o};for(const l of e){if(!/\.json$/i.test(l.path))continue;const d=t.filter(u=>xt(u,l.path,i));if(d.length===0)continue;let a;try{a=O(l.text).value}catch{continue}const c=Ee(a,d,n,s,i);c.count>0&&(o+=c.count,r.push({path:l.path,text:X(l.text,c.value)}))}return{files:r,count:o}}function Tt(e,t,n,s={}){const i=`${n}\0`,r=[];for(const o of e){const l=Ae([o],t,n,i,s);l.count>0&&r.push({path:o.path,count:l.count})}return r}function Ie(e,t,n=[]){const s=t.filter(l=>"prop"in l&&l.part==="tail"),i=[],r=new Set,o=(l,d,a,c)=>{if(typeof l=="string")for(const u of s){if(u.prop!==d||u.within&&u.within!==a)continue;const m=l.startsWith(u.prefix??"")?l.slice((u.prefix??"").length):"",h=Math.max(m.lastIndexOf("."),m.lastIndexOf("/"));if(h>0&&h<m.length-1){const b=m.slice(0,h),p=m.slice(h+1),f=`${b}\0${p}\0${c}`;!n.includes(b)&&!r.has(f)&&(r.add(f),i.push({qualifier:b,name:p,path:c}))}}else if(Array.isArray(l))l.forEach(u=>o(u,d,d??a,c));else if(l&&typeof l=="object")for(const[u,m]of Object.entries(l))o(m,u,d,c)};for(const l of e)if(!(!/\.json$/i.test(l.path)||!s.some(d=>!d.files||d.files.test(l.path))))try{o(O(l.text).value,null,null,l.path)}catch{}return i}function Ne(e,t,n,s=[]){const i=d=>d.replace(/[\\/]/g,".").toLowerCase(),r=e.map(d=>({...d})),o=new Map(r.map(d=>[i(d.id),d])),l=new Set(s.map(i));for(const d of Ie(t,n,s)){const a=i(d.qualifier);if(l.has(a))continue;let c=o.get(a);c||(c={id:d.qualifier,via:"reference",refers:[]},o.set(a,c),r.push(c));const u=c.refers??(c.refers=[]);u.includes(d.name)||u.push(d.name)}return r}const I=e=>e.slice(e.lastIndexOf("/")+1),Mt=e=>e.charCodeAt(0)===65279?e.slice(1):e;function J(e){return{id:e.id,label:e.label,labelKey:e.labelKey,icon:e.icon,match:e.match,editor:e.editor,decode(t,n){return e.select(O(t[0].text).value,n)},encode(t,n,s){const i=n[0].text,r=O(i).value,o=e.assign(r,t,s);return{files:[{path:n[0].path,text:X(i,o,{arrayKey:e.arrayKey})}]}}}}const V=J({id:"json",label:"JSON",labelKey:"devStudio.kind.json",icon:"code",match:e=>e.toLowerCase().endsWith(".json"),editor:"json",select:e=>e,assign:(e,t)=>t}),W={id:"text",label:"Text",labelKey:"devStudio.kind.text",icon:"file",match:()=>!0,editor:"text",decode:e=>e[0].text,encode:(e,t)=>({files:[{path:t[0].path,text:be(e,t[0].text)}]})};function xe(e,t){return e.find(n=>n.match(t))??(V.match(t)?V:W)}function Lt(e,t,n){for(const s of[V,W])if(s.match(e.path))try{const i=s.decode([e],n);return{key:`${s.id}:${e.path}`,kind:s,paths:[e.path],label:I(e.path),model:i,error:t}}catch{}return{key:`text:${e.path}`,kind:W,paths:[e.path],label:I(e.path),model:e.text,error:t}}function Pt(e,t,n,s){var l,d;const i=e.encode(t,n,s),r=new Map(n.map(a=>[a.path,a.text])),o=((l=i.files.find(a=>r.get(a.path)!==a.text))==null?void 0:l.path)??((d=i.deleted)==null?void 0:d.find(a=>r.has(a)));if(o!==void 0)throw new Error(`${I(o)} would not be stored as it is`)}function Ct(e,t,n){const s=new Map;for(const r of t){const o=xe(e,r.path),l=o.group?o.group(r.path):r.path,d=`${o.id}:${l}`,a=s.get(d)??{kind:o,group:l,files:[]};a.files.push(r),s.set(d,a)}const i=[];for(const[r,{kind:o,group:l,files:d}]of s){const a=d.map(u=>u.path).sort(),c=I(o.group?l:a[0]);try{const u=o.decode(d,n);Pt(o,u,d,n),i.push({key:r,kind:o,paths:a,label:c,model:u})}catch(u){const m=u instanceof Error?u.message:String(u);for(const h of d)i.push(Lt(h,m,n))}}return i.sort((r,o)=>r.label.localeCompare(o.label))}function Jt(e,t,n,s){const i=n.filter(d=>e.paths.includes(d.path)),r=e.kind.encode(t,i,s),o=new Map(n.map(d=>[d.path,d])),l=[];for(const d of r.files){const a=o.get(d.path);a&&a.text===d.text||l.push({type:"write",path:d.path,text:d.text,baseVersion:a==null?void 0:a.version})}for(const d of r.deleted??[]){const a=o.get(d);a&&l.push({type:"delete",path:d,baseVersion:a.version})}return l}function Fe(e,t){try{return JSON.parse(Mt(e))}catch{return t}}const j=e=>typeof e=="object"&&e!==null&&!Array.isArray(e),w=(...e)=>t=>{const n=t.toLowerCase();return e.some(s=>n.endsWith(s.toLowerCase()))};function D(e){return J({id:e.id,label:e.label,labelKey:e.labelKey,icon:e.icon,editor:e.editor,match:e.match,select:t=>{if(Array.isArray(t))return t;const n=j(t)?t[e.property]:void 0;return Array.isArray(n)?n:[]},assign:(t,n)=>Array.isArray(t)?n:j(t)&&!(e.property in t)&&n.length===0?t:{...j(t)?t:{},[e.property]:n},arrayKey:e.itemKey?()=>e.itemKey:void 0})}function ae(e){const t=D(e);return{...t,decode:(n,s)=>t.decode(n,s).map((i,r)=>e.toItem(i,r)),encode:(n,s,i)=>t.encode(n.map(r=>e.fromItem(r)),s,i)}}function R(e){return J({...e,select:t=>j(t)?t:{},assign:(t,n)=>n})}const Dt=/^(.*)\.([a-z]{2,3}(?:-[A-Za-z]{2,4})?)\.i18n\.json$/i,Rt=e=>{const t=Dt.exec(e);return t?{group:t[1],locale:t[2]}:null},te=e=>j(e)&&Object.values(e).every(t=>typeof t=="string");function Te(e){if(j(e)){for(const t of["translations","keys"])if(t in e){if(te(e[t]))return e[t];throw new Error(`"${t}" is not a flat map of texts`)}if(te(e))return e}throw new Error("no translations in this file")}function ne(e,t){return j(e)?j(e.translations)?{...e,translations:t}:j(e.keys)?{...e,keys:t}:te(e)?t:{...e,translations:t}:{translations:t}}function Me(e={}){const t=e.parse??Rt,n=e.pathFor??((s,i)=>`${s}.${i}.i18n.json`);return{id:e.id??"i18n",label:e.label??"Translations",labelKey:e.labelKey??"devStudio.kind.i18n",icon:"globe",editor:"i18n",match:s=>t(s)!==null,group:s=>{var i;return((i=t(s))==null?void 0:i.group)??s},decode(s){const i={};for(const r of s){const o=t(r.path);o&&(i[o.locale]={...Te(O(r.text).value)})}return i},encode(s,i){const r=new Map;let o="";for(const c of i){const u=t(c.path);u&&(r.set(u.locale,c),o=u.group)}const l=r.get("en")??i[0],d=[];for(const[c,u]of Object.entries(s)){const m=r.get(c);if(m){const b=O(m.text).value;d.push({path:m.path,text:X(m.text,ne(b,u))});continue}const h=n(o||I((l==null?void 0:l.path)??"module"),c);if(l){const b=O(l.text).value,p=j(b)&&"locale"in b?{...b,locale:c}:b;d.push({path:h,text:$(ne(p,u),H(l.text))})}else d.push({path:h,text:$({locale:c,translations:u})})}const a=[...r.entries()].filter(([c])=>!(c in s)).map(([,c])=>c.path);return{files:d,deleted:a}}}}const K=e=>typeof e=="object"&&e!==null&&!Array.isArray(e),Le=["frontend","backend","noCode","sql"],qt=["preInstall","postInstall","preUninstall","postUninstall"];function Pe(e){switch(e){case"frontend":return["typescript","javascript"];case"backend":return["csharp","javascript"];case"sql":return["sql"];case"noCode":return[]}}const _t=new Set(["read","filter","map","aggregate","set","if","forEach","write","callScript","return"]),Ce=e=>Array.isArray(e)&&e.every(t=>K(t)&&typeof t.id=="string"&&_t.has(String(t.type)));function z(e){if(Le.includes(e.kind))return e.kind;if(e.source===void 0&&Ce(e.steps))return"noCode";const t=typeof e.language=="string"?e.language.toLowerCase():"";return t.endsWith("sql")||e.source===void 0&&typeof e.sql=="string"?"sql":/^(csharp|c#|cs\b)/.test(t)?"backend":"frontend"}const Je=["id","displayName","description","language","category","trigger","returnType","source","sourcePath"],Ut=e=>Array.isArray(e)&&e.every(t=>K(t)&&typeof t.name=="string");function De(e,t){const n=`#${t+1}`;if(!K(e)||typeof e.name!="string"||!e.name){const l=K(e)&&typeof e.displayName=="string"?e.displayName:n;return{key:`#${t}`,label:l,rawReason:"no name",source:e}}const s=e.name,i=typeof e.displayName=="string"&&e.displayName?e.displayName:s,r=l=>({key:s,label:i,rawReason:l,source:e}),o={name:s,kind:z(e)};for(const l of Je){const d=e[l];if(d!==void 0){if(typeof d!="string")return r(`"${l}" is not text`);o[l]=d}}if(e.parameters!==void 0){if(!Ut(e.parameters))return r('"parameters" is not a list of named parameters');o.parameters=e.parameters}if(o.kind==="noCode"){if(e.steps!==void 0&&!Ce(e.steps))return r('"steps" are not no-code steps');o.steps=e.steps??[]}return{key:s,label:i,definition:o,source:e}}function Re(e){const t=e.definition;if(!t)return e.source;const n=K(e.source)?e.source:{},s={...n,name:t.name};for(const i of Je)t[i]===void 0?delete s[i]:s[i]=t[i];return t.parameters===void 0?delete s.parameters:s.parameters=t.parameters,t.kind==="noCode"?s.steps=t.steps??[]:z(n)==="noCode"&&delete s.steps,delete s.kind,("kind"in n||z(s)!==t.kind)&&(s.kind=t.kind),s}function Z(e){const t=new Set;return e.map((n,s)=>{const i=De(n,s);return t.has(i.key)&&(i.key=`${i.key}#${s}`),t.add(i.key),i})}function ue(e,t){if(!K(e)||!Object.values(e).every(n=>Array.isArray(n)&&n.every(s=>typeof s=="string")))throw new Error(`"${t}" is not lists of SQL statements per phase`);return e}function qe(e){const t=e.property??"scripts",n=e.phasesProperty??"phases",s=t===n,i=r=>r.scripts.map(Re);return J({id:e.id??"scripts",label:e.label??"Scripts",labelKey:e.labelKey??"devStudio.kind.scripts",icon:e.icon??"code",editor:"scriptList",match:e.match,select:r=>{if(Array.isArray(r))return{scripts:Z(r),...s?{holds:"scripts"}:{}};if(!K(r)||r[t]===void 0&&r[n]===void 0)throw new Error(`no "${t}" in this file`);const o=r[t];if(s)return Array.isArray(o)?{scripts:Z(o),holds:"scripts"}:{scripts:[],phases:ue(o,t),holds:"phases"};if(o!==void 0&&!Array.isArray(o))throw new Error(`"${t}" is not a list`);const l=r[n];return{scripts:Z(o??[]),...l!==void 0?{phases:ue(l,n)}:{}}},assign:(r,o)=>{if(o.holds==="phases"&&o.scripts.length>0)throw new Error("This file holds database scripts only; add scripts to another file.");if(Array.isArray(r)&&o.phases===void 0)return i(o);const l=K(r)?r:{};if(s)return{...l,[t]:o.holds==="phases"?o.phases??{}:i(o)};const d={...l};return(t in l||o.scripts.length>0)&&(d[t]=i(o)),o.phases===void 0?delete d[n]:d[n]=o.phases,d},arrayKey:r=>r===`/${t}`?"name":void 0})}function _e(e){const n=e.normalize("NFKD").replace(/[\u0300-\u036f]/g,"").split(/[^A-Za-z0-9]+/).filter(Boolean).map((s,i)=>i===0?s[0].toLowerCase()+s.slice(1):s[0].toUpperCase()+s.slice(1)).join("");return/^[A-Za-z_]/.test(n)?n:`script${n}`}function Vt(e){const t=_e(e.name),n=e.language??Pe(e.kind)[0],s={name:t,kind:e.kind,...e.name!==t?{displayName:e.name}:{},...n?{language:n}:{},...e.category?{category:e.category}:{},...e.trigger?{trigger:e.trigger}:{},parameters:[]},i=t[0].toUpperCase()+t.slice(1);switch(e.kind){case"noCode":return{...s,steps:[]};case"sql":return{...s,source:`-- ${e.name}
14
14
  SELECT 1;
15
15
  `};case"backend":return{...s,returnType:"object",source:n==="csharp"?`public static object ${i}(IDictionary<string, object> args)
16
16
  {
@@ -23,4 +23,4 @@ SELECT 1;
23
23
  }
24
24
  `:`export function ${t}() {
25
25
  }
26
- `}}}const T=e=>JSON.parse(JSON.stringify(e));function Et(e){const t=e.revisions!==!1;let n=0;const s=e.workspaces.map(o=>({meta:{id:o.id,label:o.label,description:o.description,icon:o.icon,readOnly:o.readOnly},packages:new Map((o.packages??[]).map(c=>[c.id,{...c,workspaceId:o.id}])),modules:new Map(o.modules.map(c=>[c.id,{...c,files:new Map(Object.entries(c.files).map(([d,u])=>[d,{text:u,version:++n}])),revisions:[]}]))}));let i=(e.templates??[]).map(o=>T(o));const r=o=>{const c=s.find(d=>d.meta.id===o);if(!c)throw new Error(`Unknown workspace "${o}"`);return c},a=o=>{const c=r(o.workspaceId).modules.get(o.id);if(!c)throw new Error(`Unknown module "${o.id}"`);return c},l=(o,c)=>({workspaceId:o,id:c.id,packageId:c.packageId,label:c.label??c.id,description:c.description,icon:c.icon,version:c.version,readOnly:c.readOnly||r(o).meta.readOnly,files:[...c.files.keys()].sort()}),f=(o,c)=>({path:o,text:c.text,version:String(c.version)});return{async listWorkspaces(){return s.map(o=>({...o.meta}))},async listModules(o){return[...r(o).modules.values()].map(d=>l(o,d))},async listPackages(o){const c=r(o),d=[...c.packages.values()],u=[...new Set([...c.modules.values()].map(y=>y.packageId).filter(Boolean))].filter(y=>!c.packages.has(y)).map(y=>({id:y,workspaceId:o,label:y,derived:!0}));return[...d,...u]},async readModule(o){return[...a(o).files.entries()].map(([d,u])=>f(d,u))},async writeModule(o,c){const d=a(o);if(d.readOnly||r(o.workspaceId).meta.readOnly)throw new Error(`Module "${o.id}" is read-only`);const u=c.filter(p=>p.baseVersion!==void 0).filter(p=>{const m=d.files.get(p.path);return m?String(m.version)!==p.baseVersion:!1}).map(p=>{var m;return{path:p.path,currentVersion:String((m=d.files.get(p.path))==null?void 0:m.version)}});if(u.length>0)return{ok:!1,conflicts:u};let y;if(t){const p={};for(const[m,S]of d.files)p[m]=S.text;y=`r${++n}`,d.revisions.unshift({id:y,timestamp:Date.now(),label:y,summary:c.map(m=>`${m.type} ${m.path}`).join(", "),files:p})}const g={};for(const p of c)if(p.type==="delete")d.files.delete(p.path);else{const m=++n;d.files.set(p.path,{text:p.text,version:m}),g[p.path]=String(m)}return{ok:!0,versions:g,revision:y}},async createModule(o){const c=r(o.workspaceId);if(c.meta.readOnly)throw new Error(`Workspace "${o.workspaceId}" is read-only`);if(c.modules.has(o.id))throw new Error(`Module "${o.id}" already exists`);const d={id:o.id,packageId:o.packageId,files:new Map(o.files.map(u=>[u.path,{text:u.text,version:++n}])),revisions:[]};return c.modules.set(o.id,d),l(o.workspaceId,d)},async deleteModule(o){const c=r(o.workspaceId);if(c.meta.readOnly)throw new Error(`Workspace "${o.workspaceId}" is read-only`);c.modules.delete(o.id)},async savePackage(o){return r(o.workspaceId).packages.set(o.id,{...o,derived:!1}),{...o,derived:!1}},async deletePackage(o){r(o.workspaceId).packages.delete(o.id)},async listTemplates(){return i.map(o=>T(o))},async saveTemplate(o,c){const d=(c==null?void 0:c.previousId)??o.id,u=T(o),y=i.findIndex(g=>g.id===d);return i=y>=0?i.map((g,p)=>p===y?u:g):[...i,u],T(u)},async deleteTemplate(o){i=i.filter(c=>c.id!==o)},async listRevisions(o,c){return a(o).revisions.filter(d=>!c||c in d.files).map(({files:d,...u})=>({...u,...c?{path:c}:{}}))},async readRevision(o,c,d){const u=a(o).revisions.find(y=>y.id===c);if(!u)throw new Error(`Unknown revision "${c}"`);return d?u.files[d]??"":JSON.stringify(u.files,null,2)},async rollback(o,c,d){const u=a(o),y=u.revisions.find(p=>p.id===c);if(!y)throw new Error(`Unknown revision "${c}"`);const g=d?{[d]:y.files[d]}:y.files;if(!d)for(const p of[...u.files.keys()])p in g||u.files.delete(p);for(const[p,m]of Object.entries(g))m!==void 0&&u.files.set(p,{text:m,version:++n})},snapshot(){return{workspaces:s.map(o=>({...o.meta,packages:[...o.packages.values()].map(({workspaceId:c,...d})=>d),modules:[...o.modules.values()].map(c=>({id:c.id,packageId:c.packageId,label:c.label,description:c.description,icon:c.icon,version:c.version,readOnly:c.readOnly,files:Object.fromEntries([...c.files.entries()].map(([d,u])=>[d,u.text]))}))})),templates:i.map(o=>T(o)),revisions:t}}}}function Ot(e){return e}function q(e,t){if(!t||e===void 0||e===null)return!0;if(t.enum&&!t.enum.includes(e))return!1;switch(t.type){case"string":return typeof e=="string";case"number":return typeof e=="number";case"integer":return Number.isInteger(e);case"boolean":return typeof e=="boolean";case"array":return Array.isArray(e)&&(!t.items||e.every(n=>q(n,t.items)));case"object":{if(typeof e!="object"||Array.isArray(e))return!1;const n=t.properties;return!n||Object.entries(e).every(([s,i])=>s in n&&q(i,n[s]))}default:return!0}}function At(e,t){var a;const n=(e.fields??[]).map(l=>l.name),s=(a=e.schema)==null?void 0:a.properties;if(!e.schema||!s)return{section:e,keys:n};const i=Object.entries(s).filter(([l,f])=>!(l in t)||q(t[l],f)),r=i.map(([l])=>l);return{section:{...e,schema:{...e.schema,properties:Object.fromEntries(i),...e.schema.required?{required:e.schema.required.filter(l=>r.includes(l))}:{}}},keys:[...r,...n]}}function It(e){var n;const t=new Set;for(const s of e){for(const i of Object.keys(((n=s.schema)==null?void 0:n.properties)??{}))t.add(i);for(const i of s.fields??[])t.add(i.name)}return t}function Nt(e){const t=n=>{const s=e.find(i=>i.name===n);return String((s==null?void 0:s.tableName)||(s==null?void 0:s.name)||n)};return e.map(n=>{const s=n,i=String(s.tableName||s.name||"Entity");return{name:i,...s.name&&s.name!==i?{entity:String(s.name)}:{},...typeof s.description=="string"&&s.description?{description:s.description}:{},columns:(Array.isArray(s.fields)?s.fields:[]).map(r=>{const a=typeof r.referencedEntity=="string"?r.referencedEntity:typeof r.references=="string"?r.references:void 0;return{name:String(r.name??""),dataType:String(r.dataType??r.type??"string"),isPrimaryKey:!!r.isPrimaryKey,isForeignKey:!!(r.isForeignKey??r.foreignKey??a),...a?{references:{table:t(a),column:typeof r.referencedField=="string"?r.referencedField:"Id"}}:{}}})}})}function Tt(e){const t=e.manifest??{},n=String(t.displayName||t.packageName||"Module"),s=(e.views??[]).map(r=>({id:`view:${r.id}`,label:r.name,type:"view"})),i=(e.entities??[]).map(r=>{const a=String(r.name??"Entity");return{id:`entity:${a}`,label:a,type:"entity"}});return{roles:[{id:"admin",label:"Admin"},{id:"user",label:"User"}],actions:[{id:"view",label:"View"},{id:"create",label:"Create"},{id:"edit",label:"Edit"},{id:"delete",label:"Delete"}],resources:[{id:"module",label:n,type:"module",children:[...s.length?[{id:"views",label:"Views",type:"group",children:s}]:[],...i.length?[{id:"entities",label:"Entities",type:"group",children:i}]:[]]}],grants:{}}}const z=M({id:"manifest",label:"Manifest",labelKey:"devStudio.kind.manifest",icon:"file",editor:"manifest",match:k(".manifest.json")}),Fe=C({id:"entities",label:"Entities",labelKey:"devStudio.kind.entities",icon:"database",editor:"entities",match:k(".entities.json"),property:"entities",itemKey:"name"}),xe=$e();function Le(e,t){const n=e,s=typeof e=="object"&&e!==null&&typeof n.id=="string";return{key:s?n.id:`#${t}`,label:s&&n.name||(s?n.id:`#${t+1}`),...s?{definition:n}:{rawReason:"no id"},source:e}}const Ce=ne({id:"views",label:"Views",labelKey:"devStudio.kind.views",icon:"grid",editor:"views",match:k(".views.json"),property:"views",itemKey:"id",toItem:(e,t)=>Le(e,t),fromItem:e=>e.definition??e.source}),Me=ne({id:"workflows",label:"Workflows",labelKey:"devStudio.kind.workflows",icon:"git-branch",editor:"workflows",match:k(".workflows.json"),property:"workflows",itemKey:"id",toItem:(e,t)=>Le(e,t),fromItem:e=>e.definition??e.source}),Pe=C({id:"dataSources",label:"Data sources",labelKey:"devStudio.kind.dataSources",icon:"database",editor:"dataSources",match:k(".datasources.json"),property:"dataSources",itemKey:"key"}),Je=M({id:"rbac",label:"Access",labelKey:"devStudio.kind.rbac",icon:"shield",editor:"rbac",match:k(".rbac.json")}),De=C({id:"hooks",label:"Lifecycle hooks",labelKey:"devStudio.kind.hooks",icon:"zap",editor:"hooks",match:k(".hooks.json"),property:"bindings",itemKey:"id"}),_e=M({id:"integrations",label:"Integrations",labelKey:"devStudio.kind.integrations",icon:"plug",editor:"integrations",match:k(".integrations.json")}),Re=M({id:"environments",label:"Environment sets",labelKey:"devStudio.kind.environments",icon:"globe",editor:"environments",match:k(".environments.json")}),Ue=Ne({match:k(".scripts.json")}),qe=[z,Fe,xe,Ce,Me,Pe,Je,De,Ue,_e,Re];function Y(e){return e.normalize("NFKD").replace(/[̀-ͯ]/g,"").replace(/ł/g,"l").replace(/Ł/g,"L").toLowerCase().replace(/[^a-z0-9]+/g,"-").replace(/^-+|-+$/g,"")||"module"}const re=e=>{const t=e.find(n=>z.match(n.path));return t?ve(t.text,void 0):void 0};function Ve(e){const t=e.find(n=>z.match(n.path));return t?E(t.path).replace(/\.manifest\.json$/i,""):"module"}const oe=e=>Array.isArray(e.fields)?e.fields:[],Ft={id:"native",kinds:qe,locales:["en","pl","de","fr","es","uk"],requiredLocales:["en"],moduleId:e=>{const t=re(e),n=(t==null?void 0:t.id)??(t==null?void 0:t.packageName);return typeof n=="string"?n:void 0},validateModule:({files:e})=>{const t=re(e);return t?["id","name","version"].filter(n=>typeof t[n]!="string"||!t[n]).map(n=>({severity:"error",code:"manifest.required",message:`The manifest needs "${n}".`,messageKey:"devStudio.issue.manifestRequired",params:{field:n},pointer:`/${n}`})):[{severity:"error",code:"manifest.missing",message:"The module has no manifest.",messageKey:"devStudio.issue.manifestMissing"}]},newFile:(e,{files:t})=>{const n=Ve(t),i={entities:["entities.json",{entities:[]}],views:["views.json",{views:[]}],workflows:["workflows.json",{workflows:[]}],dataSources:["datasources.json",{dataSources:[]}],rbac:["rbac.json",{roles:[],actions:[],resources:[],grants:{}}],hooks:["hooks.json",{bindings:[]}],scripts:["scripts.json",{scripts:[]}],integrations:["integrations.json",{integrations:[]}],environments:["environments.json",{variables:[],sets:[]}]}[e];return i?{path:`${n}.${i[0]}`,text:v(i[1])}:void 0},generateModule:async(e,{existingIds:t})=>{let n=Y(e.name);for(let i=2;t.has(n);i++)n=`${Y(e.name)}-${i}`;const s=[{path:`${n}.manifest.json`,text:v({id:n,name:e.name,version:"1.0.0",...e.description?{description:e.description}:{},...e.icon?{icon:e.icon}:{},...e.packageId?{category:e.packageId}:{}})},{path:`${n}.entities.json`,text:v({entities:e.entities})}];for(const i of e.locales){const r={"module.displayName":e.name};for(const a of e.entities){const l=String(a.name??"");r[`entity.${l}.displayName`]=l;for(const f of oe(a))r[`field.${l}.${String(f.name)}.label`]=String(f.name)}s.push({path:`${n}.${i}.i18n.json`,text:v({locale:i,translations:r})})}if(e.views){const i=e.entities.map(r=>{const a=String(r.name??"Item");return{id:`${a}List`,name:`${a} list`,kind:"grid",version:2,columns:12,dataSources:[{key:"rows",type:"entity",entity:a,autoLoad:!0}],rows:[{id:"r1",cells:[{id:"grid",controlType:"dataGrid",colSpan:12,props:{columns:oe(r).map(l=>({field:String(l.name),header:String(l.name)}))},bindings:{data:{source:"rows",field:""}}}]}]}});s.push({path:`${n}.views.json`,text:v({views:i})})}if(e.permissions){const i={roles:[{id:"viewer",label:"Viewer"},{id:"editor",label:"Editor"},{id:"admin",label:"Admin"}],actions:[{id:"view",label:"View"},{id:"edit",label:"Edit"},{id:"delete",label:"Delete"}],resources:e.entities.map(r=>({id:`entity:${String(r.name)}`,label:String(r.name),type:"entity"})),grants:{}};s.push({path:`${n}.rbac.json`,text:v(i)})}return{id:n,packageId:e.packageId,files:s}}};exports.NICE_STUDIO_SCRIPT_KINDS=je;exports.NICE_STUDIO_SCRIPT_PHASES=wt;exports.addStudioFolder=tt;exports.addStudioSection=et;exports.arrayFileKind=C;exports.buildDocuments=bt;exports.createMemoryStudioProvider=Et;exports.defineManifestSection=Ot;exports.deriveDefaultRbac=Tt;exports.detectJsonTextFormat=V;exports.emptyStudioLayout=P;exports.encodeDocument=St;exports.endsWithAny=k;exports.entitiesToSchemas=Nt;exports.fileName=E;exports.fitManifestSection=At;exports.fromStudioScriptItem=Ie;exports.i18nFileKind=$e;exports.inferStudioScriptKind=U;exports.isEmptyStudioLayout=Ge;exports.isStudioLayoutPath=ae;exports.itemsFileKind=ne;exports.jsonFallbackKind=_;exports.jsonFileKind=L;exports.jsonValueFitsSchema=q;exports.jsonValuesEqual=F;exports.keepTextFormat=fe;exports.manifestSectionKeys=It;exports.modulePrefix=Ve;exports.nativeDataSourcesKind=Pe;exports.nativeEntitiesKind=Fe;exports.nativeEnvironmentsKind=Re;exports.nativeFileKinds=qe;exports.nativeHooksKind=De;exports.nativeI18nKind=xe;exports.nativeIntegrationsKind=_e;exports.nativeManifestKind=z;exports.nativeRbacKind=Je;exports.nativeScriptsKind=Ue;exports.nativeStudioPreset=Ft;exports.nativeViewsKind=Ce;exports.nativeWorkflowsKind=Me;exports.newStudioScript=Kt;exports.objectFileKind=M;exports.parseJsonText=O;exports.parseStudioLayout=Ze;exports.patchJsonText=Q;exports.patchJsonTextDetailed=ue;exports.placeStudioEntry=it;exports.readTranslations=we;exports.removeStudioLayoutNode=st;exports.renameStudioEntryRef=rt;exports.renameStudioLayoutNode=nt;exports.resolveFileKind=ke;exports.safeJson=ve;exports.scriptsFileKind=Ne;exports.serializeStudioLayout=Ye;exports.slugifyModuleId=Y;exports.stringifyJsonText=v;exports.studioEntryRef=Be;exports.studioLayoutPath=Xe;exports.studioScriptIdentifier=Te;exports.studioScriptLanguages=Ke;exports.textFallbackKind=R;exports.toStudioScriptItem=Ae;exports.writeTranslations=G;
26
+ `}}}const M=e=>JSON.parse(JSON.stringify(e));function Wt(e){const t=e.revisions!==!1;let n=0;const s=e.workspaces.map(a=>({meta:{id:a.id,label:a.label,description:a.description,icon:a.icon,readOnly:a.readOnly},packages:new Map((a.packages??[]).map(c=>[c.id,{...c,workspaceId:a.id}])),modules:new Map(a.modules.map(c=>[c.id,{...c,files:new Map(Object.entries(c.files).map(([u,m])=>[u,{text:m,version:++n}])),revisions:[]}]))}));let i=(e.templates??[]).map(a=>M(a));const r=a=>{const c=s.find(u=>u.meta.id===a);if(!c)throw new Error(`Unknown workspace "${a}"`);return c},o=a=>{const c=r(a.workspaceId).modules.get(a.id);if(!c)throw new Error(`Unknown module "${a.id}"`);return c},l=(a,c)=>({workspaceId:a,id:c.id,packageId:c.packageId,label:c.label??c.id,description:c.description,icon:c.icon,version:c.version,readOnly:c.readOnly||r(a).meta.readOnly,files:[...c.files.keys()].sort()}),d=(a,c)=>({path:a,text:c.text,version:String(c.version)});return{async listWorkspaces(){return s.map(a=>({...a.meta}))},async listModules(a){return[...r(a).modules.values()].map(u=>l(a,u))},async listPackages(a){const c=r(a),u=[...c.packages.values()],m=[...new Set([...c.modules.values()].map(h=>h.packageId).filter(Boolean))].filter(h=>!c.packages.has(h)).map(h=>({id:h,workspaceId:a,label:h,derived:!0}));return[...u,...m]},async readModule(a){return[...o(a).files.entries()].map(([u,m])=>d(u,m))},async writeModule(a,c){const u=o(a);if(u.readOnly||r(a.workspaceId).meta.readOnly)throw new Error(`Module "${a.id}" is read-only`);const m=c.filter(p=>p.baseVersion!==void 0).filter(p=>{const f=u.files.get(p.path);return f?String(f.version)!==p.baseVersion:!1}).map(p=>{var f;return{path:p.path,currentVersion:String((f=u.files.get(p.path))==null?void 0:f.version)}});if(m.length>0)return{ok:!1,conflicts:m};let h;if(t){const p={};for(const[f,y]of u.files)p[f]=y.text;h=`r${++n}`,u.revisions.unshift({id:h,timestamp:Date.now(),label:h,summary:c.map(f=>`${f.type} ${f.path}`).join(", "),files:p})}const b={};for(const p of c)if(p.type==="delete")u.files.delete(p.path);else{const f=++n;u.files.set(p.path,{text:p.text,version:f}),b[p.path]=String(f)}return{ok:!0,versions:b,revision:h}},async createModule(a){const c=r(a.workspaceId);if(c.meta.readOnly)throw new Error(`Workspace "${a.workspaceId}" is read-only`);if(c.modules.has(a.id))throw new Error(`Module "${a.id}" already exists`);const u={id:a.id,packageId:a.packageId,files:new Map(a.files.map(m=>[m.path,{text:m.text,version:++n}])),revisions:[]};return c.modules.set(a.id,u),l(a.workspaceId,u)},async deleteModule(a){const c=r(a.workspaceId);if(c.meta.readOnly)throw new Error(`Workspace "${a.workspaceId}" is read-only`);c.modules.delete(a.id)},async savePackage(a){return r(a.workspaceId).packages.set(a.id,{...a,derived:!1}),{...a,derived:!1}},async deletePackage(a){r(a.workspaceId).packages.delete(a.id)},async listTemplates(){return i.map(a=>M(a))},async saveTemplate(a,c){const u=(c==null?void 0:c.previousId)??a.id,m=M(a),h=i.findIndex(b=>b.id===u);return i=h>=0?i.map((b,p)=>p===h?m:b):[...i,m],M(m)},async deleteTemplate(a){i=i.filter(c=>c.id!==a)},async listRevisions(a,c){return o(a).revisions.filter(u=>!c||c in u.files).map(({files:u,...m})=>({...m,...c?{path:c}:{}}))},async readRevision(a,c,u){const m=o(a).revisions.find(h=>h.id===c);if(!m)throw new Error(`Unknown revision "${c}"`);return u?m.files[u]??"":JSON.stringify(m.files,null,2)},async rollback(a,c,u){const m=o(a),h=m.revisions.find(p=>p.id===c);if(!h)throw new Error(`Unknown revision "${c}"`);const b=u?{[u]:h.files[u]}:h.files;if(!u)for(const p of[...m.files.keys()])p in b||m.files.delete(p);for(const[p,f]of Object.entries(b))f!==void 0&&m.files.set(p,{text:f,version:++n})},snapshot(){return{workspaces:s.map(a=>({...a.meta,packages:[...a.packages.values()].map(({workspaceId:c,...u})=>u),modules:[...a.modules.values()].map(c=>({id:c.id,packageId:c.packageId,label:c.label,description:c.description,icon:c.icon,version:c.version,readOnly:c.readOnly,files:Object.fromEntries([...c.files.entries()].map(([u,m])=>[u,m.text]))}))})),templates:i.map(a=>M(a)),revisions:t}}}}function zt(e){return e}function B(e,t){if(!t||e===void 0||e===null)return!0;if(t.enum&&!t.enum.includes(e))return!1;switch(t.type){case"string":return typeof e=="string";case"number":return typeof e=="number";case"integer":return Number.isInteger(e);case"boolean":return typeof e=="boolean";case"array":return Array.isArray(e)&&(!t.items||e.every(n=>B(n,t.items)));case"object":{if(typeof e!="object"||Array.isArray(e))return!1;const n=t.properties;return!n||Object.entries(e).every(([s,i])=>s in n&&B(i,n[s]))}default:return!0}}function Bt(e,t){var o;const n=(e.fields??[]).map(l=>l.name),s=(o=e.schema)==null?void 0:o.properties;if(!e.schema||!s)return{section:e,keys:n};const i=Object.entries(s).filter(([l,d])=>!(l in t)||B(t[l],d)),r=i.map(([l])=>l);return{section:{...e,schema:{...e.schema,properties:Object.fromEntries(i),...e.schema.required?{required:e.schema.required.filter(l=>r.includes(l))}:{}}},keys:[...r,...n]}}function Ht(e){var n;const t=new Set;for(const s of e){for(const i of Object.keys(((n=s.schema)==null?void 0:n.properties)??{}))t.add(i);for(const i of s.fields??[])t.add(i.name)}return t}function Xt(e){const t=n=>{const s=e.find(i=>i.name===n);return String((s==null?void 0:s.tableName)||(s==null?void 0:s.name)||n)};return e.map(n=>{const s=n,i=String(s.tableName||s.name||"Entity");return{name:i,...s.name&&s.name!==i?{entity:String(s.name)}:{},...typeof s.description=="string"&&s.description?{description:s.description}:{},columns:(Array.isArray(s.fields)?s.fields:[]).map(r=>{const o=typeof r.referencedEntity=="string"?r.referencedEntity:typeof r.references=="string"?r.references:void 0;return{name:String(r.name??""),dataType:String(r.dataType??r.type??"string"),isPrimaryKey:!!r.isPrimaryKey,isForeignKey:!!(r.isForeignKey??r.foreignKey??o),...o?{references:{table:t(o),column:typeof r.referencedField=="string"?r.referencedField:"Id"}}:{}}})}})}function Qt(e){const t=e.manifest??{},n=String(t.displayName||t.packageName||"Module"),s=(e.views??[]).map(r=>({id:`view:${r.id}`,label:r.name,type:"view"})),i=(e.entities??[]).map(r=>{const o=String(r.name??"Entity");return{id:`entity:${o}`,label:o,type:"entity"}});return{roles:[{id:"admin",label:"Admin"},{id:"user",label:"User"}],actions:[{id:"view",label:"View"},{id:"create",label:"Create"},{id:"edit",label:"Edit"},{id:"delete",label:"Delete"}],resources:[{id:"module",label:n,type:"module",children:[...s.length?[{id:"views",label:"Views",type:"group",children:s}]:[],...i.length?[{id:"entities",label:"Entities",type:"group",children:i}]:[]]}],grants:{}}}const Q=R({id:"manifest",label:"Manifest",labelKey:"devStudio.kind.manifest",icon:"file",editor:"manifest",match:w(".manifest.json")}),Ue=D({id:"entities",label:"Entities",labelKey:"devStudio.kind.entities",icon:"database",editor:"entities",match:w(".entities.json"),property:"entities",itemKey:"name"}),Ve=Me();function We(e,t){const n=e,s=typeof e=="object"&&e!==null&&typeof n.id=="string";return{key:s?n.id:`#${t}`,label:s&&n.name||(s?n.id:`#${t+1}`),...s?{definition:n}:{rawReason:"no id"},source:e}}const ze=ae({id:"views",label:"Views",labelKey:"devStudio.kind.views",icon:"grid",editor:"views",match:w(".views.json"),property:"views",itemKey:"id",toItem:(e,t)=>We(e,t),fromItem:e=>e.definition??e.source}),Be=ae({id:"workflows",label:"Workflows",labelKey:"devStudio.kind.workflows",icon:"git-branch",editor:"workflows",match:w(".workflows.json"),property:"workflows",itemKey:"id",toItem:(e,t)=>We(e,t),fromItem:e=>e.definition??e.source}),He=D({id:"dataSources",label:"Data sources",labelKey:"devStudio.kind.dataSources",icon:"database",editor:"dataSources",match:w(".datasources.json"),property:"dataSources",itemKey:"key"}),Xe=R({id:"rbac",label:"Access",labelKey:"devStudio.kind.rbac",icon:"shield",editor:"rbac",match:w(".rbac.json")}),Qe=D({id:"hooks",label:"Lifecycle hooks",labelKey:"devStudio.kind.hooks",icon:"zap",editor:"hooks",match:w(".hooks.json"),property:"bindings",itemKey:"id"}),Ze=R({id:"integrations",label:"Integrations",labelKey:"devStudio.kind.integrations",icon:"plug",editor:"integrations",match:w(".integrations.json")}),Ge=R({id:"environments",label:"Environment sets",labelKey:"devStudio.kind.environments",icon:"globe",editor:"environments",match:w(".environments.json")}),Ye=qe({match:w(".scripts.json")}),et=[Q,Ue,Ve,ze,Be,He,Xe,Qe,Ye,Ze,Ge];function se(e){return e.normalize("NFKD").replace(/[̀-ͯ]/g,"").replace(/ł/g,"l").replace(/Ł/g,"L").toLowerCase().replace(/[^a-z0-9]+/g,"-").replace(/^-+|-+$/g,"")||"module"}const ie=e=>{const t=e.find(n=>Q.match(n.path));return t?Fe(t.text,void 0):void 0};function tt(e){const t=e.find(n=>Q.match(n.path));return t?I(t.path).replace(/\.manifest\.json$/i,""):"module"}const pe=e=>Array.isArray(e.fields)?e.fields:[],ce={entity:[{prop:"references",part:"tail",files:/\.entities\.json$/i},{prop:"entity",files:/\.views\.json$/i},{value:"{name}All",files:/\.(views|scripts|datasources)\.json$/i},{value:"{name}ById",files:/\.(views|scripts|datasources)\.json$/i},{prop:"entityType",files:/\.workflows\.json$/i},{prop:"name",within:"tables",table:!0,files:/\.datasources\.json$/i},{prop:"id",prefix:"entity:",within:"resources",files:/\.rbac\.json$/i},{prop:"id",prefix:"entity:",within:"children",files:/\.rbac\.json$/i},{prop:"label",within:"resources",files:/\.rbac\.json$/i},{keysOf:"grants",prefix:"entity:",files:/\.rbac\.json$/i},{keyPattern:"entity.{name}."},{keyPattern:"field.{name}."},{prop:"target",files:/\.scripts\.json$/i},{prop:"target",within:"operations",files:/\.integrations\.json$/i},{prop:"source",within:"operations",files:/\.integrations\.json$/i}],dataSource:[{prop:"ref",files:/\.views\.json$/i},{prop:"source",files:/\.scripts\.json$/i},{prop:"target",files:/\.scripts\.json$/i},{prop:"sources",files:/\.datasources\.json$/i},{prop:"source",within:"operations",files:/\.integrations\.json$/i}]};function Zt(e,t){const n=ie(t),s=[e.id,n==null?void 0:n.id,n==null?void 0:n.packageName].filter(r=>typeof r=="string"&&r!==""),i=[];for(const r of Array.isArray(n==null?void 0:n.dependencies)?n.dependencies:[])if(typeof r=="string"&&r)i.push({id:r,via:"manifest"});else if(r&&typeof r=="object"&&typeof r.moduleId=="string"){const o=r;i.push({id:o.moduleId,via:"manifest",...typeof o.required=="boolean"?{required:o.required}:{},...typeof o.minVersion=="string"?{minVersion:o.minVersion}:{}})}return Ne(i,t,ce.entity??[],s)}const Gt={id:"native",references:ce,dependencies:e=>Zt(e.key,e.files),kinds:et,locales:["en","pl","de","fr","es","uk"],requiredLocales:["en"],moduleId:e=>{const t=ie(e),n=(t==null?void 0:t.id)??(t==null?void 0:t.packageName);return typeof n=="string"?n:void 0},validateModule:({files:e})=>{const t=ie(e);return t?["id","name","version"].filter(n=>typeof t[n]!="string"||!t[n]).map(n=>({severity:"error",code:"manifest.required",message:`The manifest needs "${n}".`,messageKey:"devStudio.issue.manifestRequired",params:{field:n},pointer:`/${n}`})):[{severity:"error",code:"manifest.missing",message:"The module has no manifest.",messageKey:"devStudio.issue.manifestMissing"}]},newFile:(e,{files:t})=>{const n=tt(t),i={entities:["entities.json",{entities:[]}],views:["views.json",{views:[]}],workflows:["workflows.json",{workflows:[]}],dataSources:["datasources.json",{dataSources:[]}],rbac:["rbac.json",{roles:[],actions:[],resources:[],grants:{}}],hooks:["hooks.json",{bindings:[]}],scripts:["scripts.json",{scripts:[]}],integrations:["integrations.json",{integrations:[]}],environments:["environments.json",{variables:[],sets:[]}]}[e];return i?{path:`${n}.${i[0]}`,text:$(i[1])}:void 0},generateModule:async(e,{existingIds:t})=>{let n=se(e.name);for(let i=2;t.has(n);i++)n=`${se(e.name)}-${i}`;const s=[{path:`${n}.manifest.json`,text:$({id:n,name:e.name,version:"1.0.0",...e.description?{description:e.description}:{},...e.icon?{icon:e.icon}:{},...e.packageId?{category:e.packageId}:{}})},{path:`${n}.entities.json`,text:$({entities:e.entities})}];for(const i of e.locales){const r={"module.displayName":e.name};for(const o of e.entities){const l=String(o.name??"");r[`entity.${l}.displayName`]=l;for(const d of pe(o))r[`field.${l}.${String(d.name)}.label`]=String(d.name)}s.push({path:`${n}.${i}.i18n.json`,text:$({locale:i,translations:r})})}if(e.views){const i=e.entities.map(r=>{const o=String(r.name??"Item");return{id:`${o}List`,name:`${o} list`,kind:"grid",version:2,columns:12,dataSources:[{key:"rows",type:"entity",entity:o,autoLoad:!0}],rows:[{id:"r1",cells:[{id:"grid",controlType:"dataGrid",colSpan:12,props:{columns:pe(r).map(l=>({field:String(l.name),header:String(l.name)}))},bindings:{data:{source:"rows",field:""}}}]}]}});s.push({path:`${n}.views.json`,text:$({views:i})})}if(e.permissions){const i={roles:[{id:"viewer",label:"Viewer"},{id:"editor",label:"Editor"},{id:"admin",label:"Admin"}],actions:[{id:"view",label:"View"},{id:"edit",label:"Edit"},{id:"delete",label:"Delete"}],resources:e.entities.map(r=>({id:`entity:${String(r.name)}`,label:String(r.name),type:"entity"})),grants:{}};s.push({path:`${n}.rbac.json`,text:$(i)})}return{id:n,packageId:e.packageId,files:s}}};exports.NICE_STUDIO_SCRIPT_KINDS=Le;exports.NICE_STUDIO_SCRIPT_PHASES=qt;exports.addStudioFolder=ut;exports.addStudioSection=ft;exports.arrayFileKind=D;exports.buildDocuments=Ct;exports.createMemoryStudioProvider=Wt;exports.defineManifestSection=zt;exports.deriveDefaultRbac=Qt;exports.detectJsonTextFormat=H;exports.emptyStudioLayout=q;exports.encodeDocument=Jt;exports.endsWithAny=w;exports.entitiesToSchemas=Xt;exports.fileName=I;exports.findStudioReferences=Tt;exports.fitManifestSection=Bt;exports.fromStudioScriptItem=Re;exports.i18nFileKind=Me;exports.inferStudioScriptKind=z;exports.isEmptyStudioLayout=ct;exports.isStudioFolderWithin=Y;exports.isStudioLayoutPath=me;exports.itemsFileKind=ae;exports.jsonFallbackKind=V;exports.jsonFileKind=J;exports.jsonValueFitsSchema=B;exports.jsonValuesEqual=P;exports.keepTextFormat=be;exports.manifestSectionKeys=Ht;exports.modulePrefix=tt;exports.moveStudioFolder=bt;exports.nativeDataSourcesKind=He;exports.nativeEntitiesKind=Ue;exports.nativeEnvironmentsKind=Ge;exports.nativeFileKinds=et;exports.nativeHooksKind=Qe;exports.nativeI18nKind=Ve;exports.nativeIntegrationsKind=Ze;exports.nativeManifestKind=Q;exports.nativeRbacKind=Xe;exports.nativeScriptsKind=Ye;exports.nativeStudioPreset=Gt;exports.nativeStudioReferences=ce;exports.nativeViewsKind=ze;exports.nativeWorkflowsKind=Be;exports.newStudioScript=Vt;exports.objectFileKind=R;exports.orderStudioEntries=gt;exports.parseJsonText=O;exports.parseStudioLayout=at;exports.patchJsonText=X;exports.patchJsonTextDetailed=ve;exports.placeStudioEntry=yt;exports.readTranslations=Te;exports.removeStudioLayoutNode=mt;exports.renameStudioEntryRef=vt;exports.renameStudioLayoutNode=pt;exports.renameStudioReferences=Ae;exports.resolveFileKind=xe;exports.safeJson=Fe;exports.scriptsFileKind=qe;exports.serializeStudioLayout=lt;exports.slugifyModuleId=se;exports.stringifyJsonText=$;exports.studioDependencies=Ne;exports.studioEntryRef=it;exports.studioLayoutPath=ot;exports.studioQualifiedReferences=Ie;exports.studioScriptIdentifier=_e;exports.studioScriptLanguages=Pe;exports.textFallbackKind=W;exports.toStudioScriptItem=De;exports.writeTranslations=ne;
package/dist/studio.d.ts CHANGED
@@ -71,6 +71,15 @@ export declare function entitiesToSchemas(entities: readonly Row_2[]): NiceDataS
71
71
  /** The file name of a path. */
72
72
  export declare const fileName: (path: string) => string;
73
73
 
74
+ /**
75
+ * The files that refer to `name` by `rules`, with how many references each holds — what a rename
76
+ * would rewrite.
77
+ */
78
+ export declare function findStudioReferences(files: readonly NiceStudioTextFile[], rules: readonly NiceStudioReferenceRule[], name: string, options?: NiceStudioRenameOptions): Array<{
79
+ path: string;
80
+ count: number;
81
+ }>;
82
+
74
83
  /**
75
84
  * A section narrowed to the properties a form can edit in this manifest: a value that does not fit
76
85
  * its property's schema ({@link jsonValueFitsSchema}) leaves the section and is edited as JSON
@@ -165,6 +174,9 @@ export declare function inferStudioScriptKind(raw: Row): NiceStudioScriptKind;
165
174
  /** Whether a layout holds nothing (its file can go). */
166
175
  export declare const isEmptyStudioLayout: (layout: NiceStudioLayout) => boolean;
167
176
 
177
+ /** Whether folder `id` is `ancestor` or sits, at any depth, inside it. */
178
+ export declare function isStudioFolderWithin(layout: NiceStudioLayout, id: string, ancestor: string): boolean;
179
+
168
180
  /** Whether a path is a module's layout file. */
169
181
  export declare const isStudioLayoutPath: (path: string) => boolean;
170
182
 
@@ -227,6 +239,17 @@ export declare function manifestSectionKeys(sections: readonly NiceManifestSecti
227
239
  /** The prefix a module's files share (`orders` of `orders.manifest.json`). */
228
240
  export declare function modulePrefix(files: readonly NiceStudioFile[]): string;
229
241
 
242
+ /**
243
+ * The layout with a folder moved (1.4.14): into another folder of its group (its section follows that
244
+ * folder's), into a section, or to its group's top (`{}`). The folders and entries inside it come
245
+ * along into the same section. A move into itself or a folder inside it, or into a folder of another
246
+ * group, leaves the layout as it was.
247
+ */
248
+ export declare function moveStudioFolder(layout: NiceStudioLayout, folderId: string, target: {
249
+ parent?: string;
250
+ section?: string;
251
+ }): NiceStudioLayout;
252
+
230
253
  export declare const nativeDataSourcesKind: NiceStudioFileKind<NiceDataSourceDef[]>;
231
254
 
232
255
  export declare const nativeEntitiesKind: NiceStudioFileKind<Row_3[]>;
@@ -257,6 +280,17 @@ export declare const nativeScriptsKind: NiceStudioFileKind<NiceStudioScripts>;
257
280
  /** The studio's own format: manifest, entities, translations, views, workflows, data sources, access, hooks, scripts. */
258
281
  export declare const nativeStudioPreset: NiceStudioPreset;
259
282
 
283
+ /**
284
+ * Where the native files refer to an entity or a data source by name (1.4.15):
285
+ * - entities: a field's `references`, a view's data source `entity` and the standard sources
286
+ * `{name}All` / `{name}ById`, a workflow's `entityType`, a data source's tables (an entity without
287
+ * `tableName`), access resources (`entity:{name}`) and their grants, translation keys, a no-code
288
+ * script's `target`, an integration operation's `source` / `target`;
289
+ * - data source keys: a view's `ref`, a script's `source` / `target`, a union's `sources`, an
290
+ * integration operation's `source`.
291
+ */
292
+ export declare const nativeStudioReferences: NiceStudioReferenceRules;
293
+
260
294
  export declare const nativeViewsKind: NiceStudioFileKind<NiceStudioItem<NiceViewDefinition>[]>;
261
295
 
262
296
  export declare const nativeWorkflowsKind: NiceStudioFileKind<NiceStudioItem<NiceWorkflowDefinition>[]>;
@@ -462,6 +496,21 @@ export declare interface NiceStudioCodecContext {
462
496
  locales: readonly string[];
463
497
  }
464
498
 
499
+ /** A module another module depends on (1.4.15 — the tree's Dependencies group, OmniVerk wishlist #1). */
500
+ export declare interface NiceStudioDependency {
501
+ /** The module it names: its id or package name. */
502
+ id: string;
503
+ /** Needed (`true`) or optional (`false`); unknown when absent. */
504
+ required?: boolean;
505
+ /** Why the module needs it. */
506
+ reason?: string;
507
+ minVersion?: string;
508
+ /** Declared in the manifest, or only referred to (a field of an entity of that module). */
509
+ via: 'manifest' | 'reference';
510
+ /** The entities of that module the files refer to. */
511
+ refers?: string[];
512
+ }
513
+
465
514
  /** A document of an open module: the files one editor works on. */
466
515
  export declare interface NiceStudioDocument<M = unknown> {
467
516
  /** Stable within the module: `${kind.id}:${group}`. */
@@ -801,6 +850,13 @@ export declare interface NiceStudioPreset {
801
850
  requiredLocales?: string[];
802
851
  /** The module's id from its files (e.g. the manifest's `packageName`). */
803
852
  moduleId?(files: readonly NiceStudioFile[]): string | undefined;
853
+ /**
854
+ * Where the module's files refer to an entity or a data source by name (1.4.15): renaming one in
855
+ * the studio rewrites these places too. Without it, a rename changes only the entity itself.
856
+ */
857
+ references?: NiceStudioReferenceRules;
858
+ /** The modules a module depends on, for the tree's Dependencies group (1.4.15). */
859
+ dependencies?(ctx: NiceStudioModuleContext): NiceStudioDependency[];
804
860
  validateModule?(ctx: NiceStudioModuleContext): NiceStudioIssue[];
805
861
  generateModule?(spec: NiceStudioModuleSpec, ctx: {
806
862
  existingIds: ReadonlySet<string>;
@@ -876,6 +932,71 @@ export declare interface NiceStudioProvider {
876
932
  rollback?(key: NiceStudioModuleKey, revisionId: string, path?: string): Promise<void>;
877
933
  }
878
934
 
935
+ /** One kind of place a name is referred to in a module's files. */
936
+ export declare type NiceStudioReferenceRule = {
937
+ /** A property, at any depth, whose string value (or each string of its array) holds the name. */
938
+ prop: string;
939
+ /**
940
+ * How the value holds it: all of it (default); its first part before a `.` (`Order.Status`,
941
+ * `Order.Created`); its last part after a `.` or `/` (`Sales.Order`, `Sales/Order` — only with
942
+ * the module's own qualifiers); or the part before a `?` (`Order?filter=…`).
943
+ */
944
+ part?: 'whole' | 'head' | 'tail' | 'query';
945
+ /** Text before the name in the value (`entity:`). */
946
+ prefix?: string;
947
+ /** Only objects held by this key (an array's or object's key): `tables`, `relations`. */
948
+ within?: string;
949
+ /** Refers to the entity's table, which is its name only while it has no `tableName`. */
950
+ table?: boolean;
951
+ /** Only files whose path matches. */
952
+ files?: RegExp;
953
+ } | {
954
+ /**
955
+ * The keys of the object held by this key (at any depth; `a.b` for nested keys) are names:
956
+ * `seeds`, `demoSeeds`, `grants`.
957
+ */
958
+ keysOf: string;
959
+ prefix?: string;
960
+ files?: RegExp;
961
+ } | {
962
+ /** A property whose string value is JSON text: the rules apply inside it (`viewJson`). */
963
+ jsonIn: string;
964
+ files?: RegExp;
965
+ } | {
966
+ /** Object keys built from the name: `{name}` marks it (`entity.{name}.`, `field.{name}.`). */
967
+ keyPattern: string;
968
+ files?: RegExp;
969
+ } | {
970
+ /** A whole string value, anywhere, built from the name: `{name}All`, `{name}ById`. */
971
+ value: string;
972
+ files?: RegExp;
973
+ };
974
+
975
+ /** The rules of a preset, by what is renamed. */
976
+ export declare interface NiceStudioReferenceRules {
977
+ entity?: NiceStudioReferenceRule[];
978
+ dataSource?: NiceStudioReferenceRule[];
979
+ }
980
+
981
+ export declare interface NiceStudioRenameOptions {
982
+ /**
983
+ * The module's own names a qualified reference may carry (`Sales` in `Sales.Order`): its id, its
984
+ * package. Qualified references to other modules are never touched.
985
+ */
986
+ qualifiers?: readonly string[];
987
+ /** Only qualified references (`Sales.Order`) — for the other modules that refer to this one. */
988
+ qualifiedOnly?: boolean;
989
+ /** The renamed entity has its own `tableName`: rules about its table do not apply. */
990
+ ownTable?: boolean;
991
+ }
992
+
993
+ export declare interface NiceStudioRenameResult {
994
+ /** The files that changed, with their new text. */
995
+ files: NiceStudioTextFile[];
996
+ /** How many references were rewritten. */
997
+ count: number;
998
+ }
999
+
879
1000
  /** A saved earlier version of a module or one of its files. */
880
1001
  export declare interface NiceStudioRevision {
881
1002
  id: string;
@@ -989,6 +1110,12 @@ export declare interface NiceStudioTemplateModule {
989
1110
  description?: string;
990
1111
  }
991
1112
 
1113
+ /** A file as the studio holds it. */
1114
+ export declare interface NiceStudioTextFile {
1115
+ path: string;
1116
+ text: string;
1117
+ }
1118
+
992
1119
  /** Translations of one document: `{ en: { key: text }, pl: { … } }` (the shape of NiceI18nEditor). */
993
1120
  export declare type NiceStudioTranslations = Record<string, Record<string, string>>;
994
1121
 
@@ -1018,6 +1145,12 @@ export declare type NiceStudioWriteResult = {
1018
1145
  /** A file whose whole content is the model (a manifest, an access model). */
1019
1146
  export declare function objectFileKind<T extends object>(o: NiceObjectFileKindOptions): NiceStudioFileKind<T>;
1020
1147
 
1148
+ /**
1149
+ * The layout with entries put in this order among their siblings (1.4.14 — dragging rows of the
1150
+ * tree): each gets `order` = its index; their section and folder stay.
1151
+ */
1152
+ export declare function orderStudioEntries(layout: NiceStudioLayout, refs: readonly string[]): NiceStudioLayout;
1153
+
1021
1154
  /** Parses JSON text that may start with a BOM, and tells how it is written. */
1022
1155
  export declare function parseJsonText(text: string): {
1023
1156
  value: unknown;
@@ -1042,7 +1175,8 @@ export declare function patchJsonTextDetailed(previous: string, next: unknown, o
1042
1175
 
1043
1176
  /**
1044
1177
  * The layout with an entry put somewhere: into a folder (its section follows the folder's), into a
1045
- * section (out of any folder), or back to its group (`{}`).
1178
+ * section (out of any folder), or back to its group (`{}`). A folder of another group (1.4.14 — a
1179
+ * drag can aim anywhere) leaves the layout as it was.
1046
1180
  */
1047
1181
  export declare function placeStudioEntry(layout: NiceStudioLayout, ref: string, target: {
1048
1182
  folder?: string;
@@ -1070,6 +1204,12 @@ export declare function renameStudioLayoutNode(layout: NiceStudioLayout, node: {
1070
1204
  id: string;
1071
1205
  }, label: string): NiceStudioLayout;
1072
1206
 
1207
+ /**
1208
+ * The files with every reference to `from` renamed to `to`, by `rules`. Only JSON files are read;
1209
+ * a file that does not parse is left alone. Returns the changed files and the count.
1210
+ */
1211
+ export declare function renameStudioReferences(files: readonly NiceStudioTextFile[], rules: readonly NiceStudioReferenceRule[], from: string, to: string, options?: NiceStudioRenameOptions): NiceStudioRenameResult;
1212
+
1073
1213
  /** The kind a path opens with: the first that matches, else JSON or text. */
1074
1214
  export declare function resolveFileKind(kinds: readonly NiceStudioFileKind[], path: string): NiceStudioFileKind;
1075
1215
 
@@ -1098,6 +1238,13 @@ export declare function slugifyModuleId(name: string): string;
1098
1238
  /** Writes `value` in a given format (defaults: two spaces, LF, final newline, no BOM). */
1099
1239
  export declare function stringifyJsonText(value: unknown, format?: Partial<NiceJsonTextFormat>): string;
1100
1240
 
1241
+ /**
1242
+ * A module's dependencies (1.4.15 — OmniVerk wishlist #1): the declared ones, each with the entities
1243
+ * of it the files refer to, then the modules only referred to (`Other.Entity` in a field) that are
1244
+ * not declared. Qualifiers are matched without regard to `.` / `/` and case.
1245
+ */
1246
+ export declare function studioDependencies(declared: readonly NiceStudioDependency[], files: readonly NiceStudioTextFile[], rules: readonly NiceStudioReferenceRule[], own?: readonly string[]): NiceStudioDependency[];
1247
+
1101
1248
  /** The ref of an entry in a layout: `group:key`. */
1102
1249
  export declare const studioEntryRef: (group: string, key: string) => string;
1103
1250
 
@@ -1107,6 +1254,17 @@ export declare const studioEntryRef: (group: string, key: string) => string;
1107
1254
  */
1108
1255
  export declare function studioLayoutPath(files: readonly NiceStudioFile[]): string;
1109
1256
 
1257
+ /**
1258
+ * The qualified references (`Other.Entity`, `Other/Entity`) in the places `rules` mark with
1259
+ * `part: 'tail'` whose qualifier is not one of `own` — the other modules a module refers to, for its
1260
+ * dependencies.
1261
+ */
1262
+ export declare function studioQualifiedReferences(files: readonly NiceStudioTextFile[], rules: readonly NiceStudioReferenceRule[], own?: readonly string[]): Array<{
1263
+ qualifier: string;
1264
+ name: string;
1265
+ path: string;
1266
+ }>;
1267
+
1110
1268
  /** `"Send invoice"` → `sendInvoice`: a name usable as a function's. */
1111
1269
  export declare function studioScriptIdentifier(name: string): string;
1112
1270