dyna-record 0.5.0 → 0.5.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/dist/src/DynaRecord.d.ts +11 -18
- package/dist/src/DynaRecord.d.ts.map +1 -1
- package/dist/src/Logger.d.ts.map +1 -1
- package/dist/src/Logger.js +0 -1
- package/dist/src/decorators/Entity.d.ts +1 -1
- package/dist/src/decorators/Entity.d.ts.map +1 -1
- package/dist/src/decorators/Entity.js +3 -5
- package/dist/src/decorators/Table.d.ts +1 -1
- package/dist/src/decorators/Table.d.ts.map +1 -1
- package/dist/src/decorators/Table.js +2 -4
- package/dist/src/decorators/attributes/BooleanAttribute.d.ts.map +1 -1
- package/dist/src/decorators/attributes/BooleanAttribute.js +7 -9
- package/dist/src/decorators/attributes/DateAttribute.d.ts.map +1 -1
- package/dist/src/decorators/attributes/DateAttribute.js +8 -10
- package/dist/src/decorators/attributes/EnumAttribute.d.ts.map +1 -1
- package/dist/src/decorators/attributes/EnumAttribute.js +7 -9
- package/dist/src/decorators/attributes/ForeignKeyAttribute.d.ts.map +1 -1
- package/dist/src/decorators/attributes/ForeignKeyAttribute.js +9 -11
- package/dist/src/decorators/attributes/NumberAttribute.d.ts.map +1 -1
- package/dist/src/decorators/attributes/NumberAttribute.js +7 -9
- package/dist/src/decorators/attributes/ObjectAttribute.d.ts.map +1 -1
- package/dist/src/decorators/attributes/ObjectAttribute.js +14 -17
- package/dist/src/decorators/attributes/PartitionKeyAttribute.d.ts.map +1 -1
- package/dist/src/decorators/attributes/PartitionKeyAttribute.js +6 -8
- package/dist/src/decorators/attributes/SortKeyAttribute.d.ts.map +1 -1
- package/dist/src/decorators/attributes/SortKeyAttribute.js +6 -8
- package/dist/src/decorators/attributes/StringAttribute.d.ts.map +1 -1
- package/dist/src/decorators/attributes/StringAttribute.js +7 -9
- package/dist/src/decorators/attributes/serializers.d.ts +2 -2
- package/dist/src/decorators/attributes/serializers.d.ts.map +1 -1
- package/dist/src/decorators/attributes/serializers.js +1 -1
- package/dist/src/decorators/relationships/BelongsTo.d.ts.map +1 -1
- package/dist/src/decorators/relationships/BelongsTo.js +7 -9
- package/dist/src/decorators/relationships/HasAndBelongsToMany.d.ts.map +1 -1
- package/dist/src/decorators/relationships/HasAndBelongsToMany.js +13 -15
- package/dist/src/decorators/relationships/HasMany.d.ts.map +1 -1
- package/dist/src/decorators/relationships/HasMany.js +15 -17
- package/dist/src/decorators/relationships/HasOne.d.ts.map +1 -1
- package/dist/src/decorators/relationships/HasOne.js +7 -9
- package/dist/src/metadata/EntityMetadata.d.ts +2 -2
- package/dist/src/metadata/EntityMetadata.d.ts.map +1 -1
- package/dist/src/metadata/MetadataStorage.d.ts.map +1 -1
- package/dist/src/metadata/MetadataStorage.js +6 -6
- package/dist/src/metadata/TableMetadata.d.ts.map +1 -1
- package/dist/src/metadata/TableMetadata.js +7 -1
- package/dist/src/metadata/relationship-metadata/BelongsToRelationship.d.ts.map +1 -1
- package/dist/src/metadata/relationship-metadata/BelongsToRelationship.js +1 -3
- package/dist/src/metadata/relationship-metadata/HasAndBelongsToManyRelationship.d.ts.map +1 -1
- package/dist/src/metadata/relationship-metadata/HasAndBelongsToManyRelationship.js +1 -3
- package/dist/src/metadata/relationship-metadata/HasManyRelationship.d.ts.map +1 -1
- package/dist/src/metadata/relationship-metadata/HasManyRelationship.js +1 -3
- package/dist/src/metadata/relationship-metadata/HasOneRelationship.d.ts.map +1 -1
- package/dist/src/metadata/relationship-metadata/HasOneRelationship.js +1 -3
- package/dist/src/metadata/relationship-metadata/OwnedByRelationship.d.ts.map +1 -1
- package/dist/src/metadata/relationship-metadata/OwnedByRelationship.js +1 -3
- package/dist/src/metadata/types.d.ts +3 -3
- package/dist/src/metadata/types.d.ts.map +1 -1
- package/dist/src/metadata/utils.js +4 -4
- package/dist/src/operations/Create/Create.js +3 -5
- package/dist/src/operations/Delete/Delete.d.ts.map +1 -1
- package/dist/src/operations/Delete/Delete.js +3 -2
- package/dist/src/operations/FindById/FindById.d.ts.map +1 -1
- package/dist/src/operations/FindById/FindById.js +4 -4
- package/dist/src/operations/Query/Query.d.ts.map +1 -1
- package/dist/src/operations/Query/Query.js +2 -1
- package/dist/src/operations/Update/Update.d.ts.map +1 -1
- package/dist/src/operations/Update/Update.js +17 -15
- package/dist/src/operations/types.d.ts +1 -1
- package/dist/src/operations/types.d.ts.map +1 -1
- package/dist/src/operations/utils/expressionBuilder.js +3 -0
- package/dist/src/operations/utils/flattenObjectForUpdate.d.ts.map +1 -1
- package/dist/src/operations/utils/flattenObjectForUpdate.js +2 -2
- package/dist/src/operations/utils/mergePartialObjectAttributes.d.ts.map +1 -1
- package/dist/src/operations/utils/mergePartialObjectAttributes.js +11 -3
- package/dist/src/operations/utils/utils.d.ts +2 -2
- package/dist/src/operations/utils/utils.d.ts.map +1 -1
- package/dist/src/query-utils/QueryBuilder.d.ts.map +1 -1
- package/dist/src/query-utils/QueryBuilder.js +11 -7
- package/dist/src/query-utils/types.d.ts.map +1 -1
- package/dist/src/relationships/JoinTable.d.ts.map +1 -1
- package/dist/src/relationships/JoinTable.js +4 -3
- package/dist/src/utils.d.ts +4 -4
- package/dist/src/utils.d.ts.map +1 -1
- package/dist/src/utils.js +13 -11
- package/package.json +10 -12
|
@@ -8,8 +8,12 @@ exports.mergePartialObjectAttributes = mergePartialObjectAttributes;
|
|
|
8
8
|
*/
|
|
9
9
|
function mergePartialObjectAttributes(target, partial, entityAttrs) {
|
|
10
10
|
for (const [key, val] of Object.entries(partial)) {
|
|
11
|
+
if (!(key in entityAttrs)) {
|
|
12
|
+
target[key] = val;
|
|
13
|
+
continue;
|
|
14
|
+
}
|
|
11
15
|
const attrMeta = entityAttrs[key];
|
|
12
|
-
if (attrMeta
|
|
16
|
+
if (attrMeta.objectSchema !== undefined) {
|
|
13
17
|
// Deep merge for ObjectAttribute (objects are never nullable)
|
|
14
18
|
const existing = target[key] ?? {};
|
|
15
19
|
target[key] = deepMergeObject(existing, val, attrMeta.objectSchema);
|
|
@@ -40,9 +44,13 @@ function deepMergeObject(existing, partial, schema) {
|
|
|
40
44
|
if (val === null || val === undefined) {
|
|
41
45
|
continue;
|
|
42
46
|
}
|
|
47
|
+
if (!(key in schema)) {
|
|
48
|
+
result[key] = val;
|
|
49
|
+
continue;
|
|
50
|
+
}
|
|
43
51
|
const fieldDef = schema[key];
|
|
44
|
-
if (fieldDef
|
|
45
|
-
result[key] = deepMergeObject(existing[key]
|
|
52
|
+
if (fieldDef.type === "object" && typeof existing[key] === "object") {
|
|
53
|
+
result[key] = deepMergeObject(existing[key], val, fieldDef.fields);
|
|
46
54
|
}
|
|
47
55
|
else {
|
|
48
56
|
result[key] = val;
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import type DynaRecord from "../../DynaRecord";
|
|
2
2
|
import type { BelongsToOrOwnedByRelationship, RelationshipMetadata } from "../../metadata";
|
|
3
|
-
import type { DynamoTableItem, EntityClass, ForeignKey,
|
|
3
|
+
import type { DynamoTableItem, EntityClass, ForeignKey, RelationshipMetaObj } from "../../types";
|
|
4
4
|
import { type EntityAttributesOnly } from "../types";
|
|
5
5
|
/**
|
|
6
6
|
* Creates an object including
|
|
@@ -16,7 +16,7 @@ export declare const buildEntityRelationshipMetaObj: (relationships: Relationshi
|
|
|
16
16
|
* @param entity - instance of DynaRecord
|
|
17
17
|
* @returns
|
|
18
18
|
*/
|
|
19
|
-
export declare const extractForeignKeyFromEntity:
|
|
19
|
+
export declare const extractForeignKeyFromEntity: (relMeta: RelationshipMetadata, entity: Partial<EntityAttributesOnly<DynaRecord>>) => ForeignKey | null | undefined;
|
|
20
20
|
/**
|
|
21
21
|
* Creates the PK and SK (key) for a table item that BelongsTo another as HasMany or HasOne
|
|
22
22
|
* @param entityClass
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"utils.d.ts","sourceRoot":"","sources":["../../../../src/operations/utils/utils.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,UAAU,MAAM,kBAAkB,CAAC;AAC/C,OAAO,KAAK,EACV,8BAA8B,EAC9B,oBAAoB,EACrB,MAAM,gBAAgB,CAAC;AAQxB,OAAO,KAAK,EACV,eAAe,EACf,WAAW,EACX,UAAU,EACV,
|
|
1
|
+
{"version":3,"file":"utils.d.ts","sourceRoot":"","sources":["../../../../src/operations/utils/utils.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,UAAU,MAAM,kBAAkB,CAAC;AAC/C,OAAO,KAAK,EACV,8BAA8B,EAC9B,oBAAoB,EACrB,MAAM,gBAAgB,CAAC;AAQxB,OAAO,KAAK,EACV,eAAe,EACf,WAAW,EACX,UAAU,EACV,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,YAC7B,oBAAoB,UACrB,OAAO,CAAC,oBAAoB,CAAC,UAAU,CAAC,CAAC,KAChD,UAAU,GAAG,IAAI,GAAG,SAKtB,CAAC;AAEF;;;;;;;GAOG;AACH,eAAO,MAAM,qBAAqB,gBACnB,WAAW,CAAC,UAAU,CAAC,YAC1B,MAAM,WACP,8BAA8B,cAC3B,MAAM,KACjB,eAqBF,CAAC;AAEF;;;GAGG;AACH,eAAO,MAAM,iBAAiB,SAAU,OAAO,KAAG,OAEjD,CAAC"}
|
|
@@ -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,EAUV,iBAAiB,EAClB,MAAM,SAAS,CAAC;AAgBjB;;;;GAIG;AACH,cAAM,YAAY;;gBASJ,KAAK,EAAE,iBAAiB;IAmBpC;;;OAGG;IACI,KAAK,IAAI,iBAAiB;IAwBjC;;;;;OAKG;IACH,OAAO,CAAC,8BAA8B;
|
|
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,EAUV,iBAAiB,EAClB,MAAM,SAAS,CAAC;AAgBjB;;;;GAIG;AACH,cAAM,YAAY;;gBASJ,KAAK,EAAE,iBAAiB;IAmBpC;;;OAGG;IACI,KAAK,IAAI,iBAAiB;IAwBjC;;;;;OAKG;IACH,OAAO,CAAC,8BAA8B;IAgBtC;;;OAGG;IACH,OAAO,CAAC,wBAAwB;IAgChC;;;;;;;;;OASG;IACH,OAAO,CAAC,YAAY;IAWpB;;;;OAIG;IACH,OAAO,CAAC,WAAW;IASnB;;;;OAIG;IACH,OAAO,CAAC,SAAS;IAejB;;;;;;;OAOG;IACH,OAAO,CAAC,YAAY;IAkCpB;;;;;;;;;OASG;IACH,OAAO,CAAC,eAAe;IA0BvB;;;;OAIG;IACH,OAAO,CAAC,QAAQ;IAehB;;;;OAIG;IACH,OAAO,CAAC,WAAW;IAUnB;;;;OAIG;IACH,OAAO,CAAC,kBAAkB;IAI1B;;;;OAIG;IACH,OAAO,CAAC,gBAAgB;IAIxB;;;;OAIG;IACH,OAAO,CAAC,aAAa;IAIrB;;;;OAIG;IACH,OAAO,CAAC,UAAU;CAGnB;AAED,eAAe,YAAY,CAAC"}
|
|
@@ -61,7 +61,9 @@ class QueryBuilder {
|
|
|
61
61
|
const valueParams = hasFilter
|
|
62
62
|
? { ...keyParams.values, ...filterParams?.values }
|
|
63
63
|
: keyParams.values;
|
|
64
|
-
return Object.entries(valueParams).reduce(
|
|
64
|
+
return Object.entries(valueParams).reduce(
|
|
65
|
+
// eslint-disable-next-line @typescript-eslint/no-unsafe-assignment -- NativeAttributeValue is 'any' from AWS SDK
|
|
66
|
+
(params, [attrName, value]) => ({ ...params, [`:${attrName}`]: value }), {});
|
|
65
67
|
}
|
|
66
68
|
/**
|
|
67
69
|
* Build ExpressionAttributeNames
|
|
@@ -149,25 +151,28 @@ class QueryBuilder {
|
|
|
149
151
|
let values = {};
|
|
150
152
|
if (Array.isArray(value)) {
|
|
151
153
|
const mappings = value.reduce((acc, val) => {
|
|
152
|
-
const placeholder = `${resolved.placeholderKey}${++this.#attrCounter}`;
|
|
154
|
+
const placeholder = `${resolved.placeholderKey}${String(++this.#attrCounter)}`;
|
|
153
155
|
values[placeholder] = val;
|
|
154
156
|
return acc.concat(`:${placeholder}`);
|
|
155
157
|
}, []);
|
|
156
158
|
condition = `${resolved.expressionPath} IN (${mappings.join()})`;
|
|
157
159
|
}
|
|
158
160
|
else if (this.isBeginsWithFilter(value)) {
|
|
159
|
-
const placeholder = `${resolved.placeholderKey}${++this.#attrCounter}`;
|
|
161
|
+
const placeholder = `${resolved.placeholderKey}${String(++this.#attrCounter)}`;
|
|
160
162
|
condition = `begins_with(${resolved.expressionPath}, :${placeholder})`;
|
|
163
|
+
// eslint-disable-next-line @typescript-eslint/no-unsafe-assignment -- NativeAttributeValue is 'any' from AWS SDK
|
|
161
164
|
values = { [placeholder]: value.$beginsWith };
|
|
162
165
|
}
|
|
163
166
|
else if (this.isContainsFilter(value)) {
|
|
164
|
-
const placeholder = `${resolved.placeholderKey}${++this.#attrCounter}`;
|
|
167
|
+
const placeholder = `${resolved.placeholderKey}${String(++this.#attrCounter)}`;
|
|
165
168
|
condition = `contains(${resolved.expressionPath}, :${placeholder})`;
|
|
169
|
+
// eslint-disable-next-line @typescript-eslint/no-unsafe-assignment -- NativeAttributeValue is 'any' from AWS SDK
|
|
166
170
|
values = { [placeholder]: value.$contains };
|
|
167
171
|
}
|
|
168
172
|
else {
|
|
169
|
-
const placeholder = `${resolved.placeholderKey}${++this.#attrCounter}`;
|
|
173
|
+
const placeholder = `${resolved.placeholderKey}${String(++this.#attrCounter)}`;
|
|
170
174
|
condition = `${resolved.expressionPath} = :${placeholder}`;
|
|
175
|
+
// eslint-disable-next-line @typescript-eslint/no-unsafe-assignment -- NativeAttributeValue is 'any' from AWS SDK
|
|
171
176
|
values = { [placeholder]: value };
|
|
172
177
|
}
|
|
173
178
|
return { expression: `${condition} AND `, values };
|
|
@@ -229,8 +234,7 @@ class QueryBuilder {
|
|
|
229
234
|
const expression = multipleVals
|
|
230
235
|
? `(${andParams.expression}) OR `
|
|
231
236
|
: `${andParams.expression} OR `;
|
|
232
|
-
|
|
233
|
-
return { expression, values };
|
|
237
|
+
return { expression, values: andParams.values };
|
|
234
238
|
}
|
|
235
239
|
/**
|
|
236
240
|
* Type guard to check if its a BeginsWithFilter
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../../src/query-utils/types.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,iBAAiB,EAAE,MAAM,uBAAuB,CAAC;AAC/D,OAAO,EAAE,KAAK,oBAAoB,EAAE,MAAM,wBAAwB,CAAC;AAEnE;;;;GAIG;AACH,MAAM,MAAM,aAAa,GAAG,IAAI,CAC9B,iBAAiB,CAAC,eAAe,CAAC,EAClC,WAAW,CACZ,CAAC;AAEF;;;;;GAKG;AACH,MAAM,WAAW,gBAAgB;IAC/B,MAAM,EAAE,MAAM,CAAC,MAAM,EAAE,oBAAoB,CAAC,CAAC;IAC7C,UAAU,EAAE,MAAM,CAAC;CACpB;AAED;;;;GAIG;AACH,MAAM,MAAM,gBAAgB,GAAG,MAAM,CAAC,aAAa,EAAE,oBAAoB,CAAC,CAAC;AAE3E;;;;;;;;;;;;;;;;;;;GAmBG;AACH,MAAM,MAAM,cAAc,GAAG,MAAM,CAAC,WAAW,EAAE,oBAAoB,CAAC,CAAC;AAEvE;;;;;;GAMG;
|
|
1
|
+
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../../src/query-utils/types.ts"],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O,CAAC,MAAM,CAAC,gBAAgB;IAoB/B,OAAO,CAAC,MAAM,CAAC,4BAA4B;CA+B5C;AAED,eAAe,SAAS,CAAC"}
|
|
@@ -79,7 +79,8 @@ class JoinTable {
|
|
|
79
79
|
}
|
|
80
80
|
return transactionResults.reduce((acc, res) => {
|
|
81
81
|
if (res.Item !== undefined) {
|
|
82
|
-
|
|
82
|
+
const id = res.Item[idAlias];
|
|
83
|
+
acc[id] = res.Item;
|
|
83
84
|
}
|
|
84
85
|
return acc;
|
|
85
86
|
}, {});
|
|
@@ -183,8 +184,8 @@ class JoinTable {
|
|
|
183
184
|
const tableMeta = metadata_1.default.getEntityTable(entities.parentEntity.name);
|
|
184
185
|
const idAlias = tableMeta.defaultAttributes.id.alias;
|
|
185
186
|
const foundEntityIds = new Set(transactionResults
|
|
186
|
-
.filter(result => result
|
|
187
|
-
.map(result => result.Item
|
|
187
|
+
.filter(result => result.Item !== undefined)
|
|
188
|
+
.map(result => result.Item[idAlias]));
|
|
188
189
|
const missingEntities = joinedEntityData.filter(entityData => {
|
|
189
190
|
return !foundEntityIds.has(entityData.entityId); // If not in Set, it's missing
|
|
190
191
|
});
|
package/dist/src/utils.d.ts
CHANGED
|
@@ -7,7 +7,7 @@ import { type EntityAttributesOnly } from "./operations";
|
|
|
7
7
|
* @param entityData
|
|
8
8
|
* @returns
|
|
9
9
|
*/
|
|
10
|
-
export declare const entityToTableItem:
|
|
10
|
+
export declare const entityToTableItem: (EntityClass: new () => DynaRecord, entityData: Partial<DynaRecord>) => DynamoTableItem;
|
|
11
11
|
/**
|
|
12
12
|
* Serialize a table item to its associated Entity class, using the class attribute property names
|
|
13
13
|
* @param EntityClass
|
|
@@ -29,7 +29,7 @@ export declare const isKeyOfEntity: (entity: DynaRecord, key: string) => key is
|
|
|
29
29
|
* @param key
|
|
30
30
|
* @returns
|
|
31
31
|
*/
|
|
32
|
-
export declare const isKeyOfObject: <T>(entity: Partial<DynaRecord>, key:
|
|
32
|
+
export declare const isKeyOfObject: <T>(entity: Partial<DynaRecord>, key: PropertyKey) => key is keyof T;
|
|
33
33
|
/**
|
|
34
34
|
* Break an array into chunks
|
|
35
35
|
* @param array
|
|
@@ -43,7 +43,7 @@ export declare const chunkArray: <T>(array: T[], size: number) => T[][];
|
|
|
43
43
|
* @param value - The value to check. This can be any type as the function is meant to validate if it's a string.
|
|
44
44
|
* @returns `true` if `value` is a string; otherwise, `false`.
|
|
45
45
|
*/
|
|
46
|
-
export declare const isString: (value:
|
|
46
|
+
export declare const isString: (value: unknown) => value is string;
|
|
47
47
|
/**
|
|
48
48
|
* Safely assigns a value to a property of an object.
|
|
49
49
|
* It's useful for dynamically assigning properties to objects where the property names might be known but the types could vary.
|
|
@@ -62,7 +62,7 @@ export declare const isString: (value: any) => value is string;
|
|
|
62
62
|
* let entity = { id: "123" };
|
|
63
63
|
* safeAssign(entity, "name", "Jane Doe");
|
|
64
64
|
*/
|
|
65
|
-
export declare const safeAssign: <TObject extends EntityAttributesOnly<DynaRecord
|
|
65
|
+
export declare const safeAssign: <TObject extends EntityAttributesOnly<DynaRecord>>(object: TObject, key: keyof TObject, value: unknown) => void;
|
|
66
66
|
/**
|
|
67
67
|
* Type guard to check if a string is a Nullable<string>
|
|
68
68
|
* @param val
|
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,QAAQ,EAAE,MAAM,SAAS,CAAC;AAEzD,OAAO,EAAE,KAAK,oBAAoB,EAAE,MAAM,cAAc,CAAC;AAEzD;;;;;GAKG;AACH,eAAO,MAAM,iBAAiB,
|
|
1
|
+
{"version":3,"file":"utils.d.ts","sourceRoot":"","sources":["../../src/utils.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,UAAU,MAAM,cAAc,CAAC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adata"));
|
|
|
13
13
|
*/
|
|
14
14
|
const entityToTableItem = (EntityClass, entityData) => {
|
|
15
15
|
const attributesMeta = metadata_1.default.getEntityAttributes(EntityClass.name);
|
|
16
|
-
return Object.entries(entityData).reduce((acc, [key,
|
|
17
|
-
|
|
18
|
-
|
|
16
|
+
return Object.entries(entityData).reduce((acc, [key, rawVal]) => {
|
|
17
|
+
if (key in attributesMeta) {
|
|
18
|
+
const attrMeta = attributesMeta[key];
|
|
19
19
|
const { alias, serializers } = attrMeta;
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
20
|
+
const val = rawVal;
|
|
21
|
+
// eslint-disable-next-line @typescript-eslint/no-unsafe-assignment -- DynamoTableItem values are NativeAttributeValue (any) from AWS SDK
|
|
22
|
+
acc[alias] =
|
|
23
|
+
serializers === undefined || val === null
|
|
24
|
+
? val
|
|
25
|
+
: serializers.toTableAttribute(val);
|
|
25
26
|
}
|
|
26
27
|
return acc;
|
|
27
28
|
}, {});
|
|
@@ -37,14 +38,14 @@ const tableItemToEntity = (EntityClass, tableItem) => {
|
|
|
37
38
|
const tableAttributes = metadata_1.default.getEntityTableAttributes(EntityClass.name);
|
|
38
39
|
const entity = new EntityClass();
|
|
39
40
|
Object.keys(tableItem).forEach(attrName => {
|
|
40
|
-
|
|
41
|
-
|
|
41
|
+
if (attrName in tableAttributes) {
|
|
42
|
+
const attrMeta = tableAttributes[attrName];
|
|
42
43
|
const { name: entityKey, serializers } = attrMeta;
|
|
43
44
|
if ((0, exports.isKeyOfEntity)(entity, entityKey)) {
|
|
44
45
|
const rawVal = tableItem[attrName];
|
|
45
46
|
const val = serializers?.toEntityAttribute === undefined
|
|
46
47
|
? rawVal
|
|
47
|
-
: serializers
|
|
48
|
+
: serializers.toEntityAttribute(rawVal);
|
|
48
49
|
(0, exports.safeAssign)(entity, entityKey, val);
|
|
49
50
|
}
|
|
50
51
|
}
|
|
@@ -78,6 +79,7 @@ exports.isKeyOfEntity = isKeyOfEntity;
|
|
|
78
79
|
* @param key
|
|
79
80
|
* @returns
|
|
80
81
|
*/
|
|
82
|
+
// eslint-disable-next-line @typescript-eslint/no-unnecessary-type-parameters -- Generic T needed for narrowing key to keyof T at call sites
|
|
81
83
|
const isKeyOfObject = (entity, key) => {
|
|
82
84
|
return key in entity;
|
|
83
85
|
};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "dyna-record",
|
|
3
|
-
"version": "0.5.
|
|
3
|
+
"version": "0.5.1",
|
|
4
4
|
"description": "Typescript Data Modeler and ORM for Dynamo",
|
|
5
5
|
"main": "dist/index.js",
|
|
6
6
|
"types": "dist/index.d.ts",
|
|
@@ -11,8 +11,8 @@
|
|
|
11
11
|
"typecheck:tests": "tsc -p tsconfig.dev.json --noEmit",
|
|
12
12
|
"test": "tsc -p tsconfig.dev.json --noEmit && jest",
|
|
13
13
|
"test:watch": "jest --watch",
|
|
14
|
-
"eslint": "npx eslint .
|
|
15
|
-
"eslint:fix": "npx eslint . --
|
|
14
|
+
"eslint": "npx eslint .",
|
|
15
|
+
"eslint:fix": "npx eslint . --fix",
|
|
16
16
|
"prettier": "npx prettier . --write",
|
|
17
17
|
"docs": "npx typedoc"
|
|
18
18
|
},
|
|
@@ -35,25 +35,23 @@
|
|
|
35
35
|
},
|
|
36
36
|
"devDependencies": {
|
|
37
37
|
"@aws-sdk/types": "^3.502.0",
|
|
38
|
+
"@eslint/js": "^9.39.3",
|
|
38
39
|
"@tsconfig/recommended": "^1.0.3",
|
|
39
40
|
"@types/jest": "^29.5.12",
|
|
40
41
|
"@types/node": "^20.11.16",
|
|
41
42
|
"@types/uuid": "^9.0.8",
|
|
42
|
-
"@typescript-eslint/eslint-plugin": "^
|
|
43
|
-
"
|
|
44
|
-
"eslint": "^
|
|
45
|
-
"
|
|
46
|
-
"eslint-config-standard-with-typescript": "^43.0.1",
|
|
47
|
-
"eslint-plugin-import": "^2.29.1",
|
|
48
|
-
"eslint-plugin-n": "^16.6.2",
|
|
49
|
-
"eslint-plugin-promise": "^6.1.1",
|
|
43
|
+
"@typescript-eslint/eslint-plugin": "^8.56.1",
|
|
44
|
+
"eslint": "^9.39.3",
|
|
45
|
+
"eslint-config-prettier": "^10.1.8",
|
|
46
|
+
"globals": "^16.5.0",
|
|
50
47
|
"jest": "^29.7.0",
|
|
51
48
|
"prettier": "^3.2.5",
|
|
52
49
|
"ts-jest": "^29.1.2",
|
|
53
50
|
"ts-node": "^10.9.2",
|
|
54
51
|
"typedoc": "^0.27.6",
|
|
55
52
|
"typedoc-plugin-missing-exports": "^3.1.0",
|
|
56
|
-
"typescript": "^5.7.2"
|
|
53
|
+
"typescript": "^5.7.2",
|
|
54
|
+
"typescript-eslint": "^8.56.1"
|
|
57
55
|
},
|
|
58
56
|
"engines": {
|
|
59
57
|
"npm": ">=10.0.0",
|