@cbnsndwch/zero-sources

Intro

Comprehensive guide to Zero Sources libraries and packages

Zero Sources provides a collection of TypeScript libraries and demo apps for building real-time change source implementations. Each library is designed to be composable, reusable, and type-safe.

Core Libraries

Watermark Storage

Demo Apps

Installation

All libraries are available via npm and can be installed with pnpm:

# Install a specific library
pnpm add @cbnsndwch/zero-source-mongodb

# Install multiple libraries
pnpm add @cbnsndwch/zero-source-mongodb @cbnsndwch/zero-watermark-zqlite

Library Organization

Libraries follow a consistent structure:

libs/[library-name]/
├── src/
│   ├── index.ts          # Public API exports
│   ├── types/            # TypeScript type definitions
│   ├── schemas/          # Zero schema definitions
│   └── utils/            # Utility functions
├── package.json
├── tsconfig.json
└── README.md

Choosing Libraries

For Change Sources

  • zero-source-mongodb: Stream MongoDB changes to Zero
  • zero-contracts: Common Zero protocol types
  • zero-watermark-zqlite or zero-watermark-nats-kv: Watermark storage

For NestJS Applications

  • zero-nest-mongoose: NestJS + Mongoose integration
  • zero-contracts: Shared types and contracts

For Demo Applications

  • zrocket-contracts: ZRocket demo schemas and types
  • synced-queries: Query utilities

Common Patterns

Basic Change Source

import { MongoDBChangeSource } from '@cbnsndwch/zero-source-mongodb';
import { ZQLiteWatermarkStorage } from '@cbnsndwch/zero-watermark-zqlite';
import { schema } from './schema';

const changeSource = new MongoDBChangeSource({
    schema,
    watermarkStorage: new ZQLiteWatermarkStorage(),
    mongoUri: process.env.MONGODB_URI
});

await changeSource.start();

Schema Definition

import { createTableSchema } from '@rocicorp/zero';

export const messageSchema = createTableSchema({
    tableName: 'message',
    columns: {
        id: { type: 'string' },
        content: { type: 'string' }
    },
    primaryKey: ['id']
});

TypeScript Support

All libraries provide full TypeScript support:

  • Type Definitions: Complete type definitions for all APIs
  • Generic Types: Leverage TypeScript generics for type safety
  • Type Inference: Automatic type inference from schemas
  • Strict Mode: Designed for TypeScript strict mode

Contributing

Want to contribute to a library?

  1. Fork the repository
  2. Create a feature branch
  3. Make your changes
  4. Add tests
  5. Submit a pull request

See CONTRIBUTING.md for details.

How was this page?