dyna-record 0.1.5 → 0.2.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +11 -13
- package/dist/src/DynaRecord.d.ts +36 -28
- package/dist/src/DynaRecord.d.ts.map +1 -1
- package/dist/src/DynaRecord.js +39 -36
- package/dist/src/decorators/Table.d.ts.map +1 -1
- package/dist/src/decorators/attributes/BooleanAttribute.d.ts.map +1 -1
- package/dist/src/decorators/attributes/DateAttribute.d.ts.map +1 -1
- package/dist/src/decorators/attributes/EnumAttribute.d.ts.map +1 -1
- package/dist/src/decorators/attributes/ForeignKeyAttribute.d.ts.map +1 -1
- package/dist/src/decorators/attributes/NumberAttribute.d.ts.map +1 -1
- package/dist/src/decorators/attributes/PartitionKeyAttribute.d.ts.map +1 -1
- package/dist/src/decorators/attributes/SortKeyAttribute.d.ts.map +1 -1
- package/dist/src/decorators/attributes/StringAttribute.d.ts.map +1 -1
- package/dist/src/decorators/attributes/serializers.d.ts +1 -1
- package/dist/src/decorators/relationships/BelongsTo.d.ts.map +1 -1
- package/dist/src/decorators/relationships/HasAndBelongsToMany.d.ts.map +1 -1
- package/dist/src/decorators/relationships/HasMany.d.ts.map +1 -1
- package/dist/src/decorators/relationships/HasOne.d.ts.map +1 -1
- package/dist/src/decorators/types.d.ts +2 -2
- package/dist/src/decorators/types.d.ts.map +1 -1
- package/dist/src/dynamo-utils/TransactGetBuilder.d.ts +4 -0
- package/dist/src/dynamo-utils/TransactGetBuilder.d.ts.map +1 -1
- package/dist/src/dynamo-utils/TransactGetBuilder.js +6 -0
- package/dist/src/metadata/EntityMetadata.d.ts +13 -1
- package/dist/src/metadata/EntityMetadata.d.ts.map +1 -1
- package/dist/src/metadata/EntityMetadata.js +21 -0
- package/dist/src/metadata/TableMetadata.d.ts.map +1 -1
- package/dist/src/metadata/TableMetadata.js +1 -3
- package/dist/src/metadata/relationship-metadata/types.d.ts +4 -0
- package/dist/src/metadata/relationship-metadata/types.d.ts.map +1 -1
- package/dist/src/metadata/types.d.ts +2 -3
- package/dist/src/metadata/types.d.ts.map +1 -1
- package/dist/src/metadata/utils.d.ts.map +1 -1
- package/dist/src/operations/Create/Create.d.ts +95 -16
- package/dist/src/operations/Create/Create.d.ts.map +1 -1
- package/dist/src/operations/Create/Create.js +170 -22
- package/dist/src/operations/Delete/Delete.d.ts +29 -25
- package/dist/src/operations/Delete/Delete.d.ts.map +1 -1
- package/dist/src/operations/Delete/Delete.js +105 -104
- package/dist/src/operations/Delete/types.d.ts +0 -3
- package/dist/src/operations/Delete/types.d.ts.map +1 -1
- package/dist/src/operations/FindById/FindById.d.ts +7 -28
- package/dist/src/operations/FindById/FindById.d.ts.map +1 -1
- package/dist/src/operations/FindById/FindById.js +36 -125
- package/dist/src/operations/FindById/types.d.ts +8 -9
- package/dist/src/operations/FindById/types.d.ts.map +1 -1
- package/dist/src/operations/Query/Query.d.ts +2 -1
- package/dist/src/operations/Query/Query.d.ts.map +1 -1
- package/dist/src/operations/Query/Query.js +17 -4
- package/dist/src/operations/Query/types.d.ts +39 -5
- package/dist/src/operations/Query/types.d.ts.map +1 -1
- package/dist/src/operations/Update/Update.d.ts +185 -24
- package/dist/src/operations/Update/Update.d.ts.map +1 -1
- package/dist/src/operations/Update/Update.js +402 -72
- package/dist/src/operations/Update/UpdateDryRun.d.ts +10 -0
- package/dist/src/operations/Update/UpdateDryRun.d.ts.map +1 -0
- package/dist/src/operations/Update/UpdateDryRun.js +15 -0
- package/dist/src/operations/Update/index.d.ts +1 -0
- package/dist/src/operations/Update/index.d.ts.map +1 -1
- package/dist/src/operations/Update/index.js +3 -1
- package/dist/src/operations/types.d.ts +6 -1
- package/dist/src/operations/types.d.ts.map +1 -1
- package/dist/src/operations/utils/expressionBuilder.d.ts.map +1 -1
- package/dist/src/operations/utils/expressionBuilder.js +1 -4
- package/dist/src/operations/utils/index.d.ts +0 -1
- package/dist/src/operations/utils/index.d.ts.map +1 -1
- package/dist/src/operations/utils/index.js +0 -6
- package/dist/src/operations/utils/utils.d.ts +13 -3
- package/dist/src/operations/utils/utils.d.ts.map +1 -1
- package/dist/src/operations/utils/utils.js +33 -3
- package/dist/src/query-utils/Filters.d.ts +1 -1
- package/dist/src/query-utils/Filters.d.ts.map +1 -1
- package/dist/src/query-utils/Filters.js +7 -15
- package/dist/src/query-utils/QueryBuilder.d.ts.map +1 -1
- package/dist/src/query-utils/QueryBuilder.js +9 -1
- package/dist/src/relationships/JoinTable.d.ts +17 -7
- package/dist/src/relationships/JoinTable.d.ts.map +1 -1
- package/dist/src/relationships/JoinTable.js +77 -20
- package/dist/src/relationships/index.d.ts +0 -1
- package/dist/src/relationships/index.d.ts.map +1 -1
- package/dist/src/relationships/index.js +1 -3
- package/dist/src/types.d.ts +6 -8
- package/dist/src/types.d.ts.map +1 -1
- package/dist/src/utils.d.ts +10 -32
- package/dist/src/utils.d.ts.map +1 -1
- package/dist/src/utils.js +13 -59
- package/package.json +4 -4
- package/dist/src/operations/utils/RelationshipTransactions.d.ts +0 -64
- package/dist/src/operations/utils/RelationshipTransactions.d.ts.map +0 -1
- package/dist/src/operations/utils/RelationshipTransactions.js +0 -125
- package/dist/src/relationships/BelongsToLink.d.ts +0 -51
- package/dist/src/relationships/BelongsToLink.d.ts.map +0 -1
- package/dist/src/relationships/BelongsToLink.js +0 -57
|
@@ -13,13 +13,7 @@ var __createBinding = (this && this.__createBinding) || (Object.create ? (functi
|
|
|
13
13
|
var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
14
14
|
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
15
15
|
};
|
|
16
|
-
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
17
|
-
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
18
|
-
};
|
|
19
16
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
20
|
-
exports.RelationshipTransactions = void 0;
|
|
21
|
-
var RelationshipTransactions_1 = require("./RelationshipTransactions");
|
|
22
|
-
Object.defineProperty(exports, "RelationshipTransactions", { enumerable: true, get: function () { return __importDefault(RelationshipTransactions_1).default; } });
|
|
23
17
|
__exportStar(require("./expressionBuilder"), exports);
|
|
24
18
|
__exportStar(require("./types"), exports);
|
|
25
19
|
__exportStar(require("./utils"), exports);
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import type DynaRecord from "../../DynaRecord";
|
|
2
|
-
import type { RelationshipMetadata } from "../../metadata";
|
|
3
|
-
import type { ForeignKey, Optional, RelationshipMetaObj } from "../../types";
|
|
2
|
+
import type { BelongsToRelationship, RelationshipMetadata } from "../../metadata";
|
|
3
|
+
import type { DynamoTableItem, EntityClass, ForeignKey, Optional, RelationshipMetaObj } from "../../types";
|
|
4
|
+
import { type EntityAttributesOnly } from "../types";
|
|
4
5
|
/**
|
|
5
6
|
* Creates an object including
|
|
6
7
|
* - relationsLookup: Object to look up RelationshipMetadata by Entity name
|
|
@@ -15,5 +16,14 @@ export declare const buildEntityRelationshipMetaObj: (relationships: Relationshi
|
|
|
15
16
|
* @param entity - instance of DynaRecord
|
|
16
17
|
* @returns
|
|
17
18
|
*/
|
|
18
|
-
export declare const extractForeignKeyFromEntity: <T extends DynaRecord
|
|
19
|
+
export declare const extractForeignKeyFromEntity: <T extends Partial<EntityAttributesOnly<DynaRecord>>>(relMeta: RelationshipMetadata, entity: T) => Optional<ForeignKey>;
|
|
20
|
+
/**
|
|
21
|
+
* Creates the PK and SK (key) for a table item that BelongsTo another as HasMany or HasOne
|
|
22
|
+
* @param entityClass
|
|
23
|
+
* @param entityId
|
|
24
|
+
* @param relMeta
|
|
25
|
+
* @param foreignKey
|
|
26
|
+
* @returns
|
|
27
|
+
*/
|
|
28
|
+
export declare const buildBelongsToLinkKey: (entityClass: EntityClass<DynaRecord>, entityId: string, relMeta: BelongsToRelationship, foreignKey: string) => DynamoTableItem;
|
|
19
29
|
//# sourceMappingURL=utils.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"utils.d.ts","sourceRoot":"","sources":["../../../../src/operations/utils/utils.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,UAAU,MAAM,kBAAkB,CAAC;AAC/C,OAAO,KAAK,
|
|
1
|
+
{"version":3,"file":"utils.d.ts","sourceRoot":"","sources":["../../../../src/operations/utils/utils.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,UAAU,MAAM,kBAAkB,CAAC;AAC/C,OAAO,KAAK,EACV,qBAAqB,EACrB,oBAAoB,EACrB,MAAM,gBAAgB,CAAC;AAQxB,OAAO,KAAK,EACV,eAAe,EACf,WAAW,EACX,UAAU,EACV,QAAQ,EACR,mBAAmB,EACpB,MAAM,aAAa,CAAC;AAErB,OAAO,EAAE,KAAK,oBAAoB,EAAE,MAAM,UAAU,CAAC;AAErD;;;;;;GAMG;AACH,eAAO,MAAM,8BAA8B,kBAC1B,oBAAoB,EAAE,KACpC,mBAaF,CAAC;AAEF;;;;;GAKG;AACH,eAAO,MAAM,2BAA2B,GACtC,CAAC,SAAS,OAAO,CAAC,oBAAoB,CAAC,UAAU,CAAC,CAAC,WAE1C,oBAAoB,UACrB,CAAC,KACR,QAAQ,CAAC,UAAU,CAKrB,CAAC;AAEF;;;;;;;GAOG;AACH,eAAO,MAAM,qBAAqB,gBACnB,WAAW,CAAC,UAAU,CAAC,YAC1B,MAAM,WACP,qBAAqB,cAClB,MAAM,KACjB,eAqBF,CAAC"}
|
|
@@ -1,6 +1,10 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
2
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.extractForeignKeyFromEntity = exports.buildEntityRelationshipMetaObj = void 0;
|
|
6
|
+
exports.buildBelongsToLinkKey = exports.extractForeignKeyFromEntity = exports.buildEntityRelationshipMetaObj = void 0;
|
|
7
|
+
const metadata_1 = __importDefault(require("../../metadata"));
|
|
4
8
|
const utils_1 = require("../../metadata/utils");
|
|
5
9
|
const utils_2 = require("../../utils");
|
|
6
10
|
/**
|
|
@@ -27,10 +31,36 @@ exports.buildEntityRelationshipMetaObj = buildEntityRelationshipMetaObj;
|
|
|
27
31
|
* @returns
|
|
28
32
|
*/
|
|
29
33
|
const extractForeignKeyFromEntity = (relMeta, entity) => {
|
|
30
|
-
return
|
|
31
|
-
(0, utils_1.isRelationshipMetadataWithForeignKey)(relMeta) &&
|
|
34
|
+
return (0, utils_1.isRelationshipMetadataWithForeignKey)(relMeta) &&
|
|
32
35
|
(0, utils_2.isKeyOfObject)(entity, relMeta.foreignKey)
|
|
33
36
|
? entity[relMeta.foreignKey]
|
|
34
37
|
: undefined;
|
|
35
38
|
};
|
|
36
39
|
exports.extractForeignKeyFromEntity = extractForeignKeyFromEntity;
|
|
40
|
+
/**
|
|
41
|
+
* Creates the PK and SK (key) for a table item that BelongsTo another as HasMany or HasOne
|
|
42
|
+
* @param entityClass
|
|
43
|
+
* @param entityId
|
|
44
|
+
* @param relMeta
|
|
45
|
+
* @param foreignKey
|
|
46
|
+
* @returns
|
|
47
|
+
*/
|
|
48
|
+
const buildBelongsToLinkKey = (entityClass, entityId, relMeta, foreignKey) => {
|
|
49
|
+
const tableMeta = metadata_1.default.getEntityTable(entityClass.name);
|
|
50
|
+
const partitionKeyAlias = tableMeta.partitionKeyAttribute.alias;
|
|
51
|
+
const sortKeyAlias = tableMeta.sortKeyAttribute.alias;
|
|
52
|
+
if ((0, utils_1.doesEntityBelongToRelAsHasMany)(entityClass, relMeta)) {
|
|
53
|
+
return {
|
|
54
|
+
[partitionKeyAlias]: relMeta.target.partitionKeyValue(foreignKey),
|
|
55
|
+
[sortKeyAlias]: entityClass.partitionKeyValue(entityId)
|
|
56
|
+
};
|
|
57
|
+
}
|
|
58
|
+
if ((0, utils_1.doesEntityBelongToRelAsHasOne)(entityClass, relMeta)) {
|
|
59
|
+
return {
|
|
60
|
+
[partitionKeyAlias]: relMeta.target.partitionKeyValue(foreignKey),
|
|
61
|
+
[sortKeyAlias]: entityClass.name
|
|
62
|
+
};
|
|
63
|
+
}
|
|
64
|
+
throw new Error("Failed to build BelongsTo key for linked record");
|
|
65
|
+
};
|
|
66
|
+
exports.buildBelongsToLinkKey = buildBelongsToLinkKey;
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { type RelationshipMetadata } from "../metadata";
|
|
2
2
|
import { type OrFilter } from "./types";
|
|
3
3
|
/**
|
|
4
|
-
* Builds the filter so that relationships that are included in the query will have their
|
|
4
|
+
* Builds the filter so that relationships that are included in the query will have their relationships included in the query
|
|
5
5
|
* @param parentClassName
|
|
6
6
|
* @param includedRelationships
|
|
7
7
|
* @returns
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Filters.d.ts","sourceRoot":"","sources":["../../../src/query-utils/Filters.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,oBAAoB,EAAE,MAAM,aAAa,CAAC;AACxD,OAAO,EAAE,KAAK,QAAQ,EAAE,MAAM,SAAS,CAAC;
|
|
1
|
+
{"version":3,"file":"Filters.d.ts","sourceRoot":"","sources":["../../../src/query-utils/Filters.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,oBAAoB,EAAE,MAAM,aAAa,CAAC;AACxD,OAAO,EAAE,KAAK,QAAQ,EAAE,MAAM,SAAS,CAAC;AAExC;;;;;GAKG;AACH,wBAAgB,2BAA2B,CACzC,eAAe,EAAE,MAAM,EACvB,qBAAqB,EAAE,oBAAoB,EAAE,GAC5C,QAAQ,CASV"}
|
|
@@ -1,25 +1,17 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.includedRelationshipsFilter =
|
|
4
|
-
const relationships_1 = require("../relationships");
|
|
3
|
+
exports.includedRelationshipsFilter = includedRelationshipsFilter;
|
|
5
4
|
/**
|
|
6
|
-
* Builds the filter so that relationships that are included in the query will have their
|
|
5
|
+
* Builds the filter so that relationships that are included in the query will have their relationships included in the query
|
|
7
6
|
* @param parentClassName
|
|
8
7
|
* @param includedRelationships
|
|
9
8
|
* @returns
|
|
10
9
|
*/
|
|
11
10
|
function includedRelationshipsFilter(parentClassName, includedRelationships) {
|
|
12
|
-
const
|
|
13
|
-
|
|
14
|
-
rel
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
const belongsToFilter = {
|
|
18
|
-
type: relationships_1.BelongsToLink.name,
|
|
19
|
-
foreignEntityType: includedRelationships.map(rel => rel.target.name)
|
|
20
|
-
};
|
|
21
|
-
filters.push(belongsToFilter);
|
|
22
|
-
}
|
|
11
|
+
const includedTypes = [
|
|
12
|
+
parentClassName,
|
|
13
|
+
...includedRelationships.map(rel => rel.target.name)
|
|
14
|
+
];
|
|
15
|
+
const filters = [{ type: includedTypes }];
|
|
23
16
|
return { $or: filters };
|
|
24
17
|
}
|
|
25
|
-
exports.includedRelationshipsFilter = includedRelationshipsFilter;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"QueryBuilder.d.ts","sourceRoot":"","sources":["../../../src/query-utils/QueryBuilder.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,iBAAiB,EAAE,MAAM,uBAAuB,CAAC;AAO/D,OAAO,KAAK,EASV,iBAAiB,EAClB,MAAM,SAAS,CAAC;AAEjB;;;;GAIG;AACH,cAAM,YAAY;;
|
|
1
|
+
{"version":3,"file":"QueryBuilder.d.ts","sourceRoot":"","sources":["../../../src/query-utils/QueryBuilder.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,iBAAiB,EAAE,MAAM,uBAAuB,CAAC;AAO/D,OAAO,KAAK,EASV,iBAAiB,EAClB,MAAM,SAAS,CAAC;AAEjB;;;;GAIG;AACH,cAAM,YAAY;;gBASJ,KAAK,EAAE,iBAAiB;IAmBpC;;;OAGG;IACI,KAAK,IAAI,iBAAiB;IAuBjC;;;;;OAKG;IACH,OAAO,CAAC,8BAA8B;IAetC;;;OAGG;IACH,OAAO,CAAC,wBAAwB;IAgChC;;;;;;;;;OASG;IACH,OAAO,CAAC,YAAY;IAWpB;;;;OAIG;IACH,OAAO,CAAC,WAAW;IASnB;;;;OAIG;IACH,OAAO,CAAC,SAAS;IAejB;;;;;OAKG;IACH,OAAO,CAAC,YAAY;IAyBpB;;;;OAIG;IACH,OAAO,CAAC,QAAQ;IAehB;;;;OAIG;IACH,OAAO,CAAC,WAAW;IAanB;;;;OAIG;IACH,OAAO,CAAC,kBAAkB;IAI1B;;;;OAIG;IACH,OAAO,CAAC,aAAa;IAIrB;;;;OAIG;IACH,OAAO,CAAC,UAAU;CAGnB;AAED,eAAe,YAAY,CAAC"}
|
|
@@ -12,6 +12,9 @@ const metadata_1 = __importDefault(require("../metadata"));
|
|
|
12
12
|
class QueryBuilder {
|
|
13
13
|
#props;
|
|
14
14
|
#tableMetadata;
|
|
15
|
+
/**
|
|
16
|
+
* Attributes of the entity and any related entities that are possible to query on
|
|
17
|
+
*/
|
|
15
18
|
#attributeMetadata;
|
|
16
19
|
#attrCounter;
|
|
17
20
|
constructor(props) {
|
|
@@ -19,7 +22,12 @@ class QueryBuilder {
|
|
|
19
22
|
this.#attrCounter = 0;
|
|
20
23
|
const entityMetadata = metadata_1.default.getEntity(props.entityClassName);
|
|
21
24
|
this.#tableMetadata = metadata_1.default.getTable(entityMetadata.tableClassName);
|
|
22
|
-
|
|
25
|
+
const relationshipsAttributesMeta = Object.values(entityMetadata.relationships).map(relMeta => metadata_1.default.getEntityAttributes(relMeta.target.name));
|
|
26
|
+
const entityAttrMeta = metadata_1.default.getEntityAttributes(props.entityClassName);
|
|
27
|
+
const allAttrMeta = [...relationshipsAttributesMeta, entityAttrMeta];
|
|
28
|
+
this.#attributeMetadata = allAttrMeta.reduce((allAttrMeta, attrMeta) => {
|
|
29
|
+
return { ...allAttrMeta, ...attrMeta };
|
|
30
|
+
}, {});
|
|
23
31
|
}
|
|
24
32
|
/**
|
|
25
33
|
* Builds and returns the `QueryCommandInput` for a DynamoDB query operation.
|
|
@@ -13,7 +13,7 @@ type ForeignKeyProperties<T> = {
|
|
|
13
13
|
/**
|
|
14
14
|
* Abstract class representing a join table for HasAndBelongsToMany relationships.
|
|
15
15
|
* This class should be extended for specific join table implementations.
|
|
16
|
-
* It is virtual and not persisted to the database but manages the
|
|
16
|
+
* It is virtual and not persisted to the database but manages the denormalized records
|
|
17
17
|
* in each related entity's partition.
|
|
18
18
|
*
|
|
19
19
|
* Example:
|
|
@@ -30,39 +30,49 @@ declare abstract class JoinTable<T extends DynaRecord, K extends DynaRecord> {
|
|
|
30
30
|
constructor(type1: EntityClass<T>, type2: EntityClass<K>);
|
|
31
31
|
/**
|
|
32
32
|
* Create a JoinTable entry
|
|
33
|
-
* Adds
|
|
33
|
+
* Adds denormalized copy of the related entity to each associated Entity's partition
|
|
34
34
|
* @param this
|
|
35
35
|
* @param keys
|
|
36
36
|
*/
|
|
37
37
|
static create<ThisClass extends JoinTable<T, K>, T extends DynaRecord, K extends DynaRecord>(this: new (type1: EntityClass<T>, type2: EntityClass<K>) => ThisClass, keys: ForeignKeyProperties<ThisClass>): Promise<void>;
|
|
38
38
|
/**
|
|
39
39
|
* Delete a JoinTable entry
|
|
40
|
-
* Deletes
|
|
40
|
+
* Deletes denormalized records from each associated Entity's partition
|
|
41
41
|
* @param this
|
|
42
42
|
* @param keys
|
|
43
43
|
*/
|
|
44
44
|
static delete<ThisClass extends JoinTable<T, K>, T extends DynaRecord, K extends DynaRecord>(this: new (type1: EntityClass<T>, type2: EntityClass<K>) => ThisClass, keys: ForeignKeyProperties<ThisClass>): Promise<void>;
|
|
45
|
+
private static preFetch;
|
|
45
46
|
/**
|
|
46
47
|
* Creates transactions:
|
|
47
|
-
* 1. Create a
|
|
48
|
+
* 1. Create a denormalized record in parents partition if its not already linked
|
|
48
49
|
* 2. Ensures that the parent EntityExists
|
|
49
50
|
* @param transactionBuilder
|
|
50
51
|
* @param keys
|
|
51
52
|
* @param parentEntityMeta
|
|
52
53
|
* @param linkedEntityMeta
|
|
53
54
|
*/
|
|
54
|
-
private static
|
|
55
|
+
private static denormalizeLinkRecord;
|
|
56
|
+
/**
|
|
57
|
+
* Builds the key to the foreign entity
|
|
58
|
+
* @param tableProps
|
|
59
|
+
* @param parentEntity
|
|
60
|
+
* @param linkedEntityId
|
|
61
|
+
* @returns
|
|
62
|
+
*/
|
|
63
|
+
private static buildForeignEntityKey;
|
|
55
64
|
/**
|
|
56
65
|
* Deletes transactions:
|
|
57
|
-
* 1. Delete a
|
|
66
|
+
* 1. Delete a denormalized record in parents partition if its linked
|
|
58
67
|
* @param transactionBuilder
|
|
59
68
|
* @param keys
|
|
60
69
|
* @param parentEntityMeta
|
|
61
70
|
* @param linkedEntityMeta
|
|
62
71
|
*/
|
|
63
|
-
private static
|
|
72
|
+
private static deleteLink;
|
|
64
73
|
private static joinTableKey;
|
|
65
74
|
private static transactionProps;
|
|
75
|
+
private static preFetchNotFoundErrorMessage;
|
|
66
76
|
}
|
|
67
77
|
export default JoinTable;
|
|
68
78
|
//# sourceMappingURL=JoinTable.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"JoinTable.d.ts","sourceRoot":"","sources":["../../../src/relationships/JoinTable.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,UAAU,MAAM,eAAe,CAAC;
|
|
1
|
+
{"version":3,"file":"JoinTable.d.ts","sourceRoot":"","sources":["../../../src/relationships/JoinTable.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,UAAU,MAAM,eAAe,CAAC;AAW5C,OAAO,KAAK,EAAE,UAAU,EAAE,WAAW,EAAmB,MAAM,UAAU,CAAC;AAEzE;;GAEG;AACH,KAAK,WAAW,GAAG,OAAO,GAAG,OAAO,CAAC;AAOrC;;GAEG;AACH,KAAK,oBAAoB,CAAC,CAAC,IAAI;KAC5B,CAAC,IAAI,OAAO,CAAC,MAAM,CAAC,EAAE,WAAW,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,SAAS,UAAU,GACzD,MAAM,GACN,KAAK;CACV,CAAC;AAqBF;;;;;;;;;;;;;GAaG;AACH,uBAAe,SAAS,CAAC,CAAC,SAAS,UAAU,EAAE,CAAC,SAAS,UAAU;IAE/D,OAAO,CAAC,QAAQ,CAAC,KAAK;IACtB,OAAO,CAAC,QAAQ,CAAC,KAAK;gBADL,KAAK,EAAE,WAAW,CAAC,CAAC,CAAC,EACrB,KAAK,EAAE,WAAW,CAAC,CAAC,CAAC;IAGxC;;;;;OAKG;WACiB,MAAM,CACxB,SAAS,SAAS,SAAS,CAAC,CAAC,EAAE,CAAC,CAAC,EACjC,CAAC,SAAS,UAAU,EACpB,CAAC,SAAS,UAAU,EAEpB,IAAI,EAAE,KAAK,KAAK,EAAE,WAAW,CAAC,CAAC,CAAC,EAAE,KAAK,EAAE,WAAW,CAAC,CAAC,CAAC,KAAK,SAAS,EACrE,IAAI,EAAE,oBAAoB,CAAC,SAAS,CAAC,GACpC,OAAO,CAAC,IAAI,CAAC;IAyBhB;;;;;OAKG;WACiB,MAAM,CACxB,SAAS,SAAS,SAAS,CAAC,CAAC,EAAE,CAAC,CAAC,EACjC,CAAC,SAAS,UAAU,EACpB,CAAC,SAAS,UAAU,EAEpB,IAAI,EAAE,KAAK,KAAK,EAAE,WAAW,CAAC,CAAC,CAAC,EAAE,KAAK,EAAE,WAAW,CAAC,CAAC,CAAC,KAAK,SAAS,EACrE,IAAI,EAAE,oBAAoB,CAAC,SAAS,CAAC,GACpC,OAAO,CAAC,IAAI,CAAC;mBAWK,QAAQ;IAmD7B;;;;;;;;OAQG;IACH,OAAO,CAAC,MAAM,CAAC,qBAAqB;IA2CpC;;;;;;OAMG;IACH,OAAO,CAAC,MAAM,CAAC,qBAAqB;IAcpC;;;;;;;OAOG;IACH,OAAO,CAAC,MAAM,CAAC,UAAU;IA0BzB,OAAO,CAAC,MAAM,CAAC,YAAY;IAoB3B,OAAO,CAAC,MAAM,CAAC,gBAAgB;IAoB/B,OAAO,CAAC,MAAM,CAAC,4BAA4B;CA6B5C;AAED,eAAe,SAAS,CAAC"}
|
|
@@ -3,14 +3,14 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
3
3
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
4
|
};
|
|
5
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
const dynamo_utils_1 = require("../dynamo-utils");
|
|
6
7
|
const TransactWriteBuilder_1 = __importDefault(require("../dynamo-utils/TransactWriteBuilder"));
|
|
8
|
+
const errors_1 = require("../errors");
|
|
7
9
|
const metadata_1 = __importDefault(require("../metadata"));
|
|
8
|
-
const utils_1 = require("../utils");
|
|
9
|
-
const BelongsToLink_1 = __importDefault(require("./BelongsToLink"));
|
|
10
10
|
/**
|
|
11
11
|
* Abstract class representing a join table for HasAndBelongsToMany relationships.
|
|
12
12
|
* This class should be extended for specific join table implementations.
|
|
13
|
-
* It is virtual and not persisted to the database but manages the
|
|
13
|
+
* It is virtual and not persisted to the database but manages the denormalized records
|
|
14
14
|
* in each related entity's partition.
|
|
15
15
|
*
|
|
16
16
|
* Example:
|
|
@@ -30,72 +30,111 @@ class JoinTable {
|
|
|
30
30
|
}
|
|
31
31
|
/**
|
|
32
32
|
* Create a JoinTable entry
|
|
33
|
-
* Adds
|
|
33
|
+
* Adds denormalized copy of the related entity to each associated Entity's partition
|
|
34
34
|
* @param this
|
|
35
35
|
* @param keys
|
|
36
36
|
*/
|
|
37
37
|
static async create(keys) {
|
|
38
38
|
const transactionBuilder = new TransactWriteBuilder_1.default();
|
|
39
39
|
const [rel1, rel2] = metadata_1.default.getJoinTable(this.name);
|
|
40
|
-
JoinTable.
|
|
41
|
-
JoinTable.
|
|
40
|
+
const transactionProps = JoinTable.transactionProps(keys, rel2, rel1);
|
|
41
|
+
const lookupTableItem = await JoinTable.preFetch(transactionProps);
|
|
42
|
+
JoinTable.denormalizeLinkRecord(transactionBuilder, keys, rel1, rel2, lookupTableItem[transactionProps.ids.linkedEntityId]);
|
|
43
|
+
JoinTable.denormalizeLinkRecord(transactionBuilder, keys, rel2, rel1, lookupTableItem[transactionProps.ids.parentId]);
|
|
42
44
|
await transactionBuilder.executeTransaction();
|
|
43
45
|
}
|
|
44
46
|
/**
|
|
45
47
|
* Delete a JoinTable entry
|
|
46
|
-
* Deletes
|
|
48
|
+
* Deletes denormalized records from each associated Entity's partition
|
|
47
49
|
* @param this
|
|
48
50
|
* @param keys
|
|
49
51
|
*/
|
|
50
52
|
static async delete(keys) {
|
|
51
53
|
const transactionBuilder = new TransactWriteBuilder_1.default();
|
|
52
54
|
const [rel1, rel2] = metadata_1.default.getJoinTable(this.name);
|
|
53
|
-
JoinTable.
|
|
54
|
-
JoinTable.
|
|
55
|
+
JoinTable.deleteLink(transactionBuilder, keys, rel1, rel2);
|
|
56
|
+
JoinTable.deleteLink(transactionBuilder, keys, rel2, rel1);
|
|
55
57
|
await transactionBuilder.executeTransaction();
|
|
56
58
|
}
|
|
59
|
+
static async preFetch(transactionProps) {
|
|
60
|
+
const { tableProps, entities, ids } = transactionProps;
|
|
61
|
+
const idAlias = tableProps.defaultAttributes.id.alias;
|
|
62
|
+
const parentKey = JoinTable.buildForeignEntityKey(tableProps, entities.linkedEntity, ids.parentId);
|
|
63
|
+
const linkedKey = JoinTable.buildForeignEntityKey(tableProps, entities.parentEntity, ids.linkedEntityId);
|
|
64
|
+
const transactionGetBuilder = new dynamo_utils_1.TransactGetBuilder();
|
|
65
|
+
transactionGetBuilder.addGet({
|
|
66
|
+
TableName: tableProps.name,
|
|
67
|
+
Key: parentKey
|
|
68
|
+
});
|
|
69
|
+
transactionGetBuilder.addGet({
|
|
70
|
+
TableName: tableProps.name,
|
|
71
|
+
Key: linkedKey
|
|
72
|
+
});
|
|
73
|
+
const transactionResults = await transactionGetBuilder.executeTransaction();
|
|
74
|
+
if (transactionResults.length !== 2) {
|
|
75
|
+
const errorMessage = this.preFetchNotFoundErrorMessage(transactionResults, entities, ids);
|
|
76
|
+
throw new errors_1.NotFoundError(errorMessage);
|
|
77
|
+
}
|
|
78
|
+
return transactionResults.reduce((acc, res) => {
|
|
79
|
+
if (res.Item !== undefined) {
|
|
80
|
+
acc[res.Item[idAlias]] = res.Item;
|
|
81
|
+
}
|
|
82
|
+
return acc;
|
|
83
|
+
}, {});
|
|
84
|
+
}
|
|
57
85
|
/**
|
|
58
86
|
* Creates transactions:
|
|
59
|
-
* 1. Create a
|
|
87
|
+
* 1. Create a denormalized record in parents partition if its not already linked
|
|
60
88
|
* 2. Ensures that the parent EntityExists
|
|
61
89
|
* @param transactionBuilder
|
|
62
90
|
* @param keys
|
|
63
91
|
* @param parentEntityMeta
|
|
64
92
|
* @param linkedEntityMeta
|
|
65
93
|
*/
|
|
66
|
-
static
|
|
94
|
+
static denormalizeLinkRecord(transactionBuilder, keys, parentEntityMeta, linkedEntityMeta, linkedRecord) {
|
|
67
95
|
const { tableProps, entities, ids } = this.transactionProps(keys, parentEntityMeta, linkedEntityMeta);
|
|
68
96
|
const { name: tableName } = tableProps;
|
|
69
97
|
const { alias: partitionKeyAlias } = tableProps.partitionKeyAttribute;
|
|
70
|
-
const { alias: sortKeyAlias } = tableProps.sortKeyAttribute;
|
|
71
98
|
const { parentEntity, linkedEntity } = entities;
|
|
72
99
|
const { parentId, linkedEntityId } = ids;
|
|
73
100
|
transactionBuilder.addPut({
|
|
74
101
|
TableName: tableName,
|
|
75
102
|
Item: {
|
|
76
|
-
...
|
|
77
|
-
...
|
|
103
|
+
...linkedRecord,
|
|
104
|
+
...this.joinTableKey(keys, parentEntityMeta, linkedEntityMeta)
|
|
78
105
|
},
|
|
79
106
|
ConditionExpression: `attribute_not_exists(${partitionKeyAlias})` // Ensure item doesn't already exist
|
|
80
107
|
}, `${parentEntity.name} with ID ${linkedEntityId} is already linked to ${linkedEntity.name} with ID ${parentId}`);
|
|
81
108
|
transactionBuilder.addConditionCheck({
|
|
82
109
|
TableName: tableName,
|
|
83
|
-
Key:
|
|
84
|
-
[partitionKeyAlias]: parentEntity.partitionKeyValue(linkedEntityId),
|
|
85
|
-
[sortKeyAlias]: parentEntity.name
|
|
86
|
-
},
|
|
110
|
+
Key: this.buildForeignEntityKey(tableProps, parentEntity, linkedEntityId),
|
|
87
111
|
ConditionExpression: `attribute_exists(${partitionKeyAlias})`
|
|
88
112
|
}, `${parentEntity.name} with ID ${linkedEntityId} does not exist`);
|
|
89
113
|
}
|
|
114
|
+
/**
|
|
115
|
+
* Builds the key to the foreign entity
|
|
116
|
+
* @param tableProps
|
|
117
|
+
* @param parentEntity
|
|
118
|
+
* @param linkedEntityId
|
|
119
|
+
* @returns
|
|
120
|
+
*/
|
|
121
|
+
static buildForeignEntityKey(tableProps, parentEntity, linkedEntityId) {
|
|
122
|
+
const { alias: partitionKeyAlias } = tableProps.partitionKeyAttribute;
|
|
123
|
+
const { alias: sortKeyAlias } = tableProps.sortKeyAttribute;
|
|
124
|
+
return {
|
|
125
|
+
[partitionKeyAlias]: parentEntity.partitionKeyValue(linkedEntityId),
|
|
126
|
+
[sortKeyAlias]: parentEntity.name
|
|
127
|
+
};
|
|
128
|
+
}
|
|
90
129
|
/**
|
|
91
130
|
* Deletes transactions:
|
|
92
|
-
* 1. Delete a
|
|
131
|
+
* 1. Delete a denormalized record in parents partition if its linked
|
|
93
132
|
* @param transactionBuilder
|
|
94
133
|
* @param keys
|
|
95
134
|
* @param parentEntityMeta
|
|
96
135
|
* @param linkedEntityMeta
|
|
97
136
|
*/
|
|
98
|
-
static
|
|
137
|
+
static deleteLink(transactionBuilder, keys, parentEntityMeta, linkedEntityMeta) {
|
|
99
138
|
const { entity: parentEntity, foreignKey: parentKey } = parentEntityMeta;
|
|
100
139
|
const { entity: linkedEntity, foreignKey: linkedKey } = linkedEntityMeta;
|
|
101
140
|
const parentId = keys[parentKey];
|
|
@@ -129,5 +168,23 @@ class JoinTable {
|
|
|
129
168
|
ids: { parentId, linkedEntityId }
|
|
130
169
|
};
|
|
131
170
|
}
|
|
171
|
+
static preFetchNotFoundErrorMessage(transactionResults, entities, ids) {
|
|
172
|
+
const joinedEntityData = [
|
|
173
|
+
{ entityId: ids.parentId, entityName: entities.linkedEntity.name },
|
|
174
|
+
{ entityId: ids.linkedEntityId, entityName: entities.parentEntity.name }
|
|
175
|
+
];
|
|
176
|
+
const tableMeta = metadata_1.default.getEntityTable(entities.parentEntity.name);
|
|
177
|
+
const idAlias = tableMeta.defaultAttributes.id.alias;
|
|
178
|
+
const foundEntityIds = new Set(transactionResults
|
|
179
|
+
.filter(result => result?.Item)
|
|
180
|
+
.map(result => result.Item?.[idAlias]));
|
|
181
|
+
const missingEntities = joinedEntityData.filter(entityData => {
|
|
182
|
+
return !foundEntityIds.has(entityData.entityId); // If not in Set, it's missing
|
|
183
|
+
});
|
|
184
|
+
const missingEntityStr = missingEntities
|
|
185
|
+
.map(entity => `(${entity.entityName}: ${entity.entityId})`)
|
|
186
|
+
.join(", ");
|
|
187
|
+
return `Entities not found: ${missingEntityStr}`;
|
|
188
|
+
}
|
|
132
189
|
}
|
|
133
190
|
exports.default = JoinTable;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/relationships/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,IAAI,
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/relationships/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,IAAI,SAAS,EAAE,MAAM,aAAa,CAAC"}
|
|
@@ -3,8 +3,6 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
3
3
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
4
|
};
|
|
5
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
-
exports.JoinTable =
|
|
7
|
-
var BelongsToLink_1 = require("./BelongsToLink");
|
|
8
|
-
Object.defineProperty(exports, "BelongsToLink", { enumerable: true, get: function () { return __importDefault(BelongsToLink_1).default; } });
|
|
6
|
+
exports.JoinTable = void 0;
|
|
9
7
|
var JoinTable_1 = require("./JoinTable");
|
|
10
8
|
Object.defineProperty(exports, "JoinTable", { enumerable: true, get: function () { return __importDefault(JoinTable_1).default; } });
|
package/dist/src/types.d.ts
CHANGED
|
@@ -1,5 +1,4 @@
|
|
|
1
1
|
import { type NativeScalarAttributeValue } from "@aws-sdk/util-dynamodb";
|
|
2
|
-
import { type BelongsToLink } from "./relationships";
|
|
3
2
|
import type { BelongsToRelationship, RelationshipMetadata } from "./metadata";
|
|
4
3
|
import type DynaRecord from "./DynaRecord";
|
|
5
4
|
/**
|
|
@@ -36,13 +35,6 @@ export type DynamoTableItem = Record<string, NativeScalarAttributeValue>;
|
|
|
36
35
|
* A utility type for objects with string keys and string values.
|
|
37
36
|
*/
|
|
38
37
|
export type StringObj = Record<string, string>;
|
|
39
|
-
/**
|
|
40
|
-
* Describes the shape of a DynamoDB item representing a `BelongsToLink`, enforcing type consistency.
|
|
41
|
-
*/
|
|
42
|
-
export interface BelongsToLinkDynamoItem {
|
|
43
|
-
Type: typeof BelongsToLink.name;
|
|
44
|
-
[key: string]: NativeScalarAttributeValue;
|
|
45
|
-
}
|
|
46
38
|
/**
|
|
47
39
|
* A utility type for making a type optional, allowing it to be undefined.
|
|
48
40
|
*/
|
|
@@ -70,4 +62,10 @@ export type MakeOptional<T, K extends keyof T> = Omit<T, K> & Partial<Pick<T, K>
|
|
|
70
62
|
* Represents an instance of a class decorated with the `Entity` decorator in DynaRecord, encapsulating entity logic.
|
|
71
63
|
*/
|
|
72
64
|
export type EntityClass<T> = (new () => T) & typeof DynaRecord;
|
|
65
|
+
/**
|
|
66
|
+
* Make a single property of an object required
|
|
67
|
+
*/
|
|
68
|
+
export type WithRequired<T, K extends keyof T> = Omit<T, K> & {
|
|
69
|
+
[P in K]-?: T[P];
|
|
70
|
+
};
|
|
73
71
|
//# sourceMappingURL=types.d.ts.map
|
package/dist/src/types.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../src/types.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,0BAA0B,EAAE,MAAM,wBAAwB,CAAC;AACzE,OAAO,
|
|
1
|
+
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../src/types.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,0BAA0B,EAAE,MAAM,wBAAwB,CAAC;AACzE,OAAO,KAAK,EAAE,qBAAqB,EAAE,oBAAoB,EAAE,MAAM,YAAY,CAAC;AAC9E,OAAO,KAAK,UAAU,MAAM,cAAc,CAAC;AAE3C;;GAEG;AACH,MAAM,MAAM,KAAK,CAAC,CAAC,EAAE,CAAC,IAAI,CAAC,GAAG;IAAE,OAAO,EAAE,CAAC,CAAA;CAAE,CAAC;AAE7C;;GAEG;AACH,MAAM,MAAM,OAAO,GAAG,KAAK,CAAC,MAAM,EAAE,SAAS,CAAC,CAAC;AAE/C;;GAEG;AACH,MAAM,MAAM,YAAY,GAAG,KAAK,CAAC,MAAM,EAAE,cAAc,CAAC,CAAC;AAEzD;;GAEG;AACH,MAAM,MAAM,UAAU,GAAG,KAAK,CAAC,MAAM,EAAE,YAAY,CAAC,CAAC;AAErD;;GAEG;AACH,MAAM,MAAM,kBAAkB,GAAG,QAAQ,CAAC,KAAK,CAAC,MAAM,EAAE,oBAAoB,CAAC,CAAC,CAAC;AAE/E;;GAEG;AACH,MAAM,MAAM,kBAAkB,GAAG,MAAM,UAAU,GAAG,UAAU,CAAC;AAE/D;;GAEG;AACH,MAAM,MAAM,eAAe,GAAG,MAAM,CAAC,MAAM,EAAE,0BAA0B,CAAC,CAAC;AAEzE;;GAEG;AACH,MAAM,MAAM,SAAS,GAAG,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;AAE/C;;GAEG;AACH,MAAM,MAAM,QAAQ,CAAC,CAAC,IAAI,CAAC,GAAG,SAAS,CAAC;AAExC;;GAEG;AACH,MAAM,MAAM,QAAQ,CAAC,CAAC,IAAI,CAAC,GAAG,IAAI,CAAC;AAEnC;;GAEG;AACH,MAAM,MAAM,kBAAkB,GAAG,MAAM,CAAC,MAAM,EAAE,oBAAoB,CAAC,CAAC;AAEtE;;GAEG;AACH,MAAM,WAAW,mBAAmB;IAClC,eAAe,EAAE,kBAAkB,CAAC;IACpC,sBAAsB,EAAE,qBAAqB,EAAE,CAAC;CACjD;AAED;;GAEG;AACH,MAAM,MAAM,YAAY,CAAC,CAAC,EAAE,CAAC,SAAS,MAAM,CAAC,IAAI,IAAI,CAAC,CAAC,EAAE,CAAC,CAAC,GACzD,OAAO,CAAC,IAAI,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,CAAC;AAEtB;;GAEG;AACH,MAAM,MAAM,WAAW,CAAC,CAAC,IAAI,CAAC,UAAU,CAAC,CAAC,GAAG,OAAO,UAAU,CAAC;AAE/D;;GAEG;AACH,MAAM,MAAM,YAAY,CAAC,CAAC,EAAE,CAAC,SAAS,MAAM,CAAC,IAAI,IAAI,CAAC,CAAC,EAAE,CAAC,CAAC,GAAG;KAC3D,CAAC,IAAI,CAAC,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC;CACjB,CAAC"}
|
package/dist/src/utils.d.ts
CHANGED
|
@@ -1,8 +1,6 @@
|
|
|
1
1
|
import type DynaRecord from "./DynaRecord";
|
|
2
|
-
import type { DynamoTableItem,
|
|
3
|
-
import { type
|
|
4
|
-
import { BelongsToLink } from "./relationships";
|
|
5
|
-
import { type EntityAttributes } from "./operations";
|
|
2
|
+
import type { DynamoTableItem, Nullable } from "./types";
|
|
3
|
+
import { type EntityAttributesOnly } from "./operations";
|
|
6
4
|
/**
|
|
7
5
|
* Convert an entity to its aliased table item fields to for dynamo interactions
|
|
8
6
|
* @param entityClassName
|
|
@@ -20,14 +18,7 @@ export declare const tableItemToEntity: <T extends DynaRecord>(EntityClass: new
|
|
|
20
18
|
/**
|
|
21
19
|
* Create an instance of a dyna record class
|
|
22
20
|
*/
|
|
23
|
-
export declare const createInstance: <T extends DynaRecord>(EntityClass: new () => T, attributes:
|
|
24
|
-
/**
|
|
25
|
-
* Serialize a dynamo table item response to a BelongsToLink
|
|
26
|
-
* @param tableMeta - Table metadata
|
|
27
|
-
* @param tableItem - Table item from dynamo response
|
|
28
|
-
* @returns - { @link BelongsToLink }
|
|
29
|
-
*/
|
|
30
|
-
export declare const tableItemToBelongsToLink: (tableMeta: TableMetadata, tableItem: BelongsToLinkDynamoItem) => BelongsToLink;
|
|
21
|
+
export declare const createInstance: <T extends DynaRecord>(EntityClass: new () => T, attributes: EntityAttributesOnly<T>) => T;
|
|
31
22
|
/**
|
|
32
23
|
* Type guard to check if the key is defined on the entity
|
|
33
24
|
*/
|
|
@@ -39,12 +30,6 @@ export declare const isKeyOfEntity: (entity: DynaRecord, key: string) => key is
|
|
|
39
30
|
* @returns
|
|
40
31
|
*/
|
|
41
32
|
export declare const isKeyOfObject: <T>(entity: Partial<DynaRecord>, key: any) => key is keyof T;
|
|
42
|
-
/**
|
|
43
|
-
* Type guard to check if the DynamoTableItem is a BelongsToLink
|
|
44
|
-
* @param res DynamoTableItem
|
|
45
|
-
* @returns boolean
|
|
46
|
-
*/
|
|
47
|
-
export declare const isBelongsToLinkDynamoItem: (res: DynamoTableItem, tableMeta: TableMetadata) => res is BelongsToLinkDynamoItem;
|
|
48
33
|
/**
|
|
49
34
|
* Break an array into chunks
|
|
50
35
|
* @param array
|
|
@@ -52,19 +37,6 @@ export declare const isBelongsToLinkDynamoItem: (res: DynamoTableItem, tableMeta
|
|
|
52
37
|
* @returns Array split into chunks of given size
|
|
53
38
|
*/
|
|
54
39
|
export declare const chunkArray: <T>(array: T[], size: number) => T[][];
|
|
55
|
-
/**
|
|
56
|
-
* Checks if a value is a valid property key (string, number, or symbol).
|
|
57
|
-
*
|
|
58
|
-
* @param value The value to be checked. This can be of any type.
|
|
59
|
-
* @returns `true` if the value is a `string`, `number`, or `symbol` (i.e., a valid property key); otherwise, `false`.
|
|
60
|
-
*
|
|
61
|
-
* @example
|
|
62
|
-
* Logger.log(isPropertyKey('test')); // true
|
|
63
|
-
* Logger.log(isPropertyKey(123)); // true
|
|
64
|
-
* Logger.log(isPropertyKey(Symbol('sym'))); // true
|
|
65
|
-
* Logger.log(isPropertyKey({})); // false
|
|
66
|
-
*/
|
|
67
|
-
export declare const isPropertyKey: (value: any) => value is PropertyKey;
|
|
68
40
|
/**
|
|
69
41
|
* Checks if the given value is a string.
|
|
70
42
|
*
|
|
@@ -90,5 +62,11 @@ export declare const isString: (value: any) => value is string;
|
|
|
90
62
|
* let entity = { id: "123" };
|
|
91
63
|
* safeAssign(entity, "name", "Jane Doe");
|
|
92
64
|
*/
|
|
93
|
-
export declare const safeAssign: <TObject extends
|
|
65
|
+
export declare const safeAssign: <TObject extends EntityAttributesOnly<DynaRecord>, TKey extends keyof TObject, TValue>(object: TObject, key: TKey, value: TValue) => void;
|
|
66
|
+
/**
|
|
67
|
+
* Type guard to check if a string is a Nullable<string>
|
|
68
|
+
* @param val
|
|
69
|
+
* @returns
|
|
70
|
+
*/
|
|
71
|
+
export declare const isNullableString: (val: unknown) => val is Nullable<string>;
|
|
94
72
|
//# sourceMappingURL=utils.d.ts.map
|
package/dist/src/utils.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"utils.d.ts","sourceRoot":"","sources":["../../src/utils.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,UAAU,MAAM,cAAc,CAAC;AAC3C,OAAO,KAAK,EAAE,eAAe,EAAE,
|
|
1
|
+
{"version":3,"file":"utils.d.ts","sourceRoot":"","sources":["../../src/utils.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,UAAU,MAAM,cAAc,CAAC;AAC3C,OAAO,KAAK,EAAE,eAAe,EAAE,QAAQ,EAAE,MAAM,SAAS,CAAC;AAGzD,OAAO,EAAE,KAAK,oBAAoB,EAAE,MAAM,cAAc,CAAC;AAEzD;;;;;GAKG;AACH,eAAO,MAAM,iBAAiB,GAAI,CAAC,SAAS,UAAU,eACvC,UAAU,CAAC,cACZ,OAAO,CAAC,UAAU,CAAC,KAC9B,eAqBF,CAAC;AAEF;;;;;GAKG;AACH,eAAO,MAAM,iBAAiB,GAAI,CAAC,SAAS,UAAU,eACvC,UAAU,CAAC,aACb,eAAe,KACzB,CAuBF,CAAC;AAEF;;GAEG;AACH,eAAO,MAAM,cAAc,GAAI,CAAC,SAAS,UAAU,eACpC,UAAU,CAAC,cACZ,oBAAoB,CAAC,CAAC,CAAC,KAClC,CAUF,CAAC;AAEF;;GAEG;AACH,eAAO,MAAM,aAAa,WAChB,UAAU,OACb,MAAM,KACV,GAAG,IAAI,MAAM,UAEf,CAAC;AAEF;;;;;GAKG;AACH,eAAO,MAAM,aAAa,GAAI,CAAC,UACrB,OAAO,CAAC,UAAU,CAAC,OACtB,GAAG,KACP,GAAG,IAAI,MAAM,CAEf,CAAC;AAEF;;;;;GAKG;AACH,eAAO,MAAM,UAAU,GAAI,CAAC,SAAS,CAAC,EAAE,QAAQ,MAAM,KAAG,CAAC,EAAE,EAI3D,CAAC;AAEF;;;;;GAKG;AACH,eAAO,MAAM,QAAQ,UAAW,GAAG,KAAG,KAAK,IAAI,MAE9C,CAAC;AAEF;;;;;;;;;;;;;;;;;GAiBG;AACH,eAAO,MAAM,UAAU,GACrB,OAAO,SAAS,oBAAoB,CAAC,UAAU,CAAC,EAChD,IAAI,SAAS,MAAM,OAAO,EAC1B,MAAM,UAEE,OAAO,OACV,IAAI,SACF,MAAM,KACZ,IAEF,CAAC;AAEF;;;;GAIG;AACH,eAAO,MAAM,gBAAgB,QAAS,OAAO,KAAG,GAAG,IAAI,QAAQ,CAAC,MAAM,CAErE,CAAC"}
|