Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions demo/main.tsp
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,14 @@ model Job {
sk: [Person.firstName],
}
)
@index(
"byAge",
{
index: "lsi1",
pk: [Person.pk],
sk: [Person.age],
}
)
model Person {
@invisible(Lifecycle)
pk: UUID;
Expand Down
10 changes: 8 additions & 2 deletions src/decorators/$index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,8 @@ const getStringValue = (source: Model, name: string) => {
}
};

const isLocalSecondaryIndex = (index: string) => /^lsi[1-5]$/.test(index);

const normalizeKey = (
keyName: string,
params: { target: Model; pattern: Model },
Expand All @@ -63,9 +65,13 @@ const normalizeKey = (
const key = getProperty(pattern, keyName);
const index = getStringValue(pattern, "index") ?? "";

// LSI (Local Secondary Index) must share the same pk as the primary index
const fieldPrefix =
keyName === "pk" && isLocalSecondaryIndex(index) ? "" : index;

if (key && key.kind === "Tuple") {
return {
field: `${index}${keyName}`,
field: `${fieldPrefix}${keyName}`,
composite: extractFieldNames(target, key),
};
}
Expand All @@ -83,7 +89,7 @@ const normalizeKey = (
}

return {
field: `${index}${keyName}`,
field: `${fieldPrefix}${keyName}`,
composite: [],
};
};
Expand Down