This package will help you to keep your app working offline!
yarn install @offlinely/server
For client integration, take a look at @offlinely/idb
-
Creating models:
Same as @offlinely/idb, but foreign references must be
{ type: mongoose.Types.ObjectId, ref: 'ReferenceModelName'}
Example:
// models/app1.ts import mongoose from 'mongoose' import { OffModel } from '@offlinely/backend' export default OffModel({ User: { firstname: String, lastname: String, age: Number, password: {type: String, required: true}, access: Boolean }, Warehouse: { name: String, user: { type: mongoose.Types.ObjectId, ref: 'User'} }, })
-
Creating the server
import {Offlinely, getTokens} from "@offlinely/backend" import app1 from "./models/app1" import app2 from "./models/myapp2" Offlinely({ App1: app1, App2: app2 // here, keys 'App1' and 'App2' will be the Mongo database name }).then(({db, listen}) => { console.log(getTokens(db)) // will log the tokens used by IDB listen(9000, () => console.log("Started on port " + 9000)) })
-
Models are just objects with custom keys and types. Types may be: String, Number, Boolean, Date, or
Custom objects(unstable)// models.ts export const User = { firstame: String, lastname: String, age: Number, access: Boolean }
-
Offlinely is a function that will retur, create and manage at the same time the models and the databases.
Offlinely(schema, address, addressParams): OfflinelyType
OfflinelyType { db, // Database instance app, // used Express instance io, // used SocketIO instance, listen, // server starter on a port (see example) extend // (unstable) Extension method }
Name Type Required Default Description schema Object Yes - Backend socket backend URL address string No "127.0.0.1:27017"
Application Name addressParams string No ""
ifaddress
contains no@
, and"authMechanism=DEFAULT&authSource=admin"
if there is an@
connexion params of mongo address -
Example
Offlinely({...})
--->
mongodb://127.0.0.1:27017/db
.Offlinely({...}, 'custom.server:port')
--->
mongodb://custom.server:port/db
.Offlinely({...}, "foo:bar@custom.server:port", "key=param&otherkey=param2")
.--->
mongodb://foo:bar@custom.server:port/db?key=param&otherkey=param2
-