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
15 changes: 14 additions & 1 deletion src/emitter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -59,9 +59,22 @@ function emitScalar(type: Scalar): Attribute {
}

function emitArrayModel(type: ArrayModelType): Attribute {
const elementType = type.indexer.value;

// Enum arrays should be emitted as DynamoDB/ElectroDB "set" type
if (elementType.kind === "Enum") {
const items = Array.from(elementType.members).map(
([key, member]) => `${member.value ?? key}`,
);
return {
type: "set",
items,
};
}

return {
type: "list",
items: emitType(type.indexer.value) as CustomAttribute,
items: emitType(elementType) as CustomAttribute,
};
}

Expand Down
23 changes: 23 additions & 0 deletions test/entities.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -205,6 +205,29 @@ suite("Person Entity", () => {
});
});

suite("Set type (CoffeePreferences[] - enum array)", () => {
test("coffeePreferences is a set type with required: true", () => {
assert.equal(Person.attributes.coffeePreferences.type, "set");
assert.equal(Person.attributes.coffeePreferences.required, true);
});

test("coffeePreferences items contain enum values", () => {
assert.deepEqual(Person.attributes.coffeePreferences.items, [
"01",
"02",
"03",
]);
});

test("coffeePreferences has correct full structure", () => {
assert.deepEqual(Person.attributes.coffeePreferences, {
type: "set",
items: ["01", "02", "03"],
required: true,
});
});
});

suite("Index configurations", () => {
test("persons index (primary, pk only)", () => {
const personsIndex = Person.indexes.persons;
Expand Down
16 changes: 16 additions & 0 deletions test/main.tsp
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,18 @@ scalar String64 extends string;
@minLength(25)
scalar UUID extends string;

enum PersonStatus {
ACTIVE: "01",
INACTIVE: "02",
DELETED: "03",
}

enum CoffeePreferences {
MILK: "01",
SUGAR: "02",
SWEETENER: "03",
}

enum CountryCode {
NL,
US,
Expand Down Expand Up @@ -91,4 +103,8 @@ model Person {
address: Address;
contact: Contact[];
nickName?: string;

status: PersonStatus;

coffeePreferences: CoffeePreferences[];
}