dyno-table 1.8.0-next.1 → 2.0.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 +1 -1
- package/dist/{batch-builder-CKYnMRyz.d.cts → batch-builder-CzNAxWNT.d.cts} +2 -2
- package/dist/{batch-builder-BOBwOIUE.d.ts → batch-builder-TpkmiBp5.d.ts} +2 -2
- package/dist/builders/delete-builder.d.cts +1 -1
- package/dist/builders/delete-builder.d.ts +1 -1
- package/dist/builders/put-builder.d.cts +1 -1
- package/dist/builders/put-builder.d.ts +1 -1
- 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.map +1 -1
- package/dist/entity.cjs +61 -95
- package/dist/entity.cjs.map +1 -1
- package/dist/entity.d.cts +3 -3
- package/dist/entity.d.ts +3 -3
- package/dist/entity.js +61 -95
- package/dist/entity.js.map +1 -1
- package/dist/index.cjs +61 -95
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +3 -3
- package/dist/index.d.ts +3 -3
- package/dist/index.js +61 -95
- package/dist/index.js.map +1 -1
- package/dist/{query-builder-DFkxojBM.d.cts → query-builder-BALW-vW_.d.cts} +2 -2
- package/dist/{query-builder-CaHzZmDf.d.ts → query-builder-BK9eM-gt.d.ts} +2 -2
- package/dist/{table-m7DQk5dK.d.ts → table-CEL7Lt1r.d.ts} +2 -2
- package/dist/{table-CHitMHXE.d.cts → table-DhvYVXQ6.d.cts} +2 -2
- package/dist/table.cjs.map +1 -1
- package/dist/table.d.cts +3 -3
- package/dist/table.d.ts +3 -3
- package/dist/table.js.map +1 -1
- package/package.json +1 -1
package/dist/index.d.cts
CHANGED
|
@@ -1,12 +1,12 @@
|
|
|
1
|
-
export { T as Table } from './table-
|
|
1
|
+
export { T as Table } from './table-DhvYVXQ6.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-3ae5znV_.cjs';
|
|
4
|
-
export { Q as QueryBuilder, a as QueryOptions } from './query-builder-
|
|
4
|
+
export { Q as QueryBuilder, a as QueryOptions } from './query-builder-BALW-vW_.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';
|
|
8
8
|
export { TransactionBuilder, TransactionOptions } from './builders/transaction-builder.cjs';
|
|
9
|
-
export { B as BatchBuilder, a as BatchError, b as BatchResult } from './batch-builder-
|
|
9
|
+
export { B as BatchBuilder, a as BatchError, b as BatchResult } from './batch-builder-CzNAxWNT.cjs';
|
|
10
10
|
export { partitionKey, sortKey } from './utils.cjs';
|
|
11
11
|
import './types.cjs';
|
|
12
12
|
import '@aws-sdk/lib-dynamodb';
|
package/dist/index.d.ts
CHANGED
|
@@ -1,12 +1,12 @@
|
|
|
1
|
-
export { T as Table } from './table-
|
|
1
|
+
export { T as Table } from './table-CEL7Lt1r.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-BtynAviC.js';
|
|
4
|
-
export { Q as QueryBuilder, a as QueryOptions } from './query-builder-
|
|
4
|
+
export { Q as QueryBuilder, a as QueryOptions } from './query-builder-BK9eM-gt.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';
|
|
8
8
|
export { TransactionBuilder, TransactionOptions } from './builders/transaction-builder.js';
|
|
9
|
-
export { B as BatchBuilder, a as BatchError, b as BatchResult } from './batch-builder-
|
|
9
|
+
export { B as BatchBuilder, a as BatchError, b as BatchResult } from './batch-builder-TpkmiBp5.js';
|
|
10
10
|
export { partitionKey, sortKey } from './utils.js';
|
|
11
11
|
import './types.js';
|
|
12
12
|
import '@aws-sdk/lib-dynamodb';
|
package/dist/index.js
CHANGED
|
@@ -3756,6 +3756,25 @@ function createEntityAwareDeleteBuilder(builder, entityName) {
|
|
|
3756
3756
|
// src/entity.ts
|
|
3757
3757
|
function defineEntity(config) {
|
|
3758
3758
|
const entityTypeAttributeName = config.settings?.entityTypeAttributeName ?? "entityType";
|
|
3759
|
+
const buildIndexes = (dataForKeyGeneration, table) => {
|
|
3760
|
+
return Object.entries(config.indexes ?? {}).reduce(
|
|
3761
|
+
(acc, [indexName, index]) => {
|
|
3762
|
+
const key = index.generateKey(dataForKeyGeneration);
|
|
3763
|
+
const gsiConfig = table.gsis[indexName];
|
|
3764
|
+
if (!gsiConfig) {
|
|
3765
|
+
throw new Error(`GSI configuration not found for index: ${indexName}`);
|
|
3766
|
+
}
|
|
3767
|
+
if (key.pk) {
|
|
3768
|
+
acc[gsiConfig.partitionKey] = key.pk;
|
|
3769
|
+
}
|
|
3770
|
+
if (key.sk && gsiConfig.sortKey) {
|
|
3771
|
+
acc[gsiConfig.sortKey] = key.sk;
|
|
3772
|
+
}
|
|
3773
|
+
return acc;
|
|
3774
|
+
},
|
|
3775
|
+
{}
|
|
3776
|
+
);
|
|
3777
|
+
};
|
|
3759
3778
|
const wrapMethodWithPreparation = (originalMethod, prepareFn, context) => {
|
|
3760
3779
|
const wrappedMethod = (...args) => {
|
|
3761
3780
|
prepareFn();
|
|
@@ -3774,18 +3793,17 @@ function defineEntity(config) {
|
|
|
3774
3793
|
}
|
|
3775
3794
|
return wrappedMethod;
|
|
3776
3795
|
};
|
|
3777
|
-
const generateTimestamps = (
|
|
3796
|
+
const generateTimestamps = (timestampsToGenerate, data) => {
|
|
3778
3797
|
if (!config.settings?.timestamps) return {};
|
|
3779
3798
|
const timestamps = {};
|
|
3780
3799
|
const now = /* @__PURE__ */ new Date();
|
|
3781
3800
|
const unixTime = Math.floor(Date.now() / 1e3);
|
|
3782
3801
|
const { createdAt, updatedAt } = config.settings.timestamps;
|
|
3783
|
-
|
|
3784
|
-
if (createdAt && typesToGenerate.includes("createdAt")) {
|
|
3802
|
+
if (createdAt && timestampsToGenerate.includes("createdAt") && !data.createdAt) {
|
|
3785
3803
|
const name = createdAt.attributeName ?? "createdAt";
|
|
3786
3804
|
timestamps[name] = createdAt.format === "UNIX" ? unixTime : now.toISOString();
|
|
3787
3805
|
}
|
|
3788
|
-
if (updatedAt &&
|
|
3806
|
+
if (updatedAt && timestampsToGenerate.includes("updatedAt") && !data.updatedAt) {
|
|
3789
3807
|
const name = updatedAt.attributeName ?? "updatedAt";
|
|
3790
3808
|
timestamps[name] = updatedAt.format === "UNIX" ? unixTime : now.toISOString();
|
|
3791
3809
|
}
|
|
@@ -3798,36 +3816,22 @@ function defineEntity(config) {
|
|
|
3798
3816
|
create: (data) => {
|
|
3799
3817
|
const builder = table.create({});
|
|
3800
3818
|
const prepareValidatedItemAsync = async () => {
|
|
3801
|
-
const
|
|
3802
|
-
const validatedData = validationResult instanceof Promise ? await validationResult : validationResult;
|
|
3819
|
+
const validatedData = await config.schema["~standard"].validate(data);
|
|
3803
3820
|
if ("issues" in validatedData && validatedData.issues) {
|
|
3804
3821
|
throw new Error(`Validation failed: ${validatedData.issues.map((i) => i.message).join(", ")}`);
|
|
3805
3822
|
}
|
|
3806
|
-
const
|
|
3807
|
-
const indexes = Object.entries(config.indexes ?? {}).reduce(
|
|
3808
|
-
(acc, [indexName, index]) => {
|
|
3809
|
-
const key = index.generateKey(validatedData.value);
|
|
3810
|
-
const gsiConfig = table.gsis[indexName];
|
|
3811
|
-
if (!gsiConfig) {
|
|
3812
|
-
throw new Error(`GSI configuration not found for index: ${indexName}`);
|
|
3813
|
-
}
|
|
3814
|
-
if (key.pk) {
|
|
3815
|
-
acc[gsiConfig.partitionKey] = key.pk;
|
|
3816
|
-
}
|
|
3817
|
-
if (key.sk && gsiConfig.sortKey) {
|
|
3818
|
-
acc[gsiConfig.sortKey] = key.sk;
|
|
3819
|
-
}
|
|
3820
|
-
return acc;
|
|
3821
|
-
},
|
|
3822
|
-
{}
|
|
3823
|
-
);
|
|
3824
|
-
const validatedItem = {
|
|
3823
|
+
const dataForKeyGeneration = {
|
|
3825
3824
|
...validatedData.value,
|
|
3825
|
+
...generateTimestamps(["createdAt", "updatedAt"], validatedData.value)
|
|
3826
|
+
};
|
|
3827
|
+
const primaryKey = config.primaryKey.generateKey(dataForKeyGeneration);
|
|
3828
|
+
const indexes = buildIndexes(dataForKeyGeneration, table);
|
|
3829
|
+
const validatedItem = {
|
|
3830
|
+
...dataForKeyGeneration,
|
|
3826
3831
|
[entityTypeAttributeName]: config.name,
|
|
3827
3832
|
[table.partitionKey]: primaryKey.pk,
|
|
3828
3833
|
...table.sortKey ? { [table.sortKey]: primaryKey.sk } : {},
|
|
3829
|
-
...indexes
|
|
3830
|
-
...generateTimestamps(["createdAt", "updatedAt"])
|
|
3834
|
+
...indexes
|
|
3831
3835
|
};
|
|
3832
3836
|
Object.assign(builder, { item: validatedItem });
|
|
3833
3837
|
return validatedItem;
|
|
@@ -3836,37 +3840,24 @@ function defineEntity(config) {
|
|
|
3836
3840
|
const validationResult = config.schema["~standard"].validate(data);
|
|
3837
3841
|
if (validationResult instanceof Promise) {
|
|
3838
3842
|
throw new Error(
|
|
3839
|
-
"Async validation is not supported in
|
|
3843
|
+
"Async validation is not supported in withBatch or withTransaction. The schema must support synchronous validation for compatibility."
|
|
3840
3844
|
);
|
|
3841
3845
|
}
|
|
3842
3846
|
if ("issues" in validationResult && validationResult.issues) {
|
|
3843
3847
|
throw new Error(`Validation failed: ${validationResult.issues.map((i) => i.message).join(", ")}`);
|
|
3844
3848
|
}
|
|
3845
|
-
const
|
|
3846
|
-
const indexes = Object.entries(config.indexes ?? {}).reduce(
|
|
3847
|
-
(acc, [indexName, index]) => {
|
|
3848
|
-
const key = index.generateKey(validationResult.value);
|
|
3849
|
-
const gsiConfig = table.gsis[indexName];
|
|
3850
|
-
if (!gsiConfig) {
|
|
3851
|
-
throw new Error(`GSI configuration not found for index: ${indexName}`);
|
|
3852
|
-
}
|
|
3853
|
-
if (key.pk) {
|
|
3854
|
-
acc[gsiConfig.partitionKey] = key.pk;
|
|
3855
|
-
}
|
|
3856
|
-
if (key.sk && gsiConfig.sortKey) {
|
|
3857
|
-
acc[gsiConfig.sortKey] = key.sk;
|
|
3858
|
-
}
|
|
3859
|
-
return acc;
|
|
3860
|
-
},
|
|
3861
|
-
{}
|
|
3862
|
-
);
|
|
3863
|
-
const validatedItem = {
|
|
3849
|
+
const dataForKeyGeneration = {
|
|
3864
3850
|
...validationResult.value,
|
|
3851
|
+
...generateTimestamps(["createdAt", "updatedAt"], validationResult.value)
|
|
3852
|
+
};
|
|
3853
|
+
const primaryKey = config.primaryKey.generateKey(dataForKeyGeneration);
|
|
3854
|
+
const indexes = buildIndexes(dataForKeyGeneration, table);
|
|
3855
|
+
const validatedItem = {
|
|
3856
|
+
...dataForKeyGeneration,
|
|
3865
3857
|
[entityTypeAttributeName]: config.name,
|
|
3866
3858
|
[table.partitionKey]: primaryKey.pk,
|
|
3867
3859
|
...table.sortKey ? { [table.sortKey]: primaryKey.sk } : {},
|
|
3868
|
-
...indexes
|
|
3869
|
-
...generateTimestamps(["createdAt", "updatedAt"])
|
|
3860
|
+
...indexes
|
|
3870
3861
|
};
|
|
3871
3862
|
Object.assign(builder, { item: validatedItem });
|
|
3872
3863
|
return validatedItem;
|
|
@@ -3893,36 +3884,22 @@ function defineEntity(config) {
|
|
|
3893
3884
|
upsert: (data) => {
|
|
3894
3885
|
const builder = table.put({});
|
|
3895
3886
|
const prepareValidatedItemAsync = async () => {
|
|
3896
|
-
const
|
|
3897
|
-
const validatedData = validationResult instanceof Promise ? await validationResult : validationResult;
|
|
3887
|
+
const validatedData = await config.schema["~standard"].validate(data);
|
|
3898
3888
|
if ("issues" in validatedData && validatedData.issues) {
|
|
3899
3889
|
throw new Error(`Validation failed: ${validatedData.issues.map((i) => i.message).join(", ")}`);
|
|
3900
3890
|
}
|
|
3901
|
-
const
|
|
3902
|
-
|
|
3903
|
-
(
|
|
3904
|
-
|
|
3905
|
-
|
|
3906
|
-
|
|
3907
|
-
throw new Error(`GSI configuration not found for index: ${indexName}`);
|
|
3908
|
-
}
|
|
3909
|
-
if (key.pk) {
|
|
3910
|
-
acc[gsiConfig.partitionKey] = key.pk;
|
|
3911
|
-
}
|
|
3912
|
-
if (key.sk && gsiConfig.sortKey) {
|
|
3913
|
-
acc[gsiConfig.sortKey] = key.sk;
|
|
3914
|
-
}
|
|
3915
|
-
return acc;
|
|
3916
|
-
},
|
|
3917
|
-
{}
|
|
3918
|
-
);
|
|
3891
|
+
const dataForKeyGeneration = {
|
|
3892
|
+
...validatedData.value,
|
|
3893
|
+
...generateTimestamps(["createdAt", "updatedAt"], validatedData.value)
|
|
3894
|
+
};
|
|
3895
|
+
const primaryKey = config.primaryKey.generateKey(dataForKeyGeneration);
|
|
3896
|
+
const indexes = buildIndexes(dataForKeyGeneration, table);
|
|
3919
3897
|
const validatedItem = {
|
|
3920
3898
|
[table.partitionKey]: primaryKey.pk,
|
|
3921
3899
|
...table.sortKey ? { [table.sortKey]: primaryKey.sk } : {},
|
|
3922
|
-
...
|
|
3900
|
+
...dataForKeyGeneration,
|
|
3923
3901
|
[entityTypeAttributeName]: config.name,
|
|
3924
|
-
...indexes
|
|
3925
|
-
...generateTimestamps(["createdAt", "updatedAt"])
|
|
3902
|
+
...indexes
|
|
3926
3903
|
};
|
|
3927
3904
|
Object.assign(builder, { item: validatedItem });
|
|
3928
3905
|
return validatedItem;
|
|
@@ -3930,36 +3907,25 @@ function defineEntity(config) {
|
|
|
3930
3907
|
const prepareValidatedItemSync = () => {
|
|
3931
3908
|
const validationResult = config.schema["~standard"].validate(data);
|
|
3932
3909
|
if (validationResult instanceof Promise) {
|
|
3933
|
-
throw new Error(
|
|
3910
|
+
throw new Error(
|
|
3911
|
+
"Async validation is not supported in withTransaction or withBatch. Use execute() instead."
|
|
3912
|
+
);
|
|
3934
3913
|
}
|
|
3935
3914
|
if ("issues" in validationResult && validationResult.issues) {
|
|
3936
3915
|
throw new Error(`Validation failed: ${validationResult.issues.map((i) => i.message).join(", ")}`);
|
|
3937
3916
|
}
|
|
3938
|
-
const
|
|
3939
|
-
|
|
3940
|
-
(
|
|
3941
|
-
|
|
3942
|
-
|
|
3943
|
-
|
|
3944
|
-
throw new Error(`GSI configuration not found for index: ${indexName}`);
|
|
3945
|
-
}
|
|
3946
|
-
if (key.pk) {
|
|
3947
|
-
acc[gsiConfig.partitionKey] = key.pk;
|
|
3948
|
-
}
|
|
3949
|
-
if (key.sk && gsiConfig.sortKey) {
|
|
3950
|
-
acc[gsiConfig.sortKey] = key.sk;
|
|
3951
|
-
}
|
|
3952
|
-
return acc;
|
|
3953
|
-
},
|
|
3954
|
-
{}
|
|
3955
|
-
);
|
|
3917
|
+
const dataForKeyGeneration = {
|
|
3918
|
+
...validationResult.value,
|
|
3919
|
+
...generateTimestamps(["createdAt", "updatedAt"], validationResult.value)
|
|
3920
|
+
};
|
|
3921
|
+
const primaryKey = config.primaryKey.generateKey(dataForKeyGeneration);
|
|
3922
|
+
const indexes = buildIndexes(dataForKeyGeneration, table);
|
|
3956
3923
|
const validatedItem = {
|
|
3957
3924
|
[table.partitionKey]: primaryKey.pk,
|
|
3958
3925
|
...table.sortKey ? { [table.sortKey]: primaryKey.sk } : {},
|
|
3959
|
-
...
|
|
3926
|
+
...dataForKeyGeneration,
|
|
3960
3927
|
[entityTypeAttributeName]: config.name,
|
|
3961
|
-
...indexes
|
|
3962
|
-
...generateTimestamps(["createdAt", "updatedAt"])
|
|
3928
|
+
...indexes
|
|
3963
3929
|
};
|
|
3964
3930
|
Object.assign(builder, { item: validatedItem });
|
|
3965
3931
|
return validatedItem;
|
|
@@ -3992,7 +3958,7 @@ function defineEntity(config) {
|
|
|
3992
3958
|
const primaryKeyObj = config.primaryKey.generateKey(key);
|
|
3993
3959
|
const builder = table.update(primaryKeyObj);
|
|
3994
3960
|
builder.condition(eq(entityTypeAttributeName, config.name));
|
|
3995
|
-
const timestamps = generateTimestamps(["updatedAt"]);
|
|
3961
|
+
const timestamps = generateTimestamps(["updatedAt"], data);
|
|
3996
3962
|
builder.set({ ...data, ...timestamps });
|
|
3997
3963
|
return builder;
|
|
3998
3964
|
},
|