dyna-record 0.2.0 → 0.2.2
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 +21 -0
- 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/metadata/EntityMetadata.d.ts +10 -2
- package/dist/src/metadata/EntityMetadata.d.ts.map +1 -1
- package/dist/src/metadata/EntityMetadata.js +13 -1
- 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 +3 -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 +5 -1
- 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.map +1 -1
- package/dist/src/operations/Create/Create.js +2 -1
- package/dist/src/operations/Delete/Delete.d.ts +5 -0
- package/dist/src/operations/Delete/Delete.d.ts.map +1 -1
- package/dist/src/operations/Delete/Delete.js +16 -0
- package/dist/src/operations/Update/Update.d.ts +2 -2
- package/dist/src/operations/Update/Update.d.ts.map +1 -1
- package/dist/src/operations/Update/Update.js +17 -10
- package/dist/src/operations/utils/utils.d.ts +2 -2
- package/dist/src/operations/utils/utils.d.ts.map +1 -1
- package/package.json +2 -2
package/README.md
CHANGED
|
@@ -264,6 +264,27 @@ class Course extends MyTable {
|
|
|
264
264
|
}
|
|
265
265
|
```
|
|
266
266
|
|
|
267
|
+
By default, a HasMany relationship is bi-directional—records are denormalized into both the parent and child entity partitions. This setup supports access patterns that allow each entity to retrieve its associated records. However, updating a HasMany entity requires updating its denormalized record in every associated partition, which can lead to issues given DynamoDB's 100-item transaction limit.
|
|
268
|
+
|
|
269
|
+
To mitigate this, you can specify uniDirectional in the HasMany decorator and remove the BelongsTo relationship from the child entity. With this configuration, only the parent-to-child access pattern is supported.
|
|
270
|
+
|
|
271
|
+
```typescript
|
|
272
|
+
import { Entity, NullableForeignKey, BelongsTo, HasMany } from "dyna-record";
|
|
273
|
+
|
|
274
|
+
@Entity
|
|
275
|
+
class Teacher extends MyTable {
|
|
276
|
+
// 'teacherId' must be defined on associated model
|
|
277
|
+
@HasMany(() => Course, { foreignKey: "teacherId", uniDirectional: true })
|
|
278
|
+
public readonly courses: Course[];
|
|
279
|
+
}
|
|
280
|
+
|
|
281
|
+
@Entity
|
|
282
|
+
class Course extends MyTable {
|
|
283
|
+
@ForeignKeyAttribute({ nullable: true })
|
|
284
|
+
public readonly teacherId?: NullableForeignKey; // Mark as optional
|
|
285
|
+
}
|
|
286
|
+
```
|
|
287
|
+
|
|
267
288
|
### HasAndBelongsToMany
|
|
268
289
|
|
|
269
290
|
[Docs](https://dyna-record.com/functions/HasAndBelongsToMany.html)
|
|
@@ -3,6 +3,13 @@ import type { EntityClass } from "../../types";
|
|
|
3
3
|
import { type ForeignEntityAttribute } from "../types";
|
|
4
4
|
interface HasManyProps<T extends DynaRecord> {
|
|
5
5
|
foreignKey: ForeignEntityAttribute<T>;
|
|
6
|
+
/**
|
|
7
|
+
* Specifies whether the relationship is unidirectional. When set to `true`, the relationship supports access patterns in only one direction, reducing denormalized data.
|
|
8
|
+
* This is useful when bidirectional access patterns are unnecessary.
|
|
9
|
+
*
|
|
10
|
+
* @default false
|
|
11
|
+
*/
|
|
12
|
+
uniDirectional?: boolean;
|
|
6
13
|
}
|
|
7
14
|
/**
|
|
8
15
|
* A decorator for establishing a one-to-many relationship between entities in a single-table design ORM system. This relationship indicates that a single instance of the entity where this decorator is applied can be associated with multiple instances of another entity. The decorator facilitates the definition and management of such relationships by automatically handling the necessary metadata registration, thereby simplifying the implementation of relational data models.
|
|
@@ -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;
|
|
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;IAEtC;;;;;OAKG;IACH,cAAc,CAAC,EAAE,OAAO,CAAC;CAC1B;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,0BAA0B,CAAC,CAAC,EAAE,CAAC,EAAE,CAAC,UAwBvE;AAED,eAAe,OAAO,CAAC"}
|
|
@@ -34,11 +34,21 @@ function HasMany(getTarget, props) {
|
|
|
34
34
|
return (_value, context) => {
|
|
35
35
|
if (context.kind === "field") {
|
|
36
36
|
context.addInitializer(function () {
|
|
37
|
+
const target = getTarget();
|
|
38
|
+
if (props.uniDirectional === true) {
|
|
39
|
+
metadata_1.default.addEntityRelationship(target.name, {
|
|
40
|
+
type: "OwnedBy",
|
|
41
|
+
propertyName: props.foreignKey,
|
|
42
|
+
foreignKey: props.foreignKey,
|
|
43
|
+
target: this.constructor
|
|
44
|
+
});
|
|
45
|
+
}
|
|
37
46
|
metadata_1.default.addEntityRelationship(this.constructor.name, {
|
|
38
47
|
type: "HasMany",
|
|
39
48
|
propertyName: context.name,
|
|
40
|
-
target
|
|
41
|
-
foreignKey: props.foreignKey
|
|
49
|
+
target,
|
|
50
|
+
foreignKey: props.foreignKey,
|
|
51
|
+
uniDirectional: props.uniDirectional
|
|
42
52
|
});
|
|
43
53
|
});
|
|
44
54
|
}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import type { BelongsToRelationship, HasRelationships, AttributeMetadata, AttributeMetadataStorage, RelationshipMetadataStorage, RelationshipMetadata } from ".";
|
|
1
|
+
import type { BelongsToRelationship, HasRelationships, AttributeMetadata, AttributeMetadataStorage, RelationshipMetadataStorage, RelationshipMetadata, OwnedByRelationship, BelongsToOrOwnedByRelationship } from ".";
|
|
2
2
|
import type DynaRecord from "../DynaRecord";
|
|
3
3
|
import { type EntityDefinedAttributes } from "../operations";
|
|
4
4
|
type EntityClass = new (...args: any) => DynaRecord;
|
|
@@ -68,9 +68,17 @@ declare class EntityMetadata {
|
|
|
68
68
|
*/
|
|
69
69
|
get allRelationships(): RelationshipMetadata[];
|
|
70
70
|
/**
|
|
71
|
-
* Returns the BelongsToRelationship metadata for the entity
|
|
71
|
+
* Returns the BelongsToRelationship (bidirectional to parent) metadata for the entity
|
|
72
72
|
*/
|
|
73
73
|
get belongsToRelationships(): BelongsToRelationship[];
|
|
74
|
+
/**
|
|
75
|
+
* Returns the OwnedByRelationship (unidirectional to parent) relationship metadata for an entity
|
|
76
|
+
*/
|
|
77
|
+
get ownedByRelationships(): OwnedByRelationship[];
|
|
78
|
+
/**
|
|
79
|
+
* Returns the BelongsToRelationship and OwnedByRelationship metadata objects for an entity
|
|
80
|
+
*/
|
|
81
|
+
get belongsToOrOwnedByRelationships(): BelongsToOrOwnedByRelationship[];
|
|
74
82
|
/**
|
|
75
83
|
* Returns the "Has" relationship metadata for the entity (EX: "HasMany")
|
|
76
84
|
*/
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"EntityMetadata.d.ts","sourceRoot":"","sources":["../../../src/metadata/EntityMetadata.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EACV,qBAAqB,EACrB,gBAAgB,EAChB,iBAAiB,EACjB,wBAAwB,EACxB,2BAA2B,EAC3B,oBAAoB,
|
|
1
|
+
{"version":3,"file":"EntityMetadata.d.ts","sourceRoot":"","sources":["../../../src/metadata/EntityMetadata.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EACV,qBAAqB,EACrB,gBAAgB,EAChB,iBAAiB,EACjB,wBAAwB,EACxB,2BAA2B,EAC3B,oBAAoB,EACpB,mBAAmB,EACnB,8BAA8B,EAC/B,MAAM,GAAG,CAAC;AACX,OAAO,KAAK,UAAU,MAAM,eAAe,CAA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ata {
|
|
|
124
124
|
return Object.values(this.relationships);
|
|
125
125
|
}
|
|
126
126
|
/**
|
|
127
|
-
* Returns the BelongsToRelationship metadata for the entity
|
|
127
|
+
* Returns the BelongsToRelationship (bidirectional to parent) metadata for the entity
|
|
128
128
|
*/
|
|
129
129
|
get belongsToRelationships() {
|
|
130
130
|
return Object.values(this.relationships).filter(rel => (0, utils_1.isBelongsToRelationship)(rel));
|
|
131
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
|
+
}
|
|
132
144
|
/**
|
|
133
145
|
* Returns the "Has" relationship metadata for the entity (EX: "HasMany")
|
|
134
146
|
*/
|
|
@@ -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,9 +11,9 @@ 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;
|
|
16
17
|
/**
|
|
17
18
|
* An array of "Has" relationships (EX: "HasMany")
|
|
18
19
|
*/
|
|
@@ -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,5 +1,5 @@
|
|
|
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
4
|
import type { MakeOptional } from "../types";
|
|
5
5
|
import type { ZodType } from "zod";
|
|
@@ -90,4 +90,8 @@ export interface AttributeMetadataOptions {
|
|
|
90
90
|
nullable?: boolean;
|
|
91
91
|
serializers?: Serializers;
|
|
92
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;
|
|
93
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,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,CA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AAM,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
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Create.d.ts","sourceRoot":"","sources":["../../../../src/operations/Create/Create.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,UAAU,MAAM,kBAAkB,CAAC;AAE/C,OAAO,KAAK,EAAmB,WAAW,EAAE,MAAM,aAAa,CAAC;AAOhE,OAAO,aAAa,MAAM,kBAAkB,CAAC;AAE7C,OAAO,KAAK,EAAE,aAAa,EAAE,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;
|
|
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"}
|
|
@@ -130,7 +130,8 @@ class Create extends OperationBase_1.default {
|
|
|
130
130
|
*/
|
|
131
131
|
buildBelongsToTransactions(entityData, tableItem) {
|
|
132
132
|
const tableName = this.tableMetadata.name;
|
|
133
|
-
|
|
133
|
+
const relMetadata = this.entityMetadata.belongsToOrOwnedByRelationships;
|
|
134
|
+
for (const relMeta of relMetadata) {
|
|
134
135
|
const foreignKey = (0, utils_2.extractForeignKeyFromEntity)(relMeta, entityData);
|
|
135
136
|
if (foreignKey !== undefined) {
|
|
136
137
|
// Ensure referenced entity exists before linking
|
|
@@ -67,6 +67,11 @@ declare class Delete<T extends DynaRecord> extends OperationBase<T> {
|
|
|
67
67
|
* @param item - Denormalized record from HasAndBelongsToMany relationship
|
|
68
68
|
*/
|
|
69
69
|
private buildDeleteJoinTableLinkTransaction;
|
|
70
|
+
/**
|
|
71
|
+
* If the entity being deleted is owned by another entity via a unidirectional relationship, delete the denormalized records
|
|
72
|
+
* @param self - The entity being deleted
|
|
73
|
+
*/
|
|
74
|
+
private buildDeleteOwnedByRelationships;
|
|
70
75
|
/**
|
|
71
76
|
* Track validation errors and throw AggregateError after all validations have been run
|
|
72
77
|
* @param err
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Delete.d.ts","sourceRoot":"","sources":["../../../../src/operations/Delete/Delete.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,UAAU,MAAM,kBAAkB,CAAC;AAY/C,OAAO,KAAK,EAEV,WAAW,EAEZ,MAAM,aAAa,CAAC;AAErB,OAAO,aAAa,MAAM,kBAAkB,CAAC;AA2B7C;;;;;;;;;GASG;AACH,cAAM,MAAM,CAAC,CAAC,SAAS,UAAU,CAAE,SAAQ,aAAa,CAAC,CAAC,CAAC;;gBAS7C,MAAM,EAAE,WAAW,CAAC,CAAC,CAAC;IAiBlC;;;;;;;OAOG;IACU,GAAG,CAAC,EAAE,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC;
|
|
1
|
+
{"version":3,"file":"Delete.d.ts","sourceRoot":"","sources":["../../../../src/operations/Delete/Delete.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,UAAU,MAAM,kBAAkB,CAAC;AAY/C,OAAO,KAAK,EAEV,WAAW,EAEZ,MAAM,aAAa,CAAC;AAErB,OAAO,aAAa,MAAM,kBAAkB,CAAC;AA2B7C;;;;;;;;;GASG;AACH,cAAM,MAAM,CAAC,CAAC,SAAS,UAAU,CAAE,SAAQ,aAAa,CAAC,CAAC,CAAC;;gBAS7C,MAAM,EAAE,WAAW,CAAC,CAAC,CAAC;IAiBlC;;;;;;;OAOG;IACU,GAAG,CAAC,EAAE,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC;IAgC3C;;;;OAIG;YACW,QAAQ;IA+BtB;;;;OAIG;IACH,OAAO,CAAC,iCAAiC;IASzC;;;OAGG;IACH,OAAO,CAAC,2BAA2B;IAOnC;;;OAGG;IACH,OAAO,CAAC,0BAA0B;IAalC;;;OAGG;IACH,OAAO,CAAC,4BAA4B;IAkBpC;;;;OAIG;YACW,iCAAiC;IA2B/C;;;;OAIG;IACH,OAAO,CAAC,uCAAuC;IA2B/C;;;OAGG;IACH,OAAO,CAAC,mCAAmC;IAiB3C;;;OAGG;IACH,OAAO,CAAC,+BAA+B;IAqBvC;;;OAGG;IACH,OAAO,CAAC,oBAAoB;IAI5B,OAAO,CAAC,cAAc;CAcvB;AAED,eAAe,MAAM,CAAC"}
|
|
@@ -57,6 +57,7 @@ class Delete extends OperationBase_1.default {
|
|
|
57
57
|
});
|
|
58
58
|
this.buildDeleteJoinTableLinkTransaction(item);
|
|
59
59
|
});
|
|
60
|
+
this.buildDeleteOwnedByRelationships(preFetchRes.self);
|
|
60
61
|
await Promise.all(preFetchRes.linkedEntitiesWithFkRef.map(async (entity) => {
|
|
61
62
|
await this.buildNullifyForeignKeyTransaction(entity);
|
|
62
63
|
}));
|
|
@@ -188,6 +189,21 @@ class Delete extends OperationBase_1.default {
|
|
|
188
189
|
});
|
|
189
190
|
}
|
|
190
191
|
}
|
|
192
|
+
/**
|
|
193
|
+
* If the entity being deleted is owned by another entity via a unidirectional relationship, delete the denormalized records
|
|
194
|
+
* @param self - The entity being deleted
|
|
195
|
+
*/
|
|
196
|
+
buildDeleteOwnedByRelationships(self) {
|
|
197
|
+
this.entityMetadata.ownedByRelationships.forEach(ownedByRelMeta => {
|
|
198
|
+
if ((0, utils_2.isKeyOfObject)(self, ownedByRelMeta.foreignKey)) {
|
|
199
|
+
const fkValue = self[ownedByRelMeta.foreignKey];
|
|
200
|
+
const keys = (0, utils_3.buildBelongsToLinkKey)(this.EntityClass, self.id, ownedByRelMeta, fkValue);
|
|
201
|
+
this.buildDeleteItemTransaction(keys, {
|
|
202
|
+
errorMessage: `Failed to delete denormalized record with keys: ${JSON.stringify(keys)}`
|
|
203
|
+
});
|
|
204
|
+
}
|
|
205
|
+
});
|
|
206
|
+
}
|
|
191
207
|
/**
|
|
192
208
|
* Track validation errors and throw AggregateError after all validations have been run
|
|
193
209
|
* @param err
|
|
@@ -98,10 +98,10 @@ declare class Update<T extends DynaRecord> extends OperationBase<T> {
|
|
|
98
98
|
*/
|
|
99
99
|
private buildUpdateItemTransaction;
|
|
100
100
|
/**
|
|
101
|
-
* Builds all necessary transactions to handle "BelongsTo" relationships when updating the entity.
|
|
101
|
+
* Builds all necessary transactions to handle "BelongsTo" or uni-directional "OwnedBy" relationships when updating the entity.
|
|
102
102
|
*
|
|
103
103
|
* **What it does:**
|
|
104
|
-
* - Checks if any foreign keys for "BelongsTo" relationships have changed.
|
|
104
|
+
* - Checks if any foreign keys for "BelongsTo" or uni-directional "OwnedBy" relationships have changed.
|
|
105
105
|
* - If so, updates or creates new denormalized link records in the related partitions.
|
|
106
106
|
* - Removes old link records that are no longer valid due to foreign key changes.
|
|
107
107
|
*
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Update.d.ts","sourceRoot":"","sources":["../../../../src/operations/Update/Update.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,UAAU,MAAM,kBAAkB,CAAC;AAC/C,OAAO,EAGL,oBAAoB,EACrB,MAAM,oBAAoB,CAAC;
|
|
1
|
+
{"version":3,"file":"Update.d.ts","sourceRoot":"","sources":["../../../../src/operations/Update/Update.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,UAAU,MAAM,kBAAkB,CAAC;AAC/C,OAAO,EAGL,oBAAoB,EACrB,MAAM,oBAAoB,CAAC;AAkB5B,OAAO,aAAa,MAAM,kBAAkB,CAAC;AAC7C,OAAO,KAAK,EAAE,iBAAiB,EAAE,aAAa,EAAE,MAAM,SAAS,CAAC;AAChE,O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AGG;IACH,OAAO,CAAC,iCAAiC;CAU1C;AAED,eAAe,MAAM,CAAC"}
|
|
@@ -9,6 +9,7 @@ const utils_2 = require("../utils");
|
|
|
9
9
|
const OperationBase_1 = __importDefault(require("../OperationBase"));
|
|
10
10
|
const metadata_1 = __importDefault(require("../../metadata"));
|
|
11
11
|
const errors_1 = require("../../errors");
|
|
12
|
+
const utils_3 = require("../../metadata/utils");
|
|
12
13
|
/**
|
|
13
14
|
* Represents an update operation for a DynaRecord-backed entity, handling both attribute updates and relationship consistency via denormalization.
|
|
14
15
|
*
|
|
@@ -102,7 +103,7 @@ class Update extends OperationBase_1.default {
|
|
|
102
103
|
* @private
|
|
103
104
|
*/
|
|
104
105
|
async preFetch(id, belongsToRelFkAndMetas) {
|
|
105
|
-
const hasRelMetas = this.entityMetadata.hasRelationships;
|
|
106
|
+
const hasRelMetas = this.entityMetadata.hasRelationships.filter(rel => !(0, utils_3.isHasManyRelationship)(rel) || rel.uniDirectional !== true);
|
|
106
107
|
const { name: tableName } = this.tableMetadata;
|
|
107
108
|
const transactionBuilder = new dynamo_utils_1.TransactGetBuilder();
|
|
108
109
|
// Get the new BelongsTo relationship entities that are being updated
|
|
@@ -218,10 +219,10 @@ class Update extends OperationBase_1.default {
|
|
|
218
219
|
}, `${this.EntityClass.name} with ID '${id}' does not exist`);
|
|
219
220
|
}
|
|
220
221
|
/**
|
|
221
|
-
* Builds all necessary transactions to handle "BelongsTo" relationships when updating the entity.
|
|
222
|
+
* Builds all necessary transactions to handle "BelongsTo" or uni-directional "OwnedBy" relationships when updating the entity.
|
|
222
223
|
*
|
|
223
224
|
* **What it does:**
|
|
224
|
-
* - Checks if any foreign keys for "BelongsTo" relationships have changed.
|
|
225
|
+
* - Checks if any foreign keys for "BelongsTo" or uni-directional "OwnedBy" relationships have changed.
|
|
225
226
|
* - If so, updates or creates new denormalized link records in the related partitions.
|
|
226
227
|
* - Removes old link records that are no longer valid due to foreign key changes.
|
|
227
228
|
*
|
|
@@ -232,7 +233,8 @@ class Update extends OperationBase_1.default {
|
|
|
232
233
|
*/
|
|
233
234
|
buildBelongsToTransactions(entityPreUpdate, updatedEntity, updateExpression, newBelongsToEntityLookup) {
|
|
234
235
|
const entityId = entityPreUpdate.id;
|
|
235
|
-
|
|
236
|
+
const relMetas = this.entityMetadata.belongsToOrOwnedByRelationships;
|
|
237
|
+
for (const relMeta of relMetas) {
|
|
236
238
|
const foreignKey = (0, utils_2.extractForeignKeyFromEntity)(relMeta, updatedEntity);
|
|
237
239
|
const isUpdatingRelationshipId = foreignKey !== undefined;
|
|
238
240
|
if (isUpdatingRelationshipId && (0, utils_1.isNullableString)(foreignKey)) {
|
|
@@ -295,8 +297,10 @@ class Update extends OperationBase_1.default {
|
|
|
295
297
|
this.buildEntityExistsCondition(relMeta, foreignKey);
|
|
296
298
|
// Denormalize entity being updated to foreign partition
|
|
297
299
|
this.buildLinkToForeignEntityTransaction(updatedEntity, relMeta, foreignKey);
|
|
298
|
-
|
|
299
|
-
|
|
300
|
+
if ((0, utils_3.isBelongsToRelationship)(relMeta)) {
|
|
301
|
+
// Add denormalized record for new entity to self
|
|
302
|
+
this.buildAddForeignEntityToSelfTransaction(updatedEntity, relMeta, foreignKey, newBelongsToEntityLookup, persistToSelfCondition, persistToSelfConditionErrMessage);
|
|
303
|
+
}
|
|
300
304
|
}
|
|
301
305
|
/**
|
|
302
306
|
* Builds a condition expression that an entity exists
|
|
@@ -374,10 +378,13 @@ class Update extends OperationBase_1.default {
|
|
|
374
378
|
};
|
|
375
379
|
// Keys to delete the linked record from the foreign entities partition
|
|
376
380
|
const oldKeysToForeignEntity = (0, utils_2.buildBelongsToLinkKey)(this.EntityClass, entityId, relMeta, oldForeignKey);
|
|
377
|
-
|
|
378
|
-
|
|
379
|
-
|
|
380
|
-
|
|
381
|
+
// OwnedByRelationships do not have a record to delete from their own partition because its unidirectional
|
|
382
|
+
if ((0, utils_3.isBelongsToRelationship)(relMeta)) {
|
|
383
|
+
this.transactionBuilder.addDelete({
|
|
384
|
+
TableName: this.tableMetadata.name,
|
|
385
|
+
Key: oldKeysToSelf
|
|
386
|
+
}, `Failed to delete denormalized record with keys: ${JSON.stringify(oldKeysToSelf)}`);
|
|
387
|
+
}
|
|
381
388
|
this.transactionBuilder.addDelete({
|
|
382
389
|
TableName: this.tableMetadata.name,
|
|
383
390
|
Key: oldKeysToForeignEntity
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import type DynaRecord from "../../DynaRecord";
|
|
2
|
-
import type {
|
|
2
|
+
import type { BelongsToOrOwnedByRelationship, RelationshipMetadata } from "../../metadata";
|
|
3
3
|
import type { DynamoTableItem, EntityClass, ForeignKey, Optional, RelationshipMetaObj } from "../../types";
|
|
4
4
|
import { type EntityAttributesOnly } from "../types";
|
|
5
5
|
/**
|
|
@@ -25,5 +25,5 @@ export declare const extractForeignKeyFromEntity: <T extends Partial<EntityAttri
|
|
|
25
25
|
* @param foreignKey
|
|
26
26
|
* @returns
|
|
27
27
|
*/
|
|
28
|
-
export declare const buildBelongsToLinkKey: (entityClass: EntityClass<DynaRecord>, entityId: string, relMeta:
|
|
28
|
+
export declare const buildBelongsToLinkKey: (entityClass: EntityClass<DynaRecord>, entityId: string, relMeta: BelongsToOrOwnedByRelationship, foreignKey: string) => DynamoTableItem;
|
|
29
29
|
//# sourceMappingURL=utils.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"utils.d.ts","sourceRoot":"","sources":["../../../../src/operations/utils/utils.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,UAAU,MAAM,kBAAkB,CAAC;AAC/C,OAAO,KAAK,EACV,
|
|
1
|
+
{"version":3,"file":"utils.d.ts","sourceRoot":"","sources":["../../../../src/operations/utils/utils.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,UAAU,MAAM,kBAAkB,CAAC;AAC/C,OAAO,KAAK,EACV,8BAA8B,EAC9B,oBAAoB,EACrB,MAAM,gBAAgB,CAAC;AAQxB,OAAO,KAAK,EACV,eAAe,EACf,WAAW,EACX,UAAU,EACV,QAAQ,EACR,mBAAmB,EACpB,MAAM,aAAa,CAAC;AAErB,OAAO,EAAE,KAAK,oBAAoB,EAAE,MAAM,UAAU,CAAC;AAErD;;;;;;GAMG;AACH,eAAO,MAAM,8BAA8B,kBAC1B,oBAAoB,EAAE,KACpC,mBAaF,CAAC;AAEF;;;;;GAKG;AACH,eAAO,MAAM,2BAA2B,GACtC,CAAC,SAAS,OAAO,CAAC,oBAAoB,CAAC,UAAU,CAAC,CAAC,WAE1C,oBAAoB,UACrB,CAAC,KACR,QAAQ,CAAC,UAAU,CAKrB,CAAC;AAEF;;;;;;;GAOG;AACH,eAAO,MAAM,qBAAqB,gBACnB,WAAW,CAAC,UAAU,CAAC,YAC1B,MAAM,WACP,8BAA8B,cAC3B,MAAM,KACjB,eAqBF,CAAC"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "dyna-record",
|
|
3
|
-
"version": "0.2.
|
|
3
|
+
"version": "0.2.2",
|
|
4
4
|
"description": "Typescript Object Relational Mapper (ORM) for Dynamo",
|
|
5
5
|
"main": "dist/index.js",
|
|
6
6
|
"types": "dist/index.d.ts",
|
|
@@ -10,7 +10,7 @@
|
|
|
10
10
|
"test": "jest",
|
|
11
11
|
"test:watch": "jest --watch",
|
|
12
12
|
"eslint": "npx eslint . --ext .ts",
|
|
13
|
-
"eslint
|
|
13
|
+
"eslint:fix": "npx eslint . --ext .ts --fix",
|
|
14
14
|
"prettier": "npx prettier . --write",
|
|
15
15
|
"docs": "npx typedoc"
|
|
16
16
|
},
|