🚀 Socket Launch Week Day 5:Introducing Repository Access Permissions and Custom Roles.Learn more
Sign In

@semantq/storage

Package Overview
Dependencies
Maintainers
1
Versions
1
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@semantq/storage

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

latest
npmnpm
Version
1.0.1
Version published
Weekly downloads
1
-83.33%
Maintainers
1
Weekly downloads
 
Created
Source

@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.

OptionTypeRequiredDescription
organizationIdstring/numberYesOrganization ID
modelNamestringYesModel name (e.g., ProjectFile, Budget)
recordIdstringYesRecord UUID
fieldKeystringYesField name (e.g., fileUrl)
originalNamestringNoOriginal filename
mimeTypestringNoFile 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

FAQs

Package last updated on 26 May 2026

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts