@infra-blocks/aws-dynamodb 0.38.0-alpha.0 → 0.39.0-alpha.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.
@@ -4,3 +4,28 @@ export declare class DynamoDbClientError extends Error {
4
4
  cause?: unknown;
5
5
  });
6
6
  }
7
+ export type TransactionCanceledCheck = {
8
+ index: number;
9
+ code: string;
10
+ };
11
+ export type TransactionCanceledCheckBuilder = {
12
+ atIndex(index: number): TransactionCanceledCheck;
13
+ };
14
+ export declare const ConditionalCheckFailed: TransactionCanceledCheckBuilder;
15
+ /**
16
+ * Returns whether the provided error is *caused* by a {@link TransactionCanceledException}
17
+ * with the given code at the given index as cancellation reason.
18
+ *
19
+ * It first starts by looking for a {@link TransactionCanceledException} in the causal chain
20
+ * using {@link @infra-blocks/error#findCauseByType}. If none is found, it returns false.
21
+ * If one is found, it returns whether the cancellation reason at the given index
22
+ * matches the given code.
23
+ *
24
+ * @param err - The error to inspect.
25
+ * @param params.index - The index amongst the cancellation reasons to inspect.
26
+ * @param params.code - The code to match against.
27
+ *
28
+ * @returns Whether the error is caused by a {@link TransactionCanceledException}
29
+ * with the given code at the given index as cancellation reason.
30
+ */
31
+ export declare function isTransactionCanceledBy(err: unknown, params: TransactionCanceledCheck): boolean;
package/lib/cjs/error.js CHANGED
@@ -1,44 +1,47 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.DynamoDbClientError = exports.TransactionInProgressException = exports.TransactionConflictException = exports.TransactionCanceledException = exports.TableNotFoundException = exports.TableInUseException = exports.TableAlreadyExistsException = exports.ResourceNotFoundException = exports.ResourceInUseException = exports.RequestLimitExceeded = exports.ReplicatedWriteConflictException = exports.ReplicaNotFoundException = exports.ReplicaAlreadyExistsException = exports.ProvisionedThroughputExceededException = exports.PolicyNotFoundException = exports.PointInTimeRecoveryUnavailableException = exports.LimitExceededException = exports.ItemCollectionSizeLimitExceededException = exports.InvalidRestoreTimeException = exports.InvalidExportTimeException = exports.InvalidEndpointException = exports.InternalServerError = exports.IndexNotFoundException = exports.ImportNotFoundException = exports.ImportConflictException = exports.IdempotentParameterMismatchException = exports.GlobalTableNotFoundException = exports.GlobalTableAlreadyExistsException = exports.ExportNotFoundException = exports.ExportConflictException = exports.DuplicateItemException = exports.ContinuousBackupsUnavailableException = exports.ConditionalCheckFailedException = exports.BatchStatementErrorCodeEnum = exports.BackupNotFoundException = exports.BackupInUseException = void 0;
3
+ exports.ConditionalCheckFailed = exports.DynamoDbClientError = exports.TransactionInProgressException = exports.TransactionConflictException = exports.TransactionCanceledException = exports.TableNotFoundException = exports.TableInUseException = exports.TableAlreadyExistsException = exports.ResourceNotFoundException = exports.ResourceInUseException = exports.RequestLimitExceeded = exports.ReplicatedWriteConflictException = exports.ReplicaNotFoundException = exports.ReplicaAlreadyExistsException = exports.ProvisionedThroughputExceededException = exports.PolicyNotFoundException = exports.PointInTimeRecoveryUnavailableException = exports.LimitExceededException = exports.ItemCollectionSizeLimitExceededException = exports.InvalidRestoreTimeException = exports.InvalidExportTimeException = exports.InvalidEndpointException = exports.InternalServerError = exports.IndexNotFoundException = exports.ImportNotFoundException = exports.ImportConflictException = exports.IdempotentParameterMismatchException = exports.GlobalTableNotFoundException = exports.GlobalTableAlreadyExistsException = exports.ExportNotFoundException = exports.ExportConflictException = exports.DuplicateItemException = exports.ContinuousBackupsUnavailableException = exports.ConditionalCheckFailedException = exports.BatchStatementErrorCodeEnum = exports.BackupNotFoundException = exports.BackupInUseException = void 0;
4
+ exports.isTransactionCanceledBy = isTransactionCanceledBy;
5
+ const client_dynamodb_1 = require("@aws-sdk/client-dynamodb");
6
+ const error_1 = require("@infra-blocks/error");
4
7
  // Those are missing the ThrottlingException and the ValidationException mentioned in the documentations.
5
8
  // They aren't exported by the AWS package at the time of this writing.
6
- var client_dynamodb_1 = require("@aws-sdk/client-dynamodb");
7
- Object.defineProperty(exports, "BackupInUseException", { enumerable: true, get: function () { return client_dynamodb_1.BackupInUseException; } });
8
- Object.defineProperty(exports, "BackupNotFoundException", { enumerable: true, get: function () { return client_dynamodb_1.BackupNotFoundException; } });
9
- Object.defineProperty(exports, "BatchStatementErrorCodeEnum", { enumerable: true, get: function () { return client_dynamodb_1.BatchStatementErrorCodeEnum; } });
10
- Object.defineProperty(exports, "ConditionalCheckFailedException", { enumerable: true, get: function () { return client_dynamodb_1.ConditionalCheckFailedException; } });
11
- Object.defineProperty(exports, "ContinuousBackupsUnavailableException", { enumerable: true, get: function () { return client_dynamodb_1.ContinuousBackupsUnavailableException; } });
12
- Object.defineProperty(exports, "DuplicateItemException", { enumerable: true, get: function () { return client_dynamodb_1.DuplicateItemException; } });
13
- Object.defineProperty(exports, "ExportConflictException", { enumerable: true, get: function () { return client_dynamodb_1.ExportConflictException; } });
14
- Object.defineProperty(exports, "ExportNotFoundException", { enumerable: true, get: function () { return client_dynamodb_1.ExportNotFoundException; } });
15
- Object.defineProperty(exports, "GlobalTableAlreadyExistsException", { enumerable: true, get: function () { return client_dynamodb_1.GlobalTableAlreadyExistsException; } });
16
- Object.defineProperty(exports, "GlobalTableNotFoundException", { enumerable: true, get: function () { return client_dynamodb_1.GlobalTableNotFoundException; } });
17
- Object.defineProperty(exports, "IdempotentParameterMismatchException", { enumerable: true, get: function () { return client_dynamodb_1.IdempotentParameterMismatchException; } });
18
- Object.defineProperty(exports, "ImportConflictException", { enumerable: true, get: function () { return client_dynamodb_1.ImportConflictException; } });
19
- Object.defineProperty(exports, "ImportNotFoundException", { enumerable: true, get: function () { return client_dynamodb_1.ImportNotFoundException; } });
20
- Object.defineProperty(exports, "IndexNotFoundException", { enumerable: true, get: function () { return client_dynamodb_1.IndexNotFoundException; } });
21
- Object.defineProperty(exports, "InternalServerError", { enumerable: true, get: function () { return client_dynamodb_1.InternalServerError; } });
22
- Object.defineProperty(exports, "InvalidEndpointException", { enumerable: true, get: function () { return client_dynamodb_1.InvalidEndpointException; } });
23
- Object.defineProperty(exports, "InvalidExportTimeException", { enumerable: true, get: function () { return client_dynamodb_1.InvalidExportTimeException; } });
24
- Object.defineProperty(exports, "InvalidRestoreTimeException", { enumerable: true, get: function () { return client_dynamodb_1.InvalidRestoreTimeException; } });
25
- Object.defineProperty(exports, "ItemCollectionSizeLimitExceededException", { enumerable: true, get: function () { return client_dynamodb_1.ItemCollectionSizeLimitExceededException; } });
26
- Object.defineProperty(exports, "LimitExceededException", { enumerable: true, get: function () { return client_dynamodb_1.LimitExceededException; } });
27
- Object.defineProperty(exports, "PointInTimeRecoveryUnavailableException", { enumerable: true, get: function () { return client_dynamodb_1.PointInTimeRecoveryUnavailableException; } });
28
- Object.defineProperty(exports, "PolicyNotFoundException", { enumerable: true, get: function () { return client_dynamodb_1.PolicyNotFoundException; } });
29
- Object.defineProperty(exports, "ProvisionedThroughputExceededException", { enumerable: true, get: function () { return client_dynamodb_1.ProvisionedThroughputExceededException; } });
30
- Object.defineProperty(exports, "ReplicaAlreadyExistsException", { enumerable: true, get: function () { return client_dynamodb_1.ReplicaAlreadyExistsException; } });
31
- Object.defineProperty(exports, "ReplicaNotFoundException", { enumerable: true, get: function () { return client_dynamodb_1.ReplicaNotFoundException; } });
32
- Object.defineProperty(exports, "ReplicatedWriteConflictException", { enumerable: true, get: function () { return client_dynamodb_1.ReplicatedWriteConflictException; } });
33
- Object.defineProperty(exports, "RequestLimitExceeded", { enumerable: true, get: function () { return client_dynamodb_1.RequestLimitExceeded; } });
34
- Object.defineProperty(exports, "ResourceInUseException", { enumerable: true, get: function () { return client_dynamodb_1.ResourceInUseException; } });
35
- Object.defineProperty(exports, "ResourceNotFoundException", { enumerable: true, get: function () { return client_dynamodb_1.ResourceNotFoundException; } });
36
- Object.defineProperty(exports, "TableAlreadyExistsException", { enumerable: true, get: function () { return client_dynamodb_1.TableAlreadyExistsException; } });
37
- Object.defineProperty(exports, "TableInUseException", { enumerable: true, get: function () { return client_dynamodb_1.TableInUseException; } });
38
- Object.defineProperty(exports, "TableNotFoundException", { enumerable: true, get: function () { return client_dynamodb_1.TableNotFoundException; } });
39
- Object.defineProperty(exports, "TransactionCanceledException", { enumerable: true, get: function () { return client_dynamodb_1.TransactionCanceledException; } });
40
- Object.defineProperty(exports, "TransactionConflictException", { enumerable: true, get: function () { return client_dynamodb_1.TransactionConflictException; } });
41
- Object.defineProperty(exports, "TransactionInProgressException", { enumerable: true, get: function () { return client_dynamodb_1.TransactionInProgressException; } });
9
+ var client_dynamodb_2 = require("@aws-sdk/client-dynamodb");
10
+ Object.defineProperty(exports, "BackupInUseException", { enumerable: true, get: function () { return client_dynamodb_2.BackupInUseException; } });
11
+ Object.defineProperty(exports, "BackupNotFoundException", { enumerable: true, get: function () { return client_dynamodb_2.BackupNotFoundException; } });
12
+ Object.defineProperty(exports, "BatchStatementErrorCodeEnum", { enumerable: true, get: function () { return client_dynamodb_2.BatchStatementErrorCodeEnum; } });
13
+ Object.defineProperty(exports, "ConditionalCheckFailedException", { enumerable: true, get: function () { return client_dynamodb_2.ConditionalCheckFailedException; } });
14
+ Object.defineProperty(exports, "ContinuousBackupsUnavailableException", { enumerable: true, get: function () { return client_dynamodb_2.ContinuousBackupsUnavailableException; } });
15
+ Object.defineProperty(exports, "DuplicateItemException", { enumerable: true, get: function () { return client_dynamodb_2.DuplicateItemException; } });
16
+ Object.defineProperty(exports, "ExportConflictException", { enumerable: true, get: function () { return client_dynamodb_2.ExportConflictException; } });
17
+ Object.defineProperty(exports, "ExportNotFoundException", { enumerable: true, get: function () { return client_dynamodb_2.ExportNotFoundException; } });
18
+ Object.defineProperty(exports, "GlobalTableAlreadyExistsException", { enumerable: true, get: function () { return client_dynamodb_2.GlobalTableAlreadyExistsException; } });
19
+ Object.defineProperty(exports, "GlobalTableNotFoundException", { enumerable: true, get: function () { return client_dynamodb_2.GlobalTableNotFoundException; } });
20
+ Object.defineProperty(exports, "IdempotentParameterMismatchException", { enumerable: true, get: function () { return client_dynamodb_2.IdempotentParameterMismatchException; } });
21
+ Object.defineProperty(exports, "ImportConflictException", { enumerable: true, get: function () { return client_dynamodb_2.ImportConflictException; } });
22
+ Object.defineProperty(exports, "ImportNotFoundException", { enumerable: true, get: function () { return client_dynamodb_2.ImportNotFoundException; } });
23
+ Object.defineProperty(exports, "IndexNotFoundException", { enumerable: true, get: function () { return client_dynamodb_2.IndexNotFoundException; } });
24
+ Object.defineProperty(exports, "InternalServerError", { enumerable: true, get: function () { return client_dynamodb_2.InternalServerError; } });
25
+ Object.defineProperty(exports, "InvalidEndpointException", { enumerable: true, get: function () { return client_dynamodb_2.InvalidEndpointException; } });
26
+ Object.defineProperty(exports, "InvalidExportTimeException", { enumerable: true, get: function () { return client_dynamodb_2.InvalidExportTimeException; } });
27
+ Object.defineProperty(exports, "InvalidRestoreTimeException", { enumerable: true, get: function () { return client_dynamodb_2.InvalidRestoreTimeException; } });
28
+ Object.defineProperty(exports, "ItemCollectionSizeLimitExceededException", { enumerable: true, get: function () { return client_dynamodb_2.ItemCollectionSizeLimitExceededException; } });
29
+ Object.defineProperty(exports, "LimitExceededException", { enumerable: true, get: function () { return client_dynamodb_2.LimitExceededException; } });
30
+ Object.defineProperty(exports, "PointInTimeRecoveryUnavailableException", { enumerable: true, get: function () { return client_dynamodb_2.PointInTimeRecoveryUnavailableException; } });
31
+ Object.defineProperty(exports, "PolicyNotFoundException", { enumerable: true, get: function () { return client_dynamodb_2.PolicyNotFoundException; } });
32
+ Object.defineProperty(exports, "ProvisionedThroughputExceededException", { enumerable: true, get: function () { return client_dynamodb_2.ProvisionedThroughputExceededException; } });
33
+ Object.defineProperty(exports, "ReplicaAlreadyExistsException", { enumerable: true, get: function () { return client_dynamodb_2.ReplicaAlreadyExistsException; } });
34
+ Object.defineProperty(exports, "ReplicaNotFoundException", { enumerable: true, get: function () { return client_dynamodb_2.ReplicaNotFoundException; } });
35
+ Object.defineProperty(exports, "ReplicatedWriteConflictException", { enumerable: true, get: function () { return client_dynamodb_2.ReplicatedWriteConflictException; } });
36
+ Object.defineProperty(exports, "RequestLimitExceeded", { enumerable: true, get: function () { return client_dynamodb_2.RequestLimitExceeded; } });
37
+ Object.defineProperty(exports, "ResourceInUseException", { enumerable: true, get: function () { return client_dynamodb_2.ResourceInUseException; } });
38
+ Object.defineProperty(exports, "ResourceNotFoundException", { enumerable: true, get: function () { return client_dynamodb_2.ResourceNotFoundException; } });
39
+ Object.defineProperty(exports, "TableAlreadyExistsException", { enumerable: true, get: function () { return client_dynamodb_2.TableAlreadyExistsException; } });
40
+ Object.defineProperty(exports, "TableInUseException", { enumerable: true, get: function () { return client_dynamodb_2.TableInUseException; } });
41
+ Object.defineProperty(exports, "TableNotFoundException", { enumerable: true, get: function () { return client_dynamodb_2.TableNotFoundException; } });
42
+ Object.defineProperty(exports, "TransactionCanceledException", { enumerable: true, get: function () { return client_dynamodb_2.TransactionCanceledException; } });
43
+ Object.defineProperty(exports, "TransactionConflictException", { enumerable: true, get: function () { return client_dynamodb_2.TransactionConflictException; } });
44
+ Object.defineProperty(exports, "TransactionInProgressException", { enumerable: true, get: function () { return client_dynamodb_2.TransactionInProgressException; } });
42
45
  class DynamoDbClientError extends Error {
43
46
  constructor(message, options) {
44
47
  super(message, options);
@@ -46,4 +49,33 @@ class DynamoDbClientError extends Error {
46
49
  }
47
50
  }
48
51
  exports.DynamoDbClientError = DynamoDbClientError;
52
+ exports.ConditionalCheckFailed = {
53
+ atIndex(index) {
54
+ return { index, code: "ConditionalCheckFailed" };
55
+ },
56
+ };
57
+ /**
58
+ * Returns whether the provided error is *caused* by a {@link TransactionCanceledException}
59
+ * with the given code at the given index as cancellation reason.
60
+ *
61
+ * It first starts by looking for a {@link TransactionCanceledException} in the causal chain
62
+ * using {@link @infra-blocks/error#findCauseByType}. If none is found, it returns false.
63
+ * If one is found, it returns whether the cancellation reason at the given index
64
+ * matches the given code.
65
+ *
66
+ * @param err - The error to inspect.
67
+ * @param params.index - The index amongst the cancellation reasons to inspect.
68
+ * @param params.code - The code to match against.
69
+ *
70
+ * @returns Whether the error is caused by a {@link TransactionCanceledException}
71
+ * with the given code at the given index as cancellation reason.
72
+ */
73
+ function isTransactionCanceledBy(err, params) {
74
+ const { index, code } = params;
75
+ const transactionError = (0, error_1.findCauseByType)(err, client_dynamodb_1.TransactionCanceledException);
76
+ if (transactionError == null) {
77
+ return false;
78
+ }
79
+ return transactionError.CancellationReasons?.[index].Code === code;
80
+ }
49
81
  //# sourceMappingURL=error.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"error.js","sourceRoot":"","sources":["../../src/error.ts"],"names":[],"mappings":";;;AAAA,yGAAyG;AACzG,uEAAuE;AACvE,4DAsCkC;AArChC,uHAAA,oBAAoB,OAAA;AACpB,0HAAA,uBAAuB,OAAA;AAEvB,8HAAA,2BAA2B,OAAA;AAC3B,kIAAA,+BAA+B,OAAA;AAC/B,wIAAA,qCAAqC,OAAA;AACrC,yHAAA,sBAAsB,OAAA;AACtB,0HAAA,uBAAuB,OAAA;AACvB,0HAAA,uBAAuB,OAAA;AAEvB,oIAAA,iCAAiC,OAAA;AACjC,+HAAA,4BAA4B,OAAA;AAC5B,uIAAA,oCAAoC,OAAA;AACpC,0HAAA,uBAAuB,OAAA;AACvB,0HAAA,uBAAuB,OAAA;AACvB,yHAAA,sBAAsB,OAAA;AACtB,sHAAA,mBAAmB,OAAA;AACnB,2HAAA,wBAAwB,OAAA;AACxB,6HAAA,0BAA0B,OAAA;AAC1B,8HAAA,2BAA2B,OAAA;AAC3B,2IAAA,wCAAwC,OAAA;AACxC,yHAAA,sBAAsB,OAAA;AACtB,0IAAA,uCAAuC,OAAA;AACvC,0HAAA,uBAAuB,OAAA;AACvB,yIAAA,sCAAsC,OAAA;AACtC,gIAAA,6BAA6B,OAAA;AAC7B,2HAAA,wBAAwB,OAAA;AACxB,mIAAA,gCAAgC,OAAA;AAChC,uHAAA,oBAAoB,OAAA;AACpB,yHAAA,sBAAsB,OAAA;AACtB,4HAAA,yBAAyB,OAAA;AACzB,8HAAA,2BAA2B,OAAA;AAC3B,sHAAA,mBAAmB,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AA,sBAAsB,OAAA;AACtB,4HAAA,yBAAyB,OAAA;AACzB,8HAAA,2BAA2B,OAAA;AAC3B,sHAAA,mBAAmB,OAAA;AACnB,yHAAA,sBAAsB,OAAA;AACtB,+HAAA,4BAA4B,OAAA;AAC5B,+HAAA,4BAA4B,OAAA;AAC5B,iIAAA,8BAA8B,OAAA;AAGhC,MAAa,mBAAoB,SAAQ,KAAK;IAC5C,YAAY,OAAe,EAAE,OAA6B;QACxD,KAAK,CAAC,OAAO,EAAE,OAAO,CAAC,CAAC;QACxB,IAAI,CAAC,IAAI,GAAG,qBAAqB,CAAC;IACpC,CAAC;CACF;AALD,kDAKC;AAWY,QAAA,sBAAsB,GAAoC;IACrE,OAAO,CAAC,KAAa;QACnB,OAAO,EAAE,KAAK,EAAE,IAAI,EAAE,wBAAwB,EAAE,CAAC;IACnD,CAAC;CACF,CAAC;AAEF;;;;;;;;;;;;;;;GAeG;AACH,SAAgB,uBAAuB,CACrC,GAAY,EACZ,MAAgC;IAEhC,MAAM,EAAE,KAAK,EAAE,IAAI,EAAE,GAAG,MAAM,CAAC;IAC/B,MAAM,gBAAgB,GAAG,IAAA,uBAAe,EAAC,GAAG,EAAE,8CAA4B,CAAC,CAAC;IAC5E,IAAI,gBAAgB,IAAI,IAAI,EAAE,CAAC;QAC7B,OAAO,KAAK,CAAC;IACf,CAAC;IACD,OAAO,gBAAgB,CAAC,mBAAmB,EAAE,CAAC,KAAK,CAAC,CAAC,IAAI,KAAK,IAAI,CAAC;AACrE,CAAC"}
@@ -4,3 +4,28 @@ export declare class DynamoDbClientError extends Error {
4
4
  cause?: unknown;
5
5
  });
6
6
  }
7
+ export type TransactionCanceledCheck = {
8
+ index: number;
9
+ code: string;
10
+ };
11
+ export type TransactionCanceledCheckBuilder = {
12
+ atIndex(index: number): TransactionCanceledCheck;
13
+ };
14
+ export declare const ConditionalCheckFailed: TransactionCanceledCheckBuilder;
15
+ /**
16
+ * Returns whether the provided error is *caused* by a {@link TransactionCanceledException}
17
+ * with the given code at the given index as cancellation reason.
18
+ *
19
+ * It first starts by looking for a {@link TransactionCanceledException} in the causal chain
20
+ * using {@link @infra-blocks/error#findCauseByType}. If none is found, it returns false.
21
+ * If one is found, it returns whether the cancellation reason at the given index
22
+ * matches the given code.
23
+ *
24
+ * @param err - The error to inspect.
25
+ * @param params.index - The index amongst the cancellation reasons to inspect.
26
+ * @param params.code - The code to match against.
27
+ *
28
+ * @returns Whether the error is caused by a {@link TransactionCanceledException}
29
+ * with the given code at the given index as cancellation reason.
30
+ */
31
+ export declare function isTransactionCanceledBy(err: unknown, params: TransactionCanceledCheck): boolean;
package/lib/esm/error.js CHANGED
@@ -1,3 +1,5 @@
1
+ import { TransactionCanceledException } from "@aws-sdk/client-dynamodb";
2
+ import { findCauseByType } from "@infra-blocks/error";
1
3
  // Those are missing the ThrottlingException and the ValidationException mentioned in the documentations.
2
4
  // They aren't exported by the AWS package at the time of this writing.
3
5
  export { BackupInUseException, BackupNotFoundException, BatchStatementErrorCodeEnum, ConditionalCheckFailedException, ContinuousBackupsUnavailableException, DuplicateItemException, ExportConflictException, ExportNotFoundException, GlobalTableAlreadyExistsException, GlobalTableNotFoundException, IdempotentParameterMismatchException, ImportConflictException, ImportNotFoundException, IndexNotFoundException, InternalServerError, InvalidEndpointException, InvalidExportTimeException, InvalidRestoreTimeException, ItemCollectionSizeLimitExceededException, LimitExceededException, PointInTimeRecoveryUnavailableException, PolicyNotFoundException, ProvisionedThroughputExceededException, ReplicaAlreadyExistsException, ReplicaNotFoundException, ReplicatedWriteConflictException, RequestLimitExceeded, ResourceInUseException, ResourceNotFoundException, TableAlreadyExistsException, TableInUseException, TableNotFoundException, TransactionCanceledException, TransactionConflictException, TransactionInProgressException, } from "@aws-sdk/client-dynamodb";
@@ -7,4 +9,33 @@ export class DynamoDbClientError extends Error {
7
9
  this.name = "DynamoDbClientError";
8
10
  }
9
11
  }
12
+ export const ConditionalCheckFailed = {
13
+ atIndex(index) {
14
+ return { index, code: "ConditionalCheckFailed" };
15
+ },
16
+ };
17
+ /**
18
+ * Returns whether the provided error is *caused* by a {@link TransactionCanceledException}
19
+ * with the given code at the given index as cancellation reason.
20
+ *
21
+ * It first starts by looking for a {@link TransactionCanceledException} in the causal chain
22
+ * using {@link @infra-blocks/error#findCauseByType}. If none is found, it returns false.
23
+ * If one is found, it returns whether the cancellation reason at the given index
24
+ * matches the given code.
25
+ *
26
+ * @param err - The error to inspect.
27
+ * @param params.index - The index amongst the cancellation reasons to inspect.
28
+ * @param params.code - The code to match against.
29
+ *
30
+ * @returns Whether the error is caused by a {@link TransactionCanceledException}
31
+ * with the given code at the given index as cancellation reason.
32
+ */
33
+ export function isTransactionCanceledBy(err, params) {
34
+ const { index, code } = params;
35
+ const transactionError = findCauseByType(err, TransactionCanceledException);
36
+ if (transactionError == null) {
37
+ return false;
38
+ }
39
+ return transactionError.CancellationReasons?.[index].Code === code;
40
+ }
10
41
  //# sourceMappingURL=error.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"error.js","sourceRoot":"","sources":["../../src/error.ts"],"names":[],"mappings":"AAAA,yGAAyG;AACzG,uEAAuE;AACvE,OAAO,EACL,oBAAoB,EACpB,uBAAuB,EAEvB,2BAA2B,EAC3B,+BAA+B,EAC/B,qCAAqC,EACrC,sBAAsB,EACtB,uBAAuB,EACvB,uBAAuB,EAEvB,iCAAiC,EACjC,4BAA4B,EAC5B,oCAAoC,EACpC,uBAAuB,EACvB,uBAAuB,EACvB,sBAAsB,EACtB,mBAAmB,EACnB,wBAAwB,EACxB,0BAA0B,EAC1B,2BAA2B,EAC3B,wCAAwC,EACxC,sBAAsB,EACtB,uCAAuC,EACvC,uBAAuB,EACvB,sCAAsC,EACtC,6BAA6B,EAC7B,wBAAwB,EACxB,gCAAgC,EAChC,oBAAoB,EACpB,sBAAsB,EACtB,yBAAyB,EACzB,2BAA2B,EAC3B,mBAAmB,EACnB,sBAAsB,EACtB,4BAA4B,EAC5B,4BAA4B,EAC5B,8BAA8B,GAC/B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E,IAAI,EAAE,wBAAwB,EAAE,CAAC;IACnD,CAAC;CACF,CAAC;AAEF;;;;;;;;;;;;;;;GAeG;AACH,MAAM,UAAU,uBAAuB,CACrC,GAAY,EACZ,MAAgC;IAEhC,MAAM,EAAE,KAAK,EAAE,IAAI,EAAE,GAAG,MAAM,CAAC;IAC/B,MAAM,gBAAgB,GAAG,eAAe,CAAC,GAAG,EAAE,4BAA4B,CAAC,CAAC;IAC5E,IAAI,gBAAgB,IAAI,IAAI,EAAE,CAAC;QAC7B,OAAO,KAAK,CAAC;IACf,CAAC;IACD,OAAO,gBAAgB,CAAC,mBAAmB,EAAE,CAAC,KAAK,CAAC,CAAC,IAAI,KAAK,IAAI,CAAC;AACrE,CAAC"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@infra-blocks/aws-dynamodb",
3
- "version": "0.38.0-alpha.0",
3
+ "version": "0.39.0-alpha.0",
4
4
  "description": "A convenience wrapper over @aws-sdk/client-dynamodb and @aws-sdk/lib-dynamodb.",
5
5
  "keywords": [
6
6
  "aws",
@@ -42,7 +42,6 @@
42
42
  "devDependencies": {
43
43
  "@biomejs/biome": "^2.1.2",
44
44
  "@infra-blocks/checks": "^0.2.7",
45
- "@infra-blocks/error": "^0.1.0",
46
45
  "@infra-blocks/iter": "^0.2.7",
47
46
  "@infra-blocks/node-console-logger": "^0.3.1",
48
47
  "@infra-blocks/test": "^0.4.0",
@@ -63,6 +62,7 @@
63
62
  "dependencies": {
64
63
  "@aws-sdk/client-dynamodb": "^3.840.0",
65
64
  "@aws-sdk/lib-dynamodb": "^3.840.0",
65
+ "@infra-blocks/error": "^0.2.0",
66
66
  "@infra-blocks/logger-interface": "^0.3.1",
67
67
  "@infra-blocks/null-logger": "^0.1.1",
68
68
  "@infra-blocks/retry": "^0.1.1",