@infra-blocks/aws-dynamodb 0.5.0 → 0.6.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/attributes/names.d.ts +22 -0
- package/lib/cjs/commands/attributes/names.js +51 -0
- package/lib/cjs/commands/attributes/names.js.map +1 -0
- package/lib/cjs/commands/attributes/values.d.ts +12 -0
- package/lib/cjs/commands/attributes/values.js +49 -0
- package/lib/cjs/commands/attributes/values.js.map +1 -0
- package/lib/cjs/commands/expressions/condition.d.ts +10 -14
- package/lib/cjs/commands/expressions/condition.js +24 -95
- package/lib/cjs/commands/expressions/condition.js.map +1 -1
- package/lib/cjs/commands/expressions/expression.d.ts +8 -0
- package/lib/cjs/commands/expressions/expression.js +3 -0
- package/lib/cjs/commands/expressions/expression.js.map +1 -0
- package/lib/cjs/commands/put-item.js +21 -3
- package/lib/cjs/commands/put-item.js.map +1 -1
- package/lib/cjs/types.d.ts +1 -1
- package/lib/esm/commands/attributes/names.d.ts +22 -0
- package/lib/esm/commands/attributes/names.js +47 -0
- package/lib/esm/commands/attributes/names.js.map +1 -0
- package/lib/esm/commands/attributes/values.d.ts +12 -0
- package/lib/esm/commands/attributes/values.js +45 -0
- package/lib/esm/commands/attributes/values.js.map +1 -0
- package/lib/esm/commands/expressions/condition.d.ts +10 -14
- package/lib/esm/commands/expressions/condition.js +24 -95
- package/lib/esm/commands/expressions/condition.js.map +1 -1
- package/lib/esm/commands/expressions/expression.d.ts +8 -0
- package/lib/esm/commands/expressions/expression.js +2 -0
- package/lib/esm/commands/expressions/expression.js.map +1 -0
- package/lib/esm/commands/put-item.js +21 -3
- package/lib/esm/commands/put-item.js.map +1 -1
- package/lib/esm/types.d.ts +1 -1
- package/package.json +1 -1
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import type { AttributePath } from "../../types.js";
|
|
2
|
+
/**
|
|
3
|
+
* A substitution always starts with the `#` character.
|
|
4
|
+
*/
|
|
5
|
+
export type Substitution = `#${string}`;
|
|
6
|
+
/**
|
|
7
|
+
* Represents a set of attribute names used in a condition expression.
|
|
8
|
+
*
|
|
9
|
+
* The uses cases for using attribute names are:
|
|
10
|
+
* - To access an attribute whose name conflicts with a DynamoDB reserved word.
|
|
11
|
+
* - To create a placeholder for repeating occurrences of an attribute name in an expression.
|
|
12
|
+
* - To prevent special characters in an attribute name from being misinterpreted in an expression.
|
|
13
|
+
*/
|
|
14
|
+
export declare class AttributeNames {
|
|
15
|
+
private readonly names;
|
|
16
|
+
private constructor();
|
|
17
|
+
add(...attributes: AttributePath[]): void;
|
|
18
|
+
getSubstitute(attribute: AttributePath): Substitution;
|
|
19
|
+
getSubstitutions(): Record<Substitution, AttributePath> | undefined;
|
|
20
|
+
private generateSubstitute;
|
|
21
|
+
static create(): AttributeNames;
|
|
22
|
+
}
|
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.AttributeNames = void 0;
|
|
4
|
+
/**
|
|
5
|
+
* Represents a set of attribute names used in a condition expression.
|
|
6
|
+
*
|
|
7
|
+
* The uses cases for using attribute names are:
|
|
8
|
+
* - To access an attribute whose name conflicts with a DynamoDB reserved word.
|
|
9
|
+
* - To create a placeholder for repeating occurrences of an attribute name in an expression.
|
|
10
|
+
* - To prevent special characters in an attribute name from being misinterpreted in an expression.
|
|
11
|
+
*/
|
|
12
|
+
class AttributeNames {
|
|
13
|
+
names;
|
|
14
|
+
constructor() {
|
|
15
|
+
this.names = new Map();
|
|
16
|
+
}
|
|
17
|
+
add(...attributes) {
|
|
18
|
+
for (const attribute of attributes) {
|
|
19
|
+
if (this.names.has(attribute)) {
|
|
20
|
+
continue;
|
|
21
|
+
}
|
|
22
|
+
const substitute = this.generateSubstitute(attribute);
|
|
23
|
+
this.names.set(attribute, substitute);
|
|
24
|
+
}
|
|
25
|
+
}
|
|
26
|
+
getSubstitute(attribute) {
|
|
27
|
+
const substitute = this.names.get(attribute);
|
|
28
|
+
if (substitute == null) {
|
|
29
|
+
throw new Error(`no substitution found for attribute: ${attribute}`);
|
|
30
|
+
}
|
|
31
|
+
return substitute;
|
|
32
|
+
}
|
|
33
|
+
getSubstitutions() {
|
|
34
|
+
if (this.names.size === 0) {
|
|
35
|
+
return undefined;
|
|
36
|
+
}
|
|
37
|
+
const result = {};
|
|
38
|
+
for (const [attribute, substitute] of this.names.entries()) {
|
|
39
|
+
result[substitute] = attribute;
|
|
40
|
+
}
|
|
41
|
+
return result;
|
|
42
|
+
}
|
|
43
|
+
generateSubstitute(attribute) {
|
|
44
|
+
return `#${attribute}`;
|
|
45
|
+
}
|
|
46
|
+
static create() {
|
|
47
|
+
return new AttributeNames();
|
|
48
|
+
}
|
|
49
|
+
}
|
|
50
|
+
exports.AttributeNames = AttributeNames;
|
|
51
|
+
//# sourceMappingURL=names.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"names.js","sourceRoot":"","sources":["../../../../src/commands/attributes/names.ts"],"names":[],"mappings":";;;AAOA;;;;;;;GAOG;AACH,MAAa,cAAc;IACR,KAAK,CAAmC;IAEzD;QACE,IAAI,CAAC,KAAK,GAAG,IAAI,GAAG,EAA+B,CAAC;IACtD,CAAC;IAED,GAAG,CAAC,GAAG,UAA2B;QAChC,KAAK,MAAM,SAAS,IAAI,UAAU,EAAE,CAAC;YACnC,IAAI,IAAI,CAAC,KAAK,CAAC,GAAG,CAAC,SAAS,CAAC,EAAE,CAAC;gBAC9B,SAAS;YACX,CAAC;YACD,MAAM,UAAU,GAAG,IAAI,CAAC,kBAAkB,CAAC,SAAS,CAAC,CAAC;YACtD,IAAI,CAAC,KAAK,CAAC,GAAG,CAAC,SAAS,EAAE,UAAU,CAAC,CAAC;QACxC,CAAC;IACH,CAAC;IAED,aAAa,CAAC,SAAwB;QACpC,MAAM,UAAU,GAAG,IAAI,CAAC,KAAK,CAAC,GAAG,CAAC,SAAS,CAAC,CAAC;QAC7C,IAAI,UAAU,IAAI,IAAI,EAAE,CAAC;YACvB,MAAM,IAAI,KAAK,CAAC,wCAAwC,SAAS,EAAE,CAAC,CAAC;QACvE,CAAC;QACD,OAAO,UAAU,CAAC;IACpB,CAAC;IAED,gBAAgB;QACd,IAAI,IAAI,CAAC,KAAK,CAAC,IAAI,KAAK,CAAC,EAAE,CAAC;YAC1B,OAAO,SAAS,CAAC;QACnB,CAAC;QAED,MAAM,MAAM,GAAwC,EAAE,CAAC;QACvD,KAAK,MAAM,CAAC,SAAS,EAAE,UAAU,CAAC,IAAI,IAAI,CAAC,KAAK,CAAC,OAAO,EAAE,EAAE,CAAC;YAC3D,MAAM,CAAC,UAAU,CAAC,GAAG,SAAS,CAAC;QACjC,CAAC;QACD,OAAO,MAAM,CAAC;IAChB,CAAC;IAEO,kBAAkB,CAAC,SAAwB;QACjD,OAAO,IAAI,SAAS,EAAkB,CAAC;IACzC,CAAC;IAED,MAAM,CAAC,MAAM;QACX,OAAO,IAAI,cAAc,EAAE,CAAC;IAC9B,CAAC;CACF;AA5CD,wCA4CC"}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import type { AttributeValue } from "../../types.js";
|
|
2
|
+
export type ValueReference = `:${string}`;
|
|
3
|
+
export declare class AttributeValues {
|
|
4
|
+
private readonly values;
|
|
5
|
+
private counter;
|
|
6
|
+
private constructor();
|
|
7
|
+
add(...values: AttributeValue[]): void;
|
|
8
|
+
getReference(value: AttributeValue): ValueReference;
|
|
9
|
+
getReferences(): Record<ValueReference, AttributeValue> | undefined;
|
|
10
|
+
private nextReference;
|
|
11
|
+
static create(): AttributeValues;
|
|
12
|
+
}
|
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.AttributeValues = void 0;
|
|
4
|
+
class AttributeValues {
|
|
5
|
+
values;
|
|
6
|
+
counter;
|
|
7
|
+
constructor() {
|
|
8
|
+
this.values = new Map();
|
|
9
|
+
this.counter = 0;
|
|
10
|
+
}
|
|
11
|
+
add(...values) {
|
|
12
|
+
for (const value of values) {
|
|
13
|
+
if (this.values.has(value)) {
|
|
14
|
+
continue;
|
|
15
|
+
}
|
|
16
|
+
const reference = this.nextReference();
|
|
17
|
+
this.values.set(value, reference);
|
|
18
|
+
}
|
|
19
|
+
}
|
|
20
|
+
getReference(value) {
|
|
21
|
+
const existing = this.values.get(value);
|
|
22
|
+
if (existing != null) {
|
|
23
|
+
return existing;
|
|
24
|
+
}
|
|
25
|
+
const reference = this.nextReference();
|
|
26
|
+
this.values.set(value, reference);
|
|
27
|
+
return reference;
|
|
28
|
+
}
|
|
29
|
+
getReferences() {
|
|
30
|
+
if (this.values.size === 0) {
|
|
31
|
+
return undefined;
|
|
32
|
+
}
|
|
33
|
+
const result = {};
|
|
34
|
+
for (const [value, reference] of this.values.entries()) {
|
|
35
|
+
result[reference] = value;
|
|
36
|
+
}
|
|
37
|
+
return result;
|
|
38
|
+
}
|
|
39
|
+
nextReference() {
|
|
40
|
+
const reference = `:${this.counter}`;
|
|
41
|
+
this.counter += 1;
|
|
42
|
+
return reference;
|
|
43
|
+
}
|
|
44
|
+
static create() {
|
|
45
|
+
return new AttributeValues();
|
|
46
|
+
}
|
|
47
|
+
}
|
|
48
|
+
exports.AttributeValues = AttributeValues;
|
|
49
|
+
//# sourceMappingURL=values.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"values.js","sourceRoot":"","sources":["../../../../src/commands/attributes/values.ts"],"names":[],"mappings":";;;AAIA,MAAa,eAAe;IACT,MAAM,CAAsC;IACrD,OAAO,CAAS;IAExB;QACE,IAAI,CAAC,MAAM,GAAG,IAAI,GAAG,EAAkC,CAAC;QACxD,IAAI,CAAC,OAAO,GAAG,CAAC,CAAC;IACnB,CAAC;IAED,GAAG,CAAC,GAAG,MAAwB;QAC7B,KAAK,MAAM,KAAK,IAAI,MAAM,EAAE,CAAC;YAC3B,IAAI,IAAI,CAAC,MAAM,CAAC,GAAG,CAAC,KAAK,CAAC,EAAE,CAAC;gBAC3B,SAAS;YACX,CAAC;YACD,MAAM,SAAS,GAAG,IAAI,CAAC,aAAa,EAAE,CAAC;YACvC,IAAI,CAAC,MAAM,CAAC,GAAG,CAAC,KAAK,EAAE,SAAS,CAAC,CAAC;QACpC,CAAC;IACH,CAAC;IAED,YAAY,CAAC,KAAqB;QAChC,MAAM,QAAQ,GAAG,IAAI,CAAC,MAAM,CAAC,GAAG,CAAC,KAAK,CAAC,CAAC;QACxC,IAAI,QAAQ,IAAI,IAAI,EAAE,CAAC;YACrB,OAAO,QAAQ,CAAC;QAClB,CAAC;QACD,MAAM,SAAS,GAAG,IAAI,CAAC,aAAa,EAAE,CAAC;QACvC,IAAI,CAAC,MAAM,CAAC,GAAG,CAAC,KAAK,EAAE,SAAS,CAAC,CAAC;QAClC,OAAO,SAAS,CAAC;IACnB,CAAC;IAED,aAAa;QACX,IAAI,IAAI,CAAC,MAAM,CAAC,IAAI,KAAK,CAAC,EAAE,CAAC;YAC3B,OAAO,SAAS,CAAC;QACnB,CAAC;QAED,MAAM,MAAM,GAA2C,EAAE,CAAC;QAC1D,KAAK,MAAM,CAAC,KAAK,EAAE,SAAS,CAAC,IAAI,IAAI,CAAC,MAAM,CAAC,OAAO,EAAE,EAAE,CAAC;YACvD,MAAM,CAAC,SAAS,CAAC,GAAG,KAAK,CAAC;QAC5B,CAAC;QACD,OAAO,MAAM,CAAC;IAChB,CAAC;IAEO,aAAa;QACnB,MAAM,SAAS,GAAG,IAAI,IAAI,CAAC,OAAO,EAAoB,CAAC;QACvD,IAAI,CAAC,OAAO,IAAI,CAAC,CAAC;QAClB,OAAO,SAAS,CAAC;IACnB,CAAC;IAED,MAAM,CAAC,MAAM;QACX,OAAO,IAAI,eAAe,EAAE,CAAC;IAC/B,CAAC;CACF;AAlDD,0CAkDC"}
|
|
@@ -1,19 +1,15 @@
|
|
|
1
|
-
import type { AttributePath, AttributeType
|
|
2
|
-
type
|
|
3
|
-
type
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
ExpressionAttributeValues?: Record<ValueReference, AttributeValue>;
|
|
8
|
-
};
|
|
9
|
-
export declare class ConditionExpression {
|
|
10
|
-
private readonly expression;
|
|
11
|
-
private readonly substitutions?;
|
|
12
|
-
private readonly values?;
|
|
1
|
+
import type { AttributePath, AttributeType } from "../../types.js";
|
|
2
|
+
import type { AttributeNames } from "../attributes/names.js";
|
|
3
|
+
import type { AttributeValues } from "../attributes/values.js";
|
|
4
|
+
import type { Expression } from "./expression.js";
|
|
5
|
+
export declare class ConditionExpression implements Expression {
|
|
6
|
+
private readonly inner;
|
|
13
7
|
private constructor();
|
|
14
|
-
|
|
8
|
+
stringify(params: {
|
|
9
|
+
attributeNames: AttributeNames;
|
|
10
|
+
attributeValues: AttributeValues;
|
|
11
|
+
}): string;
|
|
15
12
|
static attributeNotExists(attribute: AttributePath): ConditionExpression;
|
|
16
13
|
static attributeExists(attribute: AttributePath): ConditionExpression;
|
|
17
14
|
static attributeType(attribute: AttributePath, type: AttributeType): ConditionExpression;
|
|
18
15
|
}
|
|
19
|
-
export {};
|
|
@@ -1,115 +1,44 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.ConditionExpression = void 0;
|
|
4
|
-
/**
|
|
5
|
-
* Represents a set of attribute names used in a condition expression.
|
|
6
|
-
*
|
|
7
|
-
* The uses cases for using attribute names are:
|
|
8
|
-
* - To access an attribute whose name conflicts with a DynamoDB reserved word.
|
|
9
|
-
* - To create a placeholder for repeating occurrences of an attribute name in an expression.
|
|
10
|
-
* - To prevent special characters in an attribute name from being misinterpreted in an expression.
|
|
11
|
-
*/
|
|
12
|
-
class AttributeSubstitutions {
|
|
13
|
-
names;
|
|
14
|
-
constructor() {
|
|
15
|
-
this.names = new Map();
|
|
16
|
-
}
|
|
17
|
-
substitute(attribute) {
|
|
18
|
-
const existing = this.names.get(attribute);
|
|
19
|
-
if (existing != null) {
|
|
20
|
-
return existing;
|
|
21
|
-
}
|
|
22
|
-
const substitute = this.generateSubstitute(attribute);
|
|
23
|
-
this.names.set(attribute, substitute);
|
|
24
|
-
return substitute;
|
|
25
|
-
}
|
|
26
|
-
toAwsInput() {
|
|
27
|
-
const result = {};
|
|
28
|
-
for (const [attribute, substitute] of this.names.entries()) {
|
|
29
|
-
result[substitute] = attribute;
|
|
30
|
-
}
|
|
31
|
-
return result;
|
|
32
|
-
}
|
|
33
|
-
generateSubstitute(attribute) {
|
|
34
|
-
return `#${attribute}`;
|
|
35
|
-
}
|
|
36
|
-
}
|
|
37
|
-
class AttributeValues {
|
|
38
|
-
values;
|
|
39
|
-
counter;
|
|
40
|
-
constructor() {
|
|
41
|
-
this.values = new Map();
|
|
42
|
-
this.counter = 0;
|
|
43
|
-
}
|
|
44
|
-
referenceBy(value) {
|
|
45
|
-
const existing = this.values.get(value);
|
|
46
|
-
if (existing != null) {
|
|
47
|
-
return existing;
|
|
48
|
-
}
|
|
49
|
-
const reference = this.generateReference();
|
|
50
|
-
this.values.set(value, reference);
|
|
51
|
-
return reference;
|
|
52
|
-
}
|
|
53
|
-
toAwsInput() {
|
|
54
|
-
const result = {};
|
|
55
|
-
for (const [value, reference] of this.values.entries()) {
|
|
56
|
-
result[reference] = value;
|
|
57
|
-
}
|
|
58
|
-
return result;
|
|
59
|
-
}
|
|
60
|
-
generateReference() {
|
|
61
|
-
const reference = `:${this.counter}`;
|
|
62
|
-
this.counter += 1;
|
|
63
|
-
return reference;
|
|
64
|
-
}
|
|
65
|
-
}
|
|
66
4
|
class ConditionExpression {
|
|
67
|
-
|
|
68
|
-
substitutions;
|
|
69
|
-
values;
|
|
5
|
+
inner;
|
|
70
6
|
constructor(params) {
|
|
71
|
-
const {
|
|
72
|
-
this.
|
|
73
|
-
this.substitutions = substitutions;
|
|
74
|
-
this.values = values;
|
|
7
|
+
const { inner } = params;
|
|
8
|
+
this.inner = inner;
|
|
75
9
|
}
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
ConditionExpression: this.expression,
|
|
79
|
-
};
|
|
80
|
-
if (this.substitutions != null) {
|
|
81
|
-
result.ExpressionAttributeNames = this.substitutions.toAwsInput();
|
|
82
|
-
}
|
|
83
|
-
if (this.values != null) {
|
|
84
|
-
result.ExpressionAttributeValues = this.values.toAwsInput();
|
|
85
|
-
}
|
|
86
|
-
return result;
|
|
10
|
+
stringify(params) {
|
|
11
|
+
return this.inner.stringify(params);
|
|
87
12
|
}
|
|
88
13
|
static attributeNotExists(attribute) {
|
|
89
|
-
const substitutions = new AttributeSubstitutions();
|
|
90
|
-
const sub = substitutions.substitute(attribute);
|
|
91
14
|
return new ConditionExpression({
|
|
92
|
-
|
|
93
|
-
|
|
15
|
+
inner: {
|
|
16
|
+
stringify: ({ attributeNames }) => {
|
|
17
|
+
attributeNames.add(attribute);
|
|
18
|
+
return `attribute_not_exists(${attributeNames.getSubstitute(attribute)})`;
|
|
19
|
+
},
|
|
20
|
+
},
|
|
94
21
|
});
|
|
95
22
|
}
|
|
96
23
|
static attributeExists(attribute) {
|
|
97
|
-
const substitutions = new AttributeSubstitutions();
|
|
98
|
-
const sub = substitutions.substitute(attribute);
|
|
99
24
|
return new ConditionExpression({
|
|
100
|
-
|
|
101
|
-
|
|
25
|
+
inner: {
|
|
26
|
+
stringify: ({ attributeNames }) => {
|
|
27
|
+
attributeNames.add(attribute);
|
|
28
|
+
return `attribute_exists(${attributeNames.getSubstitute(attribute)})`;
|
|
29
|
+
},
|
|
30
|
+
},
|
|
102
31
|
});
|
|
103
32
|
}
|
|
104
33
|
static attributeType(attribute, type) {
|
|
105
|
-
const substitutions = new AttributeSubstitutions();
|
|
106
|
-
const sub = substitutions.substitute(attribute);
|
|
107
|
-
const values = new AttributeValues();
|
|
108
|
-
const valueRef = values.referenceBy(type);
|
|
109
34
|
return new ConditionExpression({
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
35
|
+
inner: {
|
|
36
|
+
stringify: ({ attributeNames, attributeValues }) => {
|
|
37
|
+
attributeNames.add(attribute);
|
|
38
|
+
attributeValues.add(type);
|
|
39
|
+
return `attribute_type(${attributeNames.getSubstitute(attribute)}, ${attributeValues.getReference(type)})`;
|
|
40
|
+
},
|
|
41
|
+
},
|
|
113
42
|
});
|
|
114
43
|
}
|
|
115
44
|
}
|
|
@@ -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":";;;AAKA,MAAa,mBAAmB;IACb,KAAK,CAAa;IAEnC,YAAoB,MAA6B;QAC/C,MAAM,EAAE,KAAK,EAAE,GAAG,MAAM,CAAC;QACzB,IAAI,CAAC,KAAK,GAAG,KAAK,CAAC;IACrB,CAAC;IAED,SAAS,CAAC,MAGT;QACC,OAAO,IAAI,CAAC,KAAK,CAAC,SAAS,CAAC,MAAM,CAAC,CAAC;IACtC,CAAC;IAED,MAAM,CAAC,kBAAkB,CAAC,SAAwB;QAChD,OAAO,IAAI,mBAAmB,CAAC;YAC7B,KAAK,EAAE;gBACL,SAAS,EAAE,CAAC,EAAE,cAAc,EAAE,EAAE,EAAE;oBAChC,cAAc,CAAC,GAAG,CAAC,SAAS,CAAC,CAAC;oBAC9B,OAAO,wBAAwB,cAAc,CAAC,aAAa,CAAC,SAAS,CAAC,GAAG,CAAC;gBAC5E,CAAC;aACF;SACF,CAAC,CAAC;IACL,CAAC;IAED,MAAM,CAAC,eAAe,CAAC,SAAwB;QAC7C,OAAO,IAAI,mBAAmB,CAAC;YAC7B,KAAK,EAAE;gBACL,SAAS,EAAE,CAAC,EAAE,cAAc,EAAE,EAAE,EAAE;oBAChC,cAAc,CAAC,GAAG,CAAC,SAAS,CAAC,CAAC;oBAC9B,OAAO,oBAAoB,cAAc,CAAC,aAAa,CAAC,SAAS,CAAC,GAAG,CAAC;gBACxE,CAAC;aACF;SACF,CAAC,CAAC;IACL,CAAC;IAED,MAAM,CAAC,aAAa,CAClB,SAAwB,EACxB,IAAmB;QAEnB,OAAO,IAAI,mBAAmB,CAAC;YAC7B,KAAK,EAAE;gBACL,SAAS,EAAE,CAAC,EAAE,cAAc,EAAE,eAAe,EAAE,EAAE,EAAE;oBACjD,cAAc,CAAC,GAAG,CAAC,SAAS,CAAC,CAAC;oBAC9B,eAAe,CAAC,GAAG,CAAC,IAAI,CAAC,CAAC;oBAC1B,OAAO,kBAAkB,cAAc,CAAC,aAAa,CAAC,SAAS,CAAC,KAAK,eAAe,CAAC,YAAY,CAAC,IAAI,CAAC,GAAG,CAAC;gBAC7G,CAAC;aACF;SACF,CAAC,CAAC;IACL,CAAC;CACF;AAnDD,kDAmDC"}
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import type { AttributeNames } from "../attributes/names.js";
|
|
2
|
+
import type { AttributeValues } from "../attributes/values.js";
|
|
3
|
+
export interface Expression {
|
|
4
|
+
stringify(params: {
|
|
5
|
+
attributeNames: AttributeNames;
|
|
6
|
+
attributeValues: AttributeValues;
|
|
7
|
+
}): string;
|
|
8
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"expression.js","sourceRoot":"","sources":["../../../../src/commands/expressions/expression.ts"],"names":[],"mappings":""}
|
|
@@ -2,6 +2,8 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.PutItem = void 0;
|
|
4
4
|
const lib_dynamodb_1 = require("@aws-sdk/lib-dynamodb");
|
|
5
|
+
const names_js_1 = require("./attributes/names.js");
|
|
6
|
+
const values_js_1 = require("./attributes/values.js");
|
|
5
7
|
class PutItem {
|
|
6
8
|
table;
|
|
7
9
|
item;
|
|
@@ -14,11 +16,27 @@ class PutItem {
|
|
|
14
16
|
}
|
|
15
17
|
toAwsCommandInput() {
|
|
16
18
|
const { table, item, condition } = this;
|
|
17
|
-
const
|
|
18
|
-
return {
|
|
19
|
+
const input = {
|
|
19
20
|
TableName: table,
|
|
20
21
|
Item: item,
|
|
21
|
-
|
|
22
|
+
};
|
|
23
|
+
// Expression attribute names and values can only be specified when a condition is provided,
|
|
24
|
+
// which is optional.
|
|
25
|
+
if (condition == null) {
|
|
26
|
+
return input;
|
|
27
|
+
}
|
|
28
|
+
const attributeNames = names_js_1.AttributeNames.create();
|
|
29
|
+
const attributeValues = values_js_1.AttributeValues.create();
|
|
30
|
+
// Ask the expression to stringify itself, applying the substitutions by itself.
|
|
31
|
+
const expression = condition.stringify({
|
|
32
|
+
attributeNames,
|
|
33
|
+
attributeValues,
|
|
34
|
+
});
|
|
35
|
+
return {
|
|
36
|
+
...input,
|
|
37
|
+
ConditionExpression: expression,
|
|
38
|
+
ExpressionAttributeNames: attributeNames.getSubstitutions(),
|
|
39
|
+
ExpressionAttributeValues: attributeValues.getReferences(),
|
|
22
40
|
};
|
|
23
41
|
}
|
|
24
42
|
toAwsCommand() {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"put-item.js","sourceRoot":"","sources":["../../../src/commands/put-item.ts"],"names":[],"mappings":";;;AAAA,wDAAyE;
|
|
1
|
+
{"version":3,"file":"put-item.js","sourceRoot":"","sources":["../../../src/commands/put-item.ts"],"names":[],"mappings":";;;AAAA,wDAAyE;AAEzE,oDAAuD;AACvD,sDAAyD;AAUzD,MAAa,OAAO;IACD,KAAK,CAAS;IACd,IAAI,CAAa;IACjB,SAAS,CAAuB;IAEjD,YAAoB,MAAqB;QACvC,MAAM,EAAE,KAAK,EAAE,IAAI,EAAE,SAAS,EAAE,GAAG,MAAM,CAAC;QAC1C,IAAI,CAAC,KAAK,GAAG,KAAK,CAAC;QACnB,IAAI,CAAC,IAAI,GAAG,IAAI,CAAC;QACjB,IAAI,CAAC,SAAS,GAAG,SAAS,CAAC;IAC7B,CAAC;IAED,iBAAiB;QACf,MAAM,EAAE,KAAK,EAAE,IAAI,EAAE,SAAS,EAAE,GAAG,IAAI,CAAC;QAExC,MAAM,KAAK,GAAoB;YAC7B,SAAS,EAAE,KAAK;YAChB,IAAI,EAAE,IAAI;SACX,CAAC;QAEF,4FAA4F;QAC5F,qBAAqB;QACrB,IAAI,SAAS,IAAI,IAAI,EAAE,CAAC;YACtB,OAAO,KAAK,CAAC;QACf,CAAC;QAED,MAAM,cAAc,GAAG,yBAAc,CAAC,MAAM,EAAE,CAAC;QAC/C,MAAM,eAAe,GAAG,2BAAe,CAAC,MAAM,EAAE,CAAC;QACjD,gFAAgF;QAChF,MAAM,UAAU,GAAG,SAAS,CAAC,SAAS,CAAC;YACrC,cAAc;YACd,eAAe;SAChB,CAAC,CAAC;QAEH,OAAO;YACL,GAAG,KAAK;YACR,mBAAmB,EAAE,UAAU;YAC/B,wBAAwB,EAAE,cAAc,CAAC,gBAAgB,EAAE;YAC3D,yBAAyB,EAAE,eAAe,CAAC,aAAa,EAAE;SAC3D,CAAC;IACJ,CAAC;IAED,YAAY;QACV,OAAO,IAAI,yBAAU,CAAC,IAAI,CAAC,iBAAiB,EAAE,CAAC,CAAC;IAClD,CAAC;IAED,MAAM,CAAC,IAAI,CAAC,MAAqB;QAC/B,OAAO,IAAI,OAAO,CAAC,MAAM,CAAC,CAAC;IAC7B,CAAC;CACF;AAjDD,0BAiDC"}
|
package/lib/cjs/types.d.ts
CHANGED
|
@@ -8,7 +8,7 @@ export interface Attribute {
|
|
|
8
8
|
name: AttributeName;
|
|
9
9
|
value: AttributeValue;
|
|
10
10
|
}
|
|
11
|
-
export type Attributes = Record<AttributeName,
|
|
11
|
+
export type Attributes = Record<AttributeName, AttributeValue>;
|
|
12
12
|
export type IndexFieldType = ScalarAttributeType;
|
|
13
13
|
export interface IndexField {
|
|
14
14
|
name: string;
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import type { AttributePath } from "../../types.js";
|
|
2
|
+
/**
|
|
3
|
+
* A substitution always starts with the `#` character.
|
|
4
|
+
*/
|
|
5
|
+
export type Substitution = `#${string}`;
|
|
6
|
+
/**
|
|
7
|
+
* Represents a set of attribute names used in a condition expression.
|
|
8
|
+
*
|
|
9
|
+
* The uses cases for using attribute names are:
|
|
10
|
+
* - To access an attribute whose name conflicts with a DynamoDB reserved word.
|
|
11
|
+
* - To create a placeholder for repeating occurrences of an attribute name in an expression.
|
|
12
|
+
* - To prevent special characters in an attribute name from being misinterpreted in an expression.
|
|
13
|
+
*/
|
|
14
|
+
export declare class AttributeNames {
|
|
15
|
+
private readonly names;
|
|
16
|
+
private constructor();
|
|
17
|
+
add(...attributes: AttributePath[]): void;
|
|
18
|
+
getSubstitute(attribute: AttributePath): Substitution;
|
|
19
|
+
getSubstitutions(): Record<Substitution, AttributePath> | undefined;
|
|
20
|
+
private generateSubstitute;
|
|
21
|
+
static create(): AttributeNames;
|
|
22
|
+
}
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Represents a set of attribute names used in a condition expression.
|
|
3
|
+
*
|
|
4
|
+
* The uses cases for using attribute names are:
|
|
5
|
+
* - To access an attribute whose name conflicts with a DynamoDB reserved word.
|
|
6
|
+
* - To create a placeholder for repeating occurrences of an attribute name in an expression.
|
|
7
|
+
* - To prevent special characters in an attribute name from being misinterpreted in an expression.
|
|
8
|
+
*/
|
|
9
|
+
export class AttributeNames {
|
|
10
|
+
names;
|
|
11
|
+
constructor() {
|
|
12
|
+
this.names = new Map();
|
|
13
|
+
}
|
|
14
|
+
add(...attributes) {
|
|
15
|
+
for (const attribute of attributes) {
|
|
16
|
+
if (this.names.has(attribute)) {
|
|
17
|
+
continue;
|
|
18
|
+
}
|
|
19
|
+
const substitute = this.generateSubstitute(attribute);
|
|
20
|
+
this.names.set(attribute, substitute);
|
|
21
|
+
}
|
|
22
|
+
}
|
|
23
|
+
getSubstitute(attribute) {
|
|
24
|
+
const substitute = this.names.get(attribute);
|
|
25
|
+
if (substitute == null) {
|
|
26
|
+
throw new Error(`no substitution found for attribute: ${attribute}`);
|
|
27
|
+
}
|
|
28
|
+
return substitute;
|
|
29
|
+
}
|
|
30
|
+
getSubstitutions() {
|
|
31
|
+
if (this.names.size === 0) {
|
|
32
|
+
return undefined;
|
|
33
|
+
}
|
|
34
|
+
const result = {};
|
|
35
|
+
for (const [attribute, substitute] of this.names.entries()) {
|
|
36
|
+
result[substitute] = attribute;
|
|
37
|
+
}
|
|
38
|
+
return result;
|
|
39
|
+
}
|
|
40
|
+
generateSubstitute(attribute) {
|
|
41
|
+
return `#${attribute}`;
|
|
42
|
+
}
|
|
43
|
+
static create() {
|
|
44
|
+
return new AttributeNames();
|
|
45
|
+
}
|
|
46
|
+
}
|
|
47
|
+
//# sourceMappingURL=names.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"names.js","sourceRoot":"","sources":["../../../../src/commands/attributes/names.ts"],"names":[],"mappings":"AAOA;;;;;;;GAOG;AACH,MAAM,OAAO,cAAc;IACR,KAAK,CAAmC;IAEzD;QACE,IAAI,CAAC,KAAK,GAAG,IAAI,GAAG,EAA+B,CAAC;IACtD,CAAC;IAED,GAAG,CAAC,GAAG,UAA2B;QAChC,KAAK,MAAM,SAAS,IAAI,UAAU,EAAE,CAAC;YACnC,IAAI,IAAI,CAAC,KAAK,CAAC,GAAG,CAAC,SAAS,CAAC,EAAE,CAAC;gBAC9B,SAAS;YACX,CAAC;YACD,MAAM,UAAU,GAAG,IAAI,CAAC,kBAAkB,CAAC,SAAS,CAAC,CAAC;YACtD,IAAI,CAAC,KAAK,CAAC,GAAG,CAAC,SAAS,EAAE,UAAU,CAAC,CAAC;QACxC,CAAC;IACH,CAAC;IAED,aAAa,CAAC,SAAwB;QACpC,MAAM,UAAU,GAAG,IAAI,CAAC,KAAK,CAAC,GAAG,CAAC,SAAS,CAAC,CAAC;QAC7C,IAAI,UAAU,IAAI,IAAI,EAAE,CAAC;YACvB,MAAM,IAAI,KAAK,CAAC,wCAAwC,SAAS,EAAE,CAAC,CAAC;QACvE,CAAC;QACD,OAAO,UAAU,CAAC;IACpB,CAAC;IAED,gBAAgB;QACd,IAAI,IAAI,CAAC,KAAK,CAAC,IAAI,KAAK,CAAC,EAAE,CAAC;YAC1B,OAAO,SAAS,CAAC;QACnB,CAAC;QAED,MAAM,MAAM,GAAwC,EAAE,CAAC;QACvD,KAAK,MAAM,CAAC,SAAS,EAAE,UAAU,CAAC,IAAI,IAAI,CAAC,KAAK,CAAC,OAAO,EAAE,EAAE,CAAC;YAC3D,MAAM,CAAC,UAAU,CAAC,GAAG,SAAS,CAAC;QACjC,CAAC;QACD,OAAO,MAAM,CAAC;IAChB,CAAC;IAEO,kBAAkB,CAAC,SAAwB;QACjD,OAAO,IAAI,SAAS,EAAkB,CAAC;IACzC,CAAC;IAED,MAAM,CAAC,MAAM;QACX,OAAO,IAAI,cAAc,EAAE,CAAC;IAC9B,CAAC;CACF"}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import type { AttributeValue } from "../../types.js";
|
|
2
|
+
export type ValueReference = `:${string}`;
|
|
3
|
+
export declare class AttributeValues {
|
|
4
|
+
private readonly values;
|
|
5
|
+
private counter;
|
|
6
|
+
private constructor();
|
|
7
|
+
add(...values: AttributeValue[]): void;
|
|
8
|
+
getReference(value: AttributeValue): ValueReference;
|
|
9
|
+
getReferences(): Record<ValueReference, AttributeValue> | undefined;
|
|
10
|
+
private nextReference;
|
|
11
|
+
static create(): AttributeValues;
|
|
12
|
+
}
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
export class AttributeValues {
|
|
2
|
+
values;
|
|
3
|
+
counter;
|
|
4
|
+
constructor() {
|
|
5
|
+
this.values = new Map();
|
|
6
|
+
this.counter = 0;
|
|
7
|
+
}
|
|
8
|
+
add(...values) {
|
|
9
|
+
for (const value of values) {
|
|
10
|
+
if (this.values.has(value)) {
|
|
11
|
+
continue;
|
|
12
|
+
}
|
|
13
|
+
const reference = this.nextReference();
|
|
14
|
+
this.values.set(value, reference);
|
|
15
|
+
}
|
|
16
|
+
}
|
|
17
|
+
getReference(value) {
|
|
18
|
+
const existing = this.values.get(value);
|
|
19
|
+
if (existing != null) {
|
|
20
|
+
return existing;
|
|
21
|
+
}
|
|
22
|
+
const reference = this.nextReference();
|
|
23
|
+
this.values.set(value, reference);
|
|
24
|
+
return reference;
|
|
25
|
+
}
|
|
26
|
+
getReferences() {
|
|
27
|
+
if (this.values.size === 0) {
|
|
28
|
+
return undefined;
|
|
29
|
+
}
|
|
30
|
+
const result = {};
|
|
31
|
+
for (const [value, reference] of this.values.entries()) {
|
|
32
|
+
result[reference] = value;
|
|
33
|
+
}
|
|
34
|
+
return result;
|
|
35
|
+
}
|
|
36
|
+
nextReference() {
|
|
37
|
+
const reference = `:${this.counter}`;
|
|
38
|
+
this.counter += 1;
|
|
39
|
+
return reference;
|
|
40
|
+
}
|
|
41
|
+
static create() {
|
|
42
|
+
return new AttributeValues();
|
|
43
|
+
}
|
|
44
|
+
}
|
|
45
|
+
//# sourceMappingURL=values.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"values.js","sourceRoot":"","sources":["../../../../src/commands/attributes/values.ts"],"names":[],"mappings":"AAIA,MAAM,OAAO,eAAe;IACT,MAAM,CAAsC;IACrD,OAAO,CAAS;IAExB;QACE,IAAI,CAAC,MAAM,GAAG,IAAI,GAAG,EAAkC,CAAC;QACxD,IAAI,CAAC,OAAO,GAAG,CAAC,CAAC;IACnB,CAAC;IAED,GAAG,CAAC,GAAG,MAAwB;QAC7B,KAAK,MAAM,KAAK,IAAI,MAAM,EAAE,CAAC;YAC3B,IAAI,IAAI,CAAC,MAAM,CAAC,GAAG,CAAC,KAAK,CAAC,EAAE,CAAC;gBAC3B,SAAS;YACX,CAAC;YACD,MAAM,SAAS,GAAG,IAAI,CAAC,aAAa,EAAE,CAAC;YACvC,IAAI,CAAC,MAAM,CAAC,GAAG,CAAC,KAAK,EAAE,SAAS,CAAC,CAAC;QACpC,CAAC;IACH,CAAC;IAED,YAAY,CAAC,KAAqB;QAChC,MAAM,QAAQ,GAAG,IAAI,CAAC,MAAM,CAAC,GAAG,CAAC,KAAK,CAAC,CAAC;QACxC,IAAI,QAAQ,IAAI,IAAI,EAAE,CAAC;YACrB,OAAO,QAAQ,CAAC;QAClB,CAAC;QACD,MAAM,SAAS,GAAG,IAAI,CAAC,aAAa,EAAE,CAAC;QACvC,IAAI,CAAC,MAAM,CAAC,GAAG,CAAC,KAAK,EAAE,SAAS,CAAC,CAAC;QAClC,OAAO,SAAS,CAAC;IACnB,CAAC;IAED,aAAa;QACX,IAAI,IAAI,CAAC,MAAM,CAAC,IAAI,KAAK,CAAC,EAAE,CAAC;YAC3B,OAAO,SAAS,CAAC;QACnB,CAAC;QAED,MAAM,MAAM,GAA2C,EAAE,CAAC;QAC1D,KAAK,MAAM,CAAC,KAAK,EAAE,SAAS,CAAC,IAAI,IAAI,CAAC,MAAM,CAAC,OAAO,EAAE,EAAE,CAAC;YACvD,MAAM,CAAC,SAAS,CAAC,GAAG,KAAK,CAAC;QAC5B,CAAC;QACD,OAAO,MAAM,CAAC;IAChB,CAAC;IAEO,aAAa;QACnB,MAAM,SAAS,GAAG,IAAI,IAAI,CAAC,OAAO,EAAoB,CAAC;QACvD,IAAI,CAAC,OAAO,IAAI,CAAC,CAAC;QAClB,OAAO,SAAS,CAAC;IACnB,CAAC;IAED,MAAM,CAAC,MAAM;QACX,OAAO,IAAI,eAAe,EAAE,CAAC;IAC/B,CAAC;CACF"}
|
|
@@ -1,19 +1,15 @@
|
|
|
1
|
-
import type { AttributePath, AttributeType
|
|
2
|
-
type
|
|
3
|
-
type
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
ExpressionAttributeValues?: Record<ValueReference, AttributeValue>;
|
|
8
|
-
};
|
|
9
|
-
export declare class ConditionExpression {
|
|
10
|
-
private readonly expression;
|
|
11
|
-
private readonly substitutions?;
|
|
12
|
-
private readonly values?;
|
|
1
|
+
import type { AttributePath, AttributeType } from "../../types.js";
|
|
2
|
+
import type { AttributeNames } from "../attributes/names.js";
|
|
3
|
+
import type { AttributeValues } from "../attributes/values.js";
|
|
4
|
+
import type { Expression } from "./expression.js";
|
|
5
|
+
export declare class ConditionExpression implements Expression {
|
|
6
|
+
private readonly inner;
|
|
13
7
|
private constructor();
|
|
14
|
-
|
|
8
|
+
stringify(params: {
|
|
9
|
+
attributeNames: AttributeNames;
|
|
10
|
+
attributeValues: AttributeValues;
|
|
11
|
+
}): string;
|
|
15
12
|
static attributeNotExists(attribute: AttributePath): ConditionExpression;
|
|
16
13
|
static attributeExists(attribute: AttributePath): ConditionExpression;
|
|
17
14
|
static attributeType(attribute: AttributePath, type: AttributeType): ConditionExpression;
|
|
18
15
|
}
|
|
19
|
-
export {};
|
|
@@ -1,112 +1,41 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Represents a set of attribute names used in a condition expression.
|
|
3
|
-
*
|
|
4
|
-
* The uses cases for using attribute names are:
|
|
5
|
-
* - To access an attribute whose name conflicts with a DynamoDB reserved word.
|
|
6
|
-
* - To create a placeholder for repeating occurrences of an attribute name in an expression.
|
|
7
|
-
* - To prevent special characters in an attribute name from being misinterpreted in an expression.
|
|
8
|
-
*/
|
|
9
|
-
class AttributeSubstitutions {
|
|
10
|
-
names;
|
|
11
|
-
constructor() {
|
|
12
|
-
this.names = new Map();
|
|
13
|
-
}
|
|
14
|
-
substitute(attribute) {
|
|
15
|
-
const existing = this.names.get(attribute);
|
|
16
|
-
if (existing != null) {
|
|
17
|
-
return existing;
|
|
18
|
-
}
|
|
19
|
-
const substitute = this.generateSubstitute(attribute);
|
|
20
|
-
this.names.set(attribute, substitute);
|
|
21
|
-
return substitute;
|
|
22
|
-
}
|
|
23
|
-
toAwsInput() {
|
|
24
|
-
const result = {};
|
|
25
|
-
for (const [attribute, substitute] of this.names.entries()) {
|
|
26
|
-
result[substitute] = attribute;
|
|
27
|
-
}
|
|
28
|
-
return result;
|
|
29
|
-
}
|
|
30
|
-
generateSubstitute(attribute) {
|
|
31
|
-
return `#${attribute}`;
|
|
32
|
-
}
|
|
33
|
-
}
|
|
34
|
-
class AttributeValues {
|
|
35
|
-
values;
|
|
36
|
-
counter;
|
|
37
|
-
constructor() {
|
|
38
|
-
this.values = new Map();
|
|
39
|
-
this.counter = 0;
|
|
40
|
-
}
|
|
41
|
-
referenceBy(value) {
|
|
42
|
-
const existing = this.values.get(value);
|
|
43
|
-
if (existing != null) {
|
|
44
|
-
return existing;
|
|
45
|
-
}
|
|
46
|
-
const reference = this.generateReference();
|
|
47
|
-
this.values.set(value, reference);
|
|
48
|
-
return reference;
|
|
49
|
-
}
|
|
50
|
-
toAwsInput() {
|
|
51
|
-
const result = {};
|
|
52
|
-
for (const [value, reference] of this.values.entries()) {
|
|
53
|
-
result[reference] = value;
|
|
54
|
-
}
|
|
55
|
-
return result;
|
|
56
|
-
}
|
|
57
|
-
generateReference() {
|
|
58
|
-
const reference = `:${this.counter}`;
|
|
59
|
-
this.counter += 1;
|
|
60
|
-
return reference;
|
|
61
|
-
}
|
|
62
|
-
}
|
|
63
1
|
export class ConditionExpression {
|
|
64
|
-
|
|
65
|
-
substitutions;
|
|
66
|
-
values;
|
|
2
|
+
inner;
|
|
67
3
|
constructor(params) {
|
|
68
|
-
const {
|
|
69
|
-
this.
|
|
70
|
-
this.substitutions = substitutions;
|
|
71
|
-
this.values = values;
|
|
4
|
+
const { inner } = params;
|
|
5
|
+
this.inner = inner;
|
|
72
6
|
}
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
ConditionExpression: this.expression,
|
|
76
|
-
};
|
|
77
|
-
if (this.substitutions != null) {
|
|
78
|
-
result.ExpressionAttributeNames = this.substitutions.toAwsInput();
|
|
79
|
-
}
|
|
80
|
-
if (this.values != null) {
|
|
81
|
-
result.ExpressionAttributeValues = this.values.toAwsInput();
|
|
82
|
-
}
|
|
83
|
-
return result;
|
|
7
|
+
stringify(params) {
|
|
8
|
+
return this.inner.stringify(params);
|
|
84
9
|
}
|
|
85
10
|
static attributeNotExists(attribute) {
|
|
86
|
-
const substitutions = new AttributeSubstitutions();
|
|
87
|
-
const sub = substitutions.substitute(attribute);
|
|
88
11
|
return new ConditionExpression({
|
|
89
|
-
|
|
90
|
-
|
|
12
|
+
inner: {
|
|
13
|
+
stringify: ({ attributeNames }) => {
|
|
14
|
+
attributeNames.add(attribute);
|
|
15
|
+
return `attribute_not_exists(${attributeNames.getSubstitute(attribute)})`;
|
|
16
|
+
},
|
|
17
|
+
},
|
|
91
18
|
});
|
|
92
19
|
}
|
|
93
20
|
static attributeExists(attribute) {
|
|
94
|
-
const substitutions = new AttributeSubstitutions();
|
|
95
|
-
const sub = substitutions.substitute(attribute);
|
|
96
21
|
return new ConditionExpression({
|
|
97
|
-
|
|
98
|
-
|
|
22
|
+
inner: {
|
|
23
|
+
stringify: ({ attributeNames }) => {
|
|
24
|
+
attributeNames.add(attribute);
|
|
25
|
+
return `attribute_exists(${attributeNames.getSubstitute(attribute)})`;
|
|
26
|
+
},
|
|
27
|
+
},
|
|
99
28
|
});
|
|
100
29
|
}
|
|
101
30
|
static attributeType(attribute, type) {
|
|
102
|
-
const substitutions = new AttributeSubstitutions();
|
|
103
|
-
const sub = substitutions.substitute(attribute);
|
|
104
|
-
const values = new AttributeValues();
|
|
105
|
-
const valueRef = values.referenceBy(type);
|
|
106
31
|
return new ConditionExpression({
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
32
|
+
inner: {
|
|
33
|
+
stringify: ({ attributeNames, attributeValues }) => {
|
|
34
|
+
attributeNames.add(attribute);
|
|
35
|
+
attributeValues.add(type);
|
|
36
|
+
return `attribute_type(${attributeNames.getSubstitute(attribute)}, ${attributeValues.getReference(type)})`;
|
|
37
|
+
},
|
|
38
|
+
},
|
|
110
39
|
});
|
|
111
40
|
}
|
|
112
41
|
}
|
|
@@ -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":"AAKA,MAAM,OAAO,mBAAmB;IACb,KAAK,CAAa;IAEnC,YAAoB,MAA6B;QAC/C,MAAM,EAAE,KAAK,EAAE,GAAG,MAAM,CAAC;QACzB,IAAI,CAAC,KAAK,GAAG,KAAK,CAAC;IACrB,CAAC;IAED,SAAS,CAAC,MAGT;QACC,OAAO,IAAI,CAAC,KAAK,CAAC,SAAS,CAAC,MAAM,CAAC,CAAC;IACtC,CAAC;IAED,MAAM,CAAC,kBAAkB,CAAC,SAAwB;QAChD,OAAO,IAAI,mBAAmB,CAAC;YAC7B,KAAK,EAAE;gBACL,SAAS,EAAE,CAAC,EAAE,cAAc,EAAE,EAAE,EAAE;oBAChC,cAAc,CAAC,GAAG,CAAC,SAAS,CAAC,CAAC;oBAC9B,OAAO,wBAAwB,cAAc,CAAC,aAAa,CAAC,SAAS,CAAC,GAAG,CAAC;gBAC5E,CAAC;aACF;SACF,CAAC,CAAC;IACL,CAAC;IAED,MAAM,CAAC,eAAe,CAAC,SAAwB;QAC7C,OAAO,IAAI,mBAAmB,CAAC;YAC7B,KAAK,EAAE;gBACL,SAAS,EAAE,CAAC,EAAE,cAAc,EAAE,EAAE,EAAE;oBAChC,cAAc,CAAC,GAAG,CAAC,SAAS,CAAC,CAAC;oBAC9B,OAAO,oBAAoB,cAAc,CAAC,aAAa,CAAC,SAAS,CAAC,GAAG,CAAC;gBACxE,CAAC;aACF;SACF,CAAC,CAAC;IACL,CAAC;IAED,MAAM,CAAC,aAAa,CAClB,SAAwB,EACxB,IAAmB;QAEnB,OAAO,IAAI,mBAAmB,CAAC;YAC7B,KAAK,EAAE;gBACL,SAAS,EAAE,CAAC,EAAE,cAAc,EAAE,eAAe,EAAE,EAAE,EAAE;oBACjD,cAAc,CAAC,GAAG,CAAC,SAAS,CAAC,CAAC;oBAC9B,eAAe,CAAC,GAAG,CAAC,IAAI,CAAC,CAAC;oBAC1B,OAAO,kBAAkB,cAAc,CAAC,aAAa,CAAC,SAAS,CAAC,KAAK,eAAe,CAAC,YAAY,CAAC,IAAI,CAAC,GAAG,CAAC;gBAC7G,CAAC;aACF;SACF,CAAC,CAAC;IACL,CAAC;CACF"}
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import type { AttributeNames } from "../attributes/names.js";
|
|
2
|
+
import type { AttributeValues } from "../attributes/values.js";
|
|
3
|
+
export interface Expression {
|
|
4
|
+
stringify(params: {
|
|
5
|
+
attributeNames: AttributeNames;
|
|
6
|
+
attributeValues: AttributeValues;
|
|
7
|
+
}): string;
|
|
8
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"expression.js","sourceRoot":"","sources":["../../../../src/commands/expressions/expression.ts"],"names":[],"mappings":""}
|
|
@@ -1,4 +1,6 @@
|
|
|
1
1
|
import { PutCommand } from "@aws-sdk/lib-dynamodb";
|
|
2
|
+
import { AttributeNames } from "./attributes/names.js";
|
|
3
|
+
import { AttributeValues } from "./attributes/values.js";
|
|
2
4
|
export class PutItem {
|
|
3
5
|
table;
|
|
4
6
|
item;
|
|
@@ -11,11 +13,27 @@ export class PutItem {
|
|
|
11
13
|
}
|
|
12
14
|
toAwsCommandInput() {
|
|
13
15
|
const { table, item, condition } = this;
|
|
14
|
-
const
|
|
15
|
-
return {
|
|
16
|
+
const input = {
|
|
16
17
|
TableName: table,
|
|
17
18
|
Item: item,
|
|
18
|
-
|
|
19
|
+
};
|
|
20
|
+
// Expression attribute names and values can only be specified when a condition is provided,
|
|
21
|
+
// which is optional.
|
|
22
|
+
if (condition == null) {
|
|
23
|
+
return input;
|
|
24
|
+
}
|
|
25
|
+
const attributeNames = AttributeNames.create();
|
|
26
|
+
const attributeValues = AttributeValues.create();
|
|
27
|
+
// Ask the expression to stringify itself, applying the substitutions by itself.
|
|
28
|
+
const expression = condition.stringify({
|
|
29
|
+
attributeNames,
|
|
30
|
+
attributeValues,
|
|
31
|
+
});
|
|
32
|
+
return {
|
|
33
|
+
...input,
|
|
34
|
+
ConditionExpression: expression,
|
|
35
|
+
ExpressionAttributeNames: attributeNames.getSubstitutions(),
|
|
36
|
+
ExpressionAttributeValues: attributeValues.getReferences(),
|
|
19
37
|
};
|
|
20
38
|
}
|
|
21
39
|
toAwsCommand() {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"put-item.js","sourceRoot":"","sources":["../../../src/commands/put-item.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAwB,MAAM,uBAAuB,CAAC;
|
|
1
|
+
{"version":3,"file":"put-item.js","sourceRoot":"","sources":["../../../src/commands/put-item.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAwB,MAAM,uBAAuB,CAAC;AAEzE,OAAO,EAAE,cAAc,EAAE,MAAM,uBAAuB,CAAC;AACvD,OAAO,EAAE,eAAe,EAAE,MAAM,wBAAwB,CAAC;AAUzD,MAAM,OAAO,OAAO;IACD,KAAK,CAAS;IACd,IAAI,CAAa;IACjB,SAAS,CAAuB;IAEjD,YAAoB,MAAqB;QACvC,MAAM,EAAE,KAAK,EAAE,IAAI,EAAE,SAAS,EAAE,GAAG,MAAM,CAAC;QAC1C,IAAI,CAAC,KAAK,GAAG,KAAK,CAAC;QACnB,IAAI,CAAC,IAAI,GAAG,IAAI,CAAC;QACjB,IAAI,CAAC,SAAS,GAAG,SAAS,CAAC;IAC7B,CAAC;IAED,iBAAiB;QACf,MAAM,EAAE,KAAK,EAAE,IAAI,EAAE,SAAS,EAAE,GAAG,IAAI,CAAC;QAExC,MAAM,KAAK,GAAoB;YAC7B,SAAS,EAAE,KAAK;YAChB,IAAI,EAAE,IAAI;SACX,CAAC;QAEF,4FAA4F;QAC5F,qBAAqB;QACrB,IAAI,SAAS,IAAI,IAAI,EAAE,CAAC;YACtB,OAAO,KAAK,CAAC;QACf,CAAC;QAED,MAAM,cAAc,GAAG,cAAc,CAAC,MAAM,EAAE,CAAC;QAC/C,MAAM,eAAe,GAAG,eAAe,CAAC,MAAM,EAAE,CAAC;QACjD,gFAAgF;QAChF,MAAM,UAAU,GAAG,SAAS,CAAC,SAAS,CAAC;YACrC,cAAc;YACd,eAAe;SAChB,CAAC,CAAC;QAEH,OAAO;YACL,GAAG,KAAK;YACR,mBAAmB,EAAE,UAAU;YAC/B,wBAAwB,EAAE,cAAc,CAAC,gBAAgB,EAAE;YAC3D,yBAAyB,EAAE,eAAe,CAAC,aAAa,EAAE;SAC3D,CAAC;IACJ,CAAC;IAED,YAAY;QACV,OAAO,IAAI,UAAU,CAAC,IAAI,CAAC,iBAAiB,EAAE,CAAC,CAAC;IAClD,CAAC;IAED,MAAM,CAAC,IAAI,CAAC,MAAqB;QAC/B,OAAO,IAAI,OAAO,CAAC,MAAM,CAAC,CAAC;IAC7B,CAAC;CACF"}
|
package/lib/esm/types.d.ts
CHANGED
|
@@ -8,7 +8,7 @@ export interface Attribute {
|
|
|
8
8
|
name: AttributeName;
|
|
9
9
|
value: AttributeValue;
|
|
10
10
|
}
|
|
11
|
-
export type Attributes = Record<AttributeName,
|
|
11
|
+
export type Attributes = Record<AttributeName, AttributeValue>;
|
|
12
12
|
export type IndexFieldType = ScalarAttributeType;
|
|
13
13
|
export interface IndexField {
|
|
14
14
|
name: string;
|