dyno-table 1.3.0 → 1.4.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/README.md +3 -6
- package/dist/{builder-types-C_PDZhnP.d.ts → builder-types-B_tCpn9F.d.ts} +2 -1
- package/dist/{builder-types-DtwbqMeF.d.cts → builder-types-DlaUSc-b.d.cts} +2 -1
- package/dist/builders/condition-check-builder.cjs +22 -0
- package/dist/builders/condition-check-builder.cjs.map +1 -1
- package/dist/builders/condition-check-builder.d.cts +2 -2
- package/dist/builders/condition-check-builder.d.ts +2 -2
- package/dist/builders/condition-check-builder.js +22 -0
- package/dist/builders/condition-check-builder.js.map +1 -1
- package/dist/builders/delete-builder.cjs +22 -0
- package/dist/builders/delete-builder.cjs.map +1 -1
- package/dist/builders/delete-builder.d.cts +2 -2
- package/dist/builders/delete-builder.d.ts +2 -2
- package/dist/builders/delete-builder.js +22 -0
- package/dist/builders/delete-builder.js.map +1 -1
- package/dist/builders/paginator.d.cts +1 -1
- package/dist/builders/paginator.d.ts +1 -1
- package/dist/builders/put-builder.cjs +30 -2
- package/dist/builders/put-builder.cjs.map +1 -1
- package/dist/builders/put-builder.d.cts +14 -7
- package/dist/builders/put-builder.d.ts +14 -7
- package/dist/builders/put-builder.js +30 -2
- package/dist/builders/put-builder.js.map +1 -1
- package/dist/builders/query-builder.cjs +6 -0
- package/dist/builders/query-builder.cjs.map +1 -1
- package/dist/builders/query-builder.d.cts +3 -3
- package/dist/builders/query-builder.d.ts +3 -3
- package/dist/builders/query-builder.js +6 -0
- package/dist/builders/query-builder.js.map +1 -1
- package/dist/builders/transaction-builder.cjs +16 -0
- package/dist/builders/transaction-builder.cjs.map +1 -1
- package/dist/builders/transaction-builder.d.cts +2 -2
- package/dist/builders/transaction-builder.d.ts +2 -2
- package/dist/builders/transaction-builder.js +16 -0
- package/dist/builders/transaction-builder.js.map +1 -1
- package/dist/builders/update-builder.cjs +22 -0
- package/dist/builders/update-builder.cjs.map +1 -1
- package/dist/builders/update-builder.d.cts +2 -2
- package/dist/builders/update-builder.d.ts +2 -2
- package/dist/builders/update-builder.js +22 -0
- package/dist/builders/update-builder.js.map +1 -1
- package/dist/conditions-BIpBkh4m.d.ts +729 -0
- package/dist/conditions-x6kGWMR7.d.cts +729 -0
- package/dist/conditions.cjs +6 -0
- package/dist/conditions.cjs.map +1 -1
- package/dist/conditions.d.cts +1 -1
- package/dist/conditions.d.ts +1 -1
- package/dist/conditions.js +6 -1
- package/dist/conditions.js.map +1 -1
- package/dist/entity.cjs.map +1 -1
- package/dist/entity.d.cts +4 -4
- package/dist/entity.d.ts +4 -4
- package/dist/entity.js.map +1 -1
- package/dist/{query-builder-D2FM9rsu.d.cts → query-builder-Dg9Loeco.d.cts} +2 -2
- package/dist/{query-builder-Csror9Iu.d.ts → query-builder-H9Dn0qaS.d.ts} +2 -2
- package/dist/{table-CM56NptV.d.cts → table-CmIQe-jD.d.cts} +30 -5
- package/dist/{table-B3fvMnkB.d.ts → table-TI4ULfra.d.ts} +30 -5
- package/dist/table.cjs +68 -8
- package/dist/table.cjs.map +1 -1
- package/dist/table.d.cts +4 -4
- package/dist/table.d.ts +4 -4
- package/dist/table.js +68 -8
- package/dist/table.js.map +1 -1
- package/package.json +1 -1
- package/dist/conditions--ld9a78i.d.ts +0 -331
- package/dist/conditions-ChhQWd6z.d.cts +0 -331
package/dist/table.d.cts
CHANGED
|
@@ -1,12 +1,12 @@
|
|
|
1
1
|
import './types.cjs';
|
|
2
|
-
import './conditions-
|
|
3
|
-
import './query-builder-
|
|
2
|
+
import './conditions-x6kGWMR7.cjs';
|
|
3
|
+
import './query-builder-Dg9Loeco.cjs';
|
|
4
4
|
import './builders/put-builder.cjs';
|
|
5
5
|
import './builders/delete-builder.cjs';
|
|
6
6
|
import './builders/update-builder.cjs';
|
|
7
7
|
import './builders/transaction-builder.cjs';
|
|
8
|
-
export { T as Table } from './table-
|
|
8
|
+
export { T as Table } from './table-CmIQe-jD.cjs';
|
|
9
9
|
import './builders/condition-check-builder.cjs';
|
|
10
10
|
import '@aws-sdk/lib-dynamodb';
|
|
11
11
|
import './builders/paginator.cjs';
|
|
12
|
-
import './builder-types-
|
|
12
|
+
import './builder-types-DlaUSc-b.cjs';
|
package/dist/table.d.ts
CHANGED
|
@@ -1,12 +1,12 @@
|
|
|
1
1
|
import './types.js';
|
|
2
|
-
import './conditions
|
|
3
|
-
import './query-builder-
|
|
2
|
+
import './conditions-BIpBkh4m.js';
|
|
3
|
+
import './query-builder-H9Dn0qaS.js';
|
|
4
4
|
import './builders/put-builder.js';
|
|
5
5
|
import './builders/delete-builder.js';
|
|
6
6
|
import './builders/update-builder.js';
|
|
7
7
|
import './builders/transaction-builder.js';
|
|
8
|
-
export { T as Table } from './table-
|
|
8
|
+
export { T as Table } from './table-TI4ULfra.js';
|
|
9
9
|
import './builders/condition-check-builder.js';
|
|
10
10
|
import '@aws-sdk/lib-dynamodb';
|
|
11
11
|
import './builders/paginator.js';
|
|
12
|
-
import './builder-types-
|
|
12
|
+
import './builder-types-B_tCpn9F.js';
|
package/dist/table.js
CHANGED
|
@@ -15,6 +15,11 @@ var between = (attr, lower, upper) => ({
|
|
|
15
15
|
attr,
|
|
16
16
|
value: [lower, upper]
|
|
17
17
|
});
|
|
18
|
+
var inArray = (attr, values) => ({
|
|
19
|
+
type: "in",
|
|
20
|
+
attr,
|
|
21
|
+
value: values
|
|
22
|
+
});
|
|
18
23
|
var beginsWith = createComparisonCondition("beginsWith");
|
|
19
24
|
var contains = createComparisonCondition("contains");
|
|
20
25
|
var attributeExists = (attr) => ({
|
|
@@ -84,6 +89,21 @@ var buildBetweenExpression = (condition, params) => {
|
|
|
84
89
|
const upperName = generateValueName(params, condition.value[1]);
|
|
85
90
|
return `${attrName} BETWEEN ${lowerName} AND ${upperName}`;
|
|
86
91
|
};
|
|
92
|
+
var buildInExpression = (condition, params) => {
|
|
93
|
+
validateCondition(condition);
|
|
94
|
+
if (!condition.attr) {
|
|
95
|
+
throw new Error(`Attribute is required for ${condition.type} condition`);
|
|
96
|
+
}
|
|
97
|
+
if (!Array.isArray(condition.value) || condition.value.length === 0) {
|
|
98
|
+
throw new Error("In condition requires a non-empty array of values");
|
|
99
|
+
}
|
|
100
|
+
if (condition.value.length > 100) {
|
|
101
|
+
throw new Error("In condition supports a maximum of 100 values");
|
|
102
|
+
}
|
|
103
|
+
const attrName = generateAttributeName(params, condition.attr);
|
|
104
|
+
const valueNames = condition.value.map((value) => generateValueName(params, value));
|
|
105
|
+
return `${attrName} IN (${valueNames.join(", ")})`;
|
|
106
|
+
};
|
|
87
107
|
var buildFunctionExpression = (functionName, condition, params) => {
|
|
88
108
|
validateCondition(condition);
|
|
89
109
|
if (!condition.attr) {
|
|
@@ -119,6 +139,7 @@ var buildExpression = (condition, params) => {
|
|
|
119
139
|
gt: () => buildComparisonExpression(condition, ">", params),
|
|
120
140
|
gte: () => buildComparisonExpression(condition, ">=", params),
|
|
121
141
|
between: () => buildBetweenExpression(condition, params),
|
|
142
|
+
in: () => buildInExpression(condition, params),
|
|
122
143
|
beginsWith: () => buildFunctionExpression("begins_with", condition, params),
|
|
123
144
|
contains: () => buildFunctionExpression("contains", condition, params),
|
|
124
145
|
attributeExists: () => buildAttributeFunction("attribute_exists", condition, params),
|
|
@@ -513,6 +534,7 @@ var FilterBuilder = class {
|
|
|
513
534
|
gt,
|
|
514
535
|
gte,
|
|
515
536
|
between,
|
|
537
|
+
inArray,
|
|
516
538
|
beginsWith,
|
|
517
539
|
contains,
|
|
518
540
|
attributeExists,
|
|
@@ -936,6 +958,7 @@ var PutBuilder = class {
|
|
|
936
958
|
gt,
|
|
937
959
|
gte,
|
|
938
960
|
between,
|
|
961
|
+
inArray,
|
|
939
962
|
beginsWith,
|
|
940
963
|
contains,
|
|
941
964
|
attributeExists,
|
|
@@ -956,7 +979,8 @@ var PutBuilder = class {
|
|
|
956
979
|
* @options
|
|
957
980
|
* - NONE: No return value
|
|
958
981
|
* - ALL_OLD: Returns the item's previous state if it existed, no read capacity units are consumed
|
|
959
|
-
* - CONSISTENT:
|
|
982
|
+
* - CONSISTENT: Performs a GET operation after the put to retrieve the item's new state
|
|
983
|
+
* - INPUT: Returns the input values that were passed to the operation
|
|
960
984
|
*
|
|
961
985
|
* @example
|
|
962
986
|
* ```ts
|
|
@@ -975,9 +999,14 @@ var PutBuilder = class {
|
|
|
975
999
|
* }
|
|
976
1000
|
* });
|
|
977
1001
|
* }
|
|
1002
|
+
*
|
|
1003
|
+
* // Return input values for create operations
|
|
1004
|
+
* const createResult = await builder
|
|
1005
|
+
* .returnValues('INPUT')
|
|
1006
|
+
* .execute();
|
|
978
1007
|
* ```
|
|
979
1008
|
*
|
|
980
|
-
* @param returnValues - Use 'ALL_OLD' to return previous values
|
|
1009
|
+
* @param returnValues - Use 'ALL_OLD' to return previous values, 'INPUT' to return input values, 'CONSISTENT' for fresh data, or 'NONE' (default).
|
|
981
1010
|
* @returns The builder instance for method chaining
|
|
982
1011
|
*/
|
|
983
1012
|
returnValues(returnValues) {
|
|
@@ -1148,6 +1177,7 @@ var DeleteBuilder = class {
|
|
|
1148
1177
|
gt,
|
|
1149
1178
|
gte,
|
|
1150
1179
|
between,
|
|
1180
|
+
inArray,
|
|
1151
1181
|
beginsWith,
|
|
1152
1182
|
contains,
|
|
1153
1183
|
attributeExists,
|
|
@@ -1452,6 +1482,7 @@ var UpdateBuilder = class {
|
|
|
1452
1482
|
gt,
|
|
1453
1483
|
gte,
|
|
1454
1484
|
between,
|
|
1485
|
+
inArray,
|
|
1455
1486
|
beginsWith,
|
|
1456
1487
|
contains,
|
|
1457
1488
|
attributeExists,
|
|
@@ -2496,6 +2527,7 @@ var ConditionCheckBuilder = class {
|
|
|
2496
2527
|
gt,
|
|
2497
2528
|
gte,
|
|
2498
2529
|
between,
|
|
2530
|
+
inArray,
|
|
2499
2531
|
beginsWith,
|
|
2500
2532
|
contains,
|
|
2501
2533
|
attributeExists,
|
|
@@ -2823,13 +2855,38 @@ var Table = class {
|
|
|
2823
2855
|
return primaryCondition;
|
|
2824
2856
|
}
|
|
2825
2857
|
/**
|
|
2826
|
-
* Creates a new item in the table, it will fail if the item already exists
|
|
2858
|
+
* Creates a new item in the table, it will fail if the item already exists.
|
|
2859
|
+
*
|
|
2860
|
+
* By default, this method returns the input values passed to the create operation
|
|
2861
|
+
* upon successful creation.
|
|
2862
|
+
*
|
|
2863
|
+
* You can customise the return behaviour by chaining the `.returnValues()` method:
|
|
2827
2864
|
*
|
|
2828
2865
|
* @param item The item to create
|
|
2829
|
-
* @returns A PutBuilder instance for chaining conditions and executing the
|
|
2866
|
+
* @returns A PutBuilder instance for chaining additional conditions and executing the create operation
|
|
2867
|
+
*
|
|
2868
|
+
* @example
|
|
2869
|
+
* ```ts
|
|
2870
|
+
* // Create with default behavior (returns input values)
|
|
2871
|
+
* const result = await table.create({
|
|
2872
|
+
* id: 'user-123',
|
|
2873
|
+
* name: 'John Doe',
|
|
2874
|
+
* email: 'john@example.com'
|
|
2875
|
+
* }).execute();
|
|
2876
|
+
* console.log(result); // Returns the input object
|
|
2877
|
+
*
|
|
2878
|
+
* // Create with no return value for better performance
|
|
2879
|
+
* await table.create(userData).returnValues('NONE').execute();
|
|
2880
|
+
*
|
|
2881
|
+
* // Create and get fresh data from dynamodb using a strongly consistent read
|
|
2882
|
+
* const freshData = await table.create(userData).returnValues('CONSISTENT').execute();
|
|
2883
|
+
*
|
|
2884
|
+
* // Create and get previous values (if the item was overwritten)
|
|
2885
|
+
* const oldData = await table.create(userData).returnValues('ALL_OLD').execute();
|
|
2886
|
+
* ```
|
|
2830
2887
|
*/
|
|
2831
2888
|
create(item) {
|
|
2832
|
-
return this.put(item).condition((op) => op.attributeNotExists(this.partitionKey));
|
|
2889
|
+
return this.put(item).condition((op) => op.attributeNotExists(this.partitionKey)).returnValues("INPUT");
|
|
2833
2890
|
}
|
|
2834
2891
|
get(keyCondition) {
|
|
2835
2892
|
const executor = async (params) => {
|
|
@@ -2866,10 +2923,13 @@ var Table = class {
|
|
|
2866
2923
|
ConditionExpression: params.conditionExpression,
|
|
2867
2924
|
ExpressionAttributeNames: params.expressionAttributeNames,
|
|
2868
2925
|
ExpressionAttributeValues: params.expressionAttributeValues,
|
|
2869
|
-
// CONSISTENT
|
|
2870
|
-
// response and will be
|
|
2871
|
-
ReturnValues: params.returnValues === "CONSISTENT" ? "NONE" : params.returnValues
|
|
2926
|
+
// CONSISTENT and INPUT are not valid ReturnValues for DDB, so we set NONE as we are not interested in its
|
|
2927
|
+
// response and will be handling these cases separately
|
|
2928
|
+
ReturnValues: params.returnValues === "CONSISTENT" || params.returnValues === "INPUT" ? "NONE" : params.returnValues
|
|
2872
2929
|
});
|
|
2930
|
+
if (params.returnValues === "INPUT") {
|
|
2931
|
+
return params.item;
|
|
2932
|
+
}
|
|
2873
2933
|
if (params.returnValues === "CONSISTENT") {
|
|
2874
2934
|
const getResult = await this.dynamoClient.get({
|
|
2875
2935
|
TableName: params.tableName,
|