dyna-record 0.0.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +3 -0
- package/dist/index.d.ts +2 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +17 -0
- package/dist/src/DynaRecord.d.ts +216 -0
- package/dist/src/DynaRecord.d.ts.map +1 -0
- package/dist/src/DynaRecord.js +217 -0
- package/dist/src/Logger.d.ts +42 -0
- package/dist/src/Logger.d.ts.map +1 -0
- package/dist/src/Logger.js +57 -0
- package/dist/src/decorators/Entity.d.ts +23 -0
- package/dist/src/decorators/Entity.d.ts.map +1 -0
- package/dist/src/decorators/Entity.js +32 -0
- package/dist/src/decorators/Table.d.ts +22 -0
- package/dist/src/decorators/Table.d.ts.map +1 -0
- package/dist/src/decorators/Table.js +31 -0
- package/dist/src/decorators/attributes/Attribute.d.ts +26 -0
- package/dist/src/decorators/attributes/Attribute.d.ts.map +1 -0
- package/dist/src/decorators/attributes/Attribute.js +41 -0
- package/dist/src/decorators/attributes/DateAttribute.d.ts +25 -0
- package/dist/src/decorators/attributes/DateAttribute.d.ts.map +1 -0
- package/dist/src/decorators/attributes/DateAttribute.js +43 -0
- package/dist/src/decorators/attributes/DateNullableAttribute.d.ts +26 -0
- package/dist/src/decorators/attributes/DateNullableAttribute.d.ts.map +1 -0
- package/dist/src/decorators/attributes/DateNullableAttribute.js +43 -0
- package/dist/src/decorators/attributes/ForeignKeyAttribute.d.ts +25 -0
- package/dist/src/decorators/attributes/ForeignKeyAttribute.d.ts.map +1 -0
- package/dist/src/decorators/attributes/ForeignKeyAttribute.js +40 -0
- package/dist/src/decorators/attributes/NullableAttribute.d.ts +27 -0
- package/dist/src/decorators/attributes/NullableAttribute.d.ts.map +1 -0
- package/dist/src/decorators/attributes/NullableAttribute.js +41 -0
- package/dist/src/decorators/attributes/NullableForeignKeyAttribute.d.ts +25 -0
- package/dist/src/decorators/attributes/NullableForeignKeyAttribute.d.ts.map +1 -0
- package/dist/src/decorators/attributes/NullableForeignKeyAttribute.js +40 -0
- package/dist/src/decorators/attributes/PartitionKeyAttribute.d.ts +24 -0
- package/dist/src/decorators/attributes/PartitionKeyAttribute.d.ts.map +1 -0
- package/dist/src/decorators/attributes/PartitionKeyAttribute.js +38 -0
- package/dist/src/decorators/attributes/SortKeyAttribute.d.ts +24 -0
- package/dist/src/decorators/attributes/SortKeyAttribute.d.ts.map +1 -0
- package/dist/src/decorators/attributes/SortKeyAttribute.js +38 -0
- package/dist/src/decorators/attributes/index.d.ts +10 -0
- package/dist/src/decorators/attributes/index.d.ts.map +1 -0
- package/dist/src/decorators/attributes/index.js +37 -0
- package/dist/src/decorators/attributes/serializers.d.ts +13 -0
- package/dist/src/decorators/attributes/serializers.d.ts.map +1 -0
- package/dist/src/decorators/attributes/serializers.js +19 -0
- package/dist/src/decorators/index.d.ts +6 -0
- package/dist/src/decorators/index.d.ts.map +1 -0
- package/dist/src/decorators/index.js +27 -0
- package/dist/src/decorators/relationships/BelongsTo.d.ts +34 -0
- package/dist/src/decorators/relationships/BelongsTo.d.ts.map +1 -0
- package/dist/src/decorators/relationships/BelongsTo.js +50 -0
- package/dist/src/decorators/relationships/HasAndBelongsToMany.d.ts +80 -0
- package/dist/src/decorators/relationships/HasAndBelongsToMany.d.ts.map +1 -0
- package/dist/src/decorators/relationships/HasAndBelongsToMany.js +70 -0
- package/dist/src/decorators/relationships/HasMany.d.ts +35 -0
- package/dist/src/decorators/relationships/HasMany.d.ts.map +1 -0
- package/dist/src/decorators/relationships/HasMany.js +48 -0
- package/dist/src/decorators/relationships/HasOne.d.ts +35 -0
- package/dist/src/decorators/relationships/HasOne.d.ts.map +1 -0
- package/dist/src/decorators/relationships/HasOne.js +48 -0
- package/dist/src/decorators/relationships/index.d.ts +6 -0
- package/dist/src/decorators/relationships/index.d.ts.map +1 -0
- package/dist/src/decorators/relationships/index.js +29 -0
- package/dist/src/decorators/relationships/types.d.ts +11 -0
- package/dist/src/decorators/relationships/types.d.ts.map +1 -0
- package/dist/src/decorators/relationships/types.js +2 -0
- package/dist/src/decorators/types.d.ts +30 -0
- package/dist/src/decorators/types.d.ts.map +1 -0
- package/dist/src/decorators/types.js +2 -0
- package/dist/src/dynamo-utils/DynamoClient.d.ts +34 -0
- package/dist/src/dynamo-utils/DynamoClient.d.ts.map +1 -0
- package/dist/src/dynamo-utils/DynamoClient.js +57 -0
- package/dist/src/dynamo-utils/TransactGetBuilder.d.ts +18 -0
- package/dist/src/dynamo-utils/TransactGetBuilder.d.ts.map +1 -0
- package/dist/src/dynamo-utils/TransactGetBuilder.js +32 -0
- package/dist/src/dynamo-utils/TransactWriteBuilder.d.ts +46 -0
- package/dist/src/dynamo-utils/TransactWriteBuilder.d.ts.map +1 -0
- package/dist/src/dynamo-utils/TransactWriteBuilder.js +100 -0
- package/dist/src/dynamo-utils/errors.d.ts +13 -0
- package/dist/src/dynamo-utils/errors.d.ts.map +1 -0
- package/dist/src/dynamo-utils/errors.js +17 -0
- package/dist/src/dynamo-utils/index.d.ts +8 -0
- package/dist/src/dynamo-utils/index.d.ts.map +1 -0
- package/dist/src/dynamo-utils/index.js +30 -0
- package/dist/src/dynamo-utils/types.d.ts +52 -0
- package/dist/src/dynamo-utils/types.d.ts.map +1 -0
- package/dist/src/dynamo-utils/types.js +2 -0
- package/dist/src/errors.d.ts +13 -0
- package/dist/src/errors.d.ts.map +1 -0
- package/dist/src/errors.js +17 -0
- package/dist/src/index.d.ts +6 -0
- package/dist/src/index.d.ts.map +1 -0
- package/dist/src/index.js +24 -0
- package/dist/src/metadata/AttributeMetadata.d.ts +22 -0
- package/dist/src/metadata/AttributeMetadata.d.ts.map +1 -0
- package/dist/src/metadata/AttributeMetadata.js +27 -0
- package/dist/src/metadata/EntityMetadata.d.ts +42 -0
- package/dist/src/metadata/EntityMetadata.d.ts.map +1 -0
- package/dist/src/metadata/EntityMetadata.js +49 -0
- package/dist/src/metadata/JoinTableMetadata.d.ts +23 -0
- package/dist/src/metadata/JoinTableMetadata.d.ts.map +1 -0
- package/dist/src/metadata/JoinTableMetadata.js +22 -0
- package/dist/src/metadata/MetadataStorage.d.ts +104 -0
- package/dist/src/metadata/MetadataStorage.d.ts.map +1 -0
- package/dist/src/metadata/MetadataStorage.js +194 -0
- package/dist/src/metadata/TableMetadata.d.ts +53 -0
- package/dist/src/metadata/TableMetadata.d.ts.map +1 -0
- package/dist/src/metadata/TableMetadata.js +100 -0
- package/dist/src/metadata/index.d.ts +13 -0
- package/dist/src/metadata/index.d.ts.map +1 -0
- package/dist/src/metadata/index.js +34 -0
- package/dist/src/metadata/relationship-metadata/BelongsToRelationship.d.ts +18 -0
- package/dist/src/metadata/relationship-metadata/BelongsToRelationship.d.ts.map +1 -0
- package/dist/src/metadata/relationship-metadata/BelongsToRelationship.js +26 -0
- package/dist/src/metadata/relationship-metadata/HasAndBelongsToManyRelationship.d.ts +16 -0
- package/dist/src/metadata/relationship-metadata/HasAndBelongsToManyRelationship.d.ts.map +1 -0
- package/dist/src/metadata/relationship-metadata/HasAndBelongsToManyRelationship.js +25 -0
- package/dist/src/metadata/relationship-metadata/HasManyRelationship.d.ts +18 -0
- package/dist/src/metadata/relationship-metadata/HasManyRelationship.d.ts.map +1 -0
- package/dist/src/metadata/relationship-metadata/HasManyRelationship.js +26 -0
- package/dist/src/metadata/relationship-metadata/HasOneRelationship.d.ts +17 -0
- package/dist/src/metadata/relationship-metadata/HasOneRelationship.d.ts.map +1 -0
- package/dist/src/metadata/relationship-metadata/HasOneRelationship.js +25 -0
- package/dist/src/metadata/relationship-metadata/RelationshipMetadata.d.ts +21 -0
- package/dist/src/metadata/relationship-metadata/RelationshipMetadata.d.ts.map +1 -0
- package/dist/src/metadata/relationship-metadata/RelationshipMetadata.js +18 -0
- package/dist/src/metadata/relationship-metadata/index.d.ts +7 -0
- package/dist/src/metadata/relationship-metadata/index.d.ts.map +1 -0
- package/dist/src/metadata/relationship-metadata/index.js +29 -0
- package/dist/src/metadata/relationship-metadata/types.d.ts +16 -0
- package/dist/src/metadata/relationship-metadata/types.d.ts.map +1 -0
- package/dist/src/metadata/relationship-metadata/types.js +2 -0
- package/dist/src/metadata/relationship-metadata/utils.d.ts +3 -0
- package/dist/src/metadata/relationship-metadata/utils.d.ts.map +1 -0
- package/dist/src/metadata/relationship-metadata/utils.js +25 -0
- package/dist/src/metadata/types.d.ts +90 -0
- package/dist/src/metadata/types.d.ts.map +1 -0
- package/dist/src/metadata/types.js +2 -0
- package/dist/src/metadata/utils.d.ts +42 -0
- package/dist/src/metadata/utils.d.ts.map +1 -0
- package/dist/src/metadata/utils.js +67 -0
- package/dist/src/operations/Create/Create.d.ts +39 -0
- package/dist/src/operations/Create/Create.d.ts.map +1 -0
- package/dist/src/operations/Create/Create.js +84 -0
- package/dist/src/operations/Create/index.d.ts +3 -0
- package/dist/src/operations/Create/index.d.ts.map +1 -0
- package/dist/src/operations/Create/index.js +23 -0
- package/dist/src/operations/Create/types.d.ts +7 -0
- package/dist/src/operations/Create/types.d.ts.map +1 -0
- package/dist/src/operations/Create/types.js +2 -0
- package/dist/src/operations/Delete/Delete.d.ts +74 -0
- package/dist/src/operations/Delete/Delete.d.ts.map +1 -0
- package/dist/src/operations/Delete/Delete.js +207 -0
- package/dist/src/operations/Delete/index.d.ts +2 -0
- package/dist/src/operations/Delete/index.d.ts.map +1 -0
- package/dist/src/operations/Delete/index.js +8 -0
- package/dist/src/operations/Delete/types.d.ts +7 -0
- package/dist/src/operations/Delete/types.d.ts.map +1 -0
- package/dist/src/operations/Delete/types.js +2 -0
- package/dist/src/operations/FindById/FindById.d.ts +91 -0
- package/dist/src/operations/FindById/FindById.d.ts.map +1 -0
- package/dist/src/operations/FindById/FindById.js +244 -0
- package/dist/src/operations/FindById/index.d.ts +3 -0
- package/dist/src/operations/FindById/index.d.ts.map +1 -0
- package/dist/src/operations/FindById/index.js +23 -0
- package/dist/src/operations/FindById/types.d.ts +57 -0
- package/dist/src/operations/FindById/types.d.ts.map +1 -0
- package/dist/src/operations/FindById/types.js +2 -0
- package/dist/src/operations/OperationBase.d.ts +37 -0
- package/dist/src/operations/OperationBase.d.ts.map +1 -0
- package/dist/src/operations/OperationBase.js +44 -0
- package/dist/src/operations/Query/Query.d.ts +45 -0
- package/dist/src/operations/Query/Query.d.ts.map +1 -0
- package/dist/src/operations/Query/Query.js +84 -0
- package/dist/src/operations/Query/index.d.ts +3 -0
- package/dist/src/operations/Query/index.d.ts.map +1 -0
- package/dist/src/operations/Query/index.js +23 -0
- package/dist/src/operations/Query/types.d.ts +38 -0
- package/dist/src/operations/Query/types.d.ts.map +1 -0
- package/dist/src/operations/Query/types.js +2 -0
- package/dist/src/operations/Update/Update.d.ts +48 -0
- package/dist/src/operations/Update/Update.d.ts.map +1 -0
- package/dist/src/operations/Update/Update.js +118 -0
- package/dist/src/operations/Update/index.d.ts +3 -0
- package/dist/src/operations/Update/index.d.ts.map +1 -0
- package/dist/src/operations/Update/index.js +23 -0
- package/dist/src/operations/Update/types.d.ts +32 -0
- package/dist/src/operations/Update/types.d.ts.map +1 -0
- package/dist/src/operations/Update/types.js +2 -0
- package/dist/src/operations/index.d.ts +7 -0
- package/dist/src/operations/index.d.ts.map +1 -0
- package/dist/src/operations/index.js +22 -0
- package/dist/src/operations/types.d.ts +59 -0
- package/dist/src/operations/types.d.ts.map +1 -0
- package/dist/src/operations/types.js +2 -0
- package/dist/src/operations/utils/RelationshipTransactions.d.ts +64 -0
- package/dist/src/operations/utils/RelationshipTransactions.d.ts.map +1 -0
- package/dist/src/operations/utils/RelationshipTransactions.js +125 -0
- package/dist/src/operations/utils/expressionBuilder.d.ts +9 -0
- package/dist/src/operations/utils/expressionBuilder.d.ts.map +1 -0
- package/dist/src/operations/utils/expressionBuilder.js +106 -0
- package/dist/src/operations/utils/index.d.ts +5 -0
- package/dist/src/operations/utils/index.d.ts.map +1 -0
- package/dist/src/operations/utils/index.js +25 -0
- package/dist/src/operations/utils/types.d.ts +21 -0
- package/dist/src/operations/utils/types.d.ts.map +1 -0
- package/dist/src/operations/utils/types.js +2 -0
- package/dist/src/operations/utils/utils.d.ts +19 -0
- package/dist/src/operations/utils/utils.d.ts.map +1 -0
- package/dist/src/operations/utils/utils.js +36 -0
- package/dist/src/query-utils/Filters.d.ts +10 -0
- package/dist/src/query-utils/Filters.d.ts.map +1 -0
- package/dist/src/query-utils/Filters.js +25 -0
- package/dist/src/query-utils/QueryBuilder.d.ts +90 -0
- package/dist/src/query-utils/QueryBuilder.d.ts.map +1 -0
- package/dist/src/query-utils/QueryBuilder.js +213 -0
- package/dist/src/query-utils/index.d.ts +3 -0
- package/dist/src/query-utils/index.d.ts.map +1 -0
- package/dist/src/query-utils/index.js +23 -0
- package/dist/src/query-utils/types.d.ts +89 -0
- package/dist/src/query-utils/types.d.ts.map +1 -0
- package/dist/src/query-utils/types.js +2 -0
- package/dist/src/relationships/BelongsToLink.d.ts +50 -0
- package/dist/src/relationships/BelongsToLink.d.ts.map +1 -0
- package/dist/src/relationships/BelongsToLink.js +57 -0
- package/dist/src/relationships/JoinTable.d.ts +68 -0
- package/dist/src/relationships/JoinTable.d.ts.map +1 -0
- package/dist/src/relationships/JoinTable.js +133 -0
- package/dist/src/relationships/index.d.ts +3 -0
- package/dist/src/relationships/index.d.ts.map +1 -0
- package/dist/src/relationships/index.js +10 -0
- package/dist/src/types.d.ts +73 -0
- package/dist/src/types.d.ts.map +1 -0
- package/dist/src/types.js +2 -0
- package/dist/src/utils.d.ts +89 -0
- package/dist/src/utils.d.ts.map +1 -0
- package/dist/src/utils.js +168 -0
- package/package.json +61 -0
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
14
|
+
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
15
|
+
};
|
|
16
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
17
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
18
|
+
};
|
|
19
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
20
|
+
exports.DateNullableAttribute = exports.DateAttribute = exports.NullableForeignKeyAttribute = exports.ForeignKeyAttribute = exports.SortKeyAttribute = exports.PartitionKeyAttribute = exports.NullableAttribute = exports.Attribute = void 0;
|
|
21
|
+
var Attribute_1 = require("./Attribute");
|
|
22
|
+
Object.defineProperty(exports, "Attribute", { enumerable: true, get: function () { return __importDefault(Attribute_1).default; } });
|
|
23
|
+
var NullableAttribute_1 = require("./NullableAttribute");
|
|
24
|
+
Object.defineProperty(exports, "NullableAttribute", { enumerable: true, get: function () { return __importDefault(NullableAttribute_1).default; } });
|
|
25
|
+
var PartitionKeyAttribute_1 = require("./PartitionKeyAttribute");
|
|
26
|
+
Object.defineProperty(exports, "PartitionKeyAttribute", { enumerable: true, get: function () { return __importDefault(PartitionKeyAttribute_1).default; } });
|
|
27
|
+
var SortKeyAttribute_1 = require("./SortKeyAttribute");
|
|
28
|
+
Object.defineProperty(exports, "SortKeyAttribute", { enumerable: true, get: function () { return __importDefault(SortKeyAttribute_1).default; } });
|
|
29
|
+
var ForeignKeyAttribute_1 = require("./ForeignKeyAttribute");
|
|
30
|
+
Object.defineProperty(exports, "ForeignKeyAttribute", { enumerable: true, get: function () { return __importDefault(ForeignKeyAttribute_1).default; } });
|
|
31
|
+
var NullableForeignKeyAttribute_1 = require("./NullableForeignKeyAttribute");
|
|
32
|
+
Object.defineProperty(exports, "NullableForeignKeyAttribute", { enumerable: true, get: function () { return __importDefault(NullableForeignKeyAttribute_1).default; } });
|
|
33
|
+
var DateAttribute_1 = require("./DateAttribute");
|
|
34
|
+
Object.defineProperty(exports, "DateAttribute", { enumerable: true, get: function () { return __importDefault(DateAttribute_1).default; } });
|
|
35
|
+
var DateNullableAttribute_1 = require("./DateNullableAttribute");
|
|
36
|
+
Object.defineProperty(exports, "DateNullableAttribute", { enumerable: true, get: function () { return __importDefault(DateNullableAttribute_1).default; } });
|
|
37
|
+
__exportStar(require("./serializers"), exports);
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import type { NativeScalarAttributeValue } from "@aws-sdk/util-dynamodb";
|
|
2
|
+
/**
|
|
3
|
+
* Provides serialization and deserialization functions for date attributes when interfacing with a DynamoDB table, enabling the conversion between the table's string-based date representation and JavaScript's `Date` object. DynamoDb dos not support Date types naturally, this utility allows for Date attributes to be serialized to an entity and stored as ISO strings in Dynamo.
|
|
4
|
+
*
|
|
5
|
+
* - `toEntityAttribute`: Converts a DynamoDB attribute value to a JavaScript `Date` object.
|
|
6
|
+
* - `toTableAttribute`: Converts a JavaScript `Date` object to a string representation suitable for DynamoDB storage, specifically using the ISO 8601 format. This ensures that date information is stored in a consistent and queryable format within DynamoDB.
|
|
7
|
+
*
|
|
8
|
+
*/
|
|
9
|
+
export declare const dateSerializer: {
|
|
10
|
+
toEntityAttribute: (val: NativeScalarAttributeValue) => number | bigint | boolean | Date | import("@aws-sdk/util-dynamodb").NumberValue | ArrayBuffer | Blob | DataView | null | undefined;
|
|
11
|
+
toTableAttribute: (val: Date) => string;
|
|
12
|
+
};
|
|
13
|
+
//# sourceMappingURL=serializers.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"serializers.d.ts","sourceRoot":"","sources":["../../../../src/decorators/attributes/serializers.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,0BAA0B,EAAE,MAAM,wBAAwB,CAAC;AAEzE;;;;;;GAMG;AACH,eAAO,MAAM,cAAc;6BACA,0BAA0B;4BAM3B,IAAI;CAC7B,CAAC"}
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.dateSerializer = void 0;
|
|
4
|
+
/**
|
|
5
|
+
* Provides serialization and deserialization functions for date attributes when interfacing with a DynamoDB table, enabling the conversion between the table's string-based date representation and JavaScript's `Date` object. DynamoDb dos not support Date types naturally, this utility allows for Date attributes to be serialized to an entity and stored as ISO strings in Dynamo.
|
|
6
|
+
*
|
|
7
|
+
* - `toEntityAttribute`: Converts a DynamoDB attribute value to a JavaScript `Date` object.
|
|
8
|
+
* - `toTableAttribute`: Converts a JavaScript `Date` object to a string representation suitable for DynamoDB storage, specifically using the ISO 8601 format. This ensures that date information is stored in a consistent and queryable format within DynamoDB.
|
|
9
|
+
*
|
|
10
|
+
*/
|
|
11
|
+
exports.dateSerializer = {
|
|
12
|
+
toEntityAttribute: (val) => {
|
|
13
|
+
if (typeof val === "string") {
|
|
14
|
+
return new Date(val);
|
|
15
|
+
}
|
|
16
|
+
return val;
|
|
17
|
+
},
|
|
18
|
+
toTableAttribute: (val) => val.toISOString()
|
|
19
|
+
};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/decorators/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,IAAI,MAAM,EAAE,MAAM,UAAU,CAAC;AAC7C,OAAO,EAAE,OAAO,IAAI,KAAK,EAAE,MAAM,SAAS,CAAC;AAC3C,cAAc,iBAAiB,CAAC;AAChC,cAAc,cAAc,CAAC;AAC7B,cAAc,SAAS,CAAC"}
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
14
|
+
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
15
|
+
};
|
|
16
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
17
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
18
|
+
};
|
|
19
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
20
|
+
exports.Table = exports.Entity = void 0;
|
|
21
|
+
var Entity_1 = require("./Entity");
|
|
22
|
+
Object.defineProperty(exports, "Entity", { enumerable: true, get: function () { return __importDefault(Entity_1).default; } });
|
|
23
|
+
var Table_1 = require("./Table");
|
|
24
|
+
Object.defineProperty(exports, "Table", { enumerable: true, get: function () { return __importDefault(Table_1).default; } });
|
|
25
|
+
__exportStar(require("./relationships"), exports);
|
|
26
|
+
__exportStar(require("./attributes"), exports);
|
|
27
|
+
__exportStar(require("./types"), exports);
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
import type DynaRecord from "../../DynaRecord";
|
|
2
|
+
import type { EntityClass } from "../../types";
|
|
3
|
+
import type { BelongsToField, BelongsToProps } from "./types";
|
|
4
|
+
/**
|
|
5
|
+
* A decorator for defining a "BelongsTo" relationship between entities in a single-table design using DynaRecord. This relationship indicates that the decorated field is a reference to another entity, effectively establishing a parent-child linkage. The decorator dynamically enforces the presence or optionality of this reference based on the nature of the foreign key, enhancing type safety and relationship integrity within the ORM model.
|
|
6
|
+
*
|
|
7
|
+
* The decorator must reference a foreign key defined on the model.
|
|
8
|
+
*
|
|
9
|
+
* IMPORTANT - If referenced through a {@link NullableForeignKey} then set the belongs to attribute to optional.
|
|
10
|
+
*
|
|
11
|
+
* The decorator takes into consideration whether the relationship is defined by a `NullableForeignKey`, allowing the field to be optional if so, otherwise ensuring it is not optional. This behavior aligns with relational database design principles, where a foreign key can either strictly enforce a relationship or allow for its absence.
|
|
12
|
+
*
|
|
13
|
+
* @template T The source entity type, from which the relationship originates.
|
|
14
|
+
* @template K The target entity type, to which the relationship points.
|
|
15
|
+
* @template FK The type of the foreign key attribute within the source entity, used to establish the relationship. Must be defined on the model.
|
|
16
|
+
* @param getTarget A function returning the class (constructor function) of the target entity. This enables late binding and avoids circular dependency issues.
|
|
17
|
+
* @param props Configuration object for the relationship, including the name of the foreign key attribute.
|
|
18
|
+
* @returns A class field decorator function that initializes the source entity's class prototype, registering the relationship with the ORM's metadata system. This registration process includes specifying the relationship type as "BelongsTo", along with detailing the target entity and foreign key.
|
|
19
|
+
*
|
|
20
|
+
* Usage example:
|
|
21
|
+
* ```typescript
|
|
22
|
+
* class Order extends BaseEntity {
|
|
23
|
+
* @ForeignKeyProperty({ alias: "UserId" })
|
|
24
|
+
* public readonly userId: ForeignKey;
|
|
25
|
+
*
|
|
26
|
+
* @BelongsTo(() => User, { foreignKey: 'userId' })
|
|
27
|
+
* public user: User;
|
|
28
|
+
* }
|
|
29
|
+
* ```
|
|
30
|
+
* In this example, `@BelongsTo` decorates the `user` field of the `Order` entity, establishing a "BelongsTo" relationship with the `User` entity via the `userId` foreign key. This decoration signifies that each `Order` instance is related to a specific `User` instance.
|
|
31
|
+
*/
|
|
32
|
+
declare function BelongsTo<T extends DynaRecord, K extends DynaRecord>(getTarget: () => EntityClass<K>, props: BelongsToProps<T>): (_value: undefined, context: ClassFieldDecoratorContext<T, BelongsToField<T, K, typeof props.foreignKey>>) => void;
|
|
33
|
+
export default BelongsTo;
|
|
34
|
+
//# sourceMappingURL=BelongsTo.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"BelongsTo.d.ts","sourceRoot":"","sources":["../../../../src/decorators/relationships/BelongsTo.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,UAAU,MAAM,kBAAkB,CAAC;AAC/C,OAAO,KAAK,EAAE,WAAW,EAAsB,MAAM,aAAa,CAAC;AACnE,OAAO,KAAK,EAAE,cAAc,EAAE,cAAc,EAAE,MAAM,SAAS,CAAC;AAE9D;;;;;;;;;;;;;;;;;;;;;;;;;;;GA2BG;AACH,iBAAS,SAAS,CAAC,CAAC,SAAS,UAAU,EAAE,CAAC,SAAS,UAAU,EAC3D,SAAS,EAAE,MAAM,WAAW,CAAC,CAAC,CAAC,EAC/B,KAAK,EAAE,cAAc,CAAC,CAAC,CAAC,YAGd,SAAS,WACR,2BACP,CAAC,EACD,eAAe,CAAC,EAAE,CAAC,EAAE,OAAO,MAAM,UAAU,CAAC,CAC9C,UAeJ;AAED,eAAe,SAAS,CAAC"}
|
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
const metadata_1 = __importDefault(require("../../metadata"));
|
|
7
|
+
/**
|
|
8
|
+
* A decorator for defining a "BelongsTo" relationship between entities in a single-table design using DynaRecord. This relationship indicates that the decorated field is a reference to another entity, effectively establishing a parent-child linkage. The decorator dynamically enforces the presence or optionality of this reference based on the nature of the foreign key, enhancing type safety and relationship integrity within the ORM model.
|
|
9
|
+
*
|
|
10
|
+
* The decorator must reference a foreign key defined on the model.
|
|
11
|
+
*
|
|
12
|
+
* IMPORTANT - If referenced through a {@link NullableForeignKey} then set the belongs to attribute to optional.
|
|
13
|
+
*
|
|
14
|
+
* The decorator takes into consideration whether the relationship is defined by a `NullableForeignKey`, allowing the field to be optional if so, otherwise ensuring it is not optional. This behavior aligns with relational database design principles, where a foreign key can either strictly enforce a relationship or allow for its absence.
|
|
15
|
+
*
|
|
16
|
+
* @template T The source entity type, from which the relationship originates.
|
|
17
|
+
* @template K The target entity type, to which the relationship points.
|
|
18
|
+
* @template FK The type of the foreign key attribute within the source entity, used to establish the relationship. Must be defined on the model.
|
|
19
|
+
* @param getTarget A function returning the class (constructor function) of the target entity. This enables late binding and avoids circular dependency issues.
|
|
20
|
+
* @param props Configuration object for the relationship, including the name of the foreign key attribute.
|
|
21
|
+
* @returns A class field decorator function that initializes the source entity's class prototype, registering the relationship with the ORM's metadata system. This registration process includes specifying the relationship type as "BelongsTo", along with detailing the target entity and foreign key.
|
|
22
|
+
*
|
|
23
|
+
* Usage example:
|
|
24
|
+
* ```typescript
|
|
25
|
+
* class Order extends BaseEntity {
|
|
26
|
+
* @ForeignKeyProperty({ alias: "UserId" })
|
|
27
|
+
* public readonly userId: ForeignKey;
|
|
28
|
+
*
|
|
29
|
+
* @BelongsTo(() => User, { foreignKey: 'userId' })
|
|
30
|
+
* public user: User;
|
|
31
|
+
* }
|
|
32
|
+
* ```
|
|
33
|
+
* In this example, `@BelongsTo` decorates the `user` field of the `Order` entity, establishing a "BelongsTo" relationship with the `User` entity via the `userId` foreign key. This decoration signifies that each `Order` instance is related to a specific `User` instance.
|
|
34
|
+
*/
|
|
35
|
+
function BelongsTo(getTarget, props) {
|
|
36
|
+
return function (_value, context) {
|
|
37
|
+
if (context.kind === "field") {
|
|
38
|
+
context.addInitializer(function () {
|
|
39
|
+
const entity = Object.getPrototypeOf(this);
|
|
40
|
+
metadata_1.default.addEntityRelationship(entity.constructor.name, {
|
|
41
|
+
type: "BelongsTo",
|
|
42
|
+
propertyName: context.name,
|
|
43
|
+
target: getTarget(),
|
|
44
|
+
foreignKey: props.foreignKey
|
|
45
|
+
});
|
|
46
|
+
});
|
|
47
|
+
}
|
|
48
|
+
};
|
|
49
|
+
}
|
|
50
|
+
exports.default = BelongsTo;
|
|
@@ -0,0 +1,80 @@
|
|
|
1
|
+
import { type JoinTable } from "../../relationships";
|
|
2
|
+
import type DynaRecord from "../../DynaRecord";
|
|
3
|
+
import type { EntityClass } from "../../types";
|
|
4
|
+
/**
|
|
5
|
+
* The key on the related Entity which is associated with this Entity
|
|
6
|
+
*/
|
|
7
|
+
type TargetKey<T, U> = {
|
|
8
|
+
[K in keyof T]: T[K] extends U[] ? K : never;
|
|
9
|
+
}[keyof T];
|
|
10
|
+
/**
|
|
11
|
+
* Represents a function returning metadata for a join table.
|
|
12
|
+
* @template J The type of the join table.
|
|
13
|
+
*/
|
|
14
|
+
type ThroughFunction<J extends JoinTable<DynaRecord, DynaRecord>> = () => {
|
|
15
|
+
/**
|
|
16
|
+
* The constructor function for the join table.
|
|
17
|
+
* @param {...any[]} args Constructor arguments for the join table.
|
|
18
|
+
* @returns {J} An instance of the join table.
|
|
19
|
+
*/
|
|
20
|
+
joinTable: new (...args: any[]) => J;
|
|
21
|
+
/**
|
|
22
|
+
* The key representing the foreign key property of the join table.
|
|
23
|
+
*/
|
|
24
|
+
foreignKey: keyof J;
|
|
25
|
+
};
|
|
26
|
+
interface HasAndBelongsToManyProps<T extends DynaRecord, K extends DynaRecord, J extends JoinTable<T, K>, L extends JoinTable<K, T>> {
|
|
27
|
+
/**
|
|
28
|
+
* The key of the model to add an association to.
|
|
29
|
+
*/
|
|
30
|
+
targetKey: TargetKey<T, K>;
|
|
31
|
+
/**
|
|
32
|
+
* The JoinTable properties this relationship is associated through
|
|
33
|
+
*/
|
|
34
|
+
through: ThroughFunction<J> | ThroughFunction<L>;
|
|
35
|
+
}
|
|
36
|
+
/**
|
|
37
|
+
* A decorator for defining a many-to-many relationship between entities in a single-table design ORM system. This relationship is facilitated through a join table, representing the connection between the two entities. The decorator simplifies the management of such relationships by automating the setup and handling of the join table metadata, thereby enabling seamless querying and manipulation of related entities.
|
|
38
|
+
*
|
|
39
|
+
* @template T The source entity class the decorator is applied to.
|
|
40
|
+
* @template K The target entity class that T has a many-to-many relationship with.
|
|
41
|
+
* @template J The join table entity class that associates T with K.
|
|
42
|
+
* @template L The join table entity class that associates K with T, allowing for bidirectional relationships.
|
|
43
|
+
* @param getTarget A function that returns the constructor of the target entity class. This enables lazy evaluation and avoids circular dependency issues.
|
|
44
|
+
* @param props Configuration options for the many-to-many relationship, including the key on the related entity and the details of the join table (through a "through" function) that facilitates the relationship.
|
|
45
|
+
* @returns A class field decorator function that, when applied to a field, registers the many-to-many relationship in the ORM's metadata system. This registration includes information about the join table and the relationship's configuration, essential for the ORM to handle related entities correctly.
|
|
46
|
+
*
|
|
47
|
+
* Usage example:
|
|
48
|
+
* ```typescript
|
|
49
|
+
* class User extends BaseEntity {
|
|
50
|
+
* @HasAndBelongsToMany(() => Group, {
|
|
51
|
+
* targetKey: 'users',
|
|
52
|
+
* through: () => ({
|
|
53
|
+
* joinTable: UserGroup,
|
|
54
|
+
* foreignKey: 'userId'
|
|
55
|
+
* })
|
|
56
|
+
* })
|
|
57
|
+
* public groups: Group[];
|
|
58
|
+
* }
|
|
59
|
+
*
|
|
60
|
+
* class Group extends BaseEntity {
|
|
61
|
+
* @HasAndBelongsToMany(() => User, {
|
|
62
|
+
* targetKey: 'groups',
|
|
63
|
+
* through: () => ({
|
|
64
|
+
* joinTable: UserGroup,
|
|
65
|
+
* foreignKey: 'groupId'
|
|
66
|
+
* })
|
|
67
|
+
* })
|
|
68
|
+
* public users: User[];
|
|
69
|
+
* }
|
|
70
|
+
*
|
|
71
|
+
* class AuthorBook extends JoinTable<User, Group> {
|
|
72
|
+
* public readonly userId: ForeignKey;
|
|
73
|
+
* public readonly groupId: ForeignKey;
|
|
74
|
+
* }
|
|
75
|
+
* ```
|
|
76
|
+
* In this example, `User` entities are related to `Group` entities through a many-to-many relationship, with `UserGroupJoin` serving as the join table. The decorator indicates this relationship, allowing for efficient querying and manipulation of related entities.
|
|
77
|
+
*/
|
|
78
|
+
declare function HasAndBelongsToMany<T extends DynaRecord, K extends DynaRecord, J extends JoinTable<T, K>, L extends JoinTable<K, T>>(getTarget: () => EntityClass<T>, props: HasAndBelongsToManyProps<T, K, J, L>): (_value: undefined, context: ClassFieldDecoratorContext<K, T[]>) => void;
|
|
79
|
+
export default HasAndBelongsToMany;
|
|
80
|
+
//# sourceMappingURL=HasAndBelongsToMany.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"HasAndBelongsToMany.d.ts","sourceRoot":"","sources":["../../../../src/decorators/relationships/HasAndBelongsToMany.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,KAAK,SAAS,EAAE,MAAM,qBAAqB,CAAC;AACrD,OAAO,KAAK,UAAU,MAAM,kBAAkB,CAAC;AAC/C,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,aAAa,CAAC;AAE/C;;GAEG;AACH,KAAK,SAAS,CAAC,CAAC,EAAE,CAAC,IAAI;KACpB,CAAC,IAAI,MAAM,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,SAAS,CAAC,EAAE,GAAG,CAAC,GAAG,KAAK;CAC7C,CAAC,MAAM,CAAC,CAAC,CAAC;AAEX;;;GAGG;AACH,KAAK,eAAe,CAAC,CAAC,SAAS,SAAS,CAAC,UAAU,EAAE,UAAU,CAAC,IAAI,MAAM;IACxE;;;;OAIG;IACH,SAAS,EAAE,KAAK,GAAG,IAAI,EAAE,GAAG,EAAE,KAAK,CAAC,CAAC;IACrC;;OAEG;IACH,UAAU,EAAE,MAAM,CAAC,CAAC;CACrB,CAAC;AAEF,UAAU,wBAAwB,CAChC,CAAC,SAAS,UAAU,EACpB,CAAC,SAAS,UAAU,EACpB,CAAC,SAAS,SAAS,CAAC,CAAC,EAAE,CAAC,CAAC,EACzB,CAAC,SAAS,SAAS,CAAC,CAAC,EAAE,CAAC,CAAC;IAEzB;;OAEG;IACH,SAAS,EAAE,SAAS,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC;IAC3B;;OAEG;IACH,OAAO,EAAE,eAAe,CAAC,CAAC,CAAC,GAAG,eAAe,CAAC,CAAC,CAAC,CAAC;CAClD;AAED;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAyCG;AACH,iBAAS,mBAAmB,CAC1B,CAAC,SAAS,UAAU,EACpB,CAAC,SAAS,UAAU,EACpB,CAAC,SAAS,SAAS,CAAC,CAAC,EAAE,CAAC,CAAC,EACzB,CAAC,SAAS,SAAS,CAAC,CAAC,EAAE,CAAC,CAAC,EAEzB,SAAS,EAAE,MAAM,WAAW,CAAC,CAAC,CAAC,EAC/B,KAAK,EAAE,wBAAwB,CAAC,CAAC,EAAE,CAAC,EAAE,CAAC,EAAE,CAAC,CAAC,YAE3B,SAAS,WAAW,2BAA2B,CAAC,EAAE,CAAC,EAAE,CAAC,UAqBvE;AAED,eAAe,mBAAmB,CAAC"}
|
|
@@ -0,0 +1,70 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
const metadata_1 = __importDefault(require("../../metadata"));
|
|
7
|
+
/**
|
|
8
|
+
* A decorator for defining a many-to-many relationship between entities in a single-table design ORM system. This relationship is facilitated through a join table, representing the connection between the two entities. The decorator simplifies the management of such relationships by automating the setup and handling of the join table metadata, thereby enabling seamless querying and manipulation of related entities.
|
|
9
|
+
*
|
|
10
|
+
* @template T The source entity class the decorator is applied to.
|
|
11
|
+
* @template K The target entity class that T has a many-to-many relationship with.
|
|
12
|
+
* @template J The join table entity class that associates T with K.
|
|
13
|
+
* @template L The join table entity class that associates K with T, allowing for bidirectional relationships.
|
|
14
|
+
* @param getTarget A function that returns the constructor of the target entity class. This enables lazy evaluation and avoids circular dependency issues.
|
|
15
|
+
* @param props Configuration options for the many-to-many relationship, including the key on the related entity and the details of the join table (through a "through" function) that facilitates the relationship.
|
|
16
|
+
* @returns A class field decorator function that, when applied to a field, registers the many-to-many relationship in the ORM's metadata system. This registration includes information about the join table and the relationship's configuration, essential for the ORM to handle related entities correctly.
|
|
17
|
+
*
|
|
18
|
+
* Usage example:
|
|
19
|
+
* ```typescript
|
|
20
|
+
* class User extends BaseEntity {
|
|
21
|
+
* @HasAndBelongsToMany(() => Group, {
|
|
22
|
+
* targetKey: 'users',
|
|
23
|
+
* through: () => ({
|
|
24
|
+
* joinTable: UserGroup,
|
|
25
|
+
* foreignKey: 'userId'
|
|
26
|
+
* })
|
|
27
|
+
* })
|
|
28
|
+
* public groups: Group[];
|
|
29
|
+
* }
|
|
30
|
+
*
|
|
31
|
+
* class Group extends BaseEntity {
|
|
32
|
+
* @HasAndBelongsToMany(() => User, {
|
|
33
|
+
* targetKey: 'groups',
|
|
34
|
+
* through: () => ({
|
|
35
|
+
* joinTable: UserGroup,
|
|
36
|
+
* foreignKey: 'groupId'
|
|
37
|
+
* })
|
|
38
|
+
* })
|
|
39
|
+
* public users: User[];
|
|
40
|
+
* }
|
|
41
|
+
*
|
|
42
|
+
* class AuthorBook extends JoinTable<User, Group> {
|
|
43
|
+
* public readonly userId: ForeignKey;
|
|
44
|
+
* public readonly groupId: ForeignKey;
|
|
45
|
+
* }
|
|
46
|
+
* ```
|
|
47
|
+
* In this example, `User` entities are related to `Group` entities through a many-to-many relationship, with `UserGroupJoin` serving as the join table. The decorator indicates this relationship, allowing for efficient querying and manipulation of related entities.
|
|
48
|
+
*/
|
|
49
|
+
function HasAndBelongsToMany(getTarget, props) {
|
|
50
|
+
return (_value, context) => {
|
|
51
|
+
if (context.kind === "field") {
|
|
52
|
+
context.addInitializer(function () {
|
|
53
|
+
const entity = Object.getPrototypeOf(this);
|
|
54
|
+
const target = getTarget();
|
|
55
|
+
const { joinTable, foreignKey } = props.through();
|
|
56
|
+
metadata_1.default.addEntityRelationship(entity.constructor.name, {
|
|
57
|
+
type: "HasAndBelongsToMany",
|
|
58
|
+
propertyName: context.name,
|
|
59
|
+
target,
|
|
60
|
+
joinTableName: joinTable.name
|
|
61
|
+
});
|
|
62
|
+
metadata_1.default.addJoinTable(joinTable.name, {
|
|
63
|
+
entity: target,
|
|
64
|
+
foreignKey: foreignKey
|
|
65
|
+
});
|
|
66
|
+
});
|
|
67
|
+
}
|
|
68
|
+
};
|
|
69
|
+
}
|
|
70
|
+
exports.default = HasAndBelongsToMany;
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
import type DynaRecord from "../../DynaRecord";
|
|
2
|
+
import type { EntityClass } from "../../types";
|
|
3
|
+
import { type ForeignEntityAttribute } from "../types";
|
|
4
|
+
interface HasManyProps<T extends DynaRecord> {
|
|
5
|
+
foreignKey: ForeignEntityAttribute<T>;
|
|
6
|
+
}
|
|
7
|
+
/**
|
|
8
|
+
* 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.
|
|
9
|
+
*
|
|
10
|
+
* @template T The source entity class that has many instances of another entity. This is the entity class to which the decorator is applied.
|
|
11
|
+
* @template K The target entity class that is related to `T` through a one-to-many relationship.
|
|
12
|
+
* @param getTarget A function that returns the constructor of the target entity class `T`. This function is crucial for establishing the relationship dynamically and avoids issues related to circular dependencies.
|
|
13
|
+
* @param props Configuration options for the one-to-many relationship, specifically the foreign key in the target entity that links back to the source entity. This configuration ensures the correct association and navigation between related entities.
|
|
14
|
+
* @returns A class field decorator function that, when applied to a field of type array of `T`, registers the one-to-many relationship in the ORM's metadata system. This registration is essential for the ORM to recognize and correctly handle the relationship between the source and target entities, facilitating operations such as retrieval and update of related entities.
|
|
15
|
+
*
|
|
16
|
+
* Usage example:
|
|
17
|
+
* ```typescript
|
|
18
|
+
* class User extends BaseEntity {
|
|
19
|
+
* @HasMany(() => Post, { foreignKey: 'userId' })
|
|
20
|
+
* public posts: Post[];
|
|
21
|
+
* }
|
|
22
|
+
*
|
|
23
|
+
* class Post extends BaseEntity {
|
|
24
|
+
* @ForeignKeyProperty()
|
|
25
|
+
* public readonly userId: ForeignKey;
|
|
26
|
+
*
|
|
27
|
+
* @BelongsTo(() => User, { foreignKey: "userId" })
|
|
28
|
+
* public readonly user: User;
|
|
29
|
+
* }
|
|
30
|
+
* ```
|
|
31
|
+
* In this example, each `User` entity is associated with multiple `Post` entities through a one-to-many relationship. The `@HasMany` decorator is applied to the `posts` field of the `User` class, indicating that a user can have many posts. The `foreignKey` property specifies the attribute in the `Post` entity that establishes the connection back to the `User` entity, enabling the ORM to manage the relationship effectively.
|
|
32
|
+
*/
|
|
33
|
+
declare function HasMany<T extends DynaRecord, K extends DynaRecord>(getTarget: () => EntityClass<T>, props: HasManyProps<T>): (_value: undefined, context: ClassFieldDecoratorContext<K, T[]>) => void;
|
|
34
|
+
export default HasMany;
|
|
35
|
+
//# sourceMappingURL=HasMany.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"HasMany.d.ts","sourceRoot":"","sources":["../../../../src/decorators/relationships/HasMany.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,UAAU,MAAM,kBAAkB,CAAC;AAC/C,OAAO,KAAK,EAAE,WAAW,EAAsB,MAAM,aAAa,CAAC;AACnE,OAAO,EAAE,KAAK,sBAAsB,EAAE,MAAM,UAAU,CAAC;AAEvD,UAAU,YAAY,CAAC,CAAC,SAAS,UAAU;IACzC,UAAU,EAAE,sBAAsB,CAAC,CAAC,CAAC,CAAC;CACvC;AAED;;;;;;;;;;;;;;;;;;;;;;;;;GAyBG;AACH,iBAAS,OAAO,CAAC,CAAC,SAAS,UAAU,EAAE,CAAC,SAAS,UAAU,EACzD,SAAS,EAAE,MAAM,WAAW,CAAC,CAAC,CAAC,EAC/B,KAAK,EAAE,YAAY,CAAC,CAAC,CAAC,YAEN,SAAS,WAAW,2BAA2B,CAAC,EAAE,CAAC,EAAE,CAAC,UAcvE;AAED,eAAe,OAAO,CAAC"}
|
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
const metadata_1 = __importDefault(require("../../metadata"));
|
|
7
|
+
/**
|
|
8
|
+
* A 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.
|
|
9
|
+
*
|
|
10
|
+
* @template T The source entity class that has many instances of another entity. This is the entity class to which the decorator is applied.
|
|
11
|
+
* @template K The target entity class that is related to `T` through a one-to-many relationship.
|
|
12
|
+
* @param getTarget A function that returns the constructor of the target entity class `T`. This function is crucial for establishing the relationship dynamically and avoids issues related to circular dependencies.
|
|
13
|
+
* @param props Configuration options for the one-to-many relationship, specifically the foreign key in the target entity that links back to the source entity. This configuration ensures the correct association and navigation between related entities.
|
|
14
|
+
* @returns A class field decorator function that, when applied to a field of type array of `T`, registers the one-to-many relationship in the ORM's metadata system. This registration is essential for the ORM to recognize and correctly handle the relationship between the source and target entities, facilitating operations such as retrieval and update of related entities.
|
|
15
|
+
*
|
|
16
|
+
* Usage example:
|
|
17
|
+
* ```typescript
|
|
18
|
+
* class User extends BaseEntity {
|
|
19
|
+
* @HasMany(() => Post, { foreignKey: 'userId' })
|
|
20
|
+
* public posts: Post[];
|
|
21
|
+
* }
|
|
22
|
+
*
|
|
23
|
+
* class Post extends BaseEntity {
|
|
24
|
+
* @ForeignKeyProperty()
|
|
25
|
+
* public readonly userId: ForeignKey;
|
|
26
|
+
*
|
|
27
|
+
* @BelongsTo(() => User, { foreignKey: "userId" })
|
|
28
|
+
* public readonly user: User;
|
|
29
|
+
* }
|
|
30
|
+
* ```
|
|
31
|
+
* In this example, each `User` entity is associated with multiple `Post` entities through a one-to-many relationship. The `@HasMany` decorator is applied to the `posts` field of the `User` class, indicating that a user can have many posts. The `foreignKey` property specifies the attribute in the `Post` entity that establishes the connection back to the `User` entity, enabling the ORM to manage the relationship effectively.
|
|
32
|
+
*/
|
|
33
|
+
function HasMany(getTarget, props) {
|
|
34
|
+
return (_value, context) => {
|
|
35
|
+
if (context.kind === "field") {
|
|
36
|
+
context.addInitializer(function () {
|
|
37
|
+
const entity = Object.getPrototypeOf(this);
|
|
38
|
+
metadata_1.default.addEntityRelationship(entity.constructor.name, {
|
|
39
|
+
type: "HasMany",
|
|
40
|
+
propertyName: context.name,
|
|
41
|
+
target: getTarget(),
|
|
42
|
+
foreignKey: props.foreignKey
|
|
43
|
+
});
|
|
44
|
+
});
|
|
45
|
+
}
|
|
46
|
+
};
|
|
47
|
+
}
|
|
48
|
+
exports.default = HasMany;
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
import type DynaRecord from "../../DynaRecord";
|
|
2
|
+
import type { EntityClass, Optional } from "../../types";
|
|
3
|
+
import { type ForeignEntityAttribute } from "../types";
|
|
4
|
+
interface HasOneProps<T extends DynaRecord> {
|
|
5
|
+
foreignKey: ForeignEntityAttribute<T> & keyof T;
|
|
6
|
+
}
|
|
7
|
+
/**
|
|
8
|
+
* A decorator for defining a one-to-one relationship between entities in a single-table design ORM system. This relationship implies that an instance of the entity to which this decorator is applied can be associated with at most one instance of another entity. The `HasOne` decorator plays a crucial role in establishing and managing such relationships by automatically registering the necessary metadata, thereby enabling the ORM to recognize and navigate these associations effectively.
|
|
9
|
+
*
|
|
10
|
+
* @template T The source entity class that has a one-to-one relationship with another entity. This is the class on which the decorator is applied.
|
|
11
|
+
* @template K The target entity class that is related to `T` in a one-to-one relationship.
|
|
12
|
+
* @param getTarget A function returning the constructor of the target entity class `T`. This function is essential for dynamically establishing the relationship, helping to circumvent circular dependency issues.
|
|
13
|
+
* @param props Configuration options for the one-to-one relationship, particularly the foreign key within the target entity that links it back to the source entity. This setup is critical for accurately linking and managing the entities involved.
|
|
14
|
+
* @returns A class field decorator function that, when applied to a field, registers the one-to-one relationship in the ORM's metadata system. The registration includes the target entity and the specified foreign key, ensuring that the ORM correctly interprets and maintains the relationship.
|
|
15
|
+
*
|
|
16
|
+
* Usage example:
|
|
17
|
+
* ```typescript
|
|
18
|
+
* class User extends BaseEntity {
|
|
19
|
+
* @HasOne(() => Profile, { foreignKey: 'userId' })
|
|
20
|
+
* public profile?: Profile;
|
|
21
|
+
* }
|
|
22
|
+
*
|
|
23
|
+
* class Profile extends BaseEntity {
|
|
24
|
+
* @ForeignKeyProperty()
|
|
25
|
+
* public readonly userId: ForeignKey;
|
|
26
|
+
*
|
|
27
|
+
* @BelongsTo(() => User, { foreignKey: "userId" })
|
|
28
|
+
* public readonly user: User;
|
|
29
|
+
* }
|
|
30
|
+
* ```
|
|
31
|
+
* Here, the `@HasOne` decorator is applied to the `profile` field of the `User` class, establishing a one-to-one relationship between a `User` and a `Profile`. The foreign key (`userId`) in the `Profile` entity points back to the `User` entity, enabling the ORM to manage this relationship by linking a user to at most one profile.
|
|
32
|
+
*/
|
|
33
|
+
declare function HasOne<T extends DynaRecord, K extends DynaRecord>(getTarget: () => EntityClass<T>, props: HasOneProps<T>): (_value: undefined, context: ClassFieldDecoratorContext<K, Optional<T>>) => void;
|
|
34
|
+
export default HasOne;
|
|
35
|
+
//# sourceMappingURL=HasOne.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"HasOne.d.ts","sourceRoot":"","sources":["../../../../src/decorators/relationships/HasOne.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,UAAU,MAAM,kBAAkB,CAAC;AAC/C,OAAO,KAAK,EAAE,WAAW,EAAsB,QAAQ,EAAE,MAAM,aAAa,CAAC;AAC7E,OAAO,EAAE,KAAK,sBAAsB,EAAE,MAAM,UAAU,CAAC;AAEvD,UAAU,WAAW,CAAC,CAAC,SAAS,UAAU;IACxC,UAAU,EAAE,sBAAsB,CAAC,CAAC,CAAC,GAAG,MAAM,CAAC,CAAC;CACjD;AAED;;;;;;;;;;;;;;;;;;;;;;;;;GAyBG;AACH,iBAAS,MAAM,CAAC,CAAC,SAAS,UAAU,EAAE,CAAC,SAAS,UAAU,EACxD,SAAS,EAAE,MAAM,WAAW,CAAC,CAAC,CAAC,EAC/B,KAAK,EAAE,WAAW,CAAC,CAAC,CAAC,YAGX,SAAS,WACR,2BAA2B,CAAC,EAAE,SAAS,CAAC,CAAC,CAAC,UAetD;AAED,eAAe,MAAM,CAAC"}
|
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
const metadata_1 = __importDefault(require("../../metadata"));
|
|
7
|
+
/**
|
|
8
|
+
* A decorator for defining a one-to-one relationship between entities in a single-table design ORM system. This relationship implies that an instance of the entity to which this decorator is applied can be associated with at most one instance of another entity. The `HasOne` decorator plays a crucial role in establishing and managing such relationships by automatically registering the necessary metadata, thereby enabling the ORM to recognize and navigate these associations effectively.
|
|
9
|
+
*
|
|
10
|
+
* @template T The source entity class that has a one-to-one relationship with another entity. This is the class on which the decorator is applied.
|
|
11
|
+
* @template K The target entity class that is related to `T` in a one-to-one relationship.
|
|
12
|
+
* @param getTarget A function returning the constructor of the target entity class `T`. This function is essential for dynamically establishing the relationship, helping to circumvent circular dependency issues.
|
|
13
|
+
* @param props Configuration options for the one-to-one relationship, particularly the foreign key within the target entity that links it back to the source entity. This setup is critical for accurately linking and managing the entities involved.
|
|
14
|
+
* @returns A class field decorator function that, when applied to a field, registers the one-to-one relationship in the ORM's metadata system. The registration includes the target entity and the specified foreign key, ensuring that the ORM correctly interprets and maintains the relationship.
|
|
15
|
+
*
|
|
16
|
+
* Usage example:
|
|
17
|
+
* ```typescript
|
|
18
|
+
* class User extends BaseEntity {
|
|
19
|
+
* @HasOne(() => Profile, { foreignKey: 'userId' })
|
|
20
|
+
* public profile?: Profile;
|
|
21
|
+
* }
|
|
22
|
+
*
|
|
23
|
+
* class Profile extends BaseEntity {
|
|
24
|
+
* @ForeignKeyProperty()
|
|
25
|
+
* public readonly userId: ForeignKey;
|
|
26
|
+
*
|
|
27
|
+
* @BelongsTo(() => User, { foreignKey: "userId" })
|
|
28
|
+
* public readonly user: User;
|
|
29
|
+
* }
|
|
30
|
+
* ```
|
|
31
|
+
* Here, the `@HasOne` decorator is applied to the `profile` field of the `User` class, establishing a one-to-one relationship between a `User` and a `Profile`. The foreign key (`userId`) in the `Profile` entity points back to the `User` entity, enabling the ORM to manage this relationship by linking a user to at most one profile.
|
|
32
|
+
*/
|
|
33
|
+
function HasOne(getTarget, props) {
|
|
34
|
+
return function (_value, context) {
|
|
35
|
+
if (context.kind === "field") {
|
|
36
|
+
context.addInitializer(function () {
|
|
37
|
+
const entity = Object.getPrototypeOf(this);
|
|
38
|
+
metadata_1.default.addEntityRelationship(entity.constructor.name, {
|
|
39
|
+
type: "HasOne",
|
|
40
|
+
propertyName: context.name,
|
|
41
|
+
target: getTarget(),
|
|
42
|
+
foreignKey: props.foreignKey
|
|
43
|
+
});
|
|
44
|
+
});
|
|
45
|
+
}
|
|
46
|
+
};
|
|
47
|
+
}
|
|
48
|
+
exports.default = HasOne;
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
export { default as HasMany } from "./HasMany";
|
|
2
|
+
export { default as HasOne } from "./HasOne";
|
|
3
|
+
export { default as BelongsTo } from "./BelongsTo";
|
|
4
|
+
export { default as HasAndBelongsToMany } from "./HasAndBelongsToMany";
|
|
5
|
+
export * from "./types";
|
|
6
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../src/decorators/relationships/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,IAAI,OAAO,EAAE,MAAM,WAAW,CAAC;AAC/C,OAAO,EAAE,OAAO,IAAI,MAAM,EAAE,MAAM,UAAU,CAAC;AAC7C,OAAO,EAAE,OAAO,IAAI,SAAS,EAAE,MAAM,aAAa,CAAC;AACnD,OAAO,EAAE,OAAO,IAAI,mBAAmB,EAAE,MAAM,uBAAuB,CAAC;AACvE,cAAc,SAAS,CAAC"}
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
14
|
+
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
15
|
+
};
|
|
16
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
17
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
18
|
+
};
|
|
19
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
20
|
+
exports.HasAndBelongsToMany = exports.BelongsTo = exports.HasOne = exports.HasMany = void 0;
|
|
21
|
+
var HasMany_1 = require("./HasMany");
|
|
22
|
+
Object.defineProperty(exports, "HasMany", { enumerable: true, get: function () { return __importDefault(HasMany_1).default; } });
|
|
23
|
+
var HasOne_1 = require("./HasOne");
|
|
24
|
+
Object.defineProperty(exports, "HasOne", { enumerable: true, get: function () { return __importDefault(HasOne_1).default; } });
|
|
25
|
+
var BelongsTo_1 = require("./BelongsTo");
|
|
26
|
+
Object.defineProperty(exports, "BelongsTo", { enumerable: true, get: function () { return __importDefault(BelongsTo_1).default; } });
|
|
27
|
+
var HasAndBelongsToMany_1 = require("./HasAndBelongsToMany");
|
|
28
|
+
Object.defineProperty(exports, "HasAndBelongsToMany", { enumerable: true, get: function () { return __importDefault(HasAndBelongsToMany_1).default; } });
|
|
29
|
+
__exportStar(require("./types"), exports);
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import type DynaRecord from "../../DynaRecord";
|
|
2
|
+
import type { NullableForeignKey, Optional } from "../../types";
|
|
3
|
+
import type { ForeignEntityAttribute } from "../types";
|
|
4
|
+
export interface BelongsToProps<T extends DynaRecord> {
|
|
5
|
+
foreignKey: ForeignEntityAttribute<T>;
|
|
6
|
+
}
|
|
7
|
+
/**
|
|
8
|
+
* If the relationship is linked by a NullableForeignKey then it allows the field to be optional, otherwise it ensures that is is not optional
|
|
9
|
+
*/
|
|
10
|
+
export type BelongsToField<T extends DynaRecord, K extends DynaRecord, FK extends ForeignEntityAttribute<T>> = FK extends keyof T ? T[FK] extends NullableForeignKey ? Optional<K> : K : never;
|
|
11
|
+
//# sourceMappingURL=types.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../../../src/decorators/relationships/types.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,UAAU,MAAM,kBAAkB,CAAC;AAC/C,OAAO,KAAK,EAAE,kBAAkB,EAAE,QAAQ,EAAE,MAAM,aAAa,CAAC;AAChE,OAAO,KAAK,EAAE,sBAAsB,EAAE,MAAM,UAAU,CAAC;AAEvD,MAAM,WAAW,cAAc,CAAC,CAAC,SAAS,UAAU;IAClD,UAAU,EAAE,sBAAsB,CAAC,CAAC,CAAC,CAAC;CACvC;AAED;;GAEG;AACH,MAAM,MAAM,cAAc,CACxB,CAAC,SAAS,UAAU,EACpB,CAAC,SAAS,UAAU,EACpB,EAAE,SAAS,sBAAsB,CAAC,CAAC,CAAC,IAClC,EAAE,SAAS,MAAM,CAAC,GAClB,CAAC,CAAC,EAAE,CAAC,SAAS,kBAAkB,GAC9B,QAAQ,CAAC,CAAC,CAAC,GACX,CAAC,GACH,KAAK,CAAC"}
|