@web-atoms/core 2.6.21 → 2.6.25
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/App.d.ts +1 -1
- package/dist/App.d.ts.map +1 -1
- package/dist/App.js.map +1 -1
- package/dist/core/SingleInvoker.d.ts.map +1 -1
- package/dist/core/SingleInvoker.js.map +1 -1
- package/dist/core/sleep.js.map +1 -1
- package/dist/tsconfig.tsbuildinfo +1 -1
- package/dist-esm/App.d.ts +1 -1
- package/dist-esm/App.d.ts.map +1 -1
- package/dist-esm/App.js +231 -235
- package/dist-esm/App.js.map +1 -1
- package/dist-esm/Atom.js +93 -96
- package/dist-esm/MockApp.js +17 -18
- package/dist-esm/Pack.js +1 -3
- package/dist-esm/core/AtomBinder.js +189 -187
- package/dist-esm/core/AtomComponent.js +479 -502
- package/dist-esm/core/AtomDispatcher.js +46 -48
- package/dist-esm/core/AtomDisposableList.js +24 -25
- package/dist-esm/core/AtomEnumerator.js +15 -16
- package/dist-esm/core/AtomList.js +193 -192
- package/dist-esm/core/AtomLoader.js +229 -215
- package/dist-esm/core/AtomMap.js +7 -8
- package/dist-esm/core/AtomOnce.js +22 -24
- package/dist-esm/core/AtomSelectableList.js +240 -243
- package/dist-esm/core/AtomUri.js +70 -72
- package/dist-esm/core/AtomWatcher.js +105 -111
- package/dist-esm/core/Bind.js +271 -269
- package/dist-esm/core/BindableProperty.js +26 -27
- package/dist-esm/core/CancelTokenFactory.js +21 -24
- package/dist-esm/core/Color.js +1 -2
- package/dist-esm/core/Colors.js +545 -231
- package/dist-esm/core/Command.js +236 -223
- package/dist-esm/core/Defer.js +21 -22
- package/dist-esm/core/EventScope.js +96 -88
- package/dist-esm/core/ExpressionParser.js +132 -144
- package/dist-esm/core/ExtendControl.js +7 -8
- package/dist-esm/core/FormattedError.js +7 -8
- package/dist-esm/core/FormattedString.js +4 -5
- package/dist-esm/core/Hacks.js +41 -42
- package/dist-esm/core/IFetchEvent.js +1 -2
- package/dist-esm/core/IScreen.js +1 -2
- package/dist-esm/core/IValueConverter.js +1 -2
- package/dist-esm/core/InheritedProperty.js +61 -63
- package/dist-esm/core/InjectProperty.js +12 -13
- package/dist-esm/core/KeyValuePairs.js +1 -2
- package/dist-esm/core/Markdown.js +14 -17
- package/dist-esm/core/MarkdownError.js +6 -7
- package/dist-esm/core/PropertyBinding.js +1 -2
- package/dist-esm/core/PropertyMap.js +28 -27
- package/dist-esm/core/Route.js +149 -148
- package/dist-esm/core/SingleInvoker.d.ts.map +1 -1
- package/dist-esm/core/SingleInvoker.js +32 -35
- package/dist-esm/core/SingleInvoker.js.map +1 -1
- package/dist-esm/core/StringHelper.js +49 -51
- package/dist-esm/core/TransientDisposable.js +14 -16
- package/dist-esm/core/WatchProperty.js +18 -17
- package/dist-esm/core/WebImage.js +7 -8
- package/dist-esm/core/XNode.js +134 -117
- package/dist-esm/core/sleep.js +21 -24
- package/dist-esm/core/sleep.js.map +1 -1
- package/dist-esm/core/types.js +102 -103
- package/dist-esm/di/DISingleton.js +7 -5
- package/dist-esm/di/DITransient.js +7 -5
- package/dist-esm/di/IMockOrInject.js +1 -2
- package/dist-esm/di/IServiceProvider.js +1 -2
- package/dist-esm/di/Inject.js +67 -67
- package/dist-esm/di/Register.js +25 -26
- package/dist-esm/di/RegisterScoped.js +4 -3
- package/dist-esm/di/RegisterSingleton.js +4 -3
- package/dist-esm/di/ServiceCollection.js +38 -37
- package/dist-esm/di/ServiceProvider.js +94 -94
- package/dist-esm/di/TypeKey.js +13 -12
- package/dist-esm/services/BusyIndicatorService.js +7 -11
- package/dist-esm/services/CacheService.js +54 -62
- package/dist-esm/services/FetchBuilder.js +327 -278
- package/dist-esm/services/JsonService.js +118 -116
- package/dist-esm/services/MockNavigationService.js +127 -126
- package/dist-esm/services/NavigationService.js +95 -102
- package/dist-esm/services/ReferenceService.js +30 -33
- package/dist-esm/services/http/AjaxOptions.js +1 -3
- package/dist-esm/services/http/JsonError.js +16 -15
- package/dist-esm/services/http/RestService.js +314 -323
- package/dist-esm/style/StyleRule.js +1 -2
- package/dist-esm/test.js +0 -1
- package/dist-esm/tsconfig.esm.tsbuildinfo +1 -1
- package/dist-esm/unit/AtomTest.js +10 -11
- package/dist-esm/view-model/Action.js +258 -223
- package/dist-esm/view-model/AtomViewModel.js +234 -232
- package/dist-esm/view-model/AtomWindowViewModel.js +13 -14
- package/dist-esm/view-model/BindableUrlParameter.js +7 -8
- package/dist-esm/view-model/Delay.js +21 -25
- package/dist-esm/view-model/Disposable.js +28 -29
- package/dist-esm/view-model/Load.js +72 -73
- package/dist-esm/view-model/Once.js +33 -35
- package/dist-esm/view-model/baseTypes.js +4 -5
- package/dist-esm/view-model/bindPromise.js +24 -27
- package/dist-esm/view-model/bindProperty.js +3 -4
- package/dist-esm/view-model/bindUrlParameter.js +39 -43
- package/dist-esm/web/controls/AtomComboBox.js +56 -63
- package/dist-esm/web/controls/AtomControl.js +485 -490
- package/dist-esm/web/controls/AtomGridSplitter.js +57 -50
- package/dist-esm/web/controls/AtomGridView.js +230 -222
- package/dist-esm/web/controls/AtomItemsControl.js +677 -688
- package/dist-esm/web/controls/AtomPage.js +6 -7
- package/dist-esm/web/controls/AtomTemplate.js +1 -3
- package/dist-esm/web/controls/AtomTemplateControl.js +28 -29
- package/dist-esm/web/controls/AtomViewStack.js +19 -20
- package/dist-esm/web/core/AtomUI.js +200 -200
- package/dist-esm/web/core/Encoder.js +142 -152
- package/dist-esm/web/core/HtmlNode.js +141 -139
- package/dist-esm/web/images/Busy.js +1 -2
- package/dist-esm/web/images/BusyDataUrl.js +2 -869
- package/dist-esm/web/images/Button.js +1 -2
- package/dist-esm/web/images/ButtonDataUrl.js +2 -30
- package/dist-esm/web/images/CloseButton.js +1 -2
- package/dist-esm/web/images/CloseButtonDataUrl.js +2 -30
- package/dist-esm/web/images/CloseButtonHover.js +1 -2
- package/dist-esm/web/images/CloseButtonHoverDataUrl.js +2 -24
- package/dist-esm/web/services/LastTarget.js +31 -29
- package/dist-esm/web/services/MarkdownService.js +19 -31
- package/dist-esm/web/services/NotificationPopup.js +28 -21
- package/dist-esm/web/services/PopupService.js +512 -478
- package/dist-esm/web/services/PopupWindow.js +266 -247
- package/dist-esm/web/styles/AtomAlertWindowStyle.js +39 -40
- package/dist-esm/web/styles/AtomFrameStyle.js +15 -16
- package/dist-esm/web/styles/AtomNotificationStyle.js +19 -20
- package/dist-esm/web/styles/AtomPageLinkStyle.js +11 -12
- package/dist-esm/web/styles/AtomPopupStyle.js +9 -10
- package/dist-esm/web/styles/AtomStyle.js +61 -64
- package/dist-esm/web/styles/AtomStyleSheet.js +50 -51
- package/dist-esm/web/styles/AtomWindowStyle.js +116 -117
- package/dist-esm/web/styles/IStyleDeclaration.js +1 -2
- package/dist-esm/web/styles/StyleBuilder.js +79 -80
- package/package.json +3 -1
- package/src/App.ts +1 -1
- package/src/core/SingleInvoker.ts +1 -1
- package/src/core/sleep.ts +1 -1
|
@@ -1,296 +1,345 @@
|
|
|
1
1
|
import { __addDisposableResource, __disposeResources } from "tslib";
|
|
2
2
|
import { App } from "../App.js";
|
|
3
3
|
export default class FetchBuilder {
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
}
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
4
|
+
static buildUrl(strings, ...p) {
|
|
5
|
+
let r = "";
|
|
6
|
+
for (let index = 0; index < strings.length; index++) {
|
|
7
|
+
const element = strings[index];
|
|
8
|
+
r += element;
|
|
9
|
+
if (index < p.length) {
|
|
10
|
+
r += encodeURIComponent(p[index]);
|
|
11
|
+
}
|
|
12
|
+
}
|
|
13
|
+
return r;
|
|
14
|
+
}
|
|
15
|
+
static get(url) {
|
|
16
|
+
return this.method(url, "GET");
|
|
17
|
+
}
|
|
18
|
+
static put(url) {
|
|
19
|
+
return this.method(url, "PUT");
|
|
20
|
+
}
|
|
21
|
+
static post(url) {
|
|
22
|
+
return this.method(url, "POST");
|
|
23
|
+
}
|
|
24
|
+
static delete(url) {
|
|
25
|
+
return this.method(url, "DELETE");
|
|
26
|
+
}
|
|
27
|
+
static url(url) {
|
|
28
|
+
return this.method(url, "GET");
|
|
29
|
+
}
|
|
30
|
+
static header(name, value) {
|
|
31
|
+
return new FetchBuilder({
|
|
32
|
+
headers: {
|
|
33
|
+
url: "",
|
|
34
|
+
method: "POST",
|
|
35
|
+
[name]: value
|
|
36
|
+
}
|
|
37
|
+
});
|
|
38
|
+
}
|
|
39
|
+
static method(url, method) {
|
|
40
|
+
return new FetchBuilder({
|
|
41
|
+
url,
|
|
42
|
+
method
|
|
43
|
+
});
|
|
44
|
+
}
|
|
45
|
+
constructor(request) {
|
|
46
|
+
this.request = request;
|
|
47
|
+
}
|
|
48
|
+
log(logger) {
|
|
49
|
+
return this.append({
|
|
50
|
+
log: logger
|
|
51
|
+
});
|
|
52
|
+
}
|
|
53
|
+
logWhenFailed(logger) {
|
|
54
|
+
return this.append({
|
|
55
|
+
logError: logger
|
|
56
|
+
});
|
|
57
|
+
}
|
|
58
|
+
get(url) {
|
|
59
|
+
return this.method(url, "GET");
|
|
60
|
+
}
|
|
61
|
+
put(url) {
|
|
62
|
+
return this.method(url, "PUT");
|
|
63
|
+
}
|
|
64
|
+
post(url) {
|
|
65
|
+
return this.method(url, "POST");
|
|
66
|
+
}
|
|
67
|
+
delete(url) {
|
|
68
|
+
return this.method(url, "DELETE");
|
|
69
|
+
}
|
|
70
|
+
method(url, method) {
|
|
71
|
+
return this.append({
|
|
72
|
+
url,
|
|
73
|
+
method
|
|
74
|
+
});
|
|
75
|
+
}
|
|
76
|
+
signal(signal) {
|
|
77
|
+
if (!signal) {
|
|
78
|
+
return this;
|
|
79
|
+
}
|
|
80
|
+
return this.append({
|
|
81
|
+
signal
|
|
82
|
+
});
|
|
83
|
+
}
|
|
84
|
+
cancelToken(ct) {
|
|
85
|
+
if (!ct) {
|
|
86
|
+
return this;
|
|
87
|
+
}
|
|
88
|
+
const ac = new AbortController();
|
|
89
|
+
const signal = ac.signal;
|
|
90
|
+
ct.registerForCancel(() => ac.abort());
|
|
91
|
+
return this.signal(signal);
|
|
92
|
+
}
|
|
93
|
+
form(name, value, fileName) {
|
|
94
|
+
if (value === void 0) {
|
|
95
|
+
return this;
|
|
96
|
+
}
|
|
97
|
+
const body = this.request.body ?? new FormData();
|
|
98
|
+
if (fileName) {
|
|
99
|
+
if (typeof value === "string") {
|
|
100
|
+
throw new Error("value must be a blob with content type set correctly.");
|
|
101
|
+
}
|
|
102
|
+
body.append(name, value, fileName);
|
|
103
|
+
} else {
|
|
104
|
+
body.append(name, value);
|
|
105
|
+
}
|
|
106
|
+
return this.append({
|
|
107
|
+
body
|
|
108
|
+
});
|
|
109
|
+
}
|
|
110
|
+
jsonBody(body, encode = true) {
|
|
111
|
+
if (encode) {
|
|
112
|
+
body = JSON.stringify(body);
|
|
113
|
+
}
|
|
114
|
+
const headers = this.request.headers ?? {};
|
|
115
|
+
headers["content-type"] = "application/json";
|
|
116
|
+
return this.append({
|
|
117
|
+
body,
|
|
118
|
+
headers
|
|
119
|
+
});
|
|
120
|
+
}
|
|
121
|
+
header(name, value) {
|
|
122
|
+
const headers = this.request.headers ?? {};
|
|
123
|
+
headers[name] = value;
|
|
124
|
+
return this.append({
|
|
125
|
+
headers
|
|
126
|
+
});
|
|
127
|
+
}
|
|
128
|
+
path(name, value, encode = true) {
|
|
129
|
+
let url = this.request.url;
|
|
130
|
+
if (encode) {
|
|
131
|
+
value = encodeURIComponent(value);
|
|
132
|
+
}
|
|
133
|
+
url = url.replace(name, value);
|
|
134
|
+
return this.append({
|
|
135
|
+
url
|
|
136
|
+
});
|
|
137
|
+
}
|
|
138
|
+
query(name, value, encode = true) {
|
|
139
|
+
if (value === void 0) {
|
|
140
|
+
return this;
|
|
141
|
+
}
|
|
142
|
+
let url = this.request.url;
|
|
143
|
+
if (encode) {
|
|
144
|
+
value = encodeURIComponent(value);
|
|
145
|
+
}
|
|
146
|
+
name = encodeURIComponent(name);
|
|
147
|
+
if (url.indexOf("?") === -1) {
|
|
148
|
+
url += `?${name}=${value}`;
|
|
149
|
+
} else {
|
|
150
|
+
url += `&${name}=${value}`;
|
|
151
|
+
}
|
|
152
|
+
return this.append({
|
|
153
|
+
url
|
|
154
|
+
});
|
|
155
|
+
}
|
|
156
|
+
queries(obj, encode = true, encodeObjectAsJson = true) {
|
|
157
|
+
let url = this.request.url;
|
|
158
|
+
let prefix = url.indexOf("?") === -1 ? "?" : "&";
|
|
159
|
+
for (const key in obj) {
|
|
160
|
+
if (Object.prototype.hasOwnProperty.call(obj, key)) {
|
|
161
|
+
let value = obj[key];
|
|
78
162
|
if (value === void 0) {
|
|
79
|
-
|
|
80
|
-
}
|
|
81
|
-
const body = this.request.body ?? new FormData();
|
|
82
|
-
if (fileName) {
|
|
83
|
-
if (typeof value === "string") {
|
|
84
|
-
throw new Error("value must be a blob with content type set correctly.");
|
|
85
|
-
}
|
|
86
|
-
body.append(name, value, fileName);
|
|
87
|
-
}
|
|
88
|
-
else {
|
|
89
|
-
body.append(name, value);
|
|
90
|
-
}
|
|
91
|
-
return this.append({ body });
|
|
92
|
-
}
|
|
93
|
-
jsonBody(body, encode = true) {
|
|
94
|
-
if (encode) {
|
|
95
|
-
body = JSON.stringify(body);
|
|
96
|
-
}
|
|
97
|
-
const headers = this.request.headers ?? {};
|
|
98
|
-
headers["content-type"] = "application/json";
|
|
99
|
-
return this.append({ body, headers });
|
|
100
|
-
}
|
|
101
|
-
header(name, value) {
|
|
102
|
-
const headers = this.request.headers ?? {};
|
|
103
|
-
headers[name] = value;
|
|
104
|
-
return this.append({ headers });
|
|
105
|
-
}
|
|
106
|
-
path(name, value, encode = true) {
|
|
107
|
-
let url = this.request.url;
|
|
108
|
-
if (encode) {
|
|
109
|
-
value = encodeURIComponent(value);
|
|
163
|
+
continue;
|
|
110
164
|
}
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
return this;
|
|
165
|
+
if (encodeObjectAsJson) {
|
|
166
|
+
if (typeof value === "object" && value !== null) {
|
|
167
|
+
value = JSON.stringify(value);
|
|
168
|
+
}
|
|
169
|
+
encode = true;
|
|
117
170
|
}
|
|
118
|
-
let url = this.request.url;
|
|
119
171
|
if (encode) {
|
|
120
|
-
|
|
121
|
-
}
|
|
122
|
-
name = encodeURIComponent(name);
|
|
123
|
-
if (url.indexOf("?") === -1) {
|
|
124
|
-
url += `?${name}=${value}`;
|
|
125
|
-
}
|
|
126
|
-
else {
|
|
127
|
-
url += `&${name}=${value}`;
|
|
128
|
-
}
|
|
129
|
-
return this.append({ url });
|
|
130
|
-
}
|
|
131
|
-
queries(obj, encode = true, encodeObjectAsJson = true) {
|
|
132
|
-
let url = this.request.url;
|
|
133
|
-
let prefix = url.indexOf("?") === -1 ? "?" : "&";
|
|
134
|
-
for (const key in obj) {
|
|
135
|
-
if (Object.prototype.hasOwnProperty.call(obj, key)) {
|
|
136
|
-
let value = obj[key];
|
|
137
|
-
if (value === void 0) {
|
|
138
|
-
continue;
|
|
139
|
-
}
|
|
140
|
-
if (encodeObjectAsJson) {
|
|
141
|
-
if (typeof value === "object" && value !== null) {
|
|
142
|
-
value = JSON.stringify(value);
|
|
143
|
-
}
|
|
144
|
-
encode = true;
|
|
145
|
-
}
|
|
146
|
-
if (encode) {
|
|
147
|
-
value = encodeURIComponent(value);
|
|
148
|
-
}
|
|
149
|
-
const name = encodeURIComponent(key);
|
|
150
|
-
url += `${prefix}${name}=${value}`;
|
|
151
|
-
prefix = "&";
|
|
152
|
-
}
|
|
172
|
+
value = encodeURIComponent(value);
|
|
153
173
|
}
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
}
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
return
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
}
|
|
242
|
-
const result = await postProcessor(r, jsonPostProcessor);
|
|
243
|
-
if (log) {
|
|
244
|
-
log(`${r.status} ${r.statusText || "OK"}`);
|
|
245
|
-
log(result);
|
|
174
|
+
const name = encodeURIComponent(key);
|
|
175
|
+
url += `${prefix}${name}=${value}`;
|
|
176
|
+
prefix = "&";
|
|
177
|
+
}
|
|
178
|
+
}
|
|
179
|
+
return this.append({
|
|
180
|
+
url
|
|
181
|
+
});
|
|
182
|
+
}
|
|
183
|
+
async asText(ensureSuccess = true) {
|
|
184
|
+
const {
|
|
185
|
+
result
|
|
186
|
+
} = await this.asTextResponse(ensureSuccess);
|
|
187
|
+
return result;
|
|
188
|
+
}
|
|
189
|
+
async asBlob(ensureSuccess = true) {
|
|
190
|
+
const {
|
|
191
|
+
result
|
|
192
|
+
} = await this.asBlobResponse(ensureSuccess);
|
|
193
|
+
return result;
|
|
194
|
+
}
|
|
195
|
+
async asJson(ensureSuccess = true) {
|
|
196
|
+
const {
|
|
197
|
+
result
|
|
198
|
+
} = await this.asJsonResponse(ensureSuccess);
|
|
199
|
+
return result;
|
|
200
|
+
}
|
|
201
|
+
jsonPostProcessor(jsonPostProcessor) {
|
|
202
|
+
return this.append({
|
|
203
|
+
jsonPostProcessor
|
|
204
|
+
});
|
|
205
|
+
}
|
|
206
|
+
async asJsonResponse(ensureSuccess = true) {
|
|
207
|
+
return this.execute(ensureSuccess, async (x, jsonPostProcessor) => {
|
|
208
|
+
if (!/json/i.test(x.headers.get("content-type"))) {
|
|
209
|
+
throw new Error(`Failed to parse json from ${this.request.url}\n${await x.text()}`);
|
|
210
|
+
}
|
|
211
|
+
if (jsonPostProcessor) {
|
|
212
|
+
return x.json().then(jsonPostProcessor);
|
|
213
|
+
}
|
|
214
|
+
return x.json();
|
|
215
|
+
});
|
|
216
|
+
}
|
|
217
|
+
async asTextResponse(ensureSuccess = true) {
|
|
218
|
+
return this.execute(ensureSuccess, x => x.text());
|
|
219
|
+
}
|
|
220
|
+
asBlobResponse(ensureSuccess = true) {
|
|
221
|
+
return this.execute(ensureSuccess, x => x.blob());
|
|
222
|
+
}
|
|
223
|
+
dispatcher(dispatcher) {
|
|
224
|
+
return this.append({
|
|
225
|
+
dispatcher
|
|
226
|
+
});
|
|
227
|
+
}
|
|
228
|
+
withFetchProxy(fetchProxy) {
|
|
229
|
+
return this.append({
|
|
230
|
+
fetchProxy
|
|
231
|
+
});
|
|
232
|
+
}
|
|
233
|
+
async execute(ensureSuccess = true, postProcessor) {
|
|
234
|
+
const env_1 = {
|
|
235
|
+
stack: [],
|
|
236
|
+
error: void 0,
|
|
237
|
+
hasError: false
|
|
238
|
+
};
|
|
239
|
+
try {
|
|
240
|
+
let {
|
|
241
|
+
log,
|
|
242
|
+
logError,
|
|
243
|
+
hideBusyIndicator
|
|
244
|
+
} = this.request;
|
|
245
|
+
const _d = __addDisposableResource(env_1, !hideBusyIndicator ? App.current.createBusyIndicator() : null, false);
|
|
246
|
+
try {
|
|
247
|
+
const {
|
|
248
|
+
headers,
|
|
249
|
+
fetchProxy,
|
|
250
|
+
jsonPostProcessor
|
|
251
|
+
} = this.request;
|
|
252
|
+
const r = await (fetchProxy ?? fetch)(this.request.url, this.request);
|
|
253
|
+
if (ensureSuccess) {
|
|
254
|
+
if (r.status > 300) {
|
|
255
|
+
log = logError;
|
|
256
|
+
log?.(`fetch: ${this.request.method ?? "GET"} ${this.request.url}`);
|
|
257
|
+
if (log && headers) {
|
|
258
|
+
for (const key in headers) {
|
|
259
|
+
if (headers.hasOwnProperty(key)) {
|
|
260
|
+
log?.(`${key}: ${headers[key]}`);
|
|
246
261
|
}
|
|
247
|
-
|
|
262
|
+
}
|
|
248
263
|
}
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
264
|
+
log?.(`${r.status} ${r.statusText || "Http Error"}`);
|
|
265
|
+
const type = r.headers.get("content-type");
|
|
266
|
+
if (/\/json/i.test(type)) {
|
|
267
|
+
const json = await r.json();
|
|
268
|
+
log?.(json);
|
|
269
|
+
const message = json.title ?? json.detail ?? json.message ?? json.exceptionMessage ?? "Json Server Error";
|
|
270
|
+
log = null;
|
|
271
|
+
logError = null;
|
|
272
|
+
throw new JsonError(message, json);
|
|
252
273
|
}
|
|
274
|
+
const text = await r.text();
|
|
275
|
+
log?.(text);
|
|
276
|
+
log = null;
|
|
277
|
+
logError = null;
|
|
278
|
+
throw new Error(`Fetch failed with error ${r.status} for ${this.request.url}\n${text}`);
|
|
279
|
+
}
|
|
253
280
|
}
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
281
|
+
log?.(`${this.request.method ?? "GET"} ${this.request.url}`);
|
|
282
|
+
if (log && headers) {
|
|
283
|
+
for (const key in headers) {
|
|
284
|
+
if (headers.hasOwnProperty(key)) {
|
|
285
|
+
log?.(`${key}: ${headers[key]}`);
|
|
286
|
+
}
|
|
287
|
+
}
|
|
257
288
|
}
|
|
258
|
-
|
|
259
|
-
|
|
289
|
+
const result = await postProcessor(r, jsonPostProcessor);
|
|
290
|
+
if (log) {
|
|
291
|
+
log(`${r.status} ${r.statusText || "OK"}`);
|
|
292
|
+
log(result);
|
|
260
293
|
}
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
|
|
294
|
+
return {
|
|
295
|
+
result,
|
|
296
|
+
headers: r.headers,
|
|
297
|
+
status: r.status
|
|
298
|
+
};
|
|
299
|
+
} catch (error) {
|
|
300
|
+
log?.(error);
|
|
301
|
+
throw error;
|
|
302
|
+
}
|
|
303
|
+
} catch (e_1) {
|
|
304
|
+
env_1.error = e_1;
|
|
305
|
+
env_1.hasError = true;
|
|
306
|
+
} finally {
|
|
307
|
+
__disposeResources(env_1);
|
|
308
|
+
}
|
|
309
|
+
}
|
|
310
|
+
append(r) {
|
|
311
|
+
let {
|
|
312
|
+
url
|
|
313
|
+
} = this.request;
|
|
314
|
+
const {
|
|
315
|
+
url: newUrl
|
|
316
|
+
} = r;
|
|
317
|
+
if (newUrl) {
|
|
318
|
+
if (!url) {
|
|
319
|
+
url = newUrl;
|
|
320
|
+
} else {
|
|
321
|
+
if (/^https?\:\/\//i.test(newUrl)) {
|
|
322
|
+
url = newUrl;
|
|
323
|
+
} else {
|
|
324
|
+
let fullUrl = url;
|
|
325
|
+
if (!/^https?\:\/\//i.test(url)) {
|
|
326
|
+
fullUrl = new URL(url, location.href).toString();
|
|
327
|
+
}
|
|
328
|
+
url = new URL(newUrl, fullUrl).toString();
|
|
281
329
|
}
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
|
|
330
|
+
}
|
|
331
|
+
}
|
|
332
|
+
return new FetchBuilder({
|
|
333
|
+
...this.request,
|
|
334
|
+
...r,
|
|
335
|
+
url
|
|
336
|
+
});
|
|
337
|
+
}
|
|
288
338
|
}
|
|
289
339
|
class JsonError extends Error {
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
|
|
340
|
+
constructor(message, json) {
|
|
341
|
+
super(message);
|
|
342
|
+
this.json = json;
|
|
343
|
+
}
|
|
294
344
|
}
|
|
295
|
-
FetchBuilder.JsonError = JsonError;
|
|
296
|
-
//# sourceMappingURL=FetchBuilder.js.map
|
|
345
|
+
FetchBuilder.JsonError = JsonError;
|