@2112-lab/central-plant 0.2.12 → 0.3.0
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/dist/bundle/index.js +2033 -8
- package/dist/cjs/src/core/centralPlant.js +1 -1
- package/dist/cjs/src/index.js +36 -1
- package/dist/cjs/src/managers/cache/CacheManager.js +1078 -0
- package/dist/cjs/src/managers/cache/S3CacheService.js +1442 -0
- package/dist/cjs/src/managers/cache/S3MetadataCacheService.js +502 -0
- package/dist/cjs/src/managers/cache/s3Timing.js +107 -0
- package/dist/esm/src/core/centralPlant.js +1 -1
- package/dist/esm/src/index.js +4 -1
- package/dist/esm/src/managers/cache/CacheManager.js +1070 -0
- package/dist/esm/src/managers/cache/S3CacheService.js +1410 -0
- package/dist/esm/src/managers/cache/S3MetadataCacheService.js +497 -0
- package/dist/esm/src/managers/cache/s3Timing.js +103 -0
- package/dist/index.d.ts +119 -0
- package/package.json +2 -1
package/dist/bundle/index.js
CHANGED
|
@@ -7,6 +7,7 @@ Object.defineProperty(exports, '__esModule', { value: true });
|
|
|
7
7
|
|
|
8
8
|
var THREE = require('three');
|
|
9
9
|
var pathfinder = require('@2112-lab/pathfinder');
|
|
10
|
+
var awsAmplify = require('aws-amplify');
|
|
10
11
|
|
|
11
12
|
function _interopNamespace(e) {
|
|
12
13
|
if (e && e.__esModule) return e;
|
|
@@ -37840,7 +37841,7 @@ var CentralPlant = /*#__PURE__*/function (_BaseDisposable) {
|
|
|
37840
37841
|
* Initialize the CentralPlant manager
|
|
37841
37842
|
*
|
|
37842
37843
|
* @constructor
|
|
37843
|
-
* @version 0.
|
|
37844
|
+
* @version 0.3.0
|
|
37844
37845
|
* @updated 2025-10-22
|
|
37845
37846
|
*
|
|
37846
37847
|
* @description Creates a new CentralPlant instance and initializes internal managers and utilities.
|
|
@@ -42181,10 +42182,6 @@ var CacheManager = /*#__PURE__*/function () {
|
|
|
42181
42182
|
}
|
|
42182
42183
|
return _getCacheHandle;
|
|
42183
42184
|
}()
|
|
42184
|
-
/**
|
|
42185
|
-
* Get the cache name for the current user
|
|
42186
|
-
* Memoized to prevent excessive Auth calls
|
|
42187
|
-
*/
|
|
42188
42185
|
/**
|
|
42189
42186
|
* Resets the identity, forcing a re-fetch of the user/cache name on next access
|
|
42190
42187
|
*/
|
|
@@ -42281,7 +42278,6 @@ var CacheManager = /*#__PURE__*/function () {
|
|
|
42281
42278
|
case 5:
|
|
42282
42279
|
result = _context4.v;
|
|
42283
42280
|
this.stats.hits++;
|
|
42284
|
-
result instanceof Blob ? result.size : 0;
|
|
42285
42281
|
if (result instanceof Blob) this.stats.totalBytesServed += result.size;
|
|
42286
42282
|
return _context4.a(2, result);
|
|
42287
42283
|
case 6:
|
|
@@ -42833,7 +42829,7 @@ var CacheManager = /*#__PURE__*/function () {
|
|
|
42833
42829
|
return get;
|
|
42834
42830
|
}()
|
|
42835
42831
|
/**
|
|
42836
|
-
* Delete a specific key from
|
|
42832
|
+
* Delete a specific key from the cache
|
|
42837
42833
|
*/
|
|
42838
42834
|
)
|
|
42839
42835
|
}, {
|
|
@@ -43066,7 +43062,7 @@ var CacheManager = /*#__PURE__*/function () {
|
|
|
43066
43062
|
return _response.blob();
|
|
43067
43063
|
case 28:
|
|
43068
43064
|
_blob = _context11.v;
|
|
43069
|
-
cachedTime = _response.headers.get('x-cached-time');
|
|
43065
|
+
cachedTime = _response.headers.get('x-cached-time');
|
|
43070
43066
|
sourceKey = _response.headers.get('x-source-key') || _response.headers.get('x-s3-key') || _response.headers.get('x-local-path') || _request.url;
|
|
43071
43067
|
totalSize += _blob.size;
|
|
43072
43068
|
items.push({
|
|
@@ -43123,6 +43119,2003 @@ var CacheManager = /*#__PURE__*/function () {
|
|
|
43123
43119
|
}();
|
|
43124
43120
|
var cacheManager = new CacheManager();
|
|
43125
43121
|
|
|
43122
|
+
// Configure the cache manager with Amplify Auth
|
|
43123
|
+
cacheManager.configure({
|
|
43124
|
+
getUser: function () {
|
|
43125
|
+
var _getUser = _asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee() {
|
|
43126
|
+
return _regenerator().w(function (_context) {
|
|
43127
|
+
while (1) switch (_context.n) {
|
|
43128
|
+
case 0:
|
|
43129
|
+
_context.p = 0;
|
|
43130
|
+
_context.n = 1;
|
|
43131
|
+
return awsAmplify.Auth.currentAuthenticatedUser();
|
|
43132
|
+
case 1:
|
|
43133
|
+
return _context.a(2, _context.v);
|
|
43134
|
+
case 2:
|
|
43135
|
+
_context.p = 2;
|
|
43136
|
+
_context.v;
|
|
43137
|
+
return _context.a(2, null);
|
|
43138
|
+
}
|
|
43139
|
+
}, _callee, null, [[0, 2]]);
|
|
43140
|
+
}));
|
|
43141
|
+
function getUser() {
|
|
43142
|
+
return _getUser.apply(this, arguments);
|
|
43143
|
+
}
|
|
43144
|
+
return getUser;
|
|
43145
|
+
}(),
|
|
43146
|
+
onError: function onError(error) {
|
|
43147
|
+
console.error('S3Cache Error:', error);
|
|
43148
|
+
}
|
|
43149
|
+
});
|
|
43150
|
+
|
|
43151
|
+
/**
|
|
43152
|
+
* Reset the cache manager identity.
|
|
43153
|
+
* Call this when auth state changes to ensure the correct cache partition is used.
|
|
43154
|
+
*/
|
|
43155
|
+
function resetCacheIdentity() {
|
|
43156
|
+
cacheManager.resetIdentity();
|
|
43157
|
+
console.log('🔄 Cache identity reset - will re-evaluate on next cache access');
|
|
43158
|
+
}
|
|
43159
|
+
|
|
43160
|
+
// --- Global Cache for Bundled/Static Access ---
|
|
43161
|
+
var GLOBAL_CACHE_NAME = 'asset-manager-global-v1';
|
|
43162
|
+
function getGlobalCache() {
|
|
43163
|
+
return _getGlobalCache.apply(this, arguments);
|
|
43164
|
+
}
|
|
43165
|
+
function _getGlobalCache() {
|
|
43166
|
+
_getGlobalCache = _asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee2() {
|
|
43167
|
+
return _regenerator().w(function (_context2) {
|
|
43168
|
+
while (1) switch (_context2.n) {
|
|
43169
|
+
case 0:
|
|
43170
|
+
if ('caches' in window) {
|
|
43171
|
+
_context2.n = 1;
|
|
43172
|
+
break;
|
|
43173
|
+
}
|
|
43174
|
+
return _context2.a(2, null);
|
|
43175
|
+
case 1:
|
|
43176
|
+
return _context2.a(2, caches.open(GLOBAL_CACHE_NAME));
|
|
43177
|
+
}
|
|
43178
|
+
}, _callee2);
|
|
43179
|
+
}));
|
|
43180
|
+
return _getGlobalCache.apply(this, arguments);
|
|
43181
|
+
}
|
|
43182
|
+
function executeGlobal(_x) {
|
|
43183
|
+
return _executeGlobal.apply(this, arguments);
|
|
43184
|
+
}
|
|
43185
|
+
/**
|
|
43186
|
+
* Clear the entire global cache (bundled models, thumbnails, etc.).
|
|
43187
|
+
*/
|
|
43188
|
+
function _executeGlobal() {
|
|
43189
|
+
_executeGlobal = _asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee3(_ref) {
|
|
43190
|
+
var cacheKey, fetcher, processor, metadata, cache, cachedResponse, response, responseClone, headers, responseToCache, _response, _t2, _t3, _t4, _t5, _t6, _t7;
|
|
43191
|
+
return _regenerator().w(function (_context3) {
|
|
43192
|
+
while (1) switch (_context3.n) {
|
|
43193
|
+
case 0:
|
|
43194
|
+
cacheKey = _ref.cacheKey, fetcher = _ref.fetcher, processor = _ref.processor, metadata = _ref.metadata;
|
|
43195
|
+
_context3.p = 1;
|
|
43196
|
+
_context3.n = 2;
|
|
43197
|
+
return getGlobalCache();
|
|
43198
|
+
case 2:
|
|
43199
|
+
cache = _context3.v;
|
|
43200
|
+
if (cache) {
|
|
43201
|
+
_context3.n = 5;
|
|
43202
|
+
break;
|
|
43203
|
+
}
|
|
43204
|
+
_t2 = processor;
|
|
43205
|
+
_context3.n = 3;
|
|
43206
|
+
return fetcher();
|
|
43207
|
+
case 3:
|
|
43208
|
+
_t3 = _context3.v;
|
|
43209
|
+
_context3.n = 4;
|
|
43210
|
+
return _t2(_t3);
|
|
43211
|
+
case 4:
|
|
43212
|
+
return _context3.a(2, _context3.v);
|
|
43213
|
+
case 5:
|
|
43214
|
+
_context3.n = 6;
|
|
43215
|
+
return cache.match(cacheKey);
|
|
43216
|
+
case 6:
|
|
43217
|
+
cachedResponse = _context3.v;
|
|
43218
|
+
if (!cachedResponse) {
|
|
43219
|
+
_context3.n = 8;
|
|
43220
|
+
break;
|
|
43221
|
+
}
|
|
43222
|
+
_context3.n = 7;
|
|
43223
|
+
return processor(cachedResponse);
|
|
43224
|
+
case 7:
|
|
43225
|
+
return _context3.a(2, _context3.v);
|
|
43226
|
+
case 8:
|
|
43227
|
+
_context3.n = 9;
|
|
43228
|
+
return fetcher();
|
|
43229
|
+
case 9:
|
|
43230
|
+
response = _context3.v;
|
|
43231
|
+
// Clone for cache
|
|
43232
|
+
responseClone = response.clone(); // Store with metadata headers if possible
|
|
43233
|
+
headers = new Headers(responseClone.headers);
|
|
43234
|
+
headers.append('X-Cached-Time', Date.now().toString());
|
|
43235
|
+
if (metadata) {
|
|
43236
|
+
headers.append('X-Cache-Metadata', JSON.stringify(metadata));
|
|
43237
|
+
}
|
|
43238
|
+
|
|
43239
|
+
// We need to create a new Response with updated headers to store it
|
|
43240
|
+
_t4 = Response;
|
|
43241
|
+
_context3.n = 10;
|
|
43242
|
+
return responseClone.blob();
|
|
43243
|
+
case 10:
|
|
43244
|
+
_t5 = _context3.v;
|
|
43245
|
+
_t6 = {
|
|
43246
|
+
status: responseClone.status,
|
|
43247
|
+
statusText: responseClone.statusText,
|
|
43248
|
+
headers: headers
|
|
43249
|
+
};
|
|
43250
|
+
responseToCache = new _t4(_t5, _t6);
|
|
43251
|
+
_context3.n = 11;
|
|
43252
|
+
return cache.put(cacheKey, responseToCache);
|
|
43253
|
+
case 11:
|
|
43254
|
+
_context3.n = 12;
|
|
43255
|
+
return processor(response);
|
|
43256
|
+
case 12:
|
|
43257
|
+
return _context3.a(2, _context3.v);
|
|
43258
|
+
case 13:
|
|
43259
|
+
_context3.p = 13;
|
|
43260
|
+
_t7 = _context3.v;
|
|
43261
|
+
console.warn('Global Cache execution failed, falling back to network', _t7);
|
|
43262
|
+
_context3.n = 14;
|
|
43263
|
+
return fetcher();
|
|
43264
|
+
case 14:
|
|
43265
|
+
_response = _context3.v;
|
|
43266
|
+
_context3.n = 15;
|
|
43267
|
+
return processor(_response);
|
|
43268
|
+
case 15:
|
|
43269
|
+
return _context3.a(2, _context3.v);
|
|
43270
|
+
}
|
|
43271
|
+
}, _callee3, null, [[1, 13]]);
|
|
43272
|
+
}));
|
|
43273
|
+
return _executeGlobal.apply(this, arguments);
|
|
43274
|
+
}
|
|
43275
|
+
function clearGlobalCache() {
|
|
43276
|
+
return _clearGlobalCache.apply(this, arguments);
|
|
43277
|
+
}
|
|
43278
|
+
/**
|
|
43279
|
+
* Remove expired entries from the global cache.
|
|
43280
|
+
* Returns the number of entries removed.
|
|
43281
|
+
*/
|
|
43282
|
+
function _clearGlobalCache() {
|
|
43283
|
+
_clearGlobalCache = _asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee4() {
|
|
43284
|
+
var deleted, _t8;
|
|
43285
|
+
return _regenerator().w(function (_context4) {
|
|
43286
|
+
while (1) switch (_context4.n) {
|
|
43287
|
+
case 0:
|
|
43288
|
+
_context4.p = 0;
|
|
43289
|
+
if ('caches' in window) {
|
|
43290
|
+
_context4.n = 1;
|
|
43291
|
+
break;
|
|
43292
|
+
}
|
|
43293
|
+
return _context4.a(2, false);
|
|
43294
|
+
case 1:
|
|
43295
|
+
_context4.n = 2;
|
|
43296
|
+
return caches.delete(GLOBAL_CACHE_NAME);
|
|
43297
|
+
case 2:
|
|
43298
|
+
deleted = _context4.v;
|
|
43299
|
+
if (deleted) console.log('🗑️ Global cache cleared');
|
|
43300
|
+
return _context4.a(2, deleted);
|
|
43301
|
+
case 3:
|
|
43302
|
+
_context4.p = 3;
|
|
43303
|
+
_t8 = _context4.v;
|
|
43304
|
+
console.warn('Failed to clear global cache:', _t8);
|
|
43305
|
+
return _context4.a(2, false);
|
|
43306
|
+
}
|
|
43307
|
+
}, _callee4, null, [[0, 3]]);
|
|
43308
|
+
}));
|
|
43309
|
+
return _clearGlobalCache.apply(this, arguments);
|
|
43310
|
+
}
|
|
43311
|
+
function cleanExpiredGlobalCache() {
|
|
43312
|
+
return _cleanExpiredGlobalCache.apply(this, arguments);
|
|
43313
|
+
}
|
|
43314
|
+
function _cleanExpiredGlobalCache() {
|
|
43315
|
+
_cleanExpiredGlobalCache = _asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee6() {
|
|
43316
|
+
var cache, keys, cleaned;
|
|
43317
|
+
return _regenerator().w(function (_context6) {
|
|
43318
|
+
while (1) switch (_context6.n) {
|
|
43319
|
+
case 0:
|
|
43320
|
+
_context6.n = 1;
|
|
43321
|
+
return getGlobalCache();
|
|
43322
|
+
case 1:
|
|
43323
|
+
cache = _context6.v;
|
|
43324
|
+
if (cache) {
|
|
43325
|
+
_context6.n = 2;
|
|
43326
|
+
break;
|
|
43327
|
+
}
|
|
43328
|
+
return _context6.a(2, 0);
|
|
43329
|
+
case 2:
|
|
43330
|
+
_context6.n = 3;
|
|
43331
|
+
return cache.keys();
|
|
43332
|
+
case 3:
|
|
43333
|
+
keys = _context6.v;
|
|
43334
|
+
cleaned = 0;
|
|
43335
|
+
_context6.n = 4;
|
|
43336
|
+
return Promise.all(keys.map(/*#__PURE__*/function () {
|
|
43337
|
+
var _ref2 = _asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee5(request) {
|
|
43338
|
+
var response, cachedTime, age, s3Key, expiryMs, _t9;
|
|
43339
|
+
return _regenerator().w(function (_context5) {
|
|
43340
|
+
while (1) switch (_context5.n) {
|
|
43341
|
+
case 0:
|
|
43342
|
+
_context5.p = 0;
|
|
43343
|
+
_context5.n = 1;
|
|
43344
|
+
return cache.match(request);
|
|
43345
|
+
case 1:
|
|
43346
|
+
response = _context5.v;
|
|
43347
|
+
if (response) {
|
|
43348
|
+
_context5.n = 2;
|
|
43349
|
+
break;
|
|
43350
|
+
}
|
|
43351
|
+
return _context5.a(2);
|
|
43352
|
+
case 2:
|
|
43353
|
+
cachedTime = parseInt(response.headers.get('X-Cached-Time') || '0');
|
|
43354
|
+
age = Date.now() - cachedTime;
|
|
43355
|
+
s3Key = request.url.replace('https://local.cache', '');
|
|
43356
|
+
expiryMs = cacheManager.getExpiryForPath(s3Key);
|
|
43357
|
+
if (!(age > expiryMs)) {
|
|
43358
|
+
_context5.n = 4;
|
|
43359
|
+
break;
|
|
43360
|
+
}
|
|
43361
|
+
_context5.n = 3;
|
|
43362
|
+
return cache.delete(request);
|
|
43363
|
+
case 3:
|
|
43364
|
+
cleaned++;
|
|
43365
|
+
case 4:
|
|
43366
|
+
_context5.n = 6;
|
|
43367
|
+
break;
|
|
43368
|
+
case 5:
|
|
43369
|
+
_context5.p = 5;
|
|
43370
|
+
_t9 = _context5.v;
|
|
43371
|
+
console.warn('Failed to check global cache entry:', _t9);
|
|
43372
|
+
case 6:
|
|
43373
|
+
return _context5.a(2);
|
|
43374
|
+
}
|
|
43375
|
+
}, _callee5, null, [[0, 5]]);
|
|
43376
|
+
}));
|
|
43377
|
+
return function (_x16) {
|
|
43378
|
+
return _ref2.apply(this, arguments);
|
|
43379
|
+
};
|
|
43380
|
+
}()));
|
|
43381
|
+
case 4:
|
|
43382
|
+
if (cleaned > 0) console.log("\uD83E\uDDF9 Cleaned ".concat(cleaned, " expired global cache entries"));
|
|
43383
|
+
return _context6.a(2, cleaned);
|
|
43384
|
+
}
|
|
43385
|
+
}, _callee6);
|
|
43386
|
+
}));
|
|
43387
|
+
return _cleanExpiredGlobalCache.apply(this, arguments);
|
|
43388
|
+
}
|
|
43389
|
+
function getGlobalCacheStatsDetail() {
|
|
43390
|
+
return _getGlobalCacheStatsDetail.apply(this, arguments);
|
|
43391
|
+
} // --- Exports delegating to CacheManager ---
|
|
43392
|
+
function _getGlobalCacheStatsDetail() {
|
|
43393
|
+
_getGlobalCacheStatsDetail = _asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee8() {
|
|
43394
|
+
var cache, keys, items, totalSize;
|
|
43395
|
+
return _regenerator().w(function (_context8) {
|
|
43396
|
+
while (1) switch (_context8.n) {
|
|
43397
|
+
case 0:
|
|
43398
|
+
_context8.n = 1;
|
|
43399
|
+
return getGlobalCache();
|
|
43400
|
+
case 1:
|
|
43401
|
+
cache = _context8.v;
|
|
43402
|
+
if (cache) {
|
|
43403
|
+
_context8.n = 2;
|
|
43404
|
+
break;
|
|
43405
|
+
}
|
|
43406
|
+
return _context8.a(2, {
|
|
43407
|
+
count: 0,
|
|
43408
|
+
totalSize: 0,
|
|
43409
|
+
totalSizeMB: '0.00',
|
|
43410
|
+
items: []
|
|
43411
|
+
});
|
|
43412
|
+
case 2:
|
|
43413
|
+
_context8.n = 3;
|
|
43414
|
+
return cache.keys();
|
|
43415
|
+
case 3:
|
|
43416
|
+
keys = _context8.v;
|
|
43417
|
+
items = [];
|
|
43418
|
+
totalSize = 0;
|
|
43419
|
+
_context8.n = 4;
|
|
43420
|
+
return Promise.all(keys.map(/*#__PURE__*/function () {
|
|
43421
|
+
var _ref3 = _asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee7(request) {
|
|
43422
|
+
var response, cachedTime, metadataHeader, metadata, size, cl;
|
|
43423
|
+
return _regenerator().w(function (_context7) {
|
|
43424
|
+
while (1) switch (_context7.n) {
|
|
43425
|
+
case 0:
|
|
43426
|
+
_context7.n = 1;
|
|
43427
|
+
return cache.match(request);
|
|
43428
|
+
case 1:
|
|
43429
|
+
response = _context7.v;
|
|
43430
|
+
if (response) {
|
|
43431
|
+
_context7.n = 2;
|
|
43432
|
+
break;
|
|
43433
|
+
}
|
|
43434
|
+
return _context7.a(2);
|
|
43435
|
+
case 2:
|
|
43436
|
+
cachedTime = parseInt(response.headers.get('X-Cached-Time') || '0');
|
|
43437
|
+
metadataHeader = response.headers.get('X-Cache-Metadata');
|
|
43438
|
+
metadata = metadataHeader ? JSON.parse(metadataHeader) : {};
|
|
43439
|
+
size = 0;
|
|
43440
|
+
cl = response.headers.get('Content-Length');
|
|
43441
|
+
if (cl) size = parseInt(cl);
|
|
43442
|
+
totalSize += size;
|
|
43443
|
+
items.push(_objectSpread2({
|
|
43444
|
+
url: request.url,
|
|
43445
|
+
s3Key: request.url.replace('https://local.cache', ''),
|
|
43446
|
+
size: size,
|
|
43447
|
+
sizeMB: (size / (1024 * 1024)).toFixed(2),
|
|
43448
|
+
cachedTime: cachedTime,
|
|
43449
|
+
age: Date.now() - cachedTime,
|
|
43450
|
+
isLocal: true,
|
|
43451
|
+
type: response.headers.get('Content-Type') || 'application/octet-stream'
|
|
43452
|
+
}, metadata));
|
|
43453
|
+
case 3:
|
|
43454
|
+
return _context7.a(2);
|
|
43455
|
+
}
|
|
43456
|
+
}, _callee7);
|
|
43457
|
+
}));
|
|
43458
|
+
return function (_x17) {
|
|
43459
|
+
return _ref3.apply(this, arguments);
|
|
43460
|
+
};
|
|
43461
|
+
}()));
|
|
43462
|
+
case 4:
|
|
43463
|
+
return _context8.a(2, {
|
|
43464
|
+
count: items.length,
|
|
43465
|
+
totalSize: totalSize,
|
|
43466
|
+
totalSizeMB: (totalSize / (1024 * 1024)).toFixed(2),
|
|
43467
|
+
items: items
|
|
43468
|
+
});
|
|
43469
|
+
}
|
|
43470
|
+
}, _callee8);
|
|
43471
|
+
}));
|
|
43472
|
+
return _getGlobalCacheStatsDetail.apply(this, arguments);
|
|
43473
|
+
}
|
|
43474
|
+
function getGlobalCacheStats() {
|
|
43475
|
+
return cacheManager.getGlobalStats();
|
|
43476
|
+
}
|
|
43477
|
+
function resetGlobalCacheStats() {
|
|
43478
|
+
cacheManager.resetStats();
|
|
43479
|
+
}
|
|
43480
|
+
function getCurrentCacheName() {
|
|
43481
|
+
return _getCurrentCacheName.apply(this, arguments);
|
|
43482
|
+
}
|
|
43483
|
+
function _getCurrentCacheName() {
|
|
43484
|
+
_getCurrentCacheName = _asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee9() {
|
|
43485
|
+
return _regenerator().w(function (_context9) {
|
|
43486
|
+
while (1) switch (_context9.n) {
|
|
43487
|
+
case 0:
|
|
43488
|
+
return _context9.a(2, cacheManager.getCacheName());
|
|
43489
|
+
}
|
|
43490
|
+
}, _callee9);
|
|
43491
|
+
}));
|
|
43492
|
+
return _getCurrentCacheName.apply(this, arguments);
|
|
43493
|
+
}
|
|
43494
|
+
function cleanExpiredCache() {
|
|
43495
|
+
return _cleanExpiredCache.apply(this, arguments);
|
|
43496
|
+
}
|
|
43497
|
+
function _cleanExpiredCache() {
|
|
43498
|
+
_cleanExpiredCache = _asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee0() {
|
|
43499
|
+
var userCount, globalCount, count;
|
|
43500
|
+
return _regenerator().w(function (_context0) {
|
|
43501
|
+
while (1) switch (_context0.n) {
|
|
43502
|
+
case 0:
|
|
43503
|
+
_context0.n = 1;
|
|
43504
|
+
return cacheManager.cleanExpired();
|
|
43505
|
+
case 1:
|
|
43506
|
+
userCount = _context0.v;
|
|
43507
|
+
_context0.n = 2;
|
|
43508
|
+
return cleanExpiredGlobalCache();
|
|
43509
|
+
case 2:
|
|
43510
|
+
globalCount = _context0.v;
|
|
43511
|
+
count = userCount + globalCount;
|
|
43512
|
+
if (count > 0) console.log("\uD83E\uDDF9 Cleaned ".concat(count, " expired cache entries (user: ").concat(userCount, ", global: ").concat(globalCount, ")"));
|
|
43513
|
+
return _context0.a(2, count);
|
|
43514
|
+
}
|
|
43515
|
+
}, _callee0);
|
|
43516
|
+
}));
|
|
43517
|
+
return _cleanExpiredCache.apply(this, arguments);
|
|
43518
|
+
}
|
|
43519
|
+
function cleanInvalidCacheEntries() {
|
|
43520
|
+
return _cleanInvalidCacheEntries.apply(this, arguments);
|
|
43521
|
+
}
|
|
43522
|
+
function _cleanInvalidCacheEntries() {
|
|
43523
|
+
_cleanInvalidCacheEntries = _asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee1() {
|
|
43524
|
+
var count;
|
|
43525
|
+
return _regenerator().w(function (_context1) {
|
|
43526
|
+
while (1) switch (_context1.n) {
|
|
43527
|
+
case 0:
|
|
43528
|
+
_context1.n = 1;
|
|
43529
|
+
return cacheManager.cleanInvalid();
|
|
43530
|
+
case 1:
|
|
43531
|
+
count = _context1.v;
|
|
43532
|
+
if (count > 0) console.log("\uD83E\uDDF9 Cleaned ".concat(count, " invalid cache entries"));
|
|
43533
|
+
return _context1.a(2, count);
|
|
43534
|
+
}
|
|
43535
|
+
}, _callee1);
|
|
43536
|
+
}));
|
|
43537
|
+
return _cleanInvalidCacheEntries.apply(this, arguments);
|
|
43538
|
+
}
|
|
43539
|
+
function getCacheStats() {
|
|
43540
|
+
return _getCacheStats.apply(this, arguments);
|
|
43541
|
+
}
|
|
43542
|
+
function _getCacheStats() {
|
|
43543
|
+
_getCacheStats = _asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee10() {
|
|
43544
|
+
var allUsers,
|
|
43545
|
+
userStats,
|
|
43546
|
+
globalStats,
|
|
43547
|
+
userItems,
|
|
43548
|
+
_args10 = arguments;
|
|
43549
|
+
return _regenerator().w(function (_context10) {
|
|
43550
|
+
while (1) switch (_context10.n) {
|
|
43551
|
+
case 0:
|
|
43552
|
+
allUsers = _args10.length > 0 && _args10[0] !== undefined ? _args10[0] : false;
|
|
43553
|
+
_context10.n = 1;
|
|
43554
|
+
return cacheManager.getDetailedStats(allUsers);
|
|
43555
|
+
case 1:
|
|
43556
|
+
userStats = _context10.v;
|
|
43557
|
+
_context10.n = 2;
|
|
43558
|
+
return getGlobalCacheStatsDetail();
|
|
43559
|
+
case 2:
|
|
43560
|
+
globalStats = _context10.v;
|
|
43561
|
+
// Ensure user stats items have isLocal: false
|
|
43562
|
+
userItems = userStats.items.map(function (item) {
|
|
43563
|
+
return _objectSpread2(_objectSpread2({}, item), {}, {
|
|
43564
|
+
isLocal: false
|
|
43565
|
+
});
|
|
43566
|
+
}); // Merge stats
|
|
43567
|
+
return _context10.a(2, {
|
|
43568
|
+
count: userStats.count + globalStats.count,
|
|
43569
|
+
totalSize: userStats.totalSize + globalStats.totalSize,
|
|
43570
|
+
totalSizeMB: (parseFloat(userStats.totalSizeMB) + parseFloat(globalStats.totalSizeMB)).toFixed(2),
|
|
43571
|
+
items: [].concat(_toConsumableArray(userItems), _toConsumableArray(globalStats.items))
|
|
43572
|
+
});
|
|
43573
|
+
}
|
|
43574
|
+
}, _callee10);
|
|
43575
|
+
}));
|
|
43576
|
+
return _getCacheStats.apply(this, arguments);
|
|
43577
|
+
}
|
|
43578
|
+
function getUserOnlyCacheStats() {
|
|
43579
|
+
return _getUserOnlyCacheStats.apply(this, arguments);
|
|
43580
|
+
}
|
|
43581
|
+
function _getUserOnlyCacheStats() {
|
|
43582
|
+
_getUserOnlyCacheStats = _asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee11() {
|
|
43583
|
+
var allUsers,
|
|
43584
|
+
stats,
|
|
43585
|
+
_args11 = arguments;
|
|
43586
|
+
return _regenerator().w(function (_context11) {
|
|
43587
|
+
while (1) switch (_context11.n) {
|
|
43588
|
+
case 0:
|
|
43589
|
+
allUsers = _args11.length > 0 && _args11[0] !== undefined ? _args11[0] : false;
|
|
43590
|
+
_context11.n = 1;
|
|
43591
|
+
return cacheManager.getDetailedStats(allUsers);
|
|
43592
|
+
case 1:
|
|
43593
|
+
stats = _context11.v;
|
|
43594
|
+
// Ensure items have isLocal: false
|
|
43595
|
+
stats.items = stats.items.map(function (item) {
|
|
43596
|
+
return _objectSpread2(_objectSpread2({}, item), {}, {
|
|
43597
|
+
isLocal: false
|
|
43598
|
+
});
|
|
43599
|
+
});
|
|
43600
|
+
return _context11.a(2, stats);
|
|
43601
|
+
}
|
|
43602
|
+
}, _callee11);
|
|
43603
|
+
}));
|
|
43604
|
+
return _getUserOnlyCacheStats.apply(this, arguments);
|
|
43605
|
+
}
|
|
43606
|
+
function getGlobalOnlyCacheStats() {
|
|
43607
|
+
return _getGlobalOnlyCacheStats.apply(this, arguments);
|
|
43608
|
+
}
|
|
43609
|
+
function _getGlobalOnlyCacheStats() {
|
|
43610
|
+
_getGlobalOnlyCacheStats = _asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee12() {
|
|
43611
|
+
return _regenerator().w(function (_context12) {
|
|
43612
|
+
while (1) switch (_context12.n) {
|
|
43613
|
+
case 0:
|
|
43614
|
+
_context12.n = 1;
|
|
43615
|
+
return getGlobalCacheStatsDetail();
|
|
43616
|
+
case 1:
|
|
43617
|
+
return _context12.a(2, _context12.v);
|
|
43618
|
+
}
|
|
43619
|
+
}, _callee12);
|
|
43620
|
+
}));
|
|
43621
|
+
return _getGlobalOnlyCacheStats.apply(this, arguments);
|
|
43622
|
+
}
|
|
43623
|
+
function clearS3Cache() {
|
|
43624
|
+
return _clearS3Cache.apply(this, arguments);
|
|
43625
|
+
}
|
|
43626
|
+
function _clearS3Cache() {
|
|
43627
|
+
_clearS3Cache = _asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee13() {
|
|
43628
|
+
var specificKey,
|
|
43629
|
+
clearAllUsers,
|
|
43630
|
+
result,
|
|
43631
|
+
_args13 = arguments;
|
|
43632
|
+
return _regenerator().w(function (_context13) {
|
|
43633
|
+
while (1) switch (_context13.n) {
|
|
43634
|
+
case 0:
|
|
43635
|
+
specificKey = _args13.length > 0 && _args13[0] !== undefined ? _args13[0] : null;
|
|
43636
|
+
clearAllUsers = _args13.length > 1 && _args13[1] !== undefined ? _args13[1] : false;
|
|
43637
|
+
_context13.n = 1;
|
|
43638
|
+
return cacheManager.clearCache(specificKey, clearAllUsers);
|
|
43639
|
+
case 1:
|
|
43640
|
+
result = _context13.v;
|
|
43641
|
+
if (specificKey) {
|
|
43642
|
+
_context13.n = 2;
|
|
43643
|
+
break;
|
|
43644
|
+
}
|
|
43645
|
+
_context13.n = 2;
|
|
43646
|
+
return clearGlobalCache();
|
|
43647
|
+
case 2:
|
|
43648
|
+
if (result) console.log(specificKey ? "\uD83D\uDDD1\uFE0F Cleared cache for ".concat(specificKey) : "\uD83D\uDDD1\uFE0F Cache cleared (user + global)");
|
|
43649
|
+
return _context13.a(2, result);
|
|
43650
|
+
}
|
|
43651
|
+
}, _callee13);
|
|
43652
|
+
}));
|
|
43653
|
+
return _clearS3Cache.apply(this, arguments);
|
|
43654
|
+
}
|
|
43655
|
+
function getAllCacheKeys() {
|
|
43656
|
+
return _getAllCacheKeys.apply(this, arguments);
|
|
43657
|
+
}
|
|
43658
|
+
function _getAllCacheKeys() {
|
|
43659
|
+
_getAllCacheKeys = _asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee14() {
|
|
43660
|
+
var allKeys, addKey, globalCache, keys, allCacheNames, appCaches, _iterator, _step, cacheName, cache, _keys, _t0;
|
|
43661
|
+
return _regenerator().w(function (_context14) {
|
|
43662
|
+
while (1) switch (_context14.n) {
|
|
43663
|
+
case 0:
|
|
43664
|
+
allKeys = new Set(); // Helper to add both raw and decoded versions for robust matching
|
|
43665
|
+
addKey = function addKey(url) {
|
|
43666
|
+
allKeys.add(url);
|
|
43667
|
+
try {
|
|
43668
|
+
var decoded = decodeURI(url);
|
|
43669
|
+
if (decoded !== url) allKeys.add(decoded);
|
|
43670
|
+
} catch (e) {
|
|
43671
|
+
// Ignore encoding errors
|
|
43672
|
+
}
|
|
43673
|
+
}; // 1. Get Global Cache Keys (Custom Global Cache)
|
|
43674
|
+
_context14.n = 1;
|
|
43675
|
+
return getGlobalCache();
|
|
43676
|
+
case 1:
|
|
43677
|
+
globalCache = _context14.v;
|
|
43678
|
+
if (!globalCache) {
|
|
43679
|
+
_context14.n = 3;
|
|
43680
|
+
break;
|
|
43681
|
+
}
|
|
43682
|
+
_context14.n = 2;
|
|
43683
|
+
return globalCache.keys();
|
|
43684
|
+
case 2:
|
|
43685
|
+
keys = _context14.v;
|
|
43686
|
+
keys.forEach(function (request) {
|
|
43687
|
+
return addKey(request.url);
|
|
43688
|
+
});
|
|
43689
|
+
case 3:
|
|
43690
|
+
if (!('caches' in window)) {
|
|
43691
|
+
_context14.n = 13;
|
|
43692
|
+
break;
|
|
43693
|
+
}
|
|
43694
|
+
_context14.n = 4;
|
|
43695
|
+
return caches.keys();
|
|
43696
|
+
case 4:
|
|
43697
|
+
allCacheNames = _context14.v;
|
|
43698
|
+
appCaches = allCacheNames.filter(function (name) {
|
|
43699
|
+
return name.startsWith(CACHE_NAME_PREFIX);
|
|
43700
|
+
});
|
|
43701
|
+
_iterator = _createForOfIteratorHelper(appCaches);
|
|
43702
|
+
_context14.p = 5;
|
|
43703
|
+
_iterator.s();
|
|
43704
|
+
case 6:
|
|
43705
|
+
if ((_step = _iterator.n()).done) {
|
|
43706
|
+
_context14.n = 10;
|
|
43707
|
+
break;
|
|
43708
|
+
}
|
|
43709
|
+
cacheName = _step.value;
|
|
43710
|
+
_context14.n = 7;
|
|
43711
|
+
return caches.open(cacheName);
|
|
43712
|
+
case 7:
|
|
43713
|
+
cache = _context14.v;
|
|
43714
|
+
if (!cache) {
|
|
43715
|
+
_context14.n = 9;
|
|
43716
|
+
break;
|
|
43717
|
+
}
|
|
43718
|
+
_context14.n = 8;
|
|
43719
|
+
return cache.keys();
|
|
43720
|
+
case 8:
|
|
43721
|
+
_keys = _context14.v;
|
|
43722
|
+
_keys.forEach(function (request) {
|
|
43723
|
+
return addKey(request.url);
|
|
43724
|
+
});
|
|
43725
|
+
case 9:
|
|
43726
|
+
_context14.n = 6;
|
|
43727
|
+
break;
|
|
43728
|
+
case 10:
|
|
43729
|
+
_context14.n = 12;
|
|
43730
|
+
break;
|
|
43731
|
+
case 11:
|
|
43732
|
+
_context14.p = 11;
|
|
43733
|
+
_t0 = _context14.v;
|
|
43734
|
+
_iterator.e(_t0);
|
|
43735
|
+
case 12:
|
|
43736
|
+
_context14.p = 12;
|
|
43737
|
+
_iterator.f();
|
|
43738
|
+
return _context14.f(12);
|
|
43739
|
+
case 13:
|
|
43740
|
+
return _context14.a(2, allKeys);
|
|
43741
|
+
}
|
|
43742
|
+
}, _callee14, null, [[5, 11, 12, 13]]);
|
|
43743
|
+
}));
|
|
43744
|
+
return _getAllCacheKeys.apply(this, arguments);
|
|
43745
|
+
}
|
|
43746
|
+
function switchCachePartition(_x2) {
|
|
43747
|
+
return _switchCachePartition.apply(this, arguments);
|
|
43748
|
+
}
|
|
43749
|
+
|
|
43750
|
+
// --- Data Fetchers ---
|
|
43751
|
+
|
|
43752
|
+
/**
|
|
43753
|
+
* Check all app cache partitions for a cached response.
|
|
43754
|
+
* This handles the race condition where auth may not be hydrated yet on page refresh.
|
|
43755
|
+
* @param {string} cacheKey - The cache key to look for
|
|
43756
|
+
* @returns {Promise<Response|null>} - Cached response or null if not found
|
|
43757
|
+
*/
|
|
43758
|
+
function _switchCachePartition() {
|
|
43759
|
+
_switchCachePartition = _asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee15(isAuthenticated) {
|
|
43760
|
+
var oldCacheName, partitionToDelete, deleted, newCacheName, _t1, _t10;
|
|
43761
|
+
return _regenerator().w(function (_context15) {
|
|
43762
|
+
while (1) switch (_context15.n) {
|
|
43763
|
+
case 0:
|
|
43764
|
+
_context15.p = 0;
|
|
43765
|
+
console.log("\uD83D\uDD04 Switching cache partition (authenticated: ".concat(isAuthenticated, ")..."));
|
|
43766
|
+
_context15.n = 1;
|
|
43767
|
+
return cacheManager.getCacheName();
|
|
43768
|
+
case 1:
|
|
43769
|
+
oldCacheName = _context15.v;
|
|
43770
|
+
// Reset identity to force re-evaluation of cache name
|
|
43771
|
+
cacheManager.resetIdentity();
|
|
43772
|
+
partitionToDelete = null;
|
|
43773
|
+
if (isAuthenticated) {
|
|
43774
|
+
// User logged in - delete anonymous cache
|
|
43775
|
+
partitionToDelete = "".concat(CACHE_NAME_PREFIX, "-anonymous");
|
|
43776
|
+
} else {
|
|
43777
|
+
// User logged out - delete their user-specific cache
|
|
43778
|
+
partitionToDelete = oldCacheName;
|
|
43779
|
+
}
|
|
43780
|
+
if (!partitionToDelete) {
|
|
43781
|
+
_context15.n = 3;
|
|
43782
|
+
break;
|
|
43783
|
+
}
|
|
43784
|
+
_context15.n = 2;
|
|
43785
|
+
return cacheManager.deleteCache(partitionToDelete);
|
|
43786
|
+
case 2:
|
|
43787
|
+
_t1 = _context15.v;
|
|
43788
|
+
_context15.n = 4;
|
|
43789
|
+
break;
|
|
43790
|
+
case 3:
|
|
43791
|
+
_t1 = false;
|
|
43792
|
+
case 4:
|
|
43793
|
+
deleted = _t1;
|
|
43794
|
+
_context15.n = 5;
|
|
43795
|
+
return cacheManager.getCacheName();
|
|
43796
|
+
case 5:
|
|
43797
|
+
newCacheName = _context15.v;
|
|
43798
|
+
console.log("\u2705 Cache partition switched:", {
|
|
43799
|
+
from: oldCacheName,
|
|
43800
|
+
to: newCacheName,
|
|
43801
|
+
deleted: partitionToDelete
|
|
43802
|
+
});
|
|
43803
|
+
return _context15.a(2, {
|
|
43804
|
+
oldCacheName: oldCacheName,
|
|
43805
|
+
newCacheName: newCacheName,
|
|
43806
|
+
deletedPartition: partitionToDelete,
|
|
43807
|
+
deleted: deleted
|
|
43808
|
+
});
|
|
43809
|
+
case 6:
|
|
43810
|
+
_context15.p = 6;
|
|
43811
|
+
_t10 = _context15.v;
|
|
43812
|
+
console.error('Failed to switch cache partition:', _t10);
|
|
43813
|
+
return _context15.a(2, {
|
|
43814
|
+
error: _t10.message
|
|
43815
|
+
});
|
|
43816
|
+
}
|
|
43817
|
+
}, _callee15, null, [[0, 6]]);
|
|
43818
|
+
}));
|
|
43819
|
+
return _switchCachePartition.apply(this, arguments);
|
|
43820
|
+
}
|
|
43821
|
+
function findInAllCachePartitions(_x3) {
|
|
43822
|
+
return _findInAllCachePartitions.apply(this, arguments);
|
|
43823
|
+
}
|
|
43824
|
+
function _findInAllCachePartitions() {
|
|
43825
|
+
_findInAllCachePartitions = _asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee16(cacheKey) {
|
|
43826
|
+
var allCacheNames, appCaches, encodedCacheKey, _iterator2, _step2, cacheName, cache, response, _t11;
|
|
43827
|
+
return _regenerator().w(function (_context16) {
|
|
43828
|
+
while (1) switch (_context16.n) {
|
|
43829
|
+
case 0:
|
|
43830
|
+
if ('caches' in window) {
|
|
43831
|
+
_context16.n = 1;
|
|
43832
|
+
break;
|
|
43833
|
+
}
|
|
43834
|
+
return _context16.a(2, null);
|
|
43835
|
+
case 1:
|
|
43836
|
+
_context16.n = 2;
|
|
43837
|
+
return caches.keys();
|
|
43838
|
+
case 2:
|
|
43839
|
+
allCacheNames = _context16.v;
|
|
43840
|
+
appCaches = allCacheNames.filter(function (name) {
|
|
43841
|
+
return name.startsWith(CACHE_NAME_PREFIX);
|
|
43842
|
+
}); // Also try URL-encoded version of the key in case spaces/special chars were encoded
|
|
43843
|
+
encodedCacheKey = encodeURI(cacheKey);
|
|
43844
|
+
_iterator2 = _createForOfIteratorHelper(appCaches);
|
|
43845
|
+
_context16.p = 3;
|
|
43846
|
+
_iterator2.s();
|
|
43847
|
+
case 4:
|
|
43848
|
+
if ((_step2 = _iterator2.n()).done) {
|
|
43849
|
+
_context16.n = 10;
|
|
43850
|
+
break;
|
|
43851
|
+
}
|
|
43852
|
+
cacheName = _step2.value;
|
|
43853
|
+
_context16.n = 5;
|
|
43854
|
+
return caches.open(cacheName);
|
|
43855
|
+
case 5:
|
|
43856
|
+
cache = _context16.v;
|
|
43857
|
+
_context16.n = 6;
|
|
43858
|
+
return cache.match(cacheKey);
|
|
43859
|
+
case 6:
|
|
43860
|
+
response = _context16.v;
|
|
43861
|
+
if (!response) {
|
|
43862
|
+
_context16.n = 7;
|
|
43863
|
+
break;
|
|
43864
|
+
}
|
|
43865
|
+
console.log("\u2705 [findInAllCachePartitions] Found in ".concat(cacheName, " (exact match): ").concat(cacheKey.substring(0, 80), "..."));
|
|
43866
|
+
return _context16.a(2, response);
|
|
43867
|
+
case 7:
|
|
43868
|
+
if (!(encodedCacheKey !== cacheKey)) {
|
|
43869
|
+
_context16.n = 9;
|
|
43870
|
+
break;
|
|
43871
|
+
}
|
|
43872
|
+
_context16.n = 8;
|
|
43873
|
+
return cache.match(encodedCacheKey);
|
|
43874
|
+
case 8:
|
|
43875
|
+
response = _context16.v;
|
|
43876
|
+
if (!response) {
|
|
43877
|
+
_context16.n = 9;
|
|
43878
|
+
break;
|
|
43879
|
+
}
|
|
43880
|
+
console.log("\u2705 [findInAllCachePartitions] Found in ".concat(cacheName, " (encoded match): ").concat(encodedCacheKey.substring(0, 80), "..."));
|
|
43881
|
+
return _context16.a(2, response);
|
|
43882
|
+
case 9:
|
|
43883
|
+
_context16.n = 4;
|
|
43884
|
+
break;
|
|
43885
|
+
case 10:
|
|
43886
|
+
_context16.n = 12;
|
|
43887
|
+
break;
|
|
43888
|
+
case 11:
|
|
43889
|
+
_context16.p = 11;
|
|
43890
|
+
_t11 = _context16.v;
|
|
43891
|
+
_iterator2.e(_t11);
|
|
43892
|
+
case 12:
|
|
43893
|
+
_context16.p = 12;
|
|
43894
|
+
_iterator2.f();
|
|
43895
|
+
return _context16.f(12);
|
|
43896
|
+
case 13:
|
|
43897
|
+
return _context16.a(2, null);
|
|
43898
|
+
}
|
|
43899
|
+
}, _callee16, null, [[3, 11, 12, 13]]);
|
|
43900
|
+
}));
|
|
43901
|
+
return _findInAllCachePartitions.apply(this, arguments);
|
|
43902
|
+
}
|
|
43903
|
+
function getCachedS3Object(_x4) {
|
|
43904
|
+
return _getCachedS3Object.apply(this, arguments);
|
|
43905
|
+
}
|
|
43906
|
+
function _getCachedS3Object() {
|
|
43907
|
+
_getCachedS3Object = _asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee19(s3Key) {
|
|
43908
|
+
var storageOptions,
|
|
43909
|
+
expiryMs,
|
|
43910
|
+
cacheKey,
|
|
43911
|
+
expiry,
|
|
43912
|
+
cachedResponse,
|
|
43913
|
+
cachedTime,
|
|
43914
|
+
age,
|
|
43915
|
+
_allKeys,
|
|
43916
|
+
matchingKeys,
|
|
43917
|
+
_args19 = arguments;
|
|
43918
|
+
return _regenerator().w(function (_context19) {
|
|
43919
|
+
while (1) switch (_context19.n) {
|
|
43920
|
+
case 0:
|
|
43921
|
+
storageOptions = _args19.length > 1 && _args19[1] !== undefined ? _args19[1] : {};
|
|
43922
|
+
expiryMs = _args19.length > 2 && _args19[2] !== undefined ? _args19[2] : null;
|
|
43923
|
+
cacheKey = "https://s3.cache/".concat(s3Key);
|
|
43924
|
+
expiry = expiryMs || cacheManager.getExpiryForPath(s3Key);
|
|
43925
|
+
console.log("\uD83D\uDD0D [S3Cache] Checking for cached S3 object:", {
|
|
43926
|
+
s3Key: s3Key,
|
|
43927
|
+
cacheKey: cacheKey
|
|
43928
|
+
});
|
|
43929
|
+
|
|
43930
|
+
// First, check ALL app cache partitions for a hit (handles auth race condition)
|
|
43931
|
+
_context19.n = 1;
|
|
43932
|
+
return findInAllCachePartitions(cacheKey);
|
|
43933
|
+
case 1:
|
|
43934
|
+
cachedResponse = _context19.v;
|
|
43935
|
+
if (!cachedResponse) {
|
|
43936
|
+
_context19.n = 4;
|
|
43937
|
+
break;
|
|
43938
|
+
}
|
|
43939
|
+
cachedTime = cachedResponse.headers.get('x-cached-time');
|
|
43940
|
+
age = Date.now() - parseInt(cachedTime || '0');
|
|
43941
|
+
console.log("\u2705 [S3Cache] Found in cache partition, age: ".concat(Math.round(age / 1000), "s, expiry: ").concat(Math.round(expiry / 1000), "s"));
|
|
43942
|
+
if (!(age < expiry)) {
|
|
43943
|
+
_context19.n = 3;
|
|
43944
|
+
break;
|
|
43945
|
+
}
|
|
43946
|
+
console.log("\u2705 [S3Cache] Returning cached blob for: ".concat(s3Key));
|
|
43947
|
+
_context19.n = 2;
|
|
43948
|
+
return cachedResponse.blob();
|
|
43949
|
+
case 2:
|
|
43950
|
+
return _context19.a(2, _context19.v);
|
|
43951
|
+
case 3:
|
|
43952
|
+
console.log("\u23F0 [S3Cache] Cache entry expired, will re-fetch");
|
|
43953
|
+
_context19.n = 6;
|
|
43954
|
+
break;
|
|
43955
|
+
case 4:
|
|
43956
|
+
console.log("\u274C [S3Cache] Not found in any cache partition");
|
|
43957
|
+
_context19.n = 5;
|
|
43958
|
+
return getAllCacheKeys();
|
|
43959
|
+
case 5:
|
|
43960
|
+
_allKeys = _context19.v;
|
|
43961
|
+
matchingKeys = _toConsumableArray(_allKeys).filter(function (k) {
|
|
43962
|
+
return k.includes('24dd6a7a') || k.includes('.glb');
|
|
43963
|
+
});
|
|
43964
|
+
if (matchingKeys.length > 0) {
|
|
43965
|
+
console.log("\uD83D\uDD0D [S3Cache] Available GLB cache keys:", matchingKeys.slice(0, 5));
|
|
43966
|
+
}
|
|
43967
|
+
case 6:
|
|
43968
|
+
return _context19.a(2, cacheManager.execute({
|
|
43969
|
+
cacheKey: cacheKey,
|
|
43970
|
+
sourceKey: s3Key,
|
|
43971
|
+
expiryMs: expiry,
|
|
43972
|
+
fetcher: function () {
|
|
43973
|
+
var _fetcher = _asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee17() {
|
|
43974
|
+
var result, _result, _t12;
|
|
43975
|
+
return _regenerator().w(function (_context17) {
|
|
43976
|
+
while (1) switch (_context17.n) {
|
|
43977
|
+
case 0:
|
|
43978
|
+
_context17.p = 0;
|
|
43979
|
+
_context17.n = 1;
|
|
43980
|
+
return awsAmplify.Storage.get(s3Key, _objectSpread2(_objectSpread2({}, storageOptions), {}, {
|
|
43981
|
+
download: true
|
|
43982
|
+
}));
|
|
43983
|
+
case 1:
|
|
43984
|
+
result = _context17.v;
|
|
43985
|
+
return _context17.a(2, result.Body);
|
|
43986
|
+
case 2:
|
|
43987
|
+
_context17.p = 2;
|
|
43988
|
+
_t12 = _context17.v;
|
|
43989
|
+
if (!(_t12.code === 'ExpiredToken' || _t12.message && _t12.message.includes('ExpiredToken'))) {
|
|
43990
|
+
_context17.n = 5;
|
|
43991
|
+
break;
|
|
43992
|
+
}
|
|
43993
|
+
console.warn("\u26A0\uFE0F Token expired fetching S3 object. Refreshing credentials and retrying...");
|
|
43994
|
+
_context17.n = 3;
|
|
43995
|
+
return awsAmplify.Auth.currentCredentials({
|
|
43996
|
+
bypassCache: true
|
|
43997
|
+
});
|
|
43998
|
+
case 3:
|
|
43999
|
+
_context17.n = 4;
|
|
44000
|
+
return awsAmplify.Storage.get(s3Key, _objectSpread2(_objectSpread2({}, storageOptions), {}, {
|
|
44001
|
+
download: true
|
|
44002
|
+
}));
|
|
44003
|
+
case 4:
|
|
44004
|
+
_result = _context17.v;
|
|
44005
|
+
return _context17.a(2, _result.Body);
|
|
44006
|
+
case 5:
|
|
44007
|
+
throw _t12;
|
|
44008
|
+
case 6:
|
|
44009
|
+
return _context17.a(2);
|
|
44010
|
+
}
|
|
44011
|
+
}, _callee17, null, [[0, 2]]);
|
|
44012
|
+
}));
|
|
44013
|
+
function fetcher() {
|
|
44014
|
+
return _fetcher.apply(this, arguments);
|
|
44015
|
+
}
|
|
44016
|
+
return fetcher;
|
|
44017
|
+
}(),
|
|
44018
|
+
processor: function () {
|
|
44019
|
+
var _processor = _asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee18(res) {
|
|
44020
|
+
return _regenerator().w(function (_context18) {
|
|
44021
|
+
while (1) switch (_context18.n) {
|
|
44022
|
+
case 0:
|
|
44023
|
+
if (!(res instanceof Response)) {
|
|
44024
|
+
_context18.n = 2;
|
|
44025
|
+
break;
|
|
44026
|
+
}
|
|
44027
|
+
_context18.n = 1;
|
|
44028
|
+
return res.blob();
|
|
44029
|
+
case 1:
|
|
44030
|
+
return _context18.a(2, _context18.v);
|
|
44031
|
+
case 2:
|
|
44032
|
+
return _context18.a(2, res);
|
|
44033
|
+
}
|
|
44034
|
+
}, _callee18);
|
|
44035
|
+
}));
|
|
44036
|
+
function processor(_x18) {
|
|
44037
|
+
return _processor.apply(this, arguments);
|
|
44038
|
+
}
|
|
44039
|
+
return processor;
|
|
44040
|
+
}(),
|
|
44041
|
+
logType: 'S3 Object'
|
|
44042
|
+
}));
|
|
44043
|
+
}
|
|
44044
|
+
}, _callee19);
|
|
44045
|
+
}));
|
|
44046
|
+
return _getCachedS3Object.apply(this, arguments);
|
|
44047
|
+
}
|
|
44048
|
+
function getCachedS3ObjectURL(_x5) {
|
|
44049
|
+
return _getCachedS3ObjectURL.apply(this, arguments);
|
|
44050
|
+
}
|
|
44051
|
+
function _getCachedS3ObjectURL() {
|
|
44052
|
+
_getCachedS3ObjectURL = _asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee20(s3Key) {
|
|
44053
|
+
var storageOptions,
|
|
44054
|
+
expiryMs,
|
|
44055
|
+
blob,
|
|
44056
|
+
_args20 = arguments;
|
|
44057
|
+
return _regenerator().w(function (_context20) {
|
|
44058
|
+
while (1) switch (_context20.n) {
|
|
44059
|
+
case 0:
|
|
44060
|
+
storageOptions = _args20.length > 1 && _args20[1] !== undefined ? _args20[1] : {};
|
|
44061
|
+
expiryMs = _args20.length > 2 && _args20[2] !== undefined ? _args20[2] : null;
|
|
44062
|
+
_context20.n = 1;
|
|
44063
|
+
return getCachedS3Object(s3Key, storageOptions, expiryMs);
|
|
44064
|
+
case 1:
|
|
44065
|
+
blob = _context20.v;
|
|
44066
|
+
return _context20.a(2, URL.createObjectURL(blob));
|
|
44067
|
+
}
|
|
44068
|
+
}, _callee20);
|
|
44069
|
+
}));
|
|
44070
|
+
return _getCachedS3ObjectURL.apply(this, arguments);
|
|
44071
|
+
}
|
|
44072
|
+
function preloadS3Objects(_x6) {
|
|
44073
|
+
return _preloadS3Objects.apply(this, arguments);
|
|
44074
|
+
}
|
|
44075
|
+
function _preloadS3Objects() {
|
|
44076
|
+
_preloadS3Objects = _asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee22(s3Keys) {
|
|
44077
|
+
var storageOptions,
|
|
44078
|
+
results,
|
|
44079
|
+
_args22 = arguments;
|
|
44080
|
+
return _regenerator().w(function (_context22) {
|
|
44081
|
+
while (1) switch (_context22.n) {
|
|
44082
|
+
case 0:
|
|
44083
|
+
storageOptions = _args22.length > 1 && _args22[1] !== undefined ? _args22[1] : {};
|
|
44084
|
+
results = {
|
|
44085
|
+
success: 0,
|
|
44086
|
+
failed: 0,
|
|
44087
|
+
errors: []
|
|
44088
|
+
};
|
|
44089
|
+
_context22.n = 1;
|
|
44090
|
+
return Promise.all(s3Keys.map(/*#__PURE__*/function () {
|
|
44091
|
+
var _ref4 = _asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee21(key) {
|
|
44092
|
+
var _t13;
|
|
44093
|
+
return _regenerator().w(function (_context21) {
|
|
44094
|
+
while (1) switch (_context21.n) {
|
|
44095
|
+
case 0:
|
|
44096
|
+
_context21.p = 0;
|
|
44097
|
+
_context21.n = 1;
|
|
44098
|
+
return getCachedS3Object(key, storageOptions);
|
|
44099
|
+
case 1:
|
|
44100
|
+
results.success++;
|
|
44101
|
+
_context21.n = 3;
|
|
44102
|
+
break;
|
|
44103
|
+
case 2:
|
|
44104
|
+
_context21.p = 2;
|
|
44105
|
+
_t13 = _context21.v;
|
|
44106
|
+
results.failed++;
|
|
44107
|
+
results.errors.push({
|
|
44108
|
+
key: key,
|
|
44109
|
+
error: _t13.message
|
|
44110
|
+
});
|
|
44111
|
+
case 3:
|
|
44112
|
+
return _context21.a(2);
|
|
44113
|
+
}
|
|
44114
|
+
}, _callee21, null, [[0, 2]]);
|
|
44115
|
+
}));
|
|
44116
|
+
return function (_x19) {
|
|
44117
|
+
return _ref4.apply(this, arguments);
|
|
44118
|
+
};
|
|
44119
|
+
}()));
|
|
44120
|
+
case 1:
|
|
44121
|
+
console.log("\u2705 Preload complete: ".concat(results.success, " success, ").concat(results.failed, " failed"));
|
|
44122
|
+
return _context22.a(2, results);
|
|
44123
|
+
}
|
|
44124
|
+
}, _callee22);
|
|
44125
|
+
}));
|
|
44126
|
+
return _preloadS3Objects.apply(this, arguments);
|
|
44127
|
+
}
|
|
44128
|
+
function getCachedS3Json(_x7) {
|
|
44129
|
+
return _getCachedS3Json.apply(this, arguments);
|
|
44130
|
+
}
|
|
44131
|
+
function _getCachedS3Json() {
|
|
44132
|
+
_getCachedS3Json = _asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee24(s3Key) {
|
|
44133
|
+
var storageOptions,
|
|
44134
|
+
expiryMs,
|
|
44135
|
+
_args24 = arguments;
|
|
44136
|
+
return _regenerator().w(function (_context24) {
|
|
44137
|
+
while (1) switch (_context24.n) {
|
|
44138
|
+
case 0:
|
|
44139
|
+
storageOptions = _args24.length > 1 && _args24[1] !== undefined ? _args24[1] : {};
|
|
44140
|
+
expiryMs = _args24.length > 2 && _args24[2] !== undefined ? _args24[2] : null;
|
|
44141
|
+
return _context24.a(2, cacheManager.execute({
|
|
44142
|
+
cacheKey: "https://s3.cache/".concat(s3Key),
|
|
44143
|
+
sourceKey: s3Key,
|
|
44144
|
+
expiryMs: expiryMs || cacheManager.getExpiryForPath(s3Key),
|
|
44145
|
+
fetcher: function () {
|
|
44146
|
+
var _fetcher2 = _asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee23() {
|
|
44147
|
+
var signedUrl, _signedUrl, _t14;
|
|
44148
|
+
return _regenerator().w(function (_context23) {
|
|
44149
|
+
while (1) switch (_context23.n) {
|
|
44150
|
+
case 0:
|
|
44151
|
+
_context23.p = 0;
|
|
44152
|
+
_context23.n = 1;
|
|
44153
|
+
return awsAmplify.Storage.get(s3Key, _objectSpread2(_objectSpread2({}, storageOptions), {}, {
|
|
44154
|
+
customPrefix: {
|
|
44155
|
+
public: ''
|
|
44156
|
+
}
|
|
44157
|
+
}));
|
|
44158
|
+
case 1:
|
|
44159
|
+
signedUrl = _context23.v;
|
|
44160
|
+
return _context23.a(2, fetch(signedUrl));
|
|
44161
|
+
case 2:
|
|
44162
|
+
_context23.p = 2;
|
|
44163
|
+
_t14 = _context23.v;
|
|
44164
|
+
if (!(_t14.code === 'ExpiredToken' || _t14.message && _t14.message.includes('ExpiredToken'))) {
|
|
44165
|
+
_context23.n = 5;
|
|
44166
|
+
break;
|
|
44167
|
+
}
|
|
44168
|
+
console.warn("\u26A0\uFE0F Token expired fetching S3 JSON. Refreshing credentials and retrying...");
|
|
44169
|
+
_context23.n = 3;
|
|
44170
|
+
return awsAmplify.Auth.currentCredentials({
|
|
44171
|
+
bypassCache: true
|
|
44172
|
+
});
|
|
44173
|
+
case 3:
|
|
44174
|
+
_context23.n = 4;
|
|
44175
|
+
return awsAmplify.Storage.get(s3Key, _objectSpread2(_objectSpread2({}, storageOptions), {}, {
|
|
44176
|
+
customPrefix: {
|
|
44177
|
+
public: ''
|
|
44178
|
+
}
|
|
44179
|
+
}));
|
|
44180
|
+
case 4:
|
|
44181
|
+
_signedUrl = _context23.v;
|
|
44182
|
+
return _context23.a(2, fetch(_signedUrl));
|
|
44183
|
+
case 5:
|
|
44184
|
+
throw _t14;
|
|
44185
|
+
case 6:
|
|
44186
|
+
return _context23.a(2);
|
|
44187
|
+
}
|
|
44188
|
+
}, _callee23, null, [[0, 2]]);
|
|
44189
|
+
}));
|
|
44190
|
+
function fetcher() {
|
|
44191
|
+
return _fetcher2.apply(this, arguments);
|
|
44192
|
+
}
|
|
44193
|
+
return fetcher;
|
|
44194
|
+
}(),
|
|
44195
|
+
processor: function processor(res) {
|
|
44196
|
+
return res.json();
|
|
44197
|
+
},
|
|
44198
|
+
logType: 'S3 JSON'
|
|
44199
|
+
}));
|
|
44200
|
+
}
|
|
44201
|
+
}, _callee24);
|
|
44202
|
+
}));
|
|
44203
|
+
return _getCachedS3Json.apply(this, arguments);
|
|
44204
|
+
}
|
|
44205
|
+
function getCachedLocalJson(_x8) {
|
|
44206
|
+
return _getCachedLocalJson.apply(this, arguments);
|
|
44207
|
+
}
|
|
44208
|
+
function _getCachedLocalJson() {
|
|
44209
|
+
_getCachedLocalJson = _asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee25(localPath) {
|
|
44210
|
+
return _regenerator().w(function (_context25) {
|
|
44211
|
+
while (1) switch (_context25.n) {
|
|
44212
|
+
case 0:
|
|
44213
|
+
return _context25.a(2, executeGlobal({
|
|
44214
|
+
cacheKey: "https://local.cache".concat(localPath),
|
|
44215
|
+
fetcher: function fetcher() {
|
|
44216
|
+
return fetch(localPath);
|
|
44217
|
+
},
|
|
44218
|
+
processor: function processor(res) {
|
|
44219
|
+
return res.json();
|
|
44220
|
+
},
|
|
44221
|
+
metadata: {
|
|
44222
|
+
'x-local-path': localPath
|
|
44223
|
+
}
|
|
44224
|
+
}));
|
|
44225
|
+
}
|
|
44226
|
+
}, _callee25);
|
|
44227
|
+
}));
|
|
44228
|
+
return _getCachedLocalJson.apply(this, arguments);
|
|
44229
|
+
}
|
|
44230
|
+
function getCachedLocalFile(_x9) {
|
|
44231
|
+
return _getCachedLocalFile.apply(this, arguments);
|
|
44232
|
+
}
|
|
44233
|
+
function _getCachedLocalFile() {
|
|
44234
|
+
_getCachedLocalFile = _asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee26(url) {
|
|
44235
|
+
return _regenerator().w(function (_context26) {
|
|
44236
|
+
while (1) switch (_context26.n) {
|
|
44237
|
+
case 0:
|
|
44238
|
+
if (!(!url || url.includes('undefined') || url.includes('null'))) {
|
|
44239
|
+
_context26.n = 1;
|
|
44240
|
+
break;
|
|
44241
|
+
}
|
|
44242
|
+
throw new Error("Invalid URL: ".concat(url));
|
|
44243
|
+
case 1:
|
|
44244
|
+
return _context26.a(2, executeGlobal({
|
|
44245
|
+
cacheKey: "https://local.cache".concat(url),
|
|
44246
|
+
fetcher: function fetcher() {
|
|
44247
|
+
return fetch(url);
|
|
44248
|
+
},
|
|
44249
|
+
processor: function processor(res) {
|
|
44250
|
+
return res.blob();
|
|
44251
|
+
},
|
|
44252
|
+
metadata: {
|
|
44253
|
+
'x-local-path': url
|
|
44254
|
+
}
|
|
44255
|
+
}));
|
|
44256
|
+
}
|
|
44257
|
+
}, _callee26);
|
|
44258
|
+
}));
|
|
44259
|
+
return _getCachedLocalFile.apply(this, arguments);
|
|
44260
|
+
}
|
|
44261
|
+
function getCachedLocalFileURL(_x0) {
|
|
44262
|
+
return _getCachedLocalFileURL.apply(this, arguments);
|
|
44263
|
+
}
|
|
44264
|
+
function _getCachedLocalFileURL() {
|
|
44265
|
+
_getCachedLocalFileURL = _asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee27(url) {
|
|
44266
|
+
var expiryMs,
|
|
44267
|
+
blob,
|
|
44268
|
+
_args27 = arguments;
|
|
44269
|
+
return _regenerator().w(function (_context27) {
|
|
44270
|
+
while (1) switch (_context27.n) {
|
|
44271
|
+
case 0:
|
|
44272
|
+
expiryMs = _args27.length > 1 && _args27[1] !== undefined ? _args27[1] : null;
|
|
44273
|
+
_context27.n = 1;
|
|
44274
|
+
return getCachedLocalFile(url, expiryMs);
|
|
44275
|
+
case 1:
|
|
44276
|
+
blob = _context27.v;
|
|
44277
|
+
return _context27.a(2, URL.createObjectURL(blob));
|
|
44278
|
+
}
|
|
44279
|
+
}, _callee27);
|
|
44280
|
+
}));
|
|
44281
|
+
return _getCachedLocalFileURL.apply(this, arguments);
|
|
44282
|
+
}
|
|
44283
|
+
function preloadLocalFiles(_x1) {
|
|
44284
|
+
return _preloadLocalFiles.apply(this, arguments);
|
|
44285
|
+
}
|
|
44286
|
+
|
|
44287
|
+
// --- Arbitrary JSON Helpers ---
|
|
44288
|
+
function _preloadLocalFiles() {
|
|
44289
|
+
_preloadLocalFiles = _asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee29(urls) {
|
|
44290
|
+
var results;
|
|
44291
|
+
return _regenerator().w(function (_context29) {
|
|
44292
|
+
while (1) switch (_context29.n) {
|
|
44293
|
+
case 0:
|
|
44294
|
+
console.log("preloadLocalFiles started");
|
|
44295
|
+
results = {
|
|
44296
|
+
success: 0,
|
|
44297
|
+
failed: 0,
|
|
44298
|
+
errors: []
|
|
44299
|
+
};
|
|
44300
|
+
_context29.n = 1;
|
|
44301
|
+
return Promise.all(urls.map(/*#__PURE__*/function () {
|
|
44302
|
+
var _ref5 = _asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee28(url) {
|
|
44303
|
+
var _t15;
|
|
44304
|
+
return _regenerator().w(function (_context28) {
|
|
44305
|
+
while (1) switch (_context28.n) {
|
|
44306
|
+
case 0:
|
|
44307
|
+
_context28.p = 0;
|
|
44308
|
+
_context28.n = 1;
|
|
44309
|
+
return getCachedLocalFile(url);
|
|
44310
|
+
case 1:
|
|
44311
|
+
results.success++;
|
|
44312
|
+
_context28.n = 3;
|
|
44313
|
+
break;
|
|
44314
|
+
case 2:
|
|
44315
|
+
_context28.p = 2;
|
|
44316
|
+
_t15 = _context28.v;
|
|
44317
|
+
console.error("\u274C preloadLocalFiles Preload failed for ".concat(url, ":"), _t15);
|
|
44318
|
+
results.failed++;
|
|
44319
|
+
results.errors.push({
|
|
44320
|
+
url: url,
|
|
44321
|
+
error: _t15.message
|
|
44322
|
+
});
|
|
44323
|
+
case 3:
|
|
44324
|
+
return _context28.a(2);
|
|
44325
|
+
}
|
|
44326
|
+
}, _callee28, null, [[0, 2]]);
|
|
44327
|
+
}));
|
|
44328
|
+
return function (_x20) {
|
|
44329
|
+
return _ref5.apply(this, arguments);
|
|
44330
|
+
};
|
|
44331
|
+
}()));
|
|
44332
|
+
case 1:
|
|
44333
|
+
console.log("preloadLocalFiles finished");
|
|
44334
|
+
if (results.failed > 0) {
|
|
44335
|
+
console.warn("\u26A0\uFE0F preloadLocalFiles Cache priming finished with errors: ".concat(results.failed, " failed"), results.errors);
|
|
44336
|
+
}
|
|
44337
|
+
return _context29.a(2, results);
|
|
44338
|
+
}
|
|
44339
|
+
}, _callee29);
|
|
44340
|
+
}));
|
|
44341
|
+
return _preloadLocalFiles.apply(this, arguments);
|
|
44342
|
+
}
|
|
44343
|
+
function cacheJsonData(_x10, _x11) {
|
|
44344
|
+
return _cacheJsonData.apply(this, arguments);
|
|
44345
|
+
}
|
|
44346
|
+
function _cacheJsonData() {
|
|
44347
|
+
_cacheJsonData = _asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee32(key, data) {
|
|
44348
|
+
var expiryMs,
|
|
44349
|
+
cacheKey,
|
|
44350
|
+
_args32 = arguments;
|
|
44351
|
+
return _regenerator().w(function (_context32) {
|
|
44352
|
+
while (1) switch (_context32.n) {
|
|
44353
|
+
case 0:
|
|
44354
|
+
expiryMs = _args32.length > 2 && _args32[2] !== undefined ? _args32[2] : CACHE_EXPIRY.JSON;
|
|
44355
|
+
cacheKey = "https://json.cache/".concat(key); // Delete existing entry first to ensure we overwrite with new data
|
|
44356
|
+
_context32.n = 1;
|
|
44357
|
+
return cacheManager.delete(cacheKey);
|
|
44358
|
+
case 1:
|
|
44359
|
+
return _context32.a(2, cacheManager.execute({
|
|
44360
|
+
cacheKey: cacheKey,
|
|
44361
|
+
sourceKey: key,
|
|
44362
|
+
expiryMs: expiryMs,
|
|
44363
|
+
fetcher: function () {
|
|
44364
|
+
var _fetcher3 = _asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee30() {
|
|
44365
|
+
return _regenerator().w(function (_context30) {
|
|
44366
|
+
while (1) switch (_context30.n) {
|
|
44367
|
+
case 0:
|
|
44368
|
+
return _context30.a(2, new Response(JSON.stringify(data), {
|
|
44369
|
+
headers: {
|
|
44370
|
+
'Content-Type': 'application/json'
|
|
44371
|
+
}
|
|
44372
|
+
}));
|
|
44373
|
+
}
|
|
44374
|
+
}, _callee30);
|
|
44375
|
+
}));
|
|
44376
|
+
function fetcher() {
|
|
44377
|
+
return _fetcher3.apply(this, arguments);
|
|
44378
|
+
}
|
|
44379
|
+
return fetcher;
|
|
44380
|
+
}(),
|
|
44381
|
+
processor: function () {
|
|
44382
|
+
var _processor2 = _asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee31(res) {
|
|
44383
|
+
return _regenerator().w(function (_context31) {
|
|
44384
|
+
while (1) switch (_context31.n) {
|
|
44385
|
+
case 0:
|
|
44386
|
+
return _context31.a(2, data);
|
|
44387
|
+
}
|
|
44388
|
+
}, _callee31);
|
|
44389
|
+
}));
|
|
44390
|
+
function processor(_x21) {
|
|
44391
|
+
return _processor2.apply(this, arguments);
|
|
44392
|
+
}
|
|
44393
|
+
return processor;
|
|
44394
|
+
}(),
|
|
44395
|
+
// Return the original data to the caller
|
|
44396
|
+
logType: 'Arbitrary JSON'
|
|
44397
|
+
}).then(function () {
|
|
44398
|
+
return true;
|
|
44399
|
+
}).catch(function (e) {
|
|
44400
|
+
console.error("Failed to cache JSON data ".concat(key, ":"), e);
|
|
44401
|
+
return false;
|
|
44402
|
+
}));
|
|
44403
|
+
}
|
|
44404
|
+
}, _callee32);
|
|
44405
|
+
}));
|
|
44406
|
+
return _cacheJsonData.apply(this, arguments);
|
|
44407
|
+
}
|
|
44408
|
+
function getCachedJsonData(_x12) {
|
|
44409
|
+
return _getCachedJsonData.apply(this, arguments);
|
|
44410
|
+
}
|
|
44411
|
+
function _getCachedJsonData() {
|
|
44412
|
+
_getCachedJsonData = _asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee34(key) {
|
|
44413
|
+
var expiryMs,
|
|
44414
|
+
_args34 = arguments;
|
|
44415
|
+
return _regenerator().w(function (_context34) {
|
|
44416
|
+
while (1) switch (_context34.n) {
|
|
44417
|
+
case 0:
|
|
44418
|
+
expiryMs = _args34.length > 1 && _args34[1] !== undefined ? _args34[1] : CACHE_EXPIRY.JSON;
|
|
44419
|
+
return _context34.a(2, cacheManager.get("https://json.cache/".concat(key), expiryMs, /*#__PURE__*/function () {
|
|
44420
|
+
var _ref6 = _asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee33(r) {
|
|
44421
|
+
return _regenerator().w(function (_context33) {
|
|
44422
|
+
while (1) switch (_context33.n) {
|
|
44423
|
+
case 0:
|
|
44424
|
+
return _context33.a(2, r.json());
|
|
44425
|
+
}
|
|
44426
|
+
}, _callee33);
|
|
44427
|
+
}));
|
|
44428
|
+
return function (_x22) {
|
|
44429
|
+
return _ref6.apply(this, arguments);
|
|
44430
|
+
};
|
|
44431
|
+
}()));
|
|
44432
|
+
}
|
|
44433
|
+
}, _callee34);
|
|
44434
|
+
}));
|
|
44435
|
+
return _getCachedJsonData.apply(this, arguments);
|
|
44436
|
+
}
|
|
44437
|
+
function removeCachedJsonData(_x13) {
|
|
44438
|
+
return _removeCachedJsonData.apply(this, arguments);
|
|
44439
|
+
}
|
|
44440
|
+
|
|
44441
|
+
// --- Thumbnails ---
|
|
44442
|
+
function _removeCachedJsonData() {
|
|
44443
|
+
_removeCachedJsonData = _asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee35(key) {
|
|
44444
|
+
return _regenerator().w(function (_context35) {
|
|
44445
|
+
while (1) switch (_context35.n) {
|
|
44446
|
+
case 0:
|
|
44447
|
+
return _context35.a(2, cacheManager.delete("https://json.cache/".concat(key)));
|
|
44448
|
+
}
|
|
44449
|
+
}, _callee35);
|
|
44450
|
+
}));
|
|
44451
|
+
return _removeCachedJsonData.apply(this, arguments);
|
|
44452
|
+
}
|
|
44453
|
+
function getThumbnailKey(asset) {
|
|
44454
|
+
var thumbnailKey = asset.thumbnailS3Path;
|
|
44455
|
+
if (!thumbnailKey && asset.s3Path) {
|
|
44456
|
+
var uuid = asset.uuid || asset.id;
|
|
44457
|
+
var thumbnailFilename = "".concat(uuid, ".png");
|
|
44458
|
+
thumbnailKey = "".concat(asset.s3Path, "/").concat(thumbnailFilename);
|
|
44459
|
+
}
|
|
44460
|
+
return thumbnailKey || null;
|
|
44461
|
+
}
|
|
44462
|
+
function isThumbnailCached(_x14) {
|
|
44463
|
+
return _isThumbnailCached.apply(this, arguments);
|
|
44464
|
+
}
|
|
44465
|
+
function _isThumbnailCached() {
|
|
44466
|
+
_isThumbnailCached = _asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee36(asset) {
|
|
44467
|
+
var isS3Asset, key;
|
|
44468
|
+
return _regenerator().w(function (_context36) {
|
|
44469
|
+
while (1) switch (_context36.n) {
|
|
44470
|
+
case 0:
|
|
44471
|
+
// Match the isS3Component logic: isS3Component || source === 's3' || scope === 'user'
|
|
44472
|
+
isS3Asset = asset.isS3Component || asset.source === 's3' || asset.scope === 'user';
|
|
44473
|
+
if (isS3Asset) {
|
|
44474
|
+
_context36.n = 1;
|
|
44475
|
+
break;
|
|
44476
|
+
}
|
|
44477
|
+
return _context36.a(2, true);
|
|
44478
|
+
case 1:
|
|
44479
|
+
key = getThumbnailKey(asset);
|
|
44480
|
+
if (key) {
|
|
44481
|
+
_context36.n = 2;
|
|
44482
|
+
break;
|
|
44483
|
+
}
|
|
44484
|
+
return _context36.a(2, false);
|
|
44485
|
+
case 2:
|
|
44486
|
+
return _context36.a(2, isCached(key));
|
|
44487
|
+
}
|
|
44488
|
+
}, _callee36);
|
|
44489
|
+
}));
|
|
44490
|
+
return _isThumbnailCached.apply(this, arguments);
|
|
44491
|
+
}
|
|
44492
|
+
function isCached(_x15) {
|
|
44493
|
+
return _isCached.apply(this, arguments);
|
|
44494
|
+
}
|
|
44495
|
+
|
|
44496
|
+
// --- Path/Expiry Helpers ---
|
|
44497
|
+
function _isCached() {
|
|
44498
|
+
_isCached = _asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee37(s3Key) {
|
|
44499
|
+
var expiryMs,
|
|
44500
|
+
_args37 = arguments;
|
|
44501
|
+
return _regenerator().w(function (_context37) {
|
|
44502
|
+
while (1) switch (_context37.n) {
|
|
44503
|
+
case 0:
|
|
44504
|
+
expiryMs = _args37.length > 1 && _args37[1] !== undefined ? _args37[1] : null;
|
|
44505
|
+
return _context37.a(2, cacheManager.has("https://s3.cache/".concat(s3Key), expiryMs));
|
|
44506
|
+
}
|
|
44507
|
+
}, _callee37);
|
|
44508
|
+
}));
|
|
44509
|
+
return _isCached.apply(this, arguments);
|
|
44510
|
+
}
|
|
44511
|
+
function getCacheExpiryForPath(path) {
|
|
44512
|
+
var assetType = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : null;
|
|
44513
|
+
return cacheManager.getExpiryForPath(path, assetType);
|
|
44514
|
+
}
|
|
44515
|
+
function formatCacheExpiry(ms) {
|
|
44516
|
+
var SECOND = 1000;
|
|
44517
|
+
var MINUTE = 60 * SECOND;
|
|
44518
|
+
var HOUR = 60 * MINUTE;
|
|
44519
|
+
var DAY = 24 * HOUR;
|
|
44520
|
+
var WEEK = 7 * DAY;
|
|
44521
|
+
if (ms >= WEEK) return "".concat((ms / WEEK).toFixed(1), " week(s)");
|
|
44522
|
+
if (ms >= DAY) return "".concat((ms / DAY).toFixed(1), " day(s)");
|
|
44523
|
+
if (ms >= HOUR) return "".concat((ms / HOUR).toFixed(1), " hour(s)");
|
|
44524
|
+
return "".concat((ms / 1000 / 60).toFixed(1), " minute(s)");
|
|
44525
|
+
}
|
|
44526
|
+
|
|
44527
|
+
var CACHE_KEY = 's3-component-metadata';
|
|
44528
|
+
var CACHE_VERSION = 1;
|
|
44529
|
+
|
|
44530
|
+
/**
|
|
44531
|
+
* Simple mutex implementation for preventing concurrent read-modify-write operations
|
|
44532
|
+
*/
|
|
44533
|
+
var SimpleMutex = /*#__PURE__*/function () {
|
|
44534
|
+
function SimpleMutex() {
|
|
44535
|
+
_classCallCheck(this, SimpleMutex);
|
|
44536
|
+
this._locked = false;
|
|
44537
|
+
this._queue = [];
|
|
44538
|
+
}
|
|
44539
|
+
return _createClass(SimpleMutex, [{
|
|
44540
|
+
key: "acquire",
|
|
44541
|
+
value: function () {
|
|
44542
|
+
var _acquire = _asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee() {
|
|
44543
|
+
var _this = this;
|
|
44544
|
+
return _regenerator().w(function (_context) {
|
|
44545
|
+
while (1) switch (_context.n) {
|
|
44546
|
+
case 0:
|
|
44547
|
+
return _context.a(2, new Promise(function (resolve) {
|
|
44548
|
+
if (!_this._locked) {
|
|
44549
|
+
_this._locked = true;
|
|
44550
|
+
resolve();
|
|
44551
|
+
} else {
|
|
44552
|
+
_this._queue.push(resolve);
|
|
44553
|
+
}
|
|
44554
|
+
}));
|
|
44555
|
+
}
|
|
44556
|
+
}, _callee);
|
|
44557
|
+
}));
|
|
44558
|
+
function acquire() {
|
|
44559
|
+
return _acquire.apply(this, arguments);
|
|
44560
|
+
}
|
|
44561
|
+
return acquire;
|
|
44562
|
+
}()
|
|
44563
|
+
}, {
|
|
44564
|
+
key: "release",
|
|
44565
|
+
value: function release() {
|
|
44566
|
+
if (this._queue.length > 0) {
|
|
44567
|
+
var next = this._queue.shift();
|
|
44568
|
+
next();
|
|
44569
|
+
} else {
|
|
44570
|
+
this._locked = false;
|
|
44571
|
+
}
|
|
44572
|
+
}
|
|
44573
|
+
}]);
|
|
44574
|
+
}();
|
|
44575
|
+
var S3MetadataCacheService = /*#__PURE__*/function () {
|
|
44576
|
+
function S3MetadataCacheService() {
|
|
44577
|
+
_classCallCheck(this, S3MetadataCacheService);
|
|
44578
|
+
this._mutex = new SimpleMutex();
|
|
44579
|
+
this._memoryCache = null;
|
|
44580
|
+
this._memoryCacheTime = 0;
|
|
44581
|
+
this._memoryCacheTTL = 5000; // 5 seconds in-memory cache
|
|
44582
|
+
}
|
|
44583
|
+
|
|
44584
|
+
/**
|
|
44585
|
+
* Create empty metadata structure
|
|
44586
|
+
*/
|
|
44587
|
+
return _createClass(S3MetadataCacheService, [{
|
|
44588
|
+
key: "_createEmptyMetadata",
|
|
44589
|
+
value: function _createEmptyMetadata() {
|
|
44590
|
+
return {
|
|
44591
|
+
version: CACHE_VERSION,
|
|
44592
|
+
components: [],
|
|
44593
|
+
timestamp: Date.now()
|
|
44594
|
+
};
|
|
44595
|
+
}
|
|
44596
|
+
|
|
44597
|
+
/**
|
|
44598
|
+
* Validate and migrate metadata if needed
|
|
44599
|
+
*/
|
|
44600
|
+
}, {
|
|
44601
|
+
key: "_validateMetadata",
|
|
44602
|
+
value: function _validateMetadata(metadata) {
|
|
44603
|
+
if (!metadata) {
|
|
44604
|
+
return this._createEmptyMetadata();
|
|
44605
|
+
}
|
|
44606
|
+
|
|
44607
|
+
// Ensure components array exists
|
|
44608
|
+
if (!Array.isArray(metadata.components)) {
|
|
44609
|
+
metadata.components = [];
|
|
44610
|
+
}
|
|
44611
|
+
|
|
44612
|
+
// Add version if missing (for legacy cache)
|
|
44613
|
+
if (metadata.version === undefined) {
|
|
44614
|
+
metadata.version = CACHE_VERSION;
|
|
44615
|
+
}
|
|
44616
|
+
return metadata;
|
|
44617
|
+
}
|
|
44618
|
+
|
|
44619
|
+
/**
|
|
44620
|
+
* Check if memory cache is still valid
|
|
44621
|
+
*/
|
|
44622
|
+
}, {
|
|
44623
|
+
key: "_isMemoryCacheValid",
|
|
44624
|
+
value: function _isMemoryCacheValid() {
|
|
44625
|
+
return this._memoryCache !== null && Date.now() - this._memoryCacheTime < this._memoryCacheTTL;
|
|
44626
|
+
}
|
|
44627
|
+
|
|
44628
|
+
/**
|
|
44629
|
+
* Invalidate the memory cache
|
|
44630
|
+
*/
|
|
44631
|
+
}, {
|
|
44632
|
+
key: "_invalidateMemoryCache",
|
|
44633
|
+
value: function _invalidateMemoryCache() {
|
|
44634
|
+
this._memoryCache = null;
|
|
44635
|
+
this._memoryCacheTime = 0;
|
|
44636
|
+
}
|
|
44637
|
+
|
|
44638
|
+
/**
|
|
44639
|
+
* Get all cached components
|
|
44640
|
+
* @returns {Promise<Array>} Array of cached component metadata
|
|
44641
|
+
*/
|
|
44642
|
+
}, {
|
|
44643
|
+
key: "getAll",
|
|
44644
|
+
value: (function () {
|
|
44645
|
+
var _getAll = _asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee2() {
|
|
44646
|
+
var metadata, validated, _t;
|
|
44647
|
+
return _regenerator().w(function (_context2) {
|
|
44648
|
+
while (1) switch (_context2.n) {
|
|
44649
|
+
case 0:
|
|
44650
|
+
if (!this._isMemoryCacheValid()) {
|
|
44651
|
+
_context2.n = 1;
|
|
44652
|
+
break;
|
|
44653
|
+
}
|
|
44654
|
+
return _context2.a(2, _toConsumableArray(this._memoryCache.components));
|
|
44655
|
+
case 1:
|
|
44656
|
+
_context2.p = 1;
|
|
44657
|
+
_context2.n = 2;
|
|
44658
|
+
return getCachedJsonData(CACHE_KEY);
|
|
44659
|
+
case 2:
|
|
44660
|
+
metadata = _context2.v;
|
|
44661
|
+
validated = this._validateMetadata(metadata); // Update memory cache
|
|
44662
|
+
this._memoryCache = validated;
|
|
44663
|
+
this._memoryCacheTime = Date.now();
|
|
44664
|
+
return _context2.a(2, _toConsumableArray(validated.components));
|
|
44665
|
+
case 3:
|
|
44666
|
+
_context2.p = 3;
|
|
44667
|
+
_t = _context2.v;
|
|
44668
|
+
console.warn('⚠️ S3MetadataCacheService: Failed to get components:', _t);
|
|
44669
|
+
return _context2.a(2, []);
|
|
44670
|
+
}
|
|
44671
|
+
}, _callee2, this, [[1, 3]]);
|
|
44672
|
+
}));
|
|
44673
|
+
function getAll() {
|
|
44674
|
+
return _getAll.apply(this, arguments);
|
|
44675
|
+
}
|
|
44676
|
+
return getAll;
|
|
44677
|
+
}()
|
|
44678
|
+
/**
|
|
44679
|
+
* Get the full metadata object (for advanced use cases)
|
|
44680
|
+
* @returns {Promise<Object>} Full metadata object with version, components, timestamp
|
|
44681
|
+
*/
|
|
44682
|
+
)
|
|
44683
|
+
}, {
|
|
44684
|
+
key: "getMetadata",
|
|
44685
|
+
value: (function () {
|
|
44686
|
+
var _getMetadata = _asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee3() {
|
|
44687
|
+
var metadata, validated, _t2;
|
|
44688
|
+
return _regenerator().w(function (_context3) {
|
|
44689
|
+
while (1) switch (_context3.n) {
|
|
44690
|
+
case 0:
|
|
44691
|
+
if (!this._isMemoryCacheValid()) {
|
|
44692
|
+
_context3.n = 1;
|
|
44693
|
+
break;
|
|
44694
|
+
}
|
|
44695
|
+
return _context3.a(2, _objectSpread2({}, this._memoryCache));
|
|
44696
|
+
case 1:
|
|
44697
|
+
_context3.p = 1;
|
|
44698
|
+
_context3.n = 2;
|
|
44699
|
+
return getCachedJsonData(CACHE_KEY);
|
|
44700
|
+
case 2:
|
|
44701
|
+
metadata = _context3.v;
|
|
44702
|
+
validated = this._validateMetadata(metadata);
|
|
44703
|
+
this._memoryCache = validated;
|
|
44704
|
+
this._memoryCacheTime = Date.now();
|
|
44705
|
+
return _context3.a(2, _objectSpread2({}, validated));
|
|
44706
|
+
case 3:
|
|
44707
|
+
_context3.p = 3;
|
|
44708
|
+
_t2 = _context3.v;
|
|
44709
|
+
console.warn('⚠️ S3MetadataCacheService: Failed to get metadata:', _t2);
|
|
44710
|
+
return _context3.a(2, this._createEmptyMetadata());
|
|
44711
|
+
}
|
|
44712
|
+
}, _callee3, this, [[1, 3]]);
|
|
44713
|
+
}));
|
|
44714
|
+
function getMetadata() {
|
|
44715
|
+
return _getMetadata.apply(this, arguments);
|
|
44716
|
+
}
|
|
44717
|
+
return getMetadata;
|
|
44718
|
+
}()
|
|
44719
|
+
/**
|
|
44720
|
+
* Add or update a component in the cache
|
|
44721
|
+
* Uses mutex to prevent race conditions
|
|
44722
|
+
* @param {Object} component - Component metadata to add/update
|
|
44723
|
+
* @returns {Promise<boolean>} Success status
|
|
44724
|
+
*/
|
|
44725
|
+
)
|
|
44726
|
+
}, {
|
|
44727
|
+
key: "addComponent",
|
|
44728
|
+
value: (function () {
|
|
44729
|
+
var _addComponent = _asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee4(component) {
|
|
44730
|
+
var metadata, validated, existingIndex, _t3;
|
|
44731
|
+
return _regenerator().w(function (_context4) {
|
|
44732
|
+
while (1) switch (_context4.n) {
|
|
44733
|
+
case 0:
|
|
44734
|
+
if (!(!component || !component.id && !component.uuid)) {
|
|
44735
|
+
_context4.n = 1;
|
|
44736
|
+
break;
|
|
44737
|
+
}
|
|
44738
|
+
console.warn('⚠️ S3MetadataCacheService: Cannot add component without id or uuid');
|
|
44739
|
+
return _context4.a(2, false);
|
|
44740
|
+
case 1:
|
|
44741
|
+
_context4.n = 2;
|
|
44742
|
+
return this._mutex.acquire();
|
|
44743
|
+
case 2:
|
|
44744
|
+
_context4.p = 2;
|
|
44745
|
+
_context4.n = 3;
|
|
44746
|
+
return getCachedJsonData(CACHE_KEY);
|
|
44747
|
+
case 3:
|
|
44748
|
+
metadata = _context4.v;
|
|
44749
|
+
validated = this._validateMetadata(metadata); // Remove existing entry if it exists (by id or uuid)
|
|
44750
|
+
existingIndex = validated.components.findIndex(function (c) {
|
|
44751
|
+
return c.id === component.id || c.uuid === component.uuid || component.id && c.uuid === component.id || component.uuid && c.id === component.uuid;
|
|
44752
|
+
});
|
|
44753
|
+
if (existingIndex !== -1) {
|
|
44754
|
+
validated.components.splice(existingIndex, 1);
|
|
44755
|
+
}
|
|
44756
|
+
|
|
44757
|
+
// Add new component
|
|
44758
|
+
validated.components.push(component);
|
|
44759
|
+
validated.timestamp = Date.now();
|
|
44760
|
+
|
|
44761
|
+
// Write back to cache
|
|
44762
|
+
_context4.n = 4;
|
|
44763
|
+
return cacheJsonData(CACHE_KEY, validated);
|
|
44764
|
+
case 4:
|
|
44765
|
+
// Update memory cache
|
|
44766
|
+
this._memoryCache = validated;
|
|
44767
|
+
this._memoryCacheTime = Date.now();
|
|
44768
|
+
console.log("\uD83D\uDCBE S3MetadataCacheService: Added/updated component ".concat(component.name || component.id));
|
|
44769
|
+
return _context4.a(2, true);
|
|
44770
|
+
case 5:
|
|
44771
|
+
_context4.p = 5;
|
|
44772
|
+
_t3 = _context4.v;
|
|
44773
|
+
console.error('❌ S3MetadataCacheService: Failed to add component:', _t3);
|
|
44774
|
+
return _context4.a(2, false);
|
|
44775
|
+
case 6:
|
|
44776
|
+
_context4.p = 6;
|
|
44777
|
+
this._mutex.release();
|
|
44778
|
+
return _context4.f(6);
|
|
44779
|
+
case 7:
|
|
44780
|
+
return _context4.a(2);
|
|
44781
|
+
}
|
|
44782
|
+
}, _callee4, this, [[2, 5, 6, 7]]);
|
|
44783
|
+
}));
|
|
44784
|
+
function addComponent(_x) {
|
|
44785
|
+
return _addComponent.apply(this, arguments);
|
|
44786
|
+
}
|
|
44787
|
+
return addComponent;
|
|
44788
|
+
}()
|
|
44789
|
+
/**
|
|
44790
|
+
* Remove a component from the cache
|
|
44791
|
+
* Uses mutex to prevent race conditions
|
|
44792
|
+
* @param {string} identifier - Component id or uuid to remove
|
|
44793
|
+
* @returns {Promise<boolean>} Success status
|
|
44794
|
+
*/
|
|
44795
|
+
)
|
|
44796
|
+
}, {
|
|
44797
|
+
key: "removeComponent",
|
|
44798
|
+
value: (function () {
|
|
44799
|
+
var _removeComponent = _asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee5(identifier) {
|
|
44800
|
+
var metadata, validated, originalLength, removed, _t4;
|
|
44801
|
+
return _regenerator().w(function (_context5) {
|
|
44802
|
+
while (1) switch (_context5.n) {
|
|
44803
|
+
case 0:
|
|
44804
|
+
if (identifier) {
|
|
44805
|
+
_context5.n = 1;
|
|
44806
|
+
break;
|
|
44807
|
+
}
|
|
44808
|
+
console.warn('⚠️ S3MetadataCacheService: Cannot remove component without identifier');
|
|
44809
|
+
return _context5.a(2, false);
|
|
44810
|
+
case 1:
|
|
44811
|
+
_context5.n = 2;
|
|
44812
|
+
return this._mutex.acquire();
|
|
44813
|
+
case 2:
|
|
44814
|
+
_context5.p = 2;
|
|
44815
|
+
_context5.n = 3;
|
|
44816
|
+
return getCachedJsonData(CACHE_KEY);
|
|
44817
|
+
case 3:
|
|
44818
|
+
metadata = _context5.v;
|
|
44819
|
+
if (!(!metadata || !metadata.components)) {
|
|
44820
|
+
_context5.n = 4;
|
|
44821
|
+
break;
|
|
44822
|
+
}
|
|
44823
|
+
console.log('ℹ️ S3MetadataCacheService: No metadata to remove from');
|
|
44824
|
+
return _context5.a(2, true);
|
|
44825
|
+
case 4:
|
|
44826
|
+
validated = this._validateMetadata(metadata);
|
|
44827
|
+
originalLength = validated.components.length; // Filter out the component by both id and uuid
|
|
44828
|
+
validated.components = validated.components.filter(function (c) {
|
|
44829
|
+
return c.id !== identifier && c.uuid !== identifier;
|
|
44830
|
+
});
|
|
44831
|
+
removed = originalLength !== validated.components.length;
|
|
44832
|
+
if (!removed) {
|
|
44833
|
+
_context5.n = 6;
|
|
44834
|
+
break;
|
|
44835
|
+
}
|
|
44836
|
+
validated.timestamp = Date.now();
|
|
44837
|
+
_context5.n = 5;
|
|
44838
|
+
return cacheJsonData(CACHE_KEY, validated);
|
|
44839
|
+
case 5:
|
|
44840
|
+
// Update memory cache
|
|
44841
|
+
this._memoryCache = validated;
|
|
44842
|
+
this._memoryCacheTime = Date.now();
|
|
44843
|
+
console.log("\uD83D\uDDD1\uFE0F S3MetadataCacheService: Removed component ".concat(identifier));
|
|
44844
|
+
case 6:
|
|
44845
|
+
return _context5.a(2, true);
|
|
44846
|
+
case 7:
|
|
44847
|
+
_context5.p = 7;
|
|
44848
|
+
_t4 = _context5.v;
|
|
44849
|
+
console.error('❌ S3MetadataCacheService: Failed to remove component:', _t4);
|
|
44850
|
+
return _context5.a(2, false);
|
|
44851
|
+
case 8:
|
|
44852
|
+
_context5.p = 8;
|
|
44853
|
+
this._mutex.release();
|
|
44854
|
+
return _context5.f(8);
|
|
44855
|
+
case 9:
|
|
44856
|
+
return _context5.a(2);
|
|
44857
|
+
}
|
|
44858
|
+
}, _callee5, this, [[2, 7, 8, 9]]);
|
|
44859
|
+
}));
|
|
44860
|
+
function removeComponent(_x2) {
|
|
44861
|
+
return _removeComponent.apply(this, arguments);
|
|
44862
|
+
}
|
|
44863
|
+
return removeComponent;
|
|
44864
|
+
}()
|
|
44865
|
+
/**
|
|
44866
|
+
* Clear all cached metadata
|
|
44867
|
+
* @returns {Promise<boolean>} Success status
|
|
44868
|
+
*/
|
|
44869
|
+
)
|
|
44870
|
+
}, {
|
|
44871
|
+
key: "clear",
|
|
44872
|
+
value: (function () {
|
|
44873
|
+
var _clear = _asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee6() {
|
|
44874
|
+
var _t5;
|
|
44875
|
+
return _regenerator().w(function (_context6) {
|
|
44876
|
+
while (1) switch (_context6.n) {
|
|
44877
|
+
case 0:
|
|
44878
|
+
_context6.n = 1;
|
|
44879
|
+
return this._mutex.acquire();
|
|
44880
|
+
case 1:
|
|
44881
|
+
_context6.p = 1;
|
|
44882
|
+
_context6.n = 2;
|
|
44883
|
+
return removeCachedJsonData(CACHE_KEY);
|
|
44884
|
+
case 2:
|
|
44885
|
+
this._invalidateMemoryCache();
|
|
44886
|
+
console.log('🗑️ S3MetadataCacheService: Cleared all metadata');
|
|
44887
|
+
return _context6.a(2, true);
|
|
44888
|
+
case 3:
|
|
44889
|
+
_context6.p = 3;
|
|
44890
|
+
_t5 = _context6.v;
|
|
44891
|
+
console.error('❌ S3MetadataCacheService: Failed to clear metadata:', _t5);
|
|
44892
|
+
return _context6.a(2, false);
|
|
44893
|
+
case 4:
|
|
44894
|
+
_context6.p = 4;
|
|
44895
|
+
this._mutex.release();
|
|
44896
|
+
return _context6.f(4);
|
|
44897
|
+
case 5:
|
|
44898
|
+
return _context6.a(2);
|
|
44899
|
+
}
|
|
44900
|
+
}, _callee6, this, [[1, 3, 4, 5]]);
|
|
44901
|
+
}));
|
|
44902
|
+
function clear() {
|
|
44903
|
+
return _clear.apply(this, arguments);
|
|
44904
|
+
}
|
|
44905
|
+
return clear;
|
|
44906
|
+
}()
|
|
44907
|
+
/**
|
|
44908
|
+
* Check if a component exists in the cache
|
|
44909
|
+
* @param {string} identifier - Component id or uuid
|
|
44910
|
+
* @returns {Promise<boolean>} True if exists
|
|
44911
|
+
*/
|
|
44912
|
+
)
|
|
44913
|
+
}, {
|
|
44914
|
+
key: "hasComponent",
|
|
44915
|
+
value: (function () {
|
|
44916
|
+
var _hasComponent = _asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee7(identifier) {
|
|
44917
|
+
var components;
|
|
44918
|
+
return _regenerator().w(function (_context7) {
|
|
44919
|
+
while (1) switch (_context7.n) {
|
|
44920
|
+
case 0:
|
|
44921
|
+
_context7.n = 1;
|
|
44922
|
+
return this.getAll();
|
|
44923
|
+
case 1:
|
|
44924
|
+
components = _context7.v;
|
|
44925
|
+
return _context7.a(2, components.some(function (c) {
|
|
44926
|
+
return c.id === identifier || c.uuid === identifier;
|
|
44927
|
+
}));
|
|
44928
|
+
}
|
|
44929
|
+
}, _callee7, this);
|
|
44930
|
+
}));
|
|
44931
|
+
function hasComponent(_x3) {
|
|
44932
|
+
return _hasComponent.apply(this, arguments);
|
|
44933
|
+
}
|
|
44934
|
+
return hasComponent;
|
|
44935
|
+
}()
|
|
44936
|
+
/**
|
|
44937
|
+
* Force refresh from persistent cache (bypass memory cache)
|
|
44938
|
+
* @returns {Promise<Array>} Array of cached components
|
|
44939
|
+
*/
|
|
44940
|
+
)
|
|
44941
|
+
}, {
|
|
44942
|
+
key: "refresh",
|
|
44943
|
+
value: (function () {
|
|
44944
|
+
var _refresh = _asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee8() {
|
|
44945
|
+
return _regenerator().w(function (_context8) {
|
|
44946
|
+
while (1) switch (_context8.n) {
|
|
44947
|
+
case 0:
|
|
44948
|
+
this._invalidateMemoryCache();
|
|
44949
|
+
return _context8.a(2, this.getAll());
|
|
44950
|
+
}
|
|
44951
|
+
}, _callee8, this);
|
|
44952
|
+
}));
|
|
44953
|
+
function refresh() {
|
|
44954
|
+
return _refresh.apply(this, arguments);
|
|
44955
|
+
}
|
|
44956
|
+
return refresh;
|
|
44957
|
+
}()
|
|
44958
|
+
/**
|
|
44959
|
+
* Replace all cached components with a new array
|
|
44960
|
+
* Used for bulk operations like initial fetch
|
|
44961
|
+
* @param {Array} components - Array of components to cache
|
|
44962
|
+
* @returns {Promise<boolean>} Success status
|
|
44963
|
+
*/
|
|
44964
|
+
)
|
|
44965
|
+
}, {
|
|
44966
|
+
key: "setAll",
|
|
44967
|
+
value: (function () {
|
|
44968
|
+
var _setAll = _asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee9(components) {
|
|
44969
|
+
var metadata, _t6;
|
|
44970
|
+
return _regenerator().w(function (_context9) {
|
|
44971
|
+
while (1) switch (_context9.n) {
|
|
44972
|
+
case 0:
|
|
44973
|
+
if (Array.isArray(components)) {
|
|
44974
|
+
_context9.n = 1;
|
|
44975
|
+
break;
|
|
44976
|
+
}
|
|
44977
|
+
console.warn('⚠️ S3MetadataCacheService: setAll requires an array');
|
|
44978
|
+
return _context9.a(2, false);
|
|
44979
|
+
case 1:
|
|
44980
|
+
_context9.n = 2;
|
|
44981
|
+
return this._mutex.acquire();
|
|
44982
|
+
case 2:
|
|
44983
|
+
_context9.p = 2;
|
|
44984
|
+
metadata = {
|
|
44985
|
+
version: CACHE_VERSION,
|
|
44986
|
+
components: components,
|
|
44987
|
+
timestamp: Date.now()
|
|
44988
|
+
};
|
|
44989
|
+
_context9.n = 3;
|
|
44990
|
+
return cacheJsonData(CACHE_KEY, metadata);
|
|
44991
|
+
case 3:
|
|
44992
|
+
// Update memory cache
|
|
44993
|
+
this._memoryCache = metadata;
|
|
44994
|
+
this._memoryCacheTime = Date.now();
|
|
44995
|
+
console.log("\uD83D\uDCBE S3MetadataCacheService: Set ".concat(components.length, " components"));
|
|
44996
|
+
return _context9.a(2, true);
|
|
44997
|
+
case 4:
|
|
44998
|
+
_context9.p = 4;
|
|
44999
|
+
_t6 = _context9.v;
|
|
45000
|
+
console.error('❌ S3MetadataCacheService: Failed to set components:', _t6);
|
|
45001
|
+
return _context9.a(2, false);
|
|
45002
|
+
case 5:
|
|
45003
|
+
_context9.p = 5;
|
|
45004
|
+
this._mutex.release();
|
|
45005
|
+
return _context9.f(5);
|
|
45006
|
+
case 6:
|
|
45007
|
+
return _context9.a(2);
|
|
45008
|
+
}
|
|
45009
|
+
}, _callee9, this, [[2, 4, 5, 6]]);
|
|
45010
|
+
}));
|
|
45011
|
+
function setAll(_x4) {
|
|
45012
|
+
return _setAll.apply(this, arguments);
|
|
45013
|
+
}
|
|
45014
|
+
return setAll;
|
|
45015
|
+
}())
|
|
45016
|
+
}]);
|
|
45017
|
+
}(); // Export singleton instance
|
|
45018
|
+
var s3MetadataCache = new S3MetadataCacheService();
|
|
45019
|
+
|
|
45020
|
+
/**
|
|
45021
|
+
* Measure S3 operation time and log results
|
|
45022
|
+
* @param {string} operation - Operation name (e.g., "Upload GLB", "Download JSON")
|
|
45023
|
+
* @param {Function} asyncFn - Async function to measure
|
|
45024
|
+
* @param {number} fileSize - Optional file size in bytes for speed calculation
|
|
45025
|
+
* @returns {Promise} - Result from asyncFn
|
|
45026
|
+
*/
|
|
45027
|
+
function measureS3Transfer(_x, _x2) {
|
|
45028
|
+
return _measureS3Transfer.apply(this, arguments);
|
|
45029
|
+
}
|
|
45030
|
+
function _measureS3Transfer() {
|
|
45031
|
+
_measureS3Transfer = _asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee2(operation, asyncFn) {
|
|
45032
|
+
var fileSize,
|
|
45033
|
+
startTime,
|
|
45034
|
+
executeTransfer,
|
|
45035
|
+
endTime,
|
|
45036
|
+
duration,
|
|
45037
|
+
_args2 = arguments,
|
|
45038
|
+
_t,
|
|
45039
|
+
_t2;
|
|
45040
|
+
return _regenerator().w(function (_context2) {
|
|
45041
|
+
while (1) switch (_context2.n) {
|
|
45042
|
+
case 0:
|
|
45043
|
+
fileSize = _args2.length > 2 && _args2[2] !== undefined ? _args2[2] : null;
|
|
45044
|
+
startTime = performance.now();
|
|
45045
|
+
executeTransfer = /*#__PURE__*/function () {
|
|
45046
|
+
var _ref = _asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee() {
|
|
45047
|
+
var result, endTime, duration, logMessage, sizeMB, speedMBps;
|
|
45048
|
+
return _regenerator().w(function (_context) {
|
|
45049
|
+
while (1) switch (_context.n) {
|
|
45050
|
+
case 0:
|
|
45051
|
+
_context.n = 1;
|
|
45052
|
+
return asyncFn();
|
|
45053
|
+
case 1:
|
|
45054
|
+
result = _context.v;
|
|
45055
|
+
endTime = performance.now();
|
|
45056
|
+
duration = ((endTime - startTime) / 1000).toFixed(3); // Convert to seconds
|
|
45057
|
+
logMessage = "\u23F1\uFE0F S3 ".concat(operation, ": ").concat(duration, "s");
|
|
45058
|
+
if (fileSize) {
|
|
45059
|
+
sizeMB = (fileSize / (1024 * 1024)).toFixed(2);
|
|
45060
|
+
speedMBps = (sizeMB / duration).toFixed(2);
|
|
45061
|
+
logMessage += " (".concat(sizeMB, " MB @ ").concat(speedMBps, " MB/s)");
|
|
45062
|
+
}
|
|
45063
|
+
console.log(logMessage);
|
|
45064
|
+
return _context.a(2, result);
|
|
45065
|
+
}
|
|
45066
|
+
}, _callee);
|
|
45067
|
+
}));
|
|
45068
|
+
return function executeTransfer() {
|
|
45069
|
+
return _ref.apply(this, arguments);
|
|
45070
|
+
};
|
|
45071
|
+
}();
|
|
45072
|
+
_context2.p = 1;
|
|
45073
|
+
_context2.n = 2;
|
|
45074
|
+
return executeTransfer();
|
|
45075
|
+
case 2:
|
|
45076
|
+
return _context2.a(2, _context2.v);
|
|
45077
|
+
case 3:
|
|
45078
|
+
_context2.p = 3;
|
|
45079
|
+
_t = _context2.v;
|
|
45080
|
+
if (!(_t.code === 'ExpiredToken' || _t.message && _t.message.includes('ExpiredToken'))) {
|
|
45081
|
+
_context2.n = 8;
|
|
45082
|
+
break;
|
|
45083
|
+
}
|
|
45084
|
+
console.warn("\u26A0\uFE0F Token expired during ".concat(operation, ". Attempting session refresh and retry..."));
|
|
45085
|
+
_context2.p = 4;
|
|
45086
|
+
_context2.n = 5;
|
|
45087
|
+
return awsAmplify.Auth.currentCredentials({
|
|
45088
|
+
bypassCache: true
|
|
45089
|
+
});
|
|
45090
|
+
case 5:
|
|
45091
|
+
console.log("\u2705 Session refreshed. Retrying ".concat(operation, "..."));
|
|
45092
|
+
|
|
45093
|
+
// Reset timer for the retry
|
|
45094
|
+
startTime = performance.now();
|
|
45095
|
+
_context2.n = 6;
|
|
45096
|
+
return executeTransfer();
|
|
45097
|
+
case 6:
|
|
45098
|
+
return _context2.a(2, _context2.v);
|
|
45099
|
+
case 7:
|
|
45100
|
+
_context2.p = 7;
|
|
45101
|
+
_t2 = _context2.v;
|
|
45102
|
+
console.error("\u274C Retry failed for ".concat(operation, ":"), _t2);
|
|
45103
|
+
// If retry fails, throw the Retry Error (likely unrelated or persistent auth issue)
|
|
45104
|
+
throw _t2;
|
|
45105
|
+
case 8:
|
|
45106
|
+
// Standard error handling for non-expired tokens (or if logic above didn't catch it)
|
|
45107
|
+
endTime = performance.now();
|
|
45108
|
+
duration = ((endTime - startTime) / 1000).toFixed(3);
|
|
45109
|
+
console.error("\u274C S3 ".concat(operation, " failed after ").concat(duration, "s:"), _t);
|
|
45110
|
+
throw _t;
|
|
45111
|
+
case 9:
|
|
45112
|
+
return _context2.a(2);
|
|
45113
|
+
}
|
|
45114
|
+
}, _callee2, null, [[4, 7], [1, 3]]);
|
|
45115
|
+
}));
|
|
45116
|
+
return _measureS3Transfer.apply(this, arguments);
|
|
45117
|
+
}
|
|
45118
|
+
|
|
43126
45119
|
var Rendering2D = /*#__PURE__*/function (_BaseDisposable) {
|
|
43127
45120
|
function Rendering2D(_canvas) {
|
|
43128
45121
|
var _this;
|
|
@@ -44474,6 +46467,7 @@ exports.ComponentManager = ComponentManager;
|
|
|
44474
46467
|
exports.ComponentTooltipManager = ComponentTooltipManager;
|
|
44475
46468
|
exports.EnvironmentManager = EnvironmentManager;
|
|
44476
46469
|
exports.FLOW_ATTRIBUTE_KEYS = FLOW_ATTRIBUTE_KEYS;
|
|
46470
|
+
exports.GLOBAL_CACHE_NAME = GLOBAL_CACHE_NAME;
|
|
44477
46471
|
exports.KeyboardControlsManager = KeyboardControlsManager;
|
|
44478
46472
|
exports.ModelManager = ModelManager;
|
|
44479
46473
|
exports.OperationHistoryManager = OperationHistoryManager;
|
|
@@ -44483,6 +46477,7 @@ exports.PathfindingManager = PathfindingManager;
|
|
|
44483
46477
|
exports.PerformanceMonitorManager = PerformanceMonitorManager;
|
|
44484
46478
|
exports.Rendering2D = rendering2D;
|
|
44485
46479
|
exports.Rendering3D = rendering3D;
|
|
46480
|
+
exports.S3MetadataCacheService = S3MetadataCacheService;
|
|
44486
46481
|
exports.SceneExportManager = SceneExportManager;
|
|
44487
46482
|
exports.SceneHierarchyManager = SceneHierarchyManager;
|
|
44488
46483
|
exports.SceneInitializationManager = SceneInitializationManager;
|
|
@@ -44490,15 +46485,36 @@ exports.SceneOperationsManager = SceneOperationsManager;
|
|
|
44490
46485
|
exports.SceneTooltipsManager = SceneTooltipsManager;
|
|
44491
46486
|
exports.SnapshotManager = SnapshotManager;
|
|
44492
46487
|
exports.ThreeJSResourceManager = ThreeJSResourceManager;
|
|
46488
|
+
exports.cacheJsonData = cacheJsonData;
|
|
44493
46489
|
exports.cacheManager = cacheManager;
|
|
46490
|
+
exports.cleanExpiredCache = cleanExpiredCache;
|
|
46491
|
+
exports.cleanInvalidCacheEntries = cleanInvalidCacheEntries;
|
|
46492
|
+
exports.clearS3Cache = clearS3Cache;
|
|
44494
46493
|
exports.createPathfindingRequest = createPathfindingRequest;
|
|
44495
46494
|
exports.createTransformControls = createTransformControls;
|
|
44496
46495
|
exports.findObjectByHardcodedUuid = findObjectByHardcodedUuid;
|
|
46496
|
+
exports.formatCacheExpiry = formatCacheExpiry;
|
|
44497
46497
|
exports.generateUniqueComponentId = generateUniqueComponentId;
|
|
44498
46498
|
exports.generateUuidFromName = generateUuidFromName;
|
|
46499
|
+
exports.getAllCacheKeys = getAllCacheKeys;
|
|
46500
|
+
exports.getCacheExpiryForPath = getCacheExpiryForPath;
|
|
46501
|
+
exports.getCacheStats = getCacheStats;
|
|
46502
|
+
exports.getCachedJsonData = getCachedJsonData;
|
|
46503
|
+
exports.getCachedLocalFile = getCachedLocalFile;
|
|
46504
|
+
exports.getCachedLocalFileURL = getCachedLocalFileURL;
|
|
46505
|
+
exports.getCachedLocalJson = getCachedLocalJson;
|
|
46506
|
+
exports.getCachedS3Json = getCachedS3Json;
|
|
46507
|
+
exports.getCachedS3Object = getCachedS3Object;
|
|
46508
|
+
exports.getCachedS3ObjectURL = getCachedS3ObjectURL;
|
|
46509
|
+
exports.getCurrentCacheName = getCurrentCacheName;
|
|
46510
|
+
exports.getGlobalCacheStats = getGlobalCacheStats;
|
|
46511
|
+
exports.getGlobalOnlyCacheStats = getGlobalOnlyCacheStats;
|
|
44499
46512
|
exports.getHardcodedUuid = getHardcodedUuid;
|
|
44500
46513
|
exports.getObjectTypeName = getObjectTypeName;
|
|
44501
46514
|
exports.getObjectsByType = getObjectsByType;
|
|
46515
|
+
exports.getThumbnailKey = getThumbnailKey;
|
|
46516
|
+
exports.getUserOnlyCacheStats = getUserOnlyCacheStats;
|
|
46517
|
+
exports.isCached = isCached;
|
|
44502
46518
|
exports.isComponent = isComponent;
|
|
44503
46519
|
exports.isComputed = isComputed;
|
|
44504
46520
|
exports.isConnector = isConnector;
|
|
@@ -44506,9 +46522,18 @@ exports.isDeclared = isDeclared;
|
|
|
44506
46522
|
exports.isExportable = isExportable;
|
|
44507
46523
|
exports.isGateway = isGateway;
|
|
44508
46524
|
exports.isSegment = isSegment;
|
|
46525
|
+
exports.isThumbnailCached = isThumbnailCached;
|
|
44509
46526
|
exports.loadTextureSetAndCreateMaterial = loadTextureSetAndCreateMaterial;
|
|
44510
46527
|
exports.markAsComputed = markAsComputed;
|
|
44511
46528
|
exports.markAsDeclared = markAsDeclared;
|
|
46529
|
+
exports.measureS3Transfer = measureS3Transfer;
|
|
44512
46530
|
exports.modelPreloader = modelPreloader;
|
|
46531
|
+
exports.preloadLocalFiles = preloadLocalFiles;
|
|
46532
|
+
exports.preloadS3Objects = preloadS3Objects;
|
|
46533
|
+
exports.removeCachedJsonData = removeCachedJsonData;
|
|
46534
|
+
exports.resetCacheIdentity = resetCacheIdentity;
|
|
46535
|
+
exports.resetGlobalCacheStats = resetGlobalCacheStats;
|
|
46536
|
+
exports.s3MetadataCache = s3MetadataCache;
|
|
44513
46537
|
exports.sceneViewer = sceneViewer;
|
|
44514
46538
|
exports.shouldRemoveOnRegeneration = shouldRemoveOnRegeneration;
|
|
46539
|
+
exports.switchCachePartition = switchCachePartition;
|