Skip to content

Commit

Permalink
chore: update docs
Browse files Browse the repository at this point in the history
  • Loading branch information
frytg committed Jan 6, 2025
1 parent 1905256 commit 629a99b
Show file tree
Hide file tree
Showing 5 changed files with 22 additions and 32 deletions.
3 changes: 1 addition & 2 deletions logger/logger.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
/**
* A pre-configured logger that is ready to use with syslog levels.
*
* @module
* A pre-configured logger that is ready to use with syslog levels.
*/

// load packages
Expand Down
4 changes: 4 additions & 0 deletions storage-s3/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
# Storage S3 Changelog

## 2025-01-06 - 0.0.5

- fix: `@module` docs

## 2025-01-05 - 0.0.4

- fix: `@module` docs
Expand Down
3 changes: 2 additions & 1 deletion storage-s3/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,10 @@ This is a simple opinionated wrapper around the S3 library [MinIO](https://min.i
## Usage

```ts
import { getRequiredEnv } from '@frytg/check-required-env/get';
import { getObject } from '@frytg/storage-s3';

const object = await getObject('path/to/object.json', { parseJson: true });
const object = await getObject(getRequiredEnv('STORE_S3_BUCKET_NAME'), 'path/to/object.json', { parseJson: true });
```

The MinIO client will be initialized with these required environment variables:
Expand Down
2 changes: 1 addition & 1 deletion storage-s3/deno.jsonc
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"$schema": "https://jsr.io/schema/config-file.v1.json",
"name": "@frytg/storage-s3",
"version": "0.0.4",
"version": "0.0.5",
"exports": "./storage.ts",
"imports": {
"minio": "npm:minio@^8.0.3"
Expand Down
42 changes: 14 additions & 28 deletions storage-s3/storage.ts
Original file line number Diff line number Diff line change
@@ -1,17 +1,6 @@
/**
* Storage module for S3 with common operations using MinIO.
*
* @see {@link https://min.io/docs/minio/linux/developers/javascript/API.html}
*
* @example
* ```ts
* import { getObject } from '@frytg/storage-s3'
*
* const object = await getObject(process.env.S3_BUCKET_NAME, 'path/to/object.json', { parseJson: true })
* console.log(object)
* ```
*
* @module
* Storage module for S3 with common operations using MinIO.
*/

// import packages
Expand Down Expand Up @@ -40,9 +29,9 @@ export const Client: ClientType = minioClient
* Retrieves an object from S3.
* @param {string} bucketName - The name of the bucket to retrieve the object from.
* @param {string} path - The path to the object in S3.
* @param {object} options - The options for the operation.
* @param {boolean} options.parseJson - Whether to parse the object as JSON. Defaults to `false`.
* @param {boolean} options.throwError - Whether to throw an error if the object does not exist. Defaults to `true`.
* @param {object} [options] - The options for the operation.
* @param {boolean} [options.parseJson] - Whether to parse the object as JSON. Defaults to `false`.
* @param {boolean} [options.throwError] - Whether to throw an error if the object does not exist. Defaults to `true`.
* @returns {Promise<Buffer | string | null>}
*
* @see https://min.io/docs/minio/linux/developers/javascript/API.html#getObject
Expand All @@ -52,7 +41,7 @@ export const Client: ClientType = minioClient
* import { getRequiredEnv } from '@frytg/check-required-env/get'
* import { getObject } from '@frytg/storage-s3'
*
* const object = await getObject(getRequiredEnv('S3_BUCKET_NAME'), 'path/to/object.json', { parseJson: true })
* const object = await getObject(getRequiredEnv('STORE_S3_BUCKET_NAME'), 'path/to/object.json', { parseJson: true })
* console.log(object)
* ```
*/
Expand Down Expand Up @@ -88,10 +77,9 @@ export const getObject = (

/**
* Uploads an object to S3.
* @param {string} bucketName - The name of the bucket to upload the object to.
* @param {string} path - The path to the object in S3.
* @param {Buffer | string} data - The data to upload. Can be a Buffer or a string. If JSON is passed, it will be stringified.
* @param {object} options - The options for the operation.
* @param {string} options.bucketName - The name of the bucket to upload the object to. Defaults to env `S3_BUCKET_NAME`.
* @returns {Promise<void>}
*
* @see https://min.io/docs/minio/linux/developers/javascript/API.html#putObject
Expand All @@ -101,15 +89,15 @@ export const getObject = (
* import { getRequiredEnv } from '@frytg/check-required-env/get'
* import { uploadObject } from '@frytg/storage-s3'
*
* await uploadObject(getRequiredEnv('S3_BUCKET_NAME'), 'path/to/object.json', { foo: 'bar' })
* await uploadObject(getRequiredEnv('STORE_S3_BUCKET_NAME'), 'path/to/object.json', { foo: 'bar' })
* ```
*
* @example Buffer
* ```ts
* import { getRequiredEnv } from '@frytg/check-required-env/get'
* import { uploadObject } from '@frytg/storage-s3'
*
* await uploadObject(getRequiredEnv('S3_BUCKET_NAME'), 'path/to/object.blob', Buffer.from('foo'))
* await uploadObject(getRequiredEnv('STORE_S3_BUCKET_NAME'), 'path/to/object.blob', Buffer.from('foo'))
* ```
*/
export const uploadObject = async (bucketName: string, path: string, data: Buffer | string): Promise<void> => {
Expand All @@ -125,9 +113,8 @@ export const uploadObject = async (bucketName: string, path: string, data: Buffe

/**
* Checks if an object exists in S3.
* @param {string} bucketName - The name of the bucket to check for the object.
* @param {string} path - The path to the object in S3.
* @param {object} options - The options for the operation.
* @param {string} options.bucketName - The name of the bucket to check for the object. Defaults to env `S3_BUCKET_NAME`.
* @returns {Promise<BucketItemStat | false>}
*
* @see https://min.io/docs/minio/linux/developers/javascript/API.html#statObject
Expand All @@ -137,7 +124,7 @@ export const uploadObject = async (bucketName: string, path: string, data: Buffe
* import { getRequiredEnv } from '@frytg/check-required-env/get'
* import { objectExists } from '@frytg/storage-s3'
*
* const exists = await objectExists(getRequiredEnv('S3_BUCKET_NAME'), 'path/to/object.json')
* const exists = await objectExists(getRequiredEnv('STORE_S3_BUCKET_NAME'), 'path/to/object.json')
* console.log(exists) // null if it doesn't exist, otherwise the object stat
* ```
*/
Expand All @@ -162,10 +149,9 @@ const readableStreamForListObjects = (stream: BucketStream<BucketItem>): Promise

/**
* Lists objects in S3.
* @param {string} bucketName - The name of the bucket to list the objects from.
* @param {string} prefix - The prefix to filter the objects by.
* @param {object} options - The options for the operation.
* @param {boolean} options.recursive - Whether to list recursively. Defaults to `false`.
* @param {string} options.bucketName - The name of the bucket to list the objects from. Defaults to env `S3_BUCKET_NAME`.
* @param {boolean} recursive - Whether to list recursively. Defaults to `false`.
* @returns {Promise<BucketItem[]>}
*
* @see https://min.io/docs/minio/linux/developers/javascript/API.html#listObjectsV2
Expand All @@ -175,7 +161,7 @@ const readableStreamForListObjects = (stream: BucketStream<BucketItem>): Promise
* import { getRequiredEnv } from '@frytg/check-required-env/get'
* import { listObjects } from '@frytg/storage-s3'
*
* const objects = await listObjects(getRequiredEnv('S3_BUCKET_NAME'), 'path/to/prefix')
* const objects = await listObjects(getRequiredEnv('STORE_S3_BUCKET_NAME'), 'path/to/prefix')
* console.log(objects)
* ```
*
Expand All @@ -184,7 +170,7 @@ const readableStreamForListObjects = (stream: BucketStream<BucketItem>): Promise
* import { getRequiredEnv } from '@frytg/check-required-env/get'
* import { listObjects } from '@frytg/storage-s3'
*
* const objects = await listObjects(getRequiredEnv('S3_BUCKET_NAME'), 'path/to/prefix', { recursive: true })
* const objects = await listObjects(getRequiredEnv('STORE_S3_BUCKET_NAME'), 'path/to/prefix', { recursive: true })
* console.log(objects)
* ```
*/
Expand Down

0 comments on commit 629a99b

Please sign in to comment.