Skip to content

Commit 072211f

Browse files
fix: custom fetch key to support v3.0.0-rc.5
1 parent b722467 commit 072211f

File tree

5 files changed

+11
-7
lines changed

5 files changed

+11
-7
lines changed

src/runtime/composables/$kql.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import { hash as ohash } from 'ohash'
2-
import type { KirbyQueryRequest, KirbyQueryResponse } from '../types'
2+
import type { KirbyQueryRequest, KirbyQueryResponse } from '#nuxt-kql'
33
import { useNuxtApp } from '#imports'
44
import { apiRoute } from '#build/nuxt-kql/options'
55

src/runtime/composables/$publicKql.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import type { FetchOptions } from 'ohmyfetch'
2-
import type { KirbyQueryRequest, KirbyQueryResponse } from '../types'
32
import type { ModuleOptions } from '../../module'
43
import { getAuthHeaders, headersToObject } from '../utils'
4+
import type { KirbyQueryRequest, KirbyQueryResponse } from '#nuxt-kql'
55
import { useRuntimeConfig } from '#imports'
66

77
export type PublicKqlOptions = Omit<FetchOptions, 'baseURL' | 'body' | 'params' | 'parseResponse' | 'responseType' | 'response'>
@@ -13,7 +13,7 @@ export function $publicKql<T extends KirbyQueryResponse = KirbyQueryResponse>(
1313
const { kql } = useRuntimeConfig().public
1414

1515
if (!kql?.clientRequests)
16-
throw new Error('Fetching from Kirby client-side isn\'t allowed. Enable it by setting `clientRequests` to `true`.')
16+
throw new Error('Fetching from Kirby client-side isn\'t allowed. Enable it by setting "clientRequests" to "true".')
1717

1818
return $fetch<T>(kql.prefix, {
1919
...opts,

src/runtime/composables/useKql.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,9 @@
11
import { computed, unref } from 'vue'
2+
import { hash } from 'ohash'
23
import type { Ref } from 'vue'
34
import type { NitroFetchRequest } from 'nitropack'
45
import type { AsyncData, UseFetchOptions } from 'nuxt/app'
5-
import type { KirbyQueryRequest, KirbyQueryResponse } from '../types'
6+
import type { KirbyQueryRequest, KirbyQueryResponse } from '#nuxt-kql'
67
import { useFetch } from '#imports'
78
import { apiRoute } from '#build/nuxt-kql/options'
89

@@ -19,6 +20,7 @@ export function useKql<
1920

2021
return useFetch<ResT, Error, NitroFetchRequest, ResT>(apiRoute, {
2122
...opts,
23+
key: hash(_query.value),
2224
method: 'POST',
2325
body: { query: _query.value },
2426
}) as AsyncData<ResT, true | Error>

src/runtime/composables/usePublicKql.ts

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,11 @@
11
import { computed, unref } from 'vue'
2+
import { hash } from 'ohash'
23
import type { Ref } from 'vue'
34
import type { NitroFetchRequest } from 'nitropack'
45
import type { AsyncData, UseFetchOptions } from 'nuxt/app'
5-
import type { KirbyQueryRequest, KirbyQueryResponse } from '../types'
66
import type { ModuleOptions } from '../../module'
77
import { getAuthHeaders } from '../utils'
8+
import type { KirbyQueryRequest, KirbyQueryResponse } from '#nuxt-kql'
89
import { useFetch, useRuntimeConfig } from '#imports'
910

1011
export type UseKqlOptions<T> = Omit<UseFetchOptions<T>, 'baseURL' | 'body' | 'params' | 'parseResponse' | 'responseType' | 'response'>
@@ -16,7 +17,7 @@ export function usePublicKql<
1617
const { kql } = useRuntimeConfig().public
1718

1819
if (!kql?.clientRequests)
19-
throw new Error('Fetching queries client-side isn\'t allowed. Enable it by setting `clientRequests` to `true`.')
20+
throw new Error('Fetching queries client-side isn\'t allowed. Enable it by setting "clientRequests" to "true".')
2021

2122
const _query = computed(() => unref(query))
2223

@@ -25,6 +26,7 @@ export function usePublicKql<
2526

2627
return useFetch<ResT, Error, NitroFetchRequest, ResT>(kql.prefix, {
2728
...opts,
29+
key: hash(_query.value),
2830
baseURL: kql.url,
2931
method: 'POST',
3032
body: _query.value,

src/runtime/server/api/kql.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import { createError, defineEventHandler, useBody } from 'h3'
22
import type { ModuleOptions } from '../../../module'
3-
import type { KirbyQueryRequest, KirbyQueryResponse } from '../../types'
43
import { getAuthHeaders } from '../../utils'
4+
import type { KirbyQueryRequest, KirbyQueryResponse } from '#nuxt-kql'
55
import { useRuntimeConfig } from '#imports'
66

77
export default defineEventHandler(async (event): Promise<KirbyQueryResponse> => {

0 commit comments

Comments
 (0)