@lafken/dynamo 0.11.4 → 0.11.6

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.
@@ -30,7 +30,7 @@ export type CommonExpression<E> = OnlyOne<{
30
30
  notEqual: E;
31
31
  } & NullExpression>;
32
32
  export type Filter<E> = {
33
- [key in keyof E]?: E[key] extends PrimaryPartition<number> ? number | OnlyOne<OperationExpression<number> & CommonExpression<number> & InExpression<number>> : E[key] extends PrimaryPartition<string> ? string | OnlyOne<StringExpression & StringFilterExpression & CommonExpression<string> & InExpression<string>> : E[key] extends string | number | boolean | Date | null ? E[key] | (E[key] extends number ? OnlyOne<OperationExpression<number> & CommonExpression<number> & InExpression<number>> : E[key] extends boolean ? CommonExpression<boolean> : E[key] extends null ? NullExpression : OnlyOne<StringExpression & StringFilterExpression & CommonExpression<string> & InExpression<string>>) : DeepPartial<Filter<E[key]>>;
33
+ [key in keyof E]?: E[key] extends PrimaryPartition<number> ? E[key] | OnlyOne<OperationExpression<number> & CommonExpression<number> & InExpression<number>> : E[key] extends PrimaryPartition<string> ? E[key] | OnlyOne<StringExpression & StringFilterExpression & CommonExpression<string> & InExpression<string>> : E[key] extends string | number | boolean | Date | null ? E[key] | (E[key] extends number ? OnlyOne<OperationExpression<number> & CommonExpression<number> & InExpression<number>> : E[key] extends boolean ? CommonExpression<boolean> : E[key] extends null ? NullExpression : OnlyOne<StringExpression & StringFilterExpression & CommonExpression<string> & InExpression<string>>) : DeepPartial<Filter<E[key]>>;
34
34
  };
35
35
  export type OrFilter<E> = {
36
36
  OR: Array<Filter<E> | AndFilter<E>>;
@@ -42,7 +42,7 @@ export type SortDirectionType = 'asc' | 'desc';
42
42
  export type KeyCondition<E> = {
43
43
  partition: Partial<OnlyNumberString<E>>;
44
44
  sort?: {
45
- [key in keyof E as E[key] extends number | string ? key : never]?: E[key] extends PrimaryPartition<number> ? number | OperationExpression<E[key]> : E[key] extends PrimaryPartition<string> ? string | OnlyOne<OperationExpression<E[key]> & StringExpression> : E[key] | (E[key] extends number ? OperationExpression<E[key]> : OnlyOne<OperationExpression<E[key]> | StringExpression>);
45
+ [key in keyof E as E[key] extends number | string ? key : never]?: E[key] extends PrimaryPartition<number> ? E[key] | OperationExpression<E[key]> : E[key] extends PrimaryPartition<string> ? E[key] | OnlyOne<OperationExpression<E[key]> & StringExpression> : E[key] | (E[key] extends number ? OperationExpression<E[key]> : OnlyOne<OperationExpression<E[key]> | StringExpression>);
46
46
  };
47
47
  };
48
48
  export type Item<E extends Function> = {
@@ -158,6 +158,8 @@ export type ReplaceValue<T> = {
158
158
  export type DeepReplaceValue<T> = {
159
159
  [K in keyof T]?: T[K] extends number | string | boolean | Array<any> | Date ? NumericOrExist<T[K]> : ExistValue<T[K]> | DeepReplaceValue<T[K]>;
160
160
  };
161
+ export type ReturnValueOption = 'all_new' | 'updated_new' | 'all_old' | 'none';
162
+ export type UpdateReturnType<E extends Function, R extends ReturnValueOption | undefined> = R extends 'all_new' | 'all_old' ? Item<E> : R extends 'updated_new' ? Partial<Item<E>> : undefined;
161
163
  export interface UpdateProps<E extends Function> extends UpsertProps<E> {
162
164
  /**
163
165
  * Specifies the key condition used to execute the update query.
@@ -1,14 +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
+ import type { ReturnValueOption, UpdateReturnType } from '../query-builder.types';
5
5
  import type { UpdateBuilderProps } from './update.types';
6
- export declare class UpdateBuilder<E extends ClassResource> extends QueryBuilderBase<E> {
6
+ export declare class UpdateBuilder<E extends ClassResource, R extends ReturnValueOption | undefined = undefined> extends QueryBuilderBase<E> {
7
7
  protected queryOptions: UpdateBuilderProps<E>;
8
8
  protected command: UpdateItemCommandInput;
9
9
  constructor(queryOptions: UpdateBuilderProps<E>);
10
10
  getCommand(): UpdateItemCommandInput;
11
- then<T>(resolve: (value: Partial<Item<E>> | undefined) => Item<E>, reject: (reason: any) => T): Promise<T>;
11
+ then<T>(resolve: (value: UpdateReturnType<E, R>) => T, reject: (reason: any) => T): Promise<T>;
12
12
  private exec;
13
13
  protected prepare(): void;
14
14
  private setValues;
@@ -44,9 +44,9 @@ class UpdateBuilder extends base_1.QueryBuilderBase {
44
44
  this.command = {
45
45
  TableName: this.queryOptions.modelProps.name,
46
46
  Key: (0, util_dynamodb_1.marshall)(keyCondition),
47
+ ConditionExpression: condition ? this.getFilterExpression(condition) : undefined,
47
48
  UpdateExpression: `${setExpression ? `SET ${setExpression}` : ''} ${removeExpression ? `REMOVE ${removeExpression}` : ''}`.trim(),
48
49
  ...this.getAttributesAndNames(),
49
- ConditionExpression: condition ? this.getFilterExpression(condition) : undefined,
50
50
  ReturnValues: this.queryOptions.inputProps.returnValue
51
51
  ? this.queryOptions.inputProps.returnValue.toUpperCase()
52
52
  : undefined,
@@ -63,7 +63,7 @@ const createRepository = (model) => {
63
63
  update(inputProps) {
64
64
  return new update_1.UpdateBuilder({
65
65
  ...queryBuilderProps,
66
- inputProps,
66
+ inputProps: inputProps,
67
67
  });
68
68
  },
69
69
  delete(key) {
@@ -1,6 +1,6 @@
1
1
  import type { ClassResource } from '@lafken/common';
2
2
  import type { TablePartition } from '../../main';
3
- import type { FindProps, Item, QueryOneProps, QueryProps, UpdateProps, UpsertProps } from '../query-builder';
3
+ import type { FindProps, Item, QueryOneProps, QueryProps, ReturnValueOption, UpdateProps, UpsertProps } from '../query-builder';
4
4
  import type { BulkCreateBuilder } from '../query-builder/bulk-create/bulk-create';
5
5
  import type { BulkDeleteBuilder } from '../query-builder/bulk-delete/bulk-delete';
6
6
  import type { CreateBuilder } from '../query-builder/create/create';
@@ -16,7 +16,9 @@ export type RepositoryReturn<E extends ClassResource> = {
16
16
  scan(inputProps?: FindProps<E>): ScanBuilder<E>;
17
17
  upsert(item: Item<E>, inputProps?: UpsertProps<E>): UpsertBuilder<E>;
18
18
  create(item: Item<E>): CreateBuilder<E>;
19
- update(inputProps: UpdateProps<E>): UpdateBuilder<E>;
19
+ update<R extends ReturnValueOption | undefined = undefined>(inputProps: Omit<UpdateProps<E>, 'returnValue'> & {
20
+ returnValue?: R;
21
+ }): UpdateBuilder<E, R>;
20
22
  delete(key: TablePartition<Item<E>>): DeleteBuilder<E>;
21
23
  bulkCreate(items: Item<E>[]): BulkCreateBuilder<E>;
22
24
  bulkDelete(keys: TablePartition<Item<E>>[]): BulkDeleteBuilder<E>;
@@ -2,4 +2,4 @@ import type { CreateBuilder } from '../query-builder/create/create';
2
2
  import type { DeleteBuilder } from '../query-builder/delete/delete';
3
3
  import type { UpdateBuilder } from '../query-builder/update/update';
4
4
  import type { UpsertBuilder } from '../query-builder/upsert/upsert';
5
- export type QueryTransactions = CreateBuilder<any> | UpsertBuilder<any> | UpdateBuilder<any> | DeleteBuilder<any>;
5
+ export type QueryTransactions = CreateBuilder<any> | UpsertBuilder<any> | UpdateBuilder<any, any> | DeleteBuilder<any>;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@lafken/dynamo",
3
- "version": "0.11.4",
3
+ "version": "0.11.6",
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.4"
63
+ "@lafken/resolver": "0.11.6"
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.4"
78
+ "@lafken/common": "0.11.6"
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.4"
84
+ "@lafken/common": "0.11.6"
85
85
  },
86
86
  "engines": {
87
87
  "node": ">=20.19"