const InfrastructureKind = Schema.Literal(['Manufactory', 'SolarFarm', 'Laboratory'])
const Aggregate = Schema.Struct({
tiers: Schema.Record({ key: typeof InfrastructureKind.Type, value: Schema.NonNegativeInt })
})
// ...
const [colony] = db
.select({
manufactoryTier: coloniesTable.manufactoryTier,
solarFarmTier: coloniesTable.solarFarmTier,
laboratoryTier: coloniesTable.laboratoryTier,
})
.from(coloniesTable)
.where(eq(coloniesTable.ownerId, userId))
const aggregateOne = Aggregate.make({
tiers: {
Manufactory: colony.manufactoryTier,
SolarFarm: colony.solarFarmTier,
Laboratory: colony.laboratoryTier,
}
})
const aggregateTwo = Aggregate.make({
tiers: InfrastructureKind.literals.reduce((acc, el) => {
acc[el] = colony[`${kebabCase(el)}Tier`]
return acc
}, {})
})
const InfrastructureKind = Schema.Literal(['Manufactory', 'SolarFarm', 'Laboratory'])
const Aggregate = Schema.Struct({
tiers: Schema.Record({ key: typeof InfrastructureKind.Type, value: Schema.NonNegativeInt })
})
// ...
const [colony] = db
.select({
manufactoryTier: coloniesTable.manufactoryTier,
solarFarmTier: coloniesTable.solarFarmTier,
laboratoryTier: coloniesTable.laboratoryTier,
})
.from(coloniesTable)
.where(eq(coloniesTable.ownerId, userId))
const aggregateOne = Aggregate.make({
tiers: {
Manufactory: colony.manufactoryTier,
SolarFarm: colony.solarFarmTier,
Laboratory: colony.laboratoryTier,
}
})
const aggregateTwo = Aggregate.make({
tiers: InfrastructureKind.literals.reduce((acc, el) => {
acc[el] = colony[`${kebabCase(el)}Tier`]
return acc
}, {})
})