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.
Files changed (244) hide show
  1. package/README.md +23 -7
  2. package/dist/index.d.ts +12 -2
  3. package/dist/index.d.ts.map +1 -1
  4. package/dist/index.js +13 -22
  5. package/dist/src/DynaRecord.d.ts +3 -3
  6. package/dist/src/DynaRecord.d.ts.map +1 -1
  7. package/dist/src/DynaRecord.js +24 -59
  8. package/dist/src/Logger.js +1 -3
  9. package/dist/src/decorators/Entity.d.ts +1 -1
  10. package/dist/src/decorators/Entity.d.ts.map +1 -1
  11. package/dist/src/decorators/Entity.js +3 -8
  12. package/dist/src/decorators/Table.d.ts +2 -2
  13. package/dist/src/decorators/Table.d.ts.map +1 -1
  14. package/dist/src/decorators/Table.js +3 -8
  15. package/dist/src/decorators/attributes/BooleanAttribute.d.ts +2 -2
  16. package/dist/src/decorators/attributes/BooleanAttribute.d.ts.map +1 -1
  17. package/dist/src/decorators/attributes/BooleanAttribute.js +6 -10
  18. package/dist/src/decorators/attributes/DateAttribute.d.ts +2 -2
  19. package/dist/src/decorators/attributes/DateAttribute.d.ts.map +1 -1
  20. package/dist/src/decorators/attributes/DateAttribute.js +8 -12
  21. package/dist/src/decorators/attributes/EnumAttribute.d.ts +2 -2
  22. package/dist/src/decorators/attributes/EnumAttribute.d.ts.map +1 -1
  23. package/dist/src/decorators/attributes/EnumAttribute.js +7 -10
  24. package/dist/src/decorators/attributes/ForeignKeyAttribute.d.ts +3 -3
  25. package/dist/src/decorators/attributes/ForeignKeyAttribute.d.ts.map +1 -1
  26. package/dist/src/decorators/attributes/ForeignKeyAttribute.js +6 -10
  27. package/dist/src/decorators/attributes/IdAttribute.d.ts +1 -1
  28. package/dist/src/decorators/attributes/IdAttribute.d.ts.map +1 -1
  29. package/dist/src/decorators/attributes/IdAttribute.js +3 -8
  30. package/dist/src/decorators/attributes/NumberAttribute.d.ts +2 -2
  31. package/dist/src/decorators/attributes/NumberAttribute.d.ts.map +1 -1
  32. package/dist/src/decorators/attributes/NumberAttribute.js +6 -10
  33. package/dist/src/decorators/attributes/ObjectAttribute.d.ts +3 -3
  34. package/dist/src/decorators/attributes/ObjectAttribute.d.ts.map +1 -1
  35. package/dist/src/decorators/attributes/ObjectAttribute.js +17 -21
  36. package/dist/src/decorators/attributes/PartitionKeyAttribute.d.ts +3 -3
  37. package/dist/src/decorators/attributes/PartitionKeyAttribute.d.ts.map +1 -1
  38. package/dist/src/decorators/attributes/PartitionKeyAttribute.js +6 -10
  39. package/dist/src/decorators/attributes/SortKeyAttribute.d.ts +3 -3
  40. package/dist/src/decorators/attributes/SortKeyAttribute.d.ts.map +1 -1
  41. package/dist/src/decorators/attributes/SortKeyAttribute.js +6 -10
  42. package/dist/src/decorators/attributes/StringAttribute.d.ts +2 -2
  43. package/dist/src/decorators/attributes/StringAttribute.d.ts.map +1 -1
  44. package/dist/src/decorators/attributes/StringAttribute.js +6 -10
  45. package/dist/src/decorators/attributes/index.d.ts +13 -13
  46. package/dist/src/decorators/attributes/index.d.ts.map +1 -1
  47. package/dist/src/decorators/attributes/index.js +11 -41
  48. package/dist/src/decorators/attributes/serializers.d.ts +2 -2
  49. package/dist/src/decorators/attributes/serializers.d.ts.map +1 -1
  50. package/dist/src/decorators/attributes/serializers.js +5 -12
  51. package/dist/src/decorators/attributes/types.js +1 -2
  52. package/dist/src/decorators/index.d.ts +5 -5
  53. package/dist/src/decorators/index.d.ts.map +1 -1
  54. package/dist/src/decorators/index.js +5 -27
  55. package/dist/src/decorators/relationships/BelongsTo.d.ts +4 -4
  56. package/dist/src/decorators/relationships/BelongsTo.d.ts.map +1 -1
  57. package/dist/src/decorators/relationships/BelongsTo.js +3 -8
  58. package/dist/src/decorators/relationships/HasAndBelongsToMany.d.ts +3 -3
  59. package/dist/src/decorators/relationships/HasAndBelongsToMany.d.ts.map +1 -1
  60. package/dist/src/decorators/relationships/HasAndBelongsToMany.js +4 -9
  61. package/dist/src/decorators/relationships/HasMany.d.ts +3 -3
  62. package/dist/src/decorators/relationships/HasMany.d.ts.map +1 -1
  63. package/dist/src/decorators/relationships/HasMany.js +4 -9
  64. package/dist/src/decorators/relationships/HasOne.d.ts +3 -3
  65. package/dist/src/decorators/relationships/HasOne.d.ts.map +1 -1
  66. package/dist/src/decorators/relationships/HasOne.js +3 -8
  67. package/dist/src/decorators/relationships/index.d.ts +5 -5
  68. package/dist/src/decorators/relationships/index.d.ts.map +1 -1
  69. package/dist/src/decorators/relationships/index.js +5 -29
  70. package/dist/src/decorators/relationships/types.d.ts +3 -3
  71. package/dist/src/decorators/relationships/types.d.ts.map +1 -1
  72. package/dist/src/decorators/relationships/types.js +1 -2
  73. package/dist/src/decorators/types.d.ts +3 -3
  74. package/dist/src/decorators/types.d.ts.map +1 -1
  75. package/dist/src/decorators/types.js +1 -2
  76. package/dist/src/dynamo-utils/DynamoClient.d.ts +1 -1
  77. package/dist/src/dynamo-utils/DynamoClient.d.ts.map +1 -1
  78. package/dist/src/dynamo-utils/DynamoClient.js +13 -18
  79. package/dist/src/dynamo-utils/TransactGetBuilder.d.ts +1 -1
  80. package/dist/src/dynamo-utils/TransactGetBuilder.d.ts.map +1 -1
  81. package/dist/src/dynamo-utils/TransactGetBuilder.js +5 -10
  82. package/dist/src/dynamo-utils/TransactWriteBuilder.d.ts +1 -1
  83. package/dist/src/dynamo-utils/TransactWriteBuilder.d.ts.map +1 -1
  84. package/dist/src/dynamo-utils/TransactWriteBuilder.js +11 -16
  85. package/dist/src/dynamo-utils/errors.js +2 -7
  86. package/dist/src/dynamo-utils/index.d.ts +7 -7
  87. package/dist/src/dynamo-utils/index.d.ts.map +1 -1
  88. package/dist/src/dynamo-utils/index.js +7 -30
  89. package/dist/src/dynamo-utils/types.js +1 -2
  90. package/dist/src/errors.js +3 -9
  91. package/dist/src/id.d.ts +12 -0
  92. package/dist/src/id.d.ts.map +1 -0
  93. package/dist/src/id.js +11 -0
  94. package/dist/src/index.d.ts +8 -6
  95. package/dist/src/index.d.ts.map +1 -1
  96. package/dist/src/index.js +4 -20
  97. package/dist/src/metadata/AttributeMetadata.d.ts +6 -4
  98. package/dist/src/metadata/AttributeMetadata.d.ts.map +1 -1
  99. package/dist/src/metadata/AttributeMetadata.js +5 -3
  100. package/dist/src/metadata/EntityMetadata.d.ts +3 -3
  101. package/dist/src/metadata/EntityMetadata.d.ts.map +1 -1
  102. package/dist/src/metadata/EntityMetadata.js +18 -23
  103. package/dist/src/metadata/JoinTableMetadata.d.ts +3 -3
  104. package/dist/src/metadata/JoinTableMetadata.d.ts.map +1 -1
  105. package/dist/src/metadata/JoinTableMetadata.js +1 -3
  106. package/dist/src/metadata/MetadataStorage.d.ts +7 -7
  107. package/dist/src/metadata/MetadataStorage.d.ts.map +1 -1
  108. package/dist/src/metadata/MetadataStorage.js +12 -17
  109. package/dist/src/metadata/TableMetadata.d.ts +3 -3
  110. package/dist/src/metadata/TableMetadata.d.ts.map +1 -1
  111. package/dist/src/metadata/TableMetadata.js +22 -21
  112. package/dist/src/metadata/index.d.ts +9 -9
  113. package/dist/src/metadata/index.d.ts.map +1 -1
  114. package/dist/src/metadata/index.js +11 -34
  115. package/dist/src/metadata/relationship-metadata/BelongsToRelationship.d.ts +2 -2
  116. package/dist/src/metadata/relationship-metadata/BelongsToRelationship.d.ts.map +1 -1
  117. package/dist/src/metadata/relationship-metadata/BelongsToRelationship.js +3 -8
  118. package/dist/src/metadata/relationship-metadata/HasAndBelongsToManyRelationship.d.ts +1 -1
  119. package/dist/src/metadata/relationship-metadata/HasAndBelongsToManyRelationship.d.ts.map +1 -1
  120. package/dist/src/metadata/relationship-metadata/HasAndBelongsToManyRelationship.js +3 -8
  121. package/dist/src/metadata/relationship-metadata/HasManyRelationship.d.ts +2 -2
  122. package/dist/src/metadata/relationship-metadata/HasManyRelationship.d.ts.map +1 -1
  123. package/dist/src/metadata/relationship-metadata/HasManyRelationship.js +3 -8
  124. package/dist/src/metadata/relationship-metadata/HasOneRelationship.d.ts +2 -2
  125. package/dist/src/metadata/relationship-metadata/HasOneRelationship.d.ts.map +1 -1
  126. package/dist/src/metadata/relationship-metadata/HasOneRelationship.js +3 -8
  127. package/dist/src/metadata/relationship-metadata/OwnedByRelationship.d.ts +2 -2
  128. package/dist/src/metadata/relationship-metadata/OwnedByRelationship.d.ts.map +1 -1
  129. package/dist/src/metadata/relationship-metadata/OwnedByRelationship.js +3 -8
  130. package/dist/src/metadata/relationship-metadata/RelationshipMetadata.d.ts +2 -2
  131. package/dist/src/metadata/relationship-metadata/RelationshipMetadata.d.ts.map +1 -1
  132. package/dist/src/metadata/relationship-metadata/RelationshipMetadata.js +1 -3
  133. package/dist/src/metadata/relationship-metadata/index.d.ts +6 -6
  134. package/dist/src/metadata/relationship-metadata/index.d.ts.map +1 -1
  135. package/dist/src/metadata/relationship-metadata/index.js +7 -31
  136. package/dist/src/metadata/relationship-metadata/types.d.ts +5 -5
  137. package/dist/src/metadata/relationship-metadata/types.d.ts.map +1 -1
  138. package/dist/src/metadata/relationship-metadata/types.js +1 -2
  139. package/dist/src/metadata/relationship-metadata/utils.d.ts +1 -1
  140. package/dist/src/metadata/relationship-metadata/utils.d.ts.map +1 -1
  141. package/dist/src/metadata/relationship-metadata/utils.js +11 -18
  142. package/dist/src/metadata/schemas.d.ts +523 -36
  143. package/dist/src/metadata/schemas.d.ts.map +1 -1
  144. package/dist/src/metadata/schemas.js +71 -44
  145. package/dist/src/metadata/types.d.ts +17 -4
  146. package/dist/src/metadata/types.d.ts.map +1 -1
  147. package/dist/src/metadata/types.js +1 -2
  148. package/dist/src/metadata/utils.d.ts +5 -5
  149. package/dist/src/metadata/utils.d.ts.map +1 -1
  150. package/dist/src/metadata/utils.js +14 -29
  151. package/dist/src/operations/Create/Create.d.ts +5 -5
  152. package/dist/src/operations/Create/Create.d.ts.map +1 -1
  153. package/dist/src/operations/Create/Create.js +18 -23
  154. package/dist/src/operations/Create/index.d.ts +2 -2
  155. package/dist/src/operations/Create/index.d.ts.map +1 -1
  156. package/dist/src/operations/Create/index.js +2 -23
  157. package/dist/src/operations/Create/types.d.ts +2 -2
  158. package/dist/src/operations/Create/types.d.ts.map +1 -1
  159. package/dist/src/operations/Create/types.js +1 -2
  160. package/dist/src/operations/Delete/Delete.d.ts +3 -3
  161. package/dist/src/operations/Delete/Delete.d.ts.map +1 -1
  162. package/dist/src/operations/Delete/Delete.js +28 -33
  163. package/dist/src/operations/Delete/index.d.ts +1 -1
  164. package/dist/src/operations/Delete/index.d.ts.map +1 -1
  165. package/dist/src/operations/Delete/index.js +1 -8
  166. package/dist/src/operations/Delete/types.js +1 -2
  167. package/dist/src/operations/FindById/FindById.d.ts +4 -4
  168. package/dist/src/operations/FindById/FindById.d.ts.map +1 -1
  169. package/dist/src/operations/FindById/FindById.js +17 -22
  170. package/dist/src/operations/FindById/index.d.ts +2 -2
  171. package/dist/src/operations/FindById/index.d.ts.map +1 -1
  172. package/dist/src/operations/FindById/index.js +2 -23
  173. package/dist/src/operations/FindById/types.d.ts +3 -3
  174. package/dist/src/operations/FindById/types.d.ts.map +1 -1
  175. package/dist/src/operations/FindById/types.js +1 -2
  176. package/dist/src/operations/OperationBase.d.ts +3 -3
  177. package/dist/src/operations/OperationBase.d.ts.map +1 -1
  178. package/dist/src/operations/OperationBase.js +4 -9
  179. package/dist/src/operations/Query/Query.d.ts +4 -4
  180. package/dist/src/operations/Query/Query.d.ts.map +1 -1
  181. package/dist/src/operations/Query/Query.js +15 -20
  182. package/dist/src/operations/Query/index.d.ts +2 -2
  183. package/dist/src/operations/Query/index.d.ts.map +1 -1
  184. package/dist/src/operations/Query/index.js +2 -23
  185. package/dist/src/operations/Query/types.d.ts +4 -4
  186. package/dist/src/operations/Query/types.d.ts.map +1 -1
  187. package/dist/src/operations/Query/types.js +1 -2
  188. package/dist/src/operations/Update/Update.d.ts +5 -5
  189. package/dist/src/operations/Update/Update.d.ts.map +1 -1
  190. package/dist/src/operations/Update/Update.js +37 -42
  191. package/dist/src/operations/Update/UpdateDryRun.d.ts +2 -2
  192. package/dist/src/operations/Update/UpdateDryRun.d.ts.map +1 -1
  193. package/dist/src/operations/Update/UpdateDryRun.js +3 -8
  194. package/dist/src/operations/Update/index.d.ts +3 -3
  195. package/dist/src/operations/Update/index.d.ts.map +1 -1
  196. package/dist/src/operations/Update/index.js +3 -25
  197. package/dist/src/operations/Update/types.d.ts +2 -2
  198. package/dist/src/operations/Update/types.d.ts.map +1 -1
  199. package/dist/src/operations/Update/types.js +1 -2
  200. package/dist/src/operations/index.d.ts +6 -6
  201. package/dist/src/operations/index.d.ts.map +1 -1
  202. package/dist/src/operations/index.js +6 -22
  203. package/dist/src/operations/types.d.ts +3 -3
  204. package/dist/src/operations/types.d.ts.map +1 -1
  205. package/dist/src/operations/types.js +1 -2
  206. package/dist/src/operations/utils/expressionBuilder.d.ts +2 -2
  207. package/dist/src/operations/utils/expressionBuilder.d.ts.map +1 -1
  208. package/dist/src/operations/utils/expressionBuilder.js +1 -5
  209. package/dist/src/operations/utils/flattenObjectForUpdate.d.ts +2 -2
  210. package/dist/src/operations/utils/flattenObjectForUpdate.d.ts.map +1 -1
  211. package/dist/src/operations/utils/flattenObjectForUpdate.js +3 -6
  212. package/dist/src/operations/utils/index.d.ts +5 -5
  213. package/dist/src/operations/utils/index.d.ts.map +1 -1
  214. package/dist/src/operations/utils/index.js +5 -21
  215. package/dist/src/operations/utils/mergePartialObjectAttributes.d.ts +1 -1
  216. package/dist/src/operations/utils/mergePartialObjectAttributes.d.ts.map +1 -1
  217. package/dist/src/operations/utils/mergePartialObjectAttributes.js +1 -4
  218. package/dist/src/operations/utils/types.js +1 -2
  219. package/dist/src/operations/utils/utils.d.ts +4 -4
  220. package/dist/src/operations/utils/utils.d.ts.map +1 -1
  221. package/dist/src/operations/utils/utils.js +13 -23
  222. package/dist/src/query-utils/Filters.d.ts +2 -2
  223. package/dist/src/query-utils/Filters.d.ts.map +1 -1
  224. package/dist/src/query-utils/Filters.js +1 -4
  225. package/dist/src/query-utils/QueryBuilder.d.ts +1 -1
  226. package/dist/src/query-utils/QueryBuilder.d.ts.map +1 -1
  227. package/dist/src/query-utils/QueryBuilder.js +8 -13
  228. package/dist/src/query-utils/index.d.ts +2 -2
  229. package/dist/src/query-utils/index.d.ts.map +1 -1
  230. package/dist/src/query-utils/index.js +2 -23
  231. package/dist/src/query-utils/types.js +1 -2
  232. package/dist/src/relationships/JoinTable.d.ts +2 -2
  233. package/dist/src/relationships/JoinTable.d.ts.map +1 -1
  234. package/dist/src/relationships/JoinTable.js +14 -19
  235. package/dist/src/relationships/index.d.ts +1 -1
  236. package/dist/src/relationships/index.d.ts.map +1 -1
  237. package/dist/src/relationships/index.js +1 -8
  238. package/dist/src/types.d.ts +2 -2
  239. package/dist/src/types.d.ts.map +1 -1
  240. package/dist/src/types.js +1 -2
  241. package/dist/src/utils.d.ts +3 -3
  242. package/dist/src/utils.d.ts.map +1 -1
  243. package/dist/src/utils.js +16 -31
  244. package/package.json +28 -24
@@ -1,34 +1,61 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.TableMetadataTransform = void 0;
4
- const zod_1 = require("zod");
1
+ import { z } from "zod";
2
+ /**
3
+ * Common serialized fields shared by every attribute kind.
4
+ */
5
+ const baseAttributeShape = {
6
+ name: z.string(),
7
+ alias: z.string(),
8
+ nullable: z.boolean()
9
+ };
10
+ const simpleAttributeShape = (kind) => z.object({ ...baseAttributeShape, kind: z.literal(kind) });
5
11
  /**
6
12
  * Zod schema that transforms attribute metadata to a serializable format.
7
- * Extracts only serializable properties (name, alias, nullable) and converts
8
- * the foreignKeyTarget EntityClass reference to its class name string.
9
13
  *
10
- * @property {string} name - The name of the attribute as defined on the entity
11
- * @property {string} alias - The alias of the attribute as defined in the database table
12
- * @property {boolean} nullable - Indicates whether the attribute can be null
13
- * @property {EntityClass<DynaRecord>} [foreignKeyTarget] - Optional entity class reference that will be converted to its name string
14
+ * Emits a discriminated union keyed on `kind`. Every attribute carries
15
+ * `{ name, alias, nullable, kind }`; some kinds carry an additional payload:
14
16
  *
15
- * @returns A serialized attribute metadata object with foreignKeyTarget as a string (class name) if present
17
+ * - `kind: "enum"` `values: readonly [string, ...string[]]`
18
+ * - `kind: "object"` → `schema: ObjectSchema` (the user-authored schema)
19
+ * - `kind: "foreignKey"` → `foreignKeyTarget: string` (target entity class name)
20
+ *
21
+ * Non-serializable internals (Zod types, serializers, partial types) are dropped.
16
22
  */
17
- const AttributeMetadataTransform = zod_1.z
18
- .object({
19
- name: zod_1.z.string(),
20
- alias: zod_1.z.string(),
21
- nullable: zod_1.z.boolean(),
22
- foreignKeyTarget: zod_1.z.custom().optional()
23
- })
24
- .transform(attr => ({
25
- name: attr.name,
26
- alias: attr.alias,
27
- nullable: attr.nullable,
28
- ...(attr.foreignKeyTarget != null && {
29
- foreignKeyTarget: attr.foreignKeyTarget.name
23
+ const AttributeMetadataTransform = z.discriminatedUnion("kind", [
24
+ simpleAttributeShape("string"),
25
+ simpleAttributeShape("number"),
26
+ simpleAttributeShape("boolean"),
27
+ simpleAttributeShape("date"),
28
+ z
29
+ .object({
30
+ ...baseAttributeShape,
31
+ kind: z.literal("enum"),
32
+ enumValues: z.array(z.string()).nonempty()
30
33
  })
31
- }));
34
+ .transform(({ enumValues, ...rest }) => ({
35
+ ...rest,
36
+ values: enumValues
37
+ })),
38
+ z
39
+ .object({
40
+ ...baseAttributeShape,
41
+ kind: z.literal("object"),
42
+ objectSchema: z.custom()
43
+ })
44
+ .transform(({ objectSchema, ...rest }) => ({
45
+ ...rest,
46
+ schema: objectSchema
47
+ })),
48
+ z
49
+ .object({
50
+ ...baseAttributeShape,
51
+ kind: z.literal("foreignKey"),
52
+ foreignKeyTarget: z.custom()
53
+ })
54
+ .transform(({ foreignKeyTarget, ...rest }) => ({
55
+ ...rest,
56
+ foreignKeyTarget: foreignKeyTarget.name
57
+ }))
58
+ ]);
32
59
  /**
33
60
  * Zod schema that transforms relationship metadata to a serializable format.
34
61
  * Extracts serializable properties and converts EntityClass references to their class name strings.
@@ -42,14 +69,14 @@ const AttributeMetadataTransform = zod_1.z
42
69
  *
43
70
  * @returns A serialized relationship metadata object with EntityClass references converted to strings
44
71
  */
45
- const RelationshipMetadataTransform = zod_1.z
72
+ const RelationshipMetadataTransform = z
46
73
  .object({
47
- type: zod_1.z.string(),
48
- propertyName: zod_1.z.string(),
49
- target: zod_1.z.custom().optional(),
50
- foreignKey: zod_1.z.string().optional(),
51
- joinTableName: zod_1.z.string().optional(),
52
- uniDirectional: zod_1.z.boolean().optional()
74
+ type: z.string(),
75
+ propertyName: z.string(),
76
+ target: z.custom().optional(),
77
+ foreignKey: z.string().optional(),
78
+ joinTableName: z.string().optional(),
79
+ uniDirectional: z.boolean().optional()
53
80
  })
54
81
  .transform(rel => ({
55
82
  type: rel.type,
@@ -73,13 +100,13 @@ const RelationshipMetadataTransform = zod_1.z
73
100
  *
74
101
  * @returns A serialized entity metadata object with all nested metadata transformed
75
102
  */
76
- const EntityMetadataTransform = zod_1.z
103
+ const EntityMetadataTransform = z
77
104
  .object({
78
- tableClassName: zod_1.z.string(),
79
- attributes: zod_1.z.record(zod_1.z.string(), AttributeMetadataTransform),
80
- tableAttributes: zod_1.z.record(zod_1.z.string(), AttributeMetadataTransform),
81
- relationships: zod_1.z.record(zod_1.z.string(), RelationshipMetadataTransform),
82
- idField: zod_1.z.string().optional()
105
+ tableClassName: z.string(),
106
+ attributes: z.record(z.string(), AttributeMetadataTransform),
107
+ tableAttributes: z.record(z.string(), AttributeMetadataTransform),
108
+ relationships: z.record(z.string(), RelationshipMetadataTransform),
109
+ idField: z.string().optional()
83
110
  })
84
111
  .transform(entity => ({
85
112
  tableClassName: entity.tableClassName,
@@ -110,12 +137,12 @@ const EntityMetadataTransform = zod_1.z
110
137
  * // Returns a plain object with all EntityClass references converted to strings
111
138
  * ```
112
139
  */
113
- exports.TableMetadataTransform = zod_1.z.object({
114
- name: zod_1.z.string(),
115
- delimiter: zod_1.z.string(),
116
- defaultAttributes: zod_1.z.record(zod_1.z.string(), AttributeMetadataTransform),
117
- defaultTableAttributes: zod_1.z.record(zod_1.z.string(), AttributeMetadataTransform),
140
+ export const TableMetadataTransform = z.object({
141
+ name: z.string(),
142
+ delimiter: z.string(),
143
+ defaultAttributes: z.record(z.string(), AttributeMetadataTransform),
144
+ defaultTableAttributes: z.record(z.string(), AttributeMetadataTransform),
118
145
  partitionKeyAttribute: AttributeMetadataTransform,
119
146
  sortKeyAttribute: AttributeMetadataTransform,
120
- entities: zod_1.z.record(zod_1.z.string(), EntityMetadataTransform)
147
+ entities: z.record(z.string(), EntityMetadataTransform)
121
148
  });
@@ -1,9 +1,9 @@
1
1
  import type { NativeAttributeValue } from "@aws-sdk/util-dynamodb";
2
- import type { AttributeMetadata, BelongsToRelationship, EntityMetadata, JoinTableMetadata, OwnedByRelationship, RelationshipMetadata, TableMetadata } from ".";
3
- import type DynaRecord from "../DynaRecord";
4
- import type { EntityClass, MakeOptional } from "../types";
2
+ import type { AttributeMetadata, BelongsToRelationship, EntityMetadata, JoinTableMetadata, OwnedByRelationship, RelationshipMetadata, TableMetadata } from "./index.js";
3
+ import type DynaRecord from "../DynaRecord.js";
4
+ import type { EntityClass, MakeOptional } from "../types.js";
5
5
  import type { ZodType } from "zod";
6
- import type { ObjectSchema } from "../decorators/attributes/types";
6
+ import type { ObjectSchema } from "../decorators/attributes/types.js";
7
7
  /**
8
8
  * Represents relationship metadata that includes a foreign key reference to another entity.
9
9
  */
@@ -81,6 +81,13 @@ export interface Serializers {
81
81
  */
82
82
  toTableAttribute: TableSerializer;
83
83
  }
84
+ /**
85
+ * Discriminator identifying which `@…Attribute` decorator produced an
86
+ * {@link AttributeMetadata} record. Exposed in the serialized metadata
87
+ * returned by `DynaRecord.metadata()` so consumers can switch on the
88
+ * attribute's logical type.
89
+ */
90
+ export type AttributeKind = "string" | "number" | "boolean" | "date" | "enum" | "object" | "foreignKey";
84
91
  /**
85
92
  * Defines the options for configuring attribute metadata within the ORM system. This interface specifies the settings used to describe and manage an attribute's representation and behavior in both the entity model and the underlying database schema, particularly focusing on attributes' names, aliases, nullability, and serialization strategies.
86
93
  *
@@ -91,10 +98,16 @@ export interface Serializers {
91
98
  */
92
99
  export interface AttributeMetadataOptions {
93
100
  attributeName: string;
101
+ kind: AttributeKind;
94
102
  type: ZodType;
95
103
  alias?: string;
96
104
  nullable?: boolean;
97
105
  serializers?: Serializers;
106
+ /**
107
+ * For `kind: "enum"` attributes, the allowed string values. Forwarded to
108
+ * the serialized metadata so consumers can introspect the enum domain.
109
+ */
110
+ enumValues?: readonly [string, ...string[]];
98
111
  /**
99
112
  * When the attribute represents a foreign key, this references the target entity class.
100
113
  * Used to enforce referential integrity even when a relationship decorator is not present.
@@ -1 +1 @@
1
- {"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../../src/metadata/types.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,oBAAoB,EAAE,MAAM,wBAAwB,CAAC;AACnE,OAAO,KAAK,EACV,iBAAiB,EACjB,qBAAqB,EACrB,cAAc,EACd,iBAAiB,EACjB,mBAAmB,EACnB,oBAAoB,EACpB,aAAa,EACd,MAAM,GAAG,CAAC;AACX,OAAO,KAAK,UAAU,MAAM,eAAe,CAAC;AAC5C,OAAO,KAAK,EAAE,WAAW,EAAE,YAAY,EAAE,MAAM,UAAU,CAAC;AAC1D,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,KAAK,CAAC;AACnC,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,gCAAgC,CAAC;AAEnE;;GAEG;AACH,MAAM,MAAM,kCAAkC,GAAG,OAAO,CACtD,oBAAoB,EACpB;IAAE,UAAU,EAAE,MAAM,UAAU,CAAA;CAAE,CACjC,CAAC;AAEF;;GAEG;AACH,MAAM,MAAM,wBAAwB,GAAG,MAAM,CAAC,MAAM,EAAE,iBAAiB,CAAC,CAAC;AAEzE;;GAEG;AACH,MAAM,MAAM,2BAA2B,GAAG,MAAM,CAAC,MAA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C;CACtE"}
@@ -1,2 +1 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
1
+ export {};
@@ -1,8 +1,8 @@
1
- import type { RelationshipMetadata, HasManyRelationship, BelongsToRelationship, HasOneRelationship, HasAndBelongsToManyRelationship, OwnedByRelationship, ForeignKeyAttributeMetadata } from ".";
2
- import type DynaRecord from "../DynaRecord";
3
- import type { BelongsToOrOwnedByRelationship, RelationshipMetadataWithForeignKey } from "./types";
4
- import type { EntityClass } from "../types";
5
- import type AttributeMetadata from "./AttributeMetadata";
1
+ import type { RelationshipMetadata, HasManyRelationship, BelongsToRelationship, HasOneRelationship, HasAndBelongsToManyRelationship, OwnedByRelationship, ForeignKeyAttributeMetadata } from "./index.js";
2
+ import type DynaRecord from "../DynaRecord.js";
3
+ import type { BelongsToOrOwnedByRelationship, RelationshipMetadataWithForeignKey } from "./types.js";
4
+ import type { EntityClass } from "../types.js";
5
+ import type AttributeMetadata from "./AttributeMetadata.js";
6
6
  /**
7
7
  * Type guard to check if the relationship is a HasMany
8
8
  */
@@ -1 +1 @@
1
- {"version":3,"file":"utils.d.ts","sourceRoot":"","sources":["../../../src/metadata/utils.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EACV,oBAAoB,EACpB,mBAAmB,EACnB,qBAAqB,EACrB,kBAAkB,EAClB,+BAA+B,EAC/B,mBAAmB,EACnB,2BAA2B,EAC5B,MAAM,GAAG,CAAC;AACX,OAAO,KAAK,UAAU,MAAM,eAAe,CAAC;AAC5C,OAAO,KAAK,EACV,8BAA8B,EAC9B,kCAAkC,EACnC,MAAM,SAAS,CAAC;AACjB,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,UAAU,CAAC;AAC5C,OAAO,KAAK,iBAAiB,MAAM,qBAAqB,CAAC;AAEzD;;GAEG;AACH,eAAO,MAAM,qBAAqB,QAC3B,oBAAoB,KACxB,GAAG,IAAI,mBAET,CAAC;AAEF;;GAEG;AACH,eAAO,MAAM,uBAAuB,QAC7B,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IAAI,mBAET,CAAC;AAEF;;GAEG;AACH,eAAO,MAAM,uBAAuB,GAClC,KAAK,oBAAoB,KACxB,GAAG,IAAI,qBAET,CAAC;AAEF;;GAEG;AACH,eAAO,MAAM,oBAAoB,GAC/B,KAAK,oBAAoB,KACxB,GAAG,IAAI,kBAET,CAAC;AAEF;;GAEG;AACH,eAAO,MAAM,iCAAiC,GAC5C,KAAK,oBAAoB,KACxB,GAAG,IAAI,+BAET,CAAC;AAEF;;GAEG;AACH,eAAO,MAAM,qBAAqB,GAChC,KAAK,oBAAoB,KACxB,GAAG,IAAI,mBAET,CAAC;AAEF;;;;GAIG;AACH,eAAO,MAAM,oCAAoC,GAC/C,KAAK,oBAAoB,KACxB,GAAG,IAAI,kCAET,CAAC;AAEF;;;GAGG;AACH,eAAO,MAAM,6BAA6B,GACxC,MAAM,iBAAiB,KACtB,IAAI,IAAI,2BAEV,CAAC;AAEF;;;;;GAKG;AACH,eAAO,MAAM,6BAA6B,GAAI,CAAC,SAAS,UAAU,EAChE,QAAQ,WAAW,CAAC,CAAC,CAAC,EACtB,KAAK,8BAA8B,KAClC,OAMF,CAAC;AAEF;;;;;;GAMG;AACH,eAAO,MAAM,8BAA8B,GAAI,CAAC,SAAS,UAAU,EACjE,QAAQ,WAAW,CAAC,CAAC,CAAC,EACtB,KAAK,8BAA8B,KAClC,OAMF,CAAC"}
@@ -1,73 +1,59 @@
1
- "use strict";
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.doesEntityBelongToRelAsHasMany = exports.doesEntityBelongToRelAsHasOne = exports.isForeignKeyAttributeMetadata = exports.isRelationshipMetadataWithForeignKey = exports.isOwnedByRelationship = exports.isHasAndBelongsToManyRelationship = exports.isHasOneRelationship = exports.isBelongsToRelationship = exports.isHasManyRelationship = void 0;
7
- const _1 = __importDefault(require("./"));
1
+ import Metadata from "./index.js";
8
2
  /**
9
3
  * Type guard to check if the relationship is a HasMany
10
4
  */
11
- const isHasManyRelationship = (rel) => {
5
+ export const isHasManyRelationship = (rel) => {
12
6
  return rel.type === "HasMany" && "foreignKey" in rel;
13
7
  };
14
- exports.isHasManyRelationship = isHasManyRelationship;
15
8
  /**
16
9
  * Type guard to check if the relationship is a BelongsTo
17
10
  */
18
- const isBelongsToRelationship = (rel) => {
11
+ export const isBelongsToRelationship = (rel) => {
19
12
  return rel.type === "BelongsTo" && "foreignKey" in rel;
20
13
  };
21
- exports.isBelongsToRelationship = isBelongsToRelationship;
22
14
  /**
23
15
  * Type guard to check if the relationship is a HasOne
24
16
  */
25
- const isHasOneRelationship = (rel) => {
17
+ export const isHasOneRelationship = (rel) => {
26
18
  return rel.type === "HasOne" && "foreignKey" in rel;
27
19
  };
28
- exports.isHasOneRelationship = isHasOneRelationship;
29
20
  /**
30
21
  * Type guard to check if the relationship is a HasOne
31
22
  */
32
- const isHasAndBelongsToManyRelationship = (rel) => {
23
+ export const isHasAndBelongsToManyRelationship = (rel) => {
33
24
  return rel.type === "HasAndBelongsToMany" && "joinTableName" in rel;
34
25
  };
35
- exports.isHasAndBelongsToManyRelationship = isHasAndBelongsToManyRelationship;
36
26
  /**
37
27
  * Type guard to check if the relationship is of type OwnedBy
38
28
  */
39
- const isOwnedByRelationship = (rel) => {
29
+ export const isOwnedByRelationship = (rel) => {
40
30
  return rel.type === "OwnedBy";
41
31
  };
42
- exports.isOwnedByRelationship = isOwnedByRelationship;
43
32
  /**
44
33
  * Type guard to check if the relationship metadata includes a foreignKey
45
34
  * @param rel
46
35
  * @returns
47
36
  */
48
- const isRelationshipMetadataWithForeignKey = (rel) => {
37
+ export const isRelationshipMetadataWithForeignKey = (rel) => {
49
38
  return "foreignKey" in rel;
50
39
  };
51
- exports.isRelationshipMetadataWithForeignKey = isRelationshipMetadataWithForeignKey;
52
40
  /**
53
41
  * Type guard that checks whether attribute metadata represents a foreign key.
54
42
  * Returns {@link ForeignKeyAttributeMetadata} with a guaranteed target entity.
55
43
  */
56
- const isForeignKeyAttributeMetadata = (attr) => {
44
+ export const isForeignKeyAttributeMetadata = (attr) => {
57
45
  return attr.foreignKeyTarget !== undefined;
58
46
  };
59
- exports.isForeignKeyAttributeMetadata = isForeignKeyAttributeMetadata;
60
47
  /**
61
48
  * Returns true if an "Entity" BelongsTo the provided relationship as a HasOne
62
49
  * @param Entity
63
50
  * @param rel
64
51
  * @returns
65
52
  */
66
- const doesEntityBelongToRelAsHasOne = (Entity, rel) => {
67
- const relMetadata = _1.default.getEntity(rel.target.name);
68
- return Object.values(relMetadata.relationships).some(rel => (0, exports.isHasOneRelationship)(rel) && rel.target === Entity);
53
+ export const doesEntityBelongToRelAsHasOne = (Entity, rel) => {
54
+ const relMetadata = Metadata.getEntity(rel.target.name);
55
+ return Object.values(relMetadata.relationships).some(rel => isHasOneRelationship(rel) && rel.target === Entity);
69
56
  };
70
- exports.doesEntityBelongToRelAsHasOne = doesEntityBelongToRelAsHasOne;
71
57
  /**
72
58
  * Returns true if an "Entity" BelongsTo the provided relationship as a HasMany
73
59
  * @param Entity
@@ -75,8 +61,7 @@ exports.doesEntityBelongToRelAsHasOne = doesEntityBelongToRelAsHasOne;
75
61
  * @param foreignKey
76
62
  * @returns
77
63
  */
78
- const doesEntityBelongToRelAsHasMany = (Entity, rel) => {
79
- const relMetadata = _1.default.getEntity(rel.target.name);
80
- return Object.values(relMetadata.relationships).some(rel => (0, exports.isHasManyRelationship)(rel) && rel.target === Entity);
64
+ export const doesEntityBelongToRelAsHasMany = (Entity, rel) => {
65
+ const relMetadata = Metadata.getEntity(rel.target.name);
66
+ return Object.values(relMetadata.relationships).some(rel => isHasManyRelationship(rel) && rel.target === Entity);
81
67
  };
82
- exports.doesEntityBelongToRelAsHasMany = doesEntityBelongToRelAsHasMany;
@@ -1,8 +1,8 @@
1
- import type DynaRecord from "../../DynaRecord";
2
- import type { EntityClass } from "../../types";
3
- import OperationBase from "../OperationBase";
4
- import type { CreateOptions, CreateOperationOptions } from "./types";
5
- import { type EntityAttributesOnly } from "../types";
1
+ import type DynaRecord from "../../DynaRecord.js";
2
+ import type { EntityClass } from "../../types.js";
3
+ import OperationBase from "../OperationBase.js";
4
+ import type { CreateOptions, CreateOperationOptions } from "./types.js";
5
+ import { type EntityAttributesOnly } from "../types.js";
6
6
  /**
7
7
  * Represents an operation to create a new entity record in DynamoDB, including all necessary
8
8
  * denormalized relationship records. This ensures that "BelongsTo" and "HasMany" relationships
@@ -1 +1 @@
1
- {"version":3,"file":"Create.d.ts","sourceRoot":"","sources":["../../../../src/operations/Create/Create.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,UAAU,MAAM,kBAAkB,CAAC;AAE/C,OAAO,KAAK,EAAmB,WAAW,EAAE,MAAM,aAAa,CAAC;AAOhE,OAAO,aAAa,MAAM,kBAAkB,CAAC;AAE7C,OAAO,KAAK,EAAE,aAAa,EAAE,sBAAsB,EAAE,MAAM,SAAS,CAAC;AACrE,OAAO,EAGL,KAAK,oBAAoB,EAC1B,MAAM,UAAU,CAAC;AAIlB;;;;;;;;;;;;;;;;;GAiBG;AACH,cAAM,MAAM,CAAC,CAAC,SAAS,UAAU,CAAE,SAAQ,aAAa,CAAC,CAAC,CAAC;;gBAG7C,MAAM,EAAE,WAAW,CAAC,CAAC,CAAC;IAKlC;;;;;;;;;;;;;;;;;OAiBG;IACU,GAAG,CACd,UAAU,EAAE,aAAa,CAAC,CAAC,CAAC,EAC5B,OAAO,CAAC,EAAE,sBAAsB,GAC/B,OAAO,CAAC,oBAAoB,CAAC,CAAC,CAAC,CAAC;IAuCnC;;;;;;;;;;;OAWG;IACH,OAAO,CAAC,uBAAuB;IA8B/B;;;;;;;;;OASG;IACH,OAAO,CAAC,uBAAuB;IAiB/B;;;;;;;;;;;OAWG;IACH,OAAO,CAAC,0BAA0B;IAqClC;;;;;;;OAOG;IACH,OAAO,CAAC,wCAAwC;IAkChD;;;;;;;;;;;OAWG;YACW,sBAAsB;IAmCpC;;;;;;;;;;OAUG;IACH,OAAO,CAAC,2CAA2C;IAmBnD;;;;;;;;;;;OAWG;IACH,OAAO,CAAC,uCAAuC;CA0BhD;AAED,eAAe,MAAM,CAAC"}
1
+ {"version":3,"file":"Create.d.ts","sourceRoot":"","sources":["../../../../src/operations/Create/Create.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,UAAU,MAAM,qBAAqB,CAAC;AAElD,OAAO,KAAK,EAAmB,WAAW,EAAE,MAAM,gBAAgB,CAAC;AAOnE,OAAO,aAAa,MAAM,qBAAqB,CAAC;AAKhD,OAAO,KAAK,EAAE,aAAa,EAAE,sBAAsB,EAAE,MAAM,YAAY,CAAC;AACxE,OAAO,EAGL,KAAK,oBAAoB,EAC1B,MAAM,aAAa,CAAC;AAIrB;;;;;;;;;;;;;;;;;GAiBG;AACH,cAAM,MAAM,CAAC,CAAC,SAAS,UAAU,CAAE,SAAQ,aAAa,CAAC,CAAC,CAAC;;gBAG7C,MAAM,EAAE,WAAW,CAAC,CAAC,CAAC;IAKlC;;;;;;;;;;;;;;;;;OAiBG;IACU,GAAG,CACd,UAAU,EAAE,aAAa,CAAC,CAAC,CAAC,EAC5B,OAAO,CAAC,EAAE,sBAAsB,GAC/B,OAAO,CAAC,oBAAoB,CAAC,CAAC,CAAC,CAAC;IAuCnC;;;;;;;;;;;OAWG;IACH,OAAO,CAAC,uBAAuB;IA8B/B;;;;;;;;;OASG;IACH,OAAO,CAAC,uBAAuB;IAiB/B;;;;;;;;;;;OAWG;IACH,OAAO,CAAC,0BAA0B;IAqClC;;;;;;;OAOG;IACH,OAAO,CAAC,wCAAwC;IAkChD;;;;;;;;;;;OAWG;YACW,sBAAsB;IAmCpC;;;;;;;;;;OAUG;IACH,OAAO,CAAC,2CAA2C;IAmBnD;;;;;;;;;;;OAWG;IACH,OAAO,CAAC,uCAAuC;CA0BhD;AAED,eAAe,MAAM,CAAC"}
@@ -1,14 +1,9 @@
1
- "use strict";
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
- const uuid_1 = require("uuid");
7
- const dynamo_utils_1 = require("../../dynamo-utils");
8
- const utils_1 = require("../../utils");
9
- const OperationBase_1 = __importDefault(require("../OperationBase"));
10
- const utils_2 = require("../utils");
11
- const utils_3 = require("../../metadata/utils");
1
+ import { generateId } from "../../id.js";
2
+ import { TransactGetBuilder, TransactWriteBuilder } from "../../dynamo-utils/index.js";
3
+ import { entityToTableItem, isString, tableItemToEntity } from "../../utils.js";
4
+ import OperationBase from "../OperationBase.js";
5
+ import { extractForeignKeyFromEntity, buildBelongsToLinkKey } from "../utils/index.js";
6
+ import { isBelongsToRelationship } from "../../metadata/utils.js";
12
7
  /**
13
8
  * Represents an operation to create a new entity record in DynamoDB, including all necessary
14
9
  * denormalized relationship records. This ensures that "BelongsTo" and "HasMany" relationships
@@ -27,11 +22,11 @@ const utils_3 = require("../../metadata/utils");
27
22
  *
28
23
  * @template T - The type of the entity being created, extending `DynaRecord`.
29
24
  */
30
- class Create extends OperationBase_1.default {
25
+ class Create extends OperationBase {
31
26
  #transactionBuilder;
32
27
  constructor(Entity) {
33
28
  super(Entity);
34
- this.#transactionBuilder = new dynamo_utils_1.TransactWriteBuilder();
29
+ this.#transactionBuilder = new TransactWriteBuilder();
35
30
  }
36
31
  /**
37
32
  * Executes the create operation.
@@ -56,7 +51,7 @@ class Create extends OperationBase_1.default {
56
51
  const entityAttrs = this.entityMetadata.parseRawEntityDefinedAttributes(attributes);
57
52
  const reservedAttrs = this.buildReservedAttributes(entityAttrs);
58
53
  const entityData = { ...reservedAttrs, ...entityAttrs };
59
- const tableItem = (0, utils_1.entityToTableItem)(this.EntityClass, entityData);
54
+ const tableItem = entityToTableItem(this.EntityClass, entityData);
60
55
  this.buildPutItemTransaction(tableItem, entityData.id);
61
56
  this.buildBelongsToTransactions(entityData, tableItem, referentialIntegrityCheck);
62
57
  this.buildStandaloneForeignKeyConditionChecks(entityData, referentialIntegrityCheck);
@@ -67,7 +62,7 @@ class Create extends OperationBase_1.default {
67
62
  this.buildAddBelongsToLinkToSelfTransactions(reservedAttrs.id, belongsToTableItems);
68
63
  }
69
64
  await this.#transactionBuilder.executeTransaction();
70
- return (0, utils_1.tableItemToEntity)(this.EntityClass, tableItem);
65
+ return tableItemToEntity(this.EntityClass, tableItem);
71
66
  }
72
67
  /**
73
68
  * Builds and returns entity attributes that must be reserved for system usage.
@@ -84,7 +79,7 @@ class Create extends OperationBase_1.default {
84
79
  buildReservedAttributes(entityAttrs) {
85
80
  const { idField } = this.entityMetadata;
86
81
  const id = idField === undefined
87
- ? (0, uuid_1.v4)()
82
+ ? generateId()
88
83
  : entityAttrs[idField];
89
84
  const createdAt = new Date();
90
85
  const pk = this.tableMetadata.partitionKeyAttribute.name;
@@ -136,13 +131,13 @@ class Create extends OperationBase_1.default {
136
131
  const tableName = this.tableMetadata.name;
137
132
  const relMetadata = this.entityMetadata.belongsToOrOwnedByRelationships;
138
133
  for (const relMeta of relMetadata) {
139
- const foreignKey = (0, utils_2.extractForeignKeyFromEntity)(relMeta, entityData);
134
+ const foreignKey = extractForeignKeyFromEntity(relMeta, entityData);
140
135
  if (foreignKey != null) {
141
136
  // Ensure referenced entity exists before linking
142
137
  if (referentialIntegrityCheck) {
143
138
  this.buildRelationshipExistsConditionTransaction(relMeta, foreignKey);
144
139
  }
145
- const key = (0, utils_2.buildBelongsToLinkKey)(this.EntityClass, entityData.id, relMeta, foreignKey);
140
+ const key = buildBelongsToLinkKey(this.EntityClass, entityData.id, relMeta, foreignKey);
146
141
  this.#transactionBuilder.addPut({
147
142
  TableName: tableName,
148
143
  Item: { ...tableItem, ...key },
@@ -167,7 +162,7 @@ class Create extends OperationBase_1.default {
167
162
  for (const attrMeta of standaloneForeignKeys) {
168
163
  const target = attrMeta.foreignKeyTarget;
169
164
  const foreignKeyValue = entityData[attrMeta.name];
170
- if (!(0, utils_1.isString)(foreignKeyValue))
165
+ if (!isString(foreignKeyValue))
171
166
  continue;
172
167
  const foreignKey = foreignKeyValue;
173
168
  const errMsg = `${target.name} with ID '${foreignKey}' does not exist`;
@@ -196,11 +191,11 @@ class Create extends OperationBase_1.default {
196
191
  */
197
192
  async getBelongsToTableItems(entityData) {
198
193
  const { name: tableName } = this.tableMetadata;
199
- const transactionBuilder = new dynamo_utils_1.TransactGetBuilder();
194
+ const transactionBuilder = new TransactGetBuilder();
200
195
  const relMetas = this.entityMetadata.relationships;
201
- const belongsToRelMetas = Object.values(relMetas).filter(relMeta => (0, utils_3.isBelongsToRelationship)(relMeta));
196
+ const belongsToRelMetas = Object.values(relMetas).filter(relMeta => isBelongsToRelationship(relMeta));
202
197
  belongsToRelMetas.forEach(relMeta => {
203
- const fk = (0, utils_2.extractForeignKeyFromEntity)(relMeta, entityData);
198
+ const fk = extractForeignKeyFromEntity(relMeta, entityData);
204
199
  if (fk != null) {
205
200
  transactionBuilder.addGet({
206
201
  TableName: tableName,
@@ -274,4 +269,4 @@ class Create extends OperationBase_1.default {
274
269
  });
275
270
  }
276
271
  }
277
- exports.default = Create;
272
+ export default Create;
@@ -1,3 +1,3 @@
1
- export { default as Create } from "./Create";
2
- export * from "./types";
1
+ export { default as Create } from "./Create.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/operations/Create/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,IAAI,MAAM,EAAE,MAAM,UAAU,CAAC;AAC7C,cAAc,SAAS,CAAC"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../src/operations/Create/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,IAAI,MAAM,EAAE,MAAM,aAAa,CAAC;AAChD,cAAc,YAAY,CAAC"}
@@ -1,23 +1,2 @@
1
- "use strict";
2
- var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
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.Create = void 0;
21
- var Create_1 = require("./Create");
22
- Object.defineProperty(exports, "Create", { enumerable: true, get: function () { return __importDefault(Create_1).default; } });
23
- __exportStar(require("./types"), exports);
1
+ export { default as Create } from "./Create.js";
2
+ export * from "./types.js";
@@ -1,5 +1,5 @@
1
- import type DynaRecord from "../../DynaRecord";
2
- import type { EntityDefinedAttributes } from "../types";
1
+ import type DynaRecord from "../../DynaRecord.js";
2
+ import type { EntityDefinedAttributes } from "../types.js";
3
3
  /**
4
4
  * Options for create operations
5
5
  */
@@ -1 +1 @@
1
- {"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../../../src/operations/Create/types.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,UAAU,MAAM,kBAAkB,CAAC;AAC/C,OAAO,KAAK,EAAE,uBAAuB,EAAE,MAAM,UAAU,CAAC;AAExD;;GAEG;AACH,MAAM,WAAW,sBAAsB;IACrC;;;;;OAKG;IACH,yBAAyB,CAAC,EAAE,OAAO,CAAC;CACrC;AAED;;GAEG;AACH,MAAM,MAAM,aAAa,CAAC,CAAC,SAAS,UAAU,IAAI,uBAAuB,CAAC,CAAC,CAAC,CAAC"}
1
+ {"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../../../src/operations/Create/types.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,UAAU,MAAM,qBAAqB,CAAC;AAClD,OAAO,KAAK,EAAE,uBAAuB,EAAE,MAAM,aAAa,CAAC;AAE3D;;GAEG;AACH,MAAM,WAAW,sBAAsB;IACrC;;;;;OAKG;IACH,yBAAyB,CAAC,EAAE,OAAO,CAAC;CACrC;AAED;;GAEG;AACH,MAAM,MAAM,aAAa,CAAC,CAAC,SAAS,UAAU,IAAI,uBAAuB,CAAC,CAAC,CAAC,CAAC"}
@@ -1,2 +1 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
1
+ export {};
@@ -1,6 +1,6 @@
1
- import type DynaRecord from "../../DynaRecord";
2
- import type { EntityClass } from "../../types";
3
- import OperationBase from "../OperationBase";
1
+ import type DynaRecord from "../../DynaRecord.js";
2
+ import type { EntityClass } from "../../types.js";
3
+ import OperationBase from "../OperationBase.js";
4
4
  /**
5
5
  * Implements the operation for deleting an entity and its related data from the database within the ORM framework.
6
6
  *
@@ -1 +1 @@
1
- {"version":3,"file":"Delete.d.ts","sourceRoot":"","sources":["../../../../src/operations/Delete/Delete.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,UAAU,MAAM,kBAAkB,CAAC;AAY/C,OAAO,KAAK,EAEV,WAAW,EAEZ,MAAM,aAAa,CAAC;AAErB,OAAO,aAAa,MAAM,kBAAkB,CAAC;AA2B7C;;;;;;;;;GASG;AACH,cAAM,MAAM,CAAC,CAAC,SAAS,UAAU,CAAE,SAAQ,aAAa,CAAC,CAAC,CAAC;;gBAS7C,MAAM,EAAE,WAAW,CAAC,CAAC,CAAC;IAiBlC;;;;;;;OAOG;IACU,GAAG,CAAC,EAAE,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC;IAgC3C;;;;OAIG;YACW,QAAQ;IAiCtB;;;;OAIG;IACH,OAAO,CAAC,iCAAiC;IASzC;;;OAGG;IACH,OAAO,C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