@aurios/mizzle 1.0.0 → 1.1.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.
- package/CHANGELOG.md +15 -0
- package/package.json +1 -1
- package/src/builders/base.ts +1 -1
- package/src/builders/batch-get.ts +6 -6
- package/src/builders/batch-write.ts +8 -7
- package/src/builders/delete.ts +10 -0
- package/src/builders/insert.ts +31 -3
- package/src/builders/select.ts +84 -0
- package/src/builders/update.ts +60 -0
- package/src/columns/binary-set.ts +16 -1
- package/src/columns/binary.ts +17 -1
- package/src/columns/boolean.ts +14 -1
- package/src/columns/date.ts +20 -1
- package/src/columns/json.ts +24 -1
- package/src/columns/list.ts +17 -1
- package/src/columns/map.ts +18 -1
- package/src/columns/number-set.ts +16 -1
- package/src/columns/number.ts +15 -1
- package/src/columns/string-set.ts +16 -1
- package/src/columns/string.ts +16 -1
- package/src/columns/uuid.ts +17 -1
- package/src/core/client.ts +4 -3
- package/src/core/errors.ts +1 -1
- package/src/core/parser.ts +8 -4
- package/src/core/relations.ts +153 -25
- package/src/core/retry.ts +5 -4
- package/src/core/snapshot.ts +1 -1
- package/src/core/table.ts +33 -0
- package/src/db.ts +84 -12
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,20 @@
|
|
|
1
1
|
# mizzle
|
|
2
2
|
|
|
3
|
+
## 2.0.0
|
|
4
|
+
|
|
5
|
+
### Major Changes
|
|
6
|
+
|
|
7
|
+
- 5dd0c9f: rename packages to @aurios scope
|
|
8
|
+
|
|
9
|
+
### Patch Changes
|
|
10
|
+
|
|
11
|
+
- 114efb9: Completed 100% JSDoc/TSDoc coverage for all public APIs and improved internal type safety.
|
|
12
|
+
|
|
13
|
+
- **@aurios/mizzle**: Added comprehensive documentation to Query Builders, Schema Definitions, and the main entry point. Resolved numerous linting issues by replacing `any` with safer alternatives.
|
|
14
|
+
- **@aurios/mizzling**: Fixed CLI entry point in E2E and integration tests, ensuring CI stability.
|
|
15
|
+
- **@mizzle/shared**: Enhanced utility type safety.
|
|
16
|
+
- **Infrastructure**: Updated Turbo configuration to handle new environment variables.
|
|
17
|
+
|
|
3
18
|
## 1.0.1
|
|
4
19
|
|
|
5
20
|
### Patch Changes
|
package/package.json
CHANGED
package/src/builders/base.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { BatchGetCommand } from "@aws-sdk/lib-dynamodb";
|
|
2
|
-
import { ENTITY_SYMBOLS
|
|
2
|
+
import { ENTITY_SYMBOLS } from "@mizzle/shared";
|
|
3
3
|
import { Entity, type InferSelectModel } from "../core/table";
|
|
4
4
|
import { BaseBuilder } from "./base";
|
|
5
5
|
import type { IMizzleClient } from "../core/client";
|
|
@@ -33,7 +33,7 @@ export class BatchGetBase<
|
|
|
33
33
|
|
|
34
34
|
public override async execute(): Promise<BatchGetResult<TResult>> {
|
|
35
35
|
const succeeded: TResult[] = [];
|
|
36
|
-
const failed:
|
|
36
|
+
const failed: Partial<TResult>[] = [];
|
|
37
37
|
|
|
38
38
|
// Group keys by resolved DynamoDB keys
|
|
39
39
|
let currentKeys = this.keysData.map(k => this.resolveKeys(undefined, k as Record<string, unknown>).keys);
|
|
@@ -52,7 +52,7 @@ export class BatchGetBase<
|
|
|
52
52
|
}
|
|
53
53
|
});
|
|
54
54
|
|
|
55
|
-
const response = await this.client.send(command);
|
|
55
|
+
const response = await this.client.send(command) as { Responses?: Record<string, unknown[]>, UnprocessedKeys?: Record<string, { Keys?: Record<string, unknown>[] }> };
|
|
56
56
|
|
|
57
57
|
if (response.Responses?.[this.tableName]) {
|
|
58
58
|
succeeded.push(...(response.Responses[this.tableName] as TResult[]));
|
|
@@ -61,16 +61,16 @@ export class BatchGetBase<
|
|
|
61
61
|
const unprocessed = response.UnprocessedKeys?.[this.tableName]?.Keys;
|
|
62
62
|
|
|
63
63
|
if (unprocessed && unprocessed.length > 0) {
|
|
64
|
-
currentKeys = unprocessed
|
|
64
|
+
currentKeys = unprocessed;
|
|
65
65
|
} else {
|
|
66
66
|
currentKeys = [];
|
|
67
67
|
}
|
|
68
68
|
}
|
|
69
69
|
|
|
70
70
|
if (currentKeys.length > 0) {
|
|
71
|
-
failed.push(...currentKeys);
|
|
71
|
+
failed.push(...(currentKeys as Partial<TResult>[]));
|
|
72
72
|
}
|
|
73
73
|
|
|
74
|
-
return { succeeded, failed
|
|
74
|
+
return { succeeded, failed };
|
|
75
75
|
}
|
|
76
76
|
}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { BatchWriteCommand } from "@aws-sdk/lib-dynamodb";
|
|
2
|
-
import { ENTITY_SYMBOLS
|
|
2
|
+
import { ENTITY_SYMBOLS } from "@mizzle/shared";
|
|
3
3
|
import { Entity, type InferInsertModel } from "../core/table";
|
|
4
4
|
import { BaseBuilder } from "./base";
|
|
5
5
|
import type { IMizzleClient } from "../core/client";
|
|
@@ -10,9 +10,9 @@ export type BatchWriteOperation<TEntity extends Entity> =
|
|
|
10
10
|
| { type: "put", item: InferInsertModel<TEntity> }
|
|
11
11
|
| { type: "delete", keys: Partial<InferInsertModel<TEntity>> };
|
|
12
12
|
|
|
13
|
-
export interface BatchWriteResult<
|
|
13
|
+
export interface BatchWriteResult<_T> {
|
|
14
14
|
succeededCount: number;
|
|
15
|
-
failed:
|
|
15
|
+
failed: unknown[]; // Operations that failed after all retries
|
|
16
16
|
}
|
|
17
17
|
|
|
18
18
|
export class BatchWriteBuilder {
|
|
@@ -38,7 +38,7 @@ export class BatchWriteBase<
|
|
|
38
38
|
|
|
39
39
|
public override async execute(): Promise<BatchWriteResult<InferInsertModel<TEntity>>> {
|
|
40
40
|
let succeededCount = 0;
|
|
41
|
-
let failed:
|
|
41
|
+
let failed: unknown[] = [];
|
|
42
42
|
|
|
43
43
|
const requests = this.ops.map(op => {
|
|
44
44
|
if (op.type === "put") {
|
|
@@ -64,7 +64,7 @@ export class BatchWriteBase<
|
|
|
64
64
|
}
|
|
65
65
|
});
|
|
66
66
|
|
|
67
|
-
let currentRequests = [...requests];
|
|
67
|
+
let currentRequests: unknown[] = [...requests];
|
|
68
68
|
let attempts = 0;
|
|
69
69
|
const maxBatchAttempts = 5;
|
|
70
70
|
|
|
@@ -73,11 +73,12 @@ export class BatchWriteBase<
|
|
|
73
73
|
|
|
74
74
|
const command = new BatchWriteCommand({
|
|
75
75
|
RequestItems: {
|
|
76
|
-
[this.tableName]: currentRequests
|
|
76
|
+
[this.tableName]: currentRequests as any[]
|
|
77
77
|
}
|
|
78
78
|
});
|
|
79
79
|
|
|
80
|
-
|
|
80
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
81
|
+
const response = await this.client.send(command) as { UnprocessedItems?: Record<string, any[]> };
|
|
81
82
|
|
|
82
83
|
const unprocessed = response.UnprocessedItems?.[this.tableName] || [];
|
|
83
84
|
succeededCount += (currentRequests.length - unprocessed.length);
|
package/src/builders/delete.ts
CHANGED
|
@@ -23,6 +23,11 @@ export class DeleteBuilder<
|
|
|
23
23
|
this._keys = keys;
|
|
24
24
|
}
|
|
25
25
|
|
|
26
|
+
/**
|
|
27
|
+
* Instructs Mizzle to return the deleted item after execution.
|
|
28
|
+
*
|
|
29
|
+
* @returns The current builder instance.
|
|
30
|
+
*/
|
|
26
31
|
returning(): this {
|
|
27
32
|
this._returnValues = "ALL_OLD";
|
|
28
33
|
return this;
|
|
@@ -46,6 +51,11 @@ export class DeleteBuilder<
|
|
|
46
51
|
return super.createExpressionContext(prefix);
|
|
47
52
|
}
|
|
48
53
|
|
|
54
|
+
/**
|
|
55
|
+
* Executes the delete operation.
|
|
56
|
+
*
|
|
57
|
+
* @returns A promise that resolves to the deleted item if `.returning()` was called, otherwise undefined.
|
|
58
|
+
*/
|
|
49
59
|
public override async execute(): Promise<TResult> {
|
|
50
60
|
const resolution = this.resolveKeys(undefined, this._keys);
|
|
51
61
|
|
package/src/builders/insert.ts
CHANGED
|
@@ -16,11 +16,26 @@ export class InsertBuilder<TEntity extends Entity> {
|
|
|
16
16
|
private client: IMizzleClient,
|
|
17
17
|
) {}
|
|
18
18
|
|
|
19
|
+
/**
|
|
20
|
+
* Sets the values to be inserted into the database.
|
|
21
|
+
*
|
|
22
|
+
* @example
|
|
23
|
+
* ```ts
|
|
24
|
+
* await db.insert(users).values({ id: "1", name: "Alice" }).execute();
|
|
25
|
+
* ```
|
|
26
|
+
*
|
|
27
|
+
* @param values The object containing the attributes to insert.
|
|
28
|
+
* @returns An InsertBase instance for further chaining.
|
|
29
|
+
*/
|
|
19
30
|
values(values: InferInsertModel<TEntity>): InsertBase<TEntity> {
|
|
20
31
|
return new InsertBase(this.entity, this.client, values);
|
|
21
32
|
}
|
|
22
33
|
}
|
|
23
34
|
|
|
35
|
+
interface MinimalPhysicalTable {
|
|
36
|
+
[TABLE_SYMBOLS.INDEXES]?: Record<string, { config: { pk: string; sk?: string } }>;
|
|
37
|
+
}
|
|
38
|
+
|
|
24
39
|
export class InsertBase<
|
|
25
40
|
TEntity extends Entity,
|
|
26
41
|
TResult = undefined,
|
|
@@ -42,6 +57,11 @@ export class InsertBase<
|
|
|
42
57
|
return this.valuesData;
|
|
43
58
|
}
|
|
44
59
|
|
|
60
|
+
/**
|
|
61
|
+
* Instructs Mizzle to return the inserted item after execution.
|
|
62
|
+
*
|
|
63
|
+
* @returns The current builder instance with an updated result type.
|
|
64
|
+
*/
|
|
45
65
|
returning(): InsertBase<TEntity, InferInsertModel<TEntity>> {
|
|
46
66
|
this.shouldReturnValues = true;
|
|
47
67
|
return this as unknown as InsertBase<TEntity, InferInsertModel<TEntity>>;
|
|
@@ -56,13 +76,13 @@ export class InsertBase<
|
|
|
56
76
|
|
|
57
77
|
// Also resolve GSI keys if they are defined in strategies but not in resolution.keys
|
|
58
78
|
const strategies = this.entity[ENTITY_SYMBOLS.ENTITY_STRATEGY] as unknown as Record<string, { pk: KeyStrategy, sk?: KeyStrategy }>;
|
|
59
|
-
const physicalTable = this.entity[ENTITY_SYMBOLS.PHYSICAL_TABLE];
|
|
60
|
-
const indexes =
|
|
79
|
+
const physicalTable = this.entity[ENTITY_SYMBOLS.PHYSICAL_TABLE] as unknown as MinimalPhysicalTable;
|
|
80
|
+
const indexes = physicalTable?.[TABLE_SYMBOLS.INDEXES] || {};
|
|
61
81
|
|
|
62
82
|
for (const [indexName, strategy] of Object.entries(strategies)) {
|
|
63
83
|
if (indexName === "pk" || indexName === "sk") continue;
|
|
64
84
|
|
|
65
|
-
const indexBuilder = indexes[indexName]
|
|
85
|
+
const indexBuilder = indexes[indexName];
|
|
66
86
|
if (indexBuilder) {
|
|
67
87
|
if (strategy.pk && indexBuilder.config.pk) {
|
|
68
88
|
const pkValue = this.resolveStrategyValue(strategy.pk, itemToSave);
|
|
@@ -78,6 +98,12 @@ export class InsertBase<
|
|
|
78
98
|
return finalItem;
|
|
79
99
|
}
|
|
80
100
|
|
|
101
|
+
/**
|
|
102
|
+
* Executes the insert operation.
|
|
103
|
+
*
|
|
104
|
+
* @returns A promise that resolves to the inserted item if `.returning()` was called, otherwise undefined.
|
|
105
|
+
* @throws {ItemSizeExceededError} if the item exceeds 400KB.
|
|
106
|
+
*/
|
|
81
107
|
override async execute(): Promise<TResult> {
|
|
82
108
|
const finalItem = this.buildItem();
|
|
83
109
|
|
|
@@ -138,7 +164,9 @@ export class InsertBase<
|
|
|
138
164
|
}
|
|
139
165
|
|
|
140
166
|
const finalValue = item[key];
|
|
167
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
141
168
|
item[key] = typeof (col as any).mapToDynamoValue === "function"
|
|
169
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
142
170
|
? (col as any).mapToDynamoValue(finalValue)
|
|
143
171
|
: finalValue;
|
|
144
172
|
|
package/src/builders/select.ts
CHANGED
|
@@ -23,6 +23,17 @@ export class SelectBuilder<TSelection extends SelectedFields | undefined> {
|
|
|
23
23
|
private fields?: TSelection,
|
|
24
24
|
) {}
|
|
25
25
|
|
|
26
|
+
/**
|
|
27
|
+
* Specifies the entity to select from.
|
|
28
|
+
*
|
|
29
|
+
* @example
|
|
30
|
+
* ```ts
|
|
31
|
+
* const results = await db.select().from(users).execute();
|
|
32
|
+
* ```
|
|
33
|
+
*
|
|
34
|
+
* @param entity The Mizzle entity (table) to query.
|
|
35
|
+
* @returns A SelectBase instance to further chain the query.
|
|
36
|
+
*/
|
|
26
37
|
from<TEntity extends Entity>(entity: TEntity) {
|
|
27
38
|
return new SelectBase(entity, this.client, this.fields);
|
|
28
39
|
}
|
|
@@ -50,36 +61,103 @@ export class SelectBase<
|
|
|
50
61
|
super(entity, client);
|
|
51
62
|
}
|
|
52
63
|
|
|
64
|
+
/**
|
|
65
|
+
* Adds a filter criteria to the query.
|
|
66
|
+
*
|
|
67
|
+
* For DynamoDB, this will be used as a `KeyConditionExpression` if the
|
|
68
|
+
* primary keys are provided, otherwise it will be used as a `FilterExpression`.
|
|
69
|
+
*
|
|
70
|
+
* @example
|
|
71
|
+
* ```ts
|
|
72
|
+
* import { eq, and, gt } from "@aurios/mizzle";
|
|
73
|
+
*
|
|
74
|
+
* const results = await db.select()
|
|
75
|
+
* .from(users)
|
|
76
|
+
* .where(and(eq(users.id, 1), gt(users.age, 18)))
|
|
77
|
+
* .execute();
|
|
78
|
+
* ```
|
|
79
|
+
*
|
|
80
|
+
* @param expression The expression to filter by.
|
|
81
|
+
* @returns The current builder instance for chaining.
|
|
82
|
+
*/
|
|
53
83
|
where(expression: Expression): this {
|
|
54
84
|
this._whereClause = expression;
|
|
55
85
|
return this;
|
|
56
86
|
}
|
|
57
87
|
|
|
88
|
+
/**
|
|
89
|
+
* Limits the total number of items returned by the query.
|
|
90
|
+
*
|
|
91
|
+
* @example
|
|
92
|
+
* ```ts
|
|
93
|
+
* const results = await db.select().from(users).limit(10).execute();
|
|
94
|
+
* ```
|
|
95
|
+
*
|
|
96
|
+
* @param val The maximum number of items to return.
|
|
97
|
+
* @returns The current builder instance for chaining.
|
|
98
|
+
*/
|
|
58
99
|
limit(val: number): this {
|
|
59
100
|
this._limitVal = val;
|
|
60
101
|
return this;
|
|
61
102
|
}
|
|
62
103
|
|
|
104
|
+
/**
|
|
105
|
+
* Sets the page size for the underlying DynamoDB requests.
|
|
106
|
+
* Use this with `.iterator()` to control how many items are fetched in each network request.
|
|
107
|
+
*
|
|
108
|
+
* @param val The number of items per page.
|
|
109
|
+
* @returns The current builder instance for chaining.
|
|
110
|
+
*/
|
|
63
111
|
pageSize(val: number): this {
|
|
64
112
|
this._pageSizeVal = val;
|
|
65
113
|
return this;
|
|
66
114
|
}
|
|
67
115
|
|
|
116
|
+
/**
|
|
117
|
+
* Enables or disables consistent reads for this query.
|
|
118
|
+
*
|
|
119
|
+
* @param enabled Whether consistent read is enabled. Defaults to true.
|
|
120
|
+
* @returns The current builder instance for chaining.
|
|
121
|
+
*/
|
|
68
122
|
consistentRead(enabled: boolean = true): this {
|
|
69
123
|
this._consistentReadVal = enabled;
|
|
70
124
|
return this;
|
|
71
125
|
}
|
|
72
126
|
|
|
127
|
+
/**
|
|
128
|
+
* Specifies the sort order for the query (only applicable for `Query` operations).
|
|
129
|
+
*
|
|
130
|
+
* @param forward If true (default), results are sorted in ascending order. If false, descending.
|
|
131
|
+
* @returns The current builder instance for chaining.
|
|
132
|
+
*/
|
|
73
133
|
sort(forward: boolean): this {
|
|
74
134
|
this._sortForward = forward;
|
|
75
135
|
return this;
|
|
76
136
|
}
|
|
77
137
|
|
|
138
|
+
/**
|
|
139
|
+
* Forces the use of a specific Global Secondary Index (GSI) or Local Secondary Index (LSI).
|
|
140
|
+
*
|
|
141
|
+
* @param name The name of the index to use.
|
|
142
|
+
* @returns The current builder instance for chaining.
|
|
143
|
+
*/
|
|
78
144
|
index(name: string): this {
|
|
79
145
|
this._forcedIndexName = name;
|
|
80
146
|
return this;
|
|
81
147
|
}
|
|
82
148
|
|
|
149
|
+
/**
|
|
150
|
+
* Returns an async iterator that automatically handles pagination.
|
|
151
|
+
*
|
|
152
|
+
* @example
|
|
153
|
+
* ```ts
|
|
154
|
+
* for await (const user of db.select().from(users).iterator()) {
|
|
155
|
+
* console.log(user.name);
|
|
156
|
+
* }
|
|
157
|
+
* ```
|
|
158
|
+
*
|
|
159
|
+
* @returns An AsyncIterableIterator for the query results.
|
|
160
|
+
*/
|
|
83
161
|
iterator(): AsyncIterableIterator<TResult> {
|
|
84
162
|
const self = this;
|
|
85
163
|
return (async function* () {
|
|
@@ -115,6 +193,12 @@ export class SelectBase<
|
|
|
115
193
|
}
|
|
116
194
|
}
|
|
117
195
|
|
|
196
|
+
/**
|
|
197
|
+
* Executes the query and returns all matching items.
|
|
198
|
+
*
|
|
199
|
+
* @returns A promise that resolves to an array of items.
|
|
200
|
+
* @throws Error if the query fails.
|
|
201
|
+
*/
|
|
118
202
|
override async execute(): Promise<TResult[]> {
|
|
119
203
|
const { items } = await this.fetchPage();
|
|
120
204
|
return items;
|
package/src/builders/update.ts
CHANGED
|
@@ -32,16 +32,44 @@ export class UpdateBuilder<
|
|
|
32
32
|
super(entity, client);
|
|
33
33
|
}
|
|
34
34
|
|
|
35
|
+
/**
|
|
36
|
+
* Manually specifies the primary key for the update operation.
|
|
37
|
+
*
|
|
38
|
+
* @param keyObject The raw DynamoDB key object (e.g., { pk: "USER#1", sk: "METADATA" }).
|
|
39
|
+
* @returns The current builder instance for chaining.
|
|
40
|
+
*/
|
|
35
41
|
key(keyObject: Record<string, unknown>): this {
|
|
36
42
|
this._explicitKey = keyObject;
|
|
37
43
|
return this;
|
|
38
44
|
}
|
|
39
45
|
|
|
46
|
+
/**
|
|
47
|
+
* Sets specific attributes to new values.
|
|
48
|
+
* Translates to a `SET` action in the DynamoDB UpdateExpression.
|
|
49
|
+
*
|
|
50
|
+
* @example
|
|
51
|
+
* ```ts
|
|
52
|
+
* await db.update(users)
|
|
53
|
+
* .set({ name: "Bob", age: 25 })
|
|
54
|
+
* .where(eq(users.id, "1"))
|
|
55
|
+
* .execute();
|
|
56
|
+
* ```
|
|
57
|
+
*
|
|
58
|
+
* @param values Object containing the fields and values to set.
|
|
59
|
+
* @returns The current builder instance for chaining.
|
|
60
|
+
*/
|
|
40
61
|
set(values: Partial<{ [K in keyof InferInsertModel<TEntity>]: InferInsertModel<TEntity>[K] | UpdateAction }>): this {
|
|
41
62
|
partitionUpdateValues(values as Record<string, any>, this._state, this.entity[ENTITY_SYMBOLS.COLUMNS] as Record<string, any>);
|
|
42
63
|
return this;
|
|
43
64
|
}
|
|
44
65
|
|
|
66
|
+
/**
|
|
67
|
+
* Adds a value to a numeric attribute or elements to a set.
|
|
68
|
+
* Translates to an `ADD` action in the DynamoDB UpdateExpression.
|
|
69
|
+
*
|
|
70
|
+
* @param values Object containing fields and values to add.
|
|
71
|
+
* @returns The current builder instance for chaining.
|
|
72
|
+
*/
|
|
45
73
|
add(values: Partial<InferInsertModel<TEntity>>): this {
|
|
46
74
|
const columns = this.entity[ENTITY_SYMBOLS.COLUMNS] as Record<string, any>;
|
|
47
75
|
for (const [key, val] of Object.entries(values)) {
|
|
@@ -53,11 +81,25 @@ export class UpdateBuilder<
|
|
|
53
81
|
return this;
|
|
54
82
|
}
|
|
55
83
|
|
|
84
|
+
/**
|
|
85
|
+
* Removes one or more attributes from the item.
|
|
86
|
+
* Translates to a `REMOVE` action in the DynamoDB UpdateExpression.
|
|
87
|
+
*
|
|
88
|
+
* @param fields The names of the fields to remove.
|
|
89
|
+
* @returns The current builder instance for chaining.
|
|
90
|
+
*/
|
|
56
91
|
remove(...fields: (keyof InferInsertModel<TEntity> | (string & {}))[]): this {
|
|
57
92
|
this._state.remove.push(...(fields as string[]));
|
|
58
93
|
return this;
|
|
59
94
|
}
|
|
60
95
|
|
|
96
|
+
/**
|
|
97
|
+
* Deletes elements from a set.
|
|
98
|
+
* Translates to a `DELETE` action in the DynamoDB UpdateExpression.
|
|
99
|
+
*
|
|
100
|
+
* @param values Object containing fields and the values to delete from the set.
|
|
101
|
+
* @returns The current builder instance for chaining.
|
|
102
|
+
*/
|
|
61
103
|
delete(values: Partial<InferInsertModel<TEntity>>): this {
|
|
62
104
|
const columns = this.entity[ENTITY_SYMBOLS.COLUMNS] as Record<string, any>;
|
|
63
105
|
for (const [key, val] of Object.entries(values)) {
|
|
@@ -69,11 +111,23 @@ export class UpdateBuilder<
|
|
|
69
111
|
return this;
|
|
70
112
|
}
|
|
71
113
|
|
|
114
|
+
/**
|
|
115
|
+
* Adds a condition to the update operation.
|
|
116
|
+
*
|
|
117
|
+
* @param expression The condition expression.
|
|
118
|
+
* @returns The current builder instance for chaining.
|
|
119
|
+
*/
|
|
72
120
|
where(expression: Expression): this {
|
|
73
121
|
this._whereClause = expression;
|
|
74
122
|
return this;
|
|
75
123
|
}
|
|
76
124
|
|
|
125
|
+
/**
|
|
126
|
+
* Configures what values should be returned after the update.
|
|
127
|
+
*
|
|
128
|
+
* @param value One of: "NONE", "ALL_OLD", "UPDATED_OLD", "ALL_NEW", "UPDATED_NEW".
|
|
129
|
+
* @returns The current builder instance for chaining.
|
|
130
|
+
*/
|
|
77
131
|
returning(value: "NONE" | "ALL_OLD" | "UPDATED_OLD" | "ALL_NEW" | "UPDATED_NEW"): this {
|
|
78
132
|
this._returnValues = value;
|
|
79
133
|
return this;
|
|
@@ -94,6 +148,12 @@ export class UpdateBuilder<
|
|
|
94
148
|
return super.createExpressionContext(prefix);
|
|
95
149
|
}
|
|
96
150
|
|
|
151
|
+
/**
|
|
152
|
+
* Executes the update operation.
|
|
153
|
+
*
|
|
154
|
+
* @returns A promise that resolves to the requested attributes (based on `.returning()`).
|
|
155
|
+
* @throws {ItemSizeExceededError} if the update exceeds 400KB.
|
|
156
|
+
*/
|
|
97
157
|
public override async execute(): Promise<TResult> {
|
|
98
158
|
const columns = this.entity[ENTITY_SYMBOLS.COLUMNS] as Record<string, any>;
|
|
99
159
|
for (const [key, col] of Object.entries(columns)) {
|
|
@@ -1,7 +1,6 @@
|
|
|
1
1
|
import {
|
|
2
2
|
Column,
|
|
3
3
|
type ColumnBaseConfig,
|
|
4
|
-
type ColumnRuntimeConfig,
|
|
5
4
|
} from "../core/column";
|
|
6
5
|
import {
|
|
7
6
|
ColumnBuider,
|
|
@@ -30,6 +29,7 @@ export class BinarySetColumnBuilder<
|
|
|
30
29
|
): BinarySetColumn<MakeColumnConfig<T, TTableName>> {
|
|
31
30
|
return new BinarySetColumn<MakeColumnConfig<T, TTableName>>(
|
|
32
31
|
table,
|
|
32
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
33
33
|
this.config as any,
|
|
34
34
|
);
|
|
35
35
|
}
|
|
@@ -44,6 +44,21 @@ export function binarySet(): BinarySetColumnInitial<"">;
|
|
|
44
44
|
export function binarySet<TName extends string>(
|
|
45
45
|
name: TName,
|
|
46
46
|
): BinarySetColumnInitial<TName>;
|
|
47
|
+
/**
|
|
48
|
+
* Defines a Binary Set column ("BS") in DynamoDB.
|
|
49
|
+
*
|
|
50
|
+
* Represents a set of unique binary blobs (Uint8Array/Buffer).
|
|
51
|
+
*
|
|
52
|
+
* @example
|
|
53
|
+
* ```ts
|
|
54
|
+
* const data = defineTable("data", {
|
|
55
|
+
* hashes: binarySet("hashes"),
|
|
56
|
+
* });
|
|
57
|
+
* ```
|
|
58
|
+
*
|
|
59
|
+
* @param name The name of the attribute in DynamoDB. If omitted, it will use the property name in the definition object.
|
|
60
|
+
* @returns A BinarySetColumnBuilder instance.
|
|
61
|
+
*/
|
|
47
62
|
export function binarySet(name?: string) {
|
|
48
63
|
return new BinarySetColumnBuilder(name ?? "");
|
|
49
64
|
}
|
package/src/columns/binary.ts
CHANGED
|
@@ -1,7 +1,6 @@
|
|
|
1
1
|
import {
|
|
2
2
|
Column,
|
|
3
3
|
type ColumnBaseConfig,
|
|
4
|
-
type ColumnRuntimeConfig,
|
|
5
4
|
} from "../core/column";
|
|
6
5
|
import {
|
|
7
6
|
ColumnBuider,
|
|
@@ -29,6 +28,7 @@ export class BinaryColumnBuilder<
|
|
|
29
28
|
): BinaryColumn<MakeColumnConfig<T, TTableName>> {
|
|
30
29
|
return new BinaryColumn<MakeColumnConfig<T, TTableName>>(
|
|
31
30
|
table,
|
|
31
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
32
32
|
this.config as any,
|
|
33
33
|
);
|
|
34
34
|
}
|
|
@@ -43,6 +43,22 @@ export function binary(): BinaryBuilderInitial<"">;
|
|
|
43
43
|
export function binary<TName extends string>(
|
|
44
44
|
name: TName,
|
|
45
45
|
): BinaryBuilderInitial<TName>;
|
|
46
|
+
/**
|
|
47
|
+
* Defines a Binary column ("B") in DynamoDB.
|
|
48
|
+
*
|
|
49
|
+
* Used for storing arbitrary binary data, such as images, compressed files, or raw bytes.
|
|
50
|
+
* Mizzle handles `Uint8Array` or `Buffer` (in Node) for this type.
|
|
51
|
+
*
|
|
52
|
+
* @example
|
|
53
|
+
* ```ts
|
|
54
|
+
* const files = defineTable("files", {
|
|
55
|
+
* content: binary("content"),
|
|
56
|
+
* });
|
|
57
|
+
* ```
|
|
58
|
+
*
|
|
59
|
+
* @param name The name of the attribute in DynamoDB. If omitted, it will use the property name in the definition object.
|
|
60
|
+
* @returns A BinaryColumnBuilder instance.
|
|
61
|
+
*/
|
|
46
62
|
export function binary(name?: string) {
|
|
47
63
|
return new BinaryColumnBuilder(name ?? "");
|
|
48
64
|
}
|
package/src/columns/boolean.ts
CHANGED
|
@@ -2,7 +2,6 @@ import { Column, type ColumnBaseConfig } from "../core/column";
|
|
|
2
2
|
import {
|
|
3
3
|
ColumnBuider,
|
|
4
4
|
type ColumnBuilderBaseConfig,
|
|
5
|
-
type ColumnBuilderRuntimeConfig,
|
|
6
5
|
type MakeColumnConfig,
|
|
7
6
|
} from "../core/column-builder";
|
|
8
7
|
import type { AnyTable } from "../core/table";
|
|
@@ -26,6 +25,7 @@ export class BooleanColumnBuilder<
|
|
|
26
25
|
): BooleanColumn<MakeColumnConfig<T, TTableName>> {
|
|
27
26
|
return new BooleanColumn<MakeColumnConfig<T, TTableName>>(
|
|
28
27
|
table,
|
|
28
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
29
29
|
this.config as any,
|
|
30
30
|
);
|
|
31
31
|
}
|
|
@@ -40,6 +40,19 @@ export function boolean(): BooleanColumnInitial<"">;
|
|
|
40
40
|
export function boolean<TName extends string>(
|
|
41
41
|
name: TName,
|
|
42
42
|
): BooleanColumnInitial<TName>;
|
|
43
|
+
/**
|
|
44
|
+
* Defines a Boolean column ("BOOL") in DynamoDB.
|
|
45
|
+
*
|
|
46
|
+
* @example
|
|
47
|
+
* ```ts
|
|
48
|
+
* const users = defineTable("users", {
|
|
49
|
+
* isActive: boolean("is_active").default(true),
|
|
50
|
+
* });
|
|
51
|
+
* ```
|
|
52
|
+
*
|
|
53
|
+
* @param name The name of the attribute in DynamoDB. If omitted, it will use the property name in the definition object.
|
|
54
|
+
* @returns A BooleanColumnBuilder instance.
|
|
55
|
+
*/
|
|
43
56
|
export function boolean(name?: string) {
|
|
44
57
|
return new BooleanColumnBuilder(name ?? "");
|
|
45
58
|
}
|
package/src/columns/date.ts
CHANGED
|
@@ -1,7 +1,6 @@
|
|
|
1
1
|
import {
|
|
2
2
|
Column,
|
|
3
3
|
type ColumnBaseConfig,
|
|
4
|
-
type ColumnRuntimeConfig,
|
|
5
4
|
} from "../core/column";
|
|
6
5
|
import {
|
|
7
6
|
ColumnBuider,
|
|
@@ -27,10 +26,12 @@ export class DateColumnBuilder<
|
|
|
27
26
|
}
|
|
28
27
|
|
|
29
28
|
defaultNow(): HasRuntimeDefault<HasDefault<this>> {
|
|
29
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
30
30
|
return this.$defaultFn(() => new Date() as any);
|
|
31
31
|
}
|
|
32
32
|
|
|
33
33
|
onUpdateNow(): HasDefault<this> {
|
|
34
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
34
35
|
return this.$onUpdateFn(() => new Date() as any);
|
|
35
36
|
}
|
|
36
37
|
|
|
@@ -39,6 +40,7 @@ export class DateColumnBuilder<
|
|
|
39
40
|
): DateColumn<MakeColumnConfig<T, TTableName>> {
|
|
40
41
|
return new DateColumn<MakeColumnConfig<T, TTableName>>(
|
|
41
42
|
table,
|
|
43
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
42
44
|
this.config as any,
|
|
43
45
|
);
|
|
44
46
|
}
|
|
@@ -78,6 +80,23 @@ export class DateColumn<
|
|
|
78
80
|
|
|
79
81
|
export function date(): DateColumnInitial<"">;
|
|
80
82
|
export function date<TName extends string>(name: TName): DateColumnInitial<TName>;
|
|
83
|
+
/**
|
|
84
|
+
* Defines a Date column.
|
|
85
|
+
*
|
|
86
|
+
* In DynamoDB, this is stored as an ISO 8601 string ("S"), but Mizzle automatically
|
|
87
|
+
* handles conversion to/from JavaScript Date objects in your application code.
|
|
88
|
+
*
|
|
89
|
+
* @example
|
|
90
|
+
* ```ts
|
|
91
|
+
* const posts = defineTable("posts", {
|
|
92
|
+
* createdAt: date("created_at").defaultNow(),
|
|
93
|
+
* updatedAt: date("updated_at").onUpdateNow(),
|
|
94
|
+
* });
|
|
95
|
+
* ```
|
|
96
|
+
*
|
|
97
|
+
* @param name The name of the attribute in DynamoDB. If omitted, it will use the property name in the definition object.
|
|
98
|
+
* @returns A DateColumnBuilder instance.
|
|
99
|
+
*/
|
|
81
100
|
export function date(name?: string) {
|
|
82
101
|
return new DateColumnBuilder(name ?? "");
|
|
83
102
|
}
|
package/src/columns/json.ts
CHANGED
|
@@ -1,7 +1,6 @@
|
|
|
1
1
|
import {
|
|
2
2
|
Column,
|
|
3
3
|
type ColumnBaseConfig,
|
|
4
|
-
type ColumnRuntimeConfig,
|
|
5
4
|
} from "../core/column";
|
|
6
5
|
import {
|
|
7
6
|
ColumnBuider,
|
|
@@ -29,6 +28,7 @@ export class JsonColumnBuilder<
|
|
|
29
28
|
): JsonColumn<MakeColumnConfig<T, TTableName>> {
|
|
30
29
|
return new JsonColumn<MakeColumnConfig<T, TTableName>>(
|
|
31
30
|
table,
|
|
31
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
32
32
|
this.config as any,
|
|
33
33
|
);
|
|
34
34
|
}
|
|
@@ -57,6 +57,29 @@ export function json(): JsonColumnInitial<"">;
|
|
|
57
57
|
export function json<TName extends string>(
|
|
58
58
|
name: TName,
|
|
59
59
|
): JsonColumnInitial<TName>;
|
|
60
|
+
/**
|
|
61
|
+
* Defines a JSON column.
|
|
62
|
+
*
|
|
63
|
+
* In DynamoDB, this is stored as a string ("S") containing serialized JSON.
|
|
64
|
+
* Mizzle automatically handles JSON.stringify/parse for you.
|
|
65
|
+
*
|
|
66
|
+
* You can type the JSON object using the `.$type<T>()` method.
|
|
67
|
+
*
|
|
68
|
+
* @example
|
|
69
|
+
* ```ts
|
|
70
|
+
* interface Address {
|
|
71
|
+
* street: string;
|
|
72
|
+
* city: string;
|
|
73
|
+
* }
|
|
74
|
+
*
|
|
75
|
+
* const users = defineTable("users", {
|
|
76
|
+
* address: json("address").$type<Address>(),
|
|
77
|
+
* });
|
|
78
|
+
* ```
|
|
79
|
+
*
|
|
80
|
+
* @param name The name of the attribute in DynamoDB. If omitted, it will use the property name in the definition object.
|
|
81
|
+
* @returns A JsonColumnBuilder instance.
|
|
82
|
+
*/
|
|
60
83
|
export function json(name?: string) {
|
|
61
84
|
return new JsonColumnBuilder(name ?? "");
|
|
62
85
|
}
|