@web-atoms/core 2.6.24 → 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 (120) hide show
  1. package/dist-esm/App.js +231 -235
  2. package/dist-esm/Atom.js +93 -96
  3. package/dist-esm/MockApp.js +17 -18
  4. package/dist-esm/Pack.js +1 -3
  5. package/dist-esm/core/AtomBinder.js +189 -187
  6. package/dist-esm/core/AtomComponent.js +479 -502
  7. package/dist-esm/core/AtomDispatcher.js +46 -48
  8. package/dist-esm/core/AtomDisposableList.js +24 -25
  9. package/dist-esm/core/AtomEnumerator.js +15 -16
  10. package/dist-esm/core/AtomList.js +193 -192
  11. package/dist-esm/core/AtomLoader.js +229 -215
  12. package/dist-esm/core/AtomMap.js +7 -8
  13. package/dist-esm/core/AtomOnce.js +22 -24
  14. package/dist-esm/core/AtomSelectableList.js +240 -243
  15. package/dist-esm/core/AtomUri.js +70 -72
  16. package/dist-esm/core/AtomWatcher.js +105 -111
  17. package/dist-esm/core/Bind.js +271 -269
  18. package/dist-esm/core/BindableProperty.js +26 -27
  19. package/dist-esm/core/CancelTokenFactory.js +21 -24
  20. package/dist-esm/core/Color.js +1 -2
  21. package/dist-esm/core/Colors.js +545 -231
  22. package/dist-esm/core/Command.js +236 -223
  23. package/dist-esm/core/Defer.js +21 -22
  24. package/dist-esm/core/EventScope.js +96 -88
  25. package/dist-esm/core/ExpressionParser.js +132 -144
  26. package/dist-esm/core/ExtendControl.js +7 -8
  27. package/dist-esm/core/FormattedError.js +7 -8
  28. package/dist-esm/core/FormattedString.js +4 -5
  29. package/dist-esm/core/Hacks.js +41 -42
  30. package/dist-esm/core/IFetchEvent.js +1 -2
  31. package/dist-esm/core/IScreen.js +1 -2
  32. package/dist-esm/core/IValueConverter.js +1 -2
  33. package/dist-esm/core/InheritedProperty.js +61 -63
  34. package/dist-esm/core/InjectProperty.js +12 -13
  35. package/dist-esm/core/KeyValuePairs.js +1 -2
  36. package/dist-esm/core/Markdown.js +14 -17
  37. package/dist-esm/core/MarkdownError.js +6 -7
  38. package/dist-esm/core/PropertyBinding.js +1 -2
  39. package/dist-esm/core/PropertyMap.js +28 -27
  40. package/dist-esm/core/Route.js +149 -148
  41. package/dist-esm/core/SingleInvoker.js +32 -35
  42. package/dist-esm/core/StringHelper.js +49 -51
  43. package/dist-esm/core/TransientDisposable.js +14 -16
  44. package/dist-esm/core/WatchProperty.js +18 -17
  45. package/dist-esm/core/WebImage.js +7 -8
  46. package/dist-esm/core/XNode.js +134 -117
  47. package/dist-esm/core/sleep.js +21 -24
  48. package/dist-esm/core/types.js +102 -103
  49. package/dist-esm/di/DISingleton.js +7 -5
  50. package/dist-esm/di/DITransient.js +7 -5
  51. package/dist-esm/di/IMockOrInject.js +1 -2
  52. package/dist-esm/di/IServiceProvider.js +1 -2
  53. package/dist-esm/di/Inject.js +67 -67
  54. package/dist-esm/di/Register.js +25 -26
  55. package/dist-esm/di/RegisterScoped.js +4 -3
  56. package/dist-esm/di/RegisterSingleton.js +4 -3
  57. package/dist-esm/di/ServiceCollection.js +38 -37
  58. package/dist-esm/di/ServiceProvider.js +94 -94
  59. package/dist-esm/di/TypeKey.js +13 -12
  60. package/dist-esm/services/BusyIndicatorService.js +7 -11
  61. package/dist-esm/services/CacheService.js +54 -62
  62. package/dist-esm/services/FetchBuilder.js +327 -278
  63. package/dist-esm/services/JsonService.js +118 -116
  64. package/dist-esm/services/MockNavigationService.js +127 -126
  65. package/dist-esm/services/NavigationService.js +95 -102
  66. package/dist-esm/services/ReferenceService.js +30 -33
  67. package/dist-esm/services/http/AjaxOptions.js +1 -3
  68. package/dist-esm/services/http/JsonError.js +16 -15
  69. package/dist-esm/services/http/RestService.js +314 -323
  70. package/dist-esm/style/StyleRule.js +1 -2
  71. package/dist-esm/test.js +0 -1
  72. package/dist-esm/unit/AtomTest.js +10 -11
  73. package/dist-esm/view-model/Action.js +258 -223
  74. package/dist-esm/view-model/AtomViewModel.js +234 -232
  75. package/dist-esm/view-model/AtomWindowViewModel.js +13 -14
  76. package/dist-esm/view-model/BindableUrlParameter.js +7 -8
  77. package/dist-esm/view-model/Delay.js +21 -25
  78. package/dist-esm/view-model/Disposable.js +28 -29
  79. package/dist-esm/view-model/Load.js +72 -73
  80. package/dist-esm/view-model/Once.js +33 -35
  81. package/dist-esm/view-model/baseTypes.js +4 -5
  82. package/dist-esm/view-model/bindPromise.js +24 -27
  83. package/dist-esm/view-model/bindProperty.js +3 -4
  84. package/dist-esm/view-model/bindUrlParameter.js +39 -43
  85. package/dist-esm/web/controls/AtomComboBox.js +56 -63
  86. package/dist-esm/web/controls/AtomControl.js +485 -490
  87. package/dist-esm/web/controls/AtomGridSplitter.js +57 -50
  88. package/dist-esm/web/controls/AtomGridView.js +230 -222
  89. package/dist-esm/web/controls/AtomItemsControl.js +677 -688
  90. package/dist-esm/web/controls/AtomPage.js +6 -7
  91. package/dist-esm/web/controls/AtomTemplate.js +1 -3
  92. package/dist-esm/web/controls/AtomTemplateControl.js +28 -29
  93. package/dist-esm/web/controls/AtomViewStack.js +19 -20
  94. package/dist-esm/web/core/AtomUI.js +200 -200
  95. package/dist-esm/web/core/Encoder.js +142 -152
  96. package/dist-esm/web/core/HtmlNode.js +141 -139
  97. package/dist-esm/web/images/Busy.js +1 -2
  98. package/dist-esm/web/images/BusyDataUrl.js +2 -869
  99. package/dist-esm/web/images/Button.js +1 -2
  100. package/dist-esm/web/images/ButtonDataUrl.js +2 -30
  101. package/dist-esm/web/images/CloseButton.js +1 -2
  102. package/dist-esm/web/images/CloseButtonDataUrl.js +2 -30
  103. package/dist-esm/web/images/CloseButtonHover.js +1 -2
  104. package/dist-esm/web/images/CloseButtonHoverDataUrl.js +2 -24
  105. package/dist-esm/web/services/LastTarget.js +31 -29
  106. package/dist-esm/web/services/MarkdownService.js +19 -31
  107. package/dist-esm/web/services/NotificationPopup.js +28 -21
  108. package/dist-esm/web/services/PopupService.js +512 -478
  109. package/dist-esm/web/services/PopupWindow.js +266 -247
  110. package/dist-esm/web/styles/AtomAlertWindowStyle.js +39 -40
  111. package/dist-esm/web/styles/AtomFrameStyle.js +15 -16
  112. package/dist-esm/web/styles/AtomNotificationStyle.js +19 -20
  113. package/dist-esm/web/styles/AtomPageLinkStyle.js +11 -12
  114. package/dist-esm/web/styles/AtomPopupStyle.js +9 -10
  115. package/dist-esm/web/styles/AtomStyle.js +61 -64
  116. package/dist-esm/web/styles/AtomStyleSheet.js +50 -51
  117. package/dist-esm/web/styles/AtomWindowStyle.js +116 -117
  118. package/dist-esm/web/styles/IStyleDeclaration.js +1 -2
  119. package/dist-esm/web/styles/StyleBuilder.js +79 -80
  120. package/package.json +1 -1
@@ -10,46 +10,46 @@ import CacheService from "../CacheService.js";
10
10
  import { JsonService } from "../JsonService.js";
11
11
  import JsonError from "./JsonError.js";
12
12
  function methodBuilder(method) {
13
- return function (url, options) {
14
- return function (target, propertyKey, descriptor) {
15
- target.methods = target.methods || {};
16
- const a = target.methods[propertyKey];
17
- const oldFunction = descriptor.value;
18
- descriptor.value = function (...args) {
19
- if (this.testMode || Atom.designMode) {
20
- console.log(`Test Design Mode: ${url} .. ${args.join(",")}`);
21
- const ro = oldFunction.apply(this, args);
22
- if (ro) {
23
- return ro;
24
- }
25
- }
26
- const jsCache = options ? options.jsCacheSeconds : 0;
27
- if (jsCache) {
28
- const cacheService = this.app.resolve(CacheService);
29
- const jArgs = args.map((arg) => arg instanceof CancelToken ? null : arg);
30
- const key = `${this.constructor.name}:${method}:${url}:${JSON.stringify(jArgs)}`;
31
- return cacheService.getOrCreate(key, (e) => {
32
- e.ttlSeconds = jsCache;
33
- return this.invoke(url, method, a, args, options);
34
- });
35
- }
36
- return this.invoke(url, method, a, args, options);
37
- };
38
- };
13
+ return function (url, options) {
14
+ return function (target, propertyKey, descriptor) {
15
+ target.methods = target.methods || {};
16
+ const a = target.methods[propertyKey];
17
+ const oldFunction = descriptor.value;
18
+ descriptor.value = function (...args) {
19
+ if (this.testMode || Atom.designMode) {
20
+ console.log(`Test Design Mode: ${url} .. ${args.join(",")}`);
21
+ const ro = oldFunction.apply(this, args);
22
+ if (ro) {
23
+ return ro;
24
+ }
25
+ }
26
+ const jsCache = options ? options.jsCacheSeconds : 0;
27
+ if (jsCache) {
28
+ const cacheService = this.app.resolve(CacheService);
29
+ const jArgs = args.map(arg => arg instanceof CancelToken ? null : arg);
30
+ const key = `${this.constructor.name}:${method}:${url}:${JSON.stringify(jArgs)}`;
31
+ return cacheService.getOrCreate(key, e => {
32
+ e.ttlSeconds = jsCache;
33
+ return this.invoke(url, method, a, args, options);
34
+ });
35
+ }
36
+ return this.invoke(url, method, a, args, options);
37
+ };
39
38
  };
39
+ };
40
40
  }
41
41
  function parameterBuilder(paramName, defaultValue) {
42
- return function (key) {
43
- return function (target, propertyKey, parameterIndex) {
44
- target.methods = target.methods || {};
45
- let a = target.methods[propertyKey];
46
- if (!a) {
47
- a = [];
48
- target.methods[propertyKey] = a;
49
- }
50
- a[parameterIndex] = new ServiceParameter(paramName, key, defaultValue);
51
- };
42
+ return function (key) {
43
+ return function (target, propertyKey, parameterIndex) {
44
+ target.methods = target.methods || {};
45
+ let a = target.methods[propertyKey];
46
+ if (!a) {
47
+ a = [];
48
+ target.methods[propertyKey] = a;
49
+ }
50
+ a[parameterIndex] = new ServiceParameter(paramName, key, defaultValue);
52
51
  };
52
+ };
53
53
  }
54
54
  export const Path = parameterBuilder("Path");
55
55
  export const Header = parameterBuilder("Header");
@@ -65,306 +65,297 @@ export const Delete = methodBuilder("Delete");
65
65
  export const Put = methodBuilder("Put");
66
66
  export const Patch = methodBuilder("Patch");
67
67
  export function Cancel(target, propertyKey, parameterIndex) {
68
- if (!target.methods) {
69
- target.methods = {};
70
- }
71
- let a = target.methods[propertyKey];
72
- if (!a) {
73
- a = [];
74
- target.methods[propertyKey] = a;
75
- }
76
- a[parameterIndex] = new ServiceParameter("cancel", "");
68
+ if (!target.methods) {
69
+ target.methods = {};
70
+ }
71
+ let a = target.methods[propertyKey];
72
+ if (!a) {
73
+ a = [];
74
+ target.methods[propertyKey] = a;
75
+ }
76
+ a[parameterIndex] = new ServiceParameter("cancel", "");
77
77
  }
78
78
  export class ServiceParameter {
79
- constructor(type, key, defaultValue) {
80
- this.type = type;
81
- this.key = key;
82
- this.defaultValue = defaultValue;
83
- this.type = type.toLowerCase();
84
- this.key = key;
85
- }
79
+ constructor(type, key, defaultValue) {
80
+ this.type = type;
81
+ this.key = key;
82
+ this.defaultValue = defaultValue;
83
+ this.type = type.toLowerCase();
84
+ this.key = key;
85
+ }
86
86
  }
87
87
  export default function BaseUrl(baseUrl) {
88
- return (target) => {
89
- const key = TypeKey.get(target);
90
- BaseService.baseUrls[key] = baseUrl;
91
- };
88
+ return target => {
89
+ const key = TypeKey.get(target);
90
+ BaseService.baseUrls[key] = baseUrl;
91
+ };
92
92
  }
93
- const globalNS = (typeof global !== "undefined") ? global : window;
93
+ const globalNS = typeof global !== "undefined" ? global : window;
94
94
  if (!globalNS.XMLHttpRequest) {
95
- globalNS.XMLHttpRequest = require("xmlhttprequest").XMLHttpRequest;
95
+ globalNS.XMLHttpRequest = require("xmlhttprequest").XMLHttpRequest;
96
96
  }
97
97
  let BaseService = class BaseService {
98
- static { BaseService_1 = this; }
99
- static { this.baseUrls = {}; }
100
- constructor(app, jsonService) {
101
- this.app = app;
102
- this.jsonService = jsonService;
103
- this.testMode = false;
104
- this.showProgress = true;
105
- this.showError = false;
106
- this.methods = {};
107
- this.methodReturns = {};
108
- this.jsonOptions = null;
109
- this.headers = null;
110
- this.jsonOptions = {
111
- ...this.jsonService.options
112
- };
113
- }
114
- encodeData(o) {
115
- o.dataType = "application/json";
116
- o.data = this.jsonService.stringify(o.data, this.jsonOptions);
117
- o.contentType = "application/json";
118
- return o;
119
- }
120
- sendResult(result, error) {
121
- return new Promise((resolve, reject) => {
122
- if (error) {
123
- setTimeout(() => {
124
- reject(error);
125
- }, 1);
126
- return;
127
- }
128
- setTimeout(() => {
129
- resolve(result);
130
- }, 1);
131
- });
132
- }
133
- async invoke(url, method, bag, values, methodOptions) {
134
- const env_1 = { stack: [], error: void 0, hasError: false };
135
- try {
136
- if (this.baseUrl === undefined) {
137
- let p = Object.getPrototypeOf(this);
138
- while (p) {
139
- const t = TypeKey.get(p.constructor || p);
140
- const bu = BaseService_1.baseUrls[t];
141
- if (bu) {
142
- this.baseUrl = bu;
143
- break;
144
- }
145
- p = Object.getPrototypeOf(p);
146
- }
147
- if (this.baseUrl === undefined) {
148
- this.baseUrl = null;
149
- }
150
- }
151
- if (this.baseUrl) {
152
- if (!/^\//.test(url)) {
153
- url = `${this.baseUrl}${url}`;
154
- }
155
- }
156
- const _busyIndicator = __addDisposableResource(env_1, this.showProgress ? (this.app.createBusyIndicator({
157
- title: url,
158
- description: `${method} ${url}`
159
- })) : null, false);
160
- url = UMD.resolvePath(url);
161
- let options = new AjaxOptions();
162
- options.method = method;
163
- if (methodOptions) {
164
- options.headers = methodOptions.headers;
165
- options.dataType = methodOptions.accept;
166
- }
167
- const methodHeaders = (options.headers = options.headers || {});
168
- const headers = this.headers
169
- ? ({ ...this.headers, ...methodHeaders })
170
- : methodHeaders;
171
- if (!headers["X-Requested-With"]) {
172
- headers["X-Requested-With"] = "XMLHttpRequest";
173
- }
174
- options.dataType = options.dataType || "application/json";
175
- const jsonOptions = {
176
- ...this.jsonOptions,
177
- ...(methodOptions ? methodOptions.jsonOptions : {})
178
- };
179
- if (bag) {
180
- for (let i = 0; i < bag.length; i++) {
181
- const p = bag[i];
182
- const vi = values[i];
183
- const v = vi === undefined ? p.defaultValue : vi;
184
- if (v instanceof CancelToken) {
185
- options.cancel = v;
186
- continue;
187
- }
188
- switch (p.type) {
189
- case "path":
190
- if (v === undefined) {
191
- continue;
192
- }
193
- const vs = v + "";
194
- const replacer = `{${p.key}}`;
195
- url = url.split(replacer).join(vs);
196
- break;
197
- case "query":
198
- if (v === undefined) {
199
- continue;
200
- }
201
- if (url.indexOf("?") === -1) {
202
- url += "?";
203
- }
204
- if (!/(\&|\?)$/.test(url)) {
205
- url += "&";
206
- }
207
- url += `${encodeURIComponent(p.key)}=${encodeURIComponent(v)}`;
208
- break;
209
- case "queries":
210
- if (url.indexOf("?") === -1) {
211
- url += "?";
212
- }
213
- if (!/(\&|\?)$/.test(url)) {
214
- url += "&";
215
- }
216
- for (const key in v) {
217
- if (v.hasOwnProperty(key)) {
218
- const element = v[key];
219
- if (element !== undefined) {
220
- url += `${encodeURIComponent(key)}=${encodeURIComponent(element)}&`;
221
- }
222
- }
223
- }
224
- break;
225
- case "body":
226
- options.data = v;
227
- options = this.encodeData(options);
228
- break;
229
- case "bodyformmodel":
230
- options.data = v;
231
- break;
232
- case "rawbody":
233
- options.data = v;
234
- break;
235
- case "xmlbody":
236
- options.contentType = "text/xml";
237
- options.data = v;
238
- break;
239
- case "cancel":
240
- options.cancel = v;
241
- break;
242
- case "header":
243
- if (v === undefined) {
244
- continue;
245
- }
246
- headers[p.key] = v;
247
- break;
248
- }
249
- }
250
- }
251
- options.url = url;
252
- const xhr = await this.ajax(url, options);
253
- if (/json/i.test(xhr.responseType)) {
254
- const text = xhr.responseText;
255
- const response = this.jsonService.parse(text, jsonOptions);
256
- if (xhr.status >= 400) {
257
- throw new JsonError(typeof response === "string"
258
- ? response
259
- : (response.title
260
- ?? response.detail
261
- ?? response.message
262
- ?? response.exceptionMessage
263
- ?? text
264
- ?? "Json Server Error"), response);
265
- }
266
- if (methodOptions && methodOptions.returnHeaders) {
267
- return {
268
- headers: this.parseHeaders(xhr.responseHeaders),
269
- value: response
270
- };
98
+ static {
99
+ BaseService_1 = this;
100
+ }
101
+ static {
102
+ this.baseUrls = {};
103
+ }
104
+ constructor(app, jsonService) {
105
+ this.app = app;
106
+ this.jsonService = jsonService;
107
+ this.testMode = false;
108
+ this.showProgress = true;
109
+ this.showError = false;
110
+ this.methods = {};
111
+ this.methodReturns = {};
112
+ this.jsonOptions = null;
113
+ this.headers = null;
114
+ this.jsonOptions = {
115
+ ...this.jsonService.options
116
+ };
117
+ }
118
+ encodeData(o) {
119
+ o.dataType = "application/json";
120
+ o.data = this.jsonService.stringify(o.data, this.jsonOptions);
121
+ o.contentType = "application/json";
122
+ return o;
123
+ }
124
+ sendResult(result, error) {
125
+ return new Promise((resolve, reject) => {
126
+ if (error) {
127
+ setTimeout(() => {
128
+ reject(error);
129
+ }, 1);
130
+ return;
131
+ }
132
+ setTimeout(() => {
133
+ resolve(result);
134
+ }, 1);
135
+ });
136
+ }
137
+ async invoke(url, method, bag, values, methodOptions) {
138
+ const env_1 = {
139
+ stack: [],
140
+ error: void 0,
141
+ hasError: false
142
+ };
143
+ try {
144
+ if (this.baseUrl === undefined) {
145
+ let p = Object.getPrototypeOf(this);
146
+ while (p) {
147
+ const t = TypeKey.get(p.constructor || p);
148
+ const bu = BaseService_1.baseUrls[t];
149
+ if (bu) {
150
+ this.baseUrl = bu;
151
+ break;
152
+ }
153
+ p = Object.getPrototypeOf(p);
154
+ }
155
+ if (this.baseUrl === undefined) {
156
+ this.baseUrl = null;
157
+ }
158
+ }
159
+ if (this.baseUrl) {
160
+ if (!/^\//.test(url)) {
161
+ url = `${this.baseUrl}${url}`;
162
+ }
163
+ }
164
+ const _busyIndicator = __addDisposableResource(env_1, this.showProgress ? this.app.createBusyIndicator({
165
+ title: url,
166
+ description: `${method} ${url}`
167
+ }) : null, false);
168
+ url = UMD.resolvePath(url);
169
+ let options = new AjaxOptions();
170
+ options.method = method;
171
+ if (methodOptions) {
172
+ options.headers = methodOptions.headers;
173
+ options.dataType = methodOptions.accept;
174
+ }
175
+ const methodHeaders = options.headers = options.headers || {};
176
+ const headers = this.headers ? {
177
+ ...this.headers,
178
+ ...methodHeaders
179
+ } : methodHeaders;
180
+ if (!headers["X-Requested-With"]) {
181
+ headers["X-Requested-With"] = "XMLHttpRequest";
182
+ }
183
+ options.dataType = options.dataType || "application/json";
184
+ const jsonOptions = {
185
+ ...this.jsonOptions,
186
+ ...(methodOptions ? methodOptions.jsonOptions : {})
187
+ };
188
+ if (bag) {
189
+ for (let i = 0; i < bag.length; i++) {
190
+ const p = bag[i];
191
+ const vi = values[i];
192
+ const v = vi === undefined ? p.defaultValue : vi;
193
+ if (v instanceof CancelToken) {
194
+ options.cancel = v;
195
+ continue;
196
+ }
197
+ switch (p.type) {
198
+ case "path":
199
+ if (v === undefined) {
200
+ continue;
201
+ }
202
+ const vs = v + "";
203
+ const replacer = `{${p.key}}`;
204
+ url = url.split(replacer).join(vs);
205
+ break;
206
+ case "query":
207
+ if (v === undefined) {
208
+ continue;
209
+ }
210
+ if (url.indexOf("?") === -1) {
211
+ url += "?";
212
+ }
213
+ if (!/(\&|\?)$/.test(url)) {
214
+ url += "&";
215
+ }
216
+ url += `${encodeURIComponent(p.key)}=${encodeURIComponent(v)}`;
217
+ break;
218
+ case "queries":
219
+ if (url.indexOf("?") === -1) {
220
+ url += "?";
221
+ }
222
+ if (!/(\&|\?)$/.test(url)) {
223
+ url += "&";
224
+ }
225
+ for (const key in v) {
226
+ if (v.hasOwnProperty(key)) {
227
+ const element = v[key];
228
+ if (element !== undefined) {
229
+ url += `${encodeURIComponent(key)}=${encodeURIComponent(element)}&`;
230
+ }
271
231
  }
272
- return response;
273
- }
274
- if (xhr.status >= 400) {
275
- throw new Error(xhr.responseText || "Server Error");
276
- }
277
- if (methodOptions && methodOptions.returnHeaders) {
278
- return {
279
- headers: this.parseHeaders(xhr.responseHeaders),
280
- value: xhr.responseText
281
- };
282
- }
283
- return xhr.responseText;
232
+ }
233
+ break;
234
+ case "body":
235
+ options.data = v;
236
+ options = this.encodeData(options);
237
+ break;
238
+ case "bodyformmodel":
239
+ options.data = v;
240
+ break;
241
+ case "rawbody":
242
+ options.data = v;
243
+ break;
244
+ case "xmlbody":
245
+ options.contentType = "text/xml";
246
+ options.data = v;
247
+ break;
248
+ case "cancel":
249
+ options.cancel = v;
250
+ break;
251
+ case "header":
252
+ if (v === undefined) {
253
+ continue;
254
+ }
255
+ headers[p.key] = v;
256
+ break;
257
+ }
284
258
  }
285
- catch (e_1) {
286
- env_1.error = e_1;
287
- env_1.hasError = true;
259
+ }
260
+ options.url = url;
261
+ const xhr = await this.ajax(url, options);
262
+ if (/json/i.test(xhr.responseType)) {
263
+ const text = xhr.responseText;
264
+ const response = this.jsonService.parse(text, jsonOptions);
265
+ if (xhr.status >= 400) {
266
+ throw new JsonError(typeof response === "string" ? response : response.title ?? response.detail ?? response.message ?? response.exceptionMessage ?? text ?? "Json Server Error", response);
288
267
  }
289
- finally {
290
- __disposeResources(env_1);
268
+ if (methodOptions && methodOptions.returnHeaders) {
269
+ return {
270
+ headers: this.parseHeaders(xhr.responseHeaders),
271
+ value: response
272
+ };
291
273
  }
274
+ return response;
275
+ }
276
+ if (xhr.status >= 400) {
277
+ throw new Error(xhr.responseText || "Server Error");
278
+ }
279
+ if (methodOptions && methodOptions.returnHeaders) {
280
+ return {
281
+ headers: this.parseHeaders(xhr.responseHeaders),
282
+ value: xhr.responseText
283
+ };
284
+ }
285
+ return xhr.responseText;
286
+ } catch (e_1) {
287
+ env_1.error = e_1;
288
+ env_1.hasError = true;
289
+ } finally {
290
+ __disposeResources(env_1);
292
291
  }
293
- parseHeaders(headers) {
294
- if (typeof headers === "object") {
295
- return headers;
296
- }
297
- return (headers || "")
298
- .split("\n")
299
- .reduce((pv, c) => {
300
- const cv = c.split(":");
301
- pv[cv[0]] = (cv[1] || "").trim();
302
- return pv;
303
- }, {});
292
+ }
293
+ parseHeaders(headers) {
294
+ if (typeof headers === "object") {
295
+ return headers;
304
296
  }
305
- async ajax(url, options) {
306
- url = url || options.url;
307
- if (options.cancel && options.cancel.cancelled) {
308
- throw new Error("cancelled");
309
- }
310
- const xhr = new XMLHttpRequest();
311
- return await new Promise((resolve, reject) => {
312
- if (options.cancel && options.cancel.cancelled) {
313
- reject(options.cancel.cancelled);
314
- return;
315
- }
316
- if (options.cancel) {
317
- options.cancel.registerForCancel((r) => {
318
- xhr.abort();
319
- reject(r);
320
- return;
321
- });
322
- }
323
- xhr.onreadystatechange = (e) => {
324
- if (xhr.readyState === XMLHttpRequest.DONE) {
325
- options.status = xhr.status;
326
- options.responseText = xhr.responseText;
327
- options.responseHeaders = xhr.getAllResponseHeaders();
328
- const ct = xhr.getResponseHeader("content-type");
329
- options.responseType = ct || xhr.responseType;
330
- resolve(options);
331
- }
332
- };
333
- xhr.open(options.method, url, true);
334
- if (options.dataType) {
335
- xhr.setRequestHeader("accept", options.dataType);
336
- }
337
- if (options.contentType) {
338
- xhr.setRequestHeader("content-type", options.contentType);
339
- }
340
- const h = options.headers;
341
- if (h) {
342
- for (const key in h) {
343
- if (h.hasOwnProperty(key)) {
344
- const element = h[key];
345
- xhr.setRequestHeader(key, element.toString());
346
- }
347
- }
348
- }
349
- try {
350
- xhr.send(options.data);
351
- }
352
- catch (e) {
353
- options.status = xhr.status;
354
- options.responseText = xhr.responseText;
355
- options.responseHeaders = xhr.getAllResponseHeaders();
356
- const ct = xhr.getResponseHeader("content-type");
357
- options.responseType = ct || xhr.responseType;
358
- resolve(options);
359
- }
360
- });
297
+ return (headers || "").split("\n").reduce((pv, c) => {
298
+ const cv = c.split(":");
299
+ pv[cv[0]] = (cv[1] || "").trim();
300
+ return pv;
301
+ }, {});
302
+ }
303
+ async ajax(url, options) {
304
+ url = url || options.url;
305
+ if (options.cancel && options.cancel.cancelled) {
306
+ throw new Error("cancelled");
361
307
  }
308
+ const xhr = new XMLHttpRequest();
309
+ return await new Promise((resolve, reject) => {
310
+ if (options.cancel && options.cancel.cancelled) {
311
+ reject(options.cancel.cancelled);
312
+ return;
313
+ }
314
+ if (options.cancel) {
315
+ options.cancel.registerForCancel(r => {
316
+ xhr.abort();
317
+ reject(r);
318
+ return;
319
+ });
320
+ }
321
+ xhr.onreadystatechange = e => {
322
+ if (xhr.readyState === XMLHttpRequest.DONE) {
323
+ options.status = xhr.status;
324
+ options.responseText = xhr.responseText;
325
+ options.responseHeaders = xhr.getAllResponseHeaders();
326
+ const ct = xhr.getResponseHeader("content-type");
327
+ options.responseType = ct || xhr.responseType;
328
+ resolve(options);
329
+ }
330
+ };
331
+ xhr.open(options.method, url, true);
332
+ if (options.dataType) {
333
+ xhr.setRequestHeader("accept", options.dataType);
334
+ }
335
+ if (options.contentType) {
336
+ xhr.setRequestHeader("content-type", options.contentType);
337
+ }
338
+ const h = options.headers;
339
+ if (h) {
340
+ for (const key in h) {
341
+ if (h.hasOwnProperty(key)) {
342
+ const element = h[key];
343
+ xhr.setRequestHeader(key, element.toString());
344
+ }
345
+ }
346
+ }
347
+ try {
348
+ xhr.send(options.data);
349
+ } catch (e) {
350
+ options.status = xhr.status;
351
+ options.responseText = xhr.responseText;
352
+ options.responseHeaders = xhr.getAllResponseHeaders();
353
+ const ct = xhr.getResponseHeader("content-type");
354
+ options.responseType = ct || xhr.responseType;
355
+ resolve(options);
356
+ }
357
+ });
358
+ }
362
359
  };
363
- BaseService = BaseService_1 = __decorate([
364
- __param(0, Inject),
365
- __param(1, Inject),
366
- __metadata("design:paramtypes", [App,
367
- JsonService])
368
- ], BaseService);
369
- export { BaseService };
370
- //# sourceMappingURL=RestService.js.map
360
+ BaseService = BaseService_1 = __decorate([__param(0, Inject), __param(1, Inject), __metadata("design:paramtypes", [App, JsonService])], BaseService);
361
+ export { BaseService };