Skip to content

Commit a9d7a37

Browse files
chore: svelte-query tests, validatePackages changes
1 parent 40eee07 commit a9d7a37

File tree

16 files changed

+131
-90
lines changed

16 files changed

+131
-90
lines changed

examples/svelte/ssr/src/lib/Post.svelte

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,13 @@
11
<script lang="ts">
22
import { createQuery } from '@tanstack/svelte-query'
3-
import { getPostById } from './data'
3+
import { api } from './api'
44
import type { Post } from './types'
55
66
export let postId: number
77
88
const post = createQuery<Post>({
99
queryKey: ['post', postId],
10-
queryFn: () => getPostById(postId),
10+
queryFn: () => api().getPostById(postId),
1111
})
1212
</script>
1313

examples/svelte/ssr/src/lib/Posts.svelte

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
<script lang="ts">
22
import { useQueryClient, createQuery } from '@tanstack/svelte-query'
3-
import { getPosts } from './data'
3+
import { api } from './api'
44
55
const client = useQueryClient()
66
@@ -11,7 +11,7 @@
1111
Error
1212
>({
1313
queryKey: ['posts', limit],
14-
queryFn: () => getPosts(limit),
14+
queryFn: () => api().getPosts(limit),
1515
})
1616
</script>
1717

examples/svelte/ssr/src/lib/api.ts

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
import type { Post } from './types'
2+
3+
export const api = (customFetch = fetch) => ({
4+
getPosts: async (limit: number) => {
5+
const response = await customFetch(
6+
'https://jsonplaceholder.typicode.com/posts',
7+
)
8+
const data = (await response.json()) as Post[]
9+
return data.filter((x) => x.id <= limit)
10+
},
11+
getPostById: async (id: number): Promise<Post> => {
12+
const response = await customFetch(
13+
`https://jsonplaceholder.typicode.com/posts/${id}`,
14+
)
15+
const data = (await response.json()) as Post
16+
return data
17+
},
18+
})

examples/svelte/ssr/src/lib/data.ts

Lines changed: 0 additions & 23 deletions
This file was deleted.
Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
1-
import { getPosts } from '$lib/data'
1+
import { api } from '$lib/api'
22
import type { PageLoad } from './$types'
33

44
export const load: PageLoad = async ({ parent, fetch }) => {
55
const { queryClient } = await parent()
66

77
await queryClient.prefetchQuery({
88
queryKey: ['posts', 10],
9-
queryFn: () => getPosts(10, fetch),
9+
queryFn: () => api(fetch).getPosts(10),
1010
})
1111
}

examples/svelte/ssr/src/routes/[postId]/+page.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { getPostById } from '$lib/data'
1+
import { api } from '$lib/api'
22
import type { PageLoad } from './$types'
33

44
export const load: PageLoad = async ({ parent, fetch, params }) => {
@@ -8,7 +8,7 @@ export const load: PageLoad = async ({ parent, fetch, params }) => {
88

99
await queryClient.prefetchQuery({
1010
queryKey: ['post', postId],
11-
queryFn: () => getPostById(postId, fetch),
11+
queryFn: () => api(fetch).getPostById(postId),
1212
})
1313

1414
return { postId }

packages/eslint-plugin-query/package.json

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,13 @@
1111
"url": "https://github.com/sponsors/tannerlinsley"
1212
},
1313
"main": "build/lib/index.js",
14+
"exports": {
15+
".": {
16+
"require": "./build/lib/index.js",
17+
"default": "./build/lib/index.js"
18+
},
19+
"./package.json": "./package.json"
20+
},
1421
"scripts": {
1522
"clean": "rimraf ./build",
1623
"dev": "tsup --watch --sourcemap",

packages/svelte-query/package.json

Lines changed: 20 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -2,24 +2,40 @@
22
"name": "@tanstack/svelte-query",
33
"version": "5.0.0-alpha.26",
44
"description": "Primitives for managing, caching and syncing asynchronous and remote data in Svelte",
5-
"author": "Dre Johnson",
5+
"author": "Lachlan Collins",
66
"license": "MIT",
77
"repository": "tanstack/query",
88
"homepage": "https://tanstack.com/query",
99
"funding": {
1010
"type": "github",
1111
"url": "https://github.com/sponsors/tannerlinsley"
1212
},
13+
"type": "module",
1314
"types": "build/lib/index.d.ts",
1415
"module": "build/lib/index.js",
15-
"type": "module",
16+
"svelte": "build/lib/index.js",
17+
"exports": {
18+
".": {
19+
"types": "./build/lib/index.d.ts",
20+
"import": "./build/lib/index.js",
21+
"svelte": "./build/lib/index.js",
22+
"default": "./build/lib/index.js"
23+
},
24+
"./package.json": "./package.json"
25+
},
26+
"files": [
27+
"build/lib",
28+
"src",
29+
"!build/lib/__tests__",
30+
"!src/__tests__"
31+
],
1632
"scripts": {
1733
"clean": "rimraf ./build",
1834
"test:types": "svelte-check --tsconfig ./tsconfig.json",
1935
"test:eslint": "eslint --ext .svelte,.ts ./src",
2036
"test:lib": "vitest run --coverage",
2137
"test:lib:dev": "pnpm run test:lib --watch",
22-
"build": "svelte-package --input ./src --output ./build/lib && rimraf ./build/lib/__tests__"
38+
"build": "svelte-package --input ./src --output ./build/lib"
2339
},
2440
"devDependencies": {
2541
"@sveltejs/package": "^2.0.2",
@@ -38,14 +54,5 @@
3854
},
3955
"peerDependencies": {
4056
"svelte": "^3.54.0"
41-
},
42-
"exports": {
43-
"./package.json": "./package.json",
44-
".": "./build/lib/index.js"
45-
},
46-
"svelte": "./build/lib/index.js",
47-
"files": [
48-
"build/lib/*",
49-
"src"
50-
]
57+
}
5158
}

packages/svelte-query/src/__tests__/CreateMutation.svelte

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,8 @@
11
<script lang="ts">
2-
import {
3-
createMutation,
4-
QueryClient,
5-
type CreateMutationOptions,
6-
} from '../index'
2+
import { QueryClient } from '@tanstack/query-core'
73
import { setQueryClientContext } from '../context'
4+
import { createMutation } from '../createMutation'
5+
import type { CreateMutationOptions } from '../types'
86
97
export let options: CreateMutationOptions
108

packages/svelte-query/src/__tests__/CreateQueries.svelte

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
<script lang="ts">
2-
import { createQueries, QueryClient } from '../index'
2+
import { QueryClient } from '@tanstack/query-core'
33
import { setQueryClientContext } from '../context'
4+
import { createQueries } from '../createQueries'
45
import type { QueriesOptions } from '../createQueries'
56
67
export let options: { queries: [...QueriesOptions<any>] }

0 commit comments

Comments
 (0)