@lafken/dynamo 0.11.6 → 0.11.8

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.
@@ -8,6 +8,7 @@ export declare class QueryBuilderBase<E extends ClassResource> {
8
8
  constructor(options: QueryBuilderProps<E>);
9
9
  protected attributeNames: Record<string, string>;
10
10
  protected attributeValues: Record<string, any>;
11
+ protected expressionGroupCounter: number;
11
12
  protected getKeyConditionExpression(expression: KeyCondition<E>, index?: LocalIndex<E> | GlobalIndexProperty): string;
12
13
  protected getFilterExpression<T>(filter: Filter<T> | OrFilter<T> | AndFilter<T>, names?: string[], union?: 'or' | 'and', counter?: number): string;
13
14
  protected getAttributesAndNames(): {
@@ -11,6 +11,7 @@ class QueryBuilderBase {
11
11
  }
12
12
  attributeNames = {};
13
13
  attributeValues = {};
14
+ expressionGroupCounter = 0;
14
15
  getKeyConditionExpression(expression, index) {
15
16
  const { partition, sort } = expression;
16
17
  const isGlobalIndex = index?.type === 'global';
@@ -35,16 +35,21 @@ class UpdateBuilder extends base_1.QueryBuilderBase {
35
35
  Object.keys(setValues).length > 0) {
36
36
  throw new Error('You must assign a value to update');
37
37
  }
38
- let setExpression = this.setValues(setValues, true);
38
+ let setExpression = '';
39
+ if (Object.keys(setValues).length > 0) {
40
+ setExpression = this.setValues(setValues, true, [], this.expressionGroupCounter++);
41
+ }
39
42
  if (Object.keys(replaceValues).length > 0) {
40
- setExpression += ` ${this.setValues(replaceValues, false)}`;
43
+ setExpression += ` ${this.setValues(replaceValues, false, [], this.expressionGroupCounter++)}`;
41
44
  }
42
45
  const removeExpression = this.removeValues(removeValues);
43
46
  const keyCondition = this.queryOptions.inputProps.keyCondition;
44
47
  this.command = {
45
48
  TableName: this.queryOptions.modelProps.name,
46
49
  Key: (0, util_dynamodb_1.marshall)(keyCondition),
47
- ConditionExpression: condition ? this.getFilterExpression(condition) : undefined,
50
+ ConditionExpression: condition
51
+ ? this.getFilterExpression(condition, [], 'and', this.expressionGroupCounter++)
52
+ : undefined,
48
53
  UpdateExpression: `${setExpression ? `SET ${setExpression}` : ''} ${removeExpression ? `REMOVE ${removeExpression}` : ''}`.trim(),
49
54
  ...this.getAttributesAndNames(),
50
55
  ReturnValues: this.queryOptions.inputProps.returnValue
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@lafken/dynamo",
3
- "version": "0.11.6",
3
+ "version": "0.11.8",
4
4
  "private": false,
5
5
  "description": "Define DynamoDB tables using TypeScript decorators - type-safe, declarative infrastructure with Lafken",
6
6
  "keywords": [
@@ -60,7 +60,7 @@
60
60
  "@aws-sdk/util-dynamodb": "^3.996.2",
61
61
  "aws-xray-sdk": "^3.12.0",
62
62
  "reflect-metadata": "^0.2.2",
63
- "@lafken/resolver": "0.11.6"
63
+ "@lafken/resolver": "0.11.8"
64
64
  },
65
65
  "devDependencies": {
66
66
  "@cdktn/provider-aws": "^23.5.0",
@@ -75,13 +75,13 @@
75
75
  "typescript": "6.0.2",
76
76
  "unplugin-swc": "^1.5.9",
77
77
  "vitest": "^4.1.2",
78
- "@lafken/common": "0.11.6"
78
+ "@lafken/common": "0.11.8"
79
79
  },
80
80
  "peerDependencies": {
81
81
  "@cdktn/provider-aws": ">=23.0.0",
82
82
  "cdktn": ">=0.22.0",
83
83
  "constructs": "^10.4.5",
84
- "@lafken/common": "0.11.6"
84
+ "@lafken/common": "0.11.8"
85
85
  },
86
86
  "engines": {
87
87
  "node": ">=20.19"