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,168 @@
|
|
|
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
|
+
exports.safeAssign = exports.isString = exports.isPropertyKey = exports.chunkArray = exports.isBelongsToLinkDynamoItem = exports.isKeyOfObject = exports.isKeyOfEntity = exports.tableItemToBelongsToLink = exports.tableItemToEntity = exports.entityToTableItem = void 0;
|
|
7
|
+
const metadata_1 = __importDefault(require("./metadata"));
|
|
8
|
+
const relationships_1 = require("./relationships");
|
|
9
|
+
/**
|
|
10
|
+
* Convert an entity to its aliased table item fields to for dynamo interactions
|
|
11
|
+
* @param entityClassName
|
|
12
|
+
* @param entityData
|
|
13
|
+
* @returns
|
|
14
|
+
*/
|
|
15
|
+
const entityToTableItem = (EntityClass, entityData) => {
|
|
16
|
+
const attributesMeta = metadata_1.default.getEntityAttributes(EntityClass.name);
|
|
17
|
+
return Object.entries(entityData).reduce((acc, [key, val]) => {
|
|
18
|
+
const attrMeta = attributesMeta[key];
|
|
19
|
+
if (attrMeta !== undefined) {
|
|
20
|
+
const { alias, serializers } = attrMeta;
|
|
21
|
+
// If the attribute has a custom serializer, serialize it
|
|
22
|
+
const value = serializers === undefined ? val : serializers.toTableAttribute(val);
|
|
23
|
+
acc[alias] = value;
|
|
24
|
+
}
|
|
25
|
+
return acc;
|
|
26
|
+
}, {});
|
|
27
|
+
};
|
|
28
|
+
exports.entityToTableItem = entityToTableItem;
|
|
29
|
+
/**
|
|
30
|
+
* Serialize a table item to its associated Entity class, using the class attribute property names
|
|
31
|
+
* @param EntityClass
|
|
32
|
+
* @param tableItem
|
|
33
|
+
* @returns
|
|
34
|
+
*/
|
|
35
|
+
const tableItemToEntity = (EntityClass, tableItem) => {
|
|
36
|
+
const tableAttributes = metadata_1.default.getEntityTableAttributes(EntityClass.name);
|
|
37
|
+
const entity = new EntityClass();
|
|
38
|
+
Object.keys(tableItem).forEach(attrName => {
|
|
39
|
+
const attrMeta = tableAttributes[attrName];
|
|
40
|
+
if (attrMeta !== undefined) {
|
|
41
|
+
const { name: entityKey, serializers } = attrMeta;
|
|
42
|
+
if ((0, exports.isKeyOfEntity)(entity, entityKey)) {
|
|
43
|
+
const rawVal = tableItem[attrName];
|
|
44
|
+
const val = serializers?.toEntityAttribute === undefined
|
|
45
|
+
? rawVal
|
|
46
|
+
: serializers?.toEntityAttribute(rawVal);
|
|
47
|
+
(0, exports.safeAssign)(entity, entityKey, val);
|
|
48
|
+
}
|
|
49
|
+
}
|
|
50
|
+
});
|
|
51
|
+
return entity;
|
|
52
|
+
};
|
|
53
|
+
exports.tableItemToEntity = tableItemToEntity;
|
|
54
|
+
/**
|
|
55
|
+
* Serialize a dynamo table item response to a BelongsToLink
|
|
56
|
+
* @param tableMeta - Table metadata
|
|
57
|
+
* @param tableItem - Table item from dynamo response
|
|
58
|
+
* @returns - { @link BelongsToLink }
|
|
59
|
+
*/
|
|
60
|
+
const tableItemToBelongsToLink = (tableMeta, tableItem) => {
|
|
61
|
+
const link = new relationships_1.BelongsToLink();
|
|
62
|
+
const belongsToLinkAttrs = {
|
|
63
|
+
...{
|
|
64
|
+
[tableMeta.partitionKeyAttribute.alias]: tableMeta.partitionKeyAttribute
|
|
65
|
+
},
|
|
66
|
+
...{ [tableMeta.sortKeyAttribute.alias]: tableMeta.sortKeyAttribute },
|
|
67
|
+
...tableMeta.defaultTableAttributes
|
|
68
|
+
};
|
|
69
|
+
Object.keys(tableItem).forEach(attrName => {
|
|
70
|
+
const attrMeta = belongsToLinkAttrs[attrName];
|
|
71
|
+
if (attrMeta !== undefined) {
|
|
72
|
+
const { name: entityKey, serializers } = attrMeta;
|
|
73
|
+
const rawVal = tableItem[attrName];
|
|
74
|
+
const val = serializers?.toEntityAttribute === undefined
|
|
75
|
+
? rawVal
|
|
76
|
+
: serializers?.toEntityAttribute(rawVal);
|
|
77
|
+
(0, exports.safeAssign)(link, entityKey, val);
|
|
78
|
+
}
|
|
79
|
+
});
|
|
80
|
+
return link;
|
|
81
|
+
};
|
|
82
|
+
exports.tableItemToBelongsToLink = tableItemToBelongsToLink;
|
|
83
|
+
/**
|
|
84
|
+
* Type guard to check if the key is defined on the entity
|
|
85
|
+
*/
|
|
86
|
+
const isKeyOfEntity = (entity, key) => {
|
|
87
|
+
return key in entity;
|
|
88
|
+
};
|
|
89
|
+
exports.isKeyOfEntity = isKeyOfEntity;
|
|
90
|
+
/**
|
|
91
|
+
* Type guard to check if the key is a defined property on the entity
|
|
92
|
+
* @param entity
|
|
93
|
+
* @param key
|
|
94
|
+
* @returns
|
|
95
|
+
*/
|
|
96
|
+
const isKeyOfObject = (entity, key) => {
|
|
97
|
+
return key in entity;
|
|
98
|
+
};
|
|
99
|
+
exports.isKeyOfObject = isKeyOfObject;
|
|
100
|
+
/**
|
|
101
|
+
* Type guard to check if the DynamoTableItem is a BelongsToLink
|
|
102
|
+
* @param res DynamoTableItem
|
|
103
|
+
* @returns boolean
|
|
104
|
+
*/
|
|
105
|
+
const isBelongsToLinkDynamoItem = (res, tableMeta) => {
|
|
106
|
+
return res[tableMeta.defaultAttributes.type.alias] === relationships_1.BelongsToLink.name;
|
|
107
|
+
};
|
|
108
|
+
exports.isBelongsToLinkDynamoItem = isBelongsToLinkDynamoItem;
|
|
109
|
+
/**
|
|
110
|
+
* Break an array into chunks
|
|
111
|
+
* @param array
|
|
112
|
+
* @param size
|
|
113
|
+
* @returns Array split into chunks of given size
|
|
114
|
+
*/
|
|
115
|
+
const chunkArray = (array, size) => {
|
|
116
|
+
return Array.from({ length: Math.ceil(array.length / size) }, (_, index) => array.slice(index * size, (index + 1) * size));
|
|
117
|
+
};
|
|
118
|
+
exports.chunkArray = chunkArray;
|
|
119
|
+
/**
|
|
120
|
+
* Checks if a value is a valid property key (string, number, or symbol).
|
|
121
|
+
*
|
|
122
|
+
* @param value The value to be checked. This can be of any type.
|
|
123
|
+
* @returns `true` if the value is a `string`, `number`, or `symbol` (i.e., a valid property key); otherwise, `false`.
|
|
124
|
+
*
|
|
125
|
+
* @example
|
|
126
|
+
* Logger.log(isPropertyKey('test')); // true
|
|
127
|
+
* Logger.log(isPropertyKey(123)); // true
|
|
128
|
+
* Logger.log(isPropertyKey(Symbol('sym'))); // true
|
|
129
|
+
* Logger.log(isPropertyKey({})); // false
|
|
130
|
+
*/
|
|
131
|
+
const isPropertyKey = (value) => {
|
|
132
|
+
return (typeof value === "string" ||
|
|
133
|
+
typeof value === "number" ||
|
|
134
|
+
typeof value === "symbol");
|
|
135
|
+
};
|
|
136
|
+
exports.isPropertyKey = isPropertyKey;
|
|
137
|
+
/**
|
|
138
|
+
* Checks if the given value is a string.
|
|
139
|
+
*
|
|
140
|
+
* @param value - The value to check. This can be any type as the function is meant to validate if it's a string.
|
|
141
|
+
* @returns `true` if `value` is a string; otherwise, `false`.
|
|
142
|
+
*/
|
|
143
|
+
const isString = (value) => {
|
|
144
|
+
return typeof value === "string";
|
|
145
|
+
};
|
|
146
|
+
exports.isString = isString;
|
|
147
|
+
/**
|
|
148
|
+
* Safely assigns a value to a property of an object.
|
|
149
|
+
* It's useful for dynamically assigning properties to objects where the property names might be known but the types could vary.
|
|
150
|
+
*
|
|
151
|
+
* @template TObject - The object type to which the property belongs.
|
|
152
|
+
* @template TKey - The type of the keys of `TObject`
|
|
153
|
+
* @template TValue - The value to be assigned.
|
|
154
|
+
*
|
|
155
|
+
* @param {TObject} object - The target object to which the property will be assigned.
|
|
156
|
+
* @param {TKey} key - The property name under which the value should be assigned. Must be a key of `TObject`.
|
|
157
|
+
* @param {TValue} value - The value to assign to the property on the object.
|
|
158
|
+
*
|
|
159
|
+
* @returns {void} - This function does not return a value; it performs the assignment operation directly on the passed object.
|
|
160
|
+
*
|
|
161
|
+
* @example
|
|
162
|
+
* let entity = { id: "123" };
|
|
163
|
+
* safeAssign(entity, "name", "Jane Doe");
|
|
164
|
+
*/
|
|
165
|
+
const safeAssign = (object, key, value) => {
|
|
166
|
+
object[key] = value;
|
|
167
|
+
};
|
|
168
|
+
exports.safeAssign = safeAssign;
|
package/package.json
ADDED
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "dyna-record",
|
|
3
|
+
"version": "0.0.1",
|
|
4
|
+
"description": "Typescript Object Relational Mapper (ORM) for Dynamo",
|
|
5
|
+
"main": "dist/index.js",
|
|
6
|
+
"types": "dist/index.d.ts",
|
|
7
|
+
"scripts": {
|
|
8
|
+
"build": "tsc",
|
|
9
|
+
"watch": "tsc -w",
|
|
10
|
+
"test": "jest",
|
|
11
|
+
"eslint": "npx eslint . --ext .ts",
|
|
12
|
+
"eslint-fix": "npx eslint . --ext .ts --fix",
|
|
13
|
+
"prettier": "npx prettier . --write",
|
|
14
|
+
"docs": "npx typedoc"
|
|
15
|
+
},
|
|
16
|
+
"repository": {
|
|
17
|
+
"type": "git",
|
|
18
|
+
"url": "git+https://github.com/dsdavis4/dyna-record.git"
|
|
19
|
+
},
|
|
20
|
+
"author": "dsdavis4",
|
|
21
|
+
"license": "MIT",
|
|
22
|
+
"bugs": {
|
|
23
|
+
"url": "https://github.com/dsdavis4/dyna-record/issues"
|
|
24
|
+
},
|
|
25
|
+
"homepage": "https://github.com/dsdavis4/dyna-record#readme",
|
|
26
|
+
"dependencies": {
|
|
27
|
+
"@aws-sdk/client-dynamodb": "^3.502.0",
|
|
28
|
+
"@aws-sdk/lib-dynamodb": "^3.502.0",
|
|
29
|
+
"@aws-sdk/util-dynamodb": "^3.509.0",
|
|
30
|
+
"uuid": "^9.0.1"
|
|
31
|
+
},
|
|
32
|
+
"devDependencies": {
|
|
33
|
+
"@aws-sdk/types": "^3.502.0",
|
|
34
|
+
"@tsconfig/recommended": "^1.0.3",
|
|
35
|
+
"@types/jest": "^29.5.12",
|
|
36
|
+
"@types/node": "^20.11.16",
|
|
37
|
+
"@types/uuid": "^9.0.8",
|
|
38
|
+
"@typescript-eslint/eslint-plugin": "^6.21.0",
|
|
39
|
+
"@typescript-eslint/parser": "^6.21.0",
|
|
40
|
+
"eslint": "^8.56.0",
|
|
41
|
+
"eslint-config-prettier": "^9.1.0",
|
|
42
|
+
"eslint-config-standard-with-typescript": "^43.0.1",
|
|
43
|
+
"eslint-plugin-import": "^2.29.1",
|
|
44
|
+
"eslint-plugin-n": "^16.6.2",
|
|
45
|
+
"eslint-plugin-promise": "^6.1.1",
|
|
46
|
+
"jest": "^29.7.0",
|
|
47
|
+
"prettier": "^3.2.5",
|
|
48
|
+
"ts-jest": "^29.1.2",
|
|
49
|
+
"ts-node": "^10.9.2",
|
|
50
|
+
"typedoc": "^0.25.12",
|
|
51
|
+
"typedoc-plugin-missing-exports": "^2.2.0",
|
|
52
|
+
"typescript": "^5.3.3"
|
|
53
|
+
},
|
|
54
|
+
"engines": {
|
|
55
|
+
"npm": ">=10.0.0",
|
|
56
|
+
"node": ">=18.0.0"
|
|
57
|
+
},
|
|
58
|
+
"files": [
|
|
59
|
+
"dist/**/*"
|
|
60
|
+
]
|
|
61
|
+
}
|