dyna-record 0.1.4 → 0.2.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 (123) hide show
  1. package/README.md +15 -15
  2. package/dist/src/DynaRecord.d.ts +36 -28
  3. package/dist/src/DynaRecord.d.ts.map +1 -1
  4. package/dist/src/DynaRecord.js +39 -36
  5. package/dist/src/decorators/Table.d.ts.map +1 -1
  6. package/dist/src/decorators/attributes/BooleanAttribute.d.ts.map +1 -1
  7. package/dist/src/decorators/attributes/BooleanAttribute.js +1 -2
  8. package/dist/src/decorators/attributes/DateAttribute.d.ts.map +1 -1
  9. package/dist/src/decorators/attributes/DateAttribute.js +1 -2
  10. package/dist/src/decorators/attributes/EnumAttribute.d.ts +1 -1
  11. package/dist/src/decorators/attributes/EnumAttribute.d.ts.map +1 -1
  12. package/dist/src/decorators/attributes/EnumAttribute.js +2 -3
  13. package/dist/src/decorators/attributes/ForeignKeyAttribute.d.ts +1 -1
  14. package/dist/src/decorators/attributes/ForeignKeyAttribute.d.ts.map +1 -1
  15. package/dist/src/decorators/attributes/ForeignKeyAttribute.js +2 -3
  16. package/dist/src/decorators/attributes/IdAttribute.d.ts +32 -0
  17. package/dist/src/decorators/attributes/IdAttribute.d.ts.map +1 -0
  18. package/dist/src/decorators/attributes/IdAttribute.js +41 -0
  19. package/dist/src/decorators/attributes/NumberAttribute.d.ts.map +1 -1
  20. package/dist/src/decorators/attributes/NumberAttribute.js +1 -2
  21. package/dist/src/decorators/attributes/PartitionKeyAttribute.d.ts +1 -1
  22. package/dist/src/decorators/attributes/PartitionKeyAttribute.d.ts.map +1 -1
  23. package/dist/src/decorators/attributes/PartitionKeyAttribute.js +2 -3
  24. package/dist/src/decorators/attributes/SortKeyAttribute.d.ts +1 -1
  25. package/dist/src/decorators/attributes/SortKeyAttribute.d.ts.map +1 -1
  26. package/dist/src/decorators/attributes/SortKeyAttribute.js +2 -3
  27. package/dist/src/decorators/attributes/StringAttribute.d.ts +1 -1
  28. package/dist/src/decorators/attributes/StringAttribute.d.ts.map +1 -1
  29. package/dist/src/decorators/attributes/StringAttribute.js +2 -3
  30. package/dist/src/decorators/attributes/index.d.ts +1 -0
  31. package/dist/src/decorators/attributes/index.d.ts.map +1 -1
  32. package/dist/src/decorators/attributes/index.js +3 -1
  33. package/dist/src/decorators/attributes/serializers.d.ts +1 -1
  34. package/dist/src/decorators/relationships/BelongsTo.d.ts +1 -1
  35. package/dist/src/decorators/relationships/BelongsTo.d.ts.map +1 -1
  36. package/dist/src/decorators/relationships/BelongsTo.js +2 -3
  37. package/dist/src/decorators/relationships/HasAndBelongsToMany.d.ts +2 -2
  38. package/dist/src/decorators/relationships/HasAndBelongsToMany.d.ts.map +1 -1
  39. package/dist/src/decorators/relationships/HasAndBelongsToMany.js +3 -4
  40. package/dist/src/decorators/relationships/HasMany.d.ts +2 -2
  41. package/dist/src/decorators/relationships/HasMany.d.ts.map +1 -1
  42. package/dist/src/decorators/relationships/HasMany.js +3 -4
  43. package/dist/src/decorators/relationships/HasOne.d.ts +2 -2
  44. package/dist/src/decorators/relationships/HasOne.d.ts.map +1 -1
  45. package/dist/src/decorators/relationships/HasOne.js +3 -4
  46. package/dist/src/decorators/types.d.ts +2 -2
  47. package/dist/src/decorators/types.d.ts.map +1 -1
  48. package/dist/src/dynamo-utils/TransactGetBuilder.d.ts +4 -0
  49. package/dist/src/dynamo-utils/TransactGetBuilder.d.ts.map +1 -1
  50. package/dist/src/dynamo-utils/TransactGetBuilder.js +6 -0
  51. package/dist/src/metadata/EntityMetadata.d.ts +17 -1
  52. package/dist/src/metadata/EntityMetadata.d.ts.map +1 -1
  53. package/dist/src/metadata/EntityMetadata.js +25 -0
  54. package/dist/src/metadata/MetadataStorage.d.ts +6 -0
  55. package/dist/src/metadata/MetadataStorage.d.ts.map +1 -1
  56. package/dist/src/metadata/MetadataStorage.js +9 -0
  57. package/dist/src/metadata/TableMetadata.d.ts.map +1 -1
  58. package/dist/src/metadata/TableMetadata.js +2 -6
  59. package/dist/src/metadata/relationship-metadata/types.d.ts +4 -0
  60. package/dist/src/metadata/relationship-metadata/types.d.ts.map +1 -1
  61. package/dist/src/metadata/types.d.ts +2 -3
  62. package/dist/src/metadata/types.d.ts.map +1 -1
  63. package/dist/src/metadata/utils.d.ts.map +1 -1
  64. package/dist/src/operations/Create/Create.d.ts +95 -16
  65. package/dist/src/operations/Create/Create.d.ts.map +1 -1
  66. package/dist/src/operations/Create/Create.js +180 -29
  67. package/dist/src/operations/Delete/Delete.d.ts +29 -25
  68. package/dist/src/operations/Delete/Delete.d.ts.map +1 -1
  69. package/dist/src/operations/Delete/Delete.js +105 -104
  70. package/dist/src/operations/Delete/types.d.ts +0 -3
  71. package/dist/src/operations/Delete/types.d.ts.map +1 -1
  72. package/dist/src/operations/FindById/FindById.d.ts +7 -28
  73. package/dist/src/operations/FindById/FindById.d.ts.map +1 -1
  74. package/dist/src/operations/FindById/FindById.js +36 -125
  75. package/dist/src/operations/FindById/types.d.ts +8 -9
  76. package/dist/src/operations/FindById/types.d.ts.map +1 -1
  77. package/dist/src/operations/Query/Query.d.ts +2 -1
  78. package/dist/src/operations/Query/Query.d.ts.map +1 -1
  79. package/dist/src/operations/Query/Query.js +17 -4
  80. package/dist/src/operations/Query/types.d.ts +39 -5
  81. package/dist/src/operations/Query/types.d.ts.map +1 -1
  82. package/dist/src/operations/Update/Update.d.ts +185 -24
  83. package/dist/src/operations/Update/Update.d.ts.map +1 -1
  84. package/dist/src/operations/Update/Update.js +402 -72
  85. package/dist/src/operations/Update/UpdateDryRun.d.ts +10 -0
  86. package/dist/src/operations/Update/UpdateDryRun.d.ts.map +1 -0
  87. package/dist/src/operations/Update/UpdateDryRun.js +15 -0
  88. package/dist/src/operations/Update/index.d.ts +1 -0
  89. package/dist/src/operations/Update/index.d.ts.map +1 -1
  90. package/dist/src/operations/Update/index.js +3 -1
  91. package/dist/src/operations/types.d.ts +6 -1
  92. package/dist/src/operations/types.d.ts.map +1 -1
  93. package/dist/src/operations/utils/expressionBuilder.d.ts.map +1 -1
  94. package/dist/src/operations/utils/expressionBuilder.js +1 -4
  95. package/dist/src/operations/utils/index.d.ts +0 -1
  96. package/dist/src/operations/utils/index.d.ts.map +1 -1
  97. package/dist/src/operations/utils/index.js +0 -6
  98. package/dist/src/operations/utils/utils.d.ts +13 -3
  99. package/dist/src/operations/utils/utils.d.ts.map +1 -1
  100. package/dist/src/operations/utils/utils.js +33 -3
  101. package/dist/src/query-utils/Filters.d.ts +1 -1
  102. package/dist/src/query-utils/Filters.d.ts.map +1 -1
  103. package/dist/src/query-utils/Filters.js +7 -15
  104. package/dist/src/query-utils/QueryBuilder.d.ts.map +1 -1
  105. package/dist/src/query-utils/QueryBuilder.js +9 -1
  106. package/dist/src/relationships/JoinTable.d.ts +17 -7
  107. package/dist/src/relationships/JoinTable.d.ts.map +1 -1
  108. package/dist/src/relationships/JoinTable.js +77 -20
  109. package/dist/src/relationships/index.d.ts +0 -1
  110. package/dist/src/relationships/index.d.ts.map +1 -1
  111. package/dist/src/relationships/index.js +1 -3
  112. package/dist/src/types.d.ts +6 -8
  113. package/dist/src/types.d.ts.map +1 -1
  114. package/dist/src/utils.d.ts +10 -32
  115. package/dist/src/utils.d.ts.map +1 -1
  116. package/dist/src/utils.js +13 -59
  117. package/package.json +4 -4
  118. package/dist/src/operations/utils/RelationshipTransactions.d.ts +0 -64
  119. package/dist/src/operations/utils/RelationshipTransactions.d.ts.map +0 -1
  120. package/dist/src/operations/utils/RelationshipTransactions.js +0 -125
  121. package/dist/src/relationships/BelongsToLink.d.ts +0 -51
  122. package/dist/src/relationships/BelongsToLink.d.ts.map +0 -1
  123. package/dist/src/relationships/BelongsToLink.js +0 -57
package/README.md CHANGED
@@ -89,9 +89,7 @@ import DynaRecord, {
89
89
  id: { alias: "Id" },
90
90
  type: { alias: "Type" },
91
91
  createdAt: { alias: "CreatedAt" },
92
- updatedAt: { alias: "UpdatedAt" },
93
- foreignKey: { alias: "ForeignKey" },
94
- foreignEntityType: { alias: "ForeignEntityType" }
92
+ updatedAt: { alias: "UpdatedAt" }
95
93
  }
96
94
  })
97
95
  abstract class MyTable extends DynaRecord {
@@ -113,7 +111,7 @@ By default, each entity will have [default attributes](https://dyna-record.com/t
113
111
 
114
112
  - The partition key defined on the [table](#table) class
115
113
  - The sort key defined on the [table](#table) class
116
- - [id](https://dyna-record.com/classes/default.html#id) - The auto generated uuid for the model
114
+ - [id](https://dyna-record.com/classes/default.html#id) - The id for the model. This will be an autogenerated uuid unless [IdAttribute](<(https://dyna-record.com/functions/IdAttribute.html)>) is set on a non-nullable entity attribute.
117
115
  - [type](https://dyna-record.com/classes/default.html#type) - The type of the entity. Value is the entity class name
118
116
  - [createdAt](https://dyna-record.com/classes/default.html#updatedAt) - The timestamp of when the entity was created
119
117
  - [updatedAt](https://dyna-record.com/classes/default.html#updatedAt) - Timestamp of when the entity was updated last
@@ -143,6 +141,7 @@ Use the attribute decorators below to define attributes on a model. The decorato
143
141
  - [@BooleanAttribute](https://dyna-record.com/functions/BooleanAttribute.html)
144
142
  - [@DateAttribute](https://dyna-record.com/functions/DateAttribute.html)
145
143
  - [@EnumAttribute](https://dyna-record.com/functions/EnumAttribute.html)
144
+ - [@IdAttribute](https://dyna-record.com/functions/IdAttribute.html)
146
145
 
147
146
  - The [alias](https://dyna-record.com/interfaces/AttributeOptions.html#alias) option allows you to specify the attribute name as it appears in the DynamoDB table, different from your class property name.
148
147
  - Set nullable attributes as optional for optimal type safety
@@ -202,7 +201,7 @@ class Course extends MyTable {
202
201
 
203
202
  ### Relationships
204
203
 
205
- Dyna-Record supports defining relationships between entities such as [@HasOne](https://dyna-record.com/functions/HasOne.html), [@HasMany](https://dyna-record.com/functions/HasMany.html), [@BelongsTo](https://dyna-record.com/functions/BelongsTo.html) and [@HasAndBelongsToMany](https://dyna-record.com/functions/HasAndBelongsToMany.html). It does this by de-normalizing [BelongsToLinks](https://dyna-record.com/classes/BelongsToLink.html) according the each pattern to support relational querying.
204
+ Dyna-Record supports defining relationships between entities such as [@HasOne](https://dyna-record.com/functions/HasOne.html), [@HasMany](https://dyna-record.com/functions/HasMany.html), [@BelongsTo](https://dyna-record.com/functions/BelongsTo.html) and [@HasAndBelongsToMany](https://dyna-record.com/functions/HasAndBelongsToMany.html). It does this by de-normalizing records to each of its related entities partitions.
206
205
 
207
206
  A relationship can be defined as nullable or non-nullable. Non-nullable relationships will be enforced via transactions and violations will result in [NullConstraintViolationError](https://dyna-record.com/classes/NullConstraintViolationError.html)
208
207
 
@@ -309,7 +308,7 @@ class Student extends OtherTable {
309
308
 
310
309
  [Docs](https://dyna-record.com/classes/default.html#create)
311
310
 
312
- The create method is used to insert a new record into a DynamoDB table. This method automatically handles key generation (using UUIDs), timestamps for [createdAt](https://dyna-record.com/classes/default.html#createdAt) and [updatedAt](https://dyna-record.com/classes/default.html#updatedAt) fields, and the management of relationships between entities. It leverages AWS SDK's [TransactWriteCommand](https://www.google.com/search?q=aws+transact+write+command&oq=aws+transact+write+command&gs_lcrp=EgZjaHJvbWUyBggAEEUYOTIGCAEQRRg7MgYIAhBFGDvSAQgzMjAzajBqN6gCALACAA&sourceid=chrome&ie=UTF-8) for transactional integrity, ensuring either complete success or rollback in case of any failure. The method handles conditional checks to ensure data integrity and consistency during creation. If a foreignKey is set on create, dyna-record will de-normalize the data required in order to support the relationship
311
+ The create method is used to insert a new record into a DynamoDB table. This method automatically handles key generation (using UUIDs or custom id field if [IdAttribute](<(https://dyna-record.com/functions/IdAttribute.html)>) is set), timestamps for [createdAt](https://dyna-record.com/classes/default.html#createdAt) and [updatedAt](https://dyna-record.com/classes/default.html#updatedAt) fields, and the management of relationships between entities. It leverages AWS SDK's [TransactWriteCommand](https://www.google.com/search?q=aws+transact+write+command&oq=aws+transact+write+command&gs_lcrp=EgZjaHJvbWUyBggAEEUYOTIGCAEQRRg7MgYIAhBFGDvSAQgzMjAzajBqN6gCALACAA&sourceid=chrome&ie=UTF-8) for transactional integrity, ensuring either complete success or rollback in case of any failure. The method handles conditional checks to ensure data integrity and consistency during creation. If a foreignKey is set on create, dyna-record will de-normalize the data required in order to support the relationship
313
312
 
314
313
  To use the create method, call it on the model class you wish to create a new record for. Pass the properties of the new record as an object argument to the method. Only attributes defined on the model can be configured, and will be enforced via types and runtime schema validation.
315
314
 
@@ -341,6 +340,7 @@ The method is designed to throw errors under various conditions, such as transac
341
340
 
342
341
  - Automatic Timestamp Management: The [createdAt](https://dyna-record.com/classes/default.html#createdAt) and [updatedAt](https://dyna-record.com/classes/default.html#updatedAt) fields are managed automatically and reflect the time of creation and the last update, respectively.
343
342
  - Automatic ID Generation: Each entity created gets a unique [id](https://dyna-record.com/classes/default.html#id) generated by the uuidv4 method.
343
+ - This can be customized [IdAttribute](<(https://dyna-record.com/functions/IdAttribute.html)>) to support custom id attributes
344
344
  - Relationship Management: The ORM manages entity relationships through DynamoDB's single-table design patterns, creating and maintaining the necessary links between related entities.
345
345
  - Conditional Checks: To ensure data integrity, the create method performs various conditional checks, such as verifying the existence of entities that new records relate to.
346
346
  - Error Handling: Errors during the creation process are handled gracefully, with specific errors thrown for different failure scenarios, such as conditional check failures or transaction cancellations.
@@ -391,7 +391,7 @@ There are two main patterns; query by id and query by primary key
391
391
 
392
392
  To query items using the id, simply pass the partition key value as the first parameter. This fetches all items that share the same partition key value.
393
393
 
394
- The result will be an array of the entity and [BelongsToLinks](https://dyna-record.com/classes/BelongsToLink.html)
394
+ The result will be an array of the entity or related entities that match the filters
395
395
 
396
396
  ##### Query by id
397
397
 
@@ -414,7 +414,7 @@ const result = await Customer.query("123", {
414
414
  To be more precise to the underlying data, you can specify the partition key and sort key directly. The keys here will be the partition and sort keys defined on the [table](#table) class.
415
415
 
416
416
  ```typescript
417
- const orderLinks = await Customer.query({
417
+ const orders = await Customer.query({
418
418
  pk: "Customer#123",
419
419
  sk: { $beginsWith: "Order" }
420
420
  });
@@ -431,17 +431,17 @@ const result = await Course.query(
431
431
  },
432
432
  {
433
433
  filter: {
434
- type: ["BelongsToLink", "Brewery"],
434
+ type: ["Assignment", "Teacher"],
435
435
  createdAt: { $beginsWith: "202" },
436
436
  $or: [
437
437
  {
438
- foreignKey: "111",
438
+ name: "Potions",
439
439
  updatedAt: { $beginsWith: "2023-02-15" }
440
440
  },
441
441
  {
442
- foreignKey: ["222", "333"],
442
+ type: ["science", "math"],
443
443
  createdAt: { $beginsWith: "2021-09-15T" },
444
- foreignEntityType: "Assignment"
444
+ type: "Assignment"
445
445
  },
446
446
  {
447
447
  id: "123"
@@ -538,14 +538,14 @@ await User.delete("user-id");
538
538
 
539
539
  When deleting entities involved in HasMany or HasOne relationships:
540
540
 
541
- If a Pet belongs to an Owner (HasMany relationship), deleting the Pet will remove its BelongsToLink from the Owner's partition.
542
- If a Home belongs to a Person (HasOne relationship), deleting the Home will remove its BelongsToLink from the Person's partition.
541
+ If a Pet belongs to an Owner (HasMany relationship), deleting the Pet will remove its denormalized records from the Owner's partition.
542
+ If a Home belongs to a Person (HasOne relationship), deleting the Home will remove its denormalized records from the Person's partition.
543
543
 
544
544
  ```typescript
545
545
  await Home.delete("123");
546
546
  ```
547
547
 
548
- This deletes the Home entity and its BelongsToLink with a Person.
548
+ This deletes the Home entity and its denormalized record with a Person.
549
549
 
550
550
  #### Deleting Entities from HasAndBelongsToMany Relationships
551
551
 
@@ -1,5 +1,5 @@
1
1
  import { type QueryOptions as QueryBuilderOptions } from "./query-utils";
2
- import { type FindByIdOptions, type FindByIdIncludesRes, type QueryOptions, type EntityKeyConditions, type QueryResults, Create, type CreateOptions, type UpdateOptions } from "./operations";
2
+ import { type FindByIdOptions, type FindByIdIncludesRes, type QueryOptions, type EntityKeyConditions, type QueryResults, Create, type CreateOptions, type UpdateOptions, type EntityAttributesInstance } from "./operations";
3
3
  import type { EntityClass, Optional } from "./types";
4
4
  interface DynaRecordBase {
5
5
  id: string;
@@ -48,22 +48,30 @@ declare abstract class DynaRecord implements DynaRecordBase {
48
48
  */
49
49
  readonly updatedAt: Date;
50
50
  /**
51
- * Find an entity by Id and optionally include associations
52
- * @param {string} id - Entity Id
53
- * @param {Object} options - FindByIdOptions
54
- * @returns An entity with included associations serialized
51
+ * Find an entity by Id and optionally include associations.
52
+ *
53
+ * @param {string} id - Entity Id.
54
+ * @param {undefined} [options] - No options provided, returns the entity without included associations.
55
+ * @returns {Optional<T>} An entity without included associations serialized.
55
56
  *
56
57
  * @example Without included relationships
57
58
  * ```typescript
58
59
  * const user = await User.findById("userId");
59
60
  * ```
60
61
  *
62
+ * ---
63
+ *
64
+ * @param {string} id - Entity Id.
65
+ * @param {FindByIdOptions<T>} options - FindByIdOptions specifying associations to include.
66
+ * @returns {FindByIdIncludesRes<T, FindByIdOptions<T>>} An entity with included associations serialized.
67
+ *
61
68
  * @example With included relationships
62
69
  * ```typescript
63
70
  * const user = await User.findById("userId", { include: [{ association: "profile" }] });
64
71
  * ```
65
72
  */
66
- static findById<T extends DynaRecord, Opts extends FindByIdOptions<T>>(this: EntityClass<T>, id: string, options?: Opts): Promise<Optional<T | FindByIdIncludesRes<T, Opts>>>;
73
+ static findById<T extends DynaRecord>(this: EntityClass<T>, id: string, options?: undefined): Promise<Optional<EntityAttributesInstance<T>>>;
74
+ static findById<T extends DynaRecord, Opts extends FindByIdOptions<T>>(this: EntityClass<T>, id: string, options?: Opts): Promise<Optional<FindByIdIncludesRes<T, Opts>>>;
67
75
  /**
68
76
  * Query by PartitionKey and optional SortKey/Filter/Index conditions
69
77
  * @param {Object} key - PartitionKey value and optional SortKey condition. Keys must be attributes defined on the model
@@ -92,23 +100,22 @@ declare abstract class DynaRecord implements DynaRecordBase {
92
100
  * },
93
101
  * {
94
102
  * filter: {
95
- * type: ["BelongsToLink", "Profile"],
96
- * createdAt: { $beginsWith: "202" },
97
- * $or: [
98
- * {
99
- * foreignKey: "111",
100
- * updatedAt: { $beginsWith: "2023-02-15" }
101
- * },
102
- * {
103
- * foreignKey: ["222", "333"],
104
- * createdAt: { $beginsWith: "2021-09-15T" },
105
- * foreignEntityType: "Order"
106
- * },
107
- * {
108
- * id: "123"
109
- * }
110
- * ]
111
- * }
103
+ * type: ["Profile", "Preferences"],
104
+ * createdAt: { $beginsWith: "2023" },
105
+ * $or: [
106
+ * {
107
+ * name: "John",
108
+ * email: { $beginsWith: "testing }
109
+ * },
110
+ * {
111
+ * name: "Jane",
112
+ * updatedAt: { $beginsWith: "2024" },
113
+ * },
114
+ * {
115
+ * id: "123"
116
+ * }
117
+ * ]
118
+ * }
112
119
  * }
113
120
  *);
114
121
  * ```
@@ -150,7 +157,7 @@ declare abstract class DynaRecord implements DynaRecordBase {
150
157
  * ```typescript
151
158
  * const user = await User.query("123", {
152
159
  * filter: {
153
- * type: "BelongsToLink",
160
+ * type: "Profile",
154
161
  * createdAt: "2023-11-21T12:31:21.148Z"
155
162
  * }
156
163
  * });
@@ -158,7 +165,7 @@ declare abstract class DynaRecord implements DynaRecordBase {
158
165
  */
159
166
  static query<T extends DynaRecord>(this: EntityClass<T>, id: string, options?: Omit<QueryOptions, "indexName">): Promise<QueryResults<T>>;
160
167
  /**
161
- * Create an entity. If foreign keys are included in the attributes then BelongsToLinks will be demoralized accordingly
168
+ * Create an entity. If foreign keys are included in the attributes then links will be demoralized accordingly
162
169
  * @param attributes - Attributes of the model to create
163
170
  * @returns The new Entity
164
171
  *
@@ -169,8 +176,8 @@ declare abstract class DynaRecord implements DynaRecordBase {
169
176
  static create<T extends DynaRecord>(this: EntityClass<T>, attributes: CreateOptions<T>): Promise<ReturnType<Create<T>["run"]>>;
170
177
  /**
171
178
  * Update an entity. If foreign keys are included in the attribute then:
172
- * - BelongsToLinks will be created accordingly
173
- * - If the entity already had a foreign key relationship, then those BelongsToLinks will be deleted
179
+ * - Manages associated relationship links as needed
180
+ * - If the entity already had a foreign key relationship, then denormalized records will be deleted from each partition
174
181
  * - If the foreign key is not nullable then a {@link NullConstraintViolationError} is thrown.
175
182
  * - Validation errors will be thrown if the attribute being removed is not nullable
176
183
  * @param id - The id of the entity to update
@@ -205,7 +212,7 @@ declare abstract class DynaRecord implements DynaRecordBase {
205
212
  update<T extends this>(attributes: UpdateOptions<T>): Promise<T>;
206
213
  /**
207
214
  * Delete an entity by ID
208
- * - Delete all BelongsToLinks
215
+ * - Delete all denormalized records
209
216
  * - Disassociate all foreign keys of linked models
210
217
  * @param id - The id of the entity to update
211
218
  *
@@ -226,6 +233,7 @@ declare abstract class DynaRecord implements DynaRecordBase {
226
233
  * ```
227
234
  */
228
235
  static partitionKeyValue(id: string): string;
236
+ partitionKeyValue(): string;
229
237
  }
230
238
  export default DynaRecord;
231
239
  //# sourceMappingURL=DynaRecord.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"DynaRecord.d.ts","sourceRoot":"","sources":["../../src/DynaRecord.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,KAAK,YAAY,IAAI,mBAAmB,EAAE,MAAM,eAAe,CAAC;AAEzE,OAAO,EAEL,KAAK,eAAe,EACpB,KAAK,mBAAmB,EAExB,KAAK,YAAY,EACjB,KAAK,mBAAmB,EACxB,KAAK,YAAY,EACjB,MAAM,EACN,KAAK,aAAa,EAElB,KAAK,aAAa,EAGnB,MAAM,cAAc,CAAC;AACtB,OAAO,KAAK,EAAE,WAAW,EAAE,QAAQ,EAAE,MAAM,SAAS,CAAC;AAGrD,UAAU,cAAc;IACtB,EAAE,EAAE,MAAM,CAAC;IACX,IAAI,EAAE,MAAM,CAAC;IACb,SAAS,EAAE,IAAI,CAAC;IAChB,SAAS,EAAE,IAAI,CAAC;CACjB;AAED;;;;;;;;;;;;;;;;;;;;;;GAsBG;AACH,uBAAe,UAAW,YAAW,cAAc;IACjD;;OAEG;IACH,SACgB,EAAE,EAAE,MAAM,CAAC;IAE3B;;OAEG;IACH,SACgB,IAAI,EAAE,MAAM,CAAC;IAE7B;;OAEG;IACH,SACgB,SAAS,EAAE,IAAI,CAAC;IAEhC;;OAEG;IACH,SACgB,SAAS,EAAE,IAAI,CAAC;IAEhC;;;;;;;;;;;;;;;OAeG;WACiB,Q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C,MAAM,CAAC,CAAC,CAAC,CAAC,KAAK,CAAC,CAAC,CAAC;IAKxC;;;;;;;;;;;;;;;;;;;OAmBG;WACiB,MAAM,CAAC,CAAC,SAAS,UAAU,EAC7C,IAAI,EAAE,WAAW,CAAC,CAAC,CAAC,EACpB,EAAE,EAAE,MAAM,EACV,UAAU,EAAE,aAAa,CAAC,CAAC,CAAC,GAC3B,OAAO,CAAC,IAAI,CAAC;IAKhB;;;;;;;;;;;;;OAaG;IACU,MAAM,CAAC,CAAC,SAAS,IAAI,EAChC,UAAU,EAAE,aAAa,CAAC,CAAC,CAAC,GAC3B,OAAO,CAAC,CAAC,CAAC;IAkBb;;;;;;;;;;OAUG;WACiB,MAAM,CAAC,CAAC,SAAS,UAAU,EAC7C,IAAI,EAAE,WAAW,CAAC,CAAC,CAAC,EACpB,EAAE,EAAE,MAAM,GACT,OAAO,CAAC,IAAI,CAAC;IAKhB;;;;;;;;;OASG;WACW,iBAAiB,CAAC,EAAE,EAAE,MAAM,GAAG,MAAM;IAK5C,iBAAiB,IAAI,MAAM;CAGnC;AAED,eAAe,UAAU,CAAC"}
@@ -49,13 +49,23 @@ var __runInitializers = (this && this.__runInitializers) || function (thisArg, i
49
49
  }
50
50
  return useValue ? value : void 0;
51
51
  };
52
- var __importStar = (this && this.__importStar) || function (mod) {
53
- if (mod && mod.__esModule) return mod;
54
- var result = {};
55
- if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
56
- __setModuleDefault(result, mod);
57
- return result;
58
- };
52
+ var __importStar = (this && this.__importStar) || (function () {
53
+ var ownKeys = function(o) {
54
+ ownKeys = Object.getOwnPropertyNames || function (o) {
55
+ var ar = [];
56
+ for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
57
+ return ar;
58
+ };
59
+ return ownKeys(o);
60
+ };
61
+ return function (mod) {
62
+ if (mod && mod.__esModule) return mod;
63
+ var result = {};
64
+ if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
65
+ __setModuleDefault(result, mod);
66
+ return result;
67
+ };
68
+ })();
59
69
  Object.defineProperty(exports, "__esModule", { value: true });
60
70
  const metadata_1 = __importStar(require("./metadata"));
61
71
  const decorators_1 = require("./decorators");
@@ -85,15 +95,18 @@ const utils_1 = require("./utils");
85
95
  * ```
86
96
  */
87
97
  let DynaRecord = (() => {
88
- let _instanceExtraInitializers = [];
89
98
  let _id_decorators;
90
99
  let _id_initializers = [];
100
+ let _id_extraInitializers = [];
91
101
  let _type_decorators;
92
102
  let _type_initializers = [];
103
+ let _type_extraInitializers = [];
93
104
  let _createdAt_decorators;
94
105
  let _createdAt_initializers = [];
106
+ let _createdAt_extraInitializers = [];
95
107
  let _updatedAt_decorators;
96
108
  let _updatedAt_initializers = [];
109
+ let _updatedAt_extraInitializers = [];
97
110
  return class DynaRecord {
98
111
  static {
99
112
  const _metadata = typeof Symbol === "function" && Symbol.metadata ? Object.create(null) : void 0;
@@ -101,44 +114,28 @@ let DynaRecord = (() => {
101
114
  _type_decorators = [(0, decorators_1.StringAttribute)({ alias: metadata_1.tableDefaultFields.type.alias })];
102
115
  _createdAt_decorators = [(0, decorators_1.DateAttribute)({ alias: metadata_1.tableDefaultFields.createdAt.alias })];
103
116
  _updatedAt_decorators = [(0, decorators_1.DateAttribute)({ alias: metadata_1.tableDefaultFields.updatedAt.alias })];
104
- __esDecorate(null, null, _id_decorators, { kind: "field", name: "id", static: false, private: false, access: { has: obj => "id" in obj, get: obj => obj.id, set: (obj, value) => { obj.id = value; } }, metadata: _metadata }, _id_initializers, _instanceExtraInitializers);
105
- __esDecorate(null, null, _type_decorators, { kind: "field", name: "type", static: false, private: false, access: { has: obj => "type" in obj, get: obj => obj.type, set: (obj, value) => { obj.type = value; } }, metadata: _metadata }, _type_initializers, _instanceExtraInitializers);
106
- __esDecorate(null, null, _createdAt_decorators, { kind: "field", name: "createdAt", static: false, private: false, access: { has: obj => "createdAt" in obj, get: obj => obj.createdAt, set: (obj, value) => { obj.createdAt = value; } }, metadata: _metadata }, _createdAt_initializers, _instanceExtraInitializers);
107
- __esDecorate(null, null, _updatedAt_decorators, { kind: "field", name: "updatedAt", static: false, private: false, access: { has: obj => "updatedAt" in obj, get: obj => obj.updatedAt, set: (obj, value) => { obj.updatedAt = value; } }, metadata: _metadata }, _updatedAt_initializers, _instanceExtraInitializers);
117
+ __esDecorate(null, null, _id_decorators, { kind: "field", name: "id", static: false, private: false, access: { has: obj => "id" in obj, get: obj => obj.id, set: (obj, value) => { obj.id = value; } }, metadata: _metadata }, _id_initializers, _id_extraInitializers);
118
+ __esDecorate(null, null, _type_decorators, { kind: "field", name: "type", static: false, private: false, access: { has: obj => "type" in obj, get: obj => obj.type, set: (obj, value) => { obj.type = value; } }, metadata: _metadata }, _type_initializers, _type_extraInitializers);
119
+ __esDecorate(null, null, _createdAt_decorators, { kind: "field", name: "createdAt", static: false, private: false, access: { has: obj => "createdAt" in obj, get: obj => obj.createdAt, set: (obj, value) => { obj.createdAt = value; } }, metadata: _metadata }, _createdAt_initializers, _createdAt_extraInitializers);
120
+ __esDecorate(null, null, _updatedAt_decorators, { kind: "field", name: "updatedAt", static: false, private: false, access: { has: obj => "updatedAt" in obj, get: obj => obj.updatedAt, set: (obj, value) => { obj.updatedAt = value; } }, metadata: _metadata }, _updatedAt_initializers, _updatedAt_extraInitializers);
108
121
  if (_metadata) Object.defineProperty(this, Symbol.metadata, { enumerable: true, configurable: true, writable: true, value: _metadata });
109
122
  }
110
123
  /**
111
124
  * A unique identifier for the entity itself, automatically generated upon creation.
112
125
  */
113
- id = (__runInitializers(this, _instanceExtraInitializers), __runInitializers(this, _id_initializers, void 0));
126
+ id = __runInitializers(this, _id_initializers, void 0);
114
127
  /**
115
128
  * The type of the Entity
116
129
  */
117
- type = __runInitializers(this, _type_initializers, void 0);
130
+ type = (__runInitializers(this, _id_extraInitializers), __runInitializers(this, _type_initializers, void 0));
118
131
  /**
119
132
  * The timestamp marking when the entity was created
120
133
  */
121
- createdAt = __runInitializers(this, _createdAt_initializers, void 0);
134
+ createdAt = (__runInitializers(this, _type_extraInitializers), __runInitializers(this, _createdAt_initializers, void 0));
122
135
  /**
123
136
  * The timestamp marking the last update to the entity. Initially set to the same value as `createdAt`.
124
137
  */
125
- updatedAt = __runInitializers(this, _updatedAt_initializers, void 0);
126
- /**
127
- * Find an entity by Id and optionally include associations
128
- * @param {string} id - Entity Id
129
- * @param {Object} options - FindByIdOptions
130
- * @returns An entity with included associations serialized
131
- *
132
- * @example Without included relationships
133
- * ```typescript
134
- * const user = await User.findById("userId");
135
- * ```
136
- *
137
- * @example With included relationships
138
- * ```typescript
139
- * const user = await User.findById("userId", { include: [{ association: "profile" }] });
140
- * ```
141
- */
138
+ updatedAt = (__runInitializers(this, _createdAt_extraInitializers), __runInitializers(this, _updatedAt_initializers, void 0));
142
139
  static async findById(id, options) {
143
140
  const op = new operations_1.FindById(this);
144
141
  return await op.run(id, options);
@@ -148,7 +145,7 @@ let DynaRecord = (() => {
148
145
  return await op.run(key, options);
149
146
  }
150
147
  /**
151
- * Create an entity. If foreign keys are included in the attributes then BelongsToLinks will be demoralized accordingly
148
+ * Create an entity. If foreign keys are included in the attributes then links will be demoralized accordingly
152
149
  * @param attributes - Attributes of the model to create
153
150
  * @returns The new Entity
154
151
  *
@@ -162,8 +159,8 @@ let DynaRecord = (() => {
162
159
  }
163
160
  /**
164
161
  * Update an entity. If foreign keys are included in the attribute then:
165
- * - BelongsToLinks will be created accordingly
166
- * - If the entity already had a foreign key relationship, then those BelongsToLinks will be deleted
162
+ * - Manages associated relationship links as needed
163
+ * - If the entity already had a foreign key relationship, then denormalized records will be deleted from each partition
167
164
  * - If the foreign key is not nullable then a {@link NullConstraintViolationError} is thrown.
168
165
  * - Validation errors will be thrown if the attribute being removed is not nullable
169
166
  * @param id - The id of the entity to update
@@ -211,7 +208,7 @@ let DynaRecord = (() => {
211
208
  }
212
209
  /**
213
210
  * Delete an entity by ID
214
- * - Delete all BelongsToLinks
211
+ * - Delete all denormalized records
215
212
  * - Disassociate all foreign keys of linked models
216
213
  * @param id - The id of the entity to update
217
214
  *
@@ -238,6 +235,12 @@ let DynaRecord = (() => {
238
235
  const { delimiter } = metadata_1.default.getEntityTable(this.name);
239
236
  return `${this.name}${delimiter}${id}`;
240
237
  }
238
+ partitionKeyValue() {
239
+ return this.constructor.partitionKeyValue(this.id);
240
+ }
241
+ constructor() {
242
+ __runInitializers(this, _updatedAt_extraInitializers);
243
+ }
241
244
  };
242
245
  })();
243
246
  exports.default = DynaRecord;
@@ -1 +1 @@
1
- {"version":3,"file":"Table.d.ts","sourceRoot":"","sources":["../../../src/decorators/Table.ts"],"names":[],"mappings":"AAAA,OAAiB,EAAE,KAAK,oBAAoB,EAAE,MAAM,aAAa,CAAC;AAClE,OAAO,KAAK,UAAU,MAAM,eAAe,CAAC;AAE5C;;;;;;;;;;;;;;;;GAgBG;AACH,iBAAS,KAAK,CAAC,KAAK,EAAE,oBAAoB,YACf,iBAAiB,WAAW,qBAAqB,UAK3E;AAED,eAAe,KAAK,CAAC"}
1
+ {"version":3,"file":"Table.d.ts","sourceRoot":"","sources":["../../../src/decorators/Table.ts"],"names":[],"mappings":"AAAA,OAAiB,EAAE,KAAK,oBAAoB,EAAE,MAAM,aAAa,CAAC;AAClE,OAAO,KAAK,UAAU,MAAM,eAAe,CAAC;AAE5C;;;;;;;;;;;;;;;;GAgBG;AACH,iBAAS,KAAK,CAAC,KAAK,EAAE,oBAAoB,YACf,OAAO,UAAU,WAAW,qBAAqB,UAK3E;AAED,eAAe,KAAK,CAAC"}
@@ -1 +1 @@
1
- {"version":3,"file":"BooleanAttribute.d.ts","sourceRoot":"","sources":["../../../../src/decorators/attributes/BooleanAttribute.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,UAAU,MAAM,kBAAkB,CAAC;AAE/C,OAAO,KAAK,EAAE,yBAAyB,EAAE,gBAAgB,EAAE,MAAM,UAAU,CAAC;AAE5E;;;;;;;;;;;;;;;;;;;;;;GAsBG;AACH,iBAAS,gBAAgB,CACvB,CAAC,SAAS,UAAU,EACpB,CAAC,SAAS,OAAO,EACjB,CAAC,SAAS,gBAAgB,EAC1B,KAAK,CAAC,EAAE,CAAC,YAEC,SAAS,WACR,0BAA0B,CAAC,EAAE,CAAC,EAAE,CAAC,CAAC,UAe9C;AAED,eAAe,gBAAgB,CAAC"}
1
+ {"version":3,"file":"BooleanAttribute.d.ts","sourceRoot":"","sources":["../../../../src/decorators/attributes/BooleanAttribute.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,UAAU,MAAM,kBAAkB,CAAC;AAE/C,OAAO,KAAK,EAAE,yBAAyB,EAAE,gBAAgB,EAAE,MAAM,UAAU,CAAC;AAE5E;;;;;;;;;;;;;;;;;;;;;;GAsBG;AACH,iBAAS,gBAAgB,CACvB,CAAC,SAAS,UAAU,EACpB,CAAC,SAAS,OAAO,EACjB,CAAC,SAAS,gBAAgB,EAC1B,KAAK,CAAC,EAAE,CAAC,YAEC,SAAS,WACR,yBAAyB,CAAC,CAAC,EAAE,CAAC,EAAE,CAAC,CAAC,UAa9C;AAED,eAAe,gBAAgB,CAAC"}
@@ -32,8 +32,7 @@ function BooleanAttribute(props) {
32
32
  return function (_value, context) {
33
33
  if (context.kind === "field") {
34
34
  context.addInitializer(function () {
35
- const entity = Object.getPrototypeOf(this);
36
- metadata_1.default.addEntityAttribute(entity.constructor.name, {
35
+ metadata_1.default.addEntityAttribute(this.constructor.name, {
37
36
  attributeName: context.name.toString(),
38
37
  nullable: props?.nullable,
39
38
  type: zod_1.z.boolean(),
@@ -1 +1 @@
1
- {"version":3,"file":"DateAttribute.d.ts","sourceRoot":"","sources":["../../../../src/decorators/attributes/DateAttribute.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,UAAU,MAAM,kBAAkB,CAAC;AAE/C,OAAO,KAAK,EAAE,yBAAyB,EAAE,gBAAgB,EAAE,MAAM,UAAU,CAAC;AAG5E;;;;;;;;;;;;;;;;;;;;;;;;GAwBG;AACH,iBAAS,aAAa,CACpB,CAAC,SAAS,UAAU,EACpB,CAAC,SAAS,IAAI,EACd,CAAC,SAAS,gBAAgB,EAC1B,KAAK,CAAC,EAAE,CAAC,YAEC,SAAS,WACR,0BAA0B,CAAC,EAAE,CAAC,EAAE,CAAC,CAAC,UAgB9C;AAED,eAAe,aAAa,CAAC"}
1
+ {"version":3,"file":"DateAttribute.d.ts","sourceRoot":"","sources":["../../../../src/decorators/attributes/DateAttribute.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,UAAU,MAAM,kBAAkB,CAAC;AAE/C,OAAO,KAAK,EAAE,yBAAyB,EAAE,gBAAgB,EAAE,MAAM,UAAU,CAAC;AAG5E;;;;;;;;;;;;;;;;;;;;;;;;GAwBG;AACH,iBAAS,aAAa,CACpB,CAAC,SAAS,UAAU,EACpB,CAAC,SAAS,IAAI,EACd,CAAC,SAAS,gBAAgB,EAC1B,KAAK,CAAC,EAAE,CAAC,YAEC,SAAS,WACR,yBAAyB,CAAC,CAAC,EAAE,CAAC,EAAE,CAAC,CAAC,UAc9C;AAED,eAAe,aAAa,CAAC"}
@@ -35,8 +35,7 @@ function DateAttribute(props) {
35
35
  return function (_value, context) {
36
36
  if (context.kind === "field") {
37
37
  context.addInitializer(function () {
38
- const entity = Object.getPrototypeOf(this);
39
- metadata_1.default.addEntityAttribute(entity.constructor.name, {
38
+ metadata_1.default.addEntityAttribute(this.constructor.name, {
40
39
  attributeName: context.name.toString(),
41
40
  nullable: props?.nullable,
42
41
  serializers: serializers_1.dateSerializer,
@@ -18,7 +18,7 @@ export interface EnumAttributeOptions extends AttributeOptions {
18
18
  *
19
19
  * Usage example:
20
20
  * ```typescript
21
- * class Product extends BaseEntity {
21
+ * class Product extends TableClass {
22
22
  * @EnumAttribute({ alias: 'SomeField', values: ["val-1", "val-2"] })
23
23
  * public someField: "val-1" | "val-2"; // Attribute representing the union/enum types specified in `values`. In this case the only allowed values are "val-1" and "val-2"
24
24
  *
@@ -1 +1 @@
1
- {"version":3,"file":"EnumAttribute.d.ts","sourceRoot":"","sources":["../../../../src/decorators/attributes/EnumAttribute.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,UAAU,MAAM,kBAAkB,CAAC;AAE/C,OAAO,KAAK,EAAE,yBAAyB,EAAE,gBAAgB,EAAE,MAAM,UAAU,CAAC;AAE5E;;GAEG;AACH,MAAM,WAAW,oBAAqB,SAAQ,gBAAgB;IAG5D,MAAM,EAAE,CAAC,MAAM,EAAE,GAAG,MAAM,EAAE,CAAC,CAAC;CAC/B;AAED;;;;;;;;;;;;;;;;;;;;GAoBG;AACH,iBAAS,aAAa,CACpB,CAAC,SAAS,UAAU,EACpB,KAAK,CAAC,CAAC,SAAS,CAAC,CAAC,QAAQ,CAAC,CAAC,MAAM,CAAC,EACnC,KAAK,CAAC,CAAC,SAAS,oBAAoB,EACpC,KAAK,EAAE,CAAC,YAEE,SAAS,WACR,0BAA0B,CAAC,EAAE,CAAC,EAAE,CAAC,CAAC,UAe9C;AAED,eAAe,aAAa,CAAC"}
1
+ {"version":3,"file":"EnumAttribute.d.ts","sourceRoot":"","sources":["../../../../src/decorators/attributes/EnumAttribute.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,UAAU,MAAM,kBAAkB,CAAC;AAE/C,OAAO,KAAK,EAAE,yBAAyB,EAAE,gBAAgB,EAAE,MAAM,UAAU,CAAC;AAE5E;;GAEG;AACH,MAAM,WAAW,oBAAqB,SAAQ,gBAAgB;IAG5D,MAAM,EAAE,CAAC,MAAM,EAAE,GAAG,MAAM,EAAE,CAAC,CAAC;CAC/B;AAED;;;;;;;;;;;;;;;;;;;;GAoBG;AACH,iBAAS,aAAa,CACpB,CAAC,SAAS,UAAU,EACpB,KAAK,CAAC,CAAC,SAAS,CAAC,CAAC,QAAQ,CAAC,CAAC,MAAM,CAAC,EACnC,KAAK,CAAC,CAAC,SAAS,oBAAoB,EACpC,KAAK,EAAE,CAAC,YAEE,SAAS,WACR,yBAAyB,CAAC,CAAC,EAAE,CAAC,EAAE,CAAC,CAAC,UAa9C;AAED,eAAe,aAAa,CAAC"}
@@ -17,7 +17,7 @@ const metadata_1 = __importDefault(require("../../metadata"));
17
17
  *
18
18
  * Usage example:
19
19
  * ```typescript
20
- * class Product extends BaseEntity {
20
+ * class Product extends TableClass {
21
21
  * @EnumAttribute({ alias: 'SomeField', values: ["val-1", "val-2"] })
22
22
  * public someField: "val-1" | "val-2"; // Attribute representing the union/enum types specified in `values`. In this case the only allowed values are "val-1" and "val-2"
23
23
  *
@@ -30,8 +30,7 @@ function EnumAttribute(props) {
30
30
  return function (_value, context) {
31
31
  if (context.kind === "field") {
32
32
  context.addInitializer(function () {
33
- const entity = Object.getPrototypeOf(this);
34
- metadata_1.default.addEntityAttribute(entity.constructor.name, {
33
+ metadata_1.default.addEntityAttribute(this.constructor.name, {
35
34
  attributeName: context.name.toString(),
36
35
  nullable: props?.nullable,
37
36
  type: zod_1.z.enum(props.values),
@@ -14,7 +14,7 @@ import type { AttributeDecoratorContext, AttributeOptions } from "../types";
14
14
  *
15
15
  * Usage example:
16
16
  * ```typescript
17
- * class Order extends BaseEntity {
17
+ * class Order extends TableClass {
18
18
  * @ForeignKeyAttribute({ alias: 'UserID' })
19
19
  * public userId: ForeignKey; // Foreign key to the User entity. Cannot be optional.
20
20
  *
@@ -1 +1 @@
1
- {"version":3,"file":"ForeignKeyAttribute.d.ts","sourceRoot":"","sources":["../../../../src/decorators/attributes/ForeignKeyAttribute.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,UAAU,MAAM,kBAAkB,CAAC;AAE/C,OAAO,KAAK,EAAE,UAAU,EAAE,kBAAkB,EAAE,MAAM,aAAa,CAAC;AAClE,OAAO,KAAK,EAAE,yBAAyB,EAAE,gBAAgB,EAAE,MAAM,UAAU,CAAC;AAE5E;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA6BG;AACH,iBAAS,mBAAmB,CAAC,CAAC,SAAS,UAAU,EAAE,CAAC,SAAS,gBAAgB,EAC3E,KAAK,CAAC,EAAE,CAAC,YAGC,SAAS,WACR,0BACP,CAAC,EACD,CAAC,CAAC,UAAU,CAAC,SAAS,IAAI,GAAG,kBAAkB,GAAG,UAAU,EAC5D,CAAC,CACF,UAeJ;AAED,eAAe,mBAAmB,CAAC"}
1
+ {"version":3,"file":"ForeignKeyAttribute.d.ts","sourceRoot":"","sources":["../../../../src/decorators/attributes/ForeignKeyAttribute.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,UAAU,MAAM,kBAAkB,CAAC;AAE/C,OAAO,KAAK,EAAE,UAAU,EAAE,kBAAkB,EAAE,MAAM,aAAa,CAAC;AAClE,OAAO,KAAK,EAAE,yBAAyB,EAAE,gBAAgB,EAAE,MAAM,UAAU,CAAC;AAE5E;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA6BG;AACH,iBAAS,mBAAmB,CAAC,CAAC,SAAS,UAAU,EAAE,CAAC,SAAS,gBAAgB,EAC3E,KAAK,CAAC,EAAE,CAAC,YAGC,SAAS,WACR,yBAAyB,CAChC,CAAC,EACD,CAAC,CAAC,UAAU,CAAC,SAAS,IAAI,GAAG,kBAAkB,GAAG,UAAU,EAC5D,CAAC,CACF,UAaJ;AAED,eAAe,mBAAmB,CAAC"}
@@ -18,7 +18,7 @@ const metadata_1 = __importDefault(require("../../metadata"));
18
18
  *
19
19
  * Usage example:
20
20
  * ```typescript
21
- * class Order extends BaseEntity {
21
+ * class Order extends TableClass {
22
22
  * @ForeignKeyAttribute({ alias: 'UserID' })
23
23
  * public userId: ForeignKey; // Foreign key to the User entity. Cannot be optional.
24
24
  *
@@ -39,8 +39,7 @@ function ForeignKeyAttribute(props) {
39
39
  return function (_value, context) {
40
40
  if (context.kind === "field") {
41
41
  context.addInitializer(function () {
42
- const entity = Object.getPrototypeOf(this);
43
- metadata_1.default.addEntityAttribute(entity.constructor.name, {
42
+ metadata_1.default.addEntityAttribute(this.constructor.name, {
44
43
  attributeName: context.name.toString(),
45
44
  nullable: props?.nullable,
46
45
  type: zod_1.z.string(),
@@ -0,0 +1,32 @@
1
+ import type DynaRecord from "../../DynaRecord";
2
+ /**
3
+ * An optional decorator for marking class fields as the primary identifier (ID) within the context of a single-table design entity.
4
+ *
5
+ * By default, if no IdAttribute is specified on an entity, then a uuid is generated for each entity
6
+ *
7
+ * Use this decorator to specify the field you want to use as the id for each entity. For example, if you wanted a users email to be their id.
8
+ *
9
+ * This decorator registers the decorated field as the unique identifier for the entity, ensuring proper entity identity management within the ORM.
10
+ *
11
+ * IMPORTANT! - The ID field is a required field and must be a unique identifier for each entity instance. It cannot be applied to nullable attributes
12
+ *
13
+ * @template T The entity the decorator is applied to, extending {@link DynaRecord}.
14
+ * @template K The type of the field being marked as the ID.
15
+ * @param _value This parameter is unused but required for compatibility with the class field decorator structure.
16
+ * @param context Provides metadata about the field being decorated, including its name and class.
17
+ * @returns A class field decorator function that registers the decorated field as the entity's ID within the ORM metadata system.
18
+ *
19
+ * Usage example:
20
+ * ```typescript
21
+ * class User extends TableClass {
22
+ * @IdAttribute
23
+ * @StringAttribute({ alias: "Email" })
24
+ * public readonly email: string;
25
+ * }
26
+ * ```
27
+ *
28
+ * Here, `@IdAttribute` decorates `email` of `User` as the primary identifier, ensuring it is registered and managed as the entity's unique key.
29
+ */
30
+ declare function IdAttribute<T extends DynaRecord, K extends string>(_value: undefined, context: ClassFieldDecoratorContext<T, K>): (this: T, value: K) => K;
31
+ export default IdAttribute;
32
+ //# sourceMappingURL=IdAttribute.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"IdAttribute.d.ts","sourceRoot":"","sources":["../../../../src/decorators/attributes/IdAttribute.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,UAAU,MAAM,kBAAkB,CAAC;AAG/C;;;;;;;;;;;;;;;;;;;;;;;;;;;GA2BG;AACH,iBAAS,WAAW,CAAC,CAAC,SAAS,UAAU,EAAE,CAAC,SAAS,MAAM,EACzD,MAAM,EAAE,SAAS,EACjB,OAAO,EAAE,0BAA0B,CAAC,CAAC,EAAE,CAAC,CAAC,UAElB,CAAC,SAAS,CAAC,OAInC;AAED,eAAe,WAAW,CAAC"}
@@ -0,0 +1,41 @@
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 metadata_1 = __importDefault(require("../../metadata"));
7
+ /**
8
+ * An optional decorator for marking class fields as the primary identifier (ID) within the context of a single-table design entity.
9
+ *
10
+ * By default, if no IdAttribute is specified on an entity, then a uuid is generated for each entity
11
+ *
12
+ * Use this decorator to specify the field you want to use as the id for each entity. For example, if you wanted a users email to be their id.
13
+ *
14
+ * This decorator registers the decorated field as the unique identifier for the entity, ensuring proper entity identity management within the ORM.
15
+ *
16
+ * IMPORTANT! - The ID field is a required field and must be a unique identifier for each entity instance. It cannot be applied to nullable attributes
17
+ *
18
+ * @template T The entity the decorator is applied to, extending {@link DynaRecord}.
19
+ * @template K The type of the field being marked as the ID.
20
+ * @param _value This parameter is unused but required for compatibility with the class field decorator structure.
21
+ * @param context Provides metadata about the field being decorated, including its name and class.
22
+ * @returns A class field decorator function that registers the decorated field as the entity's ID within the ORM metadata system.
23
+ *
24
+ * Usage example:
25
+ * ```typescript
26
+ * class User extends TableClass {
27
+ * @IdAttribute
28
+ * @StringAttribute({ alias: "Email" })
29
+ * public readonly email: string;
30
+ * }
31
+ * ```
32
+ *
33
+ * Here, `@IdAttribute` decorates `email` of `User` as the primary identifier, ensuring it is registered and managed as the entity's unique key.
34
+ */
35
+ function IdAttribute(_value, context) {
36
+ return function (value) {
37
+ metadata_1.default.addEntityIdField(this.constructor.name, context.name.toString());
38
+ return value;
39
+ };
40
+ }
41
+ exports.default = IdAttribute;
@@ -1 +1 @@
1
- {"version":3,"file":"NumberAttribute.d.ts","sourceRoot":"","sources":["../../../../src/decorators/attributes/NumberAttribute.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,UAAU,MAAM,kBAAkB,CAAC;AAE/C,OAAO,KAAK,EAAE,yBAAyB,EAAE,gBAAgB,EAAE,MAAM,UAAU,CAAC;AAE5E;;;;;;;;;;;;;;;;;;;;;;GAsBG;AACH,iBAAS,eAAe,CACtB,CAAC,SAAS,UAAU,EACpB,CAAC,SAAS,MAAM,EAChB,CAAC,SAAS,gBAAgB,EAC1B,KAAK,CAAC,EAAE,CAAC,YAEC,SAAS,WACR,0BAA0B,CAAC,EAAE,CAAC,EAAE,CAAC,CAAC,UAe9C;AAED,eAAe,eAAe,CAAC"}
1
+ {"version":3,"file":"NumberAttribute.d.ts","sourceRoot":"","sources":["../../../../src/decorators/attributes/NumberAttribute.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,UAAU,MAAM,kBAAkB,CAAC;AAE/C,OAAO,KAAK,EAAE,yBAAyB,EAAE,gBAAgB,EAAE,MAAM,UAAU,CAAC;AAE5E;;;;;;;;;;;;;;;;;;;;;;GAsBG;AACH,iBAAS,eAAe,CACtB,CAAC,SAAS,UAAU,EACpB,CAAC,SAAS,MAAM,EAChB,CAAC,SAAS,gBAAgB,EAC1B,KAAK,CAAC,EAAE,CAAC,YAEC,SAAS,WACR,yBAAyB,CAAC,CAAC,EAAE,CAAC,EAAE,CAAC,CAAC,UAa9C;AAED,eAAe,eAAe,CAAC"}
@@ -32,8 +32,7 @@ function NumberAttribute(props) {
32
32
  return function (_value, context) {
33
33
  if (context.kind === "field") {
34
34
  context.addInitializer(function () {
35
- const entity = Object.getPrototypeOf(this);
36
- metadata_1.default.addEntityAttribute(entity.constructor.name, {
35
+ metadata_1.default.addEntityAttribute(this.constructor.name, {
37
36
  attributeName: context.name.toString(),
38
37
  nullable: props?.nullable,
39
38
  type: zod_1.z.number(),
@@ -11,7 +11,7 @@ import type { NonNullAttributeOptions } from "../types";
11
11
  *
12
12
  * Usage example:
13
13
  * ```typescript
14
- * class User extends BaseEntity {
14
+ * class User extends TableClass {
15
15
  * @PartitionKeyAttribute()
16
16
  * public pk: PartitionKey;
17
17
  * }