Skip to content

Commit

Permalink
Fix: Response not returning correct Promise (fixes #14)
Browse files Browse the repository at this point in the history
  • Loading branch information
Refzlund committed Apr 16, 2023
1 parent 1c12421 commit b788348
Show file tree
Hide file tree
Showing 4 changed files with 27 additions and 6 deletions.
8 changes: 5 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,20 +10,22 @@
},
"devDependencies": {
"@sveltejs/adapter-auto": "^2.0.0",
"@sveltejs/kit": "^1.15.4",
"@sveltejs/kit": "^1.15.5",
"@sveltejs/package": "^2.0.2",
"@types/node": "^18.15.11",
"chokidar": "^3.5.3",
"svelte": "^3.58.0",
"svelte-check": "^3.2.0",
"svelte-preprocess": "^5.0.3",
"svelte2tsx": "^0.6.11",
"tslib": "^2.5.0",
"vite": "^4.2.1"
"vite": "^4.2.1",
"typescript": "^5.0.4"
},
"peerDependencies": {
"@sveltejs/kit": "^1.5.5",
"svelte": "^3.55.1",
"typescript": "^5.0.4"
"typescript": ">=5.0.0"
},
"repository": "github:refzlund/sveltekit-zero-api",
"homepage": "https://github.com/Refzlund/sveltekit-zero-api",
Expand Down
4 changes: 2 additions & 2 deletions src/lib/types/zeroapi.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -55,12 +55,12 @@ type _Keys<M> = Exclude<StatusCodeFn[keyof StatusCodeFn] | keyof StatusCodeFn, k

// Makes the API return type recursive
type RecursiveMethodReturn<M extends MethodReturnTypes<any>> = {
[Return in keyof M]: (cb: Callback<M[Return]>) => RecursiveMethodReturn<M> & Promise<SvelteResponse>
[Return in keyof M]: (cb: Callback<M[Return]>) => RecursiveMethodReturn<M> & Promise<SvelteResponse<ReturnType<M[Return]>>>
} & {
$: $<M, keyof M>
_: {
// TODO: Hacky ('prependCallbacks') but I'm tired
[Fn in _Keys<M>]: (cb: keyof M extends 'prependCallbacks' ? DefCallback : Callback<M[Return]>) => RecursiveMethodReturn<M>['_'] & Promise<SvelteResponse>
[Fn in _Keys<M>]: (cb: keyof M extends 'prependCallbacks' ? DefCallback : Callback<M[Return]>) => RecursiveMethodReturn<M>['_'] & Promise<SvelteResponse<ReturnType<M[Return]>>>
} & (keyof M extends 'prependCallbacks' ? {} : {
$: $<M, _Keys<M>>
})
Expand Down
7 changes: 6 additions & 1 deletion src/routes/(app)/api/fo/+server.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,11 @@ export async function GET(event: API) {
return Ok()
}

interface Bar {}

export async function POST(event: API) {
return Ok()
const bar: Bar = {}
return Ok({
body: bar
})
}
14 changes: 14 additions & 0 deletions src/routes/+page.server.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
import api from '$browser/api'
import { redirect } from '@sveltejs/kit'
import type { PageServerLoad } from './$types'

export const load: PageServerLoad = async ({ parent, fetch }) => {

const response = await api.fo.POST({}, fetch).Ok(res => {

})

return {
user: response.body
}
}

0 comments on commit b788348

Please sign in to comment.