Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Simplified type exports #113

Closed
diego-aquino opened this issue Mar 28, 2024 · 1 comment · Fixed by #114
Closed

Simplified type exports #113

diego-aquino opened this issue Mar 28, 2024 · 1 comment · Fixed by #114
Assignees
Labels
feature New feature or request
Milestone

Comments

@diego-aquino
Copy link
Member

diego-aquino commented Mar 28, 2024

No description provided.

@diego-aquino diego-aquino converted this from a draft issue Mar 28, 2024
@diego-aquino diego-aquino self-assigned this Mar 28, 2024
@diego-aquino diego-aquino added the feature New feature or request label Mar 28, 2024
@diego-aquino diego-aquino moved this from To do to In progress in Zimic Mar 28, 2024
@diego-aquino diego-aquino added this to the v0.3.0 milestone Mar 28, 2024
@diego-aquino diego-aquino changed the title Unified type exports Simplified type exports Mar 28, 2024
@diego-aquino
Copy link
Member Author

diego-aquino commented Mar 28, 2024

Migration guide

As part of Zimic's export improvements, generic HTTP types are now exported directly from zimic, as opposed to zimic/interceptor. This is more appropriate because those types are not specific to Zimic interceptors.

1. Moved HTTP type exports

No behavior changes were added to the moved types. Therefore, migrating to the new exports amounts to renaming the types and importing them from zimic directly.

Previously exported from zimic/interceptor: Equivalent now exported from zimic:
HttpInterceptorMethod HttpMethod
HttpInterceptorMethodSchema HttpServiceMethodSchema
HttpInterceptorPathSchema HttpServiceMethodsSchema
HttpInterceptorRequestSchema HttpServiceRequestSchema
HttpInterceptorResponseSchema HttpServiceResponseSchema
HttpInterceptorResponseSchemaByStatusCode HttpServiceResponseSchemaByStatusCode
HttpInterceptorResponseSchemaStatusCode HttpServiceResponseSchemaStatusCode
HttpInterceptorSchemaMethod HttpServiceSchemaMethod
HttpInterceptorSchemaPath HttpServiceSchemaPath
LiteralHttpInterceptorSchemaPath LiteralHttpServiceSchemaPath
NonLiteralHttpInterceptorSchemaPath NonLiteralHttpServiceSchemaPath
HttpInterceptorSearchParamsSchema HttpSearchParamsSchema
HttpInterceptorBodySchema HttpBody
HttpInterceptorSchema HttpServiceSchema
HttpInterceptorSchema.Root HttpSchema.Paths
HttpInterceptorSchema.Path HttpSchema.Methods
HttpInterceptorSchema.Method HttpSchema.Method
HttpInterceptorSchema.Request HttpSchema.Request
HttpInterceptorSchema.ResponseByStatusCode HttpSchema.ResponseByStatusCode
HttpInterceptorSchema.Response HttpSchema.Response
HttpInterceptorSchema.Headers HttpSchema.Headers
HttpInterceptorSchema.SearchParams HttpSchema.SearchParams
HttpInterceptorSchema.Body JSONValue

HttpSchema is a namespace, so it is imported as import { HttpSchema } from 'zimic';

2. JSONCompatible unified to JSONValue

On https://github.com/diego-aquino/zimic/issues/106, we introduced a strict JSON validation, adding the type JSONCompatible. That type was now unified with JSONValue, which both represents a JSON value and is capable of validating JSON types. We now recommend using JSONValue to declare the JSON entities used as bodies in interceptor schemas.

Generic example of JSONValue:
import { JSONValue } from 'zimic';

// `JSONValue` can be used to type expected JSON values...
function doSomething(value: JSONValue) {
  // ...
}

// ... also declare types compatible with JSON
type User = JSONValue<{
  id: string;
  name: string;
}>

type InvalidUser = JSONValue<{
  id: string;
  name: string;
  createdAt: Date // shows an error, since `Date` is not a JSON value
}>
Example of JSONValue with interceptors:
import type { JSONValue } from 'zimic';

type Organization = JSONValue<{
  id: string;
  name: string;
}>;

type User = JSONValue<{
  id: string;
  name: string;
  organization: Organization
}>;

const interceptor = createHttpInterceptor<{
  GET: {
    response: {
      200: { body: User[] };
    };
  };
}>({
  worker,
  baseURL: 'http://localhost:3000',
});

@diego-aquino diego-aquino moved this from In progress to In review in Zimic Mar 29, 2024
diego-aquino added a commit that referenced this issue Mar 29, 2024
### Refactoring
- [#zimic] Simplified and improved the type exports. Check out the
[Migration
guide](https://github.com/diego-aquino/zimic/issues/113#issuecomment-2026220610)
for more information.

### Fixes
- [#zimic] Extended `JSONSerialized` to correctly exclude functions with
arguments from the result type. Previously, only functions that had no
arguments were excluded.

Closes #113.
@github-project-automation github-project-automation bot moved this from In review to Done in Zimic Mar 29, 2024
@github-project-automation github-project-automation bot moved this to To do in Zimic May 25, 2024
@diego-aquino diego-aquino moved this from To do to Done in Zimic May 25, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
feature New feature or request
Projects
Status: Done
Development

Successfully merging a pull request may close this issue.

1 participant