Open Jean-Baptiste-Lasselle opened 2 months ago
the Pesto REST API must guarantee the integrity of the database, such that those properties are always true for and 3-tuple of (a project
, a content-type
, a content
):
content
, and a content-type
, are associated (via the content_type_id
foreign key of the content), the project_id
field of the two are equalcontent
, and a content-type
, are associated (via the content_type_id
foreign key of the content), the frontmatter
of the content
, always sucessfully compiles against the frontmatter_definition
of the content-type
for compiling frontmatter , as well as extracting the content at the same time, I have now a solution its this : https://github.com/3forges/frontmatter-experiments/issues/1
All this without creating any file.
Note also that I have one other part where https://github.com/3forges/frontmatter-experiments/issues/1 will be very useful : to generate the zod schema that pesto will use to modify the source code of an Astro website (to CRUD content types inside the source cdoe of an astro website)
Modify Pesto API source code so that those new constraints are added:
project_id
for a project that does not exist, an error is thrownfrontmatter_definition
, it must compile as typescript, and it must have one and only one interface declaration. Do verification using ts morph, as i already did in the pesto ui: so this task is about creating an new git repo for a new npm package which will be reused in both api and ui, to have one single place where ts morph based constraints and conversions are implemented, and used the same way in both api and ui. th epackage will have to always be used in the same version number in peto ui and pesto api, to ensure exact same constraints are done in ui and apicontent
is created, with aproject_id
for a project that does not exist, an error is throwncontent-type
is updated, it is not allowed to change itsproject_id
: an error is thrown (instead you can clone and delete, seecontent
clone operation below)content
is updated, it is not allowed to change itsproject_id
: an error is thrown (instead you can clone and delete, seecontent
clone operation below)content
is updated, and itscontent_type_id
is changed, then 2 constraints must be respected, or the update is not allowed:frontmatter
must compile against the newcontent-type
'sfrontmatter_definition
: otherwise, the update is not allowed, and an error is thrown (instead you can clone and delete, see content clone operation below)project_id
than the update content: otherwise, the update is not allowed, and an error is thrown (instead you can clone and delete, see content clone operation below)content_type_id
for a content type that does not exist, an error is throwncontent_type_id
content_type_id
, has aproject_id
field:Because of the above constraints on CRUD operations, we need new operations:
Something else to implement (and to move into a different issue) :
frontmatter_definition
to a zod , and store the converted result into azod_conversions
table in database (src/content/config.ts
containing all content types frontmatter defintiion converted to zod, and store the converted result into aastro_conversions
table in database this is to increase performance of conversion work, when the conversion is not found is database is it done on the fly and store in database as a cache, if you want, and then result returned. anyway we will see later about those conversion features, this is not about constraints imlplementation