http-request-manager 15.0.19 → 15.0.24
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.
- package/esm2022/lib/http-request-manager.module.mjs +2 -2
- package/esm2022/lib/http-request-services-demo/database-data-demo/database-data-demo.component.mjs +71 -0
- package/esm2022/lib/http-request-services-demo/request-manager-demo/request-manager-demo.component.mjs +5 -5
- package/esm2022/lib/http-request-services-demo/request-manager-state-demo/request-manager-state-demo.component.mjs +2 -2
- package/esm2022/lib/interceptors/request-error.interceptor.mjs +3 -3
- package/esm2022/lib/services/database-manager-services/database.manager.service.mjs +119 -0
- package/esm2022/lib/services/database-manager-services/db.storage.service.mjs +143 -0
- package/esm2022/lib/services/database-manager-services/index.mjs +4 -0
- package/esm2022/lib/services/database-manager-services/models/table-schema.mjs +20 -0
- package/esm2022/lib/services/local-storage-manager-service/local-storage-manager.service.mjs +2 -2
- package/esm2022/lib/services/request-manager-services/http-manager.service.mjs +3 -3
- package/esm2022/lib/services/request-manager-services/request.service.mjs +5 -5
- package/esm2022/lib/services/request-manager-state-service/http-manager-state.store.mjs +3 -3
- package/esm2022/lib/services/request-manager-state-service/models/api-request.model.mjs +3 -3
- package/esm2022/lib/services/utils/object-merger.service.mjs +3 -3
- package/esm2022/public-api.mjs +5 -1
- package/fesm2022/http-request-manager.mjs +360 -18
- package/fesm2022/http-request-manager.mjs.map +1 -1
- package/http-request-manager-15.0.24.tgz +0 -0
- package/lib/http-request-services-demo/database-data-demo/database-data-demo.component.d.ts +19 -0
- package/lib/http-request-services-demo/request-manager-demo/request-manager-demo.component.d.ts +9 -9
- package/lib/interceptors/request-error.interceptor.d.ts +2 -2
- package/lib/services/database-manager-services/database.manager.service.d.ts +31 -0
- package/lib/services/database-manager-services/db.storage.service.d.ts +26 -0
- package/lib/services/database-manager-services/index.d.ts +3 -0
- package/lib/services/database-manager-services/models/table-schema.d.ts +11 -0
- package/lib/services/request-manager-services/http-manager.service.d.ts +2 -2
- package/lib/services/request-manager-state-service/models/api-request.model.d.ts +8 -8
- package/package.json +10 -1
- package/public-api.d.ts +4 -0
- package/http-request-manager-15.0.19.tgz +0 -0
|
@@ -1,11 +1,11 @@
|
|
|
1
1
|
import * as i0 from '@angular/core';
|
|
2
2
|
import { inject, Injectable, APP_ID, Inject, InjectionToken, Injector, Optional, EventEmitter, Component, ViewEncapsulation, Input, Output, ViewChild, NgModule } from '@angular/core';
|
|
3
3
|
import { ComponentStore } from '@ngrx/component-store';
|
|
4
|
-
import { map, catchError, filter, finalize, takeWhile, retry, startWith, tap, mergeMap, takeUntil, withLatestFrom, switchMap, concatMap, scan, distinctUntilChanged } from 'rxjs/operators';
|
|
4
|
+
import { map, catchError, filter, delay, finalize, takeWhile, retry, startWith, tap, mergeMap, takeUntil, withLatestFrom, switchMap, concatMap, scan, distinctUntilChanged } from 'rxjs/operators';
|
|
5
5
|
import { HttpClient, HttpHeaders, HttpEventType, HttpHeaderResponse, HttpErrorResponse, HTTP_INTERCEPTORS } from '@angular/common/http';
|
|
6
6
|
import * as CryptoJS from 'crypto-js';
|
|
7
7
|
import { from, BehaviorSubject, EMPTY, throwError, defer, interval, timer, Subject, of, Subscription, catchError as catchError$1, map as map$1, tap as tap$1 } from 'rxjs';
|
|
8
|
-
import {
|
|
8
|
+
import { ToastMessageService, ToastDisplay, ToastColors, ToastMessageDisplayModule } from 'toast-message-display';
|
|
9
9
|
import * as i1 from '@ngx-translate/core';
|
|
10
10
|
import { TranslateModule } from '@ngx-translate/core';
|
|
11
11
|
import * as i2 from '@angular/forms';
|
|
@@ -42,6 +42,7 @@ import { MatChipsModule } from '@angular/material/chips';
|
|
|
42
42
|
import { MatSidenavModule } from '@angular/material/sidenav';
|
|
43
43
|
import * as i5$1 from '@angular/material/toolbar';
|
|
44
44
|
import { MatToolbarModule } from '@angular/material/toolbar';
|
|
45
|
+
import Dexie from 'dexie';
|
|
45
46
|
|
|
46
47
|
var StorageType;
|
|
47
48
|
(function (StorageType) {
|
|
@@ -710,7 +711,7 @@ class RequestService {
|
|
|
710
711
|
this.pathQueryService = inject(PathQueryService);
|
|
711
712
|
this.headersService = inject(HeadersService);
|
|
712
713
|
this.isPending = new BehaviorSubject(false);
|
|
713
|
-
this.isPending$ = this.isPending.asObservable();
|
|
714
|
+
this.isPending$ = this.isPending.asObservable().pipe(delay(1));
|
|
714
715
|
this.progress = new BehaviorSubject(0);
|
|
715
716
|
this.progress$ = this.progress.asObservable();
|
|
716
717
|
}
|
|
@@ -751,7 +752,7 @@ class RequestService {
|
|
|
751
752
|
}
|
|
752
753
|
buildCombinedHeaders(options) {
|
|
753
754
|
const headers = this.headersService.generateHeaders(options.headers);
|
|
754
|
-
return this.combineHeaders(headers, options.stream);
|
|
755
|
+
return this.combineHeaders(headers, options.stream || false);
|
|
755
756
|
}
|
|
756
757
|
request(options) {
|
|
757
758
|
return (source$) => {
|
|
@@ -790,7 +791,7 @@ class RequestService {
|
|
|
790
791
|
return status;
|
|
791
792
|
case HttpEventType.Response:
|
|
792
793
|
try {
|
|
793
|
-
const fileNamePath = (options?.saveAs) ? options.saveAs : options.path[options.path.length - 1];
|
|
794
|
+
const fileNamePath = (options?.saveAs) ? options.saveAs : (options.path) ? options.path[options.path.length - 1] : [];
|
|
794
795
|
const header_content = event.headers.get('Content-Disposition') || '';
|
|
795
796
|
// checks if header_content is not empty and splits the header_content to get the file name
|
|
796
797
|
// otherwise, it will use the fileDownload - contains the file name and extension
|
|
@@ -982,7 +983,7 @@ class HTTPManagerService extends RequestService {
|
|
|
982
983
|
constructor(configOptions) {
|
|
983
984
|
super();
|
|
984
985
|
this.configOptions = configOptions;
|
|
985
|
-
this.toastMessage = inject(
|
|
986
|
+
this.toastMessage = inject(ToastMessageService);
|
|
986
987
|
this.ng_injector = inject(Injector);
|
|
987
988
|
this.objectMergerService = inject(ObjectMergerService);
|
|
988
989
|
this.countdown = new BehaviorSubject(0);
|
|
@@ -1174,7 +1175,7 @@ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "16.2.12", ngImpo
|
|
|
1174
1175
|
}] }]; } });
|
|
1175
1176
|
|
|
1176
1177
|
class ApiRequest {
|
|
1177
|
-
constructor(server = '', path
|
|
1178
|
+
constructor(server = '', path, headers, adapter, mapper, polling, retry, stream, displayError, saveAs) {
|
|
1178
1179
|
this.server = server;
|
|
1179
1180
|
this.path = path;
|
|
1180
1181
|
this.headers = headers;
|
|
@@ -1188,7 +1189,7 @@ class ApiRequest {
|
|
|
1188
1189
|
}
|
|
1189
1190
|
static adapt(item) {
|
|
1190
1191
|
const server = Array.isArray(item?.server) ? item.server.join('/') : item?.server || '';
|
|
1191
|
-
return new ApiRequest(server, item?.path, (item?.headers) ? item.headers : {}, item?.adapter, item?.mapper, item?.polling ? Math.floor(item.polling) : 0, item?.retry ? RetryOptions.adapt(item.retry) : RetryOptions.adapt(), item?.stream, item?.displayError, item?.saveAs);
|
|
1192
|
+
return new ApiRequest(server, (item?.path) ? item.path : [], (item?.headers) ? item.headers : {}, item?.adapter, item?.mapper, item?.polling ? Math.floor(item.polling) : 0, item?.retry ? RetryOptions.adapt(item.retry) : RetryOptions.adapt(), (item?.stream) ? item.stream : false, (item?.displayError) ? item.displayError : false, item?.saveAs);
|
|
1192
1193
|
}
|
|
1193
1194
|
}
|
|
1194
1195
|
|
|
@@ -1212,8 +1213,8 @@ class ObjectMergerService {
|
|
|
1212
1213
|
const configForRoot = (this.configOptions?.httpRequestOptions) ? this.configOptions.httpRequestOptions : ConfigHTTPOptions.adapt();
|
|
1213
1214
|
const mergedOptions = ApiRequest.adapt(options);
|
|
1214
1215
|
mergedOptions.server = (options && options.server === '') ? configForRoot?.server || '' : options.server;
|
|
1215
|
-
mergedOptions.path = [...options.path, ...configForRoot?.path || []];
|
|
1216
|
-
mergedOptions.headers = { ...options.headers, ...configForRoot?.headers || {} };
|
|
1216
|
+
mergedOptions.path = [...options.path || [], ...configForRoot?.path || []];
|
|
1217
|
+
mergedOptions.headers = { ...options.headers || {}, ...configForRoot?.headers || {} };
|
|
1217
1218
|
mergedOptions.retry = (options && (options?.retry?.times !== 0 || options?.retry?.delay !== 3)) ? options.retry : configForRoot?.retry || { times: 0, delay: 3 };
|
|
1218
1219
|
mergedOptions.polling = (options && options?.polling !== 0) ? options.polling : configForRoot?.polling || 0;
|
|
1219
1220
|
mergedOptions.displayError = (options && options?.displayError) ? options.displayError : configForRoot?.displayError || false;
|
|
@@ -1417,7 +1418,7 @@ class LocalStorageManagerService extends ComponentStore {
|
|
|
1417
1418
|
this.isObjectOrArray = (obj) => {
|
|
1418
1419
|
let parsed;
|
|
1419
1420
|
try {
|
|
1420
|
-
parsed = JSON.parse(obj);
|
|
1421
|
+
parsed = (typeof obj === 'object') ? obj : JSON.parse(obj);
|
|
1421
1422
|
}
|
|
1422
1423
|
catch (e) {
|
|
1423
1424
|
return false;
|
|
@@ -1546,7 +1547,7 @@ class HTTPManagerStateService extends ComponentStore {
|
|
|
1546
1547
|
this.database = database;
|
|
1547
1548
|
this.httpManagerService = inject(HTTPManagerService);
|
|
1548
1549
|
this.error$ = this.httpManagerService.error$;
|
|
1549
|
-
this.isPending$ = this.httpManagerService.isPending
|
|
1550
|
+
this.isPending$ = this.httpManagerService.isPending$.pipe(delay(1));
|
|
1550
1551
|
// PAGINATION
|
|
1551
1552
|
this.page = new BehaviorSubject(0);
|
|
1552
1553
|
this.page$ = this.page.asObservable();
|
|
@@ -1855,7 +1856,7 @@ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "16.2.12", ngImpo
|
|
|
1855
1856
|
|
|
1856
1857
|
class RequestErrorInterceptor {
|
|
1857
1858
|
constructor() {
|
|
1858
|
-
this.toastMessage = inject(
|
|
1859
|
+
this.toastMessage = inject(ToastMessageService);
|
|
1859
1860
|
}
|
|
1860
1861
|
intercept(req, next) {
|
|
1861
1862
|
return next.handle(req).pipe(catchError$1((error) => {
|
|
@@ -2109,7 +2110,7 @@ class RequestManagerDemoComponent {
|
|
|
2109
2110
|
constructor() {
|
|
2110
2111
|
this.displayedColumns = ['id', 'name', 'lastName', 'age'];
|
|
2111
2112
|
this.fb = inject(FormBuilder);
|
|
2112
|
-
this.toastMessage = inject(
|
|
2113
|
+
this.toastMessage = inject(ToastMessageService);
|
|
2113
2114
|
this.httpManagerService = inject(HTTPManagerService);
|
|
2114
2115
|
this.isPending$ = this.httpManagerService.isPending$;
|
|
2115
2116
|
this.countdown$ = this.httpManagerService.countdown$;
|
|
@@ -2129,7 +2130,7 @@ class RequestManagerDemoComponent {
|
|
|
2129
2130
|
this.questionControl = this.fb.control("", [Validators.required]);
|
|
2130
2131
|
this.downloadRequest = ApiRequest.adapt({
|
|
2131
2132
|
server: 'assets/images',
|
|
2132
|
-
path: ['me.
|
|
2133
|
+
path: ['me.jpg'],
|
|
2133
2134
|
// saveAs: 'john.jpg' // Optional
|
|
2134
2135
|
});
|
|
2135
2136
|
// downloadRequest = ApiRequest.adapt({
|
|
@@ -2149,7 +2150,7 @@ class RequestManagerDemoComponent {
|
|
|
2149
2150
|
email: "wavecoders@gmail.com"
|
|
2150
2151
|
};
|
|
2151
2152
|
this.requestForm = this.fb.group({
|
|
2152
|
-
path: this.fb.control("
|
|
2153
|
+
path: this.fb.control("ai/"),
|
|
2153
2154
|
headers: this.fb.array([]),
|
|
2154
2155
|
adapter: [null],
|
|
2155
2156
|
mapper: [null],
|
|
@@ -2528,7 +2529,7 @@ class RequestManagerStateDemoComponent {
|
|
|
2528
2529
|
this.selectedRecord = this.fb.control(null);
|
|
2529
2530
|
this.requestForm = this.fb.group({
|
|
2530
2531
|
datatype: this.fb.control('ARRAY'),
|
|
2531
|
-
path: this.fb.control("
|
|
2532
|
+
path: this.fb.control("ai/"),
|
|
2532
2533
|
headers: this.fb.array([]),
|
|
2533
2534
|
adapter: [null],
|
|
2534
2535
|
mapper: [null],
|
|
@@ -3090,6 +3091,347 @@ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "16.2.12", ngImpo
|
|
|
3090
3091
|
}]
|
|
3091
3092
|
}] });
|
|
3092
3093
|
|
|
3094
|
+
class TableSchemaDef {
|
|
3095
|
+
constructor(table = 'unknown', schema = '') {
|
|
3096
|
+
this.table = table;
|
|
3097
|
+
this.schema = schema;
|
|
3098
|
+
}
|
|
3099
|
+
static adapt(item) {
|
|
3100
|
+
const schemaArray = (item?.schema && Array.isArray(item.schema)) ? item.schema : item.schema.split(',');
|
|
3101
|
+
const schema = schemaArray.map((item) => this.cleanString(item)).join();
|
|
3102
|
+
return new TableSchemaDef((item?.table) ? this.cleanString(item.table) : 'unknown', schema);
|
|
3103
|
+
}
|
|
3104
|
+
static cleanString(str) {
|
|
3105
|
+
const camelCaseSplit = str.replace(/([a-z])([A-Z])/g, '$1 $2');
|
|
3106
|
+
const cleanStr = camelCaseSplit
|
|
3107
|
+
.replace(/[^a-zA-Z0-9\s]/g, '') // Remove non-alphanumeric characters except spaces
|
|
3108
|
+
.toLowerCase() // Convert to lowercase
|
|
3109
|
+
.trim(); // Trim any leading or trailing spaces
|
|
3110
|
+
return cleanStr;
|
|
3111
|
+
}
|
|
3112
|
+
}
|
|
3113
|
+
|
|
3114
|
+
class DbService extends Dexie {
|
|
3115
|
+
get vr() {
|
|
3116
|
+
return (this.db.verno === 0) ? 1 : this.db.verno + 1;
|
|
3117
|
+
}
|
|
3118
|
+
get nextVr() {
|
|
3119
|
+
return this.vr + 1;
|
|
3120
|
+
}
|
|
3121
|
+
get getTables() {
|
|
3122
|
+
return this.db.tables.map(item => item.name);
|
|
3123
|
+
}
|
|
3124
|
+
async hasDatabase() {
|
|
3125
|
+
return await Dexie.exists(this.storageDB).then((res) => {
|
|
3126
|
+
this.createNewDatabase();
|
|
3127
|
+
return res;
|
|
3128
|
+
});
|
|
3129
|
+
}
|
|
3130
|
+
constructor() {
|
|
3131
|
+
super("global_storage_db");
|
|
3132
|
+
this.storageDB = "global_storage_db";
|
|
3133
|
+
this.db = new Dexie(this.storageDB);
|
|
3134
|
+
this.getTable = (table) => {
|
|
3135
|
+
return this.db.tables.find(item => item.name === table);
|
|
3136
|
+
};
|
|
3137
|
+
this.tableExists = (table) => {
|
|
3138
|
+
return (this.getTables.find(item => item === table)) ? true : false;
|
|
3139
|
+
};
|
|
3140
|
+
this.db = this;
|
|
3141
|
+
this.open().then(data => {
|
|
3142
|
+
}).catch(err => {
|
|
3143
|
+
this.createNewDatabase();
|
|
3144
|
+
});
|
|
3145
|
+
}
|
|
3146
|
+
async updateTable(table, find, data) {
|
|
3147
|
+
const tableSource = this.getTable(table);
|
|
3148
|
+
if (!tableSource || !find || !(find.key || find.value))
|
|
3149
|
+
return false;
|
|
3150
|
+
await tableSource?.where(find.key).equals(find.value).first()
|
|
3151
|
+
.then(async (rec) => {
|
|
3152
|
+
const newRec = this.updateObjectKeys(rec, data);
|
|
3153
|
+
await tableSource?.update(rec.id, newRec);
|
|
3154
|
+
});
|
|
3155
|
+
return true;
|
|
3156
|
+
}
|
|
3157
|
+
async createNewDatabase() {
|
|
3158
|
+
const db = new Dexie('global_storage_db');
|
|
3159
|
+
if (!await Dexie.exists(db.name)) {
|
|
3160
|
+
db.version(1).stores({});
|
|
3161
|
+
}
|
|
3162
|
+
await db.open();
|
|
3163
|
+
}
|
|
3164
|
+
// async createTable(table: string, schema: string) {
|
|
3165
|
+
async createTable(table, schema) {
|
|
3166
|
+
// console.log('createTable:', table, schema)
|
|
3167
|
+
this.hasDatabase().then(async (res) => {
|
|
3168
|
+
const tableDef = this.normalizeString(table);
|
|
3169
|
+
const schemaDef = this.normalizeString(schema);
|
|
3170
|
+
table = tableDef || '';
|
|
3171
|
+
schema = schemaDef || '';
|
|
3172
|
+
if (table === '' || schema === '')
|
|
3173
|
+
return;
|
|
3174
|
+
if (!this.db.isOpen()) {
|
|
3175
|
+
await this.db.open()
|
|
3176
|
+
.then(async () => {
|
|
3177
|
+
this.create(table, schema);
|
|
3178
|
+
// console.log('OPENED', table)
|
|
3179
|
+
})
|
|
3180
|
+
.catch(() => {
|
|
3181
|
+
// console.log('FAILED', table)
|
|
3182
|
+
});
|
|
3183
|
+
}
|
|
3184
|
+
else {
|
|
3185
|
+
this.create(table, schema);
|
|
3186
|
+
}
|
|
3187
|
+
const hasTable = this.getTable(table);
|
|
3188
|
+
if (!hasTable) {
|
|
3189
|
+
setTimeout(() => {
|
|
3190
|
+
this.createTable.bind(this, table, schema);
|
|
3191
|
+
this.create(table, schema);
|
|
3192
|
+
}, 300);
|
|
3193
|
+
}
|
|
3194
|
+
// console.log('DB HAS', table, hasTable)
|
|
3195
|
+
});
|
|
3196
|
+
}
|
|
3197
|
+
async create(table, schema) {
|
|
3198
|
+
// console.log('OPEN', this.db.name, this.vr, this.db.verno, 'OPEN',this.db.isOpen())
|
|
3199
|
+
if (!this.tableExists(table)) {
|
|
3200
|
+
if (this.db.isOpen())
|
|
3201
|
+
await this.db.close();
|
|
3202
|
+
const newSchema = { [table]: schema };
|
|
3203
|
+
await this.db.version(this.nextVr).stores(newSchema);
|
|
3204
|
+
// console.log('Created New Table: ', table, schema)
|
|
3205
|
+
if (!this.db.isOpen())
|
|
3206
|
+
await this.db.open();
|
|
3207
|
+
}
|
|
3208
|
+
}
|
|
3209
|
+
updateObjectKeys(obj1, obj2) {
|
|
3210
|
+
return Object.keys(obj1).reduce((updatedObj, key) => {
|
|
3211
|
+
updatedObj[key] = obj2.hasOwnProperty(key) ? obj2[key] : obj1[key];
|
|
3212
|
+
return updatedObj;
|
|
3213
|
+
}, {});
|
|
3214
|
+
}
|
|
3215
|
+
async DBOpened() {
|
|
3216
|
+
if (!this.db.isOpen()) {
|
|
3217
|
+
await this.db.open()
|
|
3218
|
+
.then(async () => {
|
|
3219
|
+
// console.log('OPENED')
|
|
3220
|
+
})
|
|
3221
|
+
.catch(async (err) => {
|
|
3222
|
+
// console.log('OPENED ERR')
|
|
3223
|
+
return false;
|
|
3224
|
+
});
|
|
3225
|
+
}
|
|
3226
|
+
else {
|
|
3227
|
+
// console.log('OPENED')
|
|
3228
|
+
}
|
|
3229
|
+
return true;
|
|
3230
|
+
}
|
|
3231
|
+
normalizeString(item) {
|
|
3232
|
+
if (!item)
|
|
3233
|
+
return;
|
|
3234
|
+
return Array.isArray(item) ?
|
|
3235
|
+
item.map((item) => this.cleanString(item)).join()
|
|
3236
|
+
: item.split(',').map((item) => this.cleanString(item)).join();
|
|
3237
|
+
}
|
|
3238
|
+
cleanString(str) {
|
|
3239
|
+
const cleanStr = str
|
|
3240
|
+
.replace(/[^a-zA-Z0-9\s]/g, '')
|
|
3241
|
+
.replace(/\s+/g, '_');
|
|
3242
|
+
return cleanStr.trim().toLowerCase();
|
|
3243
|
+
}
|
|
3244
|
+
static { this.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "16.2.12", ngImport: i0, type: DbService, deps: [], target: i0.ɵɵFactoryTarget.Injectable }); }
|
|
3245
|
+
static { this.ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "16.2.12", ngImport: i0, type: DbService, providedIn: 'root' }); }
|
|
3246
|
+
}
|
|
3247
|
+
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "16.2.12", ngImport: i0, type: DbService, decorators: [{
|
|
3248
|
+
type: Injectable,
|
|
3249
|
+
args: [{
|
|
3250
|
+
providedIn: 'root',
|
|
3251
|
+
}]
|
|
3252
|
+
}], ctorParameters: function () { return []; } });
|
|
3253
|
+
|
|
3254
|
+
class DatabaseManagerService extends DbService {
|
|
3255
|
+
constructor() {
|
|
3256
|
+
super();
|
|
3257
|
+
this.createNewDatabase();
|
|
3258
|
+
}
|
|
3259
|
+
getDatabaseTables() {
|
|
3260
|
+
return from(this.DBOpened()).pipe(map(() => this.db.tables.map(item => item.name)));
|
|
3261
|
+
}
|
|
3262
|
+
hasDatabaseTable(table) {
|
|
3263
|
+
return from(this.DBOpened()).pipe(map(() => {
|
|
3264
|
+
return this.tableExists(this.clean(table));
|
|
3265
|
+
}));
|
|
3266
|
+
}
|
|
3267
|
+
getDatabaseTable(table) {
|
|
3268
|
+
return from(this.DBOpened()).pipe(map((res) => {
|
|
3269
|
+
this.hasDatabase().then((res) => {
|
|
3270
|
+
const tables = this.db.tables;
|
|
3271
|
+
const found = tables.find(item => item.name === this.clean(table)) || null;
|
|
3272
|
+
if (!found) {
|
|
3273
|
+
console.warn('No Such Table:', this.clean(table));
|
|
3274
|
+
return;
|
|
3275
|
+
}
|
|
3276
|
+
else {
|
|
3277
|
+
return found;
|
|
3278
|
+
}
|
|
3279
|
+
});
|
|
3280
|
+
}));
|
|
3281
|
+
}
|
|
3282
|
+
getDatabaseTableSchema(table) {
|
|
3283
|
+
return from(this.DBOpened()).pipe(mergeMap((res) => this.getDatabaseTable(table)), map((dbTable) => {
|
|
3284
|
+
if (!dbTable)
|
|
3285
|
+
return [];
|
|
3286
|
+
const cols = dbTable.schema.indexes.map((col) => col.name);
|
|
3287
|
+
const pri = dbTable.schema.primKey.name;
|
|
3288
|
+
return [pri, ...cols];
|
|
3289
|
+
}));
|
|
3290
|
+
}
|
|
3291
|
+
createDatabaseTable(tableDef) {
|
|
3292
|
+
this.createTable(tableDef.table, tableDef.schema);
|
|
3293
|
+
return from(this.DBOpened());
|
|
3294
|
+
}
|
|
3295
|
+
updateDatabaseTableSchema(tableDef) {
|
|
3296
|
+
}
|
|
3297
|
+
// CRUD
|
|
3298
|
+
findTableRecords(table, column, value) {
|
|
3299
|
+
}
|
|
3300
|
+
findTableRecord(table, column, value) {
|
|
3301
|
+
}
|
|
3302
|
+
getTableRecords(table) {
|
|
3303
|
+
}
|
|
3304
|
+
getTableRecord(table, id) {
|
|
3305
|
+
}
|
|
3306
|
+
createTableRecord(table, record) {
|
|
3307
|
+
return this.createTableRecords(table, [record])
|
|
3308
|
+
.pipe(map((item) => item ? item[0] : null));
|
|
3309
|
+
}
|
|
3310
|
+
createTableRecords(table, records) {
|
|
3311
|
+
return this.getDatabaseTable(table).pipe(switchMap((tableData) => {
|
|
3312
|
+
if (!tableData)
|
|
3313
|
+
return EMPTY;
|
|
3314
|
+
return this.getDatabaseTableSchema(table).pipe(map((schema) => {
|
|
3315
|
+
const insertRecords = records.map((record) => {
|
|
3316
|
+
const objectFromSchema = {};
|
|
3317
|
+
schema.forEach((field) => {
|
|
3318
|
+
const data = record[field] ?? null;
|
|
3319
|
+
objectFromSchema[field] = data;
|
|
3320
|
+
});
|
|
3321
|
+
return objectFromSchema;
|
|
3322
|
+
});
|
|
3323
|
+
tableData.bulkPut(insertRecords);
|
|
3324
|
+
return insertRecords;
|
|
3325
|
+
}));
|
|
3326
|
+
}));
|
|
3327
|
+
}
|
|
3328
|
+
updateTableRecord(table, record) {
|
|
3329
|
+
return this.updateTableRecords(table, [record])
|
|
3330
|
+
.pipe(map(item => item.length > 0 ? item[0] : null));
|
|
3331
|
+
}
|
|
3332
|
+
updateTableRecords(table, records) {
|
|
3333
|
+
return this.getDatabaseTable(table).pipe(switchMap((tableData) => {
|
|
3334
|
+
return this.getDatabaseTableSchema(table).pipe(map((schema) => {
|
|
3335
|
+
const insertRecords = records.map((record) => {
|
|
3336
|
+
const objectFromSchema = {};
|
|
3337
|
+
schema.forEach((field) => {
|
|
3338
|
+
const data = record[field] ?? null;
|
|
3339
|
+
objectFromSchema[field] = data;
|
|
3340
|
+
});
|
|
3341
|
+
return objectFromSchema;
|
|
3342
|
+
});
|
|
3343
|
+
tableData.bulkPut(insertRecords).then(() => console.log('Updated DB'));
|
|
3344
|
+
return insertRecords;
|
|
3345
|
+
}));
|
|
3346
|
+
}));
|
|
3347
|
+
}
|
|
3348
|
+
deleteTableRecord(table, id) {
|
|
3349
|
+
}
|
|
3350
|
+
clean(str) {
|
|
3351
|
+
const cleanStr = str
|
|
3352
|
+
.replace(/[^a-zA-Z0-9\s]/g, '_') // Replace non-alphanumeric characters except spaces with underscores
|
|
3353
|
+
.replace(/\s+/g, '_') // Replace spaces with underscores
|
|
3354
|
+
.toLowerCase() // Convert to lowercase
|
|
3355
|
+
.trim(); // Trim leading or trailing spaces
|
|
3356
|
+
return cleanStr;
|
|
3357
|
+
}
|
|
3358
|
+
static { this.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "16.2.12", ngImport: i0, type: DatabaseManagerService, deps: [], target: i0.ɵɵFactoryTarget.Injectable }); }
|
|
3359
|
+
static { this.ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "16.2.12", ngImport: i0, type: DatabaseManagerService, providedIn: 'root' }); }
|
|
3360
|
+
}
|
|
3361
|
+
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "16.2.12", ngImport: i0, type: DatabaseManagerService, decorators: [{
|
|
3362
|
+
type: Injectable,
|
|
3363
|
+
args: [{
|
|
3364
|
+
providedIn: 'root'
|
|
3365
|
+
}]
|
|
3366
|
+
}], ctorParameters: function () { return []; } });
|
|
3367
|
+
|
|
3368
|
+
class DatabaseDataDemoComponent {
|
|
3369
|
+
constructor() {
|
|
3370
|
+
this.db = inject(DatabaseManagerService);
|
|
3371
|
+
}
|
|
3372
|
+
ngOnInit() {
|
|
3373
|
+
const tableDef = TableSchemaDef.adapt({ table: 'Sample Table', schema: ['id', 'lastName', 'age'] });
|
|
3374
|
+
console.log(tableDef);
|
|
3375
|
+
this.createTable(tableDef).subscribe(() => {
|
|
3376
|
+
// hasTable
|
|
3377
|
+
this.db.hasDatabaseTable('Sample Table').subscribe(data => console.log(data));
|
|
3378
|
+
// Tables
|
|
3379
|
+
this.db.getDatabaseTables().subscribe(data => console.log(data));
|
|
3380
|
+
// getTable
|
|
3381
|
+
this.db.getDatabaseTable('Sample Table').subscribe(data => console.log(data));
|
|
3382
|
+
// Table Schema
|
|
3383
|
+
this.db.getDatabaseTableSchema('Sample Table').subscribe(data => console.log(data));
|
|
3384
|
+
// Update Table Schema
|
|
3385
|
+
// const newTableDef = TableSchemaDef.adapt({table: 'sample', schema: ['id', 'name', 'age', 'amount']})
|
|
3386
|
+
// this.db.updateDatabaseTableSchema(newTableDef)
|
|
3387
|
+
// Insert Table Record
|
|
3388
|
+
const record = { id: 12, age: 45, last_name: 'Bonifacio', amount: 1200 };
|
|
3389
|
+
this.db.createTableRecord('Sample Table', record).subscribe(data => console.log(data));
|
|
3390
|
+
// Insert Table Records
|
|
3391
|
+
const records = [
|
|
3392
|
+
{ id: 12, age: 12, last_name: 'Bonifacio', amount: 80 },
|
|
3393
|
+
{ id: 10, age: 15, last_name: 'Johns', amount: 700 },
|
|
3394
|
+
{ id: 1, age: 22, last_name: 'Kims', amount: 234 },
|
|
3395
|
+
{ id: 2, age: 45, last_name: 'Harrys', amount: 1200 },
|
|
3396
|
+
];
|
|
3397
|
+
this.db.createTableRecords('Sample Table', records).subscribe(data => console.log(data));
|
|
3398
|
+
// Update Table Record
|
|
3399
|
+
const recordUpdate = { id: 12, age: 45, last_name: 'Bonifacio', amount: 5000 };
|
|
3400
|
+
this.db.createTableRecord('Sample Table', record).subscribe(data => console.log(data));
|
|
3401
|
+
// Update Table Records
|
|
3402
|
+
// const recordsUpdate = [
|
|
3403
|
+
// { id: 12, age: 12, last_name: 'Bonifacio', amount: 5000 },
|
|
3404
|
+
// { id: 10, age: 15, last_name: 'Johns', amount: 5000 },
|
|
3405
|
+
// ]
|
|
3406
|
+
// this.db.updateTableRecords('sample_table', records).subscribe(data => console.log(data))
|
|
3407
|
+
});
|
|
3408
|
+
}
|
|
3409
|
+
createTable(tableDef) {
|
|
3410
|
+
return this.db.createDatabaseTable(tableDef);
|
|
3411
|
+
}
|
|
3412
|
+
// CRUD
|
|
3413
|
+
findTableRecords(table, column, value) {
|
|
3414
|
+
}
|
|
3415
|
+
findTableRecord(table, column, value) {
|
|
3416
|
+
}
|
|
3417
|
+
getTableRecords(table) {
|
|
3418
|
+
}
|
|
3419
|
+
getTableRecord(table, id) {
|
|
3420
|
+
}
|
|
3421
|
+
createTableRecord(table, record) {
|
|
3422
|
+
}
|
|
3423
|
+
updateTableRecord(table, record) {
|
|
3424
|
+
}
|
|
3425
|
+
deleteTableRecord(table, id) {
|
|
3426
|
+
}
|
|
3427
|
+
static { this.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "16.2.12", ngImport: i0, type: DatabaseDataDemoComponent, deps: [], target: i0.ɵɵFactoryTarget.Component }); }
|
|
3428
|
+
static { this.ɵcmp = i0.ɵɵngDeclareComponent({ minVersion: "14.0.0", version: "16.2.12", type: DatabaseDataDemoComponent, selector: "app-database-data-demo", ngImport: i0, template: "<p>\n database-data-demo works!\n</p>\n", styles: [""] }); }
|
|
3429
|
+
}
|
|
3430
|
+
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "16.2.12", ngImport: i0, type: DatabaseDataDemoComponent, decorators: [{
|
|
3431
|
+
type: Component,
|
|
3432
|
+
args: [{ selector: 'app-database-data-demo', template: "<p>\n database-data-demo works!\n</p>\n" }]
|
|
3433
|
+
}], ctorParameters: function () { return []; } });
|
|
3434
|
+
|
|
3093
3435
|
/*
|
|
3094
3436
|
* Public API Surface of http-request-manager
|
|
3095
3437
|
*/
|
|
@@ -3098,5 +3440,5 @@ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "16.2.12", ngImpo
|
|
|
3098
3440
|
* Generated bundle index. Do not edit.
|
|
3099
3441
|
*/
|
|
3100
3442
|
|
|
3101
|
-
export { ApiRequest, AppService, AsymmetricalEncryptionService, ConfigHTTPOptions, ConfigOptions, DataType, DatabaseStorage, ErrorDisplaySettings, GlobalStoreOptions, HTTPManagerService, HTTPManagerStateService, HeadersService, HttpRequestManagerModule, HttpRequestServicesDemoComponent, LocalStorageManagerService, LocalStorageOptions, PathQueryService, Random, RandomNumber, RandomNumbers, RandomNumbersUnique, RandomSignature, RandomStr, RequestErrorInterceptor, RequestHeadersInterceptor, RequestOptions, RetryOptions, SettingOptions, StorageData, StorageOption, StorageType, SymmetricalEncryptionService, UUID, UtilsService, WithCredentialsInterceptor, countdown, delayedRetry, requestPolling, requestStreaming };
|
|
3443
|
+
export { ApiRequest, AppService, AsymmetricalEncryptionService, ConfigHTTPOptions, ConfigOptions, DataType, DatabaseDataDemoComponent, DatabaseStorage, ErrorDisplaySettings, GlobalStoreOptions, HTTPManagerService, HTTPManagerStateService, HeadersService, HttpRequestManagerModule, HttpRequestServicesDemoComponent, LocalStorageDemoComponent, LocalStorageManagerService, LocalStorageOptions, PathQueryService, Random, RandomNumber, RandomNumbers, RandomNumbersUnique, RandomSignature, RandomStr, RequestErrorInterceptor, RequestHeadersInterceptor, RequestManagerDemoComponent, RequestManagerStateDemoComponent, RequestOptions, RetryOptions, SettingOptions, StorageData, StorageOption, StorageType, SymmetricalEncryptionService, UUID, UtilsService, WithCredentialsInterceptor, countdown, delayedRetry, requestPolling, requestStreaming };
|
|
3102
3444
|
//# sourceMappingURL=http-request-manager.mjs.map
|