@web-atoms/core 2.4.71 → 2.5.2

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 (39) hide show
  1. package/dist/App.d.ts +1 -1
  2. package/dist/App.d.ts.map +1 -1
  3. package/dist/App.js +3 -3
  4. package/dist/App.js.map +1 -1
  5. package/dist/core/AtomLoader.d.ts.map +1 -1
  6. package/dist/core/AtomLoader.js +42 -16
  7. package/dist/core/AtomLoader.js.map +1 -1
  8. package/dist/core/types.d.ts +1 -0
  9. package/dist/core/types.d.ts.map +1 -1
  10. package/dist/core/types.js +5 -1
  11. package/dist/core/types.js.map +1 -1
  12. package/dist/services/BusyIndicatorService.d.ts +1 -2
  13. package/dist/services/BusyIndicatorService.d.ts.map +1 -1
  14. package/dist/services/BusyIndicatorService.js +1 -1
  15. package/dist/services/BusyIndicatorService.js.map +1 -1
  16. package/dist/services/FetchBuilder.d.ts.map +1 -1
  17. package/dist/services/FetchBuilder.js +21 -12
  18. package/dist/services/FetchBuilder.js.map +1 -1
  19. package/dist/services/http/RestService.d.ts.map +1 -1
  20. package/dist/services/http/RestService.js +34 -26
  21. package/dist/services/http/RestService.js.map +1 -1
  22. package/dist/tsconfig.tsbuildinfo +1 -1
  23. package/dist/view-model/Action.d.ts.map +1 -1
  24. package/dist/view-model/Action.js +7 -4
  25. package/dist/view-model/Action.js.map +1 -1
  26. package/dist/web/services/WebBusyIndicatorService.d.ts +1 -2
  27. package/dist/web/services/WebBusyIndicatorService.d.ts.map +1 -1
  28. package/dist/web/services/WebBusyIndicatorService.js +5 -1
  29. package/dist/web/services/WebBusyIndicatorService.js.map +1 -1
  30. package/package.json +2 -2
  31. package/src/App.ts +4 -4
  32. package/src/core/AtomLoader.ts +139 -151
  33. package/src/core/types.ts +7 -0
  34. package/src/services/BusyIndicatorService.ts +2 -2
  35. package/src/services/FetchBuilder.ts +44 -49
  36. package/src/services/http/RestService.ts +119 -125
  37. package/src/view-model/Action.ts +6 -4
  38. package/src/web/services/WebBusyIndicatorService.ts +6 -2
  39. package/tsconfig.json +2 -1
@@ -456,157 +456,151 @@ export class BaseService {
456
456
  }
457
457
  }
458
458
 
459
- const busyIndicator = this.showProgress ? ( this.app.createBusyIndicator({
459
+ using _busyIndicator = this.showProgress ? ( this.app.createBusyIndicator({
460
460
  title: url,
461
461
  description: `${method} ${url}`
462
462
  }) ) : null;
463
463
 
464
- try {
465
464
 
466
- url = UMD.resolvePath(url);
465
+ url = UMD.resolvePath(url);
467
466
 
468
- let options: AjaxOptions = new AjaxOptions();
469
- options.method = method;
467
+ let options: AjaxOptions = new AjaxOptions();
468
+ options.method = method;
470
469
 
471
- if (methodOptions) {
472
- options.headers = methodOptions.headers;
473
- options.dataType = methodOptions.accept;
474
- }
470
+ if (methodOptions) {
471
+ options.headers = methodOptions.headers;
472
+ options.dataType = methodOptions.accept;
473
+ }
475
474
 
476
- const methodHeaders = (options.headers = options.headers || {});
475
+ const methodHeaders = (options.headers = options.headers || {});
477
476
 
478
- const headers = this.headers
479
- ? ({ ... this.headers, ... methodHeaders })
480
- : methodHeaders;
477
+ const headers = this.headers
478
+ ? ({ ... this.headers, ... methodHeaders })
479
+ : methodHeaders;
481
480
 
482
- // this is necessary to support IsAjaxRequest in ASP.NET MVC
483
- if (!headers["X-Requested-With"]) {
484
- headers["X-Requested-With"] = "XMLHttpRequest";
485
- }
481
+ // this is necessary to support IsAjaxRequest in ASP.NET MVC
482
+ if (!headers["X-Requested-With"]) {
483
+ headers["X-Requested-With"] = "XMLHttpRequest";
484
+ }
486
485
 
487
- options.dataType = options.dataType || "application/json";
486
+ options.dataType = options.dataType || "application/json";
488
487
 
489
- const jsonOptions = {
490
- ... this.jsonOptions,
491
- ... (methodOptions ? methodOptions.jsonOptions : {})
492
- };
488
+ const jsonOptions = {
489
+ ... this.jsonOptions,
490
+ ... (methodOptions ? methodOptions.jsonOptions : {})
491
+ };
493
492
 
494
- if (bag) {
493
+ if (bag) {
495
494
 
496
- for (let i: number = 0; i < bag.length; i++) {
497
- const p: ServiceParameter = bag[i];
498
- const vi = values[i];
499
- const v: any = vi === undefined ? p.defaultValue : vi;
500
- if (v instanceof CancelToken) {
501
- options.cancel = v;
502
- continue;
503
- }
504
- switch (p.type) {
505
- case "path":
506
- if (v === undefined) {
507
- continue;
508
- }
509
- const vs: string = v + "";
510
- const replacer = `{${p.key}}`;
511
- url = url.split(replacer).join(vs);
512
- break;
513
- case "query":
514
- if (v === undefined) {
515
- continue;
516
- }
517
- if (url.indexOf("?") === -1) {
518
- url += "?";
519
- }
520
- if (! /(\&|\?)$/.test(url)) {
521
- url += "&";
522
- }
523
- url += `${encodeURIComponent(p.key)}=${encodeURIComponent(v)}`;
524
- break;
525
- case "queries":
526
- if (url.indexOf("?") === -1) {
527
- url += "?";
528
- }
529
- if (! /(\&|\?)$/.test(url)) {
530
- url += "&";
531
- }
532
- for (const key in v) {
533
- if (v.hasOwnProperty(key)) {
534
- const element = v[key];
535
- if (element !== undefined) {
536
- url += `${encodeURIComponent(key)}=${encodeURIComponent(element)}&`;
537
- }
495
+ for (let i: number = 0; i < bag.length; i++) {
496
+ const p: ServiceParameter = bag[i];
497
+ const vi = values[i];
498
+ const v: any = vi === undefined ? p.defaultValue : vi;
499
+ if (v instanceof CancelToken) {
500
+ options.cancel = v;
501
+ continue;
502
+ }
503
+ switch (p.type) {
504
+ case "path":
505
+ if (v === undefined) {
506
+ continue;
507
+ }
508
+ const vs: string = v + "";
509
+ const replacer = `{${p.key}}`;
510
+ url = url.split(replacer).join(vs);
511
+ break;
512
+ case "query":
513
+ if (v === undefined) {
514
+ continue;
515
+ }
516
+ if (url.indexOf("?") === -1) {
517
+ url += "?";
518
+ }
519
+ if (! /(\&|\?)$/.test(url)) {
520
+ url += "&";
521
+ }
522
+ url += `${encodeURIComponent(p.key)}=${encodeURIComponent(v)}`;
523
+ break;
524
+ case "queries":
525
+ if (url.indexOf("?") === -1) {
526
+ url += "?";
527
+ }
528
+ if (! /(\&|\?)$/.test(url)) {
529
+ url += "&";
530
+ }
531
+ for (const key in v) {
532
+ if (v.hasOwnProperty(key)) {
533
+ const element = v[key];
534
+ if (element !== undefined) {
535
+ url += `${encodeURIComponent(key)}=${encodeURIComponent(element)}&`;
538
536
  }
539
537
  }
540
- break;
541
- case "body":
542
- options.data = v;
543
- options = this.encodeData(options);
544
- break;
545
- case "bodyformmodel":
546
- options.data = v;
547
- break;
548
- case "rawbody":
549
- options.data = v;
550
- break;
551
- case "xmlbody":
552
- options.contentType = "text/xml";
553
- options.data = v;
554
- break;
555
- case "cancel":
556
- options.cancel = v as CancelToken;
557
- break;
558
- case "header":
559
- if (v === undefined) {
560
- continue;
561
- }
562
- headers[p.key] = v;
563
- break;
564
- }
565
- }
566
- }
567
- options.url = url;
568
-
569
- const xhr = await this.ajax(url, options);
570
-
571
- if (/json/i.test(xhr.responseType)) {
572
- const text = xhr.responseText;
573
- const response = this.jsonService.parse(text, jsonOptions );
574
-
575
- if (xhr.status >= 400) {
576
- throw new JsonError(
577
- typeof response === "string"
578
- ? response
579
- : ( response.title
580
- ?? response.detail
581
- ?? response.message
582
- ?? response.exceptionMessage
583
- ?? text
584
- ?? "Json Server Error"), response);
585
- }
586
- if (methodOptions && methodOptions.returnHeaders) {
587
- return {
588
- headers: this.parseHeaders(xhr.responseHeaders),
589
- value: response
590
- };
538
+ }
539
+ break;
540
+ case "body":
541
+ options.data = v;
542
+ options = this.encodeData(options);
543
+ break;
544
+ case "bodyformmodel":
545
+ options.data = v;
546
+ break;
547
+ case "rawbody":
548
+ options.data = v;
549
+ break;
550
+ case "xmlbody":
551
+ options.contentType = "text/xml";
552
+ options.data = v;
553
+ break;
554
+ case "cancel":
555
+ options.cancel = v as CancelToken;
556
+ break;
557
+ case "header":
558
+ if (v === undefined) {
559
+ continue;
560
+ }
561
+ headers[p.key] = v;
562
+ break;
591
563
  }
592
- return response;
593
564
  }
565
+ }
566
+ options.url = url;
567
+
568
+ const xhr = await this.ajax(url, options);
569
+
570
+ if (/json/i.test(xhr.responseType)) {
571
+ const text = xhr.responseText;
572
+ const response = this.jsonService.parse(text, jsonOptions );
573
+
594
574
  if (xhr.status >= 400) {
595
- throw new Error(xhr.responseText || "Server Error");
575
+ throw new JsonError(
576
+ typeof response === "string"
577
+ ? response
578
+ : ( response.title
579
+ ?? response.detail
580
+ ?? response.message
581
+ ?? response.exceptionMessage
582
+ ?? text
583
+ ?? "Json Server Error"), response);
596
584
  }
597
-
598
585
  if (methodOptions && methodOptions.returnHeaders) {
599
586
  return {
600
587
  headers: this.parseHeaders(xhr.responseHeaders),
601
- value: xhr.responseText
588
+ value: response
602
589
  };
603
590
  }
604
- return xhr.responseText;
605
- } finally {
606
- if (busyIndicator) {
607
- busyIndicator.dispose();
608
- }
591
+ return response;
592
+ }
593
+ if (xhr.status >= 400) {
594
+ throw new Error(xhr.responseText || "Server Error");
595
+ }
596
+
597
+ if (methodOptions && methodOptions.returnHeaders) {
598
+ return {
599
+ headers: this.parseHeaders(xhr.responseHeaders),
600
+ value: xhr.responseText
601
+ };
609
602
  }
603
+ return xhr.responseText;
610
604
 
611
605
  }
612
606
 
@@ -3,7 +3,7 @@ import Command from "../core/Command";
3
3
  import EventScope from "../core/EventScope";
4
4
  import FormattedString from "../core/FormattedString";
5
5
  import { StringHelper } from "../core/StringHelper";
6
- import { CancelToken } from "../core/types";
6
+ import { CancelToken, errorHandled } from "../core/types";
7
7
  import XNode from "../core/XNode";
8
8
  import JsonError from "../services/http/JsonError";
9
9
  import { NavigationService, NotifyType } from "../services/NavigationService";
@@ -384,12 +384,13 @@ export default function Action(
384
384
  return result;
385
385
  } catch (e) {
386
386
  if (CancelToken.isCancelled(e)) {
387
- return;
387
+ throw e;
388
388
  }
389
+ e[errorHandled] = true;
389
390
  if (/^timeout$/i.test(e.toString().trim())) {
390
391
  // tslint:disable-next-line: no-console
391
392
  console.warn(e);
392
- return;
393
+ throw e;
393
394
  }
394
395
  if (e instanceof JsonError) {
395
396
  if (e.details) {
@@ -398,10 +399,11 @@ export default function Action(
398
399
  title: "Error",
399
400
  detail: e.details
400
401
  });
401
- return;
402
+ throw e;
402
403
  }
403
404
  }
404
405
  await ns.alert(e, "Error");
406
+ throw e;
405
407
  }
406
408
  };
407
409
 
@@ -21,7 +21,7 @@ export class WebBusyIndicatorService extends BusyIndicatorService {
21
21
 
22
22
  private indicators: number = 0;
23
23
 
24
- public createIndicator(): IDisposable {
24
+ public createIndicator(): Disposable {
25
25
 
26
26
  const host = document.createElement("div");
27
27
  const popup = new AtomControl(this.app, host);
@@ -70,6 +70,10 @@ export class WebBusyIndicatorService extends BusyIndicatorService {
70
70
  }
71
71
  });
72
72
 
73
- return popup;
73
+ return {
74
+ [Symbol.dispose]() {
75
+ popup.dispose();
76
+ }
77
+ }
74
78
  }
75
79
  }
package/tsconfig.json CHANGED
@@ -16,7 +16,8 @@
16
16
  "jsxFactory": "XNode.create",
17
17
  "lib": [
18
18
  "es6",
19
- "dom"
19
+ "dom",
20
+ "ESNext.Disposable"
20
21
  ]
21
22
  },
22
23
  "include": [