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 🙏

© 2025 – Pkg Stats / Ryan Hefner

uorm

v0.6.16

Published

This is a port of python [uEngine](https://github.com/viert/uengine) MongoDB ORM library

Readme

uORM TypeScript MongoDB ORM

This is a port of python uEngine MongoDB ORM library

Usage

Declare models:

import { StorableModel, StringField, DatetimeField } from 'uorm';

class User extends StorableModel {
  static __collection__ = 'user';

  @StringField({ required: true }) username: string;
  @StringField() first_name: string;
  @StringField() last_name: string;
  @DatetimeField({ defaultValue: Date }) created_at: Date;
  @StringField() description: string;

  get fullname() {
    return `${this.first_name} ${this.last_name}`;
  }
}

Initialize database connections

import { db, DatabaseConfig } from 'uorm';

const conf: DatabaseConfig = {
  meta: {
    uri: 'mongodb://localhost',
    dbname: 'mydb',
    options: { useUnifiedTopology: true },
  },
  shards: {},
};

async function main() {
  await db.init(conf);
}

Use models for CRUD operations:

let user = await User.findOne({username: 'johndoe'})
console.log(user);
user.first_name = 'Jim'
await user.save();

const cursor = User.find({first_name: 'John'})
for await (user in cursor) {
  console.log(user); // Cursor emits User instances
}

await User.destroyAll()

Async computed properties

Model's toObject(fields: string[]) method automatically picks up any getter you have in your model:

class MyModel extends StorableModel {
  @StringField() field1: string;
  @StringField() field2: string;
  @StringField() field3: string;

  get concat() {
    return field1 + field2 + field3;
  }
}

const model = new MyModel({ field1: 'a', field2: 'b', field3: 'c' });
console.log(
  model.toObject(['field1', 'field2', 'field3', 'concat', 'non-existent'])
);
/**
{
  field1: 'a',
  field2: 'b',
  field3: 'c',
  concat: 'abc'
}
*/

However you might want to use other models in computations, i.e. you need to wait for the DB or for your cache adapter like Memcached or Redis or whatever. In this case getter will let you down, it's syncronous.

For your convenience there's an async method async asyncObject(fields) which handles this (remember that you have to await it). To expose your async computed property, use AsyncComputed decorator:

import { AsyncComputed, StorableModel } from 'uorm';

class Token extends StorableModel {
  @StringField({ required: true }) token: string;
  @ObjectIdField({ required: true }) owner_id: ObjectID;

  @AsyncComputed()
  get owner() {
    const user = await User.findOne({ _id: this.owner_id });
    return await user.asyncObject();
  }
}

Notice that calling asyncObject without arguments (like in the example above) is quite a useless thing: by default fields list equals to everything declared with <Type>Field decorator, i.e. there's nothing async there by default, thus, syncronous toObject() would suffice.