-
Notifications
You must be signed in to change notification settings - Fork 4
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
Convert to TypeScript #10
Changes from 1 commit
b3951c8
139ecd7
72973c8
6bb40f4
c8cc6d8
19ef002
cb70e24
5c04bbf
5b26988
f52ba1d
6cf8ff7
9db1dae
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -6,7 +6,11 @@ import { | |
type SetupWorkerApi, | ||
} from 'msw'; | ||
import type { Server } from 'miragejs'; | ||
import type { RouteHandler, ServerConfig } from 'miragejs/server'; | ||
import type { | ||
HandlerOptions, | ||
RouteHandler, | ||
ServerConfig, | ||
} from 'miragejs/server'; | ||
import type { AnyFactories, AnyModels, AnyRegistry } from 'miragejs/-types'; | ||
|
||
type RawHandler = RouteHandler<AnyRegistry> | {}; | ||
|
@@ -25,6 +29,13 @@ type HTTPVerb = | |
| 'options' | ||
| 'head'; | ||
|
||
type BaseHandler = ( | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I had thought about this. Really baseHandler should be defined in mirageJS proper and this implement it to ensure any changes in the handler in mirage are respected by the pretender/msw modules. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Also it would avoid the need to create these again for the pretender repo There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yeah that's a great point. In fact, I think the handlers defined in mirage are incorrect:
That's only one format, but they can also be just options, or just a handler, or a number of other formats (unfortunately). I think there's still quite a bit of cleanup / deduplication to be done, but hopefully this is at least a baby step in the right direction. |
||
path: string, | ||
// TODO: infer registry | ||
handler?: RouteHandler<AnyRegistry>, | ||
options?: HandlerOptions | ||
) => void; | ||
|
||
type MirageServer = { | ||
registerRouteHandler: ( | ||
verb: HTTPVerb, | ||
|
@@ -33,15 +44,15 @@ type MirageServer = { | |
customizedCode?: ResponseCode, | ||
options?: unknown | ||
) => (request: RestRequest) => ResponseData | PromiseLike<ResponseData>; | ||
// TODO: strengthen | ||
get?: Function; | ||
post?: Function; | ||
put?: Function; | ||
delete?: Function; | ||
del?: Function; | ||
patch?: Function; | ||
head?: Function; | ||
options?: Function; | ||
|
||
get?: BaseHandler; | ||
post?: BaseHandler; | ||
put?: BaseHandler; | ||
delete?: BaseHandler; | ||
del?: BaseHandler; | ||
patch?: BaseHandler; | ||
head?: BaseHandler; | ||
options?: BaseHandler; | ||
}; | ||
|
||
type RouteOptions = { | ||
|
@@ -134,19 +145,19 @@ export default class MswConfig { | |
|
||
mirageServer?: MirageServer; | ||
|
||
// TODO: infer models and factories | ||
mirageConfig?: ServerConfig<AnyModels, AnyFactories>; | ||
|
||
handlers: RestHandler[] = []; | ||
|
||
// TODO: strengthen | ||
get?: Function; | ||
post?: Function; | ||
put?: Function; | ||
delete?: Function; | ||
del?: Function; | ||
patch?: Function; | ||
head?: Function; | ||
options?: Function; | ||
get?: BaseHandler; | ||
post?: BaseHandler; | ||
put?: BaseHandler; | ||
delete?: BaseHandler; | ||
del?: BaseHandler; | ||
patch?: BaseHandler; | ||
head?: BaseHandler; | ||
options?: BaseHandler; | ||
|
||
create( | ||
server: MirageServer, | ||
|
@@ -229,6 +240,7 @@ export default class MswConfig { | |
}); | ||
} | ||
|
||
// TODO: infer models and factories | ||
config(mirageConfig: ServerConfig<AnyModels, AnyFactories>) { | ||
/** | ||
Sets a string to prefix all route handler URLs with. | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This type isn't actually used, but because of the way the mirage types are defined, the
/server
types won't be found unless something is imported from the top level, in which case the other modules are cached and used as well.