Skip to content
New issue

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

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

Already on GitHub? Sign in to your account

feat: rename "SetupWorkerApi"/"SetupServerApi" types to "SetupWorker"/"SetupServer" #1478

Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
3 changes: 2 additions & 1 deletion src/index.ts
Expand Up @@ -27,7 +27,8 @@ export { cleanUrl } from './utils/url/cleanUrl'
/**
* Type definitions.
*/
export type { SetupWorkerApi, StartOptions } from './setupWorker/glossary'
export type { SetupWorker, StartOptions } from './setupWorker/glossary'
export { SetupWorkerApi } from './setupWorker/setupWorker'
export type { SharedOptions } from './sharedOptions'

export * from './utils/request/MockedRequest'
Expand Down
6 changes: 5 additions & 1 deletion src/node/SetupServerApi.ts
Expand Up @@ -16,6 +16,7 @@ import { mergeRight } from '../utils/internal/mergeRight'
import { MockedRequest } from '../utils/request/MockedRequest'
import { handleRequest } from '../utils/handleRequest'
import { devUtils } from '../utils/internal/devUtils'
import { SetupServer } from './glossary'

/**
* @see https://github.com/mswjs/msw/pull/1399
Expand All @@ -28,7 +29,10 @@ const DEFAULT_LISTEN_OPTIONS: RequiredDeep<SharedOptions> = {
onUnhandledRequest: 'warn',
}

export class SetupServerApi extends SetupApi<ServerLifecycleEventsMap> {
export class SetupServerApi
extends SetupApi<ServerLifecycleEventsMap>
implements SetupServer
{
protected readonly interceptor: BatchInterceptor<
Array<Interceptor<HttpRequestEventMap>>,
HttpRequestEventMap
Expand Down
2 changes: 1 addition & 1 deletion src/node/glossary.ts
Expand Up @@ -14,7 +14,7 @@ import { MockedRequest } from '../utils/request/MockedRequest'

export type ServerLifecycleEventsMap = LifeCycleEventsMap<IsomorphicResponse>

export interface SetupServerApi {
export interface SetupServer {
/**
* Starts requests interception based on the previously provided request handlers.
* @see {@link https://mswjs.io/docs/api/setup-server/listen `server.listen()`}
Expand Down
3 changes: 2 additions & 1 deletion src/node/index.ts
@@ -1,3 +1,4 @@
export { ServerLifecycleEventsMap } from './SetupServerApi'
export { setupServer } from './setupServer'
export type { SetupServerApi } from './glossary'
export type { SetupServer } from './glossary'
export { SetupServerApi } from './SetupServerApi'
2 changes: 1 addition & 1 deletion src/setupWorker/glossary.ts
Expand Up @@ -209,7 +209,7 @@ export type StartHandler = (
) => StartReturnType
export type StopHandler = () => void

export interface SetupWorkerApi {
export interface SetupWorker {
/**
* Registers and activates the mock Service Worker.
* @see {@link https://mswjs.io/docs/api/setup-worker/start `worker.start()`}
Expand Down
8 changes: 5 additions & 3 deletions src/setupWorker/setupWorker.ts
Expand Up @@ -19,15 +19,15 @@ import { createFallbackStop } from './stop/createFallbackStop'
import { devUtils } from '../utils/internal/devUtils'
import { SetupApi } from '../SetupApi'
import { mergeRight } from '../utils/internal/mergeRight'
import { SetupWorkerApi as SetupWorker } from './glossary'
import { SetupWorker } from './glossary'

interface Listener {
target: EventTarget
eventType: string
callback: EventListener
}

class SetupWorkerApi
export class SetupWorkerApi
extends SetupApi<WorkerLifecycleEventsMap>
implements SetupWorker
{
Expand Down Expand Up @@ -225,6 +225,8 @@ class SetupWorkerApi
* @param {RequestHandler[]} handlers List of request handlers.
* @see {@link https://mswjs.io/docs/api/setup-worker `setupWorker`}
*/
export function setupWorker(...handlers: Array<RequestHandler>): SetupWorker {
export function setupWorker(
...handlers: Array<RequestHandler>
): SetupWorkerApi {
return new SetupWorkerApi(...handlers)
}
4 changes: 2 additions & 2 deletions src/setupWorker/start/utils/prepareStartHandler.ts
@@ -1,7 +1,7 @@
import { RequiredDeep } from '../../../typeUtils'
import { mergeRight } from '../../../utils/internal/mergeRight'
import {
SetupWorkerApi,
SetupWorker,
SetupWorkerInternalContext,
StartHandler,
StartOptions,
Expand Down Expand Up @@ -36,7 +36,7 @@ export function resolveStartOptions(
export function prepareStartHandler(
handler: StartHandler,
context: SetupWorkerInternalContext,
): SetupWorkerApi['start'] {
): SetupWorker['start'] {
return (initialOptions) => {
context.startOptions = resolveStartOptions(initialOptions)
return handler(context.startOptions, initialOptions || {})
Expand Down