firstly 0.0.13 → 0.0.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.
Files changed (104) hide show
  1. package/CHANGELOG.md +8 -0
  2. package/esm/ROUTES.d.ts +2 -0
  3. package/esm/ROUTES.js +1 -0
  4. package/esm/api/index.d.ts +8 -0
  5. package/esm/auth/AuthController.d.ts +12 -23
  6. package/esm/auth/AuthController.js +12 -31
  7. package/esm/auth/server/AuthController.server.d.ts +11 -11
  8. package/esm/auth/server/AuthController.server.js +83 -18
  9. package/esm/auth/server/helperFirstly.d.ts +1 -1
  10. package/esm/auth/server/helperFirstly.js +1 -0
  11. package/esm/auth/server/module.d.ts +3 -6
  12. package/esm/auth/server/providers/github.d.ts +2 -1
  13. package/esm/auth/server/providers/github.js +1 -1
  14. package/esm/auth/static/assets/Page-B0XXxe0N.d.ts +6 -0
  15. package/esm/auth/static/assets/Page-B0XXxe0N.js +1 -0
  16. package/esm/auth/static/assets/Page-DdKMiUZn.d.ts +6 -0
  17. package/esm/auth/static/assets/Page-DdKMiUZn.js +20 -0
  18. package/esm/auth/static/assets/Page-UV_hqY7I.d.ts +6 -0
  19. package/esm/auth/static/assets/Page-UV_hqY7I.js +1 -0
  20. package/esm/auth/static/assets/Page-mK42zGEw.css +1 -0
  21. package/esm/auth/static/assets/index-C9jzxOBu.d.ts +151 -0
  22. package/esm/auth/static/assets/index-C9jzxOBu.js +42 -0
  23. package/esm/auth/static/index.html +2 -2
  24. package/esm/auth/types.d.ts +26 -3
  25. package/esm/bin/cmd.js +339 -139
  26. package/esm/feedback/FeedbackController.js +57 -51
  27. package/esm/feedback/server/index.d.ts +6 -15
  28. package/esm/feedback/server/index.js +4 -5
  29. package/esm/feedback/types.d.ts +14 -0
  30. package/esm/feedback/types.js +4 -0
  31. package/esm/feedback/ui/DialogIssue.svelte +78 -62
  32. package/esm/feedback/ui/DialogIssue.svelte.d.ts +20 -18
  33. package/esm/feedback/ui/DialogIssues.svelte +37 -28
  34. package/esm/feedback/ui/DialogIssues.svelte.d.ts +20 -18
  35. package/esm/feedback/ui/DialogMilestones.svelte +18 -12
  36. package/esm/feedback/ui/DialogMilestones.svelte.d.ts +18 -16
  37. package/esm/feedback/ui/Feedback.svelte +11 -9
  38. package/esm/feedback/ui/Feedback.svelte.d.ts +16 -14
  39. package/esm/mail/server/index.d.ts +9 -2
  40. package/esm/mail/server/index.js +3 -1
  41. package/esm/mail/templates/DefaultMail.svelte +64 -44
  42. package/esm/mail/templates/DefaultMail.svelte.d.ts +28 -26
  43. package/esm/server/index.d.ts +0 -0
  44. package/esm/server/index.js +1 -0
  45. package/esm/storeItem.d.ts +1 -1
  46. package/esm/storeList.d.ts +1 -1
  47. package/esm/sveltekit/server/index.d.ts +0 -9
  48. package/esm/ui/Button.svelte +79 -56
  49. package/esm/ui/Button.svelte.d.ts +34 -24
  50. package/esm/ui/Clipboardable.svelte +18 -11
  51. package/esm/ui/Clipboardable.svelte.d.ts +34 -23
  52. package/esm/ui/Field.svelte +189 -136
  53. package/esm/ui/Field.svelte.d.ts +13 -6
  54. package/esm/ui/FieldGroup.svelte +74 -53
  55. package/esm/ui/FieldGroup.svelte.d.ts +17 -6
  56. package/esm/ui/Grid.svelte +110 -86
  57. package/esm/ui/Grid.svelte.d.ts +17 -6
  58. package/esm/ui/GridLoading.svelte +10 -5
  59. package/esm/ui/GridLoading.svelte.d.ts +19 -17
  60. package/esm/ui/GridPaginate.svelte +30 -23
  61. package/esm/ui/GridPaginate.svelte.d.ts +21 -19
  62. package/esm/ui/Icon.svelte +67 -32
  63. package/esm/ui/Icon.svelte.d.ts +52 -43
  64. package/esm/ui/Loading.svelte +5 -3
  65. package/esm/ui/Loading.svelte.d.ts +29 -18
  66. package/esm/ui/Tooltip.svelte +22 -19
  67. package/esm/ui/Tooltip.svelte.d.ts +30 -20
  68. package/esm/ui/dialog/DialogForm.svelte +48 -41
  69. package/esm/ui/dialog/DialogForm.svelte.d.ts +18 -16
  70. package/esm/ui/dialog/DialogManagement.svelte.d.ts +22 -21
  71. package/esm/ui/dialog/DialogPrimitive.svelte +32 -26
  72. package/esm/ui/dialog/DialogPrimitive.svelte.d.ts +35 -25
  73. package/esm/ui/dialog/FormEditAction.svelte +20 -12
  74. package/esm/ui/dialog/FormEditAction.svelte.d.ts +13 -6
  75. package/esm/ui/dialog/dialog.d.ts +1 -1
  76. package/esm/ui/internals/FieldContainer.svelte +13 -6
  77. package/esm/ui/internals/FieldContainer.svelte.d.ts +37 -28
  78. package/esm/ui/internals/Input.svelte +110 -76
  79. package/esm/ui/internals/Input.svelte.d.ts +34 -32
  80. package/esm/ui/internals/Textarea.svelte +39 -31
  81. package/esm/ui/internals/Textarea.svelte.d.ts +31 -28
  82. package/esm/ui/internals/select/MultiSelectMelt.svelte +174 -126
  83. package/esm/ui/internals/select/MultiSelectMelt.svelte.d.ts +29 -27
  84. package/esm/ui/internals/select/SelectMelt.svelte +168 -133
  85. package/esm/ui/internals/select/SelectMelt.svelte.d.ts +34 -32
  86. package/esm/ui/internals/select/SelectRadio.svelte +17 -11
  87. package/esm/ui/internals/select/SelectRadio.svelte.d.ts +24 -22
  88. package/esm/ui/link/Link.svelte +11 -6
  89. package/esm/ui/link/Link.svelte.d.ts +31 -22
  90. package/esm/ui/link/LinkPlus.svelte +19 -16
  91. package/esm/ui/link/LinkPlus.svelte.d.ts +20 -18
  92. package/esm/vite/index.d.ts +2 -3
  93. package/esm/vite/index.js +33 -26
  94. package/package.json +5 -5
  95. package/esm/auth/static/assets/Page-BUfjaN-D.d.ts +0 -5
  96. package/esm/auth/static/assets/Page-BUfjaN-D.js +0 -19
  97. package/esm/auth/static/assets/Page-CJ58H1vl.css +0 -1
  98. package/esm/auth/static/assets/Page-CaDAqmBS.d.ts +0 -5
  99. package/esm/auth/static/assets/Page-CaDAqmBS.js +0 -1
  100. package/esm/auth/static/assets/Page-DhdZddzJ.d.ts +0 -5
  101. package/esm/auth/static/assets/Page-DhdZddzJ.js +0 -1
  102. package/esm/auth/static/assets/index-D-Ztdt2o.d.ts +0 -54
  103. package/esm/auth/static/assets/index-D-Ztdt2o.js +0 -2
  104. /package/esm/auth/static/assets/{index-BDy4A_14.css → index-DKWpA6v7.css} +0 -0
@@ -1,19 +0,0 @@
1
- var Es=Object.defineProperty;var ui=n=>{throw TypeError(n)};var As=(n,e,t)=>e in n?Es(n,e,{enumerable:!0,configurable:!0,writable:!0,value:t}):n[e]=t;var c=(n,e,t)=>As(n,typeof e!="symbol"?e+"":e,t),fi=(n,e,t)=>e.has(n)||ui("Cannot "+t);var Re=(n,e,t)=>(fi(n,e,"read from private field"),t?t.call(n):e.get(n)),Me=(n,e,t)=>e.has(n)?ui("Cannot add the same private member more than once"):e instanceof WeakSet?e.add(n):e.set(n,t),Ne=(n,e,t,r)=>(fi(n,e,"write to private field"),r?r.call(n,t):e.set(n,t),t);import{n as se,s as Ts,r as gt,a as wt,i as Fs,g as Ss,S as st,b as at,c as Wi,e as Hr,d as N,t as S,f as Hi,h as $,j as Gi,k as L,l as dt,m as $s,o as di,p as Ps,q as ci,u as Ds,v as Qi,w as zi,x as Ki,y as Xi,z as Mr,A as M,B as hi,C as hr,D as Se,E as pi,F as Rs,G as Ms,H as ee,I as V,J as F,K as Fe,L as C,M as Ce,N as pr,O as ye,P as te,Q as re,R as ie,T as _t,U as bt,V as vt,W as Ns}from"./index-D-Ztdt2o.js";function Ls(n,e){const t={},r={},i={$$scope:1};let s=n.length;for(;s--;){const a=n[s],o=e[s];if(o){for(const f in a)f in o||(r[f]=1);for(const f in o)i[f]||(t[f]=o[f],i[f]=1);n[s]=o}else for(const f in a)i[f]=1}for(const a in r)a in t||(t[a]=void 0);return t}const lt=[];function Gr(n,e){return{subscribe:yr(n,e).subscribe}}function yr(n,e=se){let t;const r=new Set;function i(o){if(wt(n,o)&&(n=o,t)){const f=!lt.length;for(const l of r)l[1](),lt.push(l,n);if(f){for(let l=0;l<lt.length;l+=2)lt[l][0](lt[l+1]);lt.length=0}}}function s(o){i(o(n))}function a(o,f=se){const l=[o,f];return r.add(l),r.size===1&&(t=e(i,s)||se),o(n),()=>{r.delete(l),r.size===0&&t&&(t(),t=null)}}return{set:i,update:s,subscribe:a}}function mr(n,e,t){const r=!Array.isArray(n),i=r?[n]:n;if(!i.every(Boolean))throw new Error("derived() expects stores as input, got a falsy value");const s=e.length<2;return Gr(t,(a,o)=>{let f=!1;const l=[];let u=0,d=se;const p=()=>{if(u)return;d();const y=e(r?l[0]:l,a,o);s?a(y):d=Fs(y)?y:se},h=i.map((y,w)=>Ts(y,I=>{l[w]=I,u&=~(1<<w),f&&p()},()=>{u|=1<<w}));return f=!0,p(),function(){gt(h),d(),f=!1}})}const Bs=n=>{const{subscribe:e,update:t}=yr(n);return{subscribe:e,set:(r={})=>{t(i=>Object.assign(i,r))}}},gr=Bs({mode:"window",basePath:null}),Cr=(n=Ss(gr).mode)=>{let e="popstate";n==="window"&&(e="popstate"),n==="hash"&&(e="hashchange"),window.dispatchEvent(new Event(e))},yi={go:(n=0)=>{history.go(n),Cr()},push:(n,e=null)=>{history.pushState(e,"",n),Cr()},replace:(n,e=null)=>{history.replaceState(e,"",n),Cr()}},qs=n=>{const e=n.match(/^(\/[^?#]*)?/),t=n.match(/\?([^#]*)?/),r=n.match(/#(.*)?/);return{path:(e==null?void 0:e[1])||"/",query:t!=null&&t[1]?`?${t==null?void 0:t[1]}`:"",hash:r!=null&&r[1]?`#${r==null?void 0:r[1]}`:""}},mi=()=>{const{pathname:n,search:e,hash:t}=document.location;return{path:n,query:e,hash:t}},gi=()=>{let n=document.location.hash.substring(1);return n[0]!=="/"&&(n="/"+n),qs(n)},js=Gr(mi(),n=>{const e=()=>n(mi());return window.addEventListener("popstate",e),()=>window.removeEventListener("popstate",e)}),Js=Gr(gi(),n=>{const e=()=>n(gi());return window.addEventListener("hashchange",e),()=>window.removeEventListener("hashchange",e)}),Qr=mr([gr,js,Js],([n,e,t],r)=>{n.mode==="window"&&r(e),n.mode==="hash"&&r(t)}),Us=mr(Qr,n=>n.path);mr(Qr,n=>n.query);mr(Qr,n=>n.hash);const Xt=n=>n.split(/(?=\/)/),Vs=()=>{let n=0;return()=>n++},wi=(n,e)=>e===null?n:n.startsWith(e)?n.slice(e.length):n;function _i(n){let e;const t=n[11].default,r=Qi(t,n,n[10],null);return{c(){r&&r.c()},m(i,s){r&&r.m(i,s),e=!0},p(i,s){r&&r.p&&(!e||s&1024)&&zi(r,t,i,i[10],e?Xi(t,i[10],s,null):Ki(i[10]),null)},i(i){e||(S(r,i),e=!0)},o(i){$(r,i),e=!1},d(i){r&&r.d(i)}}}function Ws(n){let e=bi(wi(n[1],n[2].basePath),n[0],n[3]),t,r,i=e&&_i(n);return{c(){i&&i.c(),t=Hr()},m(s,a){i&&i.m(s,a),N(s,t,a),r=!0},p(s,[a]){a&15&&(e=bi(wi(s[1],s[2].basePath),s[0],s[3])),e?i?(i.p(s,a),a&15&&S(i,1)):(i=_i(s),i.c(),S(i,1),i.m(t.parentNode,t)):i&&(Hi(),$(i,1,1,()=>{i=null}),Gi())},i(s){r||(S(i),r=!0)},o(s){$(i),r=!1},d(s){s&&L(t),i&&i.d(s)}}}const Hs=(n,e,t,r,i)=>{const s=(l,u,d)=>{const p=Xt(u).filter(h=>h!=="/").length;return(d??0)+(l?1:p)},a=(l,u)=>{const d={invalidPath:`<Route path="${l==null?void 0:l.path}" /> has invalid path. Path must start with '/'`,fallbackOutsideRoot:"<Route fallback /> cannot be outside root <Route />",pathOutsideRoot:`<Route path="${l==null?void 0:l.path}" /> cannot be outside root <Route />`,fallbackInsideFallback:"<Route fallback /> cannot be inside <Route fallback>",pathInsideFallback:`<Route path="${l==null?void 0:l.path}" /> cannot be inside <Route fallback>`};if(l.path[0]!=="/")throw new Error(d.invalidPath);if(l.root&&l.fallback)throw new Error(d.fallbackOutsideRoot);if(l.root&&l.path!=="/")throw new Error(d.pathOutsideRoot);if(u!=null&&u.fallback&&l.fallback)throw new Error(d.fallbackInsideFallback);if(u!=null&&u.fallback&&!l.fallback)throw new Error(d.pathInsideFallback)},o=s(t,r,i==null?void 0:i.depth),f={id:n,root:e,fallback:t,path:r,depth:o};return a(f,i),f},Gs=()=>{const{subscribe:n,update:e}=yr([]);return{subscribe:n,update:t=>e(r=>[...r.filter(i=>t.id!==i.id),t]),remove:t=>e(r=>r.filter(i=>t.id!==i.id))}},bi=(n,e,t)=>{const r=(l,u,d,p)=>{let h=Xt(l).filter(I=>I!=="/"),y=Xt(d).filter(I=>I!=="/"),w="";if(d==="/")return u||h.length===p;for(let I=p-y.length;I<p;I++)w=w+h[I];return d===w},i=(l,u,d)=>{var y,w,I,O;let p=Xt(l).filter(v=>v!=="/"),h=!1;for(let v=0;v<(d==null?void 0:d.length)&&!h;v++)(y=d[v])!=null&&y.fallback||(h=r(l,((w=d[v])==null?void 0:w.root)??!1,((I=d[v])==null?void 0:I.path)??"",((O=d[v])==null?void 0:O.depth)??0));return p.length>=u&&!h},{root:s,fallback:a,path:o,depth:f}=e;return a?i(n,f,t):r(n,s,o,f)},Qs=Vs(),Er={},vi={};function zs(n,e,t){let r,i,s,a,o;dt(n,Us,v=>t(1,s=v)),dt(n,gr,v=>t(2,a=v));let{$$slots:f={},$$scope:l}=e;const u=Qs(),d=!$s(Er);let{fallback:p=!1}=e,{path:h="/"}=e;const y=yr();dt(n,y,v=>t(0,r=v));const w=di(Er);dt(n,w,v=>t(9,i=v));const I=Gs(),O=di(vi);return dt(n,O,v=>t(3,o=v)),Ps(()=>O==null?void 0:O.remove(r)),ci(Er,y),ci(vi,I),n.$$set=v=>{"fallback"in v&&t(7,p=v.fallback),"path"in v&&t(8,h=v.path),"$$scope"in v&&t(10,l=v.$$scope)},n.$$.update=()=>{n.$$.dirty&896&&Ds(y,r=Hs(u,d,p,h,i),r),n.$$.dirty&1&&(O==null||O.update(r))},[r,s,a,o,y,w,O,p,h,i,l,f]}class Ue extends st{constructor(e){super(),at(this,e,zs,Ws,Wi,{fallback:7,path:8})}}const ki=n=>{var o;const e=(o=n.target)==null?void 0:o.closest("a[href]"),t=e==null?void 0:e.href;if(e===null||t===null)return!0;const r=["","true"].includes(e.getAttribute("data-handle-ignore")??"false"),i=(e.getAttribute("target")??"_self")!=="_self",s=n.metaKey||n.ctrlKey||n.altKey||n.shiftKey,a=new URL(t).origin!==document.location.origin;if(r||i||s||a)return!0;t===document.location.href?yi.replace(t):yi.push(t),n.preventDefault()},Ks=n=>(n.addEventListener("click",ki),{destroy:()=>{n.removeEventListener("click",ki)}});function Xs(n){let e,t,r,i;const s=n[5].default,a=Qi(s,n,n[4],null);let o=[{href:n[0]},n[1]],f={};for(let l=0;l<o.length;l+=1)f=Mr(f,o[l]);return{c(){e=M("a"),a&&a.c(),hi(e,f)},m(l,u){N(l,e,u),a&&a.m(e,null),t=!0,r||(i=[hr(Ks.call(null,e)),Se(e,"click",n[6])],r=!0)},p(l,[u]){a&&a.p&&(!t||u&16)&&zi(a,s,l,l[4],t?Xi(s,l[4],u,null):Ki(l[4]),null),hi(e,f=Ls(o,[(!t||u&1)&&{href:l[0]},u&2&&l[1]]))},i(l){t||(S(a,l),t=!0)},o(l){$(a,l),t=!1},d(l){l&&L(e),a&&a.d(l),r=!1,gt(i)}}}const Zs=(n,e,t)=>(n==="hash"?"#":"")+(e??"")+t;function Ys(n,e,t){let r;const i=["href"];let s=pi(e,i),a;dt(n,gr,d=>t(3,a=d));let{$$slots:o={},$$scope:f}=e,{href:l}=e;function u(d){Ms.call(this,n,d)}return n.$$set=d=>{e=Mr(Mr({},e),Rs(d)),t(1,s=pi(e,i)),"href"in d&&t(2,l=d.href),"$$scope"in d&&t(4,f=d.$$scope)},n.$$.update=()=>{n.$$.dirty&12&&t(0,r=Zs(a.mode,a.basePath,l))},[r,s,l,a,f,o,u]}class Ve extends st{constructor(e){super(),at(this,e,Ys,Xs,Wi,{href:2})}}class tt{constructor(...e){c(this,"fields");c(this,"options",{});c(this,"target");c(this,"readonly",!0);c(this,"allowNull",!1);c(this,"dbReadOnly",!1);c(this,"isServerExpression",!1);c(this,"key","");c(this,"caption","");c(this,"inputType","");c(this,"dbName","");c(this,"valueType");this.fields=e}apiUpdateAllowed(e){throw new Error("Method not implemented.")}displayValue(e){throw new Error("Method not implemented.")}includedInApi(e){throw new Error("Method not implemented.")}toInput(e,t){throw new Error("Method not implemented.")}fromInput(e,t){throw new Error("Method not implemented.")}getDbName(){return Promise.resolve("")}getId(e){let t=i=>e[i.key];typeof e=="function"&&(t=e);let r="";return this.fields.forEach(i=>{r.length>0&&(r+=","),r+=i.valueConverter.toJson(t(i))}),r}get valueConverter(){throw new Error("cant get value converter of compound id")}isEqualTo(e){let t={},i=e.toString().split(",");return this.fields.forEach((s,a)=>{t[s.key]=s.valueConverter.fromJson(i[a])}),t}}function ne(n,e=!0){var r;if(n===void 0)throw new Error("entity is undefined");let t=n[et];if(!t&&e)throw new Error("item "+(((r=n.constructor)==null?void 0:r.name)||n)+" was not initialized using a context");return t}const et=Symbol.for("entityMember"),Zi=Symbol.for("entityInfo"),Yi=Symbol.for("entityInfo_key");function Ae(n,e=!0){if(n===void 0){if(e)throw new Error("Undefined is not an entity :)");return}let t=n[Zi];if(!t&&e)throw new Error(n.prototype.constructor.name+" is not a known entity, did you forget to set @Entity() or did you forget to add the '@' before the call to Entity?");return t}function xs(n){return n[Yi]}function Ar(n,e){return{[xi]:{toType:n,type:e}}}const xi=Symbol.for("relationInfo");function ea(n){return n==null?void 0:n[xi]}const Nr=Symbol.for("fieldRelationInfo");function oe(n){if(n)return n[Nr]}function ta(n,e,t){for(const r of n.fields.toArray()){const i=ea(r.options);if(i&&!r[Nr]){const s=i.toType(),a=e.repo(s,t),o=r.options;r[Nr]={type:i.type,toEntity:s,options:o,toRepo:a,getFields:()=>{let f=o.field,l={fields:o.fields,compoundIdField:void 0};function u(h){return Error(`Error for relation: "${n.metadata.key}.${r.key}", `+h)}let d=()=>f||l.fields;if(i.type==="toMany"&&!d()){for(const h of a.fields.toArray())if(!d()){const y=oe(h),w=h.options;if(y&&y.toEntity===n.metadata.entityType){if(y.type==="reference")f=h.key;else if(y.type==="toOne"){if(w.field)f=w.field;else if(w.fields){let I={};for(const O in w.fields)if(Object.prototype.hasOwnProperty.call(w.fields,O)){const v=w.fields[O];I[v]=O}l.fields=I}}}}if(!d())throw u(`No matching field found on target "${a.metadata.key}". Please specify field/fields`)}function p(h,y){const w=y.fields.find(h);if(!w)throw u(`Field "${h}" was not found in "${y.key}".`);return w}i.type==="reference"&&(f=r.key),f&&(i.type==="toOne"||i.type==="reference"?a.metadata.idMetadata.field instanceof tt?l.compoundIdField=f:l.fields={[a.metadata.idMetadata.field.key]:f}:n.metadata.idMetadata.field instanceof tt?l.compoundIdField=f:l.fields={[f]:n.metadata.idMetadata.field.key});for(const h in l.fields)Object.prototype.hasOwnProperty.call(l.fields,h)&&(p(h,a.metadata),p(l.fields[h],n.metadata));return l}}}}}class D{constructor(e){c(this,"apply");this.apply=e}static throwErrorIfFilterIsEmpty(e,t){if(D.isFilterEmpty(e))throw{message:`${t}: requires a filter to protect against accidental delete/update of all rows`,httpStatusCode:400}}static isFilterEmpty(e){if(e.$and){for(const t of e.$and)if(!D.isFilterEmpty(t))return!1}if(e.$or){for(const t of e.$or)if(D.isFilterEmpty(t))return!0;return!1}return Object.keys(e).filter(t=>!["$or","$and"].includes(t)).length==0}static async getPreciseValues(e,t){const r=new sr;return await D.fromEntityFilter(e,t).__applyToConsumer(r),r.preciseValues}async getPreciseValues(){const e=new sr;return await this.__applyToConsumer(e),e.preciseValues}static createCustom(e,t=""){let r={key:t,rawFilterTranslator:e};return Object.assign(i=>{if(i==null&&(i={}),!r.key)throw"Usage of custom filter before a key was assigned to it";return{[rt+r.key]:i}},{rawFilterInfo:r})}static entityFilterToJson(e,t){return D.fromEntityFilter(e,t).toJson()}static entityFilterFromJson(e,t){return Zt(e,{get:r=>t[r]})}static fromEntityFilter(e,t){let r=[];for(const i in t)if(Object.prototype.hasOwnProperty.call(t,i)){let s=t[i];if(i=="$or")r.push(new na(...s.map(a=>D.fromEntityFilter(e,a))));else if(i=="$not")r.push(new sa(D.fromEntityFilter(e,s)));else if(i=="$and")r.push(new Ii(...s.map(a=>D.fromEntityFilter(e,a))));else if(i.startsWith(rt))r.push(new D(a=>{a.custom(i.substring(rt.length),s)}));else if(i==en)r.push(new D(a=>a.databaseCustom(s)));else{const a=e.fields[i],o=oe(a),f=a.options;let l=(o==null?void 0:o.type)==="toOne"?f.fields?new ia(a,e.fields,f):new ra(e.fields[f.field]):new rr(a),u=!1;if(s!==void 0&&s!=null){s.$id!==void 0&&(s=s.$id);for(const d in s)if(Object.prototype.hasOwnProperty.call(s,d)){const p=s[d];switch(d){case"$gte":case">=":r.push(l.isGreaterOrEqualTo(p)),u=!0;break;case"$gt":case">":r.push(l.isGreaterThan(p)),u=!0;break;case"$lte":case"<=":r.push(l.isLessOrEqualTo(p)),u=!0;break;case"$lt":case"<":r.push(l.isLessThan(p)),u=!0;break;case"$ne":case"$not":case"!=":case"$nin":u=!0,Array.isArray(p)?r.push(l.isNotIn(p)):r.push(l.isDifferentFrom(p));break;case"$in":u=!0,r.push(l.isIn(p));break;case"$contains":u=!0,r.push(l.contains(p));break;case"$startsWith":u=!0,r.push(l.startsWith(p));break;case"$endsWith":u=!0,r.push(l.endsWith(p));break;case"$notContains":u=!0,r.push(l.notContains(p));break}}Array.isArray(s)&&(u=!0,r.push(l.isIn(s)))}!u&&s!==void 0&&r.push(l.isEqualTo(s))}}return new Ii(...r)}__applyToConsumer(e){this.apply(e)}static async resolve(e){return typeof e=="function"?await e():e}toJson(){let e=new ir;return this.__applyToConsumer(e),e.result}static async translateCustomWhere(e,t,r){let i=new nr(async(s,a)=>{let o=[];for(const f in t.entityType){const l=t.entityType[f];l&&l.rawFilterInfo&&l.rawFilterInfo.rawFilterTranslator&&l.rawFilterInfo.key==s&&o.push(await D.fromEntityFilter(t,await l.rawFilterInfo.rawFilterTranslator(a,r)))}return o});return e.__applyToConsumer(i),await i.resolve(),e=new D(s=>i.applyTo(s)),e}}class rr{constructor(e){c(this,"metadata");this.metadata=e}processVal(e){if(Ae(this.metadata.valueType,!1)){if(e==null){if(e===null&&!this.metadata.allowNull){const r=oe(this.metadata);if((r==null?void 0:r.type)==="reference")return r.toRepo.metadata.idMetadata.field.options.valueType===Number?0:""}return null}return typeof e=="string"||typeof e=="number"?e:ne(e).getId()}return e}contains(e){return new D(t=>t.containsCaseInsensitive(this.metadata,e))}notContains(e){return new D(t=>t.notContainsCaseInsensitive(this.metadata,e))}startsWith(e){return new D(t=>t.startsWithCaseInsensitive(this.metadata,e))}endsWith(e){return new D(t=>t.endsWithCaseInsensitive(this.metadata,e))}isLessThan(e){return e=this.processVal(e),new D(t=>t.isLessThan(this.metadata,e))}isGreaterOrEqualTo(e){return e=this.processVal(e),new D(t=>t.isGreaterOrEqualTo(this.metadata,e))}isNotIn(e){return new D(t=>{for(const r of e)t.isDifferentFrom(this.metadata,this.processVal(r))})}isDifferentFrom(e){return e=this.processVal(e),e==null&&this.metadata.allowNull?new D(t=>t.isNotNull(this.metadata)):new D(t=>t.isDifferentFrom(this.metadata,e))}isLessOrEqualTo(e){return e=this.processVal(e),new D(t=>t.isLessOrEqualTo(this.metadata,e))}isGreaterThan(e){return e=this.processVal(e),new D(t=>t.isGreaterThan(this.metadata,e))}isEqualTo(e){return e=this.processVal(e),e==null&&this.metadata.allowNull?new D(t=>t.isNull(this.metadata)):new D(t=>t.isEqualTo(this.metadata,e))}isIn(e){return e=e.map(t=>this.processVal(t)),(e==null?void 0:e.length)==1&&e[0]!=null&&e[0]!==null?new D(t=>t.isEqualTo(this.metadata,e[0])):new D(t=>t.isIn(this.metadata,e))}}class ra extends rr{processVal(e){return e?typeof e=="string"||typeof e=="number"?e:ne(e).getId():null}}class ia{constructor(e,t,r){c(this,"metadata");c(this,"fields");c(this,"relationOptions");this.metadata=e,this.fields=t,this.relationOptions=r}processVal(e){throw new Error("Invalid for Many To One Relation Field")}contains(e){throw new Error("Invalid for Many To One Relation Field")}notContains(e){throw new Error("Invalid for Many To One Relation Field")}endsWith(e){throw new Error("Invalid for Many To One Relation Field")}startsWith(e){throw new Error("Invalid for Many To One Relation Field")}isLessThan(e){throw new Error("Invalid for Many To One Relation Field")}isGreaterOrEqualTo(e){throw new Error("Invalid for Many To One Relation Field")}isNotIn(e){return new D(t=>{e.forEach(r=>this.isDifferentFrom(r).__applyToConsumer(t))})}isDifferentFrom(e){return new D(t=>{const r=[];for(const i in this.relationOptions.fields)if(Object.prototype.hasOwnProperty.call(this.relationOptions.fields,i)){const s=this.relationOptions.fields[i];r.push(new D(a=>new rr(this.fields.find(s)).isDifferentFrom(e[i]).__applyToConsumer(a)))}t.or(r)})}isLessOrEqualTo(e){throw new Error("Invalid for Many To One Relation Field")}isGreaterThan(e){throw new Error("Invalid for Many To One Relation Field")}isEqualTo(e){return new D(t=>{for(const r in this.relationOptions.fields)if(Object.prototype.hasOwnProperty.call(this.relationOptions.fields,r)){const i=this.relationOptions.fields[r];new rr(this.fields.find(i)).isEqualTo(e[r]).__applyToConsumer(t)}})}isIn(e){return new D(t=>{t.or(e.map(r=>this.isEqualTo(r)))})}}class Ii extends D{constructor(...t){super(r=>{for(const i of this.filters)i&&i.__applyToConsumer(r)});c(this,"filters");this.filters=t}add(t){this.filters.push(t)}}class na extends D{constructor(...t){super(r=>{let i=this.filters.filter(s=>s!==void 0);i.length>1?r.or(i):i.length==1&&i[0].__applyToConsumer(r)});c(this,"filters");this.filters=t}}class sa extends D{constructor(t){super(r=>{r.not(t)});c(this,"filter");this.filter=t}}const rt="$custom$",en="$db$",Lr="$an array";class ir{constructor(){c(this,"result",{});c(this,"hasUndefined",!1)}databaseCustom(e){throw new Error("database custom is not allowed with api calls.")}custom(e,t){Array.isArray(t)&&(t={[Lr]:t}),this.add(rt+e,t)}add(e,t){t===void 0&&(this.hasUndefined=!0);let r=this.result;if(!r[e]){r[e]=t;return}let i=r[e];i instanceof Array?i.push(t):i=[i,t],r[e]=i}or(e){this.add("OR",e.map(t=>{let r=new ir;return t.__applyToConsumer(r),r.result}))}not(e){let t=new ir;e.__applyToConsumer(t),this.add("NOT",t.result)}isNull(e){this.add(e.key+".null",!0)}isNotNull(e){this.add(e.key+".null",!1)}isIn(e,t){this.add(e.key+".in",t.map(r=>e.valueConverter.toJson(r)))}isEqualTo(e,t){this.add(e.key,e.valueConverter.toJson(t))}isDifferentFrom(e,t){this.add(e.key+".ne",e.valueConverter.toJson(t))}isGreaterOrEqualTo(e,t){this.add(e.key+".gte",e.valueConverter.toJson(t))}isGreaterThan(e,t){this.add(e.key+".gt",e.valueConverter.toJson(t))}isLessOrEqualTo(e,t){this.add(e.key+".lte",e.valueConverter.toJson(t))}isLessThan(e,t){this.add(e.key+".lt",e.valueConverter.toJson(t))}containsCaseInsensitive(e,t){this.add(e.key+".contains",t)}notContainsCaseInsensitive(e,t){this.add(e.key+".notContains",t)}startsWithCaseInsensitive(e,t){this.add(e.key+".startsWith",t)}endsWithCaseInsensitive(e,t){this.add(e.key+".endsWith",t)}}function Zt(n,e){let t={};function r(o){t.$and||(t.$and=[]),t.$and.push(o)}function i(o,f){t[o]===void 0?t[o]=f:r({[o]:f})}[...n.fields].forEach(o=>{function f(u,d,p=!1,h=!1){let y=e.get(o.key+u);if(y!==void 0){let w=I=>{let O=I;if(p){let J;typeof I=="string"?J=JSON.parse(I):J=I,O=J.map(q=>h?q:o.valueConverter.fromJson(q))}else O=h?O:o.valueConverter.fromJson(O);let v=d(O);v!==void 0&&i(o.key,v)};if(!p&&y instanceof Array)y.forEach(I=>{w(I)});else{p&&typeof y=="string"&&(y=JSON.parse(y));const I=a(y);for(const O of I)w(O)}}}f("",u=>u),f(".gt",u=>({$gt:u})),f(".gte",u=>({$gte:u})),f(".lt",u=>({$lt:u})),f(".lte",u=>({$lte:u})),f(".ne",u=>({$ne:u})),f(".in",u=>u,!0);var l=e.get(o.key+".null");if(l)switch(l=l.toString().trim().toLowerCase(),l){case"y":case"true":case"yes":i(o.key,null);break;default:i(o.key,{$ne:null});break}f(".contains",u=>({$contains:u}),!1,!0),f(".notContains",u=>({$notContains:u}),!1,!0),f(".startsWith",u=>({$startsWith:u}),!1,!0),f(".endsWith",u=>({$endsWith:u}),!1,!0)});let s=e.get("OR");if(s){const f=a(s).map(l=>({$or:l.map(u=>Zt(n,{get:d=>u[d]}))}));f.length==1?t.$or?t.$or.push(f[0].$or):t.$or=f[0].$or:r({$and:f})}if(s=e.get("NOT"),s){let o=a(s);const f=[];for(const l of o)if(Array.isArray(l))for(const u of l)f.push({$not:Zt(n,{get:d=>u[d]})});else f.push({$not:Zt(n,{get:u=>l[u]})});f.length==1?t.$not?t.$not.push(f[0].$not):t.$not=f[0].$not:r({$and:f})}for(const o in n.entityType){const f=n.entityType[o];if(f&&f.rawFilterInfo&&f.rawFilterInfo.rawFilterTranslator){let l=e.get(rt+o);if(l!==void 0){const u=d=>{d[Lr]!=null&&(d=d[Lr]),i(rt+o,d)};Array.isArray(l)?l.forEach(d=>u(d)):u(l)}}}return t;function a(o){if(!Array.isArray(o))return[o];const f=[],l=[];for(const u of o)Array.isArray(u)?l.push(u):f.push(u);return l.push(f),l}}class nr{constructor(e){c(this,"translateCustom");c(this,"commands",[]);c(this,"promises",[]);this.translateCustom=e}applyTo(e){this.commands.forEach(t=>t(e))}or(e){let t;this.promises.push(Promise.all(e.map(async r=>{let i=new nr(this.translateCustom);return r.__applyToConsumer(i),await i.resolve(),new D(s=>i.applyTo(s))})).then(r=>{t=r})),this.commands.push(r=>r.or(t))}not(e){let t;this.promises.push((async()=>{let r=new nr(this.translateCustom);e.__applyToConsumer(r),await r.resolve(),t=new D(i=>r.applyTo(i))})()),this.commands.push(r=>r.not(t))}isEqualTo(e,t){this.commands.push(r=>r.isEqualTo(e,t))}isDifferentFrom(e,t){this.commands.push(r=>r.isDifferentFrom(e,t))}isNull(e){this.commands.push(t=>t.isNull(e))}isNotNull(e){this.commands.push(t=>t.isNotNull(e))}isGreaterOrEqualTo(e,t){this.commands.push(r=>r.isGreaterOrEqualTo(e,t))}isGreaterThan(e,t){this.commands.push(r=>r.isGreaterThan(e,t))}isLessOrEqualTo(e,t){this.commands.push(r=>r.isLessOrEqualTo(e,t))}isLessThan(e,t){this.commands.push(r=>r.isLessThan(e,t))}containsCaseInsensitive(e,t){this.commands.push(r=>r.containsCaseInsensitive(e,t))}notContainsCaseInsensitive(e,t){this.commands.push(r=>r.notContainsCaseInsensitive(e,t))}startsWithCaseInsensitive(e,t){this.commands.push(r=>r.startsWithCaseInsensitive(e,t))}endsWithCaseInsensitive(e,t){this.commands.push(r=>r.endsWithCaseInsensitive(e,t))}isIn(e,t){this.commands.push(r=>r.isIn(e,t))}custom(e,t){this.promises.push((async()=>{let r=await this.translateCustom(e,t);r&&(Array.isArray(r)?r.forEach(i=>i.__applyToConsumer(this)):r.__applyToConsumer(this))})())}databaseCustom(e){this.commands.push(t=>t.databaseCustom(e))}async resolve(){for(;this.promises.length>0;){let e=this.promises;this.promises=[],await Promise.all(e)}}}class sr{constructor(){c(this,"rawValues",{});c(this,"preciseValues",new Proxy(this.rawValues,{get:(e,t)=>{if(t in e){let r=e[t];if(r.bad)return;if(r.values.length>0){const i=oe(r.field);if(i){if(i.type==="reference")return r.values.map(s=>i.toRepo.metadata.idMetadata.getIdFilter(s));throw new Error("Only relations toOne without field are supported.")}return r.values}}}}))}ok(e,...t){let r=this.rawValues[e.key];r?r.values.push(...t.filter(i=>!r.values.includes(i))):this.rawValues[e.key]={field:e,bad:!1,values:[...t]}}notOk(e){let t=this.rawValues[e.key];t?t.bad=!0:this.rawValues[e.key]={field:e,bad:!0,values:[]}}not(e){}or(e){const t=e.map(r=>{let i=new sr;return r.__applyToConsumer(i),i});for(const r of t)for(const i in r.rawValues)if(Object.prototype.hasOwnProperty.call(r.rawValues,i)){const s=r.rawValues[i];s&&(s.bad?this.notOk(s.field):this.ok(s.field,...s.values))}for(const r in this.rawValues)if(Object.prototype.hasOwnProperty.call(this.rawValues,r))for(const i of t)i.rawValues[r]||this.notOk(this.rawValues[r].field)}isEqualTo(e,t){this.ok(e,t)}isDifferentFrom(e,t){this.notOk(e)}isNull(e){this.ok(e,null)}isNotNull(e){this.notOk(e)}isGreaterOrEqualTo(e,t){this.notOk(e)}isGreaterThan(e,t){this.notOk(e)}isLessOrEqualTo(e,t){this.notOk(e)}isLessThan(e,t){this.notOk(e)}containsCaseInsensitive(e,t){this.notOk(e)}notContainsCaseInsensitive(e,t){this.notOk(e)}startsWithCaseInsensitive(e,t){this.notOk(e)}endsWithCaseInsensitive(e,t){this.notOk(e)}isIn(e,t){this.ok(e,...t)}custom(e,t){}databaseCustom(e){}}var aa={};const Tr=Symbol.for("remult-static1");let Yt={defaultRemultFactory:void 0,remultFactory:void 0,defaultRemult:void 0,asyncContext:void 0,columnsOfType:new Map,allEntities:[],classHelpers:new Map,actionInfo:{allActions:[],runningOnServer:!1,runActionWithoutBlockingUI:n=>n(),startBusyWithProgress:()=>({progress:n=>{},close:()=>{}})},fieldOptionsEnricher:void 0,captionTransformer:void 0,defaultDataProvider:()=>{}};typeof process<"u"&&aa.IGNORE_GLOBAL_REMULT_IN_TESTS||typeof globalThis[Tr]>"u"?(globalThis[Tr]=Yt,Yt.remultFactory=()=>tn()):Yt=globalThis[Tr];const T=Yt;function tn(){return T.defaultRemult||(T.defaultRemult=T.defaultRemultFactory()),T.defaultRemult}function oa(){T.remultFactory=()=>tn()}function it(n){const e=n;if(typeof e[Tt]=="function")return e[Tt]();throw Error("Error getting repository internal from "+n)}const Tt=Symbol.for("getInternal");class la{constructor(){c(this,"iAmRemultProxy",!0);c(this,"repoCache",new Map);c(this,"repo",(...e)=>{let t=T,r=this.repoCache.get(e[0]);r||this.repoCache.set(e[0],r=new Map);let i=r.get(e[1]);return i||(i={get fields(){return T.remultFactory().repo(...e).metadata.fields},[Tt](){return t.remultFactory().repo(...e)[Tt]()},relations:s=>t.remultFactory().repo(...e).relations(s),validate:(s,...a)=>t.remultFactory().repo(...e).validate(s,...a),addEventListener:(...s)=>t.remultFactory().repo(...e).addEventListener(...s),count:(...s)=>t.remultFactory().repo(...e).count(...s),create:(...s)=>t.remultFactory().repo(...e).create(...s),delete:s=>t.remultFactory().repo(...e).delete(s),deleteMany:s=>t.remultFactory().repo(...e).deleteMany(s),updateMany:(...s)=>t.remultFactory().repo(...e).updateMany(...s),find:(...s)=>t.remultFactory().repo(...e).find(...s),groupBy:(...s)=>t.remultFactory().repo(...e).groupBy(...s),aggregate:(...s)=>t.remultFactory().repo(...e).aggregate(...s),findFirst:(...s)=>t.remultFactory().repo(...e).findFirst(...s),findOne:(...s)=>t.remultFactory().repo(...e).findOne(...s),findId:(s,a)=>t.remultFactory().repo(...e).findId(s,a),toJson:s=>t.remultFactory().repo(...e).toJson(s),fromJson:(s,a)=>t.remultFactory().repo(...e).fromJson(s,a),getEntityRef:(...s)=>t.remultFactory().repo(...e).getEntityRef(...s),insert:s=>t.remultFactory().repo(...e).insert(s),liveQuery:(...s)=>t.remultFactory().repo(...e).liveQuery(...s),get metadata(){return T.remultFactory().repo(...e).metadata},query:s=>t.remultFactory().repo(...e).query(s),save:s=>t.remultFactory().repo(...e).save(s),upsert:s=>t.remultFactory().repo(...e).upsert(s),update:(s,a)=>t.remultFactory().repo(...e).update(s,a)},r.set(e[1],i),i)})}get liveQuerySubscriber(){return T.remultFactory().liveQuerySubscriber}set liveQuerySubscriber(e){T.remultFactory().liveQuerySubscriber=e}get liveQueryStorage(){return T.remultFactory().liveQueryStorage}set liveQueryStorage(e){T.remultFactory().liveQueryStorage=e}get liveQueryPublisher(){return T.remultFactory().liveQueryPublisher}set liveQueryPublisher(e){T.remultFactory().liveQueryPublisher=e}initUser(){return T.remultFactory().initUser()}call(e,t,...r){return T.remultFactory().call(e,t,...r)}get context(){return T.remultFactory().context}get dataProvider(){return T.remultFactory().dataProvider}set dataProvider(e){T.remultFactory().dataProvider=e}get repCache(){return T.remultFactory().repCache}authenticated(){return T.remultFactory().authenticated()}isAllowed(e){return T.remultFactory().isAllowed(e)}isAllowedForInstance(e,t){return T.remultFactory().isAllowedForInstance(e,t)}clearAllCache(){return T.remultFactory().clearAllCache()}useFetch(e){return T.remultFactory().useFetch(e)}get user(){return T.remultFactory().user}set user(e){T.remultFactory().user=e}get apiClient(){return T.remultFactory().apiClient}set apiClient(e){T.remultFactory().apiClient=e}get subscriptionServer(){return T.remultFactory().subscriptionServer}set subscriptionServer(e){T.remultFactory().subscriptionServer=e}}const ke=new la,ua="$count",fa=Symbol.for("GroupByForApiKey"),da=["sum","avg","min","max","distinctCount"],rn={error500RetryCount:4};function Br(n){return n.replace(/([a-z])([A-Z])/g,"$1 $2").replace(/^./,e=>e.toUpperCase()).replace("Email","eMail")}class ca{constructor(e,t,r){c(this,"repository");c(this,"isReferenceRelation");c(this,"allowNull");c(this,"storedItem");c(this,"id");this.repository=e,this.isReferenceRelation=t,this.allowNull=r}toJson(){if(this.storedItem)return this.item===null?null:this.repository.toJson(this.item)}setId(e){this.repository.metadata.idMetadata.field.valueType==Number&&(e=+e),this.id=e}waitLoadOf(e){return e==null?null:it(this.repository)._getCachedByIdAsync(e,!1)}get(e){if(e==null)return null;const t=it(this.repository)._getCachedById(e,this.isReferenceRelation);return this.isReferenceRelation&&!this.storedItem?!this.allowNull&&(this.id===0||this.id==="")?null:void 0:t}set(e){if(e===null&&!this.allowNull&&this.isReferenceRelation&&(this.id==0||this.id=="")){this.storedItem={item:null};return}if(this.storedItem=void 0,e)if(typeof e=="string"||typeof e=="number")this.id=e;else{let t=ne(e,!1);t&&!this.isReferenceRelation?(it(this.repository)._addToCache(e),this.id=t.getId()):(this.storedItem={item:e},this.id=e[this.repository.metadata.idMetadata.field.key])}else e===null?this.id=null:this.id=void 0}get item(){return this.storedItem?this.storedItem.item:this.get(this.id)}async waitLoad(){return this.waitLoadOf(this.id)}}class Oi{constructor(e){c(this,"url");this.url=e}add(e,t){this.url.indexOf("?")>=0?this.url+="&":this.url+="?",this.url+=encodeURIComponent(e)+"="+encodeURIComponent(t)}addObject(e,t=""){if(e!=null)for(var r in e){let i=e[r];this.add(r+t,i)}}}function yt(n){if(!n)return new Ci;let e;return e||nn(n)&&(e=new ha(n)),e||typeof n=="function"&&(e=new Ci(n)),e}function nn(n){let e=n;return!!(e&&e.get&&e.put&&e.post&&e.delete)}class ha{constructor(e){c(this,"http");this.http=e}async post(e,t){return await ar(()=>Ht(this.http.post(e,t)))}delete(e){return Ht(this.http.delete(e))}put(e,t){return Ht(this.http.put(e,t))}async get(e){return await ar(()=>Ht(this.http.get(e)))}}async function ar(n){var t,r,i,s;let e=0;for(;;)try{return await n()}catch(a){if(((t=a.message)!=null&&t.startsWith("Error occurred while trying to proxy")||(r=a.message)!=null&&r.startsWith("Error occured while trying to proxy")||(i=a.message)!=null&&i.includes("http proxy error")||(s=a.message)!=null&&s.startsWith("Gateway Timeout")||a.status==500)&&e++<rn.error500RetryCount){await new Promise((o,f)=>{setTimeout(()=>{o({})},500)});continue}throw a}}function Ht(n){let e;return n.toPromise!==void 0?e=n.toPromise():e=n,e.then(t=>t&&(t.status==200||t.status==201)&&t.headers&&t.request&&t.data!==void 0?t.data:t).catch(async t=>{throw await pa(t)})}async function pa(n){var s,a,o;let e=await n;var t;e.error?t=e.error:e.isAxiosError&&(typeof((s=e.response)==null?void 0:s.data)=="string"?t=e.response.data:t=(a=e==null?void 0:e.response)==null?void 0:a.data),t||(t=e.message),e.status==0&&e.error.isTrusted&&(t="Network Error"),typeof t=="string"&&(t={message:t}),e.modelState&&(t.modelState=e.modelState);let r=e.status;r===void 0&&(r=(o=e.response)==null?void 0:o.status),r!=null&&(t.httpStatusCode=r);var i=Object.assign(t??{},{});return i}class qr{constructor(e,t){c(this,"apiProvider");c(this,"entityRequested");c(this,"isProxy",!0);this.apiProvider=e,this.entityRequested=t}getEntityDataProvider(e){var t;return(t=this.entityRequested)==null||t.call(this,e),new ya(()=>{var r;return sn((r=this.apiProvider())==null?void 0:r.url,e.key)},()=>yt(this.apiProvider().httpClient),e)}async transaction(e){throw new Error("Method not implemented.")}}function sn(n,e){return n==null&&(n="/api"),n+"/"+e}function zr(n,e){if(n.include){let t={};for(const r in n.include)if(Object.prototype.hasOwnProperty.call(n.include,r)){let i=n.include[r];if(typeof i=="object"){const s=oe(e.fields.find(r));s&&(i=zr(i,s.toRepo.metadata))}t[r]=i}n={...n,include:t}}return n.where&&(n={...n,where:D.entityFilterToJson(e,n.where)}),n.load&&(n={...n,load:n.load(e.fields).map(t=>t.key)}),n}class ya{constructor(e,t,r){c(this,"url");c(this,"http");c(this,"entity");this.url=e,this.http=t,this.entity=r}query(e,t){return this.buildFindRequest(e).run("query",{aggregate:this.buildAggregateOptions(t)}).then(({items:i,aggregates:s})=>({items:i.map(a=>this.translateFromJson(a)),aggregates:s}))}async groupBy(e){const{run:t}=this.buildFindRequest({where:e==null?void 0:e.where,limit:e==null?void 0:e.limit,page:e==null?void 0:e.page}),r=this.buildAggregateOptions(e),i=await t("groupBy",Object.keys(r).length>0?r:void 0);return e!=null&&e.group&&i.forEach(s=>{for(const a of e.group)s[a.key]=a.valueConverter.fromJson(s[a.key])}),i}buildAggregateOptions(e){var t,r,i,s,a,o,f;return{groupBy:(t=e==null?void 0:e.group)==null?void 0:t.map(l=>l.key),sum:(r=e==null?void 0:e.sum)==null?void 0:r.map(l=>l.key),avg:(i=e==null?void 0:e.avg)==null?void 0:i.map(l=>l.key),min:(s=e==null?void 0:e.min)==null?void 0:s.map(l=>l.key),max:(a=e==null?void 0:e.max)==null?void 0:a.map(l=>l.key),distinctCount:(o=e==null?void 0:e.distinctCount)==null?void 0:o.map(l=>l.key),orderBy:(f=e==null?void 0:e.orderBy)==null?void 0:f.map(l=>{var u;return{...l,field:(u=l.field)==null?void 0:u.key}})}}translateFromJson(e){let t={};for(const r of this.entity.fields)t[r.key]=r.valueConverter.fromJson(e[r.key]);return t}translateToJson(e){let t={};for(const r of this.entity.fields)t[r.key]=r.valueConverter.toJson(e[r.key]);return t}async count(e){const{run:t}=this.buildFindRequest({where:e});return t("count").then(r=>+r.count)}async deleteMany(e){const{run:t}=this.buildFindRequest({where:e},"delete");return t("deleteMany").then(r=>+r.deleted)}async updateMany(e,t){const{run:r}=this.buildFindRequest({where:e},"put");return r("updateMany",this.toJsonOfIncludedKeys(t)).then(i=>+i.updated)}async upsertMany(e){const{run:t}=this.buildFindRequest(void 0);return t("upsertMany",e.map(r=>({where:this.toJsonOfIncludedKeys(r.where),set:r.set!==void 0?this.toJsonOfIncludedKeys(r.set):void 0}))).then(r=>r.map(i=>this.translateFromJson(i)))}find(e){let{run:t}=this.buildFindRequest(e);return t().then(r=>r.map(i=>this.translateFromJson(i)))}buildFindRequest(e,t){t||(t="get");let r=new Oi(this.url()),i;if(e){if(e.where&&(i=e.where.toJson(),ga(i,r)&&(i=void 0)),e.orderBy&&e.orderBy.Segments){let a="",o="",f=!1;e.orderBy.Segments.forEach(l=>{a.length>0&&(a+=",",o+=","),a+=l.field.key,o+=l.isDescending?"desc":"asc",l.isDescending&&(f=!0)}),a&&r.add("_sort",a),f&&r.add("_order",o)}e.limit&&r.add("_limit",e.limit),e.page&&r.add("_page",e.page)}const s=(a,o)=>{let f=new Oi(r.url);if(!a&&i&&(a="get"),a&&f.add("__action",a),i){if(t==="put")return this.http().post(f.url,{set:o,where:i});o={...o,where:i}}return o&&t!="put"?this.http().post(f.url,o):this.http()[t](f.url,o)};return{createKey:()=>JSON.stringify({url:r,filterObject:i}),run:s,subscribe:async a=>({result:await s(wa+a),unsubscribe:async()=>T.actionInfo.runActionWithoutBlockingUI(()=>this.http().post(this.url()+"?__action=endLiveQuery",{id:a}))})}}update(e,t){return this.http().put(this.url()+(e!=""?"/"+encodeURIComponent(e):"?__action=emptyId"),this.toJsonOfIncludedKeys(t)).then(r=>this.translateFromJson(r))}toJsonOfIncludedKeys(e){let t={},r=Object.keys(e);for(const i of this.entity.fields)r.includes(i.key)&&(t[i.key]=i.valueConverter.toJson(e[i.key]));return t}async delete(e){if(e=="")await this.deleteMany(D.fromEntityFilter(this.entity,this.entity.idMetadata.getIdFilter(e)));else return this.http().delete(this.url()+"/"+encodeURIComponent(e))}insert(e){return this.http().post(this.url(),this.translateToJson(e)).then(t=>this.translateFromJson(t))}insertMany(e){return this.http().post(this.url(),e.map(t=>this.translateToJson(t))).then(t=>t.map(r=>this.translateFromJson(r)))}}class Ci{constructor(e){c(this,"fetch");this.fetch=e}async get(e){return await ar(async()=>this.myFetch(e).then(t=>t))}put(e,t){return this.myFetch(e,{method:"put",body:JSON.stringify(t)})}delete(e){return this.myFetch(e,{method:"delete"})}async post(e,t){return await ar(()=>this.myFetch(e,{method:"post",body:JSON.stringify(t)}))}myFetch(e,t){const r={};if(t!=null&&t.body&&(r["Content-type"]="application/json"),typeof window<"u"&&typeof window.document<"u"&&typeof(window.document.cookie!=="undefined"))for(const i of window.document.cookie.split(";"))i.trim().startsWith("XSRF-TOKEN=")&&(r["X-XSRF-TOKEN"]=i.split("=")[1]);return(this.fetch||fetch)(e,{credentials:"include",method:t==null?void 0:t.method,body:t==null?void 0:t.body,headers:r}).then(i=>ma(i)).catch(async i=>{throw await i})}}function ma(n){if(n.status!=204){if(n.status>=200&&n.status<300)return n.json();throw n.json().then(e=>({...e,message:e.message||n.statusText,url:n.url,status:n.status})).catch(()=>{throw{message:n.statusText,url:n.url,status:n.status}})}}function ga(n,e){for(const t in n)if(Object.prototype.hasOwnProperty.call(n,t)){const r=n[t];if(Array.isArray(r)&&(r.length>0&&typeof r[0]=="object"||r.length>10)||t==="NOT")return!1}for(const t in n)if(Object.prototype.hasOwnProperty.call(n,t)){const r=n[t];Array.isArray(r)?t.endsWith(".in")?e.add(t,JSON.stringify(r)):r.forEach(i=>e.add(t,i)):t.startsWith(rt)?e.add(t,JSON.stringify(r)):e.add(t,r)}return!0}const wa="liveQuery-";var Gt,_a=new Uint8Array(16);function ba(){if(!Gt&&(Gt=typeof crypto<"u"&&crypto.getRandomValues&&crypto.getRandomValues.bind(crypto)||typeof msCrypto<"u"&&typeof msCrypto.getRandomValues=="function"&&msCrypto.getRandomValues.bind(msCrypto),!Gt))throw new Error("crypto.getRandomValues() not supported. See https://github.com/uuidjs/uuid#getrandomvalues-not-supported");return Gt(_a)}const va=/^(?:[0-9a-f]{8}-[0-9a-f]{4}-[1-5][0-9a-f]{3}-[89ab][0-9a-f]{3}-[0-9a-f]{12}|00000000-0000-0000-0000-000000000000)$/i;function ka(n){return typeof n=="string"&&va.test(n)}var me=[];for(var Fr=0;Fr<256;++Fr)me.push((Fr+256).toString(16).substr(1));function Ia(n){var e=arguments.length>1&&arguments[1]!==void 0?arguments[1]:0,t=(me[n[e+0]]+me[n[e+1]]+me[n[e+2]]+me[n[e+3]]+"-"+me[n[e+4]]+me[n[e+5]]+"-"+me[n[e+6]]+me[n[e+7]]+"-"+me[n[e+8]]+me[n[e+9]]+"-"+me[n[e+10]]+me[n[e+11]]+me[n[e+12]]+me[n[e+13]]+me[n[e+14]]+me[n[e+15]]).toLowerCase();if(!ka(t))throw TypeError("Stringified UUID is invalid");return t}function jr(n,e,t){n=n||{};var r=n.random||(n.rng||ba)();return r[6]=r[6]&15|64,r[8]=r[8]&63|128,Ia(r)}class Ee{constructor(...e){c(this,"Segments");this.Segments=e}toEntityOrderBy(){let e={};for(const t of this.Segments)t.isDescending?e[t.field.key]="desc":e[t.field.key]="asc";return e}reverse(){let e=new Ee;for(const t of this.Segments)e.Segments.push({field:t.field,isDescending:!t.isDescending});return e}compare(e,t,r){r||(r=i=>i.key);for(let i=0;i<this.Segments.length;i++){let s=this.Segments[i],a=e[r(s.field)],o=t[r(s.field)],f=s.isDescending,l=Oa(a,o,f);if(l!=0)return l}return 0}static translateOrderByToSort(e,t){let r=new Ee;if(t){for(const i in t)if(Object.prototype.hasOwnProperty.call(t,i)){const s=t[i];let a=e.fields.find(i);const o=f=>{switch(s){case"desc":r.Segments.push({field:f,isDescending:!0});break;case"asc":r.Segments.push({field:f})}};if(a){const f=oe(a);if((f==null?void 0:f.type)==="toOne"){const l=f.options;if(typeof l.field=="string")o(e.fields.find(l.field));else if(l.fields){for(const u in l.fields)if(Object.prototype.hasOwnProperty.call(l.fields,u)){const d=l.fields[u];o(e.fields.find(d.toString()))}}}else o(a)}}}return r}static createUniqueSort(e,t){(!t||Object.keys(t).length===0)&&e.options.defaultOrderBy&&(t=Ee.translateOrderByToSort(e,e.options.defaultOrderBy)),t||(t=new Ee);for(const r of e.idMetadata.fields)t.Segments.find(i=>i.field==r)||t.Segments.push({field:r});return t}static createUniqueEntityOrderBy(e,t){(!t||Object.keys(t).length===0)&&(t=e.options.defaultOrderBy),t?t={...t}:t={};for(const r of e.idMetadata.fields)t[r.key]||(t[r.key]="asc");return t}}function Oa(n,e,t){n=Ei(n),e=Ei(e);let r=0;return n>e?r=1:n<e&&(r=-1),t&&(r*=-1),r}function Ei(n){return n==null||n==null?n:n.id!==void 0?n.id:n}const Sr="stream";class Ca{constructor(e,t,r){c(this,"repo");c(this,"query");c(this,"queryChannel");c(this,"subscribeCode");c(this,"unsubscribe",()=>{});c(this,"defaultQueryState",[]);c(this,"listeners",[]);c(this,"id",jr());this.repo=e,this.query=t,this.queryChannel=`users:${r}:queries:${this.id}`,this.id=this.queryChannel}sendDefaultState(e){e(this.createReducerType(()=>[...this.defaultQueryState],this.allItemsMessage(this.defaultQueryState)))}async setAllItems(e){const t=await it(this.repo)._fromJsonArray(e,this.query.options);this.forListeners(r=>{r(()=>t)},this.allItemsMessage(t))}allItemsMessage(e){return[{type:"all",data:e}]}forListeners(e,t){e(r=>{if(this.defaultQueryState=r(this.defaultQueryState),t.find(i=>i.type==="add"||i.type==="replace")&&this.query.options.orderBy){const i=Ee.translateOrderByToSort(this.repo.metadata,this.query.options.orderBy);this.defaultQueryState.sort((s,a)=>i.compare(s,a))}});for(const r of this.listeners)e(i=>{r.next(this.createReducerType(i,t))})}createReducerType(e,t){return{applyChanges:e,changes:t,items:this.defaultQueryState}}async handle(e){{let t=e.filter(({type:i})=>i=="add"||i=="replace"),r=await it(this.repo)._fromJsonArray(t.map(i=>i.data.item),this.query.options);for(let i=0;i<t.length;i++){const s=t[i];s.data.item=r[i]}}this.forListeners(t=>{t(r=>{r||(r=[]);for(const i of e)switch(i.type){case"all":this.setAllItems(i.data);break;case"replace":{r=r.map(s=>this.repo.metadata.idMetadata.getId(s)===i.data.oldId?i.data.item:s);break}case"add":r=r.filter(s=>this.repo.metadata.idMetadata.getId(s)!==this.repo.metadata.idMetadata.getId(i.data.item)),r.push(i.data.item);break;case"remove":r=r.filter(s=>this.repo.metadata.idMetadata.getId(s)!==i.data.id);break}return r})},e)}}const Ea="_liveQueryKeepAlive";class Aa{constructor(e,t){c(this,"apiProvider");c(this,"getUserId");c(this,"queries",new Map);c(this,"channels",new Map);c(this,"client");c(this,"interval");this.apiProvider=e,this.getUserId=t}wrapMessageHandling(e){var t=this.apiProvider().wrapMessageHandling;t?t(e):e()}hasQueriesForTesting(){return this.queries.size>0}runPromise(e){return e}close(){this.queries.clear(),this.channels.clear(),this.closeIfNoListeners()}async subscribeChannel(e,t){let r=()=>{};const i=await this.openIfNoOpened();try{let s=this.channels.get(e);if(!s){this.channels.set(e,s=new Ta);try{s.unsubscribe=await i.subscribe(e,a=>this.wrapMessageHandling(()=>s.handle(a)),a=>{t.error(a)})}catch(a){throw t.error(a),a}}s.listeners.push(t),r=()=>{s.listeners.splice(s.listeners.indexOf(t),1),s.listeners.length==0&&(this.channels.delete(e),s.unsubscribe()),this.closeIfNoListeners()}}catch(s){throw t.error(s),s}return()=>{r(),r=()=>{}}}closeIfNoListeners(){this.client&&this.queries.size===0&&this.channels.size===0&&(this.runPromise(this.client.then(e=>e.close())),this.client=void 0,clearInterval(this.interval),this.interval=void 0)}subscribe(e,t,r){let i=!0,s=()=>{i=!1};return this.runPromise(it(e)._buildEntityDataProviderFindOptions(t).then(a=>{if(!i)return;const{createKey:o,subscribe:f}=new qr(this.apiProvider).getEntityDataProvider(e.metadata).buildFindRequest(a),l=o();let u=this.queries.get(l);u?u.sendDefaultState(r.next):(this.queries.set(l,u=new Ca(e,{entityKey:e.metadata.key,options:t},this.getUserId())),u.subscribeCode=()=>{u.unsubscribe&&(u.unsubscribe(),u.unsubscribe=()=>{}),this.runPromise(this.subscribeChannel(u.queryChannel,{next:d=>this.runPromise(u.handle(d)),complete:()=>{},error:d=>{u.listeners.forEach(p=>p.error(d))}}).then(d=>{if(u.listeners.length==0){d();return}this.runPromise(f(u.queryChannel).then(p=>{if(u.listeners.length===0){p.unsubscribe(),d();return}this.runPromise(u.setAllItems(p.result)),u.unsubscribe=()=>{u.unsubscribe=()=>{},d(),this.runPromise(p.unsubscribe())}}).catch(p=>{u.listeners.forEach(h=>h.error(p)),d(),this.queries.delete(l)}))})).catch(d=>{u.listeners.forEach(p=>p.error(d))})},u.subscribeCode()),u.listeners.push(r),s=()=>{u.listeners.splice(u.listeners.indexOf(r),1),r.complete(),u.listeners.length==0&&(this.queries.delete(l),u.unsubscribe()),this.closeIfNoListeners()}}).catch(a=>{r.error(a)})),()=>{s()}}openIfNoOpened(){return this.client?this.client:(this.interval=setInterval(async()=>{const e=[];for(const t of this.queries.values())e.push(t.queryChannel);if(e.length>0){let t=this.apiProvider();const r=await this.runPromise(await T.actionInfo.runActionWithoutBlockingUI(()=>yt(t.httpClient).post(t.url+"/"+Ea,e)));for(const i of r)for(const s of this.queries.values())s.queryChannel===i&&s.subscribeCode()}},3e4),this.runPromise(this.client=this.apiProvider().subscriptionClient.openConnection(()=>{for(const e of this.queries.values())e.subscribeCode()})))}}class Ta{constructor(){c(this,"unsubscribe",()=>{});c(this,"listeners",[])}async handle(e){for(const t of this.listeners)t.next(e)}}class Kr{openConnection(e){let t;const r=new Map,i=yt(ke.apiClient.httpClient);let s=!1,a;const o={close(){a.close()},async subscribe(u,d){let p=r.get(u);return p||(r.set(u,p=[]),await l(u)),p.push(d),()=>{p.splice(p.indexOf(d,1)),p.length==0&&(T.actionInfo.runActionWithoutBlockingUI(()=>i.post(ke.apiClient.url+"/"+Sr+"/unsubscribe",{channel:u,clientId:t})),r.delete(u))}}},f=()=>new Promise(u=>{p();let d=0;function p(){a&&a.close(),a=Kr.createEventSource(ke.apiClient.url+"/"+Sr),a.onmessage=h=>{let y=JSON.parse(h.data);const w=r.get(y.channel);w&&w.forEach(I=>I(y.data))},a.onerror=h=>{console.error("Live Query Event Source Error",h),a.close(),d++<rn.error500RetryCount&&setTimeout(()=>{p()},500)},a.addEventListener("connectionId",async h=>{if(t=h.data,s){for(const y of r.keys())await l(y);e()}else s=!0,u(o)})}});return f();async function l(u){await T.actionInfo.runActionWithoutBlockingUI(()=>i.post(ke.apiClient.url+"/"+Sr+"/subscribe",{channel:u,clientId:t}))===Fa&&await f()}}static createEventSource(e){return new EventSource(e,{withCredentials:!0})}}const Fa="client connection not found",Jr=Symbol.for("serverActionField");class Sa{constructor(e){c(this,"remultObjectStorage");this.remultObjectStorage=e}static enable(){T.remultFactory=()=>{const e=T.asyncContext.getStore();if(e)return e.remult;throw new Error("remult object was requested outside of a valid request cycle.valid context, try running `withRemult` or run within initApi or a remult request cycle")}}static disable(){oa()}async run(e,t){return this.remultObjectStorage?this.remultObjectStorage.run({remult:e},()=>t(e)):t(e)}isInInitRequest(){var e,t;return(t=(e=this.remultObjectStorage)==null?void 0:e.getStore())==null?void 0:t.inInitRequest}setInInitRequest(e){var r,i;const t=(r=this.remultObjectStorage)==null?void 0:r.getStore();t&&(e||(i=this.remultObjectStorage)!=null&&i.isStub)&&(t.inInitRequest=e)}getStore(){if(!this.remultObjectStorage)throw new Error("can't use static remult in this environment, `async_hooks` were not initialized");return this.remultObjectStorage.getStore()}}T.asyncContext||(T.asyncContext=new Sa(void 0));function Ft(){return T.actionInfo.runningOnServer||!ke.dataProvider.isProxy}class Le{constructor(e){c(this,"repo",(e,t)=>{t===void 0&&(t=this.dataProvider);let r=this.repCache.get(t);r||this.repCache.set(t,r=new Map);let i=r.get(e);return i||(r.set(e,i=new Xr(e,this,t,ja(e,this))),ta(i,this,t)),i});c(this,"user");c(this,"dataProvider",new qr(()=>this.apiClient));c(this,"repCache",new Map);c(this,"liveQueryStorage");c(this,"subscriptionServer");c(this,"liveQueryPublisher",{itemChanged:async()=>{}});c(this,"liveQuerySubscriber",new Aa(()=>this.apiClient,()=>{var e;return(e=this.user)==null?void 0:e.id}));c(this,"context",{});c(this,"apiClient",{url:"/api",subscriptionClient:new Kr});if(e&&e.getEntityDataProvider){this.dataProvider=e;return}if(nn(e))this.apiClient.httpClient=e;else if(typeof e=="function")this.apiClient.httpClient=e;else if(e){const t=e;t.httpClient&&(this.apiClient.httpClient=t.httpClient),t.url&&(this.apiClient.url=t.url),t.subscriptionClient&&(this.apiClient.subscriptionClient=t.subscriptionClient),t.wrapMessageHandling&&(this.apiClient.wrapMessageHandling=t.wrapMessageHandling)}}async initUser(){const t=await yt(this.apiClient.httpClient).get(sn(this.apiClient.url,"me"));return this.user=(t==null?void 0:t.id)!=null?t:void 0,this.user}authenticated(){var e;return((e=this.user)==null?void 0:e.id)!==void 0}isAllowed(e){var t,r;if(e!=null){if(e instanceof Array){for(const i of e)if(this.isAllowed(i)===!0)return!0;return!1}return typeof e=="function"?e(this):typeof e=="boolean"?e:!!(typeof e=="string"&&(r=(t=this.user)==null?void 0:t.roles)!=null&&r.includes(e.toString()))}}isAllowedForInstance(e,t){if(Array.isArray(t)){for(const r of t)if(this.isAllowedForInstance(e,r))return!0}else return typeof t=="function"?t(e,this):this.isAllowed(t)}useFetch(e){this.dataProvider=new qr(()=>({httpClient:e}))}call(e,t,...r){const i=e[Jr];if(!i.doWork)throw Error("The method received is not a valid backend method");return i.doWork(r,t,this.apiClient.url,yt(this.apiClient.httpClient))}clearAllCache(){this.repCache.clear()}}c(Le,"onFind",(e,t)=>{}),c(Le,"entityRefInit");T.defaultRemultFactory=()=>new Le;class an{constructor(){c(this,"classes",new Map)}}function $a(n,e){let t=n;for(;;){let r=T.classHelpers.get(t);r||T.classHelpers.set(t,r=new an),r.classes.set(n,e);let i=Object.getPrototypeOf(t.prototype);if(i==null)break;t=i.constructor}}const Pa={defaultPageSize:200};async function Da(n,e){const t=new Ra(n.liveQueryPublisher);let r=!0;const i=n.dataProvider;try{await n.dataProvider.transaction(async s=>{n.dataProvider=s,n.liveQueryPublisher=t,await e(s),r=!0}),r&&await t.flush()}finally{n.dataProvider=i}}class Ra{constructor(e){c(this,"orig");c(this,"transactionItems",new Map);this.orig=e}async itemChanged(e,t){let r=this.transactionItems.get(e);r||this.transactionItems.set(e,r=[]);for(const i of t)if(i.oldId!==void 0){const s=r.find(a=>a.id===i.oldId);s!==void 0?(i.deleted&&(s.deleted=!0),i.id!=s.id&&(s.id=i.id)):r.push(i)}else r.push(i)}async flush(){for(const e of this.transactionItems.keys())await this.orig.itemChanged(e,this.transactionItems.get(e))}}function Ot(n,e){return e&&Object.assign(n,e),n}class on extends Error{constructor(t){super(t.message);c(this,"modelState");c(this,"stack");c(this,"exception");c(this,"httpStatusCode");Object.assign(this,t)}}class Je{}c(Je,"number","number"),c(Je,"date","date"),c(Je,"checkbox","checkbox"),c(Je,"password","password"),c(Je,"email","email"),c(Je,"tel","tel"),c(Je,"time","time");const W=class W{};c(W,"Date",{toJson:e=>{if(e===null)return null;if(!e)return"";if(typeof e=="string"&&(e=new Date(e)),e instanceof Date)return e.toISOString();throw new Error("Expected date but got "+e)},fromJson:e=>{if(e===null)return null;if(e!=null&&e!=""&&!e.startsWith("0000-00-00"))return new Date(Date.parse(e))},toDb:e=>e,fromDb:e=>{if(typeof e=="number"&&(e=new Date(e)),typeof e=="string"&&(e=new Date(e)),e&&!(e instanceof Date))throw"expected date but got "+e;return e},fromInput:e=>W.Date.fromJson(e),toInput:e=>W.Date.toJson(e),displayValue:e=>e?e.toLocaleString():""}),c(W,"DateOnly",{fromInput:e=>W.DateOnly.fromJson(e),toInput:e=>W.DateOnly.toJson(e),toJson:e=>{var t=e;return(typeof t=="string"||typeof t=="number")&&(t=new Date(t)),!t||t==null?null:t.getHours()==0?new Date(t.valueOf()-t.getTimezoneOffset()*6e4).toISOString().substring(0,10):t.toISOString().substring(0,10)},fromJson:e=>{if(!e||e==""||e=="0000-00-00")return null;let t=new Date(Date.parse(e));return t.setMinutes(t.getMinutes()+t.getTimezoneOffset()),t},inputType:Je.date,toDb:e=>e?W.DateOnly.fromJson(W.DateOnly.toJson(e)):null,fromDb:e=>W.Date.fromDb(e),fieldTypeInDb:"date",displayValue:e=>e?e.toLocaleDateString(void 0):""}),c(W,"DateOnlyString",{...W.DateOnly,toDb:e=>{let t=W.DateOnly.toJson(e);if(t)return t.replace(/-/g,"")},fromDb:e=>{if(e===null)return null;if(e)return new Date(e.substring(0,4)+"-"+e.substring(4,6)+"-"+e.substring(6,8))}}),c(W,"Boolean",{toDb:e=>e,inputType:Je.checkbox,fromDb:e=>W.Boolean.fromJson(e),fromJson:e=>typeof e=="boolean"?e:e===1?!0:e!=null?e.toString().trim().toLowerCase()=="true":e,toJson:e=>e,fromInput:e=>W.Boolean.fromJson(e),toInput:e=>W.Boolean.toJson(e)}),c(W,"Number",{fromDb:e=>{if(e===null)return null;if(e!==void 0)return+e},toDb:e=>e,fromJson:e=>W.Number.fromDb(e),toJson:e=>W.Number.toDb(e),fromInput:(e,t)=>{let r=+e;if(e!=null)return r},toInput:(e,t)=>(e==null?void 0:e.toString())??"",inputType:Je.number}),c(W,"String",{fromDb:ut,toDb:ut,fromJson:ut,toJson:ut,fromInput:ut,toInput:ut}),c(W,"Integer",{...W.Number,toJson:e=>{let t=W.Number.toDb(e);return t&&+(+t).toFixed(0)},toDb:e=>W.Integer.toJson(e),fieldTypeInDb:"integer"}),c(W,"Default",{fromJson:e=>e,toJson:e=>e,fromDb:e=>W.JsonString.fromDb(e),toDb:e=>W.JsonString.toDb(e),fromInput:e=>W.Default.fromJson(e),toInput:e=>W.Default.toJson(e),displayValue:e=>e+"",fieldTypeInDb:"",inputType:"text"}),c(W,"JsonString",{fromJson:e=>e,toJson:e=>e,fromDb:e=>e==null?null:e?JSON.parse(W.JsonString.fromJson(e)):void 0,toDb:e=>e!==void 0?e===null?null:JSON.stringify(W.JsonString.toJson(e)):void 0,fromInput:e=>W.JsonString.fromJson(e),toInput:e=>W.JsonString.toJson(e)}),c(W,"JsonValue",{fromJson:e=>e,toJson:e=>e,fromDb:e=>e,toDb:e=>e,fromInput:e=>W.JsonString.fromJson(e),toInput:e=>W.JsonString.toJson(e),fieldTypeInDb:"json"});let _e=W;function ut(n){return n==null?n:typeof n!="string"?n.toString():n}function $r(n,e,t){let r=D.fromEntityFilter(n,e);const i=()=>{};r&&r.__applyToConsumer({custom:i,databaseCustom:i,containsCaseInsensitive:i,notContainsCaseInsensitive:i,startsWithCaseInsensitive:i,endsWithCaseInsensitive:i,isDifferentFrom:i,isEqualTo:(s,a)=>{t[s.key]=a},isGreaterOrEqualTo:i,isGreaterThan:i,isIn:i,isLessOrEqualTo:i,isLessThan:i,isNotNull:i,isNull:i,not:i,or:i})}class Ct{constructor(){c(this,"entityLoaders",new Map);c(this,"promises",[])}load(e,t){let r=this.entityLoaders.get(e.entityType);r||this.entityLoaders.set(e.entityType,r=new Ma(e));const i=r.find(t);return this.promises.push(i),i}async resolveAll(){for(const t of this.entityLoaders.values())for(const r of t.queries.values())r.resolve();if(this.promises.length===0)return;const e=this.promises;this.promises=[],await Promise.all(e),await this.resolveAll()}}class Ma{constructor(e){c(this,"rel");c(this,"queries",new Map);this.rel=e}find(e){const{where:t,...r}=zr(e,this.rel.metadata),i=JSON.stringify(r);let s=this.queries.get(i);return s||this.queries.set(i,s=new Na(this.rel)),s.find(e,t)}}class Na{constructor(e){c(this,"rel");c(this,"pendingInStatements",new Map);c(this,"whereVariations",new Map);this.rel=e}find(e,t){const r=JSON.stringify(t);let i=this.whereVariations.get(r);if(!i){const s=Object.keys(t);if(s.length===1&&typeof t[s[0]]!="object"&&!e.limit){let a=this.pendingInStatements.get(s[0]);a||this.pendingInStatements.set(s[0],a=new La(this.rel,s[0],e)),this.whereVariations.set(r,i={result:a.find(t)})}else this.whereVariations.set(r,i={result:this.rel.find(e)})}return i.result}resolve(){const e=[...this.pendingInStatements.values()];this.pendingInStatements.clear();for(const t of e)t.resolve()}}class La{constructor(e,t,r){c(this,"rel");c(this,"key");c(this,"options");c(this,"values",new Map);this.rel=e,this.key=t,this.options=r}async resolve(){const e=[...this.values.values()];if(e.length==1){this.rel.find(this.options).then(e[0].resolve,e[0].reject);return}var t={...this.options};t.where={[this.key]:e.map(i=>i.value)},t.limit=1e3,t.page=1;let r=[];try{for(;;){const i=await this.rel.find(t);if(r.push(...i),i.length<t.limit)break;t.page++}for(const i of this.values.values())i.resolve(r.filter(s=>{const o=ne(s).fields.find(this.key),f=oe(o.metadata),l=(f==null?void 0:f.type)==="reference"?o.getId():s[this.key];return i.value==l}))}catch(i){for(const s of this.values.values())s.reject(i)}}find(e){const t=e[this.key];let r=this.values.get(t);if(!r){let i,s,a=new Promise((o,f)=>{i=o,s=f});this.values.set(t,r={value:t,resolve:i,reject:s,result:a})}return r.result}}T.actionInfo;const he=class he{};c(he,"required",Et(async(e,t)=>!t.valueIsNull()&&t.value!==""&&(t.value!==void 0||oe(t.metadata)!==void 0),"Should not be empty")),c(he,"unique",Et(async(e,t)=>{if(!t.entityRef)throw"unique validation may only work on columns that are attached to an entity";return t.isBackend()&&(t.isNew||t.valueChanged())?await t.entityRef.repository.count({[t.metadata.key]:t.value})==0:!0},"already exists")),c(he,"uniqueOnBackend",Et(async(e,t)=>t.isBackend()&&(t.isNew||t.valueChanged())?await t.entityRef.repository.count({[t.metadata.key]:t.value})==0:!0,he.unique.defaultMessage)),c(he,"regex",Ze((e,t)=>t.test(e))),c(he,"email",xt(e=>/^[^\s@]+@[^\s@]+\.[^\s@]+$/.test(e),"Invalid Email")),c(he,"url",xt(e=>!!new URL(e),"Invalid Url")),c(he,"in",Ze((e,t)=>t.includes(e),e=>`Value must be one of: ${e.map(t=>typeof t=="object"?(t==null?void 0:t.id)!==void 0?t==null?void 0:t.id:t==null?void 0:t.toString():t).join(", ")}`)),c(he,"notNull",xt(e=>e!=null,"Should not be null")),c(he,"enum",Ze((e,t)=>Object.values(t).includes(e),e=>`Value must be one of ${er(e).join(", ")}`)),c(he,"relationExists",Et(async(e,t)=>t.valueIsNull()||!t.isBackend()?!0:!!await t.load(),"Relation value does not exist")),c(he,"min",Ze((e,t)=>e>=t,e=>`Value must be bigger than or equal to ${e}`)),c(he,"max",Ze((e,t)=>e<=t,e=>`Value must be smaller than or equal to ${e}`)),c(he,"maxLength",Ze((e,t)=>e.length<=t,e=>`Value must be at most ${e} characters`)),c(he,"minLength",Ze((e,t)=>e.length>=t,e=>`Value must be at least ${e} characters`)),c(he,"range",Ze((e,[t,r])=>e>=t&&e<=r,([e,t])=>`Value must be between ${e} and ${t}`)),c(he,"defaultMessage","Invalid value");let $e=he;function Et(n,e){const t=async(i,s,a)=>{const o=await n(i,s);typeof o=="string"&&o.length>0?s.error=o:o||(s.error=typeof a=="function"&&a(i,s,void 0)||a||typeof e=="function"&&e(i,s,void 0)||e||$e.defaultMessage)},r=(i,s,a)=>typeof i=="string"||i==="function"||i===void 0&&s===void 0?async(o,f,l)=>await t(o,f,i||l):t(i,s,a);return Object.defineProperty(r,"defaultMessage",{get:()=>e,set:i=>{e=i},enumerable:!0}),Object.assign(r,{withMessage:i=>async(s,a)=>r(s,a,i)})}function xt(n,e){return Et((t,r)=>r.value===void 0||r.value===null?!0:n(r.value),e)}function Ze(n,e){const t=Ba((r,i,s)=>i.value===void 0||i.value===null?!0:n(i.value,s),(r,i,s)=>typeof e=="function"&&e(s)||e,!0);return Object.assign((r,i)=>t(r,i),{get defaultMessage(){return e},set defaultMessage(r){e=r}})}function Ba(n,e,t=!1){return Object.assign((i,s)=>async(a,o)=>{const f=await n(a,o,i);typeof f=="string"?o.error=f:f||(o.error=s?typeof s=="function"?t?s(i):s(a,o,i):s:e?typeof e=="function"?e(a,o,i):e:$e.defaultMessage)},{get defaultMessage(){return e},set defaultMessage(i){e=i}})}function er(n){return Object.values(n).filter(e=>typeof n[e]!="number")}function tr(n,e,t=!1){if(!e)return n;const r=Array.isArray(e)?e:[e],i=Array.isArray(n)?n:n?[n]:[];return t?[...r,...i]:[...i,...r]}function pt(n,e){return typeof n[e]<"u"}class qa{constructor(e,t){c(this,"options");c(this,"repo");c(this,"_count");c(this,"_aggregates");this.options=e,this.repo=t,this.options||(this.options={}),this.options.pageSize||(this.options.pageSize=Pa.defaultPageSize)}async getPage(e){return(e??0)<1&&(e=1),this.repo.find({where:this.options.where,orderBy:this.options.orderBy,limit:this.options.pageSize,page:e,load:this.options.load,include:this.options.include})}async count(){return this._count===void 0&&(this._count=await this.repo.count(this.options.where)),this._count}async forEach(e){let t=0;for await(const r of this)await e(r),t++;return t}async paginator(e){this.options.orderBy=Ee.createUniqueEntityOrderBy(this.repo.metadata,this.options.orderBy);let t={where:{$and:[this.options.where,e]},orderBy:this.options.orderBy,limit:this.options.pageSize,load:this.options.load,include:this.options.include},r=()=>this.repo.find(t);if(this._aggregates===void 0&&pt(this.options,"aggregate")){let o=this.options.aggregate;if(this.repo._dataProvider.isProxy){const f=new Ct;r=()=>this.repo._rawFind(t,!1,f,async l=>{const u=await this.repo._edp.query(l,await this.repo.__buildGroupByOptions(o));return this._aggregates=u.aggregates,u.items}).then(async l=>(await f.resolveAll(),l))}else{let f=r();r=async()=>(this._aggregates=await this.repo.aggregate({...o,where:this.options.where}),this._count=this._aggregates.$count,f)}}let i=await r(),s=()=>{throw new Error("no more pages")},a=i.length==this.options.pageSize;if(a){let o=await this.repo._createAfterFilter(this.options.orderBy,i[i.length-1]);s=()=>this.paginator(o)}return{count:()=>this.count(),hasNextPage:a,items:i,nextPage:s,aggregates:this._aggregates}}[Symbol.asyncIterator](){this.options.where||(this.options.where={});let e=this.options.orderBy;this.options.orderBy=Ee.createUniqueEntityOrderBy(this.repo.metadata,e);let t=-1,r,i,s=0;return i=async()=>{if(this.options.progress&&this.options.progress.progress(s++/await this.count()),r===void 0||t==r.items.length){if(r&&!r.hasNextPage)return{value:void 0,done:!0};let a=r;if(r?r=await r.nextPage():r=await this.paginator(),t=0,r.items.length==0)return{value:void 0,done:!0};if(((a==null?void 0:a.items.length)??!1)&&this.repo.getEntityRef(a.items[0]).getId()==this.repo.getEntityRef(r.items[0]).getId())throw new Error("pagination failure, returned same first row")}return t<r.items.length?{value:r.items[t++],done:!1}:{done:!0,value:void 0}},{next:async()=>i()}}}class Xr{constructor(e,t,r,i,s){c(this,"_entity");c(this,"_remult");c(this,"_dataProvider");c(this,"_info");c(this,"_defaultFindOptions");c(this,"__edp");c(this,"_idCache",new Map);c(this,"listeners");c(this,"_cache",new Map);this._entity=e,this._remult=t,this._dataProvider=r,this._info=i,this._defaultFindOptions=s}_notFoundError(e){return{message:`id ${e} not found in entity ${this.metadata.key}`,httpStatusCode:404}}[Tt](){return this}async _createAfterFilter(e,t){let r=new Map;for(const a of Ee.translateOrderByToSort(this.metadata,e).Segments){let o=t[a.field.key];r.set(a.field.key,o)}let i={$or:[]},s=[];for(const a of Ee.translateOrderByToSort(this.metadata,e).Segments){let o={};for(const f of s)o[f.key]=r.get(f.key);s.push(a.field),a.isDescending?o[a.field.key]={$lt:r.get(a.field.key)}:o[a.field.key]={$gt:r.get(a.field.key)},i.$or.push(o)}return i}relations(e){return new Proxy({},{get:(t,r)=>{const i=this.fields.find(r),s=oe(i);if(!s)throw Error(r+" is not a relation");const{toRepo:a,returnNull:o,returnUndefined:f}=this._getFocusedRelationRepo(i,e);return s.type==="toMany"?a:{findOne:l=>o?Promise.resolve(null):f?Promise.resolve(void 0):a.findFirst({},l)}}})}_getFocusedRelationRepo(e,t){const r=oe(e);let i=r.toRepo,{findOptions:s,returnNull:a,returnUndefined:o}=this._findOptionsBasedOnRelation(r,e,void 0,t,i);return{toRepo:new Xr(i._entity,i._remult,i._dataProvider,i._info,s),returnNull:a,returnUndefined:o}}get _edp(){return this.__edp?this.__edp:this.__edp=this._dataProvider.getEntityDataProvider(this.metadata)}async aggregate(e){return(await this.groupBy(e))[0]}async groupBy(e){var t=await this.__buildGroupByOptions(e);const r=await this._edp.groupBy(t);if(!(e!=null&&e[fa])&&e.group){const i={include:{}};for(const a of e.group)i.include[a]=!0;const s=new Ct;await this._populateRelationsForFields(t.group,i,r,s),await s.resolveAll()}return r}async __buildGroupByOptions(e){var a,o,f,l,u,d;let t=await this._buildEntityDataProviderFindOptions({...e});const r=p=>{const h=this.metadata.fields.find(p);if(h===void 0)throw Error(`key "${p}" not found in entity`);return h},i=p=>{var h;if((h=e==null?void 0:e.group)!=null&&h.includes(p))throw Error(`field "${p}" cannot be used both in an aggregate and in group by`);return r(p)};var s={where:t.where,limit:t.limit,page:t.page,group:(a=e==null?void 0:e.group)==null?void 0:a.map(r),sum:(o=e==null?void 0:e.sum)==null?void 0:o.map(i),avg:(f=e==null?void 0:e.avg)==null?void 0:f.map(i),min:(l=e==null?void 0:e.min)==null?void 0:l.map(i),max:(u=e==null?void 0:e.max)==null?void 0:u.map(i),distinctCount:(d=e==null?void 0:e.distinctCount)==null?void 0:d.map(i)};if(e!=null&&e.orderBy){s.orderBy=[];for(const p in e.orderBy)if(Object.prototype.hasOwnProperty.call(e==null?void 0:e.orderBy,p)){const h=e.orderBy[p];if(h){if(typeof h=="string")s.orderBy.push({field:p==="$count"?void 0:r(p),isDescending:h==="desc",operation:p==="$count"?"count":void 0});else for(const y in h)if(Object.prototype.hasOwnProperty.call(h,y)){const w=h[y];s.orderBy.push({field:this.metadata.fields.find(p),isDescending:w==="desc",operation:y})}}}}return s}_getCachedById(e,t){e=e+"",this._getCachedByIdAsync(e,t);let r=this._idCache.get(e);if(!(r instanceof Promise))return r}async _getCachedByIdAsync(e,t){e=e+"";let r=this._idCache.get(e);if(r instanceof Promise)return await r;if(this._idCache.has(e))return r;if(t)return;this._idCache.set(e,void 0);let i=this.findId(e).then(s=>(s===void 0?r=null:r=s,this._idCache.set(e,r),r));return this._idCache.set(e,i),await i}_addToCache(e){e&&this._idCache.set(this.getEntityRef(e).getId()+"",e)}get metadata(){return this._info}addEventListener(e){return this.listeners||(this.listeners=[]),this.listeners.push(e),()=>{this.listeners.splice(this.listeners.indexOf(e),1)}}query(e){return new qa(e,this)}getEntityRef(e){let t=e[et];return t||(this._fixTypes(e),t=new Qt(this._info,e,this,this._edp,this._remult,!0),Object.defineProperty(e,et,{get:()=>t}),t.saveOriginalData()),t}async delete(e){const t=ne(e,!1);if(t)return t.delete();if(typeof e=="string"||typeof e=="number"){if(this._dataProvider.isProxy)return this._edp.delete(e);{let i=await this.findId(e);if(!i)throw this._notFoundError(e);return await ne(i).delete()}}let r=this._getRefForExistingRow(e,void 0);return this._dataProvider.isProxy||await r.reload(),r.delete()}__cleanupPartialObject(e){const t=Object.keys(e);for(let r=0;r<t.length;r++){const i=t[r],s=this.fields[i];if(s){const a=oe(s);a&&a.type==="toOne"&&a.options.field&&t.indexOf(a.options.field)>r&&a.toRepo.getEntityRef(e[i]).getId()!==e[a.options.field]&&delete e[i]}}for(const r in e)Object.prototype.hasOwnProperty.call(e,r)&&(e[r],oe(this.fields[r]));for(const r of this.fields);}async insert(e){if(Array.isArray(e))if(this._dataProvider.isProxy){let t=[],r=[];for(const i of e){this.__cleanupPartialObject(i);let s=ne(e,!1);if(s){if(!s.isNew())throw"Item is not new"}else s=await this.getEntityRef(this.create(i));t.push(s),r.push(await s.buildDtoForInsert())}return ct(await this._edp.insertMany(r),(i,s)=>t[s].processInsertResponseDto(i))}else{let t=[];for(const r of e)t.push(await this.insert(r));return t}else{let t=ne(e,!1);if(t){if(!t.isNew())throw"Item is not new";return await t.save()}else return this.__cleanupPartialObject(e),await this.getEntityRef(this.create(e)).save()}}get fields(){return this.metadata.fields}async validate(e,...t){{let r=ne(e,!1);if(r||(r=this.getEntityRef({...e})),!t||t.length===0)return await r.validate();{r.__clearErrorsAndReportChanged();let i=!1;for(const s of t)await r.fields.find(s).validate()||(i=!0);return i?r.buildErrorInfoObject():void 0}}}__createDto(e){this.__cleanupPartialObject(e);const r=this.getEntityRef({...e}).copyDataToObject(!1),i=Object.keys(e);for(const s of this.fields)(s.dbReadOnly||!i.includes(s.key))&&delete r[s.key];return r}async updateMany({where:e,set:t}){if(this.__cleanupPartialObject(t),D.throwErrorIfFilterIsEmpty(e,"updateMany"),this._dataProvider.isProxy)return this._edp.updateMany(await this._translateWhereToFilter(e),this.__createDto({...t}));{let r=0;for await(const i of this.query({where:e,aggregate:void 0}))Ot(i,t),await ne(i).save(),r++;return r}}async update(e,t){{let i=ne(t,!1);if(i)return await i.save()}{let i=ne(e,!1);if(i)return Ot(e,t),i.save()}this.__cleanupPartialObject(t);let r;if(typeof e=="object"?(r=this._getRefForExistingRow(e,this.metadata.idMetadata.getId(e)),Object.assign(r.instance,t)):r=this._getRefForExistingRow(t,e),this._dataProvider.isProxy)return await r.save(Object.keys(t));{const i=await r.reload();if(!i)throw this._notFoundError(r.id);for(const s in t)if(Object.prototype.hasOwnProperty.call(t,s)){let a=r.fields[s];if(t[s]===void 0&&oe(a.metadata))continue;a&&(i[s]=t[s])}return await this._fixTypes(i),await r.save()}}async upsert(e){if(this._dataProvider.isProxy){let s=await this._edp.upsertMany((Array.isArray(e)?e:[e]).map(f=>{var l;return(l=this._defaultFindOptions)!=null&&l.where&&($r(this.metadata,this._defaultFindOptions.where,f.where),this._fixTypes(f)),{where:this.__createDto(f.where),set:f.set?this.__createDto(f.set):void 0}}));const a=new Ct,o=await this._loadManyToOneForManyRows(s,{},a);return await a.resolveAll(),Array.isArray(e)?o:o[0]}if(Array.isArray(e))return ct(e,s=>this.upsert(s));let t=e;var r=await this.findFirst(t.where,{createIfNotFound:!0}),i=ne(r,!1);return i.isNew()?(t.set&&Ot(r,t.set),await i.save()):t.set?(Ot(r,t.set),await i.save()):r}_getRefForExistingRow(e,t){let r=ne(e,!1);if(!r){const i=new this._entity(this._remult);for(const a of this._fieldsOf(e)){const o=a.key;i[o]=e[o]}this._fixTypes(i);let s=new Qt(this._info,i,this,this._edp,this._remult,!1);typeof t=="object"&&(t=this.metadata.idMetadata.getId(t)),t?(s.id=t,s.originalId=t):s.id=s.getId(),r=s,Object.defineProperty(i,et,{get:()=>s})}return r}async save(e){if(Array.isArray(e))return ct(e,t=>this.save(t));{let t=ne(e,!1);if(t)return await t.save();if(e instanceof hn)return await this.getEntityRef(e).save();{let r=this.metadata.idMetadata.getId(e);return r===void 0?this.insert(e):this.update(r,e)}}}liveQuery(e){return e||(e={}),{subscribe:t=>{let r=t;return typeof t=="function"&&(r={next:t,complete:()=>{},error:()=>{}}),r.error??(r.error=()=>{}),r.complete??(r.complete=()=>{}),this._remult.liveQuerySubscriber.subscribe(this,e,r)}}}async _rawFind(e,t=!1,r,i){e||(e={}),this._defaultFindOptions&&(e={...this._defaultFindOptions,...e});let s=await this._buildEntityDataProviderFindOptions(e);t&&(delete s.orderBy,delete s.limit),Le.onFind(this._info,e);const a=await i(s);return await this._loadManyToOneForManyRows(a,e,r)}async find(e,t=!1){const r=new Ct,i=await this._rawFind(e,t,r,s=>this._edp.find(s));return await r.resolveAll(),i}async _buildEntityDataProviderFindOptions(e){e={...e};let t={};return t={},(!e.orderBy||Object.keys(e.orderBy).length===0)&&(this._dataProvider.isProxy||(e.orderBy=this._info.entityInfo.defaultOrderBy)),t.where=await this._translateWhereToFilter(e.where),e.orderBy!==void 0&&(t.orderBy=Ee.translateOrderByToSort(this.metadata,e.orderBy)),e.limit!==void 0&&(t.limit=e.limit),e.page!==void 0&&(t.page=e.page),t}async _fromJsonArray(e,t){const r=new Ct,i=await this._loadManyToOneForManyRows(e.map(s=>{let a={};for(const o of this.metadata.fields.toArray())a[o.key]=o.valueConverter.fromJson(s[o.key]);return a}),t,r);return await r.resolveAll(),i}async _loadManyToOneForManyRows(e,t,r){let i;t!=null&&t.load&&(i=t.load(this.metadata.fields));for(const l of this.metadata.fields)if(Ae(l.valueType,!1)&&!oe(l)){let p=!l.options.lazy;if(i!==void 0&&(p=i.includes(l)),p){let h=this._remult.repo(l.valueType),y=[];for(const w of e){let I=w[l.key];I!=null&&!y.includes(I)&&!h._idCache.has(I+"")&&y.push(I)}y.length>0&&await s(h,y)}}async function s(l,u){let d=await l.find({where:l.metadata.idMetadata.getIdFilter(...u)},!0);for(const p of d)l._addToCache(p)}const a=new Set(this.fields.toArray().map(l=>{const u=this.__getRelationAndInclude(l,t);if(u.rel&&!u.incl)return l.key}).filter(l=>l!==void 0));let o=await ct(e,async l=>await this._mapRawDataToResult(l,i,a));const f=this.metadata.fields.toArray();return this._populateRelationsForFields(f,t,o,r),o}_populateRelationsForFields(e,t,r,i){for(const s of e){let{rel:a,incl:o}=this.__getRelationAndInclude(s,t);if(a)if(o){const f=a.toRepo;for(const l of r){let{findOptions:u,returnNull:d}=this._findOptionsBasedOnRelation(a,s,o,l,f);const p=s.key;if(d)l[p]=null;else{const h=a.toEntity,y=f;i.load({entityType:h,find:w=>y._rawFind(w,!1,i,I=>y._edp.find(I)),metadata:y.metadata},u).then(w=>{w.length==0&&a.type=="toOne"||(l[p]=a.type!=="toMany"?w.length==0?null:w[0]:w)})}}}else for(const f of r)Reflect.deleteProperty(f,s.key)}}__getRelationAndInclude(e,t){var a;let r=oe(e),i=e.options.defaultIncluded;const s=(a=t==null?void 0:t.include)==null?void 0:a[e.key];return s!==void 0&&(i=s),{rel:r,incl:i}}_findOptionsBasedOnRelation(e,t,r,i,s){let a=!1,o=!1,f=[],l={},u=[];typeof e.options.findOptions=="function"?u.push(e.options.findOptions(i)):typeof e.options.findOptions=="object"&&u.push(e.options.findOptions),typeof r=="object"&&u.push(r);for(const h of u){h.where&&f.push(h.where);for(const y of["limit","include","orderBy"])h[y]&&(l[y]=h[y])}const d=e.getFields(),p=h=>{const y=ne(i,!1);let w=e.type==="reference"&&y?y.fields.find(t.key).getId():i[h];return(e.type==="toOne"||e.type==="reference")&&(w===null?a=!0:w===void 0?o=!0:e.type==="reference"&&typeof w=="object"&&(w=s.metadata.idMetadata.getId(w))),w};d.compoundIdField&&(e.type==="toMany"?f.push({[d.compoundIdField]:this.metadata.idMetadata.getId(i)}):f.push(s.metadata.idMetadata.getIdFilter(p(d.compoundIdField))));for(const h in d.fields)Object.prototype.hasOwnProperty.call(d.fields,h)&&f.push({[h]:p(d.fields[h])});return l.where={$and:f},(e.type==="toOne"||e.type==="reference")&&l.orderBy&&(l.limit=1),{findOptions:l,returnNull:a,returnUndefined:o}}async _mapRawDataToResult(e,t,r){let i=new this._entity(this._remult),s=new Qt(this._info,i,this,this._edp,this._remult,!1,r);return Object.defineProperty(i,et,{get:()=>s}),await s.loadDataFrom(e,t),s.saveOriginalData(),i}toJson(e){return e==null?e:Array.isArray(e)?e.map(t=>this.toJson(t)):typeof e.then=="function"?e.then(t=>this.toJson(t)):this.getEntityRef(e).toApiJson(!0)}fromJson(e,t){if(e==null)return e;if(Array.isArray(e))return e.map(i=>this.fromJson(i,t));let r=new this._entity(this._remult);for(const i of this._fieldsOf(e)){const s=i.key;if(Ae(i.valueType,!1)){let o=e[i.key];typeof o=="string"||typeof o=="number"?r[s]=o:r[s]=this._remult.repo(i.valueType).fromJson(o)}else e[s]!==void 0&&(r[s]=i.valueConverter.fromJson(e[i.key]))}if(this._fixTypes(r),t)return this.create(r);{let i=new Qt(this._info,r,this,this._edp,this._remult,!1);return Object.defineProperty(r,et,{get:()=>i}),i.id=i.getId(),i.saveOriginalData(),i.originalId=i.id,r}}async count(e){return this._edp.count(await this._translateWhereToFilter(e))}async deleteMany({where:e}){if(D.throwErrorIfFilterIsEmpty(e,"deleteMany"),this._dataProvider.isProxy)return this._edp.deleteMany(await this._translateWhereToFilter(e));{let t=0;for await(const r of this.query({where:e,aggregate:void 0}))await ne(r).delete(),t++;return t}}async findOne(e,t=!1){let r,i,s=e??{};if(s.useCache){let a=zr(s,this.metadata),o=JSON.stringify(a);if(i=this._cache.get(o),i!==void 0)if(i.value&&this.getEntityRef(i.value).wasDeleted())i=void 0,this._cache.delete(o);else return i.promise;else i={value:void 0,promise:void 0},this._cache.set(o,i)}return r=this.find({...s,limit:1},t).then(async a=>{let o;return a.length>0&&(o=a[0]),!o&&s.createIfNotFound&&(o=this.create(),s.where&&await $r(this.metadata,s.where,o)),o}),i&&(i.promise=r=r.then(a=>(i.value=a,a))),r}async findFirst(e,t,r=!1){if(t||(t={}),e)if(t.where){let i=t.where;t.where={$and:[i,e]}}else t.where=e;return this.findOne(t,r)}_fieldsOf(e){let t=Object.keys(e);return this.metadata.fields.toArray().filter(r=>t.includes(r.key))}create(e){var r;let t=new this._entity(this._remult);if(e){for(const i of this._fieldsOf(e)){const s=i.key;t[s]=e[s]}this._fixTypes(t)}return(r=this._defaultFindOptions)!=null&&r.where&&($r(this.metadata,this._defaultFindOptions.where,t),this._fixTypes(t)),this.getEntityRef(t),t}async _fixTypes(e){for(const t of this._fieldsOf(e)){const r=e[t.key];if(r!=null)if(t.valueType===Date&&!(r instanceof Date))e[t.key]=t.valueConverter.fromJson(t.valueConverter.toJson(r));else for(const[i,s]of[[String,"string"],[Number,"number"],[Boolean,"boolean"]])t.valueType===i&&typeof r!==s&&(e[t.key]=t.valueConverter.fromJson(t.valueConverter.toJson(r)))}return e}findId(e,t){if(e==null)return Promise.resolve(null);if(typeof e!="string"&&typeof e!="number")throw new Error("id can be either number or string, but got: "+typeof e);return this.findFirst({},{...t,where:this.metadata.idMetadata.getIdFilter(e)},!0)}async _translateWhereToFilter(e){var i,s;let t=e??{};(i=this._defaultFindOptions)!=null&&i.where&&(t={$and:[t,(s=this._defaultFindOptions)==null?void 0:s.where]}),this._dataProvider.isProxy||(this.metadata.options.backendPreprocessFilter&&(t=await this.metadata.options.backendPreprocessFilter(t,{metadata:this.metadata,getFilterPreciseValues:a=>D.getPreciseValues(this.metadata,a||t)})),this.metadata.options.backendPrefilter&&(t={$and:[t,await D.resolve(this.metadata.options.backendPrefilter)]}));let r=await D.fromEntityFilter(this.metadata,t);return r&&!this._dataProvider.isProxy&&(r=await D.translateCustomWhere(r,this.metadata,this._remult)),r}}function ja(n,e){let t=T.columnsOfType.get(n);t||T.columnsOfType.set(n,t=[]);let r=Ae(n)(e),i=xs(n),s=Object.getPrototypeOf(n);for(;s!=null;){let a=T.columnsOfType.get(s);a&&t.unshift(...a.filter(f=>!t.find(l=>l.key==f.key)));let o=Ae(s,!1);if(o){let f=o(e);r={...f,...r};let l=["saving","saved","deleting","deleted","validation"];for(const u of l)if(f[u]&&f[u]!==r[u]){let d=r[u];r[u]=async(p,h)=>{await d(p,h),await f[u](p,h)}}}s=Object.getPrototypeOf(s)}return new Wa(un(t,e),r,e,n,i)}class ln{constructor(e,t,r,i,s){c(this,"fieldsMetadata");c(this,"instance");c(this,"remult");c(this,"isNewRow");c(this,"_error");c(this,"_subscribers");c(this,"_isLoading",!1);c(this,"lookups",new Map);c(this,"errors");c(this,"originalValues",{});this.fieldsMetadata=e,this.instance=t,this.remult=r,this.isNewRow=i;{let a=r;a!=null&&a.iAmRemultProxy&&(r=T.remultFactory())}for(const a of e)if(Ae(a.valueType,!1)&&r){let f=new ca(r.repo(a.valueType),!!oe(a),a.allowNull);this.lookups.set(a.key,f);let l=t[a.key],u;Object.defineProperty(t,a.key,{get:()=>(this._subscribers&&(this._subscribers.reportObserved(),u||(u=this.fields.find(a.key),u._subscribers||(u._subscribers=new zt)),u._subscribers.reportObserved()),f.item),set:d=>{var p;f.set(d),(p=this._subscribers)==null||p.reportChanged(),u||(u=this.fields.find(a.key),u._subscribers||(u._subscribers=new zt)),u._subscribers.reportChanged()},enumerable:!(s!=null&&s.has(a.key))}),f.set(l)}else{const f=oe(a);if((f==null?void 0:f.type)==="toOne"){let l=t.hasOwnProperty(a.key),u=t[a.key];i&&!u&&(l=!1),Object.defineProperty(t,a.key,{get:()=>u,set:d=>{if(u=d,d===void 0)return;const p=a.options;if(p.field&&(this.instance[p.field]=f.toRepo.metadata.idMetadata.getId(d)),p.fields){for(const h in p.fields)if(Object.prototype.hasOwnProperty.call(p.fields,h)){const y=p.fields[h];this.instance[y]=d==null?null:d[h]}}},enumerable:!(s!=null&&s.has(a.key))}),l&&(t[a.key]=u)}}}get error(){var e;return(e=this._subscribers)==null||e.reportObserved(),this._error}set error(e){var t;this._error=e,(t=this._subscribers)==null||t.reportChanged()}subscribe(e){return this.initSubscribers(),this._subscribers.subscribe(e)}initSubscribers(){if(!this._subscribers){this._subscribers=new zt;const e=this._subscribers;for(const t of this.fieldsMetadata){let r=Ae(t.valueType,!1),i=this.fields.find(t.key);if(i._subscribers=new zt,!(r&&this.remult||oe(t))){let s=this.instance[t.key];Object.defineProperty(this.instance,t.key,{get:()=>(e.reportObserved(),i._subscribers.reportObserved(),s),set:a=>{s=a,e.reportChanged(),i._subscribers.reportChanged()},enumerable:!0})}}}}get isLoading(){var e;return(e=this._subscribers)==null||e.reportObserved(),this._isLoading}set isLoading(e){var t;this._isLoading=e,(t=this._subscribers)==null||t.reportChanged()}async waitLoad(){await ct([...this.lookups.values()],e=>e.waitLoad())}__assertValidity(){if(!this.hasErrors())throw this.buildErrorInfoObject()}buildErrorInfoObject(){var t;let e={modelState:Object.assign({},this.errors),message:this.error};if(!e.message){for(const r of this.fieldsMetadata)if((t=this.errors)!=null&&t[r.key]){e.message=this.fields[r.key].metadata.caption+": "+this.errors[r.key],this.error=e.message;break}}return new on(e)}catchSaveErrors(e){let t=e;if(t instanceof Promise)return t.then(i=>this.catchSaveErrors(i));t.error&&(t=t.error),t.message?this.error=t.message:t.Message?this.error=t.Message:this.error=t;let r=t.modelState;throw r||(r=t.ModelState),r&&(this.errors=r),e}__clearErrorsAndReportChanged(){this.errors=void 0,this.error=void 0,this._reportChangedToEntityAndFields()}_reportChangedToEntityAndFields(){if(this._subscribers){this._subscribers.reportChanged();for(const e of this.fields)e._subscribers.reportChanged()}}hasErrors(){var e;return(e=this._subscribers)==null||e.reportObserved(),!this.error&&this.errors==null}copyDataToObject(e=!1){let t={};for(const r of this.fieldsMetadata){let i=this.lookups.get(r.key),s;const a=oe(r);i?s=i.id:s=this.instance[r.key],a&&e&&!r.allowNull&&s==null&&(a.toRepo.metadata.idMetadata.field.valueType===Number?s=0:s=""),(!a||a.type==="reference")&&(s!==void 0&&(s=r.valueConverter.toJson(s),s!=null&&(s=r.valueConverter.fromJson(JSON.parse(JSON.stringify(s))))),t[r.key]=s)}return t}saveOriginalData(){this.originalValues=this.copyDataToObject(),this.saveMoreOriginalData()}saveMoreOriginalData(){}async validate(){if(this.__clearErrorsAndReportChanged(),await this.__performColumnAndEntityValidations(),this.hasErrors(),!this.hasErrors())return this.buildErrorInfoObject()}async __validateEntity(){this.__clearErrorsAndReportChanged(),await this.__performColumnAndEntityValidations(),this.__assertValidity()}async __performColumnAndEntityValidations(){}toApiJson(e=!1,t=!1){let r={};for(const i of this.fieldsMetadata)if(t||!this.remult||i.includedInApi(this.instance)){let s,a=this.lookups.get(i.key),o=!1;a?e?(s=a.toJson(),o=!0,r[i.key]=s):s=a.id:oe(i)&&!e?o=!0:(s=this.instance[i.key],this.remult||s&&Ae(s.constructor,!1)&&(s=ne(s).getId())),o||(r[i.key]=i.valueConverter.toJson(s))}return r}async _updateEntityBasedOnApi(e,t=!1){let r=Object.keys(e);for(const i of this.fieldsMetadata)if(r.includes(i.key)&&i.includedInApi(this.instance)&&(!this.remult||t||i.apiUpdateAllowed(this.instance))){let s=this.lookups.get(i.key);s?s.id=e[i.key]:this.instance[i.key]=i.valueConverter.fromJson(e[i.key])}await ct([...this.fields].filter(i=>!oe(i.metadata)),i=>i.load())}}class Qt extends ln{constructor(t,r,i,s,a,o,f){super(t.fieldsMetadata,r,a,o,f);c(this,"info");c(this,"repo");c(this,"edp");c(this,"_isNew");c(this,"repository");c(this,"metadata");c(this,"_wasDeleted",!1);c(this,"_columns");c(this,"_saving",!1);c(this,"id");c(this,"originalId");if(this.info=t,this.repo=i,this.edp=s,this._isNew=o,this.repository=i,this.metadata=t,o)for(const l of t.fieldsMetadata){const u=l.key;l.options.defaultValue&&r[u]===void 0&&(typeof l.options.defaultValue=="function"?r[u]=l.options.defaultValue(r):r[u]||(r[u]=l.options.defaultValue))}this.info.entityInfo.entityRefInit&&this.info.entityInfo.entityRefInit(this,r),Le.entityRefInit&&Le.entityRefInit(this,r)}clone(){const t=this.toApiJson(!0,!0);return this.repo.fromJson(t,this.isNew())}get relations(){return this.repo.relations(this.instance)}get apiUpdateAllowed(){return this.remult.isAllowedForInstance(this.instance,this.metadata.options.allowApiUpdate)}get apiDeleteAllowed(){return this.remult.isAllowedForInstance(this.instance,this.metadata.options.allowApiDelete)}get apiInsertAllowed(){return this.remult.isAllowedForInstance(this.instance,this.metadata.options.allowApiInsert)}getId(){const t=r=>{let i=this.lookups.get(r.key);return i?i.id:this.instance[r.key]};return this.metadata.idMetadata.field instanceof tt?this.metadata.idMetadata.field.getId(t):t(this.metadata.idMetadata.field)}saveMoreOriginalData(){this.originalId=this.getId()}wasDeleted(){var t;return(t=this._subscribers)==null||t.reportObserved(),this._wasDeleted}undoChanges(){this.loadDataFrom(this.originalValues),this.__clearErrorsAndReportChanged()}async reload(){return await this.edp.find({where:await this.getIdFilter()}).then(async t=>{if(t.length===0)throw this.repo._notFoundError(this.id);await this.loadDataFrom(t[0]),this.saveOriginalData()}),this._reportChangedToEntityAndFields(),this.instance}get fields(){if(!this._columns){let t=[],r={find:i=>r[typeof i=="string"?i:i.key],[Symbol.iterator]:()=>t[Symbol.iterator](),toArray:()=>t};for(const i of this.info.fieldsMetadata)t.push(r[i.key]=new or(i.options,i,this.instance,this,this));this._columns=r}return this._columns}async save(t){var r,i;try{if(this._saving)throw new Error("cannot save while entity is already saving");if(this._saving=!0,this.wasDeleted())throw new Error("cannot save a deleted row");this.isLoading=!0,t===void 0&&await this.__validateEntity();let s=!1,a=this.buildLifeCycleEvent(()=>s=!0);if(!this.repo._dataProvider.isProxy){for(const d of this.fields)d.metadata.options.saving&&await d.metadata.options.saving(this.instance,d,a);this.info.entityInfo.saving&&await this.info.entityInfo.saving(this.instance,a)}this.__assertValidity();let o=this.copyDataToObject(this.isNew()),f=[];for(const d of this.metadata.fields)if(d.dbReadOnly||t!==void 0&&!t.includes(d.key)){o[d.key]=void 0,f.push(d.key);let p=this.fields.find(d);p.value=p.originalValue}let l,u=this.isNew();try{if((r=this._subscribers)==null||r.reportChanged(),this.isNew())s?l=(l=await this.edp.find({where:await this.getIdFilter()}))[0]:l=await this.edp.insert(o);else{let d={},p=!1;for(const h in o)if(Object.prototype.hasOwnProperty.call(o,h)){const y=o[h];this.fields.find(h).valueChanged()&&!f.includes(h)&&y!==void 0&&(d[h]=y,p=!0)}if(!p)return this.instance;if(s)l=(await this.edp.find({where:await this.getIdFilter()}))[0];else{if(this.id===void 0)throw new Error("Invalid operation, id is undefined");l=await this.edp.update(this.id,d)}}if(l&&await this.loadDataFrom(l),a.id=this.getId(),!this.repo._dataProvider.isProxy&&(this.info.entityInfo.saved&&await this.info.entityInfo.saved(this.instance,a),this.repo.listeners))for(const d of this.repo.listeners)await((i=d.saved)==null?void 0:i.call(d,this.instance,u));return this.repo._remult.liveQueryPublisher.itemChanged(this.repo.metadata.key,[{id:this.getId(),oldId:this.getOriginalId(),deleted:!1}]),this.saveOriginalData(),this._isNew=!1,this.instance}catch(d){throw await this.catchSaveErrors(d)}}finally{this.isLoading=!1,this._reportChangedToEntityAndFields(),this._saving=!1}}async processInsertResponseDto(t){return await this.loadDataFrom(t),this.saveOriginalData(),this._isNew=!1,this.instance}async buildDtoForInsert(){await this.__validateEntity(),this.__assertValidity();let t=this.copyDataToObject(this.isNew());for(const r of this.metadata.fields)if(r.dbReadOnly){t[r.key]=void 0;let i=this.fields.find(r);i.value=i.originalValue}return t}buildLifeCycleEvent(t=()=>{}){const r=this;return{isNew:r.isNew(),fields:r.fields,id:r.getId(),originalId:r.getOriginalId(),metadata:r.repo.metadata,repository:r.repo,preventDefault:()=>t(),relations:r.repo.relations(r.instance)}}async getIdFilter(){return await this.repo._translateWhereToFilter(this.repo.metadata.idMetadata.getIdFilter(this.id))}async delete(){var i;this.__clearErrorsAndReportChanged();let t=!0,r=this.buildLifeCycleEvent(()=>t=!1);this.repo._dataProvider.isProxy||this.info.entityInfo.deleting&&await this.info.entityInfo.deleting(this.instance,r),this.__assertValidity();try{if(t){if(this.id===void 0)throw new Error("Invalid operation, id is undefined");await this.edp.delete(this.id)}if(this.repo._dataProvider.isProxy||this.info.entityInfo.deleted&&await this.info.entityInfo.deleted(this.instance,r),this.repo.listeners)for(const s of this.repo.listeners)await((i=s.deleted)==null?void 0:i.call(s,this.instance));this.repo._remult.liveQueryPublisher.itemChanged(this.repo.metadata.key,[{id:this.getId(),oldId:this.getOriginalId(),deleted:!0}]),this._wasDeleted=!0}catch(s){throw await this.catchSaveErrors(s)}}async loadDataFrom(t,r){for(const i of this.info.fields){let s=this.lookups.get(i.key);s?(s.id=t[i.key],r===void 0?!i.options.lazy&&!oe(i)&&await s.waitLoad():r.includes(i)&&await s.waitLoad()):oe(i)||(t[i.key]===void 0?delete this.instance[i.key]:this.instance[i.key]=t[i.key])}await this.calcServerExpression(),this.id=this.getId()}getOriginalId(){return this.originalId}async calcServerExpression(){if(!this.repo._dataProvider.isProxy){for(const t of this.info.fieldsMetadata)if(t.options.serverExpression){const r=await t.options.serverExpression(this.instance);r!==void 0&&(this.instance[t.key]=r)}}}isNew(){var t;return(t=this._subscribers)==null||t.reportObserved(),this._isNew}wasChanged(){var t;(t=this._subscribers)==null||t.reportObserved();for(const r of this.fields){const i=oe(r.metadata);if((!i||i.type=="reference")&&r.valueChanged())return!0}return!1}async __performColumnAndEntityValidations(){var t;for(const r of this.fieldsMetadata)r.options.validate&&await new or(r.options,r,this.instance,this,this).__performValidation();if(this.info.entityInfo.validation){let r=this.buildLifeCycleEvent(()=>{});await this.info.entityInfo.validation(this.instance,r)}if(this.repo.listeners)for(const r of this.repo.listeners)await((t=r.validating)==null?void 0:t.call(r,this.instance))}}const Ai=Symbol.for("controllerColumns");function un(n,e){return n.map(t=>Yr(t.settings(e),e))}function Ti(n,e){const t=e||ke;let r=n[Ai];if(r||(r=n[et]),!r){let i=T.columnsOfType.get(n.constructor);i||T.columnsOfType.set(n.constructor,i=[]);let s=Object.getPrototypeOf(n.constructor);for(;s!=null;){let a=T.columnsOfType.get(s);a&&i.unshift(...a.filter(o=>!i.find(f=>f.key==o.key))),s=Object.getPrototypeOf(s)}n[Ai]=r=new Ja(un(i,t).map(a=>new dn(a,void 0,t)),n,t)}return r}class Ja extends ln{constructor(t,r,i){super(t,r,i,!1);c(this,"fields");let s=[],a={find:o=>a[typeof o=="string"?o:o.key],[Symbol.iterator]:()=>s[Symbol.iterator](),toArray:()=>s};for(const o of t)s.push(a[o.key]=new or(o.options,o,r,void 0,this));this.fields=a}async __performColumnAndEntityValidations(){for(const t of this.fields)t instanceof or&&await t.__performValidation()}}class or{constructor(e,t,r,i,s){c(this,"settings");c(this,"metadata");c(this,"container");c(this,"helper");c(this,"rowBase");c(this,"_subscribers");c(this,"target");c(this,"entityRef");this.settings=e,this.metadata=t,this.container=r,this.helper=i,this.rowBase=s,this.target=this.settings.target,this.entityRef=this.helper}subscribe(e){return this._subscribers||this.rowBase.initSubscribers(),this._subscribers.subscribe(e)}valueIsNull(){this.reportObserved();let e=this.rowBase.lookups.get(this.metadata.key);return e?e.id===void 0||e.id===null:this.value===null}originalValueIsNull(){return this.reportObserved(),this.rowBase.lookups.get(this.metadata.key),this.rawOriginalValue()===null}get key(){return this.metadata.key}get repo(){var e;return(e=this.helper)==null?void 0:e.repository}async load(){let e=this.rowBase.lookups.get(this.metadata.key),t=oe(this.metadata);if(t&&this.helper){if(t.type==="toMany")return this.container[this.metadata.key]=await this.repo.relations(this.container)[this.key].find();{let r=await this.repo.relations(this.container)[this.metadata.key].findOne();if(r)this.container[this.metadata.key]=r;else return null}}else if(e)return this.valueChanged()&&await e.waitLoadOf(this.rawOriginalValue()),await e.waitLoad();return this.value}reportObserved(){var e,t;(e=this._subscribers)==null||e.reportObserved(),(t=this.rowBase._subscribers)==null||t.reportObserved()}reportChanged(){var e,t;(e=this._subscribers)==null||e.reportChanged(),(t=this.rowBase._subscribers)==null||t.reportChanged()}get error(){if(this.reportObserved(),!!this.rowBase.errors)return this.rowBase.errors[this.metadata.key]}set error(e){this.rowBase.errors||(this.rowBase.errors={}),this.rowBase.errors[this.metadata.key]=e,this.reportChanged()}get displayValue(){return this.reportObserved(),this.value!=null?this.settings.displayValue?this.settings.displayValue(this.container,this.value):this.metadata.valueConverter.displayValue?this.metadata.valueConverter.displayValue(this.value):this.value.toString():""}get value(){return this.container[this.metadata.key]}set value(e){this.container[this.metadata.key]=e}get originalValue(){this.reportObserved();let e=this.rowBase.lookups.get(this.metadata.key);return e?e.get(this.rawOriginalValue()):this.rowBase.originalValues[this.metadata.key]}rawOriginalValue(){return this.rowBase.originalValues[this.metadata.key]}setId(e){this.value=e}getId(){let e=this.rowBase.lookups.get(this.metadata.key);return e?e.id!=null?e.id:null:this.value}get inputValue(){this.reportObserved();let e=this.rowBase.lookups.get(this.metadata.key);return e?e.id!=null?e.id.toString():null:this.metadata.valueConverter.toInput(this.value,this.settings.inputType)}set inputValue(e){let t=this.rowBase.lookups.get(this.metadata.key);t?t.setId(e):this.value=this.metadata.valueConverter.fromInput(e,this.settings.inputType)}valueChanged(){this.reportObserved();let e=this.value,t=this.rowBase.lookups.get(this.metadata.key);return t&&(e=t.id),JSON.stringify(this.metadata.valueConverter.toJson(this.rowBase.originalValues[this.metadata.key]))!=JSON.stringify(this.metadata.valueConverter.toJson(e))}async __performValidation(){var e;try{const t=r=>{r!==!0&&r!==void 0&&!this.error&&(typeof r=="string"&&r.length>0?this.error=r:this.error="invalid value")};if(this.settings.validate){let r=this,i={entityRef:this.entityRef,get error(){return r.error},set error(s){r.error=s},isNew:((e=this.entityRef)==null?void 0:e.isNew())??!1,load:()=>r.load(),metadata:r.metadata,originalValue:r.originalValue,value:r.value,valueChanged:()=>r.valueChanged(),originalValueIsNull:()=>r.originalValueIsNull(),valueIsNull:()=>r.valueIsNull(),isBackend:()=>{var s,a,o;return!((o=(a=(s=r.rowBase)==null?void 0:s.remult)==null?void 0:a.dataProvider)!=null&&o.isProxy)}};if(Array.isArray(this.settings.validate))for(const s of this.settings.validate)t(await s(this.container,i));else typeof this.settings.validate=="function"&&t(await this.settings.validate(this.container,i))}}catch(t){typeof t=="string"?this.error=t:this.error=t==null?void 0:t.message}}async validate(){return await this.__performValidation(),!this.error}}let Ua={transformCaption:(n,e,t,r)=>t};const Pr=T.fieldOptionsEnricher||{enrichFieldOptions:n=>n},Va=T.captionTransformer||(T.captionTransformer=Ua);function fn(n,e,t,r){let i;return typeof n=="function"?t&&(i=n(t)):n&&(i=n),i=Va.transformCaption(t,e,i??"",r),i||(e?Br(e):"")}class dn{constructor(e,t,r){c(this,"settings");c(this,"entityDefs");c(this,"remult");c(this,"options");c(this,"target");c(this,"readonly",!1);c(this,"valueConverter");c(this,"allowNull");c(this,"caption");c(this,"dbName");c(this,"inputType");c(this,"key");c(this,"isServerExpression",!1);c(this,"valueType");this.settings=e,this.entityDefs=t,this.remult=r,this.options=this.settings,this.target=this.settings.target,this.valueConverter=new Proxy(this.settings.valueConverter??{},{get:(i,s)=>{let a=i[s];return typeof a=="function"?(...o)=>{try{return i[s](...o)}catch(f){const l=`${String(s)} failed for value ${o==null?void 0:o[0]}. Error: ${typeof f=="string"?f:f.message}`;throw new on({message:this.caption+": "+l,modelState:{[this.key]:l}})}}:a}}),this.allowNull=!!this.settings.allowNull,this.valueType=this.settings.valueType,this.key=this.settings.key,this.inputType=this.settings.inputType,e.serverExpression&&(this.isServerExpression=!0),typeof this.settings.allowApiUpdate=="boolean"&&(this.readonly=this.settings.allowApiUpdate),this.inputType||(this.inputType=this.valueConverter.inputType),this.dbName=e.dbName,this.dbName==null&&(this.dbName=e.key),this.caption=fn(e.caption,e.key,r,t)}apiUpdateAllowed(e){return this.options.allowApiUpdate===void 0?!0:this.remult.isAllowedForInstance(e,this.options.allowApiUpdate)}displayValue(e){return this.entityDefs.getEntityMetadataWithoutBreakingTheEntity(e).fields.find(this.key).displayValue}includedInApi(e){return this.options.includeInApi===void 0?!0:this.remult.isAllowedForInstance(e,this.options.includeInApi)}toInput(e,t){return this.valueConverter.toInput(e,t)}fromInput(e,t){return this.valueConverter.fromInput(e,t)}async getDbName(){return xr(this,this.entityDefs)}get dbReadOnly(){return!!this.settings.dbReadOnly}}class Wa{constructor(e,t,r,i,s){c(this,"entityInfo");c(this,"remult");c(this,"entityType");c(this,"key");c(this,"options");c(this,"fieldsMetadata",[]);c(this,"idMetadata",{getId:e=>{if(e==null)return e;const t=ne(e,!1);return t?t.getId():this.idMetadata.field instanceof tt?this.idMetadata.field.getId(e):e[this.idMetadata.field.key]},field:void 0,get fields(){return this.field instanceof tt?this.field.fields:[this.field]},createIdInFilter:e=>e.length>0?{$or:e.map(t=>this.idMetadata.getIdFilter(ne(t).getId()))}:{[this.fields.toArray()[0].key]:[]},isIdField:e=>e.key==this.idMetadata.field.key,getIdFilter:(...e)=>{if(this.idMetadata.field instanceof tt){let t=this.idMetadata.field;return e.length==1?t.isEqualTo(e[0]):{$or:e.map(r=>t.isEqualTo(r))}}return e.length==1?{[this.idMetadata.field.key]:e[0]}:{[this.idMetadata.field.key]:e}}});c(this,"fields");c(this,"dbName");c(this,"caption");if(this.entityInfo=t,this.remult=r,this.entityType=i,this.key=s,this.options=t,this.options.allowApiCrud!==void 0){let o;typeof this.options.allowApiCrud=="function"?o=(f,l)=>this.options.allowApiCrud(l):o=this.options.allowApiCrud,this.options.allowApiDelete===void 0&&(this.entityInfo.allowApiDelete=o),this.options.allowApiInsert===void 0&&(this.entityInfo.allowApiInsert=o),this.options.allowApiUpdate===void 0&&(this.entityInfo.allowApiUpdate=o),this.options.allowApiRead===void 0&&(this.options.allowApiRead=this.options.allowApiCrud)}this.options.allowApiRead===void 0&&(this.options.allowApiRead=!0),this.key||(this.key=i.name),t.dbName||(t.dbName=this.key),this.dbName=t.dbName;let a={find:o=>a[typeof o=="string"?o:o.key],[Symbol.iterator]:()=>this.fieldsMetadata[Symbol.iterator](),toArray:()=>this.fieldsMetadata};for(const o of e)this.fieldsMetadata.push(a[o.key]=new dn(o,this,r));if(this.fields=a,this.caption=fn(t.caption,this.key,r,this),t.id){let o=typeof t.id=="string"?this.fields.find(t.id):Array.isArray(t.id)?t.id.map(f=>this.fields.find(f)):typeof t.id=="function"?t.id(this.fields):Object.keys(t.id).map(f=>this.fields.find(f));Array.isArray(o)?o.length>1?this.idMetadata.field=new tt(...o):o.length==1&&(this.idMetadata.field=o[0]):this.idMetadata.field=o}if(!this.idMetadata.field){const o=this.fields.id;o?this.idMetadata.field=o:this.idMetadata.field=[...this.fields][0]}}apiUpdateAllowed(e){return this.options.allowApiUpdate===void 0?!1:e?this.getEntityMetadataWithoutBreakingTheEntity(e).apiUpdateAllowed:this.remult.isAllowedForInstance(void 0,this.options.allowApiUpdate)}get apiReadAllowed(){return this.options.allowApiRead===void 0?!0:this.remult.isAllowed(this.options.allowApiRead)}apiDeleteAllowed(e){return this.options.allowApiDelete===void 0?!1:e?this.getEntityMetadataWithoutBreakingTheEntity(e).apiDeleteAllowed:this.remult.isAllowedForInstance(void 0,this.options.allowApiDelete)}apiInsertAllowed(e){return this.options.allowApiUpdate===void 0?!1:e?this.getEntityMetadataWithoutBreakingTheEntity(e).apiInsertAllowed:this.remult.isAllowedForInstance(void 0,this.options.allowApiInsert)}getEntityMetadataWithoutBreakingTheEntity(e){let t=ne(e,!1);return t||this.remult.repo(this.entityType).getEntityRef({...e})}getDbName(){return mn(this)}}function Ha(...n){return(e,t)=>(n||(n=[]),n.splice(0,0,{valueType:e}),e[Zr]=n,e)}function Ga(n){var e,t;return((t=(e=n.options)==null?void 0:e.valueConverter)==null?void 0:t.fieldTypeInDb)==="autoincrement"}function Qa(...n){return(e,t)=>{Ha(r=>{r.valueConverter=lr.get(e),r.displayValue=(i,s)=>s==null?void 0:s.caption,r.validate=(i,s)=>{const a=lr.get(e).getValues();return s.value&&!a.find(o=>o===s.value)&&(s.value=a.find(o=>o.id===s.value.id)||s.value),$e.in(a)(i,s)}},...n)(e)}}class lr{constructor(e){c(this,"valueListType");c(this,"byIdMap",new Map);c(this,"values",[]);c(this,"isNumeric",!1);c(this,"fieldTypeInDb");c(this,"inputType");this.valueListType=e;for(let r in this.valueListType){let i=this.valueListType[r];i instanceof this.valueListType&&(i.id===void 0&&(i.id=r),typeof i.id=="number"&&(this.isNumeric=!0),i.caption===void 0&&(i.caption=Br(i.id!==void 0?i.id.toString():r)),this.byIdMap.set(i.id,i),this.values.push(i))}this.isNumeric&&(this.fieldTypeInDb="integer");var t=this.valueListType[Zr];if(t){for(const r of t)r!=null&&r.getValues&&(this.values.splice(0,this.values.length,...r.getValues()),this.byIdMap.clear(),this.values.forEach(i=>{i.caption===void 0&&i.id!==void 0&&(i.caption=Br(i.id)),this.byIdMap.set(i.id,i)}));if(this.values.find(r=>r.id===void 0))throw new Error(`ValueType ${this.valueListType} has values without an id`)}else throw new Error("ValueType not yet initialized, did you forget to call @ValueListFieldType on "+e)}static get(e){let t=Fi.get(e);return t||(t=new lr(e),Fi.set(e,t)),t}getValues(){return this.values}byId(e){return this.isNumeric&&(e=+e),this.byIdMap.get(e)}fromJson(e){return this.byId(e)}toJson(e){if(e)return e.id}fromDb(e){return this.fromJson(e)}toDb(e){return this.toJson(e)}toInput(e,t){return this.toJson(e)}fromInput(e,t){return this.fromJson(e)}displayValue(e){return e?e.caption:""}}const Fi=new Map,Zr=Symbol.for("storableMember"),Dr=Symbol.for("fieldOptionalValues");function cn(n,e){var r;let t={};for(const i of n)if(i)if(typeof i=="function")i(t,e);else{const{validate:s,...a}=i;t.validate=tr(t.validate,s),Object.assign(t,a)}return(r=Pr.enrichFieldOptions)==null||r.call(Pr,t),t}function Yr(n,e){if(n.valueType){let i=n.valueType[Zr];i&&(n=cn([...i,n],e))}if(n.valueType==String){let i=n;n.valueConverter||(i.valueConverter=_e.String)}if(n.valueType==Number){let i=n;n.valueConverter||(i.valueConverter=_e.Number)}if(n.valueType==Date){let i=n;n.valueConverter||(i.valueConverter=_e.Date)}if(n.valueType==Boolean){let i=n;i.valueConverter||(i.valueConverter=_e.Boolean)}if(!n.valueConverter){if(Ae(n.valueType,!1)){let s;n.valueConverter={toDb:a=>a,fromDb:a=>a},n.valueConverter=new Proxy(n.valueConverter,{get(a,o){if(a[o]===void 0&&s===void 0){if(o==="inputType")return"";s=e.repo(n.valueType).metadata.idMetadata.field.valueType===Number;for(const f of["fieldTypeInDb","toJson","fromJson","toDb","fromDb"])a[f]=s?_e.Integer[f]:_e.String[f]}return a[o]},set(a,o,f,l){return a[o]=f,!0}})}else n.valueConverter=_e.Default;return n}n.valueConverter.toJson||(n.valueConverter.toJson=i=>i),n.valueConverter.fromJson||(n.valueConverter.fromJson=i=>i);const t=n.valueConverter.fromJson,r=n.valueConverter.toJson;return n.valueConverter.toDb||(n.valueConverter.toDb=i=>r(i)),n.valueConverter.fromDb||(n.valueConverter.fromDb=i=>t(i)),n.valueConverter.toInput||(n.valueConverter.toInput=i=>r(i)),n.valueConverter.fromInput||(n.valueConverter.fromInput=i=>t(i)),n}class hn{get _(){return ne(this)}save(){return ne(this).save()}assign(e){return Ot(this,e),this}delete(){return this._.delete()}isNew(){return this._.isNew()}get $(){return this._.fields}}class zt{constructor(){c(this,"_subscribers")}reportChanged(){this._subscribers&&this._subscribers.forEach(e=>e.reportChanged())}reportObserved(){this._subscribers&&this._subscribers.forEach(e=>e.reportObserved())}subscribe(e){let t;return typeof e=="function"?t={reportChanged:()=>e(),reportObserved:()=>{}}:t=e,this._subscribers||(this._subscribers=[]),this._subscribers.push(t),()=>this._subscribers=this._subscribers.filter(r=>r!=t)}}function za(n){return n.metadata?n.metadata:Ae(n,!1)?ke.repo(n).metadata:n}function Ka(n){return Ae(n,!1)?ke.repo(n):n}async function ct(n,e){const t=[];for(let r=0;r<n.length;r++){const i=n[r];t.push(await e(i,r))}return t}const ht=class ht{constructor(e){c(this,"sql");c(this,"wrapIdentifier",e=>e);c(this,"provideMigrationBuilder");c(this,"createdEntities",[]);c(this,"end");this.sql=e,e.wrapIdentifier&&(this.wrapIdentifier=t=>e.wrapIdentifier(t)),pt(e,"provideMigrationBuilder")&&(this.provideMigrationBuilder=t=>e.provideMigrationBuilder(t)),pt(e,"end")&&(this.end=()=>e.end())}static getDb(e){const t=e||ke.dataProvider;if(pt(t,"createCommand"))return t;throw"the data provider is not an SqlCommandFactory"}createCommand(){return new Za(this.sql.createCommand(),ht.LogToConsole)}async execute(e){return await this.createCommand().execute(e)}_getSourceSql(){return this.sql}async ensureSchema(e){this.sql.ensureSchema&&await this.sql.ensureSchema(e)}getEntityDataProvider(e){if(!this.sql.supportsJsonColumnType)for(const t of e.fields.toArray())t.valueConverter.fieldTypeInDb==="json"&&(t.valueConverter={...t.valueConverter,toDb:_e.JsonString.toDb,fromDb:_e.JsonString.fromDb});return new pn(e,this,async t=>{this.createdEntities.indexOf(t.$entityName)<0&&(this.createdEntities.push(t.$entityName),await this.sql.entityIsUsedForTheFirstTime(e))},this.sql)}transaction(e){return this.sql.transaction(async t=>{let r=!1;try{await e(new ht({createCommand:()=>{let i=t.createCommand();return{addParameterAndReturnSqlToken:s=>i.param(s),param:s=>i.param(s),execute:async s=>{if(r)throw"can't run a command after the transaction was completed";return i.execute(s)}}},getLimitSqlSyntax:this.sql.getLimitSqlSyntax,entityIsUsedForTheFirstTime:i=>t.entityIsUsedForTheFirstTime(i),transaction:i=>t.transaction(i),supportsJsonColumnType:this.sql.supportsJsonColumnType,wrapIdentifier:this.wrapIdentifier,end:this.end,doesNotSupportReturningSyntax:this.sql.doesNotSupportReturningSyntax,doesNotSupportReturningSyntaxOnlyForUpdate:this.sql.doesNotSupportReturningSyntaxOnlyForUpdate,orderByNullsFirst:this.sql.orderByNullsFirst}))}finally{r=!0}})}static rawFilter(e){return{[en]:{buildSql:e}}}static async filterToRaw(e,t,r,i,s){r||(r=new Ya);const a=Ka(e);var o=new ze(r,i||await yn(a.metadata,s));return o._addWhere=!1,await(await it(a)._translateWhereToFilter(t)).__applyToConsumer(o),await o.resolveWhere()}};c(ht,"LogToConsole",!1),c(ht,"durationThreshold",0);let mt=ht;const Xa=new Map([["INSERT","⚪"],["SELECT","🔵"],["UPDATE","🟣"],["DELETE","🟤"],["CREATE","🟩"],["ALTER","🟨"],["DROP","🟥"],["TRUNCATE","⬛"],["GRANT","🟪"],["REVOKE","🟫"]]);class Za{constructor(e,t){c(this,"origin");c(this,"logToConsole");c(this,"args",{});this.origin=e,this.logToConsole=t}addParameterAndReturnSqlToken(e){return this.param(e)}param(e,t){let r=this.origin.param(e);return this.args[r]=e,r}async execute(e){try{let r=new Date,i=await this.origin.execute(e);if(this.logToConsole!==!1){var t=new Date().valueOf()-r.valueOf();if(t>=mt.durationThreshold){const s=t/1e3;if(this.logToConsole==="oneLiner"){const a=e.replace(/(\r\n|\n|\r|\t)/gm," ").replace(/ +/g," ").trim(),o=a.split(" ")[0].toUpperCase();console.info(`${Xa.get(o)||"💢"} (${s.toFixed(3)}) ${a} ${JSON.stringify(this.args)}`)}else typeof this.logToConsole=="function"?this.logToConsole(s,e,this.args):console.info(e+`
2
- `,{arguments:this.args,duration:s})}}return i}catch(r){throw console.error((r.message||"Sql Error")+`:
3
- `,e,{arguments:this.args,error:r}),r}}}class pn{constructor(e,t,r,i){c(this,"entity");c(this,"sql");c(this,"iAmUsed");c(this,"strategy");this.entity=e,this.sql=t,this.iAmUsed=r,this.strategy=i}async init(){let e=await yn(this.entity,t=>this.sql.wrapIdentifier(t));return await this.iAmUsed(e),e}async count(e){let t=await this.init(),r="select count(*) count from "+t.$entityName,i=this.sql.createCommand();if(e){let s=new ze(i,t);e.__applyToConsumer(s),r+=await s.resolveWhere()}return i.execute(r).then(s=>Number(s.rows[0].count))}async groupBy(e){return await xa(e,await this.init(),this.sql.createCommand(),this.sql._getSourceSql().orderByNullsFirst,this.sql._getSourceSql().getLimitSqlSyntax)}async find(e){let t=await this.init(),{colKeys:r,select:i}=this.buildSelect(t);i="select "+i,i+=`
4
- from `+t.$entityName;let s=this.sql.createCommand();if(e){if(e.where){let a=new ze(s,t);e.where.__applyToConsumer(a),i+=await a.resolveWhere()}if(e.limit&&(e.orderBy=Ee.createUniqueSort(this.entity,e.orderBy)),e.orderBy||(e.orderBy=Ee.createUniqueSort(this.entity,new Ee)),e.orderBy){let a=!0,o=[];for(const f of e.orderBy.Segments)o.push(f);for(const f of o)a?(i+=" Order By ",a=!1):i+=", ",i+=t.$dbNameOf(f.field),f.isDescending&&(i+=" desc"),this.sql._getSourceSql().orderByNullsFirst&&(f.isDescending?i+=" nulls last":i+=" nulls first")}if(e.limit){let a=1;e.page&&(a=e.page),a<1&&(a=1),i+=" "+this.strategy.getLimitSqlSyntax(e.limit,(a-1)*e.limit)}}return s.execute(i).then(a=>a.rows.map(o=>this.buildResultRow(r,o,a)))}buildResultRow(e,t,r){let i={};for(let s=0;s<e.length;s++){const a=e[s];try{i[a.key]=a.valueConverter.fromDb(t[r.getColumnKeyInResultForIndexInSelect(s)])}catch(o){throw new Error("Failed to load from db:"+a.key+`\r
5
- `+o)}}return i}buildSelect(e){let t="",r=[];for(const i of this.entity.fields)i.isServerExpression||(r.length>0&&(t+=", "),t+=e.$dbNameOf(i),i.options.sqlExpression&&(t+=" as "+i.key),r.push(i));return{colKeys:r,select:t}}async update(e,t){let r=await this.init(),i=this.sql.createCommand(),s="update "+r.$entityName+" set ",a=!1;for(const p of this.entity.fields)if(!$i(p,r)){if(t[p.key]!==void 0){let h=p.valueConverter.toDb(t[p.key]);h!==void 0&&(a?s+=", ":a=!0,s+=r.$dbNameOf(p)+" = "+i.param(h))}}const o=this.entity.idMetadata.getIdFilter(e);let f=new ze(i,r);D.fromEntityFilter(this.entity,o).__applyToConsumer(f),s+=await f.resolveWhere();let{colKeys:l,select:u}=this.buildSelect(r),d=!0;return this.sql._getSourceSql().doesNotSupportReturningSyntax&&(d=!1),d&&this.sql._getSourceSql().doesNotSupportReturningSyntaxOnlyForUpdate&&(d=!1),d&&(s+=" returning "+u),i.execute(s).then(p=>{var h,y;if((y=(h=this.sql._getSourceSql()).afterMutation)==null||y.call(h),!d)return Si(this.entity,this,t,e,"update");if(p.rows.length!=1)throw new Error("Failed to update row with id "+e+", rows updated: "+p.rows.length);return this.buildResultRow(l,p.rows[0],p)})}async delete(e){let t=await this.init(),r=this.sql.createCommand(),i=new ze(r,t);D.fromEntityFilter(this.entity,this.entity.idMetadata.getIdFilter(e)).__applyToConsumer(i);let s="delete from "+t.$entityName;return s+=await i.resolveWhere(),r.execute(s).then(()=>{var a,o;(o=(a=this.sql._getSourceSql()).afterMutation)==null||o.call(a)})}async insert(e){let t=await this.init(),r=this.sql.createCommand(),i="",s="",a=!1;for(const u of this.entity.fields)if(!$i(u,t)){let d=u.valueConverter.toDb(e[u.key]);d!=null&&(a?(i+=", ",s+=", "):a=!0,i+=t.$dbNameOf(u),s+=r.param(d))}let o=`insert into ${t.$entityName} (${i}) values (${s})`,{colKeys:f,select:l}=this.buildSelect(t);return this.sql._getSourceSql().doesNotSupportReturningSyntax||(o+=" returning "+l),await r.execute(o).then(u=>{var d,p;if((p=(d=this.sql._getSourceSql()).afterMutation)==null||p.call(d),this.sql._getSourceSql().doesNotSupportReturningSyntax)if(Ga(this.entity.idMetadata.field)){const h=u.rows[0];if(typeof h!="number")throw new Error("Auto increment, for a database that is does not support returning syntax, should return an array with the single last added id. Instead it returned: "+JSON.stringify(h));return this.find({where:new D(y=>y.isEqualTo(this.entity.idMetadata.field,h))}).then(y=>y[0])}else return Si(this.entity,this,e,void 0,"insert");return this.buildResultRow(f,u.rows[0],u)})}}c(pn,"LogToConsole",!1);class Ya{execute(e){throw new Error("Method not implemented.")}addParameterAndReturnSqlToken(e){return this.param(e)}param(e){return e===null?"null":(e instanceof Date&&(e=e.toISOString()),typeof e=="string"?(e==null&&(e=""),"'"+e.replace(/'/g,"''")+"'"):e.toString())}}function Si(n,e,t,r,i){const s=r!==void 0?n.idMetadata.getIdFilter(r):{};return e.find({where:new D(a=>{for(const o of n.idMetadata.fields)a.isEqualTo(o,t[o.key]??s[o.key])})}).then(a=>{if(a.length!=1)throw new Error(`Failed to ${i} row - result contained ${a.length} rows`);return a[0]})}async function xa(n,e,t,r,i){let s="select count(*) as count",a="";const o=[];if(o.push((d,p)=>{p[ua]=Number(d)}),n!=null&&n.group)for(const d of n==null?void 0:n.group)d.isServerExpression||(s+=", "+e.$dbNameOf(d),d.options.sqlExpression&&(s+=" as "+d.key),a==""?a=" group by ":a+=", ",a+=e.$dbNameOf(d)),o.push((p,h)=>{h[d.key]=d.valueConverter.fromDb(p)});for(const d of da){const p=n==null?void 0:n[d];if(p)for(const h of p){if(!h.isServerExpression){const w=await e.$dbNameOf(h);s+=`, ${u(d,w)} as ${h.key}_${d}`}const y=h.valueType===Number||d=="distinctCount";o.push((w,I)=>{y&&(w=Number(w)),I[h.key]={...I[h.key],[d]:w}})}}if(s+=`
6
- from `+e.$entityName,n!=null&&n.where){let d=new ze(t,e);n==null||n.where.__applyToConsumer(d),s+=await d.resolveWhere()}a&&(s+=a);let f="";if(n!=null&&n.orderBy){for(const d of n==null?void 0:n.orderBy){f==""?f=" order by ":f+=", ";let p=d.field&&await e.$dbNameOf(d.field);switch(d.operation){case"count":p=d.operation+"(*)";break;case void 0:break;default:p=u(d.operation,p)}f+=p,d.isDescending&&(f+=" desc"),r&&(d.isDescending?f+=" nulls last":f+=" nulls first")}f&&(s+=f)}if(n!=null&&n.limit){let d=1;n.page&&(d=n.page),d<1&&(d=1),s+=" "+i(n.limit,(d-1)*n.limit)}const l=await t.execute(s);return l.rows.map(d=>{let p={};return o.forEach((h,y)=>h(d[l.getColumnKeyInResultForIndexInSelect(y)],p)),p});function u(d,p){return d==="distinctCount"?`count (distinct ${p})`:`${d}( ${p} )`}}class ze{constructor(e,t){c(this,"r");c(this,"nameProvider");c(this,"where","");c(this,"_addWhere",!0);c(this,"promises",[]);this.r=e,this.nameProvider=t}async resolveWhere(){for(;this.promises.length>0;){let e=this.promises;this.promises=[];for(const t of e)await t}return this.where}custom(e,t){throw new Error("Custom filter should be translated before it gets here")}or(e){let t="";this.promises.push((async()=>{for(const r of e){let i=new ze(this.r,this.nameProvider);i._addWhere=!1,r.__applyToConsumer(i);let s=await i.resolveWhere();if(!s)return;s.length>0&&(t.length>0&&(t+=" or "),e.length>1?t+="("+s+")":t+=s)}this.addToWhere("("+t+")")})())}not(e){this.promises.push((async()=>{let t=new ze(this.r,this.nameProvider);t._addWhere=!1,e.__applyToConsumer(t);let r=await t.resolveWhere();r&&this.addToWhere("not ("+r+")")})())}isNull(e){this.promises.push((async()=>this.addToWhere(this.nameProvider.$dbNameOf(e)+" is null"))())}isNotNull(e){this.promises.push((async()=>this.addToWhere(this.nameProvider.$dbNameOf(e)+" is not null"))())}isIn(e,t){this.promises.push((async()=>{t&&t.length>0?this.addToWhere(this.nameProvider.$dbNameOf(e)+" in ("+t.map(r=>this.r.param(e.valueConverter.toDb(r))).join(",")+")"):this.addToWhere("1 = 0 /*isIn with no values*/")})())}isEqualTo(e,t){this.add(e,t,"=")}isDifferentFrom(e,t){this.add(e,t,"<>")}isGreaterOrEqualTo(e,t){this.add(e,t,">=")}isGreaterThan(e,t){this.add(e,t,">")}isLessOrEqualTo(e,t){this.add(e,t,"<=")}isLessThan(e,t){this.add(e,t,"<")}containsCaseInsensitive(e,t){this.promises.push((async()=>{this.addToWhere("lower ("+this.nameProvider.$dbNameOf(e)+") like lower ('%"+t.replace(/'/g,"''")+"%')")})())}notContainsCaseInsensitive(e,t){this.promises.push((async()=>{this.addToWhere("not lower ("+this.nameProvider.$dbNameOf(e)+") like lower ('%"+t.replace(/'/g,"''")+"%')")})())}startsWithCaseInsensitive(e,t){this.promises.push((async()=>{this.addToWhere("lower ("+this.nameProvider.$dbNameOf(e)+") like lower ('"+t.replace(/'/g,"''")+"%')")})())}endsWithCaseInsensitive(e,t){this.promises.push((async()=>{this.addToWhere("lower ("+this.nameProvider.$dbNameOf(e)+") like lower ('%"+t.replace(/'/g,"''")+"')")})())}add(e,t,r){this.promises.push((async()=>{let i=this.nameProvider.$dbNameOf(e)+" "+r+" "+this.r.param(e.valueConverter.toDb(t));this.addToWhere(i)})())}addToWhere(e){this.where.length==0?this._addWhere&&(this.where+=" where "):this.where+=" and ",this.where+=e}databaseCustom(e){this.promises.push((async()=>{if(e!=null&&e.buildSql){let t=new eo(this.r,this.nameProvider.wrapIdentifier),r=await e.buildSql(t);typeof r!="string"&&(r=t.sql),r&&this.addToWhere("("+r+")")}})())}}class eo{constructor(e,t){c(this,"r");c(this,"wrapIdentifier");c(this,"sql","");c(this,"param",(e,t)=>(typeof t=="object"&&t.valueConverter.toDb&&(e=t.valueConverter.toDb(e)),this.r.param(e)));c(this,"filterToRaw",async(e,t)=>mt.filterToRaw(e,t,this,void 0,this.wrapIdentifier));this.r=e,this.wrapIdentifier=t,this.param.bind(this),this.filterToRaw.bind(this)}addParameterAndReturnSqlToken(e){return this.param(e)}}function $i(n,e){return n.dbReadOnly||n.isServerExpression||n.options.sqlExpression&&n.dbName!=e.$dbNameOf(n)}async function yn(n,e){return to(n,e,!0)}async function to(n,e,t=!1){let r=typeof e=="function"?{wrapIdentifier:e}:e||{};var i=za(n);r.wrapIdentifier||(r.wrapIdentifier=ke.dataProvider.wrapIdentifier),r.wrapIdentifier||(r.wrapIdentifier=a=>a);const s={$entityName:await mn(i,r.wrapIdentifier),toString:()=>s.$entityName,$dbNameOf:a=>{var o;return typeof a=="string"?o=a:o=a.key,s[o]},wrapIdentifier:r.wrapIdentifier};for(const a of i.fields){let o=await xr(a,i,r.wrapIdentifier,t);a.options.sqlExpression||(typeof r.tableName=="string"?o=r.wrapIdentifier(r.tableName)+"."+o:r.tableName===!0&&(o=s.$entityName+"."+o)),s[a.key]=o}return s}async function mn(n,e=t=>t){if(n.options.sqlExpression){if(typeof n.options.sqlExpression=="string")return n.options.sqlExpression;if(typeof n.options.sqlExpression=="function"){const t=n.options.sqlExpression;try{return n.options.sqlExpression="recursive sqlExpression call for entity '"+n.key+"'. ",await t(n)}finally{n.options.sqlExpression=t}}}return e(n.dbName)}const Rr=Symbol.for("sqlExpressionInProgressKey");async function xr(n,e,t=i=>i,r=!1){try{if(n.options.sqlExpression){let a;if(typeof n.options.sqlExpression=="function"){if(n[Rr]&&!r)return"recursive sqlExpression call for field '"+n.key+"'. \0";try{n[Rr]=!0,a=await n.options.sqlExpression(e),a.includes("\0")||(n.options.sqlExpression=()=>a)}finally{delete n[Rr]}}else a=n.options.sqlExpression;return a||n.dbName}const i=oe(n);let s=(i==null?void 0:i.type)==="toOne"&&n.options.field;if(s){let a=e.fields.find(s);if(a)return xr(a,e,t,r)}return t(n.dbName)}finally{}}function gn(n,...e){return(t,r)=>{let i=t;for(;i!=null;){for(const a in i)if(Object.prototype.hasOwnProperty.call(i,a)){const o=t[a];o!=null&&o.rawFilterInfo&&(o.rawFilterInfo.key||(o.rawFilterInfo.key=a))}i=Object.getPrototypeOf(i)}let s=a=>{let o={};for(const l of e)l&&(typeof l=="function"?l(o,a):Object.assign(o,l));let f=Object.getPrototypeOf(t);if(f){let l=Ae(f,!1);if(l){let u=l(a);u&&(o={...u,...o})}}return o};return T.allEntities.push(t),$a(t,{key:n}),t[Zi]=s,t[Yi]=n,t}}var ur=typeof globalThis<"u"?globalThis:typeof window<"u"?window:typeof global<"u"?global:typeof self<"u"?self:{},Ye={},ae={},pe={};Object.defineProperty(pe,"__esModule",{value:!0});pe.output=pe.exists=pe.hash=pe.bytes=pe.bool=pe.number=pe.isBytes=void 0;function fr(n){if(!Number.isSafeInteger(n)||n<0)throw new Error(`positive integer expected, not ${n}`)}pe.number=fr;function wn(n){if(typeof n!="boolean")throw new Error(`boolean expected, not ${n}`)}pe.bool=wn;function _n(n){return n instanceof Uint8Array||n!=null&&typeof n=="object"&&n.constructor.name==="Uint8Array"}pe.isBytes=_n;function ei(n,...e){if(!_n(n))throw new Error("Uint8Array expected");if(e.length>0&&!e.includes(n.length))throw new Error(`Uint8Array expected of length ${e}, not of length=${n.length}`)}pe.bytes=ei;function bn(n){if(typeof n!="function"||typeof n.create!="function")throw new Error("Hash should be wrapped by utils.wrapConstructor");fr(n.outputLen),fr(n.blockLen)}pe.hash=bn;function vn(n,e=!0){if(n.destroyed)throw new Error("Hash instance has been destroyed");if(e&&n.finished)throw new Error("Hash#digest() has already been called")}pe.exists=vn;function kn(n,e){ei(n);const t=e.outputLen;if(n.length<t)throw new Error(`digestInto() expects output buffer of length at least ${t}`)}pe.output=kn;const ro={number:fr,bool:wn,bytes:ei,hash:bn,exists:vn,output:kn};pe.default=ro;var B={};Object.defineProperty(B,"__esModule",{value:!0});B.add5L=B.add5H=B.add4H=B.add4L=B.add3H=B.add3L=B.add=B.rotlBL=B.rotlBH=B.rotlSL=B.rotlSH=B.rotr32L=B.rotr32H=B.rotrBL=B.rotrBH=B.rotrSL=B.rotrSH=B.shrSL=B.shrSH=B.toBig=B.split=B.fromBig=void 0;const Kt=BigInt(2**32-1),Ur=BigInt(32);function ti(n,e=!1){return e?{h:Number(n&Kt),l:Number(n>>Ur&Kt)}:{h:Number(n>>Ur&Kt)|0,l:Number(n&Kt)|0}}B.fromBig=ti;function In(n,e=!1){let t=new Uint32Array(n.length),r=new Uint32Array(n.length);for(let i=0;i<n.length;i++){const{h:s,l:a}=ti(n[i],e);[t[i],r[i]]=[s,a]}return[t,r]}B.split=In;const On=(n,e)=>BigInt(n>>>0)<<Ur|BigInt(e>>>0);B.toBig=On;const Cn=(n,e,t)=>n>>>t;B.shrSH=Cn;const En=(n,e,t)=>n<<32-t|e>>>t;B.shrSL=En;const An=(n,e,t)=>n>>>t|e<<32-t;B.rotrSH=An;const Tn=(n,e,t)=>n<<32-t|e>>>t;B.rotrSL=Tn;const Fn=(n,e,t)=>n<<64-t|e>>>t-32;B.rotrBH=Fn;const Sn=(n,e,t)=>n>>>t-32|e<<64-t;B.rotrBL=Sn;const $n=(n,e)=>e;B.rotr32H=$n;const Pn=(n,e)=>n;B.rotr32L=Pn;const Dn=(n,e,t)=>n<<t|e>>>32-t;B.rotlSH=Dn;const Rn=(n,e,t)=>e<<t|n>>>32-t;B.rotlSL=Rn;const Mn=(n,e,t)=>e<<t-32|n>>>64-t;B.rotlBH=Mn;const Nn=(n,e,t)=>n<<t-32|e>>>64-t;B.rotlBL=Nn;function Ln(n,e,t,r){const i=(e>>>0)+(r>>>0);return{h:n+t+(i/2**32|0)|0,l:i|0}}B.add=Ln;const Bn=(n,e,t)=>(n>>>0)+(e>>>0)+(t>>>0);B.add3L=Bn;const qn=(n,e,t,r)=>e+t+r+(n/2**32|0)|0;B.add3H=qn;const jn=(n,e,t,r)=>(n>>>0)+(e>>>0)+(t>>>0)+(r>>>0);B.add4L=jn;const Jn=(n,e,t,r,i)=>e+t+r+i+(n/2**32|0)|0;B.add4H=Jn;const Un=(n,e,t,r,i)=>(n>>>0)+(e>>>0)+(t>>>0)+(r>>>0)+(i>>>0);B.add5L=Un;const Vn=(n,e,t,r,i,s)=>e+t+r+i+s+(n/2**32|0)|0;B.add5H=Vn;const io={fromBig:ti,split:In,toBig:On,shrSH:Cn,shrSL:En,rotrSH:An,rotrSL:Tn,rotrBH:Fn,rotrBL:Sn,rotr32H:$n,rotr32L:Pn,rotlSH:Dn,rotlSL:Rn,rotlBH:Mn,rotlBL:Nn,add:Ln,add3L:Bn,add3H:qn,add4L:jn,add4H:Jn,add5H:Vn,add5L:Un};B.default=io;var Wn={},wr={};Object.defineProperty(wr,"__esModule",{value:!0});wr.crypto=void 0;wr.crypto=typeof globalThis=="object"&&"crypto"in globalThis?globalThis.crypto:void 0;(function(n){/*! noble-hashes - MIT License (c) 2022 Paul Miller (paulmillr.com) */Object.defineProperty(n,"__esModule",{value:!0}),n.randomBytes=n.wrapXOFConstructorWithOpts=n.wrapConstructorWithOpts=n.wrapConstructor=n.checkOpts=n.Hash=n.concatBytes=n.toBytes=n.utf8ToBytes=n.asyncLoop=n.nextTick=n.hexToBytes=n.bytesToHex=n.byteSwap32=n.byteSwapIfBE=n.byteSwap=n.isLE=n.rotl=n.rotr=n.createView=n.u32=n.u8=n.isBytes=void 0;const e=wr,t=pe;function r(g){return g instanceof Uint8Array||g!=null&&typeof g=="object"&&g.constructor.name==="Uint8Array"}n.isBytes=r;const i=g=>new Uint8Array(g.buffer,g.byteOffset,g.byteLength);n.u8=i;const s=g=>new Uint32Array(g.buffer,g.byteOffset,Math.floor(g.byteLength/4));n.u32=s;const a=g=>new DataView(g.buffer,g.byteOffset,g.byteLength);n.createView=a;const o=(g,_)=>g<<32-_|g>>>_;n.rotr=o;const f=(g,_)=>g<<_|g>>>32-_>>>0;n.rotl=f,n.isLE=new Uint8Array(new Uint32Array([287454020]).buffer)[0]===68;const l=g=>g<<24&4278190080|g<<8&16711680|g>>>8&65280|g>>>24&255;n.byteSwap=l,n.byteSwapIfBE=n.isLE?g=>g:g=>(0,n.byteSwap)(g);function u(g){for(let _=0;_<g.length;_++)g[_]=(0,n.byteSwap)(g[_])}n.byteSwap32=u;const d=Array.from({length:256},(g,_)=>_.toString(16).padStart(2,"0"));function p(g){(0,t.bytes)(g);let _="";for(let A=0;A<g.length;A++)_+=d[g[A]];return _}n.bytesToHex=p;const h={_0:48,_9:57,_A:65,_F:70,_a:97,_f:102};function y(g){if(g>=h._0&&g<=h._9)return g-h._0;if(g>=h._A&&g<=h._F)return g-(h._A-10);if(g>=h._a&&g<=h._f)return g-(h._a-10)}function w(g){if(typeof g!="string")throw new Error("hex string expected, got "+typeof g);const _=g.length,A=_/2;if(_%2)throw new Error("padded hex string expected, got unpadded hex of length "+_);const H=new Uint8Array(A);for(let z=0,ue=0;z<A;z++,ue+=2){const Ie=y(g.charCodeAt(ue)),De=y(g.charCodeAt(ue+1));if(Ie===void 0||De===void 0){const Vt=g[ue]+g[ue+1];throw new Error('hex string expected, got non-hex character "'+Vt+'" at index '+ue)}H[z]=Ie*16+De}return H}n.hexToBytes=w;const I=async()=>{};n.nextTick=I;async function O(g,_,A){let H=Date.now();for(let z=0;z<g;z++){A(z);const ue=Date.now()-H;ue>=0&&ue<_||(await(0,n.nextTick)(),H+=ue)}}n.asyncLoop=O;function v(g){if(typeof g!="string")throw new Error(`utf8ToBytes expected string, got ${typeof g}`);return new Uint8Array(new TextEncoder().encode(g))}n.utf8ToBytes=v;function J(g){return typeof g=="string"&&(g=v(g)),(0,t.bytes)(g),g}n.toBytes=J;function q(...g){let _=0;for(let H=0;H<g.length;H++){const z=g[H];(0,t.bytes)(z),_+=z.length}const A=new Uint8Array(_);for(let H=0,z=0;H<g.length;H++){const ue=g[H];A.set(ue,z),z+=ue.length}return A}n.concatBytes=q;class Q{clone(){return this._cloneInto()}}n.Hash=Q;const Y={}.toString;function Z(g,_){if(_!==void 0&&Y.call(_)!=="[object Object]")throw new Error("Options should be object or undefined");return Object.assign(g,_)}n.checkOpts=Z;function j(g){const _=H=>g().update(J(H)).digest(),A=g();return _.outputLen=A.outputLen,_.blockLen=A.blockLen,_.create=()=>g(),_}n.wrapConstructor=j;function de(g){const _=(H,z)=>g(z).update(J(H)).digest(),A=g({});return _.outputLen=A.outputLen,_.blockLen=A.blockLen,_.create=H=>g(H),_}n.wrapConstructorWithOpts=de;function be(g){const _=(H,z)=>g(z).update(J(H)).digest(),A=g({});return _.outputLen=A.outputLen,_.blockLen=A.blockLen,_.create=H=>g(H),_}n.wrapXOFConstructorWithOpts=be;function ve(g=32){if(e.crypto&&typeof e.crypto.getRandomValues=="function")return e.crypto.getRandomValues(new Uint8Array(g));throw new Error("crypto.getRandomValues must be defined")}n.randomBytes=ve})(Wn);Object.defineProperty(ae,"__esModule",{value:!0});ae.shake256=ae.shake128=ae.keccak_512=ae.keccak_384=ae.keccak_256=ae.keccak_224=ae.sha3_512=ae.sha3_384=ae.sha3_256=ae.sha3_224=ae.Keccak=ae.keccakP=void 0;const ft=pe,St=B,Qe=Wn,Hn=[],Gn=[],Qn=[],no=BigInt(0),kt=BigInt(1),so=BigInt(2),ao=BigInt(7),oo=BigInt(256),lo=BigInt(113);for(let n=0,e=kt,t=1,r=0;n<24;n++){[t,r]=[r,(2*t+3*r)%5],Hn.push(2*(5*r+t)),Gn.push((n+1)*(n+2)/2%64);let i=no;for(let s=0;s<7;s++)e=(e<<kt^(e>>ao)*lo)%oo,e&so&&(i^=kt<<(kt<<BigInt(s))-kt);Qn.push(i)}const[uo,fo]=(0,St.split)(Qn,!0),Pi=(n,e,t)=>t>32?(0,St.rotlBH)(n,e,t):(0,St.rotlSH)(n,e,t),Di=(n,e,t)=>t>32?(0,St.rotlBL)(n,e,t):(0,St.rotlSL)(n,e,t);function zn(n,e=24){const t=new Uint32Array(10);for(let r=24-e;r<24;r++){for(let a=0;a<10;a++)t[a]=n[a]^n[a+10]^n[a+20]^n[a+30]^n[a+40];for(let a=0;a<10;a+=2){const o=(a+8)%10,f=(a+2)%10,l=t[f],u=t[f+1],d=Pi(l,u,1)^t[o],p=Di(l,u,1)^t[o+1];for(let h=0;h<50;h+=10)n[a+h]^=d,n[a+h+1]^=p}let i=n[2],s=n[3];for(let a=0;a<24;a++){const o=Gn[a],f=Pi(i,s,o),l=Di(i,s,o),u=Hn[a];i=n[u],s=n[u+1],n[u]=f,n[u+1]=l}for(let a=0;a<50;a+=10){for(let o=0;o<10;o++)t[o]=n[a+o];for(let o=0;o<10;o++)n[a+o]^=~t[(o+2)%10]&t[(o+4)%10]}n[0]^=uo[r],n[1]^=fo[r]}t.fill(0)}ae.keccakP=zn;class Ut extends Qe.Hash{constructor(e,t,r,i=!1,s=24){if(super(),this.blockLen=e,this.suffix=t,this.outputLen=r,this.enableXOF=i,this.rounds=s,this.pos=0,this.posOut=0,this.finished=!1,this.destroyed=!1,(0,ft.number)(r),0>=this.blockLen||this.blockLen>=200)throw new Error("Sha3 supports only keccak-f1600 function");this.state=new Uint8Array(200),this.state32=(0,Qe.u32)(this.state)}keccak(){Qe.isLE||(0,Qe.byteSwap32)(this.state32),zn(this.state32,this.rounds),Qe.isLE||(0,Qe.byteSwap32)(this.state32),this.posOut=0,this.pos=0}update(e){(0,ft.exists)(this);const{blockLen:t,state:r}=this;e=(0,Qe.toBytes)(e);const i=e.length;for(let s=0;s<i;){const a=Math.min(t-this.pos,i-s);for(let o=0;o<a;o++)r[this.pos++]^=e[s++];this.pos===t&&this.keccak()}return this}finish(){if(this.finished)return;this.finished=!0;const{state:e,suffix:t,pos:r,blockLen:i}=this;e[r]^=t,t&128&&r===i-1&&this.keccak(),e[i-1]^=128,this.keccak()}writeInto(e){(0,ft.exists)(this,!1),(0,ft.bytes)(e),this.finish();const t=this.state,{blockLen:r}=this;for(let i=0,s=e.length;i<s;){this.posOut>=r&&this.keccak();const a=Math.min(r-this.posOut,s-i);e.set(t.subarray(this.posOut,this.posOut+a),i),this.posOut+=a,i+=a}return e}xofInto(e){if(!this.enableXOF)throw new Error("XOF is not possible for this instance");return this.writeInto(e)}xof(e){return(0,ft.number)(e),this.xofInto(new Uint8Array(e))}digestInto(e){if((0,ft.output)(e,this),this.finished)throw new Error("digest() was already called");return this.writeInto(e),this.destroy(),e}digest(){return this.digestInto(new Uint8Array(this.outputLen))}destroy(){this.destroyed=!0,this.state.fill(0)}_cloneInto(e){const{blockLen:t,suffix:r,outputLen:i,rounds:s,enableXOF:a}=this;return e||(e=new Ut(t,r,i,a,s)),e.state32.set(this.state32),e.pos=this.pos,e.posOut=this.posOut,e.finished=this.finished,e.rounds=s,e.suffix=r,e.outputLen=i,e.enableXOF=a,e.destroyed=this.destroyed,e}}ae.Keccak=Ut;const xe=(n,e,t)=>(0,Qe.wrapConstructor)(()=>new Ut(e,n,t));ae.sha3_224=xe(6,144,224/8);ae.sha3_256=xe(6,136,256/8);ae.sha3_384=xe(6,104,384/8);ae.sha3_512=xe(6,72,512/8);ae.keccak_224=xe(1,144,224/8);ae.keccak_256=xe(1,136,256/8);ae.keccak_384=xe(1,104,384/8);ae.keccak_512=xe(1,72,512/8);const Kn=(n,e,t)=>(0,Qe.wrapXOFConstructorWithOpts)((r={})=>new Ut(e,n,r.dkLen===void 0?t:r.dkLen,!0));ae.shake128=Kn(31,168,128/8);ae.shake256=Kn(31,136,256/8);const{sha3_512:co}=ae,Xn=24,At=32,Vr=(n=4,e=Math.random)=>{let t="";for(;t.length<n;)t=t+Math.floor(e()*36).toString(36);return t};function Zn(n){let e=8n,t=0n;for(const r of n.values()){const i=BigInt(r);t=(t<<e)+i}return t}const Yn=(n="")=>Zn(co(n)).toString(36).slice(1),Ri=Array.from({length:26},(n,e)=>String.fromCharCode(e+97)),ho=n=>Ri[Math.floor(n()*Ri.length)],xn=({globalObj:n=typeof ur<"u"?ur:typeof window<"u"?window:{},random:e=Math.random}={})=>{const t=Object.keys(n).toString(),r=t.length?t+Vr(At,e):Vr(At,e);return Yn(r).substring(0,At)},es=n=>()=>n++,po=476782367,ts=({random:n=Math.random,counter:e=es(Math.floor(n()*po)),length:t=Xn,fingerprint:r=xn({random:n})}={})=>function(){const s=ho(n),a=Date.now().toString(36),o=e().toString(36),f=Vr(t,n),l=`${a+f+o+r}`;return`${s+Yn(l).substring(1,t)}`},yo=ts(),mo=(n,{minLength:e=2,maxLength:t=At}={})=>{const r=n.length,i=/^[0-9a-z]+$/;try{if(typeof n=="string"&&r>=e&&r<=t&&i.test(n))return!0}finally{}return!1};Ye.getConstants=()=>({defaultLength:Xn,bigLength:At});Ye.init=ts;Ye.createId=yo;Ye.bufToBigInt=Zn;Ye.createCounter=es;Ye.createFingerprint=xn;Ye.isCuid=mo;const{createId:go,init:Pl,getConstants:Dl,isCuid:Rl}=Ye;var Mi=go;const Ni=xt(n=>!isNaN(n)&&isFinite(n));class x{static object(...e){return ge(void 0,...e)}static json(...e){let t=e;return t.valueConverter&&!t.valueConverter.fieldTypeInDb&&(t.valueConverter.fieldTypeInDb="json"),ge(void 0,{valueConverter:{fieldTypeInDb:"json"}},...e)}static dateOnly(...e){return ge(()=>Date,{valueConverter:_e.DateOnly},...e)}static date(...e){return ge(()=>Date,...e)}static integer(...e){return ge(()=>Number,{valueConverter:_e.Integer,validate:Ni},...e)}static autoIncrement(...e){return ge(()=>Number,{allowApiUpdate:!1,dbReadOnly:!0,valueConverter:{..._e.Integer,fieldTypeInDb:"autoincrement"}},...e)}static number(...e){return ge(()=>Number,{validate:Ni},...e)}static createdAt(...e){return ge(()=>Date,{allowApiUpdate:!1,saving:(t,r,{isNew:i})=>{i&&(r.value=new Date)}},...e)}static updatedAt(...e){return ge(()=>Date,{allowApiUpdate:!1,saving:(t,r)=>{r.value=new Date}},...e)}static uuid(...e){return ge(()=>String,{allowApiUpdate:!1,defaultValue:()=>jr(),saving:(t,r)=>{r.value||(r.value=jr())}},...e)}static cuid(...e){return ge(()=>String,{allowApiUpdate:!1,defaultValue:()=>Mi(),saving:(t,r)=>{r.value||(r.value=Mi())}},...e)}static literal(e,...t){return x.string({validate:(r,i)=>$e.in(e())(r,i),[Dr]:e},...t)}static enum(e,...t){let r;return ge(()=>e(),{validate:(i,s)=>$e.enum(e())(i,s),[Dr]:()=>er(e())},...t,i=>{if(i[Dr]=()=>er(e()),r===void 0){let s=e();r=er(s).find(o=>typeof o=="string")?_e.String:_e.Integer}i.valueConverter?i.valueConverter.fieldTypeInDb||(i.valueConverter.fieldTypeInDb=r.fieldTypeInDb):i.valueConverter=r})}static string(...e){return ge(()=>String,...e)}static boolean(...e){return ge(()=>Boolean,...e)}}class _r{static toOne(e,t){let r=typeof t=="string"?{field:t}:t||{};return!r.field&&!r.fields&&!r.findOptions?ge(e,{...r,...Ar(e,"reference")}):ge(()=>{},{...r,serverExpression:()=>{},...Ar(e,"toOne")})}static toMany(e,t){return ge(()=>{},{...typeof t=="string"?{field:t}:t,serverExpression:()=>{},...Ar(e,"toMany")})}}function ge(n,...e){return(t,r,i)=>{const s=typeof r=="string"?r:r.name.toString();let a=l=>{let u=cn(e,l);if(u.required&&(u.validate=tr(u.validate,$e.required,!0)),pt(u,"maxLength")){let p=u;p.maxLength&&(p.validate=tr(p.validate,$e.maxLength(p.maxLength)))}if(pt(u,"minLength")){let p=u;p.minLength&&(p.validate=tr(p.validate,$e.minLength(p.minLength)))}!u.valueType&&n&&(u.valueType=n()),u.key||(u.key=s),u.dbName||(u.dbName=u.key);let d=u.valueType;return d||(d=typeof Reflect.getMetadata=="function"?Reflect.getMetadata("design:type",t,s):[],u.valueType=d),u.target||(u.target=t),u};rs(t);let o=T.columnsOfType.get(t.constructor);o||(o=[],T.columnsOfType.set(t.constructor,o));let f=o.find(l=>l.key==s);if(!f)o.push({key:s,settings:a});else{let l=f.settings;f.settings=u=>{let d=l(u),p=a(u);return Object.assign(d,p)}}}}function rs(n){if(!n)throw new Error("Set the 'experimentalDecorators:true' option in your 'tsconfig' or 'jsconfig' (target undefined)")}function wo(n,e,t,r){var i=arguments.length,s=i<3?e:r===null?r=Object.getOwnPropertyDescriptor(e,t):r,a;if(typeof Reflect=="object"&&typeof Reflect.decorate=="function")s=Reflect.decorate(n,e,t,r);else for(var o=n.length-1;o>=0;o--)(a=n[o])&&(s=(i<3?a(s):i>3?a(e,t,s):a(e,t))||s);return i>3&&s&&Object.defineProperty(e,t,s),s}function _o(n,e){if(typeof Reflect=="object"&&typeof Reflect.metadata=="function")return Reflect.metadata(n,e)}class dr extends hn{constructor(){super(...arguments);c(this,"id")}}wo([x.uuid(),_o("design:type",String)],dr.prototype,"id",void 0);/*! *****************************************************************************
7
- Copyright (C) Microsoft. All rights reserved.
8
- Licensed under the Apache License, Version 2.0 (the "License"); you may not use
9
- this file except in compliance with the License. You may obtain a copy of the
10
- License at http://www.apache.org/licenses/LICENSE-2.0
11
-
12
- THIS CODE IS PROVIDED ON AN *AS IS* BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
13
- KIND, EITHER EXPRESS OR IMPLIED, INCLUDING WITHOUT LIMITATION ANY IMPLIED
14
- WARRANTIES OR CONDITIONS OF TITLE, FITNESS FOR A PARTICULAR PURPOSE,
15
- MERCHANTABLITY OR NON-INFRINGEMENT.
16
-
17
- See the Apache Version 2.0 License for specific language governing permissions
18
- and limitations under the License.
19
- ***************************************************************************** */var Li;(function(n){(function(e){var t=typeof ur=="object"?ur:typeof self=="object"?self:typeof this=="object"?this:Function("return this;")(),r=i(n);typeof t.Reflect>"u"?t.Reflect=n:r=i(t.Reflect,r),e(r);function i(s,a){return function(o,f){typeof s[o]!="function"&&Object.defineProperty(s,o,{configurable:!0,writable:!0,value:f}),a&&a(o,f)}}})(function(e){var t=Object.prototype.hasOwnProperty,r=typeof Symbol=="function",i=r&&typeof Symbol.toPrimitive<"u"?Symbol.toPrimitive:"@@toPrimitive",s=r&&typeof Symbol.iterator<"u"?Symbol.iterator:"@@iterator",a=typeof Object.create=="function",o={__proto__:[]}instanceof Array,f=!a&&!o,l={create:a?function(){return Or(Object.create(null))}:o?function(){return Or({__proto__:null})}:function(){return Or({})},has:f?function(m,b){return t.call(m,b)}:function(m,b){return b in m},get:f?function(m,b){return t.call(m,b)?m[b]:void 0}:function(m,b){return m[b]}},u=Object.getPrototypeOf(Function),d=typeof process=="object"&&process.env&&process.env.REFLECT_METADATA_USE_MAP_POLYFILL==="true",p=!d&&typeof Map=="function"&&typeof Map.prototype.entries=="function"?Map:Is(),h=!d&&typeof Set=="function"&&typeof Set.prototype.entries=="function"?Set:Os(),y=!d&&typeof WeakMap=="function"?WeakMap:Cs(),w=new y;function I(m,b,k,E){if(ce(k)){if(!si(m))throw new TypeError;if(!ai(b))throw new TypeError;return be(m,b)}else{if(!si(m))throw new TypeError;if(!we(b))throw new TypeError;if(!we(E)&&!ce(E)&&!ot(E))throw new TypeError;return ot(E)&&(E=void 0),k=Ge(k),ve(m,b,k,E)}}e("decorate",I);function O(m,b){function k(E,P){if(!we(E))throw new TypeError;if(!ce(P)&&!ws(P))throw new TypeError;ue(m,b,E,P)}return k}e("metadata",O);function v(m,b,k,E){if(!we(k))throw new TypeError;return ce(E)||(E=Ge(E)),ue(m,b,k,E)}e("defineMetadata",v);function J(m,b,k){if(!we(b))throw new TypeError;return ce(k)||(k=Ge(k)),_(m,b,k)}e("hasMetadata",J);function q(m,b,k){if(!we(b))throw new TypeError;return ce(k)||(k=Ge(k)),A(m,b,k)}e("hasOwnMetadata",q);function Q(m,b,k){if(!we(b))throw new TypeError;return ce(k)||(k=Ge(k)),H(m,b,k)}e("getMetadata",Q);function Y(m,b,k){if(!we(b))throw new TypeError;return ce(k)||(k=Ge(k)),z(m,b,k)}e("getOwnMetadata",Y);function Z(m,b){if(!we(m))throw new TypeError;return ce(b)||(b=Ge(b)),Ie(m,b)}e("getMetadataKeys",Z);function j(m,b){if(!we(m))throw new TypeError;return ce(b)||(b=Ge(b)),De(m,b)}e("getOwnMetadataKeys",j);function de(m,b,k){if(!we(b))throw new TypeError;ce(k)||(k=Ge(k));var E=g(b,k,!1);if(ce(E)||!E.delete(m))return!1;if(E.size>0)return!0;var P=w.get(b);return P.delete(k),P.size>0||w.delete(b),!0}e("deleteMetadata",de);function be(m,b){for(var k=m.length-1;k>=0;--k){var E=m[k],P=E(b);if(!ce(P)&&!ot(P)){if(!ai(P))throw new TypeError;b=P}}return b}function ve(m,b,k,E){for(var P=m.length-1;P>=0;--P){var Oe=m[P],U=Oe(b,k,E);if(!ce(U)&&!ot(U)){if(!we(U))throw new TypeError;E=U}}return E}function g(m,b,k){var E=w.get(m);if(ce(E)){if(!k)return;E=new p,w.set(m,E)}var P=E.get(b);if(ce(P)){if(!k)return;P=new p,E.set(b,P)}return P}function _(m,b,k){var E=A(m,b,k);if(E)return!0;var P=Ir(b);return ot(P)?!1:_(m,P,k)}function A(m,b,k){var E=g(b,k,!1);return ce(E)?!1:ms(E.has(m))}function H(m,b,k){var E=A(m,b,k);if(E)return z(m,b,k);var P=Ir(b);if(!ot(P))return H(m,P,k)}function z(m,b,k){var E=g(b,k,!1);if(!ce(E))return E.get(m)}function ue(m,b,k,E){var P=g(k,E,!0);P.set(m,b)}function Ie(m,b){var k=De(m,b),E=Ir(m);if(E===null)return k;var P=Ie(E,b);if(P.length<=0)return k;if(k.length<=0)return P;for(var Oe=new h,U=[],G=0,R=k;G<R.length;G++){var K=R[G],X=Oe.has(K);X||(Oe.add(K),U.push(K))}for(var Xe=0,li=P;Xe<li.length;Xe++){var K=li[Xe],X=Oe.has(K);X||(Oe.add(K),U.push(K))}return U}function De(m,b){var k=[],E=g(m,b,!1);if(ce(E))return k;for(var P=E.keys(),Oe=_s(P),U=0;;){var G=vs(Oe);if(!G)return k.length=U,k;var R=bs(G);try{k[U]=R}catch(K){try{ks(Oe)}finally{throw K}}U++}}function Vt(m){if(m===null)return 1;switch(typeof m){case"undefined":return 0;case"boolean":return 2;case"string":return 3;case"symbol":return 4;case"number":return 5;case"object":return m===null?1:6;default:return 6}}function ce(m){return m===void 0}function ot(m){return m===null}function hs(m){return typeof m=="symbol"}function we(m){return typeof m=="object"?m!==null:typeof m=="function"}function ps(m,b){switch(Vt(m)){case 0:return m;case 1:return m;case 2:return m;case 3:return m;case 4:return m;case 5:return m}var k="string",E=oi(m,i);if(E!==void 0){var P=E.call(m,k);if(we(P))throw new TypeError;return P}return ys(m)}function ys(m,b){var k,E;{var P=m.toString;if(Wt(P)){var E=P.call(m);if(!we(E))return E}var k=m.valueOf;if(Wt(k)){var E=k.call(m);if(!we(E))return E}}throw new TypeError}function ms(m){return!!m}function gs(m){return""+m}function Ge(m){var b=ps(m);return hs(b)?b:gs(b)}function si(m){return Array.isArray?Array.isArray(m):m instanceof Object?m instanceof Array:Object.prototype.toString.call(m)==="[object Array]"}function Wt(m){return typeof m=="function"}function ai(m){return typeof m=="function"}function ws(m){switch(Vt(m)){case 3:return!0;case 4:return!0;default:return!1}}function oi(m,b){var k=m[b];if(k!=null){if(!Wt(k))throw new TypeError;return k}}function _s(m){var b=oi(m,s);if(!Wt(b))throw new TypeError;var k=b.call(m);if(!we(k))throw new TypeError;return k}function bs(m){return m.value}function vs(m){var b=m.next();return b.done?!1:b}function ks(m){var b=m.return;b&&b.call(m)}function Ir(m){var b=Object.getPrototypeOf(m);if(typeof m!="function"||m===u||b!==u)return b;var k=m.prototype,E=k&&Object.getPrototypeOf(k);if(E==null||E===Object.prototype)return b;var P=E.constructor;return typeof P!="function"||P===m?b:P}function Is(){var m={},b=[],k=function(){function U(G,R,K){this._index=0,this._keys=G,this._values=R,this._selector=K}return U.prototype["@@iterator"]=function(){return this},U.prototype[s]=function(){return this},U.prototype.next=function(){var G=this._index;if(G>=0&&G<this._keys.length){var R=this._selector(this._keys[G],this._values[G]);return G+1>=this._keys.length?(this._index=-1,this._keys=b,this._values=b):this._index++,{value:R,done:!1}}return{value:void 0,done:!0}},U.prototype.throw=function(G){throw this._index>=0&&(this._index=-1,this._keys=b,this._values=b),G},U.prototype.return=function(G){return this._index>=0&&(this._index=-1,this._keys=b,this._values=b),{value:G,done:!0}},U}();return function(){function U(){this._keys=[],this._values=[],this._cacheKey=m,this._cacheIndex=-2}return Object.defineProperty(U.prototype,"size",{get:function(){return this._keys.length},enumerable:!0,configurable:!0}),U.prototype.has=function(G){return this._find(G,!1)>=0},U.prototype.get=function(G){var R=this._find(G,!1);return R>=0?this._values[R]:void 0},U.prototype.set=function(G,R){var K=this._find(G,!0);return this._values[K]=R,this},U.prototype.delete=function(G){var R=this._find(G,!1);if(R>=0){for(var K=this._keys.length,X=R+1;X<K;X++)this._keys[X-1]=this._keys[X],this._values[X-1]=this._values[X];return this._keys.length--,this._values.length--,G===this._cacheKey&&(this._cacheKey=m,this._cacheIndex=-2),!0}return!1},U.prototype.clear=function(){this._keys.length=0,this._values.length=0,this._cacheKey=m,this._cacheIndex=-2},U.prototype.keys=function(){return new k(this._keys,this._values,E)},U.prototype.values=function(){return new k(this._keys,this._values,P)},U.prototype.entries=function(){return new k(this._keys,this._values,Oe)},U.prototype["@@iterator"]=function(){return this.entries()},U.prototype[s]=function(){return this.entries()},U.prototype._find=function(G,R){return this._cacheKey!==G&&(this._cacheIndex=this._keys.indexOf(this._cacheKey=G)),this._cacheIndex<0&&R&&(this._cacheIndex=this._keys.length,this._keys.push(G),this._values.push(void 0)),this._cacheIndex},U}();function E(U,G){return U}function P(U,G){return G}function Oe(U,G){return[U,G]}}function Os(){return function(){function m(){this._map=new p}return Object.defineProperty(m.prototype,"size",{get:function(){return this._map.size},enumerable:!0,configurable:!0}),m.prototype.has=function(b){return this._map.has(b)},m.prototype.add=function(b){return this._map.set(b,b),this},m.prototype.delete=function(b){return this._map.delete(b)},m.prototype.clear=function(){this._map.clear()},m.prototype.keys=function(){return this._map.keys()},m.prototype.values=function(){return this._map.values()},m.prototype.entries=function(){return this._map.entries()},m.prototype["@@iterator"]=function(){return this.keys()},m.prototype[s]=function(){return this.keys()},m}()}function Cs(){var m=16,b=l.create(),k=E();return function(){function R(){this._key=E()}return R.prototype.has=function(K){var X=P(K,!1);return X!==void 0?l.has(X,this._key):!1},R.prototype.get=function(K){var X=P(K,!1);return X!==void 0?l.get(X,this._key):void 0},R.prototype.set=function(K,X){var Xe=P(K,!0);return Xe[this._key]=X,this},R.prototype.delete=function(K){var X=P(K,!1);return X!==void 0?delete X[this._key]:!1},R.prototype.clear=function(){this._key=E()},R}();function E(){var R;do R="@@WeakMap@@"+G();while(l.has(b,R));return b[R]=!0,R}function P(R,K){if(!t.call(R,k)){if(!K)return;Object.defineProperty(R,k,{value:l.create()})}return R[k]}function Oe(R,K){for(var X=0;X<K;++X)R[X]=Math.random()*255|0;return R}function U(R){return typeof Uint8Array=="function"?typeof crypto<"u"?crypto.getRandomValues(new Uint8Array(R)):typeof msCrypto<"u"?msCrypto.getRandomValues(new Uint8Array(R)):Oe(new Uint8Array(R),R):Oe(new Array(R),R)}function G(){var R=U(m);R[6]=R[6]&79|64,R[8]=R[8]&191|128;for(var K="",X=0;X<m;++X){var Xe=R[X];(X===4||X===6||X===8)&&(K+="-"),Xe<16&&(K+="0"),K+=Xe.toString(16).toLowerCase()}return K}}function Or(m){return m.__=void 0,delete m.__,m}})})(Li||(Li={}));const cr=class cr{constructor(e,t,r){c(this,"actionUrl");c(this,"queue");c(this,"allowed");c(this,"doWork");this.actionUrl=e,this.queue=t,this.allowed=r}async run(e,t,r){t===void 0&&(t=ke.apiClient.url),r||(r=yt(ke.apiClient.httpClient));let i=await r.post(t+"/"+this.actionUrl,e),s=i;if(s&&s.queuedJobId){let a=T.actionInfo.startBusyWithProgress();try{let o;if(await T.actionInfo.runActionWithoutBlockingUI(async()=>{for(;!o||!o.done;)o&&await new Promise(f=>setTimeout(()=>{f(void 0)},200)),o=await r.post(t+"/"+cr.apiUrlForJobStatus,{queuedJobId:i.queuedJobId}),o.progress&&a.progress(o.progress)}),o.error)throw o.error;return a.progress(1),o.result}finally{a.close()}}else return i}__register(e){e(this.actionUrl,this.queue,this.allowed,async(t,r,i)=>{try{var s=await this.execute(t,r,i);i.success(s)}catch(a){a.isForbiddenError?i.forbidden():i.error(a,void 0)}})}};c(cr,"apiUrlForJobStatus","jobStatusInQueue");let $t=cr;class Wr extends Error{constructor(t="Forbidden"){super(t);c(this,"isForbiddenError",!0)}}class bo extends $t{constructor(t,r,i,s){super(t,i.queue??!1,i.allowed);c(this,"types");c(this,"options");c(this,"originalMethod");this.types=r,this.options=i,this.originalMethod=s}async execute(t,r,i){let s={data:{}},a=r.dataProvider;return await ss(r,this.options,async()=>{if(!r.isAllowedForInstance(void 0,this.options.allowed))throw new Wr;t.args=await ns(this.types(),t.args,r,a,i);try{s.data=await this.originalMethod(t.args)}catch(o){throw o}}),s}}function We(n){return(e,t,r)=>{const i=typeof t=="string"?t:t.name.toString(),s=r?r.value:e;let a=s;rs(e);function o(){var u=typeof Reflect.getMetadata=="function"?Reflect.getMetadata("design:paramtypes",e,i):[];return n.paramTypes&&(u=typeof n.paramTypes=="function"?n.paramTypes():n.paramTypes),u}if(e.prototype!==void 0){let u=new bo((n!=null&&n.apiPrefix?n.apiPrefix+"/":"")+i,()=>o(),n,d=>s.apply(void 0,d));return u.doWork=async(d,p,h,y)=>(d=ji(o(),d),n.blockUser===!1?await T.actionInfo.runActionWithoutBlockingUI(async()=>(await u.run({args:d},h,y)).data):(await u.run({args:d},h,y)).data),a=async function(...d){return Ft()?await s.apply(this,d):await u.doWork(d,void 0)},Bi(e,a),a[Jr]=u,r?(r.value=a,r):a}let f=T.classHelpers.get(e.constructor);f||(f=new an,T.classHelpers.set(e.constructor,f));let l={__register(u){let d=new Le;for(const p of f.classes.keys()){let h=f.classes.get(p);h.key||(h.key=d.repo(p).metadata.key),u(h.key+"/"+(n!=null&&n.apiPrefix?n.apiPrefix+"/":"")+i,n?n.queue??!1:!1,n.allowed,async(y,w,I)=>{y.args=y.args.map(v=>is(v)?void 0:v);let O=n.allowed;try{let v=w,J;await ss(v,n,async()=>{if(y.args=await ns(o(),y.args,v,v.dataProvider,I),T.allEntities.includes(p)){let q=v.repo(p),Q;const Y=y.rowInfo;if(Y.isNewRow)Q=q.create(),await q.getEntityRef(Q)._updateEntityBasedOnApi(Y.data);else{let j=await q.find({where:{...q.metadata.idMetadata.getIdFilter(Y.id),$and:[q.metadata.options.apiPrefilter??{}]}});if(j.length!=1)throw new Error("not found or too many matches");Q=j[0],await q.getEntityRef(Q)._updateEntityBasedOnApi(Y.data)}if(!v.isAllowedForInstance(Q,O))throw new Wr;let Z=ne(Q);await Z.__validateEntity();try{J={result:await s.apply(Q,y.args),rowInfo:{data:await Z.toApiJson(),isNewRow:Z.isNew(),wasChanged:Z.wasChanged(),id:Z.getOriginalId()}}}catch(j){throw Z.catchSaveErrors(j)}}else{let q=new p(v,v.dataProvider),Q=Ti(q,v);if(await Q._updateEntityBasedOnApi(y.fields),!v.isAllowedForInstance(q,O))throw new Wr;await Q.__validateEntity();try{J={result:await s.apply(q,y.args),fields:await Q.toApiJson()}}catch(Y){throw Q.catchSaveErrors(Y)}}}),I.success(J)}catch(v){v.isForbiddenError?I.forbidden():I.error(v,void 0)}})}},doWork:async function(u,d,p,h){if(u=ji(o(),u),T.allEntities.includes(e.constructor)){let y=ne(d);await y.__validateEntity();let w=f.classes.get(d.constructor);w.key||(w.key=y.repository.metadata.key+"_methods");try{let I=await new class extends $t{constructor(){super(...arguments);c(this,"execute")}}(w.key+"/"+(n!=null&&n.apiPrefix?n.apiPrefix+"/":"")+i,(n==null?void 0:n.queue)??!1,n.allowed).run({args:u,rowInfo:{data:await y.toApiJson(),isNewRow:y.isNew(),wasChanged:y.wasChanged(),id:y.getOriginalId()}},p,h);return await y._updateEntityBasedOnApi(I.rowInfo.data,!0),I.result}catch(I){throw y.catchSaveErrors(I)}}else{let y=Ti(d,void 0);try{await y.__validateEntity();let w=await new class extends $t{constructor(){super(...arguments);c(this,"execute")}}(f.classes.get(d.constructor).key+"/"+(n!=null&&n.apiPrefix?n.apiPrefix+"/":"")+i,(n==null?void 0:n.queue)??!1,n.allowed).run({args:u,fields:await y.toApiJson()},p,h);return await y._updateEntityBasedOnApi(w.fields),w.result}catch(w){throw y.catchSaveErrors(w)}}}};return a=async function(...u){let d=this;return Ft()?await s.apply(d,u):l.doWork(u,d)},Bi(e.constructor,a),a[Jr]=l,r?(r.value=a,r):a}}const vo={_isUndefined:!0};function Bi(n,e){(n[Ji]||(n[Ji]=[])).push(e),T.actionInfo.allActions.push(e)}function is(n){return n&&n._isUndefined}class qi{constructor(e){c(this,"res");this.res=e}progress(e){this.res.progress(e)}}function ji(n,e){if(n)for(let t=0;t<n.length;t++){const r=n[t];for(const i of[Le,mt])(e[t]instanceof i||r==i)&&(e[t]=void 0);if(e[t]!=null){let i={valueType:r};if(i=Yr(i,new Le),Ae(r,!1)!=null){let a=ne(e[t]);e[t]=a.getId()}i.valueConverter&&(e[t]=i.valueConverter.toJson(e[t]))}}return e.map(t=>t!==void 0?t:vo)}async function ns(n,e,t,r,i){for(let s=0;s<e.length;s++){const a=e[s];is(a)&&(e[s]=void 0)}if(n)for(let s=0;s<n.length;s++)if(e.length<s&&e.push(void 0),n[s]==Le||n[s]==Le)e[s]=t;else if(n[s]==mt&&r)e[s]=r;else if(n[s]==qi)e[s]=new qi(i);else{let a={valueType:n[s]};a=Yr(a,t),a.valueConverter&&(e[s]=a.valueConverter.fromJson(e[s])),Ae(n[s],!1)!=null&&(e[s]===null||e[s]===void 0||(e[s]=await t.repo(n[s]).findId(e[s])))}return e}const Ji=Symbol.for("classBackendMethodsArray");async function ss(n,e,t){if(e.transactional===void 0||e.transactional===!0)return await Da(n,t);await t(n.dataProvider)}function as(n,e){return ke.repo(n,e)}class ko{constructor(e,t){c(this,"id");c(this,"caption");c(this,"icon");c(this,"where");c(this,"class");c(this,"hide");this.id=e.toString(),this.caption=(t==null?void 0:t.caption)??this.id,this.icon=t==null?void 0:t.icon,this.where=t==null?void 0:t.where,this.class=t==null?void 0:t.class,this.hide=t==null?void 0:t.hide,t!=null&&t.icon&&t.icon.caption===void 0&&(t.icon.caption=t==null?void 0:t.caption)}}var Io=Object.defineProperty,Oo=Object.getOwnPropertyDescriptor,Ke=(n,e,t,r)=>{for(var i=r>1?void 0:r?Oo(e,t):e,s=n.length-1,a;s>=0;s--)(a=n[s])&&(i=(r?a(e,t,i):a(i))||i);return r&&i&&Io(e,t,i),i};let Pe=class{constructor(){c(this,"id","");c(this,"entity","");c(this,"entityId","");c(this,"changeDate",new Date);c(this,"userId","");c(this,"changes",[]);c(this,"newRow",!1);c(this,"deleted",!1)}};Ke([x.cuid()],Pe.prototype,"id",2);Ke([x.string()],Pe.prototype,"entity",2);Ke([x.string()],Pe.prototype,"entityId",2);Ke([x.date()],Pe.prototype,"changeDate",2);Ke([x.string()],Pe.prototype,"userId",2);Ke([x.json({dbName:"changesJson"})],Pe.prototype,"changes",2);Ke([x.boolean()],Pe.prototype,"newRow",2);Ke([x.boolean()],Pe.prototype,"deleted",2);Pe=Ke([gn("_ff_change_logs",{caption:"FF Change Logs",allowApiCrud:!1,defaultOrderBy:{changeDate:"desc"}})],Pe);async function Co(n,e,t){var r;if(Ft()){const i=[],s=new os(n,t),a=(t==null?void 0:t.forceNew)||e.isNew,o=(t==null?void 0:t.forceDate)||new Date;for(const f of s.fields.filter(l=>l.valueChanged()||a&&l.value))try{const l=s.excludedValues.includes(f);i.push({key:f.metadata.key,newValue:l?"***":f.value instanceof dr?f.value.id:f.metadata.options.valueConverter.toJson(f.value),oldValue:e.isNew?"---":l?"***":f.originalValue instanceof dr?f.originalValue.id:f.metadata.options.valueConverter.toJson(f.originalValue)})}catch(l){throw console.error(f),l}i.length>0&&await as(Pe).insert({changeDate:o,changes:i,entity:e.metadata.key,entityId:e.metadata.idMetadata.getId(n),userId:((r=ke.user)==null?void 0:r.id)||"",newRow:a})}}async function Eo(n,e,t){var a;const r=[],i=new os(n,t),s=(t==null?void 0:t.forceDate)||new Date;for(const o of i.fields)try{const f=i.excludedValues.includes(o);r.push({key:o.metadata.key,newValue:f?"***":"---",oldValue:f?"***":o.originalValue instanceof dr?o.originalValue.id:o.metadata.options.valueConverter.toJson(o.originalValue)})}catch(f){throw console.error(o),f}await as(Pe).insert({changeDate:s,changes:r,entity:e.metadata.key,entityId:e.metadata.idMetadata.getId(n),userId:((a=ke.user)==null?void 0:a.id)||"",deleted:!0})}class os{constructor(e,t){c(this,"fields");c(this,"excludedFields");c(this,"excludedValues");const r=ne(e);t!=null&&t.excludeColumns?this.excludedFields=t.excludeColumns(r.fields):this.excludedFields=[],t!=null&&t.excludeValues?this.excludedValues=t.excludeValues(r.fields):this.excludedValues=[],this.excludedFields.push(...r.fields.toArray().filter(i=>i.metadata.options.serverExpression)),this.excludedFields.push(...r.fields.toArray().filter(i=>i.metadata.options.sqlExpression)),this.fields=r.fields.toArray().filter(i=>!this.excludedFields.includes(i))}}const It=n=>{if(n)return Array.isArray(n)?n.map(e=>e.id):n.id};function ri(n,e){return gn(n,{...e,allowApiCrud:e.allowApiCrud??It(e.permissionApiCrud),allowApiDelete:e.allowApiDelete??It(e.permissionApiDelete),allowApiInsert:e.allowApiInsert??It(e.permissionApiInsert),allowApiRead:e.allowApiRead??It(e.permissionApiRead),allowApiUpdate:e.allowApiUpdate??It(e.permissionApiUpdate),saved:async(t,r)=>{var i;await((i=e==null?void 0:e.saved)==null?void 0:i.call(e,t,r)),e.changeLog===!1||Ft()&&await Co(t,r,e.changeLog)},deleted:async(t,r)=>{var i;await((i=e==null?void 0:e.deleted)==null?void 0:i.call(e,t,r)),e.changeLog===!1||Ft()&&await Eo(t,r,e.changeLog)}})}const ii={FF_Role_Admin:"FF_Role.Admin"};var ls=Object.defineProperty,Ao=Object.getOwnPropertyDescriptor,To=(n,e,t)=>e in n?ls(n,e,{enumerable:!0,configurable:!0,writable:!0,value:t}):n[e]=t,le=(n,e,t,r)=>{for(var i=r>1?void 0:r?Ao(e,t):e,s=n.length-1,a;s>=0;s--)(a=n[s])&&(i=(r?a(e,t,i):a(i))||i);return r&&i&&ls(e,t,i),i},br=(n,e,t)=>To(n,typeof e!="symbol"?e+"":e,t);const vr={FF_Role_Auth_Admin:"FF_Role_Auth.Admin",FF_Role_Auth_Invite:"FF_Role_Auth.Invite"};let Be=class{constructor(){c(this,"id");c(this,"createdAt");c(this,"updatedAt");c(this,"identifier");c(this,"roles",[]);c(this,"accounts");c(this,"sessions")}};le([x.cuid()],Be.prototype,"id",2);le([x.createdAt()],Be.prototype,"createdAt",2);le([x.updatedAt()],Be.prototype,"updatedAt",2);le([x.string({validate:[$e.unique(),$e.required(),n=>{var e;if(((e=n.identifier)==null?void 0:e.length)<2)throw"Must be at least 2 characters long"}]})],Be.prototype,"identifier",2);le([x.json(()=>[],{inputType:"selectEnum",valueConverter:{toDb:n=>n?n.join(","):[],fromDb:n=>n?n.split(",").map(e=>e.replace("{","").replace("}","")).filter(e=>e!==""):[]}})],Be.prototype,"roles",2);le([_r.toMany(()=>Te,"userId")],Be.prototype,"accounts",2);le([_r.toMany(()=>nt,"userId")],Be.prototype,"sessions",2);Be=le([ri("ff_auth.users",{allowApiCrud:[vr.FF_Role_Auth_Admin,ii.FF_Role_Admin],caption:"FF Auth - Users"})],Be);let Te=class{constructor(){c(this,"id");c(this,"createdAt");c(this,"updatedAt");c(this,"userId");c(this,"user");c(this,"provider",qe.PASSWORD.id);c(this,"providerUserId","");c(this,"hashPassword");c(this,"token");c(this,"expiresAt");c(this,"lastVerifiedAt")}};le([x.cuid()],Te.prototype,"id",2);le([x.createdAt()],Te.prototype,"createdAt",2);le([x.updatedAt()],Te.prototype,"updatedAt",2);le([x.string()],Te.prototype,"userId",2);le([_r.toOne(()=>Be,"userId")],Te.prototype,"user",2);le([x.string()],Te.prototype,"provider",2);le([x.string()],Te.prototype,"providerUserId",2);le([x.string({includeInApi:!1,allowNull:!0})],Te.prototype,"hashPassword",2);le([x.string({includeInApi:!1,allowNull:!0})],Te.prototype,"token",2);le([x.date({includeInApi:!1,allowNull:!0})],Te.prototype,"expiresAt",2);le([x.date({includeInApi:!1,allowNull:!0})],Te.prototype,"lastVerifiedAt",2);Te=le([ri("ff_auth.accounts",{allowApiCrud:[vr.FF_Role_Auth_Admin,ii.FF_Role_Admin],caption:"FF Auth - Accounts",changeLog:{excludeColumns:n=>[n.hashPassword,n.token]}})],Te);let nt=class{constructor(){c(this,"id");c(this,"expiresAt");c(this,"userId");c(this,"user")}};le([x.string()],nt.prototype,"id",2);le([x.date()],nt.prototype,"expiresAt",2);le([x.string()],nt.prototype,"userId",2);le([_r.toOne(()=>Be,"userId")],nt.prototype,"user",2);nt=le([ri("ff_auth.users_sessions",{allowApiCrud:[vr.FF_Role_Auth_Admin,ii.FF_Role_Admin],caption:"FF Auth - Users sessions",changeLog:!1})],nt);let qe=class extends ko{constructor(n,e){super(n,{...e})}};br(qe,"DEMO",new qe("DEMO",{caption:"Demo"}));br(qe,"PASSWORD",new qe("PASSWORD",{caption:"Password"}));br(qe,"OTP",new qe("OTP",{caption:"TOTP"}));br(qe,"OAUTH",new qe("OAUTH",{caption:"OAUTH"}));qe=le([Qa()],qe);var Fo=Object.defineProperty,So=Object.getOwnPropertyDescriptor,He=(n,e,t,r)=>{for(var i=So(e,t),s=n.length-1,a;s>=0;s--)(a=n[s])&&(i=a(e,t,i)||i);return i&&Fo(e,t,i),i},fe,Pt,Dt,Rt,Mt,Nt,Lt,Bt,qt,jt,Jt;const je=(fe=class{static _setAbstraction(e){Ne(this,Pt,e.signOut),Ne(this,Dt,e.signInDemo),Ne(this,Rt,e.invite),Ne(this,Mt,e.signUpPassword),Ne(this,Nt,e.signInPassword),Ne(this,Lt,e.forgotPassword),Ne(this,Bt,e.resetPassword),Ne(this,qt,e.signInOTP),Ne(this,jt,e.verifyOtp),Ne(this,Jt,e.signInOAuthGetUrl)}static async signOut(){var e;return await Re(e=fe,Pt).call(e)}static async signInDemo(e){var t;return await Re(t=fe,Dt).call(t,e)}static async invite(e){var t;return await Re(t=fe,Rt).call(t,e)}static async signUpPassword(e,t){var r;return await Re(r=fe,Mt).call(r,e,t)}static async signInPassword(e,t){var r;return await Re(r=fe,Nt).call(r,e,t)}static async forgotPassword(e){var t;return await Re(t=fe,Lt).call(t,e)}static async resetPassword(e,t){var r;return await Re(r=fe,Bt).call(r,e,t)}static async signInOTP(e){var t;return await Re(t=fe,qt).call(t,e)}static async verifyOtp(e,t){var r;return await Re(r=fe,jt).call(r,e,t)}static async signInOAuthGetUrl(e){var t;return await Re(t=fe,Jt).call(t,e)}},Pt=new WeakMap,Dt=new WeakMap,Rt=new WeakMap,Mt=new WeakMap,Nt=new WeakMap,Lt=new WeakMap,Bt=new WeakMap,qt=new WeakMap,jt=new WeakMap,Jt=new WeakMap,Me(fe,Pt),Me(fe,Dt),Me(fe,Rt),Me(fe,Mt),Me(fe,Nt),Me(fe,Lt),Me(fe,Bt),Me(fe,qt),Me(fe,jt),Me(fe,Jt),fe);He([We({allowed:!0})],je,"signOut");He([We({allowed:!0})],je,"signInDemo");He([We({allowed:vr.FF_Role_Auth_Invite})],je,"invite");He([We({allowed:!0})],je,"signUpPassword");He([We({allowed:!0})],je,"signInPassword");He([We({allowed:!0})],je,"forgotPassword");He([We({allowed:!0})],je,"resetPassword");He([We({allowed:!0})],je,"signInOTP");He([We({allowed:!0})],je,"verifyOtp");He([We({allowed:!0})],je,"signInOAuthGetUrl");let kr=je;function ni(n){n.focus()}function $o(n){var I;let e,t,r,i,s,a,o,f,l,u,d=((I=n[1].ui)==null?void 0:I.strings.send_password_reset_instructions)+"",p,h,y,w;return{c(){var O;e=M("div"),t=M("p"),r=ee(n[2]),i=ee(n[3]),s=V(),a=M("form"),o=M("input"),l=V(),u=M("button"),p=ee(d),F(t,"class","message"),Fe(t,"error",n[2]),Fe(t,"success",n[3]),o.required=!0,F(o,"type","email"),F(o,"placeholder",f=(O=n[1].ui)==null?void 0:O.strings.email_placeholder),u.disabled=h=!n[0]||!n[0].includes("@")||!n[0].includes(".")||n[4],F(a,"class","svelte-skcj83"),F(e,"class","login")},m(O,v){N(O,e,v),C(e,t),C(t,r),C(t,i),C(e,s),C(e,a),C(a,o),Ce(o,n[0]),C(a,l),C(a,u),C(u,p),y||(w=[hr(ni.call(null,o)),Se(o,"input",n[6]),Se(a,"submit",pr(n[5]))],y=!0)},p(O,[v]){var J,q;v&4&&ye(r,O[2]),v&8&&ye(i,O[3]),v&4&&Fe(t,"error",O[2]),v&8&&Fe(t,"success",O[3]),v&2&&f!==(f=(J=O[1].ui)==null?void 0:J.strings.email_placeholder)&&F(o,"placeholder",f),v&1&&o.value!==O[0]&&Ce(o,O[0]),v&2&&d!==(d=((q=O[1].ui)==null?void 0:q.strings.send_password_reset_instructions)+"")&&ye(p,d),v&17&&h!==(h=!O[0]||!O[0].includes("@")||!O[0].includes(".")||O[4])&&(u.disabled=h)},i:se,o:se,d(O){O&&L(e),y=!1,gt(w)}}}function Po(n,e,t){let{firstlyDataAuth:r}=e,{email:i=""}=e,s="",a="",o=!1;async function f(){t(2,s=""),t(3,a=""),t(4,o=!0);try{t(3,a=await kr.forgotPassword(i))}catch(u){u&&t(2,s=u.message??""),t(4,o=!1)}}function l(){i=this.value,t(0,i)}return n.$$set=u=>{"firstlyDataAuth"in u&&t(1,r=u.firstlyDataAuth),"email"in u&&t(0,i=u.email)},[i,r,s,a,o,f,l]}class us extends st{constructor(e){super(),at(this,e,Po,$o,wt,{firstlyDataAuth:1,email:0})}}function Do(n){var de,be,ve;let e,t,r,i,s,a,o=((de=n[2].ui)==null?void 0:de.strings.password)+"",f,l,u,d,p,h=((be=n[2].ui)==null?void 0:be.strings.confirm)+"",y,w,I,O,v,J,q=((ve=n[2].ui)==null?void 0:ve.strings.reset)+"",Q,Y,Z,j;return{c(){var g,_;e=M("div"),t=M("p"),r=ee(n[3]),i=ee(n[4]),s=V(),a=M("form"),f=ee(o),l=V(),u=M("input"),p=V(),y=ee(h),w=V(),I=M("input"),v=V(),J=M("button"),Q=ee(q),F(t,"class","message"),Fe(t,"error",n[3]),F(u,"type","password"),u.required=!0,F(u,"placeholder",d=(g=n[2].ui)==null?void 0:g.strings.password_placeholder),F(I,"type","password"),I.required=!0,F(I,"placeholder",O=(_=n[2].ui)==null?void 0:_.strings.password_placeholder),J.disabled=Y=!n[0]||!n[1]||n[5],F(a,"class","svelte-skcj83"),F(e,"class","login")},m(g,_){N(g,e,_),C(e,t),C(t,r),C(t,i),C(e,s),C(e,a),C(a,f),C(a,l),C(a,u),Ce(u,n[0]),C(a,p),C(a,y),C(a,w),C(a,I),Ce(I,n[1]),C(a,v),C(a,J),C(J,Q),Z||(j=[Se(u,"input",n[7]),Se(I,"input",n[8]),Se(a,"submit",pr(n[6]))],Z=!0)},p(g,[_]){var A,H,z,ue,Ie;_&8&&ye(r,g[3]),_&16&&ye(i,g[4]),_&8&&Fe(t,"error",g[3]),_&4&&o!==(o=((A=g[2].ui)==null?void 0:A.strings.password)+"")&&ye(f,o),_&4&&d!==(d=(H=g[2].ui)==null?void 0:H.strings.password_placeholder)&&F(u,"placeholder",d),_&1&&u.value!==g[0]&&Ce(u,g[0]),_&4&&h!==(h=((z=g[2].ui)==null?void 0:z.strings.confirm)+"")&&ye(y,h),_&4&&O!==(O=(ue=g[2].ui)==null?void 0:ue.strings.password_placeholder)&&F(I,"placeholder",O),_&2&&I.value!==g[1]&&Ce(I,g[1]),_&4&&q!==(q=((Ie=g[2].ui)==null?void 0:Ie.strings.reset)+"")&&ye(Q,q),_&35&&Y!==(Y=!g[0]||!g[1]||g[5])&&(J.disabled=Y)},i:se,o:se,d(g){g&&L(e),Z=!1,gt(j)}}}function Ro(n,e,t){let{firstlyDataAuth:r}=e,{password1:i=""}=e,{password2:s=""}=e,a="",o="",f=!1;async function l(){t(3,a=""),t(4,o=""),t(5,f=!0);const p=new URL(location.href).searchParams.get("token");try{t(4,o=await kr.resetPassword(p??"",i)),window.location.href="/"}catch(h){h&&t(3,a=h.message??""),t(5,f=!1)}}function u(){i=this.value,t(0,i)}function d(){s=this.value,t(1,s)}return n.$$set=p=>{"firstlyDataAuth"in p&&t(2,r=p.firstlyDataAuth),"password1"in p&&t(0,i=p.password1),"password2"in p&&t(1,s=p.password2)},[i,s,r,a,o,f,l,u,d]}class fs extends st{constructor(e){super(),at(this,e,Ro,Do,wt,{firstlyDataAuth:2,password1:0,password2:1})}}function Ui(n){var be,ve,g;let e,t,r,i,s,a,o=((be=n[1].ui)==null?void 0:be.strings.email)+"",f,l,u,d,p,h,y=((ve=n[1].ui)==null?void 0:ve.strings.password)+"",w,I,O,v,J,q,Q=((g=n[1].ui)==null?void 0:g.strings.btn_sign_in)+"",Y,Z,j,de;return{c(){var _,A;e=M("form"),t=M("p"),r=ee(n[3]),i=ee(n[4]),s=V(),a=M("label"),f=ee(o),l=V(),u=M("input"),p=V(),h=M("label"),w=ee(y),I=V(),O=M("input"),J=V(),q=M("button"),Y=ee(Q),F(t,"class","message"),Fe(t,"error",n[3]),u.required=!0,F(u,"type","email"),F(u,"placeholder",d=(_=n[1].ui)==null?void 0:_.strings.email_placeholder),O.required=!0,F(O,"type","password"),F(O,"placeholder",v=(A=n[1].ui)==null?void 0:A.strings.password_placeholder),q.disabled=Z=!n[0]||!n[5]||n[6],F(e,"class","svelte-skcj83")},m(_,A){N(_,e,A),C(e,t),C(t,r),C(t,i),C(e,s),C(e,a),C(a,f),C(a,l),C(a,u),Ce(u,n[0]),C(e,p),C(e,h),C(h,w),C(h,I),C(h,O),Ce(O,n[5]),C(e,J),C(e,q),C(q,Y),j||(de=[Se(u,"input",n[8]),hr(ni.call(null,u)),Se(O,"input",n[9]),Se(e,"submit",pr(n[7]))],j=!0)},p(_,A){var H,z,ue,Ie,De;A&8&&ye(r,_[3]),A&16&&ye(i,_[4]),A&8&&Fe(t,"error",_[3]),A&2&&o!==(o=((H=_[1].ui)==null?void 0:H.strings.email)+"")&&ye(f,o),A&2&&d!==(d=(z=_[1].ui)==null?void 0:z.strings.email_placeholder)&&F(u,"placeholder",d),A&1&&u.value!==_[0]&&Ce(u,_[0]),A&2&&y!==(y=((ue=_[1].ui)==null?void 0:ue.strings.password)+"")&&ye(w,y),A&2&&v!==(v=(Ie=_[1].ui)==null?void 0:Ie.strings.password_placeholder)&&F(O,"placeholder",v),A&32&&O.value!==_[5]&&Ce(O,_[5]),A&2&&Q!==(Q=((De=_[1].ui)==null?void 0:De.strings.btn_sign_in)+"")&&ye(Y,Q),A&97&&Z!==(Z=!_[0]||!_[5]||_[6])&&(q.disabled=Z)},d(_){_&&L(e),j=!1,gt(de)}}}function Mo(n){let e,t=n[2]=="login"&&Ui(n);return{c(){t&&t.c(),e=Hr()},m(r,i){t&&t.m(r,i),N(r,e,i)},p(r,[i]){r[2]=="login"?t?t.p(r,i):(t=Ui(r),t.c(),t.m(e.parentNode,e)):t&&(t.d(1),t=null)},i:se,o:se,d(r){r&&L(e),t&&t.d(r)}}}function No(n,e,t){let{firstlyDataAuth:r}=e,{view:i="login"}=e,{email:s=""}=e,a="",o="",f,l=!1;async function u(){t(3,a=""),t(4,o=""),t(6,l=!0);try{await kr.signInPassword(s,f),window.location.href=new URL(window.location.href).searchParams.get("redirect")??"/"}catch(h){h&&t(3,a=h.message??""),t(6,l=!1)}}function d(){s=this.value,t(0,s)}function p(){f=this.value,t(5,f)}return n.$$set=h=>{"firstlyDataAuth"in h&&t(1,r=h.firstlyDataAuth),"view"in h&&t(2,i=h.view),"email"in h&&t(0,s=h.email)},[s,r,i,a,o,f,l,u,d,p]}class ds extends st{constructor(e){super(),at(this,e,No,Mo,wt,{firstlyDataAuth:1,view:2,email:0})}}function Vi(n){var be,ve,g;let e,t,r,i,s,a,o=((be=n[1].ui)==null?void 0:be.strings.email)+"",f,l,u,d,p,h,y=((ve=n[1].ui)==null?void 0:ve.strings.password)+"",w,I,O,v,J,q,Q=((g=n[1].ui)==null?void 0:g.strings.btn_sign_up)+"",Y,Z,j,de;return{c(){var _,A;e=M("form"),t=M("p"),r=ee(n[3]),i=ee(n[4]),s=V(),a=M("label"),f=ee(o),l=V(),u=M("input"),p=V(),h=M("label"),w=ee(y),I=V(),O=M("input"),J=V(),q=M("button"),Y=ee(Q),F(t,"class","message"),Fe(t,"error",n[3]),u.required=!0,F(u,"type","email"),F(u,"placeholder",d=(_=n[1].ui)==null?void 0:_.strings.email_placeholder),O.required=!0,F(O,"type","password"),F(O,"placeholder",v=(A=n[1].ui)==null?void 0:A.strings.password_placeholder),q.disabled=Z=!n[0]||!n[5]||n[6],F(e,"class","svelte-skcj83")},m(_,A){N(_,e,A),C(e,t),C(t,r),C(t,i),C(e,s),C(e,a),C(a,f),C(a,l),C(a,u),Ce(u,n[0]),C(e,p),C(e,h),C(h,w),C(h,I),C(h,O),Ce(O,n[5]),C(e,J),C(e,q),C(q,Y),j||(de=[Se(u,"input",n[8]),hr(ni.call(null,u)),Se(O,"input",n[9]),Se(e,"submit",pr(n[7]))],j=!0)},p(_,A){var H,z,ue,Ie,De;A&8&&ye(r,_[3]),A&16&&ye(i,_[4]),A&8&&Fe(t,"error",_[3]),A&2&&o!==(o=((H=_[1].ui)==null?void 0:H.strings.email)+"")&&ye(f,o),A&2&&d!==(d=(z=_[1].ui)==null?void 0:z.strings.email_placeholder)&&F(u,"placeholder",d),A&1&&u.value!==_[0]&&Ce(u,_[0]),A&2&&y!==(y=((ue=_[1].ui)==null?void 0:ue.strings.password)+"")&&ye(w,y),A&2&&v!==(v=(Ie=_[1].ui)==null?void 0:Ie.strings.password_placeholder)&&F(O,"placeholder",v),A&32&&O.value!==_[5]&&Ce(O,_[5]),A&2&&Q!==(Q=((De=_[1].ui)==null?void 0:De.strings.btn_sign_up)+"")&&ye(Y,Q),A&97&&Z!==(Z=!_[0]||!_[5]||_[6])&&(q.disabled=Z)},d(_){_&&L(e),j=!1,gt(de)}}}function Lo(n){let e,t=n[2]=="login"&&Vi(n);return{c(){t&&t.c(),e=Hr()},m(r,i){t&&t.m(r,i),N(r,e,i)},p(r,[i]){r[2]=="login"?t?t.p(r,i):(t=Vi(r),t.c(),t.m(e.parentNode,e)):t&&(t.d(1),t=null)},i:se,o:se,d(r){r&&L(e),t&&t.d(r)}}}function Bo(n,e,t){let{firstlyDataAuth:r}=e,{view:i="login"}=e,{email:s=""}=e,a="",o="",f,l=!1;async function u(){t(3,a=""),t(4,o=""),t(6,l=!0);try{t(4,o=await kr.signUpPassword(s,f)),window.location.href="/"}catch(h){h&&t(3,a=h.message??""),t(6,l=!1)}}function d(){s=this.value,t(0,s)}function p(){f=this.value,t(5,f)}return n.$$set=h=>{"firstlyDataAuth"in h&&t(1,r=h.firstlyDataAuth),"view"in h&&t(2,i=h.view),"email"in h&&t(0,s=h.email)},[s,r,i,a,o,f,l,u,d,p]}class cs extends st{constructor(e){super(),at(this,e,Bo,Lo,wt,{firstlyDataAuth:1,view:2,email:0})}}function qo(n){var h,y,w,I,O;let e,t,r,i,s,a,o,f=((h=n[2].ui)==null?void 0:h.strings.app_name)&&Jo(n),l=((y=n[2].ui)==null?void 0:y.paths.sign_up)&&Uo(n),u=((w=n[2].ui)==null?void 0:w.paths.sign_in)&&Go(n),d=((I=n[2].ui)==null?void 0:I.paths.forgot_password)&&Yo(n),p=((O=n[2].ui)==null?void 0:O.paths.reset_password)&&rl(n);return{c(){e=M("div"),t=M("div"),f&&f.c(),r=V(),l&&l.c(),i=V(),u&&u.c(),s=V(),d&&d.c(),a=V(),p&&p.c(),F(t,"class","form svelte-1jjivcr"),F(e,"class","centered-layout svelte-1jjivcr")},m(v,J){N(v,e,J),C(e,t),f&&f.m(t,null),C(t,r),l&&l.m(t,null),C(t,i),u&&u.m(t,null),C(t,s),d&&d.m(t,null),C(t,a),p&&p.m(t,null),o=!0},p(v,J){var q,Q,Y,Z,j;(q=v[2].ui)!=null&&q.strings.app_name&&f.p(v,J),(Q=v[2].ui)!=null&&Q.paths.sign_up&&l.p(v,J),(Y=v[2].ui)!=null&&Y.paths.sign_in&&u.p(v,J),(Z=v[2].ui)!=null&&Z.paths.forgot_password&&d.p(v,J),(j=v[2].ui)!=null&&j.paths.reset_password&&p.p(v,J)},i(v){o||(S(l),S(u),S(d),S(p),o=!0)},o(v){$(l),$(u),$(d),$(p),o=!1},d(v){v&&L(e),f&&f.d(),l&&l.d(),u&&u.d(),d&&d.d(),p&&p.d()}}}function jo(n){var O,v,J,q,Q,Y,Z;let e,t,r,i,s,a,o,f,l,u,d=((O=n[2].ui)==null?void 0:O.strings.app_name)&&al(n),p=((v=n[2].ui)==null?void 0:v.paths.sign_up)&&ol(n),h=((J=n[2].ui)==null?void 0:J.paths.sign_in)&&dl(n),y=((q=n[2].ui)==null?void 0:q.paths.forgot_password)&&gl(n),w=((Q=n[2].ui)==null?void 0:Q.paths.reset_password)&&vl(n),I=((Z=(Y=n[2].ui)==null?void 0:Y.images)==null?void 0:Z.main)&&Cl(n);return{c(){e=M("div"),t=M("div"),r=M("div"),d&&d.c(),i=V(),p&&p.c(),s=V(),h&&h.c(),a=V(),y&&y.c(),o=V(),w&&w.c(),f=V(),l=M("div"),I&&I.c(),F(r,"class","form svelte-1jjivcr"),F(t,"class","form-side svelte-1jjivcr"),F(l,"class","image-side svelte-1jjivcr"),F(e,"class","split-layout svelte-1jjivcr")},m(j,de){N(j,e,de),C(e,t),C(t,r),d&&d.m(r,null),C(r,i),p&&p.m(r,null),C(r,s),h&&h.m(r,null),C(r,a),y&&y.m(r,null),C(r,o),w&&w.m(r,null),C(e,f),C(e,l),I&&I.m(l,null),u=!0},p(j,de){var be,ve,g,_,A,H,z;(be=j[2].ui)!=null&&be.strings.app_name&&d.p(j,de),(ve=j[2].ui)!=null&&ve.paths.sign_up&&p.p(j,de),(g=j[2].ui)!=null&&g.paths.sign_in&&h.p(j,de),(_=j[2].ui)!=null&&_.paths.forgot_password&&y.p(j,de),(A=j[2].ui)!=null&&A.paths.reset_password&&w.p(j,de),(z=(H=j[2].ui)==null?void 0:H.images)!=null&&z.main&&I.p(j,de)},i(j){u||(S(p),S(h),S(y),S(w),u=!0)},o(j){$(p),$(h),$(y),$(w),u=!1},d(j){j&&L(e),d&&d.d(),p&&p.d(),h&&h.d(),y&&y.d(),w&&w.d(),I&&I.d()}}}function Jo(n){let e;return{c(){e=M("h1"),e.textContent=`${n[2].ui.strings.app_name}`,F(e,"class","svelte-1jjivcr")},m(t,r){N(t,e,r)},p:se,d(t){t&&L(e)}}}function Uo(n){var r;let e,t;return e=new Ue({props:{path:(r=n[2].ui)==null?void 0:r.paths.sign_up,$$slots:{default:[Ho]},$$scope:{ctx:n}}}),{c(){te(e.$$.fragment)},m(i,s){re(e,i,s),t=!0},p(i,s){const a={};s&1025&&(a.$$scope={dirty:s,ctx:i}),e.$set(a)},i(i){t||(S(e.$$.fragment,i),t=!0)},o(i){$(e.$$.fragment,i),t=!1},d(i){ie(e,i)}}}function Vo(n){let e,t;return e=new Ve({props:{href:n[2].ui.paths.sign_in,$$slots:{default:[Wo]},$$scope:{ctx:n}}}),{c(){te(e.$$.fragment)},m(r,i){re(e,r,i),t=!0},p(r,i){const s={};i&1024&&(s.$$scope={dirty:i,ctx:r}),e.$set(s)},i(r){t||(S(e.$$.fragment,r),t=!0)},o(r){$(e.$$.fragment,r),t=!1},d(r){ie(e,r)}}}function Wo(n){let e=n[2].ui.strings.back_to_sign_in+"",t;return{c(){t=ee(e)},m(r,i){N(r,t,i)},p:se,d(r){r&&L(t)}}}function Ho(n){let e,t,r,i,s;function a(l){n[7](l)}let o={firstlyDataAuth:n[2]};n[0]!==void 0&&(o.email=n[0]),e=new cs({props:o}),_t.push(()=>bt(e,"email",a));let f=n[2].ui.paths.sign_in&&Vo(n);return{c(){te(e.$$.fragment),r=V(),i=M("div"),f&&f.c(),F(i,"class","form-footer svelte-1jjivcr")},m(l,u){re(e,l,u),N(l,r,u),N(l,i,u),f&&f.m(i,null),s=!0},p(l,u){const d={};!t&&u&1&&(t=!0,d.email=l[0],vt(()=>t=!1)),e.$set(d),l[2].ui.paths.sign_in&&f.p(l,u)},i(l){s||(S(e.$$.fragment,l),S(f),s=!0)},o(l){$(e.$$.fragment,l),$(f),s=!1},d(l){l&&(L(r),L(i)),ie(e,l),f&&f.d()}}}function Go(n){var r;let e,t;return e=new Ue({props:{path:(r=n[2].ui)==null?void 0:r.paths.sign_in,$$slots:{default:[Zo]},$$scope:{ctx:n}}}),{c(){te(e.$$.fragment)},m(i,s){re(e,i,s),t=!0},p(i,s){const a={};s&1025&&(a.$$scope={dirty:s,ctx:i}),e.$set(a)},i(i){t||(S(e.$$.fragment,i),t=!0)},o(i){$(e.$$.fragment,i),t=!1},d(i){ie(e,i)}}}function Qo(n){let e,t;return e=new Ve({props:{href:n[2].ui.paths.forgot_password,$$slots:{default:[zo]},$$scope:{ctx:n}}}),{c(){te(e.$$.fragment)},m(r,i){re(e,r,i),t=!0},p(r,i){const s={};i&1024&&(s.$$scope={dirty:i,ctx:r}),e.$set(s)},i(r){t||(S(e.$$.fragment,r),t=!0)},o(r){$(e.$$.fragment,r),t=!1},d(r){ie(e,r)}}}function zo(n){let e=n[2].ui.strings.forgot_password+"",t;return{c(){t=ee(e)},m(r,i){N(r,t,i)},p:se,d(r){r&&L(t)}}}function Ko(n){let e,t,r,i;return r=new Ve({props:{href:n[2].ui.paths.sign_up,$$slots:{default:[Xo]},$$scope:{ctx:n}}}),{c(){e=M("hr"),t=V(),te(r.$$.fragment)},m(s,a){N(s,e,a),N(s,t,a),re(r,s,a),i=!0},p(s,a){const o={};a&1024&&(o.$$scope={dirty:a,ctx:s}),r.$set(o)},i(s){i||(S(r.$$.fragment,s),i=!0)},o(s){$(r.$$.fragment,s),i=!1},d(s){s&&(L(e),L(t)),ie(r,s)}}}function Xo(n){let e=n[2].ui.strings.btn_sign_up+"",t;return{c(){t=ee(e)},m(r,i){N(r,t,i)},p:se,d(r){r&&L(t)}}}function Zo(n){var d,p;let e,t,r,i,s,a;function o(h){n[8](h)}let f={firstlyDataAuth:n[2]};n[0]!==void 0&&(f.email=n[0]),e=new ds({props:f}),_t.push(()=>bt(e,"email",o));let l=((d=n[2].ui)==null?void 0:d.paths.forgot_password)&&Qo(n),u=((p=n[2].ui)==null?void 0:p.paths.sign_up)&&Ko(n);return{c(){te(e.$$.fragment),r=V(),i=M("div"),l&&l.c(),s=V(),u&&u.c(),F(i,"class","form-footer svelte-1jjivcr")},m(h,y){re(e,h,y),N(h,r,y),N(h,i,y),l&&l.m(i,null),C(i,s),u&&u.m(i,null),a=!0},p(h,y){var I,O;const w={};!t&&y&1&&(t=!0,w.email=h[0],vt(()=>t=!1)),e.$set(w),(I=h[2].ui)!=null&&I.paths.forgot_password&&l.p(h,y),(O=h[2].ui)!=null&&O.paths.sign_up&&u.p(h,y)},i(h){a||(S(e.$$.fragment,h),S(l),S(u),a=!0)},o(h){$(e.$$.fragment,h),$(l),$(u),a=!1},d(h){h&&(L(r),L(i)),ie(e,h),l&&l.d(),u&&u.d()}}}function Yo(n){var r;let e,t;return e=new Ue({props:{path:(r=n[2].ui)==null?void 0:r.paths.forgot_password,$$slots:{default:[tl]},$$scope:{ctx:n}}}),{c(){te(e.$$.fragment)},m(i,s){re(e,i,s),t=!0},p(i,s){const a={};s&1025&&(a.$$scope={dirty:s,ctx:i}),e.$set(a)},i(i){t||(S(e.$$.fragment,i),t=!0)},o(i){$(e.$$.fragment,i),t=!1},d(i){ie(e,i)}}}function xo(n){let e,t;return e=new Ve({props:{href:n[2].ui.paths.sign_in,$$slots:{default:[el]},$$scope:{ctx:n}}}),{c(){te(e.$$.fragment)},m(r,i){re(e,r,i),t=!0},p(r,i){const s={};i&1024&&(s.$$scope={dirty:i,ctx:r}),e.$set(s)},i(r){t||(S(e.$$.fragment,r),t=!0)},o(r){$(e.$$.fragment,r),t=!1},d(r){ie(e,r)}}}function el(n){let e=n[2].ui.strings.back_to_sign_in+"",t;return{c(){t=ee(e)},m(r,i){N(r,t,i)},p:se,d(r){r&&L(t)}}}function tl(n){var l;let e,t,r,i,s;function a(u){n[9](u)}let o={firstlyDataAuth:n[2]};n[0]!==void 0&&(o.email=n[0]),e=new us({props:o}),_t.push(()=>bt(e,"email",a));let f=((l=n[2].ui)==null?void 0:l.paths.sign_in)&&xo(n);return{c(){te(e.$$.fragment),r=V(),i=M("div"),f&&f.c(),F(i,"class","form-footer svelte-1jjivcr")},m(u,d){re(e,u,d),N(u,r,d),N(u,i,d),f&&f.m(i,null),s=!0},p(u,d){var h;const p={};!t&&d&1&&(t=!0,p.email=u[0],vt(()=>t=!1)),e.$set(p),(h=u[2].ui)!=null&&h.paths.sign_in&&f.p(u,d)},i(u){s||(S(e.$$.fragment,u),S(f),s=!0)},o(u){$(e.$$.fragment,u),$(f),s=!1},d(u){u&&(L(r),L(i)),ie(e,u),f&&f.d()}}}function rl(n){var r;let e,t;return e=new Ue({props:{path:(r=n[2].ui)==null?void 0:r.paths.reset_password,$$slots:{default:[sl]},$$scope:{ctx:n}}}),{c(){te(e.$$.fragment)},m(i,s){re(e,i,s),t=!0},p(i,s){const a={};s&1024&&(a.$$scope={dirty:s,ctx:i}),e.$set(a)},i(i){t||(S(e.$$.fragment,i),t=!0)},o(i){$(e.$$.fragment,i),t=!1},d(i){ie(e,i)}}}function il(n){let e,t;return e=new Ve({props:{href:n[2].ui.paths.sign_in,$$slots:{default:[nl]},$$scope:{ctx:n}}}),{c(){te(e.$$.fragment)},m(r,i){re(e,r,i),t=!0},p(r,i){const s={};i&1024&&(s.$$scope={dirty:i,ctx:r}),e.$set(s)},i(r){t||(S(e.$$.fragment,r),t=!0)},o(r){$(e.$$.fragment,r),t=!1},d(r){ie(e,r)}}}function nl(n){let e=n[2].ui.strings.back_to_sign_in+"",t;return{c(){t=ee(e)},m(r,i){N(r,t,i)},p:se,d(r){r&&L(t)}}}function sl(n){var a;let e,t,r,i;e=new fs({props:{firstlyDataAuth:n[2]}});let s=((a=n[2].ui)==null?void 0:a.paths.sign_in)&&il(n);return{c(){te(e.$$.fragment),t=V(),r=M("div"),s&&s.c(),F(r,"class","form-footer svelte-1jjivcr")},m(o,f){re(e,o,f),N(o,t,f),N(o,r,f),s&&s.m(r,null),i=!0},p(o,f){var l;(l=o[2].ui)!=null&&l.paths.sign_in&&s.p(o,f)},i(o){i||(S(e.$$.fragment,o),S(s),i=!0)},o(o){$(e.$$.fragment,o),$(s),i=!1},d(o){o&&(L(t),L(r)),ie(e,o),s&&s.d()}}}function al(n){let e;return{c(){e=M("h1"),e.textContent=`${n[2].ui.strings.app_name}`,F(e,"class","svelte-1jjivcr")},m(t,r){N(t,e,r)},p:se,d(t){t&&L(e)}}}function ol(n){var r;let e,t;return e=new Ue({props:{path:(r=n[2].ui)==null?void 0:r.paths.sign_up,$$slots:{default:[fl]},$$scope:{ctx:n}}}),{c(){te(e.$$.fragment)},m(i,s){re(e,i,s),t=!0},p(i,s){const a={};s&1025&&(a.$$scope={dirty:s,ctx:i}),e.$set(a)},i(i){t||(S(e.$$.fragment,i),t=!0)},o(i){$(e.$$.fragment,i),t=!1},d(i){ie(e,i)}}}function ll(n){let e,t;return e=new Ve({props:{href:n[2].ui.paths.sign_in,$$slots:{default:[ul]},$$scope:{ctx:n}}}),{c(){te(e.$$.fragment)},m(r,i){re(e,r,i),t=!0},p(r,i){const s={};i&1024&&(s.$$scope={dirty:i,ctx:r}),e.$set(s)},i(r){t||(S(e.$$.fragment,r),t=!0)},o(r){$(e.$$.fragment,r),t=!1},d(r){ie(e,r)}}}function ul(n){let e=n[2].ui.strings.back_to_sign_in+"",t;return{c(){t=ee(e)},m(r,i){N(r,t,i)},p:se,d(r){r&&L(t)}}}function fl(n){let e,t,r,i,s;function a(l){n[4](l)}let o={firstlyDataAuth:n[2]};n[0]!==void 0&&(o.email=n[0]),e=new cs({props:o}),_t.push(()=>bt(e,"email",a));let f=n[2].ui.paths.sign_in&&ll(n);return{c(){te(e.$$.fragment),r=V(),i=M("div"),f&&f.c(),F(i,"class","form-footer svelte-1jjivcr")},m(l,u){re(e,l,u),N(l,r,u),N(l,i,u),f&&f.m(i,null),s=!0},p(l,u){const d={};!t&&u&1&&(t=!0,d.email=l[0],vt(()=>t=!1)),e.$set(d),l[2].ui.paths.sign_in&&f.p(l,u)},i(l){s||(S(e.$$.fragment,l),S(f),s=!0)},o(l){$(e.$$.fragment,l),$(f),s=!1},d(l){l&&(L(r),L(i)),ie(e,l),f&&f.d()}}}function dl(n){var r;let e,t;return e=new Ue({props:{path:(r=n[2].ui)==null?void 0:r.paths.sign_in,$$slots:{default:[ml]},$$scope:{ctx:n}}}),{c(){te(e.$$.fragment)},m(i,s){re(e,i,s),t=!0},p(i,s){const a={};s&1025&&(a.$$scope={dirty:s,ctx:i}),e.$set(a)},i(i){t||(S(e.$$.fragment,i),t=!0)},o(i){$(e.$$.fragment,i),t=!1},d(i){ie(e,i)}}}function cl(n){let e,t;return e=new Ve({props:{href:n[2].ui.paths.forgot_password,$$slots:{default:[hl]},$$scope:{ctx:n}}}),{c(){te(e.$$.fragment)},m(r,i){re(e,r,i),t=!0},p(r,i){const s={};i&1024&&(s.$$scope={dirty:i,ctx:r}),e.$set(s)},i(r){t||(S(e.$$.fragment,r),t=!0)},o(r){$(e.$$.fragment,r),t=!1},d(r){ie(e,r)}}}function hl(n){let e=n[2].ui.strings.forgot_password+"",t;return{c(){t=ee(e)},m(r,i){N(r,t,i)},p:se,d(r){r&&L(t)}}}function pl(n){let e,t,r,i;return r=new Ve({props:{href:n[2].ui.paths.sign_up,$$slots:{default:[yl]},$$scope:{ctx:n}}}),{c(){e=M("hr"),t=V(),te(r.$$.fragment)},m(s,a){N(s,e,a),N(s,t,a),re(r,s,a),i=!0},p(s,a){const o={};a&1024&&(o.$$scope={dirty:a,ctx:s}),r.$set(o)},i(s){i||(S(r.$$.fragment,s),i=!0)},o(s){$(r.$$.fragment,s),i=!1},d(s){s&&(L(e),L(t)),ie(r,s)}}}function yl(n){let e=n[2].ui.strings.btn_sign_up+"",t;return{c(){t=ee(e)},m(r,i){N(r,t,i)},p:se,d(r){r&&L(t)}}}function ml(n){var d,p;let e,t,r,i,s,a;function o(h){n[5](h)}let f={firstlyDataAuth:n[2]};n[0]!==void 0&&(f.email=n[0]),e=new ds({props:f}),_t.push(()=>bt(e,"email",o));let l=((d=n[2].ui)==null?void 0:d.paths.forgot_password)&&cl(n),u=((p=n[2].ui)==null?void 0:p.paths.sign_up)&&pl(n);return{c(){te(e.$$.fragment),r=V(),i=M("div"),l&&l.c(),s=V(),u&&u.c(),F(i,"class","form-footer svelte-1jjivcr")},m(h,y){re(e,h,y),N(h,r,y),N(h,i,y),l&&l.m(i,null),C(i,s),u&&u.m(i,null),a=!0},p(h,y){var I,O;const w={};!t&&y&1&&(t=!0,w.email=h[0],vt(()=>t=!1)),e.$set(w),(I=h[2].ui)!=null&&I.paths.forgot_password&&l.p(h,y),(O=h[2].ui)!=null&&O.paths.sign_up&&u.p(h,y)},i(h){a||(S(e.$$.fragment,h),S(l),S(u),a=!0)},o(h){$(e.$$.fragment,h),$(l),$(u),a=!1},d(h){h&&(L(r),L(i)),ie(e,h),l&&l.d(),u&&u.d()}}}function gl(n){var r;let e,t;return e=new Ue({props:{path:(r=n[2].ui)==null?void 0:r.paths.forgot_password,$$slots:{default:[bl]},$$scope:{ctx:n}}}),{c(){te(e.$$.fragment)},m(i,s){re(e,i,s),t=!0},p(i,s){const a={};s&1025&&(a.$$scope={dirty:s,ctx:i}),e.$set(a)},i(i){t||(S(e.$$.fragment,i),t=!0)},o(i){$(e.$$.fragment,i),t=!1},d(i){ie(e,i)}}}function wl(n){let e,t;return e=new Ve({props:{href:n[2].ui.paths.sign_in,$$slots:{default:[_l]},$$scope:{ctx:n}}}),{c(){te(e.$$.fragment)},m(r,i){re(e,r,i),t=!0},p(r,i){const s={};i&1024&&(s.$$scope={dirty:i,ctx:r}),e.$set(s)},i(r){t||(S(e.$$.fragment,r),t=!0)},o(r){$(e.$$.fragment,r),t=!1},d(r){ie(e,r)}}}function _l(n){let e=n[2].ui.strings.back_to_sign_in+"",t;return{c(){t=ee(e)},m(r,i){N(r,t,i)},p:se,d(r){r&&L(t)}}}function bl(n){var l;let e,t,r,i,s;function a(u){n[6](u)}let o={firstlyDataAuth:n[2]};n[0]!==void 0&&(o.email=n[0]),e=new us({props:o}),_t.push(()=>bt(e,"email",a));let f=((l=n[2].ui)==null?void 0:l.paths.sign_in)&&wl(n);return{c(){te(e.$$.fragment),r=V(),i=M("div"),f&&f.c(),F(i,"class","form-footer svelte-1jjivcr")},m(u,d){re(e,u,d),N(u,r,d),N(u,i,d),f&&f.m(i,null),s=!0},p(u,d){var h;const p={};!t&&d&1&&(t=!0,p.email=u[0],vt(()=>t=!1)),e.$set(p),(h=u[2].ui)!=null&&h.paths.sign_in&&f.p(u,d)},i(u){s||(S(e.$$.fragment,u),S(f),s=!0)},o(u){$(e.$$.fragment,u),$(f),s=!1},d(u){u&&(L(r),L(i)),ie(e,u),f&&f.d()}}}function vl(n){var r;let e,t;return e=new Ue({props:{path:(r=n[2].ui)==null?void 0:r.paths.reset_password,$$slots:{default:[Ol]},$$scope:{ctx:n}}}),{c(){te(e.$$.fragment)},m(i,s){re(e,i,s),t=!0},p(i,s){const a={};s&1024&&(a.$$scope={dirty:s,ctx:i}),e.$set(a)},i(i){t||(S(e.$$.fragment,i),t=!0)},o(i){$(e.$$.fragment,i),t=!1},d(i){ie(e,i)}}}function kl(n){let e,t;return e=new Ve({props:{href:n[2].ui.paths.sign_in,$$slots:{default:[Il]},$$scope:{ctx:n}}}),{c(){te(e.$$.fragment)},m(r,i){re(e,r,i),t=!0},p(r,i){const s={};i&1024&&(s.$$scope={dirty:i,ctx:r}),e.$set(s)},i(r){t||(S(e.$$.fragment,r),t=!0)},o(r){$(e.$$.fragment,r),t=!1},d(r){ie(e,r)}}}function Il(n){let e=n[2].ui.strings.back_to_sign_in+"",t;return{c(){t=ee(e)},m(r,i){N(r,t,i)},p:se,d(r){r&&L(t)}}}function Ol(n){var a;let e,t,r,i;e=new fs({props:{firstlyDataAuth:n[2]}});let s=((a=n[2].ui)==null?void 0:a.paths.sign_in)&&kl(n);return{c(){te(e.$$.fragment),t=V(),r=M("div"),s&&s.c(),F(r,"class","form-footer svelte-1jjivcr")},m(o,f){re(e,o,f),N(o,t,f),N(o,r,f),s&&s.m(r,null),i=!0},p(o,f){var l;(l=o[2].ui)!=null&&l.paths.sign_in&&s.p(o,f)},i(o){i||(S(e.$$.fragment,o),S(s),i=!0)},o(o){$(e.$$.fragment,o),$(s),i=!1},d(o){o&&(L(t),L(r)),ie(e,o),s&&s.d()}}}function Cl(n){let e,t;return{c(){e=M("img"),Ns(e.src,t=n[2].ui.images.main)||F(e,"src",t),F(e,"alt","Authentication"),F(e,"class","svelte-1jjivcr")},m(r,i){N(r,e,i)},p:se,d(r){r&&L(e)}}}function El(n){let e,t,r;return{c(){e=M("div"),e.innerHTML="<small>- 404 -</small>",t=V(),r=M("div"),r.innerHTML="<small>Nothing to see here</small>",F(e,"class","fallback svelte-1jjivcr"),F(r,"class","fallback svelte-1jjivcr")},m(i,s){N(i,e,s),N(i,t,s),N(i,r,s)},p:se,d(i){i&&(L(e),L(t),L(r))}}}function Al(n){let e,t,r,i,s;const a=[jo,qo],o=[];function f(l,u){return l[1]?0:1}return e=f(n),t=o[e]=a[e](n),i=new Ue({props:{fallback:!0,$$slots:{default:[El]},$$scope:{ctx:n}}}),{c(){t.c(),r=V(),te(i.$$.fragment)},m(l,u){o[e].m(l,u),N(l,r,u),re(i,l,u),s=!0},p(l,u){let d=e;e=f(l),e===d?o[e].p(l,u):(Hi(),$(o[d],1,1,()=>{o[d]=null}),Gi(),t=o[e],t?t.p(l,u):(t=o[e]=a[e](l),t.c()),S(t,1),t.m(r.parentNode,r));const p={};u&1024&&(p.$$scope={dirty:u,ctx:l}),i.$set(p)},i(l){s||(S(t),S(i.$$.fragment,l),s=!0)},o(l){$(t),$(i.$$.fragment,l),s=!1},d(l){l&&L(r),o[e].d(l),ie(i,l)}}}function Tl(n){let e,t,r;return t=new Ue({props:{$$slots:{default:[Al]},$$scope:{ctx:n}}}),{c(){e=M("div"),te(t.$$.fragment),F(e,"class","wrapper svelte-1jjivcr"),Fe(e,"with-image",n[1])},m(i,s){N(i,e,s),re(t,e,null),r=!0},p(i,[s]){const a={};s&1027&&(a.$$scope={dirty:s,ctx:i}),t.$set(a),(!r||s&2)&&Fe(e,"with-image",i[1])},i(i){r||(S(t.$$.fragment,i),r=!0)},o(i){$(t.$$.fragment,i),r=!1},d(i){i&&L(e),ie(t)}}}function Fl(n,e,t){var h,y;let r,{firstlyData:i}=e,s=i.props,a="";function o(w){a=w,t(0,a)}function f(w){a=w,t(0,a)}function l(w){a=w,t(0,a)}function u(w){a=w,t(0,a)}function d(w){a=w,t(0,a)}function p(w){a=w,t(0,a)}return n.$$set=w=>{"firstlyData"in w&&t(3,i=w.firstlyData)},t(1,r=!!((y=(h=s.ui)==null?void 0:h.images)!=null&&y.main)),[a,r,s,i,o,f,l,u,d,p]}class Ml extends st{constructor(e){super(),at(this,e,Fl,Tl,wt,{firstlyData:3})}}export{Ml as default};
@@ -1 +0,0 @@
1
- form.svelte-skcj83{display:flex;flex-direction:column}h1.svelte-1jjivcr.svelte-1jjivcr{text-align:center;margin-bottom:2rem}.wrapper.svelte-1jjivcr.svelte-1jjivcr{min-height:100vh;display:flex;justify-content:center;align-items:center;margin:0 auto}.centered-layout.svelte-1jjivcr.svelte-1jjivcr{display:flex;justify-content:center;align-items:center;width:100%}.split-layout.svelte-1jjivcr.svelte-1jjivcr{display:flex;width:100%;min-height:100vh}.form-side.svelte-1jjivcr.svelte-1jjivcr{width:50%;display:flex;justify-content:center;align-items:center}.image-side.svelte-1jjivcr.svelte-1jjivcr{width:50%;height:100vh;overflow:hidden}.image-side.svelte-1jjivcr img.svelte-1jjivcr{width:100%;height:100%;object-fit:cover}.form.svelte-1jjivcr.svelte-1jjivcr{max-width:360px;width:100%;padding:1rem;display:flex;flex-direction:column}.form-footer.svelte-1jjivcr.svelte-1jjivcr{margin-top:1rem;display:flex;flex-direction:column;justify-content:center;align-items:center}.fallback.svelte-1jjivcr.svelte-1jjivcr{display:flex;justify-content:center;align-items:center}@media (max-width: 768px){.split-layout.svelte-1jjivcr.svelte-1jjivcr{flex-direction:column}.form-side.svelte-1jjivcr.svelte-1jjivcr{width:100%;order:2}.image-side.svelte-1jjivcr.svelte-1jjivcr{width:100%;height:50vh;order:1}.form.svelte-1jjivcr.svelte-1jjivcr{max-width:100%}}
@@ -1,5 +0,0 @@
1
- export { p as default };
2
- declare class p extends o {
3
- constructor(t: any);
4
- }
5
- import { S as o } from "./index-D-Ztdt2o.js";
@@ -1 +0,0 @@
1
- import{S as o,b as r,a as l,H as i,d as c,n as a,k as f}from"./index-D-Ztdt2o.js";function u(s){let t;return{c(){t=i("Hello from files")},m(e,n){c(e,t,n)},p:a,i:a,o:a,d(e){e&&f(t)}}}class p extends o{constructor(t){super(),r(this,t,null,u,l,{})}}export{p as default};
@@ -1,5 +0,0 @@
1
- export { d as default };
2
- declare class d extends o {
3
- constructor(t: any);
4
- }
5
- import { S as o } from "./index-D-Ztdt2o.js";
@@ -1 +0,0 @@
1
- import{S as o,b as r,a as i,H as l,d as c,n as a,k as f}from"./index-D-Ztdt2o.js";function m(s){let t;return{c(){t=l("Hello from admin")},m(e,n){c(e,t,n)},p:a,i:a,o:a,d(e){e&&f(t)}}}class d extends o{constructor(t){super(),r(this,t,null,m,i,{})}}export{d as default};
@@ -1,54 +0,0 @@
1
- declare function q(e: any): any;
2
- declare function Xe(e: any, t: any): void;
3
- declare function He(e: any): any;
4
- declare function pe(e: any, t: any, n: any, r: any): () => any;
5
- declare function We(e: any, t: any): {};
6
- declare function ze(e: any): {};
7
- declare function ot(e: any, t: any): void;
8
- declare function I(e: any): Text;
9
- declare function ee(): Text;
10
- declare function R(e: any, t: any, n: any): void;
11
- declare function Ze(e: any, t: any, n: any): void;
12
- declare function Je(e: any, t: any): void;
13
- declare function Ye(e: any, t: any): void;
14
- declare function Qe(e: any): (t: any) => any;
15
- declare function be(e: any, t: any): void;
16
- declare function xe(e: any): void;
17
- declare function oe(e: any, t: any, n: any): void;
18
- declare function se(e: any, t: any): void;
19
- declare class Pe {
20
- $destroy(): void;
21
- $on(t: any, n: any): typeof a;
22
- $set(t: any): void;
23
- }
24
- declare const F: any[];
25
- declare function ct(e: any, t: any, n: any): void;
26
- declare function st(e: any): void;
27
- declare function Re(e: any, t: any): boolean;
28
- declare function de(e: any, t: any): any;
29
- declare function Le(e: any, t: any, n: any, r: any, s: any, o: any, c?: null, u?: number[]): void;
30
- declare function Te(e: any, t: any): boolean;
31
- declare function m(e: any, t: any, n: any): void;
32
- declare function te(): Text;
33
- declare function ne(): void;
34
- declare function Be(e: any): undefined;
35
- declare function E(e: any, t: any, n: any, r: any): void;
36
- declare function j(e: any): boolean;
37
- declare function re(): void;
38
- declare function h(e: any): void;
39
- declare function Ue(e: any, t: any, n: any): void;
40
- declare function rt(e: any): any;
41
- declare function a(): void;
42
- declare function nt(e: any): any;
43
- declare function et(e: any): void;
44
- declare function tt(e: any, t: any): any;
45
- declare function x(e: any): void;
46
- declare function Y(e: any, ...t: any[]): any;
47
- declare function b(e: any, t: any): void;
48
- declare function Ge(e: any, t: any, n: any): any;
49
- declare function Ve(e: any, t: any, n: any, r: any): any;
50
- declare function Fe(e: any, t: any, n: any, r: any, s: any, o: any): void;
51
- declare function Ke(e: any): -1 | number[];
52
- declare function Me(e: any, t: any, n: any, r: any): any;
53
- declare function fe(e: any, t: any): any;
54
- export { q as A, Xe as B, He as C, pe as D, We as E, ze as F, ot as G, I as H, ee as I, R as J, Ze as K, Je as L, Ye as M, Qe as N, be as O, xe as P, oe as Q, se as R, Pe as S, F as T, ct as U, st as V, Re as W, de as a, Le as b, Te as c, m as d, te as e, ne as f, Be as g, E as h, j as i, re as j, h as k, Ue as l, rt as m, a as n, nt as o, et as p, tt as q, x as r, Y as s, b as t, Ge as u, Ve as v, Fe as w, Ke as x, Me as y, fe as z };