dyna-record 0.0.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (239) hide show
  1. package/README.md +3 -0
  2. package/dist/index.d.ts +2 -0
  3. package/dist/index.d.ts.map +1 -0
  4. package/dist/index.js +17 -0
  5. package/dist/src/DynaRecord.d.ts +216 -0
  6. package/dist/src/DynaRecord.d.ts.map +1 -0
  7. package/dist/src/DynaRecord.js +217 -0
  8. package/dist/src/Logger.d.ts +42 -0
  9. package/dist/src/Logger.d.ts.map +1 -0
  10. package/dist/src/Logger.js +57 -0
  11. package/dist/src/decorators/Entity.d.ts +23 -0
  12. package/dist/src/decorators/Entity.d.ts.map +1 -0
  13. package/dist/src/decorators/Entity.js +32 -0
  14. package/dist/src/decorators/Table.d.ts +22 -0
  15. package/dist/src/decorators/Table.d.ts.map +1 -0
  16. package/dist/src/decorators/Table.js +31 -0
  17. package/dist/src/decorators/attributes/Attribute.d.ts +26 -0
  18. package/dist/src/decorators/attributes/Attribute.d.ts.map +1 -0
  19. package/dist/src/decorators/attributes/Attribute.js +41 -0
  20. package/dist/src/decorators/attributes/DateAttribute.d.ts +25 -0
  21. package/dist/src/decorators/attributes/DateAttribute.d.ts.map +1 -0
  22. package/dist/src/decorators/attributes/DateAttribute.js +43 -0
  23. package/dist/src/decorators/attributes/DateNullableAttribute.d.ts +26 -0
  24. package/dist/src/decorators/attributes/DateNullableAttribute.d.ts.map +1 -0
  25. package/dist/src/decorators/attributes/DateNullableAttribute.js +43 -0
  26. package/dist/src/decorators/attributes/ForeignKeyAttribute.d.ts +25 -0
  27. package/dist/src/decorators/attributes/ForeignKeyAttribute.d.ts.map +1 -0
  28. package/dist/src/decorators/attributes/ForeignKeyAttribute.js +40 -0
  29. package/dist/src/decorators/attributes/NullableAttribute.d.ts +27 -0
  30. package/dist/src/decorators/attributes/NullableAttribute.d.ts.map +1 -0
  31. package/dist/src/decorators/attributes/NullableAttribute.js +41 -0
  32. package/dist/src/decorators/attributes/NullableForeignKeyAttribute.d.ts +25 -0
  33. package/dist/src/decorators/attributes/NullableForeignKeyAttribute.d.ts.map +1 -0
  34. package/dist/src/decorators/attributes/NullableForeignKeyAttribute.js +40 -0
  35. package/dist/src/decorators/attributes/PartitionKeyAttribute.d.ts +24 -0
  36. package/dist/src/decorators/attributes/PartitionKeyAttribute.d.ts.map +1 -0
  37. package/dist/src/decorators/attributes/PartitionKeyAttribute.js +38 -0
  38. package/dist/src/decorators/attributes/SortKeyAttribute.d.ts +24 -0
  39. package/dist/src/decorators/attributes/SortKeyAttribute.d.ts.map +1 -0
  40. package/dist/src/decorators/attributes/SortKeyAttribute.js +38 -0
  41. package/dist/src/decorators/attributes/index.d.ts +10 -0
  42. package/dist/src/decorators/attributes/index.d.ts.map +1 -0
  43. package/dist/src/decorators/attributes/index.js +37 -0
  44. package/dist/src/decorators/attributes/serializers.d.ts +13 -0
  45. package/dist/src/decorators/attributes/serializers.d.ts.map +1 -0
  46. package/dist/src/decorators/attributes/serializers.js +19 -0
  47. package/dist/src/decorators/index.d.ts +6 -0
  48. package/dist/src/decorators/index.d.ts.map +1 -0
  49. package/dist/src/decorators/index.js +27 -0
  50. package/dist/src/decorators/relationships/BelongsTo.d.ts +34 -0
  51. package/dist/src/decorators/relationships/BelongsTo.d.ts.map +1 -0
  52. package/dist/src/decorators/relationships/BelongsTo.js +50 -0
  53. package/dist/src/decorators/relationships/HasAndBelongsToMany.d.ts +80 -0
  54. package/dist/src/decorators/relationships/HasAndBelongsToMany.d.ts.map +1 -0
  55. package/dist/src/decorators/relationships/HasAndBelongsToMany.js +70 -0
  56. package/dist/src/decorators/relationships/HasMany.d.ts +35 -0
  57. package/dist/src/decorators/relationships/HasMany.d.ts.map +1 -0
  58. package/dist/src/decorators/relationships/HasMany.js +48 -0
  59. package/dist/src/decorators/relationships/HasOne.d.ts +35 -0
  60. package/dist/src/decorators/relationships/HasOne.d.ts.map +1 -0
  61. package/dist/src/decorators/relationships/HasOne.js +48 -0
  62. package/dist/src/decorators/relationships/index.d.ts +6 -0
  63. package/dist/src/decorators/relationships/index.d.ts.map +1 -0
  64. package/dist/src/decorators/relationships/index.js +29 -0
  65. package/dist/src/decorators/relationships/types.d.ts +11 -0
  66. package/dist/src/decorators/relationships/types.d.ts.map +1 -0
  67. package/dist/src/decorators/relationships/types.js +2 -0
  68. package/dist/src/decorators/types.d.ts +30 -0
  69. package/dist/src/decorators/types.d.ts.map +1 -0
  70. package/dist/src/decorators/types.js +2 -0
  71. package/dist/src/dynamo-utils/DynamoClient.d.ts +34 -0
  72. package/dist/src/dynamo-utils/DynamoClient.d.ts.map +1 -0
  73. package/dist/src/dynamo-utils/DynamoClient.js +57 -0
  74. package/dist/src/dynamo-utils/TransactGetBuilder.d.ts +18 -0
  75. package/dist/src/dynamo-utils/TransactGetBuilder.d.ts.map +1 -0
  76. package/dist/src/dynamo-utils/TransactGetBuilder.js +32 -0
  77. package/dist/src/dynamo-utils/TransactWriteBuilder.d.ts +46 -0
  78. package/dist/src/dynamo-utils/TransactWriteBuilder.d.ts.map +1 -0
  79. package/dist/src/dynamo-utils/TransactWriteBuilder.js +100 -0
  80. package/dist/src/dynamo-utils/errors.d.ts +13 -0
  81. package/dist/src/dynamo-utils/errors.d.ts.map +1 -0
  82. package/dist/src/dynamo-utils/errors.js +17 -0
  83. package/dist/src/dynamo-utils/index.d.ts +8 -0
  84. package/dist/src/dynamo-utils/index.d.ts.map +1 -0
  85. package/dist/src/dynamo-utils/index.js +30 -0
  86. package/dist/src/dynamo-utils/types.d.ts +52 -0
  87. package/dist/src/dynamo-utils/types.d.ts.map +1 -0
  88. package/dist/src/dynamo-utils/types.js +2 -0
  89. package/dist/src/errors.d.ts +13 -0
  90. package/dist/src/errors.d.ts.map +1 -0
  91. package/dist/src/errors.js +17 -0
  92. package/dist/src/index.d.ts +6 -0
  93. package/dist/src/index.d.ts.map +1 -0
  94. package/dist/src/index.js +24 -0
  95. package/dist/src/metadata/AttributeMetadata.d.ts +22 -0
  96. package/dist/src/metadata/AttributeMetadata.d.ts.map +1 -0
  97. package/dist/src/metadata/AttributeMetadata.js +27 -0
  98. package/dist/src/metadata/EntityMetadata.d.ts +42 -0
  99. package/dist/src/metadata/EntityMetadata.d.ts.map +1 -0
  100. package/dist/src/metadata/EntityMetadata.js +49 -0
  101. package/dist/src/metadata/JoinTableMetadata.d.ts +23 -0
  102. package/dist/src/metadata/JoinTableMetadata.d.ts.map +1 -0
  103. package/dist/src/metadata/JoinTableMetadata.js +22 -0
  104. package/dist/src/metadata/MetadataStorage.d.ts +104 -0
  105. package/dist/src/metadata/MetadataStorage.d.ts.map +1 -0
  106. package/dist/src/metadata/MetadataStorage.js +194 -0
  107. package/dist/src/metadata/TableMetadata.d.ts +53 -0
  108. package/dist/src/metadata/TableMetadata.d.ts.map +1 -0
  109. package/dist/src/metadata/TableMetadata.js +100 -0
  110. package/dist/src/metadata/index.d.ts +13 -0
  111. package/dist/src/metadata/index.d.ts.map +1 -0
  112. package/dist/src/metadata/index.js +34 -0
  113. package/dist/src/metadata/relationship-metadata/BelongsToRelationship.d.ts +18 -0
  114. package/dist/src/metadata/relationship-metadata/BelongsToRelationship.d.ts.map +1 -0
  115. package/dist/src/metadata/relationship-metadata/BelongsToRelationship.js +26 -0
  116. package/dist/src/metadata/relationship-metadata/HasAndBelongsToManyRelationship.d.ts +16 -0
  117. package/dist/src/metadata/relationship-metadata/HasAndBelongsToManyRelationship.d.ts.map +1 -0
  118. package/dist/src/metadata/relationship-metadata/HasAndBelongsToManyRelationship.js +25 -0
  119. package/dist/src/metadata/relationship-metadata/HasManyRelationship.d.ts +18 -0
  120. package/dist/src/metadata/relationship-metadata/HasManyRelationship.d.ts.map +1 -0
  121. package/dist/src/metadata/relationship-metadata/HasManyRelationship.js +26 -0
  122. package/dist/src/metadata/relationship-metadata/HasOneRelationship.d.ts +17 -0
  123. package/dist/src/metadata/relationship-metadata/HasOneRelationship.d.ts.map +1 -0
  124. package/dist/src/metadata/relationship-metadata/HasOneRelationship.js +25 -0
  125. package/dist/src/metadata/relationship-metadata/RelationshipMetadata.d.ts +21 -0
  126. package/dist/src/metadata/relationship-metadata/RelationshipMetadata.d.ts.map +1 -0
  127. package/dist/src/metadata/relationship-metadata/RelationshipMetadata.js +18 -0
  128. package/dist/src/metadata/relationship-metadata/index.d.ts +7 -0
  129. package/dist/src/metadata/relationship-metadata/index.d.ts.map +1 -0
  130. package/dist/src/metadata/relationship-metadata/index.js +29 -0
  131. package/dist/src/metadata/relationship-metadata/types.d.ts +16 -0
  132. package/dist/src/metadata/relationship-metadata/types.d.ts.map +1 -0
  133. package/dist/src/metadata/relationship-metadata/types.js +2 -0
  134. package/dist/src/metadata/relationship-metadata/utils.d.ts +3 -0
  135. package/dist/src/metadata/relationship-metadata/utils.d.ts.map +1 -0
  136. package/dist/src/metadata/relationship-metadata/utils.js +25 -0
  137. package/dist/src/metadata/types.d.ts +90 -0
  138. package/dist/src/metadata/types.d.ts.map +1 -0
  139. package/dist/src/metadata/types.js +2 -0
  140. package/dist/src/metadata/utils.d.ts +42 -0
  141. package/dist/src/metadata/utils.d.ts.map +1 -0
  142. package/dist/src/metadata/utils.js +67 -0
  143. package/dist/src/operations/Create/Create.d.ts +39 -0
  144. package/dist/src/operations/Create/Create.d.ts.map +1 -0
  145. package/dist/src/operations/Create/Create.js +84 -0
  146. package/dist/src/operations/Create/index.d.ts +3 -0
  147. package/dist/src/operations/Create/index.d.ts.map +1 -0
  148. package/dist/src/operations/Create/index.js +23 -0
  149. package/dist/src/operations/Create/types.d.ts +7 -0
  150. package/dist/src/operations/Create/types.d.ts.map +1 -0
  151. package/dist/src/operations/Create/types.js +2 -0
  152. package/dist/src/operations/Delete/Delete.d.ts +74 -0
  153. package/dist/src/operations/Delete/Delete.d.ts.map +1 -0
  154. package/dist/src/operations/Delete/Delete.js +207 -0
  155. package/dist/src/operations/Delete/index.d.ts +2 -0
  156. package/dist/src/operations/Delete/index.d.ts.map +1 -0
  157. package/dist/src/operations/Delete/index.js +8 -0
  158. package/dist/src/operations/Delete/types.d.ts +7 -0
  159. package/dist/src/operations/Delete/types.d.ts.map +1 -0
  160. package/dist/src/operations/Delete/types.js +2 -0
  161. package/dist/src/operations/FindById/FindById.d.ts +91 -0
  162. package/dist/src/operations/FindById/FindById.d.ts.map +1 -0
  163. package/dist/src/operations/FindById/FindById.js +244 -0
  164. package/dist/src/operations/FindById/index.d.ts +3 -0
  165. package/dist/src/operations/FindById/index.d.ts.map +1 -0
  166. package/dist/src/operations/FindById/index.js +23 -0
  167. package/dist/src/operations/FindById/types.d.ts +57 -0
  168. package/dist/src/operations/FindById/types.d.ts.map +1 -0
  169. package/dist/src/operations/FindById/types.js +2 -0
  170. package/dist/src/operations/OperationBase.d.ts +37 -0
  171. package/dist/src/operations/OperationBase.d.ts.map +1 -0
  172. package/dist/src/operations/OperationBase.js +44 -0
  173. package/dist/src/operations/Query/Query.d.ts +45 -0
  174. package/dist/src/operations/Query/Query.d.ts.map +1 -0
  175. package/dist/src/operations/Query/Query.js +84 -0
  176. package/dist/src/operations/Query/index.d.ts +3 -0
  177. package/dist/src/operations/Query/index.d.ts.map +1 -0
  178. package/dist/src/operations/Query/index.js +23 -0
  179. package/dist/src/operations/Query/types.d.ts +38 -0
  180. package/dist/src/operations/Query/types.d.ts.map +1 -0
  181. package/dist/src/operations/Query/types.js +2 -0
  182. package/dist/src/operations/Update/Update.d.ts +48 -0
  183. package/dist/src/operations/Update/Update.d.ts.map +1 -0
  184. package/dist/src/operations/Update/Update.js +118 -0
  185. package/dist/src/operations/Update/index.d.ts +3 -0
  186. package/dist/src/operations/Update/index.d.ts.map +1 -0
  187. package/dist/src/operations/Update/index.js +23 -0
  188. package/dist/src/operations/Update/types.d.ts +32 -0
  189. package/dist/src/operations/Update/types.d.ts.map +1 -0
  190. package/dist/src/operations/Update/types.js +2 -0
  191. package/dist/src/operations/index.d.ts +7 -0
  192. package/dist/src/operations/index.d.ts.map +1 -0
  193. package/dist/src/operations/index.js +22 -0
  194. package/dist/src/operations/types.d.ts +59 -0
  195. package/dist/src/operations/types.d.ts.map +1 -0
  196. package/dist/src/operations/types.js +2 -0
  197. package/dist/src/operations/utils/RelationshipTransactions.d.ts +64 -0
  198. package/dist/src/operations/utils/RelationshipTransactions.d.ts.map +1 -0
  199. package/dist/src/operations/utils/RelationshipTransactions.js +125 -0
  200. package/dist/src/operations/utils/expressionBuilder.d.ts +9 -0
  201. package/dist/src/operations/utils/expressionBuilder.d.ts.map +1 -0
  202. package/dist/src/operations/utils/expressionBuilder.js +106 -0
  203. package/dist/src/operations/utils/index.d.ts +5 -0
  204. package/dist/src/operations/utils/index.d.ts.map +1 -0
  205. package/dist/src/operations/utils/index.js +25 -0
  206. package/dist/src/operations/utils/types.d.ts +21 -0
  207. package/dist/src/operations/utils/types.d.ts.map +1 -0
  208. package/dist/src/operations/utils/types.js +2 -0
  209. package/dist/src/operations/utils/utils.d.ts +19 -0
  210. package/dist/src/operations/utils/utils.d.ts.map +1 -0
  211. package/dist/src/operations/utils/utils.js +36 -0
  212. package/dist/src/query-utils/Filters.d.ts +10 -0
  213. package/dist/src/query-utils/Filters.d.ts.map +1 -0
  214. package/dist/src/query-utils/Filters.js +25 -0
  215. package/dist/src/query-utils/QueryBuilder.d.ts +90 -0
  216. package/dist/src/query-utils/QueryBuilder.d.ts.map +1 -0
  217. package/dist/src/query-utils/QueryBuilder.js +213 -0
  218. package/dist/src/query-utils/index.d.ts +3 -0
  219. package/dist/src/query-utils/index.d.ts.map +1 -0
  220. package/dist/src/query-utils/index.js +23 -0
  221. package/dist/src/query-utils/types.d.ts +89 -0
  222. package/dist/src/query-utils/types.d.ts.map +1 -0
  223. package/dist/src/query-utils/types.js +2 -0
  224. package/dist/src/relationships/BelongsToLink.d.ts +50 -0
  225. package/dist/src/relationships/BelongsToLink.d.ts.map +1 -0
  226. package/dist/src/relationships/BelongsToLink.js +57 -0
  227. package/dist/src/relationships/JoinTable.d.ts +68 -0
  228. package/dist/src/relationships/JoinTable.d.ts.map +1 -0
  229. package/dist/src/relationships/JoinTable.js +133 -0
  230. package/dist/src/relationships/index.d.ts +3 -0
  231. package/dist/src/relationships/index.d.ts.map +1 -0
  232. package/dist/src/relationships/index.js +10 -0
  233. package/dist/src/types.d.ts +73 -0
  234. package/dist/src/types.d.ts.map +1 -0
  235. package/dist/src/types.js +2 -0
  236. package/dist/src/utils.d.ts +89 -0
  237. package/dist/src/utils.d.ts.map +1 -0
  238. package/dist/src/utils.js +168 -0
  239. package/package.json +61 -0
package/README.md ADDED
@@ -0,0 +1,3 @@
1
+ # dyna-record
2
+
3
+ Typescript Object Relational Mapper (ORM) for Dynamo
@@ -0,0 +1,2 @@
1
+ export * from "./src";
2
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../index.ts"],"names":[],"mappings":"AAAA,cAAc,OAAO,CAAC"}
package/dist/index.js ADDED
@@ -0,0 +1,17 @@
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
+ Object.defineProperty(exports, "__esModule", { value: true });
17
+ __exportStar(require("./src"), exports);
@@ -0,0 +1,216 @@
1
+ import { type QueryOptions as QueryBuilderOptions } from "./query-utils";
2
+ import { type FindByIdOptions, type FindByIdIncludesRes, type QueryOptions, type EntityKeyConditions, type QueryResults, type CreateOptions, type UpdateOptions } from "./operations";
3
+ import type { EntityClass, Optional } from "./types";
4
+ interface DynaRecordBase {
5
+ id: string;
6
+ type: string;
7
+ createdAt: Date;
8
+ updatedAt: Date;
9
+ }
10
+ /**
11
+ * Serves as an abstract base class for entities in the ORM system. It defines standard fields such as `id`, `type`, `createdAt`, and `updatedAt`, and provides static methods for CRUD operations and queries. This class encapsulates common behaviors and properties that all entities share, leveraging decorators for attribute metadata and supporting operations like finding, creating, updating, and deleting entities.
12
+ *
13
+ * Table classes should extend this class, and each entity should extend the table class
14
+ *
15
+ * Entities extending `DynaRecord` can utilize these operations to interact with their corresponding records in the database, including handling relationships between different entities.
16
+ * @example
17
+ * ```typescript
18
+ * @Table({ name: "my-table", delimiter: "#" })
19
+ * abstract class MyTable extends DynaRecord {
20
+ * @PartitionKeyAttribute()
21
+ * public readonly pk: PartitionKey;
22
+ *
23
+ * @SortKeyAttribute()
24
+ * public readonly sk: SortKey;
25
+ * }
26
+ *
27
+ * @Entity
28
+ * class User extends MyTable {
29
+ * // User implementation
30
+ * }
31
+ * ```
32
+ */
33
+ declare abstract class DynaRecord implements DynaRecordBase {
34
+ /**
35
+ * A unique identifier for the entity itself, automatically generated upon creation.
36
+ */
37
+ readonly id: string;
38
+ /**
39
+ * The type of the Entity
40
+ */
41
+ readonly type: string;
42
+ /**
43
+ * The timestamp marking when the entity was created
44
+ */
45
+ readonly createdAt: Date;
46
+ /**
47
+ * The timestamp marking the last update to the entity. Initially set to the same value as `createdAt`.
48
+ */
49
+ readonly updatedAt: Date;
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
55
+ *
56
+ * @example Without included relationships
57
+ * ```typescript
58
+ * const user = await User.findById("userId");
59
+ * ```
60
+ *
61
+ * @example With included relationships
62
+ * ```typescript
63
+ * const user = await User.findById("userId", { include: [{ association: "profile" }] });
64
+ * ```
65
+ */
66
+ static findById<T extends DynaRecord, Opts extends FindByIdOptions<T>>(this: EntityClass<T>, id: string, options?: Opts): Promise<Optional<T | FindByIdIncludesRes<T, Opts>>>;
67
+ /**
68
+ * Query by PartitionKey and optional SortKey/Filter/Index conditions
69
+ * @param {Object} key - PartitionKey value and optional SortKey condition. Keys must be attributes defined on the model
70
+ * @param {Object=} options - QueryBuilderOptions
71
+ *
72
+ * @example By partition key only
73
+ * ```typescript
74
+ * const user = await User.query({ pk: "User#123" });
75
+ * ```
76
+ *
77
+ * @example By partition key and sort key exact match
78
+ * ```typescript
79
+ * const user = await User.query({ pk: "User#123", sk: "Profile#123" });
80
+ * ```
81
+ *
82
+ * @example By partition key and sort key begins with
83
+ * ```typescript
84
+ * const user = await User.query({ pk: "User#123", sk: { $beginsWith: "Profile" } });
85
+ * ```
86
+ *
87
+ * @example With filter (arbitrary example)
88
+ * ```typescript
89
+ * const result = await User.query(
90
+ * {
91
+ * myPk: "User|123"
92
+ * },
93
+ * {
94
+ * 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
+ * }
112
+ * }
113
+ *);
114
+ * ```
115
+ *
116
+ * @example On index
117
+ * ```typescript
118
+ * const result = await User.query(
119
+ * {
120
+ * pk: "User#123",
121
+ * sk: { $beginsWith: "Profile" }
122
+ * },
123
+ * { indexName: "myIndex" }
124
+ * );
125
+ * ```
126
+ */
127
+ static query<T extends DynaRecord>(this: EntityClass<T>, key: EntityKeyConditions<T>, options?: QueryBuilderOptions): Promise<QueryResults<T>>;
128
+ /**
129
+ * Query an EntityPartition by EntityId and optional SortKey/Filter conditions.
130
+ * QueryByIndex not supported. Use Query with keys if indexName is needed
131
+ * @param {string} id - Entity Id
132
+ * @param {Object=} options - QueryOptions. Supports filter and skCondition. indexName is not supported
133
+ *
134
+ * @example By partition key only
135
+ * ```typescript
136
+ * const user = await User.query("123");
137
+ * ```
138
+ *
139
+ * @example By partition key and sort key exact match
140
+ * ```typescript
141
+ * const user = await User.query("123", { skCondition: "Profile#111" });
142
+ * ```
143
+ *
144
+ * @example By partition key and sort key begins with
145
+ * ```typescript
146
+ * const user = await User.query("123", { skCondition: { $beginsWith: "Profile" } })
147
+ * ```
148
+ *
149
+ * @example With filter (arbitrary example)
150
+ * ```typescript
151
+ * const user = await User.query("123", {
152
+ * filter: {
153
+ * type: "BelongsToLink",
154
+ * createdAt: "2023-11-21T12:31:21.148Z"
155
+ * }
156
+ * });
157
+ * ```
158
+ */
159
+ static query<T extends DynaRecord>(this: EntityClass<T>, id: string, options?: Omit<QueryOptions, "indexName">): Promise<QueryResults<T>>;
160
+ /**
161
+ * Create an entity. If foreign keys are included in the attributes then BelongsToLinks will be demoralized accordingly
162
+ * @param attributes - Attributes of the model to create
163
+ * @returns The new Entity
164
+ *
165
+ * ```typescript
166
+ * const newUser = await User.create({ name: "Alice", email: "alice@example.com", profileId: "123" });
167
+ * ```
168
+ */
169
+ static create<T extends DynaRecord>(this: EntityClass<T>, attributes: CreateOptions<T>): Promise<T>;
170
+ /**
171
+ * 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
174
+ * - If the foreign key is not nullable then a {@link NullConstraintViolationError} is thrown. See {@link NullableForeignKeyAttribute}
175
+ * - Validation errors will be thrown if the attribute being removed is not nullable
176
+ * @param id - The id of the entity to update
177
+ * @param attributes - Attributes to update
178
+ *
179
+ *
180
+ * @example Updating an entity.
181
+ * ```typescript
182
+ * await User.update("userId", { email: "newemail@example.com", profileId: 789 });
183
+ * ```
184
+ *
185
+ * @example Removing a nullable entities attributes
186
+ * ```typescript
187
+ * await User.update("userId", { email: "newemail@example.com", someKey: null });
188
+ * ```
189
+ */
190
+ static update<T extends DynaRecord>(this: EntityClass<T>, id: string, attributes: UpdateOptions<T>): Promise<void>;
191
+ /**
192
+ * Delete an entity by ID
193
+ * - Delete all BelongsToLinks
194
+ * - Disassociate all foreign keys of linked models
195
+ * @param id - The id of the entity to update
196
+ *
197
+ * @example Delete an entity
198
+ * ```typescript
199
+ * await User.delete("userId");
200
+ * ```
201
+ */
202
+ static delete<T extends DynaRecord>(this: EntityClass<T>, id: string): Promise<void>;
203
+ /**
204
+ * Constructs the partition key value
205
+ * @param {string} id - Entity Id
206
+ * @returns Constructed partition key value
207
+ *
208
+ * @example
209
+ * ```typescript
210
+ * const pkValue = User.partitionKeyValue("userId");
211
+ * ```
212
+ */
213
+ static partitionKeyValue(id: string): string;
214
+ }
215
+ export default DynaRecord;
216
+ //# sourceMappingURL=DynaRecord.d.ts.map
@@ -0,0 +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,EAEjB,KAAK,aAAa,EAElB,KAAK,aAAa,EAEnB,MAAM,cAAc,CAAC;AACtB,OAAO,KAAK,EAAE,WAAW,EAAE,QAAQ,EAAE,MAAM,SAAS,CAAC;AAErD,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,QAAQ,CAC1B,CAAC,SAAS,UAAU,EACpB,IAAI,SAAS,eAAe,CAAC,CAAC,CAAC,EAE/B,IAAI,EAAE,WAAW,CAAC,CAAC,CAAC,EACpB,EAAE,EAAE,MAAM,EACV,OAAO,CAAC,EAAE,IAAI,GACb,OAAO,CAAC,QAAQ,CAAC,CAAC,GAAG,mBAAmB,CAAC,CAAC,EAAE,IAAI,CAAC,CAAC,CAAC;IAKtD;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;OA2DG;WACiB,KAAK,CAAC,CAAC,SAAS,UAAU,EAC5C,IAAI,EAAE,WAAW,CAAC,CAAC,CAAC,EACpB,GAAG,EAAE,mBAAmB,CAAC,CAAC,CAAC,EAC3B,OAAO,CAAC,EAAE,mBAAmB,GAC5B,OAAO,CAAC,YAAY,CAAC,CAAC,CAAC,CAAC;IAE3B;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;OA8BG;WACiB,KAAK,CAAC,CAAC,SAAS,UAAU,EAC5C,IAAI,EAAE,WAAW,CAAC,CAAC,CAAC,EACpB,EAAE,EAAE,MAAM,EACV,OAAO,CAAC,EAAE,IAAI,CAAC,YAAY,EAAE,WAAW,CAAC,GACxC,OAAO,CAAC,YAAY,CAAC,CAAC,CAAC,CAAC;IAW3B;;;;;;;;OAQG;WACiB,MAAM,CAAC,CAAC,SAAS,UAAU,EAC7C,IAAI,EAAE,WAAW,CAAC,CAAC,CAAC,EACpB,UAAU,EAAE,aAAa,CAAC,CAAC,CAAC,GAC3B,OAAO,CAAC,CAAC,CAAC;IAKb;;;;;;;;;;;;;;;;;;;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;;;;;;;;;;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;CAIpD;AAED,eAAe,UAAU,CAAC"}
@@ -0,0 +1,217 @@
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 __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
14
+ Object.defineProperty(o, "default", { enumerable: true, value: v });
15
+ }) : function(o, v) {
16
+ o["default"] = v;
17
+ });
18
+ var __esDecorate = (this && this.__esDecorate) || function (ctor, descriptorIn, decorators, contextIn, initializers, extraInitializers) {
19
+ function accept(f) { if (f !== void 0 && typeof f !== "function") throw new TypeError("Function expected"); return f; }
20
+ var kind = contextIn.kind, key = kind === "getter" ? "get" : kind === "setter" ? "set" : "value";
21
+ var target = !descriptorIn && ctor ? contextIn["static"] ? ctor : ctor.prototype : null;
22
+ var descriptor = descriptorIn || (target ? Object.getOwnPropertyDescriptor(target, contextIn.name) : {});
23
+ var _, done = false;
24
+ for (var i = decorators.length - 1; i >= 0; i--) {
25
+ var context = {};
26
+ for (var p in contextIn) context[p] = p === "access" ? {} : contextIn[p];
27
+ for (var p in contextIn.access) context.access[p] = contextIn.access[p];
28
+ context.addInitializer = function (f) { if (done) throw new TypeError("Cannot add initializers after decoration has completed"); extraInitializers.push(accept(f || null)); };
29
+ var result = (0, decorators[i])(kind === "accessor" ? { get: descriptor.get, set: descriptor.set } : descriptor[key], context);
30
+ if (kind === "accessor") {
31
+ if (result === void 0) continue;
32
+ if (result === null || typeof result !== "object") throw new TypeError("Object expected");
33
+ if (_ = accept(result.get)) descriptor.get = _;
34
+ if (_ = accept(result.set)) descriptor.set = _;
35
+ if (_ = accept(result.init)) initializers.unshift(_);
36
+ }
37
+ else if (_ = accept(result)) {
38
+ if (kind === "field") initializers.unshift(_);
39
+ else descriptor[key] = _;
40
+ }
41
+ }
42
+ if (target) Object.defineProperty(target, contextIn.name, descriptor);
43
+ done = true;
44
+ };
45
+ var __runInitializers = (this && this.__runInitializers) || function (thisArg, initializers, value) {
46
+ var useValue = arguments.length > 2;
47
+ for (var i = 0; i < initializers.length; i++) {
48
+ value = useValue ? initializers[i].call(thisArg, value) : initializers[i].call(thisArg);
49
+ }
50
+ return useValue ? value : void 0;
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
+ };
59
+ Object.defineProperty(exports, "__esModule", { value: true });
60
+ const metadata_1 = __importStar(require("./metadata"));
61
+ const decorators_1 = require("./decorators");
62
+ const operations_1 = require("./operations");
63
+ /**
64
+ * Serves as an abstract base class for entities in the ORM system. It defines standard fields such as `id`, `type`, `createdAt`, and `updatedAt`, and provides static methods for CRUD operations and queries. This class encapsulates common behaviors and properties that all entities share, leveraging decorators for attribute metadata and supporting operations like finding, creating, updating, and deleting entities.
65
+ *
66
+ * Table classes should extend this class, and each entity should extend the table class
67
+ *
68
+ * Entities extending `DynaRecord` can utilize these operations to interact with their corresponding records in the database, including handling relationships between different entities.
69
+ * @example
70
+ * ```typescript
71
+ * @Table({ name: "my-table", delimiter: "#" })
72
+ * abstract class MyTable extends DynaRecord {
73
+ * @PartitionKeyAttribute()
74
+ * public readonly pk: PartitionKey;
75
+ *
76
+ * @SortKeyAttribute()
77
+ * public readonly sk: SortKey;
78
+ * }
79
+ *
80
+ * @Entity
81
+ * class User extends MyTable {
82
+ * // User implementation
83
+ * }
84
+ * ```
85
+ */
86
+ let DynaRecord = (() => {
87
+ let _instanceExtraInitializers = [];
88
+ let _id_decorators;
89
+ let _id_initializers = [];
90
+ let _type_decorators;
91
+ let _type_initializers = [];
92
+ let _createdAt_decorators;
93
+ let _createdAt_initializers = [];
94
+ let _updatedAt_decorators;
95
+ let _updatedAt_initializers = [];
96
+ return class DynaRecord {
97
+ static {
98
+ const _metadata = typeof Symbol === "function" && Symbol.metadata ? Object.create(null) : void 0;
99
+ _id_decorators = [(0, decorators_1.Attribute)({ alias: metadata_1.tableDefaultFields.id.alias })];
100
+ _type_decorators = [(0, decorators_1.Attribute)({ alias: metadata_1.tableDefaultFields.type.alias })];
101
+ _createdAt_decorators = [(0, decorators_1.DateAttribute)({ alias: metadata_1.tableDefaultFields.createdAt.alias })];
102
+ _updatedAt_decorators = [(0, decorators_1.DateAttribute)({ alias: metadata_1.tableDefaultFields.updatedAt.alias })];
103
+ __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);
104
+ __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);
105
+ __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);
106
+ __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);
107
+ if (_metadata) Object.defineProperty(this, Symbol.metadata, { enumerable: true, configurable: true, writable: true, value: _metadata });
108
+ }
109
+ /**
110
+ * A unique identifier for the entity itself, automatically generated upon creation.
111
+ */
112
+ id = (__runInitializers(this, _instanceExtraInitializers), __runInitializers(this, _id_initializers, void 0));
113
+ /**
114
+ * The type of the Entity
115
+ */
116
+ type = __runInitializers(this, _type_initializers, void 0);
117
+ /**
118
+ * The timestamp marking when the entity was created
119
+ */
120
+ createdAt = __runInitializers(this, _createdAt_initializers, void 0);
121
+ /**
122
+ * The timestamp marking the last update to the entity. Initially set to the same value as `createdAt`.
123
+ */
124
+ updatedAt = __runInitializers(this, _updatedAt_initializers, void 0);
125
+ /**
126
+ * Find an entity by Id and optionally include associations
127
+ * @param {string} id - Entity Id
128
+ * @param {Object} options - FindByIdOptions
129
+ * @returns An entity with included associations serialized
130
+ *
131
+ * @example Without included relationships
132
+ * ```typescript
133
+ * const user = await User.findById("userId");
134
+ * ```
135
+ *
136
+ * @example With included relationships
137
+ * ```typescript
138
+ * const user = await User.findById("userId", { include: [{ association: "profile" }] });
139
+ * ```
140
+ */
141
+ static async findById(id, options) {
142
+ const op = new operations_1.FindById(this);
143
+ return await op.run(id, options);
144
+ }
145
+ static async query(key, options) {
146
+ const op = new operations_1.Query(this);
147
+ return await op.run(key, options);
148
+ }
149
+ /**
150
+ * Create an entity. If foreign keys are included in the attributes then BelongsToLinks will be demoralized accordingly
151
+ * @param attributes - Attributes of the model to create
152
+ * @returns The new Entity
153
+ *
154
+ * ```typescript
155
+ * const newUser = await User.create({ name: "Alice", email: "alice@example.com", profileId: "123" });
156
+ * ```
157
+ */
158
+ static async create(attributes) {
159
+ const op = new operations_1.Create(this);
160
+ return await op.run(attributes);
161
+ }
162
+ /**
163
+ * Update an entity. If foreign keys are included in the attribute then:
164
+ * - BelongsToLinks will be created accordingly
165
+ * - If the entity already had a foreign key relationship, then those BelongsToLinks will be deleted
166
+ * - If the foreign key is not nullable then a {@link NullConstraintViolationError} is thrown. See {@link NullableForeignKeyAttribute}
167
+ * - Validation errors will be thrown if the attribute being removed is not nullable
168
+ * @param id - The id of the entity to update
169
+ * @param attributes - Attributes to update
170
+ *
171
+ *
172
+ * @example Updating an entity.
173
+ * ```typescript
174
+ * await User.update("userId", { email: "newemail@example.com", profileId: 789 });
175
+ * ```
176
+ *
177
+ * @example Removing a nullable entities attributes
178
+ * ```typescript
179
+ * await User.update("userId", { email: "newemail@example.com", someKey: null });
180
+ * ```
181
+ */
182
+ static async update(id, attributes) {
183
+ const op = new operations_1.Update(this);
184
+ await op.run(id, attributes);
185
+ }
186
+ /**
187
+ * Delete an entity by ID
188
+ * - Delete all BelongsToLinks
189
+ * - Disassociate all foreign keys of linked models
190
+ * @param id - The id of the entity to update
191
+ *
192
+ * @example Delete an entity
193
+ * ```typescript
194
+ * await User.delete("userId");
195
+ * ```
196
+ */
197
+ static async delete(id) {
198
+ const op = new operations_1.Delete(this);
199
+ await op.run(id);
200
+ }
201
+ /**
202
+ * Constructs the partition key value
203
+ * @param {string} id - Entity Id
204
+ * @returns Constructed partition key value
205
+ *
206
+ * @example
207
+ * ```typescript
208
+ * const pkValue = User.partitionKeyValue("userId");
209
+ * ```
210
+ */
211
+ static partitionKeyValue(id) {
212
+ const { delimiter } = metadata_1.default.getEntityTable(this.name);
213
+ return `${this.name}${delimiter}${id}`;
214
+ }
215
+ };
216
+ })();
217
+ exports.default = DynaRecord;
@@ -0,0 +1,42 @@
1
+ /**
2
+ * Facilitates logging throughout the ORM system with support for different log levels: log, warn, error, and info. Logging can be toggled through the `DYNA_RECORD_LOGGING_ENABLED` environment variable. When enabled, logs are output to the console, allowing for easy tracking and debugging of the system's operations.
3
+ *
4
+ * The Logger class abstracts the console's logging methods, providing a unified API for logging across different severity levels. This encapsulation allows for more flexible logging strategies and makes it easier to modify logging behavior centrally.
5
+ *
6
+ * Each logging method accepts parameters matching those of the corresponding console method, ensuring that the Logger can be used in the same way as direct console logging while adding the capability to control logging behavior through environment variables.
7
+ *
8
+ * @method log - Outputs general informational messages to the console. Intended for logging detailed information about the flow of the application.
9
+ * @method warn - Outputs warnings to the console. Used for situations that aren't errors but could potentially lead to errors or undesired behavior.
10
+ * @method error - Outputs error messages to the console. Used for logging errors and exceptions that occur during the application's execution.
11
+ * @method info - Outputs informational messages to the console, similar to `log`. Can be used to log high-level information about the application's state or operations.
12
+ */
13
+ declare class Logger {
14
+ /**
15
+ * If debug logging is enabled, it will log to console at the given log level
16
+ * @param level
17
+ * @param logParams
18
+ */
19
+ private static _log;
20
+ /**
21
+ * Logs general informational messages.
22
+ * @param messages
23
+ */
24
+ static log(...messages: Parameters<Console["log"]>): void;
25
+ /**
26
+ * Logs warning messages.
27
+ * @param messages
28
+ */
29
+ static warn(...messages: Parameters<Console["warn"]>): void;
30
+ /**
31
+ * Logs error messages.
32
+ * @param messages
33
+ */
34
+ static error(...messages: Parameters<Console["error"]>): void;
35
+ /**
36
+ * Logs info messages.
37
+ * @param messages
38
+ */
39
+ static info(...messages: Parameters<Console["info"]>): void;
40
+ }
41
+ export default Logger;
42
+ //# sourceMappingURL=Logger.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"Logger.d.ts","sourceRoot":"","sources":["../../src/Logger.ts"],"names":[],"mappings":"AAKA;;;;;;;;;;;GAWG;AACH,cAAM,MAAM;IACV;;;;OAIG;IACH,OAAO,CAAC,MAAM,CAAC,IAAI;IAMnB;;;OAGG;IACH,MAAM,CAAC,GAAG,CAAC,GAAG,QAAQ,EAAE,UAAU,CAAC,OAAO,CAAC,KAAK,CAAC,CAAC,GAAG,IAAI;IAIzD;;;OAGG;IACH,MAAM,CAAC,IAAI,CAAC,GAAG,QAAQ,EAAE,UAAU,CAAC,OAAO,CAAC,MAAM,CAAC,CAAC,GAAG,IAAI;IAI3D;;;OAGG;IACH,MAAM,CAAC,KAAK,CAAC,GAAG,QAAQ,EAAE,UAAU,CAAC,OAAO,CAAC,OAAO,CAAC,CAAC,GAAG,IAAI;IAI7D;;;OAGG;IACH,MAAM,CAAC,IAAI,CAAC,GAAG,QAAQ,EAAE,UAAU,CAAC,OAAO,CAAC,MAAM,CAAC,CAAC,GAAG,IAAI;CAG5D;AAED,eAAe,MAAM,CAAC"}
@@ -0,0 +1,57 @@
1
+ "use strict";
2
+ /* eslint-disable @typescript-eslint/no-extraneous-class */
3
+ /* eslint-disable @typescript-eslint/no-unsafe-argument */
4
+ Object.defineProperty(exports, "__esModule", { value: true });
5
+ /**
6
+ * Facilitates logging throughout the ORM system with support for different log levels: log, warn, error, and info. Logging can be toggled through the `DYNA_RECORD_LOGGING_ENABLED` environment variable. When enabled, logs are output to the console, allowing for easy tracking and debugging of the system's operations.
7
+ *
8
+ * The Logger class abstracts the console's logging methods, providing a unified API for logging across different severity levels. This encapsulation allows for more flexible logging strategies and makes it easier to modify logging behavior centrally.
9
+ *
10
+ * Each logging method accepts parameters matching those of the corresponding console method, ensuring that the Logger can be used in the same way as direct console logging while adding the capability to control logging behavior through environment variables.
11
+ *
12
+ * @method log - Outputs general informational messages to the console. Intended for logging detailed information about the flow of the application.
13
+ * @method warn - Outputs warnings to the console. Used for situations that aren't errors but could potentially lead to errors or undesired behavior.
14
+ * @method error - Outputs error messages to the console. Used for logging errors and exceptions that occur during the application's execution.
15
+ * @method info - Outputs informational messages to the console, similar to `log`. Can be used to log high-level information about the application's state or operations.
16
+ */
17
+ class Logger {
18
+ /**
19
+ * If debug logging is enabled, it will log to console at the given log level
20
+ * @param level
21
+ * @param logParams
22
+ */
23
+ static _log(level, ...logParams) {
24
+ if (process.env.DYNA_RECORD_LOGGING_ENABLED === "true") {
25
+ console[level](...logParams);
26
+ }
27
+ }
28
+ /**
29
+ * Logs general informational messages.
30
+ * @param messages
31
+ */
32
+ static log(...messages) {
33
+ this._log("log", ...messages);
34
+ }
35
+ /**
36
+ * Logs warning messages.
37
+ * @param messages
38
+ */
39
+ static warn(...messages) {
40
+ this._log("warn", ...messages);
41
+ }
42
+ /**
43
+ * Logs error messages.
44
+ * @param messages
45
+ */
46
+ static error(...messages) {
47
+ this._log("error", ...messages);
48
+ }
49
+ /**
50
+ * Logs info messages.
51
+ * @param messages
52
+ */
53
+ static info(...messages) {
54
+ this._log("info", ...messages);
55
+ }
56
+ }
57
+ exports.default = Logger;
@@ -0,0 +1,23 @@
1
+ import type DynaRecord from "../DynaRecord";
2
+ /**
3
+ * A class decorator for marking a class as an entity within the context of the ORM system. This decorator is essential for registering the class as a distinct entity in the ORM's metadata system, enabling the ORM to recognize and manage instances of this class as part of its data model. By designating classes as entities, it facilitates their integration into the ORM framework, allowing for operations such as querying, persisting, and managing relationships between entities.
4
+ *
5
+ * IMPORTANT - All entity classes should extend a table class decorated by {@link Table}
6
+ *
7
+ * @template T The class being decorated, which extends from the base `DynaRecord` entity class. This ensures that only classes that are part of the ORM system can be decorated as entities.
8
+ * @param target The constructor function of the class being decorated. This function is used to instantiate objects of the class.
9
+ * @param context The context in which the decorator is applied, provided by the TypeScript runtime. This includes metadata about the class, such as its kind and other relevant information. The decorator uses this context to perform its registration logic.
10
+ * @returns {void} The decorator does not return a value. Instead, it performs side effects by registering the class with the ORM's metadata system.
11
+ *
12
+ * Usage example:
13
+ * ```typescript
14
+ * @Entity
15
+ * class User extends MyTable {
16
+ * // User entity implementation
17
+ * }
18
+ * ```
19
+ * In this example, the `User` class is marked as an entity using the `@Entity` decorator. This designation registers the `User` class within the ORM's metadata system, making it a recognized entity for the ORM to manage. The registration process involves associating the class with its corresponding table name and any additional metadata required by the ORM to handle instances of this class effectively.
20
+ */
21
+ declare function Entity<T extends DynaRecord>(target: new () => T, context: ClassDecoratorContext): void;
22
+ export default Entity;
23
+ //# sourceMappingURL=Entity.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"Entity.d.ts","sourceRoot":"","sources":["../../../src/decorators/Entity.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,UAAU,MAAM,eAAe,CAAC;AAE5C;;;;;;;;;;;;;;;;;;GAkBG;AACH,iBAAS,MAAM,CAAC,CAAC,SAAS,UAAU,EAClC,MAAM,EAAE,UAAU,CAAC,EACnB,OAAO,EAAE,qBAAqB,GAC7B,IAAI,CAKN;AAED,eAAe,MAAM,CAAC"}
@@ -0,0 +1,32 @@
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
+ * A class decorator for marking a class as an entity within the context of the ORM system. This decorator is essential for registering the class as a distinct entity in the ORM's metadata system, enabling the ORM to recognize and manage instances of this class as part of its data model. By designating classes as entities, it facilitates their integration into the ORM framework, allowing for operations such as querying, persisting, and managing relationships between entities.
9
+ *
10
+ * IMPORTANT - All entity classes should extend a table class decorated by {@link Table}
11
+ *
12
+ * @template T The class being decorated, which extends from the base `DynaRecord` entity class. This ensures that only classes that are part of the ORM system can be decorated as entities.
13
+ * @param target The constructor function of the class being decorated. This function is used to instantiate objects of the class.
14
+ * @param context The context in which the decorator is applied, provided by the TypeScript runtime. This includes metadata about the class, such as its kind and other relevant information. The decorator uses this context to perform its registration logic.
15
+ * @returns {void} The decorator does not return a value. Instead, it performs side effects by registering the class with the ORM's metadata system.
16
+ *
17
+ * Usage example:
18
+ * ```typescript
19
+ * @Entity
20
+ * class User extends MyTable {
21
+ * // User entity implementation
22
+ * }
23
+ * ```
24
+ * In this example, the `User` class is marked as an entity using the `@Entity` decorator. This designation registers the `User` class within the ORM's metadata system, making it a recognized entity for the ORM to manage. The registration process involves associating the class with its corresponding table name and any additional metadata required by the ORM to handle instances of this class effectively.
25
+ */
26
+ function Entity(target, context) {
27
+ if (context.kind === "class") {
28
+ const tableClassName = Object.getPrototypeOf(target).name;
29
+ metadata_1.default.addEntity(target, tableClassName);
30
+ }
31
+ }
32
+ exports.default = Entity;
@@ -0,0 +1,22 @@
1
+ import { type TableMetadataOptions } from "../metadata";
2
+ import type DynaRecord from "../DynaRecord";
3
+ /**
4
+ * A class decorator for defining and customizing the table metadata associated with an entity class within the ORM system. This decorator enriches the entity with additional metadata, specifying how the entity relates to the underlying database table. By providing custom table options, such as table names or schema definitions, this decorator plays a crucial role in bridging the gap between the ORM's abstract entities and their concrete database representations.
5
+ *
6
+ * IMPORTANT - All entity classes should extend a table
7
+ *
8
+ * @param props The {@link TableMetadataOptions} object containing metadata configuration for the table. This can include options like the table's name, delimiter and default field customizations.
9
+ * @returns A class decorator factory function that takes a target class extending `DynaRecord` and a context object provided by the TypeScript runtime. The decorator function registers the provided metadata options with the ORM's metadata system, ensuring the entity is properly configured and recognized by the ORM.
10
+ *
11
+ * Usage example:
12
+ * ```typescript
13
+ * @Table({ name: 'my-table', delimiter: '"#",' })
14
+ * class MyTable extends DynaRecord {
15
+ * // User entity implementation
16
+ * }
17
+ * ```
18
+ * In this example, the `@Table` decorator is applied to the `User` class, specifying custom table metadata options, including the table name (`users`) and the schema (`public`). These options are registered with the ORM, which then uses them to correctly map the `User` entity to the corresponding table in the database. This mapping is critical for executing ORM operations such as querying, inserting, and updating records in the `users` table.
19
+ */
20
+ declare function Table(props: TableMetadataOptions): (target: typeof DynaRecord, context: ClassDecoratorContext) => void;
21
+ export default Table;
22
+ //# sourceMappingURL=Table.d.ts.map