@nice2dev/ui-forms 1.4.5 → 1.4.7

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,13 +1,26 @@
1
- "use strict";var Fe=Object.defineProperty;var xe=(e,t,n)=>t in e?Fe(e,t,{enumerable:!0,configurable:!0,writable:!0,value:n}):e[t]=n;var ee=(e,t,n)=>xe(e,typeof t!="symbol"?t+"":t,n);Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const T=()=>({version:1,sections:[],folders:[],placement:{}}),Ie=(e,t)=>`${e}:${t}`,_=".studio.json",Me=/^([^/]+?)\.(manifest|entities|views|workflows|permissions|rbac|seeds|datasources|scripts)\.json$/i,se=e=>!e.includes("/")&&e.toLowerCase().endsWith(_);function Te(e){const t=e.find(n=>se(n.path));if(t)return t.path;for(const n of e){const s=Me.exec(n.path);if(s)return`${s[1]}${_}`}return`module${_}`}const N=e=>typeof e=="object"&&e!==null&&!Array.isArray(e),b=e=>typeof e=="string"&&e?e:void 0;function Le(e){if(!e)return T();let t;try{t=JSON.parse(e.replace(/^\uFEFF/,""))}catch{return T()}if(!N(t))return T();const n=(Array.isArray(t.sections)?t.sections:[]).filter(N).map(o=>({id:b(o.id),label:b(o.label)??b(o.id)})).filter(o=>!!o.id&&!!o.label),s=(Array.isArray(t.folders)?t.folders:[]).filter(N).map(o=>({id:b(o.id),label:b(o.label)??b(o.id),group:b(o.group),...b(o.parent)?{parent:b(o.parent)}:{},...b(o.section)?{section:b(o.section)}:{}})).filter(o=>!!o.id&&!!o.label&&!!o.group),i={};if(N(t.placement))for(const[o,c]of Object.entries(t.placement)){if(!N(c))continue;const l={};b(c.section)&&(l.section=b(c.section)),b(c.folder)&&(l.folder=b(c.folder)),typeof c.order=="number"&&Number.isFinite(c.order)&&(l.order=c.order),(l.section||l.folder||l.order!==void 0)&&(i[o]=l)}return{version:1,sections:n,folders:s,placement:i}}const Je=e=>e.sections.length===0&&e.folders.length===0&&Object.keys(e.placement).length===0;function Pe(e,t){const n=JSON.stringify(e,null,2)+`
1
+ "use strict";var qe=Object.defineProperty;var Ve=(e,t,n)=>t in e?qe(e,t,{enumerable:!0,configurable:!0,writable:!0,value:n}):e[t]=n;var se=(e,t,n)=>Ve(e,typeof t!="symbol"?t+"":t,n);Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const M=()=>({version:1,sections:[],folders:[],placement:{}}),ze=(e,t)=>`${e}:${t}`,W=".studio.json",We=/^([^/]+?)\.(manifest|entities|views|workflows|permissions|rbac|seeds|datasources|scripts)\.json$/i,ae=e=>!e.includes("/")&&e.toLowerCase().endsWith(W);function Be(e){const t=e.find(n=>ae(n.path));if(t)return t.path;for(const n of e){const s=We.exec(n.path);if(s)return`${s[1]}${W}`}return`module${W}`}const N=e=>typeof e=="object"&&e!==null&&!Array.isArray(e),b=e=>typeof e=="string"&&e?e:void 0;function He(e){if(!e)return M();let t;try{t=JSON.parse(e.replace(/^\uFEFF/,""))}catch{return M()}if(!N(t))return M();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 Xe=e=>e.sections.length===0&&e.folders.length===0&&Object.keys(e.placement).length===0;function Ze(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 De=e=>e.toLowerCase().normalize("NFKD").replace(/[̀-ͯ]/g,"").replace(/[^a-z0-9]+/g,"-").replace(/^-+|-+$/g,"")||"item";function ie(e,t){const n=De(e);let s=n;for(let i=2;t.has(s);i++)s=`${n}-${i}`;return s}function Re(e,t){const n=ie(t,new Set(e.sections.map(s=>s.id)));return{layout:{...e,sections:[...e.sections,{id:n,label:t}]},id:n}}function Ce(e,t){const n=ie(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 Ve(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 Ue(e,t){const n={};if(t.kind==="folder"){const s=e.folders.find(i=>i.id===t.id);for(const[i,o]of Object.entries(e.placement))n[i]=o.folder===t.id?{...o,folder:s==null?void 0:s.parent}:o,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:o,...c}=i;return c}return i}),placement:z(n)}}for(const[s,i]of Object.entries(e.placement))if(i.section===t.id){const{section:o,...c}=i;n[s]=c}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,...o}=s;return o}return s}),placement:z(n)}}function z(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 _e(e,t,n){var o;const s=(o=e.placement[t])==null?void 0:o.order,i={};if(n.folder){i.folder=n.folder;const c=e.folders.find(l=>l.id===n.folder);c!=null&&c.section&&(i.section=c.section)}else n.section&&(i.section=n.section);return s!==void 0&&(i.order=s),{...e,placement:z({...e.placement,[t]:i})}}function ze(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 re="\uFEFF",oe={bom:!1,eol:`
5
- `,indent:" ",finalNewline:!0,colonSpace:!0};function C(e){const t=e.charCodeAt(0)===65279,n=e.includes(`\r
4
+ `):n}const Ge=e=>e.toLowerCase().normalize("NFKD").replace(/[̀-ͯ]/g,"").replace(/[^a-z0-9]+/g,"-").replace(/^-+|-+$/g,"")||"item";function ce(e,t){const n=Ge(e);let s=n;for(let i=2;t.has(s);i++)s=`${n}-${i}`;return s}function Ye(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 Qe(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 et(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 tt(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:B(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:B(n)}}function B(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 nt(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:B({...e.placement,[t]:i})}}function st(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 q(e){const t=e.charCodeAt(0)===65279,n=e.includes(`\r
6
6
  `)?`\r
7
7
  `:`
8
- `;let s=oe.indent;const i=e.split(/\r?\n/);for(let c=1;c<i.length;c++){const l=/^([ \t]+)\S/.exec(i[c]);if(l){s=l[1];break}}const o=/"\s*:(\s?)/.exec(e);return{bom:t,eol:n,indent:s,finalNewline:/\n$/.test(e),colonSpace:o?o[1]!=="":!0}}function O(e){const t=C(e);return{value:JSON.parse(t.bom?e.slice(1):e),format:t}}function k(e,t){const n={...oe,...t},s=E(e,n,"");return(n.bom?re:"")+s+(n.finalNewline?n.eol:"")}function ae(e,t){if(t===void 0)return e;let n=t.includes(`\r
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 E(e){const t=q(e);return{value:JSON.parse(t.bom?e.slice(1):e),format:t}}function k(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
9
9
  `)?e.replace(/\r?\n/g,`\r
10
- `):e;return t.charCodeAt(0)===65279&&n.charCodeAt(0)!==65279&&(n=re+n),n}function x(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 o=t;return e.length===o.length&&e.every((c,l)=>x(c,o[l]))}const n=e,s=t,i=Object.keys(n);return i.length!==Object.keys(s).length?!1:i.every(o=>Object.prototype.hasOwnProperty.call(s,o)&&x(n[o],s[o]))}function G(e,t,n){return ce(e,t,n).text}function ce(e,t,n){const s=C(e),i=r=>({text:k(t,s),exact:!1,reason:r});let o;try{o=new We(e).parseDocument()}catch(r){return i(r instanceof Error?r.message:String(r))}if(W(o))return i("duplicate keys");const c=[],l={text:e,format:s,edits:c,options:n,compact:!e.trimEnd().includes(`
11
- `)};Y(l,o,t,"",!1);const u=qe(e,c);try{const r=JSON.parse(s.bom?u.slice(1):u);if(!x(r,t))return i("patch did not read back")}catch{return i("patch was not valid JSON")}return{text:u,exact:!0}}class We{constructor(t){ee(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 o=this.text[this.pos++];if(o==="}")return{kind:"object",start:t,end:this.pos,members:n};if(o!==",")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 W(e){if(e.kind==="object"){const t=new Set;for(const n of e.members){if(t.has(n.key)||W(n.value))return!0;t.add(n.key)}}else if(e.kind==="array")return e.items.some(W);return!1}function L(e){if(e.kind==="scalar")return e.value;if(e.kind==="array")return e.items.map(L);const t={};for(const n of e.members)t[n.key]=L(n.value);return t}function E(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(c=>s+E(c,t,s)).join(`,${t.eol}`)}${t.eol}${n}]`;const o=Object.entries(e).filter(([,c])=>c!==void 0);return o.length===0?"{}":`{${t.eol}${o.map(([c,l])=>`${s}${JSON.stringify(c)}${i}${E(l,t,s)}`).join(`,${t.eol}`)}${t.eol}${n}}`}function A(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=>A(l,t,n)).join(i)}]`;const o=Object.entries(e).filter(([,l])=>l!==void 0),c=n?"":" ";return o.length===0?"{}":`{${c}${o.map(([l,u])=>`${JSON.stringify(l)}${s}${A(u,t,n)}`).join(i)}${c}}`}const le=e=>e.compact?",":", ";function qe(e,t){let n=e;for(const s of[...t].sort((i,o)=>o.start-i.start))n=n.slice(0,s.start)+s.text+n.slice(s.end);return n}function J(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 de(e,t){return!e.slice(t.start,t.end).includes(`
13
- `)}function H(e,t,n){return e.compact?!0:t.kind==="scalar"||(t.kind==="object"?t.members.length===0:t.items.length===0)?n:de(e.text,t)}function I(e,t,n,s){const i=H(e,t,s);e.edits.push({start:t.start,end:t.end,text:i?A(n,e.format,e.compact):E(n,e.format,J(e.text,t.start))})}const fe=e=>typeof e=="object"&&e!==null&&!Array.isArray(e);function Y(e,t,n,s,i){if(t.kind==="scalar"){if(t.value===n)return;I(e,t,n,i);return}x(L(t),n)||(t.kind==="object"&&fe(n)?Be(e,t,n,s,i):t.kind==="array"&&Array.isArray(n)?He(e,t,n,s,i):I(e,t,n,i))}function ue(e,t,n){return n!==void 0?J(e.text,n):J(e.text,t.start)+e.format.indent}function Be(e,t,n,s,i){var d;const o=H(e,t,i),c=t.members.filter(f=>Object.prototype.hasOwnProperty.call(n,f.key)&&n[f.key]!==void 0),l=Object.keys(n).filter(f=>n[f]!==void 0&&!t.members.some(h=>h.key===f));if(c.length===0&&t.members.length>0){I(e,t,n,i);return}for(const f of c)Y(e,f.value,n[f.key],`${s}/${Qe(f.key)}`,o);if(pe(e,t.members.map(f=>({start:f.start,end:f.value.end})),t.members.map(f=>c.includes(f))),l.length===0)return;const u=e.format.colonSpace?": ":":";if(o){const f=l.map(h=>`${JSON.stringify(h)}${u}${A(n[h],e.format,e.compact)}`);he(e,t,c.length>0?c[c.length-1].value.end:void 0,f);return}const r=ue(e,t,(d=t.members[0])==null?void 0:d.start),a=l.map(f=>`${r}${JSON.stringify(f)}${u}${E(n[f],e.format,r)}`);me(e,t,c.length>0?c[c.length-1].value.end:void 0,a)}const Xe=["name","id","code","key","slug","state","Id"];function Ge(e,t,n,s){var u,r;const i=[...n,...s];if(i.length===0||!i.every(fe))return;const o=(a,d)=>{const f=a.map(h=>h[d]);return f.every(h=>typeof h=="string"||typeof h=="number")&&new Set(f).size===f.length},c=(r=(u=e.options)==null?void 0:u.arrayKey)==null?void 0:r.call(u,t);return(c?[c]:Xe).find(a=>o(n,a)&&o(s,a))}function He(e,t,n,s,i){var g;const o=H(e,t,i),c=t.items.map(L),l=Ge(e,s,c,n),u=p=>p[l],r=l!==void 0?c.map(p=>{const m=u(p);return n.findIndex(w=>u(w)===m)}):Ze(c,n);{const p=new Set(r.filter(m=>m>=0));for(let m=0;m<r.length;m++){if(r[m]>=0)continue;let w=-1;for(let y=m-1;y>=0;y--)if(r[y]>=0){w=r[y];break}let $=n.length;for(let y=m+1;y<r.length;y++)if(r[y]>=0){$=r[y];break}for(let y=w+1;y<$;y++)if(!p.has(y)){r[m]=y,p.add(y);break}}}const a=r.filter(p=>p>=0);if(a.some((p,m)=>m>0&&p<a[m-1])){I(e,t,n,i);return}if(a.length===0&&t.items.length>0){I(e,t,n,i);return}t.items.forEach((p,m)=>{r[m]>=0&&Y(e,p,n[r[m]],`${s}/${r[m]}`,o)}),pe(e,t.items.map(p=>({start:p.start,end:p.end})),r.map(p=>p>=0));const d=t.items.length>0&&t.items.every(p=>p.kind!=="scalar"&&de(e.text,p)),f=ue(e,t,(g=t.items[0])==null?void 0:g.start),h=new Map;n.forEach((p,m)=>{if(r.includes(m))return;let w;for(let j=t.items.length-1;j>=0;j--)if(r[j]>=0&&r[j]<m){w=j;break}const $=o?A(p,e.format,e.compact):d?`${f}${A(p,e.format)}`:`${f}${E(p,e.format,f)}`,y=h.get(w)??[];y.push($),h.set(w,y)});for(const[p,m]of h){const w=p===void 0?void 0:t.items[p].end;if(p===void 0&&a.length>0){const $=t.items[r.findIndex(j=>j>=0)],y=o?le(e):`,${e.format.eol}`;e.edits.push({start:$.start,end:$.start,text:o?m.join(y)+y:m.join(y).trimStart()+y+f});continue}o?he(e,t,w,m):me(e,t,w,m)}}const Ye=4e6;function Ze(e,t){const n=e.length,s=t.length;if(n*s>Ye)return e.map((a,d)=>d<s?d:-1);const i=e.map(a=>JSON.stringify(a)),o=t.map(a=>JSON.stringify(a)),c=Array.from({length:n+1},()=>new Uint32Array(s+1));for(let a=n-1;a>=0;a--)for(let d=s-1;d>=0;d--)c[a][d]=i[a]===o[d]?c[a+1][d+1]+1:Math.max(c[a+1][d],c[a][d+1]);const l=new Array(n).fill(-1);let u=0,r=0;for(;u<n&&r<s;)i[u]===o[r]?l[u++]=r++:c[u+1][r]>=c[u][r+1]?u++:r++;return l}function pe(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 me(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 o=t.end-1;if((t.kind==="object"?t.members.length:t.items.length)===0)e.edits.push({start:t.start+1,end:o,text:`${i}${s.join(`,${i}`)}${i}${J(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 he(e,t,n,s){const i=le(e);if(n!==void 0){e.edits.push({start:n,end:n,text:`${i}${s.join(i)}`});return}const o=t.kind==="object"&&!e.compact?" ":"";e.edits.push({start:t.start+1,end:t.end-1,text:`${o}${s.join(i)}${o}`})}function Qe(e){return e.replace(/~/g,"~0").replace(/\//g,"~1")}const K=e=>e.slice(e.lastIndexOf("/")+1),et=e=>e.charCodeAt(0)===65279?e.slice(1):e;function V(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,o=O(i).value,c=e.assign(o,t,s);return{files:[{path:n[0].path,text:G(i,c,{arrayKey:e.arrayKey})}]}}}}const P=V({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}),D={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:ae(e,t[0].text)}]})};function ye(e,t){return e.find(n=>n.match(t))??(P.match(t)?P:D)}function tt(e,t,n){for(const s of[P,D])if(s.match(e.path))try{const i=s.decode([e],n);return{key:`${s.id}:${e.path}`,kind:s,paths:[e.path],label:K(e.path),model:i,error:t}}catch{}return{key:`text:${e.path}`,kind:D,paths:[e.path],label:K(e.path),model:e.text,error:t}}function nt(e,t,n,s){var l,u;const i=e.encode(t,n,s),o=new Map(n.map(r=>[r.path,r.text])),c=((l=i.files.find(r=>o.get(r.path)!==r.text))==null?void 0:l.path)??((u=i.deleted)==null?void 0:u.find(r=>o.has(r)));if(c!==void 0)throw new Error(`${K(c)} would not be stored as it is`)}function st(e,t,n){const s=new Map;for(const o of t){const c=ye(e,o.path),l=c.group?c.group(o.path):o.path,u=`${c.id}:${l}`,r=s.get(u)??{kind:c,group:l,files:[]};r.files.push(o),s.set(u,r)}const i=[];for(const[o,{kind:c,group:l,files:u}]of s){const r=u.map(d=>d.path).sort(),a=K(c.group?l:r[0]);try{const d=c.decode(u,n);nt(c,d,u,n),i.push({key:o,kind:c,paths:r,label:a,model:d})}catch(d){const f=d instanceof Error?d.message:String(d);for(const h of u)i.push(tt(h,f,n))}}return i.sort((o,c)=>o.label.localeCompare(c.label))}function it(e,t,n,s){const i=n.filter(u=>e.paths.includes(u.path)),o=e.kind.encode(t,i,s),c=new Map(n.map(u=>[u.path,u])),l=[];for(const u of o.files){const r=c.get(u.path);r&&r.text===u.text||l.push({type:"write",path:u.path,text:u.text,baseVersion:r==null?void 0:r.version})}for(const u of o.deleted??[]){const r=c.get(u);r&&l.push({type:"delete",path:u,baseVersion:r.version})}return l}function ge(e,t){try{return JSON.parse(et(e))}catch{return t}}const v=e=>typeof e=="object"&&e!==null&&!Array.isArray(e),S=(...e)=>t=>{const n=t.toLowerCase();return e.some(s=>n.endsWith(s.toLowerCase()))};function M(e){return V({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=v(t)?t[e.property]:void 0;return Array.isArray(n)?n:[]},assign:(t,n)=>Array.isArray(t)?n:v(t)&&!(e.property in t)&&n.length===0?t:{...v(t)?t:{},[e.property]:n},arrayKey:e.itemKey?()=>e.itemKey:void 0})}function Z(e){const t=M(e);return{...t,decode:(n,s)=>t.decode(n,s).map((i,o)=>e.toItem(i,o)),encode:(n,s,i)=>t.encode(n.map(o=>e.fromItem(o)),s,i)}}function Q(e){return V({...e,select:t=>v(t)?t:{},assign:(t,n)=>n})}const rt=/^(.*)\.([a-z]{2,3}(?:-[A-Za-z]{2,4})?)\.i18n\.json$/i,ot=e=>{const t=rt.exec(e);return t?{group:t[1],locale:t[2]}:null},q=e=>v(e)&&Object.values(e).every(t=>typeof t=="string");function be(e){if(v(e)){for(const t of["translations","keys"])if(t in e){if(q(e[t]))return e[t];throw new Error(`"${t}" is not a flat map of texts`)}if(q(e))return e}throw new Error("no translations in this file")}function B(e,t){return v(e)?v(e.translations)?{...e,translations:t}:v(e.keys)?{...e,keys:t}:q(e)?t:{...e,translations:t}:{translations:t}}function we(e={}){const t=e.parse??ot,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 o of s){const c=t(o.path);c&&(i[c.locale]={...be(O(o.text).value)})}return i},encode(s,i){const o=new Map;let c="";for(const a of i){const d=t(a.path);d&&(o.set(d.locale,a),c=d.group)}const l=o.get("en")??i[0],u=[];for(const[a,d]of Object.entries(s)){const f=o.get(a);if(f){const g=O(f.text).value;u.push({path:f.path,text:G(f.text,B(g,d))});continue}const h=n(c||K((l==null?void 0:l.path)??"module"),a);if(l){const g=O(l.text).value,p=v(g)&&"locale"in g?{...g,locale:a}:g;u.push({path:h,text:k(B(p,d),C(l.text))})}else u.push({path:h,text:k({locale:a,translations:d})})}const r=[...o.entries()].filter(([a])=>!(a in s)).map(([,a])=>a.path);return{files:u,deleted:r}}}}const F=e=>JSON.parse(JSON.stringify(e));function at(e){const t=e.revisions!==!1;let n=0;const s=e.workspaces.map(r=>({meta:{id:r.id,label:r.label,description:r.description,icon:r.icon,readOnly:r.readOnly},packages:new Map((r.packages??[]).map(a=>[a.id,{...a,workspaceId:r.id}])),modules:new Map(r.modules.map(a=>[a.id,{...a,files:new Map(Object.entries(a.files).map(([d,f])=>[d,{text:f,version:++n}])),revisions:[]}]))}));let i=(e.templates??[]).map(r=>F(r));const o=r=>{const a=s.find(d=>d.meta.id===r);if(!a)throw new Error(`Unknown workspace "${r}"`);return a},c=r=>{const a=o(r.workspaceId).modules.get(r.id);if(!a)throw new Error(`Unknown module "${r.id}"`);return a},l=(r,a)=>({workspaceId:r,id:a.id,packageId:a.packageId,label:a.label??a.id,description:a.description,icon:a.icon,version:a.version,readOnly:a.readOnly||o(r).meta.readOnly,files:[...a.files.keys()].sort()}),u=(r,a)=>({path:r,text:a.text,version:String(a.version)});return{async listWorkspaces(){return s.map(r=>({...r.meta}))},async listModules(r){return[...o(r).modules.values()].map(d=>l(r,d))},async listPackages(r){const a=o(r),d=[...a.packages.values()],f=[...new Set([...a.modules.values()].map(h=>h.packageId).filter(Boolean))].filter(h=>!a.packages.has(h)).map(h=>({id:h,workspaceId:r,label:h,derived:!0}));return[...d,...f]},async readModule(r){return[...c(r).files.entries()].map(([d,f])=>u(d,f))},async writeModule(r,a){const d=c(r);if(d.readOnly||o(r.workspaceId).meta.readOnly)throw new Error(`Module "${r.id}" is read-only`);const f=a.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(f.length>0)return{ok:!1,conflicts:f};let h;if(t){const p={};for(const[m,w]of d.files)p[m]=w.text;h=`r${++n}`,d.revisions.unshift({id:h,timestamp:Date.now(),label:h,summary:a.map(m=>`${m.type} ${m.path}`).join(", "),files:p})}const g={};for(const p of a)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:h}},async createModule(r){const a=o(r.workspaceId);if(a.meta.readOnly)throw new Error(`Workspace "${r.workspaceId}" is read-only`);if(a.modules.has(r.id))throw new Error(`Module "${r.id}" already exists`);const d={id:r.id,packageId:r.packageId,files:new Map(r.files.map(f=>[f.path,{text:f.text,version:++n}])),revisions:[]};return a.modules.set(r.id,d),l(r.workspaceId,d)},async deleteModule(r){const a=o(r.workspaceId);if(a.meta.readOnly)throw new Error(`Workspace "${r.workspaceId}" is read-only`);a.modules.delete(r.id)},async savePackage(r){return o(r.workspaceId).packages.set(r.id,{...r,derived:!1}),{...r,derived:!1}},async deletePackage(r){o(r.workspaceId).packages.delete(r.id)},async listTemplates(){return i.map(r=>F(r))},async saveTemplate(r,a){const d=(a==null?void 0:a.previousId)??r.id,f=F(r),h=i.findIndex(g=>g.id===d);return i=h>=0?i.map((g,p)=>p===h?f:g):[...i,f],F(f)},async deleteTemplate(r){i=i.filter(a=>a.id!==r)},async listRevisions(r,a){return c(r).revisions.filter(d=>!a||a in d.files).map(({files:d,...f})=>({...f,...a?{path:a}:{}}))},async readRevision(r,a,d){const f=c(r).revisions.find(h=>h.id===a);if(!f)throw new Error(`Unknown revision "${a}"`);return d?f.files[d]??"":JSON.stringify(f.files,null,2)},async rollback(r,a,d){const f=c(r),h=f.revisions.find(p=>p.id===a);if(!h)throw new Error(`Unknown revision "${a}"`);const g=d?{[d]:h.files[d]}:h.files;if(!d)for(const p of[...f.files.keys()])p in g||f.files.delete(p);for(const[p,m]of Object.entries(g))m!==void 0&&f.files.set(p,{text:m,version:++n})},snapshot(){return{workspaces:s.map(r=>({...r.meta,packages:[...r.packages.values()].map(({workspaceId:a,...d})=>d),modules:[...r.modules.values()].map(a=>({id:a.id,packageId:a.packageId,label:a.label,description:a.description,icon:a.icon,version:a.version,readOnly:a.readOnly,files:Object.fromEntries([...a.files.entries()].map(([d,f])=>[d,f.text]))}))})),templates:i.map(r=>F(r)),revisions:t}}}}function ct(e){return e}function R(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=>R(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&&R(i,n[s]))}default:return!0}}function lt(e,t){var c;const n=(e.fields??[]).map(l=>l.name),s=(c=e.schema)==null?void 0:c.properties;if(!e.schema||!s)return{section:e,keys:n};const i=Object.entries(s).filter(([l,u])=>!(l in t)||R(t[l],u)),o=i.map(([l])=>l);return{section:{...e,schema:{...e.schema,properties:Object.fromEntries(i),...e.schema.required?{required:e.schema.required.filter(l=>o.includes(l))}:{}}},keys:[...o,...n]}}function dt(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 ft(e){return e.map(t=>{const n=t;return{name:String(n.tableName||n.name||"Entity"),columns:(Array.isArray(n.fields)?n.fields:[]).map(s=>({name:String(s.name??""),dataType:String(s.dataType??s.type??"string"),isPrimaryKey:!!s.isPrimaryKey,isForeignKey:!!(s.isForeignKey??s.foreignKey)}))}})}function ut(e){const t=e.manifest??{},n=String(t.displayName||t.packageName||"Module"),s=(e.views??[]).map(o=>({id:`view:${o.id}`,label:o.name,type:"view"})),i=(e.entities??[]).map(o=>{const c=String(o.name??"Entity");return{id:`entity:${c}`,label:c,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 U=Q({id:"manifest",label:"Manifest",labelKey:"devStudio.kind.manifest",icon:"file",editor:"manifest",match:S(".manifest.json")}),ke=M({id:"entities",label:"Entities",labelKey:"devStudio.kind.entities",icon:"database",editor:"entities",match:S(".entities.json"),property:"entities",itemKey:"name"}),ve=we();function Se(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 $e=Z({id:"views",label:"Views",labelKey:"devStudio.kind.views",icon:"grid",editor:"views",match:S(".views.json"),property:"views",itemKey:"id",toItem:(e,t)=>Se(e,t),fromItem:e=>e.definition??e.source}),je=Z({id:"workflows",label:"Workflows",labelKey:"devStudio.kind.workflows",icon:"git-branch",editor:"workflows",match:S(".workflows.json"),property:"workflows",itemKey:"id",toItem:(e,t)=>Se(e,t),fromItem:e=>e.definition??e.source}),Ke=M({id:"dataSources",label:"Data sources",labelKey:"devStudio.kind.dataSources",icon:"database",editor:"dataSources",match:S(".datasources.json"),property:"dataSources",itemKey:"key"}),Oe=Q({id:"rbac",label:"Access",labelKey:"devStudio.kind.rbac",icon:"shield",editor:"rbac",match:S(".rbac.json")}),Ee=M({id:"hooks",label:"Lifecycle hooks",labelKey:"devStudio.kind.hooks",icon:"zap",editor:"hooks",match:S(".hooks.json"),property:"bindings",itemKey:"id"}),Ae=[U,ke,ve,$e,je,Ke,Oe,Ee];function X(e){return e.normalize("NFKD").replace(/[̀-ͯ]/g,"").replace(/ł/g,"l").replace(/Ł/g,"L").toLowerCase().replace(/[^a-z0-9]+/g,"-").replace(/^-+|-+$/g,"")||"module"}const te=e=>{const t=e.find(n=>U.match(n.path));return t?ge(t.text,void 0):void 0};function Ne(e){const t=e.find(n=>U.match(n.path));return t?K(t.path).replace(/\.manifest\.json$/i,""):"module"}const ne=e=>Array.isArray(e.fields)?e.fields:[],pt={id:"native",kinds:Ae,locales:["en","pl","de","fr","es","uk"],requiredLocales:["en"],moduleId:e=>{const t=te(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=te(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=Ne(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:[]}]}[e];return i?{path:`${n}.${i[0]}`,text:k(i[1])}:void 0},generateModule:async(e,{existingIds:t})=>{let n=X(e.name);for(let i=2;t.has(n);i++)n=`${X(e.name)}-${i}`;const s=[{path:`${n}.manifest.json`,text:k({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:k({entities:e.entities})}];for(const i of e.locales){const o={"module.displayName":e.name};for(const c of e.entities){const l=String(c.name??"");o[`entity.${l}.displayName`]=l;for(const u of ne(c))o[`field.${l}.${String(u.name)}.label`]=String(u.name)}s.push({path:`${n}.${i}.i18n.json`,text:k({locale:i,translations:o})})}if(e.views){const i=e.entities.map(o=>{const c=String(o.name??"Item");return{id:`${c}List`,name:`${c} list`,kind:"grid",version:2,columns:12,dataSources:[{key:"rows",type:"entity",entity:c,autoLoad:!0}],rows:[{id:"r1",cells:[{id:"grid",controlType:"dataGrid",colSpan:12,props:{columns:ne(o).map(l=>({field:String(l.name),header:String(l.name)}))},bindings:{data:{source:"rows",field:""}}}]}]}});s.push({path:`${n}.views.json`,text:k({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(o=>({id:`entity:${String(o.name)}`,label:String(o.name),type:"entity"})),grants:{}};s.push({path:`${n}.rbac.json`,text:k(i)})}return{id:n,packageId:e.packageId,files:s}}};exports.addStudioFolder=Ce;exports.addStudioSection=Re;exports.arrayFileKind=M;exports.buildDocuments=st;exports.createMemoryStudioProvider=at;exports.defineManifestSection=ct;exports.deriveDefaultRbac=ut;exports.detectJsonTextFormat=C;exports.emptyStudioLayout=T;exports.encodeDocument=it;exports.endsWithAny=S;exports.entitiesToSchemas=ft;exports.fileName=K;exports.fitManifestSection=lt;exports.i18nFileKind=we;exports.isEmptyStudioLayout=Je;exports.isStudioLayoutPath=se;exports.itemsFileKind=Z;exports.jsonFallbackKind=P;exports.jsonFileKind=V;exports.jsonValueFitsSchema=R;exports.jsonValuesEqual=x;exports.keepTextFormat=ae;exports.manifestSectionKeys=dt;exports.modulePrefix=Ne;exports.nativeDataSourcesKind=Ke;exports.nativeEntitiesKind=ke;exports.nativeFileKinds=Ae;exports.nativeHooksKind=Ee;exports.nativeI18nKind=ve;exports.nativeManifestKind=U;exports.nativeRbacKind=Oe;exports.nativeStudioPreset=pt;exports.nativeViewsKind=$e;exports.nativeWorkflowsKind=je;exports.objectFileKind=Q;exports.parseJsonText=O;exports.parseStudioLayout=Le;exports.patchJsonText=G;exports.patchJsonTextDetailed=ce;exports.placeStudioEntry=_e;exports.readTranslations=be;exports.removeStudioLayoutNode=Ue;exports.renameStudioEntryRef=ze;exports.renameStudioLayoutNode=Ve;exports.resolveFileKind=ye;exports.safeJson=ge;exports.serializeStudioLayout=Pe;exports.slugifyModuleId=X;exports.stringifyJsonText=k;exports.studioEntryRef=Ie;exports.studioLayoutPath=Te;exports.textFallbackKind=D;exports.writeTranslations=B;
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 Y(e,t,n){return ue(e,t,n).text}function ue(e,t,n){const s=q(e),i=o=>({text:k(t,s),exact:!1,reason:o});let r;try{r=new it(e).parseDocument()}catch(o){return i(o instanceof Error?o.message:String(o))}if(H(r))return i("duplicate keys");const a=[],l={text:e,format:s,edits:a,options:n,compact:!e.trimEnd().includes(`
11
+ `)};ee(l,r,t,"",!1);const f=rt(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 it{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 H(e){if(e.kind==="object"){const t=new Set;for(const n of e.members){if(t.has(n.key)||H(n.value))return!0;t.add(n.key)}}else if(e.kind==="array")return e.items.some(H);return!1}function P(e){if(e.kind==="scalar")return e.value;if(e.kind==="array")return e.items.map(P);const t={};for(const n of e.members)t[n.key]=P(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 rt(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 J(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 Q(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=Q(e,t,s);e.edits.push({start:t.start,end:t.end,text:i?I(n,e.format,e.compact):A(n,e.format,J(e.text,t.start))})}const ye=e=>typeof e=="object"&&e!==null&&!Array.isArray(e);function ee(e,t,n,s,i){if(t.kind==="scalar"){if(t.value===n)return;x(e,t,n,i);return}F(P(t),n)||(t.kind==="object"&&ye(n)?ot(e,t,n,s,i):t.kind==="array"&&Array.isArray(n)?lt(e,t,n,s,i):x(e,t,n,i))}function he(e,t,n){return n!==void 0?J(e.text,n):J(e.text,t.start)+e.format.indent}function ot(e,t,n,s,i){var d;const r=Q(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)ee(e,u.value,n[u.key],`${s}/${ut(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 at=["name","id","code","key","slug","state","Id"];function ct(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]:at).find(c=>r(n,c)&&r(s,c))}function lt(e,t,n,s,i){var g;const r=Q(e,t,i),a=t.items.map(P),l=ct(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)}):ft(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&&ee(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 dt=4e6;function ft(e,t){const n=e.length,s=t.length;if(n*s>dt)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}${J(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 ut(e){return e.replace(/~/g,"~0").replace(/\//g,"~1")}const O=e=>e.slice(e.lastIndexOf("/")+1),pt=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(E(t[0].text).value,n)},encode(t,n,s){const i=n[0].text,r=E(i).value,a=e.assign(r,t,s);return{files:[{path:n[0].path,text:Y(i,a,{arrayKey:e.arrayKey})}]}}}}const D=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}),_={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))??(D.match(t)?D:_)}function mt(e,t,n){for(const s of[D,_])if(s.match(e.path))try{const i=s.decode([e],n);return{key:`${s.id}:${e.path}`,kind:s,paths:[e.path],label:O(e.path),model:i,error:t}}catch{}return{key:`text:${e.path}`,kind:_,paths:[e.path],label:O(e.path),model:e.text,error:t}}function yt(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(`${O(a)} would not be stored as it is`)}function ht(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=O(a.group?l:o[0]);try{const d=a.decode(f,n);yt(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(mt(y,u,n))}}return i.sort((r,a)=>r.label.localeCompare(a.label))}function gt(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(pt(e))}catch{return t}}const v=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 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=v(t)?t[e.property]:void 0;return Array.isArray(n)?n:[]},assign:(t,n)=>Array.isArray(t)?n:v(t)&&!(e.property in t)&&n.length===0?t:{...v(t)?t:{},[e.property]:n},arrayKey:e.itemKey?()=>e.itemKey:void 0})}function te(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 ne(e){return L({...e,select:t=>v(t)?t:{},assign:(t,n)=>n})}const bt=/^(.*)\.([a-z]{2,3}(?:-[A-Za-z]{2,4})?)\.i18n\.json$/i,St=e=>{const t=bt.exec(e);return t?{group:t[1],locale:t[2]}:null},X=e=>v(e)&&Object.values(e).every(t=>typeof t=="string");function we(e){if(v(e)){for(const t of["translations","keys"])if(t in e){if(X(e[t]))return e[t];throw new Error(`"${t}" is not a flat map of texts`)}if(X(e))return e}throw new Error("no translations in this file")}function Z(e,t){return v(e)?v(e.translations)?{...e,translations:t}:v(e.keys)?{...e,keys:t}:X(e)?t:{...e,translations:t}:{translations:t}}function $e(e={}){const t=e.parse??St,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(E(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=E(u.text).value;f.push({path:u.path,text:Y(u.text,Z(g,d))});continue}const y=n(a||O((l==null?void 0:l.path)??"module"),c);if(l){const g=E(l.text).value,p=v(g)&&"locale"in g?{...g,locale:c}:g;f.push({path:y,text:k(Z(p,d),q(l.text))})}else f.push({path:y,text:k({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"],kt=["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 vt=new Set(["read","filter","map","aggregate","set","if","forEach","write","callScript","return"]),Oe=e=>Array.isArray(e)&&e.every(t=>$(t)&&typeof t.id=="string"&&vt.has(String(t.type)));function R(e){if(je.includes(e.kind))return e.kind;if(e.source===void 0&&Oe(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 Ee=["id","displayName","description","language","category","trigger","returnType","source","sourcePath"],wt=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:R(e)};for(const l of Ee){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(!wt(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&&!Oe(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 Ee)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??[]:R(n)==="noCode"&&delete s.steps,delete s.kind,("kind"in n||R(s)!==t.kind)&&(s.kind=t.kind),s}function z(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:z(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:z(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:z(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 $t(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}
14
+ SELECT 1;
15
+ `};case"backend":return{...s,returnType:"object",source:n==="csharp"?`public static object ${i}(IDictionary<string, object> args)
16
+ {
17
+ return null;
18
+ }
19
+ `:`function ${t}(args) {
20
+ return null;
21
+ }
22
+ `};case"frontend":return{...s,returnType:"void",source:n==="typescript"?`export function ${t}(): void {
23
+ }
24
+ `:`export function ${t}() {
25
+ }
26
+ `}}}const T=e=>JSON.parse(JSON.stringify(e));function jt(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 Kt(e){return e}function U(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=>U(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&&U(i,n[s]))}default:return!0}}function Ot(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)||U(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 Et(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 At(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 It(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 V=ne({id:"manifest",label:"Manifest",labelKey:"devStudio.kind.manifest",icon:"file",editor:"manifest",match:w(".manifest.json")}),Fe=C({id:"entities",label:"Entities",labelKey:"devStudio.kind.entities",icon:"database",editor:"entities",match:w(".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=te({id:"views",label:"Views",labelKey:"devStudio.kind.views",icon:"grid",editor:"views",match:w(".views.json"),property:"views",itemKey:"id",toItem:(e,t)=>Le(e,t),fromItem:e=>e.definition??e.source}),Me=te({id:"workflows",label:"Workflows",labelKey:"devStudio.kind.workflows",icon:"git-branch",editor:"workflows",match:w(".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:w(".datasources.json"),property:"dataSources",itemKey:"key"}),Je=ne({id:"rbac",label:"Access",labelKey:"devStudio.kind.rbac",icon:"shield",editor:"rbac",match:w(".rbac.json")}),De=C({id:"hooks",label:"Lifecycle hooks",labelKey:"devStudio.kind.hooks",icon:"zap",editor:"hooks",match:w(".hooks.json"),property:"bindings",itemKey:"id"}),_e=Ne({match:w(".scripts.json")}),Re=[V,Fe,xe,Ce,Me,Pe,Je,De,_e];function G(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=>V.match(n.path));return t?ve(t.text,void 0):void 0};function Ue(e){const t=e.find(n=>V.match(n.path));return t?O(t.path).replace(/\.manifest\.json$/i,""):"module"}const oe=e=>Array.isArray(e.fields)?e.fields:[],Nt={id:"native",kinds:Re,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=Ue(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:[]}]}[e];return i?{path:`${n}.${i[0]}`,text:k(i[1])}:void 0},generateModule:async(e,{existingIds:t})=>{let n=G(e.name);for(let i=2;t.has(n);i++)n=`${G(e.name)}-${i}`;const s=[{path:`${n}.manifest.json`,text:k({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:k({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:k({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:k({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:k(i)})}return{id:n,packageId:e.packageId,files:s}}};exports.NICE_STUDIO_SCRIPT_KINDS=je;exports.NICE_STUDIO_SCRIPT_PHASES=kt;exports.addStudioFolder=Qe;exports.addStudioSection=Ye;exports.arrayFileKind=C;exports.buildDocuments=ht;exports.createMemoryStudioProvider=jt;exports.defineManifestSection=Kt;exports.deriveDefaultRbac=It;exports.detectJsonTextFormat=q;exports.emptyStudioLayout=M;exports.encodeDocument=gt;exports.endsWithAny=w;exports.entitiesToSchemas=At;exports.fileName=O;exports.fitManifestSection=Ot;exports.fromStudioScriptItem=Ie;exports.i18nFileKind=$e;exports.inferStudioScriptKind=R;exports.isEmptyStudioLayout=Xe;exports.isStudioLayoutPath=ae;exports.itemsFileKind=te;exports.jsonFallbackKind=D;exports.jsonFileKind=L;exports.jsonValueFitsSchema=U;exports.jsonValuesEqual=F;exports.keepTextFormat=fe;exports.manifestSectionKeys=Et;exports.modulePrefix=Ue;exports.nativeDataSourcesKind=Pe;exports.nativeEntitiesKind=Fe;exports.nativeFileKinds=Re;exports.nativeHooksKind=De;exports.nativeI18nKind=xe;exports.nativeManifestKind=V;exports.nativeRbacKind=Je;exports.nativeScriptsKind=_e;exports.nativeStudioPreset=Nt;exports.nativeViewsKind=Ce;exports.nativeWorkflowsKind=Me;exports.newStudioScript=$t;exports.objectFileKind=ne;exports.parseJsonText=E;exports.parseStudioLayout=He;exports.patchJsonText=Y;exports.patchJsonTextDetailed=ue;exports.placeStudioEntry=nt;exports.readTranslations=we;exports.removeStudioLayoutNode=tt;exports.renameStudioEntryRef=st;exports.renameStudioLayoutNode=et;exports.resolveFileKind=ke;exports.safeJson=ve;exports.scriptsFileKind=Ne;exports.serializeStudioLayout=Ze;exports.slugifyModuleId=G;exports.stringifyJsonText=k;exports.studioEntryRef=ze;exports.studioLayoutPath=Be;exports.studioScriptIdentifier=Te;exports.studioScriptLanguages=Ke;exports.textFallbackKind=_;exports.toStudioScriptItem=Ae;exports.writeTranslations=Z;
package/dist/studio.d.ts CHANGED
@@ -3,6 +3,7 @@ import { NiceDataSourceDef } from '@nice2dev/ui';
3
3
  import { NiceDataSourceSchemaTable } from '@nice2dev/ui';
4
4
  import { NiceFormItem } from '@nice2dev/ui';
5
5
  import { NiceHookBinding } from '@nice2dev/ui';
6
+ import { NiceNoCodeStep } from '@nice2dev/ui';
6
7
  import { NiceRbacModel } from '@nice2dev/ui';
7
8
  import { NiceViewDefinition } from '@nice2dev/ui';
8
9
  import { NiceWorkflowDefinition } from '@nice2dev/ui';
@@ -41,12 +42,12 @@ export declare function defineManifestSection<TSchema extends JsonSchema>(sectio
41
42
 
42
43
  /** A starter access model: admin / user × view / create / edit / delete over the module's views and entities. */
43
44
  export declare function deriveDefaultRbac(module: {
44
- manifest?: Row;
45
+ manifest?: Row_2;
45
46
  views?: ReadonlyArray<{
46
47
  id: string;
47
48
  name: string;
48
49
  }>;
49
- entities?: readonly Row[];
50
+ entities?: readonly Row_2[];
50
51
  }): NiceRbacModel;
51
52
 
52
53
  /** Reads how `text` is written: BOM, line breaks, indentation, final newline, colon spacing. */
@@ -65,7 +66,7 @@ export declare function encodeDocument(doc: NiceStudioDocument, model: unknown,
65
66
  export declare const endsWithAny: (...suffixes: string[]) => (path: string) => boolean;
66
67
 
67
68
  /** The module's entities as the tables NiceDataSourceBuilder queries. */
68
- export declare function entitiesToSchemas(entities: readonly Row[]): NiceDataSourceSchemaTable[];
69
+ export declare function entitiesToSchemas(entities: readonly Row_2[]): NiceDataSourceSchemaTable[];
69
70
 
70
71
  /** The file name of a path. */
71
72
  export declare const fileName: (path: string) => string;
@@ -146,12 +147,21 @@ declare interface FormFieldValidation {
146
147
  message?: string;
147
148
  }
148
149
 
150
+ /** A list item back as the stored script: its definition merged onto the entry as stored. */
151
+ export declare function fromStudioScriptItem(item: NiceStudioItem<NiceStudioScriptDef>): unknown;
152
+
149
153
  /**
150
154
  * Translations split into one file per language, edited as one document. A new language gets a
151
155
  * file shaped and formatted like its siblings; a language removed in the editor loses its file.
152
156
  */
153
157
  export declare function i18nFileKind(o?: NiceI18nFileKindOptions): NiceStudioFileKind<NiceStudioTranslations>;
154
158
 
159
+ /**
160
+ * The kind of a stored script: its `kind`, else from what it holds — no-code steps, a SQL language
161
+ * or `sql` text, a C# language (server) — else browser code.
162
+ */
163
+ export declare function inferStudioScriptKind(raw: Row): NiceStudioScriptKind;
164
+
155
165
  /** Whether a layout holds nothing (its file can go). */
156
166
  export declare const isEmptyStudioLayout: (layout: NiceStudioLayout) => boolean;
157
167
 
@@ -219,7 +229,7 @@ export declare function modulePrefix(files: readonly NiceStudioFile[]): string;
219
229
 
220
230
  export declare const nativeDataSourcesKind: NiceStudioFileKind<NiceDataSourceDef[]>;
221
231
 
222
- export declare const nativeEntitiesKind: NiceStudioFileKind<Row_2[]>;
232
+ export declare const nativeEntitiesKind: NiceStudioFileKind<Row_3[]>;
223
233
 
224
234
  /** The file kinds of the native format, in matching order. */
225
235
  export declare const nativeFileKinds: NiceStudioFileKind[];
@@ -228,17 +238,29 @@ export declare const nativeHooksKind: NiceStudioFileKind<NiceHookBinding[]>;
228
238
 
229
239
  export declare const nativeI18nKind: NiceStudioFileKind<NiceStudioTranslations>;
230
240
 
231
- export declare const nativeManifestKind: NiceStudioFileKind<Row_2>;
241
+ export declare const nativeManifestKind: NiceStudioFileKind<Row_3>;
232
242
 
233
243
  export declare const nativeRbacKind: NiceStudioFileKind<NiceRbacModel>;
234
244
 
235
- /** The studio's own format: manifest, entities, translations, views, workflows, data sources, access, hooks. */
245
+ /** `{id}.scripts.json`: `{ scripts: [...], phases: { postInstall: [...] } }` (1.4.6). */
246
+ export declare const nativeScriptsKind: NiceStudioFileKind<NiceStudioScripts>;
247
+
248
+ /** The studio's own format: manifest, entities, translations, views, workflows, data sources, access, hooks, scripts. */
236
249
  export declare const nativeStudioPreset: NiceStudioPreset;
237
250
 
238
251
  export declare const nativeViewsKind: NiceStudioFileKind<NiceStudioItem<NiceViewDefinition>[]>;
239
252
 
240
253
  export declare const nativeWorkflowsKind: NiceStudioFileKind<NiceStudioItem<NiceWorkflowDefinition>[]>;
241
254
 
255
+ /** A new script of a kind, with a starting body in its language. */
256
+ export declare function newStudioScript(spec: NiceStudioNewScript): NiceStudioScriptDef;
257
+
258
+ /** The script kinds, in the order "Add script" offers them. */
259
+ export declare const NICE_STUDIO_SCRIPT_KINDS: readonly NiceStudioScriptKind[];
260
+
261
+ /** Install phases offered for database scripts when the preset names none. */
262
+ export declare const NICE_STUDIO_SCRIPT_PHASES: readonly string[];
263
+
242
264
  /** Options of {@link arrayFileKind}. */
243
265
  export declare interface NiceArrayFileKindOptions {
244
266
  id: string;
@@ -402,8 +424,26 @@ export declare interface NiceObjectFileKindOptions {
402
424
  match(path: string): boolean;
403
425
  }
404
426
 
427
+ /** Options of {@link scriptsFileKind}. */
428
+ export declare interface NiceScriptsFileKindOptions {
429
+ id?: string;
430
+ label?: string;
431
+ labelKey?: string;
432
+ icon?: string;
433
+ match(path: string): boolean;
434
+ /** The property holding the scripts list. Default `scripts`; the file may also be the bare list. */
435
+ property?: string;
436
+ /**
437
+ * The property holding the database scripts per phase. Default `phases`. The same as `property`:
438
+ * that property holds either — a list of scripts or an object of phases (OmniVerk).
439
+ */
440
+ phasesProperty?: string;
441
+ }
442
+
405
443
  /** The studio's own editors. */
406
- export declare type NiceStudioBuiltinEditorId = 'manifest' | 'entities' | 'i18n' | 'views' | 'workflows' | 'permissions' | 'rbac' | 'dataSources' | 'seeds' | 'hooks' | 'script' | 'json' | 'text';
444
+ export declare type NiceStudioBuiltinEditorId = 'manifest' | 'entities' | 'i18n' | 'views' | 'workflows' | 'permissions' | 'rbac' | 'dataSources' | 'seeds' | 'hooks' | 'script'
445
+ /** A list of named scripts and database scripts per phase ({@link NiceStudioScripts}, 1.4.6). */
446
+ | 'scriptList' | 'json' | 'text';
407
447
 
408
448
  /** What a file kind's decode and encode know about the module. */
409
449
  export declare interface NiceStudioCodecContext {
@@ -649,6 +689,16 @@ export declare interface NiceStudioModuleSpec {
649
689
  permissions?: boolean;
650
690
  }
651
691
 
692
+ /** What "Add script" asks for. */
693
+ export declare interface NiceStudioNewScript {
694
+ kind: NiceStudioScriptKind;
695
+ /** The display name; the script's `name` is made from it. */
696
+ name: string;
697
+ language?: string;
698
+ category?: string;
699
+ trigger?: string;
700
+ }
701
+
652
702
  /** A group of modules in a workspace (a category, a product line). */
653
703
  export declare interface NiceStudioPackage {
654
704
  id: string;
@@ -714,6 +764,8 @@ export declare interface NiceStudioPreset {
714
764
  path: string;
715
765
  text: string;
716
766
  } | undefined;
767
+ /** Kinds, categories, triggers and phases of the module's scripts (1.4.6). */
768
+ scripts?: NiceStudioScriptOptions;
717
769
  /** Lifecycle triggers offered by a `hooks` document. */
718
770
  hooks?: {
719
771
  triggers: Array<{
@@ -785,6 +837,73 @@ export declare interface NiceStudioRevision {
785
837
  path?: string;
786
838
  }
787
839
 
840
+ /** A named script of a module (1.4.6). Fields the studio does not edit stay in the stored entry. */
841
+ export declare interface NiceStudioScriptDef {
842
+ id?: string;
843
+ /** The name other scripts and the app call it by (unique in the module). */
844
+ name: string;
845
+ displayName?: string;
846
+ description?: string;
847
+ kind: NiceStudioScriptKind;
848
+ /** `typescript`, `javascript`, `csharp`, `sql`… (none for a no-code script). */
849
+ language?: string;
850
+ /** Free grouping: `formatting`, `validation`, `integration`… */
851
+ category?: string;
852
+ /** What runs it: an event, a schedule, a button (one of the preset's `scripts.triggers`). */
853
+ trigger?: string;
854
+ parameters?: NiceStudioScriptParameter[];
855
+ returnType?: string;
856
+ /** The code (frontend, backend, SQL). */
857
+ source?: string;
858
+ /** A file of the module holding the code instead of `source`. */
859
+ sourcePath?: string;
860
+ /** The steps of a no-code script. */
861
+ steps?: NiceNoCodeStep[];
862
+ }
863
+
864
+ /**
865
+ * What a script is (1.4.6): code run in the browser (`frontend`), code run on the server
866
+ * (`backend`), no-code steps (`noCode`, run by `runNoCodeScript`) or a SQL query or procedure.
867
+ */
868
+ export declare type NiceStudioScriptKind = 'frontend' | 'backend' | 'noCode' | 'sql';
869
+
870
+ /** How a preset's scripts look (1.4.6). */
871
+ export declare interface NiceStudioScriptOptions {
872
+ /** The kinds "Add script" offers. Default: all four. */
873
+ kinds?: NiceStudioScriptKind[];
874
+ /** Categories offered (the module's own are offered too). */
875
+ categories?: string[];
876
+ /** What can run a script. */
877
+ triggers?: Array<{
878
+ id: string;
879
+ label: string;
880
+ description?: string;
881
+ }>;
882
+ /** Install phases offered for database scripts. Default: preInstall, postInstall, preUninstall, postUninstall. */
883
+ phases?: string[];
884
+ }
885
+
886
+ /** A parameter of a script. */
887
+ export declare interface NiceStudioScriptParameter {
888
+ name: string;
889
+ /** Its type as the script's language writes it (`string`, `Date | string`, `decimal`). */
890
+ type?: string;
891
+ description?: string;
892
+ default?: unknown;
893
+ }
894
+
895
+ /** The model of the `scriptList` editor (1.4.6): named scripts and database scripts per phase. */
896
+ export declare interface NiceStudioScripts {
897
+ scripts: Array<NiceStudioItem<NiceStudioScriptDef>>;
898
+ /** SQL statements per install phase: `{ postInstall: ['CREATE INDEX …'] }`. */
899
+ phases?: Record<string, string[]>;
900
+ /**
901
+ * What the file can hold when one property keeps either (OmniVerk's `scripts` is a list of
902
+ * scripts or an object of phases): only named scripts, or only phases. Absent: both.
903
+ */
904
+ holds?: 'scripts' | 'phases';
905
+ }
906
+
788
907
  /** The model of the `seeds` editor: rows per entity, plus demo rows. */
789
908
  export declare interface NiceStudioSeeds {
790
909
  seeds: Record<string, Array<Record<string, unknown>>>;
@@ -907,9 +1026,18 @@ declare type Row = Record<string, unknown>;
907
1026
 
908
1027
  declare type Row_2 = Record<string, unknown>;
909
1028
 
1029
+ declare type Row_3 = Record<string, unknown>;
1030
+
910
1031
  /** Parses JSON without a BOM and returns `fallback` when the text is not JSON. */
911
1032
  export declare function safeJson<T = unknown>(text: string, fallback: T): T;
912
1033
 
1034
+ /**
1035
+ * A file of named scripts and database scripts per phase (the `scriptList` editor). Scripts the
1036
+ * form does not understand stay raw and round-trip as they are; a file whose phases are not lists
1037
+ * of SQL text opens as raw JSON.
1038
+ */
1039
+ export declare function scriptsFileKind(o: NiceScriptsFileKindOptions): NiceStudioFileKind<NiceStudioScripts>;
1040
+
913
1041
  /** A layout's file text: two-space JSON with a final newline, in the line ending of `previous`. */
914
1042
  export declare function serializeStudioLayout(layout: NiceStudioLayout, previous?: string): string;
915
1043
 
@@ -928,9 +1056,18 @@ export declare const studioEntryRef: (group: string, key: string) => string;
928
1056
  */
929
1057
  export declare function studioLayoutPath(files: readonly NiceStudioFile[]): string;
930
1058
 
1059
+ /** `"Send invoice"` → `sendInvoice`: a name usable as a function's. */
1060
+ export declare function studioScriptIdentifier(name: string): string;
1061
+
1062
+ /** The languages of a kind, the first being the default (none for no-code). */
1063
+ export declare function studioScriptLanguages(kind: NiceStudioScriptKind): string[];
1064
+
931
1065
  /** Any other file, edited as text. */
932
1066
  export declare const textFallbackKind: NiceStudioFileKind<string>;
933
1067
 
1068
+ /** A stored script as a list item: with a definition when the form can keep every field it edits. */
1069
+ export declare function toStudioScriptItem(raw: unknown, index: number): NiceStudioItem<NiceStudioScriptDef>;
1070
+
934
1071
  /** The file with its translations replaced, in the same place they were. */
935
1072
  export declare function writeTranslations(root: unknown, entries: Record<string, string>): unknown;
936
1073