Skip to content

Commit

Permalink
fix: add missing imports
Browse files Browse the repository at this point in the history
  • Loading branch information
atinux committed Feb 21, 2024
1 parent 8ca7a04 commit 53485ac
Show file tree
Hide file tree
Showing 23 changed files with 55 additions and 20 deletions.
3 changes: 3 additions & 0 deletions .nuxtrc
Original file line number Diff line number Diff line change
@@ -1,2 +1,5 @@
# imports.autoImport=false
typescript.includeWorkspace=true

# enable TypeScript bundler module resolution - https://www.typescriptlang.org/docs/handbook/modules/reference.html#bundler
experimental.typescriptBundlerResolution=true
7 changes: 2 additions & 5 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -25,11 +25,8 @@
"dev:build": "nuxi build playground",
"docs": "nuxi dev docs",
"docs:build": "nuxi build docs",
"release": "npm run lint && npm run typecheck && npm run test && npm run prepack && changelogen --release && npm publish && git push --follow-tags",
"release": "npm run lint && npm run test && npm run prepack && changelogen --release && npm publish && git push --follow-tags",
"lint": "eslint .",
"typecheck": "npm run test:types && npm run test:types:playground",
"test:types": "vue-tsc --noEmit",
"test:types:playground": "cd playground && vue-tsc --noEmit",
"test": "vitest run",
"test:watch": "vitest watch"
},
Expand Down Expand Up @@ -67,4 +64,4 @@
"vitest": "^1.3.1",
"vue-tsc": "^1.8.27"
}
}
}
5 changes: 4 additions & 1 deletion playground/nuxt.config.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
export default defineNuxtConfig({
devtools: { enabled: true },
modules: [
'../src/module',
'@nuxthub/core',
'@nuxt/ui',
'@kgierke/nuxt-basic-auth'
],
Expand All @@ -19,5 +19,8 @@ export default defineNuxtConfig({
password: process.env.NUXT_ADMIN_PASSWORD || 'admin'
}
]
},
imports: {
autoImport: true
}
})
8 changes: 7 additions & 1 deletion src/module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import { readUser } from 'rc9'
import { $fetch } from 'ofetch'
import { joinURL } from 'ufo'
import { generateWrangler } from './utils'
import { version } from '../package.json'

const log = logger.withScope('nuxt:hub')

Expand Down Expand Up @@ -52,7 +53,9 @@ export interface ModuleOptions {

export default defineNuxtModule<ModuleOptions>({
meta: {
name: 'hub'
name: '@nuxthub/core',
configKey: 'hub',
version
},
defaults: {
remote: false
Expand All @@ -77,6 +80,9 @@ export default defineNuxtModule<ModuleOptions>({
})

addServerScanDir(resolve('./runtime/server'))
nuxt.options.nitro.externals = nuxt.options.nitro.externals || {}
nuxt.options.nitro.externals.inline = nuxt.options.nitro.externals.inline || []
nuxt.options.nitro.externals.inline.push(resolve('./runtime/server/'))

// nuxt prepare or production mode, stop here
if (nuxt.options._prepare || !nuxt.options.dev) {
Expand Down
1 change: 1 addition & 0 deletions src/runtime/server/api/_hub/analytics/index.put.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import type { AnalyticsEngineDataPoint } from '@cloudflare/workers-types/experimental'
import { eventHandler, readValidatedBody } from 'h3'

export default eventHandler(async (event) => {
const { data } = await readValidatedBody(event, z.object({
Expand Down
3 changes: 3 additions & 0 deletions src/runtime/server/api/_hub/blob/[...pathname].delete.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
import { eventHandler, getValidatedRouterParams } from 'h3'
import { z } from 'zod'

export default eventHandler(async (event) => {
const { pathname } = await getValidatedRouterParams(event, z.object({
pathname: z.string().min(1)
Expand Down
3 changes: 3 additions & 0 deletions src/runtime/server/api/_hub/blob/[...pathname].get.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
import { eventHandler, getValidatedRouterParams } from 'h3'
import { z } from 'zod'

export default eventHandler(async (event) => {
// TODO: handle caching in production
const { pathname } = await getValidatedRouterParams(event, z.object({
Expand Down
3 changes: 3 additions & 0 deletions src/runtime/server/api/_hub/blob/[...pathname].head.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
import { eventHandler, getValidatedRouterParams, setHeader, sendNoContent } from 'h3'
import { z } from 'zod'

export default eventHandler(async (event) => {
const { pathname } = await getValidatedRouterParams(event, z.object({
pathname: z.string().min(1)
Expand Down
3 changes: 3 additions & 0 deletions src/runtime/server/api/_hub/blob/[...pathname].put.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
import { eventHandler, getValidatedRouterParams, getHeader, getRequestWebStream } from 'h3'
import { z } from 'zod'

async function streamToArrayBuffer(stream: ReadableStream, streamSize: number) {
const result = new Uint8Array(streamSize)
let bytesRead = 0
Expand Down
2 changes: 2 additions & 0 deletions src/runtime/server/api/_hub/blob/index.get.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import { eventHandler } from 'h3'

export default eventHandler(async () => {
return useBlob().list()
})
3 changes: 3 additions & 0 deletions src/runtime/server/api/_hub/database/[command].post.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
import { eventHandler, getValidatedRouterParams, readValidatedBody } from 'h3'
import { z } from 'zod'

const statementValidation = z.object({
query: z.string().min(1).max(1e6).trim(),
params: z.any().array(),
Expand Down
2 changes: 2 additions & 0 deletions src/runtime/server/api/_hub/index.head.ts
Original file line number Diff line number Diff line change
@@ -1 +1,3 @@
import { eventHandler, sendNoContent } from 'h3'

export default eventHandler((event) => sendNoContent(event))
1 change: 1 addition & 0 deletions src/runtime/server/api/_hub/kv/[...path].ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import { eventHandler } from 'h3'
import { createH3StorageHandler } from 'unstorage/server'

export default eventHandler(async (event) => {
Expand Down
2 changes: 2 additions & 0 deletions src/runtime/server/api/_hub/primitives.get.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import { eventHandler } from 'h3'

export default eventHandler(async () => {
const [ dbCheck, kvCheck, blobCheck ] = await Promise.all([
falseIfFail(() => useDatabase().exec('PRAGMA table_list')),
Expand Down
2 changes: 2 additions & 0 deletions src/runtime/server/middleware/1.hub-auth.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
import { eventHandler, getHeader, createError } from 'h3'
import { $fetch } from 'ofetch'
import { useRuntimeConfig } from '#imports'

export default eventHandler(async (event) => {
// Skip if not a hub request
Expand Down
11 changes: 8 additions & 3 deletions src/runtime/server/plugins/cloudflare.dev.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,13 @@
export default defineNitroPlugin(async (nitroApp) => {
import type { H3Event } from 'h3'
import type { NitroApp } from 'nitropack'
// @ts-ignore
import { defineNitroPlugin, useRuntimeConfig } from '#imports'
import { hubHooks } from '../utils/hooks'

export default defineNitroPlugin(async (nitroApp: NitroApp) => {
const proxyPromise = getBindingsProxy()

nitroApp.hooks.hook('request', async (event) => {
nitroApp.hooks.hook('request', async (event: H3Event) => {
const proxy = await proxyPromise
// Inject proxy bindings to the request context
// https://github.com/unjs/nitro/blob/main/src/runtime/entries/cloudflare-pages.ts
Expand Down Expand Up @@ -49,7 +55,6 @@ async function getBindingsProxy() {
}
})

// @ts-ignore
await hubHooks.callHook('bindings:ready')

return proxy
Expand Down
3 changes: 0 additions & 3 deletions src/runtime/server/tsconfig.json

This file was deleted.

1 change: 1 addition & 0 deletions src/runtime/server/utils/analytics.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import type { AnalyticsEngineDataPoint, AnalyticsEngineDataset } from '@cloudflare/workers-types/experimental'
import { ofetch } from 'ofetch'
import { joinURL } from 'ufo'
import { useRuntimeConfig } from '#imports'

const _datasets: Record<string, AnalyticsEngineDataset> = {}

Expand Down
1 change: 1 addition & 0 deletions src/runtime/server/utils/blob.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import { defu } from 'defu'
import { randomUUID } from 'uncrypto'
import { parse } from 'pathe'
import { joinURL } from 'ufo'
import { useRuntimeConfig } from '#imports'

export interface BlobObject {
pathname: string
Expand Down
1 change: 1 addition & 0 deletions src/runtime/server/utils/database.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import type { D1Database } from '@cloudflare/workers-types/experimental'
import { ofetch } from 'ofetch'
import { joinURL } from 'ufo'
import type { H3Error } from 'h3'
import { useRuntimeConfig } from '#imports'

let _db: D1Database

Expand Down
1 change: 1 addition & 0 deletions src/runtime/server/utils/hooks.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import { useRuntimeConfig } from '#imports'
import { createHooks } from 'hookable'

export interface HubHooks {
Expand Down
1 change: 1 addition & 0 deletions src/runtime/server/utils/kv.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import { createStorage } from 'unstorage'
import httpDriver from 'unstorage/drivers/http'
import cloudflareKVBindingDriver from 'unstorage/drivers/cloudflare-kv-binding'
import { joinURL } from 'ufo'
import { useRuntimeConfig } from '#imports'

let _kv: Storage

Expand Down
8 changes: 1 addition & 7 deletions tsconfig.json
Original file line number Diff line number Diff line change
@@ -1,9 +1,3 @@
{
"extends": "./.nuxt/tsconfig.json",
"exclude": [
"playground",
"src/module/runtime/server",
"docs",
"dist"
]
"extends": "./.nuxt/tsconfig.json"
}

0 comments on commit 53485ac

Please sign in to comment.