Skip to content

Commit

Permalink
🚧 coding blind at this point
Browse files Browse the repository at this point in the history
  • Loading branch information
acidjazz committed Jan 7, 2025
1 parent 5b4f687 commit 096eaa9
Showing 1 changed file with 7 additions and 6 deletions.
13 changes: 7 additions & 6 deletions src/runtime/server/utils/metapi.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import type { MetapiDetail, MetapiResponse } from '#api-utils'
import { setResponseStatus } from 'h3'
import type { H3Event } from 'h3'

let start: number | undefined

Expand All @@ -7,7 +8,7 @@ const bench = (): string => {
return start ? `${(end - start).toFixed(3)}ms` : 'n/a'
}

const render = (data: unknown): MetapiResponse => {
const render = (data: unknown): import('#api-utils').MetapiResponse => {
return {
meta: {
benchmark: bench(),
Expand All @@ -17,7 +18,7 @@ const render = (data: unknown): MetapiResponse => {
}
}

const success = (message: string, data?: unknown): MetapiResponse => {
const success = (message: string, data?: unknown): import('#api-utils').MetapiResponse => {
return {
meta: {
benchmark: bench(),
Expand All @@ -28,7 +29,7 @@ const success = (message: string, data?: unknown): MetapiResponse => {
}
}

const error = (event: unknown, detail: MetapiDetail, code: number = 400): MetapiResponse => {
const error = (event: H3Event, detail: import('#api-utils').MetapiDetail, code: number = 400): import('#api-utils').MetapiResponse => {
setResponseStatus(event, code)
return {
meta: {
Expand All @@ -40,9 +41,9 @@ const error = (event: unknown, detail: MetapiDetail, code: number = 400): Metapi
}
}

const notFound = (event: unknown): MetapiResponse => error(event, 'Not Found', 404)
const notFound = (event: H3Event): import('#api-utils').MetapiResponse => error(event, 'Not Found', 404)

const renderNullError = (event: unknown, data: unknown): MetapiResponse => {
const renderNullError = (event: H3Event, data: unknown): import('#api-utils').MetapiResponse => {
if (data === null) return error(event, 'Not Found', 404)
return render(data)
}
Expand Down

0 comments on commit 096eaa9

Please sign in to comment.