@devrev/ts-adaas 1.4.0 → 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.
|
@@ -24,10 +24,10 @@ export declare function createWorkerAdapter<ConnectorState>({ event, adapterStat
|
|
|
24
24
|
export declare class WorkerAdapter<ConnectorState> {
|
|
25
25
|
readonly event: AirdropEvent;
|
|
26
26
|
readonly options?: WorkerAdapterOptions;
|
|
27
|
+
isTimeout: boolean;
|
|
27
28
|
private adapterState;
|
|
28
29
|
private _artifacts;
|
|
29
30
|
private hasWorkerEmitted;
|
|
30
|
-
private isTimeout;
|
|
31
31
|
private repos;
|
|
32
32
|
private loaderReports;
|
|
33
33
|
private _processedFiles;
|
|
@@ -123,7 +123,7 @@ class WorkerAdapter {
|
|
|
123
123
|
// Wait for all promises to settle and check for rate limiting
|
|
124
124
|
const results = await Promise.all(promises);
|
|
125
125
|
// Check if any of the results indicate rate limiting
|
|
126
|
-
const rateLimit = results.find(result => result === null || result === void 0 ? void 0 : result.delay);
|
|
126
|
+
const rateLimit = results.find((result) => result === null || result === void 0 ? void 0 : result.delay);
|
|
127
127
|
if (rateLimit) {
|
|
128
128
|
// Return the delay information to the caller
|
|
129
129
|
return { delay: rateLimit.delay };
|
|
@@ -688,9 +688,12 @@ class WorkerAdapter {
|
|
|
688
688
|
}) {
|
|
689
689
|
var _a, _b;
|
|
690
690
|
if (batchSize <= 0) {
|
|
691
|
-
|
|
692
|
-
|
|
693
|
-
|
|
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
|
|
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(
|
|
414
|
-
|
|
415
|
-
|
|
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(
|
|
418
|
-
// Restore console.
|
|
419
|
-
|
|
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.
|
|
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",
|
|
@@ -23,7 +23,7 @@
|
|
|
23
23
|
"author": "devrev",
|
|
24
24
|
"license": "ISC",
|
|
25
25
|
"devDependencies": {
|
|
26
|
-
"@types/jest": "^29.5.
|
|
26
|
+
"@types/jest": "^29.5.14",
|
|
27
27
|
"@types/lambda-log": "^3.0.3",
|
|
28
28
|
"@types/node": "^22.15.18",
|
|
29
29
|
"@types/yargs": "^17.0.33",
|
|
@@ -33,12 +33,12 @@
|
|
|
33
33
|
"eslint-config-prettier": "^10.1.5",
|
|
34
34
|
"eslint-plugin-prettier": "^5.1.3",
|
|
35
35
|
"jest": "^29.7.0",
|
|
36
|
-
"ts-jest": "^29.
|
|
36
|
+
"ts-jest": "^29.3.3",
|
|
37
37
|
"typescript": "^5.3.3"
|
|
38
38
|
},
|
|
39
39
|
"dependencies": {
|
|
40
|
-
"@devrev/typescript-sdk": "^1.1.
|
|
41
|
-
"axios": "^1.
|
|
40
|
+
"@devrev/typescript-sdk": "^1.1.59",
|
|
41
|
+
"axios": "^1.9.0",
|
|
42
42
|
"axios-retry": "^4.5.0",
|
|
43
43
|
"form-data": "^4.0.1",
|
|
44
44
|
"js-jsonl": "^1.1.1",
|