Skip to content

Commit c6571cb

Browse files
committed
types: update module types
1 parent b922f5e commit c6571cb

File tree

13 files changed

+117
-495
lines changed

13 files changed

+117
-495
lines changed

package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -87,6 +87,7 @@
8787
"@types/micromatch": "^4.0.9",
8888
"@types/node": "^22.8.4",
8989
"@types/pako": "^2.0.3",
90+
"@types/pg": "^8.11.10",
9091
"@types/ws": "^8.5.12",
9192
"csvtojson": "^2.0.10",
9293
"eslint": "^9.13.0",

pnpm-lock.yaml

Lines changed: 91 additions & 476 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/module.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ import {
1111
addComponentsDir,
1212
} from '@nuxt/kit'
1313
import type { Nuxt } from '@nuxt/schema'
14+
import type { ModuleOptions as MDCModuleOptions } from '@nuxtjs/mdc'
1415
import { hash } from 'ohash'
1516
import { join, dirname, isAbsolute } from 'pathe'
1617
import fastGlob from 'fast-glob'
@@ -212,7 +213,7 @@ async function processCollectionItems(nuxt: Nuxt, collections: ResolvedCollectio
212213
const databaseContents = db.fetchDevelopmentCache()
213214

214215
const configHash = hash({
215-
mdcHighlight: nuxt.options.mdc?.highlight,
216+
mdcHighlight: (nuxt.options as unknown as { mdc: MDCModuleOptions }).mdc?.highlight,
216217
contentBuild: options.build?.markdown,
217218
})
218219

src/runtime/adapters/postgres.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ import { createDatabaseAdapter } from '../internal/database-adapter'
44
export type PostgreSqlOptions = { url: string } | pg.ClientConfig
55

66
let _client: undefined | pg.Client | Promise<pg.Client>
7-
export default createDatabaseAdapter<PostgreSqlOptions>((opts = {}) => {
7+
export default createDatabaseAdapter<PostgreSqlOptions>((opts) => {
88
function getClient() {
99
if (_client) {
1010
return _client
@@ -33,7 +33,7 @@ export default createDatabaseAdapter<PostgreSqlOptions>((opts = {}) => {
3333
async first<T>(sql: string, params?: Array<number | string | boolean>) {
3434
const db = await getClient()
3535
const { rows } = params ? await db.query<T[], T>(sql, params as QueryConfigValues<T>) : await db.query<T[], T>(sql)
36-
return rows[0]
36+
return rows[0] as T
3737
},
3838
async exec(sql: string): Promise<void> {
3939
const db = await getClient()

src/runtime/api/query.post.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,14 @@
11
import { eventHandler, getRouterParam, readValidatedBody } from 'h3'
22
import { z } from 'zod'
3+
import type { RuntimeConfig } from '@nuxt/content'
34
import loadDatabaseAdapter, { checkAndImportDatabaseIntegrity } from '../internal/database.server'
45
import { useRuntimeConfig } from '#imports'
56

67
export default eventHandler(async (event) => {
78
const { sql } = await readValidatedBody(event, z.object({ sql: z.string() }).parse)
89
const collection = getRouterParam(event, 'collection')!
910

10-
const conf = useRuntimeConfig().content
11+
const conf = useRuntimeConfig().content as RuntimeConfig
1112
await checkAndImportDatabaseIntegrity(event, collection, conf)
1213

1314
return loadDatabaseAdapter(conf).all(sql)

src/runtime/app.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,10 +25,10 @@ export async function queryCollectionSearchSections(collection: keyof Collection
2525

2626
async function executeContentQuery<T extends keyof Collections, Result = Collections[T]>(collection: T, sql: string) {
2727
if (import.meta.client) {
28-
return await queryContentSqlClientWasm<T, Result>(collection, sql)
28+
return queryContentSqlClientWasm<T, Result>(collection, sql) as Promise<Result[]>
2929
}
3030
else {
31-
return await fetchQuery(tryUseNuxtApp()?.ssrContext?.event, String(collection), sql)
31+
return fetchQuery(tryUseNuxtApp()?.ssrContext?.event, String(collection), sql) as Promise<Result[]>
3232
}
3333
}
3434

src/runtime/internal/api.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import type { H3Event } from 'h3'
22
import { checksums } from '#content/manifest'
33

4-
export async function fetchDatabase(event: H3Event | undefined, collection: string) {
4+
export async function fetchDatabase(event: H3Event | undefined, collection: string): Promise<string> {
55
return await $fetch(`/api/content/${collection}/database.sql`, {
66
context: event ? { clouflare: event.context.cloudflare } : {},
77
responseType: 'text',
@@ -10,7 +10,7 @@ export async function fetchDatabase(event: H3Event | undefined, collection: stri
1010
})
1111
}
1212

13-
export async function fetchQuery(event: H3Event | undefined, collection: string, sql: string) {
13+
export async function fetchQuery<Item>(event: H3Event | undefined, collection: string, sql: string): Promise<Item[]> {
1414
return await $fetch(`/api/content/${collection}/query`, {
1515
context: event ? { clouflare: event.context.cloudflare } : {},
1616
headers: { 'content-type': 'application/json' },

src/runtime/internal/database-adapter.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import type { DatabaseAdapter } from '@nuxt/content'
22
import { parseJsonFields } from './collection'
33

4-
export function createDatabaseAdapter<Options = unknown>(factory: (otps?: Options) => DatabaseAdapter) {
4+
export function createDatabaseAdapter<Options = unknown>(factory: (otps: Options) => DatabaseAdapter) {
55
return (opts: Options) => {
66
const adapter = factory(opts)
77

src/runtime/internal/navigation.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -108,7 +108,7 @@ export async function generateNavigationTree<T extends PageCollectionItemBase>(q
108108

109109
// Create dummy parent if not found
110110
if (!parent) {
111-
const navigationConfig = conf ? pickConfigNavigationFields(conf) : {} as ContentNavigationItem
111+
const navigationConfig = (conf ? pickConfigNavigationFields(conf) : {}) as ContentNavigationItem
112112
parent = {
113113
...navigationConfig,
114114
title: navigationConfig.title || generateTitle(part),

src/runtime/nitro.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ import { generateSearchSections } from './internal/search'
77
import { fetchQuery } from './internal/api'
88

99
export const queryCollectionWithEvent = <T extends keyof Collections>(event: H3Event, collection: T): CollectionQueryBuilder<Collections[T]> => {
10-
return collectionQureyBuilder<T>(collection, (collection, sql) => fetchQuery(event, collection, sql))
10+
return collectionQureyBuilder<T>(collection, (collection, sql) => fetchQuery<T>(event, collection, sql))
1111
}
1212

1313
export async function queryCollectionNavigationWithEvent<T extends keyof PageCollections>(event: H3Event, collection: T, fields?: Array<keyof PageCollections[T]>) {

0 commit comments

Comments
 (0)