<commit_before>/*
 * moleculer
 * Copyright (c) 2017 Ice Services (https://github.com/ice-services/moleculer)
 * MIT Licensed
 */

"use strict";

//const _ = require("lodash");
const isFunction = require("lodash/isFunction");
const forIn = require("lodash/forIn");
const isObject = require("lodash/isObject");
const cloneDeep = require("lodash/cloneDeep");

const Promise = require("bluebird");

/**
 * Main Service class
 * 
 * @class Service
 */
class Service {

	/**
	 * Creates an instance of Service by schema.
	 * 
	 * @param {ServiceBroker} 	broker	broker of service
	 * @param {Object} 			schema	schema of service
	 * 
	 * @memberOf Service
	 */
	constructor(broker, schema) {

		if (!isObject(broker)) {
			throw new Error("Must to set a ServiceBroker instance!");
		}

		if (!isObject(schema)) {
			throw new Error("Must pass a service schema in constructor!");
		}

		if (!schema.name) {
			throw new Error("Service name can't be empty!");
		}
		
		this.name = schema.name;
		this.version = schema.version;
		this.settings = schema.settings || {};
		this.schema = schema;
		this.broker = broker;

		this.logger = this.broker.getLogger(this.name.toUpperCase() + "-SVC");

		this.actions = {}; // external access to actions

		this.broker.registerService(this);

		// Register actions
		if (isObject(schema.actions)) {

			forIn(schema.actions, (action, name) => {
				if (isFunction(action)) {
					// Wrap to an object
					action = {
						handler: action
					};
				}

				let innerAction = this._createActionHandler(cloneDeep(action), name);

				// Register to broker
				broker.registerAction(innerAction);

				// Expose to call `service.actions.find({ ...params })`
				this.actions[name] = (params) => {
					let ctx = new broker.ContextFactory({ broker, action: innerAction, params });
					return innerAction.handler(ctx);
				};
				
			});
<commit_msg>add Promise prop to Service<commit_after>/*
 * moleculer
 * Copyright (c) 2017 Ice Services (https://github.com/ice-services/moleculer)
 * MIT Licensed
 */

"use strict";

//const _ = require("lodash");
const isFunction = require("lodash/isFunction");
const forIn = require("lodash/forIn");
const isObject = require("lodash/isObject");
const cloneDeep = require("lodash/cloneDeep");

const Promise = require("bluebird");

/**
 * Main Service class
 * 
 * @class Service
 */
class Service {

	/**
	 * Creates an instance of Service by schema.
	 * 
	 * @param {ServiceBroker} 	broker	broker of service
	 * @param {Object} 			schema	schema of service
	 * 
	 * @memberOf Service
	 */
	constructor(broker, schema) {

		if (!isObject(broker)) {
			throw new Error("Must to set a ServiceBroker instance!");
		}

		if (!isObject(schema)) {
			throw new Error("Must pass a service schema in constructor!");
		}

		if (!schema.name) {
			throw new Error("Service name can't be empty!");
		}
		
		this.name = schema.name;
		this.version = schema.version;
		this.settings = schema.settings || {};
		this.schema = schema;
		this.broker = broker;

		if (broker) {
			this.Promise = broker.Promise;
		}

		this.logger = this.broker.getLogger(this.name.toUpperCase() + "-SVC");

		this.actions = {}; // external access to actions

		this.broker.registerService(this);

		// Register actions
		if (isObject(schema.actions)) {

			forIn(schema.actions, (action, name) => {
				if (isFunction(action)) {
					// Wrap to an object
					action = {
						handler: action
					};
				}

				let innerAction = this._createActionHandler(cloneDeep(action), name);

				// Register to broker
				broker.registerAction(innerAction);

				// Expose to call `service.actions.find({ ...params })`
				this.actions[name] = (params) => {
					let ctx = new broker.ContextFactory({ broker, action: innerAction, params });
					return innerAction.handler(ctx);
				};
				
			});

{'fraction_non_alphanumeric': 0.14446479979063073, 'fraction_numerical': 0.002093692750588851, 'mean_word_length': 3.2561247216035634, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 7, 'https://': 2, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4575524', 'n_tokens_mistral': 1393, 'n_tokens_neox': 1157, 'n_words': 306}