Skip to content

Releases: moleculerjs/moleculer-addons

moleculer-mail@1.1.0

Choose a tag to compare

@icebob icebob released this 07 Nov 18:42

Changes

  • add data: {} to settings for global template variables
  • return with MoleculerRetryableError if unable to send mail.

moleculer-db@0.6.0

Choose a tag to compare

@icebob icebob released this 12 Sep 12:35

Breaking changes

Updated Moleculer to the latest 0.11 version. It means, the clearCache method is changed.
New implementation:

clearCache() {
    this.broker.broadcast(`cache.clean.${this.name}`);
    if (this.broker.cacher)
        this.broker.cacher.clean(`${this.name}.*`);
    return this.Promise.resolve();
},

So if you call this method in a users service, the service clears the local cache with the users.* match string and emits a broadcast event with cache.clean.users name.

moleculer-db@0.5.0

Choose a tag to compare

@icebob icebob released this 08 Aug 13:51

Changes

Changed create & insert actions (breaking)

The current create action renamed to insert. It accepts entity param to create an entity. Or entities array to create multiple entities.
The create actions save a new entity from the params directly. So you can send an entity JSON directly to the create action.

// Create a new entity
broker.call("users.create", {
    name: "John",
    age: 33,
    status: true
});

// Create a new entity
broker.call("users.insert", {
    entity: {
        name: "John",
        age: 33,
        status: true
    }
});

// Create multiple entities
broker.call("users.insert", {
    entities: [
        {
            name: "John",
            age: 33,
            status: true
        },
        {
            name: "Jane",
            age: 28,
            status: true
        }
    ]
});

Better update action (breaking)

The update action update entity fields from params directly. You don't need to wrap it under an update prop.

broker.call("users.update", {
    id: 5,
    name: "Jane",
    status: false
});

Minor changes

  • added EntityNotFoundError.

moleculer-db-adapter-mongoose@0.4.0

Choose a tag to compare

Update API to moleculer-db v0.5

moleculer-db@0.4.0

Choose a tag to compare

@icebob icebob released this 17 Jul 12:53

New

Encoding & decoding IDs

There are two new encodeID and decodeID methods. You can use them if you want to encode & decode database ID (for example with hashids)

const Hashids = require("hashids");
const hashids = new Hashids("secret salt");

broker.createService({
    name: "posts",
    mixins: [DbService],
    methods: {
        encodeID(id) {
            return hashids.encodeHex(id);
        },
        decodeID(id) {
            return hashids.decodeHex(id);
        }
    }
});

Entity lifecycle events

There are 3 entity lifecycle events which are called when entities are manipulated.

broker.createService({
    name: "posts",
    mixins: [DbService],
    settings: {},

	afterConnected() {
		this.logger.info("Connected successfully");
	},

	entityCreated(json, ctx) {
		this.logger.info("New entity created!");
	},

	entityUpdated(json, ctx) {
        // You can also access to Context
		this.logger.info(`Entity updated by '${ctx.meta.user.name}' user!`);
	},

	entityRemoved(json, ctx) {
		this.logger.info("Entity removed", json);
	},    
});

Better fields filtering

A new fields filtering method is implemented. It can also handle nested properties.

const DbService = require("moleculer-db");

module.exports = {
    name: "users",
    mixins: [DbService],

    settings: {
        fields: ["name", "address.city", "address.country", "bio"]
    }
}

broker.call("users.get", { id: 5, fields: ["name", "address", "bio.height", "bio.hair", "password"] }).then(console.log);
/* The returned object contains only the following fields:
{
    name: "Walter",
    address: {
        city: "Albuquerque",
        country: "USA"
    },
    bio: {
        height: 185,
        hair: "bald"
    }
}
*/

Changes

  • deprecated fields as space-separated String in settings. Enabled only Array<String>.

  • deprecated fields as space-separated String in fields of settings.populates. Enabled only Array<String>.

  • BREAKING: model action & method is removed! Use get action instead.

  • moleculer-db-adapter-mongoose returns with Mongoose objects instead of native object. But it will be converted to native JS object in [moleculer-db].

        customAction(ctx) {
            return this.adapter.find({}).then(docs => {
                // You can access the Mongoose virtual methods & getters of `docs` here
            });
        }        

moleculer-db@0.3.0

Choose a tag to compare

@icebob icebob released this 07 Jul 10:45

New

New createMany method

A new createMany method is created. With it you can insert many entities to the database.

this.createMany(ctx, {
    entities: [...]
});

New list action with pagination

There is a new list action with pagination support.

broker.call("posts.list", { page: 2, pageSize: 10});

The result is similar as

{ 
    rows: [ 
        { title: 'Post #26' },
        { title: 'Post #27' },
        { title: 'Post #25' },
        { title: 'Post #21' },
        { title: 'Post #28' } 
    ],
    total: 28,
    page: 2,
    pageSize: 10,
    totalPage: 3 
}

New settings

  • pageSize - Default page size in list action. Default: 10
  • maxPageSize - Maximum page size in list action. Default: 100
  • maxLimit - Maximum value of limit in find action. Default: -1 (no limit)

moleculer-db v0.2.0

Choose a tag to compare

@icebob icebob released this 06 Jul 14:16

Breaking changes

Renamed service methods

  • findAll renamed to find
  • update renamed to updateMany
  • remove renamed to removeMany

clear action is removed

We removed the clear action from service The reason is if you don't filter it in whitelists of API gw, it will be published and callable from client-side what is very dangerous.

After all if you need it:

module.exports = {
	name: "posts",
	mixins: [DbService],

	actions: {
		clear(ctx) {
			return this.clear(ctx);
		}
	}
}

Renamed adapter methods

  • findAll renamed to find
  • update renamed to updateMany
  • remove renamed to removeMany

moleculer-db-adapter-mongoose@0.2.0

Choose a tag to compare

Breaking changes

Update methods to moleculer-db v0.2.0

  • findAll renamed to find
  • update renamed to updateMany
  • remove renamed to removeMany