Repository navigation
fix: read include / sort support off the wire name (#300 follow-up) - #306
Merged
Merged
Conversation
The empty-vocabulary support check matched the decoded property name, while the declared-name walk matches the wire name. A query whose wire `include` decodes into a renamed property (`Schema.encodeKeys`) was misclassified: `?include=` answered 200 and `?include=author` the codec's 400, where the owner decision on #282 makes both the unsupported 400. `admitsNoValue` now reads the property of the family's name, or, when a struct has none but its encoded side declares the name, every property the wire does not name. A struct whose wire lacks the name reads none, so unions keep their behaviour. Also pins the index-signature branch of `drawsOnlyFromEmpty` and the empty-properties guard, moves `vocabularyAnnotations` into `internal/vocabulary.ts` so `dist/index.d.ts` loses three bare side-effect imports, and rephrases the pending changeset in wire terms. Refs #282 Claude-Session: https://claude.ai/code/session_0187g2QpzaHqEzX8GJxiJBVc Co-Authored-By: Claude <noreply@anthropic.com>
3 tasks
This was referenced Oct 9, 2026
thomasfosterau
pushed a commit
that referenced
this pull request
Oct 9, 2026
…305) Review fixes on the #305 wire mapping. `wireProperties` paired a decoded property with its wire name by place whenever every place matched by AST identity. That held for `Schema.encodeKeys`, but not for any other struct transformation: a passthrough between two structs listing `sort` and `include` in another order, every wire property carrying the AST a decoded one encodes to, read the wire `include` as the decoded `sort`. It named the wrong parameter in `source.parameter` and let an empty `include` vocabulary through as a 200. It now runs the struct's one encoding transformation's decode on a probe object (each wire name holding its own sentinel) and pairs each wire name with the decoded key its sentinel lands on. `encodeKeys` is `Struct.renameKeys`, so every rename is read exactly, swaps and array-index names included. A chain of transformations, a source that is no plain struct, a `Middleware`, a decode that fails, throws or goes asynchronous, and a sentinel that lands nowhere or twice pair nothing, and the callers fall back to #306's by-name rule. The positional rule and its length guard are gone with it. The probe reads HttpApi's rebuilt query as well as the endpoint's own, so the endpoint-query threading through `SchemaErrorsLive` is dropped. `queryLeaves` also walks through a check on a renamed struct, as the formatter does, so a `Schema.makeFilter` that reports `{ path: ["count"], issue }` on a struct renaming `count` to `page[size]` names `page[size]`, not `count`. Refs #305. Claude-Session: https://claude.ai/code/session_0187g2QpzaHqEzX8GJxiJBVc Co-Authored-By: Claude <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Follow-up to #300. Refs #282.
This fixes the review findings on merged #300. The owner decided on #282 (and #261) that an empty
include/sortvocabulary means unsupported. Behaviour changes only where item 1 fixes a regression from #300. The example apps' GET responses and OpenAPI documents are byte-identical to trunk's (see "Behaviour check").1. Should-fix, regression: the support check matched the decoded name, not the wire name
admitsNoValue(src/internal/vocabulary.ts) read the decoded property namedinclude/sort.declaredNamesreads the wire name. A query whose wireincludedecodes into a renamed property was misclassified. I reproduced it on trunkbb1a07fwithSchema.Struct({ paths: Schema.optionalKey(Query.Include(Tag)) }).pipe(Schema.encodeKeys({ paths: "include" })):?include=→ 200{"paths":[]}. On4a2ba0f(before fix: read include / sort support off the family's own vocabulary (#294 follow-up) #300), and with this branch: the unsupported 400.?include=author→ the codec's 400 (This endpoint supports no include paths.,source.parameter: "paths",meta.includablePaths: []). Before fix: read include / sort support off the family's own vocabulary (#294 follow-up) #300, and with this branch: the unsupported 400.Fix. The AST does not record an
encodeKeysmapping: the rename lives inside an opaque transformation. SoadmitsNoValuenow walks the query AST without first stripping it withtoType, and on each struct it reads:includecontributes nothing, as on trunk.I chose this over falling back to the pre-#300 whole-schema walk. That walk would bring back the misclassification #300 fixed for a renamed open
includebeside an empty vocabulary under another name (see therenamed-open-includetest: it fails on4a2ba0f's sources).New tests in
src/Middleware.query.test.ts, block "which declaredinclude/sortan endpoint supports (#282)":include, with a value and with an empty value;includebeside a non-empty one under another name;includequery and a query that declares noinclude(fields: true);Query.IncludeListbeside an empty vocabulary under another name;string). This pins theArr.isReadonlyArrayNonEmpty(properties) &&guard (the reviewer's M13).Issue filed: #305 (
bug), for the pre-existing problem that such a 400 names the decodedpathsinsource.parameterrather than the wireinclude. I searched the tracker first and found no duplicate. Not fixed here.2. Nit: the index-signature branch of
drawsOnlyFromEmptyNew case:
include: Schema.optionalKey(Schema.Record(Schema.String, Query.Include(Tag)))answers?include=with the unsupported 400. This pins the reviewer's M12.3. Nit: bare side-effect imports in
dist/index.d.tscodecs.ts'simport type { Vocabulary } from "./vocabulary.js"pulledvocabulary.tsinto the declaration bundle. The bundler kept that module's unused imports asimport "effect/Option",import "effect/SchemaAST"andimport "effect/Schema".import typewas already in use, so the fix movesvocabularyAnnotationsfrominternal/codecs.tsintointernal/vocabulary.ts.codecs.tsandQuery.tsnow only value-import it, and a value import is elided from the declarations.vocabularyAnnotation(singular) becomes private. Its only caller wascodecs.ts.I diffed
dist/index.d.tsfromvp run buildagainst trunk's build (both builds are deterministic; I rebuilt each twice). The only differences are the three removedimport "effect/…"lines and the rewordedSchemaErrorsLivedoc paragraph.media-*.d.tsandschema.d.tsare byte-identical.4. Nit: the pending changeset
.changeset/empty-vocabulary-unsupported.md(patch, still pending) now says, in wire terms, which codec decides it: the one theinclude/sortquery parameter decodes through. That is the property of that name, or the property its encoding renames to that wire name (Schema.encodeKeys({ paths: "include" })). The regression fixed in item 1 never shipped, because #300 is unreleased. So no further changeset is added.5. Note for the next change
I posted a comment on #261 about the
fieldsfollow-up:admitsNoValuehas notypeparameter.fields: { articles: [...], tags: [] }as empty, sofieldsneeds a type-aware variant keyed on thefields[TYPE]wire name.fields/page/filterneeds onlydeclaredNames.Familycould replaceSPEC_FAMILIES/SUPPORT_FAMILIESas the single source of truth for the allow-list's spec-family refusal.Docs
The
SchemaErrorsLivedoc, theemptyVocabulariescomment insrc/Middleware.tsand theadmitsNoValuedoc now say "the property the wire parameter decodes into", not "the decoded property". The README has no sentence on this.Mutation checks
Each row ran
vp test run src/Middleware.query.test.ts src/Query.test.ts src/Middleware.test.ts(380 tests). Every M row applied one mutation alone to this branch'svocabulary.ts, then reverted it.bb1a07f'svocabulary.ts(unfixed) with the new testsinclude(value, empty value) and renamedincludebeside a non-empty one4a2ba0f) with the new tests (-ton the 12 new cases)Query.IncludeListbeside an empty vocabulary, and renamed emptyincludebeside a non-empty one. The two plain renamed-empty cases pass there, which confirms the regressionincludeincludebeside a non-empty onedrawsOnlyFromEmptyincludecodecsArr.isReadonlyArrayNonEmpty(properties) &&removedBehaviour check
1and2, through 20 query strings, with and without a parameterisedAccept. The query strings coverinclude/sortwith names, empty values and bracketed members, plus unknown,fields,pageandfilterparameters. The test also writesOpenApi.fromApi(Api). Results for blog (480 requests), github (960) and northwind (1680) were byte-identical between trunk's sources and this branch's: status, headers (lessdate) and body, and the OpenAPI JSON too.vp lintper changed file, trunk → head:Middleware.query.test.ts1 → 1,Middleware.ts36 → 36,Query.ts144 → 144,internal/codecs.ts32 → 32,internal/vocabulary.ts0 → 0.Verification
Run in this order in a fresh clone, on the final commit's tree:
pnpm install --frozen-lockfile: passvp run build: passvp check: pass (0 errors, warn tier only)vp run check(sources, type-level tests, examples, emitted declarations): passvp run -r test:unit: pass (root 2699, blog 54, github 45, northwind 41)vp run docgen(every JSDoc@examplecompiled and executed): pass./node_modules/.bin/fallow audit --format json --quiet --explain --gate-marker agent: verdictpassfallow audit --base origin/trunk: pass. "No issues in 6 changed files". The 4 inherited findings were excluded by the gate (SortTermunused type export,Sortduplicate export, and the complexity ofQuery.schemaandMiddleware.sourceOf, none of which this branch touches).Changeset
.changeset/empty-vocabulary-unsupported.md(patch) to describe the rule in wire terms. No new changeset: the fixed regression came in with fix: read include / sort support off the family's own vocabulary (#294 follow-up) #300, which is unreleased.Notes
include/sortreached through a renamed wire key.dist/index.d.ts. No exported signature changes.src/internal/schemaExt.ts,src/Resource*,src/Atomic*and the README (feat: answer 400 for undeclared attributes/relationships members on every resource (#292) #304), and the conformance kit (feat(Conformance): walk pagination links and check they enumerate the collection (#166) #303).includesent under another wire name and another property renamed toinclude(encodeKeys({ include: "inc", paths: "include" })). The check reads its decodedinclude, which is the wrong property, because the AST does not record the mapping. Supporting that would mean introspecting the opaque transformation, so I left it.🤖 Generated with Claude Code
Generated by Claude Code