<commit_before>'use strict';

const common = require('x2node-common');
const pointers = require('x2node-pointers');

const AbstractDBO = require('./abstract-dbo.js');
const DBOExecutionContext = require('./dbo-execution-context.js');
const FetchDBO = require('./fetch-dbo.js');
const ValueExpressionContext = require('./value-expression-context.js');
const propsTreeBuilder = require('./props-tree-builder.js');
const queryTreeBuilder = require('./query-tree-builder.js');


/////////////////////////////////////////////////////////////////////////////////
// COMMANDS
/////////////////////////////////////////////////////////////////////////////////

/**
 * Pre-fetch command. When executed, fetches all matching records due for update
 * and sets them in the context.
 *
 * @private
 * @memberof module:x2node-dbos
 * @inner
 * @implements module:x2node-dbos.DBOCommand
 */
class PrefetchCommand {

	constructor(fetchDBO) {

		this._fetchDBO = fetchDBO;
	}

	// add command execution to the chain
	queueUp(promiseChain, ctx) {

		return promiseChain.then(
			() => this._fetchDBO.execute(ctx)
		).then(
			result => {
				ctx.setRecords(result.records);
			}
		);
	}
}

/**
 * Call provided fetcher function command. When executed, gets the records from
 * the fetcher function and sets them in the context.
 *
 * @private
 * @memberof module:x2node-dbos
 * @inner
 * @implements module:x2node-dbos.DBOCommand
 */
class CallFetcherCommand {

	constructor(fetcher) {

		this._fetcher = fetcher;
	}

	// add command execution to the chain
	queueUp(promiseChain, ctx) {

		return promiseChain.then(
			() => this._fetcher(ctx.transaction, ctx.actor, ctx.filterParams)
		).then(
			result => {
				ctx.setRecords(result);
			}
		);
	}
}

/**
 * Update pre-fetched records command. When executed, goes over each record set
 * in the context, applies the patch, validates and flushes it to the database.
 *
 * @private
 * @memberof module:x2node-dbos
 * @inner
 * @implements module:x2node-dbos.DBOCommand
 */
class UpdateRecordsCommand {

	constructor(patch) {

		this._patch = patch;
	}

	// add command execution to the chain
	queueUp(promiseChain, ctx) {

		return promiseChain.then(() => {

			// pre-resolve updates sub-chain
			let recordsChain = Promise.resolve();<commit_msg>Fixed fetcher implementation.<commit_after>'use strict';

const common = require('x2node-common');
const pointers = require('x2node-pointers');

const AbstractDBO = require('./abstract-dbo.js');
const DBOExecutionContext = require('./dbo-execution-context.js');
const FetchDBO = require('./fetch-dbo.js');
const ValueExpressionContext = require('./value-expression-context.js');
const propsTreeBuilder = require('./props-tree-builder.js');
const queryTreeBuilder = require('./query-tree-builder.js');


/////////////////////////////////////////////////////////////////////////////////
// COMMANDS
/////////////////////////////////////////////////////////////////////////////////

/**
 * Pre-fetch command. When executed, fetches all matching records due for update
 * and sets them in the context.
 *
 * @private
 * @memberof module:x2node-dbos
 * @inner
 * @implements module:x2node-dbos.DBOCommand
 */
class PrefetchCommand {

	constructor(fetchDBO) {

		this._fetchDBO = fetchDBO;
	}

	// add command execution to the chain
	queueUp(promiseChain, ctx) {

		return promiseChain.then(
			() => this._fetchDBO.execute(
				ctx.transaction, ctx.actor, ctx.filterParams)
		).then(
			result => {
				ctx.setRecords(result.records);
			}
		);
	}
}

/**
 * Call provided fetcher function command. When executed, gets the records from
 * the fetcher function and sets them in the context.
 *
 * @private
 * @memberof module:x2node-dbos
 * @inner
 * @implements module:x2node-dbos.DBOCommand
 */
class CallFetcherCommand {

	constructor(fetcher) {

		this._fetcher = fetcher;
	}

	// add command execution to the chain
	queueUp(promiseChain, ctx) {

		return promiseChain.then(
			() => this._fetcher(ctx)
		).then(
			result => {
				ctx.setRecords(result);
			}
		);
	}
}

/**
 * Update pre-fetched records command. When executed, goes over each record set
 * in the context, applies the patch, validates and flushes it to the database.
 *
 * @private
 * @memberof module:x2node-dbos
 * @inner
 * @implements module:x2node-dbos.DBOCommand
 */
class UpdateRecordsCommand {

	constructor(patch) {

		this._patch = patch;
	}

	// add command execution to the chain
	queueUp(promiseChain, ctx) {

		return promiseChain.then(() => {

			// pre-resolve updates sub-chain
			let recordsChain = Promise.resolve();
{'fraction_non_alphanumeric': 0.19100633049552498, 'fraction_numerical': 0.0034926871862038856, 'mean_word_length': 2.8088113050706567, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 13, 'https://': 0, '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': '7202615', 'n_tokens_mistral': 1435, 'n_tokens_neox': 1331, 'n_words': 336}