@infra-blocks/aws-dynamodb 0.11.0 → 0.12.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/expressions/condition.d.ts +1 -40
- package/lib/cjs/commands/expressions/condition.js +0 -130
- package/lib/cjs/commands/expressions/condition.js.map +1 -1
- package/lib/cjs/commands/expressions/expression.d.ts +47 -1
- package/lib/cjs/commands/expressions/expression.js +140 -0
- package/lib/cjs/commands/expressions/expression.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/key-condition.d.ts +1 -14
- package/lib/cjs/commands/expressions/key-condition.js +0 -24
- package/lib/cjs/commands/expressions/key-condition.js.map +1 -1
- package/lib/esm/commands/expressions/condition.d.ts +1 -40
- package/lib/esm/commands/expressions/condition.js +1 -120
- package/lib/esm/commands/expressions/condition.js.map +1 -1
- package/lib/esm/commands/expressions/expression.d.ts +47 -1
- package/lib/esm/commands/expressions/expression.js +131 -1
- package/lib/esm/commands/expressions/expression.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/key-condition.d.ts +1 -14
- package/lib/esm/commands/expressions/key-condition.js +1 -21
- package/lib/esm/commands/expressions/key-condition.js.map +1 -1
- package/package.json +1 -1
|
@@ -1,41 +1,2 @@
|
|
|
1
|
-
import type { AttributePath, AttributeType, AttributeValue } from "../../types.js";
|
|
2
|
-
import type { AttributeNames } from "../attributes/names.js";
|
|
3
|
-
import type { AttributeValues } from "../attributes/values.js";
|
|
4
1
|
import type { Expression } from "./expression.js";
|
|
5
|
-
export
|
|
6
|
-
private readonly inner;
|
|
7
|
-
constructor(params: {
|
|
8
|
-
inner: Expression;
|
|
9
|
-
});
|
|
10
|
-
stringify(params: {
|
|
11
|
-
attributeNames: AttributeNames;
|
|
12
|
-
attributeValues: AttributeValues;
|
|
13
|
-
}): string;
|
|
14
|
-
}
|
|
15
|
-
/**
|
|
16
|
-
*
|
|
17
|
-
* @see https://docs.aws.amazon.com/amazondynamodb/latest/developerguide/Expressions.OperatorsAndFunctions.html
|
|
18
|
-
*/
|
|
19
|
-
export declare class ConditionExpression implements Expression {
|
|
20
|
-
private readonly inner;
|
|
21
|
-
constructor(params: {
|
|
22
|
-
inner: Expression;
|
|
23
|
-
});
|
|
24
|
-
stringify(params: {
|
|
25
|
-
attributeNames: AttributeNames;
|
|
26
|
-
attributeValues: AttributeValues;
|
|
27
|
-
}): string;
|
|
28
|
-
or(other: ConditionExpression): ConditionExpression;
|
|
29
|
-
and(other: ConditionExpression): ConditionExpression;
|
|
30
|
-
}
|
|
31
|
-
/**
|
|
32
|
-
*
|
|
33
|
-
* @see https://docs.aws.amazon.com/amazondynamodb/latest/developerguide/Expressions.OperatorsAndFunctions.html#Expressions.OperatorsAndFunctions.Functions
|
|
34
|
-
*/
|
|
35
|
-
export declare function attributeNotExists(attribute: AttributePath): ConditionExpression;
|
|
36
|
-
export declare function attributeExists(attribute: AttributePath): ConditionExpression;
|
|
37
|
-
export declare function attributeType(attribute: AttributePath, type: AttributeType): ConditionExpression;
|
|
38
|
-
export declare function beginsWith(attribute: AttributePath, value: string): ConditionExpression;
|
|
39
|
-
export declare function contains(attribute: AttributePath, value: AttributeValue | FunctionExpression): ConditionExpression;
|
|
40
|
-
export declare function size(attribute: AttributePath): FunctionExpression;
|
|
41
|
-
export declare function not(condition: ConditionExpression): ConditionExpression;
|
|
2
|
+
export type ConditionExpression = Expression;
|
|
@@ -1,133 +1,3 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.ConditionExpression = exports.FunctionExpression = void 0;
|
|
4
|
-
exports.attributeNotExists = attributeNotExists;
|
|
5
|
-
exports.attributeExists = attributeExists;
|
|
6
|
-
exports.attributeType = attributeType;
|
|
7
|
-
exports.beginsWith = beginsWith;
|
|
8
|
-
exports.contains = contains;
|
|
9
|
-
exports.size = size;
|
|
10
|
-
exports.not = not;
|
|
11
|
-
class FunctionExpression {
|
|
12
|
-
inner;
|
|
13
|
-
constructor(params) {
|
|
14
|
-
const { inner } = params;
|
|
15
|
-
this.inner = inner;
|
|
16
|
-
}
|
|
17
|
-
stringify(params) {
|
|
18
|
-
return this.inner.stringify(params);
|
|
19
|
-
}
|
|
20
|
-
}
|
|
21
|
-
exports.FunctionExpression = FunctionExpression;
|
|
22
|
-
/**
|
|
23
|
-
*
|
|
24
|
-
* @see https://docs.aws.amazon.com/amazondynamodb/latest/developerguide/Expressions.OperatorsAndFunctions.html
|
|
25
|
-
*/
|
|
26
|
-
class ConditionExpression {
|
|
27
|
-
inner;
|
|
28
|
-
constructor(params) {
|
|
29
|
-
const { inner } = params;
|
|
30
|
-
this.inner = inner;
|
|
31
|
-
}
|
|
32
|
-
stringify(params) {
|
|
33
|
-
return this.inner.stringify(params);
|
|
34
|
-
}
|
|
35
|
-
or(other) {
|
|
36
|
-
return new ConditionExpression({
|
|
37
|
-
inner: {
|
|
38
|
-
stringify: ({ attributeNames, attributeValues }) => {
|
|
39
|
-
const left = this.stringify({ attributeNames, attributeValues });
|
|
40
|
-
const right = other.stringify({ attributeNames, attributeValues });
|
|
41
|
-
return `(${left} OR ${right})`;
|
|
42
|
-
},
|
|
43
|
-
},
|
|
44
|
-
});
|
|
45
|
-
}
|
|
46
|
-
and(other) {
|
|
47
|
-
return new ConditionExpression({
|
|
48
|
-
inner: {
|
|
49
|
-
stringify: ({ attributeNames, attributeValues }) => {
|
|
50
|
-
const left = this.stringify({ attributeNames, attributeValues });
|
|
51
|
-
const right = other.stringify({ attributeNames, attributeValues });
|
|
52
|
-
return `(${left} AND ${right})`;
|
|
53
|
-
},
|
|
54
|
-
},
|
|
55
|
-
});
|
|
56
|
-
}
|
|
57
|
-
}
|
|
58
|
-
exports.ConditionExpression = ConditionExpression;
|
|
59
|
-
/**
|
|
60
|
-
*
|
|
61
|
-
* @see https://docs.aws.amazon.com/amazondynamodb/latest/developerguide/Expressions.OperatorsAndFunctions.html#Expressions.OperatorsAndFunctions.Functions
|
|
62
|
-
*/
|
|
63
|
-
function attributeNotExists(attribute) {
|
|
64
|
-
return new ConditionExpression({
|
|
65
|
-
inner: {
|
|
66
|
-
stringify: ({ attributeNames }) => {
|
|
67
|
-
return `attribute_not_exists(${attributeNames.substitute(attribute)})`;
|
|
68
|
-
},
|
|
69
|
-
},
|
|
70
|
-
});
|
|
71
|
-
}
|
|
72
|
-
function attributeExists(attribute) {
|
|
73
|
-
return new ConditionExpression({
|
|
74
|
-
inner: {
|
|
75
|
-
stringify: ({ attributeNames }) => {
|
|
76
|
-
return `attribute_exists(${attributeNames.substitute(attribute)})`;
|
|
77
|
-
},
|
|
78
|
-
},
|
|
79
|
-
});
|
|
80
|
-
}
|
|
81
|
-
function attributeType(attribute, type) {
|
|
82
|
-
return new ConditionExpression({
|
|
83
|
-
inner: {
|
|
84
|
-
stringify: ({ attributeNames, attributeValues }) => {
|
|
85
|
-
return `attribute_type(${attributeNames.substitute(attribute)}, ${attributeValues.reference(type)})`;
|
|
86
|
-
},
|
|
87
|
-
},
|
|
88
|
-
});
|
|
89
|
-
}
|
|
90
|
-
function beginsWith(attribute, value) {
|
|
91
|
-
return new ConditionExpression({
|
|
92
|
-
inner: {
|
|
93
|
-
stringify: ({ attributeNames, attributeValues }) => {
|
|
94
|
-
return `begins_with(${attributeNames.substitute(attribute)}, ${attributeValues.reference(value)})`;
|
|
95
|
-
},
|
|
96
|
-
},
|
|
97
|
-
});
|
|
98
|
-
}
|
|
99
|
-
function contains(attribute, value) {
|
|
100
|
-
return new ConditionExpression({
|
|
101
|
-
inner: {
|
|
102
|
-
stringify: ({ attributeNames, attributeValues }) => {
|
|
103
|
-
if (value instanceof FunctionExpression) {
|
|
104
|
-
return `contains(${attributeNames.substitute(attribute)}, ${value.stringify({ attributeNames, attributeValues })})`;
|
|
105
|
-
}
|
|
106
|
-
return `contains(${attributeNames.substitute(attribute)}, ${attributeValues.reference(value)})`;
|
|
107
|
-
},
|
|
108
|
-
},
|
|
109
|
-
});
|
|
110
|
-
}
|
|
111
|
-
// This is the only factory that doesn't return a ConditionExpression. This is because the size function
|
|
112
|
-
// does not return a boolean value, rather a number of items. This also means that it can be used in more
|
|
113
|
-
// complex expressions, such as in a comparison: Toto > size(Tata).
|
|
114
|
-
function size(attribute) {
|
|
115
|
-
return new FunctionExpression({
|
|
116
|
-
inner: {
|
|
117
|
-
stringify: ({ attributeNames }) => {
|
|
118
|
-
return `size(${attributeNames.substitute(attribute)})`;
|
|
119
|
-
},
|
|
120
|
-
},
|
|
121
|
-
});
|
|
122
|
-
}
|
|
123
|
-
function not(condition) {
|
|
124
|
-
return new ConditionExpression({
|
|
125
|
-
inner: {
|
|
126
|
-
stringify: ({ attributeNames, attributeValues }) => {
|
|
127
|
-
const inner = condition.stringify({ attributeNames, attributeValues });
|
|
128
|
-
return `NOT (${inner})`;
|
|
129
|
-
},
|
|
130
|
-
},
|
|
131
|
-
});
|
|
132
|
-
}
|
|
133
3
|
//# 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":""}
|
|
@@ -1,8 +1,54 @@
|
|
|
1
|
+
import type { AttributePath, AttributeType, AttributeValue } from "../../types.js";
|
|
1
2
|
import type { AttributeNames } from "../attributes/names.js";
|
|
2
3
|
import type { AttributeValues } from "../attributes/values.js";
|
|
3
|
-
export
|
|
4
|
+
export type Stringifier = (params: {
|
|
5
|
+
attributeNames: AttributeNames;
|
|
6
|
+
attributeValues: AttributeValues;
|
|
7
|
+
}) => string;
|
|
8
|
+
export interface ExpressionParams {
|
|
9
|
+
stringify: Stringifier;
|
|
10
|
+
}
|
|
11
|
+
export declare class Expression {
|
|
12
|
+
private readonly stringifier;
|
|
13
|
+
constructor(params: ExpressionParams);
|
|
14
|
+
and(rhs: Expression): Expression;
|
|
15
|
+
or(rhs: Expression): Expression;
|
|
4
16
|
stringify(params: {
|
|
5
17
|
attributeNames: AttributeNames;
|
|
6
18
|
attributeValues: AttributeValues;
|
|
7
19
|
}): string;
|
|
8
20
|
}
|
|
21
|
+
export declare function expression(params: ExpressionParams): Expression;
|
|
22
|
+
export declare function not(expression: Expression): Expression;
|
|
23
|
+
export declare abstract class Operand {
|
|
24
|
+
protected constructor();
|
|
25
|
+
beginsWith(rhs: Operand): Expression;
|
|
26
|
+
contains(rhs: Operand): Expression;
|
|
27
|
+
equals(rhs: Operand): Expression;
|
|
28
|
+
size(): Operand;
|
|
29
|
+
abstract register(params: {
|
|
30
|
+
attributeNames: AttributeNames;
|
|
31
|
+
attributeValues: AttributeValues;
|
|
32
|
+
}): string;
|
|
33
|
+
}
|
|
34
|
+
export declare class ExpressionAttribute extends Operand {
|
|
35
|
+
private readonly path;
|
|
36
|
+
constructor(path: AttributePath);
|
|
37
|
+
exists(): Expression;
|
|
38
|
+
notExists(): Expression;
|
|
39
|
+
type(type: AttributeType): Expression;
|
|
40
|
+
register(params: {
|
|
41
|
+
attributeNames: AttributeNames;
|
|
42
|
+
attributeValues: AttributeValues;
|
|
43
|
+
}): string;
|
|
44
|
+
}
|
|
45
|
+
export declare function attribute(path: AttributePath): ExpressionAttribute;
|
|
46
|
+
export declare class ExpressionValue extends Operand {
|
|
47
|
+
private readonly value;
|
|
48
|
+
constructor(value: AttributeValue);
|
|
49
|
+
register(params: {
|
|
50
|
+
attributeNames: AttributeNames;
|
|
51
|
+
attributeValues: AttributeValues;
|
|
52
|
+
}): string;
|
|
53
|
+
}
|
|
54
|
+
export declare function value(value: AttributeValue): ExpressionValue;
|
|
@@ -1,3 +1,143 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.ExpressionValue = exports.ExpressionAttribute = exports.Operand = exports.Expression = void 0;
|
|
4
|
+
exports.expression = expression;
|
|
5
|
+
exports.not = not;
|
|
6
|
+
exports.attribute = attribute;
|
|
7
|
+
exports.value = value;
|
|
8
|
+
// TODO: once we have a working structure, retype everything so that it's type safe for condition expression vs key condition expression vs update expression.
|
|
9
|
+
class Expression {
|
|
10
|
+
stringifier;
|
|
11
|
+
constructor(params) {
|
|
12
|
+
const { stringify } = params;
|
|
13
|
+
this.stringifier = stringify;
|
|
14
|
+
}
|
|
15
|
+
and(rhs) {
|
|
16
|
+
return new Expression({
|
|
17
|
+
stringify: ({ attributeNames, attributeValues }) => {
|
|
18
|
+
const left = this.stringify({ attributeNames, attributeValues });
|
|
19
|
+
const right = rhs.stringify({ attributeNames, attributeValues });
|
|
20
|
+
return `(${left} AND ${right})`;
|
|
21
|
+
},
|
|
22
|
+
});
|
|
23
|
+
}
|
|
24
|
+
or(rhs) {
|
|
25
|
+
return new Expression({
|
|
26
|
+
stringify: ({ attributeNames, attributeValues }) => {
|
|
27
|
+
const left = this.stringify({ attributeNames, attributeValues });
|
|
28
|
+
const right = rhs.stringify({ attributeNames, attributeValues });
|
|
29
|
+
return `(${left} OR ${right})`;
|
|
30
|
+
},
|
|
31
|
+
});
|
|
32
|
+
}
|
|
33
|
+
stringify(params) {
|
|
34
|
+
return this.stringifier(params);
|
|
35
|
+
}
|
|
36
|
+
}
|
|
37
|
+
exports.Expression = Expression;
|
|
38
|
+
function expression(params) {
|
|
39
|
+
return new Expression(params);
|
|
40
|
+
}
|
|
41
|
+
function not(expression) {
|
|
42
|
+
return new Expression({
|
|
43
|
+
stringify: ({ attributeNames, attributeValues }) => {
|
|
44
|
+
return `NOT (${expression.stringify({ attributeNames, attributeValues })})`;
|
|
45
|
+
},
|
|
46
|
+
});
|
|
47
|
+
}
|
|
48
|
+
class Operand {
|
|
49
|
+
constructor() { }
|
|
50
|
+
// NOTE: both sides of this expression can either be attribute names or attribute values.
|
|
51
|
+
beginsWith(rhs) {
|
|
52
|
+
return expression({
|
|
53
|
+
stringify: ({ attributeNames, attributeValues }) => {
|
|
54
|
+
return `begins_with(${this.register({ attributeNames, attributeValues })}, ${rhs.register({ attributeNames, attributeValues })})`;
|
|
55
|
+
},
|
|
56
|
+
});
|
|
57
|
+
}
|
|
58
|
+
// NOTE: both sides of this expression can either be attribute names or attribute values.
|
|
59
|
+
contains(rhs) {
|
|
60
|
+
return expression({
|
|
61
|
+
stringify: ({ attributeNames, attributeValues }) => {
|
|
62
|
+
return `contains(${this.register({ attributeNames, attributeValues })}, ${rhs.register({ attributeNames, attributeValues })})`;
|
|
63
|
+
},
|
|
64
|
+
});
|
|
65
|
+
}
|
|
66
|
+
equals(rhs) {
|
|
67
|
+
return expression({
|
|
68
|
+
stringify: ({ attributeNames, attributeValues }) => {
|
|
69
|
+
return `${this.register({ attributeNames, attributeValues })} = ${rhs.register({ attributeNames, attributeValues })}`;
|
|
70
|
+
},
|
|
71
|
+
});
|
|
72
|
+
}
|
|
73
|
+
size() {
|
|
74
|
+
return new SizeOperand(this);
|
|
75
|
+
}
|
|
76
|
+
}
|
|
77
|
+
exports.Operand = Operand;
|
|
78
|
+
class ExpressionAttribute extends Operand {
|
|
79
|
+
path;
|
|
80
|
+
constructor(path) {
|
|
81
|
+
super();
|
|
82
|
+
this.path = path;
|
|
83
|
+
}
|
|
84
|
+
// NOTE: the left hand side of this expression can only be a literal value (tested)
|
|
85
|
+
exists() {
|
|
86
|
+
return expression({
|
|
87
|
+
stringify: ({ attributeNames, attributeValues }) => {
|
|
88
|
+
return `attribute_exists(${this.register({ attributeNames, attributeValues })})`;
|
|
89
|
+
},
|
|
90
|
+
});
|
|
91
|
+
}
|
|
92
|
+
// NOTE: the left hand side of this expression can only be a literal value (tested)
|
|
93
|
+
notExists() {
|
|
94
|
+
return expression({
|
|
95
|
+
stringify: ({ attributeNames, attributeValues }) => {
|
|
96
|
+
return `attribute_not_exists(${this.register({ attributeNames, attributeValues })})`;
|
|
97
|
+
},
|
|
98
|
+
});
|
|
99
|
+
}
|
|
100
|
+
// NOTE: the left hand side of this expression *can be* an attribute value pointing to a valid path.
|
|
101
|
+
// NOTE: the right hand side of this expression *must be* an expression attribute (not a literal).
|
|
102
|
+
type(type) {
|
|
103
|
+
return expression({
|
|
104
|
+
stringify: ({ attributeNames, attributeValues }) => {
|
|
105
|
+
return `attribute_type(${this.register({ attributeNames, attributeValues })}, ${attributeValues.reference(type)})`;
|
|
106
|
+
},
|
|
107
|
+
});
|
|
108
|
+
}
|
|
109
|
+
register(params) {
|
|
110
|
+
const { attributeNames } = params;
|
|
111
|
+
return attributeNames.substitute(this.path);
|
|
112
|
+
}
|
|
113
|
+
}
|
|
114
|
+
exports.ExpressionAttribute = ExpressionAttribute;
|
|
115
|
+
function attribute(path) {
|
|
116
|
+
return new ExpressionAttribute(path);
|
|
117
|
+
}
|
|
118
|
+
class ExpressionValue extends Operand {
|
|
119
|
+
value;
|
|
120
|
+
constructor(value) {
|
|
121
|
+
super();
|
|
122
|
+
this.value = value;
|
|
123
|
+
}
|
|
124
|
+
register(params) {
|
|
125
|
+
const { attributeValues } = params;
|
|
126
|
+
return attributeValues.reference(this.value).toString();
|
|
127
|
+
}
|
|
128
|
+
}
|
|
129
|
+
exports.ExpressionValue = ExpressionValue;
|
|
130
|
+
function value(value) {
|
|
131
|
+
return new ExpressionValue(value);
|
|
132
|
+
}
|
|
133
|
+
class SizeOperand extends Operand {
|
|
134
|
+
inner;
|
|
135
|
+
constructor(operand) {
|
|
136
|
+
super();
|
|
137
|
+
this.inner = operand;
|
|
138
|
+
}
|
|
139
|
+
register(params) {
|
|
140
|
+
return `size(${this.inner.register(params)})`;
|
|
141
|
+
}
|
|
142
|
+
}
|
|
3
143
|
//# sourceMappingURL=expression.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"expression.js","sourceRoot":"","sources":["../../../../src/commands/expressions/expression.ts"],"names":[],"mappings":""}
|
|
1
|
+
{"version":3,"file":"expression.js","sourceRoot":"","sources":["../../../../src/commands/expressions/expression.ts"],"names":[],"mappings":";;;AA+DA,gCAEC;AAED,kBAMC;AAsFD,8BAEC;AAmBD,sBAEC;AA5JD,8JAA8J;AAC9J,MAAa,UAAU;IACJ,WAAW,CAAc;IAE1C,YAAY,MAAwB;QAClC,MAAM,EAAE,SAAS,EAAE,GAAG,MAAM,CAAC;QAC7B,IAAI,CAAC,WAAW,GAAG,SAAS,CAAC;IAC/B,CAAC;IAED,GAAG,CAAC,GAAe;QACjB,OAAO,IAAI,UAAU,CAAC;YACpB,SAAS,EAAE,CAAC,EAAE,cAAc,EAAE,eAAe,EAAE,EAAE,EAAE;gBACjD,MAAM,IAAI,GAAG,IAAI,CAAC,SAAS,CAAC,EAAE,cAAc,EAAE,eAAe,EAAE,CAAC,CAAC;gBACjE,MAAM,KAAK,GAAG,GAAG,CAAC,SAAS,CAAC,EAAE,cAAc,EAAE,eAAe,EAAE,CAAC,CAAC;gBACjE,OAAO,IAAI,IAAI,QAAQ,KAAK,GAAG,CAAC;YAClC,CAAC;SACF,CAAC,CAAC;IACL,CAAC;IAED,EAAE,CAAC,GAAe;QAChB,OAAO,IAAI,UAAU,CAAC;YACpB,SAAS,EAAE,CAAC,EAAE,cAAc,EAAE,eAAe,EAAE,EAAE,EAAE;gBACjD,MAAM,IAAI,GAAG,IAAI,CAAC,SAAS,CAAC,EAAE,cAAc,EAAE,eAAe,EAAE,CAAC,CAAC;gBACjE,MAAM,KAAK,GAAG,GAAG,CAAC,SAAS,CAAC,EAAE,cAAc,EAAE,eAAe,EAAE,CAAC,CAAC;gBACjE,OAAO,IAAI,IAAI,OAAO,KAAK,GAAG,CAAC;YACjC,CAAC;SACF,CAAC,CAAC;IACL,CAAC;IAED,SAAS,CAAC,MAGT;QACC,OA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rH,CAAC;SACF,CAAC,CAAC;IACL,CAAC;IAED,QAAQ,CAAC,MAGR;QACC,MAAM,EAAE,cAAc,EAAE,GAAG,MAAM,CAAC;QAClC,OAAO,cAAc,CAAC,UAAU,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;IAC9C,CAAC;CACF;AA3CD,kDA2CC;AAED,SAAgB,SAAS,CAAC,IAAmB;IAC3C,OAAO,IAAI,mBAAmB,CAAC,IAAI,CAAC,CAAC;AACvC,CAAC;AAED,MAAa,eAAgB,SAAQ,OAAO;IACzB,KAAK,CAAiB;IAEvC,YAAY,KAAqB;QAC/B,KAAK,EAAE,CAAC;QACR,IAAI,CAAC,KAAK,GAAG,KAAK,CAAC;IACrB,CAAC;IAED,QAAQ,CAAC,MAGR;QACC,MAAM,EAAE,eAAe,EAAE,GAAG,MAAM,CAAC;QACnC,OAAO,eAAe,CAAC,SAAS,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC,QAAQ,EAAE,CAAC;IAC1D,CAAC;CACF;AAfD,0CAeC;AAED,SAAgB,KAAK,CAAC,KAAqB;IACzC,OAAO,IAAI,eAAe,CAAC,KAAK,CAAC,CAAC;AACpC,CAAC;AAED,MAAM,WAAY,SAAQ,OAAO;IACd,KAAK,CAAU;IAEhC,YAAY,OAAgB;QAC1B,KAAK,EAAE,CAAC;QACR,IAAI,CAAC,KAAK,GAAG,OAAO,CAAC;IACvB,CAAC;IAED,QAAQ,CAAC,MAGR;QACC,OAAO,QAAQ,IAAI,CAAC,KAAK,CAAC,QAAQ,CAAC,MAAM,CAAC,GAAG,CAAC;IAChD,CAAC;CACF"}
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
export * from "./
|
|
1
|
+
export * from "./expression.js";
|
|
2
2
|
export * from "./key-condition.js";
|
|
@@ -14,6 +14,6 @@ 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("./
|
|
17
|
+
__exportStar(require("./expression.js"), exports);
|
|
18
18
|
__exportStar(require("./key-condition.js"), exports);
|
|
19
19
|
//# sourceMappingURL=index.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../../src/commands/expressions/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;AAAA,
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../../src/commands/expressions/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;AAAA,kDAAgC;AAChC,qDAAmC"}
|
|
@@ -1,15 +1,2 @@
|
|
|
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
1
|
import type { Expression } from "./expression.js";
|
|
5
|
-
export
|
|
6
|
-
private readonly inner;
|
|
7
|
-
constructor(params: {
|
|
8
|
-
inner: Expression;
|
|
9
|
-
});
|
|
10
|
-
stringify(params: {
|
|
11
|
-
attributeNames: AttributeNames;
|
|
12
|
-
attributeValues: AttributeValues;
|
|
13
|
-
}): string;
|
|
14
|
-
}
|
|
15
|
-
export declare function equals(name: AttributePath, value: AttributeValue): KeyConditionExpression;
|
|
2
|
+
export type KeyConditionExpression = Expression;
|
|
@@ -1,27 +1,3 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.KeyConditionExpression = void 0;
|
|
4
|
-
exports.equals = equals;
|
|
5
|
-
class KeyConditionExpression {
|
|
6
|
-
inner;
|
|
7
|
-
constructor(params) {
|
|
8
|
-
const { inner } = params;
|
|
9
|
-
this.inner = inner;
|
|
10
|
-
}
|
|
11
|
-
stringify(params) {
|
|
12
|
-
return this.inner.stringify(params);
|
|
13
|
-
}
|
|
14
|
-
}
|
|
15
|
-
exports.KeyConditionExpression = KeyConditionExpression;
|
|
16
|
-
function equals(name, value) {
|
|
17
|
-
return new KeyConditionExpression({
|
|
18
|
-
inner: {
|
|
19
|
-
stringify: ({ attributeNames, attributeValues }) => {
|
|
20
|
-
const substitute = attributeNames.substitute(name);
|
|
21
|
-
const reference = attributeValues.reference(value);
|
|
22
|
-
return `${substitute} = ${reference}`;
|
|
23
|
-
},
|
|
24
|
-
},
|
|
25
|
-
});
|
|
26
|
-
}
|
|
27
3
|
//# sourceMappingURL=key-condition.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"key-condition.js","sourceRoot":"","sources":["../../../../src/commands/expressions/key-condition.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"key-condition.js","sourceRoot":"","sources":["../../../../src/commands/expressions/key-condition.ts"],"names":[],"mappings":""}
|
|
@@ -1,41 +1,2 @@
|
|
|
1
|
-
import type { AttributePath, AttributeType, AttributeValue } from "../../types.js";
|
|
2
|
-
import type { AttributeNames } from "../attributes/names.js";
|
|
3
|
-
import type { AttributeValues } from "../attributes/values.js";
|
|
4
1
|
import type { Expression } from "./expression.js";
|
|
5
|
-
export
|
|
6
|
-
private readonly inner;
|
|
7
|
-
constructor(params: {
|
|
8
|
-
inner: Expression;
|
|
9
|
-
});
|
|
10
|
-
stringify(params: {
|
|
11
|
-
attributeNames: AttributeNames;
|
|
12
|
-
attributeValues: AttributeValues;
|
|
13
|
-
}): string;
|
|
14
|
-
}
|
|
15
|
-
/**
|
|
16
|
-
*
|
|
17
|
-
* @see https://docs.aws.amazon.com/amazondynamodb/latest/developerguide/Expressions.OperatorsAndFunctions.html
|
|
18
|
-
*/
|
|
19
|
-
export declare class ConditionExpression implements Expression {
|
|
20
|
-
private readonly inner;
|
|
21
|
-
constructor(params: {
|
|
22
|
-
inner: Expression;
|
|
23
|
-
});
|
|
24
|
-
stringify(params: {
|
|
25
|
-
attributeNames: AttributeNames;
|
|
26
|
-
attributeValues: AttributeValues;
|
|
27
|
-
}): string;
|
|
28
|
-
or(other: ConditionExpression): ConditionExpression;
|
|
29
|
-
and(other: ConditionExpression): ConditionExpression;
|
|
30
|
-
}
|
|
31
|
-
/**
|
|
32
|
-
*
|
|
33
|
-
* @see https://docs.aws.amazon.com/amazondynamodb/latest/developerguide/Expressions.OperatorsAndFunctions.html#Expressions.OperatorsAndFunctions.Functions
|
|
34
|
-
*/
|
|
35
|
-
export declare function attributeNotExists(attribute: AttributePath): ConditionExpression;
|
|
36
|
-
export declare function attributeExists(attribute: AttributePath): ConditionExpression;
|
|
37
|
-
export declare function attributeType(attribute: AttributePath, type: AttributeType): ConditionExpression;
|
|
38
|
-
export declare function beginsWith(attribute: AttributePath, value: string): ConditionExpression;
|
|
39
|
-
export declare function contains(attribute: AttributePath, value: AttributeValue | FunctionExpression): ConditionExpression;
|
|
40
|
-
export declare function size(attribute: AttributePath): FunctionExpression;
|
|
41
|
-
export declare function not(condition: ConditionExpression): ConditionExpression;
|
|
2
|
+
export type ConditionExpression = Expression;
|
|
@@ -1,121 +1,2 @@
|
|
|
1
|
-
export
|
|
2
|
-
inner;
|
|
3
|
-
constructor(params) {
|
|
4
|
-
const { inner } = params;
|
|
5
|
-
this.inner = inner;
|
|
6
|
-
}
|
|
7
|
-
stringify(params) {
|
|
8
|
-
return this.inner.stringify(params);
|
|
9
|
-
}
|
|
10
|
-
}
|
|
11
|
-
/**
|
|
12
|
-
*
|
|
13
|
-
* @see https://docs.aws.amazon.com/amazondynamodb/latest/developerguide/Expressions.OperatorsAndFunctions.html
|
|
14
|
-
*/
|
|
15
|
-
export class ConditionExpression {
|
|
16
|
-
inner;
|
|
17
|
-
constructor(params) {
|
|
18
|
-
const { inner } = params;
|
|
19
|
-
this.inner = inner;
|
|
20
|
-
}
|
|
21
|
-
stringify(params) {
|
|
22
|
-
return this.inner.stringify(params);
|
|
23
|
-
}
|
|
24
|
-
or(other) {
|
|
25
|
-
return new ConditionExpression({
|
|
26
|
-
inner: {
|
|
27
|
-
stringify: ({ attributeNames, attributeValues }) => {
|
|
28
|
-
const left = this.stringify({ attributeNames, attributeValues });
|
|
29
|
-
const right = other.stringify({ attributeNames, attributeValues });
|
|
30
|
-
return `(${left} OR ${right})`;
|
|
31
|
-
},
|
|
32
|
-
},
|
|
33
|
-
});
|
|
34
|
-
}
|
|
35
|
-
and(other) {
|
|
36
|
-
return new ConditionExpression({
|
|
37
|
-
inner: {
|
|
38
|
-
stringify: ({ attributeNames, attributeValues }) => {
|
|
39
|
-
const left = this.stringify({ attributeNames, attributeValues });
|
|
40
|
-
const right = other.stringify({ attributeNames, attributeValues });
|
|
41
|
-
return `(${left} AND ${right})`;
|
|
42
|
-
},
|
|
43
|
-
},
|
|
44
|
-
});
|
|
45
|
-
}
|
|
46
|
-
}
|
|
47
|
-
/**
|
|
48
|
-
*
|
|
49
|
-
* @see https://docs.aws.amazon.com/amazondynamodb/latest/developerguide/Expressions.OperatorsAndFunctions.html#Expressions.OperatorsAndFunctions.Functions
|
|
50
|
-
*/
|
|
51
|
-
export function attributeNotExists(attribute) {
|
|
52
|
-
return new ConditionExpression({
|
|
53
|
-
inner: {
|
|
54
|
-
stringify: ({ attributeNames }) => {
|
|
55
|
-
return `attribute_not_exists(${attributeNames.substitute(attribute)})`;
|
|
56
|
-
},
|
|
57
|
-
},
|
|
58
|
-
});
|
|
59
|
-
}
|
|
60
|
-
export function attributeExists(attribute) {
|
|
61
|
-
return new ConditionExpression({
|
|
62
|
-
inner: {
|
|
63
|
-
stringify: ({ attributeNames }) => {
|
|
64
|
-
return `attribute_exists(${attributeNames.substitute(attribute)})`;
|
|
65
|
-
},
|
|
66
|
-
},
|
|
67
|
-
});
|
|
68
|
-
}
|
|
69
|
-
export function attributeType(attribute, type) {
|
|
70
|
-
return new ConditionExpression({
|
|
71
|
-
inner: {
|
|
72
|
-
stringify: ({ attributeNames, attributeValues }) => {
|
|
73
|
-
return `attribute_type(${attributeNames.substitute(attribute)}, ${attributeValues.reference(type)})`;
|
|
74
|
-
},
|
|
75
|
-
},
|
|
76
|
-
});
|
|
77
|
-
}
|
|
78
|
-
export function beginsWith(attribute, value) {
|
|
79
|
-
return new ConditionExpression({
|
|
80
|
-
inner: {
|
|
81
|
-
stringify: ({ attributeNames, attributeValues }) => {
|
|
82
|
-
return `begins_with(${attributeNames.substitute(attribute)}, ${attributeValues.reference(value)})`;
|
|
83
|
-
},
|
|
84
|
-
},
|
|
85
|
-
});
|
|
86
|
-
}
|
|
87
|
-
export function contains(attribute, value) {
|
|
88
|
-
return new ConditionExpression({
|
|
89
|
-
inner: {
|
|
90
|
-
stringify: ({ attributeNames, attributeValues }) => {
|
|
91
|
-
if (value instanceof FunctionExpression) {
|
|
92
|
-
return `contains(${attributeNames.substitute(attribute)}, ${value.stringify({ attributeNames, attributeValues })})`;
|
|
93
|
-
}
|
|
94
|
-
return `contains(${attributeNames.substitute(attribute)}, ${attributeValues.reference(value)})`;
|
|
95
|
-
},
|
|
96
|
-
},
|
|
97
|
-
});
|
|
98
|
-
}
|
|
99
|
-
// This is the only factory that doesn't return a ConditionExpression. This is because the size function
|
|
100
|
-
// does not return a boolean value, rather a number of items. This also means that it can be used in more
|
|
101
|
-
// complex expressions, such as in a comparison: Toto > size(Tata).
|
|
102
|
-
export function size(attribute) {
|
|
103
|
-
return new FunctionExpression({
|
|
104
|
-
inner: {
|
|
105
|
-
stringify: ({ attributeNames }) => {
|
|
106
|
-
return `size(${attributeNames.substitute(attribute)})`;
|
|
107
|
-
},
|
|
108
|
-
},
|
|
109
|
-
});
|
|
110
|
-
}
|
|
111
|
-
export function not(condition) {
|
|
112
|
-
return new ConditionExpression({
|
|
113
|
-
inner: {
|
|
114
|
-
stringify: ({ attributeNames, attributeValues }) => {
|
|
115
|
-
const inner = condition.stringify({ attributeNames, attributeValues });
|
|
116
|
-
return `NOT (${inner})`;
|
|
117
|
-
},
|
|
118
|
-
},
|
|
119
|
-
});
|
|
120
|
-
}
|
|
1
|
+
export {};
|
|
121
2
|
//# 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":""}
|
|
@@ -1,8 +1,54 @@
|
|
|
1
|
+
import type { AttributePath, AttributeType, AttributeValue } from "../../types.js";
|
|
1
2
|
import type { AttributeNames } from "../attributes/names.js";
|
|
2
3
|
import type { AttributeValues } from "../attributes/values.js";
|
|
3
|
-
export
|
|
4
|
+
export type Stringifier = (params: {
|
|
5
|
+
attributeNames: AttributeNames;
|
|
6
|
+
attributeValues: AttributeValues;
|
|
7
|
+
}) => string;
|
|
8
|
+
export interface ExpressionParams {
|
|
9
|
+
stringify: Stringifier;
|
|
10
|
+
}
|
|
11
|
+
export declare class Expression {
|
|
12
|
+
private readonly stringifier;
|
|
13
|
+
constructor(params: ExpressionParams);
|
|
14
|
+
and(rhs: Expression): Expression;
|
|
15
|
+
or(rhs: Expression): Expression;
|
|
4
16
|
stringify(params: {
|
|
5
17
|
attributeNames: AttributeNames;
|
|
6
18
|
attributeValues: AttributeValues;
|
|
7
19
|
}): string;
|
|
8
20
|
}
|
|
21
|
+
export declare function expression(params: ExpressionParams): Expression;
|
|
22
|
+
export declare function not(expression: Expression): Expression;
|
|
23
|
+
export declare abstract class Operand {
|
|
24
|
+
protected constructor();
|
|
25
|
+
beginsWith(rhs: Operand): Expression;
|
|
26
|
+
contains(rhs: Operand): Expression;
|
|
27
|
+
equals(rhs: Operand): Expression;
|
|
28
|
+
size(): Operand;
|
|
29
|
+
abstract register(params: {
|
|
30
|
+
attributeNames: AttributeNames;
|
|
31
|
+
attributeValues: AttributeValues;
|
|
32
|
+
}): string;
|
|
33
|
+
}
|
|
34
|
+
export declare class ExpressionAttribute extends Operand {
|
|
35
|
+
private readonly path;
|
|
36
|
+
constructor(path: AttributePath);
|
|
37
|
+
exists(): Expression;
|
|
38
|
+
notExists(): Expression;
|
|
39
|
+
type(type: AttributeType): Expression;
|
|
40
|
+
register(params: {
|
|
41
|
+
attributeNames: AttributeNames;
|
|
42
|
+
attributeValues: AttributeValues;
|
|
43
|
+
}): string;
|
|
44
|
+
}
|
|
45
|
+
export declare function attribute(path: AttributePath): ExpressionAttribute;
|
|
46
|
+
export declare class ExpressionValue extends Operand {
|
|
47
|
+
private readonly value;
|
|
48
|
+
constructor(value: AttributeValue);
|
|
49
|
+
register(params: {
|
|
50
|
+
attributeNames: AttributeNames;
|
|
51
|
+
attributeValues: AttributeValues;
|
|
52
|
+
}): string;
|
|
53
|
+
}
|
|
54
|
+
export declare function value(value: AttributeValue): ExpressionValue;
|
|
@@ -1,2 +1,132 @@
|
|
|
1
|
-
|
|
1
|
+
// TODO: once we have a working structure, retype everything so that it's type safe for condition expression vs key condition expression vs update expression.
|
|
2
|
+
export class Expression {
|
|
3
|
+
stringifier;
|
|
4
|
+
constructor(params) {
|
|
5
|
+
const { stringify } = params;
|
|
6
|
+
this.stringifier = stringify;
|
|
7
|
+
}
|
|
8
|
+
and(rhs) {
|
|
9
|
+
return new Expression({
|
|
10
|
+
stringify: ({ attributeNames, attributeValues }) => {
|
|
11
|
+
const left = this.stringify({ attributeNames, attributeValues });
|
|
12
|
+
const right = rhs.stringify({ attributeNames, attributeValues });
|
|
13
|
+
return `(${left} AND ${right})`;
|
|
14
|
+
},
|
|
15
|
+
});
|
|
16
|
+
}
|
|
17
|
+
or(rhs) {
|
|
18
|
+
return new Expression({
|
|
19
|
+
stringify: ({ attributeNames, attributeValues }) => {
|
|
20
|
+
const left = this.stringify({ attributeNames, attributeValues });
|
|
21
|
+
const right = rhs.stringify({ attributeNames, attributeValues });
|
|
22
|
+
return `(${left} OR ${right})`;
|
|
23
|
+
},
|
|
24
|
+
});
|
|
25
|
+
}
|
|
26
|
+
stringify(params) {
|
|
27
|
+
return this.stringifier(params);
|
|
28
|
+
}
|
|
29
|
+
}
|
|
30
|
+
export function expression(params) {
|
|
31
|
+
return new Expression(params);
|
|
32
|
+
}
|
|
33
|
+
export function not(expression) {
|
|
34
|
+
return new Expression({
|
|
35
|
+
stringify: ({ attributeNames, attributeValues }) => {
|
|
36
|
+
return `NOT (${expression.stringify({ attributeNames, attributeValues })})`;
|
|
37
|
+
},
|
|
38
|
+
});
|
|
39
|
+
}
|
|
40
|
+
export class Operand {
|
|
41
|
+
constructor() { }
|
|
42
|
+
// NOTE: both sides of this expression can either be attribute names or attribute values.
|
|
43
|
+
beginsWith(rhs) {
|
|
44
|
+
return expression({
|
|
45
|
+
stringify: ({ attributeNames, attributeValues }) => {
|
|
46
|
+
return `begins_with(${this.register({ attributeNames, attributeValues })}, ${rhs.register({ attributeNames, attributeValues })})`;
|
|
47
|
+
},
|
|
48
|
+
});
|
|
49
|
+
}
|
|
50
|
+
// NOTE: both sides of this expression can either be attribute names or attribute values.
|
|
51
|
+
contains(rhs) {
|
|
52
|
+
return expression({
|
|
53
|
+
stringify: ({ attributeNames, attributeValues }) => {
|
|
54
|
+
return `contains(${this.register({ attributeNames, attributeValues })}, ${rhs.register({ attributeNames, attributeValues })})`;
|
|
55
|
+
},
|
|
56
|
+
});
|
|
57
|
+
}
|
|
58
|
+
equals(rhs) {
|
|
59
|
+
return expression({
|
|
60
|
+
stringify: ({ attributeNames, attributeValues }) => {
|
|
61
|
+
return `${this.register({ attributeNames, attributeValues })} = ${rhs.register({ attributeNames, attributeValues })}`;
|
|
62
|
+
},
|
|
63
|
+
});
|
|
64
|
+
}
|
|
65
|
+
size() {
|
|
66
|
+
return new SizeOperand(this);
|
|
67
|
+
}
|
|
68
|
+
}
|
|
69
|
+
export class ExpressionAttribute extends Operand {
|
|
70
|
+
path;
|
|
71
|
+
constructor(path) {
|
|
72
|
+
super();
|
|
73
|
+
this.path = path;
|
|
74
|
+
}
|
|
75
|
+
// NOTE: the left hand side of this expression can only be a literal value (tested)
|
|
76
|
+
exists() {
|
|
77
|
+
return expression({
|
|
78
|
+
stringify: ({ attributeNames, attributeValues }) => {
|
|
79
|
+
return `attribute_exists(${this.register({ attributeNames, attributeValues })})`;
|
|
80
|
+
},
|
|
81
|
+
});
|
|
82
|
+
}
|
|
83
|
+
// NOTE: the left hand side of this expression can only be a literal value (tested)
|
|
84
|
+
notExists() {
|
|
85
|
+
return expression({
|
|
86
|
+
stringify: ({ attributeNames, attributeValues }) => {
|
|
87
|
+
return `attribute_not_exists(${this.register({ attributeNames, attributeValues })})`;
|
|
88
|
+
},
|
|
89
|
+
});
|
|
90
|
+
}
|
|
91
|
+
// NOTE: the left hand side of this expression *can be* an attribute value pointing to a valid path.
|
|
92
|
+
// NOTE: the right hand side of this expression *must be* an expression attribute (not a literal).
|
|
93
|
+
type(type) {
|
|
94
|
+
return expression({
|
|
95
|
+
stringify: ({ attributeNames, attributeValues }) => {
|
|
96
|
+
return `attribute_type(${this.register({ attributeNames, attributeValues })}, ${attributeValues.reference(type)})`;
|
|
97
|
+
},
|
|
98
|
+
});
|
|
99
|
+
}
|
|
100
|
+
register(params) {
|
|
101
|
+
const { attributeNames } = params;
|
|
102
|
+
return attributeNames.substitute(this.path);
|
|
103
|
+
}
|
|
104
|
+
}
|
|
105
|
+
export function attribute(path) {
|
|
106
|
+
return new ExpressionAttribute(path);
|
|
107
|
+
}
|
|
108
|
+
export class ExpressionValue extends Operand {
|
|
109
|
+
value;
|
|
110
|
+
constructor(value) {
|
|
111
|
+
super();
|
|
112
|
+
this.value = value;
|
|
113
|
+
}
|
|
114
|
+
register(params) {
|
|
115
|
+
const { attributeValues } = params;
|
|
116
|
+
return attributeValues.reference(this.value).toString();
|
|
117
|
+
}
|
|
118
|
+
}
|
|
119
|
+
export function value(value) {
|
|
120
|
+
return new ExpressionValue(value);
|
|
121
|
+
}
|
|
122
|
+
class SizeOperand extends Operand {
|
|
123
|
+
inner;
|
|
124
|
+
constructor(operand) {
|
|
125
|
+
super();
|
|
126
|
+
this.inner = operand;
|
|
127
|
+
}
|
|
128
|
+
register(params) {
|
|
129
|
+
return `size(${this.inner.register(params)})`;
|
|
130
|
+
}
|
|
131
|
+
}
|
|
2
132
|
//# sourceMappingURL=expression.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"expression.js","sourceRoot":"","sources":["../../../../src/commands/expressions/expression.ts"],"names":[],"mappings":""}
|
|
1
|
+
{"version":3,"file":"expression.js","sourceRoot":"","sources":["../../../../src/commands/expressions/expression.ts"],"names":[],"mappings":"AA0BA,8JAA8J;AAC9J,MAAM,OAAO,UAAU;IACJ,WAAW,CAAc;IAE1C,YAAY,MAAwB;QAClC,MAAM,EAAE,SAAS,EAAE,GAAG,MAAM,CAAC;QAC7B,IAAI,CAAC,WAAW,GAAG,SAAS,CAAC;IAC/B,CAAC;IAED,GAAG,CAAC,GAAe;QACjB,OAAO,IAAI,UAAU,CAAC;YACpB,SAAS,EAAE,CAAC,EAAE,cAAc,EAAE,eAAe,EAAE,EAAE,EAAE;gBACjD,MAAM,IAAI,GAAG,IAAI,CAAC,SAAS,CAAC,EAAE,cAAc,EAAE,eAAe,EAAE,CAAC,CAAC;gBACjE,MAAM,KAAK,GAAG,GAAG,CAAC,SAAS,CAAC,EAAE,cAAc,EAAE,eAAe,EAAE,CAAC,CAAC;gBACjE,OAAO,IAAI,IAAI,QAAQ,KAAK,GAAG,CAAC;YAClC,CAAC;SACF,CAAC,CAAC;IACL,CAAC;IAED,EAAE,CAAC,GAAe;QAChB,OAAO,IAAI,UAAU,CAAC;YACpB,SAAS,EAAE,CAAC,EAAE,cAAc,EAAE,eAAe,EAAE,EAAE,EAAE;gBACjD,MAAM,IAAI,GAAG,IAAI,CAAC,SAAS,CAAC,EAAE,cAAc,EAAE,eAAe,EAAE,CAAC,CAAC;gBACjE,MAAM,KAAK,GAAG,GAAG,CAAC,SAAS,CAAC,EAAE,cAAc,EAAE,eAAe,EAAE,CAAC,CAAC;gBACjE,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":"index.js","sourceRoot":"","sources":["../../../../src/commands/expressions/index.ts"],"names":[],"mappings":"AAAA,cAAc,
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../../src/commands/expressions/index.ts"],"names":[],"mappings":"AAAA,cAAc,iBAAiB,CAAC;AAChC,cAAc,oBAAoB,CAAC"}
|
|
@@ -1,15 +1,2 @@
|
|
|
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
1
|
import type { Expression } from "./expression.js";
|
|
5
|
-
export
|
|
6
|
-
private readonly inner;
|
|
7
|
-
constructor(params: {
|
|
8
|
-
inner: Expression;
|
|
9
|
-
});
|
|
10
|
-
stringify(params: {
|
|
11
|
-
attributeNames: AttributeNames;
|
|
12
|
-
attributeValues: AttributeValues;
|
|
13
|
-
}): string;
|
|
14
|
-
}
|
|
15
|
-
export declare function equals(name: AttributePath, value: AttributeValue): KeyConditionExpression;
|
|
2
|
+
export type KeyConditionExpression = Expression;
|
|
@@ -1,22 +1,2 @@
|
|
|
1
|
-
export
|
|
2
|
-
inner;
|
|
3
|
-
constructor(params) {
|
|
4
|
-
const { inner } = params;
|
|
5
|
-
this.inner = inner;
|
|
6
|
-
}
|
|
7
|
-
stringify(params) {
|
|
8
|
-
return this.inner.stringify(params);
|
|
9
|
-
}
|
|
10
|
-
}
|
|
11
|
-
export function equals(name, value) {
|
|
12
|
-
return new KeyConditionExpression({
|
|
13
|
-
inner: {
|
|
14
|
-
stringify: ({ attributeNames, attributeValues }) => {
|
|
15
|
-
const substitute = attributeNames.substitute(name);
|
|
16
|
-
const reference = attributeValues.reference(value);
|
|
17
|
-
return `${substitute} = ${reference}`;
|
|
18
|
-
},
|
|
19
|
-
},
|
|
20
|
-
});
|
|
21
|
-
}
|
|
1
|
+
export {};
|
|
22
2
|
//# sourceMappingURL=key-condition.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"key-condition.js","sourceRoot":"","sources":["../../../../src/commands/expressions/key-condition.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"key-condition.js","sourceRoot":"","sources":["../../../../src/commands/expressions/key-condition.ts"],"names":[],"mappings":""}
|