Skip to content

Commit

Permalink
Merge branch 'folder-structure' into main
Browse files Browse the repository at this point in the history
  • Loading branch information
Alduino committed Jul 16, 2022
2 parents a5c7d93 b04f828 commit 828e3e0
Show file tree
Hide file tree
Showing 16 changed files with 259 additions and 70 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 16,7 @@ out/

# production
build
dist

# misc
.DS_Store
Expand Down
37 changes: 10 additions & 27 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

17 changes: 16 additions & 1 deletion project/package.json
Original file line number Diff line number Diff line change
@@ -1,6 1,21 @@
{
"name": "safe-nappi",
"main": "dist/index.js",
"module": "dist/index.mjs",
"scripts": {
"build": "tsup",
"watch": "tsup --watch"
},
"devDependencies": {
"@types/node": "18.0.5",
"next": "12.2.2",
"react": "18.2.0",
"react-dom": "18.2.0",
"tsup": "^6.1.3"
},
"peerDependencies": {
"next": "12.2.2",
"react": "18.2.0",
"react-dom": "18.2.0"
}
}
}
1 change: 1 addition & 0 deletions project/src/ApiResponse.ts
Original file line number Diff line number Diff line change
@@ -0,0 1 @@
export type ApiResponse<T extends string> = never;
4 changes: 4 additions & 0 deletions project/src/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 1,4 @@
export {nappiPlugin} from "./plugin";
export type {InferResponse} from "./inferResponse";
export type {ApiResponse} from "./ApiResponse";
export * from "./real-types";
15 changes: 6 additions & 9 deletions project/src/jsonFetch.ts
Original file line number Diff line number Diff line change
@@ -1,12 1,9 @@
interface SampleApiPathMap {
"/api/user": { data: { user: { id: number; name: string } } };
[key: `/api/some/${number}/dynamic`]: { dynamic: boolean };
}
export const jsonFetch = async (path: string, query?: Record<string, string>): Promise<unknown> => {
if (query) {
const queryObj = new URLSearchParams(query);
path = `?${queryObj.toString()}`;
}

export const jsonFetch = async <T extends keyof SampleApiPathMap>(
path: T
): Promise<SampleApiPathMap[T]> => {
const res = await fetch(path);
const data = await res.json();
return data as SampleApiPathMap[T];
return await res.json();
};
Loading

0 comments on commit 828e3e0

Please sign in to comment.