<commit_before>// @flow
import { Query } from '../../../../database';
import { getDomain } from '../../../../server';
import createPageLinks from '../utils/create-page-links';
import type { Action } from '../interfaces';

/**
* @private
*/
export default function resource(action: Action<any>): Action<any> {
  // eslint-disable-next-line func-names
  const resourceAction = async function (req, res) {
    const { route: { action: actionName } } = req;
    const result = action(req, res);
    let links = {};
    let data;
    let total;

    if (actionName === 'index') {
      [data, total] = await Promise.all([
        result,
        Query.from(result).count()
      ]);
    } else {
      data = await result;
    }

    if (Array.isArray(data) || (data && data.isModelInstance)) {
      const domain = getDomain(req);

      const {
        params,<commit_msg>fix: make sure result is an instance of query in resource enhancer (#648)<commit_after>// @flow
import { Query } from '../../../../database';
import { getDomain } from '../../../../server';
import createPageLinks from '../utils/create-page-links';
import type { Action } from '../interfaces';

/**
* @private
*/
export default function resource(action: Action<any>): Action<any> {
  // eslint-disable-next-line func-names
  const resourceAction = async function (req, res) {
    const { route: { action: actionName } } = req;
    const result = action(req, res);
    let links = {};
    let data;
    let total;

    if (actionName === 'index' && result instanceof Query) {
      [data, total] = await Promise.all([
        result,
        Query.from(result).count()
      ]);
    } else {
      data = await result;
    }

    if (Array.isArray(data) || (data && data.isModelInstance)) {
      const domain = getDomain(req);

      const {
        params,
{'fraction_non_alphanumeric': 0.16986301369863013, 'fraction_numerical': 0.0016438356164383563, 'mean_word_length': 2.5319148936170213, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 7, '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': '1688662', 'n_tokens_mistral': 533, 'n_tokens_neox': 527, 'n_words': 156}