dyna-record 0.4.11 → 0.5.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 +53 -6
- package/dist/src/DynaRecord.d.ts +28 -19
- package/dist/src/DynaRecord.d.ts.map +1 -1
- package/dist/src/DynaRecord.js +24 -6
- package/dist/src/Logger.d.ts.map +1 -1
- package/dist/src/Logger.js +0 -1
- 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 -5
- package/dist/src/decorators/Table.d.ts +1 -1
- package/dist/src/decorators/Table.d.ts.map +1 -1
- package/dist/src/decorators/Table.js +2 -4
- package/dist/src/decorators/attributes/BooleanAttribute.d.ts.map +1 -1
- package/dist/src/decorators/attributes/BooleanAttribute.js +7 -9
- package/dist/src/decorators/attributes/DateAttribute.d.ts.map +1 -1
- package/dist/src/decorators/attributes/DateAttribute.js +8 -10
- package/dist/src/decorators/attributes/EnumAttribute.d.ts.map +1 -1
- package/dist/src/decorators/attributes/EnumAttribute.js +7 -9
- package/dist/src/decorators/attributes/ForeignKeyAttribute.d.ts.map +1 -1
- package/dist/src/decorators/attributes/ForeignKeyAttribute.js +9 -11
- package/dist/src/decorators/attributes/NumberAttribute.d.ts.map +1 -1
- package/dist/src/decorators/attributes/NumberAttribute.js +7 -9
- package/dist/src/decorators/attributes/ObjectAttribute.d.ts +40 -17
- package/dist/src/decorators/attributes/ObjectAttribute.d.ts.map +1 -1
- package/dist/src/decorators/attributes/ObjectAttribute.js +80 -29
- package/dist/src/decorators/attributes/PartitionKeyAttribute.d.ts.map +1 -1
- package/dist/src/decorators/attributes/PartitionKeyAttribute.js +6 -8
- package/dist/src/decorators/attributes/SortKeyAttribute.d.ts.map +1 -1
- package/dist/src/decorators/attributes/SortKeyAttribute.js +6 -8
- package/dist/src/decorators/attributes/StringAttribute.d.ts.map +1 -1
- package/dist/src/decorators/attributes/StringAttribute.js +7 -9
- package/dist/src/decorators/attributes/serializers.d.ts +4 -3
- package/dist/src/decorators/attributes/serializers.d.ts.map +1 -1
- package/dist/src/decorators/attributes/serializers.js +2 -1
- package/dist/src/decorators/attributes/types.d.ts +20 -6
- package/dist/src/decorators/attributes/types.d.ts.map +1 -1
- package/dist/src/decorators/relationships/BelongsTo.d.ts.map +1 -1
- package/dist/src/decorators/relationships/BelongsTo.js +7 -9
- package/dist/src/decorators/relationships/HasAndBelongsToMany.d.ts.map +1 -1
- package/dist/src/decorators/relationships/HasAndBelongsToMany.js +13 -15
- package/dist/src/decorators/relationships/HasMany.d.ts.map +1 -1
- package/dist/src/decorators/relationships/HasMany.js +15 -17
- package/dist/src/decorators/relationships/HasOne.d.ts.map +1 -1
- package/dist/src/decorators/relationships/HasOne.js +7 -9
- package/dist/src/metadata/AttributeMetadata.d.ts +3 -0
- package/dist/src/metadata/AttributeMetadata.d.ts.map +1 -1
- package/dist/src/metadata/AttributeMetadata.js +5 -0
- package/dist/src/metadata/EntityMetadata.d.ts +2 -2
- package/dist/src/metadata/EntityMetadata.d.ts.map +1 -1
- package/dist/src/metadata/EntityMetadata.js +8 -1
- package/dist/src/metadata/MetadataStorage.d.ts.map +1 -1
- package/dist/src/metadata/MetadataStorage.js +6 -6
- package/dist/src/metadata/TableMetadata.d.ts.map +1 -1
- package/dist/src/metadata/TableMetadata.js +7 -1
- package/dist/src/metadata/relationship-metadata/BelongsToRelationship.d.ts.map +1 -1
- package/dist/src/metadata/relationship-metadata/BelongsToRelationship.js +1 -3
- package/dist/src/metadata/relationship-metadata/HasAndBelongsToManyRelationship.d.ts.map +1 -1
- package/dist/src/metadata/relationship-metadata/HasAndBelongsToManyRelationship.js +1 -3
- package/dist/src/metadata/relationship-metadata/HasManyRelationship.d.ts.map +1 -1
- package/dist/src/metadata/relationship-metadata/HasManyRelationship.js +1 -3
- package/dist/src/metadata/relationship-metadata/HasOneRelationship.d.ts.map +1 -1
- package/dist/src/metadata/relationship-metadata/HasOneRelationship.js +1 -3
- package/dist/src/metadata/relationship-metadata/OwnedByRelationship.d.ts.map +1 -1
- package/dist/src/metadata/relationship-metadata/OwnedByRelationship.js +1 -3
- package/dist/src/metadata/types.d.ts +14 -3
- package/dist/src/metadata/types.d.ts.map +1 -1
- package/dist/src/metadata/utils.js +4 -4
- package/dist/src/operations/Create/Create.js +3 -5
- package/dist/src/operations/Delete/Delete.d.ts.map +1 -1
- package/dist/src/operations/Delete/Delete.js +3 -2
- package/dist/src/operations/FindById/FindById.d.ts.map +1 -1
- package/dist/src/operations/FindById/FindById.js +4 -4
- package/dist/src/operations/Query/Query.d.ts.map +1 -1
- package/dist/src/operations/Query/Query.js +2 -1
- package/dist/src/operations/Update/Update.d.ts +6 -1
- package/dist/src/operations/Update/Update.d.ts.map +1 -1
- package/dist/src/operations/Update/Update.js +41 -17
- package/dist/src/operations/Update/types.d.ts +14 -4
- package/dist/src/operations/Update/types.d.ts.map +1 -1
- package/dist/src/operations/types.d.ts +1 -1
- package/dist/src/operations/types.d.ts.map +1 -1
- package/dist/src/operations/utils/expressionBuilder.d.ts +4 -3
- package/dist/src/operations/utils/expressionBuilder.d.ts.map +1 -1
- package/dist/src/operations/utils/expressionBuilder.js +66 -2
- package/dist/src/operations/utils/flattenObjectForUpdate.d.ts +19 -0
- package/dist/src/operations/utils/flattenObjectForUpdate.d.ts.map +1 -0
- package/dist/src/operations/utils/flattenObjectForUpdate.js +45 -0
- package/dist/src/operations/utils/index.d.ts +2 -0
- package/dist/src/operations/utils/index.d.ts.map +1 -1
- package/dist/src/operations/utils/index.js +2 -0
- package/dist/src/operations/utils/mergePartialObjectAttributes.d.ts +8 -0
- package/dist/src/operations/utils/mergePartialObjectAttributes.d.ts.map +1 -0
- package/dist/src/operations/utils/mergePartialObjectAttributes.js +60 -0
- package/dist/src/operations/utils/types.d.ts +16 -0
- package/dist/src/operations/utils/types.d.ts.map +1 -1
- package/dist/src/operations/utils/utils.d.ts +2 -2
- package/dist/src/operations/utils/utils.d.ts.map +1 -1
- package/dist/src/query-utils/QueryBuilder.d.ts.map +1 -1
- package/dist/src/query-utils/QueryBuilder.js +11 -7
- package/dist/src/query-utils/types.d.ts.map +1 -1
- package/dist/src/relationships/JoinTable.d.ts.map +1 -1
- package/dist/src/relationships/JoinTable.js +4 -3
- package/dist/src/utils.d.ts +4 -4
- package/dist/src/utils.d.ts.map +1 -1
- package/dist/src/utils.js +13 -11
- package/package.json +10 -12
|
@@ -79,7 +79,8 @@ class JoinTable {
|
|
|
79
79
|
}
|
|
80
80
|
return transactionResults.reduce((acc, res) => {
|
|
81
81
|
if (res.Item !== undefined) {
|
|
82
|
-
|
|
82
|
+
const id = res.Item[idAlias];
|
|
83
|
+
acc[id] = res.Item;
|
|
83
84
|
}
|
|
84
85
|
return acc;
|
|
85
86
|
}, {});
|
|
@@ -183,8 +184,8 @@ class JoinTable {
|
|
|
183
184
|
const tableMeta = metadata_1.default.getEntityTable(entities.parentEntity.name);
|
|
184
185
|
const idAlias = tableMeta.defaultAttributes.id.alias;
|
|
185
186
|
const foundEntityIds = new Set(transactionResults
|
|
186
|
-
.filter(result => result
|
|
187
|
-
.map(result => result.Item
|
|
187
|
+
.filter(result => result.Item !== undefined)
|
|
188
|
+
.map(result => result.Item[idAlias]));
|
|
188
189
|
const missingEntities = joinedEntityData.filter(entityData => {
|
|
189
190
|
return !foundEntityIds.has(entityData.entityId); // If not in Set, it's missing
|
|
190
191
|
});
|
package/dist/src/utils.d.ts
CHANGED
|
@@ -7,7 +7,7 @@ import { type EntityAttributesOnly } from "./operations";
|
|
|
7
7
|
* @param entityData
|
|
8
8
|
* @returns
|
|
9
9
|
*/
|
|
10
|
-
export declare const entityToTableItem:
|
|
10
|
+
export declare const entityToTableItem: (EntityClass: new () => DynaRecord, entityData: Partial<DynaRecord>) => DynamoTableItem;
|
|
11
11
|
/**
|
|
12
12
|
* Serialize a table item to its associated Entity class, using the class attribute property names
|
|
13
13
|
* @param EntityClass
|
|
@@ -29,7 +29,7 @@ export declare const isKeyOfEntity: (entity: DynaRecord, key: string) => key is
|
|
|
29
29
|
* @param key
|
|
30
30
|
* @returns
|
|
31
31
|
*/
|
|
32
|
-
export declare const isKeyOfObject: <T>(entity: Partial<DynaRecord>, key:
|
|
32
|
+
export declare const isKeyOfObject: <T>(entity: Partial<DynaRecord>, key: PropertyKey) => key is keyof T;
|
|
33
33
|
/**
|
|
34
34
|
* Break an array into chunks
|
|
35
35
|
* @param array
|
|
@@ -43,7 +43,7 @@ export declare const chunkArray: <T>(array: T[], size: number) => T[][];
|
|
|
43
43
|
* @param value - The value to check. This can be any type as the function is meant to validate if it's a string.
|
|
44
44
|
* @returns `true` if `value` is a string; otherwise, `false`.
|
|
45
45
|
*/
|
|
46
|
-
export declare const isString: (value:
|
|
46
|
+
export declare const isString: (value: unknown) => value is string;
|
|
47
47
|
/**
|
|
48
48
|
* Safely assigns a value to a property of an object.
|
|
49
49
|
* It's useful for dynamically assigning properties to objects where the property names might be known but the types could vary.
|
|
@@ -62,7 +62,7 @@ export declare const isString: (value: any) => value is string;
|
|
|
62
62
|
* let entity = { id: "123" };
|
|
63
63
|
* safeAssign(entity, "name", "Jane Doe");
|
|
64
64
|
*/
|
|
65
|
-
export declare const safeAssign: <TObject extends EntityAttributesOnly<DynaRecord
|
|
65
|
+
export declare const safeAssign: <TObject extends EntityAttributesOnly<DynaRecord>>(object: TObject, key: keyof TObject, value: unknown) => void;
|
|
66
66
|
/**
|
|
67
67
|
* Type guard to check if a string is a Nullable<string>
|
|
68
68
|
* @param val
|
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,cAAc,CAAC;AAC3C,OAAO,KAAK,EAAE,eAAe,EAAE,QAAQ,EAAE,MAAM,SAAS,CAAC;AAEzD,OAAO,EAAE,KAAK,oBAAoB,EAAE,MAAM,cAAc,CA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;;GAIG;AACH,eAAO,MAAM,gBAAgB,QAAS,OAAO,KAAG,GAAG,IAAI,QAAQ,CAAC,MAAM,CAErE,CAAC"}
|
package/dist/src/utils.js
CHANGED
|
@@ -13,15 +13,16 @@ const metadata_1 = __importDefault(require("./metadata"));
|
|
|
13
13
|
*/
|
|
14
14
|
const entityToTableItem = (EntityClass, entityData) => {
|
|
15
15
|
const attributesMeta = metadata_1.default.getEntityAttributes(EntityClass.name);
|
|
16
|
-
return Object.entries(entityData).reduce((acc, [key,
|
|
17
|
-
|
|
18
|
-
|
|
16
|
+
return Object.entries(entityData).reduce((acc, [key, rawVal]) => {
|
|
17
|
+
if (key in attributesMeta) {
|
|
18
|
+
const attrMeta = attributesMeta[key];
|
|
19
19
|
const { alias, serializers } = attrMeta;
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
20
|
+
const val = rawVal;
|
|
21
|
+
// eslint-disable-next-line @typescript-eslint/no-unsafe-assignment -- DynamoTableItem values are NativeAttributeValue (any) from AWS SDK
|
|
22
|
+
acc[alias] =
|
|
23
|
+
serializers === undefined || val === null
|
|
24
|
+
? val
|
|
25
|
+
: serializers.toTableAttribute(val);
|
|
25
26
|
}
|
|
26
27
|
return acc;
|
|
27
28
|
}, {});
|
|
@@ -37,14 +38,14 @@ const tableItemToEntity = (EntityClass, tableItem) => {
|
|
|
37
38
|
const tableAttributes = metadata_1.default.getEntityTableAttributes(EntityClass.name);
|
|
38
39
|
const entity = new EntityClass();
|
|
39
40
|
Object.keys(tableItem).forEach(attrName => {
|
|
40
|
-
|
|
41
|
-
|
|
41
|
+
if (attrName in tableAttributes) {
|
|
42
|
+
const attrMeta = tableAttributes[attrName];
|
|
42
43
|
const { name: entityKey, serializers } = attrMeta;
|
|
43
44
|
if ((0, exports.isKeyOfEntity)(entity, entityKey)) {
|
|
44
45
|
const rawVal = tableItem[attrName];
|
|
45
46
|
const val = serializers?.toEntityAttribute === undefined
|
|
46
47
|
? rawVal
|
|
47
|
-
: serializers
|
|
48
|
+
: serializers.toEntityAttribute(rawVal);
|
|
48
49
|
(0, exports.safeAssign)(entity, entityKey, val);
|
|
49
50
|
}
|
|
50
51
|
}
|
|
@@ -78,6 +79,7 @@ exports.isKeyOfEntity = isKeyOfEntity;
|
|
|
78
79
|
* @param key
|
|
79
80
|
* @returns
|
|
80
81
|
*/
|
|
82
|
+
// eslint-disable-next-line @typescript-eslint/no-unnecessary-type-parameters -- Generic T needed for narrowing key to keyof T at call sites
|
|
81
83
|
const isKeyOfObject = (entity, key) => {
|
|
82
84
|
return key in entity;
|
|
83
85
|
};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "dyna-record",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.5.1",
|
|
4
4
|
"description": "Typescript Data Modeler and ORM for Dynamo",
|
|
5
5
|
"main": "dist/index.js",
|
|
6
6
|
"types": "dist/index.d.ts",
|
|
@@ -11,8 +11,8 @@
|
|
|
11
11
|
"typecheck:tests": "tsc -p tsconfig.dev.json --noEmit",
|
|
12
12
|
"test": "tsc -p tsconfig.dev.json --noEmit && jest",
|
|
13
13
|
"test:watch": "jest --watch",
|
|
14
|
-
"eslint": "npx eslint .
|
|
15
|
-
"eslint:fix": "npx eslint . --
|
|
14
|
+
"eslint": "npx eslint .",
|
|
15
|
+
"eslint:fix": "npx eslint . --fix",
|
|
16
16
|
"prettier": "npx prettier . --write",
|
|
17
17
|
"docs": "npx typedoc"
|
|
18
18
|
},
|
|
@@ -35,25 +35,23 @@
|
|
|
35
35
|
},
|
|
36
36
|
"devDependencies": {
|
|
37
37
|
"@aws-sdk/types": "^3.502.0",
|
|
38
|
+
"@eslint/js": "^9.39.3",
|
|
38
39
|
"@tsconfig/recommended": "^1.0.3",
|
|
39
40
|
"@types/jest": "^29.5.12",
|
|
40
41
|
"@types/node": "^20.11.16",
|
|
41
42
|
"@types/uuid": "^9.0.8",
|
|
42
|
-
"@typescript-eslint/eslint-plugin": "^
|
|
43
|
-
"
|
|
44
|
-
"eslint": "^
|
|
45
|
-
"
|
|
46
|
-
"eslint-config-standard-with-typescript": "^43.0.1",
|
|
47
|
-
"eslint-plugin-import": "^2.29.1",
|
|
48
|
-
"eslint-plugin-n": "^16.6.2",
|
|
49
|
-
"eslint-plugin-promise": "^6.1.1",
|
|
43
|
+
"@typescript-eslint/eslint-plugin": "^8.56.1",
|
|
44
|
+
"eslint": "^9.39.3",
|
|
45
|
+
"eslint-config-prettier": "^10.1.8",
|
|
46
|
+
"globals": "^16.5.0",
|
|
50
47
|
"jest": "^29.7.0",
|
|
51
48
|
"prettier": "^3.2.5",
|
|
52
49
|
"ts-jest": "^29.1.2",
|
|
53
50
|
"ts-node": "^10.9.2",
|
|
54
51
|
"typedoc": "^0.27.6",
|
|
55
52
|
"typedoc-plugin-missing-exports": "^3.1.0",
|
|
56
|
-
"typescript": "^5.7.2"
|
|
53
|
+
"typescript": "^5.7.2",
|
|
54
|
+
"typescript-eslint": "^8.56.1"
|
|
57
55
|
},
|
|
58
56
|
"engines": {
|
|
59
57
|
"npm": ">=10.0.0",
|