dyno-table 2.2.1 → 2.3.1
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/README.md +187 -1865
- package/dist/builders.cjs +55 -0
- package/dist/builders.d.cts +4 -0
- package/dist/builders.d.ts +4 -0
- package/dist/builders.js +2 -0
- package/dist/chunk-2EWNZOUK.js +618 -0
- package/dist/chunk-2WIBY7PZ.js +46 -0
- package/dist/chunk-7UJJ7JXM.cjs +63 -0
- package/dist/chunk-DTFJJASK.js +3200 -0
- package/dist/chunk-EODPMYPE.js +558 -0
- package/dist/chunk-KA3VPIPS.cjs +560 -0
- package/dist/chunk-NTA6GDPP.cjs +622 -0
- package/dist/chunk-PB7BBCZO.cjs +32 -0
- package/dist/chunk-QVRMYGC4.js +29 -0
- package/dist/chunk-XYL43FDX.cjs +3217 -0
- package/dist/conditions.cjs +67 -62
- package/dist/conditions.js +1 -48
- package/dist/entity.cjs +14 -625
- package/dist/entity.d.cts +2 -10
- package/dist/entity.d.ts +2 -10
- package/dist/entity.js +2 -626
- package/dist/index-2cbm07Bi.d.ts +2797 -0
- package/dist/index-DlN8G9hd.d.cts +2797 -0
- package/dist/index.cjs +111 -4460
- package/dist/index.d.cts +2 -10
- package/dist/index.d.ts +2 -10
- package/dist/index.js +5 -4442
- package/dist/standard-schema.cjs +0 -2
- package/dist/standard-schema.js +0 -2
- package/dist/table.cjs +7 -3796
- package/dist/table.d.cts +163 -12
- package/dist/table.d.ts +163 -12
- package/dist/table.js +3 -3799
- package/dist/types.cjs +0 -2
- package/dist/types.js +0 -2
- package/dist/utils.cjs +10 -30
- package/dist/utils.js +1 -31
- package/package.json +6 -66
- package/dist/batch-builder-BiQDIZ7p.d.cts +0 -398
- package/dist/batch-builder-CNsLS6sR.d.ts +0 -398
- package/dist/builder-types-BTVhQSHI.d.cts +0 -169
- package/dist/builder-types-CzuLR4Th.d.ts +0 -169
- package/dist/builders/condition-check-builder.cjs +0 -422
- package/dist/builders/condition-check-builder.cjs.map +0 -1
- package/dist/builders/condition-check-builder.d.cts +0 -153
- package/dist/builders/condition-check-builder.d.ts +0 -153
- package/dist/builders/condition-check-builder.js +0 -420
- package/dist/builders/condition-check-builder.js.map +0 -1
- package/dist/builders/delete-builder.cjs +0 -484
- package/dist/builders/delete-builder.cjs.map +0 -1
- package/dist/builders/delete-builder.d.cts +0 -211
- package/dist/builders/delete-builder.d.ts +0 -211
- package/dist/builders/delete-builder.js +0 -482
- package/dist/builders/delete-builder.js.map +0 -1
- package/dist/builders/paginator.cjs +0 -193
- package/dist/builders/paginator.cjs.map +0 -1
- package/dist/builders/paginator.d.cts +0 -155
- package/dist/builders/paginator.d.ts +0 -155
- package/dist/builders/paginator.js +0 -191
- package/dist/builders/paginator.js.map +0 -1
- package/dist/builders/put-builder.cjs +0 -554
- package/dist/builders/put-builder.cjs.map +0 -1
- package/dist/builders/put-builder.d.cts +0 -319
- package/dist/builders/put-builder.d.ts +0 -319
- package/dist/builders/put-builder.js +0 -552
- package/dist/builders/put-builder.js.map +0 -1
- package/dist/builders/query-builder.cjs +0 -757
- package/dist/builders/query-builder.cjs.map +0 -1
- package/dist/builders/query-builder.d.cts +0 -6
- package/dist/builders/query-builder.d.ts +0 -6
- package/dist/builders/query-builder.js +0 -755
- package/dist/builders/query-builder.js.map +0 -1
- package/dist/builders/transaction-builder.cjs +0 -906
- package/dist/builders/transaction-builder.cjs.map +0 -1
- package/dist/builders/transaction-builder.d.cts +0 -464
- package/dist/builders/transaction-builder.d.ts +0 -464
- package/dist/builders/transaction-builder.js +0 -904
- package/dist/builders/transaction-builder.js.map +0 -1
- package/dist/builders/update-builder.cjs +0 -668
- package/dist/builders/update-builder.cjs.map +0 -1
- package/dist/builders/update-builder.d.cts +0 -374
- package/dist/builders/update-builder.d.ts +0 -374
- package/dist/builders/update-builder.js +0 -666
- package/dist/builders/update-builder.js.map +0 -1
- package/dist/conditions.cjs.map +0 -1
- package/dist/conditions.js.map +0 -1
- package/dist/entity.cjs.map +0 -1
- package/dist/entity.js.map +0 -1
- package/dist/index.cjs.map +0 -1
- package/dist/index.js.map +0 -1
- package/dist/query-builder-D3URwK9k.d.cts +0 -477
- package/dist/query-builder-cfEkU0_w.d.ts +0 -477
- package/dist/standard-schema.cjs.map +0 -1
- package/dist/standard-schema.js.map +0 -1
- package/dist/table-ClST8nkR.d.cts +0 -276
- package/dist/table-vE3cGoDy.d.ts +0 -276
- package/dist/table.cjs.map +0 -1
- package/dist/table.js.map +0 -1
- package/dist/types.cjs.map +0 -1
- package/dist/types.js.map +0 -1
- package/dist/utils.cjs.map +0 -1
- package/dist/utils.js.map +0 -1
|
@@ -1,554 +0,0 @@
|
|
|
1
|
-
'use strict';
|
|
2
|
-
|
|
3
|
-
// src/conditions.ts
|
|
4
|
-
var createComparisonCondition = (type) => (attr, value) => ({
|
|
5
|
-
type,
|
|
6
|
-
attr,
|
|
7
|
-
value
|
|
8
|
-
});
|
|
9
|
-
var eq = createComparisonCondition("eq");
|
|
10
|
-
var ne = createComparisonCondition("ne");
|
|
11
|
-
var lt = createComparisonCondition("lt");
|
|
12
|
-
var lte = createComparisonCondition("lte");
|
|
13
|
-
var gt = createComparisonCondition("gt");
|
|
14
|
-
var gte = createComparisonCondition("gte");
|
|
15
|
-
var between = (attr, lower, upper) => ({
|
|
16
|
-
type: "between",
|
|
17
|
-
attr,
|
|
18
|
-
value: [lower, upper]
|
|
19
|
-
});
|
|
20
|
-
var inArray = (attr, values) => ({
|
|
21
|
-
type: "in",
|
|
22
|
-
attr,
|
|
23
|
-
value: values
|
|
24
|
-
});
|
|
25
|
-
var beginsWith = createComparisonCondition("beginsWith");
|
|
26
|
-
var contains = createComparisonCondition("contains");
|
|
27
|
-
var attributeExists = (attr) => ({
|
|
28
|
-
type: "attributeExists",
|
|
29
|
-
attr
|
|
30
|
-
});
|
|
31
|
-
var attributeNotExists = (attr) => ({
|
|
32
|
-
type: "attributeNotExists",
|
|
33
|
-
attr
|
|
34
|
-
});
|
|
35
|
-
var and = (...conditions) => ({
|
|
36
|
-
type: "and",
|
|
37
|
-
conditions
|
|
38
|
-
});
|
|
39
|
-
var or = (...conditions) => ({
|
|
40
|
-
type: "or",
|
|
41
|
-
conditions
|
|
42
|
-
});
|
|
43
|
-
var not = (condition) => ({
|
|
44
|
-
type: "not",
|
|
45
|
-
condition
|
|
46
|
-
});
|
|
47
|
-
|
|
48
|
-
// src/expression.ts
|
|
49
|
-
var generateAttributeName = (params, attr) => {
|
|
50
|
-
if (attr.includes(".")) {
|
|
51
|
-
const pathSegments = attr.split(".");
|
|
52
|
-
const segmentNames = [];
|
|
53
|
-
for (const segment of pathSegments) {
|
|
54
|
-
let segmentName;
|
|
55
|
-
for (const [existingName, existingAttr] of Object.entries(params.expressionAttributeNames)) {
|
|
56
|
-
if (existingAttr === segment) {
|
|
57
|
-
segmentName = existingName;
|
|
58
|
-
break;
|
|
59
|
-
}
|
|
60
|
-
}
|
|
61
|
-
if (!segmentName) {
|
|
62
|
-
segmentName = `#${Object.keys(params.expressionAttributeNames).length}`;
|
|
63
|
-
params.expressionAttributeNames[segmentName] = segment;
|
|
64
|
-
}
|
|
65
|
-
segmentNames.push(segmentName);
|
|
66
|
-
}
|
|
67
|
-
return segmentNames.join(".");
|
|
68
|
-
}
|
|
69
|
-
for (const [existingName, existingAttr] of Object.entries(params.expressionAttributeNames)) {
|
|
70
|
-
if (existingAttr === attr) {
|
|
71
|
-
return existingName;
|
|
72
|
-
}
|
|
73
|
-
}
|
|
74
|
-
const attrName = `#${Object.keys(params.expressionAttributeNames).length}`;
|
|
75
|
-
params.expressionAttributeNames[attrName] = attr;
|
|
76
|
-
return attrName;
|
|
77
|
-
};
|
|
78
|
-
var generateValueName = (params, value) => {
|
|
79
|
-
const valueName = `:${params.valueCounter.count++}`;
|
|
80
|
-
params.expressionAttributeValues[valueName] = value;
|
|
81
|
-
return valueName;
|
|
82
|
-
};
|
|
83
|
-
var validateCondition = (condition, requiresAttr = true, requiresValue = true) => {
|
|
84
|
-
if (requiresAttr && !condition.attr) {
|
|
85
|
-
throw new Error(`Attribute is required for ${condition.type} condition`);
|
|
86
|
-
}
|
|
87
|
-
if (requiresValue && condition.value === void 0) {
|
|
88
|
-
throw new Error(`Value is required for ${condition.type} condition`);
|
|
89
|
-
}
|
|
90
|
-
};
|
|
91
|
-
var buildComparisonExpression = (condition, operator, params) => {
|
|
92
|
-
validateCondition(condition);
|
|
93
|
-
if (!condition.attr) {
|
|
94
|
-
throw new Error(`Attribute is required for ${condition.type} condition`);
|
|
95
|
-
}
|
|
96
|
-
const attrName = generateAttributeName(params, condition.attr);
|
|
97
|
-
const valueName = generateValueName(params, condition.value);
|
|
98
|
-
return `${attrName} ${operator} ${valueName}`;
|
|
99
|
-
};
|
|
100
|
-
var buildBetweenExpression = (condition, params) => {
|
|
101
|
-
validateCondition(condition);
|
|
102
|
-
if (!condition.attr) {
|
|
103
|
-
throw new Error(`Attribute is required for ${condition.type} condition`);
|
|
104
|
-
}
|
|
105
|
-
if (!Array.isArray(condition.value) || condition.value.length !== 2) {
|
|
106
|
-
throw new Error("Between condition requires an array of two values");
|
|
107
|
-
}
|
|
108
|
-
const attrName = generateAttributeName(params, condition.attr);
|
|
109
|
-
const lowerName = generateValueName(params, condition.value[0]);
|
|
110
|
-
const upperName = generateValueName(params, condition.value[1]);
|
|
111
|
-
return `${attrName} BETWEEN ${lowerName} AND ${upperName}`;
|
|
112
|
-
};
|
|
113
|
-
var buildInExpression = (condition, params) => {
|
|
114
|
-
validateCondition(condition);
|
|
115
|
-
if (!condition.attr) {
|
|
116
|
-
throw new Error(`Attribute is required for ${condition.type} condition`);
|
|
117
|
-
}
|
|
118
|
-
if (!Array.isArray(condition.value) || condition.value.length === 0) {
|
|
119
|
-
throw new Error("In condition requires a non-empty array of values");
|
|
120
|
-
}
|
|
121
|
-
if (condition.value.length > 100) {
|
|
122
|
-
throw new Error("In condition supports a maximum of 100 values");
|
|
123
|
-
}
|
|
124
|
-
const attrName = generateAttributeName(params, condition.attr);
|
|
125
|
-
const valueNames = condition.value.map((value) => generateValueName(params, value));
|
|
126
|
-
return `${attrName} IN (${valueNames.join(", ")})`;
|
|
127
|
-
};
|
|
128
|
-
var buildFunctionExpression = (functionName, condition, params) => {
|
|
129
|
-
validateCondition(condition);
|
|
130
|
-
if (!condition.attr) {
|
|
131
|
-
throw new Error(`Attribute is required for ${condition.type} condition`);
|
|
132
|
-
}
|
|
133
|
-
const attrName = generateAttributeName(params, condition.attr);
|
|
134
|
-
const valueName = generateValueName(params, condition.value);
|
|
135
|
-
return `${functionName}(${attrName}, ${valueName})`;
|
|
136
|
-
};
|
|
137
|
-
var buildAttributeFunction = (functionName, condition, params) => {
|
|
138
|
-
validateCondition(condition, true, false);
|
|
139
|
-
if (!condition.attr) {
|
|
140
|
-
throw new Error(`Attribute is required for ${condition.type} condition`);
|
|
141
|
-
}
|
|
142
|
-
const attrName = generateAttributeName(params, condition.attr);
|
|
143
|
-
return `${functionName}(${attrName})`;
|
|
144
|
-
};
|
|
145
|
-
var buildLogicalExpression = (operator, conditions, params) => {
|
|
146
|
-
if (!conditions || conditions.length === 0) {
|
|
147
|
-
throw new Error(`At least one condition is required for ${operator} expression`);
|
|
148
|
-
}
|
|
149
|
-
const expressions = conditions.map((c) => buildExpression(c, params));
|
|
150
|
-
return `(${expressions.join(` ${operator} `)})`;
|
|
151
|
-
};
|
|
152
|
-
var buildExpression = (condition, params) => {
|
|
153
|
-
if (!condition) return "";
|
|
154
|
-
try {
|
|
155
|
-
const expressionBuilders = {
|
|
156
|
-
eq: () => buildComparisonExpression(condition, "=", params),
|
|
157
|
-
ne: () => buildComparisonExpression(condition, "<>", params),
|
|
158
|
-
lt: () => buildComparisonExpression(condition, "<", params),
|
|
159
|
-
lte: () => buildComparisonExpression(condition, "<=", params),
|
|
160
|
-
gt: () => buildComparisonExpression(condition, ">", params),
|
|
161
|
-
gte: () => buildComparisonExpression(condition, ">=", params),
|
|
162
|
-
between: () => buildBetweenExpression(condition, params),
|
|
163
|
-
in: () => buildInExpression(condition, params),
|
|
164
|
-
beginsWith: () => buildFunctionExpression("begins_with", condition, params),
|
|
165
|
-
contains: () => buildFunctionExpression("contains", condition, params),
|
|
166
|
-
attributeExists: () => buildAttributeFunction("attribute_exists", condition, params),
|
|
167
|
-
attributeNotExists: () => buildAttributeFunction("attribute_not_exists", condition, params),
|
|
168
|
-
and: () => {
|
|
169
|
-
if (!condition.conditions) {
|
|
170
|
-
throw new Error("Conditions array is required for AND operator");
|
|
171
|
-
}
|
|
172
|
-
return buildLogicalExpression("AND", condition.conditions, params);
|
|
173
|
-
},
|
|
174
|
-
or: () => {
|
|
175
|
-
if (!condition.conditions) {
|
|
176
|
-
throw new Error("Conditions array is required for OR operator");
|
|
177
|
-
}
|
|
178
|
-
return buildLogicalExpression("OR", condition.conditions, params);
|
|
179
|
-
},
|
|
180
|
-
not: () => {
|
|
181
|
-
if (!condition.condition) {
|
|
182
|
-
throw new Error("Condition is required for NOT operator");
|
|
183
|
-
}
|
|
184
|
-
return `NOT (${buildExpression(condition.condition, params)})`;
|
|
185
|
-
}
|
|
186
|
-
};
|
|
187
|
-
const builder = expressionBuilders[condition.type];
|
|
188
|
-
if (!builder) {
|
|
189
|
-
throw new Error(`Unknown condition type: ${condition.type}`);
|
|
190
|
-
}
|
|
191
|
-
return builder();
|
|
192
|
-
} catch (error) {
|
|
193
|
-
if (error instanceof Error) {
|
|
194
|
-
console.error(`Error building expression for condition type ${condition.type}:`, error.message);
|
|
195
|
-
} else {
|
|
196
|
-
console.error(`Error building expression for condition type ${condition.type}:`, error);
|
|
197
|
-
}
|
|
198
|
-
throw error;
|
|
199
|
-
}
|
|
200
|
-
};
|
|
201
|
-
var prepareExpressionParams = (condition) => {
|
|
202
|
-
if (!condition) return {};
|
|
203
|
-
const params = {
|
|
204
|
-
expressionAttributeNames: {},
|
|
205
|
-
expressionAttributeValues: {},
|
|
206
|
-
valueCounter: { count: 0 }
|
|
207
|
-
};
|
|
208
|
-
const expression = buildExpression(condition, params);
|
|
209
|
-
return {
|
|
210
|
-
expression,
|
|
211
|
-
names: Object.keys(params.expressionAttributeNames).length > 0 ? params.expressionAttributeNames : void 0,
|
|
212
|
-
values: Object.keys(params.expressionAttributeValues).length > 0 ? params.expressionAttributeValues : void 0
|
|
213
|
-
};
|
|
214
|
-
};
|
|
215
|
-
|
|
216
|
-
// src/utils/debug-expression.ts
|
|
217
|
-
function debugCommand(command) {
|
|
218
|
-
const result = {};
|
|
219
|
-
function replaceAliases(expressionString) {
|
|
220
|
-
if (!expressionString) {
|
|
221
|
-
return expressionString;
|
|
222
|
-
}
|
|
223
|
-
let replacedString = expressionString;
|
|
224
|
-
for (const alias in command.expressionAttributeNames) {
|
|
225
|
-
const attributeName = command.expressionAttributeNames[alias];
|
|
226
|
-
const regex = new RegExp(alias, "g");
|
|
227
|
-
replacedString = replacedString.replace(regex, attributeName);
|
|
228
|
-
}
|
|
229
|
-
for (const alias in command.expressionAttributeValues) {
|
|
230
|
-
let attributeValue = command.expressionAttributeValues[alias];
|
|
231
|
-
if (attributeValue instanceof Set) {
|
|
232
|
-
const array = Array.from(attributeValue);
|
|
233
|
-
attributeValue = `Set(${array.length}){${array.map((v) => JSON.stringify(v)).join(", ")}}`;
|
|
234
|
-
} else {
|
|
235
|
-
attributeValue = JSON.stringify(attributeValue);
|
|
236
|
-
}
|
|
237
|
-
const regex = new RegExp(alias, "g");
|
|
238
|
-
replacedString = replacedString.replace(regex, attributeValue);
|
|
239
|
-
}
|
|
240
|
-
return replacedString;
|
|
241
|
-
}
|
|
242
|
-
if (command.updateExpression) {
|
|
243
|
-
result.updateExpression = replaceAliases(command.updateExpression);
|
|
244
|
-
}
|
|
245
|
-
if (command.conditionExpression) {
|
|
246
|
-
result.conditionExpression = replaceAliases(command.conditionExpression);
|
|
247
|
-
}
|
|
248
|
-
if (command.filterExpression) {
|
|
249
|
-
result.filterExpression = replaceAliases(command.filterExpression);
|
|
250
|
-
}
|
|
251
|
-
if (command.keyConditionExpression) {
|
|
252
|
-
result.keyConditionExpression = replaceAliases(command.keyConditionExpression);
|
|
253
|
-
}
|
|
254
|
-
if (command.projectionExpression) {
|
|
255
|
-
result.projectionExpression = replaceAliases(command.projectionExpression);
|
|
256
|
-
}
|
|
257
|
-
return {
|
|
258
|
-
raw: command,
|
|
259
|
-
readable: result
|
|
260
|
-
};
|
|
261
|
-
}
|
|
262
|
-
|
|
263
|
-
// src/builders/put-builder.ts
|
|
264
|
-
var PutBuilder = class {
|
|
265
|
-
item;
|
|
266
|
-
options;
|
|
267
|
-
executor;
|
|
268
|
-
tableName;
|
|
269
|
-
constructor(executor, item, tableName) {
|
|
270
|
-
this.executor = executor;
|
|
271
|
-
this.item = item;
|
|
272
|
-
this.tableName = tableName;
|
|
273
|
-
this.options = {
|
|
274
|
-
returnValues: "NONE"
|
|
275
|
-
};
|
|
276
|
-
}
|
|
277
|
-
set(valuesOrPath, value) {
|
|
278
|
-
if (typeof valuesOrPath === "object") {
|
|
279
|
-
Object.assign(this.item, valuesOrPath);
|
|
280
|
-
} else {
|
|
281
|
-
this.item[valuesOrPath] = value;
|
|
282
|
-
}
|
|
283
|
-
return this;
|
|
284
|
-
}
|
|
285
|
-
/**
|
|
286
|
-
* Adds a condition that must be satisfied for the put operation to succeed.
|
|
287
|
-
*
|
|
288
|
-
* @example
|
|
289
|
-
* ```ts
|
|
290
|
-
* // Ensure item doesn't exist (insert only)
|
|
291
|
-
* builder.condition(op => op.attributeNotExists('id'))
|
|
292
|
-
*
|
|
293
|
-
* // Complex condition with version check
|
|
294
|
-
* builder.condition(op =>
|
|
295
|
-
* op.and([
|
|
296
|
-
* op.attributeExists('id'),
|
|
297
|
-
* op.eq('version', currentVersion),
|
|
298
|
-
* op.eq('status', 'ACTIVE')
|
|
299
|
-
* ])
|
|
300
|
-
* )
|
|
301
|
-
* ```
|
|
302
|
-
*
|
|
303
|
-
* @param condition - Either a Condition object or a callback function that builds the condition
|
|
304
|
-
* @returns The builder instance for method chaining
|
|
305
|
-
*/
|
|
306
|
-
/**
|
|
307
|
-
* Adds a condition that must be satisfied for the put operation to succeed.
|
|
308
|
-
*
|
|
309
|
-
* @example
|
|
310
|
-
* ```typescript
|
|
311
|
-
* // Ensure unique dinosaur ID
|
|
312
|
-
* builder.condition(op =>
|
|
313
|
-
* op.attributeNotExists('id')
|
|
314
|
-
* );
|
|
315
|
-
*
|
|
316
|
-
* // Verify habitat requirements
|
|
317
|
-
* builder.condition(op =>
|
|
318
|
-
* op.and([
|
|
319
|
-
* op.eq('securityStatus', 'READY'),
|
|
320
|
-
* op.attributeExists('lastInspection'),
|
|
321
|
-
* op.gt('securityLevel', 5)
|
|
322
|
-
* ])
|
|
323
|
-
* );
|
|
324
|
-
*
|
|
325
|
-
* // Check breeding facility conditions
|
|
326
|
-
* builder.condition(op =>
|
|
327
|
-
* op.and([
|
|
328
|
-
* op.between('temperature', 25, 30),
|
|
329
|
-
* op.between('humidity', 60, 80),
|
|
330
|
-
* op.eq('quarantineStatus', 'CLEAR')
|
|
331
|
-
* ])
|
|
332
|
-
* );
|
|
333
|
-
* ```
|
|
334
|
-
*
|
|
335
|
-
* @param condition - Either a Condition object or a callback function that builds the condition
|
|
336
|
-
* @returns The builder instance for method chaining
|
|
337
|
-
*/
|
|
338
|
-
condition(condition) {
|
|
339
|
-
if (typeof condition === "function") {
|
|
340
|
-
const conditionOperator = {
|
|
341
|
-
eq,
|
|
342
|
-
ne,
|
|
343
|
-
lt,
|
|
344
|
-
lte,
|
|
345
|
-
gt,
|
|
346
|
-
gte,
|
|
347
|
-
between,
|
|
348
|
-
inArray,
|
|
349
|
-
beginsWith,
|
|
350
|
-
contains,
|
|
351
|
-
attributeExists,
|
|
352
|
-
attributeNotExists,
|
|
353
|
-
and,
|
|
354
|
-
or,
|
|
355
|
-
not
|
|
356
|
-
};
|
|
357
|
-
this.options.condition = condition(conditionOperator);
|
|
358
|
-
} else {
|
|
359
|
-
this.options.condition = condition;
|
|
360
|
-
}
|
|
361
|
-
return this;
|
|
362
|
-
}
|
|
363
|
-
/**
|
|
364
|
-
* Sets whether to return the item's previous values (if it existed).
|
|
365
|
-
*
|
|
366
|
-
* @options
|
|
367
|
-
* - NONE: No return value
|
|
368
|
-
* - ALL_OLD: Returns the item's previous state if it existed, no read capacity units are consumed
|
|
369
|
-
* - CONSISTENT: Performs a GET operation after the put to retrieve the item's new state
|
|
370
|
-
* - INPUT: Returns the input values that were passed to the operation
|
|
371
|
-
*
|
|
372
|
-
* @example
|
|
373
|
-
* ```ts
|
|
374
|
-
* // Get previous dinosaur state
|
|
375
|
-
* const result = await builder
|
|
376
|
-
* .returnValues('ALL_OLD')
|
|
377
|
-
* .execute();
|
|
378
|
-
*
|
|
379
|
-
* if (result) {
|
|
380
|
-
* console.log('Previous profile:', {
|
|
381
|
-
* species: result.species,
|
|
382
|
-
* status: result.status,
|
|
383
|
-
* stats: {
|
|
384
|
-
* health: result.stats.health,
|
|
385
|
-
* threatLevel: result.stats.threatLevel
|
|
386
|
-
* }
|
|
387
|
-
* });
|
|
388
|
-
* }
|
|
389
|
-
*
|
|
390
|
-
* // Return input values for create operations
|
|
391
|
-
* const createResult = await builder
|
|
392
|
-
* .returnValues('INPUT')
|
|
393
|
-
* .execute();
|
|
394
|
-
* ```
|
|
395
|
-
*
|
|
396
|
-
* @param returnValues - Use 'ALL_OLD' to return previous values, 'INPUT' to return input values, 'CONSISTENT' for fresh data, or 'NONE' (default).
|
|
397
|
-
* @returns The builder instance for method chaining
|
|
398
|
-
*/
|
|
399
|
-
returnValues(returnValues) {
|
|
400
|
-
this.options.returnValues = returnValues;
|
|
401
|
-
return this;
|
|
402
|
-
}
|
|
403
|
-
/**
|
|
404
|
-
* Generate the DynamoDB command parameters
|
|
405
|
-
*/
|
|
406
|
-
toDynamoCommand() {
|
|
407
|
-
const { expression, names, values } = prepareExpressionParams(this.options.condition);
|
|
408
|
-
return {
|
|
409
|
-
tableName: this.tableName,
|
|
410
|
-
item: this.item,
|
|
411
|
-
conditionExpression: expression,
|
|
412
|
-
expressionAttributeNames: names,
|
|
413
|
-
expressionAttributeValues: values,
|
|
414
|
-
returnValues: this.options.returnValues
|
|
415
|
-
};
|
|
416
|
-
}
|
|
417
|
-
/**
|
|
418
|
-
* Adds this put operation to a transaction.
|
|
419
|
-
*
|
|
420
|
-
* @example
|
|
421
|
-
* ```ts
|
|
422
|
-
* const transaction = new TransactionBuilder();
|
|
423
|
-
*
|
|
424
|
-
* // Add dinosaur to new habitat
|
|
425
|
-
* new PutBuilder(executor, {
|
|
426
|
-
* id: 'TREX-002',
|
|
427
|
-
* location: 'PADDOCK-B',
|
|
428
|
-
* status: 'ACTIVE',
|
|
429
|
-
* transferDate: new Date().toISOString()
|
|
430
|
-
* }, 'dinosaurs')
|
|
431
|
-
* .withTransaction(transaction);
|
|
432
|
-
*
|
|
433
|
-
* // Update habitat records
|
|
434
|
-
* new UpdateBuilder(executor, 'habitats', { id: 'PADDOCK-B' })
|
|
435
|
-
* .add('occupants', 1)
|
|
436
|
-
* .set('lastTransfer', new Date().toISOString())
|
|
437
|
-
* .withTransaction(transaction);
|
|
438
|
-
*
|
|
439
|
-
* // Execute transfer atomically
|
|
440
|
-
* await transaction.execute();
|
|
441
|
-
* ```
|
|
442
|
-
*
|
|
443
|
-
* @param transaction - The transaction builder to add this operation to
|
|
444
|
-
* @returns The builder instance for method chaining
|
|
445
|
-
*/
|
|
446
|
-
withTransaction(transaction) {
|
|
447
|
-
const command = this.toDynamoCommand();
|
|
448
|
-
transaction.putWithCommand(command);
|
|
449
|
-
return this;
|
|
450
|
-
}
|
|
451
|
-
/**
|
|
452
|
-
* Adds this put operation to a batch with optional entity type information.
|
|
453
|
-
*
|
|
454
|
-
* @example Basic Usage
|
|
455
|
-
* ```ts
|
|
456
|
-
* const batch = table.batchBuilder();
|
|
457
|
-
*
|
|
458
|
-
* // Add multiple dinosaurs to batch
|
|
459
|
-
* dinosaurRepo.create(newDino1).withBatch(batch);
|
|
460
|
-
* dinosaurRepo.create(newDino2).withBatch(batch);
|
|
461
|
-
* dinosaurRepo.create(newDino3).withBatch(batch);
|
|
462
|
-
*
|
|
463
|
-
* // Execute all operations efficiently
|
|
464
|
-
* await batch.execute();
|
|
465
|
-
* ```
|
|
466
|
-
*
|
|
467
|
-
* @example Typed Usage
|
|
468
|
-
* ```ts
|
|
469
|
-
* const batch = table.batchBuilder<{
|
|
470
|
-
* User: UserEntity;
|
|
471
|
-
* Order: OrderEntity;
|
|
472
|
-
* }>();
|
|
473
|
-
*
|
|
474
|
-
* // Add operations with type information
|
|
475
|
-
* userRepo.create(newUser).withBatch(batch, 'User');
|
|
476
|
-
* orderRepo.create(newOrder).withBatch(batch, 'Order');
|
|
477
|
-
*
|
|
478
|
-
* // Execute and get typed results
|
|
479
|
-
* const result = await batch.execute();
|
|
480
|
-
* const users: UserEntity[] = result.reads.itemsByType.User;
|
|
481
|
-
* ```
|
|
482
|
-
*
|
|
483
|
-
* @param batch - The batch builder to add this operation to
|
|
484
|
-
* @param entityType - Optional entity type key for type tracking
|
|
485
|
-
*/
|
|
486
|
-
withBatch(batch, entityType) {
|
|
487
|
-
const command = this.toDynamoCommand();
|
|
488
|
-
batch.putWithCommand(command, entityType);
|
|
489
|
-
}
|
|
490
|
-
/**
|
|
491
|
-
* Executes the put operation against DynamoDB.
|
|
492
|
-
*
|
|
493
|
-
* @example
|
|
494
|
-
* ```ts
|
|
495
|
-
* try {
|
|
496
|
-
* // Put with condition and return old values
|
|
497
|
-
* const result = await new PutBuilder(executor, newItem, 'myTable')
|
|
498
|
-
* .condition(op => op.eq('version', 1))
|
|
499
|
-
* .returnValues('ALL_OLD')
|
|
500
|
-
* .execute();
|
|
501
|
-
*
|
|
502
|
-
* console.log('Put successful, old item:', result);
|
|
503
|
-
* } catch (error) {
|
|
504
|
-
* // Handle condition check failure or other errors
|
|
505
|
-
* console.error('Put failed:', error);
|
|
506
|
-
* }
|
|
507
|
-
* ```
|
|
508
|
-
*
|
|
509
|
-
* @returns A promise that resolves to the operation result (type depends on returnValues setting)
|
|
510
|
-
* @throws Will throw an error if the condition check fails or other DynamoDB errors occur
|
|
511
|
-
*/
|
|
512
|
-
async execute() {
|
|
513
|
-
const params = this.toDynamoCommand();
|
|
514
|
-
return this.executor(params);
|
|
515
|
-
}
|
|
516
|
-
/**
|
|
517
|
-
* Gets a human-readable representation of the put command
|
|
518
|
-
* with all expression placeholders replaced by their actual values.
|
|
519
|
-
*
|
|
520
|
-
* @example
|
|
521
|
-
* ```ts
|
|
522
|
-
* const debugInfo = new PutBuilder(executor, {
|
|
523
|
-
* id: 'RAPTOR-003',
|
|
524
|
-
* species: 'Velociraptor',
|
|
525
|
-
* status: 'QUARANTINE',
|
|
526
|
-
* stats: {
|
|
527
|
-
* health: 100,
|
|
528
|
-
* aggressionLevel: 7,
|
|
529
|
-
* age: 2
|
|
530
|
-
* }
|
|
531
|
-
* }, 'dinosaurs')
|
|
532
|
-
* .condition(op =>
|
|
533
|
-
* op.and([
|
|
534
|
-
* op.attributeNotExists('id'),
|
|
535
|
-
* op.eq('quarantineStatus', 'READY'),
|
|
536
|
-
* op.gt('securityLevel', 8)
|
|
537
|
-
* ])
|
|
538
|
-
* )
|
|
539
|
-
* .debug();
|
|
540
|
-
*
|
|
541
|
-
* console.log('Dinosaur transfer command:', debugInfo);
|
|
542
|
-
* ```
|
|
543
|
-
*
|
|
544
|
-
* @returns A readable representation of the put command with resolved expressions
|
|
545
|
-
*/
|
|
546
|
-
debug() {
|
|
547
|
-
const command = this.toDynamoCommand();
|
|
548
|
-
return debugCommand(command);
|
|
549
|
-
}
|
|
550
|
-
};
|
|
551
|
-
|
|
552
|
-
exports.PutBuilder = PutBuilder;
|
|
553
|
-
//# sourceMappingURL=put-builder.cjs.map
|
|
554
|
-
//# sourceMappingURL=put-builder.cjs.map
|