Giter Club home page Giter Club logo

moonridge-client's Introduction

Moonridge-client

client library for Mongo remote ORM framework Moonridge.

Install with jspm(for browser) or npm(for node):

npm install moonridge-client

jspm install moonridge-client

Is JSPM really needed?

Moonridge is written in commonJS format(client works in node and browser without much hassle), so you need globally installed jspm to be able to install it with one command. For loading in the browser, you need systemJS(which JSPM installs for you). If you don't have jspm, install it with this command:

npm i jspm -g

As it works in node, it should be possible to run in browserify/webpack as well, but I don't guarantee it. JSPM might also be able to make you a bundle of all scripts needed. This bundle can then be used as regular script file with a script tag. Theoretically.

Basic usage

// ES6 import
import MR from 'moonridge-client'
/// cjs
const MR = require('moonridge-client')

// then just connect to your backend
const backend = MR({url: 'http://localhost:9000'})
// connecting with sync authorization
const backend = MR({url: 'http://localhost:9000', hs: { //hs stands for handshake(is passed to socket.io's connect method)
  query: '[email protected]&password=' + encodeURIComponent(password)
}})

// finally declare which model are you going to use(models are defined with schemas on the backend)
const bookModel = backend.model('book')

Backend instance API

model(string)

synchronously defines a model to be used with the backend

@param {String} name
@returns {Model}

fetchAllModels()

asynchronously gets a list of all models on the backend and then synchronously defines them

@param {String} name
@returns {Model}

authorize(object)

async authorization-use when user connects as anonymous and then gains some priviliges while session is opened

@param {Object} auth object
@returns {Promise} resolved on succesful authorization

deAuthorize()

user logged out/lost priviliges

@returns {Promise} resolved when user was removed from this socket on the server

Model instance API

query()

@returns {QueryChainable} which has same methods as mongoose.js query. When you chain all query
                          conditions, you use exec() to fire the query, Promise is returned

liveQuery([previousLiveQuery])

@param {Object} [previousLQ] useful when we want to modify an existing running LQ, pass it after it is stopped
@returns {QueryChainable} same as query, difference is that executing this QueryChainable won't return
                          promise, but liveQuery object itself

create(object)

@param {Object} toCreate
@returns {Promise} resolved when object is created in the database

update(object)

@param {Object} toUpdate moonridge object
@param {Boolean} resolveWhole if true, it will resolve with whole object instead of just the version
@returns {Promise} resolved when object is saved

Why not return whoole object by default? Because it would waste bandwith. If you need to display latest version of a document, it is preferable to use liveQuery().findOne({_id: id}), instead of manually updating your copy

remove(toRemove)

@param {Object|String} toRemove must have and _id if an object, otherwise we assume the string is the id
@returns {Promise}

addToSet(query, path, item)

@param {Object} query which will be used to find one document to update
@param {String} path
@param {*} item it is highly recommended to use simple values, not objects
@returns {Promise} resolved when object is updated

removeFromSet(query, path, item)

@param {Object} query which will be used to find one document to update
@param {String} path
@param {*} item it is highly recommended to use simple values, not objects
@returns {Promise} resolved when object is updated

on()

@returns {Promise} resolved when subscription is created on the server

off()

@returns {Promise} resolved when subscription is unsubscribed on the server

getSchema()

@returns {Promise} resolved with serialized and deserialized mongoose schema using mongoose-schema-serializer

QueryChainable instance API

Mimics mongoose query api, with some methods dropped. Implemented methods are:

all and box circle comment count distinct elemMatch equals exists find findOne geometry gt gte hint in intersects limit lt lte maxDistance maxScan mod ne near nin nor or ne polygon populate read regex select size skip slice sort where within

js-standard-style

moonridge-client's People

Contributors

capaj avatar ztzven avatar mjt60 avatar

Watchers

James Cloos avatar  avatar splnty avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.