dyno-table 2.1.0 → 2.1.1
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 +116 -0
- package/dist/builders/query-builder.cjs +44 -21
- package/dist/builders/query-builder.cjs.map +1 -1
- package/dist/builders/query-builder.d.cts +1 -1
- package/dist/builders/query-builder.d.ts +1 -1
- package/dist/builders/query-builder.js +44 -21
- package/dist/builders/query-builder.js.map +1 -1
- package/dist/entity.cjs +18 -19
- package/dist/entity.cjs.map +1 -1
- package/dist/entity.d.cts +2 -2
- package/dist/entity.d.ts +2 -2
- package/dist/entity.js +18 -19
- package/dist/entity.js.map +1 -1
- package/dist/index.cjs +76 -41
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +2 -2
- package/dist/index.d.ts +2 -2
- package/dist/index.js +76 -41
- package/dist/index.js.map +1 -1
- package/dist/{query-builder-BNWRCrJW.d.ts → query-builder-CUWdavZw.d.ts} +2 -0
- package/dist/{query-builder-DZ9JKgBN.d.cts → query-builder-DoZzZz_c.d.cts} +2 -0
- package/dist/{table-BhEeYauU.d.ts → table-4UxlW_wD.d.ts} +2 -1
- package/dist/{table-BpNOboD9.d.cts → table-D-xNCVFa.d.cts} +2 -1
- package/dist/table.cjs +58 -22
- package/dist/table.cjs.map +1 -1
- package/dist/table.d.cts +2 -2
- package/dist/table.d.ts +2 -2
- package/dist/table.js +58 -22
- package/dist/table.js.map +1 -1
- package/package.json +1 -1
package/dist/index.d.cts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
export { T as Table } from './table-
|
|
1
|
+
export { T as Table } from './table-D-xNCVFa.cjs';
|
|
2
2
|
export { EntityConfig, EntityRepository, IndexDefinition, QueryEntity, QueryRecord, createIndex, createQueries, defineEntity } from './entity.cjs';
|
|
3
3
|
export { p as ComparisonOperator, C as Condition, q as ConditionOperator, E as ExpressionParams, K as KeyConditionOperator, L as LogicalOperator, P as PrimaryKey, r as PrimaryKeyWithoutExpression, k as and, h as attributeExists, j as attributeNotExists, d as beginsWith, c as between, f as contains, e as eq, g as gt, b as gte, i as inArray, l as lt, a as lte, n as ne, m as not, o as or } from './conditions-CC3NDfUU.cjs';
|
|
4
|
-
export { Q as QueryBuilder, a as QueryOptions } from './query-builder-
|
|
4
|
+
export { Q as QueryBuilder, a as QueryOptions } from './query-builder-DoZzZz_c.cjs';
|
|
5
5
|
export { PutBuilder, PutOptions } from './builders/put-builder.cjs';
|
|
6
6
|
export { UpdateBuilder, UpdateOptions } from './builders/update-builder.cjs';
|
|
7
7
|
export { DeleteBuilder, DeleteOptions } from './builders/delete-builder.cjs';
|
package/dist/index.d.ts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
export { T as Table } from './table-
|
|
1
|
+
export { T as Table } from './table-4UxlW_wD.js';
|
|
2
2
|
export { EntityConfig, EntityRepository, IndexDefinition, QueryEntity, QueryRecord, createIndex, createQueries, defineEntity } from './entity.js';
|
|
3
3
|
export { p as ComparisonOperator, C as Condition, q as ConditionOperator, E as ExpressionParams, K as KeyConditionOperator, L as LogicalOperator, P as PrimaryKey, r as PrimaryKeyWithoutExpression, k as and, h as attributeExists, j as attributeNotExists, d as beginsWith, c as between, f as contains, e as eq, g as gt, b as gte, i as inArray, l as lt, a as lte, n as ne, m as not, o as or } from './conditions-DD0bvyHm.js';
|
|
4
|
-
export { Q as QueryBuilder, a as QueryOptions } from './query-builder-
|
|
4
|
+
export { Q as QueryBuilder, a as QueryOptions } from './query-builder-CUWdavZw.js';
|
|
5
5
|
export { PutBuilder, PutOptions } from './builders/put-builder.js';
|
|
6
6
|
export { UpdateBuilder, UpdateOptions } from './builders/update-builder.js';
|
|
7
7
|
export { DeleteBuilder, DeleteOptions } from './builders/delete-builder.js';
|
package/dist/index.js
CHANGED
|
@@ -519,30 +519,40 @@ var FilterBuilder = class {
|
|
|
519
519
|
* @returns The builder instance for method chaining
|
|
520
520
|
*/
|
|
521
521
|
filter(condition) {
|
|
522
|
-
|
|
523
|
-
|
|
524
|
-
|
|
525
|
-
|
|
526
|
-
|
|
527
|
-
|
|
528
|
-
|
|
529
|
-
|
|
530
|
-
|
|
531
|
-
|
|
532
|
-
beginsWith,
|
|
533
|
-
contains,
|
|
534
|
-
attributeExists,
|
|
535
|
-
attributeNotExists,
|
|
536
|
-
and,
|
|
537
|
-
or,
|
|
538
|
-
not
|
|
539
|
-
};
|
|
540
|
-
this.options.filter = condition(conditionOperator);
|
|
522
|
+
const newCondition = typeof condition === "function" ? condition(this.getConditionOperator()) : condition;
|
|
523
|
+
if (this.options.filter) {
|
|
524
|
+
if (this.options.filter.type === "and" && this.options.filter.conditions) {
|
|
525
|
+
this.options.filter = {
|
|
526
|
+
type: "and",
|
|
527
|
+
conditions: [...this.options.filter.conditions, newCondition]
|
|
528
|
+
};
|
|
529
|
+
} else {
|
|
530
|
+
this.options.filter = and(this.options.filter, newCondition);
|
|
531
|
+
}
|
|
541
532
|
} else {
|
|
542
|
-
this.options.filter =
|
|
533
|
+
this.options.filter = newCondition;
|
|
543
534
|
}
|
|
544
535
|
return this;
|
|
545
536
|
}
|
|
537
|
+
getConditionOperator() {
|
|
538
|
+
return {
|
|
539
|
+
eq,
|
|
540
|
+
ne,
|
|
541
|
+
lt,
|
|
542
|
+
lte,
|
|
543
|
+
gt,
|
|
544
|
+
gte,
|
|
545
|
+
between,
|
|
546
|
+
inArray,
|
|
547
|
+
beginsWith,
|
|
548
|
+
contains,
|
|
549
|
+
attributeExists,
|
|
550
|
+
attributeNotExists,
|
|
551
|
+
and,
|
|
552
|
+
or,
|
|
553
|
+
not
|
|
554
|
+
};
|
|
555
|
+
}
|
|
546
556
|
/**
|
|
547
557
|
* Specifies which attributes to return in the results.
|
|
548
558
|
*
|
|
@@ -833,10 +843,23 @@ var QueryBuilder = class _QueryBuilder extends FilterBuilder {
|
|
|
833
843
|
*/
|
|
834
844
|
clone() {
|
|
835
845
|
const clone = new _QueryBuilder(this.executor, this.keyCondition);
|
|
836
|
-
clone.options = {
|
|
846
|
+
clone.options = {
|
|
847
|
+
...this.options,
|
|
848
|
+
filter: this.deepCloneFilter(this.options.filter)
|
|
849
|
+
};
|
|
837
850
|
clone.selectedFields = new Set(this.selectedFields);
|
|
838
851
|
return clone;
|
|
839
852
|
}
|
|
853
|
+
deepCloneFilter(filter) {
|
|
854
|
+
if (!filter) return filter;
|
|
855
|
+
if (filter.type === "and" || filter.type === "or") {
|
|
856
|
+
return {
|
|
857
|
+
...filter,
|
|
858
|
+
conditions: filter.conditions?.map((condition) => this.deepCloneFilter(condition)).filter((c) => c !== void 0)
|
|
859
|
+
};
|
|
860
|
+
}
|
|
861
|
+
return { ...filter };
|
|
862
|
+
}
|
|
840
863
|
/**
|
|
841
864
|
* Executes the query against DynamoDB and returns a generator that behaves like an array.
|
|
842
865
|
*
|
|
@@ -3155,10 +3178,23 @@ var ScanBuilder = class _ScanBuilder extends FilterBuilder {
|
|
|
3155
3178
|
*/
|
|
3156
3179
|
clone() {
|
|
3157
3180
|
const clone = new _ScanBuilder(this.executor);
|
|
3158
|
-
clone.options = {
|
|
3181
|
+
clone.options = {
|
|
3182
|
+
...this.options,
|
|
3183
|
+
filter: this.deepCloneFilter(this.options.filter)
|
|
3184
|
+
};
|
|
3159
3185
|
clone.selectedFields = new Set(this.selectedFields);
|
|
3160
3186
|
return clone;
|
|
3161
3187
|
}
|
|
3188
|
+
deepCloneFilter(filter) {
|
|
3189
|
+
if (!filter) return filter;
|
|
3190
|
+
if (filter.type === "and" || filter.type === "or") {
|
|
3191
|
+
return {
|
|
3192
|
+
...filter,
|
|
3193
|
+
conditions: filter.conditions?.map((condition) => this.deepCloneFilter(condition)).filter((c) => c !== void 0)
|
|
3194
|
+
};
|
|
3195
|
+
}
|
|
3196
|
+
return { ...filter };
|
|
3197
|
+
}
|
|
3162
3198
|
/**
|
|
3163
3199
|
* Executes the scan against DynamoDB and returns a generator that behaves like an array.
|
|
3164
3200
|
*
|
|
@@ -3839,31 +3875,30 @@ var IndexBuilder = class {
|
|
|
3839
3875
|
if (!shouldUpdateIndex) {
|
|
3840
3876
|
continue;
|
|
3841
3877
|
}
|
|
3878
|
+
let key;
|
|
3842
3879
|
try {
|
|
3843
|
-
|
|
3844
|
-
if (this.hasUndefinedValues(key)) {
|
|
3845
|
-
throw new Error(
|
|
3846
|
-
`Cannot update entity: insufficient data to regenerate index "${indexName}". All attributes required by the index must be provided in the update operation, or the index must be marked as readOnly.`
|
|
3847
|
-
);
|
|
3848
|
-
}
|
|
3849
|
-
const gsiConfig = this.table.gsis[indexName];
|
|
3850
|
-
if (!gsiConfig) {
|
|
3851
|
-
throw new Error(`GSI configuration not found for index: ${indexName}`);
|
|
3852
|
-
}
|
|
3853
|
-
if (key.pk) {
|
|
3854
|
-
attributes[gsiConfig.partitionKey] = key.pk;
|
|
3855
|
-
}
|
|
3856
|
-
if (key.sk && gsiConfig.sortKey) {
|
|
3857
|
-
attributes[gsiConfig.sortKey] = key.sk;
|
|
3858
|
-
}
|
|
3880
|
+
key = indexDef.generateKey(updatedItem);
|
|
3859
3881
|
} catch (error) {
|
|
3860
|
-
if (error instanceof Error
|
|
3861
|
-
throw error;
|
|
3882
|
+
if (error instanceof Error) {
|
|
3883
|
+
throw new Error(`Missing attributes: ${error.message}`);
|
|
3862
3884
|
}
|
|
3885
|
+
throw error;
|
|
3886
|
+
}
|
|
3887
|
+
if (this.hasUndefinedValues(key)) {
|
|
3863
3888
|
throw new Error(
|
|
3864
|
-
`Cannot update entity: insufficient data to regenerate index "${indexName}". All attributes required by the index must be provided in the update operation, or the index must be readOnly.`
|
|
3889
|
+
`Missing attributes: Cannot update entity: insufficient data to regenerate index "${indexName}". All attributes required by the index must be provided in the update operation, or the index must be marked as readOnly.`
|
|
3865
3890
|
);
|
|
3866
3891
|
}
|
|
3892
|
+
const gsiConfig = this.table.gsis[indexName];
|
|
3893
|
+
if (!gsiConfig) {
|
|
3894
|
+
throw new Error(`GSI configuration not found for index: ${indexName}`);
|
|
3895
|
+
}
|
|
3896
|
+
if (key.pk) {
|
|
3897
|
+
attributes[gsiConfig.partitionKey] = key.pk;
|
|
3898
|
+
}
|
|
3899
|
+
if (key.sk && gsiConfig.sortKey) {
|
|
3900
|
+
attributes[gsiConfig.sortKey] = key.sk;
|
|
3901
|
+
}
|
|
3867
3902
|
}
|
|
3868
3903
|
return attributes;
|
|
3869
3904
|
}
|