@aurios/mizzle 1.1.2 → 1.1.4
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 +166 -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/delete.ts
CHANGED
|
@@ -1,71 +1,64 @@
|
|
|
1
1
|
import { DeleteCommand } from "@aws-sdk/lib-dynamodb";
|
|
2
|
-
import { ENTITY_SYMBOLS } from "@
|
|
2
|
+
import { ENTITY_SYMBOLS } from "@repo/shared";
|
|
3
3
|
import { Entity, type InferSelectModel } from "../core/table";
|
|
4
4
|
import { BaseBuilder } from "./base";
|
|
5
5
|
import { type IMizzleClient } from "../core/client";
|
|
6
6
|
import { type Expression } from "../expressions/operators";
|
|
7
7
|
|
|
8
8
|
export class DeleteBuilder<
|
|
9
|
-
|
|
10
|
-
|
|
9
|
+
TEntity extends Entity,
|
|
10
|
+
TResult = InferSelectModel<TEntity>,
|
|
11
11
|
> extends BaseBuilder<TEntity, TResult> {
|
|
12
|
-
|
|
12
|
+
static readonly [ENTITY_SYMBOLS.ENTITY_KIND]: string = "DeleteBuilder";
|
|
13
13
|
|
|
14
|
-
|
|
15
|
-
|
|
14
|
+
private _returnValues?: "NONE" | "ALL_OLD";
|
|
15
|
+
private _keys: Record<string, unknown>;
|
|
16
16
|
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
) {
|
|
22
|
-
super(entity, client);
|
|
23
|
-
this._keys = keys;
|
|
24
|
-
}
|
|
17
|
+
constructor(entity: TEntity, client: IMizzleClient, keys: Record<string, unknown>) {
|
|
18
|
+
super(entity, client);
|
|
19
|
+
this._keys = keys;
|
|
20
|
+
}
|
|
25
21
|
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
22
|
+
/**
|
|
23
|
+
* Instructs Mizzle to return the deleted item after execution.
|
|
24
|
+
*
|
|
25
|
+
* @returns The current builder instance.
|
|
26
|
+
*/
|
|
27
|
+
returning(): this {
|
|
28
|
+
this._returnValues = "ALL_OLD";
|
|
29
|
+
return this;
|
|
30
|
+
}
|
|
35
31
|
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
32
|
+
/** @internal */
|
|
33
|
+
get keys() {
|
|
34
|
+
return this._keys;
|
|
35
|
+
}
|
|
40
36
|
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
) {
|
|
46
|
-
return super.resolveKeys(whereClause, providedValues);
|
|
47
|
-
}
|
|
37
|
+
/** @internal */
|
|
38
|
+
public override resolveKeys(whereClause?: Expression, providedValues?: Record<string, unknown>) {
|
|
39
|
+
return super.resolveKeys(whereClause, providedValues);
|
|
40
|
+
}
|
|
48
41
|
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
42
|
+
/** @internal */
|
|
43
|
+
public override createExpressionContext(prefix = "") {
|
|
44
|
+
return super.createExpressionContext(prefix);
|
|
45
|
+
}
|
|
53
46
|
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
47
|
+
/**
|
|
48
|
+
* Executes the delete operation.
|
|
49
|
+
*
|
|
50
|
+
* @returns A promise that resolves to the deleted item if `.returning()` was called, otherwise undefined.
|
|
51
|
+
*/
|
|
52
|
+
public override async execute(): Promise<TResult> {
|
|
53
|
+
const resolution = this.resolveKeys(undefined, this._keys);
|
|
61
54
|
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
55
|
+
const command = new DeleteCommand({
|
|
56
|
+
TableName: this.tableName,
|
|
57
|
+
Key: resolution.keys,
|
|
58
|
+
ReturnValues: this._returnValues,
|
|
59
|
+
});
|
|
67
60
|
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
61
|
+
const response = (await this.client.send(command)) as any;
|
|
62
|
+
return response.Attributes as TResult;
|
|
63
|
+
}
|
|
71
64
|
}
|
package/src/builders/insert.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { PutCommand } from "@aws-sdk/lib-dynamodb";
|
|
2
|
-
import { ENTITY_SYMBOLS, TABLE_SYMBOLS } from "@
|
|
2
|
+
import { ENTITY_SYMBOLS, TABLE_SYMBOLS } from "@repo/shared";
|
|
3
3
|
import { Entity, type InferInsertModel } from "../core/table";
|
|
4
4
|
import { BaseBuilder } from "./base";
|
|
5
5
|
import { Column } from "../core/column";
|
|
@@ -9,176 +9,184 @@ import { calculateItemSize } from "../core/validation";
|
|
|
9
9
|
import { ItemSizeExceededError } from "../core/errors";
|
|
10
10
|
|
|
11
11
|
export class InsertBuilder<TEntity extends Entity> {
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
12
|
+
static readonly [ENTITY_SYMBOLS.ENTITY_KIND]: string = "InsertBuilder";
|
|
13
|
+
|
|
14
|
+
constructor(
|
|
15
|
+
private entity: TEntity,
|
|
16
|
+
private client: IMizzleClient,
|
|
17
|
+
) {}
|
|
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
|
+
*/
|
|
30
|
+
values(values: InferInsertModel<TEntity>): InsertBase<TEntity> {
|
|
31
|
+
return new InsertBase(this.entity, this.client, values);
|
|
32
|
+
}
|
|
33
33
|
}
|
|
34
34
|
|
|
35
35
|
interface MinimalPhysicalTable {
|
|
36
|
-
|
|
36
|
+
[TABLE_SYMBOLS.INDEXES]?: Record<string, { config: { pk: string; sk?: string } }>;
|
|
37
37
|
}
|
|
38
38
|
|
|
39
|
-
export class InsertBase<
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
>
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
39
|
+
export class InsertBase<TEntity extends Entity, TResult = undefined> extends BaseBuilder<
|
|
40
|
+
TEntity,
|
|
41
|
+
TResult
|
|
42
|
+
> {
|
|
43
|
+
static readonly [ENTITY_SYMBOLS.ENTITY_KIND]: string = "InsertBase";
|
|
44
|
+
|
|
45
|
+
private shouldReturnValues = false;
|
|
46
|
+
|
|
47
|
+
constructor(
|
|
48
|
+
entity: TEntity,
|
|
49
|
+
client: IMizzleClient,
|
|
50
|
+
private valuesData: InferInsertModel<TEntity>,
|
|
51
|
+
) {
|
|
52
|
+
super(entity, client);
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
/** @internal */
|
|
56
|
+
get values() {
|
|
57
|
+
return this.valuesData;
|
|
58
|
+
}
|
|
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
|
+
*/
|
|
65
|
+
returning(): InsertBase<TEntity, InferInsertModel<TEntity>> {
|
|
66
|
+
this.shouldReturnValues = true;
|
|
67
|
+
return this as unknown as InsertBase<TEntity, InferInsertModel<TEntity>>;
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
/** @internal */
|
|
71
|
+
buildItem(): Record<string, unknown> {
|
|
72
|
+
const itemToSave = this.processValues(this.valuesData);
|
|
73
|
+
const resolution = this.resolveKeys(undefined, itemToSave);
|
|
74
|
+
|
|
75
|
+
const finalItem: Record<string, unknown> = { ...itemToSave, ...resolution.keys };
|
|
76
|
+
|
|
77
|
+
// Also resolve GSI keys if they are defined in strategies but not in resolution.keys
|
|
78
|
+
const strategies = this.entity[ENTITY_SYMBOLS.ENTITY_STRATEGY] as unknown as Record<
|
|
79
|
+
string,
|
|
80
|
+
{ pk: KeyStrategy; sk?: KeyStrategy }
|
|
81
|
+
>;
|
|
82
|
+
const physicalTable = this.entity[
|
|
83
|
+
ENTITY_SYMBOLS.PHYSICAL_TABLE
|
|
84
|
+
] as unknown as MinimalPhysicalTable;
|
|
85
|
+
const indexes = physicalTable?.[TABLE_SYMBOLS.INDEXES] || {};
|
|
86
|
+
|
|
87
|
+
for (const [indexName, strategy] of Object.entries(strategies)) {
|
|
88
|
+
if (indexName === "pk" || indexName === "sk") continue;
|
|
89
|
+
|
|
90
|
+
const indexBuilder = indexes[indexName];
|
|
91
|
+
if (indexBuilder) {
|
|
92
|
+
if (strategy.pk && indexBuilder.config.pk) {
|
|
93
|
+
const pkValue = this.resolveStrategyValue(strategy.pk, itemToSave);
|
|
94
|
+
if (pkValue) finalItem[indexBuilder.config.pk] = pkValue;
|
|
95
|
+
}
|
|
96
|
+
if (strategy.sk && indexBuilder.config.sk) {
|
|
97
|
+
const skValue = this.resolveStrategyValue(strategy.sk, itemToSave);
|
|
98
|
+
if (skValue) finalItem[indexBuilder.config.sk] = skValue;
|
|
99
|
+
}
|
|
100
|
+
}
|
|
53
101
|
}
|
|
54
102
|
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
103
|
+
return finalItem;
|
|
104
|
+
}
|
|
105
|
+
|
|
106
|
+
/**
|
|
107
|
+
* Executes the insert operation.
|
|
108
|
+
*
|
|
109
|
+
* @returns A promise that resolves to the inserted item if `.returning()` was called, otherwise undefined.
|
|
110
|
+
* @throws {ItemSizeExceededError} if the item exceeds 400KB.
|
|
111
|
+
*/
|
|
112
|
+
override async execute(): Promise<TResult> {
|
|
113
|
+
const finalItem = this.buildItem();
|
|
114
|
+
|
|
115
|
+
// Size validation
|
|
116
|
+
const size = calculateItemSize(finalItem);
|
|
117
|
+
if (size > 400 * 1024) {
|
|
118
|
+
throw new ItemSizeExceededError(
|
|
119
|
+
`Item size of ${Math.round(size / 1024)}KB exceeds the 400KB limit.`,
|
|
120
|
+
);
|
|
58
121
|
}
|
|
59
122
|
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
*/
|
|
65
|
-
returning(): InsertBase<TEntity, InferInsertModel<TEntity>> {
|
|
66
|
-
this.shouldReturnValues = true;
|
|
67
|
-
return this as unknown as InsertBase<TEntity, InferInsertModel<TEntity>>;
|
|
68
|
-
}
|
|
123
|
+
const command = new PutCommand({
|
|
124
|
+
TableName: this.tableName,
|
|
125
|
+
Item: finalItem,
|
|
126
|
+
});
|
|
69
127
|
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
const itemToSave = this.processValues(this.valuesData);
|
|
73
|
-
const resolution = this.resolveKeys(undefined, itemToSave);
|
|
74
|
-
|
|
75
|
-
const finalItem: Record<string, unknown> = { ...itemToSave, ...resolution.keys };
|
|
76
|
-
|
|
77
|
-
// Also resolve GSI keys if they are defined in strategies but not in resolution.keys
|
|
78
|
-
const strategies = this.entity[ENTITY_SYMBOLS.ENTITY_STRATEGY] as unknown as Record<string, { pk: KeyStrategy, sk?: KeyStrategy }>;
|
|
79
|
-
const physicalTable = this.entity[ENTITY_SYMBOLS.PHYSICAL_TABLE] as unknown as MinimalPhysicalTable;
|
|
80
|
-
const indexes = physicalTable?.[TABLE_SYMBOLS.INDEXES] || {};
|
|
81
|
-
|
|
82
|
-
for (const [indexName, strategy] of Object.entries(strategies)) {
|
|
83
|
-
if (indexName === "pk" || indexName === "sk") continue;
|
|
84
|
-
|
|
85
|
-
const indexBuilder = indexes[indexName];
|
|
86
|
-
if (indexBuilder) {
|
|
87
|
-
if (strategy.pk && indexBuilder.config.pk) {
|
|
88
|
-
const pkValue = this.resolveStrategyValue(strategy.pk, itemToSave);
|
|
89
|
-
if (pkValue) finalItem[indexBuilder.config.pk] = pkValue;
|
|
90
|
-
}
|
|
91
|
-
if (strategy.sk && indexBuilder.config.sk) {
|
|
92
|
-
const skValue = this.resolveStrategyValue(strategy.sk, itemToSave);
|
|
93
|
-
if (skValue) finalItem[indexBuilder.config.sk] = skValue;
|
|
94
|
-
}
|
|
95
|
-
}
|
|
96
|
-
}
|
|
128
|
+
await this.client.send(command);
|
|
129
|
+
if (this.shouldReturnValues) return finalItem as unknown as TResult;
|
|
97
130
|
|
|
98
|
-
|
|
131
|
+
return undefined as unknown as TResult;
|
|
132
|
+
}
|
|
133
|
+
|
|
134
|
+
private resolveStrategyValue(
|
|
135
|
+
strategy: KeyStrategy,
|
|
136
|
+
availableValues: Record<string, unknown>,
|
|
137
|
+
): string | undefined {
|
|
138
|
+
if (strategy.type === "static") {
|
|
139
|
+
return strategy.segments[0] as string;
|
|
99
140
|
}
|
|
100
141
|
|
|
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
|
-
*/
|
|
107
|
-
override async execute(): Promise<TResult> {
|
|
108
|
-
const finalItem = this.buildItem();
|
|
109
|
-
|
|
110
|
-
// Size validation
|
|
111
|
-
const size = calculateItemSize(finalItem);
|
|
112
|
-
if (size > 400 * 1024) {
|
|
113
|
-
throw new ItemSizeExceededError(`Item size of ${Math.round(size / 1024)}KB exceeds the 400KB limit.`);
|
|
114
|
-
}
|
|
142
|
+
const resolvedParts: string[] = [];
|
|
115
143
|
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
144
|
+
for (const segment of strategy.segments) {
|
|
145
|
+
if (typeof segment === "string") {
|
|
146
|
+
resolvedParts.push(segment);
|
|
147
|
+
} else {
|
|
148
|
+
const val = availableValues[segment.name];
|
|
149
|
+
if (val === undefined || val === null) return undefined;
|
|
150
|
+
resolvedParts.push(String(val));
|
|
151
|
+
}
|
|
152
|
+
}
|
|
120
153
|
|
|
121
|
-
|
|
122
|
-
|
|
154
|
+
if (strategy.type === "prefix") return resolvedParts.join("");
|
|
155
|
+
if (strategy.type === "composite") return resolvedParts.join(strategy.separator || "#");
|
|
156
|
+
return undefined;
|
|
157
|
+
}
|
|
123
158
|
|
|
124
|
-
|
|
125
|
-
}
|
|
159
|
+
private processValues(values: InferInsertModel<TEntity>): Record<string, unknown> {
|
|
160
|
+
const item: Record<string, unknown> = { ...(values as Record<string, unknown>) };
|
|
161
|
+
const columns = this.entity[ENTITY_SYMBOLS.COLUMNS] as Record<string, Column>;
|
|
126
162
|
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
}
|
|
163
|
+
for (const key in columns) {
|
|
164
|
+
const col = columns[key];
|
|
165
|
+
if (!col) continue;
|
|
131
166
|
|
|
132
|
-
|
|
167
|
+
const value = item[key];
|
|
133
168
|
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
const val = availableValues[segment.name];
|
|
139
|
-
if (val === undefined || val === null) return undefined;
|
|
140
|
-
resolvedParts.push(String(val));
|
|
141
|
-
}
|
|
142
|
-
}
|
|
169
|
+
if (value === undefined) {
|
|
170
|
+
if (col.default !== undefined) item[key] = col.default;
|
|
171
|
+
else if (col.defaultFn) item[key] = col.defaultFn();
|
|
172
|
+
}
|
|
143
173
|
|
|
144
|
-
|
|
145
|
-
if (strategy.type === "composite") return resolvedParts.join(strategy.separator || "#");
|
|
146
|
-
return undefined;
|
|
147
|
-
}
|
|
174
|
+
const finalValue = item[key];
|
|
148
175
|
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
const columns = this.entity[ENTITY_SYMBOLS.COLUMNS] as Record<string, Column>;
|
|
154
|
-
|
|
155
|
-
for (const key in columns) {
|
|
156
|
-
const col = columns[key];
|
|
157
|
-
if (!col) continue;
|
|
158
|
-
|
|
159
|
-
const value = item[key];
|
|
160
|
-
|
|
161
|
-
if (value === undefined) {
|
|
162
|
-
if (col.default !== undefined) item[key] = col.default;
|
|
163
|
-
else if (col.defaultFn) item[key] = col.defaultFn();
|
|
164
|
-
}
|
|
165
|
-
|
|
166
|
-
const finalValue = item[key];
|
|
167
|
-
|
|
168
|
-
// Check if column has mapToDynamoValue method (it's on the Column class)
|
|
169
|
-
if (col instanceof Column) {
|
|
170
|
-
item[key] = col.mapToDynamoValue(finalValue);
|
|
171
|
-
}
|
|
172
|
-
|
|
173
|
-
if (["SS", "NS", "BS"].includes(col.columnType)) {
|
|
174
|
-
if (Array.isArray(finalValue)) {
|
|
175
|
-
const setVal = new Set(finalValue);
|
|
176
|
-
item[key] = setVal;
|
|
177
|
-
if (setVal.size === 0) delete item[key];
|
|
178
|
-
}
|
|
179
|
-
}
|
|
180
|
-
}
|
|
176
|
+
// Check if column has mapToDynamoValue method (it's on the Column class)
|
|
177
|
+
if (col instanceof Column) {
|
|
178
|
+
item[key] = col.mapToDynamoValue(finalValue);
|
|
179
|
+
}
|
|
181
180
|
|
|
182
|
-
|
|
181
|
+
if (["SS", "NS", "BS"].includes(col.columnType)) {
|
|
182
|
+
if (Array.isArray(finalValue)) {
|
|
183
|
+
const setVal = new Set(finalValue);
|
|
184
|
+
item[key] = setVal;
|
|
185
|
+
if (setVal.size === 0) delete item[key];
|
|
186
|
+
}
|
|
187
|
+
}
|
|
183
188
|
}
|
|
189
|
+
|
|
190
|
+
return item;
|
|
191
|
+
}
|
|
184
192
|
}
|
|
@@ -1,41 +1,32 @@
|
|
|
1
1
|
export abstract class QueryPromise<T> implements Promise<T> {
|
|
2
|
-
|
|
2
|
+
[Symbol.toStringTag] = "QueryPromise";
|
|
3
3
|
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
): Promise<T | TResult> {
|
|
10
|
-
return this.then(undefined, onrejected);
|
|
11
|
-
}
|
|
4
|
+
catch<TResult = never>(
|
|
5
|
+
onrejected?: ((reason: unknown) => TResult | PromiseLike<TResult>) | null | undefined,
|
|
6
|
+
): Promise<T | TResult> {
|
|
7
|
+
return this.then(undefined, onrejected);
|
|
8
|
+
}
|
|
12
9
|
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
10
|
+
finally(onfinally?: (() => void) | null | undefined): Promise<T> {
|
|
11
|
+
return this.then(
|
|
12
|
+
(value) => {
|
|
13
|
+
onfinally?.();
|
|
14
|
+
return value;
|
|
15
|
+
},
|
|
16
|
+
(reason) => {
|
|
17
|
+
onfinally?.();
|
|
18
|
+
throw reason;
|
|
19
|
+
},
|
|
20
|
+
);
|
|
21
|
+
}
|
|
25
22
|
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
| ((reason: unknown) => TResult2 | PromiseLike<TResult2>)
|
|
34
|
-
| null
|
|
35
|
-
| undefined,
|
|
36
|
-
): Promise<TResult1 | TResult2> {
|
|
37
|
-
return this.execute().then(onfulfilled, onrejected);
|
|
38
|
-
}
|
|
23
|
+
// oxlint-disable
|
|
24
|
+
then<TResult1 = T, TResult2 = never>(
|
|
25
|
+
onfulfilled?: ((value: T) => TResult1 | PromiseLike<TResult1>) | null | undefined,
|
|
26
|
+
onrejected?: ((reason: unknown) => TResult2 | PromiseLike<TResult2>) | null | undefined,
|
|
27
|
+
): Promise<TResult1 | TResult2> {
|
|
28
|
+
return this.execute().then(onfulfilled, onrejected);
|
|
29
|
+
}
|
|
39
30
|
|
|
40
|
-
|
|
31
|
+
abstract execute(): Promise<T>;
|
|
41
32
|
}
|