From 14fc23544cb299ad3a4e328505f6c711a06233c5 Mon Sep 17 00:00:00 2001 From: Diego Aquino Date: Tue, 18 Feb 2025 21:11:26 -0300 Subject: [PATCH] refactor(#zimic): `@zimic/http` package (#570) ### Refactoring - Created the package `@zimic/http` to contain resources related to HTTP. It is a peer dependency of `zimic` and should be installed alongside it. With this change, the following exports were affected: - `zimic` -> `@zimic/http` - `zimic/http` -> `@zimic/http` - `zimic/typegen` -> `@zimic/http/typegen` The errors `InvalidJSONError` and `InvalidFormDataError`, previously exported by `zimic` and `zimic/http`, are not exported by `zimic/interceptor/http`; The Zimic typegen CLI was also migrated to `@zimic/http` and can now be called with `zimic-http typegen openapi ...`. This PR starts migrating the documentation to consider `@zimic/http`. Further PRs will finish the migration. Part of https://github.com/zimicjs/zimic/issues/565. --- README.md | 2 +- apps/zimic-test-client/package.json | 3 +- .../tests/exports/exports.node.test.ts | 2 +- .../tests/exports/exports.test.ts | 36 ++--- .../interceptor/thirdParty/shared/default.ts | 3 +- .../interceptor/thirdParty/shared/schema.ts | 3 +- .../tests/typegen/typegen.node.test.ts | 2 +- "docs/wiki/api\342\200\220zimic.md" | 6 +- .../api\342\200\220zimic\342\200\220http.md" | 34 ++--- ...342\200\220interceptor\342\200\220http.md" | 24 +-- ...tor\342\200\220http\342\200\220schemas.md" | 24 +-- "docs/wiki/getting\342\200\220started.md" | 4 +- docs/wiki/home.md | 2 +- examples/package.json | 2 +- examples/with-jest-jsdom/package.json | 1 + .../with-jest-jsdom/src/clients/github.ts | 2 +- examples/with-jest-node/package.json | 1 + examples/with-jest-node/src/clients/github.ts | 2 +- examples/with-next-js-app/package.json | 1 + .../with-next-js-app/src/clients/github.ts | 2 +- examples/with-next-js-pages/package.json | 1 + .../with-next-js-pages/src/clients/github.ts | 2 +- examples/with-openapi-typegen/package.json | 3 +- .../src/clients/github/typegen/generated.ts | 2 +- examples/with-playwright/package.json | 1 + .../with-playwright/src/clients/github.ts | 2 +- examples/with-vitest-browser/package.json | 1 + .../with-vitest-browser/src/clients/github.ts | 2 +- examples/with-vitest-jsdom/package.json | 1 + .../with-vitest-jsdom/src/clients/github.ts | 2 +- examples/with-vitest-node/package.json | 1 + .../with-vitest-node/src/clients/github.ts | 2 +- packages/zimic-http/.lintstagedrc.js | 1 + packages/zimic-http/.prettierignore | 19 +++ packages/zimic-http/eslint.config.mjs | 14 ++ packages/zimic-http/index.d.ts | 1 + packages/zimic-http/package.json | 111 ++++++++++++++ .../scripts}/typegen/generateFixtureTypes.ts | 22 ++- .../src/cli/__tests__/cli.node.test.ts | 70 +++++++++ .../src/cli/__tests__/index.node.test.ts | 16 ++ packages/zimic-http/src/cli/cli.ts | 92 ++++++++++++ packages/zimic-http/src/cli/index.ts | 4 + .../fixtures/openapi/binary.comments.ts | 2 +- .../__tests__/fixtures/openapi/binary.ts | 2 +- .../__tests__/fixtures/openapi/binary.yaml | 0 .../fixtures/openapi/combinations.comments.ts | 2 +- .../fixtures/openapi/combinations.ts | 2 +- .../fixtures/openapi/combinations.yaml | 0 .../fixtures/openapi/empty.comments.ts | 2 +- .../__tests__/fixtures/openapi/empty.ts | 2 +- .../__tests__/fixtures/openapi/empty.yaml | 0 .../fixtures/openapi/examples.comments.ts | 2 +- .../__tests__/fixtures/openapi/examples.ts | 2 +- .../__tests__/fixtures/openapi/examples.yaml | 0 .../fixtures/openapi/filters.comments.ts | 2 +- .../openapi/filters.empty.notPruned.ts | 2 +- .../fixtures/openapi/filters.empty.ts | 2 +- .../openapi/filters.multiple.notPruned.ts | 2 +- .../fixtures/openapi/filters.multiple.ts | 2 +- .../filters.multipleFromFile.notPruned.ts | 2 +- .../openapi/filters.multipleFromFile.ts | 2 +- .../openapi/filters.multipleMethods.ts | 2 +- .../fixtures/openapi/filters.negative.1.ts | 2 +- .../fixtures/openapi/filters.negative.2.ts | 2 +- .../fixtures/openapi/filters.negative.3.ts | 2 +- .../openapi/filters.oneMethod.notPruned.ts | 2 +- .../fixtures/openapi/filters.oneMethod.ts | 2 +- .../openapi/filters.pathWildcard.1.ts | 2 +- .../openapi/filters.pathWildcard.2.ts | 2 +- .../openapi/filters.pathWildcard.3.ts | 2 +- .../openapi/filters.pathWildcard.4.ts | 2 +- .../openapi/filters.pathWildcard.5.ts | 2 +- .../__tests__/fixtures/openapi/filters.ts | 2 +- .../__tests__/fixtures/openapi/filters.txt | 0 .../filters.wildcardMethod.notPruned.ts | 2 +- .../openapi/filters.wildcardMethod.ts | 2 +- .../__tests__/fixtures/openapi/filters.yaml | 0 .../fixtures/openapi/formData.comments.ts | 2 +- .../__tests__/fixtures/openapi/formData.ts | 2 +- .../__tests__/fixtures/openapi/formData.yaml | 0 .../fixtures/openapi/headers.comments.ts | 2 +- .../__tests__/fixtures/openapi/headers.ts | 2 +- .../__tests__/fixtures/openapi/headers.yaml | 0 .../fixtures/openapi/pathItems.comments.ts | 2 +- .../__tests__/fixtures/openapi/pathItems.ts | 2 +- .../__tests__/fixtures/openapi/pathItems.yaml | 0 .../fixtures/openapi/pathParams.comments.ts | 2 +- .../__tests__/fixtures/openapi/pathParams.ts | 2 +- .../fixtures/openapi/pathParams.yaml | 0 .../openapi/requestBodies.comments.ts | 2 +- .../fixtures/openapi/requestBodies.ts | 2 +- .../fixtures/openapi/requestBodies.yaml | 0 .../fixtures/openapi/responses.comments.ts | 2 +- .../__tests__/fixtures/openapi/responses.ts | 2 +- .../__tests__/fixtures/openapi/responses.yaml | 0 .../fixtures/openapi/searchParams.comments.ts | 2 +- .../fixtures/openapi/searchParams.ts | 2 +- .../fixtures/openapi/searchParams.yaml | 0 .../fixtures/openapi/security.comments.ts | 2 +- .../__tests__/fixtures/openapi/security.ts | 2 +- .../__tests__/fixtures/openapi/security.yaml | 0 .../fixtures/openapi/simple.comments.ts | 2 +- .../__tests__/fixtures/openapi/simple.ts | 2 +- .../__tests__/fixtures/openapi/simple.yaml | 0 .../fixtures/openapi/webhooks.comments.ts | 2 +- .../__tests__/fixtures/openapi/webhooks.ts | 2 +- .../__tests__/fixtures/openapi/webhooks.yaml | 0 .../__tests__/fixtures/openapiTypegenCases.ts | 0 .../__tests__/fixtures/typegenFixtures.ts | 0 .../cli/typegen/__tests__/fixtures/types.ts | 0 .../typegen/__tests__/openapi.node.test.ts | 4 +- .../typegen/__tests__/typegen.node.test.ts | 4 +- .../src/cli/typegen/openapi.ts | 0 .../src}/formData/HttpFormData.ts | 2 +- .../formData/__tests__/HttpFormData.test.ts | 61 -------- .../http => zimic-http/src}/formData/types.ts | 4 +- .../src}/headers/HttpHeaders.ts | 2 +- .../headers/__tests__/HttpHeaders.test.ts | 30 +--- .../http => zimic-http/src}/headers/types.ts | 4 +- .../src/http => zimic-http/src}/index.ts | 8 +- .../__tests__/HttpPathParams.test.ts | 0 .../src}/pathParams/types.ts | 2 +- .../src}/searchParams/HttpSearchParams.ts | 2 +- .../__tests__/HttpSearchParams.test.ts | 37 +---- .../src}/searchParams/types.ts | 4 +- .../src/typegen/index.ts | 0 .../src/typegen/namespace/TypegenNamespace.ts | 0 .../src/typegen/openapi/generate.ts | 0 .../typegen/openapi/transform/components.ts | 0 .../src/typegen/openapi/transform/context.ts | 0 .../src/typegen/openapi/transform/filters.ts | 2 +- .../src/typegen/openapi/transform/imports.ts | 2 +- .../src/typegen/openapi/transform/io.ts | 0 .../src/typegen/openapi/transform/methods.ts | 2 +- .../typegen/openapi/transform/operations.ts | 0 .../src/typegen/openapi/transform/paths.ts | 0 .../src/typegen/openapi/utils/types.ts | 0 .../src/types/__tests__/json.test.ts | 132 +++++++++++++++++ .../src}/types/__tests__/schema.test.ts | 0 packages/zimic-http/src/types/arrays.d.ts | 4 + packages/zimic-http/src/types/json.ts | 89 +++++++++++ packages/zimic-http/src/types/objects.d.ts | 14 ++ .../http => zimic-http/src}/types/requests.ts | 2 +- .../http => zimic-http/src}/types/schema.ts | 34 ++--- packages/zimic-http/src/types/strings.d.ts | 9 ++ packages/zimic-http/src/types/utils.ts | 64 ++++++++ .../src/utils/__tests__/strings.test.ts | 0 .../src/utils/__tests__/time.test.ts | 0 packages/zimic-http/src/utils/console.ts | 7 + packages/zimic-http/src/utils/data.ts | 13 ++ packages/zimic-http/src/utils/files.ts | 28 ++++ packages/zimic-http/src/utils/imports.ts | 12 ++ .../src/utils/prettier.ts | 0 .../src/utils/strings.ts | 0 packages/zimic-http/src/utils/time.ts | 25 ++++ packages/zimic-http/src/utils/urls.ts | 52 +++++++ packages/zimic-http/tests/utils/console.ts | 30 ++++ .../{zimic => zimic-http}/tests/utils/json.ts | 0 packages/zimic-http/tsconfig.json | 18 +++ packages/zimic-http/tsup.config.ts | 58 ++++++++ packages/zimic-http/turbo.json | 31 ++++ packages/{zimic => zimic-http}/typegen.d.ts | 0 packages/zimic-http/vitest.config.mts | 55 +++++++ packages/zimic-http/vitest.workspace.mts | 30 ++++ packages/zimic/http.d.ts | 1 - packages/zimic/package.json | 26 +--- packages/zimic/scripts/dev/utils/console.ts | 14 -- .../zimic/src/cli/__tests__/cli.node.test.ts | 1 - packages/zimic/src/cli/cli.ts | 75 ---------- .../cli/server/__tests__/server.node.test.ts | 6 +- packages/zimic/src/fetch/FetchClient.ts | 10 +- .../__tests__/FetchClient.bodies.blob.test.ts | 2 +- .../FetchClient.bodies.formData.test.ts | 2 +- .../__tests__/FetchClient.bodies.json.test.ts | 2 +- .../FetchClient.bodies.plainText.test.ts | 2 +- .../FetchClient.bodies.searchParams.test.ts | 2 +- .../__tests__/FetchClient.bodies.test.ts | 2 +- .../__tests__/FetchClient.defaults.test.ts | 2 +- .../__tests__/FetchClient.errors.test.ts | 2 +- .../__tests__/FetchClient.headers.test.ts | 2 +- .../__tests__/FetchClient.listeners.test.ts | 2 +- .../__tests__/FetchClient.methods.test.ts | 2 +- .../__tests__/FetchClient.pathParams.test.ts | 2 +- .../FetchClient.searchParams.test.ts | 2 +- .../fetch/__tests__/FetchClient.types.test.ts | 2 +- .../src/fetch/errors/FetchResponseError.ts | 2 +- packages/zimic/src/fetch/factory.ts | 9 +- packages/zimic/src/fetch/types/public.ts | 4 +- packages/zimic/src/fetch/types/requests.ts | 6 +- packages/zimic/src/index.ts | 3 +- packages/zimic/src/interceptor/http/index.ts | 2 + .../http/interceptor/HttpInterceptorClient.ts | 7 +- .../http/interceptor/LocalHttpInterceptor.ts | 3 +- .../http/interceptor/RemoteHttpInterceptor.ts | 3 +- .../__tests__/shared/bodies/blob.ts | 3 +- .../__tests__/shared/bodies/formData.ts | 13 +- .../__tests__/shared/bodies/json.ts | 5 +- .../__tests__/shared/bodies/plainText.ts | 3 +- .../__tests__/shared/bodies/searchParams.ts | 11 +- .../interceptor/__tests__/shared/clear.ts | 2 +- .../interceptor/__tests__/shared/handlers.ts | 4 +- .../interceptor/__tests__/shared/lifeCycle.ts | 2 +- .../__tests__/shared/pathParams.ts | 2 +- .../__tests__/shared/restrictions.ts | 14 +- .../interceptor/__tests__/shared/times.ts | 2 +- .../interceptor/__tests__/shared/types.ts | 13 +- .../shared/unhandledRequests.factories.ts | 3 +- .../shared/unhandledRequests.logging.ts | 3 +- .../interceptor/__tests__/shared/utils.ts | 3 +- .../interceptor/http/interceptor/factory.ts | 18 +-- .../http/interceptor/types/handlers.ts | 2 +- .../http/interceptor/types/public.ts | 2 +- .../http/interceptor/types/requests.ts | 4 +- .../HttpInterceptorWorker.ts | 23 ++- .../LocalHttpInterceptorWorker.ts | 3 +- .../RemoteHttpInterceptorWorker.ts | 3 +- .../__tests__/shared/methods.ts | 4 +- .../errors/InvalidFormDataError.ts | 0 .../errors/InvalidJSONError.ts | 0 .../http/interceptorWorker/types/requests.ts | 2 +- .../HttpRequestHandlerClient.ts | 14 +- .../requestHandler/LocalHttpRequestHandler.ts | 3 +- .../RemoteHttpRequestHandler.ts | 3 +- .../__tests__/shared/default.ts | 2 +- .../__tests__/shared/restrictions.ts | 3 +- .../requestHandler/__tests__/shared/times.ts | 2 +- .../requestHandler/__tests__/shared/types.ts | 4 +- .../http/requestHandler/types/public.ts | 3 +- .../http/requestHandler/types/requests.ts | 17 ++- .../http/requestHandler/types/restrictions.ts | 5 +- .../interceptor/server/InterceptorServer.ts | 3 +- .../zimic/src/interceptor/server/constants.ts | 3 +- .../src/interceptor/server/types/schema.ts | 3 +- packages/zimic/src/types/json.ts | 6 +- packages/zimic/src/utils/console.ts | 3 +- packages/zimic/src/utils/files.ts | 5 - packages/zimic/src/utils/http.ts | 5 +- packages/zimic/src/utils/time.ts | 26 ---- packages/zimic/src/utils/urls.ts | 15 -- packages/zimic/tests/setup/global/shared.ts | 2 +- packages/zimic/tests/utils/interceptors.ts | 26 ++-- packages/zimic/tsup.config.ts | 7 +- packages/zimic/vitest.config.mts | 2 - pnpm-lock.yaml | 140 ++++++++++++++++-- 244 files changed, 1515 insertions(+), 632 deletions(-) create mode 100644 packages/zimic-http/.lintstagedrc.js create mode 100644 packages/zimic-http/.prettierignore create mode 100644 packages/zimic-http/eslint.config.mjs create mode 100644 packages/zimic-http/index.d.ts create mode 100644 packages/zimic-http/package.json rename packages/{zimic/scripts/dev => zimic-http/scripts}/typegen/generateFixtureTypes.ts (89%) create mode 100644 packages/zimic-http/src/cli/__tests__/cli.node.test.ts create mode 100644 packages/zimic-http/src/cli/__tests__/index.node.test.ts create mode 100644 packages/zimic-http/src/cli/cli.ts create mode 100644 packages/zimic-http/src/cli/index.ts rename packages/{zimic => zimic-http}/src/cli/typegen/__tests__/fixtures/openapi/binary.comments.ts (88%) rename packages/{zimic => zimic-http}/src/cli/typegen/__tests__/fixtures/openapi/binary.ts (88%) rename packages/{zimic => zimic-http}/src/cli/typegen/__tests__/fixtures/openapi/binary.yaml (100%) rename packages/{zimic => zimic-http}/src/cli/typegen/__tests__/fixtures/openapi/combinations.comments.ts (98%) rename packages/{zimic => zimic-http}/src/cli/typegen/__tests__/fixtures/openapi/combinations.ts (97%) rename packages/{zimic => zimic-http}/src/cli/typegen/__tests__/fixtures/openapi/combinations.yaml (100%) rename packages/{zimic => zimic-http}/src/cli/typegen/__tests__/fixtures/openapi/empty.comments.ts (77%) rename packages/{zimic => zimic-http}/src/cli/typegen/__tests__/fixtures/openapi/empty.ts (77%) rename packages/{zimic => zimic-http}/src/cli/typegen/__tests__/fixtures/openapi/empty.yaml (100%) rename packages/{zimic => zimic-http}/src/cli/typegen/__tests__/fixtures/openapi/examples.comments.ts (97%) rename packages/{zimic => zimic-http}/src/cli/typegen/__tests__/fixtures/openapi/examples.ts (93%) rename packages/{zimic => zimic-http}/src/cli/typegen/__tests__/fixtures/openapi/examples.yaml (100%) rename packages/{zimic => zimic-http}/src/cli/typegen/__tests__/fixtures/openapi/filters.comments.ts (99%) rename packages/{zimic => zimic-http}/src/cli/typegen/__tests__/fixtures/openapi/filters.empty.notPruned.ts (98%) rename packages/{zimic => zimic-http}/src/cli/typegen/__tests__/fixtures/openapi/filters.empty.ts (77%) rename packages/{zimic => zimic-http}/src/cli/typegen/__tests__/fixtures/openapi/filters.multiple.notPruned.ts (99%) rename packages/{zimic => zimic-http}/src/cli/typegen/__tests__/fixtures/openapi/filters.multiple.ts (99%) rename packages/{zimic => zimic-http}/src/cli/typegen/__tests__/fixtures/openapi/filters.multipleFromFile.notPruned.ts (99%) rename packages/{zimic => zimic-http}/src/cli/typegen/__tests__/fixtures/openapi/filters.multipleFromFile.ts (99%) rename packages/{zimic => zimic-http}/src/cli/typegen/__tests__/fixtures/openapi/filters.multipleMethods.ts (92%) rename packages/{zimic => zimic-http}/src/cli/typegen/__tests__/fixtures/openapi/filters.negative.1.ts (99%) rename packages/{zimic => zimic-http}/src/cli/typegen/__tests__/fixtures/openapi/filters.negative.2.ts (99%) rename packages/{zimic => zimic-http}/src/cli/typegen/__tests__/fixtures/openapi/filters.negative.3.ts (99%) rename packages/{zimic => zimic-http}/src/cli/typegen/__tests__/fixtures/openapi/filters.oneMethod.notPruned.ts (99%) rename packages/{zimic => zimic-http}/src/cli/typegen/__tests__/fixtures/openapi/filters.oneMethod.ts (89%) rename packages/{zimic => zimic-http}/src/cli/typegen/__tests__/fixtures/openapi/filters.pathWildcard.1.ts (94%) rename packages/{zimic => zimic-http}/src/cli/typegen/__tests__/fixtures/openapi/filters.pathWildcard.2.ts (95%) rename packages/{zimic => zimic-http}/src/cli/typegen/__tests__/fixtures/openapi/filters.pathWildcard.3.ts (92%) rename packages/{zimic => zimic-http}/src/cli/typegen/__tests__/fixtures/openapi/filters.pathWildcard.4.ts (93%) rename packages/{zimic => zimic-http}/src/cli/typegen/__tests__/fixtures/openapi/filters.pathWildcard.5.ts (93%) rename packages/{zimic => zimic-http}/src/cli/typegen/__tests__/fixtures/openapi/filters.ts (99%) rename packages/{zimic => zimic-http}/src/cli/typegen/__tests__/fixtures/openapi/filters.txt (100%) rename packages/{zimic => zimic-http}/src/cli/typegen/__tests__/fixtures/openapi/filters.wildcardMethod.notPruned.ts (99%) rename packages/{zimic => zimic-http}/src/cli/typegen/__tests__/fixtures/openapi/filters.wildcardMethod.ts (94%) rename packages/{zimic => zimic-http}/src/cli/typegen/__tests__/fixtures/openapi/filters.yaml (100%) rename packages/{zimic => zimic-http}/src/cli/typegen/__tests__/fixtures/openapi/formData.comments.ts (99%) rename packages/{zimic => zimic-http}/src/cli/typegen/__tests__/fixtures/openapi/formData.ts (98%) rename packages/{zimic => zimic-http}/src/cli/typegen/__tests__/fixtures/openapi/formData.yaml (100%) rename packages/{zimic => zimic-http}/src/cli/typegen/__tests__/fixtures/openapi/headers.comments.ts (98%) rename packages/{zimic => zimic-http}/src/cli/typegen/__tests__/fixtures/openapi/headers.ts (98%) rename packages/{zimic => zimic-http}/src/cli/typegen/__tests__/fixtures/openapi/headers.yaml (100%) rename packages/{zimic => zimic-http}/src/cli/typegen/__tests__/fixtures/openapi/pathItems.comments.ts (93%) rename packages/{zimic => zimic-http}/src/cli/typegen/__tests__/fixtures/openapi/pathItems.ts (93%) rename packages/{zimic => zimic-http}/src/cli/typegen/__tests__/fixtures/openapi/pathItems.yaml (100%) rename packages/{zimic => zimic-http}/src/cli/typegen/__tests__/fixtures/openapi/pathParams.comments.ts (96%) rename packages/{zimic => zimic-http}/src/cli/typegen/__tests__/fixtures/openapi/pathParams.ts (94%) rename packages/{zimic => zimic-http}/src/cli/typegen/__tests__/fixtures/openapi/pathParams.yaml (100%) rename packages/{zimic => zimic-http}/src/cli/typegen/__tests__/fixtures/openapi/requestBodies.comments.ts (99%) rename packages/{zimic => zimic-http}/src/cli/typegen/__tests__/fixtures/openapi/requestBodies.ts (99%) rename packages/{zimic => zimic-http}/src/cli/typegen/__tests__/fixtures/openapi/requestBodies.yaml (100%) rename packages/{zimic => zimic-http}/src/cli/typegen/__tests__/fixtures/openapi/responses.comments.ts (99%) rename packages/{zimic => zimic-http}/src/cli/typegen/__tests__/fixtures/openapi/responses.ts (98%) rename packages/{zimic => zimic-http}/src/cli/typegen/__tests__/fixtures/openapi/responses.yaml (100%) rename packages/{zimic => zimic-http}/src/cli/typegen/__tests__/fixtures/openapi/searchParams.comments.ts (99%) rename packages/{zimic => zimic-http}/src/cli/typegen/__tests__/fixtures/openapi/searchParams.ts (99%) rename packages/{zimic => zimic-http}/src/cli/typegen/__tests__/fixtures/openapi/searchParams.yaml (100%) rename packages/{zimic => zimic-http}/src/cli/typegen/__tests__/fixtures/openapi/security.comments.ts (93%) rename packages/{zimic => zimic-http}/src/cli/typegen/__tests__/fixtures/openapi/security.ts (92%) rename packages/{zimic => zimic-http}/src/cli/typegen/__tests__/fixtures/openapi/security.yaml (100%) rename packages/{zimic => zimic-http}/src/cli/typegen/__tests__/fixtures/openapi/simple.comments.ts (98%) rename packages/{zimic => zimic-http}/src/cli/typegen/__tests__/fixtures/openapi/simple.ts (98%) rename packages/{zimic => zimic-http}/src/cli/typegen/__tests__/fixtures/openapi/simple.yaml (100%) rename packages/{zimic => zimic-http}/src/cli/typegen/__tests__/fixtures/openapi/webhooks.comments.ts (77%) rename packages/{zimic => zimic-http}/src/cli/typegen/__tests__/fixtures/openapi/webhooks.ts (77%) rename packages/{zimic => zimic-http}/src/cli/typegen/__tests__/fixtures/openapi/webhooks.yaml (100%) rename packages/{zimic => zimic-http}/src/cli/typegen/__tests__/fixtures/openapiTypegenCases.ts (100%) rename packages/{zimic => zimic-http}/src/cli/typegen/__tests__/fixtures/typegenFixtures.ts (100%) rename packages/{zimic => zimic-http}/src/cli/typegen/__tests__/fixtures/types.ts (100%) rename packages/{zimic => zimic-http}/src/cli/typegen/__tests__/openapi.node.test.ts (99%) rename packages/{zimic => zimic-http}/src/cli/typegen/__tests__/typegen.node.test.ts (90%) rename packages/{zimic => zimic-http}/src/cli/typegen/openapi.ts (100%) rename packages/{zimic/src/http => zimic-http/src}/formData/HttpFormData.ts (99%) rename packages/{zimic/src/http => zimic-http/src}/formData/__tests__/HttpFormData.test.ts (91%) rename packages/{zimic/src/http => zimic-http/src}/formData/types.ts (96%) rename packages/{zimic/src/http => zimic-http/src}/headers/HttpHeaders.ts (99%) rename packages/{zimic/src/http => zimic-http/src}/headers/__tests__/HttpHeaders.test.ts (95%) rename packages/{zimic/src/http => zimic-http/src}/headers/types.ts (94%) rename packages/{zimic/src/http => zimic-http/src}/index.ts (80%) rename packages/{zimic/src/http => zimic-http/src}/pathParams/__tests__/HttpPathParams.test.ts (100%) rename packages/{zimic/src/http => zimic-http/src}/pathParams/types.ts (96%) rename packages/{zimic/src/http => zimic-http/src}/searchParams/HttpSearchParams.ts (99%) rename packages/{zimic/src/http => zimic-http/src}/searchParams/__tests__/HttpSearchParams.test.ts (94%) rename packages/{zimic/src/http => zimic-http/src}/searchParams/types.ts (97%) rename packages/{zimic => zimic-http}/src/typegen/index.ts (100%) rename packages/{zimic => zimic-http}/src/typegen/namespace/TypegenNamespace.ts (100%) rename packages/{zimic => zimic-http}/src/typegen/openapi/generate.ts (100%) rename packages/{zimic => zimic-http}/src/typegen/openapi/transform/components.ts (100%) rename packages/{zimic => zimic-http}/src/typegen/openapi/transform/context.ts (100%) rename packages/{zimic => zimic-http}/src/typegen/openapi/transform/filters.ts (97%) rename packages/{zimic => zimic-http}/src/typegen/openapi/transform/imports.ts (95%) rename packages/{zimic => zimic-http}/src/typegen/openapi/transform/io.ts (100%) rename packages/{zimic => zimic-http}/src/typegen/openapi/transform/methods.ts (99%) rename packages/{zimic => zimic-http}/src/typegen/openapi/transform/operations.ts (100%) rename packages/{zimic => zimic-http}/src/typegen/openapi/transform/paths.ts (100%) rename packages/{zimic => zimic-http}/src/typegen/openapi/utils/types.ts (100%) create mode 100644 packages/zimic-http/src/types/__tests__/json.test.ts rename packages/{zimic/src/http => zimic-http/src}/types/__tests__/schema.test.ts (100%) create mode 100644 packages/zimic-http/src/types/arrays.d.ts create mode 100644 packages/zimic-http/src/types/json.ts create mode 100644 packages/zimic-http/src/types/objects.d.ts rename packages/{zimic/src/http => zimic-http/src}/types/requests.ts (98%) rename packages/{zimic/src/http => zimic-http/src}/types/schema.ts (96%) create mode 100644 packages/zimic-http/src/types/strings.d.ts create mode 100644 packages/zimic-http/src/types/utils.ts rename packages/{zimic => zimic-http}/src/utils/__tests__/strings.test.ts (100%) rename packages/{zimic => zimic-http}/src/utils/__tests__/time.test.ts (100%) create mode 100644 packages/zimic-http/src/utils/console.ts create mode 100644 packages/zimic-http/src/utils/data.ts create mode 100644 packages/zimic-http/src/utils/files.ts create mode 100644 packages/zimic-http/src/utils/imports.ts rename packages/{zimic => zimic-http}/src/utils/prettier.ts (100%) rename packages/{zimic => zimic-http}/src/utils/strings.ts (100%) create mode 100644 packages/zimic-http/src/utils/time.ts create mode 100644 packages/zimic-http/src/utils/urls.ts create mode 100644 packages/zimic-http/tests/utils/console.ts rename packages/{zimic => zimic-http}/tests/utils/json.ts (100%) create mode 100644 packages/zimic-http/tsconfig.json create mode 100644 packages/zimic-http/tsup.config.ts create mode 100644 packages/zimic-http/turbo.json rename packages/{zimic => zimic-http}/typegen.d.ts (100%) create mode 100644 packages/zimic-http/vitest.config.mts create mode 100644 packages/zimic-http/vitest.workspace.mts delete mode 100644 packages/zimic/http.d.ts delete mode 100644 packages/zimic/scripts/dev/utils/console.ts rename packages/zimic/src/{http => interceptor/http/interceptorWorker}/errors/InvalidFormDataError.ts (100%) rename packages/zimic/src/{ => interceptor/http/interceptorWorker}/errors/InvalidJSONError.ts (100%) diff --git a/README.md b/README.md index 553285fd..6f227a40 100644 --- a/README.md +++ b/README.md @@ -55,7 +55,7 @@ Zimic provides a flexible and type-safe way to mock HTTP requests. [getting started guide](https://github.com/zimicjs/zimic/wiki/getting‐started) and starting mocking! ```ts -import { type HttpSchema } from 'zimic/http'; +import { type HttpSchema } from '@zimic/http'; import { httpInterceptor } from 'zimic/interceptor/http'; // 1. Declare your types: diff --git a/apps/zimic-test-client/package.json b/apps/zimic-test-client/package.json index 0f8274ed..f4e23124 100644 --- a/apps/zimic-test-client/package.json +++ b/apps/zimic-test-client/package.json @@ -3,7 +3,7 @@ "version": "0.0.0", "private": false, "scripts": { - "lint": "eslint --cache --no-error-on-unmatched-pattern --fix", + "lint": "eslint --cache --no-error-on-unmatched-pattern --no-warn-ignored --fix", "lint:turbo": "pnpm lint . --max-warnings 0", "style": "prettier --log-level warn --ignore-unknown --no-error-on-unmatched-pattern --cache", "style:check": "pnpm style --check", @@ -20,6 +20,7 @@ "@vitest/browser": "^3.0.5", "@vitest/coverage-istanbul": "^3.0.5", "@zimic/eslint-config-node": "workspace:*", + "@zimic/http": "workspace:*", "@zimic/lint-staged-config": "workspace:*", "@zimic/tsconfig": "workspace:*", "axios": "^1.7.9", diff --git a/apps/zimic-test-client/tests/exports/exports.node.test.ts b/apps/zimic-test-client/tests/exports/exports.node.test.ts index d6e51c34..1f0c1cc7 100644 --- a/apps/zimic-test-client/tests/exports/exports.node.test.ts +++ b/apps/zimic-test-client/tests/exports/exports.node.test.ts @@ -1,3 +1,4 @@ +import { typegen, type TypegenNamespace, type OpenAPITypegenOptions } from '@zimic/http/typegen'; import { describe, expect, expectTypeOf, it } from 'vitest'; import { interceptorServer, @@ -8,7 +9,6 @@ import { DEFAULT_ACCESS_CONTROL_HEADERS, DEFAULT_PREFLIGHT_STATUS_CODE, } from 'zimic/interceptor/server'; -import { typegen, type TypegenNamespace, type OpenAPITypegenOptions } from 'zimic/typegen'; describe('Exports (Node.js)', () => { it('should export all expected resources', () => { diff --git a/apps/zimic-test-client/tests/exports/exports.test.ts b/apps/zimic-test-client/tests/exports/exports.test.ts index c90e3910..65137d08 100644 --- a/apps/zimic-test-client/tests/exports/exports.test.ts +++ b/apps/zimic-test-client/tests/exports/exports.test.ts @@ -1,19 +1,6 @@ -import { describe, expect, expectTypeOf, it } from 'vitest'; -import { type JSONValue, type JSONSerialized, InvalidJSONError } from 'zimic'; -import { - createFetch, - type Fetch, - type FetchClient, - type FetchClientOptions, - type FetchFunction, - type FetchInput, - type FetchRequest, - type FetchRequestConstructor, - type FetchRequestInit, - type FetchResponse, - FetchResponseError, -} from 'zimic/fetch'; import { + type JSONValue, + type JSONSerialized, type HttpBody, type HttpRequest, type HttpResponse, @@ -51,8 +38,21 @@ import { type HttpSchemaPath, type InferPathParams, type MergeHttpResponsesByStatusCode, - InvalidFormDataError, -} from 'zimic/http'; +} from '@zimic/http'; +import { describe, expect, expectTypeOf, it } from 'vitest'; +import { + createFetch, + type Fetch, + type FetchClient, + type FetchClientOptions, + type FetchFunction, + type FetchInput, + type FetchRequest, + type FetchRequestConstructor, + type FetchRequestInit, + type FetchResponse, + FetchResponseError, +} from 'zimic/fetch'; import { httpInterceptor, type HttpInterceptorNamespace, @@ -90,6 +90,8 @@ import { UnregisteredBrowserServiceWorkerError, DisabledRequestSavingError, TimesCheckError, + InvalidJSONError, + InvalidFormDataError, } from 'zimic/interceptor/http'; describe('Exports', () => { diff --git a/apps/zimic-test-client/tests/interceptor/thirdParty/shared/default.ts b/apps/zimic-test-client/tests/interceptor/thirdParty/shared/default.ts index d4c70c5c..e19027da 100644 --- a/apps/zimic-test-client/tests/interceptor/thirdParty/shared/default.ts +++ b/apps/zimic-test-client/tests/interceptor/thirdParty/shared/default.ts @@ -1,6 +1,5 @@ +import { JSONSerialized, HttpHeaders, HttpRequest, HttpResponse, HttpSchema, HttpSearchParams } from '@zimic/http'; import { beforeAll, beforeEach, afterAll, expect, describe, it, expectTypeOf, afterEach } from 'vitest'; -import { JSONSerialized } from 'zimic'; -import { HttpHeaders, HttpRequest, HttpResponse, HttpSchema, HttpSearchParams } from 'zimic/http'; import { httpInterceptor, HttpInterceptorType } from 'zimic/interceptor/http'; import { importCrypto, IsomorphicCrypto } from '@tests/utils/crypto'; diff --git a/apps/zimic-test-client/tests/interceptor/thirdParty/shared/schema.ts b/apps/zimic-test-client/tests/interceptor/thirdParty/shared/schema.ts index 0280bcd7..e9a216d5 100644 --- a/apps/zimic-test-client/tests/interceptor/thirdParty/shared/schema.ts +++ b/apps/zimic-test-client/tests/interceptor/thirdParty/shared/schema.ts @@ -1,5 +1,4 @@ -import { JSONValue, JSONSerialized } from 'zimic'; -import { HttpSchema } from 'zimic/http'; +import { JSONValue, JSONSerialized, HttpSchema } from '@zimic/http'; export interface User { id: string; diff --git a/apps/zimic-test-client/tests/typegen/typegen.node.test.ts b/apps/zimic-test-client/tests/typegen/typegen.node.test.ts index 6dce2897..2b3a972a 100644 --- a/apps/zimic-test-client/tests/typegen/typegen.node.test.ts +++ b/apps/zimic-test-client/tests/typegen/typegen.node.test.ts @@ -88,7 +88,7 @@ describe('Typegen', () => { await $( 'pnpm', - ['zimic', 'typegen', 'openapi', input, '--output', generatedFilePath, '--service-name', serviceName], + ['zimic-http', 'typegen', 'openapi', input, '--output', generatedFilePath, '--service-name', serviceName], { stderr: 'inherit' }, ); diff --git "a/docs/wiki/api\342\200\220zimic.md" "b/docs/wiki/api\342\200\220zimic.md" index 8a14c862..a22725cc 100644 --- "a/docs/wiki/api\342\200\220zimic.md" +++ "b/docs/wiki/api\342\200\220zimic.md" @@ -27,7 +27,7 @@ The module `zimic` exports general resources and utility types used by Zimic. Represents or validates a type that is compatible with JSON. ```ts -import { type JSONValue } from 'zimic'; +import { type JSONValue } from '@zimic/http'; // Can be used as a standalone type: const value: JSONValue = { @@ -37,7 +37,7 @@ const value: JSONValue = { ``` ```ts -import { type JSONValue } from 'zimic'; +import { type JSONValue } from '@zimic/http'; // Can be used with a type argument to validate a JSON value: type ValidJSON = JSONValue<{ @@ -66,7 +66,7 @@ Recursively converts a type to its JSON-serialized version. Dates are converted are excluded. ```ts -import { type JSONSerialized } from 'zimic'; +import { type JSONSerialized } from '@zimic/http'; type SerializedUser = JSONSerialized<{ id: string; diff --git "a/docs/wiki/api\342\200\220zimic\342\200\220http.md" "b/docs/wiki/api\342\200\220zimic\342\200\220http.md" index daa496e2..49da1882 100644 --- "a/docs/wiki/api\342\200\220zimic\342\200\220http.md" +++ "b/docs/wiki/api\342\200\220zimic\342\200\220http.md" @@ -38,7 +38,7 @@ schema. `HttpHeaders` is fully compatible with `Headers` and is used by Zimic to headers. ```ts -import { HttpHeaders } from 'zimic/http'; +import { HttpHeaders } from '@zimic/http'; const headers = new HttpHeaders<{ accept?: string; @@ -58,7 +58,7 @@ console.log(contentType); // 'application/json' other headers: ```ts -import { type HttpSchema, HttpHeaders } from 'zimic/http'; +import { type HttpSchema, HttpHeaders } from '@zimic/http'; type HeaderSchema = HttpSchema.Headers<{ accept?: string; @@ -102,7 +102,7 @@ version. Numbers and booleans are converted to `${number}` and `${boolean}` resp serializable values are excluded, such as functions and dates. ```ts -import { type HttpSearchParamsSerialized } from 'zimic/http'; +import { type HttpSearchParamsSerialized } from '@zimic/http'; type Params = HttpSearchParamsSerialized<{ 'content-type': string; @@ -123,7 +123,7 @@ type Params = HttpSearchParamsSerialized<{ Extracts the names of the headers defined in a `HttpHeadersSchema`. Each key is considered a header name. ```ts -import { type HttpSearchParamsSerialized } from 'zimic/http'; +import { type HttpSearchParamsSerialized } from '@zimic/http'; type HeaderName = HttpHeadersSchemaName<{ 'content-type': string; @@ -139,7 +139,7 @@ strictly-typed schema. `HttpSearchParams` is fully compatible with `URLSearchPar type safety when managing search parameters. ```ts -import { HttpSearchParams } from 'zimic/http'; +import { HttpSearchParams } from '@zimic/http'; const searchParams = new HttpSearchParams<{ names?: string[]; @@ -162,7 +162,7 @@ console.log(page); // '1' comparisons with other search params: ```ts -import { type HttpSchema, HttpSearchParams } from 'zimic/http'; +import { type HttpSchema, HttpSearchParams } from '@zimic/http'; type SearchParamsSchema = HttpSchema.SearchParams<{ names?: string[]; @@ -207,7 +207,7 @@ are converted to `${number}` and `${boolean}` respectively, null becomes undefin excluded, such as functions and dates. ```ts -import { type HttpSearchParamsSerialized } from 'zimic/http'; +import { type HttpSearchParamsSerialized } from '@zimic/http'; type Params = HttpSearchParamsSerialized<{ query: string | null; @@ -230,7 +230,7 @@ name. `HttpSearchParamsSchemaName.Array` can be used to extract the names of arr `HttpSearchParamsSchemaName.NonArray` extracts the names of non-array search params. ```ts -import { type HttpSearchParamsSchemaName } from 'zimic/http'; +import { type HttpSearchParamsSchemaName } from '@zimic/http'; type SearchParamsName = HttpSearchParamsSchemaName<{ query?: string[]; @@ -261,7 +261,7 @@ strictly-typed schema. `HttpFormData` is fully compatible with `FormData` and is when managing form data. ```ts -import { HttpFormData } from 'zimic/http'; +import { HttpFormData } from '@zimic/http'; const formData = new HttpFormData<{ files: File[]; @@ -284,7 +284,7 @@ console.log(description); // 'My file' with other form data: ```ts -import { type HttpSchema, HttpFormData } from 'zimic/http'; +import { type HttpSchema, HttpFormData } from '@zimic/http'; type FormDataSchema = HttpSchema.FormData<{ files: File[]; @@ -321,7 +321,7 @@ Numbers and booleans are converted to `${number}` and `${boolean}` respectively, excluded, such as functions and dates. ```ts -import { type HttpFormDataSerialized } from 'zimic/http'; +import { type HttpFormDataSerialized } from '@zimic/http'; type Schema = HttpFormDataSerialized<{ contentTitle: string | null; @@ -348,7 +348,7 @@ schema. Optionally receives a second argument with one or more methods to filter defined in the schema are allowed. ```ts -import { type HttpSchema, type HttpSchemaPath } from 'zimic/http'; +import { type HttpSchema, type HttpSchemaPath } from '@zimic/http'; type Schema = HttpSchema<{ '/users': { @@ -376,7 +376,7 @@ Extracts the literal paths from an HTTP service schema. Optionally receives a se to filter the paths with. Only the methods defined in the schema are allowed. ```ts -import { type HttpSchema, type LiteralHttpSchemaPath } from 'zimic/http'; +import { type HttpSchema, type LiteralHttpSchemaPath } from '@zimic/http'; type Schema = HttpSchema<{ '/users': { @@ -404,7 +404,7 @@ Extracts the non-literal paths from an HTTP service schema. Optionally receives methods to filter the paths with. Only the methods defined in the schema are allowed. ```ts -import { type HttpSchema, type NonLiteralHttpSchemaPath } from 'zimic/http'; +import { type HttpSchema, type NonLiteralHttpSchemaPath } from '@zimic/http'; type Schema = HttpSchema<{ '/users': { @@ -435,7 +435,7 @@ If the first argument is a [HttpSchema](api‐zimic‐interceptor‐http‐schem checked to be a valid path in that schema. ```ts -import { HttpSchema, InferPathParams } from 'zimic/http'; +import { HttpSchema, InferPathParams } from '@zimic/http'; type MySchema = HttpSchema<{ '/users/:userId': { @@ -451,7 +451,7 @@ type PathParams = InferPathParams; ``` ```ts -import { InferPathParams } from 'zimic/http'; +import { InferPathParams } from '@zimic/http'; // Without using a schema to validate the path (works as `PathParamsSchemaFromPath`): type PathParams = InferPathParams<'/users/:userId'>; @@ -464,7 +464,7 @@ Merges multiple HTTP response schemas by status code into a single schema. When first declaration takes precedence. ```ts -import { type HttpSchema, type HttpStatusCode, type MergeHttpResponsesByStatusCode } from 'zimic/http'; +import { type HttpSchema, type HttpStatusCode, type MergeHttpResponsesByStatusCode } from '@zimic/http'; // Overriding the 400 status code with a more specific schema // and using a generic schema for all other client errors. diff --git "a/docs/wiki/api\342\200\220zimic\342\200\220interceptor\342\200\220http.md" "b/docs/wiki/api\342\200\220zimic\342\200\220interceptor\342\200\220http.md" index 48f6deb8..e3829971 100644 --- "a/docs/wiki/api\342\200\220zimic\342\200\220interceptor\342\200\220http.md" +++ "b/docs/wiki/api\342\200\220zimic\342\200\220interceptor\342\200\220http.md" @@ -785,7 +785,7 @@ An equivalent alternative using [`HttpHeaders`](api‐zimic‐http#httpheaders):
Using a local interceptor ```ts -import { type HttpSchema, HttpHeaders } from 'zimic/http'; +import { type HttpSchema, HttpHeaders } from '@zimic/http'; type UserListHeaders = HttpSchema.Headers<{ authorization: string; @@ -807,7 +807,7 @@ const creationHandler = interceptor
Using a remote interceptor ```ts -import { type HttpSchema, HttpHeaders } from 'zimic/http'; +import { type HttpSchema, HttpHeaders } from '@zimic/http'; type UserListHeaders = HttpSchema.Headers<{ authorization: string; @@ -869,7 +869,7 @@ An equivalent alternative using [`HttpSearchParams`](api‐zimic‐http#httpsear
Using a local interceptor ```ts -import { type HttpSchema, HttpSearchParams } from 'zimic/http'; +import { type HttpSchema, HttpSearchParams } from '@zimic/http'; type UserListSearchParams = HttpSchema.SearchParams<{ username?: string; @@ -891,7 +891,7 @@ const creationHandler = interceptor
Using a remote interceptor ```ts -import { type HttpSchema, HttpSearchParams } from 'zimic/http'; +import { type HttpSchema, HttpSearchParams } from '@zimic/http'; type UserListSearchParams = HttpSchema.SearchParams<{ username?: string; @@ -961,7 +961,7 @@ For JSON bodies to be correctly parsed, make sure that the intercepted requests
Using a local interceptor ```ts -import { type HttpSchema, HttpFormData } from 'zimic/http'; +import { type HttpSchema, HttpFormData } from '@zimic/http'; type UserCreationData = HttpSchema.FormData<{ username: string; @@ -991,7 +991,7 @@ const creationHandler = interceptor
Using a remote interceptor ```ts -import { type HttpSchema, HttpFormData } from 'zimic/http'; +import { type HttpSchema, HttpFormData } from '@zimic/http'; type UserCreationData = HttpSchema.FormData<{ username: string; @@ -1112,7 +1112,7 @@ const creationHandler = await interceptor
Using a local interceptor ```ts -import { type HttpSchema, HttpSearchParams } from 'zimic/http'; +import { type HttpSchema, HttpSearchParams } from '@zimic/http'; type UserGetByIdSearchParams = HttpSchema.SearchParams<{ username: string; @@ -1136,7 +1136,7 @@ const creationHandler = interceptor
Using a remote interceptor ```ts -import { type HttpSchema, HttpSearchParams } from 'zimic/http'; +import { type HttpSchema, HttpSearchParams } from '@zimic/http'; type UserGetByIdSearchParams = HttpSchema.SearchParams<{ username: string; @@ -1289,7 +1289,7 @@ const listHandler = await interceptor.get('/users').respond({
Using a local interceptor ```ts -import { type HttpSchema, HttpFormData } from 'zimic/http'; +import { type HttpSchema, HttpFormData } from '@zimic/http'; type UserGetByIdData = HttpSchema.FormData<{ username: string; @@ -1314,7 +1314,7 @@ const listHandler = interceptor.get('/users/:id').respond({
Using a remote interceptor ```ts -import { type HttpSchema, HttpFormData } from 'zimic/http'; +import { type HttpSchema, HttpFormData } from '@zimic/http'; type UserGetByIdData = HttpSchema.FormData<{ username: string; @@ -1403,7 +1403,7 @@ const listHandler = await interceptor.get('/users').respond({
Using a local interceptor ```ts -import { type HttpSchema, HttpSearchParams } from 'zimic/http'; +import { type HttpSchema, HttpSearchParams } from '@zimic/http'; type UserGetByIdSearchParams = HttpSchema.SearchParams<{ username: string; @@ -1422,7 +1422,7 @@ const listHandler = interceptor.get('/users').respond({
Using a remote interceptor ```ts -import { type HttpSchema, HttpSearchParams } from 'zimic/http'; +import { type HttpSchema, HttpSearchParams } from '@zimic/http'; type UserGetByIdSearchParams = HttpSchema.SearchParams<{ username: string; diff --git "a/docs/wiki/api\342\200\220zimic\342\200\220interceptor\342\200\220http\342\200\220schemas.md" "b/docs/wiki/api\342\200\220zimic\342\200\220interceptor\342\200\220http\342\200\220schemas.md" index 5337978c..043b39a0 100644 --- "a/docs/wiki/api\342\200\220zimic\342\200\220interceptor\342\200\220http\342\200\220schemas.md" +++ "b/docs/wiki/api\342\200\220zimic\342\200\220interceptor\342\200\220http\342\200\220schemas.md" @@ -21,7 +21,7 @@ and response bodies, and status codes. Interceptors use this schema to type your An example of a complete HTTP interceptor schema: ```ts -import { type HttpSchema } from 'zimic/http'; +import { type HttpSchema } from '@zimic/http'; import { httpInterceptor } from 'zimic/interceptor/http'; // Declaring base types @@ -95,7 +95,7 @@ const interceptor = httpInterceptor.create({ Alternatively, you can compose the schema using utility types: ```ts -import { type HttpSchema } from 'zimic/http'; +import { type HttpSchema } from '@zimic/http'; import { httpInterceptor } from 'zimic/interceptor/http'; // Declaring the base types @@ -205,7 +205,7 @@ const interceptor = httpInterceptor.create<{ ```ts -import { type HttpSchema } from 'zimic/http'; +import { type HttpSchema } from '@zimic/http'; import { httpInterceptor } from 'zimic/interceptor/http'; type UserPaths = HttpSchema<{ @@ -261,7 +261,7 @@ const interceptor = httpInterceptor.create<{ ```ts -import { type HttpSchema } from 'zimic/http'; +import { type HttpSchema } from '@zimic/http'; import { httpInterceptor } from 'zimic/interceptor/http'; type UserMethods = HttpSchema.Methods<{ @@ -296,7 +296,7 @@ Each method can have a `request`, which defines the schema of the accepted reque ```ts -import { type HttpSchema } from 'zimic/http'; +import { type HttpSchema } from '@zimic/http'; import { httpInterceptor } from 'zimic/interceptor/http'; interface UserListSearchParams { @@ -323,7 +323,7 @@ const interceptor = httpInterceptor.create<{ ```ts -import { type HttpSchema } from 'zimic/http'; +import { type HttpSchema } from '@zimic/http'; import { httpInterceptor } from 'zimic/interceptor/http'; interface UserCreationBody { @@ -359,7 +359,7 @@ const interceptor = httpInterceptor.create<{ ```ts -import { type HttpSchema, type HttpFormData } from 'zimic/http'; +import { type HttpSchema, type HttpFormData } from '@zimic/http'; import { httpInterceptor } from 'zimic/interceptor/http'; type FileUploadData = HttpSchema.FormData<{ @@ -431,7 +431,7 @@ const interceptor = httpInterceptor.create<{ ```ts -import { type HttpSchema, type HttpSearchParams } from 'zimic/http'; +import { type HttpSchema, type HttpSearchParams } from '@zimic/http'; import { httpInterceptor } from 'zimic/interceptor/http'; type UserListSearchParams = HttpSchema.SearchParams<{ @@ -458,7 +458,7 @@ const interceptor = httpInterceptor.create<{ ```ts -import { type HttpSchema } from 'zimic/http'; +import { type HttpSchema } from '@zimic/http'; import { httpInterceptor } from 'zimic/interceptor/http'; interface UserCreationBody { @@ -539,7 +539,7 @@ const interceptor = httpInterceptor.create<{ ```ts -import { type HttpSchema, type HttpFormData } from 'zimic/http'; +import { type HttpSchema, type HttpFormData } from '@zimic/http'; import { httpInterceptor } from 'zimic/interceptor/http'; type FileUploadData = HttpSchema.FormData<{ @@ -617,7 +617,7 @@ const interceptor = httpInterceptor.create<{ ```ts -import { type HttpSchema, type HttpSearchParams } from 'zimic/http'; +import { type HttpSchema, type HttpSearchParams } from '@zimic/http'; import { httpInterceptor } from 'zimic/interceptor/http'; type UserListSearchParams = HttpSchema.SearchParams<{ @@ -647,7 +647,7 @@ const interceptor = httpInterceptor.create<{ ```ts -import { type HttpSchema } from 'zimic/http'; +import { type HttpSchema } from '@zimic/http'; import { httpInterceptor } from 'zimic/interceptor/http'; interface User { diff --git "a/docs/wiki/getting\342\200\220started.md" "b/docs/wiki/getting\342\200\220started.md" index 69ee476a..4b999f1e 100644 --- "a/docs/wiki/getting\342\200\220started.md" +++ "b/docs/wiki/getting\342\200\220started.md" @@ -150,7 +150,7 @@ use remote interceptors.
Using a local interceptor ```ts - import { type HttpSchema } from 'zimic/http'; + import { type HttpSchema } from '@zimic/http'; import { httpInterceptor } from 'zimic/interceptor/http'; // Declare your types: @@ -218,7 +218,7 @@ use remote interceptors.
Using a remote interceptor ```ts - import { type HttpSchema } from 'zimic/http'; + import { type HttpSchema } from '@zimic/http'; import { httpInterceptor } from 'zimic/interceptor/http'; // Declare your types diff --git a/docs/wiki/home.md b/docs/wiki/home.md index 1f7f9b3b..faf8c24d 100644 --- a/docs/wiki/home.md +++ b/docs/wiki/home.md @@ -66,7 +66,7 @@ Zimic provides a flexible and type-safe way to mock HTTP requests. [getting started guide](https://github.com/zimicjs/zimic/wiki/getting‐started) and starting mocking! ```ts -import { type HttpSchema } from 'zimic/http'; +import { type HttpSchema } from '@zimic/http'; import { httpInterceptor } from 'zimic/interceptor/http'; // 1. Declare your types: diff --git a/examples/package.json b/examples/package.json index 29694ade..4522eda6 100644 --- a/examples/package.json +++ b/examples/package.json @@ -3,7 +3,7 @@ "version": "0.0.0", "private": false, "scripts": { - "lint": "eslint --cache --no-error-on-unmatched-pattern --fix", + "lint": "eslint --cache --no-error-on-unmatched-pattern --no-warn-ignored --fix", "lint:turbo": "pnpm lint . --max-warnings 0", "style": "prettier --log-level warn --ignore-unknown --no-error-on-unmatched-pattern --cache", "style:check": "pnpm style --check", diff --git a/examples/with-jest-jsdom/package.json b/examples/with-jest-jsdom/package.json index 37edcc0a..1f98e0a4 100644 --- a/examples/with-jest-jsdom/package.json +++ b/examples/with-jest-jsdom/package.json @@ -8,6 +8,7 @@ "types:check": "tsc --noEmit" }, "dependencies": { + "@zimic/http": "latest", "zimic": "latest" }, "devDependencies": { diff --git a/examples/with-jest-jsdom/src/clients/github.ts b/examples/with-jest-jsdom/src/clients/github.ts index 021eab4d..26271d49 100644 --- a/examples/with-jest-jsdom/src/clients/github.ts +++ b/examples/with-jest-jsdom/src/clients/github.ts @@ -1,5 +1,5 @@ +import type { HttpSchema } from '@zimic/http'; import { createFetch } from 'zimic/fetch'; -import type { HttpSchema } from 'zimic/http'; export interface GitHubRepository { id: number; diff --git a/examples/with-jest-node/package.json b/examples/with-jest-node/package.json index 50e30817..31eed767 100644 --- a/examples/with-jest-node/package.json +++ b/examples/with-jest-node/package.json @@ -8,6 +8,7 @@ "types:check": "tsc --noEmit" }, "dependencies": { + "@zimic/http": "latest", "fastify": "^5.2.1", "zod": "^3.24.2", "zimic": "latest" diff --git a/examples/with-jest-node/src/clients/github.ts b/examples/with-jest-node/src/clients/github.ts index 021eab4d..26271d49 100644 --- a/examples/with-jest-node/src/clients/github.ts +++ b/examples/with-jest-node/src/clients/github.ts @@ -1,5 +1,5 @@ +import type { HttpSchema } from '@zimic/http'; import { createFetch } from 'zimic/fetch'; -import type { HttpSchema } from 'zimic/http'; export interface GitHubRepository { id: number; diff --git a/examples/with-next-js-app/package.json b/examples/with-next-js-app/package.json index 3c2fb271..052bf908 100644 --- a/examples/with-next-js-app/package.json +++ b/examples/with-next-js-app/package.json @@ -17,6 +17,7 @@ }, "dependencies": { "@tanstack/react-query": "^5.66.0", + "@zimic/http": "latest", "clsx": "^2.1.1", "next": "^15.1.7", "react": "^19.0.0", diff --git a/examples/with-next-js-app/src/clients/github.ts b/examples/with-next-js-app/src/clients/github.ts index 5bcc1254..22fd6289 100644 --- a/examples/with-next-js-app/src/clients/github.ts +++ b/examples/with-next-js-app/src/clients/github.ts @@ -1,5 +1,5 @@ +import type { HttpSchema } from '@zimic/http'; import { createFetch } from 'zimic/fetch'; -import type { HttpSchema } from 'zimic/http'; import environment from '../config/environment'; diff --git a/examples/with-next-js-pages/package.json b/examples/with-next-js-pages/package.json index 0bdd6e67..ff090bf4 100644 --- a/examples/with-next-js-pages/package.json +++ b/examples/with-next-js-pages/package.json @@ -13,6 +13,7 @@ }, "dependencies": { "@tanstack/react-query": "^5.66.0", + "@zimic/http": "latest", "clsx": "^2.1.1", "next": "^15.1.7", "react": "^19.0.0", diff --git a/examples/with-next-js-pages/src/clients/github.ts b/examples/with-next-js-pages/src/clients/github.ts index 5bcc1254..22fd6289 100644 --- a/examples/with-next-js-pages/src/clients/github.ts +++ b/examples/with-next-js-pages/src/clients/github.ts @@ -1,5 +1,5 @@ +import type { HttpSchema } from '@zimic/http'; import { createFetch } from 'zimic/fetch'; -import type { HttpSchema } from 'zimic/http'; import environment from '../config/environment'; diff --git a/examples/with-openapi-typegen/package.json b/examples/with-openapi-typegen/package.json index 100c50f7..322fbbc4 100644 --- a/examples/with-openapi-typegen/package.json +++ b/examples/with-openapi-typegen/package.json @@ -7,9 +7,10 @@ "test:turbo": "dotenv -v CI=true -- pnpm run test run", "types:check": "tsc --noEmit", "typegen:github": "dotenv -c development -- pnpm typegen:github-no-env", - "typegen:github-no-env": "zimic typegen openapi $GITHUB_OPENAPI_SPEC_URL --output ./src/clients/github/typegen/generated.ts --service-name GitHub --filter-file ./src/clients/github/typegen/filters.txt --no-comments" + "typegen:github-no-env": "zimic-http typegen openapi $GITHUB_OPENAPI_SPEC_URL --output ./src/clients/github/typegen/generated.ts --service-name GitHub --filter-file ./src/clients/github/typegen/filters.txt --no-comments" }, "dependencies": { + "@zimic/http": "latest", "fastify": "^5.2.1", "zod": "^3.24.2", "zimic": "latest" diff --git a/examples/with-openapi-typegen/src/clients/github/typegen/generated.ts b/examples/with-openapi-typegen/src/clients/github/typegen/generated.ts index e1502ecd..c8a04779 100644 --- a/examples/with-openapi-typegen/src/clients/github/typegen/generated.ts +++ b/examples/with-openapi-typegen/src/clients/github/typegen/generated.ts @@ -1,7 +1,7 @@ // Auto-generated by zimic. // NOTE: Do not manually edit this file. Changes will be overridden. -import type { HttpSchema } from 'zimic/http'; +import type { HttpSchema } from '@zimic/http'; export type GitHubSchema = HttpSchema<{ '/repos/:owner/:repo': { diff --git a/examples/with-playwright/package.json b/examples/with-playwright/package.json index 5fa1c5c9..d55320b8 100644 --- a/examples/with-playwright/package.json +++ b/examples/with-playwright/package.json @@ -16,6 +16,7 @@ "postinstall": "pnpm deps:install-playwright" }, "dependencies": { + "@zimic/http": "latest", "clsx": "^2.1.1", "next": "^15.1.7", "react": "^19.0.0", diff --git a/examples/with-playwright/src/clients/github.ts b/examples/with-playwright/src/clients/github.ts index 5bcc1254..22fd6289 100644 --- a/examples/with-playwright/src/clients/github.ts +++ b/examples/with-playwright/src/clients/github.ts @@ -1,5 +1,5 @@ +import type { HttpSchema } from '@zimic/http'; import { createFetch } from 'zimic/fetch'; -import type { HttpSchema } from 'zimic/http'; import environment from '../config/environment'; diff --git a/examples/with-vitest-browser/package.json b/examples/with-vitest-browser/package.json index 342d5db2..f07b02d8 100644 --- a/examples/with-vitest-browser/package.json +++ b/examples/with-vitest-browser/package.json @@ -11,6 +11,7 @@ "postinstall": "concurrently --names playwright,zimic 'pnpm deps:install-playwright' 'pnpm deps:init-zimic'" }, "dependencies": { + "@zimic/http": "latest", "zimic": "latest" }, "devDependencies": { diff --git a/examples/with-vitest-browser/src/clients/github.ts b/examples/with-vitest-browser/src/clients/github.ts index 021eab4d..26271d49 100644 --- a/examples/with-vitest-browser/src/clients/github.ts +++ b/examples/with-vitest-browser/src/clients/github.ts @@ -1,5 +1,5 @@ +import type { HttpSchema } from '@zimic/http'; import { createFetch } from 'zimic/fetch'; -import type { HttpSchema } from 'zimic/http'; export interface GitHubRepository { id: number; diff --git a/examples/with-vitest-jsdom/package.json b/examples/with-vitest-jsdom/package.json index d939a83c..0264288a 100644 --- a/examples/with-vitest-jsdom/package.json +++ b/examples/with-vitest-jsdom/package.json @@ -8,6 +8,7 @@ "types:check": "tsc --noEmit" }, "dependencies": { + "@zimic/http": "latest", "zimic": "latest" }, "devDependencies": { diff --git a/examples/with-vitest-jsdom/src/clients/github.ts b/examples/with-vitest-jsdom/src/clients/github.ts index 021eab4d..26271d49 100644 --- a/examples/with-vitest-jsdom/src/clients/github.ts +++ b/examples/with-vitest-jsdom/src/clients/github.ts @@ -1,5 +1,5 @@ +import type { HttpSchema } from '@zimic/http'; import { createFetch } from 'zimic/fetch'; -import type { HttpSchema } from 'zimic/http'; export interface GitHubRepository { id: number; diff --git a/examples/with-vitest-node/package.json b/examples/with-vitest-node/package.json index bf14b151..9e3e33af 100644 --- a/examples/with-vitest-node/package.json +++ b/examples/with-vitest-node/package.json @@ -8,6 +8,7 @@ "types:check": "tsc --noEmit" }, "dependencies": { + "@zimic/http": "latest", "fastify": "^5.2.1", "zod": "^3.24.2", "zimic": "latest" diff --git a/examples/with-vitest-node/src/clients/github.ts b/examples/with-vitest-node/src/clients/github.ts index 021eab4d..26271d49 100644 --- a/examples/with-vitest-node/src/clients/github.ts +++ b/examples/with-vitest-node/src/clients/github.ts @@ -1,5 +1,5 @@ +import type { HttpSchema } from '@zimic/http'; import { createFetch } from 'zimic/fetch'; -import type { HttpSchema } from 'zimic/http'; export interface GitHubRepository { id: number; diff --git a/packages/zimic-http/.lintstagedrc.js b/packages/zimic-http/.lintstagedrc.js new file mode 100644 index 00000000..27f56620 --- /dev/null +++ b/packages/zimic-http/.lintstagedrc.js @@ -0,0 +1 @@ +module.exports = require('@zimic/lint-staged-config'); diff --git a/packages/zimic-http/.prettierignore b/packages/zimic-http/.prettierignore new file mode 100644 index 00000000..296a5e08 --- /dev/null +++ b/packages/zimic-http/.prettierignore @@ -0,0 +1,19 @@ +# Dependencies +node_modules + +# Cache +.turbo +.eslintcache +tsconfig.tsbuildinfo + +# Build +/dist +/public/mockServiceWorker.js +**/fixtures/**/generated/* + +# Tests +/tests/coverage + +# Miscellaneous +.vscode +local/ diff --git a/packages/zimic-http/eslint.config.mjs b/packages/zimic-http/eslint.config.mjs new file mode 100644 index 00000000..7bbd60b7 --- /dev/null +++ b/packages/zimic-http/eslint.config.mjs @@ -0,0 +1,14 @@ +import nodeConfig from '@zimic/eslint-config-node'; + +export default [ + ...nodeConfig, + { + ignores: ['*.d.ts', 'interceptor/*.d.ts', 'http/*.d.ts'], + }, + { + files: ['**/fixtures/*/*.ts'], + rules: { + '@typescript-eslint/no-explicit-any': 'off', + }, + }, +]; diff --git a/packages/zimic-http/index.d.ts b/packages/zimic-http/index.d.ts new file mode 100644 index 00000000..5703fb5f --- /dev/null +++ b/packages/zimic-http/index.d.ts @@ -0,0 +1 @@ +export * from './dist'; diff --git a/packages/zimic-http/package.json b/packages/zimic-http/package.json new file mode 100644 index 00000000..d33f0c81 --- /dev/null +++ b/packages/zimic-http/package.json @@ -0,0 +1,111 @@ +{ + "name": "@zimic/http", + "description": "TypeScript-first HTTP resources", + "keywords": [ + "typescript", + "types", + "typegen", + "validation", + "inference", + "http", + "static" + ], + "version": "0.0.0", + "repository": { + "type": "git", + "url": "https://github.com/zimicjs/zimic.git", + "directory": "packages/zimic-http" + }, + "author": { + "name": "Diego Aquino", + "url": "https://github.com/diego-aquino" + }, + "private": false, + "publishConfig": { + "access": "public", + "provenance": true + }, + "engines": { + "node": ">=18.13.0" + }, + "license": "MIT", + "files": [ + "package.json", + "README.md", + "LICENSE.md", + "src", + "!src/**/tests", + "!src/**/__tests__", + "!src/**/*.test.ts", + "dist", + "index.d.ts", + "typegen.d.ts" + ], + "main": "./dist/index.js", + "module": "./dist/index.mjs", + "types": "index.d.ts", + "bin": { + "zimic-http": "./dist/cli.js" + }, + "exports": { + ".": { + "types": "./dist/index.d.ts", + "import": "./dist/index.mjs", + "require": "./dist/index.js", + "default": "./dist/index.js" + }, + "./typegen": { + "types": "./dist/typegen.d.ts", + "import": "./dist/typegen.mjs", + "require": "./dist/typegen.js", + "default": "./dist/typegen.js" + }, + "./package.json": "./package.json" + }, + "scripts": { + "dev": "tsup --watch", + "cli": "node ./dist/cli.js", + "build": "tsup", + "lint": "eslint --cache --no-error-on-unmatched-pattern --no-warn-ignored --fix", + "lint:turbo": "pnpm lint . --max-warnings 0", + "style": "prettier --log-level warn --ignore-unknown --no-error-on-unmatched-pattern --cache", + "style:check": "pnpm style --check", + "style:format": "pnpm style --write", + "test": "dotenv -v NODE_ENV=test -- vitest", + "test:turbo": "dotenv -v CI=true -- pnpm run test run --coverage", + "types:check": "tsc --noEmit", + "typegen:fixtures": "tsx ./scripts/typegen/generateFixtureTypes.js", + "deps:init": "playwright install chromium", + "prepublish:patch-relative-paths": "sed -E -i 's/\\]\\(\\.\\/([^\\)]+)\\)/](..\\/..\\/\\1)/g;s/\"\\.\\/([^\"]+)\"/\"..\\/..\\/\\1\"/g'", + "prepublishOnly": "cp ../../README.md ../../LICENSE.md . && pnpm prepublish:patch-relative-paths README.md" + }, + "dependencies": { + "chalk": "4.1.2", + "openapi-typescript": "7.6.1", + "yargs": "17.7.2" + }, + "devDependencies": { + "@types/js-yaml": "^4.0.9", + "@types/node": "^22.13.4", + "@types/yargs": "^17.0.33", + "@vitest/browser": "^3.0.5", + "@vitest/coverage-istanbul": "^3.0.5", + "@zimic/eslint-config-node": "workspace:*", + "@zimic/lint-staged-config": "workspace:*", + "@zimic/tsconfig": "workspace:*", + "dotenv-cli": "^8.0.0", + "eslint": "^9.20.1", + "execa": "9.5.2", + "js-yaml": "^4.1.0", + "playwright": "^1.50.1", + "prettier": "^3.5.1", + "tsup": "^8.3.6", + "tsx": "^4.19.2", + "typescript": "^5.7.3", + "vitest": "^3.0.5", + "zimic": "^0.13.2" + }, + "peerDependencies": { + "typescript": ">=4.8.0" + } +} diff --git a/packages/zimic/scripts/dev/typegen/generateFixtureTypes.ts b/packages/zimic-http/scripts/typegen/generateFixtureTypes.ts similarity index 89% rename from packages/zimic/scripts/dev/typegen/generateFixtureTypes.ts rename to packages/zimic-http/scripts/typegen/generateFixtureTypes.ts index b102ab09..a55bb34c 100644 --- a/packages/zimic/scripts/dev/typegen/generateFixtureTypes.ts +++ b/packages/zimic-http/scripts/typegen/generateFixtureTypes.ts @@ -1,3 +1,4 @@ +import { execa as $ } from 'execa'; import path from 'path'; import yargs from 'yargs'; import { hideBin } from 'yargs/helpers'; @@ -6,9 +7,20 @@ import { version } from '@@/package.json'; import typegenFixtures from '@/cli/typegen/__tests__/fixtures/typegenFixtures'; import { TypegenFixtureCase, TypegenFixtureCaseName, TypegenFixtureType } from '@/cli/typegen/__tests__/fixtures/types'; -import { runCommand } from '@/utils/processes'; - -import { usingConsoleTime } from '../utils/console'; +import { PossiblePromise } from '@/types/utils'; + +export async function usingConsoleTime( + label: string, + callback: () => PossiblePromise, +): Promise { + console.time(label); + + try { + return await callback(); + } finally { + console.timeEnd(label); + } +} const FIXTURE_TYPEGEN_BATCH_SIZE = 15; @@ -32,7 +44,7 @@ async function generateFixtureCaseTypes(fixtureType: TypegenFixtureType, fixture ...fixtureCase.additionalArguments, ]; - await runCommand('node', commandArguments); + await $('node', commandArguments); }); return outputFilePath; @@ -42,7 +54,7 @@ async function lintGeneratedFiles(filePaths: string[]) { const lintPrefix = '[lint]'; await usingConsoleTime(lintPrefix, async () => { - await runCommand('pnpm', ['--silent', 'lint', ...filePaths]); + await $('pnpm', ['--silent', 'lint', ...filePaths]); }); } diff --git a/packages/zimic-http/src/cli/__tests__/cli.node.test.ts b/packages/zimic-http/src/cli/__tests__/cli.node.test.ts new file mode 100644 index 00000000..f233d06c --- /dev/null +++ b/packages/zimic-http/src/cli/__tests__/cli.node.test.ts @@ -0,0 +1,70 @@ +import { beforeEach, describe, expect, it, vi } from 'vitest'; + +import { version } from '@@/package.json'; + +import { usingIgnoredConsole } from '@tests/utils/console'; + +import runCLI from '../cli'; + +describe('CLI', () => { + const processArgvSpy = vi.spyOn(process, 'argv', 'get'); + + const rootHelpOutput = [ + 'zimic-http [command]', + '', + 'Commands:', + ' zimic-http typegen Generate types from schema sources', + '', + 'Options:', + ' --help Show help [boolean]', + ' --version Show version number [boolean]', + ].join('\n'); + + beforeEach(() => { + processArgvSpy.mockReturnValue([]); + }); + + it('should not throw an error if no command is provided', async () => { + processArgvSpy.mockReturnValue(['node', './dist/cli.js']); + + await usingIgnoredConsole(['error'], async (spies) => { + await runCLI(); + + expect(spies.error).toHaveBeenCalledTimes(0); + }); + }); + + it('should throw an error if an unknown command is provided', async () => { + const unknownCommand = 'unknown'; + + processArgvSpy.mockReturnValue(['node', './dist/cli.js', unknownCommand]); + + await usingIgnoredConsole(['error'], async (spies) => { + await expect(runCLI()).rejects.toThrowError('process.exit unexpectedly called with "1"'); + + expect(spies.error).toHaveBeenCalledTimes(1); + expect(spies.error).toHaveBeenCalledWith(`Unknown argument: ${unknownCommand}`); + }); + }); + + it('should show a help message', async () => { + processArgvSpy.mockReturnValue(['node', './dist/cli.js', '--help']); + await usingIgnoredConsole(['log'], async (spies) => { + await expect(runCLI()).rejects.toThrowError('process.exit unexpectedly called with "0"'); + + expect(spies.log).toHaveBeenCalledTimes(1); + expect(spies.log).toHaveBeenCalledWith(rootHelpOutput); + }); + }); + + it('should show the CLI version', async () => { + processArgvSpy.mockReturnValue(['node', './dist/cli.js', '--version']); + + await usingIgnoredConsole(['log'], async (spies) => { + await expect(runCLI()).rejects.toThrowError('process.exit unexpectedly called with "0"'); + + expect(spies.log).toHaveBeenCalledTimes(1); + expect(spies.log).toHaveBeenCalledWith(version); + }); + }); +}); diff --git a/packages/zimic-http/src/cli/__tests__/index.node.test.ts b/packages/zimic-http/src/cli/__tests__/index.node.test.ts new file mode 100644 index 00000000..6c2d1eb0 --- /dev/null +++ b/packages/zimic-http/src/cli/__tests__/index.node.test.ts @@ -0,0 +1,16 @@ +import { describe, expect, it, vi } from 'vitest'; + +import runCLI from '../cli'; + +vi.mock('../cli', () => ({ + default: vi.fn(), +})); +const runCLIMock = vi.mocked(runCLI); + +describe('CLI (entry point)', () => { + it('should run the CLI after imported', async () => { + await import('../index'); + + expect(runCLIMock).toHaveBeenCalledTimes(1); + }); +}); diff --git a/packages/zimic-http/src/cli/cli.ts b/packages/zimic-http/src/cli/cli.ts new file mode 100644 index 00000000..6b468b22 --- /dev/null +++ b/packages/zimic-http/src/cli/cli.ts @@ -0,0 +1,92 @@ +import yargs from 'yargs'; +import { hideBin } from 'yargs/helpers'; + +import { version } from '@@/package.json'; + +import generateTypesFromOpenAPI from './typegen/openapi'; + +async function runCLI() { + await yargs(hideBin(process.argv)) + .scriptName('zimic-http') + .version(version) + .showHelpOnFail(false) + .strict() + + .command('typegen', 'Generate types from schema sources', (yargs) => + yargs.demandCommand().command( + 'openapi ', + 'Generate types from an OpenAPI schema.', + (yargs) => + yargs + .positional('input', { + type: 'string', + description: + 'The path to a local OpenAPI schema file or an URL to fetch it. ' + + 'Version 3 is supported as YAML or JSON.', + demandOption: true, + }) + .option('output', { + type: 'string', + description: + 'The path to write the generated types to. If not provided, the types will be written to stdout.', + alias: 'o', + }) + .option('service-name', { + type: 'string', + description: 'The name of the service to use in the generated types.', + alias: 's', + demandOption: true, + }) + .option('comments', { + type: 'boolean', + description: 'Whether to include comments in the generated types.', + alias: 'c', + default: true, + }) + .option('prune', { + type: 'boolean', + description: + 'Whether to remove unused operations and components from the generated types. This is useful for ' + + 'reducing the size of the output file.', + alias: 'p', + default: true, + }) + .option('filter', { + type: 'string', + array: true, + description: + 'One or more expressions to filter the types to generate. Filters must follow the format ' + + '` `, where `` is an HTTP method or `*`, and `` is a literal path or a ' + + 'glob. Filters are case-sensitive regarding paths. For example, `GET /users`, `* /users`, ' + + '`GET /users/*`, and `GET /users/**/*` are valid filters. Negative filters can be created by ' + + 'prefixing the expression with `!`. For example, `!GET /users` will exclude paths matching ' + + '`GET /users`. If more than one positive filter is provided, they will be combined with OR, while ' + + 'negative filters will be combined with AND.', + alias: 'f', + }) + .option('filter-file', { + type: 'string', + description: + 'A path to a file containing filter expressions. One expression is expected per line and the format ' + + 'is the same as used in a `--filter` option. Comments are prefixed with `#`. A filter file can be ' + + 'used alongside additional `--filter` expressions.', + alias: 'F', + }), + async (cliArguments) => { + await generateTypesFromOpenAPI({ + input: cliArguments.input, + output: cliArguments.output, + serviceName: cliArguments.serviceName, + includeComments: cliArguments.comments, + prune: cliArguments.prune, + filters: cliArguments.filter, + filterFile: cliArguments.filterFile, + }); + }, + ), + ) + + .parse(); +} + +export default runCLI; diff --git a/packages/zimic-http/src/cli/index.ts b/packages/zimic-http/src/cli/index.ts new file mode 100644 index 00000000..e00cf600 --- /dev/null +++ b/packages/zimic-http/src/cli/index.ts @@ -0,0 +1,4 @@ +#!/usr/bin/env node +import runCLI from './cli'; + +void runCLI(); diff --git a/packages/zimic/src/cli/typegen/__tests__/fixtures/openapi/binary.comments.ts b/packages/zimic-http/src/cli/typegen/__tests__/fixtures/openapi/binary.comments.ts similarity index 88% rename from packages/zimic/src/cli/typegen/__tests__/fixtures/openapi/binary.comments.ts rename to packages/zimic-http/src/cli/typegen/__tests__/fixtures/openapi/binary.comments.ts index 660d945c..001ad79b 100644 --- a/packages/zimic/src/cli/typegen/__tests__/fixtures/openapi/binary.comments.ts +++ b/packages/zimic-http/src/cli/typegen/__tests__/fixtures/openapi/binary.comments.ts @@ -1,7 +1,7 @@ // Auto-generated by zimic. // NOTE: Do not manually edit this file. Changes will be overridden. -import type { HttpSchema } from '@/http'; +import type { HttpSchema } from '@/index'; export type MyServiceSchema = HttpSchema<{ '/binary-upload': { diff --git a/packages/zimic/src/cli/typegen/__tests__/fixtures/openapi/binary.ts b/packages/zimic-http/src/cli/typegen/__tests__/fixtures/openapi/binary.ts similarity index 88% rename from packages/zimic/src/cli/typegen/__tests__/fixtures/openapi/binary.ts rename to packages/zimic-http/src/cli/typegen/__tests__/fixtures/openapi/binary.ts index 99bdf9b4..70583082 100644 --- a/packages/zimic/src/cli/typegen/__tests__/fixtures/openapi/binary.ts +++ b/packages/zimic-http/src/cli/typegen/__tests__/fixtures/openapi/binary.ts @@ -1,7 +1,7 @@ // Auto-generated by zimic. // NOTE: Do not manually edit this file. Changes will be overridden. -import type { HttpSchema } from '@/http'; +import type { HttpSchema } from '@/index'; export type MyServiceSchema = HttpSchema<{ '/binary-upload': { diff --git a/packages/zimic/src/cli/typegen/__tests__/fixtures/openapi/binary.yaml b/packages/zimic-http/src/cli/typegen/__tests__/fixtures/openapi/binary.yaml similarity index 100% rename from packages/zimic/src/cli/typegen/__tests__/fixtures/openapi/binary.yaml rename to packages/zimic-http/src/cli/typegen/__tests__/fixtures/openapi/binary.yaml diff --git a/packages/zimic/src/cli/typegen/__tests__/fixtures/openapi/combinations.comments.ts b/packages/zimic-http/src/cli/typegen/__tests__/fixtures/openapi/combinations.comments.ts similarity index 98% rename from packages/zimic/src/cli/typegen/__tests__/fixtures/openapi/combinations.comments.ts rename to packages/zimic-http/src/cli/typegen/__tests__/fixtures/openapi/combinations.comments.ts index c34c7214..fbf51ac4 100644 --- a/packages/zimic/src/cli/typegen/__tests__/fixtures/openapi/combinations.comments.ts +++ b/packages/zimic-http/src/cli/typegen/__tests__/fixtures/openapi/combinations.comments.ts @@ -1,7 +1,7 @@ // Auto-generated by zimic. // NOTE: Do not manually edit this file. Changes will be overridden. -import type { HttpSchema } from '@/http'; +import type { HttpSchema } from '@/index'; export type MyServiceSchema = HttpSchema<{ '/user-or-friend': { diff --git a/packages/zimic/src/cli/typegen/__tests__/fixtures/openapi/combinations.ts b/packages/zimic-http/src/cli/typegen/__tests__/fixtures/openapi/combinations.ts similarity index 97% rename from packages/zimic/src/cli/typegen/__tests__/fixtures/openapi/combinations.ts rename to packages/zimic-http/src/cli/typegen/__tests__/fixtures/openapi/combinations.ts index 96951c6d..1f4d2e0e 100644 --- a/packages/zimic/src/cli/typegen/__tests__/fixtures/openapi/combinations.ts +++ b/packages/zimic-http/src/cli/typegen/__tests__/fixtures/openapi/combinations.ts @@ -1,7 +1,7 @@ // Auto-generated by zimic. // NOTE: Do not manually edit this file. Changes will be overridden. -import type { HttpSchema } from '@/http'; +import type { HttpSchema } from '@/index'; export type MyServiceSchema = HttpSchema<{ '/user-or-friend': { diff --git a/packages/zimic/src/cli/typegen/__tests__/fixtures/openapi/combinations.yaml b/packages/zimic-http/src/cli/typegen/__tests__/fixtures/openapi/combinations.yaml similarity index 100% rename from packages/zimic/src/cli/typegen/__tests__/fixtures/openapi/combinations.yaml rename to packages/zimic-http/src/cli/typegen/__tests__/fixtures/openapi/combinations.yaml diff --git a/packages/zimic/src/cli/typegen/__tests__/fixtures/openapi/empty.comments.ts b/packages/zimic-http/src/cli/typegen/__tests__/fixtures/openapi/empty.comments.ts similarity index 77% rename from packages/zimic/src/cli/typegen/__tests__/fixtures/openapi/empty.comments.ts rename to packages/zimic-http/src/cli/typegen/__tests__/fixtures/openapi/empty.comments.ts index a386fa9b..058f6069 100644 --- a/packages/zimic/src/cli/typegen/__tests__/fixtures/openapi/empty.comments.ts +++ b/packages/zimic-http/src/cli/typegen/__tests__/fixtures/openapi/empty.comments.ts @@ -1,6 +1,6 @@ // Auto-generated by zimic. // NOTE: Do not manually edit this file. Changes will be overridden. -import type { HttpSchema } from '@/http'; +import type { HttpSchema } from '@/index'; export type MyServiceSchema = HttpSchema<{}>; diff --git a/packages/zimic/src/cli/typegen/__tests__/fixtures/openapi/empty.ts b/packages/zimic-http/src/cli/typegen/__tests__/fixtures/openapi/empty.ts similarity index 77% rename from packages/zimic/src/cli/typegen/__tests__/fixtures/openapi/empty.ts rename to packages/zimic-http/src/cli/typegen/__tests__/fixtures/openapi/empty.ts index a386fa9b..058f6069 100644 --- a/packages/zimic/src/cli/typegen/__tests__/fixtures/openapi/empty.ts +++ b/packages/zimic-http/src/cli/typegen/__tests__/fixtures/openapi/empty.ts @@ -1,6 +1,6 @@ // Auto-generated by zimic. // NOTE: Do not manually edit this file. Changes will be overridden. -import type { HttpSchema } from '@/http'; +import type { HttpSchema } from '@/index'; export type MyServiceSchema = HttpSchema<{}>; diff --git a/packages/zimic/src/cli/typegen/__tests__/fixtures/openapi/empty.yaml b/packages/zimic-http/src/cli/typegen/__tests__/fixtures/openapi/empty.yaml similarity index 100% rename from packages/zimic/src/cli/typegen/__tests__/fixtures/openapi/empty.yaml rename to packages/zimic-http/src/cli/typegen/__tests__/fixtures/openapi/empty.yaml diff --git a/packages/zimic/src/cli/typegen/__tests__/fixtures/openapi/examples.comments.ts b/packages/zimic-http/src/cli/typegen/__tests__/fixtures/openapi/examples.comments.ts similarity index 97% rename from packages/zimic/src/cli/typegen/__tests__/fixtures/openapi/examples.comments.ts rename to packages/zimic-http/src/cli/typegen/__tests__/fixtures/openapi/examples.comments.ts index 29514da8..d4e742af 100644 --- a/packages/zimic/src/cli/typegen/__tests__/fixtures/openapi/examples.comments.ts +++ b/packages/zimic-http/src/cli/typegen/__tests__/fixtures/openapi/examples.comments.ts @@ -1,7 +1,7 @@ // Auto-generated by zimic. // NOTE: Do not manually edit this file. Changes will be overridden. -import type { HttpSchema } from '@/http'; +import type { HttpSchema } from '@/index'; export type MyServiceSchema = HttpSchema<{ '/users': { diff --git a/packages/zimic/src/cli/typegen/__tests__/fixtures/openapi/examples.ts b/packages/zimic-http/src/cli/typegen/__tests__/fixtures/openapi/examples.ts similarity index 93% rename from packages/zimic/src/cli/typegen/__tests__/fixtures/openapi/examples.ts rename to packages/zimic-http/src/cli/typegen/__tests__/fixtures/openapi/examples.ts index ae3d84d4..1947bfb1 100644 --- a/packages/zimic/src/cli/typegen/__tests__/fixtures/openapi/examples.ts +++ b/packages/zimic-http/src/cli/typegen/__tests__/fixtures/openapi/examples.ts @@ -1,7 +1,7 @@ // Auto-generated by zimic. // NOTE: Do not manually edit this file. Changes will be overridden. -import type { HttpSchema } from '@/http'; +import type { HttpSchema } from '@/index'; export type MyServiceSchema = HttpSchema<{ '/users': { diff --git a/packages/zimic/src/cli/typegen/__tests__/fixtures/openapi/examples.yaml b/packages/zimic-http/src/cli/typegen/__tests__/fixtures/openapi/examples.yaml similarity index 100% rename from packages/zimic/src/cli/typegen/__tests__/fixtures/openapi/examples.yaml rename to packages/zimic-http/src/cli/typegen/__tests__/fixtures/openapi/examples.yaml diff --git a/packages/zimic/src/cli/typegen/__tests__/fixtures/openapi/filters.comments.ts b/packages/zimic-http/src/cli/typegen/__tests__/fixtures/openapi/filters.comments.ts similarity index 99% rename from packages/zimic/src/cli/typegen/__tests__/fixtures/openapi/filters.comments.ts rename to packages/zimic-http/src/cli/typegen/__tests__/fixtures/openapi/filters.comments.ts index 7a6d610f..6276dfad 100644 --- a/packages/zimic/src/cli/typegen/__tests__/fixtures/openapi/filters.comments.ts +++ b/packages/zimic-http/src/cli/typegen/__tests__/fixtures/openapi/filters.comments.ts @@ -8,7 +8,7 @@ import type { HttpSchema, HttpSearchParams, HttpSearchParamsSerialized, -} from '@/http'; +} from '@/index'; export type MyServiceSchema = HttpSchema<{ users: { diff --git a/packages/zimic/src/cli/typegen/__tests__/fixtures/openapi/filters.empty.notPruned.ts b/packages/zimic-http/src/cli/typegen/__tests__/fixtures/openapi/filters.empty.notPruned.ts similarity index 98% rename from packages/zimic/src/cli/typegen/__tests__/fixtures/openapi/filters.empty.notPruned.ts rename to packages/zimic-http/src/cli/typegen/__tests__/fixtures/openapi/filters.empty.notPruned.ts index 91a8bc7a..3d8352fd 100644 --- a/packages/zimic/src/cli/typegen/__tests__/fixtures/openapi/filters.empty.notPruned.ts +++ b/packages/zimic-http/src/cli/typegen/__tests__/fixtures/openapi/filters.empty.notPruned.ts @@ -7,7 +7,7 @@ import type { HttpHeadersSerialized, HttpSchema, HttpSearchParamsSerialized, -} from '@/http'; +} from '@/index'; export type MyServiceSchema = HttpSchema<{}>; diff --git a/packages/zimic/src/cli/typegen/__tests__/fixtures/openapi/filters.empty.ts b/packages/zimic-http/src/cli/typegen/__tests__/fixtures/openapi/filters.empty.ts similarity index 77% rename from packages/zimic/src/cli/typegen/__tests__/fixtures/openapi/filters.empty.ts rename to packages/zimic-http/src/cli/typegen/__tests__/fixtures/openapi/filters.empty.ts index a386fa9b..058f6069 100644 --- a/packages/zimic/src/cli/typegen/__tests__/fixtures/openapi/filters.empty.ts +++ b/packages/zimic-http/src/cli/typegen/__tests__/fixtures/openapi/filters.empty.ts @@ -1,6 +1,6 @@ // Auto-generated by zimic. // NOTE: Do not manually edit this file. Changes will be overridden. -import type { HttpSchema } from '@/http'; +import type { HttpSchema } from '@/index'; export type MyServiceSchema = HttpSchema<{}>; diff --git a/packages/zimic/src/cli/typegen/__tests__/fixtures/openapi/filters.multiple.notPruned.ts b/packages/zimic-http/src/cli/typegen/__tests__/fixtures/openapi/filters.multiple.notPruned.ts similarity index 99% rename from packages/zimic/src/cli/typegen/__tests__/fixtures/openapi/filters.multiple.notPruned.ts rename to packages/zimic-http/src/cli/typegen/__tests__/fixtures/openapi/filters.multiple.notPruned.ts index a332d4b7..faaffcca 100644 --- a/packages/zimic/src/cli/typegen/__tests__/fixtures/openapi/filters.multiple.notPruned.ts +++ b/packages/zimic-http/src/cli/typegen/__tests__/fixtures/openapi/filters.multiple.notPruned.ts @@ -7,7 +7,7 @@ import type { HttpHeadersSerialized, HttpSchema, HttpSearchParamsSerialized, -} from '@/http'; +} from '@/index'; export type MyServiceSchema = HttpSchema<{ users: { diff --git a/packages/zimic/src/cli/typegen/__tests__/fixtures/openapi/filters.multiple.ts b/packages/zimic-http/src/cli/typegen/__tests__/fixtures/openapi/filters.multiple.ts similarity index 99% rename from packages/zimic/src/cli/typegen/__tests__/fixtures/openapi/filters.multiple.ts rename to packages/zimic-http/src/cli/typegen/__tests__/fixtures/openapi/filters.multiple.ts index 71d84154..bf0e2885 100644 --- a/packages/zimic/src/cli/typegen/__tests__/fixtures/openapi/filters.multiple.ts +++ b/packages/zimic-http/src/cli/typegen/__tests__/fixtures/openapi/filters.multiple.ts @@ -8,7 +8,7 @@ import type { HttpSchema, HttpSearchParams, HttpSearchParamsSerialized, -} from '@/http'; +} from '@/index'; export type MyServiceSchema = HttpSchema<{ users: { diff --git a/packages/zimic/src/cli/typegen/__tests__/fixtures/openapi/filters.multipleFromFile.notPruned.ts b/packages/zimic-http/src/cli/typegen/__tests__/fixtures/openapi/filters.multipleFromFile.notPruned.ts similarity index 99% rename from packages/zimic/src/cli/typegen/__tests__/fixtures/openapi/filters.multipleFromFile.notPruned.ts rename to packages/zimic-http/src/cli/typegen/__tests__/fixtures/openapi/filters.multipleFromFile.notPruned.ts index 2180c79b..54c9f2e9 100644 --- a/packages/zimic/src/cli/typegen/__tests__/fixtures/openapi/filters.multipleFromFile.notPruned.ts +++ b/packages/zimic-http/src/cli/typegen/__tests__/fixtures/openapi/filters.multipleFromFile.notPruned.ts @@ -8,7 +8,7 @@ import type { HttpSchema, HttpSearchParams, HttpSearchParamsSerialized, -} from '@/http'; +} from '@/index'; export type MyServiceSchema = HttpSchema<{ users: { diff --git a/packages/zimic/src/cli/typegen/__tests__/fixtures/openapi/filters.multipleFromFile.ts b/packages/zimic-http/src/cli/typegen/__tests__/fixtures/openapi/filters.multipleFromFile.ts similarity index 99% rename from packages/zimic/src/cli/typegen/__tests__/fixtures/openapi/filters.multipleFromFile.ts rename to packages/zimic-http/src/cli/typegen/__tests__/fixtures/openapi/filters.multipleFromFile.ts index 71d84154..bf0e2885 100644 --- a/packages/zimic/src/cli/typegen/__tests__/fixtures/openapi/filters.multipleFromFile.ts +++ b/packages/zimic-http/src/cli/typegen/__tests__/fixtures/openapi/filters.multipleFromFile.ts @@ -8,7 +8,7 @@ import type { HttpSchema, HttpSearchParams, HttpSearchParamsSerialized, -} from '@/http'; +} from '@/index'; export type MyServiceSchema = HttpSchema<{ users: { diff --git a/packages/zimic/src/cli/typegen/__tests__/fixtures/openapi/filters.multipleMethods.ts b/packages/zimic-http/src/cli/typegen/__tests__/fixtures/openapi/filters.multipleMethods.ts similarity index 92% rename from packages/zimic/src/cli/typegen/__tests__/fixtures/openapi/filters.multipleMethods.ts rename to packages/zimic-http/src/cli/typegen/__tests__/fixtures/openapi/filters.multipleMethods.ts index 1d209e9a..69f1df6d 100644 --- a/packages/zimic/src/cli/typegen/__tests__/fixtures/openapi/filters.multipleMethods.ts +++ b/packages/zimic-http/src/cli/typegen/__tests__/fixtures/openapi/filters.multipleMethods.ts @@ -1,7 +1,7 @@ // Auto-generated by zimic. // NOTE: Do not manually edit this file. Changes will be overridden. -import type { HttpSchema } from '@/http'; +import type { HttpSchema } from '@/index'; export type MyServiceSchema = HttpSchema<{ '/users/:userId': { diff --git a/packages/zimic/src/cli/typegen/__tests__/fixtures/openapi/filters.negative.1.ts b/packages/zimic-http/src/cli/typegen/__tests__/fixtures/openapi/filters.negative.1.ts similarity index 99% rename from packages/zimic/src/cli/typegen/__tests__/fixtures/openapi/filters.negative.1.ts rename to packages/zimic-http/src/cli/typegen/__tests__/fixtures/openapi/filters.negative.1.ts index 8609c138..9c8f2b15 100644 --- a/packages/zimic/src/cli/typegen/__tests__/fixtures/openapi/filters.negative.1.ts +++ b/packages/zimic-http/src/cli/typegen/__tests__/fixtures/openapi/filters.negative.1.ts @@ -8,7 +8,7 @@ import type { HttpSchema, HttpSearchParams, HttpSearchParamsSerialized, -} from '@/http'; +} from '@/index'; export type MyServiceSchema = HttpSchema<{ users: { diff --git a/packages/zimic/src/cli/typegen/__tests__/fixtures/openapi/filters.negative.2.ts b/packages/zimic-http/src/cli/typegen/__tests__/fixtures/openapi/filters.negative.2.ts similarity index 99% rename from packages/zimic/src/cli/typegen/__tests__/fixtures/openapi/filters.negative.2.ts rename to packages/zimic-http/src/cli/typegen/__tests__/fixtures/openapi/filters.negative.2.ts index 9f12de7f..4cf5b958 100644 --- a/packages/zimic/src/cli/typegen/__tests__/fixtures/openapi/filters.negative.2.ts +++ b/packages/zimic-http/src/cli/typegen/__tests__/fixtures/openapi/filters.negative.2.ts @@ -8,7 +8,7 @@ import type { HttpSchema, HttpSearchParams, HttpSearchParamsSerialized, -} from '@/http'; +} from '@/index'; export type MyServiceSchema = HttpSchema<{ '/notifications': { diff --git a/packages/zimic/src/cli/typegen/__tests__/fixtures/openapi/filters.negative.3.ts b/packages/zimic-http/src/cli/typegen/__tests__/fixtures/openapi/filters.negative.3.ts similarity index 99% rename from packages/zimic/src/cli/typegen/__tests__/fixtures/openapi/filters.negative.3.ts rename to packages/zimic-http/src/cli/typegen/__tests__/fixtures/openapi/filters.negative.3.ts index 696e77cb..3e1e91ba 100644 --- a/packages/zimic/src/cli/typegen/__tests__/fixtures/openapi/filters.negative.3.ts +++ b/packages/zimic-http/src/cli/typegen/__tests__/fixtures/openapi/filters.negative.3.ts @@ -8,7 +8,7 @@ import type { HttpSchema, HttpSearchParams, HttpSearchParamsSerialized, -} from '@/http'; +} from '@/index'; export type MyServiceSchema = HttpSchema<{ users: { diff --git a/packages/zimic/src/cli/typegen/__tests__/fixtures/openapi/filters.oneMethod.notPruned.ts b/packages/zimic-http/src/cli/typegen/__tests__/fixtures/openapi/filters.oneMethod.notPruned.ts similarity index 99% rename from packages/zimic/src/cli/typegen/__tests__/fixtures/openapi/filters.oneMethod.notPruned.ts rename to packages/zimic-http/src/cli/typegen/__tests__/fixtures/openapi/filters.oneMethod.notPruned.ts index e8211778..ddca2e56 100644 --- a/packages/zimic/src/cli/typegen/__tests__/fixtures/openapi/filters.oneMethod.notPruned.ts +++ b/packages/zimic-http/src/cli/typegen/__tests__/fixtures/openapi/filters.oneMethod.notPruned.ts @@ -7,7 +7,7 @@ import type { HttpHeadersSerialized, HttpSchema, HttpSearchParamsSerialized, -} from '@/http'; +} from '@/index'; export type MyServiceSchema = HttpSchema<{ users: { diff --git a/packages/zimic/src/cli/typegen/__tests__/fixtures/openapi/filters.oneMethod.ts b/packages/zimic-http/src/cli/typegen/__tests__/fixtures/openapi/filters.oneMethod.ts similarity index 89% rename from packages/zimic/src/cli/typegen/__tests__/fixtures/openapi/filters.oneMethod.ts rename to packages/zimic-http/src/cli/typegen/__tests__/fixtures/openapi/filters.oneMethod.ts index 78858664..81ca1457 100644 --- a/packages/zimic/src/cli/typegen/__tests__/fixtures/openapi/filters.oneMethod.ts +++ b/packages/zimic-http/src/cli/typegen/__tests__/fixtures/openapi/filters.oneMethod.ts @@ -1,7 +1,7 @@ // Auto-generated by zimic. // NOTE: Do not manually edit this file. Changes will be overridden. -import type { HttpSchema, HttpSearchParamsSerialized } from '@/http'; +import type { HttpSchema, HttpSearchParamsSerialized } from '@/index'; export type MyServiceSchema = HttpSchema<{ users: { diff --git a/packages/zimic/src/cli/typegen/__tests__/fixtures/openapi/filters.pathWildcard.1.ts b/packages/zimic-http/src/cli/typegen/__tests__/fixtures/openapi/filters.pathWildcard.1.ts similarity index 94% rename from packages/zimic/src/cli/typegen/__tests__/fixtures/openapi/filters.pathWildcard.1.ts rename to packages/zimic-http/src/cli/typegen/__tests__/fixtures/openapi/filters.pathWildcard.1.ts index a888d238..5086dbe1 100644 --- a/packages/zimic/src/cli/typegen/__tests__/fixtures/openapi/filters.pathWildcard.1.ts +++ b/packages/zimic-http/src/cli/typegen/__tests__/fixtures/openapi/filters.pathWildcard.1.ts @@ -1,7 +1,7 @@ // Auto-generated by zimic. // NOTE: Do not manually edit this file. Changes will be overridden. -import type { HttpSchema, HttpSearchParamsSerialized } from '@/http'; +import type { HttpSchema, HttpSearchParamsSerialized } from '@/index'; export type MyServiceSchema = HttpSchema<{ users: { diff --git a/packages/zimic/src/cli/typegen/__tests__/fixtures/openapi/filters.pathWildcard.2.ts b/packages/zimic-http/src/cli/typegen/__tests__/fixtures/openapi/filters.pathWildcard.2.ts similarity index 95% rename from packages/zimic/src/cli/typegen/__tests__/fixtures/openapi/filters.pathWildcard.2.ts rename to packages/zimic-http/src/cli/typegen/__tests__/fixtures/openapi/filters.pathWildcard.2.ts index 69700479..3f2ecbb2 100644 --- a/packages/zimic/src/cli/typegen/__tests__/fixtures/openapi/filters.pathWildcard.2.ts +++ b/packages/zimic-http/src/cli/typegen/__tests__/fixtures/openapi/filters.pathWildcard.2.ts @@ -1,7 +1,7 @@ // Auto-generated by zimic. // NOTE: Do not manually edit this file. Changes will be overridden. -import type { HttpSchema, HttpSearchParamsSerialized } from '@/http'; +import type { HttpSchema, HttpSearchParamsSerialized } from '@/index'; export type MyServiceSchema = HttpSchema<{ users: { diff --git a/packages/zimic/src/cli/typegen/__tests__/fixtures/openapi/filters.pathWildcard.3.ts b/packages/zimic-http/src/cli/typegen/__tests__/fixtures/openapi/filters.pathWildcard.3.ts similarity index 92% rename from packages/zimic/src/cli/typegen/__tests__/fixtures/openapi/filters.pathWildcard.3.ts rename to packages/zimic-http/src/cli/typegen/__tests__/fixtures/openapi/filters.pathWildcard.3.ts index 166ad1bb..b9ef9e63 100644 --- a/packages/zimic/src/cli/typegen/__tests__/fixtures/openapi/filters.pathWildcard.3.ts +++ b/packages/zimic-http/src/cli/typegen/__tests__/fixtures/openapi/filters.pathWildcard.3.ts @@ -1,7 +1,7 @@ // Auto-generated by zimic. // NOTE: Do not manually edit this file. Changes will be overridden. -import type { HttpSchema, HttpSearchParamsSerialized } from '@/http'; +import type { HttpSchema, HttpSearchParamsSerialized } from '@/index'; export type MyServiceSchema = HttpSchema<{ users: { diff --git a/packages/zimic/src/cli/typegen/__tests__/fixtures/openapi/filters.pathWildcard.4.ts b/packages/zimic-http/src/cli/typegen/__tests__/fixtures/openapi/filters.pathWildcard.4.ts similarity index 93% rename from packages/zimic/src/cli/typegen/__tests__/fixtures/openapi/filters.pathWildcard.4.ts rename to packages/zimic-http/src/cli/typegen/__tests__/fixtures/openapi/filters.pathWildcard.4.ts index 95fb5eeb..25fff750 100644 --- a/packages/zimic/src/cli/typegen/__tests__/fixtures/openapi/filters.pathWildcard.4.ts +++ b/packages/zimic-http/src/cli/typegen/__tests__/fixtures/openapi/filters.pathWildcard.4.ts @@ -1,7 +1,7 @@ // Auto-generated by zimic. // NOTE: Do not manually edit this file. Changes will be overridden. -import type { HttpSchema } from '@/http'; +import type { HttpSchema } from '@/index'; export type MyServiceSchema = HttpSchema<{ '/users/:userId': { diff --git a/packages/zimic/src/cli/typegen/__tests__/fixtures/openapi/filters.pathWildcard.5.ts b/packages/zimic-http/src/cli/typegen/__tests__/fixtures/openapi/filters.pathWildcard.5.ts similarity index 93% rename from packages/zimic/src/cli/typegen/__tests__/fixtures/openapi/filters.pathWildcard.5.ts rename to packages/zimic-http/src/cli/typegen/__tests__/fixtures/openapi/filters.pathWildcard.5.ts index 95fb5eeb..25fff750 100644 --- a/packages/zimic/src/cli/typegen/__tests__/fixtures/openapi/filters.pathWildcard.5.ts +++ b/packages/zimic-http/src/cli/typegen/__tests__/fixtures/openapi/filters.pathWildcard.5.ts @@ -1,7 +1,7 @@ // Auto-generated by zimic. // NOTE: Do not manually edit this file. Changes will be overridden. -import type { HttpSchema } from '@/http'; +import type { HttpSchema } from '@/index'; export type MyServiceSchema = HttpSchema<{ '/users/:userId': { diff --git a/packages/zimic/src/cli/typegen/__tests__/fixtures/openapi/filters.ts b/packages/zimic-http/src/cli/typegen/__tests__/fixtures/openapi/filters.ts similarity index 99% rename from packages/zimic/src/cli/typegen/__tests__/fixtures/openapi/filters.ts rename to packages/zimic-http/src/cli/typegen/__tests__/fixtures/openapi/filters.ts index 346351ca..00a31063 100644 --- a/packages/zimic/src/cli/typegen/__tests__/fixtures/openapi/filters.ts +++ b/packages/zimic-http/src/cli/typegen/__tests__/fixtures/openapi/filters.ts @@ -8,7 +8,7 @@ import type { HttpSchema, HttpSearchParams, HttpSearchParamsSerialized, -} from '@/http'; +} from '@/index'; export type MyServiceSchema = HttpSchema<{ users: { diff --git a/packages/zimic/src/cli/typegen/__tests__/fixtures/openapi/filters.txt b/packages/zimic-http/src/cli/typegen/__tests__/fixtures/openapi/filters.txt similarity index 100% rename from packages/zimic/src/cli/typegen/__tests__/fixtures/openapi/filters.txt rename to packages/zimic-http/src/cli/typegen/__tests__/fixtures/openapi/filters.txt diff --git a/packages/zimic/src/cli/typegen/__tests__/fixtures/openapi/filters.wildcardMethod.notPruned.ts b/packages/zimic-http/src/cli/typegen/__tests__/fixtures/openapi/filters.wildcardMethod.notPruned.ts similarity index 99% rename from packages/zimic/src/cli/typegen/__tests__/fixtures/openapi/filters.wildcardMethod.notPruned.ts rename to packages/zimic-http/src/cli/typegen/__tests__/fixtures/openapi/filters.wildcardMethod.notPruned.ts index 119d68e2..bb871ee3 100644 --- a/packages/zimic/src/cli/typegen/__tests__/fixtures/openapi/filters.wildcardMethod.notPruned.ts +++ b/packages/zimic-http/src/cli/typegen/__tests__/fixtures/openapi/filters.wildcardMethod.notPruned.ts @@ -7,7 +7,7 @@ import type { HttpHeadersSerialized, HttpSchema, HttpSearchParamsSerialized, -} from '@/http'; +} from '@/index'; export type MyServiceSchema = HttpSchema<{ '/users/:userId': { diff --git a/packages/zimic/src/cli/typegen/__tests__/fixtures/openapi/filters.wildcardMethod.ts b/packages/zimic-http/src/cli/typegen/__tests__/fixtures/openapi/filters.wildcardMethod.ts similarity index 94% rename from packages/zimic/src/cli/typegen/__tests__/fixtures/openapi/filters.wildcardMethod.ts rename to packages/zimic-http/src/cli/typegen/__tests__/fixtures/openapi/filters.wildcardMethod.ts index 17814b16..eca2bc5d 100644 --- a/packages/zimic/src/cli/typegen/__tests__/fixtures/openapi/filters.wildcardMethod.ts +++ b/packages/zimic-http/src/cli/typegen/__tests__/fixtures/openapi/filters.wildcardMethod.ts @@ -1,7 +1,7 @@ // Auto-generated by zimic. // NOTE: Do not manually edit this file. Changes will be overridden. -import type { HttpSchema } from '@/http'; +import type { HttpSchema } from '@/index'; export type MyServiceSchema = HttpSchema<{ '/users/:userId': { diff --git a/packages/zimic/src/cli/typegen/__tests__/fixtures/openapi/filters.yaml b/packages/zimic-http/src/cli/typegen/__tests__/fixtures/openapi/filters.yaml similarity index 100% rename from packages/zimic/src/cli/typegen/__tests__/fixtures/openapi/filters.yaml rename to packages/zimic-http/src/cli/typegen/__tests__/fixtures/openapi/filters.yaml diff --git a/packages/zimic/src/cli/typegen/__tests__/fixtures/openapi/formData.comments.ts b/packages/zimic-http/src/cli/typegen/__tests__/fixtures/openapi/formData.comments.ts similarity index 99% rename from packages/zimic/src/cli/typegen/__tests__/fixtures/openapi/formData.comments.ts rename to packages/zimic-http/src/cli/typegen/__tests__/fixtures/openapi/formData.comments.ts index 6d2741f6..ee5da3b9 100644 --- a/packages/zimic/src/cli/typegen/__tests__/fixtures/openapi/formData.comments.ts +++ b/packages/zimic-http/src/cli/typegen/__tests__/fixtures/openapi/formData.comments.ts @@ -1,7 +1,7 @@ // Auto-generated by zimic. // NOTE: Do not manually edit this file. Changes will be overridden. -import type { HttpFormData, HttpFormDataSerialized, HttpSchema } from '@/http'; +import type { HttpFormData, HttpFormDataSerialized, HttpSchema } from '@/index'; export type MyServiceSchema = HttpSchema<{ '/upload-with-literal-form-data': { diff --git a/packages/zimic/src/cli/typegen/__tests__/fixtures/openapi/formData.ts b/packages/zimic-http/src/cli/typegen/__tests__/fixtures/openapi/formData.ts similarity index 98% rename from packages/zimic/src/cli/typegen/__tests__/fixtures/openapi/formData.ts rename to packages/zimic-http/src/cli/typegen/__tests__/fixtures/openapi/formData.ts index 7c38f04d..55db3a74 100644 --- a/packages/zimic/src/cli/typegen/__tests__/fixtures/openapi/formData.ts +++ b/packages/zimic-http/src/cli/typegen/__tests__/fixtures/openapi/formData.ts @@ -1,7 +1,7 @@ // Auto-generated by zimic. // NOTE: Do not manually edit this file. Changes will be overridden. -import type { HttpFormData, HttpFormDataSerialized, HttpSchema } from '@/http'; +import type { HttpFormData, HttpFormDataSerialized, HttpSchema } from '@/index'; export type MyServiceSchema = HttpSchema<{ '/upload-with-literal-form-data': { diff --git a/packages/zimic/src/cli/typegen/__tests__/fixtures/openapi/formData.yaml b/packages/zimic-http/src/cli/typegen/__tests__/fixtures/openapi/formData.yaml similarity index 100% rename from packages/zimic/src/cli/typegen/__tests__/fixtures/openapi/formData.yaml rename to packages/zimic-http/src/cli/typegen/__tests__/fixtures/openapi/formData.yaml diff --git a/packages/zimic/src/cli/typegen/__tests__/fixtures/openapi/headers.comments.ts b/packages/zimic-http/src/cli/typegen/__tests__/fixtures/openapi/headers.comments.ts similarity index 98% rename from packages/zimic/src/cli/typegen/__tests__/fixtures/openapi/headers.comments.ts rename to packages/zimic-http/src/cli/typegen/__tests__/fixtures/openapi/headers.comments.ts index 45b6c4af..ea0f0167 100644 --- a/packages/zimic/src/cli/typegen/__tests__/fixtures/openapi/headers.comments.ts +++ b/packages/zimic-http/src/cli/typegen/__tests__/fixtures/openapi/headers.comments.ts @@ -1,7 +1,7 @@ // Auto-generated by zimic. // NOTE: Do not manually edit this file. Changes will be overridden. -import type { HttpHeadersSerialized, HttpSchema } from '@/http'; +import type { HttpHeadersSerialized, HttpSchema } from '@/index'; export type MyServiceSchema = HttpSchema<{ '/users-with-literal-component-headers': { diff --git a/packages/zimic/src/cli/typegen/__tests__/fixtures/openapi/headers.ts b/packages/zimic-http/src/cli/typegen/__tests__/fixtures/openapi/headers.ts similarity index 98% rename from packages/zimic/src/cli/typegen/__tests__/fixtures/openapi/headers.ts rename to packages/zimic-http/src/cli/typegen/__tests__/fixtures/openapi/headers.ts index cb361e5b..48286f5a 100644 --- a/packages/zimic/src/cli/typegen/__tests__/fixtures/openapi/headers.ts +++ b/packages/zimic-http/src/cli/typegen/__tests__/fixtures/openapi/headers.ts @@ -1,7 +1,7 @@ // Auto-generated by zimic. // NOTE: Do not manually edit this file. Changes will be overridden. -import type { HttpHeadersSerialized, HttpSchema } from '@/http'; +import type { HttpHeadersSerialized, HttpSchema } from '@/index'; export type MyServiceSchema = HttpSchema<{ '/users-with-literal-component-headers': { diff --git a/packages/zimic/src/cli/typegen/__tests__/fixtures/openapi/headers.yaml b/packages/zimic-http/src/cli/typegen/__tests__/fixtures/openapi/headers.yaml similarity index 100% rename from packages/zimic/src/cli/typegen/__tests__/fixtures/openapi/headers.yaml rename to packages/zimic-http/src/cli/typegen/__tests__/fixtures/openapi/headers.yaml diff --git a/packages/zimic/src/cli/typegen/__tests__/fixtures/openapi/pathItems.comments.ts b/packages/zimic-http/src/cli/typegen/__tests__/fixtures/openapi/pathItems.comments.ts similarity index 93% rename from packages/zimic/src/cli/typegen/__tests__/fixtures/openapi/pathItems.comments.ts rename to packages/zimic-http/src/cli/typegen/__tests__/fixtures/openapi/pathItems.comments.ts index 6c451c08..6f006715 100644 --- a/packages/zimic/src/cli/typegen/__tests__/fixtures/openapi/pathItems.comments.ts +++ b/packages/zimic-http/src/cli/typegen/__tests__/fixtures/openapi/pathItems.comments.ts @@ -1,7 +1,7 @@ // Auto-generated by zimic. // NOTE: Do not manually edit this file. Changes will be overridden. -import type { HttpSchema } from '@/http'; +import type { HttpSchema } from '@/index'; export type MyServiceSchema = HttpSchema<{ '/users-with-path-item-component': MyServiceComponents['pathItems']['users']; diff --git a/packages/zimic/src/cli/typegen/__tests__/fixtures/openapi/pathItems.ts b/packages/zimic-http/src/cli/typegen/__tests__/fixtures/openapi/pathItems.ts similarity index 93% rename from packages/zimic/src/cli/typegen/__tests__/fixtures/openapi/pathItems.ts rename to packages/zimic-http/src/cli/typegen/__tests__/fixtures/openapi/pathItems.ts index 5ac26aaf..dcc055aa 100644 --- a/packages/zimic/src/cli/typegen/__tests__/fixtures/openapi/pathItems.ts +++ b/packages/zimic-http/src/cli/typegen/__tests__/fixtures/openapi/pathItems.ts @@ -1,7 +1,7 @@ // Auto-generated by zimic. // NOTE: Do not manually edit this file. Changes will be overridden. -import type { HttpSchema } from '@/http'; +import type { HttpSchema } from '@/index'; export type MyServiceSchema = HttpSchema<{ '/users-with-path-item-component': MyServiceComponents['pathItems']['users']; diff --git a/packages/zimic/src/cli/typegen/__tests__/fixtures/openapi/pathItems.yaml b/packages/zimic-http/src/cli/typegen/__tests__/fixtures/openapi/pathItems.yaml similarity index 100% rename from packages/zimic/src/cli/typegen/__tests__/fixtures/openapi/pathItems.yaml rename to packages/zimic-http/src/cli/typegen/__tests__/fixtures/openapi/pathItems.yaml diff --git a/packages/zimic/src/cli/typegen/__tests__/fixtures/openapi/pathParams.comments.ts b/packages/zimic-http/src/cli/typegen/__tests__/fixtures/openapi/pathParams.comments.ts similarity index 96% rename from packages/zimic/src/cli/typegen/__tests__/fixtures/openapi/pathParams.comments.ts rename to packages/zimic-http/src/cli/typegen/__tests__/fixtures/openapi/pathParams.comments.ts index 243b466a..4498cc4c 100644 --- a/packages/zimic/src/cli/typegen/__tests__/fixtures/openapi/pathParams.comments.ts +++ b/packages/zimic-http/src/cli/typegen/__tests__/fixtures/openapi/pathParams.comments.ts @@ -1,7 +1,7 @@ // Auto-generated by zimic. // NOTE: Do not manually edit this file. Changes will be overridden. -import type { HttpSchema } from '@/http'; +import type { HttpSchema } from '@/index'; export type MyServiceSchema = HttpSchema<{ '/users/:userId': { diff --git a/packages/zimic/src/cli/typegen/__tests__/fixtures/openapi/pathParams.ts b/packages/zimic-http/src/cli/typegen/__tests__/fixtures/openapi/pathParams.ts similarity index 94% rename from packages/zimic/src/cli/typegen/__tests__/fixtures/openapi/pathParams.ts rename to packages/zimic-http/src/cli/typegen/__tests__/fixtures/openapi/pathParams.ts index 198c3bfc..b946947e 100644 --- a/packages/zimic/src/cli/typegen/__tests__/fixtures/openapi/pathParams.ts +++ b/packages/zimic-http/src/cli/typegen/__tests__/fixtures/openapi/pathParams.ts @@ -1,7 +1,7 @@ // Auto-generated by zimic. // NOTE: Do not manually edit this file. Changes will be overridden. -import type { HttpSchema } from '@/http'; +import type { HttpSchema } from '@/index'; export type MyServiceSchema = HttpSchema<{ '/users/:userId': { diff --git a/packages/zimic/src/cli/typegen/__tests__/fixtures/openapi/pathParams.yaml b/packages/zimic-http/src/cli/typegen/__tests__/fixtures/openapi/pathParams.yaml similarity index 100% rename from packages/zimic/src/cli/typegen/__tests__/fixtures/openapi/pathParams.yaml rename to packages/zimic-http/src/cli/typegen/__tests__/fixtures/openapi/pathParams.yaml diff --git a/packages/zimic/src/cli/typegen/__tests__/fixtures/openapi/requestBodies.comments.ts b/packages/zimic-http/src/cli/typegen/__tests__/fixtures/openapi/requestBodies.comments.ts similarity index 99% rename from packages/zimic/src/cli/typegen/__tests__/fixtures/openapi/requestBodies.comments.ts rename to packages/zimic-http/src/cli/typegen/__tests__/fixtures/openapi/requestBodies.comments.ts index eb485e07..74cd8d97 100644 --- a/packages/zimic/src/cli/typegen/__tests__/fixtures/openapi/requestBodies.comments.ts +++ b/packages/zimic-http/src/cli/typegen/__tests__/fixtures/openapi/requestBodies.comments.ts @@ -1,7 +1,7 @@ // Auto-generated by zimic. // NOTE: Do not manually edit this file. Changes will be overridden. -import type { HttpHeadersSerialized, HttpSchema, HttpSearchParamsSerialized } from '@/http'; +import type { HttpHeadersSerialized, HttpSchema, HttpSearchParamsSerialized } from '@/index'; export type MyServiceSchema = HttpSchema<{ '/users-with-request-body-component': { diff --git a/packages/zimic/src/cli/typegen/__tests__/fixtures/openapi/requestBodies.ts b/packages/zimic-http/src/cli/typegen/__tests__/fixtures/openapi/requestBodies.ts similarity index 99% rename from packages/zimic/src/cli/typegen/__tests__/fixtures/openapi/requestBodies.ts rename to packages/zimic-http/src/cli/typegen/__tests__/fixtures/openapi/requestBodies.ts index e062d298..7979b453 100644 --- a/packages/zimic/src/cli/typegen/__tests__/fixtures/openapi/requestBodies.ts +++ b/packages/zimic-http/src/cli/typegen/__tests__/fixtures/openapi/requestBodies.ts @@ -1,7 +1,7 @@ // Auto-generated by zimic. // NOTE: Do not manually edit this file. Changes will be overridden. -import type { HttpHeadersSerialized, HttpSchema, HttpSearchParamsSerialized } from '@/http'; +import type { HttpHeadersSerialized, HttpSchema, HttpSearchParamsSerialized } from '@/index'; export type MyServiceSchema = HttpSchema<{ '/users-with-request-body-component': { diff --git a/packages/zimic/src/cli/typegen/__tests__/fixtures/openapi/requestBodies.yaml b/packages/zimic-http/src/cli/typegen/__tests__/fixtures/openapi/requestBodies.yaml similarity index 100% rename from packages/zimic/src/cli/typegen/__tests__/fixtures/openapi/requestBodies.yaml rename to packages/zimic-http/src/cli/typegen/__tests__/fixtures/openapi/requestBodies.yaml diff --git a/packages/zimic/src/cli/typegen/__tests__/fixtures/openapi/responses.comments.ts b/packages/zimic-http/src/cli/typegen/__tests__/fixtures/openapi/responses.comments.ts similarity index 99% rename from packages/zimic/src/cli/typegen/__tests__/fixtures/openapi/responses.comments.ts rename to packages/zimic-http/src/cli/typegen/__tests__/fixtures/openapi/responses.comments.ts index d68d7feb..8d89e406 100644 --- a/packages/zimic/src/cli/typegen/__tests__/fixtures/openapi/responses.comments.ts +++ b/packages/zimic-http/src/cli/typegen/__tests__/fixtures/openapi/responses.comments.ts @@ -1,7 +1,7 @@ // Auto-generated by zimic. // NOTE: Do not manually edit this file. Changes will be overridden. -import type { HttpHeadersSerialized, HttpSchema, HttpStatusCode, MergeHttpResponsesByStatusCode } from '@/http'; +import type { HttpHeadersSerialized, HttpSchema, HttpStatusCode, MergeHttpResponsesByStatusCode } from '@/index'; export type MyServiceSchema = HttpSchema<{ '/users-with-non-numeric-status-codes': { diff --git a/packages/zimic/src/cli/typegen/__tests__/fixtures/openapi/responses.ts b/packages/zimic-http/src/cli/typegen/__tests__/fixtures/openapi/responses.ts similarity index 98% rename from packages/zimic/src/cli/typegen/__tests__/fixtures/openapi/responses.ts rename to packages/zimic-http/src/cli/typegen/__tests__/fixtures/openapi/responses.ts index 46489544..2c4ac256 100644 --- a/packages/zimic/src/cli/typegen/__tests__/fixtures/openapi/responses.ts +++ b/packages/zimic-http/src/cli/typegen/__tests__/fixtures/openapi/responses.ts @@ -1,7 +1,7 @@ // Auto-generated by zimic. // NOTE: Do not manually edit this file. Changes will be overridden. -import type { HttpHeadersSerialized, HttpSchema, HttpStatusCode, MergeHttpResponsesByStatusCode } from '@/http'; +import type { HttpHeadersSerialized, HttpSchema, HttpStatusCode, MergeHttpResponsesByStatusCode } from '@/index'; export type MyServiceSchema = HttpSchema<{ '/users-with-non-numeric-status-codes': { diff --git a/packages/zimic/src/cli/typegen/__tests__/fixtures/openapi/responses.yaml b/packages/zimic-http/src/cli/typegen/__tests__/fixtures/openapi/responses.yaml similarity index 100% rename from packages/zimic/src/cli/typegen/__tests__/fixtures/openapi/responses.yaml rename to packages/zimic-http/src/cli/typegen/__tests__/fixtures/openapi/responses.yaml diff --git a/packages/zimic/src/cli/typegen/__tests__/fixtures/openapi/searchParams.comments.ts b/packages/zimic-http/src/cli/typegen/__tests__/fixtures/openapi/searchParams.comments.ts similarity index 99% rename from packages/zimic/src/cli/typegen/__tests__/fixtures/openapi/searchParams.comments.ts rename to packages/zimic-http/src/cli/typegen/__tests__/fixtures/openapi/searchParams.comments.ts index bac2c024..1978b285 100644 --- a/packages/zimic/src/cli/typegen/__tests__/fixtures/openapi/searchParams.comments.ts +++ b/packages/zimic-http/src/cli/typegen/__tests__/fixtures/openapi/searchParams.comments.ts @@ -1,7 +1,7 @@ // Auto-generated by zimic. // NOTE: Do not manually edit this file. Changes will be overridden. -import type { HttpSchema, HttpSearchParams, HttpSearchParamsSerialized } from '@/http'; +import type { HttpSchema, HttpSearchParams, HttpSearchParamsSerialized } from '@/index'; export type MyServiceSchema = HttpSchema<{ '/users-with-literal-component-search-params-in-path': { diff --git a/packages/zimic/src/cli/typegen/__tests__/fixtures/openapi/searchParams.ts b/packages/zimic-http/src/cli/typegen/__tests__/fixtures/openapi/searchParams.ts similarity index 99% rename from packages/zimic/src/cli/typegen/__tests__/fixtures/openapi/searchParams.ts rename to packages/zimic-http/src/cli/typegen/__tests__/fixtures/openapi/searchParams.ts index 4936cd55..5a4cdeeb 100644 --- a/packages/zimic/src/cli/typegen/__tests__/fixtures/openapi/searchParams.ts +++ b/packages/zimic-http/src/cli/typegen/__tests__/fixtures/openapi/searchParams.ts @@ -1,7 +1,7 @@ // Auto-generated by zimic. // NOTE: Do not manually edit this file. Changes will be overridden. -import type { HttpSchema, HttpSearchParams, HttpSearchParamsSerialized } from '@/http'; +import type { HttpSchema, HttpSearchParams, HttpSearchParamsSerialized } from '@/index'; export type MyServiceSchema = HttpSchema<{ '/users-with-literal-component-search-params-in-path': { diff --git a/packages/zimic/src/cli/typegen/__tests__/fixtures/openapi/searchParams.yaml b/packages/zimic-http/src/cli/typegen/__tests__/fixtures/openapi/searchParams.yaml similarity index 100% rename from packages/zimic/src/cli/typegen/__tests__/fixtures/openapi/searchParams.yaml rename to packages/zimic-http/src/cli/typegen/__tests__/fixtures/openapi/searchParams.yaml diff --git a/packages/zimic/src/cli/typegen/__tests__/fixtures/openapi/security.comments.ts b/packages/zimic-http/src/cli/typegen/__tests__/fixtures/openapi/security.comments.ts similarity index 93% rename from packages/zimic/src/cli/typegen/__tests__/fixtures/openapi/security.comments.ts rename to packages/zimic-http/src/cli/typegen/__tests__/fixtures/openapi/security.comments.ts index 58c99657..6818c4f5 100644 --- a/packages/zimic/src/cli/typegen/__tests__/fixtures/openapi/security.comments.ts +++ b/packages/zimic-http/src/cli/typegen/__tests__/fixtures/openapi/security.comments.ts @@ -1,7 +1,7 @@ // Auto-generated by zimic. // NOTE: Do not manually edit this file. Changes will be overridden. -import type { HttpSchema } from '@/http'; +import type { HttpSchema } from '@/index'; export type MyServiceSchema = HttpSchema<{ '/users-with-multiple-security-schemes': { diff --git a/packages/zimic/src/cli/typegen/__tests__/fixtures/openapi/security.ts b/packages/zimic-http/src/cli/typegen/__tests__/fixtures/openapi/security.ts similarity index 92% rename from packages/zimic/src/cli/typegen/__tests__/fixtures/openapi/security.ts rename to packages/zimic-http/src/cli/typegen/__tests__/fixtures/openapi/security.ts index 941fff8b..a24fd901 100644 --- a/packages/zimic/src/cli/typegen/__tests__/fixtures/openapi/security.ts +++ b/packages/zimic-http/src/cli/typegen/__tests__/fixtures/openapi/security.ts @@ -1,7 +1,7 @@ // Auto-generated by zimic. // NOTE: Do not manually edit this file. Changes will be overridden. -import type { HttpSchema } from '@/http'; +import type { HttpSchema } from '@/index'; export type MyServiceSchema = HttpSchema<{ '/users-with-multiple-security-schemes': { diff --git a/packages/zimic/src/cli/typegen/__tests__/fixtures/openapi/security.yaml b/packages/zimic-http/src/cli/typegen/__tests__/fixtures/openapi/security.yaml similarity index 100% rename from packages/zimic/src/cli/typegen/__tests__/fixtures/openapi/security.yaml rename to packages/zimic-http/src/cli/typegen/__tests__/fixtures/openapi/security.yaml diff --git a/packages/zimic/src/cli/typegen/__tests__/fixtures/openapi/simple.comments.ts b/packages/zimic-http/src/cli/typegen/__tests__/fixtures/openapi/simple.comments.ts similarity index 98% rename from packages/zimic/src/cli/typegen/__tests__/fixtures/openapi/simple.comments.ts rename to packages/zimic-http/src/cli/typegen/__tests__/fixtures/openapi/simple.comments.ts index f2051dfe..50f429a0 100644 --- a/packages/zimic/src/cli/typegen/__tests__/fixtures/openapi/simple.comments.ts +++ b/packages/zimic-http/src/cli/typegen/__tests__/fixtures/openapi/simple.comments.ts @@ -1,7 +1,7 @@ // Auto-generated by zimic. // NOTE: Do not manually edit this file. Changes will be overridden. -import type { HttpHeadersSerialized, HttpSchema, HttpSearchParamsSerialized } from '@/http'; +import type { HttpHeadersSerialized, HttpSchema, HttpSearchParamsSerialized } from '@/index'; export type MyServiceSchema = HttpSchema<{ '/users': { diff --git a/packages/zimic/src/cli/typegen/__tests__/fixtures/openapi/simple.ts b/packages/zimic-http/src/cli/typegen/__tests__/fixtures/openapi/simple.ts similarity index 98% rename from packages/zimic/src/cli/typegen/__tests__/fixtures/openapi/simple.ts rename to packages/zimic-http/src/cli/typegen/__tests__/fixtures/openapi/simple.ts index aed3afbb..d7493bd2 100644 --- a/packages/zimic/src/cli/typegen/__tests__/fixtures/openapi/simple.ts +++ b/packages/zimic-http/src/cli/typegen/__tests__/fixtures/openapi/simple.ts @@ -1,7 +1,7 @@ // Auto-generated by zimic. // NOTE: Do not manually edit this file. Changes will be overridden. -import type { HttpHeadersSerialized, HttpSchema, HttpSearchParamsSerialized } from '@/http'; +import type { HttpHeadersSerialized, HttpSchema, HttpSearchParamsSerialized } from '@/index'; export type MyServiceSchema = HttpSchema<{ '/users': { diff --git a/packages/zimic/src/cli/typegen/__tests__/fixtures/openapi/simple.yaml b/packages/zimic-http/src/cli/typegen/__tests__/fixtures/openapi/simple.yaml similarity index 100% rename from packages/zimic/src/cli/typegen/__tests__/fixtures/openapi/simple.yaml rename to packages/zimic-http/src/cli/typegen/__tests__/fixtures/openapi/simple.yaml diff --git a/packages/zimic/src/cli/typegen/__tests__/fixtures/openapi/webhooks.comments.ts b/packages/zimic-http/src/cli/typegen/__tests__/fixtures/openapi/webhooks.comments.ts similarity index 77% rename from packages/zimic/src/cli/typegen/__tests__/fixtures/openapi/webhooks.comments.ts rename to packages/zimic-http/src/cli/typegen/__tests__/fixtures/openapi/webhooks.comments.ts index a386fa9b..058f6069 100644 --- a/packages/zimic/src/cli/typegen/__tests__/fixtures/openapi/webhooks.comments.ts +++ b/packages/zimic-http/src/cli/typegen/__tests__/fixtures/openapi/webhooks.comments.ts @@ -1,6 +1,6 @@ // Auto-generated by zimic. // NOTE: Do not manually edit this file. Changes will be overridden. -import type { HttpSchema } from '@/http'; +import type { HttpSchema } from '@/index'; export type MyServiceSchema = HttpSchema<{}>; diff --git a/packages/zimic/src/cli/typegen/__tests__/fixtures/openapi/webhooks.ts b/packages/zimic-http/src/cli/typegen/__tests__/fixtures/openapi/webhooks.ts similarity index 77% rename from packages/zimic/src/cli/typegen/__tests__/fixtures/openapi/webhooks.ts rename to packages/zimic-http/src/cli/typegen/__tests__/fixtures/openapi/webhooks.ts index a386fa9b..058f6069 100644 --- a/packages/zimic/src/cli/typegen/__tests__/fixtures/openapi/webhooks.ts +++ b/packages/zimic-http/src/cli/typegen/__tests__/fixtures/openapi/webhooks.ts @@ -1,6 +1,6 @@ // Auto-generated by zimic. // NOTE: Do not manually edit this file. Changes will be overridden. -import type { HttpSchema } from '@/http'; +import type { HttpSchema } from '@/index'; export type MyServiceSchema = HttpSchema<{}>; diff --git a/packages/zimic/src/cli/typegen/__tests__/fixtures/openapi/webhooks.yaml b/packages/zimic-http/src/cli/typegen/__tests__/fixtures/openapi/webhooks.yaml similarity index 100% rename from packages/zimic/src/cli/typegen/__tests__/fixtures/openapi/webhooks.yaml rename to packages/zimic-http/src/cli/typegen/__tests__/fixtures/openapi/webhooks.yaml diff --git a/packages/zimic/src/cli/typegen/__tests__/fixtures/openapiTypegenCases.ts b/packages/zimic-http/src/cli/typegen/__tests__/fixtures/openapiTypegenCases.ts similarity index 100% rename from packages/zimic/src/cli/typegen/__tests__/fixtures/openapiTypegenCases.ts rename to packages/zimic-http/src/cli/typegen/__tests__/fixtures/openapiTypegenCases.ts diff --git a/packages/zimic/src/cli/typegen/__tests__/fixtures/typegenFixtures.ts b/packages/zimic-http/src/cli/typegen/__tests__/fixtures/typegenFixtures.ts similarity index 100% rename from packages/zimic/src/cli/typegen/__tests__/fixtures/typegenFixtures.ts rename to packages/zimic-http/src/cli/typegen/__tests__/fixtures/typegenFixtures.ts diff --git a/packages/zimic/src/cli/typegen/__tests__/fixtures/types.ts b/packages/zimic-http/src/cli/typegen/__tests__/fixtures/types.ts similarity index 100% rename from packages/zimic/src/cli/typegen/__tests__/fixtures/types.ts rename to packages/zimic-http/src/cli/typegen/__tests__/fixtures/types.ts diff --git a/packages/zimic/src/cli/typegen/__tests__/openapi.node.test.ts b/packages/zimic-http/src/cli/typegen/__tests__/openapi.node.test.ts similarity index 99% rename from packages/zimic/src/cli/typegen/__tests__/openapi.node.test.ts rename to packages/zimic-http/src/cli/typegen/__tests__/openapi.node.test.ts index c40f9caf..6e60faf5 100644 --- a/packages/zimic/src/cli/typegen/__tests__/openapi.node.test.ts +++ b/packages/zimic-http/src/cli/typegen/__tests__/openapi.node.test.ts @@ -3,9 +3,9 @@ import filesystem from 'fs/promises'; import path from 'path'; import prettier, { Options } from 'prettier'; import { afterAll, beforeAll, beforeEach, describe, expect, it, MockInstance, vi } from 'vitest'; +import { httpInterceptor } from 'zimic/interceptor/http'; import runCLI from '@/cli/cli'; -import { httpInterceptor } from '@/interceptor/http'; import { isDefined } from '@/utils/data'; import { resolvedPrettierConfig } from '@/utils/prettier'; import { usingIgnoredConsole } from '@tests/utils/console'; @@ -105,7 +105,7 @@ describe('Type generation (OpenAPI)', () => { }); const helpOutput = [ - 'zimic typegen openapi ', + 'zimic-http typegen openapi ', '', 'Generate types from an OpenAPI schema.', '', diff --git a/packages/zimic/src/cli/typegen/__tests__/typegen.node.test.ts b/packages/zimic-http/src/cli/typegen/__tests__/typegen.node.test.ts similarity index 90% rename from packages/zimic/src/cli/typegen/__tests__/typegen.node.test.ts rename to packages/zimic-http/src/cli/typegen/__tests__/typegen.node.test.ts index 1ddd6fc1..6d29712e 100644 --- a/packages/zimic/src/cli/typegen/__tests__/typegen.node.test.ts +++ b/packages/zimic-http/src/cli/typegen/__tests__/typegen.node.test.ts @@ -11,12 +11,12 @@ describe('Type generation', () => { }); const helpOutput = [ - 'zimic typegen', + 'zimic-http typegen', '', 'Generate types from schema sources', '', 'Commands:', - ' zimic typegen openapi Generate types from an OpenAPI schema.', + ' zimic-http typegen openapi Generate types from an OpenAPI schema.', '', 'Options:', ' --help Show help [boolean]', diff --git a/packages/zimic/src/cli/typegen/openapi.ts b/packages/zimic-http/src/cli/typegen/openapi.ts similarity index 100% rename from packages/zimic/src/cli/typegen/openapi.ts rename to packages/zimic-http/src/cli/typegen/openapi.ts diff --git a/packages/zimic/src/http/formData/HttpFormData.ts b/packages/zimic-http/src/formData/HttpFormData.ts similarity index 99% rename from packages/zimic/src/http/formData/HttpFormData.ts rename to packages/zimic-http/src/formData/HttpFormData.ts index 3195981b..c42cdbb5 100644 --- a/packages/zimic/src/http/formData/HttpFormData.ts +++ b/packages/zimic-http/src/formData/HttpFormData.ts @@ -11,7 +11,7 @@ import { HttpFormDataSchema, HttpFormDataSchemaName } from './types'; * (`type`). They cannot be interfaces. * * @example - * import { HttpFormData } from 'zimic/http'; + * import { HttpFormData } from '@zimic/http'; * * const formData = new HttpFormData<{ * files: File[]; diff --git a/packages/zimic/src/http/formData/__tests__/HttpFormData.test.ts b/packages/zimic-http/src/formData/__tests__/HttpFormData.test.ts similarity index 91% rename from packages/zimic/src/http/formData/__tests__/HttpFormData.test.ts rename to packages/zimic-http/src/formData/__tests__/HttpFormData.test.ts index d5e8f71a..0c4c49b8 100644 --- a/packages/zimic/src/http/formData/__tests__/HttpFormData.test.ts +++ b/packages/zimic-http/src/formData/__tests__/HttpFormData.test.ts @@ -1,7 +1,5 @@ import { describe, expect, expectTypeOf, it } from 'vitest'; -import { formatValueToLog } from '@/utils/console'; -import { isClientSide } from '@/utils/environment'; import { importFile } from '@/utils/files'; import HttpFormData from '../HttpFormData'; @@ -594,63 +592,4 @@ describe('HttpFormData', async () => { expectTypeOf>>().toEqualTypeOf(); }); }); - - describe('Formatting', () => { - it('should be correctly formatted to log', async () => { - const formData = new HttpFormData<{ - file?: File; - blob: Blob[]; - description: string; - }>(); - - formData.set('file', file); - formData.append('blob', blob); - formData.append('blob', blob); - formData.append('blob', blob, blobName); - formData.set('description', description); - - const formattedFormData = String( - await formatValueToLog(formData.toObject(), { - colors: false, - }), - ); - - if (isClientSide()) { - expect(formattedFormData).toBe('[object Object]'); - } else { - const blobsAsFiles = formData.getAll('blob'); - expect(blobsAsFiles).toHaveLength(3); - - const formattedBlobsAsFiles = blobsAsFiles.map((blobAsFile) => - [ - 'File {', - `lastModified: ${blobAsFile.lastModified},`, - `name: '${blobAsFile.name}',`, - `size: ${blobAsFile.size},`, - `type: '${blobAsFile.type}'`, - '}', - ].join(' '), - ); - - const formattedFile = [ - 'File {', - `lastModified: ${file.lastModified},`, - `name: '${file.name}',`, - `size: ${file.size},`, - `type: '${file.type}'`, - '}', - ].join(' '); - - expect(formattedFormData).toBe( - [ - '{', - `blob: [ ${formattedBlobsAsFiles.join(', ')} ],`, - `description: '${description}',`, - `file: ${formattedFile}`, - '}', - ].join(' '), - ); - } - }); - }); }); diff --git a/packages/zimic/src/http/formData/types.ts b/packages/zimic-http/src/formData/types.ts similarity index 96% rename from packages/zimic/src/http/formData/types.ts rename to packages/zimic-http/src/formData/types.ts index cfbfe804..08094a81 100644 --- a/packages/zimic/src/http/formData/types.ts +++ b/packages/zimic-http/src/formData/types.ts @@ -25,7 +25,7 @@ export namespace HttpFormDataSchemaName { * `HttpFormDataSchemaName.NonArray` extracts the names of non-array form data fields. * * @example - * import { type HttpFormDataSchemaName } from 'zimic/http'; + * import { type HttpFormDataSchemaName } from '@zimic/http'; * * type FormDataName = HttpFormDataSchemaName<{ * title: string; @@ -68,7 +68,7 @@ type PrimitiveHttpFormDataSerialized = Type extends HttpFormDataSchema[str * are excluded, such as functions and dates. * * @example - * import { type HttpFormDataSerialized } from 'zimic/http'; + * import { type HttpFormDataSerialized } from '@zimic/http'; * * type Schema = HttpFormDataSerialized<{ * contentTitle: string | null; diff --git a/packages/zimic/src/http/headers/HttpHeaders.ts b/packages/zimic-http/src/headers/HttpHeaders.ts similarity index 99% rename from packages/zimic/src/http/headers/HttpHeaders.ts rename to packages/zimic-http/src/headers/HttpHeaders.ts index a0c701c4..76bdb451 100644 --- a/packages/zimic/src/http/headers/HttpHeaders.ts +++ b/packages/zimic-http/src/headers/HttpHeaders.ts @@ -19,7 +19,7 @@ function pickPrimitiveProperties(schema: Schem * (`type`). They cannot be interfaces. * * @example - * import { HttpHeaders } from 'zimic/http'; + * import { HttpHeaders } from '@zimic/http'; * * const headers = new HttpHeaders<{ * accept?: string; diff --git a/packages/zimic/src/http/headers/__tests__/HttpHeaders.test.ts b/packages/zimic-http/src/headers/__tests__/HttpHeaders.test.ts similarity index 95% rename from packages/zimic/src/http/headers/__tests__/HttpHeaders.test.ts rename to packages/zimic-http/src/headers/__tests__/HttpHeaders.test.ts index 0fe3f4cd..c4a4ec10 100644 --- a/packages/zimic/src/http/headers/__tests__/HttpHeaders.test.ts +++ b/packages/zimic-http/src/headers/__tests__/HttpHeaders.test.ts @@ -1,8 +1,6 @@ import { describe, expect, expectTypeOf, it } from 'vitest'; -import { HttpSchema } from '@/http/types/schema'; -import { formatValueToLog } from '@/utils/console'; -import { isClientSide } from '@/utils/environment'; +import { HttpSchema } from '@/types/schema'; import HttpHeaders from '../HttpHeaders'; import { HttpHeadersSerialized } from '../types'; @@ -587,30 +585,4 @@ describe('HttpHeaders', () => { expectTypeOf>>().toEqualTypeOf(); }); }); - - describe('Formatting', () => { - it('should be correctly formatted to log', async () => { - const headers = new HttpHeaders<{ - accept: string; - other: string; - 'content-type'?: `application/${string}`; - }>({ - accept: '*/*', - other: 'value, other', - 'content-type': undefined, - }); - - const formattedHeaders = String( - await formatValueToLog(headers.toObject(), { - colors: false, - }), - ); - - if (isClientSide()) { - expect(formattedHeaders).toBe('[object Object]'); - } else { - expect(formattedHeaders).toBe(['{', "accept: '*/*',", "other: 'value, other'", '}'].join(' ')); - } - }); - }); }); diff --git a/packages/zimic/src/http/headers/types.ts b/packages/zimic-http/src/headers/types.ts similarity index 94% rename from packages/zimic/src/http/headers/types.ts rename to packages/zimic-http/src/headers/types.ts index d17449ce..6b1e4ef0 100644 --- a/packages/zimic/src/http/headers/types.ts +++ b/packages/zimic-http/src/headers/types.ts @@ -30,7 +30,7 @@ export type HttpHeadersInit = IfNever = Type extends HttpPathParamsSchema * functions and dates. * * @example - * import { type HttpPathParamsSerialized } from 'zimic/http'; + * import { type HttpPathParamsSerialized } from '@zimic/http'; * * type Params = HttpPathParamsSerialized<{ * userId: string; diff --git a/packages/zimic/src/http/searchParams/HttpSearchParams.ts b/packages/zimic-http/src/searchParams/HttpSearchParams.ts similarity index 99% rename from packages/zimic/src/http/searchParams/HttpSearchParams.ts rename to packages/zimic-http/src/searchParams/HttpSearchParams.ts index a67b5460..cce3274a 100644 --- a/packages/zimic/src/http/searchParams/HttpSearchParams.ts +++ b/packages/zimic-http/src/searchParams/HttpSearchParams.ts @@ -23,7 +23,7 @@ function pickPrimitiveProperties(schema: * aliases (`type`). They cannot be interfaces. * * @example - * import { HttpSearchParams } from 'zimic/http'; + * import { HttpSearchParams } from '@zimic/http'; * * const searchParams = new HttpSearchParams<{ * names?: string[]; diff --git a/packages/zimic/src/http/searchParams/__tests__/HttpSearchParams.test.ts b/packages/zimic-http/src/searchParams/__tests__/HttpSearchParams.test.ts similarity index 94% rename from packages/zimic/src/http/searchParams/__tests__/HttpSearchParams.test.ts rename to packages/zimic-http/src/searchParams/__tests__/HttpSearchParams.test.ts index 704bf915..8e0803f5 100644 --- a/packages/zimic/src/http/searchParams/__tests__/HttpSearchParams.test.ts +++ b/packages/zimic-http/src/searchParams/__tests__/HttpSearchParams.test.ts @@ -1,8 +1,6 @@ import { describe, expect, expectTypeOf, it } from 'vitest'; -import { HttpSchema } from '@/http/types/schema'; -import { formatValueToLog } from '@/utils/console'; -import { isClientSide } from '@/utils/environment'; +import { HttpSchema } from '@/types/schema'; import HttpSearchParams from '../HttpSearchParams'; import { HttpSearchParamsSerialized } from '../types'; @@ -609,37 +607,4 @@ describe('HttpSearchParams', () => { expectTypeOf>>().toEqualTypeOf(); }); }); - - describe('Formatting', () => { - it('should be correctly formatted to log', async () => { - const searchParams = new HttpSearchParams({ - oneName: ['User1'], - twoNames: ['User1', 'User2'], - threeNames: ['User1', 'User2', 'User3'], - page: '1', - other: undefined, - }); - - const formattedSearchParams = String( - await formatValueToLog(searchParams.toObject(), { - colors: false, - }), - ); - - if (isClientSide()) { - expect(formattedSearchParams).toBe('[object Object]'); - } else { - expect(formattedSearchParams).toBe( - [ - '{', - "oneName: 'User1',", - "page: '1',", - "threeNames: [ 'User1', 'User2', 'User3' ],", - "twoNames: [ 'User1', 'User2' ]", - '}', - ].join(' '), - ); - } - }); - }); }); diff --git a/packages/zimic/src/http/searchParams/types.ts b/packages/zimic-http/src/searchParams/types.ts similarity index 97% rename from packages/zimic/src/http/searchParams/types.ts rename to packages/zimic-http/src/searchParams/types.ts index e466b57b..af9b72f6 100644 --- a/packages/zimic/src/http/searchParams/types.ts +++ b/packages/zimic-http/src/searchParams/types.ts @@ -43,7 +43,7 @@ export namespace HttpSearchParamsSchemaName { * `HttpSearchParamsSchemaName.NonArray` extracts the names of non-array search params. * * @example - * import { type HttpSearchParamsSchemaName } from 'zimic/http'; + * import { type HttpSearchParamsSchemaName } from '@zimic/http'; * * type SearchParamsName = HttpSearchParamsSchemaName<{ * query?: string[]; @@ -93,7 +93,7 @@ type PrimitiveHttpSearchParamsSerialized = Type extends HttpSearchParamsSc * values are excluded, such as functions and dates. * * @example - * import { type HttpSearchParamsSerialized } from 'zimic/http'; + * import { type HttpSearchParamsSerialized } from '@zimic/http'; * * type Params = HttpSearchParamsSerialized<{ * query: string | null; diff --git a/packages/zimic/src/typegen/index.ts b/packages/zimic-http/src/typegen/index.ts similarity index 100% rename from packages/zimic/src/typegen/index.ts rename to packages/zimic-http/src/typegen/index.ts diff --git a/packages/zimic/src/typegen/namespace/TypegenNamespace.ts b/packages/zimic-http/src/typegen/namespace/TypegenNamespace.ts similarity index 100% rename from packages/zimic/src/typegen/namespace/TypegenNamespace.ts rename to packages/zimic-http/src/typegen/namespace/TypegenNamespace.ts diff --git a/packages/zimic/src/typegen/openapi/generate.ts b/packages/zimic-http/src/typegen/openapi/generate.ts similarity index 100% rename from packages/zimic/src/typegen/openapi/generate.ts rename to packages/zimic-http/src/typegen/openapi/generate.ts diff --git a/packages/zimic/src/typegen/openapi/transform/components.ts b/packages/zimic-http/src/typegen/openapi/transform/components.ts similarity index 100% rename from packages/zimic/src/typegen/openapi/transform/components.ts rename to packages/zimic-http/src/typegen/openapi/transform/components.ts diff --git a/packages/zimic/src/typegen/openapi/transform/context.ts b/packages/zimic-http/src/typegen/openapi/transform/context.ts similarity index 100% rename from packages/zimic/src/typegen/openapi/transform/context.ts rename to packages/zimic-http/src/typegen/openapi/transform/context.ts diff --git a/packages/zimic/src/typegen/openapi/transform/filters.ts b/packages/zimic-http/src/typegen/openapi/transform/filters.ts similarity index 97% rename from packages/zimic/src/typegen/openapi/transform/filters.ts rename to packages/zimic-http/src/typegen/openapi/transform/filters.ts index 7c159d37..a3039717 100644 --- a/packages/zimic/src/typegen/openapi/transform/filters.ts +++ b/packages/zimic-http/src/typegen/openapi/transform/filters.ts @@ -2,7 +2,7 @@ import chalk from 'chalk'; import filesystem from 'fs/promises'; import path from 'path'; -import { HTTP_METHODS } from '@/http/types/schema'; +import { HTTP_METHODS } from '@/types/schema'; import { logWithPrefix } from '@/utils/console'; import { isNonEmpty } from '@/utils/data'; import { createRegexFromWildcardPath } from '@/utils/urls'; diff --git a/packages/zimic/src/typegen/openapi/transform/imports.ts b/packages/zimic-http/src/typegen/openapi/transform/imports.ts similarity index 95% rename from packages/zimic/src/typegen/openapi/transform/imports.ts rename to packages/zimic-http/src/typegen/openapi/transform/imports.ts index 77795853..876fa789 100644 --- a/packages/zimic/src/typegen/openapi/transform/imports.ts +++ b/packages/zimic-http/src/typegen/openapi/transform/imports.ts @@ -3,7 +3,7 @@ import { TypeTransformContext } from './context'; /* istanbul ignore next -- @preserve * The root import module is defined at build time. The fallback is not expected to be used. */ -export const TYPEGEN_HTTP_IMPORT_MODULE = process.env.TYPEGEN_HTTP_IMPORT_MODULE ?? 'zimic/http'; +export const TYPEGEN_HTTP_IMPORT_MODULE = process.env.TYPEGEN_HTTP_IMPORT_MODULE ?? '@zimic/http'; export function createImportDeclarations(context: TypeTransformContext) { const httpTypeImports = Array.from(context.typeImports.http).sort().map(createImportSpecifier); diff --git a/packages/zimic/src/typegen/openapi/transform/io.ts b/packages/zimic-http/src/typegen/openapi/transform/io.ts similarity index 100% rename from packages/zimic/src/typegen/openapi/transform/io.ts rename to packages/zimic-http/src/typegen/openapi/transform/io.ts diff --git a/packages/zimic/src/typegen/openapi/transform/methods.ts b/packages/zimic-http/src/typegen/openapi/transform/methods.ts similarity index 99% rename from packages/zimic/src/typegen/openapi/transform/methods.ts rename to packages/zimic-http/src/typegen/openapi/transform/methods.ts index 7869a7cd..82cc07b6 100644 --- a/packages/zimic/src/typegen/openapi/transform/methods.ts +++ b/packages/zimic-http/src/typegen/openapi/transform/methods.ts @@ -1,7 +1,7 @@ import chalk from 'chalk'; import ts from 'typescript'; -import { HTTP_METHODS, HttpMethod } from '@/http/types/schema'; +import { HTTP_METHODS, HttpMethod } from '@/types/schema'; import { Override } from '@/types/utils'; import { logWithPrefix } from '@/utils/console'; import { isDefined } from '@/utils/data'; diff --git a/packages/zimic/src/typegen/openapi/transform/operations.ts b/packages/zimic-http/src/typegen/openapi/transform/operations.ts similarity index 100% rename from packages/zimic/src/typegen/openapi/transform/operations.ts rename to packages/zimic-http/src/typegen/openapi/transform/operations.ts diff --git a/packages/zimic/src/typegen/openapi/transform/paths.ts b/packages/zimic-http/src/typegen/openapi/transform/paths.ts similarity index 100% rename from packages/zimic/src/typegen/openapi/transform/paths.ts rename to packages/zimic-http/src/typegen/openapi/transform/paths.ts diff --git a/packages/zimic/src/typegen/openapi/utils/types.ts b/packages/zimic-http/src/typegen/openapi/utils/types.ts similarity index 100% rename from packages/zimic/src/typegen/openapi/utils/types.ts rename to packages/zimic-http/src/typegen/openapi/utils/types.ts diff --git a/packages/zimic-http/src/types/__tests__/json.test.ts b/packages/zimic-http/src/types/__tests__/json.test.ts new file mode 100644 index 00000000..5382e5b5 --- /dev/null +++ b/packages/zimic-http/src/types/__tests__/json.test.ts @@ -0,0 +1,132 @@ +import { describe, expectTypeOf, it } from 'vitest'; + +import { JSONValue, JSONSerialized } from '../json'; + +describe('JSON types', () => { + it('should type JSON values correctly', () => { + 'a' satisfies JSONValue; + 1 satisfies JSONValue; + true satisfies JSONValue; + false satisfies JSONValue; + null satisfies JSONValue; + undefined satisfies JSONValue; + ['e'] satisfies JSONValue; + [{ g: 'g' }] satisfies JSONValue; + ({ a: 1, b: { c: { d: [] } } }) satisfies JSONValue; + + ({ + a: 'a', + b: 1, + c: true, + d: false, + e: null, + f: ['e'], + g: [{ g: 'g' }], + h: { a: 1, b: { c: { d: [] } } }, + }) satisfies JSONValue; + + // @ts-expect-error Dates are not a strict JSON value + Date satisfies JSONValue; + // @ts-expect-error Functions are not a strict JSON value + (() => {}) satisfies JSONValue; // eslint-disable-line @typescript-eslint/no-empty-function + + ({ + a: Date, + b: () => {}, // eslint-disable-line @typescript-eslint/no-empty-function + c: Symbol('c'), + d: Error, + // @ts-expect-error Object with non-JSON values are not a strict JSON value + }) satisfies JSONValue; + }); + + it('should validate if type declarations are JSON-compatible', () => { + // Checking compatibility with abstract JSON value + // eslint-disable-next-line @typescript-eslint/no-unnecessary-type-arguments + expectTypeOf>().not.toBeAny(); + + expectTypeOf>().not.toBeAny(); + expectTypeOf>().not.toBeAny(); + expectTypeOf>().not.toBeAny(); + expectTypeOf>().not.toBeAny(); + expectTypeOf>().not.toBeAny(); + expectTypeOf>().not.toBeAny(); + expectTypeOf>().not.toBeAny(); + expectTypeOf>().not.toBeAny(); + expectTypeOf>().not.toBeAny(); + expectTypeOf>().not.toBeAny(); + expectTypeOf>().not.toBeAny(); + expectTypeOf>().not.toBeAny(); + expectTypeOf>().not.toBeAny(); + expectTypeOf>().not.toBeAny(); + + // @ts-expect-error Dates are not JSON-compatible + expectTypeOf>().not.toBeAny(); + // @ts-expect-error Dates are not JSON-compatible + expectTypeOf>().not.toBeAny(); + // @ts-expect-error Functions are not JSON-compatible + expectTypeOf void>>().not.toBeAny(); + // @ts-expect-error Functions are not JSON-compatible + expectTypeOf) => Error>>().not.toBeAny(); + + // @ts-expect-error Object with non-JSON-compatible values are not JSON-compatible + expectTypeOf>().not.toBeAny(); + // @ts-expect-error Object with non-JSON-compatible values are not JSON-compatible + expectTypeOf void }>>().not.toBeAny(); + // @ts-expect-error Object with non-JSON-compatible values are not JSON-compatible + expectTypeOf>().not.toBeAny(); + // @ts-expect-error Object with non-JSON-compatible values are not JSON-compatible + expectTypeOf>().not.toBeAny(); + }); + + it('should convert types to their JSON-serialized versions', () => { + expectTypeOf>().toEqualTypeOf(); + expectTypeOf>().toEqualTypeOf(); + expectTypeOf>().toEqualTypeOf(); + expectTypeOf>().toEqualTypeOf(); + expectTypeOf>().toEqualTypeOf(); + expectTypeOf>().toEqualTypeOf(); + expectTypeOf>().toEqualTypeOf<{ a: string }>(); + expectTypeOf>().toEqualTypeOf<{ a?: string }>(); + expectTypeOf>().toEqualTypeOf<{ a: string | undefined }>(); + expectTypeOf>().toEqualTypeOf<{ a?: string | undefined }>(); + expectTypeOf>().toEqualTypeOf<{ a: string }[]>(); + expectTypeOf< + JSONSerialized<{ + a: string; + b: { c: { d: string[] } }; + }> + >().toEqualTypeOf<{ + a: string; + b: { c: { d: string[] } }; + }>(); + expectTypeOf>().toEqualTypeOf<{ a: string | null }>(); + + expectTypeOf>().toEqualTypeOf(); + expectTypeOf>().toEqualTypeOf(); + expectTypeOf>>().toEqualTypeOf>(); + expectTypeOf>>().toEqualTypeOf>(); + expectTypeOf>().toEqualTypeOf<{ a: string }>(); + expectTypeOf>().toEqualTypeOf<{ a: string[]; b: string }>(); + expectTypeOf void>>().toEqualTypeOf(); + expectTypeOf void }>>().toEqualTypeOf<{}>(); + expectTypeOf void; b: string }>>().toEqualTypeOf<{ b: string }>(); + expectTypeOf< + JSONSerialized<{ + a: (value: string, otherValue: Map) => Error; + b: string; + }> + >().toEqualTypeOf<{ + b: string; + }>(); + expectTypeOf>().toEqualTypeOf<{ b: string }>(); + expectTypeOf< + JSONSerialized<{ + a: Error; + b: string; + }> + >().toEqualTypeOf<{ + a: { name: string; message: string; stack?: string }; + b: string; + }>(); + }); +}); diff --git a/packages/zimic/src/http/types/__tests__/schema.test.ts b/packages/zimic-http/src/types/__tests__/schema.test.ts similarity index 100% rename from packages/zimic/src/http/types/__tests__/schema.test.ts rename to packages/zimic-http/src/types/__tests__/schema.test.ts diff --git a/packages/zimic-http/src/types/arrays.d.ts b/packages/zimic-http/src/types/arrays.d.ts new file mode 100644 index 00000000..26039350 --- /dev/null +++ b/packages/zimic-http/src/types/arrays.d.ts @@ -0,0 +1,4 @@ +interface ArrayConstructor { + // eslint-disable-next-line @typescript-eslint/method-signature-style + isArray(value: unknown): value is Item[]; +} diff --git a/packages/zimic-http/src/types/json.ts b/packages/zimic-http/src/types/json.ts new file mode 100644 index 00000000..244bd929 --- /dev/null +++ b/packages/zimic-http/src/types/json.ts @@ -0,0 +1,89 @@ +type JSON = { [key: string]: JSON } | JSON[] | string | number | boolean | null | undefined; + +namespace JSON { + // eslint-disable-next-line @typescript-eslint/no-explicit-any + export type Loose = Record | Loose[] | string | number | boolean | null | undefined; +} + +/** + * Represents or validates a type that is compatible with JSON. + * + * **IMPORTANT**: the input of `JSONValue` and all of its internal types must be declared inline or as a type aliases + * (`type`). They cannot be interfaces. + * + * @example + * import { type JSONValue } from '@zimic/http'; + * + * // Can be used as a standalone type: + * const value: JSONValue = { + * name: 'example', + * tags: ['one', 'two'], + * }; + * + * @example + * import { type JSONValue } from '@zimic/http'; + * + * // Can be used with a type argument to validate a JSON value: + * type ValidJSON = JSONValue<{ + * id: string; + * email: string; + * createdAt: string; + * }>; + * + * // This results in a type error: + * type InvalidJSON = JSONValue<{ + * id: string; + * email: string; + * createdAt: Date; // `Date` is not a valid JSON value. + * save: () => Promise; // Functions are not valid JSON values. + * }>; + */ +export type JSONValue = Type; + +export namespace JSONValue { + /** A loose version of the JSON value type. JSON objects are not strictly typed. */ + export type Loose = Type; +} + +/** + * Recursively converts a type to its JSON-serialized version. Dates are converted to strings and keys with non-JSON + * values are excluded. + * + * @example + * import { type JSONSerialized } from '@zimic/http'; + * + * type SerializedUser = JSONSerialized<{ + * id: string; + * email: string; + * createdAt: Date; + * save: () => Promise; + * }>; + * // { + * // id: string; + * // email: string; + * // createdAt: string; + * // } + */ +export type JSONSerialized = Type extends JSONValue + ? Type + : Type extends string | number | boolean | null | undefined + ? Type + : Type extends Date + ? string + : Type extends (...parameters: never[]) => unknown + ? never + : Type extends symbol + ? never + : Type extends Map + ? Record + : Type extends Set + ? Record + : Type extends (infer ArrayItem)[] + ? JSONSerialized[] + : Type extends object + ? { + [Key in keyof Type as [JSONSerialized] extends [never] ? never : Key]: JSONSerialized< + Type[Key] + >; + } + : never; diff --git a/packages/zimic-http/src/types/objects.d.ts b/packages/zimic-http/src/types/objects.d.ts new file mode 100644 index 00000000..1360bf69 --- /dev/null +++ b/packages/zimic-http/src/types/objects.d.ts @@ -0,0 +1,14 @@ +type ObjectKey = keyof Type & string; +type ObjectValue = Type[ObjectKey]; +type ObjectEntry = [ObjectKey, ObjectValue]; + +interface ObjectConstructor { + // eslint-disable-next-line @typescript-eslint/method-signature-style + keys(object: Type): ObjectKey[]; + + // eslint-disable-next-line @typescript-eslint/method-signature-style + values(object: Type): ObjectValue[]; + + // eslint-disable-next-line @typescript-eslint/method-signature-style + entries(object: Type): ObjectEntry[]; +} diff --git a/packages/zimic/src/http/types/requests.ts b/packages/zimic-http/src/types/requests.ts similarity index 98% rename from packages/zimic/src/http/types/requests.ts rename to packages/zimic-http/src/types/requests.ts index afdb4019..72ffeb4e 100644 --- a/packages/zimic/src/http/types/requests.ts +++ b/packages/zimic-http/src/types/requests.ts @@ -1,4 +1,5 @@ import { JSONSerialized, JSONValue } from '@/types/json'; +import { HttpStatusCode } from '@/types/schema'; import { ReplaceBy } from '@/types/utils'; import HttpFormData from '../formData/HttpFormData'; @@ -7,7 +8,6 @@ import HttpHeaders from '../headers/HttpHeaders'; import { HttpHeadersSchema } from '../headers/types'; import HttpSearchParams from '../searchParams/HttpSearchParams'; import { HttpSearchParamsSchema } from '../searchParams/types'; -import { HttpStatusCode } from './schema'; /** The body type for HTTP requests and responses. */ // eslint-disable-next-line @typescript-eslint/no-explicit-any diff --git a/packages/zimic/src/http/types/schema.ts b/packages/zimic-http/src/types/schema.ts similarity index 96% rename from packages/zimic/src/http/types/schema.ts rename to packages/zimic-http/src/types/schema.ts index 8db9e62e..e11cb9f5 100644 --- a/packages/zimic/src/http/types/schema.ts +++ b/packages/zimic-http/src/types/schema.ts @@ -288,7 +288,7 @@ export type ConvertToStrictHttpSchema = { * a type aliases (`type`). Types other than bodies cannot be interfaces. * * @example - * import { type HttpSchema } from 'zimic/http'; + * import { type HttpSchema } from '@zimic/http'; * * interface UserListHeaders { * accept: string; @@ -329,7 +329,7 @@ export namespace HttpSchema { * inline or as a type aliases (`type`). Types other than bodies cannot be interfaces. * * @example - * import { type HttpSchema } from 'zimic/http'; + * import { type HttpSchema } from '@zimic/http'; * * type UserMethods = HttpSchema.Methods<{ * GET: { @@ -352,7 +352,7 @@ export namespace HttpSchema { * inline or as a type aliases (`type`). Types other than bodies cannot be interfaces. * * @example - * import { type HttpSchema } from 'zimic/http'; + * import { type HttpSchema } from '@zimic/http'; * * type UserListMethod = HttpSchema.Method<{ * response: { @@ -375,7 +375,7 @@ export namespace HttpSchema { * inline or as a type aliases (`type`). Types other than bodies cannot be interfaces. * * @example - * import { type HttpSchema } from 'zimic/http'; + * import { type HttpSchema } from '@zimic/http'; * * type UserCreationRequest = HttpSchema.Request<{ * headers: { 'content-type': 'application/json' }; @@ -402,7 +402,7 @@ export namespace HttpSchema { * declared inline or as a type aliases (`type`). Types other than bodies cannot be interfaces. * * @example - * import { type HttpSchema } from 'zimic/http'; + * import { type HttpSchema } from '@zimic/http'; * * type UserListResponseByStatusCode = HttpSchema.ResponseByStatusCode<{ * 200: { body: User[] }; @@ -427,7 +427,7 @@ export namespace HttpSchema { * inline or as a type aliases (`type`). Types other than bodies cannot be interfaces. * * @example - * import { type HttpSchema } from 'zimic/http'; + * import { type HttpSchema } from '@zimic/http'; * * type UserListSuccessResponse = HttpSchema.Response<{ * body: User[]; @@ -450,7 +450,7 @@ export namespace HttpSchema { * {@link https://github.com/zimicjs/zimic/wiki/api‐zimic#jsonserialized `JSONSerialized`} if necessary. * * @example - * import { type HttpSchema } from 'zimic/http'; + * import { type HttpSchema } from '@zimic/http'; * * type UserListSuccessResponseBody = HttpSchema.Body; * @@ -472,7 +472,7 @@ export namespace HttpSchema { * necessary. * * @example - * import { type HttpSchema } from 'zimic/http'; + * import { type HttpSchema } from '@zimic/http'; * * type UserListHeaders = HttpSchema.Headers<{ * accept: 'application/json'; @@ -499,7 +499,7 @@ export namespace HttpSchema { * if necessary. * * @example - * import { type HttpSchema } from 'zimic/http'; + * import { type HttpSchema } from '@zimic/http'; * * type UserListSearchParams = HttpSchema.SearchParams<{ * limit: `${number}`; @@ -526,7 +526,7 @@ export namespace HttpSchema { * {@link HttpPathParamsSerialized} if necessary. * * @example - * import { type HttpSchema, InferPathParams } from 'zimic/http'; + * import { type HttpSchema, InferPathParams } from '@zimic/http'; * * type Schema = HttpSchema<{ * '/users/:userId': { @@ -553,7 +553,7 @@ export namespace HttpSchema { * necessary. * * @example - * import { HttpFormData, type HttpSchema } from 'zimic/http'; + * import { HttpFormData, type HttpSchema } from '@zimic/http'; * * type UserCreationFormData = HttpFormData< * HttpSchema.FormData<{ @@ -600,7 +600,7 @@ export type AllowAnyStringInPathParams = Path extends `${in * filter the paths with. Only the methods defined in the schema are allowed. * * @example - * import { type HttpSchema, type HttpSchemaPath } from 'zimic/http'; + * import { type HttpSchema, type HttpSchemaPath } from '@zimic/http'; * * type Schema = HttpSchema<{ * '/users': { @@ -633,7 +633,7 @@ export namespace HttpSchemaPath { * methods to filter the paths with. Only the methods defined in the schema are allowed. * * @example - * import { type HttpSchema, type HttpSchemaPath } from 'zimic/http'; + * import { type HttpSchema, type HttpSchemaPath } from '@zimic/http'; * * type Schema = HttpSchema<{ * '/users': { @@ -666,7 +666,7 @@ export namespace HttpSchemaPath { * methods to filter the paths with. Only the methods defined in the schema are allowed. * * @example - * import { type HttpSchema, type HttpSchemaPath } from 'zimic/http'; + * import { type HttpSchema, type HttpSchemaPath } from '@zimic/http'; * * type Schema = HttpSchema<{ * '/users': { @@ -744,7 +744,7 @@ type RecursiveInferPathParams = Path extends `${infer _Pref * schema. * * @example - * import { HttpSchema, InferPathParams } from 'zimic/http'; + * import { HttpSchema, InferPathParams } from '@zimic/http'; * * type MySchema = HttpSchema<{ * '/users/:userId': { @@ -759,7 +759,7 @@ type RecursiveInferPathParams = Path extends `${infer _Pref * // { userId: string } * * @example - * import { InferPathParams } from 'zimic/http'; + * import { InferPathParams } from '@zimic/http'; * * // Without using a schema to validate the path (works as `PathParamsSchemaFromPath`): * type PathParams = InferPathParams<'/users/:userId'>; @@ -800,7 +800,7 @@ type RecursiveMergeHttpResponsesByStatusCode< * first declaration takes precedence. * * @example - * import { type HttpSchema, type HttpStatusCode, MergeHttpResponsesByStatusCode } from 'zimic/http'; + * import { type HttpSchema, type HttpStatusCode, MergeHttpResponsesByStatusCode } from '@zimic/http'; * * // Overriding the 400 status code with a more specific schema * // and using a generic schema for all other client errors. diff --git a/packages/zimic-http/src/types/strings.d.ts b/packages/zimic-http/src/types/strings.d.ts new file mode 100644 index 00000000..078df4b8 --- /dev/null +++ b/packages/zimic-http/src/types/strings.d.ts @@ -0,0 +1,9 @@ +interface String { + // Using the original method signature style to correctly apply the overload. + // eslint-disable-next-line @typescript-eslint/method-signature-style + toLowerCase(): Lowercase; + + // Using the original method signature style to correctly apply the overload. + // eslint-disable-next-line @typescript-eslint/method-signature-style + toUpperCase(): Uppercase; +} diff --git a/packages/zimic-http/src/types/utils.ts b/packages/zimic-http/src/types/utils.ts new file mode 100644 index 00000000..6841b90c --- /dev/null +++ b/packages/zimic-http/src/types/utils.ts @@ -0,0 +1,64 @@ +export type Default = [undefined | void] extends [Type] + ? IfEmpty + : Exclude; + +export type DefaultNoExclude = [undefined | void] extends Type ? IfEmpty : Type; + +export type IfAny = 0 extends 1 & Type ? Yes : No; + +export type IfNever = [Type] extends [never] ? Yes : No; + +export type PossiblePromise = Type | PromiseLike; + +export type UnionToIntersection = (Union extends unknown ? (union: Union) => void : never) extends ( + intersectedUnion: infer IntersectedUnion, +) => void + ? IntersectedUnion + : never; + +type LastUnionType = + UnionToIntersection void : never> extends (x: infer LastType) => void + ? LastType + : never; + +export type UnionToTuple> = [Union] extends [never] + ? [] + : [...UnionToTuple>, LastType]; + +export type UnionHasMoreThanOneType = [UnionToIntersection] extends [never] ? true : false; + +export type Prettify = { + [Key in keyof Type]: Type[Key]; +}; + +export type ArrayItemIfArray = Type extends (infer Item)[] ? Item : Type; + +type PickArrayProperties = { + [Key in keyof Type as never[] extends Type[Key] ? Key : never]: Type[Key]; +}; + +export type ArrayKey = keyof PickArrayProperties; + +export type NonArrayKey = + string | number extends ArrayKey ? keyof Type : Exclude>; + +export type NonEmptyArray = [Type, ...Type[]]; + +export type ReplaceBy = Type extends Source ? Target : Type; + +export type Collection = Type[] | Set; + +export type DeepPartial = Type extends (...parameters: never[]) => unknown + ? Type + : Type extends (infer ArrayItem)[] + ? DeepPartial[] + : Type extends object + ? { [Key in keyof Type]?: DeepPartial } + : Type; + +export type Override = Omit & OverrideType; + +export interface Range { + min: Value; + max: Value; +} diff --git a/packages/zimic/src/utils/__tests__/strings.test.ts b/packages/zimic-http/src/utils/__tests__/strings.test.ts similarity index 100% rename from packages/zimic/src/utils/__tests__/strings.test.ts rename to packages/zimic-http/src/utils/__tests__/strings.test.ts diff --git a/packages/zimic/src/utils/__tests__/time.test.ts b/packages/zimic-http/src/utils/__tests__/time.test.ts similarity index 100% rename from packages/zimic/src/utils/__tests__/time.test.ts rename to packages/zimic-http/src/utils/__tests__/time.test.ts diff --git a/packages/zimic-http/src/utils/console.ts b/packages/zimic-http/src/utils/console.ts new file mode 100644 index 00000000..c263b57e --- /dev/null +++ b/packages/zimic-http/src/utils/console.ts @@ -0,0 +1,7 @@ +import chalk from 'chalk'; + +export function logWithPrefix(message: string, options: { method: 'log' | 'warn' | 'error' }) { + const { method } = options; + + console[method](chalk.cyan('[zimic]'), message); +} diff --git a/packages/zimic-http/src/utils/data.ts b/packages/zimic-http/src/utils/data.ts new file mode 100644 index 00000000..7d5a22cb --- /dev/null +++ b/packages/zimic-http/src/utils/data.ts @@ -0,0 +1,13 @@ +export async function blobEquals(blob: Blob, otherBlob: Blob) { + return ( + blob.type === otherBlob.type && blob.size === otherBlob.size && (await blob.text()) === (await otherBlob.text()) + ); +} + +export function isDefined(value: Value): value is NonNullable { + return value !== undefined && value !== null; +} + +export function isNonEmpty(value: Value): value is Exclude, ''> { + return isDefined(value) && value !== ''; +} diff --git a/packages/zimic-http/src/utils/files.ts b/packages/zimic-http/src/utils/files.ts new file mode 100644 index 00000000..3a2727a8 --- /dev/null +++ b/packages/zimic-http/src/utils/files.ts @@ -0,0 +1,28 @@ +import { blobEquals } from './data'; +import { createCachedDynamicImport } from './imports'; + +export const importBuffer = createCachedDynamicImport( + /* istanbul ignore next -- @preserve + * Ignoring as Node.js >=20 provides a global file and the buffer import won't run. */ + () => import('buffer'), +); + +let FileSingleton: typeof File | undefined; + +export async function importFile() { + /* istanbul ignore if -- @preserve + * Ignoring as this will only run if this function is called more than once. */ + if (FileSingleton) { + return FileSingleton; + } + + /* istanbul ignore next -- @preserve + * Ignoring as Node.js >=20 provides a global File and the import fallback won't run. */ + // eslint-disable-next-line @typescript-eslint/no-unnecessary-condition + FileSingleton = globalThis.File ?? (await importBuffer()).File; + return FileSingleton; +} + +export async function fileEquals(file: File, otherFile: File) { + return file.name === otherFile.name && (await blobEquals(file, otherFile)); +} diff --git a/packages/zimic-http/src/utils/imports.ts b/packages/zimic-http/src/utils/imports.ts new file mode 100644 index 00000000..e7a363ca --- /dev/null +++ b/packages/zimic-http/src/utils/imports.ts @@ -0,0 +1,12 @@ +export function createCachedDynamicImport( + importModuleDynamically: () => Promise, +): () => Promise { + let cachedImportResult: ImportType | undefined; + + return async function importModuleDynamicallyWithCache() { + if (cachedImportResult === undefined) { + cachedImportResult = await importModuleDynamically(); + } + return cachedImportResult; + }; +} diff --git a/packages/zimic/src/utils/prettier.ts b/packages/zimic-http/src/utils/prettier.ts similarity index 100% rename from packages/zimic/src/utils/prettier.ts rename to packages/zimic-http/src/utils/prettier.ts diff --git a/packages/zimic/src/utils/strings.ts b/packages/zimic-http/src/utils/strings.ts similarity index 100% rename from packages/zimic/src/utils/strings.ts rename to packages/zimic-http/src/utils/strings.ts diff --git a/packages/zimic-http/src/utils/time.ts b/packages/zimic-http/src/utils/time.ts new file mode 100644 index 00000000..66fee3ab --- /dev/null +++ b/packages/zimic-http/src/utils/time.ts @@ -0,0 +1,25 @@ +import { PossiblePromise } from '@/types/utils'; + +export async function usingElapsedTime(callback: () => PossiblePromise) { + const startTimeInMilliseconds = performance.now(); + + const result = await callback(); + + const endTimeInMilliseconds = performance.now(); + const elapsedTimeInMilliseconds = endTimeInMilliseconds - startTimeInMilliseconds; + + return { + startTime: startTimeInMilliseconds, + elapsedTime: elapsedTimeInMilliseconds, + endTime: endTimeInMilliseconds, + result, + }; +} + +export function formatElapsedTime(elapsedTimeInMilliseconds: number) { + if (elapsedTimeInMilliseconds < 1000) { + return `${elapsedTimeInMilliseconds.toFixed(0)}ms`; + } else { + return `${(elapsedTimeInMilliseconds / 1000).toFixed(2)}s`; + } +} diff --git a/packages/zimic-http/src/utils/urls.ts b/packages/zimic-http/src/utils/urls.ts new file mode 100644 index 00000000..5deaf9e5 --- /dev/null +++ b/packages/zimic-http/src/utils/urls.ts @@ -0,0 +1,52 @@ +export class InvalidURLError extends TypeError { + constructor(url: unknown) { + super(`Invalid URL: '${url}'`); + this.name = 'InvalidURL'; + } +} + +export interface ExtendedURL extends URL { + raw: string; +} + +function createURLOrThrow(rawURL: string | URL) { + try { + const url = new URL(rawURL) as ExtendedURL; + + Object.defineProperty(url, 'raw', { + value: rawURL.toString(), + writable: false, + enumerable: true, + configurable: false, + }); + + return url; + } catch { + throw new InvalidURLError(rawURL); + } +} + +export function createURL(rawURL: string | URL): ExtendedURL { + const url = createURLOrThrow(rawURL); + return url; +} + +export function createFileURL(filePath: string) { + return createURL(`file://${filePath}`); +} + +function prepareURLForRegex(url: string) { + const encodedURL = encodeURI(url); + return encodedURL.replace(/([.()*?+$\\])/g, '\\$1'); +} + +export function createRegexFromWildcardPath(path: string, options: { prefix: string }) { + const pathWithReplacedWildcards = prepareURLForRegex(path) + .replace(/^\/+|\/+$/g, '') + .replace(/\\\*/g, '*') + .replace(/\*\*\/\*/g, '**') + .replace(/(^|[^*])\*([^*]|$)/g, '$1[^/]*$2') + .replace(/\*\*/g, '.*'); + + return new RegExp(`^${options.prefix}/*${pathWithReplacedWildcards}/*$`); +} diff --git a/packages/zimic-http/tests/utils/console.ts b/packages/zimic-http/tests/utils/console.ts new file mode 100644 index 00000000..97ea09d3 --- /dev/null +++ b/packages/zimic-http/tests/utils/console.ts @@ -0,0 +1,30 @@ +import { MockInstance, vi } from 'vitest'; + +import { PossiblePromise } from '@/types/utils'; + +type IgnorableConsoleMethod = 'error' | 'warn' | 'info' | 'log' | 'debug'; + +type SpyByConsoleMethod = { + [Key in Method]: MockInstance; +}; + +export async function usingIgnoredConsole( + ignoredMethods: Method[], + callback: (spyByMethod: SpyByConsoleMethod) => PossiblePromise, +) { + const initialSpyByMethod = {} as SpyByConsoleMethod; + + const spyByMethod = ignoredMethods.reduce((groupedSpies, method) => { + const spy = vi.spyOn(console, method).mockImplementation(vi.fn()); + groupedSpies[method] = spy; + return groupedSpies; + }, initialSpyByMethod); + + try { + await callback(spyByMethod); + } finally { + for (const spy of Object.values(spyByMethod)) { + spy.mockRestore(); + } + } +} diff --git a/packages/zimic/tests/utils/json.ts b/packages/zimic-http/tests/utils/json.ts similarity index 100% rename from packages/zimic/tests/utils/json.ts rename to packages/zimic-http/tests/utils/json.ts diff --git a/packages/zimic-http/tsconfig.json b/packages/zimic-http/tsconfig.json new file mode 100644 index 00000000..3f5442ee --- /dev/null +++ b/packages/zimic-http/tsconfig.json @@ -0,0 +1,18 @@ +{ + "extends": "@zimic/tsconfig/tsconfig.node.json", + "compilerOptions": { + "lib": ["esnext", "dom", "dom.iterable"], + "target": "esnext", + "allowSyntheticDefaultImports": true, + "tsBuildInfoFile": "tsconfig.tsbuildinfo", + "baseUrl": ".", + "paths": { + "@/*": ["./src/*"], + "@tests/*": ["./tests/*"], + "@scripts/*": ["./scripts/*"], + "@@/package.json": ["./package.json"] + } + }, + "include": ["**/*.ts", "**/*.mts"], + "exclude": ["node_modules", "dist", "*.d.ts", "interceptor/*.d.ts", "http/*.d.ts", "**/fixtures/**/generated"] +} diff --git a/packages/zimic-http/tsup.config.ts b/packages/zimic-http/tsup.config.ts new file mode 100644 index 00000000..68d09fd4 --- /dev/null +++ b/packages/zimic-http/tsup.config.ts @@ -0,0 +1,58 @@ +import { Options, defineConfig } from 'tsup'; + +export function pickKeys(object: Type, keys: Key[]): Pick { + return keys.reduce( + (pickedObject, key) => { + pickedObject[key] = object[key]; + return pickedObject; + }, + {} as Pick, + ); +} + +const isDevelopment = process.env.npm_lifecycle_event === 'dev'; + +const sharedConfig: Options = { + bundle: true, + splitting: true, + sourcemap: true, + treeshake: true, + minify: false, + clean: true, + keepNames: true, + env: { + TYPEGEN_HTTP_IMPORT_MODULE: isDevelopment ? '@/index' : '@zimic/http', + }, +}; + +const neutralConfig = (['cjs', 'esm'] as const).map((format) => ({ + ...sharedConfig, + name: `neutral-${format}`, + platform: 'neutral', + format: [format], + dts: format === 'cjs', + entry: { + index: 'src/index.ts', + }, + external: ['buffer'], +})); + +const nodeConfig = (['cjs', 'esm'] as const).map((format) => { + const entry = { + typegen: 'src/typegen/index.ts', + cli: 'src/cli/index.ts', + }; + + const dtsEntry = pickKeys(entry, ['typegen']); + + return { + ...sharedConfig, + name: `node-${format}`, + platform: 'node', + format: [format], + dts: format === 'cjs' ? { entry: dtsEntry } : false, + entry, + }; +}); + +export default defineConfig([...neutralConfig, ...nodeConfig]); diff --git a/packages/zimic-http/turbo.json b/packages/zimic-http/turbo.json new file mode 100644 index 00000000..ac784ac4 --- /dev/null +++ b/packages/zimic-http/turbo.json @@ -0,0 +1,31 @@ +{ + "$schema": "https://turbo.build/schema.json", + "extends": ["//"], + "tasks": { + "build": { + "inputs": [ + "{src,scripts}/**/*.{ts,json}", + "{package,tsconfig}.json", + "tsup.config.ts", + "!scripts/**/*", + "!*/**/tests/**/*", + "!*/**/__tests__/**/*", + "!*/**/*.test.ts" + ], + "outputs": ["dist/**"] + }, + + "test:turbo": { + "dependsOn": ["^build"], + "inputs": ["{src,tests}/**/*.{ts,json}", "{package,tsconfig}.json", "vitest.config.mts"] + }, + + "lint:turbo": { + "inputs": ["{src,tests}/**/*.{ts,json}", "{package,tsconfig}.json", "eslint.config.mjs"] + }, + + "types:check": { + "inputs": ["{src,tests}/**/*.{ts,json}", "{package,tsconfig}.json"] + } + } +} diff --git a/packages/zimic/typegen.d.ts b/packages/zimic-http/typegen.d.ts similarity index 100% rename from packages/zimic/typegen.d.ts rename to packages/zimic-http/typegen.d.ts diff --git a/packages/zimic-http/vitest.config.mts b/packages/zimic-http/vitest.config.mts new file mode 100644 index 00000000..aeacae27 --- /dev/null +++ b/packages/zimic-http/vitest.config.mts @@ -0,0 +1,55 @@ +import path from 'path'; +import { defineConfig } from 'vitest/config'; + +export default defineConfig({ + publicDir: './public', + test: { + globals: false, + testTimeout: 5000, + hookTimeout: 5000, + retry: process.env.CI === 'true' ? 1 : 0, + maxWorkers: process.env.CI === 'true' ? '100%' : '50%', + minWorkers: 1, + clearMocks: true, + coverage: { + provider: 'istanbul', + reporter: ['text', 'html'], + reportsDirectory: './tests/coverage', + thresholds: { + functions: 100, + lines: 100, + statements: 100, + branches: 100, + }, + exclude: [ + '**/node_modules/**', + 'local/**', + 'public/**', + 'dist/**', + 'tests/coverage/**', + 'scripts/**', + '**/types/**', + '**/{*.d.ts,types,typescript}.ts', + '**/.lintstagedrc.js', + '**/eslint.config.mjs', + '**/vitest.{config,workspace}.*', + '**/tsup.config.*', + ], + }, + }, + define: { + 'process.env.TYPEGEN_HTTP_IMPORT_MODULE': "'@/index'", + }, + resolve: { + alias: { + '@': path.resolve(__dirname, './src'), + '@tests': path.resolve(__dirname, './tests'), + '@scripts': path.resolve(__dirname, './scripts'), + '@@': path.resolve(__dirname, '.'), + }, + }, + optimizeDeps: { + include: ['@vitest/coverage-istanbul'], + }, + plugins: [], +}); diff --git a/packages/zimic-http/vitest.workspace.mts b/packages/zimic-http/vitest.workspace.mts new file mode 100644 index 00000000..50de11b0 --- /dev/null +++ b/packages/zimic-http/vitest.workspace.mts @@ -0,0 +1,30 @@ +import { defineWorkspace } from 'vitest/config'; + +export default defineWorkspace([ + { + extends: 'vitest.config.mts', + test: { + name: 'node', + environment: 'node', + include: ['./{src,tests,scripts}/**/*.test.ts', './{src,tests,scripts}/**/*.node.test.ts'], + exclude: ['**/*.browser.test.ts'], + }, + }, + + { + extends: 'vitest.config.mts', + test: { + name: 'browser', + environment: undefined, + include: ['./{src,tests,scripts}/**/*.test.ts', './{src,tests,scripts}/**/*.browser.test.ts'], + exclude: ['**/*.node.test.ts'], + browser: { + instances: [{ browser: 'chromium' }], + provider: 'playwright', + enabled: true, + headless: true, + screenshotFailures: false, + }, + }, + }, +]); diff --git a/packages/zimic/http.d.ts b/packages/zimic/http.d.ts deleted file mode 100644 index 4050a4a0..00000000 --- a/packages/zimic/http.d.ts +++ /dev/null @@ -1 +0,0 @@ -export * from './dist/http'; diff --git a/packages/zimic/package.json b/packages/zimic/package.json index 04604581..81da3983 100644 --- a/packages/zimic/package.json +++ b/packages/zimic/package.json @@ -39,10 +39,8 @@ "!src/**/*.test.ts", "dist", "index.d.ts", - "http.d.ts", "interceptor/http.d.ts", - "interceptor/server.d.ts", - "typegen.d.ts" + "interceptor/server.d.ts" ], "main": "./dist/index.js", "module": "./dist/index.mjs", @@ -57,12 +55,6 @@ "require": "./dist/index.js", "default": "./dist/index.js" }, - "./http": { - "types": "./dist/http.d.ts", - "import": "./dist/http.mjs", - "require": "./dist/http.js", - "default": "./dist/http.js" - }, "./interceptor/http": { "types": "./dist/interceptor/http.d.ts", "import": "./dist/interceptor/http.mjs", @@ -75,12 +67,6 @@ "require": "./dist/interceptor/server.js", "default": "./dist/interceptor/server.js" }, - "./typegen": { - "types": "./dist/typegen.d.ts", - "import": "./dist/typegen.mjs", - "require": "./dist/typegen.js", - "default": "./dist/typegen.js" - }, "./fetch": { "types": "./dist/fetch.d.ts", "import": "./dist/fetch.mjs", @@ -93,7 +79,7 @@ "dev": "tsup --watch", "cli": "node ./dist/cli.js", "build": "tsup", - "lint": "eslint --cache --no-error-on-unmatched-pattern --fix", + "lint": "eslint --cache --no-error-on-unmatched-pattern --no-warn-ignored --fix", "lint:turbo": "pnpm lint . --max-warnings 0", "style": "prettier --log-level warn --ignore-unknown --no-error-on-unmatched-pattern --cache", "style:check": "pnpm style --check", @@ -101,7 +87,6 @@ "test": "dotenv -v NODE_ENV=test -- vitest", "test:turbo": "dotenv -v CI=true -- pnpm run test run --coverage", "types:check": "tsc --noEmit", - "typegen:fixtures": "tsx ./scripts/dev/typegen/generateFixtureTypes.js", "deps:install-playwright": "playwright install chromium", "deps:init-msw": "msw init ./public --no-save", "deps:init": "pnpm deps:install-playwright && pnpm deps:init-msw", @@ -115,7 +100,6 @@ "execa": "9.5.2", "isomorphic-ws": "5.0.0", "msw": "2.7.0", - "openapi-typescript": "7.6.1", "ws": "8.18.0", "yargs": "17.7.2" }, @@ -123,27 +107,25 @@ "bufferutil": "4.0.9" }, "devDependencies": { - "@types/cross-spawn": "^6.0.6", - "@types/js-yaml": "^4.0.9", "@types/node": "^22.13.4", "@types/ws": "^8.5.14", "@types/yargs": "^17.0.33", "@vitest/browser": "^3.0.5", "@vitest/coverage-istanbul": "^3.0.5", "@zimic/eslint-config-node": "workspace:*", + "@zimic/http": "workspace:*", "@zimic/lint-staged-config": "workspace:*", "@zimic/tsconfig": "workspace:*", "dotenv-cli": "^8.0.0", "eslint": "^9.20.1", - "js-yaml": "^4.1.0", "playwright": "^1.50.1", - "prettier": "^3.5.1", "tsup": "^8.3.6", "tsx": "^4.19.2", "typescript": "^5.7.3", "vitest": "^3.0.5" }, "peerDependencies": { + "@zimic/http": "^0.0.0", "typescript": ">=4.8.0" }, "peerDependenciesMeta": { diff --git a/packages/zimic/scripts/dev/utils/console.ts b/packages/zimic/scripts/dev/utils/console.ts deleted file mode 100644 index 5817c860..00000000 --- a/packages/zimic/scripts/dev/utils/console.ts +++ /dev/null @@ -1,14 +0,0 @@ -import { PossiblePromise } from '@/types/utils'; - -export async function usingConsoleTime( - label: string, - callback: () => PossiblePromise, -): Promise { - console.time(label); - - try { - return await callback(); - } finally { - console.timeEnd(label); - } -} diff --git a/packages/zimic/src/cli/__tests__/cli.node.test.ts b/packages/zimic/src/cli/__tests__/cli.node.test.ts index 9be3b6ee..174d43a0 100644 --- a/packages/zimic/src/cli/__tests__/cli.node.test.ts +++ b/packages/zimic/src/cli/__tests__/cli.node.test.ts @@ -15,7 +15,6 @@ describe('CLI', () => { 'Commands:', ' zimic browser Manage your browser mock configuration', ' zimic server Manage interceptor servers', - ' zimic typegen Generate types from schema sources', '', 'Options:', ' --help Show help [boolean]', diff --git a/packages/zimic/src/cli/cli.ts b/packages/zimic/src/cli/cli.ts index 4828e97e..4b9b63d9 100644 --- a/packages/zimic/src/cli/cli.ts +++ b/packages/zimic/src/cli/cli.ts @@ -5,7 +5,6 @@ import { version } from '@@/package.json'; import initializeBrowserServiceWorker from './browser/init'; import startInterceptorServer from './server/start'; -import generateTypesFromOpenAPI from './typegen/openapi'; async function runCLI() { await yargs(hideBin(process.argv)) @@ -90,80 +89,6 @@ async function runCLI() { ), ) - .command('typegen', 'Generate types from schema sources', (yargs) => - yargs.demandCommand().command( - 'openapi ', - 'Generate types from an OpenAPI schema.', - (yargs) => - yargs - .positional('input', { - type: 'string', - description: - 'The path to a local OpenAPI schema file or an URL to fetch it. ' + - 'Version 3 is supported as YAML or JSON.', - demandOption: true, - }) - .option('output', { - type: 'string', - description: - 'The path to write the generated types to. If not provided, the types will be written to stdout.', - alias: 'o', - }) - .option('service-name', { - type: 'string', - description: 'The name of the service to use in the generated types.', - alias: 's', - demandOption: true, - }) - .option('comments', { - type: 'boolean', - description: 'Whether to include comments in the generated types.', - alias: 'c', - default: true, - }) - .option('prune', { - type: 'boolean', - description: - 'Whether to remove unused operations and components from the generated types. This is useful for ' + - 'reducing the size of the output file.', - alias: 'p', - default: true, - }) - .option('filter', { - type: 'string', - array: true, - description: - 'One or more expressions to filter the types to generate. Filters must follow the format ' + - '` `, where `` is an HTTP method or `*`, and `` is a literal path or a ' + - 'glob. Filters are case-sensitive regarding paths. For example, `GET /users`, `* /users`, ' + - '`GET /users/*`, and `GET /users/**/*` are valid filters. Negative filters can be created by ' + - 'prefixing the expression with `!`. For example, `!GET /users` will exclude paths matching ' + - '`GET /users`. If more than one positive filter is provided, they will be combined with OR, while ' + - 'negative filters will be combined with AND.', - alias: 'f', - }) - .option('filter-file', { - type: 'string', - description: - 'A path to a file containing filter expressions. One expression is expected per line and the format ' + - 'is the same as used in a `--filter` option. Comments are prefixed with `#`. A filter file can be ' + - 'used alongside additional `--filter` expressions.', - alias: 'F', - }), - async (cliArguments) => { - await generateTypesFromOpenAPI({ - input: cliArguments.input, - output: cliArguments.output, - serviceName: cliArguments.serviceName, - includeComments: cliArguments.comments, - prune: cliArguments.prune, - filters: cliArguments.filter, - filterFile: cliArguments.filterFile, - }); - }, - ), - ) - .parse(); } diff --git a/packages/zimic/src/cli/server/__tests__/server.node.test.ts b/packages/zimic/src/cli/server/__tests__/server.node.test.ts index f377e5a2..16f790ff 100644 --- a/packages/zimic/src/cli/server/__tests__/server.node.test.ts +++ b/packages/zimic/src/cli/server/__tests__/server.node.test.ts @@ -137,7 +137,7 @@ describe('CLI (server)', async () => { }); it('should start the server on localhost if no hostname is provided', async () => { - processArgvSpy.mockReturnValue(['node', './dist/cli.js', 'server', 'start', '--port', '5000']); + processArgvSpy.mockReturnValue(['node', './dist/cli.js', 'server', 'start', '--port', '6500']); await usingIgnoredConsole(['log'], async (spies) => { await runCLI(); @@ -145,10 +145,10 @@ describe('CLI (server)', async () => { expect(server).toBeDefined(); expect(server!.isRunning()).toBe(true); expect(server!.hostname()).toBe('localhost'); - expect(server!.port()).toBe(5000); + expect(server!.port()).toBe(6500); expect(spies.log).toHaveBeenCalledTimes(1); - expect(spies.log).toHaveBeenCalledWith(chalk.cyan('[zimic]'), 'Server is running on http://localhost:5000'); + expect(spies.log).toHaveBeenCalledWith(chalk.cyan('[zimic]'), 'Server is running on http://localhost:6500'); }); }); diff --git a/packages/zimic/src/fetch/FetchClient.ts b/packages/zimic/src/fetch/FetchClient.ts index 20d79b1e..06b83ff8 100644 --- a/packages/zimic/src/fetch/FetchClient.ts +++ b/packages/zimic/src/fetch/FetchClient.ts @@ -1,5 +1,11 @@ -import { HttpSchema, HttpSchemaPath, HttpSchemaMethod, HttpSearchParams } from '@/http'; -import { LiteralHttpSchemaPathFromNonLiteral } from '@/http/types/schema'; +import { + HttpSchemaPath, + HttpSchemaMethod, + HttpSearchParams, + LiteralHttpSchemaPathFromNonLiteral, + HttpSchema, +} from '@zimic/http'; + import { Default } from '@/types/utils'; import { createRegexFromURL, excludeNonPathParams, joinURL } from '@/utils/urls'; diff --git a/packages/zimic/src/fetch/__tests__/FetchClient.bodies.blob.test.ts b/packages/zimic/src/fetch/__tests__/FetchClient.bodies.blob.test.ts index 6fc5b3d5..adb03f29 100644 --- a/packages/zimic/src/fetch/__tests__/FetchClient.bodies.blob.test.ts +++ b/packages/zimic/src/fetch/__tests__/FetchClient.bodies.blob.test.ts @@ -1,6 +1,6 @@ +import { HttpSchema, StrictHeaders } from '@zimic/http'; import { describe, expect, expectTypeOf, it } from 'vitest'; -import { HttpSchema, StrictHeaders } from '@/http'; import { joinURL } from '@/utils/urls'; import { usingHttpInterceptor } from '@tests/utils/interceptors'; diff --git a/packages/zimic/src/fetch/__tests__/FetchClient.bodies.formData.test.ts b/packages/zimic/src/fetch/__tests__/FetchClient.bodies.formData.test.ts index 3a2a23a0..09e10275 100644 --- a/packages/zimic/src/fetch/__tests__/FetchClient.bodies.formData.test.ts +++ b/packages/zimic/src/fetch/__tests__/FetchClient.bodies.formData.test.ts @@ -1,6 +1,6 @@ +import { HttpFormData, HttpSchema, StrictFormData, StrictHeaders } from '@zimic/http'; import { describe, expect, expectTypeOf, it } from 'vitest'; -import { HttpFormData, HttpSchema, StrictFormData, StrictHeaders } from '@/http'; import { importFile } from '@/utils/files'; import { joinURL } from '@/utils/urls'; import { usingHttpInterceptor } from '@tests/utils/interceptors'; diff --git a/packages/zimic/src/fetch/__tests__/FetchClient.bodies.json.test.ts b/packages/zimic/src/fetch/__tests__/FetchClient.bodies.json.test.ts index 573ee90a..72e76f57 100644 --- a/packages/zimic/src/fetch/__tests__/FetchClient.bodies.json.test.ts +++ b/packages/zimic/src/fetch/__tests__/FetchClient.bodies.json.test.ts @@ -1,6 +1,6 @@ +import { HttpSchema, StrictHeaders } from '@zimic/http'; import { describe, expect, expectTypeOf, it } from 'vitest'; -import { HttpSchema, StrictHeaders } from '@/http'; import { joinURL } from '@/utils/urls'; import { usingHttpInterceptor } from '@tests/utils/interceptors'; diff --git a/packages/zimic/src/fetch/__tests__/FetchClient.bodies.plainText.test.ts b/packages/zimic/src/fetch/__tests__/FetchClient.bodies.plainText.test.ts index 7baee101..1f432b5d 100644 --- a/packages/zimic/src/fetch/__tests__/FetchClient.bodies.plainText.test.ts +++ b/packages/zimic/src/fetch/__tests__/FetchClient.bodies.plainText.test.ts @@ -1,6 +1,6 @@ +import { HttpSchema, StrictHeaders } from '@zimic/http'; import { describe, expect, expectTypeOf, it } from 'vitest'; -import { HttpSchema, StrictHeaders } from '@/http'; import { joinURL } from '@/utils/urls'; import { usingHttpInterceptor } from '@tests/utils/interceptors'; diff --git a/packages/zimic/src/fetch/__tests__/FetchClient.bodies.searchParams.test.ts b/packages/zimic/src/fetch/__tests__/FetchClient.bodies.searchParams.test.ts index b0275ffc..bf470a08 100644 --- a/packages/zimic/src/fetch/__tests__/FetchClient.bodies.searchParams.test.ts +++ b/packages/zimic/src/fetch/__tests__/FetchClient.bodies.searchParams.test.ts @@ -1,6 +1,6 @@ +import { HttpSchema, HttpSearchParams, StrictFormData, StrictHeaders } from '@zimic/http'; import { describe, expect, expectTypeOf, it } from 'vitest'; -import { HttpSchema, HttpSearchParams, StrictFormData, StrictHeaders } from '@/http'; import { joinURL } from '@/utils/urls'; import { usingHttpInterceptor } from '@tests/utils/interceptors'; diff --git a/packages/zimic/src/fetch/__tests__/FetchClient.bodies.test.ts b/packages/zimic/src/fetch/__tests__/FetchClient.bodies.test.ts index 4446c0e3..4b9595ec 100644 --- a/packages/zimic/src/fetch/__tests__/FetchClient.bodies.test.ts +++ b/packages/zimic/src/fetch/__tests__/FetchClient.bodies.test.ts @@ -1,6 +1,6 @@ +import { HttpSchema } from '@zimic/http'; import { describe, it } from 'vitest'; -import { HttpSchema } from '@/http'; import { usingHttpInterceptor } from '@tests/utils/interceptors'; import createFetch from '../factory'; diff --git a/packages/zimic/src/fetch/__tests__/FetchClient.defaults.test.ts b/packages/zimic/src/fetch/__tests__/FetchClient.defaults.test.ts index 8cb1db27..e454c97e 100644 --- a/packages/zimic/src/fetch/__tests__/FetchClient.defaults.test.ts +++ b/packages/zimic/src/fetch/__tests__/FetchClient.defaults.test.ts @@ -1,6 +1,6 @@ import { describe, expect, expectTypeOf, it } from 'vitest'; +import { HttpSchema } from '@zimic/http'; -import { HttpSchema } from '@/http'; import { joinURL } from '@/utils/urls'; import { usingHttpInterceptor } from '@tests/utils/interceptors'; diff --git a/packages/zimic/src/fetch/__tests__/FetchClient.errors.test.ts b/packages/zimic/src/fetch/__tests__/FetchClient.errors.test.ts index 1d69429f..96f7ea0f 100644 --- a/packages/zimic/src/fetch/__tests__/FetchClient.errors.test.ts +++ b/packages/zimic/src/fetch/__tests__/FetchClient.errors.test.ts @@ -1,6 +1,6 @@ +import { HttpSchema } from '@zimic/http'; import { describe, expect, expectTypeOf, it } from 'vitest'; -import { HttpSchema } from '@/http'; import { joinURL } from '@/utils/urls'; import { usingHttpInterceptor } from '@tests/utils/interceptors'; diff --git a/packages/zimic/src/fetch/__tests__/FetchClient.headers.test.ts b/packages/zimic/src/fetch/__tests__/FetchClient.headers.test.ts index 380ed025..ace3e66e 100644 --- a/packages/zimic/src/fetch/__tests__/FetchClient.headers.test.ts +++ b/packages/zimic/src/fetch/__tests__/FetchClient.headers.test.ts @@ -1,6 +1,6 @@ +import { HttpSchema, StrictHeaders, HttpHeaders } from '@zimic/http'; import { describe, expect, expectTypeOf, it } from 'vitest'; -import { HttpSchema, StrictHeaders, HttpHeaders } from '@/http'; import { joinURL } from '@/utils/urls'; import { usingHttpInterceptor } from '@tests/utils/interceptors'; diff --git a/packages/zimic/src/fetch/__tests__/FetchClient.listeners.test.ts b/packages/zimic/src/fetch/__tests__/FetchClient.listeners.test.ts index 6a52a279..4752079b 100644 --- a/packages/zimic/src/fetch/__tests__/FetchClient.listeners.test.ts +++ b/packages/zimic/src/fetch/__tests__/FetchClient.listeners.test.ts @@ -1,6 +1,6 @@ +import { HttpHeaders, HttpSchema, HttpSearchParams, StrictHeaders } from '@zimic/http'; import { describe, expect, expectTypeOf, it, vi } from 'vitest'; -import { HttpHeaders, HttpSchema, HttpSearchParams, StrictHeaders } from '@/http'; import { Default } from '@/types/utils'; import { joinURL } from '@/utils/urls'; import { expectFetchError } from '@tests/utils/fetch'; diff --git a/packages/zimic/src/fetch/__tests__/FetchClient.methods.test.ts b/packages/zimic/src/fetch/__tests__/FetchClient.methods.test.ts index 5c9de022..56fc3972 100644 --- a/packages/zimic/src/fetch/__tests__/FetchClient.methods.test.ts +++ b/packages/zimic/src/fetch/__tests__/FetchClient.methods.test.ts @@ -1,6 +1,6 @@ +import { HttpSchema, StrictHeaders } from '@zimic/http'; import { describe, expect, expectTypeOf, it } from 'vitest'; -import { HttpSchema, StrictHeaders } from '@/http'; import { joinURL } from '@/utils/urls'; import { usingHttpInterceptor } from '@tests/utils/interceptors'; diff --git a/packages/zimic/src/fetch/__tests__/FetchClient.pathParams.test.ts b/packages/zimic/src/fetch/__tests__/FetchClient.pathParams.test.ts index b00edb61..49c7947c 100644 --- a/packages/zimic/src/fetch/__tests__/FetchClient.pathParams.test.ts +++ b/packages/zimic/src/fetch/__tests__/FetchClient.pathParams.test.ts @@ -1,6 +1,6 @@ +import { HttpSchema } from '@zimic/http'; import { describe, expect, expectTypeOf, it } from 'vitest'; -import { HttpSchema } from '@/http'; import { joinURL } from '@/utils/urls'; import { usingHttpInterceptor } from '@tests/utils/interceptors'; diff --git a/packages/zimic/src/fetch/__tests__/FetchClient.searchParams.test.ts b/packages/zimic/src/fetch/__tests__/FetchClient.searchParams.test.ts index 65db61ca..7a4ccf7f 100644 --- a/packages/zimic/src/fetch/__tests__/FetchClient.searchParams.test.ts +++ b/packages/zimic/src/fetch/__tests__/FetchClient.searchParams.test.ts @@ -1,6 +1,6 @@ +import { HttpSchema, HttpSearchParams } from '@zimic/http'; import { describe, expect, expectTypeOf, it } from 'vitest'; -import { HttpSchema, HttpSearchParams } from '@/http'; import { joinURL } from '@/utils/urls'; import { usingHttpInterceptor } from '@tests/utils/interceptors'; diff --git a/packages/zimic/src/fetch/__tests__/FetchClient.types.test.ts b/packages/zimic/src/fetch/__tests__/FetchClient.types.test.ts index 2f415813..253f72d2 100644 --- a/packages/zimic/src/fetch/__tests__/FetchClient.types.test.ts +++ b/packages/zimic/src/fetch/__tests__/FetchClient.types.test.ts @@ -1,6 +1,6 @@ +import { HttpSchema, MergeHttpResponsesByStatusCode } from '@zimic/http'; import { describe, expect, expectTypeOf, it } from 'vitest'; -import { HttpSchema, MergeHttpResponsesByStatusCode } from '@/http'; import { joinURL } from '@/utils/urls'; import { usingHttpInterceptor } from '@tests/utils/interceptors'; diff --git a/packages/zimic/src/fetch/errors/FetchResponseError.ts b/packages/zimic/src/fetch/errors/FetchResponseError.ts index 4f6027dc..953fe5af 100644 --- a/packages/zimic/src/fetch/errors/FetchResponseError.ts +++ b/packages/zimic/src/fetch/errors/FetchResponseError.ts @@ -1,4 +1,4 @@ -import { HttpMethod, HttpMethodSchema } from '@/http'; +import { HttpMethod, HttpMethodSchema } from '@zimic/http'; import { FetchRequest, FetchResponse } from '../types/requests'; diff --git a/packages/zimic/src/fetch/factory.ts b/packages/zimic/src/fetch/factory.ts index 8b92dfcc..7aa39400 100644 --- a/packages/zimic/src/fetch/factory.ts +++ b/packages/zimic/src/fetch/factory.ts @@ -1,13 +1,12 @@ -import { HttpSchema } from '@/http'; -import { ConvertToStrictHttpSchema } from '@/http/types/schema'; +import { HttpSchema } from '@zimic/http'; import FetchClient from './FetchClient'; import { FetchOptions, Fetch as PublicFetch } from './types/public'; function createFetch( - options: FetchOptions>, -): PublicFetch> { - const { fetch } = new FetchClient>(options); + options: FetchOptions>, +): PublicFetch> { + const { fetch } = new FetchClient>(options); return fetch; } diff --git a/packages/zimic/src/fetch/types/public.ts b/packages/zimic/src/fetch/types/public.ts index 4ff3168b..5b09eb26 100644 --- a/packages/zimic/src/fetch/types/public.ts +++ b/packages/zimic/src/fetch/types/public.ts @@ -1,5 +1,5 @@ -import { HttpSchema, HttpSchemaPath, HttpSchemaMethod } from '@/http'; -import { LiteralHttpSchemaPathFromNonLiteral } from '@/http/types/schema'; +import { HttpSchemaPath, HttpSchemaMethod, LiteralHttpSchemaPathFromNonLiteral, HttpSchema } from '@zimic/http'; + import { Default, PossiblePromise } from '@/types/utils'; import FetchResponseError from '../errors/FetchResponseError'; diff --git a/packages/zimic/src/fetch/types/requests.ts b/packages/zimic/src/fetch/types/requests.ts index e0bacfec..26844f83 100644 --- a/packages/zimic/src/fetch/types/requests.ts +++ b/packages/zimic/src/fetch/types/requests.ts @@ -11,8 +11,10 @@ import { HttpRequest, HttpSearchParams, HttpHeaders, -} from '@/http'; -import { AllowAnyStringInPathParams, LiteralHttpSchemaPathFromNonLiteral } from '@/http/types/schema'; + AllowAnyStringInPathParams, + LiteralHttpSchemaPathFromNonLiteral, +} from '@zimic/http'; + import { HttpResponseBodySchema, HttpRequestBodySchema, diff --git a/packages/zimic/src/index.ts b/packages/zimic/src/index.ts index 5ba3abc6..cb0ff5c3 100644 --- a/packages/zimic/src/index.ts +++ b/packages/zimic/src/index.ts @@ -1,2 +1 @@ -export { default as InvalidJSONError } from './errors/InvalidJSONError'; -export type { JSONValue, JSONSerialized } from './types/json'; +export {}; diff --git a/packages/zimic/src/interceptor/http/index.ts b/packages/zimic/src/interceptor/http/index.ts index 5750bd12..5f4320e6 100644 --- a/packages/zimic/src/interceptor/http/index.ts +++ b/packages/zimic/src/interceptor/http/index.ts @@ -1,5 +1,7 @@ import HttpInterceptorNamespace from './namespace/HttpInterceptorNamespace'; +export { default as InvalidJSONError } from './interceptorWorker/errors/InvalidJSONError'; +export { default as InvalidFormDataError } from './interceptorWorker/errors/InvalidFormDataError'; export { default as NotStartedHttpInterceptorError } from './interceptor/errors/NotStartedHttpInterceptorError'; export { default as UnknownHttpInterceptorPlatformError } from './interceptor/errors/UnknownHttpInterceptorPlatformError'; export { default as UnknownHttpInterceptorTypeError } from './interceptor/errors/UnknownHttpInterceptorTypeError'; diff --git a/packages/zimic/src/interceptor/http/interceptor/HttpInterceptorClient.ts b/packages/zimic/src/interceptor/http/interceptor/HttpInterceptorClient.ts index cb53d47b..d8073f9f 100644 --- a/packages/zimic/src/interceptor/http/interceptor/HttpInterceptorClient.ts +++ b/packages/zimic/src/interceptor/http/interceptor/HttpInterceptorClient.ts @@ -1,12 +1,13 @@ -import { HttpResponse } from '@/http'; import { + HttpResponse, HTTP_METHODS, HttpMethod, - HttpSchema, HttpSchemaMethod, HttpSchemaPath, HttpStatusCode, -} from '@/http/types/schema'; + HttpSchema, +} from '@zimic/http'; + import { Default, PossiblePromise } from '@/types/utils'; import { joinURL, ExtendedURL, createRegexFromURL } from '@/utils/urls'; diff --git a/packages/zimic/src/interceptor/http/interceptor/LocalHttpInterceptor.ts b/packages/zimic/src/interceptor/http/interceptor/LocalHttpInterceptor.ts index 69dae0a5..8725615a 100644 --- a/packages/zimic/src/interceptor/http/interceptor/LocalHttpInterceptor.ts +++ b/packages/zimic/src/interceptor/http/interceptor/LocalHttpInterceptor.ts @@ -1,4 +1,5 @@ -import { HttpSchema, HttpSchemaMethod, HttpSchemaPath } from '@/http/types/schema'; +import { HttpSchema, HttpSchemaMethod, HttpSchemaPath } from '@zimic/http'; + import { createURL } from '@/utils/urls'; import LocalHttpRequestHandler from '../requestHandler/LocalHttpRequestHandler'; diff --git a/packages/zimic/src/interceptor/http/interceptor/RemoteHttpInterceptor.ts b/packages/zimic/src/interceptor/http/interceptor/RemoteHttpInterceptor.ts index ccc84e8c..7af1a8e9 100644 --- a/packages/zimic/src/interceptor/http/interceptor/RemoteHttpInterceptor.ts +++ b/packages/zimic/src/interceptor/http/interceptor/RemoteHttpInterceptor.ts @@ -1,4 +1,5 @@ -import { HttpSchema, HttpSchemaMethod, HttpSchemaPath } from '@/http/types/schema'; +import { HttpSchema, HttpSchemaMethod, HttpSchemaPath } from '@zimic/http'; + import { createURL } from '@/utils/urls'; import RemoteHttpRequestHandler from '../requestHandler/RemoteHttpRequestHandler'; diff --git a/packages/zimic/src/interceptor/http/interceptor/__tests__/shared/bodies/blob.ts b/packages/zimic/src/interceptor/http/interceptor/__tests__/shared/bodies/blob.ts index c4a9539d..c79107ad 100644 --- a/packages/zimic/src/interceptor/http/interceptor/__tests__/shared/bodies/blob.ts +++ b/packages/zimic/src/interceptor/http/interceptor/__tests__/shared/bodies/blob.ts @@ -1,7 +1,6 @@ +import { HttpRequest, HttpResponse, HTTP_METHODS_WITH_REQUEST_BODY, HttpSchema } from '@zimic/http'; import { beforeEach, describe, expect, expectTypeOf, it } from 'vitest'; -import { HttpRequest, HttpResponse } from '@/http/types/requests'; -import { HTTP_METHODS_WITH_REQUEST_BODY, HttpSchema } from '@/http/types/schema'; import { promiseIfRemote } from '@/interceptor/http/interceptorWorker/__tests__/utils/promises'; import LocalHttpRequestHandler from '@/interceptor/http/requestHandler/LocalHttpRequestHandler'; import RemoteHttpRequestHandler from '@/interceptor/http/requestHandler/RemoteHttpRequestHandler'; diff --git a/packages/zimic/src/interceptor/http/interceptor/__tests__/shared/bodies/formData.ts b/packages/zimic/src/interceptor/http/interceptor/__tests__/shared/bodies/formData.ts index 4b105519..bc450677 100644 --- a/packages/zimic/src/interceptor/http/interceptor/__tests__/shared/bodies/formData.ts +++ b/packages/zimic/src/interceptor/http/interceptor/__tests__/shared/bodies/formData.ts @@ -1,10 +1,15 @@ +import { + HTTP_METHODS_WITH_REQUEST_BODY, + HttpSchema, + HttpFormData, + HttpRequest, + HttpResponse, + StrictFormData, +} from '@zimic/http'; import { beforeEach, describe, expect, expectTypeOf, it } from 'vitest'; -import InvalidFormDataError from '@/http/errors/InvalidFormDataError'; -import HttpFormData from '@/http/formData/HttpFormData'; -import { HttpRequest, HttpResponse, StrictFormData } from '@/http/types/requests'; -import { HTTP_METHODS_WITH_REQUEST_BODY, HttpSchema } from '@/http/types/schema'; import { promiseIfRemote } from '@/interceptor/http/interceptorWorker/__tests__/utils/promises'; +import InvalidFormDataError from '@/interceptor/http/interceptorWorker/errors/InvalidFormDataError'; import LocalHttpRequestHandler from '@/interceptor/http/requestHandler/LocalHttpRequestHandler'; import RemoteHttpRequestHandler from '@/interceptor/http/requestHandler/RemoteHttpRequestHandler'; import { importCrypto } from '@/utils/crypto'; diff --git a/packages/zimic/src/interceptor/http/interceptor/__tests__/shared/bodies/json.ts b/packages/zimic/src/interceptor/http/interceptor/__tests__/shared/bodies/json.ts index 03ccb8d5..9fa6b619 100644 --- a/packages/zimic/src/interceptor/http/interceptor/__tests__/shared/bodies/json.ts +++ b/packages/zimic/src/interceptor/http/interceptor/__tests__/shared/bodies/json.ts @@ -1,9 +1,8 @@ +import { HTTP_METHODS_WITH_REQUEST_BODY, HttpSchema, HttpRequest, HttpResponse } from '@zimic/http'; import { beforeEach, describe, expect, expectTypeOf, it } from 'vitest'; -import InvalidJSONError from '@/errors/InvalidJSONError'; -import { HttpRequest, HttpResponse } from '@/http/types/requests'; -import { HTTP_METHODS_WITH_REQUEST_BODY, HttpSchema } from '@/http/types/schema'; import { promiseIfRemote } from '@/interceptor/http/interceptorWorker/__tests__/utils/promises'; +import InvalidJSONError from '@/interceptor/http/interceptorWorker/errors/InvalidJSONError'; import LocalHttpRequestHandler from '@/interceptor/http/requestHandler/LocalHttpRequestHandler'; import RemoteHttpRequestHandler from '@/interceptor/http/requestHandler/RemoteHttpRequestHandler'; import { JSONSerialized, JSONValue } from '@/types/json'; diff --git a/packages/zimic/src/interceptor/http/interceptor/__tests__/shared/bodies/plainText.ts b/packages/zimic/src/interceptor/http/interceptor/__tests__/shared/bodies/plainText.ts index 89db33e7..4f8a95f1 100644 --- a/packages/zimic/src/interceptor/http/interceptor/__tests__/shared/bodies/plainText.ts +++ b/packages/zimic/src/interceptor/http/interceptor/__tests__/shared/bodies/plainText.ts @@ -1,7 +1,6 @@ +import { HttpRequest, HttpResponse, HTTP_METHODS_WITH_REQUEST_BODY, HttpSchema } from '@zimic/http'; import { beforeEach, describe, expect, expectTypeOf, it } from 'vitest'; -import { HttpRequest, HttpResponse } from '@/http/types/requests'; -import { HTTP_METHODS_WITH_REQUEST_BODY, HttpSchema } from '@/http/types/schema'; import { promiseIfRemote } from '@/interceptor/http/interceptorWorker/__tests__/utils/promises'; import LocalHttpRequestHandler from '@/interceptor/http/requestHandler/LocalHttpRequestHandler'; import RemoteHttpRequestHandler from '@/interceptor/http/requestHandler/RemoteHttpRequestHandler'; diff --git a/packages/zimic/src/interceptor/http/interceptor/__tests__/shared/bodies/searchParams.ts b/packages/zimic/src/interceptor/http/interceptor/__tests__/shared/bodies/searchParams.ts index 8e4b0bd6..89eaf197 100644 --- a/packages/zimic/src/interceptor/http/interceptor/__tests__/shared/bodies/searchParams.ts +++ b/packages/zimic/src/interceptor/http/interceptor/__tests__/shared/bodies/searchParams.ts @@ -1,8 +1,13 @@ +import { + HttpSearchParams, + HttpRequest, + HttpResponse, + StrictFormData, + HTTP_METHODS_WITH_REQUEST_BODY, + HttpSchema, +} from '@zimic/http'; import { beforeEach, describe, expect, expectTypeOf, it } from 'vitest'; -import HttpSearchParams from '@/http/searchParams/HttpSearchParams'; -import { HttpRequest, HttpResponse, StrictFormData } from '@/http/types/requests'; -import { HTTP_METHODS_WITH_REQUEST_BODY, HttpSchema } from '@/http/types/schema'; import { promiseIfRemote } from '@/interceptor/http/interceptorWorker/__tests__/utils/promises'; import LocalHttpRequestHandler from '@/interceptor/http/requestHandler/LocalHttpRequestHandler'; import RemoteHttpRequestHandler from '@/interceptor/http/requestHandler/RemoteHttpRequestHandler'; diff --git a/packages/zimic/src/interceptor/http/interceptor/__tests__/shared/clear.ts b/packages/zimic/src/interceptor/http/interceptor/__tests__/shared/clear.ts index 52303ad9..8636811a 100644 --- a/packages/zimic/src/interceptor/http/interceptor/__tests__/shared/clear.ts +++ b/packages/zimic/src/interceptor/http/interceptor/__tests__/shared/clear.ts @@ -1,6 +1,6 @@ +import { HTTP_METHODS, HttpSchema } from '@zimic/http'; import { beforeEach, describe, expect, expectTypeOf, it } from 'vitest'; -import { HTTP_METHODS, HttpSchema } from '@/http/types/schema'; import { promiseIfRemote } from '@/interceptor/http/interceptorWorker/__tests__/utils/promises'; import LocalHttpRequestHandler from '@/interceptor/http/requestHandler/LocalHttpRequestHandler'; import RemoteHttpRequestHandler from '@/interceptor/http/requestHandler/RemoteHttpRequestHandler'; diff --git a/packages/zimic/src/interceptor/http/interceptor/__tests__/shared/handlers.ts b/packages/zimic/src/interceptor/http/interceptor/__tests__/shared/handlers.ts index 2ce487f4..6dcbaa9e 100644 --- a/packages/zimic/src/interceptor/http/interceptor/__tests__/shared/handlers.ts +++ b/packages/zimic/src/interceptor/http/interceptor/__tests__/shared/handlers.ts @@ -1,8 +1,6 @@ +import { HttpHeaders, HttpSearchParams, HTTP_METHODS, HttpSchema } from '@zimic/http'; import { beforeEach, describe, expect, expectTypeOf, it } from 'vitest'; -import HttpHeaders from '@/http/headers/HttpHeaders'; -import HttpSearchParams from '@/http/searchParams/HttpSearchParams'; -import { HTTP_METHODS, HttpSchema } from '@/http/types/schema'; import { promiseIfRemote } from '@/interceptor/http/interceptorWorker/__tests__/utils/promises'; import DisabledRequestSavingError from '@/interceptor/http/requestHandler/errors/DisabledRequestSavingError'; import LocalHttpRequestHandler from '@/interceptor/http/requestHandler/LocalHttpRequestHandler'; diff --git a/packages/zimic/src/interceptor/http/interceptor/__tests__/shared/lifeCycle.ts b/packages/zimic/src/interceptor/http/interceptor/__tests__/shared/lifeCycle.ts index 3f8cee36..1712601a 100644 --- a/packages/zimic/src/interceptor/http/interceptor/__tests__/shared/lifeCycle.ts +++ b/packages/zimic/src/interceptor/http/interceptor/__tests__/shared/lifeCycle.ts @@ -1,6 +1,6 @@ +import { HTTP_METHODS, HttpSchema } from '@zimic/http'; import { beforeEach, describe, expect, it } from 'vitest'; -import { HTTP_METHODS, HttpSchema } from '@/http/types/schema'; import { promiseIfRemote } from '@/interceptor/http/interceptorWorker/__tests__/utils/promises'; import LocalHttpRequestHandler from '@/interceptor/http/requestHandler/LocalHttpRequestHandler'; import RemoteHttpRequestHandler from '@/interceptor/http/requestHandler/RemoteHttpRequestHandler'; diff --git a/packages/zimic/src/interceptor/http/interceptor/__tests__/shared/pathParams.ts b/packages/zimic/src/interceptor/http/interceptor/__tests__/shared/pathParams.ts index 1ea22620..cb48691a 100644 --- a/packages/zimic/src/interceptor/http/interceptor/__tests__/shared/pathParams.ts +++ b/packages/zimic/src/interceptor/http/interceptor/__tests__/shared/pathParams.ts @@ -1,6 +1,6 @@ +import { HTTP_METHODS, HttpSchema } from '@zimic/http'; import { beforeEach, describe, expect, expectTypeOf, it } from 'vitest'; -import { HTTP_METHODS, HttpSchema } from '@/http/types/schema'; import { promiseIfRemote } from '@/interceptor/http/interceptorWorker/__tests__/utils/promises'; import LocalHttpRequestHandler from '@/interceptor/http/requestHandler/LocalHttpRequestHandler'; import RemoteHttpRequestHandler from '@/interceptor/http/requestHandler/RemoteHttpRequestHandler'; diff --git a/packages/zimic/src/interceptor/http/interceptor/__tests__/shared/restrictions.ts b/packages/zimic/src/interceptor/http/interceptor/__tests__/shared/restrictions.ts index a758b3ea..daf47f57 100644 --- a/packages/zimic/src/interceptor/http/interceptor/__tests__/shared/restrictions.ts +++ b/packages/zimic/src/interceptor/http/interceptor/__tests__/shared/restrictions.ts @@ -1,11 +1,15 @@ +import { + HttpSchema, + HTTP_METHODS, + HttpHeaders, + HttpSearchParams, + HTTP_METHODS_WITH_REQUEST_BODY, + HttpFormData, +} from '@zimic/http'; import { beforeEach, describe, expect, expectTypeOf, it } from 'vitest'; -import InvalidFormDataError from '@/http/errors/InvalidFormDataError'; -import HttpFormData from '@/http/formData/HttpFormData'; -import HttpHeaders from '@/http/headers/HttpHeaders'; -import HttpSearchParams from '@/http/searchParams/HttpSearchParams'; -import { HTTP_METHODS, HTTP_METHODS_WITH_REQUEST_BODY, HttpSchema } from '@/http/types/schema'; import { promiseIfRemote } from '@/interceptor/http/interceptorWorker/__tests__/utils/promises'; +import InvalidFormDataError from '@/interceptor/http/interceptorWorker/errors/InvalidFormDataError'; import LocalHttpRequestHandler from '@/interceptor/http/requestHandler/LocalHttpRequestHandler'; import RemoteHttpRequestHandler from '@/interceptor/http/requestHandler/RemoteHttpRequestHandler'; import { AccessControlHeaders, DEFAULT_ACCESS_CONTROL_HEADERS } from '@/interceptor/server/constants'; diff --git a/packages/zimic/src/interceptor/http/interceptor/__tests__/shared/times.ts b/packages/zimic/src/interceptor/http/interceptor/__tests__/shared/times.ts index 228b7dd2..4a7f3eb7 100644 --- a/packages/zimic/src/interceptor/http/interceptor/__tests__/shared/times.ts +++ b/packages/zimic/src/interceptor/http/interceptor/__tests__/shared/times.ts @@ -1,6 +1,6 @@ +import { HTTP_METHODS, HttpSchema } from '@zimic/http'; import { beforeEach, describe, expect, it } from 'vitest'; -import { HTTP_METHODS, HttpSchema } from '@/http/types/schema'; import { promiseIfRemote } from '@/interceptor/http/interceptorWorker/__tests__/utils/promises'; import { expectTimesCheckError } from '@/interceptor/http/requestHandler/__tests__/shared/utils'; import LocalHttpRequestHandler from '@/interceptor/http/requestHandler/LocalHttpRequestHandler'; diff --git a/packages/zimic/src/interceptor/http/interceptor/__tests__/shared/types.ts b/packages/zimic/src/interceptor/http/interceptor/__tests__/shared/types.ts index 99e0564b..6218317d 100644 --- a/packages/zimic/src/interceptor/http/interceptor/__tests__/shared/types.ts +++ b/packages/zimic/src/interceptor/http/interceptor/__tests__/shared/types.ts @@ -1,9 +1,14 @@ +import { + HttpHeadersSerialized, + HttpSearchParamsSerialized, + HttpHeaders, + HttpSearchParams, + HttpSchema, + HttpStatusCode, + MergeHttpResponsesByStatusCode, +} from '@zimic/http'; import { beforeEach, describe, expect, expectTypeOf, it } from 'vitest'; -import { HttpHeadersSerialized, HttpSearchParamsSerialized } from '@/http'; -import HttpHeaders from '@/http/headers/HttpHeaders'; -import HttpSearchParams from '@/http/searchParams/HttpSearchParams'; -import { HttpSchema, HttpStatusCode, MergeHttpResponsesByStatusCode } from '@/http/types/schema'; import { HttpRequestHandlerPath } from '@/interceptor/http/requestHandler/types/utils'; import { usingHttpInterceptor } from '@tests/utils/interceptors'; diff --git a/packages/zimic/src/interceptor/http/interceptor/__tests__/shared/unhandledRequests.factories.ts b/packages/zimic/src/interceptor/http/interceptor/__tests__/shared/unhandledRequests.factories.ts index 7f255039..897f5638 100644 --- a/packages/zimic/src/interceptor/http/interceptor/__tests__/shared/unhandledRequests.factories.ts +++ b/packages/zimic/src/interceptor/http/interceptor/__tests__/shared/unhandledRequests.factories.ts @@ -1,7 +1,6 @@ +import { HttpSearchParams, HTTP_METHODS, HttpSchema } from '@zimic/http'; import { beforeEach, describe, expect, it, vi } from 'vitest'; -import HttpSearchParams from '@/http/searchParams/HttpSearchParams'; -import { HTTP_METHODS, HttpSchema } from '@/http/types/schema'; import { promiseIfRemote } from '@/interceptor/http/interceptorWorker/__tests__/utils/promises'; import LocalHttpRequestHandler from '@/interceptor/http/requestHandler/LocalHttpRequestHandler'; import RemoteHttpRequestHandler from '@/interceptor/http/requestHandler/RemoteHttpRequestHandler'; diff --git a/packages/zimic/src/interceptor/http/interceptor/__tests__/shared/unhandledRequests.logging.ts b/packages/zimic/src/interceptor/http/interceptor/__tests__/shared/unhandledRequests.logging.ts index 442b667f..bf7dd1b2 100644 --- a/packages/zimic/src/interceptor/http/interceptor/__tests__/shared/unhandledRequests.logging.ts +++ b/packages/zimic/src/interceptor/http/interceptor/__tests__/shared/unhandledRequests.logging.ts @@ -1,7 +1,6 @@ +import { HttpSearchParams, HTTP_METHODS, HttpSchema } from '@zimic/http'; import { afterEach, beforeEach, describe, expect, expectTypeOf, it } from 'vitest'; -import HttpSearchParams from '@/http/searchParams/HttpSearchParams'; -import { HTTP_METHODS, HttpSchema } from '@/http/types/schema'; import { httpInterceptor } from '@/interceptor/http'; import { promiseIfRemote } from '@/interceptor/http/interceptorWorker/__tests__/utils/promises'; import LocalHttpRequestHandler from '@/interceptor/http/requestHandler/LocalHttpRequestHandler'; diff --git a/packages/zimic/src/interceptor/http/interceptor/__tests__/shared/utils.ts b/packages/zimic/src/interceptor/http/interceptor/__tests__/shared/utils.ts index 4e6192c0..54b97ec1 100644 --- a/packages/zimic/src/interceptor/http/interceptor/__tests__/shared/utils.ts +++ b/packages/zimic/src/interceptor/http/interceptor/__tests__/shared/utils.ts @@ -1,7 +1,6 @@ +import { HttpHeaders, HttpSearchParams, HttpRequest } from '@zimic/http'; import { expect, expectTypeOf } from 'vitest'; -import { HttpHeaders, HttpSearchParams } from '@/http'; -import { HttpRequest } from '@/http/types/requests'; import HttpInterceptorWorker from '@/interceptor/http/interceptorWorker/HttpInterceptorWorker'; import { HttpRequestBodySchema } from '@/interceptor/http/requestHandler/types/requests'; import { PossiblePromise } from '@/types/utils'; diff --git a/packages/zimic/src/interceptor/http/interceptor/factory.ts b/packages/zimic/src/interceptor/http/interceptor/factory.ts index cc87013f..3ffd96d8 100644 --- a/packages/zimic/src/interceptor/http/interceptor/factory.ts +++ b/packages/zimic/src/interceptor/http/interceptor/factory.ts @@ -1,4 +1,4 @@ -import { ConvertToStrictHttpSchema, HttpSchema } from '@/http/types/schema'; +import { HttpSchema } from '@zimic/http'; import UnknownHttpInterceptorTypeError from './errors/UnknownHttpInterceptorTypeError'; import LocalHttpInterceptor from './LocalHttpInterceptor'; @@ -28,26 +28,22 @@ function isRemoteHttpInterceptorOptions(options: HttpInterceptorOptions) { */ export function createHttpInterceptor( options: LocalHttpInterceptorOptions, -): PublicLocalHttpInterceptor>; +): PublicLocalHttpInterceptor>; export function createHttpInterceptor( options: RemoteHttpInterceptorOptions, -): PublicRemoteHttpInterceptor>; +): PublicRemoteHttpInterceptor>; export function createHttpInterceptor( options: HttpInterceptorOptions, -): - | PublicLocalHttpInterceptor> - | PublicRemoteHttpInterceptor>; +): PublicLocalHttpInterceptor> | PublicRemoteHttpInterceptor>; export function createHttpInterceptor( options: HttpInterceptorOptions, -): - | PublicLocalHttpInterceptor> - | PublicRemoteHttpInterceptor> { +): PublicLocalHttpInterceptor> | PublicRemoteHttpInterceptor> { const type = options.type; if (isLocalHttpInterceptorOptions(options)) { - return new LocalHttpInterceptor>(options); + return new LocalHttpInterceptor>(options); } else if (isRemoteHttpInterceptorOptions(options)) { - return new RemoteHttpInterceptor>(options); + return new RemoteHttpInterceptor>(options); } throw new UnknownHttpInterceptorTypeError(type); diff --git a/packages/zimic/src/interceptor/http/interceptor/types/handlers.ts b/packages/zimic/src/interceptor/http/interceptor/types/handlers.ts index 28f94fab..cebaf980 100644 --- a/packages/zimic/src/interceptor/http/interceptor/types/handlers.ts +++ b/packages/zimic/src/interceptor/http/interceptor/types/handlers.ts @@ -4,7 +4,7 @@ import { HttpSchemaMethod, HttpSchemaPath, LiteralHttpSchemaPathFromNonLiteral, -} from '@/http/types/schema'; +} from '@zimic/http'; import { LocalHttpRequestHandler, RemoteHttpRequestHandler } from '../../requestHandler/types/public'; diff --git a/packages/zimic/src/interceptor/http/interceptor/types/public.ts b/packages/zimic/src/interceptor/http/interceptor/types/public.ts index c77ee838..77897e96 100644 --- a/packages/zimic/src/interceptor/http/interceptor/types/public.ts +++ b/packages/zimic/src/interceptor/http/interceptor/types/public.ts @@ -1,4 +1,4 @@ -import { HttpSchema } from '@/http/types/schema'; +import { HttpSchema } from '@zimic/http'; import { SyncHttpInterceptorMethodHandler, AsyncHttpInterceptorMethodHandler } from './handlers'; import { HttpInterceptorPlatform } from './options'; diff --git a/packages/zimic/src/interceptor/http/interceptor/types/requests.ts b/packages/zimic/src/interceptor/http/interceptor/types/requests.ts index 96b5ceb7..24993ef5 100644 --- a/packages/zimic/src/interceptor/http/interceptor/types/requests.ts +++ b/packages/zimic/src/interceptor/http/interceptor/types/requests.ts @@ -1,5 +1,5 @@ -import { HttpBody } from '@/http'; -import { HttpSchema, HttpSchemaMethod, HttpSchemaPath } from '@/http/types/schema'; +import { HttpBody, HttpSchema, HttpSchemaMethod, HttpSchemaPath } from '@zimic/http'; + import { Default } from '@/types/utils'; import { HttpResponseFactoryContext } from '../../interceptorWorker/types/requests'; diff --git a/packages/zimic/src/interceptor/http/interceptorWorker/HttpInterceptorWorker.ts b/packages/zimic/src/interceptor/http/interceptorWorker/HttpInterceptorWorker.ts index 3dc4e089..11530727 100644 --- a/packages/zimic/src/interceptor/http/interceptorWorker/HttpInterceptorWorker.ts +++ b/packages/zimic/src/interceptor/http/interceptorWorker/HttpInterceptorWorker.ts @@ -1,12 +1,18 @@ +import { + HttpHeadersInit, + HttpHeaders, + HttpBody, + HttpResponse, + HttpMethod, + HttpMethodSchema, + HttpSchema, + HttpStatusCode, + InferPathParams, + HttpFormData, + HttpSearchParams, +} from '@zimic/http'; import chalk from 'chalk'; -import InvalidJSONError from '@/errors/InvalidJSONError'; -import { HttpHeadersInit } from '@/http'; -import InvalidFormDataError from '@/http/errors/InvalidFormDataError'; -import HttpFormData from '@/http/formData/HttpFormData'; -import HttpHeaders from '@/http/headers/HttpHeaders'; -import { HttpBody, HttpResponse } from '@/http/types/requests'; -import { HttpMethod, HttpMethodSchema, HttpSchema, HttpStatusCode, InferPathParams } from '@/http/types/schema'; import { Default, PossiblePromise } from '@/types/utils'; import { removeArrayElement } from '@/utils/arrays'; import { formatValueToLog, logWithPrefix } from '@/utils/console'; @@ -15,7 +21,6 @@ import { isClientSide } from '@/utils/environment'; import { methodCanHaveResponseBody } from '@/utils/http'; import { createURL } from '@/utils/urls'; -import HttpSearchParams from '../../../http/searchParams/HttpSearchParams'; import HttpInterceptorClient, { AnyHttpInterceptorClient } from '../interceptor/HttpInterceptorClient'; import { HttpInterceptorPlatform, HttpInterceptorType, UnhandledRequestStrategy } from '../interceptor/types/options'; import { @@ -29,6 +34,8 @@ import { HttpInterceptorResponse, } from '../requestHandler/types/requests'; import { DEFAULT_UNHANDLED_REQUEST_STRATEGY } from './constants'; +import InvalidFormDataError from './errors/InvalidFormDataError'; +import InvalidJSONError from './errors/InvalidJSONError'; import HttpInterceptorWorkerStore from './HttpInterceptorWorkerStore'; import { HttpResponseFactory } from './types/requests'; diff --git a/packages/zimic/src/interceptor/http/interceptorWorker/LocalHttpInterceptorWorker.ts b/packages/zimic/src/interceptor/http/interceptorWorker/LocalHttpInterceptorWorker.ts index eb6b66d3..455773d2 100644 --- a/packages/zimic/src/interceptor/http/interceptorWorker/LocalHttpInterceptorWorker.ts +++ b/packages/zimic/src/interceptor/http/interceptorWorker/LocalHttpInterceptorWorker.ts @@ -1,9 +1,8 @@ +import { HttpRequest, HttpResponse, HttpMethod, HttpSchema } from '@zimic/http'; import { HttpHandler as MSWHttpHandler, SharedOptions as MSWWorkerSharedOptions, http, passthrough } from 'msw'; import * as mswBrowser from 'msw/browser'; import * as mswNode from 'msw/node'; -import { HttpRequest, HttpResponse } from '@/http/types/requests'; -import { HttpMethod, HttpSchema } from '@/http/types/schema'; import { removeArrayIndex } from '@/utils/arrays'; import { createURL } from '@/utils/urls'; diff --git a/packages/zimic/src/interceptor/http/interceptorWorker/RemoteHttpInterceptorWorker.ts b/packages/zimic/src/interceptor/http/interceptorWorker/RemoteHttpInterceptorWorker.ts index 1f2b1303..d6424521 100644 --- a/packages/zimic/src/interceptor/http/interceptorWorker/RemoteHttpInterceptorWorker.ts +++ b/packages/zimic/src/interceptor/http/interceptorWorker/RemoteHttpInterceptorWorker.ts @@ -1,8 +1,7 @@ +import { HttpResponse, HttpMethod, HttpSchema } from '@zimic/http'; import * as mswBrowser from 'msw/browser'; import * as mswNode from 'msw/node'; -import { HttpResponse } from '@/http/types/requests'; -import { HttpMethod, HttpSchema } from '@/http/types/schema'; import { HttpHandlerCommit, InterceptorServerWebSocketSchema } from '@/interceptor/server/types/schema'; import { importCrypto } from '@/utils/crypto'; import { deserializeRequest, serializeResponse } from '@/utils/fetch'; diff --git a/packages/zimic/src/interceptor/http/interceptorWorker/__tests__/shared/methods.ts b/packages/zimic/src/interceptor/http/interceptorWorker/__tests__/shared/methods.ts index 7ae6d580..ebc0dd4f 100644 --- a/packages/zimic/src/interceptor/http/interceptorWorker/__tests__/shared/methods.ts +++ b/packages/zimic/src/interceptor/http/interceptorWorker/__tests__/shared/methods.ts @@ -1,8 +1,6 @@ +import { HttpResponse, HttpHeaders, HTTP_METHODS } from '@zimic/http'; import { afterAll, beforeAll, describe, expect, it, vi } from 'vitest'; -import { HttpResponse } from '@/http'; -import HttpHeaders from '@/http/headers/HttpHeaders'; -import { HTTP_METHODS } from '@/http/types/schema'; import NotStartedHttpInterceptorError from '@/interceptor/http/interceptor/errors/NotStartedHttpInterceptorError'; import { AccessControlHeaders, DEFAULT_ACCESS_CONTROL_HEADERS } from '@/interceptor/server/constants'; import { PossiblePromise } from '@/types/utils'; diff --git a/packages/zimic/src/http/errors/InvalidFormDataError.ts b/packages/zimic/src/interceptor/http/interceptorWorker/errors/InvalidFormDataError.ts similarity index 100% rename from packages/zimic/src/http/errors/InvalidFormDataError.ts rename to packages/zimic/src/interceptor/http/interceptorWorker/errors/InvalidFormDataError.ts diff --git a/packages/zimic/src/errors/InvalidJSONError.ts b/packages/zimic/src/interceptor/http/interceptorWorker/errors/InvalidJSONError.ts similarity index 100% rename from packages/zimic/src/errors/InvalidJSONError.ts rename to packages/zimic/src/interceptor/http/interceptorWorker/errors/InvalidJSONError.ts diff --git a/packages/zimic/src/interceptor/http/interceptorWorker/types/requests.ts b/packages/zimic/src/interceptor/http/interceptorWorker/types/requests.ts index 9e0558e4..da623a8c 100644 --- a/packages/zimic/src/interceptor/http/interceptorWorker/types/requests.ts +++ b/packages/zimic/src/interceptor/http/interceptorWorker/types/requests.ts @@ -1,7 +1,7 @@ +import { HttpResponse, HttpBody, HttpRequest } from '@zimic/http'; import type { SetupWorker as BrowserMSWWorker } from 'msw/browser'; import type { SetupServer as NodeMSWWorker } from 'msw/node'; -import { HttpResponse, HttpBody, HttpRequest } from '@/http/types/requests'; import { PossiblePromise } from '@/types/utils'; export type HttpWorker = BrowserMSWWorker | NodeMSWWorker; diff --git a/packages/zimic/src/interceptor/http/requestHandler/HttpRequestHandlerClient.ts b/packages/zimic/src/interceptor/http/requestHandler/HttpRequestHandlerClient.ts index 2ab9f0eb..daa46d28 100644 --- a/packages/zimic/src/interceptor/http/requestHandler/HttpRequestHandlerClient.ts +++ b/packages/zimic/src/interceptor/http/requestHandler/HttpRequestHandlerClient.ts @@ -1,7 +1,13 @@ -import HttpFormData from '@/http/formData/HttpFormData'; -import HttpHeaders from '@/http/headers/HttpHeaders'; -import HttpSearchParams from '@/http/searchParams/HttpSearchParams'; -import { HttpSchema, HttpSchemaMethod, HttpSchemaPath, HttpStatusCode } from '@/http/types/schema'; +import { + HttpSchemaMethod, + HttpSchemaPath, + HttpStatusCode, + HttpFormData, + HttpHeaders, + HttpSearchParams, + HttpSchema, +} from '@zimic/http'; + import { Default, Range } from '@/types/utils'; import { blobContains, blobEquals } from '@/utils/data'; import { jsonContains, jsonEquals } from '@/utils/json'; diff --git a/packages/zimic/src/interceptor/http/requestHandler/LocalHttpRequestHandler.ts b/packages/zimic/src/interceptor/http/requestHandler/LocalHttpRequestHandler.ts index ee0d92dd..eee5635b 100644 --- a/packages/zimic/src/interceptor/http/requestHandler/LocalHttpRequestHandler.ts +++ b/packages/zimic/src/interceptor/http/requestHandler/LocalHttpRequestHandler.ts @@ -1,4 +1,5 @@ -import { HttpSchema, HttpSchemaMethod, HttpSchemaPath, HttpStatusCode } from '@/http/types/schema'; +import { HttpSchema, HttpSchemaMethod, HttpSchemaPath, HttpStatusCode } from '@zimic/http'; + import { Default } from '@/types/utils'; import HttpInterceptorClient from '../interceptor/HttpInterceptorClient'; diff --git a/packages/zimic/src/interceptor/http/requestHandler/RemoteHttpRequestHandler.ts b/packages/zimic/src/interceptor/http/requestHandler/RemoteHttpRequestHandler.ts index 814f3b12..37e2c6fe 100644 --- a/packages/zimic/src/interceptor/http/requestHandler/RemoteHttpRequestHandler.ts +++ b/packages/zimic/src/interceptor/http/requestHandler/RemoteHttpRequestHandler.ts @@ -1,4 +1,5 @@ -import { HttpSchema, HttpSchemaMethod, HttpSchemaPath, HttpStatusCode } from '@/http/types/schema'; +import { HttpSchema, HttpSchemaMethod, HttpSchemaPath, HttpStatusCode } from '@zimic/http'; + import { Default, PossiblePromise } from '@/types/utils'; import HttpInterceptorClient from '../interceptor/HttpInterceptorClient'; diff --git a/packages/zimic/src/interceptor/http/requestHandler/__tests__/shared/default.ts b/packages/zimic/src/interceptor/http/requestHandler/__tests__/shared/default.ts index f5092f4f..7caadd75 100644 --- a/packages/zimic/src/interceptor/http/requestHandler/__tests__/shared/default.ts +++ b/packages/zimic/src/interceptor/http/requestHandler/__tests__/shared/default.ts @@ -1,6 +1,6 @@ +import { HttpRequest, HttpResponse, StrictFormData } from '@zimic/http'; import { expectTypeOf, expect, vi, it, beforeAll, afterAll, describe } from 'vitest'; -import { HttpRequest, HttpResponse, StrictFormData } from '@/http/types/requests'; import { SharedHttpInterceptorClient } from '@/interceptor/http/interceptor/HttpInterceptorClient'; import LocalHttpInterceptor from '@/interceptor/http/interceptor/LocalHttpInterceptor'; import RemoteHttpInterceptor from '@/interceptor/http/interceptor/RemoteHttpInterceptor'; diff --git a/packages/zimic/src/interceptor/http/requestHandler/__tests__/shared/restrictions.ts b/packages/zimic/src/interceptor/http/requestHandler/__tests__/shared/restrictions.ts index 47b86332..c5d859f8 100644 --- a/packages/zimic/src/interceptor/http/requestHandler/__tests__/shared/restrictions.ts +++ b/packages/zimic/src/interceptor/http/requestHandler/__tests__/shared/restrictions.ts @@ -1,7 +1,6 @@ +import { HttpHeaders, HttpSearchParams } from '@zimic/http'; import { expectTypeOf, expect, it, beforeAll, afterAll, describe } from 'vitest'; -import HttpHeaders from '@/http/headers/HttpHeaders'; -import HttpSearchParams from '@/http/searchParams/HttpSearchParams'; import { SharedHttpInterceptorClient } from '@/interceptor/http/interceptor/HttpInterceptorClient'; import LocalHttpInterceptor from '@/interceptor/http/interceptor/LocalHttpInterceptor'; import RemoteHttpInterceptor from '@/interceptor/http/interceptor/RemoteHttpInterceptor'; diff --git a/packages/zimic/src/interceptor/http/requestHandler/__tests__/shared/times.ts b/packages/zimic/src/interceptor/http/requestHandler/__tests__/shared/times.ts index 2263b9b2..497233ee 100644 --- a/packages/zimic/src/interceptor/http/requestHandler/__tests__/shared/times.ts +++ b/packages/zimic/src/interceptor/http/requestHandler/__tests__/shared/times.ts @@ -1,6 +1,6 @@ +import { HttpFormData, HttpSearchParams } from '@zimic/http'; import { expect, it, beforeAll, afterAll, describe } from 'vitest'; -import { HttpFormData, HttpSearchParams } from '@/http'; import { SharedHttpInterceptorClient } from '@/interceptor/http/interceptor/HttpInterceptorClient'; import LocalHttpInterceptor from '@/interceptor/http/interceptor/LocalHttpInterceptor'; import RemoteHttpInterceptor from '@/interceptor/http/interceptor/RemoteHttpInterceptor'; diff --git a/packages/zimic/src/interceptor/http/requestHandler/__tests__/shared/types.ts b/packages/zimic/src/interceptor/http/requestHandler/__tests__/shared/types.ts index 6a167a82..c2771463 100644 --- a/packages/zimic/src/interceptor/http/requestHandler/__tests__/shared/types.ts +++ b/packages/zimic/src/interceptor/http/requestHandler/__tests__/shared/types.ts @@ -1,5 +1,5 @@ -import { HttpFormData, HttpSearchParams } from '@/http'; -import { HttpSchema } from '@/http/types/schema'; +import { HttpFormData, HttpSearchParams, HttpSchema } from '@zimic/http'; + import { HttpInterceptorPlatform, HttpInterceptorType } from '@/interceptor/http/interceptor/types/options'; import { PossiblePromise } from '@/types/utils'; import { ExtendedURL } from '@/utils/urls'; diff --git a/packages/zimic/src/interceptor/http/requestHandler/types/public.ts b/packages/zimic/src/interceptor/http/requestHandler/types/public.ts index 7d7253bd..98ac960f 100644 --- a/packages/zimic/src/interceptor/http/requestHandler/types/public.ts +++ b/packages/zimic/src/interceptor/http/requestHandler/types/public.ts @@ -4,7 +4,8 @@ import { HttpSchemaMethod, HttpSchemaPath, HttpStatusCode, -} from '@/http/types/schema'; +} from '@zimic/http'; + import { Default, PossiblePromise } from '@/types/utils'; import HttpRequestHandlerClient from '../HttpRequestHandlerClient'; diff --git a/packages/zimic/src/interceptor/http/requestHandler/types/requests.ts b/packages/zimic/src/interceptor/http/requestHandler/types/requests.ts index 8f86d393..4b12acef 100644 --- a/packages/zimic/src/interceptor/http/requestHandler/types/requests.ts +++ b/packages/zimic/src/interceptor/http/requestHandler/types/requests.ts @@ -1,8 +1,15 @@ -import HttpHeaders from '@/http/headers/HttpHeaders'; -import { HttpHeadersInit } from '@/http/headers/types'; -import HttpSearchParams from '@/http/searchParams/HttpSearchParams'; -import { HttpRequest, HttpResponse } from '@/http/types/requests'; -import { HttpMethodSchema, HttpResponseSchema, HttpStatusCode, InferPathParams } from '@/http/types/schema'; +import { + HttpHeaders, + HttpHeadersInit, + HttpMethodSchema, + HttpRequest, + HttpResponse, + HttpResponseSchema, + HttpSearchParams, + HttpStatusCode, + InferPathParams, +} from '@zimic/http'; + import { Default, DefaultNoExclude, IfNever, PossiblePromise, ReplaceBy } from '@/types/utils'; export type HttpRequestHandlerResponseWithBody = diff --git a/packages/zimic/src/interceptor/http/requestHandler/types/restrictions.ts b/packages/zimic/src/interceptor/http/requestHandler/types/restrictions.ts index 9dc4d8ba..341c7751 100644 --- a/packages/zimic/src/interceptor/http/requestHandler/types/restrictions.ts +++ b/packages/zimic/src/interceptor/http/requestHandler/types/restrictions.ts @@ -1,14 +1,15 @@ import { HttpBody, HttpFormData, + HttpHeaders, HttpHeadersSchema, HttpSchema, HttpSchemaMethod, HttpSchemaPath, HttpSearchParams, HttpSearchParamsSchema, -} from '@/http'; -import HttpHeaders from '@/http/headers/HttpHeaders'; +} from '@zimic/http'; + import { IfNever, Default, DeepPartial, PossiblePromise } from '@/types/utils'; import { diff --git a/packages/zimic/src/interceptor/server/InterceptorServer.ts b/packages/zimic/src/interceptor/server/InterceptorServer.ts index a10edae6..2dbdad9e 100644 --- a/packages/zimic/src/interceptor/server/InterceptorServer.ts +++ b/packages/zimic/src/interceptor/server/InterceptorServer.ts @@ -1,9 +1,8 @@ import { normalizeNodeRequest, sendNodeResponse } from '@whatwg-node/server'; +import { HttpRequest, HttpMethod } from '@zimic/http'; import { createServer, Server as HttpServer, IncomingMessage, ServerResponse } from 'http'; import type { WebSocket as Socket } from 'isomorphic-ws'; -import { HttpRequest } from '@/http'; -import { HttpMethod } from '@/http/types/schema'; import HttpInterceptorWorker from '@/interceptor/http/interceptorWorker/HttpInterceptorWorker'; import { removeArrayIndex } from '@/utils/arrays'; import { deserializeResponse, SerializedHttpRequest, serializeRequest } from '@/utils/fetch'; diff --git a/packages/zimic/src/interceptor/server/constants.ts b/packages/zimic/src/interceptor/server/constants.ts index edca15a1..b8273a02 100644 --- a/packages/zimic/src/interceptor/server/constants.ts +++ b/packages/zimic/src/interceptor/server/constants.ts @@ -1,4 +1,5 @@ -import { HTTP_METHODS, HttpSchema } from '@/http/types/schema'; +import { HTTP_METHODS, HttpSchema } from '@zimic/http'; + import { DEFAULT_HTTP_SERVER_LIFECYCLE_TIMEOUT } from '@/utils/http'; import { DEFAULT_WEB_SOCKET_MESSAGE_TIMEOUT } from '@/utils/webSocket'; diff --git a/packages/zimic/src/interceptor/server/types/schema.ts b/packages/zimic/src/interceptor/server/types/schema.ts index 2aab09b8..c6fad2c8 100644 --- a/packages/zimic/src/interceptor/server/types/schema.ts +++ b/packages/zimic/src/interceptor/server/types/schema.ts @@ -1,4 +1,5 @@ -import { HttpMethod } from '@/http/types/schema'; +import { HttpMethod } from '@zimic/http'; + import { SerializedHttpRequest, SerializedResponse } from '@/utils/fetch'; import { WebSocket } from '@/webSocket/types'; diff --git a/packages/zimic/src/types/json.ts b/packages/zimic/src/types/json.ts index 59e776f2..244bd929 100644 --- a/packages/zimic/src/types/json.ts +++ b/packages/zimic/src/types/json.ts @@ -12,7 +12,7 @@ namespace JSON { * (`type`). They cannot be interfaces. * * @example - * import { type JSONValue } from 'zimic'; + * import { type JSONValue } from '@zimic/http'; * * // Can be used as a standalone type: * const value: JSONValue = { @@ -21,7 +21,7 @@ namespace JSON { * }; * * @example - * import { type JSONValue } from 'zimic'; + * import { type JSONValue } from '@zimic/http'; * * // Can be used with a type argument to validate a JSON value: * type ValidJSON = JSONValue<{ @@ -50,7 +50,7 @@ export namespace JSONValue { * values are excluded. * * @example - * import { type JSONSerialized } from 'zimic'; + * import { type JSONSerialized } from '@zimic/http'; * * type SerializedUser = JSONSerialized<{ * id: string; diff --git a/packages/zimic/src/utils/console.ts b/packages/zimic/src/utils/console.ts index 48257da3..9221200a 100644 --- a/packages/zimic/src/utils/console.ts +++ b/packages/zimic/src/utils/console.ts @@ -1,7 +1,6 @@ +import { HttpFormData, HttpHeaders, HttpSearchParams } from '@zimic/http'; import chalk from 'chalk'; -import { HttpFormData, HttpHeaders, HttpSearchParams } from '@/http'; - import { isClientSide } from './environment'; import { isGlobalFileAvailable } from './files'; import { createCachedDynamicImport } from './imports'; diff --git a/packages/zimic/src/utils/files.ts b/packages/zimic/src/utils/files.ts index dffbec1c..1f6e011b 100644 --- a/packages/zimic/src/utils/files.ts +++ b/packages/zimic/src/utils/files.ts @@ -1,4 +1,3 @@ -import { blobEquals } from './data'; import { createCachedDynamicImport } from './imports'; export const importBuffer = createCachedDynamicImport( @@ -25,7 +24,3 @@ export async function importFile() { FileSingleton = globalThis.File ?? (await importBuffer()).File; return FileSingleton; } - -export async function fileEquals(file: File, otherFile: File) { - return file.name === otherFile.name && (await blobEquals(file, otherFile)); -} diff --git a/packages/zimic/src/utils/http.ts b/packages/zimic/src/utils/http.ts index 8cd8ac75..dda3ba15 100644 --- a/packages/zimic/src/utils/http.ts +++ b/packages/zimic/src/utils/http.ts @@ -1,12 +1,11 @@ -import { Server as HttpServer } from 'http'; - import { HTTP_METHODS_WITH_REQUEST_BODY, HTTP_METHODS_WITH_RESPONSE_BODY, HttpMethod, HttpMethodWithRequestBody, HttpMethodWithResponseBody, -} from '@/http/types/schema'; +} from '@zimic/http'; +import { Server as HttpServer } from 'http'; class HttpServerTimeoutError extends Error {} diff --git a/packages/zimic/src/utils/time.ts b/packages/zimic/src/utils/time.ts index 47209f34..c0faa4e6 100644 --- a/packages/zimic/src/utils/time.ts +++ b/packages/zimic/src/utils/time.ts @@ -1,31 +1,5 @@ -import { PossiblePromise } from '@/types/utils'; - export function waitForDelay(delayDuration: number) { return new Promise((resolve) => { setTimeout(resolve, delayDuration); }); } - -export async function usingElapsedTime(callback: () => PossiblePromise) { - const startTimeInMilliseconds = performance.now(); - - const result = await callback(); - - const endTimeInMilliseconds = performance.now(); - const elapsedTimeInMilliseconds = endTimeInMilliseconds - startTimeInMilliseconds; - - return { - startTime: startTimeInMilliseconds, - elapsedTime: elapsedTimeInMilliseconds, - endTime: endTimeInMilliseconds, - result, - }; -} - -export function formatElapsedTime(elapsedTimeInMilliseconds: number) { - if (elapsedTimeInMilliseconds < 1000) { - return `${elapsedTimeInMilliseconds.toFixed(0)}ms`; - } else { - return `${(elapsedTimeInMilliseconds / 1000).toFixed(2)}s`; - } -} diff --git a/packages/zimic/src/utils/urls.ts b/packages/zimic/src/utils/urls.ts index 0c4beb28..2932ec52 100644 --- a/packages/zimic/src/utils/urls.ts +++ b/packages/zimic/src/utils/urls.ts @@ -103,10 +103,6 @@ export function createURL( return url; } -export function createFileURL(filePath: string) { - return createURL(`file://${filePath}`); -} - function prepareURLForRegex(url: string) { const encodedURL = encodeURI(url); return encodedURL.replace(/([.()*?+$\\])/g, '\\$1'); @@ -120,17 +116,6 @@ export function createRegexFromURL(url: string) { return new RegExp(`^${urlWithReplacedPathParams}$`); } -export function createRegexFromWildcardPath(path: string, options: { prefix: string }) { - const pathWithReplacedWildcards = prepareURLForRegex(path) - .replace(/^\/+|\/+$/g, '') - .replace(/\\\*/g, '*') - .replace(/\*\*\/\*/g, '**') - .replace(/(^|[^*])\*([^*]|$)/g, '$1[^/]*$2') - .replace(/\*\*/g, '.*'); - - return new RegExp(`^${options.prefix}/*${pathWithReplacedWildcards}/*$`); -} - export function joinURL(...parts: (string | URL)[]) { return parts .map((part, index) => { diff --git a/packages/zimic/tests/setup/global/shared.ts b/packages/zimic/tests/setup/global/shared.ts index 51e55a90..4876c53a 100644 --- a/packages/zimic/tests/setup/global/shared.ts +++ b/packages/zimic/tests/setup/global/shared.ts @@ -1,6 +1,6 @@ +import { HttpHeaders } from '@zimic/http'; import type { Server } from 'http'; -import { HttpHeaders } from '@/http'; import { startHttpServer, stopHttpServer } from '@/utils/http'; let fallbackServer: Server | undefined; diff --git a/packages/zimic/tests/utils/interceptors.ts b/packages/zimic/tests/utils/interceptors.ts index e0cd471d..c9870f99 100644 --- a/packages/zimic/tests/utils/interceptors.ts +++ b/packages/zimic/tests/utils/interceptors.ts @@ -1,6 +1,6 @@ +import { HttpSchema, HttpMethod } from '@zimic/http'; import { expect } from 'vitest'; -import { ConvertToStrictHttpSchema, HttpMethod, HttpSchema } from '@/http/types/schema'; import { httpInterceptor } from '@/interceptor/http'; import HttpInterceptorStore from '@/interceptor/http/interceptor/HttpInterceptorStore'; import LocalHttpInterceptor from '@/interceptor/http/interceptor/LocalHttpInterceptor'; @@ -55,20 +55,20 @@ export async function getNodeBaseURL(type: HttpInterceptorType, server: Intercep export function createInternalHttpInterceptor( options: LocalHttpInterceptorOptions, -): LocalHttpInterceptor>; +): LocalHttpInterceptor>; export function createInternalHttpInterceptor( options: RemoteHttpInterceptorOptions, -): RemoteHttpInterceptor>; +): RemoteHttpInterceptor>; export function createInternalHttpInterceptor( options: HttpInterceptorOptions, -): LocalHttpInterceptor> | RemoteHttpInterceptor>; +): LocalHttpInterceptor> | RemoteHttpInterceptor>; export function createInternalHttpInterceptor(options: HttpInterceptorOptions) { return httpInterceptor.create({ saveRequests: true, ...options, - }) satisfies HttpInterceptor> as - | LocalHttpInterceptor> - | RemoteHttpInterceptor>; + }) satisfies HttpInterceptor> as + | LocalHttpInterceptor> + | RemoteHttpInterceptor>; } type UsingInterceptorCallback = ( @@ -82,23 +82,21 @@ interface UsingInterceptorOptions { export async function usingHttpInterceptor( interceptorOptions: HttpInterceptorOptions, - callback: UsingInterceptorCallback>, + callback: UsingInterceptorCallback>, ): Promise; export async function usingHttpInterceptor( interceptorOptions: HttpInterceptorOptions, options: UsingInterceptorOptions, - callback: UsingInterceptorCallback>, + callback: UsingInterceptorCallback>, ): Promise; export async function usingHttpInterceptor( interceptorOptions: HttpInterceptorOptions, - callbackOrOptions: UsingInterceptorCallback> | UsingInterceptorOptions, - optionalCallback?: UsingInterceptorCallback>, + callbackOrOptions: UsingInterceptorCallback> | UsingInterceptorOptions, + optionalCallback?: UsingInterceptorCallback>, ): Promise { const { start: shouldStartInterceptor = true, checkTimes: shouldCheckTimes = false } = typeof callbackOrOptions === 'function' ? {} : callbackOrOptions; - const callback = (optionalCallback ?? callbackOrOptions) as UsingInterceptorCallback< - ConvertToStrictHttpSchema - >; + const callback = (optionalCallback ?? callbackOrOptions) as UsingInterceptorCallback>; const interceptor = createInternalHttpInterceptor(interceptorOptions); diff --git a/packages/zimic/tsup.config.ts b/packages/zimic/tsup.config.ts index e17918d6..aa076a7b 100644 --- a/packages/zimic/tsup.config.ts +++ b/packages/zimic/tsup.config.ts @@ -10,8 +10,6 @@ export function pickKeys(object: Type, keys: Key[] ); } -const isDevelopment = process.env.npm_lifecycle_event === 'dev'; - const sharedConfig: Options = { bundle: true, splitting: true, @@ -22,7 +20,6 @@ const sharedConfig: Options = { keepNames: true, env: { SERVER_ACCESS_CONTROL_MAX_AGE: '', - TYPEGEN_HTTP_IMPORT_MODULE: isDevelopment ? '@/http' : 'zimic/http', }, }; @@ -34,7 +31,6 @@ const neutralConfig = (['cjs', 'esm'] as const).map((format) => ({ dts: format === 'cjs', entry: { index: 'src/index.ts', - http: 'src/http/index.ts', fetch: 'src/fetch/index.ts', 'interceptor/http': 'src/interceptor/http/index.ts', }, @@ -44,12 +40,11 @@ const neutralConfig = (['cjs', 'esm'] as const).map((format) => ({ const nodeConfig = (['cjs', 'esm'] as const).map((format) => { const entry = { 'interceptor/server': 'src/interceptor/server/index.ts', - typegen: 'src/typegen/index.ts', cli: 'src/cli/index.ts', 'scripts/postinstall': 'scripts/postinstall.ts', }; - const dtsEntry = pickKeys(entry, ['interceptor/server', 'typegen']); + const dtsEntry = pickKeys(entry, ['interceptor/server']); return { ...sharedConfig, diff --git a/packages/zimic/vitest.config.mts b/packages/zimic/vitest.config.mts index 3c4cd780..4382527d 100644 --- a/packages/zimic/vitest.config.mts +++ b/packages/zimic/vitest.config.mts @@ -29,7 +29,6 @@ export default defineConfig({ 'dist/**', 'tests/coverage/**', 'tests/setup/global/**', - 'scripts/dev/**', '**/types/**', '**/{*.d.ts,types,typescript}.ts', '**/.lintstagedrc.js', @@ -41,7 +40,6 @@ export default defineConfig({ }, define: { 'process.env.SERVER_ACCESS_CONTROL_MAX_AGE': "'0'", - 'process.env.TYPEGEN_HTTP_IMPORT_MODULE': "'@/http'", }, resolve: { alias: { diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index 74b8de0f..2d35df2a 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -53,6 +53,9 @@ importers: '@zimic/eslint-config-node': specifier: workspace:* version: link:../../packages/eslint-config-node + '@zimic/http': + specifier: workspace:* + version: link:../../packages/zimic-http '@zimic/lint-staged-config': specifier: workspace:* version: link:../../packages/lint-staged-config @@ -114,6 +117,9 @@ importers: examples/with-jest-jsdom: dependencies: + '@zimic/http': + specifier: latest + version: link:../../packages/zimic-http zimic: specifier: latest version: link:../../packages/zimic @@ -151,6 +157,9 @@ importers: examples/with-jest-node: dependencies: + '@zimic/http': + specifier: latest + version: link:../../packages/zimic-http fastify: specifier: ^5.2.1 version: 5.2.1 @@ -191,6 +200,9 @@ importers: '@tanstack/react-query': specifier: ^5.66.0 version: 5.66.0(react@19.0.0) + '@zimic/http': + specifier: latest + version: link:../../packages/zimic-http clsx: specifier: ^2.1.1 version: 2.1.1 @@ -246,6 +258,9 @@ importers: '@tanstack/react-query': specifier: ^5.66.0 version: 5.66.0(react@19.0.0) + '@zimic/http': + specifier: latest + version: link:../../packages/zimic-http clsx: specifier: ^2.1.1 version: 2.1.1 @@ -295,6 +310,9 @@ importers: examples/with-openapi-typegen: dependencies: + '@zimic/http': + specifier: latest + version: link:../../packages/zimic-http fastify: specifier: ^5.2.1 version: 5.2.1 @@ -326,6 +344,9 @@ importers: examples/with-playwright: dependencies: + '@zimic/http': + specifier: latest + version: link:../../packages/zimic-http clsx: specifier: ^2.1.1 version: 2.1.1 @@ -378,6 +399,9 @@ importers: examples/with-vitest-browser: dependencies: + '@zimic/http': + specifier: latest + version: link:../../packages/zimic-http zimic: specifier: latest version: link:../../packages/zimic @@ -412,6 +436,9 @@ importers: examples/with-vitest-jsdom: dependencies: + '@zimic/http': + specifier: latest + version: link:../../packages/zimic-http zimic: specifier: latest version: link:../../packages/zimic @@ -440,6 +467,9 @@ importers: examples/with-vitest-node: dependencies: + '@zimic/http': + specifier: latest + version: link:../../packages/zimic-http fastify: specifier: ^5.2.1 version: 5.2.1 @@ -538,9 +568,6 @@ importers: msw: specifier: 2.7.0 version: 2.7.0(@types/node@22.13.4)(typescript@5.7.3) - openapi-typescript: - specifier: 7.6.1 - version: 7.6.1(typescript@5.7.3) ws: specifier: 8.18.0 version: 8.18.0(bufferutil@4.0.9) @@ -552,12 +579,6 @@ importers: specifier: 4.0.9 version: 4.0.9 devDependencies: - '@types/cross-spawn': - specifier: ^6.0.6 - version: 6.0.6 - '@types/js-yaml': - specifier: ^4.0.9 - version: 4.0.9 '@types/node': specifier: ^22.13.4 version: 22.13.4 @@ -576,6 +597,67 @@ importers: '@zimic/eslint-config-node': specifier: workspace:* version: link:../eslint-config-node + '@zimic/http': + specifier: workspace:* + version: link:../zimic-http + '@zimic/lint-staged-config': + specifier: workspace:* + version: link:../lint-staged-config + '@zimic/tsconfig': + specifier: workspace:* + version: link:../tsconfig + dotenv-cli: + specifier: ^8.0.0 + version: 8.0.0 + eslint: + specifier: ^9.20.1 + version: 9.20.1(jiti@2.4.2) + playwright: + specifier: ^1.50.1 + version: 1.50.1 + tsup: + specifier: ^8.3.6 + version: 8.3.6(@swc/core@1.10.16(@swc/helpers@0.5.15))(jiti@2.4.2)(postcss@8.5.2)(tsx@4.19.2)(typescript@5.7.3)(yaml@2.7.0) + tsx: + specifier: ^4.19.2 + version: 4.19.2 + typescript: + specifier: ^5.7.3 + version: 5.7.3 + vitest: + specifier: ^3.0.5 + version: 3.0.5(@types/debug@4.1.12)(@types/node@22.13.4)(@vitest/browser@3.0.5)(jiti@2.4.2)(jsdom@20.0.3(bufferutil@4.0.9))(lightningcss@1.29.1)(msw@2.7.0(@types/node@22.13.4)(typescript@5.7.3))(tsx@4.19.2)(yaml@2.7.0) + + packages/zimic-http: + dependencies: + chalk: + specifier: 4.1.2 + version: 4.1.2 + openapi-typescript: + specifier: 7.6.1 + version: 7.6.1(typescript@5.7.3) + yargs: + specifier: 17.7.2 + version: 17.7.2 + devDependencies: + '@types/js-yaml': + specifier: ^4.0.9 + version: 4.0.9 + '@types/node': + specifier: ^22.13.4 + version: 22.13.4 + '@types/yargs': + specifier: ^17.0.33 + version: 17.0.33 + '@vitest/browser': + specifier: ^3.0.5 + version: 3.0.5(@types/node@22.13.4)(bufferutil@4.0.9)(playwright@1.50.1)(typescript@5.7.3)(vite@6.1.0(@types/node@22.13.4)(jiti@2.4.2)(lightningcss@1.29.1)(tsx@4.19.2)(yaml@2.7.0))(vitest@3.0.5) + '@vitest/coverage-istanbul': + specifier: ^3.0.5 + version: 3.0.5(vitest@3.0.5) + '@zimic/eslint-config-node': + specifier: workspace:* + version: link:../eslint-config-node '@zimic/lint-staged-config': specifier: workspace:* version: link:../lint-staged-config @@ -588,6 +670,9 @@ importers: eslint: specifier: ^9.20.1 version: 9.20.1(jiti@2.4.2) + execa: + specifier: 9.5.2 + version: 9.5.2 js-yaml: specifier: ^4.1.0 version: 4.1.0 @@ -609,6 +694,9 @@ importers: vitest: specifier: ^3.0.5 version: 3.0.5(@types/debug@4.1.12)(@types/node@22.13.4)(@vitest/browser@3.0.5)(jiti@2.4.2)(jsdom@20.0.3(bufferutil@4.0.9))(lightningcss@1.29.1)(msw@2.7.0(@types/node@22.13.4)(typescript@5.7.3))(tsx@4.19.2)(yaml@2.7.0) + zimic: + specifier: ^0.13.2 + version: 0.13.2(@types/node@22.13.4)(typescript@5.7.3) packages: @@ -1996,9 +2084,6 @@ packages: '@types/cookiejar@2.1.5': resolution: {integrity: sha512-he+DHOWReW0nghN24E1WUqM0efK4kI9oTqDm6XmK8ZPe2djZ90BSNdGnIyCLzCPw7/pogPlGbzI2wHGGmi4O/Q==} - '@types/cross-spawn@6.0.6': - resolution: {integrity: sha512-fXRhhUkG4H3TQk5dBhQ7m/JDdSNHKwR2BBia62lhwEIq9xGiQKLxd6LymNhn47SjXhsUEPmxi+PKw2OkW4LLjA==} - '@types/debug@4.1.12': resolution: {integrity: sha512-vIChWdVG3LG1SMxEvI/AK+FWJthlrqlTu7fbrlywTkkaONwk/UAGaULXRlf8vkzFBLVm0zkMdCquhL5aOjhXPQ==} @@ -5699,6 +5784,16 @@ packages: resolution: {integrity: sha512-GQHQqAopRhwU8Kt1DDM8NjibDXHC8eoh1erhGAJPEyveY9qqVeXvVikNKrDz69sHowPMorbPUrH/mx8c50eiBQ==} engines: {node: '>=18'} + zimic@0.13.2: + resolution: {integrity: sha512-o2OnX49rl56ORrSez3zVZg7JAFLAqL0i+zaIrb0Mj4md6xGvVpRRy/bF46hA0u5w/gB7g6njE7eBJ+RrnWJC/w==} + engines: {node: '>=18.13.0'} + hasBin: true + peerDependencies: + typescript: '>=4.8.0' + peerDependenciesMeta: + typescript: + optional: true + zod@3.24.2: resolution: {integrity: sha512-lY7CDW43ECgW9u1TcT3IoXHflywfVqDYze4waEz812jR/bZ8FHDsl7pFQoSZTz5N+2NqRXs8GBwnAwo3ZNxqhQ==} @@ -6991,10 +7086,6 @@ snapshots: '@types/cookiejar@2.1.5': {} - '@types/cross-spawn@6.0.6': - dependencies: - '@types/node': 22.13.4 - '@types/debug@4.1.12': dependencies: '@types/ms': 0.7.34 @@ -11446,4 +11537,21 @@ snapshots: yoctocolors@2.1.1: {} + zimic@0.13.2(@types/node@22.13.4)(typescript@5.7.3): + dependencies: + '@whatwg-node/server': 0.9.67 + chalk: 4.1.2 + execa: 9.5.2 + isomorphic-ws: 5.0.0(ws@8.18.0(bufferutil@4.0.9)) + msw: 2.7.0(@types/node@22.13.4)(typescript@5.7.3) + openapi-typescript: 7.6.1(typescript@5.7.3) + ws: 8.18.0(bufferutil@4.0.9) + yargs: 17.7.2 + optionalDependencies: + bufferutil: 4.0.9 + typescript: 5.7.3 + transitivePeerDependencies: + - '@types/node' + - utf-8-validate + zod@3.24.2: {}