Skip to content

Commit

Permalink
chore: format code
Browse files Browse the repository at this point in the history
  • Loading branch information
7nohe committed Oct 31, 2023
1 parent ea0db30 commit 8788385
Show file tree
Hide file tree
Showing 5 changed files with 63 additions and 59 deletions.
32 changes: 15 additions & 17 deletions examples/react-app/src/App.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,34 +4,33 @@ import {
useDefaultClientFindPets,
useDefaultClientFindPetsKey,
} from "../openapi/queries";
import { useState } from 'react';
import { queryClient } from './queryClient';
import { useState } from "react";
import { queryClient } from "./queryClient";

function App() {

const [tags, _setTags] = useState<string[]>([]);
const [limit, _setLimit] = useState<number>(10);

const { data, error, refetch } = useDefaultClientFindPets(
{ tags, limit },
);
const { data, error, refetch } = useDefaultClientFindPets({ tags, limit });

const { mutate: addPet } = useDefaultClientAddPet();

if (error) return (
<div>
<p>Failed to fetch pets</p>
<button onClick={() => refetch()}>Retry</button>
</div>
);
if (error)
return (
<div>
<p>Failed to fetch pets</p>
<button onClick={() => refetch()}>Retry</button>
</div>
);

return (
<div className="App">
<h1>Pet List</h1>
<ul>
{data instanceof Array && data?.map((pet, index) => (
<li key={pet.id + "-" + index}>{pet.name}</li>
))}
{data instanceof Array &&
data?.map((pet, index) => (
<li key={pet.id + "-" + index}>{pet.name}</li>
))}
</ul>
<button
onClick={() => {
Expand All @@ -44,8 +43,7 @@ function App() {
queryClient.invalidateQueries({
queryKey: [useDefaultClientFindPetsKey],
});
console.log("success")

console.log("success");
},
onError: (error) => console.error(error),
}
Expand Down
6 changes: 4 additions & 2 deletions src/createExports.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,14 @@
import ts from "typescript";
import { sync } from "glob";
import { sync } from "glob";
import { join } from "path";
import fs from "fs";
import { createUseQuery } from "./createUseQuery";
import { createUseMutation } from "./createUseMutation";

export const createExports = (generatedClientsPath: string) => {
const services = sync(join(generatedClientsPath, 'services', '*.ts').replace(/\\/g, '/'));
const services = sync(
join(generatedClientsPath, "services", "*.ts").replace(/\\/g, "/")
);
const nodes = services.map((servicePath) =>
ts.createSourceFile(
servicePath, // fileName
Expand Down
8 changes: 6 additions & 2 deletions src/createImports.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,12 @@ import { extname, basename, posix } from "path";
const { join } = posix;

export const createImports = (generatedClientsPath: string) => {
const models = sync(join(generatedClientsPath, 'models', '*.ts').replace(/\\/g, '/'));
const services = sync(join(generatedClientsPath, 'services', '*.ts').replace(/\\/g, '/'));
const models = sync(
join(generatedClientsPath, "models", "*.ts").replace(/\\/g, "/")
);
const services = sync(
join(generatedClientsPath, "services", "*.ts").replace(/\\/g, "/")
);
return [
ts.factory.createImportDeclaration(
undefined,
Expand Down
6 changes: 3 additions & 3 deletions src/createSource.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,9 +26,9 @@ export const createSource = (outputPath: string) => {

const node = createSourceFile(outputPath);

const result = `// generated with @7nohe/openapi-react-query-codegen@${version} \n` + printer.printNode(ts.EmitHint.Unspecified, node, resultFile);


const result =
`// generated with @7nohe/openapi-react-query-codegen@${version} \n` +
printer.printNode(ts.EmitHint.Unspecified, node, resultFile);

return result;
};
70 changes: 35 additions & 35 deletions src/createUseQuery.ts
Original file line number Diff line number Diff line change
Expand Up @@ -122,9 +122,7 @@ export const createUseQuery = (
undefined,
"TError",
undefined,
ts.factory.createKeywordTypeNode(
ts.SyntaxKind.UnknownKeyword
)
ts.factory.createKeywordTypeNode(ts.SyntaxKind.UnknownKeyword)
),
]),
[
Expand Down Expand Up @@ -206,7 +204,9 @@ export const createUseQuery = (
)
),
])
: ts.factory.createArrayLiteralExpression([])
: ts.factory.createArrayLiteralExpression(
[]
)
)
)
),
Expand Down Expand Up @@ -244,38 +244,38 @@ export const createUseQuery = (
]),
]
),
// Omit<UseQueryResult<Awaited<ReturnType<typeof myClass.myMethod>>, TError>, 'data'> & { data: TData };
ts.factory.createIntersectionTypeNode([
ts.factory.createTypeReferenceNode(
ts.factory.createIdentifier("Omit"),
[
ts.factory.createTypeReferenceNode(
ts.factory.createIdentifier("UseQueryResult"),
[
awaitedResponseDataType,
ts.factory.createTypeReferenceNode(
ts.factory.createIdentifier("TError"),
undefined
),
]
),
ts.factory.createLiteralTypeNode(
ts.factory.createStringLiteral("data")
),
]
),
ts.factory.createTypeLiteralNode([
ts.factory.createPropertySignature(
undefined,
ts.factory.createIdentifier("data"),
undefined,
ts.factory.createTypeReferenceNode(
ts.factory.createIdentifier("TData"),
undefined
)
// Omit<UseQueryResult<Awaited<ReturnType<typeof myClass.myMethod>>, TError>, 'data'> & { data: TData };
ts.factory.createIntersectionTypeNode([
ts.factory.createTypeReferenceNode(
ts.factory.createIdentifier("Omit"),
[
ts.factory.createTypeReferenceNode(
ts.factory.createIdentifier("UseQueryResult"),
[
awaitedResponseDataType,
ts.factory.createTypeReferenceNode(
ts.factory.createIdentifier("TError"),
undefined
),
]
),
ts.factory.createLiteralTypeNode(
ts.factory.createStringLiteral("data")
),
]
),
]),
])
ts.factory.createTypeLiteralNode([
ts.factory.createPropertySignature(
undefined,
ts.factory.createIdentifier("data"),
undefined,
ts.factory.createTypeReferenceNode(
ts.factory.createIdentifier("TData"),
undefined
)
),
]),
])
)
)
),
Expand Down

0 comments on commit 8788385

Please sign in to comment.