Releases: moleculerjs/moleculer-addons
[email protected]
Changes
- add
data: {}
tosettings
for global template variables - return with
MoleculerRetryableError
if unable to send mail.
[email protected]
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.
[email protected]
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
.
[email protected]
Update API to moleculer-db v0.5
[email protected]
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-separatedString
insettings
. Enabled onlyArray<String>
. -
deprecated
fields
as space-separatedString
infields
ofsettings.populates
. Enabled onlyArray<String>
. -
BREAKING:
model
action & method is removed! Useget
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 }); }
[email protected]
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 inlist
action. Default:10
maxPageSize
- Maximum page size inlist
action. Default:100
maxLimit
- Maximum value of limit infind
action. Default:-1
(no limit)
moleculer-db v0.2.0
Breaking changes
Renamed service methods
findAll
renamed tofind
update
renamed toupdateMany
remove
renamed toremoveMany
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 tofind
update
renamed toupdateMany
remove
renamed toremoveMany
[email protected]
Breaking changes
Update methods to moleculer-db v0.2.0
findAll
renamed tofind
update
renamed toupdateMany
remove
renamed toremoveMany