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

@fjell/lib-gcs

v4.4.38

Published

Google Cloud Storage Library for Fjell

Readme

@fjell/lib-gcs

Google Cloud Storage persistence library for the Fjell framework.

Overview

@fjell/lib-gcs is a Fjell persistence library that stores Items as JSON files in Google Cloud Storage buckets. It implements the full Fjell Operations interface with support for primary items, contained items, custom finders, actions, facets, and file attachments.

✨ Features

  • Full Operations Interface - All CRUD operations, queries, finders, actions, and facets
  • Primary & Contained Items - Support for hierarchical data structures (1-5 levels deep)
  • File Attachments 🆕 - Store binary files (audio, video, images) alongside item metadata
  • Type-Safe - Full TypeScript support with comprehensive type inference
  • Custom Business Logic - Define finders, actions, and facets for domain-specific operations
  • Hybrid Mode - Use with lib-firestore for metadata + GCS for files
  • Query Safety - Built-in limits to prevent expensive operations on large datasets
  • Key Sharding - Support for massive datasets (billions of objects)
  • Integration Ready - Works seamlessly with the Fjell ecosystem

📦 Installation

npm install @fjell/lib-gcs @google-cloud/storage

🚀 Quick Start

import { createPrimaryGCSLibrary } from '@fjell/lib-gcs';
import { Storage } from '@google-cloud/storage';
import { Item } from '@fjell/core';

interface User extends Item<'user'> {
  name: string;
  email: string;
}

// Initialize GCS
const storage = new Storage({
  projectId: 'my-project',
  keyFilename: '/path/to/credentials.json'
});

// Create library
const userLib = createPrimaryGCSLibrary<User, 'user'>(
  'user',           // Key type
  'users',          // Directory name in bucket
  'my-app-bucket',  // Bucket name
  storage
);

// Create a user
const user = await userLib.operations.create({
  name: 'Alice',
  email: '[email protected]'
});

// Get user by key
const retrieved = await userLib.operations.get({
  kt: 'user',
  pk: user.pk
});

// Update user
const updated = await userLib.operations.update(
  { kt: 'user', pk: user.pk },
  { name: 'Alice Smith' }
);

// List all users
const allUsers = await userLib.operations.all();

// Remove user
await userLib.operations.remove({ kt: 'user', pk: user.pk });

📚 Documentation

📖 Examples

See the examples/ directory for complete, runnable examples:

⚠️ Important Limitations

GCS is Object Storage, NOT a Database:

  • No server-side querying or filtering
  • Query operations (all(), one(), finders) download and filter in-memory
  • NOT suitable for large datasets or complex queries

Best Use Cases:

  • ✅ Small to medium datasets (<1000 items per type)
  • ✅ File storage with key-based retrieval
  • ✅ Items with large file attachments (audio, video, documents)
  • ✅ Prototyping and development
  • ✅ Hybrid architectures (Firestore for metadata + GCS for files)

For Large Datasets:

  • Use @fjell/lib-firestore for native query support
  • Enable key sharding for better performance
  • Disable query operations (querySafety.disableQueryOperations = true)
  • Consider hybrid architecture with external indexing

🎯 Key Concepts

Storage Structure

Items are stored as JSON files with paths based on their keys:

Primary Item:
  gs://my-bucket/user/alice-123.json

Contained Item (1 level):
  gs://my-bucket/post/post-456/comment/comment-789.json

Contained Item (2 levels):
  gs://my-bucket/user/u-1/post/p-1/comment/c-1/reply/r-1.json

File Attachments

Items can have associated binary files:

Item JSON:
  gs://my-bucket/recording/rec-123.json

File Attachments:
  gs://my-bucket/recording/rec-123/_files/master/0.wav
  gs://my-bucket/recording/rec-123/_files/final/output.mp3
  gs://my-bucket/recording/rec-123/_files/thumbnail/cover.jpg

🔧 Configuration Options

interface Options {
  bucketName: string;
  basePath?: string;                    // Optional prefix for all paths
  mode?: 'full' | 'files-only';        // Full storage or files-only hybrid
  useJsonExtension?: boolean;           // Add .json to files (default: true)
  
  keySharding?: {                       // For massive datasets
    enabled?: boolean;
    levels?: number;                    // Default: 2
    charsPerLevel?: number;             // Default: 1
  };
  
  querySafety?: {                       // Prevent expensive operations
    maxScanFiles?: number;              // Default: 1000
    warnThreshold?: number;             // Default: 100
    disableQueryOperations?: boolean;   // Default: false
    downloadConcurrency?: number;       // Default: 10
  };
  
  files?: {                             // File attachment config
    directory?: string;                 // Default: '_files'
    maxFileSize?: number;               // No limit by default
    allowedContentTypes?: string[];     // All allowed by default
    includeMetadataInItem?: boolean;    // Default: true
    computeChecksums?: boolean;         // Default: true
  };
}

🤝 Contributing

This library is part of the Fjell project. See the main repository for contribution guidelines.

📄 License

Apache-2.0

🔗 Related Libraries

📊 Status

Version: 4.4.9-dev.0
Status: Development/Alpha
Test Coverage: 95.88%
Tests: 301 passing