mirror of
https://github.com/harness/drone.git
synced 2025-05-02 13:40:22 +00:00
21 lines
1.0 KiB
JavaScript
21 lines
1.0 KiB
JavaScript
const { camel } = require("case");
|
|
|
|
module.exports = ({ componentName, verb, route, description, genericsTypes, paramsInPath, paramsTypes }, basePath) => {
|
|
const propsType = type =>
|
|
`${type}UsingFetchProps<${genericsTypes}>${paramsInPath.length ? ` & {${paramsTypes}}` : ""}`;
|
|
|
|
if (verb === "get") {
|
|
return `${description}export const ${camel(componentName)}Promise = (${
|
|
paramsInPath.length ? `{${paramsInPath.join(", ")}, ...props}` : "props"
|
|
}: ${propsType(
|
|
"Get",
|
|
)}, signal?: RequestInit["signal"]) => getUsingFetch<${genericsTypes}>(${basePath}, \`${route}\`, props, signal);\n\n`
|
|
}
|
|
else {
|
|
return `${description}export const ${camel(componentName)}Promise = (${
|
|
paramsInPath.length ? `{${paramsInPath.join(", ")}, ...props}` : "props"
|
|
}: ${propsType(
|
|
"Mutate",
|
|
)}, signal?: RequestInit["signal"]) => mutateUsingFetch<${genericsTypes}>("${verb.toUpperCase()}", ${basePath}, \`${route}\`, props, signal);\n\n`;
|
|
}
|
|
} |