@eresearchqut/ddb-repository 1.4.0 → 1.4.1

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.4.1](https://github.com/eresearchqut/ddb-repository/compare/v1.4.0...v1.4.1) (2025-11-21)
2
+
3
+
4
+ ### Bug Fixes
5
+
6
+ * Fix scope of internal methods ([c652753](https://github.com/eresearchqut/ddb-repository/commit/c652753156662fa08b818e0df068fbb2702881c9))
7
+
1
8
  # [1.4.0](https://github.com/eresearchqut/ddb-repository/compare/v1.3.0...v1.4.0) (2025-11-20)
2
9
 
3
10
 
@@ -27,11 +27,10 @@ var __asyncValues = (this && this.__asyncValues) || function (o) {
27
27
  function settle(resolve, reject, d, v) { Promise.resolve(v).then(function(v) { resolve({ value: v, done: d }); }, reject); }
28
28
  };
29
29
  Object.defineProperty(exports, "__esModule", { value: true });
30
- exports.DynamoDbRepository = exports.consumedCapacityMiddleware = exports.mapFilterExpressions = exports.mapFilterExpression = exports.FilterOperator = void 0;
30
+ exports.DynamoDbRepository = exports.FilterOperator = void 0;
31
31
  const client_dynamodb_1 = require("@aws-sdk/client-dynamodb");
32
32
  const util_dynamodb_1 = require("@aws-sdk/util-dynamodb");
33
33
  const lodash_1 = require("lodash");
34
- const expressionAttributeKey = (key) => (0, lodash_1.replace)(key, /-/g, "_");
35
34
  var FilterOperator;
36
35
  (function (FilterOperator) {
37
36
  FilterOperator["EQUALS"] = "=";
@@ -43,6 +42,7 @@ var FilterOperator;
43
42
  FilterOperator["IN"] = "IN";
44
43
  FilterOperator["BETWEEN"] = "BETWEEN";
45
44
  })(FilterOperator || (exports.FilterOperator = FilterOperator = {}));
45
+ const expressionAttributeKey = (key) => (0, lodash_1.replace)(key, /-/g, "_");
46
46
  const mapInKeys = (filterExpression) => Array.isArray(filterExpression.value)
47
47
  ? filterExpression.value.map((_, index) => `:${filterExpression.attribute}${index}`)
48
48
  : `:${filterExpression.attribute}`;
@@ -59,13 +59,11 @@ const mapFilterExpression = (filterExpression) => {
59
59
  `:${expressionAttributeKey(filterExpression.attribute)}`);
60
60
  }
61
61
  };
62
- exports.mapFilterExpression = mapFilterExpression;
63
62
  const mapFilterExpressions = (filterExpressions) => filterExpressions
64
63
  .map((filterExpression) => filterExpression.negate
65
- ? `NOT ${(0, exports.mapFilterExpression)(filterExpression)}`
66
- : (0, exports.mapFilterExpression)(filterExpression))
64
+ ? `NOT ${mapFilterExpression(filterExpression)}`
65
+ : mapFilterExpression(filterExpression))
67
66
  .join(" AND ");
68
- exports.mapFilterExpressions = mapFilterExpressions;
69
67
  const mapFilterExpressionValues = (filterExpression) => Array.isArray(filterExpression.value)
70
68
  ? filterExpression.value.reduce((reduction, value, index) => (Object.assign(Object.assign({}, reduction), { [`:${expressionAttributeKey(filterExpression.attribute)}${index}`]: value })), Object.assign({}))
71
69
  : {
@@ -79,21 +77,6 @@ const paginate = (array, pageSize) => {
79
77
  return acc;
80
78
  }, []);
81
79
  };
82
- const consumedCapacityMiddleware = (consumedCapacityMiddlewareConfig) => (next, context) => (args) => __awaiter(void 0, void 0, void 0, function* () {
83
- try {
84
- const { input } = args;
85
- const { ReturnConsumedCapacity } = input;
86
- const response = yield next(args);
87
- const { output } = response;
88
- const consumedCapacity = (0, lodash_1.get)(output, "ConsumedCapacity");
89
- yield consumedCapacityMiddlewareConfig.onConsumedCapacity({ ReturnConsumedCapacity, ConsumedCapacity: consumedCapacity });
90
- return response;
91
- }
92
- catch (error) {
93
- throw error;
94
- }
95
- });
96
- exports.consumedCapacityMiddleware = consumedCapacityMiddleware;
97
80
  class DynamoDbRepository {
98
81
  constructor(dynamoDBClient, tableName, hashKey, rangKey, returnConsumedCapacity = client_dynamodb_1.ReturnConsumedCapacity.TOTAL) {
99
82
  this.dynamoDBClient = dynamoDBClient;
@@ -169,7 +152,7 @@ class DynamoDbRepository {
169
152
  const projectionAttributeNames = !index && projectedAttributes ? projectedAttributes.reduce((reduction, attribute) => (Object.assign(Object.assign({}, reduction), { [`#${expressionAttributeKey(attribute)}`]: attribute })), Object.assign({})) : {};
170
153
  const hasFilterExpressions = Array.isArray(filterExpressions) && filterExpressions.length > 0;
171
154
  const FilterExpression = hasFilterExpressions
172
- ? (0, exports.mapFilterExpressions)(filterExpressions)
155
+ ? mapFilterExpressions(filterExpressions)
173
156
  : undefined;
174
157
  const filterAttributeNames = hasFilterExpressions
175
158
  ? filterExpressions.reduce((reduction, filterExpression) => (Object.assign(Object.assign({}, reduction), { [`#${expressionAttributeKey(filterExpression.attribute)}`]: filterExpression.attribute })), Object.assign({}))
@@ -0,0 +1,25 @@
1
+ "use strict";
2
+ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
3
+ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
4
+ return new (P || (P = Promise))(function (resolve, reject) {
5
+ function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
6
+ function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
7
+ function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
8
+ step((generator = generator.apply(thisArg, _arguments || [])).next());
9
+ });
10
+ };
11
+ Object.defineProperty(exports, "__esModule", { value: true });
12
+ exports.consumedCapacityMiddleware = void 0;
13
+ const lodash_1 = require("lodash");
14
+ /* eslint-disable @typescript-eslint/no-explicit-any */
15
+ /* eslint-disable @typescript-eslint/no-unused-vars */
16
+ const consumedCapacityMiddleware = (consumedCapacityMiddlewareConfig) => (next, context) => (args) => __awaiter(void 0, void 0, void 0, function* () {
17
+ const { input } = args;
18
+ const { ReturnConsumedCapacity } = input;
19
+ const response = yield next(args);
20
+ const { output } = response;
21
+ const consumedCapacity = (0, lodash_1.get)(output, "ConsumedCapacity");
22
+ yield consumedCapacityMiddlewareConfig.onConsumedCapacity({ ReturnConsumedCapacity, ConsumedCapacity: consumedCapacity });
23
+ return response;
24
+ });
25
+ exports.consumedCapacityMiddleware = consumedCapacityMiddleware;
package/dist/index.js CHANGED
@@ -1,17 +1,8 @@
1
1
  "use strict";
2
- var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
- if (k2 === undefined) k2 = k;
4
- var desc = Object.getOwnPropertyDescriptor(m, k);
5
- if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
- desc = { enumerable: true, get: function() { return m[k]; } };
7
- }
8
- Object.defineProperty(o, k2, desc);
9
- }) : (function(o, m, k, k2) {
10
- if (k2 === undefined) k2 = k;
11
- o[k2] = m[k];
12
- }));
13
- var __exportStar = (this && this.__exportStar) || function(m, exports) {
14
- for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
15
- };
16
2
  Object.defineProperty(exports, "__esModule", { value: true });
17
- __exportStar(require("./DynamoDbRepository"), exports);
3
+ exports.consumedCapacityMiddleware = exports.DynamoDbRepository = exports.FilterOperator = void 0;
4
+ var DynamoDbRepository_1 = require("./DynamoDbRepository");
5
+ Object.defineProperty(exports, "FilterOperator", { enumerable: true, get: function () { return DynamoDbRepository_1.FilterOperator; } });
6
+ Object.defineProperty(exports, "DynamoDbRepository", { enumerable: true, get: function () { return DynamoDbRepository_1.DynamoDbRepository; } });
7
+ var consumed_capacity_middleware_1 = require("./consumed-capacity-middleware");
8
+ Object.defineProperty(exports, "consumedCapacityMiddleware", { enumerable: true, get: function () { return consumed_capacity_middleware_1.consumedCapacityMiddleware; } });
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@eresearchqut/ddb-repository",
3
- "version": "1.4.0",
3
+ "version": "1.4.1",
4
4
  "description": "",
5
5
  "type": "module",
6
6
  "main": "dist/index.js",
@@ -1,7 +1,6 @@
1
1
  import {
2
2
  BatchGetItemCommand,
3
3
  BatchGetItemCommandInput,
4
- ConsumedCapacity,
5
4
  DeleteItemCommand,
6
5
  DynamoDBClient,
7
6
  GetItemCommand,
@@ -12,16 +11,7 @@ import {
12
11
  UpdateItemCommand,
13
12
  } from "@aws-sdk/client-dynamodb";
14
13
  import {marshall, unmarshall} from "@aws-sdk/util-dynamodb";
15
- import {replace, uniqWith, isEqual, pickBy, get} from "lodash";
16
- import {
17
- HandlerExecutionContext,
18
- InitializeHandler,
19
- InitializeHandlerArguments,
20
- InitializeHandlerOutput,
21
- MetadataBearer
22
- } from "@smithy/types";
23
-
24
- const expressionAttributeKey = (key: string) => replace(key, /-/g, "_");
14
+ import {replace, uniqWith, isEqual, pickBy} from "lodash";
25
15
 
26
16
  export enum FilterOperator {
27
17
  EQUALS = "=",
@@ -63,6 +53,7 @@ export interface Query extends Partial<FilterableQuery>, Partial<ProjectedQuery>
63
53
  [key: string]: unknown;
64
54
  }
65
55
 
56
+ const expressionAttributeKey = (key: string) => replace(key, /-/g, "_");
66
57
 
67
58
  const mapInKeys = (filterExpression: FilterExpression) =>
68
59
  Array.isArray(filterExpression.value)
@@ -71,7 +62,7 @@ const mapInKeys = (filterExpression: FilterExpression) =>
71
62
  )
72
63
  : `:${filterExpression.attribute}`;
73
64
 
74
- export const mapFilterExpression = (filterExpression: FilterExpression) => {
65
+ const mapFilterExpression = (filterExpression: FilterExpression) => {
75
66
  switch (filterExpression.operator) {
76
67
  case FilterOperator.IN:
77
68
  return (
@@ -91,7 +82,7 @@ export const mapFilterExpression = (filterExpression: FilterExpression) => {
91
82
  }
92
83
  };
93
84
 
94
- export const mapFilterExpressions = (
85
+ const mapFilterExpressions = (
95
86
  filterExpressions: Array<FilterExpression>,
96
87
  ) =>
97
88
  filterExpressions
@@ -127,35 +118,6 @@ const paginate = <T>(array: Array<T>, pageSize: number) => {
127
118
  }, [] as Array<Array<T>>);
128
119
  }
129
120
 
130
- export interface ConsumedCapacityDetail {
131
- ReturnConsumedCapacity: ReturnConsumedCapacity | undefined
132
- ConsumedCapacity: ConsumedCapacity | ConsumedCapacity[] | undefined
133
- }
134
-
135
- export interface ConsumedCapacityMiddlewareConfig {
136
- onConsumedCapacity: (consumedCapacity: ConsumedCapacityDetail) => Promise<unknown>;
137
- }
138
-
139
- export const consumedCapacityMiddleware =
140
- (consumedCapacityMiddlewareConfig: ConsumedCapacityMiddlewareConfig) =>
141
- <Output extends MetadataBearer = MetadataBearer>(
142
- next: InitializeHandler<any, Output>,
143
- context: HandlerExecutionContext
144
- ): InitializeHandler<any, Output> =>
145
- async (args: InitializeHandlerArguments<any>): Promise<InitializeHandlerOutput<Output>> => {
146
- try {
147
- const {input} = args;
148
- const {ReturnConsumedCapacity} = input;
149
- const response = await next(args);
150
- const {output} = response;
151
- const consumedCapacity = get(output, "ConsumedCapacity") as ConsumedCapacity | undefined;
152
- await consumedCapacityMiddlewareConfig.onConsumedCapacity({ReturnConsumedCapacity, ConsumedCapacity: consumedCapacity});
153
- return response;
154
- } catch (error) {
155
- throw error;
156
- }
157
- };
158
-
159
121
  export class DynamoDbRepository<K, T> {
160
122
 
161
123
  constructor(
@@ -402,6 +364,5 @@ export class DynamoDbRepository<K, T> {
402
364
  .then((itemSets) => itemSets.flat());
403
365
 
404
366
  };
405
-
406
367
  }
407
368
 
@@ -0,0 +1,41 @@
1
+ import {
2
+ ConsumedCapacity,
3
+ ReturnConsumedCapacity
4
+ } from "@aws-sdk/client-dynamodb";
5
+
6
+ import {
7
+ HandlerExecutionContext,
8
+ InitializeHandler,
9
+ InitializeHandlerArguments,
10
+ InitializeHandlerOutput,
11
+ MetadataBearer
12
+ } from "@smithy/types";
13
+
14
+ import {get} from "lodash";
15
+
16
+ export interface ConsumedCapacityDetail {
17
+ ReturnConsumedCapacity: ReturnConsumedCapacity | undefined
18
+ ConsumedCapacity: ConsumedCapacity | ConsumedCapacity[] | undefined
19
+ }
20
+
21
+ export interface ConsumedCapacityMiddlewareConfig {
22
+ onConsumedCapacity: (consumedCapacity: ConsumedCapacityDetail) => Promise<unknown>;
23
+ }
24
+
25
+ /* eslint-disable @typescript-eslint/no-explicit-any */
26
+ /* eslint-disable @typescript-eslint/no-unused-vars */
27
+ export const consumedCapacityMiddleware =
28
+ (consumedCapacityMiddlewareConfig: ConsumedCapacityMiddlewareConfig) =>
29
+ <Output extends MetadataBearer = MetadataBearer>(
30
+ next: InitializeHandler<any, Output>,
31
+ context: HandlerExecutionContext
32
+ ): InitializeHandler<any, Output> =>
33
+ async (args: InitializeHandlerArguments<any>): Promise<InitializeHandlerOutput<Output>> => {
34
+ const {input} = args;
35
+ const {ReturnConsumedCapacity} = input;
36
+ const response = await next(args);
37
+ const {output} = response;
38
+ const consumedCapacity = get(output, "ConsumedCapacity") as ConsumedCapacity | ConsumedCapacity[] | undefined;
39
+ await consumedCapacityMiddlewareConfig.onConsumedCapacity({ReturnConsumedCapacity, ConsumedCapacity: consumedCapacity});
40
+ return response;
41
+ };
package/src/index.ts CHANGED
@@ -1,3 +1,4 @@
1
- export * from "./DynamoDbRepository";
1
+ export {Query, IndexedQuery, ProjectedQuery, FilterableQuery, FilterExpression, FilterOperator, DynamoDbRepository} from "./DynamoDbRepository";
2
+ export {consumedCapacityMiddleware, ConsumedCapacityDetail, ConsumedCapacityMiddlewareConfig} from "./consumed-capacity-middleware"
2
3
 
3
4