angular-toolbox 0.10.2 → 0.11.1

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.
@@ -3,8 +3,8 @@ import { Injectable, NgModule, EventEmitter, Component, Directive, Output, Input
3
3
  import * as i1 from '@angular/router';
4
4
  import { RouterModule } from '@angular/router';
5
5
  import { DOCUMENT, XhrFactory } from '@angular/common';
6
- import { HttpStatusCode, HttpHeaders, HttpRequest } from '@angular/common/http';
7
- import { Observable, of } from 'rxjs';
6
+ import { HttpStatusCode, HttpHeaders, HttpErrorResponse, HttpParams, HttpRequest } from '@angular/common/http';
7
+ import { from, Observable, of } from 'rxjs';
8
8
  import * as i1$1 from '@angular/platform-browser';
9
9
 
10
10
  /**
@@ -542,9 +542,9 @@ class AbstractVersionManager {
542
542
  */
543
543
  const LAYERS_VERSION_CONFIG = {
544
544
  major: 0,
545
- minor: 10,
546
- patch: 2,
547
- buildTimestamp: 1721804425756,
545
+ minor: 11,
546
+ patch: 1,
547
+ buildTimestamp: 1722003985958,
548
548
  metadata: "beta"
549
549
  };
550
550
  /**
@@ -1393,6 +1393,14 @@ const DARK_MODE_CONFIG = {
1393
1393
  * the LICENSE file at https://pascalechemann.com/angular-toolbox/resources/license
1394
1394
  */
1395
1395
 
1396
+ /**
1397
+ * @license
1398
+ * Copyright Pascal ECHEMANN. All Rights Reserved.
1399
+ *
1400
+ * Use of this source code is governed by an MIT-style license that can be found in
1401
+ * the LICENSE file at https://pascalechemann.com/angular-toolbox/resources/license
1402
+ */
1403
+
1396
1404
  /**
1397
1405
  * @license
1398
1406
  * Copyright Pascal ECHEMANN. All Rights Reserved.
@@ -2733,7 +2741,8 @@ class HttpMockService {
2733
2741
  if (regexp.test(route)) {
2734
2742
  result = {
2735
2743
  methodConfig: methodMap.methodMock,
2736
- parameters: this.buildParameters(regexp, methodMap.keys, route)
2744
+ parameters: this.buildParameters(regexp, methodMap.keys, route),
2745
+ searchParams: url.searchParams
2737
2746
  };
2738
2747
  break;
2739
2748
  }
@@ -3137,6 +3146,90 @@ class HttpHeadersMockBuilder {
3137
3146
  */
3138
3147
  const httpHeadersMock = () => new HttpHeadersMockBuilder();
3139
3148
 
3149
+ /**
3150
+ * @license
3151
+ * Copyright Pascal ECHEMANN. All Rights Reserved.
3152
+ *
3153
+ * Use of this source code is governed by an MIT-style license that can be found in
3154
+ * the LICENSE file at https://pascalechemann.com/angular-toolbox/resources/license
3155
+ */
3156
+ /**
3157
+ * Defines the possible values for the `responseType` property of the
3158
+ * `FetchClientBuilder.buildFetchClient()` method.
3159
+ */
3160
+ var FetchClientResponseType;
3161
+ (function (FetchClientResponseType) {
3162
+ /**
3163
+ * Allows to return the response as a promise that resolves with an `ArrayBuffer`.
3164
+ */
3165
+ FetchClientResponseType["ARRAY_BUFFER"] = "arrayBuffer";
3166
+ /**
3167
+ * Allows to return the response as a promise that resolves with a `Blob`.
3168
+ */
3169
+ FetchClientResponseType["BLOB"] = "blob";
3170
+ /**
3171
+ * Allows to return the response as a promise that resolves with a `FormData` object.
3172
+ */
3173
+ FetchClientResponseType["FORM_DATA"] = "formData";
3174
+ /**
3175
+ * Allows to return the response as a promise which resolves with the result of parsing the body text as JSON.
3176
+ */
3177
+ FetchClientResponseType["JSON"] = "json";
3178
+ /**
3179
+ * Allows to return the response as a promise that resolves with a `String`.
3180
+ * The response is always decoded using UTF-8.
3181
+ */
3182
+ FetchClientResponseType["TEXT"] = "text";
3183
+ })(FetchClientResponseType || (FetchClientResponseType = {}));
3184
+
3185
+ /**
3186
+ * @license
3187
+ * Copyright Pascal ECHEMANN. All Rights Reserved.
3188
+ *
3189
+ * Use of this source code is governed by an MIT-style license that can be found in
3190
+ * the LICENSE file at https://pascalechemann.com/angular-toolbox/resources/license
3191
+ */
3192
+ /**
3193
+ * A static utility class for building `FetchClient` objects.
3194
+ */
3195
+ class FetchClientBuilder {
3196
+ /**
3197
+ * Builds and returns a new `FetchClient` object.
3198
+ *
3199
+ * @param input The definition of the resource to fetch.
3200
+ * @param init The object containing options to configure the request.
3201
+ * @param responseType Specifies the type of response for the resource to fetch.
3202
+ *
3203
+ * @returns A new `FetchClient` object.
3204
+ */
3205
+ static buildFetchClient(input, init = null, responseType = FetchClientResponseType.JSON) {
3206
+ return from(fetch(input, init || undefined).then((response) => {
3207
+ if (response.ok)
3208
+ return FetchClientBuilder.buildResponseStrategy(response, responseType);
3209
+ throw new HttpErrorResponse({
3210
+ status: response.status,
3211
+ statusText: response.statusText
3212
+ });
3213
+ }));
3214
+ }
3215
+ /**
3216
+ * @private
3217
+ */
3218
+ static buildResponseStrategy(response, responseType) {
3219
+ if (responseType === FetchClientResponseType.JSON)
3220
+ return response.json();
3221
+ if (responseType === FetchClientResponseType.BLOB)
3222
+ return response.blob();
3223
+ if (responseType === FetchClientResponseType.FORM_DATA)
3224
+ return response.formData();
3225
+ if (responseType === FetchClientResponseType.ARRAY_BUFFER)
3226
+ return response.arrayBuffer();
3227
+ if (responseType === FetchClientResponseType.TEXT)
3228
+ return response.text();
3229
+ return response.json();
3230
+ }
3231
+ }
3232
+
3140
3233
  /**
3141
3234
  * @license
3142
3235
  * Copyright Pascal ECHEMANN. All Rights Reserved.
@@ -3501,7 +3594,7 @@ class DataStorageBuilder {
3501
3594
  * @param httpResponse The `HttpResponseMock` to be stored by the framework.
3502
3595
  * @param data The data of the HTTP response to be stored by the framework.
3503
3596
  *
3504
- * @returns A new `DataStorage` objects.
3597
+ * @returns A new `DataStorage` object.
3505
3598
  */
3506
3599
  static buildDataStorage(httpResponse, data) {
3507
3600
  // TODO: add support for different data types (string, Blob, etc.)
@@ -3634,35 +3727,41 @@ class DelegateXhr extends XhrBase {
3634
3727
  * @param body A body of data to be sent in the XHR request.
3635
3728
  */
3636
3729
  send(body) {
3637
- const request = new HttpRequest(this._method, this._url, body);
3730
+ const request = this.buildHttpRequest(body);
3638
3731
  const rc = this._routeConfig;
3639
3732
  const httpResponseMock = rc.methodConfig.data(request, rc.parameters);
3640
3733
  let timer = httpResponseMock.delay || 0;
3641
3734
  if (timer > MAX_TIMER)
3642
3735
  timer = MAX_TIMER;
3643
- this._loadSubscription = this.loadData(httpResponseMock).subscribe((data) => {
3644
- this._dataStorage = DataStorageBuilder.buildDataStorage(httpResponseMock, data);
3645
- const error = this._dataStorage.httpResponse.error;
3646
- setTimeout(() => {
3647
- this.setReadyState(this.HEADERS_RECEIVED);
3648
- if (error)
3649
- return this.onError(error);
3650
- this.setReadyState(this.LOADING);
3651
- const response = this._dataStorage.httpResponse;
3652
- let headers = response.headers;
3653
- if (headers) {
3654
- this._headers.keys().forEach((key) => {
3655
- headers = headers.set(key, this._headers.get(key));
3656
- });
3657
- this._headers = headers;
3658
- }
3659
- if (!this._progressiveDownload) {
3660
- this._statusText = response.statusText || EMPTY_STRING;
3661
- this._status = response.status || 0;
3662
- return this.onLoadComplete();
3663
- }
3664
- this.doProgressiveDownload();
3665
- }, timer);
3736
+ this._loadSubscription = this.loadData(httpResponseMock).subscribe({
3737
+ next: (data) => {
3738
+ this.setDataStorage(httpResponseMock, data);
3739
+ const error = this._dataStorage.httpResponse.error;
3740
+ setTimeout(() => {
3741
+ this.setReadyState(this.HEADERS_RECEIVED);
3742
+ if (error)
3743
+ return this.onError(error);
3744
+ this.setReadyState(this.LOADING);
3745
+ const response = this._dataStorage.httpResponse;
3746
+ let headers = response.headers;
3747
+ if (headers) {
3748
+ this._headers.keys().forEach((key) => {
3749
+ headers = headers.set(key, this._headers.get(key));
3750
+ });
3751
+ this._headers = headers;
3752
+ }
3753
+ if (!this._progressiveDownload) {
3754
+ this._statusText = response.statusText || EMPTY_STRING;
3755
+ this._status = response.status || 0;
3756
+ return this.onLoadComplete();
3757
+ }
3758
+ this.doProgressiveDownload();
3759
+ }, timer);
3760
+ },
3761
+ error: (err) => {
3762
+ this.setDataStorage(httpResponseMock);
3763
+ this.onError(err);
3764
+ }
3666
3765
  });
3667
3766
  }
3668
3767
  /**
@@ -3727,7 +3826,7 @@ class DelegateXhr extends XhrBase {
3727
3826
  const methodConfig = routeConfig.methodConfig;
3728
3827
  this._routeConfig = routeConfig;
3729
3828
  this._progressiveDownload = methodConfig.progressive || false;
3730
- this.responseType = methodConfig.responseType || "";
3829
+ this.responseType = methodConfig.responseType || EMPTY_STRING;
3731
3830
  this._headers = new HttpHeaders();
3732
3831
  }
3733
3832
  /**
@@ -3823,6 +3922,22 @@ class DelegateXhr extends XhrBase {
3823
3922
  const responseBody = httpResponseMock.body;
3824
3923
  return (responseBody instanceof Observable) ? responseBody : of(responseBody);
3825
3924
  }
3925
+ /**
3926
+ * @private
3927
+ */
3928
+ setDataStorage(responseMock, data = null) {
3929
+ this._dataStorage = DataStorageBuilder.buildDataStorage(responseMock, data);
3930
+ }
3931
+ /**
3932
+ * @private
3933
+ */
3934
+ buildHttpRequest(body) {
3935
+ let params = new HttpParams();
3936
+ const it = this._routeConfig.searchParams.entries();
3937
+ for (const pair of it)
3938
+ params = params.set(pair[0], pair[1]);
3939
+ return new HttpRequest(this._method, this._url, body, { params: params });
3940
+ }
3826
3941
  }
3827
3942
 
3828
3943
  /**
@@ -4088,5 +4203,5 @@ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "18.0.3", ngImpor
4088
4203
  * Generated bundle index. Do not edit.
4089
4204
  */
4090
4205
 
4091
- export { APP_PRIDGE_REF, AbstractSubscriptionManager, AbstractVersionManager, AnchorLinklDirective, AngularToolboxLogoComponent, AngularToolboxModule, AngularToolboxVersionService, AppBridgeError, AppBrigeService, ArrayList, ArrayListEvent, ArrayListEventType, BIGINT, BOOLEAN, BUTTON_ROLE, ButtonRoleDirective, CSS_PROP, ContentRendererDirective, DARK_MODE_CONFIG, DarkModeService, EMPTY_STRING, FUNCTION, HTTP_MOCK_SERVICE, HttpHeadersMockBuilder, HttpMock, HttpMockService, HttpMockServiceError, HttpResponseMockBuilder, IdentifiableComponent, IntegrityError, LINK_ROLE, NUMBER, NavigateToUrlDirective, OBJECT, STORAGE_KEY, STRING, SYMBOL, SafeHtmlPipe, ScrollService, SubscriptionError, SubscriptionService, UNDEFINED, Uuid, VERSION_CONFIG, VersionService, httpHeadersMock, httpMockFactory, httpResponseMock };
4206
+ export { APP_PRIDGE_REF, AbstractSubscriptionManager, AbstractVersionManager, AnchorLinklDirective, AngularToolboxLogoComponent, AngularToolboxModule, AngularToolboxVersionService, AppBridgeError, AppBrigeService, ArrayList, ArrayListEvent, ArrayListEventType, BIGINT, BOOLEAN, BUTTON_ROLE, ButtonRoleDirective, CSS_PROP, ContentRendererDirective, DARK_MODE_CONFIG, DarkModeService, EMPTY_STRING, FUNCTION, FetchClientBuilder, FetchClientResponseType, HTTP_MOCK_SERVICE, HttpHeadersMockBuilder, HttpMock, HttpMockService, HttpMockServiceError, HttpResponseMockBuilder, IdentifiableComponent, IntegrityError, LINK_ROLE, NUMBER, NavigateToUrlDirective, OBJECT, STORAGE_KEY, STRING, SYMBOL, SafeHtmlPipe, ScrollService, SubscriptionError, SubscriptionService, UNDEFINED, Uuid, VERSION_CONFIG, VersionService, httpHeadersMock, httpMockFactory, httpResponseMock };
4092
4207
  //# sourceMappingURL=angular-toolbox.mjs.map