lee
lee2y ago

sujayakar has demo code that does

@sujayakar has demo code that does exactly that. it's really slick, but i'm not sure if/when we would be able to ship it
6 Replies
sujayakar
sujayakar2y ago
yep! we have the new type inference algorithm working but (1) need to integrate it and (2) need to make some product decisions (curious what you think here @cyremur). for example, it might be a bit jarring to go and infer string literals when that isn't the developers intent and instead they're getting user data shown directly in the generated schema. for example, if a user table has an email field but there are only, say, 5 rows in the table, we'd generate a v.union of v.literals of each of the user's emails! one idea I had was to default to not inferring literals (i.e. the current behavior of v.string) and then have an interaction to instantly "refine" the type in the generated schema view if desired. thoughts?
cyremur
cyremur2y ago
ok some reference info for the use case
entities: v.array(
v.object({
controller: v.float64(),
currentAction: v.float64(),
currentMove: v.float64(),
currentPower: v.float64(),
currentToughness: v.float64(),
hexId: v.float64(),
isDead: v.boolean(),
source: v.object({
abilities: v.array(v.string()),
cost: v.string(),
descriptions: v.array(v.string()),
id: v.float64(),
image: v.string(),
name: v.string(),
power: v.float64(),
properties: v.optional(v.array(v.float64())),
theme: v.object({
dark: v.string(),
light: v.string(),
primary: v.string(),
}),
toughness: v.float64(),
type: v.string(),
}),
})
)
entities: v.array(
v.object({
controller: v.float64(),
currentAction: v.float64(),
currentMove: v.float64(),
currentPower: v.float64(),
currentToughness: v.float64(),
hexId: v.float64(),
isDead: v.boolean(),
source: v.object({
abilities: v.array(v.string()),
cost: v.string(),
descriptions: v.array(v.string()),
id: v.float64(),
image: v.string(),
name: v.string(),
power: v.float64(),
properties: v.optional(v.array(v.float64())),
theme: v.object({
dark: v.string(),
light: v.string(),
primary: v.string(),
}),
toughness: v.float64(),
type: v.string(),
}),
})
)
so this is great inference
entities: v.array(
v.object({
controller: v.float64(),
currentAction: v.float64(),
currentMove: v.float64(),
currentPower: v.float64(),
currentToughness: v.float64(),
hexId: v.float64(),
isDead: v.boolean(),
source: v.object({
abilities: v.optional(
v.array(
v.union(
v.literal("Attack"),
v.literal("RangedAttackR2D1"),
v.literal("RangedAttackR2D2"),
v.literal("Move"),
v.literal("ChannelUniversal"),
v.literal("ChannelFlame"),
v.literal("ChannelPlant"),
v.literal("ChannelCloud"),
v.literal("ChannelSpring"),
v.literal("ChannelVoid"),
v.literal("ChannelAether"),
v.literal("GrowSapling"),
v.literal("Manifesting"),
v.literal("PLACEHOLDER"),
v.literal("SPELLTEMPLATE"),
v.literal("BurningHands"),
v.literal("LightningStrike"),
v.literal("RayOfIce"),
v.literal("AcidArrow")
)
)
),
cost: v.string(),
descriptions: v.array(v.string()),
id: v.float64(),
image: v.string(),
name: v.string(),
power: v.float64(),
properties: v.optional(v.array(v.float64())),
theme: v.object({
dark: v.string(),
light: v.string(),
primary: v.string(),
}),
toughness: v.float64(),
type: v.union(
v.literal("Avatar"),
v.literal("Creature"),
v.literal("Spell")
),
}),
})
),
entities: v.array(
v.object({
controller: v.float64(),
currentAction: v.float64(),
currentMove: v.float64(),
currentPower: v.float64(),
currentToughness: v.float64(),
hexId: v.float64(),
isDead: v.boolean(),
source: v.object({
abilities: v.optional(
v.array(
v.union(
v.literal("Attack"),
v.literal("RangedAttackR2D1"),
v.literal("RangedAttackR2D2"),
v.literal("Move"),
v.literal("ChannelUniversal"),
v.literal("ChannelFlame"),
v.literal("ChannelPlant"),
v.literal("ChannelCloud"),
v.literal("ChannelSpring"),
v.literal("ChannelVoid"),
v.literal("ChannelAether"),
v.literal("GrowSapling"),
v.literal("Manifesting"),
v.literal("PLACEHOLDER"),
v.literal("SPELLTEMPLATE"),
v.literal("BurningHands"),
v.literal("LightningStrike"),
v.literal("RayOfIce"),
v.literal("AcidArrow")
)
)
),
cost: v.string(),
descriptions: v.array(v.string()),
id: v.float64(),
image: v.string(),
name: v.string(),
power: v.float64(),
properties: v.optional(v.array(v.float64())),
theme: v.object({
dark: v.string(),
light: v.string(),
primary: v.string(),
}),
toughness: v.float64(),
type: v.union(
v.literal("Avatar"),
v.literal("Creature"),
v.literal("Spell")
),
}),
})
),
this is the truth now I wouldn't except it to guess source.abilities cause that's a lot honestly but source.type should be simple enough my user-in-your-face approach to this would be to highlight this on the generated schema page as a potential enum
cyremur
cyremur2y ago
this would be how I'd try to convey it to the user
No description
sujayakar
sujayakar2y ago
love it! yeah I like the framing as "potential enum" for exploration. we haven't decided on constants yet, but we'd be able infer unions up to a set length (say, 16). in your example, abilities would "overflow" to just v.string() without the ability to infer a potential enum.
cyremur
cyremur2y ago
on another note, is there away to use v.object({...}).type in a typedef? trying to get to single source of truth with the schema.ts

Did you find this page helpful?