-
-
Notifications
You must be signed in to change notification settings - Fork 25
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
refactor: split file generation and add suspense exports in own file
- Loading branch information
1 parent
e7117e1
commit 60fe3bd
Showing
11 changed files
with
873 additions
and
321 deletions.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
import { useDefaultClientFindPetsSuspense } from "../../openapi/queries/suspense"; | ||
|
||
export const SuspenseChild = () => { | ||
const { data } = useDefaultClientFindPetsSuspense({ tags: [], limit: 10 }); | ||
|
||
if (!Array.isArray(data)) { | ||
return <div>Error!</div>; | ||
} | ||
|
||
return ( | ||
<ul> | ||
{data?.map((pet, index) => ( | ||
<li key={pet.id}>{pet.name}</li> | ||
))} | ||
</ul> | ||
); | ||
}; |
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,12 @@ | ||
import { Suspense } from "react"; | ||
import { SuspenseChild } from "./SuspenseChild"; | ||
|
||
export const SuspenseParent = () => { | ||
return ( | ||
<> | ||
<Suspense fallback={<>loading...</>}> | ||
<SuspenseChild /> | ||
</Suspense> | ||
</> | ||
); | ||
}; |
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,7 +1,56 @@ | ||
import { type PathLike } from "fs"; | ||
import { stat } from "fs/promises"; | ||
import ts, { JSDocComment, NodeArray, SourceFile } from "typescript"; | ||
|
||
export const TData = ts.factory.createIdentifier("TData"); | ||
export const TError = ts.factory.createIdentifier("TError"); | ||
export const TContext = ts.factory.createIdentifier("TContext"); | ||
|
||
export const queryKeyGenericType = | ||
ts.factory.createTypeReferenceNode("TQueryKey"); | ||
export const queryKeyConstraint = ts.factory.createTypeReferenceNode("Array", [ | ||
ts.factory.createKeywordTypeNode(ts.SyntaxKind.UnknownKeyword), | ||
]); | ||
|
||
export const capitalizeFirstLetter = (str: string) => { | ||
return str.charAt(0).toUpperCase() + str.slice(1); | ||
}; | ||
|
||
export const lowercaseFirstLetter = (str: string) => { | ||
return str.charAt(0).toLowerCase() + str.slice(1); | ||
}; | ||
|
||
export const getNameFromMethod = ( | ||
method: ts.MethodDeclaration, | ||
node: ts.SourceFile | ||
) => { | ||
return method.name.getText(node); | ||
}; | ||
|
||
export type MethodDescription = { | ||
className: string; | ||
node: SourceFile; | ||
method: ts.MethodDeclaration; | ||
methodBlock: ts.Block; | ||
httpMethodName: string; | ||
jsDoc: (string | NodeArray<JSDocComment> | undefined)[]; | ||
isDeprecated: boolean; | ||
}; | ||
|
||
export async function exists(f: PathLike) { | ||
try { | ||
await stat(f); | ||
return true; | ||
} catch { | ||
return false; | ||
} | ||
} | ||
|
||
const Common = "Common"; | ||
|
||
export function BuildCommonTypeName(name: string | ts.Identifier) { | ||
if (typeof name === "string") { | ||
return ts.factory.createIdentifier(`${Common}.${name}`); | ||
} | ||
return ts.factory.createIdentifier(`${Common}.${name.text}`); | ||
} |
Oops, something went wrong.