http-request-manager 18.13.17 → 18.13.19
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.
|
@@ -876,14 +876,13 @@ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "18.2.14", ngImpo
|
|
|
876
876
|
}], ctorParameters: () => [] });
|
|
877
877
|
|
|
878
878
|
class PathTrackerStateModel {
|
|
879
|
-
constructor(baselineQuery, consumedValuesByKey = {}, watchExpiresAt
|
|
879
|
+
constructor(baselineQuery, consumedValuesByKey = {}, watchExpiresAt) {
|
|
880
880
|
this.baselineQuery = baselineQuery;
|
|
881
881
|
this.consumedValuesByKey = consumedValuesByKey;
|
|
882
882
|
this.watchExpiresAt = watchExpiresAt;
|
|
883
|
-
this.trackedAt = trackedAt;
|
|
884
883
|
}
|
|
885
884
|
static adapt(item) {
|
|
886
|
-
return new PathTrackerStateModel(item?.baselineQuery, item?.consumedValuesByKey, item?.watchExpiresAt
|
|
885
|
+
return new PathTrackerStateModel(item?.baselineQuery, item?.consumedValuesByKey, item?.watchExpiresAt);
|
|
887
886
|
}
|
|
888
887
|
}
|
|
889
888
|
|
|
@@ -904,15 +903,14 @@ class QueryTrackerStateModel {
|
|
|
904
903
|
const TRACKER_STORE_NAME = 'query_params_tracker';
|
|
905
904
|
const TRACKER_SESSION_INIT_KEY = 'query_params_tracker_initialized';
|
|
906
905
|
const DEFAULT_TRACKER_OPTIONS = SettingOptions.adapt({
|
|
907
|
-
storage: StorageType.
|
|
906
|
+
storage: StorageType.GLOBAL,
|
|
908
907
|
encrypted: false,
|
|
909
|
-
expiresIn: '1d',
|
|
910
908
|
});
|
|
911
909
|
class QueryParamsTrackerService {
|
|
912
910
|
constructor() {
|
|
913
|
-
this.localStorageManager = inject(LocalStorageManagerService);
|
|
914
911
|
this.state = { paths: {} };
|
|
915
912
|
this.stateRestored = false;
|
|
913
|
+
this.localStorageManager = inject(LocalStorageManagerService);
|
|
916
914
|
}
|
|
917
915
|
clearTracking(resetSessionInit = false) {
|
|
918
916
|
this.state = { paths: {} };
|
|
@@ -923,18 +921,12 @@ class QueryParamsTrackerService {
|
|
|
923
921
|
}
|
|
924
922
|
checkRequestOptions(requestOptions = [], options = {}) {
|
|
925
923
|
this.ensureStateRestored();
|
|
926
|
-
this.tryHydrateStateFromPersistedStore();
|
|
927
924
|
const normalized = this.normalizeRequestOptions(requestOptions);
|
|
928
925
|
if (!normalized.pathKey)
|
|
929
926
|
return false;
|
|
930
927
|
this.cleanupExpiredEntries();
|
|
931
928
|
if (!normalized.hasQuery) {
|
|
932
|
-
|
|
933
|
-
if (pathExists) {
|
|
934
|
-
return false;
|
|
935
|
-
}
|
|
936
|
-
const pathState = this.ensurePathState(normalized.pathKey);
|
|
937
|
-
pathState.trackedAt = Math.floor(Date.now() / 1000);
|
|
929
|
+
this.ensurePathState(normalized.pathKey);
|
|
938
930
|
this.persistState();
|
|
939
931
|
return true;
|
|
940
932
|
}
|
|
@@ -945,7 +937,6 @@ class QueryParamsTrackerService {
|
|
|
945
937
|
}
|
|
946
938
|
matchesPath(requestOptions = [], expectedPathOptions = []) {
|
|
947
939
|
this.ensureStateRestored();
|
|
948
|
-
this.tryHydrateStateFromPersistedStore();
|
|
949
940
|
const requestPath = this.normalizeRequestOptions(requestOptions).pathKey;
|
|
950
941
|
const expectedPath = this.normalizeRequestOptions(expectedPathOptions).pathKey;
|
|
951
942
|
return Boolean(requestPath) && requestPath === expectedPath;
|
|
@@ -1057,31 +1048,13 @@ class QueryParamsTrackerService {
|
|
|
1057
1048
|
}
|
|
1058
1049
|
}
|
|
1059
1050
|
normalizePath(pathSegments) {
|
|
1060
|
-
|
|
1061
|
-
.map((segment) => this.extractPathFromSegment(segment))
|
|
1062
|
-
.flatMap((segment) => segment.split('/'))
|
|
1051
|
+
return pathSegments
|
|
1063
1052
|
.map((segment) => String(segment).trim())
|
|
1064
|
-
.filter((segment) => segment.length > 0)
|
|
1065
|
-
|
|
1066
|
-
|
|
1067
|
-
|
|
1068
|
-
|
|
1069
|
-
return normalizedSegments.join('/');
|
|
1070
|
-
}
|
|
1071
|
-
extractPathFromSegment(segment) {
|
|
1072
|
-
const raw = String(segment).trim();
|
|
1073
|
-
if (!raw) {
|
|
1074
|
-
return '';
|
|
1075
|
-
}
|
|
1076
|
-
try {
|
|
1077
|
-
if (/^https?:\/\//i.test(raw)) {
|
|
1078
|
-
return new URL(raw).pathname;
|
|
1079
|
-
}
|
|
1080
|
-
}
|
|
1081
|
-
catch {
|
|
1082
|
-
return raw;
|
|
1083
|
-
}
|
|
1084
|
-
return raw;
|
|
1053
|
+
.filter((segment) => segment.length > 0)
|
|
1054
|
+
.join('/')
|
|
1055
|
+
.replace(/([^:]\/+)\/+/g, '$1')
|
|
1056
|
+
.replace(/^\//, '')
|
|
1057
|
+
.replace(/\/$/, '');
|
|
1085
1058
|
}
|
|
1086
1059
|
normalizeParamKey(key) {
|
|
1087
1060
|
return String(key).trim().toLowerCase();
|
|
@@ -1146,8 +1119,7 @@ class QueryParamsTrackerService {
|
|
|
1146
1119
|
}
|
|
1147
1120
|
const hasBaseline = Boolean(pathState.baselineQuery && Object.keys(pathState.baselineQuery).length > 0);
|
|
1148
1121
|
const hasTrackedValues = Object.keys(pathState.consumedValuesByKey).some((key) => (pathState.consumedValuesByKey[key] || []).length > 0);
|
|
1149
|
-
|
|
1150
|
-
if (!hasBaseline && !hasTrackedValues && !isNoQueryTracked) {
|
|
1122
|
+
if (!hasBaseline && !hasTrackedValues) {
|
|
1151
1123
|
delete this.state.paths[pathKey];
|
|
1152
1124
|
}
|
|
1153
1125
|
});
|
|
@@ -1176,20 +1148,14 @@ class QueryParamsTrackerService {
|
|
|
1176
1148
|
if (initialized === '1') {
|
|
1177
1149
|
return;
|
|
1178
1150
|
}
|
|
1151
|
+
this.clearTracking();
|
|
1179
1152
|
sessionStorage.setItem(TRACKER_SESSION_INIT_KEY, '1');
|
|
1180
1153
|
}
|
|
1181
1154
|
restoreState() {
|
|
1182
|
-
this.tryHydrateStateFromPersistedStore();
|
|
1183
|
-
if (Object.keys(this.state.paths).length > 0) {
|
|
1184
|
-
return;
|
|
1185
|
-
}
|
|
1186
1155
|
this.localStorageManager.store$(TRACKER_STORE_NAME)
|
|
1187
1156
|
.pipe(take(1))
|
|
1188
1157
|
.subscribe({
|
|
1189
1158
|
next: (storedState) => {
|
|
1190
|
-
if (Object.keys(this.state.paths).length > 0) {
|
|
1191
|
-
return;
|
|
1192
|
-
}
|
|
1193
1159
|
if (this.isTrackerState(storedState)) {
|
|
1194
1160
|
this.state = QueryTrackerStateModel.adapt(storedState);
|
|
1195
1161
|
this.cleanupExpiredEntries();
|
|
@@ -1198,60 +1164,10 @@ class QueryParamsTrackerService {
|
|
|
1198
1164
|
this.state = { paths: {} };
|
|
1199
1165
|
},
|
|
1200
1166
|
error: () => {
|
|
1201
|
-
|
|
1202
|
-
this.state = { paths: {} };
|
|
1203
|
-
}
|
|
1167
|
+
this.state = { paths: {} };
|
|
1204
1168
|
}
|
|
1205
1169
|
});
|
|
1206
1170
|
}
|
|
1207
|
-
tryHydrateStateFromPersistedStore() {
|
|
1208
|
-
if (Object.keys(this.state.paths).length > 0) {
|
|
1209
|
-
return;
|
|
1210
|
-
}
|
|
1211
|
-
const syncState = this.localStorageManager.getPersistedStoreSync(TRACKER_STORE_NAME);
|
|
1212
|
-
if (this.isTrackerState(syncState)) {
|
|
1213
|
-
this.state = QueryTrackerStateModel.adapt(syncState);
|
|
1214
|
-
this.cleanupExpiredEntries();
|
|
1215
|
-
return;
|
|
1216
|
-
}
|
|
1217
|
-
const fallbackState = this.getTrackerStateFromRawStorage();
|
|
1218
|
-
if (!this.isTrackerState(fallbackState)) {
|
|
1219
|
-
return;
|
|
1220
|
-
}
|
|
1221
|
-
this.state = QueryTrackerStateModel.adapt(fallbackState);
|
|
1222
|
-
this.cleanupExpiredEntries();
|
|
1223
|
-
}
|
|
1224
|
-
getTrackerStateFromRawStorage() {
|
|
1225
|
-
const rawSources = [
|
|
1226
|
-
this.safeParseRawStorage(localStorage.getItem('storage')),
|
|
1227
|
-
this.safeParseRawStorage(sessionStorage.getItem('storage')),
|
|
1228
|
-
];
|
|
1229
|
-
for (const source of rawSources) {
|
|
1230
|
-
if (!Array.isArray(source)) {
|
|
1231
|
-
continue;
|
|
1232
|
-
}
|
|
1233
|
-
for (const entry of source) {
|
|
1234
|
-
if (this.isTrackerState(entry?.data)) {
|
|
1235
|
-
return entry.data;
|
|
1236
|
-
}
|
|
1237
|
-
if (this.isTrackerState(entry)) {
|
|
1238
|
-
return entry;
|
|
1239
|
-
}
|
|
1240
|
-
}
|
|
1241
|
-
}
|
|
1242
|
-
return null;
|
|
1243
|
-
}
|
|
1244
|
-
safeParseRawStorage(value) {
|
|
1245
|
-
if (!value) {
|
|
1246
|
-
return null;
|
|
1247
|
-
}
|
|
1248
|
-
try {
|
|
1249
|
-
return JSON.parse(value);
|
|
1250
|
-
}
|
|
1251
|
-
catch {
|
|
1252
|
-
return null;
|
|
1253
|
-
}
|
|
1254
|
-
}
|
|
1255
1171
|
persistState() {
|
|
1256
1172
|
this.localStorageManager.storeExists$(TRACKER_STORE_NAME)
|
|
1257
1173
|
.pipe(take(1))
|
|
@@ -1276,23 +1192,7 @@ class QueryParamsTrackerService {
|
|
|
1276
1192
|
}, {}));
|
|
1277
1193
|
}
|
|
1278
1194
|
isTrackerState(value) {
|
|
1279
|
-
|
|
1280
|
-
return false;
|
|
1281
|
-
}
|
|
1282
|
-
return Object.keys(value.paths).every((pathKey) => this.isTrackerPathState(value.paths[pathKey]));
|
|
1283
|
-
}
|
|
1284
|
-
isTrackerPathState(value) {
|
|
1285
|
-
if (!this.isPlainObject(value)) {
|
|
1286
|
-
return false;
|
|
1287
|
-
}
|
|
1288
|
-
const hasValidConsumedValues = typeof value.consumedValuesByKey === 'undefined' || this.isPlainObject(value.consumedValuesByKey);
|
|
1289
|
-
const hasValidTrackedAt = typeof value.trackedAt === 'undefined' || typeof value.trackedAt === 'number';
|
|
1290
|
-
const hasValidWatchExpiresAt = typeof value.watchExpiresAt === 'undefined' || typeof value.watchExpiresAt === 'number';
|
|
1291
|
-
const hasValidBaselineQuery = typeof value.baselineQuery === 'undefined' || this.isPlainObject(value.baselineQuery);
|
|
1292
|
-
const hasTrackerMarkers = this.isPlainObject(value.consumedValuesByKey) ||
|
|
1293
|
-
typeof value.trackedAt === 'number' ||
|
|
1294
|
-
this.isPlainObject(value.baselineQuery);
|
|
1295
|
-
return hasValidConsumedValues && hasValidTrackedAt && hasValidWatchExpiresAt && hasValidBaselineQuery && hasTrackerMarkers;
|
|
1195
|
+
return this.isPlainObject(value) && this.isPlainObject(value.paths);
|
|
1296
1196
|
}
|
|
1297
1197
|
isPlainObject(value) {
|
|
1298
1198
|
return Object.prototype.toString.call(value) === '[object Object]';
|
|
@@ -5517,87 +5417,6 @@ const storage = {
|
|
|
5517
5417
|
settings: [],
|
|
5518
5418
|
};
|
|
5519
5419
|
class LocalStorageManagerService extends ComponentStore {
|
|
5520
|
-
getStoreSync(storeName) {
|
|
5521
|
-
storeName = storeName.toLowerCase();
|
|
5522
|
-
const data = this.get();
|
|
5523
|
-
const foundStore = data.settings.find(item => item.name === storeName);
|
|
5524
|
-
if (!foundStore) {
|
|
5525
|
-
return null;
|
|
5526
|
-
}
|
|
5527
|
-
const found = foundStore.options?.storage === StorageType.GLOBAL
|
|
5528
|
-
? data.localStores.find(item => item.id === foundStore.id)
|
|
5529
|
-
: data.sessionStores.find(item => item.id === foundStore.id);
|
|
5530
|
-
if (!found || !this.app?.appID) {
|
|
5531
|
-
return null;
|
|
5532
|
-
}
|
|
5533
|
-
const options = SettingOptions.adapt(foundStore.options);
|
|
5534
|
-
let storageData = found.data;
|
|
5535
|
-
if (options.encrypted) {
|
|
5536
|
-
const decryptedData = this.encryption.decrypt(found.data, this.app.appID);
|
|
5537
|
-
if (decryptedData !== null) {
|
|
5538
|
-
storageData = decryptedData;
|
|
5539
|
-
}
|
|
5540
|
-
}
|
|
5541
|
-
try {
|
|
5542
|
-
return this.isString(storageData) ? JSON.parse(storageData) : storageData;
|
|
5543
|
-
}
|
|
5544
|
-
catch {
|
|
5545
|
-
return storageData;
|
|
5546
|
-
}
|
|
5547
|
-
}
|
|
5548
|
-
getPersistedStoreSync(storeName) {
|
|
5549
|
-
storeName = this.validStoreName(String(storeName || ''));
|
|
5550
|
-
if (!storeName || !this.app?.appID) {
|
|
5551
|
-
return null;
|
|
5552
|
-
}
|
|
5553
|
-
const settingsStr = localStorage.getItem(this.storageSettingsName);
|
|
5554
|
-
if (!settingsStr) {
|
|
5555
|
-
return null;
|
|
5556
|
-
}
|
|
5557
|
-
let settings = [];
|
|
5558
|
-
try {
|
|
5559
|
-
const decryptedSettings = this.encryption.decrypt(settingsStr, this.app.appID);
|
|
5560
|
-
settings = decryptedSettings ? JSON.parse(decryptedSettings) : [];
|
|
5561
|
-
}
|
|
5562
|
-
catch {
|
|
5563
|
-
return null;
|
|
5564
|
-
}
|
|
5565
|
-
const foundSetting = settings.find(item => item.name === storeName);
|
|
5566
|
-
if (!foundSetting) {
|
|
5567
|
-
return null;
|
|
5568
|
-
}
|
|
5569
|
-
const rawStores = foundSetting.options?.storage === StorageType.GLOBAL
|
|
5570
|
-
? localStorage.getItem(this.storageName)
|
|
5571
|
-
: sessionStorage.getItem(this.storageName);
|
|
5572
|
-
if (!rawStores) {
|
|
5573
|
-
return null;
|
|
5574
|
-
}
|
|
5575
|
-
let stores = [];
|
|
5576
|
-
try {
|
|
5577
|
-
stores = JSON.parse(rawStores);
|
|
5578
|
-
}
|
|
5579
|
-
catch {
|
|
5580
|
-
return null;
|
|
5581
|
-
}
|
|
5582
|
-
const foundStore = stores.find(item => item.id === foundSetting.id);
|
|
5583
|
-
if (!foundStore) {
|
|
5584
|
-
return null;
|
|
5585
|
-
}
|
|
5586
|
-
const options = SettingOptions.adapt(foundSetting.options);
|
|
5587
|
-
let storageData = foundStore.data;
|
|
5588
|
-
if (options.encrypted) {
|
|
5589
|
-
const decryptedData = this.encryption.decrypt(foundStore.data, this.app.appID);
|
|
5590
|
-
if (decryptedData !== null) {
|
|
5591
|
-
storageData = decryptedData;
|
|
5592
|
-
}
|
|
5593
|
-
}
|
|
5594
|
-
try {
|
|
5595
|
-
return this.isString(storageData) ? JSON.parse(storageData) : storageData;
|
|
5596
|
-
}
|
|
5597
|
-
catch {
|
|
5598
|
-
return storageData;
|
|
5599
|
-
}
|
|
5600
|
-
}
|
|
5601
5420
|
startTimer() {
|
|
5602
5421
|
const timer$ = interval(1000 * 3).pipe(withLatestFrom(this.data$), map(([_, state]) => state), tap((state) => {
|
|
5603
5422
|
const expired = this.expired(state) ? this.expired(state) : [];
|
|
@@ -6558,7 +6377,15 @@ class DatabaseManagerService extends DbService {
|
|
|
6558
6377
|
}
|
|
6559
6378
|
createTableRecords(table, records) {
|
|
6560
6379
|
const tableName = this.cleanTableName(table);
|
|
6561
|
-
|
|
6380
|
+
// Keep full object payload; Dexie stores non-indexed properties as well.
|
|
6381
|
+
const insertRecords = records.map((record) => {
|
|
6382
|
+
const payload = { ...(record || {}) };
|
|
6383
|
+
if (payload.id === undefined || payload.id === null || payload.id === '') {
|
|
6384
|
+
delete payload.id;
|
|
6385
|
+
}
|
|
6386
|
+
return payload;
|
|
6387
|
+
});
|
|
6388
|
+
const writeRecords = () => from(this.DBOpened()).pipe(switchMap((opened) => {
|
|
6562
6389
|
if (!opened) {
|
|
6563
6390
|
console.error(`createTableRecords: DB not open. Cannot write to '${tableName}'.`);
|
|
6564
6391
|
return EMPTY;
|
|
@@ -6568,17 +6395,28 @@ class DatabaseManagerService extends DbService {
|
|
|
6568
6395
|
return EMPTY;
|
|
6569
6396
|
}
|
|
6570
6397
|
const tableInstance = this.table(tableName);
|
|
6571
|
-
// Keep full object payload; Dexie stores non-indexed properties as well.
|
|
6572
|
-
const insertRecords = records.map((record) => {
|
|
6573
|
-
const payload = { ...(record || {}) };
|
|
6574
|
-
if (payload.id === undefined || payload.id === null || payload.id === '') {
|
|
6575
|
-
delete payload.id;
|
|
6576
|
-
}
|
|
6577
|
-
return payload;
|
|
6578
|
-
});
|
|
6579
6398
|
console.log(`createTableRecords: Bulk putting ${insertRecords.length} records into ${tableName}`);
|
|
6580
6399
|
return from(tableInstance.bulkPut(insertRecords)).pipe(map(() => insertRecords));
|
|
6581
6400
|
}));
|
|
6401
|
+
return writeRecords().pipe(catchError((error) => {
|
|
6402
|
+
if (!this.isMissingObjectStoreError(error)) {
|
|
6403
|
+
throw error;
|
|
6404
|
+
}
|
|
6405
|
+
console.warn(`createTableRecords: Missing object store for '${tableName}'. Waiting for DB readiness and retrying once...`, error);
|
|
6406
|
+
return from(this.createNewDatabase()).pipe(switchMap(() => writeRecords()), catchError((retryError) => {
|
|
6407
|
+
console.error(`createTableRecords: Retry failed for '${tableName}'`, retryError);
|
|
6408
|
+
throw retryError;
|
|
6409
|
+
}));
|
|
6410
|
+
}));
|
|
6411
|
+
}
|
|
6412
|
+
isMissingObjectStoreError(error) {
|
|
6413
|
+
const name = String(error?.name || '').toLowerCase();
|
|
6414
|
+
const innerName = String(error?.inner?.name || '').toLowerCase();
|
|
6415
|
+
const message = String(error?.message || error?.inner?.message || '').toLowerCase();
|
|
6416
|
+
return (name.includes('notfounderror') ||
|
|
6417
|
+
innerName.includes('notfounderror') ||
|
|
6418
|
+
message.includes('object store') ||
|
|
6419
|
+
message.includes('one of the specified object stores was not found'));
|
|
6582
6420
|
}
|
|
6583
6421
|
updateTableRecord(table, record) {
|
|
6584
6422
|
const tableName = this.cleanTableName(table);
|
|
@@ -7418,14 +7256,14 @@ class HTTPManagerStateService extends ComponentStore {
|
|
|
7418
7256
|
return this.httpManagerService.getRequest(requestOptions, effectiveParams).pipe(map((apiData) => ({ data: apiData, fromCache: false })));
|
|
7419
7257
|
})).pipe(tap((packet) => {
|
|
7420
7258
|
const res = packet?.data;
|
|
7421
|
-
|
|
7259
|
+
console.log('[DEBUG] Streaming response received:', res);
|
|
7422
7260
|
if (res && res.length > 0) {
|
|
7423
|
-
|
|
7261
|
+
console.log('[DEBUG] Updating state with streaming data:', res);
|
|
7424
7262
|
this.setData$(res);
|
|
7425
7263
|
this.streamedResponse = res;
|
|
7426
7264
|
}
|
|
7427
7265
|
else {
|
|
7428
|
-
|
|
7266
|
+
console.log('[DEBUG] No streaming data or empty array:', res);
|
|
7429
7267
|
}
|
|
7430
7268
|
// Reset pending once we have a response packet (cache or network)
|
|
7431
7269
|
this.httpManagerService.isPending.next(false);
|
|
@@ -7435,33 +7273,33 @@ class HTTPManagerStateService extends ComponentStore {
|
|
|
7435
7273
|
}
|
|
7436
7274
|
return this.persistStreamDataToDb(packet?.data, options);
|
|
7437
7275
|
}), map((res) => {
|
|
7438
|
-
|
|
7276
|
+
console.log('[DEBUG] Returning data to subscribers:', res);
|
|
7439
7277
|
return res;
|
|
7440
7278
|
}), catchError((error) => {
|
|
7441
|
-
|
|
7279
|
+
console.error('[DEBUG] Streaming error:', error);
|
|
7442
7280
|
this.httpManagerService.isPending.next(false);
|
|
7443
7281
|
return of([]);
|
|
7444
7282
|
}));
|
|
7445
7283
|
}
|
|
7446
7284
|
return this.httpManagerService.getRequest(requestOptions, effectiveParams)
|
|
7447
7285
|
.pipe(tap((res) => {
|
|
7448
|
-
|
|
7286
|
+
console.log('[DEBUG] Streaming response received:', res);
|
|
7449
7287
|
// Always update state with streaming data
|
|
7450
7288
|
if (res && res.length > 0) {
|
|
7451
|
-
|
|
7289
|
+
console.log('[DEBUG] Updating state with streaming data:', res);
|
|
7452
7290
|
this.setData$(res);
|
|
7453
7291
|
this.streamedResponse = res;
|
|
7454
7292
|
}
|
|
7455
7293
|
else {
|
|
7456
|
-
|
|
7294
|
+
console.log('[DEBUG] No streaming data or empty array:', res);
|
|
7457
7295
|
}
|
|
7458
7296
|
// Reset pending once we have a response packet
|
|
7459
7297
|
this.httpManagerService.isPending.next(false);
|
|
7460
7298
|
}), concatMap((res) => this.persistStreamDataToDb(res, options)), map((res) => {
|
|
7461
|
-
|
|
7299
|
+
console.log('[DEBUG] Returning data to subscribers:', res);
|
|
7462
7300
|
return res; // Return the data so subscribers can receive it
|
|
7463
7301
|
}), catchError((error) => {
|
|
7464
|
-
|
|
7302
|
+
console.error('[DEBUG] Streaming error:', error);
|
|
7465
7303
|
this.httpManagerService.isPending.next(false);
|
|
7466
7304
|
return of([]);
|
|
7467
7305
|
}));
|
|
@@ -7561,17 +7399,24 @@ class HTTPManagerStateService extends ComponentStore {
|
|
|
7561
7399
|
});
|
|
7562
7400
|
}
|
|
7563
7401
|
}
|
|
7564
|
-
|
|
7402
|
+
const wsOptions = this.apiOptions.ws;
|
|
7403
|
+
if (!wsOptions) {
|
|
7404
|
+
this.logger.debug('StateStore', 'WSOptions not provided; skipping WebSocket initialization');
|
|
7405
|
+
return;
|
|
7406
|
+
}
|
|
7407
|
+
const wsId = String(wsOptions.id || '').trim();
|
|
7408
|
+
if (wsId !== '') {
|
|
7409
|
+
wsOptions.id = wsId;
|
|
7565
7410
|
// Auto-prefix channel ID for private state manager channels
|
|
7566
7411
|
// This ensures state manager channels are separate from user-defined channels
|
|
7567
|
-
|
|
7568
|
-
this.logger.debug('StateStore', `🔒 Private state channel configured`, { channelId:
|
|
7412
|
+
wsOptions.id = this.prefixChannel(wsOptions.id, ChannelType.STATE);
|
|
7413
|
+
this.logger.debug('StateStore', `🔒 Private state channel configured`, { channelId: wsOptions.id });
|
|
7569
7414
|
// Store our own sessionId for filtering incoming messages
|
|
7570
7415
|
this.ownSessionId = sessionStorage.getItem('WSID') || null;
|
|
7571
7416
|
this.logger.debug('StateStore', `🆔 Stored own sessionId for message filtering`, { sessionId: this.ownSessionId });
|
|
7572
7417
|
this.logger.debug('StateStore', `🔍 WebSocket configuration`, {
|
|
7573
|
-
channelId:
|
|
7574
|
-
wsServer:
|
|
7418
|
+
channelId: wsOptions.id,
|
|
7419
|
+
wsServer: wsOptions.wsServer,
|
|
7575
7420
|
sessionId: this.ownSessionId,
|
|
7576
7421
|
path: this.apiOptions.path
|
|
7577
7422
|
});
|
|
@@ -7583,13 +7428,15 @@ class HTTPManagerStateService extends ComponentStore {
|
|
|
7583
7428
|
// initWS is an effect that triggers when setApiRequestOptions is called with ws config
|
|
7584
7429
|
// The effect is already triggered by calling setApiRequestOptions above
|
|
7585
7430
|
}
|
|
7586
|
-
if (
|
|
7587
|
-
this.maxRetries =
|
|
7588
|
-
this.retryDelay = (
|
|
7431
|
+
if (wsOptions.retry) {
|
|
7432
|
+
this.maxRetries = wsOptions.retry.times || 3;
|
|
7433
|
+
this.retryDelay = (wsOptions.retry.delay && wsOptions.retry.delay * 1000) || 5 * 1000;
|
|
7589
7434
|
this.wsNextRetry.next(this.retryDelay);
|
|
7590
7435
|
}
|
|
7591
7436
|
// Validate wsServer before attempting connection
|
|
7592
|
-
|
|
7437
|
+
const wsServer = String(wsOptions.wsServer || '').trim();
|
|
7438
|
+
wsOptions.wsServer = wsServer;
|
|
7439
|
+
if (!wsServer) {
|
|
7593
7440
|
this.logger.error('StateStore', 'WSOptions invalid: wsServer is missing or empty');
|
|
7594
7441
|
return;
|
|
7595
7442
|
}
|
|
@@ -7602,9 +7449,9 @@ class HTTPManagerStateService extends ComponentStore {
|
|
|
7602
7449
|
this.connectionStatusSubscription = this.setupConnectionStatus().subscribe();
|
|
7603
7450
|
// Make initial connection attempt
|
|
7604
7451
|
this.logger.debug('StateStore', '🔄 Initial WebSocket connection attempt...');
|
|
7605
|
-
this.httpManagerService.connect(
|
|
7452
|
+
this.httpManagerService.connect(wsOptions, wsOptions.jwtToken || '');
|
|
7606
7453
|
// Initialize WS effect to handle messages
|
|
7607
|
-
this.initWS(
|
|
7454
|
+
this.initWS(wsOptions);
|
|
7608
7455
|
}
|
|
7609
7456
|
else {
|
|
7610
7457
|
this.logger.warn('StateStore', 'WSOptions invalid Id: empty');
|
|
@@ -7826,15 +7673,15 @@ class HTTPManagerStateService extends ComponentStore {
|
|
|
7826
7673
|
return;
|
|
7827
7674
|
}
|
|
7828
7675
|
// DEBUG: Log what we're sending
|
|
7829
|
-
|
|
7830
|
-
|
|
7831
|
-
|
|
7832
|
-
|
|
7833
|
-
|
|
7834
|
-
|
|
7835
|
-
|
|
7836
|
-
|
|
7837
|
-
|
|
7676
|
+
console.log('🔍 [DEBUG] sendWsCommunication called:', {
|
|
7677
|
+
wsServer,
|
|
7678
|
+
wsServerType: typeof wsServer,
|
|
7679
|
+
wsServerEmpty: wsServer === '' || wsServer === null || wsServer === undefined,
|
|
7680
|
+
method,
|
|
7681
|
+
path,
|
|
7682
|
+
user: this.apiOptions.ws.user,
|
|
7683
|
+
fullPayload: { method, path, user: this.apiOptions.ws.user }
|
|
7684
|
+
});
|
|
7838
7685
|
this.httpManagerService.sendMessageInChannel(wsServer, { method, path, user: this.apiOptions.ws.user });
|
|
7839
7686
|
}
|
|
7840
7687
|
else {
|
|
@@ -8090,8 +7937,7 @@ class HTTPManagerStateService extends ComponentStore {
|
|
|
8090
7937
|
if (!this.hasDatabase || !this.databaseOptions?.table)
|
|
8091
7938
|
return;
|
|
8092
7939
|
const tableName = this.databaseOptions.table;
|
|
8093
|
-
this.dbManagerService.clearTable(tableName)
|
|
8094
|
-
.subscribe({
|
|
7940
|
+
this.dbManagerService.clearTable(tableName).subscribe({
|
|
8095
7941
|
next: () => {
|
|
8096
7942
|
this.clearRequestCacheMetadata(tableName);
|
|
8097
7943
|
if (this.dataType === DataType.ARRAY) {
|
|
@@ -8106,17 +7952,6 @@ class HTTPManagerStateService extends ComponentStore {
|
|
|
8106
7952
|
}
|
|
8107
7953
|
});
|
|
8108
7954
|
}
|
|
8109
|
-
clearTable(tableName) {
|
|
8110
|
-
this.dbManagerService.clearTable(tableName)
|
|
8111
|
-
.subscribe({
|
|
8112
|
-
next: () => {
|
|
8113
|
-
this.clearRequestCacheMetadata(tableName);
|
|
8114
|
-
},
|
|
8115
|
-
error: (err) => {
|
|
8116
|
-
console.error(`❌ Error clearing table ${tableName}:`, err);
|
|
8117
|
-
}
|
|
8118
|
-
});
|
|
8119
|
-
}
|
|
8120
7955
|
isEmpty(obj) {
|
|
8121
7956
|
return Object.keys(obj).length === 0;
|
|
8122
7957
|
}
|