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

@mu-ts/s3

v1.3.0

Published

Simple functional wrapper around S3 SDK to make most S3 interactions a single function call.

Downloads

318

Readme

Objective

Nice sugarry layer over top of S3 to make utilizing it psuedo database-like a bit easier. Uses @aws-sdk library which is more moduarlized so your deploy sizes should be smaller.

Class Decoration

In orderto do all the neat behaviors around an objet, we need a class to associate the configurations with.

@bucket(process.env.BUCKET_NAME)
class User {
  @id
  public id: string;

  public name: string;
}

See the @mu-ts/serialization library for more control on how the object is serialized.

Behaviors

These are the commands you can use for interacting with an S3 bucket on a decorated object.

putObject(object, Class?)

You can exclude the class if the object being persisted was created from a class.

import { putObject } from '@mu-ts/s3';

let user: User = new User();
user = await putObject(user);

If you created your object dreclty in JSON you will need to define the class used to persist.

import { putObject } from '@mu-ts/s3';

let user: User = { ... };
user = await putObject(user, User);

getObject(id, Class, version?)

Load an object from S3 as an object.

import { getObject } from '@mu-ts/s3';

const user: User | undefined = await getObject(user, User);

If you want to return a specific version, you can specify that as well.

import { getObject } from '@mu-ts/s3';

const versionId: string = '...';
const user: User | undefined = await getObject(user, User, versionId);

deleteObject(id, Class, version?)

Delete an object from S3. If a specific version is deleted (versioning enabled on bucket), then it is returned, undefined is returned otherwise.

import { deleteObject } from '@mu-ts/s3';

const versionId: string | undefined = await deleteObject(user, User);

If you want to delete a specific version, you can specify that as well.

import { getObject } from '@mu-ts/s3';

const versionId: string = '...';
const user: User | undefined = await deleteObject(user, User, versionId);

headObject(id, Class, version?)

Load the metadata for an object, or get undefined if nothing is found.

import { headObject } from '@mu-ts/s3';

const metadata: Record<string, string> | undefined = await headObject(user, User);

Load the metadata for an object at a specific version, or get undefined if nothing is found.

import { getObject } from '@mu-ts/s3';

const versionId: string = '...';
const metadata: Record<string, string> | undefined = await headObject(user, User, versionId);

existsObject(id, Class, version?)

Get a boolean value for if an object exists. Uses headObject under the covers since its lighter weight than loading the whole object.

import { headObject } from '@mu-ts/s3';

const exists: boolean = await existsObject(user, User);

Load the metadata for an object at a specific version, or get undefined if nothing is found.

import { getObject } from '@mu-ts/s3';

const versionId: string = '...';
const exists: boolean = await existsObject(user, User, versionId);

listObjects(Class, prefix?, size?, continuationToken?)

Return a list of object metadata (key, etag, size, etc) for a bucket.

import { listObjects, Objects, ObjectKey } from '@mu-ts/s3';

const pageSize: number = 100;
const results: Objects = await listObjects(User, undefined, pageSize);

/**
 * Continuation tokens are returned so pagination can continue.
 */
const continuationToken: string = results.getContinuationToken();
const results: ObjectKey[] = results.getResults();

const nextResults: Objects = await listObjects(User, undefined, pageSize, continuationToken);