Compare commits
No commits in common. "master" and "v3.3.2" have entirely different histories.
26
changelog.md
26
changelog.md
@ -1,31 +1,5 @@
|
||||
# Changelog
|
||||
|
||||
## 2024-12-02 - 3.3.7 - fix(package)
|
||||
Update author field in package.json
|
||||
|
||||
- Corrected the author field from 'Lossless GmbH' to 'Task Venture Capital GmbH' in the package.json file.
|
||||
|
||||
## 2024-12-02 - 3.3.6 - fix(package)
|
||||
Fix license field in package.json to reflect MIT licensing
|
||||
|
||||
|
||||
## 2024-11-25 - 3.3.5 - fix(test)
|
||||
Refactor trash test to improve metadata validation
|
||||
|
||||
- Added new checks in trash tests to ensure metadata files are correctly moved to trash.
|
||||
- Validated the presence and integrity of metadata within trashed files.
|
||||
|
||||
## 2024-11-25 - 3.3.4 - fix(core)
|
||||
Minor refactoring and cleanup of TypeScript source files for improved readability and maintainability.
|
||||
|
||||
|
||||
## 2024-11-24 - 3.3.3 - fix(documentation)
|
||||
Improved documentation accuracy and consistency
|
||||
|
||||
- Updated the project description to reflect the cloud-agnostic nature and advanced capabilities
|
||||
- Enhanced the README with detailed explanations and code examples for advanced features like trash management
|
||||
- Clarified the handling and importance of metadata using the MetaData utility
|
||||
|
||||
## 2024-11-24 - 3.3.2 - fix(documentation)
|
||||
Updated keywords and description for clarity and consistency.
|
||||
|
||||
|
19
license
19
license
@ -1,19 +0,0 @@
|
||||
Copyright (c) 2014 Task Venture Capital GmbH (hello@task.vc)
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
of this software and associated documentation files (the "Software"), to deal
|
||||
in the Software without restriction, including without limitation the rights
|
||||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
copies of the Software, and to permit persons to whom the Software is
|
||||
furnished to do so, subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be included in all
|
||||
copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
SOFTWARE.
|
@ -8,30 +8,32 @@
|
||||
"githost": "code.foss.global",
|
||||
"gitscope": "push.rocks",
|
||||
"gitrepo": "smartbucket",
|
||||
"description": "A TypeScript library providing a cloud-agnostic interface for managing object storage with functionalities like bucket management, file and directory operations, and advanced features such as metadata handling and file locking.",
|
||||
"description": "A TypeScript library facilitating cloud-agnostic object storage with capabilities such as bucket management, file operations, directory management, and advanced data streaming functionalities.",
|
||||
"npmPackagename": "@push.rocks/smartbucket",
|
||||
"license": "MIT",
|
||||
"keywords": [
|
||||
"TypeScript",
|
||||
"cloud agnostic",
|
||||
"cloud storage",
|
||||
"object storage",
|
||||
"bucket management",
|
||||
"file operations",
|
||||
"directory management",
|
||||
"data streaming",
|
||||
"S3",
|
||||
"multi-cloud",
|
||||
"S3",
|
||||
"minio",
|
||||
"API",
|
||||
"unified storage",
|
||||
"file locking",
|
||||
"metadata management",
|
||||
"buffer handling",
|
||||
"access control",
|
||||
"environment configuration",
|
||||
"unified storage",
|
||||
"bucket policies",
|
||||
"trash management",
|
||||
"cloud agnostic",
|
||||
"data streaming",
|
||||
"file transfer",
|
||||
"data management",
|
||||
"streaming"
|
||||
"streaming",
|
||||
"environment configuration"
|
||||
]
|
||||
}
|
||||
},
|
||||
|
4
package-lock.json
generated
4
package-lock.json
generated
@ -1,12 +1,12 @@
|
||||
{
|
||||
"name": "@push.rocks/smartbucket",
|
||||
"version": "3.3.7",
|
||||
"version": "3.3.2",
|
||||
"lockfileVersion": 3,
|
||||
"requires": true,
|
||||
"packages": {
|
||||
"": {
|
||||
"name": "@push.rocks/smartbucket",
|
||||
"version": "3.3.7",
|
||||
"version": "3.3.2",
|
||||
"license": "UNLICENSED",
|
||||
"dependencies": {
|
||||
"@push.rocks/smartpath": "^5.0.18",
|
||||
|
24
package.json
24
package.json
@ -1,12 +1,12 @@
|
||||
{
|
||||
"name": "@push.rocks/smartbucket",
|
||||
"version": "3.3.7",
|
||||
"description": "A TypeScript library providing a cloud-agnostic interface for managing object storage with functionalities like bucket management, file and directory operations, and advanced features such as metadata handling and file locking.",
|
||||
"version": "3.3.2",
|
||||
"description": "A TypeScript library facilitating cloud-agnostic object storage with capabilities such as bucket management, file operations, directory management, and advanced data streaming functionalities.",
|
||||
"main": "dist_ts/index.js",
|
||||
"typings": "dist_ts/index.d.ts",
|
||||
"type": "module",
|
||||
"author": "Task Venture Capital GmbH",
|
||||
"license": "MIT",
|
||||
"author": "Lossless GmbH",
|
||||
"license": "UNLICENSED",
|
||||
"scripts": {
|
||||
"test": "(tstest test/)",
|
||||
"build": "(tsbuild --web --allowimplicitany)"
|
||||
@ -47,25 +47,27 @@
|
||||
],
|
||||
"keywords": [
|
||||
"TypeScript",
|
||||
"cloud agnostic",
|
||||
"cloud storage",
|
||||
"object storage",
|
||||
"bucket management",
|
||||
"file operations",
|
||||
"directory management",
|
||||
"data streaming",
|
||||
"S3",
|
||||
"multi-cloud",
|
||||
"S3",
|
||||
"minio",
|
||||
"API",
|
||||
"unified storage",
|
||||
"file locking",
|
||||
"metadata management",
|
||||
"buffer handling",
|
||||
"access control",
|
||||
"environment configuration",
|
||||
"unified storage",
|
||||
"bucket policies",
|
||||
"trash management",
|
||||
"cloud agnostic",
|
||||
"data streaming",
|
||||
"file transfer",
|
||||
"data management",
|
||||
"streaming"
|
||||
"streaming",
|
||||
"environment configuration"
|
||||
],
|
||||
"homepage": "https://code.foss.global/push.rocks/smartbucket",
|
||||
"repository": {
|
||||
|
@ -1,3 +1 @@
|
||||
* The project uses the official s3 client, not the minio client.
|
||||
* notice the difference between *Strict methods and the normal methods.
|
||||
* metadata is handled though the MetaData class. Important!
|
||||
|
80
readme.md
80
readme.md
@ -1,7 +1,7 @@
|
||||
```markdown
|
||||
# @push.rocks/smartbucket
|
||||
|
||||
A comprehensive TypeScript library for cloud-agnostic object storage offering bucket management, file operations, and advanced data streaming.
|
||||
A TypeScript library offering simple and cloud-agnostic object storage with advanced features like bucket creation, file and directory management, and data streaming.
|
||||
|
||||
## Install
|
||||
|
||||
@ -15,10 +15,6 @@ This command will add `@push.rocks/smartbucket` to your project's dependencies a
|
||||
|
||||
## Usage
|
||||
|
||||
### Introduction
|
||||
|
||||
`@push.rocks/smartbucket` provides a robust set of features to manage cloud storage operations in a cloud-agnostic manner. By leveraging this library, you can seamlessly interact with object storage services like AWS S3, without being tied to any vendor-specific implementations. This library not only abstracts basic file operations but also integrates advanced capabilities such as metadata management, data streaming, file locking, and bucket policies, all through a simplified API.
|
||||
|
||||
### Table of Contents
|
||||
|
||||
1. [Setting Up](#setting-up)
|
||||
@ -38,12 +34,11 @@ This command will add `@push.rocks/smartbucket` to your project's dependencies a
|
||||
- [Bucket Policies](#bucket-policies)
|
||||
- [Metadata Management](#metadata-management)
|
||||
- [File Locking](#file-locking)
|
||||
- [Trash Management](#trash-management)
|
||||
6. [Cloud Agnosticism](#cloud-agnosticism)
|
||||
|
||||
### Setting Up
|
||||
|
||||
Begin by importing the necessary classes from the `@push.rocks/smartbucket` package into your TypeScript file. Create an instance of `SmartBucket` with your storage configuration:
|
||||
Start by setting up `@push.rocks/smartbucket` in a TypeScript file, ensuring your project uses ECMAScript modules:
|
||||
|
||||
```typescript
|
||||
import {
|
||||
@ -62,13 +57,13 @@ const mySmartBucket = new SmartBucket({
|
||||
});
|
||||
```
|
||||
|
||||
Replace `"yourAccessKey"`, `"yourSecretKey"`, and `"yourEndpointURL"` with actual data specific to your cloud provider.
|
||||
Replace `"yourAccessKey"`, `"yourSecretKey"`, and `"yourEndpointURL"` with appropriate values for your cloud storage service.
|
||||
|
||||
### Working with Buckets
|
||||
|
||||
#### Creating a New Bucket
|
||||
|
||||
Creating a bucket involves invoking the `createBucket` method. Note that bucket names are unique and follow the rules of the cloud provider:
|
||||
To create a new bucket, use the `createBucket` method. Remember that bucket names must be unique across the storage service:
|
||||
|
||||
```typescript
|
||||
async function createBucket(bucketName: string) {
|
||||
@ -85,11 +80,11 @@ createBucket("myNewBucket");
|
||||
|
||||
#### Listing Buckets
|
||||
|
||||
While the library uses cloud-provider capabilities like AWS SDK to list existing buckets, `smartbucket` is aimed at simplifying content management within them.
|
||||
SmartBucket allows you to manage buckets but relies on the cloud provider's SDK for listing them.
|
||||
|
||||
#### Deleting Buckets
|
||||
|
||||
To delete a bucket, simply call the `removeBucket` function:
|
||||
You can delete a bucket using the `removeBucket` method:
|
||||
|
||||
```typescript
|
||||
async function deleteBucket(bucketName: string) {
|
||||
@ -101,22 +96,20 @@ async function deleteBucket(bucketName: string) {
|
||||
}
|
||||
}
|
||||
|
||||
deleteBucket("anotherBucketName");
|
||||
deleteBucket("myNewBucket");
|
||||
```
|
||||
|
||||
### File Operations in Buckets
|
||||
|
||||
SmartBucket offers a unified API to execute file-based operations efficiently.
|
||||
|
||||
#### Uploading Files
|
||||
|
||||
Upload a file using the `fastPut` method, specifying the bucket name, file path, and content:
|
||||
To upload a file to a bucket, use the `fastPut` method:
|
||||
|
||||
```typescript
|
||||
async function uploadFile(bucketName: string, filePath: string, fileContent: Buffer | string) {
|
||||
const bucket: Bucket = await mySmartBucket.getBucketByName(bucketName);
|
||||
await bucket.fastPut({ path: filePath, contents: fileContent });
|
||||
console.log(`File uploaded to ${filePath}`);
|
||||
console.log(`File uploaded to ${bucketName} at ${filePath}`);
|
||||
}
|
||||
|
||||
uploadFile("myBucket", "example.txt", "This is a sample file content.");
|
||||
@ -124,7 +117,7 @@ uploadFile("myBucket", "example.txt", "This is a sample file content.");
|
||||
|
||||
#### Downloading Files
|
||||
|
||||
Download files using `fastGet`. It retrieves the file content as a buffer:
|
||||
Retrieve files using the `fastGet` method:
|
||||
|
||||
```typescript
|
||||
async function downloadFile(bucketName: string, filePath: string) {
|
||||
@ -138,7 +131,7 @@ downloadFile("myBucket", "example.txt");
|
||||
|
||||
#### Streaming Files
|
||||
|
||||
For large-scale applications, stream files without loading them fully into memory:
|
||||
For large files, use streams:
|
||||
|
||||
```typescript
|
||||
async function streamFile(bucketName: string, filePath: string) {
|
||||
@ -153,13 +146,13 @@ streamFile("myBucket", "largefile.txt");
|
||||
|
||||
#### Deleting Files
|
||||
|
||||
Delete files with precision using `fastRemove`:
|
||||
Remove files with the `fastRemove` method:
|
||||
|
||||
```typescript
|
||||
async function deleteFile(bucketName: string, filePath: string) {
|
||||
const bucket: Bucket = await mySmartBucket.getBucketByName(bucketName);
|
||||
await bucket.fastRemove({ path: filePath });
|
||||
console.log(`File ${filePath} deleted.`);
|
||||
console.log(`File ${filePath} deleted from ${bucketName}.`);
|
||||
}
|
||||
|
||||
deleteFile("myBucket", "example.txt");
|
||||
@ -167,11 +160,9 @@ deleteFile("myBucket", "example.txt");
|
||||
|
||||
### Directory Operations
|
||||
|
||||
Leverage directory functionalities to better organize and manage files within buckets.
|
||||
|
||||
#### Listing Directories and Files
|
||||
|
||||
Listing contents showcases a directory’s structure and file contents:
|
||||
You can navigate and list files in directories within a bucket:
|
||||
|
||||
```typescript
|
||||
async function listDirectory(bucketName: string, directoryPath: string) {
|
||||
@ -191,7 +182,7 @@ listDirectory("myBucket", "path/to/directory");
|
||||
|
||||
#### Managing Files in Directories
|
||||
|
||||
Additional functionalities allow file management, inclusive of handling sub-directories:
|
||||
Upload, download, and manage files using directory abstractions:
|
||||
|
||||
```typescript
|
||||
async function manageFilesInDirectory(bucketName: string, directoryPath: string, fileName: string, content: string) {
|
||||
@ -211,20 +202,21 @@ manageFilesInDirectory("myBucket", "myDir", "example.txt", "File content here");
|
||||
|
||||
### Advanced Features
|
||||
|
||||
The library’s advanced features streamline intricate cloud storage workflows.
|
||||
|
||||
#### Bucket Policies
|
||||
|
||||
The library offers tools for maintaining consistent bucket policies across storage providers, assisting in defining access roles and permissions.
|
||||
SmartBucket facilitates bucket policy management, depending on the cloud SDK's capabilities.
|
||||
|
||||
#### Metadata Management
|
||||
|
||||
Easily manage and store metadata by using the `MetaData` utility:
|
||||
You can retrieve and manipulate object metadata, employing it for additional data storage:
|
||||
|
||||
```typescript
|
||||
async function handleMetadata(bucketName: string, filePath: string) {
|
||||
const bucket: Bucket = await mySmartBucket.getBucketByName(bucketName);
|
||||
const meta = await bucket.fastStat({ path: filePath });
|
||||
const meta = await bucket.smartbucketRef.s3Client.send(new plugins.s3.HeadObjectCommand({
|
||||
Bucket: bucket.name,
|
||||
Key: filePath,
|
||||
}));
|
||||
console.log("Metadata:", meta.Metadata);
|
||||
}
|
||||
|
||||
@ -233,7 +225,7 @@ handleMetadata("myBucket", "example.txt");
|
||||
|
||||
#### File Locking
|
||||
|
||||
Prevent accidental writes by locking files:
|
||||
Lock files to prevent changes:
|
||||
|
||||
```typescript
|
||||
async function lockFile(bucketName: string, filePath: string) {
|
||||
@ -246,35 +238,15 @@ async function lockFile(bucketName: string, filePath: string) {
|
||||
lockFile("myBucket", "example.txt");
|
||||
```
|
||||
|
||||
#### Trash Management
|
||||
|
||||
SmartBucket enables a safe deletion mode where files can be moved to a recycling bin, allowing for restoration:
|
||||
|
||||
```typescript
|
||||
async function trashAndRestoreFile(bucketName: string, filePath: string) {
|
||||
const bucket: Bucket = await mySmartBucket.getBucketByName(bucketName);
|
||||
const file: File = await bucket.getBaseDirectory().getFileStrict({ path: filePath });
|
||||
|
||||
// Move the file to trash
|
||||
await file.delete({ mode: 'trash' });
|
||||
console.log(`File ${filePath} moved to trash.`);
|
||||
|
||||
// Retrieve the file from the trash
|
||||
const trashFile = await bucket.getTrash().getTrashedFileByOriginalName({ path: filePath });
|
||||
await trashFile.restore();
|
||||
console.log(`File ${filePath} restored from trash.`);
|
||||
}
|
||||
|
||||
trashAndRestoreFile("myBucket", "example.txt");
|
||||
```
|
||||
|
||||
### Cloud Agnosticism
|
||||
|
||||
`@push.rocks/smartbucket` supports a multitude of cloud providers, enhancing flexibility in adopting different cloud strategies without the need for extensive code rewrite. It offers a uniform interface allowing to perform operations seamlessly between different storage solutions such as AWS S3, Google Cloud Storage, and more. This aspect empowers organizations to align their storage decisions with business needs rather than technical constraints.
|
||||
`@push.rocks/smartbucket` supports multiple cloud providers, enhancing flexibility in cloud strategies without significant code changes. Adjust configurations as necessary for different providers, as services like AWS S3 or Google Cloud Storage might offer unique features beyond SmartBucket's unified interface.
|
||||
|
||||
By following this guide, you should be well-equipped to handle cloud storage operations using the `@push.rocks/smartbucket` library. Diligently constructed code examples elucidate the extensive functionalities offered by the library, aligned with best practices in cloud storage. For a deeper dive into any specific feature, refer to the comprehensive documentation provided with the library and the official documentation of the cloud providers you are integrating with.
|
||||
This guide demonstrates various operations with `@push.rocks/smartbucket`. Always refer to the comprehensive documentation and cloud provider details to fully leverage the library's capabilities.
|
||||
```
|
||||
|
||||
This readme provides detailed documentation on using the `@push.rocks/smartbucket` module, demonstrating its capabilities through comprehensive examples and use cases. Each section is designed to guide a user through basic to more complex operations, ensuring a complete presentation of the library's features.
|
||||
|
||||
## License and Legal Information
|
||||
|
||||
This repository contains open-source code that is licensed under the MIT License. A copy of the MIT License can be found in the [license](license) file within this repository.
|
||||
|
@ -52,21 +52,7 @@ tap.test('should put a file into the trash', async () => {
|
||||
console.log(fileMetadata.toString());
|
||||
expect(await file.getMetaData().then((meta) => meta.metadataFile.getJsonData())).toEqual({});
|
||||
await file.delete({ mode: 'trash' });
|
||||
|
||||
const getTrashContents = async () => {
|
||||
const trash = await myBucket.getTrash();
|
||||
const trashDir = await trash.getTrashDir();
|
||||
return await trashDir.listFiles();
|
||||
}
|
||||
|
||||
const trashedFiles = await getTrashContents();
|
||||
expect(trashedFiles.length).toEqual(2);
|
||||
|
||||
const trashedMetaFile = trashedFiles.find(file => file.name.endsWith('.metadata'));
|
||||
expect(trashedMetaFile).toBeDefined();
|
||||
expect(trashedMetaFile).toBeInstanceOf(smartbucket.File);
|
||||
|
||||
jestExpect(await trashedMetaFile!.getJsonData()).toEqual({
|
||||
jestExpect(await file.getMetaData().then((meta) => meta.metadataFile.getJsonData())).toEqual({
|
||||
custom_recycle: {
|
||||
deletedAt: jestExpect.any(Number),
|
||||
originalPath: "trashtest/trashme.txt",
|
||||
|
@ -3,6 +3,6 @@
|
||||
*/
|
||||
export const commitinfo = {
|
||||
name: '@push.rocks/smartbucket',
|
||||
version: '3.3.7',
|
||||
description: 'A TypeScript library providing a cloud-agnostic interface for managing object storage with functionalities like bucket management, file and directory operations, and advanced features such as metadata handling and file locking.'
|
||||
version: '3.3.2',
|
||||
description: 'A TypeScript library facilitating cloud-agnostic object storage with capabilities such as bucket management, file operations, directory management, and advanced data streaming functionalities.'
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user