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.
Files changed (106) hide show
  1. package/README.md +53 -6
  2. package/dist/src/DynaRecord.d.ts +28 -19
  3. package/dist/src/DynaRecord.d.ts.map +1 -1
  4. package/dist/src/DynaRecord.js +24 -6
  5. package/dist/src/Logger.d.ts.map +1 -1
  6. package/dist/src/Logger.js +0 -1
  7. package/dist/src/decorators/Entity.d.ts +1 -1
  8. package/dist/src/decorators/Entity.d.ts.map +1 -1
  9. package/dist/src/decorators/Entity.js +3 -5
  10. package/dist/src/decorators/Table.d.ts +1 -1
  11. package/dist/src/decorators/Table.d.ts.map +1 -1
  12. package/dist/src/decorators/Table.js +2 -4
  13. package/dist/src/decorators/attributes/BooleanAttribute.d.ts.map +1 -1
  14. package/dist/src/decorators/attributes/BooleanAttribute.js +7 -9
  15. package/dist/src/decorators/attributes/DateAttribute.d.ts.map +1 -1
  16. package/dist/src/decorators/attributes/DateAttribute.js +8 -10
  17. package/dist/src/decorators/attributes/EnumAttribute.d.ts.map +1 -1
  18. package/dist/src/decorators/attributes/EnumAttribute.js +7 -9
  19. package/dist/src/decorators/attributes/ForeignKeyAttribute.d.ts.map +1 -1
  20. package/dist/src/decorators/attributes/ForeignKeyAttribute.js +9 -11
  21. package/dist/src/decorators/attributes/NumberAttribute.d.ts.map +1 -1
  22. package/dist/src/decorators/attributes/NumberAttribute.js +7 -9
  23. package/dist/src/decorators/attributes/ObjectAttribute.d.ts +40 -17
  24. package/dist/src/decorators/attributes/ObjectAttribute.d.ts.map +1 -1
  25. package/dist/src/decorators/attributes/ObjectAttribute.js +80 -29
  26. package/dist/src/decorators/attributes/PartitionKeyAttribute.d.ts.map +1 -1
  27. package/dist/src/decorators/attributes/PartitionKeyAttribute.js +6 -8
  28. package/dist/src/decorators/attributes/SortKeyAttribute.d.ts.map +1 -1
  29. package/dist/src/decorators/attributes/SortKeyAttribute.js +6 -8
  30. package/dist/src/decorators/attributes/StringAttribute.d.ts.map +1 -1
  31. package/dist/src/decorators/attributes/StringAttribute.js +7 -9
  32. package/dist/src/decorators/attributes/serializers.d.ts +4 -3
  33. package/dist/src/decorators/attributes/serializers.d.ts.map +1 -1
  34. package/dist/src/decorators/attributes/serializers.js +2 -1
  35. package/dist/src/decorators/attributes/types.d.ts +20 -6
  36. package/dist/src/decorators/attributes/types.d.ts.map +1 -1
  37. package/dist/src/decorators/relationships/BelongsTo.d.ts.map +1 -1
  38. package/dist/src/decorators/relationships/BelongsTo.js +7 -9
  39. package/dist/src/decorators/relationships/HasAndBelongsToMany.d.ts.map +1 -1
  40. package/dist/src/decorators/relationships/HasAndBelongsToMany.js +13 -15
  41. package/dist/src/decorators/relationships/HasMany.d.ts.map +1 -1
  42. package/dist/src/decorators/relationships/HasMany.js +15 -17
  43. package/dist/src/decorators/relationships/HasOne.d.ts.map +1 -1
  44. package/dist/src/decorators/relationships/HasOne.js +7 -9
  45. package/dist/src/metadata/AttributeMetadata.d.ts +3 -0
  46. package/dist/src/metadata/AttributeMetadata.d.ts.map +1 -1
  47. package/dist/src/metadata/AttributeMetadata.js +5 -0
  48. package/dist/src/metadata/EntityMetadata.d.ts +2 -2
  49. package/dist/src/metadata/EntityMetadata.d.ts.map +1 -1
  50. package/dist/src/metadata/EntityMetadata.js +8 -1
  51. package/dist/src/metadata/MetadataStorage.d.ts.map +1 -1
  52. package/dist/src/metadata/MetadataStorage.js +6 -6
  53. package/dist/src/metadata/TableMetadata.d.ts.map +1 -1
  54. package/dist/src/metadata/TableMetadata.js +7 -1
  55. package/dist/src/metadata/relationship-metadata/BelongsToRelationship.d.ts.map +1 -1
  56. package/dist/src/metadata/relationship-metadata/BelongsToRelationship.js +1 -3
  57. package/dist/src/metadata/relationship-metadata/HasAndBelongsToManyRelationship.d.ts.map +1 -1
  58. package/dist/src/metadata/relationship-metadata/HasAndBelongsToManyRelationship.js +1 -3
  59. package/dist/src/metadata/relationship-metadata/HasManyRelationship.d.ts.map +1 -1
  60. package/dist/src/metadata/relationship-metadata/HasManyRelationship.js +1 -3
  61. package/dist/src/metadata/relationship-metadata/HasOneRelationship.d.ts.map +1 -1
  62. package/dist/src/metadata/relationship-metadata/HasOneRelationship.js +1 -3
  63. package/dist/src/metadata/relationship-metadata/OwnedByRelationship.d.ts.map +1 -1
  64. package/dist/src/metadata/relationship-metadata/OwnedByRelationship.js +1 -3
  65. package/dist/src/metadata/types.d.ts +14 -3
  66. package/dist/src/metadata/types.d.ts.map +1 -1
  67. package/dist/src/metadata/utils.js +4 -4
  68. package/dist/src/operations/Create/Create.js +3 -5
  69. package/dist/src/operations/Delete/Delete.d.ts.map +1 -1
  70. package/dist/src/operations/Delete/Delete.js +3 -2
  71. package/dist/src/operations/FindById/FindById.d.ts.map +1 -1
  72. package/dist/src/operations/FindById/FindById.js +4 -4
  73. package/dist/src/operations/Query/Query.d.ts.map +1 -1
  74. package/dist/src/operations/Query/Query.js +2 -1
  75. package/dist/src/operations/Update/Update.d.ts +6 -1
  76. package/dist/src/operations/Update/Update.d.ts.map +1 -1
  77. package/dist/src/operations/Update/Update.js +41 -17
  78. package/dist/src/operations/Update/types.d.ts +14 -4
  79. package/dist/src/operations/Update/types.d.ts.map +1 -1
  80. package/dist/src/operations/types.d.ts +1 -1
  81. package/dist/src/operations/types.d.ts.map +1 -1
  82. package/dist/src/operations/utils/expressionBuilder.d.ts +4 -3
  83. package/dist/src/operations/utils/expressionBuilder.d.ts.map +1 -1
  84. package/dist/src/operations/utils/expressionBuilder.js +66 -2
  85. package/dist/src/operations/utils/flattenObjectForUpdate.d.ts +19 -0
  86. package/dist/src/operations/utils/flattenObjectForUpdate.d.ts.map +1 -0
  87. package/dist/src/operations/utils/flattenObjectForUpdate.js +45 -0
  88. package/dist/src/operations/utils/index.d.ts +2 -0
  89. package/dist/src/operations/utils/index.d.ts.map +1 -1
  90. package/dist/src/operations/utils/index.js +2 -0
  91. package/dist/src/operations/utils/mergePartialObjectAttributes.d.ts +8 -0
  92. package/dist/src/operations/utils/mergePartialObjectAttributes.d.ts.map +1 -0
  93. package/dist/src/operations/utils/mergePartialObjectAttributes.js +60 -0
  94. package/dist/src/operations/utils/types.d.ts +16 -0
  95. package/dist/src/operations/utils/types.d.ts.map +1 -1
  96. package/dist/src/operations/utils/utils.d.ts +2 -2
  97. package/dist/src/operations/utils/utils.d.ts.map +1 -1
  98. package/dist/src/query-utils/QueryBuilder.d.ts.map +1 -1
  99. package/dist/src/query-utils/QueryBuilder.js +11 -7
  100. package/dist/src/query-utils/types.d.ts.map +1 -1
  101. package/dist/src/relationships/JoinTable.d.ts.map +1 -1
  102. package/dist/src/relationships/JoinTable.js +4 -3
  103. package/dist/src/utils.d.ts +4 -4
  104. package/dist/src/utils.d.ts.map +1 -1
  105. package/dist/src/utils.js +13 -11
  106. 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
- acc[res.Item[idAlias]] = res.Item;
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?.Item)
187
- .map(result => result.Item?.[idAlias]));
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
  });
@@ -7,7 +7,7 @@ import { type EntityAttributesOnly } from "./operations";
7
7
  * @param entityData
8
8
  * @returns
9
9
  */
10
- export declare const entityToTableItem: <T extends DynaRecord>(EntityClass: new () => T, entityData: Partial<DynaRecord>) => DynamoTableItem;
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: any) => key is keyof T;
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: any) => value is string;
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>, TKey extends keyof TObject, TValue>(object: TObject, key: TKey, value: TValue) => void;
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
@@ -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,CAAC;AAEzD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Ae,EAAE,QAAQ,EAAE,MAAM,SAAS,CAAC;AAEzD,OAAO,EAAE,KAAK,oBAAoB,EAAE,MAAM,cAAc,CAAC;AAEzD;;;;;GAKG;AACH,eAAO,MAAM,iBAAiB,gBACf,UAAU,UAAU,cACrB,OAAO,CAAC,UAAU,CAAC,KAC9B,eAoBF,CAAC;AAEF;;;;;GAKG;AACH,eAAO,MAAM,iBAAiB,GAAI,CAAC,SAAS,UAAU,eACvC,UAAU,CAAC,aACb,eAAe,KACzB,CAsBF,CAAC;AAEF;;GAEG;AACH,eAAO,MAAM,cAAc,GAAI,CAAC,SAAS,UAAU,eACpC,UAAU,CAAC,cACZ,oBAAoB,CAAC,CAAC,CAAC,KAClC,CAUF,CAAC;AAEF;;GAEG;AACH,eAAO,MAAM,aAAa,WAChB,UAAU,OACb,MAAM,KACV,GAAG,IAAI,MAAM,UAEf,CAAC;AAEF;;;;;GAKG;AAEH,eAAO,MAAM,aAAa,GAAI,CAAC,UACrB,OAAO,CAAC,UAAU,CAAC,OACtB,WAAW,KACf,GAAG,IAAI,MAAM,CAEf,CAAC;AAEF;;;;;GAKG;AACH,eAAO,MAAM,UAAU,GAAI,CAAC,SAAS,CAAC,EAAE,QAAQ,MAAM,KAAG,CAAC,EAAE,EAI3D,CAAC;AAEF;;;;;GAKG;AACH,eAAO,MAAM,QAAQ,UAAW,OAAO,KAAG,KAAK,IAAI,MAElD,CAAC;AAEF;;;;;;;;;;;;;;;;;GAiBG;AACH,eAAO,MAAM,UAAU,GAAI,OAAO,SAAS,oBAAoB,CAAC,UAAU,CAAC,UACjE,OAAO,OACV,MAAM,OAAO,SACX,OAAO,KACb,IAEF,CAAC;AAEF;;;;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, val]) => {
17
- const attrMeta = attributesMeta[key];
18
- if (attrMeta !== undefined) {
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
- // If the attribute has a custom serializer, serialize it
21
- const value = serializers === undefined || val === null
22
- ? val
23
- : serializers.toTableAttribute(val);
24
- acc[alias] = value;
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
- const attrMeta = tableAttributes[attrName];
41
- if (attrMeta !== undefined) {
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?.toEntityAttribute(rawVal);
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.4.11",
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 . --ext .ts",
15
- "eslint:fix": "npx eslint . --ext .ts --fix",
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": "^6.21.0",
43
- "@typescript-eslint/parser": "^6.21.0",
44
- "eslint": "^8.56.0",
45
- "eslint-config-prettier": "^9.1.0",
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",