@acorex/core 18.5.14 → 18.5.16
Sign up to get free protection for your applications and to get access to all the features.
@@ -1,11 +1,23 @@
|
|
1
1
|
import { HttpRequest, HttpClient } from '@angular/common/http';
|
2
|
-
import { inject, Injectable } from '@angular/core';
|
2
|
+
import { inject, Injectable, signal } from '@angular/core';
|
3
3
|
import { AXDownloadTask } from './download-task';
|
4
4
|
import { AXUploadTask } from './upload-task';
|
5
|
+
import { fromEvent, map, merge, startWith } from 'rxjs';
|
6
|
+
import { isBrowser } from '@acorex/core/platform';
|
5
7
|
import * as i0 from "@angular/core";
|
6
8
|
export class AXNetworkService {
|
7
9
|
constructor() {
|
8
10
|
this.http = inject(HttpClient);
|
11
|
+
this._status = signal(true);
|
12
|
+
this.status = this._status.asReadonly();
|
13
|
+
if (isBrowser()) {
|
14
|
+
// Only subscribe to these events if on the browser platform
|
15
|
+
const onlineEvent = fromEvent(window, 'online').pipe(map(() => true));
|
16
|
+
const offlineEvent = fromEvent(window, 'offline').pipe(map(() => false));
|
17
|
+
merge(onlineEvent, offlineEvent).pipe(startWith(navigator.onLine)).subscribe(c => {
|
18
|
+
this._status.set(c);
|
19
|
+
});
|
20
|
+
}
|
9
21
|
}
|
10
22
|
// Unified method handling both types of inputs
|
11
23
|
upload(arg1, arg2) {
|
@@ -68,5 +80,5 @@ export class AXNetworkService {
|
|
68
80
|
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "18.0.2", ngImport: i0, type: AXNetworkService, decorators: [{
|
69
81
|
type: Injectable,
|
70
82
|
args: [{ providedIn: 'root' }]
|
71
|
-
}] });
|
72
|
-
//# sourceMappingURL=data:application/json;base64,
|
83
|
+
}], ctorParameters: () => [] });
|
84
|
+
//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoibmV0d29yay5zZXJ2aWNlLmpzIiwic291cmNlUm9vdCI6IiIsInNvdXJjZXMiOlsiLi4vLi4vLi4vLi4vLi4vLi4vbGlicy9jb3JlL25ldHdvcmsv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oJ0dFVCcsIGFyZywge1xuICAgICAgICAgICAgICAgIHJlcG9ydFByb2dyZXNzOiB0cnVlLFxuICAgICAgICAgICAgICAgIHJlc3BvbnNlVHlwZTogJ2Jsb2InLFxuICAgICAgICAgICAgfSk7XG4gICAgICAgIH0gZWxzZSB7XG4gICAgICAgICAgICByZXF1ZXN0ID0gbmV3IEh0dHBSZXF1ZXN0KGFyZy5tZXRob2QsIGFyZy51cmwsIGFyZy5ib2R5LCB7XG4gICAgICAgICAgICAgICAgLi4uYXJnLFxuICAgICAgICAgICAgICAgIHJlcG9ydFByb2dyZXNzOiB0cnVlLFxuICAgICAgICAgICAgICAgIHJlc3BvbnNlVHlwZTogJ2Jsb2InLFxuICAgICAgICAgICAgfSk7XG4gICAgICAgIH1cblxuICAgICAgICBjb25zdCBldmVudHMgPSB0aGlzLmh0dHAucmVxdWVzdDxCbG9iPihyZXF1ZXN0KTtcbiAgICAgICAgcmV0dXJuIG5ldyBBWERvd25sb2FkVGFzayhldmVudHMpO1xuICAgIH1cblxufSJdfQ==
|
@@ -12,4 +12,4 @@ export var AXDownloadStatus;
|
|
12
12
|
AXDownloadStatus["StartingDownload"] = "Starting download";
|
13
13
|
AXDownloadStatus["DownloadFailed"] = "Download failed";
|
14
14
|
})(AXDownloadStatus || (AXDownloadStatus = {}));
|
15
|
-
//# sourceMappingURL=data:application/json;base64,
|
15
|
+
//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoibmV0d29yay50eXBlcy5qcyIsInNvdXJjZVJvb3QiOiIiLCJzb3VyY2VzIjpbIi4uLy4uLy4uLy4uLy4uLy4uL2xpYnMvY29yZS9uZXR3b3JrL3NyYy9saWIvbmV0d29yay50eXBlcy50cyJdLCJuYW1lcyI6W10sIm1hcHBpbmdzIjoiQUFBQSxNQUFNLENBQU4sSUFBWSxjQUtYO0FBTEQsV0FBWSxjQUFjO0lBQ3RCLDRDQUEwQixDQUFBO0lBQzFCLG9EQUFrQyxDQUF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mxvYWQgZmFpbGVkXCJcbn1cblxuZXhwb3J0IHR5cGUgQVhEb3dubG9hZFJlc3BvbnNlID0ge1xuICAgIHByb2dyZXNzOiBudW1iZXI7XG4gICAgYnl0ZXNSZWNlaXZlZDogbnVtYmVyO1xuICAgIHRvdGFsQnl0ZXM6IG51bWJlcjtcbiAgICBzdGF0dXM6IEFYRG93bmxvYWRTdGF0dXM7XG4gICAgZGF0YT86IEJsb2I7IC8vIG9yIGFueSBhcHByb3ByaWF0ZSB0eXBlIGJhc2VkIG9uIHlvdXIgc3BlY2lmaWMgdXNlIGNhc2Vcbn07XG4iXX0=
|
@@ -1,8 +1,9 @@
|
|
1
|
-
import { Subject } from 'rxjs';
|
1
|
+
import { Subject, fromEvent, map as map$1, merge, startWith } from 'rxjs';
|
2
2
|
import { takeUntil, map } from 'rxjs/operators';
|
3
3
|
import { HttpEventType, HttpClient, HttpRequest } from '@angular/common/http';
|
4
4
|
import * as i0 from '@angular/core';
|
5
|
-
import { inject, Injectable } from '@angular/core';
|
5
|
+
import { inject, signal, Injectable } from '@angular/core';
|
6
|
+
import { isBrowser } from '@acorex/core/platform';
|
6
7
|
|
7
8
|
var AXUploadStatus;
|
8
9
|
(function (AXUploadStatus) {
|
@@ -109,6 +110,16 @@ class AXDownloadTask {
|
|
109
110
|
class AXNetworkService {
|
110
111
|
constructor() {
|
111
112
|
this.http = inject(HttpClient);
|
113
|
+
this._status = signal(true);
|
114
|
+
this.status = this._status.asReadonly();
|
115
|
+
if (isBrowser()) {
|
116
|
+
// Only subscribe to these events if on the browser platform
|
117
|
+
const onlineEvent = fromEvent(window, 'online').pipe(map$1(() => true));
|
118
|
+
const offlineEvent = fromEvent(window, 'offline').pipe(map$1(() => false));
|
119
|
+
merge(onlineEvent, offlineEvent).pipe(startWith(navigator.onLine)).subscribe(c => {
|
120
|
+
this._status.set(c);
|
121
|
+
});
|
122
|
+
}
|
112
123
|
}
|
113
124
|
// Unified method handling both types of inputs
|
114
125
|
upload(arg1, arg2) {
|
@@ -171,7 +182,7 @@ class AXNetworkService {
|
|
171
182
|
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "18.0.2", ngImport: i0, type: AXNetworkService, decorators: [{
|
172
183
|
type: Injectable,
|
173
184
|
args: [{ providedIn: 'root' }]
|
174
|
-
}] });
|
185
|
+
}], ctorParameters: () => [] });
|
175
186
|
|
176
187
|
/**
|
177
188
|
* Generated bundle index. Do not edit.
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"file":"acorex-core-network.mjs","sources":["../../../../libs/core/network/src/lib/network.types.ts","../../../../libs/core/network/src/lib/upload-task.ts","../../../../libs/core/network/src/lib/download-task.ts","../../../../libs/core/network/src/lib/network.service.ts","../../../../libs/core/network/src/acorex-core-network.ts"],"sourcesContent":["export enum AXUploadStatus {\n Uploading = \"Uploading...\",\n UploadComplete = \"Upload complete\",\n StartingUpload = \"Starting upload\",\n UploadFailed = \"Upload failed\"\n}\n\nexport type AXUploadResponse<T> = {\n progress: number;\n bytesTransferred: number;\n totalBytes: number;\n status: AXUploadStatus;\n result?: T;\n};\n\nexport enum AXDownloadStatus {\n Downloading = \"Downloading...\",\n DownloadComplete = \"Download complete\",\n StartingDownload = \"Starting download\",\n DownloadFailed = \"Download failed\"\n}\n\nexport type AXDownloadResponse = {\n progress: number;\n bytesReceived: number;\n totalBytes: number;\n status: AXDownloadStatus;\n data?: Blob; // or any appropriate type based on your specific use case\n};","import { Observable, Subject } from 'rxjs';\nimport { takeUntil, map } from 'rxjs/operators';\nimport { HttpEvent, HttpEventType } from '@angular/common/http';\nimport { AXUploadResponse, AXUploadStatus } from './network.types'; // Ensure correct import path\n\nexport class AXUploadTask<T> {\n private cancelSignal = new Subject<void>();\n\n constructor(private observable: Observable<HttpEvent<T>>, private totalFileSize: number) { }\n\n get events(): Observable<AXUploadResponse<T>> {\n return this.observable.pipe(\n takeUntil(this.cancelSignal),\n map(event => this.handleEvent(event))\n );\n }\n\n private handleEvent(event: HttpEvent<any>): AXUploadResponse<T> {\n switch (event.type) {\n case HttpEventType.UploadProgress:\n {\n const percentDone = Math.round(100 * event.loaded / (this.totalFileSize || event.total));\n return {\n progress: percentDone,\n bytesTransferred: event.loaded,\n totalBytes: this.totalFileSize,\n status: AXUploadStatus.Uploading\n };\n }\n\n case HttpEventType.Response:\n return {\n progress: 100,\n bytesTransferred: this.totalFileSize,\n totalBytes: this.totalFileSize,\n status: AXUploadStatus.UploadComplete,\n result: event.body\n };\n\n default:\n return {\n progress: 0,\n bytesTransferred: 0,\n totalBytes: 0,\n status: AXUploadStatus.StartingUpload\n };\n }\n }\n\n cancel() {\n this.cancelSignal.next();\n this.cancelSignal.complete();\n }\n}\n","import { Observable, Subject } from 'rxjs';\nimport { takeUntil, map } from 'rxjs/operators';\nimport { HttpEvent, HttpEventType } from '@angular/common/http';\nimport { AXDownloadResponse, AXDownloadStatus } from './network.types'; // Ensure correct import path\n\nexport class AXDownloadTask {\n private cancelSignal = new Subject<void>();\n\n constructor(private observable: Observable<HttpEvent<any>>) { }\n\n get events(): Observable<AXDownloadResponse> {\n return this.observable.pipe(\n takeUntil(this.cancelSignal),\n map(event => this.handleEvent(event)),\n );\n }\n\n private handleEvent(event: HttpEvent<any>): AXDownloadResponse {\n switch (event.type) {\n case HttpEventType.DownloadProgress:\n {\n const percentDone = Math.round(100 * event.loaded / (event.total ?? event.loaded));\n return {\n progress: percentDone,\n bytesReceived: event.loaded,\n totalBytes: event.total ?? 0,\n status: AXDownloadStatus.Downloading\n };\n }\n\n case HttpEventType.Response:\n return {\n progress: 100,\n bytesReceived: event.body.size,\n totalBytes: event.body.size,\n status: AXDownloadStatus.DownloadComplete,\n data: event.body\n };\n\n default:\n return {\n progress: 0,\n bytesReceived: 0,\n totalBytes: 0,\n status: AXDownloadStatus.StartingDownload\n };\n }\n }\n\n cancel() {\n this.cancelSignal.next();\n this.cancelSignal.complete();\n }\n}\n","import { HttpRequest, HttpClient } from '@angular/common/http';\nimport { inject, Injectable } from '@angular/core';\nimport { AXDownloadTask } from './download-task';\nimport { AXUploadTask } from './upload-task';\n\n\n\n@Injectable({ providedIn: 'root' })\nexport class AXNetworkService {\n\n private http = inject(HttpClient);\n\n // Overload signatures\n upload<T>(url: string, formData: FormData): AXUploadTask<T>;\n upload<T>(request: HttpRequest<any>): AXUploadTask<T>;\n\n // Unified method handling both types of inputs\n upload<T>(arg1: string | HttpRequest<any>, arg2?: FormData): AXUploadTask<T> {\n let request: HttpRequest<any>;\n let totalFilesSize = 0;\n\n if (typeof arg1 === 'string' && arg2 instanceof FormData) {\n // Calculate total file size\n arg2.forEach((value) => {\n if (value instanceof File) {\n totalFilesSize += value.size;\n }\n });\n request = new HttpRequest('POST', arg1, arg2, {\n reportProgress: true,\n responseType: 'json'\n });\n } else if (arg1 instanceof HttpRequest) {\n if (arg1.body instanceof FormData) {\n // Calculate total file size\n arg1.body.forEach((value) => {\n if (value instanceof File) {\n totalFilesSize += value.size;\n }\n });\n }\n request = arg1.clone({\n reportProgress: true,\n responseType: arg1.responseType || 'json'\n });\n } else {\n throw new Error(\"Invalid arguments for upload method.\");\n }\n\n const events = this.http.request<T>(request);\n return new AXUploadTask<T>(events, totalFilesSize);\n }\n\n\n\n // Overload signatures\n download(url: string): AXDownloadTask;\n download(request: HttpRequest<Blob>): AXDownloadTask;\n\n // Unified method handling both types of inputs\n download(arg: string | HttpRequest<Blob>): AXDownloadTask {\n let request: HttpRequest<Blob>;\n\n if (typeof arg === 'string') {\n request = new HttpRequest('GET', arg, {\n reportProgress: true,\n responseType: 'blob',\n });\n } else {\n request = new HttpRequest(arg.method, arg.url, arg.body, {\n ...arg,\n reportProgress: true,\n responseType: 'blob',\n });\n }\n\n const events = this.http.request<Blob>(request);\n return new AXDownloadTask(events);\n }\n\n}","/**\n * Generated bundle index. Do not edit.\n */\n\nexport * from './index';\n"],"names":[],"mappings":";;;;;;IAAY,eAKX;AALD,CAAA,UAAY,cAAc,EAAA;AACtB,IAAA,cAAA,CAAA,WAAA,CAAA,G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AG,IAAI,WAAW,CAAC,KAAK,EAAE,GAAG,EAAE;AAClC,gBAAA,cAAc,EAAE,IAAI;AACpB,gBAAA,YAAY,EAAE,MAAM;AACvB,aAAA,CAAC,CAAC;SACN;aAAM;AACH,YAAA,OAAO,GAAG,IAAI,WAAW,CAAC,GAAG,CAAC,MAAM,EAAE,GAAG,CAAC,GAAG,EAAE,GAAG,CAAC,IAAI,EAAE;AACrD,gBAAA,GAAG,GAAG;AACN,gBAAA,cAAc,EAAE,IAAI;AACpB,gBAAA,YAAY,EAAE,MAAM;AACvB,aAAA,CAAC,CAAC;SACN;QAED,MAAM,MAAM,GAAG,IAAI,CAAC,IAAI,CAAC,OAAO,CAAO,OAAO,CAAC,CAAC;AAChD,QAAA,OAAO,IAAI,cAAc,CAAC,MAAM,CAAC,CAAC;KACrC;8GAtEQ,gBAAgB,EAAA,IAAA,EAAA,EAAA,EAAA,MAAA,EAAA,EAAA,CAAA,eAAA,CAAA,UAAA,EAAA,CAAA,CAAA,EAAA;AAAhB,IAAA,SAAA,IAAA,CAAA,KAAA,GAAA,EAAA,CAAA,qBAAA,CAAA,EAAA,UAAA,EAAA,QAAA,EAAA,OAAA,EAAA,QAAA,EAAA,QAAA,EAAA,EAAA,EAAA,IAAA,EAAA,gBAAgB,cADH,MAAM,EAAA,CAAA,CAAA,EAAA;;2FACnB,gBAAgB,EAAA,UAAA,EAAA,CAAA;kBAD5B,UAAU;mBAAC,EAAE,UAAU,EAAE,MAAM,EAAE,CAAA;;;ACPlC;;AAEG;;;;"}
|
1
|
+
{"version":3,"file":"acorex-core-network.mjs","sources":["../../../../libs/core/network/src/lib/network.types.ts","../../../../libs/core/network/src/lib/upload-task.ts","../../../../libs/core/network/src/lib/download-task.ts","../../../../libs/core/network/src/lib/network.service.ts","../../../../libs/core/network/src/acorex-core-network.ts"],"sourcesContent":["export enum AXUploadStatus {\n Uploading = \"Uploading...\",\n UploadComplete = \"Upload complete\",\n StartingUpload = \"Starting upload\",\n UploadFailed = \"Upload failed\"\n}\n\nexport type AXUploadResponse<T> = {\n progress: number;\n bytesTransferred: number;\n totalBytes: number;\n status: AXUploadStatus;\n result?: T;\n};\n\nexport enum AXDownloadStatus {\n Downloading = \"Downloading...\",\n DownloadComplete = \"Download complete\",\n StartingDownload = \"Starting download\",\n DownloadFailed = \"Download failed\"\n}\n\nexport type AXDownloadResponse = {\n progress: number;\n bytesReceived: number;\n totalBytes: number;\n status: AXDownloadStatus;\n data?: Blob; // or any appropriate type based on your specific use case\n};\n","import { Observable, Subject } from 'rxjs';\nimport { takeUntil, map } from 'rxjs/operators';\nimport { HttpEvent, HttpEventType } from '@angular/common/http';\nimport { AXUploadResponse, AXUploadStatus } from './network.types'; // Ensure correct import path\n\nexport class AXUploadTask<T> {\n private cancelSignal = new Subject<void>();\n\n constructor(private observable: Observable<HttpEvent<T>>, private totalFileSize: number) { }\n\n get events(): Observable<AXUploadResponse<T>> {\n return this.observable.pipe(\n takeUntil(this.cancelSignal),\n map(event => this.handleEvent(event))\n );\n }\n\n private handleEvent(event: HttpEvent<any>): AXUploadResponse<T> {\n switch (event.type) {\n case HttpEventType.UploadProgress:\n {\n const percentDone = Math.round(100 * event.loaded / (this.totalFileSize || event.total));\n return {\n progress: percentDone,\n bytesTransferred: event.loaded,\n totalBytes: this.totalFileSize,\n status: AXUploadStatus.Uploading\n };\n }\n\n case HttpEventType.Response:\n return {\n progress: 100,\n bytesTransferred: this.totalFileSize,\n totalBytes: this.totalFileSize,\n status: AXUploadStatus.UploadComplete,\n result: event.body\n };\n\n default:\n return {\n progress: 0,\n bytesTransferred: 0,\n totalBytes: 0,\n status: AXUploadStatus.StartingUpload\n };\n }\n }\n\n cancel() {\n this.cancelSignal.next();\n this.cancelSignal.complete();\n }\n}\n","import { Observable, Subject } from 'rxjs';\nimport { takeUntil, map } from 'rxjs/operators';\nimport { HttpEvent, HttpEventType } from '@angular/common/http';\nimport { AXDownloadResponse, AXDownloadStatus } from './network.types'; // Ensure correct import path\n\nexport class AXDownloadTask {\n private cancelSignal = new Subject<void>();\n\n constructor(private observable: Observable<HttpEvent<any>>) { }\n\n get events(): Observable<AXDownloadResponse> {\n return this.observable.pipe(\n takeUntil(this.cancelSignal),\n map(event => this.handleEvent(event)),\n );\n }\n\n private handleEvent(event: HttpEvent<any>): AXDownloadResponse {\n switch (event.type) {\n case HttpEventType.DownloadProgress:\n {\n const percentDone = Math.round(100 * event.loaded / (event.total ?? event.loaded));\n return {\n progress: percentDone,\n bytesReceived: event.loaded,\n totalBytes: event.total ?? 0,\n status: AXDownloadStatus.Downloading\n };\n }\n\n case HttpEventType.Response:\n return {\n progress: 100,\n bytesReceived: event.body.size,\n totalBytes: event.body.size,\n status: AXDownloadStatus.DownloadComplete,\n data: event.body\n };\n\n default:\n return {\n progress: 0,\n bytesReceived: 0,\n totalBytes: 0,\n status: AXDownloadStatus.StartingDownload\n };\n }\n }\n\n cancel() {\n this.cancelSignal.next();\n this.cancelSignal.complete();\n }\n}\n","import { HttpRequest, HttpClient } from '@angular/common/http';\nimport { inject, Injectable, signal } from '@angular/core';\nimport { AXDownloadTask } from './download-task';\nimport { AXUploadTask } from './upload-task';\nimport { fromEvent, map, merge, startWith } from 'rxjs';\nimport { isBrowser } from '@acorex/core/platform';\n\n\n\n@Injectable({ providedIn: 'root' })\nexport class AXNetworkService {\n\n private http = inject(HttpClient);\n\n private _status = signal<boolean>(true);\n\n public readonly status = this._status.asReadonly();\n\n constructor() {\n if (isBrowser()) {\n // Only subscribe to these events if on the browser platform\n const onlineEvent = fromEvent(window, 'online').pipe(map(() => true));\n const offlineEvent = fromEvent(window, 'offline').pipe(map(() => false));\n\n merge(onlineEvent, offlineEvent).pipe(\n startWith(navigator.onLine)\n ).subscribe(c => {\n this._status.set(c);\n });\n }\n }\n\n // Overload signatures\n upload<T>(url: string, formData: FormData): AXUploadTask<T>;\n upload<T>(request: HttpRequest<any>): AXUploadTask<T>;\n\n // Unified method handling both types of inputs\n upload<T>(arg1: string | HttpRequest<any>, arg2?: FormData): AXUploadTask<T> {\n let request: HttpRequest<any>;\n let totalFilesSize = 0;\n\n if (typeof arg1 === 'string' && arg2 instanceof FormData) {\n // Calculate total file size\n arg2.forEach((value) => {\n if (value instanceof File) {\n totalFilesSize += value.size;\n }\n });\n request = new HttpRequest('POST', arg1, arg2, {\n reportProgress: true,\n responseType: 'json'\n });\n } else if (arg1 instanceof HttpRequest) {\n if (arg1.body instanceof FormData) {\n // Calculate total file size\n arg1.body.forEach((value) => {\n if (value instanceof File) {\n totalFilesSize += value.size;\n }\n });\n }\n request = arg1.clone({\n reportProgress: true,\n responseType: arg1.responseType || 'json'\n });\n } else {\n throw new Error(\"Invalid arguments for upload method.\");\n }\n\n const events = this.http.request<T>(request);\n return new AXUploadTask<T>(events, totalFilesSize);\n }\n\n\n\n // Overload signatures\n download(url: string): AXDownloadTask;\n download(request: HttpRequest<Blob>): AXDownloadTask;\n\n // Unified method handling both types of inputs\n download(arg: string | HttpRequest<Blob>): AXDownloadTask {\n let request: HttpRequest<Blob>;\n\n if (typeof arg === 'string') {\n request = new HttpRequest('GET', arg, {\n reportProgress: true,\n responseType: 'blob',\n });\n } else {\n request = new HttpRequest(arg.method, arg.url, arg.body, {\n ...arg,\n reportProgress: true,\n responseType: 'blob',\n });\n }\n\n const events = this.http.request<Blob>(request);\n return new AXDownloadTask(events);\n }\n\n}","/**\n * Generated bundle index. Do not edit.\n */\n\nexport * from './index';\n"],"names":["map"],"mappings":";;;;;;;IAAY,eAKX;AALD,CAAA,UAAY,cAAc,EAAA;AACtB,IAAA,cAAA,CAAA,WAAA,CAAA,GAAA,cAA0B,CAAA;AAC1B,IAAA,cAAA,CAAA,gBAAA,CAAA,GAAA,iBAAkC,CAAA;AAClC,IAAA,cAAA,CAAA,gBAAA,CAAA,GAAA,iBAAkC,CAAA;AAClC,IAAA,cAAA,CAAA,cAAA,CAAA,GAAA,eAA8B,CAAA;AAClC,CAAC,EALW,cAAc,KAAd,cAAc,GAKzB,EAAA,CAAA,CAAA,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FACnB,gBAAgB,EAAA,UAAA,EAAA,CAAA;kBAD5B,UAAU;mBAAC,EAAE,UAAU,EAAE,MAAM,EAAE,CAAA;;;ACTlC;;AAEG;;;;"}
|
@@ -4,6 +4,9 @@ import { AXUploadTask } from './upload-task';
|
|
4
4
|
import * as i0 from "@angular/core";
|
5
5
|
export declare class AXNetworkService {
|
6
6
|
private http;
|
7
|
+
private _status;
|
8
|
+
readonly status: import("@angular/core").Signal<boolean>;
|
9
|
+
constructor();
|
7
10
|
upload<T>(url: string, formData: FormData): AXUploadTask<T>;
|
8
11
|
upload<T>(request: HttpRequest<any>): AXUploadTask<T>;
|
9
12
|
download(url: string): AXDownloadTask;
|
package/package.json
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
{
|
2
2
|
"name": "@acorex/core",
|
3
|
-
"version": "18.5.
|
3
|
+
"version": "18.5.16",
|
4
4
|
"peerDependencies": {
|
5
5
|
"@angular/common": ">=18.0.0",
|
6
6
|
"@angular/core": ">=18.0.0",
|
@@ -32,23 +32,17 @@
|
|
32
32
|
"esm": "./esm2022/common/acorex-core-common.mjs",
|
33
33
|
"default": "./fesm2022/acorex-core-common.mjs"
|
34
34
|
},
|
35
|
-
"./events": {
|
36
|
-
"types": "./events/index.d.ts",
|
37
|
-
"esm2022": "./esm2022/events/acorex-core-events.mjs",
|
38
|
-
"esm": "./esm2022/events/acorex-core-events.mjs",
|
39
|
-
"default": "./fesm2022/acorex-core-events.mjs"
|
40
|
-
},
|
41
35
|
"./config": {
|
42
36
|
"types": "./config/index.d.ts",
|
43
37
|
"esm2022": "./esm2022/config/acorex-core-config.mjs",
|
44
38
|
"esm": "./esm2022/config/acorex-core-config.mjs",
|
45
39
|
"default": "./fesm2022/acorex-core-config.mjs"
|
46
40
|
},
|
47
|
-
"./
|
48
|
-
"types": "./
|
49
|
-
"esm2022": "./esm2022/
|
50
|
-
"esm": "./esm2022/
|
51
|
-
"default": "./fesm2022/acorex-core-
|
41
|
+
"./events": {
|
42
|
+
"types": "./events/index.d.ts",
|
43
|
+
"esm2022": "./esm2022/events/acorex-core-events.mjs",
|
44
|
+
"esm": "./esm2022/events/acorex-core-events.mjs",
|
45
|
+
"default": "./fesm2022/acorex-core-events.mjs"
|
52
46
|
},
|
53
47
|
"./file": {
|
54
48
|
"types": "./file/index.d.ts",
|
@@ -56,6 +50,12 @@
|
|
56
50
|
"esm": "./esm2022/file/acorex-core-file.mjs",
|
57
51
|
"default": "./fesm2022/acorex-core-file.mjs"
|
58
52
|
},
|
53
|
+
"./format": {
|
54
|
+
"types": "./format/index.d.ts",
|
55
|
+
"esm2022": "./esm2022/format/acorex-core-format.mjs",
|
56
|
+
"esm": "./esm2022/format/acorex-core-format.mjs",
|
57
|
+
"default": "./fesm2022/acorex-core-format.mjs"
|
58
|
+
},
|
59
59
|
"./date-time": {
|
60
60
|
"types": "./date-time/index.d.ts",
|
61
61
|
"esm2022": "./esm2022/date-time/acorex-core-date-time.mjs",
|
@@ -98,6 +98,12 @@
|
|
98
98
|
"esm": "./esm2022/storage/acorex-core-storage.mjs",
|
99
99
|
"default": "./fesm2022/acorex-core-storage.mjs"
|
100
100
|
},
|
101
|
+
"./utils": {
|
102
|
+
"types": "./utils/index.d.ts",
|
103
|
+
"esm2022": "./esm2022/utils/acorex-core-utils.mjs",
|
104
|
+
"esm": "./esm2022/utils/acorex-core-utils.mjs",
|
105
|
+
"default": "./fesm2022/acorex-core-utils.mjs"
|
106
|
+
},
|
101
107
|
"./translation": {
|
102
108
|
"types": "./translation/index.d.ts",
|
103
109
|
"esm2022": "./esm2022/translation/acorex-core-translation.mjs",
|
@@ -110,12 +116,6 @@
|
|
110
116
|
"esm": "./esm2022/types/acorex-core-types.mjs",
|
111
117
|
"default": "./fesm2022/acorex-core-types.mjs"
|
112
118
|
},
|
113
|
-
"./utils": {
|
114
|
-
"types": "./utils/index.d.ts",
|
115
|
-
"esm2022": "./esm2022/utils/acorex-core-utils.mjs",
|
116
|
-
"esm": "./esm2022/utils/acorex-core-utils.mjs",
|
117
|
-
"default": "./fesm2022/acorex-core-utils.mjs"
|
118
|
-
},
|
119
119
|
"./validation": {
|
120
120
|
"types": "./validation/index.d.ts",
|
121
121
|
"esm2022": "./esm2022/validation/acorex-core-validation.mjs",
|