mirror of
https://github.com/GabrielVidal1/ask-form.git
synced 2026-12-02 10:07:28 +01:00
`ask-form create form.yaml` takes the whole form in one file: title, description, lang and sections (each a page, keyed by its title), with fields keyed by their key, options by their value and a table's columns by their key, in the order written. A section takes an intro (markdown under its title) and a showIf for the whole page. Plain lists of option texts and the old lists (`key:` fields, `value:` options) are read too, and the flat JSON field array still works byte for byte (--fields-file spec.json). - internal/form/yaml.go: a strict YAML 1.2 subset reader, stdlib only. Ordered mappings (*form.Map), block and flow collections, | and > scalars, quotes, comments; refuses anchors, tags, ? keys, several documents, tab indentation and duplicate keys, with the line. Only true/false are booleans; a number keeps its text (json.Number). - internal/form/doc.go: ParseDoc compiles a form file (YAML, or JSON of the same shape) into the flat field array: section title -> group, intro -> a markdown block, section showIf AND-ed into its fields'. The CLI does it before POST /v1/forms, so server, relay, store and MCP are unchanged and a new CLI works with an older serve. - examples: spec.yaml + spec.fr.yaml replace the JSON specs (converted, each checked to normalise to the same fields); /spec.json still answers with the form compiled to JSON. - SKILL.md, the claude.ai sandbox skill, agent-install, README and CLAUDE.md teach the YAML form file; a test keeps SKILL.md's YAML valid. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
104 lines
5.2 KiB
YAML
104 lines
5.2 KiB
YAML
title: 'Comments: the data model'
|
|
description: Comments on posts, with replies and reactions. Here is the schema and the API as I'd build them. A few choices are yours; my picks are pre-selected, with why.
|
|
summary: |-
|
|
Design review: the schema drawn as a diagram, the endpoints in a table, then the open choices: threading, IDs, deletion, pagination.
|
|
order: 6
|
|
sections:
|
|
The model:
|
|
fields:
|
|
schema:
|
|
type: html
|
|
label: Schema
|
|
html: |-
|
|
<svg viewBox="0 0 420 250" xmlns="http://www.w3.org/2000/svg" style="display:block;width:100%;max-width:560px;height:auto;margin:0 auto;font:12.5px ui-monospace,SFMono-Regular,Menlo,monospace">
|
|
<g fill="hsl(var(--card))" stroke="hsl(var(--border))"><rect x="6" y="20" width="118" height="86" rx="10"/><rect x="6" y="140" width="118" height="70" rx="10"/></g>
|
|
<rect x="150" y="6" width="134" height="238" rx="10" fill="hsl(var(--primary) / .08)" stroke="hsl(var(--primary))"/>
|
|
<rect x="306" y="40" width="108" height="98" rx="10" fill="hsl(var(--primary) / .08)" stroke="hsl(var(--primary))"/>
|
|
<g font-weight="700" fill="hsl(var(--foreground))" font-family="system-ui,sans-serif" font-size="14"><text x="18" y="42">posts</text><text x="18" y="162">users</text><text x="162" y="28">comments</text><text x="318" y="62">reactions</text></g>
|
|
<g fill="hsl(var(--muted-foreground))">
|
|
<text x="18" y="64">id</text><text x="18" y="82">author_id</text><text x="18" y="100">…</text>
|
|
<text x="18" y="184">id</text><text x="18" y="202">name</text>
|
|
<text x="162" y="52">id</text><text x="162" y="72">post_id</text><text x="162" y="92">parent_id</text><text x="162" y="112">author_id</text><text x="162" y="132">body</text><text x="162" y="152">created_at</text><text x="162" y="172">edited_at</text><text x="162" y="192">deleted_at</text><text x="162" y="212">reply_count</text>
|
|
<text x="318" y="84">comment_id</text><text x="318" y="104">user_id</text><text x="318" y="124">emoji</text></g>
|
|
<g fill="none" stroke="hsl(var(--muted-foreground))" stroke-width="1.4"><path d="M124 60H136V68H150"/><path d="M124 180H136V108H150"/><path d="M284 48H296V80H306"/><path d="M284 88C300 88 300 100 284 100"/></g>
|
|
<text x="210" y="236" fill="hsl(var(--muted-foreground))" font-family="system-ui,sans-serif" font-size="11" text-anchor="middle">parent_id → comments.id (a reply)</text>
|
|
</svg>
|
|
endpoints:
|
|
type: markdown
|
|
label: Endpoints
|
|
text: |-
|
|
| Route | Does |
|
|
|---|---|
|
|
| `GET /posts/:id/comments` | list, newest first, paged |
|
|
| `POST /posts/:id/comments` | add; `parent_id` for a reply |
|
|
| `PATCH /comments/:id` | edit, author only |
|
|
| `DELETE /comments/:id` | delete, author or post owner |
|
|
| `PUT /comments/:id/reactions/:emoji` | toggle a reaction |
|
|
threading:
|
|
type: radio
|
|
label: How deep do replies go?
|
|
required: true
|
|
default: one-level
|
|
help: One level reads well on a phone and keeps the list a single query.
|
|
options:
|
|
one-level:
|
|
label: One level
|
|
description: Replies under a comment, no replies to replies (like Slack threads)
|
|
tree: {label: A full tree, description: Any depth (like Reddit); needs a recursive query}
|
|
flat: {label: No replies, description: Drop parent_id}
|
|
ids:
|
|
type: radio
|
|
label: ID type
|
|
required: true
|
|
default: uuid7
|
|
options:
|
|
uuid7: {label: UUID v7, description: 'Sortable by time, safe to show in URLs'}
|
|
serial:
|
|
label: Auto-increment integers
|
|
description: What posts use today; leaks the comment count
|
|
ulid: ULID strings
|
|
Behaviour:
|
|
fields:
|
|
deletion:
|
|
type: radio
|
|
label: What happens when someone deletes a comment?
|
|
required: true
|
|
default: soft
|
|
options:
|
|
soft:
|
|
label: It shows “deleted”, replies stay
|
|
description: 'Soft delete: the row keeps deleted_at, the body is wiped'
|
|
cascade: It goes, with its replies
|
|
orphan: It goes, replies move up
|
|
edit_window:
|
|
type: number
|
|
label: How long can a comment be edited? (minutes, 0 = always)
|
|
min: 0
|
|
step: 5
|
|
default: 15
|
|
reactions:
|
|
type: multiselect
|
|
label: Which reactions?
|
|
default: [👍, ❤️, 😂, 🎉]
|
|
options: [👍, ❤️, 😂, 🎉, 😮, 👀]
|
|
notify:
|
|
type: checkbox
|
|
label: Email the post's author about new comments (batched, at most hourly)
|
|
default: true
|
|
API:
|
|
fields:
|
|
pagination:
|
|
type: radio
|
|
label: Paging the list
|
|
required: true
|
|
default: cursor
|
|
options:
|
|
cursor: {label: Cursor, description: '`?after=<id>`: stable while new comments arrive'}
|
|
offset: {label: Page numbers, description: '`?page=3`: can repeat or skip a comment'}
|
|
json_case:
|
|
type: radio
|
|
label: Field names in the JSON
|
|
default: camel
|
|
help: The rest of your API uses camelCase.
|
|
options: {camel: camelCase (createdAt), snake: snake_case (created_at)}
|