Skip to content

Commit

Permalink
fix: imports
Browse files Browse the repository at this point in the history
  • Loading branch information
enkot committed Sep 21, 2023
1 parent 02bc31a commit 3cb4ccd
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 6 deletions.
1 change: 1 addition & 0 deletions playground/pets/nuxt.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ export default defineNuxtConfig({
pets: {
fetchOptions: {
baseURL: 'https://petstore3.swagger.io/api/v3',
headers: {}
}
}
}
Expand Down
3 changes: 1 addition & 2 deletions src/runtime/clients.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,7 @@ import type { FetchOptions as _FetchOptions } from 'ofetch'
import type { ErrorResponse, HttpMethod, SuccessResponse, FilterKeys, MediaType, ResponseObjectMap } from "openapi-typescript-helpers"
import type { KeysOf, MultiWatchSources, AsyncDataOptions, AsyncData, PickFrom } from "#app/composables/asyncData"
import type { OpenFetchClientName } from '#build/module/nuxt-open-fetch'
import { useFetch } from '#app'
import { toValue, computed } from '#imports'
import { toValue, computed, useNuxtApp, useFetch, useLazyFetch } from '#imports'
import { fillPath } from './utils'

type FetchResponseData<T> = FilterKeys<SuccessResponse<ResponseObjectMap<T>>, MediaType>
Expand Down
9 changes: 5 additions & 4 deletions src/runtime/plugin.ts
Original file line number Diff line number Diff line change
@@ -1,15 +1,16 @@
import type { ModuleOptions } from '../module'
import { defineNuxtPlugin, useRuntimeConfig } from '#app'

export default defineNuxtPlugin((nuxtApp) => {
if (nuxtApp.$openFetch) return

const openFetch = useRuntimeConfig().public.openFetch as ModuleOptions
const clients = useRuntimeConfig().public.openFetch.clients as Record<string, {
fetchOptions: any
}>

return {
provide: {
openFetch: Object.entries(openFetch.clients || {}).reduce((clients, [name, client]) => ({
...clients,
openFetch: Object.entries(clients || {}).reduce((acc, [name, client]) => ({
...acc,
[name]: client.fetchOptions
}), {})
}
Expand Down

0 comments on commit 3cb4ccd

Please sign in to comment.