Optimize type-level performance for unstable HttpApi types#2476
Draft
gcanti wants to merge 2 commits into
Draft
Conversation
🦋 Changeset detectedLatest commit: ddb446f The changes in this PR will be included in the next version bump. This PR includes changesets to release 27 packages
Not sure what this means? Click here to learn what changesets are. Click here if you're a maintainer who wants to add another changeset to this PR |
dd52d8f to
de6eeca
Compare
Contributor
Bundle Size Analysis
|
HttpApiBuilder handler chainsHttpApi types
c65afa5 to
a6a833b
Compare
e539529 to
587608b
Compare
587608b to
80d7900
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.
New Features
HttpApiBuilder.Handlers.handleAll, which registers a name-keyed batch of endpoint handlers for a group. Each entry can be either a handler function or{ handler, options }, and the object can be supplied in multiple partial batches.HttpApi.groupsnow preserves the concrete group type for each group name. For example,Api.groups.usersis typed as theusersgroup instead of the full group union.HttpApiGroup.endpointsnow preserves the concrete endpoint type for each endpoint name. For example,Group.endpoints.getUseris typed as thegetUserendpoint instead of the full endpoint union.Type-Level Performance
Type instantiations for the fluent handler-chain stress test improved as
follows:
For complete handler registration, the new
handleAllAPI is measured againstthe equivalent fluent
handlechain on the same endpoint set:handleAllBreaking Changes
These changes affect unstable
HttpApitype-level APIs and structural API,group, and endpoint types.
Renamed Constraint Types
Schema.Constraintterminology:HttpApi.AnytoHttpApi.Constraint,HttpApi.AnyWithPropstoHttpApi.ConstraintWithProps,HttpApiGroup.AnytoHttpApiGroup.Constraint,HttpApiGroup.AnyWithPropstoHttpApiGroup.ConstraintWithProps, andHttpApiEndpoint.AnytoHttpApiEndpoint.Constraint.HttpApiEndpoint.AnyWithPropshas been replaced byHttpApiEndpoint.Top, whoseschema parameters are constrained to
Schema.Top, including success and errorschemas.
HttpApi.isHttpApireturnsHttpApi.Constraint, andHttpApiGroup.isHttpApiGroupreturnsHttpApiGroup.Constraint.API And Group Maps
HttpApi.groupsis now typed as a name-keyed group map instead ofReadonlyRecord<string, Groups>, andHttpApitracks its group unioninvariantly. Dynamic string indexing must refine the key first or cast to a
broad runtime record.
HttpApiGroup.endpointsis now typed as a name-keyed endpoint map instead ofReadonlyRecord<string, Endpoints>, andHttpApiGrouptracks its endpointunion invariantly. Dynamic string indexing must refine the key first or cast to
a broad runtime record.
HttpApiGroup.Namenow reads the group identifier fromHttpApiGroup.Constraint; group-like structural types must satisfy thatlightweight group constraint.
Builder Handler Types
HttpApiBuilder.Handlersnow tracks endpoints through a name-keyed endpoint map and a set of handled names, instead of tracking the remaining endpoint union. Its public type parameters changed fromHandlers<R, Endpoints>toHandlers<R, EndpointsByName, HandledNames>, and its phantom fields changed from_Endpointsto~EndpointsByName/~HandledNames.HttpApiBuilder.Handlers.Anyhelper type has been removed. The internal handler item shape moved fromHttpApiBuilder.Handlers.Itemto the@internalHttpApiBuilder.HandlerItemexport.handle/handleRawregistrations for the same endpoint are no longer rejected at the call site. Missing endpoint handlers are still rejected by the finalHttpApiBuilder.groupreturn validation.Client Types
HttpApiClient.Client.Groupnow derives a client from a concrete group type:Client.Group<Group, E, R>. The previous group-union plus group-name form is no longer supported.HttpApiClient.Client.TopLevelMethodsnow returns a name-keyed method record instead of a union of[name, method]tuples.HttpApiClient.makeWithremoves the defaultHttpClientError.HttpClientErrorfrom custom client error types in the returnedClient, while preserving any additional custom client errors.Endpoint Helper Types
HttpApiEndpoint.HttpApiEndpointnow stores lightweight phantom metadata for middleware and request shapes:~Middleware,~MiddlewareServices,~Request, and~RequestRaw. Its type identifier field is nowreadonly [TypeId]: typeof TypeId.HttpApiEndpoint.Constraintis now a lightweight structural endpoint constraint and does not extendPipeable; values typed only asHttpApiEndpoint.Constraintdo not expose.pipe.HttpApiEndpointinterface. This affects helpers such asName,Success,Error,Params,Query,Payload,Headers,Middleware,MiddlewareServices,Errors,ErrorServicesEncode,ErrorServicesDecode,Request,RequestRaw,ServerServices, andClientServices.HttpApiClient.Client.Methodand related generated-client helpers now require endpoint types that satisfyHttpApiEndpoint.ConstraintRequest. Endpoint-like structural types must include the lightweight request metadata fields to be accepted.