File tree Expand file tree Collapse file tree 11 files changed +96
-335
lines changed
packages/openapi-fetch/examples/sveltekit Expand file tree Collapse file tree 11 files changed +96
-335
lines changed Original file line number Diff line number Diff line change @@ -22,7 +22,7 @@ See [swr-openapi](/swr-openapi/)
22
22
23
23
## Svelte / SvelteKit
24
24
25
- [ SvelteKit] ( https://kit. svelte.dev ) の自動型推論機能は、クライアントサイドでのデータ取得や[ ページデータ] ( https://kit. svelte.dev/docs/load#page -data ) の取得において、openapi-fetchの型を簡単に活用できます。また、追加のライブラリを必要とせずに動作します。SvelteKitは、ロード関数内で[ カスタムフェッチ] ( https://kit. svelte.dev/docs/load#making -fetch-requests ) を使用することを推奨しており、これは[ フェッチオプション] ( /ja/openapi-fetch/api#fetch-オプション ) で実現できます。
25
+ [ SvelteKit] ( https://svelte.dev/docs/kit ) の自動型推論機能は、クライアントサイドでのデータ取得や[ ページデータ] ( https://svelte.dev/docs/kit/ load#Page -data ) の取得において、openapi-fetchの型を簡単に活用できます。また、追加のライブラリを必要とせずに動作します。SvelteKitは、ロード関数内で[ カスタムフェッチ] ( https://svelte.dev/docs/kit/ load#Making -fetch-requests ) を使用することを推奨しており、これは[ フェッチオプション] ( /ja/openapi-fetch/api#fetch-オプション ) で実現できます。
26
26
27
27
_ 注: SvelteKitを使用しない場合でも、` src/routes/+page.svelte ` 内のルート例は、SvelteKitの機能を使用しておらず、どのようなセットアップにも適用可能です。_
28
28
Original file line number Diff line number Diff line change @@ -22,7 +22,7 @@ See [swr-openapi](/swr-openapi/)
22
22
23
23
## Svelte / SvelteKit
24
24
25
- [ SvelteKit] ( https://kit. svelte.dev ) ’s automatic type inference can easily pick up openapi-fetch’s types in both clientside fetching and [ Page Data] ( https://kit. svelte.dev/docs/load#page -data ) fetching. And it doesn’t need any additional libraries to work. SvelteKit also advises to use their [ custom fetch] ( https://kit. svelte.dev/docs/load#making -fetch-requests ) in load functions. This can be achieved with [ fetch options] ( /openapi-fetch/api#fetch-options ) .
25
+ [ SvelteKit] ( https://svelte.dev/docs/kit ) ’s automatic type inference can easily pick up openapi-fetch’s types in both clientside fetching and [ Page Data] ( https://svelte.dev/docs/kit/ load#Page -data ) fetching. And it doesn’t need any additional libraries to work. SvelteKit also advises to use their [ custom fetch] ( https://svelte.dev/docs/kit/ load#Making -fetch-requests ) in load functions. This can be achieved with [ fetch options] ( /openapi-fetch/api#fetch-options ) .
26
26
27
27
_ Note: if you’re using Svelte without SvelteKit, the root example in ` src/routes/+page.svelte ` doesn’t use any SvelteKit features and is generally-applicable to any setup._
28
28
Original file line number Diff line number Diff line change @@ -22,7 +22,7 @@ See [swr-openapi](/swr-openapi/)
22
22
23
23
## Svelte / SvelteKit
24
24
25
- [ SvelteKit] ( https://kit. svelte.dev ) 的自动类型推断可以轻松地在客户端获取和 [ Page Data] ( https://kit. svelte.dev/docs/load#page -data ) 获取中捕获 openapi-fetch 的类型。而且它不需要任何额外的库。SvelteKit 还建议使用它们的[ 自定义 fetch] ( https://kit. svelte.dev/docs/load#making -fetch-requests ) 在 load 函数中工作。这可以通过 [ fetch options] ( /openapi-fetch/api#fetch-options ) 实现。
25
+ [ SvelteKit] ( https://svelte.dev/docs/kit ) 的自动类型推断可以轻松地在客户端获取和 [ Page Data] ( https://svelte.dev/docs/kit/ load#Page -data ) 获取中捕获 openapi-fetch 的类型。而且它不需要任何额外的库。SvelteKit 还建议使用它们的[ 自定义 fetch] ( https://svelte.dev/docs/kit/ load#Making -fetch-requests ) 在 load 函数中工作。这可以通过 [ fetch options] ( /openapi-fetch/api#fetch-options ) 实现。
26
26
27
27
_ 注意:如果你在没有 SvelteKit 的情况下使用 Svelte,` src/routes/+page.svelte ` 中的根示例不使用任何 SvelteKit 特性,通常适用于任何设置。_
28
28
Original file line number Diff line number Diff line change 7
7
"check" : " svelte-kit sync && svelte-check --tsconfig ./tsconfig.json" ,
8
8
"check:watch" : " svelte-kit sync && svelte-check --tsconfig ./tsconfig.json --watch"
9
9
},
10
- "dependencies" : {
11
- "@sveltejs/vite-plugin-svelte-inspector" : " ^4.0.1" ,
12
- "openapi-fetch" : " workspace:^"
13
- },
14
10
"devDependencies" : {
15
- "@sveltejs/adapter-auto" : " ^3.3.1" ,
16
- "@sveltejs/kit" : " ^2.20.8" ,
17
- "@sveltejs/vite-plugin-svelte" : " ^5.0.3" ,
11
+ "@sveltejs/adapter-auto" : " ^6.0.1" ,
12
+ "@sveltejs/kit" : " ^2.22.2" ,
13
+ "@sveltejs/vite-plugin-svelte" : " ^5.1.0" ,
14
+ "openapi-fetch" : " workspace:^" ,
18
15
"openapi-typescript" : " workspace:^" ,
19
- "svelte" : " ^5.28.2" ,
20
- "svelte-check" : " ^3.8.6" ,
21
- "tslib" : " ^2.8.1" ,
16
+ "svelte" : " ^5.34.9" ,
17
+ "svelte-check" : " ^4.2.2" ,
22
18
"typescript" : " ^5.8.3" ,
23
- "vite" : " ^6.3.4"
19
+ "vite" : " ^6.3.5"
20
+ },
21
+ "pnpm" : {
22
+ "onlyBuiltDependencies" : [
23
+ " esbuild"
24
+ ]
24
25
}
25
26
}
Original file line number Diff line number Diff line change 1
- // See https://kit. svelte.dev/docs/types#app
1
+ // See https://svelte.dev/docs/kit/ types#app.d.ts
2
2
// for information about these interfaces
3
3
declare global {
4
4
namespace App {
5
5
// interface Error {}
6
6
// interface Locals {}
7
7
// interface PageData {}
8
+ // interface PageState {}
8
9
// interface Platform {}
9
10
}
10
11
}
Original file line number Diff line number Diff line change 1
1
<script lang =" ts" >
2
2
import { onMount } from " svelte" ;
3
+
3
4
import client from " $lib/api/index.js" ;
4
5
5
- let fact: Awaited <ReturnType <typeof getFact >> | undefined ;
6
+ let fact: Awaited <ReturnType <typeof getFact >> | undefined = $state ( undefined ) ;
6
7
7
8
async function getFact() {
8
9
return client .GET (" /fact" , {
12
13
});
13
14
}
14
15
15
- onMount (() => {
16
- getFact (). then (( res ) => ( fact = res ) );
16
+ onMount (async () => {
17
+ fact = await getFact ( );
17
18
});
18
19
</script >
19
20
26
27
<pre ><code >{JSON .stringify (fact .data , undefined , 2 )}</code ></pre >
27
28
{/if }
28
29
{/if }
29
- <button type ="button" on:click ={() => getFact ().then ((res ) => (fact = res ))}>Another fact!</button >
30
+ <button type ="button" onclick ={async () => (fact = await getFact ())}>
31
+ Another fact!
32
+ </button >
30
33
</div >
Original file line number Diff line number Diff line change 1
1
<script lang =" ts" >
2
- import type { PageData } from " ./$types" ;
2
+ import type { PageProps } from " ./$types" ;
3
3
4
- export let data: PageData ;
4
+ let { data } : PageProps = $props () ;
5
5
</script >
6
6
7
7
<div >
13
13
{:else }
14
14
<div >Loading...</div >
15
15
{/if }
16
- <button type ="button" on:click ={() => location .reload ()}>Another fact!</button >
16
+ <button type ="button" onclick ={() => location .reload ()}>Another fact!</button >
17
17
</div >
Original file line number Diff line number Diff line change
1
+ import type { PageLoad } from "./$types" ;
2
+
1
3
import client from "$lib/api/index.js" ;
2
4
3
5
// Note: this uses Svelte’s custom fetcher as an example, but Node’s
4
6
// native fetch works, too. See Svelte’s docs to learn the difference:
5
- // @see https://kit. svelte.dev/docs/load#making -fetch-requests
6
- export async function load ( { fetch } ) {
7
+ // @see https://svelte.dev/docs/kit/ load#Making -fetch-requests
8
+ export const load : PageLoad = async ( { fetch } ) => {
7
9
const fact = await client . GET ( "/fact" , {
8
10
params : { query : { max_length : 500 } } ,
9
11
fetch,
@@ -15,4 +17,4 @@ export async function load({ fetch }) {
15
17
error : fact . error ,
16
18
} ,
17
19
} ;
18
- }
20
+ } ;
Original file line number Diff line number Diff line change @@ -3,14 +3,14 @@ import { vitePreprocess } from "@sveltejs/vite-plugin-svelte";
3
3
4
4
/** @type {import('@sveltejs/kit').Config } */
5
5
const config = {
6
- // Consult https://kit. svelte.dev/docs/integrations#preprocessors
6
+ // Consult https://svelte.dev/docs/kit/ integrations
7
7
// for more information about preprocessors
8
8
preprocess : vitePreprocess ( ) ,
9
9
10
10
kit : {
11
- // adapter-auto only supports some environments, see https://kit. svelte.dev/docs/adapter-auto for a list.
12
- // If your environment is not supported or you settled on a specific environment, switch out the adapter.
13
- // See https://kit. svelte.dev/docs/adapters for more information about adapters.
11
+ // adapter-auto only supports some environments, see https://svelte.dev/docs/kit /adapter-auto for a list.
12
+ // If your environment is not supported, or you settled on a specific environment, switch out the adapter.
13
+ // See https://svelte.dev/docs/kit /adapters for more information about adapters.
14
14
adapter : adapter ( ) ,
15
15
} ,
16
16
} ;
Original file line number Diff line number Diff line change 3
3
"compilerOptions" : {
4
4
"allowJs" : true ,
5
5
"checkJs" : true ,
6
- "lib" : [" DOM" ],
7
6
"esModuleInterop" : true ,
8
7
"forceConsistentCasingInFileNames" : true ,
9
8
"resolveJsonModule" : true ,
10
9
"skipLibCheck" : true ,
11
10
"sourceMap" : true ,
12
- "strict" : true
11
+ "strict" : true ,
12
+ "moduleResolution" : " bundler"
13
13
}
14
- // Path aliases are handled by https://kit.svelte.dev/docs/configuration#alias
14
+ // Path aliases are handled by https://svelte.dev/docs/kit/configuration#alias
15
+ // except $lib which is handled by https://svelte.dev/docs/kit/configuration#files
15
16
//
16
17
// If you want to overwrite includes/excludes, make sure to copy over the relevant includes/excludes
17
18
// from the referenced tsconfig.json - TypeScript does not merge them in
You can’t perform that action at this time.
0 commit comments