-
-
Notifications
You must be signed in to change notification settings - Fork 329
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
Deprecate createQuery
and replace with createFunction
#1908
Merged
Merged
Changes from 3 commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
58bd6d5
Deprecate `createQuery` => Replace with `createFunction`
bharatkashyap 8c9d12e
Deprecate `createQuery` => Replace with `createFunction`
bharatkashyap 36e740c
Merge branch 'create-function' of github.com:bharatkashyap/mui-toolpa…
bharatkashyap 7d37f52
Fix: Jan review 1
bharatkashyap 429a55e
Merge branch 'master' into create-function
bharatkashyap 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 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 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 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 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 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 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 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 |
---|---|---|
@@ -0,0 +1,52 @@ | ||
import { TOOLPAD_FUNCTION } from './constants.js'; | ||
import { PrimitiveValueType } from './types.js'; | ||
|
||
interface ParameterTypeLookup { | ||
number: number; | ||
string: string; | ||
boolean: boolean; | ||
array: unknown[]; | ||
object: Record<string, unknown>; | ||
} | ||
|
||
export interface FunctionParameterConfig<P, K extends keyof P> { | ||
typeDef: PrimitiveValueType; | ||
defaultValue?: P[K]; | ||
} | ||
|
||
export interface CreateFunctionConfig<P> { | ||
parameters: { | ||
[K in keyof P]: FunctionParameterConfig<P, K>; | ||
}; | ||
} | ||
|
||
type CreateFunctionConfigParameters< | ||
C extends CreateFunctionConfig<CreateFunctionConfigParameters<C>>, | ||
> = FunctionResolverParams<C>['parameters']; | ||
|
||
export interface FunctionResolverParams< | ||
C extends CreateFunctionConfig<CreateFunctionConfigParameters<C>>, | ||
> { | ||
parameters: { | ||
[K in keyof C['parameters']]: ParameterTypeLookup[C['parameters'][K]['typeDef']['type']]; | ||
}; | ||
} | ||
|
||
export interface FunctionResolver< | ||
C extends CreateFunctionConfig<CreateFunctionConfigParameters<C>>, | ||
> { | ||
(params: FunctionResolverParams<C>): Promise<unknown>; | ||
} | ||
|
||
export interface ToolpadFunction<C extends CreateFunctionConfig<CreateFunctionConfigParameters<C>>> | ||
extends FunctionResolver<C> { | ||
[TOOLPAD_FUNCTION]: C; | ||
} | ||
|
||
export default function createFunction< | ||
C extends CreateFunctionConfig<CreateFunctionConfigParameters<C>>, | ||
>(resolver: FunctionResolver<C>, config?: C) { | ||
return Object.assign(resolver, { | ||
[TOOLPAD_FUNCTION]: config || { parameters: {} }, | ||
}); | ||
} |
This file contains 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 |
---|---|---|
|
@@ -9,11 +9,19 @@ interface QueryParameterTypeLookup { | |
object: Record<string, unknown>; | ||
} | ||
|
||
/** | ||
* @deprecated | ||
* QueryParameterConfig is deprecated. Use FunctionParameterConfig instead. | ||
*/ | ||
export interface QueryParameterConfig<P, K extends keyof P> { | ||
typeDef: PrimitiveValueType; | ||
defaultValue?: P[K]; | ||
} | ||
|
||
/** | ||
* @deprecated | ||
* CreateQueryConfig is deprecated. Use CreateFunctionConfig instead. | ||
*/ | ||
export interface CreateQueryConfig<P> { | ||
parameters: { | ||
[K in keyof P]: QueryParameterConfig<P, K>; | ||
|
@@ -23,21 +31,37 @@ export interface CreateQueryConfig<P> { | |
type CreateQueryConfigParameters<C extends CreateQueryConfig<CreateQueryConfigParameters<C>>> = | ||
QueryResolverParams<C>['parameters']; | ||
|
||
/** | ||
* @deprecated | ||
* QueryResolverParams is deprecated. Use FunctionResolverParams instead. | ||
*/ | ||
export interface QueryResolverParams<C extends CreateQueryConfig<CreateQueryConfigParameters<C>>> { | ||
parameters: { | ||
[K in keyof C['parameters']]: QueryParameterTypeLookup[C['parameters'][K]['typeDef']['type']]; | ||
}; | ||
} | ||
|
||
/** | ||
* @deprecated | ||
* QueryResolver is deprecated. Use FunctionResolver instead. | ||
*/ | ||
export interface QueryResolver<C extends CreateQueryConfig<CreateQueryConfigParameters<C>>> { | ||
(params: QueryResolverParams<C>): Promise<unknown>; | ||
} | ||
|
||
/** | ||
* @deprecated | ||
* ToolpadQuery is deprecated. Use ToolpaFunction instead. | ||
*/ | ||
export interface ToolpadQuery<C extends CreateQueryConfig<CreateQueryConfigParameters<C>>> | ||
extends QueryResolver<C> { | ||
[TOOLPAD_QUERY]: C; | ||
} | ||
|
||
/** | ||
* @deprecated | ||
* createQuery is deprecated. Use createFunction instead. | ||
*/ | ||
export default function createQuery<C extends CreateQueryConfig<CreateQueryConfigParameters<C>>>( | ||
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. Is it possible to avoid duplication this way? import createFunction from './createFuction'
/**
* @deprecated
* createQuery is deprecated. Use createFunction instead.
*/
const createQuery = createFunction
export default createQuery |
||
resolver: QueryResolver<C>, | ||
config?: C, | ||
|
This file contains 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 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,3 +1,6 @@ | ||
export * from './constants.js'; | ||
export { default as createQuery } from './createQuery.js'; | ||
export * from './createQuery.js'; | ||
|
||
export { default as createFunction } from './createFunction.js'; | ||
export * from './createFunction.js'; |
This file contains 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
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.
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.
TOOLPAD_QUERY is not public API, you can just rename