Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: use unstorage types #2136

Merged
merged 4 commits into from
Jul 17, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
3 changes: 1 addition & 2 deletions src/module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,7 @@ import { hash } from 'ohash'
import { join, relative } from 'pathe'
import type { Lang as ShikiLang, Theme as ShikiTheme } from 'shiki-es'
import { listen } from 'listhen'
import type { WatchEvent } from 'unstorage'
import { createStorage } from 'unstorage'
import { type WatchEvent, createStorage } from 'unstorage'
import { joinURL, withLeadingSlash, withTrailingSlash } from 'ufo'
import type { Component } from '@nuxt/schema'
import { name, version } from '../package.json'
Expand Down
3 changes: 1 addition & 2 deletions src/runtime/composables/client-db.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import type { Storage } from 'unstorage'
// @ts-ignore
import memoryDriver from 'unstorage/drivers/memory'
import { createStorage, prefixStorage } from 'unstorage'
import { type Storage, createStorage, prefixStorage } from 'unstorage'
import { withBase } from 'ufo'
import { useRuntimeConfig, useNuxtApp } from '#app'
import { createPipelineFetcher } from '../query/match/pipeline'
Expand Down
2 changes: 1 addition & 1 deletion src/runtime/markdown-parser/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ export const useDefaultOptions = (): MarkdownOptions => ({
export async function parse (file: string, userOptions: Partial<MarkdownOptions> = {}) {
const options = defu(userOptions, useDefaultOptions()) as MarkdownOptions

const { content, data } = await parseFrontMatter(file)
const { content, data } = parseFrontMatter(file)

// Compile markdown from file content to JSON
const body = await generateBody(content, { ...options, data })
Expand Down
6 changes: 3 additions & 3 deletions src/runtime/server/storage.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { prefixStorage } from 'unstorage'
import { type StorageValue, prefixStorage } from 'unstorage'
import { joinURL, withLeadingSlash, withoutTrailingSlash } from 'ufo'
import { hash as ohash } from 'ohash'
import type { H3Event } from 'h3'
Expand Down Expand Up @@ -151,7 +151,7 @@ export const getContent = async (event: H3Event, id: string): Promise<ParsedCont
return { _id: contentId, body: null }
}

const parsed = await parseContent(contentId, body as string) as ParsedContent
const parsed = await parseContent(contentId, body) as ParsedContent

await cacheParsedStorage.setItem(id, { parsed, hash }).catch(() => {})

Expand All @@ -161,7 +161,7 @@ export const getContent = async (event: H3Event, id: string): Promise<ParsedCont
/**
* Parse content file using registered plugins
*/
export async function parseContent (id: string, content: string, opts: ParseContentOptions = {}) {
export const parseContent = async (id: string, content: StorageValue, opts: ParseContentOptions = {}) => {
const nitroApp = useNitroApp()
const options = defu(
opts,
Expand Down
3 changes: 2 additions & 1 deletion src/runtime/transformers/index.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { extname } from 'pathe'
import { camelCase } from 'scule'
import type { StorageValue } from 'unstorage'
import type { ContentTransformer, TransformContentOptions } from '../types'
import csv from './csv'
import markdown from './markdown'
Expand Down Expand Up @@ -36,7 +37,7 @@ function getTransformers (ext: string, additionalTransformers: ContentTransforme
/**
* Parse content file using registered plugins
*/
export async function transformContent (id: string, content: string, options: TransformContentOptions = {}) {
export async function transformContent (id: string, content: StorageValue, options: TransformContentOptions = {}) {
const { transformers = [] } = options
// Call hook before parsing the file
const file = { _id: id, body: content }
Expand Down
2 changes: 1 addition & 1 deletion src/runtime/transformers/markdown.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ export default defineTransformer({
config.rehypePlugins = await importPlugins(config.rehypePlugins)
config.remarkPlugins = await importPlugins(config.remarkPlugins)

const parsed = await parse(content, config)
const parsed = await parse(content as string, config)

return <MarkdownParsedContent> {
...parsed.meta,
Expand Down
4 changes: 2 additions & 2 deletions src/runtime/transformers/yaml.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@ import { defineTransformer } from './utils'
export default defineTransformer({
name: 'Yaml',
extensions: ['.yml', '.yaml'],
parse: async (_id, content) => {
const { data } = await parseFrontMatter(`---\n${content}\n---`)
parse: (_id, content) => {
const { data } = parseFrontMatter(`---\n${content}\n---`)

// Keep array contents under `body` key
let parsed = data
Expand Down
3 changes: 2 additions & 1 deletion src/runtime/types.d.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import type { Theme } from 'shiki-es'
import type { StorageValue } from 'unstorage'

export interface ParsedContentInternalMeta {
/**
Expand Down Expand Up @@ -140,7 +141,7 @@ export interface MarkdownParsedContent extends ParsedContent {
export interface ContentTransformer {
name: string
extensions: string[]
parse?(id: string, content: string, options: any): Promise<ParsedContent> | ParsedContent
parse?(id: string, content: StorageValue, options: any): Promise<ParsedContent> | ParsedContent
transform?(content: ParsedContent, options: any): Promise<ParsedContent> | ParsedContent
}

Expand Down