Skip to content

Commit 2673021

Browse files
committed
feat: finish rpc
1 parent a9fbbe1 commit 2673021

34 files changed

+624
-383
lines changed

.prettierignore

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,16 @@
1+
# Packages
2+
node_modules
3+
14
# Package Managers
25
package-lock.json
36
pnpm-lock.yaml
47
yarn.lock
8+
bun.lock
59
bun.lockb
10+
11+
# Output
12+
/.svelte-kit
13+
14+
# Env
15+
.env.*
16+
!.env.example

.prettierrc

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
11
{
22
"useTabs": true,
3+
"tabWidth": 4,
34
"singleQuote": true,
4-
"printWidth": 80,
5+
"printWidth": 100,
56
"singleAttributePerLine": true,
67
"svelteBracketNewLine": true,
78
"quoteProps": "consistent",
@@ -13,5 +14,6 @@
1314
"parser": "svelte"
1415
}
1516
}
16-
]
17+
],
18+
"tailwindFunctions": ["cn", "tv"]
1719
}

bun.lockb

11.6 KB
Binary file not shown.

components.json

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
{
2+
"$schema": "https://next.shadcn-svelte.com/schema.json",
3+
"style": "default",
4+
"tailwind": {
5+
"config": "tailwind.config.ts",
6+
"css": "./src/styles/app.css",
7+
"baseColor": "neutral"
8+
},
9+
"aliases": {
10+
"components": "$lib/components",
11+
"utils": "$lib/utils",
12+
"ui": "$lib/components/ui",
13+
"hooks": "$lib/hooks"
14+
},
15+
"typescript": true,
16+
"registry": "https://next.shadcn-svelte.com/registry"
17+
}

eslint.config.js

Lines changed: 17 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -9,24 +9,21 @@ import svelteConfig from './svelte.config.js';
99

1010
const gitignorePath = fileURLToPath(new URL('./.gitignore', import.meta.url));
1111

12-
export default ts.config(
12+
const config = ts.config(
1313
includeIgnoreFile(gitignorePath),
1414
js.configs.recommended,
1515
...ts.configs.recommended,
1616
...svelte.configs.recommended,
1717
prettier,
18-
...svelte.configs['flat/prettier'],
18+
...svelte.configs.prettier,
1919
{
2020
languageOptions: {
21-
globals: {
22-
...globals.browser,
23-
...globals.node,
24-
},
21+
globals: { ...globals.browser, ...globals.node },
2522
},
23+
rules: { 'no-undef': 'off' },
2624
},
2725
{
2826
files: ['**/*.svelte', '**/*.svelte.ts', '**/*.svelte.js'],
29-
ignores: ['eslint.config.js', 'svelte.config.js'],
3027
languageOptions: {
3128
parserOptions: {
3229
projectService: true,
@@ -36,4 +33,17 @@ export default ts.config(
3633
},
3734
},
3835
},
36+
{
37+
rules: {
38+
'@typescript-eslint/no-unused-vars': [
39+
'error',
40+
{
41+
argsIgnorePattern: '^_',
42+
varsIgnorePattern: '^_',
43+
},
44+
],
45+
},
46+
},
3947
);
48+
49+
export default config;

package.json

Lines changed: 23 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -11,31 +11,35 @@
1111
"check": "svelte-kit sync && svelte-check --tsconfig ./tsconfig.json",
1212
"check:watch": "svelte-kit sync && svelte-check --tsconfig ./tsconfig.json --watch",
1313
"format": "prettier --write .",
14-
"lint": "prettier --check . && eslint .",
15-
"cache:delete": "bun pm cache rm -g -f"
14+
"lint": "prettier --check . && eslint ."
1615
},
1716
"devDependencies": {
18-
"@eslint/compat": "^1.2.7",
19-
"@eslint/js": "^9.21.0",
20-
"@sveltejs/adapter-auto": "^4.0.0",
21-
"@sveltejs/kit": "^2.17.3",
17+
"@eslint/compat": "^1.2.8",
18+
"@eslint/js": "^9.23.0",
19+
"@sveltejs/adapter-auto": "^6.0.0",
20+
"@sveltejs/kit": "^2.20.3",
2221
"@sveltejs/vite-plugin-svelte": "^5.0.3",
23-
"@tailwindcss/vite": "^4.0.9",
24-
"eslint": "^9.21.0",
25-
"eslint-config-prettier": "^10.0.2",
26-
"eslint-plugin-svelte": "^2.46.1",
22+
"@tailwindcss/vite": "^4.1.2",
23+
"bits-ui": "^1.3.16",
24+
"clsx": "^2.1.1",
25+
"eslint": "^9.23.0",
26+
"eslint-config-prettier": "^10.1.1",
27+
"eslint-plugin-svelte": "^3.5.1",
2728
"globals": "^16.0.0",
28-
"prettier": "^3.5.2",
29+
"mode-watcher": "^0.5.1",
30+
"prettier": "^3.5.3",
2931
"prettier-plugin-svelte": "^3.3.3",
3032
"prettier-plugin-tailwindcss": "^0.6.11",
31-
"svelte": "^5.20.4",
32-
"svelte-check": "^4.1.4",
33-
"tailwindcss": "^4.0.9",
34-
"typescript": "^5.7.3",
35-
"typescript-eslint": "^8.25.0",
36-
"vite": "^6.2.0"
37-
},
38-
"dependencies": {
33+
"svelte": "^5.25.6",
34+
"svelte-check": "^4.1.5",
35+
"svelte-sonner": "^0.3.28",
36+
"tailwind-merge": "^3.1.0",
37+
"tailwind-variants": "^1.0.0",
38+
"tailwindcss": "^4.1.2",
39+
"tw-animate-css": "^1.2.5",
40+
"typescript": "^5.8.2",
41+
"typescript-eslint": "^8.29.0",
42+
"vite": "^6.2.5",
3943
"zod": "^3.24.2"
4044
}
4145
}

src/app.css

Lines changed: 0 additions & 1 deletion
This file was deleted.

src/app.d.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
// See https://svelte.dev/docs/kit/types#app.d.ts
2+
// for information about these interfaces
13
declare global {
24
namespace App {
35
// interface Error {}

src/lib/client/caller.ts

Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
1+
import { toast } from 'svelte-sonner';
2+
import type { z } from 'zod';
3+
import type { routerBaseOutputSchema } from '../schemas';
4+
import type { AppRouterEndpoints } from '../server/caller';
5+
import type { AppRouter } from '../server/root';
6+
import type { HttpMethod } from '../server/setup';
7+
8+
type ResolvePath<T, P extends string> = P extends `${infer K}.${infer Rest}`
9+
? K extends keyof T
10+
? ResolvePath<T[K], Rest>
11+
: never
12+
: P extends keyof T
13+
? T[P]
14+
: never;
15+
16+
export type ExtractMethod<T, P extends string> =
17+
ResolvePath<T, P> extends { method: infer M } ? M : never;
18+
19+
export type ExtractInput<T, P extends string> =
20+
ResolvePath<T, P> extends { handler: (...args: infer Params) => any } ? Params[1] : never;
21+
22+
export type ExtractOutput<T, P extends string> =
23+
ResolvePath<T, P> extends { handler: (...args: any) => infer R } ? R : never;
24+
25+
type RequestOptions = Omit<RequestInfo, 'body' | 'method'>;
26+
27+
type ClientCallerInput<T extends AppRouterEndpoints> = {
28+
method: ExtractMethod<AppRouter, T>;
29+
input: ExtractInput<AppRouter, T>;
30+
requestOptions?: RequestOptions;
31+
};
32+
33+
type ClientCallerOutput<T extends AppRouterEndpoints> = Promise<
34+
ExtractOutput<AppRouter, T> | z.infer<typeof routerBaseOutputSchema> | undefined
35+
>;
36+
37+
export async function callApi<T extends AppRouterEndpoints>(
38+
endpoint: T,
39+
{ method, input, requestOptions }: ClientCallerInput<T>,
40+
): ClientCallerOutput<T> {
41+
const formattedEndpoint = endpoint.replace(/\./g, '/');
42+
43+
const response = await fetch(`api/${formattedEndpoint}`, {
44+
body: JSON.stringify(input),
45+
method: method as HttpMethod,
46+
...requestOptions,
47+
});
48+
49+
if (!response.ok) {
50+
toast.error('The request failed!', {
51+
description: response.statusText,
52+
});
53+
54+
return;
55+
}
56+
57+
try {
58+
const output = (await response.json()) as ExtractOutput<AppRouter, T>;
59+
return output;
60+
} catch {
61+
return { status: 404, message: await response.text() };
62+
}
63+
}

src/lib/client/router-utils.ts

Lines changed: 0 additions & 28 deletions
This file was deleted.

0 commit comments

Comments
 (0)