Skip to content

Commit

Permalink
chore: update
Browse files Browse the repository at this point in the history
  • Loading branch information
atinux committed Mar 18, 2024
1 parent cc68e12 commit 8ce8482
Show file tree
Hide file tree
Showing 5 changed files with 34 additions and 14 deletions.
2 changes: 1 addition & 1 deletion playground/server/api/kv/[key].delete.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ export default eventHandler(async (event) => {
}).parse)

// Delete entry for the current user
await hubKV().removeItem(key)
await hubKV().del(key)

return { key }
})
2 changes: 1 addition & 1 deletion playground/server/api/kv/index.put.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ export default eventHandler(async (event) => {
}).parse)

// Set entry for the current user
await hubKV().setItem(key, value)
await hubKV().set(key, value)

return { key, value }
})
14 changes: 7 additions & 7 deletions src/server/utils/blob.ts
Original file line number Diff line number Diff line change
Expand Up @@ -84,40 +84,40 @@ function _useBucket(name: string = 'BLOB') {

interface HubBlob {
/**
* Lists all the blobs in the bucket.
* List all the blobs in the bucket.
*
* @param options The list options
*/
list(options?: BlobListOptions): Promise<BlobObject[]>
/**
* Serves the blob from the bucket.
* Serve the blob from the bucket.
*
* @param event The H3 event (needed to set headers for the response)
* @param pathname The pathname of the blob
*/
serve(event: H3Event, pathname: string): Promise<ReadableStream<any>>
/**
* Puts a new blob into the bucket.
* Put a new blob into the bucket.
*
* @param pathname The pathname of the blob
* @param body The blob content
* @param options The put options
*/
put(pathname: string, body: string | ReadableStream<any> | ArrayBuffer | ArrayBufferView | Blob, options?: BlobPutOptions): Promise<BlobObject>
/**
* Gets the blob metadata from the bucket.
* Get the blob metadata from the bucket.
*
* @param pathname The pathname of the blob
*/
head(pathname: string): Promise<BlobObject>
/**
* Deletes the blob from the bucket.
* Delete the blob from the bucket.
*
* @param pathnames The pathname of the blob
*/
del(pathnames: string | string[]): Promise<void>
/**
* Deletes the blob from the bucket.
* Delete the blob from the bucket.
*
* @param pathnames The pathname of the blob
*/
Expand Down Expand Up @@ -340,7 +340,7 @@ function fileSizeToBytes(input: string) {
}

/**
* Ensures the blob is valid and meets the specified requirements.
* Ensure the blob is valid and meets the specified requirements.
*
* @param blob The blob to check
* @param options The options to check against
Expand Down
20 changes: 20 additions & 0 deletions src/server/utils/hooks.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,28 @@ export interface HubHooks {
'bindings:ready': () => any | void
}

/**
* Access Hub lifecycle hooks.
*
* @example ```ts
* hubHooks.on('bindings:ready', () => {
* console.log('Bindings are ready!')
* })
* ```
* @see https://hub.nuxt.com/docs/recipes/hooks#hubhooks
*/
export const hubHooks = createHooks<HubHooks>()

/**
* Run a callback when the NuxtHub environment bindings are set up.
* @param cb The callback to run
* @example ```ts
* onHubReady(() => {
* console.log('Bindings are ready!')
* })
* ```
* @see https://hub.nuxt.com/docs/recipes/hooks#onhubready
*/
export function onHubReady (cb: HubHooks['bindings:ready']) {
const hub = useRuntimeConfig().hub
if (import.meta.dev && !hub.remote) {
Expand Down
10 changes: 5 additions & 5 deletions src/server/utils/kv.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,21 +8,21 @@ import { useRuntimeConfig } from '#imports'

export interface HubKV extends Storage {
/**
* Gets all keys from the storage.
* Get all keys from the storage.
*
* @see https://hub.nuxt.com/docs/storage/kv#keys
*/
keys: Storage['getKeys']
/**
* Gets an item from the storage.
* Get an item from the storage.
*
* @param key The key to get
*
* @see https://hub.nuxt.com/docs/storage/kv#get
*/
get: Storage['getItem']
/**
* Sets an item in the storage.
* Set an item in the storage.
*
* @param key The key to set
* @param value The value to set
Expand All @@ -31,15 +31,15 @@ export interface HubKV extends Storage {
*/
set: Storage['setItem']
/**
* Checks if an item exists in the storage.
* Check if an item exists in the storage.
*
* @param key The key to check
*
* @see https://hub.nuxt.com/docs/storage/kv#has
*/
has: Storage['hasItem']
/**
* Deletes an item from the storage.
* Delete an item from the storage.
*
* @param key The key to delete
*
Expand Down

0 comments on commit 8ce8482

Please sign in to comment.