-
-
Notifications
You must be signed in to change notification settings - Fork 233
feat: add @pinia-colada/sdk plugin #1680
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 18 commits
Commits
Show all changes
19 commits
Select commit
Hold shift + click to select a range
6e6bd4d
feat: add @pinia-colada/sdk plugin
josh-hemphill 7481efa
Merge branch 'hey-api:main' into main
josh-hemphill e3e92e8
updates
josh-hemphill 9954a24
Merge remote-tracking branch 'upstream/main' into pr/josh-hemphill/1680
josh-hemphill ec975c8
reworked
josh-hemphill bc189c4
Merge remote-tracking branch 'upstream/main' into pr/josh-hemphill/1680
josh-hemphill 4c0875b
Merge remote-tracking branch 'upstream/main'
josh-hemphill 19daedc
Merge branch 'main' of https://github.com/hey-api/openapi-ts
josh-hemphill 041602f
Merge branch 'main' of https://github.com/josh-hemphill/openapi-ts
josh-hemphill 4663638
Merge commit '4c0875b149defeb4d0e28e95c8ae2cdbb130761d'
josh-hemphill f75956e
Fix config type
josh-hemphill 428254f
finally working I think
josh-hemphill 9e4cc3d
ran changeset
josh-hemphill f7e0a90
Merge branch 'main' into main
josh-hemphill 87ab39a
Merge branch 'main' of https://github.com/hey-api/openapi-ts into jos…
mrlubos 6342479
chore: merge types
mrlubos 84944e8
chore: cleanup
mrlubos 7646db7
chore: remove old snapshots
mrlubos 714e8f9
chore: stub old imports
mrlubos 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
--- | ||
'@hey-api/openapi-ts': patch | ||
--- | ||
|
||
feat(plugin): add `@pinia/colada` plugin |
13 changes: 9 additions & 4 deletions
13
...pi-ts-tests/main/test/__snapshots__/3.0.x/plugins/@hey-api/schemas/default/schemas.gen.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
13 changes: 9 additions & 4 deletions
13
...pi-ts-tests/main/test/__snapshots__/3.1.x/plugins/@hey-api/schemas/default/schemas.gen.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
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
104 changes: 104 additions & 0 deletions
104
packages/openapi-ts/src/plugins/@pinia/colada/config.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 |
---|---|---|
@@ -0,0 +1,104 @@ | ||
import { definePluginConfig } from '../../shared/utils/config'; | ||
import { handler } from './plugin'; | ||
import type { PiniaColadaPlugin } from './types'; | ||
|
||
export const defaultConfig: PiniaColadaPlugin['Config'] = { | ||
config: { | ||
enablePaginationOnKey: undefined, | ||
errorHandling: 'specific', | ||
exportFromIndex: false, | ||
groupByTag: false, | ||
importPath: '@pinia/colada', | ||
includeTypes: true, | ||
prefixUse: true, | ||
resolveQuery: undefined, | ||
resolveQueryKey: undefined, | ||
suffixQueryMutation: true, | ||
useInfiniteQueries: false, | ||
}, | ||
dependencies: ['@hey-api/typescript'], | ||
handler: handler as PiniaColadaPlugin['Handler'], | ||
name: '@pinia/colada', | ||
output: '@pinia/colada', | ||
resolveConfig: (plugin, context) => { | ||
// plugin.config.infiniteQueryKeys = context.valueToObject({ | ||
// defaultValue: { | ||
// case: plugin.config.case ?? 'camelCase', | ||
// enabled: true, | ||
// name: '{{name}}InfiniteQueryKey', | ||
// tags: false, | ||
// }, | ||
// mappers: { | ||
// boolean: (enabled) => ({ enabled }), | ||
// function: (name) => ({ name }), | ||
// string: (name) => ({ name }), | ||
// }, | ||
// value: plugin.config.infiniteQueryKeys, | ||
// }); | ||
|
||
// plugin.config.infiniteQueryOptions = context.valueToObject({ | ||
// defaultValue: { | ||
// case: plugin.config.case ?? 'camelCase', | ||
// enabled: true, | ||
// meta: false, | ||
// name: '{{name}}InfiniteOptions', | ||
// }, | ||
// mappers: { | ||
// boolean: (enabled) => ({ enabled }), | ||
// function: (name) => ({ name }), | ||
// string: (name) => ({ name }), | ||
// }, | ||
// value: plugin.config.infiniteQueryOptions, | ||
// }); | ||
|
||
// plugin.config.mutationOptions = context.valueToObject({ | ||
// defaultValue: { | ||
// case: plugin.config.case ?? 'camelCase', | ||
// enabled: true, | ||
// meta: false, | ||
// name: '{{name}}Mutation', | ||
// }, | ||
// mappers: { | ||
// boolean: (enabled) => ({ enabled }), | ||
// function: (name) => ({ name }), | ||
// string: (name) => ({ name }), | ||
// }, | ||
// value: plugin.config.mutationOptions, | ||
// }); | ||
|
||
// plugin.config.queryKeys = context.valueToObject({ | ||
// defaultValue: { | ||
// case: plugin.config.case ?? 'camelCase', | ||
// enabled: true, | ||
// name: '{{name}}QueryKey', | ||
// tags: false, | ||
// }, | ||
// mappers: { | ||
// boolean: (enabled) => ({ enabled }), | ||
// function: (name) => ({ name }), | ||
// string: (name) => ({ name }), | ||
// }, | ||
// value: plugin.config.queryKeys, | ||
// }); | ||
|
||
// plugin.config.queryOptions = context.valueToObject({ | ||
// defaultValue: { | ||
// case: plugin.config.case ?? 'camelCase', | ||
// enabled: true, | ||
// meta: false, | ||
// name: '{{name}}Options', | ||
// }, | ||
// mappers: { | ||
// boolean: (enabled) => ({ enabled }), | ||
// function: (name) => ({ name }), | ||
// string: (name) => ({ name }), | ||
// }, | ||
// value: plugin.config.queryOptions, | ||
// }); | ||
}, | ||
}; | ||
|
||
/** | ||
* Type helper for `@pinia/colada` plugin, returns {@link Plugin.Config} object | ||
*/ | ||
export const defineConfig = definePluginConfig(defaultConfig); |
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 |
---|---|---|
@@ -0,0 +1,2 @@ | ||
export { defaultConfig, defineConfig } from './config'; | ||
export type { PiniaColadaPlugin } from './types'; |
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 |
---|---|---|
@@ -0,0 +1,26 @@ | ||
import type { GeneratedFile } from '../../../generate/file'; | ||
import type { IR } from '../../../ir/types'; | ||
import type { PiniaColadaPlugin } from './types'; | ||
import { createComposable } from './utils'; | ||
|
||
/** | ||
* Creates a mutation function for an operation | ||
*/ | ||
export const createMutationFunction = ({ | ||
context, | ||
file, | ||
operation, | ||
plugin, | ||
}: { | ||
context: IR.Context; | ||
file: GeneratedFile; | ||
operation: IR.OperationObject; | ||
plugin: PiniaColadaPlugin['Instance']; | ||
}) => { | ||
// Allow hooks to customize or skip mutation generation | ||
if (plugin.config.onMutation && plugin.config.onMutation(operation) === false) { | ||
return; | ||
} | ||
|
||
createComposable({ context, file, isQuery: false, operation, plugin }); | ||
}; |
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 |
---|---|---|
@@ -0,0 +1,59 @@ | ||
import { clientId } from '../../@hey-api/client-core/utils'; | ||
import { createMutationFunction } from './mutation'; | ||
import { createQueryFunction } from './query'; | ||
import type { PiniaColadaPlugin } from './types'; | ||
import { isQuery } from './utils'; | ||
|
||
export const handler: PiniaColadaPlugin['Handler'] = ({ plugin }) => { | ||
if (!plugin.config.groupByTag) { | ||
plugin.createFile({ | ||
id: plugin.name, | ||
path: plugin.output, | ||
}); | ||
} | ||
|
||
// Create files based on grouping strategy | ||
const getFile = (tag: string) => { | ||
if (!plugin.config.groupByTag) { | ||
return ( | ||
plugin.context.file({ id: plugin.name }) ?? | ||
plugin.createFile({ | ||
id: plugin.name, | ||
path: plugin.output, | ||
}) | ||
); | ||
} | ||
|
||
const fileId = `${plugin.name}/${tag}`; | ||
return ( | ||
plugin.context.file({ id: fileId }) ?? | ||
plugin.createFile({ | ||
id: fileId, | ||
path: `${plugin.output}/${tag}`, | ||
}) | ||
); | ||
}; | ||
|
||
plugin.forEach('operation', ({ operation }) => { | ||
const file = getFile(operation.tags?.[0] || 'default'); | ||
|
||
// Determine if the operation should be a query or mutation | ||
if (isQuery(operation, plugin)) { | ||
createQueryFunction({ context: plugin.context, file, operation, plugin }); | ||
} else { | ||
createMutationFunction({ context: plugin.context, file, operation, plugin }); | ||
} | ||
}) | ||
|
||
// Add client import to all generated files | ||
Object.entries(plugin.context.files).forEach(([fileId, file]) => { | ||
if (fileId.startsWith(plugin.name)) { | ||
// Make sure we have a client import | ||
file.import({ | ||
alias: '_heyApiClient', | ||
module: file.relativePathToFile({ context: plugin.context, id: clientId }), | ||
name: 'client', | ||
}); | ||
} | ||
}); | ||
}; |
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 |
---|---|---|
@@ -0,0 +1,25 @@ | ||
import type { GeneratedFile } from '../../../generate/file'; | ||
import type { IR } from '../../../ir/types'; | ||
import type { PiniaColadaPlugin } from './types'; | ||
import { createComposable } from './utils'; | ||
|
||
/** | ||
* Creates a query function for an operation | ||
*/ | ||
export const createQueryFunction = ({ | ||
context, | ||
file, | ||
operation, | ||
plugin, | ||
}: { | ||
context: IR.Context; | ||
file: GeneratedFile; | ||
operation: IR.OperationObject; | ||
plugin: PiniaColadaPlugin['Instance']; | ||
}) => { | ||
if (plugin.config.onQuery && plugin.config.onQuery(operation) === false) { | ||
return; | ||
} | ||
|
||
createComposable({ context, file, isQuery: true, operation, plugin }); | ||
}; |
Oops, something went wrong.
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.