Skip to content

Commit

Permalink
references fix
Browse files Browse the repository at this point in the history
  • Loading branch information
Moicky committed Apr 5, 2024
1 parent e072506 commit 69fa640
Showing 1 changed file with 25 additions and 17 deletions.
42 changes: 25 additions & 17 deletions src/transactions/references/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -85,19 +85,22 @@ export const createCustomReference = async (
references: DynamoDBItemKey,
onAttribute?: string
) =>
putItem({
PK: "dynamodb:reference",
SK: randomUUID(),
item: {
PK: baseItem.PK,
...(baseItem.SK && { SK: baseItem.SK }),
},
references: {
PK: references.PK,
...(references.SK && { SK: references.SK }),
},
onAttribute: onAttribute || "",
} satisfies ReferenceMetadata);
putItem(
{
PK: "dynamodb:reference",
SK: randomUUID(),
item: {
PK: baseItem.PK,
...(baseItem.SK && { SK: baseItem.SK }),
},
references: {
PK: references.PK,
...(references.SK && { SK: references.SK }),
},
onAttribute: onAttribute || "",
} satisfies ReferenceMetadata,
{ ReturnValues: "ALL_NEW" }
);

export const resolveReferences = async <T extends DynamoDBItem>(
item: T
Expand All @@ -116,9 +119,7 @@ export const resolveReferences = async <T extends DynamoDBItem>(
return injectRefs(resolvedItem, fetchedRefs);
};

export const getDependencies = async <T extends ItemWithKey = ItemWithKey>(
item: ItemWithKey
) =>
export const getDependencies = async (item: ItemWithKey) =>
queryAllItems<ReferenceMetadata>(
"#PK = :PK",
{
Expand All @@ -129,7 +130,14 @@ export const getDependencies = async <T extends ItemWithKey = ItemWithKey>(
},
},
{ FilterExpression: "#references = :references" }
).then((refs) =>
);

export const getResolvedDependencies = async <
T extends ItemWithKey = ItemWithKey
>(
item: ItemWithKey
) =>
getDependencies(item).then((refs) =>
getItems(
refs
.map(({ item }) => item)
Expand Down

0 comments on commit 69fa640

Please sign in to comment.