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 🙏

© 2024 – Pkg Stats / Ryan Hefner

marsdb-sync-server

v0.2.0

Published

MarsDB DDP server for wotking with MarsDB Cleint (or with Meteor)

Downloads

9

Readme

MarsDB DDP Server

Build Status npm version Coverage Status Dependency Status

It's a Meteor compatible DDP server, based on MarsDB, but with major improvements. It supports methods, pub/sub and collection operations. It have very similar to the original Meteor interface, so, you really knows how to use it, if you are familiar with Meteor. But it also highly customizable, because it can be used with any server, that you passed to a configure function. Check out a basic example with express and webpack.

Features

  • Asynchonous server – no Fibers
  • Reactive joins in publish – out of the box
  • Framework agnostic – configured upon node.js's http server
  • Easy to test and play – no MongoDB needed, MarsDB works with memory by default

WARNING

It's only a concept until 1.0. Use it for your own risk. It does not support scaling, handled only changes happened on one instance. Scaling will be handled by MarsDB-Mongo module.

Examples

Basic Express/Webpack example

The repository comes with a simple example. To try it out:

git clone https://github.com/c58/marsdb-sync-server.git
cd marsdb-sync-server/example && npm install
npm start

Then, just point your browser at http://localhost:3000.

Configure a server

import http from 'http';
import MarsSync from 'marsdb-sync-server';
import requireDir from 'require-dir';

// Some server configuration
// ...
const server = http.createServer();

// Setup marsdb-sync-server
MarsSync.configure({ server });

// You must require all your models, publishers and methods.
// They will be registered in MarsSync server.
requireDir('./js/models');
requireDir('./js/publishers');
requireDir('./js/methods');

Auto-publish

// ...
// Setup marsdb-sync-server with autoPublish enabled
MarsSync.configure({ server, autoPublish: true });

// With {autoPublish: true} all documents in each
// collection will be sent to each newly connected client

Publising

import UserModel from '../models/User.model';
import TodoModel from '../models/Todo.model';
import { publish } from 'marsdb-sync-server';

// Publish all todos in a collection and all users,
// who have created todos
publish('allTodos', (ctx, arg1, arg2) => {
  // Publisher always receive first `ctx` arguments,
  // that contains `connection` field for now.
  // In next versions it would be extended by other modules
  return TodoModel.find().join((todo) => [
    // Define joins for each todo, it's not reactive
    // (changed user will not be changed in clients)
    UserModel.find(todo.authorId),

    // ...and this reactive. All changed users will be
    // sended the clients.
    UserModel.find(todo.authorId).observe(),
  ]);

  // Must return a cursor or array of cursors.
});

Methods

import { method } from 'marsdb-sync-server';

// Defines a method named 'seyHello'
method('sayHello', (ctx, name = 'unknown') => {
  // First argument the same as in `publish`
  const msg = 'Hello, ' + name;
  return msg;

  // Might return something.
  // If returned promise or array of promises, then an
  // `updated` message sended to a client when all promises
  // will be resolved.
});

Using with MongoDB (and other storages)

By default MarsDB uses memory to store collections. You can easily configure it for using MongoDB (or other storages) as a backend. Just configure MarsDB to use MongoDB before any instance of a Collection class created

// server.js
import MarsMongo from 'marsdb-mongo';
// DO NOT import Colllection releted modules here
// ...other imports

// ...some server configuration
MarsMongo.configure({ url: 'mongodb://127.0.0.1:27017' });
MarsSync.configure({ server: server });

// Require all Collection releted modules
requireDir('./js/models');
requireDir('./js/publishers');
requireDir('./js/methods');

Roadmap

  • Context customization by other modules
  • Documentation

Contributing

I'm waiting for your pull requests and issues. Don't forget to execute gulp lint before requesting. Accepted only requests without errors.

License

See License