Skip to content

Add function and middleware short forms that expand to the long form - #96

Merged
jimhoyd merged 2 commits into
mainfrom
claude/issue-84-short-form-function
Sep 18, 2026
Merged

jimhoyd merged 2 commits into
mainfrom
claude/issue-84-short-form-function

Conversation

@jimhoyd

@jimhoyd jimhoyd commented Sep 18, 2026

Copy link
Copy Markdown
Collaborator

Problem and change

The smallest function route was ten lines: a parameters block, a function.source and an args map for every {param}. NEXT-STEPS §4.1 asks for a short form.

  • function: functions/hello.mjs (a string) and string middleware entries are now admitted by schemas/urlcode.schema.json.
  • validateDocument runs a separate normalizeRoute pass (alongside the existing normalizeRouteAuth) that expands them before anything else reads the route: each {param} in the path becomes a required {type: string, minLength: 1, maxLength: 128} input plus a matching args entry, unless the route already declares that path parameter (declared parameters keep their schema and order); a middleware string becomes {source}. Strings must be project-relative .mjs/.js paths without ..; anything else is refused with the route path named.
  • The long form stays the canonical IR, so routes, audit, explain, revision hashes and the generated reference show the expansion.
  • The MCP create_route tool now writes the short form into YAML and delegates expansion to the same normalizer (its previous private expansion used maxLength: 256; one rule now).
  • Cookbook /api/items converted to the short form (route count stays 40, existing fixtures cover it).
  • Docs: docs/yaml/functions.md opens with the short form and shows the expansion, docs/SPECIFICATION.md documents the normalization, docs/AI-AUTHORING.md matrix row added, docs/YAML-REFERENCE.md regenerated, llms-full.txt rebuilt.
  • Tests (test/config.test.ts): short and long forms validate to deep-equal documents, declared parameter override, string middleware, refused strings citing the route, and a request served through the runtime (including the 128-character bound).

Verification

  • npm run verify (lint, typecheck, check incl. reference/llms-full staleness, build, tests): exit 0.
  • npm test standalone: 456 tests, 416 pass, 37 skipped (SQLite WAL skips), 3 timing-sensitive failures (sync function hangs time out, versioned fixture ... adapters, deadline kills the worker) that pass when re-run in isolation and passed inside the verify run.
  • node src/cli.ts audit --project examples/cookbook --expect-routes 40: 40 routes, 136/136 checks pass.

Compatibility and security

Additive YAML change; version: "1" and every existing long-form document validate unchanged. No new permissions, bindings or network behaviour: a short-form source goes through the same safeFile confinement as before after expansion. No data handling or deployment impact.

  • Changes match the documented portable contract; docs/examples are updated where needed.
  • Relevant tests and package checks pass, or limitations are explained above.
  • No credentials, customer data or private project material are included.
  • Runtime/starter changes remain aligned where applicable.

Closes #84

🤖 Generated with Claude Code

https://claude.ai/code/session_01AQ3ZGqNtWviSYfUMsxU54E


Generated by Claude Code

…84)

`function: functions/hello.mjs` and string `middleware` entries are now
valid YAML. Document validation expands them before anything else reads
the route: every `{param}` in the path becomes a required string input
(minLength 1, maxLength 128) plus a matching `args` entry unless the
route declares that parameter itself, and a middleware string becomes
`{source}`. Invalid strings are refused with the route named. The long
form stays the canonical IR, so routes, audit, explain, revision hashes
and the generated reference show the expansion.

The MCP create_route tool now writes the short form and relies on the
same normalizer. The cookbook /api/items route uses the short form (40
routes, unchanged). Guide, specification, authoring matrix, reference
and llms-full.txt updated; tests cover deep-equal IR, declared
parameter override, string middleware, refused strings and a request
through the runtime.

Closes #84

Co-Authored-By: Claude Fable 5.1 <[email protected]>
Claude-Session: https://claude.ai/code/session_01AQ3ZGqNtWviSYfUMsxU54E
@jimhoyd
jimhoyd merged commit 360ceed into main Sep 18, 2026
12 checks passed
@jimhoyd
jimhoyd deleted the claude/issue-84-short-form-function branch September 18, 2026 07:21
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Short form for function and middleware routes

2 participants