···3333 - just gen_typescript
3434 script:
3535 - |
3636- for file in typescript/*.ts; do
3636+ for file in {events.go,typescript/*.ts}; do
3737 if ! diff -q $file typescript_original/$(basename $file); then
3838 diff typescript_original/$(basename $file) $file
3939 echo "Generated file $file is different from original, please run 'just gen_typescript' and commit the changes"
+4-3
Justfile
···2222 sed -i '/^generator .* {/,/^}/d' schema.prisma
2323 sed -i '1i\
2424 generator goprisma {\n\
2525- provider = "go run github.com/steebchen/prisma-client-go"\n\
2525+ provider = "go run github.com/steebchen/prisma-client-go"\n\
2626 previewFeatures = ["fullTextSearchPostgres", "postgresqlExtensions"]\n\
2727 }\
2828 ' schema.prisma
···303031313232genprisma:
3333- go get github.com/steebchen/prisma-client-go
3434- go run github.com/steebchen/prisma-client-go generate
3333+ go get github.com/steebchen/prisma-client-go
3434+ go run github.com/steebchen/prisma-client-go generate
35353636gen_typescript:
3737+ bash scripts/sync-event-enum.sh
3738 go run scripts/typing.go
38393940generate:
+2-1
events.go
···3535 // When to push the notification
3636 SendAt time.Time `json:"send_at"`
3737 // Type of event that triggered the notification
3838- Event Event `json:"event" jsonschema:"enum=save_schedule,enum=clear_schedule,enum=clear_stored_schedule,enum=restore_schedule,enum=restore_schedule_eager,enum=clear_scheduled_jobs,enum=show_scheduled_jobs,enum=new_post,enum=godchild_request,enum=new_comment,enum=comment_reply,enum=custom,enum=test,enum=godchild_accepted,enum=godchild_rejected,enum=pending_signup,enum=login_stuck,enum=booking_paid,enum=contribution_paid,enum=shotgun_opens_soon,enum=shotgun_closes_soon"`
3838+ // next-line-generate event-enum-jsonschema-values
3939+ Event Event `json:"event" jsonschema:"enum=clear_scheduled_jobs,enum=clear_stored_schedule,enum=show_scheduled_jobs,enum=save_schedule,enum=restore_schedule,enum=restore_schedule_eager,enum=clear_schedule,enum=new_post,enum=godchild_request,enum=custom,enum=test,enum=godchild_accepted,enum=godchild_rejected,enum=pending_signup,enum=login_stuck,enum=booking_paid,enum=contribution_paid,enum=shotgun_opens_soon,enum=shotgun_closes_soon"`
3940 // Churros ID of the ressource (the ticket, the post, the comment, etc)
4041 // Used to determine to whom the notification should be sent
4142 // For godchild_request, this is not a user id, but a godparent request id.
+78
scripts/sync-event-enum.sh
···11+#!/bin/bash
22+33+# Exit on any error
44+set -e
55+66+# Function to extract event constants from Go file within the same const block
77+extract_events() {
88+ local file="$1"
99+ # Create a temporary file to store the const block
1010+ local tempfile=$(mktemp)
1111+1212+ # Extract the const block containing Event definitions
1313+ awk '/^const \($/ {p=1;next} /^\)$/ {p=0} p' "$file" > "$tempfile"
1414+1515+ # Extract event values from the const block
1616+ grep -o 'Event = "[^"]*"' "$tempfile" | cut -d'"' -f2 | tr '\n' '=' | sed 's/=$//' | sed 's/=/,enum=/g'
1717+1818+ # Clean up
1919+ rm "$tempfile"
2020+}
2121+2222+# Function to update JSON schema in Go file
2323+update_schema() {
2424+ local file="$1"
2525+ local events="$2"
2626+2727+ # Create temporary file
2828+ local tempfile=$(mktemp)
2929+3030+ # Flag to track if we found the generate comment
3131+ local next_line_update=0
3232+3333+ # Process the file line by line
3434+ while IFS= read -r line; do
3535+ if [ $next_line_update -eq 1 ]; then
3636+ # Update the line after the comment
3737+ echo "$line" | sed "s/jsonschema:\"enum=[^\"]*\"/jsonschema:\"enum=$events\"/" >> "$tempfile"
3838+ next_line_update=0
3939+ elif [[ $line =~ "next-line-generate event-enum-jsonschema-values" ]]; then
4040+ # Mark the next line for update
4141+ echo "$line" >> "$tempfile"
4242+ next_line_update=1
4343+ else
4444+ echo "$line" >> "$tempfile"
4545+ fi
4646+ done < "$file"
4747+4848+ # Replace original file with updated content
4949+ mv "$tempfile" "$file"
5050+}
5151+5252+# Main script
5353+main() {
5454+ local file="${1:-events.go}" # Default to events.go if no file specified
5555+5656+ if [ ! -f "$file" ]; then
5757+ echo "Error: File $file not found"
5858+ exit 1
5959+ fi
6060+6161+ echo "Processing $file..."
6262+6363+ # Extract events and update schema
6464+ local events=$(extract_events "$file")
6565+6666+ if [ -z "$events" ]; then
6767+ echo "Error: No events found in const block"
6868+ exit 1
6969+ fi
7070+7171+ update_schema "$file" "$events"
7272+7373+ echo "Successfully updated JSON schema enum values"
7474+ echo "New values: $events"
7575+}
7676+7777+# Run the script
7878+main "$@"