Skip to content

Commit ec7e13f

Browse files
committed
chore: rename use to hub prefix to avoid collision with Nitro
In order to better integrate in the future
1 parent 394a044 commit ec7e13f

28 files changed

+61
-61
lines changed

README.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,9 +9,9 @@ Build full-stack applications with Nuxt on CloudFlare, with zero configuration.
99

1010
## Features
1111

12-
- Query an SQLite database with `useDatabase()`
13-
- Access key-value storage with `useKV()`
14-
- Store files with `useBlob()`
12+
- Query an SQLite database with `hubDatabase()`
13+
- Access key-value storage with `hubKV()`
14+
- Store files with `hubBlob()`
1515

1616
Read more on https://hub.nuxt.com
1717

docs/content/docs/1.getting-started/1.index.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,9 +12,9 @@ It is **currently made to be deployed on [Cloudflare Pages](https://pages.cloudf
1212
## Storage
1313

1414
NuxtHub provides different storage to help you build full-stack applications:
15-
- **SQL database** to store your application's data with [`useDatabase()`](/docs/storage/database)
16-
- **Key-Value** to store JSON data accessible globally with low-latency with [`useKV()`](/docs/storage/kv)
17-
- **Blob storage** to store static assets, such as images, video and more with [`useBlob()`](/docs/storage/blob)
15+
- **SQL database** to store your application's data with [`hubDatabase()`](/docs/storage/database)
16+
- **Key-Value** to store JSON data accessible globally with low-latency with [`hubKV()`](/docs/storage/kv)
17+
- **Blob storage** to store static assets, such as images, video and more with [`hubBlob()`](/docs/storage/blob)
1818

1919
Each storage utils is auto-imported and ready to be used in your [Nuxt's server directory](https://nuxt.com/docs/guide/directory-structure/server).
2020

docs/content/docs/2.storage/1.database.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,12 +7,12 @@ NuxtHub Database is a layer on top of [Cloudflare D1](https://developers.cloudfl
77

88
Once properly configured, NuxtHub module exposes a server composable to the application.
99

10-
## `useDatabase()`
10+
## `hubDatabase()`
1111

1212
Server composable that returns a [D1 database client](https://developers.cloudflare.com/d1/build-databases/query-databases/).
1313

1414
```ts
15-
const db = useDatabase()
15+
const db = hubDatabase()
1616
```
1717

1818
::callout
@@ -183,7 +183,7 @@ Executes one or more queries directly without prepared statements or parameters
183183
If an error occurs, an exception is thrown with the query and error messages, execution stops and further statements are not executed.
184184

185185
```ts
186-
const result = await useDatabase().exec(`CREATE TABLE IF NOT EXISTS frameworks (id INTEGER PRIMARY KEY, name TEXT NOT NULL, year INTEGER NOT NULL DEFAULT 0)`)
186+
const result = await hubDatabase().exec(`CREATE TABLE IF NOT EXISTS frameworks (id INTEGER PRIMARY KEY, name TEXT NOT NULL, year INTEGER NOT NULL DEFAULT 0)`)
187187
console.log(result)
188188
/*
189189
{

docs/content/docs/2.storage/2.kv.md

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ NuxtHub KV is a layer to [Cloudflare Workers KV](https://developers.cloudflare.c
99

1010
Once properly configured, NuxtHub module exposes a server composable to the application.
1111

12-
## `useKV()`
12+
## `hubKV()`
1313

1414
Server composable that returns a [Storage](https://unstorage.unjs.io/getting-started/usage#interface){target=_blank}.
1515

@@ -19,7 +19,7 @@ Retrieves all keys from the storage.
1919

2020
```ts[/api/kv/index.get.ts]
2121
export default eventHandler(async () => {
22-
return await useKV().getKeys()
22+
return await hubKV().getKeys()
2323
})
2424
```
2525

@@ -31,7 +31,7 @@ Retrieves an item from the storage.
3131
export default eventHandler(async () => {
3232
const { key } = getRouterParams(event)
3333
34-
return await useKV().getItem(key)
34+
return await hubKV().getItem(key)
3535
})
3636
```
3737

@@ -43,7 +43,7 @@ Puts an item in the storage.
4343
export default eventHandler(async () => {
4444
const { key, value } = await readBody(event)
4545
46-
return await useKV().setItem(key, value)
46+
return await hubKV().setItem(key, value)
4747
})
4848
```
4949

@@ -55,7 +55,7 @@ Deletes an item from the storage.
5555
export default eventHandler(async (event) => {
5656
const { key } = getRouterParams(event)
5757
58-
await useKV().removeItem(key)
58+
await hubKV().removeItem(key)
5959
6060
return { key }
6161
})

docs/content/docs/2.storage/3.blob.md

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ NuxtHub Blob is a layer to [Cloudflare R2](https://developers.cloudflare.com/r2)
77

88
Once properly configured, NuxtHub module exposes a server composable to the application.
99

10-
## `useBlob()`
10+
## `hubBlob()`
1111

1212
Server composable that returns a set of methods to manipulate the blob storage.
1313

@@ -17,7 +17,7 @@ Returns a paginated list of blobs.
1717

1818
```ts [server/api/files.get.ts]
1919
export default eventHandler(async () => {
20-
return useBlob().list()
20+
return hubBlob().list()
2121
})
2222
```
2323

@@ -50,7 +50,7 @@ Returns a blob's data.
5050
export default eventHandler(async (event) => {
5151
const { pathname } = getRouterParams(event)
5252

53-
return useBlob().serve(event, pathname)
53+
return hubBlob().serve(event, pathname)
5454
})
5555
```
5656

@@ -82,7 +82,7 @@ If you are fetching an image with a server route similar to the one above, you m
8282
Returns a blob's metadata.
8383

8484
```ts
85-
const blob = await useBlob().head(pathname)
85+
const blob = await hubBlob().head(pathname)
8686
```
8787

8888
#### Params
@@ -113,7 +113,7 @@ export default eventHandler(async (event) => {
113113

114114
ensureBlob(file, { maxSize: '1MB', types: ['image' ]})
115115

116-
return useBlob().put(`images/${file.name}`, file, { addRandomSuffix: false })
116+
return hubBlob().put(`images/${file.name}`, file, { addRandomSuffix: false })
117117
})
118118
```
119119

@@ -152,7 +152,7 @@ Deletes a blob.
152152
export default eventHandler(async (event) => {
153153
const { pathname } = getRouterParams(event)
154154

155-
await useBlob().delete(pathname)
155+
await hubBlob().delete(pathname)
156156

157157
return sendNoContent(event)
158158
})

docs/content/docs/3.recipes/1.hooks.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ export default defineNitroPlugin(() => {
1818
// Only run migrations in development
1919
if (import.meta.dev) {
2020
onHubReady(async () => {
21-
await useDatabase().exec(`
21+
await hubDatabase().exec(`
2222
CREATE TABLE IF NOT EXISTS todos (
2323
id INTEGER PRIMARY KEY,
2424
title TEXT NOT NULL,
@@ -55,7 +55,7 @@ You can use the `hubHooks` object to listen to the `bindings:ready` event in you
5555
export default defineNitroPlugin(() => {
5656
hubHooks.hook('bindings:ready', () => {
5757
console.log('NuxtHub bindings are ready!')
58-
const db = useDatabase()
58+
const db = hubDatabase()
5959
})
6060
})
6161
```

docs/content/docs/3.recipes/2.drizzle.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -104,7 +104,7 @@ export default defineNitroPlugin(async () => {
104104
let migrationFiles = await migrationsStorage.getKeys()
105105
migrationFiles = migrationFiles.filter(key => key.endsWith('.sql'))
106106

107-
const database = useDatabase()
107+
const database = hubDatabase()
108108

109109
for (const file of migrationFiles) {
110110
consola.info(`Applying database migrations from ${file}...`)
@@ -140,7 +140,7 @@ import * as schema from '../database/schema'
140140
export const tables = schema
141141

142142
export function useDrizzle() {
143-
return drizzle(useDatabase(), { schema })
143+
return drizzle(hubDatabase(), { schema })
144144
}
145145

146146
export type User = typeof schema.users.$inferSelect

docs/content/index.yml

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ hero:
1111
trailing: true
1212
to: '/docs/getting-started'
1313
size: lg
14-
- label: Open on GitHub
14+
- label: Star on GitHub
1515
icon: i-simple-icons-github
1616
size: lg
1717
color: gray
@@ -20,9 +20,9 @@ hero:
2020
code: |
2121
```ts [server/api/hello.ts]
2222
export default eventHandler(async (event) => {
23-
const database = useDatabase()
24-
const blob = useBlob()
25-
const kv = useKV()
23+
const database = hubDatabase()
24+
const blob = hubBlob()
25+
const kv = hubKV()
2626
2727
// Do your magic here
2828
return { hello: 'world' }
@@ -37,7 +37,7 @@ features:
3737
trailing: true
3838
to: '/docs/getting-started'
3939
size: lg
40-
- label: Open on GitHub
40+
- label: Star on GitHub
4141
icon: i-simple-icons-github
4242
size: lg
4343
color: gray

playground/server/api/blob/[...pathname].delete.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,5 +3,5 @@ export default eventHandler(async (event) => {
33
pathname: z.string().min(1)
44
}).parse)
55

6-
return useBlob().delete(pathname)
6+
return hubBlob().delete(pathname)
77
})

playground/server/api/blob/[...pathname].get.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,5 +3,5 @@ export default eventHandler(async (event) => {
33
pathname: z.string().min(1)
44
}).parse)
55

6-
return useBlob().serve(event, pathname)
6+
return hubBlob().serve(event, pathname)
77
})
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
11
export default eventHandler(async () => {
2-
return useBlob().list()
2+
return hubBlob().list()
33
})

playground/server/api/blob/index.put.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ export default eventHandler(async (event) => {
55
throw createError({ statusCode: 400, message: 'Missing files' })
66
}
77

8-
const { put } = useBlob()
8+
const { put } = hubBlob()
99
const objects: BlobObject[] = []
1010
try {
1111
for (const file of files) {

playground/server/api/kv/[key].delete.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ export default eventHandler(async (event) => {
44
}).parse)
55

66
// Delete entry for the current user
7-
await useKV().removeItem(key)
7+
await hubKV().removeItem(key)
88

99
return { key }
1010
})

playground/server/api/kv/index.get.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
export default eventHandler(async () => {
22
// List entries for the current user
3-
const storage = useKV()
3+
const storage = hubKV()
44

55
const keys = await storage.getKeys()
66
// const items = await storage.getItems(keys)

playground/server/api/kv/index.put.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ export default eventHandler(async (event) => {
55
}).parse)
66

77
// Set entry for the current user
8-
await useKV().setItem(key, value)
8+
await hubKV().setItem(key, value)
99

1010
return { key, value }
1111
})

playground/server/api/test.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
export default eventHandler(async () => {
2-
const db = useDatabase()
2+
const db = hubDatabase()
33
// return useProjectKV(projectUrl).getKeys()
44
// return await db.prepare('SELECT * from todos').all()
55
// return await db.prepare("SELECT * from todos").first()

playground/server/utils/db.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,5 +14,5 @@ export const tables = {
1414
}
1515

1616
export function useDrizzle() {
17-
return drizzle(useDatabase(), { schema: tables })
17+
return drizzle(hubDatabase(), { schema: tables })
1818
}
Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,13 @@
11
import { eventHandler, getValidatedRouterParams } from 'h3'
22
import { z } from 'zod'
3-
import { useBlob } from '../../../utils/blob'
3+
import { hubBlob } from '../../../utils/blob'
44

55
export default eventHandler(async (event) => {
66
const { pathname } = await getValidatedRouterParams(event, z.object({
77
pathname: z.string().min(1)
88
}).parse)
99

10-
await useBlob().delete(pathname)
10+
await hubBlob().delete(pathname)
1111

1212
return sendNoContent(event)
1313
})
Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
11
import { eventHandler, getValidatedRouterParams } from 'h3'
22
import { z } from 'zod'
3-
import { useBlob } from '../../../utils/blob'
3+
import { hubBlob } from '../../../utils/blob'
44

55
export default eventHandler(async (event) => {
66
// TODO: handle caching in production
77
const { pathname } = await getValidatedRouterParams(event, z.object({
88
pathname: z.string().min(1)
99
}).parse)
1010

11-
return useBlob().serve(event, pathname)
11+
return hubBlob().serve(event, pathname)
1212
})

src/runtime/server/api/_hub/blob/[...pathname].head.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,13 @@
11
import { eventHandler, getValidatedRouterParams, setHeader, sendNoContent } from 'h3'
22
import { z } from 'zod'
3-
import { useBlob } from '../../../utils/blob'
3+
import { hubBlob } from '../../../utils/blob'
44

55
export default eventHandler(async (event) => {
66
const { pathname } = await getValidatedRouterParams(event, z.object({
77
pathname: z.string().min(1)
88
}).parse)
99

10-
const blob = await useBlob().head(pathname)
10+
const blob = await hubBlob().head(pathname)
1111

1212
setHeader(event, 'x-blob', JSON.stringify(blob))
1313

src/runtime/server/api/_hub/blob/[...pathname].put.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import { eventHandler, getValidatedRouterParams, getHeader, getRequestWebStream } from 'h3'
22
import { z } from 'zod'
3-
import { useBlob } from '../../../utils/blob'
3+
import { hubBlob } from '../../../utils/blob'
44

55
async function streamToArrayBuffer(stream: ReadableStream, streamSize: number) {
66
const result = new Uint8Array(streamSize)
@@ -34,5 +34,5 @@ export default eventHandler(async (event) => {
3434
const stream = getRequestWebStream(event)!
3535
const body = await streamToArrayBuffer(stream, contentLength)
3636

37-
return useBlob().put(pathname, body, options)
37+
return hubBlob().put(pathname, body, options)
3838
})
Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import { eventHandler } from 'h3'
2-
import { useBlob } from '../../../utils/blob'
2+
import { hubBlob } from '../../../utils/blob'
33

44
export default eventHandler(async () => {
5-
return useBlob().list()
5+
return hubBlob().list()
66
})

src/runtime/server/api/_hub/database/[command].post.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import { eventHandler, getValidatedRouterParams, readValidatedBody } from 'h3'
22
import { z } from 'zod'
3-
import { useDatabase } from '../../../utils/database'
3+
import { hubDatabase } from '../../../utils/database'
44

55
const statementValidation = z.object({
66
query: z.string().min(1).max(1e6).trim(),
@@ -12,7 +12,7 @@ export default eventHandler(async (event) => {
1212
const { command } = await getValidatedRouterParams(event, z.object({
1313
command: z.enum(['first', 'all', 'raw', 'run', 'dump', 'exec', 'batch'])
1414
}).parse)
15-
const db = useDatabase()
15+
const db = hubDatabase()
1616

1717
if (command === 'exec') {
1818
const { query } = await readValidatedBody(event, z.object({

src/runtime/server/api/_hub/kv/[...path].ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
import { eventHandler } from 'h3'
22
import { createH3StorageHandler } from 'unstorage/server'
3-
import { useKV } from '../../../utils/kv'
3+
import { hubKV } from '../../../utils/kv'
44

55
export default eventHandler(async (event) => {
6-
const storage = useKV()
6+
const storage = hubKV()
77
return createH3StorageHandler(storage, {
88
resolvePath(event) {
99
return event.context.params!.path || ''

0 commit comments

Comments
 (0)