Socket
Book a DemoInstallSign in
Socket

@tvux/hmmjs

Package Overview
Dependencies
Maintainers
1
Versions
3
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@tvux/hmmjs

client side mongoose like database query interface

2.69.420
latest
Source
npmnpm
Version published
Weekly downloads
20
66.67%
Maintainers
1
Weekly downloads
 
Created
Source

hmmjs

Tired of REST api definition? Wanna go fast? Hmm come to help.

With Hmm, you can query your data in db from front-end side. No more API call required.

Mongodb driver, mongoose supported (Read executor.*.test.js for example)

Get rid of a ton of bored API end-points:

Just define one and only one end-point for transfering hmm payload between client side and server side.

// server side
const client = new MongoClient('mongodb://localhost:27017');
// - you can define which db interface user will use (mongodb native driver/mongoose/etc) 
// - you can also define which db user will use:
//   - for e.g: user1 use db A, user2 use db B
const database = client.db('hmm')
const dbDriver = new Proxy({}, {
    get(__, p) {return database.collection(p)}
})
const hmm = executorFac(dbDriver, { logLevel: 'log' })
const app = express()
app.post(
    '/api', 
    /*use can add authorization at this middleware*/
    bodyParser.raw({limit: '50mb', type: () => true}),
    async (req, res) =>
        hmm(jsonFn.parse(req.body.toString()))
            .then(rs => res.json(rs))
            .catch(e => res.status(400).send(e.message)));
app.listen(3000)

Then query directly from front-end side or serverless app as simple as below.

<script>
  // browser
  window.onload = async () => {
    const url = 'http://localhost:3000/api'
    const send = async (payload) => {
      const {data} = await axios.post(url, JSONfn.stringify(payload))
      return data
    }
    const Model = HmmBuilder(send)
    await Model('user').insertOne({user: 'admin', password: '123'})
    const admin = await Model('user').findOne({user: 'admin'})
    console.log('admin', admin)
  }
</script>

Playaround

npm i && npm run dev

You may get 0 result if your db doesn't have the object id as my Db.

Roadmap

  • Explore more use cases & edge cases.

FAQs

Package last updated on 14 Apr 2024

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

About

Packages

Stay in touch

Get open source security insights delivered straight into your inbox.

  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc

U.S. Patent No. 12,346,443 & 12,314,394. Other pending.