0.2.0 • Published 7 months ago

@bastards/bcs-data-localfs v0.2.0

Weekly downloads
-
License
MIT
Repository
-
Last release
7 months ago

@bastards/bcs-data-localfs šŸ’¾

A local filesystem implementation of the BCS data layer that provides simple and efficient content storage using JSON files in your project directory.

Features 🌟

  • Simple File Storage šŸ“

    • Store content as JSON files
    • Automatic file organization by schema
    • Easy version control integration
    • Direct file system access
  • Type-Safe Content šŸ›”ļø

    • Full TypeScript support
    • Schema-based type generation
    • Runtime type validation
    • Strongly typed content access
  • Developer Friendly šŸ’»

    • Zero configuration needed
    • Instant setup
    • Easy content inspection
    • Human-readable storage format
  • Media Management šŸ–¼ļø

    • Local media file storage
    • Automatic file organization
    • Public URL generation
    • Media metadata handling

Installation šŸ“¦

npm install @bastards/bcs-data-localfs
# or
pnpm add @bastards/bcs-data-localfs
# or
yarn add @bastards/bcs-data-localfs

Usage šŸš€

  1. Configure the content endpoints in your bcs.config.ts:
import { defineConfig } from '@bastards/bcs';

export default defineConfig({
  admin: {
    // ... other admin config
    data: {
      content: '/api/bcs/content',  // Content endpoint
      media: '/api/bcs/media'       // Media endpoint
    }
  },
  build: {
    adminOutputDir: './static/admin',
    typesOutputDir: './src/lib/bcs-types'  // Where to generate TypeScript types
  }
});
  1. Set up the content API endpoints in your application (example in SvelteKit):
// src/routes/api/bcs/content/+server.ts
import { localFs } from '@bastards/bcs-data-localfs';

export const GET = async ({ url }) => {
  const storage = localFs();
  return storage.handleContentRequest(url);
};

export const POST = async ({ request }) => {
  const storage = localFs();
  return storage.handleContentRequest(request);
};

// src/routes/api/bcs/media/+server.ts
import { localFs } from '@bastards/bcs-data-localfs';

export const GET = async ({ url }) => {
  const storage = localFs();
  return storage.handleMediaRequest(url);
};

export const POST = async ({ request }) => {
  const storage = localFs();
  return storage.handleMediaRequest(request);
};
  1. Your content will be automatically stored in:
    • ./content/ - JSON files for each schema
    • ./static/media/ - Uploaded media files

Directory Structure šŸ“‚

your-project/
ā”œā”€ā”€ content/
│   ā”œā”€ā”€ Main.json
│   └── General.json
ā”œā”€ā”€ static/
│   ā”œā”€ā”€ media/
│   │   └── uploads/
│   └── admin/
└── src/
    └── lib/
        └── bcs-types/
            └── schema.d.ts

API Reference šŸ“š

The package exports the following:

function localFs(options?: {
  contentDir?: string;     // Override default content directory
  mediaDir?: string;       // Override default media directory
}): StorageHandler;

interface StorageHandler {
  handleContentRequest(urlOrRequest: URL | Request): Promise<Response>;
  handleMediaRequest(urlOrRequest: URL | Request): Promise<Response>;
}

Content Format šŸ“„

Content is stored as JSON files, one per schema:

{
  "welcomeSection": {
    "title": "Welcome to BCS",
    "emoji": "šŸš€",
    "subtitle": "A modern CMS for modern web development"
  }
}

Contributing šŸ¤

We welcome contributions! Please see our Contributing Guide for details.

License šŸ“„

MIT - see the main project repository for details.

Learn More šŸ“š

For more information about BCS and its features, check out:

0.2.0

7 months ago