Skip to content

Commit 4890997

Browse files
committed
fix: typecheck
1 parent acfbe96 commit 4890997

File tree

15 files changed

+102
-474
lines changed

15 files changed

+102
-474
lines changed

.github/workflows/ci.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ jobs:
2424
- run: pnpm dev:prepare
2525
- run: pnpm lint
2626
- run: pnpm prepack
27+
- run: pnpm typecheck
2728
- run: pnpm test
2829
- name: Publish
2930
run: pnpx pkg-pr-new publish --compact --no-template --pnpm

package.json

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@
3333
],
3434
"scripts": {
3535
"prepack": "nuxt-module-build build",
36+
"typecheck": "nuxi typecheck",
3637
"example": "run () { nuxi dev examples/$*; }; run",
3738
"docs": "nuxi dev docs",
3839
"docs:build": "nuxi build docs",
@@ -105,6 +106,7 @@
105106
"@release-it/conventional-changelog": "^9.0.3",
106107
"@types/better-sqlite3": "^7.6.12",
107108
"@types/micromatch": "^4.0.9",
109+
"@types/minimatch": "^5.1.2",
108110
"@types/node": "^22.9.1",
109111
"@types/pg": "^8.11.10",
110112
"@types/ws": "^8.5.13",

pnpm-lock.yaml

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

src/runtime/adapters/sqlite.ts

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,7 @@ export default createDatabaseAdapter<{ filename: string }>((opts) => {
77
if (!db) {
88
const filename = !opts || isAbsolute(opts?.filename || '')
99
? opts?.filename
10-
// @ts-expect-error - `_importMeta_` is defined in nitro runtime
11-
: new URL(opts.filename, globalThis._importMeta_.url).pathname
10+
: new URL(opts.filename, (globalThis as unknown as { _importMeta_: { url: string } })._importMeta_.url).pathname
1211
db = new Database(filename)
1312
}
1413

src/runtime/internal/navigation.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ export async function generateNavigationTree<T extends PageCollectionItemBase>(q
5454
stem: content.stem,
5555
children: [],
5656
...pickNavigationFields(content),
57-
})
57+
} as ContentNavigationItem)
5858

5959
// Create navigation item from content
6060
const navItem: ContentNavigationItem = getNavItem(content)

src/runtime/internal/query.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,7 @@ export const collectionQureyBuilder = <T extends keyof Collections>(collection:
8787
async count(field: keyof Collections[T] | '*' = '*', distinct: boolean = false) {
8888
return fetch(collection, buildQuery({
8989
count: { field: String(field), distinct },
90-
})).then(m => m[0].count)
90+
})).then(m => (m[0] as { count: number }).count)
9191
},
9292
}
9393

src/runtime/internal/studio/collection.ts

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,14 @@
11
import { minimatch } from 'minimatch'
22
import type { CollectionInfo } from '@nuxt/content'
33
// import { joinURL, withoutLeadingSlash } from 'ufo'
4+
import type { JsonSchema7ObjectType } from 'zod-to-json-schema'
45
import { getOrderedSchemaKeys } from '../schema'
56
// import { parseSourceBase } from './utils'
67
import { withoutRoot } from './files'
78

89
export const getCollectionByPath = (path: string, collections: Record<string, CollectionInfo>): CollectionInfo => {
910
return Object.values(collections).find((collection) => {
10-
if (!collection.source) {
11+
if (!collection.source || collection.source.length === 0) {
1112
return
1213
}
1314

@@ -26,7 +27,7 @@ export const getCollectionByPath = (path: string, collections: Record<string, Co
2627

2728
const paths = pathWithoutRoot === '/' ? ['index.yml', 'index.yaml', 'index.md', 'index.json'] : [pathWithoutRoot]
2829
return paths.some((p) => {
29-
return minimatch(p, collection.source.include)
30+
return collection.source.some(source => minimatch(p, source.include))
3031
})
3132
})
3233
}
@@ -59,13 +60,13 @@ export function generateRecordSelectByColumn(collection: CollectionInfo, column:
5960
function computeValuesBasedOnCollectionSchema(collection: CollectionInfo, data: Record<string, unknown>) {
6061
const fields: string[] = []
6162
const values: Array<string | number | boolean> = []
62-
const properties = collection.schema.definitions[collection.name].properties
63+
const properties = (collection.schema.definitions[collection.name] as JsonSchema7ObjectType).properties
6364
const sortedKeys = getOrderedSchemaKeys(properties)
6465

6566
sortedKeys.forEach((key) => {
6667
const value = (properties)[key]
6768
// const underlyingType = getUnderlyingType(value as ZodType<unknown, ZodOptionalDef>)
68-
const underlyingType = value.type
69+
const underlyingType = (value as JsonSchema7ObjectType).type
6970

7071
const defaultValue = value.default ? value.default : 'NULL'
7172
const valueToInsert = typeof data[key] !== 'undefined' ? data[key] : defaultValue

src/runtime/internal/studio/compatibility.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import type { CollectionInfo, DraftSyncFile } from '@nuxt/content'
2+
import type { JsonSchema7ObjectType } from 'zod-to-json-schema'
23

34
export const v2ToV3ParsedFile = (file: DraftSyncFile, collection: CollectionInfo) => {
45
const mappedFile: Record<string, unknown> = {
@@ -9,7 +10,7 @@ export const v2ToV3ParsedFile = (file: DraftSyncFile, collection: CollectionInfo
910
path: file.parsed._path,
1011
}
1112

12-
const properties = collection.schema.definitions[collection.name].properties
13+
const properties = (collection.schema.definitions[collection.name] as JsonSchema7ObjectType).properties
1314

1415
// Map parsed content to collection schema
1516
Object.keys(file.parsed).forEach((key) => {

src/runtime/internal/studio/index.ts

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import { createApp } from 'vue'
22
import type { AppConfig } from 'nuxt/schema'
3-
import type { CollectionInfo, FileChangeMessagePayload, FileMessageData, FileSelectMessagePayload, DraftSyncData, PreviewFile, DraftSyncFile } from '@nuxt/content'
3+
import type { PublicRuntimeConfig, CollectionInfo, FileChangeMessagePayload, FileMessageData, FileSelectMessagePayload, DraftSyncData, PreviewFile, DraftSyncFile } from '@nuxt/content'
44
import { withLeadingSlash } from 'ufo'
55
import StudioPreviewMode from '../../components/StudioPreviewMode.vue'
66
import { loadDatabaseAdapter } from '../database.client'
@@ -70,12 +70,13 @@ const syncDraftAppConfig = (appConfig?: Record<string, unknown>) => {
7070
// Reset app config to initial state if no appConfig is provided
7171
// Makes sure that app config does not contain any preview data
7272
if (!appConfig) {
73+
// @ts-expect-error -- TODO fix type
7374
deepDelete(_appConfig, initialAppConfig)
7475
}
7576
}
7677

7778
export function mountPreviewUI() {
78-
const { studio } = useRuntimeConfig().public
79+
const studio: PublicRuntimeConfig['studio'] = useRuntimeConfig().public.studio || {}
7980

8081
const previewToken = window.sessionStorage.getItem('previewToken')
8182
// Show loading
@@ -91,7 +92,7 @@ export function mountPreviewUI() {
9192

9293
export function initIframeCommunication() {
9394
const nuxtApp = useNuxtApp()
94-
const { studio } = useRuntimeConfig().public
95+
const studio: PublicRuntimeConfig['studio'] = useRuntimeConfig().public.studio
9596

9697
// Not in an iframe
9798
if (!window.parent || window.self === window.parent) {
@@ -116,7 +117,7 @@ export function initIframeCommunication() {
116117
}
117118
})
118119

119-
window.addEventListener('message', async (e: { data: FileMessageData }) => {
120+
window.addEventListener('message', async (e: { origin: string, data: FileMessageData }) => {
120121
if (!dbReady.value) {
121122
return
122123
}

src/runtime/plugins/studio/preview.client.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
1+
import type { PublicRuntimeConfig } from '@nuxt/content'
12
import { defineNuxtPlugin, useCookie, useRoute, useRuntimeConfig } from '#imports'
23

34
export default defineNuxtPlugin(async (nuxtApp) => {
4-
const studioConfig = useRuntimeConfig().public.studio || {}
5+
const studioConfig: PublicRuntimeConfig['studio'] = useRuntimeConfig().public.studio || {}
56
const route = useRoute()
67
const previewToken = useCookie('previewToken', { sameSite: 'none', secure: true })
78

0 commit comments

Comments
 (0)