refactor!: explicit pipeline abstractions and typed JS surface - #7
Conversation
pkurcx
left a comment
There was a problem hiding this comment.
Thanks, this is a careful refactor and the structure is a clear improvement. I built both this head and its base commit (1f1944e) and ran every fixture in test/fixtures through both CLIs: generated files, stdout, stderr and exit codes are identical for all 73, except the disclosed duplicate-schema-name wording. That covers the ten newly pinned fixtures too, which the new snapshots alone cannot prove. Also confirmed: fmt/clippy/cargo test clean (305), typecheck/lint/coverage/ava clean (345), and all ten commits compile standalone.
Two things need fixing before merge, and one rebase hazard:
- Runtime enums are declared but not exported.
index.d.tsnow promisesInputFormatandResponseTypeas runtime constants;lib/index.jsandlib/browser.jsexport onlygenerate,GenerateError,EmitTarget.InputFormat.Yaml(shown in the node-api docs) type-checks and throws at runtime. Under the oldconst enumit was inlined and worked. Inline comment below. - Inline-object depth is charged twice per level in
schema/mod.rs, roughly halving the nesting cap. Inline comment below. - Rebase onto main.
mainhas moved (v0.6.0, #8): 20 files conflict. #8 also added aLayoutconst-enum rewrite toscripts/patch-types.mjs, which this PR deletes, so that rewrite has to be ported intopatch-types.tsor it silently disappears. The ten new snapshot dirs need regenerating under the newmodel.ts/rest/<tag>.rest.tsnames.
Smaller behaviour changes worth listing in the description, since they are not covered by the byte-identical claim:
- JSON inputs with a repeated key were last-wins on the base and now fail with
E_INPUT_INVALID(no subcode, so a duplicate schema name in JSON never getsduplicate-schema-name). - A repeated key under
pathschanges code fromE_POLICY_VIOLATIONtoE_INPUT_INVALID, not only its message. default_groupnow returnsDefaultfortags: [""]where the base fell through to the path segment.- Re-export lines (
export type { A as X, ... } from) now wrap at 100 columns.
Non-blocking: a few why-comments dropped in e60917d are worth restoring (the Params-suffix collision rationale in plan/naming/fixed.rs, the verbatim-brace-instead-of-panic note in emit/angular/request.rs, the alias-collision note in emit/model/emit_ts_models.rs). The Emitter trait has one impl per target and no second implementation planned, so a plain function would carry less indirection; fine to keep if you prefer the shape.
…ed must-use coverage
…h iterator chains
…ents onto one line
Summary
The generator was correct but hard to change safely: no traits, diagnostics
threaded as
&mutthrough 22 signatures, schema depth counted by conventionat each call site, four files past 400 lines. Two checks were wrong: a
repeated key under
pathsreported as a duplicate schema name, and thefixture list
regen-snapshotsread had drifted fromtest/fixtures/.Nothing type-checked the published JavaScript or the tests.
How to review
About 60% of the diff is mechanical. Skim: the
src/ir→src/api_modelrename, module splits (
operations.rs,services.rs,request.rs,options.rs,typescript.rs), doc-comment trimming,scripts/*.mjs→*.ts, JSDoc inlib/andbin/, and the 26 added snapshot files.Read, in pipeline order:
src/error.rsReportermoves toRefCell; every stage takes&Reportersrc/parse/unique_map.rs,src/parse/input.rsduplicate-schema-nameroutes on the exactcomponents.schemas:prefixsrc/api_model/normalize/walk.rsSchemaWalkreplaces(context, depth, reporter)triplessrc/subcode.rsindex.d.ts.insrc/plan/artifact_plan/resolve.rssrc/emit/ts/{writer,types}.rsWriter,Render,Positionlib/wrapper-core.js,scripts/patch-types.tsInputFormat/ResponseTypebecome runtime constantsscripts/lib/snapshot-layout.tscheck-fixture-coveragegates CIBehaviour changes
Generated output is unchanged. These are not covered by that claim:
pathsnow fails asE_INPUT_INVALID, notE_POLICY_VIOLATION— caught while decoding, before the policy pass.serde_jsoncarries no field path, so in JSON a duplicate schema name gets no
duplicate-schema-namesubcode; YAML still routes it.duplicate-schema-namenow matchescomponents.schemas:exactly, so anested path like
Pet.propertiesis a plain decode failure.Valueparse failed on aduplicate key.
rest/.rest.tsandrest//index.ts.InputFormatandResponseTypestop beingconst enumand are exportedas runtime constants from both entries.
build:debugnow runspostbuild, so a debug build leaves a clean tree.Verified
--all-targets, fmt, oxlint andthree typecheck projects clean.
newly pinned fixtures plus
bench-multi-tag.templates/byte-identical tomain.native.jsdiffers only in thenapi version-check strings (
0.4.0→0.6.0, matchingpackage.json);browser.d.tsexports the two new runtime constants.parse.
Follow-ups (not in this PR)
rest-util-operations.spec.tscastsbound.requestto a two-argumentsignature while
templates/angular/rest.util.tsdeclares it with none.Predates this PR (feat!: standalone operations layout, drop the
.generatedsuffix #8); to be settled in its own issue.website/README.mdstill namebundle-engine.mjs.