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