@infra-blocks/aws-dynamodb 0.15.0-alpha.2 → 0.16.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.
Files changed (31) hide show
  1. package/lib/cjs/commands/expressions/condition.d.ts +213 -2
  2. package/lib/cjs/commands/expressions/condition.js +349 -0
  3. package/lib/cjs/commands/expressions/condition.js.map +1 -1
  4. package/lib/cjs/commands/expressions/index.d.ts +2 -1
  5. package/lib/cjs/commands/expressions/index.js +2 -1
  6. package/lib/cjs/commands/expressions/index.js.map +1 -1
  7. package/lib/cjs/commands/expressions/key-condition.d.ts +2 -2
  8. package/lib/cjs/commands/expressions/operands.d.ts +28 -0
  9. package/lib/cjs/commands/expressions/operands.js +34 -0
  10. package/lib/cjs/commands/expressions/operands.js.map +1 -0
  11. package/lib/cjs/commands/put-item.d.ts +2 -2
  12. package/lib/cjs/commands/put-item.js.map +1 -1
  13. package/lib/esm/commands/expressions/condition.d.ts +213 -2
  14. package/lib/esm/commands/expressions/condition.js +341 -1
  15. package/lib/esm/commands/expressions/condition.js.map +1 -1
  16. package/lib/esm/commands/expressions/index.d.ts +2 -1
  17. package/lib/esm/commands/expressions/index.js +2 -1
  18. package/lib/esm/commands/expressions/index.js.map +1 -1
  19. package/lib/esm/commands/expressions/key-condition.d.ts +2 -2
  20. package/lib/esm/commands/expressions/operands.d.ts +28 -0
  21. package/lib/esm/commands/expressions/operands.js +27 -0
  22. package/lib/esm/commands/expressions/operands.js.map +1 -0
  23. package/lib/esm/commands/put-item.d.ts +2 -2
  24. package/lib/esm/commands/put-item.js.map +1 -1
  25. package/package.json +1 -1
  26. package/lib/cjs/commands/expressions/expression.d.ts +0 -185
  27. package/lib/cjs/commands/expressions/expression.js +0 -326
  28. package/lib/cjs/commands/expressions/expression.js.map +0 -1
  29. package/lib/esm/commands/expressions/expression.d.ts +0 -185
  30. package/lib/esm/commands/expressions/expression.js +0 -315
  31. package/lib/esm/commands/expressions/expression.js.map +0 -1
@@ -1,2 +1,213 @@
1
- import type { Expression } from "./expression.js";
2
- export type ConditionExpression = Expression;
1
+ import type { AttributeType } from "../../types.js";
2
+ import type { AttributeNames } from "../attributes/names.js";
3
+ import type { AttributeValues } from "../attributes/values.js";
4
+ import { AttributeOperand, type IOperand, type Operand, type ValueOperand } from "./operands.js";
5
+ export type ConditionOperand = Operand | SizeOperand;
6
+ export type Stringifier = (params: {
7
+ names: AttributeNames;
8
+ values: AttributeValues;
9
+ }) => string;
10
+ export interface ConditionParams {
11
+ stringify: Stringifier;
12
+ }
13
+ export declare class Condition {
14
+ private readonly stringifier;
15
+ constructor(params: ConditionParams);
16
+ stringify(params: {
17
+ names: AttributeNames;
18
+ values: AttributeValues;
19
+ }): string;
20
+ /**
21
+ * Returns a condition that combines this one with the provided condition using the `AND` operator.
22
+ *
23
+ * @param other - The other condition to combine with this one.
24
+ *
25
+ * @returns A {@link Condition} that evaluates to true only if both conditions evaluate to true.
26
+ *
27
+ * @see https://docs.aws.amazon.com/amazondynamodb/latest/developerguide/Expressions.OperatorsAndFunctions.html#Expressions.OperatorsAndFunctions.LogicalEvaluations
28
+ */
29
+ and(other: Condition): Condition;
30
+ /**
31
+ * Returns a condition that combines this one with the provided condition using the `OR` operator.
32
+ *
33
+ * @param other - The other condition to combine with this one.
34
+ *
35
+ * @returns A {@link Condition} that evaluates to true if any conditions evaluate to true.
36
+ *
37
+ * @see https://docs.aws.amazon.com/amazondynamodb/latest/developerguide/Expressions.OperatorsAndFunctions.html#Expressions.OperatorsAndFunctions.LogicalEvaluations
38
+ */
39
+ or(other: Condition): Condition;
40
+ }
41
+ /**
42
+ * Negates the provided condition using the `NOT` operator.
43
+ *
44
+ * @param inner - The condition to negate.
45
+ *
46
+ * @returns A {@link Condition} that evaluates to the opposite of what the provided condition evaluates to.
47
+ *
48
+ * @see https://docs.aws.amazon.com/amazondynamodb/latest/developerguide/Expressions.OperatorsAndFunctions.html#Expressions.OperatorsAndFunctions.LogicalEvaluations
49
+ */
50
+ export declare function not(inner: Condition): Condition;
51
+ export declare class OperandConditionBuilder<T extends Operand> {
52
+ protected readonly operand: T;
53
+ constructor(operand: T);
54
+ /**
55
+ * Returns a condition that uses the `begins_with` function.
56
+ *
57
+ * @param rhs - The right hand side operand.
58
+ *
59
+ * @returns A {@link Condition} that evaluates to true if this operand begins with the provided one.
60
+ *
61
+ * @see https://docs.aws.amazon.com/amazondynamodb/latest/developerguide/Expressions.OperatorsAndFunctions.html#Expressions.OperatorsAndFunctions.Functions
62
+ */
63
+ beginsWith(rhs: Operand<string>): Condition;
64
+ /**
65
+ * Returns a condition that uses the `BETWEEN` operator.
66
+ *
67
+ * Both bounds are inclusive, meaning that the returned condition corresponds to `lower <= this <= upper`.
68
+ *
69
+ * @param lower - The lower inclusive bound of the range.
70
+ * @param upper - The upper inclusive bound of the range.
71
+ *
72
+ * @returns A {@link Condition} that evaluates to true if this operand is within the provided bounds.
73
+ *
74
+ * @see https://docs.aws.amazon.com/amazondynamodb/latest/developerguide/Expressions.OperatorsAndFunctions.html#Expressions.OperatorsAndFunctions.Comparators
75
+ */
76
+ between(lower: ConditionOperand, upper: ConditionOperand): Condition;
77
+ /**
78
+ * Returns a condition that uses the `contains` function.
79
+ *
80
+ * @param rhs - The right hand side operand.
81
+ *
82
+ * @returns A {@link Condition} that evaluates to true if this operand contains the provided one.
83
+ *
84
+ * @see https://docs.aws.amazon.com/amazondynamodb/latest/developerguide/Expressions.OperatorsAndFunctions.html#Expressions.OperatorsAndFunctions.Functions
85
+ */
86
+ contains(rhs: ConditionOperand): Condition;
87
+ /**
88
+ * Returns a condition that uses the `=` operator.
89
+ *
90
+ * @param rhs - The right hand side operand.
91
+ *
92
+ * @returns A {@link Condition} that evaluates to true if this operand is equal to the provided one.
93
+ *
94
+ * @see https://docs.aws.amazon.com/amazondynamodb/latest/developerguide/Expressions.OperatorsAndFunctions.html#Expressions.OperatorsAndFunctions.Comparators
95
+ */
96
+ equals(rhs: ConditionOperand): Condition;
97
+ /**
98
+ * An alias for {@link equals}.
99
+ */
100
+ eq: (rhs: ConditionOperand) => Condition;
101
+ /**
102
+ * Returns a condition that uses the `>` operator.
103
+ *
104
+ * @param rhs - The right hand side operand.
105
+ *
106
+ * @returns A {@link Condition} that evaluates to true if this operand is greater than the provided one.
107
+ *
108
+ * @see https://docs.aws.amazon.com/amazondynamodb/latest/developerguide/Expressions.OperatorsAndFunctions.html#Expressions.OperatorsAndFunctions.Comparators
109
+ */
110
+ greaterThan(rhs: ConditionOperand): Condition;
111
+ /**
112
+ * An alias for {@link greaterThan}.
113
+ */
114
+ gt: (rhs: ConditionOperand) => Condition;
115
+ /**
116
+ * Returns a condition that uses the `>=` operator.
117
+ *
118
+ * @param rhs - The right hand side operand.
119
+ *
120
+ * @returns A {@link Condition} that evaluates to true if this operand is greater than or equal to the provided one.
121
+ *
122
+ * @see https://docs.aws.amazon.com/amazondynamodb/latest/developerguide/Expressions.OperatorsAndFunctions.html#Expressions.OperatorsAndFunctions.Comparators
123
+ */
124
+ greaterThanOrEquals(rhs: ConditionOperand): Condition;
125
+ /**
126
+ * An alias for {@link greaterThanOrEquals}
127
+ */
128
+ gte: (rhs: ConditionOperand) => Condition;
129
+ /**
130
+ * Returns a condition that uses the `IN` operator.
131
+ *
132
+ * @param operands - The list of operands to check against. This function throws if the list is
133
+ * empty or contains more than 100 operands.
134
+ *
135
+ * @returns A {@link Condition} that evaluates to true if this operand is equal to any of the provided ones.
136
+ *
137
+ * @see https://docs.aws.amazon.com/amazondynamodb/latest/developerguide/Expressions.OperatorsAndFunctions.html#Expressions.OperatorsAndFunctions.Comparators
138
+ */
139
+ in(...operands: ConditionOperand[]): Condition;
140
+ /**
141
+ * Returns a condition that uses the `<` operator
142
+ *
143
+ * @param rhs - The right hand side operand.
144
+ *
145
+ * @returns A {@link Condition} that evaluates to true if this operand is lower than the provided one.
146
+ *
147
+ * @see https://docs.aws.amazon.com/amazondynamodb/latest/developerguide/Expressions.OperatorsAndFunctions.html#Expressions.OperatorsAndFunctions.Comparators
148
+ */
149
+ lowerThan(rhs: ConditionOperand): Condition;
150
+ /**
151
+ * An alias for {@link lowerThan}.
152
+ */
153
+ lt: (rhs: ConditionOperand) => Condition;
154
+ /**
155
+ * Returns a condition that uses the `<=` operator.
156
+ *
157
+ * @param rhs - The right hand side operand.
158
+ *
159
+ * @returns A {@link Condition} that evaluates to true if this operand is lower than or equal to the provided one.
160
+ *
161
+ * @see https://docs.aws.amazon.com/amazondynamodb/latest/developerguide/Expressions.OperatorsAndFunctions.html#Expressions.OperatorsAndFunctions.Comparators
162
+ */
163
+ lowerThanOrEquals(rhs: ConditionOperand): Condition;
164
+ /**
165
+ * An alias for {@link lowerThanOrEquals}
166
+ */
167
+ lte: (rhs: ConditionOperand) => Condition;
168
+ /**
169
+ * Returns a condition that uses the `<>` operator.
170
+ *
171
+ * @param rhs - The right hand side operand.
172
+ *
173
+ * @returns A {@link Condition} that evaluates to true if this operand is not equal to the provided one.
174
+ *
175
+ * @see https://docs.aws.amazon.com/amazondynamodb/latest/developerguide/Expressions.OperatorsAndFunctions.html#Expressions.OperatorsAndFunctions.Comparators
176
+ */
177
+ notEquals(rhs: ConditionOperand): Condition;
178
+ /**
179
+ * An alias for {@link notEquals}.
180
+ */
181
+ ne: (rhs: ConditionOperand) => Condition;
182
+ protected substitute(params: {
183
+ names: AttributeNames;
184
+ values: AttributeValues;
185
+ }): string;
186
+ }
187
+ export declare class AttributeConditionBuilder extends OperandConditionBuilder<AttributeOperand> {
188
+ /**
189
+ * @returns A {@link Condition} that evaluates to true if the provided attribute path exists.
190
+ */
191
+ exists(): Condition;
192
+ /**
193
+ * @returns A {@link Condition} that evaluates to true if the provided attribute path does not exist.
194
+ */
195
+ notExists(): Condition;
196
+ /**
197
+ * @param type - The type to check against.
198
+ * @returns A {@link Condition} that evaluates to true if there exists an attribute at
199
+ * the provided path of the given type.
200
+ */
201
+ isType(type: ValueOperand<AttributeType>): Condition;
202
+ }
203
+ export declare function where(attrribute: AttributeOperand): AttributeConditionBuilder;
204
+ export declare function where(operand: Exclude<Operand, AttributeOperand>): OperandConditionBuilder<Exclude<Operand, AttributeOperand>>;
205
+ export declare class SizeOperand implements IOperand {
206
+ private readonly inner;
207
+ constructor(operand: Operand);
208
+ substitute(params: {
209
+ names: AttributeNames;
210
+ values: AttributeValues;
211
+ }): string;
212
+ }
213
+ export declare function size(operand: Operand): SizeOperand;
@@ -1,3 +1,352 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.SizeOperand = exports.AttributeConditionBuilder = exports.OperandConditionBuilder = exports.Condition = void 0;
4
+ exports.not = not;
5
+ exports.where = where;
6
+ exports.size = size;
7
+ const operands_js_1 = require("./operands.js");
8
+ class Condition {
9
+ stringifier;
10
+ constructor(params) {
11
+ const { stringify } = params;
12
+ this.stringifier = stringify;
13
+ }
14
+ // TODO: exclude from exported type definitions if possible.
15
+ stringify(params) {
16
+ return this.stringifier(params);
17
+ }
18
+ /**
19
+ * Returns a condition that combines this one with the provided condition using the `AND` operator.
20
+ *
21
+ * @param other - The other condition to combine with this one.
22
+ *
23
+ * @returns A {@link Condition} that evaluates to true only if both conditions evaluate to true.
24
+ *
25
+ * @see https://docs.aws.amazon.com/amazondynamodb/latest/developerguide/Expressions.OperatorsAndFunctions.html#Expressions.OperatorsAndFunctions.LogicalEvaluations
26
+ */
27
+ and(other) {
28
+ return condition({
29
+ stringify: ({ names, values }) => {
30
+ const left = this.stringify({ names, values });
31
+ const right = other.stringify({ names, values });
32
+ return `(${left} AND ${right})`;
33
+ },
34
+ });
35
+ }
36
+ /**
37
+ * Returns a condition that combines this one with the provided condition using the `OR` operator.
38
+ *
39
+ * @param other - The other condition to combine with this one.
40
+ *
41
+ * @returns A {@link Condition} that evaluates to true if any conditions evaluate to true.
42
+ *
43
+ * @see https://docs.aws.amazon.com/amazondynamodb/latest/developerguide/Expressions.OperatorsAndFunctions.html#Expressions.OperatorsAndFunctions.LogicalEvaluations
44
+ */
45
+ or(other) {
46
+ return condition({
47
+ stringify: ({ names, values }) => {
48
+ const left = this.stringify({ names, values });
49
+ const right = other.stringify({ names, values });
50
+ return `(${left} OR ${right})`;
51
+ },
52
+ });
53
+ }
54
+ }
55
+ exports.Condition = Condition;
56
+ /**
57
+ * Negates the provided condition using the `NOT` operator.
58
+ *
59
+ * @param inner - The condition to negate.
60
+ *
61
+ * @returns A {@link Condition} that evaluates to the opposite of what the provided condition evaluates to.
62
+ *
63
+ * @see https://docs.aws.amazon.com/amazondynamodb/latest/developerguide/Expressions.OperatorsAndFunctions.html#Expressions.OperatorsAndFunctions.LogicalEvaluations
64
+ */
65
+ function not(inner) {
66
+ return condition({
67
+ stringify: ({ names, values }) => {
68
+ return `NOT (${inner.stringify({ names, values })})`;
69
+ },
70
+ });
71
+ }
72
+ // TODO: make this a static factory?
73
+ function condition(params) {
74
+ return new Condition(params);
75
+ }
76
+ // NOTE: methods here means that both sides of the conditions can either be attribute names or attribute values.
77
+ class OperandConditionBuilder {
78
+ operand;
79
+ constructor(operand) {
80
+ this.operand = operand;
81
+ }
82
+ /**
83
+ * Returns a condition that uses the `begins_with` function.
84
+ *
85
+ * @param rhs - The right hand side operand.
86
+ *
87
+ * @returns A {@link Condition} that evaluates to true if this operand begins with the provided one.
88
+ *
89
+ * @see https://docs.aws.amazon.com/amazondynamodb/latest/developerguide/Expressions.OperatorsAndFunctions.html#Expressions.OperatorsAndFunctions.Functions
90
+ */
91
+ beginsWith(rhs) {
92
+ return condition({
93
+ stringify: ({ names, values }) => {
94
+ return `begins_with(${this.substitute({ names, values })}, ${rhs.substitute({ names, values })})`;
95
+ },
96
+ });
97
+ }
98
+ /**
99
+ * Returns a condition that uses the `BETWEEN` operator.
100
+ *
101
+ * Both bounds are inclusive, meaning that the returned condition corresponds to `lower <= this <= upper`.
102
+ *
103
+ * @param lower - The lower inclusive bound of the range.
104
+ * @param upper - The upper inclusive bound of the range.
105
+ *
106
+ * @returns A {@link Condition} that evaluates to true if this operand is within the provided bounds.
107
+ *
108
+ * @see https://docs.aws.amazon.com/amazondynamodb/latest/developerguide/Expressions.OperatorsAndFunctions.html#Expressions.OperatorsAndFunctions.Comparators
109
+ */
110
+ // TODO: test with size operands.
111
+ between(lower, upper) {
112
+ return condition({
113
+ stringify: ({ names, values }) => {
114
+ return `${this.substitute({ names, values })} BETWEEN ${lower.substitute({ names, values })} AND ${upper.substitute({ names, values })}`;
115
+ },
116
+ });
117
+ }
118
+ /**
119
+ * Returns a condition that uses the `contains` function.
120
+ *
121
+ * @param rhs - The right hand side operand.
122
+ *
123
+ * @returns A {@link Condition} that evaluates to true if this operand contains the provided one.
124
+ *
125
+ * @see https://docs.aws.amazon.com/amazondynamodb/latest/developerguide/Expressions.OperatorsAndFunctions.html#Expressions.OperatorsAndFunctions.Functions
126
+ */
127
+ // TODO: test with size operands.
128
+ contains(rhs) {
129
+ return condition({
130
+ stringify: ({ names, values }) => {
131
+ return `contains(${this.substitute({ names, values })}, ${rhs.substitute({ names, values })})`;
132
+ },
133
+ });
134
+ }
135
+ /**
136
+ * Returns a condition that uses the `=` operator.
137
+ *
138
+ * @param rhs - The right hand side operand.
139
+ *
140
+ * @returns A {@link Condition} that evaluates to true if this operand is equal to the provided one.
141
+ *
142
+ * @see https://docs.aws.amazon.com/amazondynamodb/latest/developerguide/Expressions.OperatorsAndFunctions.html#Expressions.OperatorsAndFunctions.Comparators
143
+ */
144
+ // TODO: this should be typed better once moved out. It accepts the interface only to make the tests compile.
145
+ equals(rhs) {
146
+ return condition({
147
+ stringify: ({ names, values }) => {
148
+ return `${this.substitute({ names, values })} = ${rhs.substitute({ names, values })}`;
149
+ },
150
+ });
151
+ }
152
+ /**
153
+ * An alias for {@link equals}.
154
+ */
155
+ eq = this.equals.bind(this);
156
+ /**
157
+ * Returns a condition that uses the `>` operator.
158
+ *
159
+ * @param rhs - The right hand side operand.
160
+ *
161
+ * @returns A {@link Condition} that evaluates to true if this operand is greater than the provided one.
162
+ *
163
+ * @see https://docs.aws.amazon.com/amazondynamodb/latest/developerguide/Expressions.OperatorsAndFunctions.html#Expressions.OperatorsAndFunctions.Comparators
164
+ */
165
+ // TODO: test that both sides can be size manually, then add the unit tests if it makes sense.
166
+ greaterThan(rhs) {
167
+ return condition({
168
+ stringify: ({ names, values }) => {
169
+ return `${this.substitute({ names, values })} > ${rhs.substitute({ names, values })}`;
170
+ },
171
+ });
172
+ }
173
+ /**
174
+ * An alias for {@link greaterThan}.
175
+ */
176
+ gt = this.greaterThan.bind(this);
177
+ /**
178
+ * Returns a condition that uses the `>=` operator.
179
+ *
180
+ * @param rhs - The right hand side operand.
181
+ *
182
+ * @returns A {@link Condition} that evaluates to true if this operand is greater than or equal to the provided one.
183
+ *
184
+ * @see https://docs.aws.amazon.com/amazondynamodb/latest/developerguide/Expressions.OperatorsAndFunctions.html#Expressions.OperatorsAndFunctions.Comparators
185
+ */
186
+ // TODO: test that both sides can be size manually, then add the unit tests if it makes sense.
187
+ greaterThanOrEquals(rhs) {
188
+ return condition({
189
+ stringify: ({ names, values }) => {
190
+ return `${this.substitute({ names, values })} >= ${rhs.substitute({ names, values })}`;
191
+ },
192
+ });
193
+ }
194
+ /**
195
+ * An alias for {@link greaterThanOrEquals}
196
+ */
197
+ gte = this.greaterThanOrEquals.bind(this);
198
+ /**
199
+ * Returns a condition that uses the `IN` operator.
200
+ *
201
+ * @param operands - The list of operands to check against. This function throws if the list is
202
+ * empty or contains more than 100 operands.
203
+ *
204
+ * @returns A {@link Condition} that evaluates to true if this operand is equal to any of the provided ones.
205
+ *
206
+ * @see https://docs.aws.amazon.com/amazondynamodb/latest/developerguide/Expressions.OperatorsAndFunctions.html#Expressions.OperatorsAndFunctions.Comparators
207
+ */
208
+ // TODO: test that both sides can be size manually, then add the unit tests if it makes sense.
209
+ in(...operands) {
210
+ if (operands.length === 0) {
211
+ throw new Error("the IN operator requires at least one operand.");
212
+ }
213
+ if (operands.length > 100) {
214
+ throw new Error(`up to 100 operands are support for the IN operator, got ${operands.length}`);
215
+ }
216
+ return condition({
217
+ stringify: ({ names, values }) => {
218
+ const operandsString = operands
219
+ .map((operand) => operand.substitute({ names, values }))
220
+ .join(",");
221
+ return `${this.substitute({ names, values })} IN (${operandsString})`;
222
+ },
223
+ });
224
+ }
225
+ /**
226
+ * Returns a condition that uses the `<` operator
227
+ *
228
+ * @param rhs - The right hand side operand.
229
+ *
230
+ * @returns A {@link Condition} that evaluates to true if this operand is lower than the provided one.
231
+ *
232
+ * @see https://docs.aws.amazon.com/amazondynamodb/latest/developerguide/Expressions.OperatorsAndFunctions.html#Expressions.OperatorsAndFunctions.Comparators
233
+ */
234
+ // TODO: test that both sides can be size manually, then add the unit tests if it makes sense.
235
+ lowerThan(rhs) {
236
+ return condition({
237
+ stringify: ({ names, values }) => {
238
+ return `${this.substitute({ names, values })} < ${rhs.substitute({ names, values })}`;
239
+ },
240
+ });
241
+ }
242
+ /**
243
+ * An alias for {@link lowerThan}.
244
+ */
245
+ lt = this.lowerThan.bind(this);
246
+ /**
247
+ * Returns a condition that uses the `<=` operator.
248
+ *
249
+ * @param rhs - The right hand side operand.
250
+ *
251
+ * @returns A {@link Condition} that evaluates to true if this operand is lower than or equal to the provided one.
252
+ *
253
+ * @see https://docs.aws.amazon.com/amazondynamodb/latest/developerguide/Expressions.OperatorsAndFunctions.html#Expressions.OperatorsAndFunctions.Comparators
254
+ */
255
+ //TODO: test that both sides can be size manually, then add the unit tests if it makes sense.
256
+ lowerThanOrEquals(rhs) {
257
+ return condition({
258
+ stringify: ({ names, values }) => {
259
+ return `${this.substitute({ names, values })} <= ${rhs.substitute({ names, values })}`;
260
+ },
261
+ });
262
+ }
263
+ /**
264
+ * An alias for {@link lowerThanOrEquals}
265
+ */
266
+ lte = this.lowerThanOrEquals.bind(this);
267
+ /**
268
+ * Returns a condition that uses the `<>` operator.
269
+ *
270
+ * @param rhs - The right hand side operand.
271
+ *
272
+ * @returns A {@link Condition} that evaluates to true if this operand is not equal to the provided one.
273
+ *
274
+ * @see https://docs.aws.amazon.com/amazondynamodb/latest/developerguide/Expressions.OperatorsAndFunctions.html#Expressions.OperatorsAndFunctions.Comparators
275
+ */
276
+ notEquals(rhs) {
277
+ return condition({
278
+ stringify: ({ names, values }) => {
279
+ return `${this.substitute({ names, values })} <> ${rhs.substitute({ names, values })}`;
280
+ },
281
+ });
282
+ }
283
+ /**
284
+ * An alias for {@link notEquals}.
285
+ */
286
+ ne = this.notEquals.bind(this);
287
+ substitute(params) {
288
+ return this.operand.substitute(params);
289
+ }
290
+ }
291
+ exports.OperandConditionBuilder = OperandConditionBuilder;
292
+ // A specialized class with more capabilities.
293
+ class AttributeConditionBuilder extends OperandConditionBuilder {
294
+ /**
295
+ * @returns A {@link Condition} that evaluates to true if the provided attribute path exists.
296
+ */
297
+ // NOTE: the left hand side of this condition can only be a literal value (tested)
298
+ exists() {
299
+ return condition({
300
+ stringify: ({ names, values }) => {
301
+ return `attribute_exists(${this.substitute({ names, values })})`;
302
+ },
303
+ });
304
+ }
305
+ /**
306
+ * @returns A {@link Condition} that evaluates to true if the provided attribute path does not exist.
307
+ */
308
+ // NOTE: the left hand side of this condition can only be a literal value (tested)
309
+ notExists() {
310
+ return condition({
311
+ stringify: ({ names, values }) => {
312
+ return `attribute_not_exists(${this.substitute({ names, values })})`;
313
+ },
314
+ });
315
+ }
316
+ /**
317
+ * @param type - The type to check against.
318
+ * @returns A {@link Condition} that evaluates to true if there exists an attribute at
319
+ * the provided path of the given type.
320
+ */
321
+ // NOTE: the left hand side of this condition *can be* an attribute value pointing to a valid path.
322
+ // NOTE: the right hand side of this condition *must be* an condition attribute (not a literal).
323
+ isType(type) {
324
+ return condition({
325
+ stringify: ({ names, values }) => {
326
+ return `attribute_type(${this.substitute({ names, values })}, ${type.substitute({ names, values })})`;
327
+ },
328
+ });
329
+ }
330
+ }
331
+ exports.AttributeConditionBuilder = AttributeConditionBuilder;
332
+ function where(operand) {
333
+ if (operand instanceof operands_js_1.AttributeOperand) {
334
+ return new AttributeConditionBuilder(operand);
335
+ }
336
+ return new OperandConditionBuilder(operand);
337
+ }
338
+ // TODO: type this as a "value operand" of type number if possiburu or useful?
339
+ class SizeOperand {
340
+ inner;
341
+ constructor(operand) {
342
+ this.inner = operand;
343
+ }
344
+ substitute(params) {
345
+ return `size(${this.inner.substitute(params)})`;
346
+ }
347
+ }
348
+ exports.SizeOperand = SizeOperand;
349
+ function size(operand) {
350
+ return new SizeOperand(operand);
351
+ }
3
352
  //# sourceMappingURL=condition.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"condition.js","sourceRoot":"","sources":["../../../../src/commands/expressions/condition.ts"],"names":[],"mappings":""}
1
+ {"version":3,"file":"condition.js","sourceRoot":"","sources":["../../../../src/commands/expressions/condition.ts"],"names":[],"mappings":";;;AA2FA,kBAMC;AAqSD,sBAKC;AAkBD,oBAEC;AA5ZD,+CAKuB;AAmBvB,MAAa,SAAS;IACH,WAAW,CAAc;IAE1C,YAAY,MAAuB;QACjC,MAAM,EAAE,SAAS,EAAE,GAAG,MAAM,CAAC;QAC7B,IAAI,CAAC,WAAW,GAAG,SAAS,CAAC;IAC/B,CAAC;IAED,4DAA4D;IAC5D,SAAS,CAAC,MAGT;QACC,OAAO,IAAI,CAAC,WAAW,CAAC,MAAM,CAAC,CAAC;IAClC,CAAC;IAED;;;;;;;;OAQG;IACH,GAAG,CAAC,KAAgB;QAClB,OAAO,SAAS,CAAC;YACf,SAAS,EAAE,CAAC,EAAE,KAAK,EAAE,MAAM,EAAE,EAAE,EAAE;gBAC/B,MAAM,IAAI,GAAG,IAAI,CAAC,SAAS,CAAC,EAAE,KAAK,EAAE,MAAM,EAAE,CAAC,CAAC;gBAC/C,MAAM,KAAK,GAAG,KAAK,CAAC,SAAS,CAAC,EAAE,KAAK,EAAE,MAAM,EAAE,CAAC,CAAC;gBACjD,OAAO,IAAI,IAAI,QAAQ,KAAK,GAAG,CAAC;YAClC,CAAC;SACF,CAAC,CAAC;IACL,CAAC;IAED;;;;;;;;OAQG;IACH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AE,KAAK,EAAE,MAAM,EAAE,EAAE,EAAE;gBAC/B,OAAO,kBAAkB,IAAI,CAAC,UAAU,CAAC,EAAE,KAAK,EAAE,MAAM,EAAE,CAAC,KAAK,IAAI,CAAC,UAAU,CAAC,EAAE,KAAK,EAAE,MAAM,EAAE,CAAC,GAAG,CAAC;YACxG,CAAC;SACF,CAAC,CAAC;IACL,CAAC;CACF;AAvCD,8DAuCC;AAMD,SAAgB,KAAK,CAAC,OAAgB;IACpC,IAAI,OAAO,YAAY,8BAAgB,EAAE,CAAC;QACxC,OAAO,IAAI,yBAAyB,CAAC,OAAO,CAAC,CAAC;IAChD,CAAC;IACD,OAAO,IAAI,uBAAuB,CAAC,OAAO,CAAC,CAAC;AAC9C,CAAC;AAED,8EAA8E;AAC9E,MAAa,WAAW;IACL,KAAK,CAAU;IAEhC,YAAY,OAAgB;QAC1B,IAAI,CAAC,KAAK,GAAG,OAAO,CAAC;IACvB,CAAC;IAED,UAAU,CAAC,MAGV;QACC,OAAO,QAAQ,IAAI,CAAC,KAAK,CAAC,UAAU,CAAC,MAAM,CAAC,GAAG,CAAC;IAClD,CAAC;CACF;AAbD,kCAaC;AAED,SAAgB,IAAI,CAAC,OAAgB;IACnC,OAAO,IAAI,WAAW,CAAC,OAAO,CAAC,CAAC;AAClC,CAAC"}
@@ -1,2 +1,3 @@
1
- export * from "./expression.js";
1
+ export * from "./condition.js";
2
2
  export * from "./key-condition.js";
3
+ export * from "./operands.js";
@@ -14,6 +14,7 @@ var __exportStar = (this && this.__exportStar) || function(m, exports) {
14
14
  for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
15
15
  };
16
16
  Object.defineProperty(exports, "__esModule", { value: true });
17
- __exportStar(require("./expression.js"), exports);
17
+ __exportStar(require("./condition.js"), exports);
18
18
  __exportStar(require("./key-condition.js"), exports);
19
+ __exportStar(require("./operands.js"), exports);
19
20
  //# sourceMappingURL=index.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../../../../src/commands/expressions/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;AAAA,kDAAgC;AAChC,qDAAmC"}
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../../../src/commands/expressions/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;AAAA,iDAA+B;AAC/B,qDAAmC;AACnC,gDAA8B"}
@@ -1,2 +1,2 @@
1
- import type { Expression } from "./expression.js";
2
- export type KeyConditionExpression = Expression;
1
+ import type { Condition } from "./condition.js";
2
+ export type KeyConditionExpression = Condition;
@@ -0,0 +1,28 @@
1
+ import type { AttributePath, AttributeValue } from "../../types.js";
2
+ import type { AttributeNames } from "../attributes/names.js";
3
+ import type { AttributeValues } from "../attributes/values.js";
4
+ export type Operand<T extends AttributeValue = AttributeValue> = AttributeOperand | ValueOperand<T>;
5
+ export interface IOperand {
6
+ substitute(params: {
7
+ names: AttributeNames;
8
+ values: AttributeValues;
9
+ }): string;
10
+ }
11
+ export declare class ValueOperand<T extends AttributeValue> implements IOperand {
12
+ private readonly value;
13
+ constructor(value: T);
14
+ substitute(params: {
15
+ names: AttributeNames;
16
+ values: AttributeValues;
17
+ }): string;
18
+ }
19
+ export declare function value<T extends AttributeValue = AttributeValue>(value: AttributeValue): ValueOperand<T>;
20
+ export declare class AttributeOperand implements IOperand {
21
+ private readonly path;
22
+ constructor(path: AttributePath);
23
+ substitute(params: {
24
+ names: AttributeNames;
25
+ values: AttributeValues;
26
+ }): string;
27
+ }
28
+ export declare function attribute(path: AttributePath): AttributeOperand;
@@ -0,0 +1,34 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.AttributeOperand = exports.ValueOperand = void 0;
4
+ exports.value = value;
5
+ exports.attribute = attribute;
6
+ class ValueOperand {
7
+ value;
8
+ constructor(value) {
9
+ this.value = value;
10
+ }
11
+ substitute(params) {
12
+ const { values } = params;
13
+ return values.reference(this.value).toString();
14
+ }
15
+ }
16
+ exports.ValueOperand = ValueOperand;
17
+ function value(value) {
18
+ return new ValueOperand(value);
19
+ }
20
+ class AttributeOperand {
21
+ path;
22
+ constructor(path) {
23
+ this.path = path;
24
+ }
25
+ substitute(params) {
26
+ const { names } = params;
27
+ return names.substitute(this.path);
28
+ }
29
+ }
30
+ exports.AttributeOperand = AttributeOperand;
31
+ function attribute(path) {
32
+ return new AttributeOperand(path);
33
+ }
34
+ //# sourceMappingURL=operands.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"operands.js","sourceRoot":"","sources":["../../../../src/commands/expressions/operands.ts"],"names":[],"mappings":";;;AAgCA,sBAIC;AAkBD,8BAEC;AAxCD,MAAa,YAAY;IACN,KAAK,CAAI;IAE1B,YAAY,KAAQ;QAClB,IAAI,CAAC,KAAK,GAAG,KAAK,CAAC;IACrB,CAAC;IAED,UAAU,CAAC,MAGV;QACC,MAAM,EAAE,MAAM,EAAE,GAAG,MAAM,CAAC;QAC1B,OAAO,MAAM,CAAC,SAAS,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC,QAAQ,EAAE,CAAC;IACjD,CAAC;CACF;AAdD,oCAcC;AAED,SAAgB,KAAK,CACnB,KAAqB;IAErB,OAAO,IAAI,YAAY,CAAC,KAAK,CAAC,CAAC;AACjC,CAAC;AAED,MAAa,gBAAgB;IACV,IAAI,CAAgB;IAErC,YAAY,IAAmB;QAC7B,IAAI,CAAC,IAAI,GAAG,IAAI,CAAC;IACnB,CAAC;IAED,UAAU,CAAC,MAGV;QACC,MAAM,EAAE,KAAK,EAAE,GAAG,MAAM,CAAC;QACzB,OAAO,KAAK,CAAC,UAAU,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;IACrC,CAAC;CACF;AAdD,4CAcC;AAED,SAAgB,SAAS,CAAC,IAAmB;IAC3C,OAAO,IAAI,gBAAgB,CAAC,IAAI,CAAC,CAAC;AACpC,CAAC"}