firstly 0.2.1 → 0.4.0

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 (210) hide show
  1. package/CHANGELOG.md +65 -0
  2. package/esm/SqlDatabase/FF_LogToConsole.js +9 -14
  3. package/esm/carbone/CarboneController.js +2 -1
  4. package/esm/changeLog/index.d.ts +0 -10
  5. package/esm/{internals → core}/BaseEnum.d.ts +1 -1
  6. package/esm/core/FF_Entity.js +5 -0
  7. package/esm/core/helper.d.ts +2 -0
  8. package/esm/core/helper.js +3 -0
  9. package/esm/core/index.d.ts +0 -0
  10. package/esm/core/index.js +5 -0
  11. package/esm/core/tailwind.d.ts +21 -0
  12. package/esm/core/tailwind.js +22 -0
  13. package/esm/core/tryCatch.d.ts +44 -0
  14. package/esm/core/tryCatch.js +34 -0
  15. package/esm/cron/server/index.js +1 -1
  16. package/esm/feedback/FeedbackController.js +3 -2
  17. package/esm/feedback/index.d.ts +7 -2
  18. package/esm/feedback/index.js +1 -2
  19. package/esm/feedback/server/index.d.ts +0 -5
  20. package/esm/feedback/server/index.js +1 -1
  21. package/esm/formats/strings.js +2 -2
  22. package/esm/index.d.ts +16 -0
  23. package/esm/index.js +13 -0
  24. package/esm/svelte/FF_Repo.svelte.d.ts +9 -2
  25. package/esm/svelte/FF_Repo.svelte.js +40 -17
  26. package/esm/svelte/class/SP.svelte.js +14 -2
  27. package/esm/svelte/helpers/debounce.js +1 -1
  28. package/esm/svelte/index.d.ts +2 -24
  29. package/esm/svelte/index.js +2 -22
  30. package/esm/{ui → svelte/ui}/Icon.svelte +1 -1
  31. package/esm/virtual/StateDemoEnum.d.ts +3 -3
  32. package/esm/virtual/StateDemoEnum.js +3 -3
  33. package/esm/virtual/UIEntity.js +1 -2
  34. package/package.json +8 -39
  35. package/esm/auth/AuthController.d.ts +0 -58
  36. package/esm/auth/AuthController.js +0 -114
  37. package/esm/auth/Entities.d.ts +0 -47
  38. package/esm/auth/Entities.js +0 -182
  39. package/esm/auth/README.md +0 -3
  40. package/esm/auth/index.d.ts +0 -5
  41. package/esm/auth/index.js +0 -5
  42. package/esm/auth/server/AuthController.server.d.ts +0 -58
  43. package/esm/auth/server/AuthController.server.js +0 -518
  44. package/esm/auth/server/handleAuth.d.ts +0 -4
  45. package/esm/auth/server/handleAuth.js +0 -142
  46. package/esm/auth/server/handleGuard.d.ts +0 -22
  47. package/esm/auth/server/handleGuard.js +0 -34
  48. package/esm/auth/server/helperDb.d.ts +0 -10
  49. package/esm/auth/server/helperDb.js +0 -56
  50. package/esm/auth/server/helperFirstly.d.ts +0 -1
  51. package/esm/auth/server/helperFirstly.js +0 -9
  52. package/esm/auth/server/helperOslo.d.ts +0 -7
  53. package/esm/auth/server/helperOslo.js +0 -24
  54. package/esm/auth/server/helperRemultServer.d.ts +0 -5
  55. package/esm/auth/server/helperRemultServer.js +0 -44
  56. package/esm/auth/server/helperRole.d.ts +0 -19
  57. package/esm/auth/server/helperRole.js +0 -57
  58. package/esm/auth/server/index.d.ts +0 -8
  59. package/esm/auth/server/index.js +0 -8
  60. package/esm/auth/server/module.d.ts +0 -300
  61. package/esm/auth/server/module.js +0 -230
  62. package/esm/auth/server/providers/github.d.ts +0 -33
  63. package/esm/auth/server/providers/github.js +0 -87
  64. package/esm/auth/server/providers/helperProvider.d.ts +0 -1
  65. package/esm/auth/server/providers/helperProvider.js +0 -25
  66. package/esm/auth/static/assets/Page-BHW08QWz.css +0 -1
  67. package/esm/auth/static/assets/Page-BRNWcY5Z.d.ts +0 -2
  68. package/esm/auth/static/assets/Page-BRNWcY5Z.js +0 -1
  69. package/esm/auth/static/assets/Page-CFcEsGK8.d.ts +0 -2
  70. package/esm/auth/static/assets/Page-CFcEsGK8.js +0 -7
  71. package/esm/auth/static/assets/Page-tLVs5slF.d.ts +0 -2
  72. package/esm/auth/static/assets/Page-tLVs5slF.js +0 -1
  73. package/esm/auth/static/assets/index-D38rqu4x.d.ts +0 -201
  74. package/esm/auth/static/assets/index-D38rqu4x.js +0 -2
  75. package/esm/auth/static/assets/index-DKWpA6v7.css +0 -4
  76. package/esm/auth/static/favicon.svg +0 -79
  77. package/esm/auth/static/index.html +0 -13
  78. package/esm/auth/types.d.ts +0 -73
  79. package/esm/bin/cmd.d.ts +0 -1
  80. package/esm/bin/cmd.js +0 -793
  81. package/esm/feedback/ui/DialogIssue.svelte +0 -149
  82. package/esm/feedback/ui/DialogIssue.svelte.d.ts +0 -22
  83. package/esm/feedback/ui/DialogIssues.svelte +0 -114
  84. package/esm/feedback/ui/DialogIssues.svelte.d.ts +0 -22
  85. package/esm/feedback/ui/DialogMilestones.svelte +0 -43
  86. package/esm/feedback/ui/DialogMilestones.svelte.d.ts +0 -20
  87. package/esm/feedback/ui/Feedback.svelte +0 -16
  88. package/esm/feedback/ui/Feedback.svelte.d.ts +0 -18
  89. package/esm/internals/FF_Entity.d.ts +0 -2
  90. package/esm/internals/FF_Entity.js +0 -21
  91. package/esm/internals/FF_Fields.d.ts +0 -11
  92. package/esm/internals/FF_Fields.js +0 -144
  93. package/esm/internals/cellsBuildor.d.ts +0 -47
  94. package/esm/internals/cellsBuildor.js +0 -140
  95. package/esm/internals/helper.d.ts +0 -49
  96. package/esm/internals/helper.js +0 -162
  97. package/esm/internals/index.d.ts +0 -82
  98. package/esm/internals/index.js +0 -45
  99. package/esm/internals/storeItem.d.ts +0 -28
  100. package/esm/internals/storeItem.js +0 -176
  101. package/esm/internals/storeList.d.ts +0 -34
  102. package/esm/internals/storeList.js +0 -108
  103. package/esm/internals/theme.d.ts +0 -4
  104. package/esm/internals/theme.js +0 -4
  105. package/esm/server/index.d.ts +0 -52
  106. package/esm/server/index.js +0 -87
  107. package/esm/svelte/FF_Cell.svelte +0 -103
  108. package/esm/svelte/FF_Cell.svelte.d.ts +0 -33
  109. package/esm/svelte/FF_Cell_Caption.svelte +0 -20
  110. package/esm/svelte/FF_Cell_Caption.svelte.d.ts +0 -31
  111. package/esm/svelte/FF_Cell_Display.svelte +0 -61
  112. package/esm/svelte/FF_Cell_Display.svelte.d.ts +0 -29
  113. package/esm/svelte/FF_Cell_Edit.svelte +0 -104
  114. package/esm/svelte/FF_Cell_Edit.svelte.d.ts +0 -32
  115. package/esm/svelte/FF_Cell_Error.svelte +0 -20
  116. package/esm/svelte/FF_Cell_Error.svelte.d.ts +0 -31
  117. package/esm/svelte/FF_Cell_Hint.svelte +0 -20
  118. package/esm/svelte/FF_Cell_Hint.svelte.d.ts +0 -31
  119. package/esm/svelte/FF_Config.svelte +0 -29
  120. package/esm/svelte/FF_Config.svelte.d.ts +0 -9
  121. package/esm/svelte/FF_Form.svelte +0 -155
  122. package/esm/svelte/FF_Form.svelte.d.ts +0 -37
  123. package/esm/svelte/FF_Grid.svelte +0 -257
  124. package/esm/svelte/FF_Grid.svelte.d.ts +0 -37
  125. package/esm/svelte/FF_Layout.svelte +0 -62
  126. package/esm/svelte/FF_Layout.svelte.d.ts +0 -31
  127. package/esm/svelte/actions/intersection.d.ts +0 -6
  128. package/esm/svelte/actions/intersection.js +0 -17
  129. package/esm/svelte/customField.d.ts +0 -69
  130. package/esm/svelte/customField.js +0 -4
  131. package/esm/svelte/dialog/DialogManagement.svelte +0 -98
  132. package/esm/svelte/dialog/DialogManagement.svelte.d.ts +0 -18
  133. package/esm/svelte/dialog/DialogPrimitive.svelte +0 -156
  134. package/esm/svelte/dialog/DialogPrimitive.svelte.d.ts +0 -38
  135. package/esm/svelte/dialog/dialog.d.ts +0 -58
  136. package/esm/svelte/dialog/dialog.js +0 -130
  137. package/esm/svelte/ff_Config.svelte.d.ts +0 -91
  138. package/esm/svelte/ff_Config.svelte.js +0 -111
  139. package/esm/svelte/firstly.css +0 -14
  140. package/esm/svelte/helpers.d.ts +0 -30
  141. package/esm/svelte/helpers.js +0 -38
  142. package/esm/svelte/tryCatch.d.ts +0 -12
  143. package/esm/svelte/tryCatch.js +0 -18
  144. package/esm/sveltekit/server/index.d.ts +0 -5
  145. package/esm/sveltekit/server/index.js +0 -24
  146. package/esm/ui/Button.svelte +0 -138
  147. package/esm/ui/Button.svelte.d.ts +0 -13
  148. package/esm/ui/Clipboardable.svelte +0 -25
  149. package/esm/ui/Clipboardable.svelte.d.ts +0 -12
  150. package/esm/ui/Field.svelte +0 -382
  151. package/esm/ui/Field.svelte.d.ts +0 -40
  152. package/esm/ui/FieldGroup.svelte +0 -117
  153. package/esm/ui/FieldGroup.svelte.d.ts +0 -44
  154. package/esm/ui/Grid.svelte +0 -265
  155. package/esm/ui/Grid.svelte.d.ts +0 -57
  156. package/esm/ui/Grid2.svelte +0 -293
  157. package/esm/ui/Grid2.svelte.d.ts +0 -57
  158. package/esm/ui/GridLoading.svelte +0 -58
  159. package/esm/ui/GridLoading.svelte.d.ts +0 -23
  160. package/esm/ui/GridPaginate.svelte +0 -69
  161. package/esm/ui/GridPaginate.svelte.d.ts +0 -23
  162. package/esm/ui/GridPaginate2.svelte +0 -25
  163. package/esm/ui/GridPaginate2.svelte.d.ts +0 -7
  164. package/esm/ui/Loading.svelte +0 -16
  165. package/esm/ui/Loading.svelte.d.ts +0 -31
  166. package/esm/ui/Tooltip.svelte +0 -45
  167. package/esm/ui/Tooltip.svelte.d.ts +0 -32
  168. package/esm/ui/dialog/DialogForm.svelte +0 -76
  169. package/esm/ui/dialog/DialogForm.svelte.d.ts +0 -21
  170. package/esm/ui/dialog/DialogManagement.svelte +0 -96
  171. package/esm/ui/dialog/DialogManagement.svelte.d.ts +0 -26
  172. package/esm/ui/dialog/DialogPrimitive.svelte +0 -90
  173. package/esm/ui/dialog/DialogPrimitive.svelte.d.ts +0 -38
  174. package/esm/ui/dialog/FormEditAction.svelte +0 -62
  175. package/esm/ui/dialog/FormEditAction.svelte.d.ts +0 -31
  176. package/esm/ui/dialog/dialog.d.ts +0 -60
  177. package/esm/ui/dialog/dialog.js +0 -100
  178. package/esm/ui/index.d.ts +0 -6
  179. package/esm/ui/index.js +0 -20
  180. package/esm/ui/internals/FieldContainer.svelte +0 -39
  181. package/esm/ui/internals/FieldContainer.svelte.d.ts +0 -18
  182. package/esm/ui/internals/Input.svelte +0 -143
  183. package/esm/ui/internals/Input.svelte.d.ts +0 -37
  184. package/esm/ui/internals/Textarea.svelte +0 -66
  185. package/esm/ui/internals/Textarea.svelte.d.ts +0 -33
  186. package/esm/ui/internals/select/MultiSelectMelt.svelte +0 -260
  187. package/esm/ui/internals/select/MultiSelectMelt.svelte.d.ts +0 -32
  188. package/esm/ui/internals/select/Select2.svelte +0 -88
  189. package/esm/ui/internals/select/Select2.svelte.d.ts +0 -12
  190. package/esm/ui/internals/select/SelectMelt.svelte +0 -280
  191. package/esm/ui/internals/select/SelectMelt.svelte.d.ts +0 -40
  192. package/esm/ui/internals/select/SelectRadio.svelte +0 -43
  193. package/esm/ui/internals/select/SelectRadio.svelte.d.ts +0 -27
  194. package/esm/ui/link/Link.svelte +0 -33
  195. package/esm/ui/link/Link.svelte.d.ts +0 -33
  196. package/esm/ui/link/LinkPlus.svelte +0 -63
  197. package/esm/ui/link/LinkPlus.svelte.d.ts +0 -9
  198. package/esm/utils/tailwind.d.ts +0 -2
  199. package/esm/utils/tailwind.js +0 -3
  200. package/esm/utils/transition.d.ts +0 -9
  201. package/esm/utils/transition.js +0 -33
  202. package/esm/utils/types.js +0 -1
  203. /package/esm/{internals → core}/BaseEnum.js +0 -0
  204. /package/esm/{internals → core}/common.d.ts +0 -0
  205. /package/esm/{internals → core}/common.js +0 -0
  206. /package/esm/{utils → core}/types.d.ts +0 -0
  207. /package/esm/{auth → core}/types.js +0 -0
  208. /package/esm/{ui → svelte/ui}/Icon.svelte.d.ts +0 -0
  209. /package/esm/{ui → svelte/ui}/LibIcon.d.ts +0 -0
  210. /package/esm/{ui → svelte/ui}/LibIcon.js +0 -0
@@ -1,7 +0,0 @@
1
- var Ni=Object.defineProperty;var yr=s=>{throw TypeError(s)};var $i=(s,e,t)=>e in s?Ni(s,e,{enumerable:!0,configurable:!0,writable:!0,value:t}):s[e]=t;var l=(s,e,t)=>$i(s,typeof e!="symbol"?e+"":e,t),mr=(s,e,t)=>e.has(s)||yr("Cannot "+t);var ce=(s,e,t)=>(mr(s,e,"read from private field"),t?t.call(s):e.get(s)),gr=(s,e,t)=>e.has(s)?yr("Cannot add the same private member more than once"):e instanceof WeakSet?e.add(s):e.set(s,t),wr=(s,e,t,r)=>(mr(s,e,"write to private field"),r?r.call(s,t):e.set(s,t),t);import{t as ie,a as qi,r as Mi,c as xi,b as Ji,g as ut,e as De,u as ir,d as Gr,f as Kt,h as Kr,i as Hr,j as ji,k as Li,l as E,A as Bi,L as Vi,m as Ui,n as Wi,o as zr,p as Qi,q as Gi,N as Ki,s as Hi,v as zi,w as Xi,x as Yi,y as Zi,z as es,B as sr,C as ts,D as Xr,E as At,F as ke,G as rs,H as ne,I as vr,J as is,K as br,M as Ht,O as Yr,P as Be,Q as rt,R as ue,S as W,T as D,U as Ce,V as Zr,W as qe,X as ss,Y as zt,Z as _r,_ as R,$ as Z,a0 as B,a1 as P,a2 as at,a3 as S,a4 as Et,a5 as L,a6 as ns,a7 as Qe,a8 as as,a9 as Ge}from"./index-D38rqu4x.js";function os(){console.warn("https://svelte.dev/e/select_multiple_invalid_value")}function ls(s,e,t=!1,r=!1,i=!1){var n=s,a="";ie(()=>{var o=qi;if(a!==(a=e()??"")&&(o.nodes_start!==null&&(Mi(o.nodes_start,o.nodes_end),o.nodes_start=o.nodes_end=null),a!=="")){var u=a+"";t?u=`<svg>${u}</svg>`:r&&(u=`<math>${u}</math>`);var d=xi(u);if((t||r)&&(d=ut(d)),Ji(ut(d),d.lastChild),t||r)for(;ut(d);)n.before(ut(d));else n.before(d)}})}function ei(s,e,t,r,i){var o;var n=(o=e.$$slots)==null?void 0:o[t],a=!1;n===!0&&(n=e.children,a=!0),n===void 0||n(s,a?()=>r:r)}function Tt(s,e,t){De(()=>{var r=ir(()=>e(s,t==null?void 0:t())||{});if(r!=null&&r.destroy)return()=>r.destroy()})}function us(s,e){var t=void 0,r;Gr(()=>{t!==(t=e())&&(r&&(Kt(r),r=null),t&&(r=Kr(()=>{De(()=>t(s))})))})}function ti(s){var e,t,r="";if(typeof s=="string"||typeof s=="number")r+=s;else if(typeof s=="object")if(Array.isArray(s)){var i=s.length;for(e=0;e<i;e++)s[e]&&(t=ti(s[e]))&&(r&&(r+=" "),r+=t)}else for(t in s)s[t]&&(r&&(r+=" "),r+=t);return r}function ds(){for(var s,e,t=0,r="",i=arguments.length;t<i;t++)(s=arguments[t])&&(e=ti(s))&&(r&&(r+=" "),r+=e);return r}function fs(s){return typeof s=="object"?ds(s):s??""}const Ir=[...`
2
- \r\f \v\uFEFF`];function cs(s,e,t){var r=s==null?"":""+s;if(e&&(r=r?r+" "+e:e),t){for(var i in t)if(t[i])r=r?r+" "+i:i;else if(r.length)for(var n=i.length,a=0;(a=r.indexOf(i,a))>=0;){var o=a+n;(a===0||Ir.includes(r[a-1]))&&(o===r.length||Ir.includes(r[o]))?r=(a===0?"":r.substring(0,a))+r.substring(o+1):a=o}}return r===""?null:r}function Or(s,e=!1){var t=e?" !important;":";",r="";for(var i in s){var n=s[i];n!=null&&n!==""&&(r+=" "+i+": "+n+t)}return r}function Nt(s){return s[0]!=="-"||s[1]!=="-"?s.toLowerCase():s}function hs(s,e){if(e){var t="",r,i;if(Array.isArray(e)?(r=e[0],i=e[1]):r=e,s){s=String(s).replaceAll(/\s*\/\*.*?\*\/\s*/g,"").trim();var n=!1,a=0,o=!1,u=[];r&&u.push(...Object.keys(r).map(Nt)),i&&u.push(...Object.keys(i).map(Nt));var d=0,f=-1;const g=s.length;for(var c=0;c<g;c++){var h=s[c];if(o?h==="/"&&s[c-1]==="*"&&(o=!1):n?n===h&&(n=!1):h==="/"&&s[c+1]==="*"?o=!0:h==='"'||h==="'"?n=h:h==="("?a++:h===")"&&a--,!o&&n===!1&&a===0){if(h===":"&&f===-1)f=c;else if(h===";"||c===g-1){if(f!==-1){var p=Nt(s.substring(d,f).trim());if(!u.includes(p)){h!==";"&&c++;var y=s.substring(d,c).trim();t+=" "+y+";"}}d=c+1,f=-1}}}}return r&&(t+=Or(r)),i&&(t+=Or(i,!0)),t=t.trim(),t===""?null:t}return s==null?null:String(s)}function Ve(s,e,t,r,i,n){var a=s.__className;if(a!==t||a===void 0){var o=cs(t,r,n);o==null?s.removeAttribute("class"):e?s.className=o:s.setAttribute("class",o),s.__className=t}else if(n&&i!==n)for(var u in n){var d=!!n[u];(i==null||d!==!!i[u])&&s.classList.toggle(u,d)}return n}function $t(s,e={},t,r){for(var i in t){var n=t[i];e[i]!==n&&(t[i]==null?s.style.removeProperty(i):s.style.setProperty(i,n,r))}}function ps(s,e,t,r){var i=s.__style;if(i!==e){var n=hs(e,r);n==null?s.removeAttribute("style"):s.style.cssText=n,s.__style=e}else r&&(Array.isArray(r)?($t(s,t==null?void 0:t[0],r[0]),$t(s,t==null?void 0:t[1],r[1],"important")):$t(s,t,r));return r}function Xt(s,e,t){if(s.multiple){if(e==null)return;if(!Hr(e))return os();for(var r of s.options)r.selected=e.includes(kr(r));return}for(r of s.options){var i=kr(r);if(ji(i,e)){r.selected=!0;return}}(!t||e!==void 0)&&(s.selectedIndex=-1)}function ys(s,e){let t=!0;De(()=>{e&&Xt(s,ir(e),t),t=!1;var r=new MutationObserver(()=>{var i=s.__value;Xt(s,i)});return r.observe(s,{childList:!0,subtree:!0,attributes:!0,attributeFilter:["value"]}),()=>{r.disconnect()}})}function kr(s){return"__value"in s?s.__value:s.value}const Ke=Symbol("class"),He=Symbol("style"),ri=Symbol("is custom element"),ii=Symbol("is html");function ms(s,e){e?s.hasAttribute("selected")||s.setAttribute("selected",""):s.removeAttribute("selected")}function ge(s,e,t,r){var i=si(s);i[e]!==(i[e]=t)&&(e==="loading"&&(s[Vi]=t),t==null?s.removeAttribute(e):typeof t!="string"&&ni(s).includes(e)?s[e]=t:s.setAttribute(e,t))}function gs(s,e,t,r,i=!1){var n=si(s),a=n[ri],o=!n[ii],u=e||{},d=s.tagName==="OPTION";for(var f in e)f in t||(t[f]=null);t.class?t.class=fs(t.class):t[Ke]&&(t.class=null),t[He]&&(t.style??(t.style=null));var c=ni(s);for(const w in t){let C=t[w];if(d&&w==="value"&&C==null){s.value=s.__value="",u[w]=C;continue}if(w==="class"){var h=s.namespaceURI==="http://www.w3.org/1999/xhtml";Ve(s,h,C,r,e==null?void 0:e[Ke],t[Ke]),u[w]=C,u[Ke]=t[Ke];continue}if(w==="style"){ps(s,C,e==null?void 0:e[He],t[He]),u[w]=C,u[He]=t[He];continue}var p=u[w];if(C!==p){u[w]=C;var y=w[0]+w[1];if(y!=="$$")if(y==="on"){const k={},_="$$"+w;let b=w.slice(2);var g=zi(b);if(Ui(b)&&(b=b.slice(0,-7),k.capture=!0),!g&&p){if(C!=null)continue;s.removeEventListener(b,u[_],k),u[_]=null}if(C!=null)if(g)s[`__${b}`]=C,zr([b]);else{let F=function(q){u[w].call(this,q)};u[_]=Wi(b,s,F,k)}else g&&(s[`__${b}`]=void 0)}else if(w==="style")ge(s,w,C);else if(w==="autofocus")Qi(s,!!C);else if(!a&&(w==="__value"||w==="value"&&C!=null))s.value=s.__value=C;else if(w==="selected"&&d)ms(s,C);else{var m=w;o||(m=Gi(m));var O=m==="defaultValue"||m==="defaultChecked";if(C==null&&!a&&!O)if(n[w]=null,m==="value"||m==="checked"){let k=s;const _=e===void 0;if(m==="value"){let b=k.defaultValue;k.removeAttribute(m),k.defaultValue=b,k.value=k.__value=_?b:null}else{let b=k.defaultChecked;k.removeAttribute(m),k.defaultChecked=b,k.checked=_?b:!1}}else s.removeAttribute(w);else O||c.includes(m)&&(a||typeof C!="string")?s[m]=C:typeof C!="function"&&ge(s,m,C)}}}return u}function ws(s,e,t=[],r,i=!1,n=Li){const a=t.map(n);var o=void 0,u={},d=s.nodeName==="SELECT",f=!1;Gr(()=>{var c=e(...a.map(E));gs(s,o,c,r,i),f&&d&&"value"in c&&Xt(s,c.value,!1);for(let p of Object.getOwnPropertySymbols(u))c[p]||Kt(u[p]);for(let p of Object.getOwnPropertySymbols(c)){var h=c[p];p.description===Bi&&(!o||h!==o[p])&&(u[p]&&Kt(u[p]),u[p]=Kr(()=>us(s,()=>h)))}o=c}),d&&ys(s,()=>o.value),f=!0}function si(s){return s.__attributes??(s.__attributes={[ri]:s.nodeName.includes("-"),[ii]:s.namespaceURI===Ki})}var Cr=new Map;function ni(s){var e=Cr.get(s.nodeName);if(e)return e;Cr.set(s.nodeName,e=[]);for(var t,r=s,i=Element.prototype;i!==r;){t=Xi(r);for(var n in t)t[n].set&&e.push(n);r=Hi(r)}return e}function Se(s,e,t=e){var r=Yi();Zi(s,"input",i=>{var n=i?s.defaultValue:s.value;if(n=qt(s)?Mt(n):n,t(n),r&&n!==(n=e())){var a=s.selectionStart,o=s.selectionEnd;s.value=n??"",o!==null&&(s.selectionStart=a,s.selectionEnd=Math.min(o,s.value.length))}}),ir(e)==null&&s.value&&t(qt(s)?Mt(s.value):s.value),es(()=>{var i=e();qt(s)&&i===Mt(s.value)||s.type==="date"&&!i&&!s.value||i!==s.value&&(s.value=i??"")})}function qt(s){var e=s.type;return e==="number"||e==="range"}function Mt(s){return s===""?null:+s}function St(s){return function(...e){var t=e[0];return t.preventDefault(),s==null?void 0:s.apply(this,e)}}function vs(s,e){var n;var t=(n=s.$$events)==null?void 0:n[e.type],r=Hr(t)?t.slice():t==null?[]:[t];for(var i of r)i.call(this,e)}const bs=s=>{const{subscribe:e,update:t}=sr(s);return{subscribe:e,set:(r={})=>{t(i=>Object.assign(i,r))}}},Pt=bs({mode:"window",basePath:null}),xt=(s=ts(Pt).mode)=>{let e="popstate";s==="window"&&(e="popstate"),s==="hash"&&(e="hashchange"),window.dispatchEvent(new Event(e))},Fr={go:(s=0)=>{history.go(s),xt()},push:(s,e=null)=>{history.pushState(e,"",s),xt()},replace:(s,e=null)=>{history.replaceState(e,"",s),xt()}},_s=s=>{const e=s.match(/^(\/[^?#]*)?/),t=s.match(/\?([^#]*)?/),r=s.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]}`:""}},Ar=()=>{const{pathname:s,search:e,hash:t}=document.location;return{path:s,query:e,hash:t}},Er=()=>{let s=document.location.hash.substring(1);return s[0]!=="/"&&(s="/"+s),_s(s)},Is=Xr(Ar(),s=>{const e=()=>s(Ar());return window.addEventListener("popstate",e),()=>window.removeEventListener("popstate",e)}),Os=Xr(Er(),s=>{const e=()=>s(Er());return window.addEventListener("hashchange",e),()=>window.removeEventListener("hashchange",e)}),nr=At([Pt,Is,Os],([s,e,t],r)=>{s.mode==="window"&&r(e),s.mode==="hash"&&r(t)}),ks=At(nr,s=>s.path);At(nr,s=>s.query);At(nr,s=>s.hash);const Cs=()=>{let s=0;return()=>s++},ct=s=>s.split(/(?=\/)/),Fs=(s,e)=>e===null?s:s.startsWith(e)?s.slice(e.length):s,As=(s,e,t,r,i)=>{const n=(d,f,c)=>{const h=ct(f).filter(p=>p!=="/").length;return(c??0)+(d?1:h)},a=(d,f)=>{const c={invalidPath:`<Route path="${d==null?void 0:d.path}" /> has invalid path. Path must start with '/'`,fallbackOutsideRoot:"<Route fallback /> cannot be outside root <Route />",pathOutsideRoot:`<Route path="${d==null?void 0:d.path}" /> cannot be outside root <Route />`,fallbackInsideFallback:"<Route fallback /> cannot be inside <Route fallback>",pathInsideFallback:`<Route path="${d==null?void 0:d.path}" /> cannot be inside <Route fallback>`};if(d.path[0]!=="/")throw new Error(c.invalidPath);if(d.root&&d.fallback)throw new Error(c.fallbackOutsideRoot);if(d.root&&d.path!=="/")throw new Error(c.pathOutsideRoot);if(f!=null&&f.fallback&&d.fallback)throw new Error(c.fallbackInsideFallback);if(f!=null&&f.fallback&&!d.fallback)throw new Error(c.pathInsideFallback)},o=n(t,r,i==null?void 0:i.depth),u={id:s,root:e,fallback:t,path:r,depth:o};return a(u,i),u},Es=()=>{const{subscribe:s,update:e}=sr([]);return{subscribe:s,update:t=>e(r=>[...r.filter(i=>t.id!==i.id),t]),remove:t=>e(r=>r.filter(i=>t.id!==i.id))}},Ts=(s,e,t)=>{const r=(d,f,c,h)=>{let p=ct(d).filter(m=>m!=="/"),y=ct(c).filter(m=>m!=="/"),g="";if(c==="/")return f||p.length===h;for(let m=h-y.length;m<h;m++)g=g+p[m];return c===g},i=(d,f,c)=>{var y,g,m,O;let h=ct(d).filter(w=>w!=="/"),p=!1;for(let w=0;w<(c==null?void 0:c.length)&&!p;w++)(y=c[w])!=null&&y.fallback||(p=r(d,((g=c[w])==null?void 0:g.root)??!1,((m=c[w])==null?void 0:m.path)??"",((O=c[w])==null?void 0:O.depth)??0));return h.length>=f&&!p},{root:n,fallback:a,path:o,depth:u}=e;return a?i(s,u,t):r(s,n,o,u)},Ss=Cs(),Jt={},Tr={};function Ne(s,e){ke(e,!1);const[t,r]=Zr(),i=()=>qe(p,"$route",t),n=()=>qe(y,"$contextRoute",t),a=()=>qe(ks,"$globalPath",t),o=()=>qe(Pt,"$options",t),u=()=>qe(m,"$contextChildRoutes",t),d=Ss(),f=!rs(Jt);let c=ne(e,"fallback",9,!1),h=ne(e,"path",9,"/");const p=sr(),y=vr(Jt),g=Es(),m=vr(Tr);is(()=>m==null?void 0:m.remove(i())),br(Jt,p),br(Tr,g),Ht(()=>(zt(c()),zt(h()),n()),()=>{ss(p,As(d,f,c(),h(),n()))}),Ht(()=>i(),()=>{m==null||m.update(i())}),Yr(),Be(!0);var O=rt(),w=ue(O);{var C=k=>{var _=rt(),b=ue(_);ei(b,e,"default",{}),D(k,_)};W(w,k=>{Ts(Fs(a(),o().basePath),i(),u())&&k(C)})}D(s,O),Ce(),r()}const Sr=s=>{var o;const e=(o=s.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",n=s.metaKey||s.ctrlKey||s.altKey||s.shiftKey,a=new URL(t).origin!==document.location.origin;if(r||i||n||a)return!0;t===document.location.href?Fr.replace(t):Fr.push(t),s.preventDefault()},jt=s=>(s.addEventListener("click",Sr),{destroy:()=>{s.removeEventListener("click",Sr)}}),Ps=(s,e,t)=>(s==="hash"?"#":"")+(e??"")+t;var Ds=B("<a><!></a>");function ze(s,e){const t=_r(e,["children","$$slots","$$events","$$legacy"]),r=_r(t,["href"]);ke(e,!1);const[i,n]=Zr(),a=()=>qe(Pt,"$options",i),o=Z(void 0,!0);let u=ne(e,"href",9);Ht(()=>(a(),zt(u())),()=>{R(o,Ps(a().mode,a().basePath,u()))}),Yr(),Be(!0);var d=Ds();ws(d,()=>({href:E(o),...r}));var f=P(d);ei(f,e,"default",{}),Tt(d,c=>jt==null?void 0:jt(c)),De(()=>at("click",d,function(c){vs.call(this,e,c)})),D(s,d),Ce(),n()}class Ae{constructor(...e){l(this,"fields");l(this,"options",{});l(this,"target");l(this,"readonly",!0);l(this,"allowNull",!1);l(this,"dbReadOnly",!1);l(this,"isServerExpression",!1);l(this,"key","");l(this,"label","");l(this,"caption","");l(this,"inputType","");l(this,"dbName","");l(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((n,a)=>{t[n.key]=n.valueConverter.fromJson(i[a])}),t}}function $(s,e=!0){var r;if(s===void 0)throw new Error("entity is undefined");let t=s[Fe];if(!t&&e)throw new Error("item "+(((r=s.constructor)==null?void 0:r.name)||s)+" was not initialized using a context");return t}const Fe=Symbol.for("entityMember"),ai=Symbol.for("entityInfo"),oi=Symbol.for("entityInfo_key");function ee(s,e=!0){if(s===void 0){if(e)throw new Error("Undefined is not an entity :)");return}let t=s[ai];if(!t&&e)throw new Error(s.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 Rs(s){return s[oi]}function Lt(s,e){return{[li]:{toType:s,type:e}}}const li=Symbol.for("relationInfo");function Ns(s){return s==null?void 0:s[li]}const Yt=Symbol.for("fieldRelationInfo");function M(s){if(s)return s[Yt]}function $s(s,e,t){for(const r of s.fields.toArray()){const i=Ns(r.options);if(i&&!r[Yt]){const n=i.toType(),a=e.repo(n,t),o=r.options;r[Yt]={type:i.type,toEntity:n,options:o,toRepo:a,getFields:()=>{let u=o.field,d={fields:o.fields,compoundIdField:void 0};function f(p){return Error(`Error for relation: "${s.metadata.key}.${r.key}", `+p)}let c=()=>u||d.fields;if(i.type==="toMany"&&!c()){for(const p of a.fields.toArray())if(!c()){const y=M(p),g=p.options;if(y&&y.toEntity===s.metadata.entityType){if(y.type==="reference")u=p.key;else if(y.type==="toOne"){if(g.field)u=g.field;else if(g.fields){let m={};for(const O in g.fields)if(Object.prototype.hasOwnProperty.call(g.fields,O)){const w=g.fields[O];m[w]=O}d.fields=m}}}}if(!c())throw f(`No matching field found on target "${a.metadata.key}". Please specify field/fields`)}function h(p,y){const g=y.fields.find(p);if(!g)throw f(`Field "${p}" was not found in "${y.key}".`);return g}i.type==="reference"&&(u=r.key),u&&(i.type==="toOne"||i.type==="reference"?a.metadata.idMetadata.field instanceof Ae?d.compoundIdField=u:d.fields={[a.metadata.idMetadata.field.key]:u}:s.metadata.idMetadata.field instanceof Ae?d.compoundIdField=u:d.fields={[u]:s.metadata.idMetadata.field.key});for(const p in d.fields)Object.prototype.hasOwnProperty.call(d.fields,p)&&(h(p,a.metadata),h(d.fields[p],s.metadata));return d}}}}}class I{constructor(e){l(this,"apply");this.apply=e}static throwErrorIfFilterIsEmpty(e,t){if(I.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(!I.isFilterEmpty(t))return!1}if(e.$or){for(const t of e.$or)if(I.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 _t;return await I.fromEntityFilter(e,t).__applyToConsumer(r),r.preciseValues}async getPreciseValues(){const e=new _t;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{[Ee+r.key]:i}},{rawFilterInfo:r})}static entityFilterToJson(e,t){return I.fromEntityFilter(e,t).toJson()}static entityFilterFromJson(e,t){return ht(e,{get:r=>t[r]})}static fromEntityFilter(e,t){let r=[];for(const i in t)if(Object.prototype.hasOwnProperty.call(t,i)){let n=t[i];if(i=="$or")r.push(new xs(...n.map(a=>I.fromEntityFilter(e,a))));else if(i=="$not")r.push(new Js(I.fromEntityFilter(e,n)));else if(i=="$and")r.push(new Pr(...n.map(a=>I.fromEntityFilter(e,a))));else if(i.startsWith(Ee))r.push(new I(a=>{a.custom(i.substring(Ee.length),n)}));else if(i==ui)r.push(new I(a=>a.databaseCustom(n)));else{const a=e.fields[i],o=M(a),u=a.options;let d=(o==null?void 0:o.type)==="toOne"?u.fields?new Ms(a,e.fields,u):new qs(e.fields[u.field]):new wt(a),f=!1;if(n!==void 0&&n!=null){n.$id!==void 0&&(n=n.$id);for(const c in n)if(Object.prototype.hasOwnProperty.call(n,c)){const h=n[c];switch(c){case"$gte":case">=":r.push(d.isGreaterOrEqualTo(h)),f=!0;break;case"$gt":case">":r.push(d.isGreaterThan(h)),f=!0;break;case"$lte":case"<=":r.push(d.isLessOrEqualTo(h)),f=!0;break;case"$lt":case"<":r.push(d.isLessThan(h)),f=!0;break;case"$ne":case"$not":case"!=":case"$nin":f=!0,Array.isArray(h)?r.push(d.isNotIn(h)):r.push(d.isDifferentFrom(h));break;case"$in":f=!0,r.push(d.isIn(h));break;case"$contains":f=!0,r.push(d.contains(h));break;case"$startsWith":f=!0,r.push(d.startsWith(h));break;case"$endsWith":f=!0,r.push(d.endsWith(h));break;case"$notContains":f=!0,r.push(d.notContains(h));break}}Array.isArray(n)&&(f=!0,r.push(d.isIn(n)))}!f&&n!==void 0&&r.push(d.isEqualTo(n))}}return new Pr(...r)}__applyToConsumer(e){this.apply(e)}static async resolve(e){return typeof e=="function"?await e():e}toJson(){let e=new vt;return this.__applyToConsumer(e),e.result}static async translateCustomWhere(e,t,r){let i=new bt(async(n,a)=>{let o=[];for(const u in t.entityType){const d=t.entityType[u];d&&d.rawFilterInfo&&d.rawFilterInfo.rawFilterTranslator&&d.rawFilterInfo.key==n&&o.push(await I.fromEntityFilter(t,await d.rawFilterInfo.rawFilterTranslator(a,r)))}return o});return e.__applyToConsumer(i),await i.resolve(),e=new I(n=>i.applyTo(n)),e}}class wt{constructor(e){l(this,"metadata");this.metadata=e}processVal(e){if(ee(this.metadata.valueType,!1)){if(e==null){if(e===null&&!this.metadata.allowNull){const r=M(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:$(e).getId()}return e}contains(e){return new I(t=>t.containsCaseInsensitive(this.metadata,e))}notContains(e){return new I(t=>t.notContainsCaseInsensitive(this.metadata,e))}startsWith(e){return new I(t=>t.startsWithCaseInsensitive(this.metadata,e))}endsWith(e){return new I(t=>t.endsWithCaseInsensitive(this.metadata,e))}isLessThan(e){return e=this.processVal(e),new I(t=>t.isLessThan(this.metadata,e))}isGreaterOrEqualTo(e){return e=this.processVal(e),new I(t=>t.isGreaterOrEqualTo(this.metadata,e))}isNotIn(e){return new I(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 I(t=>t.isNotNull(this.metadata)):new I(t=>t.isDifferentFrom(this.metadata,e))}isLessOrEqualTo(e){return e=this.processVal(e),new I(t=>t.isLessOrEqualTo(this.metadata,e))}isGreaterThan(e){return e=this.processVal(e),new I(t=>t.isGreaterThan(this.metadata,e))}isEqualTo(e){return e=this.processVal(e),e==null&&this.metadata.allowNull?new I(t=>t.isNull(this.metadata)):new I(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 I(t=>t.isEqualTo(this.metadata,e[0])):new I(t=>t.isIn(this.metadata,e))}}class qs extends wt{processVal(e){return e?typeof e=="string"||typeof e=="number"?e:$(e).getId():null}}class Ms{constructor(e,t,r){l(this,"metadata");l(this,"fields");l(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 I(t=>{e.forEach(r=>this.isDifferentFrom(r).__applyToConsumer(t))})}isDifferentFrom(e){return new I(t=>{const r=[];for(const i in this.relationOptions.fields)if(Object.prototype.hasOwnProperty.call(this.relationOptions.fields,i)){const n=this.relationOptions.fields[i];r.push(new I(a=>new wt(this.fields.find(n)).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 I(t=>{for(const r in this.relationOptions.fields)if(Object.prototype.hasOwnProperty.call(this.relationOptions.fields,r)){const i=this.relationOptions.fields[r];new wt(this.fields.find(i)).isEqualTo(e[r]).__applyToConsumer(t)}})}isIn(e){return new I(t=>{t.or(e.map(r=>this.isEqualTo(r)))})}}class Pr extends I{constructor(...t){super(r=>{for(const i of this.filters)i&&i.__applyToConsumer(r)});l(this,"filters");this.filters=t}add(t){this.filters.push(t)}}class xs extends I{constructor(...t){super(r=>{let i=this.filters.filter(n=>n!==void 0);i.length>1?r.or(i):i.length==1&&i[0].__applyToConsumer(r)});l(this,"filters");this.filters=t}}class Js extends I{constructor(t){super(r=>{r.not(t)});l(this,"filter");this.filter=t}}const Ee="$custom$",ui="$db$",Zt="$an array";class vt{constructor(){l(this,"result",{});l(this,"hasUndefined",!1)}databaseCustom(e){throw new Error("database custom is not allowed with api calls.")}custom(e,t){Array.isArray(t)&&(t={[Zt]:t}),this.add(Ee+e,t)}add(e,t){t===void 0&&(this.hasUndefined=!0);let r=this.result;if(r[e]===void 0){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 vt;return t.__applyToConsumer(r),r.result}))}not(e){let t=new vt;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 ht(s,e){let t={};function r(o){t.$and||(t.$and=[]),t.$and.push(o)}function i(o,u){t[o]===void 0?t[o]=u:r({[o]:u})}[...s.fields].forEach(o=>{function u(f,c,h=!1,p=!1){let y=e.get(o.key+f);if(y!==void 0){let g=m=>{let O=m;if(h){let C;typeof m=="string"?C=JSON.parse(m):C=m,O=C.map(k=>p?k:o.valueConverter.fromJson(k))}else O=p?O:o.valueConverter.fromJson(O);let w=c(O);w!==void 0&&i(o.key,w)};if(!h&&y instanceof Array)y.forEach(m=>{g(m)});else{h&&typeof y=="string"&&(y=JSON.parse(y));const m=a(y);for(const O of m)g(O)}}}u("",f=>f),u(".gt",f=>({$gt:f})),u(".gte",f=>({$gte:f})),u(".lt",f=>({$lt:f})),u(".lte",f=>({$lte:f})),u(".ne",f=>({$ne:f})),u(".in",f=>f,!0);var d=e.get(o.key+".null");if(d)switch(d=d.toString().trim().toLowerCase(),d){case"y":case"true":case"yes":i(o.key,null);break;default:i(o.key,{$ne:null});break}u(".contains",f=>({$contains:f}),!1,!0),u(".notContains",f=>({$notContains:f}),!1,!0),u(".startsWith",f=>({$startsWith:f}),!1,!0),u(".endsWith",f=>({$endsWith:f}),!1,!0)});let n=e.get("OR");if(n){const u=a(n).map(d=>({$or:d.map(f=>ht(s,{get:c=>f[c]}))}));u.length==1?t.$or?t.$or.push(u[0].$or):t.$or=u[0].$or:r({$and:u})}if(n=e.get("NOT"),n){let o=a(n);const u=[];for(const d of o)if(Array.isArray(d))for(const f of d)u.push({$not:ht(s,{get:c=>f[c]})});else u.push({$not:ht(s,{get:f=>d[f]})});u.length==1?t.$not?t.$not.push(u[0].$not):t.$not=u[0].$not:r({$and:u})}for(const o in s.entityType){const u=s.entityType[o];if(u&&u.rawFilterInfo&&u.rawFilterInfo.rawFilterTranslator){let d=e.get(Ee+o);if(d!==void 0){const f=c=>{c[Zt]!=null&&(c=c[Zt]),i(Ee+o,c)};Array.isArray(d)?d.forEach(c=>f(c)):f(d)}}}return t;function a(o){if(!Array.isArray(o))return[o];const u=[],d=[];for(const f of o)Array.isArray(f)?d.push(f):u.push(f);return d.push(u),d}}class bt{constructor(e){l(this,"translateCustom");l(this,"commands",[]);l(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 bt(this.translateCustom);return r.__applyToConsumer(i),await i.resolve(),new I(n=>i.applyTo(n))})).then(r=>{t=r})),this.commands.push(r=>r.or(t))}not(e){let t;this.promises.push((async()=>{let r=new bt(this.translateCustom);e.__applyToConsumer(r),await r.resolve(),t=new I(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 _t{constructor(){l(this,"rawValues",{});l(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=M(r.field);if(i){if(i.type==="reference")return r.values.map(n=>i.toRepo.metadata.idMetadata.getIdFilter(n));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 _t;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 n=r.rawValues[i];n&&(n.bad?this.notOk(n.field):this.ok(n.field,...n.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 js={};const Bt=Symbol.for("remult-static1");let pt={defaultRemultFactory:void 0,remultFactory:void 0,defaultRemult:void 0,asyncContext:void 0,columnsOfType:new Map,allEntities:[],classHelpers:new Map,actionInfo:{allActions:[],runningOnServer:!1,runActionWithoutBlockingUI:s=>s(),startBusyWithProgress:()=>({progress:s=>{},close:()=>{}})},fieldOptionsEnricher:void 0,labelTransformer:void 0,defaultIdFactory:void 0,defaultDataProvider:()=>{}};typeof process<"u"&&js.IGNORE_GLOBAL_REMULT_IN_TESTS||typeof globalThis[Bt]>"u"?(globalThis[Bt]=pt,pt.remultFactory=()=>di()):pt=globalThis[Bt];const v=pt;function di(){return v.defaultRemult||(v.defaultRemult=v.defaultRemultFactory()),v.defaultRemult}function Ls(){v.remultFactory=()=>di()}function Te(s){const e=s;if(typeof e[it]=="function")return e[it]();throw Error("Error getting repository internal from "+s)}const it=Symbol.for("getInternal");class Bs{constructor(){l(this,"iAmRemultProxy",!0);l(this,"repoCache",new Map);l(this,"repo",(...e)=>{let t=v,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 v.remultFactory().repo(...e).metadata.fields},[it](){return t.remultFactory().repo(...e)[it]()},relations:n=>t.remultFactory().repo(...e).relations(n),validate:(n,...a)=>t.remultFactory().repo(...e).validate(n,...a),addEventListener:(...n)=>t.remultFactory().repo(...e).addEventListener(...n),count:(...n)=>t.remultFactory().repo(...e).count(...n),create:(...n)=>t.remultFactory().repo(...e).create(...n),delete:n=>t.remultFactory().repo(...e).delete(n),deleteMany:n=>t.remultFactory().repo(...e).deleteMany(n),updateMany:(...n)=>t.remultFactory().repo(...e).updateMany(...n),find:(...n)=>t.remultFactory().repo(...e).find(...n),groupBy:(...n)=>t.remultFactory().repo(...e).groupBy(...n),aggregate:(...n)=>t.remultFactory().repo(...e).aggregate(...n),findFirst:(...n)=>t.remultFactory().repo(...e).findFirst(...n),findOne:(...n)=>t.remultFactory().repo(...e).findOne(...n),findId:(n,a)=>t.remultFactory().repo(...e).findId(n,a),toJson:n=>t.remultFactory().repo(...e).toJson(n),fromJson:(n,a)=>t.remultFactory().repo(...e).fromJson(n,a),getEntityRef:(...n)=>t.remultFactory().repo(...e).getEntityRef(...n),insert:n=>t.remultFactory().repo(...e).insert(n),liveQuery:(...n)=>t.remultFactory().repo(...e).liveQuery(...n),get metadata(){return v.remultFactory().repo(...e).metadata},query:n=>t.remultFactory().repo(...e).query(n),save:n=>t.remultFactory().repo(...e).save(n),upsert:n=>t.remultFactory().repo(...e).upsert(n),update:(n,a)=>t.remultFactory().repo(...e).update(n,a)},r.set(e[1],i),i)})}get liveQuerySubscriber(){return v.remultFactory().liveQuerySubscriber}set liveQuerySubscriber(e){v.remultFactory().liveQuerySubscriber=e}get liveQueryStorage(){return v.remultFactory().liveQueryStorage}set liveQueryStorage(e){v.remultFactory().liveQueryStorage=e}get liveQueryPublisher(){return v.remultFactory().liveQueryPublisher}set liveQueryPublisher(e){v.remultFactory().liveQueryPublisher=e}subscribeAuth(e){return v.remultFactory().subscribeAuth(e)}initUser(){return v.remultFactory().initUser()}call(e,t,...r){return v.remultFactory().call(e,t,...r)}get context(){return v.remultFactory().context}get dataProvider(){return v.remultFactory().dataProvider}set dataProvider(e){v.remultFactory().dataProvider=e}get repCache(){return v.remultFactory().repCache}authenticated(){return v.remultFactory().authenticated()}isAllowed(e){return v.remultFactory().isAllowed(e)}isAllowedForInstance(e,t){return v.remultFactory().isAllowedForInstance(e,t)}clearAllCache(){return v.remultFactory().clearAllCache()}useFetch(e){return v.remultFactory().useFetch(e)}get user(){return v.remultFactory().user}set user(e){v.remultFactory().user=e}get apiClient(){return v.remultFactory().apiClient}set apiClient(e){v.remultFactory().apiClient=e}get subscriptionServer(){return v.remultFactory().subscriptionServer}set subscriptionServer(e){v.remultFactory().subscriptionServer=e}}const z=new Bs,Vs="$count",Us=Symbol.for("GroupByForApiKey"),Ws=["sum","avg","min","max","distinctCount"],fi={error500RetryCount:4};function ci(s){return s.replace(/([a-z])([A-Z])/g,"$1 $2").replace(/^./,e=>e.toUpperCase()).replace("Email","eMail")}class Qs{constructor(e,t,r){l(this,"repository");l(this,"isReferenceRelation");l(this,"allowNull");l(this,"storedItem");l(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:Te(this.repository)._getCachedByIdAsync(e,!1)}get(e){if(e==null)return null;const t=Te(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=$(e,!1);t&&!this.isReferenceRelation?(Te(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 se{constructor(...e){l(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 se;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 n=this.Segments[i],a=e[r(n.field)],o=t[r(n.field)],u=n.isDescending,d=Gs(a,o,u);if(d!=0)return d}return 0}static translateOrderByToSort(e,t){let r=new se;if(t){for(const i in t)if(Object.prototype.hasOwnProperty.call(t,i)){const n=t[i];let a=e.fields.find(i);const o=u=>{switch(n){case"desc":r.Segments.push({field:u,isDescending:!0});break;case"asc":r.Segments.push({field:u})}};if(a){const u=M(a);if((u==null?void 0:u.type)==="toOne"){const d=u.options;if(typeof d.field=="string")o(e.fields.find(d.field));else if(d.fields){for(const f in d.fields)if(Object.prototype.hasOwnProperty.call(d.fields,f)){const c=d.fields[f];o(e.fields.find(c.toString()))}}}else o(a)}}}return r}static createUniqueSort(e,t){(!t||Object.keys(t).length===0)&&e.options.defaultOrderBy&&(t=se.translateOrderByToSort(e,e.options.defaultOrderBy)),t||(t=new se);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 Gs(s,e,t){s=Dr(s),e=Dr(e);let r=0;return s>e?r=1:s<e&&(r=-1),t&&(r*=-1),r}function Dr(s){return s==null||s==null?s:s.id!==void 0?s.id:s}class hi extends Error{constructor(t){super(t.message);l(this,"modelState");l(this,"stack");l(this,"exception");l(this,"httpStatusCode");Object.assign(this,t)}}class Ks{constructor(e){l(this,"dataProvider");l(this,"isProxy");this.dataProvider=e}getEntityDataProvider(e){return new Hs(this.dataProvider.then(t=>t.getEntityDataProvider(e)))}transaction(e){return this.dataProvider.then(t=>t.transaction(e))}ensureSchema(e){return this.dataProvider.then(t=>{var r;return(r=t.ensureSchema)==null?void 0:r.call(t,e)})}}class Hs{constructor(e){l(this,"dataProvider");this.dataProvider=e}delete(e){return this.dataProvider.then(t=>t.delete(e))}insert(e){return this.dataProvider.then(t=>t.insert(e))}count(e){return this.dataProvider.then(t=>t.count(e))}find(e){return this.dataProvider.then(t=>t.find(e))}groupBy(e){return this.dataProvider.then(t=>t.groupBy(e))}update(e,t){return this.dataProvider.then(r=>r.update(e,t))}}class Rr{constructor(e){l(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)}}}async function It(s){var t,r,i,n;let e=0;for(;;)try{return await s()}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")||(n=a.message)!=null&&n.startsWith("Gateway Timeout")||a.status==500)&&e++<fi.error500RetryCount){await new Promise((o,u)=>{setTimeout(()=>{o({})},500)});continue}throw a}}class Nr{constructor(e){l(this,"fetch");this.fetch=e}async get(e){return await It(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 It(()=>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=>zs(i)).catch(async i=>{throw await i})}}function zs(s){if(s.status!=204){if(s.status>=200&&s.status<300)return s.json();throw s.json().then(e=>({...e,message:e.message||s.statusText,url:s.url,status:s.status})).catch(()=>{throw{message:s.statusText,url:s.url,status:s.status}})}}function je(s){if(!s)return new Nr;let e;return e||pi(s)&&(e=new Xs(s)),e||typeof s=="function"&&(e=new Nr(s)),e}function pi(s){let e=s;return!!(e&&e.get&&e.put&&e.post&&e.delete)}class Xs{constructor(e){l(this,"http");this.http=e}async post(e,t){return await It(()=>dt(this.http.post(e,t)))}delete(e){return dt(this.http.delete(e))}put(e,t){return dt(this.http.put(e,t))}async get(e){return await It(()=>dt(this.http.get(e)))}}function dt(s){let e;return s.toPromise!==void 0?e=s.toPromise():e=s,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 Ys(t)})}async function Ys(s){var n,a,o;let e=await s;var t;e.error?t=e.error:e.isAxiosError&&(typeof((n=e.response)==null?void 0:n.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 er{constructor(e,t){l(this,"apiProvider");l(this,"entityRequested");l(this,"isProxy",!0);this.apiProvider=e,this.entityRequested=t}getEntityDataProvider(e){var t;return(t=this.entityRequested)==null||t.call(this,e),new Zs(()=>{var r;return yi((r=this.apiProvider())==null?void 0:r.url,e.key)},()=>je(this.apiProvider().httpClient),e)}async transaction(e){throw new Error("Method not implemented.")}}function yi(s,e){return s==null&&(s="/api"),s+"/"+e}function ar(s,e){if(s.include){let t={};for(const r in s.include)if(Object.prototype.hasOwnProperty.call(s.include,r)){let i=s.include[r];if(typeof i=="object"){const n=M(e.fields.find(r));n&&(i=ar(i,n.toRepo.metadata))}t[r]=i}s={...s,include:t}}return s.where&&(s={...s,where:I.entityFilterToJson(e,s.where)}),s.load&&(s={...s,load:s.load(e.fields).map(t=>t.key)}),s}class Zs{constructor(e,t,r){l(this,"url");l(this,"http");l(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:n})=>({items:i.map(a=>this.translateFromJson(a)),aggregates:n}))}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(n=>{for(const a of e.group)n[a.key]=a.valueConverter.fromJson(n[a.key])}),i}buildAggregateOptions(e){var t,r,i,n,a,o,u;return{groupBy:(t=e==null?void 0:e.group)==null?void 0:t.map(d=>d.key),sum:(r=e==null?void 0:e.sum)==null?void 0:r.map(d=>d.key),avg:(i=e==null?void 0:e.avg)==null?void 0:i.map(d=>d.key),min:(n=e==null?void 0:e.min)==null?void 0:n.map(d=>d.key),max:(a=e==null?void 0:e.max)==null?void 0:a.map(d=>d.key),distinctCount:(o=e==null?void 0:e.distinctCount)==null?void 0:o.map(d=>d.key),orderBy:(u=e==null?void 0:e.orderBy)==null?void 0:u.map(d=>{var f;return{...d,field:(f=d.field)==null?void 0:f.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 Rr(this.url()),i;if(e){if(e.where&&(i=e.where.toJson(),en(i,r)&&(i=void 0)),e.orderBy&&e.orderBy.Segments){let a="",o="",u=!1;e.orderBy.Segments.forEach(d=>{a.length>0&&(a+=",",o+=","),a+=d.field.key,o+=d.isDescending?"desc":"asc",d.isDescending&&(u=!0)}),a&&r.add("_sort",a),u&&r.add("_order",o)}e.limit&&r.add("_limit",e.limit),e.page&&r.add("_page",e.page)}const n=(a,o)=>{let u=new Rr(r.url);if(!a&&i&&(a="get"),a&&u.add("__action",a),i){if(t==="put")return this.http().post(u.url,{set:o,where:i});o={...o,where:i}}return o&&t!="put"?this.http().post(u.url,o):this.http()[t](u.url,o)};return{createKey:()=>JSON.stringify({url:r,filterObject:i}),run:n,subscribe:async a=>({result:await n(tn+a),unsubscribe:async()=>v.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(I.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)))}}function en(s,e){for(const t in s)if(Object.prototype.hasOwnProperty.call(s,t)){const r=s[t];if(Array.isArray(r)&&(r.length>0&&typeof r[0]=="object"||r.length>10)||t==="NOT")return!1}for(const t in s)if(Object.prototype.hasOwnProperty.call(s,t)){const r=s[t];Array.isArray(r)?t.endsWith(".in")?e.add(t,JSON.stringify(r)):r.forEach(i=>e.add(t,i)):t.startsWith(Ee)?e.add(t,JSON.stringify(r)):e.add(t,r)}return!0}const tn="liveQuery-",Vt="stream";class rn{constructor(e,t,r){l(this,"repo");l(this,"query");l(this,"queryChannel");l(this,"subscribeCode");l(this,"unsubscribe",()=>{});l(this,"defaultQueryState",[]);l(this,"listeners",[]);l(this,"id",String(crypto.randomUUID()));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 Te(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=se.translateOrderByToSort(this.repo.metadata,this.query.options.orderBy);this.defaultQueryState.sort((n,a)=>i.compare(n,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 Te(this.repo)._fromJsonArray(t.map(i=>i.data.item),this.query.options);for(let i=0;i<t.length;i++){const n=t[i];n.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(n=>this.repo.metadata.idMetadata.getId(n)===i.data.oldId?i.data.item:n);break}case"add":r=r.filter(n=>this.repo.metadata.idMetadata.getId(n)!==this.repo.metadata.idMetadata.getId(i.data.item)),r.push(i.data.item);break;case"remove":r=r.filter(n=>this.repo.metadata.idMetadata.getId(n)!==i.data.id);break}return r})},e)}}const sn="_liveQueryKeepAlive";class nn{constructor(e,t){l(this,"apiProvider");l(this,"getUserId");l(this,"queries",new Map);l(this,"channels",new Map);l(this,"client");l(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 n=this.channels.get(e);if(!n){this.channels.set(e,n=new an);try{n.unsubscribe=await i.subscribe(e,a=>this.wrapMessageHandling(()=>n.handle(a)),a=>{t.error(a)})}catch(a){throw t.error(a),a}}n.listeners.push(t),r=()=>{n.listeners.splice(n.listeners.indexOf(t),1),n.listeners.length==0&&(this.channels.delete(e),n.unsubscribe()),this.closeIfNoListeners()}}catch(n){throw t.error(n),n}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,n=()=>{i=!1};return this.runPromise(Te(e)._buildEntityDataProviderFindOptions(t).then(a=>{if(!i)return;const{createKey:o,subscribe:u}=new er(this.apiProvider).getEntityDataProvider(e.metadata).buildFindRequest(a),d=o();let f=this.queries.get(d);f?f.sendDefaultState(r.next):(this.queries.set(d,f=new rn(e,{entityKey:e.metadata.key,options:t},this.getUserId())),f.subscribeCode=()=>{f.unsubscribe&&(f.unsubscribe(),f.unsubscribe=()=>{}),this.runPromise(this.subscribeChannel(f.queryChannel,{next:c=>this.runPromise(f.handle(c)),complete:()=>{},error:c=>{f.listeners.forEach(h=>h.error(c))}}).then(c=>{if(f.listeners.length==0){c();return}this.runPromise(u(f.queryChannel).then(h=>{if(f.listeners.length===0){h.unsubscribe(),c();return}this.runPromise(f.setAllItems(h.result)),f.unsubscribe=()=>{f.unsubscribe=()=>{},c(),this.runPromise(h.unsubscribe())}}).catch(h=>{f.listeners.forEach(p=>p.error(h)),c(),this.queries.delete(d)}))})).catch(c=>{f.listeners.forEach(h=>h.error(c))})},f.subscribeCode()),f.listeners.push(r),n=()=>{f.listeners.splice(f.listeners.indexOf(r),1),r.complete(),f.listeners.length==0&&(this.queries.delete(d),f.unsubscribe()),this.closeIfNoListeners()}}).catch(a=>{r.error(a)})),()=>{n()}}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 v.actionInfo.runActionWithoutBlockingUI(()=>je(t.httpClient).post(t.url+"/"+sn,e)));for(const i of r)for(const n of this.queries.values())n.queryChannel===i&&n.subscribeCode()}},3e4),this.runPromise(this.client=this.apiProvider().subscriptionClient.openConnection(()=>{for(const e of this.queries.values())e.subscribeCode()})))}}class an{constructor(){l(this,"unsubscribe",()=>{});l(this,"listeners",[])}async handle(e){for(const t of this.listeners)t.next(e)}}class or{openConnection(e){let t;const r=new Map,i=je(z.apiClient.httpClient);let n=!1,a;const o={close(){a.close()},async subscribe(f,c){let h=r.get(f);return h||(r.set(f,h=[]),await d(f)),h.push(c),()=>{h.splice(h.indexOf(c,1)),h.length==0&&(v.actionInfo.runActionWithoutBlockingUI(()=>i.post(z.apiClient.url+"/"+Vt+"/unsubscribe",{channel:f,clientId:t})),r.delete(f))}}},u=()=>new Promise(f=>{h();let c=0;function h(){a&&a.close(),a=or.createEventSource(z.apiClient.url+"/"+Vt),a.onmessage=p=>{let y=JSON.parse(p.data);const g=r.get(y.channel);g&&g.forEach(m=>m(y.data))},a.onerror=p=>{console.error("Live Query Event Source Error",p),a.close(),c++<fi.error500RetryCount&&setTimeout(()=>{h()},500)},a.addEventListener("connectionId",async p=>{if(t=p.data,n){for(const y of r.keys())await d(y);e()}else n=!0,f(o)})}});return u();async function d(f){await v.actionInfo.runActionWithoutBlockingUI(()=>i.post(z.apiClient.url+"/"+Vt+"/subscribe",{channel:f,clientId:t}))===on&&await u()}}static createEventSource(e){return new EventSource(e,{withCredentials:!0})}}const on="client connection not found",tr=Symbol.for("serverActionField");class Ye{constructor(){l(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)}}class ln{constructor(e){l(this,"remultObjectStorage");this.remultObjectStorage=e}static enable(){v.remultFactory=()=>{const e=v.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(){Ls()}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()}}v.asyncContext||(v.asyncContext=new ln(void 0));function st(){return v.actionInfo.runningOnServer||!z.dataProvider.isProxy}class he{constructor(e){l(this,"repo",(e,t)=>{let r=ee(e)(z);if(t===void 0&&r!=null&&r.dataProvider){const a=r.dataProvider(this.dataProvider);a instanceof Promise?t=new Ks(a):t=a??void 0}t||(t=this.dataProvider);let i=this.repCache.get(t);i||this.repCache.set(t,i=new Map);let n=i.get(e);return n||(i.set(e,n=new ur(e,this,t,wn(e,this))),$s(n,this,t)),n});l(this,"_subscribers");l(this,"__user");l(this,"dataProvider",new er(()=>this.apiClient));l(this,"repCache",new Map);l(this,"liveQueryStorage");l(this,"subscriptionServer");l(this,"liveQueryPublisher",{itemChanged:async()=>{}});l(this,"liveQuerySubscriber",new nn(()=>this.apiClient,()=>{var e;return(e=this.user)==null?void 0:e.id}));l(this,"context",{});l(this,"apiClient",{url:"/api",subscriptionClient:new or});if(e&&e.getEntityDataProvider){this.dataProvider=e;return}if(pi(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)}}subscribeAuth(e){return this._subscribers||(this._subscribers=new Ye),this._subscribers.subscribe(e)}get user(){var e;return(e=this._subscribers)==null||e.reportObserved(),this.__user}set user(e){var t;this.__user=e,(t=this._subscribers)==null||t.reportChanged()}async initUser(){const t=await je(this.apiClient.httpClient).get(yi(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 er(()=>({httpClient:e}))}call(e,t,...r){const i=e[tr];if(!i.doWork)throw Error("The method received is not a valid backend method");return i.doWork(r,t,this.apiClient.url,je(this.apiClient.httpClient))}clearAllCache(){this.repCache.clear()}}l(he,"onFind",(e,t)=>{}),l(he,"entityRefInit");v.defaultRemultFactory=()=>new he;class mi{constructor(){l(this,"classes",new Map)}}function un(s,e){let t=s;for(;;){let r=v.classHelpers.get(t);r||v.classHelpers.set(t,r=new mi),r.classes.set(s,e);let i=Object.getPrototypeOf(t.prototype);if(i==null)break;t=i.constructor}}const dn={defaultPageSize:200};async function fn(s,e){const t=new cn(s.liveQueryPublisher);let r=!0;const i=s.dataProvider;try{await s.dataProvider.transaction(async n=>{s.dataProvider=n,s.liveQueryPublisher=t,await e(n),r=!0}),r&&await t.flush()}finally{s.dataProvider=i}}class cn{constructor(e){l(this,"orig");l(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 n=r.find(a=>a.id===i.oldId);n!==void 0?(i.deleted&&(n.deleted=!0),i.id!=n.id&&(n.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 Ze(s,e){return e&&Object.assign(s,e),s}class le{}l(le,"number","number"),l(le,"date","date"),l(le,"checkbox","checkbox"),l(le,"password","password"),l(le,"email","email"),l(le,"tel","tel"),l(le,"time","time"),l(le,"json","json");const A=class A{};l(A,"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=>A.Date.fromJson(e),toInput:e=>A.Date.toJson(e),displayValue:e=>e?e.toLocaleString():""}),l(A,"DateOnly",{fromInput:e=>A.DateOnly.fromJson(e),toInput:e=>A.DateOnly.toJson(e),toJson:e=>{var t=e;if((typeof t=="string"||typeof t=="number")&&(t=new Date(t)),t!==void 0)return!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:le.date,toDb:e=>e?A.DateOnly.fromJson(A.DateOnly.toJson(e)):null,fromDb:e=>A.Date.fromDb(e),fieldTypeInDb:"date",displayValue:e=>e?e.toLocaleDateString(void 0):""}),l(A,"DateOnlyString",{...A.DateOnly,toDb:e=>{let t=A.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))}}),l(A,"Boolean",{toDb:e=>e,inputType:le.checkbox,fromDb:e=>A.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=>A.Boolean.fromJson(e),toInput:e=>A.Boolean.toJson(e)}),l(A,"Number",{fromDb:e=>{if(e===null)return null;if(e!==void 0)return+e},toDb:e=>e,fromJson:e=>A.Number.fromDb(e),toJson:e=>A.Number.toDb(e),fromInput:(e,t)=>{let r=+e;if(e===null)return null;if(e!==void 0)return r},toInput:(e,t)=>(e==null?void 0:e.toString())??"",inputType:le.number}),l(A,"String",{fromDb:$e,toDb:$e,fromJson:$e,toJson:$e,fromInput:$e,toInput:$e}),l(A,"Integer",{...A.Number,toJson:e=>{let t=A.Number.toDb(e);return t&&+(+t).toFixed(0)},toDb:e=>A.Integer.toJson(e),fieldTypeInDb:"integer"}),l(A,"Default",{fromJson:e=>e,toJson:e=>e,fromDb:e=>A.JsonString.fromDb(e),toDb:e=>A.JsonString.toDb(e),fromInput:e=>A.Default.fromJson(e),toInput:e=>A.Default.toJson(e),displayValue:e=>e+"",fieldTypeInDb:"",inputType:"text"}),l(A,"JsonString",{fromJson:e=>e,toJson:e=>e,fromDb:e=>e==null?null:e?JSON.parse(A.JsonString.fromJson(e)):void 0,toDb:e=>e!==void 0?e===null?null:JSON.stringify(A.JsonString.toJson(e)):void 0,fromInput:e=>A.JsonString.fromJson(e),toInput:e=>A.JsonString.toJson(e)}),l(A,"JsonValue",{fromJson:e=>e,toJson:e=>e,fromDb:e=>e,toDb:e=>e,fromInput:e=>A.JsonString.fromJson(e),toInput:e=>A.JsonString.toJson(e),fieldTypeInDb:"json"});let H=A;function $e(s){return s==null?s:typeof s!="string"?s.toString():s}function Ut(s,e,t){let r=I.fromEntityFilter(s,e);const i=()=>{};r&&r.__applyToConsumer({custom:i,databaseCustom:i,containsCaseInsensitive:i,notContainsCaseInsensitive:i,startsWithCaseInsensitive:i,endsWithCaseInsensitive:i,isDifferentFrom:i,isEqualTo:(n,a)=>{t[n.key]=a},isGreaterOrEqualTo:i,isGreaterThan:i,isIn:i,isLessOrEqualTo:i,isLessThan:i,isNotNull:i,isNull:i,not:i,or:i})}class et{constructor(){l(this,"entityLoaders",new Map);l(this,"promises",[])}load(e,t){let r=this.entityLoaders.get(e.entityType);r||this.entityLoaders.set(e.entityType,r=new hn(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 hn{constructor(e){l(this,"rel");l(this,"queries",new Map);this.rel=e}find(e){const{where:t,...r}=ar(e,this.rel.metadata),i=JSON.stringify(r);let n=this.queries.get(i);return n||this.queries.set(i,n=new pn(this.rel)),n.find(e,t)}}class pn{constructor(e){l(this,"rel");l(this,"pendingInStatements",new Map);l(this,"whereVariations",new Map);this.rel=e}find(e,t){const r=JSON.stringify(t);let i=this.whereVariations.get(r);if(!i){const n=Object.keys(t);if(n.length===1&&typeof t[n[0]]!="object"&&!e.limit){let a=this.pendingInStatements.get(n[0]);a||this.pendingInStatements.set(n[0],a=new yn(this.rel,n[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 yn{constructor(e,t,r){l(this,"rel");l(this,"key");l(this,"options");l(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(n=>{const o=$(n).fields.find(this.key),u=M(o.metadata),d=(u==null?void 0:u.type)==="reference"?o.getId():n[this.key];return i.value==d}))}catch(i){for(const n of this.values.values())n.reject(i)}}find(e){const t=e[this.key];let r=this.values.get(t);if(!r){let i,n,a=new Promise((o,u)=>{i=o,n=u});this.values.set(t,r={value:t,resolve:i,reject:n,result:a})}return r.result}}async function gi(s,e=t=>t){if(s.options.sqlExpression){if(typeof s.options.sqlExpression=="string")return s.options.sqlExpression;if(typeof s.options.sqlExpression=="function"){const t=s.options.sqlExpression;try{return s.options.sqlExpression="recursive sqlExpression call for entity '"+s.key+"'. ",await t(s)}finally{s.options.sqlExpression=t}}}return e(s.dbName)}const Wt=Symbol.for("sqlExpressionInProgressKey");async function lr(s,e,t=i=>i,r=!1){try{if(s.options.sqlExpression){let a;if(typeof s.options.sqlExpression=="function"){if(s[Wt]&&!r)return"recursive sqlExpression call for field '"+s.key+"'. \0";try{s[Wt]=!0,a=await s.options.sqlExpression(e),a.includes("\0")||(s.options.sqlExpression=()=>a)}finally{delete s[Wt]}}else a=s.options.sqlExpression;return a||s.dbName}const i=M(s);let n=(i==null?void 0:i.type)==="toOne"&&s.options.field;if(n){let a=e.fields.find(n);if(a)return lr(a,e,t,r)}return t(s.dbName)}finally{}}const U=class U{};l(U,"required",tt(async(e,t)=>!t.valueIsNull()&&t.value!==""&&(t.value!==void 0||M(t.metadata)!==void 0),"Should not be empty")),l(U,"unique",tt(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")),l(U,"uniqueOnBackend",tt(async(e,t)=>t.isBackend()&&(t.isNew||t.valueChanged())?await t.entityRef.repository.count({[t.metadata.key]:t.value})==0:!0,U.unique.defaultMessage)),l(U,"regex",Oe((e,t)=>t.test(e))),l(U,"email",yt(e=>/^[^\s@]+@[^\s@]+\.[^\s@]+$/.test(e),"Invalid Email")),l(U,"url",yt(e=>!!new URL(e),"Invalid Url")),l(U,"in",Oe((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(", ")}`)),l(U,"notNull",yt(e=>e!=null,"Should not be null")),l(U,"enum",Oe((e,t)=>Object.values(t).includes(e),e=>`Value must be one of ${mt(e).join(", ")}`)),l(U,"relationExists",tt(async(e,t)=>t.valueIsNull()||!t.isBackend()?!0:!!await t.load(),"Relation value does not exist")),l(U,"min",Oe((e,t)=>e>=t,e=>`Value must be bigger than or equal to ${e}`)),l(U,"max",Oe((e,t)=>e<=t,e=>`Value must be smaller than or equal to ${e}`)),l(U,"maxLength",Oe((e,t)=>e.length<=t,e=>`Value must be at most ${e} characters`)),l(U,"minLength",Oe((e,t)=>e.length>=t,e=>`Value must be at least ${e} characters`)),l(U,"range",Oe((e,[t,r])=>e>=t&&e<=r,([e,t])=>`Value must be between ${e} and ${t}`)),l(U,"defaultMessage","Invalid value");let de=U;function tt(s,e){const t=async(i,n,a)=>{const o=await s(i,n);typeof o=="string"&&o.length>0?n.error=o:o||(n.error=typeof a=="function"&&a(i,n,void 0)||a||typeof e=="function"&&e(i,n,void 0)||e||de.defaultMessage)},r=(i,n,a)=>typeof i=="string"||i==="function"||i===void 0&&n===void 0?async(o,u,d)=>await t(o,u,i||d):t(i,n,a);return Object.defineProperty(r,"defaultMessage",{get:()=>e,set:i=>{e=i},enumerable:!0}),Object.assign(r,{withMessage:i=>async(n,a)=>r(n,a,i)})}function yt(s,e){return tt((t,r)=>r.value===void 0||r.value===null?!0:s(r.value),e)}function Oe(s,e){const t=mn((r,i,n)=>i.value===void 0||i.value===null?!0:s(i.value,n),(r,i,n)=>typeof e=="function"&&e(n)||e,!0);return Object.assign((r,i)=>t(r,i),{get defaultMessage(){return e},set defaultMessage(r){e=r}})}function mn(s,e,t=!1){return Object.assign((i,n)=>async(a,o)=>{const u=await s(a,o,i);typeof u=="string"?o.error=u:u||(o.error=n?typeof n=="function"?t?n(i):n(a,o,i):n:e?typeof e=="function"?e(a,o,i):e:de.defaultMessage)},{get defaultMessage(){return e},set defaultMessage(i){e=i}})}function mt(s){return Object.values(s).filter(e=>typeof s[e]!="number")}function gt(s,e,t=!1){if(!e)return s;const r=Array.isArray(e)?e:[e],i=Array.isArray(s)?s:s?[s]:[];return t?[...r,...i]:[...i,...r]}function Je(s,e){return typeof s[e]<"u"}class gn{constructor(e,t){l(this,"options");l(this,"repo");l(this,"_count");l(this,"_aggregates");this.options=e,this.repo=t,this.options||(this.options={}),this.options.pageSize||(this.options.pageSize=dn.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=se.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&&Je(this.options,"aggregate")){let o=this.options.aggregate;if(this.repo._dataProvider.isProxy){const u=new et;r=()=>this.repo._rawFind(t,!1,u,async d=>{const f=await this.repo._edp.query(d,await this.repo.__buildGroupByOptions(o));return this._aggregates=f.aggregates,f.items}).then(async d=>(await u.resolveAll(),d))}else{let u=r();r=async()=>(this._aggregates=await this.repo.aggregate({...o,where:this.options.where}),this._count=this._aggregates.$count,u)}}let i=await r(),n=()=>{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]);n=()=>this.paginator(o)}return{count:()=>this.count(),hasNextPage:a,items:i,nextPage:n,aggregates:this._aggregates}}[Symbol.asyncIterator](){this.options.where||(this.options.where={});let e=this.options.orderBy;this.options.orderBy=se.createUniqueEntityOrderBy(this.repo.metadata,e);let t=-1,r,i,n=0;return i=async()=>{if(this.options.progress&&this.options.progress.progress(n++/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 ur{constructor(e,t,r,i,n){l(this,"_entity");l(this,"_remult");l(this,"_dataProvider");l(this,"_info");l(this,"_defaultFindOptions");l(this,"__edp");l(this,"_idCache",new Map);l(this,"listeners");l(this,"_cache",new Map);this._entity=e,this._remult=t,this._dataProvider=r,this._info=i,this._defaultFindOptions=n}_notFoundError(e){return{message:`id ${e} not found in entity ${this.metadata.key}`,httpStatusCode:404}}[it](){return this}async _createAfterFilter(e,t){let r=new Map;for(const a of se.translateOrderByToSort(this.metadata,e).Segments){let o=t[a.field.key];r.set(a.field.key,o)}let i={$or:[]},n=[];for(const a of se.translateOrderByToSort(this.metadata,e).Segments){let o={};for(const u of n)o[u.key]=r.get(u.key);n.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),n=M(i);if(!n)throw Error(r+" is not a relation");const{toRepo:a,returnNull:o,returnUndefined:u}=this._getFocusedRelationRepo(i,e);return n.type==="toMany"?a:{findOne:d=>o?Promise.resolve(null):u?Promise.resolve(void 0):a.findFirst({},d)}}})}_getFocusedRelationRepo(e,t){const r=M(e);let i=r.toRepo,{findOptions:n,returnNull:a,returnUndefined:o}=this._findOptionsBasedOnRelation(r,e,void 0,t,i);return{toRepo:new ur(i._entity,i._remult,i._dataProvider,i._info,n),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[Us])&&e.group){const i={include:{}};for(const a of e.group)i.include[a]=!0;const n=new et;await this._populateRelationsForFields(t.group,i,r,n),await n.resolveAll()}return r}async __buildGroupByOptions(e){var a,o,u,d,f,c;let t=await this._buildEntityDataProviderFindOptions({...e});const r=h=>{const p=this.metadata.fields.find(h);if(p===void 0)throw Error(`key "${h}" not found in entity`);return p},i=h=>{var p;if((p=e==null?void 0:e.group)!=null&&p.includes(h))throw Error(`field "${h}" cannot be used both in an aggregate and in group by`);return r(h)};var n={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:(u=e==null?void 0:e.avg)==null?void 0:u.map(i),min:(d=e==null?void 0:e.min)==null?void 0:d.map(i),max:(f=e==null?void 0:e.max)==null?void 0:f.map(i),distinctCount:(c=e==null?void 0:e.distinctCount)==null?void 0:c.map(i)};if(e!=null&&e.orderBy){n.orderBy=[];for(const h in e.orderBy)if(Object.prototype.hasOwnProperty.call(e==null?void 0:e.orderBy,h)){const p=e.orderBy[h];if(p){if(typeof p=="string")n.orderBy.push({field:h==="$count"?void 0:r(h),isDescending:p==="desc",operation:h==="$count"?"count":void 0});else for(const y in p)if(Object.prototype.hasOwnProperty.call(p,y)){const g=p[y];n.orderBy.push({field:this.metadata.fields.find(h),isDescending:g==="desc",operation:y})}}}}return n}_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(n=>(n===void 0?r=null:r=n,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 gn(e,this)}getEntityRef(e){let t=e[Fe];return t||(this._fixTypes(e),t=new ft(this._info,e,this,this._edp,this._remult,!0),Object.defineProperty(e,Fe,{get:()=>t}),t.saveOriginalData()),t}async delete(e){const t=$(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 $(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],n=this.fields[i];if(n){const a=M(n);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],M(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 n=$(e,!1);if(n){if(!n.isNew())throw"Item is not new"}else n=await this.getEntityRef(this.create(i));t.push(n),r.push(await n.buildDtoForInsert())}return Me(await this._edp.insertMany(r),(i,n)=>t[n].processInsertResponseDto(i))}else{let t=[];for(const r of e)t.push(await this.insert(r));return t}else{let t=$(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=$(e,!1);if(r||(r=this.getEntityRef({...e})),!t||t.length===0)return await r.validate();{r.__clearErrorsAndReportChanged();let i=!1;for(const n of t)await r.fields.find(n).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 n of this.fields)(n.dbReadOnly||!i.includes(n.key))&&delete r[n.key];return r}async updateMany({where:e,set:t}){if(this.__cleanupPartialObject(t),I.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}))Ze(i,t),await $(i).save(),r++;return r}}async update(e,t){{let i=$(t,!1);if(i)return await i.save()}{let i=$(e,!1);if(i)return Ze(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 n in t)if(Object.prototype.hasOwnProperty.call(t,n)){let a=r.fields[n];if(t[n]===void 0&&M(a.metadata))continue;a&&(i[n]=t[n])}return await this._fixTypes(i),await r.save()}}async upsert(e){if(this._dataProvider.isProxy){let n=await this._edp.upsertMany((Array.isArray(e)?e:[e]).map(u=>{var d;return(d=this._defaultFindOptions)!=null&&d.where&&(Ut(this.metadata,this._defaultFindOptions.where,u.where),this._fixTypes(u)),{where:this.__createDto(u.where),set:u.set?this.__createDto(u.set):void 0}}));const a=new et,o=await this._loadManyToOneForManyRows(n,{},a);return await a.resolveAll(),Array.isArray(e)?o:o[0]}if(Array.isArray(e))return Me(e,n=>this.upsert(n));let t=e;var r=await this.findFirst(t.where,{createIfNotFound:!0}),i=$(r,!1);return i.isNew()?(t.set&&Ze(r,t.set),await i.save()):t.set?(Ze(r,t.set),await i.save()):r}_getRefForExistingRow(e,t){let r=$(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 n=new ft(this._info,i,this,this._edp,this._remult,!1);typeof t=="object"&&(t=this.metadata.idMetadata.getId(t)),t?(n.id=t,n.originalId=t):n.id=n.getId(),r=n,Object.defineProperty(i,Fe,{get:()=>n})}return r}async save(e){if(Array.isArray(e))return Me(e,t=>this.save(t));{let t=$(e,!1);if(t)return await t.save();if(e instanceof Oi)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 n=await this._buildEntityDataProviderFindOptions(e);t&&(delete n.orderBy,delete n.limit),he.onFind(this._info,e);const a=await i(n);return await this._loadManyToOneForManyRows(a,e,r)}async find(e,t=!1){const r=new et,i=await this._rawFind(e,t,r,n=>this._edp.find(n));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=se.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 et,i=await this._loadManyToOneForManyRows(e.map(n=>{let a={};for(const o of this.metadata.fields.toArray())a[o.key]=o.valueConverter.fromJson(n[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 d of this.metadata.fields)if(ee(d.valueType,!1)&&!M(d)){let h=!d.options.lazy;if(i!==void 0&&(h=i.includes(d)),h){let p=this._remult.repo(d.valueType),y=[];for(const g of e){let m=g[d.key];m!=null&&!y.includes(m)&&!p._idCache.has(m+"")&&y.push(m)}y.length>0&&await n(p,y)}}async function n(d,f){let c=await d.find({where:d.metadata.idMetadata.getIdFilter(...f)},!0);for(const h of c)d._addToCache(h)}const a=new Set(this.fields.toArray().map(d=>{const f=this.__getRelationAndInclude(d,t);if(f.rel&&!f.incl)return d.key}).filter(d=>d!==void 0));let o=await Me(e,async d=>await this._mapRawDataToResult(d,i,a));const u=this.metadata.fields.toArray();return this._populateRelationsForFields(u,t,o,r),o}_populateRelationsForFields(e,t,r,i){for(const n of e){let{rel:a,incl:o}=this.__getRelationAndInclude(n,t);if(a)if(o){const u=a.toRepo;for(const d of r){let{findOptions:f,returnNull:c}=this._findOptionsBasedOnRelation(a,n,o,d,u);const h=n.key;if(c)d[h]=null;else{const p=a.toEntity,y=u;i.load({entityType:p,find:g=>y._rawFind(g,!1,i,m=>y._edp.find(m)),metadata:y.metadata},f).then(g=>{g.length==0&&a.type=="toOne"||(d[h]=a.type!=="toMany"?g.length==0?null:g[0]:g)})}}}else for(const u of r)Reflect.deleteProperty(u,n.key)}}__getRelationAndInclude(e,t){var a;let r=M(e),i=e.options.defaultIncluded;const n=(a=t==null?void 0:t.include)==null?void 0:a[e.key];return n!==void 0&&(i=n),{rel:r,incl:i}}_findOptionsBasedOnRelation(e,t,r,i,n){let a=!1,o=!1,u=[],d={},f=[];typeof e.options.findOptions=="function"?f.push(e.options.findOptions(i)):typeof e.options.findOptions=="object"&&f.push(e.options.findOptions),typeof r=="object"&&f.push(r);for(const p of f){p.where&&u.push(p.where);for(const y of["limit","include","orderBy"])p[y]&&(d[y]=p[y])}const c=e.getFields(),h=p=>{const y=$(i,!1);let g=e.type==="reference"&&y?y.fields.find(t.key).getId():i[p];return(e.type==="toOne"||e.type==="reference")&&(g===null?a=!0:g===void 0?o=!0:e.type==="reference"&&typeof g=="object"&&(g=n.metadata.idMetadata.getId(g))),g};c.compoundIdField&&(e.type==="toMany"?u.push({[c.compoundIdField]:this.metadata.idMetadata.getId(i)}):u.push(n.metadata.idMetadata.getIdFilter(h(c.compoundIdField))));for(const p in c.fields)Object.prototype.hasOwnProperty.call(c.fields,p)&&u.push({[p]:h(c.fields[p])});return d.where={$and:u},(e.type==="toOne"||e.type==="reference")&&d.orderBy&&(d.limit=1),{findOptions:d,returnNull:a,returnUndefined:o}}async _mapRawDataToResult(e,t,r){let i=new this._entity(this._remult),n=new ft(this._info,i,this,this._edp,this._remult,!1,r);return Object.defineProperty(i,Fe,{get:()=>n}),await n.loadDataFrom(e,t),n.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 n=i.key;if(ee(i.valueType,!1)){let o=e[i.key];typeof o=="string"||typeof o=="number"?r[n]=o:r[n]=this._remult.repo(i.valueType).fromJson(o)}else e[n]!==void 0&&(r[n]=i.valueConverter.fromJson(e[i.key]))}if(this._fixTypes(r),t)return this.create(r);{let i=new ft(this._info,r,this,this._edp,this._remult,!1);return Object.defineProperty(r,Fe,{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(I.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 $(r).delete(),t++;return t}}async findOne(e,t=!1){let r,i,n=e??{};if(n.useCache){let a=ar(n,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({...n,limit:1},t).then(async a=>{let o;return a.length>0&&(o=a[0]),!o&&n.createIfNotFound&&(o=this.create(),n.where&&await Ut(this.metadata,n.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 n=i.key;t[n]=e[n]}this._fixTypes(t)}return(r=this._defaultFindOptions)!=null&&r.where&&(Ut(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,n]of[[String,"string"],[Number,"number"],[Boolean,"boolean"]])t.valueType===i&&typeof r!==n&&(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,n;let t=e??{};(i=this._defaultFindOptions)!=null&&i.where&&(t={$and:[t,(n=this._defaultFindOptions)==null?void 0:n.where]}),this._dataProvider.isProxy||(this.metadata.options.backendPreprocessFilter&&(t=await this.metadata.options.backendPreprocessFilter(t,{metadata:this.metadata,getFilterPreciseValues:a=>I.getPreciseValues(this.metadata,a||t)})),this.metadata.options.backendPrefilter&&(t={$and:[t,await I.resolve(this.metadata.options.backendPrefilter)]}));let r=await I.fromEntityFilter(this.metadata,t);return r&&!this._dataProvider.isProxy&&(r=await I.translateCustomWhere(r,this.metadata,this._remult)),r}}function wn(s,e){let t=v.columnsOfType.get(s);t||v.columnsOfType.set(s,t=[]);let r=ee(s)(e),i=Rs(s),n=Object.getPrototypeOf(s);for(;n!=null;){let a=v.columnsOfType.get(n);a&&t.unshift(...a.filter(u=>!t.find(d=>d.key==u.key)));let o=ee(n,!1);if(o){let u=o(e);r={...u,...r};let d=["saving","saved","deleting","deleted","validation"];for(const f of d)if(u[f]&&u[f]!==r[f]){let c=r[f];r[f]=async(h,p)=>{await c(h,p),await u[f](h,p)}}}n=Object.getPrototypeOf(n)}return new In(vi(t,e),r,e,s,i)}class wi{constructor(e,t,r,i,n){l(this,"fieldsMetadata");l(this,"instance");l(this,"remult");l(this,"isNewRow");l(this,"_error");l(this,"_subscribers");l(this,"_isLoading",!1);l(this,"lookups",new Map);l(this,"errors");l(this,"originalValues",{});this.fieldsMetadata=e,this.instance=t,this.remult=r,this.isNewRow=i;{let a=r;a!=null&&a.iAmRemultProxy&&(r=v.remultFactory())}for(const a of e)if(ee(a.valueType,!1)&&r){let u=new Qs(r.repo(a.valueType),!!M(a),a.allowNull);this.lookups.set(a.key,u);let d=t[a.key],f;Object.defineProperty(t,a.key,{get:()=>(this._subscribers&&(this._subscribers.reportObserved(),f||(f=this.fields.find(a.key),f._subscribers||(f._subscribers=new Ye)),f._subscribers.reportObserved()),u.item),set:c=>{var h;u.set(c),(h=this._subscribers)==null||h.reportChanged(),f||(f=this.fields.find(a.key),f._subscribers||(f._subscribers=new Ye)),f._subscribers.reportChanged()},enumerable:!(n!=null&&n.has(a.key))}),u.set(d)}else{const u=M(a);if((u==null?void 0:u.type)==="toOne"){let d=t.hasOwnProperty(a.key),f=t[a.key];i&&!f&&(d=!1),Object.defineProperty(t,a.key,{get:()=>f,set:c=>{if(f=c,c===void 0)return;const h=a.options;if(h.field&&(this.instance[h.field]=u.toRepo.metadata.idMetadata.getId(c)),h.fields){for(const p in h.fields)if(Object.prototype.hasOwnProperty.call(h.fields,p)){const y=h.fields[p];this.instance[y]=c==null?null:c[p]}}},enumerable:!(n!=null&&n.has(a.key))}),d&&(t[a.key]=f)}}}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 Ye;const e=this._subscribers;for(const t of this.fieldsMetadata){let r=ee(t.valueType,!1),i=this.fields.find(t.key);if(i._subscribers=new Ye,!(r&&this.remult||M(t))){let n=this.instance[t.key];Object.defineProperty(this.instance,t.key,{get:()=>(e.reportObserved(),i._subscribers.reportObserved(),n),set:a=>{n=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 Me([...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.label+": "+this.errors[r.key],this.error=e.message;break}}return new hi(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),n;const a=M(r);i?n=i.id:n=this.instance[r.key],a&&e&&!r.allowNull&&n==null&&(a.toRepo.metadata.idMetadata.field.valueType===Number?n=0:n=""),(!a||a.type==="reference")&&(n!==void 0&&(n=r.valueConverter.toJson(n),n!=null&&(n=r.valueConverter.fromJson(JSON.parse(JSON.stringify(n))))),t[r.key]=n)}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 n,a=this.lookups.get(i.key),o=!1;a?e?(n=a.toJson(),o=!0,r[i.key]=n):n=a.id:M(i)&&!e?o=!0:(n=this.instance[i.key],this.remult||n&&ee(n.constructor,!1)&&(n=$(n).getId())),o||(r[i.key]=i.valueConverter.toJson(n))}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 n=this.lookups.get(i.key);n?n.id=e[i.key]:this.instance[i.key]=i.valueConverter.fromJson(e[i.key])}await Me([...this.fields].filter(i=>!M(i.metadata)),i=>i.load())}}class ft extends wi{constructor(t,r,i,n,a,o,u){super(t.fieldsMetadata,r,a,o,u);l(this,"info");l(this,"repo");l(this,"edp");l(this,"_isNew");l(this,"repository");l(this,"metadata");l(this,"_wasDeleted",!1);l(this,"_columns");l(this,"_saving",!1);l(this,"id");l(this,"originalId");if(this.info=t,this.repo=i,this.edp=n,this._isNew=o,this.repository=i,this.metadata=t,o)for(const d of t.fieldsMetadata){const f=d.key;d.options.defaultValue&&r[f]===void 0&&(typeof d.options.defaultValue=="function"?r[f]=d.options.defaultValue(r):r[f]||(r[f]=d.options.defaultValue))}this.info.entityInfo.entityRefInit&&this.info.entityInfo.entityRefInit(this,r),he.entityRefInit&&he.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 Ae?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 Ot(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 n=!1,a=this.buildLifeCycleEvent(()=>n=!0);if(!this.repo._dataProvider.isProxy){for(const c of this.fields)c.metadata.options.saving&&await c.metadata.options.saving(this.instance,c,a);this.info.entityInfo.saving&&await this.info.entityInfo.saving(this.instance,a)}this.__assertValidity();let o=this.copyDataToObject(this.isNew()),u=[];for(const c of this.metadata.fields)if(c.dbReadOnly||t!==void 0&&!t.includes(c.key)){o[c.key]=void 0,u.push(c.key);let h=this.fields.find(c);h.value=h.originalValue}let d,f=this.isNew();try{if((r=this._subscribers)==null||r.reportChanged(),this.isNew())n?d=(d=await this.edp.find({where:await this.getIdFilter()}))[0]:d=await this.edp.insert(o);else{let c={},h=!1;for(const p in o)if(Object.prototype.hasOwnProperty.call(o,p)){const y=o[p];this.fields.find(p).valueChanged()&&!u.includes(p)&&y!==void 0&&(c[p]=y,h=!0)}if(!h)return this.instance;if(n)d=(await this.edp.find({where:await this.getIdFilter()}))[0];else{if(this.id===void 0)throw new Error("Invalid operation, id is undefined");d=await this.edp.update(this.id,c)}}if(d&&await this.loadDataFrom(d),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 c of this.repo.listeners)await((i=c.saved)==null?void 0:i.call(c,this.instance,f));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(c){throw await this.catchSaveErrors(c)}}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 n of this.repo.listeners)await((i=n.deleted)==null?void 0:i.call(n,this.instance));this.repo._remult.liveQueryPublisher.itemChanged(this.repo.metadata.key,[{id:this.getId(),oldId:this.getOriginalId(),deleted:!0}]),this._wasDeleted=!0}catch(n){throw await this.catchSaveErrors(n)}}async loadDataFrom(t,r){for(const i of this.info.fields){let n=this.lookups.get(i.key);n?(n.id=t[i.key],r===void 0?!i.options.lazy&&!M(i)&&await n.waitLoad():r.includes(i)&&await n.waitLoad()):M(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=M(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 Ot(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 $r=Symbol.for("controllerColumns");function vi(s,e){return s.map(t=>fr(t.settings(e),e))}function qr(s,e){const t=e||z;let r=s[$r];if(r||(r=s[Fe]),!r){let i=v.columnsOfType.get(s.constructor);i||v.columnsOfType.set(s.constructor,i=[]);let n=Object.getPrototypeOf(s.constructor);for(;n!=null;){let a=v.columnsOfType.get(n);a&&i.unshift(...a.filter(o=>!i.find(u=>u.key==o.key))),n=Object.getPrototypeOf(n)}s[$r]=r=new vn(vi(i,t).map(a=>new _i(a,void 0,t)),s,t)}return r}class vn extends wi{constructor(t,r,i){super(t,r,i,!1);l(this,"fields");let n=[],a={find:o=>a[typeof o=="string"?o:o.key],[Symbol.iterator]:()=>n[Symbol.iterator](),toArray:()=>n};for(const o of t)n.push(a[o.key]=new Ot(o.options,o,r,void 0,this));this.fields=a}async __performColumnAndEntityValidations(){for(const t of this.fields)t instanceof Ot&&await t.__performValidation()}}class Ot{constructor(e,t,r,i,n){l(this,"settings");l(this,"metadata");l(this,"container");l(this,"helper");l(this,"rowBase");l(this,"_subscribers");l(this,"target");l(this,"entityRef");this.settings=e,this.metadata=t,this.container=r,this.helper=i,this.rowBase=n,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=M(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(n){r.error=n},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 n,a,o;return!((o=(a=(n=r.rowBase)==null?void 0:n.remult)==null?void 0:a.dataProvider)!=null&&o.isProxy)}};if(Array.isArray(this.settings.validate))for(const n of this.settings.validate)t(await n(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 bn={transformLabel:(s,e,t,r)=>t,set transformCaption(s){this.transformLabel=s}};const Qt=v.fieldOptionsEnricher||{enrichFieldOptions:s=>s},_n=v.labelTransformer||(v.labelTransformer=bn);function bi(s,e,t,r){let i;return typeof s=="function"?t&&(i=s(t)):s&&(i=s),i=_n.transformLabel(t,e,i??"",r),i||(e?ci(e):"")}class _i{constructor(e,t,r){l(this,"settings");l(this,"entityDefs");l(this,"remult");l(this,"options");l(this,"target");l(this,"readonly",!1);l(this,"valueConverter");l(this,"allowNull");l(this,"label");l(this,"dbName");l(this,"inputType");l(this,"key");l(this,"isServerExpression",!1);l(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,n)=>{let a=i[n];return typeof a=="function"?(...o)=>{try{return i[n](...o)}catch(u){const d=`${String(n)} failed for value ${o==null?void 0:o[0]}. Error: ${typeof u=="string"?u:u.message}`;throw new hi({message:this.label+": "+d,modelState:{[this.key]:d}})}}: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.label=bi(e.label??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 lr(this,this.entityDefs)}get caption(){return this.label}get dbReadOnly(){return!!this.settings.dbReadOnly}}class In{constructor(e,t,r,i,n){l(this,"entityInfo");l(this,"remult");l(this,"entityType");l(this,"key");l(this,"options");l(this,"fieldsMetadata",[]);l(this,"idMetadata",{getId:e=>{if(e==null)return e;const t=$(e,!1);return t?t.getId():this.idMetadata.field instanceof Ae?this.idMetadata.field.getId(e):e[this.idMetadata.field.key]},field:void 0,get fields(){return this.field instanceof Ae?this.field.fields:[this.field]},createIdInFilter:e=>e.length>0?{$or:e.map(t=>this.idMetadata.getIdFilter($(t).getId()))}:{[this.fields.toArray()[0].key]:[]},isIdField:e=>e.key==this.idMetadata.field.key,getIdFilter:(...e)=>{if(this.idMetadata.field instanceof Ae){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}}});l(this,"fields");l(this,"dbName");l(this,"label");if(this.entityInfo=t,this.remult=r,this.entityType=i,this.key=n,this.options=t,this.options.allowApiCrud!==void 0){let o;typeof this.options.allowApiCrud=="function"?o=(u,d)=>this.options.allowApiCrud(d):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 _i(o,this,r));if(this.fields=a,this.label=bi(t.label??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(u=>this.fields.find(u)):typeof t.id=="function"?t.id(this.fields):Object.keys(t.id).map(u=>this.fields.find(u));Array.isArray(o)?o.length>1?this.idMetadata.field=new Ae(...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=$(e,!1);return t||this.remult.repo(this.entityType).getEntityRef({...e})}getDbName(){return gi(this)}get caption(){return this.label}}function On(...s){return(e,t)=>(s||(s=[]),s.splice(0,0,{valueType:e}),e[dr]=s,e)}function kn(s){var e,t;return((t=(e=s.options)==null?void 0:e.valueConverter)==null?void 0:t.fieldTypeInDb)==="autoincrement"}function Cn(...s){return(e,t)=>{On(r=>{r.valueConverter=kt.get(e),r.displayValue=(i,n)=>(n==null?void 0:n.label)??(n==null?void 0:n.caption),r.validate=(i,n)=>{const a=kt.get(e).getValues();return n.value&&!a.find(o=>o===n.value)&&(n.value=a.find(o=>o.id===n.value.id)||n.value),de.in(a)(i,n)}},...s)(e)}}class kt{constructor(e){l(this,"valueListType");l(this,"byIdMap",new Map);l(this,"values",[]);l(this,"isNumeric",!1);l(this,"fieldTypeInDb");l(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),xr(i,r),this.byIdMap.set(i.id,i),this.values.push(i))}this.isNumeric&&(this.fieldTypeInDb="integer");var t=this.valueListType[dr];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=>{xr(i,""),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=Mr.get(e);return t||(t=new kt(e),Mr.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 Mr=new Map;function xr(s,e){let t=s.label??s.caption;t===void 0&&(t=ci(s.id!==void 0?s.id.toString():e)),s.label===void 0&&(s.label=t),s.caption===void 0&&(s.caption=t)}const dr=Symbol.for("storableMember"),Gt=Symbol.for("fieldOptionalValues");function Ii(s,e){var r;let t={};for(const i of s)if(i)if(typeof i=="function")i(t,e);else{const{validate:n,...a}=i;t.validate=gt(t.validate,n),Object.assign(t,a)}return(r=Qt.enrichFieldOptions)==null||r.call(Qt,t),t}function fr(s,e){if(s.valueType){let i=s.valueType[dr];i&&(s=Ii([...i,s],e))}if(s.valueType==String){let i=s;s.valueConverter||(i.valueConverter=H.String)}if(s.valueType==Number){let i=s;s.valueConverter||(i.valueConverter=H.Number)}if(s.valueType==Date){let i=s;s.valueConverter||(i.valueConverter=H.Date)}if(s.valueType==Boolean){let i=s;i.valueConverter||(i.valueConverter=H.Boolean)}if(!s.valueConverter){if(ee(s.valueType,!1)){let n;s.valueConverter={toDb:a=>a,fromDb:a=>a},s.valueConverter=new Proxy(s.valueConverter,{get(a,o){if(a[o]===void 0&&n===void 0){if(o==="inputType")return"";n=e.repo(s.valueType).metadata.idMetadata.field.valueType===Number;for(const u of["fieldTypeInDb","toJson","fromJson","toDb","fromDb"])a[u]=n?H.Integer[u]:H.String[u]}return a[o]},set(a,o,u,d){return a[o]=u,!0}})}else s.valueConverter=H.Default;return s}s.valueConverter.toJson||(s.valueConverter.toJson=i=>i),s.valueConverter.fromJson||(s.valueConverter.fromJson=i=>i);const t=s.valueConverter.fromJson,r=s.valueConverter.toJson;return s.valueConverter.toDb||(s.valueConverter.toDb=i=>r(i)),s.valueConverter.fromDb||(s.valueConverter.fromDb=i=>t(i)),s.valueConverter.toInput||(s.valueConverter.toInput=i=>r(i)),s.valueConverter.fromInput||(s.valueConverter.fromInput=i=>t(i)),s}class Oi{get _(){return $(this)}save(){return $(this).save()}assign(e){return Ze(this,e),this}delete(){return this._.delete()}isNew(){return this._.isNew()}get $(){return this._.fields}}function Fn(s){return s.metadata?s.metadata:ee(s,!1)?z.repo(s).metadata:s}function An(s){return ee(s,!1)?z.repo(s):s}async function Me(s,e){const t=[];for(let r=0;r<s.length;r++){const i=s[r];t.push(await e(i,r))}return t}const xe=class xe{constructor(e){l(this,"sql");l(this,"wrapIdentifier",e=>e);l(this,"provideMigrationBuilder");l(this,"createdEntities",[]);l(this,"end");this.sql=e,e.wrapIdentifier&&(this.wrapIdentifier=t=>e.wrapIdentifier(t)),Je(e,"provideMigrationBuilder")&&(this.provideMigrationBuilder=t=>e.provideMigrationBuilder(t)),Je(e,"end")&&(this.end=()=>e.end())}static getDb(e){const t=e||z.dataProvider;if(Je(t,"createCommand"))return t;throw"the data provider is not an SqlCommandFactory"}createCommand(){return new Tn(this.sql.createCommand(),xe.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:H.JsonString.toDb,fromDb:H.JsonString.fromDb});return new ki(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 xe({createCommand:()=>{let i=t.createCommand();return{addParameterAndReturnSqlToken:n=>i.param(n),param:n=>i.param(n),execute:async n=>{if(r)throw"can't run a command after the transaction was completed";return i.execute(n)}}},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{[ui]:{buildSql:e}}}static async filterToRaw(e,t,r,i,n){r||(r=new Sn);const a=An(e);var o=new be(r,i||await Ci(a.metadata,n));return o._addWhere=!1,await(await Te(a)._translateWhereToFilter(t)).__applyToConsumer(o),await o.resolveWhere()}};l(xe,"LogToConsole",!1),l(xe,"durationThreshold",0);let Le=xe;const En=new Map([["INSERT","⚪"],["SELECT","🔵"],["UPDATE","🟣"],["DELETE","🟤"],["CREATE","🟩"],["ALTER","🟨"],["DROP","🟥"],["TRUNCATE","⬛"],["GRANT","🟪"],["REVOKE","🟫"]]);class Tn{constructor(e,t){l(this,"origin");l(this,"logToConsole");l(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>=Le.durationThreshold){const n=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(`${En.get(o)||"💢"} (${n.toFixed(3)}) ${a} ${JSON.stringify(this.args)}`)}else typeof this.logToConsole=="function"?this.logToConsole(n,e,this.args):console.info(e+`
3
- `,{arguments:this.args,duration:n})}}return i}catch(r){throw console.error((r.message||"Sql Error")+`:
4
- `,e,{arguments:this.args,error:r}),r}}}class ki{constructor(e,t,r,i){l(this,"entity");l(this,"sql");l(this,"iAmUsed");l(this,"strategy");this.entity=e,this.sql=t,this.iAmUsed=r,this.strategy=i}async init(){let e=await Ci(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 n=new be(i,t);e.__applyToConsumer(n),r+=await n.resolveWhere()}return i.execute(r).then(n=>Number(n.rows[0].count))}async groupBy(e){return await Pn(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+=`
5
- from `+t.$entityName;let n=this.sql.createCommand();if(e){if(e.where){let a=new be(n,t);e.where.__applyToConsumer(a),i+=await a.resolveWhere()}if(e.limit&&(e.orderBy=se.createUniqueSort(this.entity,e.orderBy)),e.orderBy||(e.orderBy=se.createUniqueSort(this.entity,new se)),e.orderBy){let a=!0,o=[];for(const u of e.orderBy.Segments)o.push(u);for(const u of o)a?(i+=" Order By ",a=!1):i+=", ",i+=t.$dbNameOf(u.field),u.isDescending&&(i+=" desc"),this.sql._getSourceSql().orderByNullsFirst&&(u.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 n.execute(i).then(a=>a.rows.map(o=>this.buildResultRow(r,o,a)))}buildResultRow(e,t,r){let i={};for(let n=0;n<e.length;n++){const a=e[n];try{i[a.key]=a.valueConverter.fromDb(t[r.getColumnKeyInResultForIndexInSelect(n)])}catch(o){throw new Error("Failed to load from db:"+a.key+`\r
6
- `+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(),n="update "+r.$entityName+" set ",a=!1;for(const h of this.entity.fields)if(!jr(h,r)){if(t[h.key]!==void 0){let p=h.valueConverter.toDb(t[h.key]);p!==void 0&&(a?n+=", ":a=!0,n+=r.$dbNameOf(h)+" = "+i.param(p))}}const o=this.entity.idMetadata.getIdFilter(e);let u=new be(i,r);I.fromEntityFilter(this.entity,o).__applyToConsumer(u),n+=await u.resolveWhere();let{colKeys:d,select:f}=this.buildSelect(r),c=!0;return this.sql._getSourceSql().doesNotSupportReturningSyntax&&(c=!1),c&&this.sql._getSourceSql().doesNotSupportReturningSyntaxOnlyForUpdate&&(c=!1),c&&(n+=" returning "+f),i.execute(n).then(h=>{var p,y;if((y=(p=this.sql._getSourceSql()).afterMutation)==null||y.call(p),!c)return Jr(this.entity,this,t,e,"update");if(h.rows.length!=1)throw new Error("Failed to update row with id "+e+", rows updated: "+h.rows.length);return this.buildResultRow(d,h.rows[0],h)})}async delete(e){let t=await this.init(),r=this.sql.createCommand(),i=new be(r,t);I.fromEntityFilter(this.entity,this.entity.idMetadata.getIdFilter(e)).__applyToConsumer(i);let n="delete from "+t.$entityName;return n+=await i.resolveWhere(),r.execute(n).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="",n="",a=!1;for(const f of this.entity.fields)if(!jr(f,t)){let c=f.valueConverter.toDb(e[f.key]);c!=null&&(a?(i+=", ",n+=", "):a=!0,i+=t.$dbNameOf(f),n+=r.param(c))}let o=`insert into ${t.$entityName} (${i}) values (${n})`,{colKeys:u,select:d}=this.buildSelect(t);return this.sql._getSourceSql().doesNotSupportReturningSyntax||(o+=" returning "+d),await r.execute(o).then(f=>{var c,h;if((h=(c=this.sql._getSourceSql()).afterMutation)==null||h.call(c),this.sql._getSourceSql().doesNotSupportReturningSyntax)if(kn(this.entity.idMetadata.field)){const p=f.rows[0];if(typeof p!="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(p));return this.find({where:new I(y=>y.isEqualTo(this.entity.idMetadata.field,p))}).then(y=>y[0])}else return Jr(this.entity,this,e,void 0,"insert");return this.buildResultRow(u,f.rows[0],f)})}}l(ki,"LogToConsole",!1);class Sn{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 Jr(s,e,t,r,i){const n=r!==void 0?s.idMetadata.getIdFilter(r):{};return e.find({where:new I(a=>{for(const o of s.idMetadata.fields)a.isEqualTo(o,t[o.key]??n[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 Pn(s,e,t,r,i){let n="select count(*) as count",a="";const o=[];if(o.push((c,h)=>{h[Vs]=Number(c)}),s!=null&&s.group)for(const c of s==null?void 0:s.group)c.isServerExpression||(n+=", "+e.$dbNameOf(c),c.options.sqlExpression&&(n+=" as "+c.key),a==""?a=" group by ":a+=", ",a+=e.$dbNameOf(c)),o.push((h,p)=>{p[c.key]=c.valueConverter.fromDb(h)});for(const c of Ws){const h=s==null?void 0:s[c];if(h)for(const p of h){if(!p.isServerExpression){const g=await e.$dbNameOf(p);n+=`, ${f(c,g)} as ${p.key}_${c}`}const y=p.valueType===Number||c=="distinctCount";o.push((g,m)=>{y&&(g=Number(g)),m[p.key]={...m[p.key],[c]:g}})}}if(n+=`
7
- from `+e.$entityName,s!=null&&s.where){let c=new be(t,e);s==null||s.where.__applyToConsumer(c),n+=await c.resolveWhere()}a&&(n+=a);let u="";if(s!=null&&s.orderBy){for(const c of s==null?void 0:s.orderBy){u==""?u=" order by ":u+=", ";let h=c.field&&await e.$dbNameOf(c.field);switch(c.operation){case"count":h=c.operation+"(*)";break;case void 0:break;default:h=f(c.operation,h)}u+=h,c.isDescending&&(u+=" desc"),r&&(c.isDescending?u+=" nulls last":u+=" nulls first")}u&&(n+=u)}if(s!=null&&s.limit){let c=1;s.page&&(c=s.page),c<1&&(c=1),n+=" "+i(s.limit,(c-1)*s.limit)}const d=await t.execute(n);return d.rows.map(c=>{let h={};return o.forEach((p,y)=>p(c[d.getColumnKeyInResultForIndexInSelect(y)],h)),h});function f(c,h){return c==="distinctCount"?`count (distinct ${h})`:`${c}( ${h} )`}}class be{constructor(e,t){l(this,"r");l(this,"nameProvider");l(this,"where","");l(this,"_addWhere",!0);l(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 be(this.r,this.nameProvider);i._addWhere=!1,r.__applyToConsumer(i);let n=await i.resolveWhere();if(!n)return;n.length>0&&(t.length>0&&(t+=" or "),e.length>1?t+="("+n+")":t+=n)}this.addToWhere("("+t+")")})())}not(e){this.promises.push((async()=>{let t=new be(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 Dn(this.r,this.nameProvider.wrapIdentifier),r=await e.buildSql(t);typeof r!="string"&&(r=t.sql),r&&this.addToWhere("("+r+")")}})())}}class Dn{constructor(e,t){l(this,"r");l(this,"wrapIdentifier");l(this,"sql","");l(this,"param",(e,t)=>(typeof t=="object"&&t.valueConverter.toDb&&(e=t.valueConverter.toDb(e)),this.r.param(e)));l(this,"filterToRaw",async(e,t)=>Le.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 jr(s,e){return s.dbReadOnly||s.isServerExpression||s.options.sqlExpression&&s.dbName!=e.$dbNameOf(s)}async function Ci(s,e){return Rn(s,e,!0)}async function Rn(s,e,t=!1){let r=typeof e=="function"?{wrapIdentifier:e}:e||{};var i=Fn(s);r.wrapIdentifier||(r.wrapIdentifier=z.dataProvider.wrapIdentifier),r.wrapIdentifier||(r.wrapIdentifier=a=>a);const n={$entityName:await gi(i,r.wrapIdentifier),toString:()=>n.$entityName,$dbNameOf:a=>{var o;return typeof a=="string"?o=a:o=a.key,n[o]},wrapIdentifier:r.wrapIdentifier};for(const a of i.fields){let o=await lr(a,i,r.wrapIdentifier,t);a.options.sqlExpression||(typeof r.tableName=="string"?o=r.wrapIdentifier(r.tableName)+"."+o:r.tableName===!0&&(o=n.$entityName+"."+o)),n[a.key]=o}return n}function Fi(s,...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 n=a=>{let o={};for(const d of e)d&&(typeof d=="function"?d(o,a):Object.assign(o,d));let u=Object.getPrototypeOf(t);if(u){let d=ee(u,!1);if(d){let f=d(a);f&&(o={...f,...o})}}return o};return v.allEntities.push(t),un(t,{key:s}),t[ai]=n,t[oi]=s,t}}const Lr=yt(s=>!isNaN(s)&&isFinite(s));class T{static object(...e){return G(void 0,...e)}static json(...e){let t=e;return t.valueConverter&&!t.valueConverter.fieldTypeInDb&&(t.valueConverter.fieldTypeInDb="json"),t.valueType&&!t.valueType.inputType&&(t.valueType.inputType=le.json),G(void 0,{valueConverter:{fieldTypeInDb:"json",inputType:le.json}},...e)}static dateOnly(...e){return G(()=>Date,{valueConverter:H.DateOnly},...e)}static date(...e){return G(()=>Date,...e)}static integer(...e){return G(()=>Number,{valueConverter:H.Integer,validate:Lr},...e)}static autoIncrement(...e){return G(()=>Number,{allowApiUpdate:!1,dbReadOnly:!0,valueConverter:{...H.Integer,fieldTypeInDb:"autoincrement"}},...e)}static number(...e){return G(()=>Number,{validate:Lr},...e)}static createdAt(...e){return G(()=>Date,{allowApiUpdate:!1,saving:(t,r,{isNew:i})=>{i&&(r.value=new Date)}},...e)}static updatedAt(...e){return G(()=>Date,{allowApiUpdate:!1,saving:(t,r)=>{r.value=new Date}},...e)}static uuid(...e){return T.id({idFactory:()=>crypto.randomUUID(),...e})}static get defaultIdFactory(){return v.defaultIdFactory??(v.defaultIdFactory=()=>crypto.randomUUID())}static set defaultIdFactory(e){v.defaultIdFactory=e}static id(e){return G(()=>String,{allowApiUpdate:!1,defaultValue:()=>((e==null?void 0:e.idFactory)??T.defaultIdFactory)(),saving:(t,r)=>{if(!r.value){let i=(e==null?void 0:e.idFactory)??T.defaultIdFactory;r.value=i()}},...e})}static literal(e,...t){return T.string({validate:(r,i)=>de.in(e())(r,i),[Gt]:e},...t)}static enum(e,...t){let r;return G(()=>e(),{validate:(i,n)=>de.enum(e())(i,n),[Gt]:()=>mt(e())},...t,i=>{if(i[Gt]=()=>mt(e()),r===void 0){let n=e();r=mt(n).find(o=>typeof o=="string")?H.String:H.Integer}i.valueConverter?i.valueConverter.fieldTypeInDb||(i.valueConverter.fieldTypeInDb=r.fieldTypeInDb):i.valueConverter=r})}static string(...e){return G(()=>String,...e)}static boolean(...e){return G(()=>Boolean,...e)}}class Dt{static toOne(e,t){let r=typeof t=="string"?{field:t}:t||{};return!r.field&&!r.fields&&!r.findOptions?G(e,{...r,...Lt(e,"reference")}):G(()=>{},{...r,serverExpression:()=>{},...Lt(e,"toOne")})}static toMany(e,t){return G(()=>{},{...typeof t=="string"?{field:t}:t,serverExpression:()=>{},...Lt(e,"toMany")})}}function G(s,...e){return(t,r,i)=>{const n=typeof r=="string"?r:r.name.toString();let a=d=>{let f=Ii(e,d);if(f.required&&(f.validate=gt(f.validate,de.required,!0)),Je(f,"maxLength")){let h=f;h.maxLength&&(h.validate=gt(h.validate,de.maxLength(h.maxLength)))}if(Je(f,"minLength")){let h=f;h.minLength&&(h.validate=gt(h.validate,de.minLength(h.minLength)))}!f.valueType&&s&&(f.valueType=s()),f.key||(f.key=n),f.dbName||(f.dbName=f.key);let c=f.valueType;return c||(c=void 0,f.valueType=c),f.target||(f.target=t),f};Ai(t);let o=v.columnsOfType.get(t.constructor);o||(o=[],v.columnsOfType.set(t.constructor,o));let u=o.find(d=>d.key==n);if(!u)o.push({key:n,settings:a});else{let d=u.settings;u.settings=f=>{let c=d(f),h=a(f);return Object.assign(c,h)}}}}function Ai(s){if(!s)throw new Error("Set the 'experimentalDecorators:true' option in your 'tsconfig' or 'jsconfig' (target undefined)")}function Nn(s,e,t,r){var i=arguments.length,n=i<3?e:r===null?r=Object.getOwnPropertyDescriptor(e,t):r,a;if(typeof Reflect=="object"&&typeof Reflect.decorate=="function")n=Reflect.decorate(s,e,t,r);else for(var o=s.length-1;o>=0;o--)(a=s[o])&&(n=(i<3?a(n):i>3?a(e,t,n):a(e,t))||n);return i>3&&n&&Object.defineProperty(e,t,n),n}function $n(s,e){if(typeof Reflect=="object"&&typeof Reflect.metadata=="function")return Reflect.metadata(s,e)}class Ct extends Oi{constructor(){super(...arguments);l(this,"id")}}Nn([T.id(),$n("design:type",String)],Ct.prototype,"id",void 0);const Ft=class Ft{constructor(e,t,r){l(this,"actionUrl");l(this,"queue");l(this,"allowed");l(this,"doWork");this.actionUrl=e,this.queue=t,this.allowed=r}async run(e,t,r){t===void 0&&(t=z.apiClient.url),r||(r=je(z.apiClient.httpClient));let i=await r.post(t+"/"+this.actionUrl,e),n=i;if(n&&n.queuedJobId){let a=v.actionInfo.startBusyWithProgress();try{let o;if(await v.actionInfo.runActionWithoutBlockingUI(async()=>{for(;!o||!o.done;)o&&await new Promise(u=>setTimeout(()=>{u(void 0)},200)),o=await r.post(t+"/"+Ft.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 n=await this.execute(t,r,i);i.success(n)}catch(a){a.isForbiddenError?i.forbidden():i.error(a,void 0)}})}};l(Ft,"apiUrlForJobStatus","jobStatusInQueue");let nt=Ft;class rr extends Error{constructor(t="Forbidden"){super(t);l(this,"isForbiddenError",!0)}}class qn extends nt{constructor(t,r,i,n){super(t,i.queue??!1,i.allowed);l(this,"types");l(this,"options");l(this,"originalMethod");this.types=r,this.options=i,this.originalMethod=n}async execute(t,r,i){let n={data:{}},a=r.dataProvider;return await Si(r,this.options,async()=>{if(!r.isAllowedForInstance(void 0,this.options.allowed))throw new rr;t.args=await Ti(this.types(),t.args,r,a,i);try{n.data=await this.originalMethod(t.args)}catch(o){throw o}}),n}}function we(s){return(e,t,r)=>{const i=typeof t=="string"?t:t.name.toString(),n=r?r.value:e;let a=n;Ai(e);function o(){var f=[];return s.paramTypes&&(f=typeof s.paramTypes=="function"?s.paramTypes():s.paramTypes),f}if(e.prototype!==void 0){let f=new qn((s!=null&&s.apiPrefix?s.apiPrefix+"/":"")+i,()=>o(),s,c=>n.apply(void 0,c));return f.doWork=async(c,h,p,y)=>(c=Ur(o(),c),s.blockUser===!1?await v.actionInfo.runActionWithoutBlockingUI(async()=>(await f.run({args:c},p,y)).data):(await f.run({args:c},p,y)).data),a=async function(...c){return st()?await n.apply(this,c):await f.doWork(c,void 0)},Br(e,a),a[tr]=f,r?(r.value=a,r):a}let u=v.classHelpers.get(e.constructor);u||(u=new mi,v.classHelpers.set(e.constructor,u));let d={__register(f){let c=new he;for(const h of u.classes.keys()){let p=u.classes.get(h);p.key||(p.key=c.repo(h).metadata.key),f(p.key+"/"+(s!=null&&s.apiPrefix?s.apiPrefix+"/":"")+i,s?s.queue??!1:!1,s.allowed,async(y,g,m)=>{y.args=y.args.map(w=>Ei(w)?void 0:w);let O=s.allowed;try{let w=g,C;await Si(w,s,async()=>{if(y.args=await Ti(o(),y.args,w,w.dataProvider,m),v.allEntities.includes(h)){let k=w.repo(h),_;const b=y.rowInfo;if(b.isNewRow)_=k.create(),await k.getEntityRef(_)._updateEntityBasedOnApi(b.data);else{let q=await k.find({where:{...k.metadata.idMetadata.getIdFilter(b.id),$and:[k.metadata.options.apiPrefilter??{}]}});if(q.length!=1)throw new Error("not found or too many matches");_=q[0],await k.getEntityRef(_)._updateEntityBasedOnApi(b.data)}if(!w.isAllowedForInstance(_,O))throw new rr;let F=$(_);await F.__validateEntity();try{C={result:await n.apply(_,y.args),rowInfo:{data:await F.toApiJson(),isNewRow:F.isNew(),wasChanged:F.wasChanged(),id:F.getOriginalId()}}}catch(q){throw F.catchSaveErrors(q)}}else{let k=new h(w,w.dataProvider),_=qr(k,w);if(await _._updateEntityBasedOnApi(y.fields),!w.isAllowedForInstance(k,O))throw new rr;await _.__validateEntity();try{C={result:await n.apply(k,y.args),fields:await _.toApiJson()}}catch(b){throw _.catchSaveErrors(b)}}}),m.success(C)}catch(w){w.isForbiddenError?m.forbidden():m.error(w,void 0)}})}},doWork:async function(f,c,h,p){if(f=Ur(o(),f),v.allEntities.includes(e.constructor)){let y=$(c);await y.__validateEntity();let g=u.classes.get(c.constructor);g.key||(g.key=y.repository.metadata.key+"_methods");try{let m=await new class extends nt{constructor(){super(...arguments);l(this,"execute")}}(g.key+"/"+(s!=null&&s.apiPrefix?s.apiPrefix+"/":"")+i,(s==null?void 0:s.queue)??!1,s.allowed).run({args:f,rowInfo:{data:await y.toApiJson(),isNewRow:y.isNew(),wasChanged:y.wasChanged(),id:y.getOriginalId()}},h,p);return await y._updateEntityBasedOnApi(m.rowInfo.data,!0),m.result}catch(m){throw y.catchSaveErrors(m)}}else{let y=qr(c,void 0);try{await y.__validateEntity();let g=await new class extends nt{constructor(){super(...arguments);l(this,"execute")}}(u.classes.get(c.constructor).key+"/"+(s!=null&&s.apiPrefix?s.apiPrefix+"/":"")+i,(s==null?void 0:s.queue)??!1,s.allowed).run({args:f,fields:await y.toApiJson()},h,p);return await y._updateEntityBasedOnApi(g.fields),g.result}catch(g){throw y.catchSaveErrors(g)}}}};return a=async function(...f){let c=this;return st()?await n.apply(c,f):d.doWork(f,c)},Br(e.constructor,a),a[tr]=d,r?(r.value=a,r):a}}const Mn={_isUndefined:!0};function Br(s,e){(s[Wr]||(s[Wr]=[])).push(e),v.actionInfo.allActions.push(e)}function Ei(s){return s&&s._isUndefined}class Vr{constructor(e){l(this,"res");this.res=e}progress(e){this.res.progress(e)}}function Ur(s,e){if(s)for(let t=0;t<s.length;t++){const r=s[t];for(const i of[he,Le])(e[t]instanceof i||r==i)&&(e[t]=void 0);if(e[t]!=null){let i={valueType:r};if(i=fr(i,new he),ee(r,!1)!=null){let a=$(e[t]);e[t]=a.getId()}i.valueConverter&&(e[t]=i.valueConverter.toJson(e[t]))}}return e.map(t=>t!==void 0?t:Mn)}async function Ti(s,e,t,r,i){for(let n=0;n<e.length;n++){const a=e[n];Ei(a)&&(e[n]=void 0)}if(s)for(let n=0;n<s.length;n++)if(e.length<n&&e.push(void 0),s[n]==he||s[n]==he)e[n]=t;else if(s[n]==Le&&r)e[n]=r;else if(s[n]==Vr)e[n]=new Vr(i);else{let a={valueType:s[n]};a=fr(a,t),a.valueConverter&&(e[n]=a.valueConverter.fromJson(e[n])),ee(s[n],!1)!=null&&(e[n]===null||e[n]===void 0||(e[n]=await t.repo(s[n]).findId(e[n])))}return e}const Wr=Symbol.for("classBackendMethodsArray");async function Si(s,e,t){if(e.transactional===void 0||e.transactional===!0)return await fn(s,t);await t(s.dataProvider)}function Pi(s,e){return z.repo(s,e)}v.actionInfo;class xn{constructor(e,t){l(this,"id");l(this,"caption");l(this,"icon");l(this,"where");l(this,"class");l(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)}}const Ue={FF_Role_Admin:"FF_Role.Admin"};var Jn=Object.defineProperty,jn=Object.getOwnPropertyDescriptor,Ie=(s,e,t,r)=>{for(var i=r>1?void 0:r?jn(e,t):e,n=s.length-1,a;n>=0;n--)(a=s[n])&&(i=(r?a(e,t,i):a(i))||i);return r&&i&&Jn(e,t,i),i};const Ln={ChangeLog_Admin:"ChangeLog.Admin"};let fe=class{constructor(){l(this,"id","");l(this,"entity","");l(this,"entityId","");l(this,"changeDate",new Date);l(this,"userId","");l(this,"changes",[]);l(this,"newRow",!1);l(this,"deleted",!1)}};Ie([T.id()],fe.prototype,"id",2);Ie([T.string()],fe.prototype,"entity",2);Ie([T.string()],fe.prototype,"entityId",2);Ie([T.date()],fe.prototype,"changeDate",2);Ie([T.string()],fe.prototype,"userId",2);Ie([T.json({dbName:"changesJson"})],fe.prototype,"changes",2);Ie([T.boolean()],fe.prototype,"newRow",2);Ie([T.boolean()],fe.prototype,"deleted",2);fe=Ie([Fi("_ff_change_logs",{caption:"FF Change Logs",allowApiCrud:Ln.ChangeLog_Admin,defaultOrderBy:{changeDate:"desc"}})],fe);async function Bn(s,e,t){var r;if(st()){const i=[],n=new Di(s,t),a=(t==null?void 0:t.forceNew)||e.isNew,o=(t==null?void 0:t.forceDate)||new Date;for(const u of n.fields.filter(d=>d.valueChanged()||a&&d.value))try{const d=n.excludedValues.includes(u);i.push({key:u.metadata.key,newValue:d?"***":u.value instanceof Ct?u.value.id:u.metadata.options.valueConverter.toJson(u.value),oldValue:e.isNew?"---":d?"***":u.originalValue instanceof Ct?u.originalValue.id:u.metadata.options.valueConverter.toJson(u.originalValue)})}catch(d){throw console.error(u),d}i.length>0&&await Pi(fe).insert({changeDate:o,changes:i,entity:e.metadata.key,entityId:e.metadata.idMetadata.getId(s),userId:((r=z.user)==null?void 0:r.id)||"",newRow:a})}}async function Vn(s,e,t){var a;const r=[],i=new Di(s,t),n=(t==null?void 0:t.forceDate)||new Date;for(const o of i.fields)try{const u=i.excludedValues.includes(o);r.push({key:o.metadata.key,newValue:u?"***":"---",oldValue:u?"***":o.originalValue instanceof Ct?o.originalValue.id:o.metadata.options.valueConverter.toJson(o.originalValue)})}catch(u){throw console.error(o),u}await Pi(fe).insert({changeDate:n,changes:r,entity:e.metadata.key,entityId:e.metadata.idMetadata.getId(s),userId:((a=z.user)==null?void 0:a.id)||"",deleted:!0})}class Di{constructor(e,t){l(this,"fields");l(this,"excludedFields");l(this,"excludedValues");const r=$(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 Un=s=>({...s,saved:async(e,t)=>{var r;await((r=s==null?void 0:s.saved)==null?void 0:r.call(s,e,t)),(s==null?void 0:s.changeLog)===!1||st()&&await Bn(e,t,s==null?void 0:s.changeLog)},deleted:async(e,t)=>{var r;await((r=s==null?void 0:s.deleted)==null?void 0:r.call(s,e,t)),(s==null?void 0:s.changeLog)===!1||st()&&await Vn(e,t,s==null?void 0:s.changeLog)}}),Xe=s=>{if(s)return Array.isArray(s)?s.map(e=>e.id):s.id};function cr(s,e){return Fi(s,Un({...e,allowApiCrud:(e==null?void 0:e.allowApiCrud)??Xe(e==null?void 0:e.permissionApiCrud),allowApiDelete:(e==null?void 0:e.allowApiDelete)??Xe(e==null?void 0:e.permissionApiDelete),allowApiInsert:(e==null?void 0:e.allowApiInsert)??Xe(e==null?void 0:e.permissionApiInsert),allowApiRead:(e==null?void 0:e.allowApiRead)??Xe(e==null?void 0:e.permissionApiRead),allowApiUpdate:(e==null?void 0:e.allowApiUpdate)??Xe(e==null?void 0:e.permissionApiUpdate)}))}var Ri=Object.defineProperty,Wn=Object.getOwnPropertyDescriptor,Qn=(s,e,t)=>e in s?Ri(s,e,{enumerable:!0,configurable:!0,writable:!0,value:t}):s[e]=t,N=(s,e,t,r)=>{for(var i=r>1?void 0:r?Wn(e,t):e,n=s.length-1,a;n>=0;n--)(a=s[n])&&(i=(r?a(e,t,i):a(i))||i);return r&&i&&Ri(e,t,i),i},Rt=(s,e,t)=>Qn(s,typeof e!="symbol"?e+"":e,t);const Re={FF_Role_Auth_Admin:"FF_Role_Auth.Admin",FF_Role_Auth_Invite:"FF_Role_Auth.Invite"};let pe=class{constructor(){l(this,"id");l(this,"createdAt");l(this,"updatedAt");l(this,"name");l(this,"roles",[]);l(this,"accounts");l(this,"sessions")}};N([T.id()],pe.prototype,"id",2);N([T.createdAt({includeInApi:[Re.FF_Role_Auth_Admin,Ue.FF_Role_Admin]})],pe.prototype,"createdAt",2);N([T.updatedAt({includeInApi:[Re.FF_Role_Auth_Admin,Ue.FF_Role_Admin]})],pe.prototype,"updatedAt",2);N([T.string({required:!0,validate:[de.unique(),de.required()]})],pe.prototype,"name",2);N([T.json(()=>[],{includeInApi:[Re.FF_Role_Auth_Admin,Ue.FF_Role_Admin],inputType:"selectEnum",valueConverter:{toDb:s=>s===null?null:Array.isArray(s)?s.join(","):s,fromDb:s=>s?s.split(",").map(e=>e.replace("{","").replace("}","")).filter(e=>e!==""):[]}})],pe.prototype,"roles",2);N([Dt.toMany(()=>X,"userId")],pe.prototype,"accounts",2);N([Dt.toMany(()=>Pe,"userId")],pe.prototype,"sessions",2);pe=N([cr("ff_auth.users",{allowApiCrud:[Re.FF_Role_Auth_Admin,Ue.FF_Role_Admin],caption:"FF Auth - Users"})],pe);let X=class{constructor(){l(this,"id");l(this,"createdAt");l(this,"updatedAt");l(this,"userId");l(this,"user");l(this,"provider",ye.PASSWORD.id);l(this,"providerUserId","");l(this,"email",null);l(this,"hashPassword");l(this,"token");l(this,"expiresAt");l(this,"lastVerifiedAt");l(this,"metadata")}};N([T.id()],X.prototype,"id",2);N([T.createdAt()],X.prototype,"createdAt",2);N([T.updatedAt()],X.prototype,"updatedAt",2);N([T.string()],X.prototype,"userId",2);N([Dt.toOne(()=>pe,"userId")],X.prototype,"user",2);N([T.string()],X.prototype,"provider",2);N([T.string()],X.prototype,"providerUserId",2);N([T.string({allowNull:!0})],X.prototype,"email",2);N([T.string({includeInApi:!1,allowNull:!0})],X.prototype,"hashPassword",2);N([T.string({includeInApi:!1,allowNull:!0})],X.prototype,"token",2);N([T.date({includeInApi:!1,allowNull:!0})],X.prototype,"expiresAt",2);N([T.date({includeInApi:!1,allowNull:!0})],X.prototype,"lastVerifiedAt",2);N([T.json({includeInApi:!1,allowNull:!0})],X.prototype,"metadata",2);X=N([cr("ff_auth.accounts",{allowApiCrud:[Re.FF_Role_Auth_Admin,Ue.FF_Role_Admin],caption:"FF Auth - Accounts",changeLog:{excludeColumns:s=>[s.hashPassword,s.token]}})],X);let Pe=class{constructor(){l(this,"id");l(this,"expiresAt");l(this,"userId");l(this,"user")}};N([T.string()],Pe.prototype,"id",2);N([T.date()],Pe.prototype,"expiresAt",2);N([T.string()],Pe.prototype,"userId",2);N([Dt.toOne(()=>pe,"userId")],Pe.prototype,"user",2);Pe=N([cr("ff_auth.users_sessions",{allowApiCrud:[Re.FF_Role_Auth_Admin,Ue.FF_Role_Admin],caption:"FF Auth - Users sessions",changeLog:!1})],Pe);let ye=class extends xn{constructor(s,e){super(s,{...e})}};Rt(ye,"DEMO",new ye("DEMO",{caption:"Demo"}));Rt(ye,"PASSWORD",new ye("PASSWORD",{caption:"Password"}));Rt(ye,"OTP",new ye("OTP",{caption:"TOTP"}));Rt(ye,"OAUTH",new ye("OAUTH",{caption:"OAUTH"}));ye=N([Cn()],ye);var Gn=Object.defineProperty,Kn=Object.getOwnPropertyDescriptor,ve=(s,e,t,r)=>{for(var i=Kn(e,t),n=s.length-1,a;n>=0;n--)(a=s[n])&&(i=a(e,t,i)||i);return i&&Gn(e,t,i),i},K,re;const me=(K=class{static _setAbstraction(e){wr(this,re,e)}static async signOut(){return await ce(K,re).signOut()}static async signInDemo(e){return await ce(K,re).signInDemo(e)}static async invite(e){return await ce(K,re).invite(e)}static async signUpPassword(e,t){return await ce(K,re).signUpPassword(e,t)}static async signInPassword(e,t){return await ce(K,re).signInPassword(e,t)}static async forgotPassword(e){return await ce(K,re).forgotPassword(e)}static async resetPassword(e,t){return await ce(K,re).resetPassword(e,t)}static async signInOTP(e){return await ce(K,re).signInOTP(e)}static async verifyOtp(e,t){return await ce(K,re).verifyOtp(e,t)}static async signInOAuthGetUrl(e){return await ce(K,re).signInOAuthGetUrl(e)}},re=new WeakMap,gr(K,re),K);ve([we({allowed:!0})],me,"signOut");ve([we({allowed:!0})],me,"signInDemo");ve([we({allowed:Re.FF_Role_Auth_Invite})],me,"invite");ve([we({allowed:!0})],me,"signUpPassword");ve([we({allowed:!0})],me,"signInPassword");ve([we({allowed:!0})],me,"forgotPassword");ve([we({allowed:!0})],me,"resetPassword");ve([we({allowed:!0})],me,"signInOTP");ve([we({allowed:!0})],me,"verifyOtp");ve([we({allowed:!0})],me,"signInOAuthGetUrl");let ot=me;function _e(s){s.focus()}var Hn=B('<div class="login"><p> </p> <form class="svelte-skcj83"><input required type="email"/> <button> </button></form></div>');function zn(s,e){ke(e,!1);let t=ne(e,"firstlyDataAuth",8),r=ne(e,"email",12,""),i=Z(""),n=Z(""),a=Z(!1);async function o(){R(i,""),R(n,""),R(a,!0);try{const m=await ot.forgotPassword(r());R(n,m.message??"")}catch(m){m&&R(i,m.message??""),R(a,!1)}}Be();var u=Hn(),d=P(u);let f;var c=P(d),h=S(d,2),p=P(h);Tt(p,m=>_e==null?void 0:_e(m)),De(()=>Se(p,r));var y=S(p,2),g=P(y);ie((m,O)=>{var w,C;f=Ve(d,1,"message",null,f,m),L(c,`${E(i)??""}${E(n)??""}`),ge(p,"placeholder",(w=t().ui)==null?void 0:w.strings.email_placeholder),y.disabled=O,L(g,(C=t().ui)==null?void 0:C.strings.send_password_reset_instructions)},[()=>({error:E(i),success:E(n)}),()=>!r()||!r().includes("@")||!r().includes(".")||E(a)],Et),at("submit",h,St(o)),D(s,u),Ce()}var Xn=(s,e,t)=>e(E(t).name),Yn=B('<div class="oauth-button-icon svelte-1dwkktf"><!></div>'),Zn=B('<button class="oauth-button svelte-1dwkktf"><!> <span> </span></button>'),ea=B('<hr style="margin: 1rem"/> <div class="oauth-container svelte-1dwkktf"></div>',1);function Qr(s,e){ke(e,!0);const t=async a=>{const o=await ot.signInOAuthGetUrl({provider:a,redirect:new URL(window.location.href).searchParams.get("redirect")??"/"});window.location.href=o};var r=rt(),i=ue(r);{var n=a=>{var o=ea(),u=S(ue(o),2);ns(u,21,()=>{var d;return((d=e.firstlyDataAuth)==null?void 0:d.providers)??[]},d=>d.name,(d,f)=>{var c=Zn();c.__click=[Xn,t,f];var h=P(c);{var p=m=>{var O=Yn(),w=P(O);ls(w,()=>E(f).raw_svg),D(m,O)};W(h,m=>{E(f).raw_svg&&m(p)})}var y=S(h,2),g=P(y);ie(()=>L(g,E(f).label)),D(d,c)}),D(a,o)};W(i,a=>{var o;(((o=e.firstlyDataAuth)==null?void 0:o.providers)??[].length!==0)&&a(n)})}D(s,r),Ce()}zr(["click"]);var ta=B('<div class="login"><p> </p> <form class="svelte-skcj83"> <input type="password" required/> <input type="password" required/> <button> </button></form></div>');function ra(s,e){ke(e,!1);let t=ne(e,"firstlyDataAuth",8),r=ne(e,"password1",12,""),i=ne(e,"password2",12,""),n=Z(""),a=Z(""),o=Z(!1);async function u(){R(n,""),R(a,""),R(o,!0);const k=new URL(location.href).searchParams.get("token");try{const _=await ot.resetPassword(k??"",r());R(a,_.message??""),window.location.href="/"}catch(_){_&&R(n,_.message??""),R(o,!1)}}Be();var d=ta(),f=P(d);let c;var h=P(f),p=S(f,2),y=P(p),g=S(y),m=S(g),O=S(m),w=S(O,2),C=P(w);ie(k=>{var _,b,F,q,j;c=Ve(f,1,"message",null,c,k),L(h,`${E(n)??""}${E(a)??""}`),L(y,`${((_=t().ui)==null?void 0:_.strings.password)??""} `),ge(g,"placeholder",(b=t().ui)==null?void 0:b.strings.password_placeholder),L(m,` ${((F=t().ui)==null?void 0:F.strings.confirm)??""} `),ge(O,"placeholder",(q=t().ui)==null?void 0:q.strings.password_placeholder),w.disabled=!r()||!i()||E(o),L(C,(j=t().ui)==null?void 0:j.strings.reset)},[()=>({error:E(n)})],Et),Se(g,r),Se(O,i),at("submit",p,St(u)),D(s,d),Ce()}var ia=B('<form class="svelte-skcj83"><p> </p> <label> <input required type="email"/></label> <label> <input required type="password"/></label> <button> </button></form>');function sa(s,e){ke(e,!1);let t=ne(e,"firstlyDataAuth",8),r=ne(e,"view",8,"login"),i=ne(e,"email",12,""),n=Z(""),a=Z(""),o=Z(),u=Z(!1);async function d(){R(n,""),R(a,""),R(u,!0);try{await ot.signInPassword(i(),E(o)),window.location.href=new URL(window.location.href).searchParams.get("redirect")??"/"}catch(p){p&&R(n,p.message??""),R(u,!1)}}Be();var f=rt(),c=ue(f);{var h=p=>{var y=ia(),g=P(y);let m;var O=P(g),w=S(g,2),C=P(w),k=S(C);De(()=>Se(k,i)),Tt(k,x=>_e==null?void 0:_e(x));var _=S(w,2),b=P(_),F=S(b),q=S(_,2),j=P(q);ie(x=>{var Y,te,ae,V,J;m=Ve(g,1,"message",null,m,x),L(O,`${E(n)??""}${E(a)??""}`),L(C,`${((Y=t().ui)==null?void 0:Y.strings.email)??""} `),ge(k,"placeholder",(te=t().ui)==null?void 0:te.strings.email_placeholder),L(b,`${((ae=t().ui)==null?void 0:ae.strings.password)??""} `),ge(F,"placeholder",(V=t().ui)==null?void 0:V.strings.password_placeholder),q.disabled=!i()||!E(o)||E(u),L(j,(J=t().ui)==null?void 0:J.strings.btn_sign_in)},[()=>({error:E(n)})],Et),Se(F,()=>E(o),x=>R(o,x)),at("submit",y,St(d)),D(p,y)};W(c,p=>{r()=="login"&&p(h)})}D(s,f),Ce()}var na=B('<form class="svelte-skcj83"><p> </p> <label> <input required type="email"/></label> <label> <input required type="password"/></label> <button> </button></form>');function aa(s,e){ke(e,!1);let t=ne(e,"firstlyDataAuth",8),r=ne(e,"view",8,"login"),i=ne(e,"email",12,""),n=Z(""),a=Z(""),o=Z(),u=Z(!1);async function d(){R(n,""),R(a,""),R(u,!0);try{const p=await ot.signUpPassword(i(),E(o));R(a,p.message??""),await new Promise(y=>setTimeout(y,5e3)),window.location.href=new URL(window.location.href).searchParams.get("redirect")??"/"}catch(p){p&&R(n,p.message??""),R(u,!1)}}Be();var f=rt(),c=ue(f);{var h=p=>{var y=na(),g=P(y);let m;var O=P(g),w=S(g,2),C=P(w),k=S(C);De(()=>Se(k,i)),Tt(k,x=>_e==null?void 0:_e(x));var _=S(w,2),b=P(_),F=S(b),q=S(_,2),j=P(q);ie(x=>{var Y,te,ae,V,J;m=Ve(g,1,"message",null,m,x),L(O,`${E(n)??""}${E(a)??""}`),L(C,`${((Y=t().ui)==null?void 0:Y.strings.email)??""} `),ge(k,"placeholder",(te=t().ui)==null?void 0:te.strings.email_placeholder),L(b,`${((ae=t().ui)==null?void 0:ae.strings.password)??""} `),ge(F,"placeholder",(V=t().ui)==null?void 0:V.strings.password_placeholder),q.disabled=!i()||!E(o)||E(u),L(j,(J=t().ui)==null?void 0:J.strings.btn_sign_up)},[()=>({error:E(n)})],Et),Se(F,()=>E(o),x=>R(o,x)),at("submit",y,St(d)),D(p,y)};W(c,p=>{r()=="login"&&p(h)})}D(s,f),Ce()}var oa=B('<h1 class="svelte-1jjivcr"> </h1>'),la=B('<!> <div class="form-footer svelte-1jjivcr"><!></div> <!>',1),ua=B("<hr/> <!>",1),da=B('<!> <div class="form-footer svelte-1jjivcr"><!> <!></div> <!>',1),fa=B('<!> <div class="form-footer svelte-1jjivcr"><!></div>',1),ca=B('<!> <div class="form-footer svelte-1jjivcr"><!></div>',1),ha=B('<div class="form svelte-1jjivcr"><!> <!> <!> <!> <!></div>'),pa=B('<img alt="Authentication" class="svelte-1jjivcr"/>'),ya=B('<div class="split-layout svelte-1jjivcr"><div class="form-side svelte-1jjivcr"><!></div> <div class="image-side svelte-1jjivcr"><!></div></div>'),ma=B('<div class="centered-layout svelte-1jjivcr"><!></div>'),ga=B('<div class="fallback svelte-1jjivcr"><small>- 404 -</small></div> <div class="fallback svelte-1jjivcr"><small>Nothing to see here</small></div>',1),wa=B("<!> <!>",1),va=B("<div><!></div>");function Oa(s,e){ke(e,!0);const t=d=>{var f=ha(),c=P(f);{var h=_=>{var b=oa(),F=P(b);ie(()=>L(F,r.ui.strings.app_name)),D(_,b)};W(c,_=>{var b;(b=r.ui)!=null&&b.strings.app_name&&_(h)})}var p=S(c,2);{var y=_=>{const b=Qe(()=>{var F;return(F=r.ui)==null?void 0:F.paths.sign_up});Ne(_,{get path(){return E(b)},children:(F,q)=>{var j=la(),x=ue(j);aa(x,{get firstlyDataAuth(){return r},get email(){return E(i)},set email(J){R(i,J,!0)}});var Y=S(x,2),te=P(Y);{var ae=J=>{ze(J,{get href(){return r.ui.paths.sign_in},children:(We,Q)=>{var oe=Ge();ie(()=>L(oe,r.ui.strings.back_to_sign_in)),D(We,oe)},$$slots:{default:!0}})};W(te,J=>{r.ui.paths.sign_in&&J(ae)})}var V=S(Y,2);Qr(V,{get firstlyDataAuth(){return r}}),D(F,j)},$$slots:{default:!0}})};W(p,_=>{var b;(b=r.ui)!=null&&b.paths.sign_up&&_(y)})}var g=S(p,2);{var m=_=>{const b=Qe(()=>{var F;return(F=r.ui)==null?void 0:F.paths.sign_in});Ne(_,{get path(){return E(b)},children:(F,q)=>{var j=da(),x=ue(j);sa(x,{get firstlyDataAuth(){return r},get email(){return E(i)},set email(Q){R(i,Q,!0)}});var Y=S(x,2),te=P(Y);{var ae=Q=>{ze(Q,{get href(){return r.ui.paths.forgot_password},children:(oe,hr)=>{var lt=Ge();ie(()=>L(lt,r.ui.strings.forgot_password)),D(oe,lt)},$$slots:{default:!0}})};W(te,Q=>{var oe;(oe=r.ui)!=null&&oe.paths.forgot_password&&Q(ae)})}var V=S(te,2);{var J=Q=>{var oe=ua(),hr=S(ue(oe),2);ze(hr,{get href(){return r.ui.paths.sign_up},children:(lt,ba)=>{var pr=Ge();ie(()=>L(pr,r.ui.strings.btn_sign_up)),D(lt,pr)},$$slots:{default:!0}}),D(Q,oe)};W(V,Q=>{var oe;(oe=r.ui)!=null&&oe.paths.sign_up&&Q(J)})}var We=S(Y,2);Qr(We,{get firstlyDataAuth(){return r}}),D(F,j)},$$slots:{default:!0}})};W(g,_=>{var b;(b=r.ui)!=null&&b.paths.sign_in&&_(m)})}var O=S(g,2);{var w=_=>{const b=Qe(()=>{var F;return(F=r.ui)==null?void 0:F.paths.forgot_password});Ne(_,{get path(){return E(b)},children:(F,q)=>{var j=fa(),x=ue(j);zn(x,{get firstlyDataAuth(){return r},get email(){return E(i)},set email(V){R(i,V,!0)}});var Y=S(x,2),te=P(Y);{var ae=V=>{ze(V,{get href(){return r.ui.paths.sign_in},children:(J,We)=>{var Q=Ge();ie(()=>L(Q,r.ui.strings.back_to_sign_in)),D(J,Q)},$$slots:{default:!0}})};W(te,V=>{var J;(J=r.ui)!=null&&J.paths.sign_in&&V(ae)})}D(F,j)},$$slots:{default:!0}})};W(O,_=>{var b;(b=r.ui)!=null&&b.paths.forgot_password&&_(w)})}var C=S(O,2);{var k=_=>{const b=Qe(()=>{var F;return(F=r.ui)==null?void 0:F.paths.reset_password});Ne(_,{get path(){return E(b)},children:(F,q)=>{var j=ca(),x=ue(j);ra(x,{get firstlyDataAuth(){return r}});var Y=S(x,2),te=P(Y);{var ae=V=>{ze(V,{get href(){return r.ui.paths.sign_in},children:(J,We)=>{var Q=Ge();ie(()=>L(Q,r.ui.strings.back_to_sign_in)),D(J,Q)},$$slots:{default:!0}})};W(te,V=>{var J;(J=r.ui)!=null&&J.paths.sign_in&&V(ae)})}D(F,j)},$$slots:{default:!0}})};W(C,_=>{var b;(b=r.ui)!=null&&b.paths.reset_password&&_(k)})}D(d,f)};let r=e.firstlyData.props,i=as(""),n=Qe(()=>{var d,f;return!!((f=(d=r.ui)==null?void 0:d.images)!=null&&f.main)});var a=va();let o;var u=P(a);Ne(u,{children:(d,f)=>{var c=wa(),h=ue(c);{var p=m=>{var O=ya(),w=P(O),C=P(w);t(C);var k=S(w,2),_=P(k);{var b=F=>{var q=pa();ie(()=>ge(q,"src",r.ui.images.main)),D(F,q)};W(_,F=>{var q,j;(j=(q=r.ui)==null?void 0:q.images)!=null&&j.main&&F(b)})}D(m,O)},y=m=>{var O=ma(),w=P(O);t(w),D(m,O)};W(h,m=>{E(n)?m(p):m(y,!1)})}var g=S(h,2);Ne(g,{fallback:!0,children:(m,O)=>{var w=ga();D(m,w)},$$slots:{default:!0}}),D(d,c)},$$slots:{default:!0}}),ie(d=>o=Ve(a,1,"wrapper svelte-1jjivcr",null,o,d),[()=>({"with-image":E(n)})]),D(s,a),Ce()}export{Oa as default};
@@ -1,2 +0,0 @@
1
- export { f as default };
2
- declare function f(a: any): void;
@@ -1 +0,0 @@
1
- import{a9 as e,T as o}from"./index-D38rqu4x.js";function f(a){var t=e("Hello from admin");o(a,t)}export{f as default};
@@ -1,201 +0,0 @@
1
- declare function se(e: any, t?: boolean, n?: boolean): {
2
- f: number;
3
- v: any;
4
- reactions: null;
5
- equals: typeof Yt;
6
- rv: number;
7
- wv: number;
8
- };
9
- declare const ei: "@attach";
10
- declare function Br(e: any, t?: () => void): {
11
- set: (s: any) => void;
12
- update: (s: any) => void;
13
- subscribe: (s: any, a?: () => void) => () => void;
14
- };
15
- declare function Ur(e: any): undefined;
16
- declare function Vr(e: any, t: any): {
17
- subscribe: (s: any, a?: () => void) => () => void;
18
- };
19
- declare function pi(e: any, t: any, n: any): {
20
- subscribe: (s: any, a?: () => void) => () => void;
21
- };
22
- declare function zt(e: any, t: boolean | undefined, n: any): void;
23
- declare function ri(e: any): any;
24
- declare function En(e: any, t: any, n: any, r: any): (S: any, O: any, ...args: any[]) => any;
25
- declare function ti(e: any): any;
26
- declare function wi(e: any): void;
27
- declare function ni(e: any, t: any): any;
28
- declare const Jr: unique symbol;
29
- declare function li(e: any, t: any): void;
30
- declare const Qr: "http://www.w3.org/1999/xhtml";
31
- declare function fi(): void;
32
- declare function qr(e?: boolean): void;
33
- declare function Pr(): DocumentFragment;
34
- declare function Ke(e: any, t: any): any;
35
- declare function Rt(e: any, t: any, [n, r]?: [number, number]): void;
36
- declare function Pe(e: any, t: any): void;
37
- declare function Zt(e: any): {};
38
- declare function gi(): {}[];
39
- declare function hi(e: any, t: any, n: any): any;
40
- declare function mi(e: any, t: any): any;
41
- declare function gr(e: any): void;
42
- declare function bi(e: any, t: any): any;
43
- declare function L(e: any, t: any, n?: boolean): any;
44
- declare let y: null;
45
- declare function ht(e: any, t: any): () => any;
46
- declare function Ot(e: any, t: any): any;
47
- declare function Ar(e: any, t: any, n: any, r: any, u: any): void;
48
- declare function Ct(e: any, t?: number, n?: boolean): any;
49
- declare function he(e: any): {
50
- ctx: any;
51
- deps: null;
52
- effects: null;
53
- equals: typeof Yt;
54
- f: number;
55
- fn: any;
56
- reactions: null;
57
- rv: number;
58
- v: null;
59
- wv: number;
60
- parent: any;
61
- };
62
- declare function Lt(e: any, t: any): void;
63
- declare function Rr(e: any, t: any, n: any, r: any, u: any, i?: null): void;
64
- declare function ui(e: any): {
65
- ctx: any;
66
- deps: null;
67
- effects: null;
68
- equals: typeof Yt;
69
- f: number;
70
- fn: any;
71
- reactions: null;
72
- rv: number;
73
- v: null;
74
- wv: number;
75
- parent: any;
76
- };
77
- declare function $(e: any, t: any): {
78
- f: number;
79
- v: any;
80
- reactions: null;
81
- equals: typeof Yt;
82
- rv: number;
83
- wv: number;
84
- };
85
- declare function di(e?: string): Text;
86
- declare function ke(e: any, t: any): void;
87
- declare function Sr(e: any): DocumentFragment;
88
- declare function Ve(e: any, t?: number): {
89
- ctx: any;
90
- deps: null;
91
- nodes_start: null;
92
- nodes_end: null;
93
- f: number;
94
- first: null;
95
- fn: any;
96
- last: null;
97
- next: null;
98
- parent: any;
99
- prev: null;
100
- teardown: null;
101
- transitions: null;
102
- wv: number;
103
- };
104
- declare function ln(e: any): {
105
- ctx: any;
106
- deps: null;
107
- nodes_start: null;
108
- nodes_end: null;
109
- f: number;
110
- first: null;
111
- fn: any;
112
- last: null;
113
- next: null;
114
- parent: any;
115
- prev: null;
116
- teardown: null;
117
- transitions: null;
118
- wv: number;
119
- };
120
- declare function Z(e: any, t?: boolean): void;
121
- declare function Ne(e: any): any;
122
- declare function ae(e: any, t?: boolean): {
123
- ctx: any;
124
- deps: null;
125
- nodes_start: null;
126
- nodes_end: null;
127
- f: number;
128
- first: null;
129
- fn: any;
130
- last: null;
131
- next: null;
132
- parent: any;
133
- prev: null;
134
- teardown: null;
135
- transitions: null;
136
- wv: number;
137
- };
138
- declare var nt: (arg: any) => arg is any[];
139
- declare function ii(e: any, t: any): boolean;
140
- declare function fe(e: any): {
141
- ctx: any;
142
- deps: null;
143
- effects: null;
144
- equals: typeof Yt;
145
- f: number;
146
- fn: any;
147
- reactions: null;
148
- rv: number;
149
- v: null;
150
- wv: number;
151
- parent: any;
152
- };
153
- declare function T(e: any): any;
154
- declare function si(e: any): any;
155
- declare function Tr(e: any, t: any, n: any, r?: {}): (i: any) => any;
156
- declare function _i(e: any): void;
157
- declare function ci(e: any, t: any): void;
158
- declare function oi(e: any): any;
159
- declare function fr(e: any, t: any): void;
160
- declare var Ut: (o: any) => any;
161
- declare function It(e: any, t?: any[], n?: typeof fe): {
162
- ctx: any;
163
- deps: null;
164
- nodes_start: null;
165
- nodes_end: null;
166
- f: number;
167
- first: null;
168
- fn: any;
169
- last: null;
170
- next: null;
171
- parent: any;
172
- prev: null;
173
- teardown: null;
174
- transitions: null;
175
- wv: number;
176
- };
177
- declare function ee(e: any): any;
178
- declare function ai(e: any): boolean;
179
- declare var Sn: <T>(o: T) => { [P in keyof T]: TypedPropertyDescriptor<T[P]>; } & {
180
- [x: string]: PropertyDescriptor;
181
- };
182
- declare function Te(): boolean;
183
- declare function vi(e: any, t: any, n: any, r?: any): void;
184
- declare function dt(e: any): {
185
- ctx: any;
186
- deps: null;
187
- nodes_start: null;
188
- nodes_end: null;
189
- f: number;
190
- first: null;
191
- fn: any;
192
- last: null;
193
- next: null;
194
- parent: any;
195
- prev: null;
196
- teardown: null;
197
- transitions: null;
198
- wv: number;
199
- };
200
- declare function Yt(e: any): boolean;
201
- export { se as $, ei as A, Br as B, Ur as C, Vr as D, pi as E, zt as F, ri as G, En as H, ti as I, wi as J, ni as K, Jr as L, li as M, Qr as N, fi as O, qr as P, Pr as Q, Ke as R, Rt as S, Pe as T, Zt as U, gi as V, hi as W, mi as X, gr as Y, bi as Z, L as _, y as a, ht as a0, Ot as a1, Ar as a2, Ct as a3, he as a4, Lt as a5, Rr as a6, ui as a7, $ as a8, di as a9, ke as b, Sr as c, Ve as d, ln as e, Z as f, Ne as g, ae as h, nt as i, ii as j, fe as k, T as l, si as m, Tr as n, _i as o, ci as p, oi as q, fr as r, Ut as s, It as t, ee as u, ai as v, Sn as w, Te as x, vi as y, dt as z };