dyna-record 0.6.6 → 0.7.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 +23 -7
- package/dist/index.d.ts +12 -2
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +13 -22
- package/dist/src/DynaRecord.d.ts +3 -3
- package/dist/src/DynaRecord.d.ts.map +1 -1
- package/dist/src/DynaRecord.js +24 -59
- package/dist/src/Logger.js +1 -3
- package/dist/src/decorators/Entity.d.ts +1 -1
- package/dist/src/decorators/Entity.d.ts.map +1 -1
- package/dist/src/decorators/Entity.js +3 -8
- package/dist/src/decorators/Table.d.ts +2 -2
- package/dist/src/decorators/Table.d.ts.map +1 -1
- package/dist/src/decorators/Table.js +3 -8
- package/dist/src/decorators/attributes/BooleanAttribute.d.ts +2 -2
- package/dist/src/decorators/attributes/BooleanAttribute.d.ts.map +1 -1
- package/dist/src/decorators/attributes/BooleanAttribute.js +6 -10
- package/dist/src/decorators/attributes/DateAttribute.d.ts +2 -2
- package/dist/src/decorators/attributes/DateAttribute.d.ts.map +1 -1
- package/dist/src/decorators/attributes/DateAttribute.js +8 -12
- package/dist/src/decorators/attributes/EnumAttribute.d.ts +2 -2
- package/dist/src/decorators/attributes/EnumAttribute.d.ts.map +1 -1
- package/dist/src/decorators/attributes/EnumAttribute.js +7 -10
- package/dist/src/decorators/attributes/ForeignKeyAttribute.d.ts +3 -3
- package/dist/src/decorators/attributes/ForeignKeyAttribute.d.ts.map +1 -1
- package/dist/src/decorators/attributes/ForeignKeyAttribute.js +6 -10
- package/dist/src/decorators/attributes/IdAttribute.d.ts +1 -1
- package/dist/src/decorators/attributes/IdAttribute.d.ts.map +1 -1
- package/dist/src/decorators/attributes/IdAttribute.js +3 -8
- package/dist/src/decorators/attributes/NumberAttribute.d.ts +2 -2
- package/dist/src/decorators/attributes/NumberAttribute.d.ts.map +1 -1
- package/dist/src/decorators/attributes/NumberAttribute.js +6 -10
- package/dist/src/decorators/attributes/ObjectAttribute.d.ts +3 -3
- package/dist/src/decorators/attributes/ObjectAttribute.d.ts.map +1 -1
- package/dist/src/decorators/attributes/ObjectAttribute.js +17 -21
- package/dist/src/decorators/attributes/PartitionKeyAttribute.d.ts +3 -3
- package/dist/src/decorators/attributes/PartitionKeyAttribute.d.ts.map +1 -1
- package/dist/src/decorators/attributes/PartitionKeyAttribute.js +6 -10
- package/dist/src/decorators/attributes/SortKeyAttribute.d.ts +3 -3
- package/dist/src/decorators/attributes/SortKeyAttribute.d.ts.map +1 -1
- package/dist/src/decorators/attributes/SortKeyAttribute.js +6 -10
- package/dist/src/decorators/attributes/StringAttribute.d.ts +2 -2
- package/dist/src/decorators/attributes/StringAttribute.d.ts.map +1 -1
- package/dist/src/decorators/attributes/StringAttribute.js +6 -10
- package/dist/src/decorators/attributes/index.d.ts +13 -13
- package/dist/src/decorators/attributes/index.d.ts.map +1 -1
- package/dist/src/decorators/attributes/index.js +11 -41
- package/dist/src/decorators/attributes/serializers.d.ts +2 -2
- package/dist/src/decorators/attributes/serializers.d.ts.map +1 -1
- package/dist/src/decorators/attributes/serializers.js +5 -12
- package/dist/src/decorators/attributes/types.js +1 -2
- package/dist/src/decorators/index.d.ts +5 -5
- package/dist/src/decorators/index.d.ts.map +1 -1
- package/dist/src/decorators/index.js +5 -27
- package/dist/src/decorators/relationships/BelongsTo.d.ts +4 -4
- package/dist/src/decorators/relationships/BelongsTo.d.ts.map +1 -1
- package/dist/src/decorators/relationships/BelongsTo.js +3 -8
- package/dist/src/decorators/relationships/HasAndBelongsToMany.d.ts +3 -3
- package/dist/src/decorators/relationships/HasAndBelongsToMany.d.ts.map +1 -1
- package/dist/src/decorators/relationships/HasAndBelongsToMany.js +4 -9
- package/dist/src/decorators/relationships/HasMany.d.ts +3 -3
- package/dist/src/decorators/relationships/HasMany.d.ts.map +1 -1
- package/dist/src/decorators/relationships/HasMany.js +4 -9
- package/dist/src/decorators/relationships/HasOne.d.ts +3 -3
- package/dist/src/decorators/relationships/HasOne.d.ts.map +1 -1
- package/dist/src/decorators/relationships/HasOne.js +3 -8
- package/dist/src/decorators/relationships/index.d.ts +5 -5
- package/dist/src/decorators/relationships/index.d.ts.map +1 -1
- package/dist/src/decorators/relationships/index.js +5 -29
- package/dist/src/decorators/relationships/types.d.ts +3 -3
- package/dist/src/decorators/relationships/types.d.ts.map +1 -1
- package/dist/src/decorators/relationships/types.js +1 -2
- package/dist/src/decorators/types.d.ts +3 -3
- package/dist/src/decorators/types.d.ts.map +1 -1
- package/dist/src/decorators/types.js +1 -2
- package/dist/src/dynamo-utils/DynamoClient.d.ts +1 -1
- package/dist/src/dynamo-utils/DynamoClient.d.ts.map +1 -1
- package/dist/src/dynamo-utils/DynamoClient.js +13 -18
- package/dist/src/dynamo-utils/TransactGetBuilder.d.ts +1 -1
- package/dist/src/dynamo-utils/TransactGetBuilder.d.ts.map +1 -1
- package/dist/src/dynamo-utils/TransactGetBuilder.js +5 -10
- package/dist/src/dynamo-utils/TransactWriteBuilder.d.ts +1 -1
- package/dist/src/dynamo-utils/TransactWriteBuilder.d.ts.map +1 -1
- package/dist/src/dynamo-utils/TransactWriteBuilder.js +11 -16
- package/dist/src/dynamo-utils/errors.js +2 -7
- package/dist/src/dynamo-utils/index.d.ts +7 -7
- package/dist/src/dynamo-utils/index.d.ts.map +1 -1
- package/dist/src/dynamo-utils/index.js +7 -30
- package/dist/src/dynamo-utils/types.js +1 -2
- package/dist/src/errors.js +3 -9
- package/dist/src/id.d.ts +12 -0
- package/dist/src/id.d.ts.map +1 -0
- package/dist/src/id.js +11 -0
- package/dist/src/index.d.ts +8 -6
- package/dist/src/index.d.ts.map +1 -1
- package/dist/src/index.js +4 -20
- package/dist/src/metadata/AttributeMetadata.d.ts +6 -4
- package/dist/src/metadata/AttributeMetadata.d.ts.map +1 -1
- package/dist/src/metadata/AttributeMetadata.js +5 -3
- package/dist/src/metadata/EntityMetadata.d.ts +3 -3
- package/dist/src/metadata/EntityMetadata.d.ts.map +1 -1
- package/dist/src/metadata/EntityMetadata.js +18 -23
- package/dist/src/metadata/JoinTableMetadata.d.ts +3 -3
- package/dist/src/metadata/JoinTableMetadata.d.ts.map +1 -1
- package/dist/src/metadata/JoinTableMetadata.js +1 -3
- package/dist/src/metadata/MetadataStorage.d.ts +7 -7
- package/dist/src/metadata/MetadataStorage.d.ts.map +1 -1
- package/dist/src/metadata/MetadataStorage.js +12 -17
- package/dist/src/metadata/TableMetadata.d.ts +3 -3
- package/dist/src/metadata/TableMetadata.d.ts.map +1 -1
- package/dist/src/metadata/TableMetadata.js +22 -21
- package/dist/src/metadata/index.d.ts +9 -9
- package/dist/src/metadata/index.d.ts.map +1 -1
- package/dist/src/metadata/index.js +11 -34
- package/dist/src/metadata/relationship-metadata/BelongsToRelationship.d.ts +2 -2
- package/dist/src/metadata/relationship-metadata/BelongsToRelationship.d.ts.map +1 -1
- package/dist/src/metadata/relationship-metadata/BelongsToRelationship.js +3 -8
- package/dist/src/metadata/relationship-metadata/HasAndBelongsToManyRelationship.d.ts +1 -1
- package/dist/src/metadata/relationship-metadata/HasAndBelongsToManyRelationship.d.ts.map +1 -1
- package/dist/src/metadata/relationship-metadata/HasAndBelongsToManyRelationship.js +3 -8
- package/dist/src/metadata/relationship-metadata/HasManyRelationship.d.ts +2 -2
- package/dist/src/metadata/relationship-metadata/HasManyRelationship.d.ts.map +1 -1
- package/dist/src/metadata/relationship-metadata/HasManyRelationship.js +3 -8
- package/dist/src/metadata/relationship-metadata/HasOneRelationship.d.ts +2 -2
- package/dist/src/metadata/relationship-metadata/HasOneRelationship.d.ts.map +1 -1
- package/dist/src/metadata/relationship-metadata/HasOneRelationship.js +3 -8
- package/dist/src/metadata/relationship-metadata/OwnedByRelationship.d.ts +2 -2
- package/dist/src/metadata/relationship-metadata/OwnedByRelationship.d.ts.map +1 -1
- package/dist/src/metadata/relationship-metadata/OwnedByRelationship.js +3 -8
- package/dist/src/metadata/relationship-metadata/RelationshipMetadata.d.ts +2 -2
- package/dist/src/metadata/relationship-metadata/RelationshipMetadata.d.ts.map +1 -1
- package/dist/src/metadata/relationship-metadata/RelationshipMetadata.js +1 -3
- package/dist/src/metadata/relationship-metadata/index.d.ts +6 -6
- package/dist/src/metadata/relationship-metadata/index.d.ts.map +1 -1
- package/dist/src/metadata/relationship-metadata/index.js +7 -31
- package/dist/src/metadata/relationship-metadata/types.d.ts +5 -5
- package/dist/src/metadata/relationship-metadata/types.d.ts.map +1 -1
- package/dist/src/metadata/relationship-metadata/types.js +1 -2
- package/dist/src/metadata/relationship-metadata/utils.d.ts +1 -1
- package/dist/src/metadata/relationship-metadata/utils.d.ts.map +1 -1
- package/dist/src/metadata/relationship-metadata/utils.js +11 -18
- package/dist/src/metadata/schemas.d.ts +523 -36
- package/dist/src/metadata/schemas.d.ts.map +1 -1
- package/dist/src/metadata/schemas.js +71 -44
- package/dist/src/metadata/types.d.ts +17 -4
- package/dist/src/metadata/types.d.ts.map +1 -1
- package/dist/src/metadata/types.js +1 -2
- package/dist/src/metadata/utils.d.ts +5 -5
- package/dist/src/metadata/utils.d.ts.map +1 -1
- package/dist/src/metadata/utils.js +14 -29
- package/dist/src/operations/Create/Create.d.ts +5 -5
- package/dist/src/operations/Create/Create.d.ts.map +1 -1
- package/dist/src/operations/Create/Create.js +18 -23
- package/dist/src/operations/Create/index.d.ts +2 -2
- package/dist/src/operations/Create/index.d.ts.map +1 -1
- package/dist/src/operations/Create/index.js +2 -23
- package/dist/src/operations/Create/types.d.ts +2 -2
- package/dist/src/operations/Create/types.d.ts.map +1 -1
- package/dist/src/operations/Create/types.js +1 -2
- package/dist/src/operations/Delete/Delete.d.ts +3 -3
- package/dist/src/operations/Delete/Delete.d.ts.map +1 -1
- package/dist/src/operations/Delete/Delete.js +28 -33
- package/dist/src/operations/Delete/index.d.ts +1 -1
- package/dist/src/operations/Delete/index.d.ts.map +1 -1
- package/dist/src/operations/Delete/index.js +1 -8
- package/dist/src/operations/Delete/types.js +1 -2
- package/dist/src/operations/FindById/FindById.d.ts +4 -4
- package/dist/src/operations/FindById/FindById.d.ts.map +1 -1
- package/dist/src/operations/FindById/FindById.js +17 -22
- package/dist/src/operations/FindById/index.d.ts +2 -2
- package/dist/src/operations/FindById/index.d.ts.map +1 -1
- package/dist/src/operations/FindById/index.js +2 -23
- package/dist/src/operations/FindById/types.d.ts +3 -3
- package/dist/src/operations/FindById/types.d.ts.map +1 -1
- package/dist/src/operations/FindById/types.js +1 -2
- package/dist/src/operations/OperationBase.d.ts +3 -3
- package/dist/src/operations/OperationBase.d.ts.map +1 -1
- package/dist/src/operations/OperationBase.js +4 -9
- package/dist/src/operations/Query/Query.d.ts +4 -4
- package/dist/src/operations/Query/Query.d.ts.map +1 -1
- package/dist/src/operations/Query/Query.js +15 -20
- package/dist/src/operations/Query/index.d.ts +2 -2
- package/dist/src/operations/Query/index.d.ts.map +1 -1
- package/dist/src/operations/Query/index.js +2 -23
- package/dist/src/operations/Query/types.d.ts +4 -4
- package/dist/src/operations/Query/types.d.ts.map +1 -1
- package/dist/src/operations/Query/types.js +1 -2
- package/dist/src/operations/Update/Update.d.ts +5 -5
- package/dist/src/operations/Update/Update.d.ts.map +1 -1
- package/dist/src/operations/Update/Update.js +37 -42
- package/dist/src/operations/Update/UpdateDryRun.d.ts +2 -2
- package/dist/src/operations/Update/UpdateDryRun.d.ts.map +1 -1
- package/dist/src/operations/Update/UpdateDryRun.js +3 -8
- package/dist/src/operations/Update/index.d.ts +3 -3
- package/dist/src/operations/Update/index.d.ts.map +1 -1
- package/dist/src/operations/Update/index.js +3 -25
- package/dist/src/operations/Update/types.d.ts +2 -2
- package/dist/src/operations/Update/types.d.ts.map +1 -1
- package/dist/src/operations/Update/types.js +1 -2
- package/dist/src/operations/index.d.ts +6 -6
- package/dist/src/operations/index.d.ts.map +1 -1
- package/dist/src/operations/index.js +6 -22
- package/dist/src/operations/types.d.ts +3 -3
- package/dist/src/operations/types.d.ts.map +1 -1
- package/dist/src/operations/types.js +1 -2
- package/dist/src/operations/utils/expressionBuilder.d.ts +2 -2
- package/dist/src/operations/utils/expressionBuilder.d.ts.map +1 -1
- package/dist/src/operations/utils/expressionBuilder.js +1 -5
- package/dist/src/operations/utils/flattenObjectForUpdate.d.ts +2 -2
- package/dist/src/operations/utils/flattenObjectForUpdate.d.ts.map +1 -1
- package/dist/src/operations/utils/flattenObjectForUpdate.js +3 -6
- package/dist/src/operations/utils/index.d.ts +5 -5
- package/dist/src/operations/utils/index.d.ts.map +1 -1
- package/dist/src/operations/utils/index.js +5 -21
- package/dist/src/operations/utils/mergePartialObjectAttributes.d.ts +1 -1
- package/dist/src/operations/utils/mergePartialObjectAttributes.d.ts.map +1 -1
- package/dist/src/operations/utils/mergePartialObjectAttributes.js +1 -4
- package/dist/src/operations/utils/types.js +1 -2
- package/dist/src/operations/utils/utils.d.ts +4 -4
- package/dist/src/operations/utils/utils.d.ts.map +1 -1
- package/dist/src/operations/utils/utils.js +13 -23
- package/dist/src/query-utils/Filters.d.ts +2 -2
- package/dist/src/query-utils/Filters.d.ts.map +1 -1
- package/dist/src/query-utils/Filters.js +1 -4
- package/dist/src/query-utils/QueryBuilder.d.ts +1 -1
- package/dist/src/query-utils/QueryBuilder.d.ts.map +1 -1
- package/dist/src/query-utils/QueryBuilder.js +8 -13
- package/dist/src/query-utils/index.d.ts +2 -2
- package/dist/src/query-utils/index.d.ts.map +1 -1
- package/dist/src/query-utils/index.js +2 -23
- package/dist/src/query-utils/types.js +1 -2
- package/dist/src/relationships/JoinTable.d.ts +2 -2
- package/dist/src/relationships/JoinTable.d.ts.map +1 -1
- package/dist/src/relationships/JoinTable.js +14 -19
- package/dist/src/relationships/index.d.ts +1 -1
- package/dist/src/relationships/index.d.ts.map +1 -1
- package/dist/src/relationships/index.js +1 -8
- package/dist/src/types.d.ts +2 -2
- package/dist/src/types.d.ts.map +1 -1
- package/dist/src/types.js +1 -2
- package/dist/src/utils.d.ts +3 -3
- package/dist/src/utils.d.ts.map +1 -1
- package/dist/src/utils.js +16 -31
- package/package.json +28 -24
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"utils.d.ts","sourceRoot":"","sources":["../../../../src/operations/utils/utils.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,UAAU,MAAM,
|
|
1
|
+
{"version":3,"file":"utils.d.ts","sourceRoot":"","sources":["../../../../src/operations/utils/utils.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,UAAU,MAAM,qBAAqB,CAAC;AAClD,OAAO,KAAK,EACV,8BAA8B,EAC9B,oBAAoB,EACrB,MAAM,yBAAyB,CAAC;AAQjC,OAAO,KAAK,EACV,eAAe,EACf,WAAW,EACX,UAAU,EACV,mBAAmB,EACpB,MAAM,gBAAgB,CAAC;AAExB,OAAO,EAAE,KAAK,oBAAoB,EAAE,MAAM,aAAa,CAAC;AAExD;;;;;;GAMG;AACH,eAAO,MAAM,8BAA8B,GACzC,eAAe,oBAAoB,EAAE,KACpC,mBAaF,CAAC;AAEF;;;;;GAKG;AACH,eAAO,MAAM,2BAA2B,GACtC,SAAS,oBAAoB,EAC7B,QAAQ,OAAO,CAAC,oBAAoB,CAAC,UAAU,CAAC,CAAC,KAChD,UAAU,GAAG,IAAI,GAAG,SAKtB,CAAC;AAEF;;;;;;;GAOG;AACH,eAAO,MAAM,qBAAqB,GAChC,aAAa,WAAW,CAAC,UAAU,CAAC,EACpC,UAAU,MAAM,EAChB,SAAS,8BAA8B,EACvC,YAAY,MAAM,KACjB,eAqBF,CAAC;AAEF;;;GAGG;AACH,eAAO,MAAM,iBAAiB,GAAI,MAAM,OAAO,KAAG,OAEjD,CAAC"}
|
|
@@ -1,12 +1,6 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
};
|
|
5
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
-
exports.consistentReadVal = exports.buildBelongsToLinkKey = exports.extractForeignKeyFromEntity = exports.buildEntityRelationshipMetaObj = void 0;
|
|
7
|
-
const metadata_1 = __importDefault(require("../../metadata"));
|
|
8
|
-
const utils_1 = require("../../metadata/utils");
|
|
9
|
-
const utils_2 = require("../../utils");
|
|
1
|
+
import Metadata from "../../metadata/index.js";
|
|
2
|
+
import { doesEntityBelongToRelAsHasMany, doesEntityBelongToRelAsHasOne, isBelongsToRelationship, isRelationshipMetadataWithForeignKey } from "../../metadata/utils.js";
|
|
3
|
+
import { isKeyOfObject } from "../../utils.js";
|
|
10
4
|
/**
|
|
11
5
|
* Creates an object including
|
|
12
6
|
* - relationsLookup: Object to look up RelationshipMetadata by Entity name
|
|
@@ -14,29 +8,27 @@ const utils_2 = require("../../utils");
|
|
|
14
8
|
* @param includedRelationships
|
|
15
9
|
* @returns
|
|
16
10
|
*/
|
|
17
|
-
const buildEntityRelationshipMetaObj = (relationships) => {
|
|
11
|
+
export const buildEntityRelationshipMetaObj = (relationships) => {
|
|
18
12
|
return Object.values(relationships).reduce((acc, rel) => {
|
|
19
|
-
if (
|
|
13
|
+
if (isBelongsToRelationship(rel)) {
|
|
20
14
|
acc.belongsToRelationships.push(rel);
|
|
21
15
|
}
|
|
22
16
|
acc.relationsLookup[rel.target.name] = rel;
|
|
23
17
|
return acc;
|
|
24
18
|
}, { relationsLookup: {}, belongsToRelationships: [] });
|
|
25
19
|
};
|
|
26
|
-
exports.buildEntityRelationshipMetaObj = buildEntityRelationshipMetaObj;
|
|
27
20
|
/**
|
|
28
21
|
* Extracts a ForeignKey value from an entity instance
|
|
29
22
|
* @param relMeta - RelationshipMetadata for associated foreignKey
|
|
30
23
|
* @param entity - instance of DynaRecord
|
|
31
24
|
* @returns
|
|
32
25
|
*/
|
|
33
|
-
const extractForeignKeyFromEntity = (relMeta, entity) => {
|
|
34
|
-
return
|
|
35
|
-
|
|
26
|
+
export const extractForeignKeyFromEntity = (relMeta, entity) => {
|
|
27
|
+
return isRelationshipMetadataWithForeignKey(relMeta) &&
|
|
28
|
+
isKeyOfObject(entity, relMeta.foreignKey)
|
|
36
29
|
? entity[relMeta.foreignKey]
|
|
37
30
|
: undefined;
|
|
38
31
|
};
|
|
39
|
-
exports.extractForeignKeyFromEntity = extractForeignKeyFromEntity;
|
|
40
32
|
/**
|
|
41
33
|
* Creates the PK and SK (key) for a table item that BelongsTo another as HasMany or HasOne
|
|
42
34
|
* @param entityClass
|
|
@@ -45,17 +37,17 @@ exports.extractForeignKeyFromEntity = extractForeignKeyFromEntity;
|
|
|
45
37
|
* @param foreignKey
|
|
46
38
|
* @returns
|
|
47
39
|
*/
|
|
48
|
-
const buildBelongsToLinkKey = (entityClass, entityId, relMeta, foreignKey) => {
|
|
49
|
-
const tableMeta =
|
|
40
|
+
export const buildBelongsToLinkKey = (entityClass, entityId, relMeta, foreignKey) => {
|
|
41
|
+
const tableMeta = Metadata.getEntityTable(entityClass.name);
|
|
50
42
|
const partitionKeyAlias = tableMeta.partitionKeyAttribute.alias;
|
|
51
43
|
const sortKeyAlias = tableMeta.sortKeyAttribute.alias;
|
|
52
|
-
if (
|
|
44
|
+
if (doesEntityBelongToRelAsHasMany(entityClass, relMeta)) {
|
|
53
45
|
return {
|
|
54
46
|
[partitionKeyAlias]: relMeta.target.partitionKeyValue(foreignKey),
|
|
55
47
|
[sortKeyAlias]: entityClass.partitionKeyValue(entityId)
|
|
56
48
|
};
|
|
57
49
|
}
|
|
58
|
-
if (
|
|
50
|
+
if (doesEntityBelongToRelAsHasOne(entityClass, relMeta)) {
|
|
59
51
|
return {
|
|
60
52
|
[partitionKeyAlias]: relMeta.target.partitionKeyValue(foreignKey),
|
|
61
53
|
[sortKeyAlias]: entityClass.name
|
|
@@ -63,12 +55,10 @@ const buildBelongsToLinkKey = (entityClass, entityId, relMeta, foreignKey) => {
|
|
|
63
55
|
}
|
|
64
56
|
throw new Error("Failed to build BelongsTo key for linked record");
|
|
65
57
|
};
|
|
66
|
-
exports.buildBelongsToLinkKey = buildBelongsToLinkKey;
|
|
67
58
|
/**
|
|
68
59
|
* Consistent read value.
|
|
69
60
|
* @default false
|
|
70
61
|
*/
|
|
71
|
-
const consistentReadVal = (val) => {
|
|
62
|
+
export const consistentReadVal = (val) => {
|
|
72
63
|
return val ?? false;
|
|
73
64
|
};
|
|
74
|
-
exports.consistentReadVal = consistentReadVal;
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { type RelationshipMetadata } from "../metadata";
|
|
2
|
-
import { type OrFilter } from "./types";
|
|
1
|
+
import { type RelationshipMetadata } from "../metadata/index.js";
|
|
2
|
+
import { type OrFilter } from "./types.js";
|
|
3
3
|
/**
|
|
4
4
|
* Builds the filter so that relationships that are included in the query will have their relationships included in the query
|
|
5
5
|
* @param parentClassName
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Filters.d.ts","sourceRoot":"","sources":["../../../src/query-utils/Filters.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,oBAAoB,EAAE,MAAM,
|
|
1
|
+
{"version":3,"file":"Filters.d.ts","sourceRoot":"","sources":["../../../src/query-utils/Filters.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,oBAAoB,EAAE,MAAM,sBAAsB,CAAC;AACjE,OAAO,EAAE,KAAK,QAAQ,EAAE,MAAM,YAAY,CAAC;AAE3C;;;;;GAKG;AACH,wBAAgB,2BAA2B,CACzC,eAAe,EAAE,MAAM,EACvB,qBAAqB,EAAE,oBAAoB,EAAE,GAC5C,QAAQ,CASV"}
|
|
@@ -1,13 +1,10 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.includedRelationshipsFilter = includedRelationshipsFilter;
|
|
4
1
|
/**
|
|
5
2
|
* Builds the filter so that relationships that are included in the query will have their relationships included in the query
|
|
6
3
|
* @param parentClassName
|
|
7
4
|
* @param includedRelationships
|
|
8
5
|
* @returns
|
|
9
6
|
*/
|
|
10
|
-
function includedRelationshipsFilter(parentClassName, includedRelationships) {
|
|
7
|
+
export function includedRelationshipsFilter(parentClassName, includedRelationships) {
|
|
11
8
|
const includedTypes = [
|
|
12
9
|
parentClassName,
|
|
13
10
|
...includedRelationships.map(rel => rel.target.name)
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { type QueryCommandInput } from "@aws-sdk/lib-dynamodb";
|
|
2
|
-
import type { QueryCommandProps } from "./types";
|
|
2
|
+
import type { QueryCommandProps } from "./types.js";
|
|
3
3
|
/**
|
|
4
4
|
* Constructs and formats a DynamoDB query command based on provided key conditions and query options. This class simplifies the creation of complex DynamoDB queries by abstracting the underlying AWS SDK query command structure, particularly handling the construction of key condition expressions, filter expressions, and expression attribute names and values.
|
|
5
5
|
*
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"QueryBuilder.d.ts","sourceRoot":"","sources":["../../../src/query-utils/QueryBuilder.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,iBAAiB,EAAE,MAAM,uBAAuB,CAAC;AAO/D,OAAO,KAAK,EAUV,iBAAiB,EAClB,MAAM,
|
|
1
|
+
{"version":3,"file":"QueryBuilder.d.ts","sourceRoot":"","sources":["../../../src/query-utils/QueryBuilder.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,iBAAiB,EAAE,MAAM,uBAAuB,CAAC;AAO/D,OAAO,KAAK,EAUV,iBAAiB,EAClB,MAAM,YAAY,CAAC;AAgBpB;;;;GAIG;AACH,cAAM,YAAY;;gBASJ,KAAK,EAAE,iBAAiB;IAmBpC;;;OAGG;IACI,KAAK,IAAI,iBAAiB;IAwBjC;;;;;OAKG;IACH,OAAO,CAAC,8BAA8B;IAgBtC;;;OAGG;IACH,OAAO,CAAC,wBAAwB;IAgChC;;;;;;;;;OASG;IACH,OAAO,CAAC,YAAY;IAWpB;;;;OAIG;IACH,OAAO,CAAC,WAAW;IASnB;;;;OAIG;IACH,OAAO,CAAC,SAAS;IAejB;;;;;;;OAOG;IACH,OAAO,CAAC,YAAY;IAkCpB;;;;;;;;;OASG;IACH,OAAO,CAAC,eAAe;IAkCvB;;;;OAIG;IACH,OAAO,CAAC,QAAQ;IAehB;;;;OAIG;IACH,OAAO,CAAC,WAAW;IAUnB;;;;OAIG;IACH,OAAO,CAAC,kBAAkB;IAI1B;;;;OAIG;IACH,OAAO,CAAC,gBAAgB;IAIxB;;;;OAIG;IACH,OAAO,CAAC,aAAa;IAIrB;;;;OAIG;IACH,OAAO,CAAC,UAAU;CAGnB;AAED,eAAe,YAAY,CAAC"}
|
|
@@ -1,10 +1,5 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
-
};
|
|
5
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
-
const metadata_1 = __importDefault(require("../metadata"));
|
|
7
|
-
const utils_1 = require("../operations/utils");
|
|
1
|
+
import Metadata from "../metadata/index.js";
|
|
2
|
+
import { consistentReadVal } from "../operations/utils/index.js";
|
|
8
3
|
/**
|
|
9
4
|
* Constructs and formats a DynamoDB query command based on provided key conditions and query options. This class simplifies the creation of complex DynamoDB queries by abstracting the underlying AWS SDK query command structure, particularly handling the construction of key condition expressions, filter expressions, and expression attribute names and values.
|
|
10
5
|
*
|
|
@@ -21,10 +16,10 @@ class QueryBuilder {
|
|
|
21
16
|
constructor(props) {
|
|
22
17
|
this.#props = props;
|
|
23
18
|
this.#attrCounter = 0;
|
|
24
|
-
const entityMetadata =
|
|
25
|
-
this.#tableMetadata =
|
|
26
|
-
const relationshipsAttributesMeta = Object.values(entityMetadata.relationships).map(relMeta =>
|
|
27
|
-
const entityAttrMeta =
|
|
19
|
+
const entityMetadata = Metadata.getEntity(props.entityClassName);
|
|
20
|
+
this.#tableMetadata = Metadata.getTable(entityMetadata.tableClassName);
|
|
21
|
+
const relationshipsAttributesMeta = Object.values(entityMetadata.relationships).map(relMeta => Metadata.getEntityAttributes(relMeta.target.name));
|
|
22
|
+
const entityAttrMeta = Metadata.getEntityAttributes(props.entityClassName);
|
|
28
23
|
const allAttrMeta = [...relationshipsAttributesMeta, entityAttrMeta];
|
|
29
24
|
this.#attributeMetadata = allAttrMeta.reduce((allAttrMeta, attrMeta) => {
|
|
30
25
|
return { ...allAttrMeta, ...attrMeta };
|
|
@@ -47,7 +42,7 @@ class QueryBuilder {
|
|
|
47
42
|
KeyConditionExpression: keyFilter.expression,
|
|
48
43
|
ExpressionAttributeNames: this.expressionAttributeNames(),
|
|
49
44
|
ExpressionAttributeValues: this.expressionAttributeValueParams(keyFilter, filterParams),
|
|
50
|
-
ConsistentRead:
|
|
45
|
+
ConsistentRead: consistentReadVal(this.#props.options?.consistentRead)
|
|
51
46
|
};
|
|
52
47
|
}
|
|
53
48
|
/**
|
|
@@ -273,4 +268,4 @@ class QueryBuilder {
|
|
|
273
268
|
return filter.$or !== undefined;
|
|
274
269
|
}
|
|
275
270
|
}
|
|
276
|
-
|
|
271
|
+
export default QueryBuilder;
|
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
export { default as QueryBuilder } from "./QueryBuilder";
|
|
2
|
-
export * from "./types";
|
|
1
|
+
export { default as QueryBuilder } from "./QueryBuilder.js";
|
|
2
|
+
export * from "./types.js";
|
|
3
3
|
//# sourceMappingURL=index.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/query-utils/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,IAAI,YAAY,EAAE,MAAM,
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/query-utils/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,IAAI,YAAY,EAAE,MAAM,mBAAmB,CAAC;AAC5D,cAAc,YAAY,CAAC"}
|
|
@@ -1,23 +1,2 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
if (k2 === undefined) k2 = k;
|
|
4
|
-
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
-
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
-
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
-
}
|
|
8
|
-
Object.defineProperty(o, k2, desc);
|
|
9
|
-
}) : (function(o, m, k, k2) {
|
|
10
|
-
if (k2 === undefined) k2 = k;
|
|
11
|
-
o[k2] = m[k];
|
|
12
|
-
}));
|
|
13
|
-
var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
14
|
-
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
15
|
-
};
|
|
16
|
-
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
17
|
-
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
18
|
-
};
|
|
19
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
20
|
-
exports.QueryBuilder = void 0;
|
|
21
|
-
var QueryBuilder_1 = require("./QueryBuilder");
|
|
22
|
-
Object.defineProperty(exports, "QueryBuilder", { enumerable: true, get: function () { return __importDefault(QueryBuilder_1).default; } });
|
|
23
|
-
__exportStar(require("./types"), exports);
|
|
1
|
+
export { default as QueryBuilder } from "./QueryBuilder.js";
|
|
2
|
+
export * from "./types.js";
|
|
@@ -1,2 +1 @@
|
|
|
1
|
-
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
1
|
+
export {};
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import type DynaRecord from "../DynaRecord";
|
|
2
|
-
import type { ForeignKey, EntityClass } from "../types";
|
|
1
|
+
import type DynaRecord from "../DynaRecord.js";
|
|
2
|
+
import type { ForeignKey, EntityClass } from "../types.js";
|
|
3
3
|
/**
|
|
4
4
|
* Exclude the type1 type2 instance keys
|
|
5
5
|
*/
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"JoinTable.d.ts","sourceRoot":"","sources":["../../../src/relationships/JoinTable.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,UAAU,MAAM,
|
|
1
|
+
{"version":3,"file":"JoinTable.d.ts","sourceRoot":"","sources":["../../../src/relationships/JoinTable.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,UAAU,MAAM,kBAAkB,CAAC;AAW/C,OAAO,KAAK,EAAE,UAAU,EAAE,WAAW,EAAmB,MAAM,aAAa,CAAC;AAE5E;;GAEG;AACH,KAAK,WAAW,GAAG,OAAO,GAAG,OAAO,CAAC;AAOrC;;GAEG;AACH,KAAK,oBAAoB,CAAC,CAAC,IAAI;KAC5B,CAAC,IAAI,OAAO,CAAC,MAAM,CAAC,EAAE,WAAW,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,SAAS,UAAU,GACzD,MAAM,GACN,KAAK;CACV,CAAC;AAYF;;GAEG;AACH,UAAU,gBAAgB;IACxB;;;;;OAKG;IACH,yBAAyB,CAAC,EAAE,OAAO,CAAC;CACrC;AAWD;;;;;;;;;;;;;GAaG;AACH,uBAAe,SAAS,CAAC,CAAC,SAAS,UAAU,EAAE,CAAC,SAAS,UAAU;IAE/D,OAAO,CAAC,QAAQ,CAAC,KAAK;IACtB,OAAO,CAAC,QAAQ,CAAC,KAAK;gBADL,KAAK,EAAE,WAAW,CAAC,CAAC,CAAC,EACrB,KAAK,EAAE,WAAW,CAAC,CAAC,CAAC;IAGxC;;;;;;OAMG;WACiB,MAAM,CACxB,SAAS,SAAS,SAAS,CAAC,CAAC,EAAE,CAAC,CAAC,EACjC,CAAC,SAAS,UAAU,EACpB,CAAC,SAAS,UAAU,EAEpB,IAAI,EAAE,KAAK,KAAK,EAAE,WAAW,CAAC,CAAC,CAAC,EAAE,KAAK,EAAE,WAAW,CAAC,CAAC,CAAC,KAAK,SAAS,EACrE,IAAI,EAAE,oBAAoB,CAAC,SAAS,CAAC,EACrC,OAAO,CAAC,EAAE,gBAAgB,GACzB,OAAO,CAAC,IAAI,CAAC;IA6BhB;;;;;OAKG;WACiB,MAAM,CACxB,SAAS,SAAS,SAAS,CAAC,CAAC,EAAE,CAAC,CAAC,EACjC,CAAC,SAAS,UAAU,EACpB,CAAC,SAAS,UAAU,EAEpB,IAAI,EAAE,KAAK,KAAK,EAAE,WAAW,CAAC,CAAC,CAAC,EAAE,KAAK,EAAE,WAAW,CAAC,CAAC,CAAC,KAAK,SAAS,EACrE,IAAI,EAAE,oBAAoB,CAAC,SAAS,CAAC,GACpC,OAAO,CAAC,IAAI,CAAC;mBAWK,QAAQ;IAoD7B;;;;;;;;;;;OAWG;IACH,OAAO,CAAC,MAAM,CAAC,qBAAqB;IA8CpC;;;;;;OAMG;IACH,OAAO,CAAC,MAAM,CAAC,qBAAqB;IAcpC;;;;;;;OAOG;IACH,OAAO,CAAC,MAAM,CAAC,UAAU;IA0BzB,OAAO,CAAC,MAAM,CAAC,YAAY;IAoB3B,OAAO,CAAC,MAAM,CAAC,gBAAgB;IAoB/B,OAAO,CAAC,MAAM,CAAC,4BAA4B;CA+B5C;AAED,eAAe,SAAS,CAAC"}
|
|
@@ -1,12 +1,7 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
-
const dynamo_utils_1 = require("../dynamo-utils");
|
|
7
|
-
const TransactWriteBuilder_1 = __importDefault(require("../dynamo-utils/TransactWriteBuilder"));
|
|
8
|
-
const errors_1 = require("../errors");
|
|
9
|
-
const metadata_1 = __importDefault(require("../metadata"));
|
|
1
|
+
import { TransactGetBuilder } from "../dynamo-utils/index.js";
|
|
2
|
+
import TransactionBuilder from "../dynamo-utils/TransactWriteBuilder.js";
|
|
3
|
+
import { NotFoundError } from "../errors.js";
|
|
4
|
+
import Metadata from "../metadata/index.js";
|
|
10
5
|
/**
|
|
11
6
|
* Abstract class representing a join table for HasAndBelongsToMany relationships.
|
|
12
7
|
* This class should be extended for specific join table implementations.
|
|
@@ -37,8 +32,8 @@ class JoinTable {
|
|
|
37
32
|
*/
|
|
38
33
|
static async create(keys, options) {
|
|
39
34
|
const referentialIntegrityCheck = options?.referentialIntegrityCheck ?? true;
|
|
40
|
-
const transactionBuilder = new
|
|
41
|
-
const [rel1, rel2] =
|
|
35
|
+
const transactionBuilder = new TransactionBuilder();
|
|
36
|
+
const [rel1, rel2] = Metadata.getJoinTable(this.name);
|
|
42
37
|
const transactionProps = JoinTable.transactionProps(keys, rel2, rel1);
|
|
43
38
|
const lookupTableItem = await JoinTable.preFetch(transactionProps);
|
|
44
39
|
JoinTable.denormalizeLinkRecord(transactionBuilder, keys, rel1, rel2, lookupTableItem[transactionProps.ids.linkedEntityId], referentialIntegrityCheck);
|
|
@@ -52,8 +47,8 @@ class JoinTable {
|
|
|
52
47
|
* @param keys
|
|
53
48
|
*/
|
|
54
49
|
static async delete(keys) {
|
|
55
|
-
const transactionBuilder = new
|
|
56
|
-
const [rel1, rel2] =
|
|
50
|
+
const transactionBuilder = new TransactionBuilder();
|
|
51
|
+
const [rel1, rel2] = Metadata.getJoinTable(this.name);
|
|
57
52
|
JoinTable.deleteLink(transactionBuilder, keys, rel1, rel2);
|
|
58
53
|
JoinTable.deleteLink(transactionBuilder, keys, rel2, rel1);
|
|
59
54
|
await transactionBuilder.executeTransaction();
|
|
@@ -63,7 +58,7 @@ class JoinTable {
|
|
|
63
58
|
const idAlias = tableProps.defaultAttributes.id.alias;
|
|
64
59
|
const parentKey = JoinTable.buildForeignEntityKey(tableProps, entities.linkedEntity, ids.parentId);
|
|
65
60
|
const linkedKey = JoinTable.buildForeignEntityKey(tableProps, entities.parentEntity, ids.linkedEntityId);
|
|
66
|
-
const transactionGetBuilder = new
|
|
61
|
+
const transactionGetBuilder = new TransactGetBuilder();
|
|
67
62
|
transactionGetBuilder.addGet({
|
|
68
63
|
TableName: tableProps.name,
|
|
69
64
|
Key: parentKey
|
|
@@ -75,7 +70,7 @@ class JoinTable {
|
|
|
75
70
|
const transactionResults = await transactionGetBuilder.executeTransaction();
|
|
76
71
|
if (transactionResults.length !== 2) {
|
|
77
72
|
const errorMessage = this.preFetchNotFoundErrorMessage(transactionResults, entities, ids);
|
|
78
|
-
throw new
|
|
73
|
+
throw new NotFoundError(errorMessage);
|
|
79
74
|
}
|
|
80
75
|
return transactionResults.reduce((acc, res) => {
|
|
81
76
|
if (res.Item !== undefined) {
|
|
@@ -147,7 +142,7 @@ class JoinTable {
|
|
|
147
142
|
const { entity: linkedEntity, foreignKey: linkedKey } = linkedEntityMeta;
|
|
148
143
|
const parentId = keys[parentKey];
|
|
149
144
|
const linkedEntityId = keys[linkedKey];
|
|
150
|
-
const { name: tableName, partitionKeyAttribute } =
|
|
145
|
+
const { name: tableName, partitionKeyAttribute } = Metadata.getEntityTable(parentEntity.name);
|
|
151
146
|
transactionBuilder.addDelete({
|
|
152
147
|
TableName: tableName,
|
|
153
148
|
Key: this.joinTableKey(keys, parentEntityMeta, linkedEntityMeta),
|
|
@@ -167,7 +162,7 @@ class JoinTable {
|
|
|
167
162
|
static transactionProps(keys, parentEntityMeta, linkedEntityMeta) {
|
|
168
163
|
const { entity: parentEntity, foreignKey: parentFK } = parentEntityMeta;
|
|
169
164
|
const { entity: linkedEntity, foreignKey: linkedFK } = linkedEntityMeta;
|
|
170
|
-
const tableMetadata =
|
|
165
|
+
const tableMetadata = Metadata.getEntityTable(parentEntity.name);
|
|
171
166
|
const parentId = keys[parentFK];
|
|
172
167
|
const linkedEntityId = keys[linkedFK];
|
|
173
168
|
return {
|
|
@@ -181,7 +176,7 @@ class JoinTable {
|
|
|
181
176
|
{ entityId: ids.parentId, entityName: entities.linkedEntity.name },
|
|
182
177
|
{ entityId: ids.linkedEntityId, entityName: entities.parentEntity.name }
|
|
183
178
|
];
|
|
184
|
-
const tableMeta =
|
|
179
|
+
const tableMeta = Metadata.getEntityTable(entities.parentEntity.name);
|
|
185
180
|
const idAlias = tableMeta.defaultAttributes.id.alias;
|
|
186
181
|
const foundEntityIds = new Set(transactionResults
|
|
187
182
|
.filter(result => result.Item !== undefined)
|
|
@@ -195,4 +190,4 @@ class JoinTable {
|
|
|
195
190
|
return `Entities not found: ${missingEntityStr}`;
|
|
196
191
|
}
|
|
197
192
|
}
|
|
198
|
-
|
|
193
|
+
export default JoinTable;
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
export { default as JoinTable } from "./JoinTable";
|
|
1
|
+
export { default as JoinTable } from "./JoinTable.js";
|
|
2
2
|
//# sourceMappingURL=index.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/relationships/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,IAAI,SAAS,EAAE,MAAM,
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/relationships/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,IAAI,SAAS,EAAE,MAAM,gBAAgB,CAAC"}
|
|
@@ -1,8 +1 @@
|
|
|
1
|
-
|
|
2
|
-
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
-
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
-
};
|
|
5
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
-
exports.JoinTable = void 0;
|
|
7
|
-
var JoinTable_1 = require("./JoinTable");
|
|
8
|
-
Object.defineProperty(exports, "JoinTable", { enumerable: true, get: function () { return __importDefault(JoinTable_1).default; } });
|
|
1
|
+
export { default as JoinTable } from "./JoinTable.js";
|
package/dist/src/types.d.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { type NativeAttributeValue } from "@aws-sdk/util-dynamodb";
|
|
2
|
-
import type { BelongsToRelationship, RelationshipMetadata } from "./metadata";
|
|
3
|
-
import type DynaRecord from "./DynaRecord";
|
|
2
|
+
import type { BelongsToRelationship, RelationshipMetadata } from "./metadata/index.js";
|
|
3
|
+
import type DynaRecord from "./DynaRecord.js";
|
|
4
4
|
/**
|
|
5
5
|
* A utility type for branding primitives to ensure type safety with unique identifiers.
|
|
6
6
|
*/
|
package/dist/src/types.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../src/types.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,oBAAoB,EAAE,MAAM,wBAAwB,CAAC;AACnE,OAAO,KAAK,
|
|
1
|
+
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../src/types.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,oBAAoB,EAAE,MAAM,wBAAwB,CAAC;AACnE,OAAO,KAAK,EACV,qBAAqB,EACrB,oBAAoB,EACrB,MAAM,qBAAqB,CAAC;AAC7B,OAAO,KAAK,UAAU,MAAM,iBAAiB,CAAC;AAE9C;;GAEG;AACH,MAAM,MAAM,KAAK,CAAC,CAAC,EAAE,CAAC,IAAI,CAAC,GAAG;IAAE,OAAO,EAAE,CAAC,CAAA;CAAE,CAAC;AAE7C;;GAEG;AACH,MAAM,MAAM,OAAO,GAAG,KAAK,CAAC,MAAM,EAAE,SAAS,CAAC,CAAC;AAE/C;;GAEG;AACH,MAAM,MAAM,YAAY,GAAG,KAAK,CAAC,MAAM,EAAE,cAAc,CAAC,CAAC;AAEzD;;;;GAIG;AACH,MAAM,MAAM,UAAU,CAAC,CAAC,SAAS,UAAU,GAAG,UAAU,IAAI,KAAK,CAC/D,MAAM,EACN;IAAE,IAAI,EAAE,YAAY,CAAC;IAAC,MAAM,EAAE,CAAC,CAAA;CAAE,CAClC,CAAC;AAEF;;;;GAIG;AACH,MAAM,MAAM,kBAAkB,CAAC,CAAC,SAAS,UAAU,GAAG,UAAU,IAAI,QAAQ,CAC1E,KAAK,CAAC,MAAM,EAAE;IAAE,IAAI,EAAE,oBAAoB,CAAC;IAAC,MAAM,EAAE,CAAC,CAAA;CAAE,CAAC,CACzD,CAAC;AAEF;;GAEG;AACH,MAAM,MAAM,kBAAkB,GAAG,MAAM,UAAU,GAAG,UAAU,CAAC;AAE/D;;GAEG;AACH,MAAM,MAAM,eAAe,GAAG,MAAM,CAAC,MAAM,EAAE,oBAAoB,CAAC,CAAC;AAEnE;;GAEG;AACH,MAAM,MAAM,SAAS,GAAG,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;AAE/C;;GAEG;AACH,MAAM,MAAM,QAAQ,CAAC,CAAC,IAAI,CAAC,GAAG,SAAS,CAAC;AAExC;;GAEG;AACH,MAAM,MAAM,QAAQ,CAAC,CAAC,IAAI,CAAC,GAAG,IAAI,CAAC;AAEnC;;GAEG;AACH,MAAM,MAAM,kBAAkB,GAAG,MAAM,CAAC,MAAM,EAAE,oBAAoB,CAAC,CAAC;AAEtE;;GAEG;AACH,MAAM,WAAW,mBAAmB;IAClC,eAAe,EAAE,kBAAkB,CAAC;IACpC,sBAAsB,EAAE,qBAAqB,EAAE,CAAC;CACjD;AAED;;GAEG;AACH,MAAM,MAAM,YAAY,CAAC,CAAC,EAAE,CAAC,SAAS,MAAM,CAAC,IAAI,IAAI,CAAC,CAAC,EAAE,CAAC,CAAC,GACzD,OAAO,CAAC,IAAI,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,CAAC;AAEtB;;;GAGG;AACH,MAAM,MAAM,KAAK,CAAC,CAAC,IAAI,CAAC,SAAS,CAAC,GAAG,CAAC,GAAG,IAAI,GAAG,KAAK,CAAC;AAEtD;;;;;;GAMG;AACH,MAAM,MAAM,WAAW,CAAC,CAAC,IAAI,CAAC,UAAU,CAAC,CAAC,GAAG,OAAO,UAAU,CAAC;AAE/D;;GAEG;AACH,MAAM,MAAM,YAAY,CAAC,CAAC,EAAE,CAAC,SAAS,MAAM,CAAC,IAAI,IAAI,CAAC,CAAC,EAAE,CAAC,CAAC,GAAG;KAC3D,CAAC,IAAI,CAAC,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC;CACjB,CAAC"}
|
package/dist/src/types.js
CHANGED
|
@@ -1,2 +1 @@
|
|
|
1
|
-
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
1
|
+
export {};
|
package/dist/src/utils.d.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import type DynaRecord from "./DynaRecord";
|
|
2
|
-
import type { DynamoTableItem, Nullable } from "./types";
|
|
3
|
-
import { type EntityAttributesOnly } from "./operations";
|
|
1
|
+
import type DynaRecord from "./DynaRecord.js";
|
|
2
|
+
import type { DynamoTableItem, Nullable } from "./types.js";
|
|
3
|
+
import { type EntityAttributesOnly } from "./operations/index.js";
|
|
4
4
|
/**
|
|
5
5
|
* Convert an entity to its aliased table item fields to for dynamo interactions
|
|
6
6
|
* @param entityClassName
|
package/dist/src/utils.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"utils.d.ts","sourceRoot":"","sources":["../../src/utils.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,UAAU,MAAM,
|
|
1
|
+
{"version":3,"file":"utils.d.ts","sourceRoot":"","sources":["../../src/utils.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,UAAU,MAAM,iBAAiB,CAAC;AAC9C,OAAO,KAAK,EAAE,eAAe,EAAE,QAAQ,EAAE,MAAM,YAAY,CAAC;AAE5D,OAAO,EAAE,KAAK,oBAAoB,EAAE,MAAM,uBAAuB,CAAC;AAElE;;;;;GAKG;AACH,eAAO,MAAM,iBAAiB,GAC5B,aAAa,UAAU,UAAU,EACjC,YAAY,OAAO,CAAC,UAAU,CAAC,KAC9B,eAoBF,CAAC;AAEF;;;;;GAKG;AACH,eAAO,MAAM,iBAAiB,GAAI,CAAC,SAAS,UAAU,EACpD,aAAa,UAAU,CAAC,EACxB,WAAW,eAAe,KACzB,CAsBF,CAAC;AAEF;;GAEG;AACH,eAAO,MAAM,cAAc,GAAI,CAAC,SAAS,UAAU,EACjD,aAAa,UAAU,CAAC,EACxB,YAAY,oBAAoB,CAAC,CAAC,CAAC,KAClC,CAUF,CAAC;AAEF;;GAEG;AACH,eAAO,MAAM,aAAa,GACxB,QAAQ,UAAU,EAClB,KAAK,MAAM,KACV,GAAG,IAAI,MAAM,UAEf,CAAC;AAEF;;;;;GAKG;AAEH,eAAO,MAAM,aAAa,GAAI,CAAC,EAC7B,QAAQ,OAAO,CAAC,UAAU,CAAC,EAC3B,KAAK,WAAW,KACf,GAAG,IAAI,MAAM,CAEf,CAAC;AAEF;;;;;GAKG;AACH,eAAO,MAAM,UAAU,GAAI,CAAC,EAAE,OAAO,CAAC,EAAE,EAAE,MAAM,MAAM,KAAG,CAAC,EAAE,EAI3D,CAAC;AAEF;;;;;GAKG;AACH,eAAO,MAAM,QAAQ,GAAI,OAAO,OAAO,KAAG,KAAK,IAAI,MAElD,CAAC;AAEF;;;;;;;;;;;;;;;;;GAiBG;AACH,eAAO,MAAM,UAAU,GAAI,OAAO,SAAS,oBAAoB,CAAC,UAAU,CAAC,EACzE,QAAQ,OAAO,EACf,KAAK,MAAM,OAAO,EAClB,OAAO,OAAO,KACb,IAEF,CAAC;AAEF;;;;GAIG;AACH,eAAO,MAAM,gBAAgB,GAAI,KAAK,OAAO,KAAG,GAAG,IAAI,QAAQ,CAAC,MAAM,CAErE,CAAC"}
|
package/dist/src/utils.js
CHANGED
|
@@ -1,18 +1,12 @@
|
|
|
1
|
-
|
|
2
|
-
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
-
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
-
};
|
|
5
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
-
exports.isNullableString = exports.safeAssign = exports.isString = exports.chunkArray = exports.isKeyOfObject = exports.isKeyOfEntity = exports.createInstance = exports.tableItemToEntity = exports.entityToTableItem = void 0;
|
|
7
|
-
const metadata_1 = __importDefault(require("./metadata"));
|
|
1
|
+
import Metadata from "./metadata/index.js";
|
|
8
2
|
/**
|
|
9
3
|
* Convert an entity to its aliased table item fields to for dynamo interactions
|
|
10
4
|
* @param entityClassName
|
|
11
5
|
* @param entityData
|
|
12
6
|
* @returns
|
|
13
7
|
*/
|
|
14
|
-
const entityToTableItem = (EntityClass, entityData) => {
|
|
15
|
-
const attributesMeta =
|
|
8
|
+
export const entityToTableItem = (EntityClass, entityData) => {
|
|
9
|
+
const attributesMeta = Metadata.getEntityAttributes(EntityClass.name);
|
|
16
10
|
return Object.entries(entityData).reduce((acc, [key, rawVal]) => {
|
|
17
11
|
if (key in attributesMeta) {
|
|
18
12
|
const attrMeta = attributesMeta[key];
|
|
@@ -27,52 +21,48 @@ const entityToTableItem = (EntityClass, entityData) => {
|
|
|
27
21
|
return acc;
|
|
28
22
|
}, {});
|
|
29
23
|
};
|
|
30
|
-
exports.entityToTableItem = entityToTableItem;
|
|
31
24
|
/**
|
|
32
25
|
* Serialize a table item to its associated Entity class, using the class attribute property names
|
|
33
26
|
* @param EntityClass
|
|
34
27
|
* @param tableItem
|
|
35
28
|
* @returns
|
|
36
29
|
*/
|
|
37
|
-
const tableItemToEntity = (EntityClass, tableItem) => {
|
|
38
|
-
const tableAttributes =
|
|
30
|
+
export const tableItemToEntity = (EntityClass, tableItem) => {
|
|
31
|
+
const tableAttributes = Metadata.getEntityTableAttributes(EntityClass.name);
|
|
39
32
|
const entity = new EntityClass();
|
|
40
33
|
Object.keys(tableItem).forEach(attrName => {
|
|
41
34
|
if (attrName in tableAttributes) {
|
|
42
35
|
const attrMeta = tableAttributes[attrName];
|
|
43
36
|
const { name: entityKey, serializers } = attrMeta;
|
|
44
|
-
if (
|
|
37
|
+
if (isKeyOfEntity(entity, entityKey)) {
|
|
45
38
|
const rawVal = tableItem[attrName];
|
|
46
39
|
const val = serializers?.toEntityAttribute === undefined
|
|
47
40
|
? rawVal
|
|
48
41
|
: serializers.toEntityAttribute(rawVal);
|
|
49
|
-
|
|
42
|
+
safeAssign(entity, entityKey, val);
|
|
50
43
|
}
|
|
51
44
|
}
|
|
52
45
|
});
|
|
53
46
|
return entity;
|
|
54
47
|
};
|
|
55
|
-
exports.tableItemToEntity = tableItemToEntity;
|
|
56
48
|
/**
|
|
57
49
|
* Create an instance of a dyna record class
|
|
58
50
|
*/
|
|
59
|
-
const createInstance = (EntityClass, attributes) => {
|
|
51
|
+
export const createInstance = (EntityClass, attributes) => {
|
|
60
52
|
const entity = new EntityClass();
|
|
61
53
|
Object.entries(attributes).forEach(([attrName, val]) => {
|
|
62
|
-
if (
|
|
63
|
-
|
|
54
|
+
if (isKeyOfEntity(entity, attrName)) {
|
|
55
|
+
safeAssign(entity, attrName, val);
|
|
64
56
|
}
|
|
65
57
|
});
|
|
66
58
|
return entity;
|
|
67
59
|
};
|
|
68
|
-
exports.createInstance = createInstance;
|
|
69
60
|
/**
|
|
70
61
|
* Type guard to check if the key is defined on the entity
|
|
71
62
|
*/
|
|
72
|
-
const isKeyOfEntity = (entity, key) => {
|
|
63
|
+
export const isKeyOfEntity = (entity, key) => {
|
|
73
64
|
return key in entity;
|
|
74
65
|
};
|
|
75
|
-
exports.isKeyOfEntity = isKeyOfEntity;
|
|
76
66
|
/**
|
|
77
67
|
* Type guard to check if the key is a defined property on the entity
|
|
78
68
|
* @param entity
|
|
@@ -80,30 +70,27 @@ exports.isKeyOfEntity = isKeyOfEntity;
|
|
|
80
70
|
* @returns
|
|
81
71
|
*/
|
|
82
72
|
// eslint-disable-next-line @typescript-eslint/no-unnecessary-type-parameters -- Generic T needed for narrowing key to keyof T at call sites
|
|
83
|
-
const isKeyOfObject = (entity, key) => {
|
|
73
|
+
export const isKeyOfObject = (entity, key) => {
|
|
84
74
|
return key in entity;
|
|
85
75
|
};
|
|
86
|
-
exports.isKeyOfObject = isKeyOfObject;
|
|
87
76
|
/**
|
|
88
77
|
* Break an array into chunks
|
|
89
78
|
* @param array
|
|
90
79
|
* @param size
|
|
91
80
|
* @returns Array split into chunks of given size
|
|
92
81
|
*/
|
|
93
|
-
const chunkArray = (array, size) => {
|
|
82
|
+
export const chunkArray = (array, size) => {
|
|
94
83
|
return Array.from({ length: Math.ceil(array.length / size) }, (_, index) => array.slice(index * size, (index + 1) * size));
|
|
95
84
|
};
|
|
96
|
-
exports.chunkArray = chunkArray;
|
|
97
85
|
/**
|
|
98
86
|
* Checks if the given value is a string.
|
|
99
87
|
*
|
|
100
88
|
* @param value - The value to check. This can be any type as the function is meant to validate if it's a string.
|
|
101
89
|
* @returns `true` if `value` is a string; otherwise, `false`.
|
|
102
90
|
*/
|
|
103
|
-
const isString = (value) => {
|
|
91
|
+
export const isString = (value) => {
|
|
104
92
|
return typeof value === "string";
|
|
105
93
|
};
|
|
106
|
-
exports.isString = isString;
|
|
107
94
|
/**
|
|
108
95
|
* Safely assigns a value to a property of an object.
|
|
109
96
|
* It's useful for dynamically assigning properties to objects where the property names might be known but the types could vary.
|
|
@@ -122,16 +109,14 @@ exports.isString = isString;
|
|
|
122
109
|
* let entity = { id: "123" };
|
|
123
110
|
* safeAssign(entity, "name", "Jane Doe");
|
|
124
111
|
*/
|
|
125
|
-
const safeAssign = (object, key, value) => {
|
|
112
|
+
export const safeAssign = (object, key, value) => {
|
|
126
113
|
object[key] = value;
|
|
127
114
|
};
|
|
128
|
-
exports.safeAssign = safeAssign;
|
|
129
115
|
/**
|
|
130
116
|
* Type guard to check if a string is a Nullable<string>
|
|
131
117
|
* @param val
|
|
132
118
|
* @returns
|
|
133
119
|
*/
|
|
134
|
-
const isNullableString = (val) => {
|
|
120
|
+
export const isNullableString = (val) => {
|
|
135
121
|
return typeof val === "string" || val === null;
|
|
136
122
|
};
|
|
137
|
-
exports.isNullableString = isNullableString;
|
package/package.json
CHANGED
|
@@ -1,20 +1,29 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "dyna-record",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.7.0",
|
|
4
4
|
"description": "Typescript Data Modeler and ORM for Dynamo",
|
|
5
|
-
"
|
|
6
|
-
"types": "dist/index.d.ts",
|
|
5
|
+
"type": "module",
|
|
6
|
+
"types": "./dist/index.d.ts",
|
|
7
|
+
"sideEffects": false,
|
|
8
|
+
"exports": {
|
|
9
|
+
".": {
|
|
10
|
+
"types": "./dist/index.d.ts",
|
|
11
|
+
"default": "./dist/index.js"
|
|
12
|
+
},
|
|
13
|
+
"./package.json": "./package.json"
|
|
14
|
+
},
|
|
7
15
|
"scripts": {
|
|
8
16
|
"build": "tsc",
|
|
9
|
-
"watch": "tsc
|
|
17
|
+
"watch": "tsc --watch",
|
|
10
18
|
"typecheck": "tsc --noEmit && tsc -p tsconfig.dev.json --noEmit",
|
|
11
19
|
"typecheck:tests": "tsc -p tsconfig.dev.json --noEmit",
|
|
12
|
-
"test": "tsc -p tsconfig.dev.json --noEmit &&
|
|
13
|
-
"test:watch": "
|
|
20
|
+
"test": "tsc -p tsconfig.dev.json --noEmit && vitest run",
|
|
21
|
+
"test:watch": "vitest",
|
|
14
22
|
"eslint": "npx eslint .",
|
|
15
23
|
"eslint:fix": "npx eslint . --fix",
|
|
16
24
|
"prettier": "npx prettier . --write",
|
|
17
|
-
"docs": "npx typedoc"
|
|
25
|
+
"docs": "npx typedoc",
|
|
26
|
+
"prepublishOnly": "npm run build && npx publint"
|
|
18
27
|
},
|
|
19
28
|
"repository": {
|
|
20
29
|
"type": "git",
|
|
@@ -30,32 +39,27 @@
|
|
|
30
39
|
"@aws-sdk/client-dynamodb": "^3.502.0",
|
|
31
40
|
"@aws-sdk/lib-dynamodb": "^3.502.0",
|
|
32
41
|
"@aws-sdk/util-dynamodb": "^3.509.0",
|
|
33
|
-
"uuid": "^9.0.1",
|
|
34
42
|
"zod": "^4.3.6"
|
|
35
43
|
},
|
|
36
44
|
"devDependencies": {
|
|
37
|
-
"@
|
|
38
|
-
"@
|
|
39
|
-
"@
|
|
40
|
-
"@
|
|
41
|
-
"
|
|
42
|
-
"@types/uuid": "^9.0.8",
|
|
43
|
-
"@typescript-eslint/eslint-plugin": "^8.56.1",
|
|
44
|
-
"eslint": "^9.39.3",
|
|
45
|
+
"@eslint/js": "^10.0.1",
|
|
46
|
+
"@types/node": "^22.19.19",
|
|
47
|
+
"@typescript-eslint/eslint-plugin": "^8.60.0",
|
|
48
|
+
"@vitest/coverage-v8": "^3.2.4",
|
|
49
|
+
"eslint": "^10.4.0",
|
|
45
50
|
"eslint-config-prettier": "^10.1.8",
|
|
46
51
|
"globals": "^16.5.0",
|
|
47
|
-
"jest": "^29.7.0",
|
|
48
52
|
"prettier": "^3.2.5",
|
|
49
|
-
"
|
|
50
|
-
"
|
|
51
|
-
"typedoc": "^
|
|
52
|
-
"
|
|
53
|
-
"typescript": "^
|
|
54
|
-
"
|
|
53
|
+
"publint": "^0.3.21",
|
|
54
|
+
"typedoc": "^0.28.19",
|
|
55
|
+
"typedoc-plugin-missing-exports": "^4.1.3",
|
|
56
|
+
"typescript": "^6.0.3",
|
|
57
|
+
"typescript-eslint": "^8.60.0",
|
|
58
|
+
"vitest": "^3.2.4"
|
|
55
59
|
},
|
|
56
60
|
"engines": {
|
|
57
61
|
"npm": ">=10.0.0",
|
|
58
|
-
"node": ">=
|
|
62
|
+
"node": ">=22.12.0"
|
|
59
63
|
},
|
|
60
64
|
"files": [
|
|
61
65
|
"dist/**/*"
|