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.
- package/dist/{metadata/apiInterceptorWorker-Bb5-fQup.mjs → lib/apiInterceptorWorker-DPgtUtdA.mjs} +5870 -3195
- package/dist/lib/index-BuIblMfO.mjs +50034 -0
- package/dist/lib/index.css +1 -1
- package/dist/lib/initMock-CV-9AUzP.mjs +843 -0
- package/dist/lib/language-server-web-worker.mjs +8 -7
- package/dist/lib/language-server.mjs +6 -6
- package/dist/lib/{metadata-utils-DrEexTX9.mjs → metadata-utils-DzONZF-e.mjs} +161 -111
- package/dist/lib/scss/components-core/theming/_themes.scss +6 -7
- package/dist/lib/{server-common-ddmPKhK6.mjs → server-common-Dsyp3-Ro.mjs} +14949 -10880
- package/dist/lib/syntax-monaco.mjs +14 -11
- package/dist/lib/syntax-textmate.d.ts +2 -2
- package/dist/lib/syntax-textmate.mjs +128 -109
- package/dist/lib/transform-CBz7TQJh.mjs +7375 -0
- package/dist/lib/xmlui-parser.d.ts +3 -3
- package/dist/lib/xmlui-parser.mjs +49 -49
- package/dist/lib/xmlui-serializer-Bf9bdvlV.mjs +667 -0
- package/dist/lib/xmlui.d.ts +16 -11
- package/dist/lib/xmlui.mjs +44 -44
- package/dist/{lib/apiInterceptorWorker-DH8wqOVq.mjs → metadata/apiInterceptorWorker-BmKP8bnq.mjs} +5432 -3502
- package/dist/metadata/collectedComponentMetadata-Cdi6AFD3.mjs +55851 -0
- package/dist/metadata/initMock-B7OlSKKb.mjs +843 -0
- package/dist/metadata/style.css +1 -1
- package/dist/metadata/xmlui-metadata.mjs +3 -3
- package/dist/metadata/xmlui-metadata.umd.js +207 -419
- package/dist/scripts/package.json +3 -1
- package/dist/scripts/src/components/APICall/APICall.js +4 -4
- package/dist/scripts/src/components/Accordion/Accordion.js +1 -1
- package/dist/scripts/src/components/Accordion/AccordionItemNative.js +2 -2
- package/dist/scripts/src/components/Animation/AnimationNative.js +259 -0
- package/dist/scripts/src/components/App/App.js +10 -0
- package/dist/scripts/src/components/App/AppNative.js +29 -9
- package/dist/scripts/src/components/AutoComplete/AutoComplete.js +1 -1
- package/dist/scripts/src/components/AutoComplete/AutoCompleteNative.js +5 -4
- package/dist/scripts/src/components/Breakout/BreakoutNative.js +2 -2
- package/dist/scripts/src/components/Button/Button.js +1 -1
- package/dist/scripts/src/components/Button/ButtonNative.js +4 -0
- package/dist/scripts/src/components/Carousel/Carousel.js +13 -20
- package/dist/scripts/src/components/Carousel/CarouselContext.js +11 -2
- package/dist/scripts/src/components/Carousel/CarouselItemNative.js +2 -2
- package/dist/scripts/src/components/Carousel/CarouselNative.js +2 -2
- package/dist/scripts/src/components/Charts/AreaChart/AreaChart.js +92 -0
- package/dist/scripts/src/components/Charts/AreaChart/AreaChartNative.js +127 -0
- package/dist/scripts/src/components/Charts/BarChart/BarChart.js +4 -4
- package/dist/scripts/src/components/Charts/BarChart/BarChartNative.js +90 -82
- package/dist/scripts/src/components/Charts/LineChart/LineChart.js +3 -3
- package/dist/scripts/src/components/Charts/LineChart/LineChartNative.js +5 -1
- package/dist/scripts/src/components/Charts/RadarChart/RadarChart.js +92 -0
- package/dist/scripts/src/components/Charts/RadarChart/RadarChartNative.js +125 -0
- package/dist/scripts/src/components/Checkbox/Checkbox.js +2 -1
- package/dist/scripts/src/components/ComponentProvider.js +4 -0
- package/dist/scripts/src/components/DataSource/DataSource.js +124 -0
- package/dist/scripts/src/components/DateInput/DateInput.js +7 -9
- package/dist/scripts/src/components/DateInput/DateInputNative.js +101 -38
- package/dist/scripts/src/components/DropdownMenu/DropdownMenu.js +1 -1
- package/dist/scripts/src/components/ExpandableItem/ExpandableItemNative.js +18 -12
- package/dist/scripts/src/components/Footer/Footer.js +1 -1
- package/dist/scripts/src/components/FormItem/FormItem.js +1 -1
- package/dist/scripts/src/components/FormItem/ItemWithLabel.js +3 -3
- package/dist/scripts/src/components/Heading/Heading.js +83 -28
- package/dist/scripts/src/components/Heading/HeadingNative.js +10 -1
- package/dist/scripts/src/components/HtmlTags/HtmlTags.js +1 -1
- package/dist/scripts/src/components/Image/ImageNative.js +13 -0
- package/dist/scripts/src/components/Input/PartialInput.js +28 -3
- package/dist/scripts/src/components/List/ListNative.js +6 -5
- package/dist/scripts/src/components/NavLink/NavLink.js +1 -1
- package/dist/scripts/src/components/NavPanel/NavPanelNative.js +3 -8
- package/dist/scripts/src/components/NumberBox/NumberBoxNative.js +2 -2
- package/dist/scripts/src/components/Option/Option.js +2 -2
- package/dist/scripts/src/components/Option/OptionNative.js +12 -1
- package/dist/scripts/src/components/Pagination/Pagination.js +2 -1
- package/dist/scripts/src/components/RadioGroup/RadioGroup.js +7 -3
- package/dist/scripts/src/components/RadioGroup/RadioGroupNative.js +20 -5
- package/dist/scripts/src/components/RadioGroup/RadioItemNative.js +2 -1
- package/dist/scripts/src/components/Select/Select.js +1 -1
- package/dist/scripts/src/components/Select/SelectNative.js +1 -1
- package/dist/scripts/src/components/Slider/Slider.js +10 -8
- package/dist/scripts/src/components/Slider/SliderNative.js +24 -21
- package/dist/scripts/src/components/Switch/Switch.js +2 -1
- package/dist/scripts/src/components/Table/Table.js +1 -1
- package/dist/scripts/src/components/Table/TableNative.js +18 -13
- package/dist/scripts/src/components/TableOfContents/TableOfContents.js +1 -1
- package/dist/scripts/src/components/Text/Text.js +32 -14
- package/dist/scripts/src/components/Text/TextNative.js +17 -5
- package/dist/scripts/src/components/TextArea/TextAreaNative.js +3 -3
- package/dist/scripts/src/components/TextBox/TextBoxNative.js +3 -3
- package/dist/scripts/src/components/TimeInput/TimeInput.js +10 -10
- package/dist/scripts/src/components/TimeInput/TimeInputNative.js +87 -38
- package/dist/scripts/src/components/Toggle/Toggle.js +2 -2
- package/dist/scripts/src/components/Tooltip/Tooltip.js +9 -9
- package/dist/scripts/src/components/Tooltip/TooltipNative.js +4 -4
- package/dist/scripts/src/components/abstractions.js +7 -3
- package/dist/scripts/src/components/collectedComponentMetadata.js +316 -0
- package/dist/scripts/src/components-core/RestApiProxy.js +3 -1
- package/dist/scripts/src/components-core/StandaloneApp.js +823 -0
- package/dist/scripts/src/components-core/interception/ApiInterceptor.js +4 -1
- package/dist/scripts/src/components-core/interception/Backend.js +13 -7
- package/dist/scripts/src/components-core/markup-check.js +279 -0
- package/dist/scripts/src/components-core/parts.js +0 -4
- package/dist/scripts/src/components-core/rendering/ComponentAdapter.js +36 -16
- package/dist/scripts/src/components-core/script-runner/eval-tree-async.js +4 -1
- package/dist/scripts/src/components-core/script-runner/eval-tree-sync.js +4 -1
- package/dist/scripts/src/components-core/theming/themes/root.js +30 -17
- package/dist/scripts/src/components-core/theming/transformThemeVars.js +14 -7
- package/dist/scripts/src/components-core/xmlui-parser.js +60 -43
- package/dist/scripts/src/index.js +120 -0
- package/dist/scripts/src/parsers/xmlui-parser/transform.js +15 -4
- package/dist/standalone/xmlui-standalone.es.d.ts +23 -15
- package/dist/standalone/xmlui-standalone.umd.js +319 -823
- package/package.json +3 -1
- package/src/syntax/textMate/xmlui.tmLanguage.json +2 -2
- package/dist/lib/index-CqzCWOUw.mjs +0 -38579
- package/dist/lib/initMock-C5CXs0-5.mjs +0 -568
- package/dist/lib/transform-SMWeyMoq.mjs +0 -5391
- package/dist/lib/xmlui-serializer-a0O0jFY-.mjs +0 -497
- package/dist/metadata/collectedComponentMetadata-DIT5VbaH.mjs +0 -42985
- package/dist/metadata/initMock-D6Vi9kU_.mjs +0 -568
- package/dist/scripts/src/components-core/ScrollContext.js +0 -11
- package/dist/scripts/src/components-core/utils/audio-utils.js +0 -83
|
@@ -0,0 +1,843 @@
|
|
|
1
|
+
import { delay as delay$1, HttpResponse, matchRequestUrl } from "msw";
|
|
2
|
+
import { isArray, isObject, mapValues } from "lodash-es";
|
|
3
|
+
import { r as runEventHandlerCode, g as getDate, d as delay, m as miscellaneousUtils, a as dateFunctions, o as orderBy, T as ThrowStatementError } from "./index-BuIblMfO.mjs";
|
|
4
|
+
import Dexie from "dexie";
|
|
5
|
+
var HttpStatusCode = /* @__PURE__ */ ((HttpStatusCode2) => {
|
|
6
|
+
HttpStatusCode2[HttpStatusCode2["Continue"] = 100] = "Continue";
|
|
7
|
+
HttpStatusCode2[HttpStatusCode2["SwitchingProtocols"] = 101] = "SwitchingProtocols";
|
|
8
|
+
HttpStatusCode2[HttpStatusCode2["Processing"] = 102] = "Processing";
|
|
9
|
+
HttpStatusCode2[HttpStatusCode2["EarlyHints"] = 103] = "EarlyHints";
|
|
10
|
+
HttpStatusCode2[HttpStatusCode2["Ok"] = 200] = "Ok";
|
|
11
|
+
HttpStatusCode2[HttpStatusCode2["Created"] = 201] = "Created";
|
|
12
|
+
HttpStatusCode2[HttpStatusCode2["Accepted"] = 202] = "Accepted";
|
|
13
|
+
HttpStatusCode2[HttpStatusCode2["NonAuthoritativeInformation"] = 203] = "NonAuthoritativeInformation";
|
|
14
|
+
HttpStatusCode2[HttpStatusCode2["NoContent"] = 204] = "NoContent";
|
|
15
|
+
HttpStatusCode2[HttpStatusCode2["ResetContent"] = 205] = "ResetContent";
|
|
16
|
+
HttpStatusCode2[HttpStatusCode2["PartialContent"] = 206] = "PartialContent";
|
|
17
|
+
HttpStatusCode2[HttpStatusCode2["MultiStatus"] = 207] = "MultiStatus";
|
|
18
|
+
HttpStatusCode2[HttpStatusCode2["AlreadyReported"] = 208] = "AlreadyReported";
|
|
19
|
+
HttpStatusCode2[HttpStatusCode2["ImUsed"] = 226] = "ImUsed";
|
|
20
|
+
HttpStatusCode2[HttpStatusCode2["MultipleChoices"] = 300] = "MultipleChoices";
|
|
21
|
+
HttpStatusCode2[HttpStatusCode2["MovedPermanently"] = 301] = "MovedPermanently";
|
|
22
|
+
HttpStatusCode2[HttpStatusCode2["Found"] = 302] = "Found";
|
|
23
|
+
HttpStatusCode2[HttpStatusCode2["SeeOther"] = 303] = "SeeOther";
|
|
24
|
+
HttpStatusCode2[HttpStatusCode2["NotModified"] = 304] = "NotModified";
|
|
25
|
+
HttpStatusCode2[HttpStatusCode2["UseProxy"] = 305] = "UseProxy";
|
|
26
|
+
HttpStatusCode2[HttpStatusCode2["Unused"] = 306] = "Unused";
|
|
27
|
+
HttpStatusCode2[HttpStatusCode2["TemporaryRedirect"] = 307] = "TemporaryRedirect";
|
|
28
|
+
HttpStatusCode2[HttpStatusCode2["PermanentRedirect"] = 308] = "PermanentRedirect";
|
|
29
|
+
HttpStatusCode2[HttpStatusCode2["BadRequest"] = 400] = "BadRequest";
|
|
30
|
+
HttpStatusCode2[HttpStatusCode2["Unauthorized"] = 401] = "Unauthorized";
|
|
31
|
+
HttpStatusCode2[HttpStatusCode2["PaymentRequired"] = 402] = "PaymentRequired";
|
|
32
|
+
HttpStatusCode2[HttpStatusCode2["Forbidden"] = 403] = "Forbidden";
|
|
33
|
+
HttpStatusCode2[HttpStatusCode2["NotFound"] = 404] = "NotFound";
|
|
34
|
+
HttpStatusCode2[HttpStatusCode2["MethodNotAllowed"] = 405] = "MethodNotAllowed";
|
|
35
|
+
HttpStatusCode2[HttpStatusCode2["NotAcceptable"] = 406] = "NotAcceptable";
|
|
36
|
+
HttpStatusCode2[HttpStatusCode2["ProxyAuthenticationRequired"] = 407] = "ProxyAuthenticationRequired";
|
|
37
|
+
HttpStatusCode2[HttpStatusCode2["RequestTimeout"] = 408] = "RequestTimeout";
|
|
38
|
+
HttpStatusCode2[HttpStatusCode2["Conflict"] = 409] = "Conflict";
|
|
39
|
+
HttpStatusCode2[HttpStatusCode2["Gone"] = 410] = "Gone";
|
|
40
|
+
HttpStatusCode2[HttpStatusCode2["LengthRequired"] = 411] = "LengthRequired";
|
|
41
|
+
HttpStatusCode2[HttpStatusCode2["PreconditionFailed"] = 412] = "PreconditionFailed";
|
|
42
|
+
HttpStatusCode2[HttpStatusCode2["PayloadTooLarge"] = 413] = "PayloadTooLarge";
|
|
43
|
+
HttpStatusCode2[HttpStatusCode2["UriTooLong"] = 414] = "UriTooLong";
|
|
44
|
+
HttpStatusCode2[HttpStatusCode2["UnsupportedMediaType"] = 415] = "UnsupportedMediaType";
|
|
45
|
+
HttpStatusCode2[HttpStatusCode2["RangeNotSatisfiable"] = 416] = "RangeNotSatisfiable";
|
|
46
|
+
HttpStatusCode2[HttpStatusCode2["ExpectationFailed"] = 417] = "ExpectationFailed";
|
|
47
|
+
HttpStatusCode2[HttpStatusCode2["ImATeapot"] = 418] = "ImATeapot";
|
|
48
|
+
HttpStatusCode2[HttpStatusCode2["MisdirectedRequest"] = 421] = "MisdirectedRequest";
|
|
49
|
+
HttpStatusCode2[HttpStatusCode2["UnprocessableEntity"] = 422] = "UnprocessableEntity";
|
|
50
|
+
HttpStatusCode2[HttpStatusCode2["Locked"] = 423] = "Locked";
|
|
51
|
+
HttpStatusCode2[HttpStatusCode2["FailedDependency"] = 424] = "FailedDependency";
|
|
52
|
+
HttpStatusCode2[HttpStatusCode2["TooEarly"] = 425] = "TooEarly";
|
|
53
|
+
HttpStatusCode2[HttpStatusCode2["UpgradeRequired"] = 426] = "UpgradeRequired";
|
|
54
|
+
HttpStatusCode2[HttpStatusCode2["PreconditionRequired"] = 428] = "PreconditionRequired";
|
|
55
|
+
HttpStatusCode2[HttpStatusCode2["TooManyRequests"] = 429] = "TooManyRequests";
|
|
56
|
+
HttpStatusCode2[HttpStatusCode2["RequestHeaderFieldsTooLarge"] = 431] = "RequestHeaderFieldsTooLarge";
|
|
57
|
+
HttpStatusCode2[HttpStatusCode2["UnavailableForLegalReasons"] = 451] = "UnavailableForLegalReasons";
|
|
58
|
+
HttpStatusCode2[HttpStatusCode2["InternalServerError"] = 500] = "InternalServerError";
|
|
59
|
+
HttpStatusCode2[HttpStatusCode2["NotImplemented"] = 501] = "NotImplemented";
|
|
60
|
+
HttpStatusCode2[HttpStatusCode2["BadGateway"] = 502] = "BadGateway";
|
|
61
|
+
HttpStatusCode2[HttpStatusCode2["ServiceUnavailable"] = 503] = "ServiceUnavailable";
|
|
62
|
+
HttpStatusCode2[HttpStatusCode2["GatewayTimeout"] = 504] = "GatewayTimeout";
|
|
63
|
+
HttpStatusCode2[HttpStatusCode2["HttpVersionNotSupported"] = 505] = "HttpVersionNotSupported";
|
|
64
|
+
HttpStatusCode2[HttpStatusCode2["VariantAlsoNegotiates"] = 506] = "VariantAlsoNegotiates";
|
|
65
|
+
HttpStatusCode2[HttpStatusCode2["InsufficientStorage"] = 507] = "InsufficientStorage";
|
|
66
|
+
HttpStatusCode2[HttpStatusCode2["LoopDetected"] = 508] = "LoopDetected";
|
|
67
|
+
HttpStatusCode2[HttpStatusCode2["NotExtended"] = 510] = "NotExtended";
|
|
68
|
+
HttpStatusCode2[HttpStatusCode2["NetworkAuthenticationRequired"] = 511] = "NetworkAuthenticationRequired";
|
|
69
|
+
return HttpStatusCode2;
|
|
70
|
+
})(HttpStatusCode || {});
|
|
71
|
+
class HttpError extends Error {
|
|
72
|
+
constructor(status, details) {
|
|
73
|
+
super((details == null ? void 0 : details.message) || "Not found");
|
|
74
|
+
this.details = details;
|
|
75
|
+
this.status = status;
|
|
76
|
+
Object.setPrototypeOf(this, HttpError.prototype);
|
|
77
|
+
}
|
|
78
|
+
}
|
|
79
|
+
class NotFoundError extends HttpError {
|
|
80
|
+
constructor(details) {
|
|
81
|
+
super(404, details);
|
|
82
|
+
Object.setPrototypeOf(this, NotFoundError.prototype);
|
|
83
|
+
}
|
|
84
|
+
}
|
|
85
|
+
class UnauthorizedError extends HttpError {
|
|
86
|
+
constructor(details) {
|
|
87
|
+
super(401, details);
|
|
88
|
+
Object.setPrototypeOf(this, UnauthorizedError.prototype);
|
|
89
|
+
}
|
|
90
|
+
}
|
|
91
|
+
class ConflictError extends HttpError {
|
|
92
|
+
constructor(details) {
|
|
93
|
+
super(409, details);
|
|
94
|
+
Object.setPrototypeOf(this, ConflictError.prototype);
|
|
95
|
+
}
|
|
96
|
+
}
|
|
97
|
+
function convertErrorDetails(messageOrDetails) {
|
|
98
|
+
let details;
|
|
99
|
+
if (messageOrDetails) {
|
|
100
|
+
if (typeof messageOrDetails === "string") {
|
|
101
|
+
details = {
|
|
102
|
+
message: messageOrDetails
|
|
103
|
+
};
|
|
104
|
+
} else {
|
|
105
|
+
details = messageOrDetails;
|
|
106
|
+
}
|
|
107
|
+
}
|
|
108
|
+
return details;
|
|
109
|
+
}
|
|
110
|
+
const Errors = {
|
|
111
|
+
NotFound404: (messageOrDetails) => {
|
|
112
|
+
return new NotFoundError(convertErrorDetails(messageOrDetails));
|
|
113
|
+
},
|
|
114
|
+
Unauthorized401: (messageOrDetails) => {
|
|
115
|
+
return new UnauthorizedError(convertErrorDetails(messageOrDetails));
|
|
116
|
+
},
|
|
117
|
+
HttpError: (errorCode, messageOrDetails) => {
|
|
118
|
+
return new HttpError(errorCode, convertErrorDetails(messageOrDetails));
|
|
119
|
+
},
|
|
120
|
+
Conflict409: (messageOrDetails) => {
|
|
121
|
+
return new ConflictError(convertErrorDetails(messageOrDetails));
|
|
122
|
+
}
|
|
123
|
+
};
|
|
124
|
+
const defaultBackendEnvironment = {
|
|
125
|
+
getDate: (date) => date ? new Date(date) : /* @__PURE__ */ new Date()
|
|
126
|
+
};
|
|
127
|
+
const mapValuesDeep = (obj, cb) => {
|
|
128
|
+
if (isArray(obj)) {
|
|
129
|
+
return obj.map((innerObj) => mapValuesDeep(innerObj, cb));
|
|
130
|
+
} else if (isObject(obj)) {
|
|
131
|
+
return mapValues(obj, (val) => mapValuesDeep(val, cb));
|
|
132
|
+
} else {
|
|
133
|
+
return cb(obj);
|
|
134
|
+
}
|
|
135
|
+
};
|
|
136
|
+
class CookieService {
|
|
137
|
+
constructor() {
|
|
138
|
+
this.cookies = {};
|
|
139
|
+
}
|
|
140
|
+
setCookie(key, value) {
|
|
141
|
+
this.cookies[key] = value;
|
|
142
|
+
}
|
|
143
|
+
getCookieHeader() {
|
|
144
|
+
const cookieArrays = [];
|
|
145
|
+
Object.entries(this.cookies).forEach(([key, value]) => {
|
|
146
|
+
if (Array.isArray(value)) {
|
|
147
|
+
value.forEach((val) => cookieArrays.push(["Set-Cookie", `${key}=${val}`]));
|
|
148
|
+
} else {
|
|
149
|
+
cookieArrays.push(["Set-Cookie", `${key}=${value}`]);
|
|
150
|
+
}
|
|
151
|
+
});
|
|
152
|
+
return new Headers(cookieArrays);
|
|
153
|
+
}
|
|
154
|
+
}
|
|
155
|
+
class HeaderService {
|
|
156
|
+
constructor() {
|
|
157
|
+
this.headers = {};
|
|
158
|
+
}
|
|
159
|
+
setHeader(key, value) {
|
|
160
|
+
this.headers[key] = value;
|
|
161
|
+
}
|
|
162
|
+
getHeaders() {
|
|
163
|
+
const headersArray = [];
|
|
164
|
+
Object.entries(this.headers).forEach(([key, value]) => {
|
|
165
|
+
headersArray.push([key, value]);
|
|
166
|
+
});
|
|
167
|
+
return new Headers(headersArray);
|
|
168
|
+
}
|
|
169
|
+
}
|
|
170
|
+
class Backend {
|
|
171
|
+
constructor(definition, db, authService) {
|
|
172
|
+
this.definition = definition;
|
|
173
|
+
this.db = db;
|
|
174
|
+
this.authService = authService;
|
|
175
|
+
this.apiStateHash = {};
|
|
176
|
+
this.resolvedHelpers = mapValuesDeep(definition.helpers, (helper) => {
|
|
177
|
+
if (typeof helper === "string") {
|
|
178
|
+
return (...params) => this.runFn(helper, ...params);
|
|
179
|
+
}
|
|
180
|
+
return helper;
|
|
181
|
+
});
|
|
182
|
+
if (definition.initialize) {
|
|
183
|
+
this.runFn(definition.initialize);
|
|
184
|
+
}
|
|
185
|
+
}
|
|
186
|
+
async executeOperation(operationId, requestParams, cookieService, headerService) {
|
|
187
|
+
var _a;
|
|
188
|
+
const handler = (_a = this.definition.operations) == null ? void 0 : _a[operationId];
|
|
189
|
+
if (!handler) {
|
|
190
|
+
throw new Error(`Unknown backend operation: ${operationId}`);
|
|
191
|
+
}
|
|
192
|
+
return await this.runFn(handler, requestParams, cookieService, headerService);
|
|
193
|
+
}
|
|
194
|
+
async runFn(src, ...args) {
|
|
195
|
+
var _a, _b, _c, _d, _e, _f, _g;
|
|
196
|
+
let localContext = {
|
|
197
|
+
...this.resolvedHelpers,
|
|
198
|
+
$db: this.db,
|
|
199
|
+
$state: this.apiStateHash,
|
|
200
|
+
$authService: this.authService,
|
|
201
|
+
$env: defaultBackendEnvironment,
|
|
202
|
+
$loggedInUser: this.authService.getLoggedInUser(),
|
|
203
|
+
$pathParams: (_a = args[0]) == null ? void 0 : _a.pathParams,
|
|
204
|
+
$queryParams: (_b = args[0]) == null ? void 0 : _b.queryParams,
|
|
205
|
+
$requestBody: (_c = args[0]) == null ? void 0 : _c.requestBody,
|
|
206
|
+
$cookies: (_d = args[0]) == null ? void 0 : _d.cookies,
|
|
207
|
+
$requestHeaders: (_e = args[0]) == null ? void 0 : _e.requestHeaders,
|
|
208
|
+
$cookieService: args[1],
|
|
209
|
+
//TODO really ugly, temporary solution
|
|
210
|
+
$headerService: args[2]
|
|
211
|
+
//TODO really ugly, temporary solution
|
|
212
|
+
};
|
|
213
|
+
const evalContext = createEvalContext({
|
|
214
|
+
localContext,
|
|
215
|
+
eventArgs: args,
|
|
216
|
+
appContext: {
|
|
217
|
+
...dateFunctions,
|
|
218
|
+
...miscellaneousUtils,
|
|
219
|
+
delay,
|
|
220
|
+
Errors,
|
|
221
|
+
createFile: (...args2) => {
|
|
222
|
+
return new File(args2[0], args2[1], args2[2]);
|
|
223
|
+
},
|
|
224
|
+
appendBlob: (blob1, blob2) => {
|
|
225
|
+
if (blob1 && blob2) {
|
|
226
|
+
return new Blob([blob1, blob2], { type: blob1.type || blob2.type });
|
|
227
|
+
}
|
|
228
|
+
if (blob1) {
|
|
229
|
+
return blob1;
|
|
230
|
+
}
|
|
231
|
+
if (blob2) {
|
|
232
|
+
return blob2;
|
|
233
|
+
}
|
|
234
|
+
return null;
|
|
235
|
+
},
|
|
236
|
+
getDate
|
|
237
|
+
}
|
|
238
|
+
});
|
|
239
|
+
await runEventHandlerCode(src, evalContext);
|
|
240
|
+
return ((_g = (_f = evalContext.mainThread) == null ? void 0 : _f.blocks) == null ? void 0 : _g.length) ? evalContext.mainThread.blocks[evalContext.mainThread.blocks.length - 1].returnValue : void 0;
|
|
241
|
+
}
|
|
242
|
+
}
|
|
243
|
+
function createEvalContext(parts) {
|
|
244
|
+
return {
|
|
245
|
+
...{
|
|
246
|
+
mainThread: {
|
|
247
|
+
childThreads: [],
|
|
248
|
+
blocks: [{ vars: {} }],
|
|
249
|
+
loops: [],
|
|
250
|
+
breakLabelValue: -1
|
|
251
|
+
}
|
|
252
|
+
},
|
|
253
|
+
...parts
|
|
254
|
+
};
|
|
255
|
+
}
|
|
256
|
+
class ReadOnlyCollection {
|
|
257
|
+
constructor(items) {
|
|
258
|
+
this.list = [];
|
|
259
|
+
for (const item of items) {
|
|
260
|
+
this.list.push(item);
|
|
261
|
+
}
|
|
262
|
+
}
|
|
263
|
+
get length() {
|
|
264
|
+
return this.list.length;
|
|
265
|
+
}
|
|
266
|
+
toArray() {
|
|
267
|
+
return this.list.slice(0);
|
|
268
|
+
}
|
|
269
|
+
at(index) {
|
|
270
|
+
if (index < 0 || index > this.list.length - 1) {
|
|
271
|
+
throw new Error(`Index (${index}) is out of range [0..${Math.max(this.list.length - 1, 0)}]`);
|
|
272
|
+
}
|
|
273
|
+
return this.list[index];
|
|
274
|
+
}
|
|
275
|
+
all() {
|
|
276
|
+
return new ReadOnlyCollection(this.list);
|
|
277
|
+
}
|
|
278
|
+
async single(predicate) {
|
|
279
|
+
const filtered = await this.where(predicate);
|
|
280
|
+
if (filtered.length === 0) {
|
|
281
|
+
throw new Error("No items found with the specified predicate");
|
|
282
|
+
} else if (filtered.length > 1) {
|
|
283
|
+
throw new Error("Multiple items found with the specified predicate");
|
|
284
|
+
}
|
|
285
|
+
return filtered.at(0);
|
|
286
|
+
}
|
|
287
|
+
async singleOrDefault(predicate, defValue) {
|
|
288
|
+
const filtered = await this.where(predicate);
|
|
289
|
+
if (filtered.length === 0) {
|
|
290
|
+
return defValue;
|
|
291
|
+
} else if (filtered.length > 1) {
|
|
292
|
+
throw new Error("Multiple items found with the specified predicate");
|
|
293
|
+
}
|
|
294
|
+
return filtered.at(0);
|
|
295
|
+
}
|
|
296
|
+
async where(predicate) {
|
|
297
|
+
return new ReadOnlyCollection(await this.whereAsArray(predicate));
|
|
298
|
+
}
|
|
299
|
+
async whereAsArray(predicate) {
|
|
300
|
+
const results = await Promise.all(this.list.map(predicate ?? (async () => true)));
|
|
301
|
+
return this.list.filter((_v, index) => results[index]);
|
|
302
|
+
}
|
|
303
|
+
async orderBy(...mappers) {
|
|
304
|
+
return new ReadOnlyCollection(await orderBy(this.list, ...mappers));
|
|
305
|
+
}
|
|
306
|
+
async orderByAsArray(...mappers) {
|
|
307
|
+
return await orderBy(this.list, ...mappers);
|
|
308
|
+
}
|
|
309
|
+
async groupBy(groupKey) {
|
|
310
|
+
return new ReadOnlyCollection(await this.groupByAsArray(groupKey));
|
|
311
|
+
}
|
|
312
|
+
async groupByAsArray(groupKey) {
|
|
313
|
+
const grouped = /* @__PURE__ */ new Map();
|
|
314
|
+
for (const item of this.list) {
|
|
315
|
+
const key = await groupKey(item);
|
|
316
|
+
const matchingList = grouped.get(key);
|
|
317
|
+
if (matchingList === void 0) {
|
|
318
|
+
grouped.set(key, [item]);
|
|
319
|
+
} else {
|
|
320
|
+
matchingList.push(item);
|
|
321
|
+
}
|
|
322
|
+
}
|
|
323
|
+
const groupedItems = [];
|
|
324
|
+
for (const [key, items] of grouped.entries()) {
|
|
325
|
+
groupedItems.push({ key, items });
|
|
326
|
+
}
|
|
327
|
+
return groupedItems;
|
|
328
|
+
}
|
|
329
|
+
async distinct(distinctValue) {
|
|
330
|
+
distinctValue ?? (distinctValue = async (x) => x);
|
|
331
|
+
const values = /* @__PURE__ */ new Set();
|
|
332
|
+
for (const item of this.list) {
|
|
333
|
+
values.add(await distinctValue(item));
|
|
334
|
+
}
|
|
335
|
+
return new ReadOnlyCollection(values.values());
|
|
336
|
+
}
|
|
337
|
+
async distinctAsArray(distinctValue) {
|
|
338
|
+
return (await this.distinct(distinctValue)).toArray();
|
|
339
|
+
}
|
|
340
|
+
async maxValue(fieldName = "id", predicate) {
|
|
341
|
+
let values = predicate ? (await new ReadOnlyCollection(this.list).where(predicate)).toArray() : this.list;
|
|
342
|
+
values = await orderBy(values, (item) => item[fieldName], true);
|
|
343
|
+
return values.length === 0 ? void 0 : values[0][fieldName];
|
|
344
|
+
}
|
|
345
|
+
async skip(count) {
|
|
346
|
+
return new ReadOnlyCollection(this.list.slice(count));
|
|
347
|
+
}
|
|
348
|
+
async take(count) {
|
|
349
|
+
return new ReadOnlyCollection(this.list.slice(0, count));
|
|
350
|
+
}
|
|
351
|
+
async skipTake(skip, take) {
|
|
352
|
+
return new ReadOnlyCollection(this.list.slice(skip, take + skip));
|
|
353
|
+
}
|
|
354
|
+
}
|
|
355
|
+
class IndexedDb {
|
|
356
|
+
constructor(tables, initialData = {}, config) {
|
|
357
|
+
this.tables = tables;
|
|
358
|
+
this.initialData = initialData;
|
|
359
|
+
this.config = config;
|
|
360
|
+
this.db = null;
|
|
361
|
+
this.getItems = (resourceId) => this.getDb().table(resourceId).toArray();
|
|
362
|
+
this.findItems = async (resourceId, predicate) => {
|
|
363
|
+
const ret = await this.getItems(resourceId);
|
|
364
|
+
const results = await Promise.all(ret.map(predicate));
|
|
365
|
+
return ret.filter((_v, index) => results[index]);
|
|
366
|
+
};
|
|
367
|
+
this.getItem = async (resourceId, predicate) => {
|
|
368
|
+
const ret = await this.getItems(resourceId);
|
|
369
|
+
const results = await Promise.all(ret.map(predicate));
|
|
370
|
+
return ret.find((_v, index) => results[index]);
|
|
371
|
+
};
|
|
372
|
+
this.getItemById = async (resourceId, id) => {
|
|
373
|
+
return await this.getItem(resourceId, async (item) => {
|
|
374
|
+
return item.id + "" === id + "";
|
|
375
|
+
});
|
|
376
|
+
};
|
|
377
|
+
this.deleteItems = async (resourceId, predicate) => {
|
|
378
|
+
};
|
|
379
|
+
this.insertItem = async (resourceId, item) => {
|
|
380
|
+
const id = await this.getDb().table(resourceId).add(item);
|
|
381
|
+
return this.getItemById(resourceId, id);
|
|
382
|
+
};
|
|
383
|
+
this.updateItem = async (resourceId, item) => {
|
|
384
|
+
await this.getDb().table(resourceId).update(item.id, item);
|
|
385
|
+
return await this.getItemById(resourceId, item.id);
|
|
386
|
+
};
|
|
387
|
+
}
|
|
388
|
+
getDb() {
|
|
389
|
+
if (this.db === null) {
|
|
390
|
+
throw new Error("Db is not initialized yet");
|
|
391
|
+
}
|
|
392
|
+
return this.db;
|
|
393
|
+
}
|
|
394
|
+
async initialize() {
|
|
395
|
+
var _a, _b, _c;
|
|
396
|
+
const resolvedInitialData = typeof this.initialData === "function" ? await this.initialData() : this.initialData;
|
|
397
|
+
const schema = {};
|
|
398
|
+
const tableNames = /* @__PURE__ */ new Set();
|
|
399
|
+
if (this.tables) {
|
|
400
|
+
this.tables.forEach((tableDescriptor) => {
|
|
401
|
+
const schemaArray = [];
|
|
402
|
+
if (tableDescriptor.pk.length === 1) {
|
|
403
|
+
schemaArray.push(tableDescriptor.pk[0]);
|
|
404
|
+
} else {
|
|
405
|
+
schemaArray.push(`[${tableDescriptor.pk.join("+")}]`);
|
|
406
|
+
}
|
|
407
|
+
if (tableDescriptor.indexes) {
|
|
408
|
+
schemaArray.push(...tableDescriptor.indexes);
|
|
409
|
+
}
|
|
410
|
+
schema[tableDescriptor.name] = schemaArray.join(", ");
|
|
411
|
+
tableNames.add(tableDescriptor.name);
|
|
412
|
+
});
|
|
413
|
+
} else {
|
|
414
|
+
Object.entries(resolvedInitialData).forEach(([key]) => {
|
|
415
|
+
schema[key] = "++id";
|
|
416
|
+
tableNames.add(key);
|
|
417
|
+
});
|
|
418
|
+
}
|
|
419
|
+
const targetVersion = ((_a = this.config) == null ? void 0 : _a.version) !== void 0 && typeof ((_b = this.config) == null ? void 0 : _b.version) === "number" ? (_c = this.config) == null ? void 0 : _c.version : 1;
|
|
420
|
+
const shouldInitializeData = await this.dropDbOnVersionChange(targetVersion);
|
|
421
|
+
this.db = this.createDbInstance();
|
|
422
|
+
this.db.version(targetVersion).stores(schema);
|
|
423
|
+
if (shouldInitializeData) {
|
|
424
|
+
await Promise.all(
|
|
425
|
+
Object.entries(resolvedInitialData).map(async ([key, value]) => {
|
|
426
|
+
try {
|
|
427
|
+
await this.getDb().table(key).bulkAdd(value);
|
|
428
|
+
} catch (ignored) {
|
|
429
|
+
console.error(ignored);
|
|
430
|
+
}
|
|
431
|
+
})
|
|
432
|
+
);
|
|
433
|
+
}
|
|
434
|
+
tableNames.forEach((key) => {
|
|
435
|
+
this[`$${key}`] = createTableWrapper(this.getDb().table(key));
|
|
436
|
+
});
|
|
437
|
+
}
|
|
438
|
+
createDbInstance() {
|
|
439
|
+
var _a;
|
|
440
|
+
return new Dexie(((_a = this.config) == null ? void 0 : _a.database) ?? "defaultIndexDb");
|
|
441
|
+
}
|
|
442
|
+
async dropDbOnVersionChange(targetVersion) {
|
|
443
|
+
const tempDb = this.createDbInstance();
|
|
444
|
+
if (!await Dexie.exists(tempDb.name)) {
|
|
445
|
+
return true;
|
|
446
|
+
}
|
|
447
|
+
await tempDb.open();
|
|
448
|
+
if (tempDb.verno !== targetVersion) {
|
|
449
|
+
await tempDb.delete();
|
|
450
|
+
return true;
|
|
451
|
+
} else {
|
|
452
|
+
tempDb.close();
|
|
453
|
+
return false;
|
|
454
|
+
}
|
|
455
|
+
}
|
|
456
|
+
// --- This method signifies that a section of operations is executed in a transaction
|
|
457
|
+
async transaction(actions) {
|
|
458
|
+
if (!this.db) return;
|
|
459
|
+
const tables = this.db.tables;
|
|
460
|
+
await this.db.transaction("rw", tables, actions);
|
|
461
|
+
}
|
|
462
|
+
}
|
|
463
|
+
async function createTableWrapper(table) {
|
|
464
|
+
const getDataFn = () => table.db.table(table.name);
|
|
465
|
+
const filteredData = async (predicate) => {
|
|
466
|
+
const dataSnapshot = await table.toArray();
|
|
467
|
+
const results = await Promise.all(dataSnapshot.map(predicate ?? (async () => true)));
|
|
468
|
+
return dataSnapshot.filter((_v, index) => results[index]);
|
|
469
|
+
};
|
|
470
|
+
return {
|
|
471
|
+
native: getDataFn,
|
|
472
|
+
insert: async (item) => {
|
|
473
|
+
const id = await table.add(item);
|
|
474
|
+
return getDataFn().get(id);
|
|
475
|
+
},
|
|
476
|
+
update: async (item) => {
|
|
477
|
+
await table.update(item.id, item);
|
|
478
|
+
return getDataFn().get(item.id);
|
|
479
|
+
},
|
|
480
|
+
save: async (item) => {
|
|
481
|
+
const key = await table.put(item);
|
|
482
|
+
return table.get(key);
|
|
483
|
+
},
|
|
484
|
+
deleteById: async (id) => {
|
|
485
|
+
await table.delete(id);
|
|
486
|
+
},
|
|
487
|
+
byId: async (id) => {
|
|
488
|
+
if (id === void 0 || id === null) {
|
|
489
|
+
return null;
|
|
490
|
+
}
|
|
491
|
+
let safeId = id;
|
|
492
|
+
if (table.schema.primKey.src === "++id") {
|
|
493
|
+
safeId = Number(id);
|
|
494
|
+
}
|
|
495
|
+
return table.get(safeId);
|
|
496
|
+
},
|
|
497
|
+
toArray: async () => await table.toArray(),
|
|
498
|
+
single: async (predicate) => await new ReadOnlyCollection(await table.toArray()).single(predicate),
|
|
499
|
+
singleOrDefault: async (predicate, defValue) => {
|
|
500
|
+
return await new ReadOnlyCollection(await table.toArray()).singleOrDefault(
|
|
501
|
+
predicate,
|
|
502
|
+
defValue
|
|
503
|
+
);
|
|
504
|
+
},
|
|
505
|
+
where: async (predicate) => new ReadOnlyCollection(await filteredData(predicate)),
|
|
506
|
+
whereAsArray: async (predicate) => await filteredData(predicate),
|
|
507
|
+
orderBy: async (...mappers) => await new ReadOnlyCollection(await table.toArray()).orderBy(...mappers),
|
|
508
|
+
orderByAsArray: async (...mappers) => await new ReadOnlyCollection(await table.toArray()).orderByAsArray(...mappers),
|
|
509
|
+
groupBy: async (groupKey) => await new ReadOnlyCollection(await table.toArray()).groupBy(groupKey),
|
|
510
|
+
groupByAsArray: async (groupKey) => await new ReadOnlyCollection(await table.toArray()).groupByAsArray(groupKey),
|
|
511
|
+
distinct: async (distinctValue) => await new ReadOnlyCollection(await table.toArray()).distinct(distinctValue),
|
|
512
|
+
distinctAsArray: async (distinctValue) => await new ReadOnlyCollection(await table.toArray()).distinctAsArray(distinctValue),
|
|
513
|
+
maxValue: async (fieldName = "id", predicate) => {
|
|
514
|
+
return await new ReadOnlyCollection(await table.toArray()).maxValue(fieldName, predicate);
|
|
515
|
+
},
|
|
516
|
+
skip: async (count) => {
|
|
517
|
+
return await new ReadOnlyCollection(await table.toArray()).skip(count);
|
|
518
|
+
},
|
|
519
|
+
take: async (count) => {
|
|
520
|
+
return await new ReadOnlyCollection(await table.toArray()).take(count);
|
|
521
|
+
},
|
|
522
|
+
skipTake: async (skip, take) => {
|
|
523
|
+
return await new ReadOnlyCollection(await table.toArray()).skipTake(skip, take);
|
|
524
|
+
}
|
|
525
|
+
};
|
|
526
|
+
}
|
|
527
|
+
function convertRequestParamPart(part, paramTypes) {
|
|
528
|
+
if (!paramTypes) return part;
|
|
529
|
+
const result = { ...part };
|
|
530
|
+
Object.keys(part).forEach((key) => {
|
|
531
|
+
if (!(key in paramTypes)) return;
|
|
532
|
+
const partValue = part[key];
|
|
533
|
+
const partValueType = typeof partValue;
|
|
534
|
+
switch (paramTypes[key]) {
|
|
535
|
+
case "integer":
|
|
536
|
+
switch (partValueType) {
|
|
537
|
+
case "number":
|
|
538
|
+
result[key] = Math.round(partValue);
|
|
539
|
+
break;
|
|
540
|
+
case "string":
|
|
541
|
+
result[key] = parseInt(partValue, 10);
|
|
542
|
+
break;
|
|
543
|
+
case "boolean":
|
|
544
|
+
result[key] = partValue ? 1 : 0;
|
|
545
|
+
break;
|
|
546
|
+
}
|
|
547
|
+
break;
|
|
548
|
+
case "float":
|
|
549
|
+
case "real":
|
|
550
|
+
case "double":
|
|
551
|
+
switch (partValueType) {
|
|
552
|
+
case "number":
|
|
553
|
+
result[key] = partValue;
|
|
554
|
+
break;
|
|
555
|
+
case "string":
|
|
556
|
+
result[key] = parseFloat(partValue);
|
|
557
|
+
break;
|
|
558
|
+
case "boolean":
|
|
559
|
+
result[key] = partValue ? 1 : 0;
|
|
560
|
+
break;
|
|
561
|
+
}
|
|
562
|
+
break;
|
|
563
|
+
case "boolean":
|
|
564
|
+
switch (partValueType) {
|
|
565
|
+
case "string":
|
|
566
|
+
switch (partValue.toLowerCase()) {
|
|
567
|
+
case "true":
|
|
568
|
+
case "yes":
|
|
569
|
+
case "on":
|
|
570
|
+
result[key] = true;
|
|
571
|
+
break;
|
|
572
|
+
case "false":
|
|
573
|
+
case "no":
|
|
574
|
+
case "off":
|
|
575
|
+
result[key] = false;
|
|
576
|
+
break;
|
|
577
|
+
}
|
|
578
|
+
break;
|
|
579
|
+
case "number":
|
|
580
|
+
result[key] = !!partValue;
|
|
581
|
+
break;
|
|
582
|
+
}
|
|
583
|
+
break;
|
|
584
|
+
}
|
|
585
|
+
});
|
|
586
|
+
return result;
|
|
587
|
+
}
|
|
588
|
+
class InMemoryDb {
|
|
589
|
+
constructor(tables, initialData = {}, config) {
|
|
590
|
+
this.tables = tables;
|
|
591
|
+
this.initialData = initialData;
|
|
592
|
+
this.config = config;
|
|
593
|
+
}
|
|
594
|
+
getItems(collectionName) {
|
|
595
|
+
throw new Error("Method not implemented.");
|
|
596
|
+
}
|
|
597
|
+
getItem(collectionName, predicate) {
|
|
598
|
+
throw new Error("Method not implemented.");
|
|
599
|
+
}
|
|
600
|
+
getItemById(collectionName, id) {
|
|
601
|
+
throw new Error("Method not implemented.");
|
|
602
|
+
}
|
|
603
|
+
deleteItems(collectionName, predicate) {
|
|
604
|
+
throw new Error("Method not implemented.");
|
|
605
|
+
}
|
|
606
|
+
insertItem(collectionName, item) {
|
|
607
|
+
throw new Error("Method not implemented.");
|
|
608
|
+
}
|
|
609
|
+
updateItem(collectionName, item) {
|
|
610
|
+
throw new Error("Method not implemented.");
|
|
611
|
+
}
|
|
612
|
+
async initialize() {
|
|
613
|
+
}
|
|
614
|
+
}
|
|
615
|
+
function mergeHeaders(...sources) {
|
|
616
|
+
const result = {};
|
|
617
|
+
for (const source of sources) {
|
|
618
|
+
if (!isObject(source)) {
|
|
619
|
+
throw new TypeError("All arguments must be of type object");
|
|
620
|
+
}
|
|
621
|
+
const headers = new Headers(source);
|
|
622
|
+
for (const [key, value] of headers.entries()) {
|
|
623
|
+
if (value === void 0 || value === "undefined") {
|
|
624
|
+
delete result[key];
|
|
625
|
+
} else {
|
|
626
|
+
result[key] = value;
|
|
627
|
+
}
|
|
628
|
+
}
|
|
629
|
+
}
|
|
630
|
+
return new Headers(result);
|
|
631
|
+
}
|
|
632
|
+
class AuthService {
|
|
633
|
+
constructor(auth) {
|
|
634
|
+
const cachedLoggedInUser = JSON.parse(sessionStorage.getItem("session-logged-in-user"));
|
|
635
|
+
this.loggedInUser = cachedLoggedInUser || (auth == null ? void 0 : auth.defaultLoggedInUser);
|
|
636
|
+
}
|
|
637
|
+
login(newLoggedInUser) {
|
|
638
|
+
this.loggedInUser = newLoggedInUser;
|
|
639
|
+
sessionStorage.setItem("session-logged-in-user", JSON.stringify(newLoggedInUser));
|
|
640
|
+
}
|
|
641
|
+
logout() {
|
|
642
|
+
this.loggedInUser = null;
|
|
643
|
+
sessionStorage.removeItem("session-logged-in-user");
|
|
644
|
+
}
|
|
645
|
+
getCookieToken() {
|
|
646
|
+
return sessionStorage.getItem("session-anonymous-token");
|
|
647
|
+
}
|
|
648
|
+
setCookieToken(token) {
|
|
649
|
+
sessionStorage.setItem("session-anonymous-token", token);
|
|
650
|
+
}
|
|
651
|
+
getLoggedInUser() {
|
|
652
|
+
return this.loggedInUser;
|
|
653
|
+
}
|
|
654
|
+
}
|
|
655
|
+
async function initDb(apiDef) {
|
|
656
|
+
var _a, _b;
|
|
657
|
+
switch (apiDef.type) {
|
|
658
|
+
case "in-memory":
|
|
659
|
+
return new InMemoryDb((_a = apiDef.schemaDescriptor) == null ? void 0 : _a.tables, apiDef.initialData, apiDef.config);
|
|
660
|
+
default:
|
|
661
|
+
const indexedDb = new IndexedDb(
|
|
662
|
+
(_b = apiDef.schemaDescriptor) == null ? void 0 : _b.tables,
|
|
663
|
+
apiDef.initialData,
|
|
664
|
+
apiDef.config
|
|
665
|
+
);
|
|
666
|
+
await indexedDb.initialize();
|
|
667
|
+
return indexedDb;
|
|
668
|
+
}
|
|
669
|
+
}
|
|
670
|
+
class ApiInterceptor {
|
|
671
|
+
// public id = crypto.randomUUID();
|
|
672
|
+
constructor(apiDef) {
|
|
673
|
+
this.apiDef = apiDef;
|
|
674
|
+
this.backend = null;
|
|
675
|
+
}
|
|
676
|
+
async initialize() {
|
|
677
|
+
const backendOperations = {};
|
|
678
|
+
Object.entries(this.apiDef.operations || {}).forEach(([key, value]) => {
|
|
679
|
+
backendOperations[key] = value.handler;
|
|
680
|
+
});
|
|
681
|
+
const db = await initDb(this.apiDef);
|
|
682
|
+
const authService = new AuthService(this.apiDef.auth);
|
|
683
|
+
const definition = {
|
|
684
|
+
operations: backendOperations,
|
|
685
|
+
initialize: this.apiDef.initialize,
|
|
686
|
+
helpers: this.apiDef.helpers
|
|
687
|
+
};
|
|
688
|
+
this.backend = new Backend(definition, db, authService);
|
|
689
|
+
}
|
|
690
|
+
getOperations() {
|
|
691
|
+
return this.apiDef.operations || {};
|
|
692
|
+
}
|
|
693
|
+
getApiUrl() {
|
|
694
|
+
return this.apiDef.apiUrl || "";
|
|
695
|
+
}
|
|
696
|
+
// Use the "msw" package to execute the interceptor operation
|
|
697
|
+
async executeOperation(operationId, req, cookies, params) {
|
|
698
|
+
var _a;
|
|
699
|
+
if (this.backend === null) {
|
|
700
|
+
throw new Error("Interceptor not initialized");
|
|
701
|
+
}
|
|
702
|
+
const operation = (_a = this.apiDef.operations) == null ? void 0 : _a[operationId];
|
|
703
|
+
if (!operation) {
|
|
704
|
+
throw new Error(`Unknown API interceptor operation: ${operationId}`);
|
|
705
|
+
}
|
|
706
|
+
let reqBody;
|
|
707
|
+
try {
|
|
708
|
+
if (operation.requestShape === "formData") {
|
|
709
|
+
const formData = await req.formData();
|
|
710
|
+
const obj = {};
|
|
711
|
+
for (const key of formData.keys()) {
|
|
712
|
+
const all = formData.getAll(key);
|
|
713
|
+
if (all.length === 1) {
|
|
714
|
+
obj[key] = all[0];
|
|
715
|
+
} else {
|
|
716
|
+
obj[key] = all;
|
|
717
|
+
}
|
|
718
|
+
}
|
|
719
|
+
reqBody = obj;
|
|
720
|
+
} else if (operation.requestShape === "blob") {
|
|
721
|
+
reqBody = await req.blob();
|
|
722
|
+
} else {
|
|
723
|
+
reqBody = await req.json();
|
|
724
|
+
}
|
|
725
|
+
} catch (e) {
|
|
726
|
+
}
|
|
727
|
+
const mappedParams = this.convertRequestParams(
|
|
728
|
+
{
|
|
729
|
+
pathParams: params,
|
|
730
|
+
queryParams: Object.fromEntries(new URL(req.url).searchParams),
|
|
731
|
+
requestBody: reqBody,
|
|
732
|
+
cookies,
|
|
733
|
+
requestHeaders: Object.fromEntries(req.headers.entries()) || {}
|
|
734
|
+
},
|
|
735
|
+
operation
|
|
736
|
+
);
|
|
737
|
+
if (this.apiDef.artificialDelay === void 0) {
|
|
738
|
+
await delay$1("real");
|
|
739
|
+
} else if (this.apiDef.artificialDelay !== 0) {
|
|
740
|
+
await delay$1(this.apiDef.artificialDelay);
|
|
741
|
+
}
|
|
742
|
+
const cookieService = new CookieService();
|
|
743
|
+
const headerService = new HeaderService();
|
|
744
|
+
try {
|
|
745
|
+
const ret = await this.backend.executeOperation(
|
|
746
|
+
operationId,
|
|
747
|
+
mappedParams,
|
|
748
|
+
cookieService,
|
|
749
|
+
headerService
|
|
750
|
+
);
|
|
751
|
+
const emptyBody = ret === void 0 || ret === null;
|
|
752
|
+
const successStatusCode = operation.successStatusCode ?? (emptyBody ? HttpStatusCode.NoContent : HttpStatusCode.Ok);
|
|
753
|
+
const headers = mergeHeaders(cookieService.getCookieHeader(), headerService.getHeaders());
|
|
754
|
+
if (ret instanceof File) {
|
|
755
|
+
headers.append("Content-type", ret.type);
|
|
756
|
+
headers.append("Content-Length", ret.size + "");
|
|
757
|
+
const encodedFilename = encodeURIComponent(ret.name);
|
|
758
|
+
headers.append(
|
|
759
|
+
"Content-Disposition",
|
|
760
|
+
`attachment; filename*=UTF-8''${encodedFilename}`
|
|
761
|
+
);
|
|
762
|
+
return HttpResponse.arrayBuffer(await ret.arrayBuffer(), {
|
|
763
|
+
headers,
|
|
764
|
+
status: successStatusCode
|
|
765
|
+
});
|
|
766
|
+
}
|
|
767
|
+
if (emptyBody) {
|
|
768
|
+
return new HttpResponse(null, {
|
|
769
|
+
headers,
|
|
770
|
+
status: successStatusCode
|
|
771
|
+
});
|
|
772
|
+
}
|
|
773
|
+
return HttpResponse.json(ret, {
|
|
774
|
+
headers,
|
|
775
|
+
status: successStatusCode
|
|
776
|
+
});
|
|
777
|
+
} catch (e) {
|
|
778
|
+
console.error(e);
|
|
779
|
+
if (e instanceof ThrowStatementError && e.errorObject instanceof HttpError) {
|
|
780
|
+
return HttpResponse.json(e.errorObject.details, {
|
|
781
|
+
headers: cookieService.getCookieHeader(),
|
|
782
|
+
status: e.errorObject.status
|
|
783
|
+
});
|
|
784
|
+
}
|
|
785
|
+
return HttpResponse.json(
|
|
786
|
+
{ message: e == null ? void 0 : e.message },
|
|
787
|
+
{
|
|
788
|
+
headers: cookieService.getCookieHeader(),
|
|
789
|
+
status: HttpStatusCode.InternalServerError
|
|
790
|
+
}
|
|
791
|
+
);
|
|
792
|
+
}
|
|
793
|
+
}
|
|
794
|
+
// Ensures that type path and query params are converted according to the operation definition
|
|
795
|
+
convertRequestParams(params, operation) {
|
|
796
|
+
return {
|
|
797
|
+
...params,
|
|
798
|
+
pathParams: convertRequestParamPart(params.pathParams, operation.pathParamTypes),
|
|
799
|
+
queryParams: convertRequestParamPart(params.queryParams, operation.queryParamTypes)
|
|
800
|
+
};
|
|
801
|
+
}
|
|
802
|
+
hasMockForRequest(url, options) {
|
|
803
|
+
return this.getMockForRequest(url, options) !== void 0;
|
|
804
|
+
}
|
|
805
|
+
getMockForRequest(url, options) {
|
|
806
|
+
return Object.entries(this.getOperations()).find(([operationId, operationDef]) => {
|
|
807
|
+
if (matchRequestUrl(new URL(url, window.location.href), `${this.getApiUrl()}${operationDef.url}`, `${window.location.href}`).matches && (options.method || "get").toLowerCase() === operationDef.method.toLowerCase()) {
|
|
808
|
+
return true;
|
|
809
|
+
}
|
|
810
|
+
return false;
|
|
811
|
+
});
|
|
812
|
+
}
|
|
813
|
+
async executeMockedFetch(url, options) {
|
|
814
|
+
const mockForRequest = this.getMockForRequest(url, options);
|
|
815
|
+
if (!mockForRequest) {
|
|
816
|
+
throw new Error(`No mock found for request: ${url} with options: ${JSON.stringify(options)}`);
|
|
817
|
+
}
|
|
818
|
+
const [operationId, operationDef] = mockForRequest;
|
|
819
|
+
const match = matchRequestUrl(new URL(url, window.location.href), `${this.getApiUrl()}${operationDef.url}`, `${window.location.href}`);
|
|
820
|
+
return this.executeOperation(operationId, new Request(url, options), getCookiesAsObject(), match.params);
|
|
821
|
+
}
|
|
822
|
+
}
|
|
823
|
+
function getCookiesAsObject() {
|
|
824
|
+
const cookieString = document.cookie;
|
|
825
|
+
if (cookieString === "") {
|
|
826
|
+
return {};
|
|
827
|
+
}
|
|
828
|
+
const cookiePairs = cookieString.split("; ");
|
|
829
|
+
const cookieObject = cookiePairs.reduce((acc, currentPair) => {
|
|
830
|
+
const [key, value] = currentPair.split("=");
|
|
831
|
+
acc[decodeURIComponent(key)] = decodeURIComponent(value);
|
|
832
|
+
return acc;
|
|
833
|
+
}, {});
|
|
834
|
+
return cookieObject;
|
|
835
|
+
}
|
|
836
|
+
const initMock = async (apiInterceptorDefinition) => {
|
|
837
|
+
const apiInstance = new ApiInterceptor(apiInterceptorDefinition);
|
|
838
|
+
await apiInstance.initialize();
|
|
839
|
+
return apiInstance;
|
|
840
|
+
};
|
|
841
|
+
export {
|
|
842
|
+
initMock
|
|
843
|
+
};
|