@squiz/db-lib 1.77.3 → 1.77.4
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/CHANGELOG.md +6 -0
- package/lib/dynamodb/AbstractDynamoDbRepository.spec.d.ts.map +1 -1
- package/lib/dynamodb/AbstractDynamoDbRepository.spec.js +109 -101
- package/lib/dynamodb/AbstractDynamoDbRepository.spec.js.map +1 -1
- package/lib/externalized/ExternalizedDynamoDbRepository.d.ts +0 -6
- package/lib/externalized/ExternalizedDynamoDbRepository.d.ts.map +1 -1
- package/lib/externalized/ExternalizedDynamoDbRepository.js +2 -30
- package/lib/externalized/ExternalizedDynamoDbRepository.js.map +1 -1
- package/lib/externalized/ExternalizedDynamoDbRepository.spec.js +7 -19
- package/lib/externalized/ExternalizedDynamoDbRepository.spec.js.map +1 -1
- package/package.json +5 -5
- package/src/dynamodb/AbstractDynamoDbRepository.spec.ts +17 -9
- package/src/externalized/ExternalizedDynamoDbRepository.spec.ts +7 -21
- package/src/externalized/ExternalizedDynamoDbRepository.ts +3 -41
- package/tsconfig.tsbuildinfo +1 -1
|
@@ -189,7 +189,7 @@ describe('ExternalizedDynamoDbRepository', () => {
|
|
|
189
189
|
if (callCount === 1) {
|
|
190
190
|
// First call fails with size limit error
|
|
191
191
|
const error = new Error('Item size has exceeded the maximum allowed size');
|
|
192
|
-
|
|
192
|
+
error.name = 'ValidationException';
|
|
193
193
|
throw error;
|
|
194
194
|
}
|
|
195
195
|
// Second call succeeds
|
|
@@ -453,38 +453,24 @@ describe('ExternalizedDynamoDbRepository', () => {
|
|
|
453
453
|
});
|
|
454
454
|
|
|
455
455
|
describe('isDynamoItemSizeLimitError', () => {
|
|
456
|
-
it('
|
|
456
|
+
it('returns true for ValidationException with size message', () => {
|
|
457
457
|
const repo = new TestRepo(createDbManager(), createStorage());
|
|
458
458
|
const error = {
|
|
459
|
-
|
|
459
|
+
name: 'ValidationException',
|
|
460
460
|
message: 'Item size has exceeded the maximum allowed size',
|
|
461
461
|
};
|
|
462
462
|
|
|
463
463
|
expect(repo.testIsDynamoItemSizeLimitError(error)).toBe(true);
|
|
464
464
|
});
|
|
465
465
|
|
|
466
|
-
it('
|
|
466
|
+
it('returns false for ValidationException without the DynamoDB size limit message', () => {
|
|
467
467
|
const repo = new TestRepo(createDbManager(), createStorage());
|
|
468
468
|
const error = {
|
|
469
|
-
|
|
470
|
-
|
|
471
|
-
{
|
|
472
|
-
Code: 'ValidationException',
|
|
473
|
-
Message: 'Item size exceeded 400 KB limit',
|
|
474
|
-
},
|
|
475
|
-
],
|
|
476
|
-
};
|
|
477
|
-
|
|
478
|
-
expect(repo.testIsDynamoItemSizeLimitError(error)).toBe(true);
|
|
479
|
-
});
|
|
480
|
-
|
|
481
|
-
it('detects size keywords in error message', () => {
|
|
482
|
-
const repo = new TestRepo(createDbManager(), createStorage());
|
|
483
|
-
const error = {
|
|
484
|
-
message: 'The item size exceeds the maximum allowed size',
|
|
469
|
+
name: 'ValidationException',
|
|
470
|
+
message: 'Invalid UpdateExpression',
|
|
485
471
|
};
|
|
486
472
|
|
|
487
|
-
expect(repo.testIsDynamoItemSizeLimitError(error)).toBe(
|
|
473
|
+
expect(repo.testIsDynamoItemSizeLimitError(error)).toBe(false);
|
|
488
474
|
});
|
|
489
475
|
|
|
490
476
|
it('returns false for non-size-related errors', () => {
|
|
@@ -16,6 +16,8 @@ import { DynamoDbManager, Transaction } from '../dynamodb/DynamoDbManager';
|
|
|
16
16
|
// Local
|
|
17
17
|
import { S3ExternalStorage, S3StorageLocation } from '../s3/S3ExternalStorage';
|
|
18
18
|
|
|
19
|
+
const DYNAMO_ITEM_SIZE_LIMIT_ERROR_MESSAGE = 'Item size has exceeded the maximum allowed size';
|
|
20
|
+
|
|
19
21
|
/**
|
|
20
22
|
* The ExternalizedDynamoDbRepository class is used to store and retrieve externalized items from DynamoDB and S3.
|
|
21
23
|
* @class ExternalizedDynamoDbRepository
|
|
@@ -592,46 +594,6 @@ export abstract class ExternalizedDynamoDbRepository<
|
|
|
592
594
|
}
|
|
593
595
|
|
|
594
596
|
const err = error as Record<string, unknown>;
|
|
595
|
-
|
|
596
|
-
| Array<Record<string, unknown>>
|
|
597
|
-
| undefined;
|
|
598
|
-
const validationCodes = ['ValidationException', 'TransactionCanceledException'];
|
|
599
|
-
|
|
600
|
-
const hasValidationCode =
|
|
601
|
-
validationCodes.includes(err?.code as string) ||
|
|
602
|
-
validationCodes.includes(err?.name as string) ||
|
|
603
|
-
validationCodes.includes((err?.originalError as Record<string, unknown>)?.code as string) ||
|
|
604
|
-
validationCodes.includes((err?.originalError as Record<string, unknown>)?.name as string) ||
|
|
605
|
-
(Array.isArray(cancellationReasons) &&
|
|
606
|
-
cancellationReasons.some((reason) => validationCodes.includes((reason?.Code ?? reason?.code) as string)));
|
|
607
|
-
|
|
608
|
-
const hasSizeMessage =
|
|
609
|
-
this.hasDynamoSizeKeyword(err?.message as string) ||
|
|
610
|
-
this.hasDynamoSizeKeyword((err?.originalError as Record<string, unknown>)?.message as string) ||
|
|
611
|
-
(Array.isArray(cancellationReasons) &&
|
|
612
|
-
cancellationReasons.some((reason) =>
|
|
613
|
-
this.hasDynamoSizeKeyword((reason?.Message ?? reason?.message) as string),
|
|
614
|
-
));
|
|
615
|
-
|
|
616
|
-
return hasValidationCode || hasSizeMessage;
|
|
617
|
-
}
|
|
618
|
-
|
|
619
|
-
/**
|
|
620
|
-
* Check if the message contains the DynamoDB size keyword.
|
|
621
|
-
* @param {string} message - The message to check.
|
|
622
|
-
* @returns {boolean} True if the message contains the DynamoDB size keyword, false otherwise.
|
|
623
|
-
*/
|
|
624
|
-
private hasDynamoSizeKeyword(message?: string): boolean {
|
|
625
|
-
if (typeof message !== 'string') {
|
|
626
|
-
return false;
|
|
627
|
-
}
|
|
628
|
-
const normalized = message.toLowerCase();
|
|
629
|
-
return (
|
|
630
|
-
normalized.includes('item size') ||
|
|
631
|
-
normalized.includes('maximum allowed size') ||
|
|
632
|
-
normalized.includes('exceeds') ||
|
|
633
|
-
normalized.includes('400 kb') ||
|
|
634
|
-
normalized.includes('400kb')
|
|
635
|
-
);
|
|
597
|
+
return err.name === 'ValidationException' && err.message === DYNAMO_ITEM_SIZE_LIMIT_ERROR_MESSAGE;
|
|
636
598
|
}
|
|
637
599
|
}
|