@devrev/ts-adaas 1.4.1 → 1.4.2

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.
@@ -688,9 +688,12 @@ class WorkerAdapter {
688
688
  }) {
689
689
  var _a, _b;
690
690
  if (batchSize <= 0) {
691
- const error = new Error(`Invalid attachments batch size: ${batchSize}. Batch size must be greater than 0.`);
692
- console.error(error.message);
693
- return { error };
691
+ console.warn(`The specified batch size (${batchSize}) is invalid. Using 1 instead.`);
692
+ batchSize = 1;
693
+ }
694
+ if (batchSize > 50) {
695
+ console.warn(`The specified batch size (${batchSize}) is too large. Using 50 instead.`);
696
+ batchSize = 50;
694
697
  }
695
698
  const repos = [
696
699
  {
@@ -142,44 +142,6 @@ describe('WorkerAdapter', () => {
142
142
  expect(result[0]).toHaveLength(1);
143
143
  expect(result[1]).toHaveLength(1);
144
144
  });
145
- it('should handle invalid (0) batch size', async () => {
146
- var _a;
147
- // Arrange
148
- const mockStream = jest.fn();
149
- const consoleErrorSpy = jest.spyOn(console, 'error').mockImplementation();
150
- // Act
151
- const result = await adapter.streamAttachments({
152
- stream: mockStream,
153
- batchSize: 0,
154
- });
155
- // Assert
156
- expect(consoleErrorSpy).toHaveBeenCalled();
157
- expect(result).toEqual({
158
- error: expect.any(Error),
159
- });
160
- expect((_a = result === null || result === void 0 ? void 0 : result.error) === null || _a === void 0 ? void 0 : _a.message).toContain('Invalid attachments batch size');
161
- // Restore console.error
162
- consoleErrorSpy.mockRestore();
163
- });
164
- it('should handle invalid (negative) batch size', async () => {
165
- var _a;
166
- // Arrange
167
- const mockStream = jest.fn();
168
- const consoleErrorSpy = jest.spyOn(console, 'error').mockImplementation();
169
- // Act
170
- const result = await adapter.streamAttachments({
171
- stream: mockStream,
172
- batchSize: -1,
173
- });
174
- // Assert
175
- expect(consoleErrorSpy).toHaveBeenCalled();
176
- expect(result).toEqual({
177
- error: expect.any(Error),
178
- });
179
- expect((_a = result === null || result === void 0 ? void 0 : result.error) === null || _a === void 0 ? void 0 : _a.message).toContain('Invalid attachments batch size');
180
- // Restore console.error
181
- consoleErrorSpy.mockRestore();
182
- });
183
145
  });
184
146
  describe('defaultAttachmentsIterator', () => {
185
147
  it('should process all batches of attachments', async () => {
@@ -400,23 +362,84 @@ describe('WorkerAdapter', () => {
400
362
  expect(result).toBeUndefined();
401
363
  });
402
364
  it('should handle invalid batch size', async () => {
403
- var _a;
404
365
  // Arrange
405
366
  const mockStream = jest.fn();
406
- const consoleErrorSpy = jest.spyOn(console, 'error').mockImplementation();
367
+ const consoleWarnSpy = jest.spyOn(console, 'warn').mockImplementation();
368
+ // Set up adapter state with artifact IDs
369
+ adapter.state.toDevRev = {
370
+ attachmentsMetadata: {
371
+ artifactIds: ['artifact1'],
372
+ lastProcessed: 0,
373
+ lastProcessedAttachmentsIdsList: [],
374
+ },
375
+ };
376
+ // Mock getting attachments
377
+ adapter['uploader'].getAttachmentsFromArtifactId = jest.fn().mockResolvedValue({
378
+ attachments: [
379
+ { url: 'http://example.com/file1.pdf', id: 'attachment1', file_name: 'file1.pdf', parent_id: 'parent1' },
380
+ ],
381
+ });
382
+ // Mock the required methods
383
+ adapter.initializeRepos = jest.fn();
384
+ const mockReducedAttachments = [['batch1']];
385
+ adapter['defaultAttachmentsReducer'] = jest.fn().mockReturnValue(mockReducedAttachments);
386
+ adapter['defaultAttachmentsIterator'] = jest.fn().mockResolvedValue({});
407
387
  // Act
408
388
  const result = await adapter.streamAttachments({
409
389
  stream: mockStream,
410
390
  batchSize: 0,
411
391
  });
412
392
  // Assert
413
- expect(consoleErrorSpy).toHaveBeenCalled();
414
- expect(result).toEqual({
415
- error: expect.any(Error),
393
+ expect(consoleWarnSpy).toHaveBeenCalledWith('The specified batch size (0) is invalid. Using 1 instead.');
394
+ // Verify that the reducer was called with batchSize 50 (not 100)
395
+ expect(adapter['defaultAttachmentsReducer']).toHaveBeenCalledWith({
396
+ attachments: expect.any(Array),
397
+ adapter: adapter,
398
+ batchSize: 1,
416
399
  });
417
- expect((_a = result === null || result === void 0 ? void 0 : result.error) === null || _a === void 0 ? void 0 : _a.message).toContain('Invalid attachments batch size');
418
- // Restore console.error
419
- consoleErrorSpy.mockRestore();
400
+ expect(result).toBeUndefined();
401
+ // Restore console.warn
402
+ consoleWarnSpy.mockRestore();
403
+ });
404
+ it('should cap batch size to 50 when batchSize is greater than 50', async () => {
405
+ // Arrange
406
+ const mockStream = jest.fn();
407
+ const consoleWarnSpy = jest.spyOn(console, 'warn').mockImplementation();
408
+ // Set up adapter state with artifact IDs
409
+ adapter.state.toDevRev = {
410
+ attachmentsMetadata: {
411
+ artifactIds: ['artifact1'],
412
+ lastProcessed: 0,
413
+ lastProcessedAttachmentsIdsList: [],
414
+ },
415
+ };
416
+ // Mock getting attachments
417
+ adapter['uploader'].getAttachmentsFromArtifactId = jest.fn().mockResolvedValue({
418
+ attachments: [
419
+ { url: 'http://example.com/file1.pdf', id: 'attachment1', file_name: 'file1.pdf', parent_id: 'parent1' },
420
+ ],
421
+ });
422
+ // Mock the required methods
423
+ adapter.initializeRepos = jest.fn();
424
+ const mockReducedAttachments = [['batch1']];
425
+ adapter['defaultAttachmentsReducer'] = jest.fn().mockReturnValue(mockReducedAttachments);
426
+ adapter['defaultAttachmentsIterator'] = jest.fn().mockResolvedValue({});
427
+ // Act
428
+ const result = await adapter.streamAttachments({
429
+ stream: mockStream,
430
+ batchSize: 100, // Set batch size greater than 50
431
+ });
432
+ // Assert
433
+ expect(consoleWarnSpy).toHaveBeenCalledWith('The specified batch size (100) is too large. Using 50 instead.');
434
+ // Verify that the reducer was called with batchSize 50 (not 100)
435
+ expect(adapter['defaultAttachmentsReducer']).toHaveBeenCalledWith({
436
+ attachments: expect.any(Array),
437
+ adapter: adapter,
438
+ batchSize: 50, // Should be capped at 50
439
+ });
440
+ expect(result).toBeUndefined();
441
+ // Restore console.warn
442
+ consoleWarnSpy.mockRestore();
420
443
  });
421
444
  it('should handle empty attachments metadata artifact IDs', async () => {
422
445
  // Arrange
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@devrev/ts-adaas",
3
- "version": "1.4.1",
3
+ "version": "1.4.2",
4
4
  "description": "Typescript library containing the ADaaS(AirDrop as a Service) control protocol.",
5
5
  "type": "commonjs",
6
6
  "main": "./dist/index.js",