@eresearchqut/ddb-repository 1.0.2 → 1.2.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.
@@ -1,4 +1,4 @@
1
- name: Publish
1
+ name: Release
2
2
 
3
3
  on:
4
4
  push:
package/CHANGELOG.md CHANGED
@@ -1,23 +1,13 @@
1
- ## [1.0.2](https://github.com/eresearchqut/ddb-repository/compare/v1.0.1...v1.0.2) (2025-11-19)
1
+ # [1.2.0](https://github.com/eresearchqut/ddb-repository/compare/v1.1.0...v1.2.0) (2025-11-19)
2
2
 
3
3
 
4
- ### Bug Fixes
5
-
6
- * setting publish config access to public ([eed3a3b](https://github.com/eresearchqut/ddb-repository/commit/eed3a3b382153c457e3508d844e111b7f5b3123d))
7
-
8
- ## [1.0.1](https://github.com/eresearchqut/ddb-repository/compare/v1.0.0...v1.0.1) (2025-11-19)
9
-
10
-
11
- ### Bug Fixes
4
+ ### Features
12
5
 
13
- * remove npm registry url from the node setup as per comments on https://github.com/semantic-release/semantic-release/issues/2313 ([291d61b](https://github.com/eresearchqut/ddb-repository/commit/291d61b55c3c5c665623c264306c40e1c21977a2))
14
- * Repository and package are now public ([b07f151](https://github.com/eresearchqut/ddb-repository/commit/b07f151732f8a158a2b6f0a584e64ea9eb7f5825))
15
- * updated secret name for GITHUB_TOKEN ([7e00208](https://github.com/eresearchqut/ddb-repository/commit/7e00208f487f5987e72646c15a50fe78808f6ba4))
16
- * updated secret name for GITHUB_TOKEN ([6d3eff2](https://github.com/eresearchqut/ddb-repository/commit/6d3eff2fff43f0d0848cfc03b7e035d830a3ceb5))
6
+ * return the consumed capacity for each operation ([3910953](https://github.com/eresearchqut/ddb-repository/commit/391095398381a950c3393f9103d97d355c119538))
17
7
 
18
- # 1.0.0 (2025-11-19)
8
+ # [1.1.0](https://github.com/eresearchqut/ddb-repository/compare/v1.0.2...v1.1.0) (2025-11-19)
19
9
 
20
10
 
21
11
  ### Features
22
12
 
23
- * coverage badge ([0f3c9d1](https://github.com/eresearchqut/ddb-repository/commit/0f3c9d128b25466758062ea9e41d1c7d755c2191))
13
+ * NPM Package Badge ([fecd958](https://github.com/eresearchqut/ddb-repository/commit/fecd958d0d3725e0fc19f43f36e00eb7e5437716))
package/README.md CHANGED
@@ -1,5 +1,6 @@
1
1
  # DynamoDB Repository
2
2
 
3
+ [![npm version](https://badge.fury.io/js/@eresearchqut%2Fddb-repository.svg)](https://badge.fury.io/js/@eresearchqut%2Fddb-repository)
3
4
  [![Coverage Status](https://coveralls.io/repos/github/eresearchqut/ddb-repository/badge.svg?branch=main)](https://coveralls.io/github/eresearchqut/ddb-repository?branch=main)
4
5
 
5
6
  A TypeScript library providing a generic repository pattern implementation for AWS DynamoDB, simplifying CRUD operations and common database interactions.
@@ -80,16 +80,18 @@ const paginate = (array, pageSize) => {
80
80
  }, []);
81
81
  };
82
82
  class DynamoDbRepository {
83
- constructor(dynamoDBClient, tableName, hashKey, rangKey) {
83
+ constructor(dynamoDBClient, tableName, hashKey, rangKey, returnConsumedCapacity = client_dynamodb_1.ReturnConsumedCapacity.TOTAL) {
84
84
  this.dynamoDBClient = dynamoDBClient;
85
85
  this.tableName = tableName;
86
86
  this.hashKey = hashKey;
87
87
  this.rangKey = rangKey;
88
+ this.returnConsumedCapacity = returnConsumedCapacity;
88
89
  this.getItem = (key) => __awaiter(this, void 0, void 0, function* () {
89
90
  return this.dynamoDBClient
90
91
  .send(new client_dynamodb_1.GetItemCommand({
91
92
  TableName: this.tableName,
92
93
  Key: (0, util_dynamodb_1.marshall)(key, { removeUndefinedValues: true }),
94
+ ReturnConsumedCapacity: this.returnConsumedCapacity,
93
95
  }))
94
96
  .then((result) => result.Item ? (0, util_dynamodb_1.unmarshall)(result.Item) : undefined);
95
97
  });
@@ -98,6 +100,7 @@ class DynamoDbRepository {
98
100
  return this.dynamoDBClient
99
101
  .send(new client_dynamodb_1.PutItemCommand({
100
102
  TableName: this.tableName,
103
+ ReturnConsumedCapacity: this.returnConsumedCapacity,
101
104
  Item,
102
105
  }))
103
106
  .then(() => this.getItem(key));
@@ -129,6 +132,7 @@ class DynamoDbRepository {
129
132
  .filter(([, value]) => value !== undefined)
130
133
  .reduce((acc, [key]) => (Object.assign(Object.assign({}, acc), { [`#${expressionAttributeKey(key)}`]: key })), Object.assign(removeAttributeNames)),
131
134
  ExpressionAttributeValues: hasUpdates ? (0, util_dynamodb_1.marshall)(Object.entries(updates).reduce((acc, [key, value]) => (Object.assign(Object.assign({}, acc), { [`:${expressionAttributeKey(key)}`]: value })), Object.assign({})), { removeUndefinedValues: true }) : undefined,
135
+ ReturnConsumedCapacity: this.returnConsumedCapacity,
132
136
  };
133
137
  return this.dynamoDBClient
134
138
  .send(new client_dynamodb_1.UpdateItemCommand(updateItemCommandInput))
@@ -160,6 +164,7 @@ class DynamoDbRepository {
160
164
  : {};
161
165
  const queryCommandInput = {
162
166
  TableName: this.tableName,
167
+ ReturnConsumedCapacity: this.returnConsumedCapacity,
163
168
  IndexName: index,
164
169
  KeyConditionExpression,
165
170
  FilterExpression,
@@ -226,9 +231,10 @@ class DynamoDbRepository {
226
231
  [this.tableName]: {
227
232
  Keys: keyPage.map((key) => ((0, util_dynamodb_1.marshall)(key))),
228
233
  ProjectionExpression,
229
- ExpressionAttributeNames
234
+ ExpressionAttributeNames,
230
235
  }
231
- }
236
+ },
237
+ ReturnConsumedCapacity: this.returnConsumedCapacity,
232
238
  };
233
239
  return this.dynamoDBClient.send(new client_dynamodb_1.BatchGetItemCommand(batchRequest)).then(result => { var _a; return (_a = result.Responses) === null || _a === void 0 ? void 0 : _a[this.tableName].map((item) => (0, util_dynamodb_1.unmarshall)(item)); });
234
240
  }))))
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@eresearchqut/ddb-repository",
3
- "version": "1.0.2",
3
+ "version": "1.2.0",
4
4
  "description": "",
5
5
  "type": "module",
6
6
  "main": "dist/index.js",
@@ -7,6 +7,7 @@ import {
7
7
  paginateQuery,
8
8
  PutItemCommand,
9
9
  QueryCommandInput,
10
+ ReturnConsumedCapacity,
10
11
  UpdateItemCommand,
11
12
  } from "@aws-sdk/client-dynamodb";
12
13
  import {marshall, unmarshall} from "@aws-sdk/util-dynamodb";
@@ -125,6 +126,7 @@ export class DynamoDbRepository<K, T> {
125
126
  private readonly tableName: string,
126
127
  private readonly hashKey: string,
127
128
  private readonly rangKey?: string,
129
+ private readonly returnConsumedCapacity: ReturnConsumedCapacity | undefined = ReturnConsumedCapacity.TOTAL,
128
130
  ) {
129
131
 
130
132
  }
@@ -135,6 +137,7 @@ export class DynamoDbRepository<K, T> {
135
137
  new GetItemCommand({
136
138
  TableName: this.tableName,
137
139
  Key: marshall(key, {removeUndefinedValues: true}),
140
+ ReturnConsumedCapacity: this.returnConsumedCapacity,
138
141
  }),
139
142
  )
140
143
  .then((result) =>
@@ -148,6 +151,7 @@ export class DynamoDbRepository<K, T> {
148
151
  .send(
149
152
  new PutItemCommand({
150
153
  TableName: this.tableName,
154
+ ReturnConsumedCapacity: this.returnConsumedCapacity,
151
155
  Item,
152
156
  }),
153
157
  )
@@ -215,6 +219,7 @@ export class DynamoDbRepository<K, T> {
215
219
  ),
216
220
  {removeUndefinedValues: true},
217
221
  ) : undefined,
222
+ ReturnConsumedCapacity: this.returnConsumedCapacity,
218
223
  };
219
224
  return this.dynamoDBClient
220
225
  .send(new UpdateItemCommand(updateItemCommandInput))
@@ -275,6 +280,7 @@ export class DynamoDbRepository<K, T> {
275
280
  : {};
276
281
  const queryCommandInput: QueryCommandInput = {
277
282
  TableName: this.tableName,
283
+ ReturnConsumedCapacity: this.returnConsumedCapacity,
278
284
  IndexName: index,
279
285
  KeyConditionExpression,
280
286
  FilterExpression,
@@ -348,9 +354,10 @@ export class DynamoDbRepository<K, T> {
348
354
  [this.tableName]: {
349
355
  Keys: keyPage.map((key) => (marshall(key))),
350
356
  ProjectionExpression,
351
- ExpressionAttributeNames
357
+ ExpressionAttributeNames,
352
358
  }
353
- }
359
+ },
360
+ ReturnConsumedCapacity: this.returnConsumedCapacity,
354
361
  }
355
362
  return this.dynamoDBClient.send(new BatchGetItemCommand(batchRequest)).then(result =>
356
363
  result.Responses?.[this.tableName].map((item) => unmarshall(item) as T));