@eresearchqut/ddb-repository 1.4.1 → 1.5.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.
package/CHANGELOG.md
CHANGED
|
@@ -1,3 +1,10 @@
|
|
|
1
|
+
# [1.5.0](https://github.com/eresearchqut/ddb-repository/compare/v1.4.1...v1.5.0) (2025-11-21)
|
|
2
|
+
|
|
3
|
+
|
|
4
|
+
### Features
|
|
5
|
+
|
|
6
|
+
* Initialise the repository using options ([e3a2f46](https://github.com/eresearchqut/ddb-repository/commit/e3a2f46d3a8fb0ca467409369eef505d0451b6b0))
|
|
7
|
+
|
|
1
8
|
## [1.4.1](https://github.com/eresearchqut/ddb-repository/compare/v1.4.0...v1.4.1) (2025-11-21)
|
|
2
9
|
|
|
3
10
|
|
|
@@ -78,12 +78,8 @@ const paginate = (array, pageSize) => {
|
|
|
78
78
|
}, []);
|
|
79
79
|
};
|
|
80
80
|
class DynamoDbRepository {
|
|
81
|
-
constructor(
|
|
82
|
-
|
|
83
|
-
this.tableName = tableName;
|
|
84
|
-
this.hashKey = hashKey;
|
|
85
|
-
this.rangKey = rangKey;
|
|
86
|
-
this.returnConsumedCapacity = returnConsumedCapacity;
|
|
81
|
+
constructor(options) {
|
|
82
|
+
var _a;
|
|
87
83
|
this.getItem = (key) => __awaiter(this, void 0, void 0, function* () {
|
|
88
84
|
return this.dynamoDBClient
|
|
89
85
|
.send(new client_dynamodb_1.GetItemCommand({
|
|
@@ -238,6 +234,11 @@ class DynamoDbRepository {
|
|
|
238
234
|
}))))
|
|
239
235
|
.then((itemSets) => itemSets.flat());
|
|
240
236
|
});
|
|
237
|
+
this.dynamoDBClient = options.client;
|
|
238
|
+
this.tableName = options.tableName;
|
|
239
|
+
this.hashKey = options.hashKey;
|
|
240
|
+
this.rangKey = options.rangeKey;
|
|
241
|
+
this.returnConsumedCapacity = (_a = options.returnConsumedCapacity) !== null && _a !== void 0 ? _a : client_dynamodb_1.ReturnConsumedCapacity.TOTAL;
|
|
241
242
|
}
|
|
242
243
|
}
|
|
243
244
|
exports.DynamoDbRepository = DynamoDbRepository;
|
package/package.json
CHANGED
|
@@ -118,16 +118,27 @@ const paginate = <T>(array: Array<T>, pageSize: number) => {
|
|
|
118
118
|
}, [] as Array<Array<T>>);
|
|
119
119
|
}
|
|
120
120
|
|
|
121
|
-
export
|
|
121
|
+
export interface DynamoDbRepositoryOptions {
|
|
122
|
+
client: DynamoDBClient;
|
|
123
|
+
tableName: string;
|
|
124
|
+
hashKey: string;
|
|
125
|
+
rangeKey?: string;
|
|
126
|
+
returnConsumedCapacity?: ReturnConsumedCapacity;
|
|
127
|
+
}
|
|
122
128
|
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
) {
|
|
129
|
+
export class DynamoDbRepository<K, T> {
|
|
130
|
+
private readonly dynamoDBClient: DynamoDBClient;
|
|
131
|
+
private readonly tableName: string;
|
|
132
|
+
private readonly hashKey: string;
|
|
133
|
+
private readonly rangKey?: string;
|
|
134
|
+
private readonly returnConsumedCapacity: ReturnConsumedCapacity | undefined;
|
|
130
135
|
|
|
136
|
+
constructor(options: DynamoDbRepositoryOptions) {
|
|
137
|
+
this.dynamoDBClient = options.client;
|
|
138
|
+
this.tableName = options.tableName;
|
|
139
|
+
this.hashKey = options.hashKey;
|
|
140
|
+
this.rangKey = options.rangeKey;
|
|
141
|
+
this.returnConsumedCapacity = options.returnConsumedCapacity ?? ReturnConsumedCapacity.TOTAL;
|
|
131
142
|
}
|
|
132
143
|
|
|
133
144
|
getItem = async (key: K): Promise<T | undefined> => {
|
|
@@ -120,9 +120,23 @@ describe('DynamoDbRepository Integration Tests', () => {
|
|
|
120
120
|
}
|
|
121
121
|
|
|
122
122
|
// Initialize repositories
|
|
123
|
-
repository = new DynamoDbRepository(
|
|
124
|
-
|
|
125
|
-
|
|
123
|
+
repository = new DynamoDbRepository({
|
|
124
|
+
client: dynamoDBClient,
|
|
125
|
+
tableName: tableName,
|
|
126
|
+
hashKey: "id"
|
|
127
|
+
});
|
|
128
|
+
compositeRepository = new DynamoDbRepository({
|
|
129
|
+
client: dynamoDBClient,
|
|
130
|
+
tableName: compositeTableName,
|
|
131
|
+
hashKey: "userId",
|
|
132
|
+
rangeKey: "itemId"
|
|
133
|
+
});
|
|
134
|
+
gsiRepository = new DynamoDbRepository({
|
|
135
|
+
client: dynamoDBClient,
|
|
136
|
+
tableName: gsiTableName,
|
|
137
|
+
hashKey: "userId",
|
|
138
|
+
rangeKey: "itemId"
|
|
139
|
+
});
|
|
126
140
|
});
|
|
127
141
|
|
|
128
142
|
beforeEach(async () => {
|