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 🙏

© 2026 – Pkg Stats / Ryan Hefner

@semantq/storage

v1.0.1

Published

File storage module for semantqQL — the Node.js backend of the semantq framework.

Readme

@semantq/storage

File storage module for semantqQL — the Node.js backend of the semantq framework.

Organizes files by model record structure (e.g., product/1/images/) and provides a unified API across multiple storage providers.

Installation

npm install @semantq/storage

Quick Start

import { Storage } from '@semantq/storage';

// Upload a file (from multer, Buffer, or File object)
const result = await Storage.upload(fileBuffer, {
  organizationId: 1,
  modelName: 'ProjectFile',
  recordId: 'abc-123',
  fieldKey: 'fileUrl',
  originalName: 'document.pdf',
  mimeType: 'application/pdf'
});

// result: { storageKey, publicUrl, fileSize, fileHash, metadata }

// Get a public URL
const url = await Storage.getUrl(result.storageKey);

// Check if file exists
const exists = await Storage.exists(result.storageKey);

// Get file as buffer
const buffer = await Storage.getBuffer(result.storageKey);

// Delete file
await Storage.delete(result.storageKey);

API

Storage.upload(file, metadata)

Upload a file. Accepts a Buffer, multer file object, or browser File instance.

| Option | Type | Required | Description | |---|---|---|---| | organizationId | string/number | Yes | Organization ID | | modelName | string | Yes | Model name (e.g., ProjectFile, Budget) | | recordId | string | Yes | Record UUID | | fieldKey | string | Yes | Field name (e.g., fileUrl) | | originalName | string | No | Original filename | | mimeType | string | No | File MIME type |

Returns: { storageKey, publicUrl, fileSize, fileHash, metadata }

Storage.delete(storageKey)

Delete a file from storage. Returns boolean.

Storage.getUrl(storageKey)

Get the public URL for a file. Returns string.

Storage.getBuffer(storageKey)

Download file as a Buffer. Returns Buffer.

Storage.exists(storageKey)

Check if file exists in storage. Returns boolean.

Storage Key Structure

Files are stored with a structured path pattern:

{organizationId}/{modelName}/{recordId}/{fieldKey}/{filename}

Example:

1/projectfile/abc-123/fileurl/document_1711234567890_a1b2c3.pdf

Providers

Local (Default)

Stores files on the local filesystem. Configure in server.config.js:

storage: {
  activeProvider: 'local',
  local: {
    uploadDir: './uploads',
    baseUrl: '/uploads'
  }
}

UploadThing (Planned)

Cloud storage via UploadThing. Falls back to local provider when no token is configured.

S3 (Coming Soon)

AWS S3 provider.

Cloudinary (Coming Soon)

Cloudinary provider.

Configuration

All storage configuration lives in your SemantQQL server.config.js under the storage key:

export default {
  storage: {
    activeProvider: 'local',    // 'local' | 'uploadthing' | 's3' | 'cloudinary'
    local: {
      uploadDir: './uploads',
      baseUrl: '/uploads'
    },
    uploadthing: {
      token: process.env.UPLOADTHING_TOKEN,
      appId: process.env.UPLOADTHING_APP_ID
    }
    // s3: { ... }        (coming soon)
    // cloudinary: { ... } (coming soon)
  }
}

Usage in Services

import { Storage } from '@semantq/storage';

class ProjectFileService {
  async uploadFile(req) {
    const file = req.file;
    const userData = req.userData;

    const result = await Storage.upload(file, {
      organizationId: userData.organizationId,
      modelName: 'ProjectFile',
      recordId: req.body.projectId,
      fieldKey: 'fileUrl',
      originalName: file.originalname,
      mimeType: file.mimetype
    });

    // Save result.storageKey and result.publicUrl to your database
    await ProjectFileModel.create({
      filename: file.originalname,
      fileUrl: result.publicUrl,
      fileKey: result.storageKey,
      // ... other fields
    });
  }

  async deleteFile(fileId) {
    const file = await ProjectFileModel.findById(fileId);
    if (file?.fileKey) {
      await Storage.delete(file.fileKey);
    }
    await ProjectFileModel.delete(fileId);
  }
}

Extending

To add a new provider, extend BaseStorageProvider:

import { BaseStorageProvider } from '@semantq/storage';

class MyProvider extends BaseStorageProvider {
  constructor(config) {
    super(config);
    this.name = 'myprovider';
  }

  async upload(fileBuffer, options) { /* ... */ }
  async delete(storageKey) { /* ... */ }
  async getUrl(storageKey) { /* ... */ }
  async exists(storageKey) { /* ... */ }
  async getBuffer(storageKey) { /* ... */ }
}

License

MIT