npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

unified-serverless-storage

v0.1.4

Published

This library interfaces with multiple cloud storages, optimized for serverless architecture and concurrent writes, ensuring data integrity.

Downloads

117

Readme

A Unified Interface for Cloud-Based Storage and Lock Management

unified-serverless-storage is a versatile TypeScript library designed to simplify interactions with cloud-based storage systems like AWS, GCP, and Azure. Its primary goal is to provide a standardized interface for reading, writing, and deleting data, along with robust lock management to ensure data integrity during concurrent operations. This library is especially useful for developers working with serverless architectures who need to interface with various cloud storage providers.

Installation

You can install it via NPM or YARN

npm install unified-serverless-storage
yarn add unified-serverless-storage

Key Features

Standardized Interfaces

  • IStorageManager: The foundational interface for all storage managers. It outlines the necessary methods for any storage management operation.
  • ILockingManager: Defines the basic structure for implementing locking mechanisms to prevent concurrent access issues.
  • ILockableStorageManager: Combines storage and locking functionalities to provide a cohesive management interface.

Extensible Design

  • Support for Additional Managers: The library's architecture is deliberately flexible, allowing for easy integration of new storage and lock managers as they become necessary. This design choice ensures that developers can swiftly adapt the library to accommodate evolving storage needs and technologies.
  • Cross-Cloud Service Compatibility: A key strength of unified-serverless-storage is its ability to maintain compatibility across various cloud platforms. This ensures that the library can serve as a universal interface for cloud storage operations, simplifying the development process for applications that span multiple cloud environments.

Implemented Classes

  • LocalFileStorageManager: Manages storage operations on the local file system, providing a reliable and easy-to-use interface for local storage handling.
  • S3StorageManager: A specialized storage manager designed to interact seamlessly with AWS S3 buckets, offering robust and scalable cloud storage solutions.
  • DynamoLockingManager: Implements lock management using AWS DynamoDB, ensuring safe and efficient handling of locks in distributed systems.
  • LockableStorageManager: An all-encompassing manager that integrates storage and locking functionalities, providing a unified interface for managing lockable storage resources.

Usage Example

const localStore = new LocalFileStorageManager('./root_storage_dir_of_choice');
const s3Store = new S3StorageManager(/* AWS S3 configuration */);
const dynamoLocking = new DynamoLockingManager(/* DynamoDB configuration */);

const localLockableManager = new LockableStorageManager({
  storageManager: localStore,
  lockingManager: dynamoLocking,
});

const s3LockableManager = new LockableStorageManager({
  storageManager: s3Store,
  lockingManager: dynamoLocking,
});

Utility Functions

  • AcquireLockError: A custom error type that is thrown when acquiring a lock fails, providing detailed error information and troubleshooting guidance.
  • waitForTime: A utility function that pauses execution for a specified amount of time, useful in implementing delays or timeouts in storage operations.
  • acquireLock: A critical utility that attempts to acquire a lock on a resource, ensuring that only one operation can proceed at a time, thus preventing race conditions and data corruption.

Future Enhancements

  • Plans to integrate more storage solutions like Azure and Google Cloud.
  • Open to contributions and feedback for further development.

Terraform

S3 bucket storage

resource "aws_s3_bucket" "my_bucket" {
  bucket = "my-unique-bucket-name" # Change to your unique bucket name
}

resource "aws_iam_policy" "my_bucket" {
  name        = "my-bucket-policy"
  description = "Policy for read/write access to the S3 bucket"

  policy = jsonencode({
    Version = "2012-10-17"
    Statement = [
      {
        Action = [
          "s3:GetObject",
          "s3:PutObject",
          "s3:DeleteObject"
        ],
        Effect = "Allow",
        Resource = [
          "${aws_s3_bucket.my_bucket.arn}/*" # Granting access to all objects in the bucket
        ]
      },
      {
        Action = [
          "s3:ListBucket"
        ],
        Effect = "Allow",
        Resource = [
          aws_s3_bucket.my_bucket.arn
        ]
      }
    ]
  })
}

DynamoDB locking manager

resource "aws_dynamodb_table" "locking_table" {
  name           = "lockingTable"
  billing_mode   = "PAY_PER_REQUEST"
  hash_key       = "id"
  attribute {
    name = "id"
    type = "S"  # 'S' denotes a string type
  }
  ttl {
    attribute_name = "expireAt"
    enabled        = true
  }
  tags = {
    Name        = "LockingTable"
    Environment = "Production"
  }
}

resource "aws_iam_policy" "dynamodb_locking_policy" {
  name        = "DynamoDBLockingPolicy"
  description = "IAM policy for accessing DynamoDB Locking Table"

  policy = jsonencode({
    Version = "2012-10-17",
    Statement = [
      {
        Effect = "Allow",
        Action = [
          "dynamodb:GetItem",
          "dynamodb:PutItem",
          "dynamodb:DeleteItem",
          "dynamodb:Query",
          "dynamodb:Scan",
          "dynamodb:DescribeTable"
        ],
        Resource = aws_dynamodb_table.locking_table.arn
      }
    ]
  })
}

Contributing and Feedback

We encourage contributions to expand the library's capabilities, such as adding new storage backends, enhancing locking strategies, and refining documentation. If you have questions, suggestions, or feedback, feel free to open an issue in the GitHub repository.

License

unified-serverless-storage is available under the MIT License. For more details, refer to the LICENSE.md file in the project repository.