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,42 @@
|
|
|
1
|
+
import { type AttributeMetadata, type AttributeMetadataStorage, type RelationshipMetadataStorage } from ".";
|
|
2
|
+
import type DynaRecord from "../DynaRecord";
|
|
3
|
+
type EntityClass = new (...args: any) => DynaRecord;
|
|
4
|
+
/**
|
|
5
|
+
* Represents metadata for an entity within the ORM system, encapsulating information about the entity's attributes, relationships, and its associated database table.
|
|
6
|
+
*
|
|
7
|
+
* @property {string} tableClassName - The name of the table class instance to which this entity is mapped, providing a link between the entity and its database table.
|
|
8
|
+
* @property {AttributeMetadataStorage} attributes - A storage mapping for attribute metadata, keyed by entity field names, enabling lookup of attribute configurations.
|
|
9
|
+
* @property {AttributeMetadataStorage} tableAttributes - A storage mapping for attribute metadata, keyed by table column names (aliases), used for database interactions.
|
|
10
|
+
* @property {RelationshipMetadataStorage} relationships - A storage for relationship metadata, facilitating the management of entity relationships.
|
|
11
|
+
* @property {EntityClass} EntityClass - The constructor function of the entity class, allowing instantiation and further metadata enrichment.
|
|
12
|
+
*
|
|
13
|
+
* @param {EntityClass} entityClass - The constructor function of the entity class this metadata belongs to.
|
|
14
|
+
* @param {string} tableClassName - The name of the table class instance that maps to the database table of the entity.
|
|
15
|
+
*/
|
|
16
|
+
declare class EntityMetadata {
|
|
17
|
+
/**
|
|
18
|
+
* The name of the table class instance to which this entity belongs
|
|
19
|
+
*/
|
|
20
|
+
readonly tableClassName: string;
|
|
21
|
+
/**
|
|
22
|
+
* Attribute metadata, for looking up attribute metadata by entity key
|
|
23
|
+
*/
|
|
24
|
+
readonly attributes: AttributeMetadataStorage;
|
|
25
|
+
/**
|
|
26
|
+
* Attribute metadata, for looking up attribute metadata by table key
|
|
27
|
+
*/
|
|
28
|
+
readonly tableAttributes: AttributeMetadataStorage;
|
|
29
|
+
/**
|
|
30
|
+
* Relationship metadata. For looking up a relationship by entity key
|
|
31
|
+
*/
|
|
32
|
+
readonly relationships: RelationshipMetadataStorage;
|
|
33
|
+
readonly EntityClass: EntityClass;
|
|
34
|
+
constructor(entityClass: EntityClass, tableClassName: string);
|
|
35
|
+
/**
|
|
36
|
+
* Add attribute metadata to an entity
|
|
37
|
+
* @param attrMeta
|
|
38
|
+
*/
|
|
39
|
+
addAttribute(attrMeta: AttributeMetadata): void;
|
|
40
|
+
}
|
|
41
|
+
export default EntityMetadata;
|
|
42
|
+
//# sourceMappingURL=EntityMetadata.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"EntityMetadata.d.ts","sourceRoot":"","sources":["../../../src/metadata/EntityMetadata.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,KAAK,iBAAiB,EACtB,KAAK,wBAAwB,EAC7B,KAAK,2BAA2B,EACjC,MAAM,GAAG,CAAC;AACX,OAAO,KAAK,UAAU,MAAM,eAAe,CAAC;AAE5C,KAAK,WAAW,GAAG,KAAK,GAAG,IAAI,EAAE,GAAG,KAAK,UAAU,CAAC;AAEpD;;;;;;;;;;;GAWG;AACH,cAAM,cAAc;IAClB;;OAEG;IACH,SAAgB,cAAc,EAAE,MAAM,CAAC;IACvC;;OAEG;IACH,SAAgB,UAAU,EAAE,wBAAwB,CAAC;IACrD;;OAEG;IACH,SAAgB,eAAe,EAAE,wBAAwB,CAAC;IAE1D;;OAEG;IACH,SAAgB,aAAa,EAAE,2BAA2B,CAAC;IAE3D,SAAgB,WAAW,EAAE,WAAW,CAAC;gBAE7B,WAAW,EAAE,WAAW,EAAE,cAAc,EAAE,MAAM;IAS5D;;;OAGG;IACI,YAAY,CAAC,QAAQ,EAAE,iBAAiB,GAAG,IAAI;CAIvD;AAED,eAAe,cAAc,CAAC"}
|
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
/**
|
|
4
|
+
* Represents metadata for an entity within the ORM system, encapsulating information about the entity's attributes, relationships, and its associated database table.
|
|
5
|
+
*
|
|
6
|
+
* @property {string} tableClassName - The name of the table class instance to which this entity is mapped, providing a link between the entity and its database table.
|
|
7
|
+
* @property {AttributeMetadataStorage} attributes - A storage mapping for attribute metadata, keyed by entity field names, enabling lookup of attribute configurations.
|
|
8
|
+
* @property {AttributeMetadataStorage} tableAttributes - A storage mapping for attribute metadata, keyed by table column names (aliases), used for database interactions.
|
|
9
|
+
* @property {RelationshipMetadataStorage} relationships - A storage for relationship metadata, facilitating the management of entity relationships.
|
|
10
|
+
* @property {EntityClass} EntityClass - The constructor function of the entity class, allowing instantiation and further metadata enrichment.
|
|
11
|
+
*
|
|
12
|
+
* @param {EntityClass} entityClass - The constructor function of the entity class this metadata belongs to.
|
|
13
|
+
* @param {string} tableClassName - The name of the table class instance that maps to the database table of the entity.
|
|
14
|
+
*/
|
|
15
|
+
class EntityMetadata {
|
|
16
|
+
/**
|
|
17
|
+
* The name of the table class instance to which this entity belongs
|
|
18
|
+
*/
|
|
19
|
+
tableClassName; //
|
|
20
|
+
/**
|
|
21
|
+
* Attribute metadata, for looking up attribute metadata by entity key
|
|
22
|
+
*/
|
|
23
|
+
attributes;
|
|
24
|
+
/**
|
|
25
|
+
* Attribute metadata, for looking up attribute metadata by table key
|
|
26
|
+
*/
|
|
27
|
+
tableAttributes;
|
|
28
|
+
/**
|
|
29
|
+
* Relationship metadata. For looking up a relationship by entity key
|
|
30
|
+
*/
|
|
31
|
+
relationships;
|
|
32
|
+
EntityClass;
|
|
33
|
+
constructor(entityClass, tableClassName) {
|
|
34
|
+
this.EntityClass = entityClass;
|
|
35
|
+
this.tableClassName = tableClassName;
|
|
36
|
+
this.attributes = {};
|
|
37
|
+
this.tableAttributes = {};
|
|
38
|
+
this.relationships = {};
|
|
39
|
+
}
|
|
40
|
+
/**
|
|
41
|
+
* Add attribute metadata to an entity
|
|
42
|
+
* @param attrMeta
|
|
43
|
+
*/
|
|
44
|
+
addAttribute(attrMeta) {
|
|
45
|
+
this.attributes[attrMeta.name] = attrMeta;
|
|
46
|
+
this.tableAttributes[attrMeta.alias] = attrMeta;
|
|
47
|
+
}
|
|
48
|
+
}
|
|
49
|
+
exports.default = EntityMetadata;
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import type DynaRecord from "../DynaRecord";
|
|
2
|
+
import type { JoinTable } from "../relationships";
|
|
3
|
+
import type { EntityClass } from "../types";
|
|
4
|
+
type Entity = EntityClass<DynaRecord>;
|
|
5
|
+
type ForeignKey = keyof JoinTable<DynaRecord, DynaRecord>;
|
|
6
|
+
/**
|
|
7
|
+
* Represents the metadata for a join table used in many-to-many relationships within the ORM system. This metadata includes the entity class and the foreign key used in the join table.
|
|
8
|
+
*
|
|
9
|
+
* A join table is an intermediary table that connects two entities in a many-to-many relationship, holding foreign keys that reference the partition keys of each entity. `JoinTableMetadata` encapsulates the details of one side of such a relationship, specifically the entity involved and the foreign key within the join table that points to this entity.
|
|
10
|
+
*
|
|
11
|
+
* @property {Entity} entity - The entity class that is part of the many-to-many relationship. This entity corresponds to one side of the relationship.
|
|
12
|
+
* @property {ForeignKey} foreignKey - The foreign key in the join table that references the partition key of the `entity`. This key is crucial for linking records between the associated entities.
|
|
13
|
+
*
|
|
14
|
+
* @param {Entity} entity - The entity class involved in the many-to-many relationship.
|
|
15
|
+
* @param {ForeignKey} foreignKey - The foreign key within the join table that references the entity's partition key.
|
|
16
|
+
*/
|
|
17
|
+
declare class JoinTableMetadata {
|
|
18
|
+
readonly entity: Entity;
|
|
19
|
+
readonly foreignKey: ForeignKey;
|
|
20
|
+
constructor(entity: Entity, foreignKey: ForeignKey);
|
|
21
|
+
}
|
|
22
|
+
export default JoinTableMetadata;
|
|
23
|
+
//# sourceMappingURL=JoinTableMetadata.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"JoinTableMetadata.d.ts","sourceRoot":"","sources":["../../../src/metadata/JoinTableMetadata.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,UAAU,MAAM,eAAe,CAAC;AAC5C,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,kBAAkB,CAAC;AAClD,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,UAAU,CAAC;AAE5C,KAAK,MAAM,GAAG,WAAW,CAAC,UAAU,CAAC,CAAC;AACtC,KAAK,UAAU,GAAG,MAAM,SAAS,CAAC,UAAU,EAAE,UAAU,CAAC,CAAC;AAE1D;;;;;;;;;;GAUG;AAEH,cAAM,iBAAiB;IACrB,SAAgB,MAAM,EAAE,MAAM,CAAC;IAC/B,SAAgB,UAAU,EAAE,UAAU,CAAC;gBAE3B,MAAM,EAAE,MAAM,EAAE,UAAU,EAAE,UAAU;CAInD;AAED,eAAe,iBAAiB,CAAC"}
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
/**
|
|
4
|
+
* Represents the metadata for a join table used in many-to-many relationships within the ORM system. This metadata includes the entity class and the foreign key used in the join table.
|
|
5
|
+
*
|
|
6
|
+
* A join table is an intermediary table that connects two entities in a many-to-many relationship, holding foreign keys that reference the partition keys of each entity. `JoinTableMetadata` encapsulates the details of one side of such a relationship, specifically the entity involved and the foreign key within the join table that points to this entity.
|
|
7
|
+
*
|
|
8
|
+
* @property {Entity} entity - The entity class that is part of the many-to-many relationship. This entity corresponds to one side of the relationship.
|
|
9
|
+
* @property {ForeignKey} foreignKey - The foreign key in the join table that references the partition key of the `entity`. This key is crucial for linking records between the associated entities.
|
|
10
|
+
*
|
|
11
|
+
* @param {Entity} entity - The entity class involved in the many-to-many relationship.
|
|
12
|
+
* @param {ForeignKey} foreignKey - The foreign key within the join table that references the entity's partition key.
|
|
13
|
+
*/
|
|
14
|
+
class JoinTableMetadata {
|
|
15
|
+
entity;
|
|
16
|
+
foreignKey;
|
|
17
|
+
constructor(entity, foreignKey) {
|
|
18
|
+
this.entity = entity;
|
|
19
|
+
this.foreignKey = foreignKey;
|
|
20
|
+
}
|
|
21
|
+
}
|
|
22
|
+
exports.default = JoinTableMetadata;
|
|
@@ -0,0 +1,104 @@
|
|
|
1
|
+
import type DynaRecord from "../DynaRecord";
|
|
2
|
+
import type { MakeOptional } from "../types";
|
|
3
|
+
import TableMetadata from "./TableMetadata";
|
|
4
|
+
import EntityMetadata from "./EntityMetadata";
|
|
5
|
+
import JoinTableMetadata from "./JoinTableMetadata";
|
|
6
|
+
import type { RelationshipMetadata } from "./relationship-metadata";
|
|
7
|
+
import type { AttributeMetadataStorage, TableMetadataOptions, AttributeMetadataOptions } from "./types";
|
|
8
|
+
/**
|
|
9
|
+
* Central storage for managing and accessing all metadata related to entities, attributes, relationships, and tables within the ORM.
|
|
10
|
+
* It provides methods for retrieving and adding metadata for entities and their corresponding tables, handling relationships
|
|
11
|
+
* and attributes, and ensuring the proper initialization of metadata upon first access.
|
|
12
|
+
*/
|
|
13
|
+
declare class MetadataStorage {
|
|
14
|
+
#private;
|
|
15
|
+
/**
|
|
16
|
+
* Returns entity metadata given an entity name
|
|
17
|
+
* @param {string} entityName - Name of the entity
|
|
18
|
+
* @returns Entity metadata
|
|
19
|
+
*/
|
|
20
|
+
getEntity(entityName: string): EntityMetadata;
|
|
21
|
+
/**
|
|
22
|
+
* Returns table metadata given a table name
|
|
23
|
+
* @param {string} tableName - Name of the table
|
|
24
|
+
* @returns Table metadata
|
|
25
|
+
*/
|
|
26
|
+
getTable(tableName: string): TableMetadata;
|
|
27
|
+
/**
|
|
28
|
+
* Returns table metadata for an entity given an entity name
|
|
29
|
+
* @param {string} entityName - Name of the entity
|
|
30
|
+
* @returns Table metadata
|
|
31
|
+
*/
|
|
32
|
+
getEntityTable(entityName: string): TableMetadata;
|
|
33
|
+
/**
|
|
34
|
+
* Returns JoinTable metadata by name
|
|
35
|
+
* @param {string} joinTableName - Name of the JoinTable class
|
|
36
|
+
* @returns joinTableName metadata
|
|
37
|
+
*/
|
|
38
|
+
getJoinTable(joinTableName: string): JoinTableMetadata[];
|
|
39
|
+
/**
|
|
40
|
+
* Returns attribute metadata for attributes defined keyed by entity key
|
|
41
|
+
* @returns - {@link AttributeMetadataStorage}
|
|
42
|
+
*/
|
|
43
|
+
getEntityAttributes(entityName: string): AttributeMetadataStorage;
|
|
44
|
+
/**
|
|
45
|
+
* Returns attribute metadata for attributes defined keyed by table alias
|
|
46
|
+
* @param entityName - Name of the Entity class
|
|
47
|
+
* @returns - {@link AttributeMetadataStorage}
|
|
48
|
+
*/
|
|
49
|
+
getEntityTableAttributes(entityName: string): AttributeMetadataStorage;
|
|
50
|
+
/**
|
|
51
|
+
* Add a table to metadata storage
|
|
52
|
+
* @param tableClassName
|
|
53
|
+
* @param options
|
|
54
|
+
*/
|
|
55
|
+
addTable(tableClassName: string, options: TableMetadataOptions): void;
|
|
56
|
+
/**
|
|
57
|
+
* Add an entity to metadata storage
|
|
58
|
+
* @param entityName
|
|
59
|
+
* @param tableName
|
|
60
|
+
*/
|
|
61
|
+
addEntity(entityClass: EntityMetadata["EntityClass"], tableClassName: string): void;
|
|
62
|
+
/**
|
|
63
|
+
* Adds a relationship to an Entity's metadata storage
|
|
64
|
+
* @param entityName
|
|
65
|
+
* @param options
|
|
66
|
+
*/
|
|
67
|
+
addEntityRelationship(entityName: string, options: RelationshipMetadata): void;
|
|
68
|
+
/**
|
|
69
|
+
* Adds JoinTable metadata to storage
|
|
70
|
+
* @param joinTableName
|
|
71
|
+
* @param options
|
|
72
|
+
*/
|
|
73
|
+
addJoinTable(joinTableName: string, options: JoinTableMetadata): void;
|
|
74
|
+
/**
|
|
75
|
+
* Adds an attribute to an Entity's metadata storage
|
|
76
|
+
* @param entityName
|
|
77
|
+
* @param options
|
|
78
|
+
*/
|
|
79
|
+
addEntityAttribute(entityName: string, options: MakeOptional<AttributeMetadataOptions, "alias">): void;
|
|
80
|
+
/**
|
|
81
|
+
* Adds the partition key attribute to Table metadata storage
|
|
82
|
+
* @param entityClass
|
|
83
|
+
* @param options
|
|
84
|
+
*/
|
|
85
|
+
addPartitionKeyAttribute(entityClass: DynaRecord, options: Parameters<TableMetadata["addPartitionKeyAttribute"]>[number]): void;
|
|
86
|
+
/**
|
|
87
|
+
* Adds the sort key attribute to Table metadata storage
|
|
88
|
+
* @param entityClass
|
|
89
|
+
* @param options
|
|
90
|
+
*/
|
|
91
|
+
addSortKeyAttribute(entityClass: DynaRecord, options: Parameters<TableMetadata["addPartitionKeyAttribute"]>[number]): void;
|
|
92
|
+
/**
|
|
93
|
+
* Initialize metadata object
|
|
94
|
+
*/
|
|
95
|
+
private init;
|
|
96
|
+
/**
|
|
97
|
+
* Recursively search prototype chain and return TableMetadata for an entity class if it exists
|
|
98
|
+
* @param classPrototype
|
|
99
|
+
* @returns
|
|
100
|
+
*/
|
|
101
|
+
private getEntityTableMetadata;
|
|
102
|
+
}
|
|
103
|
+
export default MetadataStorage;
|
|
104
|
+
//# sourceMappingURL=MetadataStorage.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"MetadataStorage.d.ts","sourceRoot":"","sources":["../../../src/metadata/MetadataStorage.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,UAAU,MAAM,eAAe,CAAC;AAC5C,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,UAAU,CAAC;AAC7C,OAAO,aAAa,MAAM,iBAAiB,CAAC;AAC5C,OAAO,cAAc,MAAM,kBAAkB,CAAC;AAE9C,OAAO,iBAAiB,MAAM,qBAAqB,CAAC;AAEpD,OAAO,KAAK,EAAE,oBAAoB,EAAE,MAAM,yBAAyB,CAAC;AACpE,OAAO,KAAK,EACV,wBAAwB,EAIxB,oBAAoB,EAEpB,wBAAwB,EACzB,MAAM,SAAS,CAAC;AAEjB;;;;GAIG;AACH,cAAM,eAAe;;IAOnB;;;;OAIG;IACI,SAAS,CAAC,UAAU,EAAE,MAAM,GAAG,cAAc;IAKpD;;;;OAIG;IACI,QAAQ,CAAC,SAAS,EAAE,MAAM,GAAG,aAAa;IAKjD;;;;OAIG;IACI,cAAc,CAAC,UAAU,EAAE,MAAM,GAAG,aAAa;IAMxD;;;;OAIG;IACI,YAAY,CAAC,aAAa,EAAE,MAAM,GAAG,iBAAiB,EAAE;IAK/D;;;OAGG;IACI,mBAAmB,CAAC,UAAU,EAAE,MAAM,GAAG,wBAAwB;IAYxE;;;;OAIG;IACI,wBAAwB,CAC7B,UAAU,EAAE,MAAM,GACjB,wBAAwB;IAY3B;;;;OAIG;IACI,QAAQ,CAAC,cAAc,EAAE,MAAM,EAAE,OAAO,EAAE,oBAAoB,GAAG,IAAI;IAI5E;;;;OAIG;IACI,SAAS,CACd,WAAW,EAAE,cAAc,CAAC,aAAa,CAAC,EAC1C,cAAc,EAAE,MAAM,GACrB,IAAI;IAOP;;;;OAIG;IACI,qBAAqB,CAC1B,UAAU,EAAE,MAAM,EAClB,OAAO,EAAE,oBAAoB,GAC5B,IAAI;IAQP;;;;OAIG;IACI,YAAY,CAAC,aAAa,EAAE,MAAM,EAAE,OAAO,EAAE,iBAAiB,GAAG,IAAI;IAa5E;;;;OAIG;IACI,kBAAkB,CACvB,UAAU,EAAE,MAAM,EAClB,OAAO,EAAE,YAAY,CAAC,wBAAwB,EAAE,OAAO,CAAC,GACvD,IAAI;IAYP;;;;OAIG;IACI,wBAAwB,CAC7B,WAAW,EAAE,UAAU,EACvB,OAAO,EAAE,UAAU,CAAC,aAAa,CAAC,0BAA0B,CAAC,CAAC,CAAC,MAAM,CAAC,GACrE,IAAI;IAQP;;;;OAIG;IACI,mBAAmB,CACxB,WAAW,EAAE,UAAU,EACvB,OAAO,EAAE,UAAU,CAAC,aAAa,CAAC,0BAA0B,CAAC,CAAC,CAAC,MAAM,CAAC,GACrE,IAAI;IAQP;;OAEG;IACH,OAAO,CAAC,IAAI;IAUZ;;;;OAIG;IACH,OAAO,CAAC,sBAAsB;CAa/B;AAED,eAAe,eAAe,CAAC"}
|
|
@@ -0,0 +1,194 @@
|
|
|
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 TableMetadata_1 = __importDefault(require("./TableMetadata"));
|
|
7
|
+
const EntityMetadata_1 = __importDefault(require("./EntityMetadata"));
|
|
8
|
+
const AttributeMetadata_1 = __importDefault(require("./AttributeMetadata"));
|
|
9
|
+
const JoinTableMetadata_1 = __importDefault(require("./JoinTableMetadata"));
|
|
10
|
+
const utils_1 = require("./relationship-metadata/utils");
|
|
11
|
+
/**
|
|
12
|
+
* Central storage for managing and accessing all metadata related to entities, attributes, relationships, and tables within the ORM.
|
|
13
|
+
* It provides methods for retrieving and adding metadata for entities and their corresponding tables, handling relationships
|
|
14
|
+
* and attributes, and ensuring the proper initialization of metadata upon first access.
|
|
15
|
+
*/
|
|
16
|
+
class MetadataStorage {
|
|
17
|
+
#tables = {};
|
|
18
|
+
#entities = {};
|
|
19
|
+
#joinTables = {};
|
|
20
|
+
#initialized = false;
|
|
21
|
+
/**
|
|
22
|
+
* Returns entity metadata given an entity name
|
|
23
|
+
* @param {string} entityName - Name of the entity
|
|
24
|
+
* @returns Entity metadata
|
|
25
|
+
*/
|
|
26
|
+
getEntity(entityName) {
|
|
27
|
+
this.init();
|
|
28
|
+
return this.#entities[entityName];
|
|
29
|
+
}
|
|
30
|
+
/**
|
|
31
|
+
* Returns table metadata given a table name
|
|
32
|
+
* @param {string} tableName - Name of the table
|
|
33
|
+
* @returns Table metadata
|
|
34
|
+
*/
|
|
35
|
+
getTable(tableName) {
|
|
36
|
+
this.init();
|
|
37
|
+
return this.#tables[tableName];
|
|
38
|
+
}
|
|
39
|
+
/**
|
|
40
|
+
* Returns table metadata for an entity given an entity name
|
|
41
|
+
* @param {string} entityName - Name of the entity
|
|
42
|
+
* @returns Table metadata
|
|
43
|
+
*/
|
|
44
|
+
getEntityTable(entityName) {
|
|
45
|
+
this.init();
|
|
46
|
+
const entityMetadata = this.getEntity(entityName);
|
|
47
|
+
return this.getTable(entityMetadata.tableClassName);
|
|
48
|
+
}
|
|
49
|
+
/**
|
|
50
|
+
* Returns JoinTable metadata by name
|
|
51
|
+
* @param {string} joinTableName - Name of the JoinTable class
|
|
52
|
+
* @returns joinTableName metadata
|
|
53
|
+
*/
|
|
54
|
+
getJoinTable(joinTableName) {
|
|
55
|
+
this.init();
|
|
56
|
+
return this.#joinTables[joinTableName];
|
|
57
|
+
}
|
|
58
|
+
/**
|
|
59
|
+
* Returns attribute metadata for attributes defined keyed by entity key
|
|
60
|
+
* @returns - {@link AttributeMetadataStorage}
|
|
61
|
+
*/
|
|
62
|
+
getEntityAttributes(entityName) {
|
|
63
|
+
const entityMetadata = this.getEntity(entityName);
|
|
64
|
+
const tableMeta = this.getTable(entityMetadata.tableClassName);
|
|
65
|
+
return {
|
|
66
|
+
...entityMetadata.attributes,
|
|
67
|
+
...tableMeta.defaultAttributes,
|
|
68
|
+
[tableMeta.partitionKeyAttribute.name]: tableMeta.partitionKeyAttribute,
|
|
69
|
+
[tableMeta.sortKeyAttribute.name]: tableMeta.sortKeyAttribute
|
|
70
|
+
};
|
|
71
|
+
}
|
|
72
|
+
/**
|
|
73
|
+
* Returns attribute metadata for attributes defined keyed by table alias
|
|
74
|
+
* @param entityName - Name of the Entity class
|
|
75
|
+
* @returns - {@link AttributeMetadataStorage}
|
|
76
|
+
*/
|
|
77
|
+
getEntityTableAttributes(entityName) {
|
|
78
|
+
const entityMetadata = this.getEntity(entityName);
|
|
79
|
+
const tableMeta = this.getTable(entityMetadata.tableClassName);
|
|
80
|
+
return {
|
|
81
|
+
...entityMetadata.tableAttributes,
|
|
82
|
+
...tableMeta.defaultTableAttributes,
|
|
83
|
+
[tableMeta.partitionKeyAttribute.alias]: tableMeta.partitionKeyAttribute,
|
|
84
|
+
[tableMeta.sortKeyAttribute.alias]: tableMeta.sortKeyAttribute
|
|
85
|
+
};
|
|
86
|
+
}
|
|
87
|
+
/**
|
|
88
|
+
* Add a table to metadata storage
|
|
89
|
+
* @param tableClassName
|
|
90
|
+
* @param options
|
|
91
|
+
*/
|
|
92
|
+
addTable(tableClassName, options) {
|
|
93
|
+
this.#tables[tableClassName] = new TableMetadata_1.default(options);
|
|
94
|
+
}
|
|
95
|
+
/**
|
|
96
|
+
* Add an entity to metadata storage
|
|
97
|
+
* @param entityName
|
|
98
|
+
* @param tableName
|
|
99
|
+
*/
|
|
100
|
+
addEntity(entityClass, tableClassName) {
|
|
101
|
+
this.#entities[entityClass.name] = new EntityMetadata_1.default(entityClass, tableClassName);
|
|
102
|
+
}
|
|
103
|
+
/**
|
|
104
|
+
* Adds a relationship to an Entity's metadata storage
|
|
105
|
+
* @param entityName
|
|
106
|
+
* @param options
|
|
107
|
+
*/
|
|
108
|
+
addEntityRelationship(entityName, options) {
|
|
109
|
+
const entityMetadata = this.#entities[entityName];
|
|
110
|
+
if (entityMetadata.relationships[options.propertyName] === undefined) {
|
|
111
|
+
entityMetadata.relationships[options.propertyName] =
|
|
112
|
+
(0, utils_1.createRelationshipInstance)(options);
|
|
113
|
+
}
|
|
114
|
+
}
|
|
115
|
+
/**
|
|
116
|
+
* Adds JoinTable metadata to storage
|
|
117
|
+
* @param joinTableName
|
|
118
|
+
* @param options
|
|
119
|
+
*/
|
|
120
|
+
addJoinTable(joinTableName, options) {
|
|
121
|
+
const metadata = this.#joinTables[joinTableName];
|
|
122
|
+
if (metadata === undefined) {
|
|
123
|
+
const meta = new JoinTableMetadata_1.default(options.entity, options.foreignKey);
|
|
124
|
+
this.#joinTables[joinTableName] = [meta];
|
|
125
|
+
}
|
|
126
|
+
else if (this.#joinTables[joinTableName].length === 1) {
|
|
127
|
+
// There can only be two tables in a join table
|
|
128
|
+
const meta = new JoinTableMetadata_1.default(options.entity, options.foreignKey);
|
|
129
|
+
this.#joinTables[joinTableName].push(meta);
|
|
130
|
+
}
|
|
131
|
+
}
|
|
132
|
+
/**
|
|
133
|
+
* Adds an attribute to an Entity's metadata storage
|
|
134
|
+
* @param entityName
|
|
135
|
+
* @param options
|
|
136
|
+
*/
|
|
137
|
+
addEntityAttribute(entityName, options) {
|
|
138
|
+
const entityMetadata = this.#entities[entityName];
|
|
139
|
+
const { defaultAttributes } = this.#tables[entityMetadata.tableClassName];
|
|
140
|
+
const defaultAttrMeta = defaultAttributes[options.attributeName];
|
|
141
|
+
// The property is a default field assign it, otherwise instantiate new AttributeMetadata
|
|
142
|
+
const meta = defaultAttrMeta ?? new AttributeMetadata_1.default(options);
|
|
143
|
+
entityMetadata.addAttribute(meta);
|
|
144
|
+
}
|
|
145
|
+
/**
|
|
146
|
+
* Adds the partition key attribute to Table metadata storage
|
|
147
|
+
* @param entityClass
|
|
148
|
+
* @param options
|
|
149
|
+
*/
|
|
150
|
+
addPartitionKeyAttribute(entityClass, options) {
|
|
151
|
+
const tableMetadata = this.getEntityTableMetadata(entityClass);
|
|
152
|
+
if (tableMetadata !== undefined) {
|
|
153
|
+
tableMetadata.addPartitionKeyAttribute(options);
|
|
154
|
+
}
|
|
155
|
+
}
|
|
156
|
+
/**
|
|
157
|
+
* Adds the sort key attribute to Table metadata storage
|
|
158
|
+
* @param entityClass
|
|
159
|
+
* @param options
|
|
160
|
+
*/
|
|
161
|
+
addSortKeyAttribute(entityClass, options) {
|
|
162
|
+
const tableMetadata = this.getEntityTableMetadata(entityClass);
|
|
163
|
+
if (tableMetadata !== undefined) {
|
|
164
|
+
tableMetadata.addSortKeyAttribute(options);
|
|
165
|
+
}
|
|
166
|
+
}
|
|
167
|
+
/**
|
|
168
|
+
* Initialize metadata object
|
|
169
|
+
*/
|
|
170
|
+
init() {
|
|
171
|
+
if (!this.#initialized) {
|
|
172
|
+
// Initialize all entities once to trigger Attribute decorators and fill metadata object
|
|
173
|
+
Object.values(this.#entities).forEach(entityMeta => new entityMeta.EntityClass());
|
|
174
|
+
this.#initialized = true;
|
|
175
|
+
}
|
|
176
|
+
}
|
|
177
|
+
/**
|
|
178
|
+
* Recursively search prototype chain and return TableMetadata for an entity class if it exists
|
|
179
|
+
* @param classPrototype
|
|
180
|
+
* @returns
|
|
181
|
+
*/
|
|
182
|
+
getEntityTableMetadata(classPrototype) {
|
|
183
|
+
const protoType = Object.getPrototypeOf(classPrototype);
|
|
184
|
+
if (protoType === null)
|
|
185
|
+
return;
|
|
186
|
+
if (this.#tables[protoType.constructor.name] !== undefined) {
|
|
187
|
+
return this.#tables[protoType.constructor.name];
|
|
188
|
+
}
|
|
189
|
+
else {
|
|
190
|
+
return this.getEntityTableMetadata(protoType);
|
|
191
|
+
}
|
|
192
|
+
}
|
|
193
|
+
}
|
|
194
|
+
exports.default = MetadataStorage;
|
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
import { AttributeMetadata } from ".";
|
|
2
|
+
import type { TableMetadataOptions, DefaultFields, KeysAttributeMetadataOptions } from "./types";
|
|
3
|
+
export declare const defaultTableKeys: {
|
|
4
|
+
readonly partitionKey: "PK";
|
|
5
|
+
readonly sortKey: "SK";
|
|
6
|
+
};
|
|
7
|
+
/**
|
|
8
|
+
* Default fields with default table alias. Can be overwritten through {@link TableMetadataOptions} defaultFields
|
|
9
|
+
*/
|
|
10
|
+
export declare const tableDefaultFields: Record<DefaultFields, {
|
|
11
|
+
alias: DefaultFields;
|
|
12
|
+
}>;
|
|
13
|
+
/**
|
|
14
|
+
* Represents the metadata for a table within the ORM framework, encapsulating information such as table name, key attributes, and default field mappings. This class is fundamental for defining how entities are mapped to their underlying database tables, providing a schema-like structure that includes both key configuration and default attribute handling.
|
|
15
|
+
*
|
|
16
|
+
* The metadata includes the partition and sort key attributes of the table, which are essential for database operations. It also provides a mechanism to include default attributes and their mappings, supporting common fields like `id`, `type`, `createdAt`, and `updatedAt`, along with their serialization strategies, particularly for date fields.
|
|
17
|
+
*
|
|
18
|
+
* @property {string} name - The name of the table.
|
|
19
|
+
* @property {string} delimiter - A delimiter used in the table's composite keys.
|
|
20
|
+
* @property {Record<DefaultFields, AttributeMetadata>} defaultAttributes - A record of default attributes for the entity, keyed by entity field names.
|
|
21
|
+
* @property {Record<string, AttributeMetadata>} defaultTableAttributes - A record of default attributes for the table, keyed by table field aliases.
|
|
22
|
+
* @property {AttributeMetadata} partitionKeyAttribute - Metadata for the table's partition key attribute.
|
|
23
|
+
* @property {AttributeMetadata} sortKeyAttribute - Metadata for the table's sort key attribute.
|
|
24
|
+
*
|
|
25
|
+
* @param {TableMetadataOptions} options - Configuration options for the table metadata.
|
|
26
|
+
*/
|
|
27
|
+
declare class TableMetadata {
|
|
28
|
+
readonly name: string;
|
|
29
|
+
readonly delimiter: string;
|
|
30
|
+
readonly defaultAttributes: Record<DefaultFields, AttributeMetadata>;
|
|
31
|
+
readonly defaultTableAttributes: Record<string, AttributeMetadata>;
|
|
32
|
+
partitionKeyAttribute: AttributeMetadata;
|
|
33
|
+
sortKeyAttribute: AttributeMetadata;
|
|
34
|
+
constructor(options: TableMetadataOptions);
|
|
35
|
+
/**
|
|
36
|
+
* Creates default attribute metadata. Use {@link tableDefaultFields} unless consuming table decorator specifies overrides
|
|
37
|
+
* @param options - {@link TableMetadataOptions}
|
|
38
|
+
* @returns
|
|
39
|
+
*/
|
|
40
|
+
private buildDefaultAttributesMetadata;
|
|
41
|
+
/**
|
|
42
|
+
* Adds the partition key attribute to Table metadata storage
|
|
43
|
+
* @param options
|
|
44
|
+
*/
|
|
45
|
+
addPartitionKeyAttribute(options: KeysAttributeMetadataOptions): void;
|
|
46
|
+
/**
|
|
47
|
+
* Adds the sort key attribute to Table metadata storage
|
|
48
|
+
* @param options
|
|
49
|
+
*/
|
|
50
|
+
addSortKeyAttribute(options: KeysAttributeMetadataOptions): void;
|
|
51
|
+
}
|
|
52
|
+
export default TableMetadata;
|
|
53
|
+
//# sourceMappingURL=TableMetadata.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"TableMetadata.d.ts","sourceRoot":"","sources":["../../../src/metadata/TableMetadata.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,iBAAiB,EAAE,MAAM,GAAG,CAAC;AAEtC,OAAO,KAAK,EACV,oBAAoB,EACpB,aAAa,EAGb,4BAA4B,EAC7B,MAAM,SAAS,CAAC;AAEjB,eAAO,MAAM,gBAAgB;;;CAAiD,CAAC;AAE/E;;GAEG;AACH,eAAO,MAAM,kBAAkB,EAAE,MAAM,CACrC,aAAa,EACb;IAAE,KAAK,EAAE,aAAa,CAAA;CAAE,CAQhB,CAAC;AAEX;;;;;;;;;;;;;GAaG;AACH,cAAM,aAAa;IACjB,SAAgB,IAAI,EAAE,MAAM,CAAC;IAC7B,SAAgB,SAAS,EAAE,MAAM,CAAC;IAClC,SAAgB,iBAAiB,EAAE,MAAM,CAAC,aAAa,EAAE,iBAAiB,CAAC,CAAC;IAC5E,SAAgB,sBAAsB,EAAE,MAAM,CAAC,MAAM,EAAE,iBAAiB,CAAC,CAAC;IACnE,qBAAqB,EAAE,iBAAiB,CAAC;IACzC,gBAAgB,EAAE,iBAAiB,CAAC;gBAE/B,OAAO,EAAE,oBAAoB;IAsBzC;;;;OAIG;IACH,OAAO,CAAC,8BAA8B;IA+BtC;;;OAGG;IACI,wBAAwB,CAAC,OAAO,EAAE,4BAA4B,GAAG,IAAI;IAK5E;;;OAGG;IACI,mBAAmB,CAAC,OAAO,EAAE,4BAA4B,GAAG,IAAI;CAIxE;AAED,eAAe,aAAa,CAAC"}
|
|
@@ -0,0 +1,100 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.tableDefaultFields = exports.defaultTableKeys = void 0;
|
|
4
|
+
const _1 = require(".");
|
|
5
|
+
const decorators_1 = require("../decorators");
|
|
6
|
+
exports.defaultTableKeys = { partitionKey: "PK", sortKey: "SK" };
|
|
7
|
+
/**
|
|
8
|
+
* Default fields with default table alias. Can be overwritten through {@link TableMetadataOptions} defaultFields
|
|
9
|
+
*/
|
|
10
|
+
exports.tableDefaultFields = {
|
|
11
|
+
id: { alias: "id" },
|
|
12
|
+
type: { alias: "type" },
|
|
13
|
+
createdAt: { alias: "createdAt" },
|
|
14
|
+
updatedAt: { alias: "updatedAt" },
|
|
15
|
+
foreignKey: { alias: "foreignKey" },
|
|
16
|
+
foreignEntityType: { alias: "foreignEntityType" }
|
|
17
|
+
};
|
|
18
|
+
/**
|
|
19
|
+
* Represents the metadata for a table within the ORM framework, encapsulating information such as table name, key attributes, and default field mappings. This class is fundamental for defining how entities are mapped to their underlying database tables, providing a schema-like structure that includes both key configuration and default attribute handling.
|
|
20
|
+
*
|
|
21
|
+
* The metadata includes the partition and sort key attributes of the table, which are essential for database operations. It also provides a mechanism to include default attributes and their mappings, supporting common fields like `id`, `type`, `createdAt`, and `updatedAt`, along with their serialization strategies, particularly for date fields.
|
|
22
|
+
*
|
|
23
|
+
* @property {string} name - The name of the table.
|
|
24
|
+
* @property {string} delimiter - A delimiter used in the table's composite keys.
|
|
25
|
+
* @property {Record<DefaultFields, AttributeMetadata>} defaultAttributes - A record of default attributes for the entity, keyed by entity field names.
|
|
26
|
+
* @property {Record<string, AttributeMetadata>} defaultTableAttributes - A record of default attributes for the table, keyed by table field aliases.
|
|
27
|
+
* @property {AttributeMetadata} partitionKeyAttribute - Metadata for the table's partition key attribute.
|
|
28
|
+
* @property {AttributeMetadata} sortKeyAttribute - Metadata for the table's sort key attribute.
|
|
29
|
+
*
|
|
30
|
+
* @param {TableMetadataOptions} options - Configuration options for the table metadata.
|
|
31
|
+
*/
|
|
32
|
+
class TableMetadata {
|
|
33
|
+
name;
|
|
34
|
+
delimiter;
|
|
35
|
+
defaultAttributes;
|
|
36
|
+
defaultTableAttributes;
|
|
37
|
+
partitionKeyAttribute;
|
|
38
|
+
sortKeyAttribute;
|
|
39
|
+
constructor(options) {
|
|
40
|
+
const defaultAttrMeta = this.buildDefaultAttributesMetadata(options);
|
|
41
|
+
this.name = options.name;
|
|
42
|
+
this.delimiter = options.delimiter;
|
|
43
|
+
this.defaultAttributes = defaultAttrMeta.entityDefaults;
|
|
44
|
+
this.defaultTableAttributes = defaultAttrMeta.tableDefaults;
|
|
45
|
+
// Placeholders, these are set later
|
|
46
|
+
this.partitionKeyAttribute = {
|
|
47
|
+
name: "",
|
|
48
|
+
alias: exports.defaultTableKeys.partitionKey,
|
|
49
|
+
nullable: false,
|
|
50
|
+
serializers: { toEntityAttribute: () => "", toTableAttribute: () => "" }
|
|
51
|
+
};
|
|
52
|
+
this.sortKeyAttribute = {
|
|
53
|
+
name: "",
|
|
54
|
+
alias: exports.defaultTableKeys.sortKey,
|
|
55
|
+
nullable: false,
|
|
56
|
+
serializers: { toEntityAttribute: () => "", toTableAttribute: () => "" }
|
|
57
|
+
};
|
|
58
|
+
}
|
|
59
|
+
/**
|
|
60
|
+
* Creates default attribute metadata. Use {@link tableDefaultFields} unless consuming table decorator specifies overrides
|
|
61
|
+
* @param options - {@link TableMetadataOptions}
|
|
62
|
+
* @returns
|
|
63
|
+
*/
|
|
64
|
+
buildDefaultAttributesMetadata(options) {
|
|
65
|
+
const defaultAttrsMeta = Object.entries(exports.tableDefaultFields);
|
|
66
|
+
const customDefaults = options.defaultFields ?? {};
|
|
67
|
+
return defaultAttrsMeta.reduce((acc, [entityKey, tableKeyAlias]) => {
|
|
68
|
+
const key = entityKey;
|
|
69
|
+
const { alias } = customDefaults[key] ?? tableKeyAlias;
|
|
70
|
+
const dateFields = ["createdAt", "updatedAt"];
|
|
71
|
+
const isDateField = dateFields.includes(entityKey);
|
|
72
|
+
const meta = {
|
|
73
|
+
name: entityKey,
|
|
74
|
+
alias,
|
|
75
|
+
nullable: false,
|
|
76
|
+
serializers: isDateField ? decorators_1.dateSerializer : undefined
|
|
77
|
+
};
|
|
78
|
+
acc.entityDefaults[entityKey] = meta;
|
|
79
|
+
acc.tableDefaults[alias] = meta;
|
|
80
|
+
return acc;
|
|
81
|
+
}, { entityDefaults: {}, tableDefaults: {} });
|
|
82
|
+
}
|
|
83
|
+
/**
|
|
84
|
+
* Adds the partition key attribute to Table metadata storage
|
|
85
|
+
* @param options
|
|
86
|
+
*/
|
|
87
|
+
addPartitionKeyAttribute(options) {
|
|
88
|
+
const opts = { ...options, nullable: false };
|
|
89
|
+
this.partitionKeyAttribute = new _1.AttributeMetadata(opts);
|
|
90
|
+
}
|
|
91
|
+
/**
|
|
92
|
+
* Adds the sort key attribute to Table metadata storage
|
|
93
|
+
* @param options
|
|
94
|
+
*/
|
|
95
|
+
addSortKeyAttribute(options) {
|
|
96
|
+
const opts = { ...options, nullable: false };
|
|
97
|
+
this.sortKeyAttribute = new _1.AttributeMetadata(opts);
|
|
98
|
+
}
|
|
99
|
+
}
|
|
100
|
+
exports.default = TableMetadata;
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import TableMetadata from "./TableMetadata";
|
|
2
|
+
import EntityMetadata from "./EntityMetadata";
|
|
3
|
+
import AttributeMetadata from "./AttributeMetadata";
|
|
4
|
+
import MetadataStorage from "./MetadataStorage";
|
|
5
|
+
import JoinTableMetadata from "./JoinTableMetadata";
|
|
6
|
+
declare const _default: MetadataStorage;
|
|
7
|
+
export default _default;
|
|
8
|
+
export { TableMetadata, EntityMetadata, AttributeMetadata, JoinTableMetadata };
|
|
9
|
+
export * from "./MetadataStorage";
|
|
10
|
+
export * from "./TableMetadata";
|
|
11
|
+
export * from "./relationship-metadata";
|
|
12
|
+
export * from "./types";
|
|
13
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/metadata/index.ts"],"names":[],"mappings":"AAAA,OAAO,aAAa,MAAM,iBAAiB,CAAC;AAC5C,OAAO,cAAc,MAAM,kBAAkB,CAAC;AAC9C,OAAO,iBAAiB,MAAM,qBAAqB,CAAC;AACpD,OAAO,eAAe,MAAM,mBAAmB,CAAC;AAChD,OAAO,iBAAiB,MAAM,qBAAqB,CAAC;;AAEpD,wBAAqC;AACrC,OAAO,EAAE,aAAa,EAAE,cAAc,EAAE,iBAAiB,EAAE,iBAAiB,EAAE,CAAC;AAE/E,cAAc,mBAAmB,CAAC;AAClC,cAAc,iBAAiB,CAAC;AAChC,cAAc,yBAAyB,CAAC;AACxC,cAAc,SAAS,CAAC"}
|
|
@@ -0,0 +1,34 @@
|
|
|
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.JoinTableMetadata = exports.AttributeMetadata = exports.EntityMetadata = exports.TableMetadata = void 0;
|
|
21
|
+
const TableMetadata_1 = __importDefault(require("./TableMetadata"));
|
|
22
|
+
exports.TableMetadata = TableMetadata_1.default;
|
|
23
|
+
const EntityMetadata_1 = __importDefault(require("./EntityMetadata"));
|
|
24
|
+
exports.EntityMetadata = EntityMetadata_1.default;
|
|
25
|
+
const AttributeMetadata_1 = __importDefault(require("./AttributeMetadata"));
|
|
26
|
+
exports.AttributeMetadata = AttributeMetadata_1.default;
|
|
27
|
+
const MetadataStorage_1 = __importDefault(require("./MetadataStorage"));
|
|
28
|
+
const JoinTableMetadata_1 = __importDefault(require("./JoinTableMetadata"));
|
|
29
|
+
exports.JoinTableMetadata = JoinTableMetadata_1.default;
|
|
30
|
+
exports.default = new MetadataStorage_1.default();
|
|
31
|
+
__exportStar(require("./MetadataStorage"), exports);
|
|
32
|
+
__exportStar(require("./TableMetadata"), exports);
|
|
33
|
+
__exportStar(require("./relationship-metadata"), exports);
|
|
34
|
+
__exportStar(require("./types"), exports);
|