@infra-blocks/aws-dynamodb 0.21.0 → 0.22.0-alpha.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/lib/cjs/commands/create-table.js +3 -4
- package/lib/cjs/commands/create-table.js.map +1 -1
- package/lib/cjs/commands/expressions/index.d.ts +1 -1
- package/lib/cjs/commands/expressions/index.js +1 -1
- package/lib/cjs/commands/expressions/index.js.map +1 -1
- package/lib/cjs/commands/expressions/update/action.d.ts +33 -0
- package/lib/cjs/commands/expressions/update/action.js +3 -0
- package/lib/cjs/commands/expressions/update/action.js.map +1 -0
- package/lib/cjs/commands/expressions/update/add.d.ts +40 -0
- package/lib/cjs/commands/expressions/update/add.js +45 -0
- package/lib/cjs/commands/expressions/update/add.js.map +1 -0
- package/lib/cjs/commands/expressions/update/clauses.d.ts +22 -0
- package/lib/cjs/commands/expressions/update/clauses.js +50 -0
- package/lib/cjs/commands/expressions/update/clauses.js.map +1 -0
- package/lib/cjs/commands/expressions/update/delete.d.ts +35 -0
- package/lib/cjs/commands/expressions/update/delete.js +43 -0
- package/lib/cjs/commands/expressions/update/delete.js.map +1 -0
- package/lib/cjs/commands/expressions/update/expression.d.ts +22 -0
- package/lib/cjs/commands/expressions/update/expression.js +69 -0
- package/lib/cjs/commands/expressions/update/expression.js.map +1 -0
- package/lib/cjs/commands/expressions/update/if-not-exists.d.ts +17 -0
- package/lib/cjs/commands/expressions/update/if-not-exists.js +22 -0
- package/lib/cjs/commands/expressions/update/if-not-exists.js.map +1 -0
- package/lib/cjs/commands/expressions/update/index.d.ts +7 -0
- package/lib/cjs/commands/expressions/update/index.js +29 -0
- package/lib/cjs/commands/expressions/update/index.js.map +1 -0
- package/lib/cjs/commands/expressions/update/remove.d.ts +23 -0
- package/lib/cjs/commands/expressions/update/remove.js +34 -0
- package/lib/cjs/commands/expressions/update/remove.js.map +1 -0
- package/lib/cjs/commands/expressions/update/set.d.ts +57 -0
- package/lib/cjs/commands/expressions/update/set.js +86 -0
- package/lib/cjs/commands/expressions/update/set.js.map +1 -0
- package/lib/cjs/commands/put-item.js +4 -5
- package/lib/cjs/commands/put-item.js.map +1 -1
- package/lib/esm/commands/create-table.js +3 -4
- package/lib/esm/commands/create-table.js.map +1 -1
- package/lib/esm/commands/expressions/index.d.ts +1 -1
- package/lib/esm/commands/expressions/index.js +1 -1
- package/lib/esm/commands/expressions/index.js.map +1 -1
- package/lib/esm/commands/expressions/update/action.d.ts +33 -0
- package/lib/esm/commands/expressions/update/action.js +2 -0
- package/lib/esm/commands/expressions/update/action.js.map +1 -0
- package/lib/esm/commands/expressions/update/add.d.ts +40 -0
- package/lib/esm/commands/expressions/update/add.js +40 -0
- package/lib/esm/commands/expressions/update/add.js.map +1 -0
- package/lib/esm/commands/expressions/update/clauses.d.ts +22 -0
- package/lib/esm/commands/expressions/update/clauses.js +46 -0
- package/lib/esm/commands/expressions/update/clauses.js.map +1 -0
- package/lib/esm/commands/expressions/update/delete.d.ts +35 -0
- package/lib/esm/commands/expressions/update/delete.js +38 -0
- package/lib/esm/commands/expressions/update/delete.js.map +1 -0
- package/lib/esm/commands/expressions/update/expression.d.ts +22 -0
- package/lib/esm/commands/expressions/update/expression.js +65 -0
- package/lib/esm/commands/expressions/update/expression.js.map +1 -0
- package/lib/esm/commands/expressions/update/if-not-exists.d.ts +17 -0
- package/lib/esm/commands/expressions/update/if-not-exists.js +17 -0
- package/lib/esm/commands/expressions/update/if-not-exists.js.map +1 -0
- package/lib/esm/commands/expressions/update/index.d.ts +7 -0
- package/lib/esm/commands/expressions/update/index.js +7 -0
- package/lib/esm/commands/expressions/update/index.js.map +1 -0
- package/lib/esm/commands/expressions/update/remove.d.ts +23 -0
- package/lib/esm/commands/expressions/update/remove.js +29 -0
- package/lib/esm/commands/expressions/update/remove.js.map +1 -0
- package/lib/esm/commands/expressions/update/set.d.ts +57 -0
- package/lib/esm/commands/expressions/update/set.js +79 -0
- package/lib/esm/commands/expressions/update/set.js.map +1 -0
- package/lib/esm/commands/put-item.js +4 -5
- package/lib/esm/commands/put-item.js.map +1 -1
- package/package.json +2 -2
- package/lib/cjs/commands/expressions/update.d.ts +0 -163
- package/lib/cjs/commands/expressions/update.js +0 -258
- package/lib/cjs/commands/expressions/update.js.map +0 -1
- package/lib/esm/commands/expressions/update.d.ts +0 -163
- package/lib/esm/commands/expressions/update.js +0 -243
- package/lib/esm/commands/expressions/update.js.map +0 -1
|
@@ -1,258 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.IfNotExistsOperand = exports.DeleteAction = exports.AddAction = exports.RemoveAction = exports.SetToMinus = exports.SetToPlus = exports.UpdateExpression = void 0;
|
|
4
|
-
exports.set = set;
|
|
5
|
-
exports.remove = remove;
|
|
6
|
-
exports.add = add;
|
|
7
|
-
exports.deleteFrom = deleteFrom;
|
|
8
|
-
exports.ifNotExists = ifNotExists;
|
|
9
|
-
/**
|
|
10
|
-
*
|
|
11
|
-
* @see https://docs.aws.amazon.com/amazondynamodb/latest/developerguide/Expressions.UpdateExpressions.html
|
|
12
|
-
*/
|
|
13
|
-
class UpdateExpression {
|
|
14
|
-
clauses;
|
|
15
|
-
constructor(clauses) {
|
|
16
|
-
this.clauses = clauses;
|
|
17
|
-
}
|
|
18
|
-
stringify(params) {
|
|
19
|
-
const { names, values } = params;
|
|
20
|
-
const parts = [];
|
|
21
|
-
if (this.clauses.set != null) {
|
|
22
|
-
parts.push(`SET ${this.clauses.set
|
|
23
|
-
.map((action) => action.stringify({ names, values }))
|
|
24
|
-
.join(",")}`);
|
|
25
|
-
}
|
|
26
|
-
if (this.clauses.remove != null) {
|
|
27
|
-
parts.push(`REMOVE ${this.clauses.remove
|
|
28
|
-
.map((action) => action.stringify({ names }))
|
|
29
|
-
.join(",")}`);
|
|
30
|
-
}
|
|
31
|
-
if (this.clauses.add != null) {
|
|
32
|
-
parts.push(`ADD ${this.clauses.add
|
|
33
|
-
.map((action) => action.stringify({ names, values }))
|
|
34
|
-
.join(",")}`);
|
|
35
|
-
}
|
|
36
|
-
if (this.clauses.delete != null) {
|
|
37
|
-
parts.push(`DELETE ${this.clauses.delete
|
|
38
|
-
.map((action) => action.stringify({ names, values }))
|
|
39
|
-
.join(",")}`);
|
|
40
|
-
}
|
|
41
|
-
return parts.join("\n");
|
|
42
|
-
}
|
|
43
|
-
static from(params) {
|
|
44
|
-
const clauses = {};
|
|
45
|
-
for (const action of params) {
|
|
46
|
-
if (action instanceof SetTo ||
|
|
47
|
-
action instanceof SetToPlus ||
|
|
48
|
-
action instanceof SetToMinus) {
|
|
49
|
-
clauses.set ??= [];
|
|
50
|
-
clauses.set.push(action);
|
|
51
|
-
}
|
|
52
|
-
else if (action instanceof RemoveAction) {
|
|
53
|
-
clauses.remove ??= [];
|
|
54
|
-
clauses.remove.push(action);
|
|
55
|
-
}
|
|
56
|
-
else if (action instanceof DeleteAction) {
|
|
57
|
-
clauses.delete ??= [];
|
|
58
|
-
clauses.delete.push(action);
|
|
59
|
-
}
|
|
60
|
-
else if (action instanceof AddAction) {
|
|
61
|
-
clauses.add ??= [];
|
|
62
|
-
clauses.add.push(action);
|
|
63
|
-
}
|
|
64
|
-
else {
|
|
65
|
-
throw new Error("unknown action type in update expression");
|
|
66
|
-
}
|
|
67
|
-
}
|
|
68
|
-
return new UpdateExpression(clauses);
|
|
69
|
-
}
|
|
70
|
-
}
|
|
71
|
-
exports.UpdateExpression = UpdateExpression;
|
|
72
|
-
class SetTo {
|
|
73
|
-
path;
|
|
74
|
-
operand;
|
|
75
|
-
constructor(params) {
|
|
76
|
-
const { path, operand } = params;
|
|
77
|
-
this.path = path;
|
|
78
|
-
this.operand = operand;
|
|
79
|
-
}
|
|
80
|
-
plus(operand) {
|
|
81
|
-
return new SetToPlus({ inner: this, operand });
|
|
82
|
-
}
|
|
83
|
-
minus(operand) {
|
|
84
|
-
return new SetToMinus({ inner: this, operand });
|
|
85
|
-
}
|
|
86
|
-
stringify(params) {
|
|
87
|
-
const { names, values } = params;
|
|
88
|
-
return `${this.path.substitute({ names })} = ${this.operand.substitute({
|
|
89
|
-
names,
|
|
90
|
-
values,
|
|
91
|
-
})}`;
|
|
92
|
-
}
|
|
93
|
-
}
|
|
94
|
-
class SetToPlus {
|
|
95
|
-
inner;
|
|
96
|
-
operand;
|
|
97
|
-
constructor(params) {
|
|
98
|
-
const { inner, operand } = params;
|
|
99
|
-
this.inner = inner;
|
|
100
|
-
this.operand = operand;
|
|
101
|
-
}
|
|
102
|
-
stringify(params) {
|
|
103
|
-
const { names, values } = params;
|
|
104
|
-
return `${this.inner.stringify({ names, values })} + ${this.operand.substitute({
|
|
105
|
-
names,
|
|
106
|
-
values,
|
|
107
|
-
})}`;
|
|
108
|
-
}
|
|
109
|
-
}
|
|
110
|
-
exports.SetToPlus = SetToPlus;
|
|
111
|
-
class SetToMinus {
|
|
112
|
-
inner;
|
|
113
|
-
operand;
|
|
114
|
-
constructor(params) {
|
|
115
|
-
const { inner, operand } = params;
|
|
116
|
-
this.inner = inner;
|
|
117
|
-
this.operand = operand;
|
|
118
|
-
}
|
|
119
|
-
stringify(params) {
|
|
120
|
-
const { names, values } = params;
|
|
121
|
-
return `${this.inner.stringify({ names, values })} - ${this.operand.substitute({
|
|
122
|
-
names,
|
|
123
|
-
values,
|
|
124
|
-
})}`;
|
|
125
|
-
}
|
|
126
|
-
}
|
|
127
|
-
exports.SetToMinus = SetToMinus;
|
|
128
|
-
class SetToBuilder {
|
|
129
|
-
path;
|
|
130
|
-
constructor(path) {
|
|
131
|
-
this.path = path;
|
|
132
|
-
}
|
|
133
|
-
to(operand) {
|
|
134
|
-
return new SetTo({ path: this.path, operand });
|
|
135
|
-
}
|
|
136
|
-
}
|
|
137
|
-
// TODO: increment/decrement utilities built on top of the assignments.
|
|
138
|
-
// TODO: review API for something more streamlined.... Imagine something like:
|
|
139
|
-
// set(attribute(<name>), value(<value>)) or set(attribute(<name>), value(<first>), "+", value(<second>))
|
|
140
|
-
function set(path) {
|
|
141
|
-
return new SetToBuilder(path);
|
|
142
|
-
}
|
|
143
|
-
class RemoveAction {
|
|
144
|
-
path;
|
|
145
|
-
constructor(path) {
|
|
146
|
-
this.path = path;
|
|
147
|
-
}
|
|
148
|
-
stringify(params) {
|
|
149
|
-
const { names } = params;
|
|
150
|
-
return this.path.substitute({ names });
|
|
151
|
-
}
|
|
152
|
-
static from(path) {
|
|
153
|
-
return new RemoveAction(path);
|
|
154
|
-
}
|
|
155
|
-
}
|
|
156
|
-
exports.RemoveAction = RemoveAction;
|
|
157
|
-
/**
|
|
158
|
-
* Returns an action that will remove the specific attribute at the provided path.
|
|
159
|
-
*
|
|
160
|
-
* @param path - The path of the attribute to remove. * @see https://docs.aws.amazon.com/amazondynamodb/latest/developerguide/Expressions.UpdateExpressions.html#Expressions.UpdateExpressions.DELETE
|
|
161
|
-
|
|
162
|
-
*
|
|
163
|
-
* @returns A {@link RemoveAction} corresponding to the path provided.
|
|
164
|
-
*/
|
|
165
|
-
function remove(path) {
|
|
166
|
-
return RemoveAction.from(path);
|
|
167
|
-
}
|
|
168
|
-
// Note: the first operand *must* be an attribute name, and the second operand *must* be a value.
|
|
169
|
-
// This action only makes sense for sets and numbers.
|
|
170
|
-
class AddAction {
|
|
171
|
-
path;
|
|
172
|
-
value;
|
|
173
|
-
constructor(params) {
|
|
174
|
-
const { path, value } = params;
|
|
175
|
-
this.path = path;
|
|
176
|
-
this.value = value;
|
|
177
|
-
}
|
|
178
|
-
stringify(params) {
|
|
179
|
-
const { names, values } = params;
|
|
180
|
-
return `${this.path.substitute({ names })} ${this.value.substitute({ values })}`;
|
|
181
|
-
}
|
|
182
|
-
static from(params) {
|
|
183
|
-
return new AddAction(params);
|
|
184
|
-
}
|
|
185
|
-
}
|
|
186
|
-
exports.AddAction = AddAction;
|
|
187
|
-
/**
|
|
188
|
-
* Returns an action that will add the provided value to the attribute at the specified path.
|
|
189
|
-
*
|
|
190
|
-
* What adding means depends on the type of the attribute:
|
|
191
|
-
* - If both the attribute and the value are numbers, then an increment operation is performed.
|
|
192
|
-
* - If both the attribute and the value are sets, then a concatenation is performed.
|
|
193
|
-
*
|
|
194
|
-
* This action only supports numbers and sets as values.
|
|
195
|
-
*
|
|
196
|
-
* @param path - The attribute path to modify.
|
|
197
|
-
* @param value - The value to add to the attribute.
|
|
198
|
-
*
|
|
199
|
-
* @returns An {@link AddAction} that will add the value to the attribute at the specified path.
|
|
200
|
-
*
|
|
201
|
-
* @see https://docs.aws.amazon.com/amazondynamodb/latest/developerguide/Expressions.UpdateExpressions.html#Expressions.UpdateExpressions.ADD
|
|
202
|
-
*/
|
|
203
|
-
function add(path, value) {
|
|
204
|
-
return AddAction.from({ path, value });
|
|
205
|
-
}
|
|
206
|
-
class DeleteAction {
|
|
207
|
-
path;
|
|
208
|
-
value;
|
|
209
|
-
constructor(params) {
|
|
210
|
-
const { path, value } = params;
|
|
211
|
-
this.path = path;
|
|
212
|
-
this.value = value;
|
|
213
|
-
}
|
|
214
|
-
stringify(params) {
|
|
215
|
-
const { names, values } = params;
|
|
216
|
-
return `${this.path.substitute({ names })} ${this.value.substitute({
|
|
217
|
-
values,
|
|
218
|
-
})}`;
|
|
219
|
-
}
|
|
220
|
-
static from(params) {
|
|
221
|
-
return new DeleteAction(params);
|
|
222
|
-
}
|
|
223
|
-
}
|
|
224
|
-
exports.DeleteAction = DeleteAction;
|
|
225
|
-
/**
|
|
226
|
-
* Returns an action that will delete the provided subset from the attribute at the specified path.
|
|
227
|
-
*
|
|
228
|
-
* This operation only supports sets as values. The resulting set will be the original set minus the
|
|
229
|
-
* provided subset.
|
|
230
|
-
*
|
|
231
|
-
* @param path - The attribute path to modify.
|
|
232
|
-
* @param value - The value to remove from the attribute.
|
|
233
|
-
*
|
|
234
|
-
* @returns A {@link DeleteAction} that will remove the subset from the attribute.
|
|
235
|
-
*
|
|
236
|
-
* @see https://docs.aws.amazon.com/amazondynamodb/latest/developerguide/Expressions.UpdateExpressions.html#Expressions.UpdateExpressions.DELETE
|
|
237
|
-
*/
|
|
238
|
-
function deleteFrom(path, value) {
|
|
239
|
-
return DeleteAction.from({ path, value });
|
|
240
|
-
}
|
|
241
|
-
class IfNotExistsOperand {
|
|
242
|
-
path;
|
|
243
|
-
defaultValue;
|
|
244
|
-
constructor(params) {
|
|
245
|
-
const { path, defaultValue } = params;
|
|
246
|
-
this.path = path;
|
|
247
|
-
this.defaultValue = defaultValue;
|
|
248
|
-
}
|
|
249
|
-
substitute(params) {
|
|
250
|
-
const { names, values } = params;
|
|
251
|
-
return `if_not_exists(${this.path.substitute({ names })}, ${this.defaultValue.substitute({ names, values })})`;
|
|
252
|
-
}
|
|
253
|
-
}
|
|
254
|
-
exports.IfNotExistsOperand = IfNotExistsOperand;
|
|
255
|
-
function ifNotExists(path, defaultValue) {
|
|
256
|
-
return new IfNotExistsOperand({ path, defaultValue });
|
|
257
|
-
}
|
|
258
|
-
//# sourceMappingURL=update.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"update.js","sourceRoot":"","sources":["../../../../src/commands/expressions/update.ts"],"names":[],"mappings":";;;AAgOA,kBAEC;AA2BD,wBAEC;AAmDD,kBAKC;AA8CD,gCAKC;AAqBD,kCAKC;AA5VD;;;GAGG;AACH,MAAa,gBAAgB;IACV,OAAO,CAA0B;IAElD,YAAoB,OAAgC;QAClD,IAAI,CAAC,OAAO,GAAG,OAAO,CAAC;IACzB,CAAC;IAED,SAAS,CAAC,MAGT;QACC,MAAM,EAAE,KAAK,EAAE,MAAM,EAAE,GAAG,MAAM,CAAC;QACjC,MAAM,KAAK,GAAa,EAAE,CAAC;QAC3B,IAAI,IAAI,CAAC,OAAO,CAAC,GAAG,IAAI,IAAI,EAAE,CAAC;YAC7B,KAAK,CAAC,IAAI,CACR,OAAO,IAAI,CAAC,OAAO,CAAC,GAAG;iBACpB,GAAG,CAAC,CAAC,MAAM,EAAE,EAAE,CAAC,MAAM,CAAC,SAAS,CAAC,EAA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sC;IAEtC,OAAO,YAAY,CAAC,IAAI,CAAC,EAAE,IAAI,EAAE,KAAK,EAAE,CAAC,CAAC;AAC5C,CAAC;AAED,MAAa,kBAAkB;IACZ,IAAI,CAAmB;IACvB,YAAY,CAAU;IAEvC,YAAY,MAAyD;QACnE,MAAM,EAAE,IAAI,EAAE,YAAY,EAAE,GAAG,MAAM,CAAC;QACtC,IAAI,CAAC,IAAI,GAAG,IAAI,CAAC;QACjB,IAAI,CAAC,YAAY,GAAG,YAAY,CAAC;IACnC,CAAC;IAED,UAAU,CAAC,MAGV;QACC,MAAM,EAAE,KAAK,EAAE,MAAM,EAAE,GAAG,MAAM,CAAC;QACjC,OAAO,iBAAiB,IAAI,CAAC,IAAI,CAAC,UAAU,CAAC,EAAE,KAAK,EAAE,CAAC,KAAK,IAAI,CAAC,YAAY,CAAC,UAAU,CAAC,EAAE,KAAK,EAAE,MAAM,EAAE,CAAC,GAAG,CAAC;IACjH,CAAC;CACF;AAjBD,gDAiBC;AAED,SAAgB,WAAW,CACzB,IAAsB,EACtB,YAAqB;IAErB,OAAO,IAAI,kBAAkB,CAAC,EAAE,IAAI,EAAE,YAAY,EAAE,CAAC,CAAC;AACxD,CAAC"}
|
|
@@ -1,163 +0,0 @@
|
|
|
1
|
-
import type { AttributeValueNumber, AttributeValueSet } from "../../types.js";
|
|
2
|
-
import type { AttributeNames } from "../attributes/names.js";
|
|
3
|
-
import type { AttributeValues } from "../attributes/values.js";
|
|
4
|
-
import type { IExpression } from "./expression.js";
|
|
5
|
-
import type { AttributeOperand } from "./operands/name.js";
|
|
6
|
-
import type { IOperand, Operand } from "./operands/type.js";
|
|
7
|
-
import type { ValueOperand } from "./operands/value.js";
|
|
8
|
-
export type UpdateExpressionParams = ReadonlyArray<UpdateAction>;
|
|
9
|
-
/**
|
|
10
|
-
*
|
|
11
|
-
* @see https://docs.aws.amazon.com/amazondynamodb/latest/developerguide/Expressions.UpdateExpressions.html
|
|
12
|
-
*/
|
|
13
|
-
export declare class UpdateExpression implements IExpression {
|
|
14
|
-
private readonly clauses;
|
|
15
|
-
private constructor();
|
|
16
|
-
stringify(params: {
|
|
17
|
-
names: AttributeNames;
|
|
18
|
-
values: AttributeValues;
|
|
19
|
-
}): string;
|
|
20
|
-
static from(params: UpdateExpressionParams): UpdateExpression;
|
|
21
|
-
}
|
|
22
|
-
export interface IUpdateAction {
|
|
23
|
-
stringify(params: {
|
|
24
|
-
names: AttributeNames;
|
|
25
|
-
values: AttributeValues;
|
|
26
|
-
}): string;
|
|
27
|
-
}
|
|
28
|
-
export type UpdateAction = AddAction | DeleteAction | RemoveAction | SetAction;
|
|
29
|
-
export type SetAction = SetTo | SetToPlus | SetToMinus;
|
|
30
|
-
export type SetOperand = Operand | IfNotExistsOperand;
|
|
31
|
-
declare class SetTo implements IUpdateAction {
|
|
32
|
-
private readonly path;
|
|
33
|
-
private readonly operand;
|
|
34
|
-
constructor(params: {
|
|
35
|
-
path: AttributeOperand;
|
|
36
|
-
operand: SetOperand;
|
|
37
|
-
});
|
|
38
|
-
plus(operand: SetOperand): SetToPlus;
|
|
39
|
-
minus(operand: SetOperand): SetToMinus;
|
|
40
|
-
stringify(params: {
|
|
41
|
-
names: AttributeNames;
|
|
42
|
-
values: AttributeValues;
|
|
43
|
-
}): string;
|
|
44
|
-
}
|
|
45
|
-
export declare class SetToPlus implements IUpdateAction {
|
|
46
|
-
private readonly inner;
|
|
47
|
-
private readonly operand;
|
|
48
|
-
constructor(params: {
|
|
49
|
-
inner: SetTo;
|
|
50
|
-
operand: SetOperand;
|
|
51
|
-
});
|
|
52
|
-
stringify(params: {
|
|
53
|
-
names: AttributeNames;
|
|
54
|
-
values: AttributeValues;
|
|
55
|
-
}): string;
|
|
56
|
-
}
|
|
57
|
-
export declare class SetToMinus implements IUpdateAction {
|
|
58
|
-
private readonly inner;
|
|
59
|
-
private readonly operand;
|
|
60
|
-
constructor(params: {
|
|
61
|
-
inner: SetTo;
|
|
62
|
-
operand: SetOperand;
|
|
63
|
-
});
|
|
64
|
-
stringify(params: {
|
|
65
|
-
names: AttributeNames;
|
|
66
|
-
values: AttributeValues;
|
|
67
|
-
}): string;
|
|
68
|
-
}
|
|
69
|
-
declare class SetToBuilder {
|
|
70
|
-
private readonly path;
|
|
71
|
-
constructor(path: AttributeOperand);
|
|
72
|
-
to(operand: SetOperand): SetTo;
|
|
73
|
-
}
|
|
74
|
-
export declare function set(path: AttributeOperand): SetToBuilder;
|
|
75
|
-
export declare class RemoveAction implements IUpdateAction {
|
|
76
|
-
private readonly path;
|
|
77
|
-
private constructor();
|
|
78
|
-
stringify(params: {
|
|
79
|
-
names: AttributeNames;
|
|
80
|
-
}): string;
|
|
81
|
-
static from(path: AttributeOperand): RemoveAction;
|
|
82
|
-
}
|
|
83
|
-
/**
|
|
84
|
-
* Returns an action that will remove the specific attribute at the provided path.
|
|
85
|
-
*
|
|
86
|
-
* @param path - The path of the attribute to remove. * @see https://docs.aws.amazon.com/amazondynamodb/latest/developerguide/Expressions.UpdateExpressions.html#Expressions.UpdateExpressions.DELETE
|
|
87
|
-
|
|
88
|
-
*
|
|
89
|
-
* @returns A {@link RemoveAction} corresponding to the path provided.
|
|
90
|
-
*/
|
|
91
|
-
export declare function remove(path: AttributeOperand): RemoveAction;
|
|
92
|
-
type NumberOrSet = AttributeValueNumber | AttributeValueSet;
|
|
93
|
-
export declare class AddAction implements IUpdateAction {
|
|
94
|
-
private readonly path;
|
|
95
|
-
private readonly value;
|
|
96
|
-
private constructor();
|
|
97
|
-
stringify(params: {
|
|
98
|
-
names: AttributeNames;
|
|
99
|
-
values: AttributeValues;
|
|
100
|
-
}): string;
|
|
101
|
-
static from(params: {
|
|
102
|
-
path: AttributeOperand;
|
|
103
|
-
value: ValueOperand<NumberOrSet>;
|
|
104
|
-
}): AddAction;
|
|
105
|
-
}
|
|
106
|
-
/**
|
|
107
|
-
* Returns an action that will add the provided value to the attribute at the specified path.
|
|
108
|
-
*
|
|
109
|
-
* What adding means depends on the type of the attribute:
|
|
110
|
-
* - If both the attribute and the value are numbers, then an increment operation is performed.
|
|
111
|
-
* - If both the attribute and the value are sets, then a concatenation is performed.
|
|
112
|
-
*
|
|
113
|
-
* This action only supports numbers and sets as values.
|
|
114
|
-
*
|
|
115
|
-
* @param path - The attribute path to modify.
|
|
116
|
-
* @param value - The value to add to the attribute.
|
|
117
|
-
*
|
|
118
|
-
* @returns An {@link AddAction} that will add the value to the attribute at the specified path.
|
|
119
|
-
*
|
|
120
|
-
* @see https://docs.aws.amazon.com/amazondynamodb/latest/developerguide/Expressions.UpdateExpressions.html#Expressions.UpdateExpressions.ADD
|
|
121
|
-
*/
|
|
122
|
-
export declare function add(path: AttributeOperand, value: ValueOperand<NumberOrSet>): AddAction;
|
|
123
|
-
export declare class DeleteAction implements IUpdateAction {
|
|
124
|
-
private readonly path;
|
|
125
|
-
private readonly value;
|
|
126
|
-
private constructor();
|
|
127
|
-
stringify(params: {
|
|
128
|
-
names: AttributeNames;
|
|
129
|
-
values: AttributeValues;
|
|
130
|
-
}): string;
|
|
131
|
-
static from(params: {
|
|
132
|
-
path: AttributeOperand;
|
|
133
|
-
value: ValueOperand<AttributeValueSet>;
|
|
134
|
-
}): DeleteAction;
|
|
135
|
-
}
|
|
136
|
-
/**
|
|
137
|
-
* Returns an action that will delete the provided subset from the attribute at the specified path.
|
|
138
|
-
*
|
|
139
|
-
* This operation only supports sets as values. The resulting set will be the original set minus the
|
|
140
|
-
* provided subset.
|
|
141
|
-
*
|
|
142
|
-
* @param path - The attribute path to modify.
|
|
143
|
-
* @param value - The value to remove from the attribute.
|
|
144
|
-
*
|
|
145
|
-
* @returns A {@link DeleteAction} that will remove the subset from the attribute.
|
|
146
|
-
*
|
|
147
|
-
* @see https://docs.aws.amazon.com/amazondynamodb/latest/developerguide/Expressions.UpdateExpressions.html#Expressions.UpdateExpressions.DELETE
|
|
148
|
-
*/
|
|
149
|
-
export declare function deleteFrom(path: AttributeOperand, value: ValueOperand<AttributeValueSet>): DeleteAction;
|
|
150
|
-
export declare class IfNotExistsOperand implements IOperand {
|
|
151
|
-
private readonly path;
|
|
152
|
-
private readonly defaultValue;
|
|
153
|
-
constructor(params: {
|
|
154
|
-
path: AttributeOperand;
|
|
155
|
-
defaultValue: Operand;
|
|
156
|
-
});
|
|
157
|
-
substitute(params: {
|
|
158
|
-
names: AttributeNames;
|
|
159
|
-
values: AttributeValues;
|
|
160
|
-
}): string;
|
|
161
|
-
}
|
|
162
|
-
export declare function ifNotExists(path: AttributeOperand, defaultValue: Operand): IfNotExistsOperand;
|
|
163
|
-
export {};
|
|
@@ -1,243 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
*
|
|
3
|
-
* @see https://docs.aws.amazon.com/amazondynamodb/latest/developerguide/Expressions.UpdateExpressions.html
|
|
4
|
-
*/
|
|
5
|
-
export class UpdateExpression {
|
|
6
|
-
clauses;
|
|
7
|
-
constructor(clauses) {
|
|
8
|
-
this.clauses = clauses;
|
|
9
|
-
}
|
|
10
|
-
stringify(params) {
|
|
11
|
-
const { names, values } = params;
|
|
12
|
-
const parts = [];
|
|
13
|
-
if (this.clauses.set != null) {
|
|
14
|
-
parts.push(`SET ${this.clauses.set
|
|
15
|
-
.map((action) => action.stringify({ names, values }))
|
|
16
|
-
.join(",")}`);
|
|
17
|
-
}
|
|
18
|
-
if (this.clauses.remove != null) {
|
|
19
|
-
parts.push(`REMOVE ${this.clauses.remove
|
|
20
|
-
.map((action) => action.stringify({ names }))
|
|
21
|
-
.join(",")}`);
|
|
22
|
-
}
|
|
23
|
-
if (this.clauses.add != null) {
|
|
24
|
-
parts.push(`ADD ${this.clauses.add
|
|
25
|
-
.map((action) => action.stringify({ names, values }))
|
|
26
|
-
.join(",")}`);
|
|
27
|
-
}
|
|
28
|
-
if (this.clauses.delete != null) {
|
|
29
|
-
parts.push(`DELETE ${this.clauses.delete
|
|
30
|
-
.map((action) => action.stringify({ names, values }))
|
|
31
|
-
.join(",")}`);
|
|
32
|
-
}
|
|
33
|
-
return parts.join("\n");
|
|
34
|
-
}
|
|
35
|
-
static from(params) {
|
|
36
|
-
const clauses = {};
|
|
37
|
-
for (const action of params) {
|
|
38
|
-
if (action instanceof SetTo ||
|
|
39
|
-
action instanceof SetToPlus ||
|
|
40
|
-
action instanceof SetToMinus) {
|
|
41
|
-
clauses.set ??= [];
|
|
42
|
-
clauses.set.push(action);
|
|
43
|
-
}
|
|
44
|
-
else if (action instanceof RemoveAction) {
|
|
45
|
-
clauses.remove ??= [];
|
|
46
|
-
clauses.remove.push(action);
|
|
47
|
-
}
|
|
48
|
-
else if (action instanceof DeleteAction) {
|
|
49
|
-
clauses.delete ??= [];
|
|
50
|
-
clauses.delete.push(action);
|
|
51
|
-
}
|
|
52
|
-
else if (action instanceof AddAction) {
|
|
53
|
-
clauses.add ??= [];
|
|
54
|
-
clauses.add.push(action);
|
|
55
|
-
}
|
|
56
|
-
else {
|
|
57
|
-
throw new Error("unknown action type in update expression");
|
|
58
|
-
}
|
|
59
|
-
}
|
|
60
|
-
return new UpdateExpression(clauses);
|
|
61
|
-
}
|
|
62
|
-
}
|
|
63
|
-
class SetTo {
|
|
64
|
-
path;
|
|
65
|
-
operand;
|
|
66
|
-
constructor(params) {
|
|
67
|
-
const { path, operand } = params;
|
|
68
|
-
this.path = path;
|
|
69
|
-
this.operand = operand;
|
|
70
|
-
}
|
|
71
|
-
plus(operand) {
|
|
72
|
-
return new SetToPlus({ inner: this, operand });
|
|
73
|
-
}
|
|
74
|
-
minus(operand) {
|
|
75
|
-
return new SetToMinus({ inner: this, operand });
|
|
76
|
-
}
|
|
77
|
-
stringify(params) {
|
|
78
|
-
const { names, values } = params;
|
|
79
|
-
return `${this.path.substitute({ names })} = ${this.operand.substitute({
|
|
80
|
-
names,
|
|
81
|
-
values,
|
|
82
|
-
})}`;
|
|
83
|
-
}
|
|
84
|
-
}
|
|
85
|
-
export class SetToPlus {
|
|
86
|
-
inner;
|
|
87
|
-
operand;
|
|
88
|
-
constructor(params) {
|
|
89
|
-
const { inner, operand } = params;
|
|
90
|
-
this.inner = inner;
|
|
91
|
-
this.operand = operand;
|
|
92
|
-
}
|
|
93
|
-
stringify(params) {
|
|
94
|
-
const { names, values } = params;
|
|
95
|
-
return `${this.inner.stringify({ names, values })} + ${this.operand.substitute({
|
|
96
|
-
names,
|
|
97
|
-
values,
|
|
98
|
-
})}`;
|
|
99
|
-
}
|
|
100
|
-
}
|
|
101
|
-
export class SetToMinus {
|
|
102
|
-
inner;
|
|
103
|
-
operand;
|
|
104
|
-
constructor(params) {
|
|
105
|
-
const { inner, operand } = params;
|
|
106
|
-
this.inner = inner;
|
|
107
|
-
this.operand = operand;
|
|
108
|
-
}
|
|
109
|
-
stringify(params) {
|
|
110
|
-
const { names, values } = params;
|
|
111
|
-
return `${this.inner.stringify({ names, values })} - ${this.operand.substitute({
|
|
112
|
-
names,
|
|
113
|
-
values,
|
|
114
|
-
})}`;
|
|
115
|
-
}
|
|
116
|
-
}
|
|
117
|
-
class SetToBuilder {
|
|
118
|
-
path;
|
|
119
|
-
constructor(path) {
|
|
120
|
-
this.path = path;
|
|
121
|
-
}
|
|
122
|
-
to(operand) {
|
|
123
|
-
return new SetTo({ path: this.path, operand });
|
|
124
|
-
}
|
|
125
|
-
}
|
|
126
|
-
// TODO: increment/decrement utilities built on top of the assignments.
|
|
127
|
-
// TODO: review API for something more streamlined.... Imagine something like:
|
|
128
|
-
// set(attribute(<name>), value(<value>)) or set(attribute(<name>), value(<first>), "+", value(<second>))
|
|
129
|
-
export function set(path) {
|
|
130
|
-
return new SetToBuilder(path);
|
|
131
|
-
}
|
|
132
|
-
export class RemoveAction {
|
|
133
|
-
path;
|
|
134
|
-
constructor(path) {
|
|
135
|
-
this.path = path;
|
|
136
|
-
}
|
|
137
|
-
stringify(params) {
|
|
138
|
-
const { names } = params;
|
|
139
|
-
return this.path.substitute({ names });
|
|
140
|
-
}
|
|
141
|
-
static from(path) {
|
|
142
|
-
return new RemoveAction(path);
|
|
143
|
-
}
|
|
144
|
-
}
|
|
145
|
-
/**
|
|
146
|
-
* Returns an action that will remove the specific attribute at the provided path.
|
|
147
|
-
*
|
|
148
|
-
* @param path - The path of the attribute to remove. * @see https://docs.aws.amazon.com/amazondynamodb/latest/developerguide/Expressions.UpdateExpressions.html#Expressions.UpdateExpressions.DELETE
|
|
149
|
-
|
|
150
|
-
*
|
|
151
|
-
* @returns A {@link RemoveAction} corresponding to the path provided.
|
|
152
|
-
*/
|
|
153
|
-
export function remove(path) {
|
|
154
|
-
return RemoveAction.from(path);
|
|
155
|
-
}
|
|
156
|
-
// Note: the first operand *must* be an attribute name, and the second operand *must* be a value.
|
|
157
|
-
// This action only makes sense for sets and numbers.
|
|
158
|
-
export class AddAction {
|
|
159
|
-
path;
|
|
160
|
-
value;
|
|
161
|
-
constructor(params) {
|
|
162
|
-
const { path, value } = params;
|
|
163
|
-
this.path = path;
|
|
164
|
-
this.value = value;
|
|
165
|
-
}
|
|
166
|
-
stringify(params) {
|
|
167
|
-
const { names, values } = params;
|
|
168
|
-
return `${this.path.substitute({ names })} ${this.value.substitute({ values })}`;
|
|
169
|
-
}
|
|
170
|
-
static from(params) {
|
|
171
|
-
return new AddAction(params);
|
|
172
|
-
}
|
|
173
|
-
}
|
|
174
|
-
/**
|
|
175
|
-
* Returns an action that will add the provided value to the attribute at the specified path.
|
|
176
|
-
*
|
|
177
|
-
* What adding means depends on the type of the attribute:
|
|
178
|
-
* - If both the attribute and the value are numbers, then an increment operation is performed.
|
|
179
|
-
* - If both the attribute and the value are sets, then a concatenation is performed.
|
|
180
|
-
*
|
|
181
|
-
* This action only supports numbers and sets as values.
|
|
182
|
-
*
|
|
183
|
-
* @param path - The attribute path to modify.
|
|
184
|
-
* @param value - The value to add to the attribute.
|
|
185
|
-
*
|
|
186
|
-
* @returns An {@link AddAction} that will add the value to the attribute at the specified path.
|
|
187
|
-
*
|
|
188
|
-
* @see https://docs.aws.amazon.com/amazondynamodb/latest/developerguide/Expressions.UpdateExpressions.html#Expressions.UpdateExpressions.ADD
|
|
189
|
-
*/
|
|
190
|
-
export function add(path, value) {
|
|
191
|
-
return AddAction.from({ path, value });
|
|
192
|
-
}
|
|
193
|
-
export class DeleteAction {
|
|
194
|
-
path;
|
|
195
|
-
value;
|
|
196
|
-
constructor(params) {
|
|
197
|
-
const { path, value } = params;
|
|
198
|
-
this.path = path;
|
|
199
|
-
this.value = value;
|
|
200
|
-
}
|
|
201
|
-
stringify(params) {
|
|
202
|
-
const { names, values } = params;
|
|
203
|
-
return `${this.path.substitute({ names })} ${this.value.substitute({
|
|
204
|
-
values,
|
|
205
|
-
})}`;
|
|
206
|
-
}
|
|
207
|
-
static from(params) {
|
|
208
|
-
return new DeleteAction(params);
|
|
209
|
-
}
|
|
210
|
-
}
|
|
211
|
-
/**
|
|
212
|
-
* Returns an action that will delete the provided subset from the attribute at the specified path.
|
|
213
|
-
*
|
|
214
|
-
* This operation only supports sets as values. The resulting set will be the original set minus the
|
|
215
|
-
* provided subset.
|
|
216
|
-
*
|
|
217
|
-
* @param path - The attribute path to modify.
|
|
218
|
-
* @param value - The value to remove from the attribute.
|
|
219
|
-
*
|
|
220
|
-
* @returns A {@link DeleteAction} that will remove the subset from the attribute.
|
|
221
|
-
*
|
|
222
|
-
* @see https://docs.aws.amazon.com/amazondynamodb/latest/developerguide/Expressions.UpdateExpressions.html#Expressions.UpdateExpressions.DELETE
|
|
223
|
-
*/
|
|
224
|
-
export function deleteFrom(path, value) {
|
|
225
|
-
return DeleteAction.from({ path, value });
|
|
226
|
-
}
|
|
227
|
-
export class IfNotExistsOperand {
|
|
228
|
-
path;
|
|
229
|
-
defaultValue;
|
|
230
|
-
constructor(params) {
|
|
231
|
-
const { path, defaultValue } = params;
|
|
232
|
-
this.path = path;
|
|
233
|
-
this.defaultValue = defaultValue;
|
|
234
|
-
}
|
|
235
|
-
substitute(params) {
|
|
236
|
-
const { names, values } = params;
|
|
237
|
-
return `if_not_exists(${this.path.substitute({ names })}, ${this.defaultValue.substitute({ names, values })})`;
|
|
238
|
-
}
|
|
239
|
-
}
|
|
240
|
-
export function ifNotExists(path, defaultValue) {
|
|
241
|
-
return new IfNotExistsOperand({ path, defaultValue });
|
|
242
|
-
}
|
|
243
|
-
//# sourceMappingURL=update.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"update.js","sourceRoot":"","sources":["../../../../src/commands/expressions/update.ts"],"names":[],"mappings":"AAwCA;;;GAGG;AACH,MAAM,OAAO,gBAAgB;IACV,OAAO,CAA0B;IAElD,YAAoB,OAAgC;QAClD,IAAI,CAAC,OAAO,GAAG,OAAO,CAAC;IACzB,CAAC;IAED,SAAS,CAAC,MAGT;QACC,MAAM,EAAE,KAAK,EAAE,MAAM,EAAE,GAAG,MAAM,CAAC;QACjC,MAAM,KAAK,GAAa,EAAE,CAAC;QAC3B,IAAI,IAAI,CAAC,OAAO,CAAC,GAAG,IAAI,IAAI,EAAE,CAAC;YAC7B,KAAK,CAAC,IAAI,CACR,OAAO,IAAI,CAAC,OAAO,CAAC,GAAG;iBACpB,GAAG,CAAC,CAAC,MAAM,EAAE,EAAE,CAAC,MAAM,CAAC,SAAS,CAAC,EAAE,KAAK,EAAE,MAAM,EAAE,CAAC,CAAC;iBACpD,IAAI,CAAC,GAAG,CAAC,EAAE,CACf,CAAC;QACJ,CAAC;QACD,IAAI,IAAI,CAAC,OAAO,CAAC,MAAM,IAAI,IAAI,EAAE,CAAC;YAChC,KAAK,CAAC,IAAI,CACR,UAAU,IAAI,CAAC,OAAO,CAAC,MAAM;iBAC1B,GAAG,CAAC,CAAC,MAAM,EAAE,EAAE,CAAC,MAAM,CAAC,SAAS,CAAC,EAAE,KAAK,EAAE,CAAC,CAAC;iBAC5C,IAAI,CAAC,GAAG,CAAC,EAAE,CACf,CAAC;QACJ,CAAC;QACD,IAAI,IAAI,CAAC,OAAO,CAAC,GAAG,IAAI,IAAI,EAAE,CAAC;YAC7B,KAAK,CAAC,IAAI,CACR,OAAO,IAAI,CAAC,OAAO,CAAC,G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