dyna-record 0.1.3 → 0.1.5
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +5 -2
- package/dist/src/decorators/attributes/BooleanAttribute.d.ts.map +1 -1
- package/dist/src/decorators/attributes/BooleanAttribute.js +1 -2
- package/dist/src/decorators/attributes/DateAttribute.d.ts.map +1 -1
- package/dist/src/decorators/attributes/DateAttribute.js +1 -2
- package/dist/src/decorators/attributes/EnumAttribute.d.ts +32 -0
- package/dist/src/decorators/attributes/EnumAttribute.d.ts.map +1 -0
- package/dist/src/decorators/attributes/EnumAttribute.js +43 -0
- package/dist/src/decorators/attributes/ForeignKeyAttribute.d.ts +1 -1
- package/dist/src/decorators/attributes/ForeignKeyAttribute.d.ts.map +1 -1
- package/dist/src/decorators/attributes/ForeignKeyAttribute.js +2 -3
- package/dist/src/decorators/attributes/IdAttribute.d.ts +32 -0
- package/dist/src/decorators/attributes/IdAttribute.d.ts.map +1 -0
- package/dist/src/decorators/attributes/IdAttribute.js +41 -0
- package/dist/src/decorators/attributes/NumberAttribute.d.ts.map +1 -1
- package/dist/src/decorators/attributes/NumberAttribute.js +1 -2
- package/dist/src/decorators/attributes/PartitionKeyAttribute.d.ts +1 -1
- package/dist/src/decorators/attributes/PartitionKeyAttribute.d.ts.map +1 -1
- package/dist/src/decorators/attributes/PartitionKeyAttribute.js +2 -3
- package/dist/src/decorators/attributes/SortKeyAttribute.d.ts +1 -1
- package/dist/src/decorators/attributes/SortKeyAttribute.d.ts.map +1 -1
- package/dist/src/decorators/attributes/SortKeyAttribute.js +2 -3
- package/dist/src/decorators/attributes/StringAttribute.d.ts +1 -1
- package/dist/src/decorators/attributes/StringAttribute.d.ts.map +1 -1
- package/dist/src/decorators/attributes/StringAttribute.js +2 -3
- package/dist/src/decorators/attributes/index.d.ts +2 -0
- package/dist/src/decorators/attributes/index.d.ts.map +1 -1
- package/dist/src/decorators/attributes/index.js +5 -1
- package/dist/src/decorators/relationships/BelongsTo.d.ts +1 -1
- package/dist/src/decorators/relationships/BelongsTo.d.ts.map +1 -1
- package/dist/src/decorators/relationships/BelongsTo.js +2 -3
- package/dist/src/decorators/relationships/HasAndBelongsToMany.d.ts +2 -2
- package/dist/src/decorators/relationships/HasAndBelongsToMany.d.ts.map +1 -1
- package/dist/src/decorators/relationships/HasAndBelongsToMany.js +3 -4
- package/dist/src/decorators/relationships/HasMany.d.ts +2 -2
- package/dist/src/decorators/relationships/HasMany.d.ts.map +1 -1
- package/dist/src/decorators/relationships/HasMany.js +3 -4
- package/dist/src/decorators/relationships/HasOne.d.ts +2 -2
- package/dist/src/decorators/relationships/HasOne.d.ts.map +1 -1
- package/dist/src/decorators/relationships/HasOne.js +3 -4
- package/dist/src/metadata/EntityMetadata.d.ts +4 -0
- package/dist/src/metadata/EntityMetadata.d.ts.map +1 -1
- package/dist/src/metadata/EntityMetadata.js +4 -0
- package/dist/src/metadata/MetadataStorage.d.ts +6 -0
- package/dist/src/metadata/MetadataStorage.d.ts.map +1 -1
- package/dist/src/metadata/MetadataStorage.js +9 -0
- package/dist/src/metadata/TableMetadata.d.ts.map +1 -1
- package/dist/src/metadata/TableMetadata.js +1 -3
- package/dist/src/operations/Create/Create.d.ts.map +1 -1
- package/dist/src/operations/Create/Create.js +12 -9
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -113,7 +113,7 @@ By default, each entity will have [default attributes](https://dyna-record.com/t
|
|
|
113
113
|
|
|
114
114
|
- The partition key defined on the [table](#table) class
|
|
115
115
|
- The sort key defined on the [table](#table) class
|
|
116
|
-
- [id](https://dyna-record.com/classes/default.html#id) - The
|
|
116
|
+
- [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
117
|
- [type](https://dyna-record.com/classes/default.html#type) - The type of the entity. Value is the entity class name
|
|
118
118
|
- [createdAt](https://dyna-record.com/classes/default.html#updatedAt) - The timestamp of when the entity was created
|
|
119
119
|
- [updatedAt](https://dyna-record.com/classes/default.html#updatedAt) - Timestamp of when the entity was updated last
|
|
@@ -142,6 +142,8 @@ Use the attribute decorators below to define attributes on a model. The decorato
|
|
|
142
142
|
- [@NumberAttribute](https://dyna-record.com/functions/NumberAttribute.html)
|
|
143
143
|
- [@BooleanAttribute](https://dyna-record.com/functions/BooleanAttribute.html)
|
|
144
144
|
- [@DateAttribute](https://dyna-record.com/functions/DateAttribute.html)
|
|
145
|
+
- [@EnumAttribute](https://dyna-record.com/functions/EnumAttribute.html)
|
|
146
|
+
- [@IdAttribute](https://dyna-record.com/functions/IdAttribute.html)
|
|
145
147
|
|
|
146
148
|
- 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.
|
|
147
149
|
- Set nullable attributes as optional for optimal type safety
|
|
@@ -308,7 +310,7 @@ class Student extends OtherTable {
|
|
|
308
310
|
|
|
309
311
|
[Docs](https://dyna-record.com/classes/default.html#create)
|
|
310
312
|
|
|
311
|
-
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
|
|
313
|
+
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
|
|
312
314
|
|
|
313
315
|
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.
|
|
314
316
|
|
|
@@ -340,6 +342,7 @@ The method is designed to throw errors under various conditions, such as transac
|
|
|
340
342
|
|
|
341
343
|
- 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.
|
|
342
344
|
- Automatic ID Generation: Each entity created gets a unique [id](https://dyna-record.com/classes/default.html#id) generated by the uuidv4 method.
|
|
345
|
+
- This can be customized [IdAttribute](<(https://dyna-record.com/functions/IdAttribute.html)>) to support custom id attributes
|
|
343
346
|
- Relationship Management: The ORM manages entity relationships through DynamoDB's single-table design patterns, creating and maintaining the necessary links between related entities.
|
|
344
347
|
- 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.
|
|
345
348
|
- 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.
|
|
@@ -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,
|
|
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,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
|
-
|
|
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,
|
|
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,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
|
-
|
|
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,
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
import type DynaRecord from "../../DynaRecord";
|
|
2
|
+
import type { AttributeDecoratorContext, AttributeOptions } from "../types";
|
|
3
|
+
/**
|
|
4
|
+
* Extends {@link AttributeOptions} but requires that the allowed values are set on `values`
|
|
5
|
+
*/
|
|
6
|
+
export interface EnumAttributeOptions extends AttributeOptions {
|
|
7
|
+
values: [string, ...string[]];
|
|
8
|
+
}
|
|
9
|
+
/**
|
|
10
|
+
* A decorator for marking class fields as enum attributes within the context of a single-table design entity. Only the types specified in `values` are allowed via both the type system and runtime schema checks.
|
|
11
|
+
*
|
|
12
|
+
* This enforces a union type of the specified fields listed in `values`
|
|
13
|
+
*
|
|
14
|
+
* @template T The entity the decorator is applied to.
|
|
15
|
+
* @template K The type of the attribute, restricted to the values listed in `values` prop of EnumAttributeOptions
|
|
16
|
+
* @param props An optional object of {@link EnumAttributeOptions}, including the allowed values, configuration options such as metadata attributes and additional property characteristics.
|
|
17
|
+
* @returns A class field decorator function that targets and initializes the class's prototype to register the attribute with the ORM's metadata system, ensuring proper handling and validation of the entity's enum values.
|
|
18
|
+
*
|
|
19
|
+
* Usage example:
|
|
20
|
+
* ```typescript
|
|
21
|
+
* class Product extends TableClass {
|
|
22
|
+
* @EnumAttribute({ alias: 'SomeField', values: ["val-1", "val-2"] })
|
|
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
|
+
*
|
|
25
|
+
* @EnumAttribute({ alias: 'MyNullableField', nullable: true, values: ["val-1", "val-2"] })
|
|
26
|
+
* public myNullableField?: "val-1" | "val-2"; // Set to Optional for nullable attributes
|
|
27
|
+
* }
|
|
28
|
+
* ```
|
|
29
|
+
*/
|
|
30
|
+
declare function EnumAttribute<T extends DynaRecord, const K extends P["values"][number], const P extends EnumAttributeOptions>(props: P): (_value: undefined, context: AttributeDecoratorContext<T, K, P>) => void;
|
|
31
|
+
export default EnumAttribute;
|
|
32
|
+
//# sourceMappingURL=EnumAttribute.d.ts.map
|
|
@@ -0,0 +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,UAa9C;AAED,eAAe,aAAa,CAAC"}
|
|
@@ -0,0 +1,43 @@
|
|
|
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 zod_1 = require("zod");
|
|
7
|
+
const metadata_1 = __importDefault(require("../../metadata"));
|
|
8
|
+
/**
|
|
9
|
+
* A decorator for marking class fields as enum attributes within the context of a single-table design entity. Only the types specified in `values` are allowed via both the type system and runtime schema checks.
|
|
10
|
+
*
|
|
11
|
+
* This enforces a union type of the specified fields listed in `values`
|
|
12
|
+
*
|
|
13
|
+
* @template T The entity the decorator is applied to.
|
|
14
|
+
* @template K The type of the attribute, restricted to the values listed in `values` prop of EnumAttributeOptions
|
|
15
|
+
* @param props An optional object of {@link EnumAttributeOptions}, including the allowed values, configuration options such as metadata attributes and additional property characteristics.
|
|
16
|
+
* @returns A class field decorator function that targets and initializes the class's prototype to register the attribute with the ORM's metadata system, ensuring proper handling and validation of the entity's enum values.
|
|
17
|
+
*
|
|
18
|
+
* Usage example:
|
|
19
|
+
* ```typescript
|
|
20
|
+
* class Product extends TableClass {
|
|
21
|
+
* @EnumAttribute({ alias: 'SomeField', values: ["val-1", "val-2"] })
|
|
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
|
+
*
|
|
24
|
+
* @EnumAttribute({ alias: 'MyNullableField', nullable: true, values: ["val-1", "val-2"] })
|
|
25
|
+
* public myNullableField?: "val-1" | "val-2"; // Set to Optional for nullable attributes
|
|
26
|
+
* }
|
|
27
|
+
* ```
|
|
28
|
+
*/
|
|
29
|
+
function EnumAttribute(props) {
|
|
30
|
+
return function (_value, context) {
|
|
31
|
+
if (context.kind === "field") {
|
|
32
|
+
context.addInitializer(function () {
|
|
33
|
+
metadata_1.default.addEntityAttribute(this.constructor.name, {
|
|
34
|
+
attributeName: context.name.toString(),
|
|
35
|
+
nullable: props?.nullable,
|
|
36
|
+
type: zod_1.z.enum(props.values),
|
|
37
|
+
...props
|
|
38
|
+
});
|
|
39
|
+
});
|
|
40
|
+
}
|
|
41
|
+
};
|
|
42
|
+
}
|
|
43
|
+
exports.default = EnumAttribute;
|
|
@@ -14,7 +14,7 @@ import type { AttributeDecoratorContext, AttributeOptions } from "../types";
|
|
|
14
14
|
*
|
|
15
15
|
* Usage example:
|
|
16
16
|
* ```typescript
|
|
17
|
-
* class Order extends
|
|
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,
|
|
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,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
|
|
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
|
-
|
|
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,
|
|
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,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
|
-
|
|
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(),
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"PartitionKeyAttribute.d.ts","sourceRoot":"","sources":["../../../../src/decorators/attributes/PartitionKeyAttribute.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,UAAU,MAAM,kBAAkB,CAAC;AAE/C,OAAO,EAAE,KAAK,YAAY,EAAE,MAAM,aAAa,CAAC;AAChD,OAAO,KAAK,EAAE,uBAAuB,EAAE,MAAM,UAAU,CAAC;AAExD;;;;;;;;;;;;;;;;;GAiBG;AACH,iBAAS,qBAAqB,CAAC,CAAC,SAAS,UAAU,EAAE,CAAC,SAAS,YAAY,EACzE,KAAK,CAAC,EAAE,uBAAuB,YAGrB,SAAS,WACR,2BAA2B,CAAC,EAAE,CAAC,CAAC,
|
|
1
|
+
{"version":3,"file":"PartitionKeyAttribute.d.ts","sourceRoot":"","sources":["../../../../src/decorators/attributes/PartitionKeyAttribute.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,UAAU,MAAM,kBAAkB,CAAC;AAE/C,OAAO,EAAE,KAAK,YAAY,EAAE,MAAM,aAAa,CAAC;AAChD,OAAO,KAAK,EAAE,uBAAuB,EAAE,MAAM,UAAU,CAAC;AAExD;;;;;;;;;;;;;;;;;GAiBG;AACH,iBAAS,qBAAqB,CAAC,CAAC,SAAS,UAAU,EAAE,CAAC,SAAS,YAAY,EACzE,KAAK,CAAC,EAAE,uBAAuB,YAGrB,SAAS,WACR,2BAA2B,CAAC,EAAE,CAAC,CAAC,UAY5C;AAED,eAAe,qBAAqB,CAAC"}
|
|
@@ -15,7 +15,7 @@ const metadata_1 = __importDefault(require("../../metadata"));
|
|
|
15
15
|
*
|
|
16
16
|
* Usage example:
|
|
17
17
|
* ```typescript
|
|
18
|
-
* class User extends
|
|
18
|
+
* class User extends TableClass {
|
|
19
19
|
* @PartitionKeyAttribute()
|
|
20
20
|
* public pk: PartitionKey;
|
|
21
21
|
* }
|
|
@@ -27,8 +27,7 @@ function PartitionKeyAttribute(props) {
|
|
|
27
27
|
return function (_value, context) {
|
|
28
28
|
if (context.kind === "field") {
|
|
29
29
|
context.addInitializer(function () {
|
|
30
|
-
|
|
31
|
-
metadata_1.default.addPartitionKeyAttribute(entity, {
|
|
30
|
+
metadata_1.default.addPartitionKeyAttribute(this, {
|
|
32
31
|
attributeName: context.name.toString(),
|
|
33
32
|
type: zod_1.z.string(),
|
|
34
33
|
...props
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"SortKeyAttribute.d.ts","sourceRoot":"","sources":["../../../../src/decorators/attributes/SortKeyAttribute.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,UAAU,MAAM,kBAAkB,CAAC;AAE/C,OAAO,EAAE,KAAK,OAAO,EAAE,MAAM,aAAa,CAAC;AAC3C,OAAO,KAAK,EAAE,uBAAuB,EAAE,MAAM,UAAU,CAAC;AAExD;;;;;;;;;;;;;;;;;GAiBG;AACH,iBAAS,gBAAgB,CAAC,CAAC,SAAS,UAAU,EAAE,CAAC,SAAS,OAAO,EAC/D,KAAK,CAAC,EAAE,uBAAuB,YAGrB,SAAS,WACR,2BAA2B,CAAC,EAAE,CAAC,CAAC,
|
|
1
|
+
{"version":3,"file":"SortKeyAttribute.d.ts","sourceRoot":"","sources":["../../../../src/decorators/attributes/SortKeyAttribute.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,UAAU,MAAM,kBAAkB,CAAC;AAE/C,OAAO,EAAE,KAAK,OAAO,EAAE,MAAM,aAAa,CAAC;AAC3C,OAAO,KAAK,EAAE,uBAAuB,EAAE,MAAM,UAAU,CAAC;AAExD;;;;;;;;;;;;;;;;;GAiBG;AACH,iBAAS,gBAAgB,CAAC,CAAC,SAAS,UAAU,EAAE,CAAC,SAAS,OAAO,EAC/D,KAAK,CAAC,EAAE,uBAAuB,YAGrB,SAAS,WACR,2BAA2B,CAAC,EAAE,CAAC,CAAC,UAY5C;AAED,eAAe,gBAAgB,CAAC"}
|
|
@@ -15,7 +15,7 @@ const metadata_1 = __importDefault(require("../../metadata"));
|
|
|
15
15
|
*
|
|
16
16
|
* Usage example:
|
|
17
17
|
* ```typescript
|
|
18
|
-
* class User extends
|
|
18
|
+
* class User extends TableClass {
|
|
19
19
|
* @SortKeyAttribute()
|
|
20
20
|
* public sk: SortKey;
|
|
21
21
|
* }
|
|
@@ -27,8 +27,7 @@ function SortKeyAttribute(props) {
|
|
|
27
27
|
return function (_value, context) {
|
|
28
28
|
if (context.kind === "field") {
|
|
29
29
|
context.addInitializer(function () {
|
|
30
|
-
|
|
31
|
-
metadata_1.default.addSortKeyAttribute(entity, {
|
|
30
|
+
metadata_1.default.addSortKeyAttribute(this, {
|
|
32
31
|
attributeName: context.name.toString(),
|
|
33
32
|
type: zod_1.z.string(),
|
|
34
33
|
...props
|
|
@@ -12,7 +12,7 @@ import type { AttributeDecoratorContext, AttributeOptions, NotForeignKey } from
|
|
|
12
12
|
*
|
|
13
13
|
* Usage example:
|
|
14
14
|
* ```typescript
|
|
15
|
-
* class Product extends
|
|
15
|
+
* class Product extends TableClass {
|
|
16
16
|
* @StringAttribute({ alias: 'SKU' })
|
|
17
17
|
* public stockKeepingUnit: string; // Simple string attribute representing the product's SKU
|
|
18
18
|
*
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"StringAttribute.d.ts","sourceRoot":"","sources":["../../../../src/decorators/attributes/StringAttribute.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,UAAU,MAAM,kBAAkB,CAAC;AAE/C,OAAO,KAAK,EACV,yBAAyB,EACzB,gBAAgB,EAChB,aAAa,EACd,MAAM,UAAU,CAAC;AAElB;;;;;;;;;;;;;;;;;;;;;;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,CAAC,CAAC,EAAE,CAAC,CAAC,
|
|
1
|
+
{"version":3,"file":"StringAttribute.d.ts","sourceRoot":"","sources":["../../../../src/decorators/attributes/StringAttribute.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,UAAU,MAAM,kBAAkB,CAAC;AAE/C,OAAO,KAAK,EACV,yBAAyB,EACzB,gBAAgB,EAChB,aAAa,EACd,MAAM,UAAU,CAAC;AAElB;;;;;;;;;;;;;;;;;;;;;;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,CAAC,CAAC,EAAE,CAAC,CAAC,UAa7D;AAED,eAAe,eAAe,CAAC"}
|
|
@@ -17,7 +17,7 @@ const metadata_1 = __importDefault(require("../../metadata"));
|
|
|
17
17
|
*
|
|
18
18
|
* Usage example:
|
|
19
19
|
* ```typescript
|
|
20
|
-
* class Product extends
|
|
20
|
+
* class Product extends TableClass {
|
|
21
21
|
* @StringAttribute({ alias: 'SKU' })
|
|
22
22
|
* public stockKeepingUnit: string; // Simple string attribute representing the product's SKU
|
|
23
23
|
*
|
|
@@ -32,8 +32,7 @@ function StringAttribute(props) {
|
|
|
32
32
|
return function (_value, context) {
|
|
33
33
|
if (context.kind === "field") {
|
|
34
34
|
context.addInitializer(function () {
|
|
35
|
-
|
|
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.string(),
|
|
@@ -5,5 +5,7 @@ export { default as DateAttribute } from "./DateAttribute";
|
|
|
5
5
|
export { default as StringAttribute } from "./StringAttribute";
|
|
6
6
|
export { default as BooleanAttribute } from "./BooleanAttribute";
|
|
7
7
|
export { default as NumberAttribute } from "./NumberAttribute";
|
|
8
|
+
export { default as EnumAttribute } from "./EnumAttribute";
|
|
9
|
+
export { default as IdAttribute } from "./IdAttribute";
|
|
8
10
|
export * from "./serializers";
|
|
9
11
|
//# sourceMappingURL=index.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../src/decorators/attributes/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,IAAI,qBAAqB,EAAE,MAAM,yBAAyB,CAAC;AAC3E,OAAO,EAAE,OAAO,IAAI,gBAAgB,EAAE,MAAM,oBAAoB,CAAC;AACjE,OAAO,EAAE,OAAO,IAAI,mBAAmB,EAAE,MAAM,uBAAuB,CAAC;AACvE,OAAO,EAAE,OAAO,IAAI,aAAa,EAAE,MAAM,iBAAiB,CAAC;AAC3D,OAAO,EAAE,OAAO,IAAI,eAAe,EAAE,MAAM,mBAAmB,CAAC;AAC/D,OAAO,EAAE,OAAO,IAAI,gBAAgB,EAAE,MAAM,oBAAoB,CAAC;AACjE,OAAO,EAAE,OAAO,IAAI,eAAe,EAAE,MAAM,mBAAmB,CAAC;AAC/D,cAAc,eAAe,CAAC"}
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../src/decorators/attributes/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,IAAI,qBAAqB,EAAE,MAAM,yBAAyB,CAAC;AAC3E,OAAO,EAAE,OAAO,IAAI,gBAAgB,EAAE,MAAM,oBAAoB,CAAC;AACjE,OAAO,EAAE,OAAO,IAAI,mBAAmB,EAAE,MAAM,uBAAuB,CAAC;AACvE,OAAO,EAAE,OAAO,IAAI,aAAa,EAAE,MAAM,iBAAiB,CAAC;AAC3D,OAAO,EAAE,OAAO,IAAI,eAAe,EAAE,MAAM,mBAAmB,CAAC;AAC/D,OAAO,EAAE,OAAO,IAAI,gBAAgB,EAAE,MAAM,oBAAoB,CAAC;AACjE,OAAO,EAAE,OAAO,IAAI,eAAe,EAAE,MAAM,mBAAmB,CAAC;AAC/D,OAAO,EAAE,OAAO,IAAI,aAAa,EAAE,MAAM,iBAAiB,CAAC;AAC3D,OAAO,EAAE,OAAO,IAAI,WAAW,EAAE,MAAM,eAAe,CAAC;AACvD,cAAc,eAAe,CAAC"}
|
|
@@ -17,7 +17,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
17
17
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
18
18
|
};
|
|
19
19
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
20
|
-
exports.NumberAttribute = exports.BooleanAttribute = exports.StringAttribute = exports.DateAttribute = exports.ForeignKeyAttribute = exports.SortKeyAttribute = exports.PartitionKeyAttribute = void 0;
|
|
20
|
+
exports.IdAttribute = exports.EnumAttribute = exports.NumberAttribute = exports.BooleanAttribute = exports.StringAttribute = exports.DateAttribute = exports.ForeignKeyAttribute = exports.SortKeyAttribute = exports.PartitionKeyAttribute = void 0;
|
|
21
21
|
var PartitionKeyAttribute_1 = require("./PartitionKeyAttribute");
|
|
22
22
|
Object.defineProperty(exports, "PartitionKeyAttribute", { enumerable: true, get: function () { return __importDefault(PartitionKeyAttribute_1).default; } });
|
|
23
23
|
var SortKeyAttribute_1 = require("./SortKeyAttribute");
|
|
@@ -32,4 +32,8 @@ var BooleanAttribute_1 = require("./BooleanAttribute");
|
|
|
32
32
|
Object.defineProperty(exports, "BooleanAttribute", { enumerable: true, get: function () { return __importDefault(BooleanAttribute_1).default; } });
|
|
33
33
|
var NumberAttribute_1 = require("./NumberAttribute");
|
|
34
34
|
Object.defineProperty(exports, "NumberAttribute", { enumerable: true, get: function () { return __importDefault(NumberAttribute_1).default; } });
|
|
35
|
+
var EnumAttribute_1 = require("./EnumAttribute");
|
|
36
|
+
Object.defineProperty(exports, "EnumAttribute", { enumerable: true, get: function () { return __importDefault(EnumAttribute_1).default; } });
|
|
37
|
+
var IdAttribute_1 = require("./IdAttribute");
|
|
38
|
+
Object.defineProperty(exports, "IdAttribute", { enumerable: true, get: function () { return __importDefault(IdAttribute_1).default; } });
|
|
35
39
|
__exportStar(require("./serializers"), exports);
|
|
@@ -19,7 +19,7 @@ import type { BelongsToField, BelongsToProps } from "./types";
|
|
|
19
19
|
*
|
|
20
20
|
* Usage example:
|
|
21
21
|
* ```typescript
|
|
22
|
-
* class Order extends
|
|
22
|
+
* class Order extends TableClass {
|
|
23
23
|
* @ForeignKeyProperty({ alias: "UserId" })
|
|
24
24
|
* public readonly userId: ForeignKey;
|
|
25
25
|
*
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"BelongsTo.d.ts","sourceRoot":"","sources":["../../../../src/decorators/relationships/BelongsTo.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,UAAU,MAAM,kBAAkB,CAAC;AAC/C,OAAO,KAAK,EAAE,WAAW,EAAsB,MAAM,aAAa,CAAC;AACnE,OAAO,KAAK,EAAE,cAAc,EAAE,cAAc,EAAE,MAAM,SAAS,CAAC;AAE9D;;;;;;;;;;;;;;;;;;;;;;;;;;;GA2BG;AACH,iBAAS,SAAS,CAAC,CAAC,SAAS,UAAU,EAAE,CAAC,SAAS,UAAU,EAC3D,SAAS,EAAE,MAAM,WAAW,CAAC,CAAC,CAAC,EAC/B,KAAK,EAAE,cAAc,CAAC,CAAC,CAAC,YAGd,SAAS,WACR,2BACP,CAAC,EACD,eAAe,CAAC,EAAE,CAAC,EAAE,OAAO,MAAM,UAAU,CAAC,CAC9C,
|
|
1
|
+
{"version":3,"file":"BelongsTo.d.ts","sourceRoot":"","sources":["../../../../src/decorators/relationships/BelongsTo.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,UAAU,MAAM,kBAAkB,CAAC;AAC/C,OAAO,KAAK,EAAE,WAAW,EAAsB,MAAM,aAAa,CAAC;AACnE,OAAO,KAAK,EAAE,cAAc,EAAE,cAAc,EAAE,MAAM,SAAS,CAAC;AAE9D;;;;;;;;;;;;;;;;;;;;;;;;;;;GA2BG;AACH,iBAAS,SAAS,CAAC,CAAC,SAAS,UAAU,EAAE,CAAC,SAAS,UAAU,EAC3D,SAAS,EAAE,MAAM,WAAW,CAAC,CAAC,CAAC,EAC/B,KAAK,EAAE,cAAc,CAAC,CAAC,CAAC,YAGd,SAAS,WACR,2BACP,CAAC,EACD,eAAe,CAAC,EAAE,CAAC,EAAE,OAAO,MAAM,UAAU,CAAC,CAC9C,UAaJ;AAED,eAAe,SAAS,CAAC"}
|
|
@@ -22,7 +22,7 @@ const metadata_1 = __importDefault(require("../../metadata"));
|
|
|
22
22
|
*
|
|
23
23
|
* Usage example:
|
|
24
24
|
* ```typescript
|
|
25
|
-
* class Order extends
|
|
25
|
+
* class Order extends TableClass {
|
|
26
26
|
* @ForeignKeyProperty({ alias: "UserId" })
|
|
27
27
|
* public readonly userId: ForeignKey;
|
|
28
28
|
*
|
|
@@ -36,8 +36,7 @@ function BelongsTo(getTarget, props) {
|
|
|
36
36
|
return function (_value, context) {
|
|
37
37
|
if (context.kind === "field") {
|
|
38
38
|
context.addInitializer(function () {
|
|
39
|
-
|
|
40
|
-
metadata_1.default.addEntityRelationship(entity.constructor.name, {
|
|
39
|
+
metadata_1.default.addEntityRelationship(this.constructor.name, {
|
|
41
40
|
type: "BelongsTo",
|
|
42
41
|
propertyName: context.name,
|
|
43
42
|
target: getTarget(),
|
|
@@ -46,7 +46,7 @@ interface HasAndBelongsToManyProps<T extends DynaRecord, K extends DynaRecord, J
|
|
|
46
46
|
*
|
|
47
47
|
* Usage example:
|
|
48
48
|
* ```typescript
|
|
49
|
-
* class User extends
|
|
49
|
+
* class User extends TableClass {
|
|
50
50
|
* @HasAndBelongsToMany(() => Group, {
|
|
51
51
|
* targetKey: 'users',
|
|
52
52
|
* through: () => ({
|
|
@@ -57,7 +57,7 @@ interface HasAndBelongsToManyProps<T extends DynaRecord, K extends DynaRecord, J
|
|
|
57
57
|
* public groups: Group[];
|
|
58
58
|
* }
|
|
59
59
|
*
|
|
60
|
-
* class Group extends
|
|
60
|
+
* class Group extends TableClass {
|
|
61
61
|
* @HasAndBelongsToMany(() => User, {
|
|
62
62
|
* targetKey: 'groups',
|
|
63
63
|
* through: () => ({
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"HasAndBelongsToMany.d.ts","sourceRoot":"","sources":["../../../../src/decorators/relationships/HasAndBelongsToMany.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,KAAK,SAAS,EAAE,MAAM,qBAAqB,CAAC;AACrD,OAAO,KAAK,UAAU,MAAM,kBAAkB,CAAC;AAC/C,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,aAAa,CAAC;AAE/C;;GAEG;AACH,KAAK,SAAS,CAAC,CAAC,EAAE,CAAC,IAAI;KACpB,CAAC,IAAI,MAAM,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AAC,CAAC,CAAC,EAC/B,KAAK,EAAE,wBAAwB,CAAC,CAAC,EAAE,CAAC,EAAE,CAAC,EAAE,CAAC,CAAC,YAE3B,SAAS,WAAW,2BAA2B,CAAC,EAAE,CAAC,EAAE,CAAC,UAoBvE;AAED,eAAe,mBAAmB,CAAC"}
|
|
@@ -17,7 +17,7 @@ const metadata_1 = __importDefault(require("../../metadata"));
|
|
|
17
17
|
*
|
|
18
18
|
* Usage example:
|
|
19
19
|
* ```typescript
|
|
20
|
-
* class User extends
|
|
20
|
+
* class User extends TableClass {
|
|
21
21
|
* @HasAndBelongsToMany(() => Group, {
|
|
22
22
|
* targetKey: 'users',
|
|
23
23
|
* through: () => ({
|
|
@@ -28,7 +28,7 @@ const metadata_1 = __importDefault(require("../../metadata"));
|
|
|
28
28
|
* public groups: Group[];
|
|
29
29
|
* }
|
|
30
30
|
*
|
|
31
|
-
* class Group extends
|
|
31
|
+
* class Group extends TableClass {
|
|
32
32
|
* @HasAndBelongsToMany(() => User, {
|
|
33
33
|
* targetKey: 'groups',
|
|
34
34
|
* through: () => ({
|
|
@@ -50,10 +50,9 @@ function HasAndBelongsToMany(getTarget, props) {
|
|
|
50
50
|
return (_value, context) => {
|
|
51
51
|
if (context.kind === "field") {
|
|
52
52
|
context.addInitializer(function () {
|
|
53
|
-
const entity = Object.getPrototypeOf(this);
|
|
54
53
|
const target = getTarget();
|
|
55
54
|
const { joinTable, foreignKey } = props.through();
|
|
56
|
-
metadata_1.default.addEntityRelationship(
|
|
55
|
+
metadata_1.default.addEntityRelationship(this.constructor.name, {
|
|
57
56
|
type: "HasAndBelongsToMany",
|
|
58
57
|
propertyName: context.name,
|
|
59
58
|
target,
|
|
@@ -15,12 +15,12 @@ interface HasManyProps<T extends DynaRecord> {
|
|
|
15
15
|
*
|
|
16
16
|
* Usage example:
|
|
17
17
|
* ```typescript
|
|
18
|
-
* class User extends
|
|
18
|
+
* class User extends TableClass {
|
|
19
19
|
* @HasMany(() => Post, { foreignKey: 'userId' })
|
|
20
20
|
* public posts: Post[];
|
|
21
21
|
* }
|
|
22
22
|
*
|
|
23
|
-
* class Post extends
|
|
23
|
+
* class Post extends TableClass {
|
|
24
24
|
* @ForeignKeyProperty()
|
|
25
25
|
* public readonly userId: ForeignKey;
|
|
26
26
|
*
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"HasMany.d.ts","sourceRoot":"","sources":["../../../../src/decorators/relationships/HasMany.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,UAAU,MAAM,kBAAkB,CAAC;AAC/C,OAAO,KAAK,EAAE,WAAW,EAAsB,MAAM,aAAa,CAAC;AACnE,OAAO,EAAE,KAAK,sBAAsB,EAAE,MAAM,UAAU,CAAC;AAEvD,UAAU,YAAY,CAAC,CAAC,SAAS,UAAU;IACzC,UAAU,EAAE,sBAAsB,CAAC,CAAC,CAAC,CAAC;CACvC;AAED;;;;;;;;;;;;;;;;;;;;;;;;;GAyBG;AACH,iBAAS,OAAO,CAAC,CAAC,SAAS,UAAU,EAAE,CAAC,SAAS,UAAU,EACzD,SAAS,EAAE,MAAM,WAAW,CAAC,CAAC,CAAC,EAC/B,KAAK,EAAE,YAAY,CAAC,CAAC,CAAC,YAEN,SAAS,WAAW,2BAA2B,CAAC,EAAE,CAAC,EAAE,CAAC,
|
|
1
|
+
{"version":3,"file":"HasMany.d.ts","sourceRoot":"","sources":["../../../../src/decorators/relationships/HasMany.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,UAAU,MAAM,kBAAkB,CAAC;AAC/C,OAAO,KAAK,EAAE,WAAW,EAAsB,MAAM,aAAa,CAAC;AACnE,OAAO,EAAE,KAAK,sBAAsB,EAAE,MAAM,UAAU,CAAC;AAEvD,UAAU,YAAY,CAAC,CAAC,SAAS,UAAU;IACzC,UAAU,EAAE,sBAAsB,CAAC,CAAC,CAAC,CAAC;CACvC;AAED;;;;;;;;;;;;;;;;;;;;;;;;;GAyBG;AACH,iBAAS,OAAO,CAAC,CAAC,SAAS,UAAU,EAAE,CAAC,SAAS,UAAU,EACzD,SAAS,EAAE,MAAM,WAAW,CAAC,CAAC,CAAC,EAC/B,KAAK,EAAE,YAAY,CAAC,CAAC,CAAC,YAEN,SAAS,WAAW,2BAA2B,CAAC,EAAE,CAAC,EAAE,CAAC,UAYvE;AAED,eAAe,OAAO,CAAC"}
|
|
@@ -15,12 +15,12 @@ const metadata_1 = __importDefault(require("../../metadata"));
|
|
|
15
15
|
*
|
|
16
16
|
* Usage example:
|
|
17
17
|
* ```typescript
|
|
18
|
-
* class User extends
|
|
18
|
+
* class User extends TableClass {
|
|
19
19
|
* @HasMany(() => Post, { foreignKey: 'userId' })
|
|
20
20
|
* public posts: Post[];
|
|
21
21
|
* }
|
|
22
22
|
*
|
|
23
|
-
* class Post extends
|
|
23
|
+
* class Post extends TableClass {
|
|
24
24
|
* @ForeignKeyProperty()
|
|
25
25
|
* public readonly userId: ForeignKey;
|
|
26
26
|
*
|
|
@@ -34,8 +34,7 @@ function HasMany(getTarget, props) {
|
|
|
34
34
|
return (_value, context) => {
|
|
35
35
|
if (context.kind === "field") {
|
|
36
36
|
context.addInitializer(function () {
|
|
37
|
-
|
|
38
|
-
metadata_1.default.addEntityRelationship(entity.constructor.name, {
|
|
37
|
+
metadata_1.default.addEntityRelationship(this.constructor.name, {
|
|
39
38
|
type: "HasMany",
|
|
40
39
|
propertyName: context.name,
|
|
41
40
|
target: getTarget(),
|
|
@@ -15,12 +15,12 @@ interface HasOneProps<T extends DynaRecord> {
|
|
|
15
15
|
*
|
|
16
16
|
* Usage example:
|
|
17
17
|
* ```typescript
|
|
18
|
-
* class User extends
|
|
18
|
+
* class User extends TableClass {
|
|
19
19
|
* @HasOne(() => Profile, { foreignKey: 'userId' })
|
|
20
20
|
* public profile?: Profile;
|
|
21
21
|
* }
|
|
22
22
|
*
|
|
23
|
-
* class Profile extends
|
|
23
|
+
* class Profile extends TableClass {
|
|
24
24
|
* @ForeignKeyProperty()
|
|
25
25
|
* public readonly userId: ForeignKey;
|
|
26
26
|
*
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"HasOne.d.ts","sourceRoot":"","sources":["../../../../src/decorators/relationships/HasOne.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,UAAU,MAAM,kBAAkB,CAAC;AAC/C,OAAO,KAAK,EAAE,WAAW,EAAsB,QAAQ,EAAE,MAAM,aAAa,CAAC;AAC7E,OAAO,EAAE,KAAK,sBAAsB,EAAE,MAAM,UAAU,CAAC;AAEvD,UAAU,WAAW,CAAC,CAAC,SAAS,UAAU;IACxC,UAAU,EAAE,sBAAsB,CAAC,CAAC,CAAC,GAAG,MAAM,CAAC,CAAC;CACjD;AAED;;;;;;;;;;;;;;;;;;;;;;;;;GAyBG;AACH,iBAAS,MAAM,CAAC,CAAC,SAAS,UAAU,EAAE,CAAC,SAAS,UAAU,EACxD,SAAS,EAAE,MAAM,WAAW,CAAC,CAAC,CAAC,EAC/B,KAAK,EAAE,WAAW,CAAC,CAAC,CAAC,YAGX,SAAS,WACR,2BAA2B,CAAC,EAAE,SAAS,CAAC,CAAC,CAAC,
|
|
1
|
+
{"version":3,"file":"HasOne.d.ts","sourceRoot":"","sources":["../../../../src/decorators/relationships/HasOne.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,UAAU,MAAM,kBAAkB,CAAC;AAC/C,OAAO,KAAK,EAAE,WAAW,EAAsB,QAAQ,EAAE,MAAM,aAAa,CAAC;AAC7E,OAAO,EAAE,KAAK,sBAAsB,EAAE,MAAM,UAAU,CAAC;AAEvD,UAAU,WAAW,CAAC,CAAC,SAAS,UAAU;IACxC,UAAU,EAAE,sBAAsB,CAAC,CAAC,CAAC,GAAG,MAAM,CAAC,CAAC;CACjD;AAED;;;;;;;;;;;;;;;;;;;;;;;;;GAyBG;AACH,iBAAS,MAAM,CAAC,CAAC,SAAS,UAAU,EAAE,CAAC,SAAS,UAAU,EACxD,SAAS,EAAE,MAAM,WAAW,CAAC,CAAC,CAAC,EAC/B,KAAK,EAAE,WAAW,CAAC,CAAC,CAAC,YAGX,SAAS,WACR,2BAA2B,CAAC,EAAE,SAAS,CAAC,CAAC,CAAC,UAatD;AAED,eAAe,MAAM,CAAC"}
|
|
@@ -15,12 +15,12 @@ const metadata_1 = __importDefault(require("../../metadata"));
|
|
|
15
15
|
*
|
|
16
16
|
* Usage example:
|
|
17
17
|
* ```typescript
|
|
18
|
-
* class User extends
|
|
18
|
+
* class User extends TableClass {
|
|
19
19
|
* @HasOne(() => Profile, { foreignKey: 'userId' })
|
|
20
20
|
* public profile?: Profile;
|
|
21
21
|
* }
|
|
22
22
|
*
|
|
23
|
-
* class Profile extends
|
|
23
|
+
* class Profile extends TableClass {
|
|
24
24
|
* @ForeignKeyProperty()
|
|
25
25
|
* public readonly userId: ForeignKey;
|
|
26
26
|
*
|
|
@@ -34,8 +34,7 @@ function HasOne(getTarget, props) {
|
|
|
34
34
|
return function (_value, context) {
|
|
35
35
|
if (context.kind === "field") {
|
|
36
36
|
context.addInitializer(function () {
|
|
37
|
-
|
|
38
|
-
metadata_1.default.addEntityRelationship(entity.constructor.name, {
|
|
37
|
+
metadata_1.default.addEntityRelationship(this.constructor.name, {
|
|
39
38
|
type: "HasOne",
|
|
40
39
|
propertyName: context.name,
|
|
41
40
|
target: getTarget(),
|
|
@@ -33,6 +33,10 @@ declare class EntityMetadata {
|
|
|
33
33
|
*/
|
|
34
34
|
readonly relationships: RelationshipMetadataStorage;
|
|
35
35
|
readonly EntityClass: EntityClass;
|
|
36
|
+
/**
|
|
37
|
+
* Optional attribute of an entity, used with @IdAttribute decorator when an entity has a custom id field
|
|
38
|
+
*/
|
|
39
|
+
idField: string;
|
|
36
40
|
constructor(entityClass: EntityClass, tableClassName: string);
|
|
37
41
|
/**
|
|
38
42
|
* Add attribute metadata to an entity
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"EntityMetadata.d.ts","sourceRoot":"","sources":["../../../src/metadata/EntityMetadata.ts"],"names":[],"mappings":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,EAAE,MAAM,CAAC;gBAiBX,WAAW,EAAE,WAAW,EAAE,cAAc,EAAE,MAAM;IAS5D;;;OAGG;IACI,YAAY,CAAC,QAAQ,EAAE,iBAAiB,GAAG,IAAI;IAOtD;;;;;OAKG;IACI,+BAA+B,CACpC,UAAU,EAAE,uBAAuB,CAAC,UAAU,CAAC,GAC9C,uBAAuB,CAAC,UAAU,CAAC;IAatC;;;;;;OAMG;IACI,sCAAsC,CAC3C,UAAU,EAAE,OAAO,CAAC,uBAAuB,CAAC,UAAU,CAAC,CAAC,GACvD,OAAO,CAAC,uBAAuB,CAAC,UAAU,CAAC,CAAC;IAgB/C;;;OAGG;IACH,OAAO,CAAC,oBAAoB;CAK7B;AAED,eAAe,cAAc,CAAC"}
|
|
@@ -36,6 +36,10 @@ class EntityMetadata {
|
|
|
36
36
|
*/
|
|
37
37
|
relationships;
|
|
38
38
|
EntityClass;
|
|
39
|
+
/**
|
|
40
|
+
* Optional attribute of an entity, used with @IdAttribute decorator when an entity has a custom id field
|
|
41
|
+
*/
|
|
42
|
+
idField;
|
|
39
43
|
/**
|
|
40
44
|
* Zod schema for runtime validation on entity attributes. Validates all attributes (used on Create)
|
|
41
45
|
*/
|
|
@@ -77,6 +77,12 @@ declare class MetadataStorage {
|
|
|
77
77
|
* @param options
|
|
78
78
|
*/
|
|
79
79
|
addEntityAttribute(entityName: string, options: MakeOptional<AttributeMetadataOptions, "alias">): void;
|
|
80
|
+
/**
|
|
81
|
+
* Store the entities optional id field attribute. Used with @IdAttribute
|
|
82
|
+
* @param entityName
|
|
83
|
+
* @param fieldName
|
|
84
|
+
*/
|
|
85
|
+
addEntityIdField(entityName: string, fieldName: string): void;
|
|
80
86
|
/**
|
|
81
87
|
* Adds the partition key attribute to Table metadata storage
|
|
82
88
|
* @param entityClass
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"MetadataStorage.d.ts","sourceRoot":"","sources":["../../../src/metadata/MetadataStorage.ts"],"names":[],"mappings":"AAA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
|
entityMetadata.addAttribute(meta);
|
|
144
144
|
}
|
|
145
|
+
/**
|
|
146
|
+
* Store the entities optional id field attribute. Used with @IdAttribute
|
|
147
|
+
* @param entityName
|
|
148
|
+
* @param fieldName
|
|
149
|
+
*/
|
|
150
|
+
addEntityIdField(entityName, fieldName) {
|
|
151
|
+
const entityMetadata = this.#entities[entityName];
|
|
152
|
+
entityMetadata.idField = fieldName;
|
|
153
|
+
}
|
|
145
154
|
/**
|
|
146
155
|
* Adds the partition key attribute to Table metadata storage
|
|
147
156
|
* @param entityClass
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"TableMetadata.d.ts","sourceRoot":"","sources":["../../../src/metadata/TableMetadata.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,iBAAiB,EAAE,MAAM,GAAG,CAAC;AAEtC,OAAO,KAAK,EACV,oBAAoB,EACpB,aAAa,EAGb,4BAA4B,EAC7B,MAAM,SAAS,CAAC;AAEjB,eAAO,MAAM,gBAAgB;;;CAAiD,CAAC;AAE/E;;GAEG;AACH,eAAO,MAAM,kBAAkB,EAAE,MAAM,CACrC,aAAa,EACb;IAAE,KAAK,EAAE,aAAa,CAAA;CAAE,CAQhB,CAAC;AAEX;;;;;;;;;;;;;GAaG;AACH,cAAM,aAAa;IACjB,SAAgB,IAAI,EAAE,MAAM,CAAC;IAC7B,SAAgB,SAAS,EAAE,MAAM,CAAC;IAClC,SAAgB,iBAAiB,EAAE,MAAM,CAAC,aAAa,EAAE,iBAAiB,CAAC,CAAC;IAC5E,SAAgB,sBAAsB,EAAE,MAAM,CAAC,MAAM,EAAE,iBAAiB,CAAC,CAAC;IACnE,qBAAqB,EAAE,iBAAiB,CAAC;IACzC,gBAAgB,EAAE,iBAAiB,CAAC;IAE3C;;;;;;;;;;;;;;;;OAgBG;IACI,YAAY,EAAE,MAAM,CAAC,MAAM,EAAE,IAAI,CAAC,CAAC;gBAE9B,OAAO,EAAE,oBAAoB;
|
|
1
|
+
{"version":3,"file":"TableMetadata.d.ts","sourceRoot":"","sources":["../../../src/metadata/TableMetadata.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,iBAAiB,EAAE,MAAM,GAAG,CAAC;AAEtC,OAAO,KAAK,EACV,oBAAoB,EACpB,aAAa,EAGb,4BAA4B,EAC7B,MAAM,SAAS,CAAC;AAEjB,eAAO,MAAM,gBAAgB;;;CAAiD,CAAC;AAE/E;;GAEG;AACH,eAAO,MAAM,kBAAkB,EAAE,MAAM,CACrC,aAAa,EACb;IAAE,KAAK,EAAE,aAAa,CAAA;CAAE,CAQhB,CAAC;AAEX;;;;;;;;;;;;;GAaG;AACH,cAAM,aAAa;IACjB,SAAgB,IAAI,EAAE,MAAM,CAAC;IAC7B,SAAgB,SAAS,EAAE,MAAM,CAAC;IAClC,SAAgB,iBAAiB,EAAE,MAAM,CAAC,aAAa,EAAE,iBAAiB,CAAC,CAAC;IAC5E,SAAgB,sBAAsB,EAAE,MAAM,CAAC,MAAM,EAAE,iBAAiB,CAAC,CAAC;IACnE,qBAAqB,EAAE,iBAAiB,CAAC;IACzC,gBAAgB,EAAE,iBAAiB,CAAC;IAE3C;;;;;;;;;;;;;;;;OAgBG;IACI,YAAY,EAAE,MAAM,CAAC,MAAM,EAAE,IAAI,CAAC,CAAC;gBAE9B,OAAO,EAAE,oBAAoB;IA4BzC;;;;OAIG;IACH,OAAO,CAAC,8BAA8B;IAgCtC;;;OAGG;IACI,wBAAwB,CAAC,OAAO,EAAE,4BAA4B,GAAG,IAAI;IAO5E;;;OAGG;IACI,mBAAmB,CAAC,OAAO,EAAE,4BAA4B,GAAG,IAAI;CAMxE;AAED,eAAe,aAAa,CAAC"}
|
|
@@ -66,14 +66,12 @@ class TableMetadata {
|
|
|
66
66
|
name: "",
|
|
67
67
|
alias: exports.defaultTableKeys.partitionKey,
|
|
68
68
|
nullable: false,
|
|
69
|
-
serializers: { toEntityAttribute: () => "", toTableAttribute: () => "" },
|
|
70
69
|
type: zod_1.z.string()
|
|
71
70
|
};
|
|
72
71
|
this.sortKeyAttribute = {
|
|
73
72
|
name: "",
|
|
74
73
|
alias: exports.defaultTableKeys.sortKey,
|
|
75
74
|
nullable: false,
|
|
76
|
-
serializers: { toEntityAttribute: () => "", toTableAttribute: () => "" },
|
|
77
75
|
type: zod_1.z.string()
|
|
78
76
|
};
|
|
79
77
|
const defaultAttrNames = Object.keys(this.defaultAttributes);
|
|
@@ -98,7 +96,7 @@ class TableMetadata {
|
|
|
98
96
|
alias,
|
|
99
97
|
nullable: false,
|
|
100
98
|
serializers: isDateField ? decorators_1.dateSerializer : undefined,
|
|
101
|
-
type: isDateField ? zod_1.z.date() : zod_1.z.
|
|
99
|
+
type: isDateField ? zod_1.z.date() : zod_1.z.string()
|
|
102
100
|
};
|
|
103
101
|
acc.entityDefaults[entityKey] = meta;
|
|
104
102
|
acc.tableDefaults[alias] = meta;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Create.d.ts","sourceRoot":"","sources":["../../../../src/operations/Create/Create.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,UAAU,MAAM,kBAAkB,CAAC;AAE/C,OAAO,KAAK,EAAmB,WAAW,EAAE,MAAM,aAAa,CAAC;AAGhE,OAAO,aAAa,MAAM,kBAAkB,CAAC;AAE7C,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,SAAS,CAAC;AAC7C,OAAO,
|
|
1
|
+
{"version":3,"file":"Create.d.ts","sourceRoot":"","sources":["../../../../src/operations/Create/Create.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,UAAU,MAAM,kBAAkB,CAAC;AAE/C,OAAO,KAAK,EAAmB,WAAW,EAAE,MAAM,aAAa,CAAC;AAGhE,OAAO,aAAa,MAAM,kBAAkB,CAAC;AAE7C,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,SAAS,CAAC;AAC7C,OAAO,EAGL,KAAK,gBAAgB,EACtB,MAAM,UAAU,CAAC;AAElB;;;;;;;;GAQG;AACH,cAAM,MAAM,CAAC,CAAC,SAAS,UAAU,CAAE,SAAQ,aAAa,CAAC,CAAC,CAAC;;gBAG7C,MAAM,EAAE,WAAW,CAAC,CAAC,CAAC;IAMlC;;;;OAIG;IACU,GAAG,CAAC,UAAU,EAAE,aAAa,CAAC,CAAC,CAAC,GAAG,OAAO,CAAC,gBAAgB,CAAC,CAAC,CAAC,CAAC;IAiB5E;;;;OAIG;IACH,OAAO,CAAC,uBAAuB;IA+B/B;;;OAGG;IACH,OAAO,CAAC,uBAAuB;IAiB/B;;;OAGG;YACW,6BAA6B;CAU5C;AAED,eAAe,MAAM,CAAC"}
|
|
@@ -8,7 +8,6 @@ const dynamo_utils_1 = require("../../dynamo-utils");
|
|
|
8
8
|
const utils_1 = require("../../utils");
|
|
9
9
|
const OperationBase_1 = __importDefault(require("../OperationBase"));
|
|
10
10
|
const utils_2 = require("../utils");
|
|
11
|
-
const metadata_1 = __importDefault(require("../../metadata"));
|
|
12
11
|
/**
|
|
13
12
|
* Represents the operation for creating a new entity in the database, including handling its attributes and any related entities' associations. It will handle de-normalizing data to support relationships
|
|
14
13
|
*
|
|
@@ -24,18 +23,18 @@ class Create extends OperationBase_1.default {
|
|
|
24
23
|
super(Entity);
|
|
25
24
|
this.#transactionBuilder = new dynamo_utils_1.TransactWriteBuilder();
|
|
26
25
|
}
|
|
26
|
+
// TODO I need to handle the error where this throws because an item already exists and throw a better error...
|
|
27
27
|
/**
|
|
28
28
|
* Create an entity transaction, including relationship transactions (EX: Creating BelongsToLinks for HasMany, checking existence of relationships, etc)
|
|
29
29
|
* @param attributes
|
|
30
30
|
* @returns
|
|
31
31
|
*/
|
|
32
32
|
async run(attributes) {
|
|
33
|
-
const
|
|
34
|
-
const
|
|
35
|
-
const reservedAttrs = this.buildReservedAttributes();
|
|
33
|
+
const entityAttrs = this.entityMetadata.parseRawEntityDefinedAttributes(attributes);
|
|
34
|
+
const reservedAttrs = this.buildReservedAttributes(entityAttrs);
|
|
36
35
|
const entityData = { ...reservedAttrs, ...entityAttrs };
|
|
37
36
|
const tableItem = (0, utils_1.entityToTableItem)(this.EntityClass, entityData);
|
|
38
|
-
this.buildPutItemTransaction(tableItem);
|
|
37
|
+
this.buildPutItemTransaction(tableItem, entityData.id);
|
|
39
38
|
await this.buildRelationshipTransactions(entityData);
|
|
40
39
|
await this.#transactionBuilder.executeTransaction();
|
|
41
40
|
return (0, utils_1.tableItemToEntity)(this.EntityClass, tableItem);
|
|
@@ -45,8 +44,12 @@ class Create extends OperationBase_1.default {
|
|
|
45
44
|
* @param attributes
|
|
46
45
|
* @returns
|
|
47
46
|
*/
|
|
48
|
-
buildReservedAttributes() {
|
|
49
|
-
const
|
|
47
|
+
buildReservedAttributes(entityAttrs) {
|
|
48
|
+
const { idField } = this.entityMetadata;
|
|
49
|
+
// If the entity has has a custom id field use that, otherwise generate a uuid
|
|
50
|
+
const id = idField === undefined
|
|
51
|
+
? (0, uuid_1.v4)()
|
|
52
|
+
: entityAttrs[idField];
|
|
50
53
|
const createdAt = new Date();
|
|
51
54
|
const pk = this.tableMetadata.partitionKeyAttribute.name;
|
|
52
55
|
const sk = this.tableMetadata.sortKeyAttribute.name;
|
|
@@ -66,14 +69,14 @@ class Create extends OperationBase_1.default {
|
|
|
66
69
|
* Build the transaction for the parent entity Create item request
|
|
67
70
|
* @param tableItem
|
|
68
71
|
*/
|
|
69
|
-
buildPutItemTransaction(tableItem) {
|
|
72
|
+
buildPutItemTransaction(tableItem, id) {
|
|
70
73
|
const { name: tableName } = this.tableMetadata;
|
|
71
74
|
const putExpression = {
|
|
72
75
|
TableName: tableName,
|
|
73
76
|
Item: tableItem,
|
|
74
77
|
ConditionExpression: `attribute_not_exists(${this.partitionKeyAlias})` // Ensure item doesn't already exist
|
|
75
78
|
};
|
|
76
|
-
this.#transactionBuilder.addPut(putExpression);
|
|
79
|
+
this.#transactionBuilder.addPut(putExpression, `${this.EntityClass.name} with id: ${id} already exists`);
|
|
77
80
|
}
|
|
78
81
|
/**
|
|
79
82
|
* Build transaction items for associations
|