-
Notifications
You must be signed in to change notification settings - Fork 1.6k
Clean up middleware signature #5504
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
Merged
Merged
Changes from 1 commit
Commits
Show all changes
26 commits
Select commit
Hold shift + click to select a range
5bae495
Clean up middleware signature
compulim d8262f5
Cleaner ~types
compulim c7943e8
Remove init and clean types
compulim 5469973
Use createMiddleware
compulim adc627a
Use createXXXMiddleware
compulim 1684502
Use createXXXMiddleware
compulim 2c88f9d
Export schema
compulim c6f55f7
Move to props schema
compulim e084105
Sort import
compulim 617eaec
Add enhancer function check
compulim cf32b21
Add more checks
compulim f179c88
Clean up
compulim ff5054e
Add comment
compulim e9375b7
Better middleware array check
compulim 3f53818
Fix test
compulim 8950059
Fix flaky test
compulim 74219ca
Better typing
compulim 340642f
Better types
compulim f64baac
Clean up
compulim 5dd4494
Update warning message
compulim f409225
Clean up
compulim f4752cd
Add entry
compulim a763781
Remove comment
compulim 83ed2b1
Typo
compulim 352b7f8
Mark middleware as readonly
compulim d5439b5
Remove return
compulim File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,15 +1,20 @@ | ||
| import { type ActivityBorderDecoratorMiddleware } from './ActivityBorder/private/ActivityBorderDecoratorMiddleware'; | ||
| import { type activityBorderDecoratorTypeName } from './ActivityBorder/types'; | ||
| import { activityBorderDecoratorTypeName } from './ActivityBorder/types'; | ||
| import { type ActivityGroupingDecoratorMiddleware } from './ActivityGrouping/private/ActivityGroupingDecoratorMiddleware'; | ||
| import { type activityGroupingDecoratorTypeName } from './ActivityGrouping/types'; | ||
| import { activityGroupingDecoratorTypeName } from './ActivityGrouping/types'; | ||
|
|
||
| export type DecoratorMiddlewareTypes = { | ||
| [activityBorderDecoratorTypeName]: ReturnType<ActivityBorderDecoratorMiddleware>; | ||
| [activityGroupingDecoratorTypeName]: ReturnType<ActivityGroupingDecoratorMiddleware>; | ||
| }; | ||
| export type DecoratorMiddleware = | ||
| | ((init: typeof activityBorderDecoratorTypeName) => ReturnType<ActivityBorderDecoratorMiddleware> | false) | ||
| | ((init: typeof activityGroupingDecoratorTypeName) => ReturnType<ActivityGroupingDecoratorMiddleware> | false); | ||
|
|
||
| export type DecoratorMiddlewareInit = keyof DecoratorMiddlewareTypes; | ||
| export function activityBorderMiddleware( | ||
| enhancer: ReturnType<ActivityBorderDecoratorMiddleware> | ||
| ): (init: string) => ReturnType<ActivityBorderDecoratorMiddleware> | false { | ||
| return init => init === activityBorderDecoratorTypeName && enhancer; | ||
| } | ||
|
|
||
| export interface DecoratorMiddleware { | ||
| (init: keyof DecoratorMiddlewareTypes): DecoratorMiddlewareTypes[typeof init] | false; | ||
| export function activityGroupingMiddleware( | ||
| enhancer: ReturnType<ActivityGroupingDecoratorMiddleware> | ||
| ): (init: string) => ReturnType<ActivityGroupingDecoratorMiddleware> | false { | ||
| return init => init === activityGroupingDecoratorTypeName && enhancer; | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,23 +1,30 @@ | ||
| import templateMiddleware from './private/templateMiddleware'; | ||
| import templateMiddleware, { | ||
| type InferInit, | ||
| type InferMiddleware, | ||
| type InferProps, | ||
| type InferRequest | ||
| } from './private/templateMiddleware'; | ||
|
|
||
| const template = templateMiddleware<undefined, void, { className?: string | undefined }>('sendBoxMiddleware'); | ||
|
|
||
| const { | ||
| initMiddleware: initSendBoxMiddleware, | ||
| Provider: SendBoxMiddlewareProvider, | ||
| Proxy: SendBoxMiddlewareProxy, | ||
| // False positive, `types` is used for its typing. | ||
| // eslint-disable-next-line @typescript-eslint/no-unused-vars | ||
| types | ||
| } = templateMiddleware<undefined, void, { className?: string | undefined }>('sendBoxMiddleware'); | ||
| '~types': _types | ||
| } = template; | ||
|
|
||
| type SendBoxMiddleware = typeof types.middleware; | ||
| type SendBoxMiddlewareProps = typeof types.props; | ||
| type SendBoxMiddlewareRequest = typeof types.request; | ||
| type SendBoxMiddleware = InferMiddleware<typeof template>; | ||
| type SendBoxMiddlewareInit = InferInit<typeof template>; | ||
| type SendBoxMiddlewareProps = InferProps<typeof template>; | ||
| type SendBoxMiddlewareRequest = InferRequest<typeof template>; | ||
|
|
||
| export { | ||
| initSendBoxMiddleware, | ||
| SendBoxMiddlewareProvider, | ||
| SendBoxMiddlewareProxy, | ||
| initSendBoxMiddleware, | ||
| type SendBoxMiddleware, | ||
| type SendBoxMiddlewareInit, | ||
| type SendBoxMiddlewareProps, | ||
| type SendBoxMiddlewareRequest | ||
| }; |
25 changes: 16 additions & 9 deletions
25
packages/api/src/hooks/internal/SendBoxToolbarMiddleware.ts
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,23 +1,30 @@ | ||
| import templateMiddleware from './private/templateMiddleware'; | ||
| import templateMiddleware, { | ||
| type InferInit, | ||
| type InferMiddleware, | ||
| type InferProps, | ||
| type InferRequest | ||
| } from './private/templateMiddleware'; | ||
|
|
||
| const template = templateMiddleware<undefined, void, { className?: string | undefined }>('sendBoxToolbarMiddleware'); | ||
|
|
||
| const { | ||
| initMiddleware: initSendBoxToolbarMiddleware, | ||
| Provider: SendBoxToolbarMiddlewareProvider, | ||
| Proxy: SendBoxToolbarMiddlewareProxy, | ||
| // False positive, `types` is used for its typing. | ||
| // eslint-disable-next-line @typescript-eslint/no-unused-vars | ||
| types | ||
| } = templateMiddleware<undefined, void, { className?: string | undefined }>('sendBoxToolbarMiddleware'); | ||
| '~types': _types | ||
| } = template; | ||
|
|
||
| type SendBoxToolbarMiddleware = typeof types.middleware; | ||
| type SendBoxToolbarMiddlewareProps = typeof types.props; | ||
| type SendBoxToolbarMiddlewareRequest = typeof types.request; | ||
| type SendBoxToolbarMiddleware = InferMiddleware<typeof template>; | ||
| type SendBoxToolbarMiddlewareInit = InferInit<typeof template>; | ||
| type SendBoxToolbarMiddlewareProps = InferProps<typeof template>; | ||
| type SendBoxToolbarMiddlewareRequest = InferRequest<typeof template>; | ||
|
|
||
| export { | ||
| initSendBoxToolbarMiddleware, | ||
| SendBoxToolbarMiddlewareProvider, | ||
| SendBoxToolbarMiddlewareProxy, | ||
| initSendBoxToolbarMiddleware, | ||
| type SendBoxToolbarMiddleware, | ||
| type SendBoxToolbarMiddlewareInit, | ||
| type SendBoxToolbarMiddlewareProps, | ||
| type SendBoxToolbarMiddlewareRequest | ||
| }; |
10 changes: 7 additions & 3 deletions
10
packages/api/src/hooks/internal/private/templateMiddleware.ts
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,4 +1,8 @@ | ||
| import templateMiddleware from '../../../decorator/private/templateMiddleware'; | ||
|
compulim marked this conversation as resolved.
|
||
|
|
||
| // TODO: We should move them to a common directory. | ||
| export default templateMiddleware; | ||
| export { | ||
| default, | ||
| type InferInit, | ||
| type InferMiddleware, | ||
| type InferProps, | ||
| type InferRequest | ||
| } from '../../../decorator/private/templateMiddleware'; | ||
14 changes: 5 additions & 9 deletions
14
...nent/src/Middleware/ActivityGrouping/createDefaultActivityGroupingDecoratorMiddleware.tsx
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,22 +1,18 @@ | ||
| import { | ||
| type DecoratorMiddleware, | ||
| type DecoratorMiddlewareInit, | ||
| type DecoratorMiddlewareTypes | ||
| } from 'botframework-webchat-api/decorator'; | ||
| import { activityGroupingMiddleware, type DecoratorMiddleware } from 'botframework-webchat-api/decorator'; | ||
| import RenderActivityGrouping from './ui/RenderActivityGrouping'; | ||
| import SenderGrouping from './ui/SenderGrouping/SenderGrouping'; | ||
| import StatusGrouping from './ui/StatusGrouping/StatusGrouping'; | ||
|
|
||
| export default function createDefaultActivityGroupingDecoratorMiddleware(): readonly DecoratorMiddleware[] { | ||
| return Object.freeze([ | ||
| (init: DecoratorMiddlewareInit) => | ||
| init === 'activity grouping' && | ||
| ((() => | ||
| activityGroupingMiddleware( | ||
| () => | ||
| ({ groupingName }) => | ||
| groupingName === 'sender' | ||
| ? SenderGrouping | ||
| : groupingName === 'status' | ||
| ? StatusGrouping | ||
| : RenderActivityGrouping) satisfies DecoratorMiddlewareTypes['activity grouping']) | ||
| : RenderActivityGrouping | ||
| ) | ||
| ]); | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.