@lafken/dynamo 0.11.12 → 0.11.14
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/lib/service/query-builder/base/base.js +8 -3
- package/lib/service/query-builder/bulk-create/bulk-create.js +1 -1
- package/lib/service/query-builder/bulk-delete/bulk-delete.js +1 -1
- package/lib/service/query-builder/delete/delete.js +3 -1
- package/lib/service/query-builder/find/find.js +3 -1
- package/lib/service/query-builder/query-builder.types.d.ts +4 -4
- package/lib/service/query-builder/scan/scan.js +3 -1
- package/lib/service/query-builder/update/update.js +1 -1
- package/lib/service/query-builder/upsert/upsert.js +1 -1
- package/lib/service/repository/repository.js +3 -0
- package/lib/service/repository/repository.types.d.ts +2 -0
- package/package.json +4 -4
|
@@ -83,8 +83,13 @@ class QueryBuilderBase {
|
|
|
83
83
|
}
|
|
84
84
|
case 'AND': {
|
|
85
85
|
const andFilter = filter;
|
|
86
|
-
const
|
|
87
|
-
|
|
86
|
+
const andExpressions = [];
|
|
87
|
+
for (const condition of andFilter.AND) {
|
|
88
|
+
const expression = this.getFilterExpression(condition, names, 'and', counter);
|
|
89
|
+
counter += 1;
|
|
90
|
+
andExpressions.push(expression);
|
|
91
|
+
}
|
|
92
|
+
filterExpression.push(`(${andExpressions.join(' and ')})`);
|
|
88
93
|
break;
|
|
89
94
|
}
|
|
90
95
|
default: {
|
|
@@ -129,7 +134,7 @@ class QueryBuilderBase {
|
|
|
129
134
|
return {
|
|
130
135
|
ExpressionAttributeNames: Object.keys(this.attributeNames).length > 0 ? this.attributeNames : undefined,
|
|
131
136
|
ExpressionAttributeValues: Object.keys(this.attributeValues).length > 0
|
|
132
|
-
? (0, util_dynamodb_1.marshall)(this.attributeValues)
|
|
137
|
+
? (0, util_dynamodb_1.marshall)(this.attributeValues, { removeUndefinedValues: true })
|
|
133
138
|
: undefined,
|
|
134
139
|
};
|
|
135
140
|
}
|
|
@@ -13,7 +13,7 @@ class BulkCreateBuilder extends batch_write_1.BatchWriteBuilder {
|
|
|
13
13
|
[queryOptions.modelProps.name]: items.map((item) => {
|
|
14
14
|
return {
|
|
15
15
|
PutRequest: {
|
|
16
|
-
Item: (0, util_dynamodb_1.marshall)(item),
|
|
16
|
+
Item: (0, util_dynamodb_1.marshall)(item, { removeUndefinedValues: true }),
|
|
17
17
|
},
|
|
18
18
|
};
|
|
19
19
|
}),
|
|
@@ -14,7 +14,7 @@ class BulkDeleteBuilder extends batch_write_1.BatchWriteBuilder {
|
|
|
14
14
|
[queryOptions.modelProps.name]: items.map((item) => {
|
|
15
15
|
return {
|
|
16
16
|
DeleteRequest: {
|
|
17
|
-
Key: (0, util_dynamodb_1.marshall)(item),
|
|
17
|
+
Key: (0, util_dynamodb_1.marshall)(item, { removeUndefinedValues: true }),
|
|
18
18
|
},
|
|
19
19
|
};
|
|
20
20
|
}),
|
|
@@ -26,7 +26,9 @@ class DeleteBuilder extends base_1.QueryBuilderBase {
|
|
|
26
26
|
prepare() {
|
|
27
27
|
this.command = {
|
|
28
28
|
TableName: this.queryOptions.modelProps.name,
|
|
29
|
-
Key: (0, util_dynamodb_1.marshall)(this.queryOptions.key
|
|
29
|
+
Key: (0, util_dynamodb_1.marshall)(this.queryOptions.key, {
|
|
30
|
+
removeUndefinedValues: true,
|
|
31
|
+
}),
|
|
30
32
|
};
|
|
31
33
|
}
|
|
32
34
|
}
|
|
@@ -29,7 +29,9 @@ class FindBuilder extends base_1.QueryBuilderBase {
|
|
|
29
29
|
IndexName: index?.name,
|
|
30
30
|
KeyConditionExpression: keyConditionExpression,
|
|
31
31
|
FilterExpression: filterExpression,
|
|
32
|
-
ExclusiveStartKey: cursor
|
|
32
|
+
ExclusiveStartKey: cursor
|
|
33
|
+
? (0, util_dynamodb_1.marshall)(cursor, { removeUndefinedValues: true })
|
|
34
|
+
: undefined,
|
|
33
35
|
Limit: limit,
|
|
34
36
|
ScanIndexForward: sortDirection === 'asc',
|
|
35
37
|
ProjectionExpression: projection === 'ALL' ? undefined : projection.join(', '),
|
|
@@ -30,13 +30,13 @@ 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> ? 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]>>;
|
|
33
|
+
[key in keyof E]?: NonNullable<E[key]> extends PrimaryPartition<number> ? NonNullable<E[key]> | OnlyOne<OperationExpression<number> & CommonExpression<number> & InExpression<number>> : NonNullable<E[key]> extends PrimaryPartition<string> ? NonNullable<E[key]> | OnlyOne<StringExpression & StringFilterExpression & CommonExpression<string> & InExpression<string>> : NonNullable<E[key]> extends string | number | boolean | Date | null ? NonNullable<E[key]> | (NonNullable<E[key]> extends number ? OnlyOne<OperationExpression<number> & CommonExpression<number> & InExpression<number>> : NonNullable<E[key]> extends boolean ? CommonExpression<boolean> : NonNullable<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>>;
|
|
37
37
|
};
|
|
38
38
|
export type AndFilter<E> = {
|
|
39
|
-
AND: Filter<E> | OrFilter<E
|
|
39
|
+
AND: Array<Filter<E> | OrFilter<E>>;
|
|
40
40
|
};
|
|
41
41
|
export type SortDirectionType = 'asc' | 'desc';
|
|
42
42
|
export type KeyCondition<E> = {
|
|
@@ -72,7 +72,7 @@ export interface FindProps<E extends Function> {
|
|
|
72
72
|
* },
|
|
73
73
|
* }
|
|
74
74
|
*/
|
|
75
|
-
filter?: Filter<E['prototype']> | OrFilter<E['prototype']>;
|
|
75
|
+
filter?: Filter<E['prototype']> | OrFilter<E['prototype']> | AndFilter<E['prototype']>;
|
|
76
76
|
/**
|
|
77
77
|
* Specifies the sort order to apply to the query results.
|
|
78
78
|
* This determines whether items are returned in ascending or descending order.
|
|
@@ -248,7 +248,7 @@ export interface UpsertProps<E extends Function> {
|
|
|
248
248
|
* foo: 'bar'
|
|
249
249
|
* }
|
|
250
250
|
*/
|
|
251
|
-
condition?: Filter<E['prototype']>;
|
|
251
|
+
condition?: Filter<E['prototype']> | OrFilter<E['prototype']> | AndFilter<E['prototype']>;
|
|
252
252
|
}
|
|
253
253
|
export interface ModelInformation<E extends ClassResource> {
|
|
254
254
|
modelProps: ModelMetadata<E>;
|
|
@@ -30,7 +30,9 @@ class ScanBuilder extends base_1.QueryBuilderBase {
|
|
|
30
30
|
this.command = {
|
|
31
31
|
TableName: this.queryOptions.modelProps.name,
|
|
32
32
|
FilterExpression: filterExpression,
|
|
33
|
-
ExclusiveStartKey: cursor
|
|
33
|
+
ExclusiveStartKey: cursor
|
|
34
|
+
? (0, util_dynamodb_1.marshall)(cursor, { removeUndefinedValues: true })
|
|
35
|
+
: undefined,
|
|
34
36
|
Limit: limit,
|
|
35
37
|
ProjectionExpression: projection === 'ALL' ? undefined : projection.join(', '),
|
|
36
38
|
...this.getAttributesAndNames(),
|
|
@@ -46,7 +46,7 @@ class UpdateBuilder extends base_1.QueryBuilderBase {
|
|
|
46
46
|
const keyCondition = this.queryOptions.inputProps.keyCondition;
|
|
47
47
|
this.command = {
|
|
48
48
|
TableName: this.queryOptions.modelProps.name,
|
|
49
|
-
Key: (0, util_dynamodb_1.marshall)(keyCondition),
|
|
49
|
+
Key: (0, util_dynamodb_1.marshall)(keyCondition, { removeUndefinedValues: true }),
|
|
50
50
|
ConditionExpression: condition
|
|
51
51
|
? this.getFilterExpression(condition, [], 'and', this.expressionGroupCounter++)
|
|
52
52
|
: undefined,
|
|
@@ -31,7 +31,7 @@ class UpsertBuilder extends base_1.QueryBuilderBase {
|
|
|
31
31
|
}
|
|
32
32
|
this.command = {
|
|
33
33
|
TableName: this.queryOptions.modelProps.name,
|
|
34
|
-
Item: (0, util_dynamodb_1.marshall)(this.queryOptions.item),
|
|
34
|
+
Item: (0, util_dynamodb_1.marshall)(this.queryOptions.item, { removeUndefinedValues: true }),
|
|
35
35
|
ConditionExpression: conditionExpression,
|
|
36
36
|
...this.getAttributesAndNames(),
|
|
37
37
|
};
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import type { DynamoDBClient } from '@aws-sdk/client-dynamodb';
|
|
1
2
|
import type { ClassResource } from '@lafken/common';
|
|
2
3
|
import type { TablePartition } from '../../main';
|
|
3
4
|
import type { FindProps, Item, QueryOneProps, QueryProps, ReturnValueOption, UpdateProps, UpsertProps } from '../query-builder';
|
|
@@ -22,4 +23,5 @@ export type RepositoryReturn<E extends ClassResource> = {
|
|
|
22
23
|
delete(key: TablePartition<Item<E>>): DeleteBuilder<E>;
|
|
23
24
|
bulkCreate(items: Item<E>[]): BulkCreateBuilder<E>;
|
|
24
25
|
bulkDelete(keys: TablePartition<Item<E>>[]): BulkDeleteBuilder<E>;
|
|
26
|
+
sendRawCommand<T = unknown>(command: Parameters<DynamoDBClient['send']>[0]): Promise<T>;
|
|
25
27
|
};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@lafken/dynamo",
|
|
3
|
-
"version": "0.11.
|
|
3
|
+
"version": "0.11.14",
|
|
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.
|
|
63
|
+
"@lafken/resolver": "0.11.14"
|
|
64
64
|
},
|
|
65
65
|
"devDependencies": {
|
|
66
66
|
"@cdktn/provider-aws": "^23.9.0",
|
|
@@ -75,13 +75,13 @@
|
|
|
75
75
|
"typescript": "6.0.3",
|
|
76
76
|
"unplugin-swc": "^1.5.9",
|
|
77
77
|
"vitest": "^4.1.5",
|
|
78
|
-
"@lafken/common": "0.11.
|
|
78
|
+
"@lafken/common": "0.11.14"
|
|
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.
|
|
84
|
+
"@lafken/common": "0.11.14"
|
|
85
85
|
},
|
|
86
86
|
"engines": {
|
|
87
87
|
"node": ">=20.19"
|