Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We鈥檒l occasionally send you account related emails.

Already on GitHub? Sign in to your account

Service modifications support for ES6 classes #514

Merged
merged 2 commits into from
Apr 10, 2019
Merged

Service modifications support for ES6 classes #514

merged 2 commits into from
Apr 10, 2019

Conversation

akazakou
Copy link
Contributor

@akazakou akazakou commented Apr 5, 2019

馃摑 Description

In some cases architectual solutions can split service and service runner logic. In that case, if you need provide to service some settings or update schema parameters, you can use schemaMods.

It working for GenericObject definition, but not working for ES6 classes. I added providing schemaMods parameters to ES6 classes.

馃幆 Relevant issues

#483 Service modifications support for ES6 classes

馃拵 Type of change

  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to not work as expected)
  • This change requires a documentation update

馃摐 Example code

class ES6Service extends Service {
	constructor(broker, schemaMods) {
		super(broker);

		this.name = "es6-with-schema-mods";
		this.version = 2;
		this.settings = {};
		this.actions = {
			send: () => Prmise.resolve()
		};

		if (schemaMods && schemaMods.settings && schemaMods.settings.connectionString) {
			this.settings.connectionString = schemaMods.settings.connectionString;
		}

		// this should prevent override this.actions in parseServiceSchema method
		this.parseServiceSchema(Object.assign({}, this));
	}
}

let broker = new ServiceBroker({ logger: false });
broker.createService(ES6Service, { settings: { connectionString: "mongodb://localhost:27017/test" } });

馃殾 How Has This Been Tested?

I've added 2 additional unit tests to check schema creating proccess for ES6 classes

  • should create service from ES6 instance without schema mods
  • should create service from ES6 instance with schema mods

馃弫 Checklist:

  • My code follows the style guidelines of this project
  • I have performed a self-review of my own code
  • I have added tests that prove my fix is effective or that my feature works
  • New and existing unit tests pass locally with my changes
  • I have commented my code, particularly in hard-to-understand areas

@coveralls
Copy link

coveralls commented Apr 5, 2019

Pull Request Test Coverage Report for Build 1817

  • 1 of 1 (100.0%) changed or added relevant line in 1 file are covered.
  • No unchanged relevant lines lost coverage.
  • Overall coverage increased (+0.01%) to 91.959%

Totals Coverage Status
Change from base Build 1798: 0.01%
Covered Lines: 4840
Relevant Lines: 5027

馃挍 - Coveralls

Copy link
Member

@icebob icebob left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good job!

src/service.js Outdated Show resolved Hide resolved
Copy link
Member

@icebob icebob left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks!

@icebob icebob merged commit b585e86 into moleculerjs:master Apr 10, 2019
@akazakou akazakou deleted the feature/support-schema-mods-for-es6-services branch April 11, 2019 18:15
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants