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

@offlinely/server

v3.0.9

Published

This package will help you to keep your **offline!** app to be synced with a mongodb database online.

Downloads

28

Readme

Welcome to Offlinely!

This package will help you to keep your offline! app to be synced with a mongodb database online.

Installation

yarn install @offlinely/server

For client integration, take a look at @offlinely/idb

How to use the Server

  • Creating models:

    Same as @offlinely/idb, and you need to create an instance of IDB.Database for each db, if you have only one App, you will just need one instance of IDB.Database. Make sure you have the same structures in backend and front. For more about the model structure, take a look at the doc in @offlinely/idb

    Example:

    // models/car-brand.ts
    
    import IDB from  '@offlinely/backend'
    const createApp = () => {
      return new IDB.Database({
        User: {
          firstname:  String,
          password: {$type:  String, $required:  true},
          access:  Boolean
        },  
        Car: {
          name:  String,
          user: { $ref: 'User'}
        },
      })
    }
    
    export default createApp
  • Creating the server

    import  IDB  from  "@offlinely/backend"
    import  createApp  from  "./models/car-brand"
    
    const server = new IDB({
      TanaApp: createApp(),
      TulearApp: createApp()
      // here, keys 'App1' and 'App2' will be the Mongo database name
    })

⚠️ Important: Each object in IBD must be new Objects, here createApp creates a new instance of with a Car branding model ⚠

Documentation

Database (Models)

  • Models are just an instance of IDB.Database with custom keys and types. Types may be: String, Number, Boolean, Date, File (see File section), Enum (See Enum section), or a Complex Structure from your weird imagination

    // server.ts
    export const myDatabase = new IDB.Database({
      User: {
        firstame: String,
        lastname: String,
        age: Number,
        access: Boolean,
        // Adding $required: false will set the reference not required for creating the item
        parents: {
          dad: {$ref: 'User', $required: false},
          mom: {$ref: 'User'}
        }
      },
      ...
    })

Server

  • Server is an instance of IDB that, it will manage the syncing, the databases and ~~custom events and actions~~ [TODO].

  • You can sync as many app as you want in one instance on IDB

    class IDB(models, IDBConfig)

    const server =  new IDB({
      EniDB: createSchoolDBModel(),
      EmitDB: createSchoolDBModel(),
      EstiDB: createSchoolDBModel(),
      RemaxDB: createSellDBModel(),
      MinisoDB: createSellDBModel(),
      BikerDB: createBikeManagingDBModel()
    }, {
      port: 4000,
      mongoString: 'mongo://...'
    })

    | Name | Type | Required | Default | Description | |---|---|--:|---|---| | schema | Object | Yes | - | Backend socket backend URL | | IDBConfig.mongoString | string | No | "mongo://localhost:27017" | Connexion string of mongo database | | IDBConfig.port | number | No | 8000 | The server port that will be used |

Linking with the FrontEnd

  • To sync the server with a frontEnd app, you have to get a token from the backend. To do so call the getTokens method of the created server object.

  • You have to get these tokens just once, they will be valid even if the server restarts

    const server =  new IDB(...)
    
    server.onReady(() => {
      console.log(server.getTokens())
    })