xmlui 0.10.8 → 0.10.11

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 (118) hide show
  1. package/dist/{metadata/apiInterceptorWorker-Bb5-fQup.mjs → lib/apiInterceptorWorker-DPgtUtdA.mjs} +5870 -3195
  2. package/dist/lib/index-BuIblMfO.mjs +50034 -0
  3. package/dist/lib/index.css +1 -1
  4. package/dist/lib/initMock-CV-9AUzP.mjs +843 -0
  5. package/dist/lib/language-server-web-worker.mjs +8 -7
  6. package/dist/lib/language-server.mjs +6 -6
  7. package/dist/lib/{metadata-utils-DrEexTX9.mjs → metadata-utils-DzONZF-e.mjs} +161 -111
  8. package/dist/lib/scss/components-core/theming/_themes.scss +6 -7
  9. package/dist/lib/{server-common-ddmPKhK6.mjs → server-common-Dsyp3-Ro.mjs} +14949 -10880
  10. package/dist/lib/syntax-monaco.mjs +14 -11
  11. package/dist/lib/syntax-textmate.d.ts +2 -2
  12. package/dist/lib/syntax-textmate.mjs +128 -109
  13. package/dist/lib/transform-CBz7TQJh.mjs +7375 -0
  14. package/dist/lib/xmlui-parser.d.ts +3 -3
  15. package/dist/lib/xmlui-parser.mjs +49 -49
  16. package/dist/lib/xmlui-serializer-Bf9bdvlV.mjs +667 -0
  17. package/dist/lib/xmlui.d.ts +16 -11
  18. package/dist/lib/xmlui.mjs +44 -44
  19. package/dist/{lib/apiInterceptorWorker-DH8wqOVq.mjs → metadata/apiInterceptorWorker-BmKP8bnq.mjs} +5432 -3502
  20. package/dist/metadata/collectedComponentMetadata-Cdi6AFD3.mjs +55851 -0
  21. package/dist/metadata/initMock-B7OlSKKb.mjs +843 -0
  22. package/dist/metadata/style.css +1 -1
  23. package/dist/metadata/xmlui-metadata.mjs +3 -3
  24. package/dist/metadata/xmlui-metadata.umd.js +207 -419
  25. package/dist/scripts/package.json +3 -1
  26. package/dist/scripts/src/components/APICall/APICall.js +4 -4
  27. package/dist/scripts/src/components/Accordion/Accordion.js +1 -1
  28. package/dist/scripts/src/components/Accordion/AccordionItemNative.js +2 -2
  29. package/dist/scripts/src/components/Animation/AnimationNative.js +259 -0
  30. package/dist/scripts/src/components/App/App.js +10 -0
  31. package/dist/scripts/src/components/App/AppNative.js +29 -9
  32. package/dist/scripts/src/components/AutoComplete/AutoComplete.js +1 -1
  33. package/dist/scripts/src/components/AutoComplete/AutoCompleteNative.js +5 -4
  34. package/dist/scripts/src/components/Breakout/BreakoutNative.js +2 -2
  35. package/dist/scripts/src/components/Button/Button.js +1 -1
  36. package/dist/scripts/src/components/Button/ButtonNative.js +4 -0
  37. package/dist/scripts/src/components/Carousel/Carousel.js +13 -20
  38. package/dist/scripts/src/components/Carousel/CarouselContext.js +11 -2
  39. package/dist/scripts/src/components/Carousel/CarouselItemNative.js +2 -2
  40. package/dist/scripts/src/components/Carousel/CarouselNative.js +2 -2
  41. package/dist/scripts/src/components/Charts/AreaChart/AreaChart.js +92 -0
  42. package/dist/scripts/src/components/Charts/AreaChart/AreaChartNative.js +127 -0
  43. package/dist/scripts/src/components/Charts/BarChart/BarChart.js +4 -4
  44. package/dist/scripts/src/components/Charts/BarChart/BarChartNative.js +90 -82
  45. package/dist/scripts/src/components/Charts/LineChart/LineChart.js +3 -3
  46. package/dist/scripts/src/components/Charts/LineChart/LineChartNative.js +5 -1
  47. package/dist/scripts/src/components/Charts/RadarChart/RadarChart.js +92 -0
  48. package/dist/scripts/src/components/Charts/RadarChart/RadarChartNative.js +125 -0
  49. package/dist/scripts/src/components/Checkbox/Checkbox.js +2 -1
  50. package/dist/scripts/src/components/ComponentProvider.js +4 -0
  51. package/dist/scripts/src/components/DataSource/DataSource.js +124 -0
  52. package/dist/scripts/src/components/DateInput/DateInput.js +7 -9
  53. package/dist/scripts/src/components/DateInput/DateInputNative.js +101 -38
  54. package/dist/scripts/src/components/DropdownMenu/DropdownMenu.js +1 -1
  55. package/dist/scripts/src/components/ExpandableItem/ExpandableItemNative.js +18 -12
  56. package/dist/scripts/src/components/Footer/Footer.js +1 -1
  57. package/dist/scripts/src/components/FormItem/FormItem.js +1 -1
  58. package/dist/scripts/src/components/FormItem/ItemWithLabel.js +3 -3
  59. package/dist/scripts/src/components/Heading/Heading.js +83 -28
  60. package/dist/scripts/src/components/Heading/HeadingNative.js +10 -1
  61. package/dist/scripts/src/components/HtmlTags/HtmlTags.js +1 -1
  62. package/dist/scripts/src/components/Image/ImageNative.js +13 -0
  63. package/dist/scripts/src/components/Input/PartialInput.js +28 -3
  64. package/dist/scripts/src/components/List/ListNative.js +6 -5
  65. package/dist/scripts/src/components/NavLink/NavLink.js +1 -1
  66. package/dist/scripts/src/components/NavPanel/NavPanelNative.js +3 -8
  67. package/dist/scripts/src/components/NumberBox/NumberBoxNative.js +2 -2
  68. package/dist/scripts/src/components/Option/Option.js +2 -2
  69. package/dist/scripts/src/components/Option/OptionNative.js +12 -1
  70. package/dist/scripts/src/components/Pagination/Pagination.js +2 -1
  71. package/dist/scripts/src/components/RadioGroup/RadioGroup.js +7 -3
  72. package/dist/scripts/src/components/RadioGroup/RadioGroupNative.js +20 -5
  73. package/dist/scripts/src/components/RadioGroup/RadioItemNative.js +2 -1
  74. package/dist/scripts/src/components/Select/Select.js +1 -1
  75. package/dist/scripts/src/components/Select/SelectNative.js +1 -1
  76. package/dist/scripts/src/components/Slider/Slider.js +10 -8
  77. package/dist/scripts/src/components/Slider/SliderNative.js +24 -21
  78. package/dist/scripts/src/components/Switch/Switch.js +2 -1
  79. package/dist/scripts/src/components/Table/Table.js +1 -1
  80. package/dist/scripts/src/components/Table/TableNative.js +18 -13
  81. package/dist/scripts/src/components/TableOfContents/TableOfContents.js +1 -1
  82. package/dist/scripts/src/components/Text/Text.js +32 -14
  83. package/dist/scripts/src/components/Text/TextNative.js +17 -5
  84. package/dist/scripts/src/components/TextArea/TextAreaNative.js +3 -3
  85. package/dist/scripts/src/components/TextBox/TextBoxNative.js +3 -3
  86. package/dist/scripts/src/components/TimeInput/TimeInput.js +10 -10
  87. package/dist/scripts/src/components/TimeInput/TimeInputNative.js +87 -38
  88. package/dist/scripts/src/components/Toggle/Toggle.js +2 -2
  89. package/dist/scripts/src/components/Tooltip/Tooltip.js +9 -9
  90. package/dist/scripts/src/components/Tooltip/TooltipNative.js +4 -4
  91. package/dist/scripts/src/components/abstractions.js +7 -3
  92. package/dist/scripts/src/components/collectedComponentMetadata.js +316 -0
  93. package/dist/scripts/src/components-core/RestApiProxy.js +3 -1
  94. package/dist/scripts/src/components-core/StandaloneApp.js +823 -0
  95. package/dist/scripts/src/components-core/interception/ApiInterceptor.js +4 -1
  96. package/dist/scripts/src/components-core/interception/Backend.js +13 -7
  97. package/dist/scripts/src/components-core/markup-check.js +279 -0
  98. package/dist/scripts/src/components-core/parts.js +0 -4
  99. package/dist/scripts/src/components-core/rendering/ComponentAdapter.js +36 -16
  100. package/dist/scripts/src/components-core/script-runner/eval-tree-async.js +4 -1
  101. package/dist/scripts/src/components-core/script-runner/eval-tree-sync.js +4 -1
  102. package/dist/scripts/src/components-core/theming/themes/root.js +30 -17
  103. package/dist/scripts/src/components-core/theming/transformThemeVars.js +14 -7
  104. package/dist/scripts/src/components-core/xmlui-parser.js +60 -43
  105. package/dist/scripts/src/index.js +120 -0
  106. package/dist/scripts/src/parsers/xmlui-parser/transform.js +15 -4
  107. package/dist/standalone/xmlui-standalone.es.d.ts +23 -15
  108. package/dist/standalone/xmlui-standalone.umd.js +319 -823
  109. package/package.json +3 -1
  110. package/src/syntax/textMate/xmlui.tmLanguage.json +2 -2
  111. package/dist/lib/index-CqzCWOUw.mjs +0 -38579
  112. package/dist/lib/initMock-C5CXs0-5.mjs +0 -568
  113. package/dist/lib/transform-SMWeyMoq.mjs +0 -5391
  114. package/dist/lib/xmlui-serializer-a0O0jFY-.mjs +0 -497
  115. package/dist/metadata/collectedComponentMetadata-DIT5VbaH.mjs +0 -42985
  116. package/dist/metadata/initMock-D6Vi9kU_.mjs +0 -568
  117. package/dist/scripts/src/components-core/ScrollContext.js +0 -11
  118. package/dist/scripts/src/components-core/utils/audio-utils.js +0 -83
@@ -1,568 +0,0 @@
1
- import { delay as D, HttpResponse as g, matchRequestUrl as E } from "msw";
2
- import { isArray as N, isObject as U, mapValues as B } from "lodash-es";
3
- import { r as T, g as M, d as $, m as F, a as O, o as p, T as x } from "./index-CqzCWOUw.mjs";
4
- import q from "dexie";
5
- var A = /* @__PURE__ */ ((e) => (e[e.Continue = 100] = "Continue", e[e.SwitchingProtocols = 101] = "SwitchingProtocols", e[e.Processing = 102] = "Processing", e[e.EarlyHints = 103] = "EarlyHints", e[e.Ok = 200] = "Ok", e[e.Created = 201] = "Created", e[e.Accepted = 202] = "Accepted", e[e.NonAuthoritativeInformation = 203] = "NonAuthoritativeInformation", e[e.NoContent = 204] = "NoContent", e[e.ResetContent = 205] = "ResetContent", e[e.PartialContent = 206] = "PartialContent", e[e.MultiStatus = 207] = "MultiStatus", e[e.AlreadyReported = 208] = "AlreadyReported", e[e.ImUsed = 226] = "ImUsed", e[e.MultipleChoices = 300] = "MultipleChoices", e[e.MovedPermanently = 301] = "MovedPermanently", e[e.Found = 302] = "Found", e[e.SeeOther = 303] = "SeeOther", e[e.NotModified = 304] = "NotModified", e[e.UseProxy = 305] = "UseProxy", e[e.Unused = 306] = "Unused", e[e.TemporaryRedirect = 307] = "TemporaryRedirect", e[e.PermanentRedirect = 308] = "PermanentRedirect", e[e.BadRequest = 400] = "BadRequest", e[e.Unauthorized = 401] = "Unauthorized", e[e.PaymentRequired = 402] = "PaymentRequired", e[e.Forbidden = 403] = "Forbidden", e[e.NotFound = 404] = "NotFound", e[e.MethodNotAllowed = 405] = "MethodNotAllowed", e[e.NotAcceptable = 406] = "NotAcceptable", e[e.ProxyAuthenticationRequired = 407] = "ProxyAuthenticationRequired", e[e.RequestTimeout = 408] = "RequestTimeout", e[e.Conflict = 409] = "Conflict", e[e.Gone = 410] = "Gone", e[e.LengthRequired = 411] = "LengthRequired", e[e.PreconditionFailed = 412] = "PreconditionFailed", e[e.PayloadTooLarge = 413] = "PayloadTooLarge", e[e.UriTooLong = 414] = "UriTooLong", e[e.UnsupportedMediaType = 415] = "UnsupportedMediaType", e[e.RangeNotSatisfiable = 416] = "RangeNotSatisfiable", e[e.ExpectationFailed = 417] = "ExpectationFailed", e[e.ImATeapot = 418] = "ImATeapot", e[e.MisdirectedRequest = 421] = "MisdirectedRequest", e[e.UnprocessableEntity = 422] = "UnprocessableEntity", e[e.Locked = 423] = "Locked", e[e.FailedDependency = 424] = "FailedDependency", e[e.TooEarly = 425] = "TooEarly", e[e.UpgradeRequired = 426] = "UpgradeRequired", e[e.PreconditionRequired = 428] = "PreconditionRequired", e[e.TooManyRequests = 429] = "TooManyRequests", e[e.RequestHeaderFieldsTooLarge = 431] = "RequestHeaderFieldsTooLarge", e[e.UnavailableForLegalReasons = 451] = "UnavailableForLegalReasons", e[e.InternalServerError = 500] = "InternalServerError", e[e.NotImplemented = 501] = "NotImplemented", e[e.BadGateway = 502] = "BadGateway", e[e.ServiceUnavailable = 503] = "ServiceUnavailable", e[e.GatewayTimeout = 504] = "GatewayTimeout", e[e.HttpVersionNotSupported = 505] = "HttpVersionNotSupported", e[e.VariantAlsoNegotiates = 506] = "VariantAlsoNegotiates", e[e.InsufficientStorage = 507] = "InsufficientStorage", e[e.LoopDetected = 508] = "LoopDetected", e[e.NotExtended = 510] = "NotExtended", e[e.NetworkAuthenticationRequired = 511] = "NetworkAuthenticationRequired", e))(A || {});
6
- class m extends Error {
7
- constructor(r, n) {
8
- super((n == null ? void 0 : n.message) || "Not found"), this.details = n, this.status = r, Object.setPrototypeOf(this, m.prototype);
9
- }
10
- }
11
- class I extends m {
12
- constructor(r) {
13
- super(404, r), Object.setPrototypeOf(this, I.prototype);
14
- }
15
- }
16
- class v extends m {
17
- constructor(r) {
18
- super(401, r), Object.setPrototypeOf(this, v.prototype);
19
- }
20
- }
21
- class P extends m {
22
- constructor(r) {
23
- super(409, r), Object.setPrototypeOf(this, P.prototype);
24
- }
25
- }
26
- function k(e) {
27
- let r;
28
- return e && (typeof e == "string" ? r = {
29
- message: e
30
- } : r = e), r;
31
- }
32
- const L = {
33
- NotFound404: (e) => new I(k(e)),
34
- Unauthorized401: (e) => new v(k(e)),
35
- HttpError: (e, r) => new m(e, k(r)),
36
- Conflict409: (e) => new P(k(e))
37
- }, j = {
38
- getDate: (e) => e ? new Date(e) : /* @__PURE__ */ new Date()
39
- }, b = (e, r) => N(e) ? e.map((n) => b(n, r)) : U(e) ? B(e, (n) => b(n, r)) : r(e);
40
- class z {
41
- constructor() {
42
- this.cookies = {};
43
- }
44
- setCookie(r, n) {
45
- this.cookies[r] = n;
46
- }
47
- getCookieHeader() {
48
- const r = [];
49
- return Object.entries(this.cookies).forEach(([n, i]) => {
50
- Array.isArray(i) ? i.forEach((s) => r.push(["Set-Cookie", `${n}=${s}`])) : r.push(["Set-Cookie", `${n}=${i}`]);
51
- }), new Headers(r);
52
- }
53
- }
54
- class V {
55
- constructor() {
56
- this.headers = {};
57
- }
58
- setHeader(r, n) {
59
- this.headers[r] = n;
60
- }
61
- getHeaders() {
62
- const r = [];
63
- return Object.entries(this.headers).forEach(([n, i]) => {
64
- r.push([n, i]);
65
- }), new Headers(r);
66
- }
67
- }
68
- class G {
69
- constructor(r, n, i) {
70
- this.definition = r, this.db = n, this.authService = i, this.apiStateHash = {}, this.resolvedHelpers = b(r.helpers, (s) => typeof s == "string" ? (...a) => this.runFn(s, ...a) : s), r.initialize && this.runFn(r.initialize);
71
- }
72
- async executeOperation(r, n, i, s) {
73
- var t;
74
- const a = (t = this.definition.operations) == null ? void 0 : t[r];
75
- if (!a)
76
- throw new Error(`Unknown backend operation: ${r}`);
77
- return await this.runFn(a, n, i, s);
78
- }
79
- async runFn(r, ...n) {
80
- var a, t, w, y, c, d, o;
81
- let i = {
82
- ...this.resolvedHelpers,
83
- $db: this.db,
84
- $state: this.apiStateHash,
85
- $authService: this.authService,
86
- $env: j,
87
- $loggedInUser: this.authService.getLoggedInUser(),
88
- $pathParams: (a = n[0]) == null ? void 0 : a.pathParams,
89
- $queryParams: (t = n[0]) == null ? void 0 : t.queryParams,
90
- $requestBody: (w = n[0]) == null ? void 0 : w.requestBody,
91
- $cookies: (y = n[0]) == null ? void 0 : y.cookies,
92
- $requestHeaders: (c = n[0]) == null ? void 0 : c.requestHeaders,
93
- $cookieService: n[1],
94
- //TODO really ugly, temporary solution
95
- $headerService: n[2]
96
- //TODO really ugly, temporary solution
97
- };
98
- const s = J({
99
- localContext: i,
100
- eventArgs: n,
101
- appContext: {
102
- ...O,
103
- ...F,
104
- delay: $,
105
- Errors: L,
106
- createFile: (...l) => new File(l[0], l[1], l[2]),
107
- appendBlob: (l, u) => !l && !u ? void 0 : new Blob([l, u], {
108
- type: (l == null ? void 0 : l.type) || (u == null ? void 0 : u.type) || "application/octet-stream"
109
- }),
110
- getDate: M
111
- }
112
- });
113
- return await T(r, s), (o = (d = s.mainThread) == null ? void 0 : d.blocks) != null && o.length ? s.mainThread.blocks[s.mainThread.blocks.length - 1].returnValue : void 0;
114
- }
115
- }
116
- function J(e) {
117
- return {
118
- mainThread: {
119
- childThreads: [],
120
- blocks: [{ vars: {} }],
121
- loops: [],
122
- breakLabelValue: -1
123
- },
124
- ...e
125
- };
126
- }
127
- class h {
128
- constructor(r) {
129
- this.list = [];
130
- for (const n of r)
131
- this.list.push(n);
132
- }
133
- get length() {
134
- return this.list.length;
135
- }
136
- toArray() {
137
- return this.list.slice(0);
138
- }
139
- at(r) {
140
- if (r < 0 || r > this.list.length - 1)
141
- throw new Error(`Index (${r}) is out of range [0..${Math.max(this.list.length - 1, 0)}]`);
142
- return this.list[r];
143
- }
144
- all() {
145
- return new h(this.list);
146
- }
147
- async single(r) {
148
- const n = await this.where(r);
149
- if (n.length === 0)
150
- throw new Error("No items found with the specified predicate");
151
- if (n.length > 1)
152
- throw new Error("Multiple items found with the specified predicate");
153
- return n.at(0);
154
- }
155
- async singleOrDefault(r, n) {
156
- const i = await this.where(r);
157
- if (i.length === 0)
158
- return n;
159
- if (i.length > 1)
160
- throw new Error("Multiple items found with the specified predicate");
161
- return i.at(0);
162
- }
163
- async where(r) {
164
- return new h(await this.whereAsArray(r));
165
- }
166
- async whereAsArray(r) {
167
- const n = await Promise.all(this.list.map(r ?? (async () => !0)));
168
- return this.list.filter((i, s) => n[s]);
169
- }
170
- async orderBy(...r) {
171
- return new h(await p(this.list, ...r));
172
- }
173
- async orderByAsArray(...r) {
174
- return await p(this.list, ...r);
175
- }
176
- async groupBy(r) {
177
- return new h(await this.groupByAsArray(r));
178
- }
179
- async groupByAsArray(r) {
180
- const n = /* @__PURE__ */ new Map();
181
- for (const s of this.list) {
182
- const a = await r(s), t = n.get(a);
183
- t === void 0 ? n.set(a, [s]) : t.push(s);
184
- }
185
- const i = [];
186
- for (const [s, a] of n.entries())
187
- i.push({ key: s, items: a });
188
- return i;
189
- }
190
- async distinct(r) {
191
- r ?? (r = async (i) => i);
192
- const n = /* @__PURE__ */ new Set();
193
- for (const i of this.list)
194
- n.add(await r(i));
195
- return new h(n.values());
196
- }
197
- async distinctAsArray(r) {
198
- return (await this.distinct(r)).toArray();
199
- }
200
- async maxValue(r = "id", n) {
201
- let i = n ? (await new h(this.list).where(n)).toArray() : this.list;
202
- return i = await p(i, (s) => s[r], !0), i.length === 0 ? void 0 : i[0][r];
203
- }
204
- async skip(r) {
205
- return new h(this.list.slice(r));
206
- }
207
- async take(r) {
208
- return new h(this.list.slice(0, r));
209
- }
210
- async skipTake(r, n) {
211
- return new h(this.list.slice(r, n + r));
212
- }
213
- }
214
- class K {
215
- constructor(r, n = {}, i) {
216
- this.tables = r, this.initialData = n, this.config = i, this.db = null, this.getItems = (s) => this.getDb().table(s).toArray(), this.findItems = async (s, a) => {
217
- const t = await this.getItems(s), w = await Promise.all(t.map(a));
218
- return t.filter((y, c) => w[c]);
219
- }, this.getItem = async (s, a) => {
220
- const t = await this.getItems(s), w = await Promise.all(t.map(a));
221
- return t.find((y, c) => w[c]);
222
- }, this.getItemById = async (s, a) => await this.getItem(s, async (t) => t.id + "" == a + ""), this.deleteItems = async (s, a) => {
223
- }, this.insertItem = async (s, a) => {
224
- const t = await this.getDb().table(s).add(a);
225
- return this.getItemById(s, t);
226
- }, this.updateItem = async (s, a) => (await this.getDb().table(s).update(a.id, a), await this.getItemById(s, a.id));
227
- }
228
- getDb() {
229
- if (this.db === null)
230
- throw new Error("Db is not initialized yet");
231
- return this.db;
232
- }
233
- async initialize() {
234
- var t, w, y;
235
- const r = typeof this.initialData == "function" ? await this.initialData() : this.initialData, n = {}, i = /* @__PURE__ */ new Set();
236
- this.tables ? this.tables.forEach((c) => {
237
- const d = [];
238
- c.pk.length === 1 ? d.push(c.pk[0]) : d.push(`[${c.pk.join("+")}]`), c.indexes && d.push(...c.indexes), n[c.name] = d.join(", "), i.add(c.name);
239
- }) : Object.entries(r).forEach(([c]) => {
240
- n[c] = "++id", i.add(c);
241
- });
242
- const s = ((t = this.config) == null ? void 0 : t.version) !== void 0 && typeof ((w = this.config) == null ? void 0 : w.version) == "number" ? (y = this.config) == null ? void 0 : y.version : 1, a = await this.dropDbOnVersionChange(s);
243
- this.db = this.createDbInstance(), this.db.version(s).stores(n), a && await Promise.all(
244
- Object.entries(r).map(async ([c, d]) => {
245
- try {
246
- await this.getDb().table(c).bulkAdd(d);
247
- } catch (o) {
248
- console.error(o);
249
- }
250
- })
251
- ), i.forEach((c) => {
252
- this[`$${c}`] = W(this.getDb().table(c));
253
- });
254
- }
255
- createDbInstance() {
256
- var r;
257
- return new q(((r = this.config) == null ? void 0 : r.database) ?? "defaultIndexDb");
258
- }
259
- async dropDbOnVersionChange(r) {
260
- const n = this.createDbInstance();
261
- return await q.exists(n.name) ? (await n.open(), n.verno !== r ? (await n.delete(), !0) : (n.close(), !1)) : !0;
262
- }
263
- // --- This method signifies that a section of operations is executed in a transaction
264
- async transaction(r) {
265
- if (!this.db) return;
266
- const n = this.db.tables;
267
- await this.db.transaction("rw", n, r);
268
- }
269
- }
270
- async function W(e) {
271
- const r = () => e.db.table(e.name), n = async (i) => {
272
- const s = await e.toArray(), a = await Promise.all(s.map(i ?? (async () => !0)));
273
- return s.filter((t, w) => a[w]);
274
- };
275
- return {
276
- native: r,
277
- insert: async (i) => {
278
- const s = await e.add(i);
279
- return r().get(s);
280
- },
281
- update: async (i) => (await e.update(i.id, i), r().get(i.id)),
282
- save: async (i) => {
283
- const s = await e.put(i);
284
- return e.get(s);
285
- },
286
- deleteById: async (i) => {
287
- await e.delete(i);
288
- },
289
- byId: async (i) => {
290
- if (i == null)
291
- return null;
292
- let s = i;
293
- return e.schema.primKey.src === "++id" && (s = Number(i)), e.get(s);
294
- },
295
- toArray: async () => await e.toArray(),
296
- single: async (i) => await new h(await e.toArray()).single(i),
297
- singleOrDefault: async (i, s) => await new h(await e.toArray()).singleOrDefault(
298
- i,
299
- s
300
- ),
301
- where: async (i) => new h(await n(i)),
302
- whereAsArray: async (i) => await n(i),
303
- orderBy: async (...i) => await new h(await e.toArray()).orderBy(...i),
304
- orderByAsArray: async (...i) => await new h(await e.toArray()).orderByAsArray(...i),
305
- groupBy: async (i) => await new h(await e.toArray()).groupBy(i),
306
- groupByAsArray: async (i) => await new h(await e.toArray()).groupByAsArray(i),
307
- distinct: async (i) => await new h(await e.toArray()).distinct(i),
308
- distinctAsArray: async (i) => await new h(await e.toArray()).distinctAsArray(i),
309
- maxValue: async (i = "id", s) => await new h(await e.toArray()).maxValue(i, s),
310
- skip: async (i) => await new h(await e.toArray()).skip(i),
311
- take: async (i) => await new h(await e.toArray()).take(i),
312
- skipTake: async (i, s) => await new h(await e.toArray()).skipTake(i, s)
313
- };
314
- }
315
- function R(e, r) {
316
- if (!r) return e;
317
- const n = { ...e };
318
- return Object.keys(e).forEach((i) => {
319
- if (!(i in r)) return;
320
- const s = e[i], a = typeof s;
321
- switch (r[i]) {
322
- case "integer":
323
- switch (a) {
324
- case "number":
325
- n[i] = Math.round(s);
326
- break;
327
- case "string":
328
- n[i] = parseInt(s, 10);
329
- break;
330
- case "boolean":
331
- n[i] = s ? 1 : 0;
332
- break;
333
- }
334
- break;
335
- case "float":
336
- case "real":
337
- case "double":
338
- switch (a) {
339
- case "number":
340
- n[i] = s;
341
- break;
342
- case "string":
343
- n[i] = parseFloat(s);
344
- break;
345
- case "boolean":
346
- n[i] = s ? 1 : 0;
347
- break;
348
- }
349
- break;
350
- case "boolean":
351
- switch (a) {
352
- case "string":
353
- switch (s.toLowerCase()) {
354
- case "true":
355
- case "yes":
356
- case "on":
357
- n[i] = !0;
358
- break;
359
- case "false":
360
- case "no":
361
- case "off":
362
- n[i] = !1;
363
- break;
364
- }
365
- break;
366
- case "number":
367
- n[i] = !!s;
368
- break;
369
- }
370
- break;
371
- }
372
- }), n;
373
- }
374
- class Q {
375
- constructor(r, n = {}, i) {
376
- this.tables = r, this.initialData = n, this.config = i;
377
- }
378
- getItems(r) {
379
- throw new Error("Method not implemented.");
380
- }
381
- getItem(r, n) {
382
- throw new Error("Method not implemented.");
383
- }
384
- getItemById(r, n) {
385
- throw new Error("Method not implemented.");
386
- }
387
- deleteItems(r, n) {
388
- throw new Error("Method not implemented.");
389
- }
390
- insertItem(r, n) {
391
- throw new Error("Method not implemented.");
392
- }
393
- updateItem(r, n) {
394
- throw new Error("Method not implemented.");
395
- }
396
- async initialize() {
397
- }
398
- }
399
- function X(...e) {
400
- const r = {};
401
- for (const n of e) {
402
- if (!U(n))
403
- throw new TypeError("All arguments must be of type object");
404
- const i = new Headers(n);
405
- for (const [s, a] of i.entries())
406
- a === void 0 || a === "undefined" ? delete r[s] : r[s] = a;
407
- }
408
- return new Headers(r);
409
- }
410
- class Y {
411
- constructor(r) {
412
- const n = JSON.parse(sessionStorage.getItem("session-logged-in-user"));
413
- this.loggedInUser = n || (r == null ? void 0 : r.defaultLoggedInUser);
414
- }
415
- login(r) {
416
- this.loggedInUser = r, sessionStorage.setItem("session-logged-in-user", JSON.stringify(r));
417
- }
418
- logout() {
419
- this.loggedInUser = null, sessionStorage.removeItem("session-logged-in-user");
420
- }
421
- getCookieToken() {
422
- return sessionStorage.getItem("session-anonymous-token");
423
- }
424
- setCookieToken(r) {
425
- sessionStorage.setItem("session-anonymous-token", r);
426
- }
427
- getLoggedInUser() {
428
- return this.loggedInUser;
429
- }
430
- }
431
- async function Z(e) {
432
- var r, n;
433
- switch (e.type) {
434
- case "in-memory":
435
- return new Q((r = e.schemaDescriptor) == null ? void 0 : r.tables, e.initialData, e.config);
436
- default:
437
- const i = new K(
438
- (n = e.schemaDescriptor) == null ? void 0 : n.tables,
439
- e.initialData,
440
- e.config
441
- );
442
- return await i.initialize(), i;
443
- }
444
- }
445
- class _ {
446
- // public id = crypto.randomUUID();
447
- constructor(r) {
448
- this.apiDef = r, this.backend = null;
449
- }
450
- async initialize() {
451
- const r = {};
452
- Object.entries(this.apiDef.operations || {}).forEach(([a, t]) => {
453
- r[a] = t.handler;
454
- });
455
- const n = await Z(this.apiDef), i = new Y(this.apiDef.auth), s = {
456
- operations: r,
457
- initialize: this.apiDef.initialize,
458
- helpers: this.apiDef.helpers
459
- };
460
- this.backend = new G(s, n, i);
461
- }
462
- getOperations() {
463
- return this.apiDef.operations || {};
464
- }
465
- getApiUrl() {
466
- return this.apiDef.apiUrl || "";
467
- }
468
- // Use the "msw" package to execute the interceptor operation
469
- async executeOperation(r, n, i, s) {
470
- var d;
471
- if (this.backend === null)
472
- throw new Error("Interceptor not initialized");
473
- const a = (d = this.apiDef.operations) == null ? void 0 : d[r];
474
- if (!a)
475
- throw new Error(`Unknown API interceptor operation: ${r}`);
476
- let t;
477
- try {
478
- if (a.requestShape === "formData") {
479
- const o = await n.formData(), l = {};
480
- for (const u of o.keys()) {
481
- const f = o.getAll(u);
482
- f.length === 1 ? l[u] = f[0] : l[u] = f;
483
- }
484
- t = l;
485
- } else a.requestShape === "blob" ? t = await n.blob() : t = await n.json();
486
- } catch {
487
- }
488
- const w = this.convertRequestParams(
489
- {
490
- pathParams: s,
491
- queryParams: Object.fromEntries(new URL(n.url).searchParams),
492
- requestBody: t,
493
- cookies: i,
494
- requestHeaders: Object.fromEntries(n.headers.entries()) || {}
495
- },
496
- a
497
- );
498
- this.apiDef.artificialDelay === void 0 ? await D("real") : this.apiDef.artificialDelay !== 0 && await D(this.apiDef.artificialDelay);
499
- const y = new z(), c = new V();
500
- try {
501
- const o = await this.backend.executeOperation(
502
- r,
503
- w,
504
- y,
505
- c
506
- ), l = o == null, u = a.successStatusCode ?? (l ? A.NoContent : A.Ok), f = X(y.getCookieHeader(), c.getHeaders());
507
- return o instanceof File ? (f.append("Content-type", o.type), f.append("Content-Length", o.size + ""), f.append(
508
- "Content-Disposition",
509
- `attachment; filename="${o.name}"; filename*=utf-8''${o.name}`
510
- ), g.arrayBuffer(await o.arrayBuffer(), {
511
- headers: f,
512
- status: u
513
- })) : l ? new g(null, {
514
- headers: f,
515
- status: u
516
- }) : g.json(o, {
517
- headers: f,
518
- status: u
519
- });
520
- } catch (o) {
521
- return console.error(o), o instanceof x && o.errorObject instanceof m ? g.json(o.errorObject.details, {
522
- headers: y.getCookieHeader(),
523
- status: o.errorObject.status
524
- }) : g.json(
525
- { message: o == null ? void 0 : o.message },
526
- {
527
- headers: y.getCookieHeader(),
528
- status: A.InternalServerError
529
- }
530
- );
531
- }
532
- }
533
- // Ensures that type path and query params are converted according to the operation definition
534
- convertRequestParams(r, n) {
535
- return {
536
- ...r,
537
- pathParams: R(r.pathParams, n.pathParamTypes),
538
- queryParams: R(r.queryParams, n.queryParamTypes)
539
- };
540
- }
541
- hasMockForRequest(r, n) {
542
- return this.getMockForRequest(r, n) !== void 0;
543
- }
544
- getMockForRequest(r, n) {
545
- return Object.entries(this.getOperations()).find(([i, s]) => !!(E(new URL(r, window.location.href), `${this.getApiUrl()}${s.url}`, `${window.location.href}`).matches && (n.method || "get").toLowerCase() === s.method.toLowerCase()));
546
- }
547
- async executeMockedFetch(r, n) {
548
- const i = this.getMockForRequest(r, n);
549
- if (!i)
550
- throw new Error(`No mock found for request: ${r} with options: ${JSON.stringify(n)}`);
551
- const [s, a] = i, t = E(new URL(r, window.location.href), `${this.getApiUrl()}${a.url}`, `${window.location.href}`);
552
- return this.executeOperation(s, new Request(r, n), S(), t.params);
553
- }
554
- }
555
- function S() {
556
- const e = document.cookie;
557
- return e === "" ? {} : e.split("; ").reduce((i, s) => {
558
- const [a, t] = s.split("=");
559
- return i[decodeURIComponent(a)] = decodeURIComponent(t), i;
560
- }, {});
561
- }
562
- const ne = async (e) => {
563
- const r = new _(e);
564
- return await r.initialize(), r;
565
- };
566
- export {
567
- ne as initMock
568
- };