@aurios/mizzle 1.1.2 → 1.1.3
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/.turbo/turbo-build.log +37 -0
- package/LICENSE +21 -0
- package/README.md +57 -57
- package/dist/chunk-AQVECMXP.js +1 -0
- package/dist/chunk-DU7UPWBW.js +1 -0
- package/dist/chunk-GPYZK4WY.js +1 -0
- package/dist/chunk-NPPZW6VT.js +1 -0
- package/dist/chunk-TOYV2M4M.js +1 -0
- package/dist/chunk-UM3YF5EC.js +1 -0
- package/dist/columns.d.ts +1 -0
- package/dist/columns.js +1 -0
- package/dist/db-zHIHBm1E.d.ts +815 -0
- package/dist/db.d.ts +3 -0
- package/dist/db.js +1 -0
- package/dist/diff.d.ts +18 -0
- package/dist/diff.js +1 -0
- package/dist/index.d.ts +42 -0
- package/dist/index.js +1 -0
- package/dist/introspection.d.ts +7 -0
- package/dist/introspection.js +1 -0
- package/dist/operators-BVreW0ky.d.ts +719 -0
- package/dist/snapshot.d.ts +24 -0
- package/dist/snapshot.js +1 -0
- package/dist/table.d.ts +1 -0
- package/dist/table.js +1 -0
- package/dist/transaction-RE7LXTGV.js +1 -0
- package/package.json +82 -66
- package/src/builders/base.ts +53 -56
- package/src/builders/batch-get.ts +63 -58
- package/src/builders/batch-write.ts +81 -78
- package/src/builders/delete.ts +46 -53
- package/src/builders/insert.ts +158 -150
- package/src/builders/query-promise.ts +26 -35
- package/src/builders/relational-builder.ts +214 -191
- package/src/builders/select.ts +250 -237
- package/src/builders/transaction.ts +170 -152
- package/src/builders/update.ts +197 -192
- package/src/columns/binary-set.ts +29 -38
- package/src/columns/binary.ts +25 -35
- package/src/columns/boolean.ts +25 -30
- package/src/columns/date.ts +57 -64
- package/src/columns/index.ts +15 -15
- package/src/columns/json.ts +39 -48
- package/src/columns/list.ts +26 -36
- package/src/columns/map.ts +26 -34
- package/src/columns/number-set.ts +29 -38
- package/src/columns/number.ts +33 -40
- package/src/columns/string-set.ts +38 -47
- package/src/columns/string.ts +37 -49
- package/src/columns/uuid.ts +26 -33
- package/src/core/client.ts +9 -9
- package/src/core/column-builder.ts +194 -220
- package/src/core/column.ts +127 -135
- package/src/core/diff.ts +40 -34
- package/src/core/errors.ts +20 -17
- package/src/core/introspection.ts +62 -58
- package/src/core/operations.ts +17 -23
- package/src/core/parser.ts +82 -89
- package/src/core/relations.ts +164 -154
- package/src/core/retry.ts +52 -52
- package/src/core/snapshot.ts +131 -130
- package/src/core/strategies.ts +222 -218
- package/src/core/table.ts +189 -202
- package/src/core/validation.ts +52 -52
- package/src/db.ts +211 -209
- package/src/expressions/actions.ts +26 -26
- package/src/expressions/builder.ts +62 -54
- package/src/expressions/operators.ts +48 -48
- package/src/expressions/update-builder.ts +78 -76
- package/src/index.ts +1 -1
- package/src/indexes.ts +8 -8
- package/test/batch-resilience.test.ts +138 -0
- package/test/builders/delete.test.ts +100 -0
- package/test/builders/insert.test.ts +216 -0
- package/test/builders/relational-types.test.ts +55 -0
- package/test/builders/relational.integration.test.ts +291 -0
- package/test/builders/relational.test.ts +66 -0
- package/test/builders/select.test.ts +411 -0
- package/test/builders/transaction-errors.test.ts +46 -0
- package/test/builders/transaction-execution.test.ts +99 -0
- package/test/builders/transaction-proxy.test.ts +41 -0
- package/test/builders/update-expression.test.ts +106 -0
- package/test/builders/update.test.ts +179 -0
- package/test/core/diff.test.ts +152 -0
- package/test/core/expressions.test.ts +64 -0
- package/test/core/introspection.test.ts +47 -0
- package/test/core/parser.test.ts +69 -0
- package/test/core/snapshot-gen.test.ts +155 -0
- package/test/core/snapshot.test.ts +52 -0
- package/test/date-column.test.ts +159 -0
- package/test/fluent-writes.integration.test.ts +148 -0
- package/test/integration-retry.test.ts +77 -0
- package/test/integration.test.ts +105 -0
- package/test/item-size-error.test.ts +16 -0
- package/test/item-size-validation.test.ts +82 -0
- package/test/item-size.test.ts +47 -0
- package/test/iterator-pagination.integration.test.ts +132 -0
- package/test/jsdoc-builders.test.ts +55 -0
- package/test/jsdoc-schema.test.ts +107 -0
- package/test/json-column.test.ts +51 -0
- package/test/metadata.test.ts +54 -0
- package/test/mizzle-package.test.ts +20 -0
- package/test/relational-centralized.test.ts +83 -0
- package/test/relational-definition.test.ts +75 -0
- package/test/relational-init.test.ts +30 -0
- package/test/relational-proxy.test.ts +52 -0
- package/test/relations.test.ts +45 -0
- package/test/resilience-config.test.ts +34 -0
- package/test/retry-handler.test.ts +63 -0
- package/test/transaction.integration.test.ts +153 -0
- package/test/unified-select.integration.test.ts +153 -0
- package/test/unified-update.integration.test.ts +139 -0
- package/test/update.integration.test.ts +132 -0
- package/tsconfig.json +12 -8
- package/tsup.config.ts +11 -11
- package/vitest.config.ts +8 -0
package/src/builders/update.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { UpdateCommand } from "@aws-sdk/lib-dynamodb";
|
|
2
|
-
import { ENTITY_SYMBOLS } from "@
|
|
2
|
+
import { ENTITY_SYMBOLS } from "@repo/shared";
|
|
3
3
|
import { Entity, type InferInsertModel } from "../core/table";
|
|
4
4
|
import { Column } from "../core/column";
|
|
5
5
|
import { type Expression } from "../expressions/operators";
|
|
@@ -9,209 +9,214 @@ import { calculateItemSize } from "../core/validation";
|
|
|
9
9
|
import { ItemSizeExceededError } from "../core/errors";
|
|
10
10
|
import { buildExpression } from "../expressions/builder";
|
|
11
11
|
import { UpdateAction } from "../expressions/actions";
|
|
12
|
-
import {
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
12
|
+
import {
|
|
13
|
+
createUpdateState,
|
|
14
|
+
partitionUpdateValues,
|
|
15
|
+
buildUpdateExpressionString,
|
|
16
16
|
} from "../expressions/update-builder";
|
|
17
17
|
|
|
18
|
-
export class UpdateBuilder<
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
>
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
18
|
+
export class UpdateBuilder<TEntity extends Entity, TResult = unknown> extends BaseBuilder<
|
|
19
|
+
TEntity,
|
|
20
|
+
TResult
|
|
21
|
+
> {
|
|
22
|
+
static readonly [ENTITY_SYMBOLS.ENTITY_KIND]: string = "UpdateBuilder";
|
|
23
|
+
|
|
24
|
+
private _state = createUpdateState();
|
|
25
|
+
private _whereClause?: Expression;
|
|
26
|
+
private _returnValues?: "NONE" | "ALL_OLD" | "UPDATED_OLD" | "ALL_NEW" | "UPDATED_NEW";
|
|
27
|
+
private _explicitKey?: Record<string, unknown>;
|
|
28
|
+
|
|
29
|
+
constructor(entity: TEntity, client: IMizzleClient) {
|
|
30
|
+
super(entity, client);
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
/**
|
|
34
|
+
* Manually specifies the primary key for the update operation.
|
|
35
|
+
*
|
|
36
|
+
* @param keyObject The raw DynamoDB key object (e.g., { pk: "USER#1", sk: "METADATA" }).
|
|
37
|
+
* @returns The current builder instance for chaining.
|
|
38
|
+
*/
|
|
39
|
+
key(keyObject: Record<string, unknown>): this {
|
|
40
|
+
this._explicitKey = keyObject;
|
|
41
|
+
return this;
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
/**
|
|
45
|
+
* Sets specific attributes to new values.
|
|
46
|
+
* Translates to a `SET` action in the DynamoDB UpdateExpression.
|
|
47
|
+
*
|
|
48
|
+
* @example
|
|
49
|
+
* ```ts
|
|
50
|
+
* await db.update(users)
|
|
51
|
+
* .set({ name: "Bob", age: 25 })
|
|
52
|
+
* .where(eq(users.id, "1"))
|
|
53
|
+
* .execute();
|
|
54
|
+
* ```
|
|
55
|
+
*
|
|
56
|
+
* @param values Object containing the fields and values to set.
|
|
57
|
+
* @returns The current builder instance for chaining.
|
|
58
|
+
*/
|
|
59
|
+
set(
|
|
60
|
+
values: Partial<{
|
|
61
|
+
[K in keyof InferInsertModel<TEntity>]: InferInsertModel<TEntity>[K] | UpdateAction;
|
|
62
|
+
}>,
|
|
63
|
+
): this {
|
|
64
|
+
partitionUpdateValues(
|
|
65
|
+
values as Record<string, unknown | UpdateAction>,
|
|
66
|
+
this._state,
|
|
67
|
+
this.entity[ENTITY_SYMBOLS.COLUMNS] as unknown as Record<string, Column>,
|
|
68
|
+
);
|
|
69
|
+
return this;
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
/**
|
|
73
|
+
* Adds a value to a numeric attribute or elements to a set.
|
|
74
|
+
* Translates to an `ADD` action in the DynamoDB UpdateExpression.
|
|
75
|
+
*
|
|
76
|
+
* @param values Object containing fields and values to add.
|
|
77
|
+
* @returns The current builder instance for chaining.
|
|
78
|
+
*/
|
|
79
|
+
add(values: Partial<InferInsertModel<TEntity>>): this {
|
|
80
|
+
const columns = this.entity[ENTITY_SYMBOLS.COLUMNS] as unknown as Record<string, Column>;
|
|
81
|
+
for (const [key, val] of Object.entries(values)) {
|
|
82
|
+
const col = columns[key] as unknown as { mapToDynamoValue?: (v: unknown) => unknown };
|
|
83
|
+
this._state.add[key] =
|
|
84
|
+
col && typeof col.mapToDynamoValue === "function" ? col.mapToDynamoValue(val) : val;
|
|
34
85
|
}
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
86
|
+
return this;
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
/**
|
|
90
|
+
* Removes one or more attributes from the item.
|
|
91
|
+
* Translates to a `REMOVE` action in the DynamoDB UpdateExpression.
|
|
92
|
+
*
|
|
93
|
+
* @param fields The names of the fields to remove.
|
|
94
|
+
* @returns The current builder instance for chaining.
|
|
95
|
+
*/
|
|
96
|
+
remove(...fields: (keyof InferInsertModel<TEntity> | (string & {}))[]): this {
|
|
97
|
+
this._state.remove.push(...(fields as string[]));
|
|
98
|
+
return this;
|
|
99
|
+
}
|
|
100
|
+
|
|
101
|
+
/**
|
|
102
|
+
* Deletes elements from a set.
|
|
103
|
+
* Translates to a `DELETE` action in the DynamoDB UpdateExpression.
|
|
104
|
+
*
|
|
105
|
+
* @param values Object containing fields and the values to delete from the set.
|
|
106
|
+
* @returns The current builder instance for chaining.
|
|
107
|
+
*/
|
|
108
|
+
delete(values: Partial<InferInsertModel<TEntity>>): this {
|
|
109
|
+
const columns = this.entity[ENTITY_SYMBOLS.COLUMNS] as unknown as Record<string, Column>;
|
|
110
|
+
for (const [key, val] of Object.entries(values)) {
|
|
111
|
+
const col = columns[key] as unknown as { mapToDynamoValue?: (v: unknown) => unknown };
|
|
112
|
+
this._state.delete[key] =
|
|
113
|
+
col && typeof col.mapToDynamoValue === "function" ? col.mapToDynamoValue(val) : val;
|
|
45
114
|
}
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
115
|
+
return this;
|
|
116
|
+
}
|
|
117
|
+
|
|
118
|
+
/**
|
|
119
|
+
* Adds a condition to the update operation.
|
|
120
|
+
*
|
|
121
|
+
* @param expression The condition expression.
|
|
122
|
+
* @returns The current builder instance for chaining.
|
|
123
|
+
*/
|
|
124
|
+
where(expression: Expression): this {
|
|
125
|
+
this._whereClause = expression;
|
|
126
|
+
return this;
|
|
127
|
+
}
|
|
128
|
+
|
|
129
|
+
/**
|
|
130
|
+
* Configures what values should be returned after the update.
|
|
131
|
+
*
|
|
132
|
+
* @param value One of: "NONE", "ALL_OLD", "UPDATED_OLD", "ALL_NEW", "UPDATED_NEW".
|
|
133
|
+
* @returns The current builder instance for chaining.
|
|
134
|
+
*/
|
|
135
|
+
returning(value: "NONE" | "ALL_OLD" | "UPDATED_OLD" | "ALL_NEW" | "UPDATED_NEW"): this {
|
|
136
|
+
this._returnValues = value;
|
|
137
|
+
return this;
|
|
138
|
+
}
|
|
139
|
+
|
|
140
|
+
/** @internal */
|
|
141
|
+
get state() {
|
|
142
|
+
return this._state;
|
|
143
|
+
}
|
|
144
|
+
|
|
145
|
+
/** @internal */
|
|
146
|
+
get whereClause() {
|
|
147
|
+
return this._whereClause;
|
|
148
|
+
}
|
|
149
|
+
|
|
150
|
+
/** @internal */
|
|
151
|
+
public override createExpressionContext(prefix = "") {
|
|
152
|
+
return super.createExpressionContext(prefix);
|
|
153
|
+
}
|
|
154
|
+
|
|
155
|
+
/**
|
|
156
|
+
* Executes the update operation.
|
|
157
|
+
*
|
|
158
|
+
* @returns A promise that resolves to the requested attributes (based on `.returning()`).
|
|
159
|
+
* @throws {ItemSizeExceededError} if the update exceeds 400KB.
|
|
160
|
+
*/
|
|
161
|
+
public override async execute(): Promise<TResult> {
|
|
162
|
+
const columns = this.entity[ENTITY_SYMBOLS.COLUMNS] as unknown as Record<string, Column>;
|
|
163
|
+
for (const [key, col] of Object.entries(columns)) {
|
|
164
|
+
const column = col as unknown as {
|
|
165
|
+
onUpdateFn?: () => unknown;
|
|
166
|
+
mapToDynamoValue?: (v: unknown) => unknown;
|
|
167
|
+
};
|
|
168
|
+
if (column.onUpdateFn && !this._state.set[key] && !this._state.remove.includes(key)) {
|
|
169
|
+
const val = column.onUpdateFn();
|
|
170
|
+
this._state.set[key] = {
|
|
171
|
+
value: typeof column.mapToDynamoValue === "function" ? column.mapToDynamoValue(val) : val,
|
|
172
|
+
};
|
|
173
|
+
}
|
|
65
174
|
}
|
|
66
175
|
|
|
67
|
-
|
|
68
|
-
* Adds a value to a numeric attribute or elements to a set.
|
|
69
|
-
* Translates to an `ADD` action in the DynamoDB UpdateExpression.
|
|
70
|
-
*
|
|
71
|
-
* @param values Object containing fields and values to add.
|
|
72
|
-
* @returns The current builder instance for chaining.
|
|
73
|
-
*/
|
|
74
|
-
add(values: Partial<InferInsertModel<TEntity>>): this {
|
|
75
|
-
const columns = this.entity[ENTITY_SYMBOLS.COLUMNS] as unknown as Record<string, Column>;
|
|
76
|
-
for (const [key, val] of Object.entries(values)) {
|
|
77
|
-
const col = columns[key] as unknown as { mapToDynamoValue?: (v: unknown) => unknown };
|
|
78
|
-
this._state.add[key] = (col && typeof col.mapToDynamoValue === "function")
|
|
79
|
-
? col.mapToDynamoValue(val)
|
|
80
|
-
: val;
|
|
81
|
-
}
|
|
82
|
-
return this;
|
|
83
|
-
}
|
|
176
|
+
const keys = this.resolveUpdateKeys();
|
|
84
177
|
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
* Translates to a `REMOVE` action in the DynamoDB UpdateExpression.
|
|
88
|
-
*
|
|
89
|
-
* @param fields The names of the fields to remove.
|
|
90
|
-
* @returns The current builder instance for chaining.
|
|
91
|
-
*/
|
|
92
|
-
remove(...fields: (keyof InferInsertModel<TEntity> | (string & {}))[]): this {
|
|
93
|
-
this._state.remove.push(...(fields as string[]));
|
|
94
|
-
return this;
|
|
95
|
-
}
|
|
178
|
+
const { expressionAttributeNames, expressionAttributeValues, addName, addValue } =
|
|
179
|
+
this.createExpressionContext("up_");
|
|
96
180
|
|
|
97
|
-
|
|
98
|
-
* Deletes elements from a set.
|
|
99
|
-
* Translates to a `DELETE` action in the DynamoDB UpdateExpression.
|
|
100
|
-
*
|
|
101
|
-
* @param values Object containing fields and the values to delete from the set.
|
|
102
|
-
* @returns The current builder instance for chaining.
|
|
103
|
-
*/
|
|
104
|
-
delete(values: Partial<InferInsertModel<TEntity>>): this {
|
|
105
|
-
const columns = this.entity[ENTITY_SYMBOLS.COLUMNS] as unknown as Record<string, Column>;
|
|
106
|
-
for (const [key, val] of Object.entries(values)) {
|
|
107
|
-
const col = columns[key] as unknown as { mapToDynamoValue?: (v: unknown) => unknown };
|
|
108
|
-
this._state.delete[key] = (col && typeof col.mapToDynamoValue === "function")
|
|
109
|
-
? col.mapToDynamoValue(val)
|
|
110
|
-
: val;
|
|
111
|
-
}
|
|
112
|
-
return this;
|
|
113
|
-
}
|
|
114
|
-
|
|
115
|
-
/**
|
|
116
|
-
* Adds a condition to the update operation.
|
|
117
|
-
*
|
|
118
|
-
* @param expression The condition expression.
|
|
119
|
-
* @returns The current builder instance for chaining.
|
|
120
|
-
*/
|
|
121
|
-
where(expression: Expression): this {
|
|
122
|
-
this._whereClause = expression;
|
|
123
|
-
return this;
|
|
124
|
-
}
|
|
181
|
+
const updateExpression = buildUpdateExpressionString(this._state, addName, addValue);
|
|
125
182
|
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
* @param value One of: "NONE", "ALL_OLD", "UPDATED_OLD", "ALL_NEW", "UPDATED_NEW".
|
|
130
|
-
* @returns The current builder instance for chaining.
|
|
131
|
-
*/
|
|
132
|
-
returning(value: "NONE" | "ALL_OLD" | "UPDATED_OLD" | "ALL_NEW" | "UPDATED_NEW"): this {
|
|
133
|
-
this._returnValues = value;
|
|
134
|
-
return this;
|
|
183
|
+
let conditionExpression: string | undefined;
|
|
184
|
+
if (this._whereClause) {
|
|
185
|
+
conditionExpression = buildExpression(this._whereClause, addName, addValue);
|
|
135
186
|
}
|
|
136
187
|
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
188
|
+
// Estimate size for Update
|
|
189
|
+
// Update size is basically keys + attribute values.
|
|
190
|
+
const size = calculateItemSize({ ...keys, ...expressionAttributeValues });
|
|
191
|
+
if (size > 400 * 1024) {
|
|
192
|
+
throw new ItemSizeExceededError(
|
|
193
|
+
`Estimated update size of ${Math.round(size / 1024)}KB exceeds the 400KB limit.`,
|
|
194
|
+
);
|
|
140
195
|
}
|
|
141
196
|
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
197
|
+
const command = new UpdateCommand({
|
|
198
|
+
TableName: this.tableName,
|
|
199
|
+
Key: keys,
|
|
200
|
+
UpdateExpression: updateExpression,
|
|
201
|
+
ConditionExpression: conditionExpression,
|
|
202
|
+
ExpressionAttributeNames:
|
|
203
|
+
Object.keys(expressionAttributeNames).length > 0 ? expressionAttributeNames : undefined,
|
|
204
|
+
ExpressionAttributeValues:
|
|
205
|
+
Object.keys(expressionAttributeValues).length > 0 ? expressionAttributeValues : undefined,
|
|
206
|
+
ReturnValues: this._returnValues,
|
|
207
|
+
});
|
|
208
|
+
|
|
209
|
+
const response = (await this.client.send(command)) as any;
|
|
210
|
+
return response.Attributes as TResult;
|
|
211
|
+
}
|
|
212
|
+
|
|
213
|
+
/** @internal */
|
|
214
|
+
public resolveUpdateKeys(): Record<string, unknown> {
|
|
215
|
+
if (this._explicitKey) {
|
|
216
|
+
return this._explicitKey;
|
|
145
217
|
}
|
|
146
218
|
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
/**
|
|
153
|
-
* Executes the update operation.
|
|
154
|
-
*
|
|
155
|
-
* @returns A promise that resolves to the requested attributes (based on `.returning()`).
|
|
156
|
-
* @throws {ItemSizeExceededError} if the update exceeds 400KB.
|
|
157
|
-
*/
|
|
158
|
-
public override async execute(): Promise<TResult> {
|
|
159
|
-
const columns = this.entity[ENTITY_SYMBOLS.COLUMNS] as unknown as Record<string, Column>;
|
|
160
|
-
for (const [key, col] of Object.entries(columns)) {
|
|
161
|
-
const column = col as unknown as { onUpdateFn?: () => unknown, mapToDynamoValue?: (v: unknown) => unknown };
|
|
162
|
-
if (column.onUpdateFn && !this._state.set[key] && !this._state.remove.includes(key)) {
|
|
163
|
-
const val = column.onUpdateFn();
|
|
164
|
-
this._state.set[key] = {
|
|
165
|
-
value: typeof column.mapToDynamoValue === "function" ? column.mapToDynamoValue(val) : val
|
|
166
|
-
};
|
|
167
|
-
}
|
|
168
|
-
}
|
|
169
|
-
|
|
170
|
-
const keys = this.resolveUpdateKeys();
|
|
171
|
-
|
|
172
|
-
const { expressionAttributeNames, expressionAttributeValues, addName, addValue } = this.createExpressionContext("up_");
|
|
173
|
-
|
|
174
|
-
const updateExpression = buildUpdateExpressionString(this._state, addName, addValue);
|
|
175
|
-
|
|
176
|
-
let conditionExpression: string | undefined;
|
|
177
|
-
if (this._whereClause) {
|
|
178
|
-
conditionExpression = buildExpression(this._whereClause, addName, addValue);
|
|
179
|
-
}
|
|
180
|
-
|
|
181
|
-
// Estimate size for Update
|
|
182
|
-
// Update size is basically keys + attribute values.
|
|
183
|
-
const size = calculateItemSize({ ...keys, ...expressionAttributeValues });
|
|
184
|
-
if (size > 400 * 1024) {
|
|
185
|
-
throw new ItemSizeExceededError(`Estimated update size of ${Math.round(size / 1024)}KB exceeds the 400KB limit.`);
|
|
186
|
-
}
|
|
187
|
-
|
|
188
|
-
const command = new UpdateCommand({
|
|
189
|
-
TableName: this.tableName,
|
|
190
|
-
Key: keys,
|
|
191
|
-
UpdateExpression: updateExpression,
|
|
192
|
-
ConditionExpression: conditionExpression,
|
|
193
|
-
ExpressionAttributeNames:
|
|
194
|
-
Object.keys(expressionAttributeNames).length > 0
|
|
195
|
-
? expressionAttributeNames
|
|
196
|
-
: undefined,
|
|
197
|
-
ExpressionAttributeValues:
|
|
198
|
-
Object.keys(expressionAttributeValues).length > 0
|
|
199
|
-
? expressionAttributeValues
|
|
200
|
-
: undefined,
|
|
201
|
-
ReturnValues: this._returnValues,
|
|
202
|
-
});
|
|
203
|
-
|
|
204
|
-
const response = await this.client.send(command) as any;
|
|
205
|
-
return response.Attributes as TResult;
|
|
206
|
-
}
|
|
207
|
-
|
|
208
|
-
/** @internal */
|
|
209
|
-
public resolveUpdateKeys(): Record<string, unknown> {
|
|
210
|
-
if (this._explicitKey) {
|
|
211
|
-
return this._explicitKey;
|
|
212
|
-
}
|
|
213
|
-
|
|
214
|
-
const resolved = this.resolveKeys(this._whereClause);
|
|
215
|
-
return resolved.keys;
|
|
216
|
-
}
|
|
217
|
-
}
|
|
219
|
+
const resolved = this.resolveKeys(this._whereClause);
|
|
220
|
+
return resolved.keys;
|
|
221
|
+
}
|
|
222
|
+
}
|
|
@@ -1,64 +1,55 @@
|
|
|
1
|
+
import { Column, type ColumnBaseConfig } from "../core/column";
|
|
1
2
|
import {
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
import {
|
|
6
|
-
ColumnBuider,
|
|
7
|
-
type ColumnBuilderBaseConfig,
|
|
8
|
-
type MakeColumnConfig,
|
|
3
|
+
ColumnBuider,
|
|
4
|
+
type ColumnBuilderBaseConfig,
|
|
5
|
+
type MakeColumnConfig,
|
|
9
6
|
} from "../core/column-builder";
|
|
10
7
|
import type { AnyTable } from "../core/table";
|
|
11
8
|
|
|
12
|
-
export type BinarySetColumnInitial<TName extends string> =
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
}>;
|
|
9
|
+
export type BinarySetColumnInitial<TName extends string> = BinarySetColumnBuilder<{
|
|
10
|
+
name: TName;
|
|
11
|
+
dataType: "binarySet";
|
|
12
|
+
columnType: "BS";
|
|
13
|
+
data: Set<Uint8Array>;
|
|
14
|
+
}>;
|
|
19
15
|
|
|
20
16
|
export class BinarySetColumnBuilder<
|
|
21
|
-
|
|
17
|
+
T extends ColumnBuilderBaseConfig<"binarySet", "BS">,
|
|
22
18
|
> extends ColumnBuider<T> {
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
19
|
+
constructor(name: T["name"]) {
|
|
20
|
+
super(name, "binarySet", "BS");
|
|
21
|
+
}
|
|
26
22
|
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
23
|
+
override build<TTableName extends string>(
|
|
24
|
+
table: AnyTable,
|
|
25
|
+
): BinarySetColumn<MakeColumnConfig<T, TTableName>> {
|
|
26
|
+
return new BinarySetColumn<MakeColumnConfig<T, TTableName>>(
|
|
27
|
+
table,
|
|
28
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
29
|
+
this.config as any,
|
|
30
|
+
);
|
|
31
|
+
}
|
|
36
32
|
}
|
|
37
33
|
|
|
38
|
-
export class BinarySetColumn<
|
|
39
|
-
T extends ColumnBaseConfig<"binarySet", "BS">,
|
|
40
|
-
> extends Column<T> {
|
|
41
|
-
}
|
|
34
|
+
export class BinarySetColumn<T extends ColumnBaseConfig<"binarySet", "BS">> extends Column<T> {}
|
|
42
35
|
|
|
43
36
|
export function binarySet(): BinarySetColumnInitial<"">;
|
|
44
|
-
export function binarySet<TName extends string>(
|
|
45
|
-
name: TName,
|
|
46
|
-
): BinarySetColumnInitial<TName>;
|
|
37
|
+
export function binarySet<TName extends string>(name: TName): BinarySetColumnInitial<TName>;
|
|
47
38
|
/**
|
|
48
39
|
* Defines a Binary Set column ("BS") in DynamoDB.
|
|
49
|
-
*
|
|
40
|
+
*
|
|
50
41
|
* Represents a set of unique binary blobs (Uint8Array/Buffer).
|
|
51
|
-
*
|
|
42
|
+
*
|
|
52
43
|
* @example
|
|
53
44
|
* ```ts
|
|
54
45
|
* const data = defineTable("data", {
|
|
55
46
|
* hashes: binarySet("hashes"),
|
|
56
47
|
* });
|
|
57
48
|
* ```
|
|
58
|
-
*
|
|
49
|
+
*
|
|
59
50
|
* @param name The name of the attribute in DynamoDB. If omitted, it will use the property name in the definition object.
|
|
60
51
|
* @returns A BinarySetColumnBuilder instance.
|
|
61
52
|
*/
|
|
62
53
|
export function binarySet(name?: string) {
|
|
63
|
-
|
|
54
|
+
return new BinarySetColumnBuilder(name ?? "");
|
|
64
55
|
}
|
package/src/columns/binary.ts
CHANGED
|
@@ -1,64 +1,54 @@
|
|
|
1
|
+
import { Column, type ColumnBaseConfig } from "../core/column";
|
|
1
2
|
import {
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
import {
|
|
6
|
-
ColumnBuider,
|
|
7
|
-
type ColumnBuilderBaseConfig,
|
|
8
|
-
type MakeColumnConfig,
|
|
3
|
+
ColumnBuider,
|
|
4
|
+
type ColumnBuilderBaseConfig,
|
|
5
|
+
type MakeColumnConfig,
|
|
9
6
|
} from "../core/column-builder";
|
|
10
7
|
import type { AnyTable } from "../core/table";
|
|
11
8
|
|
|
12
9
|
export type BinaryBuilderInitial<TName extends string> = BinaryColumnBuilder<{
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
10
|
+
name: TName;
|
|
11
|
+
dataType: "binary";
|
|
12
|
+
columnType: "B";
|
|
13
|
+
data: Buffer;
|
|
17
14
|
}>;
|
|
18
15
|
|
|
19
16
|
export class BinaryColumnBuilder<
|
|
20
|
-
|
|
17
|
+
T extends ColumnBuilderBaseConfig<"binary", "B">,
|
|
21
18
|
> extends ColumnBuider<T> {
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
19
|
+
constructor(name: T["name"]) {
|
|
20
|
+
super(name, "binary", "B");
|
|
21
|
+
}
|
|
25
22
|
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
);
|
|
34
|
-
}
|
|
23
|
+
build<TTableName extends string>(table: AnyTable): BinaryColumn<MakeColumnConfig<T, TTableName>> {
|
|
24
|
+
return new BinaryColumn<MakeColumnConfig<T, TTableName>>(
|
|
25
|
+
table,
|
|
26
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
27
|
+
this.config as any,
|
|
28
|
+
);
|
|
29
|
+
}
|
|
35
30
|
}
|
|
36
31
|
|
|
37
|
-
export class BinaryColumn<
|
|
38
|
-
T extends ColumnBaseConfig<"binary", "B">,
|
|
39
|
-
> extends Column<T> {
|
|
40
|
-
}
|
|
32
|
+
export class BinaryColumn<T extends ColumnBaseConfig<"binary", "B">> extends Column<T> {}
|
|
41
33
|
|
|
42
34
|
export function binary(): BinaryBuilderInitial<"">;
|
|
43
|
-
export function binary<TName extends string>(
|
|
44
|
-
name: TName,
|
|
45
|
-
): BinaryBuilderInitial<TName>;
|
|
35
|
+
export function binary<TName extends string>(name: TName): BinaryBuilderInitial<TName>;
|
|
46
36
|
/**
|
|
47
37
|
* Defines a Binary column ("B") in DynamoDB.
|
|
48
|
-
*
|
|
38
|
+
*
|
|
49
39
|
* Used for storing arbitrary binary data, such as images, compressed files, or raw bytes.
|
|
50
40
|
* Mizzle handles `Uint8Array` or `Buffer` (in Node) for this type.
|
|
51
|
-
*
|
|
41
|
+
*
|
|
52
42
|
* @example
|
|
53
43
|
* ```ts
|
|
54
44
|
* const files = defineTable("files", {
|
|
55
45
|
* content: binary("content"),
|
|
56
46
|
* });
|
|
57
47
|
* ```
|
|
58
|
-
*
|
|
48
|
+
*
|
|
59
49
|
* @param name The name of the attribute in DynamoDB. If omitted, it will use the property name in the definition object.
|
|
60
50
|
* @returns A BinaryColumnBuilder instance.
|
|
61
51
|
*/
|
|
62
52
|
export function binary(name?: string) {
|
|
63
|
-
|
|
53
|
+
return new BinaryColumnBuilder(name ?? "");
|
|
64
54
|
}
|