@flusys/nestjs-storage 6.3.0 → 6.4.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -210,6 +210,10 @@ let FileManagerService = class FileManagerService extends _classes.ApiService {
210
210
  if (updatedFiles.length) {
211
211
  try {
212
212
  await this.repository.save(updatedFiles);
213
+ await Promise.all([
214
+ this.clearCacheForAll(),
215
+ this.clearCacheForId(updatedFiles)
216
+ ]);
213
217
  } catch {
214
218
  // Silent failure - URL update is non-critical
215
219
  }
@@ -43,6 +43,15 @@ describe('FileManagerService', ()=>{
43
43
  let mockUploadService;
44
44
  let mockCacheManager;
45
45
  let mockSharedPermissionCacheService;
46
+ const mockUtilsService = {
47
+ clearCache: jest.fn(),
48
+ getCacheKey: jest.fn().mockReturnValue('cache-key'),
49
+ trackCacheKey: jest.fn()
50
+ };
51
+ // Call history is shared across tests in this file; reset it so each cache assertion is exact.
52
+ beforeEach(()=>{
53
+ mockUtilsService.clearCache.mockClear();
54
+ });
46
55
  beforeEach(async ()=>{
47
56
  mockFileRepo = (0, _repositorymock.createMockRepository)();
48
57
  mockFileRepo.findBy = jest.fn();
@@ -84,7 +93,7 @@ describe('FileManagerService', ()=>{
84
93
  },
85
94
  {
86
95
  provide: _modules.UtilsService,
87
- useValue: {}
96
+ useValue: mockUtilsService
88
97
  },
89
98
  {
90
99
  provide: _uploadservice.UploadService,
@@ -494,6 +503,24 @@ describe('FileManagerService', ()=>{
494
503
  ], 'http', 'localhost:2002');
495
504
  expect(mockFileRepo.save).toHaveBeenCalled();
496
505
  });
506
+ it('invalidates cached file responses for the files whose URL was refreshed', async ()=>{
507
+ const file = buildFile({
508
+ id: 'file-1',
509
+ url: null,
510
+ storageConfigId: 'cfg-1'
511
+ });
512
+ mockFileRepo.findBy.mockResolvedValue([
513
+ file
514
+ ]);
515
+ mockUploadService.makeFileUrl.mockResolvedValue('https://cdn.example.com/photo.jpg');
516
+ await service.getFiles([
517
+ {
518
+ id: 'file-1'
519
+ }
520
+ ], 'http', 'localhost:2002');
521
+ expect(mockUtilsService.clearCache).toHaveBeenCalledWith('file_manager', expect.anything());
522
+ expect(mockUtilsService.clearCache).toHaveBeenCalledWith('file_manager', expect.anything(), 'file-1');
523
+ });
497
524
  it('does not persist when no file URL needed refreshing', async ()=>{
498
525
  const file = buildFile({
499
526
  id: 'file-1',
@@ -159,6 +159,10 @@ export class FileManagerService extends ApiService {
159
159
  if (updatedFiles.length) {
160
160
  try {
161
161
  await this.repository.save(updatedFiles);
162
+ await Promise.all([
163
+ this.clearCacheForAll(),
164
+ this.clearCacheForId(updatedFiles)
165
+ ]);
162
166
  } catch {
163
167
  // Silent failure - URL update is non-critical
164
168
  }
@@ -39,6 +39,15 @@ describe('FileManagerService', ()=>{
39
39
  let mockUploadService;
40
40
  let mockCacheManager;
41
41
  let mockSharedPermissionCacheService;
42
+ const mockUtilsService = {
43
+ clearCache: jest.fn(),
44
+ getCacheKey: jest.fn().mockReturnValue('cache-key'),
45
+ trackCacheKey: jest.fn()
46
+ };
47
+ // Call history is shared across tests in this file; reset it so each cache assertion is exact.
48
+ beforeEach(()=>{
49
+ mockUtilsService.clearCache.mockClear();
50
+ });
42
51
  beforeEach(async ()=>{
43
52
  mockFileRepo = createMockRepository();
44
53
  mockFileRepo.findBy = jest.fn();
@@ -80,7 +89,7 @@ describe('FileManagerService', ()=>{
80
89
  },
81
90
  {
82
91
  provide: UtilsService,
83
- useValue: {}
92
+ useValue: mockUtilsService
84
93
  },
85
94
  {
86
95
  provide: UploadService,
@@ -490,6 +499,24 @@ describe('FileManagerService', ()=>{
490
499
  ], 'http', 'localhost:2002');
491
500
  expect(mockFileRepo.save).toHaveBeenCalled();
492
501
  });
502
+ it('invalidates cached file responses for the files whose URL was refreshed', async ()=>{
503
+ const file = buildFile({
504
+ id: 'file-1',
505
+ url: null,
506
+ storageConfigId: 'cfg-1'
507
+ });
508
+ mockFileRepo.findBy.mockResolvedValue([
509
+ file
510
+ ]);
511
+ mockUploadService.makeFileUrl.mockResolvedValue('https://cdn.example.com/photo.jpg');
512
+ await service.getFiles([
513
+ {
514
+ id: 'file-1'
515
+ }
516
+ ], 'http', 'localhost:2002');
517
+ expect(mockUtilsService.clearCache).toHaveBeenCalledWith('file_manager', expect.anything());
518
+ expect(mockUtilsService.clearCache).toHaveBeenCalledWith('file_manager', expect.anything(), 'file-1');
519
+ });
493
520
  it('does not persist when no file URL needed refreshing', async ()=>{
494
521
  const file = buildFile({
495
522
  id: 'file-1',
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@flusys/nestjs-storage",
3
- "version": "6.3.0",
3
+ "version": "6.4.1",
4
4
  "description": "Modular storage package with optional AWS S3, Azure Blob, and SFTP providers",
5
5
  "main": "cjs/index.js",
6
6
  "module": "fesm/index.js",
@@ -129,7 +129,7 @@
129
129
  }
130
130
  },
131
131
  "dependencies": {
132
- "@flusys/nestjs-core": "6.3.0",
133
- "@flusys/nestjs-shared": "6.3.0"
132
+ "@flusys/nestjs-core": "6.4.1",
133
+ "@flusys/nestjs-shared": "6.4.1"
134
134
  }
135
135
  }