@lafken/dynamo 0.10.6 → 0.11.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.
@@ -222,6 +222,20 @@ export interface UpdateProps<E extends Function> extends UpsertProps<E> {
222
222
  * }
223
223
  */
224
224
  removeValues?: ObjectToBoolean<Item<E>>;
225
+ /**
226
+ * Specifies what DynamoDB should return after the update operation completes.
227
+ *
228
+ * - `'all_new'` — Returns all attributes of the item as they appear after the update.
229
+ * - `'updated_new'` — Returns only the attributes that were updated, with their new values.
230
+ * - `'all_old'` — Returns all attributes of the item as they appeared before the update.
231
+ * - `'none'` — Does not return any attribute values.
232
+ *
233
+ * @example
234
+ * {
235
+ * returnValue: 'all_new'
236
+ * }
237
+ */
238
+ returnValue?: 'all_new' | 'updated_new' | 'all_old' | 'none';
225
239
  }
226
240
  export interface UpsertProps<E extends Function> {
227
241
  /**
@@ -1,13 +1,14 @@
1
1
  import { type UpdateItemCommandInput } from '@aws-sdk/client-dynamodb';
2
2
  import type { ClassResource } from '@lafken/common';
3
3
  import { QueryBuilderBase } from '../base/base';
4
+ import type { Item } from '../query-builder.types';
4
5
  import type { UpdateBuilderProps } from './update.types';
5
6
  export declare class UpdateBuilder<E extends ClassResource> extends QueryBuilderBase<E> {
6
7
  protected queryOptions: UpdateBuilderProps<E>;
7
8
  protected command: UpdateItemCommandInput;
8
9
  constructor(queryOptions: UpdateBuilderProps<E>);
9
10
  getCommand(): UpdateItemCommandInput;
10
- then<T>(resolve: (value: boolean) => T, reject: (reason: any) => T): Promise<T>;
11
+ then<T>(resolve: (value: Partial<Item<E>> | undefined) => Item<E>, reject: (reason: any) => T): Promise<T>;
11
12
  private exec;
12
13
  protected prepare(): void;
13
14
  private setValues;
@@ -21,8 +21,12 @@ class UpdateBuilder extends base_1.QueryBuilderBase {
21
21
  }
22
22
  async exec() {
23
23
  const command = new client_dynamodb_1.UpdateItemCommand(this.command);
24
- await this.queryOptions.client.send(command);
25
- return true;
24
+ const response = await this.queryOptions.client.send(command);
25
+ if (!response?.Attributes ||
26
+ ['none', undefined].includes(this.queryOptions.inputProps.returnValue)) {
27
+ return undefined;
28
+ }
29
+ return (0, util_dynamodb_1.unmarshall)(response?.Attributes);
26
30
  }
27
31
  prepare() {
28
32
  const { removeValues = {}, replaceValues = {}, setValues = {}, condition, } = this.queryOptions.inputProps;
@@ -43,6 +47,9 @@ class UpdateBuilder extends base_1.QueryBuilderBase {
43
47
  UpdateExpression: `${setExpression ? `SET ${setExpression}` : ''} ${removeExpression ? `REMOVE ${removeExpression}` : ''}`.trim(),
44
48
  ...this.getAttributesAndNames(),
45
49
  ConditionExpression: condition ? this.getFilterExpression(condition) : undefined,
50
+ ReturnValues: this.queryOptions.inputProps.returnValue
51
+ ? this.queryOptions.inputProps.returnValue.toUpperCase()
52
+ : undefined,
46
53
  };
47
54
  }
48
55
  setValues(values, isDeepReplace, names = [], counter = 0) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@lafken/dynamo",
3
- "version": "0.10.6",
3
+ "version": "0.11.0",
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.10.6"
63
+ "@lafken/resolver": "0.11.0"
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.10.6"
78
+ "@lafken/common": "0.11.0"
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.10.6"
84
+ "@lafken/common": "0.11.0"
85
85
  },
86
86
  "engines": {
87
87
  "node": ">=20.19"