Version Packages#1952
Open
pmcelhaney wants to merge 1 commit intomainfrom
Open
Conversation
baeb65d to
0e71157
Compare
0e71157 to
8ee8fa3
Compare
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.
This PR was opened by the Changesets release GitHub action. When you're ready to do a release, you can merge this and the packages will be published to npm automatically. If you're not ready to do a release yet, that's fine, whenever you add more changesets to main, this PR will be updated.
Releases
counterfact@2.11.0
Minor Changes
a58241f: generator: emit
types/versions.tswithVersions,VersionsGTE, andVersionedtypesWhen at least one
SpecConfigentry has a non-emptyversionfield, the code generator now writestypes/versions.tsto thebasePathroot. The file exports:Versions— a union of all distinct version strings in config-declaration orderVersionsGTE— a map from each version to the set of versions that are >= itVersioned<T, V>— a utility type that narrows the$argument of a route handler to a specific API versionVersionedis also exported fromcounterfact-types/index.tsin its generic form (with explicitTVersionsandTVersionsGTEtype parameters) for use outside of the generated file.No file is written when no spec defines a
version.4bb9493: Add runtime implementation of
$.minVersion()for versioned route handlers.When multiple versioned specs share the same API group, each request's
$argument now includes:
version— a string identifying which version is handling the request(e.g.
"v1","v2").minVersion(min)— a method that returnstruewhen the current versionis greater than or equal to
minin the declared version order, andfalseotherwise.The version order is determined by the position of each spec in the
specsarray passed to
counterfact()(first entry = oldest version).For unversioned runners (
versionis not set), neitherversionnorminVersionis present on$.af44d5b:
OperationTypeCodernow emits version-mapped handler types for multi-version APIs.When two or more versioned specs share the same operation path, the shared
types/paths/<path>.types.tsfile exports a mergedHTTP_<METHOD>typewhose
$argument isVersioned<{ v1: …; v2: … }>(a union of eachversion's strongly-typed argument object). Each version's
$-argument typeis emitted to
types/<version>/paths/<path>.types.tsand imported by theshared file.
Single-spec (unversioned) output is unchanged for full backwards compatibility.
A new
Versioned<T>utility type is exported fromcounterfact-types/index.js.142bcdd: When a
SpecConfigentry declares bothgroupandversion, the server now automatically mounts that spec's routes under/<group>/<version>without requiring an explicitprefix.The derivation rules are:
prefixprovided?groupset?versionset?/<group>/<version>/<group>""(root)Two specs with the same
groupbut differentversionvalues can coexist on a single server instance — validation now checks uniqueness on the(group, version)pair instead ofgroupalone.Migration note:
SpecConfig.prefixis now an optional field (prefix?: string). Specs that omitprefixwill have it derived automatically; pass an explicitprefix: ""to force the root prefix.Patch Changes
825b65d: Cast parameters at runtime: parameters defined with OAS3-style schema types (e.g.
schema: { type: "integer" }) are now correctly cast to their declared JavaScript types in route handlers. For example, whenGET /pet/1is called,$.path.petIdwill be a number rather than a string when the OpenAPI spec declares it asinteger.161deca: Fix documentation inconsistencies: complete CLI reference table, correct programmatic API example in FAQ, fix invalid JS syntax and broken link in without-openapi guide, and fix formatting in programmatic-api guide.
6d19132: Fix TypeScript error caused by combining a mapped type and explicit properties in the same generated response object type.
When an OpenAPI spec defines a
defaultresponse alongside explicit status codes (e.g.200,400), the generatedResponseBuilderFactorytype argument now uses an intersection ({ 200: ..., 400: ... } & { [statusCode in Exclude<HttpStatusCode, 200 | 400>]: ... }) instead of mixing both in a single object literal, which TypeScript does not allow.bce607e: Update usage link in REPL and CLI banner to point to the new GitHub docs URL.
dd4abb8: Generated
$-arg types now include aversionproperty. For versioned specs the property is a string literal (e.g.version: "v3"); for unversioned specs it isnever(omitted at runtime byOmitValueWhenNever).