@lafken/dynamo 0.12.18 → 0.12.20

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.
@@ -11,6 +11,7 @@ export declare class QueryBuilderBase<E extends ClassResource> {
11
11
  protected expressionGroupCounter: number;
12
12
  protected getKeyConditionExpression(expression: KeyCondition<E>, index?: LocalIndex<E> | GlobalIndexProperty): string;
13
13
  protected getFilterExpression<T>(filter: Filter<T> | OrFilter<T> | AndFilter<T>, names?: string[], union?: 'or' | 'and', counter?: number): string;
14
+ protected getProjectionExpression(projection?: (string | number | symbol)[] | 'ALL'): string | undefined;
14
15
  protected getAttributesAndNames(): {
15
16
  ExpressionAttributeNames: Record<string, string> | undefined;
16
17
  ExpressionAttributeValues: Record<string, import("@aws-sdk/client-dynamodb").AttributeValue> | undefined;
@@ -155,6 +155,18 @@ class QueryBuilderBase {
155
155
  }
156
156
  return filterExpression.join(` ${union} `);
157
157
  }
158
+ getProjectionExpression(projection) {
159
+ if (!projection || projection === 'ALL') {
160
+ return undefined;
161
+ }
162
+ return projection
163
+ .map((attribute) => {
164
+ const name = String(attribute);
165
+ this.attributeNames[`#${name}`] = name;
166
+ return `#${name}`;
167
+ })
168
+ .join(', ');
169
+ }
158
170
  getAttributesAndNames() {
159
171
  return {
160
172
  ExpressionAttributeNames: Object.keys(this.attributeNames).length > 0 ? this.attributeNames : undefined,
@@ -37,7 +37,7 @@ class BatchGetBuilder extends base_1.QueryBuilderBase {
37
37
  }
38
38
  prepare() {
39
39
  const { consistentRead, projection } = this.queryOptions.options ?? {};
40
- const projectionExpression = projection && projection !== 'ALL' ? projection.join(', ') : undefined;
40
+ const projectionExpression = this.getProjectionExpression(projection);
41
41
  const chunkedKeys = this.chunkKeys(this.queryOptions.keys, 100);
42
42
  for (const keys of chunkedKeys) {
43
43
  this.commands.push({
@@ -46,6 +46,9 @@ class BatchGetBuilder extends base_1.QueryBuilderBase {
46
46
  Keys: keys.map((key) => (0, util_dynamodb_1.marshall)(key, { removeUndefinedValues: true })),
47
47
  ConsistentRead: consistentRead,
48
48
  ProjectionExpression: projectionExpression,
49
+ ExpressionAttributeNames: projectionExpression
50
+ ? this.attributeNames
51
+ : undefined,
49
52
  },
50
53
  },
51
54
  });
@@ -34,7 +34,7 @@ class FindBuilder extends base_1.QueryBuilderBase {
34
34
  : undefined,
35
35
  Limit: limit,
36
36
  ScanIndexForward: sortDirection === 'asc',
37
- ProjectionExpression: projection === 'ALL' ? undefined : projection.join(', '),
37
+ ProjectionExpression: this.getProjectionExpression(projection),
38
38
  ...this.getAttributesAndNames(),
39
39
  };
40
40
  }
@@ -32,13 +32,15 @@ class GetItemBuilder extends base_1.QueryBuilderBase {
32
32
  }
33
33
  prepare() {
34
34
  const { consistentRead, projection } = this.queryOptions.options ?? {};
35
+ const projectionExpression = this.getProjectionExpression(projection);
35
36
  this.command = {
36
37
  TableName: this.queryOptions.modelProps.name,
37
38
  Key: (0, util_dynamodb_1.marshall)(this.queryOptions.key, {
38
39
  removeUndefinedValues: true,
39
40
  }),
40
41
  ConsistentRead: consistentRead,
41
- ProjectionExpression: projection && projection !== 'ALL' ? projection.join(', ') : undefined,
42
+ ProjectionExpression: projectionExpression,
43
+ ExpressionAttributeNames: projectionExpression ? this.attributeNames : undefined,
42
44
  };
43
45
  }
44
46
  }
@@ -34,7 +34,7 @@ class ScanBuilder extends base_1.QueryBuilderBase {
34
34
  ? (0, util_dynamodb_1.marshall)(cursor, { removeUndefinedValues: true })
35
35
  : undefined,
36
36
  Limit: limit,
37
- ProjectionExpression: projection === 'ALL' ? undefined : projection.join(', '),
37
+ ProjectionExpression: this.getProjectionExpression(projection),
38
38
  ...this.getAttributesAndNames(),
39
39
  };
40
40
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@lafken/dynamo",
3
- "version": "0.12.18",
3
+ "version": "0.12.20",
4
4
  "private": false,
5
5
  "description": "Define DynamoDB tables using TypeScript decorators - type-safe, declarative infrastructure with Lafken",
6
6
  "keywords": [
@@ -59,7 +59,7 @@
59
59
  "@aws-sdk/client-dynamodb": "^3.1062.0",
60
60
  "@aws-sdk/util-dynamodb": "^3.996.2",
61
61
  "reflect-metadata": "^0.2.2",
62
- "@lafken/resolver": "0.12.18"
62
+ "@lafken/resolver": "0.12.20"
63
63
  },
64
64
  "devDependencies": {
65
65
  "@cdktn/provider-aws": "^24.4.0",
@@ -73,13 +73,13 @@
73
73
  "typescript": "6.0.3",
74
74
  "unplugin-swc": "^1.5.9",
75
75
  "vitest": "^4.1.8",
76
- "@lafken/common": "0.12.18"
76
+ "@lafken/common": "0.12.20"
77
77
  },
78
78
  "peerDependencies": {
79
79
  "@cdktn/provider-aws": ">=23.0.0",
80
80
  "cdktn": ">=0.22.0",
81
81
  "constructs": "^10.4.5",
82
- "@lafken/common": "0.12.18"
82
+ "@lafken/common": "0.12.20"
83
83
  },
84
84
  "engines": {
85
85
  "node": ">=20.19"