Closed goodeats closed 4 months ago
example of what the json string data for designs could look like:
// Palette
{
"format": "hex",
"value": "000000",
"opacity": 1.0
}
// Size
{
"format": "percent",
"value": 10,
"basis": "width"
}
// Fill
{
"style": "solid",
"value": "000000",
"basis": "defined"
}
// Stroke
{
"style": "solid",
"value": "000000",
"basis": "defined"
}
// Line
{
"width": 1,
"format": "pixel",
"basis": "size"
}
// Rotate
{
"value": 0,
"basis": "defined"
}
// Layout
{
"style": "random",
"count": 1000,
"rows": 9,
"columns": 9
}
// Template
{
"style": "triangle"
}
Background
A while back I moved designs to a polymorphic parent-child model architecture based on type Issue: https://github.com/goodeats/epic-pppaaattt.xyz/issues/28
It followed the advice of this article https://www.basedash.com/blog/how-to-model-inheritance-in-prisma
I was having trouble managing the JSON parse and stringify along with zod schema checks becoming a challenge to manage complexity in a scalable way
Problem
Discussion
Advantages of Using JSON Strings in the Design/Asset Model
1 is good 2 is very important, this project has gone from a fun side-project to something I could build for real users and I want to be able to meed their needs quickly 3 is fine, not as important until I need to scale... I'll be looking for help when that happens :D
Considerations and Trade-offs
1 will have to be extremely diligent with using zod to validate schema on parse and stringify for each type 2 JSON string shouldn't have to be queried for anything; just have the data and the configuration details 3 see 3 from above :D
Implementation
Define Asset Types Enum: Create an enumerator for different asset types.
Define JSON Schemas for Each Asset Type
Modify the Prisma Schema
Create Asset Interfaces
CRUD Operations
Validation Functions
Create functions to validate JSON data using Zod before storing it in the database. This ensures that the attributes data conforms to the expected structure.