dyna-record 0.1.5 → 0.2.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.
- package/README.md +11 -13
- package/dist/src/DynaRecord.d.ts +36 -28
- package/dist/src/DynaRecord.d.ts.map +1 -1
- package/dist/src/DynaRecord.js +39 -36
- package/dist/src/decorators/Table.d.ts.map +1 -1
- package/dist/src/decorators/attributes/BooleanAttribute.d.ts.map +1 -1
- package/dist/src/decorators/attributes/DateAttribute.d.ts.map +1 -1
- package/dist/src/decorators/attributes/EnumAttribute.d.ts.map +1 -1
- package/dist/src/decorators/attributes/ForeignKeyAttribute.d.ts.map +1 -1
- package/dist/src/decorators/attributes/NumberAttribute.d.ts.map +1 -1
- package/dist/src/decorators/attributes/PartitionKeyAttribute.d.ts.map +1 -1
- package/dist/src/decorators/attributes/SortKeyAttribute.d.ts.map +1 -1
- package/dist/src/decorators/attributes/StringAttribute.d.ts.map +1 -1
- package/dist/src/decorators/attributes/serializers.d.ts +1 -1
- package/dist/src/decorators/relationships/BelongsTo.d.ts.map +1 -1
- package/dist/src/decorators/relationships/HasAndBelongsToMany.d.ts.map +1 -1
- package/dist/src/decorators/relationships/HasMany.d.ts +7 -0
- package/dist/src/decorators/relationships/HasMany.d.ts.map +1 -1
- package/dist/src/decorators/relationships/HasMany.js +12 -2
- package/dist/src/decorators/relationships/HasOne.d.ts.map +1 -1
- package/dist/src/decorators/types.d.ts +2 -2
- package/dist/src/decorators/types.d.ts.map +1 -1
- package/dist/src/dynamo-utils/TransactGetBuilder.d.ts +4 -0
- package/dist/src/dynamo-utils/TransactGetBuilder.d.ts.map +1 -1
- package/dist/src/dynamo-utils/TransactGetBuilder.js +6 -0
- package/dist/src/metadata/EntityMetadata.d.ts +21 -1
- package/dist/src/metadata/EntityMetadata.d.ts.map +1 -1
- package/dist/src/metadata/EntityMetadata.js +33 -0
- package/dist/src/metadata/TableMetadata.d.ts.map +1 -1
- package/dist/src/metadata/TableMetadata.js +1 -3
- package/dist/src/metadata/relationship-metadata/BelongsToRelationship.d.ts +1 -1
- package/dist/src/metadata/relationship-metadata/BelongsToRelationship.js +1 -1
- package/dist/src/metadata/relationship-metadata/HasManyRelationship.d.ts +2 -1
- package/dist/src/metadata/relationship-metadata/HasManyRelationship.d.ts.map +1 -1
- package/dist/src/metadata/relationship-metadata/HasManyRelationship.js +2 -1
- package/dist/src/metadata/relationship-metadata/OwnedByRelationship.d.ts +18 -0
- package/dist/src/metadata/relationship-metadata/OwnedByRelationship.d.ts.map +1 -0
- package/dist/src/metadata/relationship-metadata/OwnedByRelationship.js +26 -0
- package/dist/src/metadata/relationship-metadata/RelationshipMetadata.d.ts +1 -1
- package/dist/src/metadata/relationship-metadata/RelationshipMetadata.d.ts.map +1 -1
- package/dist/src/metadata/relationship-metadata/index.d.ts +2 -1
- package/dist/src/metadata/relationship-metadata/index.d.ts.map +1 -1
- package/dist/src/metadata/relationship-metadata/index.js +3 -1
- package/dist/src/metadata/relationship-metadata/types.d.ts +7 -2
- package/dist/src/metadata/relationship-metadata/types.d.ts.map +1 -1
- package/dist/src/metadata/relationship-metadata/utils.d.ts.map +1 -1
- package/dist/src/metadata/relationship-metadata/utils.js +3 -0
- package/dist/src/metadata/types.d.ts +7 -4
- package/dist/src/metadata/types.d.ts.map +1 -1
- package/dist/src/metadata/utils.d.ts +8 -4
- package/dist/src/metadata/utils.d.ts.map +1 -1
- package/dist/src/metadata/utils.js +8 -1
- package/dist/src/operations/Create/Create.d.ts +95 -16
- package/dist/src/operations/Create/Create.d.ts.map +1 -1
- package/dist/src/operations/Create/Create.js +171 -22
- package/dist/src/operations/Delete/Delete.d.ts +32 -23
- package/dist/src/operations/Delete/Delete.d.ts.map +1 -1
- package/dist/src/operations/Delete/Delete.js +117 -100
- package/dist/src/operations/Delete/types.d.ts +0 -3
- package/dist/src/operations/Delete/types.d.ts.map +1 -1
- package/dist/src/operations/FindById/FindById.d.ts +7 -28
- package/dist/src/operations/FindById/FindById.d.ts.map +1 -1
- package/dist/src/operations/FindById/FindById.js +36 -125
- package/dist/src/operations/FindById/types.d.ts +8 -9
- package/dist/src/operations/FindById/types.d.ts.map +1 -1
- package/dist/src/operations/Query/Query.d.ts +2 -1
- package/dist/src/operations/Query/Query.d.ts.map +1 -1
- package/dist/src/operations/Query/Query.js +17 -4
- package/dist/src/operations/Query/types.d.ts +39 -5
- package/dist/src/operations/Query/types.d.ts.map +1 -1
- package/dist/src/operations/Update/Update.d.ts +185 -24
- package/dist/src/operations/Update/Update.d.ts.map +1 -1
- package/dist/src/operations/Update/Update.js +409 -72
- package/dist/src/operations/Update/UpdateDryRun.d.ts +10 -0
- package/dist/src/operations/Update/UpdateDryRun.d.ts.map +1 -0
- package/dist/src/operations/Update/UpdateDryRun.js +15 -0
- package/dist/src/operations/Update/index.d.ts +1 -0
- package/dist/src/operations/Update/index.d.ts.map +1 -1
- package/dist/src/operations/Update/index.js +3 -1
- package/dist/src/operations/types.d.ts +6 -1
- package/dist/src/operations/types.d.ts.map +1 -1
- package/dist/src/operations/utils/expressionBuilder.d.ts.map +1 -1
- package/dist/src/operations/utils/expressionBuilder.js +1 -4
- package/dist/src/operations/utils/index.d.ts +0 -1
- package/dist/src/operations/utils/index.d.ts.map +1 -1
- package/dist/src/operations/utils/index.js +0 -6
- package/dist/src/operations/utils/utils.d.ts +13 -3
- package/dist/src/operations/utils/utils.d.ts.map +1 -1
- package/dist/src/operations/utils/utils.js +33 -3
- package/dist/src/query-utils/Filters.d.ts +1 -1
- package/dist/src/query-utils/Filters.d.ts.map +1 -1
- package/dist/src/query-utils/Filters.js +7 -15
- package/dist/src/query-utils/QueryBuilder.d.ts.map +1 -1
- package/dist/src/query-utils/QueryBuilder.js +9 -1
- package/dist/src/relationships/JoinTable.d.ts +17 -7
- package/dist/src/relationships/JoinTable.d.ts.map +1 -1
- package/dist/src/relationships/JoinTable.js +77 -20
- package/dist/src/relationships/index.d.ts +0 -1
- package/dist/src/relationships/index.d.ts.map +1 -1
- package/dist/src/relationships/index.js +1 -3
- package/dist/src/types.d.ts +6 -8
- package/dist/src/types.d.ts.map +1 -1
- package/dist/src/utils.d.ts +10 -32
- package/dist/src/utils.d.ts.map +1 -1
- package/dist/src/utils.js +13 -59
- package/package.json +5 -5
- package/dist/src/operations/utils/RelationshipTransactions.d.ts +0 -64
- package/dist/src/operations/utils/RelationshipTransactions.d.ts.map +0 -1
- package/dist/src/operations/utils/RelationshipTransactions.js +0 -125
- package/dist/src/relationships/BelongsToLink.d.ts +0 -51
- package/dist/src/relationships/BelongsToLink.d.ts.map +0 -1
- package/dist/src/relationships/BelongsToLink.js +0 -57
|
@@ -6,6 +6,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
6
6
|
const zod_1 = require("zod");
|
|
7
7
|
const errors_1 = require("../errors");
|
|
8
8
|
const _1 = __importDefault(require("."));
|
|
9
|
+
const utils_1 = require("./utils");
|
|
9
10
|
/**
|
|
10
11
|
* Represents metadata for an entity within the ORM system, encapsulating information about the entity's attributes, relationships, and its associated database table.
|
|
11
12
|
*
|
|
@@ -116,5 +117,37 @@ class EntityMetadata {
|
|
|
116
117
|
const errorOptions = error instanceof zod_1.ZodError ? { cause: error.issues } : undefined;
|
|
117
118
|
return new errors_1.ValidationError("Validation errors", errorOptions);
|
|
118
119
|
}
|
|
120
|
+
/**
|
|
121
|
+
* Returns all relationship metadata for the entity
|
|
122
|
+
*/
|
|
123
|
+
get allRelationships() {
|
|
124
|
+
return Object.values(this.relationships);
|
|
125
|
+
}
|
|
126
|
+
/**
|
|
127
|
+
* Returns the BelongsToRelationship (bidirectional to parent) metadata for the entity
|
|
128
|
+
*/
|
|
129
|
+
get belongsToRelationships() {
|
|
130
|
+
return Object.values(this.relationships).filter(rel => (0, utils_1.isBelongsToRelationship)(rel));
|
|
131
|
+
}
|
|
132
|
+
/**
|
|
133
|
+
* Returns the OwnedByRelationship (unidirectional to parent) relationship metadata for an entity
|
|
134
|
+
*/
|
|
135
|
+
get ownedByRelationships() {
|
|
136
|
+
return Object.values(this.relationships).filter(relMeta => (0, utils_1.isOwnedByRelationship)(relMeta));
|
|
137
|
+
}
|
|
138
|
+
/**
|
|
139
|
+
* Returns the BelongsToRelationship and OwnedByRelationship metadata objects for an entity
|
|
140
|
+
*/
|
|
141
|
+
get belongsToOrOwnedByRelationships() {
|
|
142
|
+
return [...this.belongsToRelationships, ...this.ownedByRelationships];
|
|
143
|
+
}
|
|
144
|
+
/**
|
|
145
|
+
* Returns the "Has" relationship metadata for the entity (EX: "HasMany")
|
|
146
|
+
*/
|
|
147
|
+
get hasRelationships() {
|
|
148
|
+
return Object.values(this.relationships).filter(relMeta => (0, utils_1.isHasOneRelationship)(relMeta) ||
|
|
149
|
+
(0, utils_1.isHasManyRelationship)(relMeta) ||
|
|
150
|
+
(0, utils_1.isHasAndBelongsToManyRelationship)(relMeta));
|
|
151
|
+
}
|
|
119
152
|
}
|
|
120
153
|
exports.default = EntityMetadata;
|
|
@@ -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,
|
|
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,CAMhB,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"}
|
|
@@ -12,9 +12,7 @@ exports.tableDefaultFields = {
|
|
|
12
12
|
id: { alias: "id" },
|
|
13
13
|
type: { alias: "type" },
|
|
14
14
|
createdAt: { alias: "createdAt" },
|
|
15
|
-
updatedAt: { alias: "updatedAt" }
|
|
16
|
-
foreignKey: { alias: "foreignKey" },
|
|
17
|
-
foreignEntityType: { alias: "foreignEntityType" }
|
|
15
|
+
updatedAt: { alias: "updatedAt" }
|
|
18
16
|
};
|
|
19
17
|
/**
|
|
20
18
|
* Represents the metadata for a table within the ORM framework, encapsulating information such as table name, key attributes, and default field mappings. This class is fundamental for defining how entities are mapped to their underlying database tables, providing a schema-like structure that includes both key configuration and default attribute handling.
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import type { ForeignKeyProperty } from "../../types";
|
|
2
2
|
import RelationshipMetadata from "./RelationshipMetadata";
|
|
3
3
|
/**
|
|
4
|
-
* Represents a "Belongs To" relationship metadata within the ORM system.
|
|
4
|
+
* Represents a "Belongs To" relationship metadata within the ORM system. These are bidirectional relationships to the parent.
|
|
5
5
|
*
|
|
6
6
|
* @extends {RelationshipMetadata} Inherits the base functionality and properties of `RelationshipMetadata`.
|
|
7
7
|
* @property {"BelongsTo"} type - The type of the relationship, statically set to "BelongsTo" to signify the nature of the relationship.
|
|
@@ -5,7 +5,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
5
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
6
|
const RelationshipMetadata_1 = __importDefault(require("./RelationshipMetadata"));
|
|
7
7
|
/**
|
|
8
|
-
* Represents a "Belongs To" relationship metadata within the ORM system.
|
|
8
|
+
* Represents a "Belongs To" relationship metadata within the ORM system. These are bidirectional relationships to the parent.
|
|
9
9
|
*
|
|
10
10
|
* @extends {RelationshipMetadata} Inherits the base functionality and properties of `RelationshipMetadata`.
|
|
11
11
|
* @property {"BelongsTo"} type - The type of the relationship, statically set to "BelongsTo" to signify the nature of the relationship.
|
|
@@ -3,15 +3,16 @@ import RelationshipMetadata from "./RelationshipMetadata";
|
|
|
3
3
|
/**
|
|
4
4
|
* Extends `RelationshipMetadata` to specifically handle "HasMany" relationship metadata within the ORM system.
|
|
5
5
|
*
|
|
6
|
-
*
|
|
7
6
|
* @property {"HasMany"} type - A literal string that explicitly defines the type of relationship as "HasMany". This classification helps the ORM to apply the correct logic for relationship handling.
|
|
8
7
|
* @property {ForeignKeyProperty} foreignKey - The attribute in the associated entity that serves as a foreign key, linking back to the partition key of the owning entity. This key is essential for maintaining the integrity of the "HasMany" relationship.
|
|
8
|
+
* @property {boolean} uniDirectional - Indicates whether the relationship is unidirectional. If `true`, the relationship supports access patterns in only one direction (from the owning entity to the related entities), reducing denormalized data. This is useful when bidirectional access patterns are unnecessary.
|
|
9
9
|
*
|
|
10
10
|
* @param {RelationshipMetadata} item - An existing set of relationship metadata that should be applied to the newly created `HasManyRelationship` instance. This parameter allows for the inheritance and augmentation of relationship properties.
|
|
11
11
|
*/
|
|
12
12
|
declare class HasManyRelationship extends RelationshipMetadata {
|
|
13
13
|
type: "HasMany";
|
|
14
14
|
foreignKey: ForeignKeyProperty;
|
|
15
|
+
uniDirectional?: boolean;
|
|
15
16
|
constructor(item: RelationshipMetadata);
|
|
16
17
|
}
|
|
17
18
|
export default HasManyRelationship;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"HasManyRelationship.d.ts","sourceRoot":"","sources":["../../../../src/metadata/relationship-metadata/HasManyRelationship.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,kBAAkB,EAAE,MAAM,aAAa,CAAC;AACtD,OAAO,oBAAoB,MAAM,wBAAwB,CAAC;AAE1D;;;;;;;;GAQG;AACH,cAAM,mBAAoB,SAAQ,oBAAoB;IACpD,IAAI,EAAE,SAAS,CAAa;IAC5B,UAAU,EAAE,kBAAkB,CAAC;
|
|
1
|
+
{"version":3,"file":"HasManyRelationship.d.ts","sourceRoot":"","sources":["../../../../src/metadata/relationship-metadata/HasManyRelationship.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,kBAAkB,EAAE,MAAM,aAAa,CAAC;AACtD,OAAO,oBAAoB,MAAM,wBAAwB,CAAC;AAE1D;;;;;;;;GAQG;AACH,cAAM,mBAAoB,SAAQ,oBAAoB;IACpD,IAAI,EAAE,SAAS,CAAa;IAC5B,UAAU,EAAE,kBAAkB,CAAC;IAC/B,cAAc,CAAC,EAAE,OAAO,CAAS;gBAErB,IAAI,EAAE,oBAAoB;CAMvC;AAED,eAAe,mBAAmB,CAAC"}
|
|
@@ -7,15 +7,16 @@ const RelationshipMetadata_1 = __importDefault(require("./RelationshipMetadata")
|
|
|
7
7
|
/**
|
|
8
8
|
* Extends `RelationshipMetadata` to specifically handle "HasMany" relationship metadata within the ORM system.
|
|
9
9
|
*
|
|
10
|
-
*
|
|
11
10
|
* @property {"HasMany"} type - A literal string that explicitly defines the type of relationship as "HasMany". This classification helps the ORM to apply the correct logic for relationship handling.
|
|
12
11
|
* @property {ForeignKeyProperty} foreignKey - The attribute in the associated entity that serves as a foreign key, linking back to the partition key of the owning entity. This key is essential for maintaining the integrity of the "HasMany" relationship.
|
|
12
|
+
* @property {boolean} uniDirectional - Indicates whether the relationship is unidirectional. If `true`, the relationship supports access patterns in only one direction (from the owning entity to the related entities), reducing denormalized data. This is useful when bidirectional access patterns are unnecessary.
|
|
13
13
|
*
|
|
14
14
|
* @param {RelationshipMetadata} item - An existing set of relationship metadata that should be applied to the newly created `HasManyRelationship` instance. This parameter allows for the inheritance and augmentation of relationship properties.
|
|
15
15
|
*/
|
|
16
16
|
class HasManyRelationship extends RelationshipMetadata_1.default {
|
|
17
17
|
type = "HasMany";
|
|
18
18
|
foreignKey;
|
|
19
|
+
uniDirectional = false;
|
|
19
20
|
constructor(item) {
|
|
20
21
|
super();
|
|
21
22
|
if (item !== undefined) {
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import type { ForeignKeyProperty } from "../../types";
|
|
2
|
+
import RelationshipMetadata from "./RelationshipMetadata";
|
|
3
|
+
/**
|
|
4
|
+
* Represents an "Owned By" relationship metadata within the ORM system. These are uni-directional relationships to the parent
|
|
5
|
+
*
|
|
6
|
+
* @extends {RelationshipMetadata} Inherits the base functionality and properties of `RelationshipMetadata`.
|
|
7
|
+
* @property {"OwnedBy"} type - The type of the relationship, statically set to "OwnedBy" to signify a unidirectional relationship where the current entity is owned by another entity.
|
|
8
|
+
* @property {ForeignKeyProperty} foreignKey - The attribute representing the foreign key in the relationship. This specifies the field in the current entity that links to the owning entity, enabling relationship queries and operations.
|
|
9
|
+
*
|
|
10
|
+
* @param {RelationshipMetadata} item - The initial relationship metadata to be copied into this "Owned By" relationship instance. This facilitates the creation and setup of relationship metadata based on existing configurations.
|
|
11
|
+
*/
|
|
12
|
+
declare class OwnedByRelationship extends RelationshipMetadata {
|
|
13
|
+
type: "OwnedBy";
|
|
14
|
+
foreignKey: ForeignKeyProperty;
|
|
15
|
+
constructor(item: RelationshipMetadata);
|
|
16
|
+
}
|
|
17
|
+
export default OwnedByRelationship;
|
|
18
|
+
//# sourceMappingURL=OwnedByRelationship.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"OwnedByRelationship.d.ts","sourceRoot":"","sources":["../../../../src/metadata/relationship-metadata/OwnedByRelationship.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,kBAAkB,EAAE,MAAM,aAAa,CAAC;AACtD,OAAO,oBAAoB,MAAM,wBAAwB,CAAC;AAE1D;;;;;;;;GAQG;AACH,cAAM,mBAAoB,SAAQ,oBAAoB;IACpD,IAAI,EAAE,SAAS,CAAa;IAC5B,UAAU,EAAE,kBAAkB,CAAC;gBAEnB,IAAI,EAAE,oBAAoB;CAMvC;AAED,eAAe,mBAAmB,CAAC"}
|
|
@@ -0,0 +1,26 @@
|
|
|
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 RelationshipMetadata_1 = __importDefault(require("./RelationshipMetadata"));
|
|
7
|
+
/**
|
|
8
|
+
* Represents an "Owned By" relationship metadata within the ORM system. These are uni-directional relationships to the parent
|
|
9
|
+
*
|
|
10
|
+
* @extends {RelationshipMetadata} Inherits the base functionality and properties of `RelationshipMetadata`.
|
|
11
|
+
* @property {"OwnedBy"} type - The type of the relationship, statically set to "OwnedBy" to signify a unidirectional relationship where the current entity is owned by another entity.
|
|
12
|
+
* @property {ForeignKeyProperty} foreignKey - The attribute representing the foreign key in the relationship. This specifies the field in the current entity that links to the owning entity, enabling relationship queries and operations.
|
|
13
|
+
*
|
|
14
|
+
* @param {RelationshipMetadata} item - The initial relationship metadata to be copied into this "Owned By" relationship instance. This facilitates the creation and setup of relationship metadata based on existing configurations.
|
|
15
|
+
*/
|
|
16
|
+
class OwnedByRelationship extends RelationshipMetadata_1.default {
|
|
17
|
+
type = "OwnedBy";
|
|
18
|
+
foreignKey;
|
|
19
|
+
constructor(item) {
|
|
20
|
+
super();
|
|
21
|
+
if (item !== undefined) {
|
|
22
|
+
Object.assign(this, item);
|
|
23
|
+
}
|
|
24
|
+
}
|
|
25
|
+
}
|
|
26
|
+
exports.default = OwnedByRelationship;
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import type DynaRecord from "../../DynaRecord";
|
|
2
2
|
import type { EntityClass } from "../../types";
|
|
3
|
-
type RelationshipType = "HasMany" | "BelongsTo" | "HasOne" | "HasAndBelongsToMany";
|
|
3
|
+
type RelationshipType = "HasMany" | "BelongsTo" | "HasOne" | "HasAndBelongsToMany" | "OwnedBy";
|
|
4
4
|
/**
|
|
5
5
|
* Serves as the base class for defining metadata related to various types of relationships within the ORM system, such as "HasMany", "BelongsTo", "HasOne", and "HasAndBelongsToMany". This abstract class provides a common structure for relationship metadata, encapsulating the relationship type, target entity, and property name.
|
|
6
6
|
*
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"RelationshipMetadata.d.ts","sourceRoot":"","sources":["../../../../src/metadata/relationship-metadata/RelationshipMetadata.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,UAAU,MAAM,kBAAkB,CAAC;AAC/C,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,aAAa,CAAC;AAE/C,KAAK,gBAAgB,GACjB,SAAS,GACT,WAAW,GACX,QAAQ,GACR,qBAAqB,CAAC;
|
|
1
|
+
{"version":3,"file":"RelationshipMetadata.d.ts","sourceRoot":"","sources":["../../../../src/metadata/relationship-metadata/RelationshipMetadata.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,UAAU,MAAM,kBAAkB,CAAC;AAC/C,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,aAAa,CAAC;AAE/C,KAAK,gBAAgB,GACjB,SAAS,GACT,WAAW,GACX,QAAQ,GACR,qBAAqB,GACrB,SAAS,CAAC;AAEd;;;;;;;;;;GAUG;AACH,uBAAe,oBAAoB;IACjC,SAAgB,IAAI,EAAE,gBAAgB,CAAC;IAChC,MAAM,EAAE,WAAW,CAAC,UAAU,CAAC,CAAC;IAChC,YAAY,EAAE,MAAM,UAAU,CAAC;CACvC;AAED,eAAe,oBAAoB,CAAC"}
|
|
@@ -2,6 +2,7 @@ import BelongsToRelationship from "./BelongsToRelationship";
|
|
|
2
2
|
import HasAndBelongsToManyRelationship from "./HasAndBelongsToManyRelationship";
|
|
3
3
|
import HasManyRelationship from "./HasManyRelationship";
|
|
4
4
|
import HasOneRelationship from "./HasOneRelationship";
|
|
5
|
+
import OwnedByRelationship from "./OwnedByRelationship";
|
|
5
6
|
export * from "./types";
|
|
6
|
-
export { BelongsToRelationship, HasAndBelongsToManyRelationship, HasManyRelationship, HasOneRelationship };
|
|
7
|
+
export { BelongsToRelationship, HasAndBelongsToManyRelationship, HasManyRelationship, HasOneRelationship, OwnedByRelationship };
|
|
7
8
|
//# sourceMappingURL=index.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../src/metadata/relationship-metadata/index.ts"],"names":[],"mappings":"AAAA,OAAO,qBAAqB,MAAM,yBAAyB,CAAC;AAC5D,OAAO,+BAA+B,MAAM,mCAAmC,CAAC;AAChF,OAAO,mBAAmB,MAAM,uBAAuB,CAAC;AACxD,OAAO,kBAAkB,MAAM,sBAAsB,CAAC;
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../src/metadata/relationship-metadata/index.ts"],"names":[],"mappings":"AAAA,OAAO,qBAAqB,MAAM,yBAAyB,CAAC;AAC5D,OAAO,+BAA+B,MAAM,mCAAmC,CAAC;AAChF,OAAO,mBAAmB,MAAM,uBAAuB,CAAC;AACxD,OAAO,kBAAkB,MAAM,sBAAsB,CAAC;AACtD,OAAO,mBAAmB,MAAM,uBAAuB,CAAC;AAExD,cAAc,SAAS,CAAC;AAExB,OAAO,EACL,qBAAqB,EACrB,+BAA+B,EAC/B,mBAAmB,EACnB,kBAAkB,EAClB,mBAAmB,EACpB,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.HasOneRelationship = exports.HasManyRelationship = exports.HasAndBelongsToManyRelationship = exports.BelongsToRelationship = void 0;
|
|
20
|
+
exports.OwnedByRelationship = exports.HasOneRelationship = exports.HasManyRelationship = exports.HasAndBelongsToManyRelationship = exports.BelongsToRelationship = void 0;
|
|
21
21
|
const BelongsToRelationship_1 = __importDefault(require("./BelongsToRelationship"));
|
|
22
22
|
exports.BelongsToRelationship = BelongsToRelationship_1.default;
|
|
23
23
|
const HasAndBelongsToManyRelationship_1 = __importDefault(require("./HasAndBelongsToManyRelationship"));
|
|
@@ -26,4 +26,6 @@ const HasManyRelationship_1 = __importDefault(require("./HasManyRelationship"));
|
|
|
26
26
|
exports.HasManyRelationship = HasManyRelationship_1.default;
|
|
27
27
|
const HasOneRelationship_1 = __importDefault(require("./HasOneRelationship"));
|
|
28
28
|
exports.HasOneRelationship = HasOneRelationship_1.default;
|
|
29
|
+
const OwnedByRelationship_1 = __importDefault(require("./OwnedByRelationship"));
|
|
30
|
+
exports.OwnedByRelationship = OwnedByRelationship_1.default;
|
|
29
31
|
__exportStar(require("./types"), exports);
|
|
@@ -2,6 +2,7 @@ import type BelongsToRelationship from "./BelongsToRelationship";
|
|
|
2
2
|
import type HasAndBelongsToManyRelationship from "./HasAndBelongsToManyRelationship";
|
|
3
3
|
import type HasManyRelationship from "./HasManyRelationship";
|
|
4
4
|
import type HasOneRelationship from "./HasOneRelationship";
|
|
5
|
+
import type OwnedByRelationship from "./OwnedByRelationship";
|
|
5
6
|
/**
|
|
6
7
|
* A union type that encompasses all possible relationship metadata classes within the ORM system. This type is used to represent the metadata for various types of relationships that can exist between entities, such as "BelongsTo", "HasMany", "HasOne", and "HasAndBelongsToMany" relationships.
|
|
7
8
|
*
|
|
@@ -10,7 +11,11 @@ import type HasOneRelationship from "./HasOneRelationship";
|
|
|
10
11
|
* - `BelongsToRelationship`: Represents a "BelongsTo" relationship, indicating that the entity has a foreign key pointing to another entity.
|
|
11
12
|
* - `HasManyRelationship`: Represents a "HasMany" relationship, indicating that the entity can be associated with multiple instances of another entity.
|
|
12
13
|
* - `HasOneRelationship`: Represents a "HasOne" relationship, indicating that the entity is associated with at most one instance of another entity.
|
|
13
|
-
* - `
|
|
14
|
+
* - `OwnedByRelationship`: Represents an "OwnedBy" relationship, indicating a unidirectional relationship where the current entity is owned by another entity. This relationship focuses on linking the entity to its owner without requiring reverse associations.
|
|
14
15
|
*/
|
|
15
|
-
export type RelationshipMetadata = BelongsToRelationship | HasManyRelationship | HasOneRelationship | HasAndBelongsToManyRelationship;
|
|
16
|
+
export type RelationshipMetadata = BelongsToRelationship | HasManyRelationship | HasOneRelationship | HasAndBelongsToManyRelationship | OwnedByRelationship;
|
|
17
|
+
/**
|
|
18
|
+
* An array of "Has" relationships (EX: "HasMany")
|
|
19
|
+
*/
|
|
20
|
+
export type HasRelationships = Array<HasManyRelationship | HasOneRelationship | HasAndBelongsToManyRelationship>;
|
|
16
21
|
//# sourceMappingURL=types.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../../../src/metadata/relationship-metadata/types.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,qBAAqB,MAAM,yBAAyB,CAAC;AACjE,OAAO,KAAK,+BAA+B,MAAM,mCAAmC,CAAC;AACrF,OAAO,KAAK,mBAAmB,MAAM,uBAAuB,CAAC;AAC7D,OAAO,KAAK,kBAAkB,MAAM,sBAAsB,CAAC;
|
|
1
|
+
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../../../src/metadata/relationship-metadata/types.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,qBAAqB,MAAM,yBAAyB,CAAC;AACjE,OAAO,KAAK,+BAA+B,MAAM,mCAAmC,CAAC;AACrF,OAAO,KAAK,mBAAmB,MAAM,uBAAuB,CAAC;AAC7D,OAAO,KAAK,kBAAkB,MAAM,sBAAsB,CAAC;AAC3D,OAAO,KAAK,mBAAmB,MAAM,uBAAuB,CAAC;AAE7D;;;;;;;;;GASG;AACH,MAAM,MAAM,oBAAoB,GAC5B,qBAAqB,GACrB,mBAAmB,GACnB,kBAAkB,GAClB,+BAA+B,GAC/B,mBAAmB,CAAC;AAExB;;GAEG;AACH,MAAM,MAAM,gBAAgB,GAAG,KAAK,CAClC,mBAAmB,GAAG,kBAAkB,GAAG,+BAA+B,CAC3E,CAAC"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"utils.d.ts","sourceRoot":"","sources":["../../../../src/metadata/relationship-metadata/utils.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"utils.d.ts","sourceRoot":"","sources":["../../../../src/metadata/relationship-metadata/utils.ts"],"names":[],"mappings":"AAKA,OAAO,KAAK,EAAE,oBAAoB,EAAE,MAAM,SAAS,CAAC;AAEpD,eAAO,MAAM,0BAA0B,YAC5B,oBAAoB,KAC5B,oBAeF,CAAC"}
|
|
@@ -8,6 +8,7 @@ const BelongsToRelationship_1 = __importDefault(require("./BelongsToRelationship
|
|
|
8
8
|
const HasAndBelongsToManyRelationship_1 = __importDefault(require("./HasAndBelongsToManyRelationship"));
|
|
9
9
|
const HasManyRelationship_1 = __importDefault(require("./HasManyRelationship"));
|
|
10
10
|
const HasOneRelationship_1 = __importDefault(require("./HasOneRelationship"));
|
|
11
|
+
const OwnedByRelationship_1 = __importDefault(require("./OwnedByRelationship"));
|
|
11
12
|
const createRelationshipInstance = (options) => {
|
|
12
13
|
switch (options.type) {
|
|
13
14
|
case "BelongsTo":
|
|
@@ -18,6 +19,8 @@ const createRelationshipInstance = (options) => {
|
|
|
18
19
|
return new HasManyRelationship_1.default(options);
|
|
19
20
|
case "HasOne":
|
|
20
21
|
return new HasOneRelationship_1.default(options);
|
|
22
|
+
case "OwnedBy":
|
|
23
|
+
return new OwnedByRelationship_1.default(options);
|
|
21
24
|
default:
|
|
22
25
|
throw new Error("Invalid relationship type");
|
|
23
26
|
}
|
|
@@ -1,7 +1,6 @@
|
|
|
1
1
|
import type { NativeScalarAttributeValue } from "@aws-sdk/util-dynamodb";
|
|
2
|
-
import type { AttributeMetadata, EntityMetadata, JoinTableMetadata, RelationshipMetadata, TableMetadata } from ".";
|
|
2
|
+
import type { AttributeMetadata, BelongsToRelationship, EntityMetadata, JoinTableMetadata, OwnedByRelationship, RelationshipMetadata, TableMetadata } from ".";
|
|
3
3
|
import type DynaRecord from "../DynaRecord";
|
|
4
|
-
import type { BelongsToLink } from "../relationships";
|
|
5
4
|
import type { MakeOptional } from "../types";
|
|
6
5
|
import type { ZodType } from "zod";
|
|
7
6
|
/**
|
|
@@ -35,11 +34,11 @@ export type JoinTableMetadataStorage = Record<string, JoinTableMetadata[]>;
|
|
|
35
34
|
*/
|
|
36
35
|
export type DefaultDateFields = "createdAt" | "updatedAt";
|
|
37
36
|
/**
|
|
38
|
-
* Specifies the default fields used in entities, including fields from `DynaRecord
|
|
37
|
+
* Specifies the default fields used in entities, including fields from `DynaRecord`. Instance methods are excluded
|
|
39
38
|
*/
|
|
40
39
|
export type DefaultFields = {
|
|
41
40
|
[K in keyof DynaRecord]: DynaRecord[K] extends (...args: any[]) => any ? never : K;
|
|
42
|
-
}[keyof DynaRecord]
|
|
41
|
+
}[keyof DynaRecord];
|
|
43
42
|
/**
|
|
44
43
|
* Defines the structure for default fields within a table, mapping field names to their `AttributeMetadata` aliases.
|
|
45
44
|
*/
|
|
@@ -91,4 +90,8 @@ export interface AttributeMetadataOptions {
|
|
|
91
90
|
nullable?: boolean;
|
|
92
91
|
serializers?: Serializers;
|
|
93
92
|
}
|
|
93
|
+
/**
|
|
94
|
+
* A relationship that is either BelongsTo (bi-directional to parent) or OwnedBy (uni directional to parent)
|
|
95
|
+
*/
|
|
96
|
+
export type BelongsToOrOwnedByRelationship = BelongsToRelationship | OwnedByRelationship;
|
|
94
97
|
//# sourceMappingURL=types.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../../src/metadata/types.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,0BAA0B,EAAE,MAAM,wBAAwB,CAAC;AACzE,OAAO,KAAK,EACV,iBAAiB,EACjB,cAAc,EACd,iBAAiB,EACjB,oBAAoB,EACpB,aAAa,EACd,MAAM,GAAG,CAAC;AACX,OAAO,KAAK,UAAU,MAAM,eAAe,CAAC;AAC5C,OAAO,KAAK,EAAE,
|
|
1
|
+
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../../src/metadata/types.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,0BAA0B,EAAE,MAAM,wBAAwB,CAAC;AACzE,OAAO,KAAK,EACV,iBAAiB,EACjB,qBAAqB,EACrB,cAAc,EACd,iBAAiB,EACjB,mBAAmB,EACnB,oBAAoB,EACpB,aAAa,EACd,MAAM,GAAG,CAAC;AACX,OAAO,KAAK,UAAU,MAAM,eAAe,CAAC;AAC5C,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,UAAU,CAAC;AAC7C,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,KAAK,CAAC;AAEnC;;GAEG;AACH,MAAM,MAAM,kCAAkC,GAAG,OAAO,CACtD,oBAAoB,EACpB;IAAE,UAAU,EAAE,MAAM,UAAU,CAAA;CAAE,CACjC,CAAC;AAEF;;GAEG;AACH,MAAM,MAAM,wBAAwB,GAAG,MAAM,CAAC,MAAM,EAAE,iBAAiB,CAAC,CAAC;AAEzE;;GAEG;AACH,MAAM,MAAM,2BAA2B,GAAG,MAAM,CAAC,MAAM,EAAE,oBAAoB,CAAC,CAAC;AAE/E;;GAEG;AACH,MAAM,MAAM,oBAAoB,GAAG,MAAM,CAAC,MAAM,EAAE,aAAa,CAAC,CAAC;AAEjE;;GAEG;AACH,MAAM,MAAM,qBAAqB,GAAG,MAAM,CAAC,MAAM,EAAE,cAAc,CAAC,CAAC;AAEnE;;GAEG;AACH,MAAM,MAAM,wBAAwB,GAAG,MAAM,CAAC,MAAM,EAAE,iBAAiB,EAAE,CAAC,CAAC;AAE3E;;GAEG;AACH,MAAM,MAAM,iBAAiB,GAAG,WAAW,GAAG,WAAW,CAAC;AAE1D;;GAEG;AACH,MAAM,MAAM,aAAa,GAAG;KACzB,CAAC,IAAI,MAAM,UAAU,GAAG,UAAU,CAAC,CAAC,CAAC,SAAS,CAAC,GAAG,IAAI,EAAE,GAAG,EAAE,KAAK,GAAG,GAClE,KAAK,GACL,CAAC;CACN,CAAC,MAAM,UAAU,CAAC,CAAC;AAEpB;;GAEG;AACH,MAAM,MAAM,kBAAkB,GAAG,MAAM,CACrC,aAAa,EACb,IAAI,CAAC,iBAAiB,EAAE,OAAO,CAAC,CACjC,CAAC;AAEF;;GAEG;AACH,MAAM,MAAM,oBAAoB,GAAG,IAAI,CAAC,aAAa,EAAE,MAAM,GAAG,WAAW,CAAC,GAAG;IAC7E,aAAa,CAAC,EAAE,OAAO,CAAC,kBAAkB,CAAC,CAAC;CAC7C,CAAC;AAEF;;GAEG;AACH,MAAM,MAAM,4BAA4B,GAAG,YAAY,CACrD,IAAI,CAAC,wBAAwB,EAAE,UAAU,CAAC,EAC1C,OAAO,CACR,CAAC;AAEF;;GAEG;AACH,MAAM,MAAM,gBAAgB,GAAG,CAAC,KAAK,EAAE,0BAA0B,KAAK,GAAG,CAAC;AAE1E;;GAEG;AACH,MAAM,MAAM,eAAe,GAAG,CAAC,KAAK,EAAE,GAAG,KAAK,0BAA0B,CAAC;AAEzE;;;GAGG;AACH,MAAM,WAAW,WAAW;IAC1B;;OAEG;IACH,iBAAiB,EAAE,gBAAgB,CAAC;IACpC;;OAEG;IACH,gBAAgB,EAAE,eAAe,CAAC;CACnC;AAED;;;;;;;GAOG;AACH,MAAM,WAAW,wBAAwB;IACvC,aAAa,EAAE,MAAM,CAAC;IACtB,IAAI,EAAE,OAAO,CAAC;IACd,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,QAAQ,CAAC,EAAE,OAAO,CAAC;IACnB,WAAW,CAAC,EAAE,WAAW,CAAC;CAC3B;AAED;;GAEG;AACH,MAAM,MAAM,8BAA8B,GACtC,qBAAqB,GACrB,mBAAmB,CAAC"}
|
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import type { RelationshipMetadata, HasManyRelationship, BelongsToRelationship, HasOneRelationship, HasAndBelongsToManyRelationship } from ".";
|
|
1
|
+
import type { RelationshipMetadata, HasManyRelationship, BelongsToRelationship, HasOneRelationship, HasAndBelongsToManyRelationship, OwnedByRelationship } from ".";
|
|
2
2
|
import type DynaRecord from "../DynaRecord";
|
|
3
|
-
import type { RelationshipMetadataWithForeignKey } from "./types";
|
|
3
|
+
import type { BelongsToOrOwnedByRelationship, RelationshipMetadataWithForeignKey } from "./types";
|
|
4
4
|
import type { EntityClass } from "../types";
|
|
5
5
|
/**
|
|
6
6
|
* Type guard to check if the relationship is a HasMany
|
|
@@ -18,6 +18,10 @@ export declare const isHasOneRelationship: (rel: RelationshipMetadata) => rel is
|
|
|
18
18
|
* Type guard to check if the relationship is a HasOne
|
|
19
19
|
*/
|
|
20
20
|
export declare const isHasAndBelongsToManyRelationship: (rel: RelationshipMetadata) => rel is HasAndBelongsToManyRelationship;
|
|
21
|
+
/**
|
|
22
|
+
* Type guard to check if the relationship is of type OwnedBy
|
|
23
|
+
*/
|
|
24
|
+
export declare const isOwnedByRelationship: (rel: RelationshipMetadata) => rel is OwnedByRelationship;
|
|
21
25
|
/**
|
|
22
26
|
* Type guard to check if the relationship metadata includes a foreignKey
|
|
23
27
|
* @param rel
|
|
@@ -30,7 +34,7 @@ export declare const isRelationshipMetadataWithForeignKey: (rel: RelationshipMet
|
|
|
30
34
|
* @param rel
|
|
31
35
|
* @returns
|
|
32
36
|
*/
|
|
33
|
-
export declare const doesEntityBelongToRelAsHasOne: <T extends DynaRecord>(Entity: EntityClass<T>, rel:
|
|
37
|
+
export declare const doesEntityBelongToRelAsHasOne: <T extends DynaRecord>(Entity: EntityClass<T>, rel: BelongsToOrOwnedByRelationship) => boolean;
|
|
34
38
|
/**
|
|
35
39
|
* Returns true if an "Entity" BelongsTo the provided relationship as a HasMany
|
|
36
40
|
* @param Entity
|
|
@@ -38,5 +42,5 @@ export declare const doesEntityBelongToRelAsHasOne: <T extends DynaRecord>(Entit
|
|
|
38
42
|
* @param foreignKey
|
|
39
43
|
* @returns
|
|
40
44
|
*/
|
|
41
|
-
export declare const doesEntityBelongToRelAsHasMany: <T extends DynaRecord>(Entity: EntityClass<T>, rel:
|
|
45
|
+
export declare const doesEntityBelongToRelAsHasMany: <T extends DynaRecord>(Entity: EntityClass<T>, rel: BelongsToOrOwnedByRelationship) => boolean;
|
|
42
46
|
//# sourceMappingURL=utils.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"utils.d.ts","sourceRoot":"","sources":["../../../src/metadata/utils.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EACV,oBAAoB,EACpB,mBAAmB,EACnB,qBAAqB,EACrB,kBAAkB,EAClB,+BAA+B,
|
|
1
|
+
{"version":3,"file":"utils.d.ts","sourceRoot":"","sources":["../../../src/metadata/utils.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EACV,oBAAoB,EACpB,mBAAmB,EACnB,qBAAqB,EACrB,kBAAkB,EAClB,+BAA+B,EAC/B,mBAAmB,EACpB,MAAM,GAAG,CAAC;AACX,OAAO,KAAK,UAAU,MAAM,eAAe,CAAC;AAC5C,OAAO,KAAK,EACV,8BAA8B,EAC9B,kCAAkC,EACnC,MAAM,SAAS,CAAC;AACjB,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,UAAU,CAAC;AAE5C;;GAEG;AACH,eAAO,MAAM,qBAAqB,QAC3B,oBAAoB,KACxB,GAAG,IAAI,mBAET,CAAC;AAEF;;GAEG;AACH,eAAO,MAAM,uBAAuB,QAC7B,oBAAoB,KACxB,GAAG,IAAI,qBAET,CAAC;AAEF;;GAEG;AACH,eAAO,MAAM,oBAAoB,QAC1B,oBAAoB,KACxB,GAAG,IAAI,kBAET,CAAC;AAEF;;GAEG;AACH,eAAO,MAAM,iCAAiC,QACvC,oBAAoB,KACxB,GAAG,IAAI,+BAET,CAAC;AAEF;;GAEG;AACH,eAAO,MAAM,qBAAqB,QAC3B,oBAAoB,KACxB,GAAG,IAAI,mBAET,CAAC;AAEF;;;;GAIG;AACH,eAAO,MAAM,oCAAoC,QAC1C,oBAAoB,KACxB,GAAG,IAAI,kCAET,CAAC;AAEF;;;;;GAKG;AACH,eAAO,MAAM,6BAA6B,GAAI,CAAC,SAAS,UAAU,UACxD,WAAW,CAAC,CAAC,CAAC,OACjB,8BAA8B,KAClC,OAMF,CAAC;AAEF;;;;;;GAMG;AACH,eAAO,MAAM,8BAA8B,GAAI,CAAC,SAAS,UAAU,UACzD,WAAW,CAAC,CAAC,CAAC,OACjB,8BAA8B,KAClC,OAMF,CAAC"}
|
|
@@ -3,7 +3,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
3
3
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
4
|
};
|
|
5
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
-
exports.doesEntityBelongToRelAsHasMany = exports.doesEntityBelongToRelAsHasOne = exports.isRelationshipMetadataWithForeignKey = exports.isHasAndBelongsToManyRelationship = exports.isHasOneRelationship = exports.isBelongsToRelationship = exports.isHasManyRelationship = void 0;
|
|
6
|
+
exports.doesEntityBelongToRelAsHasMany = exports.doesEntityBelongToRelAsHasOne = exports.isRelationshipMetadataWithForeignKey = exports.isOwnedByRelationship = exports.isHasAndBelongsToManyRelationship = exports.isHasOneRelationship = exports.isBelongsToRelationship = exports.isHasManyRelationship = void 0;
|
|
7
7
|
const _1 = __importDefault(require("./"));
|
|
8
8
|
/**
|
|
9
9
|
* Type guard to check if the relationship is a HasMany
|
|
@@ -33,6 +33,13 @@ const isHasAndBelongsToManyRelationship = (rel) => {
|
|
|
33
33
|
return rel.type === "HasAndBelongsToMany" && rel.joinTableName !== undefined;
|
|
34
34
|
};
|
|
35
35
|
exports.isHasAndBelongsToManyRelationship = isHasAndBelongsToManyRelationship;
|
|
36
|
+
/**
|
|
37
|
+
* Type guard to check if the relationship is of type OwnedBy
|
|
38
|
+
*/
|
|
39
|
+
const isOwnedByRelationship = (rel) => {
|
|
40
|
+
return rel.type === "OwnedBy";
|
|
41
|
+
};
|
|
42
|
+
exports.isOwnedByRelationship = isOwnedByRelationship;
|
|
36
43
|
/**
|
|
37
44
|
* Type guard to check if the relationship metadata includes a foreignKey
|
|
38
45
|
* @param rel
|
|
@@ -2,13 +2,22 @@ import type DynaRecord from "../../DynaRecord";
|
|
|
2
2
|
import type { EntityClass } from "../../types";
|
|
3
3
|
import OperationBase from "../OperationBase";
|
|
4
4
|
import type { CreateOptions } from "./types";
|
|
5
|
-
import { type
|
|
5
|
+
import { type EntityAttributesOnly } from "../types";
|
|
6
6
|
/**
|
|
7
|
-
* Represents
|
|
7
|
+
* Represents an operation to create a new entity record in DynamoDB, including all necessary
|
|
8
|
+
* denormalized relationship records. This ensures that "BelongsTo" and "HasMany" relationships
|
|
9
|
+
* are properly maintained at the time of entity creation.
|
|
8
10
|
*
|
|
9
|
-
*
|
|
11
|
+
* **What it does:**
|
|
12
|
+
* - Converts the given attributes into a DynamoDB-compatible format.
|
|
13
|
+
* - Inserts a new entity record, ensuring no duplicate primary key conflicts.
|
|
14
|
+
* - For each "BelongsTo" relationship that includes a foreign key:
|
|
15
|
+
* - Verifies the referenced entity exists.
|
|
16
|
+
* - Creates a denormalized link record in the related entity's partition.
|
|
17
|
+
* - If the entity's relationships imply additional denormalized records in its own partition,
|
|
18
|
+
* those are also created after verifying the related entities exist.
|
|
10
19
|
*
|
|
11
|
-
* Only attributes defined on the model can be
|
|
20
|
+
* Only attributes defined on the entity model can be set, validated both at compile-time and runtime.
|
|
12
21
|
*
|
|
13
22
|
* @template T - The type of the entity being created, extending `DynaRecord`.
|
|
14
23
|
*/
|
|
@@ -16,27 +25,97 @@ declare class Create<T extends DynaRecord> extends OperationBase<T> {
|
|
|
16
25
|
#private;
|
|
17
26
|
constructor(Entity: EntityClass<T>);
|
|
18
27
|
/**
|
|
19
|
-
*
|
|
20
|
-
*
|
|
21
|
-
*
|
|
28
|
+
* Executes the create operation.
|
|
29
|
+
*
|
|
30
|
+
* **What it does:**
|
|
31
|
+
* - Parses and validates the provided attributes against the entity schema.
|
|
32
|
+
* - Generates any required reserved attributes (like `id`, `createdAt`, and `updatedAt`).
|
|
33
|
+
* - Inserts the new entity record into DynamoDB, ensuring it doesn't already exist.
|
|
34
|
+
* - For each defined "BelongsTo" relationship, ensures the related entity exists and creates
|
|
35
|
+
* a corresponding denormalized "link" record.
|
|
36
|
+
* - If the entity's creation implies that related records must also be denormalized into its own
|
|
37
|
+
* partition (due to "BelongsTo" links), retrieves and inserts those link records.
|
|
38
|
+
*
|
|
39
|
+
* @param attributes - Attributes to initialize the new entity. Must be defined on the model and valid per schema constraints.
|
|
40
|
+
* @returns A promise that resolves to the newly created entity with all attributes, including automatically set fields.
|
|
41
|
+
* @throws If the entity already exists, a uniqueness violation error is raised.
|
|
42
|
+
* @throws If a required foreign key does not correspond to an existing entity, an error is raised.
|
|
22
43
|
*/
|
|
23
|
-
run(attributes: CreateOptions<T>): Promise<
|
|
44
|
+
run(attributes: CreateOptions<T>): Promise<EntityAttributesOnly<T>>;
|
|
24
45
|
/**
|
|
25
|
-
* Builds
|
|
26
|
-
*
|
|
27
|
-
*
|
|
46
|
+
* Builds and returns entity attributes that must be reserved for system usage.
|
|
47
|
+
*
|
|
48
|
+
* **What it does:**
|
|
49
|
+
* - Generates a unique entity ID if the entity's schema does not specify an `id` field.
|
|
50
|
+
* - Sets `createdAt` and `updatedAt` to the current time.
|
|
51
|
+
* - Builds the partition and sort key values based on the entity's class and generated ID.
|
|
52
|
+
*
|
|
53
|
+
* @param entityAttrs - The user-provided entity attributes.
|
|
54
|
+
* @returns The combined attributes including all reserved fields.
|
|
55
|
+
* @private
|
|
28
56
|
*/
|
|
29
57
|
private buildReservedAttributes;
|
|
30
58
|
/**
|
|
31
|
-
*
|
|
32
|
-
*
|
|
59
|
+
* Adds a "PutItem" transaction for the new entity record.
|
|
60
|
+
*
|
|
61
|
+
* **What it does:**
|
|
62
|
+
* - Ensures the primary key does not already exist, preventing duplication.
|
|
63
|
+
*
|
|
64
|
+
* @param tableItem - The DynamoDB table item for the entity to put.
|
|
65
|
+
* @param id - The unique identifier of the new entity.
|
|
66
|
+
* @private
|
|
33
67
|
*/
|
|
34
68
|
private buildPutItemTransaction;
|
|
35
69
|
/**
|
|
36
|
-
*
|
|
37
|
-
*
|
|
70
|
+
* Adds "PutItem" transactions to create denormalized "BelongsTo" link records in the related entity's partitions.
|
|
71
|
+
*
|
|
72
|
+
* **What it does:**
|
|
73
|
+
* - For each "BelongsTo" relationship with a defined foreign key, checks that the related entity exists.
|
|
74
|
+
* - Inserts a "link" item into the related entity's partition to maintain denormalized relationships.
|
|
75
|
+
*
|
|
76
|
+
* @param entityData - The complete set of entity attributes for the new entity.
|
|
77
|
+
* @param tableItem - The main entity's DynamoDB table item.
|
|
78
|
+
* @private
|
|
38
79
|
*/
|
|
39
|
-
private
|
|
80
|
+
private buildBelongsToTransactions;
|
|
81
|
+
/**
|
|
82
|
+
* Retrieves the DynamoDB items for all entities that the new entity references via "BelongsTo" relationships.
|
|
83
|
+
*
|
|
84
|
+
* **What it does:**
|
|
85
|
+
* - For each "BelongsTo" relationship, queries DynamoDB for the related entity record.
|
|
86
|
+
* - Returns all found related items as an array.
|
|
87
|
+
* - If no relationships or no foreign keys are present, returns an empty array.
|
|
88
|
+
*
|
|
89
|
+
* @param entityData - The attributes of the entity being created.
|
|
90
|
+
* @returns A promise that resolves to an array of related DynamoDB items.
|
|
91
|
+
* @private
|
|
92
|
+
*/
|
|
93
|
+
private getBelongsToTableItems;
|
|
94
|
+
/**
|
|
95
|
+
* Adds a condition check transaction to ensure that the entity referenced by a "BelongsTo" foreign key exists.
|
|
96
|
+
*
|
|
97
|
+
* **What it does:**
|
|
98
|
+
* - Checks the existence of the related entity before creating the link item.
|
|
99
|
+
* - If the related entity does not exist, the transaction will fail, preventing creation of dangling references.
|
|
100
|
+
*
|
|
101
|
+
* @param rel - The "BelongsTo" relationship metadata.
|
|
102
|
+
* @param relationshipId - The foreign key value referencing the related entity.
|
|
103
|
+
* @private
|
|
104
|
+
*/
|
|
105
|
+
private buildRelationshipExistsConditionTransaction;
|
|
106
|
+
/**
|
|
107
|
+
* For each related entity referenced by a "BelongsTo" relationship, insert a denormalized copy of that entity
|
|
108
|
+
* into the new entity's partition. This maintains a consistent, denormalized view of relationships.
|
|
109
|
+
*
|
|
110
|
+
* **What it does:**
|
|
111
|
+
* - Adds "PutItem" operations to create link records in the newly created entity's partition.
|
|
112
|
+
* - Ensures these link records don't already exist.
|
|
113
|
+
*
|
|
114
|
+
* @param entityId - The newly created entity's ID.
|
|
115
|
+
* @param belongsToTableItems - The table items representing each related "BelongsTo" entity.
|
|
116
|
+
* @private
|
|
117
|
+
*/
|
|
118
|
+
private buildAddBelongsToLinkToSelfTransactions;
|
|
40
119
|
}
|
|
41
120
|
export default Create;
|
|
42
121
|
//# sourceMappingURL=Create.d.ts.map
|
|
@@ -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;
|
|
1
|
+
{"version":3,"file":"Create.d.ts","sourceRoot":"","sources":["../../../../src/operations/Create/Create.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,UAAU,MAAM,kBAAkB,CAAC;AAE/C,OAAO,KAAK,EAAmB,WAAW,EAAE,MAAM,aAAa,CAAC;AAOhE,OAAO,aAAa,MAAM,kBAAkB,CAAC;AAE7C,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,SAAS,CAAC;AAC7C,OAAO,EAGL,KAAK,oBAAoB,EAC1B,MAAM,UAAU,CAAC;AAIlB;;;;;;;;;;;;;;;;;GAiBG;AACH,cAAM,MAAM,CAAC,CAAC,SAAS,UAAU,CAAE,SAAQ,aAAa,CAAC,CAAC,CAAC;;gBAG7C,MAAM,EAAE,WAAW,CAAC,CAAC,CAAC;IAKlC;;;;;;;;;;;;;;;;OAgBG;IACU,GAAG,CACd,UAAU,EAAE,aAAa,CAAC,CAAC,CAAC,GAC3B,OAAO,CAAC,oBAAoB,CAAC,CAAC,CAAC,CAAC;IA4BnC;;;;;;;;;;;OAWG;IACH,OAAO,CAAC,uBAAuB;IA8B/B;;;;;;;;;OASG;IACH,OAAO,CAAC,uBAAuB;IAiB/B;;;;;;;;;;OAUG;IACH,OAAO,CAAC,0BAA0B;IAkClC;;;;;;;;;;;OAWG;YACW,sBAAsB;IAmCpC;;;;;;;;;;OAUG;IACH,OAAO,CAAC,2CAA2C;IAmBnD;;;;;;;;;;;OAWG;IACH,OAAO,CAAC,uCAAuC;CA0BhD;AAED,eAAe,MAAM,CAAC"}
|