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

blossom-server-sdk

v0.7.2

Published

A collection of classes to for building blossom servers

Downloads

251

Readme

blossom-server-sdk

A collection of classes to for building blossom servers

Documentation

Metadata storage

all metadata storage classes implement the IBlobMetadataStore interface

interface IBlobMetadataStore {
  // blobs
  hasBlob(sha256: string): boolean | Promise<boolean>;
  getBlob(sha256: string): BlobMetadata | Promise<BlobMetadata>;
  addBlob(
    data: Omit<BlobMetadata, "url">,
  ): BlobMetadata | Promise<BlobMetadata>;
  removeBlob(sha256: string): boolean | Promise<boolean>;

  // blob owners
  hasOwner(sha256: string, pubkey: string): boolean | Promise<boolean>;
  addOwner(sha256: string, pubkey: string): boolean | Promise<boolean>;
  removeOwner(sha256: string, pubkey: string): boolean | Promise<boolean>;
  getOwnerBlobs(pubkey: string): BlobMetadata[] | Promise<BlobMetadata[]>;
}

SQLite Metadata store

The BlossomSQLite class can be used to store blob metadata in a sqlite database

import { BlossomSQLite } from "blossom-server-sdk/metadata/sqlite";

const metadataStore = new BlossomSQLite("./data/mysql.db");

await metadataStore.addBlob({
  sha256: "b1674191a88ec5cdd733e4240a81803105dc412d6c6708d53ab94fc248f4f553",
  size: 184929,
  type: "application/pdf",
  uploaded: Math.floor(Date.now() / 1000),
});

await metadataStore.addOwner(
  // blob hash
  "b1674191a88ec5cdd733e4240a81803105dc412d6c6708d53ab94fc248f4f553",
  // pubkey
  "266815e0c9210dfa324c6cba3573b14bee49da4209a9456f9484e5106cd408a5",
);

const blobs = await metadataStore.getOwnerBlobs(
  "266815e0c9210dfa324c6cba3573b14bee49da4209a9456f9484e5106cd408a5",
);

const orphaned = await metadataStore.getOrphanedBlobs();

for (let blob of orphaned) {
  await metadataStore.removeBlob(blob.sha256);
}

Blob Storage

all storage classes implement the IBlobStorage interface

interface IBlobStorage {
  setup(): Promise<void>;
  hasBlob(sha256: string): Promise<boolean>;
  writeBlob(sha256: string, stream: Readable, type?: string): Promise<void>;
  getBlobSize(sha256: string): number | Promise<number>;
  getBlobType(sha256: string): string | undefined | Promise<string | undefined>;
  readBlob(sha256: string): Promise<Readable>;
  removeBlob(sha256: string): Promise<void>;
}

Local Storage

A class that uses the built-in fs module in node to store blobs in the file system

import { LocalStorage } from "blossom-server-sdk/storage/local";
import https from "https";

const storage = new LocalStorage("./data");
await storage.setup();

const sha256 =
  "b1674191a88ec5cdd733e4240a81803105dc412d6c6708d53ab94fc248f4f553";

https.get(new URL(sha256, "https://cdn.satellite.earth"), async (res) => {
  const type = res.headers["content-type"];

  // write the blob to storage with the optional type
  await storage.writeBlob(sha256, res, type);
});

S3 Storage

A storage class that uses minio to store blobs in a s3 compatible API

import { S3Storage } from "blossom-server-sdk/storage/s3";
import https from "https";

const storage = new S3Storage("./data");
await storage.setup();

const sha256 =
  "b1674191a88ec5cdd733e4240a81803105dc412d6c6708d53ab94fc248f4f553";

https.get(new URL(sha256, "https://cdn.satellite.earth"), async (res) => {
  const type = res.headers["content-type"];

  // write the blob to s3 storage with the optional type
  await storage.writeBlob(sha256, res, type);
});